]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.arch/thumb-prologue.c
Switch the license of all .c files to GPLv3.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.arch / thumb-prologue.c
1 /* Unwinder test program.
2
3 Copyright 2006, 2007 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 void tpcs_frame (void);
21
22 int
23 main (void)
24 {
25 tpcs_frame ();
26 return 0;
27 }
28
29 /* Normally Thumb functions use r7 as the frame pointer. However,
30 with the GCC option -mtpcs-frame, they may use fp instead. Make
31 sure that the prologue analyzer can handle this. */
32
33 asm(".text\n"
34 " .align 2\n"
35 " .thumb_func\n"
36 " .code 16\n"
37 "tpcs_frame_1:\n"
38 " sub sp, #16\n"
39 " push {r7}\n"
40 " add r7, sp, #20\n"
41 " str r7, [sp, #8]\n"
42 " mov r7, pc\n"
43 " str r7, [sp, #16]\n"
44 " mov r7, fp\n"
45 " str r7, [sp, #4]\n"
46 " mov r7, lr\n"
47 " str r7, [sp, #12]\n"
48 " add r7, sp, #16\n"
49 " mov fp, r7\n"
50 " mov r7, sl\n"
51 " push {r7}\n"
52
53 /* We'll set a breakpoint at this call. We can't hardcode a trap
54 instruction; the right instruction to use varies too much. And
55 we can't use a global label, because GDB will think that's the
56 start of a new function. So, this slightly convoluted
57 technique. */
58 ".Ltpcs:\n"
59 " nop\n"
60
61 " pop {r2}\n"
62 " mov sl, r2\n"
63 " pop {r7}\n"
64 " pop {r1, r2}\n"
65 " mov fp, r1\n"
66 " mov sp, r2\n"
67 " bx lr\n"
68
69 " .align 2\n"
70 " .type tpcs_offset, %object\n"
71 "tpcs_offset:\n"
72 " .word .Ltpcs - tpcs_frame_1\n"
73
74 " .align 2\n"
75 " .thumb_func\n"
76 " .code 16\n"
77 "tpcs_frame:\n"
78 " sub sp, #16\n"
79 " push {r7}\n"
80 " add r7, sp, #20\n"
81 " str r7, [sp, #8]\n"
82 " mov r7, pc\n"
83 " str r7, [sp, #16]\n"
84 " mov r7, fp\n"
85 " str r7, [sp, #4]\n"
86 " mov r7, lr\n"
87 " str r7, [sp, #12]\n"
88 " add r7, sp, #16\n"
89 " mov fp, r7\n"
90 " mov r7, sl\n"
91 " push {r7}\n"
92
93 /* Clobber saved regs around the call. */
94 " mov r7, #0\n"
95 " mov lr, r7\n"
96 " bl tpcs_frame_1\n"
97
98 " pop {r2}\n"
99 " mov sl, r2\n"
100 " pop {r7}\n"
101 " pop {r1, r2, r3}\n"
102 " mov fp, r1\n"
103 " mov sp, r2\n"
104 " mov lr, r3\n"
105 " bx lr\n"
106 );