81 O_WRONLY | O_CREAT | O_TRUNC,
82 O_WRONLY | O_CREAT | O_TRUNC |
O_BINARY,
83 O_RDWR | O_CREAT | O_TRUNC,
84 O_RDWR | O_CREAT | O_TRUNC |
O_BINARY,
85 O_WRONLY | O_CREAT | O_APPEND,
86 O_WRONLY | O_CREAT | O_APPEND |
O_BINARY,
87 O_RDWR | O_CREAT | O_APPEND,
88 O_RDWR | O_CREAT | O_APPEND |
O_BINARY
94 int fileio_errno,
bool ctrl_c);
167 bool is_read_op =
false;
205 LOG_ERROR(
"No connected TCP client for semihosting");
226 int result = write(fd, buf,
size);
235 LOG_ERROR(
"No connected TCP client for semihosting");
273 ssize_t result = read(fd, buf,
size);
315 return "EXIT_EXTENDED";
319 return "GET_CMDLINE";
355 return "ARM_RESERVED_CMD";
451 if (fd == 0 || fd == 1 || fd == 2) {
452 LOG_DEBUG(
"ignoring semihosting attempt to close %s",
453 (fd == 0) ?
"stdin" :
454 (fd == 1) ?
"stdout" :
"stderr");
559 "semihosting: *** application exited with %d ***\n",
564 "semihosting: application exception %#x\n",
574 "semihosting: *** application exited normally ***\n");
583 "semihosting: *** application exited with error ***\n");
590 "semihosting: application exception %#x\n",
650 "semihosting: *** application exited with %d ***\n",
654 fprintf(stderr,
"semihosting: exception %#x\n",
738 uint32_t len = strlen(arg) + 1;
915 uint8_t *fn = malloc(basedir_len + len + 2);
920 if (basedir_len > 0) {
922 if (fn[basedir_len - 1] !=
'/')
923 fn[basedir_len++] =
'/';
930 fn[basedir_len + len] = 0;
934 if (strcmp((
char *)fn,
":semihosting-features") == 0) {
937 }
else if (strcmp((
char *)fn,
":tt") == 0) {
940 }
else if (
mode == 4) {
942 }
else if (
mode == 8) {
957 if (strcmp((
char *)fn,
":tt") == 0) {
964 fd = dup(STDIN_FILENO);
967 }
else if (
mode < 8) {
968 fd = dup(STDOUT_FILENO);
972 fd = dup(STDERR_FILENO);
1045 uint8_t *buf = malloc(len);
1051 LOG_DEBUG(
"read(%d, 0x%" PRIx64
", %zu)=%" PRId64,
1087 LOG_ERROR(
"SYS_READC not supported by semihosting fileio");
1122 uint8_t *fn = malloc(len+1);
1180 uint8_t *fn1 = malloc(len1+1);
1181 uint8_t *fn2 = malloc(len2+1);
1250 fileio_info->
param_3 = SEEK_SET;
1297 uint8_t *
cmd = malloc(len+1);
1381 uint8_t *buf = malloc(len);
1392 LOG_DEBUG(
"write(%d, 0x%" PRIx64
", %zu)=%" PRId64,
1514 LOG_ERROR(
"Failed to read fields for user defined command"
1523 LOG_ERROR(
"The maximum length for user defined command "
1524 "parameter is %u, received length is %zu (op=0x%x)",
1539 LOG_ERROR(
"Failed to read from target, semihosting op=0x%x (%s)",
1629 fprintf(stderr,
"semihosting: unsupported call %#x\n",
1638 LOG_ERROR(
"Failed to post semihosting result");
1668 int fileio_errno,
bool ctrl_c)
1700 bool fileio_failed =
false;
1785 const int buf_len = 100;
1789 if (bytes_read == 0) {
1791 }
else if (bytes_read == -1) {
1792 LOG_ERROR(
"error during read: %s", strerror(errno));
1823 .
name =
"semihosting",
1824 .new_connection_during_keep_alive_handler =
NULL,
1828 .keep_client_alive_handler =
NULL,
1860 LOG_ERROR(
"Failed to Configure semihosting");
1870 ?
"enabled" :
"disabled");
1901 if (strcmp(
CMD_ARGV[0],
"disable") == 0) {
1905 }
else if (strcmp(
CMD_ARGV[0],
"tcp") == 0) {
1906 if (CMD_ARGC < 2 || CMD_ARGC > 3)
1913 if (strcmp(
CMD_ARGV[2],
"debug") == 0)
1915 else if (strcmp(
CMD_ARGV[2],
"stdio") == 0)
1917 else if (strcmp(
CMD_ARGV[2],
"all") != 0)
1931 LOG_ERROR(
"Failed to allocate semihosting TCP service.");
1985 ?
"enabled" :
"disabled");
2048 ?
"enabled" :
"disabled");
2062 LOG_ERROR(
"semihosting not yet enabled for current target");
2067 LOG_ERROR(
"This command is usable only from a registered user "
2068 "semihosting event callback.");
2117 .
name =
"semihosting",
2118 .handler = handle_common_semihosting_command,
2120 .usage =
"['enable'|'disable']",
2121 .help =
"activate support for semihosting operations",
2124 .name =
"semihosting_redirect",
2125 .handler = handle_common_semihosting_redirect_command,
2127 .usage =
"(disable | tcp <port> ['debug'|'stdio'|'all'])",
2128 .help =
"redirect semihosting IO",
2131 .name =
"semihosting_cmdline",
2132 .handler = handle_common_semihosting_cmdline,
2134 .usage =
"arguments",
2135 .help =
"command line arguments to be passed to program",
2138 .name =
"semihosting_fileio",
2139 .handler = handle_common_semihosting_fileio_command,
2141 .usage =
"['enable'|'disable']",
2142 .help =
"activate support for semihosting fileio operations",
2145 .name =
"semihosting_resexit",
2146 .handler = handle_common_semihosting_resumable_exit_command,
2148 .usage =
"['enable'|'disable']",
2149 .help =
"activate support for semihosting resumable exit",
2152 .name =
"semihosting_read_user_param",
2153 .handler = handle_common_semihosting_read_user_param_command,
2156 .help =
"read parameters in semihosting-user-cmd-0x10X callbacks",
2159 .name =
"semihosting_basedir",
2160 .handler = handle_common_semihosting_basedir_command,
2163 .help =
"set the base directory for semihosting I/O operations",
static int post_result(struct target *target)
Support functions to access arbitrary bits in a byte array.
void command_print_sameline(struct command_invocation *cmd, const char *format,...)
void command_print(struct command_invocation *cmd, const char *format,...)
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
#define ERROR_COMMAND_SYNTAX_ERROR
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
#define COMMAND_PARSE_ENABLE(in, out)
parses an enable/disable command argument
#define CMD_CTX
Use this macro to access the context of the command being handled, rather than accessing the variable...
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
enum esirisc_reg_num number
int gdb_get_actual_connections(void)
void log_socket_error(const char *socket_desc)
char * alloc_printf(const char *format,...)
#define ERROR_NOT_IMPLEMENTED
#define LOG_ERROR(expr ...)
#define LOG_DEBUG(expr ...)
target_addr_t addr
Start address to search for the control block.
size_t size
Size of the control block search area.
int semihosting_common_init(struct target *target, void *setup, void *post_result)
Initialize common semihosting support.
static ssize_t semihosting_redirect_write(struct semihosting *semihosting, void *buf, int size)
static const int open_host_modeflags[12]
static int semihosting_common_fileio_end(struct target *target, int result, int fileio_errno, bool ctrl_c)
const struct command_registration semihosting_common_handlers[]
static int semihosting_service_connection_closed_handler(struct connection *connection)
uint64_t semihosting_get_field(struct target *target, size_t index, uint8_t *fields)
Extract a field from the buffer, considering register size and endianness.
static const int open_gdb_modeflags[12]
static const struct service_driver semihosting_service_driver
static int semihosting_service_input_handler(struct connection *connection)
static int semihosting_getchar(struct semihosting *semihosting, int fd)
COMMAND_HANDLER(handle_common_semihosting_command)
static ssize_t semihosting_redirect_read(struct semihosting *semihosting, void *buf, int size)
static int semihosting_putchar(struct semihosting *semihosting, int fd, int c)
static int semihosting_service_new_connection_handler(struct connection *connection)
static char * semihosting_user_op_params
User operation parameter string storage buffer.
int semihosting_common(struct target *target)
Portable implementation of ARM semihosting calls.
void semihosting_set_field(struct target *target, uint64_t value, size_t index, uint8_t *fields)
Store a field in the buffer, considering register size and endianness.
static ssize_t semihosting_read(struct semihosting *semihosting, int fd, void *buf, int size)
static ssize_t semihosting_write(struct semihosting *semihosting, int fd, void *buf, int size)
int semihosting_read_fields(struct target *target, size_t number, uint8_t *fields)
Read all fields of a command from target to buffer.
static bool semihosting_is_redirected(struct semihosting *semihosting, int fd)
static void semihosting_tcp_close_cnx(struct semihosting *semihosting)
static int semihosting_common_fileio_info(struct target *target, struct gdb_fileio_info *fileio_info)
int semihosting_write_fields(struct target *target, size_t number, uint8_t *fields)
Write all fields of a command from buffer to target.
const char * semihosting_opcode_to_str(const uint64_t opcode)
Convert the syscall opcode to a human-readable string.
semihosting_redirect_config
@ SEMIHOSTING_REDIRECT_CFG_ALL
@ SEMIHOSTING_REDIRECT_CFG_DEBUG
@ SEMIHOSTING_REDIRECT_CFG_NONE
@ SEMIHOSTING_REDIRECT_CFG_STDIO
@ ADP_STOPPED_RUN_TIME_ERROR
@ ADP_STOPPED_APPLICATION_EXIT
#define SEMIHOSTING_MAX_TCL_COMMAND_FIELD_LENGTH
Maximum allowed Tcl command segment length in bytes.
@ SEMIHOSTING_SYS_TICKFREQ
@ SEMIHOSTING_USER_CMD_0X107
@ SEMIHOSTING_SYS_ISERROR
@ SEMIHOSTING_USER_CMD_0X1FF
@ SEMIHOSTING_SYS_GET_CMDLINE
@ SEMIHOSTING_SYS_EXIT_EXTENDED
@ SEMIHOSTING_ARM_RESERVED_END
@ SEMIHOSTING_ARM_RESERVED_START
@ SEMIHOSTING_SYS_HEAPINFO
@ SEMIHOSTING_SYS_ELAPSED
@ SEMIHOSTING_USER_CMD_0X100
int connection_write(struct connection *connection, const void *data, int len)
int connection_read(struct connection *connection, void *data, int len)
int remove_service(const char *name, const char *port)
int add_service(const struct service_driver *driver, const char *port, int max_connections, void *priv)
#define ERROR_SERVER_REMOTE_CLOSED
struct semihosting * semihosting
bool is_resumable
Most are resumable, except the two exit calls.
int stdin_fd
Semihosting STDIO file descriptors.
bool has_resumable_exit
When SEMIHOSTING_SYS_EXIT is called outside a debug session, things are simple, the openocd process c...
int(* setup)(struct target *target, int enable)
int(* post_result)(struct target *target)
bool hit_fileio
A flag reporting whether semihosting fileio operation is active.
size_t word_size_bytes
The Target (hart) word size; 8 for 64-bits targets.
bool is_fileio
A flag reporting whether semihosting fileio is active.
int(* user_command_extension)(struct target *target)
Target's extension of semihosting user commands.
int64_t result
The current semihosting result to be returned to the application.
char * basedir
Base directory for semihosting I/O operations.
bool is_active
A flag reporting whether semihosting is active.
int op
The current semihosting operation (R0 on ARM).
struct connection * tcp_connection
Handle to redirect semihosting print via tcp.
int sys_errno
The value to be returned by semihosting SYS_ERRNO request.
enum semihosting_redirect_config redirect_cfg
redirection configuration, NONE by default
uint64_t param
The current semihosting parameter (R1 or ARM).
char * cmdline
The semihosting command line to be passed to the target.
clock_t setup_time
The current time when 'execution starts'.
const char * name
the name of the server
int(* gdb_fileio_end)(struct target *target, int retcode, int fileio_errno, bool ctrl_c)
int(* get_gdb_fileio_info)(struct target *target, struct gdb_fileio_info *fileio_info)
struct semihosting * semihosting
struct gdb_fileio_info * fileio_info
struct target_type * type
uint64_t target_buffer_get_u64(struct target *target, const uint8_t *buffer)
int target_call_event_callbacks(struct target *target, enum target_event event)
void target_buffer_set_u32(struct target *target, uint8_t *buffer, uint32_t value)
int target_write_buffer(struct target *target, target_addr_t address, uint32_t size, const uint8_t *buffer)
int target_read_buffer(struct target *target, target_addr_t address, uint32_t size, uint8_t *buffer)
int target_write_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
Write count items of size bytes to the memory of target at the address given.
void target_buffer_set_u64(struct target *target, uint8_t *buffer, uint64_t value)
int target_read_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer)
Read count items of size bytes from the memory of target at the address given.
struct target * get_current_target(struct command_context *cmd_ctx)
void target_handle_event(struct target *target, enum target_event e)
uint32_t target_buffer_get_u32(struct target *target, const uint8_t *buffer)
static bool target_was_examined(const struct target *target)
static const char * target_name(const struct target *target)
Returns the instance-specific name of the specified target.