Line 67... |
Line 67... |
addi x14, x0, 0
|
addi x14, x0, 0
|
addi x15, x0, 0
|
addi x15, x0, 0
|
|
|
|
|
// *********************************************************
|
// *********************************************************
|
// Initialize dummy trap handler base address
|
// Setup pointers using linker script symbols
|
|
// *********************************************************
|
|
__crt0_pointer_init:
|
|
.option push
|
|
.option norelax
|
|
la sp, __crt0_stack_begin
|
|
andi sp, sp, 0xfffffffc // make sure this is aligned
|
|
addi fp, sp, 0 // frame pointer = stack pointer
|
|
la gp, __global_pointer$ // global pointer
|
|
.option pop
|
|
|
|
|
// *********************************************************
|
// *********************************************************
|
__crt0_neorv32_trap_init:
|
// Setup CPU core CSRs (some of them DO NOT have a dedicated reset and need to be explicitly initialized)
|
la x11, __crt0_dummy_trap_handler
|
// *********************************************************
|
csrw mtvec, x11 // set address of first-level exception handler
|
__crt0_cpu_csr_init:
|
|
|
|
// set address of first-level exception handler
|
|
la x10, __crt0_dummy_trap_handler
|
|
csrw mtvec, x10
|
|
csrw mepc, x10
|
|
csrw mtval, zero
|
|
csrw mcause, zero
|
|
|
|
// no global IRQ enable (is also done by hardware)
|
|
csrw mstatus, zero
|
|
|
|
// absolutely no interrupts, thanks
|
|
csrw mie, zero
|
|
|
|
// no access from less-privileged modes to counter CSRs
|
|
csrw mcounteren, zero
|
|
|
|
// stop all counters except for [m]cycle[h] and [m]instret[h]
|
|
li x11, ~5
|
|
csrw mcountinhibit, x11
|
|
|
|
// clear cycle counters
|
|
csrw mcycle, zero
|
|
csrw mcycleh, zero
|
|
|
|
// clear instruction counters
|
|
csrw minstret, zero
|
|
csrw minstreth, zero
|
|
|
|
#if defined(__riscv_flen) && (__riscv_flen != 0)
|
|
// clear floating-point CSR (rounding mode & exception flags)
|
|
csrw fcsr, zero
|
|
#endif
|
|
|
|
|
// *********************************************************
|
// *********************************************************
|
// Clear integer register file (upper half, if no E extension)
|
// Clear integer register file (upper half, if no E extension)
|
// *********************************************************
|
// *********************************************************
|
Line 101... |
Line 145... |
#endif
|
#endif
|
#endif
|
#endif
|
|
|
|
|
// *********************************************************
|
// *********************************************************
|
// No interrupts, thanks
|
|
// *********************************************************
|
|
__crt0_status_init:
|
|
li x10, 0x00001800 // clear mstatus and set mpp(1:0)
|
|
csrrw zero, mstatus, x10
|
|
csrrw zero, mie, zero // clear mie
|
|
|
|
|
|
// *********************************************************
|
|
// Setup pointers using linker script symbols
|
|
// *********************************************************
|
|
__crt0_pointer_init:
|
|
.option push
|
|
.option norelax
|
|
la sp, __crt0_stack_begin
|
|
andi sp, sp, 0xfffffffc // make sure this is aligned
|
|
addi fp, sp, 0 // frame pointer = stack pointer
|
|
la gp, __global_pointer$ // global pointer
|
|
.option pop
|
|
|
|
|
|
// *********************************************************
|
|
// Reset/deactivate IO/peripheral devices
|
// Reset/deactivate IO/peripheral devices
|
// Devices, that are not implemented, will cause a store access fault
|
// Devices, that are not implemented, will cause a store access fault
|
// which is captured but actually ignored due to the dummy handler.
|
// which is captured but actually ignored due to the dummy handler.
|
// *********************************************************
|
// *********************************************************
|
__crt0_reset_io:
|
__crt0_reset_io:
|
Line 180... |
Line 202... |
|
|
// setup arguments for calling main
|
// setup arguments for calling main
|
addi x10, zero, 0 // argc = 0
|
addi x10, zero, 0 // argc = 0
|
addi x11, zero, 0 // argv = 0
|
addi x11, zero, 0 // argv = 0
|
|
|
// clear cycle and instruction counters
|
|
csrw mcycle, zero
|
|
csrw mcycleh, zero
|
|
csrw minstret, zero
|
|
csrw minstreth, zero
|
|
// enable read-access from user-mode for cycle[h], time[h] and instret[h]
|
|
csrwi 0x306, 7 // mcounteren
|
|
// enable auto-increment of all counters
|
|
csrw 0x320, x0 // mcountinhibit
|
|
|
|
// restore mcause reset value (so that 'main' knows we are coming from reset)
|
|
li x12, 0x80000000
|
|
csrw mcause, x12
|
|
|
|
// call actual app's main function
|
// call actual app's main function
|
jal ra, main
|
jal ra, main
|
|
|
|
|
// *********************************************************
|
// *********************************************************
|