next up previous contents index
Next: 10.8.4 base_trap_handlers: Array of Up: (X86) Base Environment: Trap Previous: 10.8.2 base_trap_init: initialize the

10.8.3 base_trap_inittab: initialization table for the default trap entrypoints

   

SYNOPSIS

#include <oskit/x86/base_trap.h>

extern struct gate_init_entry base_trap_inittab [];

DESCRIPTION

This gate initialization table (see Section 10.3.9) encapsulates the base environment's default trap entrypoint code. This module provides IDT entrypoints for all of the processor-defined trap vectors; each entrypoint pushes a standard state frame on the stack (see Section 10.8.1), and then calls the C function pointed to by the corresponding entry in base_trap_handlers array (see Section 10.8.4). Through these entrypoints, the OSKit provides the client OS with a convenient, uniform method of handling all processor traps in ordinary high-level C code.

If a trap occurs and the trap entrypoint code finds that the corresponding entry in base_trap_handlers is null, or if it points to a handler routine but the handler returns a nonzero value indicating failure, the entrypoint code calls trap_dump_panic (see Section 10.8.7) to dump the register state to the console and panic the kernel. This behavior is typically appropriate in kernels that do not expect traps to occur during proper operation (e.g., boot loaders or embedded operating systems), where a trap probably indicates a serious software bug.

On the other hand, if a trap handler is present and returns success (zero), the entrypoint code restores the saved state and resumes execution of the trapping code. The trap handler may change the contents of the trap_state structure passed by the entrypoint code; in this case, final contents of the structure on return from the trap handler will be the state restored.

All of the IDT entries initialized by the base_trap_inittab are trap gates rather than interrupt gates; therefore, if hardware interrupts are enabled when a trap occurs, then interrupts will still be enabled during the trap handler unless the trap handler explicitly disables them. If the OS wants interrupts to be disabled during trap handling, it can change the processor trap vectors in the IDT (vectors 0-31) into interrupt gates, or it can simply use its own trap entrypoint code instead.

DEPENDENCIES

struct trap_state
10.8.1
base_trap_handlers
10.8.4
trap_dump_panic
10.8.7


next up previous contents index
Next: 10.8.4 base_trap_handlers: Array of Up: (X86) Base Environment: Trap Previous: 10.8.2 base_trap_init: initialize the

University of Utah Flux Research Group