Try to fix GDT; unsuccessful

This commit just existed because of a misunderstanding leading to the
belief that the GDT was finally working; it wasn't though.
This commit is contained in:
Eric-Paul Ickhorn 2024-06-18 15:41:54 +02:00
parent 4a835a0ece
commit 83eb29d55c
Signed by: epickh
GPG Key ID: 1358818BAA38B104
2 changed files with 30 additions and 41 deletions

View File

@ -8,13 +8,14 @@ UPPER_STACK_POINTER equ 0x100000
LOWER_STACK_POINTER equ (UPPER_STACK_POINTER - STACK_SIZE)
bits 16
org 0xa000
org 0x0000
entry:
mov ebx, LOWER_STACK_POINTER
mov ss, ebx
mov esp, STACK_SIZE
mov ebp, STACK_SIZE
push dx
cli
.check_a20:
push ebp
@ -25,32 +26,20 @@ entry:
cmp eax, 1
je .a20_is_enabled
cli
hlt
.a20_is_enabled:
; jmp .flat_gdt_loaded
; Reset Display
mov ah, 0x00
mov al, 0x03
int 0x10
; mov ah, 0x05
; mov al, 0
; int 0x10
mov ah, 0x0b
mov bh, 0x00
mov bl, 0
int 0x10
push ebp
mov ebp, esp
call setup_drivers
mov esp, ebp
pop ebp
mov edi, ebp
mov esi, esp
push ebp
@ -63,13 +52,11 @@ entry:
mov ebp, edi
mov esp, esi
mov ebx, some_text
push ebp
mov ebp, esp
push dword ebx
call dword write_text
mov esp, ebp
pop ebp
; push ebp
; mov ebp, esp
; call setup_drivers
; mov esp, ebp
; pop ebp
cli
hlt

View File

@ -5,7 +5,7 @@ GDT_ENTRY_SIZE equ 8
db "gdt_set_segment"
; [Furthest from EBP]
; 3. Bool (Lowest Address) Task State Segment (1) or Code/Data (0)
; 3. Bool (Lowest Address) Task State Segment (0) or Code/Data (1)
; Bool (Second-Lowest) Executable (1) or Not (0)
; Bool (Second-Highest) Stack (1) or Heap (0) Page
; Bool (Highest Address) Readable AND Writeable (1) or only what's necessary (0)
@ -19,7 +19,6 @@ gdt_set_segment:
sub esp, 64
mov esi, esp
mov [esi + (64 - 4)], eax
mov [esi + (64 - 8)], ebx
mov [esi + (64 - 12)], ecx
mov [esi + (64 - 16)], edx
@ -45,12 +44,13 @@ gdt_set_segment:
; [Lowest]
xor al, al
cmp [ebp - 16], byte 0
or al, (1 << 7) ; Present-Bit
cmp [ebp - 15], byte 0
je .after_task_segment_bit_setter
or al, (1 << 4)
.after_task_segment_bit_setter:
cmp [ebp - 15], byte 0
cmp [ebp - 14], byte 0
je .after_executable_bit_setter
or al, (1 << 3)
.after_executable_bit_setter:
@ -69,7 +69,7 @@ gdt_set_segment:
; [Highest]
; 3. Address and Size Granularity (Bytes: 0, Pages: 1)
; 2. 16-Bit or 32-Bit selector (0: 16-Bit, 1: 32-Bit)
; 1. Long Mode / 64-Bit (
; 1. Long Mode / 64-Bit
; 0. Reserved, should be 0
; [Lowest]
mov ah, (0b00001100 << 4)
@ -79,14 +79,14 @@ gdt_set_segment:
mov ecx, [ebp - 12]
shr ecx, 16
and ecx, 0b00001111
or al, cl
or ah, cl
; Store the Access Byte and the Flags into the entry.
mov ebx, [esi]
mov [ebx + 5], al ; Access Byte
mov [ebx + 6], ah ; Flags + Limit
mov eax, [ebp - 8]
mov eax, [ebp - 8] ; Base Address
mov [ebx + 2], ax
shr eax, 16
mov [ebx + 3], al
@ -136,12 +136,12 @@ load_flat_gdt:
push ebp
mov ebp, esp
push dword 1
push dword 0xa00
push dword 0x0a00
push dword 0xfffff
push byte 1
push byte 0
push byte 1
push byte 0
push byte 1
call gdt_set_segment
mov esp, ebp
pop ebp
@ -155,7 +155,7 @@ load_flat_gdt:
push byte 1
push byte 1
push byte 0
push byte 0
push byte 1
call gdt_set_segment
mov esp, ebp
pop ebp
@ -169,34 +169,29 @@ load_flat_gdt:
push byte 1
push byte 0
push byte 1
push byte 0
push byte 1
call gdt_set_segment
mov esp, ebp
pop ebp
; Write the GDT Descriptor
cli
mov [esi + 10], dword GDT_MEMORY_AREA
mov [esi + 8], word 31
mov eax, esi
add ebx, 8
lgdt [ebx]
sti
lgdt [.gdtr]
mov ax, (3 << 4)
mov ax, (3 << 3)
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ax, (2 << 4)
mov ax, (2 << 3)
mov ss, ax
jmp dword (1 << 3):.epilog
.epilog:
mov eax, cr0
or eax, 1
mov cr0, eax
jmp dword (1 << 4):.epilog
.epilog:
mov ebx, [esi + (64 - 8)]
mov ecx, [esi + (64 - 12)]
mov edx, [esi + (64 - 16)]
@ -204,3 +199,10 @@ load_flat_gdt:
mov esi, [esi + 20]
jmp esi
align 16
.gdtr:
.gdtr.length:
dw 31
.gdtr.address:
dd GDT_MEMORY_AREA