LONG MODE MULTIBOOT WORKS gsp!
This commit is contained in:
parent
d70d150da2
commit
530475e5f5
|
@ -38,7 +38,7 @@ _start:
|
||||||
mov es, ax ; And es because it is jealous
|
mov es, ax ; And es because it is jealous
|
||||||
;mov [Bootdrv], dl
|
;mov [Bootdrv], dl
|
||||||
xor dl, dl
|
xor dl, dl
|
||||||
jmp 0x0000:main ; pas sûr
|
jmp 0x0000:_loader ; pas sûr
|
||||||
|
|
||||||
;; Magnificent multiboot header for GRUB ------------------------------------ ;;
|
;; Magnificent multiboot header for GRUB ------------------------------------ ;;
|
||||||
MB_header:
|
MB_header:
|
||||||
|
@ -60,7 +60,7 @@ MB_start:
|
||||||
push eax ; 2nd argument is magic number
|
push eax ; 2nd argument is magic number
|
||||||
push ebx ; 1st argument multiboot info pointer
|
push ebx ; 1st argument multiboot info pointer
|
||||||
mov ecx, eax
|
mov ecx, eax
|
||||||
call main
|
call _loader
|
||||||
add esp, 8 ; Cleanup arguments "A la MIPS"
|
add esp, 8 ; Cleanup arguments "A la MIPS"
|
||||||
jmp Die ; Aufwiedersehen
|
jmp Die ; Aufwiedersehen
|
||||||
|
|
||||||
|
@ -79,42 +79,39 @@ Die:
|
||||||
jmp $
|
jmp $
|
||||||
|
|
||||||
;; THE CODE ----------------------------------------------------------------- ;;
|
;; THE CODE ----------------------------------------------------------------- ;;
|
||||||
main:
|
|
||||||
call MB_check
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------- ;
|
||||||
|
; _loader ;
|
||||||
|
; ;
|
||||||
|
; This is the function that initiates the launch of OS/K. It verifies that ;
|
||||||
|
; Grub has properly loaded this loader and makes the appropriate setup so ;
|
||||||
|
; that the kernel will work properly ;
|
||||||
|
; ;
|
||||||
|
; Why this original design ? Because it works well and prevent us to cause ;
|
||||||
|
; triple faults by aligment error or too long jumps (yup, it can be a problem);
|
||||||
|
; ;
|
||||||
|
; ---------------------------------------------------------------------------- ;
|
||||||
|
_loader:
|
||||||
|
jmp lbegin
|
||||||
|
|
||||||
|
%include "boot/loader/multiboot/check.inc"
|
||||||
|
lbegin:
|
||||||
|
call MB_check
|
||||||
|
jmp lnext
|
||||||
|
|
||||||
|
%include "boot/loader/cpu/cpuid.inc"
|
||||||
|
lnext:
|
||||||
call Check_cpuid
|
call Check_cpuid
|
||||||
call Is64Bits
|
call Is64Bits
|
||||||
|
jmp lnext2
|
||||||
|
|
||||||
|
%include "boot/loader/mem/structures.inc"
|
||||||
|
lnext2:
|
||||||
call Setup_paging
|
call Setup_paging
|
||||||
|
jmp lnext3
|
||||||
|
%include "boot/loader/mem/management.inc"
|
||||||
|
|
||||||
;; Registering paging
|
lnext3:
|
||||||
mov eax, PML4_table
|
|
||||||
mov cr3, eax ; Load PML4 to cr3
|
|
||||||
|
|
||||||
mov eax, cr4
|
|
||||||
or eax, 1 << 5
|
|
||||||
mov cr4, eax ; Enable PAE
|
|
||||||
|
|
||||||
;; Activate long mode
|
|
||||||
mov ecx, 0xC0000080 ; address of MSR
|
|
||||||
rdmsr ; read MSR
|
|
||||||
or eax, 1 << 8 ; LME = 1. (Long Mode Enable)
|
|
||||||
wrmsr ; write MSR
|
|
||||||
|
|
||||||
;; Enable paging
|
|
||||||
mov eax, cr0
|
|
||||||
or eax, 1 << 31 ; make MSR bit 31 (PG = Paging) to 1 :
|
|
||||||
; |1|000000000000000000000000000000
|
|
||||||
; |
|
|
||||||
; `------ Paging bit
|
|
||||||
mov cr0, eax
|
|
||||||
|
|
||||||
mov dword [0xb8000], 0x2f4b2f4f
|
mov dword [0xb8000], 0x2f4b2f4f
|
||||||
ret
|
ret
|
||||||
|
|
||||||
;; INCLUDES ----------------------------------------------------------------- ;;
|
|
||||||
%include "boot/loader/cpu/cpuid.inc"
|
|
||||||
%include "boot/loader/multiboot/check.inc"
|
|
||||||
%include "boot/loader/mem/structures.inc"
|
|
||||||
%include "boot/loader/mem/management.inc"
|
|
||||||
|
|
||||||
|
|
|
@ -52,3 +52,31 @@ Setup_paging:
|
||||||
jne .map_p2_table ; else map the next entry
|
jne .map_p2_table ; else map the next entry
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------- ;
|
||||||
|
; Enable long mode and paging ;
|
||||||
|
; ---------------------------------------------------------------------------- ;
|
||||||
|
Go64:
|
||||||
|
;; Registering paging
|
||||||
|
mov eax, PML4_table
|
||||||
|
mov cr3, eax ; Load PML4 to cr3
|
||||||
|
|
||||||
|
mov eax, cr4
|
||||||
|
or eax, 1 << 5
|
||||||
|
mov cr4, eax ; Enable PAE
|
||||||
|
|
||||||
|
;; Activate long mode
|
||||||
|
mov ecx, 0xC0000080 ; address of MSR
|
||||||
|
rdmsr ; read MSR
|
||||||
|
or eax, 1 << 8 ; LME = 1. (Long Mode Enable)
|
||||||
|
wrmsr ; write MSR
|
||||||
|
|
||||||
|
;; Enable paging
|
||||||
|
mov eax, cr0
|
||||||
|
or eax, 1 << 31 ; make MSR bit 31 (PG = Paging) to 1 :
|
||||||
|
; |1|000000000000000000000000000000
|
||||||
|
; |
|
||||||
|
; `------ Paging bit
|
||||||
|
mov cr0, eax
|
||||||
|
|
||||||
|
ret
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue