From 35a8c8f9f6d9ba12bac93a127d024428c6fe3898 Mon Sep 17 00:00:00 2001 From: Dave Berkeley Date: Sun, 17 Apr 2022 11:22:19 +0100 Subject: [PATCH] Added init_array support for vexriscv to allow static C++ ctors and C __attribute__((constructor, priority)) in gcc --- litex/soc/cores/cpu/vexriscv/crt0.S | 1 + litex/soc/software/bios/linker.ld | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/litex/soc/cores/cpu/vexriscv/crt0.S b/litex/soc/cores/cpu/vexriscv/crt0.S index 0496c84be..fa9ead4c3 100644 --- a/litex/soc/cores/cpu/vexriscv/crt0.S +++ b/litex/soc/cores/cpu/vexriscv/crt0.S @@ -84,6 +84,7 @@ bss_done: li a0, 0x880 //880 enable timer + external interrupt sources (until mstatus.MIE is set, they will never trigger an interrupt) csrw mie,a0 + call __libc_init_array call main infinit_loop: j infinit_loop diff --git a/litex/soc/software/bios/linker.ld b/litex/soc/software/bios/linker.ld index 66f8b9aff..b18560ac0 100644 --- a/litex/soc/software/bios/linker.ld +++ b/litex/soc/software/bios/linker.ld @@ -51,6 +51,15 @@ SECTIONS PROVIDE_HIDDEN (__bios_init_end = .); } > rom + .init_array : + { + . = ALIGN(4); + __init_array_start = .; + KEEP(*(SORT(.init_array.*))) + KEEP(*(.init_array)) + __init_array_end = .; + } > rom + .data : { . = ALIGN(8);