gdt.asm 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. ; GDT
  2. gdt_start:
  3. gdt_null:
  4. dd 0x0 ; the mandatory null-descriptor
  5. dd 0x0
  6. gdt_code: ; code segment of descriptor
  7. dw 0xFFFF ; Limit (bits 0-15)
  8. dw 0x0 ; Base (bits 0-15)
  9. db 0x0 ; Base (bits 16-23
  10. ; 1st flags: (present)1, (privilege)00, (descriptor type)1 -> 1001b
  11. ; type flags: (code)1, (conforming)0, (readable)1, (accessed)0 -> 1010b
  12. ; 2nd flags: (granularity)1, (32-bit default)1, (64-bit seg)0, (AVL)0 -> 1100b
  13. db 10011010b ; 1st flags and type flags
  14. db 11001111b ; 2nd flags and Limit (bits 16-19)
  15. db 0x0 ; Base (bits 24-31)
  16. gdt_data:
  17. ; type flags: (code)0, (expand down)0, (writable)1, (accessed)0 -> 0010b
  18. dw 0xFFFF ; Limit (bits 0-15)
  19. dw 0x0 ; Base (bits 0-15)
  20. db 0x0 ; Base (bits 16-23)
  21. db 10010010b ; 1st flags and type flags
  22. db 11001111b ; 2nd flags and Limit (bits 16-19)
  23. db 0x0 ; Base (bits 24-31)
  24. gdt_end: ; for calculating size of the gdt
  25. gdt_descriptor:
  26. dw gdt_end - gdt_start - 1 ; size of our GDT, always decrement true size by one
  27. dd gdt_start ; start address of our GDT
  28. ;;;
  29. ; Constants used for GDT segment offsets
  30. GDT_CODE_SEG: equ gdt_code - gdt_start
  31. GDT_DATA_SEG: equ gdt_data - gdt_start