From 353536edb7a4b3ff9e84465fd96b477491da746f Mon Sep 17 00:00:00 2001 From: Colton Pawielski Date: Sat, 20 May 2023 12:05:01 -0500 Subject: [PATCH 1/4] Add support for a return code in the exit() syscall The return code passed to exit() on the target will be transfered to the host and used as the exit code for the host application. --- host-src/tool/dc-tool.c | 3 +-- host-src/tool/syscalls.c | 8 ++++++++ host-src/tool/syscalls.h | 2 ++ target-src/dcload/syscalls.c | 4 +++- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/host-src/tool/dc-tool.c b/host-src/tool/dc-tool.c index fee2f95..922f359 100644 --- a/host-src/tool/dc-tool.c +++ b/host-src/tool/dc-tool.c @@ -1143,8 +1143,7 @@ void do_console(unsigned char *path, unsigned char *isofile) { switch(command) { case 0: - finish_serial(); - exit(0); + dc_exit(); break; case 1: dc_fstat(); diff --git a/host-src/tool/syscalls.c b/host-src/tool/syscalls.c index 6bf14a3..edbd616 100644 --- a/host-src/tool/syscalls.c +++ b/host-src/tool/syscalls.c @@ -553,3 +553,11 @@ void dc_gdbpacket(void) { if(retval > 0) send_data((unsigned char *)gdb_buf, retval, 0); } + +void dc_exit(void) { + int exit_code = (int32_t) recv_uint(); + printf("Program returned %d\n", exit_code); + finish_serial(); + exit(exit_code); +} + diff --git a/host-src/tool/syscalls.h b/host-src/tool/syscalls.h index 82a7aba..5983c3d 100644 --- a/host-src/tool/syscalls.h +++ b/host-src/tool/syscalls.h @@ -46,4 +46,6 @@ void dc_cdfs_redir_read_sectors(int isofd); void dc_gdbpacket(void); +_Noreturn void dc_exit(void); + #endif diff --git a/target-src/dcload/syscalls.c b/target-src/dcload/syscalls.c index 0556559..9919036 100644 --- a/target-src/dcload/syscalls.c +++ b/target-src/dcload/syscalls.c @@ -44,8 +44,10 @@ int strlen(const char *s) { return c; } -void dcexit(void) { +void dcexit(int ret_code) +{ scif_putchar(0); + put_uint(ret_code); scif_flush(); } From 00fb19ec1ff0070bab6011b31c29fae056233e18 Mon Sep 17 00:00:00 2001 From: Colton Pawielski Date: Sat, 20 May 2023 12:30:45 -0500 Subject: [PATCH 2/4] Fix host tool return codes Sometimes the tool would return a success code when an error had occured. This change makes it so that invalid flags and other errors return -1 to indicate failure. --- host-src/tool/dc-tool.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/host-src/tool/dc-tool.c b/host-src/tool/dc-tool.c index 922f359..eca35c6 100644 --- a/host-src/tool/dc-tool.c +++ b/host-src/tool/dc-tool.c @@ -858,8 +858,6 @@ void usage(void) { printf("-g Start a GDB server\n"); printf("-h Usage information (you\'re looking at it)\n\n"); cleanup(); - - exit(0); } /* Got to make sure WinSock is initalized */ @@ -1212,7 +1210,7 @@ void do_console(unsigned char *path, unsigned char *isofile) { printf("Unimplemented command (%d) \n", command); printf("Assuming program has exited, or something...\n"); finish_serial(); - exit(0); + exit(-1); break; } } @@ -1262,16 +1260,17 @@ int main(int argc, char *argv[]) { unsigned char *isofile = 0; int someopt; - if(argc < 2) + if (argc < 2) { usage(); - + exit(-1); + } someopt = getopt(argc, argv, AVAILABLE_OPTIONS); while(someopt > 0) { switch(someopt) { case 'x': if(command) { printf("You can only specify one of -x, -u, and -d\n"); - exit(0); + exit(-1); } command = 'x'; filename = malloc(strlen(optarg) + 1); @@ -1280,7 +1279,7 @@ int main(int argc, char *argv[]) { case 'u': if(command) { printf("You can only specify one of -x, -u, and -d\n"); - exit(0); + exit(-1); } command = 'u'; filename = malloc(strlen(optarg) + 1); @@ -1289,7 +1288,7 @@ int main(int argc, char *argv[]) { case 'd': if(command) { printf("You can only specify one of -x, -u, and -d\n"); - exit(0); + exit(-1); } command = 'd'; filename = malloc(strlen(optarg) + 1); @@ -1331,6 +1330,7 @@ int main(int argc, char *argv[]) { break; case 'h': usage(); + exit(0); break; case 'e': speedhack = 1; @@ -1358,7 +1358,7 @@ int main(int argc, char *argv[]) { struct stat statbuf; if(stat((char *)filename, &statbuf)) { perror((char *)filename); - exit(1); + exit(-1); } } @@ -1426,7 +1426,7 @@ int main(int argc, char *argv[]) { if(!size) { printf("You must specify a size (-s ) with download (-d )\n"); cleanup(); - exit(0); + exit(-1); } printf("Download %d bytes at <0x%x> to <%s>\n", size, address, filename); @@ -1438,6 +1438,7 @@ int main(int argc, char *argv[]) { do_dumbterm(); else usage(); + exit(-1); break; } From 31b242c14487f98df15e9cffe1144bbc51bd1a0e Mon Sep 17 00:00:00 2001 From: darc Date: Thu, 11 Dec 2025 23:50:33 -0600 Subject: [PATCH 3/4] Use command 22 for exiting with return code Leave command 0 as the legacy exit for legacy dcload-serial discs, but use command 22 for newer dcload-serial discs supporting return codes --- host-src/tool/dc-io.h | 1 + host-src/tool/dc-tool.c | 10 +++++++--- target-src/dcload/syscalls.c | 5 ++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/host-src/tool/dc-io.h b/host-src/tool/dc-io.h index ea38b6f..ad9bd80 100644 --- a/host-src/tool/dc-io.h +++ b/host-src/tool/dc-io.h @@ -5,5 +5,6 @@ int send_uint(unsigned int value); unsigned int recv_uint(void); void recv_data(void *data, unsigned int total, unsigned int verbose); void send_data(unsigned char *addr, unsigned int size, unsigned int verbose); +void finish_serial(void); #endif /* __DC_IO_H__ */ diff --git a/host-src/tool/dc-tool.c b/host-src/tool/dc-tool.c index eca35c6..c45d75a 100644 --- a/host-src/tool/dc-tool.c +++ b/host-src/tool/dc-tool.c @@ -1141,7 +1141,8 @@ void do_console(unsigned char *path, unsigned char *isofile) { switch(command) { case 0: - dc_exit(); + finish_serial(); + exit(0); break; case 1: dc_fstat(); @@ -1206,6 +1207,9 @@ void do_console(unsigned char *path, unsigned char *isofile) { case 21: dc_rewinddir(); break; + case 22: + dc_exit(); + break; default: printf("Unimplemented command (%d) \n", command); printf("Assuming program has exited, or something...\n"); @@ -1262,7 +1266,7 @@ int main(int argc, char *argv[]) { if (argc < 2) { usage(); - exit(-1); + exit(-1); } someopt = getopt(argc, argv, AVAILABLE_OPTIONS); while(someopt > 0) { @@ -1330,7 +1334,7 @@ int main(int argc, char *argv[]) { break; case 'h': usage(); - exit(0); + exit(0); break; case 'e': speedhack = 1; diff --git a/target-src/dcload/syscalls.c b/target-src/dcload/syscalls.c index 9919036..2d3af41 100644 --- a/target-src/dcload/syscalls.c +++ b/target-src/dcload/syscalls.c @@ -44,9 +44,8 @@ int strlen(const char *s) { return c; } -void dcexit(int ret_code) -{ - scif_putchar(0); +void dcexit(int ret_code) { + scif_putchar(22); put_uint(ret_code); scif_flush(); } From a0950d07b4ce63432a486fb846c3387ad4e67059 Mon Sep 17 00:00:00 2001 From: darc Date: Thu, 11 Dec 2025 23:57:44 -0600 Subject: [PATCH 4/4] Update version to 1.0.7 As the new return code feature has been introduced altering the behavior of the dcload-serial disc, we update the version number --- Makefile.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.cfg b/Makefile.cfg index 5ab4f01..02e8707 100644 --- a/Makefile.cfg +++ b/Makefile.cfg @@ -89,7 +89,7 @@ endif # You generally shouldn't change this unless you are making forked # versions (or test versions) # Version numbers must be of the form x.x.x -VERSION = 1.0.6 +VERSION = 1.0.7 # Define this if you want a standalone, statically linked, no dependency binary #STANDALONE_BINARY = 1