1
2
3
10
11
12
13
14
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
83
89
90
96
97
103
104
105
106
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
185
186
187
188
189
190
191
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/* ... */
#ifndef OPENOCD_TARGET_SEMIHOSTING_COMMON_H
#define OPENOCD_TARGET_SEMIHOSTING_COMMON_H
#include <stdint.h>
#include <stdbool.h>
#include <time.h>
#include "helper/replacements.h"
#include <server/server.h>
5 includes
/* ... */
enum semihosting_operation_numbers {
/* ... */
SEMIHOSTING_ENTER_SVC = 0x17,
SEMIHOSTING_SYS_CLOSE = 0x02,
SEMIHOSTING_SYS_CLOCK = 0x10,
SEMIHOSTING_SYS_ELAPSED = 0x30,
SEMIHOSTING_SYS_ERRNO = 0x13,
SEMIHOSTING_SYS_EXIT = 0x18,
SEMIHOSTING_SYS_EXIT_EXTENDED = 0x20,
SEMIHOSTING_SYS_FLEN = 0x0C,
SEMIHOSTING_SYS_GET_CMDLINE = 0x15,
SEMIHOSTING_SYS_HEAPINFO = 0x16,
SEMIHOSTING_SYS_ISERROR = 0x08,
SEMIHOSTING_SYS_ISTTY = 0x09,
SEMIHOSTING_SYS_OPEN = 0x01,
SEMIHOSTING_SYS_READ = 0x06,
SEMIHOSTING_SYS_READC = 0x07,
SEMIHOSTING_SYS_REMOVE = 0x0E,
SEMIHOSTING_SYS_RENAME = 0x0F,
SEMIHOSTING_SYS_SEEK = 0x0A,
SEMIHOSTING_SYS_SYSTEM = 0x12,
SEMIHOSTING_SYS_TICKFREQ = 0x31,
SEMIHOSTING_SYS_TIME = 0x11,
SEMIHOSTING_SYS_TMPNAM = 0x0D,
SEMIHOSTING_SYS_WRITE = 0x05,
SEMIHOSTING_SYS_WRITEC = 0x03,
SEMIHOSTING_SYS_WRITE0 = 0x04,
SEMIHOSTING_ARM_RESERVED_START = 0x32,
SEMIHOSTING_ARM_RESERVED_END = 0xFF,
SEMIHOSTING_USER_CMD_0X100 = 0x100,
SEMIHOSTING_USER_CMD_0X107 = 0x107,
SEMIHOSTING_USER_CMD_0X1FF = 0x1FF,
...};
#define SEMIHOSTING_MAX_TCL_COMMAND_FIELD_LENGTH (1024 * 1024)
/* ... */
enum semihosting_reported_exceptions {
ADP_STOPPED_APPLICATION_EXIT = ((2 << 16) + 38),
ADP_STOPPED_RUN_TIME_ERROR = ((2 << 16) + 35),
...};
enum semihosting_redirect_config {
SEMIHOSTING_REDIRECT_CFG_NONE,
SEMIHOSTING_REDIRECT_CFG_DEBUG,
SEMIHOSTING_REDIRECT_CFG_STDIO,
SEMIHOSTING_REDIRECT_CFG_ALL,
...};
enum semihosting_result {
SEMIHOSTING_NONE,
SEMIHOSTING_HANDLED,
SEMIHOSTING_WAITING,
SEMIHOSTING_ERROR
...};
struct target;
/* ... */
struct semihosting {
bool is_active;
int stdin_fd, stdout_fd, stderr_fd;
enum semihosting_redirect_config redirect_cfg;
struct connection *tcp_connection;
bool is_fileio;
bool hit_fileio;
bool is_resumable;
/* ... */
bool has_resumable_exit;
size_t word_size_bytes;
int op;
uint64_t param;
/* ... */
int64_t result;
int sys_errno;
char *cmdline;
clock_t setup_time;
char *basedir;
/* ... */
int (*user_command_extension)(struct target *target);
int (*setup)(struct target *target, int enable);
int (*post_result)(struct target *target);
...};
/* ... */
const char *semihosting_opcode_to_str(uint64_t opcode);
int semihosting_common_init(struct target *target, void *setup,
void *post_result);
int semihosting_common(struct target *target);
int semihosting_read_fields(struct target *target, size_t number,
uint8_t *fields);
int semihosting_write_fields(struct target *target, size_t number,
uint8_t *fields);
uint64_t semihosting_get_field(struct target *target, size_t index,
uint8_t *fields);
void semihosting_set_field(struct target *target, uint64_t value,
size_t index,
uint8_t *fields);
extern const struct command_registration semihosting_common_handlers[];
/* ... */
#endif