mcu_hi3321_watch/bootloader/flashboot/brandy/startup.s
2025-05-26 20:15:20 +08:00

78 lines
2.0 KiB
ArmAsm

/******************************************************************************
* @brief CRT0 file used for starting up the rest of the code
* Copyright (c) 2022 @CompanyNameMagicTag
******************************************************************************/
/**
* @brief This is the code that gets called when the processor first
* starts execution following a reset event. Only the absolutely
* necessary set is performed, after which the application
* supplied main() routine is called.
* @param None
* @retval : None
*/
.section .text.entry
.global Reset_Handler
.option norvc
Reset_Handler:
j _start
_start:
la t0, trap_excp
addi t0, t0, 3
csrw mtvec, t0
la t0, trap_vector
csrrw x0, mtvt, t0
csrwi mstatus, 0
csrwi mie, 0
.option push
.option norelax
# initialize global pointer
la gp, _gp_
.option pop
# initialize stack pointer
la sp, __stack_top__
/* init stack */
la t0, g_system_stack_begin
la t1, g_system_stack_end
beq t0, t1, end_set_stack_loop
li t2, 0xefbeadde
set_stack_loop:
sw t2, (t0)
addi t0, t0, 4
blt t0, t1, set_stack_loop
end_set_stack_loop:
/* clear bss section */
la t0, __bss_begin__
la t1, __bss_end__
beq t0, t1, end_clear_bss_loop
li t2, 0x00000000
clear_bss_loop:
sw t2, (t0)
addi t0, t0, 4
blt t0, t1, clear_bss_loop
end_clear_bss_loop:
/* set data section */
la t0, __data_begin__
la t1, __data_load__
la t2, __data_size__
beq t2, x0, end_set_data_loop
set_data_loop:
lw t3, (t1)
sw t3, (t0)
addi t0, t0, 4
addi t1, t1, 4
addi t2, t2, -4
blt x0, t2, set_data_loop
end_set_data_loop:
j main