diff --git a/cmake/compile-flags.cmake b/cmake/compile-flags.cmake index c31ba18..078c42e 100644 --- a/cmake/compile-flags.cmake +++ b/cmake/compile-flags.cmake @@ -19,7 +19,6 @@ add_compile_flags(BOTH -ffunction-sections -fdata-sections -fstrict-volatile-bitfields - -fno-zero-initialized-in-bss -O2 -ggdb ) diff --git a/lds/kendryte.ld b/lds/kendryte.ld index fad6b3f..20c6869 100644 --- a/lds/kendryte.ld +++ b/lds/kendryte.ld @@ -53,12 +53,14 @@ SECTIONS KEEP( *(.text.start) ) KEEP( *(.text.systick) ) } > ram : DATA - + .init : { KEEP (*(SORT_NONE(.init))) } > ram : DATA - + + . = ALIGN(8); + . = .; .text : { *(.text.unlikely .text.*_unlikely .text.unlikely.*) @@ -163,6 +165,7 @@ SECTIONS } > ram : DATA _edata = .; PROVIDE (edata = .); + . = ALIGN(8); . = .; __bss_start = .; .sbss2 : { *(.sbss2 .sbss2.* .gnu.linkonce.sb2.*) } > ram : DYN_DATA diff --git a/lib/bsp/crt.S b/lib/bsp/crt.S index bfa8938..12525cc 100644 --- a/lib/bsp/crt.S +++ b/lib/bsp/crt.S @@ -123,6 +123,15 @@ _start: jr t1 2: la sp, _idle_stack0_top + + # clear the bss segment + la t0, __bss_start + la t1, __bss_end +1: + sd zero, 0(t0) + addi t0, t0, 8 + bltu t0, t1, 1b + la t0, _init_bsp jr t0 diff --git a/lib/bsp/entry_user.c b/lib/bsp/entry_user.c index 355fe71..134b9d6 100644 --- a/lib/bsp/entry_user.c +++ b/lib/bsp/entry_user.c @@ -27,8 +27,6 @@ #define PLL1_OUTPUT_FREQ 160000000UL #define PLL2_OUTPUT_FREQ 45158400UL -extern uint8_t __bss_start[]; -extern uint8_t __bss_end[]; extern uint8_t _tls_data[]; extern int main(int argc, char *argv[]); @@ -40,15 +38,8 @@ static void setup_clocks() sysctl_pll_set_freq(SYSCTL_PLL2, PLL2_OUTPUT_FREQ); } -static void init_bss(void) -{ - memset(__bss_start, 0, __bss_end - __bss_start); -} - void _init_bsp() { - /* Initialize bss data to 0 */ - init_bss(); /* Init FPIOA */ fpioa_init(); bsp_pin_setup(); diff --git a/lib/bsp/except.c b/lib/bsp/except.c index 1a0f6fb..33dd771 100644 --- a/lib/bsp/except.c +++ b/lib/bsp/except.c @@ -20,49 +20,49 @@ void __attribute__((weak)) handle_misaligned_fetch(uintptr_t *regs, uintptr_t cause) { dump_core("misaligned fetch", regs, cause); - exit(1337); + sys_exit(1337); } void __attribute__((weak)) handle_fault_fetch(uintptr_t *regs, uintptr_t cause) { dump_core("fault fetch", regs, cause); - exit(1337); + sys_exit(1337); } void __attribute__((weak)) handle_illegal_instruction(uintptr_t *regs, uintptr_t cause) { dump_core("illegal instruction", regs, cause); - exit(1337); + sys_exit(1337); } void __attribute__((weak)) handle_breakpoint(uintptr_t *regs, uintptr_t cause) { dump_core("breakpoint", regs, cause); - exit(1337); + sys_exit(1337); } void __attribute__((weak)) handle_misaligned_load(uintptr_t *regs, uintptr_t cause) { dump_core("misaligned load", regs, cause); - exit(1337); + sys_exit(1337); } void __attribute__((weak)) handle_fault_load(uintptr_t *regs, uintptr_t cause) { dump_core("fault load", regs, cause); - exit(1337); + sys_exit(1337); } void __attribute__((weak)) handle_misaligned_store(uintptr_t *regs, uintptr_t cause) { dump_core("misaligned store", regs, cause); - exit(1337); + sys_exit(1337); } void __attribute__((weak)) handle_fault_store(uintptr_t *regs, uintptr_t cause) { dump_core("fault store", regs, cause); - exit(1337); + sys_exit(1337); } void handle_except(uintptr_t *regs, uintptr_t cause) diff --git a/lib/bsp/include/interrupt.h b/lib/bsp/include/interrupt.h index 259a17f..0727e34 100644 --- a/lib/bsp/include/interrupt.h +++ b/lib/bsp/include/interrupt.h @@ -46,6 +46,7 @@ void handle_irq_m_soft(uintptr_t *regs, uintptr_t cause); void handle_irq_m_timer(uintptr_t *regs, uintptr_t cause); void handle_irq_m_ext(uintptr_t *regs, uintptr_t cause); void handle_syscall(uintptr_t *regs, uintptr_t cause); +void __attribute__((noreturn)) sys_exit(int code); #ifdef __cplusplus } #endif diff --git a/lib/freertos/conf/FreeRTOSConfig.h b/lib/freertos/conf/FreeRTOSConfig.h index 9d78392..5fb51fd 100644 --- a/lib/freertos/conf/FreeRTOSConfig.h +++ b/lib/freertos/conf/FreeRTOSConfig.h @@ -92,7 +92,7 @@ enum #define configUSE_DAEMON_TASK_STARTUP_HOOK 0 /* memory */ -#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 1024 ) +#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 20480 ) #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 1024 * 1024 ) ) #define configSUPPORT_STATIC_ALLOCATION 1 #define configSUPPORT_DYNAMIC_ALLOCATION 1 diff --git a/lib/freertos/os_entry.c b/lib/freertos/os_entry.c index b818be7..86ec95c 100644 --- a/lib/freertos/os_entry.c +++ b/lib/freertos/os_entry.c @@ -48,10 +48,6 @@ static void main_thunk(void *p) /* Init libc array for C++ */ __libc_init_array(); - clear_csr(mie, MIP_MTIP); - clint_ipi_enable(); - set_csr(mstatus, MSTATUS_MIE); - install_hal(); install_drivers(); configure_fpioa(); @@ -71,6 +67,10 @@ static void os_entry_core1() int os_entry(int (*user_main)(int, char **)) { + clear_csr(mie, MIP_MTIP); + clint_ipi_enable(); + set_csr(mstatus, MSTATUS_MIE); + TaskHandle_t mainTask; main_thunk_param_t param = {}; param.user_main = user_main; diff --git a/lib/freertos/portable/port.c b/lib/freertos/portable/port.c index c132e90..f93e081 100644 --- a/lib/freertos/portable/port.c +++ b/lib/freertos/portable/port.c @@ -160,7 +160,7 @@ int vPortSetInterruptMask(void) int ret; __asm volatile("csrr %0,mie" : "=r"(ret)); - __asm volatile("csrc mie,%0" ::"i"(7)); + __asm volatile("csrc mie,%0" ::"r"(0x888)); return ret; } /*-----------------------------------------------------------*/