This RFC discusses the strategy for implementing stdio.h
on baremetal.
Context
Currently, FILE
is not supported on baremetal platforms. Therefore, functions like fprintf
have not been implemented at this current time, which means I cannot use LLVM-libc to compile programs requiring both stdout
and stderr
.
So, I submitted a PR ([libc] Add putc, fputc, and fprintf to stdio/baremetal by saturn691 · Pull Request #144567 · llvm/llvm-project · GitHub), apparently there had already been discussions about the design, but it had not been written down.
Requirements
If both these use cases can be supported, it would be amazing.
Semihosting
On ARM platforms, a lot of testing is done through the semihosting API, which, for example, allows interaction with the host filesystem (see section 6, semihosting operations). Currently a lot of the work to do with semihosting is done downstream, which I would like to upstream some time in the future, along with the C runtime (crt0).
True baremetal
True embedded projects (that are not connected to a debugger) do not use semihosting, and another interface like UART to execute I/O functions. On true baremetal, code size is an important factor, so ideally we would like to throw away the scaffolding to support semihosting.
Design
As there had already been an informal design before I joined the project, I would love to hear about it. I will document a few concerns I had with preliminary testing.
Compatibility with picolibc/newlib
They define and declare stdout/stderr/stdin
as a FILE * const
, and we define it as FILE *
, which is more in line with other libcs. Ideally I’d like a plug-and-play approach where we have some compatibility, but I know that there are a lot of trade-offs.