1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| /* boot.S - SPARC LEON2 启动汇编 */
#include "cpu.h" #include "config.h"
.seg "text" PUBLIC(start) .global start
SYM(start): start: /* 硬件复位入口 */ PUBLIC(hard_reset) SYM(hard_reset):
common_init: /* 1. 初始化 PSR (Processor State Register) */ rd %psr, %g1 or %g1, 0xFA0, %g1 ! supervisor mode, disable interrupt, enable trap wr %g0, %g1, %psr nop ! PSR 写入需要 3 个延迟槽 nop nop
/* 2. 初始化 TBR (Trap Base Register) */ set 0x40000000, %g1 ! Trap 表放在 RAM 起始位置 mov %g1, %tbr /* 3. 初始化 WIM (Window Invalid Mask) */ set WIM_INIT, %g1 ! WIM_INIT = 2 mov %g1, %wim nop nop nop
/* 4. 初始化堆栈指针 */ set STACK_BASE, %g3 ! STACK_BASE = 0x40000000 + 160KB sub %g3, 1024, %g3 ! 预留 1KB 存储 FW Header 参数 sub %g3, 128, %g3 ! 预留输入参数空间 mov %g3, %fp ! 设置 Frame Pointer sub %g3, 96, %sp ! 设置 Stack Pointer (SPARC ABI 要求) andn %sp, 0x0f, %sp ! 16 字节对齐
/* 5. 使能 Cache */ set 0x80000014, %l1 ! Cache Control Register 地址 ld [%l1], %l2 set 0x81000F, %l3 ! 使能 I-Cache 和 D-Cache or %l3, %l2, %l2 st %l2, [%l1] flush ! 刷新 Pipeline nop nop nop
/* 6. 跳转到 C 代码 */ set SYM(boot_route), %g2 jmp %g2 nop
|