mini2440的初始化_纯汇编语言

  start.S如下:

.text

.global _start

_start:
    b reset
    ldr pc, _undifined_instruction
    ldr pc, _software_interrupt
    ldr pc, _prefetch_abort
    ldr pc, _data_abort
    ldr pc, _not_used
    ldr pc, _irq
    ldr pc, _fiq

_undifined_instruction: .word undifined_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 reset

undifined_instruction:
    nop

software_interrupt:
    nop

prefetch_abort:
    nop

data_abort:
    nop

not_used:
    nop

irq:
    nop

fiq:
    nop

reset:
    bl set_svc
    bl disable_watchdog
    bl disable_interrupt
    bl disable_mmu
    bl init_clock
    bl init_sdram
    bl copy_to_ram
    bl init_stack
    bl clean_bss
    bl light_led

set_svc:
    mrs r0, cpsr
    bic r0, r0, #0x1f
    orr r0, r0, #0xd3
    msr cpsr, r0
    mov pc, lr

#define pWTCON 0x53000000
disable_watchdog:
    ldr r0, =pWTCON  @ 往WATCHDOG寄存器写0即可
    mov r1, #0x0
    str r1, [r0]
    mov pc, lr

disable_interrupt:
    mvn r1, #0x0
    ldr r0, =0x4a000008
    str r1, [r0]
    mov pc, lr

disable_mmu:
    mcr p15, 0, r0, c7, c7, 0
    mrc p15, 0, r0, c1, c0, 0
    bic r0, r0, #0x00000007
    mcr p15, 0, r0, c1, c0, 0
    mov pc, lr

#define CLKDIVN 0x4c000014
#define MPLLCON 0x4c000008
#define MPLL_405MHZ ((127<<12)|(2<<4)|(1<<0))

init_clock:
    ldr r0, =CLKDIVN
    mov r1, #0x5
    str r1, [r0]

    mcr p15, 0, r0, c1, c0, 0
    orr r0, r0, #0xc0000000
    mcr p15, 0, r0, c1, c0, 0

    ldr r0, =MPLLCON
    ldr r1, =MPLL_405MHZ
    str r1, [r0]
    mov pc, lr

@ 设置存储控制器以便使用SDRAM等外设
#define mem_contrl 0x48000000  @ 存储控制器的13个寄存器的开始地址
init_sdram:
    ldr r0, =mem_contrl
    add r3, r0, #4*13
    adrl r1, mem_data  @ 这13个值的起始存储地址

0:
    ldr r2, [r1], #4
    str r2, [r0], #4
    cmp r0, r3
    bne 0b
    mov pc, lr

copy_to_ram:
@ 将SteppingStone的4KB数据全部复制到SDRAM中
@ SteppingStone的起始地址是0x0,SDRAM的起始地址为0x30000000
    ldr r0, =0x0
    ldr r1, =0x30000000
    add r3, r0, #1024*4

copy_loop:
    ldr r2, [r0], #4
    str r2, [r1], #4
    cmp r0, r3
    bne copy_loop
    mov pc, lr

init_stack:
    ldr sp, =0x34000000
    mov pc, lr

clean_bss:
    ldr r0, =bss_start
    ldr r1, =bss_end
    cmp r0, r1
    moveq pc, lr

clean_loop:
    mov r2, #0
    str r2, [r0], #4
    cmp r0, r1
    bne clean_loop
    mov pc, lr

mem_data:
    .long 0x22000000  @ BWSCON
    .long 0x00000700  @ BANKCON0
    .long 0x00000700  @ BANKCON1
    .long 0x00000700  @ BANKCON2
    .long 0x00000700  @ BANKCON3
    .long 0x00000700  @ BANKCON4
    .long 0x00000700  @ BANKCON5
    .long 0x00018001  @ BANKCON6
    .long 0x00018001  @ BANKCON7
    .long 0x008c04f5  @ REFRESH
    .long 0x000000b1  @ BANKSIZE
    .long 0x00000030  @ MRSRB6
    .long 0x00000030  @ MRSRB7

#define GPBCON 0x56000010
#define GPBDAT 0x56000014

light_led:
    ldr r0, =GPBCON
    mov r1, #0x400
    str r1, [r0]

    ldr r0, =GPBDAT
    mov r1, #0x0
    str r1, [r0]
    mov pc, lr

  gboot.lds如下:

OUTPUT_ARCH(arm)
ENTRY(_start)

SECTIONS {
    . = 0x30000000;

    . = ALIGN(4);
    .text : {
        start.o (.text)
        *(.text)
    }

    . = ALIGN(4);
    .data : {
        *(.data)
    }

    . = ALIGN(4);
    bss_start = .;
    .bss : {
        *(.bss)
    }

    bss_end = .;
}

  Makefile如下:

all: start.o
    arm-linux-ld -Tgboot.lds -o gboot.elf $^
    arm-linux-objcopy -O binary gboot.elf gboot.bin

%.o: %.S
    arm-linux-gcc -g -c $^

.PHONY: clean
clean:
    rm *.o *.elf *.bin
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值