Chinaunix首页 | 论坛 | 博客
  • 博客访问: 19985
  • 博文数量: 8
  • 博客积分: 241
  • 博客等级: 二等列兵
  • 技术积分: 90
  • 用 户 组: 普通用户
  • 注册时间: 2009-08-04 08:35
文章分类
文章存档

2011年(1)

2010年(3)

2009年(4)

我的朋友
最近访客

分类: LINUX

2009-08-04 09:50:58

arm Linux 下最小helloworld实验,注意这里使用的是OABI方式,使用EABI要稍微修改一下程序。

/*
 * =====================================================================================
 *
 * Filename: tinyhelloworld.c
 *
 * Description: tinyhelloworld
 *
 * Version: 1.0
 * Created: 2009年07月04日 10时15分54秒
 * Revision: none
 * Compiler: gcc
 *
 * Author: qqbsd, qqbsd.zhou@gmail.com
 * Company: none
 *
 * =====================================================================================
 */


char *str = "hello world!\n";

/**********************************************
 *
 * function :print
 *description :use the syscall write
 *prototype of wirte:
 *    ssize_t write(int fd, const void *buf, size_t count)
 **********************************************/

void print(void)
{
    __asm__ __volatile__(
            "mov r0, #0x0\n\t" /*fd*/
            "mov r1, %0\n\t" /*buf*/
            "mov r2, #0x0d\n\t" /*count*/
            "swi    (0x00900000 + 4)\n\t"
            ::"r"(str):"r0","r1","r2");
}

/********************************************
 * function: exit
 * description: use the syscall exit
 ********************************************/

void exit(void)
{
    __asm__ __volatile__(
            "mov r0, #42\n\t"
            "swi    (0x00900000 + 1)\n\t");
}

void nomain(void)
{
    print();
    exit();
}


#######tinyhellowrold.lds连接脚本#######

ENTRY(nomain)
SECTIONS
{
    . = 0x00008000 + SIZEOF_HEADERS;
  tinytext :
    {
        *(.text)
      *(.data)
        *(.rodata)
    }
  /DISCARD/ :
    {
        *(.comment)
    }
}

#######tinyhelloworld的Makefile######################

tinyhelloworld:   tinyhelloworld.c
    arm-linux-gcc -S -fno-builtin  tinyhelloworld.c
    arm-linux-gcc  -c -fno-builtin tinyhelloworld.s
    arm-linux-ld  -static -T tinyhelloworld.lds -o tinyhelloworld tinyhelloworld.o
clean:
    -rm tinyhelloworld *.o tinyhelloworld.s

阅读(1332) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~