Make it build on ELF toolchain.

This commit is contained in:
itohy 1999-11-11 08:12:50 +00:00
parent 6fc41af333
commit fcc45340da
1 changed files with 143 additions and 127 deletions

View File

@ -9,7 +9,9 @@
| |
| This file is in the public domain | This file is in the public domain
| |
| $NetBSD: start.S,v 1.1 1998/09/01 19:51:56 itohy Exp $ | $NetBSD: start.S,v 1.2 1999/11/11 08:12:50 itohy Exp $
#include <machine/asm.h>
|----------------------------------------------------------- |-----------------------------------------------------------
| |
@ -20,11 +22,15 @@
#endif #endif
#ifndef STACK_SYMBOL #ifndef STACK_SYMBOL
#ifdef __ELF__
#define STACK_SYMBOL _stack /* stack top symbol name */
#else /* a.out */
#define STACK_SYMBOL stack_8K_hUMAn6 /* has largest hash val on NetBSD ld */ #define STACK_SYMBOL stack_8K_hUMAn6 /* has largest hash val on NetBSD ld */
#endif /* and will be at the end of bss */ #endif /* and will be at the end of bss */
#endif
#ifndef DUMMY___main #ifndef DUMMY___main
#define DUMMY___main 1 /* dummy __main() */ #define DUMMY___main 1 /* define dummy __main() for a.out */
#endif #endif
#ifndef SUPPORT_R_EXEC /* support ".r" relocatable executable */ #ifndef SUPPORT_R_EXEC /* support ".r" relocatable executable */
@ -114,9 +120,13 @@
.text .text
.even .even
.globl start,_main .globl _C_LABEL(main)
start: #ifdef __ELF__
ASENTRY_NOPROFILE(_start)
#else
ASENTRY_NOPROFILE(start)
#endif
#if SUPPORT_HUPAIR #if SUPPORT_HUPAIR
.word 0x611e,0x2348,0x5550,0x4149,0x5200 .word 0x611e,0x2348,0x5550,0x4149,0x5200
#else #else
@ -133,57 +143,57 @@ start:
| check if hupair | check if hupair
| |
#if SUPPORT_HUPAIR #if SUPPORT_HUPAIR
moveal a7@+,a4 moveal %a7@+,%a4
lea a2@(-8),a6 lea %a2@(-8),%a6
moveql #7,d3 moveql #7,%d3
chkhupair: chkhupair:
cmpmb a6@+,a4@+ cmpmb %a6@+,%a4@+
dbne d3,chkhupair dbne %d3,chkhupair
| d3.l: 0xFFFF: hupair, 0x000x: not hupair | d3.l: 0xFFFF: hupair, 0x000x: not hupair
addqw #1,d3 addqw #1,%d3
beqs ishupair beqs ishupair
#endif #endif
moveql #char_tab,d3 | tab (= 9) moveql #char_tab,%d3 | tab (= 9)
ishupair: | d3.l: 0: hupair, 9: not hupair ishupair: | d3.l: 0: hupair, 9: not hupair
| |
| (over)estimate and allocate argument/environ area beforehand | (over)estimate and allocate argument/environ area beforehand
| |
addql #1,a2 | skip byte count addql #1,%a2 | skip byte count
moveql #estimated_argsz,d1 | byte counter moveql #estimated_argsz,%d1 | byte counter
moveal a2,a6 moveal %a2,%a6
moveql #char_space,d4 | space moveql #char_space,%d4 | space
acou1: addql #1,d1 acou1: addql #1,%d1
moveb a6@+,d0 moveb %a6@+,%d0
beqs acou2 beqs acou2
cmpb d4,d0 | space cmpb %d4,%d0 | space
beqs acous beqs acous
cmpb d3,d0 | tab (if not hupair) cmpb %d3,%d0 | tab (if not hupair)
bnes acou1 bnes acou1
acous: addql #4,d1 | for argv area acous: addql #4,%d1 | for argv area
bras acou1 bras acou1
acou2: acou2:
#if SUPPORT_HUPAIR && HUPAIR_ARGV0 #if SUPPORT_HUPAIR && HUPAIR_ARGV0
tstb d3 tstb %d3
bnes anohp bnes anohp
moveql #-estimated_com,d2 | reset argv[0] length moveql #-estimated_com,%d2 | reset argv[0] length
moveal a6,a4 | preserve argv[0] string address moveal %a6,%a4 | preserve argv[0] string address
acouhp: addql #1,d2 acouhp: addql #1,%d2
tstb a6@+ tstb %a6@+
bnes acouhp bnes acouhp
addl d2,d1 addl %d2,%d1
anohp: anohp:
#endif #endif
| d1: estimated argument bytes | d1: estimated argument bytes
#if NEED_ENVIRON #if NEED_ENVIRON
addql #4,a3 | skip length field addql #4,%a3 | skip length field
moveal a3,a6 moveal %a3,%a6
ecou1: addql #4,d1 ecou1: addql #4,%d1
tstb a6@+ tstb %a6@+
beqs ecoue beqs ecoue
ecou2: tstb a6@+ ecou2: tstb %a6@+
bnes ecou2 bnes ecou2
bras ecou1 bras ecou1
ecoue: ecoue:
@ -194,26 +204,26 @@ ecoue:
| free memory | free memory
| and ensure the bss/stack (for .r executable) and argument areas valid | and ensure the bss/stack (for .r executable) and argument areas valid
| |
lea a0@(pdb_mcb),a5 | a5: PDB address lea %a0@(pdb_mcb),%a5 | a5: PDB address
subl a5,d1 subl %a5,%d1
#if SUPPORT_R_EXEC #if SUPPORT_R_EXEC
#define RELOC(sym, reg) lea sym+top_pdb,reg; addl a5,reg #define RELOC(sym, reg) lea sym+top_pdb,reg; addl %a5,reg
moveal a1,a6 | end of data moveal %a1,%a6 | end of data
RELOC(_end, a1) | end of bss RELOC(_end, %a1) | end of bss
#endif #endif
pea a1@(0,d1:l) | _end + size - pdb pea %a1@(0,%d1:l) | _end + size - pdb
movel a5,a7@- movel %a5,%a7@-
DOS(__SETBLOCK) DOS(__SETBLOCK)
tstl d0 tstl %d0
bpls sbnoerr bpls sbnoerr
setblock_err: setblock_err:
movew #stderr,a7@ movew #stderr,%a7@
bsrs sberr1 | pea pc@ bsrs sberr1 | pea %pc@
.asciz "setblock failed\r\n" .asciz "setblock failed\r\n"
.even .even
sberr1: DOS(__FPUTS) sberr1: DOS(__FPUTS)
movew #exit_nomem,a7@ movew #exit_nomem,%a7@
DOS(__EXIT2) | _exit(exit_nomem) DOS(__EXIT2) | _exit(exit_nomem)
sbnoerr: sbnoerr:
@ -223,15 +233,15 @@ sbnoerr:
| |
| set stack | set stack
| |
moveal #STACK_SYMBOL+STACK_SIZE,a7 moveal #STACK_SYMBOL+STACK_SIZE,%a7
#if SUPPORT_R_EXEC #if SUPPORT_R_EXEC
| |
| clear bss section | clear bss section
| |
loop_clrbss: loop_clrbss:
clrl a6@+ clrl %a6@+
cmpal a1,a6 cmpal %a1,%a6
bcss loop_clrbss bcss loop_clrbss
#endif #endif
@ -240,10 +250,10 @@ loop_clrbss:
| |
#if NEED_MEMCP #if NEED_MEMCP
# if SUPPORT_R_EXEC # if SUPPORT_R_EXEC
RELOC(__memcp, a6) RELOC(_C_LABEL(_memcp), %a6)
movel a0,a6@ movel %a0,%a6@
# else # else
movel a0,__memcp movel %a0,_C_LABEL(_memcp)
# endif # endif
#endif #endif
@ -252,10 +262,10 @@ loop_clrbss:
| |
#if NEED_PROCP #if NEED_PROCP
# if SUPPORT_R_EXEC # if SUPPORT_R_EXEC
RELOC(__procp, a6) RELOC(_C_LABEL(_procp), %a6)
movel a5,a6@ movel %a5,%a6@
# else # else
movel a5,__procp movel %a5,_C_LABEL(_procp)
# endif # endif
#endif #endif
@ -265,145 +275,145 @@ loop_clrbss:
#if NEED_VERNUM #if NEED_VERNUM
DOS(__VERNUM) DOS(__VERNUM)
# if SUPPORT_R_EXEC # if SUPPORT_R_EXEC
RELOC(__vernum, a6) RELOC(_C_LABEL(_vernum), %a6)
movel d0,a6@ movel %d0,%a6@
# else # else
movel d0,__vernum movel %d0,_C_LABEL(_vernum)
# endif # endif
#endif #endif
| |
| create argv[0] | create argv[0]
| |
moveal a1,a0 | top of argument strings moveal %a1,%a0 | top of argument strings
#if SUPPORT_HUPAIR && HUPAIR_ARGV0 #if SUPPORT_HUPAIR && HUPAIR_ARGV0
tstb d3 tstb %d3
beqs arg0lp beqs arg0lp
#endif #endif
#if ADD_PATHNAME #if ADD_PATHNAME
lea a5@(drvpath_pdb),a4 | drive and path name lea %a5@(drvpath_pdb),%a4 | drive and path name
arg0path: arg0path:
moveb a4@+,a1@+ moveb %a4@+,%a1@+
bnes arg0path bnes arg0path
subql #1,a1 | remove nul char subql #1,%a1 | remove nul char
#endif #endif
lea a5@(command_pdb),a4 | command name lea %a5@(command_pdb),%a4 | command name
arg0lp: moveb a4@+,a1@+ arg0lp: moveb %a4@+,%a1@+
bnes arg0lp bnes arg0lp
#if NEED_PROGNAME #if NEED_PROGNAME
| |
| find program basename | find program basename
| |
moveal a1,a4 moveal %a1,%a4
prognlp: prognlp:
cmpal a0,a4 cmpal %a0,%a4
beqs prognexit beqs prognexit
moveb a4@-,d0 moveb %a4@-,%d0
cmpib #char_slash,d0 cmpib #char_slash,%d0
beqs prognfou beqs prognfou
cmpib #char_backslash,d0 cmpib #char_backslash,%d0
bnes prognlp bnes prognlp
prognfou: prognfou:
addql #1,a4 | next of slash addql #1,%a4 | next of slash
prognexit: prognexit:
# if SUPPORT_R_EXEC # if SUPPORT_R_EXEC
RELOC(___progname, a6) RELOC(_C_LABEL(__progname), %a6)
movel a4,a6@ movel %a4,%a6@
# else # else
movel a4,___progname movel %a4,_C_LABEL(__progname)
# endif # endif
#endif #endif
| |
| create argument strings | create argument strings
| |
moveql #1,d0 | (d0:l) # arg moveql #1,%d0 | (d0:l) # arg
spskip: moveb a2@+,d2 spskip: moveb %a2@+,%d2
beqs comline_end beqs comline_end
cmpb d4,d2 | space cmpb %d4,%d2 | space
beqs spskip beqs spskip
cmpb d3,d2 | tab (if not hupair) cmpb %d3,%d2 | tab (if not hupair)
beqs spskip beqs spskip
| create an arg | create an arg
clrb d1 | no quote here clrb %d1 | no quote here
addql #1,d0 | increment argc addql #1,%d0 | increment argc
arglp: tstb d1 arglp: tstb %d1
bnes in_quote bnes in_quote
cmpib #char_dquote,d2 cmpib #char_dquote,%d2
beqs quote beqs quote
cmpib #char_squote,d2 cmpib #char_squote,%d2
bnes notquote bnes notquote
quote: moveb d2,d1 | save quote character quote: moveb %d2,%d1 | save quote character
bras argnextc bras argnextc
in_quote: in_quote:
cmpb d1,d2 cmpb %d1,%d2
bnes argcopyc bnes argcopyc
clrb d1 | quote ended clrb %d1 | quote ended
bras argnextc bras argnextc
notquote: notquote:
cmpb d4,d2 | space cmpb %d4,%d2 | space
beqs arg_end beqs arg_end
cmpb d3,d2 | tab (if not hupair) cmpb %d3,%d2 | tab (if not hupair)
bnes argcopyc bnes argcopyc
arg_end: arg_end:
clrb a1@+ clrb %a1@+
bras spskip bras spskip
argcopyc: argcopyc:
moveb d2,a1@+ | copy char moveb %d2,%a1@+ | copy char
argnextc: argnextc:
moveb a2@+,d2 moveb %a2@+,%d2
bnes arglp bnes arglp
clrb a1@+ clrb %a1@+
comline_end: comline_end:
| |
| create argv vector | create argv vector
| |
addql #3,a1 addql #3,%a1
movel a1,d1 movel %a1,%d1
andib #0xfc,d1 | long alignment andib #0xfc,%d1 | long alignment
moveal d1,a1 | argv moveal %d1,%a1 | argv
movel d0,d4 | argc movel %d0,%d4 | argc
| a0 is at argument strings | a0 is at argument strings
mkargv: mkargv:
movel a0,a1@+ | argv[0] ... movel %a0,%a1@+ | argv[0] ...
nxtarg: tstb a0@+ nxtarg: tstb %a0@+
bnes nxtarg bnes nxtarg
#if STRICT_SETBLOCK #if STRICT_SETBLOCK
subqw #1,d0 subqw #1,%d0
#else #else
subqw #1,d4 subqw #1,%d4
#endif #endif
bnes mkargv bnes mkargv
clrl a1@+ | argv[argc] should be NULL clrl %a1@+ | argv[argc] should be NULL
| |
| create envp vector | create envp vector
| |
#if NEED_ENVIRON #if NEED_ENVIRON
movel a1,d2 movel %a1,%d2
envlp: tstb a3@ envlp: tstb %a3@
beqs envend beqs envend
movel a3,a1@+ movel %a3,%a1@+
envskp: tstb a3@+ envskp: tstb %a3@+
bnes envskp bnes envskp
bras envlp bras envlp
envend: clrl a1@+ | NULL termination envend: clrl %a1@+ | NULL termination
# if SUPPORT_R_EXEC # if SUPPORT_R_EXEC
RELOC(_environ, a0) RELOC(_C_LABEL(environ), %a0)
movel d2,a0@ movel %d2,%a0@
# else # else
movel d2,_environ movel %d2,_C_LABEL(environ)
# endif # endif
#endif #endif
@ -411,42 +421,41 @@ envend: clrl a1@+ | NULL termination
| free unused memory | free unused memory
| |
#if STRICT_SETBLOCK #if STRICT_SETBLOCK
subal a5,a1 subal %a5,%a1
movel a1,a7@- movel %a1,%a7@-
movel a5,a7@- movel %a5,%a7@-
DOS(__SETBLOCK) | reset donburi-kanjo (never fails) DOS(__SETBLOCK) | reset donburi-kanjo (never fails)
addql #8,a7 addql #8,%a7
movel d4,d0 | argc movel %d4,%d0 | argc
#endif #endif
| |
| make parameter | make parameter
| |
#if NEED_ENVIRON #if NEED_ENVIRON
movel d2,a7@- | arg #3 --- envp movel %d2,%a7@- | arg #3 --- envp
#endif #endif
#if !C_REGPARM #if !C_REGPARM
movel d1,a7@- | arg #2 --- argv movel %d1,%a7@- | arg #2 --- argv
movel d0,a7@- | arg #1 --- argc movel %d0,%a7@- | arg #1 --- argc
#endif #endif
#if SUPPORT_R_EXEC #if SUPPORT_R_EXEC
RELOC(_main, a0) RELOC(_C_LABEL(main), %a0)
jsr a0@ jsr %a0@
#else #else
jsr _main jsr _C_LABEL(main)
#endif #endif
#if !C_REGPARM || NEED_ENVIRON #if !C_REGPARM || NEED_ENVIRON
movew d0,a7@ movew %d0,%a7@
#else #else
movew d0,a7@- movew %d0,%a7@-
#endif #endif
DOS(__EXIT2) DOS(__EXIT2)
#if DUMMY___main #if !defined(__ELF__) && DUMMY___main
.globl ___main ENTRY_NOPROFILE(__main)
___main:
rts rts
#endif #endif
@ -455,27 +464,34 @@ ___main:
| variables | variables
| |
#if NEED_MEMCP #if NEED_MEMCP
.comm __memcp,4 .comm _C_LABEL(_memcp),4
#endif #endif
#if NEED_PROCP #if NEED_PROCP
.comm __procp,4 | PDB address .comm _C_LABEL(_procp),4 | PDB address
#endif #endif
#if NEED_VERNUM #if NEED_VERNUM
.comm __vernum,4 .comm _C_LABEL(_vernum),4
#endif #endif
#if NEED_PROGNAME #if NEED_PROGNAME
.comm ___progname,4 .comm _C_LABEL(__progname),4
#endif #endif
#if NEED_ENVIRON #if NEED_ENVIRON
.comm _environ,4 | environ address .comm _C_LABEL(environ),4 | environ address
#endif #endif
|----------------------------------------------------------- |-----------------------------------------------------------
| |
| stack | stack
| |
#ifdef __ELF__
.section .stack,"aw",@nobits
.align 4
STACK_SYMBOL:
.space STACK_SIZE
#else
.comm STACK_SYMBOL,STACK_SIZE .comm STACK_SYMBOL,STACK_SIZE
#endif