题外话:前一段看了一个文章很有感触,说是很多优秀的开源开发者到了google都停止了开发。为什么呢,因为开源一个很大的动力来自于对现有开发环境的不满,而google提供了一个近似理想的开发环境,所以大家就懈怠了。有意思,呵呵。
今天学习在Qemu下运行一个简单的Hello World程序,整个过程还是参照了
http://balau82.wordpress.com/2010/02/28/hello-world-for-bare-metal-arm-using-qemu/
基本过程是产生Hello World源程序,产生内存映射文件,然后编译下载。这个实验是针对ARM的,很多源程序不是特别明白,就当一个练习吧。
1. test.c 文件
volatile unsigned int * const UART0DR = (unsigned int *)0x101f1000;
void print_uart0(const char *s) {
while(*s != '\0') { /* Loop until end of string */
*UART0DR = (unsigned int)(*s); /* Transmit char */
s++; /* Next char */
}
}
void c_entry() {
print_uart0("Hello world!\n");
}
2. startup.s文件
.global _Reset
_Reset:
LDR sp, =stack_top
BL c_entry
B .
3. test.ld文件
ENTRY(_Reset)
SECTIONS
{
. = 0x10000;
.text : {
startup.o
*(.text)
}
.data : { *(.data) }
.bss : { *(.bss) }
. = . + 0x1000; /* 4kB of stack memory */
stack_top = .;
}
4. 编译命令
arm-linux-uclibcgnueabi-as -mcpu=arm926ej-s -g startup.s -o startup.o arm-linux-uclibcgnueabi-gcc -c -mcpu=arm926ej-s -g test.c -o test.o arm-linux-uclibcgnueabi-ld -T test.ld test.o startup.o -o test.elf arm-linux-uclibcgnueabi-objcopy -O binary test.elf test.bin
5. 开始仿真
qemu-system-arm -M versatilepb -nographic -kernel test.bin运行后出现了HelloWorld的字样。结束Qemu的仿真使用ctrl+a然后x 6. 使用gdb进行远程调试在qemu中启动debug功能qemu-system-arm -M versatilepb -nographic -s -S -kernel test.bin这时qemu会等待gdb命令
7. 新开一个窗口,运行
arm-linux-uclibcgnueabi-gdb
target remote localhost:1234 file test.elfexit可以退出debug