xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.arch/amd64-disp-step.S (revision 8b657b0747480f8989760d71343d6dd33f8d4cf9)
1/* Copyright 2009-2023 Free Software Foundation, Inc.
2
3   This program is free software; you can redistribute it and/or modify
4   it under the terms of the GNU General Public License as published by
5   the Free Software Foundation; either version 3 of the License, or
6   (at your option) any later version.
7
8   This program is distributed in the hope that it will be useful,
9   but WITHOUT ANY WARRANTY; without even the implied warranty of
10   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11   GNU General Public License for more details.
12
13   You should have received a copy of the GNU General Public License
14   along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16   This file is part of the gdb testsuite.
17   It tests displaced stepping over various insns that require special
18   handling.  */
19
20	.text
21
22	.global main
23main:
24	nop
25
26/***********************************************/
27
28/* test call/ret */
29
30	.global test_call
31test_call:
32	call test_call_subr
33	nop
34	.global test_ret_end
35test_ret_end:
36	nop
37
38/***********************************************/
39
40/* test abs-jmp/rep-ret */
41
42test_abs_jmp_setup:
43	mov $test_abs_jmp_return,%rdx
44	push %rdx
45	mov $test_abs_jmp_subr,%rdx
46	.global test_abs_jmp
47test_abs_jmp:
48	jmp *%rdx
49test_abs_jmp_return:
50	nop
51	.global test_rep_ret_end
52test_rep_ret_end:
53	nop
54
55/***********************************************/
56
57/* test syscall */
58
59	.global test_syscall
60	mov $0x27,%eax /* getpid */
61test_syscall:
62	syscall
63	nop
64test_syscall_end:
65	nop
66
67/***********************************************/
68
69/* Test stepping over int3.
70   The prefixes are pointless, but it's possible, so we exercise it.  */
71
72	nop
73	.global test_int3
74test_int3:
75	repz
76	repz
77	int3
78	nop
79	.global test_int3_end
80test_int3_end:
81	nop
82
83/***********************************************/
84
85/* test rip-relative
86   GDB picks a spare register to hold the rip-relative address.
87   Exercise all the possibilities (rax-rdi, sans rsp).  */
88
89	.global test_rip_rax
90test_rip_rax:
91	add answer(%rip),%rax
92	.global test_rip_rax_end
93test_rip_rax_end:
94	nop
95
96	.global test_rip_rbx
97test_rip_rbx:
98	add answer(%rip),%rbx
99	.global test_rip_rbx_end
100test_rip_rbx_end:
101	nop
102
103	.global test_rip_rcx
104test_rip_rcx:
105	add answer(%rip),%rcx
106	.global test_rip_rcx_end
107test_rip_rcx_end:
108	nop
109
110	.global test_rip_rdx
111test_rip_rdx:
112	add answer(%rip),%rdx
113	.global test_rip_rdx_end
114test_rip_rdx_end:
115	nop
116
117	.global test_rip_rbp
118test_rip_rbp:
119	add answer(%rip),%rbp
120	.global test_rip_rbp_end
121test_rip_rbp_end:
122	nop
123
124	.global test_rip_rsi
125test_rip_rsi:
126	add answer(%rip),%rsi
127	.global test_rip_rsi_end
128test_rip_rsi_end:
129	nop
130
131	.global test_rip_rdi
132test_rip_rdi:
133	add answer(%rip),%rdi
134	.global test_rip_rdi_end
135test_rip_rdi_end:
136	nop
137
138	/* skip over test data */
139	jmp done
140
141/* test rip-relative data */
142
143answer:	.8byte 42
144
145/***********************************************/
146
147/* all done */
148
149done:
150	mov $0,%rdi
151	call exit
152	hlt
153
154/***********************************************/
155
156/* subroutine to help test call/ret */
157
158test_call_subr:
159	nop
160	.global test_call_end
161test_call_end:
162	nop
163
164	.global test_ret
165test_ret:
166	ret
167
168/***********************************************/
169
170/* subroutine to help test abs-jmp/rep-ret */
171
172test_abs_jmp_subr:
173	nop
174	.global test_abs_jmp_end
175test_abs_jmp_end:
176	nop
177
178	.global test_rep_ret
179test_rep_ret:
180	repz
181	ret
182	.section	.note.GNU-stack,"",@progbits
183