这事我们sep611uboot start.S文件。核是unicore的 汇编和arm有些不一样,但类似
.globl _start
_start:
b reset
ldw pc, _extend_handle
ldw pc, _swi_handle
ldw pc, _iabort_handle
ldw pc, _dabort_handle
ldw pc, _reserve_handle
ldw pc, _IRQ_handle
ldw pc, _FIQ_handle
_extend_handle: .word extend_handle
_swi_handle: .word swi_handle
_iabort_handle: .word iabort_handle
_dabort_handle: .word dabort_handle
_reserve_handle: .word reserve_handle
_IRQ_handle: .word IRQ_handle
_FIQ_handle: .word FIQ_handle
.balignl 16,0xdeadbeef
.global _TEXT_BASE
_TEXT_BASE:
.word TEXT_BASE @ load address
.globl _unicoreboot_start
_unicoreboot_start:
.word _start @ u-boot run address
.globl _bss_start
_bss_start:
.word __bss_start @ load end address
.globl _bss_end
_bss_end:
.word _end
.globl IRQ_STACK_START
IRQ_STACK_START:
.word 0x0badc0de
.globl FIQ_STACK_START
FIQ_STACK_START:
.word 0x0badc0de
/*
*************************************************************************
*
* Startup Code (called from the UNICORE reset exception vector)
*
* do important init only if we don't start from memory!
* relocate unicoreboot to ram
* setup stack
* jump to second stage
*
*************************************************************************
*/
/*
* the actual start code
*/
reset:
/*The first thing is to remap ddr from 0x40000000 to 0x0
*remember the code is move from the sd card to ddr
*/
@ ldw r0, =0x30008000
@ ldw r1, [r0]
@ or r1, r1, #0x80000000
@ stw r1, [r0] @本来想整合哈逻辑,乱动动,最近实验室确板子
ldw r12, =0x100
ldw r0, = 0x40300000
ldw r1, = 0x00000000
copy_vetor:
ldw r2, [r0] @其实这里没必要,因为我门的sdboot中是有ldw pc, =0x40300000 由于总线重映射原因 ddr有双重地址,所以其实代码还是在0x40300000里面跑的,见后面的链接代码
stw r2, [r1]
add r0, r0, #4
add r1, r1, #4
sub r12, r12, #4
cmpsub.a r12, #0
bne copy_vetor
@disable the irq
mov r0, asr
or r0, r0, #0x80
mov.a asr, r0
@irq stack
mov r1, asr
andn r1, r1, #0x1f
or r1, r1, #0x12 @irq mode
mov.a asr, r1
movl sp, #0x3f0000 @403f0000 @unicore sp 和lr都有相应的影子寄存器,前面如果没有进行0地址映射在这里堆栈就跑到esram里面去了,需要验证
sub sp, sp, #0x4
@svc stack
mov r1, asr
andn r1, r1, #0x1f
or r1, r1, #0x13 @svc mode
mov.a asr, r1
movl sp,#0x310000
@@ cmove stack top pointer to highest word of set58
@ movl sp,#0x3f0000 @@ set58,in user program data segment
movl r19, #0 @@ won't be dump out
@enalbe irq
mov r0, asr
andn r0, r0, #0x80
mov.a asr, r0
nop
nop
nop
ldw r0, _TEXT_BASE @ upper 128 KiB: relocated uboot @这里和经典的uboot内位图是一样的
sub r0, r0, #CONFIG_SYS_MALLOC_LEN @ malloc area
sub r0, r0, #CONFIG_SYS_GBL_DATA_SIZE @ bdinfo
#ifdef CONFIG_USE_IRQ
sub r0, r0, #(CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ)
#endif
sub sp, r0, #12 @ leave 3 words for abort-stack
clear_bss: @bss的清零是为了让默认的全局变量为0
ldw r0, _bss_start @ find start of bss segment
ldw r1, _bss_end @ stop here
mov r2, #0x00000000 @ clear
clbss_l:stw r2, [r0] @ clear loop...
add r0, r0, #4
cmpsub.a r0, r1
bel clbss_l
@ IMPORT int_vector_handler
ldw r0,=int_vector_handler
ldw r1,=0x30000070
stw r0,[r1]
stw r0,[r1+],#4
ldw pc, _start_unicoreboot @跳到c程序
_start_unicoreboot:
.word start_unicoreboot
nop
nop
nop
nop
nop
nop
/*
* exception handlers
*/
extend_handle:
mov.a pc,lr
swi_handle:
mov.a pc,lr
iabort_handle:
mov.a pc,lr
dabort_handle:
mov.a pc,lr
reserve_handle:
mov.a pc,lr
IRQ_handle: @只实现了中断
stm.w (r0 - r10), [sp]-
stm.w (lr), [sp]-
ldw r3, =0xb0000080
ldw r4, [r3]
ldw lr, =int_return
ldw pc, [r4]
int_return:
nop
nop
ldm.w (lr), [sp+]
ldm.w (r0 - r10), [sp+]
mov.a pc, lr
FIQ_handle:
mov.a pc,lr
@这是用unicore-linux-objdump -d u-boot|less >ffff 反汇编得出的结果,可以看到入口地址为0x40300000,但是注意无论是linux还是uboot,在uboot代码的自我复制重定位前必定是地址无关的
@而linux是在开启mmu之前
Disassembly of section .text:
40300000 <_start>:
40300000: bc000015 b 40300058 <reset>
40300004: 79ffc018 ldw pc, [pc+], #24 ; 40300020 <_extend_handle>
40300008: 79ffc018 ldw pc, [pc+], #24 ; 40300024 <_swi_handle>
4030000c: 79ffc018 ldw pc, [pc+], #24 ; 40300028 <_iabort_handle>
40300010: 79ffc018 ldw pc, [pc+], #24 ; 4030002c <_dabort_handle>
40300014: 79ffc018 ldw pc, [pc+], #24 ; 40300030 <_reserve_handle>
40300018: 79ffc018 ldw pc, [pc+], #24 ; 40300034 <_IRQ_handle>
4030001c: 79ffc018 ldw pc, [pc+], #24 ; 40300038 <_FIQ_handle>