UnnamedOS

Interrupt Service Routine. More...

+ Collaboration diagram for ISR:

Data Structures

union  isr_eflags_t
 The EFLAGS register. More...
 
struct  isr_registers_t
 general purpose registers More...
 
struct  cpu_state_t
 The CPU's state when an interrupt occurs. More...
 

Macros

#define IS_EXCEPTION(intr)   ((intr) <= 0x1F)
 whether the given interrupt vector is an exception
 
#define IS_IRQ(intr)    ((intr) >= 0x20 && intr <= 0x2F)
 whether the given interrupt vector is an IRQ
 
#define IS_SYSCALL(intr)    ((intr) == 0x30)
 whether the given interrupt vector is the syscall
 
#define ISR_EXCEPTION(ex)   (0x00 + (ex))
 the interrupt vector for an exception
 
#define ISR_IRQ(irq)    (0x20 + (irq))
 the interrupt vector for an IRQ
 
#define ISR_SYSCALL   0x30
 the interrupt vector for the syscall
 

Typedefs

typedef cpu_state_t *(* isr_handler_t) (cpu_state_t *cpu)
 Handles a specific interrupt. More...
 
typedef uint32_t(* isr_syscall_t) (uint32_t ebx, uint32_t ecx, uint32_t edx, uint32_t esi, uint32_t edi, cpu_state_t **cpu)
 Handles a specific syscall. More...
 

Functions

uint8_t isr_enable_interrupts (uint8_t enable)
 Enables or disables interrupts. More...
 
uint8_t isr_get_interrupts ()
 Returns whether interrupts are enabled or disabled. More...
 
void isr_register_handler (size_t intr, isr_handler_t handler)
 Registers a handler to call whenever a given interrupt is fired. More...
 
void isr_register_syscall (size_t id, void *syscall)
 Registers a syscall handler to call whenever a specified syscall is requested. More...
 
cpu_state_tisr_handle_interrupt (cpu_state_t *cpu)
 Handles all interrupts. More...
 
void isr_dump_cpu (cpu_state_t *cpu)
 Dumps a CPU state. More...
 
static cpu_state_tisr_handle_syscall (cpu_state_t *cpu)
 Handles all syscalls. More...
 
void isr_init ()
 Initializes syscalls and enables interrupts.
 

Variables

static isr_handler_t handlers [IDT_ENTRIES] = {0}
 a table that associates interrupt vectors with handlers
 
static void * syscalls [SYSCALL_NUMBER] = {0}
 a table that associates syscall IDs with handlers
 

Detailed Description

Interrupt Service Routine.

An ISR is responsible for handling IRQs, exceptions and syscalls. Here only one common ISR is used, isr_handle_interrupt. It dispatches interrupts to handlers (isr_handler_t) registered by isr_register_handler.

See also
isr_asm.S
http://www.lowlevel.eu/wiki/Teil_5_-_Interrupts
http://www.lowlevel.eu/wiki/ISR
http://wiki.osdev.org/Exceptions

Typedef Documentation

typedef cpu_state_t*(* isr_handler_t) (cpu_state_t *cpu)

Handles a specific interrupt.

Is registered with isr_register_handler().

Parameters
cputhe CPU state
Returns
a (possibly altered) CPU state
See also
isr_handle_interrupt

Definition at line 90 of file isr.h.

typedef uint32_t(* isr_syscall_t) (uint32_t ebx, uint32_t ecx, uint32_t edx, uint32_t esi, uint32_t edi, cpu_state_t **cpu)

Handles a specific syscall.

Is registered with isr_register_syscall(). Unused parameters may be omitted because isr_register_syscall() works with void*. The parameters' and return value's types may differ from uint32_t, as long as they are not larger than 4 bytes (e.g. structs).

Parameters
ebxthe syscall's 1st parameter
ecxthe syscall's 2nd parameter
edxthe syscall's 3rd parameter
esithe syscall's 4th parameter
edithe syscall's 5th parameter
cpuA reference to the CPU state / stack pointer. (This is a pointer to a pointer, so we can switch tasks from within a syscall!)
Returns
The syscall's return value. void is not allowed as type.

Definition at line 106 of file isr.h.

Function Documentation

void isr_dump_cpu ( cpu_state_t cpu)

Dumps a CPU state.

The dump is logged.

Parameters
cputhe CPU state to dump

Definition at line 123 of file isr.c.

uint8_t isr_enable_interrupts ( uint8_t  enable)

Enables or disables interrupts.

Only acts if necessary.

Parameters
enablethe new interrupt flag
Returns
interrupt flag before calling isr_enable_interrupts()

Definition at line 42 of file isr.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

uint8_t isr_get_interrupts ( )

Returns whether interrupts are enabled or disabled.

Returns
interrupt flag

Definition at line 55 of file isr.c.

+ Here is the caller graph for this function:

cpu_state_t* isr_handle_interrupt ( cpu_state_t cpu)

Handles all interrupts.

This function is called whenever an interrupt is fired. It distinguishes which action to perform (call a handler, panic etc.) and, for IRQs, notifies the PIC that this interrupt has been handled.

Parameters
cpucpu has two functions here - as a pointer (CPU state) and as a value (ESP):
cpu points to the CPU state and is the ESP pushed in isr_asm.S (the former stack pointer which points to the current task's CPU state, beginning with GS).
Returns
The pointer returned by this function is a (possibly new) ESP if we want to switch tasks (then we need to make sure that ESP points to a valid CPU state).
If we don't want to switch tasks, we just return the ESP unchanged.
See also
isr_common in isr_asm.S

Definition at line 102 of file isr.c.

+ Here is the call graph for this function:

static cpu_state_t* isr_handle_syscall ( cpu_state_t cpu)
static

Handles all syscalls.

Calls a syscall handler if registered.

Parameters
cputhe current CPU state, see isr_handle_interrupt()
Returns
the new CPU state (if a task switch is desired)

Definition at line 139 of file isr.c.

+ Here is the caller graph for this function:

void isr_register_handler ( size_t  intr,
isr_handler_t  handler 
)

Registers a handler to call whenever a given interrupt is fired.

Parameters
intrthe interrupt vector that will be handled
handlerthe function to call

Definition at line 66 of file isr.c.

+ Here is the caller graph for this function:

void isr_register_syscall ( size_t  id,
void *  syscall 
)

Registers a syscall handler to call whenever a specified syscall is requested.

Parameters
idthe ID of the syscall that will be handled
syscallthe function to call (this should be an isr_syscall_t but parameters can be omitted if desired, so we pass a void*)

Definition at line 80 of file isr.c.

+ Here is the caller graph for this function: