Skip to content

Conversation

@voltur01
Copy link
Contributor

Semihosting SYS_READ call on stdin just returns immediately indicating no data was read, thus rendering stdin unusable with QEMU.

SYS_READC blocks and waits for one symbol to be read from the terminal, however Enter key specifically is returned as '\r', thus the special case (that may not generalize well beyond QEMU).

Semihosting SYS_READ call on stdin just returns immediately indicating no data was read, thus rendering stdin unusable with QEMU.

SYS_READC blocks and waits for one symbol to be read from the terminal, however Enter key specifically is returned as '\r', thus the special case (that may not generalize well beyond QEMU).
@voltur01 voltur01 requested a review from a team as a code owner January 12, 2026 17:21
@smithp35
Copy link
Contributor

I found a QEMU https://gitlab.com/qemu-project/qemu/-/issues/1963 and a Picolibc issue raised from that picolibc/picolibc#697 that mention SYS_READ and SYS_READC.

If I've understood both issues, it seems like SYS_READ does not block in QEMU, but picolibc's read() may block indefinitely for an EOF in stdin. The picolibc response is that the IO implementation would need to use buffered IO to use QEMUs non-blocking SYS_READ.

Copy link
Contributor

@smithp35 smithp35 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the Picolibc/QEMU discussion in https://gitlab.com/qemu-project/qemu/-/issues/1963, this looks good to me. It is mentioned that newlib only uses SYS_READ, which does indeed look like the case for libgloss/arm/syscalls.c however there may be higher-level code that is able to handle non-blocking IO in newlib, or it may just not work at all with QEMU!

if (retval >= 0)
retval = size - retval;
return retval;
char *buf, size_t size) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will be worth a comment explaining why we are using SYS_READC. Something like:

Currently only supports reading from stdin. We use SYS_READC for reading from stdin as QEMUs SYS_READ does not block. For other files SYS_READ should be used as SYS_READC may block indefinitely in QEMU.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants