xref: /openbmc/qemu/tests/tcg/arm/hello-arm.c (revision af531756)
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 }
114