Guest User

GDT assembly code

a guest
Sep 26th, 2016
492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. global _gdt_install
  2.  
  3. _gdt_install:
  4.     cli
  5.     lgdt [gdt]          ; load GDT into GDTR
  6.     mov ax, 0x10
  7.     mov ds, ax
  8.     mov es, ax
  9.     mov fs, ax
  10.     mov gs, ax
  11.     ;mov ss, ax
  12.    
  13.     jmp 0x08:return
  14.  
  15. return:
  16.     ret
  17.  
  18. ; null descriptor
  19.  
  20. gdt_start: 
  21.     dd 0x00
  22.     dd 0x00
  23.  
  24. ; code descriptor: indicates readable and writable segment, and is at ring 0
  25.    
  26.     dw 0xFFFF       ; limit low: segment limit; each segment is 64K
  27.     dw 0x00         ; base low (starting address of segment): code selector can access every byte between 0x00 and 0xFFFF
  28.     db 0x00         ; base middle and base low is 3 bytes (bit 0-23 of base address)
  29.     db 10011010b    ; access byte: bits 40-47 (change bits 40 and 47 when using virtual memory)
  30.     db 11001111b    ; granularity bit: bits 48-55
  31.     db 0x00         ; base high (bits 24-32 of the base address)
  32.  
  33. ; same as code descriptor, except for bit 43, indicating this is a code descriptor
  34.  
  35.     dw 0xFFFF       ; limit low
  36.     dw 0x00         ; base low
  37.     db 0x00         ; base middle
  38.     db 10011010b    ; access byte
  39.     db 11001111b    ; granularity byte
  40.     db 0x00         ; base high
  41.  
  42. gdt_end:
  43.  
  44. gdt:
  45.     dw gdt_end - gdt_start - 1 ; limit (size of GDT)
  46.     dd gdt_start               ; base address of GDT
Advertisement
Add Comment
Please, Sign In to add comment