Commit 394411ac7442f6c3803b7f60379697b750b2ab3f

Authored by bellard
1 parent ea768640

added hello world for ARM


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@231 c046a42c-6fe2-441c-8c8c-71466251a162
tests/.cvsignore
1 1 gmon.out
2 2 testsig
3 3 hello
  4 + hello-arm
4 5 sha1.test.c
5 6 sha1.c
6 7 test-i386
... ...
tests/Makefile
... ... @@ -59,5 +59,12 @@ speed: sha1 sha1-i386
59 59 runcom: runcom.c
60 60 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<
61 61  
  62 +# arm test
  63 +hello-arm: hello-arm.o
  64 + arm-linux-ld -o $@ $<
  65 +
  66 +hello-arm.o: hello-arm.c
  67 + arm-linux-gcc -Wall -g -O2 -c -o $@ $<
  68 +
62 69 clean:
63 70 rm -f *~ *.o $(TESTS)
... ...
tests/hello-arm.c 0 → 100644
  1 +#define __NR_SYSCALL_BASE 0x900000
  2 +#define __NR_exit1 (__NR_SYSCALL_BASE+ 1)
  3 +#define __NR_write (__NR_SYSCALL_BASE+ 4)
  4 +
  5 +#define __sys2(x) #x
  6 +#define __sys1(x) __sys2(x)
  7 +
  8 +#ifndef __syscall
  9 +#define __syscall(name) "swi\t" __sys1(__NR_##name) "\n\t"
  10 +#endif
  11 +
  12 +#define __syscall_return(type, res) \
  13 +do { \
  14 + return (type) (res); \
  15 +} while (0)
  16 +
  17 +#define _syscall0(type,name) \
  18 +type name(void) { \
  19 + long __res; \
  20 + __asm__ __volatile__ ( \
  21 + __syscall(name) \
  22 + "mov %0,r0" \
  23 + :"=r" (__res) : : "r0","lr"); \
  24 + __syscall_return(type,__res); \
  25 +}
  26 +
  27 +#define _syscall1(type,name,type1,arg1) \
  28 +type name(type1 arg1) { \
  29 + long __res; \
  30 + __asm__ __volatile__ ( \
  31 + "mov\tr0,%1\n\t" \
  32 + __syscall(name) \
  33 + "mov %0,r0" \
  34 + : "=r" (__res) \
  35 + : "r" ((long)(arg1)) \
  36 + : "r0","lr"); \
  37 + __syscall_return(type,__res); \
  38 +}
  39 +
  40 +#define _syscall2(type,name,type1,arg1,type2,arg2) \
  41 +type name(type1 arg1,type2 arg2) { \
  42 + long __res; \
  43 + __asm__ __volatile__ ( \
  44 + "mov\tr0,%1\n\t" \
  45 + "mov\tr1,%2\n\t" \
  46 + __syscall(name) \
  47 + "mov\t%0,r0" \
  48 + : "=r" (__res) \
  49 + : "r" ((long)(arg1)),"r" ((long)(arg2)) \
  50 + : "r0","r1","lr"); \
  51 + __syscall_return(type,__res); \
  52 +}
  53 +
  54 +
  55 +#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
  56 +type name(type1 arg1,type2 arg2,type3 arg3) { \
  57 + long __res; \
  58 + __asm__ __volatile__ ( \
  59 + "mov\tr0,%1\n\t" \
  60 + "mov\tr1,%2\n\t" \
  61 + "mov\tr2,%3\n\t" \
  62 + __syscall(name) \
  63 + "mov\t%0,r0" \
  64 + : "=r" (__res) \
  65 + : "r" ((long)(arg1)),"r" ((long)(arg2)),"r" ((long)(arg3)) \
  66 + : "r0","r1","r2","lr"); \
  67 + __syscall_return(type,__res); \
  68 +}
  69 +
  70 +
  71 +#define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
  72 +type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \
  73 + long __res; \
  74 + __asm__ __volatile__ ( \
  75 + "mov\tr0,%1\n\t" \
  76 + "mov\tr1,%2\n\t" \
  77 + "mov\tr2,%3\n\t" \
  78 + "mov\tr3,%4\n\t" \
  79 + __syscall(name) \
  80 + "mov\t%0,r0" \
  81 + : "=r" (__res) \
  82 + : "r" ((long)(arg1)),"r" ((long)(arg2)),"r" ((long)(arg3)),"r" ((long)(arg4)) \
  83 + : "r0","r1","r2","r3","lr"); \
  84 + __syscall_return(type,__res); \
  85 +}
  86 +
  87 +
  88 +#define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5) \
  89 +type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) { \
  90 + long __res; \
  91 + __asm__ __volatile__ ( \
  92 + "mov\tr0,%1\n\t" \
  93 + "mov\tr1,%2\n\t" \
  94 + "mov\tr2,%3\n\t" \
  95 + "mov\tr3,%4\n\t" \
  96 + "mov\tr4,%5\n\t" \
  97 + __syscall(name) \
  98 + "mov\t%0,r0" \
  99 + : "=r" (__res) \
  100 + : "r" ((long)(arg1)),"r" ((long)(arg2)),"r" ((long)(arg3)),"r" ((long)(arg4)), \
  101 + "r" ((long)(arg5)) \
  102 + : "r0","r1","r2","r3","r4","lr"); \
  103 + __syscall_return(type,__res); \
  104 +}
  105 +
  106 +_syscall1(int,exit1,int,status);
  107 +_syscall3(int,write,int,fd,const char *,buf, int, len);
  108 +
  109 +void _start(void)
  110 +{
  111 + write(1, "Hello World\n", 12);
  112 + exit1(0);
  113 +}
... ...