2020-09-18 15:39:29 +03:00
|
|
|
bits 16
|
2022-07-28 10:35:59 +03:00
|
|
|
|
|
|
|
section .rodata
|
|
|
|
|
2022-07-28 23:23:12 +03:00
|
|
|
global smp_trampoline_start
|
|
|
|
smp_trampoline_start:
|
2020-09-18 15:39:29 +03:00
|
|
|
cli
|
|
|
|
cld
|
|
|
|
|
2021-03-04 07:15:20 +03:00
|
|
|
mov ebx, cs
|
|
|
|
shl ebx, 4
|
|
|
|
|
2022-07-28 23:23:12 +03:00
|
|
|
o32 lidt [cs:(invalid_idt - smp_trampoline_start)]
|
|
|
|
o32 lgdt [cs:(passed_info.gdtr - smp_trampoline_start)]
|
2020-09-18 15:39:29 +03:00
|
|
|
|
2022-07-28 23:23:12 +03:00
|
|
|
lea eax, [ebx + (.mode32 - smp_trampoline_start)]
|
|
|
|
mov [cs:(.farjmp_off - smp_trampoline_start)], eax
|
2020-09-18 15:39:29 +03:00
|
|
|
|
2021-05-20 02:16:39 +03:00
|
|
|
mov eax, 0x00000011
|
2020-09-18 15:39:29 +03:00
|
|
|
mov cr0, eax
|
2022-07-28 23:23:12 +03:00
|
|
|
o32 jmp far [cs:(.farjmp - smp_trampoline_start)]
|
2021-03-04 07:15:20 +03:00
|
|
|
|
|
|
|
.farjmp:
|
|
|
|
.farjmp_off: dd 0
|
|
|
|
.farjmp_seg: dd 0x18
|
2020-09-18 15:39:29 +03:00
|
|
|
|
|
|
|
bits 32
|
|
|
|
.mode32:
|
|
|
|
mov ax, 0x20
|
|
|
|
mov ds, ax
|
|
|
|
mov es, ax
|
|
|
|
mov fs, ax
|
|
|
|
mov gs, ax
|
|
|
|
mov ss, ax
|
|
|
|
|
2021-07-06 03:13:25 +03:00
|
|
|
xor eax, eax
|
|
|
|
lldt ax
|
|
|
|
|
2021-05-20 02:16:39 +03:00
|
|
|
xor eax, eax
|
|
|
|
mov cr4, eax
|
2020-09-18 15:39:29 +03:00
|
|
|
|
2023-08-22 02:38:48 +03:00
|
|
|
mov ecx, 0x277
|
2023-09-16 05:51:11 +03:00
|
|
|
mov eax, 0x00070406
|
|
|
|
mov edx, 0x00000105
|
2023-08-22 02:38:48 +03:00
|
|
|
wrmsr
|
|
|
|
|
2022-07-28 23:23:12 +03:00
|
|
|
test dword [ebx + (passed_info.target_mode - smp_trampoline_start)], (1 << 2)
|
2020-09-27 02:32:47 +03:00
|
|
|
jz .nox2apic
|
|
|
|
|
|
|
|
mov ecx, 0x1b
|
|
|
|
rdmsr
|
|
|
|
bts eax, 10
|
|
|
|
bts eax, 11
|
|
|
|
wrmsr
|
|
|
|
|
|
|
|
.nox2apic:
|
2022-07-28 23:23:12 +03:00
|
|
|
lea esp, [ebx + (temp_stack.top - smp_trampoline_start)]
|
2021-01-03 04:43:27 +03:00
|
|
|
|
2020-09-18 15:39:29 +03:00
|
|
|
mov eax, cr4
|
|
|
|
bts eax, 5
|
|
|
|
mov cr4, eax
|
|
|
|
|
2021-07-15 17:20:29 +03:00
|
|
|
mov ecx, 0xc0000080
|
|
|
|
mov eax, 0x100
|
|
|
|
xor edx, edx
|
|
|
|
wrmsr
|
|
|
|
|
2022-07-28 23:23:12 +03:00
|
|
|
test dword [ebx + (passed_info.target_mode - smp_trampoline_start)], (1 << 1)
|
2020-09-18 21:21:16 +03:00
|
|
|
jz .no5lv
|
|
|
|
|
|
|
|
mov eax, cr4
|
|
|
|
bts eax, 12
|
|
|
|
mov cr4, eax
|
|
|
|
|
|
|
|
.no5lv:
|
2022-07-28 23:23:12 +03:00
|
|
|
mov eax, dword [ebx + (passed_info.pagemap - smp_trampoline_start)]
|
2020-09-18 21:21:16 +03:00
|
|
|
mov cr3, eax
|
|
|
|
|
2020-09-18 15:39:29 +03:00
|
|
|
mov eax, cr0
|
|
|
|
bts eax, 31
|
|
|
|
mov cr0, eax
|
|
|
|
|
2022-07-28 23:23:12 +03:00
|
|
|
lea eax, [ebx + (.mode64 - smp_trampoline_start)]
|
2021-03-04 07:15:20 +03:00
|
|
|
push 0x28
|
|
|
|
push eax
|
|
|
|
retf
|
|
|
|
|
2020-09-18 15:39:29 +03:00
|
|
|
bits 64
|
|
|
|
.mode64:
|
|
|
|
mov ax, 0x30
|
|
|
|
mov ds, ax
|
|
|
|
mov es, ax
|
|
|
|
mov fs, ax
|
|
|
|
mov gs, ax
|
|
|
|
mov ss, ax
|
|
|
|
|
2021-07-15 17:20:29 +03:00
|
|
|
mov ebx, ebx
|
2022-07-28 23:23:12 +03:00
|
|
|
test dword [rbx + (passed_info.target_mode - smp_trampoline_start)], (1 << 3)
|
2021-07-15 17:20:29 +03:00
|
|
|
jz .nonx
|
|
|
|
|
|
|
|
mov ecx, 0xc0000080
|
|
|
|
rdmsr
|
|
|
|
bts eax, 11
|
|
|
|
wrmsr
|
|
|
|
|
|
|
|
.nonx:
|
2022-07-28 23:23:12 +03:00
|
|
|
test dword [rbx + (passed_info.target_mode - smp_trampoline_start)], (1 << 4)
|
2022-03-31 14:33:18 +03:00
|
|
|
jz .nowp
|
|
|
|
|
|
|
|
mov rax, cr0
|
|
|
|
bts rax, 16
|
|
|
|
mov cr0, rax
|
|
|
|
|
|
|
|
.nowp:
|
2022-07-28 23:23:12 +03:00
|
|
|
mov rax, qword [rbx + (passed_info.hhdm - smp_trampoline_start)]
|
|
|
|
add qword [rbx + (passed_info.gdtr - smp_trampoline_start) + 2], rax
|
|
|
|
lgdt [rbx + (passed_info.gdtr - smp_trampoline_start)]
|
2022-03-18 03:47:04 +03:00
|
|
|
|
2022-07-28 23:23:12 +03:00
|
|
|
lea rax, [rax + rbx + (parking64 - smp_trampoline_start)]
|
2022-03-18 03:47:04 +03:00
|
|
|
|
|
|
|
jmp rax
|
2020-09-18 15:39:29 +03:00
|
|
|
|
|
|
|
bits 64
|
|
|
|
parking64:
|
2021-03-04 07:15:20 +03:00
|
|
|
mov ebx, ebx
|
2022-07-28 23:23:12 +03:00
|
|
|
mov edi, dword [rbx + (passed_info.smp_info_struct - smp_trampoline_start)]
|
|
|
|
add rdi, qword [rbx + (passed_info.hhdm - smp_trampoline_start)]
|
2020-09-18 15:39:29 +03:00
|
|
|
mov eax, 1
|
2022-07-28 23:23:12 +03:00
|
|
|
lock xchg dword [rbx + (passed_info.booted_flag - smp_trampoline_start)], eax
|
2020-09-18 20:02:47 +03:00
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
.loop:
|
|
|
|
lock xadd qword [rdi + 16], rax
|
|
|
|
test rax, rax
|
|
|
|
jnz .out
|
|
|
|
pause
|
|
|
|
jmp .loop
|
|
|
|
|
|
|
|
.out:
|
|
|
|
mov rsp, qword [rdi + 8]
|
|
|
|
push 0
|
|
|
|
push rax
|
|
|
|
xor rax, rax
|
|
|
|
xor rbx, rbx
|
|
|
|
xor rcx, rcx
|
|
|
|
xor rdx, rdx
|
|
|
|
xor rsi, rsi
|
|
|
|
xor rbp, rbp
|
|
|
|
xor r8, r8
|
|
|
|
xor r9, r9
|
|
|
|
xor r10, r10
|
|
|
|
xor r11, r11
|
|
|
|
xor r12, r12
|
|
|
|
xor r13, r13
|
|
|
|
xor r14, r14
|
|
|
|
xor r15, r15
|
|
|
|
ret
|
2021-03-04 07:15:20 +03:00
|
|
|
|
|
|
|
align 16
|
|
|
|
temp_stack:
|
2021-05-19 09:29:21 +03:00
|
|
|
times 128 db 0
|
2021-03-04 07:15:20 +03:00
|
|
|
.top:
|
|
|
|
|
2021-05-19 09:29:21 +03:00
|
|
|
invalid_idt:
|
|
|
|
times 2 dq 0
|
|
|
|
|
2021-03-04 07:15:20 +03:00
|
|
|
align 16
|
|
|
|
passed_info:
|
|
|
|
.booted_flag db 0
|
|
|
|
.target_mode db 0
|
|
|
|
.pagemap dd 0
|
|
|
|
.smp_info_struct dd 0
|
|
|
|
.gdtr:
|
|
|
|
dw 0
|
2021-03-07 08:50:04 +03:00
|
|
|
dq 0
|
2022-03-18 03:47:04 +03:00
|
|
|
.hhdm:
|
|
|
|
dq 0
|
2022-07-28 10:35:59 +03:00
|
|
|
|
2022-07-28 23:23:12 +03:00
|
|
|
smp_trampoline_end:
|
|
|
|
|
|
|
|
global smp_trampoline_size
|
2022-07-28 23:30:26 +03:00
|
|
|
smp_trampoline_size dq smp_trampoline_end - smp_trampoline_start
|
2023-09-28 12:15:33 +03:00
|
|
|
|
|
|
|
section .note.GNU-stack noalloc noexec nowrite progbits
|