Extract handle_syscall().

This commit is contained in:
Alexander Myltsev 2023-01-31 15:43:55 +04:00
parent 4de207cd42
commit eff482f932

View File

@ -85,23 +85,18 @@ void register_interrupt_handler(uint8_t i, isr_t handler) {
} }
void trap(registers_t *r) { void trap(registers_t *r) {
if (r->int_no == T_SYSCALL) { // EOI
switch (r->eax) { if (r->int_no >= 40) {
case SYS_exit: port_byte_out(0xA0, 0x20); /* follower */
if (r->ebx == 0) { }
printk("* success\n"); if (r->int_no >= 32) {
} else { port_byte_out(0x20, 0x20); /* leader */
printk("* failure\n"); }
}
killproc(); // Call registered handler
case SYS_greet: if (interrupt_handlers[r->int_no] != 0) {
printk("Hello world!\n"); isr_t handler = interrupt_handlers[r->int_no];
r->eax = 0; handler(r);
break;
default:
printk("Unknown syscall\n");
r->eax = -1;
}
return; return;
} }
@ -112,19 +107,24 @@ void trap(registers_t *r) {
} }
panic(msg); panic(msg);
} }
}
/* Handle the interrupt in a more modular way */ static void handle_syscall(registers_t* r) {
if (interrupt_handlers[r->int_no] != 0) { switch (r->eax) {
isr_t handler = interrupt_handlers[r->int_no]; case SYS_exit:
handler(r); if (r->ebx == 0) {
} printk("* success\n");
} else {
// EOI printk("* failure\n");
if (r->int_no >= 40) { }
port_byte_out(0xA0, 0x20); /* follower */ killproc();
} case SYS_greet:
if (r->int_no >= 32) { printk("Hello world!\n");
port_byte_out(0x20, 0x20); /* leader */ r->eax = 0;
break;
default:
printk("Unknown syscall\n");
r->eax = -1;
} }
} }
@ -165,6 +165,8 @@ void load_idt() {
asm("lidt (%0)" : : "r"(&idt_reg)); asm("lidt (%0)" : : "r"(&idt_reg));
init_pic(); init_pic();
register_interrupt_handler(T_SYSCALL, handle_syscall);
} }
void cli() { void cli() {