diff options
Diffstat (limited to 'arch')
-rw-r--r-- | arch/x86/boot/bootsect.s | 38 |
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" |