Make the ISA extension init code paths optional in crt0.S Having the ability to disable these extension-specific code paths is necessary for low-level hardware development and unit testing. This CL also removes irq_vector.S as it 1) was resulting in undefined symbol errors when disabling exceptions, 2) wasn't actually being actively used by crt0.S (rather than pointing the mtvec CSR to the indirect jump table in irq_vector.S, crt0.S was setting it directly to the exception handler in crt0.S; irq_vector.S was in effect only used for resets and the jump table defined was never used at all), and 3) isn't plan of record to support interrupts on Springbok anyway. Change-Id: Idfb5cc45b76db1f664b1d953f4a7c2c8a5f1d174
diff --git a/springbok/CMakeLists.txt b/springbok/CMakeLists.txt index a3261e4..365e1ac 100644 --- a/springbok/CMakeLists.txt +++ b/springbok/CMakeLists.txt
@@ -6,7 +6,6 @@ target_sources(springbok_intrinsic PRIVATE crt0.S - irq_vector.S springbok_gloss.cpp springbok.cpp )
diff --git a/springbok/crt0.S b/springbok/crt0.S index 68351ce..5adebba 100644 --- a/springbok/crt0.S +++ b/springbok/crt0.S
@@ -34,6 +34,7 @@ mv t5, zero mv t6, zero +#ifndef LIBSPRINGBOK_NO_VECTOR_SUPPORT ############################################### # Put all vector registers into a known state # ############################################### @@ -56,7 +57,9 @@ # Set vector extension to "clean" xori a0, a0, 0x600 csrw mstatus, a0 +#endif +#ifndef LIBSPRINGBOK_NO_FLOAT_SUPPORT ############################################################### # Reset all other CSRs, and perform any other processor setup # ############################################################### @@ -65,8 +68,12 @@ li a1, 0x2000 or a0, a0, a1 csrw mstatus, a0 +#endif + +#ifndef LIBSPRINGBOK_NO_EXCEPTION_SUPPORT la a0, exception_handler csrw mtvec, a0 +#endif ############################################################# # Set up stack sentinels # @@ -157,11 +164,18 @@ addi sp, sp, 16 _finish: - # Store the application's return value onto the stack +#ifndef LIBSPRINGBOK_NO_EXCEPTION_SUPPORT + # Store the application's return value and machine exception program + # counter onto the stack addi sp, sp, -8 sw a0, 0(sp) csrr t0, mepc sw t0, 4(sp) +#else + # Store the application's return value onto the stack + addi sp, sp, -4 + sw a0, 0(sp) +#endif 1: .word 0x0000307B # finish (encoded as custom3<func3=3>) j 1b @@ -242,6 +256,7 @@ 2: li a0, 1 ret +#ifndef LIBSPRINGBOK_NO_EXCEPTION_SUPPORT .weak exception_handler exception_handler: # Exception occurred @@ -274,3 +289,4 @@ .weak print_csrs print_csrs: mret +#endif
diff --git a/springbok/irq_vector.S b/springbok/irq_vector.S deleted file mode 100644 index 1787f67..0000000 --- a/springbok/irq_vector.S +++ /dev/null
@@ -1,8 +0,0 @@ - // Exception handler. - .section .vectors, "ax" - .option norvc - .option push - .option norelax - .org 0x00 - j _start - j exception_handler
diff --git a/springbok/matcha.ld b/springbok/matcha.ld index ab5d339..639f700 100644 --- a/springbok/matcha.ld +++ b/springbok/matcha.ld
@@ -13,14 +13,10 @@ PROVIDE( _stack_start_sentinel = ORIGIN(DTCM) + LENGTH(DTCM) - STACK_SIZE ); PROVIDE( _stack_end_sentinel = ORIGIN(DTCM) + LENGTH(DTCM) - 64 ); -_boot_address = ORIGIN(ITCM); -ENTRY(_boot_address) +ENTRY(_start) SECTIONS { - .vectors _boot_address : ALIGN(4) { - KEEP(*(.vectors)) - } > ITCM .text : { _stext = .;
diff --git a/springbok/springbok.cpp b/springbok/springbok.cpp index 514eda0..d6d659e 100644 --- a/springbok/springbok.cpp +++ b/springbok/springbok.cpp
@@ -1,6 +1,8 @@ #include <stdint.h> #include "springbok.h" +#ifndef LIBSPRINGBOK_NO_EXCEPTION_SUPPORT + extern "C" void print_csrs(void) { uint32_t mcause; uint32_t mepc; @@ -40,6 +42,10 @@ LOG_ERROR("MIMPID:\t\t0x%08X", static_cast<unsigned int>(mimpid)); } +#endif + +#ifndef LIBSPRINGBOK_NO_FLOAT_SUPPORT + // Helper function for float_to_str. Copies a string into the output buffer. static void print_str(char *buffer, const int len, int *l, const char *str) { for (int i = 0; str[i] != '\0'; i++) { @@ -222,3 +228,13 @@ // Return the number of characters needed for display. return l; } + +#else // defined(LIBSPRINGBOK_NO_FLOAT_SUPPORT) + +extern "C" int float_to_str(const int len, char *buffer, const float value) { + // Dummy function since float support is disabled in libspringbok + LOG_ERROR("float_to_str is disabled because libspringbok was compiled without float support"); + return 0; +} + +#endif