Line 1... |
Line 1... |
/* ################################################################################################# */
|
/* ################################################################################################# */
|
/* # << NEORV32 - crt0.S - Start-Up Code >> # */
|
/* # << NEORV32 - crt0.S - Start-Up Code >> # */
|
/* # ********************************************************************************************* # */
|
/* # ********************************************************************************************* # */
|
/* # BSD 3-Clause License # */
|
/* # BSD 3-Clause License # */
|
/* # # */
|
/* # # */
|
/* # Copyright (c) 2021, Stephan Nolting. All rights reserved. # */
|
/* # Copyright (c) 2022, Stephan Nolting. All rights reserved. # */
|
/* # # */
|
/* # # */
|
/* # Redistribution and use in source and binary forms, with or without modification, are # */
|
/* # Redistribution and use in source and binary forms, with or without modification, are # */
|
/* # permitted provided that the following conditions are met: # */
|
/* # permitted provided that the following conditions are met: # */
|
/* # # */
|
/* # # */
|
/* # 1. Redistributions of source code must retain the above copyright notice, this list of # */
|
/* # 1. Redistributions of source code must retain the above copyright notice, this list of # */
|
Line 31... |
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.boot
|
.section .text.crt0
|
.balign 4
|
.balign 4
|
.global _start
|
.global _start
|
|
.global __crt0_main_exit
|
|
|
|
|
_start:
|
_start:
|
.cfi_startproc
|
.cfi_startproc
|
.cfi_undefined ra
|
.cfi_undefined ra
|
Line 137... |
Line 138... |
|
|
|
|
// ************************************************************************************************
|
// ************************************************************************************************
|
// Reset/deactivate IO/peripheral devices
|
// Reset/deactivate IO/peripheral devices
|
// Devices, that are not implemented, will cause a store bus access fault
|
// Devices, that are not implemented, will cause a store bus access fault
|
// which is captured (but actually ignored) by the dummy trap handler.
|
// that is catched (but not further processed) by the dummy trap handler.
|
// ************************************************************************************************
|
// ************************************************************************************************
|
__crt0_reset_io:
|
__crt0_reset_io:
|
la x8, __ctr0_io_space_begin // start of processor-internal IO region
|
la x8, __crt0_io_space_begin // start of processor-internal IO region
|
la x9, __ctr0_io_space_end // end of processor-internal IO region
|
la x9, __crt0_io_space_end // end of processor-internal IO region
|
|
|
__crt0_reset_io_loop:
|
__crt0_reset_io_loop:
|
sw zero, 0(x8)
|
sw zero, 0(x8)
|
addi x8, x8, 4
|
addi x8, x8, 4
|
bne x8, x9, __crt0_reset_io_loop
|
bne x8, x9, __crt0_reset_io_loop
|
Line 166... |
Line 167... |
|
|
__crt0_clear_bss_loop_end:
|
__crt0_clear_bss_loop_end:
|
|
|
|
|
// ************************************************************************************************
|
// ************************************************************************************************
|
// Copy initialized .data section from ROM to RAM (byte-wise) using linker script symbols
|
// Copy initialized .data section from ROM to RAM (byte-wise)
|
// ************************************************************************************************
|
// ************************************************************************************************
|
__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 188... |
Line 189... |
|
|
// ************************************************************************************************
|
// ************************************************************************************************
|
// Setup arguments and call main function
|
// Setup arguments and call main function
|
// ************************************************************************************************
|
// ************************************************************************************************
|
__crt0_main_entry:
|
__crt0_main_entry:
|
addi x10, zero, 0 // a0 = argc = 0
|
addi a0, zero, 0 // a0 = argc = 0
|
addi x11, zero, 0 // a1 = argv = 0
|
addi a1, zero, 0 // a1 = argv = 0
|
jal ra, main // call actual app's main function, this "should" not return
|
jal ra, main // call actual app's main function, this "should" not return
|
|
|
|
__crt0_main_exit: // main's "return" and "exit" will arrive here
|
|
csrw mscratch, a0 // backup main's return code to mscratch (for debugger)
|
|
|
|
|
// ************************************************************************************************
|
// ************************************************************************************************
|
// call "after main" handler (if there is any) if main really returns
|
// call "after main" handler (if there is any) if main really returns
|
// ************************************************************************************************
|
// ************************************************************************************************
|
__crt0_main_aftermath:
|
|
csrw mscratch, a0 // copy main's return code in mscratch for debugger
|
|
|
|
#ifndef make_bootloader // after_main handler not supported for bootloader
|
#ifndef make_bootloader // after_main handler not supported for bootloader
|
|
|
|
__crt0_main_aftermath:
|
.weak __neorv32_crt0_after_main
|
.weak __neorv32_crt0_after_main
|
la ra, __neorv32_crt0_after_main
|
la ra, __neorv32_crt0_after_main
|
beqz ra, __crt0_main_aftermath_end // check if an aftermath handler has been specified
|
beqz ra, __crt0_main_aftermath_end // check if an aftermath handler has been specified
|
jalr ra // execute handler, main's return code in a0
|
jalr ra // execute handler with main's return code still in a0
|
|
|
|
__crt0_main_aftermath_end:
|
|
|
#endif
|
#endif
|
|
|
|
|
// ************************************************************************************************
|
// ************************************************************************************************
|
// go to endless sleep mode
|
// go to endless sleep mode
|
// ************************************************************************************************
|
// ************************************************************************************************
|
__crt0_main_aftermath_end:
|
__crt0_shutdown:
|
csrci mstatus, 8 // mstatus: disable global IRQs (mstatus.mie)
|
csrci mstatus, 8 // disable global IRQs (clear mstatus.mie)
|
__crt0_main_aftermath_end_loop:
|
__crt0_shutdown_loop:
|
wfi // try to go to sleep mode
|
wfi // go to sleep mode
|
j __crt0_main_aftermath_end_loop // endless loop
|
j __crt0_shutdown_loop // endless loop
|
|
|
|
|
// ************************************************************************************************
|
// ************************************************************************************************
|
// dummy trap handler (for exceptions & IRQs during very early boot stage)
|
// dummy trap handler (for exceptions & IRQs during very early boot stage)
|
// does nothing but tries to move on to next instruction
|
// does nothing but trying to move on to the next instruction
|
// ************************************************************************************************
|
// ************************************************************************************************
|
.balign 4
|
.balign 4
|
__crt0_dummy_trap_handler:
|
__crt0_dummy_trap_handler:
|
|
|
addi sp, sp, -8
|
addi sp, sp, -8
|