tiny riscv 启动代码start.S学习

  2   .section .init;
  3     .globl _start;
  4     .type _start,@function
  5
  6
  7 _start:
  8 # this sequence of directives temporarily disables relaxation while loading the
  9 # address of a symbol into the global pointer register `_gp`.
 10 .option push
 11 .option norelax
 12     la gp, __global_pointer$
 13 .option pop
 14
 15 # loads the address of the symbol `_sp` into the register `sp`
 16 # sp points to the current top of the stack
 17     la sp, _sp
 18 #ifdef SIMULATION
 19     li x26, 0x00
 20     li x27, 0x00
 21 #endif
 22
 23     /* Load data section */
 24     la a0, _data_lma /* TODO What is the data stored at _data_lma, 0 or not? */
 25     la a1, _data
 26     la a2, _edata
 27     # if a1 >= a2, then jump forward to label 2
 28     bgeu a1, a2, 2f
 29
 30 # Copy data segement
 31 1:
 32     lw t0, (a0)
 33     sw t0, (a1)
 34     addi a0, a0, 4
 35     addi a1, a1, 4
 36     # if a1 < a2(end address), then back jump to label 1. So it is a lool here to initialize the data segement.
 37     bltu a1, a2, 1b
 38
 39 2:
 40     /* Clear bss section */
 41     la a0, __bss_start
 42     la a1, _end
 43     bgeu a0, a1, 2f
 44 1:
 45     # store 0 to the address that a0 refers to
 46     sw zero, (a0)
 47     addi a0, a0, 4
 48     bltu a0, a1, 1b
 49 2:
 50
 51     call _init
 52     call main
 53
 54 #ifdef SIMULATION
 55     li x26, 0x01
 56 #endif
 57
 58 loop:
 59     j loop

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值