Skip to content

Fix: semihosting cleanup #1730

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

Merged
merged 39 commits into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
ca27e12
semihosting: Began fixing nomenclature
dragonmux Dec 21, 2023
12e7935
semihosting: Refactored out the SEMIHOSTING_SYS_OPEN logic into a new…
dragonmux Dec 21, 2023
e599619
semihosting: Implemented a structure for holding the details of a sem…
dragonmux Dec 21, 2023
5a3c19a
semihosting: Refactored out the SEMIHOSTING_SYS_CLOSE logic into a ne…
dragonmux Dec 21, 2023
d11e120
semihosting: Refactored out the SEMIHOSTING_SYS_READ logic into a new…
dragonmux Dec 21, 2023
479692b
semihosting: Refactored out the SEMIHOSTING_SYS_WRITE logic into a ne…
dragonmux Dec 21, 2023
baac18b
semihosting: Refactored out the SEMIHOSTING_SYS_WRITEC logic into a n…
dragonmux Dec 21, 2023
e98884c
semihosting: Refactored out the SEMIHOSTING_SYS_WRITE0 logic into a n…
dragonmux Dec 21, 2023
87be761
semihosting: Refactored out the SEMIHOSTING_SYS_ISTTY logic into a ne…
dragonmux Dec 21, 2023
56d1d9c
semihosting: Refactored out the SEMIHOSTING_SYS_SEEK logic into a new…
dragonmux Dec 21, 2023
36622dc
semihosting: Refactored out the file name readout logic into a new fu…
dragonmux Dec 21, 2023
6e126d1
semihosting: Refactored out the SEMIHOSTING_SYS_RENAME logic into a n…
dragonmux Dec 21, 2023
eee159f
semihosting: Refactored out the SEMIHOSTING_SYS_REMOVE logic into a n…
dragonmux Dec 21, 2023
7efdffc
semihosting: Refactored out the SEMIHOSTING_SYS_SYSTEM logic into a n…
dragonmux Dec 22, 2023
d1d7125
semihosting: Refactored out the SEMIHOSTING_SYS_FLEN logic into a new…
dragonmux Dec 22, 2023
6c6d158
semihosting: Refactored out the SEMIHOSTING_SYS_CLOCK logic into a ne…
dragonmux Dec 22, 2023
590dd86
semihosting: Refactored out the SEMIHOSTING_SYS_TIME logic into a new…
dragonmux Dec 22, 2023
b9e8685
semihosting: Refactored out the SEMIHOSTING_SYS_READC logic into a ne…
dragonmux Dec 22, 2023
f2340ea
semihosting: Cleaned up the SEMIHOSTING_SYS_ERRNO logic
dragonmux Dec 22, 2023
705af7e
semihosting: Eliminated `hostio_open()` by inling it in `semihosting_…
dragonmux Dec 22, 2023
f6cc2ad
semihosting: Eliminated `hostio_close()` by inling it in `semihosting…
dragonmux Dec 22, 2023
5df4eb7
semihosting: Eliminated `hostio_write()` by inling it in `tc_write()`
dragonmux Dec 22, 2023
3dc3774
semihosting: Eliminated `hostio_lseek()` by inling it in `semihosting…
dragonmux Dec 22, 2023
85676e9
semihosting: Eliminated `hostio_rename()` by inling it in `semihostin…
dragonmux Dec 22, 2023
fe84181
semihosting: Eliminated `hostio_unlink()` by inling it in `semihostin…
dragonmux Dec 22, 2023
d60b478
semihosting: Eliminated `hostio_system()` by inling it in `semihostin…
dragonmux Dec 22, 2023
a88d58a
semihosting: Eliminated `hostio_isatty()` by inling it in `semihostin…
dragonmux Dec 22, 2023
fa5da9d
semihosting: Eliminated `hostio_gettimeofday()` by inling it in `semi…
dragonmux Dec 22, 2023
984e10d
semihosting: Eliminated `hostio_fstat()` by inling it in `semihosting…
dragonmux Dec 22, 2023
c97df35
semihosting: Eliminated `hostio_stat()` as it's unused anywhere
dragonmux Dec 22, 2023
18f2189
semihosting: Types and `static` fixes
dragonmux Dec 22, 2023
5bd0415
semihosting: Split out the Cortex-M specific stuff from the main semi…
dragonmux Dec 22, 2023
644c147
semihosting: Cleanup in the main request handler
dragonmux Dec 22, 2023
94e56b6
semihosting: Refactored out the SEMIHOSTING_SYS_GET_CMDLINE logic int…
dragonmux Dec 29, 2023
c177364
semihosting: Refactored out the SEMIHOSTING_SYS_TMPNAM logic into a n…
dragonmux Dec 29, 2023
c2dfb8a
semihosting: Refactored out the SEMIHOSTING_SYS_HEAPINFO logic into a…
dragonmux Dec 29, 2023
67e1d19
semihosting: Refactored out the SEMIHOSTING_SYS_ISERROR logic into a …
dragonmux Dec 29, 2023
a4bd7e5
semihosting: Refactored out the SEMIHOSTING_SYS_EXIT* logic into a ne…
dragonmux Dec 29, 2023
81b0393
semihosting: Cleaned up the request handler function
dragonmux Dec 29, 2023
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
2 changes: 1 addition & 1 deletion src/gdb_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ int gdb_main_loop(target_controller_s *tc, char *pbuf, size_t pbuf_size, size_t
#if PC_HOSTED == 0
case 'F': /* Semihosting call finished */
if (in_syscall)
return hostio_reply(tc, pbuf, size);
return semihosting_reply(tc, pbuf, size);
else {
DEBUG_GDB("*** F packet when not in syscall! '%s'\n", pbuf);
gdb_putpacketz("");
Expand Down
8 changes: 8 additions & 0 deletions src/include/buffer_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,12 @@ static inline uint32_t read_be4(const uint8_t *const buffer, const size_t offset
((uint32_t)buffer[offset + 2U] << 8U) | buffer[offset + 3U];
}

static inline uint64_t read_be8(const uint8_t *const buffer, const size_t offset)
{
return ((uint64_t)buffer[offset + 0] << 56U) | ((uint64_t)buffer[offset + 1] << 48U) |
((uint64_t)buffer[offset + 2] << 40U) | ((uint64_t)buffer[offset + 3] << 32U) |
((uint64_t)buffer[offset + 4] << 24U) | ((uint64_t)buffer[offset + 5] << 16U) |
((uint64_t)buffer[offset + 6] << 8U) | buffer[offset + 7];
}

#endif /*INCLUDE_BUFFER_UTILS_H*/
2 changes: 1 addition & 1 deletion src/include/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ struct target_controller {
void (*destroy_callback)(target_controller_s *, target_s *target);
void (*printf)(target_controller_s *, const char *fmt, va_list);

target_errno_e errno_;
target_errno_e gdb_errno;
bool interrupted;
};

Expand Down
19 changes: 19 additions & 0 deletions src/target/cortexm.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ static int cortexm_breakwatch_set(target_s *target, breakwatch_s *breakwatch);
static int cortexm_breakwatch_clear(target_s *target, breakwatch_s *breakwatch);
static target_addr_t cortexm_check_watch(target_s *target);

static bool cortexm_hostio_request(target_s *const target);

typedef struct cortexm_priv {
cortex_priv_s base;
bool stepping;
Expand Down Expand Up @@ -1368,3 +1370,20 @@ static bool cortexm_redirect_stdout(target_s *target, int argc, const char **arg
return true;
}
#endif

static bool cortexm_hostio_request(target_s *const target)
{
/* Read out the information from the target needed to complete the request */
uint32_t syscall = 0U;
target_reg_read(target, 0, &syscall, sizeof(syscall));
uint32_t r1 = 0U;
target_reg_read(target, 1, &r1, sizeof(r1));

/* Hand off to the main semihosting implementation */
const int32_t result = semihosting_request(target, syscall, r1);

/* Write the result back to the target */
target_reg_write(target, 0, &result, sizeof(result));
/* Return if the request was in any way interrupted */
return target->tc->interrupted;
}
Loading