I get a triple fault when i try to enable Higher Half Kernel in my OS. Basically this is my linker.ld:
/* The bootloader will look at this image and start execution at the symbol
designated as the entry point. */
ENTRY(loader)
SECTIONS {
/* The kernel will live at 3GB + 1MB in the virtual
address space, which will be mapped to 1MB in the
physical address space. */
. = 0xC0100000;
.text ALIGN (0x1000) : AT(ADDR(.text) - 0xC0000000) {
*(.multiboot)
*(.text)
*(.rodata*)
}
.data ALIGN (0x1000) : AT(ADDR(.data) - 0xC0000000) {
start_ctors = .;
KEEP(*( .init_array ));
KEEP(*(SORT_BY_INIT_PRIORITY( .init_array.* )));
end_ctors = .;
*(.data)
}
.bss : AT(ADDR(.bss) - 0xC0000000) {
_sbss = .;
*(COMMON)
*(.bss)
_ebss = .;
}
}
boot.asm:
;Global MultiBoot Kernel Recongnzation
MAGIC equ 0x1badb002
FLAGS equ (1<<0 | 1<<1)
CHECKSUM equ -(MAGIC + FLAGS)
;Putting in object file
section .multiboot
dd MAGIC
dd FLAGS
dd CHECKSUM
section .data
KERNEL_VIRTUAL_BASE equ 0xC0000000 ; 3GB
KERNEL_PAGE_NUMBER equ (KERNEL_VIRTUAL_BASE >> 22) ; Page directory index of kernel's 4MB PTE.
align 0x1000
BootPageDirectory:
; This page directory entry identity-maps the first 4MB of the 32-bit physical address space.
; All bits are clear except the following:
; bit 7: PS The kernel page is 4MB.
; bit 1: RW The kernel page is read/write.
; bit 0: P The kernel page is present.
; This entry must be here -- otherwise the kernel will crash immediately after paging is
; enabled because it can't fetch the next instruction! It's ok to unmap this page later.
dd 0x00000083
times (KERNEL_PAGE_NUMBER - 1) dd 0 ; Pages before kernel space.
; This page directory entry defines a 4MB page containing the kernel.
dd 0x00000083
times (1024 - KERNEL_PAGE_NUMBER - 1) dd 0 ; Pages after the kernel image.
section .text
extern kernelMain
extern callConstructors
extern page_directory
extern pages_init
; reserve initial kernel stack space -- that's 16k.
STACKSIZE equ 0x4000
; setting up entry point for linker
loader equ (_loader - 0xC0000000)
global loader
_loader:
;Enable Paging START
; NOTE: Until paging is set up, the code must be position-independent and use physical
; addresses, not virtual ones!
mov ecx, (BootPageDirectory - KERNEL_VIRTUAL_BASE)
mov cr3, ecx ; Load Page Directory Base Register.
mov ecx, cr4
or ecx, 0x00000010 ; Set PSE bit in CR4 to enable 4MB pages.
mov cr4, ecx
mov ecx, cr0
or ecx, 0x80000000 ; Set PG bit in CR0 to enable paging.
mov cr0, ecx
lea ecx, [higherhalf]
jmp ecx
higherhalf:
; Unmap the identity-mapped first 4MB of physical address space. It should not be needed
; anymore.
mov dword [BootPageDirectory], 0
invlpg [0]
mov esp, stack ; set up the stack
call callConstructors
push eax
push ebx
call kernelMain
_eof:
cli
hlt
jmp _eof
section .bss
align 32
stack:
resb STACKSIZE ; reserve 16k stack on a uint64_t boundary
I tried debugging it and i get this in my qemu.log(cut down to last part of log, where check_exceptions occur):
Trace 0x7f99594ba2c0 [001023ed]
check_exception old: 0xffffffff new 0xe
0: v=0e e=0000 i=0 cpl=0 IP=0008:001023f9 pc=001023f9 SP=0010:00006f08 CR2=001023f9
EAX=00106000 EBX=80000011 ECX=001023e0 EDX=003ff003
ESI=00000000 EDI=00111000 EBP=00000000 ESP=00006f08
EIP=001023f9 EFL=00000086 [--S--P-] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
CS =0008 00000000 ffffffff 00cf9a00 DPL=0 CS32 [-R-]
SS =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
DS =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
FS =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
GS =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
LDT=0000 00000000 0000ffff 00008200 DPL=0 LDT
TR =0000 00000000 0000ffff 00008b00 DPL=0 TSS32-busy
GDT= 000cb268 00000027
IDT= 00000000 000003ff
CR0=80000011 CR2=001023f9 CR3=00106000 CR4=00000000
DR0=00000000 DR1=00000000 DR2=00000000 DR3=00000000
DR6=ffff0ff0 DR7=00000400
CCS=000003ff CCD=80000011 CCO=LOGICL
EFER=0000000000000000
check_exception old: 0xe new 0xd
1: v=08 e=0000 i=0 cpl=0 IP=0008:001023f9 pc=001023f9 SP=0010:00006f08 env->regs[R_EAX]=00106000
EAX=00106000 EBX=80000011 ECX=001023e0 EDX=003ff003
ESI=00000000 EDI=00111000 EBP=00000000 ESP=00006f08
EIP=001023f9 EFL=00000086 [--S--P-] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
CS =0008 00000000 ffffffff 00cf9a00 DPL=0 CS32 [-R-]
SS =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
DS =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
FS =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
GS =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
LDT=0000 00000000 0000ffff 00008200 DPL=0 LDT
TR =0000 00000000 0000ffff 00008b00 DPL=0 TSS32-busy
GDT= 000cb268 00000027
IDT= 00000000 000003ff
CR0=80000011 CR2=001023f9 CR3=00106000 CR4=00000000
DR0=00000000 DR1=00000000 DR2=00000000 DR3=00000000
DR6=ffff0ff0 DR7=00000400
CCS=000003ff CCD=80000011 CCO=LOGICL
EFER=0000000000000000
check_exception old: 0x8 new 0xd
Triple fault
If you want to see my full source code, to investigate this problem more here it is: https://github.com/amanuel2/OS_Mirror . Here is where i got the tutorial from: http://wiki.osdev.org/Higher_Half_x86_Bare_Bones . Help would be appreciated!
User contributions licensed under CC BY-SA 3.0