Testcases for stepping over thread exit syscall (PR gdb/27338)
[binutils-gdb.git] / gdb / testsuite / lib / my-syscalls.S
1 /* This testcase is part of GDB, the GNU debugger.
2
3 Copyright 2020-2023 Free Software Foundation, Inc.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17
18
19 /* This file implements simple Linux syscall wrappers, to be used by tests that
20 need to know exactly where the syscall instructions are. */
21
22 #include <asm/unistd.h>
23
24 /* The SYSCALL macro below current supports calling syscalls with up
25 to 3 arguments, and, assumes the syscall never returns, like exec
26 and exit. If you need to call syscalls with more arguments or you
27 need to call syscalls that actually return, you'll need to update
28 the macros. We don't bother with optimizing setting up fewer
29 arguments for syscalls that take fewer arguments, as we're not
30 optimizating for speed or space, but for maintainability. */
31
32 #if defined(__x86_64__)
33
34 #define SYSCALL(NAME, NR) \
35 .global NAME ;\
36 NAME: ;\
37 mov $NR, %rax ;\
38 /* rdi, rsi and rdx already contain the right arguments. */ \
39 NAME ## _syscall: ;\
40 syscall ;\
41 ret ;
42
43 #elif defined(__i386__)
44
45 #define SYSCALL(NAME, NR) \
46 .global NAME ;\
47 NAME: ;\
48 mov $NR, %eax ;\
49 mov 4(%esp), %ebx ;\
50 mov 8(%esp), %ecx ;\
51 mov 12(%esp), %edx ;\
52 NAME ## _syscall: ;\
53 int $0x80 ;\
54 ret
55
56 #elif defined(__aarch64__)
57
58 #define SYSCALL(NAME, NR) \
59 .global NAME ;\
60 NAME: ;\
61 mov x8, NR ;\
62 /* x0, x1 and x2 already contain the right arguments. */ \
63 NAME ## _syscall: ;\
64 svc #0
65
66 #else
67 # error "Unsupported architecture"
68 #endif
69
70 SYSCALL (my_execve, __NR_execve)
71
72 /* void my_exit (int code); */
73
74 SYSCALL (my_exit, __NR_exit)
75
76 .section .note.GNU-stack,"",@progbits