-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[sw] add support for newlib's system calls #275
Conversation
✔️🚀 A minimal test program using dynamic memory allocation and #include <neorv32.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
int main() {
// initialize the neorv32 runtime environment
// this will take care of handling all CPU traps (interrupts and exceptions)
neorv32_rte_setup();
// setup UART0 at default baud rate, no parity bits, no hw flow control
neorv32_uart0_setup(BAUD_RATE, PARITY_NONE, FLOW_CONTROL_RTSCTS);
// output via "STDOUT" (UART0.TX)
printf("printf test\n");
// allocate 4 bytes of memory
char *char_buffer;
char_buffer = (char *) malloc(4 * sizeof(char));
// get 4 chars from "STDIN" (UART0.RX)
read((int)stdin, char_buffer, 4 * sizeof(char));
// output via UART0.TX
neorv32_uart0_printf("%c %c %c %c\n", char_buffer[0], char_buffer[1], char_buffer[2], char_buffer[3]);
free(char_buffer);
return 0;
} And the resulting output (when entering
|
This PR add support for RISC-V's newlib system calls by providing simple stubs for "OS" functions like
fork()
andwrite()
and evenprintf()
andscanf()
. A new library filesw/lib/source/syscalls.c
is added to provide these stubs.Furthermore, this PR updates the processor's linker script (
sw/common/neorv32.ld
) by providing definitions for setting up the heap. Application software can now use standard dynamic memory allocation functions likemalloc()
andfree()
.📚 A new section in the data sheet ("RAM Layout") illustrates the default RAM usage.
syscalls.c
seem to work fine. Any feedback/help is highly appreciated!©️ The stubs for the system calls were copied (and modified) from @openhwgroup's https://github.com/openhwgroup/cv32e40p/blob/master/example_tb/core/custom/syscalls.c (project license: SOLDERPAD HARDWARE LICENSE version 0.51) and @newaetech's newaetech/chipwhisperer@df8e2fa
Further references on handling newlib system calls: https://interrupt.memfault.com/blog/boostrapping-libc-with-newlib#implementing-newlib