Xen Test Framework
head.S
Go to the documentation of this file.
1#include <xtf/asm_macros.h>
2
3#include <arch/page.h>
4#include <arch/processor.h>
5#include <arch/msr-index.h>
6#include <arch/segment.h>
7
8#include <xen/elfnote.h>
9
10 .section ".text.head", "ax", @progbits
11 .code32 /* Always starts in 32bit flat mode. */
12GLOBAL(_elf_start) /* HVM common setup. */
13
14#if CONFIG_PAGING_LEVELS > 0 /* Paging setup for CR3 and CR4 */
15
16#if CONFIG_PAGING_LEVELS == 2
17 mov $X86_CR4_PSE, %eax
18#elif CONFIG_PAGING_LEVELS == 3 || CONFIG_PAGING_LEVELS == 4
19 mov $X86_CR4_PAE, %eax
20#else
21# error Bad paging mode
22#endif
23 mov %eax, %cr4
24
25 mov $cr3_target, %ebx
26 mov %ebx, %cr3
27#endif /* CONFIG_PAGING_LEVELS > 0 */
28
29#ifdef __x86_64__ /* EFER.LME = 1 */
30 mov $MSR_EFER, %ecx
31 rdmsr
32 or $EFER_LME, %eax
33 wrmsr
34#endif /* __x86_64__ */
35
36#if CONFIG_PAGING_LEVELS > 0 /* CR0.PG = 1 */
37# define MAYBE_PG X86_CR0_PG
38#else
39# define MAYBE_PG 0
40#endif /* CONFIG_PAGING_LEVELS > 0 */
41
42 mov %cr0, %eax
43 or $(X86_CR0_WP | MAYBE_PG), %eax
44 mov %eax, %cr0
45
46 lgdt gdt_ptr
47
48 /* Load code segment. */
49 ljmp $__KERN_CS, $1f
50#ifdef __x86_64__
51 .code64
52#endif
53
54 /* Load data segments. */
551: mov $__USER_DS, %eax
56 mov %eax, %ds
57 mov %eax, %es
58 mov %eax, %fs
59 mov %eax, %gs
60 mov $__KERN_DS, %eax
61 mov %eax, %ss
62
63 /* Move onto the boot stack. */
64 mov $boot_stack + PAGE_SIZE, %esp
65
66 /* Reset flags. */
67 push $X86_EFLAGS_MBS
68 popf
69
70 call xtf_main
71
72 /* panic() if xtf_main manages to return. */
73#ifdef __x86_64__
74 lea .Lmain_err_msg(%rip), %rdi
75#else
76 mov $.Lmain_err_msg, %eax
77#endif
78 call panic
79ENDFUNC(_elf_start)
80
81DECLSTR(.Lmain_err_msg, "xtf_main() returned\n")
82
83/* All HVM XTF guests are compatible with the PVH ABI. */
84ENTRY(_pvh_start)
85 mov %ebx, pvh_start_info
86 jmp _elf_start
87ENDFUNC(_pvh_start)
88ELFNOTE(Xen, XEN_ELFNOTE_PHYS32_ENTRY, .long _pvh_start)
89
90/*
91 * Local variables:
92 * tab-width: 8
93 * indent-tabs-mode: nil
94 * End:
95 */