程序员

1、U-boot-1.16 基于s3c6410 start.S

2016-07-30  本文已影响147人  2625K

u-boot-1.1.6 Start.S 流程分析 基于S3c6410

start.S 文件位于srcPath/cpu/s3c64xx/ 目录
作为uboot运行的第一段程序,它做了一些具体的初始化流程,具体工作如下:

1.设置中断向量表

.globl _start
_start: b   reset
ldr pc, _undefined_instruction
ldr pc, _software_interrupt
ldr pc, _prefetch_abort
ldr pc, _data_abort
ldr pc, _not_used
ldr pc, _irq
ldr pc, _fiq

_undefined_instruction:
    .word undefined_instruction
_software_interrupt:
    .word software_interrupt
_prefetch_abort:
    .word prefetch_abort
_data_abort:
    .word data_abort
_not_used:
    .word not_used
_irq:
    .word irq
_fiq:
    .word fiq
_pad:
    .word 0x12345678 /* now 16*4=64 */
.global _end_vect

_end_vect:

.balignl 16,0xdeadbeef  @deadbeef 坏的牛肉

2.uboot相关段定义

/*在 /board/samung/mini6410/config.mk 定义,代码运行时的地址

_TEXT_BASE:

    .word   TEXT_BASE   

/*
 * Below variable is very important because we use MMU in U-Boot.
 * Without it, we cannot run code correctly before MMU is ON.
 * by scsuh.
 */
_TEXT_PHY_BASE:
    .word   CFG_PHY_UBOOT_BASE   

.globl _armboot_start
_armboot_start:
    .word _start

/*
 * These are defined in the board-specific linker script.
 */
.globl _bss_start
_bss_start:
    .word __bss_start

.globl _bss_end
_bss_end:
    .word _end
    

#ifdef CONFIG_USE_IRQ
/* IRQ stack memory (calculated at run-time) */
.globl IRQ_STACK_START
IRQ_STACK_START:
    .word   0x0badc0de   @badcode 坏代码

/* IRQ stack memory (calculated at run-time) */
.globl FIQ_STACK_START
FIQ_STACK_START:
    .word 0x0badc0de @badcode 坏代码
#endif

3.设置cpu的工作模式为SVC32

 * set the cpu to SVC32 mode
 
mrs r0,cpsr
bic r0,r0,#0x1f
orr r0,r0,#0xd3
msr cpsr,r0

4、刷新I/D Cache

    /*
 * flush v4 I/D caches
 */
mov r0, #0
mcr p15, 0, r0, c7, c7, 0   /* flush v3/v4 cache */
mcr p15, 0, r0, c8, c7, 0   /* flush v4 TLB */

5、关闭MMU与Cache

/*
 * disable MMU stuff and caches
 */
mrc p15, 0, r0, c1, c0, 0
bic r0, r0, #0x00002300 @ clear bits 13, 9:8 (--V- --RS)
bic r0, r0, #0x00000087 @ clear bits 7, 2:0 (B--- -CAM)
orr r0, r0, #0x00000002 @ set bit 2 (A) Align
orr r0, r0, #0x00001000 @ set bit 12 (I) I-Cache
mcr p15, 0, r0, c1, c0, 0

6、设置外围基地址

/* Peri port setup */
ldr r0, =0x70000000
orr r0, r0, #0x13
mcr p15,0,r0,c15,c2,4       @ 256M(0x70000000-0x7fffffff)

7、跳转到 lowlevel_init.S (/src/board/samsung/mini6410/lowlevel_init.S)

下面的动作均是在lowlevel_init.s 中所做:

8、拷贝代码到内存

#ifdef CONFIG_BOOT_NAND
mov r0, #0x1000   @4K
bl  copy_from_nand
#endif

9.使能MMU开关

#ifdef CONFIG_ENABLE_MMU
enable_mmu:
/* enable domain access */
ldr r5, =0x0000ffff
mcr p15, 0, r5, c3, c0, 0       @ load domain access register

/* Set the TTB register */
ldr r0, _mmu_table_base
ldr r1, =CFG_PHY_UBOOT_BASE
ldr r2, =0xfff00000
bic r0, r0, r2
orr r1, r0, r1
mcr p15, 0, r1, c2, c0, 0

/* Enable the MMU */
mmu_on:
mrc p15, 0, r0, c1, c0, 0
orr r0, r0, #1          /* Set CR_M to enable MMU */
mcr p15, 0, r0, c1, c0, 0
nop
nop
nop
nop
#endif

10、设置堆栈

stack_setup:
#ifdef CONFIG_MEMORY_UPPER_CODE
ldr sp, =(CFG_UBOOT_BASE + CFG_UBOOT_SIZE - 0xc)
#else

11、清零BSS段

clear_bss:
ldr r0, _bss_start      /* find start of bss segment        */
ldr r1, _bss_end        /* stop here                        */
mov     r2, #0x00000000     /* clear                            */

clbss_l:
str r2, [r0]        /* clear loop...                    */
add r0, r0, #4
cmp r0, r1
ble clbss_l

12、跳转到start_armboot()

ldr pc, _start_armboot

_start_armboot:
.word start_armboot
上一篇 下一篇

猜你喜欢

热点阅读