152961Sralph/* 260980Sbostic * Copyright (c) 1991, 1993 360980Sbostic * The Regents of the University of California. All rights reserved. 452961Sralph * 552961Sralph * This code is derived from software contributed to Berkeley by 652961Sralph * Ralph Campbell. 752961Sralph * 855741Sralph * %sccs.include.redist.c% 952961Sralph * 10*66413Sbostic * @(#)crt0.s 8.2 (Berkeley) 03/21/94 1152961Sralph */ 1252887Sbostic 1352887Sbostic#include <machine/regdef.h> 1455741Sralph#include <machine/machAsmDefs.h> 1552887Sbostic 1652887Sbostic .comm environ, 4 1758101Sralph .data 1858101Sralph .align 2 1958101Sralph .globl __progname 2058101Sralph__progname: 2158101Sralph .word $L1 2258101Sralph$L1: 2358101Sralph .word 0 # null string plus padding 2458101Sralph .text 2552887Sbostic 2658278SralphNON_LEAF(start, 24, ra) 2758101Sralph .set noreorder 2858101Sralph lw s0, 0(sp) # get argc from stack 2958101Sralph addu s1, sp, 4 # get pointer to argv 3058101Sralph addu s2, s1, 4 # skip null pointer on stack 3158101Sralph sll v0, s0, 2 # add number of argv pointers 3258101Sralph addu s2, s2, v0 # final pointer to environment list 3358101Sralph sw s2, environ # save environment pointer 3452887Sbostic subu sp, sp, 24 # allocate standard frame 3552887Sbostic .mask 0x80000000, -4 3652887Sbostic sw zero, 20(sp) # clear return address for debugging 3758101Sralph#ifdef MCRT0 3858101Sralpheprol: 3958101Sralph la a0, eprol 4058101Sralph la a1, etext 4158101Sralph jal monstartup # monstartup(eprol, etext); 4258101Sralph nop 4358278Sralph la a0, _mcleanup 4458278Sralph jal atexit # atext(_mcleanup); 4558101Sralph nop 4658101Sralph sw zero, errno 4758101Sralph#endif 4858101Sralph lw a0, 0(s1) # a0 = argv[0]; 4958101Sralph nop 5058101Sralph beq a0, zero, 2f # skip if a0 == NULL 5158101Sralph move s3, a0 # save argv[0] 5258101Sralph jal strrchr 5358101Sralph li a1, 0x2f # a1 = '/' 5458101Sralph bne v0, zero, 1f # if slash found 5558101Sralph addu v0, v0, 1 5658101Sralph move v0, s3 # v0 = argv[0]; 5758101Sralph1: 5858101Sralph sw v0, __progname 5958101Sralph2: 6058101Sralph move a0, s0 6158101Sralph move a1, s1 6252887Sbostic jal main # v0 = main(argc, argv, env); 6358101Sralph move a2, s2 6458101Sralph jal exit # exit(v0); 6552887Sbostic move a0, v0 6652887Sbostic break 0 6758101Sralph .set reorder 6858278SralphEND(start) 6952887Sbostic 7058101Sralph#ifndef MCRT0 7152887SbosticLEAF(moncontrol) 7252887Sbostic j ra 7352887SbosticEND(moncontrol) 7452887Sbostic 7552887SbosticLEAF(_mcount) 7658101Sralph .set noreorder 7758123Sralph .set noat 7858123Sralph addu sp, sp, 8 # undo push 7952887Sbostic j ra 8058123Sralph move ra, AT 8158123Sralph .set at 8258101Sralph .set reorder 8352887SbosticEND(_mcount) 8458101Sralph#endif 85