Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Semihosting in BMP #1686

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/gdb_hostio.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,18 @@ int hostio_reply(target_controller_s *const tc, char *const pbuf, const int len)
static int hostio_get_response(target_controller_s *const tc)
{
char *const packet_buffer = gdb_packet_buffer();
const size_t size = gdb_getpacket(packet_buffer, GDB_PACKET_BUFFER_SIZE);
return gdb_main_loop(tc, packet_buffer, GDB_PACKET_BUFFER_SIZE, size, true);
/* Still have to service normal 'X'/'m'-packets */
while (true) {
/* Get back the next packet to process and have the main loop handle it */
const size_t size = gdb_getpacket(packet_buffer, GDB_PACKET_BUFFER_SIZE);
/* If this was an escape packet (or gdb_if reports link closed), fail the call */
if (size == 1U && packet_buffer[0] == '\x04')
return -1;
const int result = gdb_main_loop(tc, packet_buffer, GDB_PACKET_BUFFER_SIZE, size, true);
/* If this was an F-packet, we're done */
if (packet_buffer[0] == 'F')
return result;
}
}

/* Interface to host system calls */
Expand Down
48 changes: 46 additions & 2 deletions src/target/cortexm.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,42 @@ typedef struct cortexm_priv {
uint32_t demcr;
} cortexm_priv_s;

#ifdef ENABLE_DEBUG
const char *const semihosting_names[] = {
"",
"SYS_OPEN",
"SYS_CLOSE",
"SYS_WRITEC",
"SYS_WRITE0",
"SYS_WRITE",
"SYS_READ",
"SYS_READC",
"SYS_ISERROR",
"SYS_ISTTY",
"SYS_SEEK",
"0x0b",
"SYS_FLEN",
"SYS_TMPNAM",
"SYS_REMOVE",
"SYS_RENAME",
"SYS_CLOCK",
"SYS_TIME",
"SYS_SYSTEM",
"SYS_ERRNO",
"0x14",
"SYS_GET_CMDLINE",
"SYS_HEAPINFO",
"0x17",
[SEMIHOSTING_SYS_EXIT] = "SYS_EXIT",
/* 7 reserved */
[SEMIHOSTING_SYS_EXIT_EXTENDED] = "SYS_EXIT_EXTENDED",
/* 15 reserved */
[SEMIHOSTING_SYS_ELAPSED] = "SYS_ELAPSED",
[SEMIHOSTING_SYS_TICKFREQ] = "SYS_TICKFREQ",
"",
};
#endif

/* Register number tables */
static const uint32_t regnum_cortex_m[CORTEXM_GENERAL_REG_COUNT] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, /* standard r0-r15 */
Expand Down Expand Up @@ -1434,8 +1470,16 @@ static int cortexm_hostio_request(target_s *target)
target_mem_read(target, params, arm_regs[1], sizeof(params));
int32_t ret = 0;

DEBUG_INFO("syscall 0" PRIx32 "%" PRIx32 " (%" PRIx32 " %" PRIx32 " %" PRIx32 " %" PRIx32 ")\n", syscall, params[0],
params[1], params[2], params[3]);
#ifdef ENABLE_DEBUG
const char *syscall_descr = NULL;
if (syscall < ARRAY_LENGTH(semihosting_names))
syscall_descr = semihosting_names[syscall];
if (syscall_descr == NULL)
syscall_descr = "";

DEBUG_INFO("syscall %12s (%" PRIx32 " %" PRIx32 " %" PRIx32 " %" PRIx32 ")\n", syscall_descr, params[0], params[1],
params[2], params[3]);
#endif
switch (syscall) {
#if PC_HOSTED == 1

Expand Down