org.xwt.mips -> org.ibex.nestedvm
[nestedvm.git] / src / org / ibex / nestedvm / support.s
1 #include "syscalls.h"
2
3 #define zero $0
4 #define v0 $2
5 #define v1 $3
6 #define a0 $4
7 #define a1 $5
8 #define a2 $6
9 #define a3 $7
10 #define t0 $8
11 #define t1 $9
12 #define ra $31
13
14 /* We intentionally don't take advantage of delay slots because
15    the compiler removes them anyway */
16
17 .set noreorder;
18
19 #define SYSCALL(name) SYSCALL2(name,SYS_##name)
20 #define SYSCALL2(name,number)  \
21     .section .text.name,"ax",@progbits; \
22     .align 2;       \
23     .globl name;    \
24     .ent name;      \
25 name:               \
26     li v0, number;  \
27     syscall;        \
28     j ra;           \
29     nop;            \
30     .end name;
31
32 #define SYSCALL_R(name)        \
33     .section .text._##name##_r,"ax",@progbits; \
34     .align 2;                  \
35     .globl _##name##_r;        \
36     .ent _##name##_r;          \
37 _##name##_r:                   \
38     li v0, SYS_##name;         \
39     move t0, a0;               \
40     move a0, a1;               \
41     move a1, a2;               \
42     move a2, a3;               \
43     syscall;                   \
44     addu t1,v0,255;            \
45     sltu t1,t1,255;            \
46     bne t1,zero,$L##name##_errno;\
47     nop;                       \
48     j ra;                      \
49     nop;                       \
50 $L##name##_errno:              \
51     move a0, t0;               \
52     move a1, v0;               \
53     j _syscall_set_errno;      \
54     nop;                       \
55     .end _##name##_r;
56
57
58     .align   2
59     .globl   _call_helper
60     .ent     _call_helper
61 _call_helper:
62     subu $sp,$sp,32
63     
64     /* addr */
65     move $2,$4
66     
67     /* args 1-4 */
68     move $4,$5 
69     move $5,$6
70     move $6,$7
71     move $7,$16
72     
73     /* args 5 and 6 */
74     sw $17,16($sp)
75     sw $18,20($sp)
76     
77     /* call the func */
78     jal $31,$2
79     nop
80     
81     move $3,$2
82     li $2,SYS_pause
83     syscall
84     
85     /* shouldn't get here */
86     li $2,SYS_exit
87     li $3,1
88     syscall
89     
90     .end _call_helper
91
92 SYSCALL2(_exit,SYS_exit)
93 SYSCALL2(_pause,SYS_pause)
94 SYSCALL_R(open)
95 SYSCALL_R(close)
96 SYSCALL_R(read)
97 SYSCALL_R(write)
98 SYSCALL_R(sbrk)
99 SYSCALL_R(fstat)
100 SYSCALL(isatty)
101 SYSCALL_R(lseek)
102 SYSCALL_R(kill)
103 SYSCALL_R(getpid)
104 SYSCALL2(_call_java,SYS_calljava)
105 SYSCALL_R(stat)
106 SYSCALL_R(gettimeofday)
107 SYSCALL(sleep)
108 SYSCALL_R(times)
109 SYSCALL_R(mkdir)
110 SYSCALL(getpagesize)
111 SYSCALL_R(unlink)
112 SYSCALL_R(utime)
113 SYSCALL_R(chdir)
114 SYSCALL_R(pipe)
115 SYSCALL_R(dup2)
116 SYSCALL_R(fork)
117 SYSCALL_R(waitpid)
118 SYSCALL_R(getcwd)
119 SYSCALL_R(execve)
120 SYSCALL_R(fcntl)
121 SYSCALL_R(rmdir)
122 SYSCALL_R(sysconf)