Advertisement
glowman554

Untitled

May 24th, 2021
617
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. [bits 16]
  2. [global ap_trampoline]
  3. [global ap_trampoline_data]
  4. [extern PML4]
  5. [extern default_gdt]
  6.  
  7. %define to_target(addr) ((addr - ap_trampoline) + 0x8000)
  8.  
  9. ap_trampoline:
  10. cli
  11. cld
  12.  
  13. mov eax, cr4
  14. or eax, 1 << 5 ; PAE
  15. mov cr4, eax
  16.  
  17. mov eax, [to_target(ap_trampoline_data.pagetable)]
  18. mov cr3, eax
  19.  
  20. mov ecx, 0xC0000080 ; EFER Model Specific Register
  21. rdmsr
  22. or eax, 1 << 8
  23. wrmsr
  24.  
  25. mov eax, cr0
  26. or eax, 0x80000001 ; Paging, Protected Mode
  27. mov cr0, eax
  28.  
  29. mov [to_target(ap_trampoline_data.status)], byte 10
  30.  
  31. lgdt [to_target(gdt_descriptor)]
  32.  
  33. ;jmp $
  34.  
  35. jmp codeseg:to_target(ap_trampoline_64)
  36.  
  37. [bits 64]
  38.  
  39. ap_trampoline_64:
  40. mov ax, 0x10
  41. mov ds, ax
  42. mov es, ax
  43. mov fs, ax
  44. mov gs, ax
  45. mov ss, ax
  46.  
  47. mov [to_target(ap_trampoline_data.status)], byte 10
  48.  
  49. jmp $
  50.  
  51. ap_trampoline_data:
  52. .status: db 0
  53. .pagetable: dq 0
  54. .stack_ptr: dq 0
  55. .entry: dq 0
  56.  
  57. gdt_nulldesc:
  58. dd 0
  59. dd 0
  60. gdt_codedesc:
  61. dw 0xFFFF ; Limit
  62. dw 0x0000 ; Base (low)
  63. db 0x00 ; Base (medium)
  64. db 10101111b ; Flags
  65. db 11001111b ; Flags + Upper Limit
  66. db 0x00 ; Base (high)
  67. gdt_datadesc:
  68. dw 0xFFFF
  69. dw 0x0000
  70. db 0x00
  71. db 10101111b
  72. db 11001111b
  73. db 0x00
  74.  
  75. gdt_end:
  76.  
  77. gdt_descriptor:
  78. gdt_size:
  79. dw gdt_end - gdt_nulldesc - 1
  80. dq to_target(gdt_nulldesc)
  81.  
  82. codeseg equ gdt_codedesc - gdt_nulldesc
  83.  
  84.  
  85. times 4096 - ($ - $$) db 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement