root / tests / hello-arm.c @ 43057ab1
History | View | Annotate | Download (3.1 kB)
1 | 394411ac | bellard | #define __NR_SYSCALL_BASE 0x900000 |
---|---|---|---|
2 | 394411ac | bellard | #define __NR_exit1 (__NR_SYSCALL_BASE+ 1) |
3 | 394411ac | bellard | #define __NR_write (__NR_SYSCALL_BASE+ 4) |
4 | 394411ac | bellard | |
5 | 394411ac | bellard | #define __sys2(x) #x |
6 | 394411ac | bellard | #define __sys1(x) __sys2(x)
|
7 | 394411ac | bellard | |
8 | 394411ac | bellard | #ifndef __syscall
|
9 | 394411ac | bellard | #define __syscall(name) "swi\t" __sys1(__NR_##name) "\n\t" |
10 | 394411ac | bellard | #endif
|
11 | 394411ac | bellard | |
12 | 394411ac | bellard | #define __syscall_return(type, res) \
|
13 | 394411ac | bellard | do { \
|
14 | 394411ac | bellard | return (type) (res); \
|
15 | 394411ac | bellard | } while (0) |
16 | 394411ac | bellard | |
17 | 394411ac | bellard | #define _syscall0(type,name) \
|
18 | 394411ac | bellard | type name(void) { \
|
19 | 394411ac | bellard | long __res; \
|
20 | 394411ac | bellard | __asm__ __volatile__ ( \ |
21 | 394411ac | bellard | __syscall(name) \ |
22 | 394411ac | bellard | "mov %0,r0" \
|
23 | 394411ac | bellard | :"=r" (__res) : : "r0","lr"); \ |
24 | 394411ac | bellard | __syscall_return(type,__res); \ |
25 | 394411ac | bellard | } |
26 | 394411ac | bellard | |
27 | 394411ac | bellard | #define _syscall1(type,name,type1,arg1) \
|
28 | 394411ac | bellard | type name(type1 arg1) { \ |
29 | 394411ac | bellard | long __res; \
|
30 | 394411ac | bellard | __asm__ __volatile__ ( \ |
31 | 394411ac | bellard | "mov\tr0,%1\n\t" \
|
32 | 394411ac | bellard | __syscall(name) \ |
33 | 394411ac | bellard | "mov %0,r0" \
|
34 | 394411ac | bellard | : "=r" (__res) \
|
35 | 394411ac | bellard | : "r" ((long)(arg1)) \ |
36 | 394411ac | bellard | : "r0","lr"); \ |
37 | 394411ac | bellard | __syscall_return(type,__res); \ |
38 | 394411ac | bellard | } |
39 | 394411ac | bellard | |
40 | 394411ac | bellard | #define _syscall2(type,name,type1,arg1,type2,arg2) \
|
41 | 394411ac | bellard | type name(type1 arg1,type2 arg2) { \ |
42 | 394411ac | bellard | long __res; \
|
43 | 394411ac | bellard | __asm__ __volatile__ ( \ |
44 | 394411ac | bellard | "mov\tr0,%1\n\t" \
|
45 | 394411ac | bellard | "mov\tr1,%2\n\t" \
|
46 | 394411ac | bellard | __syscall(name) \ |
47 | 394411ac | bellard | "mov\t%0,r0" \
|
48 | 394411ac | bellard | : "=r" (__res) \
|
49 | 394411ac | bellard | : "r" ((long)(arg1)),"r" ((long)(arg2)) \ |
50 | 394411ac | bellard | : "r0","r1","lr"); \ |
51 | 394411ac | bellard | __syscall_return(type,__res); \ |
52 | 394411ac | bellard | } |
53 | 394411ac | bellard | |
54 | 394411ac | bellard | |
55 | 394411ac | bellard | #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
|
56 | 394411ac | bellard | type name(type1 arg1,type2 arg2,type3 arg3) { \ |
57 | 394411ac | bellard | long __res; \
|
58 | 394411ac | bellard | __asm__ __volatile__ ( \ |
59 | 394411ac | bellard | "mov\tr0,%1\n\t" \
|
60 | 394411ac | bellard | "mov\tr1,%2\n\t" \
|
61 | 394411ac | bellard | "mov\tr2,%3\n\t" \
|
62 | 394411ac | bellard | __syscall(name) \ |
63 | 394411ac | bellard | "mov\t%0,r0" \
|
64 | 394411ac | bellard | : "=r" (__res) \
|
65 | 394411ac | bellard | : "r" ((long)(arg1)),"r" ((long)(arg2)),"r" ((long)(arg3)) \ |
66 | 394411ac | bellard | : "r0","r1","r2","lr"); \ |
67 | 394411ac | bellard | __syscall_return(type,__res); \ |
68 | 394411ac | bellard | } |
69 | 394411ac | bellard | |
70 | 394411ac | bellard | |
71 | 394411ac | bellard | #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
|
72 | 394411ac | bellard | type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \ |
73 | 394411ac | bellard | long __res; \
|
74 | 394411ac | bellard | __asm__ __volatile__ ( \ |
75 | 394411ac | bellard | "mov\tr0,%1\n\t" \
|
76 | 394411ac | bellard | "mov\tr1,%2\n\t" \
|
77 | 394411ac | bellard | "mov\tr2,%3\n\t" \
|
78 | 394411ac | bellard | "mov\tr3,%4\n\t" \
|
79 | 394411ac | bellard | __syscall(name) \ |
80 | 394411ac | bellard | "mov\t%0,r0" \
|
81 | 394411ac | bellard | : "=r" (__res) \
|
82 | 394411ac | bellard | : "r" ((long)(arg1)),"r" ((long)(arg2)),"r" ((long)(arg3)),"r" ((long)(arg4)) \ |
83 | 394411ac | bellard | : "r0","r1","r2","r3","lr"); \ |
84 | 394411ac | bellard | __syscall_return(type,__res); \ |
85 | 394411ac | bellard | } |
86 | 394411ac | bellard | |
87 | 394411ac | bellard | |
88 | 394411ac | bellard | #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5) \
|
89 | 394411ac | bellard | type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) { \ |
90 | 394411ac | bellard | long __res; \
|
91 | 394411ac | bellard | __asm__ __volatile__ ( \ |
92 | 394411ac | bellard | "mov\tr0,%1\n\t" \
|
93 | 394411ac | bellard | "mov\tr1,%2\n\t" \
|
94 | 394411ac | bellard | "mov\tr2,%3\n\t" \
|
95 | 394411ac | bellard | "mov\tr3,%4\n\t" \
|
96 | 394411ac | bellard | "mov\tr4,%5\n\t" \
|
97 | 394411ac | bellard | __syscall(name) \ |
98 | 394411ac | bellard | "mov\t%0,r0" \
|
99 | 394411ac | bellard | : "=r" (__res) \
|
100 | 394411ac | bellard | : "r" ((long)(arg1)),"r" ((long)(arg2)),"r" ((long)(arg3)),"r" ((long)(arg4)), \ |
101 | 394411ac | bellard | "r" ((long)(arg5)) \ |
102 | 394411ac | bellard | : "r0","r1","r2","r3","r4","lr"); \ |
103 | 394411ac | bellard | __syscall_return(type,__res); \ |
104 | 394411ac | bellard | } |
105 | 394411ac | bellard | |
106 | 394411ac | bellard | _syscall1(int,exit1,int,status); |
107 | 394411ac | bellard | _syscall3(int,write,int,fd,const char *,buf, int, len); |
108 | 394411ac | bellard | |
109 | 394411ac | bellard | void _start(void) |
110 | 394411ac | bellard | { |
111 | 394411ac | bellard | write(1, "Hello World\n", 12); |
112 | 394411ac | bellard | exit1(0);
|
113 | 394411ac | bellard | } |