diff --git a/interrupt/handler.asm.S b/interrupt/handler.asm.S index b9312c5..42cc0a3 100644 --- a/interrupt/handler.asm.S +++ b/interrupt/handler.asm.S @@ -48,55 +48,53 @@ section '.text' executable macro inth op1 { + push r15 + lea r15, [rsp+8] + push r14 + push r13 + push r12 + push r11 + push r10 + push r9 + push r8 + push r15 ; original rsp in r15 + push rbp push rdi - mov rdi, op1 push rsi push rdx - mov rdx, [rsp+24] - push rcx - push r8 - push r9 - push r10 - push r11 - push rax + mov r9, rcx + mov r8, rbx + mov rcx, rax + mov rdx, [rsp+104] ; 13*8 (13 pushes of 8 bytes) + xor rsi, rsi + mov rdi, op1 call interrupt_Handler - pop rax - pop r11 - pop r10 - pop r9 - pop r8 - pop rcx - pop rdx - pop rsi - pop rdi - iretq + ; interrupt_Handler panics } macro inth_err op1 { - push rsi - push rdi - mov rdi, op1 - mov esi, [rsp+16] - push rdx - mov rdx, [rsp+32] - push rcx - push r8 - push r9 - push r10 + push r15 + lea r15, [rsp+8] + push r14 + push r13 + push r12 push r11 - push rax + push r10 + push r9 + push r8 + push r15 ; original rsp in r15 + push rbp + push rdi + push rsi + push rdx + mov r9, rcx + mov r8, rbx + mov rcx, rax + mov rdx, [rsp+8+104] ; 13*8 (13 pushes of 8 bytes) + mov esi, [rsp+104] + mov rdi, op1 call interrupt_Handler - pop rax - pop r11 - pop r10 - pop r9 - pop r8 - pop rcx - pop rdx - pop rdi - pop rsi - add rsp, 8 ; pop the error code - iretq + ; interrupt_Handler panics } interrupt_Int0: ; does not return diff --git a/interrupt/handler.c b/interrupt/handler.c index 7ed2340..c2cb8e3 100644 --- a/interrupt/handler.c +++ b/interrupt/handler.c @@ -38,8 +38,33 @@ const char *interrupt_Descriptions[] = { "Interrupt 31", }; -SYSV_ABI void interrupt_Handler(int vec, int errcode, uint64_t rip, int c, int d, int e) { - io_Printf("Panic: INT %02xh: %s, err=%d(0x%02x), rip=%llx\n", vec, interrupt_Descriptions[vec], errcode, errcode, rip); +/* A little snippet for testing the handler: + asm volatile( + "mov $0, %rax\n\t" + "mov $1, %rbx\n\t" + "mov $2, %rcx\n\t" + "mov $3, %rdx\n\t" + "mov $4, %rsi\n\t" + "mov $5, %rdi\n\t" + "mov $6, %rbp\n\t" + "mov $8, %r8\n\t" + "mov $9, %r9\n\t" + "mov $10, %r10\n\t" + "mov $11, %r11\n\t" + "mov $12, %r12\n\t" + "mov $13, %r13\n\t" + "mov $14, %r14\n\t" + "mov $15, %r15\n\t" + "int3"); + */ + +SYSV_ABI void interrupt_Handler(int vec, int errcode, uint64_t rip, uint64_t rax, uint64_t rbx, uint64_t rcx, uint64_t rdx, uint64_t rsi, uint64_t rdi, uint64_t rbp, uint64_t rsp, uint64_t r8, uint64_t r9, uint64_t r10, uint64_t r11, uint64_t r12, uint64_t r13, uint64_t r14, uint64_t r15) { + io_Printf("Panic: INT %02xh: %s, err=%d(0x%02x), rip=%llx\n" + " RAX=%016llX, RBX=%016llX, RCX=%016llX, RDX=%016llX\n" + " RSI=%016llX, RDI=%016llX, RBP=%016llX, RSP=%016llX\n" + " R8=%016llX, R9=%016llX, R10=%016llX, R11=%016llX\n" + " R12=%016llX, R13=%016llX, R14=%016llX, R15=%016llX", + vec, interrupt_Descriptions[vec], errcode, errcode, rip, rax, rbx, rcx, rdx, rsi, rdi, rbp, rsp, r8, r9, r10, r11, r12, r13, r14, r15); __Panic_HaltSystem(); } diff --git a/interrupt/interrupt.h b/interrupt/interrupt.h index 9e8c944..e9347cb 100644 --- a/interrupt/interrupt.h +++ b/interrupt/interrupt.h @@ -48,7 +48,7 @@ SYSV_ABI void interrupt_MapHandler(void *handler, int interrupt); // errorcode is 0 if nonexistent // // for IRQs, params are documented in assembly -SYSV_ABI void interrupt_Handler(int vec, int errcode, uint64_t rip, int c, int d, int e); +SYSV_ABI void interrupt_Handler(int vec, int errcode, uint64_t rip, uint64_t rax, uint64_t rbx, uint64_t rcx, uint64_t rdx, uint64_t rsi, uint64_t rdi, uint64_t rbp, uint64_t rsp, uint64_t r8, uint64_t r9, uint64_t r10, uint64_t r11, uint64_t r12, uint64_t r13, uint64_t r14, uint64_t r15); // defined in assembly SYSV_ABI void interrupt_LoadGDT(void *gdtr);