Xen Test Framework
lowlevel.S
Go to the documentation of this file.
1 #include <xtf/extable.h>
2 #include <xtf/asm_macros.h>
3 #include <xen/arch-x86/xen.h>
4 #include <arch/processor.h>
5 
6  /* Macro to generate a single test function. */
7  /* See lowlevel.h for a description of nomenclature. */
8 .macro GEN_SINGLE name, insn, fep=0, addr=0
9 
10 ENTRY(stub_\name)
11 
12  xor %eax, %eax
13 
14  .ifc \insn, into
15  /* Ensure the overflow flag is set, to trigger 'into'. */
16  mov $0x7f, %dl
17  add %dl, %dl
18  .endif
19 
20  /* Possibly insert a Xen Forced Emulation prefix. */
21  .if \fep
22  _ASM_XEN_FEP
23  .endif
24 
25 .L_\name\()_fault:
26 
27  /*
28  * Possibly insert a redundant prefix.
29  *
30  * Uses 'address size override' which has no effect on any of the
31  * target instructions, but in a form which GAS won't complain about.
32  */
33  .if \addr
34  .byte 0x67
35  .endif
36 
37  /* Target instruction to test. */
38  .ifc \insn, int3
39  int3
40  .endif
41  .ifc \insn, int_0x3
42  .byte 0xcd, 0x03 /* Some assembers turn `int $3` into `int3`. */
43  .endif
44  .ifc \insn, icebp
45  .byte 0xf1
46  .endif
47  .ifc \insn, int_0x1
48  int $0x1
49  .endif
50  .ifc \insn, into
51  .byte 0xce /* Raw opcode to avoid failure in 64bit build. */
52  .endif
53 
54 .L_\name\()_trap:
55 
56  ret
57 
58  _ASM_EXTABLE_HANDLER(.L_\name\()_fault, .L_\name\()_trap, ex_record_fault_eax)
59  _ASM_EXTABLE_HANDLER(.L_\name\()_trap, .L_\name\()_trap, ex_record_trap_eax)
60 
61 ENDFUNC(stub_\name\())
62 .endm
63 
64  /* For a single instruction, generate each test variant. */
65 .macro GEN_SEQUENCE user insn
66  GEN_SINGLE \user\()\insn \insn
67  GEN_SINGLE \user\()\insn\()_A \insn addr=1
68  GEN_SINGLE \user\()\insn\()_F \insn fep=1
69  GEN_SINGLE \user\()\insn\()_FA \insn fep=1 addr=1
70 .endm
71 
72  /* Generate test sequences for each instruction. */
73 GEN_SEQUENCE , int3
74 GEN_SEQUENCE , int_0x3
75 GEN_SEQUENCE , icebp
76 GEN_SEQUENCE , int_0x1
77 GEN_SEQUENCE , into
78 
79 .pushsection .text.user, "ax", @progbits
80 
81 GEN_SEQUENCE user_ int3
82 GEN_SEQUENCE user_ int_0x3
83 GEN_SEQUENCE user_ icebp
84 GEN_SEQUENCE user_ int_0x1
85 GEN_SEQUENCE user_ into
86 
87 .popsection
88 
89 /*
90  * Local variables:
91  * tab-width: 8
92  * indent-tabs-mode: nil
93  * End:
94  */