Separate thread for IO handling
[qemu-kvm/fedora.git] / tests / hello-mips.c
blobf8256730dd108310fb13c99ae93cce73a6d61ea0
1 /*
2 * MIPS o32 Linux syscall example
4 * http://www.linux-mips.org/wiki/RISC/os
5 * http://www.linux-mips.org/wiki/MIPSABIHistory
6 * http://www.linux.com/howtos/Assembly-HOWTO/mips.shtml
8 * mipsel-linux-gcc -nostdlib -mno-abicalls -fno-PIC -mabi=32 \
9 * -O2 -static -o hello-mips hello-mips.c
12 #define __NR_SYSCALL_BASE 4000
13 #define __NR_exit (__NR_SYSCALL_BASE+ 1)
14 #define __NR_write (__NR_SYSCALL_BASE+ 4)
16 static inline void exit1(int status)
18 register unsigned long __a0 asm("$4") = (unsigned long) status;
20 __asm__ __volatile__ (
21 " .set push \n"
22 " .set noreorder \n"
23 " li $2, %0 \n"
24 " syscall \n"
25 " .set pop "
27 : "i" (__NR_exit), "r" (__a0)
28 : "$2", "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15", "$24",
29 "memory");
32 static inline int write(int fd, const char *buf, int len)
34 register unsigned long __a0 asm("$4") = (unsigned long) fd;
35 register unsigned long __a1 asm("$5") = (unsigned long) buf;
36 register unsigned long __a2 asm("$6") = (unsigned long) len;
37 register unsigned long __a3 asm("$7");
38 unsigned long __v0;
40 __asm__ __volatile__ (
41 " .set push \n"
42 " .set noreorder \n"
43 " li $2, %2 \n"
44 " syscall \n"
45 " move %0, $2 \n"
46 " .set pop "
47 : "=r" (__v0), "=r" (__a3)
48 : "i" (__NR_write), "r" (__a0), "r" (__a1), "r" (__a2)
49 : "$2", "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15", "$24",
50 "memory");
52 /* if (__a3 == 0) */
53 return (int) __v0;
55 errno = __v0;
56 return -1;
60 void __start(void)
62 write (1, "Hello, World!\n", 14);
63 exit1 (42);