Line 1... |
Line 1... |
/* ################################################################################################# */
|
/* ################################################################################################# */
|
/* # << NEORV32 - crt0.S - Application Start-Up Code & Minimal Runtime Environment >> # */
|
/* # << NEORV32 - crt0.S - Start-Up Code >> # */
|
/* # ********************************************************************************************* # */
|
|
/* # The start-up code provides a minimal runtime environment that catches all exceptions and # */
|
|
/* # interrupts and delegates them to the handler functions (installed by user via dedicated # */
|
|
/* # install function from the neorv32 runtime environment library). # */
|
|
/* # ********************************************************************************************* # */
|
/* # ********************************************************************************************* # */
|
/* # BSD 3-Clause License # */
|
/* # BSD 3-Clause License # */
|
/* # # */
|
/* # # */
|
/* # Copyright (c) 2020, Stephan Nolting. All rights reserved. # */
|
/* # Copyright (c) 2020, Stephan Nolting. All rights reserved. # */
|
/* # # */
|
/* # # */
|
Line 35... |
Line 31... |
/* # ********************************************************************************************* # */
|
/* # ********************************************************************************************* # */
|
/* # The NEORV32 Processor - https://github.com/stnolting/neorv32 (c) Stephan Nolting # */
|
/* # The NEORV32 Processor - https://github.com/stnolting/neorv32 (c) Stephan Nolting # */
|
/* ################################################################################################# */
|
/* ################################################################################################# */
|
|
|
.file "crt0.S"
|
.file "crt0.S"
|
.section .text
|
.section .text.boot
|
.balign 4
|
.balign 4
|
.global _start
|
.global _start
|
|
|
|
|
// IO region
|
// IO region
|
Line 54... |
Line 50... |
.cfi_startproc
|
.cfi_startproc
|
.cfi_undefined ra
|
.cfi_undefined ra
|
|
|
// *********************************************************
|
// *********************************************************
|
// Clear register file
|
// Clear register file
|
|
// Assume 'worst case': rv32e
|
// *********************************************************
|
// *********************************************************
|
__crt0_reg_file_clear:
|
__crt0_reg_file_clear:
|
//addi x0, x0, 0 // hardwired to zero
|
//addi x0, x0, 0 // hardwired to zero
|
addi x1, x0, 0
|
addi x1, x0, 0
|
addi x2, x0, 0
|
addi x2, x0, 0
|
Line 69... |
Line 66... |
addi x8, x0, 0
|
addi x8, x0, 0
|
addi x9, x0, 0
|
addi x9, x0, 0
|
//addi x10, x0, 0
|
//addi x10, x0, 0
|
//addi x11, x0, 0
|
//addi x11, x0, 0
|
//addi x12, x0, 0
|
//addi x12, x0, 0
|
//addi x13, x0, 0
|
addi x13, x0, 0
|
//addi x14, x0, 0
|
addi x14, x0, 0
|
addi x15, x0, 0
|
addi x15, x0, 0
|
|
|
// since we dont know here if we are compiling for a rv32e architecture
|
|
// we won't touch registers above x15
|
|
|
|
|
|
// *********************************************************
|
|
// TEST AREA / DANGER ZONE
|
|
// *********************************************************
|
|
__crt0_tests:
|
|
nop
|
|
|
|
|
|
// *********************************************************
|
// *********************************************************
|
// Setup stack pointer
|
// Setup stack pointer
|
// *********************************************************
|
// *********************************************************
|
__crt0_stack_pointer_init:
|
__crt0_stack_pointer_init:
|
Line 98... |
Line 85... |
|
|
|
|
// *********************************************************
|
// *********************************************************
|
// Setup global pointer
|
// Setup global pointer
|
// *********************************************************
|
// *********************************************************
|
|
#ifndef __BOOTLOADER_START_CODE__
|
__crt0_global_pointer_init:
|
__crt0_global_pointer_init:
|
.option push
|
.option push
|
.option norelax
|
.option norelax
|
la gp, __global_pointer$
|
la gp, __global_pointer$
|
.option pop
|
.option pop
|
|
#endif
|
|
|
|
|
// *********************************************************
|
// *********************************************************
|
// Init trap handler base address
|
// Init trap handler base address
|
// *********************************************************
|
// *********************************************************
|
Line 118... |
Line 107... |
// *********************************************************
|
// *********************************************************
|
// 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.
|
// *********************************************************
|
// *********************************************************
|
|
#ifndef __BOOTLOADER_START_CODE__
|
__crt0_reset_io:
|
__crt0_reset_io:
|
li x11, IO_BEGIN // start of processor-internal IO region
|
li x11, IO_BEGIN // start of processor-internal IO region
|
|
|
__crt0_reset_io_loop:
|
__crt0_reset_io_loop:
|
sw zero, 0(x11)
|
sw zero, 0(x11)
|
addi x11, x11, 4
|
addi x11, x11, 4
|
bne zero, x11, __crt0_reset_io_loop
|
bne zero, x11, __crt0_reset_io_loop
|
|
#endif
|
|
|
|
|
// *********************************************************
|
// *********************************************************
|
// Clear .bss section (byte-wise)
|
// Clear .bss section (byte-wise)
|
// *********************************************************
|
// *********************************************************
|
|
#ifndef __BOOTLOADER_START_CODE__
|
__crt0_clear_bss:
|
__crt0_clear_bss:
|
la x11, __crt0_bss_start
|
la x11, __crt0_bss_start
|
la x12, __crt0_bss_end
|
la x12, __crt0_bss_end
|
|
|
__crt0_clear_bss_loop:
|
__crt0_clear_bss_loop:
|
Line 141... |
Line 133... |
sb zero, 0(x11)
|
sb zero, 0(x11)
|
addi x11, x11, 1
|
addi x11, x11, 1
|
j __crt0_clear_bss_loop
|
j __crt0_clear_bss_loop
|
|
|
__crt0_clear_bss_loop_end:
|
__crt0_clear_bss_loop_end:
|
|
#endif
|
|
|
|
|
// *********************************************************
|
// *********************************************************
|
// Copy initialized .data section from ROM to RAM (byte-wise)
|
// Copy initialized .data section from ROM to RAM (byte-wise)
|
// *********************************************************
|
// *********************************************************
|
|
#ifndef __BOOTLOADER_START_CODE__
|
__crt0_copy_data:
|
__crt0_copy_data:
|
la x11, __crt0_copy_data_src_begin // start of data area (copy source)
|
la x11, __crt0_copy_data_src_begin // start of data area (copy source)
|
la x12, __crt0_copy_data_dst_begin // start of data area (copy destination)
|
la x12, __crt0_copy_data_dst_begin // start of data area (copy destination)
|
la x13, __crt0_copy_data_dst_end // last address of destination data area
|
la x13, __crt0_copy_data_dst_end // last address of destination data area
|
|
|
Line 160... |
Line 154... |
addi x11, x11, 1
|
addi x11, x11, 1
|
addi x12, x12, 1
|
addi x12, x12, 1
|
j __crt0_copy_data_loop
|
j __crt0_copy_data_loop
|
|
|
__crt0_copy_data_loop_end:
|
__crt0_copy_data_loop_end:
|
|
#endif
|
|
|
|
|
// *********************************************************
|
// *********************************************************
|
// Call main function (with argc = argv = 0)
|
// Call main function (with argc = argv = 0)
|
// *********************************************************
|
// *********************************************************
|
Line 179... |
Line 174... |
// Go to endless sleep mode if main returns
|
// Go to endless sleep mode if main returns
|
// *********************************************************
|
// *********************************************************
|
__crt0_this_is_the_end:
|
__crt0_this_is_the_end:
|
csrrci zero, mstatus, 8 // mstatus: disable global IRQs (MIE)
|
csrrci zero, mstatus, 8 // mstatus: disable global IRQs (MIE)
|
wfi
|
wfi
|
__crt0_this_is_the_end_end:
|
j . // in case WFI is not available
|
j __crt0_this_is_the_end_end // in case Ziscr is not available
|
|
|
|
|
|
// *********************************************************
|
// *********************************************************
|
// dummy trap handler (for exceptions & IRQs)
|
// dummy trap handler (for exceptions & IRQs)
|
// tries to move on to next instruction
|
// tries to move on to next instruction
|
Line 198... |
Line 192... |
sw x9, 4(sp)
|
sw x9, 4(sp)
|
|
|
csrr x8, mcause
|
csrr x8, mcause
|
blt x8, zero, __crt0_dummy_trap_handler_irq // skip mepc modification if interrupt
|
blt x8, zero, __crt0_dummy_trap_handler_irq // skip mepc modification if interrupt
|
|
|
__crt0_dummy_trap_handler_compute_return:
|
|
csrr x8, mepc
|
csrr x8, mepc
|
|
|
// is compressed instruction?
|
// is compressed instruction?
|
lh x9, 0(x8) // get compressed instruction or lower 16 bits of uncompressed instruction that caused exception
|
lh x9, 0(x8) // get compressed instruction or lower 16 bits of uncompressed instruction that caused exception
|
andi x9, x9, 3 // mask: isolate lowest 2 opcode bits (= 11 for uncompressed instructions)
|
andi x9, x9, 3 // mask: isolate lowest 2 opcode bits (= 11 for uncompressed instructions)
|