Path: blob/master/user/lib/libc/arch/mips/syscalls-mips.S
736 views
/*1* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 20092* The President and Fellows of Harvard College.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12* 3. Neither the name of the University nor the names of its contributors13* may be used to endorse or promote products derived from this software14* without specific prior written permission.15*16* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND17* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE18* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE19* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE20* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL21* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS22* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)23* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT24* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY25* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF26* SUCH DAMAGE.27*/2829/*30* This file is copied to syscalls.S, and then the actual syscalls are31* appended as lines of the form32* SYSCALL(symbol, number)33*34* Warning: gccs before 3.0 run cpp in -traditional mode on .S files.35* So if you use an older gcc you'll need to change the token pasting36* in SYSCALL().37*/3839#include <kern/syscall.h>40#include <machine/regdefs.h>4142/*43* Definition for each syscall.44* All we do is load the syscall number into v0, the register the45* kernel expects to find it in, and jump to the shared syscall code.46* (Note that the addiu instruction is in the jump's delay slot.)47*/48#define SYSCALL(sym, num) \49.set noreorder ; \50.globl sym ; \51.type sym,@function ; \52.ent sym ; \53sym: ; \54j __syscall ; \55addiu v0, $0, SYS_##sym ; \56.end sym ; \57.set reorder5859/*60* Now, the shared system call code.61* The MIPS syscall ABI is as follows:62*63* On entry, call number in v0. The rest is like a normal function64* call: four args in a0-a3, the other args on the stack.65*66* On successful return, zero in a3 register; return value in v067* (v0 and v1 for a 64-bit return value).68*69* On error return, nonzero in a3 register; errno value in v0.70*71* The use of a3 as a return register to hold the success flag is72* gross, but I didn't make it up.73*74* Note that by longstanding Unix convention and POSIX decree, errno75* is not to be set unless the call actually fails.76*/7778.set noreorder79.text80.type __syscall,@function81.ent __syscall82__syscall:83syscall /* make system call */84beq a3, $0, 1f /* if a3 is zero, call succeeded */85nop /* delay slot */86sw v0, errno /* call failed: store errno */87li v1, -1 /* and force return value to -1 */88li v0, -1891:90j ra /* return */91nop /* delay slot */92.end __syscall93.set reorder94959697