xref: /openbmc/linux/arch/x86/xen/xen-head.S (revision e7f127b2)
1/* SPDX-License-Identifier: GPL-2.0 */
2/* Xen-specific pieces of head.S, intended to be included in the right
3	place in head.S */
4
5#ifdef CONFIG_XEN
6
7#include <linux/elfnote.h>
8#include <linux/init.h>
9
10#include <asm/boot.h>
11#include <asm/asm.h>
12#include <asm/msr.h>
13#include <asm/page_types.h>
14#include <asm/percpu.h>
15#include <asm/unwind_hints.h>
16
17#include <xen/interface/elfnote.h>
18#include <xen/interface/features.h>
19#include <xen/interface/xen.h>
20#include <xen/interface/xen-mca.h>
21#include <asm/xen/interface.h>
22
23.pushsection .noinstr.text, "ax"
24	.balign PAGE_SIZE
25SYM_CODE_START(hypercall_page)
26	.rept (PAGE_SIZE / 32)
27		UNWIND_HINT_FUNC
28		.skip 31, 0x90
29		RET
30	.endr
31
32#define HYPERCALL(n) \
33	.equ xen_hypercall_##n, hypercall_page + __HYPERVISOR_##n * 32; \
34	.type xen_hypercall_##n, @function; .size xen_hypercall_##n, 32
35#include <asm/xen-hypercalls.h>
36#undef HYPERCALL
37SYM_CODE_END(hypercall_page)
38.popsection
39
40#ifdef CONFIG_XEN_PV
41	__INIT
42SYM_CODE_START(startup_xen)
43	UNWIND_HINT_EMPTY
44	cld
45
46	/* Clear .bss */
47	xor %eax,%eax
48	mov $__bss_start, %rdi
49	mov $__bss_stop, %rcx
50	sub %rdi, %rcx
51	shr $3, %rcx
52	rep stosq
53
54	mov %rsi, xen_start_info
55	mov initial_stack(%rip), %rsp
56
57	/* Set up %gs.
58	 *
59	 * The base of %gs always points to fixed_percpu_data.  If the
60	 * stack protector canary is enabled, it is located at %gs:40.
61	 * Note that, on SMP, the boot cpu uses init data section until
62	 * the per cpu areas are set up.
63	 */
64	movl	$MSR_GS_BASE,%ecx
65	movq	$INIT_PER_CPU_VAR(fixed_percpu_data),%rax
66	cdq
67	wrmsr
68
69	call xen_start_kernel
70SYM_CODE_END(startup_xen)
71	__FINIT
72
73#ifdef CONFIG_XEN_PV_SMP
74.pushsection .text
75SYM_CODE_START(asm_cpu_bringup_and_idle)
76	UNWIND_HINT_EMPTY
77
78	call cpu_bringup_and_idle
79SYM_CODE_END(asm_cpu_bringup_and_idle)
80.popsection
81#endif
82#endif
83
84	ELFNOTE(Xen, XEN_ELFNOTE_GUEST_OS,       .asciz "linux")
85	ELFNOTE(Xen, XEN_ELFNOTE_GUEST_VERSION,  .asciz "2.6")
86	ELFNOTE(Xen, XEN_ELFNOTE_XEN_VERSION,    .asciz "xen-3.0")
87#ifdef CONFIG_X86_32
88	ELFNOTE(Xen, XEN_ELFNOTE_VIRT_BASE,      _ASM_PTR __PAGE_OFFSET)
89#else
90	ELFNOTE(Xen, XEN_ELFNOTE_VIRT_BASE,      _ASM_PTR __START_KERNEL_map)
91	/* Map the p2m table to a 512GB-aligned user address. */
92	ELFNOTE(Xen, XEN_ELFNOTE_INIT_P2M,       .quad (PUD_SIZE * PTRS_PER_PUD))
93#endif
94#ifdef CONFIG_XEN_PV
95	ELFNOTE(Xen, XEN_ELFNOTE_ENTRY,          _ASM_PTR startup_xen)
96#endif
97	ELFNOTE(Xen, XEN_ELFNOTE_HYPERCALL_PAGE, _ASM_PTR hypercall_page)
98	ELFNOTE(Xen, XEN_ELFNOTE_FEATURES,
99		.ascii "!writable_page_tables|pae_pgdir_above_4gb")
100	ELFNOTE(Xen, XEN_ELFNOTE_SUPPORTED_FEATURES,
101		.long (1 << XENFEAT_writable_page_tables) |       \
102		      (1 << XENFEAT_dom0) |                       \
103		      (1 << XENFEAT_linux_rsdp_unrestricted))
104	ELFNOTE(Xen, XEN_ELFNOTE_PAE_MODE,       .asciz "yes")
105	ELFNOTE(Xen, XEN_ELFNOTE_LOADER,         .asciz "generic")
106	ELFNOTE(Xen, XEN_ELFNOTE_L1_MFN_VALID,
107		.quad _PAGE_PRESENT; .quad _PAGE_PRESENT)
108	ELFNOTE(Xen, XEN_ELFNOTE_SUSPEND_CANCEL, .long 1)
109	ELFNOTE(Xen, XEN_ELFNOTE_MOD_START_PFN,  .long 1)
110	ELFNOTE(Xen, XEN_ELFNOTE_HV_START_LOW,   _ASM_PTR __HYPERVISOR_VIRT_START)
111	ELFNOTE(Xen, XEN_ELFNOTE_PADDR_OFFSET,   _ASM_PTR 0)
112
113#endif /*CONFIG_XEN */
114