From: John Hodge Date: Thu, 27 May 2010 13:02:51 +0000 (+0800) Subject: Working on 64-bit IDT X-Git-Tag: rel0.06~175 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=c6061d381c0af2dcc7c971347d036dc17399887a;p=tpg%2Facess2.git Working on 64-bit IDT --- diff --git a/Kernel/Makefile.BuildNum b/Kernel/Makefile.BuildNum index 165c6a4b..20bdebc4 100644 --- a/Kernel/Makefile.BuildNum +++ b/Kernel/Makefile.BuildNum @@ -1 +1 @@ -BUILD_NUM = 2212 +BUILD_NUM = 2216 diff --git a/Kernel/arch/x86/main.c b/Kernel/arch/x86/main.c index 6baec034..34cc4146 100644 --- a/Kernel/arch/x86/main.c +++ b/Kernel/arch/x86/main.c @@ -50,7 +50,7 @@ int kmain(Uint MbMagic, void *MbInfoPtr) // Set up non-boot info dependent stuff Desctab_Install(); // Set up GDT and IDT - MM_PreinitVirtual(); // Initialise vital mappings + MM_PreinitVirtual(); // Initialise virtual mappings switch(MbMagic) { diff --git a/Kernel/arch/x86_64/desctab.asm b/Kernel/arch/x86_64/desctab.asm index de606ea6..05e283d6 100644 --- a/Kernel/arch/x86_64/desctab.asm +++ b/Kernel/arch/x86_64/desctab.asm @@ -47,8 +47,53 @@ MM_LOCALAPIC equ 0xFFFFFD0000000000 %endmacro [section .text] +[global Desctab_Init] Desctab_Init: - ; Install IRQ Handlers + ; Install IDT + mov rax, gIDTPtr + lidt [rax] + + ; Save to make following instructions smaller + mov rdi, gIDT + + ; Set an IDT entry to a callback + %macro SETIDT 2 + mov rax, %2 + mov WORD [rdi + %1*16], ax + shr rax, 16 + mov WORD [rdi + %1*16+6], ax + shr rax, 16 + mov DWORD [rdi+%1*16+8], eax + ; Enable + mov ax, WORD [rdi + %1*16 + 4] + or ax, 0x8000 + mov WORD [rdi + %1*16 + 4], ax + %endmacro + + ; Install error handlers + %macro SETISR 1 + SETIDT %1, Isr%1 + %endmacro + + %assign i 0 + %rep 32 + SETISR i + %assign i i+1 + %endrep + + ; Install IRQs + %macro SETIRQ 2 + SETIDT %2, Irq%1 + %endmacro + + %assign i 0 + %rep 16 + SETIRQ i, 0xF0+i + %assign i i+1 + %endrep + + ; Remap PIC + ret ; int IRQ_AddHandler(int IRQ, void (*Handler)(int IRQ)) @@ -94,18 +139,55 @@ IRQ_AddHandler: .ret: ret -%macro DEFERR 1 +%macro ISR_NOERRNO 1 Isr%1: push 0 push %1 jmp ErrorCommon %endmacro -%macro DEFERRNO 1 +%macro ISR_ERRNO 1 Isr%1: push %1 jmp ErrorCommon %endmacro +ISR_NOERRNO 0; 0: Divide By Zero Exception +ISR_NOERRNO 1; 1: Debug Exception +ISR_NOERRNO 2; 2: Non Maskable Interrupt Exception +ISR_NOERRNO 3; 3: Int 3 Exception +ISR_NOERRNO 4; 4: INTO Exception +ISR_NOERRNO 5; 5: Out of Bounds Exception +ISR_NOERRNO 6; 6: Invalid Opcode Exception +ISR_NOERRNO 7; 7: Coprocessor Not Available Exception +ISR_ERRNO 8; 8: Double Fault Exception (With Error Code!) +ISR_NOERRNO 9; 9: Coprocessor Segment Overrun Exception +ISR_ERRNO 10; 10: Bad TSS Exception (With Error Code!) +ISR_ERRNO 11; 11: Segment Not Present Exception (With Error Code!) +ISR_ERRNO 12; 12: Stack Fault Exception (With Error Code!) +ISR_ERRNO 13; 13: General Protection Fault Exception (With Error Code!) +ISR_ERRNO 14; 14: Page Fault Exception (With Error Code!) +ISR_NOERRNO 15; 15: Reserved Exception +ISR_NOERRNO 16; 16: Floating Point Exception +ISR_NOERRNO 17; 17: Alignment Check Exception +ISR_NOERRNO 18; 18: Machine Check Exception +ISR_NOERRNO 19; 19: Reserved +ISR_NOERRNO 20; 20: Reserved +ISR_NOERRNO 21; 21: Reserved +ISR_NOERRNO 22; 22: Reserved +ISR_NOERRNO 23; 23: Reserved +ISR_NOERRNO 24; 24: Reserved +ISR_NOERRNO 25; 25: Reserved +ISR_NOERRNO 26; 26: Reserved +ISR_NOERRNO 27; 27: Reserved +ISR_NOERRNO 28; 28: Reserved +ISR_NOERRNO 29; 29: Reserved +ISR_NOERRNO 30; 30: Reserved +ISR_NOERRNO 31; 31: Reserved + +ErrorCommon: + add rsp, 2*8 + iret + %macro DEFIRQ 1 Irq%1: push 0 @@ -113,6 +195,12 @@ Irq%1: jmp IrqCommon %endmacro +%assign i 0 +%rep 16 +DEFIRQ i +%assign i i+1 +%endrep + IrqCommon: PUSH_GPR @@ -166,7 +254,10 @@ SchedulerIRQ: [section .data] gIDT: - times 256 dw 0x00080000, 0x00008E00, 0, 0 ; 64-bit Interrupt Gate, CS = 0x8, IST0 + times 256 dd 0x00080000, 0x00008E00, 0, 0 ; 64-bit Interrupt Gate, CS = 0x8, IST0 +gIDTPtr: + dw 256*16-1 + dq gIDT gaIRQ_Handlers: times 16*NUM_IRQ_CALLBACKS dq 0 diff --git a/Kernel/arch/x86_64/main.c b/Kernel/arch/x86_64/main.c index 60d5cf08..6a1520a2 100644 --- a/Kernel/arch/x86_64/main.c +++ b/Kernel/arch/x86_64/main.c @@ -3,12 +3,24 @@ */ #include +// === IMPORTS === +extern void Desctab_Init(void); +extern void MM_InitVirt(void); + +// === PROTOTYPES === + // === GLOBALS == // === CODE === void kmain(Uint MbMagic, void *MbInfoPtr) { + *(Uint16*)(0xB8000) = 0x1F00|'A'; + + Desctab_Init(); + MM_InitVirt(); + for(;;) + __asm__ __volatile__ ("hlt"); } void Arch_LoadBootModules(void) diff --git a/Kernel/arch/x86_64/start64.asm b/Kernel/arch/x86_64/start64.asm index 699c7931..c98afdbd 100644 --- a/Kernel/arch/x86_64/start64.asm +++ b/Kernel/arch/x86_64/start64.asm @@ -3,6 +3,8 @@ ; [bits 64] +[extern kmain] + [section .text] [global start64] start64: @@ -28,6 +30,8 @@ start64: mov rsp, gInitialKernelStack ; Call main + call kmain + cli .hlt: hlt