1/* 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Ralph Campbell. 7 * 8 * %sccs.include.redist.c% 9 * 10 * @(#)crt0.s 8.2 (Berkeley) 03/21/94 11 */ 12 13#include <machine/regdef.h> 14#include <machine/machAsmDefs.h> 15 16 .comm environ, 4 17 .data 18 .align 2 19 .globl __progname 20__progname: 21 .word $L1 22$L1: 23 .word 0 # null string plus padding 24 .text 25 26NON_LEAF(start, 24, ra) 27 .set noreorder 28 lw s0, 0(sp) # get argc from stack 29 addu s1, sp, 4 # get pointer to argv 30 addu s2, s1, 4 # skip null pointer on stack 31 sll v0, s0, 2 # add number of argv pointers 32 addu s2, s2, v0 # final pointer to environment list 33 sw s2, environ # save environment pointer 34 subu sp, sp, 24 # allocate standard frame 35 .mask 0x80000000, -4 36 sw zero, 20(sp) # clear return address for debugging 37#ifdef MCRT0 38eprol: 39 la a0, eprol 40 la a1, etext 41 jal monstartup # monstartup(eprol, etext); 42 nop 43 la a0, _mcleanup 44 jal atexit # atext(_mcleanup); 45 nop 46 sw zero, errno 47#endif 48 lw a0, 0(s1) # a0 = argv[0]; 49 nop 50 beq a0, zero, 2f # skip if a0 == NULL 51 move s3, a0 # save argv[0] 52 jal strrchr 53 li a1, 0x2f # a1 = '/' 54 bne v0, zero, 1f # if slash found 55 addu v0, v0, 1 56 move v0, s3 # v0 = argv[0]; 571: 58 sw v0, __progname 592: 60 move a0, s0 61 move a1, s1 62 jal main # v0 = main(argc, argv, env); 63 move a2, s2 64 jal exit # exit(v0); 65 move a0, v0 66 break 0 67 .set reorder 68END(start) 69 70#ifndef MCRT0 71LEAF(moncontrol) 72 j ra 73END(moncontrol) 74 75LEAF(_mcount) 76 .set noreorder 77 .set noat 78 addu sp, sp, 8 # undo push 79 j ra 80 move ra, AT 81 .set at 82 .set reorder 83END(_mcount) 84#endif 85