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