OpenOCD
|
Common ARM semihosting support. More...
Go to the source code of this file.
Data Structures | |
struct | semihosting_tcp_service |
Enumerations | |
enum | { TARGET_O_RDONLY = 0x000 , TARGET_O_WRONLY = 0x001 , TARGET_O_RDWR = 0x002 , TARGET_O_APPEND = 0x008 , TARGET_O_CREAT = 0x200 , TARGET_O_TRUNC = 0x400 } |
It is not possible to use O_... More... | |
Functions | |
COMMAND_HANDLER (handle_common_semihosting_basedir_command) | |
COMMAND_HANDLER (handle_common_semihosting_cmdline) | |
COMMAND_HANDLER (handle_common_semihosting_command) | |
COMMAND_HANDLER (handle_common_semihosting_fileio_command) | |
COMMAND_HANDLER (handle_common_semihosting_read_user_param_command) | |
COMMAND_HANDLER (handle_common_semihosting_redirect_command) | |
COMMAND_HANDLER (handle_common_semihosting_resumable_exit_command) | |
int | semihosting_common (struct target *target) |
Portable implementation of ARM semihosting calls. More... | |
static int | semihosting_common_fileio_end (struct target *target, int result, int fileio_errno, bool ctrl_c) |
static int | semihosting_common_fileio_info (struct target *target, struct gdb_fileio_info *fileio_info) |
int | semihosting_common_init (struct target *target, void *setup, void *post_result) |
Initialize common semihosting support. More... | |
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. More... | |
static int | semihosting_getchar (struct semihosting *semihosting, int fd) |
static bool | semihosting_is_redirected (struct semihosting *semihosting, int fd) |
const char * | semihosting_opcode_to_str (const uint64_t opcode) |
Convert the syscall opcode to a human-readable string. More... | |
static int | semihosting_putchar (struct semihosting *semihosting, int fd, int c) |
static ssize_t | semihosting_read (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. More... | |
static ssize_t | semihosting_redirect_read (struct semihosting *semihosting, void *buf, int size) |
static ssize_t | semihosting_redirect_write (struct semihosting *semihosting, void *buf, int size) |
static int | semihosting_service_connection_closed_handler (struct connection *connection) |
static int | semihosting_service_input_handler (struct connection *connection) |
static int | semihosting_service_new_connection_handler (struct connection *connection) |
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. More... | |
static void | semihosting_tcp_close_cnx (struct semihosting *semihosting) |
static ssize_t | semihosting_write (struct semihosting *semihosting, int fd, void *buf, int size) |
int | semihosting_write_fields (struct target *target, size_t number, uint8_t *fields) |
Write all fields of a command from buffer to target. More... | |
Variables | |
static const int | open_gdb_modeflags [12] |
static const int | open_host_modeflags [12] |
const struct command_registration | semihosting_common_handlers [] |
static const struct service_driver | semihosting_service_driver |
static char * | semihosting_user_op_params |
User operation parameter string storage buffer. More... | |
Common ARM semihosting support.
Semihosting enables code running on a target to use some of the I/O facilities on the host computer. The target application must be linked against a library that forwards operation requests by using an instruction trapped by the debugger.
Details can be found in "Semihosting for AArch32 and AArch64, Release 2.0" https://static.docs.arm.com/100863/0200/semihosting.pdf from ARM Ltd.
Definition in file semihosting_common.c.
anonymous enum |
It is not possible to use O_...
flags defined in sys/stat.h because they are not guaranteed to match the values defined by the GDB Remote Protocol. See https://sourceware.org/gdb/onlinedocs/gdb/Open-Flags.html#Open-Flags
Enumerator | |
---|---|
TARGET_O_RDONLY | |
TARGET_O_WRONLY | |
TARGET_O_RDWR | |
TARGET_O_APPEND | |
TARGET_O_CREAT | |
TARGET_O_TRUNC |
Definition at line 50 of file semihosting_common.c.
COMMAND_HANDLER | ( | handle_common_semihosting_basedir_command | ) |
Definition at line 2077 of file semihosting_common.c.
References semihosting::basedir, CMD, CMD_ARGC, CMD_ARGV, CMD_CTX, command_print(), ERROR_COMMAND_SYNTAX_ERROR, ERROR_FAIL, ERROR_OK, get_current_target(), semihosting::is_active, LOG_ERROR, and target::semihosting.
COMMAND_HANDLER | ( | handle_common_semihosting_cmdline | ) |
Definition at line 1990 of file semihosting_common.c.
References alloc_printf(), CMD, CMD_ARGC, CMD_ARGV, CMD_CTX, semihosting::cmdline, command_print(), ERROR_FAIL, ERROR_OK, get_current_target(), LOG_ERROR, NULL, and target::semihosting.
COMMAND_HANDLER | ( | handle_common_semihosting_command | ) |
Definition at line 1834 of file semihosting_common.c.
References CMD, CMD_ARGC, CMD_ARGV, CMD_CTX, COMMAND_PARSE_ENABLE, command_print(), ERROR_FAIL, ERROR_OK, get_current_target(), semihosting::is_active, LOG_ERROR, target::semihosting, semihosting::setup, and target_was_examined().
COMMAND_HANDLER | ( | handle_common_semihosting_fileio_command | ) |
Definition at line 1960 of file semihosting_common.c.
References CMD, CMD_ARGC, CMD_ARGV, CMD_CTX, COMMAND_PARSE_ENABLE, command_print(), ERROR_FAIL, ERROR_OK, get_current_target(), semihosting::is_active, semihosting::is_fileio, LOG_ERROR, and target::semihosting.
COMMAND_HANDLER | ( | handle_common_semihosting_read_user_param_command | ) |
Definition at line 2053 of file semihosting_common.c.
References CMD, CMD_ARGC, CMD_CTX, command_print_sameline(), ERROR_COMMAND_SYNTAX_ERROR, ERROR_FAIL, ERROR_OK, get_current_target(), semihosting::is_active, LOG_ERROR, target::semihosting, and semihosting_user_op_params.
COMMAND_HANDLER | ( | handle_common_semihosting_redirect_command | ) |
Definition at line 1875 of file semihosting_common.c.
References add_service(), alloc_printf(), CMD, CMD_ARGC, CMD_ARGV, CMD_CTX, command_print(), ERROR_COMMAND_SYNTAX_ERROR, ERROR_FAIL, ERROR_OK, get_current_target(), semihosting::is_active, LOG_ERROR, service::name, semihosting::redirect_cfg, semihosting_tcp_service::semihosting, target::semihosting, SEMIHOSTING_REDIRECT_CFG_ALL, SEMIHOSTING_REDIRECT_CFG_DEBUG, SEMIHOSTING_REDIRECT_CFG_NONE, SEMIHOSTING_REDIRECT_CFG_STDIO, semihosting_service_driver, semihosting_tcp_close_cnx(), and target_name().
COMMAND_HANDLER | ( | handle_common_semihosting_resumable_exit_command | ) |
Definition at line 2023 of file semihosting_common.c.
References CMD, CMD_ARGC, CMD_ARGV, CMD_CTX, COMMAND_PARSE_ENABLE, command_print(), ERROR_FAIL, ERROR_OK, get_current_target(), semihosting::has_resumable_exit, semihosting::is_active, LOG_ERROR, and target::semihosting.
int semihosting_common | ( | struct target * | target | ) |
Portable implementation of ARM semihosting calls.
Performs the currently pending semihosting operation encoded in target->semihosting.
This is a user defined operation (while user cmds 0x100-0x1ff are possible, only 0x100-0x107 are currently implemented).
Reads the user operation parameters from target, then fires the corresponding target event. When the target callbacks returned, cleans up the command parameter buffer.
Entry On entry, the PARAMETER REGISTER contains a pointer to a two-field data block:
Return On exit, the RETURN REGISTER contains the return status.
Definition at line 366 of file semihosting_common.c.
References addr, ADP_STOPPED_APPLICATION_EXIT, ADP_STOPPED_RUN_TIME_ERROR, semihosting::basedir, cmd, semihosting::cmdline, count, ENOTSUP, ERROR_FAIL, ERROR_NOT_IMPLEMENTED, ERROR_OK, target::fileio_info, gdb_get_actual_connections(), semihosting::has_resumable_exit, semihosting::hit_fileio, gdb_fileio_info::identifier, semihosting::is_fileio, semihosting::is_resumable, LOG_DEBUG, LOG_ERROR, mode, NULL, semihosting::op, open_gdb_modeflags, open_host_modeflags, semihosting::param, gdb_fileio_info::param_1, gdb_fileio_info::param_2, gdb_fileio_info::param_3, gdb_fileio_info::param_4, semihosting::post_result, semihosting::result, target::semihosting, semihosting_get_field(), semihosting_getchar(), SEMIHOSTING_MAX_TCL_COMMAND_FIELD_LENGTH, semihosting_opcode_to_str(), semihosting_putchar(), semihosting_read(), semihosting_read_fields(), semihosting_set_field(), SEMIHOSTING_SYS_CLOCK, SEMIHOSTING_SYS_CLOSE, SEMIHOSTING_SYS_ELAPSED, SEMIHOSTING_SYS_ERRNO, SEMIHOSTING_SYS_EXIT, SEMIHOSTING_SYS_EXIT_EXTENDED, SEMIHOSTING_SYS_FLEN, SEMIHOSTING_SYS_GET_CMDLINE, SEMIHOSTING_SYS_HEAPINFO, SEMIHOSTING_SYS_ISERROR, SEMIHOSTING_SYS_ISTTY, SEMIHOSTING_SYS_OPEN, SEMIHOSTING_SYS_READ, SEMIHOSTING_SYS_READC, SEMIHOSTING_SYS_REMOVE, SEMIHOSTING_SYS_RENAME, SEMIHOSTING_SYS_SEEK, SEMIHOSTING_SYS_SYSTEM, SEMIHOSTING_SYS_TICKFREQ, SEMIHOSTING_SYS_TIME, SEMIHOSTING_SYS_TMPNAM, SEMIHOSTING_SYS_WRITE, SEMIHOSTING_SYS_WRITE0, SEMIHOSTING_SYS_WRITEC, SEMIHOSTING_USER_CMD_0X100, SEMIHOSTING_USER_CMD_0X107, semihosting_user_op_params, semihosting_write(), semihosting_write_fields(), semihosting::setup_time, size, semihosting::stderr_fd, semihosting::stdin_fd, semihosting::stdout_fd, semihosting::sys_errno, target_call_event_callbacks(), TARGET_EVENT_HALTED, target_handle_event(), target_read_buffer(), target_read_memory(), target_write_buffer(), target_write_memory(), type, semihosting::user_command_extension, and semihosting::word_size_bytes.
Referenced by arm_semihosting(), and esp_xtensa_semihosting().
|
static |
Definition at line 1667 of file semihosting_common.c.
References ERROR_FAIL, target::fileio_info, semihosting::hit_fileio, semihosting::op, gdb_fileio_info::param_3, semihosting::post_result, semihosting::result, target::semihosting, SEMIHOSTING_SYS_ISTTY, SEMIHOSTING_SYS_READ, SEMIHOSTING_SYS_RENAME, SEMIHOSTING_SYS_SEEK, SEMIHOSTING_SYS_WRITE, and semihosting::sys_errno.
Referenced by semihosting_common_init().
|
static |
Definition at line 1649 of file semihosting_common.c.
References ERROR_FAIL, ERROR_OK, semihosting::hit_fileio, semihosting::is_fileio, and target::semihosting.
Referenced by semihosting_common_init().
int semihosting_common_init | ( | struct target * | target, |
void * | setup, | ||
void * | post_result | ||
) |
Initialize common semihosting support.
target | Pointer to the target to initialize. |
setup | |
post_result |
Definition at line 104 of file semihosting_common.c.
References semihosting::basedir, semihosting::cmdline, ERROR_FAIL, ERROR_OK, target::fileio_info, target_type::gdb_fileio_end, target_type::get_gdb_fileio_info, semihosting::has_resumable_exit, semihosting::hit_fileio, semihosting::is_active, semihosting::is_fileio, semihosting::is_resumable, LOG_DEBUG, LOG_ERROR, NULL, semihosting::op, semihosting::param, post_result(), semihosting::post_result, semihosting::redirect_cfg, semihosting::result, target::semihosting, semihosting_common_fileio_end(), semihosting_common_fileio_info(), SEMIHOSTING_REDIRECT_CFG_NONE, semihosting::setup, semihosting::setup_time, semihosting::stderr_fd, semihosting::stdin_fd, semihosting::stdout_fd, semihosting::sys_errno, semihosting::tcp_connection, target::type, semihosting::user_command_extension, and semihosting::word_size_bytes.
Referenced by arm_semihosting_init(), riscv_semihosting(), and xtensa_semihosting_init().
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.
Definition at line 1744 of file semihosting_common.c.
References target::semihosting, target_buffer_get_u32(), target_buffer_get_u64(), and semihosting::word_size_bytes.
Referenced by esp_semihosting_common(), and semihosting_common().
|
inlinestatic |
Definition at line 280 of file semihosting_common.c.
References semihosting_is_redirected(), and semihosting_redirect_read().
Referenced by semihosting_common().
|
static |
Definition at line 162 of file semihosting_common.c.
References semihosting::op, semihosting::redirect_cfg, SEMIHOSTING_REDIRECT_CFG_DEBUG, SEMIHOSTING_REDIRECT_CFG_NONE, SEMIHOSTING_REDIRECT_CFG_STDIO, SEMIHOSTING_SYS_READ, SEMIHOSTING_SYS_READC, SEMIHOSTING_SYS_WRITE, SEMIHOSTING_SYS_WRITE0, SEMIHOSTING_SYS_WRITEC, semihosting::stderr_fd, semihosting::stdin_fd, and semihosting::stdout_fd.
Referenced by semihosting_getchar(), semihosting_putchar(), semihosting_read(), and semihosting_write().
const char* semihosting_opcode_to_str | ( | uint64_t | opcode | ) |
Convert the syscall opcode to a human-readable string.
[in] | opcode | Syscall opcode |
Definition at line 301 of file semihosting_common.c.
References SEMIHOSTING_ARM_RESERVED_END, SEMIHOSTING_ARM_RESERVED_START, SEMIHOSTING_SYS_CLOCK, SEMIHOSTING_SYS_CLOSE, SEMIHOSTING_SYS_ELAPSED, SEMIHOSTING_SYS_ERRNO, SEMIHOSTING_SYS_EXIT, SEMIHOSTING_SYS_EXIT_EXTENDED, SEMIHOSTING_SYS_FLEN, SEMIHOSTING_SYS_GET_CMDLINE, SEMIHOSTING_SYS_HEAPINFO, SEMIHOSTING_SYS_ISERROR, SEMIHOSTING_SYS_ISTTY, SEMIHOSTING_SYS_OPEN, SEMIHOSTING_SYS_READ, SEMIHOSTING_SYS_READC, SEMIHOSTING_SYS_REMOVE, SEMIHOSTING_SYS_RENAME, SEMIHOSTING_SYS_SEEK, SEMIHOSTING_SYS_SYSTEM, SEMIHOSTING_SYS_TICKFREQ, SEMIHOSTING_SYS_TIME, SEMIHOSTING_SYS_TMPNAM, SEMIHOSTING_SYS_WRITE, SEMIHOSTING_SYS_WRITE0, SEMIHOSTING_SYS_WRITEC, SEMIHOSTING_USER_CMD_0X100, and SEMIHOSTING_USER_CMD_0X1FF.
Referenced by semihosting_common().
|
inlinestatic |
Definition at line 258 of file semihosting_common.c.
References semihosting_is_redirected(), and semihosting_redirect_write().
Referenced by semihosting_common().
|
inlinestatic |
Definition at line 267 of file semihosting_common.c.
References semihosting_is_redirected(), semihosting_redirect_read(), size, and semihosting::sys_errno.
Referenced by semihosting_common().
int semihosting_read_fields | ( | struct target * | target, |
size_t | number, | ||
uint8_t * | fields | ||
) |
Read all fields of a command from target to buffer.
Definition at line 1720 of file semihosting_common.c.
References number, semihosting::param, target::semihosting, target_read_memory(), and semihosting::word_size_bytes.
Referenced by esp_semihosting_common(), and semihosting_common().
|
static |
Definition at line 232 of file semihosting_common.c.
References connection_read(), ERROR_OK, ERROR_SERVER_REMOTE_CLOSED, connection::input_pending, LOG_ERROR, log_socket_error(), service::name, service::priv, connection::service, size, semihosting::sys_errno, and semihosting::tcp_connection.
Referenced by semihosting_getchar(), and semihosting_read().
|
static |
Definition at line 202 of file semihosting_common.c.
References connection_write(), LOG_ERROR, log_socket_error(), service::name, service::priv, connection::service, size, semihosting::sys_errno, and semihosting::tcp_connection.
Referenced by semihosting_putchar(), and semihosting_write().
|
static |
Definition at line 1802 of file semihosting_common.c.
References ERROR_OK, service::name, service::priv, and connection::service.
|
static |
Definition at line 1779 of file semihosting_common.c.
References connection_read(), ERROR_OK, ERROR_SERVER_REMOTE_CLOSED, connection::input_pending, LOG_ERROR, service::priv, and connection::service.
|
static |
Definition at line 1771 of file semihosting_common.c.
References ERROR_OK, service::priv, and connection::service.
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.
Definition at line 1757 of file semihosting_common.c.
References target::semihosting, target_buffer_set_u32(), target_buffer_set_u64(), and semihosting::word_size_bytes.
Referenced by semihosting_common().
|
static |
Definition at line 1811 of file semihosting_common.c.
Referenced by COMMAND_HANDLER().
|
static |
Definition at line 220 of file semihosting_common.c.
References semihosting_is_redirected(), semihosting_redirect_write(), size, and semihosting::sys_errno.
Referenced by semihosting_common().
int semihosting_write_fields | ( | struct target * | target, |
size_t | number, | ||
uint8_t * | fields | ||
) |
Write all fields of a command from buffer to target.
Definition at line 1732 of file semihosting_common.c.
References number, semihosting::param, target::semihosting, target_write_memory(), and semihosting::word_size_bytes.
Referenced by semihosting_common().
|
static |
Definition at line 61 of file semihosting_common.c.
Referenced by semihosting_common().
|
static |
Definition at line 76 of file semihosting_common.c.
Referenced by semihosting_common().
const struct command_registration semihosting_common_handlers[] |
Definition at line 2077 of file semihosting_common.c.
|
static |
Definition at line 1811 of file semihosting_common.c.
Referenced by COMMAND_HANDLER().
|
static |
User operation parameter string storage buffer.
Contains valid data when the TARGET_EVENT_SEMIHOSTING_USER_CMD_xxxxx event callbacks are running.
Definition at line 299 of file semihosting_common.c.
Referenced by COMMAND_HANDLER(), and semihosting_common().