From: John Hodge Date: Fri, 28 May 2010 06:24:14 +0000 (+0800) Subject: More work on error and interrupt handling (almost got it working) X-Git-Tag: rel0.06~173 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=182f31010e9cd84cc649e578a433169ee5c1cb5d;p=tpg%2Facess2.git More work on error and interrupt handling (almost got it working) - Note: Need to fix gdt to fix entry 0x10 --- diff --git a/Kernel/Makefile.BuildNum b/Kernel/Makefile.BuildNum index 8158a0e7..fe15723c 100644 --- a/Kernel/Makefile.BuildNum +++ b/Kernel/Makefile.BuildNum @@ -1 +1 @@ -BUILD_NUM = 2225 +BUILD_NUM = 2243 diff --git a/Kernel/arch/x86_64/desctab.asm b/Kernel/arch/x86_64/desctab.asm index 838f67e6..d49dbc43 100644 --- a/Kernel/arch/x86_64/desctab.asm +++ b/Kernel/arch/x86_64/desctab.asm @@ -78,15 +78,22 @@ Desctab_Init: %endrep ; Install IRQs - %macro SETIRQ 1 - SETIDT 0xF0+%1, Irq%1 - %endmacro - - %assign i 0 - %rep 16 - SETIRQ i - %assign i i+1 - %endrep + SETIDT 0xF0, Irq0 + SETIDT 0xF1, Irq1 + SETIDT 0xF2, Irq2 + SETIDT 0xF3, Irq3 + SETIDT 0xF4, Irq4 + SETIDT 0xF5, Irq5 + SETIDT 0xF6, Irq6 + SETIDT 0xF7, Irq7 + SETIDT 0xF8, Irq8 + SETIDT 0xF9, Irq9 + SETIDT 0xFA, Irq10 + SETIDT 0xFB, Irq11 + SETIDT 0xFC, Irq12 + SETIDT 0xFD, Irq13 + SETIDT 0xFE, Irq14 + SETIDT 0xFF, Irq15 ; Remap PIC push rdx ; Save RDX @@ -172,13 +179,13 @@ IRQ_AddHandler: %macro ISR_NOERRNO 1 Isr%1: - push 0 - push %1 + push QWORD 0 + push QWORD %1 jmp ErrorCommon %endmacro %macro ISR_ERRNO 1 Isr%1: - push %1 + push QWORD %1 jmp ErrorCommon %endmacro @@ -224,7 +231,8 @@ ErrorCommon: ;PUSH_FPU ;PUSH_XMM - mov rsi, rsp + mov rdi, rsp + xchg bx, bx call Error_Handler ;POP_XMM @@ -233,7 +241,7 @@ ErrorCommon: pop gs POP_GPR add rsp, 2*8 - iret + iretq %macro DEFIRQ 1 Irq%1: @@ -248,6 +256,7 @@ DEFIRQ i %assign i i+1 %endrep +[global IrqCommon] IrqCommon: PUSH_GPR @@ -256,18 +265,22 @@ IrqCommon: mov rax, gaIRQ_Handlers add rbx, rax + ; Check all callbacks %assign i 0 %rep NUM_IRQ_CALLBACKS + ; Get callback address mov rax, [rbx] - test rax, rax - mov rdi, [rsp+16*8] ; Get IRQ number + test rax, rax ; Check if it exists jz .skip.%[i] - call rax ; 2 Bytes (Op and Mod/RM) + ; Set RDI to IRQ number + mov rdi, [rsp+16*8] ; Get IRQ number + call rax ; Call .skip.%[i]: - add rbx, 8 + add rbx, 8 ; Next! %assign i i+1 %endrep + ; ACK mov rdi, [rsp+16*8] ; Get IRQ number cmp rdi, 8 mov al, 0x20 @@ -279,10 +292,12 @@ IrqCommon: out dx, al POP_GPR - add rsp, 16 - iret + add rsp, 8*2 + xchg bx, bx + iretq [extern Proc_Scheduler] +[global SchedulerIRQ] SchedulerIRQ: ; TODO: Find Current CPU PUSH_GPR @@ -297,11 +312,13 @@ SchedulerIRQ: ;POP_XMM ;POP_FPU POP_GPR - iret + add rsp, 8*2 + iretq [section .data] gIDT: - times 256 dd 0x00080000, 0x00000E00, 0, 0 ; 64-bit Interrupt Gate, CS = 0x8, IST0 + ; 64-bit Interrupt Gate, CS = 0x8, IST0 (Disabled) + times 256 dd 0x00080000, 0x00000E00, 0, 0 gIDTPtr: dw 256*16-1 dq gIDT diff --git a/Kernel/arch/x86_64/errors.c b/Kernel/arch/x86_64/errors.c index 605e9039..e66d550c 100644 --- a/Kernel/arch/x86_64/errors.c +++ b/Kernel/arch/x86_64/errors.c @@ -27,17 +27,19 @@ void Error_Handler(tRegs *Regs) Debug_KernelPanic(); - Warning("CPU Error %i - %s, Code: 0x%x", - Regs->IntNum, csaERROR_NAMES[Regs->IntNum], Regs->ErrorCode); - Warning(" CS:RIP = 0x%04x:%016x", Regs->CS, Regs->RIP); - Warning(" SS:RSP = 0x%04x:%016x", Regs->SS, Regs->RIP); - Warning(" RFLAGS = 0x%016x", Regs->RFlags); - Warning(" EAX %016x ECX %016x EDX %016x EBX %016x", + Log("CPU Error %x, Code: 0x%x", Regs->IntNum, Regs->ErrorCode); + Log(" - %s", csaERROR_NAMES[Regs->IntNum]); + Log(" CS:RIP = 0x%04x:%016x", Regs->CS, Regs->RIP); + Log(" SS:RSP = 0x%04x:%016x", Regs->SS, Regs->RSP); + Log(" RFLAGS = 0x%016x", Regs->RFlags); + + Log(" EAX %016x ECX %016x EDX %016x EBX %016x", Regs->RAX, Regs->RCX, Regs->RDX, Regs->RBX); - Warning(" ESP %016x EBP %016x ESI %016x EDI %016x", + Log(" ESP %016x EBP %016x ESI %016x EDI %016x", Regs->RSP, Regs->RBP, Regs->RSP, Regs->RDI); - - Warning(" FS %04x GS %04x", Regs->FS, Regs->GS); + Log(" R8 %016x R9 %016x R10 %016x R11 %016x", + Regs->R8, Regs->R9, Regs->R10, Regs->R11); + Log(" FS %04x GS %04x", Regs->FS, Regs->GS); // Control Registers diff --git a/Kernel/arch/x86_64/include/proc.h b/Kernel/arch/x86_64/include/proc.h index c92ce7e5..2672ca14 100644 --- a/Kernel/arch/x86_64/include/proc.h +++ b/Kernel/arch/x86_64/include/proc.h @@ -14,10 +14,12 @@ typedef struct { // MMX // FPU Uint FS, GS; + Uint RAX, RCX, RDX, RBX; Uint KernelRSP, RBP, RSI, RDI; Uint R8, R9, R10, R11; Uint R12, R13, R14, R15; + Uint IntNum, ErrorCode; Uint RIP, CS; Uint RFlags, RSP, SS;