2022-08-20 15:13:06 +01:00
|
|
|
.section .text
|
|
|
|
|
2022-08-21 16:42:32 +01:00
|
|
|
.global trampoline
|
|
|
|
trampoline:
|
2022-08-28 08:30:17 +01:00
|
|
|
// Set new stack
|
|
|
|
mov %rdx, %rsp
|
|
|
|
|
2022-09-08 07:01:24 +01:00
|
|
|
// hlt
|
|
|
|
// hlt
|
|
|
|
|
2022-08-28 08:30:17 +01:00
|
|
|
// Load GDTR
|
2022-08-21 19:47:26 +01:00
|
|
|
lgdt (%rcx)
|
|
|
|
|
2022-08-28 08:30:17 +01:00
|
|
|
// Far jump to 32-bit compatibility mode
|
|
|
|
// AKA (set CS to CGDT.cs32)
|
2022-08-21 19:47:26 +01:00
|
|
|
pushq $0x30
|
2022-08-21 16:42:32 +01:00
|
|
|
addq $(1f - trampoline), %rax
|
2022-08-20 15:13:06 +01:00
|
|
|
pushq %rax
|
|
|
|
lretq
|
|
|
|
|
|
|
|
.code32
|
|
|
|
1:
|
|
|
|
|
2022-08-28 08:30:17 +01:00
|
|
|
// Set all data segments to CGDT.ds
|
2022-08-21 19:47:26 +01:00
|
|
|
mov $0x10, %eax
|
2022-08-20 15:13:06 +01:00
|
|
|
mov %eax, %ds
|
|
|
|
mov %eax, %es
|
|
|
|
mov %eax, %fs
|
|
|
|
mov %eax, %gs
|
|
|
|
mov %eax, %ss
|
|
|
|
|
2022-08-28 08:30:17 +01:00
|
|
|
// Disable paging
|
2022-08-20 15:13:06 +01:00
|
|
|
mov %cr0, %eax
|
|
|
|
btr $31, %eax
|
|
|
|
mov %eax, %cr0
|
|
|
|
|
2022-08-28 08:30:17 +01:00
|
|
|
// Disable LME and friends
|
2022-08-20 15:13:06 +01:00
|
|
|
mov $0xc0000080, %ecx
|
|
|
|
xor %eax, %eax
|
|
|
|
xor %edx, %edx
|
|
|
|
wrmsr
|
|
|
|
|
2022-08-28 08:30:17 +01:00
|
|
|
// Set CR0 to (PE | NE) AKA SYS_START_CR0
|
|
|
|
mov $0x11, %eax
|
|
|
|
mov %eax, %cr0
|
|
|
|
|
|
|
|
// Set flags to 0x02
|
|
|
|
pushl $0x02
|
|
|
|
popfl
|
2022-08-20 15:13:06 +01:00
|
|
|
|
2022-08-28 08:30:17 +01:00
|
|
|
jmp *%ebx
|
2022-08-20 15:13:06 +01:00
|
|
|
|
2022-08-21 16:42:32 +01:00
|
|
|
.global trampoline_end
|
|
|
|
trampoline_end:
|