(Mostly) entering long mode
This commit is contained in:
parent
11cdc51979
commit
0bfcd7afd2
1 changed files with 32 additions and 6 deletions
38
lboot.S
38
lboot.S
|
|
@ -37,8 +37,9 @@ _start: cli
|
||||||
call print
|
call print
|
||||||
call paging
|
call paging
|
||||||
|
|
||||||
mov $msg_fin, %si
|
mov $msg_long, %si
|
||||||
call print
|
call print
|
||||||
|
call long
|
||||||
|
|
||||||
jmp hang
|
jmp hang
|
||||||
|
|
||||||
|
|
@ -231,6 +232,35 @@ _prnext: mov $COM1+5, %dx
|
||||||
|
|
||||||
_prdone: ret
|
_prdone: ret
|
||||||
|
|
||||||
|
// long: Enter long mode
|
||||||
|
long:
|
||||||
|
// Enable PAE
|
||||||
|
mov %cr4, %eax
|
||||||
|
or $0b100000, %eax
|
||||||
|
mov %eax, %cr4
|
||||||
|
|
||||||
|
// Load page table
|
||||||
|
mov pml4_ptr, %eax
|
||||||
|
mov %eax, %cr3
|
||||||
|
|
||||||
|
// Enable long mode
|
||||||
|
.set IA32_EFER, 0xC0000080
|
||||||
|
mov $IA32_EFER, %ecx
|
||||||
|
rdmsr
|
||||||
|
or $0x100, %eax
|
||||||
|
wrmsr
|
||||||
|
|
||||||
|
// Enable protected mode + paging
|
||||||
|
mov %cr0, %eax
|
||||||
|
or $0x80000001, %eax
|
||||||
|
mov %eax, %cr0
|
||||||
|
|
||||||
|
ret
|
||||||
|
|
||||||
|
// hang: sleep indefinitely
|
||||||
|
hang: hlt
|
||||||
|
jmp hang
|
||||||
|
|
||||||
// gdt: Protected mode / Unreal mode 16-bit GDT
|
// gdt: Protected mode / Unreal mode 16-bit GDT
|
||||||
gdt: // entry 0: null descriptor
|
gdt: // entry 0: null descriptor
|
||||||
.word 0
|
.word 0
|
||||||
|
|
@ -257,10 +287,6 @@ gdt: // entry 0: null descriptor
|
||||||
gdt_ptr: .word gdt_size-1
|
gdt_ptr: .word gdt_size-1
|
||||||
.long gdt
|
.long gdt
|
||||||
|
|
||||||
// hang: sleep indefinitely
|
|
||||||
hang: hlt
|
|
||||||
jmp hang
|
|
||||||
|
|
||||||
// Messages to print
|
// Messages to print
|
||||||
msg_start: .asciz "Netboot via fernlader v1 ...\r\n"
|
msg_start: .asciz "Netboot via fernlader v1 ...\r\n"
|
||||||
msg_a20: .asciz " * Enabling A20\r\n"
|
msg_a20: .asciz " * Enabling A20\r\n"
|
||||||
|
|
@ -268,7 +294,7 @@ msg_unreal: .asciz " * Unreal Mode\r\n"
|
||||||
msg_getmap: .asciz " * Memory Map\r\n"
|
msg_getmap: .asciz " * Memory Map\r\n"
|
||||||
msg_mkheap: .asciz " * Making Space\r\n"
|
msg_mkheap: .asciz " * Making Space\r\n"
|
||||||
msg_paging: .asciz " * Paging\r\n"
|
msg_paging: .asciz " * Paging\r\n"
|
||||||
msg_fin: .asciz "Finished.\r\n"
|
msg_long: .asciz " * Long Mode\r\n"
|
||||||
msg_aerr: .asciz "panic: Out of heap space.\r\n"
|
msg_aerr: .asciz "panic: Out of heap space.\r\n"
|
||||||
|
|
||||||
heap_start: .long 0
|
heap_start: .long 0
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue