xref: /linux/arch/x86/xen/xen-head.S (revision 3f0a50f345f78183f6e9b39c2f45ca5dcaa511ca)
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		ANNOTATE_NOENDBR
29		ret
30		/*
31		 * Xen will write the hypercall page, and sort out ENDBR.
32		 */
33		.skip 31, 0xcc
34	.endr
35
36#define HYPERCALL(n) \
37	.equ xen_hypercall_##n, hypercall_page + __HYPERVISOR_##n * 32; \
38	.type xen_hypercall_##n, @function; .size xen_hypercall_##n, 32
39#include <asm/xen-hypercalls.h>
40#undef HYPERCALL
41SYM_CODE_END(hypercall_page)
42.popsection
43
44#ifdef CONFIG_XEN_PV
45	__INIT
46SYM_CODE_START(startup_xen)
47	UNWIND_HINT_EMPTY
48	cld
49
50	/* Clear .bss */
51	xor %eax,%eax
52	mov $__bss_start, %rdi
53	mov $__bss_stop, %rcx
54	sub %rdi, %rcx
55	shr $3, %rcx
56	rep stosq
57
58	mov %rsi, xen_start_info
59	mov initial_stack(%rip), %rsp
60
61	/* Set up %gs.
62	 *
63	 * The base of %gs always points to fixed_percpu_data.  If the
64	 * stack protector canary is enabled, it is located at %gs:40.
65	 * Note that, on SMP, the boot cpu uses init data section until
66	 * the per cpu areas are set up.
67	 */
68	movl	$MSR_GS_BASE,%ecx
69	movq	$INIT_PER_CPU_VAR(fixed_percpu_data),%rax
70	cdq
71	wrmsr
72
73	call xen_start_kernel
74SYM_CODE_END(startup_xen)
75	__FINIT
76
77#ifdef CONFIG_XEN_PV_SMP
78.pushsection .text
79SYM_CODE_START(asm_cpu_bringup_and_idle)
80	UNWIND_HINT_EMPTY
81	ENDBR
82
83	call cpu_bringup_and_idle
84SYM_CODE_END(asm_cpu_bringup_and_idle)
85.popsection
86#endif
87#endif
88
89	ELFNOTE(Xen, XEN_ELFNOTE_GUEST_OS,       .asciz "linux")
90	ELFNOTE(Xen, XEN_ELFNOTE_GUEST_VERSION,  .asciz "2.6")
91	ELFNOTE(Xen, XEN_ELFNOTE_XEN_VERSION,    .asciz "xen-3.0")
92#ifdef CONFIG_X86_32
93	ELFNOTE(Xen, XEN_ELFNOTE_VIRT_BASE,      _ASM_PTR __PAGE_OFFSET)
94#else
95	ELFNOTE(Xen, XEN_ELFNOTE_VIRT_BASE,      _ASM_PTR __START_KERNEL_map)
96	/* Map the p2m table to a 512GB-aligned user address. */
97	ELFNOTE(Xen, XEN_ELFNOTE_INIT_P2M,       .quad (PUD_SIZE * PTRS_PER_PUD))
98#endif
99#ifdef CONFIG_XEN_PV
100	ELFNOTE(Xen, XEN_ELFNOTE_ENTRY,          _ASM_PTR startup_xen)
101#endif
102	ELFNOTE(Xen, XEN_ELFNOTE_HYPERCALL_PAGE, _ASM_PTR hypercall_page)
103	ELFNOTE(Xen, XEN_ELFNOTE_FEATURES,
104		.ascii "!writable_page_tables|pae_pgdir_above_4gb")
105	ELFNOTE(Xen, XEN_ELFNOTE_SUPPORTED_FEATURES,
106		.long (1 << XENFEAT_writable_page_tables) |       \
107		      (1 << XENFEAT_dom0) |                       \
108		      (1 << XENFEAT_linux_rsdp_unrestricted))
109	ELFNOTE(Xen, XEN_ELFNOTE_PAE_MODE,       .asciz "yes")
110	ELFNOTE(Xen, XEN_ELFNOTE_LOADER,         .asciz "generic")
111	ELFNOTE(Xen, XEN_ELFNOTE_L1_MFN_VALID,
112		.quad _PAGE_PRESENT; .quad _PAGE_PRESENT)
113	ELFNOTE(Xen, XEN_ELFNOTE_SUSPEND_CANCEL, .long 1)
114	ELFNOTE(Xen, XEN_ELFNOTE_MOD_START_PFN,  .long 1)
115	ELFNOTE(Xen, XEN_ELFNOTE_HV_START_LOW,   _ASM_PTR __HYPERVISOR_VIRT_START)
116	ELFNOTE(Xen, XEN_ELFNOTE_PADDR_OFFSET,   _ASM_PTR 0)
117
118#endif /*CONFIG_XEN */
119