full GDT, 64bt rewrite finished
This commit is contained in:
parent
6c243376ad
commit
2039495d5a
2
Makefile
2
Makefile
|
@ -60,7 +60,7 @@ obj/%.o: src/%.asm
|
|||
|
||||
# Other
|
||||
run: clean bin/shade.iso
|
||||
qemu-system-x86_64 -drive file=bin/shade.iso,index=0,media=disk,format=raw
|
||||
qemu-system-x86_64 -drive file=bin/shade.iso,index=0,media=disk,format=raw -d int -no-reboot
|
||||
|
||||
clean:
|
||||
rm -rf bin/*
|
||||
|
|
|
@ -16,7 +16,7 @@ entry_x86:
|
|||
call enable_paging
|
||||
|
||||
lgdt [gdt64.pointer]
|
||||
jmp gdt64.code_segment:entry_x64 ; Jump into 64 bit entry
|
||||
jmp gdt64.kernel_code_segment:entry_x64 ; Jump into 64 bit entry
|
||||
|
||||
hlt
|
||||
|
||||
|
@ -48,10 +48,10 @@ check_cpuid:
|
|||
jmp error
|
||||
|
||||
check_x64_supported:
|
||||
mov eax, 0x80000000 ; Magic code that i dont understand
|
||||
cpuid ; Magic code that i dont understand
|
||||
cmp eax, 0x80000001 ; Magic code that i dont undetstand
|
||||
jb .x64_unsupported ; Something went wrong so x64 isnt supported
|
||||
mov eax, 0x80000000
|
||||
cpuid
|
||||
cmp eax, 0x80000001
|
||||
jb .x64_unsupported ; CPUID extended feature set isnt even supported, def no x64
|
||||
|
||||
mov eax, 0x80000001 ; Set magic value 0x80000001 into EAX for cpuid
|
||||
cpuid ; Get "extended features list" from CPU info
|
||||
|
@ -131,11 +131,51 @@ stack_bottom:
|
|||
stack_top:
|
||||
|
||||
section .rodata
|
||||
; Access bits
|
||||
PRESENT equ 1 << 7
|
||||
NOT_SYS equ 1 << 4
|
||||
EXEC equ 1 << 3
|
||||
DC equ 1 << 2
|
||||
RW equ 1 << 1
|
||||
ACCESSED equ 1 << 0
|
||||
; Access bits: ring
|
||||
RING0 equ 0b00000000
|
||||
RING1 equ 0b00100000
|
||||
RING2 equ 0b01000000
|
||||
RING3 equ 0b01100000
|
||||
|
||||
; Flags bits
|
||||
GRAN_4K equ 1 << 7
|
||||
SZ_32 equ 1 << 6
|
||||
LONG_MODE equ 1 << 5
|
||||
|
||||
gdt64:
|
||||
dd 0 ; zero entry
|
||||
dd 0
|
||||
.code_segment: equ $ - gdt64
|
||||
dq (1 << 43) | (1 << 44) | (1 << 47) | (1 << 53) ; code segment
|
||||
.null: equ $ - gdt64
|
||||
dq 0 ; zero entry
|
||||
.kernel_code_segment: equ $ - gdt64
|
||||
dd 0xffff ; limit and base (low, bits 0-15)
|
||||
db 0 ; base (mid, bits 16-23)
|
||||
db PRESENT | RING0 | NOT_SYS | EXEC | RW ; access: 0b10011010
|
||||
db GRAN_4K | LONG_MODE | 0xf ; flags and limit (high, bits 16-19)
|
||||
db 0 ; base (high, bits 24-31)
|
||||
.kernel_data_segment: equ $ - gdt64
|
||||
dd 0xffff ; limit and base (low, bits 0-15)
|
||||
db 0 ; base (mid, bits 16-23)
|
||||
db PRESENT | RING0 | NOT_SYS | RW ; access: 0b10010010
|
||||
db GRAN_4K | SZ_32 | 0xf ; flags and limit (high, bits 16-19)
|
||||
db 0 ; base (high, bits 24-31)
|
||||
.userland_code_segment: equ $ - gdt64
|
||||
dd 0xffff ; limit and base (low, bits 0-15)
|
||||
db 0 ; base (mid, bits 16-23)
|
||||
db PRESENT | RING3 | NOT_SYS | EXEC | RW ; access: 0b11111010
|
||||
db GRAN_4K | LONG_MODE | 0xf ; flags and limit (high, bits 16-19)
|
||||
db 0 ; base (high, bits 24-31)
|
||||
.userland_data_segment: equ $ - gdt64
|
||||
dd 0xffff ; limit and base (low, bits 0-15)
|
||||
db 0 ; base (mid, bits 16-23)
|
||||
db PRESENT | RING3 | NOT_SYS | RW ; access: 0b11110010
|
||||
db GRAN_4K | SZ_32 | 0xf ; flags and limit (high, bits 16-19)
|
||||
db 0 ; base (high, bits 24-31)
|
||||
.pointer:
|
||||
dw $ - gdt64 - 1 ; length
|
||||
dq gdt64 ; address
|
|
@ -1,4 +1,4 @@
|
|||
set timeout=5
|
||||
set timeout=0
|
||||
set default=0
|
||||
|
||||
menuentry "shadeOS Development Build" {
|
||||
|
|
Loading…
Reference in New Issue