main.c
#include "s5pc100.h" void delay(int ms) { int i; while (ms--) { i = 4000; while (i--); } } int main() { int num = 0; char c; GPG3.GPG3CON = 0x1111;//将GPG3端口与LED相连的引脚设置为输出模式 GPG3.GPG3DAT = 0;//数据寄存器的值设置为零 while (1) { GPG3.GPG3DAT |= (1 << num); delay(500); GPG3.GPG3DAT &= ~(1 << num); delay(500); num++; num %= 4; } return 0; }start.s
.text .global _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_handler _fiq: .word _fiq reset: ldr r0, =0x20008000 mcr p15, 0, r0, c12, c0, 0 /*将中断向量表的地址设置为从0x20008000开始*/ init_stack: ldr r0, stackpointer /* get stack pointer */ mov sp, r0 sub r0, #128 * 4 /* 512 byte for irq mode of stack */ msr cpsr, #0xD2 mov sp, r0 sub r0, #128 * 4 /* 512 byte for fiq mode of stack */ msr cpsr, #0xD1 mov sp, r0 sub r0, #0 msr cpsr, #0xD7 mov sp, r0 sub r0, #0 msr cpsr, #0xDB mov sp, r0 sub r0, #0 msr cpsr, #0x10 mov sp,r0 /* 1024 byte for user mode of stack */ b main .align 5 irq_handler: sub lr,lr,#4 stmfd sp!,{r0-r12,lr} @bl do_irq ldmfd sp!,{r0-r12,pc}^ stackpointer: .word stack + 4 * 512 .data stack: .space 4 * 512 .end连接文件:
map.lds,其中代码段让start.o位于text的最前面
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm") /*OUTPUT_FORMAT("elf32-arm", "elf32-arm", "elf32-arm")*/ OUTPUT_ARCH(arm) ENTRY(_start) SECTIONS { . = 0x20008000; . = ALIGN(4); .text : { start.o(.text) *(.text) } . = ALIGN(4); .rodata : { *(.rodata) } . = ALIGN(4); .data : { *(.data) } . = ALIGN(4); .bss : { *(.bss) } }
Makefile
all: arm-cortex_a8-linux-gnueabi-gcc -fno-builtin -nostdinc -c -o start.o start.S arm-cortex_a8-linux-gnueabi-gcc -fno-builtin -nostdinc -c -o main.o main.c arm-cortex_a8-linux-gnueabi-ld start.o main.o -Tmap.lds -o test.elf arm-cortex_a8-linux-gnueabi-objcopy -O binary test.elf test.bin arm-cortex_a8-linux-gnueabi-objdump -D test.elf > test.dis sudo cp test.bin /var/lib/tftpboot clean: rm -rf start.o main.o test.elf test.bin test.dis其中-fno-builtin表示不接受不是两个下划线开头的内建函数(built-in function),-nostdinc表示编译时不使用c库。
arm-cortex_a8-linux-gnueabi-objcopy -O binary test.elf test.bin这句话作用是将test.elf的格式头去掉并拷贝位test.bin
arm-cortex_a8-linux-gnueabi-objdump -D test.elf > test.dis这句反汇编只是为了查看一下编译出来的汇编代码。
工程源码:点击打开链接
基于Cortex-A8裸机,点亮LED灯程序分析,布布扣,bubuko.com
原文:http://blog.csdn.net/it_liuwei/article/details/22419555