OpenOCD
semihosting_common.c File Reference

Common ARM semihosting support. More...

Include dependency graph for semihosting_common.c:

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...
 

Detailed Description

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.

Enumeration Type Documentation

◆ anonymous enum

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.

Function Documentation

◆ COMMAND_HANDLER() [1/7]

COMMAND_HANDLER ( handle_common_semihosting_basedir_command  )

◆ COMMAND_HANDLER() [2/7]

COMMAND_HANDLER ( handle_common_semihosting_cmdline  )

◆ COMMAND_HANDLER() [3/7]

◆ COMMAND_HANDLER() [4/7]

COMMAND_HANDLER ( handle_common_semihosting_fileio_command  )

◆ COMMAND_HANDLER() [5/7]

COMMAND_HANDLER ( handle_common_semihosting_read_user_param_command  )

◆ COMMAND_HANDLER() [6/7]

◆ COMMAND_HANDLER() [7/7]

COMMAND_HANDLER ( handle_common_semihosting_resumable_exit_command  )

◆ semihosting_common()

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:

  • field 1 Contains a pointer to the bound command parameter string
  • field 2 Contains the command parameter string length

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().

◆ semihosting_common_fileio_end()

◆ semihosting_common_fileio_info()

static int semihosting_common_fileio_info ( struct target target,
struct gdb_fileio_info fileio_info 
)
static

◆ semihosting_common_init()

◆ semihosting_get_field()

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().

◆ semihosting_getchar()

static int semihosting_getchar ( struct semihosting semihosting,
int  fd 
)
inlinestatic

Definition at line 280 of file semihosting_common.c.

References semihosting_is_redirected(), and semihosting_redirect_read().

Referenced by semihosting_common().

◆ semihosting_is_redirected()

◆ semihosting_opcode_to_str()

◆ semihosting_putchar()

static int semihosting_putchar ( struct semihosting semihosting,
int  fd,
int  c 
)
inlinestatic

Definition at line 258 of file semihosting_common.c.

References semihosting_is_redirected(), and semihosting_redirect_write().

Referenced by semihosting_common().

◆ semihosting_read()

static ssize_t semihosting_read ( struct semihosting semihosting,
int  fd,
void *  buf,
int  size 
)
inlinestatic

◆ semihosting_read_fields()

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().

◆ semihosting_redirect_read()

static ssize_t semihosting_redirect_read ( struct semihosting semihosting,
void *  buf,
int  size 
)
static

◆ semihosting_redirect_write()

static ssize_t semihosting_redirect_write ( struct semihosting semihosting,
void *  buf,
int  size 
)
static

◆ semihosting_service_connection_closed_handler()

static int semihosting_service_connection_closed_handler ( struct connection connection)
static

Definition at line 1802 of file semihosting_common.c.

References ERROR_OK, service::name, service::priv, and connection::service.

◆ semihosting_service_input_handler()

static int semihosting_service_input_handler ( struct connection connection)
static

◆ semihosting_service_new_connection_handler()

static int semihosting_service_new_connection_handler ( struct connection connection)
static

Definition at line 1771 of file semihosting_common.c.

References ERROR_OK, service::priv, and connection::service.

◆ semihosting_set_field()

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().

◆ semihosting_tcp_close_cnx()

static void semihosting_tcp_close_cnx ( struct semihosting semihosting)
static

Definition at line 1811 of file semihosting_common.c.

Referenced by COMMAND_HANDLER().

◆ semihosting_write()

static ssize_t semihosting_write ( struct semihosting semihosting,
int  fd,
void *  buf,
int  size 
)
static

◆ semihosting_write_fields()

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().

Variable Documentation

◆ open_gdb_modeflags

◆ open_host_modeflags

const int open_host_modeflags[12]
static
Initial value:
= {
O_RDONLY,
O_RDONLY | O_BINARY,
O_RDWR,
O_RDWR | O_BINARY,
O_WRONLY | O_CREAT | O_TRUNC,
O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
O_RDWR | O_CREAT | O_TRUNC,
O_RDWR | O_CREAT | O_TRUNC | O_BINARY,
O_WRONLY | O_CREAT | O_APPEND,
O_WRONLY | O_CREAT | O_APPEND | O_BINARY,
O_RDWR | O_CREAT | O_APPEND,
O_RDWR | O_CREAT | O_APPEND | O_BINARY
}
#define O_BINARY
Definition: replacements.h:37

Definition at line 76 of file semihosting_common.c.

Referenced by semihosting_common().

◆ semihosting_common_handlers

const struct command_registration semihosting_common_handlers[]

Definition at line 2077 of file semihosting_common.c.

◆ semihosting_service_driver

const struct service_driver semihosting_service_driver
static
Initial value:
= {
.name = "semihosting",
.new_connection_during_keep_alive_handler = NULL,
.new_connection_handler = semihosting_service_new_connection_handler,
.connection_closed_handler = semihosting_service_connection_closed_handler,
.keep_client_alive_handler = NULL,
}
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)
#define NULL
Definition: usb.h:16

Definition at line 1811 of file semihosting_common.c.

Referenced by COMMAND_HANDLER().

◆ semihosting_user_op_params

char* semihosting_user_op_params
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().