0
|
1 /*****************************************************************
|
|
2 * usys.S
|
|
3 * by Zhiyi Huang, hzy@cs.otago.ac.nz
|
|
4 * University of Otago
|
|
5 *
|
|
6 ********************************************************************/
|
|
7
|
|
8
|
|
9
|
|
10 #include "syscall.h"
|
|
11 #include "traps.h"
|
|
12
|
|
13 /* This is clumsy, but don't know how to make it smart */
|
|
14 .globl fork
|
|
15 fork:
|
|
16 push {lr}
|
|
17 push {r3}
|
|
18 push {r2}
|
|
19 push {r1}
|
|
20 push {r0}
|
|
21 mov r0, #SYS_fork
|
|
22 swi #T_SYSCALL
|
|
23 pop {r1} /* to avoid overwrite of r0 */
|
|
24 pop {r1}
|
|
25 pop {r2}
|
|
26 pop {r3}
|
|
27 pop {lr}
|
|
28 bx lr
|
|
29
|
|
30 .globl exit
|
|
31 exit:
|
|
32 push {lr}
|
|
33 push {r3}
|
|
34 push {r2}
|
|
35 push {r1}
|
|
36 push {r0}
|
|
37 mov r0, #SYS_exit
|
|
38 swi #T_SYSCALL
|
|
39 pop {r1} /* to avoid overwrite of r0 */
|
|
40 pop {r1}
|
|
41 pop {r2}
|
|
42 pop {r3}
|
|
43 pop {lr}
|
|
44 bx lr
|
|
45
|
|
46 .globl wait
|
|
47 wait:
|
|
48 push {lr}
|
|
49 push {r3}
|
|
50 push {r2}
|
|
51 push {r1}
|
|
52 push {r0}
|
|
53 mov r0, #SYS_wait
|
|
54 swi #T_SYSCALL
|
|
55 pop {r1} /* to avoid overwrite of r0 */
|
|
56 pop {r1}
|
|
57 pop {r2}
|
|
58 pop {r3}
|
|
59 pop {lr}
|
|
60 bx lr
|
|
61
|
|
62 .globl pipe
|
|
63 pipe:
|
|
64 push {lr}
|
|
65 push {r3}
|
|
66 push {r2}
|
|
67 push {r1}
|
|
68 push {r0}
|
|
69 mov r0, #SYS_pipe
|
|
70 swi #T_SYSCALL
|
|
71 pop {r1} /* to avoid overwrite of r0 */
|
|
72 pop {r1}
|
|
73 pop {r2}
|
|
74 pop {r3}
|
|
75 pop {lr}
|
|
76 bx lr
|
|
77
|
|
78 .globl read
|
|
79 read:
|
|
80 push {lr}
|
|
81 push {r3}
|
|
82 push {r2}
|
|
83 push {r1}
|
|
84 push {r0}
|
|
85 mov r0, #SYS_read
|
|
86 swi #T_SYSCALL
|
|
87 pop {r1} /* to avoid overwrite of r0 */
|
|
88 pop {r1}
|
|
89 pop {r2}
|
|
90 pop {r3}
|
|
91 pop {lr}
|
|
92 bx lr
|
|
93
|
|
94 .globl write
|
|
95 write:
|
|
96 push {lr}
|
|
97 push {r3}
|
|
98 push {r2}
|
|
99 push {r1}
|
|
100 push {r0}
|
|
101 mov r0, #SYS_write
|
|
102 swi #T_SYSCALL
|
|
103 pop {r1} /* to avoid overwrite of r0 */
|
|
104 pop {r1}
|
|
105 pop {r2}
|
|
106 pop {r3}
|
|
107 pop {lr}
|
|
108 bx lr
|
|
109
|
|
110 .globl close
|
|
111 close:
|
|
112 push {lr}
|
|
113 push {r3}
|
|
114 push {r2}
|
|
115 push {r1}
|
|
116 push {r0}
|
|
117 mov r0, #SYS_close
|
|
118 swi #T_SYSCALL
|
|
119 pop {r1} /* to avoid overwrite of r0 */
|
|
120 pop {r1}
|
|
121 pop {r2}
|
|
122 pop {r3}
|
|
123 pop {lr}
|
|
124 bx lr
|
|
125
|
|
126
|
|
127 .globl kill
|
|
128 kill:
|
|
129 push {lr}
|
|
130 push {r3}
|
|
131 push {r2}
|
|
132 push {r1}
|
|
133 push {r0}
|
|
134 mov r0, #SYS_kill
|
|
135 swi #T_SYSCALL
|
|
136 pop {r1} /* to avoid overwrite of r0 */
|
|
137 pop {r1}
|
|
138 pop {r2}
|
|
139 pop {r3}
|
|
140 pop {lr}
|
|
141 bx lr
|
|
142
|
|
143 .globl exec
|
|
144 exec:
|
|
145 push {lr}
|
|
146 push {r3}
|
|
147 push {r2}
|
|
148 push {r1}
|
|
149 push {r0}
|
|
150 mov r0, #SYS_exec
|
|
151 swi #T_SYSCALL
|
|
152 pop {r1} /* to avoid overwrite of r0 */
|
|
153 pop {r1}
|
|
154 pop {r2}
|
|
155 pop {r3}
|
|
156 pop {lr}
|
|
157 bx lr
|
|
158
|
|
159 .globl open
|
|
160 open:
|
|
161 push {lr}
|
|
162 push {r3}
|
|
163 push {r2}
|
|
164 push {r1}
|
|
165 push {r0}
|
|
166 mov r0, #SYS_open
|
|
167 swi #T_SYSCALL
|
|
168 pop {r1} /* to avoid overwrite of r0 */
|
|
169 pop {r1}
|
|
170 pop {r2}
|
|
171 pop {r3}
|
|
172 pop {lr}
|
|
173 bx lr
|
|
174
|
|
175 .globl mknod
|
|
176 mknod:
|
|
177 push {lr}
|
|
178 push {r3}
|
|
179 push {r2}
|
|
180 push {r1}
|
|
181 push {r0}
|
|
182 mov r0, #SYS_mknod
|
|
183 swi #T_SYSCALL
|
|
184 pop {r1} /* to avoid overwrite of r0 */
|
|
185 pop {r1}
|
|
186 pop {r2}
|
|
187 pop {r3}
|
|
188 pop {lr}
|
|
189 bx lr
|
|
190
|
|
191 .globl unlink
|
|
192 unlink:
|
|
193 push {lr}
|
|
194 push {r3}
|
|
195 push {r2}
|
|
196 push {r1}
|
|
197 push {r0}
|
|
198 mov r0, #SYS_unlink
|
|
199 swi #T_SYSCALL
|
|
200 pop {r1} /* to avoid overwrite of r0 */
|
|
201 pop {r1}
|
|
202 pop {r2}
|
|
203 pop {r3}
|
|
204 pop {lr}
|
|
205 bx lr
|
|
206
|
|
207 .globl fstat
|
|
208 fstat:
|
|
209 push {lr}
|
|
210 push {r3}
|
|
211 push {r2}
|
|
212 push {r1}
|
|
213 push {r0}
|
|
214 mov r0, #SYS_fstat
|
|
215 swi #T_SYSCALL
|
|
216 pop {r1} /* to avoid overwrite of r0 */
|
|
217 pop {r1}
|
|
218 pop {r2}
|
|
219 pop {r3}
|
|
220 pop {lr}
|
|
221 bx lr
|
|
222
|
|
223 .globl link
|
|
224 link:
|
|
225 push {lr}
|
|
226 push {r3}
|
|
227 push {r2}
|
|
228 push {r1}
|
|
229 push {r0}
|
|
230 mov r0, #SYS_link
|
|
231 swi #T_SYSCALL
|
|
232 pop {r1} /* to avoid overwrite of r0 */
|
|
233 pop {r1}
|
|
234 pop {r2}
|
|
235 pop {r3}
|
|
236 pop {lr}
|
|
237 bx lr
|
|
238
|
|
239 .globl mkdir
|
|
240 mkdir:
|
|
241 push {lr}
|
|
242 push {r3}
|
|
243 push {r2}
|
|
244 push {r1}
|
|
245 push {r0}
|
|
246 mov r0, #SYS_mkdir
|
|
247 swi #T_SYSCALL
|
|
248 pop {r1} /* to avoid overwrite of r0 */
|
|
249 pop {r1}
|
|
250 pop {r2}
|
|
251 pop {r3}
|
|
252 pop {lr}
|
|
253 bx lr
|
|
254
|
|
255 .globl chdir
|
|
256 chdir:
|
|
257 push {lr}
|
|
258 push {r3}
|
|
259 push {r2}
|
|
260 push {r1}
|
|
261 push {r0}
|
|
262 mov r0, #SYS_chdir
|
|
263 swi #T_SYSCALL
|
|
264 pop {r1} /* to avoid overwrite of r0 */
|
|
265 pop {r1}
|
|
266 pop {r2}
|
|
267 pop {r3}
|
|
268 pop {lr}
|
|
269 bx lr
|
|
270
|
|
271 .globl dup
|
|
272 dup:
|
|
273 push {lr}
|
|
274 push {r3}
|
|
275 push {r2}
|
|
276 push {r1}
|
|
277 push {r0}
|
|
278 mov r0, #SYS_dup
|
|
279 swi #T_SYSCALL
|
|
280 pop {r1} /* to avoid overwrite of r0 */
|
|
281 pop {r1}
|
|
282 pop {r2}
|
|
283 pop {r3}
|
|
284 pop {lr}
|
|
285 bx lr
|
|
286
|
|
287 .globl getpid
|
|
288 getpid:
|
|
289 push {lr}
|
|
290 push {r3}
|
|
291 push {r2}
|
|
292 push {r1}
|
|
293 push {r0}
|
|
294 mov r0, #SYS_getpid
|
|
295 swi #T_SYSCALL
|
|
296 pop {r1} /* to avoid overwrite of r0 */
|
|
297 pop {r1}
|
|
298 pop {r2}
|
|
299 pop {r3}
|
|
300 pop {lr}
|
|
301 bx lr
|
|
302
|
|
303 .globl sbrk
|
|
304 sbrk:
|
|
305 push {lr}
|
|
306 push {r3}
|
|
307 push {r2}
|
|
308 push {r1}
|
|
309 push {r0}
|
|
310 mov r0, #SYS_sbrk
|
|
311 swi #T_SYSCALL
|
|
312 pop {r1} /* to avoid overwrite of r0 */
|
|
313 pop {r1}
|
|
314 pop {r2}
|
|
315 pop {r3}
|
|
316 pop {lr}
|
|
317 bx lr
|
|
318
|
|
319 .globl sleep
|
|
320 sleep:
|
|
321 push {lr}
|
|
322 push {r3}
|
|
323 push {r2}
|
|
324 push {r1}
|
|
325 push {r0}
|
|
326 mov r0, #SYS_sleep
|
|
327 swi #T_SYSCALL
|
|
328 pop {r1} /* to avoid overwrite of r0 */
|
|
329 pop {r1}
|
|
330 pop {r2}
|
|
331 pop {r3}
|
|
332 pop {lr}
|
|
333 bx lr
|
|
334
|
|
335 .globl uptime
|
|
336 uptime:
|
|
337 push {lr}
|
|
338 push {r3}
|
|
339 push {r2}
|
|
340 push {r1}
|
|
341 push {r0}
|
|
342 mov r0, #SYS_uptime
|
|
343 swi #T_SYSCALL
|
|
344 pop {r1} /* to avoid overwrite of r0 */
|
|
345 pop {r1}
|
|
346 pop {r2}
|
|
347 pop {r3}
|
|
348 pop {lr}
|
|
349 bx lr
|
|
350
|
|
351
|
|
352 /*
|
|
353 SYSCALL(fork)
|
|
354 SYSCALL(exit)
|
|
355 SYSCALL(wait)
|
|
356 SYSCALL(pipe)
|
|
357 SYSCALL(read)
|
|
358 SYSCALL(write)
|
|
359 SYSCALL(close)
|
|
360 SYSCALL(kill)
|
|
361 SYSCALL(exec)
|
|
362 SYSCALL(open)
|
|
363 SYSCALL(mknod)
|
|
364 SYSCALL(unlink)
|
|
365 SYSCALL(fstat)
|
|
366 SYSCALL(link)
|
|
367 SYSCALL(mkdir)
|
|
368 SYSCALL(chdir)
|
|
369 SYSCALL(dup)
|
|
370 SYSCALL(getpid)
|
|
371 SYSCALL(sbrk)
|
|
372 SYSCALL(sleep)
|
|
373 SYSCALL(uptime)
|
|
374 */
|