Skip to content

Commit 102f643

Browse files
authored
[ATfE] Fix issue in semihosting with returning errors (#492)
This is required for testing, where we need to return a code of 1. Previously, semihosting would always exit with status OK no matter the return code for AArch32. Add minor fixes with C++ syntax.
1 parent 044c294 commit 102f643

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

arm-software/embedded/llvmlibc-support/semihost/semihost.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ namespace {
1616

1717
void stdio_open(struct __llvm_libc_stdio_cookie *cookie, int mode) {
1818
size_t args[3];
19-
args[0] = (size_t)":tt";
20-
args[1] = (size_t)mode;
21-
args[2] = (size_t)3; /* name length */
19+
args[0] = reinterpret_cast<size_t>(":tt");
20+
args[1] = static_cast<size_t>(mode);
21+
args[2] = static_cast<size_t>(3); /* name length */
2222
cookie->handle = semihosting_call(SYS_OPEN, args);
2323
}
2424
} // namespace
@@ -33,7 +33,13 @@ void __llvm_libc_exit(int status) {
3333
block[1] = status;
3434
semihosting_call(SYS_EXIT, block);
3535
#else
36-
semihosting_call(SYS_EXIT, (const void *)ADP_Stopped_ApplicationExit);
36+
if (status == 0) {
37+
semihosting_call(
38+
SYS_EXIT, reinterpret_cast<const void *>(ADP_Stopped_ApplicationExit));
39+
} else {
40+
semihosting_call(SYS_EXIT, reinterpret_cast<const void *>(
41+
ADP_Stopped_RunTimeErrorUnknown));
42+
}
3743
#endif
3844

3945
__builtin_unreachable(); /* semihosting call doesn't return */
@@ -42,9 +48,9 @@ void __llvm_libc_exit(int status) {
4248
ssize_t __llvm_libc_stdio_read(struct __llvm_libc_stdio_cookie *cookie,
4349
const char *buf, size_t size) {
4450
size_t args[4];
45-
args[0] = (size_t)cookie->handle;
46-
args[1] = (size_t)buf;
47-
args[2] = (size_t)size;
51+
args[0] = static_cast<size_t>(cookie->handle);
52+
args[1] = reinterpret_cast<size_t>(buf);
53+
args[2] = size;
4854
args[3] = 0;
4955
ssize_t retval = semihosting_call(SYS_READ, args);
5056
if (retval >= 0)
@@ -55,9 +61,9 @@ ssize_t __llvm_libc_stdio_read(struct __llvm_libc_stdio_cookie *cookie,
5561
ssize_t __llvm_libc_stdio_write(struct __llvm_libc_stdio_cookie *cookie,
5662
const char *buf, size_t size) {
5763
size_t args[4];
58-
args[0] = (size_t)cookie->handle;
59-
args[1] = (size_t)buf;
60-
args[2] = (size_t)size;
64+
args[0] = static_cast<size_t>(cookie->handle);
65+
args[1] = reinterpret_cast<size_t>(buf);
66+
args[2] = size;
6167
ssize_t retval = semihosting_call(SYS_WRITE, args);
6268
if (retval >= 0)
6369
retval = size - retval;

0 commit comments

Comments
 (0)