| 1 | section .rodata |
| 2 | |
| 3 | invalid_idt: |
| 4 | dq 0, 0 |
| 5 | |
| 6 | section .text |
| 7 | |
| 8 | extern flush_irqs |
| 9 | |
| 10 | %macro push32 1 |
| 11 | sub rsp, 4 |
| 12 | mov dword [rsp], %1 |
| 13 | %endmacro |
| 14 | |
| 15 | extern gdt |
| 16 | |
| 17 | global common_spinup |
| 18 | bits 64 |
| 19 | common_spinup: |
| 20 | cli |
| 21 | |
| 22 | lgdt [rel gdt] |
| 23 | lidt [rel invalid_idt] |
| 24 | |
| 25 | lea rbx, [rel .reload_cs] |
| 26 | |
| 27 | push 0x28 |
| 28 | push rbx |
| 29 | retfq |
| 30 | .reload_cs: |
| 31 | mov eax, 0x30 |
| 32 | mov ds, eax |
| 33 | mov es, eax |
| 34 | mov fs, eax |
| 35 | mov gs, eax |
| 36 | mov ss, eax |
| 37 | |
| 38 | push r8 |
| 39 | push r9 |
| 40 | push rcx |
| 41 | push rdx |
| 42 | push rsi |
| 43 | push rdi |
| 44 | call flush_irqs |
| 45 | pop rdi |
| 46 | pop rsi |
| 47 | pop rdx |
| 48 | pop rcx |
| 49 | pop r9 |
| 50 | pop r8 |
| 51 | |
| 52 | mov rbp, rsp |
| 53 | |
| 54 | sub esi, 4 |
| 55 | jle .no_stack_args |
| 56 | |
| 57 | .push_stack_args: |
| 58 | dec esi |
| 59 | mov eax, [rbp + 8 + rsi*8] |
| 60 | push32 eax |
| 61 | test esi, esi |
| 62 | jnz .push_stack_args |
| 63 | |
| 64 | .no_stack_args: |
| 65 | push32 r9d |
| 66 | push32 r8d |
| 67 | push32 ecx |
| 68 | push32 edx |
| 69 | |
| 70 | lea rbx, [rel .go_32] |
| 71 | |
| 72 | push 0x18 |
| 73 | push rbx |
| 74 | retfq |
| 75 | |
| 76 | bits 32 |
| 77 | .go_32: |
| 78 | mov eax, 0x20 |
| 79 | mov ds, ax |
| 80 | mov es, ax |
| 81 | mov fs, ax |
| 82 | mov gs, ax |
| 83 | mov ss, ax |
| 84 | |
| 85 | xor eax, eax |
| 86 | lldt ax |
| 87 | |
| 88 | mov eax, 0x00000011 |
| 89 | mov cr0, eax |
| 90 | |
| 91 | mov ecx, 0xc0000080 |
| 92 | xor eax, eax |
| 93 | xor edx, edx |
| 94 | wrmsr |
| 95 | |
| 96 | xor eax, eax |
| 97 | mov cr4, eax |
| 98 | mov cr3, eax |
| 99 | |
| 100 | ; Clear TSS busy bit and load TR with base 0, limit 0 |
| 101 | sub esp, 8 |
| 102 | sgdt [esp] |
| 103 | mov eax, [esp + 2] |
| 104 | add esp, 8 |
| 105 | mov byte [eax + 0x3d], 0x89 |
| 106 | mov ax, 0x38 |
| 107 | ltr ax |
| 108 | |
| 109 | call edi |
| 110 | |
| 111 | section .note.GNU-stack noalloc noexec nowrite progbits |