/*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* crt0.o for MIPS r2000/r3000.31*32* crt stands for "C runtime".33*34* Basically, this is the startup code that gets invoked before main(),35* and regains control when main returns.36*37* All we really do is save a copy of argv for use by the err* and warn*38* functions, and call exit when main returns.39*/4041#include <kern/mips/regdefs.h>42#include <kern/syscall.h>4344.set noreorder /* so we can use delay slots explicitly */4546.text47.globl __start48.type __start,@function49.ent __start50__start:51/* Load the "global pointer" register */52la gp, _gp5354/*55* We expect that the kernel passes argc in a0 and argv in a1.56* We do not expect the kernel to set up a complete stack frame,57* however.58*59* The MIPS ABI decrees that every caller will leave 16 bytes of60* space in the bottom of its stack frame for writing back the61* values of a0-a3, even when calling functions that take fewer62* than four arguments. It also requires the stack to be aligned63* to an 8-byte boundary. (This is because of 64-bit MIPS, which64* we're not dealing with... but we'll conform to the standard.)65*/66li t0, 0xfffffff8 /* mask for stack alignment */67and sp, sp, t0 /* align the stack */68addiu sp, sp, -16 /* create our frame */6970sw a1, __argv /* save second arg (argv) in __argv for use later */7172jal main /* call main */73nop /* delay slot */7475/*76* Now, we have the return value of main in v0.77*78* Move it to s0 (which is callee-save) so we still have79* it in case exit() returns.80*81* Also move it to a0 so it's the argument to exit.82*/83move s0, v0 /* save return value */84jal exit /* call exit() */85move a0, s0 /* Set argument (in delay slot) */8687/*88* If we got here, something is broken in exit().89* Try using _exit().90*/91jal _exit /* Try _exit() */92move a0, s0 /* Set argument (in delay slot) */9394/*95* If *that* doesn't work, try doing an _exit syscall by hand.96*/971:98move a0, s099li v0, SYS__exit100syscall101102/*103* ...and if we still can't exit, there's not much we can do104* but keep trying.105*/106j 1b /* loop back */107nop /* delay slot */108.end __start109110111