Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [bits 16]
- [global ap_trampoline]
- [global ap_trampoline_data]
- [extern PML4]
- [extern default_gdt]
- %define to_target(addr) ((addr - ap_trampoline) + 0x8000)
- ap_trampoline:
- cli
- cld
- mov eax, cr4
- or eax, 1 << 5 ; PAE
- mov cr4, eax
- mov eax, [to_target(ap_trampoline_data.pagetable)]
- mov cr3, eax
- mov ecx, 0xC0000080 ; EFER Model Specific Register
- rdmsr
- or eax, 1 << 8
- wrmsr
- mov eax, cr0
- or eax, 0x80000001 ; Paging, Protected Mode
- mov cr0, eax
- mov [to_target(ap_trampoline_data.status)], byte 10
- lgdt [to_target(gdt_descriptor)]
- ;jmp $
- jmp codeseg:to_target(ap_trampoline_64)
- [bits 64]
- ap_trampoline_64:
- mov ax, 0x10
- mov ds, ax
- mov es, ax
- mov fs, ax
- mov gs, ax
- mov ss, ax
- mov [to_target(ap_trampoline_data.status)], byte 10
- jmp $
- ap_trampoline_data:
- .status: db 0
- .pagetable: dq 0
- .stack_ptr: dq 0
- .entry: dq 0
- gdt_nulldesc:
- dd 0
- dd 0
- gdt_codedesc:
- dw 0xFFFF ; Limit
- dw 0x0000 ; Base (low)
- db 0x00 ; Base (medium)
- db 10101111b ; Flags
- db 11001111b ; Flags + Upper Limit
- db 0x00 ; Base (high)
- gdt_datadesc:
- dw 0xFFFF
- dw 0x0000
- db 0x00
- db 10101111b
- db 11001111b
- db 0x00
- gdt_end:
- gdt_descriptor:
- gdt_size:
- dw gdt_end - gdt_nulldesc - 1
- dq to_target(gdt_nulldesc)
- codeseg equ gdt_codedesc - gdt_nulldesc
- times 4096 - ($ - $$) db 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement