include $(ROOT)/usr/include/make/X86defs

TARGET_CFILES = start.c pll.c por.c func.c

LCINCS  = -I$(ROOT)/usr/include/sc
LDIRT += *.log

# name of the test binary;
# has to match the flash configuration;

ifdef	BOOTX
BOOT0 ?= ../../sc/boot/bootx/bootx.bin
TEST_KP ?= ../sc/kp/test.bin
TEST_FUNC ?= ../sc/func/test.bin
else	# BOOTX
BOOT0 ?= ../../sc/boot/boot0/boot0.bin
TEST_KP ?= ../sc/kp/test.512
TEST_FUNC ?= ../sc/func/test.512
endif	# BOOTX
TEST_FT ?= ../sc/ft/test.bin

default: $(TARGETS) $(TARGET_CFILES)
	
$(TARGETS): $(ROOT)/usr/lib/x86/libiosim.a

include $(COMMONRULES)

# cpu.ipc target calls testProc at time 0;

%.log: FORCE
	SC_TEST=1 SIMDEFS="+define+FASTFLASH +define+TOSHIBA_128M" \
		make -C $(shell echo $(shell pwd) \
			| sed -e 's|\(.*\)/sw/.*|\1/hw/chip/sim|') cpu.ipc > $@ 2>&1 &
	sleep 10

FORCE:
 
# run pll tests for each system pll config;

pll0.sim: start pll pll0.log $(TARGETS)
	./start -ccpu0 -En -z -a $(BOOT0) ; [ $$? -eq 0 ]
	./pll -ccpu0 -En -q -z -a "0 100000" ; [ $$? -eq 0 ]

pll1.sim: start pll pll1.log $(TARGETS)
	./start -ccpu0 -En -z -a $(BOOT0) ; [ $$? -eq 0 ]
	./pll -ccpu0 -En -q -z -a "1 100000" ; [ $$? -eq 0 ]

pll2.sim: start pll pll2.log $(TARGETS)
	./start -ccpu0 -En -z -a $(BOOT0) ; [ $$? -eq 0 ]
	./pll -ccpu0 -En -q -z -a "2 100000" ; [ $$? -eq 0 ]

pll3.sim: start pll pll3.log $(TARGETS)
	./start -ccpu0 -En -z -a $(BOOT0) ; [ $$? -eq 0 ]
	./pll -ccpu0 -En -q -z -a "3 100000" ; [ $$? -eq 0 ]

# por test;

por.sim: start por por.log $(TARGETS)
	./start -ccpu0 -En -z -a $(BOOT0) ; [ $$? -eq 0 ]
	./por -ccpu0 -En -q -z ; [ $$? -eq 0 ]

# kilopas test;
# runs slower due to hw bug;

kp.sim: start por func kp.log $(TARGETS)
	./start -ccpu0 -En -z -a $(BOOT0) ; [ $$? -eq 0 ]
	./por -ccpu0 -En -z -a 1000800 ; [ $$? -eq 0 ]
	./func -ccpu0 -En -q -z -a $(TEST_KP); [ $$? -eq 0 ]

# run functional tests;

func.sim: start por func func.log $(TARGETS)
	./start -ccpu0 -En -z -a $(BOOT0) ; [ $$? -eq 0 ]
	./por -ccpu0 -En -z ; [ $$? -eq 0 ]
	./func -ccpu0 -En -q -z -a "$(TEST_FUNC) $(TEST_FT)"; [ $$? -eq 0 ]

