Select one of the symbols to view example projects that use it.
 
Outline
#include <string.h>
#include <sys/errno.h>
#include "xtensa/semihosting.h"
#include "riscv/semihosting.h"
#define SEMIHOSTING_SYS_OPEN
#define SEMIHOSTING_SYS_CLOSE
#define SEMIHOSTING_SYS_WRITEC
#define SEMIHOSTING_SYS_WRITE0
#define SEMIHOSTING_SYS_WRITE
#define SEMIHOSTING_SYS_READ
#define SEMIHOSTING_SYS_READC
#define SEMIHOSTING_SYS_ISERROR
#define SEMIHOSTING_SYS_ISTTY
#define SEMIHOSTING_SYS_SEEK
#define SEMIHOSTING_SYS_FLEN
#define SEMIHOSTING_SYS_REMOVE
#define SEMIHOSTING_SYS_RENAME
#define SEMIHOSTING_SYS_CLOCK
#define SEMIHOSTING_SYS_TIME
#define SEMIHOSTING_SYS_SYSTEM
#define SEMIHOSTING_SYS_ERRNO
#define SEMIHOSTING_SYS_GET_CMDLINE
#define SEMIHOSTING_SYS_HEAPINFO
#define SEMIHOSTING_SYS_EXIT
#define SEMIHOSTING_SYS_EXIT_EXTENDED
#define ESP_SEMIHOSTING_SYS_DRV_INFO
#define ESP_SEMIHOSTING_SYS_SEEK
#define ESP_SEMIHOSTING_SYS_MKDIR
#define ESP_SEMIHOSTING_SYS_OPENDIR
#define ESP_SEMIHOSTING_SYS_READDIR
#define ESP_SEMIHOSTING_SYS_READDIR_R
#define ESP_SEMIHOSTING_SYS_SEEKDIR
#define ESP_SEMIHOSTING_SYS_TELLDIR
#define ESP_SEMIHOSTING_SYS_CLOSEDIR
#define ESP_SEMIHOSTING_SYS_RMDIR
#define ESP_SEMIHOSTING_SYS_ACCESS
#define ESP_SEMIHOSTING_SYS_TRUNCATE
#define ESP_SEMIHOSTING_SYS_UTIME
#define ESP_SEMIHOSTING_SYS_FSTAT
#define ESP_SEMIHOSTING_SYS_STAT
#define ESP_SEMIHOSTING_SYS_FSYNC
#define ESP_SEMIHOSTING_SYS_LINK
#define ESP_SEMIHOSTING_SYS_UNLINK
#define SEMIHOSTING_DRV_VERSION
semihosting_call(long, long *, int *)
semihosting_open(const char *, int, int)
semihosting_write(int, const void *, size_t)
semihosting_read(int, void *, size_t)
semihosting_close(int)
semihosting_seek(int, off_t, int)
semihosting_ver_info()
semihosting_fstat(int, struct stat *restrict)
semihosting_fsync(int)
semihosting_mkdir(const char *, mode_t)
semihosting_rmdir(const char *)
semihosting_access(const char *, int)
semihosting_truncate(const char *, off_t)
semihosting_utime(const char *, const struct utimbuf *)
semihosting_stat(const char *, struct stat *restrict)
semihosting_rename(const char *, const char *)
semihosting_link(const char *, const char *)
semihosting_unlink(const char *)
semihosting_opendir(const char *, long)
semihosting_readdir(long, long)
semihosting_closedir(long)
semihosting_telldir(long)
semihosting_seekdir(long, long)
Files
loading (4/5)...
SourceVuESP-IDF Framework and ExamplesESP-IDFcomponents/vfs/openocd_semihosting.h
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 *//* ... */ #pragma once #include <string.h> #include <sys/errno.h> #ifdef __XTENSA__ #include "xtensa/semihosting.h" #elif __riscv #include "riscv/semihosting.h" #else #error Unsupported architecture #endif #ifdef __cplusplus extern "C" { #endif /** * Semihosting call numbers and functions for OpenOCD. * In OpenOCD, ARM semihosting call numbers and parameters are used for * RISC-V and Xtensa targets. * * These conventions are not compatible with Xtensa ISS and QEMU for Xtensa, * which the actual Xtensa-specific semihosting call numbers and formats; * these are not supported in ESP-IDF yet. *//* ... */ #define SEMIHOSTING_SYS_OPEN 0x01 #define SEMIHOSTING_SYS_CLOSE 0x02 #define SEMIHOSTING_SYS_WRITEC 0x03 #define SEMIHOSTING_SYS_WRITE0 0x04 #define SEMIHOSTING_SYS_WRITE 0x05 #define SEMIHOSTING_SYS_READ 0x06 #define SEMIHOSTING_SYS_READC 0x07 #define SEMIHOSTING_SYS_ISERROR 0x08 #define SEMIHOSTING_SYS_ISTTY 0x09 #define SEMIHOSTING_SYS_SEEK 0x0A #define SEMIHOSTING_SYS_FLEN 0x0C #define SEMIHOSTING_SYS_REMOVE 0x0E #define SEMIHOSTING_SYS_RENAME 0x0F #define SEMIHOSTING_SYS_CLOCK 0x10 #define SEMIHOSTING_SYS_TIME 0x11 #define SEMIHOSTING_SYS_SYSTEM 0x12 #define SEMIHOSTING_SYS_ERRNO 0x13 #define SEMIHOSTING_SYS_GET_CMDLINE 0x15 #define SEMIHOSTING_SYS_HEAPINFO 0x16 #define SEMIHOSTING_SYS_EXIT 0x18 #define SEMIHOSTING_SYS_EXIT_EXTENDED 0x20 /* This call is an Espressif OpenOCD extension to send the version * information to the host. This lets the host support different IDF versions, * allowing semihosting interface to be modified over time. * * The parameters of this call are: * - pointer to the version info structure, * - size of the version info structure. * * At present, the structure should contain a single word, indicating * the semihosting interface version used by the target. * * If the syscall is recognized, the return value is zero. *//* ... */ #define ESP_SEMIHOSTING_SYS_DRV_INFO 0x100 /* 0x101...0x104 used by RiscV for custom semihosting calls */ /* Other Espressif extension sys calls */ #define ESP_SEMIHOSTING_SYS_SEEK 0x105 /* custom lseek with whence */ /* not implemented yet */ #define ESP_SEMIHOSTING_SYS_MKDIR 0x106 #define ESP_SEMIHOSTING_SYS_OPENDIR 0x107 #define ESP_SEMIHOSTING_SYS_READDIR 0x108 #define ESP_SEMIHOSTING_SYS_READDIR_R 0x109 #define ESP_SEMIHOSTING_SYS_SEEKDIR 0x10A #define ESP_SEMIHOSTING_SYS_TELLDIR 0x10B #define ESP_SEMIHOSTING_SYS_CLOSEDIR 0x10C #define ESP_SEMIHOSTING_SYS_RMDIR 0x10D #define ESP_SEMIHOSTING_SYS_ACCESS 0x10E #define ESP_SEMIHOSTING_SYS_TRUNCATE 0x10F #define ESP_SEMIHOSTING_SYS_UTIME 0x110 #define ESP_SEMIHOSTING_SYS_FSTAT 0x111 #define ESP_SEMIHOSTING_SYS_STAT 0x112 #define ESP_SEMIHOSTING_SYS_FSYNC 0x113 #define ESP_SEMIHOSTING_SYS_LINK 0x114 #define ESP_SEMIHOSTING_SYS_UNLINK 0x115 /* Semihosting version bumped to 2. Changelog; 1 - Memory based approach with 2 registers implemented as defined in the ARM standard. 2 - User defined syscall numbers located between 0x100-0x1FF 3 - The break instruction operands updated to (1, 14) 4 - Absolute path support is dropped *//* ... */ #define SEMIHOSTING_DRV_VERSION 240 defines /** * @brief Perform semihosting call and retrieve errno * * @param id semihosting call number * @param data data block to pass to the host; number of items and their * meaning depends on the semihosting call. See the spec for * details. * @param[out] out_errno output, errno value from the host. Only set if * the return value is negative. * @return return value from the host *//* ... */ static inline long semihosting_call(long id, long *data, int *out_errno) { long ret = semihosting_call_noerrno(id, data); if (ret < 0) { const int semihosting_sys_errno = SEMIHOSTING_SYS_ERRNO; *out_errno = (int)semihosting_call_noerrno(semihosting_sys_errno, NULL); }{...} return ret; }{ ... } static inline int semihosting_open(const char *path, int open_mode, int mode) { int host_errno = 0; long args[] = {(long) path, open_mode, strlen(path), 0}; (void) mode; // unused in OpenOCD int result = (int)semihosting_call(SEMIHOSTING_SYS_OPEN, args, &host_errno); if (result < 0) { errno = host_errno; }{...} return result; }{ ... } static inline ssize_t semihosting_write(int fd, const void *data, size_t size) { int host_errno = 0; long args[] = {fd, (long) data, size, 0}; ssize_t ret = (ssize_t)semihosting_call(SEMIHOSTING_SYS_WRITE, args, &host_errno); if (ret < 0) { errno = host_errno; return ret; }{...} /* On success, write syscall returns the number of bytes NOT written, * adjust the return value to match POSIX. *//* ... */ return size - (ssize_t)ret; }{ ... } static inline ssize_t semihosting_read(int fd, void *data, size_t size) { int host_errno = 0; long args[] = {fd, (long) data, size, 0}; ssize_t ret = (ssize_t)semihosting_call(SEMIHOSTING_SYS_READ, args, &host_errno); if (ret < 0) { errno = host_errno; return ret; }{...} /* On success, read syscall returns the number of bytes NOT read, * adjust the return value to match POSIX. *//* ... */ return size - (ssize_t)ret; }{ ... } static inline int semihosting_close(int fd) { int host_errno = 0; long args[] = {fd, 0, 0, 0}; int ret = (int)semihosting_call(SEMIHOSTING_SYS_CLOSE, args, &host_errno); if (ret < 0) { errno = host_errno; }{...} return ret; }{ ... } static inline off_t semihosting_seek(int fd, off_t offset, int mode) { int host_errno = 0; long args[] = {fd, offset, mode, 0}; off_t ret = (off_t)semihosting_call(ESP_SEMIHOSTING_SYS_SEEK, args, &host_errno); if (ret == -1) { errno = host_errno; }{...} return ret; }{ ... } static inline int semihosting_ver_info(void) { int host_errno = 0; struct { int version; }{ ... } ver_info = { SEMIHOSTING_DRV_VERSION }; long args[] = {(long) &ver_info, sizeof(ver_info), 0, 0}; int ret = (int)semihosting_call(ESP_SEMIHOSTING_SYS_DRV_INFO, args, &host_errno); (void) host_errno; /* errno not set by this call */ return ret; }{ ... } static inline int semihosting_fstat(int fd, struct stat *restrict statbuf) { int host_errno = 0; long args[] = {fd, (int)statbuf, 0, 0}; int ret = (int)semihosting_call(ESP_SEMIHOSTING_SYS_FSTAT, args, &host_errno); if (ret < 0) { errno = host_errno; }{...} return ret; }{ ... } static inline int semihosting_fsync(int fd) { int host_errno = 0; long args[] = {fd, 0, 0, 0}; int ret = (int)semihosting_call(ESP_SEMIHOSTING_SYS_FSYNC, args, &host_errno); if (ret < 0) { errno = host_errno; }{...} return ret; }{ ... } #ifdef CONFIG_VFS_SUPPORT_DIR static inline int semihosting_mkdir(const char *host_path, mode_t mode) { int host_errno = 0; long args[] = {(long)host_path, mode, strlen(host_path), 0}; int ret = (int)semihosting_call(ESP_SEMIHOSTING_SYS_MKDIR, args, &host_errno); if (ret < 0) { errno = host_errno; }{...} return ret; }{ ... } static inline int semihosting_rmdir(const char *host_path) { int host_errno = 0; long args[] = {(long)host_path, strlen(host_path), 0, 0}; int ret = (int)semihosting_call(ESP_SEMIHOSTING_SYS_RMDIR, args, &host_errno); if (ret < 0) { errno = host_errno; }{...} return ret; }{ ... } static inline int semihosting_access(const char *host_path, int mode) { int host_errno = 0; long args[] = {(long)host_path, strlen(host_path), mode, 0}; int ret = (int)semihosting_call(ESP_SEMIHOSTING_SYS_ACCESS, args, &host_errno); if (ret < 0) { errno = host_errno; }{...} return ret; }{ ... } static inline int semihosting_truncate(const char *host_path, off_t truncate_length) { int host_errno = 0; long args[] = {(long)host_path, strlen(host_path), truncate_length, 0}; int ret = (int)semihosting_call(ESP_SEMIHOSTING_SYS_TRUNCATE, args, &host_errno); if (ret < 0) { errno = host_errno; }{...} return ret; }{ ... } static inline int semihosting_utime(const char *host_path, const struct utimbuf *times) { int host_errno = 0; long args[] = {(long)host_path, strlen(host_path), times->actime, times->modtime}; int ret = (int)semihosting_call(ESP_SEMIHOSTING_SYS_UTIME, args, &host_errno); if (ret < 0) { errno = host_errno; }{...} return ret; }{ ... } static inline int semihosting_stat(const char *host_path, struct stat *restrict statbuf) { int host_errno = 0; long args[] = {(long)host_path, strlen(host_path), (long)statbuf, 0}; int ret = (int)semihosting_call(ESP_SEMIHOSTING_SYS_STAT, args, &host_errno); if (ret < 0) { errno = host_errno; }{...} return ret; }{ ... } static inline int semihosting_rename(const char *old_path, const char *new_path) { int host_errno = 0; long args[] = {(long)old_path, strlen(old_path), (long)new_path, strlen(new_path)}; int ret = (int)semihosting_call(SEMIHOSTING_SYS_RENAME, args, &host_errno); if (ret < 0) { errno = host_errno; }{...} return ret; }{ ... } static inline int semihosting_link(const char *path1, const char *path2) { int host_errno = 0; long args[] = {(long)path1, strlen(path1), (long)path2, strlen(path2)}; int ret = (int)semihosting_call(ESP_SEMIHOSTING_SYS_LINK, args, &host_errno); if (ret < 0) { errno = host_errno; }{...} return ret; }{ ... } static inline int semihosting_unlink(const char *path) { int host_errno = 0; long args[] = {(long)path, strlen(path), 0, 0}; int ret = (int)semihosting_call(ESP_SEMIHOSTING_SYS_UNLINK, args, &host_errno); if (ret < 0) { errno = host_errno; }{...} return ret; }{ ... } static inline int semihosting_opendir(const char *path, long offset) { int host_errno = 0; long args[] = {(long)path, strlen(path), offset, 0}; int ret = (int)semihosting_call(ESP_SEMIHOSTING_SYS_OPENDIR, args, &host_errno); if (ret < 0) { errno = host_errno; }{...} return ret; }{ ... } static inline int semihosting_readdir(long struct_dirent_ptr, long offset) { int host_errno = 0; long args[] = {struct_dirent_ptr, offset, 0, 0}; int ret = (int)semihosting_call(ESP_SEMIHOSTING_SYS_READDIR, args, &host_errno); if (ret < 0) { errno = host_errno; }{...} return ret; }{ ... } static inline int semihosting_closedir(long id) { int host_errno = 0; long args[] = {id, 0, 0, 0}; int ret = (int)semihosting_call(ESP_SEMIHOSTING_SYS_CLOSEDIR, args, &host_errno); if (ret < 0) { errno = host_errno; }{...} return ret; }{ ... } static inline long semihosting_telldir(long id) { int host_errno = 0; long args[] = {id, 0, 0, 0}; long ret = semihosting_call(ESP_SEMIHOSTING_SYS_TELLDIR, args, &host_errno); if (ret < 0) { errno = host_errno; }{...} return ret; }{ ... } static inline int semihosting_seekdir(long id, long offset) { int host_errno = 0; long args[] = {id, offset, 0, 0}; int ret = (int)semihosting_call(ESP_SEMIHOSTING_SYS_SEEKDIR, args, &host_errno); if (ret < 0) { errno = host_errno; }{...} return ret; }{ ... } /* ... */#endif #ifdef __cplusplus }{...} #endif
Details
Show:
from
Types: Columns:
This file uses the notable symbols shown below. Click anywhere in the file to view more details.