21 #include <hardware/pit.h> 22 #include <hardware/io/ps2.h> 26 #define IS_EXCEPTION(intr) ((intr) <= 0x1F) 27 #define IS_IRQ(intr) ((intr) >= 0x20 && intr <= 0x2F) 29 #define IS_SYSCALL(intr) ((intr) == 0x30) 44 if (enable && !old_interrupts) {
46 }
else if (!enable && old_interrupts)
57 asm volatile(
"pushfl; pop %%eax; mov %%eax, %0" :
"=r" (eflags.
dword));
68 println(
"%4ainterrupt vector %d not allowed%a", intr);
81 if (
id >= SYSCALL_NUMBER) {
82 println(
"%4asyscall %d not allowed%a",
id);
103 uint32_t intr = cpu->
intr;
108 panic(
"%4aEX%02x (EIP=%08x)", intr, cpu->
eip);
110 print(
"%2aIRQ%d%a", intr -
ISR_IRQ(0));
112 print(
"%4aSYS%08x%a", cpu->
r.
eax);
124 logln(
"ISR",
"uss=%08x usp=%08x efl=%08x cs= %04x eip=%08x err=%08x " 125 "int=%08x eax=%08x ecx=%08x edx=%08x",
128 logln(
"ISR",
"ebx=%08x esp=%08x ebp=%08x esi=%08x edi=%08x " 129 "ds= %04x es= %04x fs= %04x gs= %04x",
131 cpu->
ds, cpu->
es, cpu->
fs, cpu->
gs);
147 println(
"%4aUnknown syscall %08x%a", cpu->
r.
eax);
153 print(
"ISR init ... ");
void isr_dump_cpu(cpu_state_t *cpu)
Dumps a CPU state.
uint8_t isr_enable_interrupts(uint8_t enable)
Enables or disables interrupts.
uint16_t gs
GS segment register.
cpu_state_t * isr_handle_interrupt(cpu_state_t *cpu)
Handles all interrupts.
static isr_handler_t handlers[IDT_ENTRIES]
a table that associates interrupt vectors with handlers
cpu_state_t *(* isr_handler_t)(cpu_state_t *cpu)
Handles a specific interrupt.
void pic_send_eoi(uint8_t intr)
Sends an "end of interrupt" signal.
uint32_t edx
data register
static cpu_state_t * isr_handle_syscall(cpu_state_t *cpu)
Handles all syscalls.
#define IS_EXCEPTION(intr)
whether the given interrupt vector is an exception
The CPU's state when an interrupt occurs.
#define IS_SYSCALL(intr)
whether the given interrupt vector is the syscall
uint32_t esp
stack pointer register
static uint8_t old_interrupts
for temporary modifications
#define ISR_SYSCALL
the interrupt vector for the syscall
uint32_t user_ss
stack segment (only pushed and popped in user space)
uint8_t _if
interrupt flag
#define ISR_IRQ(irq)
the interrupt vector for an IRQ
uint32_t eip
the instruction to return to after the interrupt
void isr_register_handler(size_t intr, isr_handler_t handler)
Registers a handler to call whenever a given interrupt is fired.
uint16_t es
ES segment register.
void isr_init()
Initializes syscalls and enables interrupts.
void isr_register_syscall(size_t id, void *syscall)
Registers a syscall handler to call whenever a specified syscall is requested.
uint32_t dword
useful for casting
uint32_t esi
source index register
#define IDT_ENTRIES
Number of entries in the IDT.
void syscall_init()
Initializes the syscall interface.
uint32_t ebp
base pointer register
uint16_t fs
FS segment register.
struct isr_eflags_t::@8 bits
bit field
uint32_t eax
accumulator register
uint16_t cs
the code segment to return to after the interrupt
uint16_t isr_eflags_t eflags
the EFLAGS register before the interrupt was fired
uint32_t ebx
base register
uint32_t edi
destination index register
uint32_t error
hold an error code if an error occured, otherwise 0
uint32_t user_esp
stack pointer (only pushed and popped in user space)
uint16_t ds
DS segment register.
uint32_t ecx
counter register
uint32_t intr
the interrupt vector of the fired interrupt
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.
uint8_t isr_get_interrupts()
Returns whether interrupts are enabled or disabled.
#define IS_IRQ(intr)
whether the given interrupt vector is an IRQ
static void * syscalls[SYSCALL_NUMBER]
a table that associates syscall IDs with handlers
uint16_t isr_registers_t r
The general purpose registers.