From b85c2b3d4c136510ec81c4ae14e39d9e60d3922b Mon Sep 17 00:00:00 2001 From: ZipCPU Date: Mon, 24 May 2021 15:33:29 -0400 Subject: [PATCH 01/11] MASSIVE UPDATE: Update CPU structure Passes tests: cputest, contest, hello More tests to follow. Also updated copyrights and added a lot of vim folding. --- README.md | 2 +- auto-data/bkram.txt | 14 +- auto-data/busconsole.txt | 26 +- auto-data/buserr.txt | 14 +- auto-data/clock.txt | 14 +- auto-data/flash.txt | 14 +- auto-data/global.txt | 22 +- auto-data/gpio.txt | 14 +- auto-data/legalgen.txt | 14 +- auto-data/mem_bkram_only.txt | 15 +- auto-data/mem_flash_bkram.txt | 13 +- auto-data/pic.txt | 14 +- auto-data/pwrcount.txt | 14 +- auto-data/rtcdate.txt | 14 +- auto-data/rtclight.txt | 14 +- auto-data/sdspi.txt | 16 +- auto-data/simtrace.txt | 14 +- auto-data/version.txt | 14 +- auto-data/wbuart.txt | 13 +- auto-data/zipmaster.txt | 86 +- doc/20210524-gcc-10-cpu-test.png | Bin 0 -> 225572 bytes mkdatev.pl | 28 +- rtl/Makefile | 14 +- rtl/builddate.v | 18 +- rtl/cpu/axidcache.v | 928 ++++++ rtl/cpu/axiicache.v | 587 ++++ rtl/cpu/axilfetch.v | 1073 +++++++ rtl/cpu/axilops.v | 1276 ++++++++ rtl/cpu/axilperiphs.v | 551 ++++ rtl/cpu/axilpipe.v | 1787 +++++++++++ rtl/cpu/axiops.v | 905 ++++++ rtl/cpu/axipipe.v | 994 ++++++ rtl/cpu/busdelay.v | 345 ++- rtl/cpu/cpudefs.v | 71 +- rtl/cpu/cpuops.v | 105 +- rtl/cpu/dblfetch.v | 227 +- rtl/cpu/dcache.v | 415 ++- rtl/cpu/div.v | 112 +- rtl/cpu/icontrol.v | 86 +- rtl/cpu/idecode.v | 388 ++- rtl/cpu/iscachable.cpp | 62 - rtl/cpu/iscachable.v | 14 +- rtl/cpu/memops.v | 285 +- rtl/cpu/mpyop.v | 181 +- rtl/cpu/pfcache.v | 213 +- rtl/cpu/pipefetch.v | 306 -- rtl/cpu/pipemem.v | 284 +- rtl/cpu/prefetch.v | 140 +- rtl/cpu/sfifo.v | 449 +++ rtl/cpu/slowmpy.v | 121 +- rtl/cpu/wbarbiter.v | 315 +- rtl/cpu/wbdblpriarb.v | 235 +- rtl/cpu/wbdmac.v | 408 ++- rtl/cpu/wbpriarbiter.v | 136 +- rtl/cpu/wbwatchdog.v | 90 +- rtl/cpu/zipaxi.v | 1306 ++++++++ rtl/cpu/zipaxil.v | 1049 +++++++ rtl/cpu/zipbones.v | 530 +++- rtl/cpu/zipcore.v | 4882 ++++++++++++++++++++++++++++++ rtl/cpu/zipcounter.v | 83 +- rtl/cpu/zipcpu.v | 2749 ----------------- rtl/cpu/zipjiffies.v | 166 +- rtl/cpu/zipsystem.v | 1686 +++++++---- rtl/cpu/ziptimer.v | 190 +- rtl/cpu/zipwb.v | 545 ++++ rtl/main.v | 822 ++--- rtl/make.inc | 44 +- rtl/qflexpress.v | 13 +- rtl/rtc/rtcalarm.v | 112 +- rtl/rtc/rtcbare.v | 106 +- rtl/rtc/rtcdate.v | 157 +- rtl/rtc/rtclight.v | 180 +- rtl/rtc/rtcstopwatch.v | 69 +- rtl/rtc/rtctimer.v | 98 +- rtl/sdspi/sdspi.v | 407 +-- rtl/skidbuffer.v | 392 ++- rtl/toplevel.v | 120 +- rtl/wbubus/wbconsole.v | 189 +- rtl/wbubus/wbubus.v | 213 +- rtl/wbubus/wbucompactlines.v | 115 +- rtl/wbubus/wbucompress.v | 43 +- rtl/wbubus/wbuconsole.v | 306 +- rtl/wbubus/wbudecompress.v | 111 +- rtl/wbubus/wbudeword.v | 45 +- rtl/wbubus/wbuexec.v | 166 +- rtl/wbubus/wbufifo.v | 79 +- rtl/wbubus/wbuidleint.v | 149 +- rtl/wbubus/wbuinput.v | 41 +- rtl/wbubus/wbuoutput.v | 65 +- rtl/wbubus/wbureadcw.v | 70 +- rtl/wbubus/wbusixchar.v | 59 +- rtl/wbubus/wbutohex.v | 62 +- sim/verilated/automaster_tb.cpp | 44 +- sim/verilated/busmaster_tb.cpp | 14 +- sim/verilated/byteswap.cpp | 14 +- sim/verilated/byteswap.h | 14 +- sim/verilated/dblpipecmdr.h | 14 +- sim/verilated/dbluartsim.cpp | 14 +- sim/verilated/dbluartsim.h | 14 +- sim/verilated/flashsim.cpp | 9 +- sim/verilated/flashsim.h | 4 +- sim/verilated/main_tb.cpp | 80 +- sim/verilated/memsim.cpp | 14 +- sim/verilated/memsim.h | 14 +- sim/verilated/pipecmdr.h | 14 +- sim/verilated/port.h | 14 +- sim/verilated/sdspisim.cpp | 14 +- sim/verilated/sdspisim.h | 14 +- sim/verilated/tbclock.h | 14 +- sim/verilated/testb.h | 14 +- sim/verilated/twoc.cpp | 14 +- sim/verilated/twoc.h | 14 +- sim/verilated/uartsim.cpp | 14 +- sim/verilated/uartsim.h | 14 +- sim/verilated/vversion.sh | 14 +- sim/verilated/zipelf.cpp | 15 +- sim/verilated/zipelf.h | 14 +- sw/board/Makefile | 17 +- sw/board/bkram.ld | 14 +- sw/board/board.ld | 14 +- sw/board/contest.c | 59 +- sw/board/cputest.c | 16 +- sw/board/gpiotoggle.c | 14 +- sw/board/hello.c | 4 +- sw/board/sdtest.c | 14 +- sw/board/txfns.c | 14 +- sw/board/txfns.h | 14 +- sw/host/byteswap.cpp | 14 +- sw/host/byteswap.h | 14 +- sw/host/devbus.h | 14 +- sw/host/dumpflash.cpp | 14 +- sw/host/flashdrvr.cpp | 14 +- sw/host/flashdrvr.h | 15 +- sw/host/llcomms.cpp | 14 +- sw/host/llcomms.h | 14 +- sw/host/netuart.cpp | 15 +- sw/host/port.h | 16 +- sw/host/regdefs.cpp | 64 +- sw/host/regdefs.h | 81 +- sw/host/ttybus.cpp | 14 +- sw/host/ttybus.h | 15 +- sw/host/twoc.cpp | 14 +- sw/host/twoc.h | 18 +- sw/host/wbregs.cpp | 14 +- sw/host/zipdbg.cpp | 31 +- sw/host/zipelf.cpp | 14 +- sw/host/zipelf.h | 14 +- sw/host/zipload.cpp | 30 +- sw/host/zipstate.cpp | 64 +- sw/host/zopcodes.cpp | 30 +- sw/host/zopcodes.h | 14 +- sw/zlib/Makefile | 14 +- sw/zlib/board.h | 162 +- sw/zlib/bootloader.h | 14 +- sw/zlib/crt0.c | 124 +- sw/zlib/syscalls.c | 14 +- sw/zlib/udiv.c | 30 +- sw/zlib/umod.c | 14 +- sw/zlib/zipcpu.h | 18 +- sw/zlib/zipsys.h | 14 +- 160 files changed, 24422 insertions(+), 8084 deletions(-) create mode 100644 doc/20210524-gcc-10-cpu-test.png create mode 100644 rtl/cpu/axidcache.v create mode 100644 rtl/cpu/axiicache.v create mode 100644 rtl/cpu/axilfetch.v create mode 100644 rtl/cpu/axilops.v create mode 100644 rtl/cpu/axilperiphs.v create mode 100644 rtl/cpu/axilpipe.v create mode 100644 rtl/cpu/axiops.v create mode 100644 rtl/cpu/axipipe.v delete mode 100644 rtl/cpu/iscachable.cpp delete mode 100644 rtl/cpu/pipefetch.v create mode 100644 rtl/cpu/sfifo.v create mode 100644 rtl/cpu/zipaxi.v create mode 100644 rtl/cpu/zipaxil.v create mode 100644 rtl/cpu/zipcore.v delete mode 100644 rtl/cpu/zipcpu.v create mode 100644 rtl/cpu/zipwb.v diff --git a/README.md b/README.md index 4fd36fb..ff91277 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # ZBasic This project provides a very basic version of a working -[ZipCPU](https://github.com/ZipCPU/zbasic) system. It is designed so that +[ZipCPU](https://github.com/ZipCPU/zipcpu) system. It is designed so that others (you perhaps?) can then build off of it and design with it. ZBasic has three primary goals: diff --git a/auto-data/bkram.txt b/auto-data/bkram.txt index 1462236..330b917 100644 --- a/auto-data/bkram.txt +++ b/auto-data/bkram.txt @@ -1,7 +1,7 @@ ################################################################################ ## ## Filename: bkram.txt -## +## {{{ ## Project: AutoFPGA, a utility for composing FPGA designs from peripherals ## ## Purpose: To define the interface to a generic block RAM device for the @@ -11,9 +11,9 @@ ## Gisselquist Technology, LLC ## ################################################################################ -## -## Copyright (C) 2017-2020, Gisselquist Technology, LLC -## +## }}} +## Copyright (C) 2017-2021, Gisselquist Technology, LLC +## {{{ ## This program is free software (firmware): 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 @@ -28,14 +28,14 @@ ## with this program. (It's in the $(ROOT)/doc directory. Run make with no ## target there if the PDF file isn't present.) If not, see ## for a copy. -## +## }}} ## License: GPL, v3, as defined and found on www.gnu.org, +## {{{ ## http://www.gnu.org/licenses/gpl.html ## -## ################################################################################ ## -## +## }}} @PREFIX=bkram @DEVID=BKRAM @$LGMEMSZ=20 diff --git a/auto-data/busconsole.txt b/auto-data/busconsole.txt index 7ba8fc0..e736908 100644 --- a/auto-data/busconsole.txt +++ b/auto-data/busconsole.txt @@ -1,7 +1,7 @@ ################################################################################ ## ## Filename: wbuconsole.txt -## +## {{{ ## Project: AutoFPGA, a utility for composing FPGA designs from peripherals ## ## Purpose: Provide access to both a debugging bus and a console port for @@ -15,9 +15,9 @@ ## Gisselquist Technology, LLC ## ################################################################################ -## -## Copyright (C) 2017-2019, Gisselquist Technology, LLC -## +## }}} +## Copyright (C) 2017-2021, Gisselquist Technology, LLC +## {{{ ## This program is free software (firmware): 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 @@ -32,14 +32,14 @@ ## with this program. (It's in the $(ROOT)/doc directory. Run make with no ## target there if the PDF file isn't present.) If not, see ## for a copy. -## +## }}} ## License: GPL, v3, as defined and found on www.gnu.org, +## {{{ ## http://www.gnu.org/licenses/gpl.html ## -## ################################################################################ ## -## +## }}} @PREFIX=wbu @DEVID=DBGBUS @ACCESS=WBUBUS_MASTER @@ -99,11 +99,6 @@ wire zip_dbg_stall, zip_dbg_ack; wire [31:0] zip_dbg_data; `endif -@$ZIP_ADDRESS_BIT=@$BUS_ADDRESS_WIDTH-1 -@$ZIP_ADDRESS=(1<<(@$.ZIP_ADDRESS_BIT+2)) -@ZIP_ADDRESS.FORMAT= 0x%08x -@$ZIP_DBGDATA=4+@$.ZIP_ADDRESS -@ZIP_DBGDATA.FORMAT= 0x%08x @MAIN.INSERT= // The Host USB interface, to be used by the WB-UART bus rxuartlite #(.TIMER_BITS(@$(DEVID)BITS), @@ -132,10 +127,11 @@ wire [31:0] @$(MASTER.PREFIX)_tmp_addr; // Verilator lint_on UNUSED wbuconsole #(.LGWATCHDOG(@$(DEVID)WATCHDOG)) - genbus(@$(CLOCK.WIRE), @$(PREFIX)_rx_stb, @$(PREFIX)_rx_data, + genbus(@$(CLOCK.WIRE), 1'b0, @$(PREFIX)_rx_stb, @$(PREFIX)_rx_data, @$(MASTER.PREFIX)_cyc, @$(MASTER.PREFIX)_stb, @$(MASTER.PREFIX)_we, @$(MASTER.PREFIX)_tmp_addr, @$(MASTER.PREFIX)_data, @$(MASTER.PREFIX)_stall, @$(MASTER.PREFIX)_ack, - @$(MASTER.PREFIX)_err, @$(MASTER.PREFIX)_idata, + @$(MASTER.PREFIX)_idata, + @$(MASTER.PREFIX)_err, w_bus_int, @$(PREFIX)_tx_stb, @$(PREFIX)_tx_data, @$(PREFIX)_tx_busy, // @@ -146,8 +142,6 @@ assign @$(MASTER.PREFIX)_sel = 4'hf; assign @$(MASTER.PREFIX)_addr = @$(MASTER.PREFIX)_tmp_addr[(@$BUS_ADDRESS_WIDTH-1):0]; @REGDEFS.H.DEFNS= -#define R_ZIPCTRL @$.ZIP_ADDRESS -#define R_ZIPDATA @$.ZIP_DBGDATA #define BAUDRATE @$[%d](BAUDRATE) @RTL.MAKE.GROUP= WBUBUS @RTL.MAKE.SUBD=wbubus diff --git a/auto-data/buserr.txt b/auto-data/buserr.txt index 129351a..17afc2e 100644 --- a/auto-data/buserr.txt +++ b/auto-data/buserr.txt @@ -1,7 +1,7 @@ ################################################################################ ## ## Filename: buserr.txt -## +## {{{ ## Project: AutoFPGA, a utility for composing FPGA designs from peripherals ## ## Purpose: Provide a readable memory location containing the address of the @@ -11,9 +11,9 @@ ## Gisselquist Technology, LLC ## ################################################################################ -## -## Copyright (C) 2017-2020, Gisselquist Technology, LLC -## +## }}} +## Copyright (C) 2017-2021, Gisselquist Technology, LLC +## {{{ ## This program is free software (firmware): 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 @@ -28,14 +28,14 @@ ## with this program. (It's in the $(ROOT)/doc directory. Run make with no ## target there if the PDF file isn't present.) If not, see ## for a copy. -## +## }}} ## License: GPL, v3, as defined and found on www.gnu.org, +## {{{ ## http://www.gnu.org/licenses/gpl.html ## -## ################################################################################ ## -## +## }}} @PREFIX=buserr @NADDR=1 @SLAVE.TYPE=SINGLE diff --git a/auto-data/clock.txt b/auto-data/clock.txt index 52d313c..0c567c4 100644 --- a/auto-data/clock.txt +++ b/auto-data/clock.txt @@ -1,7 +1,7 @@ ################################################################################ ## ## Filename: clock.txt -## +## {{{ ## Project: AutoFPGA, a utility for composing FPGA designs from peripherals ## ## Purpose: @@ -10,9 +10,9 @@ ## Gisselquist Technology, LLC ## ################################################################################ -## -## Copyright (C) 2017-2020, Gisselquist Technology, LLC -## +## }}} +## Copyright (C) 2017-2021, Gisselquist Technology, LLC +## {{{ ## This program is free software (firmware): 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 @@ -27,14 +27,14 @@ ## with this program. (It's in the $(ROOT)/doc directory. Run make with no ## target there if the PDF file isn't present.) If not, see ## for a copy. -## +## }}} ## License: GPL, v3, as defined and found on www.gnu.org, +## {{{ ## http://www.gnu.org/licenses/gpl.html ## -## ################################################################################ ## -## +## }}} @PREFIX=clk @CLOCK.NAME=clk @CLOCK.TOP=i_clk diff --git a/auto-data/flash.txt b/auto-data/flash.txt index 4337184..21f1d44 100644 --- a/auto-data/flash.txt +++ b/auto-data/flash.txt @@ -1,7 +1,7 @@ ################################################################################ ## ## Filename: flash.txt -## +## {{{ ## Project: AutoFPGA, a utility for composing FPGA designs from peripherals ## ## Purpose: Describes the flash in our new data format. @@ -10,9 +10,9 @@ ## Gisselquist Technology, LLC ## ################################################################################ -## -## Copyright (C) 2017-2020, Gisselquist Technology, LLC -## +## }}} +## Copyright (C) 2017-2021, Gisselquist Technology, LLC +## {{{ ## This program is free software (firmware): 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 @@ -27,14 +27,14 @@ ## with this program. (It's in the $(ROOT)/doc directory. Run make with no ## target there if the PDF file isn't present.) If not, see ## for a copy. -## +## }}} ## License: GPL, v3, as defined and found on www.gnu.org, +## {{{ ## http://www.gnu.org/licenses/gpl.html ## -## ################################################################################ ## -## +## }}} @PREFIX=flash @DEVID=FLASH @ACCESS=@$(DEVID)_ACCESS diff --git a/auto-data/global.txt b/auto-data/global.txt index a325189..9cffc1c 100644 --- a/auto-data/global.txt +++ b/auto-data/global.txt @@ -1,7 +1,7 @@ ################################################################################ ## ## Filename: global.txt -## +## {{{ ## Project: ZBasic, a generic toplevel impl using the full ZipCPU ## ## Purpose: Capture any global configuration parameters @@ -10,9 +10,9 @@ ## Gisselquist Technology, LLC ## ################################################################################ -## -## Copyright (C) 2015-2020, Gisselquist Technology, LLC -## +## }}} +## Copyright (C) 2015-2021, Gisselquist Technology, LLC +## {{{ ## This program is free software (firmware): 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 @@ -27,14 +27,14 @@ ## with this program. (It's in the $(ROOT)/doc directory. Run make with no ## target there if the PDF file isn't present.) If not, see ## for a copy. -## +## }}} ## License: GPL, v3, as defined and found on www.gnu.org, +## {{{ ## http://www.gnu.org/licenses/gpl.html ## -## ################################################################################ ## -## +## }}} @LEGAL=legalgen.txt @PROJECT=ZBasic, a generic toplevel implementation using the full ZipCPU # @XDC.FILE=nexysv.xdc @@ -75,14 +75,6 @@ unsigned addrdecode(const char *v) { for(int i=0; i for a copy. -## +## }}} ## License: GPL, v3, as defined and found on www.gnu.org, +## {{{ ## http://www.gnu.org/licenses/gpl.html ## -## ################################################################################ ## -## +## }}} @PREFIX=gpio @DEVID=GPIO @NADDR=1 diff --git a/auto-data/legalgen.txt b/auto-data/legalgen.txt index fc11766..316f027 100644 --- a/auto-data/legalgen.txt +++ b/auto-data/legalgen.txt @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // DO NOT EDIT THIS FILE! @@ -14,9 +14,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2017-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2017-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -31,11 +31,11 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} diff --git a/auto-data/mem_bkram_only.txt b/auto-data/mem_bkram_only.txt index bfcfca0..bff07b5 100644 --- a/auto-data/mem_bkram_only.txt +++ b/auto-data/mem_bkram_only.txt @@ -1,7 +1,7 @@ ################################################################################ ## ## Filename: mem_flash_bkram.txt -## +## {{{ ## Project: ZBasic, a generic toplevel impl using the full ZipCPU ## ## Purpose: Describes a memory model containing nothing more than flash @@ -13,9 +13,9 @@ ## Gisselquist Technology, LLC ## ################################################################################ -## -## Copyright (C) 2017-2020, Gisselquist Technology, LLC -## +## }}} +## Copyright (C) 2017-2021, Gisselquist Technology, LLC +## {{{ ## This program is free software (firmware): 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 @@ -30,15 +30,14 @@ ## with this program. (It's in the $(ROOT)/doc directory. Run make with no ## target there if the PDF file isn't present.) If not, see ## for a copy. -## +## }}} ## License: GPL, v3, as defined and found on www.gnu.org, +## {{{ ## http://www.gnu.org/licenses/gpl.html ## -## ################################################################################ ## -## -## +## }}} @PREFIX=mem_bkram_only @MASTER.TYPE=SCRIPT @MASTER.BUS=wb diff --git a/auto-data/mem_flash_bkram.txt b/auto-data/mem_flash_bkram.txt index 19b3764..77bc661 100644 --- a/auto-data/mem_flash_bkram.txt +++ b/auto-data/mem_flash_bkram.txt @@ -1,7 +1,7 @@ ################################################################################ ## ## Filename: mem_flash_bkram.txt -## +## {{{ ## Project: ZBasic, a generic toplevel impl using the full ZipCPU ## ## Purpose: Describes a memory model containing nothing more than flash @@ -13,9 +13,9 @@ ## Gisselquist Technology, LLC ## ################################################################################ -## +## }}} ## Copyright (C) 2017-2020, Gisselquist Technology, LLC -## +## {{{ ## This program is free software (firmware): 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 @@ -30,15 +30,14 @@ ## with this program. (It's in the $(ROOT)/doc directory. Run make with no ## target there if the PDF file isn't present.) If not, see ## for a copy. -## +## }}} ## License: GPL, v3, as defined and found on www.gnu.org, +## {{{ ## http://www.gnu.org/licenses/gpl.html ## -## ################################################################################ ## -## -## +## }}} @PREFIX=mem_flash_bkram @MASTER.TYPE=SCRIPT @MASTER.BUS=wb diff --git a/auto-data/pic.txt b/auto-data/pic.txt index aab341d..eab670c 100644 --- a/auto-data/pic.txt +++ b/auto-data/pic.txt @@ -1,7 +1,7 @@ ################################################################################ ## ## Filename: pic.txt -## +## {{{ ## Project: AutoFPGA, a utility for composing FPGA designs from peripherals ## ## Purpose: @@ -10,9 +10,9 @@ ## Gisselquist Technology, LLC ## ################################################################################ -## -## Copyright (C) 2017-2020, Gisselquist Technology, LLC -## +## }}} +## Copyright (C) 2017-2021, Gisselquist Technology, LLC +## {{{ ## This program is free software (firmware): 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 @@ -27,14 +27,14 @@ ## with this program. (It's in the $(ROOT)/doc directory. Run make with no ## target there if the PDF file isn't present.) If not, see ## for a copy. -## +## }}} ## License: GPL, v3, as defined and found on www.gnu.org, +## {{{ ## http://www.gnu.org/licenses/gpl.html ## -## ################################################################################ ## -## +## }}} @PREFIX=buspic @DEVID=BUSPIC @NADDR=1 diff --git a/auto-data/pwrcount.txt b/auto-data/pwrcount.txt index 81e2bb0..f10e654 100644 --- a/auto-data/pwrcount.txt +++ b/auto-data/pwrcount.txt @@ -1,7 +1,7 @@ ################################################################################ ## ## Filename: pwrcount.txt -## +## {{{ ## Project: AutoFPGA, a utility for composing FPGA designs from peripherals ## ## Purpose: @@ -10,9 +10,9 @@ ## Gisselquist Technology, LLC ## ################################################################################ -## -## Copyright (C) 2017-2020, Gisselquist Technology, LLC -## +## }}} +## Copyright (C) 2017-2021, Gisselquist Technology, LLC +## {{{ ## This program is free software (firmware): 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 @@ -27,14 +27,14 @@ ## with this program. (It's in the $(ROOT)/doc directory. Run make with no ## target there if the PDF file isn't present.) If not, see ## for a copy. -## +## }}} ## License: GPL, v3, as defined and found on www.gnu.org, +## {{{ ## http://www.gnu.org/licenses/gpl.html ## -## ################################################################################ ## -## +## }}} @PREFIX=pwrcount @NADDR=1 @ACCESS=PWRCOUNT_ACCESS diff --git a/auto-data/rtcdate.txt b/auto-data/rtcdate.txt index 9e9acb0..eed5245 100644 --- a/auto-data/rtcdate.txt +++ b/auto-data/rtcdate.txt @@ -1,7 +1,7 @@ ################################################################################ ## ## Filename: rtcdate.txt -## +## {{{ ## Project: AutoFPGA, a utility for composing FPGA designs from peripherals ## ## Purpose: @@ -10,9 +10,9 @@ ## Gisselquist Technology, LLC ## ################################################################################ -## -## Copyright (C) 2017-2020, Gisselquist Technology, LLC -## +## }}} +## Copyright (C) 2017-2021, Gisselquist Technology, LLC +## {{{ ## This program is free software (firmware): 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 @@ -27,14 +27,14 @@ ## with this program. (It's in the $(ROOT)/doc directory. Run make with no ## target there if the PDF file isn't present.) If not, see ## for a copy. -## +## }}} ## License: GPL, v3, as defined and found on www.gnu.org, +## {{{ ## http://www.gnu.org/licenses/gpl.html ## -## ################################################################################ ## -## +## }}} @PREFIX=rtcdate @DEVID=RTCDATE @NADDR=1 diff --git a/auto-data/rtclight.txt b/auto-data/rtclight.txt index 1e587e6..0a81c2a 100644 --- a/auto-data/rtclight.txt +++ b/auto-data/rtclight.txt @@ -1,7 +1,7 @@ ################################################################################ ## ## Filename: rtclight.txt -## +## {{{ ## Project: AutoFPGA, a utility for composing FPGA designs from peripherals ## ## Purpose: @@ -10,9 +10,9 @@ ## Gisselquist Technology, LLC ## ################################################################################ -## -## Copyright (C) 2017-2020, Gisselquist Technology, LLC -## +## }}} +## Copyright (C) 2017-2021, Gisselquist Technology, LLC +## {{{ ## This program is free software (firmware): 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 @@ -27,14 +27,14 @@ ## with this program. (It's in the $(ROOT)/doc directory. Run make with no ## target there if the PDF file isn't present.) If not, see ## for a copy. -## +## }}} ## License: GPL, v3, as defined and found on www.gnu.org, +## {{{ ## http://www.gnu.org/licenses/gpl.html ## -## ################################################################################ ## -## +## }}} @PREFIX=rtc @DEVID=RTC @NADDR=8 diff --git a/auto-data/sdspi.txt b/auto-data/sdspi.txt index 8feef11..205a7a8 100644 --- a/auto-data/sdspi.txt +++ b/auto-data/sdspi.txt @@ -1,7 +1,7 @@ ################################################################################ ## ## Filename: sdspi.txt -## +## {{{ ## Project: AutoFPGA, a utility for composing FPGA designs from peripherals ## ## Purpose: Describes how to connect an SD-SPI peripheral to a wishbone @@ -17,9 +17,9 @@ ## Gisselquist Technology, LLC ## ################################################################################ -## -## Copyright (C) 2017-2020, Gisselquist Technology, LLC -## +## }}} +## Copyright (C) 2017-2021, Gisselquist Technology, LLC +## {{{ ## This program is free software (firmware): 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 @@ -34,14 +34,14 @@ ## with this program. (It's in the $(ROOT)/doc directory. Run make with no ## target there if the PDF file isn't present.) If not, see ## for a copy. -## +## }}} ## License: GPL, v3, as defined and found on www.gnu.org, +## {{{ ## http://www.gnu.org/licenses/gpl.html ## -## ################################################################################ ## -## +## }}} @PREFIX=sdcard @DEVID=SDSPI @NADDR=4 @@ -92,7 +92,7 @@ IOBUF sd_cmd_buf(.T(1'b0),.O(i_sd_cmd), .I(w_sd_cmd), .IO(io_sd_cmd)); IOBUF sd_dat3_bf(.T(1'b0),.O(i_sd[3]),.I(w_sd_data[3]),.IO(io_sd[3])); - + @MAIN.PORTLIST= // The SD-Card wires diff --git a/auto-data/simtrace.txt b/auto-data/simtrace.txt index f651349..6ab9c3a 100644 --- a/auto-data/simtrace.txt +++ b/auto-data/simtrace.txt @@ -1,7 +1,7 @@ ################################################################################ ## ## Filename: simtrace.c -## +## {{{ ## Project: AutoFPGA, a utility for composing FPGA designs from peripherals ## ## Purpose: Creates a GPIO output port for the Verilator simulation, @@ -11,9 +11,9 @@ ## Gisselquist Technology, LLC ## ################################################################################ -## -## Copyright (C) 2018-2020, Gisselquist Technology, LLC -## +## }}} +## Copyright (C) 2018-2021, Gisselquist Technology, LLC +## {{{ ## This program is free software (firmware): 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 @@ -28,14 +28,14 @@ ## with this program. (It's in the $(ROOT)/doc directory. Run make with no ## target there if the PDF file isn't present.) If not, see ## for a copy. -## +## }}} ## License: GPL, v3, as defined and found on www.gnu.org, +## {{{ ## http://www.gnu.org/licenses/gpl.html ## -## ################################################################################ ## -## +## }}} @PREFIX=simtrace @DEVID=TRACE @NADDR=4 diff --git a/auto-data/version.txt b/auto-data/version.txt index 5264d2b..760d15a 100644 --- a/auto-data/version.txt +++ b/auto-data/version.txt @@ -1,7 +1,7 @@ ################################################################################ ## ## Filename: version.txt -## +## {{{ ## Project: AutoFPGA, a utility for composing FPGA designs from peripherals ## ## Purpose: @@ -10,9 +10,9 @@ ## Gisselquist Technology, LLC ## ################################################################################ -## -## Copyright (C) 2017-2020, Gisselquist Technology, LLC -## +## }}} +## Copyright (C) 2017-2021, Gisselquist Technology, LLC +## {{{ ## This program is free software (firmware): 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 @@ -27,14 +27,14 @@ ## with this program. (It's in the $(ROOT)/doc directory. Run make with no ## target there if the PDF file isn't present.) If not, see ## for a copy. -## +## }}} ## License: GPL, v3, as defined and found on www.gnu.org, +## {{{ ## http://www.gnu.org/licenses/gpl.html ## -## ################################################################################ ## -## +## }}} @PREFIX=version @DEVID=VERSION @ACCESS=VERSION_ACCESS diff --git a/auto-data/wbuart.txt b/auto-data/wbuart.txt index 9fc2fa3..62c821b 100644 --- a/auto-data/wbuart.txt +++ b/auto-data/wbuart.txt @@ -1,7 +1,7 @@ ################################################################################ ## ## Filename: wbuart.txt -## +## {{{ ## Project: AutoFPGA, a utility for composing FPGA designs from peripherals ## ## Purpose: To describe a UART for autogen to work with. @@ -10,9 +10,9 @@ ## Gisselquist Technology, LLC ## ################################################################################ -## -## Copyright (C) 2017-2020, Gisselquist Technology, LLC -## +## }}} +## Copyright (C) 2017-2021, Gisselquist Technology, LLC +## {{{ ## This program is free software (firmware): 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 @@ -27,14 +27,15 @@ ## with this program. (It's in the $(ROOT)/doc directory. Run make with no ## target there if the PDF file isn't present.) If not, see ## for a copy. -## +## }}} ## License: GPL, v3, as defined and found on www.gnu.org, +## {{{ ## http://www.gnu.org/licenses/gpl.html ## ## ################################################################################ ## -## +## }}} # The prefix is used to create a series of bus data lines for interaction with # the bus. In this case, these will be uart_sel, uart_stall, uart_ack, and # uart_data. diff --git a/auto-data/zipmaster.txt b/auto-data/zipmaster.txt index d25e94b..2c3d2c9 100644 --- a/auto-data/zipmaster.txt +++ b/auto-data/zipmaster.txt @@ -1,7 +1,7 @@ ################################################################################ ## ## Filename: zipmaster.txt -## +## {{{ ## Project: AutoFPGA, a utility for composing FPGA designs from peripherals ## ## Purpose: To describe what needs to be done to make the ZipCPU a part @@ -13,9 +13,9 @@ ## Gisselquist Technology, LLC ## ################################################################################ -## -## Copyright (C) 2017-2020, Gisselquist Technology, LLC -## +## }}} +## Copyright (C) 2017-2021, Gisselquist Technology, LLC +## {{{ ## This program is free software (firmware): 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 @@ -30,17 +30,17 @@ ## with this program. (It's in the $(ROOT)/doc directory. Run make with no ## target there if the PDF file isn't present.) If not, see ## for a copy. -## +## }}} ## License: GPL, v3, as defined and found on www.gnu.org, +## {{{ ## http://www.gnu.org/licenses/gpl.html ## -## ################################################################################ ## ## ## Define @SYSPIC so that other peripherals needing to be on the ZipSystem's ## PIC know the name of the PIC we are using. Note that this is a global. -## +## }}} @SYSPIC= syspic @PREFIX=zip @SIM.CLOCK=clk @@ -106,19 +106,26 @@ // // assign zip_int_vector = { alt_int_vector[14:8], sys_int_vector[14:6] }; - zipsystem #(.RESET_ADDRESS(RESET_ADDRESS), - .ADDRESS_WIDTH(ZIP_ADDRESS_WIDTH), - .LGICACHE(@$(LGICACHE)),.LGDCACHE(@$(LGDCACHE)), - .START_HALTED(ZIP_START_HALTED), - .RESET_DURATION(20), - .EXTERNAL_INTERRUPTS(ZIP_INTS)) - swic(i_clk, (i_reset)||(@$(CPURESET)), + zipsystem #( + // {{{ + .RESET_ADDRESS(RESET_ADDRESS), + .ADDRESS_WIDTH(ZIP_ADDRESS_WIDTH), + .LGICACHE(@$(LGICACHE)),.LGDCACHE(@$(LGDCACHE)), + .START_HALTED(ZIP_START_HALTED), + .RESET_DURATION(20), + .EXTERNAL_INTERRUPTS(ZIP_INTS) + // }}} + ) swic( + // {{{ + i_clk, (i_reset)||(@$(CPURESET)), // Zippys wishbone interface @$(MASTER.PORTLIST), zip_int_vector, zip_cpu_int, // Debug wishbone interface @$(SLAVE.PORTLIST), - zip_debug); + zip_debug + // }}} + ); assign zip_trigger = zip_debug[31]; @BDEF.INCLUDE= #include @@ -169,7 +176,7 @@ #endif #endif -#define CPUVAR(A) VVAR(_swic__DOT__thecpu__DOT_ ## A) +#define CPUVAR(A) VVAR(_swic__DOT__thecpu__DOT__core__DOT_ ## A) #define cpu_reset VVAR(_swic__DOT__cmd_reset) #define cpu_break VVAR(_swic__DOT__cpu_break) @@ -412,16 +419,55 @@ ## ## @RTL.MAKE.GROUP=ZIPCPU -@RTL.MAKE.FILES= zipcpu.v cpuops.v pfcache.v pipemem.v pfcache.v idecode.v - wbpriarbiter.v zipsystem.v zipcounter.v zipjiffies.v ziptimer.v - wbdmac.v icontrol.v wbwatchdog.v busdelay.v cpudefs.v +@RTL.MAKE.FILES= zipsystem.v zipcore.v zipwb.v cpuops.v pfcache.v pipemem.v + pfcache.v idecode.v wbpriarbiter.v zipsystem.v zipcounter.v + zipjiffies.v ziptimer.v wbdmac.v icontrol.v wbwatchdog.v + busdelay.v cpudefs.v @RTL.MAKE.SUBD= cpu ## ## @PREFIX=zip_dbg @SLAVE.TYPE=OTHER @SLAVE.BUS=wbu @SLAVE.ORDER=1000000 -@NADDR=2 +@NADDR=128 +@REGS.N=36 +@REGS.NOTE=// ZipCPU control/debug registers +@REGS.0=32 R_ZIPCTRL CPU ZIPCTRL +@REGS.1=0 R_ZIPREGS ZIPREGS +@REGS.2=0 R_ZIPS0 SR0 +@REGS.3=1 R_ZIPS1 SR1 +@REGS.4=2 R_ZIPS2 SR2 +@REGS.5=3 R_ZIPS3 SR3 +@REGS.6=4 R_ZIPS4 SR4 +@REGS.7=5 R_ZIPS5 SR5 +@REGS.8=6 R_ZIPS6 SR6 +@REGS.9=7 R_ZIPS7 SR7 +@REGS.10=8 R_ZIPS8 SR8 +@REGS.11=9 R_ZIPS9 SR9 +@REGS.12=10 R_ZIPS10 SR10 +@REGS.13=11 R_ZIPS11 SR11 +@REGS.14=12 R_ZIPS12 SR12 +@REGS.15=13 R_ZIPSSP SSP SR13 +@REGS.16=14 R_ZIPCC ZIPCC CC SCC SR14 +@REGS.17=15 R_ZIPPC ZIPPC PC SPC SR15 +@REGS.18=16 R_ZIPUSER ZIPUSER +@REGS.19=16 R_ZIPU0 UR0 +@REGS.20=17 R_ZIPU1 UR1 +@REGS.21=18 R_ZIPU2 UR2 +@REGS.22=19 R_ZIPU3 UR3 +@REGS.23=20 R_ZIPU4 UR4 +@REGS.24=21 R_ZIPU5 UR5 +@REGS.25=22 R_ZIPU6 UR6 +@REGS.26=23 R_ZIPU7 UR7 +@REGS.27=24 R_ZIPU8 UR8 +@REGS.28=25 R_ZIPU9 UR9 +@REGS.29=26 R_ZIPU10 SR10 +@REGS.30=27 R_ZIPU11 SR11 +@REGS.31=28 R_ZIPU12 SR12 +@REGS.32=29 R_ZIPUSP USP UR13 +@REGS.33=30 R_ZIPUCC ZIPUCC UCC +@REGS.34=31 R_ZIPUPC ZIPUPC UPC +@REGS.35=64 R_ZIPSYSTEM ZIPSYSTEM ZIPSYS ## ## @PREFIX=syspic diff --git a/doc/20210524-gcc-10-cpu-test.png b/doc/20210524-gcc-10-cpu-test.png new file mode 100644 index 0000000000000000000000000000000000000000..d5870023dd1a2131a27aefa2f1f1d92e0b28dd16 GIT binary patch literal 225572 zcmV({K+?a7P) zaB^>EX>4U6ba`-PAZ2)IW&i+q+O3>vl3O{lrT=3UwFJz=asW7B_IA+A@9%(=O3JC~ zS$8U>h+vSHxPbc^91gnkfBxsXfBoxU!Kc<;F0I#5tLMKw@`#gfy8rw)-oL@;_wVPw z@_y3Kz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oaT)%dANO$_kntexvb*0u^qacj8ilT8m&)nYfi_Xv;IjT_97v^Wy< zHLS$W2j5?VpKf<-f-mm}w3|K-$NEzVL*HClv zXkV7KsI^cEc@5n_O$rW7&h)x@0_eTEM=B8raFFBc527ve%yj88&Yyf-rri7AMz1lJ zy)pmgOKt$+pdBe}{^iSt>SFXugkvCpK5+c}5}bUkIS9^aQ(X~|7yo)dLd;xH*1(^& z_SnTiE^x23^f!;G-lz@NBOs8GH}C$LN;ehkG!pRG=PJ{hSieC`1l7#ox8T$WK1%3VEBE^3YL7!dL>xp3xOS$R&OA~G{OJ~mL7m;4qA0)IGrHC>Cr@CUz! zvdR~Vc!^8XSZQuh;Esu8EKXSFllpiC4=ew9AjFP^;b_7A%0tTsp5-MQcO=Yiz5H-c z*2Yiu!$AA596q^s?z6esrCy~&6}2jyg8erc=x~b9`Zs;YUG@z350B&=$`Dls0Qw^# MDl1Y7{NnrH0IkxEQUCw| literal 0 HcmV?d00001 diff --git a/mkdatev.pl b/mkdatev.pl index 11b19a2..2792d10 100755 --- a/mkdatev.pl +++ b/mkdatev.pl @@ -2,7 +2,7 @@ ################################################################################ ## ## Filename: mkdatev.pl -## +## {{{ ## Project: ZBasic, a generic toplevel impl using the full ZipCPU ## ## Purpose: This file creates a file containing a `define DATESTAMP @@ -13,9 +13,9 @@ ## Gisselquist Technology, LLC ## ################################################################################ -## -## Copyright (C) 2015-2020, Gisselquist Technology, LLC -## +## }}} +## Copyright (C) 2015-2021, Gisselquist Technology, LLC +## {{{ ## This program is free software (firmware): 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 @@ -30,14 +30,14 @@ ## with this program. (It's in the $(ROOT)/doc directory. Run make with no ## target there if the PDF file isn't present.) If not, see ## for a copy. -## +## }}} ## License: GPL, v3, as defined and found on www.gnu.org, +## {{{ ## http://www.gnu.org/licenses/gpl.html ## -## ################################################################################ ## -## +## }}} $now = time; ($sc,$mn,$nhr,$ndy,$nmo,$nyr,$nwday,$nyday,$nisdst) = localtime($now); @@ -50,7 +50,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: builddate.v -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: This file records the date of the last build. Running "make" @@ -62,9 +62,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -79,14 +79,14 @@ // with this program. (It's in the \$(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} `ifndef DATESTAMP EOM diff --git a/rtl/Makefile b/rtl/Makefile index c78611c..2b80607 100644 --- a/rtl/Makefile +++ b/rtl/Makefile @@ -1,7 +1,7 @@ ################################################################################ ## ## Filename: rtl/Makefile -## +## {{{ ## Project: ZBasic, a generic toplevel impl using the full ZipCPU ## ## Purpose: To direct the Verilator build of the SoC sources. The result @@ -13,9 +13,9 @@ ## Gisselquist Technology, LLC ## ################################################################################ -## -## Copyright (C) 2015-2020, Gisselquist Technology, LLC -## +## }}} +## Copyright (C) 2015-2021, Gisselquist Technology, LLC +## {{{ ## This program is free software (firmware): 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 @@ -30,14 +30,14 @@ ## with this program. (It's in the $(ROOT)/doc directory. Run make with no ## target there if the PDF file isn't present.) If not, see ## for a copy. -## +## }}} ## License: GPL, v3, as defined and found on www.gnu.org, +## {{{ ## http://www.gnu.org/licenses/gpl.html ## -## ################################################################################ ## -## +## }}} all: test cpudefs.h design.h YYMMDD=`date +%Y%m%d` CXX := g++ diff --git a/rtl/builddate.v b/rtl/builddate.v index 8ee3720..9fd10ee 100644 --- a/rtl/builddate.v +++ b/rtl/builddate.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: builddate.v -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: This file records the date of the last build. Running "make" @@ -13,9 +13,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -30,16 +30,16 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} `ifndef DATESTAMP -`define DATESTAMP 32'h20201028 -`define BUILDTIME 32'h00184458 +`define DATESTAMP 32'h20210524 +`define BUILDTIME 32'h00063746 `endif // diff --git a/rtl/cpu/axidcache.v b/rtl/cpu/axidcache.v new file mode 100644 index 0000000..4a1df9d --- /dev/null +++ b/rtl/cpu/axidcache.v @@ -0,0 +1,928 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Filename: axidcache.v +// {{{ +// Project: Zip CPU -- a small, lightweight, RISC CPU soft core +// +// Purpose: A data cache built using AXI as the underlying protocol +// +// +// Creator: Dan Gisselquist, Ph.D. +// Gisselquist Technology, LLC +// +//////////////////////////////////////////////////////////////////////////////// +// }}} +// Copyright (C) 2020-2021, Gisselquist Technology, LLC +// {{{ +// This program is free software (firmware): 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 MERCHANTIBILITY 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. (It's in the $(ROOT)/doc directory. Run make with no +// target there if the PDF file isn't present.) If not, see +// for a copy. +// }}} +// License: GPL, v3, as defined and found on www.gnu.org, +// {{{ +// http://www.gnu.org/licenses/gpl.html +// +// +//////////////////////////////////////////////////////////////////////////////// +// +// +`default_nettype none +// }}} +module axidcache #( + // {{{ + // AXI Setup: address width, data width, ID width, and ID + // {{{ + parameter C_AXI_ADDR_WIDTH = 32, + parameter C_AXI_DATA_WIDTH = 64, + parameter C_AXI_ID_WIDTH = 1, + parameter [C_AXI_ID_WIDTH-1:0] AXI_ID = 0, + // }}} + // LGCACHELEN + // {{{ + // The log (base 2) of the cache size in bytes. + parameter LGCACHELEN = 8 + $clog2(C_AXI_DATA_WIDTH/8), + localparam LGCACHEWORDS= LGCACHELEN-$clog2(C_AXI_DATA_WIDTH/8), + // }}} + // LGNLINES + // {{{ + // The log (base 2) of the number of cache lines. A cache line + // is the minimum amount of data read on a miss. Each cache + // line has a valid signal and a tag associated with it. + parameter LGNLINES = (LGCACHEWORDS-3), + // }}} + parameter NAUX = 5, + // Verilator lint_off UNUSED + localparam LGPIPE = 2, + parameter [0:0] OPT_PIPE = 1'b0, + // Verilator lint_on UNUSED + parameter [0:0] OPT_LOWPOWER = 1'b0, + // Local parameters, mostly abbreviations + // {{{ + // Verilator lint_off UNUSED + localparam [0:0] OPT_LOCK = 1'b0, + // Verilator lint_on UNUSED + localparam [0:0] OPT_DUAL_READ_PORT = 1'b1, + localparam [1:0] DC_IDLE = 2'b00, + DC_WRITE = 2'b01, + DC_READS = 2'b10, + DC_READC = 2'b11, + localparam AW = C_AXI_ADDR_WIDTH, + localparam DW = C_AXI_DATA_WIDTH, + localparam IW = C_AXI_ID_WIDTH, + localparam AXILSB = $clog2(C_AXI_DATA_WIDTH/8), + localparam CS = LGCACHELEN - AXILSB, // Cache size, in wrds + localparam LS = CS-LGNLINES, // Cache lines, lg_2 + localparam TW = AW-(CS+AXILSB) // Tag width + // }}} + // }}} + ) ( + // {{{ + input wire S_AXI_ACLK, S_AXI_ARESETN, + input wire i_cpu_reset, i_clear, + // Interface from the CPU + // {{{ + input wire i_pipe_stb, i_lock, + input wire [2:0] i_op, + input wire [AW-1:0] i_addr, + input wire [31:0] i_data, + input wire [NAUX-1:0] i_oreg, + // Outputs, going back to the CPU + output reg o_busy, o_rdbusy, + output reg o_pipe_stalled, + output reg o_valid, o_err, + output reg [NAUX-1:0] o_wreg, + output reg [31:0] o_data, + // }}} + // AXI bus interface + // {{{ + // Write address + // {{{ + output wire M_AXI_AWVALID, + input wire M_AXI_AWREADY, + output wire [IW-1:0] M_AXI_AWID, + output wire [AW-1:0] M_AXI_AWADDR, + output wire [7:0] M_AXI_AWLEN, + output wire [2:0] M_AXI_AWSIZE, + output wire [1:0] M_AXI_AWBURST, + output wire M_AXI_AWLOCK, + output wire [3:0] M_AXI_AWCACHE, + output wire [2:0] M_AXI_AWPROT, + output wire [3:0] M_AXI_AWQOS, + // }}} + // Write data + // {{{ + output wire M_AXI_WVALID, + input wire M_AXI_WREADY, + output wire [DW-1:0] M_AXI_WDATA, + output wire [DW/8-1:0] M_AXI_WSTRB, + output wire M_AXI_WLAST, + // }}} + // Write return + // {{{ + input wire M_AXI_BVALID, + output wire M_AXI_BREADY, + input wire [IW-1:0] M_AXI_BID, + input wire [1:0] M_AXI_BRESP, + // }}} + // Read address + // {{{ + output wire M_AXI_ARVALID, + input wire M_AXI_ARREADY, + output wire [IW-1:0] M_AXI_ARID, + output wire [AW-1:0] M_AXI_ARADDR, + output wire [7:0] M_AXI_ARLEN, + output wire [2:0] M_AXI_ARSIZE, + output wire [1:0] M_AXI_ARBURST, + output wire M_AXI_ARLOCK, + output wire [3:0] M_AXI_ARCACHE, + output wire [2:0] M_AXI_ARPROT, + output wire [3:0] M_AXI_ARQOS, + // }}} + // Read data returned + // {{{ + input wire M_AXI_RVALID, + output wire M_AXI_RREADY, + input wire [IW-1:0] M_AXI_RID, + input wire [DW-1:0] M_AXI_RDATA, + input wire M_AXI_RLAST, + input wire [1:0] M_AXI_RRESP + // }}} + // }}} + // }}} + ); + + // Declarations + // {{{ + + // The cache itself + // {{{ + reg [(1<<(CS-LS))-1:0] cache_valid; + reg [TW-1:0] cache_tag [0:(1<> (8*req_data[AXILSB-1:0]); + + // o_data + always @(posedge S_AXI_ACLK) + begin + o_data <= shifted_data[31:0]; + casez(req_data[AXILSB +: 2]) + 2'b10: o_data[31:16] <= 0; + 2'b11: o_data[31: 8] <= 0; + default: begin end + endcase + end + // }}} + + // o_valid + // {{{ + initial o_valid = 1'b0; + always @(posedge S_AXI_ACLK) + if (i_cpu_reset || flushing) + o_valid <= 1'b0; + else if (state == DC_READS) + o_valid <= M_AXI_RVALID && !M_AXI_RRESP[1]; + else + o_valid <= r_svalid || r_dvalid; + // }}} + + // Make Verilator happy + // {{{ + // Verilator lint_off UNUSED + wire unused; + assign unused = &{ 1'b0, M_AXI_BID, M_AXI_RID, r_addr, M_AXI_RRESP[0], + M_AXI_BRESP[0], i_lock, OPT_PIPE, + shifted_data }; + // Verilator lint_on UNUSED + // }}} +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal properties +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +`ifdef FORMAL +// Formal properties for this core are maintained elsewhere +`endif +// }}} +endmodule diff --git a/rtl/cpu/axiicache.v b/rtl/cpu/axiicache.v new file mode 100644 index 0000000..d00c8d0 --- /dev/null +++ b/rtl/cpu/axiicache.v @@ -0,0 +1,587 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Filename: axiicache.v +// {{{ +// Project: Zip CPU -- a small, lightweight, RISC CPU soft core +// +// Purpose: An I-Cache, for when the CPU has an AXI interface. +// +// Goal: To return each instruction within a single clock tick. Jumps +// should only stall if they switch cache lines. +// +// This logic is driven by a couple realities: +// 1. It takes a clock to read from a block RAM address, and hence a clock +// to read from the cache. +// 2. It takes another clock to check that the tag matches +// +// Our goal will be to avoid this second check if at all possible. +// Hence, we'll test on the clock of any given request whether +// or not the request matches the last tag value, and on the next +// clock whether it new tag value (if it has changed). Hence, +// for anything found within the cache, there will be a one +// cycle delay on any branch. +// +// +// Address Words are separated into three components: +// [ Tag bits ] [ Cache line number ] [ Cache position w/in the line ] +// +// On any read from the cache, only the second two components are required. +// On any read from memory, the first two components will be fixed across +// the bus, and the third component will be adjusted from zero to its +// maximum value. +// +// +// Creator: Dan Gisselquist, Ph.D. +// Gisselquist Technology, LLC +// +//////////////////////////////////////////////////////////////////////////////// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ +// This program is free software (firmware): 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 MERCHANTIBILITY 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. (It's in the $(ROOT)/doc directory. Run make with no +// target there if the PDF file isn't present.) If not, see +// for a copy. +// }}} +// License: GPL, v3, as defined and found on www.gnu.org, +// {{{ +// http://www.gnu.org/licenses/gpl.html +// +// +//////////////////////////////////////////////////////////////////////////////// +// +// +`default_nettype none +// }}} +module axiicache #( + // {{{ + // LGCACHESZ is the log(based two) of the cache size *in bytes* + parameter LGCACHESZ = 14, + // + // LGLINESZ is the size of one cache line, represented in + // words + parameter LGLINESZ=3, + // + // LGWAYS is the number of cache "ways" + // parameter LGWAYS = 0, + // + parameter C_AXI_ID_WIDTH = 1, + parameter C_AXI_ADDR_WIDTH = 32, + parameter C_AXI_DATA_WIDTH = 32, + // + // SWAP_ENDIANNESS + parameter [0:0] SWAP_ENDIANNESS = 1'b0, + // + parameter INSN_WIDTH = 32, + parameter [C_AXI_ID_WIDTH-1:0] AXI_ID = 0, + localparam ADDRLSB = $clog2(C_AXI_DATA_WIDTH/8), + localparam LGINSN = $clog2(INSN_WIDTH/8), + // localparam INSN_PER_WORD = C_AXI_DATA_WIDTH/INSN_WIDTH, + localparam AW=C_AXI_ADDR_WIDTH, + localparam DW=C_AXI_DATA_WIDTH, + localparam LS=LGLINESZ, // Size of a cache line in words + LSB=LGLINESZ+ADDRLSB + // }}} + ) ( + // {{{ + input wire S_AXI_ACLK, + input wire S_AXI_ARESETN, + // + // The AXI Master (cache) interface + // {{{ + // An instruction cache only needs to support cache reads + output wire M_AXI_ARVALID, + input wire M_AXI_ARREADY, + output wire [C_AXI_ID_WIDTH-1:0] M_AXI_ARID, + output wire [C_AXI_ADDR_WIDTH-1:0] M_AXI_ARADDR, + output wire [7:0] M_AXI_ARLEN, + output wire [2:0] M_AXI_ARSIZE, + output wire [1:0] M_AXI_ARBURST, + output wire M_AXI_ARLOCK, + output wire [3:0] M_AXI_ARCACHE, + output wire [2:0] M_AXI_ARPROT, + output wire [3:0] M_AXI_ARQOS, + // + input wire M_AXI_RVALID, + output wire M_AXI_RREADY, + input wire [C_AXI_ID_WIDTH-1:0] M_AXI_RID, + input wire [C_AXI_DATA_WIDTH-1:0] M_AXI_RDATA, + input wire M_AXI_RLAST, + input wire [1:0] M_AXI_RRESP, + // }}} + // CPU interface + // {{{ + input wire i_cpu_reset, + input wire i_new_pc, + input wire i_clear_cache, + input wire i_ready, + input wire [AW-1:0] i_pc, + output reg [INSN_WIDTH-1:0] o_insn, + output reg [AW-1:0] o_pc, + output reg o_valid, + output reg o_illegal + // }}} +`ifdef DEPRECATED + output wire [AW-1:0] illegal_addr, + output wire [AW-LSB-1:0] bus_tag, + output wire [AW-LSB-1:0] o_tag, + output wire [AW-LSB-1:0] i_tag, + output wire [AW-LSB-1:0] lastpc_tag +`endif + // }}} + ); + + // Register/local parameter declarations + // {{{ + // localparam CACHELEN=(1<> (INSN_WIDTH * o_pc[ADDRLSB-1:LGINSN]); + o_insn = shifted[DW-1:0]; + end + end endgenerate + // }}} + + // o_pc + // {{{ + // Signal the CPU with the actual address of the value we are returning + // The ffetch properties will insure this value is correct. This CPU + // then uses it for knowing the program counter of the instruction + // contained within each stage of the pipeline + initial o_pc = 0; + always @(posedge S_AXI_ACLK) + if (i_new_pc) + o_pc <= i_pc; + else if (o_valid && i_ready) + begin + o_pc[AW-1:2] <= o_pc[AW-1:2]+1; + o_pc[1:0] <= 0; + end + // }}} + + // o_valid + // {{{ + // Are we returning a valid instruction to the CPU on this cycle? + initial o_valid = 0; + always @(posedge S_AXI_ACLK) + if (i_cpu_reset || i_clear_cache) + o_valid <= 0; + else if (o_valid && (i_ready || i_new_pc)) + begin + // Grab the next instruction--always ready on the same cycle + // if we stay within the same cache line + o_valid <= (i_pc[AW-1:LSB] == o_pc[AW-1:LSB]); + if (o_illegal) + o_valid <= 0; + if (!valid_line) + o_valid <= 0; + end else if (!o_valid && !i_new_pc) + begin + // We're stuck waiting for the cache line to become valid. + // Don't forget to check for the illegal flag. + o_valid <= valid_line; + if (illegal_valid && o_pc[AW-1:LSB] == illegal_tag) + o_valid <= 1; + end + // }}} + + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Handle bus errors here. + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // If a bus read request returns an error, then we'll mark the entire + // line as having a (valid) illegal value. Once the o_illegal value + // is set, it will remain set until either the CPU branches, or the + // cache is cleared. + // + + // illegal_tag, illegal_valid + // {{{ + // Here's the rule: if illegal_valid is true, then we know that address + // at that illegal_tag value will produce a bus error, and we can serve + // a bus error request response on any read request. + initial illegal_tag = 0; + initial illegal_valid = 0; + always @(posedge S_AXI_ACLK) + if ((i_cpu_reset)||(i_clear_cache)) + begin + illegal_tag <= 0; + illegal_valid <= 0; + end else if (M_AXI_RVALID && M_AXI_RRESP[1]) + begin + illegal_tag <= axi_araddr[AW-1:LSB]; + illegal_valid <= 1'b1; + end + // }}} + + // o_illegal + // {{{ + initial o_illegal = 1'b0; + always @(posedge S_AXI_ACLK) + if (i_cpu_reset || i_clear_cache || i_new_pc) + o_illegal <= 1'b0; + else if (o_valid && !o_illegal) + o_illegal <= 1'b0; + else if (illegal_valid && o_pc[AW-1:LSB] == illegal_tag) + o_illegal <= 1'b1; + // }}} + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Fixed/constant bus values, map registers to AXI wires/ etc. + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + // Fixed bus outputs: we read from the bus only, never write. + // Thus the output data is ... irrelevant and don't care. We set it + // to zero just to set it to something. + assign M_AXI_ARVALID= axi_arvalid; + assign M_AXI_ARID = AXI_ID; + assign M_AXI_ARADDR = axi_araddr; + assign M_AXI_ARLEN = (1< for a copy. +// +// License: GPL, v3, as defined and found on www.gnu.org, +// http://www.gnu.org/licenses/gpl.html +// +// +//////////////////////////////////////////////////////////////////////////////// +// +`default_nettype none +// }}} +module axilfetch #( + // {{{ + parameter C_AXI_ADDR_WIDTH = 32, + parameter C_AXI_DATA_WIDTH = 64, + parameter DATA_WIDTH=32, + parameter FETCH_LIMIT=16, + parameter [0:0] SWAP_ENDIANNESS = 1'b1, + localparam AW=C_AXI_ADDR_WIDTH + // }}} + ) ( + // {{{ + input wire S_AXI_ACLK, + input wire S_AXI_ARESETN, + // + // CPU interaction wires + // {{{ + input wire i_cpu_reset, + input wire i_new_pc, + input wire i_clear_cache, + input wire i_ready, + input wire [AW-1:0] i_pc, // Ignd unls i_new_pc + output wire [DATA_WIDTH-1:0] o_insn, // Insn read from bus + output reg [AW-1:0] o_pc, // Addr of that insn + output reg o_valid, // If valid + output reg o_illegal, // Bus error + // }}} + // AXI-lite bus interface + // {{{ + output reg M_AXI_ARVALID, + input wire M_AXI_ARREADY, + output reg [C_AXI_ADDR_WIDTH-1:0] M_AXI_ARADDR, + output wire [2:0] M_AXI_ARPROT, + // + input wire M_AXI_RVALID, + output wire M_AXI_RREADY, + input wire [C_AXI_DATA_WIDTH-1:0] M_AXI_RDATA, + input wire [1:0] M_AXI_RRESP + // }}} + // }}} + ); + + // Declarations + // {{{ + localparam AXILLSB = $clog2(C_AXI_DATA_WIDTH/8); + localparam INSNS_PER_WORD = C_AXI_DATA_WIDTH / DATA_WIDTH; + localparam LGDEPTH = $clog2(FETCH_LIMIT)+4; + localparam LGFIFO = $clog2(FETCH_LIMIT); + localparam W = LGDEPTH; + localparam FILLBITS = $clog2(INSNS_PER_WORD); + // ($clog2(INSNS_PER_WORD) > 0) + // ? $clog2(INSNS_PER_WORD) : 1); + + reg [W:0] new_flushcount, outstanding, + next_outstanding, flushcount; + reg flushing, flush_request, full_bus; + reg [((AXILLSB>2)?(AXILLSB-3):0):0] shift; + wire fifo_reset, fifo_wr, fifo_rd; + wire ign_fifo_full, fifo_empty; + wire [LGFIFO:0] ign_fifo_fill; + wire [C_AXI_DATA_WIDTH:0] fifo_data; + reg pending_new_pc; + reg [C_AXI_ADDR_WIDTH-1:0] pending_pc; + reg [W-1:0] fill; + reg [FILLBITS:0] out_fill; + reg [C_AXI_DATA_WIDTH-1:0] out_data; + reg [C_AXI_DATA_WIDTH-1:0] endian_swapped_rdata; + // }}} + + assign fifo_reset = i_cpu_reset || i_clear_cache || i_new_pc; + assign fifo_wr = M_AXI_RVALID && !flushing; + + + // ARPROT = 3'b100 for an unprivileged, secure instruction access + // (not sure what unprivileged or secure mean--even after reading the + // spec) + assign M_AXI_ARPROT = 3'b100; + + // next_outstanding + // {{{ + always @(*) + begin + next_outstanding = outstanding; + + case({ M_AXI_ARVALID && M_AXI_ARREADY, M_AXI_RVALID }) + 2'b10: next_outstanding = outstanding + 1; + 2'b01: next_outstanding = outstanding - 1; + default: begin end + endcase + end + // }}} + + // outstanding, full_bus + // {{{ + initial outstanding = 0; + initial full_bus = 0; + always @(posedge S_AXI_ACLK) + if (!S_AXI_ARESETN) + begin + outstanding <= 0; + full_bus <= 0; + end else begin + outstanding <= next_outstanding; + full_bus <= (next_outstanding + // + (((M_AXI_ARVALID && !M_AXI_ARREADY) ? 1:0) + >= (1< 0); + flush_request <= (M_AXI_ARVALID && !M_AXI_ARREADY); + end else begin + if (M_AXI_RVALID && flushcount > 0) + begin + flushcount <= flushcount - 1; + // Verilator lint_off CMPCONST + flushing <= (flushcount > 1); + // Verilator lint_on CMPCONST + end + + if (M_AXI_ARREADY) + flush_request <= 0; + end + // }}} + + // M_AXI_ARVALID + // {{{ + initial M_AXI_ARVALID = 1'b0; + always @(posedge S_AXI_ACLK) + if (!S_AXI_ARESETN) + M_AXI_ARVALID <= 1'b0; + else if (!M_AXI_ARVALID || M_AXI_ARREADY) + begin + M_AXI_ARVALID <= 1; + if (i_new_pc || pending_new_pc) + M_AXI_ARVALID <= 1'b1; + + // + // Throttle the number of requests we make + // Verilator lint_off CMPCONST + // out_fill will only capture 0 or 1 if DATA_WIDTH == 32 + if (fill + (M_AXI_ARVALID ? 1:0) + + ((o_valid &&(!i_ready || out_fill > 1)) ? 1:0) + >= FETCH_LIMIT) + M_AXI_ARVALID <= 1'b0; + // Verilator lint_on CMPCONST + if (i_cpu_reset || i_clear_cache || full_bus) + M_AXI_ARVALID <= 1'b0; + end + // }}} + + assign M_AXI_RREADY = 1'b1; + + // pending_new_pc + // {{{ + initial pending_new_pc = 0; + always @(posedge S_AXI_ACLK) + if (!S_AXI_ARESETN || i_clear_cache) + pending_new_pc <= 1'b0; + else if (!M_AXI_ARVALID || M_AXI_ARREADY) + pending_new_pc <= 1'b0; + else if (i_new_pc) + pending_new_pc <= 1'b1; + // }}} + + // pending_pc + // {{{ + initial pending_pc = 0; + always @(posedge S_AXI_ACLK) + if (i_new_pc) + pending_pc <= i_pc; + // }}} + + // M_AXI_ARADDR + // {{{ + always @(posedge S_AXI_ACLK) + if (!M_AXI_ARVALID || M_AXI_ARREADY) + begin + if (i_new_pc) + M_AXI_ARADDR <= i_pc; + else if (pending_new_pc) + M_AXI_ARADDR <= pending_pc; + else if (M_AXI_ARVALID) + begin + M_AXI_ARADDR[C_AXI_ADDR_WIDTH-1:AXILLSB] + <= M_AXI_ARADDR[C_AXI_ADDR_WIDTH-1:AXILLSB] +1; + M_AXI_ARADDR[AXILLSB-1:0] <= 0; + end + end + // }}} + + // o_pc + // {{{ + initial o_pc = 0; + always @(posedge S_AXI_ACLK) + if (i_new_pc) + o_pc <= i_pc; + else if (o_valid && i_ready && !o_illegal) + begin + o_pc[AW-1:2] <= o_pc[AW-1:2] + 1; + o_pc[1:0] <= 2'b00; + end + // }}} + + generate if (AXILLSB > 2) + begin : BIG_WORD + // {{{ + always @(*) + begin + shift = o_pc[AXILLSB-1:2]; + + if (FETCH_LIMIT > 0 && o_valid) + shift = 0; + end + // }}} + end else begin : NO_SHIFT + // {{{ + always @(*) + shift = 0; + // }}} + end endgenerate + + generate if (SWAP_ENDIANNESS) + begin : SWAPPED_ENDIANNESS + // {{{ + genvar gw, gb; // Word count, byte count + + for(gw=0; gw 0) + assert(!o_valid); +`endif + // }}} + end else if (FETCH_LIMIT == 2) + begin : DBLFETCH + // {{{ + // Single word cache + reg cache_valid; + reg [C_AXI_DATA_WIDTH:0] cache_data; + + assign fifo_rd = !o_valid || (i_ready && (out_fill <= 1)); + assign fifo_empty =(!M_AXI_RVALID && !cache_valid) || flushing; + assign fifo_data = cache_valid ? cache_data + : ({ M_AXI_RRESP[1], endian_swapped_rdata }); + + + assign ign_fifo_fill = cache_valid ? 1 : 0; + assign ign_fifo_full = cache_valid; + + initial cache_valid = 1'b0; + always @(posedge S_AXI_ACLK) + if (fifo_reset) + cache_valid <= 1'b0; + else if (M_AXI_RVALID && o_valid && !fifo_rd) + cache_valid <= 1; + else if (fifo_rd) + cache_valid <= 1'b0; + + always @(posedge S_AXI_ACLK) + if (M_AXI_RVALID) + cache_data <= { M_AXI_RRESP[1], endian_swapped_rdata }; + // }}} + end else begin : FIFO_FETCH + // {{{ + // FIFO cache + + // Verilator lint_off CMPCONST + // out_fill will only capture 0 or 1 if DATA_WIDTH == 32 + assign fifo_rd = !o_valid || (i_ready && (out_fill <= 1)); + // Verilator lint_on CMPCONST + + sfifo #(.BW(1+C_AXI_DATA_WIDTH), .LGFLEN(LGFIFO)) + fcache(.i_clk(S_AXI_ACLK), .i_reset(fifo_reset), + .i_wr(fifo_wr), + .i_data({M_AXI_RRESP[1], endian_swapped_rdata }), + .o_full(ign_fifo_full), .o_fill(ign_fifo_fill), + .i_rd(fifo_rd),.o_data(fifo_data),.o_empty(fifo_empty)); + // }}} + end endgenerate + + // o_valid + // {{{ + initial o_valid = 1'b0; + always @(posedge S_AXI_ACLK) + if (fifo_reset) + o_valid <= 1'b0; + else if (!o_valid || i_ready) + o_valid <= (fifo_rd && !fifo_empty) + || out_fill > (o_valid ? 1:0); + // }}} + + // out_fill + // {{{ + initial out_fill = 0; + always @(posedge S_AXI_ACLK) + if (fifo_reset) + out_fill <= 0; + else if (fifo_rd) + // Verilator lint_off WIDTH + out_fill <= (fifo_empty) ? 0: (INSNS_PER_WORD - shift); + // Verilator lint_on WIDTH + else if (i_ready && out_fill > 0) + out_fill <= out_fill - 1; + // }}} + + // out_data + // {{{ + always @(posedge S_AXI_ACLK) + if (fifo_rd) + out_data <= fifo_data[C_AXI_DATA_WIDTH-1:0]>>(DATA_WIDTH*shift); + else if (i_ready) + out_data <= out_data >> DATA_WIDTH; + // }}} + + assign o_insn = out_data[DATA_WIDTH-1:0]; + + // o_illegal + // {{{ + initial o_illegal = 1'b0; + always @(posedge S_AXI_ACLK) + if (fifo_reset) + o_illegal <= 1'b0; + else if (!o_illegal && fifo_rd && !fifo_empty) + o_illegal <= fifo_data[C_AXI_DATA_WIDTH]; + // }}} + + // Make verilator happy + // {{{ + // verilator lint_off UNUSED + wire unused; + assign unused = & { 1'b0, M_AXI_RRESP[0], ign_fifo_full, ign_fifo_fill }; + // verilator lint_on UNUSED + // }}} +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal properties +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +`ifdef FORMAL + // Declarations + // {{{ + localparam DW=DATA_WIDTH; + localparam F_LGDEPTH=LGDEPTH+2; + reg f_past_valid; + wire [(F_LGDEPTH-1):0] faxil_outstanding; + reg [(AW-1):0] f_last_pc; + reg f_last_pc_valid; + // + reg [AW-1:0] fc_pc, f_address; + reg fc_illegal; + reg [DATA_WIDTH-1:0] fc_insn; + //}}} + //////////////////////////////////////////////////////////////////////// + // + // Generic setup + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + // Keep track of a flag telling us whether or not $past() + // will return valid results + initial f_past_valid = 1'b0; + always @(posedge S_AXI_ACLK) + f_past_valid = 1'b1; + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Assumptions about our inputs + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + // Assume we start from a reset condition + // {{{ + always @(*) + if (!f_past_valid) + assume(!S_AXI_ARESETN); + + always @(*) + if (!S_AXI_ARESETN) + assume(i_cpu_reset); + // }}} + + // + // + // Let's make some assumptions about how long it takes our + // phantom bus and phantom CPU to respond. + // + // These delays need to be long enough to flush out any potential + // errors, yet still short enough that the formal method doesn't + // take forever to solve. + // + localparam F_CPU_DELAY = 4; + reg [$clog2(F_CPU_DELAY):0] f_cpu_delay; + // First, let's assume that any response from the bus comes back + // within F_WB_DELAY clocks + + // Here's our delay assumption: We'll assume that the + // wishbone will always respond within F_WB_DELAY clock ticks + // of the beginning of any cycle. + // + // This includes both dropping the stall line, as well as + // acknowledging any request. While this may not be + // a reasonable assumption for a piped master, it should + // work here for us. + + // Count the number of clocks it takes the CPU to respond to our + // instruction. + always @(posedge S_AXI_ACLK) + // If no instruction is ready, then keep our counter at zero + if (i_cpu_reset|| !o_valid || i_ready) + f_cpu_delay <= 0; + else + // Otherwise, count the clocks the CPU takes to respond + f_cpu_delay <= f_cpu_delay + 1'b1; + +`ifdef PREFETCH + // Only *assume* that we are less than F_CPU_DELAY if we are not + // integrated into the CPU + always @(posedge S_AXI_ACLK) + assume(f_cpu_delay < F_CPU_DELAY); +`endif + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Bus properties + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + faxil_master #( + // {{{ + .C_AXI_ADDR_WIDTH(C_AXI_ADDR_WIDTH), + .C_AXI_DATA_WIDTH(C_AXI_DATA_WIDTH), + .F_OPT_READ_ONLY(1'b1), + .F_OPT_COVER_BURST(5), + .F_OPT_ASSUME_RESET(1'b1), + .F_LGDEPTH(F_LGDEPTH) + // }}} + ) faxil( + // {{{ + .i_clk(S_AXI_ACLK), .i_axi_reset_n(S_AXI_ARESETN), + // Unused write interface + // {{{ + .i_axi_awvalid(1'b0), .i_axi_awready(1'b1), + .i_axi_wvalid(1'b0), .i_axi_wready(1'b1), + .i_axi_bvalid(1'b0), .i_axi_bready(1'b1), + // }}} + // Read address channel + // {{{ + .i_axi_arvalid(M_AXI_ARVALID), + .i_axi_arready(M_AXI_ARREADY), + .i_axi_araddr( M_AXI_ARADDR), + .i_axi_arprot( 3'h0), + // }}} + // Read return / data interface + // {{{ + .i_axi_rvalid(M_AXI_RVALID), + .i_axi_rready(M_AXI_RREADY), + .i_axi_rdata(M_AXI_RDATA), + .i_axi_rresp(M_AXI_RRESP), + // }}} + .f_axi_rd_outstanding(faxil_outstanding) + // }}} + ); + + + always @(*) + assert(full_bus == (outstanding >= (1< 0)); + + always @(*) + assert(flushcount <= outstanding + (flush_request ? 1:0)); + + always @(posedge S_AXI_ACLK) + if (flush_request && !i_clear_cache && !i_cpu_reset) + assert(pending_new_pc || i_new_pc); + + always @(*) + if (!M_AXI_ARVALID || !flushing) + assert(!flush_request); + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Subword return + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + reg [W:0] f_word_count; + reg [AW-1:0] f_return_addr; + reg [AW-1:0] f_out_addr, f_subout_addr; + reg [C_AXI_ADDR_WIDTH-1:0] f_req_addr, f_ret_addr; + reg [W:0] f_req_offset, f_ret_offset; + + + always @(*) + begin + f_req_offset = f_word_count; + if (flushing) + f_req_offset = f_req_offset - flushcount; + if (M_AXI_ARVALID && f_req_offset > 0) + f_req_offset = f_req_offset - 1; + + f_req_addr = f_out_addr + (f_req_offset << AXILLSB); + if (f_req_offset == 0) + f_req_addr[AXILLSB-1:0] = o_pc[AXILLSB-1:0]; + + /////////////// + + f_ret_offset = o_valid ? 1:0; + f_ret_offset = f_ret_offset + ign_fifo_fill; + + f_ret_addr = f_out_addr + (f_ret_offset << AXILLSB); + if (f_ret_offset == 0) + f_ret_addr[AXILLSB-1:0] = o_pc[AXILLSB-1:0]; + end + + always @(*) + assert(f_req_offset <= f_word_count); + + always @(*) + assert(f_req_offset == fill + (o_valid ? 1:0)); + + always @(*) + assert(f_ret_offset <= f_req_offset); + + always @(*) + if (!i_cpu_reset && !i_new_pc && !i_clear_cache + && !pending_new_pc && M_AXI_ARADDR != o_pc) + assert(M_AXI_ARADDR[AXILLSB-1:0] == 0); + + always @(*) + if (!flushing) + assert(f_word_count <= FETCH_LIMIT); + else + assert(f_word_count - flushcount <= FETCH_LIMIT); + + always @(*) + if (!i_cpu_reset && !i_new_pc && !i_clear_cache && !flush_request) + begin + if (!o_illegal) + assert(f_req_addr[AXILLSB-1:0] == M_AXI_ARADDR[AXILLSB-1:0]); + assert(f_req_addr[C_AXI_ADDR_WIDTH-1:AXILLSB] + == M_AXI_ARADDR[C_AXI_ADDR_WIDTH-1:AXILLSB]); + end + + always @(*) + if (S_AXI_ARESETN && !i_cpu_reset && !i_new_pc && !i_clear_cache + && !flushing && !o_illegal) + assert(f_ret_addr[C_AXI_ADDR_WIDTH-1:AXILLSB] + == f_return_addr[C_AXI_ADDR_WIDTH-1:AXILLSB]); + + always @(*) + begin + f_word_count = faxil_outstanding; + if (M_AXI_ARVALID) + f_word_count = f_word_count + 1; + f_word_count = f_word_count + ign_fifo_fill; + if (o_valid) + f_word_count = f_word_count + 1; + end + + + generate if (FETCH_LIMIT <= 1) + begin : F_NO_CACHE + + end else if (FETCH_LIMIT == 2) + begin : F_DBLFETCH + + end else begin : F_FIFO_CACHE + + end endgenerate + + always @(*) + begin + assert(faxil_outstanding + (M_AXI_ARVALID ? 1:0)<=(1<0)); + + // + // Assertions about our return responses + // {{{ + // While the below assertions (currently) appear to just copy the logic + // above, they still have a purpose--they'll help us guarantee that the + // logic above will never change without also requiring a change here. + // + generate if (SWAP_ENDIANNESS) + begin : CHECK_SWAPPED_ENDIANNESS + // {{{ + genvar gw, gb; // Word count, byte count + + for(gw=0; gw> (shift * DATA_WIDTH); + // }}} + end endgenerate + + always @(*) + if (M_AXI_RVALID && f_return_addr[AW-1:AXILLSB] == fc_pc[AW-1:AXILLSB]) + begin + assume(M_AXI_RRESP[1] == fc_illegal); + assume(f_bus_word == fc_insn); + end + + // + // + // Step 2: Assert that any value in our cache meets the contract + // + // + generate if (DATA_WIDTH == C_AXI_DATA_WIDTH) + begin : F_OUTDATA + // {{{ + assign f_out_data = out_data; + // }}} + end else begin : F_OUTDATA_SHIFT + // {{{ + reg [$clog2(INSNS_PER_WORD)-1:0] shift; + + always @(*) + shift = (fc_pc - f_subout_addr) >> $clog2(DATA_WIDTH/8); + + assign f_out_data = out_data >> (shift * DATA_WIDTH); + // }}} + end endgenerate + + generate if (FETCH_LIMIT == 1) + begin : F_SINGLE + end else if (FETCH_LIMIT == 2) + begin : F_CACHE_CHECK + // {{{ + reg [AW-1:0] f_cache_addr; + wire [C_AXI_DATA_WIDTH-1:0] f_cache_data; + wire f_cache_illegal; + reg f_cache_check; + + always @(*) + begin + f_cache_addr = 0; + f_cache_addr[AW-1:AXILLSB] = f_out_addr[AW-1:AXILLSB]+1; + + f_cache_check = (fc_pc[AW-1:AXILLSB] + == f_cache_addr[AW-1:AXILLSB]); + if (!DBLFETCH.cache_valid) + f_cache_check = 1'b0; + end + + if (DATA_WIDTH == C_AXI_DATA_WIDTH) + begin : F_CACHEDATA + + assign f_cache_data=DBLFETCH.cache_data[DATA_WIDTH-1:0]; + assign f_cache_illegal= DBLFETCH.cache_data[DATA_WIDTH]; + + end else begin : F_CACHEDATA_SHIFT + + reg [$clog2(INSNS_PER_WORD)-1:0] shift; + + always @(*) + shift = (fc_pc - f_cache_addr) >> $clog2(DATA_WIDTH/8); + + assign f_cache_data = DBLFETCH.cache_data >> (shift * DATA_WIDTH); + assign f_cache_illegal= DBLFETCH.cache_data[C_AXI_DATA_WIDTH]; + end + + always @(*) + if (f_cache_check && !o_illegal) + begin + assert(f_cache_data[DATA_WIDTH-1:0] == fc_insn); + assert(f_cache_illegal == fc_illegal); + end + // }}} + end else begin : F_FIFO_CHECK + // {{{ + reg [AW-1:0] f_cache_addr, f_fifo_addr; + reg [C_AXI_DATA_WIDTH-1:0] f_cache_data, f_cache_subdata, + f_fifo_subdata; + reg f_cache_illegal; + reg f_cache_check, f_cache_valid; + reg [LGFIFO:0] f_cache_distance; + reg f_cache_assume; + + + always @(*) + { f_cache_illegal, f_cache_data } + = { FIFO_FETCH.fcache.f_first_data }; + + always @(*) + f_cache_distance = FIFO_FETCH.fcache.f_distance_to_first; + + always @(*) + f_cache_valid = FIFO_FETCH.fcache.f_first_in_fifo; + + always @(*) + begin + f_cache_addr = 0; + f_cache_addr[AW-1:AXILLSB] = f_out_addr[AW-1:AXILLSB] + + (o_valid ? 1:0) + + f_cache_distance; + + f_cache_check = (fc_pc[AW-1:AXILLSB] + == f_cache_addr[AW-1:AXILLSB]); + if (!f_cache_valid) + f_cache_check = 1'b0; + end + + if (DATA_WIDTH == C_AXI_DATA_WIDTH) + begin : F_CACHEDATA + + always @(*) + f_cache_subdata = f_cache_data; + + always @(*) + f_fifo_subdata = fifo_data[DATA_WIDTH-1:0]; + + end else begin : F_CACHEDATA_SHIFT + + reg [$clog2(INSNS_PER_WORD)-1:0] shift; + + always @(*) + shift = (fc_pc - f_cache_addr) >> $clog2(DATA_WIDTH/8); + + always @(*) + f_cache_subdata = f_cache_data >> (shift * DATA_WIDTH); + always @(*) + f_fifo_subdata = fifo_data >> (shift * DATA_WIDTH); + end + + always @(*) + begin + f_fifo_addr = 0; + f_fifo_addr[AW-1:AXILLSB] = f_out_addr[AW-1:AXILLSB] + + (o_valid ? 1:0); + end + + always @(*) + if (f_cache_check && !o_illegal) + begin + assert(f_cache_subdata[DATA_WIDTH-1:0] == fc_insn); + assert(f_cache_illegal == fc_illegal); + end + + always @(*) + begin + f_cache_assume = 0; + if (ign_fifo_fill != 0 && (f_fifo_addr[AW-1:AXILLSB] + == fc_pc[AW-1:AXILLSB])) + begin + if (!f_cache_check || o_illegal) + f_cache_assume = 1; + if (f_cache_addr[AW-1:AXILLSB] + != f_fifo_addr[AW-1:AXILLSB]) + f_cache_assume = 1; + end + end + + always @(*) + if (f_cache_assume) + begin + assume(f_fifo_subdata[DATA_WIDTH-1:0] == fc_insn); + assume(fifo_data[C_AXI_DATA_WIDTH] == fc_illegal); + end + // }}} + end endgenerate + + // + // Check the final output word + // + always @(*) + if ((out_fill > 0) && (fc_pc[AW-1:AXILLSB] == f_out_addr[AW-1:AXILLSB]) + &&(fc_pc >= f_subout_addr)) + begin + if (fc_illegal) + assert(o_illegal); + else if (!o_illegal) + assert(f_out_data == fc_insn); + end + + always @(*) + if (pending_new_pc) + assert(i_new_pc || flush_request); + + always @(*) + if (pending_new_pc) + assert(o_pc == pending_pc); + + always @(*) + if (flush_request) + assert(flushcount == faxil_outstanding + 1); + + always @(*) + if (flushing) + assert(!o_illegal); + + always @(*) + if (flush_request && !i_cpu_reset && !i_new_pc && !i_clear_cache) + begin + assert(f_out_addr[C_AXI_ADDR_WIDTH-1:AXILLSB] == pending_pc[C_AXI_ADDR_WIDTH-1:AXILLSB]); + assert(o_pc == pending_pc); + end +`endif + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Cover properties + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + reg [3:0] cvr_returns; + (* anyconst *) reg cvr_always_ready; + + always @(*) + if (cvr_always_ready) + assume(M_AXI_ARREADY); + + initial cvr_returns = 0; + always @(posedge S_AXI_ACLK) + if (i_cpu_reset || i_new_pc || i_clear_cache || o_illegal) + cvr_returns <= 0; + else if (o_valid && i_ready && !cvr_returns[3]) + cvr_returns <= cvr_returns + 1; + + always @(*) + begin + cover(cvr_returns == 4'b0100); + cover(cvr_returns == 4'b0101); + cover(cvr_returns == 4'b0110 && cvr_always_ready); + end + // }}} +`endif +// }}} +endmodule diff --git a/rtl/cpu/axilops.v b/rtl/cpu/axilops.v new file mode 100644 index 0000000..56e5916 --- /dev/null +++ b/rtl/cpu/axilops.v @@ -0,0 +1,1276 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Filename: axilops.v +// {{{ +// Project: Zip CPU -- a small, lightweight, RISC CPU soft core +// +// Purpose: A memory unit to support a CPU based upon AXI-lite. This is +// a very basic memory unit designed to be low on logic and yet +// to still support a lot of options. +// +// +// Creator: Dan Gisselquist, Ph.D. +// Gisselquist Technology, LLC +// +//////////////////////////////////////////////////////////////////////////////// +// }}} +// Copyright (C) 2020-2021, Gisselquist Technology, LLC +// {{{ +// This program is free software (firmware): 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 MERCHANTIBILITY 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. (It's in the $(ROOT)/doc directory. Run make with no +// target there if the PDF file isn't present.) If not, see +// for a copy. +// }}} +// License: GPL, v3, as defined and found on www.gnu.org, +// {{{ +// http://www.gnu.org/licenses/gpl.html +// +//////////////////////////////////////////////////////////////////////////////// +// +// +`default_nettype none +// }}} +module axilops #( + // {{{ + parameter ADDRESS_WIDTH=30, + parameter C_AXI_ADDR_WIDTH = ADDRESS_WIDTH, + parameter C_AXI_DATA_WIDTH = 32, + // + // SWAP_ENDIANNESS + // {{{ + // The ZipCPU was designed to be a big endian machine. With + // no other adjustments, this design will make the ZipCPU + // *little* endian, for the simple reason that the AXI bus is + // a little endian bus. However, if SWAP_ENDIANNESS is set, + // the bytes within 32-bit words on the AXI bus will be swapped. + // This will return the CPU to being a big endian CPU on a + // little endian bus. It will also break any design that + // assumes the bus is presented to it in its proper order. + // Simple things like counters or interrupt controllers will + // therefore cease to work with this option unless they also + // swap the endianness of the words they are given. + parameter [0:0] SWAP_ENDIANNESS = 1'b0, + // }}} + // SWAP_WSTRB + // {{{ + // SWAP_WSTRB represents a second attempt to fix the endianness + // issue. It is incompatible with the SWAP_ENDIANNESS option + // above. If SWAP_WSTRB is set, then half words and words will + // be placed on the bus in little endian order, but at big + // endian addresses. Words written to the bus will be written + // in little endian order. Halfwords written to the bus at + // address 2 will be written to address 0, halfwords written to + // address 0 will be written to address 2. Bytes written to the + // but at address 3 will be written to address 0, address 2 + // will be written to address 1, address 1 to address 2, and + // address 3 to address 0. + // + // This may just be a half baked attempt to solve this problem, + // since it will fail if you ever trie to access bytes or + // halfwords at other than their intended widths. + parameter [0:0] SWAP_WSTRB = 1'b0, + // }}} + // OPT_SIGN_EXTEND + // {{{ + // Some CPU's want memory accesses to be sign extended upon + // return. The ZipCPU is not one of those CPU's. However, + // since it's fairly easy to do so, we'll implement this logic + // if ever OPT_SIGN_EXTEND is true so you can see how it would + // be done if necessary. + parameter [0:0] OPT_SIGN_EXTEND = 1'b0, + // }}} + // OPT_ALIGNMENT_ERR + // {{{ + // If set, OPT_ALIGNMENT_ERR will generate an alignment error + // on any attempt to write to or read from an unaligned word. + // If not set, unaligned reads (or writes) will be expanded into + // pairs so as to still accomplish the action requested. The + // bus does not guarantee protection, however, that these two + // writes or two reads will proceed uninterrupted. Since + // unaligned writes and unaligned reads are no longer + // guaranteed to be atomic by the AXI bus, it is possible that + // any unaligned operations might yield an incoherent result. + parameter [0:0] OPT_ALIGNMENT_ERR = 1'b1, + // }}} + // OPT_LOWPOWER + // {{{ + // If set, the design will use extra logic to guarantee that any + // unused registers are kept at zero until they are used. This + // will help to guarantee the design (ideally) has fewer + // transitions and therefore uses lower power. + parameter [0:0] OPT_LOWPOWER = 1'b0, + // }}} + localparam AW = C_AXI_ADDR_WIDTH, + localparam DW = C_AXI_DATA_WIDTH, + localparam AXILSB = $clog2(C_AXI_DATA_WIDTH/8) + // }}} + ) ( + // {{{ + input wire S_AXI_ACLK, + input wire S_AXI_ARESETN, + input wire i_cpu_reset, + // + // CPU interface + // {{{ + input wire i_stb, + input wire i_lock, + input wire [2:0] i_op, + input wire [AW-1:0] i_addr, + input wire [31:0] i_data, + input wire [4:0] i_oreg, + output reg o_busy, + output reg o_rdbusy, + output reg o_valid, + output reg o_err, + output reg [4:0] o_wreg, + output reg [31:0] o_result, + // }}} + // AXI-Lite bus interface + // + // Writes + // {{{ + output reg M_AXI_AWVALID, + input wire M_AXI_AWREADY, + output reg [AW-1:0] M_AXI_AWADDR, + output wire [2:0] M_AXI_AWPROT, + // + output reg M_AXI_WVALID, + input wire M_AXI_WREADY, + output reg [DW-1:0] M_AXI_WDATA, + output reg [DW/8-1:0] M_AXI_WSTRB, + // + input wire M_AXI_BVALID, + output reg M_AXI_BREADY, + input wire [1:0] M_AXI_BRESP, + // }}} + // Reads + // {{{ + output reg M_AXI_ARVALID, + input wire M_AXI_ARREADY, + output reg [AW-1:0] M_AXI_ARADDR, + output wire [2:0] M_AXI_ARPROT, + // + input wire M_AXI_RVALID, + output reg M_AXI_RREADY, + input wire [DW-1:0] M_AXI_RDATA, + input wire [1:0] M_AXI_RRESP + // }}} + // }}} + ); + + // Declarations + // {{{ + wire i_clk = S_AXI_ACLK; + // wire i_reset = !S_AXI_ARESETN; + + reg w_misaligned, w_misalignment_err; + wire misaligned_request, misaligned_aw_request, + misaligned_response_pending, pending_err, misaligned_read; + reg r_flushing; + reg [AXILSB+1:0] r_op; + reg [DW-1:0] next_wdata; + reg [DW/8-1:0] next_wstrb; + reg [31:0] last_result; + // reg [31:0] endian_swapped_wdata; + // reg [31:0] endian_swapped_result; + reg [2*DW/8-1:0] shifted_wstrb_word, + shifted_wstrb_halfword, + shifted_wstrb_byte; + reg [2*DW/8-1:0] swapped_wstrb_word, + swapped_wstrb_halfword, + swapped_wstrb_byte; + reg [DW-1:0] axi_wdata; + reg [DW/8-1:0] axi_wstrb; + reg [AXILSB-1:0] swapaddr; + wire [DW-1:0] endian_swapped_rdata; + reg [2*DW-1:0] pre_result; + + // }}} + + // xVALID, and xREADY + // {{{ + initial M_AXI_AWVALID = 1'b0; + initial M_AXI_WVALID = 1'b0; + initial M_AXI_ARVALID = 1'b0; + initial M_AXI_BREADY = 1'b0; + initial M_AXI_RREADY = 1'b0; + always @(posedge i_clk) + if (!S_AXI_ARESETN) + begin + // {{{ + M_AXI_AWVALID <= 1'b0; + M_AXI_WVALID <= 1'b0; + M_AXI_ARVALID <= 1'b0; + M_AXI_BREADY <= 1'b0; + M_AXI_RREADY <= 1'b0; + // }}} + end else if (M_AXI_BREADY || M_AXI_RREADY) + begin // Something is outstanding + // {{{ + if (M_AXI_AWREADY) + M_AXI_AWVALID <= M_AXI_AWVALID && misaligned_aw_request; + if (M_AXI_WREADY) + M_AXI_WVALID <= M_AXI_WVALID && misaligned_request; + if (M_AXI_ARREADY) + M_AXI_ARVALID <= M_AXI_ARVALID && misaligned_request; + + if ((M_AXI_BVALID || M_AXI_RVALID) && !misaligned_response_pending) + begin + M_AXI_BREADY <= 1'b0; + M_AXI_RREADY <= 1'b0; + end + // }}} + end else begin // New memory operation + // {{{ + // Initiate a request + M_AXI_AWVALID <= i_op[0]; // Write request + M_AXI_WVALID <= i_op[0]; // Write request + M_AXI_ARVALID <= !i_op[0]; // Read request + + // Set BREADY or RREADY to accept the response. These will + // remain ready until the response is returned. + M_AXI_BREADY <= i_op[0]; + M_AXI_RREADY <= !i_op[0]; + + if (i_cpu_reset || o_err || !i_stb || w_misalignment_err) + begin + M_AXI_AWVALID <= 0; + M_AXI_WVALID <= 0; + M_AXI_ARVALID <= 0; + + M_AXI_BREADY <= 0; + M_AXI_RREADY <= 0; + end + // }}} + end + // }}} + + // r_flushing + // {{{ + initial r_flushing = 1'b0; + always @(posedge i_clk) + if (!S_AXI_ARESETN) + // If everything is reset, then we don't need to worry about + // or wait for any pending returns--they'll be canceled by the + // global reset. + r_flushing <= 1'b0; + else if (M_AXI_BREADY || M_AXI_RREADY) + begin + if (i_cpu_reset) + // If only the CPU is reset, however, we have a problem. + // The bus hasn't been reset, and so it is still active. + // We can't respond to any new requests from the CPU + // until we flush any transactions that are currently + // active. + r_flushing <= 1'b1; + if (M_AXI_BVALID || M_AXI_RVALID) + // A request just came back, therefore we can clear + // r_flushing + r_flushing <= 1'b0; + if (misaligned_response_pending) + // ... unless we're in the middle of a misaligned + // request. In that case, there will be a second + // return that we still need to wait for. This request, + // though, will clear misaligned_response_pending. + r_flushing <= r_flushing || i_cpu_reset; + end else + // If nothing is active, we don't care about the CPU reset. + // Flushing just stays at zero. + r_flushing <= 1'b0; + // }}} + + // M_AXI_AxADDR + // {{{ + initial M_AXI_AWADDR = 0; + always @(posedge i_clk) + if (!S_AXI_ARESETN && OPT_LOWPOWER) + M_AXI_AWADDR <= 0; + else if (!M_AXI_BREADY && !M_AXI_RREADY) + begin // Initial address + // {{{ + M_AXI_AWADDR <= i_addr; + + if (OPT_LOWPOWER && (i_cpu_reset || o_err || !i_stb || w_misalignment_err)) + M_AXI_AWADDR <= 0; + + if (SWAP_ENDIANNESS || SWAP_WSTRB) + // When adjusting endianness, reads (or writes) are + // always full words. This is important since the + // the bytes at issues may (or may not) be in their + // expected locations + M_AXI_AWADDR[AXILSB-1:0] <= 0; + // }}} + end else if ((M_AXI_AWVALID && M_AXI_AWREADY) + ||(M_AXI_ARVALID && M_AXI_ARREADY)) + begin // Subsequent addresses + // {{{ + M_AXI_AWADDR[C_AXI_ADDR_WIDTH-1:AXILSB] + <= M_AXI_AWADDR[C_AXI_ADDR_WIDTH-1:AXILSB] + 1; + + M_AXI_AWADDR[AXILSB-1:0] <= 0; + + if (OPT_LOWPOWER && ((M_AXI_RREADY && !misaligned_request) + || (M_AXI_BREADY && !misaligned_aw_request))) + M_AXI_AWADDR <= 0; + // }}} + end + + always @(*) + M_AXI_ARADDR = M_AXI_AWADDR; + // }}} + + // AxPROT + // {{{ + localparam [2:0] AXI_UNPRIVILEGED_NONSECURE_DATA_ACCESS = 3'h0; + localparam [2:0] OPT_PROT=AXI_UNPRIVILEGED_NONSECURE_DATA_ACCESS; + + assign M_AXI_AWPROT = OPT_PROT; + assign M_AXI_ARPROT = OPT_PROT; + // }}} + + // shifted_wstrb_* + // {{{ + always @(*) + shifted_wstrb_word = { {(2*DW/8-4){1'b0}}, + 4'b1111} << i_addr[AXILSB-1:0]; + + always @(*) + shifted_wstrb_halfword = { {(2*DW/8-4){1'b0}}, + 4'b0011} << i_addr[AXILSB-1:0]; + + always @(*) + shifted_wstrb_byte = { {(2*DW/8-4){1'b0}}, + 4'b0001} << i_addr[AXILSB-1:0]; + // }}} + + // Swapping WSTRB bits + // {{{ + generate if (SWAP_WSTRB) + begin : SWAPPING_WSTRB + // {{{ + genvar gw, gb; + + for(gw=0; gw<2*DW/32; gw=gw+1) + begin : FOREACH_32B_WORD + for(gb=0; gb<32/8; gb=gb+1) + begin : FOREACH_BYTE + + always @(*) + begin + swapped_wstrb_word[gw*4+gb] + = shifted_wstrb_word[gw*4+(3-gb)]; + swapped_wstrb_halfword[gw*4+gb] + = shifted_wstrb_halfword[gw*4+(3-gb)]; + swapped_wstrb_byte[gw*4+gb] + = shifted_wstrb_byte[gw*4+(3-gb)]; + end end end + // }}} + end else begin : KEEP_WSTRB + // {{{ + + always @(*) + swapped_wstrb_word = shifted_wstrb_word; + + always @(*) + swapped_wstrb_halfword = shifted_wstrb_halfword; + + always @(*) + swapped_wstrb_byte = shifted_wstrb_byte; + // }}} + end endgenerate + // }}} + + // wdata, wstrb + // {{{ + always @(*) + begin + swapaddr = i_addr[AXILSB-1:0]; + if (SWAP_WSTRB) + swapaddr[1:0] = 3 - i_addr[1:0]; + end + + initial axi_wdata = 0; + initial axi_wstrb = 0; + initial next_wdata = 0; + initial next_wstrb = 0; + always @(posedge i_clk) + if (OPT_LOWPOWER && !S_AXI_ARESETN) + begin + // {{{ + axi_wdata <= 0; + axi_wstrb <= 0; + + next_wdata <= 0; + next_wstrb <= 0; + + r_op <= 0; + // }}} + end else if (i_stb) + begin + // {{{ + casez(i_op[2:1]) + 2'b10: { next_wdata, axi_wdata } + <= { {(2*C_AXI_DATA_WIDTH-16){1'b0}}, + i_data[15:0] } << (8*swapaddr); + 2'b11: { next_wdata, axi_wdata } + <= { {(2*C_AXI_DATA_WIDTH-8){1'b0}}, + i_data[7:0] } << (8*swapaddr); + default: { next_wdata, axi_wdata } + <= { {(2*C_AXI_DATA_WIDTH-32){1'b0}}, + i_data } << (8*swapaddr); + endcase + + // next_wstrb, axi_wstrb + // {{{ + casez(i_op[2:1]) + 2'b0?: { next_wstrb, axi_wstrb } <= swapped_wstrb_word; + 2'b10: { next_wstrb, axi_wstrb } <= swapped_wstrb_halfword; + 2'b11: { next_wstrb, axi_wstrb } <= swapped_wstrb_byte; + endcase + // }}} + + r_op <= { i_op[2:1] , i_addr[AXILSB-1:0] }; + + // On a read set everything to zero but only if OPT_LOWPOWER + // is set + // {{{ + if (OPT_LOWPOWER && !i_op[0]) + { next_wstrb, next_wdata, axi_wstrb, axi_wdata } <= 0; + + if (OPT_ALIGNMENT_ERR) + { next_wstrb, next_wdata } <= 0; + if (OPT_LOWPOWER) + begin + if (w_misalignment_err) + { axi_wdata, axi_wstrb, r_op } <= 0; + if (o_err || i_cpu_reset) + { next_wdata, next_wstrb, + axi_wdata, axi_wstrb, r_op } <= 0; + end + // }}} + // }}} + end else if ((misaligned_request || !OPT_LOWPOWER) && M_AXI_WREADY) + begin + // {{{ + axi_wdata <= next_wdata; + axi_wstrb <= next_wstrb; + if (OPT_LOWPOWER) + { next_wdata, next_wstrb } <= 0; + // }}} + end else if (OPT_LOWPOWER && M_AXI_WREADY) + begin + // {{{ + axi_wdata <= 0; + axi_wstrb <= 0; + // }}} + end + // }}} + + // M_AXI_WDATA, M_AXI_WSTRB + // {{{ + generate if (SWAP_ENDIANNESS) + begin : SWAP_WRITE_DATA_STRB + // {{{ + genvar gw, gb; + + for(gw=0; gw= (1<= (1<> (8*r_op[AXILSB-1:0]); + else + pre_result = { {(DW){1'b0}}, endian_swapped_rdata } + >> (8*r_op[AXILSB-1:0]); + + if (OPT_LOWPOWER && (!M_AXI_RVALID || M_AXI_RRESP[1])) + pre_result = 0; + end + + // }}} + // last_result, o_result + // {{{ + always @(posedge i_clk) + if (OPT_LOWPOWER &&(!M_AXI_RREADY || !S_AXI_ARESETN || r_flushing || i_cpu_reset)) + { last_result, o_result } <= 0; + else if (M_AXI_RVALID) + begin + // {{{ + if ((M_AXI_RRESP[1] || !misaligned_response_pending) && OPT_LOWPOWER) + last_result <= 0; + else + last_result <= endian_swapped_rdata; + + if (OPT_ALIGNMENT_ERR) + last_result <= 0; + + o_result <= pre_result; + + if (OPT_SIGN_EXTEND) + begin + // {{{ + // Optionally sign extend the return result. + casez(r_op[AXILSB +: 2]) + 2'b10: o_result[31:16] <= {(16){pre_result[15]}}; + 2'b11: o_result[31: 8] <= {(24){pre_result[7]}}; + default: begin end + endcase + // }}} + end else begin + // Fill unused return bits with zeros + casez(r_op[AXILSB +: 2]) + 2'b10: o_result[31:16] <= 0; + 2'b11: o_result[31: 8] <= 0; + default: begin end + endcase + end + + if (OPT_LOWPOWER && (M_AXI_RRESP[1] || pending_err + || misaligned_response_pending)) + o_result <= 0; + // }}} + end + // }}} + + // Make verilator happy + // {{{ + // verilator lint_off UNUSED + wire unused; + assign unused = &{ 1'b0, i_lock, M_AXI_RRESP[0], M_AXI_BRESP[0], + pre_result[2*C_AXI_DATA_WIDTH:32] }; + // verilator lint_on UNUSED + // }}} +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal properties +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +`ifdef FORMAL + // Local declarations + // {{{ +`define ASSERT assert +`ifdef AXILOPS +`define ASSUME assume +`else +`define ASSUME assert +`endif + localparam F_LGDEPTH = 2; + + reg f_misaligned; + wire [F_LGDEPTH-1:0] faxil_rd_outstanding, faxil_wr_outstanding, + faxil_awr_outstanding; + wire f_pc, f_gie, f_read_cycle; + + reg f_past_valid; + initial f_past_valid = 0; + always @(posedge i_clk) + f_past_valid = 1'b1; + always @(*) + if (!f_past_valid) + `ASSUME(!S_AXI_ARESETN); + // }}} + + //////////////////////////////////////////////////////////////////////// + // + // Bus property checks + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + faxil_master #( + // {{{ + .C_AXI_DATA_WIDTH(C_AXI_DATA_WIDTH), + .C_AXI_ADDR_WIDTH(C_AXI_ADDR_WIDTH), + .F_OPT_ASSUME_RESET(1'b1), + .F_LGDEPTH(F_LGDEPTH) + // }}} + ) faxil( + // {{{ + .i_clk(S_AXI_ACLK), .i_axi_reset_n(S_AXI_ARESETN), + // + .i_axi_awvalid(M_AXI_AWVALID), + .i_axi_awready(M_AXI_AWREADY), + .i_axi_awaddr( M_AXI_AWADDR), + .i_axi_awprot( M_AXI_AWPROT), + // + .i_axi_wvalid(M_AXI_WVALID), + .i_axi_wready(M_AXI_WREADY), + .i_axi_wdata( M_AXI_WDATA), + .i_axi_wstrb( M_AXI_WSTRB), + // + .i_axi_bvalid(M_AXI_BVALID), + .i_axi_bready(M_AXI_BREADY), + .i_axi_bresp( M_AXI_BRESP), + // + .i_axi_arvalid(M_AXI_ARVALID), + .i_axi_arready(M_AXI_ARREADY), + .i_axi_araddr( M_AXI_ARADDR), + .i_axi_arprot( M_AXI_ARPROT), + // + .i_axi_rvalid(M_AXI_RVALID), + .i_axi_rready(M_AXI_RREADY), + .i_axi_rdata( M_AXI_RDATA), + .i_axi_rresp( M_AXI_RRESP), + // + .f_axi_rd_outstanding(faxil_rd_outstanding), + .f_axi_wr_outstanding(faxil_wr_outstanding), + .f_axi_awr_outstanding(faxil_awr_outstanding) + // }}} + ); + + + always @(*) + begin + if (misaligned_request) + `ASSERT(M_AXI_WVALID || M_AXI_ARVALID); + if (misaligned_aw_request) + `ASSERT(M_AXI_AWVALID); + if (!misaligned_response_pending) + begin + `ASSERT(faxil_awr_outstanding <= (M_AXI_AWVALID ? 0:1)); + `ASSERT(faxil_wr_outstanding <= (M_AXI_WVALID ? 0:1)); + `ASSERT(faxil_rd_outstanding <= (M_AXI_ARVALID ? 0:1)); + + `ASSERT(!misaligned_request); + `ASSERT(!misaligned_aw_request); + end else if (M_AXI_RREADY) + `ASSERT(misaligned_read); + + if (!M_AXI_RREADY) + begin + `ASSERT(!M_AXI_ARVALID); + `ASSERT(faxil_rd_outstanding == 0); + // `ASSERT(misaligned_read == 1'b0); + end else begin + if (misaligned_request) + `ASSERT(faxil_rd_outstanding == 0); + `ASSERT(faxil_rd_outstanding <= 1 + (misaligned_read ? 1:0)); + end + + if (!M_AXI_BREADY) + begin + `ASSERT(!M_AXI_AWVALID); + `ASSERT(!M_AXI_WVALID); + `ASSERT(faxil_awr_outstanding == 0); + `ASSERT(faxil_wr_outstanding == 0); + end else begin + if (misaligned_request) + `ASSERT(faxil_wr_outstanding == 0); + if (misaligned_aw_request) + `ASSERT(faxil_awr_outstanding == 0); + `ASSERT(faxil_awr_outstanding <= 2); + `ASSERT(faxil_wr_outstanding <= 2); + + case({misaligned_request, + misaligned_aw_request, + misaligned_response_pending}) + 3'b000: begin + `ASSERT(faxil_awr_outstanding<= (M_AXI_BREADY ? 1:0)); + `ASSERT(faxil_wr_outstanding <= (M_AXI_BREADY ? 1:0)); + end + 3'b001: begin + `ASSERT(faxil_awr_outstanding<= 1 + (M_AXI_AWVALID ? 0:1)); + `ASSERT(faxil_wr_outstanding <= 1 + (M_AXI_WVALID ? 0:1)); + end + 3'b010: `ASSERT(0); + 3'b011: begin + `ASSERT(faxil_wr_outstanding<= 1 + (M_AXI_WVALID ? 0:1)); + `ASSERT(faxil_awr_outstanding == 0); + `ASSERT(M_AXI_AWVALID); + end + 3'b100: `ASSERT(0); + 3'b101: begin + `ASSERT(faxil_awr_outstanding<= 1 + (M_AXI_AWVALID ? 0:1)); + `ASSERT(faxil_wr_outstanding == 0); + `ASSERT(M_AXI_WVALID); + end + 3'b110: `ASSERT(0); + 3'b111: begin + `ASSERT(faxil_awr_outstanding == 0); + `ASSERT(faxil_wr_outstanding == 0); + `ASSERT(M_AXI_AWVALID); + `ASSERT(M_AXI_WVALID); + end + default: begin end + endcase + end + + + // Rule: Only one of the two xREADY's may be valid, never both + `ASSERT(!M_AXI_BREADY || !M_AXI_RREADY); + end + + // f_misaligned + // {{{ + always @(*) + begin + f_misaligned = 0; + case(r_op[AXILSB +: 2]) + 2'b01: f_misaligned = ((r_op[AXILSB-1:0] + 3) >= (1<= (1< 0 && (!OPT_LOWPOWER || (f_read_cycle && !o_err))) + assert(o_wreg == f_last_reg); + + always @(*) + if (o_busy && (!OPT_LOWPOWER || (M_AXI_RREADY && !r_flushing))) + assert(o_wreg[4] == f_gie); + + always @(*) + if (M_AXI_RREADY) + begin + assert(f_read_cycle || r_flushing); + end else if (M_AXI_BREADY) + assert(!f_read_cycle); + + // ???? Not written yet + // + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Cover properties + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + reg [3:0] cvr_writes, cvr_reads; + + initial cvr_writes = 0; + always @(posedge i_clk) + if (!S_AXI_ARESETN) + cvr_writes <= 0; + else if (M_AXI_BVALID&& !misaligned_response_pending && !cvr_writes[3]) + cvr_writes <= cvr_writes + 1; + + initial cvr_reads = 0; + always @(posedge i_clk) + if (!S_AXI_ARESETN) + cvr_reads <= 0; + else if (M_AXI_RVALID && !misaligned_response_pending && !cvr_reads[3]) + cvr_reads <= cvr_reads + 1; + + // Cover a write response + always @(posedge i_clk) + cover(M_AXI_BVALID && !M_AXI_BRESP[1]); + always @(posedge i_clk) + cover(M_AXI_BVALID && M_AXI_BRESP[1]); + + always @(posedge i_clk) + cover(M_AXI_RVALID && !M_AXI_RRESP[1]); + always @(posedge i_clk) + cover(M_AXI_RVALID && M_AXI_RRESP[1]); + + + always @(posedge i_clk) + cover(cvr_writes > 3); + + always @(posedge i_clk) + cover(cvr_reads > 3); + // }}} +`endif +// }}} +endmodule +// +// +// Usage (from yosys): +// (BFOR) (!ZOI,ALIGN) (ZOI,ALIGN) (!ZOI,!ALIGN) +// Cells 230 226 281 225 +// FDRE 114 116 116 116 +// LUT2 17 23 76 19 +// LUT3 9 23 17 20 +// LUT4 15 4 11 14 +// LUT5 18 18 7 15 +// LUT6 33 18 54 38 +// MUX7 16 12 2 +// MUX8 8 1 1 +// +// diff --git a/rtl/cpu/axilperiphs.v b/rtl/cpu/axilperiphs.v new file mode 100644 index 0000000..04494cc --- /dev/null +++ b/rtl/cpu/axilperiphs.v @@ -0,0 +1,551 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Filename: axilperiphs +// {{{ +// Project: WB2AXIPSP: bus bridges and other odds and ends +// +// Purpose: +// Registers: +// 0x00 PIC Interrupt controller +// 0x04 Watchdog +// 0x08 (Reserved) +// 0x0c CTRIC Secondary interrupt controller +// 0x10 TMRA +// 0x14 TMRB +// 0x18 TMRC +// 0x1c JIFF +// (No User counters) +// (No DMA) +// +// +// Creator: Dan Gisselquist, Ph.D. +// Gisselquist Technology, LLC +// +//////////////////////////////////////////////////////////////////////////////// +// }}} +// Copyright (C) 2020-2021, Gisselquist Technology, LLC +// {{{ +// +// This file is part of the WB2AXIP project. +// +// The WB2AXIP project contains free software and gateware, licensed under the +// Apache License, Version 2.0 (the "License"). You may not use this project, +// or this file, except in compliance with the License. You may obtain a copy +// of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations +// under the License. +// +//////////////////////////////////////////////////////////////////////////////// +// }}} +// +`default_nettype none +// +module axilperiphs #( + // {{{ + // + // Size of the AXI-lite bus. These are fixed, since 1) AXI-lite + // is fixed at a width of 32-bits by Xilinx def'n, and 2) since + // we only ever have 4 configuration words. + parameter C_AXI_ADDR_WIDTH = 5, + localparam C_AXI_DATA_WIDTH = 32, + parameter [0:0] OPT_SKIDBUFFER = 1'b1, + parameter [0:0] OPT_LOWPOWER = 0, + parameter EXTERNAL_INTERRUPTS = 1, + localparam ADDRLSB = $clog2(C_AXI_DATA_WIDTH)-3 + // }}} + ) ( + // {{{ + input wire S_AXI_ACLK, + input wire S_AXI_ARESETN, + // AXI-lite interface + // {{{ + input wire S_AXI_AWVALID, + output wire S_AXI_AWREADY, + input wire [C_AXI_ADDR_WIDTH-1:0] S_AXI_AWADDR, + input wire [2:0] S_AXI_AWPROT, + // + input wire S_AXI_WVALID, + output wire S_AXI_WREADY, + input wire [C_AXI_DATA_WIDTH-1:0] S_AXI_WDATA, + input wire [C_AXI_DATA_WIDTH/8-1:0] S_AXI_WSTRB, + // + output wire S_AXI_BVALID, + input wire S_AXI_BREADY, + output wire [1:0] S_AXI_BRESP, + // + input wire S_AXI_ARVALID, + output wire S_AXI_ARREADY, + input wire [C_AXI_ADDR_WIDTH-1:0] S_AXI_ARADDR, + input wire [2:0] S_AXI_ARPROT, + // + output wire S_AXI_RVALID, + input wire S_AXI_RREADY, + output wire [C_AXI_DATA_WIDTH-1:0] S_AXI_RDATA, + output wire [1:0] S_AXI_RRESP, + // }}} + input wire i_cpu_reset, + input wire i_cmd_halt, + input wire [EXTERNAL_INTERRUPTS-1:0] i_ivec, + output wire o_interrupt, + output wire o_watchdog_reset + // }}} + ); + + //////////////////////////////////////////////////////////////////////// + // + // Register/wire signal declarations + // + //////////////////////////////////////////////////////////////////////// + // + // {{{ + wire i_reset = !S_AXI_ARESETN; + + wire axil_write_ready; + wire [C_AXI_ADDR_WIDTH-ADDRLSB-1:0] awskd_addr; + // + wire [C_AXI_DATA_WIDTH-1:0] wskd_data; + wire [C_AXI_DATA_WIDTH/8-1:0] wskd_strb; + reg axil_bvalid; + // + wire axil_read_ready; + wire [C_AXI_ADDR_WIDTH-ADDRLSB-1:0] arskd_addr; + reg [C_AXI_DATA_WIDTH-1:0] axil_read_data; + reg axil_read_valid; + + wire pic_stall, pic_ack; + wire [31:0] pic_data; + + wire wdog_stall, wdog_ack; + wire [31:0] wdog_data; + + wire apic_stall, apic_ack, apic_int; + wire [31:0] apic_data; + + wire tmrb_stall, tmrb_ack, tmrb_int; + wire tmra_stall, tmra_ack, tmra_int; + wire [31:0] tmra_data; + + wire tmrb_stall, tmrb_ack, tmrb_int; + wire [31:0] tmrb_data; + + wire tmrc_stall, tmrc_ack, tmrc_int; + wire [31:0] tmrc_data; + + wire jif_stall, jif_ack, jif_int; + wire [31:0] jif_data; + // }}} + + //////////////////////////////////////////////////////////////////////// + // + // AXI-lite signaling + // + //////////////////////////////////////////////////////////////////////// + // + // {{{ + + // + // Write signaling + // + // {{{ + + generate if (OPT_SKIDBUFFER) + begin : SKIDBUFFER_WRITE + + wire awskd_valid, wskd_valid; + + skidbuffer #(.OPT_OUTREG(0), + .OPT_LOWPOWER(OPT_LOWPOWER), + .DW(C_AXI_ADDR_WIDTH-ADDRLSB)) + axilawskid(// + .i_clk(S_AXI_ACLK), .i_reset(i_reset), + .i_valid(S_AXI_AWVALID), .o_ready(S_AXI_AWREADY), + .i_data(S_AXI_AWADDR[C_AXI_ADDR_WIDTH-1:ADDRLSB]), + .o_valid(awskd_valid), .i_ready(axil_write_ready), + .o_data(awskd_addr)); + + skidbuffer #(.OPT_OUTREG(0), + .OPT_LOWPOWER(OPT_LOWPOWER), + .DW(C_AXI_DATA_WIDTH+C_AXI_DATA_WIDTH/8)) + axilwskid(// + .i_clk(S_AXI_ACLK), .i_reset(i_reset), + .i_valid(S_AXI_WVALID), .o_ready(S_AXI_WREADY), + .i_data({ S_AXI_WDATA, S_AXI_WSTRB }), + .o_valid(wskd_valid), .i_ready(axil_write_ready), + .o_data({ wskd_data, wskd_strb })); + + assign axil_write_ready = awskd_valid && wskd_valid + && (!S_AXI_BVALID || S_AXI_BREADY); + + end else begin : SIMPLE_WRITES + + reg axil_awready; + + initial axil_awready = 1'b0; + always @(posedge S_AXI_ACLK) + if (!S_AXI_ARESETN) + axil_awready <= 1'b0; + else + axil_awready <= !axil_awready + && (S_AXI_AWVALID && S_AXI_WVALID) + && (!S_AXI_BVALID || S_AXI_BREADY); + + assign S_AXI_AWREADY = axil_awready; + assign S_AXI_WREADY = axil_awready; + + assign awskd_addr = S_AXI_AWADDR[C_AXI_ADDR_WIDTH-1:ADDRLSB]; + assign wskd_data = S_AXI_WDATA; + assign wskd_strb = S_AXI_WSTRB; + + assign axil_write_ready = axil_awready; + + end endgenerate + + initial axil_bvalid = 0; + always @(posedge S_AXI_ACLK) + if (i_reset) + axil_bvalid <= 0; + else if (axil_write_ready) + axil_bvalid <= 1; + else if (S_AXI_BREADY) + axil_bvalid <= 0; + + assign S_AXI_BVALID = axil_bvalid; + assign S_AXI_BRESP = 2'b00; + // }}} + + // + // Read signaling + // + // {{{ + + generate if (OPT_SKIDBUFFER) + begin : SKIDBUFFER_READ + + wire arskd_valid; + + skidbuffer #(.OPT_OUTREG(0), + .OPT_LOWPOWER(OPT_LOWPOWER), + .DW(C_AXI_ADDR_WIDTH-ADDRLSB)) + axilarskid(// + .i_clk(S_AXI_ACLK), .i_reset(i_reset), + .i_valid(S_AXI_ARVALID), .o_ready(S_AXI_ARREADY), + .i_data(S_AXI_ARADDR[C_AXI_ADDR_WIDTH-1:ADDRLSB]), + .o_valid(arskd_valid), .i_ready(axil_read_ready), + .o_data(arskd_addr)); + + assign axil_read_ready = arskd_valid + && (!axil_read_valid || S_AXI_RREADY); + + end else begin : SIMPLE_READS + + reg axil_arready; + + always @(*) + axil_arready = !S_AXI_RVALID; + + assign arskd_addr = S_AXI_ARADDR[C_AXI_ADDR_WIDTH-1:ADDRLSB]; + assign S_AXI_ARREADY = axil_arready; + assign axil_read_ready = (S_AXI_ARVALID && S_AXI_ARREADY); + + end endgenerate + + initial axil_read_valid = 1'b0; + always @(posedge S_AXI_ACLK) + if (i_reset) + axil_read_valid <= 1'b0; + else if (axil_read_ready) + axil_read_valid <= 1'b1; + else if (S_AXI_RREADY) + axil_read_valid <= 1'b0; + + assign S_AXI_RVALID = axil_read_valid; + assign S_AXI_RDATA = axil_read_data; + assign S_AXI_RRESP = 2'b00; + // }}} + + // }}} + //////////////////////////////////////////////////////////////////////// + // + // AXI-lite register logic + // + //////////////////////////////////////////////////////////////////////// + // + // {{{ + // wire aint, bint, cint, jifint, altint; + + reg [30:0] int_vector; + + generate if (EXTERNAL_INTERRUPTS == 0) + begin + + always @(*) + begin + int_vector = 0; + int_vector[5:0] = { apic_int, tmra_int, tmrb_int, + tmrc_int, jif_int, 1'b0 }; + end + + end else if (EXTERNAL_INTERRUPTS == 1) + begin + + always @(*) + begin + int_vector = 0; + int_vector[5:0] = { apic_int, tmra_int, tmrb_int, + tmrc_int, jif_int, i_ivec[0] }; + end + + end else begin + + always @(*) + begin + int_vector = 0; + int_vector[5:0] = { apic_int, tmra_int, tmrb_int, + tmrc_int, jif_int, i_ivec[0] }; + int_vector[EXTERNAL_INTERRUPTS+5-1:6] + = i_ivec[EXTERNAL_INTERRUPTS-1:1]; + end + + end endgenerate + + icontrol #(.IUSED(15)) + pic( + .i_clk(S_AXI_ACLK), .i_reset(i_cpu_reset), + .i_wb_cyc(axil_write_ready), + .i_wb_stb(axil_write_ready && awskd_addr == 3'b000), + .i_wb_we(1'b1), .i_wb_data(wskd_data), .i_wb_sel(wskd_strb), + .o_wb_stall(pic_stall), .o_wb_ack(pic_ack),.o_wb_data(pic_data), + .i_brd_ints(int_vector[14:0]), .o_interrupt(o_interrupt)); + + ziptimer #(32,31,0) + watchdog( + .i_clk(S_AXI_ACLK), .i_reset(i_cpu_reset), + .i_ce(!i_cmd_halt), .i_wb_cyc(1'b1), + .i_wb_stb(axil_write_ready && awskd_addr == 3'b001), + .i_wb_we(1'b1), .i_wb_data(wskd_data), // .i_wb_sel(wskd_strb), + .o_wb_stall(wdog_stall), + .o_wb_ack(wdog_ack), .o_wb_data(wdog_data), + .o_int(o_watchdog_reset)); + + generate if (EXTERNAL_INTERRUPTS > 15) + begin : APIC + + icontrol #(.IUSED(15)) + apic( .i_clk(S_AXI_ACLK), .i_reset(i_cpu_reset), + .i_wb_cyc(axil_write_ready), + .i_wb_stb(axil_write_ready && awskd_addr == 3'b000), + .i_wb_we(1'b1), .i_wb_data(wskd_data), + .i_wb_sel(wskd_strb), + .o_wb_stall(apic_stall), .o_wb_ack(apic_ack), + .o_wb_data(apic_data), + .i_brd_ints(int_vector[30:15]), + .o_interrupt(o_interrupt)); + + end else begin + + assign apic_data = 0; + assign apic_stall = 0; + assign apic_ack = 0; + assign apic_int = 0; + + end endgenerate + + ziptimer + timer_a( + .i_clk(S_AXI_ACLK), .i_reset(i_cpu_reset), + .i_ce(!i_cmd_halt), .i_wb_cyc(1'b1), + .i_wb_stb(axil_write_ready && awskd_addr == 3'b100), + .i_wb_we(1'b1), .i_wb_data(wskd_data), .o_wb_stall(tmra_stall), + .o_wb_ack(tmra_ack), .o_wb_data(tmra_data), .o_int(tmra_int)); + + ziptimer + timer_b( + .i_clk(S_AXI_ACLK), .i_reset(i_cpu_reset), + .i_ce(!i_cmd_halt), .i_wb_cyc(1'b1), + .i_wb_stb(axil_write_ready && awskd_addr == 3'b101), + .i_wb_we(1'b1), .i_wb_data(wskd_data), .o_wb_stall(tmrb_stall), + .o_wb_ack(tmrb_ack), .o_wb_data(tmrb_data), .o_int(tmrb_int)); + + ziptimer + timer_c( + .i_clk(S_AXI_ACLK), .i_reset(i_cpu_reset), + .i_ce(!i_cmd_halt), .i_wb_cyc(1'b1), + .i_wb_stb(axil_write_ready && awskd_addr == 3'b110), + .i_wb_we(1'b1), .i_wb_data(wskd_data), .o_wb_stall(tmrc_stall), + .o_wb_ack(tmrc_ack), .o_wb_data(tmrc_data), .o_int(tmrc_int)); + + zipjiffies + jiffies( + .i_clk(S_AXI_ACLK), .i_reset(i_cpu_reset), + .i_ce(!i_cmd_halt), .i_wb_cyc(1'b1), + .i_wb_stb(axil_write_ready && awskd_addr == 3'b111), + .i_wb_we(1'b1), .i_wb_data(wskd_data), .o_wb_stall(jif_stall), + .o_wb_ack(jif_ack), .o_wb_data(jif_data), .o_int(jif_int)); + + initial axil_read_data = 0; + always @(posedge S_AXI_ACLK) + if (OPT_LOWPOWER && !S_AXI_ARESETN) + axil_read_data <= 0; + else if (!S_AXI_RVALID || S_AXI_RREADY) + begin + case(arskd_addr) + 3'b000: axil_read_data <= pic_data; + 3'b001: axil_read_data <= wdog_data; + // 3'b10: axil_read_data <= watchdog_data; + 3'b011: axil_read_data <= apic_data; + 3'b100: axil_read_data <= tmra_data; + 3'b101: axil_read_data <= tmrb_data; + 3'b110: axil_read_data <= tmrc_data; + 3'b111: axil_read_data <= jif_data; + default: axil_read_data <= 0; + endcase + + if (OPT_LOWPOWER && !axil_read_ready) + axil_read_data <= 0; + end + + function [C_AXI_DATA_WIDTH-1:0] apply_wstrb; + input [C_AXI_DATA_WIDTH-1:0] prior_data; + input [C_AXI_DATA_WIDTH-1:0] new_data; + input [C_AXI_DATA_WIDTH/8-1:0] wstrb; + + integer k; + for(k=0; k for a copy. +// +// License: GPL, v3, as defined and found on www.gnu.org, +// http://www.gnu.org/licenses/gpl.html +// +// +//////////////////////////////////////////////////////////////////////////////// +// +// +`default_nettype none +// }}} +module axilpipe #( + // {{{ + parameter ADDRESS_WIDTH=30, + parameter C_AXI_ADDR_WIDTH = ADDRESS_WIDTH, + parameter C_AXI_DATA_WIDTH = 32, + localparam AW = C_AXI_ADDR_WIDTH, + localparam DW = C_AXI_DATA_WIDTH, + // + // AXI locks are a challenge, and require support from the + // CPU. Specifically, we have to be able to unroll and re-do + // the load instruction on any atomic access failure. For that + // reason, we'll ignore the lock request initially. + // + // parameter [0:0] IMPLEMENT_LOCK=1'b1, + parameter [0:0] OPT_ALIGNMENT_ERR = 1'b1, + // Verilator lint_off UNUSED + // This *should* be used -- need to rewrite so that it is + parameter [0:0] OPT_LOWPOWER = 1'b0, + // Verilator lint_on UNUSED + parameter [0:0] SWAP_WSTRB = 0, + parameter [0:0] OPT_SIGN_EXTEND = 0 + // }}} + ) ( + // {{{ + input wire S_AXI_ACLK, + input wire S_AXI_ARESETN, + input wire i_cpu_reset, + // + // CPU interface + // {{{ + input wire i_stb, + input wire i_lock, + input wire [2:0] i_op, + input wire [31:0] i_addr, + input wire [31:0] i_data, + input wire [4:0] i_oreg, + output reg o_busy, + output reg o_pipe_stalled, + output reg o_rdbusy, + output reg o_valid, + output reg o_err, + output reg [4:0] o_wreg, + output reg [31:0] o_result, + // }}} + // + // AXI-Lite bus interface + // {{{ + // Writes + // {{{ + output reg M_AXI_AWVALID, + input wire M_AXI_AWREADY, + output reg [AW-1:0] M_AXI_AWADDR, + output wire [2:0] M_AXI_AWPROT, + // + output reg M_AXI_WVALID, + input wire M_AXI_WREADY, + output reg [DW-1:0] M_AXI_WDATA, + output reg [DW/8-1:0] M_AXI_WSTRB, + // + input wire M_AXI_BVALID, + output wire M_AXI_BREADY, + input wire [1:0] M_AXI_BRESP, + // }}} + // Reads + // {{{ + output reg M_AXI_ARVALID, + input wire M_AXI_ARREADY, + output reg [AW-1:0] M_AXI_ARADDR, + output wire [2:0] M_AXI_ARPROT, + // + input wire M_AXI_RVALID, + output wire M_AXI_RREADY, + input wire [DW-1:0] M_AXI_RDATA, + input wire [1:0] M_AXI_RRESP + // }}} + // }}} + // }}} + ); + + // Declarations + // {{{ + localparam AXILLSB = $clog2(C_AXI_ADDR_WIDTH/8); + localparam LGPIPE = 4; + localparam FIFO_WIDTH = AXILLSB+1+2+5 + 1; + + wire i_clk = S_AXI_ACLK; + + reg w_misaligned; + wire misaligned_request, misaligned_aw_request, pending_err, + w_misalignment_err; + reg [C_AXI_DATA_WIDTH-1:0] next_wdata; + reg [C_AXI_DATA_WIDTH/8-1:0] next_wstrb; + + + reg none_outstanding, bus_abort, + read_abort, write_abort; + reg [LGPIPE:0] beats_outstanding; + reg r_flushing, flush_request, + r_pipe_stalled; + reg [LGPIPE:0] flushcount, new_flushcount; + reg [LGPIPE:0] wraddr, rdaddr; + reg [4:0] ar_oreg; + reg [1:0] ar_op; + reg [AXILLSB-1:0] adr_lsb; + reg [FIFO_WIDTH-1:0] fifo_data [0:((1< ((M_AXI_RVALID || M_AXI_BVALID) ? 1:0)) + o_busy <= 1; + else + o_busy <= 0; +`ifdef FORMAL + always @(*) + assert(o_busy == (!none_outstanding || M_AXI_ARVALID + || M_AXI_AWVALID || M_AXI_WVALID)); +`endif + // }}} + + // Read busy + // {{{ + // True if the CPU should expect some kind of pending response from a + // read, and so should stall for that purpose. False otherwise. + initial o_rdbusy = 0; + always @(posedge S_AXI_ACLK) + if (i_cpu_reset || r_flushing) + o_rdbusy <= 0; + else if ((i_stb && w_misalignment_err) || bus_abort) + o_rdbusy <= 0; + else if (i_stb && !i_op[0]) + o_rdbusy <= 1; + else if (o_rdbusy && !M_AXI_ARVALID) + o_rdbusy <= (beats_outstanding > (M_AXI_RVALID ? 1:0)); + +`ifdef FORMAL + reg writing; + + always @(posedge S_AXI_ACLK) + if (!o_busy) + writing <= i_op[0]; + + always @(*) + begin + if (writing) + assert(!o_rdbusy); + if (r_flushing) + assert(!o_rdbusy); + if (!o_busy) + assert(!o_rdbusy); + end +`endif + // }}} + + // o_pipe_stalled, r_pipe_stalled + // {{{ + // True if the CPU should expect some kind of pending response from a + // read, and so should stall for that purpose. False otherwise. + generate if (OPT_ALIGNMENT_ERR) + begin : FULL_PIPE_STALL + // {{{ + // Here, we stall if the FIFO is ever full. In this case, + // any new beat will count as only one item to the FIFO, and + // so we can run all the way to full. + reg [LGPIPE:0] beats_committed; + + always @(*) + beats_committed = beats_outstanding + + ((i_stb && !w_misalignment_err) ? 1:0) + + ((M_AXI_AWVALID || M_AXI_WVALID + || M_AXI_ARVALID) ? 1:0); + + initial r_pipe_stalled = 0; + always @(posedge S_AXI_ACLK) + if (i_cpu_reset) + r_pipe_stalled <= 0; + else if (M_AXI_RVALID || M_AXI_BVALID) + r_pipe_stalled <= 0; + else // if (!r_pipe_stalled) + r_pipe_stalled <= (beats_committed >= (1<= (1<= (1<= (1< 1); + end + + casez({M_AXI_AWVALID && (M_AXI_AWREADY && !misaligned_aw_request), + (M_AXI_WVALID && M_AXI_WREADY && !misaligned_request), + (M_AXI_ARVALID && M_AXI_ARREADY && !misaligned_request) }) + 3'b001: flush_request <= 0; + 3'b10?: flush_request <= M_AXI_WVALID; + 3'b01?: flush_request <= M_AXI_AWVALID; + 3'b11?: flush_request <= 0; + default: begin end + endcase + // }}} + end +`ifdef FORMAL + always @(*) + begin + assert(r_flushing == (flushcount > 0)); + if (!r_flushing) + assert(!flush_request); + else + assert(flush_request == (M_AXI_AWVALID || M_AXI_WVALID || M_AXI_ARVALID)); + if (r_flushing && !flush_request) + begin + assert(!misaligned_request); + assert(!misaligned_aw_request); + end + + if (flush_request) + assert(flushcount == beats_outstanding + 1 + + ((misaligned_request + || misaligned_aw_request) ? 1:0)); + // else if (faxil_rd_outstanding > 0 || M_AXI_ARVALID) + else if (r_flushing) + assert(beats_outstanding == flushcount); + else + assert(beats_outstanding >= flushcount); + end +`endif + // }}} + + // Bus addressing + // {{{ + initial M_AXI_AWADDR = 0; + always @(posedge i_clk) + if (i_stb) + begin + M_AXI_AWADDR <= i_addr[AW-1:0]; + if (SWAP_WSTRB) + M_AXI_AWADDR[AXILLSB-1:0] <= 0; + end else if (!OPT_ALIGNMENT_ERR + && ((M_AXI_AWVALID && M_AXI_AWREADY) // && misaligned_aw_request + || (M_AXI_ARVALID && M_AXI_ARREADY))) // && misaligned_request)) + begin + M_AXI_AWADDR[AW-1:AXILLSB] <= M_AXI_AWADDR[AW-1:AXILLSB] + 1; + M_AXI_AWADDR[AXILLSB-1:0] <= 0; + end + + always @(*) + M_AXI_ARADDR = M_AXI_AWADDR; + // }}} + + // Is this request misaligned? + // {{{ + always @(*) + casez(i_op[2:1]) + // Full word + 2'b0?: w_misaligned = (i_addr[AXILLSB-1:0]+3) >= (1<= (1<> (i_addr[AXILLSB-1:0] * 8); + 2'b11: wide_wdata + = { i_data[7:0], {(2*C_AXI_DATA_WIDTH-8){1'b0}} } + >> (i_addr[AXILLSB-1:0] * 8); + default: wide_wdata + = ({ i_data, {(2*C_AXI_DATA_WIDTH-32){ 1'b0 }} } + >> (i_addr[AXILLSB-1:0] * 8)); + endcase + + casez(i_op[2:1]) + 2'b0?: wide_wstrb + = { 4'b1111, {(C_AXI_DATA_WIDTH/4-4){1'b0}} } >> i_addr[AXILLSB-1:0]; + 2'b10: wide_wstrb + = { 2'b11, {(C_AXI_DATA_WIDTH/4-2){1'b0}} } >> i_addr[AXILLSB-1:0]; + 2'b11: wide_wstrb + = { 1'b0, {(C_AXI_DATA_WIDTH/4-1){1'b0}} } >> i_addr[AXILLSB-1:0]; + endcase + // }}} + end else begin : LITTLE_ENDIAN_DATA + // {{{ + casez(i_op[2:1]) + 2'b10: wide_wdata + = { {(2*C_AXI_DATA_WIDTH-16){1'b0}}, i_data[15:0] } << (8*i_addr[AXILLSB-1:0]); + 2'b11: wide_wdata + = { {(2*C_AXI_DATA_WIDTH-8){1'b0}}, i_data[7:0] } << (8*i_addr[AXILLSB-1:0]); + default: wide_wdata + = { {(C_AXI_DATA_WIDTH){1'b0}}, i_data } + << (8*i_addr[AXILLSB-1:0]); + endcase + + casez(i_op[2:1]) + 2'b0?: wide_wstrb + = { {(C_AXI_DATA_WIDTH/4-4){1'b0}}, 4'b1111} << i_addr[AXILLSB-1:0]; + 2'b10: wide_wstrb + = { {(C_AXI_DATA_WIDTH/4-4){1'b0}}, 4'b0011} << i_addr[AXILLSB-1:0]; + 2'b11: wide_wstrb + = { {(C_AXI_DATA_WIDTH/4-4){1'b0}}, 4'b0001} << i_addr[AXILLSB-1:0]; + endcase + // }}} + end + // }}} + + // WDATA and WSTRB + // {{{ + initial M_AXI_WDATA = 0; + initial M_AXI_WSTRB = 0; + initial next_wdata = 0; + initial next_wstrb = 0; + always @(posedge i_clk) + if (i_stb) + begin + if (SWAP_WSTRB) + begin : BACKWARDS_ORDER_REG + // {{{ + { M_AXI_WDATA, next_wdata } <= wide_wdata; + { M_AXI_WSTRB, next_wstrb } <= wide_wstrb; + // }}} + end else begin + // {{{ + { M_AXI_WDATA, next_wdata } <= wide_wdata; + { M_AXI_WSTRB, next_wstrb } <= wide_wstrb; + // }}} + end + + if (OPT_ALIGNMENT_ERR) + { next_wstrb, next_wdata } <= 0; + + end else if ((OPT_LOWPOWER || !OPT_ALIGNMENT_ERR) && M_AXI_WREADY) + begin + M_AXI_WDATA <= next_wdata; + M_AXI_WSTRB <= next_wstrb; + if (OPT_LOWPOWER) + { next_wdata, next_wstrb } <= 0; + end + // }}} + + generate if (OPT_ALIGNMENT_ERR) + begin + // {{{ + // Generate an error on any misaligned request + assign misaligned_request = 1'b0; + + assign misaligned_aw_request = 1'b0; + assign pending_err = 1'b0; + // }}} + end else begin + // {{{ + reg r_misaligned_request, r_misaligned_aw_request, + r_pending_err; + + // misaligned_request + // {{{ + initial r_misaligned_request = 0; + always @(posedge i_clk) + if (!S_AXI_ARESETN) + r_misaligned_request <= 0; + else if (i_stb && !o_err && !i_cpu_reset && !bus_abort) + r_misaligned_request <= w_misaligned; + else if ((M_AXI_WVALID && M_AXI_WREADY) + || (M_AXI_ARVALID && M_AXI_ARREADY)) + r_misaligned_request <= 1'b0; + + assign misaligned_request = r_misaligned_request; + // }}} + + // misaligned_aw_request + // {{{ + initial r_misaligned_aw_request = 0; + always @(posedge i_clk) + if (!S_AXI_ARESETN) + r_misaligned_aw_request <= 0; + else if (i_stb && !o_err && !i_cpu_reset && !write_abort) + r_misaligned_aw_request <= w_misaligned && i_op[0]; + else if (M_AXI_AWREADY) + r_misaligned_aw_request <= 1'b0; + + assign misaligned_aw_request = r_misaligned_aw_request; + // }}} + + // pending_err + // {{{ + initial r_pending_err = 1'b0; + always @(posedge i_clk) + if (i_cpu_reset || i_stb || o_err || r_flushing) + r_pending_err <= 1'b0; + else if ((M_AXI_BVALID && M_AXI_BRESP[1]) + || (M_AXI_RVALID && M_AXI_RRESP[1])) + r_pending_err <= 1'b1; + + assign pending_err = r_pending_err; + // }}} + +`ifdef FORMAL + always @(*) + if (pending_err) + assert(r_flushing || o_err); +`endif + // }}} + end endgenerate + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Read transaction FIFO + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + // wraddr + // {{{ + initial wraddr = 0; + always @(posedge S_AXI_ACLK) + if (bus_abort || flush_request) // bus_abort includes i_cpu_reset + wraddr <= 0; + else if ((M_AXI_ARVALID && M_AXI_ARREADY) || (M_AXI_WVALID && M_AXI_WREADY)) + wraddr <= wraddr + 1; + // }}} + + // rdaddr + // {{{ + initial rdaddr = 0; + always @(posedge S_AXI_ACLK) + if (bus_abort || r_flushing) + rdaddr <= 0; + else if (M_AXI_RVALID||M_AXI_BVALID) + rdaddr <= rdaddr + 1; + // }}} + + // ar_oreg, ar_op, adr_lsb + // {{{ + always @(posedge S_AXI_ACLK) + if (i_stb) + { ar_oreg, ar_op, adr_lsb } <= { i_oreg, i_op[2:1], i_addr[AXILLSB-1:0] }; + else if ((M_AXI_ARVALID && M_AXI_ARREADY)||(M_AXI_WVALID && M_AXI_WREADY)) + adr_lsb <= 0; + // }}} + + // fifo_data + // {{{ + always @(posedge S_AXI_ACLK) + if ((M_AXI_ARVALID && M_AXI_ARREADY) || (M_AXI_WVALID && M_AXI_WREADY)) + fifo_data[wraddr[LGPIPE-1:0]] <= { M_AXI_ARVALID, ar_oreg,ar_op, + misaligned_request, M_AXI_ARADDR[AXILLSB-1:0] }; + + always @(*) + fifo_read_data = fifo_data[rdaddr[LGPIPE-1:0]]; + assign { fifo_read_op, fifo_return_reg, fifo_op, + fifo_misaligned, fifo_lsb } = fifo_read_data; + // }}} + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Read return generation + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + // o_valid + // {{{ + initial o_valid = 1'b0; + always @(posedge i_clk) + if (i_cpu_reset || r_flushing) + o_valid <= 1'b0; + else if (OPT_ALIGNMENT_ERR && i_stb && w_misaligned) + o_valid <= 1'b0; + else + o_valid <= M_AXI_RVALID && !M_AXI_RRESP[1] // && !pending_err + && !fifo_misaligned; + // }}} + + // o_wreg + // {{{ + always @(posedge i_clk) + o_wreg <= fifo_return_reg; + // }}} + + // o_result, misdata + // {{{ + // Need to realign any returning data + // wide_return + // {{{ + always @(*) + if (fifo_misaligned && !OPT_ALIGNMENT_ERR) + wide_return = { M_AXI_RDATA, misdata } >> (8*fifo_lsb); + else + wide_return = { {(C_AXI_DATA_WIDTH){1'b0}}, M_AXI_RDATA } + >> (8*fifo_lsb); + // }}} + + // misdata + // {{{ + always @(posedge i_clk) + if (OPT_ALIGNMENT_ERR) + misdata <= 0; + else if (M_AXI_RVALID) + begin + if (fifo_misaligned) + misdata <= M_AXI_RDATA; + else + misdata <= 0; + end + // }}} + + // o_result + // {{{ + always @(posedge i_clk) + begin + o_result <= wide_return[31:0]; + + if (OPT_SIGN_EXTEND) + begin + // {{{ + case(fifo_op) + 2'b10: o_result[31:16] <= {(16){wide_return[15]}}; + 2'b11: o_result[15: 8] <= {( 8){wide_return[ 7]}}; + endcase + // }}} + end else if (fifo_op[1]) + begin + // {{{ + if (fifo_op[0]) + o_result[15: 8] <= 0; + else + o_result[31:16] <= 0; + // }}} + end + + if (OPT_LOWPOWER&&(i_cpu_reset || |r_flushing || !M_AXI_RVALID)) + o_result <= 0; + end + // }}} + // }}} + + // o_err - report bus errors back to the CPU + // {{{ + initial o_err = 1'b0; + always @(posedge i_clk) + if (i_cpu_reset || r_flushing || o_err) + o_err <= 1'b0; + else if (OPT_ALIGNMENT_ERR && i_stb && w_misaligned) + o_err <= 1'b1; + else if (M_AXI_BVALID || M_AXI_RVALID) + o_err <= (M_AXI_BVALID && M_AXI_BRESP[1]) + || (M_AXI_RVALID && M_AXI_RRESP[1]); + else + o_err <= 1'b0; + // }}} + + // Return xREADY -- always ready + // {{{ + assign M_AXI_RREADY = 1; + assign M_AXI_BREADY = 1; + // }}} + + // AxPROT -- CPU data + // {{{ + assign M_AXI_AWPROT = 3'b000; + assign M_AXI_ARPROT = 3'b000; + + // }}} + // }}} + + // Make verilator happy + // {{{ + // verilator lint_off UNUSED + wire unused; + assign unused = &{ 1'b0, M_AXI_RRESP[0], M_AXI_BRESP[0], i_lock, + // i_addr[31:C_AXI_ADDR_WIDTH], + (&i_addr), wide_return[2*C_AXI_DATA_WIDTH-1:32], + pending_err, adr_lsb, fifo_read_op, + none_outstanding }; + // verilator lint_on UNUSED + // }}} +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal property section +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +`ifdef FORMAL + // Declarations + // {{{ +`define ASSERT assert +`ifndef BMC_ASSERT +`define BMC_ASSERT assume +`endif +`ifdef AXILPIPE +`define ASSUME assume +`else +`define ASSUME assert +`endif + localparam F_LGDEPTH = LGPIPE+1; + + wire [F_LGDEPTH-1:0] faxil_rd_outstanding, faxil_wr_outstanding, + faxil_awr_outstanding; + reg [LGPIPE:0] f_fifo_fill; + + reg f_clrfifo, f_wrfifo, f_rdfifo; + wire misaligned_response_pending; + reg [1:0] f_fsmfifo; + (* anyconst *) reg [LGPIPE:0] f_first_addr; + reg [LGPIPE:0] f_next_addr, + f_penu_addr, f_last_written, + f_distance_to_first, f_distance_to_next; + reg [FIFO_WIDTH-1:0] f_first_data, f_next_data, f_penu_data; + reg [4:0] f_first_return_reg, f_next_return_reg, f_return_reg, + f_penu_return_reg; + reg f_first_in_fifo, f_next_in_fifo, + f_first_misaligned, f_next_misaligned, + f_this_misaligned, f_penu_misaligned, + f_first_read_cycle, f_next_read_cycle, + f_this_read_cycle, f_penu_read_cycle; + + + wire [LGPIPE:0] cpu_outstanding; + wire cpu_gie, cpu_pc, cpu_read_cycle; + wire [4:0] cpu_last_reg, cpu_addr_reg; + reg [4:0] f_ar_areg; + + (* anyseq *) reg [4:0] f_areg; + reg f_done; + + + reg f_past_valid; + initial f_past_valid = 0; + always @(posedge i_clk) + f_past_valid = 1'b1; + + always @(*) + if (!f_past_valid) + `ASSUME(!S_AXI_ARESETN); + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Bus property checking + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + faxil_master #( + // {{{ + .C_AXI_DATA_WIDTH(C_AXI_DATA_WIDTH), + .C_AXI_ADDR_WIDTH(C_AXI_ADDR_WIDTH), + .F_OPT_ASSUME_RESET(1'b1), + .F_LGDEPTH(F_LGDEPTH) + // }}} + ) faxil( + // {{{ + .i_clk(S_AXI_ACLK), .i_axi_reset_n(S_AXI_ARESETN), + // + .i_axi_awvalid(M_AXI_AWVALID), + .i_axi_awready(M_AXI_AWREADY), + .i_axi_awaddr( M_AXI_AWADDR), + .i_axi_awprot( M_AXI_AWPROT), + // + .i_axi_wvalid(M_AXI_WVALID), + .i_axi_wready(M_AXI_WREADY), + .i_axi_wdata( M_AXI_WDATA), + .i_axi_wstrb( M_AXI_WSTRB), + // + .i_axi_bvalid(M_AXI_BVALID), + .i_axi_bready(M_AXI_BREADY), + .i_axi_bresp( M_AXI_BRESP), + // + .i_axi_arvalid(M_AXI_ARVALID), + .i_axi_arready(M_AXI_ARREADY), + .i_axi_araddr( M_AXI_ARADDR), + .i_axi_arprot( M_AXI_ARPROT), + // + .i_axi_rvalid(M_AXI_RVALID), + .i_axi_rready(M_AXI_RREADY), + .i_axi_rdata( M_AXI_RDATA), + .i_axi_rresp( M_AXI_RRESP), + // + .f_axi_rd_outstanding(faxil_rd_outstanding), + .f_axi_wr_outstanding(faxil_wr_outstanding), + .f_axi_awr_outstanding(faxil_awr_outstanding) + // }}} + ); + + + always @(*) + f_fifo_fill = wraddr - rdaddr; + + always @(*) + begin + if (misaligned_request) + `ASSERT(M_AXI_WVALID || M_AXI_ARVALID); + if (misaligned_aw_request) + `ASSERT(M_AXI_AWVALID); + + if (M_AXI_ARVALID || faxil_rd_outstanding > 0) + begin + assert(faxil_wr_outstanding == 0 + && faxil_awr_outstanding == 0); + assert(!M_AXI_AWVALID); + assert(!M_AXI_WVALID); + end + + if (faxil_wr_outstanding > 0 || faxil_awr_outstanding > 0 + || M_AXI_AWVALID || M_AXI_WVALID) + begin + assert(faxil_rd_outstanding == 0); + assert(!M_AXI_ARVALID); + end + + // Rule: Only one of the two VALID's may be valid, never both + `ASSERT(!M_AXI_RVALID || (!M_AXI_AWVALID && !M_AXI_WVALID)); + + assert(beats_outstanding + + ((misaligned_request && !misaligned_aw_request && M_AXI_WVALID) ? 1:0) + + ((M_AXI_WVALID && !M_AXI_AWVALID) ? 1:0) + == faxil_rd_outstanding + faxil_awr_outstanding); + + assert(beats_outstanding + + ((misaligned_aw_request && !misaligned_request) ? 1:0) + + ((M_AXI_AWVALID && !M_AXI_WVALID) ? 1:0) + == faxil_rd_outstanding + faxil_wr_outstanding); + + if (OPT_ALIGNMENT_ERR && !r_flushing + && (faxil_rd_outstanding > 0 || M_AXI_ARVALID)) + assert(f_fifo_fill == faxil_rd_outstanding); + else if (OPT_ALIGNMENT_ERR && !r_flushing + && (faxil_wr_outstanding > 0 || M_AXI_WVALID)) + assert(f_fifo_fill == faxil_wr_outstanding); + + if (faxil_rd_outstanding == 0 && faxil_wr_outstanding == 0) + assert(f_fifo_fill == 0); + end + + always @(*) + if (!o_busy) + `ASSERT(!r_flushing); + + // Following any i_stb request, assuming we are idle, immediately + // begin a bus transaction + always @(posedge i_clk) + if ((f_past_valid)&&($past(i_stb && !o_err)) + &&(!$past(o_busy))&&($past(!i_cpu_reset))) + begin + `ASSERT(o_busy || (OPT_ALIGNMENT_ERR && o_err)); + end + + always @(*) + if (o_busy && !misaligned_request && OPT_LOWPOWER) + begin + assert(next_wdata == 0); + assert(next_wstrb == 0); + end + + // o_err checking + // {{{ + // If a transaction ends in an error, send o_err on the output port. + always @(posedge i_clk) + if (f_past_valid) + begin + if ($past(i_cpu_reset || r_flushing || o_err)) + `ASSERT(!o_err); + else if ($past(M_AXI_BVALID && M_AXI_BRESP[1])) + `ASSERT(o_err); + else if ($past(M_AXI_RVALID && M_AXI_RRESP[1])) + `ASSERT(o_err); + else if (OPT_ALIGNMENT_ERR && $past(i_stb && w_misaligned)) + `ASSERT(o_err); + else if (!$past(pending_err)) + `ASSERT(!o_err); + end + // }}} + + always @(posedge i_clk) + if ((f_past_valid)&&($past(!i_cpu_reset))&&($past(i_stb))) + begin + // On a write, assert o_wb_we should be true + assert($past(i_op[0] && !o_err + && (!M_AXI_BVALID || !M_AXI_BRESP[1]) + && (!OPT_ALIGNMENT_ERR || !w_misaligned)) + == (M_AXI_AWVALID && M_AXI_WVALID)); + end + + always @(posedge i_clk) + if ((!f_past_valid)||($past(i_cpu_reset))) + `ASSUME(!i_stb); + + always @(*) + if (!S_AXI_ARESETN) + `ASSUME(i_cpu_reset); + + // misaligned_response_pending + // {{{ + generate if (OPT_ALIGNMENT_ERR) + begin : NO_MISALIGNED_RESPONSES + + assign misaligned_response_pending = 0; + + end else begin : MISALIGNED_RESPONSE_PENDING + reg r_misaligned_response_pending; + + always @(*) + begin + r_misaligned_response_pending = fifo_misaligned; + if (wraddr == rdaddr) + r_misaligned_response_pending = 0; + end + + assign misaligned_response_pending + = r_misaligned_response_pending; + end endgenerate + // }}} + + + always @(*) + if (o_busy) + begin + cover(i_stb); + cover(o_valid); + cover(o_err); + end else begin + cover(o_valid); + cover(o_err); + end + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Zero on idle checks + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + generate if (OPT_LOWPOWER) + begin + always @(*) + if (!M_AXI_AWVALID && !M_AXI_ARVALID) + `ASSERT(M_AXI_AWADDR == 0); + + always @(*) + if (!M_AXI_WVALID) + begin + `ASSERT(M_AXI_WDATA == 0); + `ASSERT(M_AXI_WSTRB == 0); + + `ASSERT(next_wdata == 0); + `ASSERT(next_wstrb == 0); + end + + end endgenerate + // }}} + //////////////////////////////////////////////////////////////////////// + // + // FIFO property checking + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + always @(*) + begin + // {{{ + f_next_addr = f_first_addr + 1; + f_last_written = wraddr - 1; + + f_penu_addr = rdaddr + 1; + f_penu_data = fifo_data[f_penu_addr[LGPIPE-1:0]]; + + f_clrfifo = (!S_AXI_ARESETN || bus_abort || flush_request); + f_wrfifo = (!f_clrfifo) && ((M_AXI_ARVALID && M_AXI_ARREADY) + || (M_AXI_WVALID && M_AXI_WREADY)); + f_rdfifo = (!f_clrfifo) && ((M_AXI_RVALID && M_AXI_RREADY) + || (M_AXI_BVALID && M_AXI_BREADY)); + + f_distance_to_first = f_first_addr - rdaddr; + f_distance_to_next = f_next_addr - rdaddr; + + f_first_in_fifo = (f_distance_to_first < f_fifo_fill) && (f_fifo_fill > 0); + f_next_in_fifo = (f_distance_to_next < f_fifo_fill) && (f_fifo_fill > 0); + + f_return_reg = fifo_return_reg; + + f_first_return_reg = f_first_data[AXILLSB+3 +: 5]; + f_next_return_reg = f_next_data[AXILLSB+3 +: 5]; + f_penu_return_reg = f_penu_data[AXILLSB+3 +: 5]; + + f_first_misaligned = f_first_data[AXILLSB]; + f_next_misaligned = f_next_data[AXILLSB]; + f_this_misaligned = fifo_read_data[AXILLSB]; + f_penu_misaligned = f_penu_data[AXILLSB]; + + f_first_read_cycle = f_first_data[FIFO_WIDTH-1]; + f_next_read_cycle = f_next_data[FIFO_WIDTH-1]; + f_this_read_cycle = fifo_read_data[FIFO_WIDTH-1]; + f_penu_read_cycle = f_penu_data[FIFO_WIDTH-1]; + // }}} + end + + always @(*) + if (r_flushing && !f_clrfifo) + assert(rdaddr == wraddr); + + always @(*) + if (!f_clrfifo) + begin + if (f_first_in_fifo) + `ASSERT(f_first_data == fifo_data[f_first_addr]); + if (f_next_in_fifo) + `ASSERT(f_next_data == fifo_data[f_next_addr]); + end + + always @(posedge S_AXI_ACLK) + if (f_wrfifo && wraddr == f_first_addr) + f_first_data <= { M_AXI_ARVALID, ar_oreg, ar_op, misaligned_request, M_AXI_ARADDR[AXILLSB-1:0] }; + + always @(posedge S_AXI_ACLK) + if (f_wrfifo && wraddr == f_next_addr) + f_next_data <= { M_AXI_ARVALID, ar_oreg, ar_op, misaligned_request, M_AXI_ARADDR[AXILLSB-1:0] }; + + // f_fsmfifo + // {{{ + initial f_fsmfifo = 2'b00; + always @(posedge S_AXI_ACLK) + if (f_clrfifo) + f_fsmfifo <= 2'b00; + else case(f_fsmfifo) + 2'b00: if (f_wrfifo && wraddr == f_first_addr) + f_fsmfifo <= 2'b01; + 2'b01: if (f_rdfifo && rdaddr == f_first_addr) + f_fsmfifo <= 2'b00; + else if (f_wrfifo && wraddr == f_next_addr) + f_fsmfifo <= 2'b10; + 2'b10: if (f_rdfifo && rdaddr == f_first_addr) + f_fsmfifo <= 2'b11; + 2'b11: if (f_rdfifo) + f_fsmfifo <= 2'b00; + endcase + + always @(*) + if (!f_clrfifo) + case(f_fsmfifo) + 2'b00: begin + // {{{ + `ASSERT(!f_first_in_fifo); + end + // }}} + 2'b01: begin + // {{{ + `ASSERT(f_fifo_fill >= 1); + `ASSERT(f_first_in_fifo); + end + // }}} + 2'b10: begin + // {{{ + `ASSERT(f_fifo_fill >= 2); + `ASSERT(f_first_in_fifo); + `ASSERT(f_next_in_fifo); + end + // }}} + 2'b11: begin + // {{{ + `ASSERT(f_fifo_fill >= 1); + `ASSERT(f_next_in_fifo); + end + // }}} + endcase + // }}} + + // { ar_oreg, ar_op, misaligned_request, M_AXI_ARADDR[AXILLSB-1:0] }; + + // cpu_gie checks + // {{{ + always @(*) + if (M_AXI_ARVALID) + `ASSERT(cpu_gie == ar_oreg[4]); + + always @(*) + if (!f_clrfifo && f_fifo_fill != 0) + begin + if (M_AXI_ARVALID || M_AXI_WVALID || M_AXI_AWVALID) + `ASSERT(cpu_gie == ar_oreg[4]); + + if ((!f_first_in_fifo || rdaddr != f_first_addr) + && (!f_next_in_fifo || rdaddr != f_next_addr) + && (f_fifo_fill > 0)) + `ASSUME(cpu_gie == f_return_reg[4]); + + if (f_first_in_fifo) + `ASSERT(cpu_gie == f_first_return_reg[4]); + if (f_next_in_fifo) + `ASSERT(cpu_gie == f_next_return_reg[4]); + end + // }}} + + // cpu_pc checks + // {{{ + always @(*) + if (M_AXI_ARVALID) + `ASSERT(cpu_pc == ((&ar_oreg[3:1]) && (o_err || !flush_request))); + + always @(*) + if (!f_clrfifo && f_fifo_fill != 0) + begin + if ((M_AXI_ARVALID || (rdaddr != f_last_written))) + `ASSERT(f_this_misaligned || !cpu_read_cycle || !(&f_return_reg[3:1])); + else if (f_fifo_fill > 0 && !M_AXI_ARVALID) + `ASSERT(f_this_misaligned || !cpu_read_cycle || cpu_pc == (&f_return_reg[3:1])); + + if ((!f_first_in_fifo || rdaddr != f_first_addr) + && (!f_next_in_fifo || rdaddr != f_next_addr) + && cpu_read_cycle) + begin + if (M_AXI_ARVALID) // && (&ar_oreg[3:1])) + `ASSUME(!(&f_return_reg[3:1])); + else if (rdaddr != f_last_written) + `ASSUME(!(&f_return_reg[3:1])); + else if (!M_AXI_ARVALID && !o_err) + `ASSUME(cpu_pc == (&f_return_reg[3:1])); // Not last written + end + + if (f_first_in_fifo && cpu_read_cycle) + begin + if (!cpu_pc || M_AXI_ARVALID + || (f_last_written != f_first_addr)) + `ASSERT(f_first_misaligned || !cpu_read_cycle || !(&f_first_return_reg[3:1])); + else if (!M_AXI_ARVALID && !o_err) + `ASSERT(&f_first_return_reg[3:1]); + end + + if (f_next_in_fifo && cpu_read_cycle) + begin + if (!cpu_pc || M_AXI_ARVALID + || (f_last_written != f_next_addr)) + `ASSERT(f_next_misaligned || !(&f_next_return_reg[3:1])); + else if (!M_AXI_ARVALID && !o_err) + `ASSERT(&f_next_return_reg[3:1]); + end + + if (M_AXI_ARVALID) + `ASSERT(cpu_pc == (&ar_oreg[3:1])); + end + // }}} + + always @(*) + if (cpu_read_cycle && !r_flushing) + assert(o_rdbusy==((rdaddr != wraddr)||(M_AXI_ARVALID))); + + always @(*) + if (cpu_read_cycle) + assert(!M_AXI_AWVALID && !M_AXI_WVALID && faxil_awr_outstanding == 0); + + // Verifying the alignment flags + // {{{ + always @(*) + if (M_AXI_ARVALID && OPT_ALIGNMENT_ERR) + assert(!misaligned_request); + + always @(*) + if (!f_clrfifo && f_fifo_fill != 0) + begin + if (OPT_ALIGNMENT_ERR) + begin + // {{{ + if (f_first_in_fifo) + `ASSERT(!f_first_misaligned); + if (f_next_in_fifo) + `ASSERT(!f_next_misaligned); + if ((!f_first_in_fifo || rdaddr != f_first_addr) + && (!f_next_in_fifo || rdaddr != f_next_addr)) + `ASSUME(!f_this_misaligned); + // }}} + end else begin + // {{{ + if (f_first_in_fifo && f_first_misaligned) + begin + if (f_next_in_fifo) + `ASSERT(!f_next_misaligned); + else begin + `ASSERT(!misaligned_request); + `ASSERT(M_AXI_ARVALID || M_AXI_WVALID); + end + end + + if (misaligned_response_pending + && (!f_first_in_fifo || rdaddr != f_first_addr)) + begin + if (f_fifo_fill > 1) + `BMC_ASSERT(!f_penu_misaligned); + else if (f_fifo_fill == 1) + `BMC_ASSERT(!misaligned_request); + end + // }}} + end + end + // }}} + + // Verifying unaligned registers remain the same + // {{{ + always @(*) + if (!f_clrfifo && f_fifo_fill != 0 && !OPT_ALIGNMENT_ERR) + begin + if (f_first_in_fifo && f_first_misaligned) + begin + if (f_next_in_fifo) + begin + `ASSERT(f_first_return_reg == f_next_return_reg); + end else begin + `ASSERT(M_AXI_ARVALID || M_AXI_WVALID); + `ASSERT(!misaligned_request); + `ASSERT(f_first_return_reg == ar_oreg); + end + end + + if (misaligned_response_pending + && (!f_first_in_fifo || rdaddr != f_first_addr)) + begin + if (f_fifo_fill == 1) + begin + `BMC_ASSERT(M_AXI_ARVALID || M_AXI_WVALID); + `BMC_ASSERT(!misaligned_request); + `BMC_ASSERT(f_first_return_reg == ar_oreg); + end else + `BMC_ASSERT(fifo_return_reg == f_penu_return_reg); + end + end + // }}} + + always @(*) + assert(f_fifo_fill <= (1< 0) + begin + if (f_first_in_fifo) + `ASSERT(cpu_read_cycle == f_first_read_cycle); + if (f_next_in_fifo) + `ASSERT(cpu_read_cycle == f_next_read_cycle); + + if (// f_fifo_fill > 0 && // Redundant + (!f_first_in_fifo || rdaddr != f_first_addr) + && (!f_next_in_fifo || rdaddr != f_next_addr)) + begin + `BMC_ASSERT(cpu_read_cycle == f_this_read_cycle); + end + + if (f_fifo_fill > 1 + && (!f_first_in_fifo || f_penu_addr != f_first_addr) + && (!f_next_in_fifo || f_penu_addr != f_next_addr)) + begin + `BMC_ASSERT(cpu_read_cycle == f_penu_read_cycle); + end + + if (cpu_read_cycle) + begin + `ASSERT(!M_AXI_AWVALID && !M_AXI_WVALID); + `ASSERT(faxil_awr_outstanding == 0); + `ASSERT(faxil_wr_outstanding == 0); + end + end + // }}} + + // Verifying the cpu_last_reg + // {{{ + always @(*) + if (M_AXI_WVALID || M_AXI_ARVALID) + assert(cpu_last_reg == ar_oreg); + else if (!f_clrfifo && f_fifo_fill > 0) + begin + if (f_first_in_fifo && f_first_addr == f_last_written) + assert(f_first_return_reg == cpu_last_reg); + if (f_next_in_fifo && f_next_addr == f_last_written) + assert(f_next_return_reg == cpu_last_reg); + if (rdaddr == f_last_written + && (rdaddr != f_first_addr) + && (rdaddr != f_next_addr)) + `BMC_ASSERT(fifo_return_reg == cpu_last_reg); + end + // }}} + + // Verifying the cpu_addr_reg + // {{{ + always @(posedge S_AXI_ACLK) + if (i_stb) + f_ar_areg <= f_areg; + + always @(*) + if (o_rdbusy) + `ASSERT(f_ar_areg == cpu_addr_reg); + + always @(*) + if (!f_clrfifo && o_rdbusy && f_fifo_fill > 0) + begin + if (f_first_in_fifo && f_first_addr != f_last_written) + assert(f_first_return_reg != cpu_addr_reg + || f_first_misaligned); + if (f_next_in_fifo && f_next_addr != f_last_written) + assert(f_next_return_reg != cpu_addr_reg + || f_next_misaligned); + + // If the base address register exists in the FIFO, then it + // can't be part of any current requests. + if ((f_first_in_fifo && (f_first_return_reg == cpu_addr_reg) && !f_first_misaligned) + ||(f_next_in_fifo && (f_next_return_reg == cpu_addr_reg) && !f_next_misaligned)) + assert(!M_AXI_WVALID && !M_AXI_ARVALID); + + if ((rdaddr != f_last_written || M_AXI_WVALID || M_AXI_ARVALID) + && !misaligned_response_pending + && (cpu_outstanding > (o_valid ? 1:0)) + && (rdaddr != f_first_addr) + && (rdaddr != f_next_addr)) + `BMC_ASSERT(fifo_return_reg != cpu_addr_reg); + end + + // }}} + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Contract properties + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + initial f_done = 1'b0; + always @(posedge i_clk) + if (i_cpu_reset || r_flushing) + f_done <= 1'b0; + else + f_done <= (M_AXI_RVALID && !M_AXI_RRESP[1] + || M_AXI_BVALID && !M_AXI_BRESP[1]) && !pending_err + && !misaligned_response_pending; + + + fmem #( + // {{{ + .F_LGDEPTH(LGPIPE+1), .OPT_MAXDEPTH(1< 0) + `ASSERT(r_flushing); + + always @(*) + if (!o_err && cpu_outstanding > 0) + begin + if (faxil_rd_outstanding > 0 || M_AXI_ARVALID || o_rdbusy) + assert(cpu_read_cycle); + else if (faxil_awr_outstanding > 0 || faxil_wr_outstanding > 0 + || M_AXI_AWVALID || M_AXI_WVALID) + assert(!cpu_read_cycle); + end + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Cover properties + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + reg [LGPIPE:0] cvr_writes, cvr_reads, cvr_valids; + reg cvr_idle; + + always @(*) + begin + cvr_idle = 1; + if (i_cpu_reset || o_err || f_done) + cvr_idle = 1'b0; + if (M_AXI_AWVALID || M_AXI_WVALID || M_AXI_ARVALID) + cvr_idle = 1'b0; + if (faxil_awr_outstanding > 0) + cvr_idle = 1'b0; + if (faxil_wr_outstanding > 0) + cvr_idle = 1'b0; + if (faxil_rd_outstanding > 0) + cvr_idle = 1'b0; + end + + initial cvr_writes = 0; + always @(posedge i_clk) + if (i_cpu_reset || o_err) + cvr_writes <= 0; + else if (M_AXI_BVALID&& !misaligned_response_pending && !(&cvr_writes)) + cvr_writes <= cvr_writes + 1; + + initial cvr_reads = 0; + always @(posedge i_clk) + if (i_cpu_reset || o_err) + cvr_reads <= 0; + else if (M_AXI_RVALID && !misaligned_response_pending && !(&cvr_reads)) + cvr_reads <= cvr_reads + 1; + + initial cvr_valids = 0; + always @(posedge i_clk) + if (i_cpu_reset || o_err) + cvr_valids <= 0; + else if (o_valid) + cvr_valids <= cvr_valids + 1; + + // Cover a write response + always @(posedge i_clk) + cover(M_AXI_BVALID && !M_AXI_BRESP[1]); + always @(posedge i_clk) + cover(M_AXI_BVALID && M_AXI_BRESP[1]); + + always @(posedge i_clk) + cover(M_AXI_RVALID && !M_AXI_RRESP[1]); + always @(posedge i_clk) + cover(M_AXI_RVALID && M_AXI_RRESP[1]); + + + always @(posedge i_clk) + if (cvr_idle) + begin + cover(cvr_writes > 3); + cover(cvr_reads > 3); + cover(cvr_valids > 3); + + cover(cvr_writes > (1< (1< (1< (1< (1< (1< 3); + cover(cvr_unaligned_reads > 3); + + cover(cvr_unaligned_writes > (1< (1<= (f_done ? 1:0) + + faxil_rd_outstanding[F_LGDEPTH-1:1]); + else if (!r_flushing) + `BMC_ASSERT(cpu_outstanding >= (f_done ? 1:0) + + faxil_wr_outstanding[F_LGDEPTH-1:1]); + + if (!r_flushing && !o_err) + assert(f_fifo_fill == beats_outstanding + + ((misaligned_aw_request && !misaligned_request) ? 1:0) + + (M_AXI_AWVALID && !M_AXI_WVALID)); + + if (!r_flushing && !o_err) + `BMC_ASSERT((cpu_outstanding == 0) == (!M_AXI_AWVALID + && !M_AXI_WVALID && !M_AXI_ARVALID + && (beats_outstanding + (f_done ? 1:0) == 0))); + else if (o_err) + `BMC_ASSERT(cpu_outstanding > 0); + + + if (!r_flushing && !o_err && cpu_outstanding == (f_done ? 1:0)) + `BMC_ASSERT(beats_outstanding == 0 + && !M_AXI_AWVALID && !M_AXI_WVALID + && !M_AXI_ARVALID); + end + + // }}} +`endif +// }}} +endmodule diff --git a/rtl/cpu/axiops.v b/rtl/cpu/axiops.v new file mode 100644 index 0000000..38fe90e --- /dev/null +++ b/rtl/cpu/axiops.v @@ -0,0 +1,905 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Filename: axiops.v +// {{{ +// Project: Zip CPU -- a small, lightweight, RISC CPU soft core +// +// Purpose: A memory unit to support a CPU based upon AXI4. This is about +// the simplest AXI4 interface I can design for this purpose. +// +// Creator: Dan Gisselquist, Ph.D. +// Gisselquist Technology, LLC +// +//////////////////////////////////////////////////////////////////////////////// +// }}} +// Copyright (C) 2020-2021, Gisselquist Technology, LLC +// {{{ +// This program is free software (firmware): 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 MERCHANTIBILITY 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. (It's in the $(ROOT)/doc directory. Run make with no +// target there if the PDF file isn't present.) If not, see +// for a copy. +// }}} +// License: GPL, v3, as defined and found on www.gnu.org, +// {{{ +// http://www.gnu.org/licenses/gpl.html +// +//////////////////////////////////////////////////////////////////////////////// +// +// +`default_nettype none +// }}} +module axiops #( + // {{{ + parameter C_AXI_ADDR_WIDTH = 32, + parameter C_AXI_DATA_WIDTH = 32, + parameter C_AXI_ID_WIDTH = 1, + localparam ADDRESS_WIDTH=C_AXI_ADDR_WIDTH, + parameter [((C_AXI_ID_WIDTH > 0)? C_AXI_ID_WIDTH:1)-1:0] + AXI_ID = 0, + // + // SWAP_ENDIANNESS + // {{{ + // The ZipCPU was designed to be a big endian machine. With + // no other adjustments, this design will make the ZipCPU + // *little* endian, for the simple reason that the AXI bus is + // a little endian bus. However, if SWAP_ENDIANNESS is set, + // the bytes within 32-bit words on the AXI bus will be swapped. + // This will return the CPU to being a big endian CPU on a + // little endian bus. It will also break any design that + // assumes the bus is presented to it in its proper order. + // Simple things like counters or interrupt controllers will + // therefore cease to work with this option unless they also + // swap the endianness of the words they are given. + parameter [0:0] SWAP_ENDIANNESS = 1'b0, + // }}} + // SWAP_WSTRB + // {{{ + // SWAP_WSTRB represents a second attempt to fix the endianness + // issue. It is incompatible with the SWAP_ENDIANNESS option + // above. If SWAP_WSTRB is set, then half words and words will + // be placed on the bus in little endian order, but at big + // endian addresses. Words written to the bus will be written + // in little endian order. Halfwords written to the bus at + // address 2 will be written to address 0, halfwords written to + // address 0 will be written to address 2. Bytes written to the + // but at address 3 will be written to address 0, address 2 + // will be written to address 1, address 1 to address 2, and + // address 3 to address 0. + // + // This may just be a half baked attempt to solve this problem, + // since it will fail if you ever trie to access bytes or + // halfwords at other than their intended widths. + parameter [0:0] SWAP_WSTRB = 1'b0, + // }}} + // OPT_SIGN_EXTEND + // {{{ + // Some CPU's want memory accesses to be sign extended upon + // return. The ZipCPU is not one of those CPU's. However, + // since it's fairly easy to do so, we'll implement this logic + // if ever OPT_SIGN_EXTEND is true so you can see how it would + // be done if necessary. + parameter [0:0] OPT_SIGN_EXTEND = 1'b0, + // }}} + parameter [0:0] OPT_LOCK=1'b1, + // OPT_ALIGNMENT_ERR + // {{{ + // If set, OPT_ALIGNMENT_ERR will generate an alignment error + // on any attempt to write to or read from an unaligned word. + // If not set, unaligned reads (or writes) will be expanded into + // pairs so as to still accomplish the action requested. The + // bus does not guarantee protection, however, that these two + // writes or two reads will proceed uninterrupted. Since + // unaligned writes and unaligned reads are no longer + // guaranteed to be atomic by the AXI bus, it is possible that + // any unaligned operations might yield an incoherent result. + parameter [0:0] OPT_ALIGNMENT_ERR = 1'b0, + // }}} + // OPT_LOWPOWER + // {{{ + // If set, the design will use extra logic to guarantee that any + // unused registers are kept at zero until they are used. This + // will help to guarantee the design (ideally) has fewer + // transitions and therefore uses lower power. + parameter [0:0] OPT_LOWPOWER = 1'b1, + // }}} + parameter [3:0] OPT_QOS = 0, + localparam IW = (C_AXI_ID_WIDTH > 0) ? C_AXI_ID_WIDTH:1, + localparam AW = C_AXI_ADDR_WIDTH, + localparam DW = C_AXI_DATA_WIDTH, + localparam AXILSB = $clog2(C_AXI_DATA_WIDTH/8) + // }}} + ) ( + // {{{ + input wire S_AXI_ACLK, + input wire S_AXI_ARESETN, + input wire i_cpu_reset, + // + // CPU interface + // {{{ + input wire i_stb, + input wire i_lock, + input wire [2:0] i_op, + input wire [AW-1:0] i_addr, + input wire [AW-1:0] i_restart_pc, + input wire [31:0] i_data, + input wire [4:0] i_oreg, + output reg o_busy, + output reg o_rdbusy, + output reg o_valid, + output reg o_err, + output reg [4:0] o_wreg, + output reg [31:0] o_result, + // }}} + // AXI4 bus interface + // + // Writes + // {{{ + output reg M_AXI_AWVALID, + input wire M_AXI_AWREADY, + output wire [IW-1:0] M_AXI_AWID, + output reg [AW-1:0] M_AXI_AWADDR, + output wire [7:0] M_AXI_AWLEN, + output wire [2:0] M_AXI_AWSIZE, + output wire [1:0] M_AXI_AWBURST, + output wire M_AXI_AWLOCK, + output wire [3:0] M_AXI_AWCACHE, + output wire [2:0] M_AXI_AWPROT, + output wire [3:0] M_AXI_AWQOS, + // + output reg M_AXI_WVALID, + input wire M_AXI_WREADY, + output reg [DW-1:0] M_AXI_WDATA, + output reg [DW/8-1:0] M_AXI_WSTRB, + output wire M_AXI_WLAST, + // + input wire M_AXI_BVALID, + output reg M_AXI_BREADY, + input wire [IW-1:0] M_AXI_BID, + input wire [1:0] M_AXI_BRESP, + // }}} + // Reads + // {{{ + output reg M_AXI_ARVALID, + input wire M_AXI_ARREADY, + output wire [IW-1:0] M_AXI_ARID, + output reg [AW-1:0] M_AXI_ARADDR, + output wire [7:0] M_AXI_ARLEN, + output wire [2:0] M_AXI_ARSIZE, + output wire [1:0] M_AXI_ARBURST, + output wire M_AXI_ARLOCK, + output wire [3:0] M_AXI_ARCACHE, + output wire [2:0] M_AXI_ARPROT, + output wire [3:0] M_AXI_ARQOS, + // + input wire M_AXI_RVALID, + output reg M_AXI_RREADY, + input wire [IW-1:0] M_AXI_RID, + input wire [DW-1:0] M_AXI_RDATA, + input wire M_AXI_RLAST, + input wire [1:0] M_AXI_RRESP + // }}} + // }}} + ); + + // Declarations + // {{{ + localparam CPU_DATA_WIDTH = 32; + // Verilator lint_off WIDTH + localparam [2:0] DSZ = $clog2(CPU_DATA_WIDTH/8); + // Verilator lint_on WIDTH + localparam [1:0] AXI_INCR = 2'b01, + OKAY = 2'b00, + EXOKAY = 2'b01; + + wire i_clk = S_AXI_ACLK; + // wire i_reset = !S_AXI_ARESETN; + + reg w_misaligned, w_misalignment_err; + wire misaligned_request, misaligned_aw_request, + misaligned_response_pending, pending_err, misaligned_read; + reg r_flushing; + reg [AW-1:0] r_pc; + reg [AXILSB+1:0] r_op; + reg [DW-1:0] next_wdata; + reg [DW/8-1:0] next_wstrb; + reg [31:0] last_result; + // reg [31:0] endian_swapped_wdata; + // reg [31:0] endian_swapped_result; + reg [2*DW/8-1:0] shifted_wstrb_word, + shifted_wstrb_halfword, + shifted_wstrb_byte; + reg [2*DW/8-1:0] swapped_wstrb_word, + swapped_wstrb_halfword, + swapped_wstrb_byte; + reg [DW-1:0] axi_wdata; + reg [DW/8-1:0] axi_wstrb; + reg r_lock; + reg [AXILSB-1:0] swapaddr; + wire [DW-1:0] endian_swapped_rdata; + reg [2*DW-1:0] pre_result; + + // }}} + + // xVALID, and xREADY + // {{{ + initial M_AXI_AWVALID = 1'b0; + initial M_AXI_WVALID = 1'b0; + initial M_AXI_ARVALID = 1'b0; + initial M_AXI_BREADY = 1'b0; + initial M_AXI_RREADY = 1'b0; + always @(posedge i_clk) + if (!S_AXI_ARESETN) + begin + // {{{ + M_AXI_AWVALID <= 1'b0; + M_AXI_WVALID <= 1'b0; + M_AXI_ARVALID <= 1'b0; + M_AXI_BREADY <= 1'b0; + M_AXI_RREADY <= 1'b0; + // }}} + end else if (M_AXI_BREADY || M_AXI_RREADY) + begin // Something is outstanding + // {{{ + if (M_AXI_AWREADY) + M_AXI_AWVALID <= M_AXI_AWVALID && misaligned_aw_request; + if (M_AXI_WREADY) + M_AXI_WVALID <= M_AXI_WVALID && misaligned_request; + if (M_AXI_ARREADY) + M_AXI_ARVALID <= M_AXI_ARVALID && misaligned_request; + + if ((M_AXI_BVALID || M_AXI_RVALID) && !misaligned_response_pending) + begin + M_AXI_BREADY <= 1'b0; + M_AXI_RREADY <= 1'b0; + end + // }}} + end else begin // New memory operation + // {{{ + // Initiate a request + M_AXI_AWVALID <= i_op[0]; // Write request + M_AXI_WVALID <= i_op[0]; // Write request + M_AXI_ARVALID <= !i_op[0]; // Read request + + // Set BREADY or RREADY to accept the response. These will + // remain ready until the response is returned. + M_AXI_BREADY <= i_op[0]; + M_AXI_RREADY <= !i_op[0]; + + if (i_cpu_reset || o_err || !i_stb || w_misalignment_err) + begin + M_AXI_AWVALID <= 0; + M_AXI_WVALID <= 0; + M_AXI_ARVALID <= 0; + + M_AXI_BREADY <= 0; + M_AXI_RREADY <= 0; + end + // }}} + end + // }}} + + // r_lock + // {{{ + initial r_lock = 1'b0; + always @(posedge i_clk) + if (!OPT_LOCK || (!S_AXI_ARESETN && OPT_LOWPOWER)) + begin + // {{{ + r_lock <= 1'b0; + // }}} + end else if (M_AXI_BREADY || M_AXI_RREADY) + begin // Something is outstanding + // {{{ + if (OPT_LOWPOWER && (M_AXI_BVALID || M_AXI_RVALID)) + r_lock <= 1'b0; + // }}} + end else begin // New memory operation + // {{{ + // Initiate a request + r_lock <= i_lock && i_stb; + + if (OPT_LOWPOWER && (i_cpu_reset || o_err || w_misaligned)) + r_lock <= 1'b0; + // }}} + end + + assign M_AXI_AWLOCK = r_lock; + assign M_AXI_ARLOCK = r_lock; + // }}} + + // r_flushing + // {{{ + initial r_flushing = 1'b0; + always @(posedge i_clk) + if (!S_AXI_ARESETN) + // If everything is reset, then we don't need to worry about + // or wait for any pending returns--they'll be canceled by the + // global reset. + r_flushing <= 1'b0; + else if (M_AXI_BREADY || M_AXI_RREADY) + begin + if (i_cpu_reset) + // If only the CPU is reset, however, we have a problem. + // The bus hasn't been reset, and so it is still active. + // We can't respond to any new requests from the CPU + // until we flush any transactions that are currently + // active. + r_flushing <= 1'b1; + if (M_AXI_BVALID || M_AXI_RVALID) + // A request just came back, therefore we can clear + // r_flushing + r_flushing <= 1'b0; + if (misaligned_response_pending) + // ... unless we're in the middle of a misaligned + // request. In that case, there will be a second + // return that we still need to wait for. This request, + // though, will clear misaligned_response_pending. + r_flushing <= r_flushing || i_cpu_reset; + end else + // If nothing is active, we don't care about the CPU reset. + // Flushing just stays at zero. + r_flushing <= 1'b0; + // }}} + + // M_AXI_AxADDR + // {{{ + initial M_AXI_AWADDR = 0; + always @(posedge i_clk) + if (!S_AXI_ARESETN && OPT_LOWPOWER) + M_AXI_AWADDR <= 0; + else if (!M_AXI_BREADY && !M_AXI_RREADY) + begin // Initial address + // {{{ + M_AXI_AWADDR <= i_addr; + + if (OPT_LOWPOWER && (i_cpu_reset || o_err || !i_stb || w_misalignment_err)) + M_AXI_AWADDR <= 0; + + if (SWAP_ENDIANNESS || SWAP_WSTRB) + // When adjusting endianness, reads (or writes) are + // always full words. This is important since the + // the bytes at issues may (or may not) be in their + // expected locations + M_AXI_AWADDR[AXILSB-1:0] <= 0; + // }}} + end else if ((M_AXI_AWVALID && M_AXI_AWREADY) + ||(M_AXI_ARVALID && M_AXI_ARREADY)) + begin // Subsequent addresses + // {{{ + M_AXI_AWADDR[C_AXI_ADDR_WIDTH-1:AXILSB] + <= M_AXI_AWADDR[C_AXI_ADDR_WIDTH-1:AXILSB] + 1; + + M_AXI_AWADDR[AXILSB-1:0] <= 0; + + if (OPT_LOWPOWER && ((M_AXI_RREADY && !misaligned_request) + || (M_AXI_BREADY && !misaligned_aw_request))) + M_AXI_AWADDR <= 0; + // }}} + end + + always @(*) + M_AXI_ARADDR = M_AXI_AWADDR; + // }}} + + // M_AXI_AxSIZE + // {{{ + reg [2:0] awsize; + + initial awsize = 3'b010; + always @(posedge i_clk) + if (!S_AXI_ARESETN) + awsize <= 3'b010; + else if (!M_AXI_BREADY && !M_AXI_RREADY && (!OPT_LOWPOWER || i_stb)) + begin + casez(i_op[2:1]) + 2'b0?: awsize <= 3'b010; + 2'b10: awsize <= 3'b001; + 2'b11: awsize <= 3'b000; + // default: begin end + endcase + end + + assign M_AXI_AWSIZE = awsize; + assign M_AXI_ARSIZE = M_AXI_AWSIZE; + // }}} + + // AxOTHER + // {{{ + localparam [3:0] AXI_NON_CACHABLE_BUFFERABLE = 4'h3; + localparam [3:0] OPT_CACHE = AXI_NON_CACHABLE_BUFFERABLE; + localparam [2:0] AXI_UNPRIVILEGED_NONSECURE_DATA_ACCESS = 3'h0; + localparam [2:0] OPT_PROT=AXI_UNPRIVILEGED_NONSECURE_DATA_ACCESS; + + assign M_AXI_AWID = AXI_ID; + assign M_AXI_AWLEN = 0; + assign M_AXI_AWBURST = AXI_INCR; + assign M_AXI_AWCACHE = M_AXI_AWLOCK ? 0: OPT_CACHE; + assign M_AXI_AWPROT = OPT_PROT; + assign M_AXI_AWQOS = OPT_QOS; + assign M_AXI_WLAST = 1; + + assign M_AXI_ARID = AXI_ID; + assign M_AXI_ARLEN = 0; + assign M_AXI_ARBURST = AXI_INCR; + assign M_AXI_ARCACHE = M_AXI_ARLOCK ? 0: OPT_CACHE; + assign M_AXI_ARPROT = OPT_PROT; + assign M_AXI_ARQOS = OPT_QOS; + // }}} + + // shifted_wstrb_* + // {{{ + always @(*) + shifted_wstrb_word = { {(2*DW/8-4){1'b0}}, + 4'b1111} << i_addr[AXILSB-1:0]; + + always @(*) + shifted_wstrb_halfword = { {(2*DW/8-4){1'b0}}, + 4'b0011} << i_addr[AXILSB-1:0]; + + always @(*) + shifted_wstrb_byte = { {(2*DW/8-4){1'b0}}, + 4'b0001} << i_addr[AXILSB-1:0]; + // }}} + + // Swapping WSTRB bits + // {{{ + generate if (SWAP_WSTRB) + begin : SWAPPING_WSTRB + // {{{ + genvar gw, gb; + + for(gw=0; gw<2*DW/32; gw=gw+1) + begin : FOREACH_32B_WORD + for(gb=0; gb<32/8; gb=gb+1) + begin : FOREACH_BYTE + + always @(*) + begin + swapped_wstrb_word[gw*4+gb] + = shifted_wstrb_word[gw*4+(3-gb)]; + swapped_wstrb_halfword[gw*4+gb] + = shifted_wstrb_halfword[gw*4+(3-gb)]; + swapped_wstrb_byte[gw*4+gb] + = shifted_wstrb_byte[gw*4+(3-gb)]; + end end end + // }}} + end else begin : KEEP_WSTRB + // {{{ + + always @(*) + swapped_wstrb_word = shifted_wstrb_word; + + always @(*) + swapped_wstrb_halfword = shifted_wstrb_halfword; + + always @(*) + swapped_wstrb_byte = shifted_wstrb_byte; + // }}} + end endgenerate + // }}} + + // wdata, wstrb + // {{{ + always @(*) + begin + swapaddr = i_addr[AXILSB-1:0]; + if (SWAP_WSTRB) + swapaddr[1:0] = 3 - i_addr[1:0]; + end + + initial axi_wdata = 0; + initial axi_wstrb = 0; + initial next_wdata = 0; + initial next_wstrb = 0; + always @(posedge i_clk) + if (OPT_LOWPOWER && !S_AXI_ARESETN) + begin + // {{{ + axi_wdata <= 0; + axi_wstrb <= 0; + + next_wdata <= 0; + next_wstrb <= 0; + + r_op <= 0; + // }}} + end else if (i_stb) + begin + // {{{ + casez(i_op[2:1]) + 2'b10: { next_wdata, axi_wdata } + <= { {(2*C_AXI_DATA_WIDTH-16){1'b0}}, + i_data[15:0] } << (8*swapaddr); + 2'b11: { next_wdata, axi_wdata } + <= { {(2*C_AXI_DATA_WIDTH-8){1'b0}}, + i_data[7:0] } << (8*swapaddr); + default: { next_wdata, axi_wdata } + <= { {(2*C_AXI_DATA_WIDTH-32){1'b0}}, + i_data } << (8*swapaddr); + endcase + + // next_wstrb, axi_wstrb + // {{{ + casez(i_op[2:1]) + 2'b0?: { next_wstrb, axi_wstrb } <= swapped_wstrb_word; + 2'b10: { next_wstrb, axi_wstrb } <= swapped_wstrb_halfword; + 2'b11: { next_wstrb, axi_wstrb } <= swapped_wstrb_byte; + endcase + // }}} + + r_op <= { i_op[2:1] , i_addr[AXILSB-1:0] }; + + // On a read set everything to zero but only if OPT_LOWPOWER + // is set + // {{{ + if (OPT_LOWPOWER && !i_op[0]) + { next_wstrb, next_wdata, axi_wstrb, axi_wdata } <= 0; + + if (w_misalignment_err) + { next_wstrb, next_wdata } <= 0; + if (OPT_LOWPOWER) + begin + if (w_misalignment_err) + { axi_wdata, axi_wstrb, r_op } <= 0; + if (o_err || i_cpu_reset) + { next_wdata, next_wstrb, + axi_wdata, axi_wstrb, r_op } <= 0; + end + // }}} + // }}} + end else if ((misaligned_request || !OPT_LOWPOWER) && M_AXI_WREADY) + begin + // {{{ + axi_wdata <= next_wdata; + axi_wstrb <= next_wstrb; + if (OPT_LOWPOWER) + { next_wdata, next_wstrb } <= 0; + // }}} + end else if (OPT_LOWPOWER && M_AXI_WREADY) + begin + // {{{ + axi_wdata <= 0; + axi_wstrb <= 0; + // }}} + end + // }}} + + // M_AXI_WDATA, M_AXI_WSTRB + // {{{ + generate if (SWAP_ENDIANNESS) + begin : SWAP_WRITE_DATA_STRB + // {{{ + genvar gw, gb; + + for(gw=0; gw= (1<= (1<> (8*r_op[AXILSB-1:0]); + else + pre_result = { {(DW){1'b0}}, endian_swapped_rdata } + >> (8*r_op[AXILSB-1:0]); + + if (OPT_LOWPOWER && (!M_AXI_RVALID || M_AXI_RRESP[1])) + pre_result = 0; + end + + // }}} + // last_result, o_result + // {{{ + always @(posedge i_clk) + if (OPT_LOWPOWER &&((!M_AXI_RREADY && (!OPT_LOCK || !M_AXI_BREADY)) + || !S_AXI_ARESETN || r_flushing || i_cpu_reset)) + { last_result, o_result } <= 0; + else begin + // {{{ + if (OPT_LOCK && M_AXI_BVALID && (!OPT_LOWPOWER + || (r_lock && M_AXI_BRESP == OKAY))) + begin + o_result <= 0; + o_result[AW-1:0] <= r_pc; + end + + if (M_AXI_RVALID) + begin + // {{{ + if (OPT_LOWPOWER && (M_AXI_RRESP[1] || !misaligned_response_pending)) + last_result <= 0; + else + last_result <= endian_swapped_rdata; + + if (OPT_ALIGNMENT_ERR) + last_result <= 0; + + o_result <= pre_result; + + if (OPT_SIGN_EXTEND) + begin + // {{{ + // Optionally sign extend the return result. + casez(r_op[AXILSB +: 2]) + 2'b10: o_result[31:16] <= {(16){pre_result[15]}}; + 2'b11: o_result[31: 8] <= {(24){pre_result[7]}}; + default: begin end + endcase + // }}} + end else begin + // Fill unused return bits with zeros + casez(r_op[AXILSB +: 2]) + 2'b10: o_result[31:16] <= 0; + 2'b11: o_result[31: 8] <= 0; + default: begin end + endcase + end + + if (OPT_LOWPOWER && (M_AXI_RRESP[1] || pending_err + || misaligned_response_pending + || (r_lock && !M_AXI_RRESP[0]))) + o_result <= 0; + // }}} + end + // }}} + end + // }}} + + // Make verilator happy + // {{{ + // verilator lint_off UNUSED + wire unused; + assign unused = &{ 1'b0, M_AXI_BID, M_AXI_RID, M_AXI_RLAST, + pre_result[2*C_AXI_DATA_WIDTH:32] }; + // verilator lint_on UNUSED + // }}} +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal properties +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +`ifdef FORMAL +// Formal properties for this core are maintained elsewhere +`endif +// }}} +endmodule diff --git a/rtl/cpu/axipipe.v b/rtl/cpu/axipipe.v new file mode 100644 index 0000000..d8576df --- /dev/null +++ b/rtl/cpu/axipipe.v @@ -0,0 +1,994 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Filename: axipipe.v +// {{{ +// Project: Zip CPU -- a small, lightweight, RISC CPU soft core +// +// Purpose: A memory unit to support a CPU based upon AXI-lite. Unlike the +// axilops core, this one will permit multiple requests to be +// outstanding at any given time. +// +// +// Creator: Dan Gisselquist, Ph.D. +// Gisselquist Technology, LLC +// +//////////////////////////////////////////////////////////////////////////////// +// }}} +// Copyright (C) 2020-2021, Gisselquist Technology, LLC +// {{{ +// This program is free software (firmware): 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 MERCHANTIBILITY 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. (It's in the $(ROOT)/doc directory. Run make with no +// target there if the PDF file isn't present.) If not, see +// for a copy. +// +// License: GPL, v3, as defined and found on www.gnu.org, +// http://www.gnu.org/licenses/gpl.html +// +// +//////////////////////////////////////////////////////////////////////////////// +// +// +`default_nettype none +// }}} +module axipipe #( + // {{{ + parameter C_AXI_ADDR_WIDTH = 30, + parameter C_AXI_DATA_WIDTH = 32, + parameter C_AXI_ID_WIDTH = 1, + parameter [((C_AXI_ID_WIDTH>0)? C_AXI_ID_WIDTH:1)-1:0] + AXI_ID = 0, + localparam AW = C_AXI_ADDR_WIDTH, + localparam DW = C_AXI_DATA_WIDTH, + localparam IW =(C_AXI_ID_WIDTH > 0) ? C_AXI_ID_WIDTH : 1, + // + // parameter [0:0] SWAP_ENDIANNESS = 1'b0, + parameter [0:0] SWAP_WSTRB = 1'b0, + parameter [0:0] OPT_SIGN_EXTEND = 1'b0, + // AXI locks are a challenge, and require support from the + // CPU. Specifically, we have to be able to unroll and re-do + // the load instruction on any atomic access failure. For that + // reason, we'll ignore the lock request initially. + parameter [0:0] OPT_LOCK=1'b1, + parameter [0:0] OPT_ALIGNMENT_ERR = 1'b0, + parameter [0:0] OPT_LOWPOWER = 1'b1, + parameter [3:0] OPT_QOS = 0 + // }}} + ) ( + // {{{ + input wire S_AXI_ACLK, + input wire S_AXI_ARESETN, + input wire i_cpu_reset, + // + // CPU interface + // {{{ + input wire i_stb, + input wire i_lock, + input wire [2:0] i_op, + input wire [AW-1:0] i_addr, + input wire [AW-1:0] i_restart_pc, + input wire [31:0] i_data, + input wire [4:0] i_oreg, + output reg o_busy, + output reg o_pipe_stalled, + output reg o_rdbusy, + output reg o_valid, + output reg o_err, + output reg [4:0] o_wreg, + output reg [31:0] o_result, + // }}} + // + // AXI4 bus interface + // {{{ + // Writes + // {{{ + output reg M_AXI_AWVALID, + input wire M_AXI_AWREADY, + output wire [IW-1:0] M_AXI_AWID, + output reg [AW-1:0] M_AXI_AWADDR, + output wire [7:0] M_AXI_AWLEN, + output wire [2:0] M_AXI_AWSIZE, + output wire [1:0] M_AXI_AWBURST, + output wire M_AXI_AWLOCK, + output wire [3:0] M_AXI_AWCACHE, + output wire [2:0] M_AXI_AWPROT, + output wire [3:0] M_AXI_AWQOS, + // + output reg M_AXI_WVALID, + input wire M_AXI_WREADY, + output reg [DW-1:0] M_AXI_WDATA, + output reg [DW/8-1:0] M_AXI_WSTRB, + output wire M_AXI_WLAST, + // + input wire M_AXI_BVALID, + input wire [IW-1:0] M_AXI_BID, + output wire M_AXI_BREADY, + input wire [1:0] M_AXI_BRESP, + // }}} + // Reads + // {{{ + output reg M_AXI_ARVALID, + input wire M_AXI_ARREADY, + output wire [IW-1:0] M_AXI_ARID, + output reg [AW-1:0] M_AXI_ARADDR, + output wire [7:0] M_AXI_ARLEN, + output wire [2:0] M_AXI_ARSIZE, + output wire [1:0] M_AXI_ARBURST, + output wire M_AXI_ARLOCK, + output wire [3:0] M_AXI_ARCACHE, + output wire [2:0] M_AXI_ARPROT, + output wire [3:0] M_AXI_ARQOS, + // + input wire M_AXI_RVALID, + output wire M_AXI_RREADY, + input wire [IW-1:0] M_AXI_RID, + input wire [DW-1:0] M_AXI_RDATA, + input wire M_AXI_RLAST, + input wire [1:0] M_AXI_RRESP + // }}} + // }}} + // }}} + ); + + // Declarations + // {{{ + localparam AXILSB = $clog2(C_AXI_DATA_WIDTH/8); + localparam [2:0] DSZ = AXILSB[2:0]; + localparam LGPIPE = 4; + localparam FIFO_WIDTH = AXILSB+1+2+4 + 1; + localparam [1:0] AXI_INCR = 2'b01, + OKAY = 2'b00, + EXOKAY = 2'b01; + // SLVERR + // DECERR + + wire i_clk = S_AXI_ACLK; + + reg w_misaligned; + wire misaligned_request, misaligned_aw_request, pending_err; + reg w_misalignment_err; + reg [C_AXI_DATA_WIDTH-1:0] next_wdata; + reg [C_AXI_DATA_WIDTH/8-1:0] next_wstrb; + + reg [AW-1:0] r_pc; + reg r_lock; + reg [2:0] axi_size; + + reg none_outstanding, bus_abort, + read_abort, write_abort; + reg [LGPIPE:0] beats_outstanding; + reg r_flushing, flush_request, + r_pipe_stalled; + reg [LGPIPE:0] flushcount, new_flushcount; + reg [LGPIPE:0] wraddr, rdaddr; + reg [3:0] ar_oreg; + reg [1:0] ar_op; + reg [AXILSB-1:0] adr_lsb; + reg [FIFO_WIDTH-1:0] fifo_data [0:((1< ((M_AXI_RVALID || M_AXI_BVALID) ? 1:0)) + o_busy <= 1; + else + o_busy <= 0; + // }}} + + // Read busy + // {{{ + // True if the CPU should expect some kind of pending response from a + // read, and so should stall for that purpose. False otherwise. + initial o_rdbusy = 0; + always @(posedge S_AXI_ACLK) + if (i_cpu_reset || r_flushing) + o_rdbusy <= 0; + else if ((i_stb && w_misalignment_err) || bus_abort) + o_rdbusy <= 0; + else if (i_stb && (!i_op[0] || (OPT_LOCK && i_lock))) + o_rdbusy <= 1; + else if (OPT_LOCK) + begin + if (M_AXI_AWVALID || M_AXI_ARVALID || M_AXI_WVALID) + o_rdbusy <= o_rdbusy; + else if (o_rdbusy) + o_rdbusy <= (beats_outstanding > ((M_AXI_RVALID||M_AXI_BVALID) ? 1:0)); + end else if (o_rdbusy && !M_AXI_ARVALID) + o_rdbusy <= (beats_outstanding > (M_AXI_RVALID ? 1:0)); + // }}} + + // o_pipe_stalled, r_pipe_stalled + // {{{ + // True if the CPU should expect some kind of pending response from a + // read, and so should stall for that purpose. False otherwise. + generate if (OPT_ALIGNMENT_ERR) + begin : FULL_PIPE_STALL + // {{{ + // Here, we stall if the FIFO is ever full. In this case, + // any new beat will count as only one item to the FIFO, and + // so we can run all the way to full. + reg [LGPIPE:0] beats_committed; + + always @(*) + beats_committed = beats_outstanding + + ((i_stb && !w_misalignment_err) ? 1:0) + + ((M_AXI_AWVALID || M_AXI_WVALID + || M_AXI_ARVALID) ? 1:0); + + initial r_pipe_stalled = 0; + always @(posedge S_AXI_ACLK) + if (i_cpu_reset) + r_pipe_stalled <= 0; + else if (M_AXI_RVALID || M_AXI_BVALID) + r_pipe_stalled <= 0; + else if (i_stb && i_lock && !w_misalignment_err) + r_pipe_stalled <= 1; + else if (OPT_LOCK && r_lock) + r_pipe_stalled <= (beats_committed > 0); + else + r_pipe_stalled <= (beats_committed >= (1< ((M_AXI_RVALID || M_AXI_BVALID) ? 1:0))) + r_pipe_stalled <= 1; + if (i_stb && (w_misaligned && !w_misalignment_err) && !o_pipe_stalled) + r_pipe_stalled <= 1'b1; + if (misaligned_request && (M_AXI_WVALID && !M_AXI_WREADY)) + r_pipe_stalled <= 1'b1; + if (misaligned_request && (M_AXI_ARVALID && !M_AXI_ARREADY)) + r_pipe_stalled <= 1'b1; + if (misaligned_aw_request && (M_AXI_AWVALID && !M_AXI_AWREADY)) + r_pipe_stalled <= 1'b1; + if (beats_committed >= (1< 1); + end + + casez({M_AXI_AWVALID && (M_AXI_AWREADY && !misaligned_aw_request), + (M_AXI_WVALID && M_AXI_WREADY && !misaligned_request), + (M_AXI_ARVALID && M_AXI_ARREADY && !misaligned_request) }) + 3'b001: flush_request <= 0; + 3'b10?: flush_request <= M_AXI_WVALID; + 3'b01?: flush_request <= M_AXI_AWVALID; + 3'b11?: flush_request <= 0; + default: begin end + endcase + // }}} + end + // }}} + + // Bus addressing + // {{{ + initial M_AXI_AWADDR = 0; + always @(posedge i_clk) + if (i_stb) + begin + M_AXI_AWADDR <= i_addr[AW-1:0]; + if (SWAP_WSTRB) + M_AXI_AWADDR[AXILSB-1:0] <= 0; + end else if (!OPT_ALIGNMENT_ERR + && ((M_AXI_AWVALID && M_AXI_AWREADY) // && misaligned_aw_request + || (M_AXI_ARVALID && M_AXI_ARREADY))) // && misaligned_request)) + begin + M_AXI_AWADDR[AW-1:AXILSB] <= M_AXI_AWADDR[AW-1:AXILSB] + 1; + M_AXI_AWADDR[AXILSB-1:0] <= 0; + end + + always @(*) + M_AXI_ARADDR = M_AXI_AWADDR; + // }}} + + // Is this request misaligned? + // {{{ + always @(*) + casez(i_op[2:1]) + // Full word + 2'b0?: w_misaligned = (i_addr[AXILSB-1:0]+3) >= (1<= (1<> (i_addr[AXILSB-1:0] * 8); + 2'b11: wide_wdata + = { i_data[7:0], {(2*C_AXI_DATA_WIDTH-8){1'b0}} } + >> (i_addr[AXILSB-1:0] * 8); + default: wide_wdata + = ({ i_data, {(2*C_AXI_DATA_WIDTH-32){ 1'b0 }} } + >> (i_addr[AXILSB-1:0] * 8)); + endcase + + casez(i_op[2:1]) + 2'b0?: wide_wstrb + = { 4'b1111, {(C_AXI_DATA_WIDTH/4-4){1'b0}} } >> i_addr[AXILSB-1:0]; + 2'b10: wide_wstrb + = { 2'b11, {(C_AXI_DATA_WIDTH/4-2){1'b0}} } >> i_addr[AXILSB-1:0]; + 2'b11: wide_wstrb + = { 1'b0, {(C_AXI_DATA_WIDTH/4-1){1'b0}} } >> i_addr[AXILSB-1:0]; + endcase + // }}} + end else begin : LITTLE_ENDIAN_DATA + // {{{ + casez(i_op[2:1]) + 2'b10: wide_wdata + = { {(2*C_AXI_DATA_WIDTH-16){1'b0}}, i_data[15:0] } << (8*i_addr[AXILSB-1:0]); + 2'b11: wide_wdata + = { {(2*C_AXI_DATA_WIDTH-8){1'b0}}, i_data[7:0] } << (8*i_addr[AXILSB-1:0]); + default: wide_wdata + = { {(C_AXI_DATA_WIDTH){1'b0}}, i_data } + << (8*i_addr[AXILSB-1:0]); + endcase + + casez(i_op[2:1]) + 2'b0?: wide_wstrb + = { {(C_AXI_DATA_WIDTH/4-4){1'b0}}, 4'b1111} << i_addr[AXILSB-1:0]; + 2'b10: wide_wstrb + = { {(C_AXI_DATA_WIDTH/4-4){1'b0}}, 4'b0011} << i_addr[AXILSB-1:0]; + 2'b11: wide_wstrb + = { {(C_AXI_DATA_WIDTH/4-4){1'b0}}, 4'b0001} << i_addr[AXILSB-1:0]; + endcase + // }}} + end + // }}} + + // WDATA and WSTRB + // {{{ + initial M_AXI_WDATA = 0; + initial M_AXI_WSTRB = 0; + initial next_wdata = 0; + initial next_wstrb = 0; + always @(posedge i_clk) + if (i_stb) + begin + if (SWAP_WSTRB) + begin : BACKWARDS_ORDER_REG + // {{{ + { M_AXI_WDATA, next_wdata } <= wide_wdata; + { M_AXI_WSTRB, next_wstrb } <= wide_wstrb; + // }}} + end else begin + // {{{ + { next_wdata, M_AXI_WDATA } <= wide_wdata; + { next_wstrb, M_AXI_WSTRB } <= wide_wstrb; + // }}} + end + + if (OPT_ALIGNMENT_ERR) + { next_wstrb, next_wdata } <= 0; + + end else if ((OPT_LOWPOWER || !OPT_ALIGNMENT_ERR) && M_AXI_WREADY) + begin + M_AXI_WDATA <= next_wdata; + M_AXI_WSTRB <= next_wstrb; + if (OPT_LOWPOWER) + { next_wdata, next_wstrb } <= 0; + end + // }}} + + generate if (OPT_ALIGNMENT_ERR) + begin + // {{{ + // Generate an error on any misaligned request + assign misaligned_request = 1'b0; + + assign misaligned_aw_request = 1'b0; + assign pending_err = 1'b0; + // }}} + end else begin + // {{{ + reg r_misaligned_request, r_misaligned_aw_request, + r_pending_err; + + // misaligned_request + // {{{ + initial r_misaligned_request = 0; + always @(posedge i_clk) + if (!S_AXI_ARESETN) + r_misaligned_request <= 0; + else if (i_stb && !o_err && !i_cpu_reset && !bus_abort) + r_misaligned_request <= w_misaligned && !w_misalignment_err; + else if ((M_AXI_WVALID && M_AXI_WREADY) + || (M_AXI_ARVALID && M_AXI_ARREADY)) + r_misaligned_request <= 1'b0; + + assign misaligned_request = r_misaligned_request; + // }}} + + // misaligned_aw_request + // {{{ + initial r_misaligned_aw_request = 0; + always @(posedge i_clk) + if (!S_AXI_ARESETN) + r_misaligned_aw_request <= 0; + else if (i_stb && !o_err && !i_cpu_reset && !write_abort) + r_misaligned_aw_request <= w_misaligned && i_op[0] && !w_misalignment_err; + else if (M_AXI_AWREADY) + r_misaligned_aw_request <= 1'b0; + + assign misaligned_aw_request = r_misaligned_aw_request; + // }}} + + // pending_err + // {{{ + initial r_pending_err = 1'b0; + always @(posedge i_clk) + if (i_cpu_reset || i_stb || o_err || r_flushing) + r_pending_err <= 1'b0; + else if ((M_AXI_BVALID && M_AXI_BRESP[1]) + || (M_AXI_RVALID && M_AXI_RRESP[1])) + r_pending_err <= 1'b1; + + assign pending_err = r_pending_err; + // }}} + // }}} + end endgenerate + + // AxOTHER + // {{{ + localparam [3:0] AXI_NON_CACHABLE_BUFFERABLE = 4'h3; + localparam [3:0] OPT_CACHE = AXI_NON_CACHABLE_BUFFERABLE; + localparam [2:0] AXI_UNPRIVILEGED_NONSECURE_DATA_ACCESS = 3'h0; + localparam [2:0] OPT_PROT=AXI_UNPRIVILEGED_NONSECURE_DATA_ACCESS; + + assign M_AXI_AWID = AXI_ID; + assign M_AXI_AWLEN = 0; + assign M_AXI_AWBURST = AXI_INCR; + assign M_AXI_AWCACHE = M_AXI_AWLOCK ? 0:OPT_CACHE; + assign M_AXI_AWPROT = OPT_PROT; + assign M_AXI_AWQOS = OPT_QOS; + assign M_AXI_WLAST = 1; + + assign M_AXI_ARID = AXI_ID; + assign M_AXI_ARLEN = 0; + assign M_AXI_ARBURST = AXI_INCR; + assign M_AXI_ARCACHE = M_AXI_ARLOCK ? 0:OPT_CACHE; + assign M_AXI_ARPROT = OPT_PROT; + assign M_AXI_ARQOS = OPT_QOS; + // }}} + + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Read transaction FIFO + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + // wraddr + // {{{ + initial wraddr = 0; + always @(posedge S_AXI_ACLK) + if (bus_abort || flush_request) // bus_abort includes i_cpu_reset + wraddr <= 0; + else if ((M_AXI_ARVALID && M_AXI_ARREADY) || (M_AXI_WVALID && M_AXI_WREADY)) + wraddr <= wraddr + 1; + // }}} + + // rdaddr + // {{{ + initial rdaddr = 0; + always @(posedge S_AXI_ACLK) + if (bus_abort || r_flushing) + rdaddr <= 0; + else if (M_AXI_RVALID||M_AXI_BVALID) + rdaddr <= rdaddr + 1; + // }}} + + // ar_oreg, ar_op, adr_lsb + // {{{ + always @(posedge S_AXI_ACLK) + if (i_stb) + { fifo_gie, ar_oreg, ar_op, adr_lsb } <= { i_oreg, i_op[2:1], i_addr[AXILSB-1:0] }; + else if ((M_AXI_ARVALID && M_AXI_ARREADY)||(M_AXI_WVALID && M_AXI_WREADY)) + adr_lsb <= 0; + // }}} + + // fifo_data + // {{{ + always @(posedge S_AXI_ACLK) + if ((M_AXI_ARVALID && M_AXI_ARREADY) || (M_AXI_WVALID && M_AXI_WREADY)) + fifo_data[wraddr[LGPIPE-1:0]] <= { M_AXI_ARVALID, ar_oreg,ar_op, + misaligned_request, M_AXI_ARADDR[AXILSB-1:0] }; + + always @(*) + fifo_read_data = fifo_data[rdaddr[LGPIPE-1:0]]; + + assign { fifo_read_op, fifo_return_reg, fifo_op, + fifo_misaligned, fifo_lsb } = fifo_read_data; + // }}} + + // r_pc + // {{{ + always @(posedge S_AXI_ACLK) + if (!OPT_LOCK) + r_pc <= 0; + else if (i_stb && i_lock && !i_op[0]) + r_pc <= i_restart_pc; + // }}} + + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Read return generation + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + // o_valid + // {{{ + initial o_valid = 1'b0; + always @(posedge i_clk) + if (i_cpu_reset || r_flushing) + o_valid <= 1'b0; + else if (OPT_LOCK && r_lock) + o_valid <= (M_AXI_RVALID && M_AXI_RRESP == EXOKAY) + ||(M_AXI_BVALID && M_AXI_BRESP == OKAY); + else if (OPT_ALIGNMENT_ERR && i_stb && w_misaligned) + o_valid <= 1'b0; + else + o_valid <= M_AXI_RVALID && !M_AXI_RRESP[1] // && !pending_err + && !fifo_misaligned; + // }}} + + // o_wreg + // {{{ + always @(posedge i_clk) + begin + o_wreg <= { fifo_gie, fifo_return_reg }; + if (OPT_LOCK && r_lock && M_AXI_BVALID) + o_wreg[3:0] <= 4'hf; + end + // }}} + + // o_result, misdata + // {{{ + // Need to realign any returning data + // wide_return + // {{{ + always @(*) + if (fifo_misaligned && !OPT_ALIGNMENT_ERR) + wide_return = { M_AXI_RDATA, misdata } >> (8*fifo_lsb); + else + wide_return = { {(C_AXI_DATA_WIDTH){1'b0}}, M_AXI_RDATA } + >> (8*fifo_lsb); + // }}} + + // misdata + // {{{ + always @(posedge i_clk) + if (OPT_ALIGNMENT_ERR) + misdata <= 0; + else if (M_AXI_RVALID) + begin + if (fifo_misaligned) + misdata <= M_AXI_RDATA; + else + misdata <= 0; + end + // }}} + + // o_result + // {{{ + always @(posedge i_clk) + if (OPT_LOWPOWER && (!S_AXI_ARESETN || r_flushing || i_cpu_reset)) + o_result <= 0; + else if (OPT_LOCK && M_AXI_BVALID && (!OPT_LOWPOWER || (r_lock && M_AXI_BRESP == OKAY))) + begin + o_result <= 0; + o_result[AW-1:0] <= r_pc; + end else if (!OPT_LOWPOWER || M_AXI_RVALID) + begin + o_result <= wide_return[31:0]; + + if (OPT_SIGN_EXTEND) + begin + // {{{ + case(fifo_op) + 2'b10: o_result[31:16] <= {(16){wide_return[15]}}; + 2'b11: o_result[15: 8] <= {( 8){wide_return[ 7]}}; + endcase + // }}} + end else if (fifo_op[1]) + begin + // {{{ + if (fifo_op[0]) + o_result[15: 8] <= 0; + else + o_result[31:16] <= 0; + // }}} + end + + if (OPT_LOWPOWER&&(i_cpu_reset || r_flushing)) + o_result <= 0; + end + // }}} + // }}} + + // o_err - report bus errors back to the CPU + // {{{ + initial o_err = 1'b0; + always @(posedge i_clk) + if (i_cpu_reset || r_flushing || o_err) + o_err <= 1'b0; + else if (i_stb && w_misalignment_err) + o_err <= 1'b1; + else if (OPT_LOCK && r_lock) + o_err <= (M_AXI_BVALID && M_AXI_BRESP[1]) + ||(M_AXI_RVALID && M_AXI_RRESP != EXOKAY); + else if (M_AXI_BVALID || M_AXI_RVALID) + o_err <= (M_AXI_BVALID && M_AXI_BRESP[1]) + || (M_AXI_RVALID && M_AXI_RRESP[1]); + else + o_err <= 1'b0; + // }}} + + // Return xREADY -- always ready + // {{{ + assign M_AXI_RREADY = 1; + assign M_AXI_BREADY = 1; + // }}} + + // }}} + + // Make verilator happy + // {{{ + // verilator lint_off UNUSED + wire unused; + assign unused = &{ 1'b0, M_AXI_RRESP[0], M_AXI_BRESP[0], + M_AXI_BID, M_AXI_RID, M_AXI_RLAST, + // i_addr[31:C_AXI_ADDR_WIDTH], + (&i_addr), wide_return[2*C_AXI_DATA_WIDTH-1:32], + pending_err, adr_lsb, fifo_read_op, + none_outstanding }; + // verilator lint_on UNUSED + // }}} +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal property section +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +`ifdef FORMAL +// Formal properties for this core are maintained elsewhere +`endif +// }}} +endmodule diff --git a/rtl/cpu/busdelay.v b/rtl/cpu/busdelay.v index 4077271..0f9d545 100644 --- a/rtl/cpu/busdelay.v +++ b/rtl/cpu/busdelay.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: busdelay.v -// +// {{{ // Project: Zip CPU -- a small, lightweight, RISC CPU soft core // // Purpose: Delay any access to the wishbone bus by a single clock. @@ -36,9 +36,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -53,200 +53,227 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // // `default_nettype none -// -module busdelay(i_clk, i_reset, - // The input bus - i_wb_cyc, i_wb_stb, i_wb_we, i_wb_addr, i_wb_data, i_wb_sel, - o_wb_stall, o_wb_ack, o_wb_data, o_wb_err, - // The delayed bus - o_dly_cyc, o_dly_stb, o_dly_we, o_dly_addr,o_dly_data,o_dly_sel, - i_dly_stall, i_dly_ack, i_dly_data, i_dly_err); - parameter AW=32, DW=32; - localparam F_LGDEPTH=4; - parameter [0:0] DELAY_STALL = 1; - input wire i_clk, i_reset; - // Input/master bus - input wire i_wb_cyc, i_wb_stb, i_wb_we; - input wire [(AW-1):0] i_wb_addr; - input wire [(DW-1):0] i_wb_data; - input wire [(DW/8-1):0] i_wb_sel; - output wire o_wb_stall; - output reg o_wb_ack; - output reg [(DW-1):0] o_wb_data; - output reg o_wb_err; - // Delayed bus - output reg o_dly_cyc, o_dly_stb, o_dly_we; - output reg [(AW-1):0] o_dly_addr; - output reg [(DW-1):0] o_dly_data; - output reg [(DW/8-1):0] o_dly_sel; - input wire i_dly_stall; - input wire i_dly_ack; - input wire [(DW-1):0] i_dly_data; - input wire i_dly_err; +// }}} +module busdelay #( + // {{{ + parameter AW=32, DW=32, + parameter [0:0] DELAY_STALL = 1, + parameter [0:0] OPT_LOWPOWER = 0 + // }}} + ) ( + // {{{ + input wire i_clk, i_reset, + // Input/master bus + // {{{ + input wire i_wb_cyc, i_wb_stb, i_wb_we, + input wire [(AW-1):0] i_wb_addr, + input wire [(DW-1):0] i_wb_data, + input wire [(DW/8-1):0] i_wb_sel, + output wire o_wb_stall, + output reg o_wb_ack, + output reg [(DW-1):0] o_wb_data, + output reg o_wb_err, + // }}} + // Delayed bus + // {{{ + output reg o_dly_cyc, o_dly_stb, o_dly_we, + output reg [(AW-1):0] o_dly_addr, + output reg [(DW-1):0] o_dly_data, + output reg [(DW/8-1):0] o_dly_sel, + input wire i_dly_stall, + input wire i_dly_ack, + input wire [(DW-1):0] i_dly_data, + input wire i_dly_err + // }}} + // }}} + ); - generate - if (DELAY_STALL != 0) - begin + generate if (DELAY_STALL) + begin : SKIDBUFFER + // {{{ reg r_stb, r_we; reg [(AW-1):0] r_addr; reg [(DW-1):0] r_data; reg [(DW/8-1):0] r_sel; + // o_dly_cyc + // {{{ initial o_dly_cyc = 1'b0; + always @(posedge i_clk) + if (i_reset || !i_wb_cyc) + o_dly_cyc <= 1'b0; + else + o_dly_cyc <= (!o_wb_err)&&((!i_dly_err)||(!o_dly_cyc)); + // }}} + + // o_dly_stb + // {{{ initial o_dly_stb = 1'b0; + always @(posedge i_clk) + if (i_reset || !i_wb_cyc || o_wb_err || (o_dly_cyc && i_dly_err)) + o_dly_stb <= 1'b0; + else if (!o_dly_stb || !i_dly_stall) + o_dly_stb <= i_wb_stb || r_stb; + // }}} + + // r_stb + // {{{ + initial r_stb = 1'b0; + always @(posedge i_clk) + if (i_reset || !i_wb_cyc || o_wb_err || i_dly_err + || !i_dly_stall || !o_dly_stb) + r_stb <= 1'b0; + else if (i_wb_stb && !o_wb_stall) // && (o_dly_stb&&i_dly_stall) + r_stb <= 1'b1; + // }}} + + // r_* + // {{{ + initial { r_we, r_addr, r_data, r_sel } = 0; + always @(posedge i_clk) + if (OPT_LOWPOWER && (i_reset || !i_wb_cyc || i_dly_err + || !o_dly_stb || !i_dly_stall)) + { r_we, r_addr, r_data, r_sel } <= 0; + else if (i_wb_stb && !o_wb_stall) // && (o_dly_stb&&i_dly_stall) + { r_we, r_addr, r_data, r_sel } + <= { i_wb_we, i_wb_addr, i_wb_data, i_wb_sel }; + // }}} + initial o_dly_we = 1'b0; initial o_dly_addr = 0; initial o_dly_data = 0; initial o_dly_sel = 0; - initial r_stb = 1'b0; - initial r_we = 1'b0; - initial r_addr = 0; - initial r_data = 0; - initial r_sel = 0; - initial o_wb_ack = 1'b0; - initial o_wb_err = 1'b0; always @(posedge i_clk) + if (OPT_LOWPOWER && (i_reset || (!i_wb_cyc || o_wb_err || (o_dly_cyc && i_dly_err)))) + { o_dly_we, o_dly_addr, o_dly_data, o_dly_sel } <= 0; + else if (!o_dly_stb || !i_dly_stall) begin - o_dly_cyc <= (i_wb_cyc)&&(!i_reset)&&(!o_wb_err) - &&((!i_dly_err)||(!o_dly_cyc)); - - if ((!i_dly_stall)||(!o_dly_stb)) - begin - r_we <= i_wb_we; - r_addr <= i_wb_addr; - r_data <= i_wb_data; - r_sel <= i_wb_sel; - - if (r_stb) - begin - o_dly_we <= r_we; - o_dly_addr <= r_addr; - o_dly_data <= r_data; - o_dly_sel <= r_sel; - o_dly_stb <= 1'b1; - end else begin - o_dly_we <= i_wb_we; - o_dly_addr <= i_wb_addr; - o_dly_data <= i_wb_data; - o_dly_sel <= i_wb_sel; - o_dly_stb <= i_wb_stb; - end - - r_stb <= 1'b0; - end else if ((!r_stb)&&(!o_wb_stall)) - begin - r_we <= i_wb_we; - r_addr <= i_wb_addr; - r_data <= i_wb_data; - r_sel <= i_wb_sel; - r_stb <= i_wb_stb; - end - - if ((!i_wb_cyc)||((i_dly_err)&&(o_dly_cyc))||(o_wb_err)) - begin - o_dly_stb <= 1'b0; - r_stb <= 1'b0; - end - - if ((i_reset)||(!i_wb_cyc)||(o_wb_err)) - o_wb_ack <= 1'b0; + if (r_stb) + { o_dly_we, o_dly_addr, o_dly_data, o_dly_sel } <= { r_we, r_addr, r_data, r_sel }; + else if (!OPT_LOWPOWER || i_wb_stb) + { o_dly_we, o_dly_addr, o_dly_data, o_dly_sel } <= { i_wb_we, i_wb_addr, i_wb_data, i_wb_sel }; else - o_wb_ack <= (i_dly_ack)&&(o_dly_cyc)&&(!i_dly_err); - o_wb_data <= i_dly_data; + { o_dly_addr, o_dly_data, o_dly_sel } <= 0; - if (!i_wb_cyc) - o_wb_err <= 1'b0; - else - o_wb_err <= (i_dly_err)&&(o_dly_cyc); - - if (i_reset) - begin - r_stb <= 0; - r_we <= 0; - o_dly_stb <= 0; - o_wb_err <= 0; - o_wb_ack <= 0; - end end assign o_wb_stall = r_stb; -`ifdef FORMAL - assign f_wpending = { r_stb, r_we, r_addr, r_data, r_sel }; -`endif - end else begin + // o_wb_ack + // {{{ + initial o_wb_ack = 0; + always @(posedge i_clk) + if (i_reset || !i_wb_cyc || o_wb_err || !o_dly_cyc) + o_wb_ack <= 1'b0; + else + o_wb_ack <= (i_dly_ack); + // }}} + + // o_wb_data + // {{{ + initial o_wb_data = 0; + always @(posedge i_clk) + if (OPT_LOWPOWER && (i_reset || !i_wb_cyc || !o_dly_cyc + || o_wb_err || !i_dly_ack)) + o_wb_data <= 0; + else + o_wb_data <= i_dly_data; + // }}} + // o_wb_err + // {{{ + initial o_wb_err = 1'b0; + always @(posedge i_clk) + if (i_reset || !i_wb_cyc || !o_dly_cyc) + o_wb_err <= 1'b0; + else + o_wb_err <= i_dly_err; + // }}} + // }}} + end else begin + // {{{ initial o_dly_cyc = 1'b0; initial o_dly_stb = 1'b0; initial o_dly_we = 1'b0; initial o_dly_addr = 0; initial o_dly_data = 0; initial o_dly_sel = 0; - initial o_wb_ack = 0; - initial o_wb_err = 0; always @(posedge i_clk) - if (i_reset) - o_dly_cyc <= 1'b0; - else if ((i_dly_err)&&(o_dly_cyc)) - o_dly_cyc <= 1'b0; - else if ((o_wb_err)&&(i_wb_cyc)) - o_dly_cyc <= 1'b0; - else - o_dly_cyc <= i_wb_cyc; + if (i_reset) + o_dly_cyc <= 1'b0; + else if ((i_dly_err)&&(o_dly_cyc)) + o_dly_cyc <= 1'b0; + else if ((o_wb_err)&&(i_wb_cyc)) + o_dly_cyc <= 1'b0; + else + o_dly_cyc <= i_wb_cyc; // Add the i_wb_cyc criteria here, so we can simplify the // o_wb_stall criteria below, which would otherwise *and* // these two. always @(posedge i_clk) - if (i_reset) - o_dly_stb <= 1'b0; - else if ((i_dly_err)&&(o_dly_cyc)) - o_dly_stb <= 1'b0; - else if ((o_wb_err)&&(i_wb_cyc)) - o_dly_stb <= 1'b0; - else if (!i_wb_cyc) - o_dly_stb <= 1'b0; - else if (!o_wb_stall) - o_dly_stb <= (i_wb_stb); + if (i_reset) + o_dly_stb <= 1'b0; + else if ((i_dly_err)&&(o_dly_cyc)) + o_dly_stb <= 1'b0; + else if ((o_wb_err)&&(i_wb_cyc)) + o_dly_stb <= 1'b0; + else if (!i_wb_cyc) + o_dly_stb <= 1'b0; + else if (!o_wb_stall) + o_dly_stb <= (i_wb_stb); always @(posedge i_clk) - if (!o_wb_stall) - o_dly_we <= i_wb_we; - always @(posedge i_clk) - if (!o_wb_stall) - o_dly_addr<= i_wb_addr; - always @(posedge i_clk) - if (!o_wb_stall) - o_dly_data <= i_wb_data; + if (!o_wb_stall) + o_dly_we <= i_wb_we; + + initial o_dly_addr = 0; always @(posedge i_clk) - if (!o_wb_stall) - o_dly_sel <= i_wb_sel; + if (OPT_LOWPOWER && (i_reset || !i_wb_cyc || o_wb_err + || (o_dly_cyc && i_dly_err))) + { o_dly_addr, o_dly_data, o_dly_sel } <= 0; + else if (!o_dly_stb || !i_dly_stall) + begin + { o_dly_addr, o_dly_data, o_dly_sel } + <= { i_wb_addr, i_wb_data, i_wb_sel }; + if (OPT_LOWPOWER && !i_wb_stb) + { o_dly_addr, o_dly_data, o_dly_sel } <= 0; + end + + initial o_wb_ack = 0; always @(posedge i_clk) - if (i_reset) - o_wb_ack <= 1'b0; - else - o_wb_ack <= ((i_dly_ack)&&(!i_dly_err) - &&(o_dly_cyc)&&(i_wb_cyc)) - &&(!o_wb_err); + if (i_reset) + o_wb_ack <= 1'b0; + else + o_wb_ack <= ((i_dly_ack)&&(!i_dly_err) + &&(o_dly_cyc)&&(i_wb_cyc)) + &&(!o_wb_err); + + initial o_wb_err = 0; always @(posedge i_clk) - if (i_reset) - o_wb_err <= 1'b0; - else if (!o_dly_cyc) - o_wb_err <= 1'b0; - else - o_wb_err <= (o_wb_err)||(i_dly_err)&&(i_wb_cyc); + if (i_reset) + o_wb_err <= 1'b0; + else if (!o_dly_cyc) + o_wb_err <= 1'b0; + else + o_wb_err <= (o_wb_err)||(i_dly_err)&&(i_wb_cyc); + + initial o_wb_data = 0; always @(posedge i_clk) + if (OPT_LOWPOWER && (i_reset || !i_wb_cyc || !o_dly_cyc || o_wb_err || !i_dly_ack)) + o_wb_data <= 0; + else o_wb_data <= i_dly_data; // Our only non-delayed line, yet still really delayed. Perhaps @@ -255,15 +282,19 @@ module busdelay(i_clk, i_reset, // assign o_wb_stall=((i_wb_cyc)&&(i_dly_stall)&&(o_dly_stb));//&&o_cyc assign o_wb_stall = (i_dly_stall)&&(o_dly_stb); -`ifdef FORMAL - // f_wpending isn't used if DELAY_STALL is zero, but we'll give - // it a seemingly useful value anyway--if for no other reason - // than to be sure we set it to the right number of bits - assign f_wpending = { i_wb_stb, i_wb_we, i_wb_addr, i_wb_data, i_wb_sel }; -`endif + // }}} end endgenerate - +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal properties +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// `ifdef FORMAL // Formal properties for this module are maintained elsewhere `endif +// }}} endmodule diff --git a/rtl/cpu/cpudefs.v b/rtl/cpu/cpudefs.v index e9b0f0a..0d0fb98 100644 --- a/rtl/cpu/cpudefs.v +++ b/rtl/cpu/cpudefs.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: cpudefs.v -// +// {{{ // Project: Zip CPU -- a small, lightweight, RISC CPU soft core // // Purpose: Some architectures have some needs, others have other needs. @@ -27,9 +27,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -44,14 +44,15 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // // //////////////////////////////////////////////////////////////////////////////// // -// +// }}} `ifndef CPUDEFS_H `define CPUDEFS_H // @@ -60,7 +61,8 @@ // it handles various instructions within the set: // // -// +// OPT_MULTIPLY +// {{{ // OPT_MULTIPLY controls whether or not the multiply is built and included // in the ALU by default. Set this option and a parameter will be set that // includes the multiply. (This parameter may still be overridden, as with @@ -76,9 +78,10 @@ // // `define OPT_MULTIPLY 3 +// }}} // -// -// +// OPT_DIVIDE +// {{{ // OPT_DIVIDE controls whether or not the divide instruction is built and // included into the ZipCPU by default. Set this option and a parameter will // be set that causes the divide unit to be included. (This parameter may @@ -89,9 +92,10 @@ // // `define OPT_DIVIDE +// }}} // -// -// +// OPT_IMPLEMENT_FPU +// {{{ // OPT_IMPLEMENT_FPU will (one day) control whether or not the floating point // unit (once I have one) is built and included into the ZipCPU by default. // At that time, if this option is set then a parameter will be set that @@ -103,10 +107,10 @@ // // // `define OPT_IMPLEMENT_FPU +// }}} // -// -// -// +// OPT_SINGLE_FETCH +// {{{ // OPT_SINGLE_FETCH controls whether or not the prefetch has a cache, and // whether or not it can issue one instruction per clock. When set, the // prefetch has no cache, and only one instruction is fetched at a time. @@ -133,8 +137,10 @@ // speed isn't as important. Otherwise, just leave this undefined. // // `define OPT_SINGLE_FETCH +// }}} // -// +// OPT_DOUBLE_FETCH +// {{{ // OPT_DOUBLE_FETCH is an alternative to OPT_SINGLE_FETCH. It is designed to // increase performance primarily when using an instruction memory which has // one cost for a random access, and a second (lower) cost for sequential @@ -156,9 +162,10 @@ `ifndef OPT_SINGLE_FETCH // `define OPT_DOUBLE_FETCH `endif +// }}} // -// -// +// OPT_CIS +// {{{ // The ZipCPU ISA defines an optional compressed instruction set (CIS) // complement. This compressed instruction format allows two instructions to // be packed into the same instruction word. Some instructions can be so @@ -168,10 +175,10 @@ // the instruction set. // `define OPT_CIS // COST: about 87 LUTs +// }}} // -// -// -// +// OPT_EARLY_BRANCHING +// {{{ // OPT_EARLY_BRANCHING is an attempt to execute a BRA statement as early // as possible, to avoid as many pipeline stalls on a branch as possible. // With the OPT_TRADITIONAL_PFCACHE, BRA instructions cost only a single @@ -184,10 +191,11 @@ // have the LUTs available to afford it. // `define OPT_EARLY_BRANCHING +// }}} // // -// -// +// Pipelining +// {{{ // The next several options are pipeline optimization options. They make no // sense in a single instruction fetch mode, hence we #ifndef them so they // are only defined if we are in a full pipelined mode (i.e. OPT_SINGLE_FETCH @@ -198,6 +206,8 @@ // // // +// OPT_PIPELINED +// {{{ // OPT_PIPELINED is the natural result and opposite of using the single // instruction fetch unit. If you are not using that unit, the ZipCPU will // be pipelined. The option is defined here more for readability than @@ -207,9 +217,10 @@ // In other words, leave this define alone--lest you break the ZipCPU. // `define OPT_PIPELINED +// }}} // -// -// +// OPT_TRADITIONAL_PFCACHE +// {{{ // OPT_TRADITIONAL_PFCACHE allows you to switch between one of two prefetch // caches. If enabled, a more traditional cache is implemented. This more // traditional cache (currently) uses many more LUTs, but it also reduces @@ -220,19 +231,22 @@ // If you have the fabric to support this option, I recommend including it. // `define OPT_TRADITIONAL_PFCACHE +// }}} // // -// -// +// OPT_DCACHE +// {{{ // OPT_DCACHE enables a CPU data cache for (hopefully) better performance // in terms of speed. It requires telling the CPU which parts of memory // can be cachable in terms of three separate address regions: one for the // SDRAM, one for the flash, and another for the block RAM. // `define OPT_DCACHE +// }}} // // -// +// OPT_PIPELINED_BUS_ACCESS +// {{{ // OPT_PIPELINED_BUS_ACCESS controls whether or not LOD/STO instructions // can take advantaged of pipelined bus instructions. To be eligible, the // operations must be identical (cannot pipeline loads and stores, just loads @@ -246,13 +260,14 @@ // wishbone bus can handle pipelined bus accesses. // `define OPT_PIPELINED_BUS_ACCESS -// +// }}} // // // // `endif // OPT_DOUBLE_FETCH `endif // OPT_SINGLE_FETCH +// }}} // // // [EXPERIMENTAL--and not (yet) finished] diff --git a/rtl/cpu/cpuops.v b/rtl/cpu/cpuops.v index b5ef639..e44e6ca 100644 --- a/rtl/cpu/cpuops.v +++ b/rtl/cpu/cpuops.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: cpuops.v -// +// {{{ // Project: Zip CPU -- a small, lightweight, RISC CPU soft core // // Purpose: This is the ZipCPU ALU function. It handles all of the @@ -12,9 +12,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -29,11 +29,11 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // // @@ -41,23 +41,44 @@ // // `include "cpudefs.v" -// -module cpuops(i_clk,i_reset, i_stb, i_op, i_a, i_b, o_c, o_f, o_valid, - o_busy); - parameter IMPLEMENT_MPY = `OPT_MULTIPLY; - parameter [0:0] OPT_SHIFTS = 1'b1; - input wire i_clk, i_reset, i_stb; - input wire [3:0] i_op; - input wire [31:0] i_a, i_b; - output reg [31:0] o_c; - output wire [3:0] o_f; - output reg o_valid; - output wire o_busy; +// }}} +module cpuops #( + // {{{ + parameter IMPLEMENT_MPY = `OPT_MULTIPLY, + parameter [0:0] OPT_SHIFTS = 1'b1 + // }}} + ) ( + // {{{ + input wire i_clk, i_reset, i_stb, + input wire [3:0] i_op, + input wire [31:0] i_a, i_b, + output reg [31:0] o_c, + output wire [3:0] o_f, + output reg o_valid, + output wire o_busy + // }}} + ); + + // Declarations + // {{{ + wire [31:0] w_brev_result; + wire z, n, v, vx; + reg c, pre_sign, set_ovfl, keep_sgn_on_ovfl; + + wire [32:0] w_lsr_result, w_asr_result, w_lsl_result; + + wire [63:0] mpy_result; // Where we dump the multiply result + wire mpyhi; // Return the high half of the multiply + wire mpybusy; // The multiply is busy if true + wire mpydone; // True if we'll be valid on the next clock; + wire this_is_a_multiply_op; + reg r_busy; genvar k; + // }}} // Shift register pre-logic - wire [32:0] w_lsr_result, w_asr_result, w_lsl_result; + // {{{ generate if (OPT_SHIFTS) begin : IMPLEMENT_SHIFTS wire signed [32:0] w_pre_asr_input, w_pre_asr_shifted; @@ -79,19 +100,20 @@ module cpuops(i_clk,i_reset, i_stb, i_op, i_a, i_b, o_c, o_f, o_valid, assign w_lsl_result = { i_a[31:0], 1'b0 }; end endgenerate + // }}} // // Bit reversal pre-logic - wire [31:0] w_brev_result; + // {{{ generate for(k=0; k<32; k=k+1) begin : bit_reversal_cpuop assign w_brev_result[k] = i_b[31-k]; end endgenerate + // }}} - // Prelogic for our flags registers - wire z, n, v; - reg c, pre_sign, set_ovfl, keep_sgn_on_ovfl; + // Prelogic for our flags registers : set_ovfl and keep_sgn_on_ovfl + // {{{ always @(posedge i_clk) if (i_stb) // 1 LUT set_ovfl<=(((i_op==4'h0)&&(i_a[31] != i_b[31]))//SUB&CMP @@ -104,19 +126,16 @@ module cpuops(i_clk,i_reset, i_stb, i_op, i_a, i_b, o_c, o_f, o_valid, keep_sgn_on_ovfl<= (((i_op==4'h0)&&(i_a[31] != i_b[31]))//SUB&CMP ||((i_op==4'h2)&&(i_a[31] == i_b[31]))); // ADD + // }}} - wire [63:0] mpy_result; // Where we dump the multiply result - wire mpyhi; // Return the high half of the multiply - wire mpybusy; // The multiply is busy if true - wire mpydone; // True if we'll be valid on the next clock; - + // Multiply + // {{{ // A 4-way multiplexer can be done in one 6-LUT. // A 16-way multiplexer can therefore be done in 4x 6-LUT's with // the Xilinx multiplexer fabric that follows. // Given that we wish to apply this multiplexer approach to 33-bits, // this will cost a minimum of 132 6-LUTs. - wire this_is_a_multiply_op; assign this_is_a_multiply_op = (i_stb)&&((i_op[3:1]==3'h5)||(i_op[3:0]==4'hc)); // @@ -129,10 +148,11 @@ module cpuops(i_clk,i_reset, i_stb, i_op, i_a, i_b, o_c, o_f, o_valid, `endif `MPYOP #(.IMPLEMENT_MPY(IMPLEMENT_MPY)) thempy(i_clk, i_reset, this_is_a_multiply_op, i_op[1:0], i_a, i_b, mpydone, mpybusy, mpy_result, mpyhi); + // }}} // // The master ALU case statement - // + // {{{ always @(posedge i_clk) if (i_stb) begin @@ -157,8 +177,10 @@ module cpuops(i_clk,i_reset, i_stb, i_op, i_a, i_b, o_c, o_f, o_valid, end else // if (mpydone) // set the output based upon the multiply result o_c <= (mpyhi)?mpy_result[63:32]:mpy_result[31:0]; + // }}} - reg r_busy; + // o_busy, r_busy + // {{{ initial r_busy = 1'b0; always @(posedge i_clk) if (i_reset) @@ -169,15 +191,20 @@ module cpuops(i_clk,i_reset, i_stb, i_op, i_a, i_b, o_c, o_f, o_valid, r_busy <= 1'b0; assign o_busy = (r_busy); // ||((IMPLEMENT_MPY>1)&&(this_is_a_multiply_op)); + // }}} - + // Flags assignment and determination + // {{{ assign z = (o_c == 32'h0000); assign n = (o_c[31]); assign v = (set_ovfl)&&(pre_sign != o_c[31]); - wire vx = (keep_sgn_on_ovfl)&&(pre_sign != o_c[31]); + assign vx = (keep_sgn_on_ovfl)&&(pre_sign != o_c[31]); assign o_f = { v, n^vx, c, z }; + // }}} + // o_valid + // {{{ initial o_valid = 1'b0; always @(posedge i_clk) if (i_reset) @@ -186,8 +213,18 @@ module cpuops(i_clk,i_reset, i_stb, i_op, i_a, i_b, o_c, o_f, o_valid, o_valid <= (i_stb); else o_valid <=((i_stb)&&(!this_is_a_multiply_op))||(mpydone); - + // }}} +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal properties +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// `ifdef FORMAL // Formal properties for this module are maintained elsewhere `endif +// }}} endmodule diff --git a/rtl/cpu/dblfetch.v b/rtl/cpu/dblfetch.v index 4979024..465f189 100644 --- a/rtl/cpu/dblfetch.v +++ b/rtl/cpu/dblfetch.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: dblfetch.v -// +// {{{ // Project: Zip CPU -- a small, lightweight, RISC CPU soft core // // Purpose: This is one step beyond the simplest instruction fetch, @@ -22,9 +22,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2017-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2017-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -39,83 +39,99 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // // `default_nettype none -// -module dblfetch(i_clk, i_reset, i_new_pc, i_clear_cache, - i_stall_n, i_pc, o_insn, o_pc, o_valid, - o_wb_cyc, o_wb_stb, o_wb_we, o_wb_addr, o_wb_data, - i_wb_stall, i_wb_ack, i_wb_err, i_wb_data, - o_illegal); - parameter ADDRESS_WIDTH=30; - localparam AW=ADDRESS_WIDTH, DW = 32; - input wire i_clk, i_reset, i_new_pc, i_clear_cache, - i_stall_n; - input wire [(AW+1):0] i_pc; - output reg [(DW-1):0] o_insn; - output reg [(AW+1):0] o_pc; - output reg o_valid; - // Wishbone outputs - output reg o_wb_cyc, o_wb_stb; - output wire o_wb_we; - output reg [(AW-1):0] o_wb_addr; - output wire [(DW-1):0] o_wb_data; - // And return inputs - input wire i_wb_stall, i_wb_ack, i_wb_err; - input wire [(DW-1):0] i_wb_data; - // And ... the result if we got an error - output reg o_illegal; - - assign o_wb_we = 1'b0; - assign o_wb_data = 32'h0000; +// }}} +module dblfetch #( + // {{{ + parameter ADDRESS_WIDTH=30, + localparam AW=ADDRESS_WIDTH, DW = 32 + // }}} + ) ( + // {{{ + input wire i_clk, i_reset, + // CPU signals--from the CPU + input wire i_new_pc, i_clear_cache,i_ready, + input wire [(AW+1):0] i_pc, + // ... and in return + output reg o_valid, + output reg o_illegal, + output reg [(DW-1):0] o_insn, + output reg [(AW+1):0] o_pc, + // Wishbone outputs + output reg o_wb_cyc, o_wb_stb, + output wire o_wb_we, + output reg [(AW-1):0] o_wb_addr, + output wire [(DW-1):0] o_wb_data, + // And return inputs + input wire i_wb_stall, i_wb_ack, i_wb_err, + input wire [(DW-1):0] i_wb_data + // }}} + ); - reg last_stb, invalid_bus_cycle; + // Local declarations + // {{{ + reg last_stb, invalid_bus_cycle; reg [(DW-1):0] cache_word; reg cache_valid; reg [1:0] inflight; reg cache_illegal; + // }}} + assign o_wb_we = 1'b0; + assign o_wb_data = 32'h0000; + + // o_wb_cyc, o_wb_stb + // {{{ initial o_wb_cyc = 1'b0; initial o_wb_stb = 1'b0; always @(posedge i_clk) - if ((i_reset)||((o_wb_cyc)&&(i_wb_err))) + if ((i_reset)||((o_wb_cyc)&&(i_wb_err))) + begin : RESET_ABORT + // {{{ + o_wb_cyc <= 1'b0; + o_wb_stb <= 1'b0; + // }}} + end else if (o_wb_cyc) + begin : END_CYCLE + // {{{ + if ((!o_wb_stb)||(!i_wb_stall)) + o_wb_stb <= (!last_stb); + + // Relase the bus on the second ack + if (((i_wb_ack)&&(!o_wb_stb)&&(inflight<=1)) + ||((!o_wb_stb)&&(inflight == 0)) + // Or any new transaction request + ||((i_new_pc)||(i_clear_cache))) begin o_wb_cyc <= 1'b0; o_wb_stb <= 1'b0; - end else if (o_wb_cyc) - begin - if ((!o_wb_stb)||(!i_wb_stall)) - o_wb_stb <= (!last_stb); - - // Relase the bus on the second ack - if (((i_wb_ack)&&(!o_wb_stb)&&(inflight<=1)) - ||((!o_wb_stb)&&(inflight == 0)) - // Or any new transaction request - ||((i_new_pc)||(i_clear_cache))) - begin - o_wb_cyc <= 1'b0; - o_wb_stb <= 1'b0; - end - - end else if ((i_new_pc)||(invalid_bus_cycle) - ||((o_valid)&&(i_stall_n)&&(!o_illegal))) - begin - // Initiate a bus cycle if ... the last bus cycle was - // aborted (bus error or new_pc), we've been given a - // new PC to go get, or we just exhausted our one - // instruction cache - o_wb_cyc <= 1'b1; - o_wb_stb <= 1'b1; end + // }}} + end else if ((i_new_pc)||(invalid_bus_cycle) + ||((o_valid)&&(i_ready)&&(!o_illegal))) + begin : START_CYCLE + // {{{ + // Initiate a bus cycle if ... the last bus cycle was + // aborted (bus error or new_pc), we've been given a + // new PC to go get, or we just exhausted our one + // instruction cache + o_wb_cyc <= 1'b1; + o_wb_stb <= 1'b1; + // }}} + end + // }}} + // inflight + // {{{ initial inflight = 2'b00; always @(posedge i_clk) if (!o_wb_cyc) @@ -130,112 +146,147 @@ module dblfetch(i_clk, i_reset, i_new_pc, i_clear_cache, default: begin end endcase end + // }}} + // last_stb + // {{{ always @(*) - last_stb = (inflight != 2'b00)||((o_valid)&&(!i_stall_n)); + last_stb = (inflight != 2'b00)||((o_valid)&&(!i_ready)); + // }}} + // invalid_bus_cycle + // {{{ initial invalid_bus_cycle = 1'b0; always @(posedge i_clk) if ((o_wb_cyc)&&(i_new_pc)) invalid_bus_cycle <= 1'b1; else if (!o_wb_cyc) invalid_bus_cycle <= 1'b0; + // }}} + // o_wb_addr + // {{{ initial o_wb_addr = {(AW){1'b1}}; always @(posedge i_clk) if (i_new_pc) o_wb_addr <= i_pc[AW+1:2]; else if ((o_wb_stb)&&(!i_wb_stall)) o_wb_addr <= o_wb_addr + 1'b1; + // }}} //////////////////////////////////////////////////////////////////////// // // Now for the immediate output word to the CPU - // + // {{{ //////////////////////////////////////////////////////////////////////// + // o_valid + // {{{ initial o_valid = 1'b0; always @(posedge i_clk) if ((i_reset)||(i_new_pc)||(i_clear_cache)) o_valid <= 1'b0; else if ((o_wb_cyc)&&((i_wb_ack)||(i_wb_err))) o_valid <= 1'b1; - else if (i_stall_n) + else if (i_ready) o_valid <= cache_valid; + // }}} + // o_insn + // {{{ always @(posedge i_clk) - if ((!o_valid)||(i_stall_n)) + if ((!o_valid)||(i_ready)) begin if (cache_valid) o_insn <= cache_word; else o_insn <= i_wb_data; end + // }}} - initial o_pc[1:0] = 2'b00; + // o_pc + // {{{ always @(posedge i_clk) if (i_new_pc) o_pc <= i_pc; - else if ((o_valid)&&(i_stall_n)) + else if ((o_valid)&&(i_ready)) + begin o_pc[AW+1:2] <= o_pc[AW+1:2] + 1'b1; + o_pc[1:0] <= 2'b00; + end + // }}} + // o_illegal + // {{{ initial o_illegal = 1'b0; always @(posedge i_clk) if ((i_reset)||(i_new_pc)||(i_clear_cache)) o_illegal <= 1'b0; - else if ((!o_valid)||(i_stall_n)) + else if ((!o_valid)||(i_ready)) begin if (cache_valid) o_illegal <= (o_illegal)||(cache_illegal); else if ((o_wb_cyc)&&(i_wb_err)) o_illegal <= 1'b1; end + // }}} - + // }}} //////////////////////////////////////////////////////////////////////// // // Now for the output/cached word - // + // {{{ //////////////////////////////////////////////////////////////////////// + // + // + // cache_valid + // {{{ initial cache_valid = 1'b0; always @(posedge i_clk) if ((i_reset)||(i_new_pc)||(i_clear_cache)) cache_valid <= 1'b0; else begin if ((o_valid)&&(o_wb_cyc)&&((i_wb_ack)||(i_wb_err))) - cache_valid <= (!i_stall_n)||(cache_valid); - else if (i_stall_n) + cache_valid <= (!i_ready)||(cache_valid); + else if (i_ready) cache_valid <= 1'b0; end + // }}} + // cache_word + // {{{ always @(posedge i_clk) if (i_wb_ack) cache_word <= i_wb_data; + // }}} + // cache_illegal + // {{{ initial cache_illegal = 1'b0; always @(posedge i_clk) if ((i_reset)||(i_clear_cache)||(i_new_pc)) cache_illegal <= 1'b0; - else if ((o_wb_cyc)&&(i_wb_err)&&(o_valid)&&(!i_stall_n)) - cache_illegal <= 1'b1; + // Older logic ... + // else if ((o_wb_cyc)&&(i_wb_err)&&(o_valid)&&(!i_ready)) + // cache_illegal <= 1'b1; + else if ((o_valid && (!i_ready || cache_valid)) + &&(o_wb_cyc)&&(i_wb_ack || i_wb_err)) + cache_illegal <= i_wb_err; + // }}} + + // }}} +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal property section +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// `ifdef FORMAL // The formal properties for this design are maintained elsewhere `endif // FORMAL +// }}} endmodule -// -// Usage: (this) (prior) (old) (S6) -// Cells 374 387 585 459 -// FDRE 135 108 203 171 -// LUT1 2 3 2 -// LUT2 9 3 4 5 -// LUT3 98 76 104 71 -// LUT4 2 0 2 2 -// LUT5 3 35 35 3 -// LUT6 6 5 10 43 -// MUXCY 58 62 93 62 -// MUXF7 1 0 2 3 -// MUXF8 0 1 1 -// RAM64X1D 0 32 32 32 -// XORCY 60 64 96 64 -// diff --git a/rtl/cpu/dcache.v b/rtl/cpu/dcache.v index c66d33d..11f14bd 100644 --- a/rtl/cpu/dcache.v +++ b/rtl/cpu/dcache.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: dcache.v -// +// {{{ // Project: Zip CPU -- a small, lightweight, RISC CPU soft core // // Purpose: To provide a simple data cache for the ZipCPU. The cache is @@ -47,9 +47,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2016-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2016-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -59,77 +59,87 @@ // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // // `default_nettype none // // -module dcache(i_clk, i_reset, i_clear, i_pipe_stb, i_lock, - i_op, i_addr, i_data, i_oreg, - o_busy, o_pipe_stalled, o_valid, o_err, o_wreg,o_data, - o_wb_cyc_gbl, o_wb_cyc_lcl, o_wb_stb_gbl, o_wb_stb_lcl, - o_wb_we, o_wb_addr, o_wb_data, o_wb_sel, - i_wb_stall, i_wb_ack, i_wb_err, i_wb_data `ifdef FORMAL - , f_nreqs, f_nacks, f_outstanding, f_pc +`define ASSERT assert + +`ifdef DCACHE +`define ASSUME assume +`else +`define ASSUME assert `endif +`endif + // }}} +module dcache #( + // {{{ + parameter LGCACHELEN = 8, + ADDRESS_WIDTH=30, + LGNLINES=(LGCACHELEN-3), // Log of the number of separate cache lines + NAUX=5, // # of aux d-wires to keep aligned w/memops + parameter [0:0] OPT_LOCAL_BUS=1'b1, + parameter [0:0] OPT_PIPE=1'b1, + parameter [0:0] OPT_LOCK=1'b1, + parameter [0:0] OPT_DUAL_READ_PORT=1'b1, + parameter OPT_FIFO_DEPTH = 4, + localparam AW = ADDRESS_WIDTH, // Just for ease of notation below + localparam CS = LGCACHELEN, // Number of bits in a cache address + localparam LS = CS-LGNLINES, // Bits to spec position w/in cline + parameter [0:0] OPT_LOWPOWER = 1'b0, + localparam DW = 32, // Bus data width + localparam DP = OPT_FIFO_DEPTH, + // + localparam [1:0] DC_IDLE = 2'b00, // Bus is idle + localparam [1:0] DC_WRITE = 2'b01, // Write + localparam [1:0] DC_READS = 2'b10, // Read a single value(!cachd) + localparam [1:0] DC_READC = 2'b11 // Read a whole cache line + // }}} + ) ( + // {{{ + input wire i_clk, i_reset, i_clear, + // Interface from the CPU + // {{{ + input wire i_pipe_stb, i_lock, + input wire [2:0] i_op, + input wire [(DW-1):0] i_addr, + input wire [(DW-1):0] i_data, + input wire [(NAUX-1):0] i_oreg, // Aux data, such as reg to write to + // Outputs, going back to the CPU + output reg o_busy, o_rdbusy, + output reg o_pipe_stalled, + output reg o_valid, o_err, + output reg [(NAUX-1):0] o_wreg, + output reg [(DW-1):0] o_data, + // }}} + // Wishbone bus master outputs + // {{{ + output wire o_wb_cyc_gbl, o_wb_cyc_lcl, + output reg o_wb_stb_gbl, o_wb_stb_lcl, + output reg o_wb_we, + output reg [(AW-1):0] o_wb_addr, + output reg [(DW-1):0] o_wb_data, + output wire [(DW/8-1):0] o_wb_sel, + // Wishbone bus slave response inputs + input wire i_wb_stall, i_wb_ack, i_wb_err, + input wire [(DW-1):0] i_wb_data + // }}} + // }}} ); - parameter LGCACHELEN = 8, - ADDRESS_WIDTH=30, - LGNLINES=(LGCACHELEN-3), // Log of the number of separate cache lines - NAUX=5; // # of aux d-wires to keep aligned w/memops - parameter [0:0] OPT_LOCAL_BUS=1'b1; - parameter [0:0] OPT_PIPE=1'b1; - parameter [0:0] OPT_LOCK=1'b1; - parameter [0:0] OPT_DUAL_READ_PORT=1'b1; - parameter OPT_FIFO_DEPTH = 4; - localparam AW = ADDRESS_WIDTH; // Just for ease of notation below - localparam CS = LGCACHELEN; // Number of bits in a cache address - localparam LS = CS-LGNLINES; // Bits to spec position w/in cline - parameter F_LGDEPTH=1 + (((!OPT_PIPE)||(LS > OPT_FIFO_DEPTH)) - ? LS : OPT_FIFO_DEPTH); - localparam LGAUX = 3; // log_2 of the maximum number of piped data - localparam DW = 32; // Bus data width - localparam DP = OPT_FIFO_DEPTH; - // - localparam [1:0] DC_IDLE = 2'b00; // Bus is idle - localparam [1:0] DC_WRITE = 2'b01; // Write - localparam [1:0] DC_READS = 2'b10; // Read a single value(!cachd) - localparam [1:0] DC_READC = 2'b11; // Read a whole cache line - // - input wire i_clk, i_reset, i_clear; - // Interface from the CPU - input wire i_pipe_stb, i_lock; - input wire [2:0] i_op; - input wire [(DW-1):0] i_addr; - input wire [(DW-1):0] i_data; - input wire [(NAUX-1):0] i_oreg; // Aux data, such as reg to write to - // Outputs, going back to the CPU - output reg o_busy; - output reg o_pipe_stalled; - output reg o_valid, o_err; - output reg [(NAUX-1):0] o_wreg; - output reg [(DW-1):0] o_data; - // Wishbone bus master outputs - output wire o_wb_cyc_gbl, o_wb_cyc_lcl; - output reg o_wb_stb_gbl, o_wb_stb_lcl; - output reg o_wb_we; - output reg [(AW-1):0] o_wb_addr; - output reg [(DW-1):0] o_wb_data; - output wire [(DW/8-1):0] o_wb_sel; - // Wishbone bus slave response inputs - input wire i_wb_stall, i_wb_ack, i_wb_err; - input wire [(DW-1):0] i_wb_data; + + // Declarations + // {{{ // // output reg [31:0] o_debug; - reg cyc, stb, last_ack, end_of_line, last_line_stb; reg r_wb_cyc_gbl, r_wb_cyc_lcl; // npending is the number of pending non-cached operations, counted @@ -164,42 +174,46 @@ module dcache(i_clk, i_reset, i_clear, i_pipe_stb, i_lock, wire [(LGNLINES-1):0] i_cline; wire [(CS-1):0] i_caddr; - assign i_cline = i_addr[(CS+1):LS+2]; - assign i_caddr = i_addr[(CS+1):2]; - wire cache_miss_inow, w_cachable; - assign cache_miss_inow = (!last_tag_valid) - ||(last_tag != i_addr[(AW+1):LS+2]) - ||(!c_v[i_cline]); - wire raw_cachable_address; - - iscachable chkaddress(i_addr[AW+1:2], raw_cachable_address); - - assign w_cachable = ((!OPT_LOCAL_BUS)||(i_addr[(DW-1):(DW-8)]!=8'hff)) - &&((!i_lock)||(!OPT_LOCK))&&(raw_cachable_address); - reg r_cachable, r_svalid, r_dvalid, r_rd, r_cache_miss, r_rd_pending; reg [(AW-1):0] r_addr; wire [(LGNLINES-1):0] r_cline; wire [(CS-1):0] r_caddr; wire [(AW-LS-1):0] r_ctag; - - assign r_cline = r_addr[(CS-1):LS]; - assign r_caddr = r_addr[(CS-1):0]; - assign r_ctag = r_addr[(AW-1):LS]; - - reg wr_cstb, r_iv, in_cache; reg [(AW-LS-1):0] r_itag; reg [DW/8-1:0] r_sel; reg [(NAUX+4-1):0] req_data; reg gie; + // }}} + // Convenience assignments + // {{{ + assign i_cline = i_addr[(CS+1):LS+2]; + assign i_caddr = i_addr[(CS+1):2]; + assign cache_miss_inow = (!last_tag_valid) + ||(last_tag != i_addr[(AW+1):LS+2]) + ||(!c_v[i_cline]); - // + assign w_cachable = ((!OPT_LOCAL_BUS)||(i_addr[(DW-1):(DW-8)]!=8'hff)) + &&((!i_lock)||(!OPT_LOCK))&&(raw_cachable_address); + + + assign r_cline = r_addr[(CS-1):LS]; + assign r_caddr = r_addr[(CS-1):0]; + assign r_ctag = r_addr[(AW-1):LS]; + // }}} + + // Cachability checking + // {{{ + iscachable chkaddress(i_addr[AW+1:2], raw_cachable_address); + // }}} + + // r_* values + // {{{ // The one-clock delayed read values from the cache. // initial r_rd = 1'b0; @@ -285,12 +299,15 @@ module dcache(i_clk, i_reset, i_clear, i_pipe_stb, i_lock, last_tag_valid <= 0; end end + // }}} + // o_wb_sel, r_sel + // {{{ initial r_sel = 4'hf; always @(posedge i_clk) if (i_reset) r_sel <= 4'hf; - else if (!o_pipe_stalled) + else if (!o_pipe_stalled && (!OPT_LOWPOWER || i_pipe_stb)) begin casez({i_op[2:1], i_addr[1:0]}) 4'b0???: r_sel <= 4'b1111; @@ -301,25 +318,56 @@ module dcache(i_clk, i_reset, i_clear, i_pipe_stb, i_lock, 4'b1110: r_sel <= 4'b0010; 4'b1111: r_sel <= 4'b0001; endcase - end + end else if (OPT_LOWPOWER && !i_wb_stall) + r_sel <= 4'h0; assign o_wb_sel = (state == DC_READC) ? 4'hf : r_sel; + // }}} + // o_wb_data + // {{{ initial o_wb_data = 0; always @(posedge i_clk) if (i_reset) o_wb_data <= 0; - else if (!o_busy || !i_wb_stall) + else if ((!o_busy || !i_wb_stall) && (!OPT_LOWPOWER || i_pipe_stb)) begin - casez(i_op[2:1]) - 2'b0?: o_wb_data <= i_data; - 2'b10: o_wb_data <= { (2){i_data[15:0]} }; - 2'b11: o_wb_data <= { (4){i_data[ 7:0]} }; - endcase - end + if (DW == 32) + begin + if (OPT_LOWPOWER) + begin : ZERO_UNUSED_DATA_BITS + casez({ i_op[2:1], i_addr[1:0] }) + 4'b0???: o_wb_data <= i_data; + 4'b100?: o_wb_data <= { i_data[15:0], 16'h0 }; + 4'b101?: o_wb_data <= { 16'h0, i_data[15:0] }; + 4'b1100: o_wb_data <= { i_data[7:0], 24'h0 }; + 4'b1101: o_wb_data <= { 8'h0, i_data[7:0], 16'h0 }; + 4'b1110: o_wb_data <= { 16'h0, i_data[7:0], 8'h0 }; + 4'b1111: o_wb_data <= { 24'h0, i_data[7:0] }; + endcase + end else begin : DUPLICATE_UNUSED_DATA_BITS + casez(i_op[2:1]) + 2'b0?: o_wb_data <= i_data; + 2'b10: o_wb_data <= { (2){i_data[15:0]} }; + 2'b11: o_wb_data <= { (4){i_data[ 7:0]} }; + endcase + end + end else begin + casez(i_op[2:1]) + 2'b0?: o_wb_data <= i_data << (8*i_addr[$clog2(DW)-1:0]); + 2'b10: o_wb_data <= { 16'h0, i_data[15:0] } << (8*i_addr[$clog2(DW)-1:0]); + 2'b11: o_wb_data <= { 24'h0, i_data[7:0] } << (8*i_addr[$clog2(DW)-1:0]); + endcase + end + end else if (OPT_LOWPOWER && !i_wb_stall) + o_wb_data <= 0; + // }}} + // Register return FIFO + // {{{ generate if (OPT_PIPE) begin : OPT_PIPE_FIFO + // {{{ reg [NAUX+4-2:0] fifo_data [0:((1< for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // // `default_nettype none -// +// }}} // `include "cpudefs.v" // -module div(i_clk, i_reset, i_wr, i_signed, i_numerator, i_denominator, - o_busy, o_valid, o_err, o_quotient, o_flags); - parameter BW=32, LGBW = 5; - input wire i_clk, i_reset; - // Input parameters - input wire i_wr, i_signed; - input wire [(BW-1):0] i_numerator, i_denominator; - // Output parameters - output reg o_busy, o_valid, o_err; - output reg [(BW-1):0] o_quotient; - output wire [3:0] o_flags; - +module div #( + parameter BW=32, LGBW = 5 + ) ( + // {{{ + input wire i_clk, i_reset, + // Input parameters + input wire i_wr, i_signed, + input wire [(BW-1):0] i_numerator, i_denominator, + // Output parameters + output reg o_busy, o_valid, o_err, + output reg [(BW-1):0] o_quotient, + output wire [3:0] o_flags + // }}} + ); + + // Local declarations + // {{{ // r_busy is an internal busy register. It will clear one clock // before we are valid, so it can't be o_busy ... // @@ -120,14 +125,18 @@ module div(i_clk, i_reset, i_wr, i_signed, i_numerator, i_denominator, wire [(BW):0] diff; // , xdiff[(BW-1):0]; assign diff = r_dividend[2*BW-2:BW-1] - r_divisor; - reg r_sign, pre_sign, r_z, r_c, last_bit; + reg r_sign, pre_sign, r_z, r_c, last_bit; reg [(LGBW-1):0] r_bit; - reg zero_divisor; + reg zero_divisor; + wire w_n; + // }}} + // r_busy + // {{{ // The Divide logic begins with r_busy. We use r_busy to determine // whether or not the divide is in progress, vs being complete. // Here, we clear r_busy on any reset and set it on i_wr (the request - // do to a divide). The divide ends when we are on the last bit, + // to do a divide). The divide ends when we are on the last bit, // or equivalently when we discover we are dividing by zero. initial r_busy = 1'b0; always @(posedge i_clk) @@ -137,7 +146,10 @@ module div(i_clk, i_reset, i_wr, i_signed, i_numerator, i_denominator, r_busy <= 1'b1; else if ((last_bit)||(zero_divisor)) r_busy <= 1'b0; + // }}} + // o_busy + // {{{ // o_busy is very similar to r_busy, save for some key differences. // Primary among them is that o_busy needs to (possibly) be true // for an extra clock after r_busy clears. This would be that extra @@ -154,11 +166,17 @@ module div(i_clk, i_reset, i_wr, i_signed, i_numerator, i_denominator, o_busy <= 1'b0; else if (!r_busy) o_busy <= 1'b0; + // }}} + // zero_divisor + // {{{ always @(posedge i_clk) if (i_wr) zero_divisor <= (i_denominator == 0); + // }}} + // o_valid + // {{{ // o_valid is part of the ZipCPU protocol. It will be set to true // anytime our answer is valid and may be used by the calling module. // Indeed, the ZipCPU will halt (and ignore us) once the i_wr has been @@ -183,7 +201,10 @@ module div(i_clk, i_reset, i_wr, i_signed, i_numerator, i_denominator, o_valid <= 1'b1; end else o_valid <= 1'b0; + // }}} + // o_err + // {{{ // Division by zero error reporting. Anytime we detect a zero divisor, // we set our output error, and then hold it until we are valid and // everything clears. @@ -195,9 +216,10 @@ module div(i_clk, i_reset, i_wr, i_signed, i_numerator, i_denominator, o_err <= 1'b1; else o_err <= 1'b0; + // }}} // r_bit - // + // {{{ // Keep track of which "bit" of our divide we are on. This number // ranges from 31 down to zero. On any write, we set ourselves to // 5'h1f. Otherwise, while we are busy (but not within the pre-sign @@ -210,9 +232,10 @@ module div(i_clk, i_reset, i_wr, i_signed, i_numerator, i_denominator, r_bit <= r_bit + 1'b1; else r_bit <= 0; + // }}} // last_bit - // + // {{{ // This logic replaces a lot of logic that was inside our giant state // machine with ... something simpler. In particular, we'll use this // logic to determine if we are processing our last bit. The only trick @@ -227,9 +250,10 @@ module div(i_clk, i_reset, i_wr, i_signed, i_numerator, i_denominator, last_bit <= (r_bit == {(LGBW){1'b1}}-1'b1); else last_bit <= 1'b0; + // }}} // pre_sign - // + // {{{ // This is part of the state machine. pre_sign indicates that we need // a extra clock to take the absolute value of our inputs. It need only // be true for the one clock, and then it must clear itself. @@ -239,7 +263,10 @@ module div(i_clk, i_reset, i_wr, i_signed, i_numerator, i_denominator, pre_sign <= 1'b0; else pre_sign <= (i_wr)&&(i_signed)&&((i_numerator[BW-1])||(i_denominator[BW-1])); + // }}} + // r_z + // {{{ // As a result of our operation, we need to set the flags. The most // difficult of these is the "Z" flag indicating that the result is // zero. Here, we'll use the same logic that sets the low-order @@ -250,8 +277,10 @@ module div(i_clk, i_reset, i_wr, i_signed, i_numerator, i_denominator, r_z <= 1'b1; else if ((r_busy)&&(!pre_sign)&&(!diff[BW])) r_z <= 1'b0; + // }}} // r_dividend + // {{{ // This is initially the numerator. On a signed divide, it then becomes // the absolute value of the numerator. We'll subtract from this value // the divisor for every output bit we are looking for--just as with @@ -277,7 +306,10 @@ module div(i_clk, i_reset, i_wr, i_signed, i_numerator, i_denominator, // guarantees that, when i_wr is set, the new value // is already set as desired. r_dividend <= { 31'h0, i_numerator }; + // }}} + // r_divisor + // {{{ initial r_divisor = 0; always @(posedge i_clk) if (i_reset) @@ -288,8 +320,10 @@ module div(i_clk, i_reset, i_wr, i_signed, i_numerator, i_denominator, r_divisor <= -r_divisor; end else if (!r_busy) r_divisor <= i_denominator; + // }}} // r_sign + // {{{ // is a flag for our state machine control(s). r_sign will be set to // true any time we are doing a signed divide and the result must be // negative. In that case, we take a final logic stage at the end of @@ -308,7 +342,10 @@ module div(i_clk, i_reset, i_wr, i_signed, i_numerator, i_denominator, r_sign <= (r_sign)&&(!zero_divisor); else r_sign <= 1'b0; + // }}} + // o_quotient + // {{{ initial o_quotient = 0; always @(posedge i_clk) if (i_reset) @@ -322,7 +359,10 @@ module div(i_clk, i_reset, i_wr, i_signed, i_numerator, i_denominator, o_quotient <= -o_quotient; else o_quotient <= 0; + // }}} + // r_c + // {{{ // Set Carry on an exact divide // Perhaps nothing uses this, but ... well, I suppose we could remove // this logic eventually, just ... not yet. @@ -332,17 +372,28 @@ module div(i_clk, i_reset, i_wr, i_signed, i_numerator, i_denominator, r_c <= 1'b0; else r_c <= (r_busy)&&(diff == 0); + // }}} + // w_n + // {{{ // The last flag: Negative. This flag is set assuming that the result // of the divide was negative (i.e., the high order bit is set). This // will also be true of an unsigned divide--if the high order bit is // ever set upon completion. Indeed, you might argue that there's no // logic involved. - wire w_n; assign w_n = o_quotient[(BW-1)]; + // }}} assign o_flags = { 1'b0, w_n, r_c, r_z }; - +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal properties +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// `ifdef FORMAL reg f_past_valid; initial f_past_valid = 0; @@ -424,8 +475,9 @@ module div(i_clk, i_reset, i_wr, i_signed, i_numerator, i_denominator, always @(*) if ((o_valid)&&(!o_err)) + begin assert(r_z == ((o_quotient == 0)? 1'b1:1'b0)); - else if (o_busy) + end else if (o_busy) assert(r_z == (((o_quotient&f_bits_set[BW-1:0]) == 0)? 1'b1: 1'b0)); always @(*) @@ -502,6 +554,7 @@ module div(i_clk, i_reset, i_wr, i_signed, i_numerator, i_denominator, assert((r_divisor == 0) == zero_divisor); `ifdef VERIFIC + // {{{ // Verify unsigned division assert property (@(posedge i_clk) disable iff (i_reset) @@ -522,7 +575,8 @@ module div(i_clk, i_reset, i_wr, i_signed, i_numerator, i_denominator, ##1 ((r_busy)&&(!o_err)&&(!o_valid)) ##1 ((o_err)&&(o_valid)))); - + // }}} `endif // VERIFIC `endif +// }}} endmodule diff --git a/rtl/cpu/icontrol.v b/rtl/cpu/icontrol.v index d7ce947..a361168 100644 --- a/rtl/cpu/icontrol.v +++ b/rtl/cpu/icontrol.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: icontrol.v -// +// {{{ // Project: Zip CPU -- a small, lightweight, RISC CPU soft core // // Purpose: An interrupt controller, for managing many interrupt sources. @@ -51,9 +51,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015,2017-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -68,41 +68,48 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // // `default_nettype none -// -module icontrol(i_clk, i_reset, i_wb_cyc, i_wb_stb, i_wb_we, i_wb_data, - i_wb_sel, - o_wb_stall, o_wb_ack, o_wb_data, - i_brd_ints, o_interrupt); - parameter IUSED = 12, DW=32; - input wire i_clk, i_reset; - input wire i_wb_cyc, i_wb_stb, i_wb_we; - input wire [DW-1:0] i_wb_data; - input wire [DW/8-1:0] i_wb_sel; - output wire o_wb_stall, o_wb_ack; - output reg [DW-1:0] o_wb_data; - input wire [(IUSED-1):0] i_brd_ints; - output reg o_interrupt; +// }}} +module icontrol #( + // {{{ + parameter IUSED = 12, DW=32 + // }}} + ) ( + // {{{ + input wire i_clk, i_reset, + input wire i_wb_cyc, i_wb_stb, i_wb_we, + input wire [DW-1:0] i_wb_data, + input wire [DW/8-1:0] i_wb_sel, + output wire o_wb_stall, o_wb_ack, + output reg [DW-1:0] o_wb_data, + input wire [(IUSED-1):0] i_brd_ints, + output reg o_interrupt + // }}} + ); + // Local declarations + // {{{ reg [(IUSED-1):0] r_int_state; reg [(IUSED-1):0] r_int_enable; reg r_mie; wire w_any; wire wb_write, enable_ints, disable_ints; + // }}} assign wb_write = (i_wb_stb)&&(i_wb_we); assign enable_ints = (wb_write)&&( i_wb_data[15]); assign disable_ints = (wb_write)&&(!i_wb_data[15]); - // + // r_int_state + // {{{ // First step: figure out which interrupts have triggered. An // interrupt "triggers" when the incoming interrupt wire is high, and // stays triggered until cleared by the bus. @@ -115,8 +122,10 @@ module icontrol(i_clk, i_reset, i_wb_cyc, i_wb_stb, i_wb_we, i_wb_data, | (r_int_state & (~i_wb_data[(IUSED-1):0])); else r_int_state <= (r_int_state | i_brd_ints); + // }}} - // + // r_int_enable + // {{{ // Second step: determine which interrupts are enabled. // Only interrupts that are enabled will be propagated forward on // the global interrupt line. @@ -128,9 +137,11 @@ module icontrol(i_clk, i_reset, i_wb_cyc, i_wb_stb, i_wb_we, i_wb_data, r_int_enable <= r_int_enable | i_wb_data[16 +: IUSED]; else if (disable_ints) r_int_enable <= r_int_enable & (~ i_wb_data[16 +: IUSED]); + // }}} - // - // Third step: The global interrupt enable bit. + // r_mie + // {{{ + // Third step: The master (global) interrupt enable bit. initial r_mie = 1'b0; always @(posedge i_clk) if (i_reset) @@ -139,11 +150,14 @@ module icontrol(i_clk, i_reset, i_wb_cyc, i_wb_stb, i_wb_we, i_wb_data, r_mie <= 1'b1; else if (disable_ints && i_wb_data[DW-1]) r_mie <= 1'b0; + // }}} // // Have "any" enabled interrupts triggered? assign w_any = ((r_int_state & r_int_enable) != 0); + // o_interrupt + // {{{ // How then shall the interrupt wire be set? initial o_interrupt = 1'b0; always @(posedge i_clk) @@ -151,8 +165,10 @@ module icontrol(i_clk, i_reset, i_wb_cyc, i_wb_stb, i_wb_we, i_wb_data, o_interrupt <= 1'b0; else o_interrupt <= (r_mie)&&(w_any); + // }}} - // + // o_wb_data + // {{{ // Create the output data. Place this into the next clock, to keep // it synchronous with w_any. initial o_wb_data = 0; @@ -165,8 +181,13 @@ module icontrol(i_clk, i_reset, i_wb_cyc, i_wb_stb, i_wb_we, i_wb_data, o_wb_data[16 +: IUSED] <= r_int_enable; o_wb_data[ 0 +: IUSED] <= r_int_state; end + // }}} + + assign o_wb_ack = i_wb_stb; + assign o_wb_stall = 1'b0; // Make verilator happy + // {{{ generate if (IUSED < 15) begin // verilator lint_off UNUSED @@ -177,15 +198,22 @@ module icontrol(i_clk, i_reset, i_wb_cyc, i_wb_stb, i_wb_we, i_wb_data, end endgenerate - assign o_wb_ack = i_wb_stb; - assign o_wb_stall = 1'b0; - // Verilator lint_off UNUSED wire unused; assign unused = &{ 1'b0, i_wb_cyc, i_wb_sel }; // verilator lint_on UNUSED - + // }}} +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal properties section +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// `ifdef FORMAL // Formal properties for this module are maintained elsewhere `endif +// }}} endmodule diff --git a/rtl/cpu/idecode.v b/rtl/cpu/idecode.v index 59afce7..21fc55f 100644 --- a/rtl/cpu/idecode.v +++ b/rtl/cpu/idecode.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: idecode.v -// +// {{{ // Project: Zip CPU -- a small, lightweight, RISC CPU soft core // // Purpose: This RTL file specifies how instructions are to be decoded @@ -18,9 +18,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -36,79 +36,74 @@ // target there if the PDF file isn't present.) If not, see // for a copy. // +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // // `default_nettype none +// }}} // -`define CPU_SP_REG 4'hd -`define CPU_CC_REG 4'he -`define CPU_PC_REG 4'hf // -`define CISBIT 31 -`define CISIMMSEL 23 -`define IMMSEL 18 -// -// -// -module idecode(i_clk, i_reset, i_ce, i_stalled, - i_instruction, i_gie, i_pc, i_pf_valid, - i_illegal, - o_valid, - o_phase, o_illegal, - o_pc, - o_dcdR, o_dcdA, o_dcdB, - o_preA, o_preB, - o_I, o_zI, - o_cond, o_wF, - o_op, o_ALU, o_M, o_DV, o_FP, o_break, o_lock, - o_wR, o_rA, o_rB, - o_early_branch, o_early_branch_stb, o_branch_pc, o_ljmp, - o_pipe, - o_sim, o_sim_immv - ); - parameter ADDRESS_WIDTH=24; - parameter [0:0] OPT_MPY = 1'b1; - parameter [0:0] OPT_EARLY_BRANCHING = 1'b1; - parameter [0:0] OPT_PIPELINED = 1'b1; - parameter [0:0] OPT_DIVIDE = (OPT_PIPELINED); - parameter [0:0] OPT_FPU = 1'b0; - parameter [0:0] OPT_CIS = 1'b1; - parameter [0:0] OPT_LOCK = (OPT_PIPELINED); - parameter [0:0] OPT_OPIPE = (OPT_PIPELINED); - parameter [0:0] OPT_SIM = 1'b0; - parameter [0:0] OPT_NO_USERMODE = 1'b0; - localparam AW = ADDRESS_WIDTH; - // - input wire i_clk, i_reset, i_ce, i_stalled; - input wire [31:0] i_instruction; - input wire i_gie; - input wire [(AW+1):0] i_pc; - input wire i_pf_valid, i_illegal; - output wire o_valid, o_phase; - output reg o_illegal; - output reg [(AW+1):0] o_pc; - output reg [6:0] o_dcdR, o_dcdA, o_dcdB; - output wire [4:0] o_preA, o_preB; - output wire [31:0] o_I; - output reg o_zI; - output reg [3:0] o_cond; - output reg o_wF; - output reg [3:0] o_op; - output reg o_ALU, o_M, o_DV, o_FP, o_break; - output reg o_lock; - output reg o_wR, o_rA, o_rB; - output wire o_early_branch, o_early_branch_stb; - output wire [(AW+1):0] o_branch_pc; - output wire o_ljmp; - output wire o_pipe; - output reg o_sim /* verilator public_flat */; - output reg [22:0] o_sim_immv /* verilator public_flat */; - +module idecode #( + // {{{ + parameter ADDRESS_WIDTH=24, + parameter [0:0] OPT_MPY = 1'b1, + parameter [0:0] OPT_EARLY_BRANCHING = 1'b1, + parameter [0:0] OPT_PIPELINED = 1'b1, + parameter [0:0] OPT_DIVIDE = (OPT_PIPELINED), + parameter [0:0] OPT_FPU = 1'b0, + parameter [0:0] OPT_CIS = 1'b1, + parameter [0:0] OPT_LOCK = (OPT_PIPELINED), + parameter [0:0] OPT_OPIPE = (OPT_PIPELINED), + parameter [0:0] OPT_SIM = 1'b0, + parameter [0:0] OPT_NO_USERMODE = 1'b0, + localparam AW = ADDRESS_WIDTH + // }}} + ) ( + // {{{ + input wire i_clk, i_reset, i_ce, i_stalled, + input wire [31:0] i_instruction, + input wire i_gie, + input wire [(AW+1):0] i_pc, + input wire i_pf_valid, i_illegal, + output wire o_valid, o_phase, + output reg o_illegal, + output reg [(AW+1):0] o_pc, + output reg [6:0] o_dcdR, o_dcdA, o_dcdB, + output wire [4:0] o_preA, o_preB, + output wire [31:0] o_I, + output reg o_zI, + output reg [3:0] o_cond, + output reg o_wF, + output reg [3:0] o_op, + output reg o_ALU, o_M, o_DV, o_FP, o_break, + output reg o_lock, + output reg o_wR, o_rA, o_rB, + output wire o_early_branch, o_early_branch_stb, + output wire [(AW+1):0] o_branch_pc, + output wire o_ljmp, + output wire o_pipe, + output reg o_sim /* verilator public_flat */, + output reg [22:0] o_sim_immv /* verilator public_flat */ +`ifdef FORMAL + , output reg [31:0] f_insn_word, + output reg f_insn_gie +`endif + // }}} + ); + + // Declarations + // {{{ + localparam [3:0] CPU_SP_REG = 4'hd, + CPU_CC_REG = 4'he, + CPU_PC_REG = 4'hf; + localparam CISBIT = 31, + CISIMMSEL = 23, + IMMSEL = 18; wire [4:0] w_op; wire w_ldi, w_mov, w_cmptst, w_ldilo, w_ALU, w_brev, @@ -125,11 +120,21 @@ module idecode(i_clk, i_reset, i_ce, i_stalled, wire [31:0] iword; wire pf_valid; - assign pf_valid = (i_pf_valid)&&(!o_early_branch_stb); + reg [14:0] r_nxt_half; + reg [4:0] w_cis_op; + reg [22:0] r_I, w_fullI; + wire [22:0] w_I; + wire w_Iz; + reg [1:0] w_immsrc; + reg r_valid, r_insn_is_pipeable; - reg [14:0] r_nxt_half; + // }}} + assign pf_valid = (i_pf_valid)&&(!o_early_branch_stb); + + // iword + // {{{ generate if (OPT_CIS) begin : SET_IWORD @@ -146,10 +151,13 @@ module idecode(i_clk, i_reset, i_ce, i_stalled, assign unused_nxt_half = r_nxt_half; // verilator lint_on UNUSED end endgenerate + // }}} + // w_ljmp, w_cis_ljmp : Long jump early branching + // {{{ generate if (OPT_EARLY_BRANCHING) - begin + begin : GEN_CIS_LONGJUMP if (OPT_CIS) begin : CIS_EARLY_BRANCHING @@ -163,19 +171,20 @@ module idecode(i_clk, i_reset, i_ce, i_stalled, assign w_ljmp = (iword == 32'h7c87c000); - end else begin : NO_EARLY_BRANCHING + end else begin : NO_CIS_JUMPING assign w_cis_ljmp = 1'b0; assign w_ljmp = 1'b0; end endgenerate + // }}} - reg [4:0] w_cis_op; - + // w_cis_op : Get the opcode + // {{{ generate if (OPT_CIS) begin : GEN_CIS_OP always @(*) - if (!iword[`CISBIT]) + if (!iword[CISBIT]) w_cis_op = iword[26:22]; else case(iword[26:24]) 3'h0: w_cis_op = 5'h00; // ADD @@ -194,8 +203,10 @@ module idecode(i_clk, i_reset, i_ce, i_stalled, w_cis_op = w_op; end endgenerate + // }}} // Decode instructions + // {{{ assign w_op= iword[26:22]; assign w_mov = (w_cis_op == 5'h0d); assign w_ldi = (w_cis_op[4:1] == 4'hc); @@ -208,61 +219,67 @@ module idecode(i_clk, i_reset, i_ce, i_stalled, assign w_add = (w_cis_op[4:0] == 5'h02); assign w_mem = (w_cis_op[4:3] == 2'b10)&&(w_cis_op[2:1] !=2'b00); assign w_sto = (w_mem)&&( w_cis_op[0]); - assign w_div = (!iword[`CISBIT])&&(w_op[4:1] == 4'h7); - assign w_fpu = (!iword[`CISBIT])&&(w_op[4:3] == 2'b11) + assign w_div = (!iword[CISBIT])&&(w_op[4:1] == 4'h7); + assign w_fpu = (!iword[CISBIT])&&(w_op[4:3] == 2'b11) &&(w_dcdR[3:1] != 3'h7)&&(w_op[2:1] != 2'b00); // If the result register is either CC or PC, and this would otherwise // be a floating point instruction with floating point opcode of 0, // then this is a NOOP. - assign w_special= (!iword[`CISBIT])&&((!OPT_FPU)||(w_dcdR[3:1]==3'h7)) + assign w_special= (!iword[CISBIT])&&((!OPT_FPU)||(w_dcdR[3:1]==3'h7)) &&(w_op[4:2] == 3'b111); assign w_break = (w_special)&&(w_op[4:0]==5'h1c); assign w_lock = (w_special)&&(w_op[4:0]==5'h1d); assign w_sim = (w_special)&&(w_op[4:0]==5'h1e); assign w_noop = (w_special)&&(w_op[4:1]==4'hf); // Must include w_sim + // }}} - - // w_dcdR (4 LUTs) - // + // w_dcdR, w_dcdA + // {{{ // What register will we be placing results into (if at all)? // // Two parts to the result register: the register set, given for // moves in iword[18] but only for the supervisor, and the other // four bits encoded in the instruction. // - assign w_dcdR = { ((!iword[`CISBIT])&&(!OPT_NO_USERMODE)&&(w_mov)&&(!i_gie))?iword[`IMMSEL]:i_gie, + assign w_dcdR = { ((!iword[CISBIT])&&(!OPT_NO_USERMODE)&&(w_mov)&&(!i_gie))?iword[IMMSEL]:i_gie, iword[30:27] }; - // dcdB - What register is used in the opB? - // - assign w_dcdB[4] = ((!iword[`CISBIT])&&(w_mov)&&(!OPT_NO_USERMODE)&&(!i_gie))?iword[13]:i_gie; - assign w_dcdB[3:0]= (iword[`CISBIT]) - ? (((!iword[`CISIMMSEL])&&(iword[26:25]==2'b10)) - ? `CPU_SP_REG : iword[22:19]) - : iword[17:14]; - // 0 LUTs assign w_dcdA = w_dcdR; // on ZipCPU, A is always result reg - // 2 LUTs, 1 delay each - assign w_dcdR_pc = (w_dcdR == {i_gie, `CPU_PC_REG}); - assign w_dcdR_cc = (w_dcdR == {i_gie, `CPU_CC_REG}); // 0 LUTs assign w_dcdA_pc = w_dcdR_pc; assign w_dcdA_cc = w_dcdR_cc; + // 2 LUTs, 1 delay each + assign w_dcdR_pc = (w_dcdR == {i_gie, CPU_PC_REG}); + assign w_dcdR_cc = (w_dcdR == {i_gie, CPU_CC_REG}); + // }}} + + // dcdB - What register is used in the opB? + // {{{ + assign w_dcdB[4] = ((!iword[CISBIT])&&(w_mov)&&(!OPT_NO_USERMODE)&&(!i_gie))?iword[13]:i_gie; + assign w_dcdB[3:0]= (iword[CISBIT]) + ? (((!iword[CISIMMSEL])&&(iword[26:25]==2'b10)) + ? CPU_SP_REG : iword[22:19]) + : iword[17:14]; + // 2 LUTs, 1 delays each - assign w_dcdB_pc = (w_rB)&&(w_dcdB[3:0] == `CPU_PC_REG); - assign w_dcdB_cc = (w_rB)&&(w_dcdB[3:0] == `CPU_CC_REG); + assign w_dcdB_pc = (w_rB)&&(w_dcdB[3:0] == CPU_PC_REG); + assign w_dcdB_cc = (w_rB)&&(w_dcdB[3:0] == CPU_CC_REG); + // }}} - // + // w_cond + // {{{ // Under what condition will we execute this instruction? Only the // load immediate instruction and the CIS instructions are completely // unconditional. Well ... not quite. The BREAK, LOCK, and SIM/NOOP // instructions are also unconditional. // - assign w_cond = ((w_ldi)||(w_special)||(iword[`CISBIT])) ? 4'h8 : + assign w_cond = ((w_ldi)||(w_special)||(iword[CISBIT])) ? 4'h8 : { (iword[21:19]==3'h0), iword[21:19] }; + // }}} // rA - do we need to read register A? + // {{{ assign w_rA = // Floating point reads reg A ((w_fpu)&&(OPT_FPU)) // Divide's read A @@ -274,50 +291,58 @@ module idecode(i_clk, i_reset, i_ce, i_stalled, ||(w_sto) // Test/compares ||(w_cmptst); - // rB -- do we read a register for operand B? Specifically, do we - // add the registers value to the immediate to create opB? + // }}} + + // rB -- do we read a register for operand B? + // {{{ + // Specifically, do we add the registers value to the immediate to + // create opB? assign w_rB = (w_mov) - ||((!iword[`CISBIT])&&(iword[`IMMSEL])&&(!w_ldi)&&(!w_special)) - ||(( iword[`CISBIT])&&(iword[`CISIMMSEL])&&(!w_ldi)) + ||((!iword[CISBIT])&&(iword[IMMSEL])&&(!w_ldi)&&(!w_special)) + ||(( iword[CISBIT])&&(iword[CISIMMSEL])&&(!w_ldi)) // If using compressed instruction sets, // we *always* read on memory operands. - ||(( iword[`CISBIT])&&(w_mem)); + ||(( iword[CISBIT])&&(w_mem)); + // }}} // wR -- will we be writing our result back? + // {{{ // wR_n = !wR // All but STO, NOOP/BREAK/LOCK, and CMP/TST write back to w_dcdR assign w_wR_n = (w_sto) ||(w_special) ||(w_cmptst); assign w_wR = !w_wR_n; + // }}} // // wF -- do we write flags when we are done? - // + // {{{ assign w_wF = (w_cmptst) ||((w_cond[3])&&(((w_fpu)&&(OPT_FPU))||(w_div) ||((w_ALU)&&(!w_mov)&&(!w_ldilo)&&(!w_brev) &&(w_dcdR[3:1] != 3'h7)))); + // }}} + // w_immsrc - where does the immediate value come from + // {{{ // Bottom 13 bits: no LUT's // w_dcd[12: 0] -- no LUTs // w_dcd[ 13] -- 2 LUTs // w_dcd[17:14] -- (5+i0+i1) = 3 LUTs, 1 delay // w_dcd[22:18] : 5 LUTs, 1 delay (assuming high bit is o/w determined) - reg [22:0] r_I, w_fullI; - wire [22:0] w_I; - wire w_Iz; - - reg [1:0] w_immsrc; always @(*) if (w_ldi) w_immsrc = 0; else if (w_mov) w_immsrc = 1; - else if (!iword[`IMMSEL]) + else if (!iword[IMMSEL]) w_immsrc = 2; - else // if (!iword[`IMMSEL]) + else // if (!iword[IMMSEL]) w_immsrc = 3; + // }}} + // w_fullI -- extracting the immediate value from the insn word + // {{{ always @(*) case(w_immsrc) 2'b00: w_fullI = { iword[22:0] }; // LDI @@ -330,22 +355,25 @@ module idecode(i_clk, i_reset, i_ce, i_stalled, // MOVE immediates have one less bit :((w_mov) ?{ {(23-13){iword[12]}}, iword[12:0] } // Normal Op-B immediate ... 18 or 14 bits - :((!iword[`IMMSEL]) ? { {(23-18){iword[17]}}, iword[17:0] } + :((!iword[IMMSEL]) ? { {(23-18){iword[17]}}, iword[17:0] } : { {(23-14){iword[13]}}, iword[13:0] } )); */ + // }}} + // w_I and w_Iz: Immediate value decoding + // {{{ generate if (OPT_CIS) begin : GEN_CIS_IMMEDIATE wire [7:0] w_halfbits; - assign w_halfbits = iword[`CISIMMSEL:16]; + assign w_halfbits = iword[CISIMMSEL:16]; wire [7:0] w_halfI; assign w_halfI = (iword[26:24]==3'h6) ? w_halfbits[7:0] // 8'b for LDI :(w_halfbits[7])? { {(6){w_halfbits[2]}}, w_halfbits[1:0]} :{ w_halfbits[6], w_halfbits[6:0] }; - assign w_I = (iword[`CISBIT]) + assign w_I = (iword[CISBIT]) ? {{(23-8){w_halfI[7]}}, w_halfI } : w_fullI; @@ -356,9 +384,10 @@ module idecode(i_clk, i_reset, i_ce, i_stalled, end endgenerate assign w_Iz = (w_I == 0); + // }}} - - // + // o_phase + // {{{ // The o_phase parameter is special. It needs to let the software // following know that it cannot break/interrupt on an o_phase asserted // instruction, lest the break take place between the first and second @@ -367,6 +396,7 @@ module idecode(i_clk, i_reset, i_ce, i_stalled, // a 32-bit instruction or the second half of a 2x16-bit instruction. generate if (OPT_CIS) begin : GEN_CIS_PHASE + // {{{ reg r_phase; // Phase is '1' on the first instruction of a two-part set @@ -388,32 +418,41 @@ module idecode(i_clk, i_reset, i_ce, i_stalled, // back to the first r_phase <= 0; else - r_phase <= (i_instruction[`CISBIT])&&(!i_illegal); + r_phase <= (i_instruction[CISBIT])&&(!i_illegal); end else if (i_ce) r_phase <= 1'b0; assign o_phase = r_phase; - end else begin + // }}} + end else begin : NO_CIS + // {{{ assign o_phase = 1'b0; + // }}} end endgenerate + // }}} - + // o_illegal + // {{{ initial o_illegal = 1'b0; always @(posedge i_clk) if (i_reset) o_illegal <= 1'b0; else if (i_ce && o_phase) begin + // {{{ o_illegal <= o_illegal; // Cannot happen in compressed word ... // 1. multiply op-codes // 2. divide opcodes // 3. FPU opcodes // 4. special opcodes - end else if (i_ce && i_pf_valid) begin + // }}} + end else if (i_ce && i_pf_valid) + begin + // {{{ o_illegal <= 1'b0; - if ((!OPT_CIS)&&(i_instruction[`CISBIT])) + if ((!OPT_CIS)&&(i_instruction[CISBIT])) o_illegal <= 1'b1; if ((!OPT_MPY)&&(w_mpy)) o_illegal <= 1'b1; @@ -445,10 +484,15 @@ module idecode(i_clk, i_reset, i_ce, i_stalled, if ((!OPT_LOCK)&&(w_lock)) o_illegal <= 1'b1; + // Bus errors always create illegal instructions if (i_illegal) o_illegal <= 1'b1; + // }}} end + // }}} + // o_pc + // {{{ initial o_pc = 0; always @(posedge i_clk) if ((i_ce)&&((o_phase)||(i_pf_valid))) @@ -457,7 +501,7 @@ module idecode(i_clk, i_reset, i_ce, i_stalled, if (OPT_CIS) begin - if (iword[`CISBIT]) + if (iword[CISBIT]) begin if (o_phase) o_pc[AW+1:1] <= o_pc[AW+1:1] + 1'b1; @@ -472,16 +516,25 @@ module idecode(i_clk, i_reset, i_ce, i_stalled, o_pc <= { i_pc[AW+1:2] + 1'b1, 2'b00 }; end end + // }}} + // Generate output products + // {{{ initial o_dcdR = 0; initial o_dcdA = 0; initial o_dcdB = 0; initial o_DV = 0; initial o_FP = 0; initial o_lock = 0; + initial o_sim = 1'b0; + initial o_sim_immv = 0; + // r_I, o_zI, o_wR, o_rA, o_rB, o_dcdR, o_dcdA, o_dcdB always @(posedge i_clk) if (i_ce) begin + // {{{ + // o_cond, o_wF + // {{{ // Under what condition will we execute this // instruction? Only the load immediate instruction // is completely unconditional. @@ -490,7 +543,10 @@ module idecode(i_clk, i_reset, i_ce, i_stalled, // UNLESS: the conditional instruction was a CMP // or TST instruction. o_wF <= w_wF; + // }}} + // o_op + // {{{ // Record what operation/op-code (4-bits) we are doing // Note that LDI magically becomes a MOV // instruction here. That way it's a pass through @@ -505,8 +561,8 @@ module idecode(i_clk, i_reset, i_ce, i_stalled, o_op <= w_cis_op[3:0]; if ((w_ldi)||(w_noop)||(w_lock)) o_op <= 4'hd; + // }}} - // Default values o_dcdR <= { w_dcdR_cc, w_dcdR_pc, w_dcdR}; o_dcdA <= { w_dcdA_cc, w_dcdA_pc, w_dcdA}; o_dcdB <= { w_dcdB_cc, w_dcdB_pc, w_dcdB}; @@ -516,6 +572,8 @@ module idecode(i_clk, i_reset, i_ce, i_stalled, r_I <= w_I; o_zI <= w_Iz; + // o_ALU, o_M, o_DV, o_FP + // {{{ // Turn a NOOP into an ALU operation--subtract in // particular, although it doesn't really matter as long // as it doesn't take longer than one clock. Note @@ -526,15 +584,21 @@ module idecode(i_clk, i_reset, i_ce, i_stalled, o_M <= w_mem; o_DV <= (OPT_DIVIDE)&&(w_div); o_FP <= (OPT_FPU)&&(w_fpu); + // }}} + // o_break, o_lock + // {{{ o_break <= w_break; o_lock <= (OPT_LOCK)&&(w_lock); + // }}} if (OPT_CIS) r_nxt_half <= { iword[14:0] }; else r_nxt_half <= 0; + // o_sim, o_sim_immv -- simulation instructions vs NOOPs + // {{{ if (OPT_SIM) begin // Support the SIM instruction(s) @@ -544,13 +608,19 @@ module idecode(i_clk, i_reset, i_ce, i_stalled, o_sim <= 1'b0; o_sim_immv <= 0; end + // }}} + // }}} end + // }}} assign o_preA = w_dcdA; assign o_preB = w_dcdB; + // o_early_branch, o_early_branch_stb, o_branch_pc + // {{{ generate if (OPT_EARLY_BRANCHING) begin : GEN_EARLY_BRANCH_LOGIC + // {{{ reg r_early_branch, r_early_branch_stb, r_ljmp; @@ -568,11 +638,11 @@ module idecode(i_clk, i_reset, i_ce, i_stalled, r_ljmp <= 1'b0; else if (pf_valid) begin - if ((OPT_CIS)&&(iword[`CISBIT])) + if ((OPT_CIS)&&(iword[CISBIT])) r_ljmp <= w_cis_ljmp; else r_ljmp <= (w_ljmp); - end else if ((OPT_CIS)&&(o_phase)&&(iword[`CISBIT])) + end else if ((OPT_CIS)&&(o_phase)&&(iword[CISBIT])) r_ljmp <= w_cis_ljmp; end assign o_ljmp = r_ljmp; @@ -591,10 +661,10 @@ module idecode(i_clk, i_reset, i_ce, i_stalled, // LW (PC),PC r_early_branch <= 1'b1; r_early_branch_stb <= 1'b1; - end else if ((!iword[`CISBIT])&&(iword[30:27]==`CPU_PC_REG) + end else if ((!iword[CISBIT])&&(iword[30:27]==CPU_PC_REG) &&(w_cond[3])) begin - if ((w_add)&&(!iword[`IMMSEL])) + if ((w_add)&&(!iword[IMMSEL])) begin // Add x,PC r_early_branch <= 1'b1; @@ -635,7 +705,9 @@ module idecode(i_clk, i_reset, i_ce, i_stalled, assign o_early_branch = r_early_branch; assign o_early_branch_stb = r_early_branch_stb; assign o_branch_pc = r_branch_pc; - end else begin + // }}} + end else begin : NO_EARLY_BRANCHING + // {{{ assign w_ljmp_dly = 1'b0; assign o_early_branch = 1'b0; assign o_early_branch_stb = 1'b0; @@ -646,9 +718,12 @@ module idecode(i_clk, i_reset, i_ce, i_stalled, wire early_branch_unused; assign early_branch_unused = w_add; // verilator lint_on UNUSED + // }}} end endgenerate + // }}} - + // o_pipe + // {{{ // To be a pipeable operation there must be ... // 1. Two valid adjacent instructions // 2. Both must be memory operations, of the same time (both lods @@ -659,14 +734,11 @@ module idecode(i_clk, i_reset, i_ce, i_stalled, // Note that we're not using iword here ... there's a lot of logic // taking place, and it's only valid if the new word is not compressed. // - reg r_valid, r_insn_is_pipeable; generate if (OPT_OPIPE) begin : GEN_OPIPE + // {{{ reg r_pipe; - wire [13:0] pipe_addr_diff; - assign pipe_addr_diff = w_I[13:0] - r_I[13:0]; - // Pipeline logic is too extreme for a single clock. // Let's break it into two clocks, using r_insn_is_pipeable // If this function is true, then the instruction associated @@ -682,7 +754,7 @@ module idecode(i_clk, i_reset, i_ce, i_stalled, r_insn_is_pipeable <= 1'b0; else if (o_ljmp) r_insn_is_pipeable <= 1'b0; - else if ((i_ce)&&((!OPT_CIS)&&(i_instruction[`CISBIT]))) + else if ((i_ce)&&((!OPT_CIS)&&(i_instruction[CISBIT]))) r_insn_is_pipeable <= 1'b0; else if (i_ce) begin // This is a valid instruction @@ -722,24 +794,25 @@ module idecode(i_clk, i_reset, i_ce, i_stalled, // Both must be register ops &&(w_rB) // Both must use the same register for B - &&(w_dcdB[3:0] == o_dcdB[3:0]) - // CC or PC registers are not valid addresses - // Captured above - // But ... the result can never be B - // Captured above - // - // Reads to CC or PC not allowed - // &&((o_op[0])||(w_dcdR[3:1] != 3'h7)) - // Prior-reads to CC or PC not allowed - // Captured above - // Same condition, or no condition before - &&((w_cond[2:0]==o_cond[2:0]) - ||(o_cond[2:0] == 3'h0)) - // Same or incrementing immediate - &&(w_I[13]==r_I[13]) - &&(pipe_addr_diff <= 14'h4); + &&(w_dcdB[3:0] == o_dcdB[3:0]); + // // CC or PC registers are not valid addresses + // // Captured above + // // But ... the result can never be B + // // Captured above + // // + // // Reads to CC or PC not allowed + // // &&((o_op[0])||(w_dcdR[3:1] != 3'h7)) + // // Prior-reads to CC or PC not allowed + // // Captured above + // // Same condition, or no condition now + // &&((w_cond[2:0]==o_cond[2:0]) + // ||(w_cond[2:0] == 3'h0)); + // // Same or incrementing immediate + // &&(w_I[22]==r_I[22]); assign o_pipe = r_pipe; + // }}} end else begin + // {{{ assign o_pipe = 1'b0; always @(*) r_insn_is_pipeable = 1'b0; @@ -748,8 +821,12 @@ module idecode(i_clk, i_reset, i_ce, i_stalled, wire unused_pipable; assign unused_pipable = r_insn_is_pipeable; // verilator lint_on UNUSED + // }}} end endgenerate + // }}} + // o_valid + // {{{ initial r_valid = 1'b0; generate if (OPT_PIPELINED) begin : GEN_DCD_VALID @@ -775,16 +852,29 @@ module idecode(i_clk, i_reset, i_ce, i_stalled, end endgenerate assign o_valid = r_valid; + // }}} assign o_I = { {(32-22){r_I[22]}}, r_I[21:0] }; // Make Verilator happy across all our various options + // {{{ // verilator lint_off UNUSED wire [5:0] possibly_unused; assign possibly_unused = { w_lock, w_ljmp, w_ljmp_dly, w_cis_ljmp, i_pc[1:0] }; // verilator lint_on UNUSED + // }}} +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal properties +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// `ifdef FORMAL // Formal properties for this module are maintained elsewhere `endif +// }}} endmodule diff --git a/rtl/cpu/iscachable.cpp b/rtl/cpu/iscachable.cpp deleted file mode 100644 index 255ebd9..0000000 --- a/rtl/cpu/iscachable.cpp +++ /dev/null @@ -1,62 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Filename: ./iscachable.v -// -// Project: ZBasic, a generic toplevel implementation using the full ZipCPU -// -// DO NOT EDIT THIS FILE! -// Computer Generated: This file is computer generated by AUTOFPGA. DO NOT EDIT. -// DO NOT EDIT THIS FILE! -// -// CmdLine: autofpga autofpga -o . clock.txt global.txt version.txt buserr.txt pic.txt pwrcount.txt gpio.txt rtclight.txt rtcdate.txt busconsole.txt bkram.txt flash.txt zipmaster.txt sdspi.txt mem_flash_bkram.txt mem_bkram_only.txt -// -// Creator: Dan Gisselquist, Ph.D. -// Gisselquist Technology, LLC -// -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2017-2020, Gisselquist Technology, LLC -// -// This program is free software (firmware): 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 MERCHANTIBILITY 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. (It's in the $(ROOT)/doc directory. Run make with no -// target there if the PDF file isn't present.) If not, see -// for a copy. -// -// License: GPL, v3, as defined and found on www.gnu.org, -// http://www.gnu.org/licenses/gpl.html -// -// -//////////////////////////////////////////////////////////////////////////////// -// -// -`default_nettype none -// -module iscachable(i_addr, o_cachable); - localparam AW = 23; - input wire [AW-1:0] i_addr; - output reg o_cachable; - - always @(*) - begin - o_cachable = 1'b0; - // Bus master: wb - // Bus master: wb_sio - // bkram - if ((i_addr[22:0] & 23'h780000) == 23'h300000) - o_cachable = 1'b1; - // flash - if ((i_addr[22:0] & 23'h400000) == 23'h400000) - o_cachable = 1'b1; - end - -endmodule diff --git a/rtl/cpu/iscachable.v b/rtl/cpu/iscachable.v index 4ae5c00..9e92f06 100644 --- a/rtl/cpu/iscachable.v +++ b/rtl/cpu/iscachable.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: ./iscachable.v -// +// {{{ // Project: ZBasic, a generic toplevel implementation using the full ZipCPU // // DO NOT EDIT THIS FILE! @@ -14,9 +14,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2017-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2017-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -31,14 +31,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} `default_nettype none // module iscachable(i_addr, o_cachable); diff --git a/rtl/cpu/memops.v b/rtl/cpu/memops.v index 39c92cf..a62a40d 100644 --- a/rtl/cpu/memops.v +++ b/rtl/cpu/memops.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: memops.v -// +// {{{ // Project: Zip CPU -- a small, lightweight, RISC CPU soft core // // Purpose: A memory unit to support a CPU. @@ -11,16 +11,17 @@ // before it completes the last one. Unpredictable results might then // occurr. // -// 20150919 -- Added support for handling BUS ERR's (i.e., the WB -// error signal). +// BIG ENDIAN +// Note that this core assumes a big endian bus, with the MSB +// of the bus word being the least bus address // // Creator: Dan Gisselquist, Ph.D. // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -35,58 +36,77 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // // `default_nettype none -// -module memops(i_clk, i_reset, i_stb, i_lock, - i_op, i_addr, i_data, i_oreg, - o_busy, o_valid, o_err, o_wreg, o_result, - o_wb_cyc_gbl, o_wb_cyc_lcl, - o_wb_stb_gbl, o_wb_stb_lcl, - o_wb_we, o_wb_addr, o_wb_data, o_wb_sel, - i_wb_stall, i_wb_ack, i_wb_err, i_wb_data - ); - parameter ADDRESS_WIDTH=30; - parameter [0:0] IMPLEMENT_LOCK=1'b1, - WITH_LOCAL_BUS=1'b1, - OPT_ALIGNMENT_ERR=1'b1, - OPT_ZERO_ON_IDLE=1'b0; - localparam AW=ADDRESS_WIDTH; - input wire i_clk, i_reset; - input wire i_stb, i_lock; - // CPU interface - input wire [2:0] i_op; - input wire [31:0] i_addr; - input wire [31:0] i_data; - input wire [4:0] i_oreg; - // CPU outputs - output wire o_busy; - output reg o_valid; - output reg o_err; - output reg [4:0] o_wreg; - output reg [31:0] o_result; - // Wishbone outputs - output wire o_wb_cyc_gbl; - output reg o_wb_stb_gbl; - output wire o_wb_cyc_lcl; - output reg o_wb_stb_lcl; - output reg o_wb_we; - output reg [(AW-1):0] o_wb_addr; - output reg [31:0] o_wb_data; - output reg [3:0] o_wb_sel; - // Wishbone inputs - input wire i_wb_stall, i_wb_ack, i_wb_err; - input wire [31:0] i_wb_data; +// }}} +module memops #( + // {{{ + parameter ADDRESS_WIDTH=30, + parameter [0:0] IMPLEMENT_LOCK=1'b1, + WITH_LOCAL_BUS=1'b1, + OPT_ALIGNMENT_ERR=1'b1, + OPT_LOWPOWER=1'b0, + OPT_LITTLE_ENDIAN = 1'b0, + localparam AW=ADDRESS_WIDTH, + parameter F_LGDEPTH = 2 + // }}} + ) ( + // {{{ + input wire i_clk, i_reset, + // CPU interface + // {{{ + input wire i_stb, i_lock, + input wire [2:0] i_op, + input wire [31:0] i_addr, + input wire [31:0] i_data, + input wire [4:0] i_oreg, + // CPU outputs + output wire o_busy, + output reg o_rdbusy, + output reg o_valid, + output reg o_err, + output reg [4:0] o_wreg, + output reg [31:0] o_result, + // }}} + // Wishbone + // {{{ + output wire o_wb_cyc_gbl, + output wire o_wb_cyc_lcl, + output reg o_wb_stb_gbl, + output reg o_wb_stb_lcl, + output reg o_wb_we, + output reg [(AW-1):0] o_wb_addr, + output reg [31:0] o_wb_data, + output reg [3:0] o_wb_sel, + // Wishbone inputs + input wire i_wb_stall, i_wb_ack, i_wb_err, + input wire [31:0] i_wb_data + // }}} + // }}} + ); + + // Declarations + // {{{ +`ifdef FORMAL + wire [(F_LGDEPTH-1):0] f_nreqs, f_nacks, f_outstanding; +`endif - reg misaligned; + reg misaligned; + reg r_wb_cyc_gbl, r_wb_cyc_lcl; + reg [3:0] r_op; + reg lock_gbl, lock_lcl; + wire gbl_stb, lcl_stb; + // }}} + // misaligned + // {{{ generate if (OPT_ALIGNMENT_ERR) begin : GENERATE_ALIGNMENT_ERR always @(*) @@ -100,14 +120,18 @@ module memops(i_clk, i_reset, i_stb, i_lock, end else always @(*) misaligned = 1'b0; endgenerate + // }}} - reg r_wb_cyc_gbl, r_wb_cyc_lcl; - wire gbl_stb, lcl_stb; + // lcl_stb, gbl_stb + // {{{ assign lcl_stb = (i_stb)&&(WITH_LOCAL_BUS!=0)&&(i_addr[31:24]==8'hff) &&(!misaligned); assign gbl_stb = (i_stb)&&((WITH_LOCAL_BUS==0)||(i_addr[31:24]!=8'hff)) &&(!misaligned); + // }}} + // r_wb_cyc_gbl, r_wb_cyc_lcl + // {{{ initial r_wb_cyc_gbl = 1'b0; initial r_wb_cyc_lcl = 1'b0; always @(posedge i_clk) @@ -127,31 +151,38 @@ module memops(i_clk, i_reset, i_stb, i_lock, r_wb_cyc_lcl <= (lcl_stb); r_wb_cyc_gbl <= (gbl_stb); end + // }}} + + // o_wb_stb_gbl + // {{{ initial o_wb_stb_gbl = 1'b0; always @(posedge i_clk) if (i_reset) o_wb_stb_gbl <= 1'b0; else if ((i_wb_err)&&(r_wb_cyc_gbl)) o_wb_stb_gbl <= 1'b0; + else if (gbl_stb) + o_wb_stb_gbl <= 1'b1; else if (o_wb_cyc_gbl) o_wb_stb_gbl <= (o_wb_stb_gbl)&&(i_wb_stall); - else - // Grab wishbone on any new transaction to the gbl bus - o_wb_stb_gbl <= (gbl_stb); + // }}} + // o_wb_stb_lcl + // {{{ initial o_wb_stb_lcl = 1'b0; always @(posedge i_clk) if (i_reset) o_wb_stb_lcl <= 1'b0; else if ((i_wb_err)&&(r_wb_cyc_lcl)) o_wb_stb_lcl <= 1'b0; + else if (lcl_stb) + o_wb_stb_lcl <= 1'b1; else if (o_wb_cyc_lcl) o_wb_stb_lcl <= (o_wb_stb_lcl)&&(i_wb_stall); - else - // Grab wishbone on any new transaction to the lcl bus - o_wb_stb_lcl <= (lcl_stb); + // }}} - reg [3:0] r_op; + // o_wb_we, o_wb_data, o_wb_sel + // {{{ initial o_wb_we = 1'b0; initial o_wb_data = 0; initial o_wb_sel = 0; @@ -159,15 +190,23 @@ module memops(i_clk, i_reset, i_stb, i_lock, if (i_stb) begin o_wb_we <= i_op[0]; - if (OPT_ZERO_ON_IDLE) + if (OPT_LOWPOWER) begin - casez({ i_op[2:1], i_addr[1:0] }) - 4'b100?: o_wb_data <= { i_data[15:0], 16'h00 }; - 4'b101?: o_wb_data <= { 16'h00, i_data[15:0] }; - 4'b1100: o_wb_data <= { i_data[7:0], 24'h00 }; - 4'b1101: o_wb_data <= { 8'h00, i_data[7:0], 16'h00 }; - 4'b1110: o_wb_data <= { 16'h00, i_data[7:0], 8'h00 }; - 4'b1111: o_wb_data <= { 24'h00, i_data[7:0] }; + casez({ OPT_LITTLE_ENDIAN, i_op[2:1], i_addr[1:0] }) + 5'b0100?: o_wb_data <= { i_data[15:0], 16'h00 }; + 5'b0101?: o_wb_data <= { 16'h00, i_data[15:0] }; + 5'b01100: o_wb_data <= { i_data[7:0], 24'h00 }; + 5'b01101: o_wb_data <= { 8'h00, i_data[7:0], 16'h00 }; + 5'b01110: o_wb_data <= { 16'h00, i_data[7:0], 8'h00 }; + 5'b01111: o_wb_data <= { 24'h00, i_data[7:0] }; + // + 5'b1100?: o_wb_data <= { 16'h00, i_data[15:0] }; + 5'b1101?: o_wb_data <= { i_data[15:0], 16'h00 }; + 5'b11100: o_wb_data <= { 24'h00, i_data[7:0] }; + 5'b11101: o_wb_data <= { 16'h00, i_data[7:0], 8'h00 }; + 5'b11110: o_wb_data <= { 8'h00, i_data[7:0], 16'h00 }; + 5'b11111: o_wb_data <= { i_data[7:0], 24'h00 }; + // default: o_wb_data <= i_data; endcase end else @@ -178,25 +217,37 @@ module memops(i_clk, i_reset, i_stb, i_lock, endcase o_wb_addr <= i_addr[(AW+1):2]; - casez({ i_op[2:1], i_addr[1:0] }) - 4'b01??: o_wb_sel <= 4'b1111; - 4'b100?: o_wb_sel <= 4'b1100; - 4'b101?: o_wb_sel <= 4'b0011; - 4'b1100: o_wb_sel <= 4'b1000; - 4'b1101: o_wb_sel <= 4'b0100; - 4'b1110: o_wb_sel <= 4'b0010; - 4'b1111: o_wb_sel <= 4'b0001; + casez({ OPT_LITTLE_ENDIAN, i_op[2:1], i_addr[1:0] }) + 5'b001??: o_wb_sel <= 4'b1111; + 5'b0100?: o_wb_sel <= 4'b1100; + 5'b0101?: o_wb_sel <= 4'b0011; + 5'b01100: o_wb_sel <= 4'b1000; + 5'b01101: o_wb_sel <= 4'b0100; + 5'b01110: o_wb_sel <= 4'b0010; + 5'b01111: o_wb_sel <= 4'b0001; + // + 5'b101??: o_wb_sel <= 4'b1111; + 5'b1100?: o_wb_sel <= 4'b0011; + 5'b1101?: o_wb_sel <= 4'b1100; + 5'b11100: o_wb_sel <= 4'b0001; + 5'b11101: o_wb_sel <= 4'b0010; + 5'b11110: o_wb_sel <= 4'b0100; + 5'b11111: o_wb_sel <= 4'b1000; + // default: o_wb_sel <= 4'b1111; endcase r_op <= { i_op[2:1] , i_addr[1:0] }; - end else if ((OPT_ZERO_ON_IDLE)&&(!o_wb_cyc_gbl)&&(!o_wb_cyc_lcl)) + end else if ((OPT_LOWPOWER)&&(!o_wb_cyc_gbl)&&(!o_wb_cyc_lcl)) begin o_wb_we <= 1'b0; o_wb_addr <= 0; o_wb_data <= 32'h0; o_wb_sel <= 4'h0; end + // }}} + // o_valid + // {{{ initial o_valid = 1'b0; always @(posedge i_clk) if (i_reset) @@ -204,6 +255,10 @@ module memops(i_clk, i_reset, i_stb, i_lock, else o_valid <= (((o_wb_cyc_gbl)||(o_wb_cyc_lcl)) &&(i_wb_ack)&&(!o_wb_we)); + // }}} + + // o_err + // {{{ initial o_err = 1'b0; always @(posedge i_clk) if (i_reset) @@ -214,34 +269,62 @@ module memops(i_clk, i_reset, i_stb, i_lock, o_err <= misaligned; else o_err <= 1'b0; + // }}} assign o_busy = (r_wb_cyc_gbl)||(r_wb_cyc_lcl); + // o_rdbusy + // {{{ + initial o_rdbusy = 1'b0; + always @(posedge i_clk) + if (i_reset|| ((o_wb_cyc_gbl || o_wb_cyc_lcl)&&(i_wb_err || i_wb_ack))) + o_rdbusy <= 1'b0; + else if (i_stb && !i_op[0] && !misaligned) + o_rdbusy <= 1'b1; + else if (o_valid) + o_rdbusy <= 1'b0; + // }}} + always @(posedge i_clk) if (i_stb) o_wreg <= i_oreg; + + // o_result + // {{{ always @(posedge i_clk) - if ((OPT_ZERO_ON_IDLE)&&(!i_wb_ack)) + if ((OPT_LOWPOWER)&&(!i_wb_ack)) o_result <= 32'h0; else begin - casez(r_op) - 4'b01??: o_result <= i_wb_data; - 4'b100?: o_result <= { 16'h00, i_wb_data[31:16] }; - 4'b101?: o_result <= { 16'h00, i_wb_data[15: 0] }; - 4'b1100: o_result <= { 24'h00, i_wb_data[31:24] }; - 4'b1101: o_result <= { 24'h00, i_wb_data[23:16] }; - 4'b1110: o_result <= { 24'h00, i_wb_data[15: 8] }; - 4'b1111: o_result <= { 24'h00, i_wb_data[ 7: 0] }; + casez({ OPT_LITTLE_ENDIAN, r_op }) + 5'b?01??: o_result <= i_wb_data; + // + // Big endian + 5'b0100?: o_result <= { 16'h00, i_wb_data[31:16] }; + 5'b0101?: o_result <= { 16'h00, i_wb_data[15: 0] }; + 5'b01100: o_result <= { 24'h00, i_wb_data[31:24] }; + 5'b01101: o_result <= { 24'h00, i_wb_data[23:16] }; + 5'b01110: o_result <= { 24'h00, i_wb_data[15: 8] }; + 5'b01111: o_result <= { 24'h00, i_wb_data[ 7: 0] }; + // + // Little endian : Same bus result, just grab a different bits + // from the bus return to send back to the CPU. + 5'b1100?: o_result <= { 16'h00, i_wb_data[15: 0] }; + 5'b1101?: o_result <= { 16'h00, i_wb_data[31:16] }; + 5'b11100: o_result <= { 24'h00, i_wb_data[ 7: 0] }; + 5'b11101: o_result <= { 24'h00, i_wb_data[15: 8] }; + 5'b11110: o_result <= { 24'h00, i_wb_data[23:16] }; + 5'b11111: o_result <= { 24'h00, i_wb_data[31:24] }; default: o_result <= i_wb_data; endcase end + // }}} - reg lock_gbl, lock_lcl; - + // lock_gbl and lock_lcl + // {{{ generate if (IMPLEMENT_LOCK != 0) begin - + // {{{ initial lock_gbl = 1'b0; initial lock_lcl = 1'b0; @@ -271,8 +354,9 @@ module memops(i_clk, i_reset, i_stb, i_lock, assign o_wb_cyc_gbl = (r_wb_cyc_gbl)||(lock_gbl); assign o_wb_cyc_lcl = (r_wb_cyc_lcl)||(lock_lcl); - end else begin - + // }}} + end else begin : NO_LOCK + // {{{ assign o_wb_cyc_gbl = (r_wb_cyc_gbl); assign o_wb_cyc_lcl = (r_wb_cyc_lcl); @@ -284,10 +368,19 @@ module memops(i_clk, i_reset, i_stb, i_lock, wire [2:0] lock_unused; assign lock_unused = { i_lock, lock_gbl, lock_lcl }; // verilator lint_on UNUSED - + // }}} end endgenerate + // }}} + +`ifdef VERILATOR + always @(posedge i_clk) + if ((r_wb_cyc_gbl)||(r_wb_cyc_lcl)) + assert(!i_stb); +`endif + // Make verilator happy + // {{{ // verilator lint_off UNUSED generate if (AW < 22) begin : TOO_MANY_ADDRESS_BITS @@ -297,8 +390,18 @@ module memops(i_clk, i_reset, i_stb, i_lock, end endgenerate // verilator lint_on UNUSED - + // }}} +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal properties +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// `ifdef FORMAL // Formal properties for this module are maintained elsewhere `endif +// }}} endmodule diff --git a/rtl/cpu/mpyop.v b/rtl/cpu/mpyop.v index 429fb20..d46ffb7 100644 --- a/rtl/cpu/mpyop.v +++ b/rtl/cpu/mpyop.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: mpyop.v -// +// {{{ // Project: Zip CPU -- a small, lightweight, RISC CPU soft core // // Purpose: This code has been pulled from the cpuops.v file so as to @@ -14,9 +14,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -31,32 +31,43 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // // `default_nettype none -// -module mpyop(i_clk,i_reset, i_stb, i_op, i_a, i_b, o_valid, o_busy, o_result, o_hi); - // The following parameter selects which multiply algorithm we use. - // Timing performance is strictly dependent upon it. - parameter IMPLEMENT_MPY = 1; - input wire i_clk, i_reset, i_stb; - input wire [1:0] i_op; // 2'b00=MPY, 2'b10=MPYUHI, 2'b11=MPYSHI - input wire [31:0] i_a, i_b; - output wire o_valid; // True if we'll be valid on the next clock; - output wire o_busy; // The multiply is busy if true - output wire [63:0] o_result; // Where we dump the multiply result - output reg o_hi; // Return the high half of the multiply +// }}} +module mpyop #( + // {{{ + // The following parameter selects which multiply algorithm we + // use. Timing performance is strictly dependent upon it. + parameter IMPLEMENT_MPY = 1 + // }}} + ) ( + // {{{ + input wire i_clk, i_reset, i_stb, + // + // Three types of multiply operations. + // 2'b00: 32x32 multiply, returning the low order 32 bits + // 2'b10: 32x32 unsigned multiply, returning upper 32 bits + // 2'b11: 32x32 signed multiply, returning upper 32 bits + input wire [1:0] i_op, + input wire [31:0] i_a, i_b, + output wire o_valid, // True if the result is valid + output wire o_busy, // + output wire [63:0] o_result, // multiply result + output wire o_hi // Return the high half of mpy + // }}} + ); // A 4-way multiplexer can be done in one 6-LUT. // A 16-way multiplexer can therefore be done in 4x 6-LUT's with - // the Xilinx multiplexer fabric that follows. + // the Xilinx multiplexer fabric that follows. // Given that we wish to apply this multiplexer approach to 33-bits, // this will cost a minimum of 132 6-LUTs. @@ -67,22 +78,23 @@ module mpyop(i_clk,i_reset, i_stb, i_op, i_a, i_b, o_valid, o_busy, o_result, o_ generate if (IMPLEMENT_MPY == 0) begin : MPYNONE // No multiply support. - + // {{{ assign o_result = 64'h00; assign o_busy = 1'b0; assign o_valid = i_stb; - always @(*) o_hi = 1'b0; // Not needed + assign o_hi = 1'b0; // Not needed `ifdef VERILATOR // verilator lint_off UNUSED - wire [32+32+5-1:0] mpy_unused; - assign mpy_unused = { i_clk, i_reset, i_stb, i_op, i_a, i_b }; + wire mpy_unused; + assign mpy_unused = &{ 1'b0, i_clk, i_reset, i_stb, i_op, i_a, i_b }; // verilator lint_on UNUSED `endif + // }}} end else begin : IMPY if (IMPLEMENT_MPY == 1) begin : MPY1CK // Our single clock option (no extra clocks) - + // {{{ wire signed [63:0] w_mpy_a_input, w_mpy_b_input; assign w_mpy_a_input = {{(32){(i_a[31])&(i_op[0])}},i_a[31:0]}; @@ -91,69 +103,97 @@ module mpyop(i_clk,i_reset, i_stb, i_op, i_a, i_b, o_valid, o_busy, o_result, o_ assign o_result = w_mpy_a_input * w_mpy_b_input; assign o_busy = 1'b0; - assign o_valid = 1'b0; - always @(*) o_hi = i_op[1]; + assign o_valid = i_stb; + assign o_hi = i_op[1]; `ifdef VERILATOR // verilator lint_off UNUSED - wire [3:0] mpy_unused; - assign mpy_unused = { i_clk, i_reset, i_stb, i_op[1] }; + wire mpy_unused; + assign mpy_unused = &{ 1'b0, i_clk, i_reset, i_stb, i_op[1] }; // verilator lint_on UNUSED `endif - + // }}} end else begin: MPN1 if (IMPLEMENT_MPY == 2) begin : MPY2CK // Our two clock option (ALU must pause for 1 clock) - + // {{{ reg signed [63:0] r_mpy_a_input, r_mpy_b_input; + reg mpypipe; + + // r_mpy_?_input: Register the inputs + // {{{ always @(posedge i_clk) begin r_mpy_a_input <={{(32){(i_a[31])&(i_op[0])}},i_a[31:0]}; r_mpy_b_input <={{(32){(i_b[31])&(i_op[0])}},i_b[31:0]}; end + // }}} assign o_result = r_mpy_a_input * r_mpy_b_input; assign o_busy = 1'b0; - reg mpypipe; + // mpypipe + // {{{ initial mpypipe = 1'b0; always @(posedge i_clk) - if (i_reset) - mpypipe <= 1'b0; - else - mpypipe <= (i_stb); + if (i_reset) + mpypipe <= 1'b0; + else + mpypipe <= (i_stb); + // }}} assign o_valid = mpypipe; // this_is_a_multiply_op; + + // o_hi + // {{{ + reg r_hi; + always @(posedge i_clk) if (i_stb) - o_hi <= i_op[1]; + r_hi <= i_op[1]; + assign o_hi = r_hi; + // }}} + // }}} end else begin : MPN2 if (IMPLEMENT_MPY == 3) begin : MPY3CK // Our three clock option (ALU pauses for 2 clocks) + // {{{ + + // Declarations + // {{{ reg signed [63:0] r_smpy_result; reg [63:0] r_umpy_result; reg signed [31:0] r_mpy_a_input, r_mpy_b_input; reg [1:0] mpypipe; reg [1:0] r_sgn; + // }}} + // mpypipe (FSM state) + // {{{ initial mpypipe = 2'b0; always @(posedge i_clk) - if (i_reset) - mpypipe <= 2'b0; - else + if (i_reset) + mpypipe <= 2'b0; + else mpypipe <= { mpypipe[0], i_stb }; + // }}} - // First clock + // First clock : register r_mpy_?_input, r_sgn + // {{{ always @(posedge i_clk) begin r_mpy_a_input <= i_a[31:0]; r_mpy_b_input <= i_b[31:0]; r_sgn <= { r_sgn[0], i_op[0] }; end + // }}} - // Second clock + // Second clock : perform the multiply + // {{{ `ifdef VERILATOR + // Veri1ator only implementation + // {{{ wire signed [63:0] s_mpy_a_input, s_mpy_b_input; wire [63:0] u_mpy_a_input, u_mpy_b_input; @@ -165,8 +205,10 @@ module mpyop(i_clk,i_reset, i_stb, i_op, i_a, i_b, o_valid, o_busy, o_result, o_ r_smpy_result <= s_mpy_a_input * s_mpy_b_input; always @(posedge i_clk) r_umpy_result <= u_mpy_a_input * u_mpy_b_input; + // }}} `else - + // Synthesis implementation + // {{{ wire [31:0] u_mpy_a_input, u_mpy_b_input; assign u_mpy_a_input = r_mpy_a_input; @@ -176,31 +218,45 @@ module mpyop(i_clk,i_reset, i_stb, i_op, i_a, i_b, o_valid, o_busy, o_result, o_ r_smpy_result <= r_mpy_a_input * r_mpy_b_input; always @(posedge i_clk) r_umpy_result <= u_mpy_a_input * u_mpy_b_input; + // }}} `endif + reg r_hi; always @(posedge i_clk) if (i_stb) - o_hi <= i_op[1]; + r_hi <= i_op[1]; + + assign o_hi = r_hi; assign o_busy = mpypipe[0]; assign o_result = (r_sgn[1])?r_smpy_result:r_umpy_result; assign o_valid = mpypipe[1]; + // }}} - // Results are then set on the third clock + // Results are then available and registered on the third clock + // }}} end else begin : MPN3 if (IMPLEMENT_MPY == 4) - begin : MPY4CK // The three clock option + begin : MPY4CK // The four clock option, polynomial multiplication + // {{{ + // Declarations + // {{{ reg [63:0] r_mpy_result; reg [31:0] r_mpy_a_input, r_mpy_b_input; - reg r_mpy_signed; + reg r_mpy_signed, r_hi; reg [2:0] mpypipe; + reg [31:0] pp_f, pp_l; // F and L from FOIL + reg [32:0] pp_oi; // The O and I from FOIL + reg [32:0] pp_s; + // }}} - // First clock, latch in the inputs + // First clock, latch in the inputs : mpypipe, r_mpy_?_input + // {{{ initial mpypipe = 3'b0; always @(posedge i_clk) begin // mpypipe indicates we have a multiply in the // pipeline. In this case, the multiply - // pipeline is a two stage pipeline, so we need + // pipeline is a two stage pipeline, so we need // two bits in the pipe. if (i_reset) mpypipe <= 3'h0; @@ -225,15 +281,17 @@ module mpyop(i_clk,i_reset, i_stb, i_op, i_a, i_b, o_valid, o_busy, o_result, o_ r_mpy_signed <= i_op[0]; if (i_stb) - o_hi <= i_op[1]; + r_hi <= i_op[1]; end + // }}} + assign o_hi = r_hi; assign o_busy = |mpypipe[1:0]; assign o_valid = mpypipe[2]; - // Second clock, do the multiplies, get the "partial - // products". Here, we break our input up into two - // halves, + // Second clock, do the multiplies, get the "partial products". + // {{{ + // Here, we break our input up into two halves, // // A = (2^16 ah + al) // B = (2^16 bh + bl) @@ -264,9 +322,6 @@ module mpyop(i_clk,i_reset, i_stb, i_op, i_a, i_b, o_valid, o_busy, o_result, o_ // +(al*bl) // - 2^31 (2^16 bh+bl + 2^16 ah+al + 2^31) // - reg [31:0] pp_f, pp_l; // F and L from FOIL - reg [32:0] pp_oi; // The O and I from FOIL - reg [32:0] pp_s; always @(posedge i_clk) begin pp_f<=r_mpy_a_input[31:16]*r_mpy_b_input[31:16]; @@ -281,8 +336,10 @@ module mpyop(i_clk,i_reset, i_stb, i_op, i_a, i_b, o_valid, o_busy, o_result, o_ else pp_s <= 33'h0; end + // }}} - // Third clock, add the results and produce a product + // Third clock, add the results and get a product: r_mpy_result + // {{{ always @(posedge i_clk) begin r_mpy_result[15:0] <= pp_l[15:0]; @@ -292,11 +349,17 @@ module mpyop(i_clk,i_reset, i_stb, i_op, i_a, i_b, o_valid, o_busy, o_result, o_ + { pp_s, 15'h00 } + { pp_f, 16'h00 }; end + // }}} assign o_result = r_mpy_result; // Fourth clock -- results are clocked into writeback + // }}} end else begin : MPYSLOW - + // {{{ + // Use an external multiply implementation, for when DSPs aren't + // available. + // + reg r_hi; // verilator lint_off UNUSED wire unused_aux; wire [65:0] full_result; @@ -311,8 +374,10 @@ module mpyop(i_clk,i_reset, i_stb, i_op, i_a, i_b, o_valid, o_busy, o_result, o_ always @(posedge i_clk) if (i_stb) - o_hi <= i_op[1]; + r_hi <= i_op[1]; + assign o_hi = r_hi; + // }}} end end end end end endgenerate // All possible multiply results have been determined diff --git a/rtl/cpu/pfcache.v b/rtl/cpu/pfcache.v index fcafb25..3c5ee51 100644 --- a/rtl/cpu/pfcache.v +++ b/rtl/cpu/pfcache.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: pfcache.v -// +// {{{ // Project: Zip CPU -- a small, lightweight, RISC CPU soft core // // Purpose: Keeping our CPU fed with instructions, at one per clock and @@ -34,9 +34,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -51,54 +51,69 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // // `default_nettype none -// -module pfcache(i_clk, i_reset, i_new_pc, i_clear_cache, - // i_early_branch, i_from_addr, - i_stall_n, i_pc, o_insn, o_pc, o_valid, - o_wb_cyc, o_wb_stb, o_wb_we, o_wb_addr, o_wb_data, - i_wb_stall, i_wb_ack, i_wb_err, i_wb_data, - o_illegal - ); - parameter LGCACHELEN = 12, ADDRESS_WIDTH=30, - LGLINES=8; // Log of the number of separate cache lines - localparam CACHELEN=(1< for a copy. -// -// License: GPL, v3, as defined and found on www.gnu.org, -// http://www.gnu.org/licenses/gpl.html -// -// -//////////////////////////////////////////////////////////////////////////////// -// -// -`default_nettype none -// -module pipefetch(i_clk, i_rst, i_new_pc, i_clear_cache, i_stall_n, i_pc, - o_i, o_pc, o_v, - o_wb_cyc, o_wb_stb, o_wb_we, o_wb_addr, o_wb_data, - i_wb_stall, i_wb_ack, i_wb_err, i_wb_data, i_wb_request, - o_illegal); - parameter RESET_ADDRESS=32'h0010_0000, - LGCACHELEN = 6, ADDRESS_WIDTH=24, - CACHELEN=(1<= r_cache_base + CACHELEN) - ||(i_pc >= r_cache_base + bus_nvalid+5))); - wire w_ran_off_end_of_cache; - assign w_ran_off_end_of_cache =((r_addr_set)&&((r_addr < r_cache_base) - ||(r_addr >= r_cache_base + CACHELEN) - ||(r_addr >= r_cache_base + bus_nvalid+5))); - wire w_running_out_of_cache; - assign w_running_out_of_cache = (r_addr_set) - &&(r_addr >= r_cache_base + - // {{(AW-LGCACHELEN-1),{1'b0}},2'b11, - // {(LGCACHELEN-1){1'b0}}}) - // (1<<(LGCACHELEN-2)) + (1<<(LGCACHELEN-1))) - +(3<<(LGCACHELEN-2))) - &&(|r_nvalid[(LGCACHELEN):(LGCACHELEN-1)]); - - initial r_cache_base = RESET_ADDRESS[(AW+1):2]; - always @(posedge i_clk) - begin - if ((i_rst)||(i_clear_cache)||((o_wb_cyc)&&(i_wb_err))) - begin - o_wb_cyc <= 1'b0; - o_wb_stb <= 1'b0; - // r_cache_base <= RESET_ADDRESS; - // end else if ((~o_wb_cyc)&&(i_new_pc)&&(r_nvalid != 0) - // &&(i_pc >= r_cache_base) - // &&(i_pc < r_cache_base + bus_nvalid)) - // begin - // The new instruction is in our cache, do nothing - // with the bus here. - end else if ((o_wb_cyc)&&(w_pc_out_of_bounds)) - begin - // We need to abandon our bus action to start over in - // a new region, setting up a new cache. This may - // happen mid cycle while waiting for a result. By - // dropping o_wb_cyc, we state that we are no longer - // interested in that result--whatever it might be. - o_wb_cyc <= 1'b0; - o_wb_stb <= 1'b0; - end else if ((~o_wb_cyc)&&(~r_nvalid[LGCACHELEN])&&(~i_wb_request)&&(r_addr_set)) - begin - // Restart a bus cycle that was interrupted when the - // data section wanted access to our bus. - o_wb_cyc <= 1'b1; - o_wb_stb <= 1'b1; - // o_wb_addr <= r_cache_base + bus_nvalid; - end else if ((~o_wb_cyc)&&( - (w_pc_out_of_bounds)||(w_ran_off_end_of_cache))) - begin - // Start a bus transaction - o_wb_cyc <= 1'b1; - o_wb_stb <= 1'b1; - // o_wb_addr <= (i_new_pc) ? i_pc : r_addr; - // r_nvalid <= 0; - // r_cache_base <= (i_new_pc) ? i_pc : r_addr; - // w_cache_offset <= 0; - end else if ((~o_wb_cyc)&&(w_running_out_of_cache)) - begin - // If we're using the last quarter of the cache, then - // let's start a bus transaction to extend the cache. - o_wb_cyc <= 1'b1; - o_wb_stb <= 1'b1; - // o_wb_addr <= r_cache_base + (1<<(LGCACHELEN)); - // r_nvalid <= r_nvalid - (1<<(LGCACHELEN-2)); - // r_cache_base <= r_cache_base + (1<<(LGCACHELEN-2)); - // w_cache_offset <= w_cache_offset + (1<<(LGCACHELEN-2)); - end else if (o_wb_cyc) - begin - // This handles everything ... but the case where - // while reading we need to extend our cache. - if ((o_wb_stb)&&(~i_wb_stall)) - begin - // o_wb_addr <= o_wb_addr + 1; - if ((o_wb_addr - r_cache_base >= CACHELEN-1) - ||(i_wb_request)) - o_wb_stb <= 1'b0; - end - - if (i_wb_ack) - begin - // r_nvalid <= r_nvalid + 1; - if ((r_acks_waiting == 1)&&(~o_wb_stb)) - o_wb_cyc <= 1'b0; - end else if ((r_acks_waiting == 0)&&(~o_wb_stb)) - o_wb_cyc <= 1'b0; - end - end - - - initial r_nvalid = 0; - always @(posedge i_clk) - if ((i_rst)||(i_clear_cache)) // Required, so we can reload memoy and then reset - r_nvalid <= 0; - else if ((~o_wb_cyc)&&( - (w_pc_out_of_bounds)||(w_ran_off_end_of_cache))) - r_nvalid <= 0; - else if ((~o_wb_cyc)&&(w_running_out_of_cache)) - r_nvalid[LGCACHELEN:(LGCACHELEN-2)] - <= r_nvalid[LGCACHELEN:(LGCACHELEN-2)] +3'b111; - // i.e. - (1<<(LGCACHELEN-2)); - else if ((o_wb_cyc)&&(i_wb_ack)) - r_nvalid <= r_nvalid + {{(LGCACHELEN){1'b0}},1'b1}; // +1; - - always @(posedge i_clk) - if (i_clear_cache) - r_cache_base <= i_pc; - else if ((~o_wb_cyc)&&( - (w_pc_out_of_bounds) - ||(w_ran_off_end_of_cache))) - r_cache_base <= (i_new_pc) ? i_pc : r_addr; - else if ((~o_wb_cyc)&&(w_running_out_of_cache)) - r_cache_base[(AW-1):(LGCACHELEN-2)] - <= r_cache_base[(AW-1):(LGCACHELEN-2)] - + {{(AW-LGCACHELEN+1){1'b0}},1'b1}; - // i.e. + (1<<(LGCACHELEN-2)); - - always @(posedge i_clk) - if (i_clear_cache) - r_cache_offset <= 0; - else if ((~o_wb_cyc)&&( - (w_pc_out_of_bounds) - ||(w_ran_off_end_of_cache))) - r_cache_offset <= 0; - else if ((~o_wb_cyc)&&(w_running_out_of_cache)) - r_cache_offset[1:0] <= r_cache_offset[1:0] + 2'b01; - assign w_cache_offset = { r_cache_offset, {(LGCACHELEN-2){1'b0}} }; - - always @(posedge i_clk) - if (i_clear_cache) - o_wb_addr <= i_pc; - else if ((o_wb_cyc)&&(w_pc_out_of_bounds)) - begin - if (i_wb_ack) - o_wb_addr <= r_cache_base + bus_nvalid+1; - else - o_wb_addr <= r_cache_base + bus_nvalid; - end else if ((~o_wb_cyc)&&((w_pc_out_of_bounds) - ||(w_ran_off_end_of_cache))) - o_wb_addr <= (i_new_pc) ? i_pc : r_addr; - else if ((o_wb_stb)&&(~i_wb_stall)) // && o_wb_cyc - o_wb_addr <= o_wb_addr + 1; - - initial r_acks_waiting = 0; - always @(posedge i_clk) - if (~o_wb_cyc) - r_acks_waiting <= 0; - // o_wb_cyc *must* be true for all following - else if ((o_wb_stb)&&(~i_wb_stall)&&(~i_wb_ack)) //&&(o_wb_cyc) - r_acks_waiting <= r_acks_waiting + {{(LGCACHELEN){1'b0}},1'b1}; - else if ((i_wb_ack)&&((~o_wb_stb)||(i_wb_stall))) //&&(o_wb_cyc) - r_acks_waiting <= r_acks_waiting + {(LGCACHELEN+1){1'b1}}; // - 1; - - always @(posedge i_clk) - if ((o_wb_cyc)&&(i_wb_ack)) - cache[r_nvalid[(LGCACHELEN-1):0]+w_cache_offset] - <= i_wb_data; - - initial r_addr_set = 1'b0; - always @(posedge i_clk) - if ((i_rst)||(i_new_pc)) - r_addr_set <= 1'b1; - else if (i_clear_cache) - r_addr_set <= 1'b0; - - // Now, read from the cache - wire w_cv; // Cache valid, address is in the cache - reg r_cv; - assign w_cv = ((r_nvalid != 0)&&(r_addr>=r_cache_base) - &&(r_addr-r_cache_base < bus_nvalid)); - always @(posedge i_clk) - r_cv <= (~i_new_pc)&&((w_cv)||((~i_stall_n)&&(r_cv))); - assign o_v = (r_cv)&&(~i_new_pc); - - always @(posedge i_clk) - if (i_new_pc) - r_addr <= i_pc; - else if ( ((i_stall_n)&&(w_cv)) || ((~i_stall_n)&&(w_cv)&&(r_addr == o_pc)) ) - r_addr <= r_addr + {{(AW-1){1'b0}},1'b1}; - - wire [(LGCACHELEN-1):0] c_rdaddr, c_cache_base; - assign c_cache_base = r_cache_base[(LGCACHELEN-1):0]; - assign c_rdaddr = r_addr[(LGCACHELEN-1):0]-c_cache_base+w_cache_offset; - always @(posedge i_clk) - if ((~o_v)||((i_stall_n)&&(o_v))) - o_i <= cache[c_rdaddr]; - always @(posedge i_clk) - if ((~o_v)||((i_stall_n)&&(o_v))) - o_pc <= r_addr; - - reg [(AW-1):0] ill_address; - initial ill_address = 0; - always @(posedge i_clk) - if ((o_wb_cyc)&&(i_wb_err)) - ill_address <= o_wb_addr - {{(AW-LGCACHELEN-1){1'b0}}, r_acks_waiting}; - - assign o_illegal = (o_pc == ill_address)&&(~i_rst)&&(~i_new_pc)&&(~i_clear_cache); - -endmodule diff --git a/rtl/cpu/pipemem.v b/rtl/cpu/pipemem.v index e72c756..df05589 100644 --- a/rtl/cpu/pipemem.v +++ b/rtl/cpu/pipemem.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: pipemem.v -// +// {{{ // Project: Zip CPU -- a small, lightweight, RISC CPU soft core // // Purpose: A memory unit to support a CPU, this time one supporting @@ -16,9 +16,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -33,58 +33,69 @@ // with this program. (It's in the $(ROOT)/doc directory, run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // // `default_nettype none -// -module pipemem(i_clk, i_reset, i_pipe_stb, i_lock, - i_op, i_addr, i_data, i_oreg, - o_busy, o_pipe_stalled, o_valid, o_err, o_wreg, o_result, - o_wb_cyc_gbl, o_wb_cyc_lcl, - o_wb_stb_gbl, o_wb_stb_lcl, - o_wb_we, o_wb_addr, o_wb_data, o_wb_sel, - i_wb_stall, i_wb_ack, i_wb_err, i_wb_data - ); - parameter ADDRESS_WIDTH=30; - parameter [0:0] IMPLEMENT_LOCK=1'b1, - WITH_LOCAL_BUS=1'b1, - OPT_ZERO_ON_IDLE=1'b0, - // OPT_ALIGNMENT_ERR - OPT_ALIGNMENT_ERR=1'b0; - localparam AW=ADDRESS_WIDTH, - FLN=4; - parameter [(FLN-1):0] OPT_MAXDEPTH=4'hd; - input wire i_clk, i_reset; - input wire i_pipe_stb, i_lock; - // CPU interface - input wire [2:0] i_op; - input wire [31:0] i_addr; - input wire [31:0] i_data; - input wire [4:0] i_oreg; - // CPU outputs - output wire o_busy; - output wire o_pipe_stalled; - output reg o_valid; - output reg o_err; - output reg [4:0] o_wreg; - output reg [31:0] o_result; - // Wishbone outputs - output wire o_wb_cyc_gbl; - output reg o_wb_stb_gbl; - output wire o_wb_cyc_lcl; - output reg o_wb_stb_lcl, o_wb_we; - output reg [(AW-1):0] o_wb_addr; - output reg [31:0] o_wb_data; - output reg [3:0] o_wb_sel; - // Wishbone inputs - input wire i_wb_stall, i_wb_ack, i_wb_err; - input wire [31:0] i_wb_data; +// }}} +module pipemem #( + // {{{ + parameter ADDRESS_WIDTH=30, + parameter [0:0] IMPLEMENT_LOCK=1'b1, + WITH_LOCAL_BUS=1'b1, + OPT_ZERO_ON_IDLE=1'b0, + // OPT_ALIGNMENT_ERR + OPT_ALIGNMENT_ERR=1'b0, + localparam AW=ADDRESS_WIDTH, + FLN=4, + parameter [(FLN-1):0] OPT_MAXDEPTH=4'hd + // }}} + ) ( + // {{{ + input wire i_clk, i_reset, + // CPU interface + // {{{ + input wire i_pipe_stb, i_lock, + input wire [2:0] i_op, + input wire [31:0] i_addr, + input wire [31:0] i_data, + input wire [4:0] i_oreg, + // CPU outputs + output wire o_busy, o_rdbusy, + output wire o_pipe_stalled, + output reg o_valid, + output reg o_err, + output reg [4:0] o_wreg, + output reg [31:0] o_result, + // }}} + // Wishbone outputs + // {{{ + output wire o_wb_cyc_gbl, + output wire o_wb_cyc_lcl, + output reg o_wb_stb_gbl, + output reg o_wb_stb_lcl, o_wb_we, + output reg [(AW-1):0] o_wb_addr, + output reg [31:0] o_wb_data, + output reg [3:0] o_wb_sel, + // Wishbone inputs + input wire i_wb_stall, i_wb_ack, i_wb_err, + input wire [31:0] i_wb_data + // }}} + // }}} + ); + + // Declarations + // {{{ + localparam F_LGDEPTH=FLN+1; +`ifdef FORMAL + wire [(F_LGDEPTH-1):0] f_nreqs, f_nacks, f_outstanding; + reg f_pc; +`endif reg cyc; @@ -93,11 +104,13 @@ module pipemem(i_clk, i_reset, i_pipe_stb, i_lock, wire [(FLN-1):0] nxt_rdaddr, fifo_fill; reg [(3+5-1):0] fifo_oreg [0:15]; reg fifo_gie; - initial rdaddr = 0; - initial wraddr = 0; - - reg misaligned; + wire gbl_stb, lcl_stb, lcl_bus; + wire [7:0] w_wreg; + reg misaligned; + // }}} + // misaligned + // {{{ always @(*) if (OPT_ALIGNMENT_ERR) begin @@ -109,14 +122,23 @@ module pipemem(i_clk, i_reset, i_pipe_stb, i_lock, endcase end else misaligned = 1'b0; + // }}} + // fifo_oreg + // {{{ always @(posedge i_clk) fifo_oreg[wraddr] <= { i_oreg[3:0], i_op[2:1], i_addr[1:0] }; + // }}} + // fifo_gie + // {{{ always @(posedge i_clk) if (i_pipe_stb) fifo_gie <= i_oreg[4]; + // }}} + // wraddr + // {{{ initial wraddr = 0; always @(posedge i_clk) if (i_reset) @@ -125,7 +147,10 @@ module pipemem(i_clk, i_reset, i_pipe_stb, i_lock, wraddr <= 0; else if (i_pipe_stb) wraddr <= wraddr + 1'b1; + // }}} + // rdaddr + // {{{ initial rdaddr = 0; always @(posedge i_clk) if (i_reset) @@ -134,9 +159,12 @@ module pipemem(i_clk, i_reset, i_pipe_stb, i_lock, rdaddr <= 0; else if ((i_wb_ack)&&(cyc)) rdaddr <= rdaddr + 1'b1; + // }}} assign fifo_fill = wraddr - rdaddr; + // fifo_full + // {{{ initial fifo_full = 0; always @(posedge i_clk) if (i_reset) @@ -147,40 +175,56 @@ module pipemem(i_clk, i_reset, i_pipe_stb, i_lock, fifo_full <= (fifo_fill >= OPT_MAXDEPTH-1); else fifo_full <= (fifo_fill >= OPT_MAXDEPTH); + // }}} assign nxt_rdaddr = rdaddr + 1'b1; - wire gbl_stb, lcl_stb, lcl_bus; + // lcl_bus, lcl_stb, gbl_stb + // {{{ assign lcl_bus = (i_addr[31:24]==8'hff)&&(WITH_LOCAL_BUS); assign lcl_stb = (lcl_bus)&&(!misaligned); assign gbl_stb = ((!lcl_bus)||(!WITH_LOCAL_BUS))&&(!misaligned); //= ((i_addr[31:8]!=24'hc00000)||(i_addr[7:5]!=3'h0)); + // }}} + // cyc, [or]_wb_[cyc|stb]_[lcl|gbl] + // {{{ initial cyc = 0; initial r_wb_cyc_lcl = 0; initial r_wb_cyc_gbl = 0; initial o_wb_stb_lcl = 0; initial o_wb_stb_gbl = 0; always @(posedge i_clk) - if (i_reset) - begin - r_wb_cyc_gbl <= 1'b0; - r_wb_cyc_lcl <= 1'b0; - o_wb_stb_gbl <= 1'b0; - o_wb_stb_lcl <= 1'b0; - cyc <= 1'b0; - end else if (cyc) begin - if (((!i_wb_stall)&&(!i_pipe_stb)&&(!misaligned)) - ||(i_wb_err)) + if (cyc) begin - o_wb_stb_gbl <= 1'b0; - o_wb_stb_lcl <= 1'b0; + if (((!i_wb_stall)&&(!i_pipe_stb)&&(!misaligned)) + ||(i_wb_err)) + begin + o_wb_stb_gbl <= 1'b0; + o_wb_stb_lcl <= 1'b0; + end + + if (((i_wb_ack)&&(nxt_rdaddr == wraddr) + &&((!i_pipe_stb)||(misaligned))) + ||(i_wb_err)) + begin + r_wb_cyc_gbl <= 1'b0; + r_wb_cyc_lcl <= 1'b0; + o_wb_stb_gbl <= 1'b0; + o_wb_stb_lcl <= 1'b0; + cyc <= 1'b0; + end + end else if (i_pipe_stb) // New memory operation + begin // Grab the wishbone + r_wb_cyc_lcl <= lcl_stb; + r_wb_cyc_gbl <= gbl_stb; + o_wb_stb_lcl <= lcl_stb; + o_wb_stb_gbl <= gbl_stb; + cyc <= (!misaligned); end - if (((i_wb_ack)&&(nxt_rdaddr == wraddr) - &&((!i_pipe_stb)||(misaligned))) - ||(i_wb_err)) + if (i_reset) begin r_wb_cyc_gbl <= 1'b0; r_wb_cyc_lcl <= 1'b0; @@ -188,23 +232,30 @@ module pipemem(i_clk, i_reset, i_pipe_stb, i_lock, o_wb_stb_lcl <= 1'b0; cyc <= 1'b0; end - end else if (i_pipe_stb) // New memory operation - begin // Grab the wishbone - r_wb_cyc_lcl <= lcl_stb; - r_wb_cyc_gbl <= gbl_stb; - o_wb_stb_lcl <= lcl_stb; - o_wb_stb_gbl <= gbl_stb; - cyc <= (!misaligned); + + if (!WITH_LOCAL_BUS) + begin + r_wb_cyc_lcl <= 1'b0; + o_wb_stb_lcl <= 1'b0; + end end + // }}} + // o_wb_addr, o_wb_sel, and o_wb_data + // {{{ always @(posedge i_clk) if ((!cyc)||(!i_wb_stall)) begin + // o_wb_add + // {{{ if ((OPT_ZERO_ON_IDLE)&&(!i_pipe_stb)) o_wb_addr <= 0; else o_wb_addr <= i_addr[(AW+1):2]; + // }}} + // o_wb_sel + // {{{ if ((OPT_ZERO_ON_IDLE)&&(!i_pipe_stb)) o_wb_sel <= 4'b0000; else casez({ i_op[2:1], i_addr[1:0] }) @@ -216,7 +267,10 @@ module pipemem(i_clk, i_reset, i_pipe_stb, i_lock, 4'b1111: o_wb_sel <= 4'b0001; // Op = 7 default: o_wb_sel <= 4'b1111; // Op = 7 endcase + // }}} + // o_wb_data + // {{{ if ((OPT_ZERO_ON_IDLE)&&(!i_pipe_stb)) o_wb_data <= 0; else casez({ i_op[2:1], i_addr[1:0] }) @@ -227,34 +281,53 @@ module pipemem(i_clk, i_reset, i_pipe_stb, i_lock, 4'b1110: o_wb_data <= { 16'h00, i_data[7:0], 8'h00 }; 4'b1111: o_wb_data <= { 24'h00, i_data[7:0] }; default: o_wb_data <= i_data; - endcase + endcase + // }}} end + // }}} + // o_wb_we + // {{{ always @(posedge i_clk) if ((i_pipe_stb)&&(!cyc)) o_wb_we <= i_op[0]; else if ((OPT_ZERO_ON_IDLE)&&(!cyc)) o_wb_we <= 1'b0; + // }}} + // o_valid + // {{{ initial o_valid = 1'b0; always @(posedge i_clk) if (i_reset) o_valid <= 1'b0; else o_valid <= (cyc)&&(i_wb_ack)&&(!o_wb_we); + // }}} + // o_err + // {{{ initial o_err = 1'b0; always @(posedge i_clk) if (i_reset) o_err <= 1'b0; else o_err <= ((cyc)&&(i_wb_err))||((i_pipe_stb)&&(misaligned)); + // }}} + assign o_busy = cyc; + assign o_rdbusy = o_busy && !o_wb_we; - wire [7:0] w_wreg; assign w_wreg = fifo_oreg[rdaddr]; + + // o_wreg + // {{{ always @(posedge i_clk) o_wreg <= { fifo_gie, w_wreg[7:4] }; + // }}} + + // o_result + // {{{ always @(posedge i_clk) if ((OPT_ZERO_ON_IDLE)&&((!cyc)||((!i_wb_ack)&&(!i_wb_err)))) o_result <= 0; @@ -269,42 +342,75 @@ module pipemem(i_clk, i_reset, i_pipe_stb, i_lock, default: o_result <= i_wb_data[31:0]; endcase end + // }}} + // o_pipe_stalled + // {{{ assign o_pipe_stalled = ((cyc)&&(fifo_full))||((cyc) &&((i_wb_stall)||((!o_wb_stb_lcl)&&(!o_wb_stb_gbl)))); + // }}} + // lock_gbl, lock_lcl + // {{{ generate if (IMPLEMENT_LOCK != 0) - begin + begin : LOCK_REGISTER + // {{{ reg lock_gbl, lock_lcl; initial lock_gbl = 1'b0; initial lock_lcl = 1'b0; always @(posedge i_clk) - if ((i_reset)||((i_wb_err)&&(cyc)) - ||((i_pipe_stb)&&(misaligned))) begin - lock_gbl <= 1'b0; - lock_lcl <= 1'b0; - end else begin - lock_gbl <= (i_lock)&&((r_wb_cyc_gbl)||(lock_gbl)); - lock_lcl <= (i_lock)&&((r_wb_cyc_lcl)||(lock_lcl)); + lock_gbl <= r_wb_cyc_gbl || lock_gbl; + lock_lcl <= r_wb_cyc_lcl || lock_lcl; + + if (i_reset || (i_wb_err && cyc) + || (i_pipe_stb && misaligned) + || !i_lock) + begin + lock_gbl <= 1'b0; + lock_lcl <= 1'b0; + end + + if (!WITH_LOCAL_BUS) + lock_lcl <= 1'b0; end assign o_wb_cyc_gbl = (r_wb_cyc_gbl)||(lock_gbl); assign o_wb_cyc_lcl = (r_wb_cyc_lcl)||(lock_lcl); - end else begin + // }}} + end else begin : NO_LOCK + // {{{ assign o_wb_cyc_gbl = (r_wb_cyc_gbl); assign o_wb_cyc_lcl = (r_wb_cyc_lcl); + + // verilator lint_off UNUSED + wire unused_lock; + assign unused_lock = &{ 1'b0, i_lock }; + // verilator lint_on UNUSED + // }}} end endgenerate + // }}} // Make verilator happy + // {{{ // verilator lint_off UNUSED wire unused; - assign unused = i_lock; + assign unused = { 1'b0 }; // verilator lint_on UNUSED - + // }}} +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal property section +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// `ifdef FORMAL // Formal properties for this module are maintained elsewhere `endif // FORMAL +// }}} endmodule diff --git a/rtl/cpu/prefetch.v b/rtl/cpu/prefetch.v index bef0263..4043f6d 100644 --- a/rtl/cpu/prefetch.v +++ b/rtl/cpu/prefetch.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: prefetch.v -// +// {{{ // Project: Zip CPU -- a small, lightweight, RISC CPU soft core // // Purpose: This is a very simple instruction fetch approach. It gets @@ -29,9 +29,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015,2017-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -46,44 +46,51 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // // `default_nettype none // -// -module prefetch(i_clk, i_reset, i_new_pc, i_clear_cache, i_stalled_n, i_pc, - o_insn, o_pc, o_valid, o_illegal, - o_wb_cyc, o_wb_stb, o_wb_we, o_wb_addr, o_wb_data, - i_wb_stall, i_wb_ack, i_wb_err, i_wb_data); - parameter ADDRESS_WIDTH=30, DATA_WIDTH=32; - localparam AW=ADDRESS_WIDTH, - DW=DATA_WIDTH; - input wire i_clk, i_reset; - // CPU interaction wires - input wire i_new_pc, i_clear_cache, i_stalled_n; - // We ignore i_pc unless i_new_pc is true as well - input wire [(AW+1):0] i_pc; - output reg [(DW-1):0] o_insn; // Instruction read from WB - output wire [(AW+1):0] o_pc; // Address of that instruction - output reg o_valid; // If the output is valid - output reg o_illegal; // Result is from a bus err - // Wishbone outputs - output reg o_wb_cyc, o_wb_stb; - output wire o_wb_we; - output reg [(AW-1):0] o_wb_addr; - output wire [(DW-1):0] o_wb_data; - // And return inputs - input wire i_wb_stall, i_wb_ack, i_wb_err; - input wire [(DW-1):0] i_wb_data; +// }}} +module prefetch #( + // {{{ + parameter ADDRESS_WIDTH=30, DATA_WIDTH=32, + localparam AW=ADDRESS_WIDTH, + DW=DATA_WIDTH, + parameter [0:0] OPT_ALIGNED = 1'b0 + // }}} + ) ( + // {{{ + input wire i_clk, i_reset, + // CPU interaction wires + input wire i_new_pc, i_clear_cache, + i_ready, + // We ignore i_pc unless i_new_pc is true as well + input wire [(AW+1):0] i_pc, + output reg o_valid, // If output is valid + output reg o_illegal, // bus err result + output reg [(DW-1):0] o_insn, // Insn read from WB + output reg [(AW+1):0] o_pc, // Addr of that insn + // Wishbone outputs + output reg o_wb_cyc, o_wb_stb, + output wire o_wb_we, + output reg [(AW-1):0] o_wb_addr, + output wire [(DW-1):0] o_wb_data, + // And return inputs + input wire i_wb_stall, i_wb_ack, i_wb_err, + input wire [(DW-1):0] i_wb_data + // }}} + ); // Declare local variables + // {{{ reg invalid; + // }}} // These are kind of obligatory outputs when dealing with a bus, that // we'll set them here. Nothing's going to pay attention to these, @@ -91,34 +98,41 @@ module prefetch(i_clk, i_reset, i_new_pc, i_clear_cache, i_stalled_n, i_pc, assign o_wb_we = 1'b0; assign o_wb_data = 32'h0000; + // o_wb_cyc, o_wb_stb + // {{{ // Let's build it simple and upgrade later: For each instruction // we do one bus cycle to get the instruction. Later we should // pipeline this, but for now let's just do one at a time. initial o_wb_cyc = 1'b0; initial o_wb_stb = 1'b0; always @(posedge i_clk) - if ((i_reset)||((o_wb_cyc)&&((i_wb_ack)||(i_wb_err)))) + if ((i_reset || i_clear_cache)||((o_wb_cyc)&&((i_wb_ack)||(i_wb_err)))) begin + // {{{ // End any bus cycle on a reset, or a return ACK // or error. o_wb_cyc <= 1'b0; o_wb_stb <= 1'b0; + // }}} end else if ((!o_wb_cyc)&&( // Start if the last instruction output was // accepted, *and* it wasn't a bus error // response - ((i_stalled_n)&&(!o_illegal)) + ((i_ready)&&(!o_illegal)) // Start if the last bus result ended up // invalid ||(invalid) // Start on any request for a new address ||(i_new_pc))) begin + // {{{ // Initiate a bus transaction o_wb_cyc <= 1'b1; o_wb_stb <= 1'b1; + // }}} end else if (o_wb_cyc) begin + // {{{ // If our request has been accepted, then drop the // strobe line if (!i_wb_stall) @@ -134,9 +148,12 @@ module prefetch(i_clk, i_reset, i_new_pc, i_clear_cache, i_stalled_n, i_pc, o_wb_cyc <= 1'b0; o_wb_stb <= 1'b0; end + // }}} end + // }}} - // + // invalid + // {{{ // If during the current bus request, a command came in from the CPU // that will invalidate the results of that request, then we need to // keep track of an "invalid" flag to remember that and so squash @@ -148,9 +165,10 @@ module prefetch(i_clk, i_reset, i_new_pc, i_clear_cache, i_stalled_n, i_pc, invalid <= 1'b0; else if (i_new_pc) invalid <= 1'b1; + // }}} // The wishbone request address, o_wb_addr - // + // {{{ // The rule regarding this address is that it can *only* be changed // when no bus request is active. Further, since the CPU is depending // upon this value to know what "PC" is associated with the instruction @@ -162,15 +180,20 @@ module prefetch(i_clk, i_reset, i_new_pc, i_clear_cache, i_stalled_n, i_pc, always @(posedge i_clk) if (i_new_pc) o_wb_addr <= i_pc[AW+1:2]; - else if ((o_valid)&&(i_stalled_n)&&(!o_illegal)) + else if ((o_valid)&&(i_ready)&&(!o_illegal)) o_wb_addr <= o_wb_addr + 1'b1; + // }}} + // o_insn + // {{{ // The instruction returned is given by the data returned from the bus. always @(posedge i_clk) if ((o_wb_cyc)&&(i_wb_ack)) o_insn <= i_wb_data; + // }}} - // + // o_valid, o_illegal + // {{{ // Finally, the flags associated with the prefetch. The rule is that // if the output represents a return from the bus, then o_valid needs // to be true. o_illegal will be true any time the last bus request @@ -199,7 +222,7 @@ module prefetch(i_clk, i_reset, i_new_pc, i_clear_cache, i_stalled_n, i_pc, // o_valid <= 1'b1; o_illegal <= ( i_wb_err); - end else if (i_stalled_n) + end else if (i_ready) begin // Once the CPU accepts any result we produce, clear // the valid flag, lest we send two identical @@ -212,18 +235,55 @@ module prefetch(i_clk, i_reset, i_new_pc, i_clear_cache, i_stalled_n, i_pc, // is given to us, via i_new_pc, or we are asked // to check again via i_clear_cache // - // o_illegal <= (!i_stalled_n); + // o_illegal <= (!i_ready); end + // }}} // The o_pc output shares its value with the (last) wishbone address - assign o_pc = { o_wb_addr, 2'b00 }; + // {{{ + generate if (OPT_ALIGNED) + begin : ALIGNED_PF_PC + // {{{ + always @(*) + o_pc = { o_wb_addr, 2'b00 }; + // }}} + end else begin : GENERATE_PF_PC + // {{{ + initial o_pc = 0; + always @(posedge i_clk) + if (i_new_pc) + o_pc <= i_pc; + else if (o_valid && !o_illegal && i_ready) + begin + o_pc <= o_pc + 4; + o_pc[1:0] <= 2'b00; + end + // }}} + end endgenerate +`ifdef FORMAL + always @(*) + assert(o_pc[AW+1:2] == o_wb_addr); +`endif + // }}} // Make verilator happy + // {{{ // verilator lint_off UNUSED wire [1:0] unused; assign unused = i_pc[1:0]; // verilator lint_on UNUSED + // }}} +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal properties +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// `ifdef FORMAL // Formal properties for this module are maintained elsewhere `endif +// }}} endmodule diff --git a/rtl/cpu/sfifo.v b/rtl/cpu/sfifo.v new file mode 100644 index 0000000..185a2c9 --- /dev/null +++ b/rtl/cpu/sfifo.v @@ -0,0 +1,449 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Filename: sfifo.v +// {{{ +// Project: Zip CPU -- a small, lightweight, RISC CPU soft core +// +// Purpose: A synchronous data FIFO. +// +// Creator: Dan Gisselquist, Ph.D. +// Gisselquist Technology, LLC +// +//////////////////////////////////////////////////////////////////////////////// +// +// Written and distributed by Gisselquist Technology, LLC +// }}} +// This program is hereby granted to the public domain. +// {{{ +// This program is free software (firmware): 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 MERCHANTIBILITY 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. (It's in the $(ROOT)/doc directory. Run make with no +// target there if the PDF file isn't present.) If not, see +// for a copy. +// }}} +// License: GPL, v3, as defined and found on www.gnu.org, +// {{{ +// http://www.gnu.org/licenses/gpl.html +// +//////////////////////////////////////////////////////////////////////////////// +// +// +`default_nettype none +// }}} +module sfifo #( + // {{{ + parameter BW=8, // Byte/data width + parameter LGFLEN=4, + parameter [0:0] OPT_ASYNC_READ = 1'b1, + parameter [0:0] OPT_WRITE_ON_FULL = 1'b0, + parameter [0:0] OPT_READ_ON_EMPTY = 1'b0, + localparam FLEN=(1<1) + assert(!r_empty); + else if ($past(!i_rd && f_fill > 0)) + assert(!r_empty); + end + + always @(*) + if (!r_empty) + // This also applies for the registered read case + assert(mem[rd_addr] == o_data); + else if (OPT_READ_ON_EMPTY) + assert(o_data == i_data); + + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Formal contract: (Twin write test) + // {{{ + // If you write two values in succession, you should be able to read + // those same two values in succession some time later. + // + //////////////////////////////////////////////////////////////////////// + // + // + (* anyconst *) reg [LGFLEN:0] f_first_addr; + reg [LGFLEN:0] f_second_addr; + reg [BW-1:0] f_first_data, f_second_data; + + reg f_first_addr_in_fifo, f_first_in_fifo; + reg f_second_addr_in_fifo, f_second_in_fifo; + reg [LGFLEN:0] f_distance_to_first, f_distance_to_second; + + always @(*) + f_second_addr = f_first_addr + 1; + + always @(*) + begin + f_distance_to_first = (f_first_addr - rd_addr); + f_first_addr_in_fifo = 0; + if ((f_fill != 0) && (f_distance_to_first < f_fill)) + f_first_addr_in_fifo = 1; + end + + always @(*) + begin + f_distance_to_second = (f_second_addr - rd_addr); + f_second_addr_in_fifo = 0; + if ((f_fill != 0) && (f_distance_to_second < f_fill)) + f_second_addr_in_fifo = 1; + end + + always @(posedge i_clk) + if (w_wr && wr_addr == f_first_addr) + f_first_data <= i_data; + + always @(posedge i_clk) + if (w_wr && wr_addr == f_second_addr) + f_second_data <= i_data; + + always @(*) + if (f_first_addr_in_fifo) + assert(mem[f_first_addr] == f_first_data); + always @(*) + f_first_in_fifo = (f_first_addr_in_fifo && (mem[f_first_addr] == f_first_data)); + + always @(*) + if (f_second_addr_in_fifo) + assert(mem[f_second_addr] == f_second_data); + + always @(*) + f_second_in_fifo = (f_second_addr_in_fifo && (mem[f_second_addr] == f_second_data)); + + always @(posedge i_clk) + if (f_past_valid && !$past(i_reset)) + begin + case({$past(f_first_in_fifo), $past(f_second_in_fifo)}) + 2'b00: begin + if ($past(w_wr && (!w_rd || !r_empty)) + &&($past(wr_addr == f_first_addr))) + assert(f_first_in_fifo); + else + assert(!f_first_in_fifo); + // + // The second could be in the FIFO, since + // one might write other data than f_first_data + // + // assert(!f_second_in_fifo); + end + 2'b01: begin + assert(!f_first_in_fifo); + if ($past(w_rd && (rd_addr==f_second_addr))) + assert((o_empty&&!OPT_ASYNC_READ)||!f_second_in_fifo); + else + assert(f_second_in_fifo); + end + 2'b10: begin + if ($past(w_wr) + &&($past(wr_addr == f_second_addr))) + assert(f_second_in_fifo); + else + assert(!f_second_in_fifo); + if ($past(!w_rd ||(rd_addr != f_first_addr))) + assert(f_first_in_fifo); + end + 2'b11: begin + assert(f_second_in_fifo); + if ($past(!w_rd ||(rd_addr != f_first_addr))) + begin + assert(f_first_in_fifo); + if (rd_addr == f_first_addr) + assert(o_data == f_first_data); + end else begin + assert(!f_first_in_fifo); + assert(o_data == f_second_data); + end + end + endcase + end + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Cover properties + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + reg f_was_full; + initial f_was_full = 0; + always @(posedge i_clk) + if (o_full) + f_was_full <= 1; + +`ifdef SFIFO + always @(posedge i_clk) + cover($fell(f_empty)); + + always @(posedge i_clk) + cover($fell(o_empty)); + + always @(posedge i_clk) + cover(f_was_full && f_empty); + + always @(posedge i_clk) + cover($past(o_full,2)&&(!$past(o_full))&&(o_full)); + + always @(posedge i_clk) + if (f_past_valid) + cover($past(o_empty,2)&&(!$past(o_empty))&& o_empty); +`endif + // }}} +`endif // FORMAL +// }}} +endmodule +`ifndef YOSYS +`default_nettype wire +`endif diff --git a/rtl/cpu/slowmpy.v b/rtl/cpu/slowmpy.v index cbeb585..c5473e5 100644 --- a/rtl/cpu/slowmpy.v +++ b/rtl/cpu/slowmpy.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: slowmpy.v -// +// {{{ // Project: Zip CPU -- a small, lightweight, RISC CPU soft core // // Purpose: This is a signed (OPT_SIGNED=1) or unsigned (OPT_SIGNED=0) @@ -15,9 +15,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2018-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2018-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -32,72 +32,91 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // // `default_nettype none -// -// -module slowmpy(i_clk, i_reset, i_stb, i_a, i_b, i_aux, o_busy, - o_done, o_p, o_aux); - parameter LGNA = 6; - parameter [LGNA:0] NA = 33; - parameter [0:0] OPT_SIGNED = 1'b1; - localparam NB = NA; // Must be = NA for OPT_SIGNED to work - // - input wire i_clk, i_reset; - // - input wire i_stb; - input wire signed [(NA-1):0] i_a; - input wire signed [(NB-1):0] i_b; - input wire i_aux; - output reg o_busy, o_done; - output reg signed [(NA+NB-1):0] o_p; - output reg o_aux; +// }}} +module slowmpy #( + // {{{ + parameter LGNA = 6, + parameter [LGNA:0] NA = 33, + parameter [0:0] OPT_SIGNED = 1'b1, + localparam NB = NA // Must be = NA for OPT_SIGNED to work + // }}} + ) ( + // {{{ + input wire i_clk, i_reset, + // + input wire i_stb, + input wire signed [(NA-1):0] i_a, + input wire signed [(NB-1):0] i_b, + input wire i_aux, + output reg o_busy, o_done, + output reg signed [(NA+NB-1):0] o_p, + output reg o_aux + // }}} + ); + // Declarations + // {{{ reg [LGNA-1:0] count; reg [NA-1:0] p_a; reg [NB-1:0] p_b; reg [NA+NB-1:0] partial; reg aux; + reg almost_done; + wire pre_done; + wire [NA-1:0] pwire; + // }}} - reg almost_done; - - wire pre_done; assign pre_done = (count == 0); + + // almost_done + // {{{ initial almost_done = 1'b0; always @(posedge i_clk) almost_done <= (!i_reset)&&(o_busy)&&(pre_done); + // }}} + // aux, o_done, o_busy + // {{{ initial aux = 0; initial o_done = 0; initial o_busy = 0; always @(posedge i_clk) if (i_reset) begin + // {{{ aux <= 0; o_done <= 0; o_busy <= 0; + // }}} end else if ((!o_busy)&&(i_stb)) begin + // {{{ o_done <= 0; o_busy <= 1; aux <= i_aux; + // }}} end else if ((o_busy)&&(almost_done)) begin + // {{{ o_done <= 1; o_busy <= 0; + // }}} end else o_done <= 0; + // }}} - wire [NA-1:0] pwire; assign pwire = (p_b[0] ? p_a : 0); - + // count, partial, p_a, p_b + // {{{ always @(posedge i_clk) if (!o_busy) begin @@ -120,19 +139,33 @@ module slowmpy(i_clk, i_reset, i_stb, i_a, i_b, i_aux, o_busy, + ((p_b[0]) ? {1'b0,p_a} : 0); count <= count - 1; end + // }}} + // o_p, o_aux + // {{{ always @(posedge i_clk) if (almost_done) begin if (OPT_SIGNED) o_p <= partial[NA+NB-1:0] - + {1'b1,{(NA-2){1'b0}},1'b1, {(NB){1'b0}}}; + + { 1'b1, {(NA-2){1'b0}}, 1'b1, {(NB){1'b0}} }; else o_p <= partial[NA+NB-1:0]; o_aux <= aux; end - + // }}} +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal properties +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// `ifdef FORMAL + // Declarations and reset + // {{{ `define ASSERT assert `ifdef SLOWMPY `define ASSUME assume @@ -141,13 +174,16 @@ module slowmpy(i_clk, i_reset, i_stb, i_a, i_b, i_aux, o_busy, `endif reg f_past_valid; + initial f_past_valid = 1'b0; always @(posedge i_clk) f_past_valid <= 1'b1; + initial assume(i_reset); always @(*) if (!f_past_valid) `ASSUME(i_reset); + // }}} always @(posedge i_clk) if ((!f_past_valid)||($past(i_reset))) @@ -169,7 +205,7 @@ module slowmpy(i_clk, i_reset, i_stb, i_a, i_b, i_aux, o_busy, // // For now, just formally verify our internal signaling - // + // {{{ always @(posedge i_clk) `ASSERT(almost_done == (o_busy&&(&count))); @@ -197,21 +233,30 @@ module slowmpy(i_clk, i_reset, i_stb, i_a, i_b, i_aux, o_busy, if (o_done) begin if ((f_a == 0)||(f_b == 0)) + begin `ASSERT(o_p == 0); - else + end else `ASSERT(o_p[NA+NB-1] == f_a[NA-1] ^ f_b[NA-1]); end - + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Cover properties + // {{{ + //////////////////////////////////////////////////////////////////////// + // always @(posedge i_clk) cover(o_done); - reg f_past_done; - initial f_past_done = 1'b0; + reg cvr_past_done; + initial cvr_past_done = 1'b0; always @(posedge i_clk) if (o_done) - f_past_done = 1'b1; + cvr_past_done <= 1'b1; always @(posedge i_clk) - cover((o_done)&&(f_past_done)); + cover((o_done)&&(cvr_past_done)); + // }}} `endif +// }}} endmodule diff --git a/rtl/cpu/wbarbiter.v b/rtl/cpu/wbarbiter.v index 194fb3b..a122c17 100644 --- a/rtl/cpu/wbarbiter.v +++ b/rtl/cpu/wbarbiter.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: wbarbiter.v -// +// {{{ // Project: Zip CPU -- a small, lightweight, RISC CPU soft core // // Purpose: This is a priority bus arbiter. It allows two separate wishbone @@ -33,9 +33,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2019, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -50,140 +50,151 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // // `default_nettype none // `define WBA_ALTERNATING -// -module wbarbiter(i_clk, i_reset, - // Bus A -- the priority bus - i_a_cyc, i_a_stb, i_a_we, i_a_adr, i_a_dat, i_a_sel, - o_a_stall, o_a_ack, o_a_err, - // Bus B - i_b_cyc, i_b_stb, i_b_we, i_b_adr, i_b_dat, i_b_sel, - o_b_stall, o_b_ack, o_b_err, - // Combined/arbitrated bus - o_cyc, o_stb, o_we, o_adr, o_dat, o_sel, i_stall, i_ack, i_err +// }}} +module wbarbiter #( + // {{{ + parameter DW=32, AW=32, + parameter SCHEME="ALTERNATING", + parameter [0:0] OPT_ZERO_ON_IDLE = 1'b0 `ifdef FORMAL - , - f_a_nreqs, f_a_nacks, f_a_outstanding, - f_b_nreqs, f_b_nacks, f_b_outstanding, - f_nreqs, f_nacks, f_outstanding + , parameter F_MAX_STALL = 3, + parameter F_MAX_ACK_DELAY = 3, + parameter F_LGDEPTH=3 `endif - ); - parameter DW=32, AW=32; - parameter SCHEME="ALTERNATING"; - parameter [0:0] OPT_ZERO_ON_IDLE = 1'b0; - parameter F_MAX_STALL = 3; - parameter F_MAX_ACK_DELAY = 3; + // }}} + ) ( + // {{{ + input wire i_clk, i_reset, + // Bus A -- the priority bus + // {{{ + input wire i_a_cyc, i_a_stb, i_a_we, + input wire [(AW-1):0] i_a_adr, + input wire [(DW-1):0] i_a_dat, + input wire [(DW/8-1):0] i_a_sel, + output wire o_a_stall, o_a_ack, o_a_err, + // }}} + // Bus B + // {{{ + input wire i_b_cyc, i_b_stb, i_b_we, + input wire [(AW-1):0] i_b_adr, + input wire [(DW-1):0] i_b_dat, + input wire [(DW/8-1):0] i_b_sel, + output wire o_b_stall, o_b_ack, o_b_err, + // }}} + // Combined/arbitrated bus + // {{{ + output wire o_cyc, o_stb, o_we, + output wire [(AW-1):0] o_adr, + output wire [(DW-1):0] o_dat, + output wire [(DW/8-1):0] o_sel, + input wire i_stall, i_ack, i_err + // }}} `ifdef FORMAL - parameter F_LGDEPTH=3; -`endif - - // - input wire i_clk, i_reset; - // Bus A - input wire i_a_cyc, i_a_stb, i_a_we; - input wire [(AW-1):0] i_a_adr; - input wire [(DW-1):0] i_a_dat; - input wire [(DW/8-1):0] i_a_sel; - output wire o_a_stall, o_a_ack, o_a_err; - // Bus B - input wire i_b_cyc, i_b_stb, i_b_we; - input wire [(AW-1):0] i_b_adr; - input wire [(DW-1):0] i_b_dat; - input wire [(DW/8-1):0] i_b_sel; - output wire o_b_stall, o_b_ack, o_b_err; - // - output wire o_cyc, o_stb, o_we; - output wire [(AW-1):0] o_adr; - output wire [(DW-1):0] o_dat; - output wire [(DW/8-1):0] o_sel; - input wire i_stall, i_ack, i_err; - // -`ifdef FORMAL - output wire [(F_LGDEPTH-1):0] f_nreqs, f_nacks, f_outstanding, + , output wire [(F_LGDEPTH-1):0] + f_nreqs, f_nacks, f_outstanding, f_a_nreqs, f_a_nacks, f_a_outstanding, - f_b_nreqs, f_b_nacks, f_b_outstanding; + f_b_nreqs, f_b_nacks, f_b_outstanding `endif + // }}} + ); + // {{{ // Go high immediately (new cycle) if ... // Previous cycle was low and *someone* is requesting a bus cycle // Go low immadiately if ... // We were just high and the owner no longer wants the bus // WISHBONE Spec recommends no logic between a FF and the o_cyc // This violates that spec. (Rec 3.15, p35) + // }}} + + // Local declarations + // {{{ reg r_a_owner; + // }}} assign o_cyc = (r_a_owner) ? i_a_cyc : i_b_cyc; initial r_a_owner = 1'b1; + // r_a_owner -- determined through arbitration + // {{{ generate if (SCHEME == "PRIORITY") begin : PRI - + // {{{ always @(posedge i_clk) - if (!i_b_cyc) - r_a_owner <= 1'b1; - // Allow B to set its CYC line w/o activating this - // interface - else if ((i_b_stb)&&(!i_a_cyc)) - r_a_owner <= 1'b0; - + if (!i_b_cyc) + r_a_owner <= 1'b1; + // Allow B to set its CYC line w/o activating this + // interface + else if ((i_b_stb)&&(!i_a_cyc)) + r_a_owner <= 1'b0; + // }}} end else if (SCHEME == "ALTERNATING") begin : ALT - + // {{{ reg last_owner; + initial last_owner = 1'b0; always @(posedge i_clk) - if ((i_a_cyc)&&(r_a_owner)) - last_owner <= 1'b1; - else if ((i_b_cyc)&&(!r_a_owner)) - last_owner <= 1'b0; + if ((i_a_cyc)&&(r_a_owner)) + last_owner <= 1'b1; + else if ((i_b_cyc)&&(!r_a_owner)) + last_owner <= 1'b0; always @(posedge i_clk) - if ((!i_a_cyc)&&(!i_b_cyc)) - r_a_owner <= !last_owner; - else if ((r_a_owner)&&(!i_a_cyc)) - begin - - if (i_b_stb) - r_a_owner <= 1'b0; + if ((!i_a_cyc)&&(!i_b_cyc)) + r_a_owner <= !last_owner; + else if ((r_a_owner)&&(!i_a_cyc)) + begin - end else if ((!r_a_owner)&&(!i_b_cyc)) - begin + if (i_b_stb) + r_a_owner <= 1'b0; - if (i_a_stb) - r_a_owner <= 1'b1; + end else if ((!r_a_owner)&&(!i_b_cyc)) + begin - end + if (i_a_stb) + r_a_owner <= 1'b1; + end + // }}} end else // if (SCHEME == "LAST") begin : LST + // {{{ always @(posedge i_clk) - if ((!i_a_cyc)&&(i_b_stb)) - r_a_owner <= 1'b0; - else if ((!i_b_cyc)&&(i_a_stb)) - r_a_owner <= 1'b1; + if ((!i_a_cyc)&&(i_b_stb)) + r_a_owner <= 1'b0; + else if ((!i_b_cyc)&&(i_a_stb)) + r_a_owner <= 1'b1; + // ?}}} end endgenerate + // }}} - + // o_we + // {{{ // Realistically, if neither master owns the bus, the output is a // don't care. Thus we trigger off whether or not 'A' owns the bus. // If 'B' owns it all we care is that 'A' does not. Likewise, if // neither owns the bus than the values on the various lines are // irrelevant. assign o_we = (r_a_owner) ? i_a_we : i_b_we; + // }}} + // Other bus outputs + // {{{ generate if (OPT_ZERO_ON_IDLE) - begin - // + begin : LOW_POWER + // {{{ // OPT_ZERO_ON_IDLE will use up more logic and may even slow // down the master clock if set. However, it may also reduce // the power used by the FPGA by preventing things from toggling @@ -202,7 +213,9 @@ module wbarbiter(i_clk, i_reset, assign o_b_stall = (o_cyc)&&(!r_a_owner) ? i_stall : 1'b1; assign o_a_err = (o_cyc)&&( r_a_owner) ? i_err : 1'b0; assign o_b_err = (o_cyc)&&(!r_a_owner) ? i_err : 1'b0; - end else begin + // }}} + end else begin : LOW_LOGIC + // {{{ assign o_stb = (r_a_owner) ? i_a_stb : i_b_stb; assign o_adr = (r_a_owner) ? i_a_adr : i_b_adr; @@ -224,14 +237,26 @@ module wbarbiter(i_clk, i_reset, // assign o_a_err = ( r_a_owner) ? i_err : 1'b0; assign o_b_err = (!r_a_owner) ? i_err : 1'b0; + // }}} end endgenerate + // }}} // Make Verilator happy + // {{{ // verilator lint_off UNUSED wire unused; assign unused = i_reset; // verilator lint_on UNUSED - + // }}} +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal properties +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// `ifdef FORMAL `ifdef WBARBITER @@ -266,58 +291,83 @@ module wbarbiter(i_clk, i_reset, assert($past(r_a_owner) == r_a_owner); end - fwb_master #(.DW(DW), .AW(AW), - .F_MAX_STALL(F_MAX_STALL), - .F_LGDEPTH(F_LGDEPTH), - .F_MAX_ACK_DELAY(F_MAX_ACK_DELAY), - .F_OPT_RMW_BUS_OPTION(1), - .F_OPT_DISCONTINUOUS(1), - .F_OPT_CLK2FFLOGIC(1'b0)) - f_wbm(i_clk, i_reset, - o_cyc, o_stb, o_we, o_adr, o_dat, o_sel, - i_ack, i_stall, 32'h0, i_err, - f_nreqs, f_nacks, f_outstanding); - - fwb_slave #(.DW(DW), .AW(AW), - .F_MAX_STALL(0), - .F_LGDEPTH(F_LGDEPTH), - .F_MAX_ACK_DELAY(0), - .F_OPT_RMW_BUS_OPTION(1), - .F_OPT_DISCONTINUOUS(1), - .F_OPT_CLK2FFLOGIC(1'b0)) - f_wba(i_clk, i_reset, - i_a_cyc, i_a_stb, i_a_we, i_a_adr, i_a_dat, i_a_sel, - o_a_ack, o_a_stall, 32'h0, o_a_err, - f_a_nreqs, f_a_nacks, f_a_outstanding); - - fwb_slave #(.DW(DW), .AW(AW), - .F_MAX_STALL(0), - .F_LGDEPTH(F_LGDEPTH), - .F_MAX_ACK_DELAY(0), - .F_OPT_RMW_BUS_OPTION(1), - .F_OPT_DISCONTINUOUS(1), - .F_OPT_CLK2FFLOGIC(1'b0)) - f_wbb(i_clk, i_reset, - i_b_cyc, i_b_stb, i_b_we, i_b_adr, i_b_dat, i_b_sel, - o_b_ack, o_b_stall, 32'h0, o_b_err, - f_b_nreqs, f_b_nacks, f_b_outstanding); + fwb_master #( + // {{{ + .DW(DW), .AW(AW), + .F_MAX_STALL(F_MAX_STALL), + .F_LGDEPTH(F_LGDEPTH), + .F_MAX_ACK_DELAY(F_MAX_ACK_DELAY), + .F_OPT_RMW_BUS_OPTION(1), + .F_OPT_DISCONTINUOUS(1), + .F_OPT_CLK2FFLOGIC(1'b0) + // }}} + ) f_wbm ( + // {{{ + i_clk, i_reset, + o_cyc, o_stb, o_we, o_adr, o_dat, o_sel, + i_ack, i_stall, 32'h0, i_err, + f_nreqs, f_nacks, f_outstanding + // }}} + ); + + fwb_slave #( + // {{{ + .DW(DW), .AW(AW), + .F_MAX_STALL(0), + .F_LGDEPTH(F_LGDEPTH), + .F_MAX_ACK_DELAY(0), + .F_OPT_RMW_BUS_OPTION(1), + .F_OPT_DISCONTINUOUS(1), + .F_OPT_CLK2FFLOGIC(1'b0) + // }}} + ) f_wba ( + // {{{ + i_clk, i_reset, + i_a_cyc, i_a_stb, i_a_we, i_a_adr, i_a_dat, i_a_sel, + o_a_ack, o_a_stall, 32'h0, o_a_err, + f_a_nreqs, f_a_nacks, f_a_outstanding + // }}} + ); + + fwb_slave #( + // {{{ + .DW(DW), .AW(AW), + .F_MAX_STALL(0), + .F_LGDEPTH(F_LGDEPTH), + .F_MAX_ACK_DELAY(0), + .F_OPT_RMW_BUS_OPTION(1), + .F_OPT_DISCONTINUOUS(1), + .F_OPT_CLK2FFLOGIC(1'b0) + // }}} + ) f_wbb ( + // {{{ + i_clk, i_reset, + i_b_cyc, i_b_stb, i_b_we, i_b_adr, i_b_dat, i_b_sel, + o_b_ack, o_b_stall, 32'h0, o_b_err, + f_b_nreqs, f_b_nacks, f_b_outstanding + // }}} + ); + // Induction properties, relating nreqs and nacks to r_a_owner + // {{{ always @(posedge i_clk) - if (r_a_owner) - begin - assert(f_b_nreqs == 0); - assert(f_b_nacks == 0); - assert(f_a_outstanding == f_outstanding); - end else begin - assert(f_a_nreqs == 0); - assert(f_a_nacks == 0); - assert(f_b_outstanding == f_outstanding); - end + if (r_a_owner) + begin + assert(f_b_nreqs == 0); + assert(f_b_nacks == 0); + assert(f_a_outstanding == f_outstanding); + end else begin + assert(f_a_nreqs == 0); + assert(f_a_nacks == 0); + assert(f_b_outstanding == f_outstanding); + end + // }}} always @(posedge i_clk) if ((f_past_valid)&&(!$past(i_reset)) &&($past(i_a_stb))&&(!$past(i_b_cyc))) assert(r_a_owner); + always @(posedge i_clk) if ((f_past_valid)&&(!$past(i_reset)) &&(!$past(i_a_cyc))&&($past(i_b_stb))) @@ -328,5 +378,6 @@ module wbarbiter(i_clk, i_reset, assert(!$past(o_cyc)); `endif +// }}} endmodule diff --git a/rtl/cpu/wbdblpriarb.v b/rtl/cpu/wbdblpriarb.v index 9f308cf..3506485 100644 --- a/rtl/cpu/wbdblpriarb.v +++ b/rtl/cpu/wbdblpriarb.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: wbdblpriarb.v -// +// {{{ // Project: Zip CPU -- a small, lightweight, RISC CPU soft core // // Purpose: This should almost be identical to the priority arbiter, save @@ -43,9 +43,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015,2018-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -60,65 +60,80 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // // `default_nettype none -// -module wbdblpriarb(i_clk, i_reset, - // Bus A - i_a_cyc_a,i_a_cyc_b,i_a_stb_a,i_a_stb_b,i_a_we,i_a_adr, i_a_dat, i_a_sel, o_a_stall, o_a_ack, o_a_err, - // Bus B - i_b_cyc_a,i_b_cyc_b,i_b_stb_a,i_b_stb_b,i_b_we,i_b_adr, i_b_dat, i_b_sel, o_b_stall, o_b_ack, o_b_err, - // Both buses - o_cyc_a, o_cyc_b, o_stb_a, o_stb_b, o_we, o_adr, o_dat, o_sel, - i_stall, i_ack, i_err +// }}} +module wbdblpriarb #( + // {{{ + parameter DW=32, AW=32, + // OPT_ZERO_ON_IDLE + // {{{ + // OPT_ZERO_ON_IDLE uses more logic than the alternative. It + // should be useful for reducing power, as these circuits tend + // to drive wires all the way across the design, but it may also + // slow down the master clock. I've used it as an option when + // using VER1LATOR, 'cause zeroing things on idle can make them + // stand out all the more when staring at wires and dumps and + // such. + parameter [0:0] OPT_ZERO_ON_IDLE = 1'b0 + // }}} + // }}} + ) ( + // {{{ + input wire i_clk, i_reset, + // Bus A + // {{{ + input wire i_a_cyc_a, i_a_cyc_b, + i_a_stb_a, i_a_stb_b, i_a_we, + input wire [(AW-1):0] i_a_adr, + input wire [(DW-1):0] i_a_dat, + input wire [(DW/8-1):0] i_a_sel, + output wire o_a_stall, o_a_ack, o_a_err, + // }}} + // Bus B + // {{{ + input wire i_b_cyc_a, i_b_cyc_b, + i_b_stb_a, i_b_stb_b, i_b_we, + input wire [(AW-1):0] i_b_adr, + input wire [(DW-1):0] i_b_dat, + input wire [(DW/8-1):0] i_b_sel, + output wire o_b_stall, o_b_ack, o_b_err, + // }}} + // Both buses (i.e. the outgoing, arbitrated bus) + // {{{ + output wire o_cyc_a, o_cyc_b, + o_stb_a, o_stb_b, o_we, + output wire [(AW-1):0] o_adr, + output wire [(DW-1):0] o_dat, + output wire [(DW/8-1):0] o_sel, + input wire i_stall, i_ack, i_err + // }}} +`ifdef FORMAL + // {{{ + // These wires are relics from when the ZipCPU was verified + // with this arbiter internal to it. Since this is no longer + // the case, they're now no more than declarations + , output wire [(F_LGDEPTH-1):0] + f_nreqs_a, f_nacks_a, f_outstanding_a, + f_nreqs_b, f_nacks_b, f_outstanding_b, + f_a_nreqs_a, f_a_nacks_a, f_a_outstanding_a, + f_a_nreqs_b, f_a_nacks_b, f_a_outstanding_b, + f_b_nreqs_a, f_b_nacks_a, f_b_outstanding_a, + f_b_nreqs_b, f_b_nacks_b, f_b_outstanding_b + // }}} +`endif + // }}} ); - parameter DW=32, AW=32; - // - // ZERO_ON_IDLE uses more logic than the alternative. It should be - // useful for reducing power, as these circuits tend to drive wires - // all the way across the design, but it may also slow down the master - // clock. I've used it as an option when using VERILATOR, 'cause - // zeroing things on idle can make them stand out all the more when - // staring at wires and dumps and such. - parameter [0:0] OPT_ZERO_ON_IDLE = 1'b0; - // - // - parameter F_LGDEPTH = 3; - // - // - parameter F_MAX_STALL = 0; - parameter F_MAX_ACK_DELAY=0; - // - // Wishbone doesn't use an i_ce signal. While it could, they dislike - // what it would (might) do to the synchronous reset signal, i_reset. - input wire i_clk, i_reset; - // Bus A - input wire i_a_cyc_a, i_a_cyc_b, i_a_stb_a, i_a_stb_b, i_a_we; - input wire [(AW-1):0] i_a_adr; - input wire [(DW-1):0] i_a_dat; - input wire [(DW/8-1):0] i_a_sel; - output wire o_a_stall, o_a_ack, o_a_err; - // Bus B - input wire i_b_cyc_a, i_b_cyc_b, i_b_stb_a, i_b_stb_b, i_b_we; - input wire [(AW-1):0] i_b_adr; - input wire [(DW-1):0] i_b_dat; - input wire [(DW/8-1):0] i_b_sel; - output wire o_b_stall, o_b_ack, o_b_err; - // - output wire o_cyc_a,o_cyc_b, o_stb_a, o_stb_b, o_we; - output wire [(AW-1):0] o_adr; - output wire [(DW-1):0] o_dat; - output wire [(DW/8-1):0] o_sel; - input wire i_stall, i_ack, i_err; - + // r_a_owner + // {{{ // All of our logic is really captured in the 'r_a_owner' register. // This register determines who owns the bus. If no one is requesting // the bus, ownership goes to A on the next clock. Otherwise, if B is @@ -131,49 +146,52 @@ module wbdblpriarb(i_clk, i_reset, initial r_a_owner = 1'b1; always @(posedge i_clk) - if (i_reset) - r_a_owner <= 1'b1; - /* - // Remain with the "last owner" until 1) the other bus requests - // access, and 2) the last owner no longer wants it. This - // logic "idles" on the last owner. - // - // This is an alternating bus owner strategy - // - else if ((!o_cyc_a)&&(!o_cyc_b)) - r_a_owner <= ((i_b_stb_a)||(i_b_stb_b))? 1'b0:1'b1; - // - // Expanding this out - // - // else if ((r_a_owner)&&((i_a_cyc_a)||(i_a_cyc_b))) - // r_a_owner <= 1'b1; - // else if ((!r_a_owner)&&((i_b_cyc_a)||(i_b_cyc_b))) - // r_a_owner <= 1'b0; - // else if ((r_a_owner)&&((i_b_stb_a)||(i_b_stb_b))) - // r_a_owner <= 1'b0; - // else if ((!r_a_owner)&&((i_a_stb_a)||(i_a_stb_b))) - // r_a_owner <= 1'b0; - // - // Logic required: - // - // Reset line - // + 9 inputs (data) - // + 9 inputs (CE) - // Could be done with three LUTs - // First two evaluate o_cyc_a and o_cyc_b (above) - */ - // Option 2: - // - // "Idle" on A as the owner. - // If a request is made from B, AND A is idle, THEN - // switch. Otherwise, if B is ever idle, revert back to A - // regardless of whether A wants it or not. - else if ((!i_b_cyc_a)&&(!i_b_cyc_b)) - r_a_owner <= 1'b1; - else if ((!i_a_cyc_a)&&(!i_a_cyc_b) - &&((i_b_stb_a)||(i_b_stb_b))) - r_a_owner <= 1'b0; + if (i_reset) + r_a_owner <= 1'b1; + /* + // Remain with the "last owner" until 1) the other bus requests + // access, and 2) the last owner no longer wants it. This + // logic "idles" on the last owner. + // + // This is an alternating bus owner strategy + // + else if ((!o_cyc_a)&&(!o_cyc_b)) + r_a_owner <= ((i_b_stb_a)||(i_b_stb_b))? 1'b0:1'b1; + // + // Expanding this out + // + // else if ((r_a_owner)&&((i_a_cyc_a)||(i_a_cyc_b))) + // r_a_owner <= 1'b1; + // else if ((!r_a_owner)&&((i_b_cyc_a)||(i_b_cyc_b))) + // r_a_owner <= 1'b0; + // else if ((r_a_owner)&&((i_b_stb_a)||(i_b_stb_b))) + // r_a_owner <= 1'b0; + // else if ((!r_a_owner)&&((i_a_stb_a)||(i_a_stb_b))) + // r_a_owner <= 1'b0; + // + // Logic required: + // + // Reset line + // + 9 inputs (data) + // + 9 inputs (CE) + // Could be done with three LUTs + // First two evaluate o_cyc_a and o_cyc_b (above) + */ + // Option 2: + // + // "Idle" on A as the owner. + // If a request is made from B, AND A is idle, THEN + // switch. Otherwise, if B is ever idle, revert back to A + // regardless of whether A wants it or not. + else if ((!i_b_cyc_a)&&(!i_b_cyc_b)) + r_a_owner <= 1'b1; + else if ((!i_a_cyc_a)&&(!i_a_cyc_b) + &&((i_b_stb_a)||(i_b_stb_b))) + r_a_owner <= 1'b0; + // }}} + // o_cyc*, o_stb*, o_we + // {{{ // Realistically, if neither master owns the bus, the output is a // don't care. Thus we trigger off whether or not 'A' owns the bus. // If 'B' owns it all we care is that 'A' does not. Likewise, if @@ -185,9 +203,15 @@ module wbdblpriarb(i_clk, i_reset, assign o_stb_a = (r_a_owner) ? i_a_stb_a : i_b_stb_a; assign o_stb_b = (r_a_owner) ? i_a_stb_b : i_b_stb_b; assign o_we = (r_a_owner) ? i_a_we : i_b_we; + // }}} + + // Other bus outputs and returns + // {{{ generate if (OPT_ZERO_ON_IDLE) - begin + begin : OPT_LOWPOWER + // {{{ wire o_cyc, o_stb; + assign o_cyc = ((o_cyc_a)||(o_cyc_b)); assign o_stb = ((o_stb_a)||(o_stb_b)); assign o_adr = (o_stb)?((r_a_owner) ? i_a_adr : i_b_adr):0; @@ -199,7 +223,9 @@ module wbdblpriarb(i_clk, i_reset, assign o_b_stall = (o_cyc)&&(!r_a_owner) ? i_stall : 1'b1; assign o_a_err = (o_cyc)&&( r_a_owner) ? i_err : 1'b0; assign o_b_err = (o_cyc)&&(!r_a_owner) ? i_err : 1'b0; - end else begin + // }}} + end else begin : OPT_LOWLOGIC + // {{{ assign o_adr = (r_a_owner) ? i_a_adr : i_b_adr; assign o_dat = (r_a_owner) ? i_a_dat : i_b_dat; assign o_sel = (r_a_owner) ? i_a_sel : i_b_sel; @@ -219,10 +245,21 @@ module wbdblpriarb(i_clk, i_reset, // assign o_a_err = ( r_a_owner) ? i_err : 1'b0; assign o_b_err = (!r_a_owner) ? i_err : 1'b0; + // }}} end endgenerate - + // }}} +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal properties +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// `ifdef FORMAL // The formal properties for this module are maintained elsewhere `endif +// }}} endmodule diff --git a/rtl/cpu/wbdmac.v b/rtl/cpu/wbdmac.v index e158350..0aec704 100644 --- a/rtl/cpu/wbdmac.v +++ b/rtl/cpu/wbdmac.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: wbdmac.v -// +// {{{ // Project: Zip CPU -- a small, lightweight, RISC CPU soft core // // Purpose: Wishbone DMA controller @@ -85,9 +85,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -102,97 +102,67 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // // //////////////////////////////////////////////////////////////////////////////// // // -`define DMA_IDLE 3'b000 -`define DMA_WAIT 3'b001 -`define DMA_READ_REQ 3'b010 -`define DMA_READ_ACK 3'b011 -`define DMA_PRE_WRITE 3'b100 -`define DMA_WRITE_REQ 3'b101 -`define DMA_WRITE_ACK 3'b110 - -module wbdmac(i_clk, i_reset, - i_swb_cyc, i_swb_stb, i_swb_we, i_swb_addr, i_swb_data, - o_swb_stall, o_swb_ack, o_swb_data, - o_mwb_cyc, o_mwb_stb, o_mwb_we, o_mwb_addr, o_mwb_data, - i_mwb_stall, i_mwb_ack, i_mwb_data, i_mwb_err, - i_dev_ints, - o_interrupt); - parameter ADDRESS_WIDTH=30, LGMEMLEN = 10, DW=32; - localparam LGDV=5; - localparam AW=ADDRESS_WIDTH; - input wire i_clk, i_reset; - // Slave/control wishbone inputs - input wire i_swb_cyc, i_swb_stb, i_swb_we; - input wire [1:0] i_swb_addr; - input wire [(DW-1):0] i_swb_data; - // Slave/control wishbone outputs - output reg o_swb_ack; - output wire o_swb_stall; - output reg [(DW-1):0] o_swb_data; - // Master/DMA wishbone control - output wire o_mwb_cyc, o_mwb_stb, o_mwb_we; - output reg [(AW-1):0] o_mwb_addr; - output reg [(DW-1):0] o_mwb_data; - // Master/DMA wishbone responses from the bus - input wire i_mwb_stall, i_mwb_ack; - input wire [(DW-1):0] i_mwb_data; - input wire i_mwb_err; - // The interrupt device interrupt lines - input wire [(DW-1):0] i_dev_ints; - // An interrupt to be set upon completion - output reg o_interrupt; - // Need to release the bus for a higher priority user - // This logic had lots of problems, so it is being - // removed. If you want to make sure the bus is available - // for a higher priority user, adjust the transfer length - // accordingly. - // - // input i_other_busmaster_requests_bus; - // - +// +`default_nettype none +// }}} +module wbdmac #( + // {{{ + parameter ADDRESS_WIDTH=30, LGMEMLEN = 10, DW=32, + localparam LGDV=5, + localparam AW=ADDRESS_WIDTH, + localparam [2:0] DMA_IDLE = 3'b000, + localparam [2:0] DMA_WAIT = 3'b001, + localparam [2:0] DMA_READ_REQ = 3'b010, + localparam [2:0] DMA_READ_ACK = 3'b011, + localparam [2:0] DMA_PRE_WRITE = 3'b100, + localparam [2:0] DMA_WRITE_REQ = 3'b101, + localparam [2:0] DMA_WRITE_ACK = 3'b110 + // }}} + ) ( + // {{{ + input wire i_clk, i_reset, + // Slave port + // {{{ + // Slave/control wishbone inputs + input wire i_swb_cyc, i_swb_stb, i_swb_we, + input wire [1:0] i_swb_addr, + input wire [(DW-1):0] i_swb_data, + // Slave/control wishbone outputs + output wire o_swb_stall, + output reg o_swb_ack, + output reg [(DW-1):0] o_swb_data, + // }}} + // Master/DMA port + // {{{ + output wire o_mwb_cyc, o_mwb_stb, o_mwb_we, + output reg [(AW-1):0] o_mwb_addr, + output reg [(DW-1):0] o_mwb_data, + // Master/DMA wishbone responses from the bus + input wire i_mwb_stall, i_mwb_ack, + input wire [(DW-1):0] i_mwb_data, + input wire i_mwb_err, + // }}} + // The interrupt device interrupt lines + input wire [(DW-1):0] i_dev_ints, + // An interrupt to be set upon completion + output reg o_interrupt + // }}} + ); + + // Local declarations + // {{{ wire s_cyc, s_stb, s_we; wire [1:0] s_addr; wire [31:0] s_data; -`define DELAY_ACCESS -`ifdef DELAY_ACCESS - reg r_s_cyc, r_s_stb, r_s_we; - reg [1:0] r_s_addr; - reg [31:0] r_s_data; - - always @(posedge i_clk) - r_s_cyc <= i_swb_cyc; - always @(posedge i_clk) - if (i_reset) - r_s_stb <= 1'b0; - else - r_s_stb <= i_swb_stb; - always @(posedge i_clk) - r_s_we <= i_swb_we; - always @(posedge i_clk) - r_s_addr<= i_swb_addr; - always @(posedge i_clk) - r_s_data<= i_swb_data; - - assign s_cyc = r_s_cyc; - assign s_stb = r_s_stb; - assign s_we = r_s_we; - assign s_addr= r_s_addr; - assign s_data= r_s_data; -`else - assign s_cyc = i_swb_cyc; - assign s_stb = i_swb_stb; - assign s_we = i_swb_we; - assign s_addr= i_swb_addr; - assign s_data= i_swb_data; -`endif reg [2:0] dma_state; reg cfg_err, cfg_len_nonzero; @@ -208,25 +178,76 @@ module wbdmac(i_clk, i_reset, reg [(DW-1):0] dma_mem [0:(((1< 1); end + // }}} + // nracks + // {{{ initial nracks = 0; always @(posedge i_clk) if (i_reset) nracks <= 0; - else if ((dma_state == `DMA_IDLE)||(dma_state == `DMA_WAIT)) + else if ((dma_state == DMA_IDLE)||(dma_state == DMA_WAIT)) nracks <= 0; else if ((o_mwb_stb)&&(!o_mwb_we)&&(!i_mwb_stall)) nracks <= nracks + 1'b1; + // }}} + // nread + // {{{ initial nread = 0; always @(posedge i_clk) if (i_reset) nread <= 0; - else if ((dma_state == `DMA_IDLE)||(dma_state == `DMA_WAIT)) + else if ((dma_state == DMA_IDLE)||(dma_state == DMA_WAIT)) nread <= 0; else if ((!o_mwb_we)&&(i_mwb_ack)) nread <= nread + 1'b1; + // }}} + // nwritten + // {{{ initial nwritten = 0; always @(posedge i_clk) if (i_reset) @@ -394,7 +441,10 @@ module wbdmac(i_clk, i_reset, nwritten <= 0; else if ((o_mwb_stb)&&(!i_mwb_stall)) nwritten <= nwritten + 1'b1; + // }}} + // nwacks + // {{{ initial nwacks = 0; always @(posedge i_clk) if (i_reset) @@ -403,25 +453,31 @@ module wbdmac(i_clk, i_reset, nwacks <= 0; else if (i_mwb_ack) nwacks <= nwacks + 1'b1; + // }}} + // cfg_err + // {{{ initial cfg_err = 1'b0; always @(posedge i_clk) if (i_reset) cfg_err <= 1'b0; - else if (dma_state == `DMA_IDLE) + else if (dma_state == DMA_IDLE) begin if ((s_stb)&&(s_we)&&(s_addr==2'b00)) cfg_err <= 1'b0; end else if (((i_mwb_err)&&(o_mwb_cyc))||(abort)) cfg_err <= 1'b1; + // }}} + // last_read_request + // {{{ initial last_read_request = 1'b0; always @(posedge i_clk) if (i_reset) last_read_request <= 1'b0; - else if ((dma_state == `DMA_WAIT)||(dma_state == `DMA_READ_REQ)) + else if ((dma_state == DMA_WAIT)||(dma_state == DMA_READ_REQ)) begin - if ((!i_mwb_stall)&&(dma_state == `DMA_READ_REQ)) + if ((!i_mwb_stall)&&(dma_state == DMA_READ_REQ)) begin last_read_request <= (nracks + 1 == { 1'b0, cfg_blocklen_sub_one}) @@ -432,22 +488,23 @@ module wbdmac(i_clk, i_reset, ||(bus_nracks == cfg_len-1); end else last_read_request <= 1'b0; + // }}} - - wire [(LGMEMLEN):0] next_nread; assign next_nread = nread + 1'b1; + // last_read_ack + // {{{ initial last_read_ack = 1'b0; always @(posedge i_clk) if (i_reset) last_read_ack <= 0; - else if (dma_state == `DMA_READ_REQ) + else if (dma_state == DMA_READ_REQ) begin if ((i_mwb_ack)&&((!o_mwb_stb)||(i_mwb_stall))) last_read_ack <= (next_nread == { 1'b0, cfg_blocklen_sub_one }); else last_read_ack <= (nread == { 1'b0, cfg_blocklen_sub_one }); - end else if (dma_state == `DMA_READ_ACK) + end else if (dma_state == DMA_READ_ACK) begin if ((i_mwb_ack)&&((!o_mwb_stb)||(i_mwb_stall))) last_read_ack <= (nread+2 == nracks); @@ -455,14 +512,17 @@ module wbdmac(i_clk, i_reset, last_read_ack <= (next_nread == nracks); end else last_read_ack <= 1'b0; + // }}} + // last_write_request + // {{{ initial last_write_request = 1'b0; always @(posedge i_clk) if (i_reset) last_write_request <= 1'b0; - else if (dma_state == `DMA_PRE_WRITE) + else if (dma_state == DMA_PRE_WRITE) last_write_request <= (nread <= 1); - else if (dma_state == `DMA_WRITE_REQ) + else if (dma_state == DMA_WRITE_REQ) begin if (i_mwb_stall) last_write_request <= (nwritten >= nread-1); @@ -470,12 +530,15 @@ module wbdmac(i_clk, i_reset, last_write_request <= (nwritten >= nread-2); end else last_write_request <= 1'b0; + // }}} + // last_write_ack + // {{{ initial last_write_ack = 1'b0; always @(posedge i_clk) if (i_reset) last_write_ack <= 1'b0; - else if((dma_state == `DMA_WRITE_REQ)||(dma_state == `DMA_WRITE_ACK)) + else if((dma_state == DMA_WRITE_REQ)||(dma_state == DMA_WRITE_ACK)) begin if ((i_mwb_ack)&&((!o_mwb_stb)||(i_mwb_stall))) last_write_ack <= (nwacks+2 == nwritten); @@ -483,54 +546,60 @@ module wbdmac(i_clk, i_reset, last_write_ack <= (nwacks+1 == nwritten); end else last_write_ack <= 1'b0; + // }}} + assign o_mwb_cyc = (dma_state == DMA_READ_REQ) + ||(dma_state == DMA_READ_ACK) + ||(dma_state == DMA_WRITE_REQ) + ||(dma_state == DMA_WRITE_ACK); - assign o_mwb_cyc = (dma_state == `DMA_READ_REQ) - ||(dma_state == `DMA_READ_ACK) - ||(dma_state == `DMA_WRITE_REQ) - ||(dma_state == `DMA_WRITE_ACK); - - assign o_mwb_stb = (dma_state == `DMA_READ_REQ) - ||(dma_state == `DMA_WRITE_REQ); + assign o_mwb_stb = (dma_state == DMA_READ_REQ) + ||(dma_state == DMA_WRITE_REQ); - assign o_mwb_we = (dma_state == `DMA_PRE_WRITE) - ||(dma_state == `DMA_WRITE_REQ) - ||(dma_state == `DMA_WRITE_ACK); + assign o_mwb_we = (dma_state == DMA_PRE_WRITE) + ||(dma_state == DMA_WRITE_REQ) + ||(dma_state == DMA_WRITE_ACK); - // + // rdaddr + // {{{ // This is tricky. In order for Vivado to consider dma_mem to be a // proper memory, it must have a simple address fed into it. Hence // the read_address (rdaddr) register. The problem is that this // register must always be one greater than the address we actually // want to read from, unless we are idling. So ... the math is touchy. // - reg [(LGMEMLEN-1):0] rdaddr; initial rdaddr = 0; always @(posedge i_clk) if (i_reset) rdaddr <= 0; - else if((dma_state == `DMA_IDLE)||(dma_state == `DMA_WAIT) - ||(dma_state == `DMA_WRITE_ACK)) + else if((dma_state == DMA_IDLE)||(dma_state == DMA_WAIT) + ||(dma_state == DMA_WRITE_ACK)) rdaddr <= 0; - else if ((dma_state == `DMA_PRE_WRITE) - ||((dma_state==`DMA_WRITE_REQ)&&(!i_mwb_stall))) + else if ((dma_state == DMA_PRE_WRITE) + ||((dma_state == DMA_WRITE_REQ)&&(!i_mwb_stall))) rdaddr <= rdaddr + {{(LGMEMLEN-1){1'b0}},1'b1}; + // }}} + // o_mwb_data + // {{{ always @(posedge i_clk) if (i_reset) o_mwb_data <= 0; - else if ((dma_state != `DMA_WRITE_REQ)||(!i_mwb_stall)) + else if ((dma_state != DMA_WRITE_REQ)||(!i_mwb_stall)) o_mwb_data <= dma_mem[rdaddr]; always @(posedge i_clk) - if((dma_state == `DMA_READ_REQ)||(dma_state == `DMA_READ_ACK)) + if((dma_state == DMA_READ_REQ)||(dma_state == DMA_READ_ACK)) dma_mem[nread[(LGMEMLEN-1):0]] <= i_mwb_data; + // }}} + // o_swb_data + // {{{ always @(posedge i_clk) if (i_reset) o_swb_data <= 0; else casez(s_addr) - 2'b00: o_swb_data <= { (dma_state != `DMA_IDLE), cfg_err, + 2'b00: o_swb_data <= { (dma_state != DMA_IDLE), cfg_err, !cfg_incs, !cfg_incd, 1'b0, nread, cfg_on_dev_trigger, cfg_dev_trigger, @@ -540,7 +609,10 @@ module wbdmac(i_clk, i_reset, 2'b10: o_swb_data <= { {(DW-2-AW){1'b0}}, cfg_raddr, 2'b00 }; 2'b11: o_swb_data <= { {(DW-2-AW){1'b0}}, cfg_waddr, 2'b00 }; endcase + // }}} + // trigger + // {{{ // This causes us to wait a minimum of two clocks before starting: One // to go into the wait state, and then one while in the wait state to // develop the trigger. @@ -549,10 +621,13 @@ module wbdmac(i_clk, i_reset, if (i_reset) trigger <= 1'b0; else - trigger <= (dma_state == `DMA_WAIT) + trigger <= (dma_state == DMA_WAIT) &&((!cfg_on_dev_trigger) ||(i_dev_ints[cfg_dev_trigger])); + // }}} + // o_swb_ack + // {{{ // Ack any access. We'll quietly ignore any access where we are busy, // but ack it anyway. In other words, before writing to the device, // double check that it isn't busy, and then write. @@ -564,34 +639,55 @@ module wbdmac(i_clk, i_reset, o_swb_ack <= 1'b0; else o_swb_ack <= (s_stb); + // }}} assign o_swb_stall = 1'b0; + // abort + // {{{ initial abort = 1'b0; always @(posedge i_clk) if (i_reset) abort <= 1'b0; - else if (dma_state == `DMA_IDLE) + else if (dma_state == DMA_IDLE) abort <= 1'b0; else abort <= ((s_stb)&&(s_we) &&(s_addr == 2'b00) &&(s_data == 32'hffed0000)); + // }}} + // user_halt + // {{{ initial user_halt = 1'b0; always @(posedge i_clk) - user_halt <= ((user_halt)&&(dma_state != `DMA_IDLE)) - ||((s_stb)&&(s_we)&&(dma_state != `DMA_IDLE) + if (i_reset) + user_halt <= 1'b0; + else + user_halt <= ((user_halt)&&(dma_state != DMA_IDLE)) + ||((s_stb)&&(s_we)&&(dma_state != DMA_IDLE) &&(s_addr == 2'b00) &&(s_data == 32'hafed0000)); - + // }}} // Make verilator happy + // {{{ // verilator lint_off UNUSED wire unused; assign unused = s_cyc; // verilator lint_on UNUSED + // }}} +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal properties +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// `ifdef FORMAL // The formal properties for this module are maintained elsewhere `endif +// }}} endmodule diff --git a/rtl/cpu/wbpriarbiter.v b/rtl/cpu/wbpriarbiter.v index 7dfdc22..b95ed00 100644 --- a/rtl/cpu/wbpriarbiter.v +++ b/rtl/cpu/wbpriarbiter.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: wbpriarbiter.v -// +// {{{ // Project: Zip CPU -- a small, lightweight, RISC CPU soft core // // Purpose: This is a priority bus arbiter. It allows two separate wishbone @@ -25,9 +25,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015,2018-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -42,69 +42,81 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // // `default_nettype none -// -module wbpriarbiter(i_clk, - // Bus A - i_a_cyc, i_a_stb, i_a_we, i_a_adr, i_a_dat, i_a_sel, o_a_stall, o_a_ack, o_a_err, - // Bus B - i_b_cyc, i_b_stb, i_b_we, i_b_adr, i_b_dat, i_b_sel, o_b_stall, o_b_ack, o_b_err, - // Both buses - o_cyc, o_stb, o_we, o_adr, o_dat, o_sel, i_stall, i_ack, i_err); - parameter DW=32, AW=32; - // - // ZERO_ON_IDLE uses more logic than the alternative. It should be - // useful for reducing power, as these circuits tend to drive wires - // all the way across the design, but it may also slow down the master - // clock. I've used it as an option when using VERILATOR, 'cause - // zeroing things on idle can make them stand out all the more when - // staring at wires and dumps and such. - parameter [0:0] OPT_ZERO_ON_IDLE = 1'b0; - // - input wire i_clk; - // Bus A - input wire i_a_cyc, i_a_stb, i_a_we; - input wire [(AW-1):0] i_a_adr; - input wire [(DW-1):0] i_a_dat; - input wire [(DW/8-1):0] i_a_sel; - output wire o_a_stall, o_a_ack, o_a_err; - // Bus B - input wire i_b_cyc, i_b_stb, i_b_we; - input wire [(AW-1):0] i_b_adr; - input wire [(DW-1):0] i_b_dat; - input wire [(DW/8-1):0] i_b_sel; - output wire o_b_stall, o_b_ack, o_b_err; - // - output wire o_cyc, o_stb, o_we; - output wire [(AW-1):0] o_adr; - output wire [(DW-1):0] o_dat; - output wire [(DW/8-1):0] o_sel; - input wire i_stall, i_ack, i_err; +// }}} +module wbpriarbiter #( + // {{{ + parameter DW=32, AW=32, + // OPT_ZERO_ON_IDLE + // {{{ + // ZERO_ON_IDLE uses more logic than the alternative. It should + // be useful for reducing power, as these circuits tend to drive + // wires all the way across the design, but it may also slow + // down the master clock. I've used it as an option when using + // VER1LATOR, 'cause zeroing things on idle can make them stand + // out all the more when staring at wires and dumps and such. + parameter [0:0] OPT_ZERO_ON_IDLE = 1'b0 + // }}} + // }}} + ) ( + // {{{ + input wire i_clk, + // Bus A + // {{{ + input wire i_a_cyc, i_a_stb, i_a_we, + input wire [(AW-1):0] i_a_adr, + input wire [(DW-1):0] i_a_dat, + input wire [(DW/8-1):0] i_a_sel, + output wire o_a_stall, o_a_ack, o_a_err, + // }}} + // Bus B + // {{{ + input wire i_b_cyc, i_b_stb, i_b_we, + input wire [(AW-1):0] i_b_adr, + input wire [(DW-1):0] i_b_dat, + input wire [(DW/8-1):0] i_b_sel, + output wire o_b_stall, o_b_ack, o_b_err, + // }}} + // Outgoing combined bus + // {{{ + output wire o_cyc, o_stb, o_we, + output wire [(AW-1):0] o_adr, + output wire [(DW-1):0] o_dat, + output wire [(DW/8-1):0] o_sel, + input wire i_stall, i_ack, i_err + // }}} + // }}} + ); + + reg r_a_owner; + // r_a_owner + // {{{ // Go high immediately (new cycle) if ... // Previous cycle was low and *someone* is requesting a bus cycle // Go low immadiately if ... // We were just high and the owner no longer wants the bus // WISHBONE Spec recommends no logic between a FF and the o_cyc // This violates that spec. (Rec 3.15, p35) - reg r_a_owner; - initial r_a_owner = 1'b1; always @(posedge i_clk) - if (!i_b_cyc) - r_a_owner <= 1'b1; - // Allow B to set its CYC line w/o activating this interface - else if ((i_b_cyc)&&(i_b_stb)&&(!i_a_cyc)) - r_a_owner <= 1'b0; + if (!i_b_cyc) + r_a_owner <= 1'b1; + // Allow B to set its CYC line w/o activating this interface + else if ((i_b_cyc)&&(i_b_stb)&&(!i_a_cyc)) + r_a_owner <= 1'b0; + // }}} + // CYC, STB, and WE + // {{{ // Realistically, if neither master owns the bus, the output is a // don't care. Thus we trigger off whether or not 'A' owns the bus. // If 'B' owns it all we care is that 'A' does not. Likewise, if @@ -114,8 +126,13 @@ module wbpriarbiter(i_clk, assign o_cyc = (r_a_owner) ? i_a_cyc : i_b_cyc; assign o_we = (r_a_owner) ? i_a_we : i_b_we; assign o_stb = (r_a_owner) ? i_a_stb : i_b_stb; + // }}} + + // Everything else + // {{{ generate if (OPT_ZERO_ON_IDLE) - begin + begin : OPT_LOWPOWER + // {{{ assign o_adr = (o_stb)?((r_a_owner) ? i_a_adr : i_b_adr):0; assign o_dat = (o_stb)?((r_a_owner) ? i_a_dat : i_b_dat):0; assign o_sel = (o_stb)?((r_a_owner) ? i_a_sel : i_b_sel):0; @@ -125,7 +142,9 @@ module wbpriarbiter(i_clk, assign o_b_stall = (o_cyc)&&(!r_a_owner) ? i_stall : 1'b1; assign o_a_err = (o_cyc)&&( r_a_owner) ? i_err : 1'b0; assign o_b_err = (o_cyc)&&(!r_a_owner) ? i_err : 1'b0; - end else begin + // }}} + end else begin : OPT_LOWLOGIC + // {{{ assign o_adr = (r_a_owner) ? i_a_adr : i_b_adr; assign o_dat = (r_a_owner) ? i_a_dat : i_b_dat; assign o_sel = (r_a_owner) ? i_a_sel : i_b_sel; @@ -145,9 +164,20 @@ module wbpriarbiter(i_clk, // assign o_a_err = ( r_a_owner) ? i_err : 1'b0; assign o_b_err = (!r_a_owner) ? i_err : 1'b0; + // }}} end endgenerate - + // }}} +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal properties +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// `ifdef FORMAL // Formal properties for this module are maintained elsewhere `endif +// }}} endmodule diff --git a/rtl/cpu/wbwatchdog.v b/rtl/cpu/wbwatchdog.v index 2210379..389e7bc 100644 --- a/rtl/cpu/wbwatchdog.v +++ b/rtl/cpu/wbwatchdog.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: wbwatchdog.v -// +// {{{ // Project: Zip CPU -- a small, lightweight, RISC CPU soft core // // Purpose: A Zip timer, redesigned to be a bus watchdog @@ -22,9 +22,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015,2017-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -39,40 +39,59 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // // `default_nettype none -// -module wbwatchdog(i_clk, i_reset, i_timeout, o_int); - parameter BW = 32; - input wire i_clk, i_reset; - // Inputs (these were at one time wishbone controlled ...) - input wire [(BW-1):0] i_timeout; - // Interrupt line - output reg o_int; +// }}} +module wbwatchdog #( + parameter BW = 32 + ) ( + // {{{ + input wire i_clk, i_reset, + // Inputs (these were at one time wishbone controlled ...) + input wire [(BW-1):0] i_timeout, + // Interrupt line + output reg o_int + // }}} + ); reg [(BW-1):0] r_value; + + // r_value + // {{{ initial r_value = {(BW){1'b1}}; always @(posedge i_clk) - if (i_reset) - r_value <= i_timeout[(BW-1):0]; - else if (!o_int) - r_value <= r_value + {(BW){1'b1}}; // r_value - 1; + if (i_reset) + r_value <= i_timeout[(BW-1):0]; + else if (!o_int) + r_value <= r_value + {(BW){1'b1}}; // r_value - 1; + // }}} // Set the interrupt on our last tick. + // {{{ initial o_int = 1'b0; always @(posedge i_clk) - if (i_reset) - o_int <= 1'b0; - else if (!o_int) - o_int <= (r_value == { {(BW-1){1'b0}}, 1'b1 }); - + if (i_reset) + o_int <= 1'b0; + else if (!o_int) + o_int <= (r_value == { {(BW-1){1'b0}}, 1'b1 }); + // }}} +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal properties +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// `ifdef FORMAL reg f_past_valid; @@ -80,30 +99,28 @@ module wbwatchdog(i_clk, i_reset, i_timeout, o_int); always @(posedge f_past_valid) f_past_valid <= 1'b1; - /////////////////////////////////////////////// - // + //////////////////////////////////////////////////////////////////////// // // Assumptions about our inputs + // {{{ + //////////////////////////////////////////////////////////////////////// // // - /////////////////////////////////////////////// always @(*) assume(i_timeout > 1); + always @(posedge i_clk) if (f_past_valid) assume(i_timeout == $past(i_timeout)); - - // - // - /////////////////////////////////////////////// - // + // }}} + //////////////////////////////////////////////////////////////////////// // // Assertions about our internal state and our outputs + // {{{ + //////////////////////////////////////////////////////////////////////// // // - /////////////////////////////////////////////// - // - // + always @(posedge i_clk) if ((f_past_valid)&&($past(o_int))&&(!$past(i_reset))) assert(o_int); @@ -121,10 +138,13 @@ module wbwatchdog(i_clk, i_reset, i_timeout, o_int); if ((!f_past_valid)||($past(i_reset))) begin if (!f_past_valid) + begin assert(r_value == {(BW){1'b1}}); - else // if ($past(i_reset)) + end else // if ($past(i_reset)) assert(r_value == $past(i_timeout)); assert(!o_int); end + // }}} `endif +// }}} endmodule diff --git a/rtl/cpu/zipaxi.v b/rtl/cpu/zipaxi.v new file mode 100644 index 0000000..9d52869 --- /dev/null +++ b/rtl/cpu/zipaxi.v @@ -0,0 +1,1306 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Filename: zipaxi.v +// {{{ +// Project: Zip CPU -- a small, lightweight, RISC CPU soft core +// +// Purpose: A potential top level module holding the core of the Zip CPU +// together--this one with AXI4 instruction and data interfaces, +// and an AXI-lite debug interfaces. In general, the Zip CPU is designed +// to be as simple as possible. (actual implementation aside ...) The +// instruction set is about as RISC as you can get, with only 26 +// instruction types currently supported. (There are still 8-instruction +// Op-Codes reserved for floating point, and 5 which can be used for +// transactions not requiring registers.) Please see the accompanying +// spec.pdf file for a description of these instructions. +// +// This version is bus width agnostic for both instruction and data buses, +// although the debug bus must still be 32-bits. Instruction and data +// buses must be at least 32-bits wide. +// +// Creator: Dan Gisselquist, Ph.D. +// Gisselquist Technology, LLC +// +//////////////////////////////////////////////////////////////////////////////// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ +// This program is free software (firmware): 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 MERCHANTIBILITY 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. (It's in the $(ROOT)/doc directory. Run make with no +// target there if the PDF file isn't present.) If not, see +// for a copy. +// }}} +// License: GPL, v3, as defined and found on www.gnu.org, +// {{{ +// http://www.gnu.org/licenses/gpl.html +// +//////////////////////////////////////////////////////////////////////////////// +// +// +`default_nettype none +// +`include "cpudefs.v" +// +// }}} +module zipaxi #( + // {{{ + parameter C_DBG_ADDR_WIDTH = 8, + localparam C_DBG_DATA_WIDTH = 32, + localparam DBGLSB = $clog2(C_DBG_DATA_WIDTH/8), + parameter C_AXI_ADDR_WIDTH = 32, + parameter C_AXI_DATA_WIDTH = 32, + parameter C_AXI_ID_WIDTH = 1, + parameter INSN_ID = 0, + parameter DATA_ID = 0, + localparam ADDRESS_WIDTH = C_AXI_ADDR_WIDTH, + localparam AXILSB = $clog2(C_AXI_DATA_WIDTH/8), + parameter [C_AXI_ADDR_WIDTH-1:0] RESET_ADDRESS=32'h010_0000, + parameter [0:0] START_HALTED = 1'b0, +`ifdef OPT_MULTIPLY + parameter IMPLEMENT_MPY = `OPT_MULTIPLY, +`else + parameter IMPLEMENT_MPY = 0, +`endif +`ifdef OPT_DIVIDE + parameter [0:0] IMPLEMENT_DIVIDE = 1, +`else + parameter [0:0] IMPLEMENT_DIVIDE = 0, +`endif +`ifdef OPT_IMPLEMENT_FPU + parameter [0:0] IMPLEMENT_FPU = 1, +`else + parameter [0:0] IMPLEMENT_FPU = 0, +`endif +`ifdef OPT_EARLY_BRANCHING + parameter [0:0] EARLY_BRANCHING = 1, +`else + parameter [0:0] EARLY_BRANCHING = 0, +`endif +`ifdef OPT_CIS + parameter [0:0] OPT_CIS = 1'b1, +`else + parameter [0:0] OPT_CIS = 1'b0, +`endif + // localparam [0:0] OPT_NO_USERMODE = 1'b0, +`ifdef OPT_PIPELINED + parameter [0:0] OPT_PIPELINED = 1'b1, +`else + parameter [0:0] OPT_PIPELINED = 1'b0, +`endif +`ifdef OPT_PIPELINED_BUS_ACCESS + localparam [0:0] OPT_PIPELINED_BUS_ACCESS = (OPT_PIPELINED), +`else + localparam [0:0] OPT_PIPELINED_BUS_ACCESS = 1'b0, +`endif + // localparam [0:0] OPT_MEMPIPE = OPT_PIPELINED_BUS_ACCESS, + localparam [0:0] IMPLEMENT_LOCK=1, + // localparam [0:0] OPT_LOCK=(IMPLEMENT_LOCK)&&(OPT_PIPELINED), + parameter LGICACHE = 8, + parameter LGILINESZ= 3, + parameter OPT_LGDCACHE = 0, + parameter OPT_LGDLINESZ = 3, + localparam [0:0] OPT_DCACHE = (OPT_LGDCACHE > 0), + parameter RESET_DURATION = 10, + // localparam [0:0] WITH_LOCAL_BUS = 1'b0, + localparam AW=ADDRESS_WIDTH-2 +`ifdef FORMAL + , parameter F_LGDEPTH=8 +`endif + // }}} + ) ( + // {{{ + input wire S_AXI_ACLK, S_AXI_ARESETN, + i_interrupt, + // Debug interface + // {{{ + // Debug interface -- inputs +// input wire i_halt, i_clear_cache, +// input wire [4:0] i_dbg_wreg, +// input wire i_dbg_we, +// input wire [31:0] i_dbg_data, +// input wire [4:0] i_dbg_rreg, + // Debug interface -- outputs +// output wire cpu_dbg_stall, +// output reg [31:0] o_dbg_reg, +// output reg [2:0] o_dbg_cc, +// output wire o_break, + input wire S_DBG_AWVALID, + output wire S_DBG_AWREADY, + input wire [C_DBG_ADDR_WIDTH-1:0] S_DBG_AWADDR, + input wire [2:0] S_DBG_AWPROT, + // + input wire S_DBG_WVALID, + output wire S_DBG_WREADY, + input wire [31:0] S_DBG_WDATA, + input wire [3:0] S_DBG_WSTRB, + // + output reg S_DBG_BVALID, + input wire S_DBG_BREADY, + output wire [1:0] S_DBG_BRESP, + // + input wire S_DBG_ARVALID, + output wire S_DBG_ARREADY, + input wire [7:0] S_DBG_ARADDR, + input wire [2:0] S_DBG_ARPROT, + // + output reg S_DBG_RVALID, + input wire S_DBG_RREADY, + output reg [31:0] S_DBG_RDATA, + output wire [1:0] S_DBG_RRESP, + // + // }}} + // Instruction bus (master) + // {{{ + output wire M_INSN_AWVALID, + input wire M_INSN_AWREADY, + output wire [C_AXI_ID_WIDTH-1:0] M_INSN_AWID, + output wire [C_AXI_ADDR_WIDTH-1:0] M_INSN_AWADDR, + output wire [7:0] M_INSN_AWLEN, + output wire [2:0] M_INSN_AWSIZE, + output wire [1:0] M_INSN_AWBURST, + output wire M_INSN_AWLOCK, + output wire [3:0] M_INSN_AWCACHE, + output wire [2:0] M_INSN_AWPROT, + output wire [3:0] M_INSN_AWQOS, + // + output wire M_INSN_WVALID, + input wire M_INSN_WREADY, + output wire [C_AXI_DATA_WIDTH-1:0] M_INSN_WDATA, + output wire [C_AXI_DATA_WIDTH/8-1:0] M_INSN_WSTRB, + output wire M_INSN_WLAST, + // + input wire M_INSN_BVALID, + input wire [C_AXI_ID_WIDTH-1:0] M_INSN_BID, + output wire M_INSN_BREADY, + input wire [1:0] M_INSN_BRESP, + // + output wire M_INSN_ARVALID, + input wire M_INSN_ARREADY, + output wire [C_AXI_ID_WIDTH-1:0] M_INSN_ARID, + output wire [C_AXI_ADDR_WIDTH-1:0] M_INSN_ARADDR, + output wire [7:0] M_INSN_ARLEN, + output wire [2:0] M_INSN_ARSIZE, + output wire [1:0] M_INSN_ARBURST, + output wire M_INSN_ARLOCK, + output wire [3:0] M_INSN_ARCACHE, + output wire [2:0] M_INSN_ARPROT, + output wire [3:0] M_INSN_ARQOS, + // + input wire M_INSN_RVALID, + output wire M_INSN_RREADY, + input wire [C_AXI_ID_WIDTH-1:0] M_INSN_RID, + input wire [C_AXI_DATA_WIDTH-1:0] M_INSN_RDATA, + input wire M_INSN_RLAST, + input wire [1:0] M_INSN_RRESP, + // }}} + // Data bus (master) + // {{{ + output wire M_DATA_AWVALID, + input wire M_DATA_AWREADY, + output wire [C_AXI_ID_WIDTH-1:0] M_DATA_AWID, + output wire [C_AXI_ADDR_WIDTH-1:0] M_DATA_AWADDR, + output wire [7:0] M_DATA_AWLEN, + output wire [2:0] M_DATA_AWSIZE, + output wire [1:0] M_DATA_AWBURST, + output wire M_DATA_AWLOCK, + output wire [3:0] M_DATA_AWCACHE, + output wire [2:0] M_DATA_AWPROT, + output wire [3:0] M_DATA_AWQOS, + // + output wire M_DATA_WVALID, + input wire M_DATA_WREADY, + output wire [C_AXI_DATA_WIDTH-1:0] M_DATA_WDATA, + output wire [C_AXI_DATA_WIDTH/8-1:0] M_DATA_WSTRB, + output wire M_DATA_WLAST, + // + input wire M_DATA_BVALID, + output wire M_DATA_BREADY, + input wire [C_AXI_ID_WIDTH-1:0] M_DATA_BID, + input wire [1:0] M_DATA_BRESP, + // + output wire M_DATA_ARVALID, + input wire M_DATA_ARREADY, + output wire [C_AXI_ID_WIDTH-1:0] M_DATA_ARID, + output wire [C_AXI_ADDR_WIDTH-1:0] M_DATA_ARADDR, + output wire [7:0] M_DATA_ARLEN, + output wire [2:0] M_DATA_ARSIZE, + output wire [1:0] M_DATA_ARBURST, + output wire M_DATA_ARLOCK, + output wire [3:0] M_DATA_ARCACHE, + output wire [2:0] M_DATA_ARPROT, + output wire [3:0] M_DATA_ARQOS, + // + input wire M_DATA_RVALID, + output wire M_DATA_RREADY, + input wire [C_AXI_ID_WIDTH-1:0] M_DATA_RID, + input wire [C_AXI_DATA_WIDTH-1:0] M_DATA_RDATA, + input wire M_DATA_RLAST, + input wire [1:0] M_DATA_RRESP, + // }}} + // Accounting outputs ... to help us count stalls and usage + output wire o_op_stall, + output wire o_pf_stall, + output wire o_i_count + // +`ifdef DEBUG_SCOPE + , output reg [31:0] o_debug +`endif + // }}} + ); + + // Declarations + // {{{ + localparam FETCH_LIMIT = 4; + wire [31:0] cpu_debug; + + localparam RESET_BIT = 6, + STEP_BIT = 8, + HALT_BIT = 10, + CLEAR_CACHE_BIT = 11; + localparam [0:0] OPT_LOWPOWER = 1'b0; + localparam [0:0] OPT_ALIGNMENT_ERR = 1'b0; + localparam [0:0] SWAP_ENDIANNESS = 1'b0; + + // AXI-lite signal handling + // {{{ + wire awskd_valid, wskd_valid, arskd_valid; + wire dbg_write_ready, dbg_read_ready; + wire [C_DBG_ADDR_WIDTH-DBGLSB-1:0] awskd_addr, arskd_addr; + wire [31:0] wskd_data; + wire [3:0] wskd_strb; + reg dbg_write_valid, dbg_read_valid; + reg [4:0] dbg_write_reg; + wire [4:0] dbg_read_reg; + reg [31:0] dbg_write_data; + wire [31:0] dbg_read_data; + wire cpu_dbg_stall, cpu_break; + wire [2:0] cpu_dbg_cc; + // }}} + + reg reset_hold; + wire cpu_clken; + + // CPU control registers + // {{{ + reg cmd_halt, cmd_reset, cmd_step, cmd_clear_cache; + wire [31:0] cpu_status; + wire dbg_cmd_write; + // }}} + + // Fetch + // {{{ + wire pf_new_pc, clear_icache, pf_ready; + wire [AW+1:0] pf_request_address; + wire [31:0] pf_instruction; + wire [AW+1:0] pf_instruction_pc; + wire pf_valid, pf_illegal; + // }}} + // Memory + // {{{ + wire clear_dcache, mem_ce, bus_lock; + wire [2:0] mem_op; + wire [31:0] mem_cpu_addr, mem_lock_pc; + wire [31:0] mem_wdata; + wire [4:0] mem_reg; + wire mem_busy, mem_rdbusy, mem_pipe_stalled, mem_valid, + mem_bus_err; + wire [4:0] mem_wreg; + wire [31:0] mem_result; + // }}} + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Debug signal handling + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + // + // Write signaling + // {{{ + skidbuffer #( + // {{{ + .OPT_OUTREG(0), + .OPT_LOWPOWER(OPT_LOWPOWER), + .DW(C_DBG_ADDR_WIDTH-DBGLSB) + // }}} + ) dbgawskd( + // {{{ + .i_clk(S_AXI_ACLK), .i_reset(!S_AXI_ARESETN), + .i_valid(S_DBG_AWVALID), + .o_ready(S_DBG_AWREADY), + .i_data(S_DBG_AWADDR[C_DBG_ADDR_WIDTH-1:DBGLSB]), + .o_valid(awskd_valid), .i_ready(dbg_write_ready), + .o_data(awskd_addr) + // }}} + ); + + skidbuffer #( + // {{{ + .OPT_OUTREG(0), + .OPT_LOWPOWER(OPT_LOWPOWER), + .DW(C_DBG_DATA_WIDTH+C_DBG_DATA_WIDTH/8) + // }}} + ) dbgwskd( + // {{{ + .i_clk(S_AXI_ACLK), .i_reset(!S_AXI_ARESETN), + .i_valid(S_DBG_WVALID), + .o_ready(S_DBG_WREADY), + .i_data({ S_DBG_WDATA, S_DBG_WSTRB }), + .o_valid(wskd_valid), .i_ready(dbg_write_ready), + .o_data({ wskd_data, wskd_strb }) + // }}} + ); + + assign dbg_write_ready = awskd_valid && wskd_valid + && ((wskd_strb==0) || awskd_addr[5] || !cpu_dbg_stall + || !dbg_write_valid) + && (!S_DBG_BVALID || S_DBG_BREADY); + + // dbg_write_valid + // {{{ + initial dbg_write_valid = 0; + always @(posedge S_AXI_ACLK) + if (!S_AXI_ARESETN) + dbg_write_valid <= 1'b0; + else if (!dbg_write_valid || !cpu_dbg_stall) + begin + dbg_write_valid <= dbg_write_ready && (|wskd_strb) && !awskd_addr[5]; + end + // }}} + + // dbg_write_reg + // {{{ + always @(posedge S_AXI_ACLK) + if (!dbg_write_valid || !cpu_dbg_stall) + begin + dbg_write_reg <= awskd_addr[4:0]; + if (OPT_LOWPOWER && !dbg_write_valid) + dbg_write_reg <= 0; + end + // }}} + + // dbg_write_data + // {{{ + always @(posedge S_AXI_ACLK) + if (!dbg_write_valid || !cpu_dbg_stall) + begin + dbg_write_data <= wskd_data; + if (OPT_LOWPOWER && !dbg_write_ready) + dbg_write_data <= 0; + end + // }}} + + // S_DBG_BVALID + // {{{ + initial S_DBG_BVALID = 1'b0; + always @(posedge S_AXI_ACLK) + if (!S_AXI_ARESETN) + S_DBG_BVALID <= 1'b0; + else if (dbg_write_ready) + S_DBG_BVALID <= 1'b1; + else if (S_DBG_BREADY) + S_DBG_BVALID <= 1'b0; + // }}} + + // S_DBG_BRESP + // {{{ + assign S_DBG_BRESP = 2'b00; + // }}} + + // }}} + + // + // Read signaling + // {{{ + + skidbuffer #( + // {{{ + .OPT_OUTREG(0), + .OPT_LOWPOWER(OPT_LOWPOWER), + .DW(C_DBG_ADDR_WIDTH-DBGLSB) + // }}} + ) dbgarskd( + // {{{ + .i_clk(S_AXI_ACLK), .i_reset(!S_AXI_ARESETN), + .i_valid(S_DBG_ARVALID), + .o_ready(S_DBG_ARREADY), + .i_data(S_DBG_ARADDR[C_DBG_ADDR_WIDTH-1:DBGLSB]), + .o_valid(arskd_valid), .i_ready(dbg_read_ready), + .o_data(arskd_addr) + // }}} + ); + + assign dbg_read_ready = arskd_valid && !dbg_read_valid + && (!S_DBG_RVALID || S_DBG_RREADY); + + assign dbg_read_reg = (OPT_LOWPOWER && !dbg_read_ready) + ? 5'h0 : arskd_addr[4:0]; + + // dbg_read_valid + // {{{ + initial dbg_read_valid = 0; + always @(posedge S_AXI_ACLK) + if (!S_AXI_ARESETN) + dbg_read_valid <= 0; + else + dbg_read_valid <= dbg_read_ready && arskd_addr[5]; + // }}} + + // S_DBG_RVALID + // {{{ + initial S_DBG_RVALID = 0; + always @(posedge S_AXI_ACLK) + if (!S_AXI_ARESETN) + S_DBG_RVALID <= 0; + else if (!S_DBG_RVALID || S_DBG_RREADY) + S_DBG_RVALID <= (dbg_read_ready && !arskd_addr[5]) + || dbg_read_valid; + // }}} + + // S_DBG_RDATA + // {{{ + initial S_DBG_RDATA = 0; + always @(posedge S_AXI_ACLK) + if (OPT_LOWPOWER && !S_AXI_ARESETN) + S_DBG_RDATA <= 0; + else if (!S_DBG_RVALID || S_DBG_RREADY) + begin + // {{{ + if (dbg_read_valid) + S_DBG_RDATA <= dbg_read_data; + else + S_DBG_RDATA <= cpu_status; + + if (OPT_LOWPOWER && !dbg_read_valid && !dbg_read_ready) + S_DBG_RDATA <= 0; + // }}} + end + // }}} + + assign S_DBG_RRESP = 2'b00; + // }}} + + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Reset, halt, clear-cache, and step controls + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + assign dbg_cmd_write = (dbg_write_ready && awskd_addr[5]); + + // + // Always start us off with an initial reset + // {{{ + generate if (RESET_DURATION > 0) + begin : INITIAL_RESET_HOLD + // {{{ + reg [$clog2(RESET_DURATION)-1:0] reset_counter; + + initial reset_counter = RESET_DURATION; + always @(posedge S_AXI_ACLK) + if (!S_AXI_ARESETN) + reset_counter <= RESET_DURATION; + else if (reset_counter > 0) + reset_counter <= reset_counter - 1; + + initial reset_hold = 1; + always @(posedge S_AXI_ACLK) + if (!S_AXI_ARESETN) + reset_hold <= 1; + else + reset_hold <= (reset_counter > 1); +`ifdef FORMAL + always @(*) + assert(reset_hold == (reset_counter != 0)); +`endif + // }}} + end else begin + + always @(*) + reset_hold = 0; + + end endgenerate + + // cmd_reset + // {{{ + initial cmd_reset = 1'b1; + always @(posedge S_AXI_ACLK) + if (!S_AXI_ARESETN) + cmd_reset <= 1'b1; + else if (reset_hold) + cmd_reset <= 1'b1; + else if (cpu_break && !START_HALTED) + cmd_reset <= 1'b1; + else + cmd_reset <= (dbg_cmd_write && wskd_strb[0] + && wskd_data[RESET_BIT]); + // }}} + // }}} + + // cmd_halt + // {{{ + always @(posedge S_AXI_ACLK) + if (!S_AXI_ARESETN) + cmd_halt <= START_HALTED; + else if (cmd_reset && START_HALTED) + cmd_halt <= START_HALTED; + else begin + // {{{ + if (!dbg_write_valid && !cpu_dbg_stall && dbg_cmd_write + && wskd_strb[1] && (!wskd_data[HALT_BIT] + || wskd_data[STEP_BIT])) + cmd_halt <= 1'b0; + + // Reasons to halt + + // 1. Halt on any unhandled CPU exception. The cause of the + // exception must be cured before we can (re)start. + // If the CPU is configured to start immediately on power + // up, we leave it to reset on any exception instead. + if (cpu_break && START_HALTED) + cmd_halt <= 1'b1; + + // 2. Halt on any user request to halt. (Only valid if the + // STEP bit isn't also set) + + if (dbg_cmd_write && wskd_strb[1] && wskd_data[HALT_BIT] + && !wskd_data[STEP_BIT]) + cmd_halt <= 1'b1; + + // 3. Halt on any user request to write to a CPU register + if (dbg_write_ready && !awskd_addr[5] && wskd_strb != 0) + cmd_halt <= 1'b1; + + // 4. Halt following any step command + if (cmd_step) + cmd_halt <= 1'b1; + + // 4. Halt following any clear cache + if (cmd_clear_cache) + cmd_halt <= 1'b1; + + // 5. Halt on any clear cache bit--independent of any step bit + if (dbg_cmd_write && wskd_strb[1] && wskd_data[CLEAR_CACHE_BIT]) + cmd_halt <= 1'b1; + // }}} + end + // }}} + + // cmd_clear_cache + // {{{ + initial cmd_clear_cache = 1'b0; + always @(posedge S_AXI_ACLK) + if (!S_AXI_ARESETN || cmd_reset) + cmd_clear_cache <= 1'b0; + else if (dbg_cmd_write && wskd_data[CLEAR_CACHE_BIT] + && wskd_data[HALT_BIT] && wskd_strb[1]) + cmd_clear_cache <= 1'b1; + else if (cmd_halt && !cpu_dbg_stall) + cmd_clear_cache <= 1'b0; + // }}} + + // cmd_step + // {{{ + initial cmd_step = 1'b0; + always @(posedge S_AXI_ACLK) + if (!S_AXI_ARESETN) + cmd_step <= 1'b0; + else if (dbg_cmd_write && wskd_data[STEP_BIT] && wskd_strb[1]) + cmd_step <= 1'b1; + else if (!cpu_dbg_stall) + cmd_step <= 1'b0; + // }}} + + // cpu_status + // {{{ + // 0x10000 -> cpu_gie + // 0x08000 -> (Reserved/unused) + // 0x04000 -> cpu_break + // 0x02000 -> cpu_gie + // 0x01000 -> cpu_sleep + // 0x00800 -> cmd_clear_cache + // 0x00400 -> cmd_halt + // 0x00200 -> cmd_stall + // 0x00100 -> cmd_step + // 0x00080 -> Interrupt pending + // 0x00040 -> Reset + // 0x0003f -> Unused (old register address) + assign cpu_status = { 8'h0, 7'h0, i_interrupt, + cpu_break, cpu_dbg_cc, + 1'b0, cmd_halt, !cpu_dbg_stall, 1'b0, + i_interrupt, cmd_reset, 6'h0 }; + // }}} + + // }}} + //////////////////////////////////////////////////////////////////////// + // + // The ZipCPU Core + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // +`ifdef FORMAL + // {{{ + (* anyseq *) reg f_cpu_halted, f_cpu_data, f_cpu_stall, + f_cpu_break; + (* anyseq *) reg [2:0] f_cpu_dbg_cc; + (* anyseq *) reg [2:0] f_cpu_dbg_read_data; + + assign cpu_dbg_stall = f_cpu_stall; + assign cpu_break = f_cpu_break; + assign cpu_dbg_cc = f_cpu_dbg_cc; + assign dbg_read_data = f_cpu_dbg_read_data; + + fdebug #( + // {{{ + .OPT_DISTRIBUTED_RAM(1'b1) + // }}} + ) fdbg ( + // {{{ + .i_clk(S_AXI_ACLK), + .i_reset(!S_AXI_ARESETN), + .i_cpu_reset(cmd_reset), + .i_halt(cmd_halt), + .i_halted(f_cpu_halted), + .i_clear_cache(cmd_clear_cache), + .i_dbg_we(dbg_write_valid), + .i_dbg_reg(dbg_write_reg), + .i_dbg_data(dbg_write_data), + .i_dbg_stall(cpu_dbg_stall), + .i_dbg_break(cpu_break), + .i_dbg_cc(cpu_dbg_cc) + // }}} + ); + // }}} +`else + zipcore #( + // {{{ + .RESET_ADDRESS(RESET_ADDRESS), + .ADDRESS_WIDTH(C_AXI_ADDR_WIDTH-2), + .IMPLEMENT_MPY(IMPLEMENT_MPY), + .IMPLEMENT_DIVIDE(IMPLEMENT_DIVIDE), + .IMPLEMENT_FPU(IMPLEMENT_FPU), + .OPT_EARLY_BRANCHING(EARLY_BRANCHING), + .OPT_CIS(OPT_CIS), + // .OPT_NO_USERMODE(OPT_NO_USERMODE), + .OPT_PIPELINED(OPT_PIPELINED), + .OPT_PIPELINED_BUS_ACCESS(OPT_PIPELINED_BUS_ACCESS), + // localparam [0:0] OPT_MEMPIPE = OPT_PIPELINED_BUS_ACCESS; + .IMPLEMENT_LOCK(IMPLEMENT_LOCK), + .OPT_DCACHE(OPT_DCACHE), + // localparam [0:0] OPT_LOCK=(IMPLEMENT_LOCK)&&(OPT_PIPELINED); + // parameter [0:0] WITH_LOCAL_BUS = 1'b1; + .OPT_GATE_CLOCK(1'b0) +`ifdef FORMAL + , .F_LGDEPTH(F_LGDEPTH) +`endif + // }}} + ) core ( + // {{{ + .i_clk(S_AXI_ACLK), .i_reset(cmd_reset), + .i_interrupt(i_interrupt), + // Debug interface + // {{{ + .i_halt(cmd_halt), .i_clear_cache(cmd_clear_cache), + .i_dbg_wreg(dbg_write_reg), .i_dbg_we(dbg_write_valid), + .i_dbg_data(dbg_write_data), .i_dbg_rreg(dbg_read_reg), + .o_dbg_stall(cpu_dbg_stall), .o_dbg_reg(dbg_read_data), + .o_dbg_cc(cpu_dbg_cc), .o_break(cpu_break), + // }}} + // Instruction fetch interface + // {{{ + .o_pf_new_pc(pf_new_pc), .o_clear_icache(clear_icache), + .o_pf_ready(pf_ready), + .o_pf_request_address(pf_request_address), + .i_pf_valid(pf_valid), + .i_pf_illegal(pf_illegal), + .i_pf_instruction(pf_instruction), + .i_pf_instruction_pc(pf_instruction_pc), + // }}} + // Memory unit interface + // {{{ + .o_clear_dcache(clear_dcache), .o_mem_ce(mem_ce), + .o_bus_lock(bus_lock), .o_mem_op(mem_op), + .o_mem_addr(mem_cpu_addr), + .o_mem_data(mem_wdata), + .o_mem_lock_pc(mem_lock_pc), + .o_mem_reg(mem_reg), + .i_mem_busy(mem_busy), + .i_mem_rdbusy(mem_rdbusy), + .i_mem_pipe_stalled(mem_pipe_stalled), + .i_mem_valid(mem_valid), + .i_bus_err(mem_bus_err), + .i_mem_wreg(mem_wreg), + .i_mem_result(mem_result), + // }}} + // Accounting/CPU usage interface + .o_op_stall(o_op_stall), .o_pf_stall(o_pf_stall), + .o_i_count(o_i_count), + .o_clken(cpu_clken), + .o_debug(cpu_debug) + // }}} + ); +`endif + // }}} + // o_debug -- the debugging bus input + // {{{ +`ifdef DEBUG_SCOPE + assign o_debug = cpu_debug; +`else + // Verilator lint_off UNUSED + wire dbg_unused; + assign dbg_unused = &{ 1'b0, cpu_debug }; +`endif + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Instruction Fetch + // {{{ + //////////////////////////////////////////////////////////////////////// + // + +`ifndef FORMAL + generate if (LGICACHE > 0) + begin : INSN_CACHE + + axiicache #( + // {{{ + .C_AXI_ADDR_WIDTH(C_AXI_ADDR_WIDTH), + .C_AXI_DATA_WIDTH(C_AXI_DATA_WIDTH), + .AXI_ID(INSN_ID), + .LGCACHESZ(LGICACHE), + .LGLINESZ(LGILINESZ), + .SWAP_ENDIANNESS(SWAP_ENDIANNESS) + // }}} + ) pf ( + // {{{ + .S_AXI_ACLK(S_AXI_ACLK), .S_AXI_ARESETN(S_AXI_ARESETN), + // CPU signals + // {{{ + .i_cpu_reset(cmd_reset), + .i_new_pc(pf_new_pc), + .i_clear_cache(clear_icache), + .i_ready(pf_ready), + .i_pc(pf_request_address), + .o_insn(pf_instruction), + .o_pc(pf_instruction_pc), + .o_valid(pf_valid), + .o_illegal(pf_illegal), + // }}} + // AXI4 (full) bus signals + // {{{ + .M_AXI_ARVALID(M_INSN_ARVALID), + .M_AXI_ARREADY(M_INSN_ARREADY), + .M_AXI_ARID( M_INSN_ARID), + .M_AXI_ARADDR( M_INSN_ARADDR), + .M_AXI_ARLEN( M_INSN_ARLEN), + .M_AXI_ARSIZE( M_INSN_ARSIZE), + .M_AXI_ARBURST(M_INSN_ARBURST), + .M_AXI_ARLOCK( M_INSN_ARLOCK), + .M_AXI_ARCACHE(M_INSN_ARCACHE), + .M_AXI_ARPROT( M_INSN_ARPROT), + .M_AXI_ARQOS( M_INSN_ARQOS), + // + .M_AXI_RVALID(M_INSN_RVALID), + .M_AXI_RREADY(M_INSN_RREADY), + .M_AXI_RID( M_INSN_RID), + .M_AXI_RDATA( M_INSN_RDATA), + .M_AXI_RLAST( M_INSN_RLAST), + .M_AXI_RRESP( M_INSN_RRESP) + // }}} + // }}} + ); + + end else begin : AXILFETCH + + axilfetch #( + // {{{ + .C_AXI_ADDR_WIDTH(C_AXI_ADDR_WIDTH), + .C_AXI_DATA_WIDTH(C_AXI_DATA_WIDTH), + .FETCH_LIMIT(FETCH_LIMIT), + .SWAP_ENDIANNESS(SWAP_ENDIANNESS) + // }}} + ) pf ( + // {{{ + .S_AXI_ACLK(S_AXI_ACLK), .S_AXI_ARESETN(S_AXI_ARESETN), + // CPU signals + // {{{ + .i_cpu_reset(cmd_reset), + .i_new_pc(pf_new_pc), + .i_clear_cache(clear_icache), + .i_ready(pf_ready), + .i_pc(pf_request_address), + .o_insn(pf_instruction), + .o_pc(pf_instruction_pc), + .o_valid(pf_valid), + .o_illegal(pf_illegal), + // }}} + // AXI-lite bus signals + // {{{ + .M_AXI_ARVALID(M_INSN_ARVALID), + .M_AXI_ARREADY(M_INSN_ARREADY), + .M_AXI_ARADDR(M_INSN_ARADDR), + .M_AXI_ARPROT(M_INSN_ARPROT), + // + .M_AXI_RVALID(M_INSN_RVALID), + .M_AXI_RREADY(M_INSN_RREADY), + .M_AXI_RDATA(M_INSN_RDATA), + .M_AXI_RRESP(M_INSN_RRESP) + // }}} + // }}} + ); + + assign M_INSN_ARID = INSN_ID; + // ARADDR + assign M_INSN_ARLEN = 0; + assign M_INSN_ARSIZE = AXILSB[2:0]; + assign M_INSN_ARBURST = 2'b01; + assign M_INSN_ARLOCK = 1'b0; + assign M_INSN_ARCACHE = 4'h3; + // PROT + assign M_INSN_ARQOS = 4'h0; + + end endgenerate +`endif + + // Assign values to the (unused) M_INSN_* write ports + // {{{ + assign M_INSN_AWVALID = 0; + assign M_INSN_AWVALID = 0; + assign M_INSN_AWID = INSN_ID; + assign M_INSN_AWADDR = 0; + assign M_INSN_AWLEN = 0; + assign M_INSN_AWSIZE = 0; + assign M_INSN_AWBURST = 0; + assign M_INSN_AWLOCK = 0; + assign M_INSN_AWCACHE = 0; + assign M_INSN_AWPROT = 0; + assign M_INSN_AWQOS = 0; + // + assign M_INSN_WVALID = 0; + assign M_INSN_WDATA = 0; + assign M_INSN_WSTRB = 0; + assign M_INSN_WLAST = 0; + // + assign M_INSN_BREADY = 1'b1; + // + // }}} + + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Memory Unit + // {{{ + //////////////////////////////////////////////////////////////////////// + // +`ifndef FORMAL + generate if (OPT_DCACHE) + begin : DATA_CACHE + + axidcache #( + // {{{ + .C_AXI_ADDR_WIDTH(C_AXI_ADDR_WIDTH), + .C_AXI_DATA_WIDTH(C_AXI_DATA_WIDTH), + .C_AXI_ID_WIDTH(C_AXI_ID_WIDTH), + .AXI_ID(DATA_ID), + .LGCACHELEN(OPT_LGDCACHE), + .LGNLINES(OPT_LGDCACHE-$clog2(C_AXI_DATA_WIDTH/8)-OPT_LGDLINESZ), + // .SWAP_ENDIANNESS(SWAP_ENDIANNESS), + // .SWAP_WSTRB(1'b0), + // .OPT_SIGN_EXTEND(OPT_SIGN_EXTEND), + .OPT_LOWPOWER(OPT_LOWPOWER) + // .OPT_LOCAL_BUS(WITH_LOCAL_BUS), + // .OPT_PIPE(OPT_MEMPIPE), + // .OPT_LOCK(IMPLEMENT_LOCK) +// `ifdef FORMAL + // Used with OPT_PIPE, not yet enabled + // , .OPT_FIFO_DEPTH(2) + // , .F_LGDEPTH(F_LGDEPTH) +// `endif + // }}} + ) mem( + // {{{ + .S_AXI_ACLK(S_AXI_ACLK), .S_AXI_ARESETN(S_AXI_ARESETN), + .i_cpu_reset(cmd_reset), .i_clear(clear_dcache), + // CPU interface + // {{{ + .i_pipe_stb(mem_ce), + .i_lock(bus_lock), + .i_op(mem_op), + .i_addr(mem_cpu_addr), + .i_data(mem_wdata), + .i_oreg(mem_reg), + .o_busy(mem_busy), + .o_pipe_stalled(mem_pipe_stalled), + .o_rdbusy(mem_rdbusy), + .o_valid(mem_valid), + .o_err(mem_bus_err), + .o_wreg(mem_wreg), + .o_data(mem_result), + // }}} + // Write interface + // {{{ + .M_AXI_AWVALID(M_DATA_AWVALID), + .M_AXI_AWREADY(M_DATA_AWREADY), + .M_AXI_AWID( M_DATA_AWID), + .M_AXI_AWADDR( M_DATA_AWADDR), + .M_AXI_AWLEN( M_DATA_AWLEN), + .M_AXI_AWSIZE( M_DATA_AWSIZE), + .M_AXI_AWBURST(M_DATA_AWBURST), + .M_AXI_AWLOCK( M_DATA_AWLOCK), + .M_AXI_AWCACHE(M_DATA_AWCACHE), + .M_AXI_AWPROT( M_DATA_AWPROT), + .M_AXI_AWQOS( M_DATA_AWQOS), + // + .M_AXI_WVALID(M_DATA_WVALID), + .M_AXI_WREADY(M_DATA_WREADY), + .M_AXI_WDATA(M_DATA_WDATA), + .M_AXI_WSTRB(M_DATA_WSTRB), + .M_AXI_WLAST(M_DATA_WLAST), + // + .M_AXI_BVALID(M_DATA_BVALID), + .M_AXI_BREADY(M_DATA_BREADY), + .M_AXI_BID( M_DATA_BID), + .M_AXI_BRESP( M_DATA_BRESP), + // }}} + // Read interface + // {{{ + .M_AXI_ARVALID(M_DATA_ARVALID), + .M_AXI_ARREADY(M_DATA_ARREADY), + .M_AXI_ARID( M_DATA_ARID), + .M_AXI_ARADDR( M_DATA_ARADDR), + .M_AXI_ARLEN( M_DATA_ARLEN), + .M_AXI_ARSIZE( M_DATA_ARSIZE), + .M_AXI_ARBURST(M_DATA_ARBURST), + .M_AXI_ARLOCK( M_DATA_ARLOCK), + .M_AXI_ARCACHE(M_DATA_ARCACHE), + .M_AXI_ARPROT( M_DATA_ARPROT), + .M_AXI_ARQOS( M_DATA_ARQOS), + // + .M_AXI_RVALID(M_DATA_RVALID), + .M_AXI_RREADY(M_DATA_RREADY), + .M_AXI_RID( M_DATA_RID), + .M_AXI_RDATA( M_DATA_RDATA), + .M_AXI_RLAST( M_DATA_RLAST), + .M_AXI_RRESP( M_DATA_RRESP) + // }}} + // }}} + ); + + end else if (OPT_PIPELINED_BUS_ACCESS) + begin : PIPELINED_MEM + + axipipe #( + // {{{ + .C_AXI_ADDR_WIDTH(C_AXI_ADDR_WIDTH), + .C_AXI_DATA_WIDTH(C_AXI_DATA_WIDTH), + .C_AXI_ID_WIDTH(C_AXI_ID_WIDTH), + .AXI_ID(DATA_ID), + .OPT_LOCK(IMPLEMENT_LOCK), + .OPT_ALIGNMENT_ERR(OPT_ALIGNMENT_ERR), + .OPT_LOWPOWER(OPT_LOWPOWER) + // .OPT_SIGN_EXTEND(OPT_SIGN_EXTEND) + // }}} + ) domem( + // {{{ + .S_AXI_ACLK(S_AXI_ACLK), .S_AXI_ARESETN(S_AXI_ARESETN), + .i_cpu_reset(cmd_reset), + // CPU interface + // {{{ + .i_stb(mem_ce), + .i_lock(bus_lock), + .i_op(mem_op), + .i_addr(mem_cpu_addr), + .i_restart_pc(mem_lock_pc), + .i_data(mem_wdata), + .i_oreg(mem_reg), + .o_busy(mem_busy), + .o_pipe_stalled(mem_pipe_stalled), + .o_rdbusy(mem_rdbusy), + .o_valid(mem_valid), + .o_err(mem_bus_err), + .o_wreg(mem_wreg), + .o_result(mem_result), + // }}} + // AXI + // Write interface + // {{{ + .M_AXI_AWVALID(M_DATA_AWVALID), + .M_AXI_AWREADY(M_DATA_AWREADY), + .M_AXI_AWID( M_DATA_AWID), + .M_AXI_AWADDR( M_DATA_AWADDR), + .M_AXI_AWLEN( M_DATA_AWLEN), + .M_AXI_AWSIZE( M_DATA_AWSIZE), + .M_AXI_AWBURST(M_DATA_AWBURST), + .M_AXI_AWLOCK( M_DATA_AWLOCK), + .M_AXI_AWCACHE(M_DATA_AWCACHE), + .M_AXI_AWPROT( M_DATA_AWPROT), + .M_AXI_AWQOS( M_DATA_AWQOS), + // + .M_AXI_WVALID(M_DATA_WVALID), + .M_AXI_WREADY(M_DATA_WREADY), + .M_AXI_WDATA(M_DATA_WDATA), + .M_AXI_WSTRB(M_DATA_WSTRB), + .M_AXI_WLAST(M_DATA_WLAST), + // + .M_AXI_BVALID(M_DATA_BVALID), + .M_AXI_BREADY(M_DATA_BREADY), + .M_AXI_BID( M_DATA_BID), + .M_AXI_BRESP( M_DATA_BRESP), + // }}} + // Read interface + // {{{ + .M_AXI_ARVALID(M_DATA_ARVALID), + .M_AXI_ARREADY(M_DATA_ARREADY), + .M_AXI_ARID( M_DATA_ARID), + .M_AXI_ARADDR( M_DATA_ARADDR), + .M_AXI_ARLEN( M_DATA_ARLEN), + .M_AXI_ARSIZE( M_DATA_ARSIZE), + .M_AXI_ARBURST(M_DATA_ARBURST), + .M_AXI_ARLOCK( M_DATA_ARLOCK), + .M_AXI_ARCACHE(M_DATA_ARCACHE), + .M_AXI_ARPROT( M_DATA_ARPROT), + .M_AXI_ARQOS( M_DATA_ARQOS), + // + .M_AXI_RVALID(M_DATA_RVALID), + .M_AXI_RREADY(M_DATA_RREADY), + .M_AXI_RID( M_DATA_RID), + .M_AXI_RDATA( M_DATA_RDATA), + .M_AXI_RLAST( M_DATA_RLAST), + .M_AXI_RRESP( M_DATA_RRESP) + // }}} + // }}} + ); + + // Make Verilator happy + // {{{ + // Verilator lint_off UNUSED + wire unused_pipe; + assign unused_pipe = &{ 1'b0, clear_dcache }; + // Verilator lint_on UNUSED + // }}} + end else begin : BARE_MEM + + axiops #( + // {{{ + .C_AXI_ADDR_WIDTH(C_AXI_ADDR_WIDTH), + .C_AXI_DATA_WIDTH(C_AXI_DATA_WIDTH), + .C_AXI_ID_WIDTH(C_AXI_ID_WIDTH), + .AXI_ID(DATA_ID), + .SWAP_ENDIANNESS(SWAP_ENDIANNESS), + .SWAP_WSTRB(1'b0), + // .OPT_SIGN_EXTEND(OPT_SIGN_EXTEND), + .OPT_LOCK(IMPLEMENT_LOCK), + .OPT_ALIGNMENT_ERR(OPT_ALIGNMENT_ERR), + .OPT_LOWPOWER(OPT_LOWPOWER) + // }}} + ) domem( + // {{{ + .S_AXI_ACLK(S_AXI_ACLK), .S_AXI_ARESETN(S_AXI_ARESETN), + .i_cpu_reset(cmd_reset), + // CPU interface + // {{{ + .i_stb(mem_ce), + .i_lock(bus_lock), + .i_op(mem_op), + .i_addr(mem_cpu_addr), + .i_restart_pc(mem_lock_pc), + .i_data(mem_wdata), + .i_oreg(mem_reg), + .o_busy(mem_busy), + .o_rdbusy(mem_rdbusy), + .o_valid(mem_valid), + .o_err(mem_bus_err), + .o_wreg(mem_wreg), + .o_result(mem_result), + // }}} + // AXI4 (full) + // Write interface + // {{{ + .M_AXI_AWVALID(M_DATA_AWVALID), + .M_AXI_AWREADY(M_DATA_AWREADY), + .M_AXI_AWID( M_DATA_AWID), + .M_AXI_AWADDR( M_DATA_AWADDR), + .M_AXI_AWLEN( M_DATA_AWLEN), + .M_AXI_AWSIZE( M_DATA_AWSIZE), + .M_AXI_AWBURST(M_DATA_AWBURST), + .M_AXI_AWLOCK( M_DATA_AWLOCK), + .M_AXI_AWCACHE(M_DATA_AWCACHE), + .M_AXI_AWPROT( M_DATA_AWPROT), + .M_AXI_AWQOS( M_DATA_AWQOS), + // + .M_AXI_WVALID(M_DATA_WVALID), + .M_AXI_WREADY(M_DATA_WREADY), + .M_AXI_WDATA(M_DATA_WDATA), + .M_AXI_WSTRB(M_DATA_WSTRB), + .M_AXI_WLAST(M_DATA_WLAST), + // + .M_AXI_BVALID(M_DATA_BVALID), + .M_AXI_BREADY(M_DATA_BREADY), + .M_AXI_BID( M_DATA_BID), + .M_AXI_BRESP( M_DATA_BRESP), + // }}} + // Read interface + // {{{ + .M_AXI_ARVALID(M_DATA_ARVALID), + .M_AXI_ARREADY(M_DATA_ARREADY), + .M_AXI_ARID( M_DATA_ARID), + .M_AXI_ARADDR( M_DATA_ARADDR), + .M_AXI_ARLEN( M_DATA_ARLEN), + .M_AXI_ARSIZE( M_DATA_ARSIZE), + .M_AXI_ARBURST(M_DATA_ARBURST), + .M_AXI_ARLOCK( M_DATA_ARLOCK), + .M_AXI_ARCACHE(M_DATA_ARCACHE), + .M_AXI_ARPROT( M_DATA_ARPROT), + .M_AXI_ARQOS( M_DATA_ARQOS), + // + .M_AXI_RVALID(M_DATA_RVALID), + .M_AXI_RREADY(M_DATA_RREADY), + .M_AXI_RID( M_DATA_RID), + .M_AXI_RDATA( M_DATA_RDATA), + .M_AXI_RLAST( M_DATA_RLAST), + .M_AXI_RRESP( M_DATA_RRESP) + // }}} + // }}} + ); + + assign mem_pipe_stalled = mem_busy; + + // Make Verilator happy + // {{{ + // Verilator lint_off UNUSED + wire unused_bare; + assign unused_bare = &{ 1'b0, clear_dcache }; + // Verilator lint_on UNUSED + // }}} + end endgenerate +`endif + // }}} + // Make Verilator happy + // {{{ + // Verilator lint_off UNUSED + wire unused; + assign unused = &{ 1'b0, cpu_clken, + S_DBG_AWADDR[DBGLSB-1:0], + S_DBG_ARADDR[DBGLSB-1:0], + S_DBG_ARPROT, S_DBG_AWPROT, + M_INSN_AWREADY, M_INSN_WREADY, + M_INSN_BVALID, M_INSN_BID, M_INSN_BRESP, + mem_lock_pc + }; + // Verilator lint_on UNUSED + // }}} +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal properties +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +`ifdef FORMAL + wire [F_LGDEPTH-1:0] faxil_rd_outstanding, + faxil_wr_outstanding, faxil_awr_outstanding; + + //////////////////////////////////////////////////////////////////////// + // + // AXI-lite debug interface + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + + faxil_slave #( + // {{{ + .C_AXI_DATA_WIDTH(C_DBG_DATA_WIDTH), + .C_AXI_ADDR_WIDTH(C_DBG_ADDR_WIDTH), + .F_LGDEPTH(F_LGDEPTH), + .F_AXI_MAXWAIT(0), + .F_AXI_MAXDELAY(0) + // }}} + ) faxil ( + // {{{ + .i_clk(S_AXI_ACLK), .i_axi_reset_n(S_AXI_ARESETN), + // AXI-lite debug writes + // {{{ + .i_axi_awvalid(S_DBG_AWVALID), + .i_axi_awready(S_DBG_AWREADY), + .i_axi_awaddr(S_DBG_AWADDR), + .i_axi_awprot(S_DBG_AWPROT), + // + .i_axi_wvalid(S_DBG_WVALID), + .i_axi_wready(S_DBG_WREADY), + .i_axi_wdata(S_DBG_WDATA), + .i_axi_wstrb(S_DBG_WSTRB), + // + .i_axi_bvalid(S_DBG_BVALID), + .i_axi_bready(S_DBG_BREADY), + .i_axi_bresp(S_DBG_BRESP), + // }}} + // AXI-lite debug reads + // {{{ + .i_axi_arvalid(S_DBG_ARVALID), + .i_axi_arready(S_DBG_ARREADY), + .i_axi_araddr(S_DBG_ARADDR), + .i_axi_arprot(S_DBG_ARPROT), + // + .i_axi_rvalid(S_DBG_RVALID), + .i_axi_rready(S_DBG_RREADY), + .i_axi_rdata(S_DBG_RDATA), + .i_axi_rresp(S_DBG_RRESP), + // }}} + // Induction + // {{{ + .f_axi_rd_outstanding(faxil_rd_outstanding), + .f_axi_wr_outstanding(faxil_wr_outstanding), + .f_axi_awr_outstanding(faxil_awr_outstanding) + // }}} + // }}} + ); + + always @(*) + if (S_AXI_ARESETN) + begin + assert(faxil_rd_outstanding == (S_DBG_ARREADY ? 0:1) + +(dbg_read_valid ? 1:0) + (S_DBG_RVALID ? 1:0)); + + assert(!dbg_read_valid || !S_DBG_RVALID); + + assert(faxil_wr_outstanding == (S_DBG_WREADY ? 0:1) + +(S_DBG_BVALID ? 1:0)); + + assert(faxil_awr_outstanding == (S_DBG_AWREADY ? 0:1) + +(S_DBG_BVALID ? 1:0)); + end + + // }}} + //////////////////////////////////////////////////////////////////////// + // + // CPU's debug interface + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + // Captured above + + // }}} +`endif +// }}} +endmodule diff --git a/rtl/cpu/zipaxil.v b/rtl/cpu/zipaxil.v new file mode 100644 index 0000000..c08c70d --- /dev/null +++ b/rtl/cpu/zipaxil.v @@ -0,0 +1,1049 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Filename: zipaxil.v +// {{{ +// Project: Zip CPU -- a small, lightweight, RISC CPU soft core +// +// Purpose: A potential top level module holding the core of the Zip CPU +// together--this one with AXI-lite instruction, data, and debug +// interfaces. In general, the Zip CPU is designed to be as simple as +// possible. (actual implementation aside ...) The instruction set is +// about as RISC as you can get, with only 26 instruction types currently +// supported. (There are still 8-instruction Op-Codes reserved for +// floating point, and 5 which can be used for transactions not requiring +// registers.) Please see the accompanying spec.pdf file for a description +// of these instructions. +// +// All instructions are 32-bits wide. All bus accesses, both address and +// data, are 32-bits over a wishbone bus. +// +// The Zip CPU is fully pipelined with the following pipeline stages: +// +// 1. Prefetch, returns the instruction from memory. +// +// 2. Instruction Decode +// +// 3. Read Operands +// +// 4. Apply Instruction +// +// 4. Write-back Results +// +// Further information about the inner workings of this CPU, such as +// what causes pipeline stalls, may be found in the spec.pdf file. (The +// documentation within this file had become out of date and out of sync +// with the spec.pdf, so look to the spec.pdf for accurate and up to date +// information.) +// +// Creator: Dan Gisselquist, Ph.D. +// Gisselquist Technology, LLC +// +//////////////////////////////////////////////////////////////////////////////// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ +// This program is free software (firmware): 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 MERCHANTIBILITY 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. (It's in the $(ROOT)/doc directory. Run make with no +// target there if the PDF file isn't present.) If not, see +// for a copy. +// }}} +// License: GPL, v3, as defined and found on www.gnu.org, +// {{{ +// http://www.gnu.org/licenses/gpl.html +// +//////////////////////////////////////////////////////////////////////////////// +// +// +`default_nettype none +// +`include "cpudefs.v" +// +// }}} +module zipaxil #( + // {{{ + parameter C_DBG_ADDR_WIDTH = 8, + localparam C_DBG_DATA_WIDTH = 32, + localparam DBGLSB = $clog2(C_DBG_DATA_WIDTH/8), + parameter C_AXI_ADDR_WIDTH = 32, + parameter C_AXI_DATA_WIDTH = 32, + localparam ADDRESS_WIDTH = C_AXI_ADDR_WIDTH, + parameter [C_AXI_ADDR_WIDTH-1:0] RESET_ADDRESS=32'h010_0000, + parameter [0:0] START_HALTED = 1'b0, +`ifdef OPT_MULTIPLY + parameter IMPLEMENT_MPY = `OPT_MULTIPLY, +`else + parameter IMPLEMENT_MPY = 0, +`endif +`ifdef OPT_DIVIDE + parameter [0:0] IMPLEMENT_DIVIDE = 1, +`else + parameter [0:0] IMPLEMENT_DIVIDE = 0, +`endif +`ifdef OPT_IMPLEMENT_FPU + parameter [0:0] IMPLEMENT_FPU = 1, +`else + parameter [0:0] IMPLEMENT_FPU = 0, +`endif +`ifdef OPT_EARLY_BRANCHING + parameter [0:0] EARLY_BRANCHING = 1, +`else + parameter [0:0] EARLY_BRANCHING = 0, +`endif +`ifdef OPT_CIS + parameter [0:0] OPT_CIS = 1'b1, +`else + parameter [0:0] OPT_CIS = 1'b0, +`endif + // localparam [0:0] OPT_NO_USERMODE = 1'b0, +`ifdef OPT_PIPELINED + parameter [0:0] OPT_PIPELINED = 1'b1, +`else + parameter [0:0] OPT_PIPELINED = 1'b0, +`endif +`ifdef OPT_PIPELINED_BUS_ACCESS + localparam [0:0] OPT_PIPELINED_BUS_ACCESS = (OPT_PIPELINED), +`else + localparam [0:0] OPT_PIPELINED_BUS_ACCESS = 1'b0, +`endif + // localparam [0:0] OPT_MEMPIPE = OPT_PIPELINED_BUS_ACCESS, + localparam [0:0] IMPLEMENT_LOCK=0, + // localparam [0:0] OPT_LOCK=(IMPLEMENT_LOCK)&&(OPT_PIPELINED), + // localparam OPT_LGDCACHE = 0, + // localparam [0:0] OPT_DCACHE = (OPT_LGDCACHE > 0), + parameter RESET_DURATION = 10, + // localparam [0:0] WITH_LOCAL_BUS = 1'b0, + localparam AW=ADDRESS_WIDTH-2 +`ifdef FORMAL + , parameter F_LGDEPTH=8 +`endif + // }}} + ) ( + // {{{ + input wire S_AXI_ACLK, S_AXI_ARESETN, + i_interrupt, + // Debug interface + // {{{ + // Debug interface -- inputs +// input wire i_halt, i_clear_cache, +// input wire [4:0] i_dbg_wreg, +// input wire i_dbg_we, +// input wire [31:0] i_dbg_data, +// input wire [4:0] i_dbg_rreg, + // Debug interface -- outputs +// output wire cpu_dbg_stall, +// output reg [31:0] o_dbg_reg, +// output reg [2:0] o_dbg_cc, +// output wire o_break, + input wire S_DBG_AWVALID, + output wire S_DBG_AWREADY, + input wire [C_DBG_ADDR_WIDTH-1:0] S_DBG_AWADDR, + input wire [2:0] S_DBG_AWPROT, + // + input wire S_DBG_WVALID, + output wire S_DBG_WREADY, + input wire [31:0] S_DBG_WDATA, + input wire [3:0] S_DBG_WSTRB, + // + output reg S_DBG_BVALID, + input wire S_DBG_BREADY, + output wire [1:0] S_DBG_BRESP, + // + input wire S_DBG_ARVALID, + output wire S_DBG_ARREADY, + input wire [7:0] S_DBG_ARADDR, + input wire [2:0] S_DBG_ARPROT, + // + output reg S_DBG_RVALID, + input wire S_DBG_RREADY, + output reg [31:0] S_DBG_RDATA, + output wire [1:0] S_DBG_RRESP, + // + // }}} + // Instruction bus (master) + // {{{ + output wire M_INSN_AWVALID, + input wire M_INSN_AWREADY, + output wire [C_AXI_ADDR_WIDTH-1:0] M_INSN_AWADDR, + output wire [2:0] M_INSN_AWPROT, + // + output wire M_INSN_WVALID, + input wire M_INSN_WREADY, + output wire [C_AXI_DATA_WIDTH-1:0] M_INSN_WDATA, + output wire [C_AXI_DATA_WIDTH/8-1:0] M_INSN_WSTRB, + // + input wire M_INSN_BVALID, + output wire M_INSN_BREADY, + input wire [1:0] M_INSN_BRESP, + // + output wire M_INSN_ARVALID, + input wire M_INSN_ARREADY, + output wire [C_AXI_ADDR_WIDTH-1:0] M_INSN_ARADDR, + output wire [2:0] M_INSN_ARPROT, + // + input wire M_INSN_RVALID, + output wire M_INSN_RREADY, + input wire [C_AXI_DATA_WIDTH-1:0] M_INSN_RDATA, + input wire [1:0] M_INSN_RRESP, + // }}} + // Data bus (master) + // {{{ + output wire M_DATA_AWVALID, + input wire M_DATA_AWREADY, + output wire [C_AXI_ADDR_WIDTH-1:0] M_DATA_AWADDR, + output wire [2:0] M_DATA_AWPROT, + // + output wire M_DATA_WVALID, + input wire M_DATA_WREADY, + output wire [C_AXI_DATA_WIDTH-1:0] M_DATA_WDATA, + output wire [C_AXI_DATA_WIDTH/8-1:0] M_DATA_WSTRB, + // + input wire M_DATA_BVALID, + output wire M_DATA_BREADY, + input wire [1:0] M_DATA_BRESP, + // + output wire M_DATA_ARVALID, + input wire M_DATA_ARREADY, + output wire [C_AXI_ADDR_WIDTH-1:0] M_DATA_ARADDR, + output wire [2:0] M_DATA_ARPROT, + // + input wire M_DATA_RVALID, + output wire M_DATA_RREADY, + input wire [C_AXI_DATA_WIDTH-1:0] M_DATA_RDATA, + input wire [1:0] M_DATA_RRESP, + // }}} + // Accounting outputs ... to help us count stalls and usage + output wire o_op_stall, + output wire o_pf_stall, + output wire o_i_count + // +`ifdef DEBUG_SCOPE + , output reg [31:0] o_debug +`endif + // }}} + ); + + // Declarations + // {{{ + localparam FETCH_LIMIT = 4; + wire [31:0] cpu_debug; + + localparam RESET_BIT = 6, + STEP_BIT = 8, + HALT_BIT = 10, + CLEAR_CACHE_BIT = 11; + localparam [0:0] OPT_LOWPOWER = 1'b1; + localparam [0:0] SWAP_ENDIANNESS = 1'b0; + + // AXI-lite signal handling + // {{{ + wire awskd_valid, wskd_valid, arskd_valid; + wire dbg_write_ready, dbg_read_ready; + wire [C_DBG_ADDR_WIDTH-DBGLSB-1:0] awskd_addr, arskd_addr; + wire [31:0] wskd_data; + wire [3:0] wskd_strb; + reg dbg_write_valid, dbg_read_valid; + reg [4:0] dbg_write_reg; + wire [4:0] dbg_read_reg; + reg [31:0] dbg_write_data; + wire [31:0] dbg_read_data; + wire cpu_dbg_stall, cpu_break; + wire [2:0] cpu_dbg_cc; + // }}} + + reg reset_hold; + wire cpu_clken; + + // CPU control registers + // {{{ + reg cmd_halt, cmd_reset, cmd_step, cmd_clear_cache; + wire [31:0] cpu_status; + wire dbg_cmd_write; + // }}} + + // Fetch + // {{{ + wire pf_new_pc, clear_icache, pf_ready; + wire [AW+1:0] pf_request_address; + wire [31:0] pf_instruction; + wire [AW+1:0] pf_instruction_pc; + wire pf_valid, pf_illegal; + // }}} + // Memory + // {{{ + wire clear_dcache, mem_ce, bus_lock; + wire [2:0] mem_op; + wire [31:0] mem_cpu_addr; + wire [AW+1:0] mem_lock_pc; + wire [31:0] mem_wdata; + wire [4:0] mem_reg; + wire mem_busy, mem_rdbusy, mem_pipe_stalled, mem_valid, + mem_bus_err; + wire [4:0] mem_wreg; + wire [31:0] mem_result; + // }}} + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Debug signal handling + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + // + // Write signaling + // {{{ + skidbuffer #( + // {{{ + .OPT_OUTREG(0), + .OPT_LOWPOWER(OPT_LOWPOWER), + .DW(C_DBG_ADDR_WIDTH-DBGLSB) + // }}} + ) dbgawskd( + // {{{ + .i_clk(S_AXI_ACLK), .i_reset(!S_AXI_ARESETN), + .i_valid(S_DBG_AWVALID), + .o_ready(S_DBG_AWREADY), + .i_data(S_DBG_AWADDR[C_DBG_ADDR_WIDTH-1:DBGLSB]), + .o_valid(awskd_valid), .i_ready(dbg_write_ready), + .o_data(awskd_addr) + // }}} + ); + + skidbuffer #( + // {{{ + .OPT_OUTREG(0), + .OPT_LOWPOWER(OPT_LOWPOWER), + .DW(C_DBG_DATA_WIDTH+C_DBG_DATA_WIDTH/8) + // }}} + ) dbgwskd( + // {{{ + .i_clk(S_AXI_ACLK), .i_reset(!S_AXI_ARESETN), + .i_valid(S_DBG_WVALID), + .o_ready(S_DBG_WREADY), + .i_data({ S_DBG_WDATA, S_DBG_WSTRB }), + .o_valid(wskd_valid), .i_ready(dbg_write_ready), + .o_data({ wskd_data, wskd_strb }) + // }}} + ); + + assign dbg_write_ready = awskd_valid && wskd_valid + && ((wskd_strb==0) || awskd_addr[5] || !cpu_dbg_stall + || !dbg_write_valid) + && (!S_DBG_BVALID || S_DBG_BREADY); + + // dbg_write_valid + // {{{ + initial dbg_write_valid = 0; + always @(posedge S_AXI_ACLK) + if (!S_AXI_ARESETN) + dbg_write_valid <= 1'b0; + else if (!dbg_write_valid || !cpu_dbg_stall) + begin + dbg_write_valid <= dbg_write_ready && (|wskd_strb) && !awskd_addr[5]; + end + // }}} + + // dbg_write_reg + // {{{ + always @(posedge S_AXI_ACLK) + if (!dbg_write_valid || !cpu_dbg_stall) + begin + dbg_write_reg <= awskd_addr[4:0]; + if (OPT_LOWPOWER && !dbg_write_valid) + dbg_write_reg <= 0; + end + // }}} + + // dbg_write_data + // {{{ + always @(posedge S_AXI_ACLK) + if (!dbg_write_valid || !cpu_dbg_stall) + begin + dbg_write_data <= wskd_data; + if (OPT_LOWPOWER && !dbg_write_ready) + dbg_write_data <= 0; + end + // }}} + + // S_DBG_BVALID + // {{{ + initial S_DBG_BVALID = 1'b0; + always @(posedge S_AXI_ACLK) + if (!S_AXI_ARESETN) + S_DBG_BVALID <= 1'b0; + else if (dbg_write_ready) + S_DBG_BVALID <= 1'b1; + else if (S_DBG_BREADY) + S_DBG_BVALID <= 1'b0; + // }}} + + // S_DBG_BRESP + // {{{ + assign S_DBG_BRESP = 2'b00; + // }}} + + // }}} + + // + // Read signaling + // {{{ + + skidbuffer #( + // {{{ + .OPT_OUTREG(0), + .OPT_LOWPOWER(OPT_LOWPOWER), + .DW(C_DBG_ADDR_WIDTH-DBGLSB) + // }}} + ) dbgarskd( + // {{{ + .i_clk(S_AXI_ACLK), .i_reset(!S_AXI_ARESETN), + .i_valid(S_DBG_ARVALID), + .o_ready(S_DBG_ARREADY), + .i_data(S_DBG_ARADDR[C_DBG_ADDR_WIDTH-1:DBGLSB]), + .o_valid(arskd_valid), .i_ready(dbg_read_ready), + .o_data(arskd_addr) + // }}} + ); + + assign dbg_read_ready = arskd_valid && !dbg_read_valid + && (!S_DBG_RVALID || S_DBG_RREADY); + + assign dbg_read_reg = (OPT_LOWPOWER && !dbg_read_ready) + ? 5'h0 : arskd_addr[4:0]; + + // dbg_read_valid + // {{{ + initial dbg_read_valid = 0; + always @(posedge S_AXI_ACLK) + if (!S_AXI_ARESETN) + dbg_read_valid <= 0; + else + dbg_read_valid <= dbg_read_ready && arskd_addr[5]; + // }}} + + // S_DBG_RVALID + // {{{ + initial S_DBG_RVALID = 0; + always @(posedge S_AXI_ACLK) + if (!S_AXI_ARESETN) + S_DBG_RVALID <= 0; + else if (!S_DBG_RVALID || S_DBG_RREADY) + S_DBG_RVALID <= (dbg_read_ready && !arskd_addr[5]) + || dbg_read_valid; + // }}} + + // S_DBG_RDATA + // {{{ + initial S_DBG_RDATA = 0; + always @(posedge S_AXI_ACLK) + if (OPT_LOWPOWER && !S_AXI_ARESETN) + S_DBG_RDATA <= 0; + else if (!S_DBG_RVALID || S_DBG_RREADY) + begin + // {{{ + if (dbg_read_valid) + S_DBG_RDATA <= dbg_read_data; + else + S_DBG_RDATA <= cpu_status; + + if (OPT_LOWPOWER && !dbg_read_valid && !dbg_read_ready) + S_DBG_RDATA <= 0; + // }}} + end + // }}} + + assign S_DBG_RRESP = 2'b00; + // }}} + + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Reset, halt, clear-cache, and step controls + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + assign dbg_cmd_write = (dbg_write_ready && awskd_addr[5]); + + // + // Always start us off with an initial reset + // {{{ + generate if (RESET_DURATION > 0) + begin : INITIAL_RESET_HOLD + // {{{ + reg [$clog2(RESET_DURATION)-1:0] reset_counter; + + initial reset_counter = RESET_DURATION; + always @(posedge S_AXI_ACLK) + if (!S_AXI_ARESETN) + reset_counter <= RESET_DURATION; + else if (reset_counter > 0) + reset_counter <= reset_counter - 1; + + initial reset_hold = 1; + always @(posedge S_AXI_ACLK) + if (!S_AXI_ARESETN) + reset_hold <= 1; + else + reset_hold <= (reset_counter > 1); +`ifdef FORMAL + always @(*) + assert(reset_hold == (reset_counter != 0)); +`endif + // }}} + end else begin + + always @(*) + reset_hold = 0; + + end endgenerate + + // cmd_reset + // {{{ + initial cmd_reset = 1'b1; + always @(posedge S_AXI_ACLK) + if (!S_AXI_ARESETN) + cmd_reset <= 1'b1; + else if (reset_hold) + cmd_reset <= 1'b1; + else if (cpu_break && !START_HALTED) + cmd_reset <= 1'b1; + else + cmd_reset <= (dbg_cmd_write && wskd_strb[0] + && wskd_data[RESET_BIT]); + // }}} + // }}} + + // cmd_halt + // {{{ + always @(posedge S_AXI_ACLK) + if (!S_AXI_ARESETN) + cmd_halt <= START_HALTED; + else if (cmd_reset && START_HALTED) + cmd_halt <= START_HALTED; + else begin + // {{{ + if (!dbg_write_valid && !cpu_dbg_stall && dbg_cmd_write + && wskd_strb[1] && (!wskd_data[HALT_BIT] + || wskd_data[STEP_BIT])) + cmd_halt <= 1'b0; + + // Reasons to halt + + // 1. Halt on any unhandled CPU exception. The cause of the + // exception must be cured before we can (re)start. + // If the CPU is configured to start immediately on power + // up, we leave it to reset on any exception instead. + if (cpu_break && START_HALTED) + cmd_halt <= 1'b1; + + // 2. Halt on any user request to halt. (Only valid if the + // STEP bit isn't also set) + + if (dbg_cmd_write && wskd_strb[1] && wskd_data[HALT_BIT] + && !wskd_data[STEP_BIT]) + cmd_halt <= 1'b1; + + // 3. Halt on any user request to write to a CPU register + if (dbg_write_ready && !awskd_addr[5] && wskd_strb != 0) + cmd_halt <= 1'b1; + + // 4. Halt following any step command + if (cmd_step) + cmd_halt <= 1'b1; + + // 4. Halt following any clear cache + if (cmd_clear_cache) + cmd_halt <= 1'b1; + + // 5. Halt on any clear cache bit--independent of any step bit + if (dbg_cmd_write && wskd_strb[1] && wskd_data[CLEAR_CACHE_BIT]) + cmd_halt <= 1'b1; + // }}} + end + // }}} + + // cmd_clear_cache + // {{{ + initial cmd_clear_cache = 1'b0; + always @(posedge S_AXI_ACLK) + if (!S_AXI_ARESETN || cmd_reset) + cmd_clear_cache <= 1'b0; + else if (dbg_cmd_write && wskd_data[CLEAR_CACHE_BIT] + && wskd_data[HALT_BIT] && wskd_strb[1]) + cmd_clear_cache <= 1'b1; + else if (cmd_halt && !cpu_dbg_stall) + cmd_clear_cache <= 1'b0; + // }}} + + // cmd_step + // {{{ + initial cmd_step = 1'b0; + always @(posedge S_AXI_ACLK) + if (!S_AXI_ARESETN) + cmd_step <= 1'b0; + else if (dbg_cmd_write && wskd_data[STEP_BIT] && wskd_strb[1]) + cmd_step <= 1'b1; + else if (!cpu_dbg_stall) + cmd_step <= 1'b0; + // }}} + + // cpu_status + // {{{ + // 0x10000 -> cpu_gie + // 0x08000 -> (Reserved/unused) + // 0x04000 -> cpu_break + // 0x02000 -> cpu_gie + // 0x01000 -> cpu_sleep + // 0x00800 -> cmd_clear_cache + // 0x00400 -> cmd_halt + // 0x00200 -> cmd_stall + // 0x00100 -> cmd_step + // 0x00080 -> Interrupt pending + // 0x00040 -> Reset + // 0x0003f -> Unused (old register address) + assign cpu_status = { 8'h0, 7'h0, i_interrupt, + cpu_break, cpu_dbg_cc, + 1'b0, cmd_halt, !cpu_dbg_stall, 1'b0, + i_interrupt, cmd_reset, 6'h0 }; + // }}} + + // }}} + //////////////////////////////////////////////////////////////////////// + // + // The ZipCPU Core + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // +`ifdef FORMAL + // {{{ + (* anyseq *) reg f_cpu_halted, f_cpu_data, f_cpu_stall, + f_cpu_break; + (* anyseq *) reg [2:0] f_cpu_dbg_cc; + (* anyseq *) reg [2:0] f_cpu_dbg_read_data; + + assign cpu_dbg_stall = f_cpu_stall; + assign cpu_break = f_cpu_break; + assign cpu_dbg_cc = f_cpu_dbg_cc; + assign dbg_read_data = f_cpu_dbg_read_data; + + fdebug #( + // {{{ + .OPT_DISTRIBUTED_RAM(1'b1) + // }}} + ) fdbg ( + // {{{ + .i_clk(S_AXI_ACLK), + .i_reset(!S_AXI_ARESETN), + .i_cpu_reset(cmd_reset), + .i_halt(cmd_halt), + .i_halted(f_cpu_halted), + .i_clear_cache(cmd_clear_cache), + .i_dbg_we(dbg_write_valid), + .i_dbg_reg(dbg_write_reg), + .i_dbg_data(dbg_write_data), + .i_dbg_stall(cpu_dbg_stall), + .i_dbg_break(cpu_break), + .i_dbg_cc(cpu_dbg_cc) + // }}} + ); + // }}} +`else + zipcore #( + // {{{ + .RESET_ADDRESS(RESET_ADDRESS), + .ADDRESS_WIDTH(C_AXI_ADDR_WIDTH-2), + .IMPLEMENT_MPY(IMPLEMENT_MPY), + .IMPLEMENT_DIVIDE(IMPLEMENT_DIVIDE), + .IMPLEMENT_FPU(IMPLEMENT_FPU), + .OPT_EARLY_BRANCHING(EARLY_BRANCHING), + .OPT_CIS(OPT_CIS), + // .OPT_NO_USERMODE(OPT_NO_USERMODE), + .OPT_PIPELINED(OPT_PIPELINED), + .OPT_PIPELINED_BUS_ACCESS(OPT_PIPELINED_BUS_ACCESS), + // localparam [0:0] OPT_MEMPIPE = OPT_PIPELINED_BUS_ACCESS; + .IMPLEMENT_LOCK(IMPLEMENT_LOCK), + .OPT_DCACHE(1'b0), + // localparam [0:0] OPT_LOCK=(IMPLEMENT_LOCK)&&(OPT_PIPELINED); + // parameter [0:0] WITH_LOCAL_BUS = 1'b1; + .OPT_GATE_CLOCK(1'b0) +`ifdef FORMAL + , .F_LGDEPTH(F_LGDEPTH) +`endif + // }}} + ) core ( + // {{{ + .i_clk(S_AXI_ACLK), .i_reset(cmd_reset), + .i_interrupt(i_interrupt), + .o_clken(cpu_clken), + // Debug interface + // {{{ + .i_halt(cmd_halt), .i_clear_cache(cmd_clear_cache), + .i_dbg_wreg(dbg_write_reg), .i_dbg_we(dbg_write_valid), + .i_dbg_data(dbg_write_data),.i_dbg_rreg(dbg_read_reg), + .o_dbg_stall(cpu_dbg_stall),.o_dbg_reg(dbg_read_data), + .o_dbg_cc(cpu_dbg_cc), .o_break(cpu_break), + // }}} + // Instruction fetch interface + // {{{ + .o_pf_new_pc(pf_new_pc), .o_clear_icache(clear_icache), + .o_pf_ready(pf_ready), + .o_pf_request_address(pf_request_address), + .i_pf_valid(pf_valid), .i_pf_illegal(pf_illegal), + .i_pf_instruction(pf_instruction), + .i_pf_instruction_pc(pf_instruction_pc), + // }}} + // Memory unit interface + // {{{ + .o_clear_dcache(clear_dcache), .o_mem_ce(mem_ce), + .o_bus_lock(bus_lock), + .o_mem_op(mem_op), .o_mem_addr(mem_cpu_addr), + .o_mem_data(mem_wdata), + .o_mem_lock_pc(mem_lock_pc), + .o_mem_reg(mem_reg), + .i_mem_busy(mem_busy), .i_mem_rdbusy(mem_rdbusy), + .i_mem_pipe_stalled(mem_pipe_stalled), + .i_mem_valid(mem_valid), + .i_bus_err(mem_bus_err), + .i_mem_wreg(mem_wreg), + .i_mem_result(mem_result), + // }}} + // Accounting/CPU usage interface + .o_op_stall(o_op_stall), .o_pf_stall(o_pf_stall), + .o_i_count(o_i_count), + .o_debug(cpu_debug) + // }}} + ); +`endif + // }}} + // o_debug -- the debugging bus input + // {{{ +`ifdef DEBUG_SCOPE + assign o_debug = cpu_debug; +`else + // Verilator lint_off UNUSED + wire dbg_unused; + assign dbg_unused = &{ 1'b0, cpu_debug }; +`endif + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Instruction Fetch + // {{{ + //////////////////////////////////////////////////////////////////////// + // + +`ifndef FORMAL + + axilfetch #( + // {{{ + .C_AXI_ADDR_WIDTH(C_AXI_ADDR_WIDTH), + .C_AXI_DATA_WIDTH(C_AXI_DATA_WIDTH), + .FETCH_LIMIT(FETCH_LIMIT), + .SWAP_ENDIANNESS(SWAP_ENDIANNESS) + // }}} + ) pf ( + // {{{ + .S_AXI_ACLK(S_AXI_ACLK), .S_AXI_ARESETN(S_AXI_ARESETN), + // CPU signals + // {{{ + .i_cpu_reset(cmd_reset), + .i_new_pc(pf_new_pc), + .i_clear_cache(clear_icache), + .i_ready(pf_ready), + .i_pc(pf_request_address), + .o_insn(pf_instruction), + .o_pc(pf_instruction_pc), + .o_valid(pf_valid), + .o_illegal(pf_illegal), + // }}} + // AXI-lite bus signals + // {{{ + .M_AXI_ARVALID(M_INSN_ARVALID), + .M_AXI_ARREADY(M_INSN_ARREADY), + .M_AXI_ARADDR(M_INSN_ARADDR), + .M_AXI_ARPROT(M_INSN_ARPROT), + // + .M_AXI_RVALID(M_INSN_RVALID), + .M_AXI_RREADY(M_INSN_RREADY), + .M_AXI_RDATA(M_INSN_RDATA), + .M_AXI_RRESP(M_INSN_RRESP) + // }}} + // }}} + ); + +`endif + + // Assign values to the (unused) M_INSN_* write ports + // {{{ + assign M_INSN_AWVALID = 0; + assign M_INSN_AWVALID = 0; + assign M_INSN_AWADDR = 0; + assign M_INSN_AWPROT = 0; + // + assign M_INSN_WVALID = 0; + assign M_INSN_WDATA = 0; + assign M_INSN_WSTRB = 0; + // + assign M_INSN_BREADY = 1'b1; + // }}} + + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Memory Unit + // {{{ + //////////////////////////////////////////////////////////////////////// + // +`ifndef FORMAL + generate if (OPT_PIPELINED_BUS_ACCESS) + begin : PIPELINED_MEM + + axilpipe #( + // {{{ + .C_AXI_ADDR_WIDTH(C_AXI_ADDR_WIDTH), + .C_AXI_DATA_WIDTH(C_AXI_DATA_WIDTH) //, + // .OPT_SIGN_EXTEND(OPT_SIGN_EXTEND) + // }}} + ) domem( + // {{{ + .S_AXI_ACLK(S_AXI_ACLK), .S_AXI_ARESETN(S_AXI_ARESETN), + .i_cpu_reset(cmd_reset), + // CPU interface + // {{{ + .i_stb(mem_ce), + .i_lock(bus_lock), + .i_op(mem_op), + .i_addr(mem_cpu_addr), + .i_data(mem_wdata), + .i_oreg(mem_reg), + .o_busy(mem_busy), + .o_pipe_stalled(mem_pipe_stalled), + .o_rdbusy(mem_rdbusy), + .o_valid(mem_valid), + .o_err(mem_bus_err), + .o_wreg(mem_wreg), + .o_result(mem_result), + // }}} + // AXI-lite + // Write interface + // {{{ + .M_AXI_AWVALID(M_DATA_AWVALID), + .M_AXI_AWREADY(M_DATA_AWREADY), + .M_AXI_AWADDR(M_DATA_AWADDR), + .M_AXI_AWPROT(M_DATA_AWPROT), + // + .M_AXI_WVALID(M_DATA_WVALID), + .M_AXI_WREADY(M_DATA_WREADY), + .M_AXI_WDATA(M_DATA_WDATA), + .M_AXI_WSTRB(M_DATA_WSTRB), + // + .M_AXI_BVALID(M_DATA_BVALID), + .M_AXI_BREADY(M_DATA_BREADY), + .M_AXI_BRESP(M_DATA_BRESP), + // }}} + // Read interface + // {{{ + .M_AXI_ARVALID(M_DATA_ARVALID), + .M_AXI_ARREADY(M_DATA_ARREADY), + .M_AXI_ARADDR(M_DATA_ARADDR), + .M_AXI_ARPROT(M_DATA_ARPROT), + // + .M_AXI_RVALID(M_DATA_RVALID), + .M_AXI_RREADY(M_DATA_RREADY), + .M_AXI_RDATA(M_DATA_RDATA), + .M_AXI_RRESP(M_DATA_RRESP) + // }}} + // }}} + ); + + end else begin : BARE_MEM + + axilops #( + // {{{ + .C_AXI_ADDR_WIDTH(C_AXI_ADDR_WIDTH), + .C_AXI_DATA_WIDTH(C_AXI_DATA_WIDTH), + .SWAP_ENDIANNESS(SWAP_ENDIANNESS), + .SWAP_WSTRB(1'b0), + .OPT_ALIGNMENT_ERR(1'b0), + .OPT_LOWPOWER(OPT_LOWPOWER) + // }}} + ) domem( + // {{{ + .S_AXI_ACLK(S_AXI_ACLK), .S_AXI_ARESETN(S_AXI_ARESETN), + .i_cpu_reset(cmd_reset), + // CPU interface + // {{{ + .i_stb(mem_ce), + .i_lock(bus_lock), + .i_op(mem_op), + .i_addr(mem_cpu_addr), + .i_data(mem_wdata), + .i_oreg(mem_reg), + .o_busy(mem_busy), + .o_rdbusy(mem_rdbusy), + .o_valid(mem_valid), + .o_err(mem_bus_err), + .o_wreg(mem_wreg), + .o_result(mem_result), + // }}} + // AXI-lite + // Write interface + // {{{ + .M_AXI_AWVALID(M_DATA_AWVALID), + .M_AXI_AWREADY(M_DATA_AWREADY), + .M_AXI_AWADDR(M_DATA_AWADDR), + .M_AXI_AWPROT(M_DATA_AWPROT), + // + .M_AXI_WVALID(M_DATA_WVALID), + .M_AXI_WREADY(M_DATA_WREADY), + .M_AXI_WDATA(M_DATA_WDATA), + .M_AXI_WSTRB(M_DATA_WSTRB), + // + .M_AXI_BVALID(M_DATA_BVALID), + .M_AXI_BREADY(M_DATA_BREADY), + .M_AXI_BRESP(M_DATA_BRESP), + // }}} + // Read interface + // {{{ + .M_AXI_ARVALID(M_DATA_ARVALID), + .M_AXI_ARREADY(M_DATA_ARREADY), + .M_AXI_ARADDR(M_DATA_ARADDR), + .M_AXI_ARPROT(M_DATA_ARPROT), + // + .M_AXI_RVALID(M_DATA_RVALID), + .M_AXI_RREADY(M_DATA_RREADY), + .M_AXI_RDATA(M_DATA_RDATA), + .M_AXI_RRESP(M_DATA_RRESP) + // }}} + // }}} + ); + + assign mem_pipe_stalled = mem_busy; + end endgenerate +`endif + // }}} + // Make Verilator happy + // {{{ + // Verilator lint_off UNUSED + wire unused; + assign unused = &{ 1'b0, cpu_clken, S_DBG_AWADDR[DBGLSB-1:0], + mem_lock_pc, clear_dcache, + S_DBG_ARADDR[DBGLSB-1:0], + S_DBG_ARPROT, S_DBG_AWPROT, + M_INSN_AWREADY, M_INSN_WREADY, + M_INSN_BVALID, M_INSN_BRESP }; + // Verilator lint_on UNUSED + // }}} +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal properties +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +`ifdef FORMAL + wire [F_LGDEPTH-1:0] faxil_rd_outstanding, + faxil_wr_outstanding, faxil_awr_outstanding; + + //////////////////////////////////////////////////////////////////////// + // + // AXI-lite debug interface + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + + faxil_slave #( + // {{{ + .C_AXI_DATA_WIDTH(C_DBG_DATA_WIDTH), + .C_AXI_ADDR_WIDTH(C_DBG_ADDR_WIDTH), + .F_LGDEPTH(F_LGDEPTH), + .F_AXI_MAXWAIT(0), + .F_AXI_MAXDELAY(0) + // }}} + ) faxil ( + // {{{ + .i_clk(S_AXI_ACLK), .i_axi_reset_n(S_AXI_ARESETN), + // AXI-lite debug writes + // {{{ + .i_axi_awvalid(S_DBG_AWVALID), + .i_axi_awready(S_DBG_AWREADY), + .i_axi_awaddr(S_DBG_AWADDR), + .i_axi_awprot(S_DBG_AWPROT), + // + .i_axi_wvalid(S_DBG_WVALID), + .i_axi_wready(S_DBG_WREADY), + .i_axi_wdata(S_DBG_WDATA), + .i_axi_wstrb(S_DBG_WSTRB), + // + .i_axi_bvalid(S_DBG_BVALID), + .i_axi_bready(S_DBG_BREADY), + .i_axi_bresp(S_DBG_BRESP), + // }}} + // AXI-lite debug reads + // {{{ + .i_axi_arvalid(S_DBG_ARVALID), + .i_axi_arready(S_DBG_ARREADY), + .i_axi_araddr(S_DBG_ARADDR), + .i_axi_arprot(S_DBG_ARPROT), + // + .i_axi_rvalid(S_DBG_RVALID), + .i_axi_rready(S_DBG_RREADY), + .i_axi_rdata(S_DBG_RDATA), + .i_axi_rresp(S_DBG_RRESP), + // }}} + // Induction + // {{{ + .f_axi_rd_outstanding(faxil_rd_outstanding), + .f_axi_wr_outstanding(faxil_wr_outstanding), + .f_axi_awr_outstanding(faxil_awr_outstanding) + // }}} + // }}} + ); + + always @(*) + if (S_AXI_ARESETN) + begin + assert(faxil_rd_outstanding == (S_DBG_ARREADY ? 0:1) + +(dbg_read_valid ? 1:0) + (S_DBG_RVALID ? 1:0)); + + assert(!dbg_read_valid || !S_DBG_RVALID); + + assert(faxil_wr_outstanding == (S_DBG_WREADY ? 0:1) + +(S_DBG_BVALID ? 1:0)); + + assert(faxil_awr_outstanding == (S_DBG_AWREADY ? 0:1) + +(S_DBG_BVALID ? 1:0)); + end + + // }}} + //////////////////////////////////////////////////////////////////////// + // + // CPU's debug interface + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + // Captured above + + // }}} +`endif +// }}} +endmodule diff --git a/rtl/cpu/zipbones.v b/rtl/cpu/zipbones.v index 6e668cc..cd4e189 100644 --- a/rtl/cpu/zipbones.v +++ b/rtl/cpu/zipbones.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: zipbones.v -// +// {{{ // Project: Zip CPU -- a small, lightweight, RISC CPU soft core // // Purpose: In the spirit of keeping the Zip CPU small, this implements a @@ -12,9 +12,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -29,11 +29,11 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // // @@ -41,98 +41,133 @@ // `include "cpudefs.v" // -`define RESET_BIT 6 -`define STEP_BIT 8 -`define HALT_BIT 10 -`define CLEAR_CACHE_BIT 11 -// +// }}} +module zipbones #( + // {{{ + parameter RESET_ADDRESS=32'h1000_0000, + ADDRESS_WIDTH=30, + // CPU options + // {{{ `ifdef OPT_TRADITIONAL_PFCACHE -`define LGICACHE_DEFAULT 8 + LGICACHE = 8, `else -`define LGICACHE_DEFAULT 0 + LGICACHE = 0, `endif -// `ifdef OPT_DCACHE -`define LGDCACHE_DEFAULT 10 + // Set to zero for no data cache + LGDCACHE = 10, `else -`define LGDCACHE_DEFAULT 0 -`endif -module zipbones(i_clk, i_reset, - // Wishbone master interface from the CPU - o_wb_cyc, o_wb_stb, o_wb_we, o_wb_addr, o_wb_data, o_wb_sel, - i_wb_stall, i_wb_ack, i_wb_data, i_wb_err, - // Incoming interrupts - i_ext_int, - // Our one outgoing interrupt - o_ext_int, - // Wishbone slave interface for debugging purposes - i_dbg_cyc, i_dbg_stb, i_dbg_we, i_dbg_addr, i_dbg_data, - o_dbg_stall, o_dbg_ack, o_dbg_data -`ifdef DEBUG_SCOPE - , o_cpu_debug + LGDCACHE = 0, `endif - ); - parameter RESET_ADDRESS=32'h0100000, ADDRESS_WIDTH=30, - LGICACHE=`LGICACHE_DEFAULT, - LGDCACHE=`LGDCACHE_DEFAULT; - parameter [0:0] START_HALTED=0; - parameter EXTERNAL_INTERRUPTS=1, + parameter [0:0] START_HALTED=0, + parameter `ifdef OPT_MULTIPLY - IMPLEMENT_MPY = `OPT_MULTIPLY; + OPT_MPY = `OPT_MULTIPLY, `else - IMPLEMENT_MPY = 0; + OPT_MPY = 0, `endif - parameter [0:0] `ifdef OPT_DIVIDE - IMPLEMENT_DIVIDE=1, + parameter [0:0] OPT_DIV=1, `else - IMPLEMENT_DIVIDE=0, + parameter [0:0] OPT_DIV=0, `endif `ifdef OPT_IMPLEMENT_FPU - IMPLEMENT_FPU=1, + parameter [0:0] OPT_FPU = 1, `else - IMPLEMENT_FPU=0, + parameter [0:0] OPT_FPU = 0, `endif - IMPLEMENT_LOCK=1; - localparam // Derived parameters - PHYSICAL_ADDRESS_WIDTH=ADDRESS_WIDTH, - PAW=ADDRESS_WIDTH, -`ifdef OPT_MMU - VIRTUAL_ADDRESS_WIDTH=30, -`else - VIRTUAL_ADDRESS_WIDTH=PAW, -`endif - LGTLBSZ = 6, - VAW=VIRTUAL_ADDRESS_WIDTH; - - localparam AW=ADDRESS_WIDTH; - input wire i_clk, i_reset; - // Wishbone master - output wire o_wb_cyc, o_wb_stb, o_wb_we; - output wire [(PAW-1):0] o_wb_addr; - output wire [31:0] o_wb_data; - output wire [3:0] o_wb_sel; - input wire i_wb_stall, i_wb_ack; - input wire [31:0] i_wb_data; - input wire i_wb_err; - // Incoming interrupts - input wire i_ext_int; - // Outgoing interrupt - output wire o_ext_int; - // Wishbone slave - input wire i_dbg_cyc, i_dbg_stb, i_dbg_we, i_dbg_addr; - input wire [31:0] i_dbg_data; - output wire o_dbg_ack; - output wire o_dbg_stall; - output wire [31:0] o_dbg_data; - // + parameter [0:0] OPT_LOCK = 1, + parameter RESET_DURATION = 10, + // }}} + // Short-cut names + // {{{ + localparam // Derived parameters + PAW=ADDRESS_WIDTH, + // localparam AW=ADDRESS_WIDTH, + // }}} + // Debug bit allocations + // {{{ + // DBGCTRL + // 10 HALT + // 9 HALT(ED) + // 8 STEP (W=1 steps, and returns to halted) + // 7 INTERRUPT-FLAG + // 6 RESET_FLAG + // ADDRESS: + // 5 PERIPHERAL-BIT + // [4:0] REGISTER-ADDR + // DBGDATA + // read/writes internal registers + // + localparam RESET_BIT = 6, + localparam STEP_BIT = 8, + localparam HALT_BIT = 10, + localparam CLEAR_CACHE_BIT = 11 + // }}} + // }}} + ) ( + // {{{ + input wire i_clk, i_reset, + // Wishbone master interface from the CPU + // {{{ + output wire o_wb_cyc, o_wb_stb, o_wb_we, + output wire [(PAW-1):0] o_wb_addr, + output wire [31:0] o_wb_data, + output wire [3:0] o_wb_sel, + input wire i_wb_stall, i_wb_ack, + input wire [31:0] i_wb_data, + input wire i_wb_err, + // }}} + // Incoming interrupts + input wire i_ext_int, + // Our one outgoing interrupt + output wire o_ext_int, + // Wishbone slave interface for debugging purposes + // {{{ + input wire i_dbg_cyc, i_dbg_stb, i_dbg_we, + input wire [5:0] i_dbg_addr, + input wire [31:0] i_dbg_data, + input wire [3:0] i_dbg_sel, + output wire o_dbg_stall, + output wire o_dbg_ack, + output wire [31:0] o_dbg_data + // }}} `ifdef DEBUG_SCOPE - output wire [31:0] o_cpu_debug; + , output wire [31:0] o_cpu_debug `endif - wire dbg_cyc, dbg_stb, dbg_we, dbg_addr, dbg_stall; - wire [31:0] dbg_idata, dbg_odata; - reg dbg_ack; + // }}} + ); + // Declarations + // {{{ + wire cpu_clken; + wire dbg_cyc, dbg_stb, dbg_we, dbg_stall; + wire [5:0] dbg_addr; + wire [31:0] dbg_idata; + reg [31:0] dbg_odata; + reg dbg_ack; + wire cpu_break, dbg_cmd_write; + wire reset_hold; + reg cmd_reset, cmd_halt, cmd_step, cmd_clear_cache, + cmd_write; + reg [4:0] cmd_waddr; + reg [31:0] cmd_wdata; + wire [2:0] cpu_dbg_cc; + wire cpu_reset, cpu_halt, cpu_dbg_stall; + wire cpu_lcl_cyc, cpu_lcl_stb, + cpu_op_stall, cpu_pf_stall, cpu_i_count; + wire [31:0] cpu_dbg_data; + wire [31:0] cpu_status; + reg dbg_pre_addr, dbg_pre_ack; + reg [31:0] dbg_cpu_status; + // }}} + //////////////////////////////////////////////////////////////////////// + // + // The external debug interface + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // assign dbg_cyc = i_dbg_cyc; assign dbg_stb = i_dbg_stb; assign dbg_we = i_dbg_we; @@ -141,118 +176,321 @@ module zipbones(i_clk, i_reset, assign o_dbg_ack = dbg_ack; assign o_dbg_stall = dbg_stall; assign o_dbg_data = dbg_odata; + // }}} + //////////////////////////////////////////////////////////////////////// // // The external debug interface + // {{{ + //////////////////////////////////////////////////////////////////////// + // // // We offer only a limited interface here, requiring a pre-register // write to set the local address. This interface allows access to // the Zip System on a debug basis only, and not to the rest of the // wishbone bus. Further, to access these registers, the control - // register must first be accessed to both stop the CPU and to + // register must first be accessed to both stop the CPU and to // set the following address in question. Hence all accesses require // two accesses: write the address to the control register (and halt // the CPU if not halted), then read/write the data from the data // register. // - wire cpu_break, dbg_cmd_write; - reg cmd_reset, cmd_halt, cmd_step, cmd_clear_pf_cache; - reg [4:0] cmd_addr; - wire [3:0] cpu_dbg_cc; - assign dbg_cmd_write = (dbg_stb)&&(dbg_we)&&(!dbg_addr); + assign dbg_cmd_write = (dbg_stb)&&(dbg_we)&&(dbg_addr[5]); + // // Always start us off with an initial reset - // + // {{{ + generate if (RESET_DURATION > 0) + begin : INITIAL_RESET_HOLD + // {{{ + reg [$clog2(RESET_DURATION)-1:0] reset_counter; + reg hold; + + initial reset_counter = RESET_DURATION; + always @(posedge i_clk) + if (i_reset) + reset_counter <= RESET_DURATION; + else if (reset_counter > 0) + reset_counter <= reset_counter - 1; + + initial hold = 1; + always @(posedge i_clk) + if (i_reset) + hold <= 1; + else + hold <= (reset_counter > 1); + + assign reset_hold = hold; +`ifdef FORMAL + always @(*) + assert(reset_hold == (reset_counter != 0)); +`endif + // }}} + end else begin + + assign reset_hold = 0; + + end endgenerate + + // cmd_reset + // {{{ + // Always start us off with an initial reset initial cmd_reset = 1'b1; always @(posedge i_clk) - cmd_reset <= ((dbg_cmd_write)&&(dbg_idata[`RESET_BIT])); - // + if (i_reset) + cmd_reset <= 1'b1; + else if (reset_hold) + cmd_reset <= 1'b1; + else if (cpu_break && !START_HALTED) + cmd_reset <= 1'b1; + else + cmd_reset <= ((dbg_cmd_write)&&(dbg_idata[RESET_BIT])); + // }}} + // }}} + + // cmd_halt + // {{{ initial cmd_halt = START_HALTED; always @(posedge i_clk) if (i_reset) cmd_halt <= START_HALTED; - else if (cmd_reset) + else if (cmd_reset && START_HALTED) cmd_halt <= START_HALTED; - else if (dbg_cmd_write) - cmd_halt <= ((dbg_idata[`HALT_BIT])&&(!dbg_idata[`STEP_BIT])); - else if ((cmd_step)||(cpu_break)) - cmd_halt <= 1'b1; + else begin + // {{{ + // When shall we release from a halt? Only if we have come to + // a full and complete stop. Even then, we only release if we + // aren't being given a command to step the CPU. + // + if (!cmd_write && !cpu_dbg_stall && dbg_cmd_write + && (!dbg_idata[HALT_BIT] || dbg_idata[STEP_BIT])) + cmd_halt <= 1'b0; + + // Reasons to halt + + // 1. Halt on any unhandled CPU exception. The cause of the + // exception must be cured before we can (re)start. + // If the CPU is configured to start immediately on power + // up, we leave it to reset on any exception instead. + if (cpu_break && START_HALTED) + cmd_halt <= 1'b1; + + // 2. Halt on any user request to halt. (Only valid if the + // STEP bit isn't also set) + if (dbg_cmd_write && dbg_idata[HALT_BIT] + && !dbg_idata[STEP_BIT]) + cmd_halt <= 1'b1; + + // 3. Halt on any user request to write to a CPU register + if (i_dbg_stb && dbg_we && !dbg_addr[5]) + cmd_halt <= 1'b1; + + // 4. Halt following any step command + if (cmd_step) + cmd_halt <= 1'b1; + + // 4. Halt following any clear cache + if (cmd_clear_cache) + cmd_halt <= 1'b1; - initial cmd_clear_pf_cache = 1'b1; + // 5. Halt on any clear cache bit--independent of any step bit + if (dbg_cmd_write && dbg_idata[CLEAR_CACHE_BIT]) + cmd_halt <= 1'b1; + // }}} + end + // }}} + + // cmd_clear_cache + // {{{ + initial cmd_clear_cache = 1'b0; always @(posedge i_clk) - cmd_clear_pf_cache <= (dbg_cmd_write)&&(dbg_idata[`CLEAR_CACHE_BIT]); - // + if (i_reset || cpu_reset) + cmd_clear_cache <= 1'b0; + else if (dbg_cmd_write && dbg_idata[CLEAR_CACHE_BIT] + && dbg_idata[HALT_BIT]) + cmd_clear_cache <= 1'b1; + else if (cmd_halt && !cpu_dbg_stall) + cmd_clear_cache <= 1'b0; + // }}} + + // cmd_step + // {{{ initial cmd_step = 1'b0; always @(posedge i_clk) - cmd_step <= (dbg_cmd_write)&&(dbg_idata[`STEP_BIT]); - // - initial cmd_addr = 5'h0; - always @(posedge i_clk) - if (dbg_cmd_write) - cmd_addr <= dbg_idata[4:0]; + if (i_reset) + cmd_step <= 1'b0; + else if (dbg_cmd_write && dbg_idata[STEP_BIT]) + cmd_step <= 1'b1; + else if (!cpu_dbg_stall) + cmd_step <= 1'b0; + // }}} - wire cpu_reset; assign cpu_reset = (cmd_reset); - wire cpu_halt, cpu_dbg_stall; assign cpu_halt = (cmd_halt); - wire [31:0] cmd_data; // Values: - // 0x0003f -> cmd_addr mask - // 0x00040 -> reset - // 0x00080 -> PIC interrrupt pending - // 0x00100 -> cmd_step - // 0x00200 -> cmd_stall - // 0x00400 -> cmd_halt - // 0x00800 -> cmd_clear_pf_cache - // 0x01000 -> cc.sleep + // 0x10000 -> External interrupt is high + // + // 0x08000 -> cpu_break (CPU is halted on an error) + // 0x04000 -> Supervisor bus error // 0x02000 -> cc.gie - // 0x10000 -> External interrupt line is high - assign cmd_data = { 7'h00, 8'h00, i_ext_int, - cpu_dbg_cc, + // 0x01000 -> cc.sleep + // 0x00800 -> cmd_clear_cache + // 0x00400 -> cmd_halt + // 0x00200 -> cmd_stall + // 0x00100 -> cmd_step + // 0x00080 -> PIC interrrupt pending + // 0x00040 -> reset + // 0x0003f -> cmd_addr mask + assign cpu_status = { 7'h00, 8'h00, i_ext_int, + cpu_break, cpu_dbg_cc, 1'b0, cmd_halt, (!cpu_dbg_stall), 1'b0, - i_ext_int, cpu_reset, 1'b0, cmd_addr }; + i_ext_int, cpu_reset, 6'h0 }; + + initial cmd_write = 0; + always @(posedge i_clk) + if (i_reset || cpu_reset) + cmd_write <= 1'b0; + else if (!cmd_write || !cpu_dbg_stall) + cmd_write <= dbg_stb && dbg_we && !dbg_addr[5] && (|i_dbg_sel); + always @(posedge i_clk) + if ((!cmd_write || !cpu_dbg_stall)&&(dbg_stb && dbg_we && !dbg_addr[5])) + begin + cmd_waddr <= dbg_addr[4:0]; + cmd_wdata <= dbg_idata; + end + // }}} + //////////////////////////////////////////////////////////////////////// // // The CPU itself - // - wire cpu_lcl_cyc, cpu_lcl_stb, - cpu_dbg_we, - cpu_op_stall, cpu_pf_stall, cpu_i_count; - wire [31:0] cpu_dbg_data; - assign cpu_dbg_we = ((dbg_stb)&&(dbg_we)&&(dbg_addr)); - zipcpu #(.RESET_ADDRESS(RESET_ADDRESS), - .ADDRESS_WIDTH(ADDRESS_WIDTH), - .LGICACHE(LGICACHE), - .OPT_LGDCACHE(LGDCACHE), - .WITH_LOCAL_BUS(0)) - thecpu(i_clk, cpu_reset, i_ext_int, - cpu_halt, cmd_clear_pf_cache, cmd_addr[4:0], cpu_dbg_we, - dbg_idata, cpu_dbg_stall, cpu_dbg_data, - cpu_dbg_cc, cpu_break, - o_wb_cyc, o_wb_stb, - cpu_lcl_cyc, cpu_lcl_stb, - o_wb_we, o_wb_addr, o_wb_data, o_wb_sel, - i_wb_stall, i_wb_ack, i_wb_data, - (i_wb_err)||(cpu_lcl_cyc), - cpu_op_stall, cpu_pf_stall, cpu_i_count + // {{{ +`ifdef FORMAL + (* anyseq *) reg f_cpu_halted, f_cpu_data, f_cpu_stall, + f_cpu_break; + (* anyseq *) reg [2:0] f_cpu_dbg_cc; + (* anyseq *) reg [31:0] f_cpu_dbg_data; + + assign cpu_dbg_stall = f_cpu_stall; + assign cpu_break = f_cpu_break; + assign cpu_dbg_cc = f_cpu_dbg_cc; + assign cpu_dbg_data = f_cpu_dbg_data; + + fdebug #( + // {{{ + .OPT_DISTRIBUTED_RAM(1'b1) + // }}} + ) fdbg ( + // {{{ + .i_clk(i_clk), + .i_reset(i_reset), + .i_cpu_reset(cpu_reset), + .i_halt(cpu_halt), + .i_halted(f_cpu_halted), + .i_clear_cache(cmd_clear_cache), + .i_dbg_we(cmd_write), + .i_dbg_reg(cmd_waddr), + .i_dbg_data(cmd_wdata), + .i_dbg_stall(cpu_dbg_stall), + .i_dbg_break(cpu_break), + .i_dbg_cc(cpu_dbg_cc) + // }}} + ); +`else + zipwb #( + // {{{ + .RESET_ADDRESS(RESET_ADDRESS), + .ADDRESS_WIDTH(ADDRESS_WIDTH), + .LGICACHE(LGICACHE), + .OPT_LGDCACHE(LGDCACHE), + .IMPLEMENT_MPY(OPT_MPY), + .IMPLEMENT_DIVIDE(OPT_DIV), + .IMPLEMENT_FPU(OPT_FPU), + .IMPLEMENT_LOCK(OPT_LOCK), + .WITH_LOCAL_BUS(0) + // }}} + ) thecpu( + // {{{ + .i_clk(i_clk), .i_reset(cpu_reset), .i_interrupt(i_ext_int), + .o_cpu_clken(cpu_clken), + .i_halt(cpu_halt), .i_clear_cache(cmd_clear_cache), + .i_dbg_wreg(cmd_waddr), .i_dbg_we(cmd_write), + .i_dbg_data(cmd_wdata), + .i_dbg_rreg(dbg_addr[4:0]), + .o_dbg_stall(cpu_dbg_stall), .o_dbg_reg(cpu_dbg_data), + .o_dbg_cc(cpu_dbg_cc), .o_break(cpu_break), + .o_wb_gbl_cyc(o_wb_cyc), .o_wb_gbl_stb(o_wb_stb), + .o_wb_lcl_cyc(cpu_lcl_cyc), + .o_wb_lcl_stb(cpu_lcl_stb), + .o_wb_we(o_wb_we), .o_wb_addr(o_wb_addr), + .o_wb_data(o_wb_data), .o_wb_sel(o_wb_sel), + .i_wb_stall(i_wb_stall), + .i_wb_ack(i_wb_ack), + .i_wb_data(i_wb_data), + .i_wb_err((i_wb_err)||(cpu_lcl_cyc)), + .o_op_stall(cpu_op_stall), .o_pf_stall(cpu_pf_stall), + .o_i_count(cpu_i_count) `ifdef DEBUG_SCOPE , o_cpu_debug `endif - ); + // }}} + ); +`endif + // }}} // Return debug response values - assign dbg_odata = (!dbg_addr)?cmd_data :cpu_dbg_data; + // {{{ + // assign dbg_odata = (dbg_addr[5])?cpu_status :cpu_dbg_data; + + always @(posedge i_clk) + dbg_pre_addr <= dbg_addr[5]; + + always @(posedge i_clk) + dbg_cpu_status <= cpu_status; + + initial dbg_pre_ack = 1'b0; + always @(posedge i_clk) + if (i_reset || !i_dbg_cyc) + dbg_pre_ack <= 1'b0; + else + dbg_pre_ack <= dbg_stb && !o_dbg_stall; + initial dbg_ack = 1'b0; always @(posedge i_clk) - dbg_ack <= (dbg_stb)&&(!o_dbg_stall); - assign dbg_stall= (cpu_dbg_stall)&&(dbg_addr); + if (i_reset || !i_dbg_cyc) + dbg_ack <= 1'b0; + else + dbg_ack <= dbg_pre_ack; + + always @(posedge i_clk) + if (dbg_pre_addr) + dbg_odata <= dbg_cpu_status; + else + dbg_odata <= cpu_dbg_data; + assign dbg_stall= (!cmd_write || !cpu_dbg_stall) && dbg_we && !dbg_addr[5]; + // }}} + // }}} assign o_ext_int = (cmd_halt) && (!i_wb_stall); // Make Verilator happy + // {{{ // verilator lint_off UNUSED - wire [4:0] unused; - assign unused = { dbg_cyc, cpu_lcl_stb, cpu_op_stall, cpu_pf_stall, cpu_i_count }; + wire unused; + assign unused = &{ 1'b0, dbg_cyc, cpu_lcl_stb, cpu_op_stall, + cpu_pf_stall, cpu_i_count, cpu_clken }; // verilator lint_on UNUSED - + // }}} +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal properties +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +`ifdef FORMAL +// Formal properties for this core are maintained elsewhere +`endif +// }}} endmodule diff --git a/rtl/cpu/zipcore.v b/rtl/cpu/zipcore.v new file mode 100644 index 0000000..b062cf8 --- /dev/null +++ b/rtl/cpu/zipcore.v @@ -0,0 +1,4882 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Filename: zipcore.v +// +// Project: Zip CPU -- a small, lightweight, RISC CPU soft core +// {{{ +// Purpose: +// +// Creator: Dan Gisselquist, Ph.D. +// Gisselquist Technology, LLC +// +//////////////////////////////////////////////////////////////////////////////// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ +// This program is free software (firmware): 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 MERCHANTIBILITY 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. (It's in the $(ROOT)/doc directory. Run make with no +// target there if the PDF file isn't present.) If not, see +// for a copy. +// }}} +// License: GPL, v3, as defined and found on www.gnu.org, +// {{{ +// http://www.gnu.org/licenses/gpl.html +// +// +//////////////////////////////////////////////////////////////////////////////// +// +// +`default_nettype none +// }}} +// Macros +// {{{ +// +// }}} +module zipcore #( + // {{{ + parameter ADDRESS_WIDTH=30, // 32-b word addr width + parameter [ADDRESS_WIDTH+1:0] RESET_ADDRESS=32'h010_0000, + parameter IMPLEMENT_MPY = 0, + parameter [0:0] IMPLEMENT_SHIFTS = 1, + parameter [0:0] IMPLEMENT_DIVIDE = 1, +`ifdef OPT_IMPLEMENT_FPU + parameter [0:0] IMPLEMENT_FPU = 1, +`else + parameter [0:0] IMPLEMENT_FPU = 0, +`endif + parameter [0:0] OPT_EARLY_BRANCHING = 1, + parameter [0:0] OPT_CIS = 1'b1, + parameter [0:0] OPT_PIPELINED = 1'b1, + parameter [0:0] OPT_PIPELINED_BUS_ACCESS = (OPT_PIPELINED), + parameter [0:0] IMPLEMENT_LOCK=1, + parameter [0:0] OPT_DCACHE = 1, + parameter [0:0] OPT_NO_USERMODE = 1'b0, + parameter [0:0] OPT_LOWPOWER = 1'b0, + parameter [0:0] OPT_GATE_CLOCK = 1'b1, + + localparam AW=ADDRESS_WIDTH +`ifdef FORMAL + , parameter F_LGDEPTH=4 +`endif + // }}} + ) ( + // {{{ + input wire i_clk, i_reset, i_interrupt, + output wire o_clken, + // Debug interface + // {{{ + input wire i_halt, i_clear_cache, + input wire [4:0] i_dbg_wreg, + input wire i_dbg_we, + input wire [31:0] i_dbg_data, + input wire [4:0] i_dbg_rreg, + // + output wire o_dbg_stall, + output reg [31:0] o_dbg_reg, + output reg [2:0] o_dbg_cc, + output wire o_break, + // }}} + // Instruction fetch interface + // {{{ + output wire o_pf_new_pc, + output wire o_clear_icache, + output wire o_pf_ready, + output wire [(AW+1):0] o_pf_request_address, + input wire i_pf_valid, i_pf_illegal, + input wire [31:0] i_pf_instruction, + input wire [(AW+1):0] i_pf_instruction_pc, + // }}} + // Memory unit interface + // {{{ + output wire o_clear_dcache, + output wire o_mem_ce, + output wire o_bus_lock, + output wire [2:0] o_mem_op, + output wire [31:0] o_mem_addr, + output wire [31:0] o_mem_data, + output wire [(AW+1):0] o_mem_lock_pc, + output wire [4:0] o_mem_reg, + input wire i_mem_busy, i_mem_rdbusy, + i_mem_pipe_stalled, i_mem_valid, + input wire i_bus_err, + input wire [4:0] i_mem_wreg, + input wire [31:0] i_mem_result, + // }}} + // Accounting outputs ... to help us count stalls and usage + // {{{ + output wire o_op_stall, + output wire o_pf_stall, + output wire o_i_count, + // }}} + // Debug data for on-line/live tracing + // {{{ + output reg [31:0] o_debug + //}}} + // }}} + ); + + // Local parameter definitions + // {{{ + // Verilator lint_off UNUSED + localparam [0:0] OPT_MEMPIPE = OPT_PIPELINED_BUS_ACCESS; + localparam [(AW-1):0] RESET_BUS_ADDRESS = RESET_ADDRESS[(AW+1):2]; + localparam [0:0] OPT_LOCK=(IMPLEMENT_LOCK)&&(OPT_PIPELINED); + localparam [3:0] CPU_CC_REG = 4'he, + CPU_PC_REG = 4'hf; + localparam [3:0] CPU_SUB_OP = 4'h0,// also a compare instruction + CPU_AND_OP = 4'h1,// also a test instruction + CPU_BREV_OP= 4'h8, + CPU_MOV_OP = 4'hd; + localparam CPU_CLRDCACHE_BIT=15, // Set to clr D-cache,auto clears + CPU_CLRICACHE_BIT=14, // Set to clr I-cache,auto clears + CPU_PHASE_BIT = 13, // Set on last half of a CIS + CPU_FPUERR_BIT = 12, // Set on floating point error + CPU_DIVERR_BIT = 11, // Set on divide error + CPU_BUSERR_BIT = 10, // Set on bus error + CPU_TRAP_BIT = 9, // User TRAP has taken place + CPU_ILL_BIT = 8, // Illegal instruction + CPU_BREAK_BIT = 7, + CPU_STEP_BIT = 6, // Will step one (or two CIS) ins + CPU_GIE_BIT = 5, + CPU_SLEEP_BIT = 4; + // Verilator lint_on UNUSED + // }}} + + // Register declarations + // {{{ + // The distributed RAM style comment is necessary on the + // SPARTAN6 with XST to prevent XST from oversimplifying the register + // set and in the process ruining everything else. It basically + // optimizes logic away, to where it no longer works. The logic + // as described herein will work, this just makes sure XST implements + // that logic. + // + (* ram_style = "distributed" *) + reg [31:0] regset [0:(OPT_NO_USERMODE)? 15:31]; + + // Condition codes + // (BUS, TRAP,ILL,BREAKEN,STEP,GIE,SLEEP ), V, N, C, Z + reg [3:0] flags, iflags; + wire [15:0] w_uflags, w_iflags; + reg break_en, step, sleep, r_halted; + wire break_pending, trap, gie, ubreak, pending_interrupt; + wire ill_err_u; + reg ill_err_i; + reg ibus_err_flag; + wire ubus_err_flag; + wire idiv_err_flag, udiv_err_flag; + wire ifpu_err_flag, ufpu_err_flag; + wire ihalt_phase, uhalt_phase; + + // The master chip enable + wire master_ce, master_stall; + // + + // + // PIPELINE STAGE #1 :: Prefetch + // Variable declarations + // + // {{{ + reg [(AW+1):0] pf_pc; + reg new_pc; + wire clear_pipeline; + + reg dcd_stalled; + // wire pf_cyc, pf_stb, pf_we, pf_stall, pf_ack, pf_err; + // wire [(AW-1):0] pf_addr; + // wire pf_valid, pf_gie, pf_illegal; + wire pf_gie; +`ifdef FORMAL + wire [31:0] f_dcd_insn_word; + wire f_dcd_insn_gie; + reg [31:0] f_op_insn_word; + reg [31:0] f_alu_insn_word; +`endif + + assign clear_pipeline = new_pc; + // }}} + + // + // PIPELINE STAGE #2 :: Instruction Decode + // Variable declarations + // + // + // {{{ + wire [3:0] dcd_opn; + wire dcd_ce, dcd_phase; + wire [4:0] dcd_A, dcd_B, dcd_R, dcd_preA, dcd_preB; + wire dcd_Acc, dcd_Bcc, dcd_Apc, dcd_Bpc, dcd_Rcc, dcd_Rpc; + wire [3:0] dcd_F; + wire dcd_wR, dcd_rA, dcd_rB, + dcd_ALU, dcd_M, dcd_DIV, dcd_FP, + dcd_wF, dcd_gie, dcd_break, dcd_lock, + dcd_pipe, dcd_ljmp; + wire dcd_valid; + wire [AW+1:0] dcd_pc /* verilator public_flat */; + wire [31:0] dcd_I; + wire dcd_zI; // true if dcd_I == 0 + wire dcd_A_stall, dcd_B_stall, dcd_F_stall; + + wire dcd_illegal; + wire dcd_early_branch, dcd_early_branch_stb; + wire [(AW+1):0] dcd_branch_pc; + + wire dcd_sim; + wire [22:0] dcd_sim_immv; + wire prelock_stall; + wire cc_invalid_for_dcd; + wire pending_sreg_write; + // }}} + + + // + // + // PIPELINE STAGE #3 :: Read Operands + // Variable declarations + // + // + // + // {{{ + // Now, let's read our operands + reg op_valid /* verilator public_flat */, + op_valid_mem, op_valid_alu; + reg op_valid_div, op_valid_fpu; + wire op_stall; + wire [3:0] op_opn; + reg [4:0] op_R; + reg op_Rcc; + reg [4:0] op_Aid, op_Bid; + reg op_rA, op_rB; + reg [31:0] r_op_Av, r_op_Bv; + reg [(AW+1):0] op_pc; + wire [31:0] w_op_Av, w_op_Bv, op_Av, op_Bv; + reg [31:0] w_pcB_v, w_pcA_v; + reg [31:0] w_op_BnI; + reg op_wR, op_wF; + wire op_gie; + wire [3:0] op_Fl; + reg [6:0] r_op_F; + wire [7:0] op_F; + wire op_ce, op_phase, op_pipe; + reg r_op_break; + wire w_op_valid; + wire op_lowpower_clear; + wire [8:0] w_cpu_info; + // Some pipeline control wires + reg op_illegal; + wire op_break; + wire op_lock; + +`ifdef VERILATOR + reg op_sim /* verilator public_flat */; + reg [22:0] op_sim_immv /* verilator public_flat */; + reg alu_sim /* verilator public_flat */; + reg [22:0] alu_sim_immv /* verilator public_flat */; +`else + wire op_sim = 1'b0; +`endif + // }}} + + + // + // + // PIPELINE STAGE #4 :: ALU / Memory + // Variable declarations + // + // + // {{{ + wire [(AW+1):0] alu_pc; + reg [4:0] alu_reg; + reg r_alu_pc_valid, mem_pc_valid; + wire alu_pc_valid; + wire alu_phase; + wire alu_ce /* verilator public_flat */, alu_stall; + wire [31:0] alu_result; + wire [3:0] alu_flags; + wire alu_valid, alu_busy; + wire set_cond; + reg alu_wR, alu_wF; + wire alu_gie, alu_illegal; + + + wire mem_ce, mem_stalled; + + wire div_ce, div_error, div_busy, div_valid; + wire [31:0] div_result; + wire [3:0] div_flags; + + wire fpu_ce, fpu_error, fpu_busy, fpu_valid; + wire [31:0] fpu_result; + wire [3:0] fpu_flags; + reg adf_ce_unconditional; + + + reg dbgv, dbg_clear_pipe; + reg [31:0] dbg_val; + reg [31:0] debug_pc; + reg r_dbg_stall; + + assign div_ce = (op_valid_div)&&(adf_ce_unconditional)&&(set_cond); + assign fpu_ce = (IMPLEMENT_FPU)&&(op_valid_fpu)&&(adf_ce_unconditional)&&(set_cond); + + // }}} + + // + // + // PIPELINE STAGE #5 :: Write-back + // Variable declarations + // + // {{{ + wire wr_discard, wr_write_pc, wr_write_cc, + wr_write_scc, wr_write_ucc; + reg wr_reg_ce, wr_flags_ce; + reg [3:0] wr_flags; + reg [2:0] wr_index; + wire [4:0] wr_reg_id; + reg [31:0] wr_gpreg_vl, wr_spreg_vl; + wire w_switch_to_interrupt, w_release_from_interrupt; + reg [(AW+1):0] ipc; + wire [(AW+1):0] upc; + reg last_write_to_cc; + wire cc_write_hold; + reg r_clear_icache; + + reg pfpcset; + reg [2:0] pfpcsrc; + // }}} + + // }}} + //////////////////////////////////////////////////////////////////////// + // + // MASTER: clock enable. + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + assign master_ce = ((!i_halt)||(alu_phase)) + &&(!cc_write_hold)&&(!o_break)&&(!sleep); + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Calculate stall conditions + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + // PIPELINE STAGE #1 :: Prefetch + // These are calculated externally, within the prefetch module. + // + // PIPELINE STAGE #2 :: Instruction Decode + // {{{ + always @(*) + if (OPT_PIPELINED) + dcd_stalled = (dcd_valid && op_stall); + else + dcd_stalled = (!master_ce) + // Can't step forward when we need to be halted + ||(ill_err_i)||(ibus_err_flag)||(idiv_err_flag) + ||((dcd_valid || op_valid) && !dcd_early_branch) + ||(alu_busy)||(div_busy)||(fpu_busy)||(i_mem_busy); + // }}} + // + // PIPELINE STAGE #3 :: Read Operands + // {{{ + generate if (OPT_PIPELINED) + begin : GEN_OP_STALL + reg r_cc_invalid_for_dcd; + reg r_pending_sreg_write; + + // cc_invalid_for_dcd + // {{{ + initial r_cc_invalid_for_dcd = 1'b0; + always @(posedge i_clk) + if (clear_pipeline) + r_cc_invalid_for_dcd <= 1'b0; + else if ((alu_ce || mem_ce)&&(set_cond)&&(op_valid) &&((op_wF) + ||((op_wR)&&(op_R[4:0] == { op_gie, CPU_CC_REG })))) + // If an instruction in the pipeline will write to the + // CC register, then we can't be allowed to release + // any instruction depending upon the CC register + // (for other than conditional execution) into the + // pipeline. + r_cc_invalid_for_dcd <= 1'b1; + else if (r_cc_invalid_for_dcd) + // While the pipeline is busy, keep r_cc_invalid_for_dcd + // high. + r_cc_invalid_for_dcd <= ((alu_busy)||(i_mem_rdbusy)||(div_busy)||(fpu_busy)); + else + r_cc_invalid_for_dcd <= 1'b0; + + assign cc_invalid_for_dcd = r_cc_invalid_for_dcd; + // }}} + + // pending_sreg_write + // {{{ + // Used to determine if we need to stall for flags to be ready + initial r_pending_sreg_write = 1'b0; + always @(posedge i_clk) + if (clear_pipeline) + r_pending_sreg_write <= 1'b0; + else if (((adf_ce_unconditional)||(mem_ce)) + &&(set_cond)&&(!op_illegal) + &&(op_wR) + &&(op_R[3:1] == 3'h7) + &&(op_R[4:0] != { gie, 4'hf })) + r_pending_sreg_write <= 1'b1; + else if ((!i_mem_rdbusy)&&(!alu_busy)) + r_pending_sreg_write <= 1'b0; + + assign pending_sreg_write = r_pending_sreg_write; + // }}} + + assign op_stall = (op_valid)&&( + // {{{ + // Only stall if we're loaded w/validins and the + // next stage is accepting our instruction + (!adf_ce_unconditional)&&(!mem_ce) + ) + ||(dcd_valid)&&( + // If we are halted, then accepting anything + // into the Op stage might accept a register + // that then gets modified by the debugging + // interface so as to be invalid. + i_halt + // Stall if we need to wait for an operand A + // to be ready to read + || (dcd_A_stall) + // Likewise for B, also includes logic + // regarding immediate offset (register must + // be in register file if we need to add to + // an immediate) + ||(dcd_B_stall) + // Or if we need to wait on flags to work on the + // CC register + ||(dcd_F_stall) + ); + // }}} + assign op_ce = ((dcd_valid)||(dcd_illegal)||(dcd_early_branch))&&(!op_stall); + + end else begin : NO_OP_STALLS // !OPT_PIPELINED + // {{{ + assign op_stall = 1'b0; // (o_break)||(pending_interrupt); + assign op_ce = ((dcd_valid)||(dcd_early_branch))&&(!op_stall); + assign pending_sreg_write = 1'b0; + assign cc_invalid_for_dcd = 1'b0; + + // Verilator lint_off UNUSED + wire pipe_unused; + assign pipe_unused = &{ 1'b0, cc_invalid_for_dcd, + pending_sreg_write }; + // Verilator lint_on UNUSED + // }}} + end endgenerate + + // BUT ... op_ce is too complex for many of the data operations. So + // let's make their circuit enable code simpler. In particular, if + // op_ doesn't need to be preserved, we can change it all we want + // ... right? The clear_pipeline code, for example, really only needs + // to determine whether op_valid is true. + // assign op_change_data_ce = (!op_stall); + // }}} + // + // PIPELINE STAGE #4 :: ALU / Memory + // {{{ + // 1. Basic stall is if the previous stage is valid and the next is + // busy. + // 2. Also stall if the prior stage is valid and the master clock enable + // is de-selected + // 3. Stall if someone on the other end is writing the CC register, + // since we don't know if it'll put us to sleep or not. + // 4. Last case: Stall if we would otherwise move a break instruction + // through the ALU. Break instructions are not allowed through + // the ALU. + generate if (OPT_PIPELINED) + begin : GEN_ALU_STALL + // alu_stall, alu_ce + // {{{ + assign alu_stall = (((master_stall)||(i_mem_rdbusy))&&(op_valid_alu)) //Case 1&2 + ||(wr_reg_ce)&&(wr_write_cc); + // assign // alu_ce = (master_ce)&&(op_valid_alu)&&(!alu_stall) + // &&(!clear_pipeline)&&(!op_illegal) + // &&(!pending_sreg_write) + // &&(!alu_sreg_stall); + assign alu_ce = (adf_ce_unconditional)&&(op_valid_alu); + + // Verilator lint_off unused + wire unused_alu_stall = alu_stall; + // Verilator lint_on unused + // }}} + end else begin : NO_ALU_STALLS + // alu_stall, alu_ce + // {{{ + assign alu_stall = (master_stall); + //assign alu_ce = (master_ce)&&(op_valid_alu) + // &&(!clear_pipeline) + // &&(!alu_stall); + assign alu_ce = (adf_ce_unconditional)&&(op_valid_alu); + + // Verilator lint_off unused + wire unused_alu_stall = alu_stall; + // Verilator lint_on unused + // }}} + end endgenerate + // + + // mem_ce + // {{{ + // Note: if you change the conditions for mem_ce, you must also change + // alu_pc_valid. + // + assign mem_ce = (master_ce)&&(op_valid_mem)&&(!mem_stalled) + &&(!clear_pipeline); + // }}} + + // mem_stalled + // {{{ + generate if (OPT_PIPELINED_BUS_ACCESS) + begin + // {{{ + assign mem_stalled = (master_stall)||((op_valid_mem)&&( + (i_mem_pipe_stalled) + ||(i_bus_err)||(div_error) + ||((!op_pipe)&&(i_mem_busy)) + // Stall waiting for flags to be valid + // Or waiting for a write to the PC register + // Or CC register, since that can change the + // PC as well + ||((wr_reg_ce) + &&((wr_write_pc)||(wr_write_cc))))); + // }}} + end else if (OPT_PIPELINED) + begin + // {{{ + assign mem_stalled = (master_stall)||((op_valid_mem)&&( + (i_bus_err)||(div_error)||(i_mem_busy) + // Stall waiting for flags to be valid + // Or waiting for a write to the PC register + // Or CC register, since that can change the + // PC as well + ||((wr_reg_ce) + &&((wr_write_pc)||(wr_write_cc))))); + // }}} + end else begin + // {{{ + assign mem_stalled = master_stall || i_mem_busy; + // }}} + end endgenerate + // }}} + // }}} + + // + // Master stall condition + // {{{ + assign master_stall = (!master_ce)||(!op_valid)||(ill_err_i) + ||(ibus_err_flag)||(idiv_err_flag) + ||(pending_interrupt)&&(!alu_phase) + ||(alu_busy)||(div_busy)||(fpu_busy)||(op_break) + ||((OPT_PIPELINED)&&( + prelock_stall + ||((i_mem_busy)&&(op_illegal)) + ||((i_mem_busy)&&(op_valid_div)) + ||(alu_illegal)||(o_break))); + // }}} + // + // (Everything but memory) stall condition + // {{{ + + // ALU, DIV, or FPU CE ... equivalent to the OR of all three of these + always @(*) + if (OPT_PIPELINED) + adf_ce_unconditional = + (!master_stall)&&(!op_valid_mem)&&(!i_mem_rdbusy) + &&((!i_mem_busy)||(!op_wR)||(op_R[4:1] != { gie, 3'h7})); + else + adf_ce_unconditional = (!master_stall)&&(op_valid)&&(!op_valid_mem); + // }}} + // }}} + //////////////////////////////////////////////////////////////////////// + // + // PIPELINE STAGE #1 :: Instruction fetch + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + assign o_pf_ready = (!dcd_stalled && !dcd_phase); + + assign o_pf_new_pc = (new_pc)||((dcd_early_branch_stb)&&(!clear_pipeline)); + + assign o_pf_request_address = ((dcd_early_branch_stb)&&(!clear_pipeline)) + ? dcd_branch_pc:pf_pc; + assign pf_gie = gie; + // }}} + //////////////////////////////////////////////////////////////////////// + // + // PIPELINE STAGE #2 :: Instruction Decode + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + assign dcd_ce =((OPT_PIPELINED)&&(!dcd_valid))||(!dcd_stalled); + wire [6:0] dcd_full_R, dcd_full_A, dcd_full_B; + + idecode #( + // {{{ + .ADDRESS_WIDTH(AW), + .OPT_MPY((IMPLEMENT_MPY!=0)? 1'b1:1'b0), + .OPT_PIPELINED(OPT_PIPELINED), + .OPT_EARLY_BRANCHING(OPT_EARLY_BRANCHING), + .OPT_DIVIDE(IMPLEMENT_DIVIDE), + .OPT_FPU(IMPLEMENT_FPU), + .OPT_LOCK(OPT_LOCK), + .OPT_OPIPE(OPT_PIPELINED_BUS_ACCESS), + .OPT_NO_USERMODE(OPT_NO_USERMODE), +`ifdef VERILATOR + .OPT_SIM(1'b1), +`else + .OPT_SIM(1'b0), +`endif + .OPT_CIS(OPT_CIS) + // }}} + ) instruction_decoder( + // {{{ + i_clk, (i_reset)||(clear_pipeline)||(o_clear_icache), + dcd_ce, + dcd_stalled, i_pf_instruction, pf_gie, + i_pf_instruction_pc, i_pf_valid, i_pf_illegal, + dcd_valid, dcd_phase, + dcd_illegal, dcd_pc, + dcd_full_R, dcd_full_A, dcd_full_B, + dcd_preA, dcd_preB, + dcd_I, dcd_zI, dcd_F, dcd_wF, dcd_opn, + dcd_ALU, dcd_M, dcd_DIV, dcd_FP, dcd_break, dcd_lock, + dcd_wR,dcd_rA, dcd_rB, + dcd_early_branch, dcd_early_branch_stb, + dcd_branch_pc, dcd_ljmp, + dcd_pipe, + dcd_sim, dcd_sim_immv +`ifdef FORMAL + , f_dcd_insn_word, f_dcd_insn_gie +`endif + // }}} + ); + + assign { dcd_Rcc, dcd_Rpc, dcd_R } = dcd_full_R; + assign { dcd_Acc, dcd_Apc, dcd_A } = dcd_full_A; + assign { dcd_Bcc, dcd_Bpc, dcd_B } = dcd_full_B; + assign dcd_gie = pf_gie; + // }}} + //////////////////////////////////////////////////////////////////////// + // + // PIPELINE STAGE #3 :: Read Operands (Registers) + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + // op_pipe + // {{{ + generate if (OPT_PIPELINED_BUS_ACCESS) + begin : GEN_OP_PIPE + reg r_op_pipe; + + // To be a pipeable operation, there must be + // two valid adjacent instructions + // Both must be memory instructions + // Both must be writes, or both must be reads + // Both operations must be to the same identical address, + // or at least a single (one) increment above that + // address + // + // However ... we need to know this before this clock, hence + // this is calculated in the instruction decoder. + initial r_op_pipe = 1'b0; + always @(posedge i_clk) + if ((OPT_LOWPOWER && i_reset)||(clear_pipeline)||(i_halt)) + r_op_pipe <= 1'b0; + else if (op_ce) + r_op_pipe <= (dcd_pipe)&&(op_valid_mem)&&(!OPT_LOWPOWER || !dcd_illegal); + else if ((wr_reg_ce)&&(wr_reg_id == op_Bid[4:0])) + r_op_pipe <= 1'b0; + else if (mem_ce) // Clear us any time an op_ is clocked in + r_op_pipe <= 1'b0; + + assign op_pipe = r_op_pipe; +`ifdef FORMAL + always @(*) + if (OPT_LOWPOWER && !op_valid_mem) + assert(!r_op_pipe); +`endif + end else begin + + assign op_pipe = 1'b0; + + end endgenerate + // }}} + + // Read from our register set + // {{{ +// `define NO_DISTRIBUTED_RAM +`ifdef NO_DISTRIBUTED_RAM + reg [31:0] pre_rewrite_value, pre_op_Av, pre_op_Bv; + reg pre_rewrite_flag_A, pre_rewrite_flag_B; + + always @(posedge i_clk) + if (dcd_ce) + begin + pre_rewrite_flag_A <= (wr_reg_ce)&&(dcd_preA == wr_reg_id); + pre_rewrite_flag_B <= (wr_reg_ce)&&(dcd_preB == wr_reg_id); + pre_rewrite_value <= wr_gpreg_vl; + end + + generate if (OPT_NO_USERMODE) + begin + always @(posedge i_clk) + if (dcd_ce) + begin + pre_op_Av <= regset[dcd_preA[3:0]]; + pre_op_Bv <= regset[dcd_preB[3:0]]; + end + end else begin + + always @(posedge i_clk) + if (dcd_ce) + begin + pre_op_Av <= regset[dcd_preA]; + pre_op_Bv <= regset[dcd_preB]; + end + + end endgenerate + + assign w_op_Av = (pre_rewrite_flag_A) ? pre_rewrite_value : pre_op_Av; + assign w_op_Bv = (pre_rewrite_flag_B) ? pre_rewrite_value : pre_op_Bv; +`else + generate if (OPT_NO_USERMODE) + begin + assign w_op_Av = regset[dcd_A[3:0]]; + assign w_op_Bv = regset[dcd_B[3:0]]; + end else begin + + assign w_op_Av = regset[dcd_A]; + assign w_op_Bv = regset[dcd_B]; + + end endgenerate + + // verilator lint_off UNUSED + wire unused_prereg_addrs; + assign unused_prereg_addrs = &{ 1'b0, dcd_preA, dcd_preB }; + // verilator lint_on UNUSED +`endif + // }}} + + assign w_cpu_info = { + // {{{ + 1'b1, + (IMPLEMENT_MPY >0)? 1'b1:1'b0, + (IMPLEMENT_DIVIDE >0)? 1'b1:1'b0, + (IMPLEMENT_FPU >0)? 1'b1:1'b0, + OPT_PIPELINED, + 1'b0, + (OPT_EARLY_BRANCHING > 0)? 1'b1:1'b0, + OPT_PIPELINED_BUS_ACCESS, + OPT_CIS + }; + // }}} + + always @(*) + begin + w_pcA_v = 0; + if ((OPT_NO_USERMODE)||(dcd_A[4] == dcd_gie)) + w_pcA_v[(AW+1):0] = { dcd_pc[AW+1:2], 2'b00 }; + else + w_pcA_v[(AW+1):0] = { upc[(AW+1):2], uhalt_phase, 1'b0 }; + end + + // Op register addresses + // {{{ + generate if (OPT_PIPELINED) + begin : OP_REG_ADVANEC + // {{{ + initial op_R = 0; + initial op_Aid = 0; + initial op_Bid = 0; + initial op_rA = 0; + initial op_rB = 0; + initial op_Rcc = 0; + always @(posedge i_clk) + begin + if (op_ce && (!OPT_LOWPOWER || w_op_valid)) + begin + op_R <= dcd_R; + op_Aid <= dcd_A; + if ((dcd_rB)&&(!dcd_early_branch)&&(!dcd_illegal)) + op_Bid <= dcd_B; + op_rA <= (dcd_rA)&&(!dcd_early_branch)&&(!dcd_illegal); + op_rB <= (dcd_rB)&&(!dcd_early_branch)&&(!dcd_illegal); + op_Rcc <= (dcd_Rcc)&&(dcd_wR)&&(dcd_R[4]==dcd_gie); + end + + if (op_lowpower_clear) + begin + op_rA <= 1'b0; + op_rB <= 1'b0; + end + end + // }}} + end else begin : OP_REG_COPY + // {{{ + always @(*) + begin + op_R = dcd_R; + op_Aid = dcd_A; + op_Bid = dcd_B; + op_rA = dcd_rA; + op_rB = dcd_rB; + op_Rcc = (dcd_Rcc)&&(dcd_wR)&&(dcd_R[4]==dcd_gie); + end + // }}} + end endgenerate + // }}} + + // r_op_Av -- The registered value of the op A register + // {{{ + reg [2:0] avsrc; + reg [2:0] bvsrc; + reg [1:0] bisrc; + + always @(*) + begin + avsrc = 3'b000; + if (!OPT_PIPELINED || op_ce) + begin + if (dcd_Apc) + avsrc = 3'b101; + else if (dcd_Acc) + avsrc = 3'b110; + else + avsrc = 3'b111; + end + + if (OPT_PIPELINED && wr_reg_ce) + begin + if (!op_ce && wr_reg_id == op_Aid && op_rA) + avsrc = 3'b100; + else if (op_ce && wr_reg_id == dcd_A) + avsrc = 3'b100; + end + end + +// 44313 + initial r_op_Av = 0; + always @(posedge i_clk) + begin + if (avsrc[2]) + case(avsrc[1:0]) + 2'b00: r_op_Av <= wr_gpreg_vl; + 2'b01: r_op_Av <= w_pcA_v; + 2'b10: r_op_Av <= { w_cpu_info, w_op_Av[22:16], (dcd_A[4])?w_uflags:w_iflags }; + 2'b11: r_op_Av <= w_op_Av; + endcase + + if (op_lowpower_clear) + r_op_Av <= 0; + end + // }}} + + // w_op_B -- The registered value of the op B register + // {{{ + always @(*) + begin + w_pcB_v = 0; + if ((OPT_NO_USERMODE)||(dcd_B[4] == dcd_gie)) + w_pcB_v[(AW+1):0] = { dcd_pc[AW+1:2], 2'b00 }; + else + w_pcB_v[(AW+1):0] = { upc[(AW+1):2], uhalt_phase, 1'b0 }; + end + + always @(*) + if (!dcd_rB) + bisrc = 0; + else if ((OPT_PIPELINED)&&(wr_reg_ce)&&(wr_reg_id == dcd_B)) + bisrc = 1; + else if (dcd_Bcc) + bisrc = 2; + else + bisrc = 3; + + always @(*) + case(bisrc[1:0]) + 2'b00: w_op_BnI = 0; + 2'b01: w_op_BnI = wr_gpreg_vl; + 2'b10: w_op_BnI = { w_cpu_info, w_op_Bv[22:16], + (dcd_B[4]) ? w_uflags : w_iflags }; + 2'b11: w_op_BnI = w_op_Bv; + endcase + + always @(*) + begin + bvsrc = 0; + if ((!OPT_PIPELINED)||(op_ce)) + begin + if ((dcd_Bpc)&&(dcd_rB)) + bvsrc = 3'b100; + else + bvsrc = 3'b101; + end else if ((OPT_PIPELINED)&&(op_rB) + &&(wr_reg_ce)&&(op_Bid == wr_reg_id)) + bvsrc = 3'b110; + end + + initial r_op_Bv = 0; + always @(posedge i_clk) + begin + if (bvsrc[2]) casez(bvsrc[1:0]) + 2'b00: r_op_Bv <= w_pcB_v + { dcd_I[29:0], 2'b00 }; + 2'b01: r_op_Bv <= w_op_BnI + dcd_I; + 2'b1?: r_op_Bv <= wr_gpreg_vl; + endcase + + if (op_lowpower_clear) + r_op_Bv <= 0; + end + // }}} + + // op_F + // {{{ + // The logic here has become more complex than it should be, no thanks + // to Xilinx's Vivado trying to help. The conditions are supposed to + // be two sets of four bits: the top bits specify what bits matter, the + // bottom specify what those top bits must equal. However, two of + // conditions check whether bits are on, and those are the only two + // conditions checking those bits. Therefore, Vivado complains that + // these two bits are redundant. Hence the convoluted expression + // below, arriving at what we finally want in the (now wire net) + // op_F. + initial r_op_F = 7'h00; + always @(posedge i_clk) + begin + if ((!OPT_PIPELINED)||(op_ce)) + // Cannot do op_change_data_ce here since op_F depends + // upon being either correct for a valid op, or correct + // for the last valid op + begin // Set the flag condition codes, bit order is [3:0]=VNCZ + case(dcd_F[2:0]) + 3'h0: r_op_F <= 7'h00; // Always + 3'h1: r_op_F <= 7'h11; // Z + 3'h2: r_op_F <= 7'h44; // LT + 3'h3: r_op_F <= 7'h22; // C + 3'h4: r_op_F <= 7'h08; // V + 3'h5: r_op_F <= 7'h10; // NE + 3'h6: r_op_F <= 7'h40; // GE (!N) + 3'h7: r_op_F <= 7'h20; // NC + endcase + end + + if (op_lowpower_clear) + r_op_F <= 7'h00; + end // Bit order is { (flags_not_used), VNCZ mask, VNCZ value } + assign op_F = { r_op_F[3], r_op_F[6:0] }; + // }}} + + // op_valid + // {{{ + assign w_op_valid = (!clear_pipeline)&&(dcd_valid) + &&(!dcd_ljmp)&&(!dcd_early_branch); + + initial op_valid = 1'b0; + initial op_valid_alu = 1'b0; + initial op_valid_mem = 1'b0; + initial op_valid_div = 1'b0; + initial op_valid_fpu = 1'b0; + always @(posedge i_clk) + if ((i_reset)||(clear_pipeline)) + begin + // {{{ + op_valid <= 1'b0; + op_valid_alu <= 1'b0; + op_valid_mem <= 1'b0; + op_valid_div <= 1'b0; + op_valid_fpu <= 1'b0; + // }}} + end else if (op_ce) + begin + // {{{ + // Do we have a valid instruction? + // The decoder may vote to stall one of its + // instructions based upon something we currently + // have in our queue. This instruction must then + // move forward, and get a stall cycle inserted. + // Hence, the test on dcd_stalled here. If we must + // wait until our operands are valid, then we aren't + // valid yet until then. + if (OPT_PIPELINED || !op_valid) + begin + op_valid <= (w_op_valid)||(dcd_early_branch); + op_valid_alu <= (w_op_valid)&&((dcd_ALU)||(dcd_illegal)); + op_valid_mem <= (dcd_M)&&(!dcd_illegal) + &&(w_op_valid); + op_valid_div <= (IMPLEMENT_DIVIDE)&&(dcd_DIV)&&(!dcd_illegal)&&(w_op_valid); + op_valid_fpu <= (IMPLEMENT_FPU)&&(dcd_FP)&&(!dcd_illegal)&&(w_op_valid); + end else if ((adf_ce_unconditional)||(mem_ce)) + begin + op_valid <= 1'b0; + op_valid_alu <= 1'b0; + op_valid_mem <= 1'b0; + op_valid_div <= 1'b0; + op_valid_fpu <= 1'b0; + end + // }}} + end else if ((adf_ce_unconditional)||(mem_ce)) + begin + // {{{ + // If nothing advances into the OP stage, yet what was in + // the OP stage moves forward, then we need to invalidate what + // used to be here. + op_valid <= 1'b0; + op_valid_alu <= 1'b0; + op_valid_mem <= 1'b0; + op_valid_div <= 1'b0; + op_valid_fpu <= 1'b0; + // }}} + end + // }}} + + // op_lowpower_clear + // {{{ + generate if (!OPT_LOWPOWER || !OPT_PIPELINED) + begin : NO_OP_LOWPOWER_CLEAR + + assign op_lowpower_clear = 1'b0; + + end else begin : GEN_OP_LOWPOWER_CLEAR + reg r_op_lowpower_clear; + + always @(*) + if (i_reset || clear_pipeline) + r_op_lowpower_clear = 1'b1; + else if (op_ce && !w_op_valid) + r_op_lowpower_clear = 1'b1; + else if ((!op_ce || !w_op_valid)&&(adf_ce_unconditional || mem_ce)) + r_op_lowpower_clear = 1'b1; + else + r_op_lowpower_clear = 1'b0; + + assign op_lowpower_clear = r_op_lowpower_clear; + end endgenerate + // }}} + + // op_break + // {{{ + // Here's part of our debug interface. When we recognize a break + // instruction, we set the op_break flag. That'll prevent this + // instruction from entering the ALU, and cause an interrupt before + // this instruction. Thus, returning to this code will cause the + // break to repeat and continue upon return. To get out of this + // condition, replace the break instruction with what it is supposed + // to be, step through it, and then replace it back. In this fashion, + // a debugger can step through code. + // assign w_op_break = (dcd_break)&&(r_dcd_I[15:0] == 16'h0001); + + initial r_op_break = 1'b0; + always @(posedge i_clk) + if (clear_pipeline) + r_op_break <= 1'b0; + else if ((OPT_PIPELINED)&&(op_ce)) + r_op_break <= (dcd_valid)&&(dcd_break)&&(!dcd_illegal); + else if ((!OPT_PIPELINED)&&(dcd_valid)) + r_op_break <= (dcd_break)&&(!dcd_illegal); + + assign op_break = r_op_break; + // }}} + + // op_lock + // {{{ + generate if ((!OPT_PIPELINED)||(!OPT_LOCK)) + begin : NO_OPLOCK + + assign op_lock = 1'b0; + + // Verilator lint_off UNUSED + wire dcd_lock_unused; + assign dcd_lock_unused = dcd_lock; + // Verilator lint_on UNUSED + + end else // if (IMPLEMENT_LOCK != 0) + begin : OPLOCK + reg r_op_lock; + + initial r_op_lock = 1'b0; + always @(posedge i_clk) + if (clear_pipeline) + r_op_lock <= 1'b0; + else if (op_ce) + r_op_lock <= (dcd_valid)&&(dcd_lock) + &&(!dcd_illegal); + assign op_lock = r_op_lock; + + end endgenerate + // }}} + + // op_illegal + // {{{ + initial op_illegal = 1'b0; + always @(posedge i_clk) + if ((i_reset)||(clear_pipeline)) + op_illegal <= 1'b0; + else if (OPT_PIPELINED) + begin + if (op_ce) + op_illegal <= (dcd_valid)&&(!dcd_ljmp) + &&(!dcd_early_branch)&&(dcd_illegal); + end else if (!OPT_PIPELINED) + begin + if (dcd_valid) + op_illegal <= (!dcd_ljmp)&&(!dcd_early_branch)&&(dcd_illegal); + end + // }}} + + // op_wF + // {{{ + always @(posedge i_clk) + begin + if ((!OPT_PIPELINED)||(op_ce)) + op_wF <= (dcd_wF)&&((!dcd_Rcc)||(!dcd_wR)) + &&(!dcd_early_branch); + + if (op_lowpower_clear) + op_wF <= 1'b0; + end + // }}} + + // op_wR + // {{{ + generate if ((OPT_PIPELINED)||(OPT_EARLY_BRANCHING)) + begin + + initial op_wR = 1'b0; + always @(posedge i_clk) + begin + if (op_ce) + op_wR <= (dcd_wR)&&(!dcd_early_branch); + if (op_lowpower_clear) + op_wR <= 1'b0; + end + + end else begin + + always @(*) + op_wR = (dcd_wR); + + end endgenerate + // }}} + + // op_sim, op_sim_immv, alu_sim, alu_sim_immv + // {{{ +`ifdef VERILATOR + always @(posedge i_clk) + if (op_ce) + begin + op_sim <= dcd_sim; + op_sim_immv <= dcd_sim_immv; + end else if (adf_ce_unconditional) + op_sim <= 1'b0; + + // + // We need an extra ALU sim stage. + // + // It's not quite true that all instructions leaving the OP stage + // are committed. ALU instructions aren't committed until the next + // cycle. That way they don't need to wait to determine if a branch + // was taken or not. + always @(posedge i_clk) + begin + if (adf_ce_unconditional) + alu_sim <= op_sim && op_valid_alu; + else + alu_sim <= 1'b0; + + if (adf_ce_unconditional) + alu_sim_immv <= op_sim_immv; + + if (i_reset || clear_pipeline) + alu_sim <= 1'b0; + end +`endif + // }}} + + // op_pc + // {{{ + generate if ((OPT_PIPELINED)||(OPT_EARLY_BRANCHING)) + begin : SET_OP_PC + + initial op_pc[0] = 1'b0; + always @(posedge i_clk) + if (op_ce && (!OPT_LOWPOWER || w_op_valid)) + op_pc <= (dcd_early_branch)?dcd_branch_pc:dcd_pc; + + end else begin : SET_OP_PC + + always @(*) + op_pc = dcd_pc; + + end endgenerate + // }}} + + // op_opn -- the opcode of the current operation + // {{{ + generate if (!OPT_PIPELINED) + begin : COPY_DCD_OPN + + assign op_opn = dcd_opn; + + end else begin : FWD_OPERATION + + reg [3:0] r_op_opn; + + always @(posedge i_clk) + if (op_ce && (!OPT_LOWPOWER || w_op_valid || dcd_early_branch)) + begin + // Which ALU operation? Early branches are + // unimplemented moves + r_op_opn <= ((dcd_early_branch)||(dcd_illegal)) + ? CPU_MOV_OP : dcd_opn; + // opM <= dcd_M; // Is this a memory operation? + // What register will these results be written into? + end + + assign op_opn = r_op_opn; + + end endgenerate + // }}} + assign op_gie = gie; + + assign op_Fl = (op_gie)?(w_uflags[3:0]):(w_iflags[3:0]); + + // op_phase + // {{{ + generate if (OPT_CIS) + begin : OPT_CIS_OP_PHASE + + reg r_op_phase; + + initial r_op_phase = 1'b0; + always @(posedge i_clk) + if ((i_reset)||(clear_pipeline)) + r_op_phase <= 1'b0; + else if (op_ce) + r_op_phase <= (dcd_phase)&&((!dcd_wR)||(!dcd_Rpc)); + + assign op_phase = r_op_phase; + end else begin : OPT_NOCIS_OP_PHASE + assign op_phase = 1'b0; + + // verilator lint_off UNUSED + wire OPT_CIS_dcdRpc; + assign OPT_CIS_dcdRpc = dcd_Rpc; + // verilator lint_on UNUSED + end endgenerate + // }}} + + // op_Av -- the combinatorial A value input to the ALU/MEM/DIV stage + // {{{ + // This is tricky. First, the PC and Flags registers aren't kept in + // register set but in special registers of their own. So step one + // is to select the right register. Step to is to replace that + // register with the results of an ALU or memory operation, if such + // results are now available. Otherwise, we'd need to insert a wait + // state of some type. + // + // The alternative approach would be to define some sort of + // op_stall wire, which would stall any upstream stage. + // We'll create a flag here to start our coordination. Once we + // define this flag to something other than just plain zero, then + // the stalls will already be in place. + generate if (OPT_PIPELINED) + begin + + assign op_Av = ((wr_reg_ce)&&(wr_reg_id == op_Aid)) + ? wr_gpreg_vl : r_op_Av; + + end else begin + + assign op_Av = r_op_Av; + + end endgenerate + // }}} + + // dcd_A_stall + // {{{ + // Stall if we have decoded an instruction that will read register A + // AND ... something that may write a register is running + // AND (series of conditions here ...) + // The operation might set flags, and we wish to read the + // CC register + // OR ... (No other conditions) + generate if (OPT_PIPELINED) + begin + + assign dcd_A_stall = (dcd_rA) // &&(dcd_valid) is checked for elsewhere + &&((op_valid)||(i_mem_rdbusy) + ||(div_busy)||(fpu_busy)) + &&(((op_wF)||(cc_invalid_for_dcd))&&(dcd_Acc)) + ||((dcd_rA)&&(dcd_Acc)&&(cc_invalid_for_dcd)); + end else begin + + // There are no pipeline hazards, if we aren't pipelined + assign dcd_A_stall = 1'b0; + + end endgenerate + // }}} + + // op_Bv + // {{{ + assign op_Bv = ((OPT_PIPELINED)&&(wr_reg_ce) + &&(wr_reg_id == op_Bid)&&(op_rB)) + ? wr_gpreg_vl: r_op_Bv; + // }}} + + // dcd_B_stall, dcd_F_stall + // {{{ + generate if (OPT_PIPELINED) + begin : DCD_BF_STALLS + // Stall if we have decoded an instruction that will read register B + // AND ... something that may write a (unknown) register is running + // AND (series of conditions here ...) + // The operation might set flags, and we wish to read the + // CC register + // OR the operation might set register B, and we still need + // a clock to add the offset to it + assign dcd_B_stall = (dcd_rB) // &&(dcd_valid) is checked for elsewhere + // {{{ + // If the op stage isn't valid, yet something + // is running, then it must have been valid. + // We'll use the last values from that stage + // (op_wR, op_wF, op_R) in our logic below. + &&((op_valid)||(i_mem_rdbusy) + ||(div_busy)||(fpu_busy)||(alu_busy)) + &&( + // Okay, what happens if the result register + // from instruction 1 becomes the input for + // instruction two, *and* there's an immediate + // offset in instruction two? In that case, we + // need an extra clock between the two + // instructions to calculate the base plus + // offset. + // + // What if instruction 1 (or before) is in a + // memory pipeline? We may no longer know what + // the register was! We will then need to + // blindly wait. We'll temper this only waiting + // if we're not piping this new instruction. + // If we were piping, the pipe logic in the + // decode circuit has told us that the hazard + // is clear, so we're okay then. + // + ((!dcd_zI)&&( + ((op_R == dcd_B)&&(op_wR)) + ||((i_mem_rdbusy)&&(!dcd_pipe)) + ||(((alu_busy || + div_busy || i_mem_rdbusy)) + &&(alu_reg == dcd_B)) + ||((wr_reg_ce)&&(wr_reg_id[3:1] == 3'h7)) + )) + // Stall following any instruction that will + // set the flags, if we're going to need the + // flags (CC) register for op_B. + ||(((op_wF)||(cc_invalid_for_dcd))&&(dcd_Bcc)) + // Stall on any ongoing memory operation that + // will write to op_B -- captured above + // ||((i_mem_busy)&&(!mem_we)&&(mem_last_reg==dcd_B)&&(!dcd_zI)) + ) + ||((dcd_rB)&&(dcd_Bcc)&&(cc_invalid_for_dcd)); + // }}} + assign dcd_F_stall = ((!dcd_F[3]) + // {{{ + ||((dcd_rA)&&(dcd_A[3:1]==3'h7) + &&(dcd_A[4:0] != { gie, 4'hf})) + ||((dcd_rB)&&(dcd_B[3:1]==3'h7)) + &&(dcd_B[4:0] != { gie, 4'hf})) + &&(((op_valid)&&(op_wR) + &&(op_R[3:1]==3'h7) + &&(op_R[4:0]!={gie, 4'hf})) + ||(pending_sreg_write)); + // &&(dcd_valid) is checked for elsewhere + // }}} + end else begin : NO_PIPELINE_NO_STALL + // {{{ + // No stalls without pipelining, 'cause how can you have a + // pipeline hazard without the pipeline? + assign dcd_B_stall = 1'b0; + assign dcd_F_stall = 1'b0; + // }}} + end endgenerate + // }}} + + // }}} + //////////////////////////////////////////////////////////////////////// + // + // PIPELINE STAGE #4 :: Apply Instruction + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + // The ALU itself + cpuops #( + // {{{ + .IMPLEMENT_MPY(IMPLEMENT_MPY), + .OPT_SHIFTS(IMPLEMENT_SHIFTS) + // }}} + ) doalu( + // {{{ + i_clk, ((i_reset)||(clear_pipeline)), + alu_ce, op_opn, op_Av, op_Bv, + alu_result, alu_flags, alu_valid, alu_busy); + // }}} + + // Divide + // {{{ + generate if (IMPLEMENT_DIVIDE != 0) + begin : DIVIDE +`ifdef FORMAL +`define DIVIDE_MODULE abs_div +`else +`define DIVIDE_MODULE div +`endif + `DIVIDE_MODULE thedivide(i_clk, ((i_reset)||(clear_pipeline)), + div_ce, op_opn[0], + op_Av, op_Bv, div_busy, div_valid, div_error, div_result, + div_flags); + + end else begin + // {{{ + assign div_error = 1'b0; // Can't be high unless div_valid + assign div_busy = 1'b0; + assign div_valid = 1'b0; + assign div_result= 32'h00; + assign div_flags = 4'h0; + + // Make verilator happy here + // verilator lint_off UNUSED + wire unused_divide; + assign unused_divide = div_ce; + // verilator lint_on UNUSED + // }}} + end endgenerate + // }}} + + // (Non-existent) FPU + // {{{ + generate if (IMPLEMENT_FPU != 0) + begin : FPU + // + // sfpu thefpu(i_clk, i_reset, fpu_ce, op_opn[2:0], + // op_Av, op_Bv, fpu_busy, fpu_valid, fpu_err, fpu_result, + // fpu_flags); + // +`ifdef FORMAL + abs_div thefpu(i_clk, ((i_reset)||(clear_pipeline)), + fpu_ce, op_opn[2:0], + op_Av, op_Bv, fpu_busy, fpu_valid, fpu_error, fpu_result, + fpu_flags); + +`else + assign fpu_error = 1'b0; // Must only be true if fpu_valid + assign fpu_busy = 1'b0; + assign fpu_valid = 1'b0; + assign fpu_result= 32'h00; + assign fpu_flags = 4'h0; +`endif + end else begin + assign fpu_error = 1'b0; + assign fpu_busy = 1'b0; + assign fpu_valid = 1'b0; + assign fpu_result= 32'h00; + assign fpu_flags = 4'h0; + end endgenerate + // }}} + + // Condition handling + // {{{ + assign set_cond = ((op_F[7:4]&op_Fl[3:0])==op_F[3:0]); + initial alu_wF = 1'b0; + initial alu_wR = 1'b0; + generate if (OPT_PIPELINED) + begin + always @(posedge i_clk) + if (i_reset) + begin + alu_wR <= 1'b0; + alu_wF <= 1'b0; + end else if (alu_ce) + begin + // alu_reg <= op_R; + alu_wR <= (op_wR)&&(set_cond)&&(!op_illegal); + alu_wF <= (op_wF)&&(set_cond)&&(!op_illegal); + end else if (!alu_busy) begin + // These are strobe signals, so clear them if not + // set for any particular clock + alu_wR <= (r_halted)&&(i_dbg_we && !o_dbg_stall); + alu_wF <= 1'b0; + end + end else begin + + always @(posedge i_clk) + begin + alu_wR <= (op_wR)&&(set_cond)&&(!op_illegal); + alu_wF <= (op_wF)&&(set_cond)&&(!op_illegal); + end + + end endgenerate + // }}} + + // alu_phase + // {{{ + // Instruction phase (which half of the instruction we are on) tracking + generate if (OPT_CIS) + begin : GEN_ALU_PHASE + + reg r_alu_phase; + + initial r_alu_phase = 1'b0; + always @(posedge i_clk) + if ((i_reset)||(clear_pipeline)) + r_alu_phase <= 1'b0; + else if (((adf_ce_unconditional)||(mem_ce))&&(op_valid)) + r_alu_phase <= op_phase; + else if ((adf_ce_unconditional)||(mem_ce)) + r_alu_phase <= 1'b0; + + assign alu_phase = r_alu_phase; + end else begin + + assign alu_phase = 1'b0; + end endgenerate + // }}} + + // alu_reg + // {{{ + generate if (OPT_PIPELINED) + begin + + always @(posedge i_clk) + if (alu_ce || div_ce || o_mem_ce || fpu_ce) + alu_reg <= op_R; + else if (i_dbg_we && !o_dbg_stall) + alu_reg <= i_dbg_wreg; + + end else begin + + always @(posedge i_clk) + if (i_dbg_we && !o_dbg_stall) + alu_reg <= i_dbg_wreg; + else + alu_reg <= op_R; + end endgenerate + // }}} + + // wr_index + // {{{ + initial wr_index = 0; + always @(posedge i_clk) + begin + if ((OPT_PIPELINED && (mem_ce || adf_ce_unconditional)) + ||(!OPT_PIPELINED && op_valid)) + begin + wr_index <= 0; + /* + if (op_valid_mem) + wr_index <= 3'b001; + if (op_valid_alu) + wr_index <= 3'b010; + if (op_valid_div) + wr_index <= 3'b011; + if (op_valid_fpu) + wr_index <= 3'b100; + */ + + wr_index[0] <= (op_valid_mem | op_valid_div); + wr_index[1] <= (op_valid_alu | op_valid_div); + wr_index[2] <= (op_valid_fpu); + end + + if (i_dbg_we && !o_dbg_stall) + wr_index <= 3'b000; + + if (!IMPLEMENT_FPU) + wr_index[2] <= 1'b0; + end + // }}} + + // + // DEBUG Register write access starts here + // + // {{{ + initial dbgv = 1'b0; + always @(posedge i_clk) + if (i_reset || !r_halted) + dbgv <= 0; + else + dbgv <= i_dbg_we && !o_dbg_stall; + + always @(posedge i_clk) + dbg_val <= i_dbg_data; + + // dbg_clear_pipe + // {{{ + always @(posedge i_clk) + if (i_reset || clear_pipeline || !r_halted) + dbg_clear_pipe <= 0; + else if (i_dbg_we && !o_dbg_stall) + begin + dbg_clear_pipe <= 1'b0; + + if (!OPT_PIPELINED) + dbg_clear_pipe <= 1'b1; + if ((i_dbg_wreg == op_Bid)&&(op_rB)) + dbg_clear_pipe <= 1'b1; + if (i_dbg_wreg[3:1] == 3'h7) + dbg_clear_pipe <= 1'b1; + end else if ((!OPT_PIPELINED)&&(i_clear_cache && !o_dbg_stall)) + dbg_clear_pipe <= 1'b1; + else + dbg_clear_pipe <= 1'b0; + // }}} + + assign alu_gie = gie; + // }}} + + // r_alu_pc + // {{{ + generate if (OPT_PIPELINED) + begin : GEN_ALU_PC + reg [(AW+1):0] r_alu_pc; + initial r_alu_pc = 0; + always @(posedge i_clk) + if ((adf_ce_unconditional) + ||((master_ce)&&(op_valid_mem) + &&(!clear_pipeline)&&(!mem_stalled))) + r_alu_pc <= op_pc; + assign alu_pc = r_alu_pc; + + end else begin + + assign alu_pc = op_pc; + + end endgenerate + // }}} + + // r_alu_illegal + // {{{ + generate if (OPT_PIPELINED) + begin : SET_ALU_ILLEGAL + reg r_alu_illegal; + + initial r_alu_illegal = 0; + always @(posedge i_clk) + if (clear_pipeline) + r_alu_illegal <= 1'b0; + else if (adf_ce_unconditional) + r_alu_illegal <= op_illegal; + else + r_alu_illegal <= 1'b0; + + assign alu_illegal = (r_alu_illegal); + end else begin : SET_ALU_ILLEGAL + assign alu_illegal = op_illegal; + end endgenerate + // }}} + + // r_alu_pc_valid, mem_pc_valid + // {{{ + initial r_alu_pc_valid = 1'b0; + initial mem_pc_valid = 1'b0; + always @(posedge i_clk) + if (clear_pipeline) + r_alu_pc_valid <= 1'b0; + else if ((adf_ce_unconditional)&&(!op_phase)) + r_alu_pc_valid <= 1'b1; + else if (((!alu_busy)&&(!div_busy)&&(!fpu_busy))||(clear_pipeline)) + r_alu_pc_valid <= 1'b0; + + assign alu_pc_valid = (r_alu_pc_valid) + &&((!alu_busy)&&(!div_busy)&&(!fpu_busy)); + + always @(posedge i_clk) + if (i_reset) + mem_pc_valid <= 1'b0; + else + mem_pc_valid <= (mem_ce); + // }}} + + // Bus lock logic + // {{{ + generate + if ((OPT_PIPELINED)&&(!OPT_LOCK)) + begin : BUSLOCK + reg r_prelock_stall; + reg r_prelock_primed; + reg [1:0] r_bus_lock; + reg [AW+1:0] r_lock_pc; + + // r_prelock_stall + // {{{ + initial r_prelock_stall = 1'b0; + always @(posedge i_clk) + if (clear_pipeline) + r_prelock_stall <= 1'b0; + else if ((op_valid)&&(op_lock)&&(op_ce)) + r_prelock_stall <= 1'b1; + else if ((op_valid)&&(dcd_valid)&&(i_pf_valid)) + r_prelock_stall <= 1'b0; + // }}} + + // r_prelock_primed + // {{{ + initial r_prelock_primed = 1'b0; + always @(posedge i_clk) + if (clear_pipeline) + r_prelock_primed <= 1'b0; + else if (r_prelock_stall) + r_prelock_primed <= 1'b1; + else if ((adf_ce_unconditional)||(mem_ce)) + r_prelock_primed <= 1'b0; + // }}} + + // r_lock_pc + // {{{ + always @(posedge i_clk) + if (op_valid && op_ce && op_lock) + r_lock_pc <= op_pc; + // }}} + + // r_bus_lock + // {{{ + // Count 3 cycles. The lock will only hold solid for three + // cycles after the LOCK instruction is received. Count those + // cycles here. + initial r_bus_lock = 2'b00; + always @(posedge i_clk) + if (clear_pipeline) + r_bus_lock <= 2'b00; + else if ((op_valid)&&((adf_ce_unconditional)||(mem_ce))) + begin + if (r_prelock_primed) + r_bus_lock <= 2'b10; + else if (r_bus_lock != 2'h0) + r_bus_lock <= r_bus_lock + 2'b11; + end + // }}} + + assign prelock_stall = r_prelock_stall; + assign o_bus_lock = |r_bus_lock; + assign o_mem_lock_pc = r_lock_pc; + end else begin + // {{{ + assign prelock_stall = 1'b0; + assign o_bus_lock = 1'b0; + assign o_mem_lock_pc = 0; + // }}} + end endgenerate + // }}} + + // Memory interface + // {{{ + // This logic is now managed outside the ZipCore + // + assign o_mem_ce = mem_ce && set_cond; + assign o_mem_op = op_opn[2:0]; + assign o_mem_data = op_Av; + assign o_mem_addr = op_Bv; + assign o_mem_reg = op_R; + + // }}} + // }}} + //////////////////////////////////////////////////////////////////////// + // + // PIPELINE STAGE #5 :: Write-back results + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + // + // This stage is not allowed to stall. If results are ready to be + // written back, they are written back at all cost. Sleepy CPU's + // won't prevent write back, nor debug modes, halting the CPU, nor + // anything else. Indeed, the (master_ce) bit is only as relevant + // as knowinig something is available for writeback. + + // wr_discard, wr_reg_ce + // {{{ + // + // Write back to our generic register set ... + // When shall we write back? On one of two conditions + // Note that the flags needed to be checked before issuing the + // bus instruction, so they don't need to be checked here. + // Further, alu_wR includes (set_cond), so we don't need to + // check for that here either. + assign wr_discard = (clear_pipeline || alu_illegal); + always @(*) + case(wr_index) + 3'b000: wr_reg_ce = dbgv; + 3'b001: wr_reg_ce = i_mem_valid; + //3'b010: wr_reg_ce = (!wr_discard)&&(alu_wR && alu_valid); + 3'b011: wr_reg_ce = (!wr_discard)&&(div_valid)&&(!div_error); + 3'b100: wr_reg_ce = (!wr_discard)&&(fpu_valid)&&(!fpu_error); + default: wr_reg_ce = (!wr_discard)&&(alu_wR && alu_valid); + endcase + // }}} + + // wr_reg_id, wr_write-cc, wr_write_scc, wr_write_ucc, wr_write_pc + // {{{ + // Which register shall be written? + // COULD SIMPLIFY THIS: by adding three bits to these registers, + // One or PC, one for CC, and one for GIE match + // Note that the alu_reg is the register to write on a divide or + // FPU operation. + generate if (OPT_NO_USERMODE) + begin + assign wr_reg_id[3:0] = (i_mem_valid) + ? i_mem_wreg[3:0] : alu_reg[3:0]; + + assign wr_reg_id[4] = 1'b0; + end else begin + assign wr_reg_id = (i_mem_valid) ? i_mem_wreg : alu_reg; + end endgenerate + + // Are we writing to the CC register? + assign wr_write_cc = (wr_reg_id[3:0] == CPU_CC_REG); + assign wr_write_scc = (wr_reg_id[4:0] == {1'b0, CPU_CC_REG}); + assign wr_write_ucc = (wr_reg_id[4:0] == {1'b1, CPU_CC_REG}); + // Are we writing to the PC? + assign wr_write_pc = (wr_reg_id[3:0] == CPU_PC_REG); + // }}} + + // wr_?preg_vl: Select from among sources the value to be writtena + // {{{ + always @(*) + case(wr_index) + 3'b000: wr_gpreg_vl = dbg_val; + 3'b001: wr_gpreg_vl = i_mem_result; + // 3'b010: wr_gpreg_vl = alu_result; + 3'b011: wr_gpreg_vl = div_result; + 3'b100: wr_gpreg_vl = fpu_result; + default: wr_gpreg_vl = alu_result; + endcase + + always @(*) + case(wr_index[1:0]) + 2'b00: wr_spreg_vl = dbg_val; + 2'b01: wr_spreg_vl = i_mem_result; + // 3'b010: wr_gpreg_vl = alu_result; + default: wr_spreg_vl = alu_result; + endcase + // }}} + + // Update the register set + // {{{ + generate if (OPT_NO_USERMODE) + begin : SET_REGISTERS + + always @(posedge i_clk) + if (wr_reg_ce) + regset[wr_reg_id[3:0]] <= wr_gpreg_vl; + + end else begin : SET_REGISTERS + + always @(posedge i_clk) + if (wr_reg_ce) + regset[wr_reg_id] <= wr_gpreg_vl; + + end endgenerate + // }}} + + // + // Write back to the condition codes/flags register ... + + // wr_flags_ce : should condition codes be written to? + // {{{ + // When shall we write to our flags register? alu_wF already + // includes the set condition ... + // assign wr_flags_ce = (alu_wF)&&((alu_valid) + // ||(div_valid)||(fpu_valid)) + // &&(!clear_pipeline)&&(!alu_illegal); + always @(*) + begin + wr_flags_ce = 0; + if (alu_wF && !wr_discard) + case(wr_index) + // 3'b000: wr_flags_ce = 0; // Debug + // 3'b001: wr_flags_ce = 0; // Memory + 3'b010: wr_flags_ce = alu_valid; // ALU + 3'b011: wr_flags_ce = div_valid && !div_error; // DIV + 3'b100: wr_flags_ce = fpu_valid && !fpu_error; // FPU + default: wr_flags_ce = 0; + endcase + end + // }}} + + // wr_flags: what should the new condition codes be? + // {{{ + always @(*) + begin + wr_flags = 0; + case(wr_index) + 3'b010: wr_flags = alu_flags; + 3'b011: wr_flags = div_flags; + 3'b100: wr_flags = fpu_flags; + default: wr_flags = 0; + endcase + end + // }}} + + // w_uflags, w_iflags : Define the current CC registers + // {{{ + assign w_uflags = { 2'b00, uhalt_phase, ufpu_err_flag, + udiv_err_flag, ubus_err_flag, trap, ill_err_u, + ubreak, step, 1'b1, sleep, + ((wr_flags_ce)&&(alu_gie))?wr_flags:flags }; + assign w_iflags = { 2'b00, ihalt_phase, ifpu_err_flag, + idiv_err_flag, ibus_err_flag, trap, ill_err_i, + break_en, 1'b0, 1'b0, sleep, + ((wr_flags_ce)&&(!alu_gie))?wr_flags:iflags }; + // }}} + + // flags: The user condition codes, Z, C, N, and V + // {{{ + // What value to write? + always @(posedge i_clk) + // If explicitly writing the register itself + if ((wr_reg_ce)&&(wr_write_ucc)) + flags <= wr_gpreg_vl[3:0]; + // Otherwise if we're setting the flags from an ALU operation + else if ((wr_flags_ce)&&(alu_gie)) + flags <= (div_valid)?div_flags:((fpu_valid)?fpu_flags + : alu_flags); + // }}} + + // uflags: The supervisor condition codes, Z, C, N, and V + // {{{ + always @(posedge i_clk) + if ((wr_reg_ce)&&(wr_write_scc)) + iflags <= wr_gpreg_vl[3:0]; + else if ((wr_flags_ce)&&(!alu_gie)) + iflags <= (div_valid)?div_flags:((fpu_valid)?fpu_flags + : alu_flags); + // }}} + + // break_en + // {{{ + // The 'break' enable bit. This bit can only be set from supervisor + // mode. It controls what the CPU does upon encountering a break + // instruction. + // + // The goal, upon encountering a break is that the CPU should stop and + // not execute the break instruction, choosing instead to enter into + // either interrupt mode or halt first. + // if ((break_en) AND (break_instruction)) // user mode or not + // HALT CPU + // else if (break_instruction) // only in user mode + // set an interrupt flag, set the user break bit, + // go to supervisor mode, allow supervisor to step the CPU. + initial break_en = 1'b0; + always @(posedge i_clk) + if (i_reset) + break_en <= 1'b0; + else if ((wr_reg_ce)&&(wr_write_scc)) + break_en <= wr_spreg_vl[CPU_BREAK_BIT]; + // }}} + + // break_pending + // {{{ + generate if (OPT_PIPELINED) + begin : GEN_PENDING_BREAK + reg r_break_pending; + + initial r_break_pending = 1'b0; + always @(posedge i_clk) + if ((clear_pipeline)||(!op_valid)) + r_break_pending <= 1'b0; + else if ((op_break)&&(!r_break_pending)) + r_break_pending <= (!alu_busy)&&(!div_busy) + &&(!fpu_busy)&&(!i_mem_busy) + &&(!wr_reg_ce); + // else + // r_break_pending <= 1'b0; + + assign break_pending = r_break_pending; + end else begin + + assign break_pending = op_break; + end endgenerate + // }}} + + // o_break + // {{{ + assign o_break = ((break_en)||(!op_gie))&&(break_pending) + &&(!clear_pipeline) + ||(ill_err_i) + ||((!alu_gie)&&(i_bus_err)) + ||((!alu_gie)&&(div_error)) + ||((!alu_gie)&&(fpu_error)) + ||((!alu_gie)&&(alu_illegal)&&(!clear_pipeline)); + // }}} + + // sleep + // {{{ + // The sleep register. Setting the sleep register causes the CPU to + // sleep until the next interrupt. Setting the sleep register within + // interrupt mode causes the processor to halt until a reset. This is + // a panic/fault halt. The trick is that you cannot be allowed to + // set the sleep bit and switch to supervisor mode in the same + // instruction: users are not allowed to halt the CPU. + initial sleep = 1'b0; + generate if (OPT_NO_USERMODE) + begin : GEN_NO_USERMODE_SLEEP + // {{{ + reg r_sleep_is_halt; + initial r_sleep_is_halt = 1'b0; + always @(posedge i_clk) + if (i_reset) + r_sleep_is_halt <= 1'b0; + else if ((wr_reg_ce)&&(wr_write_cc) + &&(wr_spreg_vl[CPU_SLEEP_BIT]) + &&(!wr_spreg_vl[CPU_GIE_BIT])) + r_sleep_is_halt <= 1'b1; + + // Trying to switch to user mode, either via a WAIT or an RTU + // instruction will cause the CPU to sleep until an interrupt, + // in the NO-USERMODE build. + always @(posedge i_clk) + if ((i_reset)||((i_interrupt)&&(!r_sleep_is_halt))) + sleep <= 1'b0; + else if ((wr_reg_ce)&&(wr_write_cc) + &&(wr_spreg_vl[CPU_GIE_BIT])) + sleep <= 1'b1; + // }}} + end else begin : GEN_SLEEP + // {{{ + always @(posedge i_clk) + if ((i_reset)||(w_switch_to_interrupt)) + sleep <= 1'b0; + else if ((wr_reg_ce)&&(wr_write_cc)&&(!alu_gie)) + // In supervisor mode, we have no protections. + // The supervisor can set the sleep bit however + // he wants. Well ... not quite. Switching to + // user mode and sleep mode shouold only be + // possible if the interrupt flag isn't set. + // Thus: if (i_interrupt) + // &&(wr_spreg_vl[GIE]) + // don't set the sleep bit + // otherwise however it would o.w. be set + sleep <= (wr_spreg_vl[CPU_SLEEP_BIT]) + &&((!i_interrupt) + ||(!wr_spreg_vl[CPU_GIE_BIT])); + else if ((wr_reg_ce)&&(wr_write_cc)&&(wr_spreg_vl[CPU_GIE_BIT])) + // In user mode, however, you can only set the + // sleep mode while remaining in user mode. + // You can't switch to sleep mode *and* + // supervisor mode at the same time, lest you + // halt the CPU. + sleep <= wr_spreg_vl[CPU_SLEEP_BIT]; + // }}} + end endgenerate + // }}} + + // step : debug single-step control + // {{{ + always @(posedge i_clk) + if (i_reset) + step <= 1'b0; + else if ((wr_reg_ce)&&(!alu_gie)&&(wr_write_ucc)) + step <= wr_spreg_vl[CPU_STEP_BIT]; + // }}} + + // o_clken + // {{{ + generate if (!OPT_GATE_CLOCK) + begin : NO_CLOCK_GATE + + assign o_clken = 1'b1; + + end else begin : GEN_CLOCK_GATE + reg r_clken; + + // Actual clock gating signal + // + // = r_clken || (i_interrupt&&!i_halt) || i_dbg_we + // + always @(posedge i_clk) + if (i_reset || (i_halt && r_halted && !i_dbg_we)) + r_clken <= i_mem_busy; + else if (!i_halt&& (!sleep || i_interrupt || pending_interrupt)) + r_clken <= 1'b1; + else // if (sleep || i_halt) + begin + r_clken <= 1'b0; + + // If we are in the middle of a lock operation, then + // don't shut the clock off + if (o_bus_lock) + r_clken <= 1'b1; + + // If we are in between two compressed instructions + // from the same word, then don't disable the clock + if (alu_phase) + r_clken <= 1'b1; + + // Don't shut the clock off if we are still busy with + // any previous operation(s) + if (i_mem_busy || alu_busy || div_busy || fpu_busy + || wr_reg_ce || i_dbg_we + || i_bus_err) + r_clken <= 1'b1; + + if (i_halt && !r_halted) + r_clken <= 1'b1; + + // Should we wait for a valid PF result before halting? + // if (!i_pf_valid) r_clken <= 1'b1; + // if (!op_valid && !dcd_illegal) r_clken <= 1'b1; + // if (!dcd_valid && !i_pf_illegal) r_clken <= 1'b1; + end + + assign o_clken = r_clken; + end endgenerate + // }}} + + // gie, switch_to_interrupt, release_from_interrupt + // {{{ + // The GIE register. Only interrupts can disable the interrupt register + generate if (OPT_NO_USERMODE) + begin + // {{{ + assign w_switch_to_interrupt = 1'b0; + assign w_release_from_interrupt = 1'b0; + // }}} + end else begin : GEN_PENDING_INTERRUPT + + reg r_pending_interrupt; + + always @(posedge i_clk) + if (i_reset) + r_pending_interrupt <= 1'b0; + else if ((clear_pipeline)||(w_switch_to_interrupt)||(!gie)) + r_pending_interrupt <= 1'b0; + else if (i_interrupt) + r_pending_interrupt <= 1'b1; + else if (adf_ce_unconditional) + begin + if ((op_illegal)||(step)||(break_pending)) + r_pending_interrupt <= 1'b1; + end else if (break_pending) + r_pending_interrupt <= 1'b1; + else if ((mem_ce)&&(step)) + r_pending_interrupt <= 1'b1; + + assign pending_interrupt = r_pending_interrupt && !i_halt; + + + assign w_switch_to_interrupt = (gie)&&( + // On interrupt (obviously) + ((pending_interrupt) + &&(!alu_phase)&&(!o_bus_lock)&&(!i_mem_busy)) + // + // On division by zero. If the divide isn't + // implemented, div_valid and div_error will be short + // circuited and that logic will be bypassed + ||(div_error) + // + // Same thing on a floating point error. Note that + // fpu_error must *never* be set unless fpu_valid is + // also set as well, else this will fail. + ||(fpu_error) + // + // + ||(i_bus_err) + // + // If we write to the CC register + ||((wr_reg_ce)&&(!wr_spreg_vl[CPU_GIE_BIT]) + &&(wr_reg_id[4])&&(wr_write_cc)) + ); + assign w_release_from_interrupt = (!gie)&&(!i_interrupt) + // Then if we write the sCC register + &&(((wr_reg_ce)&&(wr_spreg_vl[CPU_GIE_BIT]) + &&(wr_write_scc)) + ); + +`ifdef FORMAL + always @(posedge i_clk) + if (r_pending_interrupt && gie && !clear_pipeline) + assert(i_interrupt || step || alu_illegal + || ill_err_u || break_pending); +`endif + end endgenerate + + generate if (OPT_NO_USERMODE) + begin + + assign gie = 1'b0; + + end else begin : SET_GIE + + reg r_gie; + + initial r_gie = 1'b0; + always @(posedge i_clk) + if (i_reset) + r_gie <= 1'b0; + else if (w_switch_to_interrupt) + r_gie <= 1'b0; + else if (w_release_from_interrupt) + r_gie <= 1'b1; + + assign gie = r_gie; + end endgenerate + // }}} + + // trap, ubreak + // {{{ + generate if (OPT_NO_USERMODE) + begin + + assign trap = 1'b0; + assign ubreak = 1'b0; + + end else begin : SET_TRAP_N_UBREAK + + reg r_trap; + reg r_ubreak; + + // A trap is generated when the user writes to the CC + // register to clear the GIE bit. This is how the supervisor + // can tell that supervisor mode was entered by a request from + // usermode. + initial r_trap = 1'b0; + always @(posedge i_clk) + if ((i_reset)||(w_release_from_interrupt)) + r_trap <= 1'b0; + else if ((alu_gie)&&(wr_reg_ce)&&(!wr_spreg_vl[CPU_GIE_BIT]) + &&(wr_write_ucc)) // &&(wr_reg_id[4]) implied + r_trap <= 1'b1; + else if ((wr_reg_ce)&&(wr_write_ucc)&&(!alu_gie)) + r_trap <= (r_trap)&&(wr_spreg_vl[CPU_TRAP_BIT]); + + // A user break is an indication of an exception. Something + // went wrong. When entering supervisor mode, if this bit + // is set the supervisor then knows something went wrong in + // userspace that needs to be looked into. + initial r_ubreak = 1'b0; + always @(posedge i_clk) + if ((i_reset)||(w_release_from_interrupt)) + r_ubreak <= 1'b0; + else if ((op_gie)&&(break_pending)&&(w_switch_to_interrupt)) + r_ubreak <= 1'b1; + else if (((!alu_gie)||(dbgv))&&(wr_reg_ce)&&(wr_write_ucc)) + r_ubreak <= (ubreak)&&(wr_spreg_vl[CPU_BREAK_BIT]); + + assign trap = r_trap; + assign ubreak = r_ubreak; + + end endgenerate + // }}} + + // ill_err_i, ill_err_u: Illegal instruction flags + // {{{ + initial ill_err_i = 1'b0; + always @(posedge i_clk) + if (i_reset) + ill_err_i <= 1'b0; + // Only the debug interface can clear this bit + else if ((dbgv)&&(wr_write_scc)) + ill_err_i <= (ill_err_i)&&(wr_spreg_vl[CPU_ILL_BIT]); + else if ((alu_illegal)&&(!alu_gie)&&(!clear_pipeline)) + ill_err_i <= 1'b1; + + generate if (OPT_NO_USERMODE) + begin + + assign ill_err_u = 1'b0; + + end else begin : SET_USER_ILLEGAL_INSN + + reg r_ill_err_u; + + initial r_ill_err_u = 1'b0; + always @(posedge i_clk) + // The bit is automatically cleared on release from interrupt + // or reset + if ((i_reset)||(w_release_from_interrupt)) + r_ill_err_u <= 1'b0; + // If the supervisor (or debugger) writes to this + // register, clearing the bit, then clear it + else if (((!alu_gie)||(dbgv))&&(wr_reg_ce)&&(wr_write_ucc)) + r_ill_err_u <=((ill_err_u)&&(wr_spreg_vl[CPU_ILL_BIT])); + else if ((alu_illegal)&&(alu_gie)&&(!clear_pipeline)) + r_ill_err_u <= 1'b1; + + assign ill_err_u = r_ill_err_u; + + end endgenerate + // }}} + + // ibus_err_flag, ubus_err_flag : Bus error flags + // {{{ + // Supervisor/interrupt bus error flag -- this will crash the CPU if + // ever set. + initial ibus_err_flag = 1'b0; + always @(posedge i_clk) + if (i_reset) + ibus_err_flag <= 1'b0; + else if ((dbgv)&&(wr_write_scc)) + ibus_err_flag <= (ibus_err_flag)&&(wr_spreg_vl[CPU_BUSERR_BIT]); + else if ((i_bus_err)&&(!alu_gie)) + ibus_err_flag <= 1'b1; + // User bus error flag -- if ever set, it will cause an interrupt to + // supervisor mode. + generate if (OPT_NO_USERMODE) + begin + + assign ubus_err_flag = 1'b0; + + end else begin : SET_USER_BUSERR + + reg r_ubus_err_flag; + + initial r_ubus_err_flag = 1'b0; + always @(posedge i_clk) + if ((i_reset)||(w_release_from_interrupt)) + r_ubus_err_flag <= 1'b0; + else if (((!alu_gie)||(dbgv))&&(wr_reg_ce)&&(wr_write_ucc)) + r_ubus_err_flag <= (ubus_err_flag)&&(wr_spreg_vl[CPU_BUSERR_BIT]); + else if ((i_bus_err)&&(alu_gie)) + r_ubus_err_flag <= 1'b1; + + assign ubus_err_flag = r_ubus_err_flag; + end endgenerate + // }}} + + // idiv_err_flag, udiv_err_flag : Divide by zero error flags + // {{{ + generate if (IMPLEMENT_DIVIDE != 0) + begin : DIVERR + // {{{ + reg r_idiv_err_flag, r_udiv_err_flag; + + // Supervisor/interrupt divide (by zero) error flag -- this will + // crash the CPU if ever set. This bit is thus available for us + // to be able to tell if/why the CPU crashed. + initial r_idiv_err_flag = 1'b0; + always @(posedge i_clk) + if (i_reset) + r_idiv_err_flag <= 1'b0; + else if ((dbgv)&&(wr_write_scc)) + r_idiv_err_flag <= (r_idiv_err_flag)&&(wr_spreg_vl[CPU_DIVERR_BIT]); + else if ((div_error)&&(!alu_gie)) + r_idiv_err_flag <= 1'b1; + + assign idiv_err_flag = r_idiv_err_flag; + + if (OPT_NO_USERMODE) + begin + assign udiv_err_flag = 1'b0; + end else begin + + // User divide (by zero) error flag -- if ever set, it will + // cause a sudden switch interrupt to supervisor mode. + initial r_udiv_err_flag = 1'b0; + always @(posedge i_clk) + if ((i_reset)||(w_release_from_interrupt)) + r_udiv_err_flag <= 1'b0; + else if (((!alu_gie)||(dbgv))&&(wr_reg_ce) + &&(wr_write_ucc)) + r_udiv_err_flag <= (r_udiv_err_flag)&&(wr_spreg_vl[CPU_DIVERR_BIT]); + else if ((div_error)&&(alu_gie)) + r_udiv_err_flag <= 1'b1; + + assign udiv_err_flag = r_udiv_err_flag; + end + // }}} + end else begin + // {{{ + assign idiv_err_flag = 1'b0; + assign udiv_err_flag = 1'b0; + // }}} + end endgenerate + // }}} + + // ifpu_err_flag, ufpu_err_flag : Floating point error flag(s) + // {{{ + generate if (IMPLEMENT_FPU !=0) + begin : FPUERR + // {{{ + // Supervisor/interrupt floating point error flag -- this will + // crash the CPU if ever set. + reg r_ifpu_err_flag, r_ufpu_err_flag; + initial r_ifpu_err_flag = 1'b0; + always @(posedge i_clk) + if (i_reset) + r_ifpu_err_flag <= 1'b0; + else if ((dbgv)&&(wr_write_scc)) + r_ifpu_err_flag <= (r_ifpu_err_flag)&&(wr_spreg_vl[CPU_FPUERR_BIT]); + else if ((fpu_error)&&(fpu_valid)&&(!alu_gie)) + r_ifpu_err_flag <= 1'b1; + // User floating point error flag -- if ever set, it will cause + // a sudden switch interrupt to supervisor mode. + initial r_ufpu_err_flag = 1'b0; + always @(posedge i_clk) + if ((i_reset)&&(w_release_from_interrupt)) + r_ufpu_err_flag <= 1'b0; + else if (((!alu_gie)||(dbgv))&&(wr_reg_ce) + &&(wr_write_ucc)) + r_ufpu_err_flag <= (r_ufpu_err_flag)&&(wr_spreg_vl[CPU_FPUERR_BIT]); + else if ((fpu_error)&&(alu_gie)&&(fpu_valid)) + r_ufpu_err_flag <= 1'b1; + + assign ifpu_err_flag = r_ifpu_err_flag; + assign ufpu_err_flag = r_ufpu_err_flag; + // }}} + end else begin + // {{{ + assign ifpu_err_flag = 1'b0; + assign ufpu_err_flag = 1'b0; + // }}} + end endgenerate + // }}} + + // ihalt_phase, uhalt_phase : If an instruction was broken when halting + // {{{ + generate if (OPT_CIS) + begin : GEN_IHALT_PHASE + reg r_ihalt_phase; + + initial r_ihalt_phase = 0; + always @(posedge i_clk) + if (i_reset) + r_ihalt_phase <= 1'b0; + else if ((!alu_gie)&&(alu_pc_valid)&&(!clear_pipeline)) + r_ihalt_phase <= alu_phase; + + assign ihalt_phase = r_ihalt_phase; + end else begin : GEN_IHALT_PHASE + + assign ihalt_phase = 1'b0; + + end endgenerate + + generate if ((!OPT_CIS) || (OPT_NO_USERMODE)) + begin : GEN_UHALT_PHASE + + assign uhalt_phase = 1'b0; + + end else begin : GEN_UHALT_PHASE + + reg r_uhalt_phase; + + initial r_uhalt_phase = 1'b0; + always @(posedge i_clk) + if ((i_reset)||(w_release_from_interrupt)) + r_uhalt_phase <= 1'b0; + else if ((alu_gie)&&(alu_pc_valid)) + r_uhalt_phase <= alu_phase; + else if ((!alu_gie)&&(wr_reg_ce)&&(wr_write_pc) + &&(wr_reg_id[4])) + r_uhalt_phase <= wr_spreg_vl[1]; + + assign uhalt_phase = r_uhalt_phase; + + end endgenerate + // }}} + + // ipc, upc: Program counters + // {{{ + // + // Write backs to the PC register, and general increments of it + // We support two: upc and ipc. If the instruction is normal, + // we increment upc, if interrupt level we increment ipc. If + // the instruction writes the PC, we write whichever PC is appropriate. + // + // Do we need to all our partial results from the pipeline? + // What happens when the pipeline has gie and !gie instructions within + // it? Do we clear both? What if a gie instruction tries to clear + // a non-gie instruction? + + // upc + generate if (OPT_NO_USERMODE) + begin + // {{{ + assign upc = {(AW+2){1'b0}}; + // }}} + end else begin : SET_USER_PC + // {{{ + reg [(AW+1):0] r_upc; + + always @(posedge i_clk) + if ((wr_reg_ce)&&(wr_reg_id[4])&&(wr_write_pc)) + r_upc <= { wr_spreg_vl[(AW+1):2], 2'b00 }; + else if ((alu_gie)&& + (((alu_pc_valid)&&(!clear_pipeline)&&(!alu_illegal)) + ||(mem_pc_valid))) + r_upc <= alu_pc; + + assign upc = r_upc; + // }}} + end endgenerate + + // ipc + // {{{ + initial ipc = { RESET_BUS_ADDRESS, 2'b00 }; + always @(posedge i_clk) + if (i_reset) + ipc <= { RESET_BUS_ADDRESS, 2'b00 }; + else if ((wr_reg_ce)&&(!wr_reg_id[4])&&(wr_write_pc)) + ipc <= { wr_spreg_vl[(AW+1):2], 2'b00 }; + else if ((!alu_gie)&&(!alu_phase)&& + (((alu_pc_valid)&&(!clear_pipeline)&&(!alu_illegal)) + ||(mem_pc_valid))) + ipc <= alu_pc; + // }}} + // }}} + + // pf_pc : the program counter used by the pre-fetch + // {{{ + + // pfpcset, pfpcsrc + // {{{ + always @(*) + begin + pfpcset = 0; + pfpcsrc = 0; + if (i_reset) + begin + pfpcsrc = 0; + pfpcset = 1; + end else if ((dbgv)&&(wr_reg_ce)&&(wr_reg_id[4] == gie && wr_write_pc)) + begin + pfpcsrc = 1; // spreg + pfpcset = 1; + end else if ((w_switch_to_interrupt) + ||((!gie)&&((o_clear_icache)||(dbg_clear_pipe)))) + begin + pfpcsrc = 2; // ipc + pfpcset = 1; + end else if ((w_release_from_interrupt)||((gie)&&((o_clear_icache)||(dbg_clear_pipe)))) + begin + pfpcsrc = 3; // upc + pfpcset = 1; + end else if ((wr_reg_ce)&&(wr_reg_id[4] == gie && wr_write_pc)) + begin + pfpcsrc = 1; // spreg + pfpcset = 1; + end else if ((dcd_early_branch_stb)&&(!clear_pipeline)) + begin + pfpcsrc = 4; // branch + pfpcset = 1; + end else if ((new_pc)||(o_pf_ready&& i_pf_valid)) + begin + pfpcsrc = 5; // PC increment + pfpcset = 1; + end + end + // }}} + + initial pf_pc = { RESET_BUS_ADDRESS, 2'b00 }; + always @(posedge i_clk) + if (pfpcset) + case(pfpcsrc) + 3'b000: pf_pc <= { RESET_BUS_ADDRESS, 2'b00 }; + 3'b001: pf_pc <= { wr_spreg_vl[(AW+1):2], 2'b00 }; + 3'b010: pf_pc <= { ipc[(AW+1):2], 2'b00 }; + 3'b011: pf_pc <= { upc[(AW+1):2], 2'b00 }; + 3'b100: pf_pc <= { dcd_branch_pc[AW+1:2] + 1'b1, 2'b00 }; + 3'b101: pf_pc <= { pf_pc[(AW+1):2] + 1'b1, 2'b00 }; + default: pf_pc <= { RESET_BUS_ADDRESS, 2'b00 }; + endcase +/* + if (i_reset) + pf_pc <= { RESET_BUS_ADDRESS, 2'b00 }; + else if ((dbg_clear_pipe)&&(wr_reg_ce)&&(wr_write_pc)) + pf_pc <= { wr_spreg_vl[(AW+1):2], 2'b00 }; + else if ((w_switch_to_interrupt) + ||((!gie)&&((o_clear_icache)||(dbg_clear_pipe)))) + pf_pc <= { ipc[(AW+1):2], 2'b00 }; + else if ((w_release_from_interrupt)||((gie)&&((o_clear_icache)||(dbg_clear_pipe)))) + pf_pc <= { upc[(AW+1):2], 2'b00 }; + else if ((wr_reg_ce)&&(wr_reg_id[4] == gie)&&(wr_write_pc)) + pf_pc <= { wr_spreg_vl[(AW+1):2], 2'b00 }; + else if ((dcd_early_branch_stb)&&(!clear_pipeline)) + pf_pc <= { dcd_branch_pc[AW+1:2] + 1'b1, 2'b00 }; + else if ((new_pc)||((!pf_stalled)&&(i_pf_valid))) + pf_pc <= { pf_pc[(AW+1):2] + 1'b1, 2'b00 }; +*/ + // }}} + + initial last_write_to_cc = 1'b0; + always @(posedge i_clk) + if (i_reset) + last_write_to_cc <= 1'b0; + else + last_write_to_cc <= (wr_reg_ce)&&(wr_write_cc); + assign cc_write_hold = (wr_reg_ce)&&(wr_write_cc)||(last_write_to_cc); + + // o_clear_icache + // {{{ + // If we aren't pipelined, or equivalently if we have no cache, these + // instructions will get quietly (or not so quietly) ignored by the + // optimizer. + initial r_clear_icache = 1'b1; + always @(posedge i_clk) + if (i_reset) + r_clear_icache <= 1'b0; + else if (i_clear_cache && !o_dbg_stall) + r_clear_icache <= 1'b1; + else if ((wr_reg_ce)&&(wr_write_scc)) + r_clear_icache <= wr_spreg_vl[CPU_CLRICACHE_BIT]; + else + r_clear_icache <= 1'b0; + + assign o_clear_icache = r_clear_icache; + // }}} + + // o_clear_dcache + // {{{ + generate if (OPT_DCACHE) + begin : CLEAR_DCACHE + reg r_clear_dcache; + + initial r_clear_dcache = 1'b1; + always @(posedge i_clk) + if (i_reset) + r_clear_dcache <= 1'b0; + else if (i_clear_cache && !o_dbg_stall) + r_clear_dcache <= 1'b1; + else if ((wr_reg_ce)&&(wr_write_scc)) + r_clear_dcache <= wr_spreg_vl[CPU_CLRDCACHE_BIT]; + else + r_clear_dcache <= 1'b0; + + assign o_clear_dcache = r_clear_dcache; + end else begin : NOCLEAR_DCACHE + + assign o_clear_dcache = 1'b0; + + end endgenerate + // }}} + + // new_pc : does the Prefetch need to clear the pipeline and start over? + // {{{ + initial new_pc = 1'b1; + always @(posedge i_clk) + if ((i_reset)||(o_clear_icache)||(dbg_clear_pipe)) + new_pc <= 1'b1; + else if (w_switch_to_interrupt) + new_pc <= 1'b1; + else if (w_release_from_interrupt) + new_pc <= 1'b1; + // else if ((wr_reg_ce)&&(wr_reg_id[4] == gie)&&(wr_write_pc)) + // Can't check for *this* PC here, since a user PC might be + // loaded in the pipeline and hence rewritten. Thus, while + // I hate to do it, we'll need to clear the pipeline on any + // PC write + else if ((wr_reg_ce)&&(alu_gie == wr_reg_id[4])&&(wr_write_pc)) + new_pc <= 1'b1; + else + new_pc <= 1'b0; + // }}} + + // + // The debug write-back interface + // {{{ + + // debug_pc + // {{{ + generate if (OPT_NO_USERMODE) + begin + // {{{ + always @(*) + begin + debug_pc = 0; + debug_pc[(AW+1):0] = { ipc, 2'b00 }; + end + // }}} + end else begin + // {{{ + always @(*) + begin + debug_pc = 0; + if (i_dbg_rreg[4]) + // User mode + debug_pc[(AW+1):0] + = { upc[(AW+1):2], uhalt_phase, 1'b0 }; + else + // Supervisor mode + debug_pc[(AW+1):0] + = { ipc[(AW+1):2], ihalt_phase, 1'b0 }; + end + // }}} + end endgenerate + // }}} + + // o_dbg_reg + // {{{ + generate if (OPT_NO_USERMODE) + begin : NO_USER_SETDBG + // {{{ + always @(posedge i_clk) + begin + o_dbg_reg <= regset[i_dbg_rreg[3:0]]; + if (i_dbg_rreg[3:0] == CPU_PC_REG) + o_dbg_reg <= debug_pc; + else if (i_dbg_rreg[3:0] == CPU_CC_REG) + begin + o_dbg_reg[15:0] <= w_iflags; + o_dbg_reg[31:23] <= w_cpu_info; + o_dbg_reg[CPU_GIE_BIT] <= gie; + end + end + // }}} + end else begin : SETDBG + // {{{ + reg [31:0] pre_dbg_reg; + +`ifdef NO_DISTRIBUTED_RAM + // {{{ + reg dbg_reg_sel; + reg [31:0] pre_dbg_special; + + always @(posedge i_clk) + dbg_reg_sel <= (i_dbg_rreg[3:1] == 3'h7); + + always @(posedge i_clk) + pre_dbg_reg <= regset[i_dbg_rreg]; + + always @(posedge i_clk) + if (i_dbg_rreg[0]) + pre_dbg_special <= debug_pc; + else begin + pre_dbg_special[15:0] <= (i_dbg_rreg[4]) + ? w_uflags : w_iflags; + pre_dbg_special[31:23] <= w_cpu_info; + pre_dbg_special[CPU_GIE_BIT] <= gie; + end + + always @(posedge i_clk) + if (dbg_reg_sel) + o_dbg_reg <= pre_dbg_special; + else + o_dbg_reg <= pre_dbg_reg; + // }}} +`else + // {{{ + always @(*) + pre_dbg_reg = regset[i_dbg_rreg]; + + always @(posedge i_clk) + begin + o_dbg_reg <= pre_dbg_reg; + if (i_dbg_rreg[3:0] == CPU_PC_REG) + o_dbg_reg <= debug_pc; + else if (i_dbg_rreg[3:0] == CPU_CC_REG) + begin + o_dbg_reg[15:0] <= (i_dbg_rreg[4]) + ? w_uflags : w_iflags; + o_dbg_reg[31:23] <= w_cpu_info; + o_dbg_reg[CPU_GIE_BIT] <= gie; + end + end + // }}} +`endif + // }}} + end endgenerate + // }}} + + always @(posedge i_clk) + o_dbg_cc <= { i_bus_err, gie, sleep }; + + // r_halted + // {{{ + generate if (OPT_PIPELINED) + begin + // {{{ + always @(posedge i_clk) + if (!i_halt) + r_halted <= 1'b0; + else if (i_reset || r_halted) + r_halted <= 1'b1; + else + r_halted <= (!alu_phase)&&(!o_bus_lock)&&( + // To be halted, any long lasting instruction + // must be completed. + (i_pf_valid)&&(!i_mem_busy)&&(!alu_busy) + &&(!div_busy)&&(!fpu_busy) + // Operations must either be valid, or illegal + &&((op_valid)||(dcd_illegal)) + // Decode stage must be either valid, in reset, + // or producing an illelgal instruction + &&((dcd_valid)||(i_pf_illegal))); + // }}} + end else begin + // {{{ + always @(posedge i_clk) + if (!i_halt) + r_halted <= 1'b0; + else if (i_reset || r_halted) + r_halted <= 1'b1; + else + r_halted <= (!alu_phase) + // To be halted, any long lasting instruction + // must be completed. + &&(i_pf_valid)&&(!i_mem_busy)&&(!alu_busy) + &&(!div_busy)&&(!fpu_busy); + // }}} + end endgenerate + // }}} + + // o_dbg_stall + // {{{ + initial r_dbg_stall = 1'b1; + + always @(posedge i_clk) + if (i_reset) + r_dbg_stall <= 1'b1; + else if (!r_halted || (wr_reg_ce && wr_reg_id[3:1] == 3'h7)) + r_dbg_stall <= 1'b1; + else + r_dbg_stall <= (i_dbg_we && !o_dbg_stall); + + assign o_dbg_stall = !r_halted || r_dbg_stall; + // }}} + // }}} + + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Accounting outputs + // {{{ + + // + // + // Produce accounting outputs: Account for any CPU stalls, so we can + // later evaluate how well we are doing. + // + // + assign o_op_stall = (master_ce)&&(op_stall); + assign o_pf_stall = (master_ce)&&(!i_pf_valid); + assign o_i_count = (alu_pc_valid)&&(!clear_pipeline); + // }}} + //////////////////////////////////////////////////////////////////////// + // + // The debug scope output + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + reg debug_trigger, dbg_mem_we; + wire [31:0] debug_flags; + + initial debug_trigger = 1'b0; + always @(posedge i_clk) + debug_trigger <= (!i_halt)&&(o_break); + + always @(posedge i_clk) + if (o_mem_ce) + dbg_mem_we <= o_mem_op[0]; + + assign debug_flags = { debug_trigger, 3'b101, + master_ce, i_halt, o_break, sleep, + gie, ibus_err_flag, trap, ill_err_i, + o_clear_icache, i_pf_valid, i_pf_illegal, dcd_ce, + dcd_valid, dcd_stalled, op_ce, op_valid, + op_pipe, alu_ce, alu_busy, alu_wR, + alu_illegal, alu_wF, mem_ce, dbg_mem_we, + i_mem_busy, i_mem_pipe_stalled, (new_pc), (dcd_early_branch) }; + + // Verilator lint_off UNUSED + wire [27:0] dbg_pc, dbg_wb_addr; + // Verilator lint_on UNUSED + generate if (AW-1 < 27) + begin + assign dbg_pc[(AW-1):0] = pf_pc[(AW+1):2]; + assign dbg_pc[27:AW] = 0; + + assign dbg_wb_addr[(AW-1):0] = 0; + assign dbg_wb_addr[27:AW] = 0; + end else // if (AW-1 >= 27) + begin + assign dbg_pc[27:0] = pf_pc[29:2]; + assign dbg_wb_addr = 0; + end endgenerate + + reg [2:0] dbgsrc; + + always @(posedge i_clk) + begin + dbgsrc <= 0; + if ((i_halt)||(!master_ce)||(debug_trigger)||(o_break)) + dbgsrc <= 3'b000; + else if ((i_mem_valid)||((!clear_pipeline)&&(!alu_illegal) + &&(((alu_wR)&&(alu_valid)) + ||(div_valid)||(fpu_valid)))) + dbgsrc <= 3'b001; + else if (clear_pipeline) + dbgsrc <= 3'b010; + else + dbgsrc <= 3'b100; + end + + always @(posedge i_clk) + casez(dbgsrc) + 3'b000: o_debug <= debug_flags; + 3'b001: o_debug <= { debug_trigger, 1'b0, wr_reg_id[3:0], + wr_gpreg_vl[25:0]}; + 3'b010: o_debug <= { debug_trigger, 3'b100, dbg_pc }; + 3'b011: o_debug <= 32'h0; + 3'b1??: o_debug <= debug_flags; + endcase + + // }}} + // Make verilator happy + // {{{ + // verilator lint_off UNUSED + wire unused; + assign unused = &{ 1'b0, fpu_ce, wr_spreg_vl[1:0], + ipc[1:0], upc[1:0], pf_pc[1:0], + dcd_rA, dcd_pipe, dcd_zI, + dcd_A_stall, dcd_B_stall, dcd_F_stall, + op_Rcc, op_pipe, op_lock, i_mem_pipe_stalled, prelock_stall, + dcd_F }; + generate if (AW+2 < 32) + begin + wire [31:(AW+2)] generic_ignore; + assign generic_ignore = wr_spreg_vl[31:(AW+2)]; + end endgenerate + // verilator lint_on UNUSED + // }}} + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal properties +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +`ifdef FORMAL + // Declarations + // {{{ +`ifdef ZIPCPU +`define ASSUME assume +`else +`define ASSUME assert +`endif +`define ASSERT assert +// +// + + wire [1+1+4+15+6+4+13+AW+1+32+4+23-1:0] f_dcd_data; + wire fc_op_prepipe; + wire [6:0] fc_alu_Aid; + wire fc_alu_wR, fc_alu_M, fc_alu_prepipe; + reg f_alu_phase; + + reg f_past_valid; + + reg [2:0] f_dbg_pc_seq, f_dbg_cc_seq, f_dbg_reg_seq; + + wire fc_op_illegal, fc_op_wF, fc_op_ALU, fc_op_M, + fc_op_DV, fc_op_FP, fc_op_break, + fc_op_lock, fc_op_wR, fc_op_rA, fc_op_rB, + fc_op_sim; + wire [6:0] fc_op_Rid, fc_op_Aid, fc_op_Bid; + wire [31:0] fc_op_I; + wire [3:0] fc_op_cond; + wire [3:0] fc_op_op; + wire [22:0] fc_op_sim_immv; + wire f_op_insn; //f_alu_insn,f_wb_insn + reg f_op_phase, f_op_early_branch; + reg f_op_zI; + reg f_op_branch; + + wire [31:0] f_Bv; + reg [31:0] f_Av, f_pre_Bv; + + reg f_alu_branch; + + wire [31:0] f_dcd_mem_addr; + wire [AW-1:0] f_next_mem, f_op_mem_addr; + wire [4+AW+2+7+4-1:0] f_op_data; + + wire fc_alu_illegal, fc_alu_wF, fc_alu_ALU, fc_alu_DV, + fc_alu_FP, fc_alu_break, fc_alu_lock, + fc_alu_rA, fc_alu_rB, fc_alu_sim; + wire [6:0] fc_alu_Rid, fc_alu_Bid; + wire [31:0] fc_alu_I; + wire [3:0] fc_alu_cond; + wire [3:0] fc_alu_op; + wire [22:0] fc_alu_sim_immv; + + wire [F_LGDEPTH-1:0] f_mem_outstanding; + wire f_mem_gie, f_mem_pc, f_read_cycle, + f_exwrite_cycle; + wire [4:0] f_last_reg, f_addr_reg; + + initial f_past_valid = 1'b0; + always @(posedge i_clk) + f_past_valid <= 1'b1; + +`ifndef VERIFIC + initial assume(i_reset); +`endif + always @(posedge i_clk) + if (!f_past_valid) + assume(i_reset); + // }}} + //////////////////////////////////////////////////////////////////////// + // + // The debugging interface + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + fdebug #( +`ifdef NO_DISTRIBUTED_RAM + .OPT_DISTRIBUTED_RAM(1'b0) +`else + .OPT_DISTRIBUTED_RAM(1'b1) +`endif + ) fdbg ( + // {{{ + .i_clk(i_clk), + .i_reset(i_reset), + .i_cpu_reset(i_reset), + .i_halt(i_halt), + .i_halted(r_halted), + .i_clear_cache(i_clear_cache), + .i_dbg_we(i_dbg_we), + .i_dbg_reg(i_dbg_wreg), + .i_dbg_data(i_dbg_data), + .i_dbg_stall(o_dbg_stall), + .i_dbg_break(o_break), + .i_dbg_cc(o_dbg_cc) + // , .i_dbg_rreg(i_dbg_rreg), + // .i_dbg_rdata(o_dbg_rdata), + // }}} + ); + + always @(*) + if (i_halt && r_halted) + begin + `ASSERT(!alu_ce); + `ASSERT(!alu_phase); + `ASSERT(!div_ce); + `ASSERT(!o_mem_ce); + `ASSERT(f_mem_outstanding == 0); + end + + // o_dbg_reg -- Reading from the debugging interface +`ifdef NO_DISTRIBUTED_RAM + always @(posedge i_clk) + if (f_past_valid&&$past(f_past_valid) + && $past(i_halt)&&$past(i_halt,2)&&(!$past(i_dbg_we))) + begin + if ($past(i_dbg_rreg[3:1],2) != 3'h7) + `ASSERT(o_dbg_reg + == $past(regset[i_dbg_rreg],2)); + end +`else + always @(posedge i_clk) + if ((f_past_valid)&&($past(i_halt))&&(!$past(i_dbg_we))) + begin + if ($past(i_dbg_rreg[3:1]) != 3'h7) + `ASSERT(o_dbg_reg == $past(regset[i_dbg_rreg])); + if ($past(i_dbg_rreg[4:0]) == 5'h0f) + `ASSERT(o_dbg_reg[AW+1:0] == $past({ ipc[(AW+1):2], ihalt_phase, 1'b0})); + if ($past(i_dbg_rreg[4:0]) == 5'h1f) + `ASSERT(o_dbg_reg[AW+1:0] == $past({ upc[(AW+1):2], uhalt_phase, 1'b0})); + if ($past(i_dbg_rreg[4:0]) == 5'h0e) + begin + `ASSERT(o_dbg_reg[15:6] == $past(w_iflags[15:6])); + `ASSERT(o_dbg_reg[ 4:0] == $past(w_iflags[ 4:0])); + end + + if ($past(i_dbg_rreg[4:0]) == 5'h1e) + begin + `ASSERT(o_dbg_reg[15:6] == $past(w_uflags[15:6])); + `ASSERT(o_dbg_reg[ 4:0] == $past(w_uflags[ 4:0])); + end + + if ($past(i_dbg_rreg[3:0]) == 4'he) + begin + `ASSERT(o_dbg_reg[15] == 1'b0); + `ASSERT(o_dbg_reg[31:23] == w_cpu_info); + `ASSERT(o_dbg_reg[CPU_GIE_BIT] == $past(gie)); + end + end +`endif + + initial f_dbg_pc_seq = 0; + always @(posedge i_clk) + if (i_reset) + f_dbg_pc_seq <= 0; + else begin + f_dbg_pc_seq[0] <= i_dbg_we && !o_dbg_stall + && (i_dbg_wreg == { gie, CPU_PC_REG }); + f_dbg_pc_seq[2:1] <= f_dbg_pc_seq[1:0]; + end + + always @(posedge i_clk) + begin + if (f_dbg_pc_seq[0]) + begin + `ASSERT(dbgv && alu_reg == { gie, CPU_PC_REG }); + end + + if (f_dbg_pc_seq[1]) + begin + `ASSERT(clear_pipeline); + `ASSERT(o_pf_request_address == $past({ i_dbg_data[31:2], 2'b00 },2)); + end + end + + initial f_dbg_cc_seq = 0; + always @(posedge i_clk) + if (i_reset) + f_dbg_cc_seq <= 0; + else begin + f_dbg_cc_seq[0] <= i_dbg_we && !o_dbg_stall + && (i_dbg_wreg == { gie, CPU_CC_REG }); + f_dbg_cc_seq[2:1] <= f_dbg_cc_seq[1:0]; + end + + always @(posedge i_clk) + if (f_dbg_cc_seq[0]) + begin + `ASSERT(wr_reg_ce); + `ASSERT(wr_reg_id == $past(i_dbg_wreg)); + `ASSERT(wr_spreg_vl == $past(i_dbg_data)); + end + + initial f_dbg_reg_seq = 0; + always @(posedge i_clk) + if (i_reset) + f_dbg_reg_seq <= 0; + else begin + f_dbg_reg_seq[0] <= i_dbg_we && !o_dbg_stall + && (i_dbg_rreg[3:1] != 3'h7 ); + f_dbg_reg_seq[2:1] <= f_dbg_reg_seq[1:0]; + end + + always @(posedge i_clk) + begin + if (f_dbg_reg_seq[0] && !i_reset) + begin + `ASSERT(dbgv && alu_reg == $past(i_dbg_wreg)); + `ASSERT($past(i_dbg_rreg[3:1]) != 3'h7); + `ASSERT(dbg_val == $past(i_dbg_data)); + + `ASSERT(wr_reg_ce); + `ASSERT(wr_gpreg_vl == $past(i_dbg_data)); + `ASSERT(wr_reg_id == $past(i_dbg_wreg)); + end + + // if (f_dbg_reg_seq[1]) + // begin + // end + end + + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Reset checks + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + + always @(posedge i_clk) + if ((!f_past_valid)||($past(i_reset))) + begin + // Initial assertions + `ASSERT(!i_pf_valid); + `ASSERT(!dcd_phase); + `ASSERT(!op_phase); + `ASSERT(!alu_phase); + // + `ASSERT(!i_pf_valid); + `ASSERT(!dcd_valid); + `ASSERT(!op_valid); + `ASSERT(!op_valid_mem); + `ASSERT(!op_valid_div); + `ASSERT(!op_valid_alu); + `ASSERT(!op_valid_fpu); + // + `ASSERT(!alu_valid); + `ASSERT(!alu_busy); + // + `ASSERT(!i_mem_valid); + `ASSERT(!i_mem_rdbusy); + `ASSERT(!i_bus_err); + // + `ASSERT(!div_valid); + `ASSERT(!div_busy); + `ASSERT(!div_error); + // + `ASSERT(!fpu_valid); + `ASSERT(!fpu_busy); + `ASSERT(!fpu_error); + // + `ASSERT(!ill_err_i); + `ASSERT(!ill_err_u); + `ASSERT(!idiv_err_flag); + `ASSERT(!udiv_err_flag); + `ASSERT(!ibus_err_flag); + `ASSERT(!ubus_err_flag); + `ASSERT(!ifpu_err_flag); + `ASSERT(!ufpu_err_flag); + `ASSERT(!ihalt_phase); + `ASSERT(!uhalt_phase); + end + + always @(*) + begin + if (i_pf_valid) `ASSERT(f_past_valid); + if (dcd_valid) `ASSERT(f_past_valid); + if (alu_pc_valid) `ASSERT(f_past_valid); + if (i_mem_valid) `ASSERT(f_past_valid); + if (div_valid) `ASSERT(f_past_valid); + if (fpu_valid) `ASSERT(f_past_valid); + if (w_op_valid) `ASSERT(f_past_valid); + // if (i_mem_busy) `ASSERT(f_past_valid); + if (i_mem_rdbusy) `ASSERT(f_past_valid); + if (div_busy) `ASSERT(f_past_valid); + if (fpu_busy) `ASSERT(f_past_valid); + end + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Pipeline signaling check + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + always @(posedge i_clk) + if (clear_pipeline) + begin + // `ASSERT(!alu_ce); + `ASSERT(!mem_ce); + end + + always @(posedge i_clk) + if ((f_past_valid)&&($past(clear_pipeline))) + begin + `ASSERT(!alu_busy); + `ASSERT(!div_busy); + `ASSERT(!i_mem_rdbusy); + `ASSERT(!fpu_busy); + // + `ASSERT(!alu_valid); + `ASSERT(!div_valid); + `ASSERT(!fpu_valid); + end + + always @(*) + if (dcd_ce) + `ASSERT((op_ce)||(!dcd_valid)); + + always @(*) + if ((op_ce)&&(!clear_pipeline)) + `ASSERT((adf_ce_unconditional)||(mem_ce)||(!op_valid)); + + // + // Make sure the dcd stage is never permanently stalled + always @(posedge i_clk) + if ((f_past_valid)&&(!$past(alu_wR))&&(!$past(alu_wF)) + &&($past(f_past_valid,2))&&(!$past(alu_wR,2))&&(!$past(alu_wF)) + &&(!op_valid)&&(master_ce) + &&(!clear_pipeline)&&(!i_reset) + &&(!div_busy)&&(!div_valid) + &&(!i_mem_busy)&&(!i_mem_valid)&&(!i_bus_err) + &&(!alu_busy)&&(!alu_pc_valid)&&(!alu_valid) + &&(!fpu_busy)&&(!fpu_valid)&&(!fpu_error) + &&(!op_break)&&(!o_break) + &&(!w_switch_to_interrupt) + &&(!ibus_err_flag)&&(!ill_err_i)&&(!idiv_err_flag)) + begin + if (OPT_PIPELINED) + `ASSERT(dcd_ce || cc_invalid_for_dcd || i_halt); + if (!dcd_valid) + `ASSERT(dcd_ce); + end + + always @(posedge i_clk) + if (OPT_PIPELINED && !i_halt && !i_reset && (wr_flags_ce + || (wr_reg_ce && wr_reg_id == { op_gie, CPU_CC_REG }))) + `ASSERT(cc_invalid_for_dcd); + + always @(posedge i_clk) + if (!f_past_valid || !OPT_PIPELINED) + begin + `ASSERT(!cc_invalid_for_dcd); + end else if (alu_busy) + begin + `ASSERT(cc_invalid_for_dcd == (alu_wF || alu_reg == { gie, CPU_CC_REG })); + end else if (i_mem_rdbusy || i_bus_err) + begin + `ASSERT(i_bus_err || cc_invalid_for_dcd == (alu_reg == { gie, CPU_CC_REG })); + end else if (!clear_pipeline && cc_invalid_for_dcd) + begin + `ASSERT(alu_illegal || wr_flags_ce + || ((i_mem_valid || i_bus_err) + && ($past(i_mem_rdbusy + && f_last_reg == { gie, CPU_CC_REG }))) + || (wr_flags_ce || (wr_reg_ce && wr_reg_id == { op_gie, CPU_CC_REG })) + || ($past(wr_flags_ce) + || $past(wr_reg_ce && wr_reg_id == { op_gie, CPU_CC_REG }))); + end + + // + // Make sure the ops stage is never permanently stalled + always @(*) + if ((op_valid)&&(master_ce)&&(!clear_pipeline)&&(!i_reset) + &&(!div_busy)&&(!div_valid) + &&(!i_mem_busy)&&(!i_mem_valid)&&(!i_bus_err) + &&(!alu_busy)&&(!alu_pc_valid) + &&(!fpu_busy)&&(!fpu_valid)&&(!fpu_error) + &&(!op_break)&&(!o_break) + &&(!w_switch_to_interrupt) + &&(!alu_illegal) + &&(!ibus_err_flag)&&(!ill_err_i)&&(!idiv_err_flag)) + `ASSERT(adf_ce_unconditional | mem_ce); + + // + // Make sure that, following an op_ce && op_valid, op_valid is only + // true if dcd_valid was as well + always @(posedge i_clk) + if ((f_past_valid)&&($past(op_ce && op_valid && !dcd_valid))) + begin + if ($past(dcd_early_branch)) + begin + `ASSERT(!dcd_early_branch); + end else + `ASSERT(!op_valid); + end + + // + // Same for the next step + always @(posedge i_clk) + if ((f_past_valid)&&($past(op_valid && (mem_ce ||adf_ce_unconditional))) + &&(!$past(dcd_valid))) + begin + if ($past(dcd_early_branch)) + begin + `ASSERT(!dcd_early_branch); + end else + `ASSERT(!op_valid); + end + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Assertions about the Program counter + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + always @(*) + if (i_pf_valid) + `ASSERT(i_pf_instruction_pc[1:0]==2'b00); + + always @(*) + if ((dcd_valid)&&(!dcd_illegal)) + `ASSERT((!dcd_pc[1])||(dcd_phase)); + + always @(*) + `ASSERT(!op_pc[0]); + + always @(*) + `ASSERT(!alu_pc[0]); + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Assertions about the prefetch (output) stage + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + always @(posedge i_clk) + if ((!clear_pipeline)&&(i_pf_valid)) + `ASSERT(pf_gie == gie); + + always @(*) + if ((i_pf_valid)&&(!clear_pipeline)) + `ASSERT(pf_gie == gie); + + ffetch #(.ADDRESS_WIDTH(ADDRESS_WIDTH), .OPT_CONTRACT(1'b0), + .OPT_ALIGNED(1'b1)) + chkifetch( + .i_clk(i_clk), .i_reset(i_reset), + .cpu_new_pc(o_pf_new_pc), + .cpu_clear_cache(o_clear_icache), + .cpu_pc(o_pf_request_address), .pf_valid(i_pf_valid), + .cpu_ready(o_pf_ready), .pf_pc(i_pf_instruction_pc), + .pf_insn(i_pf_instruction), .pf_illegal(i_pf_illegal)); + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Assertions about the decode stage + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + assign f_dcd_data = { + dcd_phase, + dcd_opn, dcd_A, dcd_B, dcd_R, // 4+15 + dcd_Acc, dcd_Bcc, dcd_Apc, dcd_Bpc, dcd_Rcc, dcd_Rpc,//6 + dcd_F, // 4 + dcd_wR, dcd_rA, dcd_rB, + dcd_ALU, dcd_M, dcd_DIV, dcd_FP, + dcd_wF, dcd_gie, dcd_break, dcd_lock, + dcd_pipe, dcd_ljmp, + dcd_pc, // AW+1 + dcd_I, // 32 + dcd_zI, // true if dcd_I == 0 + dcd_illegal, + dcd_early_branch, + dcd_sim, dcd_sim_immv + }; + + always @(posedge i_clk) + if ((f_past_valid)&&(!$past(i_reset))&&(!$past(clear_pipeline)) + &&(!$past(o_clear_icache)) + &&($past(dcd_valid))&&($past(dcd_stalled)) + &&(!clear_pipeline)) + begin + `ASSERT((!OPT_PIPELINED)||(dcd_valid)); + `ASSERT($stable(f_dcd_data)); + `ASSERT($stable(f_dcd_insn_word)); + end + + always @(*) + if ((dcd_valid || dcd_phase)&&(!clear_pipeline)) + `ASSERT(f_dcd_insn_gie == dcd_gie); + + always @(posedge i_clk) + if ((dcd_valid)&&(!dcd_illegal)&&(!clear_pipeline)) + begin + `ASSERT(dcd_gie == gie); + if ((gie)||(dcd_phase)) + begin + `ASSERT((!dcd_wR)||(dcd_R[4]==dcd_gie)); + `ASSERT((!dcd_rA)||(dcd_A[4]==dcd_gie)); + `ASSERT((!dcd_rB)||(dcd_B[4]==dcd_gie)); + end else if ((!dcd_early_branch)&&((dcd_M) + ||(dcd_DIV)||(dcd_FP)||(!dcd_wR))) + `ASSERT(!dcd_gie); + if ((dcd_ALU)&&(dcd_opn==CPU_MOV_OP)) + begin + `ASSERT(((!dcd_rA)&&(dcd_wR)) + ||((!dcd_rA)&&(!dcd_rB)&&(!dcd_wR))); + end else if (dcd_ALU) + `ASSERT( + (gie == dcd_R[4]) + &&(gie == dcd_A[4]) + &&((!dcd_rB)||(gie == dcd_B[4])) + &&(dcd_gie == gie)); + end + + always @(*) + if ((op_valid)&&(op_rA)&&(op_Aid[3:1] == 3'h7)&&(!clear_pipeline) + &&(op_Aid[4:0] != { gie, 4'hf})) + `ASSERT(!pending_sreg_write); + + always @(*) + if ((op_valid)&&(op_rB)&&(op_Bid[3:1] == 3'h7)&&(!clear_pipeline) + &&(op_Bid[4:0] != { gie, 4'hf})) + `ASSERT(!pending_sreg_write); + + + always @(*) + if ((dcd_valid)&&(!clear_pipeline)) + `ASSERT(dcd_gie == gie); + + // + // + // Piped Memory assertions + // + // + always @(*) + if ((dcd_valid)&&(dcd_M)&&(dcd_pipe)&&(!dcd_illegal)&&(!alu_illegal) + &&(!break_pending)&&(!clear_pipeline)) + begin + if (op_valid_mem) + begin + `ASSERT(op_opn[0] == dcd_opn[0]); + `ASSERT((!dcd_rB) + ||(op_Bid[4:0] == dcd_B[4:0])); + `ASSERT(op_rB == dcd_rB); + end + `ASSERT(dcd_B[4] == dcd_gie); + end + + always @(*) + if (op_valid_mem && op_pipe && i_mem_busy) + `ASSERT(f_read_cycle == !op_opn[0]); + + always @(*) + if ((dcd_valid)&&(!dcd_M)) + `ASSERT((dcd_illegal)||(!dcd_pipe)); + + assign f_dcd_mem_addr = w_op_BnI+dcd_I; + + always @(posedge i_clk) + if ((f_past_valid)&&($past(dcd_early_branch))&&(!dcd_early_branch) + &&(dcd_valid)) + `ASSERT(!dcd_pipe); + always @(*) + if ((dcd_valid)&&(dcd_early_branch)) + `ASSERT(!dcd_M); + + always @(*) + if ((dcd_valid)&&(!dcd_illegal)&&(!fc_op_prepipe)) + `ASSERT(!dcd_pipe); + + always @(*) + if ((dcd_valid)&&(dcd_pipe)&&(w_op_valid)) + begin + // `ASSERT((dcd_A[3:1] != 3'h7)||(dcd_opn[0])); + `ASSERT(dcd_B[3:1] != 3'h7); + `ASSERT(dcd_rB); + `ASSERT(dcd_M); + `ASSERT(dcd_B == op_Bid); + if (op_valid) + `ASSERT((op_valid_mem)||(op_illegal)); + + if (op_valid_mem) + begin + `ASSERT((dcd_I[AW+1:3] == 0) + ||(!alu_busy)||(!div_busy) + ||(!alu_wR)||(alu_reg != dcd_B)); + `ASSERT((!op_wR)||(op_Aid != op_Bid)); + end + end + + // + // Decode option processing + // + + // OPT_CIS ... the compressed instruction set + always @(*) + if ((!OPT_CIS)&&(dcd_valid)) + begin + `ASSERT(!dcd_phase); + `ASSERT(dcd_pc[1:0] == 2'b0); + end + + always @(*) + if ((dcd_valid)&&(dcd_phase)) + `ASSERT(f_dcd_insn_word[31]); + + + // OPT_EARLY_BRANCHING + always @(*) + if (!OPT_EARLY_BRANCHING) + `ASSERT((!dcd_early_branch) + &&(!dcd_early_branch_stb) + &&(!dcd_ljmp)); + + // IMPLEMENT_DIVIDE + always @(*) + if ((dcd_DIV)&&(dcd_valid)&&(!dcd_illegal)) + `ASSERT(dcd_wR); + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Assertions about the op stage + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + assign f_op_data = { op_valid_mem, op_valid_alu, + op_valid_div, op_valid_fpu, + // The Av and Bv values can change while we are stalled in the + // op stage--that's why we are stalled there + // r_op_Av, r_op_Bv, // 32 ea + op_pc[AW+1:2], // AW + op_wR, op_wF, + r_op_F, // 7 + op_illegal, op_break, + op_lock, op_pipe + }; + + + always @(posedge i_clk) + if ((f_past_valid)&&($past(op_valid))&&(!$past(i_reset)) + &&(!$past(clear_pipeline))) + begin + if (($past(op_valid_mem))&&($past(mem_stalled))) + `ASSERT($stable(f_op_data[AW+16:1])&&(!$rose(op_pipe))); + if (($past(op_valid_div))&&($past(div_busy))) + `ASSERT($stable(f_op_data)); + end + + f_idecode #( + // {{{ + .OPT_MPY((IMPLEMENT_MPY!=0)? 1'b1:1'b0), + .OPT_DIVIDE(IMPLEMENT_DIVIDE), + .OPT_FPU(IMPLEMENT_FPU), + .OPT_LOCK(OPT_LOCK), + .OPT_OPIPE(OPT_PIPELINED_BUS_ACCESS), + .OPT_SIM(1'b0), + .OPT_CIS(OPT_CIS) + // }}} + ) f_insn_decode_op( + // {{{ + f_op_insn_word, f_op_phase, op_gie, + fc_op_illegal, fc_op_Rid, fc_op_Aid, fc_op_Bid, + fc_op_I, fc_op_cond, fc_op_wF, fc_op_op, fc_op_ALU, + fc_op_M, fc_op_DV, fc_op_FP, fc_op_break, fc_op_lock, + fc_op_wR, fc_op_rA, fc_op_rB, fc_op_prepipe, + fc_op_sim, fc_op_sim_immv + // }}} + ); + + initial f_op_early_branch = 1'b0; + always @(posedge i_clk) + if (op_ce) + begin + f_op_insn_word <= f_dcd_insn_word; + f_op_phase <= dcd_phase; + f_op_early_branch <= dcd_early_branch; + f_op_zI <= dcd_zI; + end + + initial f_op_branch = 1'b0; + always @(posedge i_clk) + if ((i_reset)||(clear_pipeline)) + f_op_branch <= 1'b0; + else if (op_ce) + f_op_branch <= (dcd_early_branch)||dcd_ljmp; + else if ((adf_ce_unconditional)||(mem_ce)) + f_op_branch <= 1'b0; + + always @(*) + if (!OPT_EARLY_BRANCHING) + begin + `ASSERT(!f_op_branch); + end else if ((f_op_early_branch)&&(op_valid)) + `ASSERT(f_op_branch); + + + always @(posedge i_clk) + if ((op_valid)&&((f_op_branch)||(!fc_op_illegal))&&(!clear_pipeline)) + begin + // {{{ + if (f_op_branch) + begin + // {{{ + `ASSERT(!op_valid_alu); + `ASSERT(!op_valid_mem); + `ASSERT(!op_valid_div); + `ASSERT(!op_valid_fpu); + `ASSERT(!op_illegal); + `ASSERT(!op_rA); + `ASSERT(!op_rB); + `ASSERT(!op_wR); + `ASSERT(!op_wF); + `ASSERT(op_opn == CPU_MOV_OP); + // }}} + end + + if (op_illegal) + begin + // {{{ + `ASSERT(!op_valid_mem); + `ASSERT(!op_valid_div); + `ASSERT(!op_valid_fpu); + `ASSERT( op_valid_alu); + `ASSERT((!OPT_PIPELINED)||(!op_rA)); + `ASSERT((!OPT_PIPELINED)||(!op_rB)); + `ASSERT(!f_op_branch); + // }}} + end else begin + if (!f_op_branch) + begin + // {{{ + `ASSERT(fc_op_ALU == op_valid_alu); + `ASSERT(fc_op_M == op_valid_mem); + `ASSERT(fc_op_DV == op_valid_div); + `ASSERT(fc_op_FP == op_valid_fpu); + `ASSERT(fc_op_rA == op_rA); + `ASSERT(fc_op_rB == op_rB); + `ASSERT(fc_op_wF == op_wF); + `ASSERT(fc_op_Rid[4:0] == op_R); + `ASSERT(f_op_zI == (fc_op_I == 0)); + `ASSERT(fc_op_wF == op_wF); + `ASSERT(fc_op_lock == op_lock); + `ASSERT(fc_op_break == op_break); + `ASSERT(fc_op_I == 0 || !i_mem_rdbusy + || !fc_op_rB + || (fc_op_Bid[4:0] != f_last_reg + && (f_mem_outstanding <= 1) + && (!fc_op_M || !op_pipe)) + || fc_op_Bid[4:0] == f_addr_reg); + if (!i_halt && !i_reset) + `ASSERT((!wr_reg_ce) + ||(wr_reg_id != fc_op_Bid[4:0]) + ||(!op_rB)||(fc_op_I == 0)); +`ifdef VERILATOR + `ASSERT(fc_op_sim == op_sim); + `ASSERT(fc_op_sim_immv == op_sim_immv); +`endif + + case(fc_op_cond[2:0]) + 3'h0: `ASSERT(op_F == 8'h00); // Always + 3'h1: `ASSERT(op_F == 8'h11); // Z + 3'h2: `ASSERT(op_F == 8'h44); // LT + 3'h3: `ASSERT(op_F == 8'h22); // C + 3'h4: `ASSERT(op_F == 8'h88); // V + 3'h5: `ASSERT(op_F == 8'h10); // NE + 3'h6: `ASSERT(op_F == 8'h40); // GE (!N) + 3'h7: `ASSERT(op_F == 8'h20); // NC + endcase + + if ((fc_op_wR)&&(fc_op_Rid[4:0] == { gie, CPU_PC_REG})) + begin + `ASSERT(!op_phase); + end else + `ASSERT(f_op_phase == op_phase); + // }}} + end // Bit order is { (flags_not_used), VNCZ mask, VNCZ value } + `ASSERT((!op_wR)||(fc_op_Rid[4:0] == op_R)); + `ASSERT(((!op_wR)&&(!op_rA))||(fc_op_Aid[4:0] == op_Aid[4:0])); + `ASSERT((!op_rB)||(fc_op_Bid[4:0] == op_Bid)); + // + // if ((!alu_illegal)&&(!ill_err_i)&&(!clear_pipeline)) + + if (f_op_early_branch) + begin + // {{{ + `ASSERT(op_opn == CPU_MOV_OP); + `ASSERT(!op_wR); + `ASSERT(!op_wF); + `ASSERT(f_op_branch); + // }}} + end else begin + // {{{ + `ASSERT(fc_op_op == op_opn); + `ASSERT(fc_op_wR == op_wR); + // }}} + end + end + if (!OPT_PIPELINED_BUS_ACCESS) + `ASSERT((!i_mem_rdbusy)||(i_mem_wreg != fc_op_Bid) + ||(!fc_op_rB)||(fc_op_I == 0)); + // }}} + end else if ((op_valid)&&(!clear_pipeline)&&(fc_op_illegal)) + begin + // {{{ + `ASSERT(op_illegal); + `ASSERT(op_valid_alu); + `ASSERT(!f_op_branch); + // }}} + end + + always @(*) + if ((op_valid)&&(op_illegal)) + begin + `ASSERT(!op_valid_div); + `ASSERT(!op_valid_fpu); + `ASSERT(!op_valid_mem); + end + +// always @(*) +// if (!op_valid) +// `ASSERT(!op_break); + + always @(*) + if ((!OPT_CIS)&&(op_valid)) + begin + `ASSERT((!op_phase)||(op_illegal)); + `ASSERT(op_pc[1:0] == 2'b0); + end + + always @(*) + if ((!OPT_LOCK)&&(op_valid)) + `ASSERT((!op_lock)||(op_illegal)); + + always @(*) + if (!OPT_EARLY_BRANCHING) + `ASSERT(!f_op_early_branch); + + + always @(*) + if (op_ce) + `ASSERT((dcd_valid)||(dcd_illegal)||(dcd_early_branch)); + + always @(*) + if ((f_past_valid)&&(!f_op_zI)&&(i_mem_rdbusy)&&(op_valid)&&(op_rB)) + `ASSERT((!OPT_DCACHE)||(OPT_MEMPIPE) + ||(i_mem_wreg != op_Bid)); + + always @(posedge i_clk) + if ((op_valid)&&(op_rB)&&(!f_op_zI)&&((i_mem_rdbusy)||(i_mem_valid)) + &&(i_mem_wreg != {gie, CPU_PC_REG})) + begin + if (!OPT_MEMPIPE) + begin + `ASSERT(fc_alu_Aid[4:0] == i_mem_wreg); + `ASSERT(i_mem_wreg != op_Bid); + end + end + + always @(posedge i_clk) + if (i_mem_rdbusy) + begin + `ASSERT(fc_alu_M); + `ASSERT((!OPT_PIPELINED)||(fc_alu_wR)); + end + + always @(*) + if ((op_valid)&&(!clear_pipeline)) + `ASSERT(op_gie == gie); + + always @(*) + if ((op_valid_alu)&&(!op_illegal)) + begin + if ((op_opn != CPU_SUB_OP) + &&(op_opn != CPU_AND_OP) + &&(op_opn != CPU_MOV_OP)) + begin + `ASSERT(op_wR); + end + if ((op_opn != CPU_MOV_OP)&&(op_opn != CPU_BREV_OP)) + `ASSERT(op_rA); + end + + + always @(posedge i_clk) + if ((op_valid)&&(!op_illegal) + &&(!alu_illegal)&&(!ill_err_i)&&(!clear_pipeline)) + begin + `ASSERT(op_gie == gie); + if ((gie)||(op_phase)) + begin + `ASSERT((!op_wR)||(op_R[4] == gie)); + `ASSERT((!op_rA)||(op_Aid[4] == gie)); + `ASSERT((!op_rB)||(op_Bid[4] == gie)); + end else if (((op_valid_mem) + ||(op_valid_div)||(op_valid_fpu) + ||((op_valid_alu)&&(op_opn!=CPU_MOV_OP)))) + begin + `ASSERT((!op_wR)||(op_R[4] == gie)); + `ASSERT((!op_rA)||(op_Aid[4] == gie)); + `ASSERT((!op_rB)||(op_Bid[4] == gie)); + end + end + + always @(posedge i_clk) + if ((!op_valid)&&(!$past(op_illegal)) + &&(!clear_pipeline)&&(!pending_interrupt)) + `ASSERT(!op_illegal); + + always @(*) + begin + if (alu_ce) + `ASSERT(adf_ce_unconditional); + if (div_ce) + `ASSERT(adf_ce_unconditional); + if (fpu_ce) + `ASSERT(adf_ce_unconditional); + + if ((op_valid)&&(op_illegal)) + `ASSERT(op_valid_alu); + end + + always @(*) + if (mem_ce) + `ASSERT((op_valid)&&(op_valid_mem)&&(!op_illegal)); + + always @(*) + if (div_ce) + `ASSERT(op_valid_div); + + + always @(*) + if ((ibus_err_flag)||(ill_err_i)||(idiv_err_flag)) + begin + `ASSERT(master_stall); + `ASSERT(!mem_ce); + `ASSERT(!alu_ce); + `ASSERT(!div_ce); + `ASSERT(!adf_ce_unconditional); + end + + always @(posedge i_clk) + if ((adf_ce_unconditional)||(mem_ce)) + `ASSERT(op_valid); + + always @(*) + if ((op_valid_alu)&&(!adf_ce_unconditional)&&(!clear_pipeline)) + `ASSERT(!op_ce); + + always @(*) + if ((op_valid_div)&&(!adf_ce_unconditional)) + `ASSERT(!op_ce); + + always @(posedge i_clk) + if (alu_stall) + `ASSERT(!alu_ce); + always @(posedge i_clk) + if (mem_stalled) + `ASSERT(!o_mem_ce); + always @(posedge i_clk) + if (div_busy) + `ASSERT(!div_ce); + + always @(*) + if ((!i_reset)&&(break_pending)&&(!clear_pipeline)) + `ASSERT((op_valid)&&(op_break)); + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Memory + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // Op: Memory pipeline assertions + // + + assign f_next_mem = o_mem_addr + 1'b1; + assign f_op_mem_addr = op_Bv[AW+1:2]; + + fmem #( + // {{{ + .IMPLEMENT_LOCK(OPT_LOCK), .F_LGDEPTH(F_LGDEPTH), + .OPT_MAXDEPTH((OPT_PIPELINED && OPT_PIPELINED_BUS_ACCESS) + ? 14:1), + .OPT_AXI_LOCK(2) // Let the solver pick + // }}} + ) chkmemops( + // {{{ + .i_clk(i_clk), .i_sys_reset(i_reset), .i_cpu_reset(i_reset), + // + .i_stb(o_mem_ce), + .i_pipe_stalled(i_mem_pipe_stalled), + .i_clear_cache(o_clear_dcache), + .i_lock(o_bus_lock), + .i_op(o_mem_op), .i_data(o_mem_data), .i_addr(o_mem_addr), + .i_oreg(o_mem_reg), .i_areg(op_Bid), + .i_busy(i_mem_busy),.i_rdbusy(i_mem_rdbusy), + .i_valid(i_mem_valid), .i_err(i_bus_err), .i_wreg(i_mem_wreg), + .i_result(i_mem_result), + .f_outstanding(f_mem_outstanding), + .f_pc(f_mem_pc), .f_gie(f_mem_gie), + .f_read_cycle(f_read_cycle), + .f_axi_write_cycle(f_exwrite_cycle), + .f_last_reg(f_last_reg), .f_addr_reg(f_addr_reg) + // }}} + ); + + always @(*) + if ((op_valid)&&(!fc_alu_prepipe)) + `ASSERT((!op_valid_mem)||(!op_pipe)); + + // Validate op_opn and (some of) op_Bid + // {{{ + always @(*) + if ((op_valid_mem)&&(op_pipe)) + begin + // {{{ + if (i_mem_rdbusy) + `ASSERT(op_opn[0] == 1'b0); + if (f_mem_outstanding > ((i_bus_err || i_mem_valid) ? 1:0)) + `ASSERT(op_opn[0] != fc_alu_wR); + + // if ((i_mem_busy)&&(!i_mem_rdbusy && !i_mem_valid)) + // `ASSERT(!o_mem_ce || op_opn[0] == 1'b1); + + if (i_mem_rdbusy) + begin + if (OPT_PIPELINED_BUS_ACCESS) + begin end + else if (OPT_DCACHE) + `ASSERT(!i_mem_valid || i_mem_wreg != op_Bid); + end + // }}} + end + // }}} + + always @(posedge i_clk) + if ((op_valid_mem)&&(op_pipe)) + begin + // {{{ + if ((i_mem_busy)&&(!OPT_DCACHE)) + `ASSERT((f_op_mem_addr == o_mem_addr) + ||(f_op_mem_addr == f_next_mem)); + if (i_mem_valid) + `ASSERT(op_Bid != i_mem_wreg); + + if (alu_busy||alu_valid) + `ASSERT((!alu_wR)||(op_Bid != alu_reg)); + + if (f_past_valid) + begin + if ((i_mem_busy)&&(!OPT_DCACHE)) + `ASSERT((op_Bv[(AW+1):2]==o_mem_addr[(AW-1):0]) + ||(op_Bv[(AW+1):2]==o_mem_addr[(AW-1):0]+1'b1)); + + if ($past(mem_ce)) + `ASSERT(op_Bid == $past(op_Bid)); + end + + `ASSERT(op_Bid[3:1] != 3'h7); + + if ((i_mem_rdbusy)||(i_mem_valid)) + begin + if (!OPT_MEMPIPE) + begin + // {{{ + `ASSERT(fc_alu_Aid[4:0] == i_mem_wreg); + `ASSERT(i_mem_wreg != op_Bid); + // }}} + end else if (OPT_DCACHE) + begin + // {{{ + `ASSERT(fc_alu_Aid[4:0] != op_Bid); + // }}} + end else // if (!OPT_DCACHE) + begin + // {{{ + if ((i_mem_valid) + ||($past(i_mem_rdbusy))) + `ASSERT(i_mem_wreg != op_Bid); + // }}} + end + end + // }}} + end + + always @(*) + if ((dcd_valid)&&(dcd_pipe)) + `ASSERT((op_Aid[3:1] != 3'h7)||(op_opn[0])); + + always @(*) + if ((op_valid)&(!op_valid_mem)) + `ASSERT((op_illegal)||(!op_pipe)); + + // Check f_addr_reg and f_last_reg + // {{{ + always @(*) + if (OPT_MEMPIPE && (op_valid && op_rB) + &&(!f_op_zI)&&((i_mem_rdbusy)||(i_mem_valid))) + `ASSERT(f_last_reg != op_Bid); + + always @(*) + if (i_mem_rdbusy) + `ASSERT(f_last_reg == alu_reg); + + always @(*) + if ((op_valid_mem)&&(op_pipe) && i_mem_valid) + `ASSERT(op_Bid != i_mem_wreg); + + always @(*) + if ((op_valid_mem)&&(op_pipe) && (i_mem_rdbusy || i_mem_valid)) + `ASSERT(op_Bid == f_addr_reg); + + always @(*) + if (i_mem_rdbusy) + begin + if (op_valid_mem && op_pipe) + begin + `ASSERT(op_Bid == f_addr_reg); + `ASSERT(op_Bid != f_last_reg); + if (dcd_M && dcd_pipe && !dcd_illegal + && !dcd_early_branch) + `ASSERT(op_Bid == dcd_B[4:0]); + end else if (!op_valid_mem && dcd_M && dcd_pipe + && !dcd_illegal && !dcd_early_branch) + `ASSERT(dcd_B[4:0] == f_addr_reg); + end + // }}} + + always @(*) + if (op_valid && !f_op_zI && i_mem_rdbusy && (f_last_reg != { gie, CPU_PC_REG })) + `ASSERT(!op_rB || fc_op_Bid[4:0] == f_addr_reg + ||((f_mem_outstanding == 1) && (fc_op_Bid[4:0] != f_last_reg))); + + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Assertions about the ALU stage + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + always @(*) + if ((alu_ce)&&(!clear_pipeline)) + `ASSERT((op_valid_alu)&&(op_gie == gie)); + always @(*) + if ((mem_ce)&&(!clear_pipeline)) + `ASSERT((op_valid_mem)&&(op_gie == gie)); + always @(*) + if ((div_ce)&&(!clear_pipeline)) + `ASSERT((op_valid_div)&&(op_gie == gie)); + + always @(*) + if ((!clear_pipeline)&&((i_mem_valid)||(div_valid)||(div_busy) + ||(i_mem_rdbusy)||(alu_valid))) + `ASSERT(alu_gie == gie); + always @(*) + if ((!OPT_CIS)&&(alu_pc_valid)) + `ASSERT(alu_pc[1:0] == 2'b0); + always @(*) + if (!OPT_LOCK) + `ASSERT((!o_bus_lock)&&(!prelock_stall)); + always @(*) + if (!IMPLEMENT_DIVIDE) + `ASSERT((!dcd_DIV)&&(!op_valid_div)&&(!div_busy)&&(!div_valid)&&(!div_ce)); + always @(*) + if (IMPLEMENT_MPY == 0) + `ASSERT(alu_busy == 1'b0); + + + always @(*) + if (!clear_pipeline) + begin + if ((alu_valid)||(alu_illegal)) + `ASSERT(alu_gie == gie); + if (div_valid) + `ASSERT(alu_gie == gie); + end + + always @(*) + if (alu_busy) + begin + `ASSERT(!i_mem_rdbusy); + `ASSERT(!div_busy); + `ASSERT(!fpu_busy); + end else if (i_mem_rdbusy) + begin + `ASSERT(!div_busy); + `ASSERT(!fpu_busy); + end else if (div_busy) + `ASSERT(!fpu_busy); + + always @(posedge i_clk) + if ((div_valid)||(div_busy)) + `ASSERT(alu_reg[3:1] != 3'h7); + + always @(posedge i_clk) + if ((f_past_valid)&&(wr_reg_ce) + &&((!$past(r_halted))||(!$past(i_dbg_we)))) + `ASSERT(alu_gie == gie); + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Contract checking : A operand + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + always @(*) + begin + f_Av = regset[fc_op_Aid[4:0]]; + if (fc_op_Aid[3:0] == CPU_PC_REG) + begin + if ((wr_reg_ce)&&(wr_reg_id == fc_op_Aid[4:0])) + f_Av = wr_spreg_vl; + else if (fc_op_Aid[4] == op_gie) + f_Av = op_pc; // f_next_addr; + else if (fc_op_Aid[3:0] == { 1'b1, CPU_PC_REG }) + begin + f_Av[31:(AW+1)] = 0; + f_Av[(AW+1):0] = { upc, uhalt_phase, 1'b0 }; + end + end else if (fc_op_Aid[4:0] == { 1'b0, CPU_CC_REG }) + begin + f_Av = { w_cpu_info, regset[fc_op_Aid[4:0]][22:16], w_iflags }; + if ((wr_reg_ce)&&(wr_reg_id == fc_op_Aid[4:0])) + f_Av[22:16] = wr_spreg_vl[22:16]; + end else if (fc_op_Aid[4:0] == { 1'b1, CPU_CC_REG }) + begin + f_Av = { w_cpu_info, regset[fc_op_Aid[4:0]][22:16], w_uflags }; + if ((wr_reg_ce)&&(wr_reg_id == fc_op_Aid[4:0])) + f_Av[22:16] = wr_spreg_vl[22:16]; + end else if ((wr_reg_ce)&&(wr_reg_id == fc_op_Aid[4:0])) + f_Av = wr_gpreg_vl; + else + f_Av = regset[fc_op_Aid[4:0]]; + end + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Contract checking : B operand + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + // The PRE-logic + always @(*) + begin + f_pre_Bv = regset[fc_op_Bid[4:0]]; + // + if (fc_op_Bid[3:0] == CPU_PC_REG) + begin + // Can always read your own address + if (fc_op_Bid[4] == op_gie) + f_pre_Bv = { {(30-AW){1'b0}}, op_pc[(AW+1):2], 2'b00 }; // f_next_addr; + else // if (fc_op_Bid[4]) + // Supervisor or user may read the users PC reg + begin + f_pre_Bv = 0; + f_pre_Bv[(AW+1):0] = { upc[(AW+1):2], uhalt_phase, 1'b0 }; + if ((wr_reg_ce)&&(wr_reg_id == fc_op_Bid[4:0])) + f_pre_Bv = wr_spreg_vl; + end + end else if (fc_op_Bid[3:0] == CPU_CC_REG) + begin + f_pre_Bv = { w_cpu_info, regset[fc_op_Bid[4:0]][22:16], + w_uflags }; + // if ((fc_op_Bid[4] == op_gie)&&(!fc_op_Bid[4])) + f_pre_Bv[15:0] = (gie || fc_op_Bid[4]) ? w_uflags : w_iflags; + + if ((wr_reg_ce)&&(wr_reg_id == fc_op_Bid[4:0])) + f_pre_Bv[22:16] = wr_spreg_vl[22:16]; + + end else if ((wr_reg_ce)&&(wr_reg_id == fc_op_Bid[4:0])) + f_pre_Bv = wr_gpreg_vl; + else + f_pre_Bv = regset[fc_op_Bid[4:0]]; + end + + + // The actual calculation of B + assign f_Bv = (fc_op_rB) + ? ((fc_op_Bid[5]) + ? ( { f_pre_Bv }+{ fc_op_I[29:0],2'b00 }) + : (f_pre_Bv + fc_op_I)) + : fc_op_I; + // }}} + //////////////////////////////////////////////////////////////////////// + // + // CONTRACT: The operands to an ALU/MEM/DIV operation must be valid. + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + always @(posedge i_clk) + if (!i_reset && op_valid && !op_illegal + && (!clear_pipeline && !dbg_clear_pipe) + && (!i_halt || !dbgv) + &&((!wr_reg_ce)||(wr_reg_id!= { gie, CPU_PC_REG })) + &&(!f_op_branch)) + begin + if ((fc_op_rA)&&(fc_op_Aid[3:1] != 3'h7)) + `ASSERT(f_Av == op_Av); + + if (!fc_op_rB || fc_op_Bid[4:0] != { gie, CPU_CC_REG } + || !OPT_PIPELINED) + begin + `ASSERT(f_Bv == op_Bv); + end else if (f_op_zI) + `ASSERT(((f_Bv ^ op_Bv) & 32'hffff_c0ff) == 0); + end + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Assertions about the ALU stage + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + // alu_valid + // alu_ce + // alu_stall + // ALU stage assertions + + always @(posedge i_clk) + if ((alu_ce)||(mem_ce)||(div_ce)||(fpu_ce)) + begin + f_alu_insn_word <= f_op_insn_word; + f_alu_phase <= f_op_phase; + end + + initial f_alu_branch = 1'b0; + always @(posedge i_clk) + if ((adf_ce_unconditional)||(mem_ce)) + f_alu_branch <= f_op_branch; + else + f_alu_branch <= 1'b0; + + f_idecode #( + // {{{ + .OPT_MPY((IMPLEMENT_MPY!=0)? 1'b1:1'b0), + .OPT_DIVIDE(IMPLEMENT_DIVIDE), + .OPT_FPU(IMPLEMENT_FPU), + .OPT_LOCK(OPT_LOCK), + .OPT_OPIPE(OPT_PIPELINED_BUS_ACCESS), + .OPT_SIM(1'b0), + .OPT_CIS(OPT_CIS) + // }}} + ) f_insn_decode_alu( + // {{{ + f_alu_insn_word, f_alu_phase, alu_gie, + fc_alu_illegal, fc_alu_Rid, fc_alu_Aid, fc_alu_Bid, + fc_alu_I, fc_alu_cond, fc_alu_wF, fc_alu_op, fc_alu_ALU, + fc_alu_M, fc_alu_DV, fc_alu_FP, fc_alu_break, + fc_alu_lock, fc_alu_wR, fc_alu_rA, fc_alu_rB, + fc_alu_prepipe, fc_alu_sim, fc_alu_sim_immv + // }}} + ); + + always @(posedge i_clk) + if (!wr_reg_ce) + begin + if (f_alu_branch) + begin + `ASSERT((!div_valid)&&(!div_busy)); + `ASSERT((!fpu_valid)&&(!fpu_busy)); + `ASSERT(!i_mem_rdbusy); + `ASSERT(!alu_busy); + end else begin + if (!fc_alu_DV) + `ASSERT((!div_valid)&&(!div_busy)&&(!div_error)); + if (!fc_alu_M) + `ASSERT(!i_mem_rdbusy); + if (!fc_alu_ALU) + `ASSERT(!alu_busy); + if (!fc_alu_FP) + `ASSERT((!fpu_busy)&&(!fpu_error)); + if (alu_busy) + `ASSERT((fc_alu_op[3:1] == 3'h5) + ||(fc_alu_op[3:0] == 4'hc)); + if ((alu_busy)||(div_busy)||(fpu_busy)) + begin + `ASSERT(!i_mem_rdbusy); + `ASSERT((clear_pipeline) + ||(fc_alu_Rid[4:0] == alu_reg)); + if (alu_busy) + `ASSERT(fc_alu_wF == alu_wF); + if ((fc_alu_Rid[3:1] == 3'h7)&&(alu_wR) + &&(fc_alu_Rid[4:0] != { gie, 4'hf })) + `ASSERT(pending_sreg_write); + end else if (i_mem_rdbusy) + begin + if ($past(i_mem_rdbusy)) + `ASSERT(fc_alu_Rid[4] == f_mem_gie); + end + + //if ((div_busy)||(fpu_busy)) + // `ASSERT(alu_wR); + //else + if ((alu_busy)&&(alu_wR)) + `ASSERT(fc_alu_wR); + + if (alu_busy || i_mem_rdbusy || div_busy) + begin + if ((fc_alu_wR)&&(fc_alu_Rid[4:0] == { gie, CPU_PC_REG})) + begin + `ASSERT(!alu_phase); + end else + `ASSERT(f_alu_phase == alu_phase); + end + end + + end else if (!dbgv) // && wr_reg_ce + begin + `ASSERT(fc_alu_DV || (!div_valid)&&(!div_error)); + `ASSERT(fc_alu_ALU|| !alu_valid); + `ASSERT(fc_alu_M || !i_mem_valid); + `ASSERT(fc_alu_FP || (!fpu_valid)&&(!fpu_error)); + `ASSERT((!alu_busy)&&(!div_busy)&&(!fpu_busy)); + + if ((!alu_illegal)&&(fc_alu_cond[3])&&(fc_alu_wR)&&(fc_alu_ALU)) + `ASSERT(alu_wR); + if (!i_mem_valid) + `ASSERT(fc_alu_Rid[4:0] == alu_reg); + `ASSERT((!alu_wR)||(fc_alu_wR == alu_wR)); + if (alu_valid) + `ASSERT(fc_alu_wF == alu_wF); + if (!fc_alu_wF) + `ASSERT(!wr_flags_ce); + + `ASSERT(!f_alu_branch); + end + + always @(posedge i_clk) + if (f_mem_pc && i_mem_rdbusy) + begin + // {{{ + `ASSERT(!OPT_PIPELINED || cc_invalid_for_dcd + || fc_alu_Rid[4:0] != { gie, CPU_CC_REG }); + `ASSERT(!mem_ce); + + if (OPT_PIPELINED && fc_alu_Rid[4:0] != { gie, CPU_PC_REG }) + `ASSERT(pending_sreg_write); + if ((!OPT_DCACHE)||(!OPT_MEMPIPE)) + begin + `ASSERT(!fc_alu_prepipe); + end else if ((i_mem_rdbusy)&&(!$past(mem_ce))&&(!$past(mem_ce,2))) + `ASSERT(!fc_alu_prepipe); + // }}} + end else if (i_mem_rdbusy) + begin + `ASSERT(!pending_sreg_write); + // assert(!cc_invalid_for_dcd); + end + + // Ongoing memory operation check + // {{{ + always @(posedge i_clk) + if (i_mem_rdbusy) + begin + // In pipelined mode, this is an ongoing load operation + // Otherwise, mem_rdbusy == i_mem_busy and we have no idea + // what type of operation we are in + `ASSERT(!fc_alu_illegal); + `ASSERT(fc_alu_M); + `ASSERT(alu_reg == f_last_reg); + if (alu_reg == f_addr_reg) + `ASSERT(!op_pipe); + if (fc_alu_cond[3]) + `ASSERT(fc_alu_Rid[4:0] == alu_reg); + + if ((fc_alu_wR)&&(fc_alu_Rid[4:0] == { gie, CPU_PC_REG})) + begin + `ASSERT(!alu_phase); + end else + `ASSERT(f_alu_phase == alu_phase); + + if (f_exwrite_cycle) + begin + `ASSERT(!fc_alu_wR); + end else + `ASSERT(fc_alu_wR); + end else if ((i_mem_busy)&&(fc_alu_M) + &&(f_mem_outstanding > ((i_mem_valid || i_bus_err) ? 1:0)) + &&(!i_bus_err)) + begin // Ongoing store operation + // {{{ + `ASSERT(!fc_alu_illegal); + `ASSERT(fc_alu_M); + `ASSERT(!fc_alu_wR); + // }}} + end + // }}} + + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Assertions about the writeback stage + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + initial assert((!OPT_LOCK)||(OPT_PIPELINED)); + + always @(posedge i_clk) + if ((f_past_valid)&&($past(i_reset))&&($past(gie) != gie)) + `ASSERT(clear_pipeline); + + always @(*) + if (!IMPLEMENT_FPU) + begin + `ASSERT(!ifpu_err_flag); + `ASSERT(!ufpu_err_flag); + end + + always @(posedge i_clk) + if (dbgv) + begin + `ASSERT(wr_index == 3'h0); + `ASSERT(wr_gpreg_vl == $past(i_dbg_data)); + `ASSERT(wr_spreg_vl == $past(i_dbg_data)); + end + + always @(*) + if (i_mem_rdbusy || i_mem_valid) + begin + `ASSERT(wr_index == 3'h1); + if (i_mem_valid) + `ASSERT(wr_gpreg_vl == i_mem_result); + end + + always @(*) + if (alu_busy || alu_valid) + begin + `ASSERT(wr_index == 3'h2); + if (alu_valid) + begin + `ASSERT(wr_gpreg_vl == alu_result); + `ASSERT(wr_spreg_vl == alu_result); + end + end + + always @(*) + if (div_busy || div_valid || div_error) + begin + `ASSERT(wr_index == 3'h3); + if (div_valid) + `ASSERT(wr_gpreg_vl == div_result); + end + + always @(*) + if (fpu_busy || fpu_valid || fpu_error) + begin + `ASSERT(wr_index == 3'h4); + if (fpu_valid) + `ASSERT(wr_gpreg_vl == fpu_result); + end + + always @(posedge i_clk) + if ((f_past_valid)&&(r_halted)) + begin + `ASSERT(!div_busy); + `ASSERT(!i_mem_rdbusy); + `ASSERT(!alu_busy); + `ASSERT(!div_valid); + `ASSERT(!i_mem_valid); + `ASSERT(!alu_valid); + end + + always @(*) + if (((wr_reg_ce)||(wr_flags_ce))&&(!dbgv)) + `ASSERT(!alu_illegal); + + always @(*) + if (!fc_alu_wR) + `ASSERT(!i_mem_rdbusy); + + always @(*) + if (alu_illegal) + `ASSERT(!i_mem_rdbusy); + + always @(posedge i_clk) + if (wr_reg_ce && !$past(i_dbg_we)) + begin + `ASSERT(fc_alu_wR); + + // Since writes are asynchronous, they can create errors later + `ASSERT((!i_bus_err)||(!i_mem_valid)); + `ASSERT(!fpu_error); + `ASSERT(!div_error); + end + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Clock enable checking + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + always @(posedge i_clk) + if (!OPT_GATE_CLOCK) + begin + assert(o_clken); + end else if (!f_past_valid) + begin end // clken can be anything on the first clock + else if (!OPT_GATE_CLOCK) + begin + assert(o_clken); + end else if ($past(i_reset && !i_mem_busy)) + begin + assert(!o_clken); + end else if (i_mem_busy || div_busy || alu_busy || fpu_busy) + begin + assert(o_clken); + end else if ($past(i_interrupt && !i_halt)) + begin + assert(o_clken); + end else if (!sleep && !r_halted) + begin + assert(o_clken); + end + + always @(posedge i_clk) + if (!i_reset && sleep) + begin + assert(!wr_reg_ce || dbgv); + assert(!i_mem_rdbusy); + end + + always @(posedge i_clk) + if (!i_reset && r_halted) + assert(!i_mem_busy); + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Low power checking + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + // In low power mode, *nothing* should change unless we are doing + // something. + + generate if (OPT_LOWPOWER && OPT_PIPELINED) + begin : F_OPT_LOWPOWER_CHECK + wire [70:0] op_state; + + // + // OP* registers can only be expected to hold steady if + // pipelined. If not pipelined, many of these registers + // become aliases for the decode registers which will + // (of course) change from one clock to the next. + // + assign op_state = { op_valid_mem, op_valid_div, op_valid_alu, + op_valid_fpu, + op_opn, op_R, op_Rcc, op_Aid, + op_Bid, op_pc, + r_op_break, op_illegal }; + + always @(posedge i_clk) + if (f_past_valid && !$past(i_reset) && !$past(clear_pipeline) + && ($past(op_valid && !adf_ce_unconditional && !mem_ce) + ||($past(!op_valid && !dcd_ljmp) && !op_valid))) + begin + assert($stable(op_state)); + end + + always @(posedge i_clk) + if (f_past_valid && !op_valid) + begin + assert(r_op_F == 7'h00); + assert(!op_wR); + assert(!op_wF); + assert(!op_rA); + assert(!op_rB); + + assert(r_op_Av == 0); + assert(r_op_Bv == 0); + end + + end endgenerate + + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Ad-hoc (unsorted) properties + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + always @(posedge i_clk) + if ((f_past_valid)&&(!$past(i_reset))&&($past(i_mem_rdbusy)) + &&(!$past(i_mem_valid) + ||($past(i_mem_wreg[3:1] != 3'h7)))) + `ASSERT(!i_mem_valid || i_mem_wreg[4] == alu_gie); + + always @(posedge i_clk) + if (i_mem_valid) + `ASSERT(i_mem_wreg[4] == alu_gie); + + always @(posedge i_clk) + if (i_mem_rdbusy) + `ASSERT(alu_gie == f_mem_gie); + + always @(posedge i_clk) + if (f_mem_outstanding > 0) + `ASSERT(alu_gie == f_mem_gie); + + + + // Break instructions are not allowed to move past the op stage + always @(*) + if ((break_pending)||(op_break)) + `ASSERT((!alu_ce)&&(!mem_ce)&&(!div_ce)&&(!fpu_ce)); + + always @(*) + if (op_break) + `ASSERT((!alu_ce)&&(!mem_ce)&&(!div_ce)&&(!fpu_ce)); + + always @(posedge i_clk) + if ((f_past_valid)&&(!$past(i_reset)) + &&($past(break_pending))&&(!break_pending)) + `ASSERT((clear_pipeline)||($past(clear_pipeline))); + + always @(*) + if ((o_break)||((alu_valid)&&(alu_illegal))) + begin + `ASSERT(!alu_ce); + `ASSERT(!mem_ce); + `ASSERT(!div_ce); + `ASSERT(!fpu_ce); + `ASSERT(!i_mem_rdbusy); + // The following two shouldn't be true, but will be true + // following a bus error + if (!i_bus_err) + begin + `ASSERT(!alu_busy); + `ASSERT(!div_busy); + `ASSERT(!fpu_busy); + end + end + + always @(posedge i_clk) + if ((f_past_valid)&&(!$past(i_reset))&&(!$past(clear_pipeline))&& + ($past(div_busy))&&(!clear_pipeline)) + begin + `ASSERT($stable(alu_reg)); + `ASSERT(alu_reg[4] == alu_gie); + `ASSERT($stable(alu_pc)); + `ASSERT($stable(alu_phase)); + end + + always @(posedge i_clk) + if ((f_past_valid)&&(!$past(i_reset))&&(!i_reset) + &&(!$past(clear_pipeline))&&(!clear_pipeline) + &&(($past(div_busy))||($past(i_mem_rdbusy)))) + `ASSERT($stable(alu_gie)); + + always @(posedge i_clk) + if (i_mem_rdbusy && f_mem_outstanding > 0) + `ASSERT(!new_pc); + + always @(posedge i_clk) + if ((wr_reg_ce)&&((wr_write_cc)||(wr_write_pc))) + `ASSERT(wr_spreg_vl == wr_gpreg_vl); + + always @(posedge i_clk) + if ((f_past_valid)&&(!$past(clear_pipeline))&&(!$past(i_reset)) + &&($past(op_valid))&&($past(op_illegal))&&(!op_illegal)) + `ASSERT(alu_illegal); + + always @(*) + if ((OPT_PIPELINED)&&(alu_valid)&&(alu_wR)&&(!clear_pipeline) + &&(alu_reg[3:1] == 3'h7) + &&(alu_reg[4:0] != { gie, CPU_PC_REG })) + `ASSERT(pending_sreg_write); + + always @(posedge i_clk) + if ((OPT_PIPELINED)&&(i_mem_valid || i_mem_rdbusy) + &&(f_last_reg[3:1] == 3'h7) + &&(f_last_reg[4:0] != { gie, CPU_PC_REG })) + begin + `ASSERT(pending_sreg_write); + end else if ((OPT_PIPELINED)&&(OPT_DCACHE) + && i_mem_valid + &&($past(i_mem_rdbusy)) + &&($past(i_mem_rdbusy,2))) + `ASSERT((i_mem_wreg[3:1] != 3'h7) + ||(i_mem_wreg == { gie, CPU_PC_REG}) + ||(pending_sreg_write)); + + always @(*) + if ((op_valid_alu)||(op_valid_div)||(op_valid_mem)||(op_valid_fpu)) + `ASSERT(op_valid); + + always @(*) + if (!OPT_PIPELINED) + begin + if (op_valid) + begin + `ASSERT(!dcd_valid); + `ASSERT(!i_mem_busy || f_mem_outstanding == 0); + `ASSERT(!alu_busy); + `ASSERT(!div_busy); + `ASSERT((!wr_reg_ce)||(dbgv)); + `ASSERT(!wr_flags_ce); + end + end + + always @(posedge i_clk) + if ((!OPT_PIPELINED)&&(f_past_valid)) + begin + if (op_valid) + `ASSERT($stable(f_dcd_insn_word)); + end + + always @(posedge i_clk) + if ((alu_ce)||(div_ce)||(fpu_ce)) + `ASSERT(adf_ce_unconditional); + + always @(posedge i_clk) + if ((!clear_pipeline)&&(master_ce)&&(op_ce)&&(op_valid)) + begin + if (op_valid_mem) + begin + `ASSERT((mem_ce)||(!set_cond)); + end else begin + `ASSERT(!master_stall); + if ((set_cond)&&(op_valid_div)) + `ASSERT(div_ce||pending_sreg_write); + if (!op_valid_alu) + `ASSERT(!alu_ce); + end + end + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Cover statements + // {{{ + //////////////////////////////////////////////////////////////////////// + // + always @(posedge i_clk) + if ((gie)&&(wr_reg_ce)) + begin + // Cover the switch to interrupt + cover((i_interrupt)&&(!alu_phase)&&(!o_bus_lock)); + + // Cover a "step" instruction + cover(((alu_pc_valid)||(mem_pc_valid)) + &&(step)&&(!alu_phase)&&(!o_bus_lock)); + + // Cover a break instruction + cover((master_ce)&&(break_pending)&&(!break_en)); + + // Cover an illegal instruction + cover((alu_illegal)&&(!clear_pipeline)); + + // Cover a division by zero + cover(div_error); + + // Cover a bus error + cover(i_bus_err); + + // Cover a TRAP instruction to the CC register + cover(((wr_reg_ce)&&(!wr_spreg_vl[CPU_GIE_BIT]) + &&(wr_reg_id[4])&&(wr_write_cc))); + end + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Careless assumptions + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + // Once asserted, an interrupt will stay asserted while the CPU is + // in user mode + always @(posedge i_clk) + if ((f_past_valid)&&($past(i_interrupt && gie))) + assume(i_interrupt); + // }}} +`endif // FORMAL +// }}} +endmodule diff --git a/rtl/cpu/zipcounter.v b/rtl/cpu/zipcounter.v index 5fa12b8..0e32280 100644 --- a/rtl/cpu/zipcounter.v +++ b/rtl/cpu/zipcounter.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: zipcounter.v -// +// {{{ // Project: Zip CPU -- a small, lightweight, RISC CPU soft core // // Purpose: @@ -26,9 +26,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -43,60 +43,79 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none -// -module zipcounter(i_clk, i_reset, i_event, - i_wb_cyc, i_wb_stb, i_wb_we, i_wb_data, - o_wb_stall, o_wb_ack, o_wb_data, - o_int); - parameter BW = 32; - input wire i_clk, i_reset, i_event; - // Wishbone inputs - input wire i_wb_cyc, i_wb_stb, i_wb_we; - input wire [(BW-1):0] i_wb_data; - // Wishbone outputs - output wire o_wb_stall; - output reg o_wb_ack; - output reg [(BW-1):0] o_wb_data; - // Interrupt line - output reg o_int; +// }}} +module zipcounter #( + // {{{ + parameter BW = 32 + // }}} + ) ( + // {{{ + input wire i_clk, i_reset, i_event, + // Wishbone inputs + input wire i_wb_cyc, i_wb_stb, i_wb_we, + input wire [(BW-1):0] i_wb_data, + // Wishbone outputs + output wire o_wb_stall, + output reg o_wb_ack, + output reg [(BW-1):0] o_wb_data, + // Interrupt line + output reg o_int + // }}} + ); + // o_int, o_wb_data + // {{{ initial o_int = 0; initial o_wb_data = 32'h00; always @(posedge i_clk) - if (i_reset) - { o_int, o_wb_data } <= 0; - else if ((i_wb_stb)&&(i_wb_we)) - { o_int, o_wb_data } <= { 1'b0, i_wb_data }; - else if (i_event) - { o_int, o_wb_data } <= o_wb_data+{{(BW-1){1'b0}},1'b1}; - else - o_int <= 1'b0; + if (i_reset) + { o_int, o_wb_data } <= 0; + else if ((i_wb_stb)&&(i_wb_we)) + { o_int, o_wb_data } <= { 1'b0, i_wb_data }; + else if (i_event) + { o_int, o_wb_data } <= o_wb_data+{{(BW-1){1'b0}},1'b1}; + else + o_int <= 1'b0; + // }}} + // o_wb_ack + // {{{ initial o_wb_ack = 1'b0; always @(posedge i_clk) if (i_reset) o_wb_ack <= 1'b0; else o_wb_ack <= i_wb_stb; + // }}} assign o_wb_stall = 1'b0; // Make verilator happy + // {{{ // verilator lint_off UNUSED wire unused; assign unused = i_wb_cyc; // verilator lint_on UNUSED - + // }}} +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal properties +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// `ifdef FORMAL // Formal properties for this module are maintained elsewhere `endif +// }}} endmodule diff --git a/rtl/cpu/zipcpu.v b/rtl/cpu/zipcpu.v deleted file mode 100644 index b470acd..0000000 --- a/rtl/cpu/zipcpu.v +++ /dev/null @@ -1,2749 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Filename: zipcpu.v -// -// Project: Zip CPU -- a small, lightweight, RISC CPU soft core -//{{{ -// Purpose: This is the top level module holding the core of the Zip CPU -// together. The Zip CPU is designed to be as simple as possible. -// (actual implementation aside ...) The instruction set is about as -// RISC as you can get, with only 26 instruction types currently supported. -// (There are still 8-instruction Op-Codes reserved for floating point, -// and 5 which can be used for transactions not requiring registers.) -// Please see the accompanying spec.pdf file for a description of these -// instructions. -// -// All instructions are 32-bits wide. All bus accesses, both address and -// data, are 32-bits over a wishbone bus. -// -// The Zip CPU is fully pipelined with the following pipeline stages: -// -// 1. Prefetch, returns the instruction from memory. -// -// 2. Instruction Decode -// -// 3. Read Operands -// -// 4. Apply Instruction -// -// 4. Write-back Results -// -// Further information about the inner workings of this CPU, such as -// what causes pipeline stalls, may be found in the spec.pdf file. (The -// documentation within this file had become out of date and out of sync -// with the spec.pdf, so look to the spec.pdf for accurate and up to date -// information.) -// -// -// In general, the pipelining is controlled by three pieces of logic -// per stage: _ce, _stall, and _valid. _valid means that the stage -// holds a valid instruction. _ce means that the instruction from the -// previous stage is to move into this one, and _stall means that the -// instruction from the previous stage may not move into this one. -// The difference between these control signals allows individual stages -// to propagate instructions independently. In general, the logic works -// as: -// -// -// assign (n)_ce = (n-1)_valid && (!(n)_stall) -// -// -// always @(posedge i_clk) -// if ((i_reset)||(clear_pipeline)) -// (n)_valid = 0 -// else if (n)_ce -// (n)_valid = 1 -// else if (n+1)_ce -// (n)_valid = 0 -// -// assign (n)_stall = ( (n-1)_valid && ( pipeline hazard detection ) ) -// || ( (n)_valid && (n+1)_stall ); -// -// and ... -// -// always @(posedge i_clk) -// if (n)_ce -// (n)_variable = ... whatever logic for this stage -// -// Note that a stage can stall even if no instruction is loaded into -// it. -// -//}}} -// Creator: Dan Gisselquist, Ph.D. -// Gisselquist Technology, LLC -// -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -//{{{ -// This program is free software (firmware): 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 MERCHANTIBILITY 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. (It's in the $(ROOT)/doc directory. Run make with no -// target there if the PDF file isn't present.) If not, see -// for a copy. -//}}} -// License: GPL, v3, as defined and found on www.gnu.org, -// http://www.gnu.org/licenses/gpl.html -// -// -//////////////////////////////////////////////////////////////////////////////// -// -// -`default_nettype none -// -`define CPU_SUB_OP 4'h0 // also a compare instruction -`define CPU_AND_OP 4'h1 // also a test instruction -`define CPU_BREV_OP 4'h8 -`define CPU_MOV_OP 4'hd -// -`define CPU_CC_REG 4'he -`define CPU_PC_REG 4'hf -`define CPU_CLRDCACHE_BIT 15 // Set to clear the D-cache,automatically clears -`define CPU_CLRICACHE_BIT 14 // Set to clear the I-cache,automatically clears -`define CPU_PHASE_BIT 13 // Set if we are executing the latter half of a CIS -`define CPU_FPUERR_BIT 12 // Floating point error flag, set on error -`define CPU_DIVERR_BIT 11 // Divide error flag, set on divide by zero -`define CPU_BUSERR_BIT 10 // Bus error flag, set on error -`define CPU_TRAP_BIT 9 // User TRAP has taken place -`define CPU_ILL_BIT 8 // Illegal instruction -`define CPU_BREAK_BIT 7 -`define CPU_STEP_BIT 6 // Will step one (or two CIS) instructions -`define CPU_GIE_BIT 5 -`define CPU_SLEEP_BIT 4 -// Compile time defines -// -`include "cpudefs.v" -// -// -module zipcpu(i_clk, i_reset, i_interrupt, - // Debug interface - i_halt, i_clear_pf_cache, i_dbg_reg, i_dbg_we, i_dbg_data, - o_dbg_stall, o_dbg_reg, o_dbg_cc, - o_break, - // CPU interface to the wishbone bus - o_wb_gbl_cyc, o_wb_gbl_stb, - o_wb_lcl_cyc, o_wb_lcl_stb, - o_wb_we, o_wb_addr, o_wb_data, o_wb_sel, - i_wb_stall, i_wb_ack, i_wb_data, - i_wb_err, - // Accounting/CPU usage interface - o_op_stall, o_pf_stall, o_i_count -`ifdef DEBUG_SCOPE - , o_debug // , o_dcache_debug -`endif - ); - // Parameters - //{{{ - parameter [31:0] RESET_ADDRESS=32'h010_0000; - parameter ADDRESS_WIDTH=30, - LGICACHE=12; -`ifdef OPT_MULTIPLY - parameter IMPLEMENT_MPY = `OPT_MULTIPLY; -`else - parameter IMPLEMENT_MPY = 0; -`endif -`ifdef OPT_DIVIDE - parameter [0:0] IMPLEMENT_DIVIDE = 1; -`else - parameter [0:0] IMPLEMENT_DIVIDE = 0; -`endif -`ifdef OPT_IMPLEMENT_FPU - parameter [0:0] IMPLEMENT_FPU = 1; -`else - parameter [0:0] IMPLEMENT_FPU = 0; -`endif -`ifdef OPT_EARLY_BRANCHING - parameter [0:0] EARLY_BRANCHING = 1; -`else - parameter [0:0] EARLY_BRANCHING = 0; -`endif -`ifdef OPT_CIS - parameter [0:0] OPT_CIS = 1'b1; -`else - parameter [0:0] OPT_CIS = 1'b0; -`endif -`ifdef OPT_NO_USERMODE - localparam [0:0] OPT_NO_USERMODE = 1'b1; -`else - localparam [0:0] OPT_NO_USERMODE = 1'b0; -`endif -`ifdef OPT_PIPELINED - parameter [0:0] OPT_PIPELINED = 1'b1; -`else - parameter [0:0] OPT_PIPELINED = 1'b0; -`endif -`ifdef OPT_PIPELINED_BUS_ACCESS - localparam [0:0] OPT_PIPELINED_BUS_ACCESS = (OPT_PIPELINED); -`else - localparam [0:0] OPT_PIPELINED_BUS_ACCESS = 1'b0; -`endif - localparam [0:0] OPT_MEMPIPE = OPT_PIPELINED_BUS_ACCESS; - parameter [0:0] IMPLEMENT_LOCK=1; - localparam [0:0] OPT_LOCK=(IMPLEMENT_LOCK)&&(OPT_PIPELINED); -`ifdef OPT_DCACHE - parameter OPT_LGDCACHE = 10; -`else - parameter OPT_LGDCACHE = 0; -`endif - localparam [0:0] OPT_DCACHE = (OPT_LGDCACHE > 0); - - parameter [0:0] WITH_LOCAL_BUS = 1'b1; - localparam AW=ADDRESS_WIDTH; - localparam [(AW-1):0] RESET_BUS_ADDRESS = RESET_ADDRESS[(AW+1):2]; - parameter F_LGDEPTH=8; - - //}}} - // I/O declarations - //{{{ - input wire i_clk, i_reset, i_interrupt; - // Debug interface -- inputs - input wire i_halt, i_clear_pf_cache; - input wire [4:0] i_dbg_reg; - input wire i_dbg_we; - input wire [31:0] i_dbg_data; - // Debug interface -- outputs - output wire o_dbg_stall; - output reg [31:0] o_dbg_reg; - output reg [3:0] o_dbg_cc; - output wire o_break; - // Wishbone interface -- outputs - output wire o_wb_gbl_cyc, o_wb_gbl_stb; - output wire o_wb_lcl_cyc, o_wb_lcl_stb, o_wb_we; - output wire [(AW-1):0] o_wb_addr; - output wire [31:0] o_wb_data; - output wire [3:0] o_wb_sel; - // Wishbone interface -- inputs - input wire i_wb_stall, i_wb_ack; - input wire [31:0] i_wb_data; - input wire i_wb_err; - // Accounting outputs ... to help us count stalls and usage - output wire o_op_stall; - output wire o_pf_stall; - output wire o_i_count; - // -`ifdef DEBUG_SCOPE - output reg [31:0] o_debug; - // output wire [31:0] o_dcache_debug; -`endif - //}}} - - - // Registers - // - // The distributed RAM style comment is necessary on the - // SPARTAN6 with XST to prevent XST from oversimplifying the register - // set and in the process ruining everything else. It basically - // optimizes logic away, to where it no longer works. The logic - // as described herein will work, this just makes sure XST implements - // that logic. - // - (* ram_style = "distributed" *) - reg [31:0] regset [0:(OPT_NO_USERMODE)? 15:31]; - - // Condition codes - // (BUS, TRAP,ILL,BREAKEN,STEP,GIE,SLEEP ), V, N, C, Z - reg [3:0] flags, iflags; - wire [15:0] w_uflags, w_iflags; - reg break_en, step, sleep, r_halted; - wire break_pending, trap, gie, ubreak, pending_interrupt; - wire w_clear_icache, w_clear_dcache, ill_err_u; - reg ill_err_i; - reg ibus_err_flag; - wire ubus_err_flag; - wire idiv_err_flag, udiv_err_flag; - wire ifpu_err_flag, ufpu_err_flag; - wire ihalt_phase, uhalt_phase; - - // The master chip enable - wire master_ce, master_stall; - - // - // - // PIPELINE STAGE #1 :: Prefetch - // Variable declarations - // - //{{{ - reg [(AW+1):0] pf_pc; - wire [(AW+1):0] pf_request_address, pf_instruction_pc; - reg new_pc; - wire clear_pipeline; - - reg dcd_stalled; - wire pf_cyc, pf_stb, pf_we, pf_stall, pf_ack, pf_err; - wire [(AW-1):0] pf_addr; - wire [31:0] pf_data; - wire [31:0] pf_instruction; - wire pf_valid, pf_gie, pf_illegal; - wire pf_stalled; - wire pf_new_pc; - - assign clear_pipeline = new_pc; - //}}} - - // - // - // PIPELINE STAGE #2 :: Instruction Decode - // Variable declarations - // - // - //{{{ - reg op_valid /* verilator public_flat */, - op_valid_mem, op_valid_alu; - reg op_valid_div, op_valid_fpu; - wire op_stall, dcd_ce, dcd_phase; - wire [3:0] dcd_opn; - wire [4:0] dcd_A, dcd_B, dcd_R, dcd_preA, dcd_preB; - wire dcd_Acc, dcd_Bcc, dcd_Apc, dcd_Bpc, dcd_Rcc, dcd_Rpc; - wire [3:0] dcd_F; - wire dcd_wR, dcd_rA, dcd_rB, - dcd_ALU, dcd_M, dcd_DIV, dcd_FP, - dcd_wF, dcd_gie, dcd_break, dcd_lock, - dcd_pipe, dcd_ljmp; - wire dcd_valid; - wire [AW+1:0] dcd_pc /* verilator public_flat */; - wire [31:0] dcd_I; - wire dcd_zI; // true if dcd_I == 0 - wire dcd_A_stall, dcd_B_stall, dcd_F_stall; - - wire dcd_illegal; - wire dcd_early_branch, dcd_early_branch_stb; - wire [(AW+1):0] dcd_branch_pc; - - wire dcd_sim; - wire [22:0] dcd_sim_immv; - wire prelock_stall; - wire cc_invalid_for_dcd; - wire pending_sreg_write; - //}}} - - - // - // - // PIPELINE STAGE #3 :: Read Operands - // Variable declarations - // - // - // - //{{{ - // Now, let's read our operands - reg [4:0] alu_reg; - wire [3:0] op_opn; - reg [4:0] op_R; - reg op_Rcc; - reg [4:0] op_Aid, op_Bid; - reg op_rA, op_rB; - reg [31:0] r_op_Av, r_op_Bv; - reg [(AW+1):0] op_pc; - wire [31:0] w_op_Av, w_op_Bv, op_Av, op_Bv; - reg [31:0] w_pcB_v, w_pcA_v; - reg [31:0] w_op_BnI; - reg op_wR, op_wF; - wire op_gie; - wire [3:0] op_Fl; - reg [6:0] r_op_F; - wire [7:0] op_F; - wire op_ce, op_phase, op_pipe; - reg r_op_break; - reg [3:0] r_op_opn; - wire w_op_valid; - wire [8:0] w_cpu_info; - // Some pipeline control wires - reg op_illegal; - wire op_break; - wire op_lock; - -`ifdef VERILATOR - reg op_sim /* verilator public_flat */; - reg [22:0] op_sim_immv /* verilator public_flat */; - reg alu_sim /* verilator public_flat */; - reg [22:0] alu_sim_immv /* verilator public_flat */; -`else - wire op_sim = 1'b0; -`endif - //}}} - - - // - // - // PIPELINE STAGE #4 :: ALU / Memory - // Variable declarations - // - // - //{{{ - wire [(AW+1):0] alu_pc; - reg r_alu_pc_valid, mem_pc_valid; - wire alu_pc_valid; - wire alu_phase; - wire alu_ce /* verilator public_flat */, alu_stall; - wire [31:0] alu_result; - wire [3:0] alu_flags; - wire alu_valid, alu_busy; - wire set_cond; - reg alu_wR, alu_wF; - wire alu_gie, alu_illegal; - - - wire mem_ce, mem_stalled; - wire mem_pipe_stalled; - wire mem_valid, mem_stall, mem_ack, mem_err, bus_err, - mem_cyc_gbl, mem_cyc_lcl, mem_stb_gbl, mem_stb_lcl, mem_we; - wire [4:0] mem_wreg; - - wire mem_busy, mem_rdbusy; - wire [(AW-1):0] mem_addr; - wire [31:0] mem_data, mem_result; - wire [3:0] mem_sel; - - wire div_ce, div_error, div_busy, div_valid; - wire [31:0] div_result; - wire [3:0] div_flags; - - wire fpu_ce, fpu_error, fpu_busy, fpu_valid; - wire [31:0] fpu_result; - wire [3:0] fpu_flags; - reg adf_ce_unconditional; - - wire bus_lock; - - reg dbgv, dbg_clear_pipe; - reg [31:0] dbg_val; - - assign div_ce = (op_valid_div)&&(adf_ce_unconditional)&&(set_cond); - assign fpu_ce = (IMPLEMENT_FPU)&&(op_valid_fpu)&&(adf_ce_unconditional)&&(set_cond); - - //}}} - - // - // - // PIPELINE STAGE #5 :: Write-back - // Variable declarations - // - //{{{ - wire wr_discard, wr_write_pc, wr_write_cc, - wr_write_scc, wr_write_ucc; - reg wr_reg_ce, wr_flags_ce; - reg [3:0] wr_flags; - reg [2:0] wr_index; - wire [4:0] wr_reg_id; - reg [31:0] wr_gpreg_vl, wr_spreg_vl; - wire w_switch_to_interrupt, w_release_from_interrupt; - reg [(AW+1):0] ipc; - wire [(AW+1):0] upc; - reg last_write_to_cc; - wire cc_write_hold; - reg r_clear_icache, r_clear_dcache; - //}}} - - - - // - // MASTER: clock enable. - // - assign master_ce = ((!i_halt)||(alu_phase)) - &&(!cc_write_hold)&&(!o_break)&&(!sleep); - - - // - // PIPELINE STAGE #1 :: Prefetch - // Calculate stall conditions - // - // These are calculated externally, within the prefetch module. - // - - // - // PIPELINE STAGE #2 :: Instruction Decode - // Calculate stall conditions - - always @(*) - if (OPT_PIPELINED) - dcd_stalled = (dcd_valid)&&(op_stall); - else - dcd_stalled = (!master_ce)||(ill_err_i)||(dcd_valid)||(op_valid) - ||(ibus_err_flag)||(idiv_err_flag) - ||(alu_busy)||(div_busy)||(fpu_busy)||(mem_busy); - // - // PIPELINE STAGE #3 :: Read Operands - // Calculate stall conditions - //{{{ - generate if (OPT_PIPELINED) - begin : GEN_OP_STALL - reg r_cc_invalid_for_dcd; - always @(posedge i_clk) - r_cc_invalid_for_dcd <= - (set_cond)&&(op_valid) - &&((op_wF)||((op_wR)&&(op_R[4:0] == { op_gie, `CPU_CC_REG }))) - ||((r_cc_invalid_for_dcd) - &&((alu_busy)||(mem_rdbusy)||(div_busy)||(fpu_busy))); - - assign cc_invalid_for_dcd = r_cc_invalid_for_dcd; - - reg r_pending_sreg_write; - initial r_pending_sreg_write = 1'b0; - always @(posedge i_clk) - if (clear_pipeline) - r_pending_sreg_write <= 1'b0; - else if (((adf_ce_unconditional)||(mem_ce)) - &&(set_cond)&&(!op_illegal) - &&(op_wR) - &&(op_R[3:1] == 3'h7) - &&(op_R[4:0] != { gie, 4'hf })) - r_pending_sreg_write <= 1'b1; - else if ((!mem_rdbusy)&&(!alu_busy)) - r_pending_sreg_write <= 1'b0; - - assign pending_sreg_write = r_pending_sreg_write; - - assign op_stall = (op_valid)&&( - //{{{ - // Only stall if we're loaded w/validins and the - // next stage is accepting our instruction - (!adf_ce_unconditional)&&(!mem_ce) - ) - ||(dcd_valid)&&( - // Stall if we need to wait for an operand A - // to be ready to read - (dcd_A_stall) - // Likewise for B, also includes logic - // regarding immediate offset (register must - // be in register file if we need to add to - // an immediate) - ||(dcd_B_stall) - // Or if we need to wait on flags to work on the - // CC register - ||(dcd_F_stall) - ); - //}}} - assign op_ce = ((dcd_valid)||(dcd_illegal)||(dcd_early_branch))&&(!op_stall); - - end else begin // !OPT_PIPELINED - - assign op_stall = 1'b0; // (o_break)||(pending_interrupt); - assign op_ce = ((dcd_valid)||(dcd_early_branch))&&(!op_stall); - assign pending_sreg_write = 1'b0; - assign cc_invalid_for_dcd = 1'b0; - - // Verilator lint_off UNUSED - wire [1:0] pipe_unused; - assign pipe_unused = { cc_invalid_for_dcd, - pending_sreg_write }; - // Verilator lint_on UNUSED - end endgenerate - - // BUT ... op_ce is too complex for many of the data operations. So - // let's make their circuit enable code simpler. In particular, if - // op_ doesn't need to be preserved, we can change it all we want - // ... right? The clear_pipeline code, for example, really only needs - // to determine whether op_valid is true. - // assign op_change_data_ce = (!op_stall); - //}}} - - // - // PIPELINE STAGE #4 :: ALU / Memory - // Calculate stall conditions - // - //{{{ - // 1. Basic stall is if the previous stage is valid and the next is - // busy. - // 2. Also stall if the prior stage is valid and the master clock enable - // is de-selected - // 3. Stall if someone on the other end is writing the CC register, - // since we don't know if it'll put us to sleep or not. - // 4. Last case: Stall if we would otherwise move a break instruction - // through the ALU. Break instructions are not allowed through - // the ALU. - generate if (OPT_PIPELINED) - begin : GEN_ALU_STALL - assign alu_stall = (((master_stall)||(mem_rdbusy))&&(op_valid_alu)) //Case 1&2 - ||(wr_reg_ce)&&(wr_write_cc); - // assign // alu_ce = (master_ce)&&(op_valid_alu)&&(!alu_stall) - // &&(!clear_pipeline)&&(!op_illegal) - // &&(!pending_sreg_write) - // &&(!alu_sreg_stall); - assign alu_ce = (adf_ce_unconditional)&&(op_valid_alu); - - // Verilator lint_off unused - wire unused_alu_stall = alu_stall; - // Verilator lint_on unused - end else begin - - assign alu_stall = (master_stall); - //assign alu_ce = (master_ce)&&(op_valid_alu) - // &&(!clear_pipeline) - // &&(!alu_stall); - assign alu_ce = (adf_ce_unconditional)&&(op_valid_alu); - - // Verilator lint_off unused - wire unused_alu_stall = alu_stall; - // Verilator lint_on unused - end endgenerate - // - - // - // Note: if you change the conditions for mem_ce, you must also change - // alu_pc_valid. - // - assign mem_ce = (master_ce)&&(op_valid_mem)&&(!mem_stalled) - &&(!clear_pipeline); - - generate if (OPT_PIPELINED_BUS_ACCESS) - begin - - assign mem_stalled = (master_stall)||((op_valid_mem)&&( - (mem_pipe_stalled) - ||(bus_err)||(div_error) - ||((!op_pipe)&&(mem_busy)) - // Stall waiting for flags to be valid - // Or waiting for a write to the PC register - // Or CC register, since that can change the - // PC as well - ||((wr_reg_ce) - &&((wr_write_pc)||(wr_write_cc))))); - end else if (OPT_PIPELINED) - begin - assign mem_stalled = (master_stall)||((op_valid_mem)&&( - (bus_err)||(div_error)||(mem_busy) - // Stall waiting for flags to be valid - // Or waiting for a write to the PC register - // Or CC register, since that can change the - // PC as well - ||((wr_reg_ce) - &&((wr_write_pc)||(wr_write_cc))))); - end else begin - - assign mem_stalled = (master_stall); - - end endgenerate - //}}} - - assign master_stall = (!master_ce)||(!op_valid)||(ill_err_i) - ||(ibus_err_flag)||(idiv_err_flag) - ||(pending_interrupt)&&(!alu_phase) - ||(alu_busy)||(div_busy)||(fpu_busy)||(op_break) - ||((OPT_PIPELINED)&&( - ((OPT_LOCK)&&(prelock_stall)) - ||((mem_busy)&&(op_illegal)) - ||((mem_busy)&&(op_valid_div)) - ||(alu_illegal)||(o_break))); - - - // ALU, DIV, or FPU CE ... equivalent to the OR of all three of these - always @(*) - if (OPT_PIPELINED) - adf_ce_unconditional = - (!master_stall)&&(!op_valid_mem)&&(!mem_rdbusy) - &&((!mem_busy)||(!op_wR)||(op_R[4:1] != { gie, 3'h7})); - else - adf_ce_unconditional = (!master_stall)&&(op_valid)&&(!op_valid_mem); - - // - // - // PIPELINE STAGE #1 :: Prefetch - // - // - //{{{ - assign pf_stalled = (dcd_stalled)||(dcd_phase); - - assign pf_new_pc = (new_pc)||((dcd_early_branch_stb)&&(!clear_pipeline)); - - assign pf_request_address = ((dcd_early_branch_stb)&&(!clear_pipeline)) - ? dcd_branch_pc:pf_pc; - assign pf_gie = gie; -`ifdef OPT_SINGLE_FETCH - prefetch #(ADDRESS_WIDTH) - //{{{ - pf(i_clk, (i_reset), pf_new_pc, w_clear_icache, - (!pf_stalled), - pf_request_address, - pf_instruction, pf_instruction_pc, - pf_valid, pf_illegal, - pf_cyc, pf_stb, pf_we, pf_addr, pf_data, - pf_stall, pf_ack, pf_err, i_wb_data); - //}}} -`else -`ifdef OPT_DOUBLE_FETCH - - dblfetch #(ADDRESS_WIDTH) - //{{{ - pf(i_clk, i_reset, pf_new_pc, w_clear_icache, - (!pf_stalled), - pf_request_address, - pf_instruction, pf_instruction_pc, - pf_valid, - pf_cyc, pf_stb, pf_we, pf_addr, pf_data, - pf_stall, pf_ack, pf_err, i_wb_data, - pf_illegal); - //}}} - -`else // Not single fetch and not double fetch - -`ifdef OPT_TRADITIONAL_PFCACHE - pfcache #(LGICACHE, ADDRESS_WIDTH) - //{{{ - pf(i_clk, i_reset, pf_new_pc, w_clear_icache, - // dcd_pc, - (!pf_stalled), - pf_request_address, - pf_instruction, pf_instruction_pc, pf_valid, - pf_cyc, pf_stb, pf_we, pf_addr, pf_data, - pf_stall, pf_ack, pf_err, i_wb_data, - pf_illegal); - //}}} -`else - pipefetch #({RESET_BUS_ADDRESS, 2'b00}, LGICACHE, ADDRESS_WIDTH) - //{{{ - pf(i_clk, i_reset, pf_new_pc, - w_clear_icache, (!pf_stalled), - (new_pc)?pf_pc:dcd_branch_pc, - pf_instruction, pf_instruction_pc, pf_valid, - pf_cyc, pf_stb, pf_we, pf_addr, pf_data, - pf_stall, pf_ack, pf_err, i_wb_data, - (mem_cyc_lcl)||(mem_cyc_gbl), - pf_illegal); - //}}} -`endif // OPT_TRADITIONAL_CACHE -`endif // OPT_DOUBLE_FETCH -`endif // OPT_SINGLE_FETCH - //}}} - - // - // - // PIPELINE STAGE #2 :: Instruction Decode - // - // - //{{{ - assign dcd_ce =((OPT_PIPELINED)&&(!dcd_valid))||(!dcd_stalled); - idecode #(.ADDRESS_WIDTH(AW), - .OPT_MPY((IMPLEMENT_MPY!=0)? 1'b1:1'b0), - .OPT_PIPELINED(OPT_PIPELINED), - .OPT_EARLY_BRANCHING(EARLY_BRANCHING), - .OPT_DIVIDE(IMPLEMENT_DIVIDE), - .OPT_FPU(IMPLEMENT_FPU), - .OPT_LOCK(OPT_LOCK), - .OPT_OPIPE(OPT_PIPELINED_BUS_ACCESS), - .OPT_NO_USERMODE(OPT_NO_USERMODE), -`ifdef VERILATOR - .OPT_SIM(1'b1), -`else - .OPT_SIM(1'b0), -`endif - .OPT_CIS(OPT_CIS)) - instruction_decoder(i_clk, - (i_reset)||(clear_pipeline)||(w_clear_icache), - dcd_ce, - dcd_stalled, pf_instruction, pf_gie, - pf_instruction_pc, pf_valid, pf_illegal, - dcd_valid, dcd_phase, - dcd_illegal, dcd_pc, - { dcd_Rcc, dcd_Rpc, dcd_R }, - { dcd_Acc, dcd_Apc, dcd_A }, - { dcd_Bcc, dcd_Bpc, dcd_B }, - dcd_preA, dcd_preB, - dcd_I, dcd_zI, dcd_F, dcd_wF, dcd_opn, - dcd_ALU, dcd_M, dcd_DIV, dcd_FP, dcd_break, dcd_lock, - dcd_wR,dcd_rA, dcd_rB, - dcd_early_branch, dcd_early_branch_stb, - dcd_branch_pc, dcd_ljmp, - dcd_pipe, - dcd_sim, dcd_sim_immv - ); - assign dcd_gie = pf_gie; - //}}} - - // - // - // PIPELINE STAGE #3 :: Read Operands (Registers) - // - // - //{{{ - generate if (OPT_PIPELINED_BUS_ACCESS) - begin : GEN_OP_PIPE - reg r_op_pipe; - - initial r_op_pipe = 1'b0; - // To be a pipeable operation, there must be - // two valid adjacent instructions - // Both must be memory instructions - // Both must be writes, or both must be reads - // Both operations must be to the same identical address, - // or at least a single (one) increment above that - // address - // - // However ... we need to know this before this clock, hence - // this is calculated in the instruction decoder. - always @(posedge i_clk) - if ((clear_pipeline)||(i_halt)) - r_op_pipe <= 1'b0; - else if (op_ce) - r_op_pipe <= (dcd_pipe)&&(op_valid_mem); - else if ((wr_reg_ce)&&(wr_reg_id == op_Bid[4:0])) - r_op_pipe <= 1'b0; - else if (mem_ce) // Clear us any time an op_ is clocked in - r_op_pipe <= 1'b0; - - assign op_pipe = r_op_pipe; - end else begin - - assign op_pipe = 1'b0; - - end endgenerate - -// `define NO_DISTRIBUTED_RAM -`ifdef NO_DISTRIBUTED_RAM - reg [31:0] pre_rewrite_value, pre_op_Av, pre_op_Bv; - reg pre_rewrite_flag_A, pre_rewrite_flag_B; - - always @(posedge i_clk) - if (dcd_ce) - begin - pre_rewrite_flag_A <= (wr_reg_ce)&&(dcd_preA == wr_reg_id); - pre_rewrite_flag_B <= (wr_reg_ce)&&(dcd_preB == wr_reg_id); - pre_rewrite_value <= wr_gpreg_vl; - end - - generate if (OPT_NO_USERMODE) - begin - always @(posedge i_clk) - if (dcd_ce) - begin - pre_op_Av <= regset[dcd_preA[3:0]]; - pre_op_Bv <= regset[dcd_preB[3:0]]; - end - end else begin - - always @(posedge i_clk) - if (dcd_ce) - begin - pre_op_Av <= regset[dcd_preA]; - pre_op_Bv <= regset[dcd_preB]; - end - - end endgenerate - - assign w_op_Av = (pre_rewrite_flag_A) ? pre_rewrite_value : pre_op_Av; - assign w_op_Bv = (pre_rewrite_flag_B) ? pre_rewrite_value : pre_op_Bv; -`else - generate if (OPT_NO_USERMODE) - begin - assign w_op_Av = regset[dcd_A[3:0]]; - assign w_op_Bv = regset[dcd_B[3:0]]; - end else begin - - assign w_op_Av = regset[dcd_A]; - assign w_op_Bv = regset[dcd_B]; - - end endgenerate - - // verilator lint_off UNUSED - wire [9:0] unused_prereg_addrs; - assign unused_prereg_addrs = { dcd_preA, dcd_preB }; - // verilator lint_on UNUSED -`endif - - assign w_cpu_info = { - //{{{ - 1'b1, - (IMPLEMENT_MPY >0)? 1'b1:1'b0, - (IMPLEMENT_DIVIDE >0)? 1'b1:1'b0, - (IMPLEMENT_FPU >0)? 1'b1:1'b0, - OPT_PIPELINED, -`ifdef OPT_TRADITIONAL_CACHE - 1'b1, -`else - 1'b0, -`endif - (EARLY_BRANCHING > 0)? 1'b1:1'b0, - OPT_PIPELINED_BUS_ACCESS, - OPT_CIS - }; - //}}} - - always @(*) - begin - w_pcA_v = 0; - if ((OPT_NO_USERMODE)||(dcd_A[4] == dcd_gie)) - w_pcA_v[(AW+1):0] = { dcd_pc[AW+1:2], 2'b00 }; - else - w_pcA_v[(AW+1):0] = { upc[(AW+1):2], uhalt_phase, 1'b0 }; - end - - generate if (OPT_PIPELINED) - begin : OPV - initial op_R = 0; - initial op_Aid = 0; - initial op_Bid = 0; - initial op_rA = 0; - initial op_rB = 0; - initial op_Rcc = 0; - always @(posedge i_clk) - if (op_ce) - begin - op_R <= dcd_R; - op_Aid <= dcd_A; - op_Bid <= dcd_B; - op_rA <= (dcd_rA)&&(!dcd_early_branch)&&(!dcd_illegal); - op_rB <= (dcd_rB)&&(!dcd_early_branch)&&(!dcd_illegal); - op_Rcc <= (dcd_Rcc)&&(dcd_wR)&&(dcd_R[4]==dcd_gie); - end - - end else begin - - always @(*) - begin - op_R = dcd_R; - op_Aid = dcd_A; - op_Bid = dcd_B; - op_rA = dcd_rA; - op_rB = dcd_rB; - op_Rcc = (dcd_Rcc)&&(dcd_wR)&&(dcd_R[4]==dcd_gie); - end - - end endgenerate - - reg [2:0] avsrc; - always @(*) - begin - avsrc = 3'b000; - if (!OPT_PIPELINED || op_ce) - begin - if (dcd_Apc) - avsrc = 3'b101; - else if (dcd_Acc) - avsrc = 3'b110; - else - avsrc = 3'b111; - end - - if (OPT_PIPELINED && wr_reg_ce) - begin - if (!op_ce && wr_reg_id == op_Aid && op_rA) - avsrc = 3'b100; - else if (op_ce && wr_reg_id == dcd_A) - avsrc = 3'b100; - end - end - -// 44313 - always @(posedge i_clk) - if (avsrc[2]) - case(avsrc[1:0]) - 2'b00: r_op_Av <= wr_gpreg_vl; - 2'b01: r_op_Av <= w_pcA_v; - 2'b10: r_op_Av <= { w_cpu_info, w_op_Av[22:16], (dcd_A[4])?w_uflags:w_iflags }; - 2'b11: r_op_Av <= w_op_Av; - endcase - - always @(*) - begin - w_pcB_v = 0; - if ((OPT_NO_USERMODE)||(dcd_B[4] == dcd_gie)) - w_pcB_v[(AW+1):0] = { dcd_pc[AW+1:2], 2'b00 }; - else - w_pcB_v[(AW+1):0] = { upc[(AW+1):2], uhalt_phase, 1'b0 }; - end - - reg [2:0] bvsrc; - reg [1:0] bisrc; - always @(*) - if (!dcd_rB) - bisrc = 0; - else if ((OPT_PIPELINED)&&(wr_reg_ce)&&(wr_reg_id == dcd_B)) - bisrc = 1; - else if (dcd_Bcc) - bisrc = 2; - else - bisrc = 3; - - always @(*) - case(bisrc[1:0]) - 2'b00: w_op_BnI = 0; - 2'b01: w_op_BnI = wr_gpreg_vl; - 2'b10: w_op_BnI = { w_cpu_info, w_op_Bv[22:16], - (dcd_B[4]) ? w_uflags : w_iflags }; - 2'b11: w_op_BnI = w_op_Bv; - endcase - - always @(*) - begin - bvsrc = 0; - if ((!OPT_PIPELINED)||(op_ce)) - begin - if ((dcd_Bpc)&&(dcd_rB)) - bvsrc = 3'b100; - else - bvsrc = 3'b101; - end else if ((OPT_PIPELINED)&&(op_rB) - &&(wr_reg_ce)&&(op_Bid == wr_reg_id)) - bvsrc = 3'b110; - end - - always @(posedge i_clk) - if (bvsrc[2]) casez(bvsrc[1:0]) - 2'b00: r_op_Bv <= w_pcB_v + { dcd_I[29:0], 2'b00 }; - 2'b01: r_op_Bv <= w_op_BnI + dcd_I; - 2'b1?: r_op_Bv <= wr_gpreg_vl; - endcase - - // The logic here has become more complex than it should be, no thanks - // to Xilinx's Vivado trying to help. The conditions are supposed to - // be two sets of four bits: the top bits specify what bits matter, the - // bottom specify what those top bits must equal. However, two of - // conditions check whether bits are on, and those are the only two - // conditions checking those bits. Therefore, Vivado complains that - // these two bits are redundant. Hence the convoluted expression - // below, arriving at what we finally want in the (now wire net) - // op_F. - always @(posedge i_clk) - if ((!OPT_PIPELINED)||(op_ce)) - // Cannot do op_change_data_ce here since op_F depends - // upon being either correct for a valid op, or correct - // for the last valid op - begin // Set the flag condition codes, bit order is [3:0]=VNCZ - case(dcd_F[2:0]) - 3'h0: r_op_F <= 7'h00; // Always - 3'h1: r_op_F <= 7'h11; // Z - 3'h2: r_op_F <= 7'h44; // LT - 3'h3: r_op_F <= 7'h22; // C - 3'h4: r_op_F <= 7'h08; // V - 3'h5: r_op_F <= 7'h10; // NE - 3'h6: r_op_F <= 7'h40; // GE (!N) - 3'h7: r_op_F <= 7'h20; // NC - endcase - end // Bit order is { (flags_not_used), VNCZ mask, VNCZ value } - assign op_F = { r_op_F[3], r_op_F[6:0] }; - - assign w_op_valid = (!clear_pipeline)&&(dcd_valid) - &&(!dcd_ljmp)&&(!dcd_early_branch); - - initial op_valid = 1'b0; - initial op_valid_alu = 1'b0; - initial op_valid_mem = 1'b0; - initial op_valid_div = 1'b0; - initial op_valid_fpu = 1'b0; - always @(posedge i_clk) - if ((i_reset)||(clear_pipeline)) - begin - op_valid <= 1'b0; - op_valid_alu <= 1'b0; - op_valid_mem <= 1'b0; - op_valid_div <= 1'b0; - op_valid_fpu <= 1'b0; - end else if (op_ce) - begin - // Do we have a valid instruction? - // The decoder may vote to stall one of its - // instructions based upon something we currently - // have in our queue. This instruction must then - // move forward, and get a stall cycle inserted. - // Hence, the test on dcd_stalled here. If we must - // wait until our operands are valid, then we aren't - // valid yet until then. - if (OPT_PIPELINED || !op_valid) - begin - op_valid <= (w_op_valid)||(dcd_early_branch); - op_valid_alu <= (w_op_valid)&&((dcd_ALU)||(dcd_illegal)); - op_valid_mem <= (dcd_M)&&(!dcd_illegal) - &&(w_op_valid); - op_valid_div <= (IMPLEMENT_DIVIDE)&&(dcd_DIV)&&(!dcd_illegal)&&(w_op_valid); - op_valid_fpu <= (IMPLEMENT_FPU)&&(dcd_FP)&&(!dcd_illegal)&&(w_op_valid); - end else if ((adf_ce_unconditional)||(mem_ce)) - begin - op_valid <= 1'b0; - op_valid_alu <= 1'b0; - op_valid_mem <= 1'b0; - op_valid_div <= 1'b0; - op_valid_fpu <= 1'b0; - end - end else if ((adf_ce_unconditional)||(mem_ce)) - begin - op_valid <= 1'b0; - op_valid_alu <= 1'b0; - op_valid_mem <= 1'b0; - op_valid_div <= 1'b0; - op_valid_fpu <= 1'b0; - end - - // Here's part of our debug interface. When we recognize a break - // instruction, we set the op_break flag. That'll prevent this - // instruction from entering the ALU, and cause an interrupt before - // this instruction. Thus, returning to this code will cause the - // break to repeat and continue upon return. To get out of this - // condition, replace the break instruction with what it is supposed - // to be, step through it, and then replace it back. In this fashion, - // a debugger can step through code. - // assign w_op_break = (dcd_break)&&(r_dcd_I[15:0] == 16'h0001); - - initial r_op_break = 1'b0; - always @(posedge i_clk) - if (clear_pipeline) - r_op_break <= 1'b0; - else if ((OPT_PIPELINED)&&(op_ce)) - r_op_break <= (dcd_valid)&&(dcd_break)&&(!dcd_illegal); - else if ((!OPT_PIPELINED)&&(dcd_valid)) - r_op_break <= (dcd_break)&&(!dcd_illegal); - assign op_break = r_op_break; - - generate if ((!OPT_PIPELINED)||(!OPT_LOCK)) - begin - - assign op_lock = 1'b0; - - // Verilator lint_off UNUSED - wire dcd_lock_unused; - assign dcd_lock_unused = dcd_lock; - // Verilator lint_on UNUSED - - end else // if (IMPLEMENT_LOCK != 0) - begin : OPLOCK - reg r_op_lock; - - initial r_op_lock = 1'b0; - always @(posedge i_clk) - if (clear_pipeline) - r_op_lock <= 1'b0; - else if (op_ce) - r_op_lock <= (dcd_valid)&&(dcd_lock) - &&(!dcd_illegal); - assign op_lock = r_op_lock; - - end endgenerate - - initial op_illegal = 1'b0; - always @(posedge i_clk) - if ((i_reset)||(clear_pipeline)) - op_illegal <= 1'b0; - else if (OPT_PIPELINED) - begin - if (op_ce) - op_illegal <= (dcd_valid)&&(!dcd_ljmp) - &&(!dcd_early_branch)&&(dcd_illegal); - end else if (!OPT_PIPELINED) - begin - if (dcd_valid) - op_illegal <= (!dcd_ljmp)&&(!dcd_early_branch)&&(dcd_illegal); - end - - always @(posedge i_clk) - if ((!OPT_PIPELINED)||(op_ce)) - op_wF <= (dcd_wF)&&((!dcd_Rcc)||(!dcd_wR)) - &&(!dcd_early_branch); - - generate if ((OPT_PIPELINED)||(EARLY_BRANCHING)) - begin - - always @(posedge i_clk) - if (op_ce) - op_wR <= (dcd_wR)&&(!dcd_early_branch); - - end else begin - - always @(*) - op_wR = (dcd_wR); - - end endgenerate - -`ifdef VERILATOR -`ifdef SINGLE_FETCH - always @(*) - begin - op_sim = dcd_sim; - op_sim_immv = dcd_sim_immv; - - alu_sim = op_sim; - alu_sim_immv = op_sim_immv; - end -`else - always @(posedge i_clk) - if (op_ce) - begin - op_sim <= dcd_sim; - op_sim_immv <= dcd_sim_immv; - end else if (adf_ce_unconditional) - op_sim <= 1'b0; - - // - // We need an extra ALU sim stage. - // - // It's not quite true that all instructions leaving the OP stage - // are committed. ALU instructions aren't committed until the next - // cycle. That way they don't need to wait to determine if a branch - // was taken or not. - always @(posedge i_clk) - begin - if (adf_ce_unconditional) - alu_sim <= op_sim && op_valid_alu; - else - alu_sim <= 1'b0; - - if (adf_ce_unconditional) - alu_sim_immv <= op_sim_immv; - - if (i_reset || clear_pipeline) - alu_sim <= 1'b0; - end -`endif -`endif - - - generate if ((OPT_PIPELINED)||(EARLY_BRANCHING)) - begin : SET_OP_PC - - initial op_pc[0] = 1'b0; - always @(posedge i_clk) - if (op_ce) - op_pc <= (dcd_early_branch)?dcd_branch_pc:dcd_pc; - - end else begin : SET_OP_PC - - always @(*) - op_pc = dcd_pc; - - end endgenerate - - generate if (!OPT_PIPELINED) - begin - always @(*) - r_op_opn = dcd_opn; - - end else begin - - always @(posedge i_clk) - if (op_ce) - begin - // Which ALU operation? Early branches are - // unimplemented moves - r_op_opn <= ((dcd_early_branch)||(dcd_illegal)) - ? `CPU_MOV_OP : dcd_opn; - // opM <= dcd_M; // Is this a memory operation? - // What register will these results be written into? - end - - end endgenerate - - assign op_opn = r_op_opn; - assign op_gie = gie; - - assign op_Fl = (op_gie)?(w_uflags[3:0]):(w_iflags[3:0]); - - generate if (OPT_CIS) - begin : OPT_CIS_OP_PHASE - - reg r_op_phase; - - initial r_op_phase = 1'b0; - always @(posedge i_clk) - if ((i_reset)||(clear_pipeline)) - r_op_phase <= 1'b0; - else if (op_ce) - r_op_phase <= (dcd_phase)&&((!dcd_wR)||(!dcd_Rpc)); - assign op_phase = r_op_phase; - end else begin : OPT_NOCIS_OP_PHASE - assign op_phase = 1'b0; - - // verilator lint_off UNUSED - wire OPT_CIS_dcdRpc; - assign OPT_CIS_dcdRpc = dcd_Rpc; - // verilator lint_on UNUSED - end endgenerate - - // This is tricky. First, the PC and Flags registers aren't kept in - // register set but in special registers of their own. So step one - // is to select the right register. Step to is to replace that - // register with the results of an ALU or memory operation, if such - // results are now available. Otherwise, we'd need to insert a wait - // state of some type. - // - // The alternative approach would be to define some sort of - // op_stall wire, which would stall any upstream stage. - // We'll create a flag here to start our coordination. Once we - // define this flag to something other than just plain zero, then - // the stalls will already be in place. - generate if (OPT_PIPELINED) - begin - - assign op_Av = ((wr_reg_ce)&&(wr_reg_id == op_Aid)) - ? wr_gpreg_vl : r_op_Av; - - end else begin - - assign op_Av = r_op_Av; - - end endgenerate - - // Stall if we have decoded an instruction that will read register A - // AND ... something that may write a register is running - // AND (series of conditions here ...) - // The operation might set flags, and we wish to read the - // CC register - // OR ... (No other conditions) - generate if (OPT_PIPELINED) - begin - - assign dcd_A_stall = (dcd_rA) // &&(dcd_valid) is checked for elsewhere - &&((op_valid)||(mem_rdbusy) - ||(div_busy)||(fpu_busy)) - &&(((op_wF)||(cc_invalid_for_dcd))&&(dcd_Acc)) - ||((dcd_rA)&&(dcd_Acc)&&(cc_invalid_for_dcd)); - end else begin - - // There are no pipeline hazards, if we aren't pipelined - assign dcd_A_stall = 1'b0; - - end endgenerate - - assign op_Bv = ((OPT_PIPELINED)&&(wr_reg_ce) - &&(wr_reg_id == op_Bid)&&(op_rB)) - ? wr_gpreg_vl: r_op_Bv; - - generate if (OPT_PIPELINED) - begin - // Stall if we have decoded an instruction that will read register B - // AND ... something that may write a (unknown) register is running - // AND (series of conditions here ...) - // The operation might set flags, and we wish to read the - // CC register - // OR the operation might set register B, and we still need - // a clock to add the offset to it - assign dcd_B_stall = (dcd_rB) // &&(dcd_valid) is checked for elsewhere - //{{{ - // If the op stage isn't valid, yet something - // is running, then it must have been valid. - // We'll use the last values from that stage - // (op_wR, op_wF, op_R) in our logic below. - &&((op_valid)||(mem_rdbusy) - ||(div_busy)||(fpu_busy)||(alu_busy)) - &&( - // Okay, what happens if the result register - // from instruction 1 becomes the input for - // instruction two, *and* there's an immediate - // offset in instruction two? In that case, we - // need an extra clock between the two - // instructions to calculate the base plus - // offset. - // - // What if instruction 1 (or before) is in a - // memory pipeline? We may no longer know what - // the register was! We will then need to - // blindly wait. We'll temper this only waiting - // if we're not piping this new instruction. - // If we were piping, the pipe logic in the - // decode circuit has told us that the hazard - // is clear, so we're okay then. - // - ((!dcd_zI)&&( - ((op_R == dcd_B)&&(op_wR)) - ||((mem_rdbusy)&&(!dcd_pipe)) - ||(((alu_busy)||(div_busy))&&(alu_reg == dcd_B)) - ||((wr_reg_ce)&&(wr_reg_id[3:1] == 3'h7)) - )) - // Stall following any instruction that will - // set the flags, if we're going to need the - // flags (CC) register for op_B. - ||(((op_wF)||(cc_invalid_for_dcd))&&(dcd_Bcc)) - // Stall on any ongoing memory operation that - // will write to op_B -- captured above - // ||((mem_busy)&&(!mem_we)&&(mem_last_reg==dcd_B)&&(!dcd_zI)) - ) - ||((dcd_rB)&&(dcd_Bcc)&&(cc_invalid_for_dcd)); - //}}} - assign dcd_F_stall = ((!dcd_F[3]) - //{{{ - ||((dcd_rA)&&(dcd_A[3:1]==3'h7) - &&(dcd_A[4:0] != { gie, 4'hf})) - ||((dcd_rB)&&(dcd_B[3:1]==3'h7)) - &&(dcd_B[4:0] != { gie, 4'hf})) - &&(((op_valid)&&(op_wR) - &&(op_R[3:1]==3'h7) - &&(op_R[4:0]!={gie, 4'hf})) - ||(pending_sreg_write)); - // &&(dcd_valid) is checked for elsewhere - //}}} - end else begin - // No stalls without pipelining, 'cause how can you have a pipeline - // hazard without the pipeline? - assign dcd_B_stall = 1'b0; - assign dcd_F_stall = 1'b0; - end endgenerate - - //}}} - // - // - // PIPELINE STAGE #4 :: Apply Instruction - // - // - // ALU - cpuops #(IMPLEMENT_MPY) doalu(i_clk, ((i_reset)||(clear_pipeline)), - //{{{ - alu_ce, op_opn, op_Av, op_Bv, - alu_result, alu_flags, alu_valid, alu_busy); - //}}} - - // Divide - //{{{ - generate if (IMPLEMENT_DIVIDE != 0) - begin : DIVIDE -`define DIVIDE_MODULE div - `DIVIDE_MODULE thedivide(i_clk, ((i_reset)||(clear_pipeline)), - div_ce, op_opn[0], - op_Av, op_Bv, div_busy, div_valid, div_error, div_result, - div_flags); - - end else begin - - assign div_error = 1'b0; // Can't be high unless div_valid - assign div_busy = 1'b0; - assign div_valid = 1'b0; - assign div_result= 32'h00; - assign div_flags = 4'h0; - - // Make verilator happy here - // verilator lint_off UNUSED - wire unused_divide; - assign unused_divide = div_ce; - // verilator lint_on UNUSED - end endgenerate - //}}} - - // (Non-existent) FPU - //{{{ - generate if (IMPLEMENT_FPU != 0) - begin : FPU - // - // sfpu thefpu(i_clk, i_reset, fpu_ce, op_opn[2:0], - // op_Av, op_Bv, fpu_busy, fpu_valid, fpu_err, fpu_result, - // fpu_flags); - // - assign fpu_error = 1'b0; // Must only be true if fpu_valid - assign fpu_busy = 1'b0; - assign fpu_valid = 1'b0; - assign fpu_result= 32'h00; - assign fpu_flags = 4'h0; - end else begin - assign fpu_error = 1'b0; - assign fpu_busy = 1'b0; - assign fpu_valid = 1'b0; - assign fpu_result= 32'h00; - assign fpu_flags = 4'h0; - end endgenerate - //}}} - - - assign set_cond = ((op_F[7:4]&op_Fl[3:0])==op_F[3:0]); - initial alu_wF = 1'b0; - initial alu_wR = 1'b0; - generate if (OPT_PIPELINED) - begin - always @(posedge i_clk) - if (i_reset) - begin - alu_wR <= 1'b0; - alu_wF <= 1'b0; - end else if (alu_ce) - begin - // alu_reg <= op_R; - alu_wR <= (op_wR)&&(set_cond)&&(!op_illegal); - alu_wF <= (op_wF)&&(set_cond)&&(!op_illegal); - end else if (!alu_busy) begin - // These are strobe signals, so clear them if not - // set for any particular clock - alu_wR <= (r_halted)&&(i_dbg_we); - alu_wF <= 1'b0; - end - end else begin - - always @(posedge i_clk) - alu_wR <= (op_wR)&&(set_cond)&&(!op_illegal); - always @(posedge i_clk) - alu_wF <= (op_wF)&&(set_cond)&&(!op_illegal); - - end endgenerate - - generate if (OPT_CIS) - begin : GEN_ALU_PHASE - - reg r_alu_phase; - initial r_alu_phase = 1'b0; - always @(posedge i_clk) - if ((i_reset)||(clear_pipeline)) - r_alu_phase <= 1'b0; - else if (((adf_ce_unconditional)||(mem_ce))&&(op_valid)) - r_alu_phase <= op_phase; - else if ((adf_ce_unconditional)||(mem_ce)) - r_alu_phase <= 1'b0; - assign alu_phase = r_alu_phase; - end else begin - - assign alu_phase = 1'b0; - end endgenerate - - generate if (OPT_PIPELINED) - begin - - always @(posedge i_clk) - if (adf_ce_unconditional) - alu_reg <= op_R; - else if ((r_halted)&&(i_dbg_we)) - alu_reg <= i_dbg_reg; - - end else begin - - always @(posedge i_clk) - if ((r_halted)&&(i_dbg_we)) - alu_reg <= i_dbg_reg; - else - alu_reg <= op_R; - end endgenerate - - initial wr_index = 0; - always @(posedge i_clk) - begin - if ((OPT_PIPELINED && (mem_ce || adf_ce_unconditional)) - ||(!OPT_PIPELINED && op_valid)) - begin - wr_index <= 0; - /* - if (op_valid_mem) - wr_index <= 3'b001; - if (op_valid_alu) - wr_index <= 3'b010; - if (op_valid_div) - wr_index <= 3'b011; - if (op_valid_fpu) - wr_index <= 3'b100; - */ - - wr_index[0] <= (op_valid_mem | op_valid_div); - wr_index[1] <= (op_valid_alu | op_valid_div); - wr_index[2] <= (op_valid_fpu); - end - - if (i_dbg_we && r_halted) - wr_index <= 3'b000; - - if (!IMPLEMENT_FPU) - wr_index[2] <= 1'b0; - end - - // - // DEBUG Register write access starts here - // - //{{{ - initial dbgv = 1'b0; - always @(posedge i_clk) - if (i_reset) - dbgv <= 0; - else - dbgv <= (i_dbg_we)&&(r_halted); - - always @(posedge i_clk) - dbg_val <= i_dbg_data; - always @(posedge i_clk) - if ((i_reset)||(clear_pipeline)) - dbg_clear_pipe <= 0; - else if ((i_dbg_we)&&(r_halted)) - begin - dbg_clear_pipe <= 1'b0; - - if (!OPT_PIPELINED) - dbg_clear_pipe <= 1'b1; - if ((i_dbg_reg == op_Bid)&&(op_rB)) - dbg_clear_pipe <= 1'b1; - if (i_dbg_reg[3:1] == 3'h7) - dbg_clear_pipe <= 1'b1; - end else if ((!OPT_PIPELINED)&&(i_clear_pf_cache)) - dbg_clear_pipe <= 1'b1; - else - dbg_clear_pipe <= 1'b0; - - assign alu_gie = gie; - //}}} - - generate if (OPT_PIPELINED) - begin : GEN_ALU_PC - reg [(AW+1):0] r_alu_pc; - initial r_alu_pc = 0; - always @(posedge i_clk) - if ((adf_ce_unconditional) - ||((master_ce)&&(op_valid_mem) - &&(!clear_pipeline)&&(!mem_stalled))) - r_alu_pc <= op_pc; - assign alu_pc = r_alu_pc; - - end else begin - - assign alu_pc = op_pc; - - end endgenerate - - generate if (OPT_PIPELINED) - begin : SET_ALU_ILLEGAL - reg r_alu_illegal; - - initial r_alu_illegal = 0; - always @(posedge i_clk) - if (clear_pipeline) - r_alu_illegal <= 1'b0; - else if (adf_ce_unconditional) - r_alu_illegal <= op_illegal; - else - r_alu_illegal <= 1'b0; - - assign alu_illegal = (r_alu_illegal); - end else begin : SET_ALU_ILLEGAL - assign alu_illegal = op_illegal; - end endgenerate - - initial r_alu_pc_valid = 1'b0; - initial mem_pc_valid = 1'b0; - always @(posedge i_clk) - if (clear_pipeline) - r_alu_pc_valid <= 1'b0; - else if ((adf_ce_unconditional)&&(!op_phase)) - r_alu_pc_valid <= 1'b1; - else if (((!alu_busy)&&(!div_busy)&&(!fpu_busy))||(clear_pipeline)) - r_alu_pc_valid <= 1'b0; - - assign alu_pc_valid = (r_alu_pc_valid) - &&((!alu_busy)&&(!div_busy)&&(!fpu_busy)); - - always @(posedge i_clk) - if (i_reset) - mem_pc_valid <= 1'b0; - else - mem_pc_valid <= (mem_ce); - - // Bus lock logic - //{{{ - generate - if ((OPT_PIPELINED)&&(!OPT_LOCK)) - begin : BUSLOCK - reg r_prelock_stall; - - initial r_prelock_stall = 1'b0; - always @(posedge i_clk) - if (clear_pipeline) - r_prelock_stall <= 1'b0; - else if ((op_valid)&&(op_lock)&&(op_ce)) - r_prelock_stall <= 1'b1; - else if ((op_valid)&&(dcd_valid)&&(pf_valid)) - r_prelock_stall <= 1'b0; - - assign prelock_stall = r_prelock_stall; - - reg r_prelock_primed; - initial r_prelock_primed = 1'b0; - always @(posedge i_clk) - if (clear_pipeline) - r_prelock_primed <= 1'b0; - else if (r_prelock_stall) - r_prelock_primed <= 1'b1; - else if ((adf_ce_unconditional)||(mem_ce)) - r_prelock_primed <= 1'b0; - - reg [1:0] r_bus_lock; - initial r_bus_lock = 2'b00; - always @(posedge i_clk) - if (clear_pipeline) - r_bus_lock <= 2'b00; - else if ((op_valid)&&((adf_ce_unconditional)||(mem_ce))) - begin - if (r_prelock_primed) - r_bus_lock <= 2'b10; - else if (r_bus_lock != 2'h0) - r_bus_lock <= r_bus_lock + 2'b11; - end - - assign bus_lock = |r_bus_lock; - end else begin - assign prelock_stall = 1'b0; - assign bus_lock = 1'b0; - end endgenerate - //}}} - - // Memory interface - //{{{ - generate if (OPT_DCACHE) - begin : MEM_DCACHE - - dcache #(.LGCACHELEN(OPT_LGDCACHE), .ADDRESS_WIDTH(AW), - .LGNLINES(OPT_LGDCACHE-3), .OPT_LOCAL_BUS(WITH_LOCAL_BUS), - .OPT_PIPE(OPT_MEMPIPE), - .OPT_LOCK(OPT_LOCK) - ) docache(i_clk, i_reset, w_clear_dcache, - ///{{{ - (mem_ce)&&(set_cond), bus_lock, - (op_opn[2:0]), op_Bv, op_Av, op_R, - mem_busy, mem_pipe_stalled, - mem_valid, bus_err, mem_wreg, mem_result, - mem_cyc_gbl, mem_cyc_lcl, - mem_stb_gbl, mem_stb_lcl, - mem_we, mem_addr, mem_data, mem_sel, - mem_stall, mem_ack, mem_err, i_wb_data - // , o_dcache_debug - ); - ///}}} - end else begin : NO_CACHE - if (OPT_PIPELINED_BUS_ACCESS) - begin : MEM - - pipemem #(.ADDRESS_WIDTH(AW), - .IMPLEMENT_LOCK(OPT_LOCK), - .WITH_LOCAL_BUS(WITH_LOCAL_BUS) - ) domem(i_clk,i_reset, - ///{{{ - (mem_ce)&&(set_cond), bus_lock, - (op_opn[2:0]), op_Bv, op_Av, op_R, - mem_busy, mem_pipe_stalled, - mem_valid, bus_err, mem_wreg, mem_result, - mem_cyc_gbl, mem_cyc_lcl, - mem_stb_gbl, mem_stb_lcl, - mem_we, mem_addr, mem_data, mem_sel, - mem_stall, mem_ack, mem_err, i_wb_data - ); - //}}} - end else begin : MEM - - memops #(.ADDRESS_WIDTH(AW), - .IMPLEMENT_LOCK(OPT_LOCK), - .WITH_LOCAL_BUS(WITH_LOCAL_BUS) - ) domem(i_clk,i_reset, - //{{{ - (mem_ce)&&(set_cond), bus_lock, - (op_opn[2:0]), op_Bv, op_Av, op_R, - mem_busy, - mem_valid, bus_err, mem_wreg, mem_result, - mem_cyc_gbl, mem_cyc_lcl, - mem_stb_gbl, mem_stb_lcl, - mem_we, mem_addr, mem_data, mem_sel, - mem_stall, mem_ack, mem_err, i_wb_data - ); - //}}} - assign mem_pipe_stalled = 1'b0; - end end endgenerate - - assign mem_rdbusy = (mem_busy)&&((!OPT_PIPELINED)||(!mem_we)); - - // Either the prefetch or the instruction gets the memory bus, but - // never both. - generate if (OPT_PIPELINED) - begin : PRIORITY_DATA - - wbdblpriarb #(.DW(32),.AW(AW) - ) pformem(i_clk, i_reset, - //{{{ - // Memory access to the arbiter, priority position - mem_cyc_gbl, mem_cyc_lcl, mem_stb_gbl, mem_stb_lcl, - mem_we, mem_addr, mem_data, mem_sel, - mem_stall, mem_ack, mem_err, - // Prefetch access to the arbiter - // - // At a first glance, we might want something like: - // - // pf_cyc, 1'b0, pf_stb, 1'b0, pf_we, pf_addr, pf_data, 4'hf, - // - // However, we know that the prefetch will not generate any - // writes. Therefore, the write specific lines (mem_data and - // mem_sel) can be shared with the memory in order to ease - // timing and LUT usage. - pf_cyc,1'b0,pf_stb, 1'b0, pf_we, pf_addr, mem_data, mem_sel, - pf_stall, pf_ack, pf_err, - // Common wires, in and out, of the arbiter - o_wb_gbl_cyc, o_wb_lcl_cyc, o_wb_gbl_stb, o_wb_lcl_stb, - o_wb_we, o_wb_addr, o_wb_data, o_wb_sel, - i_wb_stall, i_wb_ack, i_wb_err - ); - //}}} - - end else begin : PRIORITY_PREFETCH - - wbdblpriarb #(.DW(32),.AW(AW) - ) pformem(i_clk, i_reset, - //{{{ - // Prefetch access to the arbiter, priority position - // - // At a first glance, we might want something like: - // - // pf_cyc, 1'b0, pf_stb, 1'b0, pf_we, pf_addr, pf_data, 4'hf, - // - // However, we know that the prefetch will not generate any - // writes. Therefore, the write specific lines (mem_data and - // mem_sel) can be shared with the memory in order to ease - // timing and LUT usage. - pf_cyc,1'b0,pf_stb, 1'b0, pf_we, pf_addr, mem_data, mem_sel, - pf_stall, pf_ack, pf_err, - // Memory access to the arbiter - mem_cyc_gbl, mem_cyc_lcl, mem_stb_gbl, mem_stb_lcl, - mem_we, mem_addr, mem_data, mem_sel, - mem_stall, mem_ack, mem_err, - // Common wires, in and out, of the arbiter - o_wb_gbl_cyc, o_wb_lcl_cyc, o_wb_gbl_stb, o_wb_lcl_stb, - o_wb_we, o_wb_addr, o_wb_data, o_wb_sel, - i_wb_stall, i_wb_ack, i_wb_err - ); - //}}} - end endgenerate - - //}}} - //}}} - - - // - // - // - // - // - // - // - // - // PIPELINE STAGE #5 :: Write-back results - // - //{{{ - // - // This stage is not allowed to stall. If results are ready to be - // written back, they are written back at all cost. Sleepy CPU's - // won't prevent write back, nor debug modes, halting the CPU, nor - // anything else. Indeed, the (master_ce) bit is only as relevant - // as knowinig something is available for writeback. - - // - // Write back to our generic register set ... - // When shall we write back? On one of two conditions - // Note that the flags needed to be checked before issuing the - // bus instruction, so they don't need to be checked here. - // Further, alu_wR includes (set_cond), so we don't need to - // check for that here either. - assign wr_discard = (clear_pipeline || alu_illegal); - always @(*) - case(wr_index) - 3'b000: wr_reg_ce = dbgv; - 3'b001: wr_reg_ce = mem_valid; - //3'b010: wr_reg_ce = (!wr_discard)&&(alu_wR && alu_valid); - 3'b011: wr_reg_ce = (!wr_discard)&&(div_valid)&&(!div_error); - 3'b100: wr_reg_ce = (!wr_discard)&&(fpu_valid)&&(!fpu_error); - default: wr_reg_ce = (!wr_discard)&&(alu_wR && alu_valid); - endcase - - // Which register shall be written? - // COULD SIMPLIFY THIS: by adding three bits to these registers, - // One or PC, one for CC, and one for GIE match - // Note that the alu_reg is the register to write on a divide or - // FPU operation. - generate if (OPT_NO_USERMODE) - begin - assign wr_reg_id[3:0] = (mem_valid) - ? mem_wreg[3:0] : alu_reg[3:0]; - - assign wr_reg_id[4] = 1'b0; - end else begin - assign wr_reg_id = (mem_valid) ? mem_wreg : alu_reg; - end endgenerate - - // Are we writing to the CC register? - assign wr_write_cc = (wr_reg_id[3:0] == `CPU_CC_REG); - assign wr_write_scc = (wr_reg_id[4:0] == {1'b0, `CPU_CC_REG}); - assign wr_write_ucc = (wr_reg_id[4:0] == {1'b1, `CPU_CC_REG}); - // Are we writing to the PC? - assign wr_write_pc = (wr_reg_id[3:0] == `CPU_PC_REG); - - // What value to write? - always @(*) - case(wr_index) - 3'b000: wr_gpreg_vl = dbg_val; - 3'b001: wr_gpreg_vl = mem_result; - // 3'b010: wr_gpreg_vl = alu_result; - 3'b011: wr_gpreg_vl = div_result; - 3'b100: wr_gpreg_vl = fpu_result; - default: wr_gpreg_vl = alu_result; - endcase - - always @(*) - case(wr_index[1:0]) - 2'b00: wr_spreg_vl = dbg_val; - 2'b01: wr_spreg_vl = mem_result; - // 3'b010: wr_gpreg_vl = alu_result; - default: wr_spreg_vl = alu_result; - endcase - - generate if (OPT_NO_USERMODE) - begin : SET_REGISTERS - - always @(posedge i_clk) - if (wr_reg_ce) - regset[{1'b0,wr_reg_id[3:0]}] <= wr_gpreg_vl; - - end else begin : SET_REGISTERS - - always @(posedge i_clk) - if (wr_reg_ce) - regset[wr_reg_id] <= wr_gpreg_vl; - - end endgenerate - - - // - // Write back to the condition codes/flags register ... - // When shall we write to our flags register? alu_wF already - // includes the set condition ... - // assign wr_flags_ce = (alu_wF)&&((alu_valid) - // ||(div_valid)||(fpu_valid)) - // &&(!clear_pipeline)&&(!alu_illegal); - always @(*) - begin - wr_flags_ce = 0; - if (alu_wF && !wr_discard) - case(wr_index) - // 3'b000: wr_flags_ce = 0; // Debug - // 3'b001: wr_flags_ce = 0; // Memory - 3'b010: wr_flags_ce = alu_valid; // ALU - 3'b011: wr_flags_ce = div_valid && !div_error; // DIV - 3'b100: wr_flags_ce = fpu_valid && !fpu_error; // FPU - default: wr_flags_ce = 0; - endcase - end - - always @(*) - begin - wr_flags = 0; - case(wr_index) - 3'b010: wr_flags = alu_flags; - 3'b011: wr_flags = div_flags; - 3'b100: wr_flags = fpu_flags; - default: wr_flags = 0; - endcase - end - - assign w_uflags = { 2'b00, uhalt_phase, ufpu_err_flag, - udiv_err_flag, ubus_err_flag, trap, ill_err_u, - ubreak, step, 1'b1, sleep, - ((wr_flags_ce)&&(alu_gie))?wr_flags:flags }; - assign w_iflags = { 2'b00, ihalt_phase, ifpu_err_flag, - idiv_err_flag, ibus_err_flag, trap, ill_err_i, - break_en, 1'b0, 1'b0, sleep, - ((wr_flags_ce)&&(!alu_gie))?wr_flags:iflags }; - - - // What value to write? - always @(posedge i_clk) - // If explicitly writing the register itself - if ((wr_reg_ce)&&(wr_write_ucc)) - flags <= wr_gpreg_vl[3:0]; - // Otherwise if we're setting the flags from an ALU operation - else if ((wr_flags_ce)&&(alu_gie)) - flags <= (div_valid)?div_flags:((fpu_valid)?fpu_flags - : alu_flags); - - always @(posedge i_clk) - if ((wr_reg_ce)&&(wr_write_scc)) - iflags <= wr_gpreg_vl[3:0]; - else if ((wr_flags_ce)&&(!alu_gie)) - iflags <= (div_valid)?div_flags:((fpu_valid)?fpu_flags - : alu_flags); - - // The 'break' enable bit. This bit can only be set from supervisor - // mode. It control what the CPU does upon encountering a break - // instruction. - // - // The goal, upon encountering a break is that the CPU should stop and - // not execute the break instruction, choosing instead to enter into - // either interrupt mode or halt first. - // if ((break_en) AND (break_instruction)) // user mode or not - // HALT CPU - // else if (break_instruction) // only in user mode - // set an interrupt flag, set the user break bit, - // go to supervisor mode, allow supervisor to step the CPU. - // Upon a CPU halt, any break condition will be reset. The - // external debugger will then need to deal with whatever - // condition has taken place. - initial break_en = 1'b0; - always @(posedge i_clk) - if ((i_reset)||(i_halt)) - break_en <= 1'b0; - else if ((wr_reg_ce)&&(wr_write_scc)) - break_en <= wr_spreg_vl[`CPU_BREAK_BIT]; - - generate if (OPT_PIPELINED) - begin : GEN_PENDING_BREAK - reg r_break_pending; - - initial r_break_pending = 1'b0; - always @(posedge i_clk) - if ((clear_pipeline)||(!op_valid)) - r_break_pending <= 1'b0; - else if ((op_break)&&(!r_break_pending)) - r_break_pending <= (!alu_busy)&&(!div_busy) - &&(!fpu_busy)&&(!mem_busy) - &&(!wr_reg_ce); - // else - // r_break_pending <= 1'b0; - - assign break_pending = r_break_pending; - end else begin - - assign break_pending = op_break; - end endgenerate - - - assign o_break = ((break_en)||(!op_gie))&&(break_pending) - &&(!clear_pipeline) - ||(ill_err_i) - ||((!alu_gie)&&(bus_err)) - ||((!alu_gie)&&(div_error)) - ||((!alu_gie)&&(fpu_error)) - ||((!alu_gie)&&(alu_illegal)&&(!clear_pipeline)); - - // The sleep register. Setting the sleep register causes the CPU to - // sleep until the next interrupt. Setting the sleep register within - // interrupt mode causes the processor to halt until a reset. This is - // a panic/fault halt. The trick is that you cannot be allowed to - // set the sleep bit and switch to supervisor mode in the same - // instruction: users are not allowed to halt the CPU. - initial sleep = 1'b0; - generate if (OPT_NO_USERMODE) - begin : GEN_NO_USERMODE_SLEEP - reg r_sleep_is_halt; - initial r_sleep_is_halt = 1'b0; - always @(posedge i_clk) - if (i_reset) - r_sleep_is_halt <= 1'b0; - else if ((wr_reg_ce)&&(wr_write_cc) - &&(wr_spreg_vl[`CPU_SLEEP_BIT]) - &&(!wr_spreg_vl[`CPU_GIE_BIT])) - r_sleep_is_halt <= 1'b1; - - // Trying to switch to user mode, either via a WAIT or an RTU - // instruction will cause the CPU to sleep until an interrupt, - // in the NO-USERMODE build. - always @(posedge i_clk) - if ((i_reset)||((i_interrupt)&&(!r_sleep_is_halt))) - sleep <= 1'b0; - else if ((wr_reg_ce)&&(wr_write_cc) - &&(wr_spreg_vl[`CPU_GIE_BIT])) - sleep <= 1'b1; - - end else begin : GEN_SLEEP - - always @(posedge i_clk) - if ((i_reset)||(w_switch_to_interrupt)) - sleep <= 1'b0; - else if ((wr_reg_ce)&&(wr_write_cc)&&(!alu_gie)) - // In supervisor mode, we have no protections. - // The supervisor can set the sleep bit however - // he wants. Well ... not quite. Switching to - // user mode and sleep mode shouold only be - // possible if the interrupt flag isn't set. - // Thus: if (i_interrupt) - // &&(wr_spreg_vl[GIE]) - // don't set the sleep bit - // otherwise however it would o.w. be set - sleep <= (wr_spreg_vl[`CPU_SLEEP_BIT]) - &&((!i_interrupt) - ||(!wr_spreg_vl[`CPU_GIE_BIT])); - else if ((wr_reg_ce)&&(wr_write_cc) - &&(wr_spreg_vl[`CPU_GIE_BIT])) - // In user mode, however, you can only set the - // sleep mode while remaining in user mode. - // You can't switch to sleep mode *and* - // supervisor mode at the same time, lest you - // halt the CPU. - sleep <= wr_spreg_vl[`CPU_SLEEP_BIT]; - end endgenerate - - always @(posedge i_clk) - if (i_reset) - step <= 1'b0; - else if ((wr_reg_ce)&&(!alu_gie)&&(wr_write_ucc)) - step <= wr_spreg_vl[`CPU_STEP_BIT]; - - // The GIE register. Only interrupts can disable the interrupt register - generate if (OPT_NO_USERMODE) - begin - - assign w_switch_to_interrupt = 1'b0; - assign w_release_from_interrupt = 1'b0; - - end else begin : GEN_PENDING_INTERRUPT - - reg r_pending_interrupt; - - always @(posedge i_clk) - if (i_reset) - r_pending_interrupt <= 1'b0; - else if ((clear_pipeline)||(w_switch_to_interrupt)||(!gie)) - r_pending_interrupt <= 1'b0; - else if (i_interrupt) - r_pending_interrupt <= 1'b1; - else if (adf_ce_unconditional) - begin - if ((op_illegal)||(step)||(break_pending)) - r_pending_interrupt <= 1'b1; - end else if (break_pending) - r_pending_interrupt <= 1'b1; - else if ((mem_ce)&&(step)) - r_pending_interrupt <= 1'b1; - - assign pending_interrupt = r_pending_interrupt; - - - assign w_switch_to_interrupt = (gie)&&( - // On interrupt (obviously) - ((pending_interrupt) - &&(!alu_phase)&&(!bus_lock)&&(!mem_busy)) - // - // On division by zero. If the divide isn't - // implemented, div_valid and div_error will be short - // circuited and that logic will be bypassed - ||(div_error) - // - // Same thing on a floating point error. Note that - // fpu_error must *never* be set unless fpu_valid is - // also set as well, else this will fail. - ||(fpu_error) - // - // - ||(bus_err) - // - // If we write to the CC register - ||((wr_reg_ce)&&(!wr_spreg_vl[`CPU_GIE_BIT]) - &&(wr_reg_id[4])&&(wr_write_cc)) - ); - assign w_release_from_interrupt = (!gie)&&(!i_interrupt) - // Then if we write the sCC register - &&(((wr_reg_ce)&&(wr_spreg_vl[`CPU_GIE_BIT]) - &&(wr_write_scc)) - ); - end endgenerate - - generate if (OPT_NO_USERMODE) - begin - - assign gie = 1'b0; - - end else begin : SET_GIE - - reg r_gie; - - initial r_gie = 1'b0; - always @(posedge i_clk) - if (i_reset) - r_gie <= 1'b0; - else if (w_switch_to_interrupt) - r_gie <= 1'b0; - else if (w_release_from_interrupt) - r_gie <= 1'b1; - - assign gie = r_gie; - end endgenerate - - generate if (OPT_NO_USERMODE) - begin - - assign trap = 1'b0; - assign ubreak = 1'b0; - - end else begin : SET_TRAP_N_UBREAK - - reg r_trap; - - initial r_trap = 1'b0; - always @(posedge i_clk) - if ((i_reset)||(w_release_from_interrupt)) - r_trap <= 1'b0; - else if ((alu_gie)&&(wr_reg_ce)&&(!wr_spreg_vl[`CPU_GIE_BIT]) - &&(wr_write_ucc)) // &&(wr_reg_id[4]) implied - r_trap <= 1'b1; - else if ((wr_reg_ce)&&(wr_write_ucc)&&(!alu_gie)) - r_trap <= (r_trap)&&(wr_spreg_vl[`CPU_TRAP_BIT]); - - reg r_ubreak; - - initial r_ubreak = 1'b0; - always @(posedge i_clk) - if ((i_reset)||(w_release_from_interrupt)) - r_ubreak <= 1'b0; - else if ((op_gie)&&(break_pending)&&(w_switch_to_interrupt)) - r_ubreak <= 1'b1; - else if (((!alu_gie)||(dbgv))&&(wr_reg_ce)&&(wr_write_ucc)) - r_ubreak <= (ubreak)&&(wr_spreg_vl[`CPU_BREAK_BIT]); - - assign trap = r_trap; - assign ubreak = r_ubreak; - - end endgenerate - - - initial ill_err_i = 1'b0; - always @(posedge i_clk) - if (i_reset) - ill_err_i <= 1'b0; - // Only the debug interface can clear this bit - else if ((dbgv)&&(wr_write_scc)) - ill_err_i <= (ill_err_i)&&(wr_spreg_vl[`CPU_ILL_BIT]); - else if ((alu_illegal)&&(!alu_gie)&&(!clear_pipeline)) - ill_err_i <= 1'b1; - - generate if (OPT_NO_USERMODE) - begin - - assign ill_err_u = 1'b0; - - end else begin : SET_USER_ILLEGAL_INSN - - reg r_ill_err_u; - - initial r_ill_err_u = 1'b0; - always @(posedge i_clk) - // The bit is automatically cleared on release from interrupt - // or reset - if ((i_reset)||(w_release_from_interrupt)) - r_ill_err_u <= 1'b0; - // If the supervisor (or debugger) writes to this - // register, clearing the bit, then clear it - else if (((!alu_gie)||(dbgv))&&(wr_reg_ce)&&(wr_write_ucc)) - r_ill_err_u <=((ill_err_u)&&(wr_spreg_vl[`CPU_ILL_BIT])); - else if ((alu_illegal)&&(alu_gie)&&(!clear_pipeline)) - r_ill_err_u <= 1'b1; - - assign ill_err_u = r_ill_err_u; - - end endgenerate - - // Supervisor/interrupt bus error flag -- this will crash the CPU if - // ever set. - initial ibus_err_flag = 1'b0; - always @(posedge i_clk) - if (i_reset) - ibus_err_flag <= 1'b0; - else if ((dbgv)&&(wr_write_scc)) - ibus_err_flag <= (ibus_err_flag)&&(wr_spreg_vl[`CPU_BUSERR_BIT]); - else if ((bus_err)&&(!alu_gie)) - ibus_err_flag <= 1'b1; - // User bus error flag -- if ever set, it will cause an interrupt to - // supervisor mode. - generate if (OPT_NO_USERMODE) - begin - - assign ubus_err_flag = 1'b0; - - end else begin : SET_USER_BUSERR - - reg r_ubus_err_flag; - - initial r_ubus_err_flag = 1'b0; - always @(posedge i_clk) - if ((i_reset)||(w_release_from_interrupt)) - r_ubus_err_flag <= 1'b0; - else if (((!alu_gie)||(dbgv))&&(wr_reg_ce)&&(wr_write_ucc)) - r_ubus_err_flag <= (ubus_err_flag)&&(wr_spreg_vl[`CPU_BUSERR_BIT]); - else if ((bus_err)&&(alu_gie)) - r_ubus_err_flag <= 1'b1; - - assign ubus_err_flag = r_ubus_err_flag; - end endgenerate - - generate if (IMPLEMENT_DIVIDE != 0) - begin : DIVERR - reg r_idiv_err_flag, r_udiv_err_flag; - - // Supervisor/interrupt divide (by zero) error flag -- this will - // crash the CPU if ever set. This bit is thus available for us - // to be able to tell if/why the CPU crashed. - initial r_idiv_err_flag = 1'b0; - always @(posedge i_clk) - if (i_reset) - r_idiv_err_flag <= 1'b0; - else if ((dbgv)&&(wr_write_scc)) - r_idiv_err_flag <= (r_idiv_err_flag)&&(wr_spreg_vl[`CPU_DIVERR_BIT]); - else if ((div_error)&&(!alu_gie)) - r_idiv_err_flag <= 1'b1; - - assign idiv_err_flag = r_idiv_err_flag; - - if (OPT_NO_USERMODE) - begin - assign udiv_err_flag = 1'b0; - end else begin - - // User divide (by zero) error flag -- if ever set, it will - // cause a sudden switch interrupt to supervisor mode. - initial r_udiv_err_flag = 1'b0; - always @(posedge i_clk) - if ((i_reset)||(w_release_from_interrupt)) - r_udiv_err_flag <= 1'b0; - else if (((!alu_gie)||(dbgv))&&(wr_reg_ce) - &&(wr_write_ucc)) - r_udiv_err_flag <= (r_udiv_err_flag)&&(wr_spreg_vl[`CPU_DIVERR_BIT]); - else if ((div_error)&&(alu_gie)) - r_udiv_err_flag <= 1'b1; - - assign udiv_err_flag = r_udiv_err_flag; - end - end else begin - assign idiv_err_flag = 1'b0; - assign udiv_err_flag = 1'b0; - end endgenerate - - generate if (IMPLEMENT_FPU !=0) - begin : FPUERR - // Supervisor/interrupt floating point error flag -- this will - // crash the CPU if ever set. - reg r_ifpu_err_flag, r_ufpu_err_flag; - initial r_ifpu_err_flag = 1'b0; - always @(posedge i_clk) - if (i_reset) - r_ifpu_err_flag <= 1'b0; - else if ((dbgv)&&(wr_write_scc)) - r_ifpu_err_flag <= (r_ifpu_err_flag)&&(wr_spreg_vl[`CPU_FPUERR_BIT]); - else if ((fpu_error)&&(fpu_valid)&&(!alu_gie)) - r_ifpu_err_flag <= 1'b1; - // User floating point error flag -- if ever set, it will cause - // a sudden switch interrupt to supervisor mode. - initial r_ufpu_err_flag = 1'b0; - always @(posedge i_clk) - if ((i_reset)&&(w_release_from_interrupt)) - r_ufpu_err_flag <= 1'b0; - else if (((!alu_gie)||(dbgv))&&(wr_reg_ce) - &&(wr_write_ucc)) - r_ufpu_err_flag <= (r_ufpu_err_flag)&&(wr_spreg_vl[`CPU_FPUERR_BIT]); - else if ((fpu_error)&&(alu_gie)&&(fpu_valid)) - r_ufpu_err_flag <= 1'b1; - - assign ifpu_err_flag = r_ifpu_err_flag; - assign ufpu_err_flag = r_ufpu_err_flag; - end else begin - assign ifpu_err_flag = 1'b0; - assign ufpu_err_flag = 1'b0; - end endgenerate - - generate if (OPT_CIS) - begin : GEN_IHALT_PHASE - reg r_ihalt_phase; - - initial r_ihalt_phase = 0; - always @(posedge i_clk) - if (i_reset) - r_ihalt_phase <= 1'b0; - else if ((!alu_gie)&&(alu_pc_valid)&&(!clear_pipeline)) - r_ihalt_phase <= alu_phase; - - assign ihalt_phase = r_ihalt_phase; - end else begin : GEN_IHALT_PHASE - - assign ihalt_phase = 1'b0; - - end endgenerate - - generate if ((!OPT_CIS) || (OPT_NO_USERMODE)) - begin : GEN_UHALT_PHASE - - assign uhalt_phase = 1'b0; - - end else begin : GEN_UHALT_PHASE - - reg r_uhalt_phase; - - initial r_uhalt_phase = 1'b0; - always @(posedge i_clk) - if ((i_reset)||(w_release_from_interrupt)) - r_uhalt_phase <= 1'b0; - else if ((alu_gie)&&(alu_pc_valid)) - r_uhalt_phase <= alu_phase; - else if ((!alu_gie)&&(wr_reg_ce)&&(wr_write_pc) - &&(wr_reg_id[4])) - r_uhalt_phase <= wr_spreg_vl[1]; - - assign uhalt_phase = r_uhalt_phase; - - end endgenerate - - // - // Write backs to the PC register, and general increments of it - // We support two: upc and ipc. If the instruction is normal, - // we increment upc, if interrupt level we increment ipc. If - // the instruction writes the PC, we write whichever PC is appropriate. - // - // Do we need to all our partial results from the pipeline? - // What happens when the pipeline has gie and !gie instructions within - // it? Do we clear both? What if a gie instruction tries to clear - // a non-gie instruction? - generate if (OPT_NO_USERMODE) - begin - - assign upc = {(AW+2){1'b0}}; - - end else begin : SET_USER_PC - - reg [(AW+1):0] r_upc; - - always @(posedge i_clk) - if ((wr_reg_ce)&&(wr_reg_id[4])&&(wr_write_pc)) - r_upc <= { wr_spreg_vl[(AW+1):2], 2'b00 }; - else if ((alu_gie)&& - (((alu_pc_valid)&&(!clear_pipeline)&&(!alu_illegal)) - ||(mem_pc_valid))) - r_upc <= alu_pc; - assign upc = r_upc; - end endgenerate - - initial ipc = { RESET_BUS_ADDRESS, 2'b00 }; - always @(posedge i_clk) - if (i_reset) - ipc <= { RESET_BUS_ADDRESS, 2'b00 }; - else if ((wr_reg_ce)&&(!wr_reg_id[4])&&(wr_write_pc)) - ipc <= { wr_spreg_vl[(AW+1):2], 2'b00 }; - else if ((!alu_gie)&&(!alu_phase)&& - (((alu_pc_valid)&&(!clear_pipeline)&&(!alu_illegal)) - ||(mem_pc_valid))) - ipc <= alu_pc; - - reg pfpcset; - reg [2:0] pfpcsrc; - always @(*) - begin - pfpcset = 0; - pfpcsrc = 0; - if (i_reset) - begin - pfpcsrc = 0; - pfpcset = 1; - end else if ((dbg_clear_pipe)&&(wr_reg_ce)&&(wr_write_pc)) - begin - pfpcsrc = 1; // spreg - pfpcset = 1; - end else if ((w_switch_to_interrupt) - ||((!gie)&&((w_clear_icache)||(dbg_clear_pipe)))) - begin - pfpcsrc = 2; // ipc - pfpcset = 1; - end else if ((w_release_from_interrupt)||((gie)&&((w_clear_icache)||(dbg_clear_pipe)))) - begin - pfpcsrc = 3; // upc - pfpcset = 1; - end else if ((wr_reg_ce)&&(wr_reg_id[4] == gie)&&(wr_write_pc)) - begin - pfpcsrc = 1; // spreg - pfpcset = 1; - end else if ((dcd_early_branch_stb)&&(!clear_pipeline)) - begin - pfpcsrc = 4; // branch - pfpcset = 1; - end else if ((new_pc)||((!pf_stalled)&&(pf_valid))) - begin - pfpcsrc = 5; // PC increment - pfpcset = 1; - end - end - - initial pf_pc = { RESET_BUS_ADDRESS, 2'b00 }; - always @(posedge i_clk) - if (pfpcset) - case(pfpcsrc) - 3'b000: pf_pc <= { RESET_BUS_ADDRESS, 2'b00 }; - 3'b001: pf_pc <= { wr_spreg_vl[(AW+1):2], 2'b00 }; - 3'b010: pf_pc <= { ipc[(AW+1):2], 2'b00 }; - 3'b011: pf_pc <= { upc[(AW+1):2], 2'b00 }; - 3'b100: pf_pc <= { dcd_branch_pc[AW+1:2] + 1'b1, 2'b00 }; - 3'b101: pf_pc <= { pf_pc[(AW+1):2] + 1'b1, 2'b00 }; - default: pf_pc <= { RESET_BUS_ADDRESS, 2'b00 }; - endcase - - initial last_write_to_cc = 1'b0; - always @(posedge i_clk) - if (i_reset) - last_write_to_cc <= 1'b0; - else - last_write_to_cc <= (wr_reg_ce)&&(wr_write_cc); - assign cc_write_hold = (wr_reg_ce)&&(wr_write_cc)||(last_write_to_cc); - - // If we aren't pipelined, or equivalently if we have no cache, these - // instructions will get quietly (or not so quietly) ignored by the - // optimizer. - initial r_clear_icache = 1'b1; - always @(posedge i_clk) - if (i_reset) - r_clear_icache <= 1'b0; - else if ((r_halted)&&(i_clear_pf_cache)) - r_clear_icache <= 1'b1; - else if ((wr_reg_ce)&&(wr_write_scc)) - r_clear_icache <= wr_spreg_vl[`CPU_CLRICACHE_BIT]; - else - r_clear_icache <= 1'b0; - assign w_clear_icache = r_clear_icache; - - generate if (OPT_LGDCACHE > 0) - begin : CLEAR_DCACHE - initial r_clear_dcache = 1'b1; - always @(posedge i_clk) - if (i_reset) - r_clear_dcache <= 1'b0; - else if ((r_halted)&&(i_clear_pf_cache)) - r_clear_dcache <= 1'b1; - else if ((wr_reg_ce)&&(wr_write_scc)) - r_clear_dcache <= wr_spreg_vl[`CPU_CLRDCACHE_BIT]; - else - r_clear_dcache <= 1'b0; - end else begin : NOCLEAR_DCACHE - always @(*) - r_clear_dcache = 1'b0; - end endgenerate - - assign w_clear_dcache = r_clear_dcache; - - initial new_pc = 1'b1; - always @(posedge i_clk) - if ((i_reset)||(w_clear_icache)||(dbg_clear_pipe)) - new_pc <= 1'b1; - else if (w_switch_to_interrupt) - new_pc <= 1'b1; - else if (w_release_from_interrupt) - new_pc <= 1'b1; - // else if ((wr_reg_ce)&&(wr_reg_id[4] == gie)&&(wr_write_pc)) - // Can't check for *this* PC here, since a user PC might be - // loaded in the pipeline and hence rewritten. Thus, while - // I hate to do it, we'll need to clear the pipeline on any - // PC write - else if ((wr_reg_ce)&&(alu_gie == wr_reg_id[4])&&(wr_write_pc)) - new_pc <= 1'b1; - else - new_pc <= 1'b0; - - // - // The debug write-back interface - //{{{ - reg [31:0] debug_pc; - generate if (OPT_NO_USERMODE) - begin - - always @(*) - begin - debug_pc = 0; - debug_pc[(AW+1):0] = { ipc, 2'b00 }; - end - - end else begin - - always @(*) - begin - debug_pc = 0; - if (i_dbg_reg[4]) - // User mode - debug_pc[(AW+1):0] - = { upc[(AW+1):2], uhalt_phase, 1'b0 }; - else - // Supervisor mode - debug_pc[(AW+1):0] - = { ipc[(AW+1):2], ihalt_phase, 1'b0 }; - end - - end endgenerate - - generate if (OPT_NO_USERMODE) - begin : NO_USER_SETDBG - - always @(posedge i_clk) - begin - o_dbg_reg <= regset[i_dbg_reg[3:0]]; - if (i_dbg_reg[3:0] == `CPU_PC_REG) - o_dbg_reg <= debug_pc; - else if (i_dbg_reg[3:0] == `CPU_CC_REG) - begin - o_dbg_reg[15:0] <= w_iflags; - o_dbg_reg[31:23] <= w_cpu_info; - o_dbg_reg[`CPU_GIE_BIT] <= gie; - end - end - end else begin : SETDBG - -`ifdef NO_DISTRIBUTED_RAM - reg [31:0] pre_dbg_reg; - always @(posedge i_clk) - pre_dbg_reg <= regset[i_dbg_reg]; - - always @(posedge i_clk) - begin - o_dbg_reg <= pre_dbg_reg; - if (i_dbg_reg[3:0] == `CPU_PC_REG) - o_dbg_reg <= debug_pc; - else if (i_dbg_reg[3:0] == `CPU_CC_REG) - begin - o_dbg_reg[15:0] <= (i_dbg_reg[4]) - ? w_uflags : w_iflags; - o_dbg_reg[31:23] <= w_cpu_info; - o_dbg_reg[`CPU_GIE_BIT] <= gie; - end - end - -`else - always @(posedge i_clk) - begin - o_dbg_reg <= regset[i_dbg_reg]; - if (i_dbg_reg[3:0] == `CPU_PC_REG) - o_dbg_reg <= debug_pc; - else if (i_dbg_reg[3:0] == `CPU_CC_REG) - begin - o_dbg_reg[15:0] <= (i_dbg_reg[4]) - ? w_uflags : w_iflags; - o_dbg_reg[31:23] <= w_cpu_info; - o_dbg_reg[`CPU_GIE_BIT] <= gie; - end - end -`endif - - end endgenerate - - always @(posedge i_clk) - o_dbg_cc <= { o_break, bus_err, gie, sleep }; - - generate if (OPT_PIPELINED) - begin - always @(posedge i_clk) - r_halted <= (i_halt)&&(!alu_phase)&&(!bus_lock)&&( - // To be halted, any long lasting instruction - // must be completed. - (!pf_cyc)&&(!mem_busy)&&(!alu_busy) - &&(!div_busy)&&(!fpu_busy) - // Operations must either be valid, or illegal - &&((op_valid)||(i_reset)||(dcd_illegal)) - // Decode stage must be either valid, in reset, - // or producing an illelgal instruction - &&((dcd_valid)||(i_reset)||(pf_illegal))); - end else begin - - always @(posedge i_clk) - r_halted <= (i_halt)&&(!alu_phase) - // To be halted, any long lasting instruction - // must be completed. - &&(!pf_cyc)&&(!mem_busy)&&(!alu_busy) - &&(!div_busy)&&(!fpu_busy); - end endgenerate -`ifdef NO_DISTRIBUTED_RAM - reg r_dbg_stall; - initial r_dbg_stall = 1'b1; - - always @(posedge i_clk) - if (i_reset) - r_dbg_stall <= 1'b1; - else if (!r_halted) - r_dbg_stall <= 1'b1; - else - r_dbg_stall <= (!i_dbg_we)||(!r_dbg_stall); - - assign o_dbg_stall = !r_halted; -`else - assign o_dbg_stall = !r_halted; -`endif - //}}} - - //}}} - - // - // - // Produce accounting outputs: Account for any CPU stalls, so we can - // later evaluate how well we are doing. - // - // - assign o_op_stall = (master_ce)&&(op_stall); - assign o_pf_stall = (master_ce)&&(!pf_valid); - assign o_i_count = (alu_pc_valid)&&(!clear_pipeline); - -`ifdef DEBUG_SCOPE - //{{{ - - reg debug_trigger; - initial debug_trigger = 1'b0; - always @(posedge i_clk) - debug_trigger <= (!i_halt)&&(o_break); - - wire [31:0] debug_flags; - assign debug_flags = { debug_trigger, 3'b101, - master_ce, i_halt, o_break, sleep, - gie, ibus_err_flag, trap, ill_err_i, - w_clear_icache, pf_valid, pf_illegal, dcd_ce, - dcd_valid, dcd_stalled, op_ce, op_valid, - op_pipe, alu_ce, alu_busy, alu_wR, - alu_illegal, alu_wF, mem_ce, mem_we, - mem_busy, mem_pipe_stalled, (new_pc), (dcd_early_branch) }; - - // Verilator lint_off UNUSED - wire [27:0] dbg_pc, dbg_wb_addr; - // Verilator lint_on UNUSED - generate if (AW-1 < 27) - begin - assign dbg_pc[(AW-1):0] = pf_pc[(AW+1):2]; - assign dbg_pc[27:AW] = 0; - - assign dbg_wb_addr[(AW-1):0] = o_wb_addr; - assign dbg_wb_addr[27:AW] = 0; - end else // if (AW-1 >= 27) - begin - assign dbg_pc[27:0] = pf_pc[29:2]; - assign dbg_wb_addr = o_wb_addr; - end endgenerate - - reg [2:0] dbgsrc; - - always @(posedge i_clk) - begin - dbgsrc <= 0; - if ((i_halt)||(!master_ce)||(debug_trigger)||(o_break)) - dbgsrc <= 3'b000; - else if ((mem_valid)||((!clear_pipeline)&&(!alu_illegal) - &&(((alu_wR)&&(alu_valid)) - ||(div_valid)||(fpu_valid)))) - dbgsrc <= 3'b001; - else if (clear_pipeline) - dbgsrc <= 3'b010; - else if ((o_wb_gbl_stb)|(o_wb_lcl_stb)) - dbgsrc <= 3'b011; - else - dbgsrc <= 3'b100; - end - - always @(posedge i_clk) - casez(dbgsrc) - 3'b000: o_debug <= debug_flags; - 3'b001: o_debug <= { debug_trigger, 1'b0, wr_reg_id[3:0], - wr_gpreg_vl[25:0]}; - 3'b010: o_debug <= { debug_trigger, 3'b100, dbg_pc }; - 3'b011: o_debug <= {debug_trigger, 2'b11, o_wb_gbl_stb, o_wb_we, - (o_wb_we)?o_wb_data[26:0] : dbg_wb_addr[26:0] }; - 3'b1??: o_debug <= debug_flags; - endcase - - //}}} -`endif - - // Make verilator happy - //{{{ - // verilator lint_off UNUSED - wire [56:0] unused; - assign unused = { pf_new_pc, - fpu_ce, pf_data, wr_spreg_vl[1:0], - ipc[1:0], upc[1:0], pf_pc[1:0], - dcd_rA, dcd_pipe, dcd_zI, - dcd_A_stall, dcd_B_stall, dcd_F_stall, - op_Rcc, op_pipe, op_lock, mem_pipe_stalled, prelock_stall, - dcd_F }; - generate if (AW+2 < 32) - begin - wire [31:(AW+2)] generic_ignore; - assign generic_ignore = wr_spreg_vl[31:(AW+2)]; - end endgenerate - // verilator lint_on UNUSED - //}}} - - // Formal methods - //{{{ -`ifdef FORMAL -// The ZipCPU formal properties are maintained elsewhere -`endif // FORMAL - //}}} - -endmodule diff --git a/rtl/cpu/zipjiffies.v b/rtl/cpu/zipjiffies.v index f97cd99..f9e1412 100644 --- a/rtl/cpu/zipjiffies.v +++ b/rtl/cpu/zipjiffies.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: zipjiffies.v -// +// {{{ // Project: Zip CPU -- a small, lightweight, RISC CPU soft core // // Purpose: This peripheral is motivated by the Linux use of 'jiffies'. @@ -44,9 +44,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -61,40 +61,45 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // // `default_nettype none -// -module zipjiffies(i_clk, i_reset, i_ce, - i_wb_cyc, i_wb_stb, i_wb_we, i_wb_data, - o_wb_stall, o_wb_ack, o_wb_data, - o_int); - parameter BW = 32; - input wire i_clk, i_reset, i_ce; - // Wishbone inputs - input wire i_wb_cyc, i_wb_stb, i_wb_we; - input wire [(BW-1):0] i_wb_data; - // Wishbone outputs - output wire o_wb_stall; - output reg o_wb_ack; - output wire [(BW-1):0] o_wb_data; - // Interrupt line - output reg o_int; - +// }}} +module zipjiffies #( + parameter BW = 32 + ) ( + // {{{ + input wire i_clk, i_reset, i_ce, + // Wishbone inputs + input wire i_wb_cyc, i_wb_stb, i_wb_we, + input wire [(BW-1):0] i_wb_data, + input wire [BW/8-1:0] i_wb_sel, + // Wishbone outputs + output wire o_wb_stall, + output reg o_wb_ack, + output wire [(BW-1):0] o_wb_data, + // Interrupt line + output reg o_int + // }}} + ); + + // Local declarations + // {{{ reg [(BW-1):0] r_counter; // - reg int_set, new_set; + reg int_set, new_set, int_now; reg [(BW-1):0] int_when, new_when; - wire signed [(BW-1):0] till_when; - reg signed [(BW-1):0] till_wb; + reg signed [(BW-1):0] till_wb, till_when; + // }}} - // + // r_counter + // {{{ // Our counter logic: The counter is always counting up--it cannot // be stopped or altered. It's really quite simple. Okay, not quite. // We still support the clock enable line. We do this in order to @@ -102,19 +107,32 @@ module zipjiffies(i_clk, i_reset, i_ce, // debugger, the timer's all slow down so that everything can be stepped // together, one clock at a time. // - initial r_counter = 0; always @(posedge i_clk) if (i_reset) r_counter <= 0; else if (i_ce) r_counter <= r_counter+1; + // }}} - // + // int_now + // {{{ + initial int_now = 0; + always @(posedge i_clk) + if (i_reset) + int_now <= 0; + else if (i_ce) + int_now <= ((r_counter + 1) == (int_when)); + else + int_now <= 1'b0; + // }}} + + // new_set, new_when + // {{{ // Writes to the counter set an interrupt--but only if they are in the // future as determined by the signed result of an unsigned subtract. // - assign till_when = int_when-r_counter; + // assign till_when = int_when-r_counter; // assign till_wb = new_when-r_counter; initial new_set = 1'b0; @@ -128,18 +146,26 @@ module zipjiffies(i_clk, i_reset, i_ce, till_wb <= (i_wb_data - r_counter - (i_ce ? 1:0)); + till_when <= (int_when - i_wb_data); + if (i_reset) new_set <= 1'b0; end + // }}} + // o_int, int_set + // {{{ initial o_int = 1'b0; initial int_set = 1'b0; always @(posedge i_clk) if (i_reset) begin + // {{{ o_int <= 0; int_set <= 0; + // }}} end else begin + // {{{ o_int <= 1'b0; if ((i_ce)&&(int_set)&&(r_counter == int_when)) // Interrupts are self-clearing @@ -149,15 +175,21 @@ module zipjiffies(i_clk, i_reset, i_ce, if ((new_set)&&(till_wb > 0)) int_set <= 1'b1; - else if ((i_ce)&&(r_counter == int_when)) + else if (int_now) int_set <= 1'b0; + // }}} end + // }}} + // int_when + // {{{ always @(posedge i_clk) - if ((new_set)&&(till_wb > 0)&&((till_wb 0)&&((till_when[BW-1])||(!int_set))) int_when <= new_when; + // }}} - // + // o_wb_ack + // {{{ // Acknowledge any wishbone accesses -- everything we did took only // one clock anyway. // @@ -167,72 +199,73 @@ module zipjiffies(i_clk, i_reset, i_ce, o_wb_ack <= 1'b0; else o_wb_ack <= i_wb_stb; + // }}} assign o_wb_data = r_counter; assign o_wb_stall = 1'b0; // Make verilator happy + // {{{ // verilator lint_off UNUSED wire unused; - assign unused = i_wb_cyc; + assign unused = &{ 1'b0, i_wb_cyc, i_wb_sel }; // verilator lint_on UNUSED + // }}} +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal properties +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// `ifdef FORMAL reg f_past_valid; initial f_past_valid = 1'b0; always @(posedge i_clk) f_past_valid <= 1'b1; - //////////////////////////////////////////////// - // + //////////////////////////////////////////////////////////////////////// // // Assumptions about our inputs + // {{{ + //////////////////////////////////////////////////////////////////////// // // - //////////////////////////////////////////////// - // - // Some basic WB assumtions - - // We will not start out in a wishbone cycle - initial assume(!i_wb_cyc); - - // Following any reset the cycle line will be low - always @(posedge i_clk) - if ((f_past_valid)&&($past(i_reset))) - assume(!i_wb_cyc); + // One basic WB assumtion // Anytime the stb is high, the cycle line must also be high always @(posedge i_clk) assume((!i_wb_stb)||(i_wb_cyc)); - - - //////////////////////////////////////////////// - // - // - // Assumptions about our bus outputs + // }}} + //////////////////////////////////////////////////////////////////////// // + // Assertions about our bus outputs + // {{{ + //////////////////////////////////////////////////////////////////////// // - //////////////////////////////////////////////// // // We never stall the bus always @(*) assert(!o_wb_stall); + // We always ack every transaction on the following clock always @(posedge i_clk) if ((f_past_valid)&&(!$past(i_reset))&&($past(i_wb_stb))) + begin assert(o_wb_ack); - else + end else assert(!o_wb_ack); - - - //////////////////////////////////////////////// - // + // }}} + /////////////////////////////////////////////////////////////////////// // // Assumptions about our internal state and our outputs + // {{{ + //////////////////////////////////////////////////////////////////////// // // - //////////////////////////////////////////////// - // always @(posedge i_clk) if ((f_past_valid)&&($past(i_reset))) begin @@ -247,8 +280,9 @@ module zipjiffies(i_clk, i_reset, i_ce, always @(posedge i_clk) if ((f_past_valid)&&(!$past(i_reset))&&($past(i_wb_stb)) &&($past(i_wb_we))) + begin assert(new_set); - else + end else assert(!new_set); // @@ -277,7 +311,7 @@ module zipjiffies(i_clk, i_reset, i_ce, &&($past(r_counter)==$past(int_when))) begin assert((o_int)||(!$past(int_set))); - assert((!int_set)||($past(new_set))); + // assert((!int_set)||($past(new_set))); // !!!!! end always @(posedge i_clk) @@ -286,8 +320,9 @@ module zipjiffies(i_clk, i_reset, i_ce, always @(posedge i_clk) if ((!f_past_valid)||($past(i_reset))) + begin assert(!o_int); - else if (($past(new_set))&&($past(till_wb) < 0)) + end else if (($past(new_set))&&($past(till_wb) < 0)) assert(o_int); always @(posedge i_clk) @@ -296,6 +331,7 @@ module zipjiffies(i_clk, i_reset, i_ce, ||($past(till_wb[BW-1])) ||($past(till_wb == 0)))) assert(int_when == $past(int_when)); - // + // }}} `endif +// }}} endmodule diff --git a/rtl/cpu/zipsystem.v b/rtl/cpu/zipsystem.v index 06b4f15..a8b16a6 100644 --- a/rtl/cpu/zipsystem.v +++ b/rtl/cpu/zipsystem.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: zipsystem.v -// +// {{{ // Project: Zip CPU -- a small, lightweight, RISC CPU soft core // // Purpose: This portion of the ZIP CPU implements a number of soft @@ -62,9 +62,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -81,184 +81,322 @@ // for a copy. // // License: GPL, v3, as defined and found on www.gnu.org, +// }}} // http://www.gnu.org/licenses/gpl.html -// +// {{{ // //////////////////////////////////////////////////////////////////////////////// // // `default_nettype none -// +// }}} `include "cpudefs.v" // -`define RESET_BIT 6 -`define STEP_BIT 8 -`define HALT_BIT 10 -`define CLEAR_CACHE_BIT 11 -// -// While I hate adding delays to any bus access, this next delay is required -// to make timing close in my Basys-3 design. -`define DELAY_DBG_BUS -// -// `define DELAY_EXT_BUS -// -// -// If space is tight, you might not wish to have your performance and -// accounting counters, so let's make those optional here -// Without this flag, Slice LUT count is 3315 (ZipSystem),2432 (ZipCPU) -// When including counters, -// Slice LUTs ZipSystem ZipCPU -// With Counters 3315 2432 -// Without Counters 2796 2046 - -// -// Now, where am I placing all of my peripherals? -`define PERIPHBASE 32'hc0000000 -`define INTCTRL 8'h0 // -`define WATCHDOG 8'h1 // Interrupt generates reset signal -`define BUSWATCHDOG 8'h2 // Sets IVEC[0] -`define CTRINT 8'h3 // Sets IVEC[5] -`define TIMER_A 8'h4 // Sets IVEC[4] -`define TIMER_B 8'h5 // Sets IVEC[3] -`define TIMER_C 8'h6 // Sets IVEC[2] -`define JIFFIES 8'h7 // Sets IVEC[1] - - -`ifdef INCLUDE_ACCOUNTING_COUNTERS -`define MSTR_TASK_CTR 8'h08 -`define MSTR_MSTL_CTR 8'h09 -`define MSTR_PSTL_CTR 8'h0a -`define MSTR_INST_CTR 8'h0b -`define USER_TASK_CTR 8'h0c -`define USER_MSTL_CTR 8'h0d -`define USER_PSTL_CTR 8'h0e -`define USER_INST_CTR 8'h0f -`endif - -`ifdef OPT_MMU -`define MMU_ADDR 8'h80 -`endif - -// Although I have a hole at 5'h2, the DMA controller requires four wishbone -// addresses, therefore we place it by itself and expand our address bus -// width here by another bit. -`define DMAC 5'h10 - -// `define RTC_CLOCK 32'hc0000008 // A global something -// `define BITREV 32'hc0000003 -// -// DBGCTRL -// 10 HALT -// 9 HALT(ED) -// 8 STEP (W=1 steps, and returns to halted) -// 7 INTERRUPT-FLAG -// 6 RESET_FLAG -// ADDRESS: -// 5 PERIPHERAL-BIT -// [4:0] REGISTER-ADDR -// DBGDATA -// read/writes internal registers -// +// Debug address space: +// {{{ +// 0-15 0x0? Supervisors registers +// 16-31 0x1? User registers +// 32-63 0x2? CPU command register (singular, one register only) +// 64 0x40 Interrupt controller +// 65 0x41 Watchdog +// 66 0x42 Bus watchdog +// 67 0x43 CTRINT +// 68 0x44 Timer A +// 69 0x45 Timer B +// 70 0x46 Timer C +// 71 0x47 Jiffies +// 72 0x48 Master task counter +// 73 0x49 Master task counter +// 74 0x4a Master task counter +// 75 0x4b Master instruction counter +// 76 0x4c User task counter +// 77 0x4d User task counter +// 78 0x4e User task counter +// 79 0x4f User instruction counter +// 80 0x50 DMAC Control/Status register +// 81 0x51 DMAC Length +// 82 0x52 DMAC Read (source) address +// 83 0x53 DMAC Write (destination) address // +/////// /////// /////// /////// // +// (MMU ... is not available via debug bus) +// }}} +module zipsystem #( + // {{{ + parameter RESET_ADDRESS=32'h1000_0000, + ADDRESS_WIDTH=30, `ifdef OPT_TRADITIONAL_PFCACHE -`define LGICACHE_DEFAULT 10 + LGICACHE=10, `else -`define LGICACHE_DEFAULT 0 + LGICACHE=0, `endif -// `ifdef OPT_DCACHE -`define LGDCACHE_DEFAULT 10 + // Set to zero for no data cache + LGDCACHE=10, `else -`define LGDCACHE_DEFAULT 0 + LGDCACHE=0, `endif -module zipsystem(i_clk, i_reset, - // Wishbone master interface from the CPU - o_wb_cyc, o_wb_stb, o_wb_we, o_wb_addr, o_wb_data, o_wb_sel, - i_wb_stall, i_wb_ack, i_wb_data, i_wb_err, - // Incoming interrupts - i_ext_int, - // Our one outgoing interrupt - o_ext_int, - // Wishbone slave interface for debugging purposes - i_dbg_cyc, i_dbg_stb, i_dbg_we, i_dbg_addr, i_dbg_data, - i_dbg_sel, - o_dbg_stall, o_dbg_ack, o_dbg_data -`ifdef DEBUG_SCOPE - , o_cpu_debug -`endif - ); - parameter RESET_ADDRESS=32'h1000_0000, ADDRESS_WIDTH=30, - LGICACHE=`LGICACHE_DEFAULT, - LGDCACHE=`LGDCACHE_DEFAULT; // Set to zero for no data cache - parameter [0:0] START_HALTED=1; - parameter EXTERNAL_INTERRUPTS=1, + parameter [0:0] START_HALTED=1, + parameter EXTERNAL_INTERRUPTS=1, `ifdef OPT_MULTIPLY - IMPLEMENT_MPY = `OPT_MULTIPLY; + OPT_MPY = `OPT_MULTIPLY, `else - IMPLEMENT_MPY = 0; + OPT_MPY = 0, `endif - parameter [0:0] `ifdef OPT_DIVIDE - IMPLEMENT_DIVIDE=1, + parameter [0:0] OPT_DIV=1, `else - IMPLEMENT_DIVIDE=0, + parameter [0:0] OPT_DIV=0, `endif `ifdef OPT_IMPLEMENT_FPU - IMPLEMENT_FPU=1, + parameter [0:0] OPT_FPU=1, +`else + parameter [0:0] OPT_FPU=0, +`endif + parameter [0:0] OPT_LOCK=1, +`ifdef INCLUDE_DMA_CONTROLLER + parameter [0:0] OPT_DMA=1, +`else + parameter [0:0] OPT_DMA=0, +`endif + parameter [0:0] OPT_LOWPOWER=0, +`ifdef INCLUDE_ACCOUNTING_COUNTERS + localparam [0:0] OPT_ACCOUNTING = 1'b1, `else - IMPLEMENT_FPU=0, + localparam [0:0] OPT_ACCOUNTING = 1'b0, `endif - IMPLEMENT_LOCK=1; - parameter RESET_DURATION = 0; - localparam // Derived parameters - PHYSICAL_ADDRESS_WIDTH=ADDRESS_WIDTH, - PAW=ADDRESS_WIDTH, + // Bus delay options + // {{{ + // While I hate adding delays to any bus access, this next + // delay is required to make timing close in my Basys-3 design. + parameter [0:0] DELAY_DBG_BUS = 1'b1, + // + parameter [0:0] DELAY_EXT_BUS = 1'b0, + // }}} + parameter RESET_DURATION = 0, + // Short-cut names + // {{{ + localparam // Derived parameters + // PHYSICAL_ADDRESS_WIDTH=ADDRESS_WIDTH, + PAW=ADDRESS_WIDTH, `ifdef OPT_MMU - VIRTUAL_ADDRESS_WIDTH=30, + VIRTUAL_ADDRESS_WIDTH=30, `else - VIRTUAL_ADDRESS_WIDTH=PAW, + VIRTUAL_ADDRESS_WIDTH=PAW, `endif - LGTLBSZ = 6, - VAW=VIRTUAL_ADDRESS_WIDTH; - - localparam AW=ADDRESS_WIDTH; - input wire i_clk, i_reset; - // Wishbone master - output wire o_wb_cyc, o_wb_stb, o_wb_we; - output wire [(PAW-1):0] o_wb_addr; - output wire [31:0] o_wb_data; - output wire [3:0] o_wb_sel; - input wire i_wb_stall, i_wb_ack; - input wire [31:0] i_wb_data; - input wire i_wb_err; - // Incoming interrupts - input wire [(EXTERNAL_INTERRUPTS-1):0] i_ext_int; - // Outgoing interrupt - output wire o_ext_int; - // Wishbone slave - input wire i_dbg_cyc, i_dbg_stb, i_dbg_we, i_dbg_addr; - input wire [31:0] i_dbg_data; - input wire [3:0] i_dbg_sel; - output wire o_dbg_ack; - output wire o_dbg_stall; - output wire [31:0] o_dbg_data; - // + // LGTLBSZ = 6, // Log TLB size + // VAW=VIRTUAL_ADDRESS_WIDTH, + + // localparam AW=ADDRESS_WIDTH, + // }}} + // Peripheral addresses + // {{{ + // Verilator lint_off UNUSED + // These values may (or may not) be used, depending on whether + // or not the respective peripheral is included in the + // CPU. + localparam [31:0] PERIPHBASE = 32'hc0000000, + localparam [7:0] INTCTRL = 8'h0, + localparam [7:0] WATCHDOG = 8'h1, // Interrupt generates reset signal + localparam [7:0] BUSWATCHDOG = 8'h2, // Sets IVEC[0] + localparam [7:0] CTRINT = 8'h3, // Sets IVEC[5] + localparam [7:0] TIMER_A = 8'h4, // Sets IVEC[4] + localparam [7:0] TIMER_B = 8'h5, // Sets IVEC[3] + localparam [7:0] TIMER_C = 8'h6, // Sets IVEC[2] + localparam [7:0] JIFFIES = 8'h7, // Sets IVEC[1] + // Accounting counter addresses + localparam [7:0] MSTR_TASK_CTR = 8'h08, + localparam [7:0] MSTR_MSTL_CTR = 8'h09, + localparam [7:0] MSTR_PSTL_CTR = 8'h0a, + localparam [7:0] MSTR_INST_CTR = 8'h0b, + localparam [7:0] USER_TASK_CTR = 8'h0c, + localparam [7:0] USER_MSTL_CTR = 8'h0d, + localparam [7:0] USER_PSTL_CTR = 8'h0e, + localparam [7:0] USER_INST_CTR = 8'h0f, + // The MMU + localparam [7:0] MMU_ADDR = 8'h80, + // DMA controller (DMAC) + // Although I have a hole at 5'h2, the DMA controller requires + // four wishbone addresses, therefore we place it by itself + // and expand our address bus width here by another bit. + localparam [7:0] DMAC_ADDR = 8'h10, + // Verilator lint_on UNUSED + // }}} + // Debug bit allocations + // {{{ + // DBGCTRL + // 10 HALT + // 9 HALT(ED) + // 8 STEP (W=1 steps, and returns to halted) + // 7 INTERRUPT-FLAG + // 6 RESET_FLAG + // ADDRESS: + // 5 PERIPHERAL-BIT + // [4:0] REGISTER-ADDR + // DBGDATA + // read/writes internal registers + // + localparam RESET_BIT = 6, + localparam STEP_BIT = 8, + localparam HALT_BIT = 10, + localparam CLEAR_CACHE_BIT = 11 + // }}} + // }}} + ) ( + // {{{ + input wire i_clk, i_reset, + // Wishbone master interface from the CPU + // {{{ + output wire o_wb_cyc, o_wb_stb, o_wb_we, + output wire [(PAW-1):0] o_wb_addr, + output wire [31:0] o_wb_data, + output wire [3:0] o_wb_sel, + input wire i_wb_stall, i_wb_ack, + input wire [31:0] i_wb_data, + input wire i_wb_err, + // }}} + // Incoming interrupts + input wire [(EXTERNAL_INTERRUPTS-1):0] i_ext_int, + // Our one outgoing interrupt + output wire o_ext_int, + // Wishbone slave interface for debugging purposes + // {{{ + input wire i_dbg_cyc, i_dbg_stb, i_dbg_we, + input wire [6:0] i_dbg_addr, + input wire [31:0] i_dbg_data, + input wire [3:0] i_dbg_sel, + output wire o_dbg_stall, + output wire o_dbg_ack, + output wire [31:0] o_dbg_data + // }}} `ifdef DEBUG_SCOPE - output wire [31:0] o_cpu_debug; + , output wire [31:0] o_cpu_debug `endif - + // }}} + ); + + // Local declarations + // {{{ + localparam [1:0] DBG_ADDR_CPU = 2'b00, + DBG_ADDR_CTRL= 2'b01, + DBG_ADDR_SYS = 2'b10; wire [31:0] ext_idata; - // Handle our interrupt vector generation/coordination wire [14:0] main_int_vector, alt_int_vector; wire ctri_int, tma_int, tmb_int, tmc_int, jif_int, dmac_int; wire mtc_int, moc_int, mpc_int, mic_int, utc_int, uoc_int, upc_int, uic_int; + wire [31:0] actr_data; + wire actr_ack, actr_stall; + + // + wire cpu_clken; + // + // + wire sys_cyc, sys_stb, sys_we; + wire [7:0] sys_addr; + wire [(PAW-1):0] cpu_addr; + wire [31:0] sys_data; + reg [31:0] sys_idata; + reg sys_ack; + wire sys_stall; + + wire sel_counter, sel_timer, sel_pic, sel_apic, + sel_watchdog, sel_bus_watchdog, sel_dmac, sel_mmus; + + wire dbg_cyc, dbg_stb, dbg_we, dbg_stall; + wire [6:0] dbg_addr; + wire [31:0] dbg_idata; + reg [31:0] dbg_odata; + reg dbg_ack; + wire [3:0] dbg_sel; + wire no_dbg_err; + + wire cpu_break, dbg_cmd_write; + reg cmd_reset, cmd_halt, cmd_step, cmd_clear_pf_cache, + reset_hold, cpu_halt; + wire [2:0] cpu_dbg_cc; + + wire cpu_reset; + wire cpu_dbg_stall; + wire [31:0] pic_data; + wire [31:0] cpu_status; + wire cpu_gie; + + wire wdt_stall, wdt_ack, wdt_reset; + wire [31:0] wdt_data; + reg wdbus_ack; + reg [(PAW-1):0] r_wdbus_data; + wire [31:0] wdbus_data; + wire reset_wdbus_timer, wdbus_int; + + wire cpu_op_stall, cpu_pf_stall, cpu_i_count; + + wire dmac_stb, dc_err; + wire [31:0] dmac_data; + wire dmac_stall, dmac_ack; + wire dc_cyc, dc_stb, dc_we, dc_stall, dc_ack; + wire [31:0] dc_data; + wire [(PAW-1):0] dc_addr; + wire cpu_gbl_cyc; + wire [31:0] dmac_int_vec; + + wire ctri_sel, ctri_stall, ctri_ack; + wire [31:0] ctri_data; + + wire tma_stall, tma_ack; + wire tmb_stall, tmb_ack; + wire tmc_stall, tmc_ack; + wire jif_stall, jif_ack; + wire [31:0] tma_data; + wire [31:0] tmb_data; + wire [31:0] tmc_data; + wire [31:0] jif_data; + + wire pic_interrupt, pic_stall, pic_ack; + + wire cpu_gbl_stb, cpu_lcl_cyc, cpu_lcl_stb, + cpu_we, cpu_dbg_we; + wire [31:0] cpu_data, cpu_idata; + wire [3:0] cpu_sel, mmu_sel; + wire cpu_stall, cpu_ack, cpu_err; + wire [31:0] cpu_dbg_data; + + wire ext_stall, ext_ack; + wire mmu_cyc, mmu_stb, mmu_we, mmu_stall, mmu_ack, mmu_err; + wire mmus_stall, mmus_ack; + wire [PAW-1:0] mmu_addr; + wire [31:0] mmu_data, mmu_idata, mmus_data; + wire cpu_miss; + + wire mmu_cpu_stall, mmu_cpu_ack; + wire [31:0] mmu_cpu_idata; + + // The wires associated with cache snooping + wire pf_return_stb, pf_return_we, pf_return_cachable; + wire [19:0] pf_return_v, pf_return_p; + wire ext_cyc, ext_stb, ext_we, ext_err; + wire [(PAW-1):0] ext_addr; + wire [31:0] ext_odata; + wire [3:0] ext_sel; + reg [31:0] tmr_data; + reg [2:0] w_ack_idx, ack_idx; + reg last_sys_stb; + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Handle our interrupt vector generation/coordination + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + // Main interrupt vector + // {{{ assign main_int_vector[5:0] = { ctri_int, tma_int, tmb_int, tmc_int, jif_int, dmac_int }; - generate if (EXTERNAL_INTERRUPTS < 9) assign main_int_vector[14:6] = { {(9-EXTERNAL_INTERRUPTS){1'b0}}, @@ -266,111 +404,128 @@ module zipsystem(i_clk, i_reset, else assign main_int_vector[14:6] = i_ext_int[8:0]; endgenerate - generate - if (EXTERNAL_INTERRUPTS <= 9) -`ifdef INCLUDE_ACCOUNTING_COUNTERS + // }}} + + // The alternate interrupt vector + // {{{ + generate if (EXTERNAL_INTERRUPTS <= 9 && OPT_ACCOUNTING) + begin assign alt_int_vector = { 7'h00, mtc_int, moc_int, mpc_int, mic_int, utc_int, uoc_int, upc_int, uic_int }; -`else + end else if (EXTERNAL_INTERRUPTS <= 9) // && !OPT_ACCOUNTING + begin assign alt_int_vector = { 15'h00 }; -`endif - else -`ifdef INCLUDE_ACCOUNTING_COUNTERS - if (EXTERNAL_INTERRUPTS >= 15) + end else if (OPT_ACCOUNTING && EXTERNAL_INTERRUPTS >= 15) + begin assign alt_int_vector = { i_ext_int[14:8], mtc_int, moc_int, mpc_int, mic_int, utc_int, uoc_int, upc_int, uic_int }; - else + end else if (OPT_ACCOUNTING) + begin + assign alt_int_vector = { {(7-(EXTERNAL_INTERRUPTS-9)){1'b0}}, i_ext_int[(EXTERNAL_INTERRUPTS-1):9], mtc_int, moc_int, mpc_int, mic_int, utc_int, uoc_int, upc_int, uic_int }; -`else - if (EXTERNAL_INTERRUPTS >= 24) + end else if (!OPT_ACCOUNTING && EXTERNAL_INTERRUPTS >= 24) + begin + assign alt_int_vector = { i_ext_int[(EXTERNAL_INTERRUPTS-1):9] }; - else + end else begin assign alt_int_vector = { {(15-(EXTERNAL_INTERRUPTS-9)){1'b0}}, i_ext_int[(EXTERNAL_INTERRUPTS-1):9] }; -`endif - endgenerate + end endgenerate + // }}} + + // Make Verilator happy + // {{{ + generate if (!OPT_ACCOUNTING) + begin : UNUSED_ACCOUNTING + // Verilator lint_off UNUSED + wire unused_ctrs; + assign unused_ctrs = &{ 1'b0, + moc_int, mpc_int, mic_int, mtc_int, + uoc_int, upc_int, uic_int, utc_int, + cpu_gie, cpu_op_stall, cpu_pf_stall, cpu_i_count }; + // Verilator lint_on UNUSED + end endgenerate + // }}} + // }}} + //////////////////////////////////////////////////////////////////////// + // // Delay the debug port by one clock, to meet timing requirements - wire dbg_cyc, dbg_stb, dbg_we, dbg_addr, dbg_stall; - wire [31:0] dbg_idata, dbg_odata; - reg dbg_ack; - wire [3:0] dbg_sel; - wire no_dbg_err; -`ifdef DELAY_DBG_BUS - // Make verilator happy - // verilator lint_off UNUSED - // verilator lint_on UNUSED - wire dbg_err; - assign dbg_err = 1'b0; - busdelay #(1,32) wbdelay(i_clk, i_reset, - i_dbg_cyc, i_dbg_stb, i_dbg_we, i_dbg_addr, i_dbg_data, 4'hf, - o_dbg_stall, o_dbg_ack, o_dbg_data, no_dbg_err, - dbg_cyc, dbg_stb, dbg_we, dbg_addr, dbg_idata, dbg_sel, - dbg_stall, dbg_ack, dbg_odata, dbg_err); -`else - assign dbg_cyc = i_dbg_cyc; - assign dbg_stb = i_dbg_stb; - assign dbg_we = i_dbg_we; - assign dbg_addr = i_dbg_addr; - assign dbg_idata = i_dbg_data; - assign o_dbg_ack = dbg_ack; - assign o_dbg_stall = dbg_stall; - assign o_dbg_data = dbg_odata; - assign dbg_sel = 4'b1111; - assign no_dbg_err = 1'b0; -`endif - + // {{{ + //////////////////////////////////////////////////////////////////////// // + generate if (DELAY_DBG_BUS) + begin : DELAY_THE_DEBUG_BUS + // {{{ + wire dbg_err; + assign dbg_err = 1'b0; + busdelay #( + // {{{ + .AW(7),.DW(32) + // }}} + ) wbdelay( + // {{{ + i_clk, i_reset, + i_dbg_cyc, i_dbg_stb, i_dbg_we, i_dbg_addr, i_dbg_data, + 4'hf, + o_dbg_stall, o_dbg_ack, o_dbg_data, no_dbg_err, + dbg_cyc, dbg_stb, dbg_we, dbg_addr, dbg_idata, dbg_sel, + dbg_stall, dbg_ack, dbg_odata, dbg_err + // }}} + ); + // }}} + end else begin : NO_DEBUG_BUS_DELAY + // {{{ + assign dbg_cyc = i_dbg_cyc; + assign dbg_stb = i_dbg_stb; + assign dbg_we = i_dbg_we; + assign dbg_addr = i_dbg_addr; + assign dbg_idata = i_dbg_data; + assign o_dbg_ack = dbg_ack; + assign o_dbg_stall = dbg_stall; + assign o_dbg_data = dbg_odata; + assign dbg_sel = 4'b1111; + assign no_dbg_err = 1'b0; + // }}} + end endgenerate + // }}} + //////////////////////////////////////////////////////////////////////// // + // Bus decoding, sel_* + // {{{ + //////////////////////////////////////////////////////////////////////// // - wire sys_cyc, sys_stb, sys_we; - wire [7:0] sys_addr; - wire [(PAW-1):0] cpu_addr; - wire [31:0] sys_data; - reg [31:0] sys_idata; - reg sys_ack; - wire sys_stall; - - wire sel_counter, sel_timer, sel_pic, sel_apic, - sel_watchdog, sel_bus_watchdog, sel_dmac, sel_mmus; // - assign sel_pic = (sys_stb)&&(sys_addr == `INTCTRL); - assign sel_watchdog = (sys_stb)&&(sys_addr == `WATCHDOG); - assign sel_bus_watchdog= (sys_stb)&&(sys_addr == `BUSWATCHDOG); - assign sel_apic = (sys_stb)&&(sys_addr == `CTRINT); - assign sel_timer = (sys_stb)&&(sys_addr[7:2] == 6'h1); - assign sel_counter = (sys_stb)&&(sys_addr[7:3] == 5'h1); - assign sel_dmac = (sys_stb)&&(sys_addr[7:4] == 4'h1); + + assign sel_pic = (sys_stb)&&(sys_addr == INTCTRL); + assign sel_watchdog = (sys_stb)&&(sys_addr == WATCHDOG); + assign sel_bus_watchdog= (sys_stb)&&(sys_addr == BUSWATCHDOG); + assign sel_apic = (sys_stb)&&(sys_addr == CTRINT); + assign sel_timer = (sys_stb)&&(sys_addr[7:2]==TIMER_A[7:2]); + assign sel_counter = (sys_stb)&&(sys_addr[7:3]==MSTR_TASK_CTR[7:3]); + assign sel_dmac = (sys_stb)&&(sys_addr[7:4] ==DMAC_ADDR[7:4]); assign sel_mmus = (sys_stb)&&(sys_addr[7]); + // }}} + //////////////////////////////////////////////////////////////////////// // // The external debug interface + // {{{ + //////////////////////////////////////////////////////////////////////// // - // We offer only a limited interface here, requiring a pre-register - // write to set the local address. This interface allows access to - // the Zip System on a debug basis only, and not to the rest of the - // wishbone bus. Further, to access these registers, the control - // register must first be accessed to both stop the CPU and to - // set the following address in question. Hence all accesses require - // two accesses: write the address to the control register (and halt - // the CPU if not halted), then read/write the data from the data - // register. // - wire cpu_break, dbg_cmd_write; - reg cmd_reset, cmd_halt, cmd_step, cmd_clear_pf_cache, - reset_hold, cpu_halt; - reg [5:0] cmd_addr; - wire [3:0] cpu_dbg_cc; - assign dbg_cmd_write = (dbg_stb)&&(dbg_we)&&(!dbg_addr); - // - // Always start us off with an initial reset + + assign dbg_cmd_write = (dbg_stb)&&(dbg_we) + &&(dbg_addr[6:5] == DBG_ADDR_CTRL); // + // cmd_halt, reset_hold: Always start us off with an initial reset + // {{{ generate if (RESET_DURATION > 0) begin : INITIAL_RESET_HOLD @@ -395,7 +550,7 @@ module zipsystem(i_clk, i_reset, if (i_reset) cmd_halt <= START_HALTED; else if (dbg_cmd_write) - cmd_halt <= ((dbg_idata[`HALT_BIT])&&(!dbg_idata[`STEP_BIT])); + cmd_halt <= ((dbg_idata[HALT_BIT])&&(!dbg_idata[STEP_BIT])); end else begin @@ -406,80 +561,111 @@ module zipsystem(i_clk, i_reset, cmd_halt = START_HALTED; end endgenerate + // }}} + // cmd_reset + // {{{ initial cmd_reset = 1'b1; always @(posedge i_clk) - cmd_reset <= ((dbg_cmd_write)&&(dbg_idata[`RESET_BIT])) + if (i_reset) + cmd_reset <= 1'b1; + else + cmd_reset <= ((dbg_cmd_write)&&(dbg_idata[RESET_BIT])) ||(wdt_reset) || reset_hold; - // + // }}} + + // cpu_halt + // {{{ initial cpu_halt = START_HALTED; always @(posedge i_clk) if (i_reset) - cpu_halt <= cmd_halt; + cpu_halt <= START_HALTED; else if (cmd_reset) cpu_halt <= cmd_halt; else if (dbg_cmd_write) - cpu_halt <= ((dbg_idata[`HALT_BIT])&&(!dbg_idata[`STEP_BIT])); + cpu_halt <= ((dbg_idata[HALT_BIT])&&(!dbg_idata[STEP_BIT])); else if ((cmd_step)||(cpu_break)) cpu_halt <= 1'b1; + // }}} + // cmd_clear_pf_cache + // {{{ initial cmd_clear_pf_cache = 1'b1; always @(posedge i_clk) - cmd_clear_pf_cache <= (dbg_cmd_write)&&(dbg_idata[`CLEAR_CACHE_BIT]); - // + if (i_reset) + cmd_clear_pf_cache <= 1'b1; + else + cmd_clear_pf_cache <= (dbg_cmd_write)&&(dbg_idata[CLEAR_CACHE_BIT]); + // }}} + + // cmd_step + // {{{ initial cmd_step = 1'b0; always @(posedge i_clk) - cmd_step <= (dbg_cmd_write)&&(dbg_idata[`STEP_BIT]); - // - initial cmd_addr = 6'h0; - always @(posedge i_clk) - if (dbg_cmd_write) - cmd_addr <= dbg_idata[5:0]; + if (i_reset) + cmd_step <= 1'b0; + else + cmd_step <= (dbg_cmd_write)&&(dbg_idata[STEP_BIT]); + // }}} - wire cpu_reset; assign cpu_reset = (cmd_reset); - wire cpu_dbg_stall; - wire [31:0] pic_data; - wire [31:0] cmd_data; + // cpu_status + // {{{ // Values: - // 0x0003f -> cmd_addr mask - // 0x00040 -> reset - // 0x00080 -> PIC interrrupt pending - // 0x00100 -> cmd_step - // 0x00200 -> cmd_stall - // 0x00400 -> cmd_halt - // 0x00800 -> cmd_clear_pf_cache - // 0x01000 -> cc.sleep - // 0x02000 -> cc.gie - // 0x04000 -> External (PIC) interrupt line is high + // 0xxxxx_0000 -> External interrupt lines + // + // 0x0_8000 -> cpu_break (CPU is halted on an error) + // 0x0_4000 -> Supervisor bus error + // 0x0_2000 -> cc.gie + // 0x0_1000 -> cc.sleep + // 0x0_0800 -> cmd_clear_pf_cache + // 0x0_0400 -> [HALT request, cmd_halt] + // 0x0_0200 -> [CPU is halted] + // 0x0_0100 -> [UNUSED -- was cmd_step] + // + // 0x0_0080 -> PIC interrrupt pending + // 0x0_0040 -> reset + // 0x0_003f -> [UNUSED -- was cmd_addr mask] // Other external interrupts follow generate if (EXTERNAL_INTERRUPTS < 16) - assign cmd_data = { {(16-EXTERNAL_INTERRUPTS){1'b0}}, + assign cpu_status = { {(16-EXTERNAL_INTERRUPTS){1'b0}}, i_ext_int, - cpu_dbg_cc, // 4 bits + cpu_break, cpu_dbg_cc, // 4 bits 1'b0, cmd_halt, (!cpu_dbg_stall), 1'b0, - pic_data[15], cpu_reset, cmd_addr }; + pic_interrupt, cpu_reset, 6'h0 }; else - assign cmd_data = { i_ext_int[15:0], cpu_dbg_cc, + assign cpu_status = { i_ext_int[15:0], + cpu_break, cpu_dbg_cc, // 4 bits 1'b0, cmd_halt, (!cpu_dbg_stall), 1'b0, - pic_data[15], cpu_reset, cmd_addr }; + pic_interrupt, cpu_reset, 6'h0 }; endgenerate + // }}} - wire cpu_gie; assign cpu_gie = cpu_dbg_cc[1]; - + // }}} + //////////////////////////////////////////////////////////////////////// // // The WATCHDOG Timer + // {{{ + //////////////////////////////////////////////////////////////////////// + // // - wire wdt_stall, wdt_ack, wdt_reset; - wire [31:0] wdt_data; ziptimer #(32,31,0) - watchdog(i_clk, cpu_reset, !cmd_halt, - sys_cyc, (sys_stb)&&(sel_watchdog), sys_we, - sys_data, - wdt_stall, wdt_ack, wdt_data, wdt_reset); + watchdog( + // {{{ + .i_clk(i_clk), .i_reset(cpu_reset), + .i_ce(!cmd_halt), + .i_wb_cyc(sys_cyc), + .i_wb_stb((sys_stb)&&(sel_watchdog)), + .i_wb_we(sys_we), .i_wb_data(sys_data), .i_wb_sel(4'hf), + .o_wb_stall(wdt_stall), + .o_wb_ack(wdt_ack), + .o_wb_data(wdt_data), + .o_int(wdt_reset) + // }}} + ); // // Position two, a second watchdog timer--this time for the wishbone @@ -487,155 +673,225 @@ module zipsystem(i_clk, i_reset, // configuration, it cannot be configured and all bus accesses must // take less than the number written to this register. // - reg wdbus_ack; - reg [(PAW-1):0] r_wdbus_data; - wire [31:0] wdbus_data; - wire reset_wdbus_timer, wdbus_int; assign reset_wdbus_timer = (!o_wb_cyc)||(o_wb_stb)||(i_wb_ack); - wbwatchdog #(14) watchbus(i_clk,(cpu_reset)||(reset_wdbus_timer), - 14'h2000, wdbus_int); + + wbwatchdog #(14) + watchbus( + // {{{ + i_clk,(cpu_reset)||(reset_wdbus_timer), + 14'h2000, wdbus_int + // }}} + ); + initial r_wdbus_data = 0; always @(posedge i_clk) - if ((wdbus_int)||(cpu_err)) - r_wdbus_data <= o_wb_addr; + if ((wdbus_int)||(cpu_err)) + r_wdbus_data <= o_wb_addr; + assign wdbus_data = { {(32-PAW){1'b0}}, r_wdbus_data }; initial wdbus_ack = 1'b0; always @(posedge i_clk) - wdbus_ack <= ((sys_cyc)&&(sys_stb)&&(sel_bus_watchdog)); - - // Counters -- for performance measurement and accounting - // - // Here's the stuff we'll be counting .... + if (i_reset || !sys_cyc) + wdbus_ack <= 1'b0; + else + wdbus_ack <= (sys_stb)&&(sel_bus_watchdog); + // }}} + //////////////////////////////////////////////////////////////////////// // - wire cpu_op_stall, cpu_pf_stall, cpu_i_count; - -`ifdef INCLUDE_ACCOUNTING_COUNTERS + // Performance counters + // {{{ + //////////////////////////////////////////////////////////////////////// // - // The master counters will, in general, not be reset. They'll be used - // for an overall counter. // - // Master task counter - wire mtc_stall, mtc_ack; - wire [31:0] mtc_data; - zipcounter mtask_ctr(i_clk, 1'b0, (!cpu_halt), sys_cyc, - (sys_stb)&&(sel_counter)&&(sys_addr[2:0] == 3'b000), - sys_we, sys_data, - mtc_stall, mtc_ack, mtc_data, mtc_int); - // Master Operand Stall counter - wire moc_stall, moc_ack; - wire [31:0] moc_data; - zipcounter mmstall_ctr(i_clk,1'b0, (cpu_op_stall), sys_cyc, - (sys_stb)&&(sel_counter)&&(sys_addr[2:0] == 3'b001), - sys_we, sys_data, - moc_stall, moc_ack, moc_data, moc_int); + // Here's the stuff we'll be counting .... + // + generate if (OPT_ACCOUNTING) + begin : ACCOUNTING_COUNTERS + // {{{ + // Local definitions + // {{{ + // Verilator lint_off UNUSED + wire mtc_stall, mtc_ack; + wire moc_stall, moc_ack; + wire mpc_stall, mpc_ack; + wire mic_stall, mic_ack; + wire utc_stall, utc_ack; + wire uoc_stall, uoc_ack; + wire upc_stall, upc_ack; + wire uic_stall, uic_ack; + // Verilator lint_on UNUSED + wire [31:0] mtc_data; + wire [31:0] moc_data; + wire [31:0] mpc_data; + wire [31:0] mic_data; + wire [31:0] utc_data; + wire [31:0] uoc_data; + wire [31:0] upc_data; + wire [31:0] uic_data; + reg [31:0] r_actr_data; + // }}} + + // Master counters + // {{{ + // The master counters will, in general, not be reset. They'll + // be used for an overall counter. + // + // Master task counter + zipcounter + mtask_ctr( + // {{{ + i_clk, 1'b0, (!cpu_halt), sys_cyc, + (sys_stb)&&(sel_counter)&&(sys_addr[2:0] == 3'b000), + sys_we, sys_data, + mtc_stall, mtc_ack, mtc_data, mtc_int + // }}} + ); - // Master PreFetch-Stall counter - wire mpc_stall, mpc_ack; - wire [31:0] mpc_data; - zipcounter mpstall_ctr(i_clk,1'b0, (cpu_pf_stall), sys_cyc, - (sys_stb)&&(sel_counter)&&(sys_addr[2:0] == 3'b010), - sys_we, sys_data, - mpc_stall, mpc_ack, mpc_data, mpc_int); + // Master Operand Stall counter + zipcounter + mmstall_ctr( + // {{{ + i_clk,1'b0, (cpu_op_stall), sys_cyc, + (sys_stb)&&(sel_counter)&&(sys_addr[2:0] == 3'b001), + sys_we, sys_data, + moc_stall, moc_ack, moc_data, moc_int + // }}} + ); - // Master Instruction counter - wire mic_stall, mic_ack; - wire [31:0] mic_data; - zipcounter mins_ctr(i_clk,1'b0, (cpu_i_count), sys_cyc, - (sys_stb)&&(sel_counter)&&(sys_addr[2:0] == 3'b011), + // Master PreFetch-Stall counter + zipcounter + mpstall_ctr( + // {{{ + i_clk,1'b0, (cpu_pf_stall), sys_cyc, + (sys_stb)&&(sel_counter)&&(sys_addr[2:0] == 3'b010), sys_we, sys_data, - mic_stall, mic_ack, mic_data, mic_int); + mpc_stall, mpc_ack, mpc_data, mpc_int + // }}} + ); - // - // The user counters are different from those of the master. They will - // be reset any time a task is given control of the CPU. - // - // User task counter - wire utc_stall, utc_ack; - wire [31:0] utc_data; - zipcounter utask_ctr(i_clk,1'b0, (!cpu_halt)&&(cpu_gie), sys_cyc, - (sys_stb)&&(sel_counter)&&(sys_addr[2:0] == 3'b100), - sys_we, sys_data, - utc_stall, utc_ack, utc_data, utc_int); + // Master Instruction counter + zipcounter + mins_ctr( + // {{{ + i_clk,1'b0, (cpu_i_count), sys_cyc, + (sys_stb)&&(sel_counter)&&(sys_addr[2:0] == 3'b011), + sys_we, sys_data, + mic_stall, mic_ack, mic_data, mic_int + // }}} + ); + // }}} + // User counters + // {{{ + // The user counters are different from those of the master. + // They will be reset any time a task is given control of the + // CPU. + // + // User task counter + zipcounter + utask_ctr( + // {{{ + i_clk,1'b0, (!cpu_halt)&&(cpu_gie), sys_cyc, + (sys_stb)&&(sel_counter)&&(sys_addr[2:0] == 3'b100), + sys_we, sys_data, + utc_stall, utc_ack, utc_data, utc_int + // }}} + ); - // User Op-Stall counter - wire uoc_stall, uoc_ack; - wire [31:0] uoc_data; - zipcounter umstall_ctr(i_clk,1'b0, (cpu_op_stall)&&(cpu_gie), sys_cyc, + // User Op-Stall counter + zipcounter + umstall_ctr( + // {{{ + i_clk,1'b0, (cpu_op_stall)&&(cpu_gie), sys_cyc, (sys_stb)&&(sel_counter)&&(sys_addr[2:0] == 3'b101), sys_we, sys_data, - uoc_stall, uoc_ack, uoc_data, uoc_int); + uoc_stall, uoc_ack, uoc_data, uoc_int + // }}} + ); - // User PreFetch-Stall counter - wire upc_stall, upc_ack; - wire [31:0] upc_data; - zipcounter upstall_ctr(i_clk,1'b0, (cpu_pf_stall)&&(cpu_gie), sys_cyc, + // User PreFetch-Stall counter + zipcounter + upstall_ctr( + // {{{ + i_clk,1'b0, (cpu_pf_stall)&&(cpu_gie), sys_cyc, (sys_stb)&&(sel_counter)&&(sys_addr[2:0] == 3'b110), sys_we, sys_data, - upc_stall, upc_ack, upc_data, upc_int); + upc_stall, upc_ack, upc_data, upc_int + // }}} + ); - // User instruction counter - wire uic_stall, uic_ack; - wire [31:0] uic_data; - zipcounter uins_ctr(i_clk,1'b0, (cpu_i_count)&&(cpu_gie), sys_cyc, + // User instruction counter + zipcounter + uins_ctr( + // {{{ + i_clk,1'b0, (cpu_i_count)&&(cpu_gie), sys_cyc, (sys_stb)&&(sel_counter)&&(sys_addr[2:0] == 3'b111), sys_we, sys_data, - uic_stall, uic_ack, uic_data, uic_int); - - // A little bit of pre-cleanup (actr = accounting counters) - wire actr_stall, actr_ack; - reg [31:0] actr_data; - assign actr_ack = sel_counter; - assign actr_stall = 1'b0; - always @(*) - begin - case(sys_addr[2:0]) - 3'h0: actr_data = mtc_data; - 3'h1: actr_data = moc_data; - 3'h2: actr_data = mpc_data; - 3'h3: actr_data = mic_data; - 3'h4: actr_data = utc_data; - 3'h5: actr_data = uoc_data; - 3'h6: actr_data = upc_data; - 3'h7: actr_data = uic_data; - endcase - end -`else // INCLUDE_ACCOUNTING_COUNTERS - reg actr_ack; - wire actr_stall; - wire [31:0] actr_data; - assign actr_stall = 1'b0; - assign actr_data = 32'h0000; - - assign mtc_int = 1'b0; - assign moc_int = 1'b0; - assign mpc_int = 1'b0; - assign mic_int = 1'b0; - assign utc_int = 1'b0; - assign uoc_int = 1'b0; - assign upc_int = 1'b0; - assign uic_int = 1'b0; + uic_stall, uic_ack, uic_data, uic_int + // }}} + ); + // }}} - always @(posedge i_clk) - actr_ack <= sel_counter; -`endif // INCLUDE_ACCOUNTING_COUNTERS + // A little bit of pre-cleanup (actr = accounting counters) + assign actr_ack = sel_counter; + assign actr_stall = 1'b0; + // actr_data + // {{{ + always @(*) + begin + case(sys_addr[2:0]) + 3'h0: r_actr_data = mtc_data; + 3'h1: r_actr_data = moc_data; + 3'h2: r_actr_data = mpc_data; + 3'h3: r_actr_data = mic_data; + 3'h4: r_actr_data = utc_data; + 3'h5: r_actr_data = uoc_data; + 3'h6: r_actr_data = upc_data; + 3'h7: r_actr_data = uic_data; + endcase + end + + assign actr_data = r_actr_data; + // }}} + // }}} + end else begin : NO_ACCOUNTING_COUNTERS + // {{{ + + assign actr_stall = 1'b0; + assign actr_data = 32'h0000; + + assign mtc_int = 1'b0; + assign moc_int = 1'b0; + assign mpc_int = 1'b0; + assign mic_int = 1'b0; + assign utc_int = 1'b0; + assign uoc_int = 1'b0; + assign upc_int = 1'b0; + assign uic_int = 1'b0; + + assign actr_ack = sel_counter; + // }}} + end endgenerate + // }}} + //////////////////////////////////////////////////////////////////////// // // The DMA Controller + // {{{ + //////////////////////////////////////////////////////////////////////// + // // - wire dmac_stb, dc_err; - wire [31:0] dmac_data; - wire dmac_stall, dmac_ack; - wire dc_cyc, dc_stb, dc_we, dc_stall, dc_ack; - wire [31:0] dc_data; - wire [(PAW-1):0] dc_addr; - wire cpu_gbl_cyc; - wire [31:0] dmac_int_vec; assign dmac_int_vec = { 1'b0, alt_int_vector, 1'b0, main_int_vector[14:1], 1'b0 }; assign dmac_stb = (sys_stb)&&(sel_dmac); -`ifdef INCLUDE_DMA_CONTROLLER - wbdmac #(PAW) dma_controller(i_clk, cpu_reset, + + generate if (OPT_DMA) + begin : DMA + // {{{ + wbdmac #(PAW) + dma_controller( + // {{{ + i_clk, cpu_reset, sys_cyc, dmac_stb, sys_we, sys_addr[1:0], sys_data, dmac_stall, dmac_ack, dmac_data, @@ -645,176 +901,279 @@ module zipsystem(i_clk, i_reset, // External device interrupts dmac_int_vec, // DMAC interrupt, for upon completion - dmac_int); -`else - reg r_dmac_ack; - initial r_dmac_ack = 1'b0; - always @(posedge i_clk) - r_dmac_ack <= (sys_cyc)&&(dmac_stb); - assign dmac_ack = r_dmac_ack; - assign dmac_data = 32'h000; - assign dmac_stall = 1'b0; - - assign dc_cyc = 1'b0; - assign dc_stb = 1'b0; - assign dc_we = 1'b0; - assign dc_addr = { (PAW) {1'b0} }; - assign dc_data = 32'h00; - - assign dmac_int = 1'b0; -`endif + dmac_int + // }}} + ); + // }}} + end else begin : NO_DMA + // {{{ + reg r_dmac_ack; - wire ctri_sel, ctri_stall, ctri_ack; - wire [31:0] ctri_data; - assign ctri_sel = (sys_stb)&&(sel_apic); -`ifdef INCLUDE_ACCOUNTING_COUNTERS - // - // Counter Interrupt controller - // - generate if (EXTERNAL_INTERRUPTS <= 9) - begin : ALT_PIC - icontrol #(8) ctri(i_clk, cpu_reset, sys_cyc, (ctri_sel), sys_we, - sys_data, 4'hf, ctri_stall, ctri_ack, ctri_data, - alt_int_vector[7:0], ctri_int); - end else begin : ALT_PIC - icontrol #(8+(EXTERNAL_INTERRUPTS-9)) - ctri(i_clk, cpu_reset, sys_cyc, (ctri_sel), sys_we, - sys_data, 4'hf, ctri_stall, ctri_ack, ctri_data, - alt_int_vector[(EXTERNAL_INTERRUPTS-2):0], - ctri_int); + initial r_dmac_ack = 1'b0; + always @(posedge i_clk) + if (i_reset) + r_dmac_ack <= 1'b0; + else + r_dmac_ack <= (sys_cyc)&&(dmac_stb); + assign dmac_ack = r_dmac_ack; + assign dmac_data = 32'h000; + assign dmac_stall = 1'b0; + + assign dc_cyc = 1'b0; + assign dc_stb = 1'b0; + assign dc_we = 1'b0; + assign dc_addr = { (PAW) {1'b0} }; + assign dc_data = 32'h00; + + assign dmac_int = 1'b0; + + // Make Verilator happy + // {{{ + // Verilator lint_off UNUSED + wire unused_dmac; + assign unused_dmac = &{ 1'b0, dc_err, dc_ack, + dc_stall, dmac_int_vec }; + // Verilator lint_on UNUSED + // }}} + // }}} end endgenerate + // }}} + //////////////////////////////////////////////////////////////////////// + // + // The alternate interrupt controller + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + assign ctri_sel = (sys_stb)&&(sel_apic); + generate if (OPT_ACCOUNTING) + begin : PIC_WITH_ACCOUNTING + // + // Interrupt controller + // + if (EXTERNAL_INTERRUPTS <= 9) + begin : ALT_PIC + icontrol #(8) + ctri( + // {{{ + .i_clk(i_clk), .i_reset(cpu_reset), + .i_wb_cyc(sys_cyc), .i_wb_stb(ctri_sel), + .i_wb_we(sys_we), .i_wb_data(sys_data), .i_wb_sel(4'hf), + .o_wb_stall(ctri_stall), .o_wb_ack(ctri_ack), + .o_wb_data(ctri_data), + .i_brd_ints(alt_int_vector[7:0]), .o_interrupt(ctri_int) + // }}} + ); + end else begin : ALT_PIC + icontrol #(8+(EXTERNAL_INTERRUPTS-9)) + ctri( + // {{{ + .i_clk(i_clk), .i_reset(cpu_reset), + .i_wb_cyc(sys_cyc), .i_wb_stb(ctri_sel), + .i_wb_we(sys_we), .i_wb_data(sys_data), + .i_wb_sel(4'hf), + .o_wb_stall(ctri_stall), + .o_wb_ack(ctri_ack), + .o_wb_data(ctri_data), + .i_brd_ints(alt_int_vector[(EXTERNAL_INTERRUPTS-2):0]), + .o_interrupt(ctri_int) + // }}} + ); + end + end else begin : PIC_WITHOUT_ACCOUNTING + + if (EXTERNAL_INTERRUPTS <= 9) + begin : ALT_PIC + assign ctri_stall = 1'b0; + assign ctri_data = 32'h0000; + assign ctri_int = 1'b0; + end else begin : ALT_PIC + icontrol #(EXTERNAL_INTERRUPTS-9) + ctri( + // {{{ + .i_clk(i_clk), .i_reset(cpu_reset), + .i_wb_cyc(sys_cyc), .i_wb_stb(ctri_sel), + .i_wb_we(sys_we), .i_wb_data(sys_data), + .i_wb_sel(4'hf), + .o_wb_stall(ctri_stall), + .o_wb_ack(ctri_ack), + .o_wb_data(ctri_data), + .i_brd_ints(alt_int_vector[(EXTERNAL_INTERRUPTS-10):0]), + .o_interrupt(ctri_int) + // }}} + ); + end -`else // INCLUDE_ACCOUNTING_COUNTERS - - generate if (EXTERNAL_INTERRUPTS <= 9) - begin : ALT_PIC - assign ctri_stall = 1'b0; - assign ctri_data = 32'h0000; - assign ctri_int = 1'b0; - end else begin : ALT_PIC - icontrol #(EXTERNAL_INTERRUPTS-9) - ctri(i_clk, cpu_reset, (ctri_sel), sys_we, - sys_data, ctri_stall, ctri_ack, ctri_data, - alt_int_vector[(EXTERNAL_INTERRUPTS-10):0], - ctri_int); end endgenerate -`endif // INCLUDE_ACCOUNTING_COUNTERS - + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Timers + // {{{ + //////////////////////////////////////////////////////////////////////// + // // // Timer A // - wire tma_stall, tma_ack; - wire [31:0] tma_data; - ziptimer timer_a(i_clk, cpu_reset, !cmd_halt, - sys_cyc, (sys_stb)&&(sel_timer)&&(sys_addr[1:0] == 2'b00), - sys_we, sys_data, - tma_stall, tma_ack, tma_data, tma_int); + ziptimer + timer_a( + // {{{ + .i_clk(i_clk), .i_reset(cpu_reset), .i_ce(!cmd_halt), + .i_wb_cyc(sys_cyc), + .i_wb_stb((sys_stb)&&(sel_timer)&&(sys_addr[1:0] == 2'b00)), + .i_wb_we(sys_we), .i_wb_data(sys_data), .i_wb_sel(4'hf), + .o_wb_stall(tma_stall), .o_wb_ack(tma_ack), + .o_wb_data(tma_data), + .o_int(tma_int) + // }}} + ); // // Timer B // - wire tmb_stall, tmb_ack; - wire [31:0] tmb_data; - ziptimer timer_b(i_clk, cpu_reset, !cmd_halt, - sys_cyc, (sys_stb)&&(sel_timer)&&(sys_addr[1:0] == 2'b01), - sys_we, sys_data, - tmb_stall, tmb_ack, tmb_data, tmb_int); + ziptimer timer_b( + // {{{ + .i_clk(i_clk), .i_reset(cpu_reset), .i_ce(!cmd_halt), + .i_wb_cyc(sys_cyc), + .i_wb_stb((sys_stb)&&(sel_timer)&&(sys_addr[1:0] == 2'b01)), + .i_wb_we(sys_we), .i_wb_data(sys_data), .i_wb_sel(4'hf), + .o_wb_stall(tmb_stall), .o_wb_ack(tmb_ack), + .o_wb_data(tmb_data), + .o_int(tmb_int) + // }}} + ); // // Timer C // - wire tmc_stall, tmc_ack; - wire [31:0] tmc_data; - ziptimer timer_c(i_clk, cpu_reset, !cmd_halt, - sys_cyc, (sys_stb)&&(sel_timer)&&(sys_addr[1:0]==2'b10), - sys_we, sys_data, - tmc_stall, tmc_ack, tmc_data, tmc_int); + ziptimer timer_c( + // {{{ + .i_clk(i_clk), .i_reset(cpu_reset), .i_ce(!cmd_halt), + .i_wb_cyc(sys_cyc), + .i_wb_stb((sys_stb)&&(sel_timer)&&(sys_addr[1:0] == 2'b10)), + .i_wb_we(sys_we), .i_wb_data(sys_data), .i_wb_sel(4'hf), + .o_wb_stall(tmc_stall), .o_wb_ack(tmc_ack), + .o_wb_data(tmc_data), + .o_int(tmc_int) + // }}} + ); // // JIFFIES // - wire jif_stall, jif_ack; - wire [31:0] jif_data; - zipjiffies jiffies(i_clk, cpu_reset, !cmd_halt, - sys_cyc, (sys_stb)&&(sel_timer)&&(sys_addr[1:0] == 2'b11), sys_we, - sys_data, - jif_stall, jif_ack, jif_data, jif_int); - + zipjiffies jiffies( + // {{{ + .i_clk(i_clk), .i_reset(cpu_reset), .i_ce(!cmd_halt), + .i_wb_cyc(sys_cyc), + .i_wb_stb((sys_stb)&&(sel_timer)&&(sys_addr[1:0] == 2'b11)), + .i_wb_we(sys_we), .i_wb_data(sys_data), .i_wb_sel(4'hf), + .o_wb_stall(jif_stall), .o_wb_ack(jif_ack), + .o_wb_data(jif_data), + .o_int(jif_int) + // }}} + ); + // }}} + //////////////////////////////////////////////////////////////////////// + // + // The main (programmable) interrupt controller peripheral + // {{{ + //////////////////////////////////////////////////////////////////////// // - // The programmable interrupt controller peripheral // - wire pic_interrupt, pic_stall, pic_ack; generate if (EXTERNAL_INTERRUPTS < 9) begin : MAIN_PIC - icontrol #(6+EXTERNAL_INTERRUPTS) pic(i_clk, cpu_reset, - sys_cyc, (sys_cyc)&&(sys_stb)&&(sel_pic),sys_we, - sys_data, 4'hf, pic_stall, pic_ack, pic_data, - main_int_vector[(6+EXTERNAL_INTERRUPTS-1):0], pic_interrupt); + icontrol #(6+EXTERNAL_INTERRUPTS) + pic( + // {{{ + i_clk, cpu_reset, + sys_cyc, (sys_cyc)&&(sys_stb)&&(sel_pic),sys_we, + sys_data, 4'hf, pic_stall, pic_ack, pic_data, + main_int_vector[(6+EXTERNAL_INTERRUPTS-1):0], + pic_interrupt + // }}} + ); end else begin : MAIN_PIC - icontrol #(15) pic(i_clk, cpu_reset, - sys_cyc, (sys_cyc)&&(sys_stb)&&(sel_pic),sys_we, - sys_data, 4'hf, pic_stall, pic_ack, pic_data, - main_int_vector[14:0], pic_interrupt); + icontrol #(15) + pic( + // {{{ + i_clk, cpu_reset, + sys_cyc, (sys_cyc)&&(sys_stb)&&(sel_pic),sys_we, + sys_data, 4'hf, pic_stall, pic_ack, pic_data, + main_int_vector[14:0], pic_interrupt + // }}} + ); end endgenerate - + // }}} + //////////////////////////////////////////////////////////////////////// // // The CPU itself + // {{{ + //////////////////////////////////////////////////////////////////////// // - wire cpu_gbl_stb, cpu_lcl_cyc, cpu_lcl_stb, - cpu_we, cpu_dbg_we; - wire [31:0] cpu_data, cpu_idata; - wire [3:0] cpu_sel, mmu_sel; - wire cpu_stall, cpu_ack, cpu_err; - wire [31:0] cpu_dbg_data; - assign cpu_dbg_we = ((dbg_cyc)&&(dbg_stb)&&(!cmd_addr[5]) - &&(dbg_we)&&(dbg_addr)); - zipcpu #( .RESET_ADDRESS(RESET_ADDRESS), - .ADDRESS_WIDTH(VIRTUAL_ADDRESS_WIDTH), - .LGICACHE(LGICACHE), - .OPT_LGDCACHE(LGDCACHE), - .IMPLEMENT_MPY(IMPLEMENT_MPY), - .IMPLEMENT_DIVIDE(IMPLEMENT_DIVIDE), - .IMPLEMENT_FPU(IMPLEMENT_FPU), - .IMPLEMENT_LOCK(IMPLEMENT_LOCK), - .WITH_LOCAL_BUS(1'b1) - ) - thecpu(i_clk, cpu_reset, pic_interrupt, - cpu_halt, cmd_clear_pf_cache, cmd_addr[4:0], cpu_dbg_we, - dbg_idata, cpu_dbg_stall, cpu_dbg_data, - cpu_dbg_cc, cpu_break, - cpu_gbl_cyc, cpu_gbl_stb, - cpu_lcl_cyc, cpu_lcl_stb, - cpu_we, cpu_addr, cpu_data, cpu_sel, - // Return values from the Wishbone bus - cpu_stall, cpu_ack, cpu_idata, cpu_err, - cpu_op_stall, cpu_pf_stall, cpu_i_count + // + assign cpu_dbg_we = ((dbg_cyc)&&(dbg_stb)&&(dbg_we) + &&(dbg_addr[6:5] == DBG_ADDR_CPU)); + + zipwb #( + // {{{ + .RESET_ADDRESS(RESET_ADDRESS), + .ADDRESS_WIDTH(VIRTUAL_ADDRESS_WIDTH), + .LGICACHE(LGICACHE), + .OPT_LGDCACHE(LGDCACHE), + .IMPLEMENT_MPY(OPT_MPY), + .IMPLEMENT_DIVIDE(OPT_DIV), + .IMPLEMENT_FPU(OPT_FPU), + .IMPLEMENT_LOCK(OPT_LOCK), + .WITH_LOCAL_BUS(1'b1) + // }}} + ) thecpu( + // {{{ + .i_clk(i_clk), .i_reset(cpu_reset), .i_interrupt(pic_interrupt), + .o_cpu_clken(cpu_clken), + // Debug interface + // {{{ + .i_halt(cpu_halt), .i_clear_cache(cmd_clear_pf_cache), + .i_dbg_wreg(dbg_addr[4:0]), .i_dbg_we(cpu_dbg_we), + .i_dbg_data(dbg_idata), + .i_dbg_rreg(dbg_addr[4:0]), + .o_dbg_stall(cpu_dbg_stall), + .o_dbg_reg(cpu_dbg_data), .o_dbg_cc(cpu_dbg_cc), + .o_break(cpu_break), + // }}} + // Wishbone bus interface + // {{{ + .o_wb_gbl_cyc(cpu_gbl_cyc), .o_wb_gbl_stb(cpu_gbl_stb), + .o_wb_lcl_cyc(cpu_lcl_cyc), .o_wb_lcl_stb(cpu_lcl_stb), + .o_wb_we(cpu_we), .o_wb_addr(cpu_addr), + .o_wb_data(cpu_data), .o_wb_sel(cpu_sel), + // Return values from the Wishbone bus + .i_wb_stall(cpu_stall), .i_wb_ack(cpu_ack), + .i_wb_data(cpu_idata), .i_wb_err(cpu_err), + // }}} + .o_op_stall(cpu_op_stall), .o_pf_stall(cpu_pf_stall), + .o_i_count(cpu_i_count) `ifdef DEBUG_SCOPE - , o_cpu_debug + , o_cpu_debug `endif - ); + // }}} + ); - wire ext_stall, ext_ack; - wire mmu_cyc, mmu_stb, mmu_we, mmu_stall, mmu_ack, mmu_err; - wire mmus_stall, mmus_ack; - wire [PAW-1:0] mmu_addr; - wire [31:0] mmu_data, mmu_idata, mmus_data; - - // Specific responses from the MMU - wire cpu_miss; + // }}} + //////////////////////////////////////////////////////////////////////// + // + // The (unused) MMU + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // // The mmu_cpu_ lines are the return bus lines from the MMU. They // are separate from the cpu_'s lines simply because either the sys_ // (local) bus or the mmu_cpu_ (global) bus might return a response to // the CPU, and the responses haven't been merged back together again // yet. - wire mmu_cpu_stall, mmu_cpu_ack; - wire [31:0] mmu_cpu_idata; - - // The wires associated with cache snooping - wire pf_return_stb, pf_return_we, pf_return_cachable; - wire [19:0] pf_return_v, pf_return_p; `ifdef OPT_MMU // Ok ... here's the MMU @@ -839,6 +1198,8 @@ module zipsystem(i_clk, i_reset, pf_return_cachable); `else + reg r_mmus_ack; + assign mmu_cyc = cpu_gbl_cyc; assign mmu_stb = cpu_gbl_stb; assign mmu_we = cpu_we; @@ -850,10 +1211,14 @@ module zipsystem(i_clk, i_reset, assign mmu_cpu_idata = mmu_idata; assign mmu_cpu_stall = mmu_stall; assign mmu_cpu_ack = mmu_ack; - reg r_mmus_ack; + initial r_mmus_ack = 1'b0; always @(posedge i_clk) + if (i_reset) + r_mmus_ack <= 1'b0; + else r_mmus_ack <= (sys_stb)&&(sys_addr[7]); + assign mmus_ack = r_mmus_ack; assign mmus_stall = 1'b0; assign mmus_data = 32'h0; @@ -864,6 +1229,7 @@ module zipsystem(i_clk, i_reset, assign pf_return_we = 0; assign pf_return_cachable = 0; `endif + // // Responses from the MMU still need to be merged/muxed back together // with the responses from the local bus assign cpu_ack = ((cpu_lcl_cyc)&&(sys_ack)) @@ -877,12 +1243,14 @@ module zipsystem(i_clk, i_reset, // integrated into the CPU, they are unused. Here we tell Verilator // not to be surprised that these lines are unused: - // verilator lint_off UNUSED - wire [(3+1+20+20-1):0] mmu_unused; - assign mmu_unused = { pf_return_stb, pf_return_we, - pf_return_p, pf_return_v, pf_return_cachable, - cpu_miss }; - // verilator lint_on UNUSED + // }}} + //////////////////////////////////////////////////////////////////////// + // + // The internal sys bus + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // // Now, arbitrate the bus ... first for the local peripherals // For the debugger to have access to the local system bus, the @@ -894,86 +1262,22 @@ module zipsystem(i_clk, i_reset, // and one of two other things. Either // ((cpu_halt)&&(!cpu_dbg_stall)) the CPU is completely halted, // or - // (!cmd_addr[5]) we are trying to read a CPU register + // (!dbg_addr[5]) we are trying to read a CPU register // while in motion. Let the user beware that, // by not waiting for the CPU to fully halt, // his results may not be what he expects. // - wire sys_dbg_cyc = ((dbg_cyc)&&(!cpu_lcl_cyc)&&(dbg_addr)) - &&(cmd_addr[5]); - assign sys_cyc = (cpu_lcl_cyc)||(sys_dbg_cyc); + assign sys_cyc = (cpu_lcl_cyc)||(dbg_cyc); assign sys_stb = (cpu_lcl_cyc) ? (cpu_lcl_stb) - : ((dbg_stb)&&(dbg_addr)&&(cmd_addr[5])); + : ((dbg_stb)&&(dbg_addr[6:5]==DBG_ADDR_SYS)); assign sys_we = (cpu_lcl_cyc) ? cpu_we : dbg_we; - assign sys_addr= (cpu_lcl_cyc) ? cpu_addr[7:0] : { 3'h0, cmd_addr[4:0]}; + assign sys_addr= (cpu_lcl_cyc) ? cpu_addr[7:0] : { 3'h0, dbg_addr[4:0]}; assign sys_data= (cpu_lcl_cyc) ? cpu_data : dbg_idata; - // Return debug response values - // A return from one of three busses: - // CMD giving command instructions to the CPU (step, halt, etc) - // CPU-DBG-DATA internal register responses from within the CPU - // sys Responses from the front-side bus here in the ZipSystem - assign dbg_odata = (!dbg_addr) ? cmd_data - :((!cmd_addr[5])?cpu_dbg_data : sys_idata); - initial dbg_ack = 1'b0; - always @(posedge i_clk) - dbg_ack <= (dbg_stb)&&(!dbg_stall); - assign dbg_stall=(dbg_cyc)&&( - ((!sys_dbg_cyc)&&(cpu_dbg_stall)) - ||(sys_stall) - )&&(dbg_addr); - - // Now for the external wishbone bus - // Need to arbitrate between the flash cache and the CPU - // The way this works, though, the CPU will stall once the flash - // cache gets access to the bus--the CPU will be stuck until the - // flash cache is finished with the bus. - wire ext_cyc, ext_stb, ext_we, ext_err; - wire [(PAW-1):0] ext_addr; - wire [31:0] ext_odata; - wire [3:0] ext_sel; - wbpriarbiter #(32,PAW) dmacvcpu(i_clk, - mmu_cyc, mmu_stb, mmu_we, mmu_addr, mmu_data, mmu_sel, - mmu_stall, mmu_ack, mmu_err, - dc_cyc, dc_stb, dc_we, dc_addr, dc_data, 4'hf, - dc_stall, dc_ack, dc_err, - ext_cyc, ext_stb, ext_we, ext_addr, ext_odata, ext_sel, - ext_stall, ext_ack, ext_err); - assign mmu_idata = ext_idata; -/* - assign ext_cyc = mmu_cyc; - assign ext_stb = mmu_stb; - assign ext_we = mmu_we; - assign ext_odata= mmu_data; - assign ext_addr = mmu_addr; - assign ext_sel = mmu_sel; - assign mmu_ack = ext_ack; - assign mmu_stall= ext_stall; - assign mmu_err = ext_err; -*/ - -`ifdef DELAY_EXT_BUS - busdelay #(.AW(PAW),.DW(32),.DELAY_STALL(0)) extbus(i_clk, i_reset, - ext_cyc, ext_stb, ext_we, ext_addr, ext_odata, ext_sel, - ext_stall, ext_ack, ext_idata, ext_err, - o_wb_cyc, o_wb_stb, o_wb_we, o_wb_addr, o_wb_data, o_wb_sel, - i_wb_stall, i_wb_ack, i_wb_data, (i_wb_err)||(wdbus_int)); -`else - assign o_wb_cyc = ext_cyc; - assign o_wb_stb = ext_stb; - assign o_wb_we = ext_we; - assign o_wb_addr = ext_addr; - assign o_wb_data = ext_odata; - assign o_wb_sel = ext_sel; - assign ext_stall = i_wb_stall; - assign ext_ack = i_wb_ack; - assign ext_idata = i_wb_data; - assign ext_err = (i_wb_err)||(wdbus_int); -`endif - - reg [31:0] tmr_data; + // tmr_data + // {{{ always @(*) begin case(sys_addr[1:0]) @@ -985,33 +1289,20 @@ module zipsystem(i_clk, i_reset, // tmr_ack == sys_stb && sel_timer end + // }}} - reg [2:0] w_ack_idx, ack_idx; - always @(*) - begin - w_ack_idx = 0; - if (sel_mmus) w_ack_idx = w_ack_idx | 3'h0; - if (sel_watchdog) w_ack_idx = w_ack_idx | 3'h1; - if (sel_bus_watchdog) w_ack_idx = w_ack_idx | 3'h2; - if (sel_apic) w_ack_idx = w_ack_idx | 3'h3; - if (sel_timer) w_ack_idx = w_ack_idx | 3'h4; - if (sel_counter) w_ack_idx = w_ack_idx | 3'h5; - if (sel_dmac) w_ack_idx = w_ack_idx | 3'h6; - if (sel_pic) w_ack_idx = w_ack_idx | 3'h7; - end - - always @(posedge i_clk) - if (sys_stb) - ack_idx <= w_ack_idx; - - reg last_sys_stb; + // last_sys_stb + // {{{ initial last_sys_stb = 0; always @(posedge i_clk) if (i_reset) last_sys_stb <= 0; else last_sys_stb <= sys_stb; + // }}} + // sys_ack, sys_idata + // {{{ always @(posedge i_clk) begin case(ack_idx) @@ -1028,33 +1319,186 @@ module zipsystem(i_clk, i_reset, if (i_reset || !sys_cyc) sys_ack <= 1'b0; end + // }}} + // w_ack_idx + // {{{ + always @(*) + begin + w_ack_idx = 0; + if (sel_mmus) w_ack_idx = w_ack_idx | 3'h0; + if (sel_watchdog) w_ack_idx = w_ack_idx | 3'h1; + if (sel_bus_watchdog) w_ack_idx = w_ack_idx | 3'h2; + if (sel_apic) w_ack_idx = w_ack_idx | 3'h3; + if (sel_timer) w_ack_idx = w_ack_idx | 3'h4; + if (sel_counter) w_ack_idx = w_ack_idx | 3'h5; + if (sel_dmac) w_ack_idx = w_ack_idx | 3'h6; + if (sel_pic) w_ack_idx = w_ack_idx | 3'h7; + end + // }}} + + // ack_idx + // {{{ + always @(posedge i_clk) + if (sys_stb) + ack_idx <= w_ack_idx; + // }}} assign sys_stall = 1'b0; + + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Return debug response values + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + reg dbg_pre_ack; + reg [1:0] dbg_pre_addr; + reg [31:0] dbg_cpu_status; + + always @(posedge i_clk) + dbg_pre_addr <= dbg_addr[6:5]; + + always @(posedge i_clk) + dbg_cpu_status <= cpu_status; + + initial dbg_pre_ack = 1'b0; + always @(posedge i_clk) + if (i_reset || !i_dbg_cyc) + dbg_pre_ack <= 1'b0; + else + dbg_pre_ack <= dbg_stb && !o_dbg_stall; + + // A return from one of three busses: + // CMD giving command instructions to the CPU (step, halt, etc) + // CPU-DBG-DATA internal register responses from within the CPU + // sys Responses from the front-side bus here in the ZipSystem + // assign dbg_odata = (!dbg_addr) ? cpu_status + // :((!cmd_addr[5])?cpu_dbg_data : sys_idata); + initial dbg_ack = 1'b0; + always @(posedge i_clk) + if (i_reset || !dbg_cyc) + dbg_ack <= 1'b0; + else + dbg_ack <= dbg_pre_ack; + + always @(posedge i_clk) + if (!OPT_LOWPOWER || (dbg_cyc && dbg_pre_ack)) + casez(dbg_pre_addr) + DBG_ADDR_CPU: dbg_odata <= cpu_dbg_data; + DBG_ADDR_CTRL: dbg_odata <= dbg_cpu_status; + // DBG_ADDR_SYS: + default: dbg_odata <= sys_idata; + endcase + + // assign dbg_stall = (!dbg_cmd_write || !cpu_dbg_stall) && dbg_we + // && (dbg_addr[6:5] == 2'b00); + assign dbg_stall = (cpu_dbg_stall && cpu_dbg_we) + ||(dbg_addr[6]==DBG_ADDR_SYS[1] && cpu_lcl_cyc); + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Arbitrate between CPU and DMA + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + // Now for the external wishbone bus + // Need to arbitrate between the flash cache and the CPU + // The way this works, though, the CPU will stall once the flash + // cache gets access to the bus--the CPU will be stuck until the + // flash cache is finished with the bus. + wbpriarbiter #(32,PAW) + dmacvcpu( + // {{{ + i_clk, + mmu_cyc, mmu_stb, mmu_we, mmu_addr, mmu_data, mmu_sel, + mmu_stall, mmu_ack, mmu_err, + dc_cyc, dc_stb, dc_we, dc_addr, dc_data, 4'hf, + dc_stall, dc_ack, dc_err, + ext_cyc, ext_stb, ext_we, ext_addr, ext_odata, ext_sel, + ext_stall, ext_ack, ext_err + // }}} + ); + assign mmu_idata = ext_idata; +/* + assign ext_cyc = mmu_cyc; + assign ext_stb = mmu_stb; + assign ext_we = mmu_we; + assign ext_odata= mmu_data; + assign ext_addr = mmu_addr; + assign ext_sel = mmu_sel; + assign mmu_ack = ext_ack; + assign mmu_stall= ext_stall; + assign mmu_err = ext_err; +*/ + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Delay access to the external bus by one clock (if necessary) + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + generate if (DELAY_EXT_BUS) + begin : DELAY_EXTERNAL_BUS + // {{{ + busdelay #( + // {{{ + .AW(PAW), + .DW(32), + .DELAY_STALL(0) + // }}} + ) extbus( + // {{{ + i_clk, i_reset, + ext_cyc, ext_stb, ext_we, ext_addr, ext_odata, ext_sel, + ext_stall, ext_ack, ext_idata, ext_err, + o_wb_cyc, o_wb_stb, o_wb_we, o_wb_addr, o_wb_data, + o_wb_sel, + i_wb_stall, i_wb_ack, i_wb_data, (i_wb_err)||(wdbus_int) + // }}} + ); + // }}} + end else begin : NO_EXTERNAL_BUS_DELAY + // {{{ + assign o_wb_cyc = ext_cyc; + assign o_wb_stb = ext_stb; + assign o_wb_we = ext_we; + assign o_wb_addr = ext_addr; + assign o_wb_data = ext_odata; + assign o_wb_sel = ext_sel; + assign ext_stall = i_wb_stall; + assign ext_ack = i_wb_ack; + assign ext_idata = i_wb_data; + assign ext_err = (i_wb_err)||(wdbus_int); + // }}} + end endgenerate + // }}} + assign o_ext_int = (cmd_halt) && (!cpu_stall); // Make verilator happy + // {{{ // verilator lint_off UNUSED wire unused; - assign unused = &{ 1'b0, pic_ack, pic_stall, + assign unused = &{ 1'b0, dbg_addr[5:0], + pic_ack, pic_stall, cpu_clken, tma_ack, tma_stall, tmb_ack, tmb_stall, tmc_ack, tmc_stall, jif_ack, jif_stall, no_dbg_err, dbg_sel, sel_mmus, ctri_ack, ctri_stall, mmus_stall, dmac_stall, wdt_ack, wdt_stall, actr_ack, actr_stall, wdbus_ack, i_dbg_sel, - moc_ack, mtc_ack, mic_ack, mpc_ack, - uoc_ack, utc_ack, uic_ack, upc_ack, - moc_stall, mtc_stall, mic_stall, mpc_stall, - uoc_stall, utc_stall, uic_stall, upc_stall }; -`ifndef INCLUDE_ACCOUNTING_COUNTERS - wire [11:0] unused_ctrs; - assign unused_ctrs = { - moc_int, mpc_int, mic_int, mtc_int, - uoc_int, upc_int, uic_int, utc_int, - cpu_gie, cpu_op_stall, cpu_pf_stall, cpu_i_count }; -`endif -`ifndef INCLUDE_DMA_CONTROLLER - wire [34:0] unused_dmac; - assign unused_dmac = { dc_err, dc_ack, dc_stall, dmac_int_vec }; -`endif + // moc_ack, mtc_ack, mic_ack, mpc_ack, + // uoc_ack, utc_ack, uic_ack, upc_ack, + // moc_stall, mtc_stall, mic_stall, mpc_stall, + // uoc_stall, utc_stall, uic_stall, upc_stall, + // Unused MMU pins + pf_return_stb, pf_return_we, pf_return_p, pf_return_v, + pf_return_cachable, cpu_miss }; // verilator lint_on UNUSED + // }}} endmodule diff --git a/rtl/cpu/ziptimer.v b/rtl/cpu/ziptimer.v index b527302..a49b6ed 100644 --- a/rtl/cpu/ziptimer.v +++ b/rtl/cpu/ziptimer.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: ziptimer.v -// +// {{{ // Project: Zip CPU -- a small, lightweight, RISC CPU soft core // // Purpose: A lighter weight implementation of the Zip Timer. @@ -44,9 +44,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015,2017-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -61,135 +61,187 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // // `default_nettype none -// -module ziptimer(i_clk, i_reset, i_ce, - i_wb_cyc, i_wb_stb, i_wb_we, i_wb_data, - o_wb_stall, o_wb_ack, o_wb_data, - o_int); - parameter BW = 32, VW = (BW-1), RELOADABLE=1; - input wire i_clk, i_reset, i_ce; - // Wishbone inputs - input wire i_wb_cyc, i_wb_stb, i_wb_we; - input wire [(BW-1):0] i_wb_data; - // Wishbone outputs - output wire o_wb_stall; - output reg o_wb_ack; - output wire [(BW-1):0] o_wb_data; - // Interrupt line - output reg o_int; - +// }}} +module ziptimer #( + // {{{ + parameter BW = 32, VW = (BW-1), + parameter [0:0] RELOADABLE = 1 + // }}} + ) ( + // {{{ + input wire i_clk, i_reset, i_ce, + // Wishbone inputs + input wire i_wb_cyc, i_wb_stb, i_wb_we, + input wire [BW-1:0] i_wb_data, + input wire [BW/8-1:0] i_wb_sel, + // Wishbone outputs + output wire o_wb_stall, + output reg o_wb_ack, + output wire [BW-1:0] o_wb_data, + // Interrupt line + output reg o_int + // }}} + ); + + // Local declarations + // {{{ reg r_running; reg r_zero = 1'b1; reg [(VW-1):0] r_value; wire wb_write; - assign wb_write = ((i_wb_stb)&&(i_wb_we)); wire auto_reload; wire [(VW-1):0] interval_count; + // }}} + + assign wb_write = ((i_wb_stb)&&(i_wb_we)); + // r_running + // {{{ initial r_running = 1'b0; always @(posedge i_clk) - if (i_reset) - r_running <= 1'b0; - else if (wb_write) - r_running <= (|i_wb_data[(VW-1):0]); - else if ((r_zero)&&(!auto_reload)) - r_running <= 1'b0; - + if (i_reset) + r_running <= 1'b0; + else if (wb_write) + r_running <= (|i_wb_data[(VW-1):0]); + else if ((r_zero)&&(!auto_reload)) + r_running <= 1'b0; + // }}} + + // r_auto_reload, r_interval_count + // {{{ generate if (RELOADABLE != 0) begin + // {{{ reg r_auto_reload; reg [(VW-1):0] r_interval_count; + // r_auto_reload + // {{{ initial r_auto_reload = 1'b0; - always @(posedge i_clk) - if (i_reset) - r_auto_reload <= 1'b0; - else if (wb_write) - r_auto_reload <= (i_wb_data[(BW-1)]) + if (i_reset) + r_auto_reload <= 1'b0; + else if (wb_write) + r_auto_reload <= (i_wb_data[(BW-1)]) &&(|i_wb_data[(VW-1):0]); + // }}} assign auto_reload = r_auto_reload; + // r_interval_count + // {{{ // If setting auto-reload mode, and the value to other // than zero, set the auto-reload value always @(posedge i_clk) - if (wb_write) + if (i_reset) + r_interval_count <= 0; + else if (wb_write) r_interval_count <= i_wb_data[(VW-1):0]; + // }}} + assign interval_count = r_interval_count; - end else begin + // }}} + end else begin : NO_AUTO_RELOAD + // {{{ assign auto_reload = 1'b0; assign interval_count = 0; + // }}} end endgenerate + // }}} - + // r_value + // {{{ initial r_value = 0; always @(posedge i_clk) - if (i_reset) - r_value <= 0; - else if (wb_write) - r_value <= i_wb_data[(VW-1):0]; - else if ((i_ce)&&(r_running)) - begin - if (!r_zero) - r_value <= r_value - 1'b1; - else if (auto_reload) - r_value <= interval_count; - end - + if (i_reset) + r_value <= 0; + else if (wb_write) + r_value <= i_wb_data[(VW-1):0]; + else if ((i_ce)&&(r_running)) + begin + if (!r_zero) + r_value <= r_value - 1'b1; + else if (auto_reload) + r_value <= interval_count; + end + // }}} + + // r_zero + // {{{ always @(posedge i_clk) - if (i_reset) + if (i_reset) + r_zero <= 1'b1; + else if (wb_write) + r_zero <= (i_wb_data[(VW-1):0] == 0); + else if ((r_running)&&(i_ce)) + begin + if (r_value == { {(VW-1){1'b0}}, 1'b1 }) r_zero <= 1'b1; - else if (wb_write) - r_zero <= (i_wb_data[(VW-1):0] == 0); - else if ((r_running)&&(i_ce)) - begin - if (r_value == { {(VW-1){1'b0}}, 1'b1 }) - r_zero <= 1'b1; - else if ((r_zero)&&(auto_reload)) - r_zero <= 1'b0; - end + else if ((r_zero)&&(auto_reload)) + r_zero <= 1'b0; + end + // }}} + // o_int + // {{{ // Set the interrupt on our last tick, as we transition from one to // zero. initial o_int = 1'b0; always @(posedge i_clk) - if ((i_reset)||(wb_write)||(!i_ce)) - o_int <= 1'b0; - else // if (i_ce) - o_int <= (r_value == { {(VW-1){1'b0}}, 1'b1 }); - + if ((i_reset)||(wb_write)||(!i_ce)) + o_int <= 1'b0; + else // if (i_ce) + o_int <= (r_value == { {(VW-1){1'b0}}, 1'b1 }); + // }}} + + // o_wb_ack + // {{{ initial o_wb_ack = 1'b0; always @(posedge i_clk) o_wb_ack <= (!i_reset)&&(i_wb_stb); + // }}} assign o_wb_stall = 1'b0; + // o_wb_data + // {{{ generate if (VW < BW-1) assign o_wb_data = { auto_reload, {(BW-1-VW){1'b0}}, r_value }; else assign o_wb_data = { auto_reload, r_value }; endgenerate + // }}} // Make verilator happy + // {{{ // verilator lint_off UNUSED - wire [32:0] unused; - assign unused = { i_wb_cyc, i_wb_data }; + wire unused; + assign unused = &{ 1'b0, i_wb_cyc, i_wb_data, i_wb_sel }; // verilator lint_on UNUSED - + // }}} +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal properties +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// `ifdef FORMAL // The formal properties for this module are maintained elsewhere `endif +// }}} endmodule diff --git a/rtl/cpu/zipwb.v b/rtl/cpu/zipwb.v new file mode 100644 index 0000000..494c694 --- /dev/null +++ b/rtl/cpu/zipwb.v @@ -0,0 +1,545 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Filename: zipwb.v +// {{{ +// Project: Zip CPU -- a small, lightweight, RISC CPU soft core +// +// Purpose: This is the top level module holding the core of the Zip CPU +// together. The Zip CPU is designed to be as simple as possible. +// (actual implementation aside ...) The instruction set is about as +// RISC as you can get, with only 26 instruction types currently supported. +// (There are still 8-instruction Op-Codes reserved for floating point, +// and 5 which can be used for transactions not requiring registers.) +// Please see the accompanying spec.pdf file for a description of these +// instructions. +// +// All instructions are 32-bits wide. All bus accesses, both address and +// data, are 32-bits over a wishbone bus. +// +// The Zip CPU is fully pipelined with the following pipeline stages: +// +// 1. Prefetch, returns the instruction from memory. +// +// 2. Instruction Decode +// +// 3. Read Operands +// +// 4. Apply Instruction +// +// 4. Write-back Results +// +// Further information about the inner workings of this CPU, such as +// what causes pipeline stalls, may be found in the spec.pdf file. (The +// documentation within this file had become out of date and out of sync +// with the spec.pdf, so look to the spec.pdf for accurate and up to date +// information.) +// +// +// In general, the pipelining is controlled by three pieces of logic +// per stage: _ce, _stall, and _valid. _valid means that the stage +// holds a valid instruction. _ce means that the instruction from the +// previous stage is to move into this one, and _stall means that the +// instruction from the previous stage may not move into this one. +// The difference between these control signals allows individual stages +// to propagate instructions independently. In general, the logic works +// as: +// +// +// assign (n)_ce = (n-1)_valid && (!(n)_stall) +// +// +// always @(posedge i_clk) +// if ((i_reset)||(clear_pipeline)) +// (n)_valid = 0 +// else if (n)_ce +// (n)_valid = 1 +// else if (n+1)_ce +// (n)_valid = 0 +// +// assign (n)_stall = ( (n-1)_valid && ( pipeline hazard detection ) ) +// || ( (n)_valid && (n+1)_stall ); +// +// and ... +// +// always @(posedge i_clk) +// if (n)_ce +// (n)_variable = ... whatever logic for this stage +// +// Note that a stage can stall even if no instruction is loaded into +// it. +// +// Creator: Dan Gisselquist, Ph.D. +// Gisselquist Technology, LLC +// +//////////////////////////////////////////////////////////////////////////////// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ +// This program is free software (firmware): 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 MERCHANTIBILITY 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. (It's in the $(ROOT)/doc directory. Run make with no +// target there if the PDF file isn't present.) If not, see +// for a copy. +// }}} +// License: GPL, v3, as defined and found on www.gnu.org, +// {{{ +// http://www.gnu.org/licenses/gpl.html +// +// +//////////////////////////////////////////////////////////////////////////////// +// +// +`default_nettype none +// +`include "cpudefs.v" +// +// }}} +module zipwb #( + // {{{ + parameter [31:0] RESET_ADDRESS=32'h010_0000, + parameter ADDRESS_WIDTH=30, + LGICACHE=12, +`ifdef OPT_MULTIPLY + parameter IMPLEMENT_MPY = `OPT_MULTIPLY, +`else + parameter IMPLEMENT_MPY = 0, +`endif +`ifdef OPT_DIVIDE + parameter [0:0] IMPLEMENT_DIVIDE = 1, +`else + parameter [0:0] IMPLEMENT_DIVIDE = 0, +`endif +`ifdef OPT_IMPLEMENT_FPU + parameter [0:0] IMPLEMENT_FPU = 1, +`else + parameter [0:0] IMPLEMENT_FPU = 0, +`endif +`ifdef OPT_EARLY_BRANCHING + parameter [0:0] EARLY_BRANCHING = 1, +`else + parameter [0:0] EARLY_BRANCHING = 0, +`endif +`ifdef OPT_CIS + parameter [0:0] OPT_CIS = 1'b1, +`else + parameter [0:0] OPT_CIS = 1'b0, +`endif +`ifdef OPT_PIPELINED + parameter [0:0] OPT_PIPELINED = 1'b1, +`else + parameter [0:0] OPT_PIPELINED = 1'b0, +`endif + parameter [0:0] IMPLEMENT_LOCK=1, +`ifdef OPT_DCACHE + parameter OPT_LGDCACHE = 10, +`else + parameter OPT_LGDCACHE = 0, +`endif + + parameter [0:0] WITH_LOCAL_BUS = 1'b1, + localparam AW=ADDRESS_WIDTH +`ifdef FORMAL + , parameter F_LGDEPTH=8 +`endif + // }}} + ) ( + // {{{ + input wire i_clk, i_reset, i_interrupt, + output wire o_cpu_clken, + // Debug interface -- inputs + input wire i_halt, i_clear_cache, + input wire [4:0] i_dbg_wreg, + input wire i_dbg_we, + input wire [31:0] i_dbg_data, + input wire [4:0] i_dbg_rreg, + // Debug interface -- outputs + output wire o_dbg_stall, + output reg [31:0] o_dbg_reg, + output reg [2:0] o_dbg_cc, + output wire o_break, + // CPU interface to the wishbone bus + // Wishbone interface -- outputs + output wire o_wb_gbl_cyc, o_wb_gbl_stb, + output wire o_wb_lcl_cyc, o_wb_lcl_stb, o_wb_we, + output wire [(AW-1):0] o_wb_addr, + output wire [31:0] o_wb_data, + output wire [3:0] o_wb_sel, + // Wishbone interface -- inputs + input wire i_wb_stall, i_wb_ack, + input wire [31:0] i_wb_data, + input wire i_wb_err, + // Accounting outputs ... to help us count stalls and usage + output wire o_op_stall, + output wire o_pf_stall, + output wire o_i_count + // +`ifdef DEBUG_SCOPE + , output reg [31:0] o_debug +`endif + // }}} + ); + + // Declarations + // {{{ + localparam [0:0] OPT_DCACHE = (OPT_LGDCACHE > 0); +`ifdef OPT_PIPELINED_BUS_ACCESS + localparam [0:0] OPT_PIPELINED_BUS_ACCESS = (OPT_PIPELINED); +`else + localparam [0:0] OPT_PIPELINED_BUS_ACCESS = 1'b0; +`endif + localparam [0:0] OPT_MEMPIPE = OPT_PIPELINED_BUS_ACCESS; + localparam [0:0] OPT_LOCK=(IMPLEMENT_LOCK)&&(OPT_PIPELINED); +`ifdef OPT_NO_USERMODE + localparam [0:0] OPT_NO_USERMODE = 1'b1; +`else + localparam [0:0] OPT_NO_USERMODE = 1'b0; +`endif +`ifdef OPT_SINGLE_FETCH + localparam FETCH_LIMIT = (LGICACHE > 0) ? 4 : 1; +`else +`ifdef OPT_DOUBLE_FETCH + localparam FETCH_LIMIT = (LGICACHE > 0) ? 4 : 2; +`else + localparam FETCH_LIMIT = 4; +`endif // OPT_DOUBLE_FETCH +`endif // OPT_SINGLE_FETCH + + wire [31:0] cpu_debug; + + // Fetch + // {{{ + wire pf_new_pc, clear_icache, pf_ready; + wire [AW+1:0] pf_request_address; + wire [31:0] pf_instruction; + wire [AW+1:0] pf_instruction_pc; + wire pf_valid, pf_illegal; + // + wire [AW-1:0] pf_addr; + wire [31:0] pf_data; + wire pf_cyc, pf_stb, pf_we, pf_stall, pf_ack, pf_err; + // }}} + // Memory + // {{{ + wire clear_dcache, mem_ce, bus_lock; + wire [2:0] mem_op; + wire [31:0] mem_cpu_addr; + wire [AW+1:0] mem_lock_pc; + wire [31:0] mem_wdata, mem_data; + wire [4:0] mem_reg; + wire mem_busy, mem_rdbusy, mem_pipe_stalled, mem_valid, + mem_bus_err; + wire [4:0] mem_wreg; + wire [31:0] mem_result; + // + wire mem_stb_lcl, mem_stb_gbl, mem_cyc_lcl, mem_cyc_gbl; + wire [AW-1:0] mem_bus_addr; + wire mem_we, mem_stall, mem_ack, mem_err; + wire [3:0] mem_sel; + // }}} + // }}} + //////////////////////////////////////////////////////////////////////// + // + // The ZipCPU Core + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + zipcore #( + // {{{ + .RESET_ADDRESS(RESET_ADDRESS), + .ADDRESS_WIDTH(ADDRESS_WIDTH), + .IMPLEMENT_MPY(IMPLEMENT_MPY), + .IMPLEMENT_DIVIDE(IMPLEMENT_DIVIDE), + .IMPLEMENT_FPU(IMPLEMENT_FPU), + .OPT_EARLY_BRANCHING(EARLY_BRANCHING), + .OPT_CIS(OPT_CIS), + .OPT_NO_USERMODE(OPT_NO_USERMODE), + .OPT_PIPELINED(OPT_PIPELINED), + .OPT_PIPELINED_BUS_ACCESS(OPT_MEMPIPE), + .IMPLEMENT_LOCK(IMPLEMENT_LOCK) + // localparam [0:0] OPT_LOCK=(IMPLEMENT_LOCK)&&(OPT_PIPELINED); + // parameter [0:0] WITH_LOCAL_BUS = 1'b1; + // localparam AW=ADDRESS_WIDTH; + // localparam [(AW-1):0] RESET_BUS_ADDRESS = RESET_ADDRESS[(AW+1):2]; +`ifdef FORMAL + , .F_LGDEPTH(F_LGDEPTH) +`endif + // }}} + ) core ( + // {{{ + .i_clk(i_clk), .i_reset(i_reset), .i_interrupt(i_interrupt), + .o_clken(o_cpu_clken), + // Debug interface + // {{{ + .i_halt(i_halt), .i_clear_cache(i_clear_cache), + .i_dbg_wreg(i_dbg_wreg), .i_dbg_we(i_dbg_we), + .i_dbg_data(i_dbg_data), + .i_dbg_rreg(i_dbg_rreg), .o_dbg_stall(o_dbg_stall), + .o_dbg_reg(o_dbg_reg), .o_dbg_cc(o_dbg_cc), + .o_break(o_break), + // }}} + // Instruction fetch interface + // {{{ + .o_pf_new_pc(pf_new_pc), .o_clear_icache(clear_icache), + .o_pf_ready(pf_ready), + .o_pf_request_address(pf_request_address), + .i_pf_valid(pf_valid), .i_pf_illegal(pf_illegal), + .i_pf_instruction(pf_instruction), + .i_pf_instruction_pc(pf_instruction_pc), + // }}} + // Memory unit interface + // {{{ + .o_clear_dcache(clear_dcache), .o_mem_ce(mem_ce), + .o_bus_lock(bus_lock), + .o_mem_op(mem_op), .o_mem_addr(mem_cpu_addr), + .o_mem_data(mem_wdata), + .o_mem_lock_pc(mem_lock_pc), + .o_mem_reg(mem_reg), + .i_mem_busy(mem_busy), .i_mem_rdbusy(mem_rdbusy), + .i_mem_pipe_stalled(mem_pipe_stalled), + .i_mem_valid(mem_valid), + .i_bus_err(mem_bus_err), + .i_mem_wreg(mem_wreg), + .i_mem_result(mem_result), + // }}} + // Accounting/CPU usage interface + // {{{ + .o_op_stall(o_op_stall), .o_pf_stall(o_pf_stall), + .o_i_count(o_i_count), + // }}} + .o_debug(cpu_debug) + // }}} + ); + // }}} + // o_debug -- the debugging bus input + // {{{ +`ifdef DEBUG_SCOPE + assign o_debug = cpu_debug; +`else + // Verilator lint_off UNUSED + wire dbg_unused; + assign dbg_unused = &{ 1'b0, cpu_debug }; +`endif + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Instruction Fetch + // {{{ + //////////////////////////////////////////////////////////////////////// + // + generate if (FETCH_LIMIT <= 1) + begin : SINGLE_FETCH + + prefetch #(ADDRESS_WIDTH) + // {{{ + pf(i_clk, i_reset, + // CPU signals + pf_new_pc, clear_icache, pf_ready, + pf_request_address, + pf_valid, pf_illegal, pf_instruction, + pf_instruction_pc, + // Wishbone signals + pf_cyc, pf_stb, pf_we, pf_addr, pf_data, + pf_stall, pf_ack, pf_err, i_wb_data); + // }}} + end else if (FETCH_LIMIT == 2 || LGICACHE == 0) + begin : DBLFETCH + + dblfetch #(ADDRESS_WIDTH) + // {{{ + pf(i_clk, i_reset, + // CPU signals + pf_new_pc, clear_icache, pf_ready, + pf_request_address, + pf_valid, pf_illegal, pf_instruction, + pf_instruction_pc, + // Wishbone signals + pf_cyc, pf_stb, pf_we, pf_addr, pf_data, + pf_stall, pf_ack, pf_err, i_wb_data); + // }}} + end else begin : PFCACHE + + pfcache #(LGICACHE, ADDRESS_WIDTH) + // {{{ + pf(i_clk, i_reset, + // CPU signals + pf_new_pc, clear_icache, pf_ready, + pf_request_address, + pf_valid, pf_illegal, pf_instruction, + pf_instruction_pc, + // Wishbone signals + pf_cyc, pf_stb, pf_we, pf_addr, pf_data, + pf_stall, pf_ack, pf_err, i_wb_data); + // }}} + end endgenerate + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Memory Unit + // {{{ + //////////////////////////////////////////////////////////////////////// + // + generate if (OPT_DCACHE) + begin : DATA_CACHE + + dcache #( + // {{{ + .LGCACHELEN(OPT_LGDCACHE), + .ADDRESS_WIDTH(AW), + .LGNLINES(OPT_LGDCACHE-3), + .OPT_LOCAL_BUS(WITH_LOCAL_BUS), + .OPT_PIPE(OPT_MEMPIPE), + .OPT_LOCK(OPT_LOCK) +`ifdef FORMAL + , .OPT_FIFO_DEPTH(2) + , .F_LGDEPTH(F_LGDEPTH) +`endif + // }}} + ) mem(i_clk, i_reset, clear_dcache, + /// {{{ + // CPU interface + mem_ce, bus_lock, mem_op, mem_cpu_addr, mem_wdata, mem_reg, + mem_busy, mem_rdbusy, mem_pipe_stalled, + mem_valid, mem_bus_err, mem_wreg, mem_result, + // Wishbone interface + mem_cyc_gbl, mem_cyc_lcl, + mem_stb_gbl, mem_stb_lcl, + mem_we, mem_bus_addr, mem_data, mem_sel, + mem_stall, mem_ack, mem_err, i_wb_data + /// }}} + ); + end else if (OPT_PIPELINED_BUS_ACCESS) + begin : PIPELINED_MEM + + pipemem #( + // {{{ + .ADDRESS_WIDTH(AW), + .IMPLEMENT_LOCK(OPT_LOCK), + .WITH_LOCAL_BUS(WITH_LOCAL_BUS) +`ifdef FORMAL + , .OPT_MAXDEPTH(4'h3), + .F_LGDEPTH(F_LGDEPTH) +`endif + // }}} + ) domem(i_clk, i_reset, + /// {{{ + // CPU interface + mem_ce, bus_lock, mem_op, mem_cpu_addr, mem_wdata, mem_reg, + mem_busy, mem_rdbusy, mem_pipe_stalled, + mem_valid, mem_bus_err, mem_wreg, mem_result, + // Wishbone interface + mem_cyc_gbl, mem_cyc_lcl, + mem_stb_gbl, mem_stb_lcl, + mem_we, mem_bus_addr, mem_data, mem_sel, + mem_stall, mem_ack, mem_err, i_wb_data + // }}} + ); + end else begin : BARE_MEM + + memops #( + // {{{ + .ADDRESS_WIDTH(AW), + .IMPLEMENT_LOCK(OPT_LOCK), + .WITH_LOCAL_BUS(WITH_LOCAL_BUS) +`ifdef FORMAL + , .F_LGDEPTH(F_LGDEPTH) +`endif // F_LGDEPTH + // }}} + ) domem(i_clk, i_reset, + /// {{{ + // CPU interface + mem_ce, bus_lock, mem_op, mem_cpu_addr, mem_wdata, mem_reg, + mem_busy, mem_rdbusy, + mem_valid, mem_bus_err, mem_wreg, mem_result, + // Wishbone interface + mem_cyc_gbl, mem_cyc_lcl, + mem_stb_gbl, mem_stb_lcl, + mem_we, mem_bus_addr, mem_data, mem_sel, + mem_stall, mem_ack, mem_err, i_wb_data + // }}} + ); + + assign mem_pipe_stalled = mem_busy; + end endgenerate + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Bus arbiter + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // Either the prefetch or the instruction gets the memory bus, but + // never both under this arbitration scheme. + generate if (OPT_PIPELINED) + begin : PRIORITY_DATA + + wbdblpriarb #( + .DW(32), + .AW(AW) + ) pformem(i_clk, i_reset, + // {{{ + // Memory access to the arbiter, priority position + mem_cyc_gbl, mem_cyc_lcl, mem_stb_gbl, mem_stb_lcl, + mem_we, mem_bus_addr, mem_data, mem_sel, + mem_stall, mem_ack, mem_err, + // Prefetch access to the arbiter + // + // At a first glance, we might want something like: + // + // pf_cyc, 1'b0, pf_stb, 1'b0, pf_we, pf_addr, pf_data, 4'hf, + // + // However, we know that the prefetch will not generate + // any writes. Therefore, the write specific lines + // (mem_data and mem_sel) can be shared with the memory + // in order to ease timing and LUT usage. + pf_cyc,1'b0,pf_stb, 1'b0, pf_we, + pf_addr, mem_data, mem_sel, + pf_stall, pf_ack, pf_err, + // Common wires, in and out, of the arbiter + o_wb_gbl_cyc, o_wb_lcl_cyc, o_wb_gbl_stb, o_wb_lcl_stb, + o_wb_we, o_wb_addr, o_wb_data, o_wb_sel, + i_wb_stall, i_wb_ack, i_wb_err + // }}} + ); + + end else begin : PRIORITY_PREFETCH + + wbdblpriarb #( + .DW(32), .AW(AW) + ) pformem(i_clk, i_reset, + //{{{ + // Prefetch access to the arbiter, priority position + // + pf_cyc,1'b0,pf_stb, 1'b0, pf_we, + pf_addr, mem_data, mem_sel, + pf_stall, pf_ack, pf_err, + // Memory access to the arbiter + mem_cyc_gbl, mem_cyc_lcl, mem_stb_gbl, mem_stb_lcl, + mem_we, mem_bus_addr, mem_data, mem_sel, + mem_stall, mem_ack, mem_err, + // Common wires, in and out, of the arbiter + o_wb_gbl_cyc, o_wb_lcl_cyc, o_wb_gbl_stb, o_wb_lcl_stb, + o_wb_we, o_wb_addr, o_wb_data, o_wb_sel, + i_wb_stall, i_wb_ack, i_wb_err + ); + //}}} + end endgenerate + //}}} + // Make Verilator happy + // {{{ + // Verilator lint_off UNUSED + wire unused; + assign unused = &{ 1'b0, pf_data, mem_lock_pc, clear_dcache }; + // Verilator lint_on UNUSED + // }}} +endmodule diff --git a/rtl/main.v b/rtl/main.v index c391956..4dc8538 100644 --- a/rtl/main.v +++ b/rtl/main.v @@ -2,7 +2,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: ./main.v -// +// {{{ // Project: ZBasic, a generic toplevel implementation using the full ZipCPU // // DO NOT EDIT THIS FILE! @@ -15,9 +15,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2017-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2017-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -32,15 +32,19 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} `default_nettype none +//////////////////////////////////////////////////////////////////////////////// +// +// Macro defines +// {{{ // // // Here is a list of defines which may be used, post auto-design @@ -55,16 +59,16 @@ // First, the independent access fields for any bus masters `define WBUBUS_MASTER // And then for the independent peripherals -`define BUSCONSOLE_ACCESS -`define GPIO_ACCESS +`define INCLUDE_ZIPCPU +`define BKRAM_ACCESS `define VERSION_ACCESS -`define BUSPIC_ACCESS +`define SDSPI_ACCESS `define RTC_ACCESS -`define BKRAM_ACCESS -`define FLASH_ACCESS -`define INCLUDE_ZIPCPU +`define BUSCONSOLE_ACCESS +`define BUSPIC_ACCESS `define PWRCOUNT_ACCESS -`define SDSPI_ACCESS +`define GPIO_ACCESS +`define FLASH_ACCESS // // // The list of those things that have @DEPENDS tags @@ -85,12 +89,14 @@ // End of dependency list // // +// }}} +//////////////////////////////////////////////////////////////////////////////// // // Any include files -// +// {{{ // These are drawn from anything with a MAIN.INCLUDE definition. `include "builddate.v" -// +// }}} // // Finally, we define our main module itself. We start with the list of // I/O ports, or wires, passed into (or out of) the main function. @@ -99,37 +105,26 @@ // from the fields given by @MAIN.PORTLIST // module main(i_clk, i_reset, - // GPIO ports - i_gpio, o_gpio, + // {{{ + i_cpu_reset, // UART/host to wishbone interface i_wbu_uart_rx, o_wbu_uart_tx, - // The Universal QSPI Flash - o_qspi_cs_n, o_qspi_sck, o_qspi_dat, i_qspi_dat, o_qspi_mod, - i_cpu_reset, // The SD-Card wires - o_sd_sck, o_sd_cmd, o_sd_data, i_sd_cmd, i_sd_data, i_sd_detect); + o_sd_sck, o_sd_cmd, o_sd_data, i_sd_cmd, i_sd_data, i_sd_detect, + // GPIO ports + i_gpio, o_gpio, + // The Universal QSPI Flash + o_qspi_cs_n, o_qspi_sck, o_qspi_dat, i_qspi_dat, o_qspi_mod // }}} +); +//////////////////////////////////////////////////////////////////////////////// // // Any parameter definitions -// +// {{{ // These are drawn from anything with a MAIN.PARAM definition. // As they aren't connected to the toplevel at all, it would // be best to use localparam over parameter, but here we don't // check // - // WBUBUS parameters - // - // Baudrate : 1000000 - // Clock : 100000000 - localparam [23:0] BUSUART = 24'h64; // 1000000 baud - localparam DBGBUSBITS = $clog2(BUSUART); - // - // Maximum command is 6 bytes, where each byte takes 10 baud clocks - // and each baud clock requires DBGBUSBITS to represent. Here, - // we'll add one more for good measure. - localparam DBGBUSWATCHDOG_RAW = DBGBUSBITS + 9; - localparam DBGBUSWATCHDOG = (DBGBUSWATCHDOG_RAW > 19) - ? DBGBUSWATCHDOG_RAW : 19; - // // // Variables/definitions needed by the ZipCPU BUS master // @@ -149,6 +144,20 @@ module main(i_clk, i_reset, // A boolean, indicating whether or not the ZipCPU be halted on startup? localparam ZIP_START_HALTED=1'b1; // + // WBUBUS parameters + // + // Baudrate : 1000000 + // Clock : 100000000 + localparam [23:0] BUSUART = 24'h64; // 1000000 baud + localparam DBGBUSBITS = $clog2(BUSUART); + // + // Maximum command is 6 bytes, where each byte takes 10 baud clocks + // and each baud clock requires DBGBUSBITS to represent. Here, + // we'll add one more for good measure. + localparam DBGBUSWATCHDOG_RAW = DBGBUSBITS + 9; + localparam DBGBUSWATCHDOG = (DBGBUSWATCHDOG_RAW > 19) + ? DBGBUSWATCHDOG_RAW : 19; + // // Initial calendar DATE // `ifdef VERSION_ACCESS @@ -156,7 +165,11 @@ module main(i_clk, i_reset, `else parameter INITIAL_DATE = 30'h20000101; `endif +// }}} +//////////////////////////////////////////////////////////////////////////////// // +// Port declarations +// {{{ // The next step is to declare all of the various ports that were just // listed above. // @@ -167,18 +180,9 @@ module main(i_clk, i_reset, // verilator lint_off UNUSED input wire i_reset; // verilator lint_on UNUSED - localparam NGPI = 11, NGPO=11; - // GPIO ports - input [(NGPI-1):0] i_gpio; - output wire [(NGPO-1):0] o_gpio; + input wire i_cpu_reset; input wire i_wbu_uart_rx; output wire o_wbu_uart_tx; - // The Universal QSPI flash - output wire o_qspi_cs_n, o_qspi_sck; - output wire [3:0] o_qspi_dat; - input wire [3:0] i_qspi_dat; - output wire [1:0] o_qspi_mod; - input wire i_cpu_reset; // SD-Card declarations output wire o_sd_sck, o_sd_cmd; output wire [3:0] o_sd_data; @@ -187,41 +191,54 @@ module main(i_clk, i_reset, input wire [3:0] i_sd_data; // verilator lint_on UNUSED input wire i_sd_detect; - // Make Verilator happy ... defining bus wires for lots of components - // often ends up with unused wires lying around. We'll turn off - // Ver1lator's lint warning here that checks for unused wires. + localparam NGPI = 11, NGPO=11; + // GPIO ports + input [(NGPI-1):0] i_gpio; + output wire [(NGPO-1):0] o_gpio; + // The Universal QSPI flash + output wire o_qspi_cs_n, o_qspi_sck; + output wire [3:0] o_qspi_dat; + input wire [3:0] i_qspi_dat; + output wire [1:0] o_qspi_mod; +// }}} + // Make Verilator happy + // {{{ + // Defining bus wires for lots of components often ends up with unused + // wires lying around. We'll turn off Ver1lator's lint warning + // here that checks for unused wires. + // }}} // verilator lint_off UNUSED - - - + //////////////////////////////////////////////////////////////////////// // // Declaring interrupt lines - // + // {{{ // These declarations come from the various components values // given under the @INT..WIRE key. // - wire uarttxf_int; // uart.INT.UARTTXF.WIRE + wire zip_cpu_int; // zip.INT.ZIP.WIRE + wire sdcard_int; // sdcard.INT.SDCARD.WIRE + wire rtc_int; // rtc.INT.RTC.WIRE wire uartrxf_int; // uart.INT.UARTRXF.WIRE wire uarttx_int; // uart.INT.UARTTX.WIRE + wire uarttxf_int; // uart.INT.UARTTXF.WIRE wire uartrx_int; // uart.INT.UARTRX.WIRE - wire gpio_int; // gpio.INT.GPIO.WIRE wire w_bus_int; // buspic.INT.BUS.WIRE - wire rtc_int; // rtc.INT.RTC.WIRE - wire zip_cpu_int; // zip.INT.ZIP.WIRE - wire sdcard_int; // sdcard.INT.SDCARD.WIRE - - + wire gpio_int; // gpio.INT.GPIO.WIRE + // }}} + //////////////////////////////////////////////////////////////////////// // // Component declarations - // + // {{{ // These declarations come from the @MAIN.DEFNS keys found in the // various components comprising the design. // - // Console definitions - wire w_console_rx_stb, w_console_tx_stb, w_console_busy; - wire [6:0] w_console_rx_data, w_console_tx_data; - wire [31:0] uart_debug; - wire sd_reset; + // ZipSystem/ZipCPU connection definitions + // All we define here is a set of scope wires + wire [31:0] zip_debug; + wire zip_trigger; + wire [ZIP_INTS-1:0] zip_int_vector; +// BUILDTIME doesnt need to include builddate.v a second time +// `include "builddate.v" // // // UART interface @@ -244,50 +261,42 @@ module main(i_clk, i_reset, wire zip_dbg_stall, zip_dbg_ack; wire [31:0] zip_dbg_data; `endif + wire[31:0] sdspi_debug; // This clock step is designed to match 100000000 Hz localparam [31:0] RTC_CLKSTEP = 32'h002af31d; wire rtc_ppd; wire ck_pps; + // Console definitions + wire w_console_rx_stb, w_console_tx_stb, w_console_busy; + wire [6:0] w_console_rx_data, w_console_tx_data; + wire [31:0] uart_debug; + reg [24-1:0] r_buserr_addr; + reg [31:0] r_pwrcount_data; + wire sd_reset; // Definitions for the flash debug port wire flash_dbg_trigger; wire [31:0] flash_debug; -// BUILDTIME doesnt need to include builddate.v a second time -// `include "builddate.v" - reg [24-1:0] r_buserr_addr; - // ZipSystem/ZipCPU connection definitions - // All we define here is a set of scope wires - wire [31:0] zip_debug; - wire zip_trigger; - wire [ZIP_INTS-1:0] zip_int_vector; - reg [31:0] r_pwrcount_data; - wire[31:0] sdspi_debug; - +// }}} + //////////////////////////////////////////////////////////////////////// // // Declaring interrupt vector wires - // + // {{{ // These declarations come from the various components having // PIC and PIC.MAX keys. // - wire [14:0] bus_int_vector; wire [14:0] sys_int_vector; wire [14:0] alt_int_vector; + wire [14:0] bus_int_vector; + // }}} + //////////////////////////////////////////////////////////////////////// // - // - // Define bus wires - // - // + // Declare bus signals + // {{{ + //////////////////////////////////////////////////////////////////////// // Bus wb - // Wishbone definitions for bus wb, component wbu_arbiter - // Verilator lint_off UNUSED - wire wb_wbu_arbiter_cyc, wb_wbu_arbiter_stb, wb_wbu_arbiter_we; - wire [22:0] wb_wbu_arbiter_addr; - wire [31:0] wb_wbu_arbiter_data; - wire [3:0] wb_wbu_arbiter_sel; - wire wb_wbu_arbiter_stall, wb_wbu_arbiter_ack, wb_wbu_arbiter_err; - wire [31:0] wb_wbu_arbiter_idata; - // Verilator lint_on UNUSED + // {{{ // Wishbone definitions for bus wb, component zip // Verilator lint_off UNUSED wire wb_zip_cyc, wb_zip_stb, wb_zip_we; @@ -297,6 +306,15 @@ module main(i_clk, i_reset, wire wb_zip_stall, wb_zip_ack, wb_zip_err; wire [31:0] wb_zip_idata; // Verilator lint_on UNUSED + // Wishbone definitions for bus wb, component wbu_arbiter + // Verilator lint_off UNUSED + wire wb_wbu_arbiter_cyc, wb_wbu_arbiter_stb, wb_wbu_arbiter_we; + wire [22:0] wb_wbu_arbiter_addr; + wire [31:0] wb_wbu_arbiter_data; + wire [3:0] wb_wbu_arbiter_sel; + wire wb_wbu_arbiter_stall, wb_wbu_arbiter_ack, wb_wbu_arbiter_err; + wire [31:0] wb_wbu_arbiter_idata; + // Verilator lint_on UNUSED // Wishbone definitions for bus wb(SIO), component buildtime // Verilator lint_off UNUSED wire wb_buildtime_cyc, wb_buildtime_stb, wb_buildtime_we; @@ -423,7 +441,9 @@ module main(i_clk, i_reset, wire wb_flash_stall, wb_flash_ack, wb_flash_err; wire [31:0] wb_flash_idata; // Verilator lint_on UNUSED + // }}} // Bus wbu + // {{{ // Wishbone definitions for bus wbu, component wbu // Verilator lint_off UNUSED wire wbu_cyc, wbu_stb, wbu_we; @@ -451,10 +471,12 @@ module main(i_clk, i_reset, wire wbu_zip_stall, wbu_zip_ack, wbu_zip_err; wire [31:0] wbu_zip_idata; // Verilator lint_on UNUSED - - // - // Peripheral address decoding + // }}} + // }}} + //////////////////////////////////////////////////////////////////////// // + // Peripheral address decoding, bus handling + // {{{ // // BUS-LOGIC for wb // @@ -573,44 +595,44 @@ module main(i_clk, i_reset, wb_xbar( .i_clk(i_clk), .i_reset(i_reset), .i_mcyc({ - wb_zip_cyc, - wb_wbu_arbiter_cyc + wb_wbu_arbiter_cyc, + wb_zip_cyc }), .i_mstb({ - wb_zip_stb, - wb_wbu_arbiter_stb + wb_wbu_arbiter_stb, + wb_zip_stb }), .i_mwe({ - wb_zip_we, - wb_wbu_arbiter_we + wb_wbu_arbiter_we, + wb_zip_we }), .i_maddr({ - wb_zip_addr, - wb_wbu_arbiter_addr + wb_wbu_arbiter_addr, + wb_zip_addr }), .i_mdata({ - wb_zip_data, - wb_wbu_arbiter_data + wb_wbu_arbiter_data, + wb_zip_data }), .i_msel({ - wb_zip_sel, - wb_wbu_arbiter_sel + wb_wbu_arbiter_sel, + wb_zip_sel }), .o_mstall({ - wb_zip_stall, - wb_wbu_arbiter_stall + wb_wbu_arbiter_stall, + wb_zip_stall }), .o_mack({ - wb_zip_ack, - wb_wbu_arbiter_ack + wb_wbu_arbiter_ack, + wb_zip_ack }), .o_mdata({ - wb_zip_idata, - wb_wbu_arbiter_idata + wb_wbu_arbiter_idata, + wb_zip_idata }), .o_merr({ - wb_zip_err, - wb_wbu_arbiter_err + wb_wbu_arbiter_err, + wb_zip_err }), // Slave connections .o_scyc({ @@ -814,9 +836,11 @@ module main(i_clk, i_reset, }) ); + // }}} + //////////////////////////////////////////////////////////////////////// // // Declare the interrupt busses - // + // {{{ // Interrupt busses are defined by anything with a @PIC tag. // The @PIC.BUS tag defines the name of the wire bus below, // while the @PIC.MAX tag determines the size of the bus width. @@ -828,33 +852,33 @@ module main(i_clk, i_reset, // exists, then your interrupt will be assigned to the position given // by the ID# in that tag. // - assign bus_int_vector = { - 1'b0, - 1'b0, - 1'b0, + assign sys_int_vector = { 1'b0, 1'b0, 1'b0, 1'b0, 1'b0, + uarttxf_int, + uartrxf_int, + sdcard_int, + w_bus_int, 1'b0, 1'b0, 1'b0, 1'b0, 1'b0, - sdcard_int, - gpio_int + 1'b0 }; - assign sys_int_vector = { + assign alt_int_vector = { 1'b0, 1'b0, 1'b0, 1'b0, + uartrx_int, + uarttx_int, + rtc_int, + 1'b0, 1'b0, - sdcard_int, - uartrxf_int, - uarttxf_int, - w_bus_int, 1'b0, 1'b0, 1'b0, @@ -862,14 +886,11 @@ module main(i_clk, i_reset, 1'b0, 1'b0 }; - assign alt_int_vector = { + assign bus_int_vector = { 1'b0, 1'b0, 1'b0, 1'b0, - rtc_int, - uartrx_int, - uarttx_int, 1'b0, 1'b0, 1'b0, @@ -877,10 +898,19 @@ module main(i_clk, i_reset, 1'b0, 1'b0, 1'b0, - 1'b0 + 1'b0, + 1'b0, + gpio_int, + sdcard_int }; - - + // }}} + //////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////// + // + // @MAIN.INSERT and @MAIN.ALT + // {{{ + //////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////// // // // Now we turn to defining all of the parts and pieces of what @@ -895,89 +925,111 @@ module main(i_clk, i_reset, // or making sure all of the various interrupt wires are set to // zero if the component is not included. // - assign wb_wbu_arbiter_cyc = wbu_wbu_arbiter_cyc; - assign wb_wbu_arbiter_stb = wbu_wbu_arbiter_stb; - assign wb_wbu_arbiter_we = wbu_wbu_arbiter_we; - assign wb_wbu_arbiter_addr = wbu_wbu_arbiter_addr[23-1:0]; - assign wb_wbu_arbiter_data = wbu_wbu_arbiter_data; - assign wb_wbu_arbiter_sel = wbu_wbu_arbiter_sel; +`ifdef INCLUDE_ZIPCPU + // {{{ // - assign wbu_wbu_arbiter_stall = wb_wbu_arbiter_stall; - assign wbu_wbu_arbiter_ack = wb_wbu_arbiter_ack; - assign wbu_wbu_arbiter_idata = wb_wbu_arbiter_idata; - assign wbu_wbu_arbiter_err = wb_wbu_arbiter_err; - -`ifdef BUSCONSOLE_ACCESS - wbconsole #(.LGFLEN(6)) console(i_clk, 1'b0, - wb_uart_cyc, wb_uart_stb, wb_uart_we, - wb_uart_addr[2-1:0], - wb_uart_data, // 32 bits wide - wb_uart_sel, // 32/8 bits wide - wb_uart_stall, wb_uart_ack, wb_uart_idata, - w_console_tx_stb, w_console_tx_data, w_console_busy, - w_console_rx_stb, w_console_rx_data, - uartrx_int, uarttx_int, uartrxf_int, uarttxf_int, - uart_debug); -`else // BUSCONSOLE_ACCESS - // - // In the case that there is no wb_uart peripheral - // responding on the wb bus - assign wb_uart_ack = 1'b0; - assign wb_uart_err = (wb_uart_stb); - assign wb_uart_stall = 0; - assign wb_uart_idata = 0; - - assign uarttxf_int = 1'b0; // uart.INT.UARTTXF.WIRE - assign uartrxf_int = 1'b0; // uart.INT.UARTRXF.WIRE - assign uarttx_int = 1'b0; // uart.INT.UARTTX.WIRE - assign uartrx_int = 1'b0; // uart.INT.UARTRX.WIRE -`endif // BUSCONSOLE_ACCESS - -`ifdef GPIO_ACCESS + // The ZipCPU/ZipSystem BUS master // - // GPIO // - // This interface should allow us to control up to 16 GPIO inputs, and - // another 16 GPIO outputs. The interrupt trips when any of the inputs - // changes. (Sorry, which input isn't (yet) selectable.) + assign zip_int_vector = { alt_int_vector[14:8], sys_int_vector[14:6] }; + zipsystem #( + // {{{ + .RESET_ADDRESS(RESET_ADDRESS), + .ADDRESS_WIDTH(ZIP_ADDRESS_WIDTH), + .LGICACHE(12),.LGDCACHE(12), + .START_HALTED(ZIP_START_HALTED), + .RESET_DURATION(20), + .EXTERNAL_INTERRUPTS(ZIP_INTS) + // }}} + ) swic( + // {{{ + i_clk, (i_reset)||(i_cpu_reset), + // Zippys wishbone interface + wb_zip_cyc, wb_zip_stb, wb_zip_we, + wb_zip_addr[23-1:0], + wb_zip_data, // 32 bits wide + wb_zip_sel, // 32/8 bits wide + wb_zip_stall, wb_zip_ack, wb_zip_idata,wb_zip_err, + zip_int_vector, zip_cpu_int, + // Debug wishbone interface + wbu_zip_cyc, wbu_zip_stb, wbu_zip_we, + wbu_zip_addr[7-1:0], + wbu_zip_data, // 32 bits wide + wbu_zip_sel, // 32/8 bits wide + wbu_zip_stall, wbu_zip_ack, wbu_zip_idata, + zip_debug + // }}} + ); + assign zip_trigger = zip_debug[31]; + // }}} +`else // INCLUDE_ZIPCPU + // {{{ + // Null bus master + // {{{ + // }}} + // Null bus slave + // {{{ + // - localparam INITIAL_GPIO = 11'h0; - wbgpio #(NGPI, NGPO, INITIAL_GPIO) - gpioi(i_clk, wb_gpio_cyc, wb_gpio_stb, wb_gpio_we, - wb_gpio_data, // 32 bits wide - wb_gpio_sel, // 32/8 bits wide - wb_gpio_stall, wb_gpio_ack, wb_gpio_idata, - i_gpio, o_gpio, gpio_int); + // In the case that there is no wbu_zip peripheral + // responding on the wbu bus + assign wbu_zip_ack = 1'b0; + assign wbu_zip_err = (wbu_zip_stb); + assign wbu_zip_stall = 0; + assign wbu_zip_idata = 0; - assign sd_reset = o_gpio[0]; -`else // GPIO_ACCESS - assign gpio_int = 1'b0; // gpio.INT.GPIO.WIRE -`endif // GPIO_ACCESS + // }}} + // Null interrupt definitions + // {{{ + assign zip_cpu_int = 1'b0; // zip.INT.ZIP.WIRE + // }}} + // }}} +`endif // INCLUDE_ZIPCPU + + assign wb_buildtime_idata = `BUILDTIME; + assign wb_buildtime_ack = wb_buildtime_stb; + assign wb_buildtime_stall = 1'b0; +`ifdef BKRAM_ACCESS + // {{{ + memdev #(.LGMEMSZ(20), .EXTRACLOCK(1)) + bkrami(i_clk, i_reset, + wb_bkram_cyc, wb_bkram_stb, wb_bkram_we, + wb_bkram_addr[18-1:0], + wb_bkram_data, // 32 bits wide + wb_bkram_sel, // 32/8 bits wide + wb_bkram_stall, wb_bkram_ack, wb_bkram_idata); + // }}} +`else // BKRAM_ACCESS + // {{{ + // Null bus slave + // {{{ + + // + // In the case that there is no wb_bkram peripheral + // responding on the wb bus + assign wb_bkram_ack = 1'b0; + assign wb_bkram_err = (wb_bkram_stb); + assign wb_bkram_stall = 0; + assign wb_bkram_idata = 0; + + // }}} + // }}} +`endif // BKRAM_ACCESS `ifdef VERSION_ACCESS + // {{{ assign wb_version_idata = `DATESTAMP; assign wb_version_ack = wb_version_stb; assign wb_version_stall = 1'b0; + // }}} `else // VERSION_ACCESS + // {{{ + // }}} `endif // VERSION_ACCESS -`ifdef FLASHCFG_ACCESS - // The Flash control interface is defined by the flash instantiation - // hence we don't need to do anything to define it here. -`else // FLASHCFG_ACCESS - - // - // In the case that there is no wb_flashcfg peripheral - // responding on the wb bus - assign wb_flashcfg_ack = 1'b0; - assign wb_flashcfg_err = (wb_flashcfg_stb); - assign wb_flashcfg_stall = 0; - assign wb_flashcfg_idata = 0; - -`endif // FLASHCFG_ACCESS - `ifdef WBUBUS_MASTER + // {{{ // The Host USB interface, to be used by the WB-UART bus rxuartlite #(.TIMER_BITS(DBGBUSBITS), .CLOCKS_PER_BAUD(BUSUART[DBGBUSBITS-1:0])) @@ -1005,10 +1057,11 @@ module main(i_clk, i_reset, wire [31:0] wbu_tmp_addr; // Verilator lint_on UNUSED wbuconsole #(.LGWATCHDOG(DBGBUSWATCHDOG)) - genbus(i_clk, wbu_rx_stb, wbu_rx_data, + genbus(i_clk, 1'b0, wbu_rx_stb, wbu_rx_data, wbu_cyc, wbu_stb, wbu_we, wbu_tmp_addr, wbu_data, wbu_stall, wbu_ack, - wbu_err, wbu_idata, + wbu_idata, + wbu_err, w_bus_int, wbu_tx_stb, wbu_tx_data, wbu_tx_busy, // @@ -1018,24 +1071,59 @@ module main(i_clk, i_reset, wbubus_dbg[0]); assign wbu_sel = 4'hf; assign wbu_addr = wbu_tmp_addr[(24-1):0]; + // }}} `else // WBUBUS_MASTER + // {{{ + // Null bus master + // {{{ + // }}} + // }}} `endif // WBUBUS_MASTER -`ifdef BUSPIC_ACCESS - // - // The BUS Interrupt controller +`ifdef SDSPI_ACCESS + // {{{ + // SPI mapping + wire w_sd_cs_n, w_sd_mosi, w_sd_miso; + + sdspi sdcardi(i_clk, sd_reset, + wb_sdcard_cyc, wb_sdcard_stb, wb_sdcard_we, + wb_sdcard_addr[2-1:0], + wb_sdcard_data, // 32 bits wide + wb_sdcard_sel, // 32/8 bits wide + wb_sdcard_stall, wb_sdcard_ack, wb_sdcard_idata, + w_sd_cs_n, o_sd_sck, w_sd_mosi, w_sd_miso, i_sd_detect, + sdcard_int, 1'b1, sdspi_debug); + + assign w_sd_miso = i_sd_data[0]; + assign o_sd_data = { w_sd_cs_n, 3'b111 }; + assign o_sd_cmd = w_sd_mosi; + // }}} +`else // SDSPI_ACCESS + // {{{ + assign o_sd_sck = 1'b1; + assign o_sd_cmd = 1'b1; + assign o_sd_data = 4'hf; + // Null bus slave + // {{{ + // - icontrol #(15) buspici(i_clk, 1'b0, - wb_buspic_cyc, wb_buspic_stb, wb_buspic_we, - wb_buspic_data, // 32 bits wide - wb_buspic_sel, // 32/8 bits wide - wb_buspic_stall, wb_buspic_ack, wb_buspic_idata, - bus_int_vector, w_bus_int); -`else // BUSPIC_ACCESS - assign w_bus_int = 1'b0; // buspic.INT.BUS.WIRE -`endif // BUSPIC_ACCESS + // In the case that there is no wb_sdcard peripheral + // responding on the wb bus + assign wb_sdcard_ack = 1'b0; + assign wb_sdcard_err = (wb_sdcard_stb); + assign wb_sdcard_stall = 0; + assign wb_sdcard_idata = 0; + + // }}} + // Null interrupt definitions + // {{{ + assign sdcard_int = 1'b0; // sdcard.INT.SDCARD.WIRE + // }}} + // }}} +`endif // SDSPI_ACCESS `ifdef RTC_ACCESS + // {{{ rtclight #(.DEFAULT_SPEED(32'h2af31d), .OPT_TIMER(1'b1), .OPT_STOPWATCH(1'b1), @@ -1047,8 +1135,12 @@ module main(i_clk, i_reset, wb_rtc_sel, // 32/8 bits wide wb_rtc_stall, wb_rtc_ack, wb_rtc_idata, rtc_int, ck_pps, rtc_ppd); + // }}} `else // RTC_ACCESS + // {{{ assign ck_pps = 1'b0; + // Null bus slave + // {{{ // // In the case that there is no wb_rtc peripheral @@ -1058,76 +1150,72 @@ module main(i_clk, i_reset, assign wb_rtc_stall = 0; assign wb_rtc_idata = 0; + // }}} + // Null interrupt definitions + // {{{ assign rtc_int = 1'b0; // rtc.INT.RTC.WIRE + // }}} + // }}} `endif // RTC_ACCESS -`ifdef BKRAM_ACCESS - memdev #(.LGMEMSZ(20), .EXTRACLOCK(1)) - bkrami(i_clk, i_reset, - wb_bkram_cyc, wb_bkram_stb, wb_bkram_we, - wb_bkram_addr[18-1:0], - wb_bkram_data, // 32 bits wide - wb_bkram_sel, // 32/8 bits wide - wb_bkram_stall, wb_bkram_ack, wb_bkram_idata); -`else // BKRAM_ACCESS +`ifdef BUSCONSOLE_ACCESS + // {{{ + wbconsole #(.LGFLEN(6)) console(i_clk, 1'b0, + wb_uart_cyc, wb_uart_stb, wb_uart_we, + wb_uart_addr[2-1:0], + wb_uart_data, // 32 bits wide + wb_uart_sel, // 32/8 bits wide + wb_uart_stall, wb_uart_ack, wb_uart_idata, + w_console_tx_stb, w_console_tx_data, w_console_busy, + w_console_rx_stb, w_console_rx_data, + uartrx_int, uarttx_int, uartrxf_int, uarttxf_int, + uart_debug); + // }}} +`else // BUSCONSOLE_ACCESS + // {{{ + // Null bus slave + // {{{ // - // In the case that there is no wb_bkram peripheral + // In the case that there is no wb_uart peripheral // responding on the wb bus - assign wb_bkram_ack = 1'b0; - assign wb_bkram_err = (wb_bkram_stb); - assign wb_bkram_stall = 0; - assign wb_bkram_idata = 0; - -`endif // BKRAM_ACCESS + assign wb_uart_ack = 1'b0; + assign wb_uart_err = (wb_uart_stb); + assign wb_uart_stall = 0; + assign wb_uart_idata = 0; -`ifdef FLASH_ACCESS - qflexpress #(.LGFLASHSZ(24), .OPT_CLKDIV(1), - .OPT_ENDIANSWAP(0), - .NDUMMY(6), .RDDELAY(0), - .OPT_STARTUP_FILE("spansion.hex"), -`ifdef FLASHCFG_ACCESS - .OPT_CFG(1'b1) -`else - .OPT_CFG(1'b0) -`endif - ) - flashi(i_clk, i_reset, - // Primary memory reading inputs - wb_flash_cyc, wb_flash_stb, wb_flash_we, - wb_flash_addr[22-1:0], - wb_flash_data, // 32 bits wide - wb_flash_sel, // 32/8 bits wide - wb_flash_stall, wb_flash_ack, wb_flash_idata, - // Configuration bus ports - wb_flashcfg_cyc, wb_flashcfg_stb, wb_flashcfg_we, - wb_flashcfg_data, // 32 bits wide - wb_flashcfg_sel, // 32/8 bits wide - wb_flashcfg_stall, wb_flashcfg_ack, wb_flashcfg_idata, - o_qspi_sck, o_qspi_cs_n, o_qspi_mod, o_qspi_dat, i_qspi_dat, - flash_dbg_trigger, flash_debug); -`else // FLASH_ACCESS - assign o_qspi_sck = 1'b1; - assign o_qspi_cs_n = 1'b1; - assign o_qspi_mod = 2'b01; - assign o_qspi_dat = 4'b1111; - // Verilator lint_off UNUSED - wire flash_unused = &{ 1'b0, i_qspi_dat }; - // Verilator lint_on UNUSED + // }}} + // Null interrupt definitions + // {{{ + assign uartrxf_int = 1'b0; // uart.INT.UARTRXF.WIRE + assign uarttx_int = 1'b0; // uart.INT.UARTTX.WIRE + assign uarttxf_int = 1'b0; // uart.INT.UARTTXF.WIRE + assign uartrx_int = 1'b0; // uart.INT.UARTRX.WIRE + // }}} + // }}} +`endif // BUSCONSOLE_ACCESS +`ifdef BUSPIC_ACCESS + // {{{ // - // In the case that there is no wb_flash peripheral - // responding on the wb bus - assign wb_flash_ack = 1'b0; - assign wb_flash_err = (wb_flash_stb); - assign wb_flash_stall = 0; - assign wb_flash_idata = 0; - -`endif // FLASH_ACCESS + // The BUS Interrupt controller + // + icontrol #(15) buspici(i_clk, 1'b0, + wb_buspic_cyc, wb_buspic_stb, wb_buspic_we, + wb_buspic_data, // 32 bits wide + wb_buspic_sel, // 32/8 bits wide + wb_buspic_stall, wb_buspic_ack, wb_buspic_idata, + bus_int_vector, w_bus_int); + // }}} +`else // BUSPIC_ACCESS + // {{{ + // Null interrupt definitions + // {{{ + assign w_bus_int = 1'b0; // buspic.INT.BUS.WIRE + // }}} + // }}} +`endif // BUSPIC_ACCESS - assign wb_buildtime_idata = `BUILDTIME; - assign wb_buildtime_ack = wb_buildtime_stb; - assign wb_buildtime_stall = 1'b0; always @(posedge i_clk) if (wb_zip_err) begin @@ -1142,49 +1230,8 @@ module main(i_clk, i_reset, assign wb_buserr_ack = wb_buserr_stb; assign wb_buserr_idata = { {(30-24){1'b0}}, r_buserr_addr, 2'b00 }; -`ifdef INCLUDE_ZIPCPU - // - // - // The ZipCPU/ZipSystem BUS master - // - // - assign zip_int_vector = { alt_int_vector[14:8], sys_int_vector[14:6] }; - zipsystem #(.RESET_ADDRESS(RESET_ADDRESS), - .ADDRESS_WIDTH(ZIP_ADDRESS_WIDTH), - .LGICACHE(12),.LGDCACHE(12), - .START_HALTED(ZIP_START_HALTED), - .RESET_DURATION(20), - .EXTERNAL_INTERRUPTS(ZIP_INTS)) - swic(i_clk, (i_reset)||(i_cpu_reset), - // Zippys wishbone interface - wb_zip_cyc, wb_zip_stb, wb_zip_we, - wb_zip_addr[23-1:0], - wb_zip_data, // 32 bits wide - wb_zip_sel, // 32/8 bits wide - wb_zip_stall, wb_zip_ack, wb_zip_idata,wb_zip_err, - zip_int_vector, zip_cpu_int, - // Debug wishbone interface - wbu_zip_cyc, wbu_zip_stb, wbu_zip_we, - wbu_zip_addr[1-1:0], - wbu_zip_data, // 32 bits wide - wbu_zip_sel, // 32/8 bits wide - wbu_zip_stall, wbu_zip_ack, wbu_zip_idata, - zip_debug); - assign zip_trigger = zip_debug[31]; -`else // INCLUDE_ZIPCPU - - // - // In the case that there is no wbu_zip peripheral - // responding on the wbu bus - assign wbu_zip_ack = 1'b0; - assign wbu_zip_err = (wbu_zip_stb); - assign wbu_zip_stall = 0; - assign wbu_zip_idata = 0; - - assign zip_cpu_int = 1'b0; // zip.INT.ZIP.WIRE -`endif // INCLUDE_ZIPCPU - `ifdef PWRCOUNT_ACCESS + // {{{ initial r_pwrcount_data = 32'h0; always @(posedge i_clk) if (r_pwrcount_data[31]) @@ -1195,10 +1242,26 @@ module main(i_clk, i_reset, assign wb_pwrcount_stall = 1'b0; assign wb_pwrcount_ack = wb_pwrcount_stb; assign wb_pwrcount_idata = r_pwrcount_data; + // }}} `else // PWRCOUNT_ACCESS + // {{{ + // }}} `endif // PWRCOUNT_ACCESS + assign wb_wbu_arbiter_cyc = wbu_wbu_arbiter_cyc; + assign wb_wbu_arbiter_stb = wbu_wbu_arbiter_stb; + assign wb_wbu_arbiter_we = wbu_wbu_arbiter_we; + assign wb_wbu_arbiter_addr = wbu_wbu_arbiter_addr[23-1:0]; + assign wb_wbu_arbiter_data = wbu_wbu_arbiter_data; + assign wb_wbu_arbiter_sel = wbu_wbu_arbiter_sel; + // + assign wbu_wbu_arbiter_stall = wb_wbu_arbiter_stall; + assign wbu_wbu_arbiter_ack = wb_wbu_arbiter_ack; + assign wbu_wbu_arbiter_idata = wb_wbu_arbiter_idata; + assign wbu_wbu_arbiter_err = wb_wbu_arbiter_err; + `ifdef RTCDATE_ACCESS + // {{{ // // The Calendar DATE // @@ -1208,41 +1271,112 @@ module main(i_clk, i_reset, wb_rtcdate_data, // 32 bits wide wb_rtcdate_sel, // 32/8 bits wide wb_rtcdate_stall, wb_rtcdate_ack, wb_rtcdate_idata); + // }}} `else // RTCDATE_ACCESS + // {{{ + // }}} `endif // RTCDATE_ACCESS -`ifdef SDSPI_ACCESS - // SPI mapping - wire w_sd_cs_n, w_sd_mosi, w_sd_miso; +`ifdef GPIO_ACCESS + // {{{ + // + // GPIO + // + // This interface should allow us to control up to 16 GPIO inputs, and + // another 16 GPIO outputs. The interrupt trips when any of the inputs + // changes. (Sorry, which input isn't (yet) selectable.) + // + localparam INITIAL_GPIO = 11'h0; + wbgpio #(NGPI, NGPO, INITIAL_GPIO) + gpioi(i_clk, wb_gpio_cyc, wb_gpio_stb, wb_gpio_we, + wb_gpio_data, // 32 bits wide + wb_gpio_sel, // 32/8 bits wide + wb_gpio_stall, wb_gpio_ack, wb_gpio_idata, + i_gpio, o_gpio, gpio_int); - sdspi sdcardi(i_clk, sd_reset, - wb_sdcard_cyc, wb_sdcard_stb, wb_sdcard_we, - wb_sdcard_addr[2-1:0], - wb_sdcard_data, // 32 bits wide - wb_sdcard_sel, // 32/8 bits wide - wb_sdcard_stall, wb_sdcard_ack, wb_sdcard_idata, - w_sd_cs_n, o_sd_sck, w_sd_mosi, w_sd_miso, i_sd_detect, - sdcard_int, 1'b1, sdspi_debug); + assign sd_reset = o_gpio[0]; + // }}} +`else // GPIO_ACCESS + // {{{ + // Null interrupt definitions + // {{{ + assign gpio_int = 1'b0; // gpio.INT.GPIO.WIRE + // }}} + // }}} +`endif // GPIO_ACCESS - assign w_sd_miso = i_sd_data[0]; - assign o_sd_data = { w_sd_cs_n, 3'b111 }; - assign o_sd_cmd = w_sd_mosi; -`else // SDSPI_ACCESS - assign o_sd_sck = 1'b1; - assign o_sd_cmd = 1'b1; - assign o_sd_data = 4'hf; +`ifdef FLASHCFG_ACCESS + // {{{ + // The Flash control interface is defined by the flash instantiation + // hence we don't need to do anything to define it here. + // }}} +`else // FLASHCFG_ACCESS + // {{{ + // Null bus slave + // {{{ // - // In the case that there is no wb_sdcard peripheral + // In the case that there is no wb_flashcfg peripheral // responding on the wb bus - assign wb_sdcard_ack = 1'b0; - assign wb_sdcard_err = (wb_sdcard_stb); - assign wb_sdcard_stall = 0; - assign wb_sdcard_idata = 0; + assign wb_flashcfg_ack = 1'b0; + assign wb_flashcfg_err = (wb_flashcfg_stb); + assign wb_flashcfg_stall = 0; + assign wb_flashcfg_idata = 0; - assign sdcard_int = 1'b0; // sdcard.INT.SDCARD.WIRE -`endif // SDSPI_ACCESS + // }}} + // }}} +`endif // FLASHCFG_ACCESS + +`ifdef FLASH_ACCESS + // {{{ + qflexpress #(.LGFLASHSZ(24), .OPT_CLKDIV(1), + .OPT_ENDIANSWAP(0), + .NDUMMY(6), .RDDELAY(0), + .OPT_STARTUP_FILE("spansion.hex"), +`ifdef FLASHCFG_ACCESS + .OPT_CFG(1'b1) +`else + .OPT_CFG(1'b0) +`endif + ) + flashi(i_clk, i_reset, + // Primary memory reading inputs + wb_flash_cyc, wb_flash_stb, wb_flash_we, + wb_flash_addr[22-1:0], + wb_flash_data, // 32 bits wide + wb_flash_sel, // 32/8 bits wide + wb_flash_stall, wb_flash_ack, wb_flash_idata, + // Configuration bus ports + wb_flashcfg_cyc, wb_flashcfg_stb, wb_flashcfg_we, + wb_flashcfg_data, // 32 bits wide + wb_flashcfg_sel, // 32/8 bits wide + wb_flashcfg_stall, wb_flashcfg_ack, wb_flashcfg_idata, + o_qspi_sck, o_qspi_cs_n, o_qspi_mod, o_qspi_dat, i_qspi_dat, + flash_dbg_trigger, flash_debug); + // }}} +`else // FLASH_ACCESS + // {{{ + assign o_qspi_sck = 1'b1; + assign o_qspi_cs_n = 1'b1; + assign o_qspi_mod = 2'b01; + assign o_qspi_dat = 4'b1111; + // Verilator lint_off UNUSED + wire flash_unused = &{ 1'b0, i_qspi_dat }; + // Verilator lint_on UNUSED + // Null bus slave + // {{{ + // + // In the case that there is no wb_flash peripheral + // responding on the wb bus + assign wb_flash_ack = 1'b0; + assign wb_flash_err = (wb_flash_stb); + assign wb_flash_stall = 0; + assign wb_flash_idata = 0; + // }}} + // }}} +`endif // FLASH_ACCESS + // }}} endmodule // main.v diff --git a/rtl/make.inc b/rtl/make.inc index 635a5f3..357ac7c 100644 --- a/rtl/make.inc +++ b/rtl/make.inc @@ -1,7 +1,7 @@ ################################################################################ ## ## Filename: ./rtl.make.inc -## +## {{{ ## Project: ZBasic, a generic toplevel implementation using the full ZipCPU ## ## DO NOT EDIT THIS FILE! @@ -14,9 +14,9 @@ ## Gisselquist Technology, LLC ## ################################################################################ -## -## Copyright (C) 2017-2020, Gisselquist Technology, LLC -## +## }}} +## Copyright (C) 2017-2021, Gisselquist Technology, LLC +## {{{ ## This program is free software (firmware): 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 @@ -31,33 +31,33 @@ ## with this program. (It's in the $(ROOT)/doc directory. Run make with no ## target there if the PDF file isn't present.) If not, see ## for a copy. -## +## }}} ## License: GPL, v3, as defined and found on www.gnu.org, +## {{{ ## http://www.gnu.org/licenses/gpl.html ## -## ################################################################################ ## -## -CONSOLED := wbuart -CONSOLE := $(addprefix $(CONSOLED)/,txuartlite.v rxuartlite.v ufifo.v) -GPIO := wbgpio.v - -FLASH := qflexpress.v +## }}} +ZIPCPUD := cpu +ZIPCPU := $(addprefix $(ZIPCPUD)/,zipsystem.v zipcore.v zipwb.v cpuops.v pfcache.v pipemem.v pfcache.v idecode.v wbpriarbiter.v zipsystem.v zipcounter.v zipjiffies.v ziptimer.v wbdmac.v icontrol.v wbwatchdog.v busdelay.v cpudefs.v) +BKRAM := memdev.v WBUBUSD := wbubus WBUBUS := $(addprefix $(WBUBUSD)/,wbuconsole.v wbufifo.v wbucompactlines.v wbucompress.v wbudecompress.v wbudeword.v wbuexec.v wbuidleint.v wbuinput.v wbuoutput.v wbureadcw.v wbusixchar.v wbutohex.v wbconsole.v) -BUSPICD := cpu -BUSPIC := $(addprefix $(BUSPICD)/,icontrol.v) +SDSPID := sdspi +SDSPI := $(addprefix $(SDSPID)/,sdspi.v llsdspi.v spicmd.v spirxdata.v spitxdata.v) RTCD := rtc RTC := $(addprefix $(RTCD)/,rtclight.v rtcbare.v rtcalarm.v rtcstopwatch.v rtctimer.v) -BKRAM := memdev.v - -ZIPCPUD := cpu -ZIPCPU := $(addprefix $(ZIPCPUD)/,zipcpu.v cpuops.v pfcache.v pipemem.v pfcache.v idecode.v wbpriarbiter.v zipsystem.v zipcounter.v zipjiffies.v ziptimer.v wbdmac.v icontrol.v wbwatchdog.v busdelay.v cpudefs.v) +CONSOLED := wbuart +CONSOLE := $(addprefix $(CONSOLED)/,txuartlite.v rxuartlite.v ufifo.v) +BUSPICD := cpu +BUSPIC := $(addprefix $(BUSPICD)/,icontrol.v) RTCDATED := rtc RTCDATE := $(addprefix $(RTCDATED)/,rtcdate.v) -SDSPID := sdspi -SDSPI := $(addprefix $(SDSPID)/,sdspi.v llsdspi.v spicmd.v spirxdata.v spitxdata.v) -VFLIST := main.v $(CONSOLE) $(GPIO) $(FLASH) $(WBUBUS) $(BUSPIC) $(RTC) $(BKRAM) $(ZIPCPU) $(RTCDATE) $(SDSPI) -AUTOVDIRS := -y wbuart -y wbubus -y cpu -y rtc -y sdspi +GPIO := wbgpio.v + +FLASH := qflexpress.v + +VFLIST := main.v $(ZIPCPU) $(BKRAM) $(WBUBUS) $(SDSPI) $(RTC) $(CONSOLE) $(BUSPIC) $(RTCDATE) $(GPIO) $(FLASH) +AUTOVDIRS := -y cpu -y wbubus -y sdspi -y rtc -y wbuart diff --git a/rtl/qflexpress.v b/rtl/qflexpress.v index 21b8b07..0b460c6 100644 --- a/rtl/qflexpress.v +++ b/rtl/qflexpress.v @@ -147,7 +147,7 @@ module qflexpress(i_clk, i_reset, // localparam [4:0] CFG_MODE = 12; localparam [4:0] QSPEED_BIT = 11; - localparam [4:0] DSPEED_BIT = 10; // Not supported + // localparam [4:0] DSPEED_BIT = 10; // Not supported localparam [4:0] DIR_BIT = 9; localparam [4:0] USER_CS_n = 8; // @@ -155,7 +155,7 @@ module qflexpress(i_clk, i_reset, localparam [1:0] QUAD_WRITE = 2'b10; localparam [1:0] QUAD_READ = 2'b11; // localparam [7:0] DIO_READ_CMD = 8'hbb; - localparam [7:0] QIO_READ_CMD = OPT_ADDR32 ? 8'hec : 8'heb; + // localparam [7:0] QIO_READ_CMD = OPT_ADDR32 ? 8'hec : 8'heb; // localparam AW=LGFLASHSZ-2; localparam DW=32; @@ -206,10 +206,11 @@ module qflexpress(i_clk, i_reset, // // Memory vs Configuration bus arbiter // - wbarbiter #(.DW(DW), .AW(AW+1), .SCHEME("PRIORITY"), - .F_MAX_STALL(0), - .F_MAX_ACK_DELAY(0)) - arbiter(i_clk, i_reset, + wbarbiter #( + // {{{ + .DW(DW), .AW(AW+1), .SCHEME("PRIORITY") + // }}} + ) arbiter(i_clk, i_reset, i_wb_cyc, i_wb_stb, i_wb_we, { 1'b0, i_wb_addr }, i_wb_data, i_wb_sel, o_wb_stall, o_wb_ack, ign_wb_err, diff --git a/rtl/rtc/rtcalarm.v b/rtl/rtc/rtcalarm.v index c836bbb..bc9ba8d 100644 --- a/rtl/rtc/rtcalarm.v +++ b/rtl/rtc/rtcalarm.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: rtcalarm.v -// +// {{{ // Project: A Wishbone Controlled Real--time Clock Core, w/ GPS synch // // Purpose: Implement an alarm for a real time clock. @@ -11,9 +11,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -28,38 +28,48 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // // `default_nettype none -// +// }}} // set, clear, turn on, turn off -module rtcalarm(i_clk, i_reset, i_now, +module rtcalarm #( + // {{{ + parameter [0:0] OPT_PREVALIDATED_INPUT = 1'b0, + parameter [21:0] OPT_INITIAL_ALARM_TIME = 0, + parameter [0:0] OPT_START_ENABLED = 0, + parameter [0:0] OPT_FIXED_ALARM_TIME = 0 + // }}} + ) ( + // {{{ + input wire i_clk, i_reset, // - i_wr, i_clear, i_enable, i_alarm_time, i_valid, + input wire [21:0] i_now, // - o_data, o_alarm); - parameter [0:0] OPT_PREVALIDATED_INPUT = 1'b0; - parameter [21:0] OPT_INITIAL_ALARM_TIME = 0; - parameter [0:0] OPT_START_ENABLED = 0; - parameter [0:0] OPT_FIXED_ALARM_TIME = 0; - // - input wire i_clk, i_reset; - // - input wire [21:0] i_now; - // - input wire i_wr; - input wire i_enable, i_clear; - input wire [21:0] i_alarm_time; - input wire [2:0] i_valid; - // - output wire [31:0] o_data; - output wire o_alarm; + input wire i_wr, + input wire i_clear, i_enable, + input wire [21:0] i_alarm_time, + input wire [2:0] i_valid, + // + output wire [31:0] o_data, + output wire o_alarm + // }}} + ); + + // Signal declarations + // {{{ + reg [2:0] pre_valid; + reg [21:0] validated_alarm_time; + reg [21:0] alarm_time, past_time; + reg enabled, // Whether the alarm is enabled + tripped; // Whether the alarm has tripped + // }}} // // The alarm code @@ -70,20 +80,22 @@ module rtcalarm(i_clk, i_reset, i_now, // can come and see that the alarm tripped. // // - reg [21:0] alarm_time, past_time; - reg enabled, // Whether the alarm is enabled - tripped; // Whether the alarm has tripped + // enabled + // {{{ initial enabled = OPT_START_ENABLED; always @(posedge i_clk) if (i_reset) enabled <= OPT_START_ENABLED; else if (i_wr) enabled <= i_enable; + // }}} always @(posedge i_clk) past_time <= i_now; + // tripped + // {{{ initial tripped= 1'b0; always @(posedge i_clk) if (i_reset) @@ -92,21 +104,22 @@ module rtcalarm(i_clk, i_reset, i_now, tripped <= 1'b1; else if ((i_wr)&&(i_clear)) tripped <= 1'b0; + // }}} - reg [2:0] pre_valid; - reg [21:0] validated_alarm_time; + // pre_valid, validated_alarm_time + // {{{ generate if (OPT_PREVALIDATED_INPUT) begin : INPUT_IS_VALID - + // {{{ always @(*) pre_valid = ((!OPT_FIXED_ALARM_TIME)&&(i_wr)) ? i_valid : 0; always @(*) validated_alarm_time = i_valid; - + // }}} end else begin : CHECK_INPUT_VALIDITY - + // {{{ initial pre_valid = 0; always @(posedge i_clk) if ((i_reset)||(!i_wr)||(OPT_FIXED_ALARM_TIME)) @@ -128,9 +141,12 @@ module rtcalarm(i_clk, i_reset, i_now, always @(posedge i_clk) validated_alarm_time <= i_alarm_time; - + // }}} end endgenerate + // }}} + // alarm_time + // {{{ initial alarm_time = OPT_INITIAL_ALARM_TIME; always @(posedge i_clk) if (i_reset) @@ -147,16 +163,27 @@ module rtcalarm(i_clk, i_reset, i_now, if (pre_valid[2]) // Hours alarm_time[21:16] <= validated_alarm_time[21:16]; end + // }}} assign o_data = { 6'h0, tripped, enabled, 2'b00, alarm_time }; assign o_alarm = tripped; // Make verilator happy + // {{{ // verilator lint_off UNUSED - // wire [6:0] unused; - // assign unused = { i_wb_cyc, i_wb_data[31:26] }; + // wire unused; + // assign unused = &{ 1'b0, i_wb_cyc, i_wb_data[31:26] }; // verilator lint_on UNUSED - + // }}} +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal properties +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// `ifdef FORMAL `ifdef RTCALARM `define ASSUME assume @@ -247,6 +274,12 @@ module rtcalarm(i_clk, i_reset, i_now, if ((f_past_valid)&&($past(i_wr))&&(!$past(i_reset))) `ASSERT(enabled == $past(i_enable)); + //////////////////////////////////////////////////////////////////////// + // + // Cover checks + // {{{ + //////////////////////////////////////////////////////////////////////// + // always @(posedge i_clk) if ((f_past_valid)&&(!$past(tripped))) cover(tripped); @@ -254,6 +287,7 @@ module rtcalarm(i_clk, i_reset, i_now, always @(posedge i_clk) if ((f_past_valid)&&($past(tripped))) cover(!tripped); - + // }}} `endif +// }}} endmodule diff --git a/rtl/rtc/rtcbare.v b/rtl/rtc/rtcbare.v index 2e0ff57..3394e60 100644 --- a/rtl/rtc/rtcbare.v +++ b/rtl/rtc/rtcbare.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: rtcbare.v -// +// {{{ // Project: A Wishbone Controlled Real--time Clock Core, w/ GPS synch // // Purpose: This is the bare RTC clock logic. It accepts an (optional) @@ -24,9 +24,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -41,8 +41,9 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // // @@ -50,41 +51,54 @@ // // `default_nettype none -// -module rtcbare(i_clk, i_reset, +// }}} +module rtcbare #( + // {{{ + // Set OPT_PREVALIDATED_INPUT to 1'b1 if the instantiating + // module will never set i_wr true with invalid BCD data in + // i_data. Otherwise, setting it to zero will cause a + // validation check, and ignore any incoming values that are + // not valid BCD on a bytewise level. + parameter [0:0] OPT_PREVALIDATED_INPUT = 1'b0 + // }}} + ) ( + // {{{ + input wire i_clk, i_reset, // Wishbone interface - i_pps, i_wr, i_data, i_valid, + input wire i_pps, i_wr, + input wire [21:0] i_data, + input wire [2:0] i_valid, // Output registers - o_data, // multiplexed based upon i_wb_addr + output wire [21:0] o_data, // multiplexed based on i_wb_adr // A once-per-day strobe on the last clock of the day - o_ppd); - // - // Set OPT_PREVALIDATED_INPUT to 1'b1 if the instantiating module - // will never set i_wr true with invalid BCD data in i_data. - // Otherwise, setting it to zero will cause a validation check, - // and ignore any incoming values that are not valid BCD on a bytewise - // level. - parameter [0:0] OPT_PREVALIDATED_INPUT = 1'b0; - // - input wire i_clk, i_reset; - // - input wire i_pps, i_wr; - input wire [21:0] i_data; - input wire [2:0] i_valid; - output wire [21:0] o_data; - output wire o_ppd; + output wire o_ppd + // }}} + ); + // Signal declarations + // {{{ reg [21:0] bcd_clock, next_clock; reg [5:0] carry; reg pre_ppd; + reg [2:0] pre_valid; + reg [21:0] pre_bcd_clock; + + reg [2:0] suppressed, suppress_count; + // }}} + + // pre_ppd + // {{{ initial pre_ppd = 1'b0; always @(posedge i_clk) if (i_reset) pre_ppd <= 1'b0; else pre_ppd <= (bcd_clock == 22'h23_59_59); + // }}} + // carry, next_clock + // {{{ initial carry = 0; initial next_clock = 22'h00_00_01; always @(posedge i_clk) @@ -148,18 +162,14 @@ module rtcbare(i_clk, i_reset, else next_clock[21:20] <= bcd_clock[21:20]; end + // }}} - // - // + // pre_bcd_clock, pre_valid + // {{{ // Validate the input before setting the clock - // - // - reg [2:0] pre_valid; - reg [21:0] pre_bcd_clock; - generate if (OPT_PREVALIDATED_INPUT) begin : NO_VALIDATION_REQUIRED - + // {{{ // Write data through with no check // This can be combinatorial, with no clock required. // @@ -171,9 +181,9 @@ module rtcbare(i_clk, i_reset, always @(*) pre_bcd_clock = i_data; - + // }}} end else begin : VALIDATE_INPUT_BCD - // + // {{{ // Double check that the input contains valid BCD data // // We'll use this to prevent a write given invalid data @@ -199,12 +209,12 @@ module rtcbare(i_clk, i_reset, always @(posedge i_clk) pre_bcd_clock <= i_data; - + // }}} end endgenerate + // }}} - - reg [2:0] suppressed, suppress_count; - + // suprpressed, suppress_count + // {{{ initial suppressed = 3'h7; initial suppress_count = 3'h5; always @(posedge i_clk) @@ -222,8 +232,10 @@ module rtcbare(i_clk, i_reset, suppress_count <= suppress_count - 1; else suppressed <= 0; + // }}} - + // bcd_clock + // {{{ initial bcd_clock = 0; always @(posedge i_clk) if (i_reset) @@ -245,10 +257,19 @@ module rtcbare(i_clk, i_reset, if (pre_valid[2]) bcd_clock[21:16] <= pre_bcd_clock[21:16]; end + // }}} assign o_data = bcd_clock; assign o_ppd = (pre_ppd)&&(i_pps); - +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal properties +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// `ifdef FORMAL `ifdef RTCBARE `define ASSUME assume @@ -357,7 +378,6 @@ module rtcbare(i_clk, i_reset, always @(*) if (suppressed[1]) `ASSERT(suppressed[2]); - - `endif +// }}}} endmodule diff --git a/rtl/rtc/rtcdate.v b/rtl/rtc/rtcdate.v index b02032b..5021c2c 100644 --- a/rtl/rtc/rtcdate.v +++ b/rtl/rtc/rtcdate.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: rtcdate.v -// +// {{{ // Project: A Wishbone Controlled Real--time Clock Core // // Purpose: @@ -27,9 +27,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -44,8 +44,9 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // // @@ -53,42 +54,60 @@ // // `default_nettype none -// -module rtcdate(i_clk, i_ppd, i_wb_cyc, i_wb_stb, i_wb_we, i_wb_data, i_wb_sel, - o_wb_stall, o_wb_ack, o_wb_data); - parameter [29:0] INITIAL_DATE = 30'h20000101; - input wire i_clk; - // A one part per day signal, i.e. basically a clock enable line that - // controls when the beginning of the day happens. This line should - // be high on the very last second of any day in order for the rtcdate - // module to always have the right date. - input wire i_ppd; - // Wishbone inputs - input wire i_wb_cyc, i_wb_stb, i_wb_we; - input wire [31:0] i_wb_data; - input wire [3:0] i_wb_sel; - // Wishbone outputs - output wire o_wb_stall; - output reg o_wb_ack; - output wire [31:0] o_wb_data; - +// }}} +module rtcdate #( + parameter [29:0] INITIAL_DATE = 30'h20000101 + ) ( + // {{{ + input wire i_clk, + // A one part per day signal, i.e. basically a clock enable + // line that controls when the beginning of the day happens. + // This line should be high on the very last second of any day + // in order for the rtcdate module to always have the right + // date. + input wire i_ppd, + // Wishbone inputs + input wire i_wb_cyc, i_wb_stb, i_wb_we, + input wire [31:0] i_wb_data, + input wire [3:0] i_wb_sel, + // Wishbone outputs + output wire o_wb_stall, + output reg o_wb_ack, + output wire [31:0] o_wb_data + // }}} + ); + + // Signal declarations + // {{{ wire update; reg [9:0] r_block_updates; + reg [5:0] r_day; + reg [4:0] r_mon; + reg [13:0] r_year; + + reg last_day_of_month, last_day_of_year, is_leap_year; + reg [5:0] days_per_month; + reg year_divisible_by_four, century_year, four_century_year; + reg [5:0] next_day, fixd_day; + reg [4:0] next_mon, fixd_mon; + reg [13:0] next_year; + reg [2:0] next_year_c; + // }}} + + // r_block_updates + // {{{ initial r_block_updates = 10'h3ff; always @(posedge i_clk) if ((i_wb_we)&&(i_wb_stb)) r_block_updates <= 10'h3ff; else r_block_updates <= { r_block_updates[8:0], 1'b0 }; + // }}} assign update = (i_ppd)&&(!r_block_updates[9]); - reg [5:0] r_day; - reg [4:0] r_mon; - reg [13:0] r_year; - - reg last_day_of_month, last_day_of_year, is_leap_year; - reg [5:0] days_per_month; + // days_per_month + // {{{ initial days_per_month = 6'h31; // Remember, this is BCD always @(posedge i_clk) begin // Clock 3 @@ -108,6 +127,15 @@ module rtcdate(i_clk, i_ppd, i_wb_cyc, i_wb_stb, i_wb_we, i_wb_data, i_wb_sel, default: days_per_month <= 6'h31; // Invalid month endcase end + // }}} + + //////////////////////////////////////////////////////////////////////// + // + // Years + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // initial last_day_of_month = 1'b0; always @(posedge i_clk) // Clock 4 @@ -118,23 +146,33 @@ module rtcdate(i_clk, i_ppd, i_wb_cyc, i_wb_stb, i_wb_we, i_wb_data, i_wb_sel, last_day_of_year <= (last_day_of_month) && (r_mon == 5'h12); - reg year_divisible_by_four, century_year, four_century_year; initial year_divisible_by_four = 1'b0; - initial century_year = 1'b0; - initial four_century_year = 1'b0; - initial is_leap_year = 1'b0; always @(posedge i_clk) // Clock 1 year_divisible_by_four<= ((!r_year[0])&&(r_year[4]==r_year[1])); + + initial century_year = 1'b0; always @(posedge i_clk) // Clock 1 century_year <= (r_year[7:0] == 8'h00); + + initial four_century_year = 1'b0; always @(posedge i_clk) // Clock 1 four_century_year <= ((!r_year[8])&&((r_year[12]==r_year[9]))); + + initial is_leap_year = 1'b0; always @(posedge i_clk) // Clock 2 is_leap_year <= (year_divisible_by_four)&&((!century_year) ||((century_year)&&(four_century_year))); + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Days + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + // Adjust the day of month - reg [5:0] next_day, fixd_day; initial next_day = INITIAL_DATE[5:0]; always @(posedge i_clk) if (last_day_of_month) @@ -166,10 +204,17 @@ module rtcdate(i_clk, i_ppd, i_wb_cyc, i_wb_stb, i_wb_we, i_wb_data, i_wb_sel, if ((i_wb_stb)&&(i_wb_we)&&(!i_wb_data[7])&&(i_wb_sel[0])) r_day <= i_wb_data[5:0]; end + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Months + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // // Adjust the month of the year - reg [4:0] next_mon, fixd_mon; - + initial next_mon = 5'h01; always @(posedge i_clk) if (last_day_of_year) next_mon <= 5'h01; @@ -200,10 +245,16 @@ module rtcdate(i_clk, i_ppd, i_wb_cyc, i_wb_stb, i_wb_we, i_wb_data, i_wb_sel, if ((i_wb_stb)&&(i_wb_we)&&(!i_wb_data[15])&&(i_wb_sel[1])) r_mon <= i_wb_data[12:8]; end + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Years (again) + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // // Adjust the year - reg [13:0] next_year; - reg [2:0] next_year_c; initial next_year = INITIAL_DATE[29:16]; initial next_year_c = 0; always @(posedge i_clk) @@ -243,22 +294,40 @@ module rtcdate(i_clk, i_ppd, i_wb_cyc, i_wb_stb, i_wb_we, i_wb_data, i_wb_sel, &&(i_wb_sel[3:2]==2'b11)) r_year <= i_wb_data[29:16]; end + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Bus returns + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // initial o_wb_ack = 1'b0; always @(posedge i_clk) o_wb_ack <= (i_wb_stb); assign o_wb_stall = 1'b0; - assign o_wb_data = { 2'h0, r_year, 3'h0, r_mon, 2'h0, r_day }; + // }}} // Make Verilator happy + // {{{ // verilator lint_off UNUSED wire unused; - assign unused = &{ 1'b0, i_wb_cyc, i_wb_data[30], - i_wb_data[14:13], i_wb_data[6] }; + assign unused = &{ 1'b0, i_wb_cyc, i_wb_data[30], i_wb_data[14:13], + i_wb_data[6] }; // verilator lint_on UNUSED - + // }}} +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal properties +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// `ifdef FORMAL `ifdef RTCDATE `define ASSUME assume @@ -326,6 +395,6 @@ module rtcdate(i_clk, i_ppd, i_wb_cyc, i_wb_stb, i_wb_we, i_wb_data, i_wb_sel, assert(r_year[ 7: 4] <= 4'h9); assert(r_year[11: 8] <= 4'h9); end - `endif +// }}} endmodule diff --git a/rtl/rtc/rtclight.v b/rtl/rtc/rtclight.v index b0558c9..e919925 100644 --- a/rtl/rtc/rtclight.v +++ b/rtl/rtc/rtclight.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: rtclight.v -// +// {{{ // Project: A Wishbone Controlled Real--time Clock Core // // Purpose: Implement a real time clock, including alarm, count--down @@ -17,9 +17,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -34,8 +34,9 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // // @@ -43,35 +44,38 @@ // // `default_nettype none -// -module rtclight(i_clk, i_reset, +// }}} +module rtclight #( + // {{{ + parameter DEFAULT_SPEED = 32'd2814750, // 100 Mhz + parameter [0:0] OPT_TIMER = 1'b1, + parameter [0:0] OPT_STOPWATCH = 1'b1, + parameter [0:0] OPT_ALARM = 1'b1, + parameter [0:0] OPT_FIXED_SPEED = 1'b1 + // }}} + ) ( + // {{{ + input wire i_clk, i_reset, // Wishbone interface - i_wb_cyc, i_wb_stb, i_wb_we, i_wb_addr, i_wb_data, i_wb_sel, - o_wb_stall, o_wb_ack, o_wb_data, + input wire i_wb_cyc, i_wb_stb, i_wb_we, + input wire [2:0] i_wb_addr, + input wire [31:0] i_wb_data, + input wire [3:0] i_wb_sel, + // + output wire o_wb_stall, + output reg o_wb_ack, + output reg [31:0] o_wb_data, // Output controls - o_interrupt, + output wire o_interrupt, // A once-per-second strobe - o_pps, + o_pps, // A once-per-day strobe on the last clock of the day - o_ppd); - parameter DEFAULT_SPEED = 32'd2814750; // 100 Mhz - parameter [0:0] OPT_TIMER = 1'b1; - parameter [0:0] OPT_STOPWATCH = 1'b1; - parameter [0:0] OPT_ALARM = 1'b1; - parameter [0:0] OPT_FIXED_SPEED = 1'b1; - - input wire i_clk, i_reset; - // - input wire i_wb_cyc, i_wb_stb, i_wb_we; - input wire [2:0] i_wb_addr; - input wire [31:0] i_wb_data; - input wire [3:0] i_wb_sel; - // - output reg o_wb_ack; - output wire o_wb_stall; - output reg [31:0] o_wb_data; - output wire o_interrupt, o_pps, o_ppd; + o_ppd + // }}} + ); + // Signal declarations + // {{{ reg [31:0] ckspeed; wire [21:0] clock_data; @@ -82,7 +86,18 @@ module rtclight(i_clk, i_reset, reg ck_wr, tm_wr, al_wr, wr_zero; reg [31:0] wr_data; reg [2:0] wr_valid; + wire tm_int, al_int; + reg ck_carry; + reg [39:0] ck_counter; + wire ck_pps, ck_ppd; + reg ck_prepps; + reg [7:0] ck_sub; + wire sp_sel; + // }}} + + // ck_wr, tm_wr, al_wr + // {{{ initial ck_wr = 1'b0; initial tm_wr = 1'b0; initial al_wr = 1'b0; @@ -98,7 +113,10 @@ module rtclight(i_clk, i_reset, //sw_wr<=((i_wb_stb)&&(i_wb_addr==3'b010)&&(i_wb_we)); al_wr <= ((i_wb_stb)&&(i_wb_addr==3'b011)&&(i_wb_we)); end + // }}} + // wr_data, wr_valid, wr_zero + // {{{ always @(posedge i_clk) begin wr_data <= i_wb_data; @@ -110,31 +128,46 @@ module rtclight(i_clk, i_reset, &&(i_wb_data[21:16] <= 6'h23); wr_zero <= (i_wb_data[23:0]==0); end + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Sub-clock handling, PPS generation + // {{{ + //////////////////////////////////////////////////////////////////////// + // - wire tm_int, al_int; - - reg ck_carry; - reg [39:0] ck_counter; initial ck_carry = 1'b0; initial ck_counter = 40'h00; always @(posedge i_clk) { ck_carry, ck_counter } <= ck_counter + { 8'h00, ckspeed }; - wire ck_pps, ck_ppd; - reg ck_prepps; - reg [7:0] ck_sub; assign ck_pps = (ck_carry)&&(ck_prepps); assign o_pps = ck_pps; + always @(posedge i_clk) begin if (ck_carry) ck_sub <= ck_sub + 8'h1; ck_prepps <= (ck_sub == 8'hff); end - + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Bare clock + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // rtcbare clock(i_clk, i_reset, ck_pps, ck_wr, wr_data[21:0], wr_valid, clock_data, ck_ppd); - + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Timer + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // generate if (OPT_TIMER) begin rtctimer #(.LGSUBCK(8)) @@ -150,6 +183,14 @@ module rtclight(i_clk, i_reset, assign unused_timer = tm_wr; // Verilator lint_on UNUSED end endgenerate + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Stopwatch + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // generate if (OPT_STOPWATCH) begin @@ -174,6 +215,14 @@ module rtclight(i_clk, i_reset, assign sw_running = 0; end endgenerate + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Alarm + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // generate if (OPT_ALARM) begin @@ -191,6 +240,14 @@ module rtclight(i_clk, i_reset, assign unused_alarm = al_wr; // Verilator lint_on UNUSED end endgenerate + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Clock speedx control + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // // // The ckspeed register is equal to 2^48 divded by the number of @@ -200,7 +257,6 @@ module rtclight(i_clk, i_reset, // device. Further, because this is only the lower 32 bits of a // 48 bit counter per seconds, the clock jitter is kept below // 1 part in 65 thousand. - wire sp_sel; generate if (!OPT_FIXED_SPEED) begin : ADJUSTABLE_CLOCK_RATE @@ -218,13 +274,14 @@ module rtclight(i_clk, i_reset, ckspeed = DEFAULT_SPEED; end endgenerate - - assign o_interrupt = tm_int || al_int; - - // A once-per day strobe, on the last second of the day so that the - // the next clock is the first clock of the day. This is useful for - // connecting this module to a year/month/date date/calendar module. - assign o_ppd = (ck_ppd); + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Bus returns + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // assign o_wb_stall = 1'b0; @@ -236,21 +293,34 @@ module rtclight(i_clk, i_reset, o_wb_ack <= i_wb_stb; always @(posedge i_clk) - case(i_wb_addr[2:0]) - 3'b000: o_wb_data <= { 10'h0, clock_data }; - 3'b001: o_wb_data <= timer_data; - 3'b010: o_wb_data <= { sw_running, stopwatch_data }; - 3'b011: o_wb_data <= alarm_data; - 3'b100: o_wb_data <= ckspeed; - default: o_wb_data <= 32'h000; - endcase + case(i_wb_addr[2:0]) + 3'b000: o_wb_data <= { 10'h0, clock_data }; + 3'b001: o_wb_data <= timer_data; + 3'b010: o_wb_data <= { sw_running, stopwatch_data }; + 3'b011: o_wb_data <= alarm_data; + 3'b100: o_wb_data <= ckspeed; + default: o_wb_data <= 32'h000; + endcase + // }}} + + // o_ppd + // {{{ + // A once-per day strobe, on the last second of the day so that the + // the next clock is the first clock of the day. This is useful for + // connecting this module to a year/month/date date/calendar module. + assign o_ppd = (ck_ppd); + // }}} + + assign o_interrupt = tm_int || al_int; + // Make verilator hapy + // {{{ // verilator lint_off UNUSED wire unused; assign unused = &{ 1'b0, sp_sel, i_wb_cyc, wr_data[31:25], i_wb_sel[3] }; // verilator lint_on UNUSED - + // }}} `ifdef FORMAL // `ifdef RTCLIGHT diff --git a/rtl/rtc/rtcstopwatch.v b/rtl/rtc/rtcstopwatch.v index a770b09..3b19cdc 100644 --- a/rtl/rtc/rtcstopwatch.v +++ b/rtl/rtc/rtcstopwatch.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: rtcstopwatch.v -// +// {{{ // Project: A Wishbone Controlled Real--time Clock Core, w/ GPS synch // // Purpose: Implement a stop watch in BCD. @@ -10,9 +10,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -27,8 +27,9 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // // @@ -36,24 +37,31 @@ // // `default_nettype none -// -module rtcstopwatch(i_clk, i_reset, i_ckstep, - i_clear, i_start, i_stop, o_value, o_running); - // - input wire i_clk, i_reset; - // - input wire [31:0] i_ckstep; - input wire i_clear, i_start, i_stop; - output wire [30:0] o_value; - output wire o_running; +// }}} +module rtcstopwatch( + // {{{ + input wire i_clk, i_reset, + // + input wire [31:0] i_ckstep, + input wire i_clear, i_start, i_stop, + output wire [30:0] o_value, + output wire o_running + // }}} + ); + // Signal declarations + // {{{ reg [30:0] counter; reg [45:0] sw_subticks; reg [36:0] sw_step; reg [13:0] last_step; reg [6:0] sw_carry; reg sw_ppms, carry, sw_running; + reg [30:0] next_sw; + // }}} + // i_ckstep + // {{{ // i_ckstep is the bottom 32 bits of a 48 counter step that rolls over // once per second. If we multiply by 100, we'll then have a 48 bit // counter step that will roll over once every 10 milliseconds. @@ -63,10 +71,13 @@ module rtcstopwatch(i_clk, i_reset, i_ckstep, sw_step <= { 1'b0, i_ckstep, 4'h0 } + { 2'b0, i_ckstep, 3'h0 } + { 5'h0, i_ckstep }; + // }}} always @(posedge i_clk) last_step <= sw_step[36:23]; + // sw_ppms, sw_subticks, carry + // {{{ initial sw_ppms = 0; initial sw_subticks = 0; initial carry = 0; @@ -83,6 +94,7 @@ module rtcstopwatch(i_clk, i_reset, i_ckstep, + {{(23){1'b0}}, carry }; end else sw_ppms <= 1'b0; + // }}} // // Stopwatch functionality @@ -95,7 +107,8 @@ module rtcstopwatch(i_clk, i_reset, i_ckstep, // will only clear it if it was already stopped. // - reg [30:0] next_sw; + // next_sw + // {{{ initial next_sw = 0; always @(posedge i_clk) if (i_reset || i_clear) @@ -167,30 +180,47 @@ module rtcstopwatch(i_clk, i_reset, i_ckstep, if (sw_carry[6]) next_sw[30:28] <= counter[30:28] + 1'b1; end + // }}} - + // counter + // {{{ initial counter = 31'h00000; always @(posedge i_clk) if (i_reset || i_clear) counter <= 0; else if ((sw_ppms)&&(sw_running)) counter <= next_sw; + // }}} + // sw_running + // {{{ initial sw_running = 0; always @(posedge i_clk) if (i_reset || i_stop) sw_running <= 1'b0; else if (i_start) sw_running <= 1'b1; + // }}} assign o_value = counter; assign o_running = sw_running; // Make verilator happy + // {{{ // verilator lint_off UNUSED - wire [2:0] unused; - assign unused = sw_step[2:0]; + wire unused; + assign unused = &{ 1'b0, sw_step[2:0] }; // verilator lint_on UNUSED + // }}} +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal properties +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// `ifdef FORMAL `ifdef STOPWATCH `define ASSUME assume @@ -246,4 +276,5 @@ module rtcstopwatch(i_clk, i_reset, i_ckstep, `ASSERT(!sw_ppms); `endif +// }}} endmodule diff --git a/rtl/rtc/rtctimer.v b/rtl/rtc/rtctimer.v index 232612d..48e9bae 100644 --- a/rtl/rtc/rtctimer.v +++ b/rtl/rtc/rtctimer.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: rtctimer.v -// +// {{{ // Project: A Wishbone Controlled Real--time Clock Core, w/ GPS synch // // Purpose: Implements a count down timer @@ -11,9 +11,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -28,34 +28,37 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // // `default_nettype none -// -module rtctimer(i_clk, i_reset, - i_sub_ck, i_wr, i_data, i_valid, i_zero, - o_data, o_interrupt); - parameter LGSUBCK = 2; - parameter [0:0] OPT_PREVALIDATED_INPUT = 1'b0; - parameter [21:0] OPT_FIXED_INTERVAL = 0; - // - input wire i_clk, i_reset; - // - input wire i_sub_ck; - // - input wire i_wr; - input wire [24:0] i_data; - input wire [2:0] i_valid; - input wire i_zero; - output wire [31:0] o_data; - output wire o_interrupt; - +// }}} +module rtctimer #( + // {{{ + parameter LGSUBCK = 2 + // }}} + ) ( + // {{{ + input wire i_clk, i_reset, + // + input wire i_sub_ck, + // + input wire i_wr, + input wire [24:0] i_data, + input wire [2:0] i_valid, + input wire i_zero, + output wire [31:0] o_data, + output wire o_interrupt + // }}} + ); + + // Signal declarations + // {{{ reg [23:0] bcd_timer; // wire [6:0] bcd_hours, bcd_minutes, bcd_seconds; // assign bcd_seconds = bcd_timer[ 6:0]; @@ -67,6 +70,13 @@ module rtctimer(i_clk, i_reset, reg [4:0] tmr_carry, pre_tmr_carry; reg last_tick; + reg tm_pre_pps, tm_int, tm_running, tm_alarm; + wire tm_stopped, tm_pps; + reg [(LGSUBCK-1):0] tm_sub; + // }}} + + // pre_tmr_carry, tmr_carry, next_timer + // {{{ initial tmr_carry = 0; initial next_timer = 0; always @(posedge i_clk) @@ -86,6 +96,7 @@ module rtctimer(i_clk, i_reset, // Keep unused bits at zero next_timer <= 24'h00; // Seconds + // {{{ if (tmr_carry[0]) next_timer[3:0] <= 4'h9; else @@ -97,8 +108,10 @@ module rtctimer(i_clk, i_reset, next_timer[ 6: 4] <= (bcd_timer[ 6: 4]-3'h1); else next_timer[6:4] <= bcd_timer[6:4]; + // }}} // Minutes + // {{{ if (tmr_carry[2]) next_timer[11:8] <= 4'h9; else if (tmr_carry[1]) @@ -111,8 +124,10 @@ module rtctimer(i_clk, i_reset, next_timer[14:12] <= (bcd_timer[14:12]-3'h1); else next_timer[14:12] <= bcd_timer[14:12]; + // }}} // Hours + // {{{ if (tmr_carry[4]) next_timer[19:16] <= 4'h9; else if (tmr_carry[3]) @@ -124,21 +139,24 @@ module rtctimer(i_clk, i_reset, next_timer[23:20] <= (bcd_timer[23:20]-4'h1); else next_timer[23:20] <= bcd_timer[23:20]; + // }}} end + // }}} - reg tm_pre_pps, tm_int, tm_running, tm_alarm; - wire tm_stopped, tm_pps; assign tm_stopped = !tm_running; - reg [(LGSUBCK-1):0] tm_sub; - + // tm_sub + // {{{ initial tm_sub = 0; always @(posedge i_clk) if ((i_reset)||((i_wr)&&(!tm_running)&&(&i_valid)&&(!i_zero))) tm_sub <= 0; else if ((i_sub_ck)&&(tm_running)) tm_sub <= tm_sub + 1; + // }}} + // tm_pre_pps, tm_pps + // {{{ initial tm_pre_pps = 1'b0; always @(posedge i_clk) if ((i_reset)||((i_wr)&&(!tm_running))) @@ -149,12 +167,14 @@ module rtctimer(i_clk, i_reset, tm_pre_pps <= (&tm_sub); assign tm_pps = (tm_pre_pps)&&(i_sub_ck); + // }}} + // bcd_timer, tm_int, tm_running, tm_alarm + // {{{ initial bcd_timer = 24'h00; initial tm_int = 1'b0; initial tm_running = 1'b0; initial tm_alarm = 1'b0; - always @(posedge i_clk) if (i_reset) begin @@ -199,16 +219,27 @@ module rtctimer(i_clk, i_reset, tm_alarm <= 1'b0; end end + // }}} assign o_interrupt = tm_int; assign o_data = { 6'h00, tm_alarm, tm_running, bcd_timer }; // Make Verilator happy + // {{{ // verilator lint_off UNUSED - // wire [6:0] unused; - // assign unused = i_data[31:25]; + // wire unused; + // assign unused = &{ 1'b0, i_data[31:25] }; // verilator lint_on UNUSED - + // }}} +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal properties +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// `ifdef FORMAL `ifdef RTCTIMER `define ASSUME assume @@ -329,4 +360,5 @@ module rtctimer(i_clk, i_reset, if ((f_past_valid)&&(!$past(i_reset))&&($past(tm_alarm))) cover(!tm_alarm); `endif +// }}} endmodule diff --git a/rtl/sdspi/sdspi.v b/rtl/sdspi/sdspi.v index d053553..a0351c7 100644 --- a/rtl/sdspi/sdspi.v +++ b/rtl/sdspi/sdspi.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: sdspi.v -// +// {{{ // Project: SD-Card controller, using a shared SPI interface // // Purpose: SD Card controller, using SPI interface with the card and @@ -13,9 +13,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2016-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2016-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -30,117 +30,104 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none -// -module sdspi(i_clk, i_sd_reset, +// }}} +module sdspi #( + // {{{ + parameter [0:0] OPT_CARD_DETECT = 1'b1, + // + // LGFIFOLN defines the size of the internal memory in words. + // An LGFIFOLN of 7 is appropriate for a 2^(7+2)=512 byte FIFO + parameter LGFIFOLN = 7, + parameter POWERUP_IDLE = 1000, + // + // Many SD-Cards require a minimum number of SPI clocks to get + // them started. STARTUP_CLOCKS defines this number. Set this + // to zero if you don't want to use this initialization + // sequence. + parameter STARTUP_CLOCKS = 75, + // + // For my first design, using an 80MHz clock, 7 bits to the + // clock divider was plenty. Now that I'm starting to use + // faster and faster designs, it becomes important to + // parameterize the number of bits in the clock divider. More + // than 8, however, and the interface will need to change. + parameter CKDIV_BITS = 8, + // + // The SPI frequency is given by the system clock frequency + // divided by a (clock_divider + 1). INITIAL_CLKDIV provides + // an initial value for this clock divider. + parameter [CKDIV_BITS-1:0] INITIAL_CLKDIV = 8'h7c, + // + // When I originally built this SDSPI controller, it was for an + // environment where the SPI was shared. Doing this requires + // feedback from an arbiter, to know when one SPI device has + // the bus or not. This feedback is provided in i_bus_grant. + // If you don't have an arbiter, just set i_bus_grant to the + // constant 1'b1 and set OPT_SPI_ARBITRATION to 1'b0 to remove + // this extra logic. + parameter [0:0] OPT_SPI_ARBITRATION = 1'b0, + // + // + parameter [0:0] OPT_EXTRA_WB_CLOCK = 1'b0, + // + // + // + localparam AW = 2, DW = 32 + // }}} + ) ( + // {{{ + input wire i_clk, i_sd_reset, // Wishbone interface - i_wb_cyc, i_wb_stb, i_wb_we, i_wb_addr, i_wb_data, i_wb_sel, - o_wb_stall, o_wb_ack, o_wb_data, + // {{{ + input wire i_wb_cyc, i_wb_stb, i_wb_we, + input wire [AW-1:0] i_wb_addr, + input wire [DW-1:0] i_wb_data, + input wire [DW/8-1:0] i_wb_sel, + output wire o_wb_stall, + output reg o_wb_ack, + output reg [DW-1:0] o_wb_data, + // }}} // SDCard interface - o_cs_n, o_sck, o_mosi, i_miso, i_card_detect, + // {{{ + output wire o_cs_n, o_sck, o_mosi, + input wire i_miso, i_card_detect, + // }}} // Our interrupt - o_int, - // And whether or not we own the bus - i_bus_grant, + output reg o_int, + // .. and whether or not we can use the SPI port + input wire i_bus_grant, // And some wires for debugging it all - o_debug); - parameter [0:0] OPT_CARD_DETECT = 1'b1; - // - // LGFIFOLN defines the size of the internal memory in words. An - // LGFIFOLN of 7 is appropriate for a 2^(7+2)=512 byte FIFO - parameter LGFIFOLN = 7; - parameter POWERUP_IDLE = 1000; - // - // Many SD-Cards require a minimum number of SPI clocks to get them - // started. STARTUP_CLOCKS defines this number. Set this to zero - // if you don't want to use this initialization sequence. - parameter STARTUP_CLOCKS = 75; - // - // For my first design, using an 80MHz clock, 7 bits to the clock - // divider was plenty. Now that I'm starting to use faster and faster - // designs, it becomes important to parameterize the number of bits - // in the clock divider. More than 8, however, and the interface - // will need to change. - parameter CKDIV_BITS = 8; - // - // The SPI frequency is given by the system clock frequency divided - // by a (clock_divider + 1). INITIAL_CLKDIV provides an initial value - // for this clock divider. - parameter [CKDIV_BITS-1:0] INITIAL_CLKDIV = 8'h7c; - // - // When I originally built this SDSPI controller, it was for an - // environment where the SPI was shared. Doing this requires feedback - // from an arbiter, to know when one SPI device has the bus or not. - // This feedback is provided in i_bus_grant. If you don't have an - // arbiter, just set i_bus_grant to the constant 1'b1 and set - // OPT_SPI_ARBITRATION to 1'b0 to remove this extra logic. - parameter [0:0] OPT_SPI_ARBITRATION = 1'b0; - // - // - parameter [0:0] OPT_EXTRA_WB_CLOCK = 1'b0; - // - // - // - localparam AW = 2, DW = 32; + output reg [DW-1:0] o_debug + // }}} + ); + + // Local declarations + // {{{ localparam [1:0] SDSPI_CMD_ADDRESS = 2'b00, SDSPI_DAT_ADDRESS = 2'b01, SDSPI_FIFO_A_ADDR = 2'b10, SDSPI_FIFO_B_ADDR = 2'b11; - localparam [1:0] SDSPI_EXPECT_R1 = 2'b00, - SDSPI_EXPECT_R1B = 2'b01, - SDSPI_EXPECT_R3 = 2'b10; - - localparam [2:0] SDSPI_RSP_NONE = 3'h0, // No response yet from device - SDSPI_RSP_BSYWAIT = 3'h1, // R1b, wait for device to send nonzero - SDSPI_RSP_GETWORD = 3'h2, // Get 32-bit data word from device - SDSPI_RSP_GETTOKEN = 3'h4, // Write to device, read from FIFO, wait for completion token - SDSPI_RSP_WAIT_WHILE_BUSY =3'h5,// Read from device - SDSPI_RSP_RDCOMPLETE = 3'h6, - SDSPI_RSP_WRITING = 3'h7; // Read from device, write into FIFO localparam BLKBASE = 16; - // - // - input wire i_clk, i_sd_reset; - // - input wire i_wb_cyc, i_wb_stb, i_wb_we; - input wire [AW-1:0] i_wb_addr; - input wire [DW-1:0] i_wb_data; - input wire [DW/8-1:0] i_wb_sel; - output wire o_wb_stall; - output reg o_wb_ack; - output reg [DW-1:0] o_wb_data; - // - output wire o_cs_n, o_sck, o_mosi; - input wire i_miso, i_card_detect; - // The interrupt - output reg o_int; - // .. and whether or not we can use the SPI port - input wire i_bus_grant; - // - output reg [DW-1:0] o_debug; reg dbg_trigger; // // Command register bit definitions // localparam CARD_REMOVED_BIT= 18, - CRCERR_BIT = 16, + // CRCERR_BIT = 16, ERR_BIT = 15, FIFO_ID_BIT = 12, USE_FIFO_BIT = 11, FIFO_WRITE_BIT = 10; - // - // Some WB simplifications: - // reg r_cmd_busy; wire wb_stb, write_stb, wb_cmd_stb, new_data; @@ -149,9 +136,71 @@ module sdspi(i_clk, i_sd_reset, reg [1:0] pipe_addr; reg dly_stb; + reg [31:0] fifo_a [0:((1< for a copy. +// }}} +// License: GPL, v3, as defined and found on www.gnu.org, +// {{{ +// http://www.gnu.org/licenses/gpl.html // -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations -// under the License. // //////////////////////////////////////////////////////////////////////////////// // // `default_nettype none -// -module skidbuffer(i_clk, i_reset, - i_valid, o_ready, i_data, - o_valid, i_ready, o_data); - parameter [0:0] OPT_LOWPOWER = 0; - parameter [0:0] OPT_OUTREG = 1; - // - parameter [0:0] OPT_PASSTHROUGH = 0; - parameter DW = 8; - input wire i_clk, i_reset; - input wire i_valid; - output reg o_ready; - input wire [DW-1:0] i_data; - output reg o_valid; - input wire i_ready; - output reg [DW-1:0] o_data; +// }}} +module skidbuffer #( + // {{{ + parameter [0:0] OPT_LOWPOWER = 0, + parameter [0:0] OPT_OUTREG = 1, + // + parameter [0:0] OPT_PASSTHROUGH = 0, + parameter DW = 8, + parameter [0:0] OPT_INITIAL = 1'b1 + // }}} + ) ( + // {{{ + input wire i_clk, i_reset, + input wire i_valid, + output reg o_ready, + input wire [DW-1:0] i_data, + output reg o_valid, + input wire i_ready, + output reg [DW-1:0] o_data + // }}} + ); reg [DW-1:0] r_data; generate if (OPT_PASSTHROUGH) - begin - + begin : PASSTHROUGH + // {{{ always @(*) - o_ready = i_ready; - always @(*) - o_valid = i_valid; + { o_valid, o_ready } = { i_valid, i_ready }; + always @(*) if (!i_valid && OPT_LOWPOWER) o_data = 0; @@ -111,13 +120,15 @@ module skidbuffer(i_clk, i_reset, always @(*) r_data = 0; - end else begin - // + // }}} + end else begin : LOGIC // We'll start with skid buffer itself - // + // {{{ reg r_valid; - initial r_valid = 0; + // r_valid + // {{{ + initial if (OPT_INITIAL) r_valid = 0; always @(posedge i_clk) if (i_reset) r_valid <= 0; @@ -126,8 +137,11 @@ module skidbuffer(i_clk, i_reset, r_valid <= 1; else if (i_ready) r_valid <= 0; + // }}} - initial r_data = 0; + // r_data + // {{{ + initial if (OPT_INITIAL) r_data = 0; always @(posedge i_clk) if (OPT_LOWPOWER && i_reset) r_data <= 0; @@ -135,19 +149,29 @@ module skidbuffer(i_clk, i_reset, r_data <= 0; else if ((!OPT_LOWPOWER || !OPT_OUTREG || i_valid) && o_ready) r_data <= i_data; + // }}} + // o_ready + // {{{ always @(*) o_ready = !r_valid; + // }}} // // And then move on to the output port // if (!OPT_OUTREG) - begin - + begin : NET_OUTPUT + // Outputs are combinatorially determined from inputs + // {{{ + // o_valid + // {{{ always @(*) o_valid = !i_reset && (i_valid || r_valid); + // }}} + // o_data + // {{{ always @(*) if (r_valid) o_data = r_data; @@ -155,16 +179,24 @@ module skidbuffer(i_clk, i_reset, o_data = i_data; else o_data = 0; - end else begin - - initial o_valid = 0; + // }}} + // }}} + end else begin : REG_OUTPUT + // Register our outputs + // {{{ + // o_valid + // {{{ + initial if (OPT_INITIAL) o_valid = 0; always @(posedge i_clk) if (i_reset) o_valid <= 0; else if (!o_valid || i_ready) o_valid <= (i_valid || r_valid); + // }}} - initial o_data = 0; + // o_data + // {{{ + initial if (OPT_INITIAL) o_data = 0; always @(posedge i_clk) if (OPT_LOWPOWER && i_reset) o_data <= 0; @@ -178,17 +210,53 @@ module skidbuffer(i_clk, i_reset, else o_data <= 0; end - end + // }}} + // }}} + end + // }}} end endgenerate - +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal properties +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// `ifdef FORMAL +`ifdef SKIDBUFFER +`define ASSUME assume +`else +`define ASSUME assert +`endif + + reg f_past_valid; + + initial f_past_valid = 0; + always @(posedge i_clk) + f_past_valid <= 1; + + always @(*) + if (!f_past_valid) + assume(i_reset); + + //////////////////////////////////////////////////////////////////////// + // + // Incoming stream properties / assumptions + // {{{ + //////////////////////////////////////////////////////////////////////// + // + always @(posedge i_clk) + if (!f_past_valid) + begin + `ASSUME(!i_valid || !OPT_INITIAL); + end else if ($past(i_valid && !o_ready && !i_reset) && !i_reset) + `ASSUME(i_valid && $stable(i_data)); + `ifdef VERIFIC `define FORMAL_VERIFIC -`endif -`endif -// -`ifdef FORMAL_VERIFIC // Reset properties property RESET_CLEARS_IVALID; @(posedge i_clk) i_reset |=> !i_valid; @@ -204,79 +272,193 @@ module skidbuffer(i_clk, i_reset, `else assert property (IDATA_HELD_WHEN_NOT_READY); `endif +`endif + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Outgoing stream properties / assumptions + // {{{ + //////////////////////////////////////////////////////////////////////// + // generate if (!OPT_PASSTHROUGH) begin - assert property (@(posedge i_clk) - OPT_OUTREG && i_reset |=> o_ready && !o_valid); - - assert property (@(posedge i_clk) - !OPT_OUTREG && i_reset |-> !o_valid); + always @(posedge i_clk) + if (!f_past_valid) // || $past(i_reset)) + begin + // Following any reset, valid must be deasserted + assert(!o_valid || !OPT_INITIAL); + end else if ($past(o_valid && !i_ready && !i_reset) && !i_reset) + // Following any stall, valid must remain high and + // data must be preserved + assert(o_valid && $stable(o_data)); + end endgenerate + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Other properties + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + generate if (!OPT_PASSTHROUGH) + begin // Rule #1: - // Once o_valid goes high, the data cannot change until the - // clock after i_ready - assert property (@(posedge i_clk) - disable iff (i_reset) - o_valid && !i_ready - |=> (o_valid && $stable(o_data))); + // If registered, then following any reset we should be + // ready for a new request + // {{{ + always @(posedge i_clk) + if (f_past_valid && $past(OPT_OUTREG && i_reset)) + assert(o_ready); + // }}} // Rule #2: // All incoming data must either go directly to the // output port, or into the skid buffer + // {{{ +`ifndef VERIFIC + always @(posedge i_clk) + if (f_past_valid && !$past(i_reset) && $past(i_valid && o_ready + && (!OPT_OUTREG || o_valid) && !i_ready)) + assert(!o_ready && r_data == $past(i_data)); +`else assert property (@(posedge i_clk) disable iff (i_reset) (i_valid && o_ready && (!OPT_OUTREG || o_valid) && !i_ready) |=> (!o_ready && r_data == $past(i_data))); +`endif + // }}} // Rule #3: // After the last transaction, o_valid should become idle + // {{{ if (!OPT_OUTREG) begin - - assert property (@(posedge i_clk) - disable iff (i_reset) - i_ready |=> (o_valid == i_valid)); - + // {{{ + always @(posedge i_clk) + if (f_past_valid && !$past(i_reset) && !i_reset + && $past(i_ready)) + begin + assert(o_valid == i_valid); + assert(!i_valid || (o_data == i_data)); + end + // }}} end else begin + // {{{ + always @(posedge i_clk) + if (f_past_valid && !$past(i_reset)) + begin + if ($past(i_valid && o_ready)) + assert(o_valid); - assert property (@(posedge i_clk) - disable iff (i_reset) - i_valid && o_ready |=> o_valid); - - assert property (@(posedge i_clk) - disable iff (i_reset) - !i_valid && o_ready && i_ready |=> !o_valid); - + if ($past(!i_valid && o_ready && i_ready)) + assert(!o_valid); + end + // }}} end + // }}} // Rule #4 - // Same thing, but this time for r_valid - assert property (@(posedge i_clk) - !o_ready && i_ready |=> o_ready); - + // Same thing, but this time for o_ready + // {{{ + always @(posedge i_clk) + if (f_past_valid && $past(!o_ready && i_ready)) + assert(o_ready); + // }}} + // If OPT_LOWPOWER is set, o_data and r_data both need to be + // zero any time !o_valid or !r_valid respectively + // {{{ if (OPT_LOWPOWER) begin - // - // If OPT_LOWPOWER is set, o_data and r_data both need - // to be zero any time !o_valid or !r_valid respectively - assert property (@(posedge i_clk) - (OPT_OUTREG || !i_reset) && !o_valid |-> o_data == 0); - - assert property (@(posedge i_clk) - o_ready |-> r_data == 0); - - // else - // if OPT_LOWPOWER isn't set, we can lower our - // logic count by not forcing these values to zero. - end + always @(*) + if ((OPT_OUTREG || !i_reset) && !o_valid) + assert(o_data == 0); + always @(*) + if (o_ready) + assert(r_data == 0); + + end + // }}} + end endgenerate + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Cover checks + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // `ifdef SKIDBUFFER + generate if (!OPT_PASSTHROUGH) + begin reg f_changed_data; + initial f_changed_data = 0; + always @(posedge i_clk) + if (i_reset) + f_changed_data <= 1; + else if (i_valid && $past(!i_valid || o_ready)) + begin + if (i_data != $past(i_data + 1)) + f_changed_data <= 0; + end else if (!i_valid && i_data != 0) + f_changed_data <= 0; + + +`ifndef VERIFIC + reg [3:0] cvr_steps, cvr_hold; + + always @(posedge i_clk) + if (i_reset) + begin + cvr_steps <= 0; + cvr_hold <= 0; + end else begin + cvr_steps <= cvr_steps + 1; + cvr_hold <= cvr_hold + 1; + case(cvr_steps) + 0: if (o_valid || i_valid) + cvr_steps <= 0; + 1: if (!i_valid || !i_ready) + cvr_steps <= 0; + 2: if (!i_valid || !i_ready) + cvr_steps <= 0; + 3: if (!i_valid || !i_ready) + cvr_steps <= 0; + 4: if (!i_valid || i_ready) + cvr_steps <= 0; + 5: if (!i_valid || !i_ready) + cvr_steps <= 0; + 6: if (!i_valid || !i_ready) + cvr_steps <= 0; + 7: if (!i_valid || i_ready) + cvr_steps <= 0; + 8: if (!i_valid || i_ready) + cvr_steps <= 0; + 9: if (!i_valid || !i_ready) + cvr_steps <= 0; + 10: if (!i_valid || !i_ready) + cvr_steps <= 0; + 11: if (!i_valid || !i_ready) + cvr_steps <= 0; + 12: begin + cvr_steps <= cvr_steps; + cover(!o_valid && !i_valid && f_changed_data); + if (!o_valid || !i_ready) + cvr_steps <= 0; + else + cvr_hold <= cvr_hold + 1; + end + default: assert(0); + endcase + end + +`else // Cover test cover property (@(posedge i_clk) disable iff (i_reset) @@ -289,22 +471,14 @@ module skidbuffer(i_clk, i_reset, // Wait for the design to clear ##1 o_valid && i_ready [*0:5] ##1 (!o_valid && !i_valid && f_changed_data)); - - initial f_changed_data = 0; - always @(posedge i_clk) - if (i_reset) - f_changed_data <= 1; - else if (i_valid && $past(!i_valid || o_ready)) - begin - if (i_data != $past(i_data + 1)) - f_changed_data <= 0; - end else if (!i_valid && i_data != 0) - f_changed_data <= 0; - -`endif // SKIDCOVER +`endif end endgenerate +`endif // SKIDBUFFER + -`endif // FORMAL_VERIFIC + // }}} +`endif +// }}} endmodule `ifndef YOSYS `default_nettype wire diff --git a/rtl/toplevel.v b/rtl/toplevel.v index 0dbd7fd..5472f4c 100644 --- a/rtl/toplevel.v +++ b/rtl/toplevel.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: ./toplevel.v -// +// {{{ // Project: ZBasic, a generic toplevel implementation using the full ZipCPU // // DO NOT EDIT THIS FILE! @@ -14,9 +14,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2017-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2017-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -31,14 +31,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} `default_nettype none @@ -56,16 +56,16 @@ // also appear in this list // module toplevel(i_clk, - // GPIO ports - i_gpio, o_gpio, - // UART/host to wishbone interface - i_wbu_uart_rx, o_wbu_uart_tx, - // Top level Quad-SPI I/O ports - o_qspi_cs_n, io_qspi_dat, // A reset wire for the ZipCPU i_cpu_resetn, + // UART/host to wishbone interface + i_wbu_uart_rx, o_wbu_uart_tx, // SD Card - o_sd_sck, io_sd_cmd, io_sd, i_sd_cd); + o_sd_sck, io_sd_cmd, io_sd, i_sd_cd, + // GPIO ports + i_gpio, o_gpio, + // Top level Quad-SPI I/O ports + o_qspi_cs_n, io_qspi_dat); // // Declaring our input and output ports. We listed these above, // now we are declaring them here. @@ -79,23 +79,23 @@ module toplevel(i_clk, // We start with any @CLOCK.TOP keys // input wire i_clk; + // A reset wire for the ZipCPU + input wire i_cpu_resetn; + input wire i_wbu_uart_rx; + output wire o_wbu_uart_tx; + // SD Card + output wire o_sd_sck; + inout wire io_sd_cmd; + inout wire [3:0] io_sd; + input wire i_sd_cd; // GPIO wires localparam NGPI = 11, NGPO=11; // GPIO ports input wire [(11-1):0] i_gpio; output wire [(11-1):0] o_gpio; - input wire i_wbu_uart_rx; - output wire o_wbu_uart_tx; // Quad SPI flash output wire o_qspi_cs_n; inout wire [3:0] io_qspi_dat; - // A reset wire for the ZipCPU - input wire i_cpu_resetn; - // SD Card - output wire o_sd_sck; - inout wire io_sd_cmd; - inout wire [3:0] io_sd; - input wire i_sd_cd; // @@ -104,15 +104,15 @@ module toplevel(i_clk, // These declarations just copy data from the @TOP.DEFNS key // within the component data files. // - wire w_qspi_sck, w_qspi_cs_n; - wire [1:0] qspi_bmod; - wire [3:0] qspi_dat; - wire s_clk, s_reset; wire w_sd_cmd; wire [3:0] w_sd_data; wire i_sd_cmd; wire [3:0] i_sd; + wire s_clk, s_reset; + wire w_qspi_sck, w_qspi_cs_n; + wire [1:0] qspi_bmod; + wire [3:0] qspi_dat; // @@ -131,16 +131,16 @@ module toplevel(i_clk, // main thedesign(s_clk, s_reset, - // GPIO wires - i_gpio, o_gpio, - // UART/host to wishbone interface - i_wbu_uart_rx, o_wbu_uart_tx, - // Quad SPI flash - w_qspi_cs_n, w_qspi_sck, qspi_dat, io_qspi_dat, qspi_bmod, // Reset wire for the ZipCPU (!i_cpu_resetn), + // UART/host to wishbone interface + i_wbu_uart_rx, o_wbu_uart_tx, // SD Card - o_sd_sck, w_sd_cmd, w_sd_data, io_sd_cmd, io_sd, i_sd_cd); + o_sd_sck, w_sd_cmd, w_sd_data, io_sd_cmd, io_sd, i_sd_cd, + // GPIO wires + i_gpio, o_gpio, + // Quad SPI flash + w_qspi_cs_n, w_qspi_sck, qspi_dat, io_qspi_dat, qspi_bmod); // @@ -150,6 +150,32 @@ module toplevel(i_clk, // + // + // + // Wires for setting up the SD Card Controller + // + // + // assign io_sd_cmd = w_sd_cmd ? 1'bz:1'b0; + // assign io_sd[0] = w_sd_data[0]? 1'bz:1'b0; + // assign io_sd[1] = w_sd_data[1]? 1'bz:1'b0; + // assign io_sd[2] = w_sd_data[2]? 1'bz:1'b0; + // assign io_sd[3] = w_sd_data[3]? 1'bz:1'b0; + + + // IOBUF sd_cmd_buf(.T(w_sd_cmd),.O(i_sd_cmd), .I(1'b0), .IO(io_sd_cmd)); + IOBUF sd_dat0_bf(.T(1'b1),.O(i_sd[0]),.I(1'b1),.IO(io_sd[0])); + IOBUF sd_dat1_bf(.T(1'b1),.O(i_sd[1]),.I(1'b1),.IO(io_sd[1])); + IOBUF sd_dat2_bf(.T(1'b1),.O(i_sd[2]),.I(1'b1),.IO(io_sd[2])); + // IOBUF sd_dat3_bf(.T(w_sd_data[3]),.O(i_sd[3]),.I(1'b0),.IO(io_sd[3])); + + IOBUF sd_cmd_buf(.T(1'b0),.O(i_sd_cmd), .I(w_sd_cmd), .IO(io_sd_cmd)); + IOBUF sd_dat3_bf(.T(1'b0),.O(i_sd[3]),.I(w_sd_data[3]),.IO(io_sd[3])); + + + + assign s_clk = i_clk; + assign s_reset = 1'b0; // This design requires local, not global resets + // // // Wires for setting up the QSPI flash wishbone peripheral @@ -221,32 +247,6 @@ module toplevel(i_clk, ); - assign s_clk = i_clk; - assign s_reset = 1'b0; // This design requires local, not global resets - - // - // - // Wires for setting up the SD Card Controller - // - // - // assign io_sd_cmd = w_sd_cmd ? 1'bz:1'b0; - // assign io_sd[0] = w_sd_data[0]? 1'bz:1'b0; - // assign io_sd[1] = w_sd_data[1]? 1'bz:1'b0; - // assign io_sd[2] = w_sd_data[2]? 1'bz:1'b0; - // assign io_sd[3] = w_sd_data[3]? 1'bz:1'b0; - - - // IOBUF sd_cmd_buf(.T(w_sd_cmd),.O(i_sd_cmd), .I(1'b0), .IO(io_sd_cmd)); - IOBUF sd_dat0_bf(.T(1'b1),.O(i_sd[0]),.I(1'b1),.IO(io_sd[0])); - IOBUF sd_dat1_bf(.T(1'b1),.O(i_sd[1]),.I(1'b1),.IO(io_sd[1])); - IOBUF sd_dat2_bf(.T(1'b1),.O(i_sd[2]),.I(1'b1),.IO(io_sd[2])); - // IOBUF sd_dat3_bf(.T(w_sd_data[3]),.O(i_sd[3]),.I(1'b0),.IO(io_sd[3])); - - IOBUF sd_cmd_buf(.T(1'b0),.O(i_sd_cmd), .I(w_sd_cmd), .IO(io_sd_cmd)); - IOBUF sd_dat3_bf(.T(1'b0),.O(i_sd[3]),.I(w_sd_data[3]),.IO(io_sd[3])); - - - endmodule // end of toplevel.v module definition diff --git a/rtl/wbubus/wbconsole.v b/rtl/wbubus/wbconsole.v index 7f5aa14..81a09de 100644 --- a/rtl/wbubus/wbconsole.v +++ b/rtl/wbubus/wbconsole.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: wbconsole.v -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: Unlilke wbuart-insert.v, this is a full blown wishbone core @@ -13,9 +13,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2019, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -30,30 +30,52 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none -// -module wbconsole(i_clk, i_rst, - // - i_wb_cyc, i_wb_stb, i_wb_we, i_wb_addr, i_wb_data, i_wb_sel, - o_wb_stall, o_wb_ack, o_wb_data, +// }}} +module wbconsole #( + parameter [3:0] LGFLEN = 4 + ) ( + // {{{ + input wire i_clk, i_reset, + // Wishbone inputs + // {{{ + input wire i_wb_cyc, i_wb_stb, i_wb_we, + input wire [1:0] i_wb_addr, + input wire [31:0] i_wb_data, + input wire [3:0] i_wb_sel, + output wire o_wb_stall, + output reg o_wb_ack, + output reg [31:0] o_wb_data, + // }}} + // TX + // {{{ + output wire o_uart_stb, + output wire [6:0] o_uart_data, + input wire i_uart_busy, + // }}} + // RX + // {{{ + input wire i_uart_stb, + input wire [6:0] i_uart_data, + // }}} + // Interrupts + output wire o_uart_rx_int, o_uart_tx_int, + o_uart_rxfifo_int, o_uart_txfifo_int, // - o_uart_stb, o_uart_data, i_uart_busy, - i_uart_stb, i_uart_data, - // - o_uart_rx_int, o_uart_tx_int, - o_uart_rxfifo_int, o_uart_txfifo_int, - // - o_debug); - parameter [3:0] LGFLEN = 4; - parameter [0:0] HARDWARE_FLOW_CONTROL_PRESENT = 1'b1; + output reg [31:0] o_debug + // }}} + ); + + // Local declarations + // {{{ + // parameter [0:0] HARDWARE_FLOW_CONTROL_PRESENT = 1'b1; // Perform a simple/quick bounds check on the log FIFO length, to make // sure its within the bounds we can support with our current // interface. @@ -65,47 +87,35 @@ module wbconsole(i_clk, i_rst, UART_FIFO = 2'b01, UART_RXREG = 2'b10, UART_TXREG = 2'b11; - // - input wire i_clk, i_rst; - // Wishbone inputs - input wire i_wb_cyc, i_wb_stb, i_wb_we; - input wire [1:0] i_wb_addr; - input wire [31:0] i_wb_data; - input wire [3:0] i_wb_sel; - output wire o_wb_stall; - output reg o_wb_ack; - output reg [31:0] o_wb_data; - // - output wire o_uart_stb; - output wire [6:0] o_uart_data; - input wire i_uart_busy; - // - input wire i_uart_stb; - input wire [6:0] i_uart_data; - // - output wire o_uart_rx_int, o_uart_tx_int, - o_uart_rxfifo_int, o_uart_txfifo_int; - // - output reg [31:0] o_debug; - ///////////////////////////////////////// - // - // - // First, the receiver - // - // - ///////////////////////////////////////// - - - // We place it into a receiver FIFO. - // - // Here's the declarations for the wires it needs. reg rx_uart_reset; wire rx_empty_n, rx_fifo_err; wire [6:0] rxf_wb_data; wire [15:0] rxf_status; reg rxf_wb_read; + + wire [31:0] wb_rx_data; + + wire tx_empty_n, txf_err; + wire [15:0] txf_status; + reg txf_wb_write, tx_uart_reset; + reg [6:0] txf_wb_data; + + wire [31:0] wb_tx_data; + wire [31:0] wb_fifo_data; + reg [1:0] r_wb_addr; + reg r_wb_ack; + // }}} + //////////////////////////////////////////////////////////////////////// + // + // First, the receiver + // {{{ + //////////////////////////////////////////////////////////////////////// + // // + + // We place it into a receiver FIFO. + // And here's the FIFO proper. // // Note that the FIFO will be cleared upon any reset: either if there's @@ -118,12 +128,18 @@ module wbconsole(i_clk, i_rst, // four status-type values: 1) is it non-empty, 2) is the FIFO over half // full, 3) a 16-bit status register, containing info regarding how full // the FIFO truly is, and 4) an error indicator. - ufifo #(.LGFLEN(LCLLGFLEN), .BW(7), .RXFIFO(1)) - rxfifo(i_clk, (i_rst)||(rx_uart_reset), + ufifo #( + .LGFLEN(LCLLGFLEN), .BW(7), .RXFIFO(1) + ) rxfifo( + // {{{ + i_clk, (i_reset)||(rx_uart_reset), i_uart_stb, i_uart_data, rx_empty_n, rxf_wb_read, rxf_wb_data, - rxf_status, rx_fifo_err); + rxf_status, rx_fifo_err + // }}} + ); + assign o_uart_rxfifo_int = rxf_status[1]; // We produce four interrupts. One of the receive interrupts indicates @@ -142,7 +158,7 @@ module wbconsole(i_clk, i_rst, initial rx_uart_reset = 1'b1; always @(posedge i_clk) - if ((i_rst)||((i_wb_stb)&&(i_wb_addr[1:0]==UART_SETUP)&&(i_wb_we))) + if ((i_reset)||((i_wb_stb)&&(i_wb_addr[1:0]==UART_SETUP)&&(i_wb_we))) // The receiver reset, always set on a master reset // request. rx_uart_reset <= 1'b1; @@ -158,23 +174,18 @@ module wbconsole(i_clk, i_rst, // that would be read from the FIFO, an error indicator set upon // reading from an empty FIFO, a break indicator, and the frame and // parity error signals. - wire [31:0] wb_rx_data; assign wb_rx_data = { 16'h00, 3'h0, rx_fifo_err, 1'b0, 1'b0, 1'b0, !rx_empty_n, 1'b0, rxf_wb_data}; - - ///////////////////////////////////////// - // + // }}} + //////////////////////////////////////////////////////////////////////// // // Then the UART transmitter + // {{{ + //////////////////////////////////////////////////////////////////////// // // - ///////////////////////////////////////// - wire tx_empty_n, txf_err; - wire [15:0] txf_status; - reg txf_wb_write, tx_uart_reset; - reg [6:0] txf_wb_data; // Unlike the receiver which goes from RXUART -> UFIFO -> WB, the // transmitter basically goes WB -> UFIFO -> TXUART. Hence, to build @@ -193,7 +204,7 @@ module wbconsole(i_clk, i_rst, end // Transmit FIFO - // + // {{{ // Most of this is just wire management. The TX FIFO is identical in // implementation to the RX FIFO (theyre both UFIFOs), but the TX // FIFO is fed from the WB and read by the transmitter. Some key @@ -201,12 +212,18 @@ module wbconsole(i_clk, i_rst, // break. We read from the FIFO any time the UART transmitter is idle. // and ... we just set the values (above) for controlling writing into // this. - ufifo #(.LGFLEN(LGFLEN), .BW(7), .RXFIFO(0)) - txfifo(i_clk, (tx_uart_reset), + ufifo #( + .LGFLEN(LGFLEN), .BW(7), .RXFIFO(0) + ) txfifo( + // {{{ + i_clk, (tx_uart_reset), txf_wb_write, txf_wb_data, tx_empty_n, (!i_uart_busy)&&(tx_empty_n), o_uart_data, - txf_status, txf_err); + txf_status, txf_err + // }}} + ); + // }}} assign o_uart_stb = tx_empty_n; @@ -220,19 +237,20 @@ module wbconsole(i_clk, i_rst, assign o_uart_txfifo_int = txf_status[1]; // TX-Reset logic - // + // {{{ // This is nearly identical to the RX reset logic above. Basically, // any time someone writes to bit [12] the transmitter will go through // a reset cycle. Keep bit [12] low, and everything will proceed as // normal. initial tx_uart_reset = 1'b1; always @(posedge i_clk) - if((i_rst)||((i_wb_stb)&&(i_wb_addr == UART_SETUP)&&(i_wb_we))) + if((i_reset)||((i_wb_stb)&&(i_wb_addr == UART_SETUP)&&(i_wb_we))) tx_uart_reset <= 1'b1; else if ((i_wb_stb)&&(i_wb_addr[1:0]==UART_TXREG)&&(i_wb_we)) tx_uart_reset <= i_wb_data[12]; else tx_uart_reset <= 1'b0; + // }}} // Now that we are done with the chain, pick some wires for the user // to read on any read of the transmit port. @@ -246,29 +264,33 @@ module wbconsole(i_clk, i_rst, // voltage on the line (o_uart_tx)--and even the voltage on the receive // line (ck_uart), as well as our current setting of the break and // whether or not we are actively transmitting. - wire [31:0] wb_tx_data; assign wb_tx_data = { 16'h00, 1'b0, txf_status[1:0], txf_err, 1'b0, o_uart_stb, 1'b0, (i_uart_busy|tx_empty_n), 1'b0,(i_uart_busy|tx_empty_n)?txf_wb_data:7'h0}; + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Bus return handling + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // // Each of the FIFO's returns a 16 bit status value. This value tells // us both how big the FIFO is, as well as how much of the FIFO is in // use. Let's merge those two status words together into a word we // can use when reading about the FIFO. - wire [31:0] wb_fifo_data; assign wb_fifo_data = { txf_status, rxf_status }; // You may recall from above that reads take two clocks. Hence, we // need to delay the address decoding for a clock until the data is // ready. We do that here. - reg [1:0] r_wb_addr; always @(posedge i_clk) r_wb_addr <= i_wb_addr; // Likewise, the acknowledgement is delayed by one clock. - reg r_wb_ack; always @(posedge i_clk) // We'll ACK in two clocks r_wb_ack <= i_wb_stb; always @(posedge i_clk) // Okay, time to set the ACK @@ -291,6 +313,14 @@ module wbconsole(i_clk, i_rst, // perhaps, but doesn't stall the pipeline.) Hence, we can just // set this value to zero. assign o_wb_stall = 1'b0; + // }}} + //////////////////////////////////////////////////////////////////////// + // + // A debug return + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // always @(posedge i_clk) begin @@ -313,11 +343,14 @@ module wbconsole(i_clk, i_rst, else o_debug[6:0] <= rxf_wb_data; end + // }}} // Make verilator happy + // {{{ // verilator lint_off UNUSED wire unused; assign unused = &{ 1'b0, i_wb_cyc, i_wb_data[31:13], i_wb_data[11:7], i_wb_sel }; // verilator lint_on UNUSED + // }}} endmodule diff --git a/rtl/wbubus/wbubus.v b/rtl/wbubus/wbubus.v index 5232284..d00b064 100644 --- a/rtl/wbubus/wbubus.v +++ b/rtl/wbubus/wbubus.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: wbubus.v -// +// {{{ // Project: FPGA library // // Purpose: This is the top level file for the entire JTAG-USB to Wishbone @@ -15,9 +15,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -32,104 +32,181 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none -// -module wbubus(i_clk, i_rx_stb, i_rx_data, - o_wb_cyc, o_wb_stb, o_wb_we, o_wb_addr, o_wb_data, - i_wb_stall, i_wb_ack, i_wb_data, i_wb_err, - i_interrupt, - o_tx_stb, o_tx_data, i_tx_busy); - parameter LGWATCHDOG=19, - LGINPUT_FIFO=6, - LGOUTPUT_FIFO=10; - parameter [0:0] CMD_PORT_OFF_UNTIL_ACCESSED = 1'b1; - input wire i_clk; - input wire i_rx_stb; - input wire [7:0] i_rx_data; - output wire o_wb_cyc, o_wb_stb, o_wb_we; - output wire [31:0] o_wb_addr, o_wb_data; - input wire i_wb_stall, i_wb_ack; - input wire [31:0] i_wb_data; - input wire i_wb_err; - input wire i_interrupt; - output wire o_tx_stb; - output wire [7:0] o_tx_data; - input wire i_tx_busy; - // output wire o_dbg; - - +// }}} +module wbubus #( + // {{{ + parameter LGWATCHDOG=19, + LGINPUT_FIFO=6, + LGOUTPUT_FIFO=10, + parameter [0:0] CMD_PORT_OFF_UNTIL_ACCESSED = 1'b1 + // }}} + ) ( + // {{{ + input wire i_clk, + input wire i_reset, + // RX + // {{{ + input wire i_rx_stb, + input wire [7:0] i_rx_data, + // }}} + // Wishbone master + // {{{ + output wire o_wb_cyc, o_wb_stb, o_wb_we, + output wire [31:0] o_wb_addr, o_wb_data, + input wire i_wb_stall, i_wb_ack, + input wire [31:0] i_wb_data, + input wire i_wb_err, + // }}} + input wire i_interrupt, + // TX + // {{{ + output wire o_tx_stb, + output wire [7:0] o_tx_data, + input wire i_tx_busy + // }}} + // , output wire o_dbg; + // }}} + ); + + // Local declarations + // {{{ + wire soft_reset; reg r_wdt_reset; - reg cmd_port_active; + wire cmd_port_active, w_tx_stb; + wire in_stb; + wire [35:0] in_word; + wire w_bus_busy, fifo_in_stb, exec_stb, w_bus_reset; + wire [35:0] fifo_in_word, exec_word; + wire ofifo_err; + reg [(LGWATCHDOG-1):0] r_wdt_timer; + // wire [30:0] out_dbg; + // }}} + // cmd_port_active + // {{{ generate if (CMD_PORT_OFF_UNTIL_ACCESSED) begin - initial cmd_port_active = 1'b0; + reg r_cmd_port_active; + + initial r_cmd_port_active = 1'b0; always @(posedge i_clk) if (i_rx_stb && i_rx_data[7]) - cmd_port_active <= 1'b1; + r_cmd_port_active <= 1'b1; + + assign cmd_port_active = r_cmd_port_active; end else begin - always @(*) - cmd_port_active = 1'b1; + assign cmd_port_active = 1'b1; end endgenerate + // }}} + //////////////////////////////////////////////////////////////////////// + // // Decode ASCII input requests into WB bus cycle requests - wire in_stb; - wire [35:0] in_word; - wbuinput getinput(i_clk, i_rx_stb, i_rx_data, in_stb, in_word); - - wire w_bus_busy, fifo_in_stb, exec_stb, w_bus_reset; - wire [35:0] fifo_in_word, exec_word; - - generate - if (LGINPUT_FIFO < 2) + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + wbuinput + getinput( + // {{{ + .i_clk(i_clk), .i_reset(i_reset), + .i_stb(i_rx_stb), .i_byte(i_rx_data), + .o_soft_reset(soft_reset), + .o_stb(in_stb), .o_codword(in_word) + // }}} + ); + // }}} + //////////////////////////////////////////////////////////////////////// + // + // The input FIFO + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + generate if (LGINPUT_FIFO < 2) begin : NO_INPUT_FIFO - assign fifo_in_stb = in_stb; - assign fifo_in_word = in_word; - assign w_bus_reset = 1'b0; + assign fifo_in_stb = in_stb; + assign fifo_in_word = in_word; + assign w_bus_reset = soft_reset; end else begin : INPUT_FIFO wire ififo_empty_n, ififo_err; + assign fifo_in_stb = (~w_bus_busy)&&(ififo_empty_n); assign w_bus_reset = r_wdt_reset; - wbufifo #(36,LGINPUT_FIFO) padififo(i_clk, w_bus_reset, - in_stb, in_word, fifo_in_stb, fifo_in_word, - ififo_empty_n, ififo_err); + + wbufifo #( + // {{{ + .BW(36),.LGFLEN(LGINPUT_FIFO) + // }}} + ) padififo( + // {{{ + .i_clk(i_clk), .i_reset(w_bus_reset), + .i_wr(in_stb), .i_data(in_word), + .i_rd(fifo_in_stb), .o_data(fifo_in_word), + .o_empty_n(ififo_empty_n), .o_err(ififo_err) + // }}} + ); // verilator lint_off UNUSED wire gen_unused; assign gen_unused = ififo_err; // verilator lint_on UNUSED end endgenerate + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Run the bus + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // // Take requests in, Run the bus, send results out // This only works if no requests come in while requests // are pending. - wbuexec runwb(i_clk, r_wdt_reset, fifo_in_stb, fifo_in_word, w_bus_busy, - o_wb_cyc, o_wb_stb, o_wb_we, o_wb_addr, o_wb_data, - i_wb_stall, i_wb_ack, i_wb_err, i_wb_data, - exec_stb, exec_word); - - wire ofifo_err, w_tx_stb; - // wire [30:0] out_dbg; - wbuoutput #(LGOUTPUT_FIFO) wroutput(i_clk, w_bus_reset, - exec_stb, exec_word, - o_wb_cyc, i_interrupt, exec_stb, - w_tx_stb, o_tx_data, i_tx_busy || !cmd_port_active, ofifo_err); - assign o_tx_stb = cmd_port_active & w_tx_stb; + wbuexec + runwb( + // {{{ + .i_clk(i_clk), .i_reset(r_wdt_reset), + .i_stb(fifo_in_stb), .i_codword(fifo_in_word), + .o_busy(w_bus_busy), + .o_wb_cyc(o_wb_cyc), .o_wb_stb(o_wb_stb), .o_wb_we(o_wb_we), + .o_wb_addr(o_wb_addr), .o_wb_data(o_wb_data), + .i_wb_stall(i_wb_stall), .i_wb_ack(i_wb_ack), + .i_wb_data(i_wb_data), .i_wb_err(i_wb_err), + .o_stb(exec_stb), .o_codword(exec_word) + // }}} + ); + // }}} + + wbuoutput #( + LGOUTPUT_FIFO + ) wroutput( + // {{{ + .i_clk(i_clk), .i_reset(i_reset), .i_soft_reset(w_bus_reset), + .i_stb(exec_stb), .i_codword(exec_word), + .i_wb_cyc(o_wb_cyc), .i_int(i_interrupt), .i_bus_busy(exec_stb), + .o_stb(w_tx_stb), .o_char(o_tx_data), .i_tx_busy(i_tx_busy), + .o_fifo_err(ofifo_err) + // }}} + ); + + assign o_tx_stb = w_tx_stb && cmd_port_active; // verilator lint_off UNUSED wire ofifo_unused; @@ -137,10 +214,11 @@ module wbubus(i_clk, i_rx_stb, i_rx_data, // verilator lint_on UNUSED // Add in a watchdog timer to the bus - reg [(LGWATCHDOG-1):0] r_wdt_timer; + // {{{ initial r_wdt_reset = 1'b0; initial r_wdt_timer = 0; always @(posedge i_clk) + begin if ((~o_wb_cyc)||(i_wb_ack)) begin r_wdt_timer <= 0; @@ -154,5 +232,10 @@ module wbubus(i_clk, i_rx_stb, i_rx_data, r_wdt_reset <= 1'b0; end + if (soft_reset) + r_wdt_reset <= 1'b1; + end + // }}} + endmodule diff --git a/rtl/wbubus/wbucompactlines.v b/rtl/wbubus/wbucompactlines.v index 76958f2..631d6c1 100644 --- a/rtl/wbubus/wbucompactlines.v +++ b/rtl/wbubus/wbucompactlines.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: wbucompactlines.v -// +// {{{ // Project: FPGA library // // Purpose: Removes 'end of line' characters placed at the end of every @@ -14,9 +14,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -31,8 +31,9 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // // @@ -54,88 +55,124 @@ // last word. If the last word was a // `default_nettype none -// -module wbucompactlines(i_clk, i_stb, i_nl_hexbits, o_stb, o_nl_hexbits, - i_bus_busy, i_tx_busy, o_busy); +// }}} +module wbucompactlines ( + // {{{ + input wire i_clk, i_reset, i_stb, + input wire [6:0] i_nl_hexbits, + output reg o_stb, + output reg [6:0] o_nl_hexbits, + input wire i_bus_busy, + input wire i_tx_busy, + output wire o_busy + // }}} + ); + + // Local declarations + // {{{ localparam [6:0] MAX_LINE_LENGTH = 79; localparam [6:0] TRIGGER_LENGTH = (MAX_LINE_LENGTH-6); - input wire i_clk, i_stb; - input wire [6:0] i_nl_hexbits; - output reg o_stb; - output reg [6:0] o_nl_hexbits; - input wire i_bus_busy; - input wire i_tx_busy; - output wire o_busy; - reg last_out_nl, last_in_nl, full_line, r_busy; reg [6:0] linelen; + // }}} + // last_out_nl + // {{{ initial last_out_nl = 1'b1; always @(posedge i_clk) - if ((!i_tx_busy)&&(o_stb)) + if (i_reset) + last_out_nl <= 1'b1; + else if ((!i_tx_busy)&&(o_stb)) last_out_nl <= (o_nl_hexbits[6]); + // }}} + // last_in_nl + // {{{ initial last_in_nl = 1'b1; always @(posedge i_clk) - if ((i_stb)&&(!o_busy)) + if (i_reset) + last_in_nl <= 1'b1; + else if ((i_stb)&&(!o_busy)) last_in_nl <= (i_nl_hexbits[6]); + // }}} + // linelen + // {{{ // Now, let's count how long our lines are initial linelen = 7'h00; always @(posedge i_clk) - if ((!i_tx_busy)&&(o_stb)) + if (i_reset) + linelen <= 0; + else if ((!i_tx_busy)&&(o_stb)) begin if (o_nl_hexbits[6]) linelen <= 0; else linelen <= linelen + 7'h1; end + // }}} + // full_line + // {{{ initial full_line = 1'b0; always @(posedge i_clk) - if ((!i_tx_busy)&&(o_stb)) + if (i_reset) + full_line <= 0; + else if ((!i_tx_busy)&&(o_stb)) begin if (o_nl_hexbits[6]) full_line <= 0; else full_line <= (linelen >= TRIGGER_LENGTH); end + // }}} - + // o_stb, o_nl_hexbits + // {{{ // Now that we know whether or not the last character was a newline, // and indeed how many characters we have in any given line, we can // selectively remove newlines from our output stream. initial o_stb = 1'b0; always @(posedge i_clk) - if ((i_stb)&&(!o_busy)) begin - // Only accept incoming newline requests if our line is already - // full, otherwise quietly suppress them - o_stb <= (full_line)||(!i_nl_hexbits[6]); - o_nl_hexbits <= i_nl_hexbits; - end else if (!o_busy) - begin // Send an EOL if we are idle + if ((i_stb)&&(!o_busy)) + begin + // Only accept incoming newline requests if our line is + // already full, otherwise quietly suppress them + o_stb <= (full_line)||(!i_nl_hexbits[6]); + o_nl_hexbits <= i_nl_hexbits; + end else if (!o_busy) + begin // Send an EOL if we are idle - // Without a request, we'll add a newline, but only if - // 1. There's nothing coming down the channel (!bus_busy) - // 2. What we last sent wasn't a new-line - // 3. The last thing that came in was a newline - // In otherwords, we can resurrect one of the newlines we - // squashed above - o_stb <= (!i_tx_busy)&&(!i_bus_busy)&&(!last_out_nl)&&(last_in_nl); - o_nl_hexbits <= 7'h40; - end else if (!i_tx_busy) - o_stb <= 1'b0; + // Without a request, we'll add a newline, but only if + // 1. There's nothing coming down the channel + // (!bus_busy) + // 2. What we last sent wasn't a new-line + // 3. The last thing that came in was a newline + // In otherwords, we can resurrect one of the newlines + // we squashed above + o_stb <= (!i_tx_busy)&&(!i_bus_busy)&&(!last_out_nl)&&(last_in_nl); + o_nl_hexbits <= 7'h40; + end else if (!i_tx_busy) + o_stb <= 1'b0; + + if (i_reset) + o_stb <= 1'b0; + end + // }}} + // o_busy + // {{{ initial r_busy = 1'b0; always @(posedge i_clk) r_busy <= (o_stb)&&(i_tx_busy); assign o_busy = (r_busy)||(o_stb); + // }}} /* output wire [27:0] o_dbg; - assign o_dbg = { o_stb, o_nl_hexbits, o_busy, r_busy, full_line, + assign o_dbg = { o_stb, o_nl_hexbits, o_busy, r_busy, full_line, i_bus_busy, linelen, i_tx_busy, i_stb, i_nl_hexbits }; */ endmodule diff --git a/rtl/wbubus/wbucompress.v b/rtl/wbubus/wbucompress.v index 0154e0e..090e1b8 100644 --- a/rtl/wbubus/wbucompress.v +++ b/rtl/wbubus/wbucompress.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: wbucompress.v -// +// {{{ // Project: FPGA library // // Purpose: When reading many words that are identical, it makes no sense @@ -25,9 +25,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -42,30 +42,33 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none // // All input words are valid codewords. If we can, we make them // better here. -module wbucompress(i_clk, i_reset, i_stb, i_codword, i_busy, o_stb, o_cword, - o_busy); - parameter DW=32, CW=36, TBITS=10; - input wire i_clk, i_reset, i_stb; - input wire [(CW-1):0] i_codword; - input wire i_busy; - output reg o_stb; - output wire [(CW-1):0] o_cword; - output wire o_busy; - - // - // +// }}} +module wbucompress #( + parameter DW=32, CW=36, TBITS=10 + ) ( + // {{{ + input wire i_clk, i_reset, i_stb, + input wire [(CW-1):0] i_codword, + input wire i_busy, + output reg o_stb, + output wire [(CW-1):0] o_cword, + output wire o_busy + // }}} + ); + + // Local declarations + // {{{ // First stage is to compress the address. // This stage requires one clock. // @@ -83,7 +86,7 @@ module wbucompress(i_clk, i_reset, i_stb, i_codword, i_busy, o_stb, o_cword, wire [31:0] w_addr; wire [3:0] addr_zcheck; reg tbl_busy; - + // }}} //////////////////////////////////////////////////////////////////////// // // Address compression stage diff --git a/rtl/wbubus/wbuconsole.v b/rtl/wbubus/wbuconsole.v index 077b041..fbcb828 100644 --- a/rtl/wbubus/wbuconsole.v +++ b/rtl/wbubus/wbuconsole.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: wbuconsole.v -// +// {{{ // Project: FPGA library // // Purpose: This is the top level file for the entire JTAG-USB to Wishbone @@ -25,9 +25,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -42,130 +42,213 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none -// -module wbuconsole(i_clk, i_rx_stb, i_rx_data, - o_wb_cyc, o_wb_stb, o_wb_we, o_wb_addr, o_wb_data, - i_wb_stall, i_wb_ack, i_wb_err, i_wb_data, - i_interrupt, - o_tx_stb, o_tx_data, i_tx_busy, - i_console_stb, i_console_data, o_console_busy, - o_console_stb, o_console_data, - o_dbg); - parameter LGWATCHDOG=19, - LGINPUT_FIFO=6, - LGOUTPUT_FIFO=10; - parameter [0:0] CMD_PORT_OFF_UNTIL_ACCESSED = 1'b1; - input wire i_clk; - input wire i_rx_stb; - input wire [7:0] i_rx_data; - output wire o_wb_cyc, o_wb_stb, o_wb_we; - output wire [31:0] o_wb_addr, o_wb_data; - input wire i_wb_stall, i_wb_ack, i_wb_err; - input wire [31:0] i_wb_data; - input wire i_interrupt; - output wire o_tx_stb; - output wire [7:0] o_tx_data; - input wire i_tx_busy; - // - input wire i_console_stb; - input wire [6:0] i_console_data; - output wire o_console_busy; - // - output reg o_console_stb; - output reg [6:0] o_console_data; - // - output wire o_dbg; - - - +// }}} +module wbuconsole #( + // {{{ + parameter LGWATCHDOG=19, + LGINPUT_FIFO=6, + LGOUTPUT_FIFO=10, + parameter [0:0] CMD_PORT_OFF_UNTIL_ACCESSED = 1'b1 + // }}} + ) ( + // {{{ + input wire i_clk, + input wire i_reset, + // RX + // {{{ + input wire i_rx_stb, + input wire [7:0] i_rx_data, + // }}} + // Wishbone master + // {{{ + output wire o_wb_cyc, o_wb_stb, o_wb_we, + output wire [31:0] o_wb_addr, o_wb_data, + input wire i_wb_stall, i_wb_ack, + input wire [31:0] i_wb_data, + input wire i_wb_err, + // }}} + input wire i_interrupt, + // TX + // {{{ + output wire o_tx_stb, + output wire [7:0] o_tx_data, + input wire i_tx_busy, + // }}} + // CONSOLE + // {{{ + input wire i_console_stb, + input wire [6:0] i_console_data, + output wire o_console_busy, + // + output reg o_console_stb, + output reg [6:0] o_console_data, + // }}} + output wire o_dbg + // }}} + ); + // Local declarations + // {{{ + wire soft_reset; + reg r_wdt_reset; + wire cmd_port_active; + wire in_stb; + wire [35:0] in_word; + wire w_bus_busy, fifo_in_stb, exec_stb, w_bus_reset; + wire [35:0] fifo_in_word, exec_word; + reg ps_full; + reg [7:0] ps_data; + wire wbu_tx_stb; + wire [7:0] wbu_tx_data; + wire ofifo_err; + reg [(LGWATCHDOG-1):0] r_wdt_timer; + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Forward console inputs to the console + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + initial o_console_stb = 1'b0; always @(posedge i_clk) o_console_stb <= (i_rx_stb)&&(i_rx_data[7] == 1'b0); + always @(posedge i_clk) o_console_data <= i_rx_data[6:0]; + // }}} - - - reg r_wdt_reset, cmd_port_active; - + // cmd_port_active + // {{{ generate if (CMD_PORT_OFF_UNTIL_ACCESSED) begin - initial cmd_port_active = 1'b0; + reg r_cmd_port_active; + + initial r_cmd_port_active = 1'b0; always @(posedge i_clk) if (i_rx_stb && i_rx_data[7]) - cmd_port_active <= 1'b1; - + r_cmd_port_active <= 1'b1; + + assign cmd_port_active = r_cmd_port_active; + end else begin - always @(*) - cmd_port_active = 1'b1; - + assign cmd_port_active = 1'b1; + end endgenerate + // }}} + //////////////////////////////////////////////////////////////////////// + // // Decode ASCII input requests into WB bus cycle requests - wire in_stb; - wire [35:0] in_word; - wbuinput getinput(i_clk, (i_rx_stb)&&(i_rx_data[7]), { 1'b0, i_rx_data[6:0] }, in_stb, in_word); - - wire w_bus_busy, fifo_in_stb, exec_stb, w_bus_reset; - wire [35:0] fifo_in_word, exec_word; + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + wbuinput + getinput( + // {{{ + .i_clk(i_clk), .i_reset(i_reset), + .i_stb(i_rx_stb && i_rx_data[7]), .i_byte({ 1'b0, i_rx_data[6:0] }), + .o_soft_reset(soft_reset), + .o_stb(in_stb), .o_codword(in_word) + // }}} + ); + // }}} + //////////////////////////////////////////////////////////////////////// + // + // The input FIFO + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + generate if (LGINPUT_FIFO < 2) + begin : NO_INPUT_FIFO - generate - if (LGINPUT_FIFO < 2) - begin assign fifo_in_stb = in_stb; assign fifo_in_word = in_word; - assign w_bus_reset = 1'b0; - end else begin + assign w_bus_reset = soft_reset; + + end else begin : INPUT_FIFO wire ififo_empty_n, ififo_err; + assign fifo_in_stb = (~w_bus_busy)&&(ififo_empty_n); assign w_bus_reset = r_wdt_reset; - wbufifo #(36,LGINPUT_FIFO) - padififo(i_clk, w_bus_reset, - in_stb, in_word, fifo_in_stb, fifo_in_word, - ififo_empty_n, ififo_err); - // Make verilator happy + wbufifo #( + // {{{ + .BW(36),.LGFLEN(LGINPUT_FIFO) + // }}} + ) padififo( + // {{{ + .i_clk(i_clk), .i_reset(w_bus_reset), + .i_wr(in_stb), .i_data(in_word), + .i_rd(fifo_in_stb), .o_data(fifo_in_word), + .o_empty_n(ififo_empty_n), .o_err(ififo_err) + // }}} + ); + // verilator lint_off UNUSED - wire unused_fifo; - assign unused_fifo = ififo_err; + wire gen_unused; + assign gen_unused = ififo_err; // verilator lint_on UNUSED end endgenerate + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Run the bus + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // // Take requests in, Run the bus, send results out // This only works if no requests come in while requests // are pending. - wbuexec runwb(i_clk, r_wdt_reset, fifo_in_stb, fifo_in_word, w_bus_busy, - o_wb_cyc, o_wb_stb, o_wb_we, o_wb_addr, o_wb_data, - i_wb_stall, i_wb_ack, i_wb_err, i_wb_data, - exec_stb, exec_word); + wbuexec + runwb( + // {{{ + .i_clk(i_clk), .i_reset(r_wdt_reset), + .i_stb(fifo_in_stb), .i_codword(fifo_in_word), + .o_busy(w_bus_busy), + .o_wb_cyc(o_wb_cyc), .o_wb_stb(o_wb_stb), .o_wb_we(o_wb_we), + .o_wb_addr(o_wb_addr), .o_wb_data(o_wb_data), + .i_wb_stall(i_wb_stall), .i_wb_ack(i_wb_ack), + .i_wb_data(i_wb_data), .i_wb_err(i_wb_err), + .o_stb(exec_stb), .o_codword(exec_word) + // }}} + ); + // }}} - reg ps_full; - reg [7:0] ps_data; - wire wbu_tx_stb; - wire [7:0] wbu_tx_data; + wbuoutput #( + LGOUTPUT_FIFO + ) wroutput( + // {{{ + .i_clk(i_clk), .i_reset(i_reset), .i_soft_reset(w_bus_reset), + .i_stb(exec_stb), .i_codword(exec_word), + .i_wb_cyc(o_wb_cyc), .i_int(i_interrupt), .i_bus_busy(exec_stb), + .o_stb(wbu_tx_stb), .o_char(wbu_tx_data), .i_tx_busy(ps_full), + .o_fifo_err(ofifo_err) + // }}} + ); - wire ofifo_err; - // wire [30:0] out_dbg; - wbuoutput #(LGOUTPUT_FIFO) - wroutput(i_clk, w_bus_reset, - exec_stb, exec_word, - o_wb_cyc, i_interrupt, exec_stb, - wbu_tx_stb, wbu_tx_data, - ps_full && cmd_port_active, ofifo_err); - - // Let's now arbitrate between the two outputs + //////////////////////////////////////////////////////////////////////// + // + // Arbitrate between the two outputs, console and dbg bus + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // initial ps_full = 1'b0; always @(posedge i_clk) if (!ps_full) @@ -185,24 +268,39 @@ module wbuconsole(i_clk, i_rx_stb, i_rx_data, assign o_tx_stb = ps_full; assign o_tx_data = ps_data; assign o_console_busy = (wbu_tx_stb && cmd_port_active)||(ps_full); - + // }}} + //////////////////////////////////////////////////////////////////////// + // // Add in a watchdog timer to the bus - reg [(LGWATCHDOG-1):0] r_wdt_timer; - initial r_wdt_reset = 1'b0; + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + initial r_wdt_reset = 1'b1; initial r_wdt_timer = 0; always @(posedge i_clk) - if ((~o_wb_cyc)||(i_wb_ack)) - begin - r_wdt_timer <= 0; - r_wdt_reset <= 1'b0; - end else if (&r_wdt_timer) - begin - r_wdt_reset <= 1'b1; - r_wdt_timer <= 0; - end else begin - r_wdt_timer <= r_wdt_timer+{{(LGWATCHDOG-1){1'b0}},1'b1}; - r_wdt_reset <= 1'b0; - end + if (i_reset || soft_reset) + begin + r_wdt_timer <= 0; + r_wdt_reset <= 1'b1; + end else if ((~o_wb_cyc)||(i_wb_ack)) + begin + // We're inactive, or the bus has responded: reset the timer + // {{{ + r_wdt_timer <= 0; + r_wdt_reset <= 1'b0; + // }}} + end else if (&r_wdt_timer) + begin // TIMEOUT!!! + // {{{ + r_wdt_reset <= 1'b1; + r_wdt_timer <= 0; + // }}} + end else begin // Tick-tock ... + r_wdt_timer <= r_wdt_timer+{{(LGWATCHDOG-1){1'b0}},1'b1}; + r_wdt_reset <= 1'b0; + end + // }}} assign o_dbg = w_bus_reset; diff --git a/rtl/wbubus/wbudecompress.v b/rtl/wbubus/wbudecompress.v index cd6391e..b77fae0 100644 --- a/rtl/wbubus/wbudecompress.v +++ b/rtl/wbubus/wbudecompress.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: wbudecompress.v -// +// {{{ // Project: FPGA library // // Purpose: Compression via this interface is simply a lookup table. @@ -16,9 +16,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -33,22 +33,26 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none -// -module wbudecompress(i_clk, i_stb, i_word, o_stb, o_word); - input wire i_clk, i_stb; - input wire [35:0] i_word; - output reg o_stb; - output reg [35:0] o_word; - +// }}} +module wbudecompress ( + // {{{ + input wire i_clk, i_reset, i_stb, + input wire [35:0] i_word, + output reg o_stb, + output reg [35:0] o_word + // }}} + ); + + // Local declarations + // {{{ reg [7:0] wr_addr; reg [31:0] compression_tbl [0:255]; reg [35:0] r_word; @@ -59,36 +63,64 @@ module wbudecompress(i_clk, i_stb, i_word, o_stb, o_word); reg [31:0] cword; reg [2:0] r_stb; wire cmd_write_not_compressed; - + // }}} + //////////////////////////////////////////////////////////////////////// + // // Clock zero // { o_stb, r_stb } = 0 + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // assign cmd_write_not_compressed = (i_word[35:33] == 3'h3); // Clock one: { o_stb, r_stb } = 4'h1 when done + + // wr_addr + // {{{ initial wr_addr = 8'h0; always @(posedge i_clk) - if ((i_stb)&&(cmd_write_not_compressed)) + if (i_reset) + wr_addr <= 8'h0; + else if ((i_stb)&&(cmd_write_not_compressed)) wr_addr <= wr_addr + 8'h1; + // }}} + // Write to compression_tbl + // {{{ always @(posedge i_clk) if (i_stb) compression_tbl[wr_addr] <= { i_word[32:31], i_word[29:0] }; + // }}} + // r_word + // {{{ always @(posedge i_clk) if (i_stb) r_word <= i_word; - - + // }}} + // }}} + //////////////////////////////////////////////////////////////////////// + // // Clock two, calculate the table address ... 1 is the smallest address // { o_stb, r_stb } = 4'h2 when done + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + // cmd_addr + // {{{ always @(posedge i_clk) if (i_stb) cmd_addr <= wr_addr - { i_word[32:31], i_word[29:24] }; + // }}} + // r_addr + // {{{ // Let's also calculate the address, in case this is a compressed // address word - always @(posedge i_clk) if (i_stb) case(i_word[32:30]) @@ -103,7 +135,10 @@ module wbudecompress(i_clk, i_stb, i_word, o_stb, o_word); endcase assign w_addr = { {(7){r_addr[24]}}, r_addr }; + // }}} + // rd_len + // {{{ always @(posedge i_clk) if (i_stb) begin @@ -112,27 +147,55 @@ module wbudecompress(i_clk, i_stb, i_word, o_stb, o_word); else rd_len <= 10'h09 + { 1'b0,i_word[33:31],i_word[29:24] }; end - + // }}} + // }}} + //////////////////////////////////////////////////////////////////////// + // // Clock three, read the table value // { o_stb, r_stb } = 4'h4 when done // Maintaining ... // r_word (clock 1) // r_addr, rd_len (clock 2) + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // always @(posedge i_clk) cword <= compression_tbl[cmd_addr]; - + // r_stb + // {{{ // Pipeline the strobe signal to create an output strobe, 3 clocks later initial r_stb = 0; always @(posedge i_clk) + if (i_reset) + r_stb <= 0; + else r_stb <= { r_stb[1:0], i_stb }; - + // }}} + // }}} + //////////////////////////////////////////////////////////////////////// + // // Clock four, now that the table value is valid, let's set our output // word. // { o_stb, r_stb } = 4'h8 when done + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + // o_stb + // {{{ initial o_stb = 0; always @(posedge i_clk) + if (i_reset) + o_stb <= 0; + else o_stb <= r_stb[2]; + // }}} + + // o_word + // {{{ // Maintaining ... // r_word (clock 1) // r_addr, rd_len (clock 2) @@ -162,6 +225,6 @@ module wbudecompress(i_clk, i_stb, i_word, o_stb, o_word); // 6'b1?????: o_word <= { 5'b11000, r_word[30], 20'h00, rd_len }; default: o_word <= r_word; endcase - + // }}} + // }}} endmodule - diff --git a/rtl/wbubus/wbudeword.v b/rtl/wbubus/wbudeword.v index f34b297..be311d9 100644 --- a/rtl/wbubus/wbudeword.v +++ b/rtl/wbubus/wbudeword.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: wbudeword.v -// +// {{{ // Project: FPGA library // // Purpose: Once a word has come from the bus, undergone compression, had @@ -15,9 +15,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -32,26 +32,33 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none -// -module wbudeword(i_clk, i_stb, i_word, i_tx_busy, o_stb, o_nl_hexbits, o_busy); - input wire i_clk, i_stb; - input wire [35:0] i_word; - input wire i_tx_busy; - output reg o_stb; - output reg [6:0] o_nl_hexbits; - output reg o_busy; - +// }}} +module wbudeword ( + // {{{ + input wire i_clk, i_reset, i_stb, + input wire [35:0] i_word, + input wire i_tx_busy, + output reg o_stb, + output reg [6:0] o_nl_hexbits, + output reg o_busy + // }}} + ); + // Local declarations + // {{{ wire [2:0] w_len; + reg [2:0] r_len; + reg [29:0] r_word; + // }}} + assign w_len = (i_word[35:33]==3'b000)? 3'b001 : (i_word[35:32]==4'h2)? 3'b110 : (i_word[35:32]==4'h3)? (3'b010+{1'b0,i_word[31:30]}) @@ -59,8 +66,6 @@ module wbudeword(i_clk, i_stb, i_word, i_tx_busy, o_stb, o_nl_hexbits, o_busy); : (i_word[35:34]==2'b10)? 3'b001 : 3'b110; - reg [2:0] r_len; - reg [29:0] r_word; initial o_stb = 1'b0; initial o_busy = 1'b0; initial o_nl_hexbits = 7'h40; @@ -85,7 +90,9 @@ module wbudeword(i_clk, i_stb, i_word, i_tx_busy, o_stb, o_nl_hexbits, o_busy); initial o_stb = 1'b0; always @(posedge i_clk) - if (i_stb && !o_busy) + if (i_reset) + o_stb <= 1'b0; + else if (i_stb && !o_busy) o_stb <= 1'b1; else if (r_len == 0 && !i_tx_busy) o_stb <= 1'b0; diff --git a/rtl/wbubus/wbuexec.v b/rtl/wbubus/wbuexec.v index f2647c6..02774ad 100644 --- a/rtl/wbubus/wbuexec.v +++ b/rtl/wbubus/wbuexec.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: wbuexec.v -// +// {{{ // Project: FPGA library // // Purpose: This is the part of the USB-JTAG to wishbone conversion that @@ -15,9 +15,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -32,24 +32,51 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none -// -module wbuexec(i_clk, i_reset, i_stb, i_codword, o_busy, - o_wb_cyc, o_wb_stb, o_wb_we, o_wb_addr, o_wb_data, - i_wb_stall, i_wb_ack, i_wb_err, i_wb_data, - o_stb, o_codword); - parameter AW = 32, DW = 32; - // - // - localparam [5:0] END_OF_WRITE = 6'h2e; +// }}} +module wbuexec #( + parameter AW = 32, DW = 32 + ) ( + // {{{ + input wire i_clk, i_reset, + // The command inputs + // {{{ + input wire i_stb, + input wire [35:0] i_codword, + output reg o_busy, + // }}} + // Wishbone outputs + // {{{ + output reg o_wb_cyc, + output reg o_wb_stb, + output reg o_wb_we, + output reg [AW-1:0] o_wb_addr, + output reg [DW-1:0] o_wb_data, + // }}} + // Wishbone inputs + // {{{ + input wire i_wb_stall, i_wb_ack, + input wire [DW-1:0] i_wb_data, + input wire i_wb_err, + // }}} + // And our codeword outputs + // {{{ + output reg o_stb, + output reg [35:0] o_codword + // }}} + // }}} + ); + + // Local declarations + // {{{ + // localparam [5:0] END_OF_WRITE = 6'h2e; localparam [1:0] WB_IDLE = 2'b00, WB_READ_REQUEST = 2'b01, WB_WRITE_REQUEST = 2'b10, @@ -57,32 +84,28 @@ module wbuexec(i_clk, i_reset, i_stb, i_codword, o_busy, WB_FLUSH_WRITE_REQUESTS = 2'b11; localparam [1:0] WRITE_PREFIX = 2'b01; - // - input wire i_clk, i_reset; - // The command inputs - input wire i_stb; - input wire [35:0] i_codword; - output reg o_busy; - // Wishbone outputs - output reg o_wb_cyc; - output reg o_wb_stb; - output reg o_wb_we; - output reg [31:0] o_wb_addr, o_wb_data; - // Wishbone inputs - input wire i_wb_stall, i_wb_ack, i_wb_err; - input wire [31:0] i_wb_data; - // And our codeword outputs - output reg o_stb; - output reg [35:0] o_codword; - wire [31:0] w_cod_data; - assign w_cod_data={ i_codword[32:31], i_codword[29:0] }; + +// wire w_accept, w_eow, w_newwr, w_new_err; +// // wire w_newad, w_newrd; +// assign w_accept = (i_stb)&&(!o_busy); +// // assign w_newad = (w_accept)&&(i_codword[35:34] == 2'b00); +// assign w_newwr = (w_accept)&&(i_codword[35:34] == WRITE_PREFIX); +// assign w_eow = (w_accept)&&(i_codword[35:30] == END_OF_WRITE); +// // assign w_newrd = (w_accept)&&(i_codword[35:34] == 2'b11); +// assign w_new_err = ((w_accept) +// &&(i_codword[35:33] != 3'h3) +// &&(i_codword[35:30] != END_OF_WRITE)); reg [1:0] wb_state; reg [9:0] r_acks_needed, r_len; reg r_inc, r_new_addr, last_read_request, last_ack, zero_acks; - reg single_read_request; + assign w_cod_data={ i_codword[32:31], i_codword[29:0] }; + // }}} + + // CYC, STB, wb_state and o_busy + // {{{ initial wb_state = WB_IDLE; initial o_wb_cyc = 1'b0; initial o_wb_stb = 1'b0; @@ -90,14 +113,18 @@ module wbuexec(i_clk, i_reset, i_stb, i_codword, o_busy, always @(posedge i_clk) if (i_reset) begin + // {{{ wb_state <= WB_IDLE; o_wb_cyc <= 1'b0; o_wb_stb <= 1'b0; o_busy <= 1'b0; + // }}} end else case(wb_state) WB_IDLE: begin + // {{{ o_wb_cyc <= 1'b0; o_wb_stb <= 1'b0; + o_busy <= 1'b0; // The new instruction. The following // don't matter if we're not running, @@ -110,7 +137,7 @@ module wbuexec(i_clk, i_reset, i_stb, i_codword, o_busy, // starting a write. Hence, let's always set it as // though we were about to start a write. // - o_wb_data <= w_cod_data; + // o_wb_data <= w_cod_data; // if (i_stb) begin @@ -146,7 +173,9 @@ module wbuexec(i_clk, i_reset, i_stb, i_codword, o_busy, ; endcase end end + // }}} WB_READ_REQUEST: begin + // {{{ o_wb_cyc <= 1'b1; // o_wb_stb <= 1'b1; @@ -156,7 +185,7 @@ module wbuexec(i_clk, i_reset, i_stb, i_codword, o_busy, if (!i_wb_stall) // Deal with the strobe line begin // Strobe was accepted, busy should be '1' here - if ((single_read_request)||(last_read_request)) + if (last_read_request) o_wb_stb <= 1'b0; end @@ -174,43 +203,39 @@ module wbuexec(i_clk, i_reset, i_stb, i_codword, o_busy, wb_state <= WB_IDLE; o_busy <= 1'b0; end end + // }}} WB_WRITE_REQUEST: begin + // {{{ o_wb_cyc <= 1'b1; - // o_wb_stb <= 1'b1; o_busy <= 1'b1; - // - - // Don't need to worry about accepting anything new - // here, since we'll always be busy while in this state. - // Hence, we cannot accept new write requests. - // if (!i_wb_stall) o_wb_stb <= 1'b0; - if (!o_busy) - o_wb_data <= w_cod_data; - - if (i_stb && !o_wb_stb) + if (i_stb && (!o_wb_stb || !i_wb_stall)) begin if (o_busy && (i_codword[35:34] != WRITE_PREFIX) && zero_acks) begin o_wb_cyc <= 1'b0; - // o_busy <= 1'b0; + o_busy <= 1'b0; wb_state <= WB_IDLE; - end - - if (!o_busy) // && w_newwr must be true + end else if (!o_busy) // && w_newwr must be true begin o_wb_stb <= 1'b1; o_busy <= 1'b1; - end else if ((i_codword[35:34] == WRITE_PREFIX) - ||zero_acks) - // (r_acks_needed == (i_wb_ack ? 1:0))) + end else if (i_codword[35:34] == WRITE_PREFIX) o_busy <= 1'b0; end + if (!i_stb && !o_wb_stb && o_busy && zero_acks) + begin + o_wb_cyc <= 1'b0; + o_wb_stb <= 1'b0; + wb_state <= WB_IDLE; + o_busy <= 1'b0; + end + if (i_wb_err) // Bus returns an error begin o_wb_cyc <= 1'b0; @@ -218,7 +243,9 @@ module wbuexec(i_clk, i_reset, i_stb, i_codword, o_busy, wb_state <= WB_FLUSH_WRITE_REQUESTS; o_busy <= 1'b1; end end + // }}} WB_FLUSH_WRITE_REQUESTS: begin + // {{{ // We come in here after an error within a write // We need to wait until the command cycle finishes // issuing all its write commands before we can go back @@ -237,18 +264,26 @@ module wbuexec(i_clk, i_reset, i_stb, i_codword, o_busy, wb_state <= WB_IDLE; o_busy <= 1'b0; end end + // }}} default: begin + // {{{ wb_state <= WB_IDLE; o_wb_cyc <= 1'b0; o_wb_stb <= 1'b0; o_busy <= 1'b0; end + // }}} endcase + // }}} + + always @(posedge i_clk) + if (!o_busy) + o_wb_data <= w_cod_data; always @(posedge i_clk) if (wb_state == WB_IDLE) // Will this be a write? - o_wb_we <= (!i_codword[35]); + o_wb_we <= !i_codword[35]; always @(posedge i_clk) if (i_stb && !o_busy && i_codword[35:32] == 4'h0) @@ -335,10 +370,6 @@ module wbuexec(i_clk, i_reset, i_stb, i_codword, o_busy, 2'b01: zero_acks <= (r_acks_needed == 10'h01); default: begin end endcase -`ifdef FORMAL - always @(*) - assert(zero_acks == (r_acks_needed == 0)); -`endif always @(posedge i_clk) if (!o_wb_cyc) // (!o_wb_cyc)&&(i_codword[35:34] == 2'b11)) @@ -346,21 +377,8 @@ module wbuexec(i_clk, i_reset, i_stb, i_codword, o_busy, else if ((o_wb_stb)&&(!i_wb_stall)&&(|r_len)) r_len <= r_len - 10'h01; -// single_read_request and last_read_request used to be ... -// always @(posedge i_clk) -// begin -// single_read_request <= (!o_wb_cyc)&&(i_codword[9:0] <= 10'h01); -// // When there is one read request left, it will be the last one -// // will be the last one -// last_read_request <= (o_wb_stb)&&(r_len[9:2] == 8'h00) -// &&((!r_len[1]) -// ||((!r_len[0])&&(!i_wb_stall))); -// end - always @(posedge i_clk) begin - if (!o_wb_cyc) - single_read_request <= (i_codword[9:0] <= 10'h01); // When there is one read request left, it will be the last one // will be the last one if (!o_wb_cyc) diff --git a/rtl/wbubus/wbufifo.v b/rtl/wbubus/wbufifo.v index 9845164..296f346 100644 --- a/rtl/wbubus/wbufifo.v +++ b/rtl/wbubus/wbufifo.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: wbufifo.v -// +// {{{ // Project: FPGA library // // Purpose: This was once a FIFO for a UART ... but now it works as a @@ -12,9 +12,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -36,19 +36,24 @@ // //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none -// -module wbufifo(i_clk, i_reset, i_wr, i_data, i_rd, o_data, o_empty_n, o_err); - parameter BW=66, LGFLEN=10; - input wire i_clk, i_reset; - input wire i_wr; - input wire [(BW-1):0] i_data; - input wire i_rd; - output reg [(BW-1):0] o_data; - output reg o_empty_n; - output wire o_err; - +// }}} +module wbufifo #( + parameter BW=66, LGFLEN=10 + ) ( + // {{{ + input wire i_clk, i_reset, + input wire i_wr, + input wire [(BW-1):0] i_data, + input wire i_rd, + output reg [(BW-1):0] o_data, + output reg o_empty_n, + output wire o_err + // }}} + ); + + // Local declarations + // {{{ localparam FLEN=(1< for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none -// -module wbuidleint(i_clk, i_stb, i_codword, i_cyc, i_busy, i_int, - o_stb, o_codword, o_busy, - i_tx_busy); +// }}} +module wbuidleint( + // {{{ + input wire i_clk, i_reset, + // From the FIFO following the bus executor + input wire i_stb, + input wire [35:0] i_codword, + // From the rest of the board + input wire i_cyc, i_busy, i_int, + // To the next stage + output reg o_stb, + output reg [35:0] o_codword, + output reg o_busy, + // Is the next stage busy? + input wire i_tx_busy + // }}} + ); + + // Local declarations + // {{{ localparam CW_INTERRUPT = { 6'h4, 30'h0000 }; // interrupt codeword localparam CW_BUSBUSY = { 6'h1, 30'h0000 }; // bus busy, ow idle localparam CW_IDLE = { 6'h0, 30'h0000 }; // idle codeword - - input wire i_clk; - // From the FIFO following the bus executor - input wire i_stb; - input wire [35:0] i_codword; - // From the rest of the board - input wire i_cyc, i_busy, i_int; - // To the next stage - output reg o_stb; - output reg [35:0] o_codword; - output reg o_busy; - // Is the next stage busy? - input wire i_tx_busy; +`ifdef VERILATOR + localparam IDLEBITS = 22; +`else + localparam IDLEBITS = 31; +`endif reg int_request, int_sent; wire idle_expired; reg idle_state; reg [IDLEBITS-1:0] idle_counter; + // }}} + // int_request + // {{{ initial int_request = 1'b0; always @(posedge i_clk) - if((o_stb)&&(!i_tx_busy)&&(o_codword[35:30]==6'h4)) - int_request <= i_int; - else - int_request <= (int_request)||(i_int); + if (i_reset) + int_request <= 0; + else if (i_int) + int_request <= 1; + else if((o_stb)&&(!i_tx_busy)&&(o_codword[35:30]==CW_INTERRUPT[35:30])) + int_request <= 0; + // }}} -`ifdef VERILATOR - localparam IDLEBITS = 22; -`else - localparam IDLEBITS = 31; -`endif + // idle_counter + // {{{ // Now, for the idle counter initial idle_counter = 0; always @(posedge i_clk) - if ((i_stb)||(o_stb)||(i_busy)) + if (i_reset || (i_stb)||(o_stb)||(i_busy)) idle_counter <= 0; else if (!idle_counter[IDLEBITS-1]) idle_counter <= idle_counter + 1; + // }}} + // idle_state + // {{{ initial idle_state = 1'b0; always @(posedge i_clk) - if ((o_stb)&&(!i_tx_busy)&&(o_codword[35:30]==CW_IDLE[35:30])) + if (i_reset) + // We are now idle, and can rest + idle_state <= 1'b1; + else if ((o_stb)&&(!i_tx_busy)&&(o_codword[35:30]==CW_IDLE[35:30])) // We are now idle, and can rest idle_state <= 1'b1; else if (!idle_counter[IDLEBITS-1]) // We became active, and can rest no longer idle_state <= 1'b0; + // }}} assign idle_expired = (!idle_state)&&(idle_counter[IDLEBITS-1]); + // o_stb, o_codword + // {{{ initial o_stb = 1'b0; always @(posedge i_clk) - if(!o_stb || !i_tx_busy) begin - if (i_stb) - begin // On a valid output, just send it out - // We'll open this strobe, even if the transmitter - // is busy, just 'cause we might otherwise lose it - o_stb <= 1'b1; - o_codword <= i_codword; - end else begin - // Our indicators take a clock to reset, hence - // we'll idle for one clock before sending either an - // interrupt or an idle indicator. The bus busy - // indicator is really only ever used to let us know - // that something's broken. - o_stb <= (!o_stb)&&(int_request || idle_expired); - - if (int_request && !int_sent) - o_codword[35:30] <= CW_INTERRUPT[35:30]; - else begin - o_codword[35:30] <= CW_IDLE[35:30]; - if (i_cyc) - o_codword[35:30] <= CW_BUSBUSY[35:30]; + if(!o_stb || !i_tx_busy) + begin + if (i_stb) + begin + // On a valid output, just send it out + // We'll open this strobe, even if the + // transmitter is busy, just 'cause we might + // otherwise lose it + o_stb <= 1'b1; + o_codword <= i_codword; + end else begin + // Our indicators take a clock to reset, hence + // we'll idle for one clock before sending + // either an interrupt or an idle indicator. + // The bus busy indicator is really only ever + // used to let us know that something's broken. + o_stb <= (!o_stb)&&(int_request || idle_expired); + + if (int_request && !int_sent) + o_codword[35:30] <= CW_INTERRUPT[35:30]; + else begin + o_codword[35:30] <= CW_IDLE[35:30]; + if (i_cyc) + o_codword[35:30] <= CW_BUSBUSY[35:30]; + end end end + + if (i_reset) + o_stb <= 1'b0; end + // }}} always @(*) o_busy = o_stb; + // int_sent + // {{{ initial int_sent = 1'b0; always @(posedge i_clk) - if ((int_request)&&((!o_stb)&&(!o_busy)&&(!i_stb))) + if (i_reset) + int_sent <= 1'b0; + else if ((int_request)&&((!o_stb)&&(!o_busy)&&(!i_stb))) int_sent <= 1'b1; - else if (~i_int) + else if (!i_int) int_sent <= 1'b0; - + // }}} endmodule diff --git a/rtl/wbubus/wbuinput.v b/rtl/wbubus/wbuinput.v index 2f4418b..a2c2bfd 100644 --- a/rtl/wbubus/wbuinput.v +++ b/rtl/wbubus/wbuinput.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: wbuinput.v -// +// {{{ // Project: FPGA library // // Purpose: Coordinates the receiption of bytes, which are then translated @@ -15,9 +15,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -32,30 +32,36 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none -// -module wbuinput(i_clk, i_stb, i_byte, o_stb, o_codword); - input wire i_clk, i_stb; - input wire [7:0] i_byte; - output wire o_stb; - output wire [35:0] o_codword; +// }}} +module wbuinput ( + // {{{ + input wire i_clk, i_reset, + i_stb, + input wire [7:0] i_byte, + output wire o_soft_reset, + output wire o_stb, + output wire [35:0] o_codword + // }}} + ); wire hx_stb, hx_valid; wire [5:0] hx_hexbits; - wbutohex tobits(i_clk, i_stb, i_byte, - hx_stb, hx_valid, hx_hexbits); wire cw_stb; wire [35:0] cw_word; - wbureadcw formcw(i_clk, hx_stb, hx_valid, hx_hexbits, + + wbutohex tobits(i_clk, i_reset, i_stb, i_byte, o_soft_reset, + hx_stb, hx_valid, hx_hexbits); + + wbureadcw formcw(i_clk, i_reset, hx_stb, hx_valid, hx_hexbits, cw_stb, cw_word); // `define DEBUGGING @@ -63,7 +69,8 @@ module wbuinput(i_clk, i_stb, i_byte, o_stb, o_codword); assign o_stb = cw_stb; assign o_codword = cw_word; `else - wbudecompress unpack(i_clk,cw_stb,cw_word, o_stb, o_codword); + wbudecompress unpack(i_clk, i_reset, + cw_stb, cw_word, o_stb, o_codword); `endif endmodule diff --git a/rtl/wbubus/wbuoutput.v b/rtl/wbubus/wbuoutput.v index 55a7143..28482bf 100644 --- a/rtl/wbubus/wbuoutput.v +++ b/rtl/wbubus/wbuoutput.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: wbuoutput.v -// +// {{{ // Project: FPGA library // // Purpose: Converts 36-bit codewords into bytes to be placed on the serial @@ -14,9 +14,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -31,32 +31,35 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none -// -module wbuoutput(i_clk, i_rst, i_stb, i_codword, - i_wb_cyc, i_int, i_bus_busy, - o_stb, o_char, i_tx_busy, o_fifo_err); - parameter LGOUTPUT_FIFO = 10; - input wire i_clk, i_rst; - input wire i_stb; - input wire [35:0] i_codword; - // Not Idle indicators - input wire i_wb_cyc, i_int, i_bus_busy; - // Outputs to our UART transmitter - output wire o_stb; - output wire [7:0] o_char; - // Miscellaneous I/O: UART transmitter busy, and fifo error - input wire i_tx_busy; - output wire o_fifo_err; +// }}} +module wbuoutput #( + parameter LGOUTPUT_FIFO = 10 + ) ( + // {{{ + input wire i_clk, i_reset, i_soft_reset, + input wire i_stb, + input wire [35:0] i_codword, + // Not Idle indicators + input wire i_wb_cyc, i_int, i_bus_busy, + // Outputs to our UART transmitter + output wire o_stb, + output wire [7:0] o_char, + // Miscellaneous I/O: UART transmitter busy, and fifo error + input wire i_tx_busy, + output wire o_fifo_err + // }}} + ); + // Local declarations + // {{{ wire fifo_rd, dw_busy, fifo_empty_n, fifo_err; wire [35:0] fifo_codword; @@ -64,7 +67,10 @@ module wbuoutput(i_clk, i_rst, i_stb, i_codword, cp_busy, byte_busy; wire [35:0] cw_codword, cp_word; wire [6:0] dw_bits, ln_bits; + // }}} + // Output FIFO + // {{{ generate if (LGOUTPUT_FIFO < 2) begin : NO_OUTBOUND_FIFO @@ -77,15 +83,16 @@ module wbuoutput(i_clk, i_rst, i_stb, i_codword, assign fifo_rd = (fifo_empty_n)&&(!cw_busy); wbufifo #(36,LGOUTPUT_FIFO) - busoutfifo(i_clk, i_rst, i_stb, i_codword, + busoutfifo(i_clk, i_soft_reset, i_stb, i_codword, fifo_rd, fifo_codword, fifo_empty_n, fifo_err); end endgenerate assign o_fifo_err = fifo_err; + // }}} - wbuidleint buildcw(i_clk, fifo_rd, fifo_codword, + wbuidleint buildcw(i_clk, i_soft_reset, fifo_rd, fifo_codword, i_wb_cyc, i_bus_busy, i_int, cw_stb, cw_codword, cw_busy, cp_stb && cp_busy); // assign o_dbg = dw_busy; // Always asserted ... ??? @@ -105,18 +112,18 @@ module wbuoutput(i_clk, i_rst, i_stb, i_codword, assign cp_word = cw_codword; assign cp_busy = dw_busy; `else - wbucompress packit(i_clk, 1'b0, cw_stb, cw_codword, dw_busy, + wbucompress packit(i_clk, i_soft_reset,cw_stb, cw_codword, dw_busy, cp_stb, cp_word, cp_busy); `endif - wbudeword deword(i_clk, cp_stb, cp_word, ln_busy, + wbudeword deword(i_clk, i_reset, cp_stb, cp_word, ln_busy, dw_stb, dw_bits, dw_busy); - wbucompactlines linepacker(i_clk, dw_stb, dw_bits, + wbucompactlines linepacker(i_clk, i_reset, dw_stb, dw_bits, ln_stb, ln_bits, (i_wb_cyc||i_bus_busy||fifo_empty_n||cw_busy), byte_busy, ln_busy); - wbusixchar mkbytes(i_clk, ln_stb, ln_bits, o_stb, o_char, byte_busy, i_tx_busy); + wbusixchar mkbytes(i_clk, i_reset, ln_stb, ln_bits, o_stb, o_char, byte_busy, i_tx_busy); endmodule diff --git a/rtl/wbubus/wbureadcw.v b/rtl/wbubus/wbureadcw.v index 5fd2d8c..a43d3a9 100644 --- a/rtl/wbubus/wbureadcw.v +++ b/rtl/wbubus/wbureadcw.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: wbureadcw.v -// +// {{{ // Project: FPGA library // // Purpose: Read bytes from a serial port (i.e. the jtagser) and translate @@ -16,9 +16,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -33,26 +33,28 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none // // Goal: single clock pipeline, 50 slices or less -// -module wbureadcw(i_clk, i_stb, i_valid, i_hexbits, - o_stb, o_codword); - input wire i_clk, i_stb, i_valid; - input wire [5:0] i_hexbits; - output reg o_stb; - output reg [35:0] o_codword; - +// }}} +module wbureadcw( + // {{{ + input wire i_clk, i_reset, i_stb, i_valid, + input wire [5:0] i_hexbits, + output reg o_stb, + output reg [35:0] o_codword + // }}} + ); + // Local declarations + // {{{ // Timing: // Clock 0: i_stb is high, i_valid is low // Clock 1: shiftreg[5:0] is valid, cw_len is valid @@ -64,27 +66,35 @@ module wbureadcw(i_clk, i_stb, i_valid, i_hexbits, // cw_len = 0, // r_len = 0 (unless i_stb) // Ready for next word - reg [2:0] r_len, cw_len; reg [1:0] lastcw; wire w_stb; + reg [35:0] shiftreg; + + // }}} + assign w_stb = ((r_len == cw_len)&&(cw_len != 0)) ||((i_stb)&&(!i_valid)&&(lastcw == 2'b01)); + // r_len + // {{{ // r_len is the length of the codeword as it exists // in our register initial r_len = 3'h0; always @(posedge i_clk) - if ((i_stb)&&(!i_valid)) // Newline reset + if (i_reset) + r_len <= 0; + else if ((i_stb)&&(!i_valid)) // Newline reset r_len <= 0; else if (w_stb) // reset/restart w/o newline r_len <= (i_stb)? 3'h1:3'h0; else if (i_stb) //in middle of word r_len <= r_len + 3'h1; + // }}} - reg [35:0] shiftreg; - + // shiftreg + // {{{ initial shiftreg = 0; always @(posedge i_clk) if (w_stb) @@ -98,21 +108,34 @@ module wbureadcw(i_clk, i_stb, i_valid, i_hexbits, 3'b101: shiftreg[ 5: 0] <= i_hexbits; default: begin end endcase + // }}} + // lastcw + // {{{ initial lastcw = 2'b00; always @(posedge i_clk) if (o_stb) lastcw <= o_codword[35:34]; + // }}} + + // o_codword + // {{{ always @(posedge i_clk) if ((i_stb)&&(!i_valid)&&(lastcw == 2'b01)) + // End of write signal o_codword[35:30] <= 6'h2e; else o_codword <= shiftreg; + // }}} + // cw_len + // {{{ // How long do we expect this codeword to be? initial cw_len = 3'b000; always @(posedge i_clk) - if ((i_stb)&&(!i_valid)) + if (i_reset) + cw_len <= 0; + else if ((i_stb)&&(!i_valid)) cw_len <= 0; else if ((i_stb)&&((cw_len == 0)||(w_stb))) begin @@ -128,10 +151,13 @@ module wbureadcw(i_clk, i_stb, i_valid, i_hexbits, cw_len <= 3'h6; end else if (w_stb) cw_len <= 0; + // }}} + // o_stb + // {{{ initial o_stb = 1'b0; always @(posedge i_clk) - o_stb <= w_stb; - + o_stb <= w_stb && !i_reset; + // }}} endmodule diff --git a/rtl/wbubus/wbusixchar.v b/rtl/wbubus/wbusixchar.v index df36513..d03ff38 100644 --- a/rtl/wbubus/wbusixchar.v +++ b/rtl/wbubus/wbusixchar.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: wbusixchar.v -// +// {{{ // Project: FPGA library // // Purpose: Supports a conversion from a six digit bus to a printable @@ -21,9 +21,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -38,33 +38,45 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none -// -module wbusixchar(i_clk, i_stb, i_bits, o_stb, o_char, o_busy, i_busy); - input wire i_clk; - input wire i_stb; - input wire [6:0] i_bits; - output reg o_stb; - output reg [7:0] o_char; - output wire o_busy; - input wire i_busy; +// }}} +module wbusixchar( + // {{{ + input wire i_clk, i_reset, + input wire i_stb, + input wire [6:0] i_bits, + output reg o_stb, + output reg [7:0] o_char, + output wire o_busy, + input wire i_busy + // }}} + ); + // Local declarations + // {{{ + reg [6:0] remap [0:127]; + reg [6:0] newv; + // }}} + + // o_stb + // {{{ initial o_stb = 1'b0; always @(posedge i_clk) - if (!o_stb || !i_busy) + if (i_reset) + o_stb <= 1'b0; + else if (!o_stb || !i_busy) o_stb <= i_stb; + // }}} - reg [6:0] remap [0:127]; - reg [6:0] newv; - + // newv + // {{{ integer k; always @(*) begin for(k=0; k<128; k=k+1) @@ -93,13 +105,16 @@ module wbusixchar(i_clk, i_stb, i_bits, o_stb, o_char, o_busy, i_busy); remap[k] = newv; end end + // }}} + // o_char + // {{{ initial o_char = 8'h00; always @(posedge i_clk) if (!o_busy) o_char <= { 1'b0, remap[i_bits] }; + // }}} - assign o_busy = o_stb; - + assign o_busy = o_stb && i_busy; endmodule diff --git a/rtl/wbubus/wbutohex.v b/rtl/wbubus/wbutohex.v index 6e4c54d..5a5453a 100644 --- a/rtl/wbubus/wbutohex.v +++ b/rtl/wbubus/wbutohex.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: wbutohex.v -// +// {{{ // Project: FPGA library // // Purpose: Supports a printable character conversion from a printable @@ -21,9 +21,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -38,31 +38,41 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none -// -module wbutohex(i_clk, i_stb, i_byte, o_stb, o_valid, o_hexbits); - input wire i_clk, i_stb; - input wire [7:0] i_byte; - output reg o_stb, o_valid; - output reg [5:0] o_hexbits; - - initial o_stb = 1'b0; - always @(posedge i_clk) - o_stb <= i_stb; +// }}} +module wbutohex ( + // {{{ + input wire i_clk, i_reset, i_stb, + input wire [7:0] i_byte, + output reg o_soft_reset, + output reg o_stb, o_valid, + output reg [5:0] o_hexbits + // }}} + ); + // Local declarations + // {{{ reg [6:0] remap [0:127]; - integer k; reg [6:0] newv; + // }}} + + // o_stb + // {{{ + initial o_stb = 1'b0; + always @(posedge i_clk) + o_stb <= i_stb && !i_reset; + // }}} + // newv, remap + // {{{ always @(*) // initial begin @@ -91,14 +101,26 @@ module wbutohex(i_clk, i_stb, i_byte, o_stb, o_valid, o_hexbits); remap[k] = newv; end end - + // }}} + + // o_valid + // {{{ always @(posedge i_clk) begin { o_valid, o_hexbits } <= remap[i_byte[6:0]]; if (i_byte[7]) o_valid <= 0; end + // }}} - + // o_soft_reset + // {{{ + initial o_soft_reset = 1'b1; + always @(posedge i_clk) + if (i_reset) + o_soft_reset <= 1; + else + o_soft_reset <= i_stb && (i_byte[6:0] == 7'h3); + // }}} endmodule diff --git a/sim/verilated/automaster_tb.cpp b/sim/verilated/automaster_tb.cpp index c1a1ed1..652090f 100644 --- a/sim/verilated/automaster_tb.cpp +++ b/sim/verilated/automaster_tb.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: automaster_tb.cpp -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: This file calls and accesses the main.v function via the @@ -13,9 +13,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2019, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -30,14 +30,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #include #include #include @@ -56,6 +56,7 @@ #include "main_tb.cpp" void usage(void) { + // {{{ fprintf(stderr, "USAGE: main_tb [zipcpu-elf-file]\n"); fprintf(stderr, #ifdef SDSPI_ACCESS @@ -70,8 +71,11 @@ void usage(void) { "\t\tbe a vcd file\n" ); } +// }}} int main(int argc, char **argv) { + // Variable declaration and initialization + // {{{ #ifdef OLED_ACCESS Gtk::Main main_instance(argc, argv); #endif @@ -87,7 +91,10 @@ int main(int argc, char **argv) { FILE *profile_fp; MAINTB *tb = new MAINTB; + // }}} + // Process arguments + // {{{ for(int argn=1; argn < argc; argn++) { if (argv[argn][0] == '-') for(int j=1; (j<512)&&(argv[argn][j]);j++) { @@ -120,7 +127,10 @@ int main(int argc, char **argv) { exit(EXIT_FAILURE); } } + // }}} + // Setup + // {{{ if (elfload) willexit = true; if (debug_flag) { @@ -146,13 +156,15 @@ int main(int argc, char **argv) { } } else profile_fp = NULL; - + // }}} tb->reset(); #ifdef SDSPI_ACCESS tb->setsdcard(sdimage_file); #endif + // Load the ZipCPU + // {{{ if (elfload) { #ifndef INCLUDE_ZIPCPU fprintf(stderr, "ERR: Design has no ZipCPU\n"); @@ -189,11 +201,15 @@ int main(int argc, char **argv) { tb->m_core->cpu_cmd_halt = 0; tb->m_core->VVAR(_swic__DOT__cmd_reset) = 0; } + // }}} + // Main while(1) loop + // {{{ #ifdef OLED_ACCESS Gtk::Main::run(tb->m_oled); #else - if (profile_fp) { + if (profile_fp) { // Profile the ZipCPU + // {{{ unsigned long last_instruction_tick = 0, now = 0; while((!willexit)||(!tb->done())) { unsigned long iticks; @@ -214,13 +230,19 @@ int main(int argc, char **argv) { last_instruction_tick = now; } } - } else if (willexit) { + // }}} + } else if (willexit) { // Run until an exit call + // {{{ while(!tb->done()) tb->tick(); - } else + // }}} + } else // Run forever + // {{{ while(true) tb->tick(); + // }}} #endif + // }}} tb->close(); delete tb; diff --git a/sim/verilated/busmaster_tb.cpp b/sim/verilated/busmaster_tb.cpp index 939abee..8c930a6 100644 --- a/sim/verilated/busmaster_tb.cpp +++ b/sim/verilated/busmaster_tb.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: busmaster_tb.cpp -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: This is piped version of the testbench for the busmaster @@ -15,9 +15,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2017, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -32,14 +32,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #include #include #include diff --git a/sim/verilated/byteswap.cpp b/sim/verilated/byteswap.cpp index c723d5a..02f14d1 100644 --- a/sim/verilated/byteswap.cpp +++ b/sim/verilated/byteswap.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: byteswap.cpp -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: To convert between little endian and big endian byte orders, @@ -13,9 +13,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2019, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -30,14 +30,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #include #include "byteswap.h" diff --git a/sim/verilated/byteswap.h b/sim/verilated/byteswap.h index 0e7e131..00a65c1 100644 --- a/sim/verilated/byteswap.h +++ b/sim/verilated/byteswap.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: byteswap.h -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: To convert between little endian and big endian byte orders, @@ -13,9 +13,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2019, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -30,14 +30,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #ifndef BYTESWAP_H #define BYTESWAP_H diff --git a/sim/verilated/dblpipecmdr.h b/sim/verilated/dblpipecmdr.h index 51c7553..bfd93fb 100644 --- a/sim/verilated/dblpipecmdr.h +++ b/sim/verilated/dblpipecmdr.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: dblpipecmdr.h -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: This program attaches to a Verilated Verilog IP core. @@ -21,9 +21,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2017, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -38,14 +38,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #ifndef DBLPIPECMDR_H #define DBLPIPECMDR_H diff --git a/sim/verilated/dbluartsim.cpp b/sim/verilated/dbluartsim.cpp index 970bf55..94ba6e3 100644 --- a/sim/verilated/dbluartsim.cpp +++ b/sim/verilated/dbluartsim.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: dbluartsim.cpp -// +// {{{ // Project: wbuart32, a full featured UART with simulator // // Purpose: To forward a Verilator simulated UART link over a pair of @@ -14,9 +14,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2019, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -31,14 +31,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #include #include #include diff --git a/sim/verilated/dbluartsim.h b/sim/verilated/dbluartsim.h index 59f25c6..44e208f 100644 --- a/sim/verilated/dbluartsim.h +++ b/sim/verilated/dbluartsim.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: dbluartsim.h -// +// {{{ // Project: wbuart32, a full featured UART with simulator // // Purpose: To forward a Verilator simulated UART link, demultiplexed over @@ -14,9 +14,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2019, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -31,14 +31,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #ifndef DBLUARTSIM_H #define DBLUARTSIM_H diff --git a/sim/verilated/flashsim.cpp b/sim/verilated/flashsim.cpp index c2694e1..4687b37 100644 --- a/sim/verilated/flashsim.cpp +++ b/sim/verilated/flashsim.cpp @@ -16,7 +16,7 @@ // //////////////////////////////////////////////////////////////////////////////// // -// Copyright (C) 2015,2017-2019, Gisselquist Technology, LLC +// Copyright (C) 2015-2021, Gisselquist Technology, LLC // // This file is part of the set of Wishbone controlled SPI flash controllers // project @@ -437,8 +437,9 @@ int FLASHSIM::operator()(const int csn, const int sck, const int dat) { m_state = QSPIF_QUAD_READ_CMD; m_mode = FM_QSPI; break; - case 0x000: - case 0x0ff: + case 0x000: // Dummy implementation of CMD 8'h00 + case 0x031: // Dummy implementation of CMD 8'h31 + case 0x0ff: // Dummy implementation of CMD 8'hff m_state = QSPIF_IDLE; m_mode = FM_SPI; break; @@ -582,7 +583,7 @@ int FLASHSIM::operator()(const int csn, const int sck, const int dat) { } } else if ((m_count >= 24+4*NDUMMY)&&(0 == (m_sreg&0x01))) { QOREG(m_mem[m_addr++]); - if (m_debug) printf("QSPIF[%08x]/QR = %02x\n", m_addr-1, m_oreg & 0x0ff); + // if (m_debug) printf("QSPIF[%08x]/QR = %02x\n", m_addr-1, m_oreg & 0x0ff); } else m_oreg = 0; break; case QSPIF_PP: diff --git a/sim/verilated/flashsim.h b/sim/verilated/flashsim.h index c6f8bbb..6679f35 100644 --- a/sim/verilated/flashsim.h +++ b/sim/verilated/flashsim.h @@ -14,7 +14,7 @@ // //////////////////////////////////////////////////////////////////////////////// // -// Copyright (C) 2015-2019, Gisselquist Technology, LLC +// Copyright (C) 2015-2021, Gisselquist Technology, LLC // // This file is part of the set of Wishbone controlled SPI flash controllers // project @@ -111,7 +111,7 @@ class FLASHSIM { void load(const unsigned addr, const char *fname); void load(const uint32_t offset, const char *data, const uint32_t len); bool write_protect(void) { return ((m_sreg & QSPIF_WEL_FLAG)==0); } - bool write_in_progress(void) { return ((m_sreg | QSPIF_WIP_FLAG)!=0); } + bool write_in_progress(void) { return ((m_sreg & QSPIF_WIP_FLAG)!=0); } bool xip_mode(void) { return (QSPIF_QUAD_READ_IDLE == m_state); } bool deep_sleep(bool newval); bool deep_sleep(void) const; diff --git a/sim/verilated/main_tb.cpp b/sim/verilated/main_tb.cpp index d7bce0c..7a91be7 100644 --- a/sim/verilated/main_tb.cpp +++ b/sim/verilated/main_tb.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: ./main_tb.cpp -// +// {{{ // Project: ZBasic, a generic toplevel implementation using the full ZipCPU // // DO NOT EDIT THIS FILE! @@ -14,9 +14,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2017-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2017-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -31,14 +31,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} // // SIM.INCLUDE // @@ -53,27 +53,18 @@ #include "design.h" #include "regdefs.h" #include "testb.h" -#include "dbluartsim.h" -#include "byteswap.h" -#include "flashsim.h" #include "zipelf.h" +#include "byteswap.h" +#include "dbluartsim.h" #include "sdspisim.h" +#include "flashsim.h" // // SIM.DEFINES // // This tag is useful fr pasting in any #define values that // might then control the simulation following. // -#ifndef VVAR -#ifdef NEW_VERILATOR -#define VVAR(A) main__DOT_ ## A -#else -#define VVAR(A) v__DOT_ ## A -#endif -#endif - -#define block_ram VVAR(_bkrami__DOT__mem) #ifndef VVAR #ifdef NEW_VERILATOR #define VVAR(A) main__DOT_ ## A @@ -82,7 +73,7 @@ #endif #endif -#define CPUVAR(A) VVAR(_swic__DOT__thecpu__DOT_ ## A) +#define CPUVAR(A) VVAR(_swic__DOT__thecpu__DOT__core__DOT_ ## A) #define cpu_reset VVAR(_swic__DOT__cmd_reset) #define cpu_break VVAR(_swic__DOT__cpu_break) @@ -119,6 +110,15 @@ #define cpu_wr_reg_id CPUVAR(_wr_reg_id) #define cpu_wr_gpreg CPUVAR(_wr_gpreg_vl) +#ifndef VVAR +#ifdef NEW_VERILATOR +#define VVAR(A) main__DOT_ ## A +#else +#define VVAR(A) v__DOT_ ## A +#endif +#endif + +#define block_ram VVAR(_bkrami__DOT__mem) #ifndef VVAR #ifdef NEW_VERILATOR @@ -163,14 +163,14 @@ class MAINTB : public TESTB { // If you have any simulation components, create a // SIM.DEFNS tag to have those components defined here // as part of the main_tb.cpp function. - DBLUARTSIM *m_wbu; -#ifdef FLASH_ACCESS - FLASHSIM *m_flash; -#endif // FLASH_ACCESS int m_cpu_bombed; + DBLUARTSIM *m_wbu; #ifdef SDSPI_ACCESS SDSPISIM m_sdcard; #endif // SDSPI_ACCESS +#ifdef FLASH_ACCESS + FLASHSIM *m_flash; +#endif // FLASH_ACCESS MAINTB(void) { // SIM.INIT // @@ -178,19 +178,19 @@ class MAINTB : public TESTB { // create a SIM.INIT tag. That tag's value will be pasted // here. // + // From zip + m_cpu_bombed = 0; // From wbu m_wbu = new DBLUARTSIM(); m_wbu->setup(100); - // From flash -#ifdef FLASH_ACCESS - m_flash = new FLASHSIM(FLASHLGLEN, false, 0, 6); -#endif // FLASH_ACCESS - // From zip - m_cpu_bombed = 0; // From sdcard #ifdef SDSPI_ACCESS m_sdcard.debug(false); #endif // SDSPI_ACCESS + // From flash +#ifdef FLASH_ACCESS + m_flash = new FLASHSIM(FLASHLGLEN, false, 0, 6); +#endif // FLASH_ACCESS } void reset(void) { @@ -236,16 +236,6 @@ class MAINTB : public TESTB { // // SIM.TICK tags go here for SIM.CLOCK=clk // - // SIM.TICK from wbu - m_core->i_wbu_uart_rx = (*m_wbu)(m_core->o_wbu_uart_tx); - // SIM.TICK from flash -#ifdef FLASH_ACCESS - m_core->i_qspi_dat = m_flash->simtick( - m_core->o_qspi_cs_n, - m_core->o_qspi_sck, - m_core->o_qspi_dat, - m_core->o_qspi_mod); -#endif // FLASH_ACCESS // SIM.TICK from zip #ifdef INCLUDE_ZIPCPU // ZipCPU Sim instruction support @@ -265,6 +255,8 @@ class MAINTB : public TESTB { } #endif // INCLUDE_ZIPCPU + // SIM.TICK from wbu + m_core->i_wbu_uart_rx = (*m_wbu)(m_core->o_wbu_uart_tx); // SIM.TICK from sdcard #ifdef SDSPI_ACCESS m_core->i_sd_data = m_sdcard((m_core->o_sd_data&8)?1:0, @@ -273,6 +265,14 @@ class MAINTB : public TESTB { m_core->i_sd_data |= (m_core->o_sd_data&0x0e); m_core->i_sd_detect = 1; #endif // SDSPI_ACCESS + // SIM.TICK from flash +#ifdef FLASH_ACCESS + m_core->i_qspi_dat = m_flash->simtick( + m_core->o_qspi_cs_n, + m_core->o_qspi_sck, + m_core->o_qspi_dat, + m_core->o_qspi_mod); +#endif // FLASH_ACCESS writeout = false; // // SIM.DBGCONDITION diff --git a/sim/verilated/memsim.cpp b/sim/verilated/memsim.cpp index bf25d95..0276798 100644 --- a/sim/verilated/memsim.cpp +++ b/sim/verilated/memsim.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: memsim.cpp -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: This creates a memory like device to act on a WISHBONE bus. @@ -18,9 +18,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2019, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -35,14 +35,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #include #include #include diff --git a/sim/verilated/memsim.h b/sim/verilated/memsim.h index 6873dfc..9147e1a 100644 --- a/sim/verilated/memsim.h +++ b/sim/verilated/memsim.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: memsim.h -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: This creates a memory like device to act on a WISHBONE bus. @@ -18,9 +18,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2019, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -35,14 +35,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #ifndef MEMSIM_H #define MEMSIM_H diff --git a/sim/verilated/pipecmdr.h b/sim/verilated/pipecmdr.h index 03d0d59..cda5ea6 100644 --- a/sim/verilated/pipecmdr.h +++ b/sim/verilated/pipecmdr.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: pipecmdr.h -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: This program attaches to a Verilated Verilog IP core. @@ -16,9 +16,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2017, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -33,14 +33,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #ifndef PIPECMDR_H #define PIPECMDR_H diff --git a/sim/verilated/port.h b/sim/verilated/port.h index 7cfaab9..39818d5 100644 --- a/sim/verilated/port.h +++ b/sim/verilated/port.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: port.h -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: Defines the communication parameters necessary for communicating @@ -12,9 +12,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2018, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -29,14 +29,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #ifndef PORT_H #define PORT_H diff --git a/sim/verilated/sdspisim.cpp b/sim/verilated/sdspisim.cpp index 2018d7a..b256058 100644 --- a/sim/verilated/sdspisim.cpp +++ b/sim/verilated/sdspisim.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: sdspisim.cpp -// +// {{{ // Project: Wishbone Controlled SD-Card Controller over SPI port // // Purpose: This library simulates the operation of a SPI commanded SD-Card, @@ -14,9 +14,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2019, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -31,14 +31,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #include #include #include diff --git a/sim/verilated/sdspisim.h b/sim/verilated/sdspisim.h index 200174d..fe0aac0 100644 --- a/sim/verilated/sdspisim.h +++ b/sim/verilated/sdspisim.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: sdspisim.h -// +// {{{ // Project: Wishbone Controlled SD-Card Controller over SPI port // // Purpose: This library simulates the operation of a SPI commanded SD-Card, @@ -14,9 +14,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2019, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -31,14 +31,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #ifndef SDSPISIM_H #define SDSPISIM_H diff --git a/sim/verilated/tbclock.h b/sim/verilated/tbclock.h index 18fde63..4a0374c 100644 --- a/sim/verilated/tbclock.h +++ b/sim/verilated/tbclock.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: tbclock.h -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: TBCLOCK is a class originally developed for the VideoZIP project @@ -13,9 +13,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2019, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2017-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -30,14 +30,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #ifndef TBCLOCK_H #define TBCLOCK_H diff --git a/sim/verilated/testb.h b/sim/verilated/testb.h index 615ccd4..17eb123 100644 --- a/sim/verilated/testb.h +++ b/sim/verilated/testb.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: ./testb.h -// +// {{{ // Project: ZBasic, a generic toplevel implementation using the full ZipCPU // // DO NOT EDIT THIS FILE! @@ -14,9 +14,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2017-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2017-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -31,14 +31,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #ifndef TESTB_H #define TESTB_H diff --git a/sim/verilated/twoc.cpp b/sim/verilated/twoc.cpp index 429b88f..e234178 100644 --- a/sim/verilated/twoc.cpp +++ b/sim/verilated/twoc.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: twoc.cpp -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: Some various two's complement related C++ helper routines. @@ -13,9 +13,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -30,14 +30,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #include "twoc.h" long sbits(const long val, const int bits) { diff --git a/sim/verilated/twoc.h b/sim/verilated/twoc.h index cf48564..537094c 100644 --- a/sim/verilated/twoc.h +++ b/sim/verilated/twoc.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: twoc.h -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: Some various two's complement related C++ helper routines. @@ -13,9 +13,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -30,14 +30,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #ifndef TWOC_H #define TWOC_H diff --git a/sim/verilated/uartsim.cpp b/sim/verilated/uartsim.cpp index 45efb2e..19eb4e6 100644 --- a/sim/verilated/uartsim.cpp +++ b/sim/verilated/uartsim.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: uartsim.cpp -// +// {{{ // Project: wbuart32, a full featured UART with simulator // // Purpose: To forward a Verilator simulated UART link over a TCP/IP pipe. @@ -10,9 +10,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2019, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -27,14 +27,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #include #include #include diff --git a/sim/verilated/uartsim.h b/sim/verilated/uartsim.h index 3e5f5bb..71d531c 100644 --- a/sim/verilated/uartsim.h +++ b/sim/verilated/uartsim.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: uartsim.h -// +// {{{ // Project: wbuart32, a full featured UART with simulator // // Purpose: To forward a Verilator simulated UART link over a TCP/IP pipe. @@ -13,9 +13,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2019, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -30,14 +30,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #ifndef UARTSIM_H #define UARTSIM_H diff --git a/sim/verilated/vversion.sh b/sim/verilated/vversion.sh index c2a2178..39a8235 100755 --- a/sim/verilated/vversion.sh +++ b/sim/verilated/vversion.sh @@ -2,7 +2,7 @@ ################################################################################ ## ## Filename: vversion.sh -## +## {{{ ## Project: ZBasic, a generic toplevel impl using the full ZipCPU ## ## Purpose: To determine whether or not the verilator prefix for internal @@ -14,9 +14,9 @@ ## Gisselquist Technology, LLC ## ################################################################################ -## -## Copyright (C) 2017-2018, Gisselquist Technology, LLC -## +## }}} +## Copyright (C) 2017-2021, Gisselquist Technology, LLC +## {{{ ## This program is free software (firmware): 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 @@ -31,14 +31,14 @@ ## with this program. (It's in the $(ROOT)/doc directory. Run make with no ## target there if the PDF file isn't present.) If not, see ## for a copy. -## +## }}} ## License: GPL, v3, as defined and found on www.gnu.org, +## {{{ ## http://www.gnu.org/licenses/gpl.html ## -## ################################################################################ ## -## +## }}} if [[ -x ${VERILATOR_ROOT}/bin/verilator ]]; then export VERILATOR=${VERILATOR_ROOT}/bin/verilator diff --git a/sim/verilated/zipelf.cpp b/sim/verilated/zipelf.cpp index f29d0ff..f8bb907 100644 --- a/sim/verilated/zipelf.cpp +++ b/sim/verilated/zipelf.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: zipelf.cpp -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: @@ -11,9 +11,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2019, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -28,15 +28,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// - +// }}} #include #include #include diff --git a/sim/verilated/zipelf.h b/sim/verilated/zipelf.h index 467731b..7ba4fbe 100644 --- a/sim/verilated/zipelf.h +++ b/sim/verilated/zipelf.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: zipelf.h -// +// {{{ // Project: Zip CPU -- a small, lightweight, RISC CPU soft core // // Purpose: @@ -11,9 +11,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2019, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -28,14 +28,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #ifndef ZIPELF_H #define ZIPELF_H diff --git a/sw/board/Makefile b/sw/board/Makefile index 9637317..0e70158 100644 --- a/sw/board/Makefile +++ b/sw/board/Makefile @@ -1,7 +1,7 @@ ################################################################################ ## ## Filename: Makefile -## +## {{{ ## Project: ZBasic, a generic toplevel impl using the full ZipCPU ## ## Purpose: @@ -10,9 +10,9 @@ ## Gisselquist Technology, LLC ## ################################################################################ -## -## Copyright (C) 2016-2020, Gisselquist Technology, LLC -## +## }}} +## Copyright (C) 2016-2021, Gisselquist Technology, LLC +## {{{ ## This program is free software (firmware): 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 @@ -27,14 +27,14 @@ ## with this program. (It's in the $(ROOT)/doc directory. Run make with no ## target there if the PDF file isn't present.) If not, see ## for a copy. -## +## }}} ## License: GPL, v3, as defined and found on www.gnu.org, +## {{{ ## http://www.gnu.org/licenses/gpl.html ## -## ################################################################################ ## -## +## }}} .PHONY: all PROGRAMS := hello sdtest cputest gpiotoggle contest all: $(PROGRAMS) @@ -96,7 +96,8 @@ $(OBJDIR)/cputest.s: cputest.c $(CC) $(CFLAGS) -S -Wa,-cis -fno-builtin $< -o $@ cputest: $(OBJDIR)/cputestcis.o board.ld $(LIB) - $(CC) $(CFLAGS) $(LFLAGS) $< $(LIBS) -o $@ + # $(CC) $(CFLAGS) $(LFLAGS) $< $(LIBS) -o $@ + $(CC) $(CFLAGS) $(LBKRAM) $< $(LIBS) -o $@ $(OBJDIR)/contest.o: contest.c diff --git a/sw/board/bkram.ld b/sw/board/bkram.ld index 216d0ab..b6c6f91 100644 --- a/sw/board/bkram.ld +++ b/sw/board/bkram.ld @@ -1,7 +1,7 @@ /******************************************************************************* * * Filename: bkram.ld -* +* {{{ * Project: ZBasic, a generic toplevel implementation using the full ZipCPU * * DO NOT EDIT THIS FILE! @@ -14,9 +14,9 @@ * Gisselquist Technology, LLC * /******************************************************************************* -* -* Copyright (C) 2017-2020, Gisselquist Technology, LLC -* +* }}} +* Copyright (C) 2017-2021, Gisselquist Technology, LLC +* {{{ * This program is free software (firmware): 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 @@ -31,14 +31,14 @@ * with this program. (It's in the $(ROOT)/doc directory. Run make with no * target there if the PDF file isn't present.) If not, see * for a copy. -* +* }}} * License: GPL, v3, as defined and found on www.gnu.org, +* {{{ * http://www.gnu.org/licenses/gpl.html * -* /******************************************************************************* * -* +* }}} */ ENTRY(_start) diff --git a/sw/board/board.ld b/sw/board/board.ld index bba997a..a4b010b 100644 --- a/sw/board/board.ld +++ b/sw/board/board.ld @@ -1,7 +1,7 @@ /******************************************************************************* * * Filename: board.ld -* +* {{{ * Project: ZBasic, a generic toplevel implementation using the full ZipCPU * * DO NOT EDIT THIS FILE! @@ -14,9 +14,9 @@ * Gisselquist Technology, LLC * /******************************************************************************* -* -* Copyright (C) 2017-2020, Gisselquist Technology, LLC -* +* }}} +* Copyright (C) 2017-2021, Gisselquist Technology, LLC +* {{{ * This program is free software (firmware): 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 @@ -31,14 +31,14 @@ * with this program. (It's in the $(ROOT)/doc directory. Run make with no * target there if the PDF file isn't present.) If not, see * for a copy. -* +* }}} * License: GPL, v3, as defined and found on www.gnu.org, +* {{{ * http://www.gnu.org/licenses/gpl.html * -* /******************************************************************************* * -* +* }}} */ ENTRY(_start) diff --git a/sw/board/contest.c b/sw/board/contest.c index 42de449..1f597be 100644 --- a/sw/board/contest.c +++ b/sw/board/contest.c @@ -1,19 +1,20 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: contest.c -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // -// Purpose: Quick test of the interconnect, make sure everything responds -// like we are expecting it to. +// Purpose: A "connection-test". This is a quick test of the interconnect, +// just to make sure everything on the bus responds like we are +// expecting it to. // // Creator: Dan Gisselquist, Ph.D. // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2019, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2019-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -28,59 +29,21 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #include "board.h" #include "txfns.h" #include "zipcpu.h" #define SKIP_BOOTLOADER -/* -asm("\t.section\t.start,\"ax\",@progbits\n" - "\t.global\t_start\n" -"_start:" "\t; Here's the global ZipCPU entry point upon reset/reboot\n" - "\tLDI\t_top_of_stack,SP" "\t; Set up our supervisor stack ptr\n" - "\tMOV\t_kernel_is_dead(PC),uPC" "\t; Set user PC pointer to somewhere valid\n" -#ifndef SKIP_BOOTLOADER - "\tMOV\t_after_bootloader(PC),R0" " ; JSR to the bootloader routine\n" - "\tBRA\t_bootloader\n" -"_after_bootloader:\n" - "\tLDI\t_top_of_stack,SP" "\t; Set up our supervisor stack ptr\n" - "\tOR\t0xc000,CC" "\t; Clear the both caches\n" -#endif -#ifdef __USE_INIT_FINIT - "\tJSR\tinit" "\t; Initialize any constructor code\n" - // - "\tLDI\tfini,R1" "\t; \n" - "\tJSR\t_atexit" "\t; Initialize any constructor code\n" -#endif - // - "\tCLR\tR1" "\t; argc = 0\n" - "\tMOV\t_argv(PC),R2" "\t; argv = &0\n" -// "\tLDI\t__env,R3" "\t; env = NULL\n" - "\tJSR\tmain" "\t; Call the user main() function\n" - // -"_graceful_kernel_exit:" "\t; Halt on any return from main--gracefully\n" -// "\tJSR\texit\n" "\t; Call the _exit as part of exiting\n" -"\t.global\t_exit\n" -"_exit:\n" - "\tNEXIT\tR1\n" "\t; If in simulation, call an exit function\n" -"_kernel_is_dead:" "\t; Halt the CPU\n" - "\tHALT\n" "\t; We should *never* continue following a\n" - "\tBRA\t_kernel_is_dead" "\t; halt, do something useful if so ??\n" -"_argv:\n" - "\t.WORD\t0,0\n" - "\t.section\t.text"); -*/ - -void rwcheckm(const char *str, volatile unsigned *const a, const int mask){ +void rwcheckm(const char *str, volatile unsigned *const a, const int mask) { const unsigned NONCE = 0x12345678; unsigned original, failed; volatile char *const cp = (volatile char *const)a; diff --git a/sw/board/cputest.c b/sw/board/cputest.c index 32b4b88..35e1c49 100644 --- a/sw/board/cputest.c +++ b/sw/board/cputest.c @@ -1,7 +1,7 @@ /////////////////////////////////////////////////////////////////////////////// // // Filename: cputest.c -// +// {{{ // Project: Zip CPU -- a small, lightweight, RISC CPU soft core // // Purpose: To test the CPU, it's instructions, cache, and pipeline, to make @@ -13,9 +13,9 @@ // Gisselquist Technology, LLC // /////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -30,14 +30,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// /////////////////////////////////////////////////////////////////////////////// // -// +// }}} #include #include "board.h" #include "zipcpu.h" @@ -82,7 +82,7 @@ unsigned zip_ucc(void); unsigned zip_cc(void); -void zip_save_context(int *); +void zip_save_context(void *); void zip_halt(void); diff --git a/sw/board/gpiotoggle.c b/sw/board/gpiotoggle.c index 61ba7b8..160f219 100644 --- a/sw/board/gpiotoggle.c +++ b/sw/board/gpiotoggle.c @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: gpiotoggle.c -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: A touch of C code to see just how fast we can reasonably toggle @@ -11,9 +11,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2020-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -28,14 +28,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #include #ifdef GPIO_ACCESS diff --git a/sw/board/hello.c b/sw/board/hello.c index 5949b9c..61a89c3 100644 --- a/sw/board/hello.c +++ b/sw/board/hello.c @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: helloworld.c -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: The original Helllo World program. If everything works, this @@ -16,7 +16,7 @@ // //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #include int main(int argc, char **argv) { diff --git a/sw/board/sdtest.c b/sw/board/sdtest.c index cdf20bd..064d9df 100644 --- a/sw/board/sdtest.c +++ b/sw/board/sdtest.c @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: sdtest.c -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: This small program tests the SD card, proving whether it does @@ -11,9 +11,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -28,14 +28,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #include #include #include "board.h" diff --git a/sw/board/txfns.c b/sw/board/txfns.c index 96fa076..cd45f0a 100644 --- a/sw/board/txfns.c +++ b/sw/board/txfns.c @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: txfns.c -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: These are some *very* simple UART routines, designed to support @@ -14,9 +14,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -31,14 +31,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #include #include "board.h" #include "txfns.h" diff --git a/sw/board/txfns.h b/sw/board/txfns.h index 9462d79..324fddc 100644 --- a/sw/board/txfns.h +++ b/sw/board/txfns.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: txfns.h -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: These are some *very* simple UART routines, designed to support @@ -14,9 +14,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -31,14 +31,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #ifndef TXFNS_H #define TXFNS_H diff --git a/sw/host/byteswap.cpp b/sw/host/byteswap.cpp index 682bc77..7dd69e8 100644 --- a/sw/host/byteswap.cpp +++ b/sw/host/byteswap.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: byteswap.cpp -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: To convert between little endian and big endian byte orders, @@ -13,9 +13,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -30,14 +30,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #include #include "byteswap.h" diff --git a/sw/host/byteswap.h b/sw/host/byteswap.h index 0bcd651..fc768e2 100644 --- a/sw/host/byteswap.h +++ b/sw/host/byteswap.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: byteswap.h -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: To convert between little endian and big endian byte orders, @@ -13,9 +13,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -30,14 +30,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #ifndef BYTESWAP_H #define BYTESWAP_H diff --git a/sw/host/devbus.h b/sw/host/devbus.h index 7c5b178..0d7e737 100644 --- a/sw/host/devbus.h +++ b/sw/host/devbus.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: devbus.h -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: The purpose of this file is to document an interface which @@ -21,9 +21,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -38,14 +38,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #ifndef DEVBUS_H #define DEVBUS_H diff --git a/sw/host/dumpflash.cpp b/sw/host/dumpflash.cpp index 22c924e..90ed78f 100644 --- a/sw/host/dumpflash.cpp +++ b/sw/host/dumpflash.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: dumpflash.cpp -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: Read/Empty the entire contents of the flash memory to a file. @@ -11,9 +11,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -28,14 +28,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #include #include #include diff --git a/sw/host/flashdrvr.cpp b/sw/host/flashdrvr.cpp index e7ba362..dff3142 100644 --- a/sw/host/flashdrvr.cpp +++ b/sw/host/flashdrvr.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: flashdrvr.cpp -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: Flash driver. Encapsulates the erasing and programming (i.e. @@ -11,9 +11,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -28,14 +28,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #include #include #include diff --git a/sw/host/flashdrvr.h b/sw/host/flashdrvr.h index 346f6b8..0d12f69 100644 --- a/sw/host/flashdrvr.h +++ b/sw/host/flashdrvr.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: flashdrvr.h -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: Flash driver. Encapsulates writing, both erasing sectors and @@ -11,9 +11,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -28,15 +28,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// -// +// }}} #ifndef FLASHDRVR_H #define FLASHDRVR_H diff --git a/sw/host/llcomms.cpp b/sw/host/llcomms.cpp index 7dbbba4..7555292 100644 --- a/sw/host/llcomms.cpp +++ b/sw/host/llcomms.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: llcomms.cpp -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: This is the C++ program on the command side that will interact @@ -14,9 +14,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -31,14 +31,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #include #include #include diff --git a/sw/host/llcomms.h b/sw/host/llcomms.h index e01590f..1d53a49 100644 --- a/sw/host/llcomms.h +++ b/sw/host/llcomms.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: llcomms.h -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: This is the C++ program on the command side that will interact @@ -13,9 +13,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -30,14 +30,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #ifndef LLCOMMS_H #define LLCOMMS_H diff --git a/sw/host/netuart.cpp b/sw/host/netuart.cpp index b8e0f15..7b8a0ca 100644 --- a/sw/host/netuart.cpp +++ b/sw/host/netuart.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: netuart.cpp -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: @@ -10,9 +10,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -27,15 +27,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// - +// }}} #include #include #include diff --git a/sw/host/port.h b/sw/host/port.h index e5442d6..9bede2c 100644 --- a/sw/host/port.h +++ b/sw/host/port.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: port.h -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: Defines the communication parameters necessary for communicating @@ -14,9 +14,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -31,14 +31,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #ifndef PORT_H #define PORT_H @@ -47,7 +47,7 @@ // computer, test it, and when/if it doesn't work we can replace the device // with the test-bench. Across the network, no one will know any better that // anything had changed. -#define FPGAHOST "localhost" // A random hostname,back from the grave +#define FPGAHOST "localhost" #define FPGAPORT 8845 #define FPGAOPEN(V) V= new FPGA(new NETCOMMS(FPGAHOST, FPGAPORT)) diff --git a/sw/host/regdefs.cpp b/sw/host/regdefs.cpp index 517b702..aefe4e7 100644 --- a/sw/host/regdefs.cpp +++ b/sw/host/regdefs.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: ./regdefs.cpp -// +// {{{ // Project: ZBasic, a generic toplevel implementation using the full ZipCPU // // DO NOT EDIT THIS FILE! @@ -14,9 +14,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2017-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2017-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -31,14 +31,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #include #include #include @@ -76,7 +76,55 @@ const REGNAME raw_bregs[] = { { R_RTCDATE , "DATE" }, { R_VERSION , "VERSION" }, { R_BKRAM , "RAM" }, - { R_FLASH , "FLASH" } + { R_FLASH , "FLASH" }, + { R_ZIPCTRL , "CPU" }, + { R_ZIPCTRL , "ZIPCTRL" }, + { R_ZIPREGS , "ZIPREGS" }, + { R_ZIPS0 , "SR0" }, + { R_ZIPS1 , "SR1" }, + { R_ZIPS2 , "SR2" }, + { R_ZIPS3 , "SR3" }, + { R_ZIPS4 , "SR4" }, + { R_ZIPS5 , "SR5" }, + { R_ZIPS6 , "SR6" }, + { R_ZIPS7 , "SR7" }, + { R_ZIPS8 , "SR8" }, + { R_ZIPS9 , "SR9" }, + { R_ZIPS10 , "SR10" }, + { R_ZIPS11 , "SR11" }, + { R_ZIPS12 , "SR12" }, + { R_ZIPSSP , "SSP" }, + { R_ZIPSSP , "SR13" }, + { R_ZIPCC , "ZIPCC" }, + { R_ZIPCC , "CC" }, + { R_ZIPCC , "SCC" }, + { R_ZIPCC , "SR14" }, + { R_ZIPPC , "ZIPPC" }, + { R_ZIPPC , "PC" }, + { R_ZIPPC , "SPC" }, + { R_ZIPPC , "SR15" }, + { R_ZIPUSER , "ZIPUSER" }, + { R_ZIPU0 , "UR0" }, + { R_ZIPU1 , "UR1" }, + { R_ZIPU2 , "UR2" }, + { R_ZIPU3 , "UR3" }, + { R_ZIPU4 , "UR4" }, + { R_ZIPU5 , "UR5" }, + { R_ZIPU6 , "UR6" }, + { R_ZIPU7 , "UR7" }, + { R_ZIPU8 , "UR8" }, + { R_ZIPU9 , "UR9" }, + { R_ZIPU10 , "SR10" }, + { R_ZIPU11 , "SR11" }, + { R_ZIPU12 , "SR12" }, + { R_ZIPUSP , "USP" }, + { R_ZIPUSP , "UR13" }, + { R_ZIPUCC , "ZIPUCC" }, + { R_ZIPUCC , "UCC" }, + { R_ZIPUPC , "ZIPUPC" }, + { R_ZIPUPC , "UPC" }, + { R_ZIPSYSTEM , "ZIPSYSTEM" }, + { R_ZIPSYSTEM , "ZIPSYS" } }; // REGSDEFS.CPP.INSERT for any bus masters diff --git a/sw/host/regdefs.h b/sw/host/regdefs.h index d1a7ef2..99887e9 100644 --- a/sw/host/regdefs.h +++ b/sw/host/regdefs.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: ./regdefs.h -// +// {{{ // Project: ZBasic, a generic toplevel implementation using the full ZipCPU // // DO NOT EDIT THIS FILE! @@ -14,9 +14,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2017-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2017-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -31,14 +31,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #ifndef REGDEFS_H #define REGDEFS_H @@ -81,14 +81,49 @@ #define R_VERSION 0x00a00018 // 00a00018, wbregs names: VERSION #define R_BKRAM 0x00c00000 // 00c00000, wbregs names: RAM #define R_FLASH 0x01000000 // 01000000, wbregs names: FLASH +// ZipCPU control/debug registers +#define R_ZIPCTRL 0x02000080 // 02000000, wbregs names: CPU, ZIPCTRL +#define R_ZIPREGS 0x02000000 // 02000000, wbregs names: ZIPREGS +#define R_ZIPS0 0x02000000 // 02000000, wbregs names: SR0 +#define R_ZIPS1 0x02000004 // 02000000, wbregs names: SR1 +#define R_ZIPS2 0x02000008 // 02000000, wbregs names: SR2 +#define R_ZIPS3 0x0200000c // 02000000, wbregs names: SR3 +#define R_ZIPS4 0x02000010 // 02000000, wbregs names: SR4 +#define R_ZIPS5 0x02000014 // 02000000, wbregs names: SR5 +#define R_ZIPS6 0x02000018 // 02000000, wbregs names: SR6 +#define R_ZIPS7 0x0200001c // 02000000, wbregs names: SR7 +#define R_ZIPS8 0x02000020 // 02000000, wbregs names: SR8 +#define R_ZIPS9 0x02000024 // 02000000, wbregs names: SR9 +#define R_ZIPS10 0x02000028 // 02000000, wbregs names: SR10 +#define R_ZIPS11 0x0200002c // 02000000, wbregs names: SR11 +#define R_ZIPS12 0x02000030 // 02000000, wbregs names: SR12 +#define R_ZIPSSP 0x02000034 // 02000000, wbregs names: SSP, SR13 +#define R_ZIPCC 0x02000038 // 02000000, wbregs names: ZIPCC, CC, SCC, SR14 +#define R_ZIPPC 0x0200003c // 02000000, wbregs names: ZIPPC, PC, SPC, SR15 +#define R_ZIPUSER 0x02000040 // 02000000, wbregs names: ZIPUSER +#define R_ZIPU0 0x02000040 // 02000000, wbregs names: UR0 +#define R_ZIPU1 0x02000044 // 02000000, wbregs names: UR1 +#define R_ZIPU2 0x02000048 // 02000000, wbregs names: UR2 +#define R_ZIPU3 0x0200004c // 02000000, wbregs names: UR3 +#define R_ZIPU4 0x02000050 // 02000000, wbregs names: UR4 +#define R_ZIPU5 0x02000054 // 02000000, wbregs names: UR5 +#define R_ZIPU6 0x02000058 // 02000000, wbregs names: UR6 +#define R_ZIPU7 0x0200005c // 02000000, wbregs names: UR7 +#define R_ZIPU8 0x02000060 // 02000000, wbregs names: UR8 +#define R_ZIPU9 0x02000064 // 02000000, wbregs names: UR9 +#define R_ZIPU10 0x02000068 // 02000000, wbregs names: SR10 +#define R_ZIPU11 0x0200006c // 02000000, wbregs names: SR11 +#define R_ZIPU12 0x02000070 // 02000000, wbregs names: SR12 +#define R_ZIPUSP 0x02000074 // 02000000, wbregs names: USP, UR13 +#define R_ZIPUCC 0x02000078 // 02000000, wbregs names: ZIPUCC, UCC +#define R_ZIPUPC 0x0200007c // 02000000, wbregs names: ZIPUPC, UPC +#define R_ZIPSYSTEM 0x02000100 // 02000000, wbregs names: ZIPSYSTEM, ZIPSYS // // The @REGDEFS.H.DEFNS tag // // @REGDEFS.H.DEFNS for masters -#define R_ZIPCTRL 0x02000000 -#define R_ZIPDATA 0x02000004 #define BAUDRATE 1000000 #define CLKFREQHZ 100000000 // @REGDEFS.H.DEFNS for peripherals @@ -108,20 +143,6 @@ // // @REGDEFS.H.INSERT for masters // @REGDEFS.H.INSERT for peripherals -// Flash control constants -#define QSPI_FLASH // This core and hardware support a Quad SPI flash -#define SZPAGEB 256 -#define PGLENB 256 -#define SZPAGEW 64 -#define PGLENW 64 -#define NPAGES 256 -#define SECTORSZB (NPAGES * SZPAGEB) // In bytes, not words!! -#define SECTORSZW (NPAGES * SZPAGEW) // In words -#define NSECTORS 64 -#define SECTOROF(A) ((A) & (-1<<16)) -#define SUBSECTOROF(A) ((A) & (-1<<12)) -#define PAGEOF(A) ((A) & (-1<<8)) - #define CPU_GO 0x0000 #define CPU_RESET 0x0040 @@ -142,6 +163,20 @@ #define RESET_ADDRESS 0x01400000 +// Flash control constants +#define QSPI_FLASH // This core and hardware support a Quad SPI flash +#define SZPAGEB 256 +#define PGLENB 256 +#define SZPAGEW 64 +#define PGLENW 64 +#define NPAGES 256 +#define SECTORSZB (NPAGES * SZPAGEB) // In bytes, not words!! +#define SECTORSZW (NPAGES * SZPAGEW) // In words +#define NSECTORS 64 +#define SECTOROF(A) ((A) & (-1<<16)) +#define SUBSECTOROF(A) ((A) & (-1<<12)) +#define PAGEOF(A) ((A) & (-1<<8)) + // @REGDEFS.H.INSERT from the top level typedef struct { unsigned m_addr; diff --git a/sw/host/ttybus.cpp b/sw/host/ttybus.cpp index e1fcb3d..d19ccee 100644 --- a/sw/host/ttybus.cpp +++ b/sw/host/ttybus.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: ttybus.cpp -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: This is the C++ program on the command side that will interact @@ -15,9 +15,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -32,14 +32,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #include #include #include diff --git a/sw/host/ttybus.h b/sw/host/ttybus.h index 5e7b349..fe8e09b 100644 --- a/sw/host/ttybus.h +++ b/sw/host/ttybus.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: ttybus.h -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: This is the C++ program on the command side that will interact @@ -21,9 +21,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -38,15 +38,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// -// +// }}} #ifndef TTYBUS_H #define TTYBUS_H diff --git a/sw/host/twoc.cpp b/sw/host/twoc.cpp index 0676f1d..ee06a23 100644 --- a/sw/host/twoc.cpp +++ b/sw/host/twoc.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: twoc.cpp -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: Some various two's complement related C++ helper routines. @@ -13,9 +13,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -30,14 +30,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #include "twoc.h" long sbits(const long val, const int bits) { diff --git a/sw/host/twoc.h b/sw/host/twoc.h index a04953c..765e727 100644 --- a/sw/host/twoc.h +++ b/sw/host/twoc.h @@ -1,21 +1,21 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: twoc.h -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: Some various two's complement related C++ helper routines. // Specifically, these help extract signed numbers from -// packed bitfields, while guaranteeing that the upper bits -// are properly sign extended (or not) as desired. +// packed bitfields, while guaranteeing that the upper bits are properly +// sign extended (or not) as desired. // // Creator: Dan Gisselquist, Ph.D. // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -30,14 +30,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #ifndef TWOC_H #define TWOC_H diff --git a/sw/host/wbregs.cpp b/sw/host/wbregs.cpp index 9d925ee..3749ffd 100644 --- a/sw/host/wbregs.cpp +++ b/sw/host/wbregs.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: wbregs.cpp -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: To give a user access, via a command line program, to read @@ -13,9 +13,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -30,14 +30,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #include #include #include diff --git a/sw/host/zipdbg.cpp b/sw/host/zipdbg.cpp index be04376..6aa619f 100644 --- a/sw/host/zipdbg.cpp +++ b/sw/host/zipdbg.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: zipdbg.cpp -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: Provide a debugger to step through the ZipCPU assembler, @@ -13,9 +13,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -30,14 +30,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} // BUGS: // - No ability to verify CPU functionality (3rd party simulator) // - No ability to set/clear breakpoints @@ -108,12 +108,9 @@ class ZIPPY : public DEVBUS { void read_raw_state(void) { m_state.m_valid = false; - for(int i=0; i<16; i++) - m_state.m_sR[i] = cmd_read(i); - for(int i=0; i<16; i++) - m_state.m_uR[i] = cmd_read(i+16); - for(int i=0; i<20; i++) - m_state.m_p[i] = cmd_read(i+32); + readi(R_ZIPREGS, 16, m_state.m_sR); + readi(R_ZIPUSER, 16, m_state.m_uR); + readi(R_ZIPSYSTEM, 20, m_state.m_p); m_state.m_gie = (m_state.m_sR[14] & 0x020); m_state.m_pc = (m_state.m_gie) ? (m_state.m_uR[15]):(m_state.m_sR[15]); @@ -264,6 +261,7 @@ class ZIPPY : public DEVBUS { } unsigned int cmd_read(unsigned int a) { + /* int errcount = 0; unsigned int s; @@ -289,9 +287,13 @@ class ZIPPY : public DEVBUS { exit(EXIT_FAILURE); } return readio(R_ZIPDATA); + */ + + return readio(R_ZIPREGS + (4*a)); } void cmd_write(unsigned int a, int v) { + /* int errcount = 0; unsigned int s; @@ -318,6 +320,9 @@ class ZIPPY : public DEVBUS { } writeio(R_ZIPDATA, (unsigned int)v); + */ + + writeio(R_ZIPREGS+(4*a), (unsigned int)v); } void read_state(void) { diff --git a/sw/host/zipelf.cpp b/sw/host/zipelf.cpp index e693b74..6f35126 100644 --- a/sw/host/zipelf.cpp +++ b/sw/host/zipelf.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: zipelf.cpp -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: @@ -11,9 +11,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -28,14 +28,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #include #include diff --git a/sw/host/zipelf.h b/sw/host/zipelf.h index c4f15ba..bc3d0a2 100644 --- a/sw/host/zipelf.h +++ b/sw/host/zipelf.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: zipelf.h -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: @@ -11,9 +11,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -28,14 +28,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #ifndef ZIPELF_H #define ZIPELF_H diff --git a/sw/host/zipload.cpp b/sw/host/zipload.cpp index 071c91e..d53bdd2 100644 --- a/sw/host/zipload.cpp +++ b/sw/host/zipload.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: zipload.cpp -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: To load a program for the ZipCPU into memory, whether flash @@ -13,9 +13,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -30,14 +30,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #include #include #include @@ -336,23 +336,25 @@ int main(int argc, char **argv) { // Now ... how shall we start this CPU? printf("Clearing the CPUs registers\n"); - for(int i=0; i<32; i++) { - m_fpga->writeio(R_ZIPCTRL, CPU_HALT|i); - m_fpga->writeio(R_ZIPDATA, 0); + { + unsigned r[32]; + m_fpga->writeio(R_ZIPCTRL, CPU_HALT); + for(int i=0; i<32; i++) + r[i] = 0; + m_fpga->writei(R_ZIPREGS, 32, r); } m_fpga->writeio(R_ZIPCTRL, CPU_HALT|CPU_CLRCACHE); printf("Setting PC to %08x\n", entry); - m_fpga->writeio(R_ZIPCTRL, CPU_HALT|CPU_sPC); - m_fpga->writeio(R_ZIPDATA, entry); + m_fpga->writeio(R_ZIPPC, entry); if (start_when_finished) { printf("Starting the CPU\n"); - m_fpga->writeio(R_ZIPCTRL, CPU_GO|CPU_sPC); + m_fpga->writeio(R_ZIPCTRL, CPU_GO); } else { printf("The CPU should be fully loaded, you may now\n"); printf("start it (from reset/reboot) with:\n"); - printf("> wbregs cpu 0x0f\n"); + printf("> wbregs cpu 0\n"); printf("\n"); } } catch(BUSERR a) { diff --git a/sw/host/zipstate.cpp b/sw/host/zipstate.cpp index 555acff..b01f6bc 100644 --- a/sw/host/zipstate.cpp +++ b/sw/host/zipstate.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: zipstate.cpp -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: To get a quick (understandable) peek at what the ZipCPU @@ -14,9 +14,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -31,14 +31,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #include #include #include @@ -59,28 +59,18 @@ void closeup(int v) { exit(0); } +/* unsigned int cmd_read(FPGA *fpga, int r) { const unsigned int MAXERR = 1000; unsigned int errcount = 0; unsigned int s; - fpga->writeio(R_ZIPCTRL, CPU_HALT|(r&0x03f)); - while((((s = fpga->readio(R_ZIPCTRL))&CPU_STALL)== 0)&&(errcount= MAXERR) { - printf("ERR: errcount(%d) >= MAXERR on cmd_read(a=%02x)\n", - errcount, r); - printf("ZIPCTRL = 0x%08x", s); - if ((s & 0x0200)==0) printf(" BUSY"); - if (s & 0x0400) printf(" HALTED"); - if ((s & 0x03000)==0x01000) - printf(" SW-HALT"); - else { - if (s & 0x01000) printf(" SLEEPING"); - if (s & 0x02000) printf(" GIE(UsrMode)"); - } printf("\n"); - exit(EXIT_FAILURE); - } return fpga->readio(R_ZIPDATA); + return fpga->readio(R_ZIPCTRL, CPU_REGBASE + (r*4)); +} +*/ + +void read_regs(FPGA *fpga, unsigned *r) { + fpga->readi(R_ZIPREGS, 32, r); } void usage(void) { @@ -108,34 +98,40 @@ int main(int argc, char **argv) { v = m_fpga->readio(R_ZIPCTRL); printf("0x%08x: ", v); + if (v & 0x0040) printf("RESET "); if (v & 0x0080) printf("PINT "); // if (v & 0x0100) printf("STEP "); // self resetting - if((v & 0x00200)==0) printf("BUSY "); - if (v & 0x00400) printf("HALTED "); + if((v & 0x00200)==0) printf("HALTED "); + if (v & 0x00400) printf("HALT_REQ "); + // if (v & 0x0800) printf("CLR-CACHE "); if((v & 0x03000)==0x01000) { printf("SW-HALT"); } else { if (v & 0x01000) printf("SLEEPING "); if (v & 0x02000) printf("GIE(UsrMode) "); } - // if (v & 0x0800) printf("CLR-CACHE "); + if (v & 0x04000) printf("sBusErr "); + if (v & 0x08000) printf("BREAK-HALT"); printf("\n"); } else { - printf("Reading the long-state ...\n"); + unsigned r[32]; + + printf("Reading the long-state ...\n"); fflush(stdout); + read_regs(m_fpga, r); for(int i=0; i<14; i++) { - printf("sR%-2d: 0x%08x ", i, cmd_read(m_fpga, i)); + printf("sR%-2d: 0x%08x ", i, r[i]); if ((i&3)==3) printf("\n"); - } printf("sCC : 0x%08x ", cmd_read(m_fpga, 14)); - printf("sPC : 0x%08x ", cmd_read(m_fpga, 15)); + } printf("sCC : 0x%08x ", r[14]); + printf("sPC : 0x%08x ", r[15]); printf("\n\n"); for(int i=0; i<14; i++) { - printf("uR%-2d: 0x%08x ", i, cmd_read(m_fpga, i+16)); + printf("uR%-2d: 0x%08x ", i, r[i+16]); if ((i&3)==3) printf("\n"); - } printf("uCC : 0x%08x ", cmd_read(m_fpga, 14+16)); - printf("uPC : 0x%08x ", cmd_read(m_fpga, 15+16)); + } printf("uCC : 0x%08x ", r[14]); + printf("uPC : 0x%08x ", r[15]); printf("\n\n"); } diff --git a/sw/host/zopcodes.cpp b/sw/host/zopcodes.cpp index 9364d43..5c98663 100644 --- a/sw/host/zopcodes.cpp +++ b/sw/host/zopcodes.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: zopcodes.cpp -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: A simple program to handle the disassembly and definition @@ -15,9 +15,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -32,14 +32,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #include #include #include @@ -532,13 +532,14 @@ zipi_to_halfstring(const uint32_t addr, const ZIPI ins, char *line, const ZOPCOD int dv = zip_getbits(ins, ZIP_REGFIELD(27)); int iv = zip_sbits(ins, 13); uint32_t ref; + char opcode[128]; ref = (iv<<2) + addr + 4; - sprintf(line, "%s%s", "MOV", zip_ccstr[cv]); - sprintf(line, "%-11s", line); - sprintf(line, "%s0x%08x", line, ref); - sprintf(line, "%s,%s", line, zip_regstr[dv]); + sprintf(opcode, "%s%s", "MOV", zip_ccstr[cv]); + sprintf(line, "%-11s", opcode); + sprintf(opcode, "%s0x%08x", line, ref); + sprintf(line, "%s,%s", opcode, zip_regstr[dv]); return; } else if (TWOWORD_CIS_JSR(ins)) { @@ -569,11 +570,12 @@ zipi_to_halfstring(const uint32_t addr, const ZIPI ins, char *line, const ZOPCOD // zip_oplist[i].s_mask, zip_oplist[i].s_val); if ((ins & listp[i].s_mask) == listp[i].s_val) { // Write the opcode onto our line - sprintf(line, "%s", listp[i].s_opstr); + char opcode[128]; + sprintf(opcode, "%s", listp[i].s_opstr); if (listp[i].s_cf != ZIP_OPUNUSED) { int bv = zip_getbits(ins, listp[i].s_cf); - strcat(line, zip_ccstr[bv]); - } sprintf(line, "%-11s", line); // Pad it to 11 chars + strcat(opcode, zip_ccstr[bv]); + } sprintf(line, "%-11s", opcode); // Pad it to 11 chars int ra = -1, rb = -1, rr = -1, imv = 0; diff --git a/sw/host/zopcodes.h b/sw/host/zopcodes.h index 386ddb0..7dd323d 100644 --- a/sw/host/zopcodes.h +++ b/sw/host/zopcodes.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: zopcodes.h -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: A structure defined to keep track of our various opcodes and @@ -11,9 +11,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -28,14 +28,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #ifndef ZOPCODES_H #define ZOPCODES_H diff --git a/sw/zlib/Makefile b/sw/zlib/Makefile index c30d10c..f6bc4ec 100644 --- a/sw/zlib/Makefile +++ b/sw/zlib/Makefile @@ -1,7 +1,7 @@ ################################################################################ ## ## Filename: Makefile -## +## {{{ ## Project: ZBasic, a generic toplevel impl using the full ZipCPU ## ## Purpose: To guide/direct the build of the board-specific portion of @@ -13,9 +13,9 @@ ## Gisselquist Technology, LLC ## ################################################################################ -## -## Copyright (C) 2017-2020, Gisselquist Technology, LLC -## +## }}} +## Copyright (C) 2017-2021, Gisselquist Technology, LLC +## {{{ ## This program is free software (firmware): 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 @@ -30,14 +30,14 @@ ## with this program. (It's in the $(ROOT)/doc directory. Run make with no ## target there if the PDF file isn't present.) If not, see ## for a copy. -## +## }}} ## License: GPL, v3, as defined and found on www.gnu.org, +## {{{ ## http://www.gnu.org/licenses/gpl.html ## -## ################################################################################ ## -## +## }}} CC := zip-gcc AR := zip-ar OBJDIR := obj-zip diff --git a/sw/zlib/board.h b/sw/zlib/board.h index d243a35..b149865 100644 --- a/sw/zlib/board.h +++ b/sw/zlib/board.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: ./board.h -// +// {{{ // Project: ZBasic, a generic toplevel implementation using the full ZipCPU // // DO NOT EDIT THIS FILE! @@ -14,9 +14,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2017-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2017-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -31,14 +31,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #ifndef BOARD_H #define BOARD_H @@ -62,45 +62,9 @@ #endif // INCLUDE_ZIPCPU -typedef struct CONSOLE_S { - unsigned u_setup; - unsigned u_fifo; - unsigned u_rx, u_tx; -} CONSOLE; - -#define _uart_txbusy ((_uart->u_fifo & 0x10000)==0) - - -// -// GPIO input wires -// -#define GPIO_IN(WIRE) (((WIRE)>>16)&1) -// -// GPIO output wires -// -#define GPIO_SET(WIRE) (((WIRE)<<16)|(WIRE)) -#define GPIO_CLR(WIRE) ((WIRE)<<16) -// -// - - -#define BUSPIC(X) (1<u_fifo & 0x10000)==0) + + +#define BUSPIC(X) (1<>16)&1) +// +// GPIO output wires +// +#define GPIO_SET(WIRE) (((WIRE)<<16)|(WIRE)) +#define GPIO_CLR(WIRE) ((WIRE)<<16) +// +// + + +#define _BOARD_HAS_BUILDTIME +static volatile unsigned *const _buildtime = ((unsigned *)0x00a00000); +#ifdef BKRAM_ACCESS +#define _BOARD_HAS_BKRAM +extern char _bkram[0x00100000]; +#endif // BKRAM_ACCESS #ifdef VERSION_ACCESS #define _BOARD_HAS_VERSION static volatile unsigned *const _version = ((unsigned *)0x00a00018); #endif // VERSION_ACCESS -#ifdef FLASHCFG_ACCESS -#define _BOARD_HAS_FLASHCFG -static volatile unsigned * const _flashcfg = ((unsigned *)(0x00200000)); -#endif // FLASHCFG_ACCESS -#ifdef BUSPIC_ACCESS -#define _BOARD_HAS_BUSPIC -static volatile unsigned *const _buspic = ((unsigned *)0x00a00008); -#endif // BUSPIC_ACCESS +#ifdef SDSPI_ACCESS +#define _BOARD_HAS_SDSPI +static volatile SDSPI *const _sdcard = ((SDSPI *)0x00400000); +#endif // SDSPI_ACCESS #ifdef RTC_ACCESS #define _BOARD_HAS_RTC static volatile RTCLIGHT *const _rtc = ((RTCLIGHT *)0x00800000); #endif // RTC_ACCESS -#ifdef BKRAM_ACCESS -#define _BOARD_HAS_BKRAM -extern char _bkram[0x00100000]; -#endif // BKRAM_ACCESS -#ifdef FLASH_ACCESS -#define _BOARD_HAS_FLASH -extern int _flash[1]; -#endif // FLASH_ACCESS -#define _BOARD_HAS_BUILDTIME -static volatile unsigned *const _buildtime = ((unsigned *)0x00a00000); +#ifdef BUSCONSOLE_ACCESS +#define _BOARD_HAS_BUSCONSOLE +static volatile CONSOLE *const _uart = ((CONSOLE *)0x00600000); +#endif // BUSCONSOLE_ACCESS +#ifdef BUSPIC_ACCESS +#define _BOARD_HAS_BUSPIC +static volatile unsigned *const _buspic = ((unsigned *)0x00a00008); +#endif // BUSPIC_ACCESS #define _BOARD_HAS_BUSERR static volatile unsigned *const _buserr = ((unsigned *)0x00a00004); #ifdef PWRCOUNT_ACCESS @@ -169,16 +161,21 @@ static volatile unsigned *const _pwrcount = ((unsigned *)0x00a00010); #define _BOARD_HAS_RTCDATE static volatile unsigned *const _rtcdate = ((unsigned *)10485780); #endif // RTCDATE_ACCESS -#ifdef SDSPI_ACCESS -#define _BOARD_HAS_SDSPI -static volatile SDSPI *const _sdcard = ((SDSPI *)0x00400000); -#endif // SDSPI_ACCESS +#ifdef GPIO_ACCESS +#define _BOARD_HAS_GPIO +static volatile unsigned *const _gpio = ((unsigned *)0x00a0000c); +#endif // GPIO_ACCESS +#ifdef FLASHCFG_ACCESS +#define _BOARD_HAS_FLASHCFG +static volatile unsigned * const _flashcfg = ((unsigned *)(0x00200000)); +#endif // FLASHCFG_ACCESS +#ifdef FLASH_ACCESS +#define _BOARD_HAS_FLASH +extern int _flash[1]; +#endif // FLASH_ACCESS // // Interrupt assignments (3 PICs) // -// PIC: buspic -#define BUSPIC_GPIO BUSPIC(0) -#define BUSPIC_SDCARD BUSPIC(1) // PIC: syspic #define SYSPIC_DMAC SYSPIC(0) #define SYSPIC_JIFFIES SYSPIC(1) @@ -187,9 +184,9 @@ static volatile SDSPI *const _sdcard = ((SDSPI *)0x00400000); #define SYSPIC_TMA SYSPIC(4) #define SYSPIC_ALT SYSPIC(5) #define SYSPIC_BUS SYSPIC(6) -#define SYSPIC_UARTTXF SYSPIC(7) +#define SYSPIC_SDCARD SYSPIC(7) #define SYSPIC_UARTRXF SYSPIC(8) -#define SYSPIC_SDCARD SYSPIC(9) +#define SYSPIC_UARTTXF SYSPIC(9) // PIC: altpic #define ALTPIC_UIC ALTPIC(0) #define ALTPIC_UOC ALTPIC(1) @@ -199,7 +196,10 @@ static volatile SDSPI *const _sdcard = ((SDSPI *)0x00400000); #define ALTPIC_MOC ALTPIC(5) #define ALTPIC_MPC ALTPIC(6) #define ALTPIC_MTC ALTPIC(7) -#define ALTPIC_UARTTX ALTPIC(8) -#define ALTPIC_UARTRX ALTPIC(9) -#define ALTPIC_RTC ALTPIC(10) +#define ALTPIC_RTC ALTPIC(8) +#define ALTPIC_UARTTX ALTPIC(9) +#define ALTPIC_UARTRX ALTPIC(10) +// PIC: buspic +#define BUSPIC_SDCARD BUSPIC(0) +#define BUSPIC_GPIO BUSPIC(1) #endif // BOARD_H diff --git a/sw/zlib/bootloader.h b/sw/zlib/bootloader.h index 5224423..7d7e7f5 100644 --- a/sw/zlib/bootloader.h +++ b/sw/zlib/bootloader.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: bootloader.h -// +// {{{ // Project: Zip CPU -- a small, lightweight, RISC CPU soft core // // Purpose: @@ -11,9 +11,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -28,14 +28,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #ifndef BOOTLOADER_H #define BOOTLOADER_H diff --git a/sw/zlib/crt0.c b/sw/zlib/crt0.c index a482f75..9b15443 100644 --- a/sw/zlib/crt0.c +++ b/sw/zlib/crt0.c @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: crt0.c -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: To start a program from flash, loading its various components @@ -90,9 +90,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2017-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2017-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -102,19 +102,21 @@ // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #include "zipcpu.h" #include "board.h" // Our current board support file #include "bootloader.h" #include "zipsys.h" +// USE_DMA +// {{{ // A bootloader is about nothing more than copying memory from a couple // particular locations (Flash/ROM) to other locations in memory (BLKRAM // and SDRAM). Our DMA is a hardware accelerator that does nothing but @@ -127,13 +129,16 @@ // however: 1) It obscures for any readers of this code what is actually // happening, and 2) it makes the code dependent upon yet another piece of the // hardware design working. For these reasons, we allow you to turn it off. +// }}} #ifdef _HAVE_ZIPSYS_DMA #define USE_DMA #endif // -// _start: -// +// _start: (Assembly routine) +// {{{ +// Notes: +// {{{ // Every computer needs to start processing from somewhere on reboot, and every // program needs some entry point. For the ZipCPU, that starting place is the // routine with the _start symbol. It is important that this start symbol be @@ -151,7 +156,7 @@ // the kernel entry function. It also sets up a return address for the kernel // entry function so that, should the kernel ever exit, it wouldn't exit on // any error but rather it would exit by halting the CPU. -// +// }}} asm("\t.section\t.start,\"ax\",@progbits\n" "\t.global\t_start\n" "_start:" "\t; Here's the global ZipCPU entry point upon reset/reboot\n" @@ -187,19 +192,21 @@ asm("\t.section\t.start,\"ax\",@progbits\n" "_argv:\n" "\t.WORD\t0,0\n" "\t.section\t.text"); +// }}} -// +// extern _bootloader +// {{{ // We need to insist that the bootloader be kept in Flash, else it would depend // upon running a routine from memory that ... wasn't in memory yet. For this // purpose, we place the bootloader in a special .boot section. We'll also tell // the linker, via the linker script, that this .boot section needs to be placed // into flash. -// +// }}} extern void _bootloader(void) __attribute__ ((section (".boot"))); // // bootloader() -// +// {{{ // Here's the actual boot loader itself. It copies three areas from flash: // 1. An area from flash to block RAM // 2. A second area from flash to SDRAM @@ -207,12 +214,31 @@ extern void _bootloader(void) __attribute__ ((section (".boot"))); // zero. This is sometimes called the BSS segment. // #ifndef SKIP_BOOTLOADER +// NOTNULL(A) +// {{{ +// Several comparisons below look like: if (_ram != NULL) or even +// if (_ram == NULL). The problem is that, in order to optimize linking, we've +// defined _ram as something like: unsigned _ram[1]; This means that GCC +// believes space is actually allocated for _ram somewhere (by the linker), but +// just doesn't know where. Hence, GCC will optimize these comparisons away, +// since it knows they cannot be NULL. The macro below helps to return the +// comparison back to what it should be--getting GCC out of the way in the +// process. It's an ugly hack, but it works. #define NOTNULL(A) (4 != (unsigned)&A[1]) +// }}} void _bootloader(void) { // NSTR("BOOTLOADER"); int *ramend = _ram_image_end, *bsend = _bss_image_end; if (!NOTNULL(_rom)) { + // No ROM present + // {{{ + // In this case, we have the least to do: an external loader + // has already been responsible for loading us into memory. + // All that's then required is simply to zero out the BSS + // segment and start. This can be done either with (or without) + // the DMA. If you want to understand how this routine + // works, check out the non-DMA section #ifdef USE_DMA // NSTR("No-ROM"); // @@ -234,22 +260,31 @@ void _bootloader(void) { while((_zip->z_pic & SYSINT_DMAC)==0) ; } CLEAR_CACHE; -#else +#else // USE_DMA int *wrp = _ram_image_end; while(wrp < _bss_image_end) *wrp++ = 0; +#endif // USE_DMA return; -#endif - return; + // }}} } int *kramdev = (_kram) ? _kram : _ram; + // Okay, we have ROM present. We need to copy our instructions and + // data from the ROM to a designated RAM area. Indeed, we allow two + // designated RAM areas: kernel (fast) and normal RAM. Once done, + // we zero out the BSS segment. This can be done with or without the + // DMA #ifdef USE_DMA + // {{{ // Disable and clear all interrupts _zip->z_pic = CLEARPIC; // NSTR("DMA"); _zip->z_dma.d_ctrl= DMACLEAR; + + // Copy to Kernel RAM + // {{{ if (NOTNULL(_kram)) { _zip->z_dma.d_rd = _kram_start; // Flash memory ptr _zip->z_dma.d_wr = (_kram) ? _kram : _ram; @@ -263,18 +298,17 @@ void _bootloader(void) { while((_zip->z_pic & SYSINT_DMAC)==0) ; } - - // Writing to kram, need to switch to RAM - _zip->z_dma.d_wr = _ram; - _zip->z_dma.d_len = ramend - _ram; } else { // NSTR("No-KRAM"); // Continue writing to the RAM device from where we left off - _zip->z_dma.d_len = ramend - _ram; _zip->z_dma.d_rd = _ram_image_start; // ROM (flash) memory - _zip->z_dma.d_wr = _ram; } + // }}} + // Copy to external or regular RAM + // {{{ + _zip->z_dma.d_wr = _ram; + _zip->z_dma.d_len = ramend - _ram; if (_zip->z_dma.d_len>0) { // NSTR("RAM"); _zip->z_pic = SYSINT_DMAC; @@ -283,7 +317,10 @@ void _bootloader(void) { while((_zip->z_pic & SYSINT_DMAC)==0) ; } + // }}} + // Zero out the BSS segment + // {{{ if (bsend != ramend) { volatile int zero = 0; @@ -297,31 +334,44 @@ void _bootloader(void) { while((_zip->z_pic & SYSINT_DMAC)==0) ; } + // }}} CLEAR_CACHE; // Disable and clear all interrupts _zip->z_pic = CLEARPIC; + // }}} #else - int *rdp = _kram_start, *wrp = (_kram) ? _kram : _ram; + // {{{ + int *rdp = _kram_start, *wrp; // NSTR("Not using DMA"); + // Copy to Kernel RAM + // {{{ + if (NOTNULL(_kram)) + wrp = _kram; + else + wrp = _ram; + // Load any part of the image into kernel RAM (i.e. fast or block RAM), + // but *only* if there's a block RAM section in the image. Based upon + // our LD script, the block RAM should be filled from _blkram to + // _kernel_image_end. It starts at _kram_start --- our last valid + // address within the flash address region. // - // Load any part of the image into block RAM, but *only* if there's a - // block RAM section in the image. Based upon our LD script, the - // block RAM should be filled from _blkram to _kernel_image_end. - // It starts at _kram_start --- our last valid address within - // the flash address region. - // - if (_kram_end != _kram_start) { + if (_kram_end != _kram_start) { // The memory copy // NSTR("KRAM"); while(wrp < _kram_end) *wrp++ = *rdp++; } + // }}} + // If there's a separate RAM section, then we'll switch to writing into + // it next. If not, we'll continue writing from where we left off in + // kernel RAM. if (NOTNULL(_ram)) wrp = _ram; - // + // Copy to external or regular RAM + // {{{ // Now, we move on to the SDRAM image. We'll here load into SDRAM // memory up to the end of the SDRAM image, _sdram_image_end. // As with the last pointer, this one is also created for us by the @@ -331,8 +381,10 @@ void _bootloader(void) { // NSTR("RAM"); for(int i=0; i< ramend - _ram; i++) *wrp++ = *rdp++; + // }}} - // + // Zero out the BSS segment + // {{{ // Finally, we load BSS. This is the segment that only needs to be // cleared to zero. It is available for global variables, but some // initialization is expected within it. We start writing where @@ -341,9 +393,11 @@ void _bootloader(void) { // NSTR("BSS"); for(int i=0; i #include #include diff --git a/sw/zlib/udiv.c b/sw/zlib/udiv.c index f158358..aceef46 100644 --- a/sw/zlib/udiv.c +++ b/sw/zlib/udiv.c @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: udiv.c -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: This is a temporary file--a crutch if you will--until a similar @@ -13,9 +13,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -30,21 +30,24 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #include - +// Bit reversal +// {{{ #ifdef __ZIPCPU__ #include "zipcpu.h" #else +// This is a compatibility function, in case we are ever running ZipCPU +// programs on a non-ZipCPU platform uint32_t zip_bitrev(const uint32_t a) { uint32_t r, b = a; r = 0; @@ -54,7 +57,10 @@ uint32_t zip_bitrev(const uint32_t a) { } return r; } #endif +// }}} +// cltz: Count leading zeros +// {{{ extern int cltz(unsigned long); #ifdef __ZIPCPU__ @@ -120,7 +126,10 @@ cltz(unsigned long v) { return cnt; } #endif +// }}} +// __udivdi3 +// {{{ unsigned long __udivdi3(unsigned long a, unsigned long b) { unsigned long r; @@ -168,8 +177,10 @@ __udivdi3(unsigned long a, unsigned long b) { } return r; } } +// }}} -// +// __divdi3 +// {{{ // A possible assembly version of __divdi3 // // SUB 8,SP @@ -225,3 +236,4 @@ long __divdi3(long a, long b) { r = -r; return r; } +// }}} diff --git a/sw/zlib/umod.c b/sw/zlib/umod.c index 0f20790..386dda8 100644 --- a/sw/zlib/umod.c +++ b/sw/zlib/umod.c @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: umod.c -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: This is a temporary file--a crutch if you will--until a similar @@ -19,9 +19,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2017-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2017-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -36,14 +36,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #include diff --git a/sw/zlib/zipcpu.h b/sw/zlib/zipcpu.h index 592c066..9529cf5 100644 --- a/sw/zlib/zipcpu.h +++ b/sw/zlib/zipcpu.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: zipsys.h -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: Declare the capabilities and memory structure of the ZipSystem @@ -11,9 +11,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -28,14 +28,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #ifndef ZIPCPU_H #define ZIPCPU_H @@ -72,8 +72,8 @@ extern void zip_rtu(void); extern void zip_halt(void); extern void zip_idle(void); extern void zip_syscall(void); -extern void zip_restore_context(int *); -extern void zip_save_context(int *); +extern void zip_restore_context(void *); +extern void zip_save_context(void *); extern int zip_bitrev(int v); extern unsigned zip_cc(void); extern unsigned zip_ucc(void); diff --git a/sw/zlib/zipsys.h b/sw/zlib/zipsys.h index 6bb2d8b..27d5957 100644 --- a/sw/zlib/zipsys.h +++ b/sw/zlib/zipsys.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: zipsys.h -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: Declare the capabilities and memory structure of the ZipSystem @@ -11,9 +11,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -28,14 +28,14 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} #ifndef ZIPSYS_H #define ZIPSYS_H From 6b50f3c42b204fdd330e46a52050b2b4e82b1ba5 Mon Sep 17 00:00:00 2001 From: ZipCPU Date: Tue, 14 Sep 2021 13:54:34 -0400 Subject: [PATCH 02/11] CPU updated to ZipCore, CPUTest passes --- Makefile | 18 +- auto-data/Makefile | 16 +- auto-data/bkram.txt | 2 +- auto-data/busconsole.txt | 3 +- auto-data/buserr.txt | 2 +- auto-data/clock.txt | 2 +- auto-data/flash.txt | 2 +- auto-data/global.txt | 2 +- auto-data/gpio.txt | 2 +- auto-data/legalgen.txt | 2 +- auto-data/mem_bkram_only.txt | 2 +- auto-data/mem_flash_bkram.txt | 2 +- auto-data/pic.txt | 2 +- auto-data/pwrcount.txt | 2 +- auto-data/rtcdate.txt | 2 +- auto-data/rtclight.txt | 2 +- auto-data/sdspi.txt | 2 +- auto-data/simtrace.txt | 2 +- auto-data/version.txt | 2 +- auto-data/wbuart.txt | 2 +- auto-data/zipmaster.txt | 67 ++-- doc/Makefile | 16 +- doc/src/gqtekspec.cls | 2 +- mkdatev.pl | 4 +- rtl/Makefile | 4 +- rtl/addrdecode.v | 229 +++++++----- rtl/builddate.v | 4 +- rtl/cpu/axidcache.v | 340 +++++++++++++----- rtl/cpu/axiicache.v | 27 +- rtl/cpu/axilfetch.v | 294 ++++++++++------ rtl/cpu/axilops.v | 143 ++++++-- rtl/cpu/axilperiphs.v | 331 ++++++++++++++--- rtl/cpu/axilpipe.v | 123 +++++-- rtl/cpu/axiops.v | 153 +++++--- rtl/cpu/axipipe.v | 76 +++- rtl/cpu/busdelay.v | 2 +- rtl/cpu/cpudefs.v | 2 +- rtl/cpu/cpuops.v | 2 +- rtl/cpu/dblfetch.v | 2 +- rtl/cpu/dcache.v | 4 +- rtl/cpu/div.v | 11 +- rtl/cpu/icontrol.v | 2 +- rtl/cpu/idecode.v | 5 +- rtl/cpu/iscachable.v | 16 +- rtl/cpu/memops.v | 2 +- rtl/cpu/mpyop.v | 2 +- rtl/cpu/pfcache.v | 6 +- rtl/cpu/pipemem.v | 2 +- rtl/cpu/prefetch.v | 2 +- rtl/cpu/sfifo.v | 58 ++- rtl/cpu/slowmpy.v | 18 +- rtl/cpu/wbarbiter.v | 2 +- rtl/cpu/wbdblpriarb.v | 2 +- rtl/cpu/wbdmac.v | 2 +- rtl/cpu/wbwatchdog.v | 2 +- rtl/cpu/zipaxi.v | 168 ++++++--- rtl/cpu/zipaxil.v | 192 ++++++---- rtl/cpu/zipbones.v | 105 ++++-- rtl/cpu/zipcore.v | 279 ++++++++++++--- rtl/cpu/zipcounter.v | 2 +- rtl/cpu/zipjiffies.v | 2 +- rtl/cpu/zipsystem.v | 229 ++++++++---- rtl/cpu/ziptimer.v | 2 +- rtl/cpu/zipwb.v | 11 +- rtl/main.v | 14 +- rtl/make.inc | 2 +- rtl/memdev.v | 98 ++++-- rtl/qflexpress.v | 14 +- rtl/rtc/rtcalarm.v | 2 +- rtl/rtc/rtcbare.v | 2 +- rtl/rtc/rtcdate.v | 2 +- rtl/rtc/rtclight.v | 2 +- rtl/rtc/rtcstopwatch.v | 2 +- rtl/rtc/rtctimer.v | 2 +- rtl/sdspi/llsdspi.v | 186 ++++++---- rtl/sdspi/sdspi.v | 95 ++++- rtl/sdspi/spicmd.v | 106 ++++-- rtl/sdspi/spirxdata.v | 160 ++++++--- rtl/sdspi/spitxdata.v | 165 ++++++--- rtl/skidbuffer.v | 41 ++- rtl/toplevel.v | 4 +- rtl/wbgpio.v | 78 +++-- rtl/wbscope/wbscopc.v | 604 ++++++++++++++++++++------------ rtl/wbscope/wbscope.v | 348 +++++++++++------- rtl/wbuart/rxuartlite.v | 155 +++++--- rtl/wbuart/txuartlite.v | 123 ++++--- rtl/wbuart/ufifo.v | 135 +++++-- rtl/wbuart/wbuart.v | 453 ++++++++++++++---------- rtl/wbubus/wbconsole.v | 2 +- rtl/wbubus/wbubus.v | 2 +- rtl/wbubus/wbucompactlines.v | 2 +- rtl/wbubus/wbucompress.v | 2 +- rtl/wbubus/wbuconsole.v | 2 +- rtl/wbubus/wbudecompress.v | 2 +- rtl/wbubus/wbudeword.v | 2 +- rtl/wbubus/wbuexec.v | 2 +- rtl/wbubus/wbufifo.v | 2 +- rtl/wbubus/wbuidleint.v | 2 +- rtl/wbubus/wbuinput.v | 2 +- rtl/wbubus/wbuoutput.v | 2 +- rtl/wbubus/wbureadcw.v | 2 +- rtl/wbubus/wbusixchar.v | 2 +- rtl/wbubus/wbutohex.v | 2 +- rtl/wbxbar.v | 236 +++++++------ sim/verilated/Makefile | 15 +- sim/verilated/automaster_tb.cpp | 10 +- sim/verilated/busmaster_tb.cpp | 2 +- sim/verilated/byteswap.cpp | 2 +- sim/verilated/byteswap.h | 2 +- sim/verilated/dblpipecmdr.h | 2 +- sim/verilated/dbluartsim.cpp | 4 +- sim/verilated/dbluartsim.h | 2 +- sim/verilated/main_tb.cpp | 52 ++- sim/verilated/memsim.cpp | 2 +- sim/verilated/memsim.h | 2 +- sim/verilated/pipecmdr.h | 2 +- sim/verilated/port.h | 2 +- sim/verilated/sdspisim.cpp | 2 +- sim/verilated/sdspisim.h | 2 +- sim/verilated/tbclock.h | 2 +- sim/verilated/testb.h | 34 +- sim/verilated/twoc.cpp | 2 +- sim/verilated/twoc.h | 2 +- sim/verilated/uartsim.cpp | 2 +- sim/verilated/uartsim.h | 2 +- sim/verilated/vversion.sh | 18 +- sim/verilated/zipelf.h | 2 +- sw/board/Makefile | 9 +- sw/board/bkram.ld | 6 +- sw/board/board.ld | 6 +- sw/board/contest.c | 2 +- sw/board/cputest.c | 2 +- sw/board/gpiotoggle.c | 2 +- sw/board/hellosim.s | 16 +- sw/board/sdtest.c | 2 +- sw/board/txfns.c | 2 +- sw/board/txfns.h | 2 +- sw/host/Makefile | 16 +- sw/host/byteswap.cpp | 2 +- sw/host/byteswap.h | 2 +- sw/host/devbus.h | 2 +- sw/host/dumpflash.cpp | 2 +- sw/host/flashdrvr.cpp | 2 +- sw/host/flashdrvr.h | 2 +- sw/host/llcomms.cpp | 2 +- sw/host/llcomms.h | 2 +- sw/host/netuart.cpp | 2 +- sw/host/port.h | 2 +- sw/host/regdefs.cpp | 10 +- sw/host/regdefs.h | 3 +- sw/host/ttybus.cpp | 2 +- sw/host/ttybus.h | 2 +- sw/host/twoc.cpp | 2 +- sw/host/twoc.h | 2 +- sw/host/wbregs.cpp | 2 +- sw/host/zipdbg.cpp | 2 +- sw/host/zipelf.cpp | 2 +- sw/host/zipelf.h | 2 +- sw/host/zipload.cpp | 2 +- sw/host/zipstate.cpp | 2 +- sw/host/zopcodes.h | 2 +- sw/zlib/Makefile | 2 +- sw/zlib/board.h | 3 +- sw/zlib/bootloader.h | 2 +- sw/zlib/syscalls.c | 2 +- sw/zlib/udiv.c | 2 +- sw/zlib/umod.c | 2 +- sw/zlib/zipcpu.h | 3 +- sw/zlib/zipsys.h | 2 +- 169 files changed, 4301 insertions(+), 2081 deletions(-) diff --git a/Makefile b/Makefile index 986f1a1..d0d9b42 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ ################################################################################ ## ## Filename: Makefile -## +## {{{ ## Project: ZBasic, a generic toplevel impl using the full ZipCPU ## ## Purpose: A master project makefile. It tries to build all targets @@ -12,11 +12,11 @@ ## Gisselquist Technology, LLC ## ################################################################################ -## -## Copyright (C) 2015-2020, Gisselquist Technology, LLC -## +## }}} +## Copyright (C) 2015-2021, Gisselquist Technology, LLC +## {{{ ## This program is free software (firmware): you can redistribute it and/or -## modify it under the terms of the GNU General Public License as published +## 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. ## @@ -29,14 +29,14 @@ ## with this program. (It's in the $(ROOT)/doc directory. Run make with no ## target there if the PDF file isn't present.) If not, see ## for a copy. -## +## }}} ## License: GPL, v3, as defined and found on www.gnu.org, +## {{{ ## http://www.gnu.org/licenses/gpl.html ## -## ################################################################################ ## -## +## }}} .PHONY: all all: check-install archive datestamp rtl sim sw # @@ -163,7 +163,7 @@ sw: sw-host sw-zlib sw-board # .PHONY: sw-host sw-host: - $(SUBMAKE) sw/host + +$(SUBMAKE) sw/host # # diff --git a/auto-data/Makefile b/auto-data/Makefile index 68d8d00..389717d 100644 --- a/auto-data/Makefile +++ b/auto-data/Makefile @@ -1,7 +1,7 @@ ################################################################################ ## ## Filename: auto-data/Makefile -## +## {{{ ## Project: ZBasic, a generic toplevel impl using the full ZipCPU ## ## Purpose: To direct the build of the autofpga automatically generated @@ -13,11 +13,11 @@ ## Gisselquist Technology, LLC ## ################################################################################ -## -## Copyright (C) 2017-2020, Gisselquist Technology, LLC -## +## }}} +## Copyright (C) 2017-2021, Gisselquist Technology, LLC +## {{{ ## This program is free software (firmware): you can redistribute it and/or -## modify it under the terms of the GNU General Public License as published +## 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. ## @@ -30,14 +30,14 @@ ## with this program. (It's in the $(ROOT)/doc directory. Run make with no ## target there if the PDF file isn't present.) If not, see ## for a copy. -## +## }}} ## License: GPL, v3, as defined and found on www.gnu.org, +## {{{ ## http://www.gnu.org/licenses/gpl.html ## -## ################################################################################ ## -## +## }}} .PHONY: all all: data # diff --git a/auto-data/bkram.txt b/auto-data/bkram.txt index 330b917..7671b39 100644 --- a/auto-data/bkram.txt +++ b/auto-data/bkram.txt @@ -15,7 +15,7 @@ ## Copyright (C) 2017-2021, Gisselquist Technology, LLC ## {{{ ## This program is free software (firmware): you can redistribute it and/or -## modify it under the terms of the GNU General Public License as published +## 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. ## diff --git a/auto-data/busconsole.txt b/auto-data/busconsole.txt index e736908..cbf12cf 100644 --- a/auto-data/busconsole.txt +++ b/auto-data/busconsole.txt @@ -19,7 +19,7 @@ ## Copyright (C) 2017-2021, Gisselquist Technology, LLC ## {{{ ## This program is free software (firmware): you can redistribute it and/or -## modify it under the terms of the GNU General Public License as published +## 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. ## @@ -223,6 +223,7 @@ typedef struct CONSOLE_S { } CONSOLE; #define _@$(PREFIX)_txbusy ((_uart->u_fifo & 0x10000)==0) +#define _@$(PREFIX)_txidle ((_uart->u_tx & 0x100) ==0) @BDEF.IONAME= io_console @BDEF.IOTYPE= CONSOLE @BDEF.OSDEF= _BOARD_HAS_BUSCONSOLE diff --git a/auto-data/buserr.txt b/auto-data/buserr.txt index 17afc2e..a735fa5 100644 --- a/auto-data/buserr.txt +++ b/auto-data/buserr.txt @@ -15,7 +15,7 @@ ## Copyright (C) 2017-2021, Gisselquist Technology, LLC ## {{{ ## This program is free software (firmware): you can redistribute it and/or -## modify it under the terms of the GNU General Public License as published +## 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. ## diff --git a/auto-data/clock.txt b/auto-data/clock.txt index 0c567c4..5570909 100644 --- a/auto-data/clock.txt +++ b/auto-data/clock.txt @@ -14,7 +14,7 @@ ## Copyright (C) 2017-2021, Gisselquist Technology, LLC ## {{{ ## This program is free software (firmware): you can redistribute it and/or -## modify it under the terms of the GNU General Public License as published +## 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. ## diff --git a/auto-data/flash.txt b/auto-data/flash.txt index 21f1d44..c86aed0 100644 --- a/auto-data/flash.txt +++ b/auto-data/flash.txt @@ -14,7 +14,7 @@ ## Copyright (C) 2017-2021, Gisselquist Technology, LLC ## {{{ ## This program is free software (firmware): you can redistribute it and/or -## modify it under the terms of the GNU General Public License as published +## 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. ## diff --git a/auto-data/global.txt b/auto-data/global.txt index 9cffc1c..f323b5f 100644 --- a/auto-data/global.txt +++ b/auto-data/global.txt @@ -14,7 +14,7 @@ ## Copyright (C) 2015-2021, Gisselquist Technology, LLC ## {{{ ## This program is free software (firmware): you can redistribute it and/or -## modify it under the terms of the GNU General Public License as published +## 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. ## diff --git a/auto-data/gpio.txt b/auto-data/gpio.txt index 0cc8cf2..4406cbe 100644 --- a/auto-data/gpio.txt +++ b/auto-data/gpio.txt @@ -14,7 +14,7 @@ ## Copyright (C) 2017-2021, Gisselquist Technology, LLC ## {{{ ## This program is free software (firmware): you can redistribute it and/or -## modify it under the terms of the GNU General Public License as published +## 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. ## diff --git a/auto-data/legalgen.txt b/auto-data/legalgen.txt index 316f027..32f965c 100644 --- a/auto-data/legalgen.txt +++ b/auto-data/legalgen.txt @@ -18,7 +18,7 @@ // Copyright (C) 2017-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/auto-data/mem_bkram_only.txt b/auto-data/mem_bkram_only.txt index bff07b5..b817210 100644 --- a/auto-data/mem_bkram_only.txt +++ b/auto-data/mem_bkram_only.txt @@ -17,7 +17,7 @@ ## Copyright (C) 2017-2021, Gisselquist Technology, LLC ## {{{ ## This program is free software (firmware): you can redistribute it and/or -## modify it under the terms of the GNU General Public License as published +## 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. ## diff --git a/auto-data/mem_flash_bkram.txt b/auto-data/mem_flash_bkram.txt index 77bc661..8ead968 100644 --- a/auto-data/mem_flash_bkram.txt +++ b/auto-data/mem_flash_bkram.txt @@ -17,7 +17,7 @@ ## Copyright (C) 2017-2020, Gisselquist Technology, LLC ## {{{ ## This program is free software (firmware): you can redistribute it and/or -## modify it under the terms of the GNU General Public License as published +## 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. ## diff --git a/auto-data/pic.txt b/auto-data/pic.txt index eab670c..cf57a63 100644 --- a/auto-data/pic.txt +++ b/auto-data/pic.txt @@ -14,7 +14,7 @@ ## Copyright (C) 2017-2021, Gisselquist Technology, LLC ## {{{ ## This program is free software (firmware): you can redistribute it and/or -## modify it under the terms of the GNU General Public License as published +## 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. ## diff --git a/auto-data/pwrcount.txt b/auto-data/pwrcount.txt index f10e654..81d1c7e 100644 --- a/auto-data/pwrcount.txt +++ b/auto-data/pwrcount.txt @@ -14,7 +14,7 @@ ## Copyright (C) 2017-2021, Gisselquist Technology, LLC ## {{{ ## This program is free software (firmware): you can redistribute it and/or -## modify it under the terms of the GNU General Public License as published +## 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. ## diff --git a/auto-data/rtcdate.txt b/auto-data/rtcdate.txt index eed5245..d770960 100644 --- a/auto-data/rtcdate.txt +++ b/auto-data/rtcdate.txt @@ -14,7 +14,7 @@ ## Copyright (C) 2017-2021, Gisselquist Technology, LLC ## {{{ ## This program is free software (firmware): you can redistribute it and/or -## modify it under the terms of the GNU General Public License as published +## 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. ## diff --git a/auto-data/rtclight.txt b/auto-data/rtclight.txt index 0a81c2a..17445e3 100644 --- a/auto-data/rtclight.txt +++ b/auto-data/rtclight.txt @@ -14,7 +14,7 @@ ## Copyright (C) 2017-2021, Gisselquist Technology, LLC ## {{{ ## This program is free software (firmware): you can redistribute it and/or -## modify it under the terms of the GNU General Public License as published +## 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. ## diff --git a/auto-data/sdspi.txt b/auto-data/sdspi.txt index 205a7a8..938c316 100644 --- a/auto-data/sdspi.txt +++ b/auto-data/sdspi.txt @@ -21,7 +21,7 @@ ## Copyright (C) 2017-2021, Gisselquist Technology, LLC ## {{{ ## This program is free software (firmware): you can redistribute it and/or -## modify it under the terms of the GNU General Public License as published +## 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. ## diff --git a/auto-data/simtrace.txt b/auto-data/simtrace.txt index 6ab9c3a..add719e 100644 --- a/auto-data/simtrace.txt +++ b/auto-data/simtrace.txt @@ -15,7 +15,7 @@ ## Copyright (C) 2018-2021, Gisselquist Technology, LLC ## {{{ ## This program is free software (firmware): you can redistribute it and/or -## modify it under the terms of the GNU General Public License as published +## 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. ## diff --git a/auto-data/version.txt b/auto-data/version.txt index 760d15a..639c849 100644 --- a/auto-data/version.txt +++ b/auto-data/version.txt @@ -14,7 +14,7 @@ ## Copyright (C) 2017-2021, Gisselquist Technology, LLC ## {{{ ## This program is free software (firmware): you can redistribute it and/or -## modify it under the terms of the GNU General Public License as published +## 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. ## diff --git a/auto-data/wbuart.txt b/auto-data/wbuart.txt index 62c821b..60ff3a3 100644 --- a/auto-data/wbuart.txt +++ b/auto-data/wbuart.txt @@ -14,7 +14,7 @@ ## Copyright (C) 2017-2021, Gisselquist Technology, LLC ## {{{ ## This program is free software (firmware): you can redistribute it and/or -## modify it under the terms of the GNU General Public License as published +## 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. ## diff --git a/auto-data/zipmaster.txt b/auto-data/zipmaster.txt index 2c3d2c9..7b3e7d1 100644 --- a/auto-data/zipmaster.txt +++ b/auto-data/zipmaster.txt @@ -17,7 +17,7 @@ ## Copyright (C) 2017-2021, Gisselquist Technology, LLC ## {{{ ## This program is free software (firmware): you can redistribute it and/or -## modify it under the terms of the GNU General Public License as published +## 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. ## @@ -100,10 +100,10 @@ wire zip_trigger; wire [ZIP_INTS-1:0] zip_int_vector; @MAIN.INSERT= - // + //////////////////////////////////////////////////////////////////////// // // The ZipCPU/ZipSystem BUS master - // + // {{{ // assign zip_int_vector = { alt_int_vector[14:8], sys_int_vector[14:6] }; zipsystem #( @@ -162,14 +162,18 @@ #define RESET_ADDRESS @$[0x%08x](RESET_ADDRESS) - @SIM.CLOCK=clk @SIM.INCLUDE= #include "zipelf.h" @SIM.DEFINES= #ifndef VVAR -#ifdef NEW_VERILATOR +#ifdef ROOT_VERILATOR + +#include "Vmain___024root.h" +#define VVAR(A) rootp->main__DOT_ ## A + +#elif defined(NEW_VERILATOR) #define VVAR(A) main__DOT_ ## A #else #define VVAR(A) v__DOT_ ## A @@ -187,7 +191,11 @@ #define cpu_gie CPUVAR(_SET_GIE__DOT__r_gie) #define cpu_iflags CPUVAR(_w_iflags) #define cpu_uflags CPUVAR(_w_uflags) +#ifdef ROOT_VERILATOR +#define cpu_regs CPUVAR(_regset.m_storage) +#else #define cpu_regs CPUVAR(_regset) +#endif #define cpu_cmd_addr VVAR(_swic__DOT__cmd_addr) #define cpu_bus_err CPUVAR(_bus_err) #define cpu_ibus_err CPUVAR(_ibus_err_flag) @@ -223,6 +231,8 @@ m_core->i_cpu_reset = 0; @SIM.METHODS= #ifdef @$(ACCESS) + // ZipCPU Access functions + // {{{ void loadelf(const char *elfname) { ELFSECTION **secpp, *secp; uint32_t entry; @@ -319,31 +329,31 @@ if ((imm & 0x0fffff)==0x00100) { // SIM Exit(0) close(); - exit(0); + // exit(0); + m_done = true; } else if ((imm & 0x0ffff0)==0x00310) { // SIM Exit(User-Reg) - int rcode, rnum; - rnum = (imm&0x0f)+16; - rcode = regp[rnum] & 0x0ff; - if ((m_core->cpu_wr_ce)&&(m_core->cpu_wr_reg_id==rnum)) - rcode = m_core->cpu_wr_gpreg; + // int rnum; + // rnum = (imm&0x0f)+16; + // rcode = regp[rnum] & 0x0ff; + // if ((m_core->cpu_wr_ce)&&(m_core->cpu_wr_reg_id==rnum)) + // rcode = m_core->cpu_wr_gpreg; close(); - exit(rcode); + // exit(rcode); } else if ((imm & 0x0ffff0)==0x00300) { // SIM Exit(Reg) - int rcode, rnum; - rnum = (imm&0x0f)+rbase; - rcode = regp[rnum] & 0x0ff; - if ((m_core->cpu_wr_ce)&&(m_core->cpu_wr_reg_id==rnum)) - rcode = m_core->cpu_wr_gpreg; + // int rnum; + // rnum = (imm&0x0f)+rbase; + // rcode = regp[rnum] & 0x0ff; + // if ((m_core->cpu_wr_ce)&&(m_core->cpu_wr_reg_id==rnum)) + // rcode = m_core->cpu_wr_gpreg; close(); - exit(rcode); + // exit(rcode); } else if ((imm & 0x0fff00)==0x00100) { // SIM Exit(Imm) - int rcode; - rcode = imm & 0x0ff; + // rcode = imm & 0x0ff; close(); - exit(rcode); + // exit(rcode); } else if ((imm & 0x0fffff)==0x002ff) { // Full/unconditional dump printf("SIM-DUMP\n"); @@ -375,7 +385,7 @@ rcode = m_core->cpu_wr_gpreg; printf("%c", rcode&0x0ff); } else if ((imm & 0x0fffe0)==0x00220) { - // SOUT[User Reg] + // SOUT[Reg] int rcode, rnum; rnum = (imm&0x0f)+rbase; rcode = regp[rnum]; @@ -395,10 +405,12 @@ m_core->cpu_upc); } fflush(stdout); } + // }}} #endif // @$(ACCESS) @SIM.TICK= #ifdef @$(ACCESS) // ZipCPU Sim instruction support + // {{{ if ((m_core->cpu_sim) &&(!m_core->cpu_new_pc)) { // @@ -413,6 +425,7 @@ m_cpu_bombed++; dump(m_core->cpu_regs); } + // }}} #endif // @$(ACCESS) ## @@ -470,6 +483,12 @@ @REGS.35=64 R_ZIPSYSTEM ZIPSYSTEM ZIPSYS ## ## +## }}} +################################################################################ +## +## Interrupt definitions +## {{{ +################################################################################ @PREFIX=syspic @PIC.BUS= sys_int_vector @PIC.MAX=15 @@ -548,5 +567,5 @@ @INT.MTC.PIC=altpic @INT.MTC.ID=7 ## -## -## +## }}} +################################################################################ diff --git a/doc/Makefile b/doc/Makefile index 8770d2b..a8d7c61 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -1,7 +1,7 @@ ################################################################################ ## ## Filename: Makefile -## +## {{{ ## Project: ZBasic, a generic toplevel impl using the full ZipCPU ## ## Purpose: To coordinate the build of documentation PDFs from their @@ -20,11 +20,11 @@ ## Gisselquist Technology, LLC ## ################################################################################ -## -## Copyright (C) 2015-2016, Gisselquist Technology, LLC -## +## }}} +## Copyright (C) 2015-2021, Gisselquist Technology, LLC +## {{{ ## This program is free software (firmware): you can redistribute it and/or -## modify it under the terms of the GNU General Public License as published +## 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. ## @@ -37,14 +37,14 @@ ## with this program. (It's in the $(ROOT)/doc directory. Run make with no ## target there if the PDF file isn't present.) If not, see ## for a copy. -## +## }}} ## License: GPL, v3, as defined and found on www.gnu.org, +## {{{ ## http://www.gnu.org/licenses/gpl.html ## -## ################################################################################ ## -## +## }}} all: gpl pdf: gpl DSRC := src diff --git a/doc/src/gqtekspec.cls b/doc/src/gqtekspec.cls index ac53f2c..193e345 100644 --- a/doc/src/gqtekspec.cls +++ b/doc/src/gqtekspec.cls @@ -1,6 +1,6 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%/ % -% Copyright (C) 2015, Gisselquist Technology, LLC +% Copyright (C) 2015-2021, Gisselquist Technology, LLC % % This template is free software: you can redistribute it and/or modify it % under the terms of the GNU General Public License as published by the diff --git a/mkdatev.pl b/mkdatev.pl index 2792d10..d61c479 100755 --- a/mkdatev.pl +++ b/mkdatev.pl @@ -17,7 +17,7 @@ ## Copyright (C) 2015-2021, Gisselquist Technology, LLC ## {{{ ## This program is free software (firmware): you can redistribute it and/or -## modify it under the terms of the GNU General Public License as published +## 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. ## @@ -66,7 +66,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/rtl/Makefile b/rtl/Makefile index 2b80607..b194f9f 100644 --- a/rtl/Makefile +++ b/rtl/Makefile @@ -17,7 +17,7 @@ ## Copyright (C) 2015-2021, Gisselquist Technology, LLC ## {{{ ## This program is free software (firmware): you can redistribute it and/or -## modify it under the terms of the GNU General Public License as published +## 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. ## @@ -104,7 +104,7 @@ design.h: main.v @echo "#endif // DESIGN_H" >> $@ $(VOBJ)/V%__ALL.a: $(VOBJ)/V%.mk - $(SUBMAKE) V$*.mk + +$(SUBMAKE) V$*.mk .PHONY: archive: diff --git a/rtl/addrdecode.v b/rtl/addrdecode.v index ef8c691..fd80270 100644 --- a/rtl/addrdecode.v +++ b/rtl/addrdecode.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: addrdecode.v -// +// {{{ // Project: WB2AXIPSP: bus bridges and other odds and ends // // Purpose: @@ -10,9 +10,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2019-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2019-2021, Gisselquist Technology, LLC +// {{{ // This file is part of the WB2AXIP project. // // The WB2AXIP project contains free software and gateware, licensed under the @@ -32,48 +32,70 @@ // // `default_nettype none -// -module addrdecode(i_clk, i_reset, i_valid, o_stall, i_addr, i_data, - o_valid, i_stall, o_decode, o_addr, o_data); - parameter NS=8; - parameter AW = 32, DW=32+32/8+1+1; - // - // SLAVE_ADDR contains address assignments for each of the various - // slaves we are adjudicating between. - parameter [NS*AW-1:0] SLAVE_ADDR = { - { 3'b111, {(AW-3){1'b0}}}, - { 3'b110, {(AW-3){1'b0}}}, - { 3'b101, {(AW-3){1'b0}}}, - { 3'b100, {(AW-3){1'b0}}}, - { 3'b011, {(AW-3){1'b0}}}, - { 3'b010, {(AW-3){1'b0}}}, - { 4'b0010, {(AW-4){1'b0}}}, - { 4'b0000, {(AW-4){1'b0}}} }; - // - // SLAVE_MASK contains a mask of those address bits in SLAVE_ADDR - // which are relevant. It shall be true that if - // !SLAVE_MASK[k] then !SLAVE_ADDR[k], for any bits of k - parameter [NS*AW-1:0] SLAVE_MASK = (NS <= 1) ? 0 - : { {(NS-2){ 3'b111, {(AW-3){1'b0}}}}, - {(2){ 4'b1111, {(AW-4){1'b0}} }} }; - // - // ACCESS_ALLOWED is a bit-wise mask indicating which slaves may get - // access to the bus. If ACCESS_ALLOWED[slave] is true, then a master - // can connect to the slave via this method. This parameter is - // primarily here to support AXI (or other similar buses) which may have - // separate accesses for both read and write. By using this, a - // read-only slave can be connected, which would also naturally create - // an error on any attempt to write to it. - parameter [NS-1:0] ACCESS_ALLOWED = -1; - // - // If OPT_REGISTERED is set, address decoding will take an extra clock, - // and will register the results of the decoding operation. - parameter [0:0] OPT_REGISTERED = 0; - // - // If OPT_LOWPOWER is set, then whenever the output is not valid, any - // respective data linse will also be forced to zero in an effort - // to minimize power. - parameter [0:0] OPT_LOWPOWER = 0; +// }}} +module addrdecode #( + // {{{ + parameter NS=8, + parameter AW = 32, DW=32+32/8+1+1, + // + // SLAVE_ADDR contains address assignments for each of the + // various slaves we are adjudicating between. + parameter [NS*AW-1:0] SLAVE_ADDR = { + { 3'b111, {(AW-3){1'b0}} }, + { 3'b110, {(AW-3){1'b0}} }, + { 3'b101, {(AW-3){1'b0}} }, + { 3'b100, {(AW-3){1'b0}} }, + { 3'b011, {(AW-3){1'b0}} }, + { 3'b010, {(AW-3){1'b0}} }, + { 4'b0010, {(AW-4){1'b0}} }, + { 4'b0000, {(AW-4){1'b0}} }}, + // + // SLAVE_MASK contains a mask of those address bits in + // SLAVE_ADDR which are relevant. It shall be true that if + // !SLAVE_MASK[k] then !SLAVE_ADDR[k], for any bits of k + parameter [NS*AW-1:0] SLAVE_MASK = (NS <= 1) ? 0 + : { {(NS-2){ 3'b111, {(AW-3){1'b0}} }}, + {(2){ 4'b1111, {(AW-4){1'b0}} }} }, + // + // ACCESS_ALLOWED is a bit-wise mask indicating which slaves + // may get access to the bus. If ACCESS_ALLOWED[slave] is true, + // then a master can connect to the slave via this method. This + // parameter is primarily here to support AXI (or other similar + // buses) which may have separate accesses for both read and + // write. By using this, a read-only slave can be connected, + // which would also naturally create an error on any attempt to + // write to it. + parameter [NS-1:0] ACCESS_ALLOWED = -1, + // + // If OPT_REGISTERED is set, address decoding will take an extra + // clock, and will register the results of the decoding + // operation. + parameter [0:0] OPT_REGISTERED = 0, + // + // If OPT_LOWPOWER is set, then whenever the output is not + // valid, any respective data linse will also be forced to zero + // in an effort to minimize power. + parameter [0:0] OPT_LOWPOWER = 0 + // }}} + ) ( + // {{{ + input wire i_clk, i_reset, + // + input wire i_valid, + output reg o_stall, + input wire [AW-1:0] i_addr, + input wire [DW-1:0] i_data, + // + output reg o_valid, + input wire i_stall, + output reg [NS:0] o_decode, + output reg [AW-1:0] o_addr, + output reg [DW-1:0] o_data + // }}} + ); + + // Local declarations + // {{{ // // OPT_NONESEL controls whether or not the address lines are fully // proscribed, or whether or not a "no-slave identified" slave should @@ -83,63 +105,67 @@ module addrdecode(i_clk, i_reset, i_valid, o_stall, i_addr, i_data, localparam [0:0] OPT_NONESEL = (!ACCESS_ALLOWED[0]) || (SLAVE_MASK[AW-1:0] != 0); // - input wire i_clk, i_reset; - // - input wire i_valid; - output reg o_stall; - input wire [AW-1:0] i_addr; - input wire [DW-1:0] i_data; - // - output reg o_valid; - input wire i_stall; - output reg [NS:0] o_decode; - output reg [AW-1:0] o_addr; - output reg [DW-1:0] o_data; - - reg [NS:0] request; + wire [NS:0] request; reg [NS-1:0] prerequest; - reg none_sel; integer iM; + // }}} + // prerequest + // {{{ always @(*) for(iM=0; iM 1 && |prerequest[NS-1:1])) - request[0] = 1'b0; + r_request[0] = 1'b0; end + assign request[NS-1:0] = r_request; + // }}} end else if (NS == 1) - begin - - always @(*) - request = { 1'b0, i_valid }; - + begin : SINGLE_SLAVE + // {{{ + assign request[0] = i_valid; + // }}} end else begin + // {{{ + reg [NS-1:0] r_request; always @(*) begin for(iM=0; iM 1 && |prerequest[NS-1:1])) - request[0] = 1'b0; + r_request[0] = 1'b0; end + assign request[NS-1:0] = r_request; + // }}} end endgenerate + // }}} + // request[NS] + // {{{ generate if (OPT_NONESEL) begin + reg r_request_NS, r_none_sel; + always @(*) begin // Let's assume nothing's been selected, and then check @@ -148,29 +174,38 @@ module addrdecode(i_clk, i_reset, i_valid, o_stall, i_addr, i_data, // Note that none_sel will be considered an error // condition in the follow-on processing. Therefore // it's important to clear it if no request is pending. - none_sel = i_valid && (prerequest == 0); + r_none_sel = i_valid && (prerequest == 0); // // request[NS] indicates a request for a non-existent // slave. A request that should (eventually) return a // bus error // - request[NS] = none_sel; + r_request_NS = r_none_sel; end + + assign request[NS] = r_request_NS; end else begin - always @(*) - { request[NS], none_sel } = 2'b00; + assign request[NS] = 1'b0; end endgenerate + // }}} + // o_valid, o_addr, o_data, o_decode, o_stall + // {{{ generate if (OPT_REGISTERED) begin + + // o_valid + // {{{ initial o_valid = 0; always @(posedge i_clk) if (i_reset) o_valid <= 0; else if (!o_stall) o_valid <= i_valid; + // }}} - + // o_addr, o_data + // {{{ initial o_addr = 0; initial o_data = 0; always @(posedge i_clk) @@ -188,7 +223,10 @@ module addrdecode(i_clk, i_reset, i_valid, o_stall, i_addr, i_data, o_addr <= 0; o_data <= 0; end + // }}} + // o_decode + // {{{ initial o_decode = 0; always @(posedge i_clk) if (i_reset) @@ -198,9 +236,13 @@ module addrdecode(i_clk, i_reset, i_valid, o_stall, i_addr, i_data, o_decode <= request; else if (OPT_LOWPOWER && !i_stall) o_decode <= 0; + // }}} + // o_stall + // {{{ always @(*) o_stall = (o_valid && i_stall); + // }}} end else begin always @(*) @@ -213,12 +255,30 @@ module addrdecode(i_clk, i_reset, i_valid, o_stall, i_addr, i_data, o_decode = request; end + // Make Verilator happy + // {{{ // verilator lint_off UNUSED wire unused; - assign unused = &{ 1'b0, i_clk, i_reset }; + assign unused = &{ 1'b0, +`ifdef VERILATOR + // Can't declare the clock as unused for formal, + // lest it not be recognized as *the* clock + i_clk, +`endif + i_reset }; // verilator lint_on UNUSED + // }}} end endgenerate - + // }}} +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal properties +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// `ifdef FORMAL reg f_past_valid; initial f_past_valid = 0; @@ -295,6 +355,8 @@ module addrdecode(i_clk, i_reset, i_valid, o_stall, i_addr, i_data, if (!ACCESS_ALLOWED[iM]) assert(!o_decode[iM]); + // LOWPOWER check + // {{{ generate if (OPT_LOWPOWER && OPT_REGISTERED) begin always @(*) @@ -305,11 +367,12 @@ module addrdecode(i_clk, i_reset, i_valid, o_stall, i_addr, i_data, assert(o_data == 0); end end endgenerate + // }}} // // The output decoded value may only ever have one value high, // never more--i.e. $onehot0 - // + // {{{ `ifdef VERIFIC always @(*) assert($onehot0(request)); @@ -327,15 +390,18 @@ module addrdecode(i_clk, i_reset, i_valid, o_stall, i_addr, i_data, if (request != 0) assert(onehot_request); `endif + // }}} //////////////////////////////////////////////////////////////////////// // // Cover properties + // {{{ + //////////////////////////////////////////////////////////////////////// // - // Make sure all addresses are reachable // - //////////////////////////////////////////////////////////////////////// + // + // Make sure all addresses are reachable // reg [NS:0] f_reached; @@ -376,8 +442,9 @@ module addrdecode(i_clk, i_reset, i_valid, o_stall, i_addr, i_data, cover($changed(o_decode)); end endgenerate - + // }}} `endif // FORMAL +// }}} endmodule `ifndef YOSYS `default_nettype wire diff --git a/rtl/builddate.v b/rtl/builddate.v index 9fd10ee..18f66e8 100644 --- a/rtl/builddate.v +++ b/rtl/builddate.v @@ -39,7 +39,7 @@ // // }}} `ifndef DATESTAMP -`define DATESTAMP 32'h20210524 -`define BUILDTIME 32'h00063746 +`define DATESTAMP 32'h20210914 +`define BUILDTIME 32'h00113009 `endif // diff --git a/rtl/cpu/axidcache.v b/rtl/cpu/axidcache.v index 4a1df9d..4a91ba2 100644 --- a/rtl/cpu/axidcache.v +++ b/rtl/cpu/axidcache.v @@ -15,7 +15,7 @@ // Copyright (C) 2020-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -61,10 +61,12 @@ module axidcache #( // line has a valid signal and a tag associated with it. parameter LGNLINES = (LGCACHEWORDS-3), // }}} + parameter [0:0] SWAP_WSTRB = 1'b0, + parameter [0:0] OPT_SIGN_EXTEND = 1'b0, parameter NAUX = 5, - // Verilator lint_off UNUSED - localparam LGPIPE = 2, parameter [0:0] OPT_PIPE = 1'b0, + // Verilator lint_off UNUSED + localparam LGPIPE = (OPT_PIPE) ? 4:2, // Verilator lint_on UNUSED parameter [0:0] OPT_LOWPOWER = 1'b0, // Local parameters, mostly abbreviations @@ -185,8 +187,8 @@ module axidcache #( wire [TW-1:0] r_ctag, i_ctag; reg r_iv, r_rv, r_check, w_v; - reg zero_noutstanding, last_ack; - reg [1:0] noutstanding; + reg zero_noutstanding, last_ack, full_pipe; + reg [LGPIPE-1:0] noutstanding; reg [CS-1:0] wcache_addr; reg [DW-1:0] wcache_data; reg [DW/8-1:0] wcache_strb; @@ -201,24 +203,33 @@ module axidcache #( last_tag_valid, w_cache_miss; reg [DW-1:0] pre_data, shifted_data; reg [AXILSB+1:0] req_data; + wire [AXILSB-1:0] req_lsb; + wire [1:0] req_op; + + reg [1:0] suppress_miss; + reg [CS-1:0] read_addr; + // AXI registers + // {{{ reg axi_awvalid, axi_wvalid; reg [AW-1:0] axi_awaddr; reg [DW-1:0] axi_wdata; reg [DW/8-1:0] axi_wstrb; + wire [DW-1:0] axi_rdata; reg axi_arvalid; reg [AW-1:0] axi_araddr; reg [7:0] axi_arlen; reg [2:0] axi_arsize; // }}} + // }}} // Fixed AXI outputs that aren't changing // {{{ assign M_AXI_AWID = AXI_ID; assign M_AXI_ARID = AXI_ID; assign M_AXI_AWLEN = 0; // All writes are one beat only - assign M_AXI_AWSIZE = 2; // Write thru cache: All writes are 32-b + assign M_AXI_AWSIZE = 3'b010; // Write thru cache: All writes are 32-b assign M_AXI_AWBURST = 2'b01; // INCR addressing only assign M_AXI_ARBURST = 2'b01; @@ -246,16 +257,6 @@ module axidcache #( always @(*) begin misaligned = checklsb(i_op[2:1], i_addr[AXILSB-1:0]); - /* - mislsb = { 1'b0, i_addr[AXILSB-1:0] }; - case(i_op[2:1]) - 2'b10: mislsb = mislsb + 1; - 2'b11: mislsb = mislsb + 0; - default: mislsb = mislsb + 3; - endcase - - misaligned = mislsb[AXILSB]; - */ end function checklsb; @@ -265,16 +266,18 @@ module axidcache #( reg [AXILSB:0] mislsbfn; mislsbfn = { 1'b0, addr }; + mislsbfn[2] = 0; case(op[1:0]) 2'b10: mislsbfn = mislsbfn + 1; 2'b11: mislsbfn = mislsbfn + 0; default: mislsbfn = mislsbfn + 3; endcase - checklsb = mislsbfn[AXILSB]; + // checklsb = mislsbfn[AXILSB]; + checklsb = mislsbfn[2]; endfunction // }}} - + // Address decoding // {{{ assign i_cline = i_addr[LS+AXILSB +: (CS-LS)]; // Cache line @@ -318,7 +321,16 @@ module axidcache #( w_tag = (r_check) ? r_itag : r_rtag; // Cachability checking - iscachable chkaddress(i_addr[AW-1:2], address_is_cachable); + // {{{ + // Note that the correct address width must be built-in to the + // iscachable routine. It is *not* parameterizable. iscachable must + // be rewritten if the address width changes because, of necessity, that + // also means the address map is changing and therefore what is and + // isn't cachable. etc. + iscachable chkaddress( + i_addr[AW-1:2], address_is_cachable + ); + // }}} initial r_rd_pending = 0; initial r_cache_miss = 0; @@ -400,6 +412,14 @@ module axidcache #( always @(*) zero_noutstanding = (noutstanding == 0); + always @(*) + begin + full_pipe = 1'b0; + if (&noutstanding[LGPIPE-1:1]) + full_pipe = noutstanding[0] + || (M_AXI_AWVALID || M_AXI_WVALID); + end + always @(*) last_ack = (noutstanding <= 1)&&(!M_AXI_ARVALID && !M_AXI_AWVALID); @@ -407,16 +427,29 @@ module axidcache #( always @(posedge S_AXI_ACLK) if (!S_AXI_ARESETN) flushing <= 0; - else if (i_cpu_reset && (!last_ack || M_AXI_ARVALID || M_AXI_AWVALID)) - flushing <= 1; - else if (M_AXI_RVALID) - flushing <= (i_cpu_reset || flushing || M_AXI_RRESP[1]) && (!M_AXI_RLAST || !last_ack); - else if (M_AXI_BVALID) - flushing <= (i_cpu_reset || flushing || M_AXI_BRESP[1]) && !last_ack; - else if (!zero_noutstanding) - flushing <= (i_cpu_reset || flushing); - else if (zero_noutstanding && !M_AXI_ARVALID && !M_AXI_AWVALID) - flushing <= 0; + else if (flushing) + begin // Can we clear flushing? + if (zero_noutstanding) + flushing <= 1'b0; + if (last_ack && (M_AXI_BVALID + || (M_AXI_RVALID && M_AXI_RLAST))) + flushing <= 1'b0; + if (M_AXI_AWVALID || M_AXI_ARVALID || M_AXI_WVALID) + flushing <= 1'b1; + end else if (i_cpu_reset + || (M_AXI_RVALID && M_AXI_RRESP[1]) + || (M_AXI_BVALID && M_AXI_BRESP[1]) + || (OPT_PIPE && i_pipe_stb && misaligned)) + begin // Flushing causes + flushing <= 1'b0; + if (M_AXI_ARVALID || M_AXI_AWVALID || M_AXI_WVALID) + flushing <= 1'b1; + if (!last_ack) + flushing <= 1'b1; + if ((noutstanding >= 1) && !M_AXI_BVALID + && (!M_AXI_RVALID || !M_AXI_RLAST)) + flushing <= 1'b1; + end // }}} // Read handling @@ -479,7 +512,8 @@ module axidcache #( // }}} DC_WRITE: begin // {{{ - if (M_AXI_BVALID && M_AXI_BREADY && last_ack) + if (M_AXI_BVALID && M_AXI_BREADY + && (!OPT_PIPE || (last_ack && !i_pipe_stb))) state <= DC_IDLE; end // }}} @@ -493,7 +527,6 @@ module axidcache #( // M_AXI_ARVALID, axi_arvalid // {{{ - reg [1:0] suppress_miss; always @(posedge S_AXI_ACLK) suppress_miss <= { suppress_miss[0] || set_vflag, set_vflag }; always @(*) @@ -550,6 +583,13 @@ module axidcache #( 2'b11: axi_arsize <= 3'd0; default: axi_arsize <= 3'd2; endcase + + if (SWAP_WSTRB) + begin + axi_araddr[AXILSB-1:0] <= ~i_addr[AXILSB-1:0]; + axi_araddr[1:0] <= 0; + axi_arsize <= 3'b010; + end // }}} end @@ -601,7 +641,13 @@ module axidcache #( begin axi_awaddr <= i_addr; - if (!i_pipe_stb || !i_op[0] || misaligned) + if (SWAP_WSTRB) + begin + // axi_awaddr[AXILSB-1:0] <= ~i_addr[AXILSB-1:0]; + axi_awaddr[1:0] <= 0; + end + + if (OPT_LOWPOWER && (!i_pipe_stb || !i_op[0] || misaligned)) axi_awaddr <= 0; end @@ -640,30 +686,72 @@ module axidcache #( // WDATA // {{{ - casez(i_op[2:1]) - // Write a 16b half-word - 2'b10: axi_wdata <= { {(C_AXI_DATA_WIDTH-16){1'b0}}, + if (SWAP_WSTRB) + begin + // {{{ + casez(i_op[2:1]) + // Write a 16b half-word + 2'b10: axi_wdata <= { i_data[15:0], + {(C_AXI_DATA_WIDTH-16){1'b0}} } + >> (8*i_addr[AXILSB-1:0]); + // Write an 8b half-word + 2'b11: axi_wdata <= { i_data[7:0], + {(C_AXI_DATA_WIDTH-8){1'b0}} } + >> (8*i_addr[AXILSB-1:0]); + default: axi_wdata <= { i_data, + {(C_AXI_DATA_WIDTH-32){1'b0}} } + >> (8*i_addr[AXILSB-1:0]); + endcase + // }}} + end else begin + // {{{ + casez(i_op[2:1]) + // Write a 16b half-word + 2'b10: axi_wdata <= { {(C_AXI_DATA_WIDTH-16){1'b0}}, i_data[15:0] } << (8*i_addr[AXILSB-1:0]); - // Write an 8b half-word - 2'b11: axi_wdata <= { {(C_AXI_DATA_WIDTH-8){1'b0}}, + // Write an 8b half-word + 2'b11: axi_wdata <= { {(C_AXI_DATA_WIDTH-8){1'b0}}, i_data[7:0] } << (8*i_addr[AXILSB-1:0]); - default: axi_wdata <= { {(C_AXI_DATA_WIDTH-32){1'b0}}, + default: axi_wdata <= { {(C_AXI_DATA_WIDTH-32){1'b0}}, i_data } << (8*i_addr[AXILSB-1:0]); - endcase + endcase + // }}} + end // }}} // WSTRB // {{{ - casez(i_op[2:1]) - // Write a 16b half-word - 2'b10: axi_wstrb <= { {(C_AXI_DATA_WIDTH/8-4){1'b0}}, + if (SWAP_WSTRB) + begin + // {{{ + casez(i_op[2:1]) + // Write a 16b half-word + 2'b10: axi_wstrb <= { 2'b11, + {(C_AXI_DATA_WIDTH/8-2){1'b0}} } + >> (i_addr[AXILSB-1:0]); + // Write an 8b half-word + 2'b11: axi_wstrb <= { 1'b1, + {(C_AXI_DATA_WIDTH/8-1){1'b0}} } + >> (i_addr[AXILSB-1:0]); + default: axi_wstrb <= { 4'b1111, + {(C_AXI_DATA_WIDTH/8-4){1'b0}} } + >> (i_addr[AXILSB-1:0]); + endcase + // }}} + end else begin + // {{{ + casez(i_op[2:1]) + // Write a 16b half-word + 2'b10: axi_wstrb <= { {(C_AXI_DATA_WIDTH/8-4){1'b0}}, 4'b0011 } << (i_addr[AXILSB-1:0]); - // Write an 8b half-word - 2'b11: axi_wstrb <= { {(C_AXI_DATA_WIDTH/8-4){1'b0}}, + // Write an 8b half-word + 2'b11: axi_wstrb <= { {(C_AXI_DATA_WIDTH/8-4){1'b0}}, 4'b0001 } << (i_addr[AXILSB-1:0]); - default: axi_wstrb <= { {(C_AXI_DATA_WIDTH/8-4){1'b0}}, - 4'b1111 } << (i_addr[AXILSB-1:0]); - endcase + default: axi_wstrb <= { {(C_AXI_DATA_WIDTH/8-4){1'b0}}, + 4'b1111 } << (i_addr[AXILSB-1:0]); + endcase + // }}} + end // }}} // OPT_LOWPOWER: Clear if nothing is being used @@ -678,14 +766,35 @@ module axidcache #( // }}} end - assign M_AXI_WDATA = axi_wdata; - assign M_AXI_WSTRB = axi_wstrb; + genvar gk; + generate if (!SWAP_WSTRB) + begin + assign M_AXI_WDATA = axi_wdata; + assign M_AXI_WSTRB = axi_wstrb; + + assign axi_rdata = M_AXI_RDATA; + end else for(gk=0; gk> (8*i_addr[AXILSB-1:0]); + // Write an 8b half-word + 2'b11: wcache_data <= { i_data[7:0], + {(DW-8){1'b0}} } + >> (8*i_addr[AXILSB-1:0]); + default: wcache_data <= { i_data, + {(DW-32){1'b0}} } + >> (8*i_addr[AXILSB-1:0]); + endcase + end else begin + casez(i_op[2:1]) + // Write a 16b half-word + 2'b10: wcache_data <= { {(DW-16){1'b0}}, i_data[15:0] } << (8*i_addr[AXILSB-1:0]); - // Write an 8b half-word - 2'b11: wcache_data <= { {(C_AXI_DATA_WIDTH-8){1'b0}}, + // Write an 8b half-word + 2'b11: wcache_data <= { {(DW-8){1'b0}}, i_data[7:0] } << (8*i_addr[AXILSB-1:0]); - default: wcache_data <= { {(C_AXI_DATA_WIDTH-32){1'b0}}, + default: wcache_data <= { {(DW-32){1'b0}}, i_data } << (8*i_addr[AXILSB-1:0]); - endcase + endcase + end // }}} // wcache_strb // {{{ - casez(i_op[2:1]) - // Write a 16b half-word - 2'b10: wcache_strb<= { {(C_AXI_DATA_WIDTH/8-4){1'b0}}, - 4'h3 } << (i_addr[AXILSB-1:0]); - // Write an 8b byte - 2'b11: wcache_strb<= { {(C_AXI_DATA_WIDTH/8-4){1'b0}}, - 4'h1 } << (i_addr[AXILSB-1:0]); - default: wcache_strb<={{(C_AXI_DATA_WIDTH/8-4){1'b0}}, - 4'hf } << (i_addr[AXILSB-1:0]); - endcase + if (SWAP_WSTRB) + begin + case(i_op[2:1]) + // Write a 16b half-word + 2'b10: wcache_strb<= + { 2'h3, {(C_AXI_DATA_WIDTH/8-2){1'b0}} } + >> (i_addr[AXILSB-1:0]); + // Write an 8b byte + 2'b11: wcache_strb<= + { 1'b1, {(C_AXI_DATA_WIDTH/8-1){1'b0}} } + >> (i_addr[AXILSB-1:0]); + default: wcache_strb<= + { 4'hf, {(C_AXI_DATA_WIDTH/8-4){1'b0}} } + >> (i_addr[AXILSB-1:0]); + endcase + end else begin + case(i_op[2:1]) + // Write a 16b half-word + 2'b10: wcache_strb<= + { {(C_AXI_DATA_WIDTH/8-4){1'b0}}, 4'h3 } + << (i_addr[AXILSB-1:0]); + // Write an 8b byte + 2'b11: wcache_strb<= + { {(C_AXI_DATA_WIDTH/8-4){1'b0}}, 4'h1 } + << (i_addr[AXILSB-1:0]); + default: wcache_strb<= + {{(C_AXI_DATA_WIDTH/8-4){1'b0}}, 4'hf } + << (i_addr[AXILSB-1:0]); + endcase + end // }}} if (!i_pipe_stb || !i_op[0] || misaligned) @@ -782,7 +928,7 @@ module axidcache #( // else if (state == DC_READC && M_AXI_RVALID && M_AXI_RLAST) else if (r_dvalid || r_svalid) o_busy <= 1'b0; - else if (M_AXI_BVALID && last_ack) + else if (M_AXI_BVALID && last_ack && (!OPT_PIPE || !i_pipe_stb)) o_busy <= 1'b0; // }}} @@ -807,10 +953,18 @@ module axidcache #( // o_pipe_stalled // {{{ always @(*) - // if (!OPT_PIPE) + if (!OPT_PIPE) o_pipe_stalled = o_busy; - // else - // o_pipe_stalled = // more complex + else if (o_rdbusy || flushing) + o_pipe_stalled = 1'b1; + else if (M_AXI_AWVALID && !M_AXI_AWREADY) + o_pipe_stalled = 1'b1; + else if (M_AXI_WVALID && !M_AXI_WREADY) + o_pipe_stalled = 1'b1; + else if (full_pipe) + o_pipe_stalled = 1'b1; + else + o_pipe_stalled = 1'b0; // }}} // o_wreg @@ -825,7 +979,10 @@ module axidcache #( // {{{ always @(posedge S_AXI_ACLK) if (i_pipe_stb) - req_data <= { i_op[2:1], i_addr[AXILSB-1:0] }; + req_data <= { i_op[2:1], rev_addr[AXILSB-1:0] }; + + assign req_lsb = req_data[AXILSB-1:0]; + assign req_op = req_data[AXILSB +: 2]; // }}} // o_err @@ -872,22 +1029,41 @@ module axidcache #( if (r_svalid) pre_data = cached_iword; else if (state == DC_READS) - pre_data = M_AXI_RDATA; + pre_data = axi_rdata; else pre_data = cached_rword; always @(*) - shifted_data = pre_data >> (8*req_data[AXILSB-1:0]); + if (SWAP_WSTRB) + begin + shifted_data = pre_data << (8*req_lsb); + + casez(req_op) + 2'b10: shifted_data[31:0] = { 16'h0, shifted_data[DW-1:DW-16] }; + 2'b11: shifted_data[31:0] = { 24'h0, shifted_data[DW-1:DW- 8] }; + default: shifted_data[31:0] = shifted_data[DW-1:DW-32]; + endcase + end else + shifted_data = pre_data >> (8*req_lsb); // o_data always @(posedge S_AXI_ACLK) begin o_data <= shifted_data[31:0]; - casez(req_data[AXILSB +: 2]) - 2'b10: o_data[31:16] <= 0; - 2'b11: o_data[31: 8] <= 0; - default: begin end - endcase + if (OPT_SIGN_EXTEND) + begin + casez(req_op) + 2'b10: o_data[31:16] <= {(16){shifted_data[15]}}; + 2'b11: o_data[31: 8] <= {(24){shifted_data[ 7]}}; + default: begin end + endcase + end else begin + casez(req_op) + 2'b10: o_data[31:16] <= 0; + 2'b11: o_data[31: 8] <= 0; + default: begin end + endcase + end end // }}} @@ -908,8 +1084,8 @@ module axidcache #( // Verilator lint_off UNUSED wire unused; assign unused = &{ 1'b0, M_AXI_BID, M_AXI_RID, r_addr, M_AXI_RRESP[0], - M_AXI_BRESP[0], i_lock, OPT_PIPE, - shifted_data }; + M_AXI_BRESP[0], i_lock, shifted_data, + rev_addr[C_AXI_ADDR_WIDTH-1:AXILSB] }; // Verilator lint_on UNUSED // }}} //////////////////////////////////////////////////////////////////////////////// diff --git a/rtl/cpu/axiicache.v b/rtl/cpu/axiicache.v index d00c8d0..99cfd0e 100644 --- a/rtl/cpu/axiicache.v +++ b/rtl/cpu/axiicache.v @@ -39,7 +39,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -433,8 +433,18 @@ module axiicache #( begin : NO_LINE_SHIFT always @(*) - o_insn = cache_word; + o_insn = cache_word[INSN_WIDTH-1:0]; + // Make Verilator happy + // {{{ + // Verilator lint_off UNUSED + if (DW > INSN_WIDTH) + begin + wire unused_wide; + assign unused_wide = &{ 1'b0, cache_word[DW-1:INSN_WIDTH] }; + end + // Verilator lint_on UNUSED + // }}} end else begin : SHIFT_CACHE_LINE reg [C_AXI_DATA_WIDTH-1:0] shifted; @@ -442,8 +452,19 @@ module axiicache #( always @(*) begin shifted=cache_word >> (INSN_WIDTH * o_pc[ADDRLSB-1:LGINSN]); - o_insn = shifted[DW-1:0]; + o_insn = shifted[INSN_WIDTH-1:0]; end + + // Make Verilator happy + // {{{ + // Verilator lint_off UNUSED + if (DW > INSN_WIDTH) + begin + wire unused_wide; + assign unused_wide = &{ 1'b0, shifted[DW-1:INSN_WIDTH] }; + end + // Verilator lint_on UNUSED + // }}} end endgenerate // }}} diff --git a/rtl/cpu/axilfetch.v b/rtl/cpu/axilfetch.v index 8ba3959..9227005 100644 --- a/rtl/cpu/axilfetch.v +++ b/rtl/cpu/axilfetch.v @@ -15,7 +15,7 @@ // Copyright (C) 2020-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -41,9 +41,9 @@ module axilfetch #( // {{{ parameter C_AXI_ADDR_WIDTH = 32, parameter C_AXI_DATA_WIDTH = 64, - parameter DATA_WIDTH=32, + parameter INSN_WIDTH=32, parameter FETCH_LIMIT=16, - parameter [0:0] SWAP_ENDIANNESS = 1'b1, + parameter [0:0] SWAP_ENDIANNESS = 1'b0, localparam AW=C_AXI_ADDR_WIDTH // }}} ) ( @@ -58,7 +58,7 @@ module axilfetch #( input wire i_clear_cache, input wire i_ready, input wire [AW-1:0] i_pc, // Ignd unls i_new_pc - output wire [DATA_WIDTH-1:0] o_insn, // Insn read from bus + output wire [INSN_WIDTH-1:0] o_insn, // Insn read from bus output reg [AW-1:0] o_pc, // Addr of that insn output reg o_valid, // If valid output reg o_illegal, // Bus error @@ -81,7 +81,8 @@ module axilfetch #( // Declarations // {{{ localparam AXILLSB = $clog2(C_AXI_DATA_WIDTH/8); - localparam INSNS_PER_WORD = C_AXI_DATA_WIDTH / DATA_WIDTH; + localparam INSNS_PER_WORD = C_AXI_DATA_WIDTH / INSN_WIDTH; + localparam INSN_LSB = $clog2(INSN_WIDTH/8); localparam LGDEPTH = $clog2(FETCH_LIMIT)+4; localparam LGFIFO = $clog2(FETCH_LIMIT); localparam W = LGDEPTH; @@ -92,7 +93,7 @@ module axilfetch #( reg [W:0] new_flushcount, outstanding, next_outstanding, flushcount; reg flushing, flush_request, full_bus; - reg [((AXILLSB>2)?(AXILLSB-3):0):0] shift; + wire [((AXILLSB>INSN_LSB) ? (AXILLSB-INSN_LSB-1):0):0] shift; wire fifo_reset, fifo_wr, fifo_rd; wire ign_fifo_full, fifo_empty; wire [LGFIFO:0] ign_fifo_fill; @@ -272,26 +273,19 @@ module axilfetch #( o_pc <= i_pc; else if (o_valid && i_ready && !o_illegal) begin - o_pc[AW-1:2] <= o_pc[AW-1:2] + 1; - o_pc[1:0] <= 2'b00; + o_pc <= 0; + o_pc[AW-1:INSN_LSB] <= o_pc[AW-1:INSN_LSB] + 1; end // }}} - generate if (AXILLSB > 2) + generate if (AXILLSB > INSN_LSB) begin : BIG_WORD // {{{ - always @(*) - begin - shift = o_pc[AXILLSB-1:2]; - - if (FETCH_LIMIT > 0 && o_valid) - shift = 0; - end + assign shift = o_pc[AXILLSB-1:INSN_LSB]; // }}} end else begin : NO_SHIFT // {{{ - always @(*) - shift = 0; + assign shift = 0; // }}} end endgenerate @@ -300,11 +294,12 @@ module axilfetch #( // {{{ genvar gw, gb; // Word count, byte count - for(gw=0; gw 0) + begin + if (fifo_empty) + out_fill <= 0; + else if (o_valid) + out_fill <= INSNS_PER_WORD[FILLBITS:0]; + else + // Verilator lint_off WIDTH + out_fill <= (INSNS_PER_WORD[FILLBITS:0] - shift); + // Verilator lint_on WIDTH + end else if (i_ready && out_fill > 0) out_fill <= out_fill - 1; // }}} @@ -407,12 +420,16 @@ module axilfetch #( // {{{ always @(posedge S_AXI_ACLK) if (fifo_rd) - out_data <= fifo_data[C_AXI_DATA_WIDTH-1:0]>>(DATA_WIDTH*shift); - else if (i_ready) - out_data <= out_data >> DATA_WIDTH; + begin + if (o_valid || (INSN_WIDTH == C_AXI_DATA_WIDTH)) + out_data <= fifo_data[C_AXI_DATA_WIDTH-1:0]; + else + out_data <= fifo_data[C_AXI_DATA_WIDTH-1:0]>>(INSN_WIDTH*shift); + end else if (i_ready) + out_data <= out_data >> INSN_WIDTH; // }}} - assign o_insn = out_data[DATA_WIDTH-1:0]; + assign o_insn = out_data[INSN_WIDTH-1:0]; // o_illegal // {{{ @@ -443,16 +460,20 @@ module axilfetch #( `ifdef FORMAL // Declarations // {{{ - localparam DW=DATA_WIDTH; + localparam DW=INSN_WIDTH; localparam F_LGDEPTH=LGDEPTH+2; reg f_past_valid; wire [(F_LGDEPTH-1):0] faxil_outstanding; + // Verilator lint_off UNUSED + wire [(F_LGDEPTH-1):0] faxil_awr_outstanding, + faxil_wr_outstanding; + // Verilator lint_on UNUSED reg [(AW-1):0] f_last_pc; reg f_last_pc_valid; // reg [AW-1:0] fc_pc, f_address; reg fc_illegal; - reg [DATA_WIDTH-1:0] fc_insn; + reg [INSN_WIDTH-1:0] fc_insn; //}}} //////////////////////////////////////////////////////////////////////// // @@ -466,7 +487,7 @@ module axilfetch #( // will return valid results initial f_past_valid = 1'b0; always @(posedge S_AXI_ACLK) - f_past_valid = 1'b1; + f_past_valid <= 1'b1; // }}} //////////////////////////////////////////////////////////////////////// // @@ -549,8 +570,13 @@ module axilfetch #( // Unused write interface // {{{ .i_axi_awvalid(1'b0), .i_axi_awready(1'b1), + .i_axi_awaddr( {(AW){1'b0}}), + .i_axi_awprot( 3'h0), .i_axi_wvalid(1'b0), .i_axi_wready(1'b1), + .i_axi_wdata({(C_AXI_DATA_WIDTH){1'b0}}), + .i_axi_wstrb({(C_AXI_DATA_WIDTH/8){1'b0}}), .i_axi_bvalid(1'b0), .i_axi_bready(1'b1), + .i_axi_bresp(2'b00), // }}} // Read address channel // {{{ @@ -566,6 +592,8 @@ module axilfetch #( .i_axi_rdata(M_AXI_RDATA), .i_axi_rresp(M_AXI_RRESP), // }}} + .f_axi_awr_outstanding(faxil_awr_outstanding), + .f_axi_wr_outstanding(faxil_wr_outstanding), .f_axi_rd_outstanding(faxil_outstanding) // }}} ); @@ -595,11 +623,11 @@ module axilfetch #( //////////////////////////////////////////////////////////////////////// // // - reg [W:0] f_word_count; - reg [AW-1:0] f_return_addr; - reg [AW-1:0] f_out_addr, f_subout_addr; - reg [C_AXI_ADDR_WIDTH-1:0] f_req_addr, f_ret_addr; - reg [W:0] f_req_offset, f_ret_offset; + reg [W:0] f_word_count; + reg [AW-1:0] f_return_addr; + reg [AW-1:0] f_out_addr, f_subout_addr; + reg [AW-1:0] f_req_addr, f_ret_addr; + reg [W:0] f_req_offset, f_ret_offset; always @(*) @@ -610,28 +638,29 @@ module axilfetch #( if (M_AXI_ARVALID && f_req_offset > 0) f_req_offset = f_req_offset - 1; - f_req_addr = f_out_addr + (f_req_offset << AXILLSB); - if (f_req_offset == 0) - f_req_addr[AXILLSB-1:0] = o_pc[AXILLSB-1:0]; + // Verilator lint_off WIDTH + f_req_addr = 0; + f_req_addr[AW-1:AXILLSB] = f_out_addr[AW-1:AXILLSB] + + f_req_offset; /////////////// f_ret_offset = o_valid ? 1:0; f_ret_offset = f_ret_offset + ign_fifo_fill; - f_ret_addr = f_out_addr + (f_ret_offset << AXILLSB); - if (f_ret_offset == 0) - f_ret_addr[AXILLSB-1:0] = o_pc[AXILLSB-1:0]; + f_ret_addr = 0; + f_ret_addr[AW-1:AXILLSB] = f_out_addr[AW-1:AXILLSB] + f_ret_offset; end always @(*) + if (S_AXI_ARESETN) + begin assert(f_req_offset <= f_word_count); - always @(*) assert(f_req_offset == fill + (o_valid ? 1:0)); - always @(*) assert(f_ret_offset <= f_req_offset); + end always @(*) if (!i_cpu_reset && !i_new_pc && !i_clear_cache @@ -639,25 +668,27 @@ module axilfetch #( assert(M_AXI_ARADDR[AXILLSB-1:0] == 0); always @(*) - if (!flushing) - assert(f_word_count <= FETCH_LIMIT); - else - assert(f_word_count - flushcount <= FETCH_LIMIT); + if (S_AXI_ARESETN) + begin + if (!flushing) + begin + assert(f_word_count <= FETCH_LIMIT); + end else + assert(f_word_count - flushcount <= FETCH_LIMIT); + end always @(*) if (!i_cpu_reset && !i_new_pc && !i_clear_cache && !flush_request) begin - if (!o_illegal) - assert(f_req_addr[AXILLSB-1:0] == M_AXI_ARADDR[AXILLSB-1:0]); - assert(f_req_addr[C_AXI_ADDR_WIDTH-1:AXILLSB] - == M_AXI_ARADDR[C_AXI_ADDR_WIDTH-1:AXILLSB]); + // if (!o_illegal) + // assert(f_req_addr[AXILLSB-1:0] == M_AXI_ARADDR[AXILLSB-1:0]); + assert(f_req_addr[AW-1:AXILLSB] == M_AXI_ARADDR[AW-1:AXILLSB]); end always @(*) if (S_AXI_ARESETN && !i_cpu_reset && !i_new_pc && !i_clear_cache && !flushing && !o_illegal) - assert(f_ret_addr[C_AXI_ADDR_WIDTH-1:AXILLSB] - == f_return_addr[C_AXI_ADDR_WIDTH-1:AXILLSB]); + assert(f_ret_addr[AW-1:AXILLSB] == f_return_addr[AW-1:AXILLSB]); always @(*) begin @@ -684,7 +715,7 @@ module axilfetch #( begin assert(faxil_outstanding + (M_AXI_ARVALID ? 1:0)<=(1<0)); + generate if (AXILLSB != INSN_LSB) + begin : OUTFILL_CHK + always @(*) + if (o_valid && !o_illegal) + assert(out_fill == INSNS_PER_WORD - o_pc[AXILLSB-1:INSN_LSB]); + end else begin + always @(*) + if (S_AXI_ARESETN) + assert(out_fill <= 1); + end endgenerate + // // Assertions about our return responses // {{{ @@ -755,11 +803,11 @@ module axilfetch #( // {{{ genvar gw, gb; // Word count, byte count - for(gw=0; gw> (shift * DATA_WIDTH); + assign f_bus_word = endian_swapped_rdata >> (bshift * INSN_WIDTH); + // Verilator lint_on WIDTH // }}} end endgenerate @@ -849,19 +912,21 @@ module axilfetch #( // Step 2: Assert that any value in our cache meets the contract // // - generate if (DATA_WIDTH == C_AXI_DATA_WIDTH) + generate if (INSN_WIDTH == C_AXI_DATA_WIDTH) begin : F_OUTDATA // {{{ assign f_out_data = out_data; // }}} end else begin : F_OUTDATA_SHIFT // {{{ - reg [$clog2(INSNS_PER_WORD)-1:0] shift; + reg [$clog2(INSNS_PER_WORD)-1:0] ashift; + // Verilator lint_off WIDTH always @(*) - shift = (fc_pc - f_subout_addr) >> $clog2(DATA_WIDTH/8); + ashift = (fc_pc - f_subout_addr) >> INSN_LSB; - assign f_out_data = out_data >> (shift * DATA_WIDTH); + assign f_out_data = out_data >> (ashift * INSN_WIDTH); + // Verilator lint_on WIDTH // }}} end endgenerate @@ -886,27 +951,27 @@ module axilfetch #( f_cache_check = 1'b0; end - if (DATA_WIDTH == C_AXI_DATA_WIDTH) + if (INSN_WIDTH == C_AXI_DATA_WIDTH) begin : F_CACHEDATA - assign f_cache_data=DBLFETCH.cache_data[DATA_WIDTH-1:0]; - assign f_cache_illegal= DBLFETCH.cache_data[DATA_WIDTH]; + assign f_cache_data=DBLFETCH.cache_data[INSN_WIDTH-1:0]; + assign f_cache_illegal= DBLFETCH.cache_data[INSN_WIDTH]; end else begin : F_CACHEDATA_SHIFT - reg [$clog2(INSNS_PER_WORD)-1:0] shift; + reg [$clog2(INSNS_PER_WORD)-1:0] ashift; always @(*) - shift = (fc_pc - f_cache_addr) >> $clog2(DATA_WIDTH/8); + ashift = (fc_pc - f_cache_addr) >> INSN_LSB; - assign f_cache_data = DBLFETCH.cache_data >> (shift * DATA_WIDTH); + assign f_cache_data = DBLFETCH.cache_data >> (ashift * INSN_WIDTH); assign f_cache_illegal= DBLFETCH.cache_data[C_AXI_DATA_WIDTH]; end always @(*) if (f_cache_check && !o_illegal) begin - assert(f_cache_data[DATA_WIDTH-1:0] == fc_insn); + assert(f_cache_data[INSN_WIDTH-1:0] == fc_insn); assert(f_cache_illegal == fc_illegal); end // }}} @@ -944,26 +1009,28 @@ module axilfetch #( f_cache_check = 1'b0; end - if (DATA_WIDTH == C_AXI_DATA_WIDTH) + if (INSN_WIDTH == C_AXI_DATA_WIDTH) begin : F_CACHEDATA always @(*) f_cache_subdata = f_cache_data; always @(*) - f_fifo_subdata = fifo_data[DATA_WIDTH-1:0]; + f_fifo_subdata = fifo_data[INSN_WIDTH-1:0]; end else begin : F_CACHEDATA_SHIFT - reg [$clog2(INSNS_PER_WORD)-1:0] shift; + reg [$clog2(INSNS_PER_WORD)-1:0] ashift; + // Verilator lint_off WIDTH always @(*) - shift = (fc_pc - f_cache_addr) >> $clog2(DATA_WIDTH/8); + ashift = (fc_pc - f_cache_addr) >> INSN_LSB; + // Verilator lint_on WIDTH always @(*) - f_cache_subdata = f_cache_data >> (shift * DATA_WIDTH); + f_cache_subdata = f_cache_data >> (ashift * INSN_WIDTH); always @(*) - f_fifo_subdata = fifo_data >> (shift * DATA_WIDTH); + f_fifo_subdata = fifo_data >> (ashift * INSN_WIDTH); end always @(*) @@ -976,7 +1043,7 @@ module axilfetch #( always @(*) if (f_cache_check && !o_illegal) begin - assert(f_cache_subdata[DATA_WIDTH-1:0] == fc_insn); + assert(f_cache_subdata[INSN_WIDTH-1:0] == fc_insn); assert(f_cache_illegal == fc_illegal); end @@ -997,7 +1064,7 @@ module axilfetch #( always @(*) if (f_cache_assume) begin - assume(f_fifo_subdata[DATA_WIDTH-1:0] == fc_insn); + assume(f_fifo_subdata[INSN_WIDTH-1:0] == fc_insn); assume(fifo_data[C_AXI_DATA_WIDTH] == fc_illegal); end // }}} @@ -1005,14 +1072,15 @@ module axilfetch #( // // Check the final output word - // + // This checks all instruction positions within that word always @(*) - if ((out_fill > 0) && (fc_pc[AW-1:AXILLSB] == f_out_addr[AW-1:AXILLSB]) - &&(fc_pc >= f_subout_addr)) + if ((out_fill > 0) + && (fc_pc[AW-1:AXILLSB] == f_out_addr[AW-1:AXILLSB])) begin if (fc_illegal) + begin assert(o_illegal); - else if (!o_illegal) + end else if (!o_illegal && fc_pc >= f_subout_addr) assert(f_out_data == fc_insn); end @@ -1024,9 +1092,11 @@ module axilfetch #( if (pending_new_pc) assert(o_pc == pending_pc); + // Verilator lint_off WIDTH always @(*) if (flush_request) assert(flushcount == faxil_outstanding + 1); + // Verilator lint_on WIDTH always @(*) if (flushing) @@ -1035,7 +1105,7 @@ module axilfetch #( always @(*) if (flush_request && !i_cpu_reset && !i_new_pc && !i_clear_cache) begin - assert(f_out_addr[C_AXI_ADDR_WIDTH-1:AXILLSB] == pending_pc[C_AXI_ADDR_WIDTH-1:AXILLSB]); + assert(f_out_addr[AW-1:AXILLSB] == pending_pc[AW-1:AXILLSB]); assert(o_pc == pending_pc); end `endif @@ -1047,8 +1117,10 @@ module axilfetch #( //////////////////////////////////////////////////////////////////////// // // - reg [3:0] cvr_returns; + // Verilator lint_off UNDRIVEN (* anyconst *) reg cvr_always_ready; + // Verilator lint_on UNDRIVEN + reg [3:0] cvr_returns; always @(*) if (cvr_always_ready) @@ -1068,6 +1140,14 @@ module axilfetch #( cover(cvr_returns == 4'b0110 && cvr_always_ready); end // }}} + + // Make Verilator happy + // {{{ + // Verilator lint_off UNUSED + wire unused_formal; + assign unused_formal = &{ 1'b0, f_ret_addr[AXILLSB-1:0] }; + // Verilator lint_on UNUSED + // }}} `endif // }}} endmodule diff --git a/rtl/cpu/axilops.v b/rtl/cpu/axilops.v index 56e5916..0ff4204 100644 --- a/rtl/cpu/axilops.v +++ b/rtl/cpu/axilops.v @@ -17,7 +17,7 @@ // Copyright (C) 2020-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -340,23 +340,38 @@ module axilops #( // shifted_wstrb_* // {{{ - always @(*) + generate if (SWAP_WSTRB) + begin : BIG_ENDIAN_WSTRB + always @(*) + shifted_wstrb_word = { 4'b1111, {(2*DW/8-4){1'b0}} } + >> i_addr[AXILSB-1:0]; + + always @(*) + shifted_wstrb_halfword = { 2'b11, {(2*DW/8-2){1'b0}} } + >> i_addr[AXILSB-1:0]; + + always @(*) + shifted_wstrb_byte = { 1'b1, {(2*DW/8-1){1'b0}} } + >> i_addr[AXILSB-1:0]; + end else begin : NORMAL_SHIFTED_WSTRB + always @(*) shifted_wstrb_word = { {(2*DW/8-4){1'b0}}, 4'b1111} << i_addr[AXILSB-1:0]; - always @(*) + always @(*) shifted_wstrb_halfword = { {(2*DW/8-4){1'b0}}, 4'b0011} << i_addr[AXILSB-1:0]; - always @(*) + always @(*) shifted_wstrb_byte = { {(2*DW/8-4){1'b0}}, 4'b0001} << i_addr[AXILSB-1:0]; + end endgenerate // }}} // Swapping WSTRB bits // {{{ - generate if (SWAP_WSTRB) - begin : SWAPPING_WSTRB + generate if (SWAP_ENDIANNESS) + begin : SWAPPING_ENDIANNESS // {{{ genvar gw, gb; @@ -393,11 +408,7 @@ module axilops #( // wdata, wstrb // {{{ always @(*) - begin swapaddr = i_addr[AXILSB-1:0]; - if (SWAP_WSTRB) - swapaddr[1:0] = 3 - i_addr[1:0]; - end initial axi_wdata = 0; initial axi_wstrb = 0; @@ -418,25 +429,49 @@ module axilops #( end else if (i_stb) begin // {{{ - casez(i_op[2:1]) - 2'b10: { next_wdata, axi_wdata } - <= { {(2*C_AXI_DATA_WIDTH-16){1'b0}}, - i_data[15:0] } << (8*swapaddr); - 2'b11: { next_wdata, axi_wdata } - <= { {(2*C_AXI_DATA_WIDTH-8){1'b0}}, - i_data[7:0] } << (8*swapaddr); - default: { next_wdata, axi_wdata } - <= { {(2*C_AXI_DATA_WIDTH-32){1'b0}}, - i_data } << (8*swapaddr); - endcase + if (SWAP_WSTRB) + begin + casez(i_op[2:1]) + 2'b10: { axi_wdata, next_wdata } + <= { i_data[15:0], {(2*C_AXI_DATA_WIDTH-16){1'b0}} } + >> (8*swapaddr); + 2'b11: { axi_wdata, next_wdata } + <= { i_data[7:0], {(2*C_AXI_DATA_WIDTH-8){1'b0}} } + >> (8*swapaddr); + default: { axi_wdata, next_wdata } + <= { i_data, {(2*C_AXI_DATA_WIDTH-32){1'b0}} } + >> (8*swapaddr); + endcase + end else begin + casez(i_op[2:1]) + 2'b10: { next_wdata, axi_wdata } + <= { {(2*C_AXI_DATA_WIDTH-16){1'b0}}, + i_data[15:0] } << (8*swapaddr); + 2'b11: { next_wdata, axi_wdata } + <= { {(2*C_AXI_DATA_WIDTH-8){1'b0}}, + i_data[7:0] } << (8*swapaddr); + default: { next_wdata, axi_wdata } + <= { {(2*C_AXI_DATA_WIDTH-32){1'b0}}, + i_data } << (8*swapaddr); + endcase + end // next_wstrb, axi_wstrb // {{{ - casez(i_op[2:1]) - 2'b0?: { next_wstrb, axi_wstrb } <= swapped_wstrb_word; - 2'b10: { next_wstrb, axi_wstrb } <= swapped_wstrb_halfword; - 2'b11: { next_wstrb, axi_wstrb } <= swapped_wstrb_byte; - endcase + if (SWAP_WSTRB) + begin + casez(i_op[2:1]) + 2'b0?: { axi_wstrb, next_wstrb } <= swapped_wstrb_word; + 2'b10: { axi_wstrb, next_wstrb } <= swapped_wstrb_halfword; + 2'b11: { axi_wstrb, next_wstrb } <= swapped_wstrb_byte; + endcase + end else begin + casez(i_op[2:1]) + 2'b0?: { next_wstrb, axi_wstrb } <= swapped_wstrb_word; + 2'b10: { next_wstrb, axi_wstrb } <= swapped_wstrb_halfword; + 2'b11: { next_wstrb, axi_wstrb } <= swapped_wstrb_byte; + endcase + end // }}} r_op <= { i_op[2:1] , i_addr[AXILSB-1:0] }; @@ -515,7 +550,9 @@ module axilops #( // w_misalignment_err // {{{ always @(*) + begin w_misalignment_err = OPT_ALIGNMENT_ERR && w_misaligned; + end // }}} // misaligned_[aw_|]request, pending_err, misaligned_response_pending @@ -592,6 +629,8 @@ module axilops #( else if (i_stb && !o_err && !i_cpu_reset) r_misaligned_read <= w_misaligned && !i_op[0] && !w_misalignment_err; + else if (M_AXI_RVALID) + r_misaligned_read <= (misaligned_response_pending); assign misaligned_read = r_misaligned_read; // }}} @@ -682,12 +721,35 @@ module axilops #( // tool knows we want a shift of the full 2*DW width. always @(*) begin - if (misaligned_read && !OPT_ALIGNMENT_ERR) - pre_result = { endian_swapped_rdata, last_result } - >> (8*r_op[AXILSB-1:0]); - else - pre_result = { {(DW){1'b0}}, endian_swapped_rdata } + if (SWAP_WSTRB) + begin + if (misaligned_read && !OPT_ALIGNMENT_ERR) + pre_result={ last_result, endian_swapped_rdata } + << (8*r_op[AXILSB-1:0]); + else + pre_result = { endian_swapped_rdata, {(DW){1'b0}} } + << (8*r_op[AXILSB-1:0]); + + casez(r_op[AXILSB +: 2]) + 2'b10: pre_result = { 16'h0, + pre_result[(2*DW)-1:(2*DW)-16], + {(DW){1'b0}} }; + 2'b11: pre_result = { 24'h0, + pre_result[(2*DW)-1:(2*DW)-8], + {(DW){1'b0}} }; + default: begin end + endcase + + pre_result[31:0] = pre_result[(2*DW-1):(2*DW-32)]; + + end else begin + if (misaligned_read && !OPT_ALIGNMENT_ERR) + pre_result={ endian_swapped_rdata, last_result } + >> (8*r_op[AXILSB-1:0]); + else + pre_result = { {(DW){1'b0}}, endian_swapped_rdata } >> (8*r_op[AXILSB-1:0]); + end if (OPT_LOWPOWER && (!M_AXI_RVALID || M_AXI_RRESP[1])) pre_result = 0; @@ -710,7 +772,7 @@ module axilops #( if (OPT_ALIGNMENT_ERR) last_result <= 0; - o_result <= pre_result; + o_result <= pre_result[31:0]; if (OPT_SIGN_EXTEND) begin @@ -743,7 +805,7 @@ module axilops #( // verilator lint_off UNUSED wire unused; assign unused = &{ 1'b0, i_lock, M_AXI_RRESP[0], M_AXI_BRESP[0], - pre_result[2*C_AXI_DATA_WIDTH:32] }; + pre_result[2*C_AXI_DATA_WIDTH-1:32] }; // verilator lint_on UNUSED // }}} //////////////////////////////////////////////////////////////////////////////// @@ -1050,22 +1112,26 @@ module axilops #( if (f_past_valid) begin if ($past(i_cpu_reset || r_flushing || o_err)) + begin `ASSERT(!o_err); - else if ($past(M_AXI_BVALID && M_AXI_BRESP[1])) + end else if ($past(M_AXI_BVALID && M_AXI_BRESP[1])) begin if ($past(misaligned_response_pending)) + begin `ASSERT((!o_err && pending_err) || r_flushing); - else + end else `ASSERT(o_err); end else if ($past(M_AXI_RVALID && M_AXI_RRESP[1])) begin if ($past(misaligned_response_pending)) + begin `ASSERT((!o_err && pending_err) || r_flushing); - else + end else `ASSERT(o_err); end else if (OPT_ALIGNMENT_ERR && $past(i_stb && w_misaligned)) + begin `ASSERT(o_err); - else if (!$past(pending_err)) + end else if (!$past(pending_err)) `ASSERT(!o_err); //else if ($past(misaligned)) //`ASSERT(o_err); @@ -1193,8 +1259,9 @@ module axilops #( always @(*) if (f_pc) + begin assert(o_wreg[3:1] == 3'h7 || (OPT_LOWPOWER && o_err)); - else if (o_rdbusy) + end else if (o_rdbusy) assert(o_wreg[3:1] != 3'h7); always @(*) diff --git a/rtl/cpu/axilperiphs.v b/rtl/cpu/axilperiphs.v index 04494cc..7c5ea2a 100644 --- a/rtl/cpu/axilperiphs.v +++ b/rtl/cpu/axilperiphs.v @@ -52,11 +52,12 @@ module axilperiphs #( // Size of the AXI-lite bus. These are fixed, since 1) AXI-lite // is fixed at a width of 32-bits by Xilinx def'n, and 2) since // we only ever have 4 configuration words. - parameter C_AXI_ADDR_WIDTH = 5, + parameter C_AXI_ADDR_WIDTH = 6, localparam C_AXI_DATA_WIDTH = 32, parameter [0:0] OPT_SKIDBUFFER = 1'b1, parameter [0:0] OPT_LOWPOWER = 0, parameter EXTERNAL_INTERRUPTS = 1, + parameter [0:0] OPT_COUNTERS = 1, localparam ADDRLSB = $clog2(C_AXI_DATA_WIDTH)-3 // }}} ) ( @@ -90,7 +91,11 @@ module axilperiphs #( output wire [1:0] S_AXI_RRESP, // }}} input wire i_cpu_reset, - input wire i_cmd_halt, + input wire i_cpu_halted, + input wire i_cpu_gie, + input wire i_cpu_pfstall, + input wire i_cpu_opstall, + input wire i_cpu_icount, input wire [EXTERNAL_INTERRUPTS-1:0] i_ivec, output wire o_interrupt, output wire o_watchdog_reset @@ -100,10 +105,30 @@ module axilperiphs #( //////////////////////////////////////////////////////////////////////// // // Register/wire signal declarations - // + // {{{ //////////////////////////////////////////////////////////////////////// // - // {{{ + // + localparam [3:0] ADR_PIC = 4'h0, + ADR_WATCHDOG = 4'h1, + ADR_APIC = 4'h2; + // No bus watchdog + + localparam [3:0] ADR_TIMERA = 4'h4, + ADR_TIMERB = 4'h5, + ADR_TIMERC = 4'h6, + ADR_JIFFIES= 4'h7; + + localparam [3:0] ADR_MCLOCKS = 4'h8, + ADR_MOPSTALL = 4'h9, + ADR_MPFSTALL = 4'ha, + ADR_MICOUNT = 4'hb; + + localparam [3:0] ADR_UCLOCKS = 4'hc, + ADR_UOPSTALL = 4'hd, + ADR_UPFSTALL = 4'he, + ADR_UICOUNT = 4'hf; + wire i_reset = !S_AXI_ARESETN; wire axil_write_ready; @@ -127,7 +152,6 @@ module axilperiphs #( wire apic_stall, apic_ack, apic_int; wire [31:0] apic_data; - wire tmrb_stall, tmrb_ack, tmrb_int; wire tmra_stall, tmra_ack, tmra_int; wire [31:0] tmra_data; @@ -140,14 +164,13 @@ module axilperiphs #( wire jif_stall, jif_ack, jif_int; wire [31:0] jif_data; // }}} - //////////////////////////////////////////////////////////////////////// // // AXI-lite signaling - // + // {{{ //////////////////////////////////////////////////////////////////////// // - // {{{ + // // // Write signaling @@ -273,26 +296,35 @@ module axilperiphs #( //////////////////////////////////////////////////////////////////////// // // AXI-lite register logic + // {{{ + //////////////////////////////////////////////////////////////////////// + // // + //////////////////////////////////////////////////////////////////////// // + // Interrupt handling // {{{ - // wire aint, bint, cint, jifint, altint; - + //////////////////////////////////////////////////////////////////////// + // + // reg [30:0] int_vector; + // Generate the interrupt vector + // {{{ generate if (EXTERNAL_INTERRUPTS == 0) - begin - + begin : NO_EXTERNAL_INTERRUPTS + // {{{ always @(*) begin int_vector = 0; int_vector[5:0] = { apic_int, tmra_int, tmrb_int, tmrc_int, jif_int, 1'b0 }; end - + // }}} end else if (EXTERNAL_INTERRUPTS == 1) - begin + begin : SINGLE_EXTERNAL_INTERRUPT + // {{{ always @(*) begin @@ -300,9 +332,9 @@ module axilperiphs #( int_vector[5:0] = { apic_int, tmra_int, tmrb_int, tmrc_int, jif_int, i_ivec[0] }; end - - end else begin - + // }}} + end else begin : MANY_EXTERNAL_INTERRUPTS + // {{{ always @(*) begin int_vector = 0; @@ -311,41 +343,54 @@ module axilperiphs #( int_vector[EXTERNAL_INTERRUPTS+5-1:6] = i_ivec[EXTERNAL_INTERRUPTS-1:1]; end - + // }}} end endgenerate + // }}} icontrol #(.IUSED(15)) pic( + // {{{ .i_clk(S_AXI_ACLK), .i_reset(i_cpu_reset), .i_wb_cyc(axil_write_ready), - .i_wb_stb(axil_write_ready && awskd_addr == 3'b000), + .i_wb_stb(axil_write_ready && awskd_addr == ADR_PIC), .i_wb_we(1'b1), .i_wb_data(wskd_data), .i_wb_sel(wskd_strb), .o_wb_stall(pic_stall), .o_wb_ack(pic_ack),.o_wb_data(pic_data), - .i_brd_ints(int_vector[14:0]), .o_interrupt(o_interrupt)); + .i_brd_ints(int_vector[14:0]), .o_interrupt(o_interrupt) + // }}} + ); ziptimer #(32,31,0) watchdog( + // {{{ .i_clk(S_AXI_ACLK), .i_reset(i_cpu_reset), - .i_ce(!i_cmd_halt), .i_wb_cyc(1'b1), - .i_wb_stb(axil_write_ready && awskd_addr == 3'b001), - .i_wb_we(1'b1), .i_wb_data(wskd_data), // .i_wb_sel(wskd_strb), + .i_ce(!i_cpu_halted), .i_wb_cyc(1'b1), + .i_wb_stb(axil_write_ready && awskd_addr == ADR_WATCHDOG), + .i_wb_we(1'b1), .i_wb_data(wskd_data), .i_wb_sel(wskd_strb), .o_wb_stall(wdog_stall), .o_wb_ack(wdog_ack), .o_wb_data(wdog_data), - .o_int(o_watchdog_reset)); + .o_int(o_watchdog_reset) + // }}} + ); + // APIC + // {{{ generate if (EXTERNAL_INTERRUPTS > 15) begin : APIC icontrol #(.IUSED(15)) - apic( .i_clk(S_AXI_ACLK), .i_reset(i_cpu_reset), + apic( + // {{{ + .i_clk(S_AXI_ACLK), .i_reset(i_cpu_reset), .i_wb_cyc(axil_write_ready), - .i_wb_stb(axil_write_ready && awskd_addr == 3'b000), + .i_wb_stb(axil_write_ready && awskd_addr == ADR_APIC), .i_wb_we(1'b1), .i_wb_data(wskd_data), .i_wb_sel(wskd_strb), .o_wb_stall(apic_stall), .o_wb_ack(apic_ack), .o_wb_data(apic_data), .i_brd_ints(int_vector[30:15]), - .o_interrupt(o_interrupt)); + .o_interrupt(o_interrupt) + // }}} + ); end else begin @@ -355,61 +400,236 @@ module axilperiphs #( assign apic_int = 0; end endgenerate - + // }}} + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Timers + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // ziptimer timer_a( + // {{{ .i_clk(S_AXI_ACLK), .i_reset(i_cpu_reset), - .i_ce(!i_cmd_halt), .i_wb_cyc(1'b1), - .i_wb_stb(axil_write_ready && awskd_addr == 3'b100), - .i_wb_we(1'b1), .i_wb_data(wskd_data), .o_wb_stall(tmra_stall), - .o_wb_ack(tmra_ack), .o_wb_data(tmra_data), .o_int(tmra_int)); + .i_ce(!i_cpu_halted), .i_wb_cyc(1'b1), + .i_wb_stb(axil_write_ready && awskd_addr == ADR_TIMERA), + .i_wb_we(1'b1), .i_wb_data(wskd_data), .i_wb_sel(wskd_strb), + .o_wb_stall(tmra_stall), + .o_wb_ack(tmra_ack), .o_wb_data(tmra_data), .o_int(tmra_int) + // }}} + ); ziptimer timer_b( + // {{{ .i_clk(S_AXI_ACLK), .i_reset(i_cpu_reset), - .i_ce(!i_cmd_halt), .i_wb_cyc(1'b1), - .i_wb_stb(axil_write_ready && awskd_addr == 3'b101), - .i_wb_we(1'b1), .i_wb_data(wskd_data), .o_wb_stall(tmrb_stall), - .o_wb_ack(tmrb_ack), .o_wb_data(tmrb_data), .o_int(tmrb_int)); + .i_ce(!i_cpu_halted), .i_wb_cyc(1'b1), + .i_wb_stb(axil_write_ready && awskd_addr == ADR_TIMERB), + .i_wb_we(1'b1), .i_wb_data(wskd_data), .i_wb_sel(wskd_strb), + .o_wb_stall(tmrb_stall), + .o_wb_ack(tmrb_ack), .o_wb_data(tmrb_data), .o_int(tmrb_int) + // }}} + ); ziptimer timer_c( + // {{{ .i_clk(S_AXI_ACLK), .i_reset(i_cpu_reset), - .i_ce(!i_cmd_halt), .i_wb_cyc(1'b1), - .i_wb_stb(axil_write_ready && awskd_addr == 3'b110), - .i_wb_we(1'b1), .i_wb_data(wskd_data), .o_wb_stall(tmrc_stall), - .o_wb_ack(tmrc_ack), .o_wb_data(tmrc_data), .o_int(tmrc_int)); + .i_ce(!i_cpu_halted), .i_wb_cyc(1'b1), + .i_wb_stb(axil_write_ready && awskd_addr == ADR_TIMERC), + .i_wb_we(1'b1), .i_wb_data(wskd_data), .i_wb_sel(wskd_strb), + .o_wb_stall(tmrc_stall), + .o_wb_ack(tmrc_ack), .o_wb_data(tmrc_data), .o_int(tmrc_int) + // }}} + ); zipjiffies jiffies( + // {{{ .i_clk(S_AXI_ACLK), .i_reset(i_cpu_reset), - .i_ce(!i_cmd_halt), .i_wb_cyc(1'b1), - .i_wb_stb(axil_write_ready && awskd_addr == 3'b111), - .i_wb_we(1'b1), .i_wb_data(wskd_data), .o_wb_stall(jif_stall), - .o_wb_ack(jif_ack), .o_wb_data(jif_data), .o_int(jif_int)); + .i_ce(!i_cpu_halted), .i_wb_cyc(1'b1), + .i_wb_stb(axil_write_ready && awskd_addr == ADR_JIFFIES), + .i_wb_we(1'b1), .i_wb_data(wskd_data), .i_wb_sel(wskd_strb), + .o_wb_stall(jif_stall), + .o_wb_ack(jif_ack), .o_wb_data(jif_data), .o_int(jif_int) + // }}} + ); + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Optional performance counters + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + wire [31:0] mtask, mopstall, mpfstall, micount; + wire [31:0] utask, uopstall, upfstall, uicount; + + generate if (OPT_COUNTERS) + begin : ACCOUNTING_COUNTERS + // {{{ + reg [31:0] r_mtask, r_mopstall, r_mpfstall, r_micount; + reg [31:0] r_utask, r_uopstall, r_upfstall, r_uicount; + + initial { r_mtask, r_mopstall, r_mpfstall, r_micount } = 0; + always @(posedge S_AXI_ACLK) + if (i_cpu_reset) + { r_mtask, r_mopstall, r_mpfstall, r_micount } <= 0; + else begin + if (!i_cpu_halted) + r_mtask <= r_mtask + 1; + if (i_cpu_opstall) + r_mopstall <= mopstall + 1; + if (i_cpu_pfstall) + r_mpfstall <= r_mpfstall + 1; + if (i_cpu_icount) + r_micount <= r_micount + 1; + + if (axil_write_ready) + case(awskd_addr) + ADR_MCLOCKS: begin + // {{{ + if(wskd_strb[0]) r_mtask[ 7: 0]<=wskd_data[ 7: 0]; + if(wskd_strb[1]) r_mtask[15: 8]<=wskd_data[15: 8]; + if(wskd_strb[2]) r_mtask[23:16]<=wskd_data[23:16]; + if(wskd_strb[3]) r_mtask[31:24]<=wskd_data[31:24]; + end + // }}} + ADR_MOPSTALL: begin + // {{{ + if(wskd_strb[0]) r_mopstall[ 7: 0]<=wskd_data[ 7: 0]; + if(wskd_strb[1]) r_mopstall[15: 8]<=wskd_data[15: 8]; + if(wskd_strb[2]) r_mopstall[23:16]<=wskd_data[23:16]; + if(wskd_strb[3]) r_mopstall[31:24]<=wskd_data[31:24]; + end + // }}} + ADR_MPFSTALL: begin + // {{{ + if(wskd_strb[0]) r_mpfstall[ 7: 0]<=wskd_data[ 7: 0]; + if(wskd_strb[1]) r_mpfstall[15: 8]<=wskd_data[15: 8]; + if(wskd_strb[2]) r_mpfstall[23:16]<=wskd_data[23:16]; + if(wskd_strb[3]) r_mpfstall[31:24]<=wskd_data[31:24]; + end + // }}} + ADR_MICOUNT: begin + // {{{ + if(wskd_strb[0]) r_micount[ 7: 0]<=wskd_data[ 7: 0]; + if(wskd_strb[1]) r_micount[15: 8]<=wskd_data[15: 8]; + if(wskd_strb[2]) r_micount[23:16]<=wskd_data[23:16]; + if(wskd_strb[3]) r_micount[31:24]<=wskd_data[31:24]; + end + // }}} + default: begin end + endcase + end + + initial { r_utask, r_uopstall, r_upfstall, r_uicount } = 0; + always @(posedge S_AXI_ACLK) + if (i_cpu_reset) + { r_utask, r_uopstall, r_upfstall, r_uicount } <= 0; + else begin + if (!i_cpu_halted && i_cpu_gie) + r_utask <= r_utask + 1; + if (i_cpu_opstall && i_cpu_gie) + r_uopstall <= r_uopstall + 1; + if (i_cpu_pfstall && i_cpu_gie) + r_upfstall <= r_upfstall + 1; + if (i_cpu_icount && i_cpu_gie) + r_uicount <= r_uicount + 1; + + if (axil_write_ready) + case(awskd_addr) + ADR_UCLOCKS: begin + // {{{ + if(wskd_strb[0]) r_utask[ 7: 0]<=wskd_data[ 7: 0]; + if(wskd_strb[1]) r_utask[15: 8]<=wskd_data[15: 8]; + if(wskd_strb[2]) r_utask[23:16]<=wskd_data[23:16]; + if(wskd_strb[3]) r_utask[31:24]<=wskd_data[31:24]; + end + // }}} + ADR_UOPSTALL: begin + // {{{ + if(wskd_strb[0]) r_uopstall[ 7: 0]<=wskd_data[ 7: 0]; + if(wskd_strb[1]) r_uopstall[15: 8]<=wskd_data[15: 8]; + if(wskd_strb[2]) r_uopstall[23:16]<=wskd_data[23:16]; + if(wskd_strb[3]) r_uopstall[31:24]<=wskd_data[31:24]; + end + // }}} + ADR_UPFSTALL: begin + // {{{ + if(wskd_strb[0]) r_upfstall[ 7: 0]<=wskd_data[ 7: 0]; + if(wskd_strb[1]) r_upfstall[15: 8]<=wskd_data[15: 8]; + if(wskd_strb[2]) r_upfstall[23:16]<=wskd_data[23:16]; + if(wskd_strb[3]) r_upfstall[31:24]<=wskd_data[31:24]; + end + // }}} + ADR_UICOUNT: begin + // {{{ + if(wskd_strb[0]) r_uicount[ 7: 0]<=wskd_data[ 7: 0]; + if(wskd_strb[1]) r_uicount[15: 8]<=wskd_data[15: 8]; + if(wskd_strb[2]) r_uicount[23:16]<=wskd_data[23:16]; + if(wskd_strb[3]) r_uicount[31:24]<=wskd_data[31:24]; + end + // }}} + default: begin end + endcase + end + + assign { mtask, mopstall, mpfstall, micount } = + { r_mtask, r_mopstall, r_mpfstall, r_micount }; + assign { utask, uopstall, upfstall, uicount } = + { r_utask, r_uopstall, r_upfstall, r_uicount }; + // }}} + end else begin : NO_ACCOUNTING + + assign { mtask, mopstall, mpfstall, micount } = 0; + assign { utask, uopstall, upfstall, uicount } = 0; + + end endgenerate + // }}} + + // axil_read_data + // {{{ initial axil_read_data = 0; always @(posedge S_AXI_ACLK) if (OPT_LOWPOWER && !S_AXI_ARESETN) axil_read_data <= 0; else if (!S_AXI_RVALID || S_AXI_RREADY) begin - case(arskd_addr) - 3'b000: axil_read_data <= pic_data; - 3'b001: axil_read_data <= wdog_data; + axil_read_data <= 0; + case({ (OPT_COUNTERS & arskd_addr[3]), arskd_addr[2:0] }) + ADR_PIC: axil_read_data <= pic_data; + ADR_WATCHDOG: axil_read_data <= wdog_data; // 3'b10: axil_read_data <= watchdog_data; - 3'b011: axil_read_data <= apic_data; - 3'b100: axil_read_data <= tmra_data; - 3'b101: axil_read_data <= tmrb_data; - 3'b110: axil_read_data <= tmrc_data; - 3'b111: axil_read_data <= jif_data; + ADR_APIC: axil_read_data <= apic_data; + ADR_TIMERA: axil_read_data <= tmra_data; + ADR_TIMERB: axil_read_data <= tmrb_data; + ADR_TIMERC: axil_read_data <= tmrc_data; + ADR_JIFFIES: axil_read_data <= jif_data; + // Supervisor counters + ADR_MCLOCKS: axil_read_data <= mtask; + ADR_MOPSTALL: axil_read_data <= mopstall; + ADR_MPFSTALL: axil_read_data <= mpfstall; + ADR_MICOUNT: axil_read_data <= micount; + // User counters + ADR_UCLOCKS: axil_read_data <= utask; + ADR_UOPSTALL: axil_read_data <= uopstall; + ADR_UPFSTALL: axil_read_data <= upfstall; + ADR_UICOUNT: axil_read_data <= uicount; default: axil_read_data <= 0; endcase if (OPT_LOWPOWER && !axil_read_ready) axil_read_data <= 0; end + // }}} + // apply_wstrb + // {{{ function [C_AXI_DATA_WIDTH-1:0] apply_wstrb; input [C_AXI_DATA_WIDTH-1:0] prior_data; input [C_AXI_DATA_WIDTH-1:0] new_data; @@ -424,6 +644,10 @@ module axilperiphs #( endfunction // }}} + // }}} + + // Make Verilator happy + // {{{ // Verilator lint_off UNUSED wire unused; assign unused = &{ 1'b0, S_AXI_AWPROT, S_AXI_ARPROT, @@ -436,6 +660,7 @@ module axilperiphs #( tmra_ack, tmrb_ack, tmrc_ack, jif_ack }; // Verilator lint_on UNUSED // }}} + // }}} `ifdef FORMAL //////////////////////////////////////////////////////////////////////// // @@ -478,7 +703,6 @@ module axilperiphs #( .i_axi_awvalid(S_AXI_AWVALID), .i_axi_awready(S_AXI_AWREADY), .i_axi_awaddr( S_AXI_AWADDR), - .i_axi_awcache(4'h0), .i_axi_awprot( S_AXI_AWPROT), // .i_axi_wvalid(S_AXI_WVALID), @@ -493,7 +717,6 @@ module axilperiphs #( .i_axi_arvalid(S_AXI_ARVALID), .i_axi_arready(S_AXI_ARREADY), .i_axi_araddr( S_AXI_ARADDR), - .i_axi_arcache(4'h0), .i_axi_arprot( S_AXI_ARPROT), // .i_axi_rvalid(S_AXI_RVALID), diff --git a/rtl/cpu/axilpipe.v b/rtl/cpu/axilpipe.v index 6a1d042..9c82ed8 100644 --- a/rtl/cpu/axilpipe.v +++ b/rtl/cpu/axilpipe.v @@ -17,7 +17,7 @@ // Copyright (C) 2020-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -52,8 +52,6 @@ module axilpipe #( // CPU. Specifically, we have to be able to unroll and re-do // the load instruction on any atomic access failure. For that // reason, we'll ignore the lock request initially. - // - // parameter [0:0] IMPLEMENT_LOCK=1'b1, parameter [0:0] OPT_ALIGNMENT_ERR = 1'b1, // Verilator lint_off UNUSED // This *should* be used -- need to rewrite so that it is @@ -121,7 +119,7 @@ module axilpipe #( // Declarations // {{{ - localparam AXILLSB = $clog2(C_AXI_ADDR_WIDTH/8); + localparam AXILLSB = $clog2(C_AXI_DATA_WIDTH/8); localparam LGPIPE = 4; localparam FIFO_WIDTH = AXILLSB+1+2+5 + 1; @@ -261,7 +259,7 @@ module axilpipe #( reg writing; always @(posedge S_AXI_ACLK) - if (!o_busy) + if (i_stb && !o_busy) writing <= i_op[0]; always @(*) @@ -306,8 +304,9 @@ module axilpipe #( `ifdef FORMAL always @(*) if (beats_outstanding + ((M_AXI_AWVALID || M_AXI_WVALID || M_AXI_ARVALID) ? 1:0) >= (1<= (1< 0)); if (!r_flushing) + begin assert(!flush_request); - else + end else assert(flush_request == (M_AXI_AWVALID || M_AXI_WVALID || M_AXI_ARVALID)); if (r_flushing && !flush_request) begin @@ -547,13 +550,15 @@ module axilpipe #( end if (flush_request) + begin assert(flushcount == beats_outstanding + 1 + ((misaligned_request || misaligned_aw_request) ? 1:0)); // else if (faxil_rd_outstanding > 0 || M_AXI_ARVALID) - else if (r_flushing) + end else if (r_flushing) + begin assert(beats_outstanding == flushcount); - else + end else assert(beats_outstanding >= flushcount); end `endif @@ -663,8 +668,8 @@ module axilpipe #( // }}} end else begin // {{{ - { M_AXI_WDATA, next_wdata } <= wide_wdata; - { M_AXI_WSTRB, next_wstrb } <= wide_wstrb; + { next_wdata, M_AXI_WDATA } <= wide_wdata; + { next_wstrb, M_AXI_WSTRB } <= wide_wstrb; // }}} end @@ -786,10 +791,11 @@ module axilpipe #( always @(posedge S_AXI_ACLK) if ((M_AXI_ARVALID && M_AXI_ARREADY) || (M_AXI_WVALID && M_AXI_WREADY)) fifo_data[wraddr[LGPIPE-1:0]] <= { M_AXI_ARVALID, ar_oreg,ar_op, - misaligned_request, M_AXI_ARADDR[AXILLSB-1:0] }; + misaligned_request, adr_lsb }; always @(*) fifo_read_data = fifo_data[rdaddr[LGPIPE-1:0]]; + assign { fifo_read_op, fifo_return_reg, fifo_op, fifo_misaligned, fifo_lsb } = fifo_read_data; // }}} @@ -827,11 +833,38 @@ module axilpipe #( // wide_return // {{{ always @(*) - if (fifo_misaligned && !OPT_ALIGNMENT_ERR) - wide_return = { M_AXI_RDATA, misdata } >> (8*fifo_lsb); - else - wide_return = { {(C_AXI_DATA_WIDTH){1'b0}}, M_AXI_RDATA } + begin + if (SWAP_WSTRB) + begin + if (fifo_misaligned && !OPT_ALIGNMENT_ERR) + wide_return = { misdata, M_AXI_RDATA } + << (8*fifo_lsb); + else + wide_return = { M_AXI_RDATA, {(DW){1'b0}} } + << (8*fifo_lsb); + + casez(fifo_op[1:0]) + 2'b10: wide_return = { {(16){1'b0}}, + wide_return[(2*DW)-1:(2*DW)-16], + {(2*DW-32){1'b0}} }; + 2'b11: wide_return = { {(24){1'b0}}, + wide_return[(2*DW)-1:(2*DW)-8], + {(2*DW-32){1'b0}} }; + default: begin end + endcase + + wide_return[31:0] = wide_return[(2*DW-1):(2*DW-32)]; + end else begin + if (fifo_misaligned && !OPT_ALIGNMENT_ERR) + wide_return = { M_AXI_RDATA, misdata } >> (8*fifo_lsb); + else + wide_return = { {(C_AXI_DATA_WIDTH){1'b0}}, M_AXI_RDATA } >> (8*fifo_lsb); + end + + if (OPT_LOWPOWER && (!M_AXI_RVALID || M_AXI_RRESP[1])) + wide_return = 0; + end // }}} // misdata @@ -859,14 +892,14 @@ module axilpipe #( // {{{ case(fifo_op) 2'b10: o_result[31:16] <= {(16){wide_return[15]}}; - 2'b11: o_result[15: 8] <= {( 8){wide_return[ 7]}}; + 2'b11: o_result[31: 8] <= {(24){wide_return[ 7]}}; endcase // }}} end else if (fifo_op[1]) begin // {{{ if (fifo_op[0]) - o_result[15: 8] <= 0; + o_result[31: 8] <= 0; else o_result[31:16] <= 0; // }}} @@ -1070,8 +1103,9 @@ module axilpipe #( if (OPT_ALIGNMENT_ERR && !r_flushing && (faxil_rd_outstanding > 0 || M_AXI_ARVALID)) + begin assert(f_fifo_fill == faxil_rd_outstanding); - else if (OPT_ALIGNMENT_ERR && !r_flushing + end else if (OPT_ALIGNMENT_ERR && !r_flushing && (faxil_wr_outstanding > 0 || M_AXI_WVALID)) assert(f_fifo_fill == faxil_wr_outstanding); @@ -1106,14 +1140,18 @@ module axilpipe #( if (f_past_valid) begin if ($past(i_cpu_reset || r_flushing || o_err)) + begin `ASSERT(!o_err); - else if ($past(M_AXI_BVALID && M_AXI_BRESP[1])) + end else if ($past(M_AXI_BVALID && M_AXI_BRESP[1])) + begin `ASSERT(o_err); - else if ($past(M_AXI_RVALID && M_AXI_RRESP[1])) + end else if ($past(M_AXI_RVALID && M_AXI_RRESP[1])) + begin `ASSERT(o_err); - else if (OPT_ALIGNMENT_ERR && $past(i_stb && w_misaligned)) + end else if (OPT_ALIGNMENT_ERR && $past(i_stb && w_misaligned)) + begin `ASSERT(o_err); - else if (!$past(pending_err)) + end else if (!$past(pending_err)) `ASSERT(!o_err); end // }}} @@ -1257,11 +1295,11 @@ module axilpipe #( always @(posedge S_AXI_ACLK) if (f_wrfifo && wraddr == f_first_addr) - f_first_data <= { M_AXI_ARVALID, ar_oreg, ar_op, misaligned_request, M_AXI_ARADDR[AXILLSB-1:0] }; + f_first_data <= { M_AXI_ARVALID, ar_oreg, ar_op, misaligned_request, adr_lsb }; always @(posedge S_AXI_ACLK) if (f_wrfifo && wraddr == f_next_addr) - f_next_data <= { M_AXI_ARVALID, ar_oreg, ar_op, misaligned_request, M_AXI_ARADDR[AXILLSB-1:0] }; + f_next_data <= { M_AXI_ARVALID, ar_oreg, ar_op, misaligned_request, adr_lsb }; // f_fsmfifo // {{{ @@ -1348,8 +1386,9 @@ module axilpipe #( if (!f_clrfifo && f_fifo_fill != 0) begin if ((M_AXI_ARVALID || (rdaddr != f_last_written))) + begin `ASSERT(f_this_misaligned || !cpu_read_cycle || !(&f_return_reg[3:1])); - else if (f_fifo_fill > 0 && !M_AXI_ARVALID) + end else if (f_fifo_fill > 0 && !M_AXI_ARVALID) `ASSERT(f_this_misaligned || !cpu_read_cycle || cpu_pc == (&f_return_reg[3:1])); if ((!f_first_in_fifo || rdaddr != f_first_addr) @@ -1357,10 +1396,12 @@ module axilpipe #( && cpu_read_cycle) begin if (M_AXI_ARVALID) // && (&ar_oreg[3:1])) + begin `ASSUME(!(&f_return_reg[3:1])); - else if (rdaddr != f_last_written) + end else if (rdaddr != f_last_written) + begin `ASSUME(!(&f_return_reg[3:1])); - else if (!M_AXI_ARVALID && !o_err) + end else if (!M_AXI_ARVALID && !o_err) `ASSUME(cpu_pc == (&f_return_reg[3:1])); // Not last written end @@ -1368,8 +1409,9 @@ module axilpipe #( begin if (!cpu_pc || M_AXI_ARVALID || (f_last_written != f_first_addr)) + begin `ASSERT(f_first_misaligned || !cpu_read_cycle || !(&f_first_return_reg[3:1])); - else if (!M_AXI_ARVALID && !o_err) + end else if (!M_AXI_ARVALID && !o_err) `ASSERT(&f_first_return_reg[3:1]); end @@ -1377,8 +1419,9 @@ module axilpipe #( begin if (!cpu_pc || M_AXI_ARVALID || (f_last_written != f_next_addr)) + begin `ASSERT(f_next_misaligned || !(&f_next_return_reg[3:1])); - else if (!M_AXI_ARVALID && !o_err) + end else if (!M_AXI_ARVALID && !o_err) `ASSERT(&f_next_return_reg[3:1]); end @@ -1420,8 +1463,9 @@ module axilpipe #( if (f_first_in_fifo && f_first_misaligned) begin if (f_next_in_fifo) + begin `ASSERT(!f_next_misaligned); - else begin + end else begin `ASSERT(!misaligned_request); `ASSERT(M_AXI_ARVALID || M_AXI_WVALID); end @@ -1431,8 +1475,9 @@ module axilpipe #( && (!f_first_in_fifo || rdaddr != f_first_addr)) begin if (f_fifo_fill > 1) + begin `BMC_ASSERT(!f_penu_misaligned); - else if (f_fifo_fill == 1) + end else if (f_fifo_fill == 1) `BMC_ASSERT(!misaligned_request); end // }}} @@ -1514,8 +1559,9 @@ module axilpipe #( // {{{ always @(*) if (M_AXI_WVALID || M_AXI_ARVALID) + begin assert(cpu_last_reg == ar_oreg); - else if (!f_clrfifo && f_fifo_fill > 0) + end else if (!f_clrfifo && f_fifo_fill > 0) begin if (f_first_in_fifo && f_first_addr == f_last_written) assert(f_first_return_reg == cpu_last_reg); @@ -1606,10 +1652,12 @@ module axilpipe #( always @(*) if (flush_request) + begin `ASSERT(cpu_outstanding == 0 || o_err); - else if (r_flushing) + end else if (r_flushing) + begin `ASSERT(o_err || cpu_outstanding == 0); - else if (OPT_ALIGNMENT_ERR) + end else if (OPT_ALIGNMENT_ERR) begin if (!o_err) `ASSERT(cpu_outstanding == (beats_outstanding - flushcount) @@ -1626,8 +1674,9 @@ module axilpipe #( if (!o_err && cpu_outstanding > 0) begin if (faxil_rd_outstanding > 0 || M_AXI_ARVALID || o_rdbusy) + begin assert(cpu_read_cycle); - else if (faxil_awr_outstanding > 0 || faxil_wr_outstanding > 0 + end else if (faxil_awr_outstanding > 0 || faxil_wr_outstanding > 0 || M_AXI_AWVALID || M_AXI_WVALID) assert(!cpu_read_cycle); end diff --git a/rtl/cpu/axiops.v b/rtl/cpu/axiops.v index 38fe90e..65dc3d3 100644 --- a/rtl/cpu/axiops.v +++ b/rtl/cpu/axiops.v @@ -15,7 +15,7 @@ // Copyright (C) 2020-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -43,7 +43,6 @@ module axiops #( parameter C_AXI_ADDR_WIDTH = 32, parameter C_AXI_DATA_WIDTH = 32, parameter C_AXI_ID_WIDTH = 1, - localparam ADDRESS_WIDTH=C_AXI_ADDR_WIDTH, parameter [((C_AXI_ID_WIDTH > 0)? C_AXI_ID_WIDTH:1)-1:0] AXI_ID = 0, // @@ -149,7 +148,7 @@ module axiops #( output wire [IW-1:0] M_AXI_AWID, output reg [AW-1:0] M_AXI_AWADDR, output wire [7:0] M_AXI_AWLEN, - output wire [2:0] M_AXI_AWSIZE, + output wire [2:0] M_AXI_AWSIZE, output wire [1:0] M_AXI_AWBURST, output wire M_AXI_AWLOCK, output wire [3:0] M_AXI_AWCACHE, @@ -174,7 +173,7 @@ module axiops #( output wire [IW-1:0] M_AXI_ARID, output reg [AW-1:0] M_AXI_ARADDR, output wire [7:0] M_AXI_ARLEN, - output wire [2:0] M_AXI_ARSIZE, + output wire [2:0] M_AXI_ARSIZE, output wire [1:0] M_AXI_ARBURST, output wire M_AXI_ARLOCK, output wire [3:0] M_AXI_ARCACHE, @@ -395,18 +394,28 @@ module axiops #( // {{{ reg [2:0] awsize; - initial awsize = 3'b010; + initial awsize = DSZ; always @(posedge i_clk) if (!S_AXI_ARESETN) - awsize <= 3'b010; + awsize <= DSZ; else if (!M_AXI_BREADY && !M_AXI_RREADY && (!OPT_LOWPOWER || i_stb)) begin casez(i_op[2:1]) - 2'b0?: awsize <= 3'b010; - 2'b10: awsize <= 3'b001; - 2'b11: awsize <= 3'b000; - // default: begin end + 2'b0?: begin + awsize <= 3'b010; // Word + if ((|i_addr[1:0]) && !w_misaligned) + awsize <= AXILSB[2:0]; + end + 2'b10: begin + awsize <= 3'b001; // Half-word + if (i_addr[0] && !w_misaligned) + awsize <= AXILSB[2:0]; + end + 2'b11: awsize <= 3'b000; // Byte endcase + + if (SWAP_WSTRB) + awsize <= DSZ; end assign M_AXI_AWSIZE = awsize; @@ -438,23 +447,38 @@ module axiops #( // shifted_wstrb_* // {{{ - always @(*) + generate if (SWAP_WSTRB) + begin : BIG_ENDIAN_WSTRB + always @(*) + shifted_wstrb_word = { 4'b1111, {(2*DW/8-4){1'b0}} } + >> i_addr[AXILSB-1:0]; + + always @(*) + shifted_wstrb_halfword = { 2'b11, {(2*DW/8-2){1'b0}} } + >> i_addr[AXILSB-1:0]; + + always @(*) + shifted_wstrb_byte = { 1'b1, {(2*DW/8-1){1'b0}} } + >> i_addr[AXILSB-1:0]; + end else begin : NORMAL_SHIFTED_WSTRB + always @(*) shifted_wstrb_word = { {(2*DW/8-4){1'b0}}, 4'b1111} << i_addr[AXILSB-1:0]; - always @(*) + always @(*) shifted_wstrb_halfword = { {(2*DW/8-4){1'b0}}, 4'b0011} << i_addr[AXILSB-1:0]; - always @(*) + always @(*) shifted_wstrb_byte = { {(2*DW/8-4){1'b0}}, 4'b0001} << i_addr[AXILSB-1:0]; + end endgenerate // }}} // Swapping WSTRB bits // {{{ - generate if (SWAP_WSTRB) - begin : SWAPPING_WSTRB + generate if (SWAP_ENDIANNESS) + begin : SWAPPING_ENDIANNESS // {{{ genvar gw, gb; @@ -491,11 +515,7 @@ module axiops #( // wdata, wstrb // {{{ always @(*) - begin swapaddr = i_addr[AXILSB-1:0]; - if (SWAP_WSTRB) - swapaddr[1:0] = 3 - i_addr[1:0]; - end initial axi_wdata = 0; initial axi_wstrb = 0; @@ -516,25 +536,49 @@ module axiops #( end else if (i_stb) begin // {{{ - casez(i_op[2:1]) - 2'b10: { next_wdata, axi_wdata } - <= { {(2*C_AXI_DATA_WIDTH-16){1'b0}}, - i_data[15:0] } << (8*swapaddr); - 2'b11: { next_wdata, axi_wdata } - <= { {(2*C_AXI_DATA_WIDTH-8){1'b0}}, - i_data[7:0] } << (8*swapaddr); - default: { next_wdata, axi_wdata } - <= { {(2*C_AXI_DATA_WIDTH-32){1'b0}}, - i_data } << (8*swapaddr); - endcase + if (SWAP_WSTRB) + begin + casez(i_op[2:1]) + 2'b10: { axi_wdata, next_wdata } + <= { i_data[15:0], {(2*C_AXI_DATA_WIDTH-16){1'b0}} } + >> (8*swapaddr); + 2'b11: { axi_wdata, next_wdata } + <= { i_data[7:0], {(2*C_AXI_DATA_WIDTH-8){1'b0}} } + >> (8*swapaddr); + default: { axi_wdata, next_wdata } + <= { i_data, {(2*C_AXI_DATA_WIDTH-32){1'b0}} } + >> (8*swapaddr); + endcase + end else begin + casez(i_op[2:1]) + 2'b10: { next_wdata, axi_wdata } + <= { {(2*C_AXI_DATA_WIDTH-16){1'b0}}, + i_data[15:0] } << (8*swapaddr); + 2'b11: { next_wdata, axi_wdata } + <= { {(2*C_AXI_DATA_WIDTH-8){1'b0}}, + i_data[7:0] } << (8*swapaddr); + default: { next_wdata, axi_wdata } + <= { {(2*C_AXI_DATA_WIDTH-32){1'b0}}, + i_data } << (8*swapaddr); + endcase + end // next_wstrb, axi_wstrb // {{{ - casez(i_op[2:1]) - 2'b0?: { next_wstrb, axi_wstrb } <= swapped_wstrb_word; - 2'b10: { next_wstrb, axi_wstrb } <= swapped_wstrb_halfword; - 2'b11: { next_wstrb, axi_wstrb } <= swapped_wstrb_byte; - endcase + if (SWAP_WSTRB) + begin + casez(i_op[2:1]) + 2'b0?: { axi_wstrb, next_wstrb } <= swapped_wstrb_word; + 2'b10: { axi_wstrb, next_wstrb } <= swapped_wstrb_halfword; + 2'b11: { axi_wstrb, next_wstrb } <= swapped_wstrb_byte; + endcase + end else begin + casez(i_op[2:1]) + 2'b0?: { next_wstrb, axi_wstrb } <= swapped_wstrb_word; + 2'b10: { next_wstrb, axi_wstrb } <= swapped_wstrb_halfword; + 2'b11: { next_wstrb, axi_wstrb } <= swapped_wstrb_byte; + endcase + end // }}} r_op <= { i_op[2:1] , i_addr[AXILSB-1:0] }; @@ -767,7 +811,7 @@ module axiops #( o_busy = M_AXI_BREADY || M_AXI_RREADY; o_rdbusy = (M_AXI_BREADY && r_lock) || M_AXI_RREADY; if (r_flushing) - o_rdbusy <= 1'b0; + o_rdbusy = 1'b0; end // }}} @@ -812,12 +856,35 @@ module axiops #( // tool knows we want a shift of the full 2*DW width. always @(*) begin - if (misaligned_read && !OPT_ALIGNMENT_ERR) - pre_result = { endian_swapped_rdata, last_result } - >> (8*r_op[AXILSB-1:0]); - else - pre_result = { {(DW){1'b0}}, endian_swapped_rdata } + if (SWAP_WSTRB) + begin + if (misaligned_read && !OPT_ALIGNMENT_ERR) + pre_result={ last_result, endian_swapped_rdata } + << (8*r_op[AXILSB-1:0]); + else + pre_result = { endian_swapped_rdata, {(DW){1'b0}} } + << (8*r_op[AXILSB-1:0]); + + casez(r_op[AXILSB +: 2]) + 2'b10: pre_result = { 16'h0, + pre_result[(2*DW)-1:(2*DW)-16], + {(DW){1'b0}} }; + 2'b11: pre_result = { 24'h0, + pre_result[(2*DW)-1:(2*DW)-8], + {(DW){1'b0}} }; + default: begin end + endcase + + pre_result[31:0] = pre_result[(2*DW-1):(2*DW-32)]; + + end else begin + if (misaligned_read && !OPT_ALIGNMENT_ERR) + pre_result={ endian_swapped_rdata, last_result } >> (8*r_op[AXILSB-1:0]); + else + pre_result = { {(DW){1'b0}}, endian_swapped_rdata } + >> (8*r_op[AXILSB-1:0]); + end if (OPT_LOWPOWER && (!M_AXI_RVALID || M_AXI_RRESP[1])) pre_result = 0; @@ -850,7 +917,7 @@ module axiops #( if (OPT_ALIGNMENT_ERR) last_result <= 0; - o_result <= pre_result; + o_result <= pre_result[31:0]; if (OPT_SIGN_EXTEND) begin @@ -886,7 +953,7 @@ module axiops #( // verilator lint_off UNUSED wire unused; assign unused = &{ 1'b0, M_AXI_BID, M_AXI_RID, M_AXI_RLAST, - pre_result[2*C_AXI_DATA_WIDTH:32] }; + pre_result[2*C_AXI_DATA_WIDTH-1:32] }; // verilator lint_on UNUSED // }}} //////////////////////////////////////////////////////////////////////////////// diff --git a/rtl/cpu/axipipe.v b/rtl/cpu/axipipe.v index d8576df..57d9f49 100644 --- a/rtl/cpu/axipipe.v +++ b/rtl/cpu/axipipe.v @@ -17,7 +17,7 @@ // Copyright (C) 2020-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -282,8 +282,16 @@ module axipipe #( axi_size <= AXILSB[2:0]; else begin casez(i_op[2:1]) - 2'b0?: axi_size <= 3'b010; - 2'b10: axi_size <= 3'b001; + 2'b0?: begin + axi_size <= 3'b010; + if ((|i_addr[1:0]) && !w_misaligned) + axi_size <= AXILSB[2:0]; + end + 2'b10: begin + axi_size <= 3'b001; + if (i_addr[0] && !w_misaligned) + axi_size <= AXILSB[2:0]; + end 2'b11: axi_size <= 3'b000; // default: begin end endcase @@ -634,20 +642,22 @@ module axipipe #( casez(i_op[2:1]) 2'b0?: wide_wstrb - = { 4'b1111, {(C_AXI_DATA_WIDTH/4-4){1'b0}} } >> i_addr[AXILSB-1:0]; + = { 4'b1111, {(2*C_AXI_DATA_WIDTH/8-4){1'b0}} } >> i_addr[AXILSB-1:0]; 2'b10: wide_wstrb - = { 2'b11, {(C_AXI_DATA_WIDTH/4-2){1'b0}} } >> i_addr[AXILSB-1:0]; + = { 2'b11, {(2*C_AXI_DATA_WIDTH/8-2){1'b0}} } >> i_addr[AXILSB-1:0]; 2'b11: wide_wstrb - = { 1'b0, {(C_AXI_DATA_WIDTH/4-1){1'b0}} } >> i_addr[AXILSB-1:0]; + = { 1'b1, {(2*C_AXI_DATA_WIDTH/8-1){1'b0}} } >> i_addr[AXILSB-1:0]; endcase // }}} end else begin : LITTLE_ENDIAN_DATA // {{{ casez(i_op[2:1]) 2'b10: wide_wdata - = { {(2*C_AXI_DATA_WIDTH-16){1'b0}}, i_data[15:0] } << (8*i_addr[AXILSB-1:0]); + = { {(2*C_AXI_DATA_WIDTH-16){1'b0}}, i_data[15:0] } + << (8*i_addr[AXILSB-1:0]); 2'b11: wide_wdata - = { {(2*C_AXI_DATA_WIDTH-8){1'b0}}, i_data[7:0] } << (8*i_addr[AXILSB-1:0]); + = { {(2*C_AXI_DATA_WIDTH-8){1'b0}}, i_data[7:0] } + << (8*i_addr[AXILSB-1:0]); default: wide_wdata = { {(C_AXI_DATA_WIDTH){1'b0}}, i_data } << (8*i_addr[AXILSB-1:0]); @@ -655,11 +665,11 @@ module axipipe #( casez(i_op[2:1]) 2'b0?: wide_wstrb - = { {(C_AXI_DATA_WIDTH/4-4){1'b0}}, 4'b1111} << i_addr[AXILSB-1:0]; + = { {(2*C_AXI_DATA_WIDTH/8-4){1'b0}}, 4'b1111} << i_addr[AXILSB-1:0]; 2'b10: wide_wstrb - = { {(C_AXI_DATA_WIDTH/4-4){1'b0}}, 4'b0011} << i_addr[AXILSB-1:0]; + = { {(2*C_AXI_DATA_WIDTH/8-4){1'b0}}, 4'b0011} << i_addr[AXILSB-1:0]; 2'b11: wide_wstrb - = { {(C_AXI_DATA_WIDTH/4-4){1'b0}}, 4'b0001} << i_addr[AXILSB-1:0]; + = { {(2*C_AXI_DATA_WIDTH/8-4){1'b0}}, 4'b0001} << i_addr[AXILSB-1:0]; endcase // }}} end @@ -823,7 +833,7 @@ module axipipe #( always @(posedge S_AXI_ACLK) if ((M_AXI_ARVALID && M_AXI_ARREADY) || (M_AXI_WVALID && M_AXI_WREADY)) fifo_data[wraddr[LGPIPE-1:0]] <= { M_AXI_ARVALID, ar_oreg,ar_op, - misaligned_request, M_AXI_ARADDR[AXILSB-1:0] }; + misaligned_request, adr_lsb }; always @(*) fifo_read_data = fifo_data[rdaddr[LGPIPE-1:0]]; @@ -882,11 +892,38 @@ module axipipe #( // wide_return // {{{ always @(*) - if (fifo_misaligned && !OPT_ALIGNMENT_ERR) - wide_return = { M_AXI_RDATA, misdata } >> (8*fifo_lsb); - else - wide_return = { {(C_AXI_DATA_WIDTH){1'b0}}, M_AXI_RDATA } + begin + if (SWAP_WSTRB) + begin + if (fifo_misaligned && !OPT_ALIGNMENT_ERR) + wide_return = { misdata, M_AXI_RDATA } + << (8*fifo_lsb); + else + wide_return = { M_AXI_RDATA, {(DW){1'b0}} } + << (8*fifo_lsb); + + casez(fifo_op[1:0]) + 2'b10: wide_return = { {(16){1'b0}}, + wide_return[(2*DW)-1:(2*DW)-16], + {(2*DW-32){1'b0}} }; + 2'b11: wide_return = { {(24){1'b0}}, + wide_return[(2*DW)-1:(2*DW)-8], + {(2*DW-32){1'b0}} }; + default: begin end + endcase + + wide_return[31:0] = wide_return[(2*DW-1):(2*DW-32)]; + end else begin + if (fifo_misaligned && !OPT_ALIGNMENT_ERR) + wide_return = { M_AXI_RDATA, misdata } >> (8*fifo_lsb); + else + wide_return = { {(C_AXI_DATA_WIDTH){1'b0}}, M_AXI_RDATA } >> (8*fifo_lsb); + end + + if (OPT_LOWPOWER && (!M_AXI_RVALID || M_AXI_RRESP[1])) + wide_return = 0; + end // }}} // misdata @@ -914,6 +951,7 @@ module axipipe #( o_result[AW-1:0] <= r_pc; end else if (!OPT_LOWPOWER || M_AXI_RVALID) begin + o_result <= wide_return[31:0]; if (OPT_SIGN_EXTEND) @@ -921,14 +959,14 @@ module axipipe #( // {{{ case(fifo_op) 2'b10: o_result[31:16] <= {(16){wide_return[15]}}; - 2'b11: o_result[15: 8] <= {( 8){wide_return[ 7]}}; + 2'b11: o_result[31: 8] <= {(24){wide_return[ 7]}}; endcase // }}} end else if (fifo_op[1]) begin // {{{ if (fifo_op[0]) - o_result[15: 8] <= 0; + o_result[31: 8] <= 0; else o_result[31:16] <= 0; // }}} @@ -974,7 +1012,7 @@ module axipipe #( M_AXI_BID, M_AXI_RID, M_AXI_RLAST, // i_addr[31:C_AXI_ADDR_WIDTH], (&i_addr), wide_return[2*C_AXI_DATA_WIDTH-1:32], - pending_err, adr_lsb, fifo_read_op, + pending_err, fifo_read_op, none_outstanding }; // verilator lint_on UNUSED // }}} diff --git a/rtl/cpu/busdelay.v b/rtl/cpu/busdelay.v index 0f9d545..9f95571 100644 --- a/rtl/cpu/busdelay.v +++ b/rtl/cpu/busdelay.v @@ -40,7 +40,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/rtl/cpu/cpudefs.v b/rtl/cpu/cpudefs.v index 0d0fb98..c769f3a 100644 --- a/rtl/cpu/cpudefs.v +++ b/rtl/cpu/cpudefs.v @@ -31,7 +31,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/rtl/cpu/cpuops.v b/rtl/cpu/cpuops.v index e44e6ca..2bc3aab 100644 --- a/rtl/cpu/cpuops.v +++ b/rtl/cpu/cpuops.v @@ -16,7 +16,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/rtl/cpu/dblfetch.v b/rtl/cpu/dblfetch.v index 465f189..59c34cc 100644 --- a/rtl/cpu/dblfetch.v +++ b/rtl/cpu/dblfetch.v @@ -26,7 +26,7 @@ // Copyright (C) 2017-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/rtl/cpu/dcache.v b/rtl/cpu/dcache.v index 11f14bd..faa9bde 100644 --- a/rtl/cpu/dcache.v +++ b/rtl/cpu/dcache.v @@ -51,7 +51,7 @@ // Copyright (C) 2016-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -209,7 +209,7 @@ module dcache #( // Cachability checking // {{{ - iscachable chkaddress(i_addr[AW+1:2], raw_cachable_address); + iscachable chkaddress(i_addr[AW+1:0], raw_cachable_address); // }}} // r_* values diff --git a/rtl/cpu/div.v b/rtl/cpu/div.v index 5001e26..7fecd48 100644 --- a/rtl/cpu/div.v +++ b/rtl/cpu/div.v @@ -74,7 +74,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -517,8 +517,9 @@ module div #( &&($past(r_divisor[2*BW-2:BW])==0)) begin if ($past(r_divisor) == 0) + begin assert(o_err); - else if ($past(pre_sign)) + end else if ($past(pre_sign)) begin if ($past(r_dividend[BW-1])) assert(r_dividend == -$past(r_dividend)); @@ -530,8 +531,9 @@ module div #( end end else begin if (o_quotient[0]) + begin assert(r_dividend == $past(diff)); - else + end else assert(r_dividend == $past(r_dividend)); // r_divisor should shift down on every step @@ -539,8 +541,9 @@ module div #( assert(r_divisor[2*BW-3:0]==$past(r_divisor[2*BW-2:1])); end if ($past(r_dividend) >= $past(r_divisor[BW-1:0])) + begin assert(o_quotient[0]); - else + end else assert(!o_quotient[0]); end */ diff --git a/rtl/cpu/icontrol.v b/rtl/cpu/icontrol.v index a361168..171b260 100644 --- a/rtl/cpu/icontrol.v +++ b/rtl/cpu/icontrol.v @@ -55,7 +55,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/rtl/cpu/idecode.v b/rtl/cpu/idecode.v index 21fc55f..d5598a3 100644 --- a/rtl/cpu/idecode.v +++ b/rtl/cpu/idecode.v @@ -22,7 +22,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -60,6 +60,7 @@ module idecode #( parameter [0:0] OPT_LOCK = (OPT_PIPELINED), parameter [0:0] OPT_OPIPE = (OPT_PIPELINED), parameter [0:0] OPT_SIM = 1'b0, + parameter [0:0] OPT_SUPPRESS_NULL_BRANCHES = 1'b0, parameter [0:0] OPT_NO_USERMODE = 1'b0, localparam AW = ADDRESS_WIDTH // }}} @@ -668,7 +669,7 @@ module idecode #( begin // Add x,PC r_early_branch <= 1'b1; - r_early_branch_stb <= 1'b1; + r_early_branch_stb <= (!OPT_SUPPRESS_NULL_BRANCHES) || !w_Iz; end else begin r_early_branch <= 1'b0; r_early_branch_stb <= 1'b0; diff --git a/rtl/cpu/iscachable.v b/rtl/cpu/iscachable.v index 9e92f06..8af9f50 100644 --- a/rtl/cpu/iscachable.v +++ b/rtl/cpu/iscachable.v @@ -18,7 +18,7 @@ // Copyright (C) 2017-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -41,10 +41,12 @@ // }}} `default_nettype none // -module iscachable(i_addr, o_cachable); - localparam AW = 23; - input wire [AW-1:0] i_addr; - output reg o_cachable; +module iscachable( + // {{{ + input wire [25-1:0] i_addr, + output reg o_cachable + // }}} + ); always @(*) begin @@ -52,10 +54,10 @@ module iscachable(i_addr, o_cachable); // Bus master: wb // Bus master: wb_sio // bkram - if ((i_addr[22:0] & 23'h780000) == 23'h300000) + if ((i_addr[24:0] & 25'h1e00000) == 25'h0c00000) o_cachable = 1'b1; // flash - if ((i_addr[22:0] & 23'h400000) == 23'h400000) + if ((i_addr[24:0] & 25'h1000000) == 25'h1000000) o_cachable = 1'b1; end diff --git a/rtl/cpu/memops.v b/rtl/cpu/memops.v index a62a40d..c19c7d1 100644 --- a/rtl/cpu/memops.v +++ b/rtl/cpu/memops.v @@ -23,7 +23,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/rtl/cpu/mpyop.v b/rtl/cpu/mpyop.v index d46ffb7..4be05d5 100644 --- a/rtl/cpu/mpyop.v +++ b/rtl/cpu/mpyop.v @@ -18,7 +18,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/rtl/cpu/pfcache.v b/rtl/cpu/pfcache.v index 3c5ee51..9dcdc1b 100644 --- a/rtl/cpu/pfcache.v +++ b/rtl/cpu/pfcache.v @@ -38,7 +38,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -70,7 +70,7 @@ module pfcache #( parameter LGCACHELEN = 12, ADDRESS_WIDTH=30, LGLINES=6, // Log of # of separate cache lines `endif - // localparam CACHELEN=(1<1) + begin assert(!r_empty); - else if ($past(!i_rd && f_fill > 0)) + end else if ($past(!i_rd && f_fill > 0)) assert(!r_empty); end always @(*) if (!r_empty) + begin // This also applies for the registered read case - assert(mem[rd_addr] == o_data); - else if (OPT_READ_ON_EMPTY) + assert(mem[rd_addr[LGFLEN-1:0]] == o_data); + end else if (OPT_READ_ON_EMPTY) assert(o_data == i_data); // }}} @@ -315,7 +322,10 @@ module sfifo #( //////////////////////////////////////////////////////////////////////// // // + + // Verilator lint_off UNDRIVEN (* anyconst *) reg [LGFLEN:0] f_first_addr; + // Verilator lint_on UNDRIVEN reg [LGFLEN:0] f_second_addr; reg [BW-1:0] f_first_data, f_second_data; @@ -352,16 +362,16 @@ module sfifo #( always @(*) if (f_first_addr_in_fifo) - assert(mem[f_first_addr] == f_first_data); + assert(mem[f_first_addr[LGFLEN-1:0]] == f_first_data); always @(*) - f_first_in_fifo = (f_first_addr_in_fifo && (mem[f_first_addr] == f_first_data)); + f_first_in_fifo = (f_first_addr_in_fifo && (mem[f_first_addr[LGFLEN-1:0]] == f_first_data)); always @(*) if (f_second_addr_in_fifo) - assert(mem[f_second_addr] == f_second_data); + assert(mem[f_second_addr[LGFLEN-1:0]] == f_second_data); always @(*) - f_second_in_fifo = (f_second_addr_in_fifo && (mem[f_second_addr] == f_second_data)); + f_second_in_fifo = (f_second_addr_in_fifo && (mem[f_second_addr[LGFLEN-1:0]] == f_second_data)); always @(posedge i_clk) if (f_past_valid && !$past(i_reset)) @@ -370,9 +380,11 @@ module sfifo #( 2'b00: begin if ($past(w_wr && (!w_rd || !r_empty)) &&($past(wr_addr == f_first_addr))) + begin assert(f_first_in_fifo); - else + end else begin assert(!f_first_in_fifo); + end // // The second could be in the FIFO, since // one might write other data than f_first_data @@ -382,16 +394,20 @@ module sfifo #( 2'b01: begin assert(!f_first_in_fifo); if ($past(w_rd && (rd_addr==f_second_addr))) + begin assert((o_empty&&!OPT_ASYNC_READ)||!f_second_in_fifo); - else + end else begin assert(f_second_in_fifo); + end end 2'b10: begin if ($past(w_wr) &&($past(wr_addr == f_second_addr))) + begin assert(f_second_in_fifo); - else + end else begin assert(!f_second_in_fifo); + end if ($past(!w_rd ||(rd_addr != f_first_addr))) assert(f_first_in_fifo); end @@ -417,13 +433,13 @@ module sfifo #( //////////////////////////////////////////////////////////////////////// // // +`ifdef SFIFO reg f_was_full; initial f_was_full = 0; always @(posedge i_clk) if (o_full) f_was_full <= 1; -`ifdef SFIFO always @(posedge i_clk) cover($fell(f_empty)); @@ -441,6 +457,12 @@ module sfifo #( cover($past(o_empty,2)&&(!$past(o_empty))&& o_empty); `endif // }}} + + // Make Verilator happy + // Verilator lint_off UNUSED + wire unused_formal; + assign unused_formal = &{ 1'b0, f_next[LGFLEN], f_empty }; + // Verilator lint_on UNUSED `endif // FORMAL // }}} endmodule diff --git a/rtl/cpu/slowmpy.v b/rtl/cpu/slowmpy.v index c5473e5..91d52c5 100644 --- a/rtl/cpu/slowmpy.v +++ b/rtl/cpu/slowmpy.v @@ -19,7 +19,7 @@ // Copyright (C) 2018-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -47,6 +47,7 @@ module slowmpy #( parameter LGNA = 6, parameter [LGNA:0] NA = 33, parameter [0:0] OPT_SIGNED = 1'b1, + parameter [0:0] OPT_LOWPOWER = 1'b0, localparam NB = NA // Must be = NA for OPT_SIGNED to work // }}} ) ( @@ -97,14 +98,14 @@ module slowmpy #( o_done <= 0; o_busy <= 0; // }}} - end else if ((!o_busy)&&(i_stb)) + end else if (!o_busy) begin // {{{ o_done <= 0; - o_busy <= 1; - aux <= i_aux; + o_busy <= i_stb; + aux <= (!OPT_LOWPOWER || i_stb) ? i_aux : 0; // }}} - end else if ((o_busy)&&(almost_done)) + end else if (almost_done) begin // {{{ o_done <= 1; @@ -115,6 +116,7 @@ module slowmpy #( // }}} assign pwire = (p_b[0] ? p_a : 0); + // count, partial, p_a, p_b // {{{ always @(posedge i_clk) @@ -124,6 +126,12 @@ module slowmpy #( partial <= 0; p_a <= i_a; p_b <= i_b; + + if (OPT_LOWPOWER && !i_stb) + begin + p_a <= 0; + p_b <= 0; + end end else begin p_b <= (p_b >> 1); // partial[NA+NB-1:NB] <= partial[NA+NB diff --git a/rtl/cpu/wbarbiter.v b/rtl/cpu/wbarbiter.v index a122c17..dfdfaac 100644 --- a/rtl/cpu/wbarbiter.v +++ b/rtl/cpu/wbarbiter.v @@ -37,7 +37,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/rtl/cpu/wbdblpriarb.v b/rtl/cpu/wbdblpriarb.v index 3506485..a837c06 100644 --- a/rtl/cpu/wbdblpriarb.v +++ b/rtl/cpu/wbdblpriarb.v @@ -47,7 +47,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/rtl/cpu/wbdmac.v b/rtl/cpu/wbdmac.v index 0aec704..14e642e 100644 --- a/rtl/cpu/wbdmac.v +++ b/rtl/cpu/wbdmac.v @@ -89,7 +89,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/rtl/cpu/wbwatchdog.v b/rtl/cpu/wbwatchdog.v index 389e7bc..cc08549 100644 --- a/rtl/cpu/wbwatchdog.v +++ b/rtl/cpu/wbwatchdog.v @@ -26,7 +26,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/rtl/cpu/zipaxi.v b/rtl/cpu/zipaxi.v index 9d52869..0706735 100644 --- a/rtl/cpu/zipaxi.v +++ b/rtl/cpu/zipaxi.v @@ -26,7 +26,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -64,8 +64,9 @@ module zipaxi #( parameter DATA_ID = 0, localparam ADDRESS_WIDTH = C_AXI_ADDR_WIDTH, localparam AXILSB = $clog2(C_AXI_DATA_WIDTH/8), - parameter [C_AXI_ADDR_WIDTH-1:0] RESET_ADDRESS=32'h010_0000, + parameter [C_AXI_ADDR_WIDTH-1:0] RESET_ADDRESS=0, parameter [0:0] START_HALTED = 1'b0, + parameter [0:0] SWAP_WSTRB = 1'b0, `ifdef OPT_MULTIPLY parameter IMPLEMENT_MPY = `OPT_MULTIPLY, `else @@ -102,17 +103,22 @@ module zipaxi #( `else localparam [0:0] OPT_PIPELINED_BUS_ACCESS = 1'b0, `endif - // localparam [0:0] OPT_MEMPIPE = OPT_PIPELINED_BUS_ACCESS, + localparam [0:0] OPT_MEMPIPE = OPT_PIPELINED_BUS_ACCESS, localparam [0:0] IMPLEMENT_LOCK=1, // localparam [0:0] OPT_LOCK=(IMPLEMENT_LOCK)&&(OPT_PIPELINED), parameter LGICACHE = 8, parameter LGILINESZ= 3, parameter OPT_LGDCACHE = 0, parameter OPT_LGDLINESZ = 3, - localparam [0:0] OPT_DCACHE = (OPT_LGDCACHE > 0), + localparam [0:0] OPT_DCACHE = (OPT_LGDCACHE > 2), parameter RESET_DURATION = 10, // localparam [0:0] WITH_LOCAL_BUS = 1'b0, - localparam AW=ADDRESS_WIDTH-2 + localparam AW=ADDRESS_WIDTH-2, +`ifdef VERILATOR + localparam [0:0] OPT_GATE_CLOCK = 1'b1 +`else + localparam [0:0] OPT_GATE_CLOCK = 1'b0 +`endif `ifdef FORMAL , parameter F_LGDEPTH=8 `endif @@ -120,7 +126,7 @@ module zipaxi #( ) ( // {{{ input wire S_AXI_ACLK, S_AXI_ARESETN, - i_interrupt, + i_interrupt, i_cpu_reset, // Debug interface // {{{ // Debug interface -- inputs @@ -180,8 +186,8 @@ module zipaxi #( output wire M_INSN_WLAST, // input wire M_INSN_BVALID, - input wire [C_AXI_ID_WIDTH-1:0] M_INSN_BID, output wire M_INSN_BREADY, + input wire [C_AXI_ID_WIDTH-1:0] M_INSN_BID, input wire [1:0] M_INSN_BRESP, // output wire M_INSN_ARVALID, @@ -248,6 +254,9 @@ module zipaxi #( input wire [1:0] M_DATA_RRESP, // }}} // Accounting outputs ... to help us count stalls and usage + output wire o_cmd_reset, + output wire o_halted, + output wire o_gie, output wire o_op_stall, output wire o_pf_stall, output wire o_i_count @@ -283,12 +292,12 @@ module zipaxi #( wire [4:0] dbg_read_reg; reg [31:0] dbg_write_data; wire [31:0] dbg_read_data; - wire cpu_dbg_stall, cpu_break; + wire cpu_dbg_stall, cpu_break, dbg_write_stall; wire [2:0] cpu_dbg_cc; // }}} reg reset_hold; - wire cpu_clken; + wire cpu_clken, cpu_clock, clk_gate; // CPU control registers // {{{ @@ -309,7 +318,8 @@ module zipaxi #( // {{{ wire clear_dcache, mem_ce, bus_lock; wire [2:0] mem_op; - wire [31:0] mem_cpu_addr, mem_lock_pc; + wire [31:0] mem_cpu_addr; + wire [AW+1:0] mem_lock_pc; wire [31:0] mem_wdata; wire [4:0] mem_reg; wire mem_busy, mem_rdbusy, mem_pipe_stalled, mem_valid, @@ -364,8 +374,8 @@ module zipaxi #( ); assign dbg_write_ready = awskd_valid && wskd_valid - && ((wskd_strb==0) || awskd_addr[5] || !cpu_dbg_stall - || !dbg_write_valid) + && ((wskd_strb==0) || awskd_addr[5] + || !dbg_write_stall) && (!S_DBG_BVALID || S_DBG_BREADY); // dbg_write_valid @@ -374,7 +384,7 @@ module zipaxi #( always @(posedge S_AXI_ACLK) if (!S_AXI_ARESETN) dbg_write_valid <= 1'b0; - else if (!dbg_write_valid || !cpu_dbg_stall) + else if (!dbg_write_stall) begin dbg_write_valid <= dbg_write_ready && (|wskd_strb) && !awskd_addr[5]; end @@ -383,7 +393,7 @@ module zipaxi #( // dbg_write_reg // {{{ always @(posedge S_AXI_ACLK) - if (!dbg_write_valid || !cpu_dbg_stall) + if (!dbg_write_stall) begin dbg_write_reg <= awskd_addr[4:0]; if (OPT_LOWPOWER && !dbg_write_valid) @@ -394,7 +404,7 @@ module zipaxi #( // dbg_write_data // {{{ always @(posedge S_AXI_ACLK) - if (!dbg_write_valid || !cpu_dbg_stall) + if (!dbg_write_stall) begin dbg_write_data <= wskd_data; if (OPT_LOWPOWER && !dbg_write_ready) @@ -512,14 +522,14 @@ module zipaxi #( initial reset_counter = RESET_DURATION; always @(posedge S_AXI_ACLK) - if (!S_AXI_ARESETN) + if (!S_AXI_ARESETN || i_cpu_reset) reset_counter <= RESET_DURATION; else if (reset_counter > 0) reset_counter <= reset_counter - 1; initial reset_hold = 1; always @(posedge S_AXI_ACLK) - if (!S_AXI_ARESETN) + if (!S_AXI_ARESETN || i_cpu_reset) reset_hold <= 1; else reset_hold <= (reset_counter > 1); @@ -539,7 +549,7 @@ module zipaxi #( // {{{ initial cmd_reset = 1'b1; always @(posedge S_AXI_ACLK) - if (!S_AXI_ARESETN) + if (!S_AXI_ARESETN || i_cpu_reset) cmd_reset <= 1'b1; else if (reset_hold) cmd_reset <= 1'b1; @@ -556,6 +566,8 @@ module zipaxi #( always @(posedge S_AXI_ACLK) if (!S_AXI_ARESETN) cmd_halt <= START_HALTED; + else if (i_cpu_reset && !dbg_write_ready && !dbg_write_stall) + cmd_halt <= START_HALTED; else if (cmd_reset && START_HALTED) cmd_halt <= START_HALTED; else begin @@ -617,7 +629,7 @@ module zipaxi #( // {{{ initial cmd_step = 1'b0; always @(posedge S_AXI_ACLK) - if (!S_AXI_ARESETN) + if (!S_AXI_ARESETN || i_cpu_reset) cmd_step <= 1'b0; else if (dbg_cmd_write && wskd_data[STEP_BIT] && wskd_strb[1]) cmd_step <= 1'b1; @@ -673,7 +685,7 @@ module zipaxi #( // {{{ .i_clk(S_AXI_ACLK), .i_reset(!S_AXI_ARESETN), - .i_cpu_reset(cmd_reset), + .i_cpu_reset(cmd_reset || i_cpu_reset), .i_halt(cmd_halt), .i_halted(f_cpu_halted), .i_clear_cache(cmd_clear_cache), @@ -701,18 +713,19 @@ module zipaxi #( .OPT_PIPELINED_BUS_ACCESS(OPT_PIPELINED_BUS_ACCESS), // localparam [0:0] OPT_MEMPIPE = OPT_PIPELINED_BUS_ACCESS; .IMPLEMENT_LOCK(IMPLEMENT_LOCK), - .OPT_DCACHE(OPT_DCACHE), + .OPT_DCACHE(OPT_LGDCACHE != 0), // localparam [0:0] OPT_LOCK=(IMPLEMENT_LOCK)&&(OPT_PIPELINED); // parameter [0:0] WITH_LOCAL_BUS = 1'b1; - .OPT_GATE_CLOCK(1'b0) + .OPT_GATE_CLOCK(OPT_GATE_CLOCK) `ifdef FORMAL , .F_LGDEPTH(F_LGDEPTH) `endif // }}} ) core ( // {{{ - .i_clk(S_AXI_ACLK), .i_reset(cmd_reset), + .i_clk(cpu_clock), .i_reset(cmd_reset), .i_interrupt(i_interrupt), + .o_clken(cpu_clken), // Debug interface // {{{ .i_halt(cmd_halt), .i_clear_cache(cmd_clear_cache), @@ -750,11 +763,14 @@ module zipaxi #( // Accounting/CPU usage interface .o_op_stall(o_op_stall), .o_pf_stall(o_pf_stall), .o_i_count(o_i_count), - .o_clken(cpu_clken), .o_debug(cpu_debug) // }}} ); `endif + assign o_cmd_reset = cmd_reset; + assign o_gie = cpu_dbg_cc[1]; + assign o_halted = !cpu_dbg_stall; + assign dbg_write_stall = dbg_write_valid&&(cpu_dbg_stall || !clk_gate); // }}} // o_debug -- the debugging bus input // {{{ @@ -764,6 +780,7 @@ module zipaxi #( // Verilator lint_off UNUSED wire dbg_unused; assign dbg_unused = &{ 1'b0, cpu_debug }; + // Verilator lint_on UNUSED `endif // }}} //////////////////////////////////////////////////////////////////////// @@ -779,11 +796,15 @@ module zipaxi #( axiicache #( // {{{ + .C_AXI_ID_WIDTH(C_AXI_ID_WIDTH), .C_AXI_ADDR_WIDTH(C_AXI_ADDR_WIDTH), .C_AXI_DATA_WIDTH(C_AXI_DATA_WIDTH), .AXI_ID(INSN_ID), .LGCACHESZ(LGICACHE), .LGLINESZ(LGILINESZ), + // Instruction fetches don't need subword access, + // so SWAPWSTRB doesn't make any sense here. + // .SWAP_WSTRB(SWAP_WSTRB), .SWAP_ENDIANNESS(SWAP_ENDIANNESS) // }}} ) pf ( @@ -832,6 +853,7 @@ module zipaxi #( .C_AXI_ADDR_WIDTH(C_AXI_ADDR_WIDTH), .C_AXI_DATA_WIDTH(C_AXI_DATA_WIDTH), .FETCH_LIMIT(FETCH_LIMIT), + // .SWAP_WSTRB(SWAP_WSTRB), .SWAP_ENDIANNESS(SWAP_ENDIANNESS) // }}} ) pf ( @@ -908,6 +930,31 @@ module zipaxi #( //////////////////////////////////////////////////////////////////////// // `ifndef FORMAL + wire [C_AXI_DATA_WIDTH-1:0] i_bus_data, o_bus_data; + wire [C_AXI_DATA_WIDTH/8-1:0] o_bus_strb; + + generate if (SWAP_WSTRB && C_AXI_DATA_WIDTH > 32 && !OPT_DCACHE) + begin : SWAP_BUS_WORD_ORDER + genvar gk; + + for(gk=0; gk 0) begin : PIPELINED_MEM axipipe #( @@ -1012,6 +1059,7 @@ module zipaxi #( .AXI_ID(DATA_ID), .OPT_LOCK(IMPLEMENT_LOCK), .OPT_ALIGNMENT_ERR(OPT_ALIGNMENT_ERR), + .SWAP_WSTRB(SWAP_WSTRB), .OPT_LOWPOWER(OPT_LOWPOWER) // .OPT_SIGN_EXTEND(OPT_SIGN_EXTEND) // }}} @@ -1024,7 +1072,7 @@ module zipaxi #( .i_stb(mem_ce), .i_lock(bus_lock), .i_op(mem_op), - .i_addr(mem_cpu_addr), + .i_addr(mem_cpu_addr[AW+1:0]), .i_restart_pc(mem_lock_pc), .i_data(mem_wdata), .i_oreg(mem_reg), @@ -1053,8 +1101,8 @@ module zipaxi #( // .M_AXI_WVALID(M_DATA_WVALID), .M_AXI_WREADY(M_DATA_WREADY), - .M_AXI_WDATA(M_DATA_WDATA), - .M_AXI_WSTRB(M_DATA_WSTRB), + .M_AXI_WDATA(o_bus_data), + .M_AXI_WSTRB(o_bus_strb), .M_AXI_WLAST(M_DATA_WLAST), // .M_AXI_BVALID(M_DATA_BVALID), @@ -1079,7 +1127,7 @@ module zipaxi #( .M_AXI_RVALID(M_DATA_RVALID), .M_AXI_RREADY(M_DATA_RREADY), .M_AXI_RID( M_DATA_RID), - .M_AXI_RDATA( M_DATA_RDATA), + .M_AXI_RDATA( i_bus_data), .M_AXI_RLAST( M_DATA_RLAST), .M_AXI_RRESP( M_DATA_RRESP) // }}} @@ -1102,7 +1150,7 @@ module zipaxi #( .C_AXI_ID_WIDTH(C_AXI_ID_WIDTH), .AXI_ID(DATA_ID), .SWAP_ENDIANNESS(SWAP_ENDIANNESS), - .SWAP_WSTRB(1'b0), + .SWAP_WSTRB(SWAP_WSTRB), // .OPT_SIGN_EXTEND(OPT_SIGN_EXTEND), .OPT_LOCK(IMPLEMENT_LOCK), .OPT_ALIGNMENT_ERR(OPT_ALIGNMENT_ERR), @@ -1117,7 +1165,7 @@ module zipaxi #( .i_stb(mem_ce), .i_lock(bus_lock), .i_op(mem_op), - .i_addr(mem_cpu_addr), + .i_addr(mem_cpu_addr[AW+1:0]), .i_restart_pc(mem_lock_pc), .i_data(mem_wdata), .i_oreg(mem_reg), @@ -1145,8 +1193,8 @@ module zipaxi #( // .M_AXI_WVALID(M_DATA_WVALID), .M_AXI_WREADY(M_DATA_WREADY), - .M_AXI_WDATA(M_DATA_WDATA), - .M_AXI_WSTRB(M_DATA_WSTRB), + .M_AXI_WDATA(o_bus_data), + .M_AXI_WSTRB(o_bus_strb), .M_AXI_WLAST(M_DATA_WLAST), // .M_AXI_BVALID(M_DATA_BVALID), @@ -1171,7 +1219,7 @@ module zipaxi #( .M_AXI_RVALID(M_DATA_RVALID), .M_AXI_RREADY(M_DATA_RREADY), .M_AXI_RID( M_DATA_RID), - .M_AXI_RDATA( M_DATA_RDATA), + .M_AXI_RDATA( i_bus_data), .M_AXI_RLAST( M_DATA_RLAST), .M_AXI_RRESP( M_DATA_RRESP) // }}} @@ -1190,6 +1238,42 @@ module zipaxi #( end endgenerate `endif // }}} + //////////////////////////////////////////////////////////////////////// + // + // (Optional) Clock gate + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + generate if (OPT_GATE_CLOCK) + begin : GATE_CPU_CLOCK + + reg gatep, gaten; + + always @(posedge S_AXI_ACLK) + if (!S_AXI_ARESETN) + gatep <= 1'b1; + else + gatep <= cpu_clken; + + always @(negedge S_AXI_ACLK) + if (!S_AXI_ARESETN) + gaten <= 1'b1; + else + gaten <= gatep; + + assign cpu_clock = S_AXI_ACLK && gaten; + assign clk_gate = gaten; + + end else begin : NO_CLOCK_GATE + + assign cpu_clock = S_AXI_ACLK; + assign clk_gate = 1'b1; + + end endgenerate + // }}} + // Make Verilator happy // {{{ // Verilator lint_off UNUSED @@ -1201,7 +1285,7 @@ module zipaxi #( M_INSN_AWREADY, M_INSN_WREADY, M_INSN_BVALID, M_INSN_BID, M_INSN_BRESP, mem_lock_pc - }; + }; // Verilator lint_on UNUSED // }}} //////////////////////////////////////////////////////////////////////////////// diff --git a/rtl/cpu/zipaxil.v b/rtl/cpu/zipaxil.v index c08c70d..bb31087 100644 --- a/rtl/cpu/zipaxil.v +++ b/rtl/cpu/zipaxil.v @@ -14,26 +14,9 @@ // registers.) Please see the accompanying spec.pdf file for a description // of these instructions. // -// All instructions are 32-bits wide. All bus accesses, both address and -// data, are 32-bits over a wishbone bus. -// -// The Zip CPU is fully pipelined with the following pipeline stages: -// -// 1. Prefetch, returns the instruction from memory. -// -// 2. Instruction Decode -// -// 3. Read Operands -// -// 4. Apply Instruction -// -// 4. Write-back Results -// -// Further information about the inner workings of this CPU, such as -// what causes pipeline stalls, may be found in the spec.pdf file. (The -// documentation within this file had become out of date and out of sync -// with the spec.pdf, so look to the spec.pdf for accurate and up to date -// information.) +// This version is bus width agnostic for both instruction and data buses, +// although the debug bus must still be 32-bits. Instruction and data +// buses must be at least 32-bits wide. // // Creator: Dan Gisselquist, Ph.D. // Gisselquist Technology, LLC @@ -43,7 +26,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -72,13 +55,11 @@ module zipaxil #( // {{{ parameter C_DBG_ADDR_WIDTH = 8, - localparam C_DBG_DATA_WIDTH = 32, - localparam DBGLSB = $clog2(C_DBG_DATA_WIDTH/8), parameter C_AXI_ADDR_WIDTH = 32, parameter C_AXI_DATA_WIDTH = 32, - localparam ADDRESS_WIDTH = C_AXI_ADDR_WIDTH, parameter [C_AXI_ADDR_WIDTH-1:0] RESET_ADDRESS=32'h010_0000, parameter [0:0] START_HALTED = 1'b0, + parameter [0:0] SWAP_WSTRB = 1'b1, `ifdef OPT_MULTIPLY parameter IMPLEMENT_MPY = `OPT_MULTIPLY, `else @@ -104,25 +85,23 @@ module zipaxil #( `else parameter [0:0] OPT_CIS = 1'b0, `endif - // localparam [0:0] OPT_NO_USERMODE = 1'b0, `ifdef OPT_PIPELINED parameter [0:0] OPT_PIPELINED = 1'b1, `else parameter [0:0] OPT_PIPELINED = 1'b0, `endif -`ifdef OPT_PIPELINED_BUS_ACCESS - localparam [0:0] OPT_PIPELINED_BUS_ACCESS = (OPT_PIPELINED), -`else - localparam [0:0] OPT_PIPELINED_BUS_ACCESS = 1'b0, -`endif - // localparam [0:0] OPT_MEMPIPE = OPT_PIPELINED_BUS_ACCESS, - localparam [0:0] IMPLEMENT_LOCK=0, - // localparam [0:0] OPT_LOCK=(IMPLEMENT_LOCK)&&(OPT_PIPELINED), - // localparam OPT_LGDCACHE = 0, - // localparam [0:0] OPT_DCACHE = (OPT_LGDCACHE > 0), parameter RESET_DURATION = 10, // localparam [0:0] WITH_LOCAL_BUS = 1'b0, - localparam AW=ADDRESS_WIDTH-2 +`ifdef VERILATOR + parameter [0:0] OPT_SIM = 1'b1, +`else + parameter [0:0] OPT_SIM = 1'b0, +`endif +`ifdef VERILATOR + localparam [0:0] OPT_GATE_CLOCK = 1'b0 +`else + localparam [0:0] OPT_GATE_CLOCK = 1'b0 +`endif `ifdef FORMAL , parameter F_LGDEPTH=8 `endif @@ -130,7 +109,7 @@ module zipaxil #( ) ( // {{{ input wire S_AXI_ACLK, S_AXI_ARESETN, - i_interrupt, + i_interrupt, i_cpu_reset, // Debug interface // {{{ // Debug interface -- inputs @@ -222,6 +201,9 @@ module zipaxil #( input wire [1:0] M_DATA_RRESP, // }}} // Accounting outputs ... to help us count stalls and usage + output wire o_cmd_reset, + output wire o_halted, + output wire o_gie, output wire o_op_stall, output wire o_pf_stall, output wire o_i_count @@ -234,6 +216,20 @@ module zipaxil #( // Declarations // {{{ + // localparam [0:0] OPT_NO_USERMODE = 1'b0; + localparam [0:0] IMPLEMENT_LOCK=0; + localparam C_DBG_DATA_WIDTH = 32; + localparam DBGLSB = $clog2(C_DBG_DATA_WIDTH/8); + localparam ADDRESS_WIDTH = C_AXI_ADDR_WIDTH; + localparam AW=ADDRESS_WIDTH-2; +`ifdef OPT_PIPELINED_BUS_ACCESS + localparam [0:0] OPT_PIPELINED_BUS_ACCESS = (OPT_PIPELINED); +`else + localparam [0:0] OPT_PIPELINED_BUS_ACCESS = 1'b0; +`endif + localparam OPT_LGDCACHE = (OPT_PIPELINED_BUS_ACCESS)? 1:0; + localparam [0:0] OPT_DCACHE = (OPT_LGDCACHE > 0); + localparam FETCH_LIMIT = 4; wire [31:0] cpu_debug; @@ -242,6 +238,7 @@ module zipaxil #( HALT_BIT = 10, CLEAR_CACHE_BIT = 11; localparam [0:0] OPT_LOWPOWER = 1'b1; + localparam [0:0] OPT_ALIGNMENT_ERR = 1'b0; localparam [0:0] SWAP_ENDIANNESS = 1'b0; // AXI-lite signal handling @@ -256,12 +253,12 @@ module zipaxil #( wire [4:0] dbg_read_reg; reg [31:0] dbg_write_data; wire [31:0] dbg_read_data; - wire cpu_dbg_stall, cpu_break; + wire cpu_dbg_stall, cpu_break, dbg_write_stall; wire [2:0] cpu_dbg_cc; // }}} reg reset_hold; - wire cpu_clken; + wire cpu_clken, cpu_clock, clk_gate; // CPU control registers // {{{ @@ -283,7 +280,7 @@ module zipaxil #( wire clear_dcache, mem_ce, bus_lock; wire [2:0] mem_op; wire [31:0] mem_cpu_addr; - wire [AW+1:0] mem_lock_pc; + wire [AW+1:0] mem_lock_pc; wire [31:0] mem_wdata; wire [4:0] mem_reg; wire mem_busy, mem_rdbusy, mem_pipe_stalled, mem_valid, @@ -338,8 +335,8 @@ module zipaxil #( ); assign dbg_write_ready = awskd_valid && wskd_valid - && ((wskd_strb==0) || awskd_addr[5] || !cpu_dbg_stall - || !dbg_write_valid) + && ((wskd_strb==0) || awskd_addr[5] + || !dbg_write_stall) && (!S_DBG_BVALID || S_DBG_BREADY); // dbg_write_valid @@ -348,7 +345,7 @@ module zipaxil #( always @(posedge S_AXI_ACLK) if (!S_AXI_ARESETN) dbg_write_valid <= 1'b0; - else if (!dbg_write_valid || !cpu_dbg_stall) + else if (!dbg_write_stall) begin dbg_write_valid <= dbg_write_ready && (|wskd_strb) && !awskd_addr[5]; end @@ -357,10 +354,11 @@ module zipaxil #( // dbg_write_reg // {{{ always @(posedge S_AXI_ACLK) - if (!dbg_write_valid || !cpu_dbg_stall) + if (!dbg_write_stall) begin dbg_write_reg <= awskd_addr[4:0]; - if (OPT_LOWPOWER && !dbg_write_valid) + if (OPT_LOWPOWER && (!dbg_write_ready || wskd_strb == 0 + || awskd_addr[5])) dbg_write_reg <= 0; end // }}} @@ -368,7 +366,7 @@ module zipaxil #( // dbg_write_data // {{{ always @(posedge S_AXI_ACLK) - if (!dbg_write_valid || !cpu_dbg_stall) + if (!dbg_write_stall) begin dbg_write_data <= wskd_data; if (OPT_LOWPOWER && !dbg_write_ready) @@ -486,14 +484,14 @@ module zipaxil #( initial reset_counter = RESET_DURATION; always @(posedge S_AXI_ACLK) - if (!S_AXI_ARESETN) + if (!S_AXI_ARESETN || i_cpu_reset) reset_counter <= RESET_DURATION; else if (reset_counter > 0) reset_counter <= reset_counter - 1; initial reset_hold = 1; always @(posedge S_AXI_ACLK) - if (!S_AXI_ARESETN) + if (!S_AXI_ARESETN || i_cpu_reset) reset_hold <= 1; else reset_hold <= (reset_counter > 1); @@ -513,7 +511,7 @@ module zipaxil #( // {{{ initial cmd_reset = 1'b1; always @(posedge S_AXI_ACLK) - if (!S_AXI_ARESETN) + if (!S_AXI_ARESETN || i_cpu_reset) cmd_reset <= 1'b1; else if (reset_hold) cmd_reset <= 1'b1; @@ -530,6 +528,8 @@ module zipaxil #( always @(posedge S_AXI_ACLK) if (!S_AXI_ARESETN) cmd_halt <= START_HALTED; + else if (i_cpu_reset && !dbg_write_ready && !dbg_write_stall) + cmd_halt <= START_HALTED; else if (cmd_reset && START_HALTED) cmd_halt <= START_HALTED; else begin @@ -591,7 +591,7 @@ module zipaxil #( // {{{ initial cmd_step = 1'b0; always @(posedge S_AXI_ACLK) - if (!S_AXI_ARESETN) + if (!S_AXI_ARESETN || i_cpu_reset) cmd_step <= 1'b0; else if (dbg_cmd_write && wskd_data[STEP_BIT] && wskd_strb[1]) cmd_step <= 1'b1; @@ -647,7 +647,7 @@ module zipaxil #( // {{{ .i_clk(S_AXI_ACLK), .i_reset(!S_AXI_ARESETN), - .i_cpu_reset(cmd_reset), + .i_cpu_reset(cmd_reset || i_cpu_reset), .i_halt(cmd_halt), .i_halted(f_cpu_halted), .i_clear_cache(cmd_clear_cache), @@ -669,23 +669,24 @@ module zipaxil #( .IMPLEMENT_DIVIDE(IMPLEMENT_DIVIDE), .IMPLEMENT_FPU(IMPLEMENT_FPU), .OPT_EARLY_BRANCHING(EARLY_BRANCHING), + .OPT_SIM(OPT_SIM), .OPT_CIS(OPT_CIS), // .OPT_NO_USERMODE(OPT_NO_USERMODE), .OPT_PIPELINED(OPT_PIPELINED), .OPT_PIPELINED_BUS_ACCESS(OPT_PIPELINED_BUS_ACCESS), // localparam [0:0] OPT_MEMPIPE = OPT_PIPELINED_BUS_ACCESS; .IMPLEMENT_LOCK(IMPLEMENT_LOCK), - .OPT_DCACHE(1'b0), + .OPT_DCACHE(OPT_DCACHE), // localparam [0:0] OPT_LOCK=(IMPLEMENT_LOCK)&&(OPT_PIPELINED); // parameter [0:0] WITH_LOCAL_BUS = 1'b1; - .OPT_GATE_CLOCK(1'b0) + .OPT_GATE_CLOCK(OPT_GATE_CLOCK) `ifdef FORMAL , .F_LGDEPTH(F_LGDEPTH) `endif // }}} ) core ( // {{{ - .i_clk(S_AXI_ACLK), .i_reset(cmd_reset), + .i_clk(cpu_clock), .i_reset(cmd_reset), .i_interrupt(i_interrupt), .o_clken(cpu_clken), // Debug interface @@ -727,6 +728,10 @@ module zipaxil #( // }}} ); `endif + assign o_cmd_reset = cmd_reset; + assign o_gie = cpu_dbg_cc[1]; + assign o_halted = !cpu_dbg_stall; + assign dbg_write_stall = dbg_write_valid&&(cpu_dbg_stall || !clk_gate); // }}} // o_debug -- the debugging bus input // {{{ @@ -736,6 +741,7 @@ module zipaxil #( // Verilator lint_off UNUSED wire dbg_unused; assign dbg_unused = &{ 1'b0, cpu_debug }; + // Verilator lint_on UNUSED `endif // }}} //////////////////////////////////////////////////////////////////////// @@ -814,7 +820,9 @@ module zipaxil #( axilpipe #( // {{{ .C_AXI_ADDR_WIDTH(C_AXI_ADDR_WIDTH), - .C_AXI_DATA_WIDTH(C_AXI_DATA_WIDTH) //, + .C_AXI_DATA_WIDTH(C_AXI_DATA_WIDTH), + .OPT_ALIGNMENT_ERR(OPT_ALIGNMENT_ERR), + .SWAP_WSTRB(SWAP_WSTRB) //, // .OPT_SIGN_EXTEND(OPT_SIGN_EXTEND) // }}} ) domem( @@ -842,8 +850,8 @@ module zipaxil #( // {{{ .M_AXI_AWVALID(M_DATA_AWVALID), .M_AXI_AWREADY(M_DATA_AWREADY), - .M_AXI_AWADDR(M_DATA_AWADDR), - .M_AXI_AWPROT(M_DATA_AWPROT), + .M_AXI_AWADDR( M_DATA_AWADDR), + .M_AXI_AWPROT( M_DATA_AWPROT), // .M_AXI_WVALID(M_DATA_WVALID), .M_AXI_WREADY(M_DATA_WREADY), @@ -852,19 +860,19 @@ module zipaxil #( // .M_AXI_BVALID(M_DATA_BVALID), .M_AXI_BREADY(M_DATA_BREADY), - .M_AXI_BRESP(M_DATA_BRESP), + .M_AXI_BRESP( M_DATA_BRESP), // }}} // Read interface // {{{ .M_AXI_ARVALID(M_DATA_ARVALID), .M_AXI_ARREADY(M_DATA_ARREADY), - .M_AXI_ARADDR(M_DATA_ARADDR), - .M_AXI_ARPROT(M_DATA_ARPROT), + .M_AXI_ARADDR( M_DATA_ARADDR), + .M_AXI_ARPROT( M_DATA_ARPROT), // .M_AXI_RVALID(M_DATA_RVALID), .M_AXI_RREADY(M_DATA_RREADY), - .M_AXI_RDATA(M_DATA_RDATA), - .M_AXI_RRESP(M_DATA_RRESP) + .M_AXI_RDATA( M_DATA_RDATA), + .M_AXI_RRESP( M_DATA_RRESP) // }}} // }}} ); @@ -876,8 +884,8 @@ module zipaxil #( .C_AXI_ADDR_WIDTH(C_AXI_ADDR_WIDTH), .C_AXI_DATA_WIDTH(C_AXI_DATA_WIDTH), .SWAP_ENDIANNESS(SWAP_ENDIANNESS), - .SWAP_WSTRB(1'b0), - .OPT_ALIGNMENT_ERR(1'b0), + .SWAP_WSTRB(SWAP_WSTRB), + .OPT_ALIGNMENT_ERR(OPT_ALIGNMENT_ERR), .OPT_LOWPOWER(OPT_LOWPOWER) // }}} ) domem( @@ -904,8 +912,8 @@ module zipaxil #( // {{{ .M_AXI_AWVALID(M_DATA_AWVALID), .M_AXI_AWREADY(M_DATA_AWREADY), - .M_AXI_AWADDR(M_DATA_AWADDR), - .M_AXI_AWPROT(M_DATA_AWPROT), + .M_AXI_AWADDR( M_DATA_AWADDR), + .M_AXI_AWPROT( M_DATA_AWPROT), // .M_AXI_WVALID(M_DATA_WVALID), .M_AXI_WREADY(M_DATA_WREADY), @@ -914,19 +922,19 @@ module zipaxil #( // .M_AXI_BVALID(M_DATA_BVALID), .M_AXI_BREADY(M_DATA_BREADY), - .M_AXI_BRESP(M_DATA_BRESP), + .M_AXI_BRESP( M_DATA_BRESP), // }}} // Read interface // {{{ .M_AXI_ARVALID(M_DATA_ARVALID), .M_AXI_ARREADY(M_DATA_ARREADY), - .M_AXI_ARADDR(M_DATA_ARADDR), - .M_AXI_ARPROT(M_DATA_ARPROT), + .M_AXI_ARADDR( M_DATA_ARADDR), + .M_AXI_ARPROT( M_DATA_ARPROT), // .M_AXI_RVALID(M_DATA_RVALID), .M_AXI_RREADY(M_DATA_RREADY), - .M_AXI_RDATA(M_DATA_RDATA), - .M_AXI_RRESP(M_DATA_RRESP) + .M_AXI_RDATA( M_DATA_RDATA), + .M_AXI_RRESP( M_DATA_RRESP) // }}} // }}} ); @@ -935,16 +943,54 @@ module zipaxil #( end endgenerate `endif // }}} + //////////////////////////////////////////////////////////////////////// + // + // (Optional) Clock gate + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + generate if (OPT_GATE_CLOCK) + begin : GATE_CPU_CLOCK + + reg gatep, gaten; + + always @(posedge S_AXI_ACLK) + if (!S_AXI_ARESETN) + gatep <= 1'b1; + else + gatep <= cpu_clken; + + always @(negedge S_AXI_ACLK) + if (!S_AXI_ARESETN) + gaten <= 1'b1; + else + gaten <= gatep; + + assign cpu_clock = S_AXI_ACLK && gaten; + assign clk_gate = gaten; + + end else begin : NO_CLOCK_GATE + + assign cpu_clock = S_AXI_ACLK; + assign clk_gate = 1'b1; + + end endgenerate + // }}} + // Make Verilator happy // {{{ // Verilator lint_off UNUSED wire unused; - assign unused = &{ 1'b0, cpu_clken, S_DBG_AWADDR[DBGLSB-1:0], + assign unused = &{ 1'b0, cpu_clken, + S_DBG_AWADDR[DBGLSB-1:0], mem_lock_pc, clear_dcache, S_DBG_ARADDR[DBGLSB-1:0], S_DBG_ARPROT, S_DBG_AWPROT, M_INSN_AWREADY, M_INSN_WREADY, - M_INSN_BVALID, M_INSN_BRESP }; + M_INSN_BVALID, M_INSN_BRESP + }; // Verilator lint_on UNUSED // }}} //////////////////////////////////////////////////////////////////////////////// diff --git a/rtl/cpu/zipbones.v b/rtl/cpu/zipbones.v index cd4e189..c12afb3 100644 --- a/rtl/cpu/zipbones.v +++ b/rtl/cpu/zipbones.v @@ -16,7 +16,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -47,43 +47,67 @@ module zipbones #( parameter RESET_ADDRESS=32'h1000_0000, ADDRESS_WIDTH=30, // CPU options + // LGICACHE // {{{ `ifdef OPT_TRADITIONAL_PFCACHE LGICACHE = 8, `else LGICACHE = 0, `endif + // }}} + // OPT_DCACHE + // {{{ `ifdef OPT_DCACHE // Set to zero for no data cache LGDCACHE = 10, `else LGDCACHE = 0, `endif + // }}} parameter [0:0] START_HALTED=0, parameter + // OPT_MPY + // {{{ `ifdef OPT_MULTIPLY OPT_MPY = `OPT_MULTIPLY, `else OPT_MPY = 0, `endif + // }}} + // OPT_DIV + // {{{ `ifdef OPT_DIVIDE parameter [0:0] OPT_DIV=1, `else parameter [0:0] OPT_DIV=0, `endif + // }}} + // OPT_FPU + // {{{ `ifdef OPT_IMPLEMENT_FPU parameter [0:0] OPT_FPU = 1, `else parameter [0:0] OPT_FPU = 0, `endif - parameter [0:0] OPT_LOCK = 1, - parameter RESET_DURATION = 10, // }}} + parameter [0:0] OPT_LOCK=1, + parameter [0:0] OPT_LOWPOWER=0, + parameter RESET_DURATION = 10, // Short-cut names // {{{ localparam // Derived parameters + // PHYSICAL_ADDRESS_WIDTH=ADDRESS_WIDTH, PAW=ADDRESS_WIDTH, +`ifdef OPT_MMU + // VIRTUAL_ADDRESS_WIDTH=30, +`else + // VIRTUAL_ADDRESS_WIDTH=PAW, +`endif + // LGTLBSZ = 6, + // VAW=VIRTUAL_ADDRESS_WIDTH, + // localparam AW=ADDRESS_WIDTH, + localparam DW=32, // Bus data width // }}} // Debug bit allocations // {{{ @@ -111,11 +135,11 @@ module zipbones #( // Wishbone master interface from the CPU // {{{ output wire o_wb_cyc, o_wb_stb, o_wb_we, - output wire [(PAW-1):0] o_wb_addr, - output wire [31:0] o_wb_data, - output wire [3:0] o_wb_sel, + output wire [(PAW-1):0] o_wb_addr, + output wire [DW-1:0] o_wb_data, + output wire [DW/8-1:0] o_wb_sel, input wire i_wb_stall, i_wb_ack, - input wire [31:0] i_wb_data, + input wire [DW-1:0] i_wb_data, input wire i_wb_err, // }}} // Incoming interrupts @@ -126,11 +150,11 @@ module zipbones #( // {{{ input wire i_dbg_cyc, i_dbg_stb, i_dbg_we, input wire [5:0] i_dbg_addr, - input wire [31:0] i_dbg_data, - input wire [3:0] i_dbg_sel, + input wire [DW-1:0] i_dbg_data, + input wire [DW/8-1:0] i_dbg_sel, output wire o_dbg_stall, output wire o_dbg_ack, - output wire [31:0] o_dbg_data + output wire [DW-1:0] o_dbg_data // }}} `ifdef DEBUG_SCOPE , output wire [31:0] o_cpu_debug @@ -203,7 +227,7 @@ module zipbones #( begin : INITIAL_RESET_HOLD // {{{ reg [$clog2(RESET_DURATION)-1:0] reset_counter; - reg hold; + reg r_reset_hold; initial reset_counter = RESET_DURATION; always @(posedge i_clk) @@ -212,14 +236,14 @@ module zipbones #( else if (reset_counter > 0) reset_counter <= reset_counter - 1; - initial hold = 1; + initial r_reset_hold = 1; always @(posedge i_clk) if (i_reset) - hold <= 1; + r_reset_hold <= 1; else - hold <= (reset_counter > 1); + r_reset_hold <= (reset_counter > 1); - assign reset_hold = hold; + assign reset_hold = r_reset_hold; `ifdef FORMAL always @(*) assert(reset_hold == (reset_counter != 0)); @@ -230,6 +254,7 @@ module zipbones #( assign reset_hold = 0; end endgenerate + // }}} // cmd_reset // {{{ @@ -326,6 +351,8 @@ module zipbones #( assign cpu_reset = (cmd_reset); + // cpu_status + // {{{ assign cpu_halt = (cmd_halt); // Values: // 0x10000 -> External interrupt is high @@ -348,10 +375,11 @@ module zipbones #( initial cmd_write = 0; always @(posedge i_clk) - if (i_reset || cpu_reset) + if (i_reset) cmd_write <= 1'b0; else if (!cmd_write || !cpu_dbg_stall) - cmd_write <= dbg_stb && dbg_we && !dbg_addr[5] && (|i_dbg_sel); + cmd_write <= dbg_stb && dbg_we && (|i_dbg_sel) + && !dbg_addr[5]; always @(posedge i_clk) if ((!cmd_write || !cpu_dbg_stall)&&(dbg_stb && dbg_we && !dbg_addr[5])) @@ -371,9 +399,9 @@ module zipbones #( (* anyseq *) reg [31:0] f_cpu_dbg_data; assign cpu_dbg_stall = f_cpu_stall; - assign cpu_break = f_cpu_break; - assign cpu_dbg_cc = f_cpu_dbg_cc; - assign cpu_dbg_data = f_cpu_dbg_data; + assign cpu_break = f_cpu_break; + assign cpu_dbg_cc = f_cpu_dbg_cc; + assign cpu_dbg_data = f_cpu_dbg_data; fdebug #( // {{{ @@ -406,27 +434,41 @@ module zipbones #( .IMPLEMENT_DIVIDE(OPT_DIV), .IMPLEMENT_FPU(OPT_FPU), .IMPLEMENT_LOCK(OPT_LOCK), +`ifdef VERILATOR + .OPT_SIM(1'b1), +`else + .OPT_SIM(1'b0), +`endif .WITH_LOCAL_BUS(0) // }}} ) thecpu( // {{{ .i_clk(i_clk), .i_reset(cpu_reset), .i_interrupt(i_ext_int), .o_cpu_clken(cpu_clken), + // Debug interface + // {{{ .i_halt(cpu_halt), .i_clear_cache(cmd_clear_cache), .i_dbg_wreg(cmd_waddr), .i_dbg_we(cmd_write), .i_dbg_data(cmd_wdata), .i_dbg_rreg(dbg_addr[4:0]), - .o_dbg_stall(cpu_dbg_stall), .o_dbg_reg(cpu_dbg_data), - .o_dbg_cc(cpu_dbg_cc), .o_break(cpu_break), + .o_dbg_stall(cpu_dbg_stall), + .o_dbg_reg(cpu_dbg_data), + .o_dbg_cc(cpu_dbg_cc), + .o_break(cpu_break), + // }}} + // Wishbone bus interface + // {{{ .o_wb_gbl_cyc(o_wb_cyc), .o_wb_gbl_stb(o_wb_stb), .o_wb_lcl_cyc(cpu_lcl_cyc), .o_wb_lcl_stb(cpu_lcl_stb), .o_wb_we(o_wb_we), .o_wb_addr(o_wb_addr), .o_wb_data(o_wb_data), .o_wb_sel(o_wb_sel), + // Return values from the Wishbone bus .i_wb_stall(i_wb_stall), .i_wb_ack(i_wb_ack), .i_wb_data(i_wb_data), .i_wb_err((i_wb_err)||(cpu_lcl_cyc)), + // }}} .o_op_stall(cpu_op_stall), .o_pf_stall(cpu_pf_stall), .o_i_count(cpu_i_count) `ifdef DEBUG_SCOPE @@ -436,9 +478,13 @@ module zipbones #( ); `endif // }}} - + //////////////////////////////////////////////////////////////////////// + // // Return debug response values // {{{ + //////////////////////////////////////////////////////////////////////// + // + // // assign dbg_odata = (dbg_addr[5])?cpu_status :cpu_dbg_data; always @(posedge i_clk) @@ -462,12 +508,15 @@ module zipbones #( dbg_ack <= dbg_pre_ack; always @(posedge i_clk) - if (dbg_pre_addr) - dbg_odata <= dbg_cpu_status; - else - dbg_odata <= cpu_dbg_data; + if (!OPT_LOWPOWER || dbg_pre_ack) + begin + if (dbg_pre_addr) + dbg_odata <= dbg_cpu_status; + else + dbg_odata <= cpu_dbg_data; + end - assign dbg_stall= (!cmd_write || !cpu_dbg_stall) && dbg_we && !dbg_addr[5]; + assign dbg_stall= reset_hold || ((cmd_write && cpu_dbg_stall) && dbg_we && !dbg_addr[5]); // }}} // }}} assign o_ext_int = (cmd_halt) && (!i_wb_stall); diff --git a/rtl/cpu/zipcore.v b/rtl/cpu/zipcore.v index b062cf8..55a9c1f 100644 --- a/rtl/cpu/zipcore.v +++ b/rtl/cpu/zipcore.v @@ -14,7 +14,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -56,6 +56,7 @@ module zipcore #( `endif parameter [0:0] OPT_EARLY_BRANCHING = 1, parameter [0:0] OPT_CIS = 1'b1, + parameter [0:0] OPT_SIM = 1'b0, parameter [0:0] OPT_PIPELINED = 1'b1, parameter [0:0] OPT_PIPELINED_BUS_ACCESS = (OPT_PIPELINED), parameter [0:0] IMPLEMENT_LOCK=1, @@ -277,14 +278,10 @@ module zipcore #( wire op_break; wire op_lock; -`ifdef VERILATOR - reg op_sim /* verilator public_flat */; - reg [22:0] op_sim_immv /* verilator public_flat */; - reg alu_sim /* verilator public_flat */; - reg [22:0] alu_sim_immv /* verilator public_flat */; -`else - wire op_sim = 1'b0; -`endif + wire op_sim /* verilator public_flat */; + wire [22:0] op_sim_immv /* verilator public_flat */; + wire alu_sim /* verilator public_flat */; + wire [22:0] alu_sim_immv /* verilator public_flat */; // }}} @@ -353,6 +350,8 @@ module zipcore #( reg pfpcset; reg [2:0] pfpcsrc; + + wire w_clken; // }}} // }}} @@ -441,7 +440,7 @@ module zipcore #( assign op_stall = (op_valid)&&( // {{{ - // Only stall if we're loaded w/validins and the + // Only stall if we're loaded w/valid insns and the // next stage is accepting our instruction (!adf_ce_unconditional)&&(!mem_ce) ) @@ -642,11 +641,7 @@ module zipcore #( .OPT_LOCK(OPT_LOCK), .OPT_OPIPE(OPT_PIPELINED_BUS_ACCESS), .OPT_NO_USERMODE(OPT_NO_USERMODE), -`ifdef VERILATOR - .OPT_SIM(1'b1), -`else - .OPT_SIM(1'b0), -`endif + .OPT_SIM(OPT_SIM), .OPT_CIS(OPT_CIS) // }}} ) instruction_decoder( @@ -1181,38 +1176,38 @@ module zipcore #( end endgenerate // }}} - // op_sim, op_sim_immv, alu_sim, alu_sim_immv + // op_sim, op_sim_immv // {{{ -`ifdef VERILATOR - always @(posedge i_clk) - if (op_ce) - begin - op_sim <= dcd_sim; - op_sim_immv <= dcd_sim_immv; - end else if (adf_ce_unconditional) - op_sim <= 1'b0; + generate if (OPT_SIM) + begin : OP_SIM + // + // Only execute this if OPT_SIM is true--that is, if we + // are running from a simulated environment. + // + reg r_op_sim; + reg [22:0] r_op_sim_immv; - // - // We need an extra ALU sim stage. - // - // It's not quite true that all instructions leaving the OP stage - // are committed. ALU instructions aren't committed until the next - // cycle. That way they don't need to wait to determine if a branch - // was taken or not. - always @(posedge i_clk) - begin - if (adf_ce_unconditional) - alu_sim <= op_sim && op_valid_alu; - else - alu_sim <= 1'b0; + always @(posedge i_clk) + if (op_ce) + begin + r_op_sim <= dcd_sim; + r_op_sim_immv <= dcd_sim_immv; + end else if (adf_ce_unconditional) + r_op_sim <= 1'b0; - if (adf_ce_unconditional) - alu_sim_immv <= op_sim_immv; + assign op_sim = r_op_sim; + assign op_sim_immv = r_op_sim_immv; - if (i_reset || clear_pipeline) - alu_sim <= 1'b0; - end -`endif + end else begin : NO_OP_SIM + + assign op_sim = 0; + assign op_sim_immv = 0; + + // Verilator lint_off UNUSED + wire op_sim_unused; + assign op_sim_unused = &{ 1'b0, dcd_sim, dcd_sim_immv }; + // Verilator lint_on UNUSED + end endgenerate // }}} // op_pc @@ -1801,6 +1796,169 @@ module zipcore #( assign o_mem_addr = op_Bv; assign o_mem_reg = op_R; + // }}} + + // Sim instructions, alu_sim, alu_sim_immv + generate if (OPT_SIM) + begin : ALU_SIM + reg r_alu_sim; + reg [22:0] r_alu_sim_immv; + + initial r_alu_sim = 1'b0; + always @(posedge i_clk) + begin + if (!i_reset && !clear_pipeline && adf_ce_unconditional + && op_sim && op_valid_alu) + begin + // Execute simulation only instructions + // {{{ + if ((op_sim_immv[19:10] == 10'h0)&&(op_sim_immv[8])) + begin // [N/S]EXIT + // {{{ + // $finish; + + // if (op_sim_immv[19:4] == 16'h0031) + // Exit(User reg), code cpu_wr_gpreg + // Verilog offers no support for this. + // Veri1ator might, but it isn't + // standard. + // if (op_sim_immv[19:4] == 16'h0030) + // Exit(Normal reg), code cpu_wr_gpreg + // $finish; + // if (op_sim_immv[19:8] == 12'h001) + // Exit(Immediate), code cpu_wr_gpreg + // $finish; + // }}} + end + + if (op_sim_immv[19:0] == 20'h2ff) + begin + // DUMP all registers + // {{{ + if (!op_gie) + begin + $write("sR0 : %08x ", regset[0]); + $write("sR1 : %08x ", regset[1]); + $write("sR2 : %08x ", regset[2]); + $write("sR3 : %08x\n",regset[3]); + + $write("sR4 : %08x ", regset[4]); + $write("sR5 : %08x ", regset[5]); + $write("sR6 : %08x ", regset[6]); + $write("sR7 : %08x\n",regset[7]); + + $write("sR8 : %08x ", regset[8]); + $write("sR9 : %08x ", regset[9]); + $write("sR10: %08x ", regset[10]); + $write("sR11: %08x\n",regset[11]); + + $write("sR12: %08x ", regset[12]); + $write("sSP : %08x ", regset[13]); + $write("sCC : %08x ", w_iflags); + $write("sPC : %08x\n", (!op_gie) ? op_pc : ipc); + $write("\n", (!op_gie) ? op_pc : ipc); + end + + $write("uR0 : %08x ", regset[16]); + $write("uR1 : %08x ", regset[17]); + $write("uR2 : %08x ", regset[18]); + $write("uR3 : %08x\n",regset[19]); + + $write("uR4 : %08x ", regset[20]); + $write("uR5 : %08x ", regset[21]); + $write("uR6 : %08x ", regset[22]); + $write("uR7 : %08x\n",regset[23]); + + $write("uR8 : %08x ", regset[24]); + $write("uR9 : %08x ", regset[25]); + $write("uR10: %08x ", regset[26]); + $write("uR11: %08x\n",regset[27]); + + $write("uR12: %08x ", regset[28]); + $write("uSP : %08x ", regset[29]); + $write("uCC : %08x ", w_uflags); + $write("uPC : %08x\n", (op_gie) ? op_pc : upc); + // }}} + end + + if (op_sim_immv[19:4] == 16'h0020) + begin + // Dump a register + // {{{ + $write("@%08x ", op_pc); + $write("%c", (op_gie) ? "s":"u"); + $write("R[%2d] = 0x", op_sim_immv[3:0]); + // Dump a register + if (wr_reg_ce && wr_reg_id == { 1'b1, op_sim_immv[3:0] }) + $display("%08x", wr_gpreg_vl); + else + $display("%08x", regset[{ op_gie, + op_sim_immv[3:0]}]); + // }}} + end + if (op_sim_immv[19:4] == 16'h0021) + begin + // Dump a user register + // {{{ + $write("@%08x u", op_pc); + $write("R[%2d] = 0x", op_sim_immv[3:0]); + if (wr_reg_ce && wr_reg_id == { 1'b1, op_sim_immv[3:0] }) + $display("%08x\n", wr_gpreg_vl); + else + $display("%08x\n", regset[{ 1'b1, + op_sim_immv[3:0]}]); + // }}} + end + if (op_sim_immv[19:4] == 16'h0023) + begin + // SOUT(user register) + // {{{ + if (wr_reg_ce && wr_reg_id == { 1'b1, op_sim_immv[3:0] }) + $write("%c", wr_gpreg_vl[7:0]); + else + $write("%c", regset[{ 1'b1, op_sim_immv[3:0]}][7:0]); + // }}} + end + if (op_sim_immv[19:4] == 16'h0022) + begin + // SOUT(register) + // {{{ + if (wr_reg_ce && wr_reg_id == { gie, op_sim_immv[3:0] }) + $write("%c", wr_gpreg_vl[7:0]); + else + $write("%c", regset[{ gie, op_sim_immv[3:0]}][7:0]); + // }}} + end + + if (op_sim_immv[19:8] == 12'h004) + begin + // SOUT(Immediate) + // {{{ + $write("%c", op_sim_immv[7:0]); + // }}} + end + + // ELSE unrecognized SIM instruction + + // Set alu_sim either way + r_alu_sim <= 1'b1; + // }}} + end else + r_alu_sim <= 1'b0; + + if (adf_ce_unconditional) + r_alu_sim_immv <= op_sim_immv; + end + + assign alu_sim = r_alu_sim; + assign alu_sim_immv = r_alu_sim_immv; + + end else begin : NO_ALU_SIM + + assign alu_sim = 0; + assign alu_sim_immv = 0; + + end endgenerate // }}} // }}} //////////////////////////////////////////////////////////////////////// @@ -2109,6 +2267,7 @@ module zipcore #( generate if (!OPT_GATE_CLOCK) begin : NO_CLOCK_GATE + assign w_clken = 1'b1; assign o_clken = 1'b1; end else begin : GEN_CLOCK_GATE @@ -2120,7 +2279,7 @@ module zipcore #( // always @(posedge i_clk) if (i_reset || (i_halt && r_halted && !i_dbg_we)) - r_clken <= i_mem_busy; + r_clken <= i_mem_busy || !i_halt; else if (!i_halt&& (!sleep || i_interrupt || pending_interrupt)) r_clken <= 1'b1; else // if (sleep || i_halt) @@ -2153,7 +2312,13 @@ module zipcore #( // if (!dcd_valid && !i_pf_illegal) r_clken <= 1'b1; end - assign o_clken = r_clken; + assign w_clken = r_clken; + + // Wake up on interrupts, debug write requests, or the raising + // of the halt flag if we're not sleeping. + assign o_clken = r_clken || i_dbg_we || i_clear_cache + || i_mem_busy + || (!i_halt && (i_interrupt || !sleep)); end endgenerate // }}} @@ -2822,10 +2987,7 @@ module zipcore #( (i_pf_valid)&&(!i_mem_busy)&&(!alu_busy) &&(!div_busy)&&(!fpu_busy) // Operations must either be valid, or illegal - &&((op_valid)||(dcd_illegal)) - // Decode stage must be either valid, in reset, - // or producing an illelgal instruction - &&((dcd_valid)||(i_pf_illegal))); + &&((dcd_valid)||(dcd_illegal))); // }}} end else begin // {{{ @@ -2957,7 +3119,7 @@ module zipcore #( dcd_rA, dcd_pipe, dcd_zI, dcd_A_stall, dcd_B_stall, dcd_F_stall, op_Rcc, op_pipe, op_lock, i_mem_pipe_stalled, prelock_stall, - dcd_F }; + dcd_F, w_clken }; generate if (AW+2 < 32) begin wire [31:(AW+2)] generic_ignore; @@ -4601,13 +4763,13 @@ module zipcore #( else if (!OPT_GATE_CLOCK) begin assert(o_clken); - end else if ($past(i_reset && !i_mem_busy)) + end else if ($past(i_reset && !i_mem_busy && i_halt)) begin - assert(!o_clken); + assert(!w_clken); end else if (i_mem_busy || div_busy || alu_busy || fpu_busy) begin assert(o_clken); - end else if ($past(i_interrupt && !i_halt)) + end else if ($past((i_interrupt || pending_interrupt) && !i_halt)) begin assert(o_clken); end else if (!sleep && !r_halted) @@ -4615,6 +4777,17 @@ module zipcore #( assert(o_clken); end + always @(posedge i_clk) + if (!OPT_GATE_CLOCK) + begin + assert(o_clken); + end else if (i_dbg_we || i_clear_cache || i_mem_busy) + begin + assert(o_clken); + end else if (!i_halt && (i_interrupt || !sleep)) + assert(o_clken); + + always @(posedge i_clk) if (!i_reset && sleep) begin diff --git a/rtl/cpu/zipcounter.v b/rtl/cpu/zipcounter.v index 0e32280..a2c32c6 100644 --- a/rtl/cpu/zipcounter.v +++ b/rtl/cpu/zipcounter.v @@ -30,7 +30,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/rtl/cpu/zipjiffies.v b/rtl/cpu/zipjiffies.v index f9e1412..99e0f4e 100644 --- a/rtl/cpu/zipjiffies.v +++ b/rtl/cpu/zipjiffies.v @@ -48,7 +48,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/rtl/cpu/zipsystem.v b/rtl/cpu/zipsystem.v index a8b16a6..729d31a 100644 --- a/rtl/cpu/zipsystem.v +++ b/rtl/cpu/zipsystem.v @@ -66,7 +66,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -79,11 +79,10 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// -// License: GPL, v3, as defined and found on www.gnu.org, // }}} -// http://www.gnu.org/licenses/gpl.html +// License: GPL, v3, as defined and found on www.gnu.org, // {{{ +// http://www.gnu.org/licenses/gpl.html // //////////////////////////////////////////////////////////////////////////////// // @@ -126,46 +125,69 @@ module zipsystem #( // {{{ parameter RESET_ADDRESS=32'h1000_0000, ADDRESS_WIDTH=30, + localparam DW=32, + // CPU options + // LGICACHE + // {{{ `ifdef OPT_TRADITIONAL_PFCACHE - LGICACHE=10, + parameter LGICACHE=10, `else - LGICACHE=0, + parameter LGICACHE=0, `endif + // }}} + // OPT_DCACHE + // {{{ `ifdef OPT_DCACHE // Set to zero for no data cache LGDCACHE=10, `else LGDCACHE=0, `endif + // }}} parameter [0:0] START_HALTED=1, parameter EXTERNAL_INTERRUPTS=1, + // OPT_MPY + // {{{ `ifdef OPT_MULTIPLY OPT_MPY = `OPT_MULTIPLY, `else OPT_MPY = 0, `endif + // }}} + // OPT_DIV + // {{{ `ifdef OPT_DIVIDE parameter [0:0] OPT_DIV=1, `else parameter [0:0] OPT_DIV=0, `endif + // }}} + // OPT_FPU + // {{{ `ifdef OPT_IMPLEMENT_FPU - parameter [0:0] OPT_FPU=1, + parameter [0:0] OPT_FPU = 1, `else - parameter [0:0] OPT_FPU=0, + parameter [0:0] OPT_FPU = 0, `endif + // }}} parameter [0:0] OPT_LOCK=1, + // OPT_DMA + // {{{ `ifdef INCLUDE_DMA_CONTROLLER parameter [0:0] OPT_DMA=1, `else parameter [0:0] OPT_DMA=0, `endif + // }}} parameter [0:0] OPT_LOWPOWER=0, + // OPT_ACCOUNTING + // {{{ `ifdef INCLUDE_ACCOUNTING_COUNTERS localparam [0:0] OPT_ACCOUNTING = 1'b1, `else localparam [0:0] OPT_ACCOUNTING = 1'b0, `endif + // }}} // Bus delay options // {{{ // While I hate adding delays to any bus access, this next @@ -250,8 +272,8 @@ module zipsystem #( // {{{ output wire o_wb_cyc, o_wb_stb, o_wb_we, output wire [(PAW-1):0] o_wb_addr, - output wire [31:0] o_wb_data, - output wire [3:0] o_wb_sel, + output wire [DW-1:0] o_wb_data, + output wire [DW/8-1:0] o_wb_sel, input wire i_wb_stall, i_wb_ack, input wire [31:0] i_wb_data, input wire i_wb_err, @@ -264,11 +286,11 @@ module zipsystem #( // {{{ input wire i_dbg_cyc, i_dbg_stb, i_dbg_we, input wire [6:0] i_dbg_addr, - input wire [31:0] i_dbg_data, - input wire [3:0] i_dbg_sel, + input wire [DW-1:0] i_dbg_data, + input wire [DW/8-1:0] i_dbg_sel, output wire o_dbg_stall, output wire o_dbg_ack, - output wire [31:0] o_dbg_data + output wire [DW-1:0] o_dbg_data // }}} `ifdef DEBUG_SCOPE , output wire [31:0] o_cpu_debug @@ -314,8 +336,12 @@ module zipsystem #( wire no_dbg_err; wire cpu_break, dbg_cmd_write; - reg cmd_reset, cmd_halt, cmd_step, cmd_clear_pf_cache, - reset_hold, cpu_halt; + reg cmd_reset, cmd_step, cmd_clear_cache; + reg cmd_write; + reg [4:0] cmd_waddr; + reg [31:0] cmd_wdata; + wire reset_hold; + reg cmd_halt; wire [2:0] cpu_dbg_cc; wire cpu_reset; @@ -397,8 +423,7 @@ module zipsystem #( // {{{ assign main_int_vector[5:0] = { ctri_int, tma_int, tmb_int, tmc_int, jif_int, dmac_int }; - generate - if (EXTERNAL_INTERRUPTS < 9) + generate if (EXTERNAL_INTERRUPTS < 9) assign main_int_vector[14:6] = { {(9-EXTERNAL_INTERRUPTS){1'b0}}, i_ext_int }; else @@ -524,12 +549,13 @@ module zipsystem #( assign dbg_cmd_write = (dbg_stb)&&(dbg_we) &&(dbg_addr[6:5] == DBG_ADDR_CTRL); // - // cmd_halt, reset_hold: Always start us off with an initial reset + // reset_hold: Always start us off with an initial reset // {{{ generate if (RESET_DURATION > 0) begin : INITIAL_RESET_HOLD - + // {{{ reg [$clog2(RESET_DURATION)-1:0] reset_counter; + reg r_reset_hold; initial reset_counter = RESET_DURATION; always @(posedge i_clk) @@ -538,64 +564,105 @@ module zipsystem #( else if (reset_counter > 0) reset_counter <= reset_counter - 1; - initial reset_hold = 1; + initial r_reset_hold = 1; always @(posedge i_clk) if (i_reset) - reset_hold <= 1; + r_reset_hold <= 1; else - reset_hold <= (reset_counter != 0); - - initial cmd_halt = START_HALTED; - always @(posedge i_clk) - if (i_reset) - cmd_halt <= START_HALTED; - else if (dbg_cmd_write) - cmd_halt <= ((dbg_idata[HALT_BIT])&&(!dbg_idata[STEP_BIT])); - - end else begin + r_reset_hold <= (reset_counter > 1); + assign reset_hold = r_reset_hold; +`ifdef FORMAL always @(*) - reset_hold = 0; + assert(reset_hold == (reset_counter != 0)); +`endif + // }}} + end else begin - always @(*) - cmd_halt = START_HALTED; + assign reset_hold = 0; end endgenerate // }}} // cmd_reset // {{{ + // Always start us off with an initial reset initial cmd_reset = 1'b1; always @(posedge i_clk) if (i_reset) cmd_reset <= 1'b1; + else if (reset_hold || wdt_reset) + cmd_reset <= 1'b1; + else if (cpu_break && !START_HALTED) + cmd_reset <= 1'b1; else - cmd_reset <= ((dbg_cmd_write)&&(dbg_idata[RESET_BIT])) - ||(wdt_reset) || reset_hold; + cmd_reset <= ((dbg_cmd_write)&&(dbg_idata[RESET_BIT])); + // }}} // }}} - // cpu_halt + // cmd_halt // {{{ - initial cpu_halt = START_HALTED; + initial cmd_halt = START_HALTED; always @(posedge i_clk) if (i_reset) - cpu_halt <= START_HALTED; - else if (cmd_reset) - cpu_halt <= cmd_halt; - else if (dbg_cmd_write) - cpu_halt <= ((dbg_idata[HALT_BIT])&&(!dbg_idata[STEP_BIT])); - else if ((cmd_step)||(cpu_break)) - cpu_halt <= 1'b1; + cmd_halt <= START_HALTED; + else if (cmd_reset && START_HALTED) + cmd_halt <= START_HALTED; + else begin + // {{{ + // When shall we release from a halt? Only if we have come to + // a full and complete stop. Even then, we only release if we + // aren't being given a command to step the CPU. + // + if (!cmd_write && !cpu_dbg_stall && dbg_cmd_write + && (!dbg_idata[HALT_BIT] || dbg_idata[STEP_BIT])) + cmd_halt <= 1'b0; + + // Reasons to halt + + // 1. Halt on any unhandled CPU exception. The cause of the + // exception must be cured before we can (re)start. + // If the CPU is configured to start immediately on power + // up, we leave it to reset on any exception instead. + if (cpu_break && START_HALTED) + cmd_halt <= 1'b1; + + // 2. Halt on any user request to halt. (Only valid if the + // STEP bit isn't also set) + if (dbg_cmd_write && dbg_idata[HALT_BIT] + && !dbg_idata[STEP_BIT]) + cmd_halt <= 1'b1; + + // 3. Halt on any user request to write to a CPU register + if (i_dbg_stb && dbg_we && !dbg_addr[5]) + cmd_halt <= 1'b1; + + // 4. Halt following any step command + if (cmd_step) + cmd_halt <= 1'b1; + + // 4. Halt following any clear cache + if (cmd_clear_cache) + cmd_halt <= 1'b1; + + // 5. Halt on any clear cache bit--independent of any step bit + if (dbg_cmd_write && dbg_idata[CLEAR_CACHE_BIT]) + cmd_halt <= 1'b1; + // }}} + end // }}} - // cmd_clear_pf_cache + // cmd_clear_cache // {{{ - initial cmd_clear_pf_cache = 1'b1; + initial cmd_clear_cache = 1'b0; always @(posedge i_clk) - if (i_reset) - cmd_clear_pf_cache <= 1'b1; - else - cmd_clear_pf_cache <= (dbg_cmd_write)&&(dbg_idata[CLEAR_CACHE_BIT]); + if (i_reset || cpu_reset) + cmd_clear_cache <= 1'b0; + else if (dbg_cmd_write && dbg_idata[CLEAR_CACHE_BIT] + && dbg_idata[HALT_BIT]) + cmd_clear_cache <= 1'b1; + else if (cmd_halt && !cpu_dbg_stall) + cmd_clear_cache <= 1'b0; // }}} // cmd_step @@ -604,8 +671,10 @@ module zipsystem #( always @(posedge i_clk) if (i_reset) cmd_step <= 1'b0; - else - cmd_step <= (dbg_cmd_write)&&(dbg_idata[STEP_BIT]); + else if (dbg_cmd_write && dbg_idata[STEP_BIT]) + cmd_step <= 1'b1; + else if (!cpu_dbg_stall) + cmd_step <= 1'b0; // }}} assign cpu_reset = (cmd_reset); @@ -644,6 +713,21 @@ module zipsystem #( // }}} assign cpu_gie = cpu_dbg_cc[1]; + + initial cmd_write = 0; + always @(posedge i_clk) + if (i_reset || cpu_reset) + cmd_write <= 1'b0; + else if (!cmd_write || !cpu_dbg_stall) + cmd_write <= dbg_stb && dbg_we && (|i_dbg_sel) + && (dbg_addr[6:5] == DBG_ADDR_CPU); + + always @(posedge i_clk) + if ((!cmd_write || !cpu_dbg_stall)&&(dbg_stb && dbg_we && !dbg_addr[5])) + begin + cmd_waddr <= dbg_addr[4:0]; + cmd_wdata <= dbg_idata; + end // }}} //////////////////////////////////////////////////////////////////////// // @@ -741,7 +825,7 @@ module zipsystem #( zipcounter mtask_ctr( // {{{ - i_clk, 1'b0, (!cpu_halt), sys_cyc, + i_clk, 1'b0, (!cmd_halt), sys_cyc, (sys_stb)&&(sel_counter)&&(sys_addr[2:0] == 3'b000), sys_we, sys_data, mtc_stall, mtc_ack, mtc_data, mtc_int @@ -791,7 +875,7 @@ module zipsystem #( zipcounter utask_ctr( // {{{ - i_clk,1'b0, (!cpu_halt)&&(cpu_gie), sys_cyc, + i_clk,1'b0, (!cmd_halt)&&(cpu_gie), sys_cyc, (sys_stb)&&(sel_counter)&&(sys_addr[2:0] == 3'b100), sys_we, sys_data, utc_stall, utc_ack, utc_data, utc_int @@ -1126,6 +1210,11 @@ module zipsystem #( .IMPLEMENT_DIVIDE(OPT_DIV), .IMPLEMENT_FPU(OPT_FPU), .IMPLEMENT_LOCK(OPT_LOCK), +`ifdef VERILATOR + .OPT_SIM(1'b1), +`else + .OPT_SIM(1'b0), +`endif .WITH_LOCAL_BUS(1'b1) // }}} ) thecpu( @@ -1134,28 +1223,30 @@ module zipsystem #( .o_cpu_clken(cpu_clken), // Debug interface // {{{ - .i_halt(cpu_halt), .i_clear_cache(cmd_clear_pf_cache), - .i_dbg_wreg(dbg_addr[4:0]), .i_dbg_we(cpu_dbg_we), - .i_dbg_data(dbg_idata), - .i_dbg_rreg(dbg_addr[4:0]), + .i_halt(cmd_halt), .i_clear_cache(cmd_clear_cache), + .i_dbg_wreg(cmd_waddr), .i_dbg_we(cmd_write), + .i_dbg_data(cmd_wdata), + .i_dbg_rreg(dbg_addr[4:0]), .o_dbg_stall(cpu_dbg_stall), - .o_dbg_reg(cpu_dbg_data), .o_dbg_cc(cpu_dbg_cc), + .o_dbg_reg(cpu_dbg_data), + .o_dbg_cc(cpu_dbg_cc), .o_break(cpu_break), // }}} // Wishbone bus interface // {{{ .o_wb_gbl_cyc(cpu_gbl_cyc), .o_wb_gbl_stb(cpu_gbl_stb), - .o_wb_lcl_cyc(cpu_lcl_cyc), .o_wb_lcl_stb(cpu_lcl_stb), - .o_wb_we(cpu_we), .o_wb_addr(cpu_addr), - .o_wb_data(cpu_data), .o_wb_sel(cpu_sel), - // Return values from the Wishbone bus - .i_wb_stall(cpu_stall), .i_wb_ack(cpu_ack), - .i_wb_data(cpu_idata), .i_wb_err(cpu_err), + .o_wb_lcl_cyc(cpu_lcl_cyc), + .o_wb_lcl_stb(cpu_lcl_stb), + .o_wb_we(cpu_we), .o_wb_addr(cpu_addr), + .o_wb_data(cpu_data), .o_wb_sel(cpu_sel), + // Return values from the Wishbone bus + .i_wb_stall(cpu_stall), .i_wb_ack(cpu_ack), + .i_wb_data(cpu_idata), .i_wb_err(cpu_err), // }}} - .o_op_stall(cpu_op_stall), .o_pf_stall(cpu_pf_stall), - .o_i_count(cpu_i_count) + .o_op_stall(cpu_op_stall), .o_pf_stall(cpu_pf_stall), + .o_i_count(cpu_i_count) `ifdef DEBUG_SCOPE - , o_cpu_debug + , o_cpu_debug `endif // }}} ); diff --git a/rtl/cpu/ziptimer.v b/rtl/cpu/ziptimer.v index a49b6ed..140103e 100644 --- a/rtl/cpu/ziptimer.v +++ b/rtl/cpu/ziptimer.v @@ -48,7 +48,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/rtl/cpu/zipwb.v b/rtl/cpu/zipwb.v index 494c694..2836737 100644 --- a/rtl/cpu/zipwb.v +++ b/rtl/cpu/zipwb.v @@ -76,7 +76,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -144,7 +144,11 @@ module zipwb #( `else parameter OPT_LGDCACHE = 0, `endif - +`ifdef VERILATOR + parameter [0:0] OPT_SIM = 1'b1, +`else + parameter [0:0] OPT_SIM = 1'b0, +`endif parameter [0:0] WITH_LOCAL_BUS = 1'b1, localparam AW=ADDRESS_WIDTH `ifdef FORMAL @@ -263,9 +267,10 @@ module zipwb #( .IMPLEMENT_FPU(IMPLEMENT_FPU), .OPT_EARLY_BRANCHING(EARLY_BRANCHING), .OPT_CIS(OPT_CIS), - .OPT_NO_USERMODE(OPT_NO_USERMODE), + .OPT_SIM(OPT_SIM), .OPT_PIPELINED(OPT_PIPELINED), .OPT_PIPELINED_BUS_ACCESS(OPT_MEMPIPE), + .OPT_NO_USERMODE(OPT_NO_USERMODE), .IMPLEMENT_LOCK(IMPLEMENT_LOCK) // localparam [0:0] OPT_LOCK=(IMPLEMENT_LOCK)&&(OPT_PIPELINED); // parameter [0:0] WITH_LOCAL_BUS = 1'b1; diff --git a/rtl/main.v b/rtl/main.v index 4dc8538..49272a6 100644 --- a/rtl/main.v +++ b/rtl/main.v @@ -19,7 +19,7 @@ // Copyright (C) 2017-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -479,7 +479,7 @@ module main(i_clk, i_reset, // {{{ // // BUS-LOGIC for wb - // + // {{{ // // wb Bus logic to handle SINGLE slaves // @@ -727,9 +727,11 @@ module main(i_clk, i_reset, }) ); + // End of bus logic for wb + // }}} // // BUS-LOGIC for wbu - // + // {{{ // // No class SINGLE peripherals on the "wbu" bus // @@ -836,6 +838,8 @@ module main(i_clk, i_reset, }) ); + // End of bus logic for wbu + // }}} // }}} //////////////////////////////////////////////////////////////////////// // @@ -927,10 +931,10 @@ module main(i_clk, i_reset, // `ifdef INCLUDE_ZIPCPU // {{{ - // + //////////////////////////////////////////////////////////////////////// // // The ZipCPU/ZipSystem BUS master - // + // {{{ // assign zip_int_vector = { alt_int_vector[14:8], sys_int_vector[14:6] }; zipsystem #( diff --git a/rtl/make.inc b/rtl/make.inc index 357ac7c..032e271 100644 --- a/rtl/make.inc +++ b/rtl/make.inc @@ -18,7 +18,7 @@ ## Copyright (C) 2017-2021, Gisselquist Technology, LLC ## {{{ ## This program is free software (firmware): you can redistribute it and/or -## modify it under the terms of the GNU General Public License as published +## 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. ## diff --git a/rtl/memdev.v b/rtl/memdev.v index dc0d62f..1f34a45 100644 --- a/rtl/memdev.v +++ b/rtl/memdev.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: memdev.v -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: This file is really simple: it creates an on-chip memory, @@ -17,11 +17,11 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -34,59 +34,74 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none -// -module memdev(i_clk, i_reset, - i_wb_cyc, i_wb_stb, i_wb_we, i_wb_addr, i_wb_data, i_wb_sel, - o_wb_stall, o_wb_ack, o_wb_data); - parameter LGMEMSZ=15, DW=32, EXTRACLOCK= 1; - parameter HEXFILE=""; - parameter [0:0] OPT_ROM = 1'b0; - localparam AW = LGMEMSZ - 2; - input wire i_clk, i_reset; - input wire i_wb_cyc, i_wb_stb, i_wb_we; - input wire [(AW-1):0] i_wb_addr; - input wire [(DW-1):0] i_wb_data; - input wire [(DW/8-1):0] i_wb_sel; - output wire o_wb_stall; - output reg o_wb_ack; - output reg [(DW-1):0] o_wb_data; - +// }}} +module memdev #( + // {{{ + parameter LGMEMSZ=15, DW=32, EXTRACLOCK= 1, + parameter HEXFILE="", + parameter [0:0] OPT_ROM = 1'b0, + localparam AW = LGMEMSZ - 2 + // }}} + ) ( + // {{{ + input wire i_clk, i_reset, + input wire i_wb_cyc, i_wb_stb, i_wb_we, + input wire [(AW-1):0] i_wb_addr, + input wire [(DW-1):0] i_wb_data, + input wire [(DW/8-1):0] i_wb_sel, + output wire o_wb_stall, + output reg o_wb_ack, + output reg [(DW-1):0] o_wb_data + // }}} + ); + + // Local declarations + // {{{ wire w_wstb, w_stb; wire [(DW-1):0] w_data; wire [(AW-1):0] w_addr; wire [(DW/8-1):0] w_sel; reg [(DW-1):0] mem [0:((1< for a copy. -// +// }}} // License: LGPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/lgpl.html // -// //////////////////////////////////////////////////////////////////////////////// // // `default_nettype none -// +// }}} // 290 raw, 372 w/ pipe, 410 cfg, 499 cfg w/pipe module qflexpress(i_clk, i_reset, i_wb_cyc, i_wb_stb, i_wb_we, i_wb_addr, i_wb_data, i_wb_sel, diff --git a/rtl/rtc/rtcalarm.v b/rtl/rtc/rtcalarm.v index bc9ba8d..b44a3a9 100644 --- a/rtl/rtc/rtcalarm.v +++ b/rtl/rtc/rtcalarm.v @@ -15,7 +15,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/rtl/rtc/rtcbare.v b/rtl/rtc/rtcbare.v index 3394e60..b991739 100644 --- a/rtl/rtc/rtcbare.v +++ b/rtl/rtc/rtcbare.v @@ -28,7 +28,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/rtl/rtc/rtcdate.v b/rtl/rtc/rtcdate.v index 5021c2c..95b3036 100644 --- a/rtl/rtc/rtcdate.v +++ b/rtl/rtc/rtcdate.v @@ -31,7 +31,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/rtl/rtc/rtclight.v b/rtl/rtc/rtclight.v index e919925..0b679f1 100644 --- a/rtl/rtc/rtclight.v +++ b/rtl/rtc/rtclight.v @@ -21,7 +21,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/rtl/rtc/rtcstopwatch.v b/rtl/rtc/rtcstopwatch.v index 3b19cdc..dda74e7 100644 --- a/rtl/rtc/rtcstopwatch.v +++ b/rtl/rtc/rtcstopwatch.v @@ -14,7 +14,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/rtl/rtc/rtctimer.v b/rtl/rtc/rtctimer.v index 48e9bae..616bc56 100644 --- a/rtl/rtc/rtctimer.v +++ b/rtl/rtc/rtctimer.v @@ -15,7 +15,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/rtl/sdspi/llsdspi.v b/rtl/sdspi/llsdspi.v index 50b6c40..e8c3d6a 100644 --- a/rtl/sdspi/llsdspi.v +++ b/rtl/sdspi/llsdspi.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: llsdspi.v -// +// {{{ // Project: SD-Card controller, using a shared SPI interface // // Purpose: This file implements the "lower-level" interface to the @@ -62,11 +62,11 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2016-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2016-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -79,70 +79,74 @@ // with this program. (It's in the $(ROOT)/doc directory, run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// +// }}} `default_nettype none // -module llsdspi(i_clk, i_reset, i_speed, i_cs, i_stb, i_byte, - o_cs_n, o_sclk, o_mosi, i_miso, - o_stb, o_byte, o_idle, i_bus_grant); - parameter SPDBITS = 7, - // Minimum startup clocks - STARTUP_CLOCKS = 150, - // System clocks to wait before the startup clock - // sequence - POWERUP_IDLE = 1000; - // - // This core was originally developed for a shared SPI bus - // implementation on a XuLA2-LX25 board--one that shared flash with - // the SD-card. Few cards support such an implementation any more, - // since per protocol CS high (inactive) and clock and data pins - // toggling could well put the SD card into it's SD mode instead of - // SPI mode. - parameter [0:0] OPT_SPI_ARBITRATION = 1'b0; - // - // - localparam [0:0] CSN_ON_STARTUP = 1'b1; - // - // The MOSI INACTIVE VALUE *MUST* be 1'b1 to be compliant - localparam [0:0] MOSI_INACTIVE_VALUE = 1'b1; - // - // Normally, an SPI transaction shuts the clock down when finished. - // If OPT_CONTINUOUS_CLOCK is set, the clock will be continuous. - // This also means that any driving program must be ready when the - // SDSPI is idle. - parameter [0:0] OPT_CONTINUOUS_CLOCK = 1'b0; - - // - input wire i_clk, i_reset; - // Parameters/setup - input wire [(SPDBITS-1):0] i_speed; - // The incoming interface - input wire i_cs; - input wire i_stb; - input wire [7:0] i_byte; - // The actual SPI interface - output reg o_cs_n, o_sclk, o_mosi; - input wire i_miso; - // The outgoing interface - output reg o_stb; - output reg [7:0] o_byte; - output reg o_idle; - // And whether or not we actually own the interface (yet) - input wire i_bus_grant; - +module llsdspi #( + // {{{ + parameter SPDBITS = 7, + // Minimum startup clocks + STARTUP_CLOCKS = 150, + // System clocks to wait before the startup + // clock sequence + POWERUP_IDLE = 1000, + // + // This core was originally developed for a shared SPI bus + // implementation on a XuLA2-LX25 board--one that shared flash + // with the SD-card. Few cards support such an implementation + // any more, since per protocol CS high (inactive) and clock + // and data pins toggling could well put the SD card into it's + // SD mode instead of SPI mode. + parameter [0:0] OPT_SPI_ARBITRATION = 1'b0, + // + // + localparam [0:0] CSN_ON_STARTUP = 1'b1, + // + // The MOSI INACTIVE VALUE *MUST* be 1'b1 to be compliant + localparam [0:0] MOSI_INACTIVE_VALUE = 1'b1, + // + // Normally, an SPI transaction shuts the clock down when + // finished. If OPT_CONTINUOUS_CLOCK is set, the clock will be + // continuous. This also means that any driving program must + // be ready when the SDSPI is idle. + parameter [0:0] OPT_CONTINUOUS_CLOCK = 1'b0 + // }}} + ) ( + // {{{ + input wire i_clk, i_reset, + // Parameters/setup + input wire [(SPDBITS-1):0] i_speed, + // The incoming interface + input wire i_cs, + input wire i_stb, + input wire [7:0] i_byte, + // The actual SPI interface + output reg o_cs_n, o_sclk, o_mosi, + input wire i_miso, + // The outgoing interface + output reg o_stb, + output reg [7:0] o_byte, + output reg o_idle, + // And whether or not we actually own the interface (yet) + input wire i_bus_grant + // }}} + ); + + // Signal / localparam declarations + // {{{ localparam [3:0] LLSDSPI_IDLE = 4'h0, LLSDSPI_HOTIDLE = 4'h1, LLSDSPI_WAIT = 4'h2, LLSDSPI_START = 4'h3, LLSDSPI_END = 4'hb; -// + // reg r_z_counter; reg [(SPDBITS-1):0] r_clk_counter; reg r_idle; @@ -152,14 +156,16 @@ module llsdspi(i_clk, i_reset, i_speed, i_cs, i_stb, i_byte, reg restart_counter; wire bus_grant; + reg startup_hold, powerup_hold; + // }}} assign bus_grant = (OPT_SPI_ARBITRATION ? i_bus_grant : 1'b1); - reg startup_hold, powerup_hold; - + // Wait for power up + // {{{ generate if (POWERUP_IDLE > 0) begin : WAIT_FOR_POWERUP - + // {{{ localparam POWERUP_BITS = $clog2(POWERUP_IDLE); reg [POWERUP_BITS-1:0] powerup_counter; @@ -182,9 +188,13 @@ module llsdspi(i_clk, i_reset, i_speed, i_cs, i_stb, i_byte, always @(*) powerup_hold = 0; end endgenerate + // }}} + // Send a minimum number of start up clocks after power up + // {{{ generate if (STARTUP_CLOCKS > 0) begin : WAIT_FOR_STARTUP + // {{{ localparam STARTUP_BITS = $clog2(STARTUP_CLOCKS); reg [STARTUP_BITS-1:0] startup_counter; @@ -210,22 +220,29 @@ module llsdspi(i_clk, i_reset, i_speed, i_cs, i_stb, i_byte, if (startup_counter > 0) assert(startup_hold); `endif + // }}} end else begin always @(*) startup_hold = 0; end endgenerate + // }}} assign byte_accepted = (i_stb)&&(o_idle); //////////////////////////////////////////////////////////////////////// // // Clock divider and speed control + // {{{ + //////////////////////////////////////////////////////////////////////// + // // initial r_clk_counter = 0; initial r_z_counter = 1'b1; + // restart_counter + // {{{ always @(*) if (OPT_CONTINUOUS_CLOCK || powerup_hold) restart_counter = !powerup_hold; @@ -246,7 +263,10 @@ module llsdspi(i_clk, i_reset, i_speed, i_cs, i_stb, i_byte, else restart_counter = !r_idle; end + // }}} + // r_clk_counter, r_z_counter + // {{{ always @(posedge i_clk) begin if (!r_z_counter) @@ -259,11 +279,19 @@ module llsdspi(i_clk, i_reset, i_speed, i_cs, i_stb, i_byte, r_z_counter <= (i_speed == 0); end end + // }}} + // }}} //////////////////////////////////////////////////////////////////////// // // Control o_stb, o_cs_n, and o_mosi + // {{{ + //////////////////////////////////////////////////////////////////////// // + // + + // o_cs_n, r_state + // {{{ initial o_cs_n = CSN_ON_STARTUP; initial r_state = LLSDSPI_IDLE; always @(posedge i_clk) @@ -307,15 +335,24 @@ module llsdspi(i_clk, i_reset, i_speed, i_cs, i_stb, i_byte, if (startup_hold) o_cs_n <= 1; end + // }}} + // r_ireg + // {{{ always @(posedge i_clk) if (r_z_counter && !o_sclk) r_ireg <= { r_ireg[6:0], i_miso }; + // }}} + // o_byte + // {{{ always @(posedge i_clk) if (r_z_counter && o_sclk && r_state == LLSDSPI_END) o_byte <= r_ireg; + // }}} + // r_idle + // {{{ initial r_idle = 0; always @(posedge i_clk) if (startup_hold || i_reset) @@ -332,7 +369,10 @@ module llsdspi(i_clk, i_reset, i_speed, i_cs, i_stb, i_byte, else r_idle <= 1'b0; end + // }}} + // o_sclk + // {{{ initial o_sclk = 1; always @(posedge i_clk) if (i_reset) @@ -345,7 +385,10 @@ module llsdspi(i_clk, i_reset, i_speed, i_cs, i_stb, i_byte, && (startup_hold || (i_cs && !o_cs_n) || !o_sclk)) o_sclk <= (r_state == LLSDSPI_WAIT) || !o_sclk; end + // }}} + // r_byte, o_mosi + // {{{ initial r_byte = -1; initial o_mosi = MOSI_INACTIVE_VALUE; always @(posedge i_clk) @@ -374,14 +417,20 @@ module llsdspi(i_clk, i_reset, i_speed, i_cs, i_stb, i_byte, o_mosi <= MOSI_INACTIVE_VALUE; end end + // }}} + // o_stb + // {{{ initial o_stb = 1'b0; always @(posedge i_clk) if (i_reset || startup_hold || !i_cs || !r_z_counter || !o_sclk) o_stb <= 1'b0; else o_stb <= (r_state >= LLSDSPI_END); + // }}} + // o_idle + // {{{ always @(*) begin if (OPT_CONTINUOUS_CLOCK) @@ -389,9 +438,18 @@ module llsdspi(i_clk, i_reset, i_speed, i_cs, i_stb, i_byte, else o_idle = (r_idle)&&(r_z_counter); end - + // }}} + // }}} +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal properties +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// `ifdef FORMAL -`endif +`endif // FORMAL +// }}} endmodule - - diff --git a/rtl/sdspi/sdspi.v b/rtl/sdspi/sdspi.v index a0351c7..59e1788 100644 --- a/rtl/sdspi/sdspi.v +++ b/rtl/sdspi/sdspi.v @@ -17,7 +17,7 @@ // Copyright (C) 2016-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -43,29 +43,39 @@ module sdspi #( // {{{ parameter [0:0] OPT_CARD_DETECT = 1'b1, // + // LGFIFOLN + // {{{ // LGFIFOLN defines the size of the internal memory in words. // An LGFIFOLN of 7 is appropriate for a 2^(7+2)=512 byte FIFO parameter LGFIFOLN = 7, + // }}} parameter POWERUP_IDLE = 1000, - // + // STARTUP_CLOCKS + // {{{ // Many SD-Cards require a minimum number of SPI clocks to get // them started. STARTUP_CLOCKS defines this number. Set this // to zero if you don't want to use this initialization // sequence. parameter STARTUP_CLOCKS = 75, - // + // }}} + // CKDIV_BITS + // {{{ // For my first design, using an 80MHz clock, 7 bits to the // clock divider was plenty. Now that I'm starting to use // faster and faster designs, it becomes important to // parameterize the number of bits in the clock divider. More // than 8, however, and the interface will need to change. parameter CKDIV_BITS = 8, - // + // }}} + // INITIAL_CLKDIV + // {{{ // The SPI frequency is given by the system clock frequency // divided by a (clock_divider + 1). INITIAL_CLKDIV provides // an initial value for this clock divider. parameter [CKDIV_BITS-1:0] INITIAL_CLKDIV = 8'h7c, - // + // }}} + // OPT_SPI_ARBITRATION + // {{{ // When I originally built this SDSPI controller, it was for an // environment where the SPI was shared. Doing this requires // feedback from an arbiter, to know when one SPI device has @@ -74,6 +84,7 @@ module sdspi #( // constant 1'b1 and set OPT_SPI_ARBITRATION to 1'b0 to remove // this extra logic. parameter [0:0] OPT_SPI_ARBITRATION = 1'b0, + // }}} // // parameter [0:0] OPT_EXTRA_WB_CLOCK = 1'b0, @@ -105,11 +116,12 @@ module sdspi #( // .. and whether or not we can use the SPI port input wire i_bus_grant, // And some wires for debugging it all + // output reg [DW-1:0] o_debug // }}} ); - // Local declarations + // Signal / parameter declarations // {{{ localparam [1:0] SDSPI_CMD_ADDRESS = 2'b00, SDSPI_DAT_ADDRESS = 2'b01, @@ -117,7 +129,6 @@ module sdspi #( SDSPI_FIFO_B_ADDR = 2'b11; localparam BLKBASE = 16; - reg dbg_trigger; // // Command register bit definitions @@ -128,8 +139,13 @@ module sdspi #( FIFO_ID_BIT = 12, USE_FIFO_BIT = 11, FIFO_WRITE_BIT = 10; + // + // Some WB simplifications: + // reg r_cmd_busy; + reg dbg_trigger; + wire wb_stb, write_stb, wb_cmd_stb, new_data; wire [AW-1:0] wb_addr; wire [DW-1:0] wb_data; @@ -177,6 +193,7 @@ module sdspi #( wire [7:0] cmd_out_byte; wire cmd_sent, cmd_valid, cmd_busy; wire [39:0] cmd_response; + reg rx_start; wire spi_write_to_fifo; wire rx_valid, rx_busy; @@ -190,13 +207,11 @@ module sdspi #( wire [7:0] tx_response; reg last_busy; - // }}} - // - // Some WB simplifications: - // - // Poss. delay the WB interaction + // }}} + + // Take an extra wishbone clock? // {{{ generate if (!OPT_EXTRA_WB_CLOCK) begin : EXTRA_WB_PASSTHROUGH @@ -249,11 +264,16 @@ module sdspi #( // }}} end endgenerate // }}} - + //////////////////////////////////////////////////////////////////////// + // + // Lower-level SDSPI driver + // {{{ + //////////////////////////////////////////////////////////////////////// // // Access to our lower-level SDSPI driver, the one that actually // uses/sets the SPI ports // + llsdspi #( // {{{ .SPDBITS(CKDIV_BITS), @@ -269,6 +289,14 @@ module sdspi #( i_bus_grant // }}} ); + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Command controller + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // assign w_reset = i_sd_reset || r_watchdog_err; @@ -283,6 +311,14 @@ module sdspi #( cmd_valid, cmd_response // }}} ); + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Receive data (not commands) + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // spirxdata spirxdatai( @@ -294,6 +330,14 @@ module sdspi #( rx_valid, rx_response // }}} ); + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Transmit/send data (not commands) to the SD card + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // spitxdata #(.RDDELAY(2)) spitxdatai( @@ -306,11 +350,18 @@ module sdspi #( tx_valid, tx_response // }}} ); + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Internal FIFO memory + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // // // Let's work with our FIFO memory here ... // - // always @(posedge i_clk) begin if ((write_stb)&&(wb_addr == SDSPI_CMD_ADDRESS)) @@ -580,7 +631,6 @@ module sdspi #( r_sdspi_clk <= INITIAL_CLKDIV; end // }}} - //////////////////////////////////////////////////////////////////////// // // Wishbone return logic @@ -648,6 +698,8 @@ module sdspi #( // {{{ //////////////////////////////////////////////////////////////////////// // + // + // Depends upon the i_card_detect signal. Set this signal to 1'b1 if // you your device doesn't have it. // @@ -748,5 +800,16 @@ module sdspi #( spi_read_from_fifo }; // verilator lint_on UNUSED // }}} +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal verification properties +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +`ifdef FORMAL +`endif +// }}} endmodule - diff --git a/rtl/sdspi/spicmd.v b/rtl/sdspi/spicmd.v index c078a99..41811fd 100644 --- a/rtl/sdspi/spicmd.v +++ b/rtl/sdspi/spicmd.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: spicmd.v -// +// {{{ // Project: SD-Card controller, using a shared SPI interface // // Purpose: @@ -10,11 +10,11 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2019-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2019-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -36,29 +36,32 @@ // // `default_nettype none -// -module spicmd(i_clk, i_reset, i_cmd_stb, i_cmd_type, i_cmd, i_cmd_data, o_busy, - o_ll_stb, o_ll_byte, i_ll_busy, i_ll_stb, i_ll_byte, - o_cmd_sent, o_rxvalid, o_response); - input wire i_clk, i_reset; - // - input wire i_cmd_stb; - input wire [1:0] i_cmd_type; - input wire [5:0] i_cmd; - input wire [31:0] i_cmd_data; - // - output reg o_busy; - output wire o_ll_stb; - output wire [7:0] o_ll_byte; - input wire i_ll_busy; - // - input wire i_ll_stb; - input wire [7:0] i_ll_byte; - // - output reg o_cmd_sent; - output reg o_rxvalid; - output reg [39:0] o_response; +// }}} +module spicmd ( + // {{{ + input wire i_clk, i_reset, + // + input wire i_cmd_stb, + input wire [1:0] i_cmd_type, + input wire [5:0] i_cmd, + input wire [31:0] i_cmd_data, + output reg o_busy, + // + output wire o_ll_stb, + output wire [7:0] o_ll_byte, + input wire i_ll_busy, + // + input wire i_ll_stb, + input wire [7:0] i_ll_byte, + // + output reg o_cmd_sent, + output reg o_rxvalid, + output reg [39:0] o_response + // }}} + ); + // Signal declarations + // {{{ reg almost_sent; reg [4:0] crc_valid_sreg; reg crc_busy; @@ -67,7 +70,12 @@ module spicmd(i_clk, i_reset, i_cmd_stb, i_cmd_type, i_cmd, i_cmd_data, o_busy, reg [7:0] crc_byte; reg rx_r1_byte, rx_check_busy, rxvalid; reg [2:0] rx_counter; + localparam CRC_POLYNOMIAL = 7'h09; // Was 8'h12 + reg [6:0] next_crc_byte; + // }}} + // o_busy + // {{{ initial o_busy = 1'b0; always @(posedge i_clk) if (i_reset) @@ -77,7 +85,10 @@ module spicmd(i_clk, i_reset, i_cmd_stb, i_cmd_type, i_cmd, i_cmd_data, o_busy, // else if (o_rxvalid) else if (rxvalid && !rx_check_busy) o_busy <= 1'b0; + // }}} + // shift_data + // {{{ initial shift_data = -1; always @(posedge i_clk) if (!o_busy && i_cmd_stb) @@ -88,23 +99,33 @@ module spicmd(i_clk, i_reset, i_cmd_stb, i_cmd_type, i_cmd, i_cmd_data, o_busy, if (crc_valid_sreg[0]) shift_data[39:32] <= crc_byte; end + // }}} assign o_ll_stb = o_busy; assign o_ll_byte = shift_data[39:32]; + // o_cmd_sent + // {{{ initial o_cmd_sent = 1'b0; always @(posedge i_clk) if (i_reset || !o_busy) { o_cmd_sent, almost_sent } <= 2'b00; else if (!o_cmd_sent && !i_ll_busy) { o_cmd_sent, almost_sent } <= { almost_sent, crc_valid_sreg[0] }; + // }}} + + // crc_valid_sreg + // {{{ initial crc_valid_sreg = 5'b10000; always @(posedge i_clk) if (!o_busy) crc_valid_sreg <= 5'b10000; else if (!i_ll_busy) crc_valid_sreg <= crc_valid_sreg >> 1; + // }}} + // crc_busy, crc_bit_counter + // {{{ initial crc_busy = 1'b0; initial crc_bit_counter = 20; always @(posedge i_clk) @@ -117,15 +138,19 @@ module spicmd(i_clk, i_reset, i_cmd_stb, i_cmd_type, i_cmd, i_cmd_data, o_busy, crc_bit_counter <= crc_bit_counter - 1; crc_busy <= (crc_bit_counter > 1); end + // }}} + // crc_shift_reg + // {{{ always @(posedge i_clk) if (!o_busy) crc_shift_reg <= { 2'b01, i_cmd, i_cmd_data }; else if (crc_busy) crc_shift_reg <= crc_shift_reg << 2; + // }}} - localparam CRC_POLYNOMIAL = 7'h09; // Was 8'h12 - reg [6:0] next_crc_byte; + // next_crc_byte + // {{{ always @(*) begin next_crc_byte = { crc_byte[6:1], 1'b0 }; @@ -136,14 +161,20 @@ module spicmd(i_clk, i_reset, i_cmd_stb, i_cmd_type, i_cmd, i_cmd_data, o_busy, else next_crc_byte = (next_crc_byte<<1); end + // }}} + // crc_byte + // {{{ initial crc_byte = 0; always @(posedge i_clk) if (!o_busy) crc_byte <= 1; else if (crc_busy) crc_byte <= { next_crc_byte, 1'b1 }; + // }}} + // rx_r1_byte, rx_counter, rxvalid, rx_check_busy + // {{{ initial rxvalid = 1'b0; initial rx_counter = 1; always @(posedge i_clk) @@ -167,14 +198,20 @@ module spicmd(i_clk, i_reset, i_cmd_stb, i_cmd_type, i_cmd, i_cmd_data, o_busy, if (rx_r1_byte && i_ll_byte != 0) rx_check_busy <= 1'b0; end + // }}} + // o_rxvalid + // {{{ initial o_rxvalid = 0; always @(posedge i_clk) if (i_reset || !o_busy) o_rxvalid <= 0; else if (rxvalid && !rx_check_busy) o_rxvalid <= 1; + // }}} + // o_response + // {{{ initial o_response = -1; always @(posedge i_clk) if (!o_busy) @@ -186,7 +223,16 @@ module spicmd(i_clk, i_reset, i_cmd_stb, i_cmd_type, i_cmd, i_cmd_data, o_busy, else o_response[31:0] <= { o_response[23:0], i_ll_byte }; end - + // }}} +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal properties +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// `ifdef FORMAL `endif endmodule diff --git a/rtl/sdspi/spirxdata.v b/rtl/sdspi/spirxdata.v index 0b7a815..0e88388 100644 --- a/rtl/sdspi/spirxdata.v +++ b/rtl/sdspi/spirxdata.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: spirxdata.v -// +// {{{ // Project: SD-Card controller, using a shared SPI interface // // Purpose: To handle all of the processing associated with receiving data @@ -13,11 +13,11 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2019-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2019-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -30,41 +30,43 @@ // with this program. (It's in the $(ROOT)/doc directory, run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none -// -module spirxdata(i_clk, i_reset, i_start, i_lgblksz, i_fifo, o_busy, - i_ll_stb, i_ll_byte, - o_write, o_addr, o_data, - o_rxvalid, o_response); - parameter DW = 32, AW = 8; - localparam CRC_POLYNOMIAL = 16'h1021; - // - input wire i_clk, i_reset; - // - input wire i_start; - input wire [3:0] i_lgblksz; - input wire i_fifo; - output reg o_busy; - // - input wire i_ll_stb; - input wire [7:0] i_ll_byte; - // - output reg o_write; - output reg [AW-1:0] o_addr; - output reg [DW-1:0] o_data; - // - output reg o_rxvalid; - output reg [7:0] o_response; - - +// }}} +module spirxdata #( + // {{{ + parameter DW = 32, AW = 8, + localparam CRC_POLYNOMIAL = 16'h1021 + // }}} + ) ( + // {{{ + input wire i_clk, i_reset, + // + input wire i_start, + input wire [3:0] i_lgblksz, + input wire i_fifo, + output reg o_busy, + // + input wire i_ll_stb, + input wire [7:0] i_ll_byte, + // + output reg o_write, + output reg [AW-1:0] o_addr, + output reg [DW-1:0] o_data, + // + output reg o_rxvalid, + output reg [7:0] o_response + // }}} + ); + + // Signal declarations + // {{{ reg error_token, start_token, token, received_token, done, lastaddr; reg all_mem_written, lastdata; @@ -79,8 +81,11 @@ module spirxdata(i_clk, i_reset, i_start, i_lgblksz, i_fifo, o_busy, reg crc_err, crc_active; reg [2:0] fill; reg [23:0] gearbox; + reg [15:0] first_crc_data; + // }}} - + // error_token + // {{{ always @(*) begin error_token = 0; @@ -90,7 +95,10 @@ module spirxdata(i_clk, i_reset, i_start, i_lgblksz, i_fifo, o_busy, if (!i_ll_stb || received_token) error_token = 0; end + // }}} + // start_token + // {{{ always @(*) begin start_token = 0; @@ -100,21 +108,32 @@ module spirxdata(i_clk, i_reset, i_start, i_lgblksz, i_fifo, o_busy, if (!i_ll_stb || received_token) start_token = 0; end + // }}} + // token + // {{{ always @(*) token = (start_token || error_token); + // }}} + // done + // {{{ always @(*) done = (i_ll_stb && (crc_byte>1)); + // }}} - + // received_token + // {{{ initial received_token = 0; always @(posedge i_clk) if (i_reset || !o_busy) received_token <= 0; else if (token) received_token <= 1; + // }}} + // o_busy + // {{{ initial o_busy = 0; always @(posedge i_clk) if (i_reset) @@ -123,14 +142,20 @@ module spirxdata(i_clk, i_reset, i_start, i_lgblksz, i_fifo, o_busy, o_busy <= i_start; else if (error_token || done) o_busy <= 0; + // }}} + // o_rxvalid + // {{{ initial o_rxvalid = 0; always @(posedge i_clk) if (i_reset || !o_busy) o_rxvalid <= 0; else if (error_token || done) o_rxvalid <= 1; + // }}} + // o_response + // {{{ initial o_response = 0; always @(posedge i_clk) if (i_reset || !o_busy) @@ -139,7 +164,10 @@ module spirxdata(i_clk, i_reset, i_start, i_lgblksz, i_fifo, o_busy, o_response <= i_ll_byte; else if (done) o_response <= (crc_err || (crc_data[7:0] != i_ll_byte)) ? 8'h10 : 0; + // }}} + // o_write + // {{{ initial o_write = 0; always @(posedge i_clk) if (i_reset || !o_busy) @@ -148,18 +176,27 @@ module spirxdata(i_clk, i_reset, i_start, i_lgblksz, i_fifo, o_busy, o_write <= (&fill) && i_ll_stb; else o_write <= 0; + // }}} - initial o_write = 0; + // o_data + // {{{ + initial o_data = 0; always @(posedge i_clk) if (received_token && !all_mem_written) o_data <= { gearbox, i_ll_byte }; + // }}} + // o_addr + // {{{ always @(posedge i_clk) if (!o_busy) o_addr <= { i_fifo, {(AW-1){1'b0}} }; else if (o_write && !lastaddr) o_addr <= o_addr + 1; + // }}} + // fill + // {{{ initial fill = 0; always @(posedge i_clk) begin @@ -173,27 +210,39 @@ module spirxdata(i_clk, i_reset, i_start, i_lgblksz, i_fifo, o_busy, else if (i_ll_stb) fill <= { fill[1:0], 1'b1 }; end + // }}} + // lastdata + // {{{ always @(posedge i_clk) if (!o_busy) lastdata <= 0; else if (!lastdata) lastdata <= (lastaddr && (&fill)); + // }}} + // all_mem_written + // {{{ initial all_mem_written = 0; always @(posedge i_clk) if (i_reset || !o_busy) all_mem_written <= 0; else if (o_write && lastaddr) all_mem_written <= 1; + // }}} + // crc_byte + // {{{ initial crc_byte = 0; always @(posedge i_clk) if (i_reset || !o_busy) crc_byte <= 0; else if (i_ll_stb && lastaddr && lastdata) crc_byte <= crc_byte + 1; + // }}} + // lastaddr, r_lgblksz_m3 + // {{{ initial r_lgblksz_m3 = 0; initial lastaddr = 0; always @(posedge i_clk) @@ -215,16 +264,24 @@ module spirxdata(i_clk, i_reset, i_start, i_lgblksz, i_fifo, o_busy, default: lastaddr <= (&o_addr[6:1]); // 512 bytes endcase end + // }}} //////////////////////////////////////////////////////////////////////// // // CRC calculation + // {{{ + //////////////////////////////////////////////////////////////////////// + // // + // new_data_byte + // {{{ always @(*) new_data_byte = (i_ll_stb && !all_mem_written); + // }}} - + // crc_fill, crc_active + // {{{ initial crc_fill = 0; initial crc_active = 0; always @(posedge i_clk) @@ -243,16 +300,20 @@ module spirxdata(i_clk, i_reset, i_start, i_lgblksz, i_fifo, o_busy, else crc_active <= (crc_fill > 1); end + // }}} + // crc_gearbox + // {{{ always @(posedge i_clk) if (!crc_active) crc_gearbox <= i_ll_byte; else crc_gearbox <= { crc_gearbox[8-3:0], 2'b00 }; + // }}} - reg [15:0] first_crc_data; - + // first_crc_data, next_crc_data + // {{{ always @(*) begin first_crc_data = crc_data << 1;; @@ -265,14 +326,20 @@ module spirxdata(i_clk, i_reset, i_start, i_lgblksz, i_fifo, o_busy, else next_crc_data = (first_crc_data << 1); end + // }}} + // crc_data + // {{{ initial crc_data = 0; always @(posedge i_clk) if (!o_busy) crc_data <= 0; else if (crc_active) crc_data <= next_crc_data; + // }}} + // crc_err + // {{{ initial crc_err = 0; always @(posedge i_clk) if (i_reset || !o_busy) @@ -281,7 +348,18 @@ module spirxdata(i_clk, i_reset, i_start, i_lgblksz, i_fifo, o_busy, crc_err <= (crc_data[15:8] != i_ll_byte); // else if (i_ll_stb && (crc_byte == 2) // crc_err <= (crc_data[7:0] != i_ll_byte); - + // }}} + // }}} +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal properties +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// `ifdef FORMAL `endif // FORMAL +// }}} endmodule diff --git a/rtl/sdspi/spitxdata.v b/rtl/sdspi/spitxdata.v index e4da675..eb50384 100644 --- a/rtl/sdspi/spitxdata.v +++ b/rtl/sdspi/spitxdata.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: spitxdata.v -// +// {{{ // Project: SD-Card controller, using a shared SPI interface // // Purpose: To handle all of the processing associated with sending data @@ -11,11 +11,11 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2016-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2016-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -28,49 +28,53 @@ // with this program. (It's in the $(ROOT)/doc directory, run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // // `default_nettype none -// -module spitxdata(i_clk, i_reset, i_start, i_lgblksz, i_fifo, o_busy, - o_read, o_addr, i_data, - i_ll_busy, o_ll_stb, o_ll_byte, - i_ll_stb, i_ll_byte, o_rxvalid, o_response); - parameter DW = 32, AW = 8, RDDELAY = 2; - localparam CRC_POLYNOMIAL = 16'h1021; - // - input wire i_clk, i_reset; - // - input wire i_start; - input wire [3:0] i_lgblksz; - input wire i_fifo; - output reg o_busy; - // - output reg o_read; - output reg [AW-1:0] o_addr; - input wire [DW-1:0] i_data; - // - input wire i_ll_busy; - output reg o_ll_stb; - output wire [7:0] o_ll_byte; - // - input wire i_ll_stb; - input wire [7:0] i_ll_byte; - // - output reg o_rxvalid; - output reg [7:0] o_response; - +// }}} +module spitxdata #( + // {{{ + parameter DW = 32, AW = 8, RDDELAY = 2, + localparam CRC_POLYNOMIAL = 16'h1021 + // }}} + ) ( + // {{{ + input wire i_clk, i_reset, + // + input wire i_start, + input wire [3:0] i_lgblksz, + input wire i_fifo, + output reg o_busy, + // + output reg o_read, + output reg [AW-1:0] o_addr, + input wire [DW-1:0] i_data, + // + input wire i_ll_busy, + output reg o_ll_stb, + output wire [7:0] o_ll_byte, + // + input wire i_ll_stb, + input wire [7:0] i_ll_byte, + // + output reg o_rxvalid, + output reg [7:0] o_response + // }}} + ); - reg [RDDELAY-1:0] rdvalid; - reg [8+DW-1:0] gearbox; - reg [1+(DW/8)-1:0] fill; - reg crc_flag, crc_stb, data_read, all_mem_read; + // Signal declarations + // {{{ + reg [RDDELAY-1:0] rdvalid; + reg [8+DW-1:0] gearbox; + reg [1+(DW/8)-1:0] fill; + reg crc_flag, crc_stb, data_read, + all_mem_read; reg lastaddr, data_sent, received_token, all_idle; @@ -80,10 +84,18 @@ module spitxdata(i_clk, i_reset, i_start, i_lgblksz, i_fifo, o_busy, reg [15:0] crc_data; reg token; + reg [2:0] r_lgblksz_m3; + reg [15:0] next_crc_data; + // }}} + // token + // {{{ always @(*) token = (data_sent && i_ll_stb && i_ll_byte[0] &&!i_ll_byte[4]); + // }}} + // o_busy + // {{{ initial o_busy = 0; always @(posedge i_clk) if (i_reset) @@ -92,7 +104,10 @@ module spitxdata(i_clk, i_reset, i_start, i_lgblksz, i_fifo, o_busy, o_busy <= i_start; else if (all_idle && i_ll_stb && (&i_ll_byte)) o_busy <= 0; + // }}} + // o_rxvalid, received_token + // {{{ initial o_rxvalid = 0; initial received_token = 0; always @(posedge i_clk) @@ -102,29 +117,42 @@ module spitxdata(i_clk, i_reset, i_start, i_lgblksz, i_fifo, o_busy, { received_token, o_rxvalid } <= 2'b11; else o_rxvalid <= 0; + // }}} + // all_idle + // {{{ initial all_idle = 0; always @(posedge i_clk) if (i_reset || !o_busy) all_idle <= 0; else if (received_token && i_ll_stb && (&i_ll_byte)) all_idle <= 1'b1; + // }}} + // o_response + // {{{ always @(posedge i_clk) if (token) o_response <= i_ll_byte; + // }}} // o_read & o_addr // 0: arbited read request // 1: read data // 2: muxed read data + + // rdvalid + // {{{ initial rdvalid = 0; always @(posedge i_clk) if (i_reset || !o_busy) rdvalid <= 0; else rdvalid <= { rdvalid[RDDELAY-2:0], o_read }; + // }}} + // o_ll_stb + // {{{ initial o_ll_stb = 0; always @(posedge i_clk) if (i_reset || !o_busy) @@ -133,7 +161,10 @@ module spitxdata(i_clk, i_reset, i_start, i_lgblksz, i_fifo, o_busy, o_ll_stb <= 1; else if (data_read && !fill[4]) o_ll_stb <= 0; + // }}} + // fill + // {{{ initial fill = 0; always @(posedge i_clk) begin @@ -163,9 +194,12 @@ module spitxdata(i_clk, i_reset, i_start, i_lgblksz, i_fifo, o_busy, else if (!o_busy) fill <= (i_start) ? 5'h10 : 0; end + // }}} assign o_ll_byte = gearbox[39:32]; + // crc_stb, o_read + // {{{ initial { crc_stb, o_read } = 0; always @(posedge i_clk) if (i_reset || !o_busy) @@ -182,39 +216,55 @@ module spitxdata(i_clk, i_reset, i_start, i_lgblksz, i_fifo, o_busy, end end else { crc_stb, o_read } <= 0; + // }}} + // o_addr + // {{{ always @(posedge i_clk) if (!o_busy) o_addr <= { i_fifo, {(AW-1){1'b0}} }; else if (o_read && !lastaddr) o_addr[AW-2:0] <= o_addr[AW-2:0] + 1; + // }}} + // all_mem_read + // {{{ initial all_mem_read = 0; always @(posedge i_clk) if (i_reset || !o_busy) all_mem_read <= 0; else if (o_read && lastaddr) all_mem_read <= 1; + // }}} + // crc_flag + // {{{ initial crc_flag = 0; always @(posedge i_clk) if (i_reset || !o_busy) crc_flag <= 0; else if (crc_stb) crc_flag <= 1; + // }}} + // data_read + // {{{ always @(*) data_read = crc_flag; + // }}} + // data_sent + // {{{ initial data_sent = 0; always @(posedge i_clk) if (i_reset || !o_busy) data_sent <= 1'b0; else if (data_read && !fill[3] && o_ll_stb && !i_ll_busy) data_sent <= 1'b1; + // }}} - reg [2:0] r_lgblksz_m3; - + // r_lgblksz_m3, lastaddr + // {{{ initial r_lgblksz_m3 = 0; initial lastaddr = 0; always @(posedge i_clk) @@ -236,11 +286,18 @@ module spitxdata(i_clk, i_reset, i_start, i_lgblksz, i_fifo, o_busy, default: lastaddr <= (&o_addr[6:1]); // 512 bytes endcase end + // }}} //////////////////////////////////////////////////////////////////////// // // CRC calculation + // {{{ + //////////////////////////////////////////////////////////////////////// // + // + + // crc_fill + // {{{ initial crc_fill = 0; always @(posedge i_clk) if (i_reset || !o_busy) @@ -258,15 +315,19 @@ module spitxdata(i_clk, i_reset, i_start, i_lgblksz, i_fifo, o_busy, else crc_active <= (crc_fill > 1); end + // }}} + // crc_gearbox + // {{{ always @(posedge i_clk) if (!crc_active) crc_gearbox <= i_data; else crc_gearbox <= { crc_gearbox[DW-3:0], 2'b00 }; + // }}} - reg [15:0] next_crc_data; - + // next_crc_data + // {{{ always @(*) begin next_crc_data = crc_data << 1;; @@ -279,13 +340,27 @@ module spitxdata(i_clk, i_reset, i_start, i_lgblksz, i_fifo, o_busy, else next_crc_data = (next_crc_data << 1); end + // }}} + // crc_data + // {{{ always @(posedge i_clk) if (!o_busy) crc_data <= 0; else if (crc_active) crc_data <= next_crc_data; - + // }}} + // }}} +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal properties +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// `ifdef FORMAL `endif +// }}} endmodule diff --git a/rtl/skidbuffer.v b/rtl/skidbuffer.v index 4c19d4d..b41bb9a 100644 --- a/rtl/skidbuffer.v +++ b/rtl/skidbuffer.v @@ -59,7 +59,7 @@ // Copyright (C) 2019-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -96,21 +96,20 @@ module skidbuffer #( // {{{ input wire i_clk, i_reset, input wire i_valid, - output reg o_ready, + output wire o_ready, input wire [DW-1:0] i_data, - output reg o_valid, + output wire o_valid, input wire i_ready, output reg [DW-1:0] o_data // }}} ); - reg [DW-1:0] r_data; + wire [DW-1:0] w_data; generate if (OPT_PASSTHROUGH) begin : PASSTHROUGH // {{{ - always @(*) - { o_valid, o_ready } = { i_valid, i_ready }; + assign { o_valid, o_ready } = { i_valid, i_ready }; always @(*) if (!i_valid && OPT_LOWPOWER) @@ -118,13 +117,13 @@ module skidbuffer #( else o_data = i_data; - always @(*) - r_data = 0; + assign w_data = 0; // }}} end else begin : LOGIC // We'll start with skid buffer itself // {{{ reg r_valid; + reg [DW-1:0] r_data; // r_valid // {{{ @@ -149,12 +148,13 @@ module skidbuffer #( r_data <= 0; else if ((!OPT_LOWPOWER || !OPT_OUTREG || i_valid) && o_ready) r_data <= i_data; + + assign w_data = r_data; // }}} // o_ready // {{{ - always @(*) - o_ready = !r_valid; + assign o_ready = !r_valid; // }}} // @@ -166,8 +166,7 @@ module skidbuffer #( // {{{ // o_valid // {{{ - always @(*) - o_valid = !i_reset && (i_valid || r_valid); + assign o_valid = !i_reset && (i_valid || r_valid); // }}} // o_data @@ -186,12 +185,16 @@ module skidbuffer #( // {{{ // o_valid // {{{ - initial if (OPT_INITIAL) o_valid = 0; + reg ro_valid; + + initial if (OPT_INITIAL) ro_valid = 0; always @(posedge i_clk) if (i_reset) - o_valid <= 0; + ro_valid <= 0; else if (!o_valid || i_ready) - o_valid <= (i_valid || r_valid); + ro_valid <= (i_valid || r_valid); + + assign o_valid = ro_valid; // }}} // o_data @@ -216,6 +219,14 @@ module skidbuffer #( end // }}} end endgenerate + + // Keep Verilator happy + // {{{ + // Verilator lint_off UNUSED + wire unused; + assign unused = &{ 1'b0, w_data }; + // Verilator lint_on UNUSED + // }}} //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// diff --git a/rtl/toplevel.v b/rtl/toplevel.v index 5472f4c..b380080 100644 --- a/rtl/toplevel.v +++ b/rtl/toplevel.v @@ -18,7 +18,7 @@ // Copyright (C) 2017-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -170,7 +170,7 @@ module toplevel(i_clk, IOBUF sd_cmd_buf(.T(1'b0),.O(i_sd_cmd), .I(w_sd_cmd), .IO(io_sd_cmd)); IOBUF sd_dat3_bf(.T(1'b0),.O(i_sd[3]),.I(w_sd_data[3]),.IO(io_sd[3])); - + assign s_clk = i_clk; diff --git a/rtl/wbgpio.v b/rtl/wbgpio.v index bc01628..5835084 100644 --- a/rtl/wbgpio.v +++ b/rtl/wbgpio.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: wbgpio.v -// +// {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // // Purpose: This extremely simple GPIO controller, although minimally @@ -33,11 +33,11 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -50,57 +50,72 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none -// -module wbgpio(i_clk, i_wb_cyc, i_wb_stb, i_wb_we, i_wb_data, i_wb_sel, - o_wb_stall, o_wb_ack, o_wb_data, - i_gpio, o_gpio, o_int); - parameter NIN=16, NOUT=16; - parameter [(NOUT-1):0] DEFAULT=0; - input wire i_clk; - // - input wire i_wb_cyc, i_wb_stb, i_wb_we; - input wire [31:0] i_wb_data; - input wire [32/8-1:0] i_wb_sel; - // - output wire o_wb_stall; - output wire o_wb_ack; - output wire [31:0] o_wb_data; - // - input wire [(NIN-1):0] i_gpio; - output reg [(NOUT-1):0] o_gpio; - // - output reg o_int; +// }}} +module wbgpio #( + // {{{ + parameter NIN=16, NOUT=16, + parameter [(NOUT-1):0] DEFAULT=0 + // }}} + ) ( + // {{{ + input wire i_clk, + // + input wire i_wb_cyc, i_wb_stb, i_wb_we, + input wire [31:0] i_wb_data, + input wire [32/8-1:0] i_wb_sel, + // + output wire o_wb_stall, + output wire o_wb_ack, + output wire [31:0] o_wb_data, + // + input wire [(NIN-1):0] i_gpio, + output reg [(NOUT-1):0] o_gpio, + // + output reg o_int + // }}} + ); + + // Local declarations + // {{{ + reg [(NIN-1):0] x_gpio, q_gpio, r_gpio; + wire [15:0] hi_bits, low_bits; + // }}} assign o_wb_ack = i_wb_stb; assign o_wb_stall = 1'b0; + // o_gpio + // {{{ // 9LUT's, 16 FF's initial o_gpio = DEFAULT; always @(posedge i_clk) if ((i_wb_stb)&&(i_wb_we)) o_gpio <= ((o_gpio)&(~i_wb_data[(NOUT+16-1):16])) |((i_wb_data[(NOUT-1):0])&(i_wb_data[(NOUT+16-1):16])); + // }}} - reg [(NIN-1):0] x_gpio, q_gpio, r_gpio; // 3 LUTs, 33 FF's + // {{{ always @(posedge i_clk) begin { r_gpio, q_gpio, x_gpio } <= { q_gpio, x_gpio, i_gpio }; o_int <= (x_gpio != q_gpio); end + // }}} - wire [15:0] hi_bits, low_bits; + // o_wb_data + // {{{ assign hi_bits[ (NIN -1):0] = r_gpio; assign low_bits[(NOUT-1):0] = o_gpio; + generate if (NIN < 16) assign hi_bits[ 15: NIN] = 0; @@ -109,10 +124,13 @@ module wbgpio(i_clk, i_wb_cyc, i_wb_stb, i_wb_we, i_wb_data, i_wb_sel, endgenerate assign o_wb_data = { hi_bits, low_bits }; + // }}} // Make Verilator happy + // {{{ // verilator lint_off UNUSED wire unused; assign unused = &{ 1'b0, i_wb_cyc, i_wb_data[31:0], i_wb_sel }; // verilator lint_on UNUSED + // }}} endmodule diff --git a/rtl/wbscope/wbscopc.v b/rtl/wbscope/wbscopc.v index b92be23..b4227d6 100644 --- a/rtl/wbscope/wbscopc.v +++ b/rtl/wbscope/wbscopc.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: wbscopc.v -// +// {{{ // Project: WBScope, a wishbone hosted scope // // Purpose: This scope is identical in function to the wishbone scope @@ -42,11 +42,11 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -59,45 +59,61 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // // `default_nettype none -// -module wbscopc(i_data_clk, i_ce, i_trigger, i_data, - i_wb_clk, i_wb_cyc, i_wb_stb, i_wb_we, i_wb_addr, i_wb_data, i_wb_sel, - o_wb_stall, o_wb_ack, o_wb_data, - o_interrupt); - parameter [4:0] LGMEM = 5'd10; - parameter BUSW = 32, NELM=(BUSW-1); - parameter [0:0] SYNCHRONOUS=1; - parameter HOLDOFFBITS=20; - parameter [(HOLDOFFBITS-1):0] DEFAULT_HOLDOFF = ((1<<(LGMEM-1))-4); - parameter STEP_BITS=BUSW-1; - parameter [(STEP_BITS-1):0] MAX_STEP= {(STEP_BITS){1'b1}}; - // The input signals that we wish to record - input wire i_data_clk, i_ce, i_trigger; - input wire [(NELM-1):0] i_data; - // The WISHBONE bus for reading and configuring this scope - input wire i_wb_clk, i_wb_cyc, i_wb_stb, i_wb_we; - input wire i_wb_addr; // One address line only - input wire [(BUSW-1):0] i_wb_data; - input wire [(BUSW/8-1):0] i_wb_sel; - output wire o_wb_stall, o_wb_ack; - output reg [(BUSW-1):0] o_wb_data; - // And, finally, for a final flair --- offer to interrupt the CPU after - // our trigger has gone off. This line is equivalent to the scope - // being stopped. It is not maskable here. - output wire o_interrupt; - - - - reg [(LGMEM-1):0] raddr; +// }}} +module wbscopc #( + // {{{ + parameter [4:0] LGMEM = 5'd10, + parameter BUSW = 32, NELM=(BUSW-1), + parameter [0:0] SYNCHRONOUS=1, + parameter HOLDOFFBITS=20, + parameter [(HOLDOFFBITS-1):0] DEFAULT_HOLDOFF + = ((1<<(LGMEM-1))-4), + parameter STEP_BITS=BUSW-1, + parameter [(STEP_BITS-1):0] MAX_STEP= {(STEP_BITS){1'b1}} + // }}} + ) ( + // {{{ + // The input signals that we wish to record + input wire i_data_clk, i_ce, i_trigger, + input wire [(NELM-1):0] i_data, + // The WISHBONE bus for reading and configuring this scope + // {{{ + input wire i_wb_clk, i_wb_cyc, + i_wb_stb, i_wb_we, + input wire i_wb_addr, // One address line only + input wire [(BUSW-1):0] i_wb_data, + input wire [(BUSW/8-1):0] i_wb_sel, + output wire o_wb_stall, o_wb_ack, + output reg [(BUSW-1):0] o_wb_data, + // }}} + // And, finally, for a final flair --- offer to interrupt the + // CPU after our trigger has gone off. This line is equivalent + // to the scope being stopped. It is not maskable here. + output wire o_interrupt + // }}} + ); + + // Signal declarations + // {{{ + // Pseudo bus signals + // {{{ + wire write_stb, read_from_data, write_to_control; + reg [31:0] o_bus_data; + wire bus_clock; + reg read_address; + wire [BUSW-1:0] i_bus_data; + // }}} + + reg [(LGMEM-1):0] raddr, waddr; reg [(BUSW-1):0] mem[0:((1< 0) begin @@ -139,7 +239,7 @@ module wbscopc(i_data_clk, i_ce, i_trigger, i_data, // Resets are synchronous to the bus clock, not the data clock // so do a clock transfer here - initial q_iflags = 3'b000; + initial { q_iflags, r_iflags } = 6'h0; initial r_reset_complete = 1'b0; always @(posedge i_data_clk) begin @@ -152,13 +252,13 @@ module wbscopc(i_data_clk, i_ce, i_trigger, i_data, assign dw_manual_trigger = r_iflags[1]; assign dw_disable_trigger = r_iflags[0]; - (* ASYNC_REG = "TRUE" *) reg q_reset_complete; - reg qq_reset_complete; + (* ASYNC_REG = "TRUE" *) reg q_reset_complete, + qq_reset_complete; // Pass an acknowledgement back from the data clock to the bus // clock that the reset has been accomplished initial q_reset_complete = 1'b0; initial qq_reset_complete = 1'b0; - always @(posedge i_wb_clk) + always @(posedge bus_clock) begin q_reset_complete <= r_reset_complete; qq_reset_complete <= q_reset_complete; @@ -166,64 +266,80 @@ module wbscopc(i_data_clk, i_ce, i_trigger, i_data, assign bw_reset_complete = qq_reset_complete; end endgenerate - + // }}} + //////////////////////////////////////////////////////////////////////// // // Set up the trigger + // {{{ + //////////////////////////////////////////////////////////////////////// // // - // Write with the i-clk, or input clock. All outputs read with the - // WISHBONE-clk, or i_wb_clk clock. - reg dr_triggered, dr_primed; - wire dw_trigger; + + // dw_trigger -- trigger wire, defined on the data clock + // {{{ + // Write with the i_clk, or input clock. All outputs read with the + // bus clock, or i_wb_clk as we've called it here. assign dw_trigger = (dr_primed)&&( ((i_trigger)&&(!dw_disable_trigger)) ||(dw_manual_trigger)); + // }}} + + // dr_triggered + // {{{ initial dr_triggered = 1'b0; always @(posedge i_data_clk) - if (dw_reset) - dr_triggered <= 1'b0; - else if ((i_ce)&&(dw_trigger)) - dr_triggered <= 1'b1; + if (dw_reset) + dr_triggered <= 1'b0; + else if ((i_ce)&&(dw_trigger)) + dr_triggered <= 1'b1; + // }}} // // Determine when memory is full and capture is complete // // Writes take place on the data clock - // The counter is unsigned - (* ASYNC_REG="TRUE" *) reg [(HOLDOFFBITS-1):0] holdoff_counter; - reg dr_stopped; - initial dr_stopped = 1'b0; + // holdoff_counter + // {{{ + // The counter is unsigned initial holdoff_counter = 0; always @(posedge i_data_clk) - if (dw_reset) - holdoff_counter <= 0; - else if ((i_ce)&&(dr_triggered)&&(!dr_stopped)) - begin - holdoff_counter <= holdoff_counter + 1'b1; - end - + if (dw_reset) + holdoff_counter <= 0; + else if ((i_ce)&&(dr_triggered)&&(!dr_stopped)) + holdoff_counter <= holdoff_counter + 1'b1; + // }}} + + // dr_stopped + // {{{ + initial dr_stopped = 1'b0; always @(posedge i_data_clk) - if ((!dr_triggered)||(dw_reset)) - dr_stopped <= 1'b0; - else if ((i_ce)&&(!dr_stopped)) - begin - if (HOLDOFFBITS > 1) // if (i_ce) - dr_stopped <= (holdoff_counter >= br_holdoff); - else if (HOLDOFFBITS <= 1) - dr_stopped <= ((i_ce)&&(dw_trigger)); - end + if ((!dr_triggered)||(dw_reset)) + dr_stopped <= 1'b0; + else if ((i_ce)&&(!dr_stopped)) + begin + if (HOLDOFFBITS > 1) // if (i_ce) + dr_stopped <= (holdoff_counter >= br_holdoff); + else if (HOLDOFFBITS <= 1) + dr_stopped <= ((i_ce)&&(dw_trigger)); + end + // }}} - localparam DLYSTOP=5; - reg [(DLYSTOP-1):0] dr_stop_pipe; always @(posedge i_data_clk) - if (dw_reset) - dr_stop_pipe <= 0; - else if (i_ce) - dr_stop_pipe <= { dr_stop_pipe[(DLYSTOP-2):0], dr_stopped }; + if (dw_reset) + dr_stop_pipe <= 0; + else if (i_ce) + dr_stop_pipe <= { dr_stop_pipe[(DLYSTOP-2):0], dr_stopped }; - wire dw_final_stop; assign dw_final_stop = dr_stop_pipe[(DLYSTOP-1)]; + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Write to memory + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // // A big part of this scope is the run length of any particular // data value. Hence, when the address line (i.e. data[31]) @@ -234,11 +350,9 @@ module wbscopc(i_data_clk, i_ce, i_trigger, i_data, // data changes, but increment it on all other clocks. Should the // address difference get to our maximum value, we let it saturate // rather than overflow. - reg [(STEP_BITS-1):0] ck_addr; - reg [(NELM-1):0] qd_data; - reg dr_force_write, dr_run_timeout, - new_data; + // dr_force_write, dr_force_inhibit + // {{{ // // The "dr_force_write" logic here is designed to make sure we write // at least every MAX_STEP samples, and that we stop as soon as @@ -247,109 +361,123 @@ module wbscopc(i_data_clk, i_ce, i_trigger, i_data, // doesn't have enough transitions to fill our buffer, we'll at least // fill the buffer with repeats. // - reg dr_force_inhibit; initial ck_addr = 0; initial dr_force_write = 1'b0; always @(posedge i_data_clk) - if (dw_reset) - begin - dr_force_write <= 1'b1; - dr_force_inhibit <= 1'b0; - end else if (i_ce) - begin - dr_force_inhibit <= (dr_force_write); - if ((dr_run_timeout)&&(!dr_force_write)&&(!dr_force_inhibit)) - dr_force_write <= 1'b1; - else if (((dw_trigger)&&(!dr_triggered))||(!dr_primed)) - dr_force_write <= 1'b1; - else - dr_force_write <= 1'b0; - end + if (dw_reset) + begin + dr_force_write <= 1'b1; + dr_force_inhibit <= 1'b0; + end else if (i_ce) + begin + dr_force_inhibit <= (dr_force_write); + if ((dr_run_timeout)&&(!dr_force_write)&&(!dr_force_inhibit)) + dr_force_write <= 1'b1; + else if (((dw_trigger)&&(!dr_triggered))||(!dr_primed)) + dr_force_write <= 1'b1; + else + dr_force_write <= 1'b0; + end + // }}} - // - // Keep track of how long it has been since the last write - // + // ck_addr: Keep track of how long it has been since the last write + // {{{ always @(posedge i_data_clk) - if (dw_reset) + if (dw_reset) + ck_addr <= 0; + else if (i_ce) + begin + if ((dr_force_write)||(new_data)||(dr_stopped)) ck_addr <= 0; - else if (i_ce) - begin - if ((dr_force_write)||(new_data)||(dr_stopped)) - ck_addr <= 0; - else - ck_addr <= ck_addr + 1'b1; - end + else + ck_addr <= ck_addr + 1'b1; + end + // }}} + // dr_run_timeout + // {{{ always @(posedge i_data_clk) - if (dw_reset) - dr_run_timeout <= 1'b1; - else if (i_ce) - dr_run_timeout <= (ck_addr >= MAX_STEP-1'b1); - + if (dw_reset) + dr_run_timeout <= 1'b1; + else if (i_ce) + dr_run_timeout <= (ck_addr >= MAX_STEP-1'b1); + // }}} + + // new_data + // {{{ always @(posedge i_data_clk) - if (dw_reset) - new_data <= 1'b1; - else if (i_ce) - new_data <= (i_data != qd_data); - + if (dw_reset) + new_data <= 1'b1; + else if (i_ce) + new_data <= (i_data != qd_data); + // }}} + + // qd_data + // {{{ always @(posedge i_data_clk) - if (i_ce) - qd_data <= i_data; + if (i_ce) + qd_data <= i_data; + // }}} - wire [(BUSW-2):0] w_data; + // w_data + // {{{ generate if (NELM == BUSW-1) assign w_data = qd_data; else assign w_data = { {(BUSW-NELM-1){1'b0}}, qd_data }; endgenerate + // }}} - // + // imm_val, imm_adr, lst_val, lst_adr + // {{{ // To do our RLE compression, we keep track of two registers: the most // recent data to the device (imm_ prefix) and the data from one // clock ago. This allows us to suppress writes to the scope which // would otherwise be two address writes in a row. - reg imm_adr, lst_adr; // Is this an address (1'b1) or data value? - reg [(BUSW-2):0] lst_val, // Data for the scope, delayed by one - imm_val; // Data to write to the scope initial lst_adr = 1'b1; initial imm_adr = 1'b1; always @(posedge i_data_clk) - if (dw_reset) - begin - imm_val <= 31'h0; - imm_adr <= 1'b1; - lst_val <= 31'h0; - lst_adr <= 1'b1; - end else if (i_ce) + if (dw_reset) + begin + imm_val <= 31'h0; + imm_adr <= 1'b1; + lst_val <= 31'h0; + lst_adr <= 1'b1; + end else if (i_ce) + begin + if ((new_data)||(dr_force_write)||(dr_stopped)) begin - if ((new_data)||(dr_force_write)||(dr_stopped)) - begin - imm_val <= w_data; - imm_adr <= 1'b0; // Last thing we wrote was data - lst_val <= imm_val; - lst_adr <= imm_adr; - end else begin - imm_val <= ck_addr; // Minimum value here is '1' - imm_adr <= 1'b1; // This (imm) is an address - lst_val <= imm_val; - lst_adr <= imm_adr; - end + imm_val <= w_data; + imm_adr <= 1'b0; // Last thing we wrote was data + lst_val <= imm_val; + lst_adr <= imm_adr; + end else begin + imm_val <= ck_addr; // Minimum value here is '1' + imm_adr <= 1'b1; // This (imm) is an address + lst_val <= imm_val; + lst_adr <= imm_adr; end + end + // }}} - // + // record_ce + // {{{ // Here's where we suppress writing pairs of address words to the // scope at once. // - reg record_ce; - reg [(BUSW-1):0] r_data; initial record_ce = 1'b0; always @(posedge i_data_clk) record_ce <= (i_ce)&&((!lst_adr)||(!imm_adr))&&(!dr_stop_pipe[2]); + // }}} + + // r_data + // {{{ always @(posedge i_data_clk) r_data <= ((!lst_adr)||(!imm_adr)) ? { lst_adr, lst_val } : { {(32 - NELM){1'b0}}, qd_data }; + // }}} // // Actually do our writes to memory. Record, via 'primed' when @@ -361,23 +489,30 @@ module wbscopc(i_data_clk, i_ce, i_trigger, i_data, // The clock transfer on the stopped line handles the clock // transfer for these signals. // - reg [(LGMEM-1):0] waddr; + + // waddr, dr_primed + // {{{ initial waddr = {(LGMEM){1'b0}}; initial dr_primed = 1'b0; always @(posedge i_data_clk) - if (dw_reset) // For simulation purposes, supply a valid value - begin - waddr <= 0; // upon reset. - dr_primed <= 1'b0; - end else if (record_ce) - begin - // mem[waddr] <= i_data; - waddr <= waddr + {{(LGMEM-1){1'b0}},1'b1}; - dr_primed <= (dr_primed)||(&waddr); - end + if (dw_reset) // For simulation purposes, supply a valid value + begin + waddr <= 0; // upon reset. + dr_primed <= 1'b0; + end else if (record_ce) + begin + // mem[waddr] <= i_data; + waddr <= waddr + {{(LGMEM-1){1'b0}},1'b1}; + dr_primed <= (dr_primed)||(&waddr); + end + // }}} + + // mem[] <= r_data + // {{{ always @(posedge i_data_clk) - if (record_ce) - mem[waddr] <= r_data; + if (record_ce) + mem[waddr] <= r_data; + // }}} // @@ -386,18 +521,21 @@ module wbscopc(i_data_clk, i_ce, i_trigger, i_data, // Bus response // // - + // }}} + // }}} + //////////////////////////////////////////////////////////////////////// // - // Clock transfer of the status signals + // Move the status signals back to the bus clock + // {{{ + //////////////////////////////////////////////////////////////////////// // - wire bw_stopped, bw_triggered, bw_primed; - generate - if (SYNCHRONOUS > 0) - begin + generate if (SYNCHRONOUS > 0) + begin : SYNCHRONOUS_RETURN assign bw_stopped = dw_final_stop; assign bw_triggered = dr_triggered; assign bw_primed = dr_primed; - end else begin + end else begin : ASYNC_STATUS + // {{{ // These aren't a problem, since none of these are strobe // signals. They goes from low to high, and then stays high // for many clocks. Swapping is thus easy--two flip flops to @@ -407,67 +545,73 @@ module wbscopc(i_data_clk, i_ce, i_trigger, i_data, reg [2:0] r_oflags; initial q_oflags = 3'h0; initial r_oflags = 3'h0; - always @(posedge i_wb_clk) - if (bw_reset_request) - begin - q_oflags <= 3'h0; - r_oflags <= 3'h0; - end else begin - q_oflags <= { dw_final_stop, dr_triggered, dr_primed }; - r_oflags <= q_oflags; - end + always @(posedge bus_clock) + if (bw_reset_request) + begin + q_oflags <= 3'h0; + r_oflags <= 3'h0; + end else begin + q_oflags <= { dw_final_stop, dr_triggered, dr_primed }; + r_oflags <= q_oflags; + end assign bw_stopped = r_oflags[2]; assign bw_triggered = r_oflags[1]; assign bw_primed = r_oflags[0]; + // }}} end endgenerate - - + // }}} + //////////////////////////////////////////////////////////////////////// // - // Reads use the bus clock + // Read from the memory, using the bus clock. Otherwise respond to bus + // {{{ + //////////////////////////////////////////////////////////////////////// // - reg br_wb_ack, br_pre_wb_ack; - initial br_wb_ack = 1'b0; - wire bw_cyc_stb; + // + + // Reads use the bus clock assign bw_cyc_stb = (i_wb_stb); + initial br_pre_wb_ack = 1'b0; initial br_wb_ack = 1'b0; - always @(posedge i_wb_clk) + always @(posedge bus_clock) begin - if ((bw_reset_request) - ||((bw_cyc_stb)&&(i_wb_addr)&&(i_wb_we))) + if ((bw_reset_request)||(write_to_control)) raddr <= 0; - else if ((bw_cyc_stb)&&(i_wb_addr)&&(!i_wb_we)&&(bw_stopped)) + else if ((read_from_data)&&(bw_stopped)) raddr <= raddr + 1'b1; // Data read, when stopped br_pre_wb_ack <= bw_cyc_stb; br_wb_ack <= (br_pre_wb_ack)&&(i_wb_cyc); end + assign o_wb_ack = br_wb_ack; + always @(posedge bus_clock) + if (read_from_data) + this_addr <= raddr + waddr + 1'b1; + else + this_addr <= raddr + waddr; - reg [(LGMEM-1):0] this_addr; - always @(posedge i_wb_clk) - if ((bw_cyc_stb)&&(i_wb_addr)&&(!i_wb_we)) - this_addr <= raddr + waddr + 1'b1; - else - this_addr <= raddr + waddr; - - reg [31:0] nxt_mem; - always @(posedge i_wb_clk) + always @(posedge bus_clock) nxt_mem <= mem[this_addr]; - wire [19:0] full_holdoff; + // holdoff sub-register + // {{{ assign full_holdoff[(HOLDOFFBITS-1):0] = br_holdoff; generate if (HOLDOFFBITS < 20) assign full_holdoff[19:(HOLDOFFBITS)] = 0; endgenerate + // }}} - wire [4:0] bw_lgmem; assign bw_lgmem = LGMEM; - always @(posedge i_wb_clk) - if (!i_wb_addr) // Control register read - o_wb_data <= { bw_reset_request, + + // Bus read + // {{{ + always @(posedge bus_clock) + begin + if (!read_address) // Control register read + o_bus_data <= { bw_reset_request, bw_stopped, bw_triggered, bw_primed, @@ -477,28 +621,42 @@ module wbscopc(i_data_clk, i_ce, i_trigger, i_data, bw_lgmem, full_holdoff }; else if (!bw_stopped) // read, prior to stopping - o_wb_data <= {1'b0, w_data };// Violates clk tfr rules + // + // *WARNING*: THIS READ IS NOT PROTECTED FROM + // ASYNCHRONOUS COHERENCE ISSUES! + // + o_bus_data <= {1'b0, w_data };// Violates clk tfr rules else // if (i_wb_addr) // Read from FIFO memory - o_wb_data <= nxt_mem; // mem[raddr+waddr]; - - assign o_wb_stall = 1'b0; - assign o_wb_ack = (i_wb_cyc)&&(br_wb_ack); + o_bus_data <= nxt_mem; // mem[raddr+waddr]; + end + // }}} - reg br_level_interrupt; + assign o_wb_data = o_bus_data; + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Interrupt generation + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // initial br_level_interrupt = 1'b0; - assign o_interrupt = (bw_stopped)&&(!bw_disable_trigger) - &&(!br_level_interrupt); - always @(posedge i_wb_clk) + always @(posedge bus_clock) if ((bw_reset_complete)||(bw_reset_request)) br_level_interrupt<= 1'b0; else br_level_interrupt<= (bw_stopped)&&(!bw_disable_trigger); - // Make Verilator happy + assign o_interrupt = (bw_stopped)&&(!bw_disable_trigger) + &&(!br_level_interrupt); + // }}} + + // Make verilator happy + // {{{ // verilator lint_off UNUSED wire unused; - assign unused = &{ 1'b0, i_wb_data[30:28], i_wb_data[25:HOLDOFFBITS], + assign unused = &{ 1'b0, i_bus_data[30:28], i_bus_data[25:HOLDOFFBITS], i_wb_sel }; // verilator lint_on UNUSED - + // }}} endmodule diff --git a/rtl/wbscope/wbscope.v b/rtl/wbscope/wbscope.v index a2e1c96..57e0b81 100644 --- a/rtl/wbscope/wbscope.v +++ b/rtl/wbscope/wbscope.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: wbscope.v -// +// {{{ // Project: WBScope, a wishbone hosted scope // // Purpose: This is a generic/library routine for providing a bus accessed @@ -58,9 +58,9 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): 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 @@ -75,77 +75,106 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // // `default_nettype none -// -module wbscope(i_data_clk, i_ce, i_trigger, i_data, - i_wb_clk, i_wb_cyc, i_wb_stb, i_wb_we, i_wb_addr, i_wb_data, i_wb_sel, - o_wb_stall, o_wb_ack, o_wb_data, - o_interrupt); - parameter [4:0] LGMEM = 5'd10; - parameter BUSW = 32; - parameter [0:0] SYNCHRONOUS=1; - parameter HOLDOFFBITS = 20; - parameter [(HOLDOFFBITS-1):0] DEFAULT_HOLDOFF = ((1<<(LGMEM-1))-4); - // The input signals that we wish to record - input wire i_data_clk, i_ce, i_trigger; - input wire [(BUSW-1):0] i_data; - // The WISHBONE bus for reading and configuring this scope - input wire i_wb_clk, i_wb_cyc, i_wb_stb, i_wb_we; - input wire i_wb_addr; // One address line only - input wire [(BUSW-1):0] i_wb_data; - input wire [(BUSW/8-1):0] i_wb_sel; - output wire o_wb_stall, o_wb_ack; - output wire [(BUSW-1):0] o_wb_data; - // And, finally, for a final flair --- offer to interrupt the CPU after - // our trigger has gone off. This line is equivalent to the scope - // being stopped. It is not maskable here. - output wire o_interrupt; - - wire bus_clock; +// }}} +module wbscope #( + // {{{ + parameter [4:0] LGMEM = 5'd10, + parameter BUSW = 32, + parameter [0:0] SYNCHRONOUS=1, + parameter HOLDOFFBITS = 20, + parameter [(HOLDOFFBITS-1):0] DEFAULT_HOLDOFF = ((1<<(LGMEM-1))-4) + // }}} + ) ( + // {{{ + // The input signals that we wish to record + input wire i_data_clk, i_ce, i_trigger, + input wire [(BUSW-1):0] i_data, + // The WISHBONE bus for reading and configuring this scope + // {{{ + input wire i_wb_clk, i_wb_cyc, + i_wb_stb, i_wb_we, + input wire i_wb_addr, // One address line only + input wire [(BUSW-1):0] i_wb_data, + input wire [(BUSW/8-1):0] i_wb_sel, + output wire o_wb_stall, o_wb_ack, + output wire [(BUSW-1):0] o_wb_data, + // }}} + // And, finally, for a final flair --- offer to interrupt the + // CPU after our trigger has gone off. This line is equivalent + // to the scope being stopped. It is not maskable here. + output wire o_interrupt + // }}} + ); + + // Signal declarations + // {{{ + wire bus_clock; + wire read_from_data; + wire write_stb; + wire write_to_control; + reg read_address; + wire [31:0] i_bus_data; + reg [(LGMEM-1):0] raddr; + reg [(BUSW-1):0] mem[0:((1< 0) begin @@ -200,7 +231,8 @@ module wbscope(i_data_clk, i_ce, i_trigger, i_data, assign bw_reset_complete = bw_reset_request; end else begin reg r_reset_complete; - (* ASYNC_REG = "TRUE" *) reg [2:0] q_iflags, r_iflags; + (* ASYNC_REG = "TRUE" *) reg [2:0] q_iflags; + reg [2:0] r_iflags; // Resets are synchronous to the bus clock, not the data clock // so do a clock transfer here @@ -230,49 +262,76 @@ module wbscope(i_data_clk, i_ce, i_trigger, i_data, end assign bw_reset_complete = qq_reset_complete; - end endgenerate + end endgenerate + // }}} + //////////////////////////////////////////////////////////////////////// // // Set up the trigger + // {{{ + //////////////////////////////////////////////////////////////////////// // // - // Write with the i-clk, or input clock. All outputs read with the - // bus clock, or bus_clock as we've called it here. - reg dr_triggered, dr_primed; - wire dw_trigger; + + // dw_trigger -- trigger wire, defined on the data clock + // {{{ + // Write with the i_clk, or input clock. All outputs read with the + // bus clock, or i_wb_clk as we've called it here. assign dw_trigger = (dr_primed)&&( ((i_trigger)&&(!dw_disable_trigger)) ||(dw_manual_trigger)); + // }}} + + // dr_triggered + // {{{ initial dr_triggered = 1'b0; always @(posedge i_data_clk) if (dw_reset) dr_triggered <= 1'b0; else if ((i_ce)&&(dw_trigger)) dr_triggered <= 1'b1; + // }}} // // Determine when memory is full and capture is complete // // Writes take place on the data clock - // The counter is unsigned - (* ASYNC_REG="TRUE" *) reg [(HOLDOFFBITS-1):0] counter; - reg dr_stopped; - initial dr_stopped = 1'b0; + // counter + // {{{ + // The counter is unsigned initial counter = 0; always @(posedge i_data_clk) if (dw_reset) counter <= 0; else if ((i_ce)&&(dr_triggered)&&(!dr_stopped)) counter <= counter + 1'b1; + // }}} + // dr_stopped + // {{{ + initial dr_stopped = 1'b0; always @(posedge i_data_clk) if ((!dr_triggered)||(dw_reset)) dr_stopped <= 1'b0; - else if (HOLDOFFBITS > 1) // if (i_ce) - dr_stopped <= (counter >= br_holdoff); - else if (HOLDOFFBITS <= 1) - dr_stopped <= ((i_ce)&&(dw_trigger)); + else if (!dr_stopped) + begin + if (HOLDOFFBITS > 1) // if (i_ce) + dr_stopped <= (counter >= br_holdoff); + else if (HOLDOFFBITS <= 1) + dr_stopped <= ((i_ce)&&(dw_trigger)); + end + // }}} + + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Write to memory + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + // // Actually do our writes to memory. Record, via 'primed' when @@ -284,7 +343,9 @@ module wbscope(i_data_clk, i_ce, i_trigger, i_data, // The clock transfer on the stopped line handles the clock // transfer for these signals. // - reg [(LGMEM-1):0] waddr; + + // waddr, dr_primed + // {{{ initial waddr = {(LGMEM){1'b0}}; initial dr_primed = 1'b0; always @(posedge i_data_clk) @@ -299,13 +360,14 @@ module wbscope(i_data_clk, i_ce, i_trigger, i_data, if (!dr_primed) dr_primed <= (&waddr); end + // }}} + // wr_piped_data -- delay data to match the trigger + // {{{ // Delay the incoming data so that we can get our trigger // logic to line up with the data. The goal is to have a // hold off of zero place the trigger in the last memory // address. - localparam STOPDELAY = 1; - wire [(BUSW-1):0] wr_piped_data; generate if (STOPDELAY == 0) // No delay ... just assign the wires to our input lines @@ -329,22 +391,28 @@ module wbscope(i_data_clk, i_ce, i_trigger, i_data, data_pipe <= { data_pipe[((STOPDELAY-1)*BUSW-1):0], i_data }; assign wr_piped_data = { data_pipe[(STOPDELAY*BUSW-1):((STOPDELAY-1)*BUSW)] }; end endgenerate + // }}} + // mem[] <= wr_piped_data + // {{{ always @(posedge i_data_clk) if ((i_ce)&&(!dr_stopped)) mem[waddr] <= wr_piped_data; - + // }}} + // }}} + //////////////////////////////////////////////////////////////////////// // - // Clock transfer of the status signals + // Move the status signals back to the bus clock + // {{{ + //////////////////////////////////////////////////////////////////////// // - wire bw_stopped, bw_triggered, bw_primed; - generate - if (SYNCHRONOUS > 0) - begin + generate if (SYNCHRONOUS > 0) + begin : SYNCHRONOUS_RETURN assign bw_stopped = dr_stopped; assign bw_triggered = dr_triggered; assign bw_primed = dr_primed; - end else begin + end else begin : ASYNC_STATUS + // {{{ // These aren't a problem, since none of these are strobe // signals. They goes from low to high, and then stays high // for many clocks. Swapping is thus easy--two flip flops to @@ -355,25 +423,32 @@ module wbscope(i_data_clk, i_ce, i_trigger, i_data, initial q_oflags = 3'h0; initial r_oflags = 3'h0; always @(posedge bus_clock) - if (bw_reset_request) - begin - q_oflags <= 3'h0; - r_oflags <= 3'h0; - end else begin - q_oflags <= { dr_stopped, dr_triggered, dr_primed }; - r_oflags <= q_oflags; - end + if (bw_reset_request) + begin + q_oflags <= 3'h0; + r_oflags <= 3'h0; + end else begin + q_oflags <= { dr_stopped, dr_triggered, dr_primed }; + r_oflags <= q_oflags; + end assign bw_stopped = r_oflags[2]; assign bw_triggered = r_oflags[1]; assign bw_primed = r_oflags[0]; + // }}} end endgenerate + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Read from the memory, using the bus clock. Otherwise respond to bus + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // // Reads use the bus clock - reg br_wb_ack, br_pre_wb_ack; - initial br_wb_ack = 1'b0; - wire bw_cyc_stb; assign bw_cyc_stb = (i_wb_stb); + initial br_pre_wb_ack = 1'b0; initial br_wb_ack = 1'b0; always @(posedge bus_clock) @@ -386,60 +461,79 @@ module wbscope(i_data_clk, i_ce, i_trigger, i_data, br_pre_wb_ack <= bw_cyc_stb; br_wb_ack <= (br_pre_wb_ack)&&(i_wb_cyc); end + assign o_wb_ack = (i_wb_cyc)&&(br_wb_ack); - reg [(LGMEM-1):0] this_addr; always @(posedge bus_clock) if (read_from_data) this_addr <= raddr + waddr + 1'b1; else this_addr <= raddr + waddr; - reg [31:0] nxt_mem; always @(posedge bus_clock) nxt_mem <= mem[this_addr]; - wire [19:0] full_holdoff; + // holdoff sub-register + // {{{ assign full_holdoff[(HOLDOFFBITS-1):0] = br_holdoff; generate if (HOLDOFFBITS < 20) assign full_holdoff[19:(HOLDOFFBITS)] = 0; endgenerate + // }}} - reg [31:0] o_bus_data; - wire [4:0] bw_lgmem; assign bw_lgmem = LGMEM; + + // Bus read + // {{{ always @(posedge bus_clock) - if (!read_address) // Control register read - o_bus_data <= { bw_reset_request, - bw_stopped, - bw_triggered, - bw_primed, - bw_manual_trigger, - bw_disable_trigger, - (raddr == {(LGMEM){1'b0}}), - bw_lgmem, - full_holdoff }; - else if (!bw_stopped) // read, prior to stopping - o_bus_data <= i_data; - else // if (i_wb_addr) // Read from FIFO memory - o_bus_data <= nxt_mem; // mem[raddr+waddr]; + begin + if (!read_address) // Control register read + o_bus_data <= { bw_reset_request, + bw_stopped, + bw_triggered, + bw_primed, + bw_manual_trigger, + bw_disable_trigger, + (raddr == {(LGMEM){1'b0}}), + bw_lgmem, + full_holdoff }; + else if (!bw_stopped) // read, prior to stopping + // + // *WARNING*: THIS READ IS NOT PROTECTED FROM + // ASYNCHRONOUS COHERENCE ISSUES! + // + o_bus_data <= i_data; + else // if (i_wb_addr) // Read from FIFO memory + o_bus_data <= nxt_mem; // mem[raddr+waddr]; + end + // }}} assign o_wb_data = o_bus_data; - - reg br_level_interrupt; + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Interrupt generation + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // initial br_level_interrupt = 1'b0; - assign o_interrupt = (bw_stopped)&&(!bw_disable_trigger) - &&(!br_level_interrupt); always @(posedge bus_clock) if ((bw_reset_complete)||(bw_reset_request)) br_level_interrupt<= 1'b0; else br_level_interrupt<= (bw_stopped)&&(!bw_disable_trigger); - // verilator lint_off UNUSED + assign o_interrupt = (bw_stopped)&&(!bw_disable_trigger) + &&(!br_level_interrupt); + // }}} + // Make verilator happy + // {{{ + // verilator lint_off UNUSED wire unused; assign unused = &{ 1'b0, i_bus_data[30:28], i_bus_data[25:0], i_wb_sel }; // verilator lint_on UNUSED + // }}} endmodule diff --git a/rtl/wbuart/rxuartlite.v b/rtl/wbuart/rxuartlite.v index 81237ff..d098c33 100644 --- a/rtl/wbuart/rxuartlite.v +++ b/rtl/wbuart/rxuartlite.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: rxuartlite.v -// +// {{{ // Project: wbuart32, a full featured UART with simulator // // Purpose: Receive and decode inputs from a single UART line. @@ -20,11 +20,11 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -37,38 +37,51 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none -// -`define RXUL_BIT_ZERO 4'h0 -`define RXUL_BIT_ONE 4'h1 -`define RXUL_BIT_TWO 4'h2 -`define RXUL_BIT_THREE 4'h3 -`define RXUL_BIT_FOUR 4'h4 -`define RXUL_BIT_FIVE 4'h5 -`define RXUL_BIT_SIX 4'h6 -`define RXUL_BIT_SEVEN 4'h7 -`define RXUL_STOP 4'h8 -`define RXUL_WAIT 4'h9 -`define RXUL_IDLE 4'hf - -module rxuartlite(i_clk, i_uart_rx, o_wr, o_data); - parameter TIMER_BITS = 10; - parameter [(TIMER_BITS-1):0] CLOCKS_PER_BAUD = 868; - localparam TB = TIMER_BITS; - input wire i_clk; - input wire i_uart_rx; - output reg o_wr; - output reg [7:0] o_data; - - +// }}} +module rxuartlite #( + // {{{ + parameter TIMER_BITS = 10, +`ifdef FORMAL + parameter [(TIMER_BITS-1):0] CLOCKS_PER_BAUD = 16, // Necessary for formal proof +`else + parameter [(TIMER_BITS-1):0] CLOCKS_PER_BAUD = 868, // 115200 MBaud at 100MHz +`endif + localparam TB = TIMER_BITS, + // + localparam [3:0] RXUL_BIT_ZERO = 4'h0, + // Verilator lint_off UNUSED + // These are used by the formal solver + localparam [3:0] RXUL_BIT_ONE = 4'h1, + localparam [3:0] RXUL_BIT_TWO = 4'h2, + localparam [3:0] RXUL_BIT_THREE = 4'h3, + localparam [3:0] RXUL_BIT_FOUR = 4'h4, + localparam [3:0] RXUL_BIT_FIVE = 4'h5, + localparam [3:0] RXUL_BIT_SIX = 4'h6, + localparam [3:0] RXUL_BIT_SEVEN = 4'h7, + // Verilator lint_on UNUSED + localparam [3:0] RXUL_STOP = 4'h8, + localparam [3:0] RXUL_WAIT = 4'h9, + localparam [3:0] RXUL_IDLE = 4'hf + // }}} + ) ( + // {{{ + input wire i_clk, + input wire i_uart_rx, + output reg o_wr, + output reg [7:0] o_data + // }}} + ); + + // Signal/register declarations + // {{{ wire [(TB-1):0] half_baud; reg [3:0] state; @@ -76,72 +89,93 @@ module rxuartlite(i_clk, i_uart_rx, o_wr, o_data); reg [(TB-1):0] baud_counter; reg zero_baud_counter; + reg q_uart, qq_uart, ck_uart; + reg [(TB-1):0] chg_counter; + reg half_baud_time; + reg [7:0] data_reg; + // }}} + // ck_uart + // {{{ // Since this is an asynchronous receiver, we need to register our // input a couple of clocks over to avoid any problems with // metastability. We do that here, and then ignore all but the // ck_uart wire. - reg q_uart, qq_uart, ck_uart; initial q_uart = 1'b1; initial qq_uart = 1'b1; initial ck_uart = 1'b1; always @(posedge i_clk) { ck_uart, qq_uart, q_uart } <= { qq_uart, q_uart, i_uart_rx }; + // }}} + // chg_counter + // {{{ // Keep track of the number of clocks since the last change. // // This is used to determine if we are in either a break or an idle // condition, as discussed further below. - reg [(TB-1):0] chg_counter; initial chg_counter = {(TB){1'b1}}; always @(posedge i_clk) if (qq_uart != ck_uart) chg_counter <= 0; else if (chg_counter != { (TB){1'b1} }) chg_counter <= chg_counter + 1; + // }}} + // half_baud_time + // {{{ // Are we in the middle of a baud iterval? Specifically, are we // in the middle of a start bit? Set this to high if so. We'll use // this within our state machine to transition out of the IDLE // state. - reg half_baud_time; initial half_baud_time = 0; always @(posedge i_clk) half_baud_time <= (!ck_uart)&&(chg_counter >= half_baud-1'b1-1'b1); + // }}} - - initial state = `RXUL_IDLE; + // state + // {{{ + initial state = RXUL_IDLE; always @(posedge i_clk) - if (state == `RXUL_IDLE) + if (state == RXUL_IDLE) begin // Idle state, independent of baud counter + // {{{ // By default, just stay in the IDLE state - state <= `RXUL_IDLE; + state <= RXUL_IDLE; if ((!ck_uart)&&(half_baud_time)) // UNLESS: We are in the center of a valid // start bit - state <= `RXUL_BIT_ZERO; - end else if ((state >= `RXUL_WAIT)&&(ck_uart)) - state <= `RXUL_IDLE; + state <= RXUL_BIT_ZERO; + // }}} + end else if ((state >= RXUL_WAIT)&&(ck_uart)) + state <= RXUL_IDLE; else if (zero_baud_counter) begin - if (state <= `RXUL_STOP) + // {{{ + if (state <= RXUL_STOP) // Data arrives least significant bit first. // By the time this is clocked in, it's what // you'll have. state <= state + 1; + // }}} end + // }}} + // data_reg + // {{{ // Data bit capture logic. // // This is drastically simplified from the state machine above, based // upon: 1) it doesn't matter what it is until the end of a captured // byte, and 2) the data register will flush itself of any invalid // data in all other cases. Hence, let's keep it real simple. - reg [7:0] data_reg; always @(posedge i_clk) - if ((zero_baud_counter)&&(state != `RXUL_STOP)) + if ((zero_baud_counter)&&(state != RXUL_STOP)) data_reg <= { qq_uart, data_reg[7:1] }; + // }}} + // o_wr, o_data + // {{{ // Our data bit logic doesn't need nearly the complexity of all that // work above. Indeed, we only need to know if we are at the end of // a stop bit, in which case we copy the data_reg into our output @@ -151,47 +185,58 @@ module rxuartlite(i_clk, i_uart_rx, o_wr, o_data); initial o_wr = 1'b0; initial o_data = 8'h00; always @(posedge i_clk) - if ((zero_baud_counter)&&(state == `RXUL_STOP)&&(ck_uart)) + if ((zero_baud_counter)&&(state == RXUL_STOP)&&(ck_uart)) begin o_wr <= 1'b1; o_data <= data_reg; end else o_wr <= 1'b0; + // }}} - // The baud counter - // + // baud_counter -- The baud counter + // {{{ // This is used as a "clock divider" if you will, but the clock needs // to be reset before any byte can be decoded. In all other respects, // we set ourselves up for CLOCKS_PER_BAUD counts between baud // intervals. initial baud_counter = 0; always @(posedge i_clk) - if (((state==`RXUL_IDLE))&&(!ck_uart)&&(half_baud_time)) + if (((state==RXUL_IDLE))&&(!ck_uart)&&(half_baud_time)) baud_counter <= CLOCKS_PER_BAUD-1'b1; - else if (state == `RXUL_WAIT) + else if (state == RXUL_WAIT) baud_counter <= 0; - else if ((zero_baud_counter)&&(state < `RXUL_STOP)) + else if ((zero_baud_counter)&&(state < RXUL_STOP)) baud_counter <= CLOCKS_PER_BAUD-1'b1; else if (!zero_baud_counter) baud_counter <= baud_counter-1'b1; + // }}} // zero_baud_counter - // + // {{{ // Rather than testing whether or not (baud_counter == 0) within our // (already too complicated) state transition tables, we use // zero_baud_counter to pre-charge that test on the clock // before--cleaning up some otherwise difficult timing dependencies. initial zero_baud_counter = 1'b1; always @(posedge i_clk) - if ((state == `RXUL_IDLE)&&(!ck_uart)&&(half_baud_time)) + if ((state == RXUL_IDLE)&&(!ck_uart)&&(half_baud_time)) zero_baud_counter <= 1'b0; - else if (state == `RXUL_WAIT) + else if (state == RXUL_WAIT) zero_baud_counter <= 1'b1; - else if ((zero_baud_counter)&&(state < `RXUL_STOP)) + else if ((zero_baud_counter)&&(state < RXUL_STOP)) zero_baud_counter <= 1'b0; else if (baud_counter == 1) zero_baud_counter <= 1'b1; - + // }}} +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal properties +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// `ifdef FORMAL // Formal properties for this module are maintained elsewhere `endif diff --git a/rtl/wbuart/txuartlite.v b/rtl/wbuart/txuartlite.v index 1aa89f3..38a83c1 100644 --- a/rtl/wbuart/txuartlite.v +++ b/rtl/wbuart/txuartlite.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: txuartlite.v -// +// {{{ // Project: wbuart32, a full featured UART with simulator // // Purpose: Transmit outputs over a single UART line. This particular UART @@ -24,11 +24,11 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -41,73 +41,87 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // // `default_nettype none -// -`define TXUL_BIT_ZERO 4'h0 -`define TXUL_BIT_ONE 4'h1 -`define TXUL_BIT_TWO 4'h2 -`define TXUL_BIT_THREE 4'h3 -`define TXUL_BIT_FOUR 4'h4 -`define TXUL_BIT_FIVE 4'h5 -`define TXUL_BIT_SIX 4'h6 -`define TXUL_BIT_SEVEN 4'h7 -`define TXUL_STOP 4'h8 -`define TXUL_IDLE 4'hf -// -// -module txuartlite(i_clk, i_wr, i_data, o_uart_tx, o_busy); - parameter [4:0] TIMING_BITS = 5'd24; - localparam TB = TIMING_BITS; - parameter [(TB-1):0] CLOCKS_PER_BAUD = 8; // 24'd868; - input wire i_clk; - input wire i_wr; - input wire [7:0] i_data; - // And the UART input line itself - output reg o_uart_tx; - // A line to tell others when we are ready to accept data. If - // (i_wr)&&(!o_busy) is ever true, then the core has accepted a byte - // for transmission. - output wire o_busy; +// }}} +module txuartlite #( + // {{{ + // TIMING_BITS -- the number of bits required to represent + // the number of clocks per baud. 24 should be sufficient for + // most baud rates, but you can trim it down to save logic if + // you would like. TB is just an abbreviation for TIMING_BITS. + parameter [4:0] TIMING_BITS = 5'd24, + localparam TB = TIMING_BITS, + // CLOCKS_PER_BAUD -- the number of system clocks per baud + // interval. + parameter [(TB-1):0] CLOCKS_PER_BAUD = 8 // 24'd868 + // }}} + ) ( + // {{{ + input wire i_clk, + input wire i_wr, + input wire [7:0] i_data, + // And the UART input line itself + output reg o_uart_tx, + // A line to tell others when we are ready to accept data. If + // (i_wr)&&(!o_busy) is ever true, then the core has accepted + // a byte for transmission. + output wire o_busy + // }}} + ); + + // Register/net declarations + // {{{ + localparam [3:0] TXUL_BIT_ZERO = 4'h0, + // TXUL_BIT_ONE = 4'h1, + // TXUL_BIT_TWO = 4'h2, + // TXUL_BIT_THREE = 4'h3, + // TXUL_BIT_FOUR = 4'h4, + // TXUL_BIT_FIVE = 4'h5, + // TXUL_BIT_SIX = 4'h6, + // TXUL_BIT_SEVEN = 4'h7, + TXUL_STOP = 4'h8, + TXUL_IDLE = 4'hf; reg [(TB-1):0] baud_counter; reg [3:0] state; reg [7:0] lcl_data; reg r_busy, zero_baud_counter; + // }}} // Big state machine controlling: r_busy, state // {{{ // initial r_busy = 1'b1; - initial state = `TXUL_IDLE; + initial state = TXUL_IDLE; always @(posedge i_clk) begin if (!zero_baud_counter) // r_busy needs to be set coming into here r_busy <= 1'b1; - else if (state > `TXUL_STOP) // STATE_IDLE + else if (state > TXUL_STOP) // STATE_IDLE begin - state <= `TXUL_IDLE; + state <= TXUL_IDLE; r_busy <= 1'b0; if ((i_wr)&&(!r_busy)) begin // Immediately start us off with a start bit r_busy <= 1'b1; - state <= `TXUL_BIT_ZERO; + state <= TXUL_BIT_ZERO; end end else begin // One clock tick in each of these states ... r_busy <= 1'b1; - if (state <=`TXUL_STOP) // start bit, 8-d bits, stop-b + if (state <=TXUL_STOP) // start bit, 8-d bits, stop-b state <= state + 1'b1; else - state <= `TXUL_IDLE; + state <= TXUL_IDLE; end end // }}} @@ -122,7 +136,6 @@ module txuartlite(i_clk, i_wr, i_data, o_uart_tx, o_busy); assign o_busy = (r_busy); // }}} - // lcl_data // {{{ // @@ -190,7 +203,7 @@ module txuartlite(i_clk, i_wr, i_data, o_uart_tx, o_busy); // than waiting for the end of the next (fictitious and arbitrary) baud // interval. // - // When (i_wr)&&(!r_busy)&&(state == `TXUL_IDLE) then we're not only in + // When (i_wr)&&(!r_busy)&&(state == TXUL_IDLE) then we're not only in // the idle state, but we also just accepted a command to start writing // the next word. At this point, the baud counter needs to be reset // to the number of CLOCKS_PER_BAUD, and zero_baud_counter set to zero. @@ -203,7 +216,7 @@ module txuartlite(i_clk, i_wr, i_data, o_uart_tx, o_busy); always @(posedge i_clk) begin zero_baud_counter <= (baud_counter == 1); - if (state == `TXUL_IDLE) + if (state == TXUL_IDLE) begin baud_counter <= 0; zero_baud_counter <= 1'b1; @@ -212,22 +225,32 @@ module txuartlite(i_clk, i_wr, i_data, o_uart_tx, o_busy); baud_counter <= CLOCKS_PER_BAUD - 1'b1; zero_baud_counter <= 1'b0; end - end else if ((zero_baud_counter)&&(state == 4'h9)) + end else if (!zero_baud_counter) + baud_counter <= baud_counter - 1'b1; + else if (state > TXUL_STOP) begin baud_counter <= 0; zero_baud_counter <= 1'b1; - end else if (!zero_baud_counter) - baud_counter <= baud_counter - 1'b1; - else + end else if (state == TXUL_STOP) + // Need to complete this state one clock early, so + // we can release busy one clock before the stop bit + // is complete, so we can start on the next byte + // exactly 10*CLOCKS_PER_BAUD clocks after we started + // the last one + baud_counter <= CLOCKS_PER_BAUD - 2; + else // All other states baud_counter <= CLOCKS_PER_BAUD - 1'b1; end // }}} -// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // // FORMAL METHODS -// -// -// +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// `ifdef FORMAL `endif endmodule diff --git a/rtl/wbuart/ufifo.v b/rtl/wbuart/ufifo.v index 06af310..b48789a 100644 --- a/rtl/wbuart/ufifo.v +++ b/rtl/wbuart/ufifo.v @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// // // Filename: ufifo.v -// +// {{{ // Project: wbuart32, a full featured UART with simulator // // Purpose: A synchronous data FIFO, designed for supporting the Wishbone @@ -17,11 +17,11 @@ // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2015-2020, Gisselquist Technology, LLC -// +// }}} +// Copyright (C) 2015-2021, Gisselquist Technology, LLC +// {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -34,31 +34,38 @@ // with this program. (It's in the $(ROOT)/doc directory. Run make with no // target there if the PDF file isn't present.) If not, see // for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // // `default_nettype none -// -module ufifo(i_clk, i_reset, i_wr, i_data, o_empty_n, i_rd, o_data, o_status, o_err); - parameter BW=8; // Byte/data width - parameter [3:0] LGFLEN=4; - parameter [0:0] RXFIFO=1'b1; - input wire i_clk, i_reset; - input wire i_wr; - input wire [(BW-1):0] i_data; - output wire o_empty_n; // True if something is in FIFO - input wire i_rd; - output wire [(BW-1):0] o_data; - output wire [15:0] o_status; - output wire o_err; - - localparam FLEN=(1< for a copy. -// +// }}} // License: GPL, v3, as defined and found on www.gnu.org, +// {{{ // http://www.gnu.org/licenses/gpl.html // // @@ -39,118 +40,142 @@ // // `default_nettype none -// -module wbuart(i_clk, i_rst, +// }}} +// `define USE_LITE_UART +module wbuart #( + // {{{ + // 4MB 8N1, when using 100MHz clock + parameter [30:0] INITIAL_SETUP = 31'd25, + parameter [3:0] LGFLEN = 4, + parameter [0:0] HARDWARE_FLOW_CONTROL_PRESENT = 1'b1, + // Perform a simple/quick bounds check on the log FIFO length, + // to make sure its within the bounds we can support with our + // current interface. + localparam [3:0] LCLLGFLEN = (LGFLEN > 4'ha)? 4'ha + : ((LGFLEN < 4'h2) ? 4'h2 : LGFLEN) + // }}} + ) ( + // {{{ + input wire i_clk, i_reset, + // Wishbone inputs + input wire i_wb_cyc, + input wire i_wb_stb, i_wb_we, + input wire [1:0] i_wb_addr, + input wire [31:0] i_wb_data, + input wire [3:0] i_wb_sel, + output wire o_wb_stall, + output reg o_wb_ack, + output reg [31:0] o_wb_data, // - i_wb_cyc, i_wb_stb, i_wb_we, i_wb_addr, i_wb_data, - o_wb_stall, o_wb_ack, o_wb_data, - // - i_uart_rx, o_uart_tx, i_cts_n, o_rts_n, - // - o_uart_rx_int, o_uart_tx_int, - o_uart_rxfifo_int, o_uart_txfifo_int); - parameter [30:0] INITIAL_SETUP = 31'd25; // 4MB 8N1, when using 100MHz clock - parameter [3:0] LGFLEN = 4; - parameter [0:0] HARDWARE_FLOW_CONTROL_PRESENT = 1'b1; - // Perform a simple/quick bounds check on the log FIFO length, to make - // sure its within the bounds we can support with our current - // interface. - localparam [3:0] LCLLGFLEN = (LGFLEN > 4'ha)? 4'ha - : ((LGFLEN < 4'h2) ? 4'h2 : LGFLEN); - localparam [1:0] UART_SETUP = 2'b00, + input wire i_uart_rx, + output wire o_uart_tx, + input wire i_cts_n, + output reg o_rts_n, + output wire o_uart_rx_int, o_uart_tx_int, + o_uart_rxfifo_int, o_uart_txfifo_int + // }}} + ); + + localparam [1:0] UART_SETUP = 2'b00, UART_FIFO = 2'b01, UART_RXREG = 2'b10, UART_TXREG = 2'b11; - // - input wire i_clk, i_rst; - // Wishbone inputs - input wire i_wb_cyc; // We ignore CYC for efficiency - input wire i_wb_stb, i_wb_we; - input wire [1:0] i_wb_addr; - input wire [31:0] i_wb_data; // and only use 30 lines here - output wire o_wb_stall; - output reg o_wb_ack; - output reg [31:0] o_wb_data; - // - input wire i_uart_rx; - output wire o_uart_tx; - // RTS is used for hardware flow control. According to Wikipedia, it - // should probably be renamed RTR for "ready to receive". It tell us - // whether or not the receiving hardware is ready to accept another - // byte. If low, the transmitter will pause. - // - // If you don't wish to use hardware flow control, just set i_cts_n to - // 1'b0 and let the optimizer simply remove this logic. - input wire i_cts_n; - // CTS is the "Clear-to-send" signal. We set it anytime our FIFO - // isn't full. Feel free to ignore this output if you do not wish to - // use flow control. - output reg o_rts_n; - output wire o_uart_rx_int, o_uart_tx_int, - o_uart_rxfifo_int, o_uart_txfifo_int; + // Register and signal declarations + // {{{ wire tx_busy; - + reg [30:0] uart_setup; + // Receiver + wire rx_stb, rx_break, rx_perr, rx_ferr, ck_uart; + wire [7:0] rx_uart_data; + reg rx_uart_reset; + // Receive FIFO + wire rx_empty_n, rx_fifo_err; + wire [7:0] rxf_wb_data; + wire [15:0] rxf_status; + reg rxf_wb_read; // + wire [(LCLLGFLEN-1):0] check_cutoff; + reg r_rx_perr, r_rx_ferr; + wire [31:0] wb_rx_data; + // The transmitter + wire tx_empty_n, txf_err, tx_break; + wire [7:0] tx_data; + wire [15:0] txf_status; + reg txf_wb_write, tx_uart_reset; + reg [7:0] txf_wb_data; + // + wire [31:0] wb_tx_data; + wire [31:0] wb_fifo_data; + reg [1:0] r_wb_addr; + reg r_wb_ack; + // }}} + + // uart_setup + // {{{ // The UART setup parameters: bits per byte, stop bits, parity, and // baud rate are all captured within this uart_setup register. // - reg [30:0] uart_setup; initial uart_setup = INITIAL_SETUP | ((HARDWARE_FLOW_CONTROL_PRESENT==1'b0)? 31'h40000000 : 0); always @(posedge i_clk) - // Under wishbone rules, a write takes place any time i_wb_stb - // is high. If that's the case, and if the write was to the - // setup address, then set us up for the new parameters. - if ((i_wb_stb)&&(i_wb_addr == UART_SETUP)&&(i_wb_we)) - uart_setup <= { - (i_wb_data[30]) + // Under wishbone rules, a write takes place any time i_wb_stb + // is high. If that's the case, and if the write was to the + // setup address, then set us up for the new parameters. + if ((i_wb_stb)&&(i_wb_addr == UART_SETUP)&&(i_wb_we)) + begin + if (i_wb_sel[0]) + uart_setup[7:0] <= i_wb_data[7:0]; + if (i_wb_sel[1]) + uart_setup[15:8] <= i_wb_data[15:8]; + if (i_wb_sel[2]) + uart_setup[23:16] <= i_wb_data[23:16]; + if (i_wb_sel[3]) + uart_setup[30:24] <= { (i_wb_data[30]) ||(!HARDWARE_FLOW_CONTROL_PRESENT), - i_wb_data[29:0] }; - - ///////////////////////////////////////// - // + i_wb_data[29:24] }; + end + // }}} + //////////////////////////////////////////////////////////////////////// // - // First, the UART receiver + // The UART receiver + // {{{ + //////////////////////////////////////////////////////////////////////// // // - ///////////////////////////////////////// - - // First the wires/registers this receiver depends upon - wire rx_stb, rx_break, rx_perr, rx_ferr, ck_uart; - wire [7:0] rx_uart_data; - reg rx_uart_reset; + // The receiver itself + // {{{ // Here's our UART receiver. Basically, it accepts our setup wires, // the UART input, a clock, and a reset line, and produces outputs: // a stb (true when new data is ready), and an 8-bit data out value // valid when stb is high. `ifdef USE_LITE_UART - rxuartlite #(INITIAL_SETUP[23:0]) + // {{{ + rxuartlite #(.CLOCKS_PER_BAUD(INITIAL_SETUP[23:0])) rx(i_clk, i_uart_rx, rx_stb, rx_uart_data); assign rx_break = 1'b0; assign rx_perr = 1'b0; assign rx_ferr = 1'b0; assign ck_uart = 1'b0; + // }}} `else + // {{{ // The full receiver also produces a break value (true during a break // cond.), and parity/framing error flags--also valid when stb is true. - rxuart #(INITIAL_SETUP) rx(i_clk, (i_rst)||(rx_uart_reset), + rxuart #(.INITIAL_SETUP(INITIAL_SETUP)) rx(i_clk, (i_reset)||(rx_uart_reset), uart_setup, i_uart_rx, rx_stb, rx_uart_data, rx_break, rx_perr, rx_ferr, ck_uart); // The real trick is ... now that we have this extra data, what do we do // with it? + // }}} `endif + // }}} - - // We place it into a receiver FIFO. - // - // Here's the declarations for the wires it needs. - wire rx_empty_n, rx_fifo_err; - wire [7:0] rxf_wb_data; - wire [15:0] rxf_status; - reg rxf_wb_read; + // The receive FIFO + // {{{ + // We place new arriving data into a receiver FIFO. // // And here's the FIFO proper. // @@ -164,12 +189,21 @@ module wbuart(i_clk, i_rst, // four status-type values: 1) is it non-empty, 2) is the FIFO over half // full, 3) a 16-bit status register, containing info regarding how full // the FIFO truly is, and 4) an error indicator. - ufifo #(.LGFLEN(LCLLGFLEN), .RXFIFO(1)) - rxfifo(i_clk, (i_rst)||(rx_break)||(rx_uart_reset), - rx_stb, rx_uart_data, - rx_empty_n, - rxf_wb_read, rxf_wb_data, - rxf_status, rx_fifo_err); + ufifo #( + // {{{ + .LGFLEN(LCLLGFLEN), .RXFIFO(1) + // }}} + ) rxfifo( + // {{{ + .i_clk(i_clk), .i_reset((i_reset)||(rx_break)||(rx_uart_reset)), + .i_wr(rx_stb), .i_data(rx_uart_data), + .o_empty_n(rx_empty_n), + .i_rd(rxf_wb_read), .o_data(rxf_wb_data), + .o_status(rxf_status), .o_err(rx_fifo_err) + // }}} + ); + // }}} + assign o_uart_rxfifo_int = rxf_status[1]; // We produce four interrupts. One of the receive interrupts indicates @@ -177,6 +211,8 @@ module wbuart(i_clk, i_rst, // the CPU. assign o_uart_rx_int = rxf_status[0]; + // o_rts_n + // {{{ // The clear to send line, which may be ignored, but which we set here // to be true any time the FIFO has fewer than N-2 items in it. // Why not N-1? Because at N-1 we are totally full, but already so full @@ -184,92 +220,102 @@ module wbuart(i_clk, i_rst, // receive it. (Transmit might've started on the next character by the // time we set this--thus we need to set it to one, one character before // necessary). - wire [(LCLLGFLEN-1):0] check_cutoff; assign check_cutoff = -3; always @(posedge i_clk) o_rts_n <= ((HARDWARE_FLOW_CONTROL_PRESENT) &&(!uart_setup[30]) &&(rxf_status[(LCLLGFLEN+1):2] > check_cutoff)); + // }}} + // rxf_wb_read + // {{{ // If the bus requests that we read from the receive FIFO, we need to // tell this to the receive FIFO. Note that because we are using a // clock here, the output from the receive FIFO will necessarily be // delayed by an extra clock. initial rxf_wb_read = 1'b0; always @(posedge i_clk) - rxf_wb_read <= (i_wb_stb)&&(i_wb_addr[1:0]==UART_RXREG) + rxf_wb_read <= (i_wb_stb)&&(i_wb_addr[1:0]== UART_RXREG) &&(!i_wb_we); + // }}} + // r_rx_perr, r_rx_ferr -- parity and framing errors + // {{{ // Now, let's deal with those RX UART errors: both the parity and frame // errors. As you may recall, these are valid only when rx_stb is // valid, so we need to hold on to them until the user reads them via // a UART read request.. - reg r_rx_perr, r_rx_ferr; initial r_rx_perr = 1'b0; initial r_rx_ferr = 1'b0; always @(posedge i_clk) - if ((rx_uart_reset)||(rx_break)) - begin - // Clear the error - r_rx_perr <= 1'b0; - r_rx_ferr <= 1'b0; - end else if ((i_wb_stb) - &&(i_wb_addr[1:0]==UART_RXREG)&&(i_wb_we)) + if ((rx_uart_reset)||(rx_break)) + begin + // Clear the error + r_rx_perr <= 1'b0; + r_rx_ferr <= 1'b0; + end else if ((i_wb_stb) + &&(i_wb_addr[1:0]== UART_RXREG)&&(i_wb_we)) + begin + // Reset the error lines if a '1' is ever written to + // them, otherwise leave them alone. + // + if (i_wb_sel[1]) begin - // Reset the error lines if a '1' is ever written to - // them, otherwise leave them alone. - // r_rx_perr <= (r_rx_perr)&&(~i_wb_data[9]); r_rx_ferr <= (r_rx_ferr)&&(~i_wb_data[10]); - end else if (rx_stb) - begin - // On an rx_stb, capture any parity or framing error - // indications. These aren't kept with the data rcvd, - // but rather kept external to the FIFO. As a result, - // if you get a parity or framing error, you will never - // know which data byte it was associated with. - // For now ... that'll work. - r_rx_perr <= (r_rx_perr)||(rx_perr); - r_rx_ferr <= (r_rx_ferr)||(rx_ferr); end + end else if (rx_stb) + begin + // On an rx_stb, capture any parity or framing error + // indications. These aren't kept with the data rcvd, + // but rather kept external to the FIFO. As a result, + // if you get a parity or framing error, you will never + // know which data byte it was associated with. + // For now ... that'll work. + r_rx_perr <= (r_rx_perr)||(rx_perr); + r_rx_ferr <= (r_rx_ferr)||(rx_ferr); + end + // }}} + // rx_uart_reset + // {{{ initial rx_uart_reset = 1'b1; always @(posedge i_clk) - if ((i_rst)||((i_wb_stb)&&(i_wb_addr[1:0]==UART_SETUP)&&(i_wb_we))) - // The receiver reset, always set on a master reset - // request. - rx_uart_reset <= 1'b1; - else if ((i_wb_stb)&&(i_wb_addr[1:0]==UART_RXREG)&&(i_wb_we)) - // Writes to the receive register will command a receive - // reset anytime bit[12] is set. - rx_uart_reset <= i_wb_data[12]; - else - rx_uart_reset <= 1'b0; + if ((i_reset)||((i_wb_stb)&&(i_wb_addr[1:0]== UART_SETUP)&&(i_wb_we))) + // The receiver reset, always set on a master reset + // request. + rx_uart_reset <= 1'b1; + else if ((i_wb_stb)&&(i_wb_addr[1:0]== UART_RXREG)&&(i_wb_we)&&i_wb_sel[1]) + // Writes to the receive register will command a receive + // reset anytime bit[12] is set. + rx_uart_reset <= i_wb_data[12]; + else + rx_uart_reset <= 1'b0; + // }}} + // wb_rx_data + // {{{ // Finally, we'll construct a 32-bit value from these various wires, // to be returned over the bus on any read. These include the data // that would be read from the FIFO, an error indicator set upon // reading from an empty FIFO, a break indicator, and the frame and // parity error signals. - wire [31:0] wb_rx_data; assign wb_rx_data = { 16'h00, 3'h0, rx_fifo_err, rx_break, rx_ferr, r_rx_perr, !rx_empty_n, rxf_wb_data}; - - ///////////////////////////////////////// - // + // }}} + // }}} + //////////////////////////////////////////////////////////////////////// // - // Then the UART transmitter + // The UART transmitter + // {{{ + //////////////////////////////////////////////////////////////////////// // // - ///////////////////////////////////////// - wire tx_empty_n, txf_err, tx_break; - wire [7:0] tx_data; - wire [15:0] txf_status; - reg txf_wb_write, tx_uart_reset; - reg [7:0] txf_wb_data; + // txf_wb_write, txf_wb_data + // {{{ // Unlike the receiver which goes from RXUART -> UFIFO -> WB, the // transmitter basically goes WB -> UFIFO -> TXUART. Hence, to build // support for the transmitter, we start with the command to write data @@ -282,12 +328,13 @@ module wbuart(i_clk, i_rst, always @(posedge i_clk) begin txf_wb_write <= (i_wb_stb)&&(i_wb_addr == UART_TXREG) - &&(i_wb_we); + &&(i_wb_we)&&(i_wb_sel[0]); txf_wb_data <= i_wb_data[7:0]; end + // }}} // Transmit FIFO - // + // {{{ // Most of this is just wire management. The TX FIFO is identical in // implementation to the RX FIFO (theyre both UFIFOs), but the TX // FIFO is fed from the WB and read by the transmitter. Some key @@ -295,12 +342,23 @@ module wbuart(i_clk, i_rst, // break. We read from the FIFO any time the UART transmitter is idle. // and ... we just set the values (above) for controlling writing into // this. - ufifo #(.LGFLEN(LGFLEN), .RXFIFO(0)) - txfifo(i_clk, (tx_break)||(tx_uart_reset), - txf_wb_write, txf_wb_data, - tx_empty_n, - (!tx_busy)&&(tx_empty_n), tx_data, - txf_status, txf_err); + ufifo #( + // {{{ + .LGFLEN(LGFLEN), .RXFIFO(0) + // }}} + ) txfifo( + // {{{ + .i_clk(i_clk), .i_reset((tx_break)||(tx_uart_reset)), + .i_wr(txf_wb_write), .i_data(txf_wb_data), + .o_empty_n(tx_empty_n), + .i_rd((!tx_busy)&&(tx_empty_n)), .o_data(tx_data), + .o_status(txf_status), .o_err(txf_err) + // }}} + ); + // }}} + + // Transmit interrupts + // {{{ // Let's create two transmit based interrupts from the FIFO for the CPU. // The first will be true any time the FIFO has at least one open // position within it. @@ -309,10 +367,11 @@ module wbuart(i_clk, i_rst, // full, allowing us a change to always keep it (near) fully // charged. assign o_uart_txfifo_int = txf_status[1]; + // }}} -`ifndef USE_LITE_UART // Break logic - // +`ifndef USE_LITE_UART + // {{{ // A break in a UART controller is any time the UART holds the line // low for an extended period of time. Here, we capture the wb_data[9] // wire, on writes, as an indication we wish to break. As long as you @@ -322,36 +381,51 @@ module wbuart(i_clk, i_rst, reg r_tx_break; initial r_tx_break = 1'b0; always @(posedge i_clk) - if (i_rst) - r_tx_break <= 1'b0; - else if ((i_wb_stb)&&(i_wb_addr[1:0]==UART_TXREG)&&(i_wb_we)) - r_tx_break <= i_wb_data[9]; + if (i_reset) + r_tx_break <= 1'b0; + else if ((i_wb_stb)&&(i_wb_addr[1:0]== UART_TXREG)&&(i_wb_we) + &&(i_wb_sel[1])) + r_tx_break <= i_wb_data[9]; + assign tx_break = r_tx_break; + // }}} `else + // {{{ assign tx_break = 1'b0; + // }}} `endif // TX-Reset logic - // + // {{{ // This is nearly identical to the RX reset logic above. Basically, // any time someone writes to bit [12] the transmitter will go through // a reset cycle. Keep bit [12] low, and everything will proceed as // normal. initial tx_uart_reset = 1'b1; always @(posedge i_clk) - if((i_rst)||((i_wb_stb)&&(i_wb_addr == UART_SETUP)&&(i_wb_we))) - tx_uart_reset <= 1'b1; - else if ((i_wb_stb)&&(i_wb_addr[1:0]==UART_TXREG)&&(i_wb_we)) - tx_uart_reset <= i_wb_data[12]; - else - tx_uart_reset <= 1'b0; + if((i_reset)||((i_wb_stb)&&(i_wb_addr == UART_SETUP)&&(i_wb_we))) + tx_uart_reset <= 1'b1; + else if ((i_wb_stb)&&(i_wb_addr[1:0]== UART_TXREG)&&(i_wb_we) && i_wb_sel[1]) + tx_uart_reset <= i_wb_data[12]; + else + tx_uart_reset <= 1'b0; + // }}} + // The actuall transmitter itself `ifdef USE_LITE_UART - txuartlite #(INITIAL_SETUP[23:0]) tx(i_clk, (tx_empty_n), tx_data, + // {{{ + txuartlite #(.CLOCKS_PER_BAUD(INITIAL_SETUP[23:0])) tx(i_clk, (tx_empty_n), tx_data, o_uart_tx, tx_busy); + // }}} `else + // cts_n + // {{{ wire cts_n; assign cts_n = (HARDWARE_FLOW_CONTROL_PRESENT)&&(i_cts_n); + // }}} + + // The *full* transmitter impleemntation + // {{{ // Finally, the UART transmitter module itself. Note that we haven't // connected the reset wire. Transmitting is as simple as setting // the stb value (here set to tx_empty_n) and the data. When these @@ -361,76 +435,103 @@ module wbuart(i_clk, i_rst, // we read it here. (You might notice above, we register a read any // time (tx_empty_n) and (!tx_busy) are both true---the condition for // starting to transmit a new byte.) - txuart #(INITIAL_SETUP) tx(i_clk, 1'b0, uart_setup, + txuart #(.INITIAL_SETUP(INITIAL_SETUP)) tx(i_clk, 1'b0, uart_setup, r_tx_break, (tx_empty_n), tx_data, cts_n, o_uart_tx, tx_busy); + // }}} `endif + // wb_tx_data + // {{{ // Now that we are done with the chain, pick some wires for the user // to read on any read of the transmit port. // // This port is different from reading from the receive port, since // there are no side effects. (Reading from the receive port advances // the receive FIFO, here only writing to the transmit port advances the - // transmit FIFO--hence the read values are free for ... whatever.) + // transmit FIFO--hence the read values are free for ... whatever.) // We choose here to provide information about the transmit FIFO // (txf_err, txf_half_full, txf_full_n), information about the current // voltage on the line (o_uart_tx)--and even the voltage on the receive // line (ck_uart), as well as our current setting of the break and // whether or not we are actively transmitting. - wire [31:0] wb_tx_data; assign wb_tx_data = { 16'h00, - i_cts_n, txf_status[1:0], txf_err, - ck_uart, o_uart_tx, tx_break, (tx_busy|txf_status[0]), - (tx_busy|txf_status[0])?txf_wb_data:8'b00}; + i_cts_n, txf_status[1:0], txf_err, + ck_uart, o_uart_tx, tx_break, (tx_busy|txf_status[0]), + (tx_busy|txf_status[0])?txf_wb_data:8'b00}; + // }}} + // }}} + //////////////////////////////////////////////////////////////////////// + // + // Bus / register handling + // {{{ + //////////////////////////////////////////////////////////////////////// + // + // + + // wb_fifo_data + // {{{ // Each of the FIFO's returns a 16 bit status value. This value tells - // us both how big the FIFO is, as well as how much of the FIFO is in + // us both how big the FIFO is, as well as how much of the FIFO is in // use. Let's merge those two status words together into a word we // can use when reading about the FIFO. - wire [31:0] wb_fifo_data; assign wb_fifo_data = { txf_status, rxf_status }; + // }}} + // r_wb_addr + // {{{ // You may recall from above that reads take two clocks. Hence, we - // need to delay the address decoding for a clock until the data is + // need to delay the address decoding for a clock until the data is // ready. We do that here. - reg [1:0] r_wb_addr; always @(posedge i_clk) r_wb_addr <= i_wb_addr; + // }}} - // Likewise, the acknowledgement is delayed by one clock. - reg r_wb_ack; - + // r_wb_ack + // {{{ initial r_wb_ack = 1'b0; always @(posedge i_clk) // We'll ACK in two clocks - r_wb_ack <= i_wb_stb; + r_wb_ack <= (!i_reset)&&(i_wb_stb); + // }}} + // o_wb_ack + // {{{ initial o_wb_ack = 1'b0; always @(posedge i_clk) // Okay, time to set the ACK - o_wb_ack <= i_wb_cyc && r_wb_ack; + o_wb_ack <= (!i_reset)&&(r_wb_ack)&&(i_wb_cyc); + // }}} + // o_wb_data + // {{{ // Finally, set the return data. This data must be valid on the same // clock o_wb_ack is high. On all other clocks, it is irrelelant--since // no one cares, no one is reading it, it gets lost in the mux in the // interconnect, etc. For this reason, we can just simplify our logic. always @(posedge i_clk) - casez(r_wb_addr) - UART_SETUP: o_wb_data <= { 1'b0, uart_setup }; - UART_FIFO: o_wb_data <= wb_fifo_data; - UART_RXREG: o_wb_data <= wb_rx_data; - UART_TXREG: o_wb_data <= wb_tx_data; - endcase + casez(r_wb_addr) + UART_SETUP: o_wb_data <= { 1'b0, uart_setup }; + UART_FIFO: o_wb_data <= wb_fifo_data; + UART_RXREG: o_wb_data <= wb_rx_data; + UART_TXREG: o_wb_data <= wb_tx_data; + endcase + // }}} + // o_wb_stall + // {{{ // This device never stalls. Sure, it takes two clocks, but they are // pipelined, and nothing stalls that pipeline. (Creates FIFO errors, // perhaps, but doesn't stall the pipeline.) Hence, we can just // set this value to zero. assign o_wb_stall = 1'b0; + // }}} + // }}} // Make verilator happy + // {{{ // verilator lint_off UNUSED - wire [33:0] unused; - assign unused = { i_rst, i_wb_cyc, i_wb_data }; + wire unused; + assign unused = &{ 1'b0, i_wb_data[31] }; // verilator lint_on UNUSED - + // }}} endmodule diff --git a/rtl/wbubus/wbconsole.v b/rtl/wbubus/wbconsole.v index 81a09de..a3960d2 100644 --- a/rtl/wbubus/wbconsole.v +++ b/rtl/wbubus/wbconsole.v @@ -17,7 +17,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/rtl/wbubus/wbubus.v b/rtl/wbubus/wbubus.v index d00b064..6888189 100644 --- a/rtl/wbubus/wbubus.v +++ b/rtl/wbubus/wbubus.v @@ -19,7 +19,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/rtl/wbubus/wbucompactlines.v b/rtl/wbubus/wbucompactlines.v index 631d6c1..a6130bf 100644 --- a/rtl/wbubus/wbucompactlines.v +++ b/rtl/wbubus/wbucompactlines.v @@ -18,7 +18,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/rtl/wbubus/wbucompress.v b/rtl/wbubus/wbucompress.v index 090e1b8..24f8fba 100644 --- a/rtl/wbubus/wbucompress.v +++ b/rtl/wbubus/wbucompress.v @@ -29,7 +29,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/rtl/wbubus/wbuconsole.v b/rtl/wbubus/wbuconsole.v index fbcb828..be57e84 100644 --- a/rtl/wbubus/wbuconsole.v +++ b/rtl/wbubus/wbuconsole.v @@ -29,7 +29,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/rtl/wbubus/wbudecompress.v b/rtl/wbubus/wbudecompress.v index b77fae0..c1f1f78 100644 --- a/rtl/wbubus/wbudecompress.v +++ b/rtl/wbubus/wbudecompress.v @@ -20,7 +20,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/rtl/wbubus/wbudeword.v b/rtl/wbubus/wbudeword.v index be311d9..a6a819b 100644 --- a/rtl/wbubus/wbudeword.v +++ b/rtl/wbubus/wbudeword.v @@ -19,7 +19,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/rtl/wbubus/wbuexec.v b/rtl/wbubus/wbuexec.v index 02774ad..92fb339 100644 --- a/rtl/wbubus/wbuexec.v +++ b/rtl/wbubus/wbuexec.v @@ -19,7 +19,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/rtl/wbubus/wbufifo.v b/rtl/wbubus/wbufifo.v index 296f346..74101dd 100644 --- a/rtl/wbubus/wbufifo.v +++ b/rtl/wbubus/wbufifo.v @@ -16,7 +16,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/rtl/wbubus/wbuidleint.v b/rtl/wbubus/wbuidleint.v index 05d1f4c..434d884 100644 --- a/rtl/wbubus/wbuidleint.v +++ b/rtl/wbubus/wbuidleint.v @@ -19,7 +19,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/rtl/wbubus/wbuinput.v b/rtl/wbubus/wbuinput.v index a2c2bfd..afe532e 100644 --- a/rtl/wbubus/wbuinput.v +++ b/rtl/wbubus/wbuinput.v @@ -19,7 +19,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/rtl/wbubus/wbuoutput.v b/rtl/wbubus/wbuoutput.v index 28482bf..0baf055 100644 --- a/rtl/wbubus/wbuoutput.v +++ b/rtl/wbubus/wbuoutput.v @@ -18,7 +18,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/rtl/wbubus/wbureadcw.v b/rtl/wbubus/wbureadcw.v index a43d3a9..4cbb7ab 100644 --- a/rtl/wbubus/wbureadcw.v +++ b/rtl/wbubus/wbureadcw.v @@ -20,7 +20,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/rtl/wbubus/wbusixchar.v b/rtl/wbubus/wbusixchar.v index d03ff38..c9653b1 100644 --- a/rtl/wbubus/wbusixchar.v +++ b/rtl/wbubus/wbusixchar.v @@ -25,7 +25,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/rtl/wbubus/wbutohex.v b/rtl/wbubus/wbutohex.v index 5a5453a..a161764 100644 --- a/rtl/wbubus/wbutohex.v +++ b/rtl/wbubus/wbutohex.v @@ -25,7 +25,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/rtl/wbxbar.v b/rtl/wbxbar.v index e2b71bc..e5faf92 100644 --- a/rtl/wbxbar.v +++ b/rtl/wbxbar.v @@ -52,7 +52,7 @@ // //////////////////////////////////////////////////////////////////////////////// // }}} -// Copyright (C) 2019-2020, Gisselquist Technology, LLC +// Copyright (C) 2019-2021, Gisselquist Technology, LLC // {{{ // This file is part of the WB2AXIP project. // @@ -116,10 +116,6 @@ module wbxbar #( parameter [0:0] OPT_STARVATION_TIMEOUT = 1'b0 && (OPT_TIMEOUT > 0), // - // TIMEOUT_WIDTH is the number of bits in counter used to check - // on a timeout. - localparam TIMEOUT_WIDTH = $clog2(OPT_TIMEOUT), - // // OPT_DBLBUFFER is used to register all of the outputs, and // thus avoid adding additional combinational latency through // the core that might require a slower clock speed. @@ -130,18 +126,7 @@ module wbxbar #( // that could be used to reduce the logic count of the device. // Hence, OPT_LOWPOWER will use more logic, but it won't drive // bus wires unless there's a value to drive onto them. - parameter [0:0] OPT_LOWPOWER = 1'b1, - // - // LGNM is the log (base two) of the number of bus masters - // connecting to this crossbar - localparam LGNM = (NM>1) ? $clog2(NM) : 1, - // - // LGNM is the log (base two) of the number of slaves plus one - // come out of the system. The extra "plus one" is used for a - // pseudo slave representing the case where the given address - // doesn't connect to any of the slaves. This address will - // generate a bus error. - localparam LGNS = $clog2(NS+1) + parameter [0:0] OPT_LOWPOWER = 1'b1 // }}} ) ( // {{{ @@ -178,6 +163,21 @@ module wbxbar #( // // Register declarations // {{{ + // + // TIMEOUT_WIDTH is the number of bits in counter used to check + // on a timeout. + localparam TIMEOUT_WIDTH = $clog2(OPT_TIMEOUT); + // + // LGNM is the log (base two) of the number of bus masters + // connecting to this crossbar + localparam LGNM = (NM>1) ? $clog2(NM) : 1; + // + // LGNS is the log (base two) of the number of slaves plus one + // come out of the system. The extra "plus one" is used for a + // pseudo slave representing the case where the given address + // doesn't connect to any of the slaves. This address will + // generate a bus error. + localparam LGNS = $clog2(NS+1); // At one time I used o_macc and o_sacc to put into the outgoing // trace file, just enough logic to tell me if a transaction was // taking place on the given clock. @@ -200,26 +200,27 @@ module wbxbar #( // Verilator lint_off UNUSED wire [LGMAXBURST-1:0] w_mpending [0:NM-1]; // Verilator lint_on UNUSED - reg [NM-1:0] mfull, mnearfull, mempty, timed_out; + reg [NM-1:0] mfull, mnearfull, mempty; + wire [NM-1:0] timed_out; localparam NMFULL = (NM > 1) ? (1< 0) begin deadlock_timer <= deadlock_timer - 1; - timed_out[N] <= (deadlock_timer <= 1); + r_timed_out <= (deadlock_timer <= 1); end + + assign timed_out[N] = r_timed_out; end // }}} end else begin : NO_TIMEOUT // {{{ - always @(*) - timed_out = 0; + assign timed_out = 0; // }}} end endgenerate // }}} @@ -1199,7 +1207,7 @@ module wbxbar #( // Double check the timeout flags for consistency generate for(N=0; N for a copy. -## +## }}} ## License: GPL, v3, as defined and found on www.gnu.org, +## {{{ ## http://www.gnu.org/licenses/gpl.html ## ## ################################################################################ ## -## +## }}} .PHONY: all # Make certain the "all" target is the first and therefore the default target all: diff --git a/sim/verilated/automaster_tb.cpp b/sim/verilated/automaster_tb.cpp index 652090f..456df80 100644 --- a/sim/verilated/automaster_tb.cpp +++ b/sim/verilated/automaster_tb.cpp @@ -17,7 +17,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -87,7 +87,7 @@ int main(int argc, char **argv) { #endif *profile_file = NULL, *trace_file = NULL; // "trace.vcd"; - bool debug_flag = false, willexit = false; + bool debug_flag = false, willexit = false, verbose_flag = false; FILE *profile_fp; MAINTB *tb = new MAINTB; @@ -109,6 +109,7 @@ int main(int argc, char **argv) { case 'f': profile_file = "pfile.bin"; break; case 't': trace_file = argv[++argn]; j=1000; break; case 'h': usage(); exit(0); break; + case 'v': verbose_flag = true; break; default: fprintf(stderr, "ERR: Unexpected flag, -%c\n\n", argv[argn][j]); @@ -133,7 +134,7 @@ int main(int argc, char **argv) { // {{{ if (elfload) willexit = true; - if (debug_flag) { + if (debug_flag && verbose_flag) { printf("Opening design with\n"); printf("\tDebug Access port = %d\n", FPGAPORT); // fpga_port); printf("\tSerial Console = %d\n", FPGAPORT+1); @@ -178,7 +179,8 @@ int main(int argc, char **argv) { elfread(elfload, entry, secpp); free(secpp); - printf("Attempting to start from 0x%08x\n", entry); + if (verbose_flag) + printf("Attempting to start ZipCPU from 0x%08x\n", entry); tb->m_core->cpu_ipc = entry; tb->m_core->cpu_cmd_halt = 0; diff --git a/sim/verilated/busmaster_tb.cpp b/sim/verilated/busmaster_tb.cpp index 8c930a6..fe78317 100644 --- a/sim/verilated/busmaster_tb.cpp +++ b/sim/verilated/busmaster_tb.cpp @@ -19,7 +19,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/sim/verilated/byteswap.cpp b/sim/verilated/byteswap.cpp index 02f14d1..9430036 100644 --- a/sim/verilated/byteswap.cpp +++ b/sim/verilated/byteswap.cpp @@ -17,7 +17,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/sim/verilated/byteswap.h b/sim/verilated/byteswap.h index 00a65c1..7419999 100644 --- a/sim/verilated/byteswap.h +++ b/sim/verilated/byteswap.h @@ -17,7 +17,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/sim/verilated/dblpipecmdr.h b/sim/verilated/dblpipecmdr.h index bfd93fb..c547048 100644 --- a/sim/verilated/dblpipecmdr.h +++ b/sim/verilated/dblpipecmdr.h @@ -25,7 +25,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/sim/verilated/dbluartsim.cpp b/sim/verilated/dbluartsim.cpp index 94ba6e3..c5de2b6 100644 --- a/sim/verilated/dbluartsim.cpp +++ b/sim/verilated/dbluartsim.cpp @@ -18,7 +18,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -99,7 +99,7 @@ int DBLUARTSIM::setup_listener(const int port) { DBLUARTSIM::DBLUARTSIM(const int port, const bool copy_to_stdout) : m_copy(copy_to_stdout) { - m_debug = true; + m_debug = false; m_con = m_cmd = -1; m_skt = setup_listener(port); m_console = setup_listener(port+1); diff --git a/sim/verilated/dbluartsim.h b/sim/verilated/dbluartsim.h index 44e208f..dc71c00 100644 --- a/sim/verilated/dbluartsim.h +++ b/sim/verilated/dbluartsim.h @@ -18,7 +18,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/sim/verilated/main_tb.cpp b/sim/verilated/main_tb.cpp index 7a91be7..37bc799 100644 --- a/sim/verilated/main_tb.cpp +++ b/sim/verilated/main_tb.cpp @@ -18,7 +18,7 @@ // Copyright (C) 2017-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -66,7 +66,12 @@ // might then control the simulation following. // #ifndef VVAR -#ifdef NEW_VERILATOR +#ifdef ROOT_VERILATOR + +#include "Vmain___024root.h" +#define VVAR(A) rootp->main__DOT_ ## A + +#elif defined(NEW_VERILATOR) #define VVAR(A) main__DOT_ ## A #else #define VVAR(A) v__DOT_ ## A @@ -84,7 +89,11 @@ #define cpu_gie CPUVAR(_SET_GIE__DOT__r_gie) #define cpu_iflags CPUVAR(_w_iflags) #define cpu_uflags CPUVAR(_w_uflags) +#ifdef ROOT_VERILATOR +#define cpu_regs CPUVAR(_regset.m_storage) +#else #define cpu_regs CPUVAR(_regset) +#endif #define cpu_cmd_addr VVAR(_swic__DOT__cmd_addr) #define cpu_bus_err CPUVAR(_bus_err) #define cpu_ibus_err CPUVAR(_ibus_err_flag) @@ -239,6 +248,7 @@ class MAINTB : public TESTB { // SIM.TICK from zip #ifdef INCLUDE_ZIPCPU // ZipCPU Sim instruction support + // {{{ if ((m_core->cpu_sim) &&(!m_core->cpu_new_pc)) { // @@ -253,6 +263,7 @@ class MAINTB : public TESTB { m_cpu_bombed++; dump(m_core->cpu_regs); } + // }}} #endif // INCLUDE_ZIPCPU // SIM.TICK from wbu @@ -430,6 +441,8 @@ class MAINTB : public TESTB { // it will be pasated here. // #ifdef INCLUDE_ZIPCPU + // ZipCPU Access functions + // {{{ void loadelf(const char *elfname) { ELFSECTION **secpp, *secp; uint32_t entry; @@ -526,31 +539,31 @@ class MAINTB : public TESTB { if ((imm & 0x0fffff)==0x00100) { // SIM Exit(0) close(); - exit(0); + // exit(0); + m_done = true; } else if ((imm & 0x0ffff0)==0x00310) { // SIM Exit(User-Reg) - int rcode, rnum; - rnum = (imm&0x0f)+16; - rcode = regp[rnum] & 0x0ff; - if ((m_core->cpu_wr_ce)&&(m_core->cpu_wr_reg_id==rnum)) - rcode = m_core->cpu_wr_gpreg; + // int rnum; + // rnum = (imm&0x0f)+16; + // rcode = regp[rnum] & 0x0ff; + // if ((m_core->cpu_wr_ce)&&(m_core->cpu_wr_reg_id==rnum)) + // rcode = m_core->cpu_wr_gpreg; close(); - exit(rcode); + // exit(rcode); } else if ((imm & 0x0ffff0)==0x00300) { // SIM Exit(Reg) - int rcode, rnum; - rnum = (imm&0x0f)+rbase; - rcode = regp[rnum] & 0x0ff; - if ((m_core->cpu_wr_ce)&&(m_core->cpu_wr_reg_id==rnum)) - rcode = m_core->cpu_wr_gpreg; + // int rnum; + // rnum = (imm&0x0f)+rbase; + // rcode = regp[rnum] & 0x0ff; + // if ((m_core->cpu_wr_ce)&&(m_core->cpu_wr_reg_id==rnum)) + // rcode = m_core->cpu_wr_gpreg; close(); - exit(rcode); + // exit(rcode); } else if ((imm & 0x0fff00)==0x00100) { // SIM Exit(Imm) - int rcode; - rcode = imm & 0x0ff; + // rcode = imm & 0x0ff; close(); - exit(rcode); + // exit(rcode); } else if ((imm & 0x0fffff)==0x002ff) { // Full/unconditional dump printf("SIM-DUMP\n"); @@ -582,7 +595,7 @@ class MAINTB : public TESTB { rcode = m_core->cpu_wr_gpreg; printf("%c", rcode&0x0ff); } else if ((imm & 0x0fffe0)==0x00220) { - // SOUT[User Reg] + // SOUT[Reg] int rcode, rnum; rnum = (imm&0x0f)+rbase; rcode = regp[rnum]; @@ -602,6 +615,7 @@ class MAINTB : public TESTB { m_core->cpu_upc); } fflush(stdout); } + // }}} #endif // INCLUDE_ZIPCPU #ifdef SDSPI_ACCESS void setsdcard(const char *fn) { diff --git a/sim/verilated/memsim.cpp b/sim/verilated/memsim.cpp index 0276798..a012d16 100644 --- a/sim/verilated/memsim.cpp +++ b/sim/verilated/memsim.cpp @@ -22,7 +22,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/sim/verilated/memsim.h b/sim/verilated/memsim.h index 9147e1a..91c6938 100644 --- a/sim/verilated/memsim.h +++ b/sim/verilated/memsim.h @@ -22,7 +22,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/sim/verilated/pipecmdr.h b/sim/verilated/pipecmdr.h index cda5ea6..656c78a 100644 --- a/sim/verilated/pipecmdr.h +++ b/sim/verilated/pipecmdr.h @@ -20,7 +20,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/sim/verilated/port.h b/sim/verilated/port.h index 39818d5..28563ae 100644 --- a/sim/verilated/port.h +++ b/sim/verilated/port.h @@ -16,7 +16,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/sim/verilated/sdspisim.cpp b/sim/verilated/sdspisim.cpp index b256058..d45bbc5 100644 --- a/sim/verilated/sdspisim.cpp +++ b/sim/verilated/sdspisim.cpp @@ -18,7 +18,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/sim/verilated/sdspisim.h b/sim/verilated/sdspisim.h index fe0aac0..8e80627 100644 --- a/sim/verilated/sdspisim.h +++ b/sim/verilated/sdspisim.h @@ -18,7 +18,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/sim/verilated/tbclock.h b/sim/verilated/tbclock.h index 4a0374c..564a1de 100644 --- a/sim/verilated/tbclock.h +++ b/sim/verilated/tbclock.h @@ -17,7 +17,7 @@ // Copyright (C) 2017-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/sim/verilated/testb.h b/sim/verilated/testb.h index 17eb123..7b18163 100644 --- a/sim/verilated/testb.h +++ b/sim/verilated/testb.h @@ -18,7 +18,7 @@ // Copyright (C) 2017-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -76,6 +76,7 @@ template class TESTB { // TESTB(void) { + // {{{ m_core = new VA; m_time_ps = 0ul; m_trace = NULL; @@ -83,14 +84,19 @@ template class TESTB { m_paused_trace = false; Verilated::traceEverOn(true); } + // }}} + virtual ~TESTB(void) { + // {{{ if (m_trace) m_trace->close(); delete m_core; m_core = NULL; } + // }}} // // opentrace() + // {{{ // // Useful for beginning a (VCD) trace. To open such a trace, just call // opentrace() with the name of the VCD file you'd like to trace @@ -105,19 +111,21 @@ template class TESTB { m_paused_trace = false; } } + // }}} // // trace() - // + // {{{ // A synonym for opentrace() above. // void trace(const char *vcdname) { opentrace(vcdname); } + // }}} // // pausetrace(pause) - // + // {{{ // Set/clear a flag telling us whether or not to write to the VCD trace // file. The default is to write to the file, but this can be changed // by calling pausetrace. pausetrace(false) will resume tracing, @@ -128,20 +136,22 @@ template class TESTB { m_paused_trace = pausetrace; return m_paused_trace; } + // }}} // // pausetrace() - // + // {{{ // Like pausetrace(bool) above, except that pausetrace() will return // the current status of the pausetrace flag above. Specifically, it // will return true if the trace has been paused or false otherwise. virtual bool pausetrace(void) { return m_paused_trace; } + // }}} // // closetrace() - // + // {{{ // Closes the open trace file. No more information will be written // to it virtual void closetrace(void) { @@ -151,10 +161,11 @@ template class TESTB { m_trace = NULL; } } + // }}} // // eval() - // + // {{{ // This is a synonym for Verilator's eval() function. It evaluates all // of the logic within the design. AutoFPGA based designs shouldn't // need to be calling this, they should call tick() instead. However, @@ -164,10 +175,11 @@ template class TESTB { virtual void eval(void) { m_core->eval(); } + // }}} // // tick() - // + // {{{ // tick() is the main entry point into this helper core. In general, // tick() will advance the clock by one clock tick. In a multiple clock // design, this will advance the clocks up until the nearest clock @@ -203,15 +215,19 @@ template class TESTB { // to advance their inputs based upon this clock sim_clk_tick(); } + // }}} virtual void sim_clk_tick(void) { + // {{{ // AutoFPGA will override this method within main_tb.cpp if any // @SIM.TICK key is present within a design component also // containing a @SIM.CLOCK key identifying this clock. That // component must also set m_changed to true. m_changed = false; } + // }}} virtual bool done(void) { + // {{{ if (m_done) return true; @@ -220,10 +236,11 @@ template class TESTB { return m_done; } + // }}} // // reset() - // + // {{{ // Sets the i_reset input for one clock tick. It's really just a // function for the capabilies shown below. You'll want to reset any // external input values before calling this though. @@ -233,6 +250,7 @@ template class TESTB { m_core->i_reset = 0; // printf("RESET\n"); } + // }}} }; #endif // TESTB diff --git a/sim/verilated/twoc.cpp b/sim/verilated/twoc.cpp index e234178..f803686 100644 --- a/sim/verilated/twoc.cpp +++ b/sim/verilated/twoc.cpp @@ -17,7 +17,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/sim/verilated/twoc.h b/sim/verilated/twoc.h index 537094c..d7924da 100644 --- a/sim/verilated/twoc.h +++ b/sim/verilated/twoc.h @@ -17,7 +17,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/sim/verilated/uartsim.cpp b/sim/verilated/uartsim.cpp index 19eb4e6..45efc81 100644 --- a/sim/verilated/uartsim.cpp +++ b/sim/verilated/uartsim.cpp @@ -14,7 +14,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/sim/verilated/uartsim.h b/sim/verilated/uartsim.h index 71d531c..9b4c1be 100644 --- a/sim/verilated/uartsim.h +++ b/sim/verilated/uartsim.h @@ -17,7 +17,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/sim/verilated/vversion.sh b/sim/verilated/vversion.sh index 39a8235..20dc259 100755 --- a/sim/verilated/vversion.sh +++ b/sim/verilated/vversion.sh @@ -18,7 +18,7 @@ ## Copyright (C) 2017-2021, Gisselquist Technology, LLC ## {{{ ## This program is free software (firmware): you can redistribute it and/or -## modify it under the terms of the GNU General Public License as published +## 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. ## @@ -39,7 +39,7 @@ ################################################################################ ## ## }}} -if [[ -x ${VERILATOR_ROOT}/bin/verilator ]]; +if [[ x${VERILATOR_ROOT} != "x" && -x ${VERILATOR_ROOT}/bin/verilator ]]; then export VERILATOR=${VERILATOR_ROOT}/bin/verilator fi @@ -58,7 +58,19 @@ VVER=`echo ${VVERLINE} | cut -d " " -f 2` LATER=`echo $VVER \>= 3.9 | bc` if [[ $LATER > 0 ]]; then - echo "-DNEW_VERILATOR" + RLATER=`echo $VVER \>= 4.2 | bc` + if [[ $RLATER > 0 ]]; + then + ## I'm not quite certain when Verilator started requiring a further + ## subreference through rootp-> and including the Vdesgin___024root.h + ## include file. My best guess is that it is Verilator 4.2, but I don't + ## know that for certain. What I do know is that on the development + ## verrsion 4.211, it requires different semantics to peek at register + ## names. This is our attempt to capture that dependency. + echo "-DROOT_VERILATOR" + else + echo "-DNEW_VERILATOR" + fi else echo "-DOLD_VERILATOR" fi diff --git a/sim/verilated/zipelf.h b/sim/verilated/zipelf.h index 7ba4fbe..a19aeed 100644 --- a/sim/verilated/zipelf.h +++ b/sim/verilated/zipelf.h @@ -15,7 +15,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/sw/board/Makefile b/sw/board/Makefile index 0e70158..0334433 100644 --- a/sw/board/Makefile +++ b/sw/board/Makefile @@ -14,7 +14,7 @@ ## Copyright (C) 2016-2021, Gisselquist Technology, LLC ## {{{ ## This program is free software (firmware): you can redistribute it and/or -## modify it under the terms of the GNU General Public License as published +## 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. ## @@ -51,7 +51,7 @@ SUBMAKE:= $(MAKE) --no-print-directory -C # # TTTT := tttt -SOURCES := hello.c sdtest.c cputest.c gpiotoggle.c contest.c +SOURCES := hello.c sdtest.c cputest.c gpiotoggle.c contest.c rintftst.c HEADERS := DUMPRTL := -fdump-rtl-all DUMPTREE:= -fdump-tree-all @@ -109,6 +109,8 @@ contest: $(OBJDIR)/contest.o $(OBJDIR)/txfns.o board.ld $(LIB) $(OBJDIR)/hello.o: hello.c $(CC) -O3 -c $< -o $@ +$(OBJDIR)/rintftst.o: rintftst.c + $(CC) $(CFLAGS) -O3 -c $< -o $@ $(OBJDIR)/gettysburg.o: gettysburg.c $(CC) -O3 -c $< -o $@ $(OBJDIR)/gpiotoggle.o: gpiotoggle.c @@ -117,6 +119,9 @@ $(OBJDIR)/gpiotoggle.o: gpiotoggle.c hello: $(OBJDIR)/hello.o board.ld $(LIB) $(CC) $(CFLAGS) $(LFLAGS) $< $(LIBS) -o $@ +rintftst: $(OBJDIR)/rintftst.o $(OBJDIR)/txfns.o board.ld $(LIB) + $(CC) $(CFLAGS) $(LFLAGS) $< $(OBJDIR)/txfns.o $(LIBS) -o $@ + sdtest: $(OBJDIR)/sdtest.o board.ld $(LIB) $(CC) $(CFLAGS) $(LFLAGS) $< $(LIBS) -o $@ diff --git a/sw/board/bkram.ld b/sw/board/bkram.ld index b6c6f91..fb66c7f 100644 --- a/sw/board/bkram.ld +++ b/sw/board/bkram.ld @@ -18,7 +18,7 @@ * Copyright (C) 2017-2021, Gisselquist Technology, LLC * {{{ * This program is free software (firmware): you can redistribute it and/or -* modify it under the terms of the GNU General Public License as published +* 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. * @@ -48,7 +48,9 @@ MEMORY * has a defined name in its @LD.NAME tag, it will be listed here * under that name, otherwise it will be listed under it's * @$(PREFIX) tag with an underscore prepended to it. The permissions - * are given by the @LD.PERM tag. If no permission tag exists, a + * are given by the @LD.PERM tag. Allowable permissions include + * 'r' (read only), 'rx' (read and execute, but no writes), + * 'wx' (read, write, and execute). If no permission tag exists, a * permission of 'r' will be assumed. */ bkram(wx) : ORIGIN = 0x00c00000, LENGTH = 0x00100000 diff --git a/sw/board/board.ld b/sw/board/board.ld index a4b010b..b7a6a21 100644 --- a/sw/board/board.ld +++ b/sw/board/board.ld @@ -18,7 +18,7 @@ * Copyright (C) 2017-2021, Gisselquist Technology, LLC * {{{ * This program is free software (firmware): you can redistribute it and/or -* modify it under the terms of the GNU General Public License as published +* 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. * @@ -48,7 +48,9 @@ MEMORY * has a defined name in its @LD.NAME tag, it will be listed here * under that name, otherwise it will be listed under it's * @$(PREFIX) tag with an underscore prepended to it. The permissions - * are given by the @LD.PERM tag. If no permission tag exists, a + * are given by the @LD.PERM tag. Allowable permissions include + * 'r' (read only), 'rx' (read and execute, but no writes), + * 'wx' (read, write, and execute). If no permission tag exists, a * permission of 'r' will be assumed. */ bkram(wx) : ORIGIN = 0x00c00000, LENGTH = 0x00100000 diff --git a/sw/board/contest.c b/sw/board/contest.c index 1f597be..4e063bd 100644 --- a/sw/board/contest.c +++ b/sw/board/contest.c @@ -16,7 +16,7 @@ // Copyright (C) 2019-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/sw/board/cputest.c b/sw/board/cputest.c index 35e1c49..ed22ae1 100644 --- a/sw/board/cputest.c +++ b/sw/board/cputest.c @@ -17,7 +17,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/sw/board/gpiotoggle.c b/sw/board/gpiotoggle.c index 160f219..0bcc3d3 100644 --- a/sw/board/gpiotoggle.c +++ b/sw/board/gpiotoggle.c @@ -15,7 +15,7 @@ // Copyright (C) 2020-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/sw/board/hellosim.s b/sw/board/hellosim.s index 70a3d8a..a10c00c 100644 --- a/sw/board/hellosim.s +++ b/sw/board/hellosim.s @@ -1,7 +1,7 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; Filename: hellosim.s -;; +;; {{{ ;; Project: Zip CPU -- a small, lightweight, RISC CPU soft core ;; ;; Purpose: Hello World, only using the SIM instructions, as an initial @@ -12,11 +12,11 @@ ;; Gisselquist Technology, LLC ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; -;; Copyright (C) 2017-2019, Gisselquist Technology, LLC -;; +;; }}} +;; Copyright (C) 2017-2021, Gisselquist Technology, LLC +;; {{{ ;; This program is free software (firmware): you can redistribute it and/or -;; modify it under the terms of the GNU General Public License as published +;; 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. ;; @@ -24,14 +24,14 @@ ;; ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ;; for more details. -;; +;; }}} ;; License: GPL, v3, as defined and found on www.gnu.org, +;; {{{ ;; http://www.gnu.org/licenses/gpl.html ;; -;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; -;; +;; }}} .section .start, "ax" .global _start _start: diff --git a/sw/board/sdtest.c b/sw/board/sdtest.c index 064d9df..6bc4b71 100644 --- a/sw/board/sdtest.c +++ b/sw/board/sdtest.c @@ -15,7 +15,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/sw/board/txfns.c b/sw/board/txfns.c index cd45f0a..5cfd95d 100644 --- a/sw/board/txfns.c +++ b/sw/board/txfns.c @@ -18,7 +18,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/sw/board/txfns.h b/sw/board/txfns.h index 324fddc..5a66341 100644 --- a/sw/board/txfns.h +++ b/sw/board/txfns.h @@ -18,7 +18,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/sw/host/Makefile b/sw/host/Makefile index 1dd30f5..6949f53 100644 --- a/sw/host/Makefile +++ b/sw/host/Makefile @@ -1,7 +1,7 @@ ################################################################################ ## ## Filename: Makefile -## +## {{{ ## Project: ZBasic, a generic toplevel impl using the full ZipCPU ## ## Purpose: @@ -11,11 +11,11 @@ ## Gisselquist Technology, LLC ## ################################################################################ -## -## Copyright (C) 2015-2020, Gisselquist Technology, LLC -## +## }}} +## Copyright (C) 2015-2021, Gisselquist Technology, LLC +## {{{ ## This program is free software (firmware): you can redistribute it and/or -## modify it under the terms of the GNU General Public License as published +## 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. ## @@ -28,14 +28,14 @@ ## with this program. (It's in the $(ROOT)/doc directory. Run make with no ## target there if the PDF file isn't present.) If not, see ## for a copy. -## +## }}} ## License: GPL, v3, as defined and found on www.gnu.org, +## {{{ ## http://www.gnu.org/licenses/gpl.html ## -## ################################################################################ ## -## +## }}} .PHONY: all PROGRAMS := wbregs netuart zipload zipstate zipdbg SCOPES := diff --git a/sw/host/byteswap.cpp b/sw/host/byteswap.cpp index 7dd69e8..7ec4ce1 100644 --- a/sw/host/byteswap.cpp +++ b/sw/host/byteswap.cpp @@ -17,7 +17,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/sw/host/byteswap.h b/sw/host/byteswap.h index fc768e2..a339bb6 100644 --- a/sw/host/byteswap.h +++ b/sw/host/byteswap.h @@ -17,7 +17,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/sw/host/devbus.h b/sw/host/devbus.h index 0d7e737..49b1471 100644 --- a/sw/host/devbus.h +++ b/sw/host/devbus.h @@ -25,7 +25,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/sw/host/dumpflash.cpp b/sw/host/dumpflash.cpp index 90ed78f..a811d5a 100644 --- a/sw/host/dumpflash.cpp +++ b/sw/host/dumpflash.cpp @@ -15,7 +15,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/sw/host/flashdrvr.cpp b/sw/host/flashdrvr.cpp index dff3142..6206928 100644 --- a/sw/host/flashdrvr.cpp +++ b/sw/host/flashdrvr.cpp @@ -15,7 +15,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/sw/host/flashdrvr.h b/sw/host/flashdrvr.h index 0d12f69..481b80c 100644 --- a/sw/host/flashdrvr.h +++ b/sw/host/flashdrvr.h @@ -15,7 +15,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/sw/host/llcomms.cpp b/sw/host/llcomms.cpp index 7555292..0c735c2 100644 --- a/sw/host/llcomms.cpp +++ b/sw/host/llcomms.cpp @@ -18,7 +18,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/sw/host/llcomms.h b/sw/host/llcomms.h index 1d53a49..bca3a9f 100644 --- a/sw/host/llcomms.h +++ b/sw/host/llcomms.h @@ -17,7 +17,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/sw/host/netuart.cpp b/sw/host/netuart.cpp index 7b8a0ca..70edd09 100644 --- a/sw/host/netuart.cpp +++ b/sw/host/netuart.cpp @@ -14,7 +14,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/sw/host/port.h b/sw/host/port.h index 9bede2c..9c4c377 100644 --- a/sw/host/port.h +++ b/sw/host/port.h @@ -18,7 +18,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // diff --git a/sw/host/regdefs.cpp b/sw/host/regdefs.cpp index aefe4e7..b477a59 100644 --- a/sw/host/regdefs.cpp +++ b/sw/host/regdefs.cpp @@ -18,7 +18,7 @@ // Copyright (C) 2017-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -140,14 +140,6 @@ unsigned addrdecode(const char *v) { for(int i=0; iu_fifo & 0x10000)==0) +#define _uart_txidle ((_uart->u_tx & 0x100) ==0) #define BUSPIC(X) (1< Date: Tue, 14 Sep 2021 14:37:30 -0400 Subject: [PATCH 03/11] Updated ZipDBG. Should now work --- sw/host/zipdbg.cpp | 172 ++++++++++++++++++++++++++------------------- 1 file changed, 100 insertions(+), 72 deletions(-) diff --git a/sw/host/zipdbg.cpp b/sw/host/zipdbg.cpp index 91b4ad0..c9feaea 100644 --- a/sw/host/zipdbg.cpp +++ b/sw/host/zipdbg.cpp @@ -40,7 +40,7 @@ // }}} // BUGS: // - No ability to verify CPU functionality (3rd party simulator) -// - No ability to set/clear breakpoints +// - No ability to set/clear breakpoints (yet) // // #include @@ -107,7 +107,11 @@ class ZIPPY : public DEVBUS { m_show_users_timers(false), m_show_cc(false) {} void read_raw_state(void) { + // {{{ m_state.m_valid = false; + + // Read registers and peripherals + // {{{ readi(R_ZIPREGS, 16, m_state.m_sR); readi(R_ZIPUSER, 16, m_state.m_uR); readi(R_ZIPSYSTEM, 20, m_state.m_p); @@ -115,7 +119,10 @@ class ZIPPY : public DEVBUS { m_state.m_gie = (m_state.m_sR[14] & 0x020); m_state.m_pc = (m_state.m_gie) ? (m_state.m_uR[15]):(m_state.m_sR[15]); m_state.m_sp = (m_state.m_gie) ? (m_state.m_uR[13]):(m_state.m_sR[13]); + // }}} + // Read the instructions in memory + // {{{ if (m_state.m_last_pc_valid) m_state.m_imem[0].m_a = m_state.m_last_pc; else @@ -150,22 +157,43 @@ class ZIPPY : public DEVBUS { m_state.m_imem[i+1].m_valid = false; } } + // }}} + // Read the stack + // {{{ m_state.m_smem[0].m_a = m_state.m_sp; - for(int i=1; i<5; i++) - m_state.m_smem[i].m_a = m_state.m_smem[i-1].m_a+4; - for(int i=0; i<5; i++) { - m_state.m_smem[i].m_valid = true; - if (m_state.m_smem[i].m_valid) - try { - m_state.m_smem[i].m_d = readio(m_state.m_smem[i].m_a); + + try { // Try a fast read. Works if no bus errors + // {{{ + unsigned int buffer[5]; + readi(m_state.m_sp, 5, buffer); + for(int i=0; i<5; i++) { m_state.m_smem[i].m_valid = true; - } catch(BUSERR be) { - m_state.m_smem[i].m_valid = false; + m_state.m_smem[i].m_a = m_state.m_sp + 4*i; + m_state.m_smem[i].m_d = buffer[i]; + } + // }}} + } catch(BUSERR be) { + // {{{ + // Got a bus error. Try reading each value + // from the stack individually. + for(int i=0; i<5; i++) { + m_state.m_smem[i].m_valid = true; + if (m_state.m_smem[i].m_valid) + try { + m_state.m_smem[i].m_d = readio(m_state.m_smem[i].m_a); + m_state.m_smem[i].m_valid = true; + } catch(BUSERR be) { + m_state.m_smem[i].m_valid = false; + } } + // }}} } + // }}} + m_state.m_valid = true; } + // }}} void kill(void) { m_fpga->kill(); } void close(void) { m_fpga->close(); } @@ -193,29 +221,38 @@ class ZIPPY : public DEVBUS { bool stalled(void) { return ((readio(R_ZIPCTRL)&CPU_STALL)==0); } void show_user_timers(bool v) { + // {{{ m_show_users_timers = v; } + // }}} void toggle_cc(void) { + // {{{ m_show_cc = !m_show_cc; } + // }}} void showval(int y, int x, const char *lbl, unsigned int v, bool c) { + // {{{ if (c) mvprintw(y,x, ">%s> 0x%08x<", lbl, v); else mvprintw(y,x, " %s: 0x%08x ", lbl, v); } + // }}} void dispreg(int y, int x, const char *n, unsigned int v, bool c) { + // {{{ // 4,4,8,1 = 17 of 20, +2 = 18 if (c) mvprintw(y, x, ">%s> 0x%08x<", n, v); else mvprintw(y, x, " %s: 0x%08x ", n, v); } + // }}} int showins(int y, const char *lbl, const unsigned int pcidx, bool ignore_a) { + // {{{ char la[80], lb[80]; int r = y-1, bln = r; @@ -246,8 +283,10 @@ class ZIPPY : public DEVBUS { return r; } + // }}} void showstack(int y, const char *lbl, const unsigned int idx) { + // {{{ mvprintw(y, 27+26, "%s%08x ", lbl, m_state.m_smem[idx].m_a); if (m_state.m_gie) attroff(A_BOLD); @@ -259,73 +298,26 @@ class ZIPPY : public DEVBUS { printw("(Bus Err)"); attroff(A_BOLD); } + // }}} + // Routine is not used + /* unsigned int cmd_read(unsigned int a) { - /* - int errcount = 0; - unsigned int s; - - writeio(R_ZIPCTRL, CMD_HALT|(a&0x3f)); - while((((s=readio(R_ZIPCTRL))&CPU_STALL)== 0)&&(errcount= MAXERR) { - endwin(); - printf("ERR: errcount(%d) >= MAXERR on cmd_read(a=%2x)\n", errcount, a); - printf("ZIPCTRL = 0x%08x", s); - if ((s & 0x0200)==0) printf(" STALL"); - if (s & 0x0400) printf(" HALTED"); - if ((s & 0x03000)==0x01000) - printf(" SW-HALT"); - else { - if (s & 0x01000) printf(" SLEEPING"); - if (s & 0x02000) printf(" GIE(UsrMode)"); - } printf("\n"); - exit(EXIT_FAILURE); - } - return readio(R_ZIPDATA); - */ - + // {{{ return readio(R_ZIPREGS + (4*a)); } + // }}} + */ + // Writes to the CPU are simpler with our newer cmd_write interface void cmd_write(unsigned int a, int v) { - /* - int errcount = 0; - unsigned int s; - - writeio(R_ZIPCTRL, CMD_HALT|(a&0x3f)); - while((((s=readio(R_ZIPCTRL))&CPU_STALL)== 0)&&(errcount= MAXERR) { - endwin(); - printf("ERR: errcount(%d) >= MAXERR on cmd_read(a=%2x)\n", errcount, a); - printf("ZIPCTRL = 0x%08x", s); - if ((s & 0x0200)==0) printf(" STALL"); - if (s & 0x0400) printf(" HALTED"); - if ((s & 0x03000)==0x01000) - printf(" SW-HALT"); - else { - if (s & 0x01000) printf(" SLEEPING"); - if (s & 0x02000) printf(" GIE(UsrMode)"); - } printf("\n"); - exit(EXIT_FAILURE); - } - - writeio(R_ZIPDATA, (unsigned int)v); - */ - + // {{{ writeio(R_ZIPREGS+(4*a), (unsigned int)v); } + // }}} void read_state(void) { + // {{{ int ln= 0; bool gie; @@ -336,6 +328,8 @@ class ZIPPY : public DEVBUS { else if (m_cursor >= 44) m_cursor = 43; + // Peripheral state + // {{{ mvprintw(ln,0, "Peripherals"); mvprintw(ln,30,"%-50s", "CPU State: "); { @@ -382,7 +376,10 @@ class ZIPPY : public DEVBUS { showval(ln,40, "UPST", m_state.m_p[14], (m_cursor==10)); showval(ln,60, "UICT", m_state.m_p[15], (m_cursor==11)); } + // }}} + // Draw supervisor registers + // {{{ ln++; ln++; unsigned int cc = m_state.m_sR[14]; @@ -434,7 +431,10 @@ class ZIPPY : public DEVBUS { } dispreg(ln,60, "sPC ", m_state.m_sR[15], (m_cursor==27)); ln++; + // }}} + // Draw user registers + // {{{ if (gie) attron(A_BOLD); else @@ -479,10 +479,13 @@ class ZIPPY : public DEVBUS { (cc&1)?"Z":" "); } dispreg(ln,60, "uPC ", m_state.m_uR[15], (m_cursor==43)); + // }}} attroff(A_BOLD); ln+=3; + // Show instruction pipe and top of stack + // {{{ showins(ln+4, " ", 0, true); { int lclln = ln+3; @@ -491,7 +494,9 @@ class ZIPPY : public DEVBUS { for(int i=0; i<5; i++) showstack(ln+i, (i==0)?">":" ", i); } + // }}} } + // }}} void cursor_up(void) { if (m_cursor > 3) @@ -517,21 +522,27 @@ const int ZIPPY::MAXERR = 100000; FPGA *m_fpga; void get_value(ZIPPY *zip) { + // {{{ int wy, wx, ra; int c = zip->cursor(); - wx = (c & 0x03) * 20 + 9 + 1; + wx = (c & 0x03) * 20 + 9; wy = (c >> 2); if (wy >= 3+4) wy++; - if (wy > 3) + if (wy >= 3) wy += 2; wy++; + // Get the register address from the cursor position + // {{{ if (c >= 12) + // ZipCPU registers have an offset of 12 from the cursor + // address ra = c - 12; else ra = c + 32; + // }}} bool done = false; char str[16]; @@ -539,8 +550,11 @@ void get_value(ZIPPY *zip) { attron(A_NORMAL | A_UNDERLINE); mvprintw(wy, wx, "%-8s", ""); while(!done) { + // Get a keypress int chv = getch(); - switch(chv) { + + switch(chv) { // Process the keypress + // {{{ case KEY_ESCAPE: pos = 0; str[pos] = '\0'; done = true; break; @@ -569,39 +583,53 @@ void get_value(ZIPPY *zip) { case 'D': case 'd': str[pos++] = 'D'; break; case 'E': case 'e': str[pos++] = 'E'; break; case 'F': case 'f': str[pos++] = 'F'; break; + // }}} } + // Update the value on the screen + // {{{ if (pos > 8) pos = 8; str[pos] = '\0'; attron(A_NORMAL | A_UNDERLINE); - mvprintw(wy, wx, "%-8s", str); + mvprintw(wy, wx, "%8s", str); + /* if (pos > 0) { attron(A_NORMAL | A_UNDERLINE | A_BLINK); - mvprintw(wy, wx+pos-1, "%c", str[pos-1]); + mvprintw(wy, wx, "%s", str); } + */ attrset(A_NORMAL); + // }}} } + // Update a register by writing a new value to it + // {{{ if (pos > 0) { int v; v = strtoul(str, NULL, 16); zip->cmd_write(ra, v); } + // }}} } +// }}} void on_sigint(int v) { + // {{{ endwin(); fprintf(stderr, "Interrupted!\n"); exit(-2); } +// }}} void stall_screen(void) { + // {{{ erase(); mvprintw(0,0, "CPU is stalled. (Q to quit)\n"); } +// }}} char gbl_errstr[8192]; void eprintf(const char *fmt, ...) { From a551031e379176fd7585fd20938dc0c3a4494eca Mon Sep 17 00:00:00 2001 From: ZipCPU Date: Fri, 1 Oct 2021 14:02:24 -0400 Subject: [PATCH 04/11] More CPU upgrades, better LOCK handling --- rtl/builddate.v | 6 +- rtl/cpu/axiops.v | 59 +++++---- rtl/cpu/busdelay.v | 1 - rtl/cpu/cpudefs.v | 1 - rtl/cpu/cpuops.v | 2 - rtl/cpu/dblfetch.v | 1 - rtl/cpu/div.v | 189 +-------------------------- rtl/cpu/icontrol.v | 1 - rtl/cpu/idecode.v | 5 +- rtl/cpu/memops.v | 4 - rtl/cpu/mpyop.v | 1 - rtl/cpu/pfcache.v | 6 - rtl/cpu/pipemem.v | 1 - rtl/cpu/prefetch.v | 2 - rtl/cpu/slowmpy.v | 95 +------------- rtl/cpu/wbarbiter.v | 121 +---------------- rtl/cpu/wbdblpriarb.v | 1 - rtl/cpu/wbdmac.v | 2 - rtl/cpu/wbwatchdog.v | 54 +------- rtl/cpu/zipbones.v | 34 +---- rtl/cpu/zipcore.v | 292 +++++++++++++++++++++++++++++++++--------- rtl/cpu/zipjiffies.v | 113 +--------------- rtl/cpu/zipsystem.v | 21 ++- rtl/cpu/ziptimer.v | 1 - rtl/cpu/zipwb.v | 9 +- rtl/wbubus/wbufifo.v | 1 - sw/board/cputest.c | 26 ++-- sw/host/zipelf.h | 4 +- sw/zlib/syscalls.c | 20 ++- sw/zlib/zipcpu.h | 2 +- 30 files changed, 329 insertions(+), 746 deletions(-) diff --git a/rtl/builddate.v b/rtl/builddate.v index 18f66e8..0a99a88 100644 --- a/rtl/builddate.v +++ b/rtl/builddate.v @@ -17,7 +17,7 @@ // Copyright (C) 2015-2021, Gisselquist Technology, LLC // {{{ // This program is free software (firmware): you can redistribute it and/or -// modify it under the terms of the GNU General Public License as published +// 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. // @@ -39,7 +39,7 @@ // // }}} `ifndef DATESTAMP -`define DATESTAMP 32'h20210914 -`define BUILDTIME 32'h00113009 +`define DATESTAMP 32'h20210930 +`define BUILDTIME 32'h00223316 `endif // diff --git a/rtl/cpu/axiops.v b/rtl/cpu/axiops.v index 65dc3d3..22a903c 100644 --- a/rtl/cpu/axiops.v +++ b/rtl/cpu/axiops.v @@ -222,7 +222,7 @@ module axiops #( swapped_wstrb_byte; reg [DW-1:0] axi_wdata; reg [DW/8-1:0] axi_wstrb; - reg r_lock; + reg axlock; reg [AXILSB-1:0] swapaddr; wire [DW-1:0] endian_swapped_rdata; reg [2*DW-1:0] pre_result; @@ -287,33 +287,38 @@ module axiops #( end // }}} - // r_lock + // axlock // {{{ - initial r_lock = 1'b0; + initial axlock = 1'b0; always @(posedge i_clk) if (!OPT_LOCK || (!S_AXI_ARESETN && OPT_LOWPOWER)) begin // {{{ - r_lock <= 1'b0; + axlock <= 1'b0; // }}} end else if (M_AXI_BREADY || M_AXI_RREADY) begin // Something is outstanding // {{{ if (OPT_LOWPOWER && (M_AXI_BVALID || M_AXI_RVALID)) - r_lock <= 1'b0; + axlock <= axlock && i_lock && M_AXI_RVALID; // }}} end else begin // New memory operation // {{{ // Initiate a request - r_lock <= i_lock && i_stb; - - if (OPT_LOWPOWER && (i_cpu_reset || o_err || w_misaligned)) - r_lock <= 1'b0; + if (!OPT_LOWPOWER) + axlock <= i_lock; + else begin + if (i_stb) + axlock <= i_lock; + + if (i_cpu_reset || o_err || w_misaligned) + axlock <= 1'b0; + end // }}} end - assign M_AXI_AWLOCK = r_lock; - assign M_AXI_ARLOCK = r_lock; + assign M_AXI_AWLOCK = axlock; + assign M_AXI_ARLOCK = axlock; // }}} // r_flushing @@ -392,34 +397,34 @@ module axiops #( // M_AXI_AxSIZE // {{{ - reg [2:0] awsize; + reg [2:0] axsize; - initial awsize = DSZ; + initial axsize = DSZ; always @(posedge i_clk) if (!S_AXI_ARESETN) - awsize <= DSZ; + axsize <= DSZ; else if (!M_AXI_BREADY && !M_AXI_RREADY && (!OPT_LOWPOWER || i_stb)) begin casez(i_op[2:1]) 2'b0?: begin - awsize <= 3'b010; // Word + axsize <= 3'b010; // Word if ((|i_addr[1:0]) && !w_misaligned) - awsize <= AXILSB[2:0]; + axsize <= AXILSB[2:0]; end 2'b10: begin - awsize <= 3'b001; // Half-word + axsize <= 3'b001; // Half-word if (i_addr[0] && !w_misaligned) - awsize <= AXILSB[2:0]; + axsize <= AXILSB[2:0]; end - 2'b11: awsize <= 3'b000; // Byte + 2'b11: axsize <= 3'b000; // Byte endcase if (SWAP_WSTRB) - awsize <= DSZ; + axsize <= DSZ; end - assign M_AXI_AWSIZE = awsize; - assign M_AXI_ARSIZE = M_AXI_AWSIZE; + assign M_AXI_AWSIZE = axsize; + assign M_AXI_ARSIZE = axsize; // }}} // AxOTHER @@ -775,7 +780,7 @@ module axiops #( always @(posedge i_clk) if (i_cpu_reset || r_flushing) o_valid <= 1'b0; - else if (r_lock) + else if (axlock) o_valid <= (M_AXI_RVALID && M_AXI_RRESP == EXOKAY) || (M_AXI_BVALID && M_AXI_BRESP == OKAY); else @@ -791,7 +796,7 @@ module axiops #( o_err <= 1'b0; else if (i_stb && w_misalignment_err) o_err <= 1'b1; - else if (r_lock) + else if (axlock) begin o_err <= (M_AXI_BVALID && M_AXI_BRESP[1]) || (M_AXI_RVALID && M_AXI_RRESP != EXOKAY); @@ -809,7 +814,7 @@ module axiops #( always @(*) begin o_busy = M_AXI_BREADY || M_AXI_RREADY; - o_rdbusy = (M_AXI_BREADY && r_lock) || M_AXI_RREADY; + o_rdbusy = (M_AXI_BREADY && axlock) || M_AXI_RREADY; if (r_flushing) o_rdbusy = 1'b0; end @@ -900,7 +905,7 @@ module axiops #( else begin // {{{ if (OPT_LOCK && M_AXI_BVALID && (!OPT_LOWPOWER - || (r_lock && M_AXI_BRESP == OKAY))) + || (axlock && M_AXI_BRESP == OKAY))) begin o_result <= 0; o_result[AW-1:0] <= r_pc; @@ -940,7 +945,7 @@ module axiops #( if (OPT_LOWPOWER && (M_AXI_RRESP[1] || pending_err || misaligned_response_pending - || (r_lock && !M_AXI_RRESP[0]))) + || (axlock && !M_AXI_RRESP[0]))) o_result <= 0; // }}} end diff --git a/rtl/cpu/busdelay.v b/rtl/cpu/busdelay.v index 9f95571..f1146f1 100644 --- a/rtl/cpu/busdelay.v +++ b/rtl/cpu/busdelay.v @@ -60,7 +60,6 @@ // //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none // }}} module busdelay #( diff --git a/rtl/cpu/cpudefs.v b/rtl/cpu/cpudefs.v index c769f3a..def299c 100644 --- a/rtl/cpu/cpudefs.v +++ b/rtl/cpu/cpudefs.v @@ -49,7 +49,6 @@ // {{{ // http://www.gnu.org/licenses/gpl.html // -// //////////////////////////////////////////////////////////////////////////////// // // }}} diff --git a/rtl/cpu/cpuops.v b/rtl/cpu/cpuops.v index 2bc3aab..06e4c3c 100644 --- a/rtl/cpu/cpuops.v +++ b/rtl/cpu/cpuops.v @@ -36,10 +36,8 @@ // //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none // -// `include "cpudefs.v" // }}} module cpuops #( diff --git a/rtl/cpu/dblfetch.v b/rtl/cpu/dblfetch.v index 59c34cc..24923dd 100644 --- a/rtl/cpu/dblfetch.v +++ b/rtl/cpu/dblfetch.v @@ -46,7 +46,6 @@ // //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none // }}} module dblfetch #( diff --git a/rtl/cpu/div.v b/rtl/cpu/div.v index 7fecd48..b8760c1 100644 --- a/rtl/cpu/div.v +++ b/rtl/cpu/div.v @@ -94,11 +94,8 @@ // //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none // }}} -// `include "cpudefs.v" -// module div #( parameter BW=32, LGBW = 5 ) ( @@ -395,191 +392,7 @@ module div #( //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// `ifdef FORMAL - reg f_past_valid; - initial f_past_valid = 0; - always @(posedge i_clk) - f_past_valid <= 1'b1; - -`ifdef DIV -`define ASSUME assume -`else -`define ASSUME assert -`endif - - initial `ASSUME(i_reset); - always @(*) - if (!f_past_valid) - `ASSUME(i_reset); - - always @(posedge i_clk) - if ((!f_past_valid)||($past(i_reset))) - begin - assert(!o_busy); - assert(!o_valid); - assert(!o_err); - // - assert(!r_busy); - // assert(!zero_divisor); - assert(r_bit==0); - assert(!last_bit); - assert(!pre_sign); - // assert(!r_z); - // assert(r_dividend==0); - assert(o_quotient==0); - assert(!r_c); - assert(r_divisor==0); - - `ASSUME(!i_wr); - end - - always @(*) - if (o_busy) - `ASSUME(!i_wr); - - always @(posedge i_clk) - if ((f_past_valid)&&(!$past(i_reset))&&($past(o_busy))&&(!o_busy)) - begin - assert(o_valid); - end - - // A formal methods section - // - // This section isn't yet complete. For now, it is just - // a description of things I think should be in here ... not - // yet a description of what it would take to prove - // this divide (yet). - always @(*) - if (o_err) - assert(o_valid); - - always @(posedge i_clk) - if ((f_past_valid)&&(!$past(i_wr))) - assert(!pre_sign); - always @(posedge i_clk) - if ((f_past_valid)&&(!$past(i_reset))&&($past(i_wr))&&($past(i_signed)) - &&(|$past({i_numerator[BW-1],i_denominator[BW-1]}))) - assert(pre_sign); - - // always @(posedge i_clk) - // if ((f_past_valid)&&(!$past(pre_sign))) - // assert(!r_sign); - reg [BW:0] f_bits_set; - - always @(posedge i_clk) - if ((f_past_valid)&&(!$past(i_reset))&&($past(i_wr))) - assert(o_busy); - - always @(posedge i_clk) - if ((f_past_valid)&&($past(o_valid))) - assert(!o_valid); - - always @(*) - if ((o_valid)&&(!o_err)) - begin - assert(r_z == ((o_quotient == 0)? 1'b1:1'b0)); - end else if (o_busy) - assert(r_z == (((o_quotient&f_bits_set[BW-1:0]) == 0)? 1'b1: 1'b0)); - - always @(*) - if ((o_valid)&&(!o_err)) - assert(w_n == o_quotient[BW-1]); - - always @(posedge i_clk) - if ((f_past_valid)&&(!$past(r_busy))&&(!$past(i_wr))) - assert(!o_busy); - always @(posedge i_clk) - assert((!o_busy)||(!o_valid)); - - always @(*) - if(r_busy) - assert(o_busy); - - always @(posedge i_clk) - if (i_reset) - f_bits_set <= 0; - else if (i_wr) - f_bits_set <= 0; - else if ((r_busy)&&(!pre_sign)) - f_bits_set <= { f_bits_set[BW-1:0], 1'b1 }; - - always @(posedge i_clk) - if (r_busy) - assert(((1<= $past(r_divisor[BW-1:0])) - begin - assert(o_quotient[0]); - end else - assert(!o_quotient[0]); - end - */ - - always @(*) - if (r_busy) - assert((f_bits_set & r_dividend[BW-1:0])==0); - - always @(*) - if (r_busy) - assert((r_divisor == 0) == zero_divisor); - -`ifdef VERIFIC - // {{{ - // Verify unsigned division - assert property (@(posedge i_clk) - disable iff (i_reset) - (i_wr)&&(i_denominator != 0)&&(!i_signed) - |=> ((!o_err)&&(!o_valid)&&(o_busy)&&(!r_sign)&&(!pre_sign) - throughout (r_bit == 0) - ##1 ((r_bit == $past(r_bit)+1)&&({1'b0,r_bit}< BW-1)) - [*0:$] - ##1 ({ 1'b0, r_bit } == BW-1)) - ##1 (!o_err)&&(o_valid)); - - // Verify division by zero - assert property (@(posedge i_clk) - disable iff (i_reset) - (i_wr)&&(i_denominator == 0) - |=> (zero_divisor throughout - (!o_err)&&(!o_valid)&&(pre_sign) [*0:1] - ##1 ((r_busy)&&(!o_err)&&(!o_valid)) - ##1 ((o_err)&&(o_valid)))); - - // }}} -`endif // VERIFIC +// The formal properties for this module are maintained elsewhere `endif // }}} endmodule diff --git a/rtl/cpu/icontrol.v b/rtl/cpu/icontrol.v index 171b260..b33a6f5 100644 --- a/rtl/cpu/icontrol.v +++ b/rtl/cpu/icontrol.v @@ -75,7 +75,6 @@ // //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none // }}} module icontrol #( diff --git a/rtl/cpu/idecode.v b/rtl/cpu/idecode.v index d5598a3..9f45f53 100644 --- a/rtl/cpu/idecode.v +++ b/rtl/cpu/idecode.v @@ -43,11 +43,8 @@ // //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none // }}} -// -// module idecode #( // {{{ parameter ADDRESS_WIDTH=24, @@ -876,6 +873,6 @@ module idecode #( //////////////////////////////////////////////////////////////////////////////// `ifdef FORMAL // Formal properties for this module are maintained elsewhere -`endif +`endif // FORMAL // }}} endmodule diff --git a/rtl/cpu/memops.v b/rtl/cpu/memops.v index c19c7d1..1c2d28b 100644 --- a/rtl/cpu/memops.v +++ b/rtl/cpu/memops.v @@ -43,7 +43,6 @@ // //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none // }}} module memops #( @@ -94,9 +93,6 @@ module memops #( // Declarations // {{{ -`ifdef FORMAL - wire [(F_LGDEPTH-1):0] f_nreqs, f_nacks, f_outstanding; -`endif reg misaligned; reg r_wb_cyc_gbl, r_wb_cyc_lcl; diff --git a/rtl/cpu/mpyop.v b/rtl/cpu/mpyop.v index 4be05d5..2c029c5 100644 --- a/rtl/cpu/mpyop.v +++ b/rtl/cpu/mpyop.v @@ -38,7 +38,6 @@ // //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none // }}} module mpyop #( diff --git a/rtl/cpu/pfcache.v b/rtl/cpu/pfcache.v index 9dcdc1b..d452542 100644 --- a/rtl/cpu/pfcache.v +++ b/rtl/cpu/pfcache.v @@ -58,7 +58,6 @@ // //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none // }}} module pfcache #( @@ -121,11 +120,6 @@ module pfcache #( assign o_wb_we = 1'b0; assign o_wb_data = 0; -`ifdef FORMAL - assign f_pc_wb = i_pc[AW+1:2]; -`endif - - wire r_v; reg [(BUSW-1):0] cache [0:CACHELEN-1]; reg [(AW-CW-1):0] cache_tags [0:((1<<(LGLINES))-1)]; diff --git a/rtl/cpu/pipemem.v b/rtl/cpu/pipemem.v index 7c43591..d096644 100644 --- a/rtl/cpu/pipemem.v +++ b/rtl/cpu/pipemem.v @@ -40,7 +40,6 @@ // //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none // }}} module pipemem #( diff --git a/rtl/cpu/prefetch.v b/rtl/cpu/prefetch.v index 4699f80..bc113ca 100644 --- a/rtl/cpu/prefetch.v +++ b/rtl/cpu/prefetch.v @@ -53,9 +53,7 @@ // //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none -// // }}} module prefetch #( // {{{ diff --git a/rtl/cpu/slowmpy.v b/rtl/cpu/slowmpy.v index 91d52c5..736e145 100644 --- a/rtl/cpu/slowmpy.v +++ b/rtl/cpu/slowmpy.v @@ -39,7 +39,6 @@ // //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none // }}} module slowmpy #( @@ -172,99 +171,7 @@ module slowmpy #( //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// `ifdef FORMAL - // Declarations and reset - // {{{ -`define ASSERT assert -`ifdef SLOWMPY -`define ASSUME assume -`else -`define ASSUME assert -`endif - - reg f_past_valid; - - initial f_past_valid = 1'b0; - always @(posedge i_clk) - f_past_valid <= 1'b1; - - initial assume(i_reset); - always @(*) - if (!f_past_valid) - `ASSUME(i_reset); - // }}} - - always @(posedge i_clk) - if ((!f_past_valid)||($past(i_reset))) - begin - `ASSERT(almost_done == 0); - `ASSERT(o_done == 0); - `ASSERT(o_busy == 0); - `ASSERT(aux == 0); - end - - // Assumptions about our inputs - always @(posedge i_clk) - if ((f_past_valid)&&(!$past(i_reset))&&($past(i_stb))&&($past(o_busy))) - begin - `ASSUME(i_stb); - `ASSUME($stable(i_a)); - `ASSUME($stable(i_b)); - end - - // - // For now, just formally verify our internal signaling - // {{{ - - always @(posedge i_clk) - `ASSERT(almost_done == (o_busy&&(&count))); - - always @(*) - if (!(&count[LGNA-1:1])||(count[0])) - `ASSERT(!o_done); - - always @(posedge i_clk) - if (o_done) - `ASSERT(!o_busy); - always @(posedge i_clk) - if (!o_busy) - `ASSERT(!almost_done); - - reg [NA-1:0] f_a, f_b; - always @(posedge i_clk) - if ((i_stb)&&(!o_busy)) - begin - f_a <= i_a; - f_b <= i_b; - end - - always @(*) - if (o_done) - begin - if ((f_a == 0)||(f_b == 0)) - begin - `ASSERT(o_p == 0); - end else - `ASSERT(o_p[NA+NB-1] == f_a[NA-1] ^ f_b[NA-1]); - end - // }}} - //////////////////////////////////////////////////////////////////////// - // - // Cover properties - // {{{ - //////////////////////////////////////////////////////////////////////// - // - always @(posedge i_clk) - cover(o_done); - - reg cvr_past_done; - initial cvr_past_done = 1'b0; - always @(posedge i_clk) - if (o_done) - cvr_past_done <= 1'b1; - - always @(posedge i_clk) - cover((o_done)&&(cvr_past_done)); - // }}} +// Formal properties for this design are maintained elsewhere `endif // }}} endmodule diff --git a/rtl/cpu/wbarbiter.v b/rtl/cpu/wbarbiter.v index dfdfaac..3a31e05 100644 --- a/rtl/cpu/wbarbiter.v +++ b/rtl/cpu/wbarbiter.v @@ -57,7 +57,6 @@ // //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none // `define WBA_ALTERNATING @@ -258,125 +257,7 @@ module wbarbiter #( //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// `ifdef FORMAL - -`ifdef WBARBITER -`define ASSUME assume -`else -`define ASSUME assert -`endif - - reg f_past_valid; - initial f_past_valid = 1'b0; - always @(posedge i_clk) - f_past_valid <= 1'b1; - - initial `ASSUME(!i_a_cyc); - initial `ASSUME(!i_a_stb); - - initial `ASSUME(!i_b_cyc); - initial `ASSUME(!i_b_stb); - - initial `ASSUME(!i_ack); - initial `ASSUME(!i_err); - - always @(*) - if (!f_past_valid) - `ASSUME(i_reset); - - always @(posedge i_clk) - begin - if (o_cyc) - assert((i_a_cyc)||(i_b_cyc)); - if ((f_past_valid)&&($past(o_cyc))&&(o_cyc)) - assert($past(r_a_owner) == r_a_owner); - end - - fwb_master #( - // {{{ - .DW(DW), .AW(AW), - .F_MAX_STALL(F_MAX_STALL), - .F_LGDEPTH(F_LGDEPTH), - .F_MAX_ACK_DELAY(F_MAX_ACK_DELAY), - .F_OPT_RMW_BUS_OPTION(1), - .F_OPT_DISCONTINUOUS(1), - .F_OPT_CLK2FFLOGIC(1'b0) - // }}} - ) f_wbm ( - // {{{ - i_clk, i_reset, - o_cyc, o_stb, o_we, o_adr, o_dat, o_sel, - i_ack, i_stall, 32'h0, i_err, - f_nreqs, f_nacks, f_outstanding - // }}} - ); - - fwb_slave #( - // {{{ - .DW(DW), .AW(AW), - .F_MAX_STALL(0), - .F_LGDEPTH(F_LGDEPTH), - .F_MAX_ACK_DELAY(0), - .F_OPT_RMW_BUS_OPTION(1), - .F_OPT_DISCONTINUOUS(1), - .F_OPT_CLK2FFLOGIC(1'b0) - // }}} - ) f_wba ( - // {{{ - i_clk, i_reset, - i_a_cyc, i_a_stb, i_a_we, i_a_adr, i_a_dat, i_a_sel, - o_a_ack, o_a_stall, 32'h0, o_a_err, - f_a_nreqs, f_a_nacks, f_a_outstanding - // }}} - ); - - fwb_slave #( - // {{{ - .DW(DW), .AW(AW), - .F_MAX_STALL(0), - .F_LGDEPTH(F_LGDEPTH), - .F_MAX_ACK_DELAY(0), - .F_OPT_RMW_BUS_OPTION(1), - .F_OPT_DISCONTINUOUS(1), - .F_OPT_CLK2FFLOGIC(1'b0) - // }}} - ) f_wbb ( - // {{{ - i_clk, i_reset, - i_b_cyc, i_b_stb, i_b_we, i_b_adr, i_b_dat, i_b_sel, - o_b_ack, o_b_stall, 32'h0, o_b_err, - f_b_nreqs, f_b_nacks, f_b_outstanding - // }}} - ); - - // Induction properties, relating nreqs and nacks to r_a_owner - // {{{ - always @(posedge i_clk) - if (r_a_owner) - begin - assert(f_b_nreqs == 0); - assert(f_b_nacks == 0); - assert(f_a_outstanding == f_outstanding); - end else begin - assert(f_a_nreqs == 0); - assert(f_a_nacks == 0); - assert(f_b_outstanding == f_outstanding); - end - // }}} - - always @(posedge i_clk) - if ((f_past_valid)&&(!$past(i_reset)) - &&($past(i_a_stb))&&(!$past(i_b_cyc))) - assert(r_a_owner); - - always @(posedge i_clk) - if ((f_past_valid)&&(!$past(i_reset)) - &&(!$past(i_a_cyc))&&($past(i_b_stb))) - assert(!r_a_owner); - - always @(posedge i_clk) - if ((f_past_valid)&&(r_a_owner != $past(r_a_owner))) - assert(!$past(o_cyc)); - +// The formal properties for this module are maintained elsewhere `endif // }}} endmodule diff --git a/rtl/cpu/wbdblpriarb.v b/rtl/cpu/wbdblpriarb.v index a837c06..21c8568 100644 --- a/rtl/cpu/wbdblpriarb.v +++ b/rtl/cpu/wbdblpriarb.v @@ -67,7 +67,6 @@ // //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none // }}} module wbdblpriarb #( diff --git a/rtl/cpu/wbdmac.v b/rtl/cpu/wbdmac.v index 14e642e..52c3f54 100644 --- a/rtl/cpu/wbdmac.v +++ b/rtl/cpu/wbdmac.v @@ -110,8 +110,6 @@ // //////////////////////////////////////////////////////////////////////////////// // -// -// `default_nettype none // }}} module wbdmac #( diff --git a/rtl/cpu/wbwatchdog.v b/rtl/cpu/wbwatchdog.v index cc08549..0ca17ef 100644 --- a/rtl/cpu/wbwatchdog.v +++ b/rtl/cpu/wbwatchdog.v @@ -46,7 +46,6 @@ // //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none // }}} module wbwatchdog #( @@ -93,58 +92,7 @@ module wbwatchdog #( //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// `ifdef FORMAL - reg f_past_valid; - - initial f_past_valid = 1'b0; - always @(posedge f_past_valid) - f_past_valid <= 1'b1; - - //////////////////////////////////////////////////////////////////////// - // - // Assumptions about our inputs - // {{{ - //////////////////////////////////////////////////////////////////////// - // - // - always @(*) - assume(i_timeout > 1); - - always @(posedge i_clk) - if (f_past_valid) - assume(i_timeout == $past(i_timeout)); - // }}} - //////////////////////////////////////////////////////////////////////// - // - // Assertions about our internal state and our outputs - // {{{ - //////////////////////////////////////////////////////////////////////// - // - // - - always @(posedge i_clk) - if ((f_past_valid)&&($past(o_int))&&(!$past(i_reset))) - assert(o_int); - - always @(*) - assert(o_int == (r_value == 0)); - - always @(posedge i_clk) - if ((f_past_valid)&&(!$past(i_reset))&&(!$past(o_int))) - begin - assert(r_value == $past(r_value)-1'b1); - end - - always @(posedge i_clk) - if ((!f_past_valid)||($past(i_reset))) - begin - if (!f_past_valid) - begin - assert(r_value == {(BW){1'b1}}); - end else // if ($past(i_reset)) - assert(r_value == $past(i_timeout)); - assert(!o_int); - end - // }}} +// Formal properties are maintained elsewhere `endif // }}} endmodule diff --git a/rtl/cpu/zipbones.v b/rtl/cpu/zipbones.v index c12afb3..ae2768c 100644 --- a/rtl/cpu/zipbones.v +++ b/rtl/cpu/zipbones.v @@ -36,7 +36,6 @@ // //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none // `include "cpudefs.v" @@ -392,38 +391,7 @@ module zipbones #( // // The CPU itself // {{{ -`ifdef FORMAL - (* anyseq *) reg f_cpu_halted, f_cpu_data, f_cpu_stall, - f_cpu_break; - (* anyseq *) reg [2:0] f_cpu_dbg_cc; - (* anyseq *) reg [31:0] f_cpu_dbg_data; - - assign cpu_dbg_stall = f_cpu_stall; - assign cpu_break = f_cpu_break; - assign cpu_dbg_cc = f_cpu_dbg_cc; - assign cpu_dbg_data = f_cpu_dbg_data; - fdebug #( - // {{{ - .OPT_DISTRIBUTED_RAM(1'b1) - // }}} - ) fdbg ( - // {{{ - .i_clk(i_clk), - .i_reset(i_reset), - .i_cpu_reset(cpu_reset), - .i_halt(cpu_halt), - .i_halted(f_cpu_halted), - .i_clear_cache(cmd_clear_cache), - .i_dbg_we(cmd_write), - .i_dbg_reg(cmd_waddr), - .i_dbg_data(cmd_wdata), - .i_dbg_stall(cpu_dbg_stall), - .i_dbg_break(cpu_break), - .i_dbg_cc(cpu_dbg_cc) - // }}} - ); -`else zipwb #( // {{{ .RESET_ADDRESS(RESET_ADDRESS), @@ -476,7 +444,7 @@ module zipbones #( `endif // }}} ); -`endif + // }}} //////////////////////////////////////////////////////////////////////// // diff --git a/rtl/cpu/zipcore.v b/rtl/cpu/zipcore.v index 55a9c1f..04a13e8 100644 --- a/rtl/cpu/zipcore.v +++ b/rtl/cpu/zipcore.v @@ -131,7 +131,7 @@ module zipcore #( // Verilator lint_off UNUSED localparam [0:0] OPT_MEMPIPE = OPT_PIPELINED_BUS_ACCESS; localparam [(AW-1):0] RESET_BUS_ADDRESS = RESET_ADDRESS[(AW+1):2]; - localparam [0:0] OPT_LOCK=(IMPLEMENT_LOCK)&&(OPT_PIPELINED); + localparam [0:0] OPT_LOCK= IMPLEMENT_LOCK; localparam [3:0] CPU_CC_REG = 4'he, CPU_PC_REG = 4'hf; localparam [3:0] CPU_SUB_OP = 4'h0,// also a compare instruction @@ -581,7 +581,7 @@ module zipcore #( // {{{ assign master_stall = (!master_ce)||(!op_valid)||(ill_err_i) ||(ibus_err_flag)||(idiv_err_flag) - ||(pending_interrupt)&&(!alu_phase) + ||(pending_interrupt && !o_bus_lock)&&(!alu_phase) ||(alu_busy)||(div_busy)||(fpu_busy)||(op_break) ||((OPT_PIPELINED)&&( prelock_stall @@ -1097,7 +1097,7 @@ module zipcore #( // op_lock // {{{ - generate if ((!OPT_PIPELINED)||(!OPT_LOCK)) + generate if (!OPT_LOCK) begin : NO_OPLOCK assign op_lock = 1'b0; @@ -1108,7 +1108,7 @@ module zipcore #( // Verilator lint_on UNUSED end else // if (IMPLEMENT_LOCK != 0) - begin : OPLOCK + begin : GEN_OPLOCK reg r_op_lock; initial r_op_lock = 1'b0; @@ -1718,7 +1718,7 @@ module zipcore #( // Bus lock logic // {{{ generate - if ((OPT_PIPELINED)&&(!OPT_LOCK)) + if (OPT_LOCK) begin : BUSLOCK reg r_prelock_stall; reg r_prelock_primed; @@ -1729,7 +1729,7 @@ module zipcore #( // {{{ initial r_prelock_stall = 1'b0; always @(posedge i_clk) - if (clear_pipeline) + if (!OPT_PIPELINED || clear_pipeline) r_prelock_stall <= 1'b0; else if ((op_valid)&&(op_lock)&&(op_ce)) r_prelock_stall <= 1'b1; @@ -1741,7 +1741,9 @@ module zipcore #( // {{{ initial r_prelock_primed = 1'b0; always @(posedge i_clk) - if (clear_pipeline) + if (!OPT_PIPELINED) + r_prelock_primed <= 1'b1; + else if (clear_pipeline) r_prelock_primed <= 1'b0; else if (r_prelock_stall) r_prelock_primed <= 1'b1; @@ -1765,16 +1767,20 @@ module zipcore #( always @(posedge i_clk) if (clear_pipeline) r_bus_lock <= 2'b00; - else if ((op_valid)&&((adf_ce_unconditional)||(mem_ce))) + else if (op_valid && (adf_ce_unconditional||mem_ce)) begin - if (r_prelock_primed) + if (r_bus_lock != 2'b00) + r_bus_lock <= r_bus_lock - 1; + else if (!OPT_PIPELINED) + begin + if ((op_valid)&&(op_lock)&&(op_ce)) + r_bus_lock <= 2'b10; + end else if (r_prelock_primed) r_bus_lock <= 2'b10; - else if (r_bus_lock != 2'h0) - r_bus_lock <= r_bus_lock + 2'b11; end // }}} - assign prelock_stall = r_prelock_stall; + assign prelock_stall = OPT_PIPELINED && r_prelock_stall; assign o_bus_lock = |r_bus_lock; assign o_mem_lock_pc = r_lock_pc; end else begin @@ -2256,7 +2262,7 @@ module zipcore #( // step : debug single-step control // {{{ always @(posedge i_clk) - if (i_reset) + if (i_reset || OPT_NO_USERMODE) step <= 1'b0; else if ((wr_reg_ce)&&(!alu_gie)&&(wr_write_ucc)) step <= wr_spreg_vl[CPU_STEP_BIT]; @@ -2338,18 +2344,21 @@ module zipcore #( always @(posedge i_clk) if (i_reset) r_pending_interrupt <= 1'b0; - else if ((clear_pipeline)||(w_switch_to_interrupt)||(!gie)) + else if (!gie || clear_pipeline || w_switch_to_interrupt) r_pending_interrupt <= 1'b0; - else if (i_interrupt) - r_pending_interrupt <= 1'b1; - else if (adf_ce_unconditional) - begin - if ((op_illegal)||(step)||(break_pending)) + else begin + if (i_interrupt) + r_pending_interrupt <= 1'b1; + + if (break_pending) + r_pending_interrupt <= 1'b1; + + if (adf_ce_unconditional && op_illegal) + r_pending_interrupt <= 1'b1; + + if ((adf_ce_unconditional || mem_ce) && step) r_pending_interrupt <= 1'b1; - end else if (break_pending) - r_pending_interrupt <= 1'b1; - else if ((mem_ce)&&(step)) - r_pending_interrupt <= 1'b1; + end assign pending_interrupt = r_pending_interrupt && !i_halt; @@ -3500,7 +3509,8 @@ module zipcore #( `ASSERT(cc_invalid_for_dcd == (alu_wF || alu_reg == { gie, CPU_CC_REG })); end else if (i_mem_rdbusy || i_bus_err) begin - `ASSERT(i_bus_err || cc_invalid_for_dcd == (alu_reg == { gie, CPU_CC_REG })); + `ASSERT(i_bus_err || f_exwrite_cycle + || cc_invalid_for_dcd == (alu_reg == { gie, CPU_CC_REG })); end else if (!clear_pipeline && cc_invalid_for_dcd) begin `ASSERT(alu_illegal || wr_flags_ce @@ -3522,10 +3532,14 @@ module zipcore #( &&(!fpu_busy)&&(!fpu_valid)&&(!fpu_error) &&(!op_break)&&(!o_break) &&(!w_switch_to_interrupt) - &&(!alu_illegal) + &&(!alu_illegal) && (!prelock_stall) &&(!ibus_err_flag)&&(!ill_err_i)&&(!idiv_err_flag)) `ASSERT(adf_ce_unconditional | mem_ce); + always @(posedge i_clk) + if (f_past_valid&& $past(op_valid && dcd_valid && i_pf_valid && !op_ce)) + `ASSERT(!prelock_stall); + // // Make sure that, following an op_ce && op_valid, op_valid is only // true if dcd_valid was as well @@ -3894,12 +3908,13 @@ module zipcore #( `ASSERT(fc_op_lock == op_lock); `ASSERT(fc_op_break == op_break); `ASSERT(fc_op_I == 0 || !i_mem_rdbusy + || f_exwrite_cycle || !fc_op_rB || (fc_op_Bid[4:0] != f_last_reg && (f_mem_outstanding <= 1) && (!fc_op_M || !op_pipe)) || fc_op_Bid[4:0] == f_addr_reg); - if (!i_halt && !i_reset) + if (!i_halt && !i_reset && !f_exwrite_cycle) `ASSERT((!wr_reg_ce) ||(wr_reg_id != fc_op_Bid[4:0]) ||(!op_rB)||(fc_op_I == 0)); @@ -4012,7 +4027,7 @@ module zipcore #( if (i_mem_rdbusy) begin `ASSERT(fc_alu_M); - `ASSERT((!OPT_PIPELINED)||(fc_alu_wR)); + `ASSERT(!OPT_PIPELINED||fc_alu_wR || (OPT_LOCK && f_mem_pc)); end always @(*) @@ -4130,7 +4145,8 @@ module zipcore #( fmem #( // {{{ - .IMPLEMENT_LOCK(OPT_LOCK), .F_LGDEPTH(F_LGDEPTH), + .IMPLEMENT_LOCK(OPT_LOCK), + .F_LGDEPTH(F_LGDEPTH), .OPT_MAXDEPTH((OPT_PIPELINED && OPT_PIPELINED_BUS_ACCESS) ? 14:1), .OPT_AXI_LOCK(2) // Let the solver pick @@ -4167,7 +4183,7 @@ module zipcore #( begin // {{{ if (i_mem_rdbusy) - `ASSERT(op_opn[0] == 1'b0); + `ASSERT(op_opn[0] == f_exwrite_cycle); if (f_mem_outstanding > ((i_bus_err || i_mem_valid) ? 1:0)) `ASSERT(op_opn[0] != fc_alu_wR); @@ -4210,7 +4226,7 @@ module zipcore #( `ASSERT(op_Bid[3:1] != 3'h7); - if ((i_mem_rdbusy)||(i_mem_valid)) + if ((i_mem_rdbusy||i_mem_valid) && !f_exwrite_cycle) begin if (!OPT_MEMPIPE) begin @@ -4246,12 +4262,12 @@ module zipcore #( // Check f_addr_reg and f_last_reg // {{{ always @(*) - if (OPT_MEMPIPE && (op_valid && op_rB) - &&(!f_op_zI)&&((i_mem_rdbusy)||(i_mem_valid))) + if (OPT_MEMPIPE && (op_valid && op_rB) && !f_exwrite_cycle + &&(!f_op_zI)&&(i_mem_rdbusy || i_mem_valid)) `ASSERT(f_last_reg != op_Bid); always @(*) - if (i_mem_rdbusy) + if (i_mem_rdbusy && !f_exwrite_cycle) `ASSERT(f_last_reg == alu_reg); always @(*) @@ -4577,7 +4593,11 @@ module zipcore #( `ASSERT(alu_wR); if (!i_mem_valid) `ASSERT(fc_alu_Rid[4:0] == alu_reg); - `ASSERT((!alu_wR)||(fc_alu_wR == alu_wR)); + if (f_exwrite_cycle) + begin + `ASSERT(!alu_wR); + end else + `ASSERT((!alu_wR)||(fc_alu_wR == alu_wR)); if (alu_valid) `ASSERT(fc_alu_wF == alu_wF); if (!fc_alu_wF) @@ -4590,16 +4610,18 @@ module zipcore #( if (f_mem_pc && i_mem_rdbusy) begin // {{{ - `ASSERT(!OPT_PIPELINED || cc_invalid_for_dcd + `ASSERT(!OPT_PIPELINED || cc_invalid_for_dcd || !fc_alu_wR || fc_alu_Rid[4:0] != { gie, CPU_CC_REG }); `ASSERT(!mem_ce); - if (OPT_PIPELINED && fc_alu_Rid[4:0] != { gie, CPU_PC_REG }) + if (OPT_PIPELINED && fc_alu_Rid[4:0] != { gie, CPU_PC_REG } + && (!OPT_LOCK || fc_alu_wR)) `ASSERT(pending_sreg_write); if ((!OPT_DCACHE)||(!OPT_MEMPIPE)) begin `ASSERT(!fc_alu_prepipe); - end else if ((i_mem_rdbusy)&&(!$past(mem_ce))&&(!$past(mem_ce,2))) + end else if ((i_mem_rdbusy && !f_exwrite_cycle) + &&(!$past(mem_ce))&&(!$past(mem_ce,2))) `ASSERT(!fc_alu_prepipe); // }}} end else if (i_mem_rdbusy) @@ -4618,8 +4640,9 @@ module zipcore #( // what type of operation we are in `ASSERT(!fc_alu_illegal); `ASSERT(fc_alu_M); - `ASSERT(alu_reg == f_last_reg); - if (alu_reg == f_addr_reg) + if (!f_exwrite_cycle) + `ASSERT(alu_reg == f_last_reg); + if (!f_exwrite_cycle && alu_reg == f_addr_reg) `ASSERT(!op_pipe); if (fc_alu_cond[3]) `ASSERT(fc_alu_Rid[4:0] == alu_reg); @@ -4647,6 +4670,26 @@ module zipcore #( end // }}} + always @(*) + if (!fc_alu_wR && i_mem_rdbusy) + begin + `ASSERT(OPT_LOCK); + `ASSERT(f_mem_outstanding == 1); + `ASSERT(f_mem_pc); + `ASSERT(!f_read_cycle); + `ASSERT(!cc_invalid_for_dcd); + `ASSERT(f_exwrite_cycle); + // `ASSERT(i_mem_wreg[3:0] == 4'hf); + `ASSERT(fc_alu_M); + `ASSERT(!pending_sreg_write); + `ASSERT(!alu_wR); + end else if (i_mem_rdbusy) + begin + `ASSERT(fc_alu_wR); + `ASSERT(!f_exwrite_cycle); + `ASSERT(f_read_cycle); + end + // }}} //////////////////////////////////////////////////////////////////////// // @@ -4656,8 +4699,6 @@ module zipcore #( // // - initial assert((!OPT_LOCK)||(OPT_PIPELINED)); - always @(posedge i_clk) if ((f_past_valid)&&($past(i_reset))&&($past(gie) != gie)) `ASSERT(clear_pipeline); @@ -4728,7 +4769,7 @@ module zipcore #( `ASSERT(!alu_illegal); always @(*) - if (!fc_alu_wR) + if (!fc_alu_wR && (!OPT_LOCK || !f_mem_pc)) `ASSERT(!i_mem_rdbusy); always @(*) @@ -4738,7 +4779,8 @@ module zipcore #( always @(posedge i_clk) if (wr_reg_ce && !$past(i_dbg_we)) begin - `ASSERT(fc_alu_wR); + if (!fc_alu_wR) + `ASSERT(OPT_LOCK && f_exwrite_cycle); // Since writes are asynchronous, they can create errors later `ASSERT((!i_bus_err)||(!i_mem_valid)); @@ -4797,7 +4839,7 @@ module zipcore #( always @(posedge i_clk) if (!i_reset && r_halted) - assert(!i_mem_busy); + assert(!i_mem_rdbusy); // }}} //////////////////////////////////////////////////////////////////////// // @@ -4948,7 +4990,8 @@ module zipcore #( always @(posedge i_clk) if ((OPT_PIPELINED)&&(i_mem_valid || i_mem_rdbusy) &&(f_last_reg[3:1] == 3'h7) - &&(f_last_reg[4:0] != { gie, CPU_PC_REG })) + &&(!f_exwrite_cycle + && f_last_reg[4:0] != { gie, CPU_PC_REG })) begin `ASSERT(pending_sreg_write); end else if ((OPT_PIPELINED)&&(OPT_DCACHE) @@ -4956,6 +4999,7 @@ module zipcore #( &&($past(i_mem_rdbusy)) &&($past(i_mem_rdbusy,2))) `ASSERT((i_mem_wreg[3:1] != 3'h7) + ||f_exwrite_cycle ||(i_mem_wreg == { gie, CPU_PC_REG}) ||(pending_sreg_write)); @@ -5010,31 +5054,165 @@ module zipcore #( //////////////////////////////////////////////////////////////////////// // always @(posedge i_clk) - if ((gie)&&(wr_reg_ce)) begin - // Cover the switch to interrupt - cover((i_interrupt)&&(!alu_phase)&&(!o_bus_lock)); + cover(!i_reset); + cover(!i_halt); // !!! + cover(!i_reset && !i_halt); + end + + always @(posedge i_clk) + if (!i_halt && !i_reset) + begin + cover(i_pf_valid && i_pf_illegal); + cover(i_pf_valid && !i_pf_illegal); + + cover(dcd_valid && dcd_illegal); + cover(dcd_valid && !dcd_illegal); + + cover(op_valid && !op_illegal); + cover(op_valid && op_illegal); + cover(op_valid && !op_illegal && op_ce); + cover(op_valid && op_illegal && op_ce); + + cover(alu_valid); + cover(div_valid); + cover(o_mem_ce); + cover(i_mem_valid); + + cover(wr_reg_ce); + + cover(gie); + end + + always @(posedge i_clk) + if (!i_halt && !i_reset && !$past(i_reset)) + begin + cover(i_interrupt && !alu_phase && !o_bus_lock); + cover(alu_illegal); + cover( gie && w_switch_to_interrupt); + cover(!gie && w_release_from_interrupt); + + // Cover an illegal instruction + cover(alu_illegal); + cover(alu_illegal && !clear_pipeline); - // Cover a "step" instruction - cover(((alu_pc_valid)||(mem_pc_valid)) - &&(step)&&(!alu_phase)&&(!o_bus_lock)); // Cover a break instruction cover((master_ce)&&(break_pending)&&(!break_en)); + cover(o_break); +// if (master_ce && (break_en || break_pending)) +// `ASSERT(!wr_reg_ce); - // Cover an illegal instruction - cover((alu_illegal)&&(!clear_pipeline)); + + cover(gie); + cover(gie && step); + cover(gie && step && w_switch_to_interrupt); + cover(gie && step && w_switch_to_interrupt && !i_interrupt); + end + + always @(posedge i_clk) + if (!i_halt && !i_reset && !$past(i_reset)) + begin + cover(step); + cover(step && wr_reg_ce); + cover($fell(step) && $stable(!i_reset && !i_halt)); + cover($past(step && !i_reset && !i_halt)); + cover($past(step && !i_reset && !i_halt,2)); + cover(!o_bus_lock && alu_ce && step); + cover(step && !gie); + cover(step && !gie && wr_reg_ce); // Cover a division by zero - cover(div_error); + cover(!IMPLEMENT_DIVIDE || div_busy); + cover(!IMPLEMENT_DIVIDE || div_error); + cover(!IMPLEMENT_DIVIDE || div_valid); + end + + generate if (OPT_LOCK) + begin : F_CVR_LOCK + + always @(posedge i_clk) + if (f_past_valid && !i_reset + && !$past(i_reset || clear_pipeline)) + begin + cover($rose(o_bus_lock)); + cover($fell(o_bus_lock)); // !!!! + cover($fell(o_bus_lock) + && !$past(i_bus_err || div_error || alu_illegal)); + end + + end else begin + + always @(*) + `ASSERT(!o_bus_lock); + + end endgenerate + + always @(posedge i_clk) + if (!i_halt && !i_reset && !$past(i_reset) && wr_reg_ce) + begin + `ASSERT(!alu_illegal); + end + + always @(posedge i_clk) + if (!i_halt && !i_reset && wr_reg_ce) + begin + cover(o_bus_lock); + + // Cover the switch to interrupt + cover(i_interrupt); + cover(i_interrupt && !alu_phase); + cover(i_interrupt && !o_bus_lock); // !!! + cover((i_interrupt)&&(!alu_phase)&&(!o_bus_lock)); // !!! + + // Cover a "step" instruction + // + cover(((alu_pc_valid)||(mem_pc_valid)) + &&(step)&&(!alu_phase)&&(!o_bus_lock)); // !!! + // `ASSERT(!(((alu_pc_valid)||(mem_pc_valid)) + // &&(step)&&(!alu_phase)&&(!o_bus_lock))); // Cover a bus error cover(i_bus_err); // Cover a TRAP instruction to the CC register - cover(((wr_reg_ce)&&(!wr_spreg_vl[CPU_GIE_BIT]) - &&(wr_reg_id[4])&&(wr_write_cc))); + cover(!alu_gie && !wr_spreg_vl[CPU_GIE_BIT] + &&(wr_reg_id[4])&&(wr_write_cc)); + + // Cover an AXI lock return branch + cover(i_mem_valid && f_exwrite_cycle && !f_read_cycle); + end + + // Cover all the various reasons to switch to an interrupt + // {{{ + always @(posedge i_clk) + if ((f_past_valid && !i_reset && !$past(i_reset) && !i_halt) && gie) + begin + cover((pending_interrupt) + &&(!alu_phase)&&(!o_bus_lock)&&(!i_mem_busy)); + + cover(div_error); + // cover(fpu_error); + cover(i_bus_err); + cover(wr_reg_ce && !wr_spreg_vl[CPU_GIE_BIT] + && wr_reg_id[4] && wr_write_cc); + + if (!clear_pipeline && !w_switch_to_interrupt) + begin + cover(pending_interrupt); + + cover(i_interrupt); + + cover(mem_ce && step); + cover(break_pending && !adf_ce_unconditional); + cover(adf_ce_unconditional && op_illegal); + cover(adf_ce_unconditional && step); + end + + `ASSERT(!adf_ce_unconditional || !break_pending); end + // }}} + // }}} //////////////////////////////////////////////////////////////////////// // @@ -5047,7 +5225,7 @@ module zipcore #( // Once asserted, an interrupt will stay asserted while the CPU is // in user mode always @(posedge i_clk) - if ((f_past_valid)&&($past(i_interrupt && gie))) + if ((f_past_valid)&&($past(i_interrupt && (gie || !i_mem_busy)))) assume(i_interrupt); // }}} `endif // FORMAL diff --git a/rtl/cpu/zipjiffies.v b/rtl/cpu/zipjiffies.v index 99e0f4e..ac39a31 100644 --- a/rtl/cpu/zipjiffies.v +++ b/rtl/cpu/zipjiffies.v @@ -68,7 +68,6 @@ // //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none // }}} module zipjiffies #( @@ -221,117 +220,7 @@ module zipjiffies #( //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// `ifdef FORMAL - reg f_past_valid; - initial f_past_valid = 1'b0; - always @(posedge i_clk) - f_past_valid <= 1'b1; - - //////////////////////////////////////////////////////////////////////// - // - // Assumptions about our inputs - // {{{ - //////////////////////////////////////////////////////////////////////// - // - // - // One basic WB assumtion - - // Anytime the stb is high, the cycle line must also be high - always @(posedge i_clk) - assume((!i_wb_stb)||(i_wb_cyc)); - // }}} - //////////////////////////////////////////////////////////////////////// - // - // Assertions about our bus outputs - // {{{ - //////////////////////////////////////////////////////////////////////// - // - // - - // We never stall the bus - always @(*) - assert(!o_wb_stall); - - // We always ack every transaction on the following clock - always @(posedge i_clk) - if ((f_past_valid)&&(!$past(i_reset))&&($past(i_wb_stb))) - begin - assert(o_wb_ack); - end else - assert(!o_wb_ack); - // }}} - /////////////////////////////////////////////////////////////////////// - // - // Assumptions about our internal state and our outputs - // {{{ - //////////////////////////////////////////////////////////////////////// - // - // - always @(posedge i_clk) - if ((f_past_valid)&&($past(i_reset))) - begin - assert(!o_wb_ack); - end - - always @(posedge i_clk) - if ((f_past_valid)&&(!$past(i_reset))&&($past(i_wb_stb)) - &&($past(i_wb_we))) - assert(new_when == $past(i_wb_data)); - - always @(posedge i_clk) - if ((f_past_valid)&&(!$past(i_reset))&&($past(i_wb_stb)) - &&($past(i_wb_we))) - begin - assert(new_set); - end else - assert(!new_set); - - // - // - // - - always @(posedge i_clk) - if ((f_past_valid)&&($past(i_reset))) - assert(!o_int); - - always @(posedge i_clk) - if ((f_past_valid)&&($past(i_reset))) - begin - assert(!int_set); - assert(!new_set); - end - - always @(posedge i_clk) - if ((f_past_valid)&&(!$past(i_reset))&&($past(new_set)) - &&(!$past(till_wb[BW-1])) - &&($past(till_wb) > 0)) - assert(int_set); - - always @(posedge i_clk) - if ((f_past_valid)&&(!$past(i_reset))&&($past(i_ce)) - &&($past(r_counter)==$past(int_when))) - begin - assert((o_int)||(!$past(int_set))); - // assert((!int_set)||($past(new_set))); // !!!!! - end - - always @(posedge i_clk) - if ((f_past_valid)&&(!$past(i_reset))&&(!$past(new_set))&&(!$past(int_set))) - assert(!int_set); - - always @(posedge i_clk) - if ((!f_past_valid)||($past(i_reset))) - begin - assert(!o_int); - end else if (($past(new_set))&&($past(till_wb) < 0)) - assert(o_int); - - always @(posedge i_clk) - if ((f_past_valid)&& - ((!$past(new_set)) - ||($past(till_wb[BW-1])) - ||($past(till_wb == 0)))) - assert(int_when == $past(int_when)); - // }}} +// Formal properties are maintained elsewhere `endif // }}} endmodule diff --git a/rtl/cpu/zipsystem.v b/rtl/cpu/zipsystem.v index 729d31a..e78fb41 100644 --- a/rtl/cpu/zipsystem.v +++ b/rtl/cpu/zipsystem.v @@ -86,7 +86,6 @@ // //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none // }}} `include "cpudefs.v" @@ -598,7 +597,6 @@ module zipsystem #( else cmd_reset <= ((dbg_cmd_write)&&(dbg_idata[RESET_BIT])); // }}} - // }}} // cmd_halt // {{{ @@ -714,6 +712,8 @@ module zipsystem #( assign cpu_gie = cpu_dbg_cc[1]; + // cmd_write + // {{{ initial cmd_write = 0; always @(posedge i_clk) if (i_reset || cpu_reset) @@ -721,7 +721,10 @@ module zipsystem #( else if (!cmd_write || !cpu_dbg_stall) cmd_write <= dbg_stb && dbg_we && (|i_dbg_sel) && (dbg_addr[6:5] == DBG_ADDR_CPU); + // }}} + // cmd_waddr, cmd_wdata + // {{{ always @(posedge i_clk) if ((!cmd_write || !cpu_dbg_stall)&&(dbg_stb && dbg_we && !dbg_addr[5])) begin @@ -729,6 +732,7 @@ module zipsystem #( cmd_wdata <= dbg_idata; end // }}} + // }}} //////////////////////////////////////////////////////////////////////// // // The WATCHDOG Timer @@ -1592,4 +1596,17 @@ module zipsystem #( pf_return_cachable, cpu_miss }; // verilator lint_on UNUSED // }}} +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// Formal properties +// {{{ +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +`ifdef FORMAL +// Formal properties are maintained elsewhere +`endif +// }}} endmodule diff --git a/rtl/cpu/ziptimer.v b/rtl/cpu/ziptimer.v index 140103e..4f64b16 100644 --- a/rtl/cpu/ziptimer.v +++ b/rtl/cpu/ziptimer.v @@ -68,7 +68,6 @@ // //////////////////////////////////////////////////////////////////////////////// // -// `default_nettype none // }}} module ziptimer #( diff --git a/rtl/cpu/zipwb.v b/rtl/cpu/zipwb.v index 2836737..bcc048a 100644 --- a/rtl/cpu/zipwb.v +++ b/rtl/cpu/zipwb.v @@ -413,7 +413,8 @@ module zipwb #( ) mem(i_clk, i_reset, clear_dcache, /// {{{ // CPU interface - mem_ce, bus_lock, mem_op, mem_cpu_addr, mem_wdata, mem_reg, + mem_ce, bus_lock && OPT_PIPELINED, + mem_op, mem_cpu_addr, mem_wdata, mem_reg, mem_busy, mem_rdbusy, mem_pipe_stalled, mem_valid, mem_bus_err, mem_wreg, mem_result, // Wishbone interface @@ -439,7 +440,8 @@ module zipwb #( ) domem(i_clk, i_reset, /// {{{ // CPU interface - mem_ce, bus_lock, mem_op, mem_cpu_addr, mem_wdata, mem_reg, + mem_ce, bus_lock && OPT_PIPELINED, + mem_op, mem_cpu_addr, mem_wdata, mem_reg, mem_busy, mem_rdbusy, mem_pipe_stalled, mem_valid, mem_bus_err, mem_wreg, mem_result, // Wishbone interface @@ -463,7 +465,8 @@ module zipwb #( ) domem(i_clk, i_reset, /// {{{ // CPU interface - mem_ce, bus_lock, mem_op, mem_cpu_addr, mem_wdata, mem_reg, + mem_ce, bus_lock && OPT_PIPELINED, + mem_op, mem_cpu_addr, mem_wdata, mem_reg, mem_busy, mem_rdbusy, mem_valid, mem_bus_err, mem_wreg, mem_result, // Wishbone interface diff --git a/rtl/wbubus/wbufifo.v b/rtl/wbubus/wbufifo.v index 74101dd..a1b8125 100644 --- a/rtl/wbubus/wbufifo.v +++ b/rtl/wbubus/wbufifo.v @@ -164,7 +164,6 @@ module wbufifo #( else if (!o_empty_n || i_rd) o_empty_n <= r_empty_n; // }}} - //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// diff --git a/sw/board/cputest.c b/sw/board/cputest.c index ed22ae1..ec79fce 100644 --- a/sw/board/cputest.c +++ b/sw/board/cputest.c @@ -1445,17 +1445,21 @@ void entry(void) { test_fails(start_time, &testlist[tnum]); txstr("Pass\r\n"); testlist[tnum++] = 0; // #21 - // MPY_TEST - testid("Multiply test"); MARKSTART; - if ((run_test(mpy_test, user_stack_ptr))||(zip_ucc()&CC_EXCEPTION)) - test_fails(start_time, &testlist[tnum]); - txstr("Pass\r\n"); testlist[tnum++] = 0; // #22 - - // MPYxHI_TEST - testid("Multiply HI-word test"); MARKSTART; - if ((run_test(mpyhi_test, user_stack_ptr))||(zip_ucc()&CC_EXCEPTION)) - test_fails(start_time, &testlist[tnum]); - txstr("Pass\r\n"); testlist[tnum++] = 0; // #23 + if ((zip_cc() & 0x40000000)==0) { + txstr("No multiply unit installed\r\n"); + } else { + // MPY_TEST + testid("Multiply test"); MARKSTART; + if ((run_test(mpy_test, user_stack_ptr))||(zip_ucc()&CC_EXCEPTION)) + test_fails(start_time, &testlist[tnum]); + txstr("Pass\r\n"); testlist[tnum++] = 0; // #22 + + // MPYxHI_TEST + testid("Multiply HI-word test"); MARKSTART; + if ((run_test(mpyhi_test, user_stack_ptr))||(zip_ucc()&CC_EXCEPTION)) + test_fails(start_time, &testlist[tnum]); + txstr("Pass\r\n"); testlist[tnum++] = 0; // #23 + } // DIV_TEST testid("Divide test"); diff --git a/sw/host/zipelf.h b/sw/host/zipelf.h index 0f156dd..9f08497 100644 --- a/sw/host/zipelf.h +++ b/sw/host/zipelf.h @@ -4,7 +4,9 @@ // {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // -// Purpose: +// Purpose: The ZIPELF class is designed to simplify the representation +// of the fields in an ELF file, for the purpose of loading a +// computer from the sections within it. // // // Creator: Dan Gisselquist, Ph.D. diff --git a/sw/zlib/syscalls.c b/sw/zlib/syscalls.c index 1e726b1..a16cd76 100644 --- a/sw/zlib/syscalls.c +++ b/sw/zlib/syscalls.c @@ -51,30 +51,26 @@ #define UARTTX _uart->u_tx #endif +#ifdef _ZIP_HAS_WBUART +#define TXBUSY ((_uart->u_fifo & 0x010000)==0) +#elif defined(_ZIP_HAS_UARTTX) +#define TXBUSY ((UARTTX & 0x0100)!=0) +#endif + void _outbyte(char v) { -#ifdef _ZIP_HAS_WBUART if (v == '\n') { // Depend upon the WBUART, not the PIC - while((_uart->u_fifo & 0x010000)==0) + while(TXBUSY) ; UARTTX = (unsigned)'\r'; } // Depend upon the WBUART, not the PIC - while((_uart->u_fifo & 0x010000)==0) + while(TXBUSY) ; uint8_t c = v; UARTTX = (unsigned)c; -#else -#ifdef _ZIP_HAS_UARTTX - // Depend upon the WBUART, not the PIC - while(UARTTX & 0x100) - ; - uint8_t c = v; - UARTTX = (unsigned)c; -#endif -#endif } int diff --git a/sw/zlib/zipcpu.h b/sw/zlib/zipcpu.h index 0db4abd..b3a1c14 100644 --- a/sw/zlib/zipcpu.h +++ b/sw/zlib/zipcpu.h @@ -1,6 +1,6 @@ //////////////////////////////////////////////////////////////////////////////// // -// Filename: zipsys.h +// Filename: zipcpu.h // {{{ // Project: ZBasic, a generic toplevel impl using the full ZipCPU // From 7e31c6fe8c56908afe3cd8ca56d2071f16338b5d Mon Sep 17 00:00:00 2001 From: ZipCPU Date: Mon, 4 Oct 2021 13:32:16 -0400 Subject: [PATCH 05/11] STEP/LOCK verification: hellostep and lockcheck s/w programs added --- rtl/builddate.v | 4 +- rtl/cpu/zipcore.v | 30 ++---------- sw/board/.gitignore | 4 ++ sw/board/Makefile | 8 +++- sw/board/hellostep.c | 67 ++++++++++++++++++++++++++ sw/board/lockcheck.c | 109 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 194 insertions(+), 28 deletions(-) create mode 100644 sw/board/hellostep.c create mode 100644 sw/board/lockcheck.c diff --git a/rtl/builddate.v b/rtl/builddate.v index 0a99a88..197c804 100644 --- a/rtl/builddate.v +++ b/rtl/builddate.v @@ -39,7 +39,7 @@ // // }}} `ifndef DATESTAMP -`define DATESTAMP 32'h20210930 -`define BUILDTIME 32'h00223316 +`define DATESTAMP 32'h20211004 +`define BUILDTIME 32'h00100532 `endif // diff --git a/rtl/cpu/zipcore.v b/rtl/cpu/zipcore.v index 04a13e8..a9f03ad 100644 --- a/rtl/cpu/zipcore.v +++ b/rtl/cpu/zipcore.v @@ -1717,11 +1717,9 @@ module zipcore #( // Bus lock logic // {{{ - generate - if (OPT_LOCK) + generate if (OPT_LOCK) begin : BUSLOCK reg r_prelock_stall; - reg r_prelock_primed; reg [1:0] r_bus_lock; reg [AW+1:0] r_lock_pc; @@ -1737,25 +1735,11 @@ module zipcore #( r_prelock_stall <= 1'b0; // }}} - // r_prelock_primed - // {{{ - initial r_prelock_primed = 1'b0; - always @(posedge i_clk) - if (!OPT_PIPELINED) - r_prelock_primed <= 1'b1; - else if (clear_pipeline) - r_prelock_primed <= 1'b0; - else if (r_prelock_stall) - r_prelock_primed <= 1'b1; - else if ((adf_ce_unconditional)||(mem_ce)) - r_prelock_primed <= 1'b0; - // }}} - // r_lock_pc // {{{ always @(posedge i_clk) if (op_valid && op_ce && op_lock) - r_lock_pc <= op_pc; + r_lock_pc <= op_pc-4; // }}} // r_bus_lock @@ -1771,12 +1755,8 @@ module zipcore #( begin if (r_bus_lock != 2'b00) r_bus_lock <= r_bus_lock - 1; - else if (!OPT_PIPELINED) - begin - if ((op_valid)&&(op_lock)&&(op_ce)) - r_bus_lock <= 2'b10; - end else if (r_prelock_primed) - r_bus_lock <= 2'b10; + else if ((op_valid)&&(op_lock)&&(op_ce)) + r_bus_lock <= 2'b11; end // }}} @@ -2356,7 +2336,7 @@ module zipcore #( if (adf_ce_unconditional && op_illegal) r_pending_interrupt <= 1'b1; - if ((adf_ce_unconditional || mem_ce) && step) + if ((adf_ce_unconditional || mem_ce) && step && !op_lock && !o_bus_lock) r_pending_interrupt <= 1'b1; end diff --git a/sw/board/.gitignore b/sw/board/.gitignore index 1cfe38f..bf25344 100644 --- a/sw/board/.gitignore +++ b/sw/board/.gitignore @@ -6,6 +6,10 @@ contest contest.txt hello hello.txt +hellostep +hellostep.txt +lockcheck +lockcheck.txt sdtest sdtest.txt gpiotoggle diff --git a/sw/board/Makefile b/sw/board/Makefile index 0334433..658262a 100644 --- a/sw/board/Makefile +++ b/sw/board/Makefile @@ -36,7 +36,7 @@ ## ## }}} .PHONY: all -PROGRAMS := hello sdtest cputest gpiotoggle contest +PROGRAMS := hello sdtest cputest gpiotoggle contest hellostep lockcheck all: $(PROGRAMS) # # @@ -128,6 +128,12 @@ sdtest: $(OBJDIR)/sdtest.o board.ld $(LIB) gpiotoggle: $(OBJDIR)/gpiotoggle.o bkram.ld $(LIB) $(CC) $(CFLAGS) $(LFLAGS) $< $(LIBS) -o $@ +hellostep: $(OBJDIR)/hellostep.o bkram.ld $(OBJDIR)/txfns.o $(LIB) + $(CC) $(CFLAGS) $(LFLAGS) $< $(OBJDIR)/txfns.o $(LIBS) -o $@ + +lockcheck: $(OBJDIR)/lockcheck.o $(OBJDIR)/txfns.o bkram.ld $(LIB) + $(CC) $(CFLAGS) $(LFLAGS) $< $(OBJDIR)/txfns.o $(LIBS) -o $@ + .PHONY: iftttt ifeq (,$(wildcard tttt/)) iftttt: diff --git a/sw/board/hellostep.c b/sw/board/hellostep.c new file mode 100644 index 0000000..37fdd75 --- /dev/null +++ b/sw/board/hellostep.c @@ -0,0 +1,67 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Filename: hellostep.c +// {{{ +// Project: ZBasic, a generic toplevel impl using the full ZipCPU +// +// Purpose: The original Helllo World program. If everything works, this +// will print Hello World to the UART, and then halt the CPU--if +// run with no O/S. +// +// +//////////////////////////////////////////////////////////////////////////////// +// +// Gisselquist Technology asserts no ownership rights over this particular +// hello world program. +// +//////////////////////////////////////////////////////////////////////////////// +// +// }}} +#include +#include "zipcpu.h" +#include "txfns.h" + +void user_main(void) { + printf("Hello, World!\n"); + zip_syscall(); +} + +int main(int argc, char **argv) { + int done = 0, success = 1; + unsigned user_regs[16]; + unsigned user_stack[512]; + + for(unsigned k=0; k<16; k++) + user_regs[k] = 0; + user_regs[15] = (unsigned)user_main; + user_regs[14] = CC_STEP; + user_regs[13] = (unsigned)&user_stack[512]; + zip_restore_context(user_regs); + + while(!done) { + unsigned ucc; + + zip_rtu(); + + ucc = zip_ucc(); + if (ucc & CC_EXCEPTION) { + txstr("\r\nEXCEPTION: CC = ");txhex(ucc); txstr("\r\n"); + txstr("\r\n"); + while((_uart->u_fifo & 0x010000) == 0) + ; + done = 1; + success = 0; + } if (ucc & CC_TRAP) + done = 1; + else if ((ucc & CC_STEP) == 0) { + success = 0; + txstr("\r\nCC & STEP == 0 ?? CC = "); txhex(ucc); + txstr("\r\n"); + while((_uart->u_fifo & 0x010000) == 0) + ; + } + } + + if (success) + txstr("\r\n\r\nSUCCESS!\r\n"); +} diff --git a/sw/board/lockcheck.c b/sw/board/lockcheck.c new file mode 100644 index 0000000..e2fba8d --- /dev/null +++ b/sw/board/lockcheck.c @@ -0,0 +1,109 @@ +#include +#include +#include "txfns.h" +#include "zipcpu.h" +#include "board.h" + +const unsigned NUM_TASKS = 4; + +typedef struct TASKT_S { + unsigned volatile *regs; + unsigned *stackp; +} TASKT; + +volatile char atomic; +volatile unsigned shared_resource; + +void user_task(int task_id, int *loops) { + unsigned task_fail = 0; + *loops = 0; + while(*loops < 1024) { + if (!__atomic_test_and_set(&atomic, __ATOMIC_RELAXED)) { + shared_resource = task_id; + for(int k=0; k<5; k++) { + // if (shared_resource != task_id) LED = RED; + if (shared_resource != task_id) + task_fail = 1; + if (atomic != 1) + task_fail = 1; + } + + *loops = *loops + 1; + atomic = 0; + } + } + + while (__atomic_test_and_set(&atomic, __ATOMIC_RELAXED)) {} + + printf("Task #%d: COMPLETE\n", task_id); + atomic = 0; + + if (task_fail) + *loops = -1; + zip_syscall(); + (*_gpio) = GPIO_SET(2); + while(1) + txchr('!'); +} + +// And a main task that steps each task +int main(int argc,char **argv) { + TASKT TASK[NUM_TASKS]; + unsigned task_loops[NUM_TASKS]; + unsigned success = 1; + + atomic = 0; + shared_resource = 0; + + // Step up tasks + for(int taskn=0; taskn < NUM_TASKS; taskn++) { + TASK[taskn].regs = malloc(sizeof(int)*16); + TASK[taskn].stackp= malloc(sizeof(int)*512) + + sizeof(int)*512; + for(int r=0; r<13; r++) + TASK[taskn].regs[r] = 0; + TASK[taskn].regs[15] = (unsigned)user_task; + TASK[taskn].regs[14] = CC_STEP; + TASK[taskn].regs[13] = (unsigned)TASK[taskn].stackp; + TASK[taskn].regs[ 1] = taskn; // The task ID + TASK[taskn].regs[ 2] = (unsigned)&task_loops[taskn]; + } + + (*_gpio) = GPIO_SET(1); + + // Then run them + while(1) { + int completed; + + completed = 0; + for(int taskn=0; taskn < NUM_TASKS; taskn++) { + if (TASK[taskn].regs[14] & (CC_TRAP | CC_EXCEPTION)) { + completed++; + } else { + zip_restore_context((void *)TASK[taskn].regs); + // zip_ucc() |= STEP;//What's the syntax here?!? + zip_rtu(); + zip_save_context((void *)TASK[taskn].regs); + if (zip_ucc() & (CC_EXCEPTION)) + success = 0; + } + } + + if (completed >= NUM_TASKS) + break; + } + + if (success) { + for(int taskn=0; taskn < NUM_TASKS; taskn++) { + printf(" LOOPS[%2d] = 0x%08x\n", taskn, task_loops[taskn]); + if (task_loops[taskn] == 0xffffffff) + success = 0; + } + + if (success) + printf("SUCCESS!\n"); + else + printf("TASK FAILURE\n"); + } else + printf("TEST FAILURE!\n"); +} From 02370bda3d9d97c1ea32274c4d84d3dea8edb861 Mon Sep 17 00:00:00 2001 From: ZipCPU Date: Mon, 4 Oct 2021 13:32:53 -0400 Subject: [PATCH 06/11] ZIPSTATE: Adjusted to better match the new status word in ZipCore --- sw/host/zipstate.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/sw/host/zipstate.cpp b/sw/host/zipstate.cpp index 392a2d3..39323ec 100644 --- a/sw/host/zipstate.cpp +++ b/sw/host/zipstate.cpp @@ -101,17 +101,25 @@ int main(int argc, char **argv) { if (v & 0x0040) printf("RESET "); if (v & 0x0080) printf("PINT "); // if (v & 0x0100) printf("STEP "); // self resetting - if((v & 0x00200)==0) printf("HALTED "); - if (v & 0x00400) printf("HALT_REQ "); + // if (v & 0x00200) printf("DBG-STALL "); + if (v & 0x00400) { + if (v & 0x0200) + printf("DBG-HALTED "); + else + printf("HALT_REQ "); + } // if (v & 0x0800) printf("CLR-CACHE "); if((v & 0x03000)==0x01000) { - printf("SW-HALT"); + printf("SW-HALTED"); } else { if (v & 0x01000) printf("SLEEPING "); if (v & 0x02000) printf("GIE(UsrMode) "); } if (v & 0x04000) printf("sBusErr "); if (v & 0x08000) printf("BREAK-HALT"); + + if ((v & 0x0fc00) == 0) + printf("Running"); printf("\n"); } else { unsigned r[32]; From 92641352539f57b253714ae8528eccb991379467 Mon Sep 17 00:00:00 2001 From: ZipCPU Date: Mon, 4 Oct 2021 13:33:10 -0400 Subject: [PATCH 07/11] ZIPDBG: Initial break support capability --- sw/host/zipdbg.cpp | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/sw/host/zipdbg.cpp b/sw/host/zipdbg.cpp index c9feaea..eba36c6 100644 --- a/sw/host/zipdbg.cpp +++ b/sw/host/zipdbg.cpp @@ -101,10 +101,12 @@ class ZIPPY : public DEVBUS { DEVBUS *m_fpga; int m_cursor; ZIPSTATE m_state; - bool m_user_break, m_show_users_timers, m_show_cc; + bool m_show_users_timers, m_show_cc, m_stopped_at_break; public: - ZIPPY(DEVBUS *fpga) : m_fpga(fpga), m_cursor(0), m_user_break(false), - m_show_users_timers(false), m_show_cc(false) {} + ZIPPY(DEVBUS *fpga) : m_fpga(fpga), m_cursor(0), + m_show_users_timers(false), + m_show_cc(false), + m_stopped_at_break(false) {} void read_raw_state(void) { // {{{ @@ -130,8 +132,11 @@ class ZIPPY : public DEVBUS { try { m_state.m_imem[0].m_d = readio(m_state.m_imem[0].m_a); m_state.m_imem[0].m_valid = true; + + m_stopped_at_break = ((m_state.m_imem[0].m_d & 0xf7ffffff) == 0x77000000); } catch(BUSERR be) { m_state.m_imem[0].m_valid = false; + m_stopped_at_break = false; } m_state.m_imem[1].m_a = m_state.m_pc; try { @@ -215,7 +220,25 @@ class ZIPPY : public DEVBUS { void clear(void) { m_fpga->clear(); } void reset(void) { writeio(R_ZIPCTRL, CPU_RESET|CPU_HALT); } - void step(void) { writeio(R_ZIPCTRL, CPU_STEP); m_state.step(); } + void step(void) { + // {{{ + if (m_stopped_at_break) { + unsigned break_insn, insn_addr; + const unsigned noop_insn = 0x77c00000; + + insn_addr = m_state.m_imem[0].m_a; + break_insn = m_state.m_imem[0].m_d; + + writeio(insn_addr, noop_insn); + writeio(R_ZIPCTRL, CPU_CLRCACHE); + writeio(R_ZIPCTRL, CPU_STEP); m_state.step(); + writeio(insn_addr, break_insn); + writeio(R_ZIPCTRL, CPU_CLRCACHE); + } else { + writeio(R_ZIPCTRL, CPU_STEP); m_state.step(); + } + // }}} + } void go(void) { writeio(R_ZIPCTRL, CPU_GO); } void halt(void) { writeio(R_ZIPCTRL, CPU_HALT); } bool stalled(void) { return ((readio(R_ZIPCTRL)&CPU_STALL)==0); } From 25b9568f44d50cfaeb3522eb33e33f4d554aaac4 Mon Sep 17 00:00:00 2001 From: ZipCPU Date: Fri, 12 Nov 2021 19:44:32 -0500 Subject: [PATCH 08/11] Upgraded the ZipCPU to a prior to 3.0 release - Removed cpudefs.v - Moved sim/verilated directory to the sim/ directory - Fixed the non-reset start address bug in sim/automaster_tb.cpp All simulations pass in default configuration --- Makefile | 44 +- auto-data/flash.txt | 1 - auto-data/zipmaster.txt | 8 +- doc/hellostep.png | Bin 0 -> 298667 bytes doc/lockcheck.png | Bin 0 -> 472750 bytes rtl/Makefile | 11 +- rtl/builddate.v | 4 +- rtl/cpu/axidcache.v | 18 +- rtl/cpu/axiicache.v | 4 + rtl/cpu/axilfetch.v | 4 + rtl/cpu/axilperiphs.v | 1 - rtl/cpu/cpudefs.v | 290 ------ rtl/cpu/cpuops.v | 43 +- rtl/cpu/dcache.v | 20 +- rtl/cpu/div.v | 7 +- rtl/cpu/idecode.v | 87 +- rtl/cpu/memops.v | 10 +- rtl/cpu/mpyop.v | 54 +- rtl/cpu/pfcache.v | 2 +- rtl/cpu/pipemem.v | 6 +- rtl/cpu/wbdmac.v | 33 +- rtl/cpu/wbpriarbiter.v | 1 - rtl/cpu/zipaxi.v | 167 ++-- rtl/cpu/zipaxil.v | 133 +-- rtl/cpu/zipbones.v | 169 ++-- rtl/cpu/zipcore.v | 1285 +++++++++++++++---------- rtl/cpu/zipsystem.v | 314 +++--- rtl/cpu/zipwb.v | 198 ++-- rtl/main.v | 11 +- rtl/qflexpress.v | 520 ++++++---- sim/{verilated => }/.gitignore | 0 sim/{verilated => }/Makefile | 6 +- sim/{verilated => }/automaster_tb.cpp | 16 +- sim/{verilated => }/busmaster_tb.cpp | 0 sim/{verilated => }/byteswap.cpp | 0 sim/{verilated => }/byteswap.h | 0 sim/{verilated => }/dblpipecmdr.h | 0 sim/{verilated => }/dbluartsim.cpp | 0 sim/{verilated => }/dbluartsim.h | 0 sim/{verilated => }/flashsim.cpp | 0 sim/{verilated => }/flashsim.h | 0 sim/{verilated => }/main_tb.cpp | 2 - sim/{verilated => }/memsim.cpp | 0 sim/{verilated => }/memsim.h | 0 sim/{verilated => }/pipecmdr.h | 0 sim/{verilated => }/port.h | 0 sim/{verilated => }/sdspisim.cpp | 0 sim/{verilated => }/sdspisim.h | 0 sim/{verilated => }/spansion.hex | 0 sim/{verilated => }/tbclock.h | 0 sim/{verilated => }/testb.h | 0 sim/{verilated => }/twoc.cpp | 0 sim/{verilated => }/twoc.h | 0 sim/{verilated => }/uartsim.cpp | 0 sim/{verilated => }/uartsim.h | 0 sim/{verilated => }/vversion.sh | 0 sim/{verilated => }/zipelf.cpp | 0 sim/{verilated => }/zipelf.h | 0 sw/host/zipdbg.cpp | 5 +- sw/zlib/syscalls.c | 49 + 60 files changed, 1924 insertions(+), 1599 deletions(-) create mode 100644 doc/hellostep.png create mode 100644 doc/lockcheck.png delete mode 100644 rtl/cpu/cpudefs.v rename sim/{verilated => }/.gitignore (100%) rename sim/{verilated => }/Makefile (97%) rename sim/{verilated => }/automaster_tb.cpp (94%) rename sim/{verilated => }/busmaster_tb.cpp (100%) rename sim/{verilated => }/byteswap.cpp (100%) rename sim/{verilated => }/byteswap.h (100%) rename sim/{verilated => }/dblpipecmdr.h (100%) rename sim/{verilated => }/dbluartsim.cpp (100%) rename sim/{verilated => }/dbluartsim.h (100%) rename sim/{verilated => }/flashsim.cpp (100%) rename sim/{verilated => }/flashsim.h (100%) rename sim/{verilated => }/main_tb.cpp (99%) rename sim/{verilated => }/memsim.cpp (100%) rename sim/{verilated => }/memsim.h (100%) rename sim/{verilated => }/pipecmdr.h (100%) rename sim/{verilated => }/port.h (100%) rename sim/{verilated => }/sdspisim.cpp (100%) rename sim/{verilated => }/sdspisim.h (100%) rename sim/{verilated => }/spansion.hex (100%) rename sim/{verilated => }/tbclock.h (100%) rename sim/{verilated => }/testb.h (100%) rename sim/{verilated => }/twoc.cpp (100%) rename sim/{verilated => }/twoc.h (100%) rename sim/{verilated => }/uartsim.cpp (100%) rename sim/{verilated => }/uartsim.h (100%) rename sim/{verilated => }/vversion.sh (100%) rename sim/{verilated => }/zipelf.cpp (100%) rename sim/{verilated => }/zipelf.h (100%) diff --git a/Makefile b/Makefile index d0d9b42..2b8e0ca 100644 --- a/Makefile +++ b/Makefile @@ -39,6 +39,8 @@ ## }}} .PHONY: all all: check-install archive datestamp rtl sim sw +AUTOD := auto-data +SIMD := sim # # Could also depend upon load, if desired, but not necessary BENCH := # `find bench -name Makefile` `find bench -name "*.cpp"` `find bench -name "*.h"` @@ -117,18 +119,18 @@ archive: # .PHONY: autodata autodata: check-autofpga - $(SUBMAKE) auto-data - $(call copyif-changed,auto-data/toplevel.v,rtl/toplevel.v) - $(call copyif-changed,auto-data/main.v,rtl/main.v) - $(call copyif-changed,auto-data/iscachable.v,rtl/cpu/iscachable.v) - $(call copyif-changed,auto-data/regdefs.h,sw/host/regdefs.h) - $(call copyif-changed,auto-data/regdefs.cpp,sw/host/regdefs.cpp) - $(call copyif-changed,auto-data/board.h,sw/zlib/board.h) - $(call copyif-changed,auto-data/board.ld,sw/board/board.ld) - $(call copyif-changed,auto-data/bkram.ld,sw/board/bkram.ld) - $(call copyif-changed,auto-data/rtl.make.inc,rtl/make.inc) - $(call copyif-changed,auto-data/testb.h,sim/verilated/testb.h) - $(call copyif-changed,auto-data/main_tb.cpp,sim/verilated/main_tb.cpp) + $(SUBMAKE) $(AUTOD) + $(call copyif-changed,$(AUTOD)/toplevel.v,rtl/toplevel.v) + $(call copyif-changed,$(AUTOD)/main.v,rtl/main.v) + $(call copyif-changed,$(AUTOD)/iscachable.v,rtl/cpu/iscachable.v) + $(call copyif-changed,$(AUTOD)/regdefs.h,sw/host/regdefs.h) + $(call copyif-changed,$(AUTOD)/regdefs.cpp,sw/host/regdefs.cpp) + $(call copyif-changed,$(AUTOD)/board.h,sw/zlib/board.h) + $(call copyif-changed,$(AUTOD)/board.ld,sw/board/board.ld) + $(call copyif-changed,$(AUTOD)/bkram.ld,sw/board/bkram.ld) + $(call copyif-changed,$(AUTOD)/rtl.make.inc,rtl/make.inc) + $(call copyif-changed,$(AUTOD)/testb.h,$(SIMD)/testb.h) + $(call copyif-changed,$(AUTOD)/main_tb.cpp,$(SIMD)/main_tb.cpp) # # @@ -148,7 +150,7 @@ rtl: verilated # .PHONY: sim sim: rtl check-gpp - +@$(SUBMAKE) sim/verilated + +@$(SUBMAKE) $(SIMD) # # @@ -188,11 +190,11 @@ sw-board: sw-zlib check-zip-gcc # .PHONY: hello hello: sim sw - sim/verilated/main_tb sw/board/hello + sim/main_tb sw/board/hello .PHONY: sdtest sdtest: sim sw - sim/verilated/main_tb sw/board/sdtest + sim/main_tb sw/board/sdtest .PHONY: test test: hello @@ -217,9 +219,9 @@ endef .PHONY: clean clean: - +$(SUBMAKE) auto-data clean - +$(SUBMAKE) sim/verilated clean - +$(SUBMAKE) rtl clean - +$(SUBMAKE) sw/zlib clean - +$(SUBMAKE) sw/board clean - +$(SUBMAKE) sw/host clean + +$(SUBMAKE) auto-data clean + +$(SUBMAKE) sim clean + +$(SUBMAKE) rtl clean + +$(SUBMAKE) sw/zlib clean + +$(SUBMAKE) sw/board clean + +$(SUBMAKE) sw/host clean diff --git a/auto-data/flash.txt b/auto-data/flash.txt index c86aed0..290d3e7 100644 --- a/auto-data/flash.txt +++ b/auto-data/flash.txt @@ -42,7 +42,6 @@ @$NADDR=(1<<(@$LGFLASHSZ-2)) @$NBYTES=(1<<@$LGFLASHSZ) @NBYTES.FORMAT=0x%08x -@ACCESS= FLASH_ACCESS @SLAVE.TYPE=MEMORY @SLAVE.BUS=wb @NDUMMY=6 diff --git a/auto-data/zipmaster.txt b/auto-data/zipmaster.txt index 7b3e7d1..f2b133e 100644 --- a/auto-data/zipmaster.txt +++ b/auto-data/zipmaster.txt @@ -109,8 +109,8 @@ zipsystem #( // {{{ .RESET_ADDRESS(RESET_ADDRESS), - .ADDRESS_WIDTH(ZIP_ADDRESS_WIDTH), - .LGICACHE(@$(LGICACHE)),.LGDCACHE(@$(LGDCACHE)), + .ADDRESS_WIDTH(ZIP_ADDRESS_WIDTH+2), + .OPT_LGICACHE(@$(LGICACHE)), .OPT_LGDCACHE(@$(LGDCACHE)), .START_HALTED(ZIP_START_HALTED), .RESET_DURATION(20), .EXTERNAL_INTERRUPTS(ZIP_INTS) @@ -126,7 +126,9 @@ zip_debug // }}} ); + assign zip_trigger = zip_debug[31]; + // }}} @BDEF.INCLUDE= #include #include @@ -214,9 +216,7 @@ #else #define cpu_alu_pc CPUVAR(_op_pc) #endif -#ifdef OPT_CIS #define cpu_alu_phase CPUVAR(_GEN_ALU_PHASE__DOT__r_alu_phase) -#endif #define cpu_wr_ce CPUVAR(_wr_reg_ce) #define cpu_wr_reg_id CPUVAR(_wr_reg_id) #define cpu_wr_gpreg CPUVAR(_wr_gpreg_vl) diff --git a/doc/hellostep.png b/doc/hellostep.png new file mode 100644 index 0000000000000000000000000000000000000000..a1fd934cd4880e8468629011d3fa176ee2e35ff0 GIT binary patch literal 298667 zcmV)bK&iipP) zaB^>EX>4U6ba`-PAZ2)IW&i+q+O3&uk|ehcg#Xtmd;}6CK=L>wK}PrnKE6NH^p18V z*_I+az0=)O4?ciIW}@~v|N7^B{=rX?CQsGYZI~r~>Zn5|UwZob8Si^e^?iST=1uxJ z`pfZ07O&wKLdSEF!1|RV&?enKQEHw@^w7d z&p_jReX-Ho&r4mOf%fOZcPXFW`n{~LkNErfE{6b667D>p5I5mtnV285`3ATE6VR;X`dMJ_wvzSol9dB;27&YhV(bE#wo%iQuGU(bI#`FCE=y*ombBba5qv0_~kxMmrV zxp?O)5|ZyHZ~6xK$Lo{+^b@dvDjC!_%$*I+w7!N|nt#JqdGlPjPWk*Qq5L%e3_ysO zTUkslWFT2Cnk}a$(sCw_odiu*F4V>%16fs^MM^Ej?0)&0c!#+O4p@CYp>jxqfnF$ttTZUAEflYpl6}&#qgy?Y8?Kd%AdWXu{2#cOO1a zehy4=>d|AToqood7p&cK>(y(w-G0ZN-&y-)^$)MVk+uBEn!K5c>)LnLIQq2qV~8Ad zqLDK)CN-1s78wB05;;pf*D8^@$Qjj5QK+y;jodt*BV(kno-BIvckX`6++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