# );\r
#------------------------------------------------------------------------------\r
ASM_PFX(JumpToKernel):\r
+\r
+ // Set up for executing kernel. BP in %esi, entry point on the stack\r
+ // (64-bit when the 'ret' will use it as 32-bit, but we're little-endian)\r
movq %rdx, %rsi\r
- addq $0x200, %rcx\r
- callq %rcx\r
+ pushq %rcx\r
+\r
+ // Jump into the compatibility mode CS\r
+ pushq $0x10\r
+ leaq 1f, %rax\r
+ pushq %rax\r
+ retfq\r
+\r
+1: // Now in compatibility mode\r
+.code32\r
+ movl $0x18, %eax\r
+ movl %eax, %ds\r
+ movl %eax, %es\r
+ movl %eax, %fs\r
+ movl %eax, %gs\r
+ movl %eax, %ss\r
+\r
+ // Disable paging\r
+ movl %cr0, %eax\r
+ btcl $31, %eax\r
+ movl %eax, %cr0\r
+\r
+ // Disable long mode in EFER\r
+ movl $0x0c0000080, %ecx\r
+ rdmsr\r
+ btcl $8, %eax\r
+ wrmsr\r
+\r
+ // Disable PAE\r
+ movl %cr4, %eax\r
+ btcl $5, %eax\r
+ movl %eax, %cr4\r
+\r
+ // Zero registers and 'return' to kernel\r
+ xorl %ebp, %ebp\r
+ xorl %edi, %edi\r
+ xorl %ebx, %ebx\r
ret\r
+.code64\r
\r
;------------------------------------------------------------------------------\r
JumpToKernel PROC\r
\r
- mov rsi, rdx\r
- add rcx, 200h\r
- call rcx\r
- ret\r
+ ; Set up for executing kernel. BP in %esi, entry point on the stack\r
+ ; (64-bit when the 'ret' will use it as 32-bit, but we're little-endian)\r
+ mov rsi, rdx\r
+ push rcx\r
+\r
+ ; Jump into the compatibility mode CS\r
+ push 10h\r
+ lea rax, @F\r
+ push rax\r
+ DB 048h, 0cbh ; retfq\r
+\r
+@@:\r
+ ; Now in compatibility mode.\r
+\r
+ DB 0b8h, 018h, 000h, 000h, 000h ; movl $0x18, %eax\r
+ DB 08eh, 0d8h ; movl %eax, %ds\r
+ DB 08eh, 0c0h ; movl %eax, %es\r
+ DB 08eh, 0e0h ; movl %eax, %fs\r
+ DB 08eh, 0e8h ; movl %eax, %gs\r
+ DB 08eh, 0d0h ; movl %eax, %ss\r
+\r
+ ; Disable paging\r
+ DB 00fh, 020h, 0c0h ; movl %cr0, %eax\r
+ DB 00fh, 0bah, 0f8h, 01fh ; btcl $31, %eax\r
+ DB 00fh, 022h, 0c0h ; movl %eax, %cr0\r
+\r
+ ; Disable long mode in EFER\r
+ DB 0b9h, 080h, 000h, 000h, 0c0h ; movl $0x0c0000080, %ecx\r
+ DB 00fh, 032h ; rdmsr\r
+ DB 00fh, 0bah, 0f8h, 008h ; btcl $8, %eax\r
+ DB 00fh, 030h ; wrmsr\r
+\r
+ ; Disable PAE\r
+ DB 00fh, 020h, 0e0h ; movl %cr4, %eax\r
+ DB 00fh, 0bah, 0f8h, 005h ; btcl $5, %eax\r
+ DB 00fh, 022h, 0e0h ; movl %eax, %cr4\r
+\r
+ DB 031h, 0edh ; xor %ebp, %ebp\r
+ DB 031h, 0ffh ; xor %edi, %edi\r
+ DB 031h, 0dbh ; xor %ebx, %ebx\r
+ DB 0c3h ; ret\r
\r
JumpToKernel ENDP\r
\r