Improved build system and project directory structure

This commit is contained in:
(Tim) Efthimis Kritikos 2023-02-16 01:46:22 +00:00
parent 5e0c990394
commit ded47555a5
20 changed files with 422 additions and 72 deletions

14
.gitignore vendored
View File

@ -3,9 +3,11 @@
*.lx2
*.o
*.swp
cpu/boot_code.bin
cpu/boot_code.txt
cpu/brainfuck.bin
cpu/brainfuck.txt
cpu/memdump.txt
cpu/memdump.bin
*.memdump
*.lxt # Not sure when those crop up
boot_code/brainfuck.bin
boot_code/brainfuck.txt
boot_code/brainfuck_mandelbrot.bin
boot_code/brainfuck_mandelbrot.txt
system/boot_code.bin
system/boot_code.txt

35
Makefile Normal file
View File

@ -0,0 +1,35 @@
# This file is part of the 9086 project.
#
# Copyright (c) 2023 Efthymios Kritikos
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
SYSTEM_VVP=system/system.vvp
BOOT_CODE=boot_code/brainfuck.txt
GTKWSAVE=./gtkwave_savefile.gtkw
include common.mk
boot_code/%txt:
${Q}make ${MAKEOPTS} -C boot_code $(subst boot_code/,,$@)
${SYSTEM_VVP}:
${Q}make ${MAKEOPTS} -C system system.vvp
clean:
${Q}make ${MAKEOPTS} -C system clean
${Q}make ${MAKEOPTS} -C boot_code clean

View File

@ -12,8 +12,7 @@ A CPU that aims to be binary compatible with the 8086 and with as many optimisat
* [ ] Is superscalar
### Building it
To build it you need Icarus Verilog, bin86, GNU make, xxd and the posix coreutils.
Go into the cpu directory and run `make`
To build this project you need Icarus Verilog, bin86, GNU make, xxd and the posix coreutils and run `make` on the top level directory.
At the time of development the versions used are :

14
boot_code/Makefile Normal file
View File

@ -0,0 +1,14 @@
SOURCE=$(shell ls |grep asm$)
BINARIES=$(subst .asm,.txt,${SOURCE})
BUILD_FILES=${BINARIES}
BUILD_FILES+=$(subst .asm,.memdump,${SOURCE})
BUILD_FILES+=$(subst .asm,.lx2,${SOURCE})
BUILD_FILES+=$(subst .asm,.bin,${SOURCE})
all: ${BINARIES}
include ../common.mk
clean:
$(call QUIET_CLEAN,boot_code)
${Q}rm -f $(BUILD_FILES) *lxt

View File

@ -0,0 +1,264 @@
; brainfuck.asm - Naive and unoptimised implementation of a brainfuck interpreter
;
; This file is part of the 9086 project.
;
; Copyright (c) 2023 Efthymios Kritikos
;
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program. If not, see <http://www.gnu.org/licenses/>.
mov si,#prog
mov BX,#data
mov CX,#bracket
dec si
INTERPRET:
inc si
mov al,[si]
cmp al,#'+
jz WAS_PLUS
cmp al,#'-
jz WAS_MINUS
cmp al,#'>
jz WAS_MR
cmp al,#'<
jz WAS_ML
cmp al,#'[
jz WAS_PL
cmp al,#']
jz WAS_PR
cmp al,#'.
jz WAS_PRINT
jmp PROG_END
WAS_PLUS:
inc BYTE [BX]
JMP INTERPRET
WAS_MINUS:
dec BYTE [BX]
JMP INTERPRET
WAS_MR:
inc bx
JMP INTERPRET
WAS_ML:
dec bx
JMP INTERPRET
WAS_PL:
MOV AL,[BX]
cmp AL,#0
jz SKIP_CODE_BLOCK
;have to enter loop
MOV AX,SI
inc CX
inc CX
MOV SI,CX
mov [SI],AX
mov SI,AX
JMP INTERPRET
SKIP_CODE_BLOCK:
;have to skip loop
MOV DX,#0
SKIP_LOOP:
INC SI
mov AL,[SI]
CMP AL,#']
JZ WAS_CLOSE1
CMP AL,#'[
JZ WAS_OPEN1
JMP SKIP_LOOP
WAS_CLOSE1:
CMP DX,#0
JZ INTERPRET
DEC DX
JMP SKIP_LOOP
WAS_OPEN1:
INC DX
JMP SKIP_LOOP
WAS_PR:
mov AL,[BX]
cmp AL,#0
JZ EXIT_PR
MOV SI,CX
mov ax,[SI]
mov si,ax
JMP INTERPRET
EXIT_PR:
DEC CX
DEC CX
jmp INTERPRET
WAS_PRINT:
mov ah, #0x02
MOV DL,[BX]
int #0x21
JMP INTERPRET
PROG_END:
hlt
bracket: .BLKB 280
data: .BLKB 560
;prog db '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.f'
prog:.ASCII '+++++++++++++[->++>>>+++++>++>+<<<<<<]>>>>>++++++>--->>>>>>>>>>+++++++++++++++[['
.ASCII '>>>>>>>>>]+[<<<<<<<<<]>>>>>>>>>-]+[>>>>>>>>[-]>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>[-]+'
.ASCII '<<<<<<<+++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>>+>>>>>>>>>>>>>>>>>>>>>>>>>>'
.ASCII '>+<<<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+[>>>>>>[>>>>>>>[-]>>]<<<<<<<<<[<<<<<<<<<]>>'
.ASCII '>>>>>[-]+<<<<<<++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>+<<<<<<+++++++[-[->>>'
.ASCII '>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>+<<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[[-]>>>>>>[>>>>>'
.ASCII '>>[-<<<<<<+>>>>>>]<<<<<<[->>>>>>+<<+<<<+<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>'
.ASCII '[>>>>>>>>[-<<<<<<<+>>>>>>>]<<<<<<<[->>>>>>>+<<+<<<+<<]>>>>>>>>]<<<<<<<<<[<<<<<<<'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>>>'
.ASCII '-<<[-<<<<<<+>>>>>>]<<<<<<[->>>>>>+<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+>>>>>>[>>>>>>'
.ASCII '>>>]>[-]+<]]+>[-<[>>>>>>>>>]<<<<<<<<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>[-]<<<++++'
.ASCII '+[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>->>>>>>>>>>>>>>>>>>>>>>>>>>>-<<<<<<[<<<<'
.ASCII '<<<<<]]>>>]'

49
common.mk Normal file
View File

@ -0,0 +1,49 @@
QUIET=1
ifeq "${QUIET}" "1"
QUIET_AS = @echo ' AS '$@;
QUIET_VVP = @echo ' VVP '$@;
QUIET_IVERILOG = @echo ' IVERILOG '$@;
QUIET_CLEAN = @printf ' CLEAN %s\n' $1;
Q = @
MAKEOPTS=--no-print-directory
.SILENT:
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,$<)"
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
${Q}dd if="$<" of="$(subst .bin,.stage,$<)" conv=notrunc,nocreat status=none
${Q}xxd -ps -c 2 "$(subst .bin,.stage,$<)" > "$@"
${Q}rm "$(subst .bin,.stage,$<)"
%.bin:%.asm
${QUIET_AS}
${Q}as86 -0 "$<" -b "$@"
# Running simulation
%.lx2 %.memdump: %.txt ${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: disas
%.disas: %.bin
objdump -D -b binary -m i8086 $^ | less
# Tools
.PHONY: %.wave
%.wave : %.lx2
gtkwave "$<" "${GTKWSAVE}"

View File

@ -1,59 +0,0 @@
# This file is part of the 9086 project.
#
# Copyright (c) 2023 Efthymios Kritikos
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
SOURCES=processor.v testbench.v memory.v registers.v alu.v
INCLUDES=proc_state_def.v alu_header.v config.v
VVP=processor.vvp
.PHONY: brainf
brainf: ${VVP} brainfuck.txt
vvp ${VVP} +BOOT_CODE=brainfuck.txt
grep -v '^//' memdump.txt | xxd -ps -c 2 -r > memdump.bin
.PHONY: run
run: ${VVP} boot_code.txt
vvp ${VVP}
grep -v '^//' memdump.txt | xxd -ps -c 2 -r > memdump.bin
.PHONY: build
build: ${VVP}
.PHONY: wave
wave: ${VVP} brainfuck.txt
vvp ${VVP} -lxt2 #+BOOT_CODE=brainfuck.txt
gtkwave test.lx2 gtkwave_savefile.gtkw
grep -v '^//' memdump.txt | xxd -ps -c 2 -r > memdump.bin
${VVP} : ${SOURCES} ${INCLUDES}
iverilog -g2012 ${SOURCES} -o $@
%.txt:%.bin
dd if=/dev/zero bs=1 count=16384 of=$(subst .bin,.stage,$^) status=none
dd if=$^ of=$(subst .bin,.stage,$^) conv=notrunc,nocreat status=none
xxd -ps -c 2 $(subst .bin,.stage,$^) > $@
rm $(subst .bin,.stage,$^)
%.bin:%.asm
as86 -0 $< -b $@
.PHONY: disas
disas: brainfuck.bin
objdump -D -b binary -m i8086 $^ | less
.PHONY: clean
clean:
rm -f ${VVP} test.lx2 boot_code.txt boot_code.bin brainfuck.txt brainfuck.bin memdump.txt

BIN
cpu/test

Binary file not shown.

35
system/Makefile Normal file
View File

@ -0,0 +1,35 @@
# This file is part of the 9086 project.
#
# Copyright (c) 2023 Efthymios Kritikos
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
SOURCES=processor.v testbench.v memory.v registers.v alu.v
INCLUDES=proc_state_def.v alu_header.v config.v
SYSTEM_VVP=system.vvp
BOOT_CODE=boot_code.txt
GTKWSAVE=../gtkwave_savefile.gtkw
include ../common.mk
# COMPILING
${SYSTEM_VVP} : ${SOURCES} ${INCLUDES}
${QUIET_IVERILOG}
${Q}iverilog -g2012 ${SOURCES} -o $@
.PHONY: clean
clean:
$(call QUIET_CLEAN,system)
${Q}rm -f ${SYSTEM_VVP} *.lx2 boot_code.txt boot_code.bin *memdump *memdumptxt

View File

@ -16,6 +16,7 @@ inc [si]
inc [si]
inc [si]
dec [si]
dec cx
cmp CX,#0x00
jz start
HLT

View File

@ -21,8 +21,10 @@ module mem(input [19:0] address,inout wire [15:0] data ,input rd,input wr,input
reg [15:0] memory [0:8191];
initial begin
string boot_code;
if(!$value$plusargs("BOOT_CODE=%s",boot_code))
boot_code="boot_code.txt";
if(!$value$plusargs("BOOT_CODE=%s",boot_code))begin
$display("No boot code specified. Please add +BOOT_CODE=<path> to your vvp args");
$finish;
end
$readmemh(boot_code, memory);
end

View File

@ -38,9 +38,17 @@ clock_gen #(.FREQ(1000)) u1(clk_enable, clock);
assign romcs=0;
integer cycles=0;
string memdump_name;
initial begin
$dumpfile("test.lx2");
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";
end
reset = 0;
clk_enable <= 1;
@ -51,7 +59,7 @@ end
always @(posedge HALT) begin
$display("Processor halted.\nCycles run for: %d",cycles);
$writememh("memdump.txt", sysmem.memory);
$writememh(memdump_name, sysmem.memory);
#(`CPU_SPEED) //Just for the waveform
$finish;
end
@ -59,7 +67,7 @@ end
always @(posedge ERROR) begin
clk_enable <= 0;
$display("PROCESSOR RUN INTO AN ERROR.\nCycles run for: %d",cycles);
$writememh("memdump.txt", sysmem.memory);
$writememh(memdump_name, sysmem.memory);
#(`CPU_SPEED) //Just for the waveform
$finish;
end