From ca7b65d25e725725ebbcc0b4fa122362afeb54ef Mon Sep 17 00:00:00 2001 From: Philip Wiese Date: Thu, 2 May 2024 17:46:28 +0200 Subject: [PATCH 1/3] [fix] Fix problems with linker garbage collection --- sw/snRuntime/base.ld | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sw/snRuntime/base.ld b/sw/snRuntime/base.ld index d0979b719..171921d5e 100644 --- a/sw/snRuntime/base.ld +++ b/sw/snRuntime/base.ld @@ -66,7 +66,7 @@ SECTIONS .cbss : { __cbss_start = .; - *(.cbss .cbss.*) + KEEP(*(.cbss .cbss.*)) __cbss_end = .; } >L3 From 9b54adef630da682f04d52df47ca0f2343c5e1df Mon Sep 17 00:00:00 2001 From: Philip Wiese Date: Thu, 2 May 2024 17:46:42 +0200 Subject: [PATCH 2/3] [fix] Statically allocate printf buffers --- .../snitch_cluster/sw/runtime/rtl/src/putchar.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/target/snitch_cluster/sw/runtime/rtl/src/putchar.c b/target/snitch_cluster/sw/runtime/rtl/src/putchar.c index ea5841888..77d7b5443 100644 --- a/target/snitch_cluster/sw/runtime/rtl/src/putchar.c +++ b/target/snitch_cluster/sw/runtime/rtl/src/putchar.c @@ -25,16 +25,21 @@ void _putchar(char character) { extern uintptr_t volatile tohost, fromhost; // Rudimentary string buffer for putc calls. -extern uint32_t _edram; #define PUTC_BUFFER_LEN (1024 - sizeof(size_t)) -struct putc_buffer_header { + +typedef struct { size_t size; uint64_t syscall_mem[8]; -}; -static volatile struct putc_buffer { - struct putc_buffer_header hdr; +} putc_buffer_header_t; + +typedef struct putc_buffer { + putc_buffer_header_t hdr; char data[PUTC_BUFFER_LEN]; -} *const putc_buffer = (void *)&_edram; +} putc_buffer_t; + +static volatile putc_buffer_t + putc_buffer[SNRT_CLUSTER_NUM * SNRT_CLUSTER_CORE_NUM] + __attribute__((section(".dram"))); // Provide an implementation for putchar. void _putchar(char character) { From a55a92a14bd8d84025f6280c32f07d8e0d89ac62 Mon Sep 17 00:00:00 2001 From: Luca Colagrande Date: Fri, 19 Jul 2024 10:40:27 +0200 Subject: [PATCH 3/3] sw: Thread-safe `putchar()` function --- target/snitch_cluster/sw/runtime/rtl/src/putchar.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/target/snitch_cluster/sw/runtime/rtl/src/putchar.c b/target/snitch_cluster/sw/runtime/rtl/src/putchar.c index 77d7b5443..e9412473e 100644 --- a/target/snitch_cluster/sw/runtime/rtl/src/putchar.c +++ b/target/snitch_cluster/sw/runtime/rtl/src/putchar.c @@ -51,10 +51,12 @@ void _putchar(char character) { buf->hdr.syscall_mem[2] = (uintptr_t)&buf->data; // buffer buf->hdr.syscall_mem[3] = buf->hdr.size; // length + snrt_mutex_acquire(snrt_mutex()); tohost = (uintptr_t)buf->hdr.syscall_mem; while (fromhost == 0) ; fromhost = 0; + snrt_mutex_release(snrt_mutex()); buf->hdr.size = 0; }