2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright 2016 Toomas Soome <tsoome@me.com>
16 #include <x86/specialreg.h>
18 .file "multiboot_tramp.s"
21 * The current dboot in illumos kernel is running in 32bit mode
22 * and expecting following 32-bit multiboot execution environment:
25 * EBX: 32-bit physical address of MBI
26 * CS: 32-bit read/execute code segment with offset 0 and limit 0xFFFFFFFF
27 * DS: 32-bit read/write code segment with offset 0 and limit 0xFFFFFFFF
28 * ES: 32-bit read/write code segment with offset 0 and limit 0xFFFFFFFF
29 * FS: 32-bit read/write code segment with offset 0 and limit 0xFFFFFFFF
30 * GS: 32-bit read/write code segment with offset 0 and limit 0xFFFFFFFF
31 * SS: 32-bit read/write data segment with offset 0 and limit 0xFFFFFFFF
33 * CR0: PG cleared, PE set
34 * EFLAGS: VM cleared, IF cleared
43 .globl multiboot_tramp
44 .type multiboot_tramp, STT_FUNC
47 * void multiboot_tramp(uint32_t magic, struct relocator *relocator,
53 movq %rax, %rsp /* Switch to temporary stack. */
54 movq 0x8(%rsi), %rax /* relocator->copy */
55 pushq %rdi /* save magic */
56 pushq %rdx /* save entry */
59 movq %rax, %rbx /* MBI */
60 popq %rsi /* entry to rsi */
61 popq %rdi /* restore magic */
63 lea gdtaddr(%rip), %rdx
65 lea gdtdesc(%rip), %rax
68 /* record the address */
69 lea multiboot_tramp_2(%rip), %rcx
75 lea multiboot_tramp_1(%rip), %rax
88 movl %cr0, %eax /* disable paging */
93 movl %cr4, %eax /* disable PAE, PGE, PSE */
94 andl $~(CR4_PGE | CR4_PAE | CR4_PSE), %eax
97 rdmsr /* updates %edx:%eax */
98 btcl $8, %eax /* clear long mode */
100 movl %edi, %eax /* magic */
101 jmp *%esi /* jump to kernel */
106 .word 0x0, 0x0 /* NULL entry */
107 .byte 0x0, 0x0, 0x0, 0x0
108 .word 0xffff, 0x0 /* code segment */
109 .byte 0x0, 0x9a, 0xcf, 0x0
110 .word 0xffff, 0x0 /* data segment */
111 .byte 0x0, 0x92, 0xcf, 0x0
115 gdtdesc: .word gdt_end - gdt - 1 /* limit */
116 gdtaddr: .long 0 /* base */