diff --git a/src/gdb_hostio.c b/src/gdb_hostio.c index 1c76a5f9821..3ba9eb580da 100644 --- a/src/gdb_hostio.c +++ b/src/gdb_hostio.c @@ -24,6 +24,8 @@ #include "gdb_hostio.h" #include "gdb_packet.h" +#if PC_HOSTED == 0 + int hostio_reply(target_controller_s *const tc, char *const pbuf, const int len) { (void)len; @@ -149,3 +151,4 @@ int hostio_system(target_controller_s *tc, target_addr_t cmd, size_t cmd_len) gdb_putpacket_f("Fsystem,%08" PRIx32 "/%zX", cmd, cmd_len); return hostio_get_response(tc); } +#endif // PC_HOSTED diff --git a/src/gdb_main.c b/src/gdb_main.c index b2aa30795c9..a52df7b1f96 100644 --- a/src/gdb_main.c +++ b/src/gdb_main.c @@ -116,6 +116,7 @@ target_controller_s gdb_controller = { .destroy_callback = gdb_target_destroy_callback, .printf = gdb_target_printf, +#if PC_HOSTED == 0 .open = hostio_open, .close = hostio_close, .read = hostio_read, @@ -128,12 +129,17 @@ target_controller_s gdb_controller = { .gettimeofday = hostio_gettimeofday, .isatty = hostio_isatty, .system = hostio_system, +#endif }; /* execute gdb remote command stored in 'pbuf'. returns immediately, no busy waiting. */ int gdb_main_loop(target_controller_s *tc, char *pbuf, size_t pbuf_size, size_t size, bool in_syscall) { +#if PC_HOSTED == 1 + (void)tc; + (void)in_syscall; +#endif bool single_step = false; /* GDB protocol main loop */ @@ -280,7 +286,8 @@ int gdb_main_loop(target_controller_s *tc, char *pbuf, size_t pbuf_size, size_t break; } - case 'F': /* Semihosting call finished */ +#if PC_HOSTED == 0 + case 'F': /* File-I/O call finished */ if (in_syscall) return hostio_reply(tc, pbuf, size); else { @@ -288,6 +295,7 @@ int gdb_main_loop(target_controller_s *tc, char *pbuf, size_t pbuf_size, size_t gdb_putpacketz(""); } break; +#endif case '!': /* Enable Extended GDB Protocol. */ /* diff --git a/src/include/target.h b/src/include/target.h index b8052147f91..30d4cbf3667 100644 --- a/src/include/target.h +++ b/src/include/target.h @@ -157,6 +157,7 @@ struct target_controller { void (*destroy_callback)(target_controller_s *, target_s *target); void (*printf)(target_controller_s *, const char *fmt, va_list); +#if PC_HOSTED == 0 /* Interface to host system calls */ int (*open)(target_controller_s *, target_addr_t path, size_t path_len, target_open_flags_e flags, mode_t mode); int (*close)(target_controller_s *, int fd); @@ -170,6 +171,7 @@ struct target_controller { int (*gettimeofday)(target_controller_s *, target_addr_t tv, target_addr_t tz); int (*isatty)(target_controller_s *, int fd); int (*system)(target_controller_s *, target_addr_t cmd, size_t cmd_len); +#endif target_errno_e errno_; bool interrupted; }; diff --git a/src/target/target.c b/src/target/target.c index 8a162e6d66d..310a8e270ec 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -574,6 +574,7 @@ void tc_printf(target_s *t, const char *fmt, ...) va_end(ap); } +#if PC_HOSTED == 0 /* Interface to host system calls */ int tc_open(target_s *t, target_addr_t path, size_t plen, target_open_flags_e flags, mode_t mode) { @@ -602,7 +603,7 @@ int tc_read(target_s *t, int fd, target_addr_t buf, unsigned int count) int tc_write(target_s *t, int fd, target_addr_t buf, unsigned int count) { -#if PC_HOSTED == 0 + /* BMP feature: redirect semihosting writes to debug_serial */ if (t->stdout_redirected && (fd == STDOUT_FILENO || fd == STDERR_FILENO)) { while (count) { uint8_t tmp[STDOUT_READ_BUF_SIZE]; @@ -616,8 +617,8 @@ int tc_write(target_s *t, int fd, target_addr_t buf, unsigned int count) } return 0; } -#endif + /* Delegate to gdb_hostio */ if (t->tc->write == NULL) return 0; return t->tc->write(t->tc, fd, buf, count); @@ -688,3 +689,4 @@ int tc_system(target_s *t, target_addr_t cmd, size_t cmdlen) } return t->tc->system(t->tc, cmd, cmdlen); } +#endif // PC_HOSTED