Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux 程式設計 >> Linux 程式設計

skyeye 下開發 S3C6410X 程式:寫第一個 helloworld

要在 skyeye 模擬器上跑 S3C6410X 的裸機程式,最經典的起點就是透過 UART 印出 helloworld。核心觀念只有一個:把某個記憶體位址當成暫存器,直接寫入字元,資料就會從序列埠送出去。

helloworld.c

依據 S3C6410X 的硬體資訊,UART0 的發送暫存器位址為 0x7f005020。

/*************************************************************************
> File Name: helloworld.c
> Author: muge0913
> Mail: muge0913@sina.com
> Created Time: 2013年02月12日星期二 15時33分11秒
************************************************************************/
#define UTXH0 ((volatile unsigned int *)(0x7f005020))

void helloworld()
{
    const char *p = "helloworld--muge0913\n";
    while (*p) {
        *UTXH0 = *p++;
    }
    while (1);
}

這裡的 volatile 修飾子不可省略,它告訴編譯器「這個位址的值可能隨時被硬體改變,每次都老實去記憶體讀寫,不要幫我做最佳化」,否則整段迴圈很可能被編譯器直接消掉。

skyeye.conf

# skyeye config file for s3c6410, os_test
arch:arm
cpu:arm11
mach:s3c6410x

# physical memory
mem_bank:map=M,type=RW,addr = 0x00000000,size = 0x00800000,file=./helloworld.bin

# all peripherals IO mapping area
mem_bank:map=I,type=RW,addr = 0x70000000,size = 0x10000000

uart:mod=term

記憶體從 0x00000000 起是因為 ARM 處理器上電後就從 0x00 處開始取指令;file= 表示預先載入到這片記憶體的映像檔;boot=yes 則表示預設從此處啟動。

編譯

arm-elf-gcc -O2 -c helloworld.c
arm-elf-ld -e helloworld -Ttext 0x00 helloworld.o -o helloworld
arm-elf-objcopy -O binary helloworld helloworld.bin

三個步驟分別是編譯、連結(指定進入點與文字段起始位址)與轉成純二進位檔。-Ttext 0x00 讓程式被放在位址 0,正好對應模擬器的載入位置。

執行測試

$ skyeye-main.py
$ start
$ run

終端機上就會看到 helloworld--muge0913 的字樣。相關連結:Ubuntu 12.04 下安裝 skyeye 1.3.3 的步驟可另行參考。

Copyright © Linux教程網 All Rights Reserved