#
# Buildfile for V I/O protocol boot
#
# NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
#
# Do you know what you're doing ? Are you sure that you know what you're
# doing ? This set of programs operates under a very special set of
# constraints and normal rules of programming do not always apply.
# Though kludgey in appearence Vload is at the very heart of the V-system
# and THERE IS ONLY ONE VLOAD. V and xV boot using a single version of
# this program. Installing a broken Vload makes it impossible for anybody
# to boot anything including netwatch. This makes for a very difficult 
# debugging chore.
#
# If you're not sure that you know what you're doing don't be ashamed
# to ask somebody who does.
# 
# NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
#
# Warning: Vload must run in a very limited amount of memory. After you
#  make any changes, note the output of the "size68 -h" that the buildfile
#  runs on Vload*.r. For Vload10, if the sum of the first two hex
#  numbers (code + initialized data) is more than 0x1C00 it will NOT work.
#  Vload50 can go up to 0x1E00.  These restrictions are imposed by the Sun
#  Network Disk (ND) boot protocol; versions of Vload that will not be booted
#  by ND are allowed to be larger.  Sun-1's on the 3Mb experimental network,
#  Sun-3's (except ones with pre-release ROMs), and the machine we use for
#  netwatching (3Mb and Excelan interfaces) all use EFTP or TFTP and hence
#  can support larger Vloads.
# There is also a limit on the total size, which is imposed by the load
#  origin specified with the -T option in the final ld68 step. The load
#  origin plus the total size must not go beyond the end of mapped memory.
#  The load origin also must not be so low that it runs into the team or
#  kernel being loaded.  Thus, the Sun-1 versions of Vload (called
#  "Vload" and "xlnVload") cannot have total size larger than 
#  0x20000 - 0x1d000 = 0x3000.  The total size is the last number printed
#  out by the "size68 -h" command.
#
# Further warning: Vload*.b must be the first module name passed to ld68,
#   so that the symbol "entry" labels the first instruction in the program.
#
# Tim Mann, March 22, 1984
#
# Nasty comments added by Lance Berc because he had to work on Vload
# for a month once after various people had randomized it to the point
# where no versions would compile or link. 8/85 - 12/85

# Support for the CMC ENP-30 board has been removed from the buildfile - lance

#include ../../../buildprefix

VPATH= . ../mi
.SUFFIXES:
.SUFFIXES: .b .c

V=../../..
MI=../mi
INCL= -I. -I$(MI) -I$(V)/libc/include/m68k -I$(V)/libc/include/mi

C68FLAGS= -O -vV $(INCL)

.c.b:
	cc68 $(C68FLAGS) -c $*.c

#ifdef X
LINK= ld68 -vx
#else
LINK= ld68 -vV
#endif

# Sun-1 board w/sun 3meg ethernet interface
ALL3= Vload V VV xVload xV xVV 1.Boot

# Sun-2 / 3com
ALL10= Vload10.d Vload10.boot

# Sun-1 / Excelan
ALL10XLN= xlnVload xlnV xlnVV xlnxVload xlnxV xlnxVV

# Sun-2/50 (Intel 82586)
ALL50= Vload50.d

# Sun-3 (Intel 82586)
ALL3IE= Vload3+ie.d

ALL= $(ALL3) $(ALL10) $(ALL10XLN) $(ALL50) $(ALL3IE)

C68FLAGS3=    $(C68FLAGS)           -DENET3MEG  -DLOTS_OF_ROOM
C68FLAGS10XLN=$(C68FLAGS)           -DENET10MEG -DLOTS_OF_ROOM -DEXCELAN
C68FLAGS3IE=  $(C68FLAGS) -DMC68010 -DENET10MEG -DLOTS_OF_ROOM -DSUN3
C68FLAGS10=   $(C68FLAGS) -DMC68010 -DENET10MEG -DNDBOOT       -DTHREECOM
C68FLAGS50=   $(C68FLAGS) -DMC68010 -DENET10MEG -DNDBOOT       -DSUN50

SUN1LIBS= -lVsaconsole -lsun1rawio
SUN2LIBS= -lVsaconsole -lsun2rawio
SUN3LIBS= -lVsaconsole -lsun3rawio

OBJECTS= open.b close.b read.b qwconfig.b load.b ikc.b misc.b

OBJECTS3=     Vload3.b    enet3.b        getvalue.b    $(OBJECTS)
OBJECTS10XLN= Vload10x.b  enet10x.b      getvalue.b    $(OBJECTS)
OBJECTS3IE=   Vload3+ie.b enetie.b fc3.b getvalue.b    $(OBJECTS)
OBJECTS10=    Vload10.b   enet3com.b     getvalue.nd.b $(OBJECTS)
OBJECTS50=    Vload50.b   enet50.b fc3.b getvalue.nd.b $(OBJECTS)

all: $(ALL)

# special stripped version of get value - used with ndboot versions.
getvalue.nd.b: $(MI)/getvalue.c
	cc68 $(C68FLAGS) -DNDBOOT -c $(MI)/getvalue.c -o getvalue.nd.b

# 3Mbit version
# Update the downloadable image (byte-reversed),
#   changing the entry point to 1000
#  .68 is the default extension for rev68

Vload3.b: $(MI)/Vload.c
	cc68 $(C68FLAGS3) -c $(MI)/Vload.c -o Vload3.b
enet3.b: enet3.c 
	cc68 $(C68FLAGS3) -c enet3.c

Vload: Vload.68 addr1000
	sh -c "dd bs=28 count=1 < Vload.68 > FOO.68"
	cat addr1000 >> FOO.68
	sh -c "dd bs=32 skip=1 < Vload.68 >> FOO.68"
	rev68 FOO Vload
	rm -f FOO.68
	size68 -h Vload

# Update the unreversed version
Vload.68: $(OBJECTS3) 
	$(LINK) -e entry -o Vload.68 -s -T 1d000 $(OBJECTS3) $(SUN1LIBS)

Vload.sym: $(OBJECTS3) 
	$(LINK) -e entry -o foo -X -T 1d000 $(OBJECTS3) $(SUN1LIBS)
	nm68 -n -h foo | grep -v " a " > Vload.sym
	rm foo

V: Vload
	cp Vload V
VV: Vload
	cp Vload VV

xVload: Vload
	cp Vload xVload
xV: xVload
	cp xVload xV
xVV: xVload
	cp xVload xVV

1.Boot: Vload
	cp Vload 1.Boot

# 10Mbit version (MC68020 with Intel 82586 chip as found in Sun-3/75)
#  .r is byte-reversed, with Sun-style b.out header.
#  .d has the b.out header stripped.
#  .boot has the SMI-Unix style a.out header, with entry point 4000.
# fc3.b is made with the Sun 50 stuff.

enetie.b: enetie.c i82586.h
	cc68 $(C68FLAGS3IE) -c enetie.c
Vload3+ie.b: $(MI)/Vload.c
	cc68 $(C68FLAGS3IE) -DXV -c $(MI)/Vload.c -o Vload3+ie.b

Vload3+ie.68: $(OBJECTS3IE) 
	$(LINK) -e entry -o Vload3+ie.68 -s -T b8000 $(OBJECTS3IE) $(SUN3LIBS)

Vload3+ie.r: Vload3+ie.68
	rev68 Vload3+ie Vload3+ie.r
	size68 -h Vload3+ie.r

Vload3+ie.d: Vload3+ie.r
	sh -c "dd bs=32 skip=1 < Vload3+ie.r > Vload3+ie.d"

Vload3+ie.boot: Vload3+ie.r addr4000
	sh -c "dd bs=4 count=5 < Vload3+ie.r > Vload3+ie.boot"
	cat addr4000 >> Vload3+ie.boot
	sh -c "dd bs=4 skip=5 count=2 < Vload3+ie.r >> Vload3+ie.boot"
	sh -c "dd bs=32 skip=1 < Vload3+ie.r >> Vload3+ie.boot"

Vload3+ie.sym: Vload3+ie.d
	$(LINK) -e entry -o foo -X -T b8000 $(OBJECTS3IE) $(SUN3LIBS)
	nm68 -n -h foo | grep -v " a " > Vload3+ie.sym
	rm foo

# 10Mbit version (MC68010 with Intel 82586 chip as found in Sun 50)
#  .r is byte-reversed, with Sun-style b.out header.
#  .d has the b.out header stripped.
#  .boot has the SMI-Unix style a.out header, with entry point 4000.

enet50.b: enet50.c enet50.h
	cc68 $(C68FLAGS50) -c enet50.c
fc3.b: fc3.c
	cc68 $(C68FLAGS50) -c fc3.c
Vload50.b: $(MI)/Vload.c
	cc68 $(C68FLAGS50) -DXV -c $(MI)/Vload.c -o Vload50.b

Vload50.68: $(OBJECTS50) 
	$(LINK) -e entry -o Vload50.68 -s -T b8000 $(OBJECTS50) $(SUN2LIBS)
	rm -f Vload50.sym

Vload50.r: Vload50.68
	rev68 Vload50 Vload50.r
	size68 -h Vload50.r

Vload50.d: Vload50.r
	sh -c "dd bs=32 skip=1 < Vload50.r > Vload50.d"

Vload50.boot: Vload50.r addr4000
	sh -c "dd bs=4 count=5 < Vload50.r > Vload50.boot"
	cat addr4000 >> Vload50.boot
	sh -c "dd bs=4 skip=5 count=2 < Vload50.r >> Vload50.boot"
	sh -c "dd bs=32 skip=1 < Vload50.r >> Vload50.boot"

Vload50.sym: $(OBJECTS50) 
	$(LINK) -e entry -o foo -X -T b8000 $(OBJECTS50) $(SUN2LIBS)
	nm68 -n -h foo | grep -v " a " > Vload50.sym
	rm foo

# 10Mbit version (MC68010 with 3Com board)
# Update the downloadable images
#  .r is byte-reversed, with Sun-style b.out header.
#  .d has the b.out header stripped.
#  .boot has the SMI-Unix style a.out header, with entry point 4000.
#  
Vload10.b: $(MI)/Vload.c
	cc68 $(C68FLAGS10) -DXV -c $(MI)/Vload.c -o Vload10.b
enet3com.b: enet3com.c
	cc68 $(C68FLAGS10) -I../../../libc/drivers/m68k -c enet3com.c
# CROCK!  We (temporarily, I hope) pull enet3com.h out of this hat.  Ideally,
#         we should abolish Vload's enet3com.c and use the verion from
#         libc/drivers, unless there's a vital difference in space consumption

Vload10.68: $(OBJECTS10) 
	$(LINK) -e entry -o Vload10.68 -s -T b8000 $(OBJECTS10) $(SUN2LIBS)
	rm -f Vload10.sym

Vload10.r: Vload10.68
	rev68 Vload10 Vload10.r
	size68 -h Vload10.r

Vload10.d: Vload10.r
	sh -c "dd bs=32 skip=1 < Vload10.r > Vload10.d"

Vload10.boot: Vload10.r addr4000
	sh -c "dd bs=4 count=5 < Vload10.r > Vload10.boot"
	cat addr4000 >> Vload10.boot
	sh -c "dd bs=4 skip=5 count=2 < Vload10.r >> Vload10.boot"
	sh -c "dd bs=32 skip=1 < Vload10.r >> Vload10.boot"

Vload10.sym: $(OBJECTS10) 
	$(LINK) -e entry -o foo -X -T b8000 $(OBJECTS10) $(SUN2LIBS)
	nm68 -n -h foo | grep -v " a " > Vload10.sym
	rm foo

# 10Mbit version (MC68000 with Excelan board)
# Update the downloadable image (byte-reversed),
#   changing the entry point to 1000
#  .68 is the default extension for rev68

Vload10x.b: $(MI)/Vload.c
	cc68 $(C68FLAGS10XLN) -c $(MI)/Vload.c -o Vload10x.b
enet10x.b: enet10x.c
	cc68 $(C68FLAGS10XLN) -c enet10x.c

Vload10x.68: $(OBJECTS10XLN) 
	$(LINK) -e entry -o Vload10x.68 -s -T 1d000 $(OBJECTS10XLN) $(SUN1LIBS)
	rm -f Vload10x.sym

xlnVload: Vload10x.68 addr1000
	sh -c "dd bs=28 count=1 < Vload10x.68 > FOO.68"
	cat addr1000 >> FOO.68
	sh -c "dd bs=32 skip=1 < Vload10x.68 >> FOO.68"
	rev68 FOO xlnVload
	rm -f FOO.68
	size68 -h xlnVload

Vload10x.sym: $(OBJECTS10XLN) 
	$(LINK) -e entry -o foo -X -T 1d000 $(OBJECTS10XLN) $(SUN1LIBS)
	nm68 -n -h foo | grep -v " a " > Vload10x.sym
	rm foo

xlnV: xlnVload
	cp xlnVload xlnV
xlnVV: xlnVload
	cp xlnVload xlnVV

xlnxVload: xlnVload
	cp xlnVload xlnxVload
xlnxV: xlnxVload
	cp xlnxVload xlnxV
xlnxVV: xlnxVload
	cp xlnxVload xlnxVV

# Standard buildfile entries
relink:
	rm -f *.68 $(ALL) *.sym

clean:
	rm -f *.b *.d *.o *.r *.s *.ls *.BAK *.CKP *.68 *.boot *.sym .emacs*

install: all
	netinstall -x -p -m 0654 "$(ALL3) Vload3+ie.d" /usr/sun/bootfile
	netinstall -x -p -m 0654 "$(ALL10XLN)" /usr/sun/bootfile
	netinstall -x -p "Vload10.d Vload50.d" $(PRODUCTION_VSYS)/boot
	netinstall -x -p "Vload10.d Vload50.d" /usr/sun/Vboot 
# 19-Mar-86: The final line (installing in /usr/sun/Vboot) should go away as
#	     soon as all Stanford hosts have /usr/V directory structures and
#	     run a version of the ndserver that looks in /usr/V/boot (and
#	     the config files have been changed appropriately).
# The first two lines (installing to /usr/sun/bootfile) are for Sun-1 and
# Sun-3 machines: these boot using EFTP or TFTP (?), and the unix servers we
# run (nothing to do with the V system) look in /usr/sun/bootfile.
# The third line is for machines that boot using the Sun ND protocol; our
# ndserver expects to fetch these from /usr/V/boot.

