summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMarvin Borner2021-07-05 12:59:37 +0200
committerMarvin Borner2021-07-05 12:59:37 +0200
commit832a5046b42f53f7ab329942a862e1b4c0a6f6db (patch)
tree33133b077696710b6db8a2689f3dce06d1b98c73
parent0c4427cada337b4a80e1ec0a16be08b75412321b (diff)
Reduced GDT magic numbers
-rw-r--r--src/entry/bootsector.asm9
-rw-r--r--src/entry/definitions.asm12
2 files changed, 17 insertions, 4 deletions
diff --git a/src/entry/bootsector.asm b/src/entry/bootsector.asm
index 1beb850..c3532ee 100644
--- a/src/entry/bootsector.asm
+++ b/src/entry/bootsector.asm
@@ -139,6 +139,7 @@ dap: ; Disk Address Packet
dd 0 ; More storage bytes
; Global Descriptor Table (GDT)
+; There are better explanations for the constants in definitions.asm
gdt:
dw .size - 1 + 8 ; GDT size
dd .start - 8 ; GDT start address
@@ -147,16 +148,16 @@ gdt:
dw 0xffff ; Limit
dw 0x0000 ; Base (low 16 bits)
db 0x00 ; Base (mid 8 bits)
- db 10011010b ; Access
- db 11001111b ; Granularity
+ db GDT_PRESENT | GDT_DESCRIPTOR | GDT_EXECUTABLE | GDT_READWRITE ; Access
+ db GDT_GRANULARITY | GDT_SIZE | 0xf ; Granularity
db 0x00 ; Base (high 8 bits)
; Data
dw 0xffff ; Limit
dw 0x0000 ; Base (low 16 bits)
db 0x00 ; Base (mid 8 bits)
- db 10010010b ; Access
- db 11001111b ; Granularity
+ db GDT_PRESENT | GDT_DESCRIPTOR | GDT_READWRITE ; Access; Data isn't executable
+ db GDT_GRANULARITY | GDT_SIZE | 0xf ; Granularity
db 0x00 ; Base (high 8 bits)
.end:
.size: equ .end - .start
diff --git a/src/entry/definitions.asm b/src/entry/definitions.asm
index dcaa141..019eefa 100644
--- a/src/entry/definitions.asm
+++ b/src/entry/definitions.asm
@@ -24,3 +24,15 @@
%define DISK_EXT_CHECK_REQ 0x55aa ; First extension check signature (request)
%define DISK_EXT_CHECK_RESP 0xaa55 ; Second extension check signature (response)
%define DISK_READ 0x42 ; Disk extended read command
+
+; GDT constants (bitmap)
+%define GDT_MAX_LIMIT 0xffff ; I just use the max limit lel
+%define GDT_PRESENT 0b10000000 ; Is present
+%define GDT_RING3 0b01100000 ; Privilege level 3
+%define GDT_DESCRIPTOR 0b00010000 ; Descriptor type, set for code/data
+%define GDT_EXECUTABLE 0b00001000 ; Can be executed
+%define GDT_READWRITE 0b00000010 ; Read/write access for code/data
+%define GDT_ACCESSED 0b00000001 ; Whether segment is accessible
+%define GDT_GRANULARITY 0x80 ; Page granularity (4KiB)
+%define GDT_SIZE 0x40 ; Use 32 bit selectors
+%define GDT_DATA_OFFSET 0x10 ; Offset to GDT data segment