IBNOS
Typedefs | Functions
Interrupts

Typedefs

typedef uint32_t(* interrupt_callback) (uint32_t interrupt, uint32_t error, struct thread *t)
 

Functions

uint32_t dispatchInterrupt (uint32_t interrupt, uint32_t error, struct thread *t)
 Handle an incoming interrupt. More...
 
bool interruptReserve (uint32_t interrupt, interrupt_callback callback)
 Request an interrupt. More...
 
void interruptFree (uint32_t interrupt)
 Free a previously requested interrupt. More...
 
uint32_t interrupt_0x0E (uint32_t interrupt, uint32_t error, struct thread *t)
 
uint32_t interrupt_0x07 (UNUSED uint32_t interrupt, UNUSED uint32_t error, struct thread *t)
 Coprocessor / FPU not available handler. More...
 
uint32_t interrupt_0x10 (UNUSED uint32_t interrupt, UNUSED uint32_t error, struct thread *t)
 
uint32_t interrupt_0x80 (UNUSED uint32_t interrupt, UNUSED uint32_t error, struct thread *t)
 Interrupt which handles Syscalls. More...
 

Interrupt return values

#define INTERRUPT_UNHANDLED   0
 
#define INTERRUPT_CONTINUE_EXECUTION   1
 
#define INTERRUPT_YIELD   2
 
#define INTERRUPT_EXIT_THREAD   3
 
#define INTERRUPT_EXIT_PROCESS   4
 

Detailed Description

Interrupts are used for several purposes on x86 machines.

The first purpose is to handle software errors. When a program does something which is not allowed, like accessing an invalid memory address, or something impossible like a division by zero, an Interrupt is triggered.

The CPU looks up an entry in the interrupt descriptor table (IDT), which is defined by the OS, and then calls a function (or does a task switch depending on the flags defined inside the interrupt table).

Interrupts can also be invoked by hardware, to notify the CPU about new data like a pressed key on the keyboard. These interrupts are called IRQs and can be controlled through the Programmable Interrupt Controller.

The third way to invoke an interrupt is by using the INT opcode inside a program. This allows a programs to communicate with the kernel. In IBNOS the interrupt 0x80 is used to implement syscalls.

For more information about Interrupts and IRQs take a look at http://wiki.osdev.org/Interrupts

Macro Definition Documentation

◆ INTERRUPT_CONTINUE_EXECUTION

#define INTERRUPT_CONTINUE_EXECUTION   1

The interrupt was handled, continue execution

Definition at line 48 of file interrupt.h.

◆ INTERRUPT_EXIT_PROCESS

#define INTERRUPT_EXIT_PROCESS   4

Exit the current process

Definition at line 54 of file interrupt.h.

◆ INTERRUPT_EXIT_THREAD

#define INTERRUPT_EXIT_THREAD   3

Exit the current thread

Definition at line 52 of file interrupt.h.

◆ INTERRUPT_UNHANDLED

#define INTERRUPT_UNHANDLED   0

The interrupt could not be handled -> system failure / abort process

Definition at line 46 of file interrupt.h.

◆ INTERRUPT_YIELD

#define INTERRUPT_YIELD   2

Continue with a different task

Definition at line 50 of file interrupt.h.

Typedef Documentation

◆ interrupt_callback

typedef uint32_t(* interrupt_callback) (uint32_t interrupt, uint32_t error, struct thread *t)

Definition at line 59 of file interrupt.h.

Function Documentation

◆ dispatchInterrupt()

uint32_t dispatchInterrupt ( uint32_t  interrupt,
uint32_t  error,
struct thread t 
)

Handle an incoming interrupt.

This function handles an incoming interrupt and executes a registered interrupt handler (if any).

Parameters
interruptThe interrupt which should be handled
errorAn optional error code passed by the CPU
tThe currently running thread or NULL for kernel interrupts
Returns
How to continue, take a look at the Interrupt return values defines

Definition at line 83 of file interrupt.c.

◆ interrupt_0x07()

uint32_t interrupt_0x07 ( UNUSED uint32_t  interrupt,
UNUSED uint32_t  error,
struct thread t 
)

Coprocessor / FPU not available handler.

We use hardware task switches which do not automatically save the values of the FPU. The CPU automatically protects the FPU and raises an exception if the FPU is used for the first time after a task switch. This handler saves the content of the FPU to the last task which used the FPU so that the current task can safely alter the content.

Parameters
interruptAlways 0x07
errorDoes not apply to this interrupt
tThe thread which tried to use the FPU
Returns
Always INTERRUPT_CONTINUE_EXECUTION

Definition at line 123 of file interrupt.c.

◆ interrupt_0x0E()

uint32_t interrupt_0x0E ( uint32_t  interrupt,
uint32_t  error,
struct thread t 
)

◆ interrupt_0x10()

uint32_t interrupt_0x10 ( UNUSED uint32_t  interrupt,
UNUSED uint32_t  error,
struct thread t 
)

Definition at line 153 of file interrupt.c.

◆ interrupt_0x80()

uint32_t interrupt_0x80 ( UNUSED uint32_t  interrupt,
UNUSED uint32_t  error,
struct thread t 
)

Interrupt which handles Syscalls.

This function is called when a user mode program calls the interrupt 0x80. This interrupt is used to handle Syscalls and gives the user mode program the possibility to execute predefined functions in the kernel.

Parameters
interruptAlways 0x80
errorDoes not apply to this interrupt
tThe thread which called the syscall
Returns
How to continue, depends on the called function and must be one of the Interrupt return values

Definition at line 198 of file interrupt.c.

◆ interruptFree()

void interruptFree ( uint32_t  interrupt)

Free a previously requested interrupt.

Parameters
interruptThe previously requested interrupt

Definition at line 742 of file interrupt.c.

◆ interruptReserve()

bool interruptReserve ( uint32_t  interrupt,
interrupt_callback  callback 
)

Request an interrupt.

Parameters
interruptThe interrupt you need
callbackThe function which should be called when the interrupt occurs.
Returns
True if successful or false otherwise.

Definition at line 727 of file interrupt.c.