/* [<][>][^][v][top][bottom][index][help] */
1 /*
2 * Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
3 * The President and Fellows of Harvard College.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30 /*
31 * This file is copied to syscalls.S, and then the actual syscalls are
32 * appended as lines of the form
33 * SYSCALL(symbol, number)
34 *
35 * Warning: gccs before 3.0 run cpp in -traditional mode on .S files.
36 * So if you use an older gcc you'll need to change the token pasting
37 * in SYSCALL().
38 */
39
40 #include <kern/syscall.h>
41 #include <machine/regdefs.h>
42
43 /*
44 * Definition for each syscall.
45 * All we do is load the syscall number into v0, the register the
46 * kernel expects to find it in, and jump to the shared syscall code.
47 * (Note that the addiu instruction is in the jump's delay slot.)
48 */
49 #define SYSCALL(sym, num) \
50 .set noreorder ; \
51 .globl sym ; \
52 .type sym,@function ; \
53 .ent sym ; \
54 sym: ; \
55 j __syscall ; \
56 addiu v0, $0, SYS_##sym ; \
57 .end sym ; \
58 .set reorder
59
60 /*
61 * Now, the shared system call code.
62 * The MIPS syscall ABI is as follows:
63 *
64 * On entry, call number in v0. The rest is like a normal function
65 * call: four args in a0-a3, the other args on the stack.
66 *
67 * On successful return, zero in a3 register; return value in v0
68 * (v0 and v1 for a 64-bit return value).
69 *
70 * On error return, nonzero in a3 register; errno value in v0.
71 *
72 * The use of a3 as a return register to hold the success flag is
73 * gross, but I didn't make it up.
74 *
75 * Note that by longstanding Unix convention and POSIX decree, errno
76 * is not to be set unless the call actually fails.
77 */
78
79 .set noreorder
80 .text
81 .type __syscall,@function
82 .ent __syscall
83 __syscall:
84 syscall /* make system call */
85 beq a3, $0, 1f /* if a3 is zero, call succeeded */
86 nop /* delay slot */
87 sw v0, errno /* call failed: store errno */
88 li v1, -1 /* and force return value to -1 */
89 li v0, -1
90 1:
91 j ra /* return */
92 nop /* delay slot */
93 .end __syscall
94 .set reorder
95