80 O_WRONLY | O_CREAT | O_TRUNC,
81 O_WRONLY | O_CREAT | O_TRUNC |
O_BINARY,
82 O_RDWR | O_CREAT | O_TRUNC,
83 O_RDWR | O_CREAT | O_TRUNC |
O_BINARY,
84 O_WRONLY | O_CREAT | O_APPEND,
85 O_WRONLY | O_CREAT | O_APPEND |
O_BINARY,
86 O_RDWR | O_CREAT | O_APPEND,
87 O_RDWR | O_CREAT | O_APPEND |
O_BINARY
93 int fileio_errno,
bool ctrl_c);
169 bool is_read_op =
false;
207 LOG_ERROR(
"No connected TCP client for semihosting");
228 return write(fd, buf,
size);
234 LOG_ERROR(
"No connected TCP client for semihosting");
272 ssize_t result = read(fd, buf,
size);
388 if (fd == 0 || fd == 1 || fd == 2) {
389 LOG_DEBUG(
"ignoring semihosting attempt to close %s",
390 (fd == 0) ?
"stdin" :
391 (fd == 1) ?
"stdout" :
"stderr");
500 "semihosting: *** application exited with %d ***\n",
505 "semihosting: application exception %#x\n",
515 "semihosting: *** application exited normally ***\n");
524 "semihosting: *** application exited with error ***\n");
531 "semihosting: application exception %#x\n",
591 "semihosting: *** application exited with %d ***\n",
595 fprintf(stderr,
"semihosting: exception %#x\n",
679 uint32_t len = strlen(arg) + 1;
854 uint8_t *fn = malloc(basedir_len + len + 2);
859 if (basedir_len > 0) {
861 if (fn[basedir_len - 1] !=
'/')
862 fn[basedir_len++] =
'/';
869 fn[basedir_len + len] = 0;
873 if (strcmp((
char *)fn,
":semihosting-features") == 0) {
876 }
else if (strcmp((
char *)fn,
":tt") == 0) {
894 if (strcmp((
char *)fn,
":tt") == 0) {
900 int fd = dup(STDIN_FILENO);
905 }
else if (
mode < 8) {
906 int fd = dup(STDOUT_FILENO);
912 int fd = dup(STDERR_FILENO);
983 uint8_t *buf = malloc(len);
989 LOG_DEBUG(
"read(%d, 0x%" PRIx64
", %zu)=%" PRId64,
1025 LOG_ERROR(
"SYS_READC not supported by semihosting fileio");
1060 uint8_t *fn = malloc(len+1);
1117 uint8_t *fn1 = malloc(len1+1);
1118 uint8_t *fn2 = malloc(len2+1);
1185 fileio_info->
param_3 = SEEK_SET;
1231 uint8_t *
cmd = malloc(len+1);
1315 uint8_t *buf = malloc(len);
1327 LOG_DEBUG(
"write(%d, 0x%" PRIx64
", %zu)=%" PRId64,
1449 LOG_ERROR(
"Failed to read fields for user defined command"
1458 LOG_ERROR(
"The maximum length for user defined command "
1459 "parameter is %u, received length is %zu (op=0x%x)",
1474 LOG_ERROR(
"Failed to read from target, semihosting op=0x%x",
1563 fprintf(stderr,
"semihosting: unsupported call %#x\n",
1572 LOG_ERROR(
"Failed to post semihosting result");
1602 int fileio_errno,
bool ctrl_c)
1709 const int buf_len = 100;
1713 if (bytes_read == 0) {
1715 }
else if (bytes_read == -1) {
1716 LOG_ERROR(
"error during read: %s", strerror(errno));
1749 .
name =
"semihosting",
1750 .new_connection_during_keep_alive_handler =
NULL,
1754 .keep_client_alive_handler =
NULL,
1786 LOG_ERROR(
"Failed to Configure semihosting");
1796 ?
"enabled" :
"disabled");
1827 if (strcmp(
CMD_ARGV[0],
"disable") == 0) {
1831 }
else if (strcmp(
CMD_ARGV[0],
"tcp") == 0) {
1832 if (CMD_ARGC < 2 || CMD_ARGC > 3)
1839 if (strcmp(
CMD_ARGV[2],
"debug") == 0)
1841 else if (strcmp(
CMD_ARGV[2],
"stdio") == 0)
1843 else if (strcmp(
CMD_ARGV[2],
"all") != 0)
1857 LOG_ERROR(
"Failed to allocate semihosting TCP service.");
1911 ?
"enabled" :
"disabled");
1974 ?
"enabled" :
"disabled");
1988 LOG_ERROR(
"semihosting not yet enabled for current target");
1993 LOG_ERROR(
"This command is usable only from a registered user "
1994 "semihosting event callback.");
2043 .
name =
"semihosting",
2044 .handler = handle_common_semihosting_command,
2046 .usage =
"['enable'|'disable']",
2047 .help =
"activate support for semihosting operations",
2050 .name =
"semihosting_redirect",
2051 .handler = handle_common_semihosting_redirect_command,
2053 .usage =
"(disable | tcp <port> ['debug'|'stdio'|'all'])",
2054 .help =
"redirect semihosting IO",
2057 .name =
"semihosting_cmdline",
2058 .handler = handle_common_semihosting_cmdline,
2060 .usage =
"arguments",
2061 .help =
"command line arguments to be passed to program",
2064 .name =
"semihosting_fileio",
2065 .handler = handle_common_semihosting_fileio_command,
2067 .usage =
"['enable'|'disable']",
2068 .help =
"activate support for semihosting fileio operations",
2071 .name =
"semihosting_resexit",
2072 .handler = handle_common_semihosting_resumable_exit_command,
2074 .usage =
"['enable'|'disable']",
2075 .help =
"activate support for semihosting resumable exit",
2078 .name =
"semihosting_read_user_param",
2079 .handler = handle_common_semihosting_read_user_param_command,
2082 .help =
"read parameters in semihosting-user-cmd-0x10X callbacks",
2085 .name =
"semihosting_basedir",
2086 .handler = handle_common_semihosting_basedir_command,
2089 .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
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 ...)
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)
int gdb_actual_connections
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.
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_SYS_GET_CMDLINE
@ SEMIHOSTING_SYS_EXIT_EXTENDED
@ 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 const char * target_name(struct target *target)
Returns the instance-specific name of the specified target.
static bool target_was_examined(struct target *target)