1111#include "libk/defs.h"
1212#include "process.h"
1313
14+ #undef SERVICE
15+ #define SERVICE "SYSCALL"
16+
1417#define MAX_CALLBACKS 0x100
1518static sys_call_handler_t __callbacks [MAX_CALLBACKS ];
1619
1720static void callback (registers_t * regs );
1821
1922void system_call_init (uint8_t isr_interrupt_no ) {
20- kmemset (__callbacks , 0 , sizeof (__callbacks ));
23+ if (!kmemset (__callbacks , 0 , sizeof (__callbacks ))) {
24+ KLOG_ERROR ("Failed to clear memory of callback handlers array" );
25+ KPANIC ("Failed to clear callback handlers array" );
26+ }
27+ KLOG_DEBUG ("Registering interrupt handler on IRQ %u" , isr_interrupt_no );
2128 register_interrupt_handler (isr_interrupt_no , callback );
29+
30+ KLOG_DEBUG ("Initialized system calls" );
2231}
2332
2433void system_call_register (uint8_t family , sys_call_handler_t handler ) {
25- if (family > MAX_CALLBACKS ) {
34+ KLOG_DEBUG ("Registering handler for family 0x%02X" , family );
35+ if (family >= MAX_CALLBACKS ) {
36+ KLOG_ERROR ("Cannot register handler for family 0x%02X, must be < 0x%X" , family , MAX_CALLBACKS );
2637 PANIC ("Out of range interrupt family" );
2738 }
2839 __callbacks [family ] = handler ;
@@ -36,7 +47,7 @@ static void callback(registers_t * regs) {
3647
3748 // if (family != 0x01 && family != 0x10) {
3849 // process_t * proc = get_current_process();
39- // KLOGS_DEBUG("SYS_CALL", "Got system call 0x%04x from PID %u", (int)int_no, proc->pid);
50+ // KLOG_DEBUG( "Got system call 0x%04x from PID %u", (int)int_no, proc->pid);
4051 // }
4152
4253 void * args_data = UINT2PTR (regs -> ebx );
@@ -47,9 +58,7 @@ static void callback(registers_t * regs) {
4758 res = handler (int_no , args_data , regs );
4859 }
4960 else {
50- vga_puts ("Unknown interrupt: 0x" );
51- vga_putx (int_no );
52- // print_trace(®s);
61+ KLOG_ERROR ("Failed to find handler for interrupt 0x%04X" , int_no );
5362 PANIC ("UNKNOWN INTERRUPT" );
5463 }
5564
0 commit comments