1
2
3
4
5
6
7
8
9
10
11
12#define __NR_SYSCALL_BASE 4000
13#define __NR_exit (__NR_SYSCALL_BASE+ 1)
14#define __NR_write (__NR_SYSCALL_BASE+ 4)
15
16static inline void exit1(int status)
17{
18 register unsigned long __a0 asm("$4") = (unsigned long) status;
19
20 __asm__ __volatile__ (
21 " .set push \n"
22 " .set noreorder \n"
23 " li $2, %0 \n"
24 " syscall \n"
25 " .set pop "
26 :
27 : "i" (__NR_exit), "r" (__a0)
28 : "$2", "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15", "$24",
29 "memory");
30}
31
32static inline int write(int fd, const char *buf, int len)
33{
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;
39
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");
51
52
53 return (int) __v0;
54
55
56
57
58}
59
60void __start(void)
61{
62 write (1, "Hello, World!\n", 14);
63 exit1(0);
64}
65