Advertisement
glowman554

Untitled

May 23rd, 2021
2,192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.     jmp 0:to_target(.start)
  14.  
  15. .start:
  16.  
  17.     xor ax, ax
  18.     mov ds, ax
  19.     mov es, ax
  20.     mov fs, ax
  21.     mov ss, ax
  22.     mov gs, ax
  23.     mov sp, 0x7c00
  24.  
  25.     in al, 0x92
  26.     or al, 2
  27.     out 0x92, al
  28.  
  29.  
  30.     mov eax, PML4
  31.     mov cr3, eax
  32.  
  33.     mov eax, cr4
  34.     or eax, (1 << 5)
  35.     mov cr4, eax
  36.  
  37.     mov ecx, 0xC0000080 ; EFER Model Specific Register
  38.     rdmsr
  39.     or eax, 1 << 8
  40.     wrmsr
  41.    
  42.     mov eax, 0x80000011
  43.     mov cr0, eax
  44.  
  45.     mov eax, default_gdt
  46.     lgdt [eax]
  47.  
  48.     jmp 0x8:to_target(ap_trampoline_long_mode)
  49.  
  50. [bits 64]
  51. ap_trampoline_long_mode:
  52.  
  53.     mov ax, 0x10
  54.     mov ds, ax
  55.     mov es, ax
  56.     mov fs, ax
  57.     mov gs, ax
  58.     mov ss, ax
  59.  
  60.     mov rsp, [to_target(ap_trampoline_data.stack_ptr)]
  61.  
  62.     mov [to_target(ap_trampoline_data.status)], byte 10
  63.  
  64.     jmp [to_target(ap_trampoline_data.entry)]
  65.  
  66.     jmp $
  67.  
  68. ap_trampoline_data:
  69.     .status: db 0
  70.     .pagetable: dq 0
  71.     .stack_ptr: dq 0
  72.     .entry: dq 0
  73.  
  74. times 4096 - ($ - $$) db 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement