diff --git a/Makefile b/Makefile index 0018688..0f9cdf3 100644 --- a/Makefile +++ b/Makefile @@ -24,12 +24,18 @@ GTKWSAVE=./gtkwave_savefile.gtkw include common.mk -boot_code/%txt: +.PHONY:${BOOT_CODE} +${BOOT_CODE}: ${Q}make ${MAKEOPTS} -C boot_code $(subst boot_code/,,$@) +boot_code/%.txt: + ${Q}make ${MAKEOPTS} -C boot_code $(subst boot_code/,,$@) + +.PHONY:${SYSTEM_VVP} ${SYSTEM_VVP}: ${Q}make ${MAKEOPTS} -C system system.vvp +.PHONY: clean clean: ${Q}make ${MAKEOPTS} -C system clean ${Q}make ${MAKEOPTS} -C boot_code clean diff --git a/boot_code/brainfuck.asm b/boot_code/brainfuck.asm index c6d9d53..6dba1b2 100644 --- a/boot_code/brainfuck.asm +++ b/boot_code/brainfuck.asm @@ -117,5 +117,8 @@ hlt bracket: .BLKB 280 data: .BLKB 560 -;prog db '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.f' -prog:.ASCII '++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.' +prog: +.ASCII '++++++++++[>+>+++>+++++++>++++++++++<<<<-]>>>++.>+.+++++++..+++.<<++.>+++++++++++++++.>.+++.------.--------.<<.>>++.+++++' +.ASCII '+++++++.---.--.<<.>---------------------.>+++++.-----------------.++++++++.+++++.--------.+++++++++++++++.---------------' +.ASCII '---.++++++++.<<<.>>>------------------.++++++++++++++++++++++.++++++.---.+.<<.>>+.--.+++.---------.+++++++++++++.<<++++++' +.ASCII '++++++.------------.>----------.--------.++++++++.--.<<.' diff --git a/common.mk b/common.mk index f6490ba..461c107 100644 --- a/common.mk +++ b/common.mk @@ -1,3 +1,4 @@ +.PRECIOUS:${BOOT_CODE} QUIET=1 ifeq "${QUIET}" "1" @@ -12,15 +13,13 @@ else Q = endif -run: ${BOOT_CODE} ${SYSTEM_VVP} - ${QUIET_VVP} - ${Q}vvp "${SYSTEM_VVP}" -lxt2 +BOOT_CODE="$<" +WAVEFORM="$(subst .txt,.lx2,$<)" +MEMDUMP="$(subst .txt,.memdumptxt,$<)" - ${Q}grep -v '^//' "$(subst .txt,.memdumptxt,$<)" | xxd -ps -c 2 -r > "$(subst .txt,.memdump,$<)" - ${Q}rm "$(subst .txt,.memdumptxt,$<)" +.PHONY: run wave disas +run: $(subst .txt,.run,${BOOT_CODE}) wave: $(subst .txt,.wave,${BOOT_CODE}) disas: $(subst .txt,.disas,${BOOT_CODE}) + # Assembling code %.txt:%.bin ${Q}dd if=/dev/zero bs=1 count=16384 of="$(subst .bin,.stage,$<)" status=none @@ -39,11 +38,13 @@ disas: $(subst .txt,.disas,${BOOT_CODE}) ${Q}grep -v '^//' "$(subst .txt,.memdumptxt,$<)" | xxd -ps -c 2 -r > "$(subst .txt,.memdump,$<)" ${Q}rm "$(subst .txt,.memdumptxt,$<)" -.PHONY: disas +%.run: %.txt ${SYSTEM_VVP} + ${QUIET_VVP} + ${Q}vvp "${SYSTEM_VVP}" +BOOT_CODE="$<" + %.disas: %.bin objdump -D -b binary -m i8086 $^ | less # Tools -.PHONY: %.wave %.wave : %.lx2 gtkwave "$<" "${GTKWSAVE}" diff --git a/system/Makefile b/system/Makefile index ecc9e31..2ab5780 100644 --- a/system/Makefile +++ b/system/Makefile @@ -26,7 +26,7 @@ include ../common.mk # COMPILING ${SYSTEM_VVP} : ${SOURCES} ${INCLUDES} ${QUIET_IVERILOG} - ${Q}iverilog -g2012 ${SOURCES} -o $@ + ${Q}iverilog -g2012 -o "$@" ${SOURCES} .PHONY: clean diff --git a/system/testbench.v b/system/testbench.v index 0d70c28..74ce7c0 100644 --- a/system/testbench.v +++ b/system/testbench.v @@ -41,13 +41,9 @@ integer cycles=0; string memdump_name; initial begin string waveform_name; - if(!$value$plusargs("WAVEFORM=%s",waveform_name))begin - waveform_name="waveform.lx2"; - end - $dumpfile(waveform_name); - $dumpvars(0,p,u1); - if(!$value$plusargs("MEMDUMP=%s",memdump_name))begin - memdump_name="memdump.txt"; + if($value$plusargs("WAVEFORM=%s",waveform_name))begin + $dumpfile(waveform_name); + $dumpvars(0,p,u1); end reset = 0; clk_enable <= 1; @@ -59,7 +55,9 @@ end always @(posedge HALT) begin $display("Processor halted.\nCycles run for: %d",cycles); - $writememh(memdump_name, sysmem.memory); + if($value$plusargs("MEMDUMP=%s",memdump_name))begin + $writememh(memdump_name, sysmem.memory); + end #(`CPU_SPEED) //Just for the waveform $finish; end @@ -67,7 +65,9 @@ end always @(posedge ERROR) begin clk_enable <= 0; $display("PROCESSOR RUN INTO AN ERROR.\nCycles run for: %d",cycles); - $writememh(memdump_name, sysmem.memory); + if($value$plusargs("MEMDUMP=%s",memdump_name))begin + $writememh(memdump_name, sysmem.memory); + end #(`CPU_SPEED) //Just for the waveform $finish; end