master
h 133 lines 4.01 KB
Raw
1 /*
2 * GDB Syscall support
3 *
4 * Copyright (c) 2023 Linaro Ltd
5 *
6 * SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8
9 #ifndef _SYSCALLS_H_
10 #define _SYSCALLS_H_
11
12 /* For gdb file i/o remote protocol open flags. */
13 #define GDB_O_RDONLY 0
14 #define GDB_O_WRONLY 1
15 #define GDB_O_RDWR 2
16 #define GDB_O_APPEND 8
17 #define GDB_O_CREAT 0x200
18 #define GDB_O_TRUNC 0x400
19 #define GDB_O_EXCL 0x800
20
21 /* For gdb file i/o remote protocol errno values */
22 #define GDB_EPERM 1
23 #define GDB_ENOENT 2
24 #define GDB_EINTR 4
25 #define GDB_EIO 5
26 #define GDB_EBADF 9
27 #define GDB_EACCES 13
28 #define GDB_EFAULT 14
29 #define GDB_EBUSY 16
30 #define GDB_EEXIST 17
31 #define GDB_ENODEV 19
32 #define GDB_ENOTDIR 20
33 #define GDB_EISDIR 21
34 #define GDB_EINVAL 22
35 #define GDB_ENFILE 23
36 #define GDB_EMFILE 24
37 #define GDB_EFBIG 27
38 #define GDB_ENOSPC 28
39 #define GDB_ESPIPE 29
40 #define GDB_EROFS 30
41 #define GDB_ENOSYS 88
42 #define GDB_ENAMETOOLONG 91
43 #define GDB_EUNKNOWN 9999
44
45 /* For gdb file i/o remote protocol lseek whence. */
46 #define GDB_SEEK_SET 0
47 #define GDB_SEEK_CUR 1
48 #define GDB_SEEK_END 2
49
50 /* For gdb file i/o stat/fstat. */
51 typedef uint32_t gdb_mode_t;
52 typedef uint32_t gdb_time_t;
53
54 struct gdb_stat {
55 uint32_t gdb_st_dev; /* device */
56 uint32_t gdb_st_ino; /* inode */
57 gdb_mode_t gdb_st_mode; /* protection */
58 uint32_t gdb_st_nlink; /* number of hard links */
59 uint32_t gdb_st_uid; /* user ID of owner */
60 uint32_t gdb_st_gid; /* group ID of owner */
61 uint32_t gdb_st_rdev; /* device type (if inode device) */
62 uint64_t gdb_st_size; /* total size, in bytes */
63 uint64_t gdb_st_blksize; /* blocksize for filesystem I/O */
64 uint64_t gdb_st_blocks; /* number of blocks allocated */
65 gdb_time_t gdb_st_atime; /* time of last access */
66 gdb_time_t gdb_st_mtime; /* time of last modification */
67 gdb_time_t gdb_st_ctime; /* time of last change */
68 } QEMU_PACKED;
69
70 struct gdb_timeval {
71 gdb_time_t tv_sec; /* second */
72 uint64_t tv_usec; /* microsecond */
73 } QEMU_PACKED;
74
75 typedef void (*gdb_syscall_complete_cb)(CPUState *cpu, uint64_t ret, int err);
76
77 /**
78 * gdb_do_syscall:
79 * @cb: function to call when the system call has completed
80 * @fmt: gdb syscall format string
81 * ...: list of arguments to interpolate into @fmt
82 *
83 * Send a GDB syscall request. This function will return immediately;
84 * the callback function will be called later when the remote system
85 * call has completed.
86 *
87 * @fmt should be in the 'call-id,parameter,parameter...' format documented
88 * for the F request packet in the GDB remote protocol. A limited set of
89 * printf-style format specifiers is supported:
90 * %x - target_ulong argument printed in hex
91 * %lx - 64-bit argument printed in hex
92 * %s - string pointer (target_ulong) and length (int) pair
93 */
94 void gdb_do_syscall(gdb_syscall_complete_cb cb, const char *fmt, ...);
95
96 /**
97 * use_gdb_syscalls() - report if GDB should be used for syscalls
98 *
99 * This is mostly driven by the semihosting mode the user configures
100 * but assuming GDB is allowed by that we report true if GDB is
101 * connected to the stub.
102 */
103 int use_gdb_syscalls(void);
104
105 /**
106 * host_to_gdb_errno: convert host errno to GDB errno value
107 * @err: errno from host
108 *
109 * Given an error number from the host, this helper function returns
110 * its GDB File-I/O specified representation.
111 */
112 int host_to_gdb_errno(int err);
113
114 /**
115 * gdb_exit: exit gdb session, reporting inferior status
116 * @code: exit code reported
117 *
118 * This closes the session and sends a final packet to GDB reporting
119 * the exit status of the program. It also cleans up any connections
120 * detritus before returning.
121 */
122 void gdb_exit(int code);
123
124 /**
125 * gdb_qemu_exit: ask qemu to exit
126 * @code: exit code reported
127 *
128 * This requests qemu to exit. This function is allowed to return as
129 * the exit request might be processed asynchronously by qemu backend.
130 */
131 void gdb_qemu_exit(int code);
132
133 #endif /* _SYSCALLS_H_ */