2 * x86_64 boot and support code
4 * Copyright 2019 Linaro
6 * This work is licensed under the terms of the GNU GPL, version 3 or later.
7 * See the COPYING file in the top-level directory.
9 * Unlike the i386 version we instead use Xen's PVHVM booting header
10 * which should drop us automatically into 32 bit mode ready to go. I've
11 * nabbed bits of the Linux kernel setup to achieve this.
13 * SPDX-License-Identifier: GPL-3.0-or-later
18 #define ELFNOTE_START(name, type, flags) \
19 .pushsection .note.name, flags,@note ; \
21 .long 2f - 1f /* namesz */ ; \
22 .long 4484f - 3f /* descsz */ ; \
32 #define ELFNOTE(name, type, desc) \
33 ELFNOTE_START(name, type, "") \
37 #define XEN_ELFNOTE_ENTRY 1
38 #define XEN_ELFNOTE_HYPERCALL_PAGE 2
39 #define XEN_ELFNOTE_VIRT_BASE 3
40 #define XEN_ELFNOTE_PADDR_OFFSET 4
41 #define XEN_ELFNOTE_PHYS32_ENTRY 18
43 #define __ASM_FORM(x) x
44 #define __ASM_FORM_RAW(x) x
45 #define __ASM_FORM_COMMA(x) x,
46 #define __ASM_SEL(a,b) __ASM_FORM(b)
47 #define __ASM_SEL_RAW(a,b) __ASM_FORM_RAW(b)
48 #define _ASM_PTR __ASM_SEL(.long, .quad)
50 ELFNOTE(Xen, XEN_ELFNOTE_VIRT_BASE, _ASM_PTR 0x100000)
51 ELFNOTE(Xen, XEN_ELFNOTE_ENTRY, _ASM_PTR _start)
52 ELFNOTE(Xen, XEN_ELFNOTE_PHYS32_ENTRY, _ASM_PTR _start) /* entry == virtbase */
53 ELFNOTE(Xen, XEN_ELFNOTE_PADDR_OFFSET, _ASM_PTR 0)
56 * Entry point for PVH guests.
58 * Xen ABI specifies the following register state when we come here:
60 * - `ebx`: contains the physical memory address where the loader has placed
61 * the boot start info structure.
62 * - `cr0`: bit 0 (PE) must be set. All the other writeable bits are cleared.
63 * - `cr4`: all bits are cleared.
64 * - `cs `: must be a 32-bit read/execute code segment with a base of ‘0’
65 * and a limit of ‘0xFFFFFFFF’. The selector value is unspecified.
66 * - `ds`, `es`: must be a 32-bit read/write data segment with a base of
67 * ‘0’ and a limit of ‘0xFFFFFFFF’. The selector values are all
69 * - `tr`: must be a 32-bit TSS (active) with a base of '0' and a limit
71 * - `eflags`: bit 17 (VM) must be cleared. Bit 9 (IF) must be cleared.
72 * Bit 8 (TF) must be cleared. Other bits are all unspecified.
74 * All other processor registers and flag bits are unspecified. The OS is in
75 * charge of setting up it's own stack, GDT and IDT.
94 /* Enable PAE mode (bit 5). */
99 #define MSR_EFER 0xc0000080 /* extended feature register */
101 /* Enable Long mode. */
115 /* Jump to 64-bit mode. */
127 /* don't worry about stack frame, assume everthing is garbage when we return */
130 /* output any non-zero result in eax to isa-debug-exit device */
135 1: /* QEMU ACPI poweroff */
145 * x86_64 calling convention is rdi, rsi, rdx, rcx, r8, r9
148 /* Output a single character to serial port */
157 /* Interrupt Descriptor Table */
168 idt_06: .int 0, 0 /* intr_6_opcode, Invalid Opcode */
197 * Global Descriptor Table (GDT)
199 * This describes various memory areas (segments) through
200 * segment descriptors. In 32 bit mode each segment each
201 * segement is associated with segment registers which are
202 * implicitly (or explicitly) referenced depending on the
203 * instruction. However in 64 bit mode selectors are flat and
204 * segmented addressing isn't used.
209 .short gdt_en - gdt - 1
220 // Data ds:, ss:, es:, fs:, and gs:
232 .short gdt64_en - gdt64 - 1
264 .quad 0x1e7 | (i << 21)
270 .quad .Lpd + 7 + 0 * 4096 /* 0-1 GB */
271 .quad .Lpd + 7 + 1 * 4096 /* 1-2 GB */
272 .quad .Lpd + 7 + 2 * 4096 /* 2-3 GB */
273 .quad .Lpd + 7 + 3 * 4096 /* 3-4 GB */
277 .quad .Lpdp + 7 /* 0-512 GB */