PatchworkOS
Loading...
Searching...
No Matches
Interrupts

Interrupt Handling. More...

Data Structures

struct  interrupt_frame_t
 Trap Frame Structure. More...
 
struct  interrupt_ctx_t
 Per-CPU Interrupt Context. More...
 

Macros

#define INTERRUPT_FRAME_IN_USER_SPACE(frame)   ((frame)->ss == (GDT_SS_RING3) && (frame)->cs == (GDT_CS_RING3))
 Checks if a interrupt frame is from user space.
 

Enumerations

enum  page_fault_errors_t {
  PAGE_FAULT_PRESENT = 1 << 0 ,
  PAGE_FAULT_WRITE = 1 << 1 ,
  PAGE_FAULT_USER = 1 << 2 ,
  PAGE_FAULT_RESERVED = 1 << 3 ,
  PAGE_FAULT_INSTRUCTION = 1 << 4 ,
  PAGE_FAULT_PROTECTION_KEY = 1 << 5 ,
  PAGE_FAULT_SHADOW_STACK = 1 << 6 ,
  PAGE_FAULT_SOFTWARE_GUARD_EXT = 1 << 7
}
 Page Fault Error Codes. More...
 
enum  interrupt_t {
  EXCEPTION_DIVIDE_ERROR = 0x0 ,
  EXCEPTION_DEBUG = 0x1 ,
  EXCEPTION_NMI = 0x2 ,
  EXCEPTION_BREAKPOINT = 0x3 ,
  EXCEPTION_OVERFLOW = 0x4 ,
  EXCEPTION_BOUND_RANGE_EXCEEDED = 0x5 ,
  EXCEPTION_INVALID_OPCODE = 0x6 ,
  EXCEPTION_DEVICE_NOT_AVAILABLE = 0x7 ,
  EXCEPTION_DOUBLE_FAULT = 0x8 ,
  EXCEPTION_COPROCESSOR_SEGMENT_OVERRUN = 0x9 ,
  EXCEPTION_INVALID_TSS = 0xA ,
  EXCEPTION_SEGMENT_NOT_PRESENT = 0xB ,
  EXCEPTION_STACK_FAULT = 0xC ,
  EXCEPTION_GENERAL_PROTECTION = 0xD ,
  EXCEPTION_PAGE_FAULT = 0xE ,
  EXCEPTION_RESERVED = 0xF ,
  EXCEPTION_X87_FPU_ERROR = 0x10 ,
  EXCEPTION_ALIGNMENT_CHECK = 0x11 ,
  EXCEPTION_MACHINE_CHECK = 0x12 ,
  EXCEPTION_SIMD_EXCEPTION = 0x13 ,
  EXCEPTION_VIRTUALIZATION_EXCEPTION = 0x14 ,
  EXCEPTION_CONTROL_PROTECTION_EXCEPTION = 0x15 ,
  EXCEPTION_RESERVED_16 = 0x16 ,
  EXCEPTION_RESERVED_17 = 0x17 ,
  EXCEPTION_RESERVED_18 = 0x18 ,
  EXCEPTION_RESERVED_19 = 0x19 ,
  EXCEPTION_RESERVED_1A = 0x1A ,
  EXCEPTION_RESERVED_1B = 0x1B ,
  EXCEPTION_RESERVED_1C = 0x1C ,
  EXCEPTION_RESERVED_1D = 0x1D ,
  EXCEPTION_RESERVED_1E = 0x1E ,
  EXCEPTION_RESERVED_1F = 0x1F ,
  EXCEPTION_AMOUNT = 0x20 ,
  EXTERNAL_INTERRUPT_BASE = 0x20 ,
  INTERRUPT_TLB_SHOOTDOWN = 0xFA ,
  INTERRUPT_DIE = 0xFB ,
  INTERRUPT_NOTE = 0xFC ,
  INTERRUPT_TIMER = 0xFD ,
  INTERRUPT_HALT = 0xFE ,
  INTERRUPT_AMOUNT = 0xFF
}
 CPU vector identifiers. More...
 

Functions

void interrupt_ctx_init (interrupt_ctx_t *ctx)
 Initializes the CLI context.
 
void interrupt_disable (void)
 Disable interrupts and increment the disableDepth.
 
void interrupt_enable (void)
 Decrement the CLI depth and enable interrupts if depth reaches zero and interrupts were previously enabled.
 
void interrupt_handler (interrupt_frame_t *frame)
 Handles CPU interrupts.
 

Variables

void * vectorTable [INTERRUPT_AMOUNT]
 Pointers to functions to handle each vector.
 

Detailed Description

Interrupt Handling.

This module provides structures and functions for handling CPU interrupts.

Macro Definition Documentation

◆ INTERRUPT_FRAME_IN_USER_SPACE

#define INTERRUPT_FRAME_IN_USER_SPACE (   frame)    ((frame)->ss == (GDT_SS_RING3) && (frame)->cs == (GDT_CS_RING3))

Checks if a interrupt frame is from user space.

Parameters
frameThe interrupt frame to check.
Returns
true if the interrupt frame is from user space, false otherwise.

Definition at line 76 of file interrupt.h.

Enumeration Type Documentation

◆ interrupt_t

CPU vector identifiers.

External interrupts (IRQ's) are defined in irq_t.

Enumerator
EXCEPTION_DIVIDE_ERROR 
EXCEPTION_DEBUG 
EXCEPTION_NMI 
EXCEPTION_BREAKPOINT 
EXCEPTION_OVERFLOW 
EXCEPTION_BOUND_RANGE_EXCEEDED 
EXCEPTION_INVALID_OPCODE 
EXCEPTION_DEVICE_NOT_AVAILABLE 
EXCEPTION_DOUBLE_FAULT 
EXCEPTION_COPROCESSOR_SEGMENT_OVERRUN 
EXCEPTION_INVALID_TSS 
EXCEPTION_SEGMENT_NOT_PRESENT 
EXCEPTION_STACK_FAULT 
EXCEPTION_GENERAL_PROTECTION 
EXCEPTION_PAGE_FAULT 
EXCEPTION_RESERVED 
EXCEPTION_X87_FPU_ERROR 
EXCEPTION_ALIGNMENT_CHECK 
EXCEPTION_MACHINE_CHECK 
EXCEPTION_SIMD_EXCEPTION 
EXCEPTION_VIRTUALIZATION_EXCEPTION 
EXCEPTION_CONTROL_PROTECTION_EXCEPTION 
EXCEPTION_RESERVED_16 
EXCEPTION_RESERVED_17 
EXCEPTION_RESERVED_18 
EXCEPTION_RESERVED_19 
EXCEPTION_RESERVED_1A 
EXCEPTION_RESERVED_1B 
EXCEPTION_RESERVED_1C 
EXCEPTION_RESERVED_1D 
EXCEPTION_RESERVED_1E 
EXCEPTION_RESERVED_1F 
EXCEPTION_AMOUNT 
EXTERNAL_INTERRUPT_BASE 
INTERRUPT_TLB_SHOOTDOWN 

TLB shootdown interrupt.

INTERRUPT_DIE 

Kills and frees the current thread.

INTERRUPT_NOTE 

Nofify that a note is available.

INTERRUPT_TIMER 

The timer subsystem interrupt.

INTERRUPT_HALT 

Halt the CPU.

INTERRUPT_AMOUNT 

Definition at line 96 of file interrupt.h.

◆ page_fault_errors_t

Page Fault Error Codes.

Will be stored in the error code of the interrupt frame on a page fault.

Enumerator
PAGE_FAULT_PRESENT 
PAGE_FAULT_WRITE 
PAGE_FAULT_USER 
PAGE_FAULT_RESERVED 
PAGE_FAULT_INSTRUCTION 
PAGE_FAULT_PROTECTION_KEY 
PAGE_FAULT_SHADOW_STACK 
PAGE_FAULT_SOFTWARE_GUARD_EXT 

Definition at line 22 of file interrupt.h.

Function Documentation

◆ interrupt_ctx_init()

void interrupt_ctx_init ( interrupt_ctx_t ctx)

Initializes the CLI context.

Parameters
cliThe CLI context to initialize.

Definition at line 19 of file interrupt.c.

References interrupt_ctx_t::disableDepth, interrupt_ctx_t::inInterrupt, and interrupt_ctx_t::oldRflags.

Referenced by cpu_init().

◆ interrupt_disable()

void interrupt_disable ( void  )

Disable interrupts and increment the disableDepth.

Must have a matching interrupt_enable() call to re-enable interrupts when depth reaches zero.

Definition at line 26 of file interrupt.c.

References interrupt_ctx_t::disableDepth, cpu_t::interrupt, interrupt_ctx_t::oldRflags, rflags_read(), and smp_self_unsafe().

Referenced by apic_timer_ticks_per_ns(), lock_acquire(), rwlock_read_acquire(), rwlock_write_acquire(), smp_self(), and timer_acquire().

◆ interrupt_enable()

void interrupt_enable ( void  )

Decrement the CLI depth and enable interrupts if depth reaches zero and interrupts were previously enabled.

Definition at line 38 of file interrupt.c.

References assert, interrupt_ctx_t::disableDepth, cpu_t::interrupt, interrupt_ctx_t::oldRflags, RFLAGS_INTERRUPT_ENABLE, rflags_read(), and smp_self_unsafe().

Referenced by apic_timer_ticks_per_ns(), lock_acquire(), lock_release(), rwlock_read_release(), rwlock_write_release(), smp_put(), and timer_release().

◆ interrupt_handler()

Variable Documentation

◆ vectorTable

void* vectorTable[INTERRUPT_AMOUNT]
extern

Pointers to functions to handle each vector.

Referenced by idt_init().