arm 裸机程序

来源:互联网 发布:淘宝销量第一的产品 编辑:程序博客网 时间:2024/05/01 22:44

loadbin D:\armProgram.bin  f8001000

setpc  f8001000


makefile shell :

#!/bin/bash
 export PATH=/opt/freescale/usr/local/gcc-4.4.4-glibc-2.11.1-multilib-1.0/arm-fsl-linux-gnueabi/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
arm-linux-gcc -g -c -o armProgram.o armProgram.S  
arm-linux-gcc -g -c -o armcProgram.o armcProgram.c
arm-linux-ld -Ttext 0xf8001000 -g armProgram.o armcProgram.o -o armProgram_elf  
#arm-linux-ld -Ttext 0xf8001000 -g armcProgram.o -o armProgram_elf
arm-linux-objcopy -O binary -S armProgram_elf armProgram.bin  


armcProgram.c 内容:

  void start_armboot (void)
{
    *((int *)(0x53fa8320)) = 1;  //alt1  gpio1[3]  user_led
    *((int *)(0x53f84004)) = *((int *)(0x53f84004)) | 8;  //gpio1[3]
    while( 1 )
    {
        *((unsigned int *) 0x53f84000) = *((unsigned int *) 0x53f84000) ^  (1<<3);
    }
    
    return ;
}


armProgram.S 内容:

.globl _start

_start: b    reset
    

.globl _armboot_start
_armboot_start:
    .word _start

reset:
    /*
     * set the cpu to SVC32 mode
     */
    mrs    r0, cpsr    //read cpsr to ro
    bic    r0, r0, #0x1f  //clear r0's 0x1f bits  ==>  r0 & (~0x1f)
    orr    r0, r0, #0xd3  
    msr    cpsr,r0   //store ro0 to cpsr

    /* the mask ROM code should have PLL and others stable */

    bl    cpu_init_crit

    /* Set up the stack */
stack_setup:
    ldr    r0, =0xf8010000            @ upper 128 KiB: relocated uboot
    sub    r0, r0, #1024 @ malloc area  1024
    sub    r0, r0, #512 @ bdinfo 512

    sub    sp, r0, #12        @ leave 3 words for abort-stack
    and    sp, sp, #~7        @ 8 byte alinged for (ldr/str)d
//删除了bss部分,出错了

    ldr    pc, _start_armboot    @ jump to C code

_start_armboot: .word start_armboot


/*************************************************************************
 *
 * CPU_init_critical registers
 *
 * setup important registers
 * setup memory timing
 *
 *************************************************************************/
cpu_init_crit:
    /*
     * Invalidate L1 I/D
     */
    mov    r0, #0            @ set up for MCR
    mcr    p15, 0, r0, c8, c7, 0    @ invalidate TLBs
    mcr    p15, 0, r0, c7, c5, 0    @ invalidate icache

    /*
     * disable MMU stuff and caches
     */
    mrc    p15, 0, r0, c1, c0, 0
    bic    r0, r0, #0x00002000    @ clear bits 13 (--V-)
    bic    r0, r0, #0x00000007    @ clear bits 2:0 (-CAM)
    orr    r0, r0, #0x00000002    @ set bit 1 (--A-) Align
    orr    r0, r0, #0x00000800    @ set bit 12 (Z---) BTB
    mcr    p15, 0, r0, c1, c0, 0

    mov    pc, lr            @ back to my caller
原创粉丝点击