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