本文参考http://blog.csdn.net/eagle_lzt/article/details/6364692编写
贴上自己写的程序做个笔记,大家可以用jlink,或者dnw下载程序。
飞凌提供的uboot源码在“OK6410A官方基础资料2G\Linux-3.0.1\uboot_sourcedode\uboot1.1.6_FORLINX_6410.tgz”中,解压找到system.map
打开搜索printf找到 printf的地址,如图所示。
hello.c:
void (*show)(char*,...) = 0xc7e114a8;
int main(void)
{
show("hello.world!\n");
show("hello.linux\n");
return 0;
}
Makefile:
hello.bin:hello.o
arm-linux-ld -Ttext 0x50008000 hello.o -o hello.elf
arm-linux-objcopy -O binary hello.elf hello.bin
arm-linux-objdump -d hello.elf > hello.dls
hello.o:hello.c
arm-linux-gcc -c hello.c -o hello.o
clean:
rm hello.bin hello.o hello.elf hello.dls
反汇编代码:
hello.elf: file format elf32-littlearm
Disassembly of section .text:
50008000 <main>:
50008000: e1a0c00d mov ip, sp
50008004: e92dd800 push {fp, ip, lr, pc}
50008008: e24cb004 sub fp, ip, #4 ; 0x4
5000800c: e59f3034 ldr r3, [pc, #52] ; 50008048 <main+0x48>
50008010: e5933000 ldr r3, [r3]
50008014: e59f0030 ldr r0, [pc, #48] ; 5000804c <main+0x4c>
50008018: e1a0e00f mov lr, pc
5000801c: e12fff13 bx r3
50008020: e59f3020 ldr r3, [pc, #32] ; 50008048 <main+0x48>
50008024: e5933000 ldr r3, [r3]
50008028: e59f0020 ldr r0, [pc, #32] ; 50008050 <main+0x50>
5000802c: e1a0e00f mov lr, pc
50008030: e12fff13 bx r3
50008034: e3a03000 mov r3, #0 ; 0x0
50008038: e1a00003 mov r0, r3
5000803c: e24bd00c sub sp, fp, #12 ; 0xc
50008040: e89d6800 ldm sp, {fp, sp, lr}
50008044: e12fff1e bx lr
50008048: 50010074 .word 0x50010074
5000804c: 50008054 .word 0x50008054
50008050: 50008064 .word 0x50008064
-----------------------------------------
下面的程序是C语言内嵌汇编输出CPSR的状态:
void (*show)(char*,...) = 0xc7e114a8;
int main(void)
{
unsigned long cpsr;
__asm__ __volatile__(
"mrs %0,cpsr \n"
: "=r"(cpsr)
);
show("CPSR = 0x%x\n",cpsr);
return 0;
}