summaryrefslogtreecommitdiffstats
path: root/arch/x86/boot
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2021-08-26 17:39:31 +0000
committerJoursoir <chat@joursoir.net>2021-08-26 17:48:49 +0000
commit5b8595c6c63fcc12fbf8e1ad32986b7e59bb3d75 (patch)
tree3ddcb6a33723163ef434769ae9f7447c479c01e5 /arch/x86/boot
parent279f7f2ae76e14fbf3d55a330df4e607f1de03f0 (diff)
downloadmfsos-5b8595c6c63fcc12fbf8e1ad32986b7e59bb3d75.tar.gz
mfsos-5b8595c6c63fcc12fbf8e1ad32986b7e59bb3d75.tar.bz2
mfsos-5b8595c6c63fcc12fbf8e1ad32986b7e59bb3d75.zip
x86/boot/bootsect: add a filled GDT structure
Diffstat (limited to 'arch/x86/boot')
-rw-r--r--arch/x86/boot/bootsect.s38
1 files changed, 38 insertions, 0 deletions
diff --git a/arch/x86/boot/bootsect.s b/arch/x86/boot/bootsect.s
index 6f90746..eedf3bd 100644
--- a/arch/x86/boot/bootsect.s
+++ b/arch/x86/boot/bootsect.s
@@ -4,6 +4,10 @@
.include "bios.inc"
+# Define some constants for the GDT segment descriptor offsets
+.set CODESEG, gdt_code - gdt_start
+.set DATASEG, gdt_data - gdt_start
+
.set MAGIC, 0xAA55
.section .text.bootentry # Code that will start executing at
@@ -48,7 +52,41 @@ disk_error:
BIOS_PRINT $disk_error_msg
jmp .
+# Global Descriptor Table (contains 8-byte entries)
+gdt_start:
+gdt_null: # The mandatory null descriptor
+ .quad 0x0
+
+gdt_code: # The code segment descriptor
+ # Base = 0x0, limit = 0xfffff
+ # 1st flags: (present)1 (privilege)00 (descriptor type)1 -> b1001
+ # Type flags: (code)1 (conforming)0 (readable)1 (accessed)0 -> b1010
+ # 2nd flags: (granularity)1 (size)1 (64-bit seg)0 (AVL)0 -> b1100
+ .word 0xffff # Limit (bits 0-15)
+ .word 0x0 # Base (bits 0-15)
+ .byte 0x0 # Base (bits 16-23)
+ .byte 0b10011010 # 1st flags, type flags
+ .byte 0b11001111 # 2nd flags, limit (bits 16-19)
+ .byte 0x0 # Base (bits 24-31)
+
+gdt_data: # the data segment descriptor
+ # Same as code segment except for the type flags:
+ # Type flags: (code)0 (direction)0 (writable)1, (accessed)0 -> b0010
+ # P.S: direction bit: 0 the segment grows up
+ .word 0xffff # Limit (bits 0-15)
+ .word 0x0 # Base (bits 0-15)
+ .byte 0x0 # Base (bits 16-23)
+ .byte 0b10010010 # 1st flags, type flags
+ .byte 0b11001111 # 2nd flags, limit (bits 16-19)
+ .byte 0x0 # Base (bits 24-31)
+gdt_end:
+
# Global variables
+gdt_descriptor:
+ # Size of GDT, always less one of the true size
+ .word gdt_end - gdt_start - 1
+ .long gdt_start # Start address of our GDT
+
boot_real_mode_msg:
.asciz "Started mfsos in 16-bit real mode\r\n"