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

View File

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