* gas/cfi/cfi.exp: Testsuite for cfi machinery.
[deliverable/binutils-gdb.git] / gas / testsuite / gas / cfi / cfi-i386.s
1 #; $ as -o test.o gas-cfi-test.s && gcc -nostdlib -o test test.o
2
3 .text
4
5 #; func_locvars
6 #; - function with a space on the stack
7 #; allocated for local variables
8
9 .type func_locvars,@function
10 func_locvars:
11 .cfi_startproc
12
13 #; alocate space for local vars
14 sub $0x1234,%esp
15 .cfi_adjust_cfa_offset 0x1234
16
17 #; dummy body
18 movl $1,%eax
19
20 #; release space of local vars and return
21 add $0x1234,%esp
22 .cfi_adjust_cfa_offset -0x1234
23 ret
24 .cfi_endproc
25
26 #; func_prologue
27 #; - functions that begins with standard
28 #; prologue: "pushq %rbp; movq %rsp,%rbp"
29
30 .type func_prologue,@function
31 func_prologue:
32 .cfi_startproc
33
34 #; prologue, CFI is valid after
35 #; each instruction.
36 pushl %ebp
37 .cfi_def_cfa_offset 8
38 .cfi_offset ebp,-8
39 movl %esp, %ebp
40 .cfi_def_cfa_register ebp
41
42 #; function body
43 call func_locvars
44 addl $3, %eax
45
46 #; epilogue with valid CFI
47 #; (we're better than gcc :-)
48 leave
49 .cfi_def_cfa_register esp
50 ret
51 .cfi_endproc
52
53 #; func_otherreg
54 #; - function that moves frame pointer to
55 #; another register (r12) and then allocates
56 #; a space for local variables
57
58 .type func_otherreg,@function
59 func_otherreg:
60 .cfi_startproc
61
62 #; save frame pointer to ebx
63 mov %esp,%ebx
64 .cfi_def_cfa_register ebx
65
66 #; alocate space for local vars
67 #; (no .cfi_{def,adjust}_cfa_offset here,
68 #; because CFA is computed from r12!)
69 sub $100,%esp
70
71 #; function body
72 call func_prologue
73 add $2, %eax
74
75 #; restore frame pointer from r12
76 mov %ebx,%esp
77 .cfi_def_cfa esp,4
78 ret
79 .cfi_endproc
80
81 #; main
82 #; - typical function
83 .type main,@function
84 main:
85 .cfi_startproc
86
87 #; only function body that doesn't
88 #; touch the stack at all.
89 call func_otherreg
90
91 #; return
92 ret
93 .cfi_endproc
94
95 #; _start
96 #; - standard entry point
97
98 .type _start,@function
99 .globl _start
100 _start:
101 .cfi_startproc
102 call main
103 movl %eax,%edi
104 movl $0x1,%eax
105 int $0x80
106 hlt
107 .cfi_endproc
This page took 0.033139 seconds and 5 git commands to generate.