1: /*
   2:  * Copyright (c) 1987 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  */
   6: 
   7: #ifdef LIBC_SCCS
   8:         <@(#)crt0.s	2.4 (2.11BSD GTE) 2/02/95\0>
   9:         .even
  10: #endif LIBC_SCCS
  11: 
  12: /*
  13:  * C runtime startoff.  When an a.out is loaded by the kernel, the kernel
  14:  * sets up the stack as follows:
  15:  *
  16:  *	_________________________________
  17:  *	| (NULL)			| 0177776: top of memory
  18:  *	|-------------------------------|
  19:  *	| 				|
  20:  *	| environment strings		|
  21:  *	| 				|
  22:  *	|-------------------------------|
  23:  *	| 				|
  24:  *	| argument strings		|
  25:  *	| 				|
  26:  *	|-------------------------------|
  27:  *	| envv[envc] (NULL)		| end of environment vector tag, a 0
  28:  *	|-------------------------------|
  29:  *	| envv[envc-1]			| pointer to last environment string
  30:  *	|-------------------------------|
  31:  *	| ...				|
  32:  *	|-------------------------------|
  33:  *	| envv[0]			| pointer to first environment string
  34:  *	|-------------------------------|
  35:  *	| argv[argc] (NULL)		| end of argument vector tag, a 0
  36:  *	|-------------------------------|
  37:  *	| argv[argc-1]			| pointer to last argument string
  38:  *	|-------------------------------|
  39:  *	| ...				|
  40:  *	|-------------------------------|
  41:  *	| argv[0]			| pointer to first argument string
  42:  *	|-------------------------------|
  43:  * sp->	| argc				| number of arguments
  44:  *	---------------------------------
  45:  *
  46:  * Crt0 simply moves the argc down two places in the stack, calculates the
  47:  * the addresses of argv[0] and envv[0], putting those values into the two
  48:  * spaces opened up to set the stack up as main expects to see it.
  49:  */
  50: 
  51: 
  52: .bss
  53: .globl  _environ                / copy of envv vector pointer for getenv and
  54: _environ: .=.+2                 /   others
  55: .text
  56: 
  57: /*
  58:  * Paragraph below retained for historical purposes.
  59:  *
  60:  * The following zero has a number of purposes - it serves as a null terminated
  61:  * string for uninitialized string pointers on separate I&D machines for
  62:  * instance.  But we never would have put it here for that reason; programs
  63:  * which use uninitialized pointer *should* die.  The real reason it's here is
  64:  * so you can declare "char blah[] = "foobar" at the start of a C program
  65:  * and not have printf generate "(null)" when you try to print it because
  66:  * blah is at address zero on separate I&D machines ...  sick, sick, sick ...
  67:  *
  68:  * In porting bits and pieces of the 4.4-Lite C library the global program
  69:  * name location '___progname' was needed.  Rather than take up another two
  70:  * bytes of D space the 0th location was used.   The '(null)' string was
  71:  * removed from doprnt.s so now when programs use uninitialized pointers
  72:  * they will be rewarded with argv[0].  This is no sicker than before and
  73:  * may cause bad programs to die sooner.
  74: */
  75:         .data
  76:         .globl  ___progname, _strrchr
  77: 
  78: ___progname: 0
  79:         .text
  80: 
  81: .globl  _exit, _main
  82: 
  83: 
  84: .globl  start
  85: start:
  86:         setd                    / set double precision
  87:         sub     $4,sp           / make room for argv and env pointers
  88:         mov     sp,r0
  89:         mov     4(sp),(r0)+     / copy argc down
  90:         mov     sp,(r0)         / calculate position of arg pointers
  91:         add     $6,(r0)
  92:         mov     *(r0),___progname
  93:         mov     (r0)+,(r0)      / calculate position of env pointers
  94:         add     (sp),(r0)
  95:         add     (sp),(r0)
  96:         add     $2,(r0)
  97:         mov     (r0),_environ   / environ = &envv[0]
  98: 
  99: #ifdef NONFP
 100: .globl  setfpt                  / if non floating point version of the
 101:                                 /   library, set up floating point simulator
 102:         jsr     pc,setfpt       /   trap - see ../fpsim/README for uglyness
 103: #endif
 104: 
 105: #ifdef MCRT0
 106: .globl  _etext, _monstartup
 107: 
 108:         mov     $_etext,-(sp)   / monstartup(2, &_etext)
 109:         mov     $eprol,-(sp)
 110:         jsr     pc,_monstartup
 111:         cmp     (sp)+,(sp)+
 112: #endif MCRT0
 113: 
 114:         clr     r5              / for adb and longjmp/rollback ...
 115:         mov     $'/,-(sp)
 116:         mov     ___progname,-(sp)
 117:         jsr     pc,_strrchr
 118:         tst     r0
 119:         beq     1f
 120:         inc     r0
 121:         mov     r0,___progname
 122: 1:
 123:         cmp     (sp)+,(sp)+
 124:         jsr     pc,_main        / call main
 125:         mov     r0,(sp)         /   and pass main's return value to _exit ...
 126:         jsr     pc,*$_exit
 127: 
 128: 
 129: #ifdef MCRT0
 130: .globl  _monitor, __cleanup, __exit
 131: 
 132: _exit:                          / catch call to exit
 133:         clr     -(sp)           / monitor(0) - write profiling information out
 134:         jsr     pc,_monitor
 135:         jsr     pc,__cleanup    / the real exit calls _cleanup so we do too
 136:         cmp     (sp)+,(sp)+     / toss monitor's parameter and our return
 137:         jsr     pc,__exit       /   address leaving the exit code and exit
 138: eprol:                          / start of default histogram recording
 139: 
 140: #else !MCRT0
 141: 
 142: /*
 143:  * null mcount and moncontrol,
 144:  * just in case some routine is compiled for profiling
 145:  */
 146: .globl  mcount, _moncontrol
 147: mcount:
 148: _moncontrol:
 149:         rts     pc              / do nothing
 150: 
 151: #endif MCRT0

Defined functions

_exit declared in line 81; defined in line 132; used 3285 times
_moncontrol declared in line 146; defined in line 148; used 5 times
eprol defined in line 138; used 1 times
mcount declared in line 146; defined in line 147; used 1 times
start declared in line 84; defined in line 85; used 1 times
  • in line 84

Defined variables

Last modified: 1995-02-03
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 5431
Valid CSS Valid XHTML 1.0 Strict