Merge pull request #1447 from thomasw04/feature/semihosting-stdout

[feature] Make SYS_OPEN in semihosting recognize ":tt"
develop
nightwalker-87 2025-01-09 00:47:53 +01:00 zatwierdzone przez GitHub
commit 72148beb31
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
1 zmienionych plików z 17 dodań i 1 usunięć

Wyświetl plik

@ -156,7 +156,7 @@ int32_t do_semihosting (stlink_t *sl, uint32_t r0, uint32_t r1, uint32_t *ret) {
mode = args[1];
name_len = args[2];
if (mode > 12) {
if (mode > 11) {
/* Invalid mode */
DLOG("Semihosting SYS_OPEN error: invalid mode %d\n", mode);
*ret = -1;
@ -191,6 +191,22 @@ int32_t do_semihosting (stlink_t *sl, uint32_t r0, uint32_t r1, uint32_t *ret) {
DLOG("Semihosting: open('%s', (SH open mode)%d, 0644)\n", name, mode);
if (name_len == 4 && strncmp(":tt", name, 3) == 0) {
if (mode <= 3) {
*ret = STDIN_FILENO;
} else if (mode >= 4 && mode <= 11) {
*ret = STDERR_FILENO;
} else {
DLOG("Semihosting SYS_OPEN error: invalid mode %d for :tt\n", mode);
*ret = -1;
saved_errno = EINVAL;
}
DLOG("Semihosting: return %d\n", *ret);
free(name);
break;
}
*ret = (uint32_t) open(name, open_mode_flags[mode], 0644);
saved_errno = errno;