├── sim ├── verilated │ ├── .gitignore │ ├── spansion.hex │ ├── zipelf.h │ ├── twoc.h │ ├── twoc.cpp │ ├── port.h │ ├── vversion.sh │ ├── memsim.h │ ├── byteswap.h │ ├── sdspisim.h │ ├── byteswap.cpp │ ├── memsim.cpp │ └── Makefile └── sdcard.img ├── rtl ├── .gitignore ├── cpu │ ├── README.md │ ├── iscachable.cpp │ ├── iscachable.v │ ├── zipcounter.v │ └── wbwatchdog.v ├── builddate.v ├── wbubus │ ├── wbuinput.v │ ├── wbutohex.v │ ├── wbusixchar.v │ ├── wbudeword.v │ ├── wbuoutput.v │ ├── wbureadcw.v │ └── wbuidleint.v ├── make.inc ├── Makefile └── wbgpio.v ├── bench └── formal │ └── .gitignore ├── doc ├── gpl-3.0.pdf ├── src │ └── GT.eps └── Makefile ├── sw ├── host │ ├── .gitignore │ ├── nflashid.sh │ ├── zipelf.h │ ├── twoc.h │ ├── twoc.cpp │ ├── port.h │ ├── flashdrvr.h │ ├── llcomms.h │ ├── byteswap.h │ ├── byteswap.cpp │ ├── zopcodes.h │ ├── dumpflash.cpp │ ├── regdefs.cpp │ ├── Makefile │ ├── zipstate.cpp │ └── ttybus.h ├── board │ ├── dhrystone │ │ ├── .gitignore │ │ └── Makefile │ ├── .gitignore │ ├── hello.c │ ├── hellosim.s │ ├── txfns.h │ ├── bkram.ld │ ├── board.ld │ └── txfns.c └── zlib │ ├── bootloader.h │ ├── umod.c │ ├── Makefile │ ├── zipcpu.h │ └── zipsys.h ├── .gitmodules ├── auto-data ├── .gitignore ├── profile.txt ├── legalgen.txt ├── clock.txt ├── pwrcount.txt ├── pic.txt ├── rtcdate.txt ├── simtrace.txt ├── mem_bkram_only.txt ├── version.txt ├── buserr.txt ├── mem_flash_bkram.txt ├── Makefile ├── rtclight.txt ├── bkram.txt ├── gpio.txt └── global.txt ├── .gitignore ├── README.md └── mkdatev.pl /sim/verilated/.gitignore: -------------------------------------------------------------------------------- 1 | sdcard.img 2 | pfile.bin 3 | -------------------------------------------------------------------------------- /rtl/.gitignore: -------------------------------------------------------------------------------- 1 | build.bqm 2 | build.edif 3 | build.edif 4 | -------------------------------------------------------------------------------- /bench/formal/.gitignore: -------------------------------------------------------------------------------- 1 | memdev_extra 2 | memdev_mem 3 | memdev_rom 4 | -------------------------------------------------------------------------------- /sim/sdcard.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZipCPU/zbasic/HEAD/sim/sdcard.img -------------------------------------------------------------------------------- /doc/gpl-3.0.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZipCPU/zbasic/HEAD/doc/gpl-3.0.pdf -------------------------------------------------------------------------------- /sw/host/.gitignore: -------------------------------------------------------------------------------- 1 | netuart 2 | obj-pc 3 | wbregs 4 | zipdbg 5 | zipload 6 | zipstate 7 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "sw/board/tttt"] 2 | path = sw/board/tttt 3 | url = https://github.com/ZipCPU/tttt 4 | -------------------------------------------------------------------------------- /sw/board/dhrystone/.gitignore: -------------------------------------------------------------------------------- 1 | dry2 2 | dry2.txt 3 | notes.txt 4 | pfile.bin 5 | *.map 6 | *.bin 7 | dry.txt 8 | pfile.txt 9 | -------------------------------------------------------------------------------- /sw/board/.gitignore: -------------------------------------------------------------------------------- 1 | contest 2 | contest.txt 3 | cputest 4 | cputest.txt 5 | contest 6 | contest.txt 7 | hello 8 | hello.txt 9 | sdtest 10 | sdtest.txt 11 | gpiotoggle 12 | gpiotoggle.txt 13 | hellosim.txt 14 | -------------------------------------------------------------------------------- /auto-data/.gitignore: -------------------------------------------------------------------------------- 1 | board.h 2 | board.ld 3 | bkram.ld 4 | build.xdc 5 | main.v 6 | regdefs.h 7 | regdefs.cpp 8 | rtl.make.inc 9 | testb.h 10 | toplevel.v 11 | main_tb.cpp 12 | iscachable.v 13 | autofpga.dbg 14 | -------------------------------------------------------------------------------- /sim/verilated/spansion.hex: -------------------------------------------------------------------------------- 1 | 7ff 2 | 7ff 3 | 7ff 4 | 7ff 5 | 7ff 6 | 7ff 7 | 7ff 8 | 7ff 9 | 7ff 10 | 7ff 11 | 7ff 12 | 7ff 13 | 7ff 14 | 7ff 15 | 7ff 16 | 7ff 17 | 7ff 18 | 7ff 19 | 0ff 20 | 0ff 21 | 7ff 22 | 7ff 23 | 0eb 24 | 200 25 | 200 26 | 200 27 | 2a0 28 | 200 29 | 300 30 | 300 31 | 7ff 32 | 7ff 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | legal.txt 2 | .svn 3 | xilinx 4 | obj_dir 5 | obj-pc 6 | obj-zip 7 | *.o 8 | *.a 9 | *.vcd 10 | *.tjz 11 | .swp 12 | .*.swp 13 | .*.swo 14 | svn-commit* 15 | *_tb 16 | *_tb.dbl 17 | *dbg.txt 18 | *dump.txt 19 | *debug.txt 20 | tags 21 | main_tb 22 | hello 23 | hellosim 24 | cpudefs.h 25 | design.h 26 | 20*build.v 27 | builddate.v 28 | octave-workspace 29 | *.xdc 30 | *.dbg 31 | *.map 32 | -------------------------------------------------------------------------------- /rtl/cpu/README.md: -------------------------------------------------------------------------------- 1 | If you are looking for where the [ZipCPU](https://github.com/ZipCPU/zipcpu) 2 | is within this distribution, you've just found it! 3 | 4 | This directory contains the Verilog sources that come from the 5 | [ZipCPU](https://github.com/ZipCPU/zipcpu) repository. The have been pulled 6 | from the [core ZipCPU 7 | directory](https://github.com/ZipCPU/zipcpu/tree/master/rtl/core), the [ZipCPU 8 | peripherals 9 | directory](https://github.com/ZipCPU/zipcpu/tree/master/rtl/peripherals), and 10 | the [auxiliary directory](https://github.com/ZipCPU/zipcpu/tree/master/rtl/aux) 11 | of bus interaction helpers. 12 | -------------------------------------------------------------------------------- /sw/board/hello.c: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: helloworld.c 4 | // 5 | // Project: ZBasic, a generic toplevel impl using the full ZipCPU 6 | // 7 | // Purpose: The original Helllo World program. If everything works, this 8 | // will print Hello World to the UART, and then halt the CPU--if 9 | // run with no O/S. 10 | // 11 | // 12 | //////////////////////////////////////////////////////////////////////////////// 13 | // 14 | // Gisselquist Technology asserts no ownership rights over this particular 15 | // hello world program. 16 | // 17 | //////////////////////////////////////////////////////////////////////////////// 18 | // 19 | // 20 | #include 21 | 22 | int main(int argc, char **argv) { 23 | printf("Hello, World!\n"); 24 | } 25 | -------------------------------------------------------------------------------- /auto-data/profile.txt: -------------------------------------------------------------------------------- 1 | @PREFIX=profiler 2 | @DEPENDS=INCLUDE_ZIPCPU 3 | @ACCESS=PROFILE_ZIPCPU 4 | @SIM.DEFNS= 5 | FILE *m_profile_fp; 6 | unsigned long m_last_instruction_tickcount; 7 | @SIM.INIT= 8 | #ifdef PROFILE_ZIPCPU 9 | m_profile_fp = fopen("pfile.bin","wb"); 10 | m_last_instruction_tickcount = 0; 11 | #else 12 | m_profile_fp = NULL; 13 | #endif 14 | @SIM.CLOCK=clk 15 | @SIM.TICK= 16 | if (m_profile_fp) { 17 | bool retire_instruction; 18 | static unsigned m_profile_clock_ticks = 0; 19 | 20 | m_profile_clock_ticks++; 21 | 22 | retire_instruction = (((m_core->cpu_alu_pc_valid) 23 | ||(m_core->cpu_mem_pc_valid)) 24 | &&(!m_core->cpu_new_pc)); 25 | if (retire_instruction) { 26 | unsigned long iticks = m_profile_clock_ticks 27 | - m_last_instruction_tickcount; 28 | 29 | unsigned buf[2]; 30 | buf[0] = m_core->cpu_alu_pc-4; 31 | #ifdef OPT_CIS 32 | if (m_core->cpu_alu_phase) 33 | buf[0] += 2; 34 | #endif 35 | buf[1] = (unsigned)iticks; 36 | fwrite(buf, sizeof(unsigned), 2, m_profile_fp); 37 | 38 | m_last_instruction_tickcount = m_profile_clock_ticks; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /sw/host/nflashid.sh: -------------------------------------------------------------------------------- 1 | #!bin/bash 2 | 3 | ./wbregs flashcfg 0x0001100 # Activate config mode 4 | ./wbregs flashcfg 0x00010ff # Send 16(*4) bits of ones, break the mode 5 | ./wbregs flashcfg 0x00010ff 6 | ./wbregs flashcfg 0x0001100 # Inactivate the port 7 | 8 | # echo READ-ID 9 | ./wbregs flashcfg 0x000109f # Issue the read ID command 10 | ./wbregs flashcfg 0x0001000 # Read the ID 11 | ./wbregs flashcfg 12 | ./wbregs flashcfg 0x0001000 # 13 | ./wbregs flashcfg 14 | ./wbregs flashcfg 0x0001000 # 15 | ./wbregs flashcfg 16 | ./wbregs flashcfg 0x0001000 # 17 | ./wbregs flashcfg 18 | ./wbregs flashcfg 0x0001100 # End the command 19 | 20 | echo Return to QSPI 21 | ./wbregs flashcfg 0x00010eb # Return us to QSPI mode, via QIO_READ cmd 22 | ./wbregs flashcfg 0x0001a00 # dummy address 23 | ./wbregs flashcfg 0x0001a00 # dummy address 24 | ./wbregs flashcfg 0x0001a00 # dummy address 25 | ./wbregs flashcfg 0x0001aa0 # mode byte 26 | ./wbregs flashcfg 0x0001800 # empty byte, switching directions 27 | ./wbregs flashcfg 0x0001800 # Read a byte of data 28 | ./wbregs flashcfg 0x0001800 # Read a byte of data 29 | ./wbregs flashcfg 0x0001900 # Raise (deactivate) CS_n 30 | ./wbregs flashcfg 0x0000100 # Return to user mode 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ZBasic 2 | 3 | This project provides a very basic version of a working 4 | [ZipCPU](https://github.com/ZipCPU/zbasic) system. It is designed so that 5 | others (you perhaps?) can then build off of it and design with it. 6 | ZBasic has three primary goals: 7 | 8 | - To provide a usable beginning system to allow users to get *something* up and running quickly 9 | 10 | - To provide a very basic system that can then be matched with an emulator, and used to test library and compiler functionality apart from actual hardware. 11 | 12 | - To demonstrate the utility of [autofpga](https://github.com/ZipCPU/autofpga), and its ability to quickly, easily, and seemlessly add components to a design 13 | 14 | If you'd like to give this a spin, consider the instructions 15 | [in this article](http://zipcpu.com/zipcpu/2018/02/12/zbasic-intro.html) 16 | describing how to do so. 17 | 18 | # Status 19 | 20 | The ZBasic system can now be made using [autofpga](https://github.com/ZipCPU/autofpga), all the way from zero to Hello World successfully in Verilator testing. 21 | 22 | # License 23 | 24 | Gisselquist Technology, LLC, is pleased to provide you access to this entire 25 | project under the GPLv3 license. If this license will not work for you, please 26 | contact me. 27 | 28 | -------------------------------------------------------------------------------- /sw/board/dhrystone/Makefile: -------------------------------------------------------------------------------- 1 | all: dry2 2 | CC=zip-gcc 3 | RAW=dry.c 4 | # SCORE = (CLKSPD*NRUNS*TICKS)/1757 5 | # TICKS = 0x5a320 (100 runs), 0xd6d (1 run) 6 | # DMIPS/MHZ = (1e6 * NRUNS / TICKS / 1757) 7 | # 8 | # Runs: 1 0x000e79 (was 5a320) 9 | # Runs: 100 0x05a48f 10 | # Runs: 100 0x03366e ( 4k cache) 11 | # Runs: 100 0x033263 (16k cache) 12 | # Runs: 100 0x033263 (32k cache) 13 | # Runs: 1000 0x1ff79f (32k cache) 14 | # Runs: 1000 0x6d122a (SingleFetch, block RAM) 15 | # Runs: 100 0xb53897 (SingleFetch, insns in flash), 0.0048 DMIPS/MHz 16 | # Runs: 100 0x944c3a (DoubleFetch, insns in flash), 0.0058 DMIPS/MHz 17 | ZBASIC := ../../.. 18 | LDSCRIPT := $(ZBASIC)/sw/board/board.ld 19 | ZBASICLIB := $(ZBASIC)/sw/zlib/libzbasic.a 20 | ZLIBD := -L$(ZBASIC)/sw/zlib 21 | LFLAGS := -T $(LDSCRIPT) $(ZLIBD) -lc -lm -lzbasic -lgcc -Wl,-Map=dry.map 22 | INCD := -I$(ZBASIC)/sw/zlib -I$(ZBASIC)/sw/board -I$(ZBASIC)/rtl 23 | CFLAGS=-O3 $(INCD) 24 | dry1.o: dry.c 25 | $(CC) -c $(CFLAGS) $(RAW) -o dry1.o 26 | dry2: dry1.o dry.c 27 | $(CC) -DPASS2 $(CFLAGS) $(RAW) dry1.o $(LFLAGS) -o dry2 28 | dry2.txt: dry2 29 | zip-objdump -Dr dry2 > dry2.txt 30 | .PHONY: dry.txt 31 | dry.txt: 32 | @echo "Cannot make dry.txt, did you mean to ask me to make dry2.txt?" 33 | 34 | clean: 35 | rm -f dry1.o dry2 36 | 37 | test: dry2 38 | $(ZBASIC)/sim/verilated/main_tb ./dry2 39 | -------------------------------------------------------------------------------- /auto-data/legalgen.txt: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: 4 | // 5 | // Project: ZBasic, a generic toplevel impl using the full ZipCPU 6 | // 7 | // DO NOT EDIT THIS FILE! 8 | // Computer Generated: This file is computer generated by AUTOFPGA. DO NOT EDIT. 9 | // DO NOT EDIT THIS FILE! 10 | // 11 | // CmdLine: 12 | // 13 | // Creator: Dan Gisselquist, Ph.D. 14 | // Gisselquist Technology, LLC 15 | // 16 | //////////////////////////////////////////////////////////////////////////////// 17 | // 18 | // Copyright (C) 2017-2020, Gisselquist Technology, LLC 19 | // 20 | // This program is free software (firmware): you can redistribute it and/or 21 | // modify it under the terms of the GNU General Public License as published 22 | // by the Free Software Foundation, either version 3 of the License, or (at 23 | // your option) any later version. 24 | // 25 | // This program is distributed in the hope that it will be useful, but WITHOUT 26 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 27 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 28 | // for more details. 29 | // 30 | // You should have received a copy of the GNU General Public License along 31 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 32 | // target there if the PDF file isn't present.) If not, see 33 | // for a copy. 34 | // 35 | // License: GPL, v3, as defined and found on www.gnu.org, 36 | // http://www.gnu.org/licenses/gpl.html 37 | // 38 | // 39 | //////////////////////////////////////////////////////////////////////////////// 40 | // 41 | // 42 | -------------------------------------------------------------------------------- /sw/board/hellosim.s: -------------------------------------------------------------------------------- 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 2 | ;; 3 | ;; Filename: hellosim.s 4 | ;; 5 | ;; Project: Zip CPU -- a small, lightweight, RISC CPU soft core 6 | ;; 7 | ;; Purpose: Hello World, only using the SIM instructions, as an initial 8 | ;; test of whether or not the special SIM instructions even work. 9 | ;; 10 | ;; 11 | ;; Creator: Dan Gisselquist, Ph.D. 12 | ;; Gisselquist Technology, LLC 13 | ;; 14 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 15 | ;; 16 | ;; Copyright (C) 2017-2019, Gisselquist Technology, LLC 17 | ;; 18 | ;; This program is free software (firmware): you can redistribute it and/or 19 | ;; modify it under the terms of the GNU General Public License as published 20 | ;; by the Free Software Foundation, either version 3 of the License, or (at 21 | ;; your option) any later version. 22 | ;; 23 | ;; This program is distributed in the hope that it will be useful, but WITHOUT 24 | ;; ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 25 | ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 26 | ;; for more details. 27 | ;; 28 | ;; License: GPL, v3, as defined and found on www.gnu.org, 29 | ;; http://www.gnu.org/licenses/gpl.html 30 | ;; 31 | ;; 32 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 33 | ;; 34 | ;; 35 | .section .start, "ax" 36 | .global _start 37 | _start: 38 | NOUT 'H' 39 | NOUT 'e' 40 | NOUT 'l' 41 | NOUT 'l' 42 | NOUT 'o' 43 | NOUT ' ' 44 | NOUT 'W' 45 | NOUT 'o' 46 | NOUT 'r' 47 | NOUT 'l' 48 | NOUT 'd' 49 | NOUT '!' 50 | NOUT '\r' 51 | NOUT '\n' 52 | NEXIT 0 53 | HALT 54 | BUSY 55 | -------------------------------------------------------------------------------- /sw/host/zipelf.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: zipelf.h 4 | // 5 | // Project: ZBasic, a generic toplevel impl using the full ZipCPU 6 | // 7 | // Purpose: 8 | // 9 | // 10 | // Creator: Dan Gisselquist, Ph.D. 11 | // Gisselquist Technology, LLC 12 | // 13 | //////////////////////////////////////////////////////////////////////////////// 14 | // 15 | // Copyright (C) 2015-2020, Gisselquist Technology, LLC 16 | // 17 | // This program is free software (firmware): you can redistribute it and/or 18 | // modify it under the terms of the GNU General Public License as published 19 | // by the Free Software Foundation, either version 3 of the License, or (at 20 | // your option) any later version. 21 | // 22 | // This program is distributed in the hope that it will be useful, but WITHOUT 23 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 24 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 25 | // for more details. 26 | // 27 | // You should have received a copy of the GNU General Public License along 28 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 29 | // target there if the PDF file isn't present.) If not, see 30 | // for a copy. 31 | // 32 | // License: GPL, v3, as defined and found on www.gnu.org, 33 | // http://www.gnu.org/licenses/gpl.html 34 | // 35 | // 36 | //////////////////////////////////////////////////////////////////////////////// 37 | // 38 | // 39 | #ifndef ZIPELF_H 40 | #define ZIPELF_H 41 | 42 | #include 43 | 44 | class ELFSECTION { 45 | public: 46 | uint32_t m_start, m_len; 47 | char m_data[4]; 48 | }; 49 | 50 | bool iself(const char *fname); 51 | void elfread(const char *fname, uint32_t &entry, ELFSECTION **§ions); 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /sim/verilated/zipelf.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: zipelf.h 4 | // 5 | // Project: Zip CPU -- a small, lightweight, RISC CPU soft core 6 | // 7 | // Purpose: 8 | // 9 | // 10 | // Creator: Dan Gisselquist, Ph.D. 11 | // Gisselquist Technology, LLC 12 | // 13 | //////////////////////////////////////////////////////////////////////////////// 14 | // 15 | // Copyright (C) 2015-2019, Gisselquist Technology, LLC 16 | // 17 | // This program is free software (firmware): you can redistribute it and/or 18 | // modify it under the terms of the GNU General Public License as published 19 | // by the Free Software Foundation, either version 3 of the License, or (at 20 | // your option) any later version. 21 | // 22 | // This program is distributed in the hope that it will be useful, but WITHOUT 23 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 24 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 25 | // for more details. 26 | // 27 | // You should have received a copy of the GNU General Public License along 28 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 29 | // target there if the PDF file isn't present.) If not, see 30 | // for a copy. 31 | // 32 | // License: GPL, v3, as defined and found on www.gnu.org, 33 | // http://www.gnu.org/licenses/gpl.html 34 | // 35 | // 36 | //////////////////////////////////////////////////////////////////////////////// 37 | // 38 | // 39 | #ifndef ZIPELF_H 40 | #define ZIPELF_H 41 | 42 | #include 43 | 44 | class ELFSECTION { 45 | public: 46 | uint32_t m_start, m_len; 47 | char m_data[4]; 48 | }; 49 | 50 | bool iself(const char *fname); 51 | void elfread(const char *fname, uint32_t &entry, ELFSECTION **§ions); 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /sw/zlib/bootloader.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: bootloader.h 4 | // 5 | // Project: Zip CPU -- a small, lightweight, RISC CPU soft core 6 | // 7 | // Purpose: 8 | // 9 | // 10 | // Creator: Dan Gisselquist, Ph.D. 11 | // Gisselquist Technology, LLC 12 | // 13 | //////////////////////////////////////////////////////////////////////////////// 14 | // 15 | // Copyright (C) 2015-2020, Gisselquist Technology, LLC 16 | // 17 | // This program is free software (firmware): you can redistribute it and/or 18 | // modify it under the terms of the GNU General Public License as published 19 | // by the Free Software Foundation, either version 3 of the License, or (at 20 | // your option) any later version. 21 | // 22 | // This program is distributed in the hope that it will be useful, but WITHOUT 23 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 24 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 25 | // for more details. 26 | // 27 | // You should have received a copy of the GNU General Public License along 28 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 29 | // target there if the PDF file isn't present.) If not, see 30 | // for a copy. 31 | // 32 | // License: GPL, v3, as defined and found on www.gnu.org, 33 | // http://www.gnu.org/licenses/gpl.html 34 | // 35 | // 36 | //////////////////////////////////////////////////////////////////////////////// 37 | // 38 | // 39 | #ifndef BOOTLOADER_H 40 | #define BOOTLOADER_H 41 | 42 | extern int _top_of_heap[1], _top_of_stack[1]; 43 | extern int _boot_address[1]; 44 | 45 | extern int _ram[1], _rom[1], _kram[1]; 46 | 47 | extern int _boot_address[1], 48 | _kram_start[1], _kram_end[1], 49 | _ram_image_start[1], _ram_image_end[1], 50 | _bss_image_end[1]; 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /rtl/builddate.v: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: builddate.v 4 | // 5 | // Project: ZBasic, a generic toplevel impl using the full ZipCPU 6 | // 7 | // Purpose: This file records the date of the last build. Running "make" 8 | // in the main directory will create this file. The `define found 9 | // within it then creates a version stamp that can be used to tell which 10 | // configuration is within an FPGA and so forth. 11 | // 12 | // Creator: Dan Gisselquist, Ph.D. 13 | // Gisselquist Technology, LLC 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | // 17 | // Copyright (C) 2015-2020, Gisselquist Technology, LLC 18 | // 19 | // This program is free software (firmware): you can redistribute it and/or 20 | // modify it under the terms of the GNU General Public License as published 21 | // by the Free Software Foundation, either version 3 of the License, or (at 22 | // your option) any later version. 23 | // 24 | // This program is distributed in the hope that it will be useful, but WITHOUT 25 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 26 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 27 | // for more details. 28 | // 29 | // You should have received a copy of the GNU General Public License along 30 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 31 | // target there if the PDF file isn't present.) If not, see 32 | // for a copy. 33 | // 34 | // License: GPL, v3, as defined and found on www.gnu.org, 35 | // http://www.gnu.org/licenses/gpl.html 36 | // 37 | // 38 | //////////////////////////////////////////////////////////////////////////////// 39 | // 40 | // 41 | `ifndef DATESTAMP 42 | `define DATESTAMP 32'h20201028 43 | `define BUILDTIME 32'h00184458 44 | `endif 45 | // 46 | -------------------------------------------------------------------------------- /auto-data/clock.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | ## 3 | ## Filename: clock.txt 4 | ## 5 | ## Project: AutoFPGA, a utility for composing FPGA designs from peripherals 6 | ## 7 | ## Purpose: 8 | ## 9 | ## Creator: Dan Gisselquist, Ph.D. 10 | ## Gisselquist Technology, LLC 11 | ## 12 | ################################################################################ 13 | ## 14 | ## Copyright (C) 2017-2020, Gisselquist Technology, LLC 15 | ## 16 | ## This program is free software (firmware): you can redistribute it and/or 17 | ## modify it under the terms of the GNU General Public License as published 18 | ## by the Free Software Foundation, either version 3 of the License, or (at 19 | ## your option) any later version. 20 | ## 21 | ## This program is distributed in the hope that it will be useful, but WITHOUT 22 | ## ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 23 | ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 24 | ## for more details. 25 | ## 26 | ## You should have received a copy of the GNU General Public License along 27 | ## with this program. (It's in the $(ROOT)/doc directory. Run make with no 28 | ## target there if the PDF file isn't present.) If not, see 29 | ## for a copy. 30 | ## 31 | ## License: GPL, v3, as defined and found on www.gnu.org, 32 | ## http://www.gnu.org/licenses/gpl.html 33 | ## 34 | ## 35 | ################################################################################ 36 | ## 37 | ## 38 | @PREFIX=clk 39 | @CLOCK.NAME=clk 40 | @CLOCK.TOP=i_clk 41 | @$CLOCK.FREQUENCY=100000000 42 | @CLOCK.WIRE=i_clk 43 | @TOP.DEFNS= 44 | wire s_clk, s_reset; 45 | @TOP.INSERT= 46 | assign s_clk = i_clk; 47 | assign s_reset = 1'b0; // This design requires local, not global resets 48 | @REGDEFS.H.DEFNS= 49 | #define CLKFREQHZ @$(CLOCK.FREQUENCY) 50 | @BDEF.DEFN= 51 | #define CLKFREQHZ @$(CLOCK.FREQUENCY) 52 | -------------------------------------------------------------------------------- /sim/verilated/twoc.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: twoc.h 4 | // 5 | // Project: ZBasic, a generic toplevel impl using the full ZipCPU 6 | // 7 | // Purpose: Some various two's complement related C++ helper routines. 8 | // Specifically, these help extract signed numbers from 9 | // packed bitfields, while guaranteeing that the upper bits 10 | // are properly sign extended (or not) as desired. 11 | // 12 | // Creator: Dan Gisselquist, Ph.D. 13 | // Gisselquist Technology, LLC 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | // 17 | // Copyright (C) 2015, Gisselquist Technology, LLC 18 | // 19 | // This program is free software (firmware): you can redistribute it and/or 20 | // modify it under the terms of the GNU General Public License as published 21 | // by the Free Software Foundation, either version 3 of the License, or (at 22 | // your option) any later version. 23 | // 24 | // This program is distributed in the hope that it will be useful, but WITHOUT 25 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 26 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 27 | // for more details. 28 | // 29 | // You should have received a copy of the GNU General Public License along 30 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 31 | // target there if the PDF file isn't present.) If not, see 32 | // for a copy. 33 | // 34 | // License: GPL, v3, as defined and found on www.gnu.org, 35 | // http://www.gnu.org/licenses/gpl.html 36 | // 37 | // 38 | //////////////////////////////////////////////////////////////////////////////// 39 | // 40 | // 41 | #ifndef TWOC_H 42 | #define TWOC_H 43 | 44 | extern long sbits(const long val, const int bits); 45 | extern unsigned long ubits(const long val, const int bits); 46 | 47 | #endif 48 | 49 | -------------------------------------------------------------------------------- /sw/board/txfns.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: txfns.h 4 | // 5 | // Project: ZBasic, a generic toplevel impl using the full ZipCPU 6 | // 7 | // Purpose: These are some *very* simple UART routines, designed to support 8 | // a program before the C-library is up and running. Once the 9 | // C-library is running on a device, it is anticipated that these routines 10 | // will no longer be needed or used--since they access the raw hardware 11 | // device(s). 12 | // 13 | // Creator: Dan Gisselquist, Ph.D. 14 | // Gisselquist Technology, LLC 15 | // 16 | //////////////////////////////////////////////////////////////////////////////// 17 | // 18 | // Copyright (C) 2015-2020, Gisselquist Technology, LLC 19 | // 20 | // This program is free software (firmware): you can redistribute it and/or 21 | // modify it under the terms of the GNU General Public License as published 22 | // by the Free Software Foundation, either version 3 of the License, or (at 23 | // your option) any later version. 24 | // 25 | // This program is distributed in the hope that it will be useful, but WITHOUT 26 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 27 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 28 | // for more details. 29 | // 30 | // You should have received a copy of the GNU General Public License along 31 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 32 | // target there if the PDF file isn't present.) If not, see 33 | // for a copy. 34 | // 35 | // License: GPL, v3, as defined and found on www.gnu.org, 36 | // http://www.gnu.org/licenses/gpl.html 37 | // 38 | // 39 | //////////////////////////////////////////////////////////////////////////////// 40 | // 41 | // 42 | #ifndef TXFNS_H 43 | #define TXFNS_H 44 | 45 | #include "board.h" 46 | 47 | extern void txchr(char ch); 48 | extern void txstr(const char *str); 49 | extern void txhex(unsigned val); 50 | extern void txdecimal(int val); 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /sw/host/twoc.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: twoc.h 4 | // 5 | // Project: ZBasic, a generic toplevel impl using the full ZipCPU 6 | // 7 | // Purpose: Some various two's complement related C++ helper routines. 8 | // Specifically, these help extract signed numbers from 9 | // packed bitfields, while guaranteeing that the upper bits 10 | // are properly sign extended (or not) as desired. 11 | // 12 | // Creator: Dan Gisselquist, Ph.D. 13 | // Gisselquist Technology, LLC 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | // 17 | // Copyright (C) 2015-2020, Gisselquist Technology, LLC 18 | // 19 | // This program is free software (firmware): you can redistribute it and/or 20 | // modify it under the terms of the GNU General Public License as published 21 | // by the Free Software Foundation, either version 3 of the License, or (at 22 | // your option) any later version. 23 | // 24 | // This program is distributed in the hope that it will be useful, but WITHOUT 25 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 26 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 27 | // for more details. 28 | // 29 | // You should have received a copy of the GNU General Public License along 30 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 31 | // target there if the PDF file isn't present.) If not, see 32 | // for a copy. 33 | // 34 | // License: GPL, v3, as defined and found on www.gnu.org, 35 | // http://www.gnu.org/licenses/gpl.html 36 | // 37 | // 38 | //////////////////////////////////////////////////////////////////////////////// 39 | // 40 | // 41 | #ifndef TWOC_H 42 | #define TWOC_H 43 | 44 | extern long sbits(const long val, const int bits); 45 | extern bool sfits(const long val, const int bits); 46 | extern unsigned long ubits(const long val, const int bits); 47 | extern unsigned long rndbits(const long val, const int bi, const int bo); 48 | 49 | #endif 50 | 51 | -------------------------------------------------------------------------------- /sim/verilated/twoc.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: twoc.cpp 4 | // 5 | // Project: ZBasic, a generic toplevel impl using the full ZipCPU 6 | // 7 | // Purpose: Some various two's complement related C++ helper routines. 8 | // Specifically, these help extract signed numbers from 9 | // packed bitfields, while guaranteeing that the upper bits 10 | // are properly sign extended (or not) as desired. 11 | // 12 | // Creator: Dan Gisselquist, Ph.D. 13 | // Gisselquist Technology, LLC 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | // 17 | // Copyright (C) 2015, Gisselquist Technology, LLC 18 | // 19 | // This program is free software (firmware): you can redistribute it and/or 20 | // modify it under the terms of the GNU General Public License as published 21 | // by the Free Software Foundation, either version 3 of the License, or (at 22 | // your option) any later version. 23 | // 24 | // This program is distributed in the hope that it will be useful, but WITHOUT 25 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 26 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 27 | // for more details. 28 | // 29 | // You should have received a copy of the GNU General Public License along 30 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 31 | // target there if the PDF file isn't present.) If not, see 32 | // for a copy. 33 | // 34 | // License: GPL, v3, as defined and found on www.gnu.org, 35 | // http://www.gnu.org/licenses/gpl.html 36 | // 37 | // 38 | //////////////////////////////////////////////////////////////////////////////// 39 | // 40 | // 41 | #include "twoc.h" 42 | 43 | long sbits(const long val, const int bits) { 44 | long r; 45 | 46 | r = val & ((1l< for a copy. 32 | // 33 | // License: GPL, v3, as defined and found on www.gnu.org, 34 | // http://www.gnu.org/licenses/gpl.html 35 | // 36 | // 37 | //////////////////////////////////////////////////////////////////////////////// 38 | // 39 | // 40 | #ifndef PORT_H 41 | #define PORT_H 42 | 43 | // There are two ways to connect: via a serial port, and via a TCP socket 44 | // connected to a serial port. This way, we can connect the device on one 45 | // computer, test it, and when/if it doesn't work we can replace the device 46 | // with the test-bench. Across the network, no one will know any better that 47 | // anything had changed. 48 | #define FPGAHOST "localhost" 49 | #define FPGAPORT 8845 50 | 51 | #define FPGAOPEN(V) V= new FPGA(new NETCOMMS(FPGAHOST, FPGAPORT)) 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /sw/host/twoc.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: twoc.cpp 4 | // 5 | // Project: ZBasic, a generic toplevel impl using the full ZipCPU 6 | // 7 | // Purpose: Some various two's complement related C++ helper routines. 8 | // Specifically, these help extract signed numbers from 9 | // packed bitfields, while guaranteeing that the upper bits are properly 10 | // extended (or not) as desired. 11 | // 12 | // Creator: Dan Gisselquist, Ph.D. 13 | // Gisselquist Technology, LLC 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | // 17 | // Copyright (C) 2015-2020, Gisselquist Technology, LLC 18 | // 19 | // This program is free software (firmware): you can redistribute it and/or 20 | // modify it under the terms of the GNU General Public License as published 21 | // by the Free Software Foundation, either version 3 of the License, or (at 22 | // your option) any later version. 23 | // 24 | // This program is distributed in the hope that it will be useful, but WITHOUT 25 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 26 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 27 | // for more details. 28 | // 29 | // You should have received a copy of the GNU General Public License along 30 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 31 | // target there if the PDF file isn't present.) If not, see 32 | // for a copy. 33 | // 34 | // License: GPL, v3, as defined and found on www.gnu.org, 35 | // http://www.gnu.org/licenses/gpl.html 36 | // 37 | // 38 | //////////////////////////////////////////////////////////////////////////////// 39 | // 40 | // 41 | #include "twoc.h" 42 | 43 | long sbits(const long val, const int bits) { 44 | long r; 45 | 46 | r = val & ((1l< for a copy. 30 | ## 31 | ## License: GPL, v3, as defined and found on www.gnu.org, 32 | ## http://www.gnu.org/licenses/gpl.html 33 | ## 34 | ## 35 | ################################################################################ 36 | ## 37 | ## 38 | @PREFIX=pwrcount 39 | @NADDR=1 40 | @ACCESS=PWRCOUNT_ACCESS 41 | @SLAVE.TYPE=SINGLE 42 | @SLAVE.BUS=wb 43 | @MAIN.DEFNS= 44 | reg [31:0] r_pwrcount_data; 45 | @MAIN.INSERT= 46 | initial r_@$(PREFIX)_data = 32'h0; 47 | always @(posedge i_clk) 48 | if (r_@$(PREFIX)_data[31]) 49 | r_@$(PREFIX)_data[30:0] <= r_@$(PREFIX)_data[30:0] + 1'b1; 50 | else 51 | r_@$(PREFIX)_data[31:0] <= r_@$(PREFIX)_data[31:0] + 1'b1; 52 | 53 | assign @$(SLAVE.PREFIX)_stall = 1'b0; 54 | assign @$(SLAVE.PREFIX)_ack = @$(SLAVE.PREFIX)_stb; 55 | assign @$(SLAVE.PREFIX)_idata = r_@$(PREFIX)_data; 56 | @REGS.N=1 57 | @REGS.0= 0 R_PWRCOUNT PWRCOUNT 58 | @BDEF.OSVAL= static volatile unsigned *const _@$(PREFIX) = ((unsigned *)@$[0x%08x](REGBASE)); 59 | -------------------------------------------------------------------------------- /sw/zlib/umod.c: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: umod.c 4 | // 5 | // Project: ZBasic, a generic toplevel impl using the full ZipCPU 6 | // 7 | // Purpose: This is a temporary file--a crutch if you will--until a similar 8 | // capability is merged into GCC. Right now, GCC has no way of 9 | // taking the module of two 64-bit numbers, and this routine provides that 10 | // capability. 11 | // 12 | // This routine is required by and used by newlib's printf in order to 13 | // print decimal numbers (%d) to an IO stream. 14 | // 15 | // Once gcc is properly patched, this will be removed from the 16 | // repository. 17 | // 18 | // Creator: Dan Gisselquist, Ph.D. 19 | // Gisselquist Technology, LLC 20 | // 21 | //////////////////////////////////////////////////////////////////////////////// 22 | // 23 | // Copyright (C) 2017-2020, Gisselquist Technology, LLC 24 | // 25 | // This program is free software (firmware): you can redistribute it and/or 26 | // modify it under the terms of the GNU General Public License as published 27 | // by the Free Software Foundation, either version 3 of the License, or (at 28 | // your option) any later version. 29 | // 30 | // This program is distributed in the hope that it will be useful, but WITHOUT 31 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 32 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 33 | // for more details. 34 | // 35 | // You should have received a copy of the GNU General Public License along 36 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 37 | // target there if the PDF file isn't present.) If not, see 38 | // for a copy. 39 | // 40 | // License: GPL, v3, as defined and found on www.gnu.org, 41 | // http://www.gnu.org/licenses/gpl.html 42 | // 43 | // 44 | //////////////////////////////////////////////////////////////////////////////// 45 | // 46 | // 47 | #include 48 | 49 | 50 | unsigned long __udivdi3(unsigned long, unsigned long); 51 | 52 | __attribute((noinline)) 53 | unsigned long __umoddi3(unsigned long a, unsigned long b) { 54 | unsigned long r; 55 | 56 | // Return a modulo b, or a%b in C syntax 57 | r = __udivdi3(a, b); 58 | r = r * b; 59 | r = a - r; 60 | return r; 61 | } 62 | 63 | -------------------------------------------------------------------------------- /sw/host/port.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: port.h 4 | // 5 | // Project: ZBasic, a generic toplevel impl using the full ZipCPU 6 | // 7 | // Purpose: Defines the communication parameters necessary for communicating 8 | // both with our actual hardware device, as well as with our Verilator 9 | // simulation. The result is that whatever communicates with the other may 10 | // not know the difference (as desired). 11 | // 12 | // 13 | // Creator: Dan Gisselquist, Ph.D. 14 | // Gisselquist Technology, LLC 15 | // 16 | //////////////////////////////////////////////////////////////////////////////// 17 | // 18 | // Copyright (C) 2015-2020, Gisselquist Technology, LLC 19 | // 20 | // This program is free software (firmware): you can redistribute it and/or 21 | // modify it under the terms of the GNU General Public License as published 22 | // by the Free Software Foundation, either version 3 of the License, or (at 23 | // your option) any later version. 24 | // 25 | // This program is distributed in the hope that it will be useful, but WITHOUT 26 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 27 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 28 | // for more details. 29 | // 30 | // You should have received a copy of the GNU General Public License along 31 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 32 | // target there if the PDF file isn't present.) If not, see 33 | // for a copy. 34 | // 35 | // License: GPL, v3, as defined and found on www.gnu.org, 36 | // http://www.gnu.org/licenses/gpl.html 37 | // 38 | // 39 | //////////////////////////////////////////////////////////////////////////////// 40 | // 41 | // 42 | #ifndef PORT_H 43 | #define PORT_H 44 | 45 | // There are two ways to connect: via a serial port, and via a TCP socket 46 | // connected to a serial port. This way, we can connect the device on one 47 | // computer, test it, and when/if it doesn't work we can replace the device 48 | // with the test-bench. Across the network, no one will know any better that 49 | // anything had changed. 50 | #define FPGAHOST "localhost" // A random hostname,back from the grave 51 | #define FPGAPORT 8845 52 | 53 | #define FPGAOPEN(V) V= new FPGA(new NETCOMMS(FPGAHOST, FPGAPORT)) 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /auto-data/pic.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | ## 3 | ## Filename: pic.txt 4 | ## 5 | ## Project: AutoFPGA, a utility for composing FPGA designs from peripherals 6 | ## 7 | ## Purpose: 8 | ## 9 | ## Creator: Dan Gisselquist, Ph.D. 10 | ## Gisselquist Technology, LLC 11 | ## 12 | ################################################################################ 13 | ## 14 | ## Copyright (C) 2017-2020, Gisselquist Technology, LLC 15 | ## 16 | ## This program is free software (firmware): you can redistribute it and/or 17 | ## modify it under the terms of the GNU General Public License as published 18 | ## by the Free Software Foundation, either version 3 of the License, or (at 19 | ## your option) any later version. 20 | ## 21 | ## This program is distributed in the hope that it will be useful, but WITHOUT 22 | ## ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 23 | ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 24 | ## for more details. 25 | ## 26 | ## You should have received a copy of the GNU General Public License along 27 | ## with this program. (It's in the $(ROOT)/doc directory. Run make with no 28 | ## target there if the PDF file isn't present.) If not, see 29 | ## for a copy. 30 | ## 31 | ## License: GPL, v3, as defined and found on www.gnu.org, 32 | ## http://www.gnu.org/licenses/gpl.html 33 | ## 34 | ## 35 | ################################################################################ 36 | ## 37 | ## 38 | @PREFIX=buspic 39 | @DEVID=BUSPIC 40 | @NADDR=1 41 | @BUSP=wb 42 | @ACCESS=BUSPIC_ACCESS 43 | @SLAVE.TYPE=SINGLE 44 | @SLAVE.BUS=@$(BUSP) 45 | @PIC.BUS= bus_int_vector 46 | @PIC.MAX= 15 47 | @INT.BUS.WIRE= w_bus_int 48 | @INT.BUS.PIC= syspic 49 | @INT.BUS.ID= 6 50 | @BDEF.DEFN= 51 | #define BUSPIC(X) (1< for a copy. 30 | ## 31 | ## License: GPL, v3, as defined and found on www.gnu.org, 32 | ## http://www.gnu.org/licenses/gpl.html 33 | ## 34 | ## 35 | ################################################################################ 36 | ## 37 | ## 38 | @PREFIX=rtcdate 39 | @DEVID=RTCDATE 40 | @NADDR=1 41 | @ACCESS=@$(DEVID)_ACCESS 42 | @DEPENDS=RTC_ACCESS 43 | @SLAVE.TYPE=SINGLE 44 | @SLAVE.BUS=wb 45 | @MAIN.PARAM= 46 | // 47 | // Initial calendar DATE 48 | // 49 | `ifdef VERSION_ACCESS 50 | parameter INITIAL_DATE = `DATESTAMP; 51 | `else 52 | parameter INITIAL_DATE = 30'h20000101; 53 | `endif 54 | @MAIN.INSERT= 55 | // 56 | // The Calendar DATE 57 | // 58 | rtcdate #(.INITIAL_DATE(INITIAL_DATE[29:0])) 59 | @$(PREFIX)i(i_clk, rtc_ppd, 60 | @$(SLAVE.PORTLIST)); 61 | @REGS.N=1 62 | @REGS.0= 0 R_@$(DEVID) @$(DEVID) DATE 63 | @BDEF.IONAME= _@$(PREFIX) 64 | @BDEF.IOTYPE= unsigned 65 | @BDEF.OSDEF= _BOARD_HAS_@$(DEVID) 66 | @BDEF.OSVAL= static volatile @$(BDEF.IOTYPE) *const @$(BDEF.IONAME) = ((@$BDEF.IOTYPE *)@$REGBASE); 67 | @RTL.MAKE.SUBD=rtc 68 | @RTL.MAKE.GROUP=@$(DEVID) 69 | @RTL.MAKE.FILES=rtcdate.v 70 | -------------------------------------------------------------------------------- /rtl/cpu/iscachable.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: ./iscachable.v 4 | // 5 | // Project: ZBasic, a generic toplevel implementation using the full ZipCPU 6 | // 7 | // DO NOT EDIT THIS FILE! 8 | // Computer Generated: This file is computer generated by AUTOFPGA. DO NOT EDIT. 9 | // DO NOT EDIT THIS FILE! 10 | // 11 | // 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 12 | // 13 | // Creator: Dan Gisselquist, Ph.D. 14 | // Gisselquist Technology, LLC 15 | // 16 | //////////////////////////////////////////////////////////////////////////////// 17 | // 18 | // Copyright (C) 2017-2020, Gisselquist Technology, LLC 19 | // 20 | // This program is free software (firmware): you can redistribute it and/or 21 | // modify it under the terms of the GNU General Public License as published 22 | // by the Free Software Foundation, either version 3 of the License, or (at 23 | // your option) any later version. 24 | // 25 | // This program is distributed in the hope that it will be useful, but WITHOUT 26 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 27 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 28 | // for more details. 29 | // 30 | // You should have received a copy of the GNU General Public License along 31 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 32 | // target there if the PDF file isn't present.) If not, see 33 | // for a copy. 34 | // 35 | // License: GPL, v3, as defined and found on www.gnu.org, 36 | // http://www.gnu.org/licenses/gpl.html 37 | // 38 | // 39 | //////////////////////////////////////////////////////////////////////////////// 40 | // 41 | // 42 | `default_nettype none 43 | // 44 | module iscachable(i_addr, o_cachable); 45 | localparam AW = 23; 46 | input wire [AW-1:0] i_addr; 47 | output reg o_cachable; 48 | 49 | always @(*) 50 | begin 51 | o_cachable = 1'b0; 52 | // Bus master: wb 53 | // Bus master: wb_sio 54 | // bkram 55 | if ((i_addr[22:0] & 23'h780000) == 23'h300000) 56 | o_cachable = 1'b1; 57 | // flash 58 | if ((i_addr[22:0] & 23'h400000) == 23'h400000) 59 | o_cachable = 1'b1; 60 | end 61 | 62 | endmodule 63 | -------------------------------------------------------------------------------- /rtl/cpu/iscachable.v: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: ./iscachable.v 4 | // 5 | // Project: ZBasic, a generic toplevel implementation using the full ZipCPU 6 | // 7 | // DO NOT EDIT THIS FILE! 8 | // Computer Generated: This file is computer generated by AUTOFPGA. DO NOT EDIT. 9 | // DO NOT EDIT THIS FILE! 10 | // 11 | // CmdLine: autofpga autofpga -d -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 12 | // 13 | // Creator: Dan Gisselquist, Ph.D. 14 | // Gisselquist Technology, LLC 15 | // 16 | //////////////////////////////////////////////////////////////////////////////// 17 | // 18 | // Copyright (C) 2017-2020, Gisselquist Technology, LLC 19 | // 20 | // This program is free software (firmware): you can redistribute it and/or 21 | // modify it under the terms of the GNU General Public License as published 22 | // by the Free Software Foundation, either version 3 of the License, or (at 23 | // your option) any later version. 24 | // 25 | // This program is distributed in the hope that it will be useful, but WITHOUT 26 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 27 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 28 | // for more details. 29 | // 30 | // You should have received a copy of the GNU General Public License along 31 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 32 | // target there if the PDF file isn't present.) If not, see 33 | // for a copy. 34 | // 35 | // License: GPL, v3, as defined and found on www.gnu.org, 36 | // http://www.gnu.org/licenses/gpl.html 37 | // 38 | // 39 | //////////////////////////////////////////////////////////////////////////////// 40 | // 41 | // 42 | `default_nettype none 43 | // 44 | module iscachable( 45 | // {{{ 46 | input wire [25-1:0] i_addr, 47 | output reg o_cachable 48 | // }}} 49 | ); 50 | 51 | always @(*) 52 | begin 53 | o_cachable = 1'b0; 54 | // Bus master: wb 55 | // Bus master: wb_sio 56 | // bkram 57 | if ((i_addr[24:0] & 25'h1e00000) == 25'h0c00000) 58 | o_cachable = 1'b1; 59 | // flash 60 | if ((i_addr[24:0] & 25'h1000000) == 25'h1000000) 61 | o_cachable = 1'b1; 62 | end 63 | 64 | endmodule 65 | -------------------------------------------------------------------------------- /auto-data/simtrace.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | ## 3 | ## Filename: simtrace.c 4 | ## 5 | ## Project: AutoFPGA, a utility for composing FPGA designs from peripherals 6 | ## 7 | ## Purpose: Creates a GPIO output port for the Verilator simulation, 8 | ## indicating if and when the CPU wants a trace to take place. 9 | ## 10 | ## Creator: Dan Gisselquist, Ph.D. 11 | ## Gisselquist Technology, LLC 12 | ## 13 | ################################################################################ 14 | ## 15 | ## Copyright (C) 2018-2020, Gisselquist Technology, LLC 16 | ## 17 | ## This program is free software (firmware): you can redistribute it and/or 18 | ## modify it under the terms of the GNU General Public License as published 19 | ## by the Free Software Foundation, either version 3 of the License, or (at 20 | ## your option) any later version. 21 | ## 22 | ## This program is distributed in the hope that it will be useful, but WITHOUT 23 | ## ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 24 | ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 25 | ## for more details. 26 | ## 27 | ## You should have received a copy of the GNU General Public License along 28 | ## with this program. (It's in the $(ROOT)/doc directory. Run make with no 29 | ## target there if the PDF file isn't present.) If not, see 30 | ## for a copy. 31 | ## 32 | ## License: GPL, v3, as defined and found on www.gnu.org, 33 | ## http://www.gnu.org/licenses/gpl.html 34 | ## 35 | ## 36 | ################################################################################ 37 | ## 38 | ## 39 | @PREFIX=simtrace 40 | @DEVID=TRACE 41 | @NADDR=4 42 | @ACCESS=SIMTRACE_ACCESS 43 | @SLAVE.TYPE=SINGLE 44 | @SLAVE.BUS=wb 45 | @BUS.NAME=wb 46 | @MAIN.PORTLIST= 47 | // The Sim trace output wire 48 | o_trace 49 | @MAIN.IODECL= 50 | // Sim trace declaration 51 | output reg o_trace; 52 | @MAIN.INSERT= 53 | always @(posedge i_clk) 54 | if (i_reset) 55 | o_trace <= 1'b0; 56 | else if ((simtrace_sel)&&(wb_stb)&&(wb_we)) 57 | o_trace <= wb_data[0]; 58 | 59 | assign simtrace_data = { 31'h0, o_trace }; 60 | @MAIN.ALT= 61 | assign o_trace = 1'b0; 62 | @REGS.N=1 63 | @REGS.NOTE= // Sim Trace register 64 | @REGS.0= 0 R_@$(DEVID) TRACE 65 | @BDEF.DEFN= 66 | @BDEF.IONAME=_simtrace 67 | @BDEF.IOTYPE=unsigned 68 | @BDEF.OSDEF=_BOARD_HAS_@$(DEVID) 69 | @BDEF.OSVAL=static volatile @$BDEF.IOTYPE *const @$BDEF.IONAME = ((@$BDEF.IOTYPE *)@$[0x%08x](REGBASE)); 70 | -------------------------------------------------------------------------------- /rtl/wbubus/wbuinput.v: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: wbuinput.v 4 | // 5 | // Project: FPGA library 6 | // 7 | // Purpose: Coordinates the receiption of bytes, which are then translated 8 | // into codewords describing postential bus transactions. This 9 | // includes turning the human readable bytes into more compact bits, 10 | // forming those bits into codewords, and decompressing any that reference 11 | // addresses within a compression table. 12 | // 13 | // 14 | // Creator: Dan Gisselquist, Ph.D. 15 | // Gisselquist Technology, LLC 16 | // 17 | //////////////////////////////////////////////////////////////////////////////// 18 | // 19 | // Copyright (C) 2015-2020, Gisselquist Technology, LLC 20 | // 21 | // This program is free software (firmware): you can redistribute it and/or 22 | // modify it under the terms of the GNU General Public License as published 23 | // by the Free Software Foundation, either version 3 of the License, or (at 24 | // your option) any later version. 25 | // 26 | // This program is distributed in the hope that it will be useful, but WITHOUT 27 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 28 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 29 | // for more details. 30 | // 31 | // You should have received a copy of the GNU General Public License along 32 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 33 | // target there if the PDF file isn't present.) If not, see 34 | // for a copy. 35 | // 36 | // License: GPL, v3, as defined and found on www.gnu.org, 37 | // http://www.gnu.org/licenses/gpl.html 38 | // 39 | // 40 | //////////////////////////////////////////////////////////////////////////////// 41 | // 42 | // 43 | `default_nettype none 44 | // 45 | module wbuinput(i_clk, i_stb, i_byte, o_stb, o_codword); 46 | input wire i_clk, i_stb; 47 | input wire [7:0] i_byte; 48 | output wire o_stb; 49 | output wire [35:0] o_codword; 50 | 51 | wire hx_stb, hx_valid; 52 | wire [5:0] hx_hexbits; 53 | wbutohex tobits(i_clk, i_stb, i_byte, 54 | hx_stb, hx_valid, hx_hexbits); 55 | 56 | wire cw_stb; 57 | wire [35:0] cw_word; 58 | wbureadcw formcw(i_clk, hx_stb, hx_valid, hx_hexbits, 59 | cw_stb, cw_word); 60 | 61 | // `define DEBUGGING 62 | `ifdef DEBUGGING 63 | assign o_stb = cw_stb; 64 | assign o_codword = cw_word; 65 | `else 66 | wbudecompress unpack(i_clk,cw_stb,cw_word, o_stb, o_codword); 67 | `endif 68 | 69 | endmodule 70 | -------------------------------------------------------------------------------- /doc/src/GT.eps: -------------------------------------------------------------------------------- 1 | %!PS-Adobe-3.0 EPSF-3.0 2 | %%BoundingBox: 0 0 504 288 3 | %%Creator: Gisselquist Technology LLC 4 | %%Title: Gisselquist Technology Logo 5 | %%CreationDate: 11 Mar 2014 6 | %%EndComments 7 | %%BeginProlog 8 | /black { 0 setgray } def 9 | /white { 1 setgray } def 10 | /height { 288 } def 11 | /lw { height 8 div } def 12 | %%EndProlog 13 | % %%Page: 1 14 | 15 | false { % A bounding box 16 | 0 setlinewidth 17 | newpath 18 | 0 0 moveto 19 | 0 height lineto 20 | 1.625 height mul lw add 0 rlineto 21 | 0 height neg rlineto 22 | closepath stroke 23 | } if 24 | 25 | true { % The "G" 26 | newpath 27 | height 2 div 1.25 mul height moveto 28 | height 2 div height 4 div sub height lineto 29 | 0 height 3 4 div mul lineto 30 | 0 height 4 div lineto 31 | height 4 div 0 lineto 32 | height 3 4 div mul 0 lineto 33 | height height 4 div lineto 34 | height height 2 div lineto 35 | % 36 | height lw sub height 2 div lineto 37 | height lw sub height 4 div lw 2 div add lineto 38 | height 3 4 div mul lw 2 div sub lw lineto 39 | height 4 div lw 2 div add lw lineto 40 | lw height 4 div lw 2 div add lineto 41 | lw height 3 4 div mul lw 2 div sub lineto 42 | height 4 div lw 2 div add height lw sub lineto 43 | height 2 div 1.25 mul height lw sub lineto 44 | closepath fill 45 | newpath 46 | height 2 div height 2 div moveto 47 | height 2 div 0 rlineto 48 | 0 height 2 div neg rlineto 49 | lw neg 0 rlineto 50 | 0 height 2 div lw sub rlineto 51 | height 2 div height 2 div lw sub lineto 52 | closepath fill 53 | } if 54 | 55 | height 2 div 1.25 mul lw add 0 translate 56 | false { 57 | newpath 58 | 0 height moveto 59 | height 0 rlineto 60 | 0 lw neg rlineto 61 | height lw sub 2 div neg 0 rlineto 62 | 0 height lw sub neg rlineto 63 | lw neg 0 rlineto 64 | 0 height lw sub rlineto 65 | height lw sub 2 div neg 0 rlineto 66 | 0 lw rlineto 67 | closepath fill 68 | } if 69 | 70 | true { % The "T" of "GT". 71 | newpath 72 | 0 height moveto 73 | height lw add 2 div 0 rlineto 74 | 0 height neg rlineto 75 | lw neg 0 rlineto 76 | 0 height lw sub rlineto 77 | height lw sub 2 div neg 0 rlineto 78 | closepath fill 79 | 80 | % The right half of the top of the "T" 81 | newpath 82 | % (height + lw)/2 + lw 83 | height lw add 2 div lw add height moveto 84 | % height - (above) = height - height/2 - 3/2 lw = height/2-3/2lw 85 | height 3 lw mul sub 2 div 0 rlineto 86 | 0 lw neg rlineto 87 | height 3 lw mul sub 2 div neg 0 rlineto 88 | closepath fill 89 | } if 90 | 91 | 92 | grestore 93 | showpage 94 | %%EOF 95 | -------------------------------------------------------------------------------- /sw/host/flashdrvr.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: flashdrvr.h 4 | // 5 | // Project: ZBasic, a generic toplevel impl using the full ZipCPU 6 | // 7 | // Purpose: Flash driver. Encapsulates writing, both erasing sectors and 8 | // the programming pages, to the flash device. 9 | // 10 | // Creator: Dan Gisselquist, Ph.D. 11 | // Gisselquist Technology, LLC 12 | // 13 | //////////////////////////////////////////////////////////////////////////////// 14 | // 15 | // Copyright (C) 2015-2020, Gisselquist Technology, LLC 16 | // 17 | // This program is free software (firmware): you can redistribute it and/or 18 | // modify it under the terms of the GNU General Public License as published 19 | // by the Free Software Foundation, either version 3 of the License, or (at 20 | // your option) any later version. 21 | // 22 | // This program is distributed in the hope that it will be useful, but WITHOUT 23 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 24 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 25 | // for more details. 26 | // 27 | // You should have received a copy of the GNU General Public License along 28 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 29 | // target there if the PDF file isn't present.) If not, see 30 | // for a copy. 31 | // 32 | // License: GPL, v3, as defined and found on www.gnu.org, 33 | // http://www.gnu.org/licenses/gpl.html 34 | // 35 | // 36 | //////////////////////////////////////////////////////////////////////////////// 37 | // 38 | // 39 | // 40 | #ifndef FLASHDRVR_H 41 | #define FLASHDRVR_H 42 | 43 | #include "regdefs.h" 44 | 45 | class FLASHDRVR { 46 | private: 47 | DEVBUS *m_fpga; 48 | bool m_debug; 49 | unsigned m_id; // ID of the flash device 50 | 51 | // 52 | void take_offline(void); 53 | void place_online(void); 54 | void restore_dualio(void); 55 | void restore_quadio(void); 56 | static void restore_dualio(DEVBUS *fpga); 57 | static void restore_quadio(DEVBUS *fpga); 58 | // 59 | bool verify_config(void); 60 | void set_config(void); 61 | void flwait(void); 62 | public: 63 | FLASHDRVR(DEVBUS *fpga); 64 | bool erase_sector(const unsigned sector, const bool verify_erase=true); 65 | bool page_program(const unsigned addr, const unsigned len, 66 | const char *data, const bool verify_write=true); 67 | bool write(const unsigned addr, const unsigned len, 68 | const char *data, const bool verify=false); 69 | 70 | unsigned flashid(void); 71 | 72 | static void take_offline(DEVBUS *fpga); 73 | static void place_online(DEVBUS *fpga); 74 | }; 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /sw/host/llcomms.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: llcomms.h 4 | // 5 | // Project: ZBasic, a generic toplevel impl using the full ZipCPU 6 | // 7 | // Purpose: This is the C++ program on the command side that will interact 8 | // with a UART on an FPGA, both sending and receiving characters. 9 | // Any bus interaction will call routines from this lower level library to 10 | // accomplish the actual connection to and transmission to/from the board. 11 | // 12 | // Creator: Dan Gisselquist, Ph.D. 13 | // Gisselquist Technology, LLC 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | // 17 | // Copyright (C) 2015-2020, Gisselquist Technology, LLC 18 | // 19 | // This program is free software (firmware): you can redistribute it and/or 20 | // modify it under the terms of the GNU General Public License as published 21 | // by the Free Software Foundation, either version 3 of the License, or (at 22 | // your option) any later version. 23 | // 24 | // This program is distributed in the hope that it will be useful, but WITHOUT 25 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 26 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 27 | // for more details. 28 | // 29 | // You should have received a copy of the GNU General Public License along 30 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 31 | // target there if the PDF file isn't present.) If not, see 32 | // for a copy. 33 | // 34 | // License: GPL, v3, as defined and found on www.gnu.org, 35 | // http://www.gnu.org/licenses/gpl.html 36 | // 37 | // 38 | //////////////////////////////////////////////////////////////////////////////// 39 | // 40 | // 41 | #ifndef LLCOMMS_H 42 | #define LLCOMMS_H 43 | 44 | class LLCOMMSI { 45 | protected: 46 | int m_fdw, m_fdr; 47 | LLCOMMSI(void); 48 | public: 49 | unsigned long m_total_nread, m_total_nwrit; 50 | 51 | virtual ~LLCOMMSI(void) { close(); } 52 | virtual void kill(void) { this->close(); }; 53 | virtual void close(void); 54 | virtual void write(char *buf, int len); 55 | virtual int read(char *buf, int len); 56 | virtual bool poll(unsigned ms); 57 | 58 | // Tests whether or not bytes are available to be read, returns a 59 | // count of the bytes that may be immediately read 60 | virtual int available(void); // { return 0; }; 61 | }; 62 | 63 | class TTYCOMMS : public LLCOMMSI { 64 | public: 65 | TTYCOMMS(const char *dev); 66 | }; 67 | 68 | class NETCOMMS : public LLCOMMSI { 69 | public: 70 | NETCOMMS(const char *dev, const int port); 71 | virtual void close(void); 72 | }; 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /auto-data/mem_bkram_only.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | ## 3 | ## Filename: mem_flash_bkram.txt 4 | ## 5 | ## Project: ZBasic, a generic toplevel impl using the full ZipCPU 6 | ## 7 | ## Purpose: Describes a memory model containing nothing more than flash 8 | ## and block RAM. This will be used to create a board.ld linker 9 | ## script that can be used to link ZipCPU programs. 10 | ## 11 | ## 12 | ## Creator: Dan Gisselquist, Ph.D. 13 | ## Gisselquist Technology, LLC 14 | ## 15 | ################################################################################ 16 | ## 17 | ## Copyright (C) 2017-2020, Gisselquist Technology, LLC 18 | ## 19 | ## This program is free software (firmware): you can redistribute it and/or 20 | ## modify it under the terms of the GNU General Public License as published 21 | ## by the Free Software Foundation, either version 3 of the License, or (at 22 | ## your option) any later version. 23 | ## 24 | ## This program is distributed in the hope that it will be useful, but WITHOUT 25 | ## ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 26 | ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 27 | ## for more details. 28 | ## 29 | ## You should have received a copy of the GNU General Public License along 30 | ## with this program. (It's in the $(ROOT)/doc directory. Run make with no 31 | ## target there if the PDF file isn't present.) If not, see 32 | ## for a copy. 33 | ## 34 | ## License: GPL, v3, as defined and found on www.gnu.org, 35 | ## http://www.gnu.org/licenses/gpl.html 36 | ## 37 | ## 38 | ################################################################################ 39 | ## 40 | ## 41 | ## 42 | @PREFIX=mem_bkram_only 43 | @MASTER.TYPE=SCRIPT 44 | @MASTER.BUS=wb 45 | @LD.FILE=bkram.ld 46 | @LD.DEFNS= 47 | /* LD.DEFNS from @$(PREFIX) */ 48 | _kram = 0; /* No high-speed kernel RAM */ 49 | _ram = ORIGIN(bkram); 50 | _rom = 0; 51 | _top_of_stack = ORIGIN(bkram) + LENGTH(bkram); 52 | 53 | @LD.SCRIPT= 54 | /* LD.SCRIPT from @$(PREFIX) */ 55 | SECTIONS 56 | { 57 | .ramcode ORIGIN(bkram) : ALIGN(4) { 58 | _boot_address = .; 59 | _kram_start = .; 60 | _kram_end = .; 61 | _ram_image_start = . ; 62 | *(.start) *(.boot) 63 | *(.kernel) 64 | *(.text.startup) 65 | *(.text*) 66 | *(.rodata*) *(.strings) 67 | *(.data) *(COMMON) 68 | }> bkram 69 | _ram_image_end = . ; 70 | .bss : ALIGN_WITH_INPUT { 71 | *(.bss) 72 | _bss_image_end = . ; 73 | } > bkram 74 | _top_of_heap = .; 75 | } 76 | # 77 | -------------------------------------------------------------------------------- /auto-data/version.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | ## 3 | ## Filename: version.txt 4 | ## 5 | ## Project: AutoFPGA, a utility for composing FPGA designs from peripherals 6 | ## 7 | ## Purpose: 8 | ## 9 | ## Creator: Dan Gisselquist, Ph.D. 10 | ## Gisselquist Technology, LLC 11 | ## 12 | ################################################################################ 13 | ## 14 | ## Copyright (C) 2017-2020, Gisselquist Technology, LLC 15 | ## 16 | ## This program is free software (firmware): you can redistribute it and/or 17 | ## modify it under the terms of the GNU General Public License as published 18 | ## by the Free Software Foundation, either version 3 of the License, or (at 19 | ## your option) any later version. 20 | ## 21 | ## This program is distributed in the hope that it will be useful, but WITHOUT 22 | ## ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 23 | ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 24 | ## for more details. 25 | ## 26 | ## You should have received a copy of the GNU General Public License along 27 | ## with this program. (It's in the $(ROOT)/doc directory. Run make with no 28 | ## target there if the PDF file isn't present.) If not, see 29 | ## for a copy. 30 | ## 31 | ## License: GPL, v3, as defined and found on www.gnu.org, 32 | ## http://www.gnu.org/licenses/gpl.html 33 | ## 34 | ## 35 | ################################################################################ 36 | ## 37 | ## 38 | @PREFIX=version 39 | @DEVID=VERSION 40 | @ACCESS=VERSION_ACCESS 41 | @NADDR=1 42 | @SLAVE.TYPE=SINGLE 43 | @SLAVE.BUS=wb 44 | @MAIN.INCLUDE= 45 | `include "builddate.v" 46 | @MAIN.INSERT= 47 | assign @$(SLAVE.PREFIX)_idata = `DATESTAMP; 48 | assign @$(SLAVE.PREFIX)_ack = @$(SLAVE.PREFIX)_stb; 49 | assign @$(SLAVE.PREFIX)_stall = 1'b0; 50 | @REGS.N=1 51 | @REGS.0= 0 R_@$(DEVID) @$(DEVID) 52 | @BDEF.IONAME=_@$(PREFIX) 53 | @BDEF.IOTYPE=unsigned 54 | @BDEF.OSDEF=_BOARD_HAS_@$(DEVID) 55 | @BDEF.OSVAL=static volatile @$BDEF.IOTYPE *const @$BDEF.IONAME = ((@$BDEF.IOTYPE *)@$[0x%08x](REGBASE)); 56 | ## 57 | ## 58 | ## 59 | @PREFIX=buildtime 60 | @DEVID=BUILDTIME 61 | @NADDR=1 62 | @SLAVE.TYPE=SINGLE 63 | @SLAVE.BUS=wb 64 | @MAIN.DEFNS= 65 | // BUILDTIME doesnt need to include builddate.v a second time 66 | // `include "builddate.v" 67 | @MAIN.INSERT= 68 | assign @$(SLAVE.PREFIX)_idata = `BUILDTIME; 69 | assign @$(SLAVE.PREFIX)_ack = @$(SLAVE.PREFIX)_stb; 70 | assign @$(SLAVE.PREFIX)_stall = 1'b0; 71 | @REGS.N=1 72 | @REGS.0= 0 R_@$(DEVID) @$(DEVID) 73 | @BDEF.IONAME=_@$(PREFIX) 74 | @BDEF.IOTYPE=unsigned 75 | @BDEF.OSDEF=_BOARD_HAS_@$(DEVID) 76 | @BDEF.OSVAL=static volatile @$BDEF.IOTYPE *const @$BDEF.IONAME = ((@$.BDEF.IOTYPE *)@$[0x%08x](REGBASE)); 77 | -------------------------------------------------------------------------------- /auto-data/buserr.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | ## 3 | ## Filename: buserr.txt 4 | ## 5 | ## Project: AutoFPGA, a utility for composing FPGA designs from peripherals 6 | ## 7 | ## Purpose: Provide a readable memory location containing the address of the 8 | ## last bus error. 9 | ## 10 | ## Creator: Dan Gisselquist, Ph.D. 11 | ## Gisselquist Technology, LLC 12 | ## 13 | ################################################################################ 14 | ## 15 | ## Copyright (C) 2017-2020, Gisselquist Technology, LLC 16 | ## 17 | ## This program is free software (firmware): you can redistribute it and/or 18 | ## modify it under the terms of the GNU General Public License as published 19 | ## by the Free Software Foundation, either version 3 of the License, or (at 20 | ## your option) any later version. 21 | ## 22 | ## This program is distributed in the hope that it will be useful, but WITHOUT 23 | ## ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 24 | ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 25 | ## for more details. 26 | ## 27 | ## You should have received a copy of the GNU General Public License along 28 | ## with this program. (It's in the $(ROOT)/doc directory. Run make with no 29 | ## target there if the PDF file isn't present.) If not, see 30 | ## for a copy. 31 | ## 32 | ## License: GPL, v3, as defined and found on www.gnu.org, 33 | ## http://www.gnu.org/licenses/gpl.html 34 | ## 35 | ## 36 | ################################################################################ 37 | ## 38 | ## 39 | @PREFIX=buserr 40 | @NADDR=1 41 | @SLAVE.TYPE=SINGLE 42 | @SLAVE.BUS=wb 43 | @SINGLE.INPUT= r_bus_err 44 | @CLOCK.NAME=clk 45 | @$RWID=(@$(zip.MASTER.BUS.AWID) > @$(wbu.MASTER.BUS.AWID)) ? @$(zip.MASTER.BUS.AWID) : @$(wbu.MASTER.BUS.AWID) 46 | @MAIN.DEFNS= 47 | reg [@$(RWID)-1:0] r_@$(PREFIX)_addr; 48 | @MAIN.INSERT= 49 | always @(posedge @$(CLOCK.WIRE)) 50 | if (@$(zip.MASTER.PREFIX)_err) 51 | begin 52 | r_@$(PREFIX)_addr <= 0; 53 | r_@$(PREFIX)_addr[@$(zip.MASTER.BUS.AWID)-1:0] <= @$(zip.MASTER.PREFIX)_addr[@$(zip.MASTER.BUS.AWID)-1:0]; 54 | end else if (@$(wbu.MASTER.PREFIX)_err) 55 | begin 56 | r_@$(PREFIX)_addr <= 0; 57 | r_@$(PREFIX)_addr[@$(wbu.MASTER.BUS.AWID)-1:0] <= @$(wbu.MASTER.PREFIX)_addr[@$(wbu.MASTER.BUS.AWID)-1:0]; 58 | end 59 | assign @$(SLAVE.PREFIX)_stall= 1'b0; 60 | assign @$(SLAVE.PREFIX)_ack = @$(SLAVE.PREFIX)_stb; 61 | assign @$(SLAVE.PREFIX)_idata = { {(30-@$(RWID)){1'b0}}, 62 | r_@$(PREFIX)_addr, 2'b00 }; 63 | @REGS.N=1 64 | @REGS.0= 0 R_BUSERR BUSERR 65 | @BDEF.IONAME=io_buserr 66 | @BDEF.IOTYPE=unsigned 67 | @BDEF.OSDEF=_BOARD_HAS_BUSERR 68 | @BDEF.OSVAL=static volatile @$THIS.BDEF.IOTYPE *const _buserr = ((@$THIS.BDEF.IOTYPE *)@$[0x%08x](REGBASE)); 69 | -------------------------------------------------------------------------------- /auto-data/mem_flash_bkram.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | ## 3 | ## Filename: mem_flash_bkram.txt 4 | ## 5 | ## Project: ZBasic, a generic toplevel impl using the full ZipCPU 6 | ## 7 | ## Purpose: Describes a memory model containing nothing more than flash 8 | ## and block RAM. This will be used to create a board.ld linker 9 | ## script that can be used to link ZipCPU programs. 10 | ## 11 | ## 12 | ## Creator: Dan Gisselquist, Ph.D. 13 | ## Gisselquist Technology, LLC 14 | ## 15 | ################################################################################ 16 | ## 17 | ## Copyright (C) 2017-2020, Gisselquist Technology, LLC 18 | ## 19 | ## This program is free software (firmware): you can redistribute it and/or 20 | ## modify it under the terms of the GNU General Public License as published 21 | ## by the Free Software Foundation, either version 3 of the License, or (at 22 | ## your option) any later version. 23 | ## 24 | ## This program is distributed in the hope that it will be useful, but WITHOUT 25 | ## ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 26 | ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 27 | ## for more details. 28 | ## 29 | ## You should have received a copy of the GNU General Public License along 30 | ## with this program. (It's in the $(ROOT)/doc directory. Run make with no 31 | ## target there if the PDF file isn't present.) If not, see 32 | ## for a copy. 33 | ## 34 | ## License: GPL, v3, as defined and found on www.gnu.org, 35 | ## http://www.gnu.org/licenses/gpl.html 36 | ## 37 | ## 38 | ################################################################################ 39 | ## 40 | ## 41 | ## 42 | @PREFIX=mem_flash_bkram 43 | @MASTER.TYPE=SCRIPT 44 | @MASTER.BUS=wb 45 | @LD.FILE=board.ld 46 | @LD.DEFNS= 47 | /* LD.DEFNS from zipmaster.txt */ 48 | _kram = 0; /* No high-speed kernel RAM */ 49 | _ram = ORIGIN(bkram); 50 | _rom = ORIGIN(flash); 51 | _top_of_stack = ORIGIN(bkram) + LENGTH(bkram); 52 | 53 | @LD.SCRIPT= 54 | /* LD.SCRIPT from zipmaster.txt */ 55 | SECTIONS 56 | { 57 | .rocode @$[0x%08x](zip.RESET_ADDRESS) : ALIGN(4) { 58 | _boot_address = .; 59 | *(.start) *(.boot) 60 | } > flash 61 | _kram_start = . ; 62 | _kram_end = . ; 63 | _ram_image_start = . ; 64 | .kernel : ALIGN_WITH_INPUT { 65 | *(.kernel) 66 | *(.text.startup) 67 | *(.text*) 68 | *(.rodata*) *(.strings) 69 | *(.data) *(COMMON) 70 | }> bkram AT> flash 71 | _ram_image_end = . ; 72 | .bss : ALIGN_WITH_INPUT { 73 | *(.bss) 74 | _bss_image_end = . ; 75 | } > bkram 76 | _top_of_heap = .; 77 | } 78 | # 79 | -------------------------------------------------------------------------------- /auto-data/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | ## 3 | ## Filename: auto-data/Makefile 4 | ## 5 | ## Project: ZBasic, a generic toplevel impl using the full ZipCPU 6 | ## 7 | ## Purpose: To direct the build of the autofpga automatically generated 8 | ## files. The various configuration files are the *.txt files 9 | ## found in this directory. 10 | ## 11 | ## 12 | ## Creator: Dan Gisselquist, Ph.D. 13 | ## Gisselquist Technology, LLC 14 | ## 15 | ################################################################################ 16 | ## 17 | ## Copyright (C) 2017-2020, Gisselquist Technology, LLC 18 | ## 19 | ## This program is free software (firmware): you can redistribute it and/or 20 | ## modify it under the terms of the GNU General Public License as published 21 | ## by the Free Software Foundation, either version 3 of the License, or (at 22 | ## your option) any later version. 23 | ## 24 | ## This program is distributed in the hope that it will be useful, but WITHOUT 25 | ## ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 26 | ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 27 | ## for more details. 28 | ## 29 | ## You should have received a copy of the GNU General Public License along 30 | ## with this program. (It's in the $(ROOT)/doc directory. Run make with no 31 | ## target there if the PDF file isn't present.) If not, see 32 | ## for a copy. 33 | ## 34 | ## License: GPL, v3, as defined and found on www.gnu.org, 35 | ## http://www.gnu.org/licenses/gpl.html 36 | ## 37 | ## 38 | ################################################################################ 39 | ## 40 | ## 41 | .PHONY: all 42 | all: data 43 | # 44 | # Could also depend upon load, if desired, but not necessary 45 | # 46 | # This is the list of components that will form our project. Each file consists 47 | # of parts and pieces of our project that autofpga will copy/paste into our 48 | # main project files. 49 | # 50 | BASE := global.txt # dlyarbiter.txt 51 | AUX := version.txt buserr.txt pic.txt pwrcount.txt 52 | IO := gpio.txt # spio.txt 53 | RTC := rtclight.txt rtcdate.txt 54 | DBGBUS := busconsole.txt 55 | MEMORY := bkram.txt flash.txt 56 | CPU := zipmaster.txt # profile.txt 57 | NETWORK := # mdio.txt enet.txt 58 | SDCARD := sdspi.txt 59 | SCOPES := # flashscope.txt cpuscope.txt 60 | LDSCRIPT:= mem_flash_bkram.txt mem_bkram_only.txt 61 | DATA := clock.txt $(BASE) $(AUX) $(IO) $(RTC) \ 62 | $(DBGBUS) $(MEMORY) $(CPU) $(NETWORK) $(SDCARD) \ 63 | $(SCOPES) $(LDSCRIPT) 64 | 65 | AUTOFPGA := autofpga 66 | $(AUTOFPGA): 67 | 68 | .PHONY: data 69 | data: $(AUTOFPGA) $(DATA) 70 | $(AUTOFPGA) -d -o . $(DATA) 71 | 72 | clean: 73 | rm -f toplevel.v main.v regdefs.h regdefs.cpp board.h board.ld 74 | rm -f rtl.make.inc main_tb.cpp 75 | rm -f dump.txt 76 | -------------------------------------------------------------------------------- /sw/zlib/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | ## 3 | ## Filename: Makefile 4 | ## 5 | ## Project: ZBasic, a generic toplevel impl using the full ZipCPU 6 | ## 7 | ## Purpose: To guide/direct the build of the board-specific portion of 8 | ## newlib. 9 | ## 10 | ## Targets: 11 | ## 12 | ## Creator: Dan Gisselquist, Ph.D. 13 | ## Gisselquist Technology, LLC 14 | ## 15 | ################################################################################ 16 | ## 17 | ## Copyright (C) 2017-2020, Gisselquist Technology, LLC 18 | ## 19 | ## This program is free software (firmware): you can redistribute it and/or 20 | ## modify it under the terms of the GNU General Public License as published 21 | ## by the Free Software Foundation, either version 3 of the License, or (at 22 | ## your option) any later version. 23 | ## 24 | ## This program is distributed in the hope that it will be useful, but WITHOUT 25 | ## ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 26 | ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 27 | ## for more details. 28 | ## 29 | ## You should have received a copy of the GNU General Public License along 30 | ## with this program. (It's in the $(ROOT)/doc directory. Run make with no 31 | ## target there if the PDF file isn't present.) If not, see 32 | ## for a copy. 33 | ## 34 | ## License: GPL, v3, as defined and found on www.gnu.org, 35 | ## http://www.gnu.org/licenses/gpl.html 36 | ## 37 | ## 38 | ################################################################################ 39 | ## 40 | ## 41 | CC := zip-gcc 42 | AR := zip-ar 43 | OBJDIR := obj-zip 44 | INCS := -I. -I../../rtl 45 | CFLAGS := -O3 $(INCS) 46 | LIBSRCS := udiv.c umod.c syscalls.c crt0.c 47 | LIBOBJS := $(addprefix $(OBJDIR)/,$(subst .c,.o,$(LIBSRCS))) 48 | ZIPLIB := libzbasic.a 49 | all: $(ZIPLIB) 50 | 51 | $(OBJDIR)/%.o: %.c 52 | $(mk-objdir) 53 | $(CC) $(CFLAGS) -c $< -o $@ 54 | 55 | $(OBJDIR)/%.s: %.c 56 | $(mk-objdir) 57 | $(CC) $(CFLAGS) -fdump-rtl-all -S $< -o $@ 58 | 59 | $(OBJDIR)/crt0.o: crt0.c 60 | $(mk-objdir) 61 | $(CC) $(CFLAGS) -ffreestanding -c $< -o $@ 62 | 63 | $(ZIPLIB): $(LIBOBJS) 64 | $(AR) -cru $@ $(LIBOBJS) 65 | 66 | clean: 67 | rm -rf $(ZIPLIB) $(OBJDIR)/ 68 | 69 | define mk-objdir 70 | @bash -c "if [ ! -e $(OBJDIR) ]; then mkdir -p $(OBJDIR); fi" 71 | endef 72 | 73 | define build-depends 74 | @echo "Building dependency file(s)" 75 | $(mk-objdir) 76 | @$(CC) $(CFLAGS) -MM $(LIBSRCS) > $(OBJDIR)/xdepends.txt 77 | @sed -e 's/^.*.o: /$(OBJDIR)\/&/' < $(OBJDIR)/xdepends.txt > $(OBJDIR)/depends.txt 78 | @rm $(OBJDIR)/xdepends.txt 79 | endef 80 | 81 | tags: $(LIBSRCS) $(HEADERS) 82 | @echo "Generating tags" 83 | @ctags $(LIBSRCS) $(HEADERS) 84 | 85 | 86 | .PHONY: depends 87 | depends: tags 88 | $(build-depends) 89 | 90 | $(OBJDIR)/depends.txt: $(SOURCES) $(HEADERS) 91 | $(build-depends) 92 | 93 | -include $(OBJDIR)/depends.txt 94 | -------------------------------------------------------------------------------- /doc/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | ## 3 | ## Filename: Makefile 4 | ## 5 | ## Project: ZBasic, a generic toplevel impl using the full ZipCPU 6 | ## 7 | ## Purpose: To coordinate the build of documentation PDFs from their 8 | ## LaTeX sources. 9 | ## 10 | ## Targets include: 11 | ## all Builds all documents 12 | ## 13 | ## gpl-3.0.pdf Builds the GPL license these files are released 14 | ## under. 15 | ## 16 | ## spec.pdf Builds the specification for the SDSPI 17 | ## controller. 18 | ## 19 | ## Creator: Dan Gisselquist, Ph.D. 20 | ## Gisselquist Technology, LLC 21 | ## 22 | ################################################################################ 23 | ## 24 | ## Copyright (C) 2015-2016, Gisselquist Technology, LLC 25 | ## 26 | ## This program is free software (firmware): you can redistribute it and/or 27 | ## modify it under the terms of the GNU General Public License as published 28 | ## by the Free Software Foundation, either version 3 of the License, or (at 29 | ## your option) any later version. 30 | ## 31 | ## This program is distributed in the hope that it will be useful, but WITHOUT 32 | ## ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 33 | ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 34 | ## for more details. 35 | ## 36 | ## You should have received a copy of the GNU General Public License along 37 | ## with this program. (It's in the $(ROOT)/doc directory. Run make with no 38 | ## target there if the PDF file isn't present.) If not, see 39 | ## for a copy. 40 | ## 41 | ## License: GPL, v3, as defined and found on www.gnu.org, 42 | ## http://www.gnu.org/licenses/gpl.html 43 | ## 44 | ## 45 | ################################################################################ 46 | ## 47 | ## 48 | all: gpl 49 | pdf: gpl 50 | DSRC := src 51 | 52 | .PHONY: gpl 53 | gpl: gpl-3.0.pdf 54 | 55 | gpl-3.0.pdf: $(DSRC)/gpl-3.0.tex 56 | latex $(DSRC)/gpl-3.0.tex 57 | latex $(DSRC)/gpl-3.0.tex 58 | dvips -q -z -t letter -P pdf -o gpl-3.0.ps gpl-3.0.dvi 59 | ps2pdf -dAutoRotatePages=/All gpl-3.0.ps gpl-3.0.pdf 60 | rm gpl-3.0.dvi gpl-3.0.log gpl-3.0.aux gpl-3.0.ps 61 | 62 | .PHONY: spec 63 | spec: spec.pdf 64 | 65 | spec.pdf: $(DSRC)/spec.tex $(DSRC)/gqtekspec.cls $(DSRC)/GT.eps 66 | cd $(DSRC)/; latex spec.tex 67 | cd $(DSRC)/; latex spec.tex 68 | cd $(DSRC)/; dvips -q -z -t letter -P pdf -o ../spec.ps spec.dvi 69 | ps2pdf -dAutoRotatePages=/All spec.ps spec.pdf 70 | -grep -i warning $(DSRC)/spec.log 71 | @rm -f $(DSRC)/spec.dvi $(DSRC)/spec.log 72 | @rm -f $(DSRC)/spec.aux $(DSRC)/spec.toc 73 | @rm -f $(DSRC)/spec.lot $(DSRC)/spec.lof 74 | @rm -f $(DSRC)/spec.out spec.ps 75 | 76 | .PHONY: clean 77 | clean: 78 | rm -f $(DSRC)/spec.dvi $(DSRC)/spec.log 79 | rm -f $(DSRC)/spec.aux $(DSRC)/spec.toc 80 | rm -f $(DSRC)/spec.lot $(DSRC)/spec.lof 81 | rm -f $(DSRC)/spec.out spec.ps spec.pdf 82 | rm -f gpl-3.0.pdf 83 | 84 | -------------------------------------------------------------------------------- /sim/verilated/vversion.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ################################################################################ 3 | ## 4 | ## Filename: vversion.sh 5 | ## 6 | ## Project: ZBasic, a generic toplevel impl using the full ZipCPU 7 | ## 8 | ## Purpose: To determine whether or not the verilator prefix for internal 9 | ## variables is v__DOT__ or the name of the top level followed by 10 | ## __DOT__. If it is the later, output -DNEW_VERILATOR, else be silent. 11 | ## 12 | ## 13 | ## Creator: Dan Gisselquist, Ph.D. 14 | ## Gisselquist Technology, LLC 15 | ## 16 | ################################################################################ 17 | ## 18 | ## Copyright (C) 2017-2018, Gisselquist Technology, LLC 19 | ## 20 | ## This program is free software (firmware): you can redistribute it and/or 21 | ## modify it under the terms of the GNU General Public License as published 22 | ## by the Free Software Foundation, either version 3 of the License, or (at 23 | ## your option) any later version. 24 | ## 25 | ## This program is distributed in the hope that it will be useful, but WITHOUT 26 | ## ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 27 | ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 28 | ## for more details. 29 | ## 30 | ## You should have received a copy of the GNU General Public License along 31 | ## with this program. (It's in the $(ROOT)/doc directory. Run make with no 32 | ## target there if the PDF file isn't present.) If not, see 33 | ## for a copy. 34 | ## 35 | ## License: GPL, v3, as defined and found on www.gnu.org, 36 | ## http://www.gnu.org/licenses/gpl.html 37 | ## 38 | ## 39 | ################################################################################ 40 | ## 41 | ## 42 | if [[ x${VERILATOR_ROOT} != "x" && -x ${VERILATOR_ROOT}/bin/verilator ]]; 43 | then 44 | export VERILATOR=${VERILATOR_ROOT}/bin/verilator 45 | fi 46 | if [[ ! -x ${VERILATOR} ]]; 47 | then 48 | export VERILATOR=verilator 49 | fi 50 | if [[ ! -x `which ${VERILATOR}` ]]; 51 | then 52 | echo "Verilator not found in environment or in path" 53 | exit -1 54 | fi 55 | 56 | VVERLINE=`${VERILATOR} -V | grep -i ^Verilator` 57 | VVER=`echo ${VVERLINE} | cut -d " " -f 2` 58 | LATER=`echo $VVER \>= 3.9 | bc` 59 | if [[ $LATER > 0 ]]; 60 | then 61 | RLATER=`echo $VVER \>= 4.2 | bc` 62 | if [[ $RLATER > 0 ]]; 63 | then 64 | ## I'm not quite certain when Verilator started requiring a further 65 | ## subreference through rootp-> and including the Vdesgin___024root.h 66 | ## include file. My best guess is that it is Verilator 4.2, but I don't 67 | ## know that for certain. What I do know is that on the development 68 | ## verrsion 4.211, it requires different semantics to peek at register 69 | ## names. This is our attempt to capture that dependency. 70 | echo "-DROOT_VERILATOR" 71 | else 72 | echo "-DNEW_VERILATOR" 73 | fi 74 | else 75 | echo "-DOLD_VERILATOR" 76 | fi 77 | exit 0 78 | -------------------------------------------------------------------------------- /auto-data/rtclight.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | ## 3 | ## Filename: rtclight.txt 4 | ## 5 | ## Project: AutoFPGA, a utility for composing FPGA designs from peripherals 6 | ## 7 | ## Purpose: 8 | ## 9 | ## Creator: Dan Gisselquist, Ph.D. 10 | ## Gisselquist Technology, LLC 11 | ## 12 | ################################################################################ 13 | ## 14 | ## Copyright (C) 2017-2020, Gisselquist Technology, LLC 15 | ## 16 | ## This program is free software (firmware): you can redistribute it and/or 17 | ## modify it under the terms of the GNU General Public License as published 18 | ## by the Free Software Foundation, either version 3 of the License, or (at 19 | ## your option) any later version. 20 | ## 21 | ## This program is distributed in the hope that it will be useful, but WITHOUT 22 | ## ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 23 | ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 24 | ## for more details. 25 | ## 26 | ## You should have received a copy of the GNU General Public License along 27 | ## with this program. (It's in the $(ROOT)/doc directory. Run make with no 28 | ## target there if the PDF file isn't present.) If not, see 29 | ## for a copy. 30 | ## 31 | ## License: GPL, v3, as defined and found on www.gnu.org, 32 | ## http://www.gnu.org/licenses/gpl.html 33 | ## 34 | ## 35 | ################################################################################ 36 | ## 37 | ## 38 | @PREFIX=rtc 39 | @DEVID=RTC 40 | @NADDR=8 41 | @SLAVE.TYPE=DOUBLE 42 | @SLAVE.BUS=wb 43 | @ACCESS=RTC_ACCESS 44 | @CLOCK.NAME=clk 45 | @CLKFREQHZ=@$(CLOCK.FREQUENCY) 46 | @$CLKSTEP=((1<<48)/@$(CLOCK.FREQUENCY)) 47 | @INT.RTC.WIRE=rtc_int 48 | @INT.RTC.PIC=altpic 49 | @MAIN.DEFNS= 50 | // This clock step is designed to match @$(CLOCK.FREQUENCY) Hz 51 | localparam [31:0] RTC_CLKSTEP = @$[32'h%08x](CLKSTEP); 52 | wire @$(PREFIX)_ppd; 53 | wire ck_pps; 54 | @MAIN.INSERT= 55 | rtclight #(.DEFAULT_SPEED(@$[32'h%x](CLKSTEP)), 56 | .OPT_TIMER(1'b1), 57 | .OPT_STOPWATCH(1'b1), 58 | .OPT_ALARM(1'b0), 59 | .OPT_FIXED_SPEED(1'b1)) 60 | the@$(PREFIX)(i_clk, i_reset, @$(SLAVE.PORTLIST), 61 | @$(PREFIX)_int, ck_pps, @$(PREFIX)_ppd); 62 | @MAIN.ALT= 63 | assign ck_pps = 1'b0; 64 | @REGS.NOTE= // RTC clock registers 65 | @REGS.N=5 66 | @REGS.0= 0 R_CLOCK CLOCK 67 | @REGS.1= 1 R_TIMER TIMER 68 | @REGS.2= 2 R_STOPWATCH STOPWATCH 69 | @REGS.3= 3 R_CKALARM ALARM CKALARM 70 | @REGS.4= 4 R_CKSPEED CKSPEED 71 | @BDEF.DEFN= 72 | typedef struct RTCLIGHT_S { 73 | unsigned r_clock, r_stopwatch, r_timer, r_alarm; 74 | } RTCLIGHT; 75 | @BDEF.IONAME=_rtc 76 | @BDEF.IOTYPE=RTCLIGHT 77 | @BDEF.OSDEF=_BOARD_HAS_RTC 78 | @BDEF.OSVAL=static volatile @$BDEF.IOTYPE *const @$(BDEF.IONAME) = ((@$BDEF.IOTYPE *)@$[0x%08x](REGBASE)); 79 | # 80 | # 81 | @RTL.MAKE.GROUP=@$(DEVID) 82 | @RTL.MAKE.SUBD=rtc 83 | @RTL.MAKE.FILES=rtclight.v rtcbare.v rtcalarm.v rtcstopwatch.v rtctimer.v 84 | ## 85 | ## 86 | -------------------------------------------------------------------------------- /sim/verilated/memsim.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: memsim.h 4 | // 5 | // Project: ZBasic, a generic toplevel impl using the full ZipCPU 6 | // 7 | // Purpose: This creates a memory like device to act on a WISHBONE bus. 8 | // It doesn't exercise the bus thoroughly, but does give some 9 | // exercise to the bus to see whether or not the bus master can control 10 | // it. 11 | // 12 | // This particular version differs from the memsim version within the 13 | // ZipCPU project in that there is a variable delay from request to 14 | // completion. 15 | // 16 | // 17 | // Creator: Dan Gisselquist, Ph.D. 18 | // Gisselquist Technology, LLC 19 | // 20 | //////////////////////////////////////////////////////////////////////////////// 21 | // 22 | // Copyright (C) 2015-2019, Gisselquist Technology, LLC 23 | // 24 | // This program is free software (firmware): you can redistribute it and/or 25 | // modify it under the terms of the GNU General Public License as published 26 | // by the Free Software Foundation, either version 3 of the License, or (at 27 | // your option) any later version. 28 | // 29 | // This program is distributed in the hope that it will be useful, but WITHOUT 30 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 31 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 32 | // for more details. 33 | // 34 | // You should have received a copy of the GNU General Public License along 35 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 36 | // target there if the PDF file isn't present.) If not, see 37 | // for a copy. 38 | // 39 | // License: GPL, v3, as defined and found on www.gnu.org, 40 | // http://www.gnu.org/licenses/gpl.html 41 | // 42 | // 43 | //////////////////////////////////////////////////////////////////////////////// 44 | // 45 | // 46 | #ifndef MEMSIM_H 47 | #define MEMSIM_H 48 | 49 | class MEMSIM { 50 | public: 51 | typedef unsigned int BUSW; 52 | typedef unsigned char uchar; 53 | 54 | BUSW *m_mem, m_len, m_mask, m_head, m_tail, m_delay_mask, m_delay; 55 | int *m_fifo_ack; 56 | BUSW *m_fifo_data; 57 | 58 | 59 | MEMSIM(const unsigned int nwords, const unsigned int delay=27); 60 | ~MEMSIM(void); 61 | void load(const char *fname); 62 | void load(const unsigned int addr, const char *buf,const size_t len); 63 | void apply(const uchar wb_cyc, const uchar wb_stb, 64 | const uchar wb_we, 65 | const BUSW wb_addr, const BUSW wb_data, 66 | const uchar wb_sel, 67 | uchar &o_ack, uchar &o_stall, BUSW &o_data); 68 | void operator()(const uchar wb_cyc, const uchar wb_stb, 69 | const uchar wb_we, 70 | const BUSW wb_addr, const BUSW wb_data, 71 | const uchar wb_sel, 72 | uchar &o_ack, uchar &o_stall, BUSW &o_data) { 73 | apply(wb_cyc, wb_stb, wb_we, wb_addr, wb_data, wb_sel, o_ack, o_stall, o_data); 74 | } 75 | BUSW &operator[](const BUSW addr) { return m_mem[addr&m_mask]; } 76 | }; 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /auto-data/bkram.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | ## 3 | ## Filename: bkram.txt 4 | ## 5 | ## Project: AutoFPGA, a utility for composing FPGA designs from peripherals 6 | ## 7 | ## Purpose: To define the interface to a generic block RAM device for the 8 | ## purposes of autofpga. 9 | ## 10 | ## Creator: Dan Gisselquist, Ph.D. 11 | ## Gisselquist Technology, LLC 12 | ## 13 | ################################################################################ 14 | ## 15 | ## Copyright (C) 2017-2020, Gisselquist Technology, LLC 16 | ## 17 | ## This program is free software (firmware): you can redistribute it and/or 18 | ## modify it under the terms of the GNU General Public License as published 19 | ## by the Free Software Foundation, either version 3 of the License, or (at 20 | ## your option) any later version. 21 | ## 22 | ## This program is distributed in the hope that it will be useful, but WITHOUT 23 | ## ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 24 | ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 25 | ## for more details. 26 | ## 27 | ## You should have received a copy of the GNU General Public License along 28 | ## with this program. (It's in the $(ROOT)/doc directory. Run make with no 29 | ## target there if the PDF file isn't present.) If not, see 30 | ## for a copy. 31 | ## 32 | ## License: GPL, v3, as defined and found on www.gnu.org, 33 | ## http://www.gnu.org/licenses/gpl.html 34 | ## 35 | ## 36 | ################################################################################ 37 | ## 38 | ## 39 | @PREFIX=bkram 40 | @DEVID=BKRAM 41 | @$LGMEMSZ=20 42 | @LGMEMSZ.FORMAT=%d 43 | @$NADDR=(1<<(@$THIS.LGMEMSZ-2)) 44 | @$NBYTES=(1<<(@$THIS.LGMEMSZ)) 45 | @NBYTES.FORMAT=0x%08x 46 | @ACCESS=@$(DEVID)_ACCESS 47 | @SLAVE.TYPE=MEMORY 48 | @SLAVE.BUS=wb 49 | @MAIN.INSERT= 50 | memdev #(.LGMEMSZ(@$THIS.LGMEMSZ), .EXTRACLOCK(1)) 51 | @$(PREFIX)i(i_clk, i_reset, 52 | @$(SLAVE.PORTLIST)); 53 | @REGS.N=1 54 | @REGS.0= 0 R_@$(DEVID) RAM 55 | @REGDEFS.H.DEFNS= 56 | #define @$(DEVID)BASE @$[0x%08x](REGBASE) 57 | #define @$(DEVID)LEN @$NBYTES 58 | @BDEF.OSDEF=_BOARD_HAS_@$(DEVID) 59 | @MEM.NAME= @$(PREFIX) 60 | @BDEF.OSVAL=extern char _@$(MEM.NAME)[@$NBYTES]; 61 | @LD.PERM= wx 62 | @LD.NAME= @$(MEM.NAME) 63 | @RTL.MAKE.GROUP= @$(DEVID) 64 | @RTL.MAKE.FILES= memdev.v 65 | @$NADDRHX = @$NADDR 66 | @NADDRHX.FORMAT= 0x%x 67 | @SIM.INCLUDE= 68 | #include "byteswap.h" 69 | @SIM.DEFINES= 70 | #ifndef VVAR 71 | #ifdef NEW_VERILATOR 72 | #define VVAR(A) main__DOT_ ## A 73 | #else 74 | #define VVAR(A) v__DOT_ ## A 75 | #endif 76 | #endif 77 | 78 | #define block_ram VVAR(_@$(PREFIX)i__DOT__mem) 79 | @SIM.LOAD= 80 | start = start & (-4); 81 | wlen = (wlen+3)&(-4); 82 | 83 | // Need to byte swap data to get it into the memory 84 | char *bswapd = new char[len+8]; 85 | memcpy(bswapd, &buf[offset], wlen); 86 | byteswapbuf(len>>2, (uint32_t *)bswapd); 87 | memcpy(&m_core->block_ram[start], bswapd, wlen); 88 | delete bswapd; 89 | -------------------------------------------------------------------------------- /rtl/make.inc: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | ## 3 | ## Filename: ./rtl.make.inc 4 | ## 5 | ## Project: ZBasic, a generic toplevel implementation using the full ZipCPU 6 | ## 7 | ## DO NOT EDIT THIS FILE! 8 | ## Computer Generated: This file is computer generated by AUTOFPGA. DO NOT EDIT. 9 | ## DO NOT EDIT THIS FILE! 10 | ## 11 | ## CmdLine: autofpga autofpga -d -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 12 | ## 13 | ## Creator: Dan Gisselquist, Ph.D. 14 | ## Gisselquist Technology, LLC 15 | ## 16 | ################################################################################ 17 | ## 18 | ## Copyright (C) 2017-2020, Gisselquist Technology, LLC 19 | ## 20 | ## This program is free software (firmware): you can redistribute it and/or 21 | ## modify it under the terms of the GNU General Public License as published 22 | ## by the Free Software Foundation, either version 3 of the License, or (at 23 | ## your option) any later version. 24 | ## 25 | ## This program is distributed in the hope that it will be useful, but WITHOUT 26 | ## ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 27 | ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 28 | ## for more details. 29 | ## 30 | ## You should have received a copy of the GNU General Public License along 31 | ## with this program. (It's in the $(ROOT)/doc directory. Run make with no 32 | ## target there if the PDF file isn't present.) If not, see 33 | ## for a copy. 34 | ## 35 | ## License: GPL, v3, as defined and found on www.gnu.org, 36 | ## http://www.gnu.org/licenses/gpl.html 37 | ## 38 | ## 39 | ################################################################################ 40 | ## 41 | ## 42 | ZIPCPUD := cpu 43 | 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) 44 | BKRAM := memdev.v 45 | 46 | WBUBUSD := wbubus 47 | 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) 48 | SDSPID := sdspi 49 | SDSPI := $(addprefix $(SDSPID)/,sdspi.v llsdspi.v spicmd.v spirxdata.v spitxdata.v) 50 | RTCD := rtc 51 | RTC := $(addprefix $(RTCD)/,rtclight.v rtcbare.v rtcalarm.v rtcstopwatch.v rtctimer.v) 52 | CONSOLED := wbuart 53 | CONSOLE := $(addprefix $(CONSOLED)/,txuartlite.v rxuartlite.v ufifo.v) 54 | BUSPICD := cpu 55 | BUSPIC := $(addprefix $(BUSPICD)/,icontrol.v) 56 | RTCDATED := rtc 57 | RTCDATE := $(addprefix $(RTCDATED)/,rtcdate.v) 58 | GPIO := wbgpio.v 59 | 60 | FLASH := qflexpress.v 61 | 62 | VFLIST := main.v $(ZIPCPU) $(BKRAM) $(WBUBUS) $(SDSPI) $(RTC) $(CONSOLE) $(BUSPIC) $(RTCDATE) $(GPIO) $(FLASH) 63 | AUTOVDIRS := -y cpu -y wbubus -y sdspi -y rtc -y wbuart 64 | -------------------------------------------------------------------------------- /sw/host/byteswap.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: byteswap.h 4 | // 5 | // Project: ZBasic, a generic toplevel impl using the full ZipCPU 6 | // 7 | // Purpose: To convert between little endian and big endian byte orders, 8 | // and to handle conversions between character strings and 9 | // bit-endian words made from those characters. 10 | // 11 | // 12 | // Creator: Dan Gisselquist, Ph.D. 13 | // Gisselquist Technology, LLC 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | // 17 | // Copyright (C) 2015-2020, Gisselquist Technology, LLC 18 | // 19 | // This program is free software (firmware): you can redistribute it and/or 20 | // modify it under the terms of the GNU General Public License as published 21 | // by the Free Software Foundation, either version 3 of the License, or (at 22 | // your option) any later version. 23 | // 24 | // This program is distributed in the hope that it will be useful, but WITHOUT 25 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 26 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 27 | // for more details. 28 | // 29 | // You should have received a copy of the GNU General Public License along 30 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 31 | // target there if the PDF file isn't present.) If not, see 32 | // for a copy. 33 | // 34 | // License: GPL, v3, as defined and found on www.gnu.org, 35 | // http://www.gnu.org/licenses/gpl.html 36 | // 37 | // 38 | //////////////////////////////////////////////////////////////////////////////// 39 | // 40 | // 41 | #ifndef BYTESWAP_H 42 | #define BYTESWAP_H 43 | 44 | #include 45 | 46 | /* 47 | * The byte swapping routines below are designed to support conversions from a little endian 48 | * machine/host (such as my PC) to the big endian byte order used on the ZipCPU. If the current 49 | * machine is already little endian, no byte swapping is required. 50 | */ 51 | #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 52 | /* 53 | * byteswap 54 | * 55 | * Given a big (or little) endian word, return a little (or big) endian word. 56 | */ 57 | extern uint32_t 58 | byteswap(uint32_t v); 59 | 60 | /* 61 | * byteswapbuf 62 | * 63 | * To swap from the byte order of every 32-bit word in the given buffer. 64 | */ 65 | extern void byteswapbuf(int ln, uint32_t *buf); 66 | 67 | #else 68 | #define byteswap(A) (A) 69 | #define byteswapbuf(A, B) 70 | #endif 71 | 72 | /* 73 | * buildword 74 | * 75 | * Given a pointer within an array of characters, build a 32-bit big-endian 76 | * word from those characters. Does not require the character pointer to be 77 | * aligned. 78 | */ 79 | extern uint32_t buildword(const unsigned char *p); 80 | 81 | /* 82 | * buildswap 83 | * 84 | * Same as buildword, except that we build a little endian word from the 85 | * characters given to us. Hence the first character is the low order octet 86 | * of the word. 87 | */ 88 | extern uint32_t buildswap(const unsigned char *p); 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /sim/verilated/byteswap.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: byteswap.h 4 | // 5 | // Project: ZBasic, a generic toplevel impl using the full ZipCPU 6 | // 7 | // Purpose: To convert between little endian and big endian byte orders, 8 | // and to handle conversions between character strings and 9 | // bit-endian words made from those characters. 10 | // 11 | // 12 | // Creator: Dan Gisselquist, Ph.D. 13 | // Gisselquist Technology, LLC 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | // 17 | // Copyright (C) 2015-2019, Gisselquist Technology, LLC 18 | // 19 | // This program is free software (firmware): you can redistribute it and/or 20 | // modify it under the terms of the GNU General Public License as published 21 | // by the Free Software Foundation, either version 3 of the License, or (at 22 | // your option) any later version. 23 | // 24 | // This program is distributed in the hope that it will be useful, but WITHOUT 25 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 26 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 27 | // for more details. 28 | // 29 | // You should have received a copy of the GNU General Public License along 30 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 31 | // target there if the PDF file isn't present.) If not, see 32 | // for a copy. 33 | // 34 | // License: GPL, v3, as defined and found on www.gnu.org, 35 | // http://www.gnu.org/licenses/gpl.html 36 | // 37 | // 38 | //////////////////////////////////////////////////////////////////////////////// 39 | // 40 | // 41 | #ifndef BYTESWAP_H 42 | #define BYTESWAP_H 43 | 44 | #include 45 | 46 | /* 47 | * The byte swapping routines below are designed to support conversions from a little endian 48 | * machine/host (such as my PC) to the big endian byte order used on the ZipCPU. If the current 49 | * machine is already little endian, no byte swapping is required. 50 | */ 51 | #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 52 | /* 53 | * byteswap 54 | * 55 | * Given a big (or little) endian word, return a little (or big) endian word. 56 | */ 57 | extern uint32_t 58 | byteswap(uint32_t v); 59 | 60 | /* 61 | * byteswapbuf 62 | * 63 | * To swap from the byte order of every 32-bit word in the given buffer. 64 | */ 65 | extern void byteswapbuf(int ln, uint32_t *buf); 66 | 67 | #else 68 | #define byteswap(A) (A) 69 | #define byteswapbuf(A, B) 70 | #endif 71 | 72 | /* 73 | * buildword 74 | * 75 | * Given a pointer within an array of characters, build a 32-bit big-endian 76 | * word from those characters. Does not require the character pointer to be 77 | * aligned. 78 | */ 79 | extern uint32_t buildword(const unsigned char *p); 80 | 81 | /* 82 | * buildswap 83 | * 84 | * Same as buildword, except that we build a little endian word from the 85 | * characters given to us. Hence the first character is the low order octet 86 | * of the word. 87 | */ 88 | extern uint32_t buildswap(const unsigned char *p); 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /rtl/wbubus/wbutohex.v: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: wbutohex.v 4 | // 5 | // Project: FPGA library 6 | // 7 | // Purpose: Supports a printable character conversion from a printable 8 | // ASCII character to six bits of valid data. The encoding is 9 | // as follows: 10 | // 11 | // 0-9 -> 0-9 12 | // A-Z -> 10-35 13 | // a-z -> 36-61 14 | // @ -> 62 15 | // % -> 63 16 | // 17 | // Note that decoding is stateless, yet requires one clock. 18 | // 19 | // 20 | // Creator: Dan Gisselquist, Ph.D. 21 | // Gisselquist Technology, LLC 22 | // 23 | //////////////////////////////////////////////////////////////////////////////// 24 | // 25 | // Copyright (C) 2015-2020, Gisselquist Technology, LLC 26 | // 27 | // This program is free software (firmware): you can redistribute it and/or 28 | // modify it under the terms of the GNU General Public License as published 29 | // by the Free Software Foundation, either version 3 of the License, or (at 30 | // your option) any later version. 31 | // 32 | // This program is distributed in the hope that it will be useful, but WITHOUT 33 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 34 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 35 | // for more details. 36 | // 37 | // You should have received a copy of the GNU General Public License along 38 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 39 | // target there if the PDF file isn't present.) If not, see 40 | // for a copy. 41 | // 42 | // License: GPL, v3, as defined and found on www.gnu.org, 43 | // http://www.gnu.org/licenses/gpl.html 44 | // 45 | // 46 | //////////////////////////////////////////////////////////////////////////////// 47 | // 48 | // 49 | `default_nettype none 50 | // 51 | module wbutohex(i_clk, i_stb, i_byte, o_stb, o_valid, o_hexbits); 52 | input wire i_clk, i_stb; 53 | input wire [7:0] i_byte; 54 | output reg o_stb, o_valid; 55 | output reg [5:0] o_hexbits; 56 | 57 | initial o_stb = 1'b0; 58 | always @(posedge i_clk) 59 | o_stb <= i_stb; 60 | 61 | reg [6:0] remap [0:127]; 62 | 63 | integer k; 64 | reg [6:0] newv; 65 | 66 | always @(*) 67 | // initial 68 | begin 69 | for(k=0; k<128; k=k+1) 70 | begin 71 | newv = 7'h40; 72 | // verilator lint_off WIDTH 73 | if ((k >= 48)&&(k <= 57)) // A digit 74 | begin 75 | newv = k; 76 | newv[6:4] = 3'b100; 77 | end else if ((k >= 65)&&(k <= 90)) // Upper case 78 | begin 79 | newv[5:0] = ((k&8'h3f) + 6'h09);// -'A'+10 80 | newv[6] = 1'b1; 81 | end else if ((k >= 97)&&(k <= 122)) 82 | newv[5:0] = ((k&8'h3f) + 6'h03); // -'a'+(10+26) 83 | // verilator lint_on WIDTH 84 | else if (k == 64) // An '@' sign 85 | newv[5:0] = 6'h3e; 86 | else if (k == 37) // A '%' sign 87 | newv[5:0] = 6'h3f; 88 | else 89 | newv = 0; 90 | 91 | remap[k] = newv; 92 | end 93 | end 94 | 95 | always @(posedge i_clk) 96 | begin 97 | { o_valid, o_hexbits } <= remap[i_byte[6:0]]; 98 | if (i_byte[7]) 99 | o_valid <= 0; 100 | end 101 | 102 | 103 | endmodule 104 | 105 | -------------------------------------------------------------------------------- /sim/verilated/sdspisim.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: sdspisim.h 4 | // 5 | // Project: Wishbone Controlled SD-Card Controller over SPI port 6 | // 7 | // Purpose: This library simulates the operation of a SPI commanded SD-Card, 8 | // such as might be found on a XuLA2-LX25 board made by xess.com. 9 | // 10 | // This simulator is for testing use in a Verilator/C++ environment, where 11 | // it would be used in place of the actual hardware. 12 | // 13 | // Creator: Dan Gisselquist, Ph.D. 14 | // Gisselquist Technology, LLC 15 | // 16 | //////////////////////////////////////////////////////////////////////////////// 17 | // 18 | // Copyright (C) 2015-2019, Gisselquist Technology, LLC 19 | // 20 | // This program is free software (firmware): you can redistribute it and/or 21 | // modify it under the terms of the GNU General Public License as published 22 | // by the Free Software Foundation, either version 3 of the License, or (at 23 | // your option) any later version. 24 | // 25 | // This program is distributed in the hope that it will be useful, but WITHOUT 26 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 27 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 28 | // for more details. 29 | // 30 | // You should have received a copy of the GNU General Public License along 31 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 32 | // target there if the PDF file isn't present.) If not, see 33 | // for a copy. 34 | // 35 | // License: GPL, v3, as defined and found on www.gnu.org, 36 | // http://www.gnu.org/licenses/gpl.html 37 | // 38 | // 39 | //////////////////////////////////////////////////////////////////////////////// 40 | // 41 | // 42 | #ifndef SDSPISIM_H 43 | #define SDSPISIM_H 44 | 45 | typedef enum eRESET_STATES { 46 | SDSPI_POWERUP_RESET, 47 | SDSPI_CMD0_IDLE, 48 | SDSPI_RCVD_CMD8, 49 | SDSPI_RCVD_ACMD41, 50 | SDSPI_RESET_COMPLETE, 51 | SDSPI_IN_OPERATION 52 | } RESET_STATES; 53 | 54 | #define SDSPI_RSPLEN 8 55 | #define SDSPI_MAXBLKLEN (1+2048+2) 56 | #define SDSPI_CSDLEN (16) 57 | #define SDSPI_CIDLEN (16) 58 | class SDSPISIM { 59 | FILE *m_dev; 60 | unsigned long m_devblocks; 61 | 62 | int m_last_sck, m_delay, m_mosi; 63 | bool m_busy, m_debug, m_block_address, m_altcmd_flag, 64 | m_syncd, m_host_supports_high_capacity, m_reading_data, 65 | m_have_token; 66 | 67 | RESET_STATES m_reset_state; 68 | 69 | int m_cmdidx, m_bitpos, m_rspidx, m_rspdly, m_blkdly, 70 | m_blklen, m_blkidx, m_last_miso, m_powerup_busy, 71 | m_rxloc; 72 | char m_cmdbuf[8], m_dat_out, m_dat_in; 73 | char m_rspbuf[SDSPI_RSPLEN]; 74 | char m_block_buf[SDSPI_MAXBLKLEN]; 75 | char m_csd[SDSPI_CSDLEN], m_cid[SDSPI_CIDLEN]; 76 | 77 | public: 78 | SDSPISIM(const bool debug = false); 79 | void load(const char *fname); 80 | void debug(const bool dbg) { m_debug = dbg; } 81 | bool debug(void) const { return m_debug; } 82 | int operator()(const int csn, const int sck, const int dat); 83 | unsigned cmdcrc(int ln, char *buf) const; 84 | bool check_cmdcrc(char *buf) const; 85 | unsigned blockcrc(int ln, char *buf) const; 86 | void add_block_crc(int ln, char *buf) const; 87 | }; 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /rtl/wbubus/wbusixchar.v: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: wbusixchar.v 4 | // 5 | // Project: FPGA library 6 | // 7 | // Purpose: Supports a conversion from a six digit bus to a printable 8 | // ASCII character representing those six bits. The encoding is 9 | // as follows: 10 | // 11 | // 0-9 -> 0-9 12 | // A-Z -> 10-35 13 | // a-z -> 36-61 14 | // @ -> 62 15 | // % -> 63 16 | // 17 | // Note that decoding is stateless, yet requires one clock. 18 | // 19 | // 20 | // Creator: Dan Gisselquist, Ph.D. 21 | // Gisselquist Technology, LLC 22 | // 23 | //////////////////////////////////////////////////////////////////////////////// 24 | // 25 | // Copyright (C) 2015-2020, Gisselquist Technology, LLC 26 | // 27 | // This program is free software (firmware): you can redistribute it and/or 28 | // modify it under the terms of the GNU General Public License as published 29 | // by the Free Software Foundation, either version 3 of the License, or (at 30 | // your option) any later version. 31 | // 32 | // This program is distributed in the hope that it will be useful, but WITHOUT 33 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 34 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 35 | // for more details. 36 | // 37 | // You should have received a copy of the GNU General Public License along 38 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 39 | // target there if the PDF file isn't present.) If not, see 40 | // for a copy. 41 | // 42 | // License: GPL, v3, as defined and found on www.gnu.org, 43 | // http://www.gnu.org/licenses/gpl.html 44 | // 45 | // 46 | //////////////////////////////////////////////////////////////////////////////// 47 | // 48 | // 49 | `default_nettype none 50 | // 51 | module wbusixchar(i_clk, i_stb, i_bits, o_stb, o_char, o_busy, i_busy); 52 | input wire i_clk; 53 | input wire i_stb; 54 | input wire [6:0] i_bits; 55 | output reg o_stb; 56 | output reg [7:0] o_char; 57 | output wire o_busy; 58 | input wire i_busy; 59 | 60 | initial o_stb = 1'b0; 61 | always @(posedge i_clk) 62 | if (!o_stb || !i_busy) 63 | o_stb <= i_stb; 64 | 65 | reg [6:0] remap [0:127]; 66 | reg [6:0] newv; 67 | 68 | integer k; 69 | always @(*) begin 70 | for(k=0; k<128; k=k+1) 71 | begin 72 | newv = 0; 73 | // verilator lint_off WIDTH 74 | // `define BROKEN_CODE 75 | `ifdef BROKEN_CODE 76 | if (k[6]) 77 | `else 78 | if (k >= 64) 79 | `endif 80 | newv = 7'h0a; 81 | else if (k <= 6'h09) // A digit, WORKS 82 | newv = "0" + { 3'h0, k[3:0] }; 83 | else if (k[5:0] <= 6'd35) // Upper case 84 | newv[6:0] = 7'h41 + { 1'h0, k[5:0] } - 7'd10; // -'A'+10 85 | else if (k[5:0] <= 6'd61) 86 | newv = 7'h61 + { 1'h0, k[5:0] } - 7'd36;// -'a'+(10+26) 87 | // verilator lint_on WIDTH 88 | else if (k[5:0] == 6'd62) // An '@' sign 89 | newv = 7'h40; 90 | else // if (i_char == 6'h63) // A '%' sign 91 | newv = 7'h25; 92 | 93 | remap[k] = newv; 94 | end 95 | end 96 | 97 | initial o_char = 8'h00; 98 | always @(posedge i_clk) 99 | if (!o_busy) 100 | o_char <= { 1'b0, remap[i_bits] }; 101 | 102 | assign o_busy = o_stb; 103 | 104 | endmodule 105 | 106 | -------------------------------------------------------------------------------- /sw/host/byteswap.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: byteswap.cpp 4 | // 5 | // Project: ZBasic, a generic toplevel impl using the full ZipCPU 6 | // 7 | // Purpose: To convert between little endian and big endian byte orders, 8 | // and to handle conversions between character strings and 9 | // bit-endian words made from those characters. 10 | // 11 | // 12 | // Creator: Dan Gisselquist, Ph.D. 13 | // Gisselquist Technology, LLC 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | // 17 | // Copyright (C) 2015-2020, Gisselquist Technology, LLC 18 | // 19 | // This program is free software (firmware): you can redistribute it and/or 20 | // modify it under the terms of the GNU General Public License as published 21 | // by the Free Software Foundation, either version 3 of the License, or (at 22 | // your option) any later version. 23 | // 24 | // This program is distributed in the hope that it will be useful, but WITHOUT 25 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 26 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 27 | // for more details. 28 | // 29 | // You should have received a copy of the GNU General Public License along 30 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 31 | // target there if the PDF file isn't present.) If not, see 32 | // for a copy. 33 | // 34 | // License: GPL, v3, as defined and found on www.gnu.org, 35 | // http://www.gnu.org/licenses/gpl.html 36 | // 37 | // 38 | //////////////////////////////////////////////////////////////////////////////// 39 | // 40 | // 41 | #include 42 | #include "byteswap.h" 43 | 44 | /* 45 | * byteswap 46 | * 47 | * Given a big (or little) endian word, return a little (or big) endian word. 48 | */ 49 | uint32_t 50 | byteswap(uint32_t v) { 51 | uint32_t r = 0; 52 | 53 | r = (v & 0x0ff); 54 | r <<= 8; v >>= 8; 55 | r |= (v & 0x0ff); 56 | r <<= 8; v >>= 8; 57 | r |= (v & 0x0ff); 58 | r <<= 8; v >>= 8; 59 | r |= (v & 0x0ff); 60 | 61 | return r; 62 | } 63 | 64 | 65 | /* 66 | * byteswapbuf 67 | * 68 | * To swap from the byte order of every 32-bit word in the given buffer. 69 | */ 70 | void 71 | byteswapbuf(int ln, uint32_t *buf) { 72 | for(int i=0; i for a copy. 31 | // 32 | // License: GPL, v3, as defined and found on www.gnu.org, 33 | // http://www.gnu.org/licenses/gpl.html 34 | // 35 | // 36 | //////////////////////////////////////////////////////////////////////////////// 37 | // 38 | // 39 | #ifndef ZIPCPU_H 40 | #define ZIPCPU_H 41 | 42 | #define CC_Z 0x0001 43 | #define CC_C 0x0002 44 | #define CC_N 0x0004 45 | #define CC_V 0x0008 46 | #define CC_SLEEP 0x0010 47 | #define CC_GIE 0x0020 48 | #define CC_STEP 0x0040 49 | #define CC_BREAK 0x0080 50 | #define CC_ILL 0x0100 51 | #define CC_TRAP 0x0200 52 | #define CC_BUSERR 0x0400 53 | #define CC_DIVERR 0x0800 54 | #define CC_FPUERR 0x1000 55 | #define CC_IPHASE 0x2000 56 | #define CC_MMUERR 0x8000 57 | #define CC_FAULT (CC_ILL|CC_BUSERR|CC_DIVERR|CC_FPUERR) 58 | #define CC_EXCEPTION (CC_BREAK|CC_FAULT|CC_MMUERR) 59 | 60 | #define CLEAR_ICACHE asm("OR 16384,CC") 61 | #define CLEAR_DCACHE asm("OR 32768,CC") 62 | #define CLEAR_CACHE asm("OR 49152,CC") 63 | 64 | // extern void zip_break(void); 65 | #define zip_break() asm("BREAK\n") 66 | // #define BREAK(ID) asm("BREAK " ##ID "\n") 67 | #define GETUREG(A,ID) asm("MOV " ID ",%0" : "=r"(A)) 68 | #define SETUREG(A,ID) asm("MOV %0," ID : : "r"(A)) 69 | #define NSTR(A) asm("NSTR \"" A "\\n\"") 70 | #define NVAL(V) do { unsigned tmp = (unsigned)(V); asm volatile("NDUMP %0":"=r"(tmp):"0"(tmp)); } while(0) 71 | extern void zip_rtu(void); 72 | extern void zip_halt(void); 73 | extern void zip_idle(void); 74 | extern void zip_syscall(void); 75 | extern void zip_restore_context(void *); 76 | extern void zip_save_context(void *); 77 | extern int zip_bitrev(int v); 78 | extern unsigned zip_cc(void); 79 | extern unsigned zip_ucc(void); 80 | 81 | extern void save_context(int *); 82 | extern void restore_context(int *); 83 | extern int syscall(int,int,int,int); 84 | 85 | #ifndef NULL 86 | #define NULL ((void *)0) 87 | #endif 88 | 89 | #define ASMFNSTR(A) "\t.section\t.text\n\t.global\t" A "\n\t.type\t" A ",@function\n" A ":\n" 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /sim/verilated/byteswap.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: byteswap.cpp 4 | // 5 | // Project: ZBasic, a generic toplevel impl using the full ZipCPU 6 | // 7 | // Purpose: To convert between little endian and big endian byte orders, 8 | // and to handle conversions between character strings and 9 | // bit-endian words made from those characters. 10 | // 11 | // 12 | // Creator: Dan Gisselquist, Ph.D. 13 | // Gisselquist Technology, LLC 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | // 17 | // Copyright (C) 2015-2019, Gisselquist Technology, LLC 18 | // 19 | // This program is free software (firmware): you can redistribute it and/or 20 | // modify it under the terms of the GNU General Public License as published 21 | // by the Free Software Foundation, either version 3 of the License, or (at 22 | // your option) any later version. 23 | // 24 | // This program is distributed in the hope that it will be useful, but WITHOUT 25 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 26 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 27 | // for more details. 28 | // 29 | // You should have received a copy of the GNU General Public License along 30 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 31 | // target there if the PDF file isn't present.) If not, see 32 | // for a copy. 33 | // 34 | // License: GPL, v3, as defined and found on www.gnu.org, 35 | // http://www.gnu.org/licenses/gpl.html 36 | // 37 | // 38 | //////////////////////////////////////////////////////////////////////////////// 39 | // 40 | // 41 | #include 42 | #include "byteswap.h" 43 | 44 | /* 45 | * byteswap 46 | * 47 | * Given a big (or little) endian word, return a little (or big) endian word. 48 | */ 49 | uint32_t 50 | byteswap(uint32_t v) { 51 | uint32_t r = 0; 52 | 53 | r = (v & 0x0ff); 54 | r <<= 8; v >>= 8; 55 | r |= (v & 0x0ff); 56 | r <<= 8; v >>= 8; 57 | r |= (v & 0x0ff); 58 | r <<= 8; v >>= 8; 59 | r |= (v & 0x0ff); 60 | 61 | return r; 62 | } 63 | 64 | 65 | /* 66 | * byteswapbuf 67 | * 68 | * To swap from the byte order of every 32-bit word in the given buffer. 69 | */ 70 | void 71 | byteswapbuf(int ln, uint32_t *buf) { 72 | for(int i=0; i for a copy. 30 | ## 31 | ## License: GPL, v3, as defined and found on www.gnu.org, 32 | ## http://www.gnu.org/licenses/gpl.html 33 | ## 34 | ## 35 | ################################################################################ 36 | ## 37 | ## 38 | @PREFIX=gpio 39 | @DEVID=GPIO 40 | @NADDR=1 41 | @ACCESS=@$(DEVID)_ACCESS 42 | @SLAVE.TYPE=SINGLE 43 | @SLAVE.BUS=wb 44 | @NUMOUTPUT=11 45 | @NUMINPUT=11 46 | @INT.GPIO.WIRE=gpio_int 47 | @INT.GPIO.PIC=buspic 48 | @TOP.PORTLIST= 49 | // GPIO ports 50 | i_@$(PREFIX), o_@$(PREFIX) 51 | @TOP.IODECL= 52 | // GPIO wires 53 | localparam NGPI = @$(NUMINPUT), NGPO=@$(NUMOUTPUT); 54 | // GPIO ports 55 | input wire [(@$(NUMINPUT)-1):0] i_@$(PREFIX); 56 | output wire [(@$(NUMOUTPUT)-1):0] o_@$(PREFIX); 57 | @TOP.MAIN= 58 | // GPIO wires 59 | i_@$(PREFIX), o_@$(PREFIX) 60 | @MAIN.PORTLIST= 61 | // GPIO ports 62 | i_@$(PREFIX), o_@$(PREFIX) 63 | @MAIN.IODECL= 64 | localparam NGPI = @$(NUMINPUT), NGPO=@$(NUMOUTPUT); 65 | // @$(DEVID) ports 66 | input [(NGPI-1):0] i_@$(PREFIX); 67 | output wire [(NGPO-1):0] o_@$(PREFIX); 68 | @MAIN.DEFNS= 69 | wire sd_reset; 70 | @MAIN.INSERT= 71 | // 72 | // @$(DEVID) 73 | // 74 | // This interface should allow us to control up to 16 @$(DEVID) inputs, and 75 | // another 16 @$(DEVID) outputs. The interrupt trips when any of the inputs 76 | // changes. (Sorry, which input isn't (yet) selectable.) 77 | // 78 | localparam INITIAL_@$(DEVID) = @$(NUMOUTPUT)'h0; 79 | wbgpio #(NGPI, NGPO, INITIAL_@$(DEVID)) 80 | @$(PREFIX)i(i_clk, @$(SLAVE.PORTLIST), 81 | i_@$(PREFIX), o_@$(PREFIX), @$(PREFIX)_int); 82 | 83 | assign sd_reset = o_@$(PREFIX)[0]; 84 | @REGS.N=1 85 | @REGS.0= 0 R_@$(DEVID) @$(DEVID) GPI GPO 86 | @BDEF.DEFN= 87 | // 88 | // @$(DEVID) input wires 89 | // 90 | #define @$(DEVID)_IN(WIRE) (((WIRE)>>16)&1) 91 | // 92 | // @$(DEVID) output wires 93 | // 94 | #define @$(DEVID)_SET(WIRE) (((WIRE)<<16)|(WIRE)) 95 | #define @$(DEVID)_CLR(WIRE) ((WIRE)<<16) 96 | // 97 | // 98 | @BDEF.IONAME= i_@$(PREFIX) 99 | @BDEF.IOTYPE= unsigned 100 | @BDEF.OSDEF= _BOARD_HAS_@$(DEVID) 101 | @BDEF.OSVAL= static volatile @$.BDEF.IOTYPE *const _@$(PREFIX) = ((@$.BDEF.IOTYPE *)@$[0x%08x](REGBASE)); 102 | @RTL.MAKE.FILES=wbgpio.v 103 | @RTL.MAKE.GROUP=@$(DEVID) 104 | -------------------------------------------------------------------------------- /rtl/wbubus/wbudeword.v: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: wbudeword.v 4 | // 5 | // Project: FPGA library 6 | // 7 | // Purpose: Once a word has come from the bus, undergone compression, had 8 | // idle cycles and interrupts placed in it, this routine converts 9 | // that word form a 36-bit single word into a series of 6-bit words 10 | // that can head to the output routine. Hence, it 'deword's the value: 11 | // unencoding the 36-bit word encoding. 12 | // 13 | // 14 | // Creator: Dan Gisselquist, Ph.D. 15 | // Gisselquist Technology, LLC 16 | // 17 | //////////////////////////////////////////////////////////////////////////////// 18 | // 19 | // Copyright (C) 2015-2020, Gisselquist Technology, LLC 20 | // 21 | // This program is free software (firmware): you can redistribute it and/or 22 | // modify it under the terms of the GNU General Public License as published 23 | // by the Free Software Foundation, either version 3 of the License, or (at 24 | // your option) any later version. 25 | // 26 | // This program is distributed in the hope that it will be useful, but WITHOUT 27 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 28 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 29 | // for more details. 30 | // 31 | // You should have received a copy of the GNU General Public License along 32 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 33 | // target there if the PDF file isn't present.) If not, see 34 | // for a copy. 35 | // 36 | // License: GPL, v3, as defined and found on www.gnu.org, 37 | // http://www.gnu.org/licenses/gpl.html 38 | // 39 | // 40 | //////////////////////////////////////////////////////////////////////////////// 41 | // 42 | // 43 | `default_nettype none 44 | // 45 | module wbudeword(i_clk, i_stb, i_word, i_tx_busy, o_stb, o_nl_hexbits, o_busy); 46 | input wire i_clk, i_stb; 47 | input wire [35:0] i_word; 48 | input wire i_tx_busy; 49 | output reg o_stb; 50 | output reg [6:0] o_nl_hexbits; 51 | output reg o_busy; 52 | 53 | 54 | wire [2:0] w_len; 55 | assign w_len = (i_word[35:33]==3'b000)? 3'b001 56 | : (i_word[35:32]==4'h2)? 3'b110 57 | : (i_word[35:32]==4'h3)? (3'b010+{1'b0,i_word[31:30]}) 58 | : (i_word[35:34]==2'b01)? 3'b010 59 | : (i_word[35:34]==2'b10)? 3'b001 60 | : 3'b110; 61 | 62 | reg [2:0] r_len; 63 | reg [29:0] r_word; 64 | initial o_stb = 1'b0; 65 | initial o_busy = 1'b0; 66 | initial o_nl_hexbits = 7'h40; 67 | initial r_len = 0; 68 | always @(posedge i_clk) 69 | if ((i_stb)&&(!o_busy)) // Only accept when not busy 70 | begin 71 | r_word <= i_word[29:0]; 72 | o_nl_hexbits <= { 1'b0, i_word[35:30] }; // No newline ... yet 73 | end else if (!i_tx_busy) 74 | begin 75 | if (r_len > 1) 76 | begin 77 | o_nl_hexbits <= { 1'b0, r_word[29:24] }; 78 | r_word[29:6] <= r_word[23:0]; 79 | end else if (!o_nl_hexbits[6]) 80 | begin 81 | // Place a 7'h40 between every pair of words 82 | o_nl_hexbits <= 7'h40; 83 | end 84 | end 85 | 86 | initial o_stb = 1'b0; 87 | always @(posedge i_clk) 88 | if (i_stb && !o_busy) 89 | o_stb <= 1'b1; 90 | else if (r_len == 0 && !i_tx_busy) 91 | o_stb <= 1'b0; 92 | 93 | initial r_len = 0; 94 | always @(posedge i_clk) 95 | if (i_stb && !o_busy) 96 | r_len <= w_len; 97 | else if (!i_tx_busy && (r_len > 0)) 98 | r_len <= r_len - 1; 99 | 100 | always @(*) 101 | o_busy = o_stb; 102 | 103 | `ifdef FORMAL 104 | // Formal properties for this module are maintained elsewhere 105 | `endif 106 | endmodule 107 | 108 | -------------------------------------------------------------------------------- /sw/board/bkram.ld: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Filename: bkram.ld 4 | * 5 | * Project: ZBasic, a generic toplevel implementation using the full ZipCPU 6 | * 7 | * DO NOT EDIT THIS FILE! 8 | * Computer Generated: This file is computer generated by AUTOFPGA. DO NOT EDIT. 9 | * DO NOT EDIT THIS FILE! 10 | * 11 | * CmdLine: autofpga autofpga -d -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 12 | * 13 | * Creator: Dan Gisselquist, Ph.D. 14 | * Gisselquist Technology, LLC 15 | * 16 | /******************************************************************************* 17 | * 18 | * Copyright (C) 2017-2020, Gisselquist Technology, LLC 19 | * 20 | * This program is free software (firmware): you can redistribute it and/or 21 | * modify it under the terms of the GNU General Public License as published 22 | * by the Free Software Foundation, either version 3 of the License, or (at 23 | * your option) any later version. 24 | * 25 | * This program is distributed in the hope that it will be useful, but WITHOUT 26 | * ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 27 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 28 | * for more details. 29 | * 30 | * You should have received a copy of the GNU General Public License along 31 | * with this program. (It's in the $(ROOT)/doc directory. Run make with no 32 | * target there if the PDF file isn't present.) If not, see 33 | * for a copy. 34 | * 35 | * License: GPL, v3, as defined and found on www.gnu.org, 36 | * http://www.gnu.org/licenses/gpl.html 37 | * 38 | * 39 | /******************************************************************************* 40 | * 41 | * 42 | */ 43 | ENTRY(_start) 44 | 45 | MEMORY 46 | { 47 | /* To be listed here, a slave must be of type MEMORY. If the slave 48 | * has a defined name in its @LD.NAME tag, it will be listed here 49 | * under that name, otherwise it will be listed under it's 50 | * @$(PREFIX) tag with an underscore prepended to it. The permissions 51 | * are given by the @LD.PERM tag. Allowable permissions include 52 | * 'r' (read only), 'rx' (read and execute, but no writes), 53 | * 'wx' (read, write, and execute). If no permission tag exists, a 54 | * permission of 'r' will be assumed. 55 | */ 56 | bkram(wx) : ORIGIN = 0x00c00000, LENGTH = 0x00100000 57 | flash(rx) : ORIGIN = 0x01000000, LENGTH = 0x01000000 58 | } 59 | 60 | /* For each defined memory peripheral, we also define a pointer to that 61 | * memory. The name of this pointer is given by the @LD.NAME tag within 62 | * the memory peripheral's configuration 63 | */ 64 | _bkram = ORIGIN(bkram); 65 | _flash = ORIGIN(flash); 66 | /* LD.DEFNS from mem_bkram_only */ 67 | _kram = 0; /* No high-speed kernel RAM */ 68 | _ram = ORIGIN(bkram); 69 | _rom = 0; 70 | _top_of_stack = ORIGIN(bkram) + LENGTH(bkram); 71 | 72 | 73 | /* LD.SCRIPT from mem_bkram_only */ 74 | SECTIONS 75 | { 76 | .ramcode ORIGIN(bkram) : ALIGN(4) { 77 | _boot_address = .; 78 | _kram_start = .; 79 | _kram_end = .; 80 | _ram_image_start = . ; 81 | *(.start) *(.boot) 82 | *(.kernel) 83 | *(.text.startup) 84 | *(.text*) 85 | *(.rodata*) *(.strings) 86 | *(.data) *(COMMON) 87 | }> bkram 88 | _ram_image_end = . ; 89 | .bss : ALIGN_WITH_INPUT { 90 | *(.bss) 91 | _bss_image_end = . ; 92 | } > bkram 93 | _top_of_heap = .; 94 | } 95 | 96 | -------------------------------------------------------------------------------- /sw/host/zopcodes.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: zopcodes.h 4 | // 5 | // Project: ZBasic, a generic toplevel impl using the full ZipCPU 6 | // 7 | // Purpose: A structure defined to keep track of our various opcodes and 8 | // some of their shortcut synonyms. 9 | // 10 | // Creator: Dan Gisselquist, Ph.D. 11 | // Gisselquist Technology, LLC 12 | // 13 | //////////////////////////////////////////////////////////////////////////////// 14 | // 15 | // Copyright (C) 2015-2020, Gisselquist Technology, LLC 16 | // 17 | // This program is free software (firmware): you can redistribute it and/or 18 | // modify it under the terms of the GNU General Public License as published 19 | // by the Free Software Foundation, either version 3 of the License, or (at 20 | // your option) any later version. 21 | // 22 | // This program is distributed in the hope that it will be useful, but WITHOUT 23 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 24 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 25 | // for more details. 26 | // 27 | // You should have received a copy of the GNU General Public License along 28 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 29 | // target there if the PDF file isn't present.) If not, see 30 | // for a copy. 31 | // 32 | // License: GPL, v3, as defined and found on www.gnu.org, 33 | // http://www.gnu.org/licenses/gpl.html 34 | // 35 | // 36 | //////////////////////////////////////////////////////////////////////////////// 37 | // 38 | // 39 | #ifndef ZOPCODES_H 40 | #define ZOPCODES_H 41 | 42 | #include 43 | 44 | // MACROS used in the instruction definition list. 45 | #define ZIP_OPUNUSED -1 46 | #define ISUSEROP(A) ((a&(~0x0f))==0x000) 47 | #define ISSUPROP(A) ((a&(~0x0f))==0x010) 48 | #define ISLCLROP(A) ((a&(~0x0f))==0x020) 49 | #define ZIP_BITFIELD(LN,MN) (((LN&0x0ff)<<8)+(MN&0x0ff)) // A generic bitfield 50 | #define ZIP_REGFIELD(MN) (0x00000400 +(MN&0x0ff)) // Normal register field 51 | #define ZIP_URGFIELD(MN) (0x0100400 +(MN&0x0ff)) // User register field 52 | #define ZIP_IMMFIELD(LN,MN) (0x40000000 + (((LN&0x0ff)<<8)+(MN&0x0ff))) // Sgn extnd 53 | #define ZIP_SRGFIELD(MN) (0x0200400 +(MN&0x0ff)) 54 | #define ZIP_SP 0xd0000 55 | 56 | typedef uint32_t ZIPI; // A Zip CPU instruction 57 | 58 | typedef struct { 59 | char s_opstr[8]; // OPCode name 60 | ZIPI s_mask, // Bits that must match 4 this pattern to match 61 | s_val; // What those masked bits must be 62 | // 63 | // The following describe not the value, but the bits where there 64 | // respective vaules will be found within the instruction. For example, 65 | // an instruction with no immediate will have an s_i value of -1 66 | // (ZIP_OPUNUSED), whereas an instruction with an immediate value of -1 67 | // might have an s_i value of ZIP_BITFIELD(14,0), or 0x0400. The 68 | // opcode itself will tell you what the value is--not this structure 69 | // describing the opcode. 70 | // 71 | int s_result, // Register where the result will be placed 72 | s_ra, // A register, often the result 73 | s_rb, // B register, source operand (if used) 74 | s_i, // Immediate value, added to B if B is used 75 | s_cf; // Condition flags. 76 | } ZOPCODE; 77 | 78 | extern const char *zip_regstr[49], *zip_ccstr[8]; 79 | 80 | extern const ZOPCODE *zip_oplist, *zip_opbottomlist; 81 | extern const int nzip_oplist, nzip_opbottom; 82 | 83 | // Disassemble an opcode 84 | extern void zipi_to_double_string(const uint32_t, const ZIPI, char *, char *); 85 | extern const char *zop_regstr[]; 86 | extern const char *zop_ccstr[]; 87 | extern unsigned int zop_early_branch(const unsigned int pc, const ZIPI ins); 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /auto-data/global.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | ## 3 | ## Filename: global.txt 4 | ## 5 | ## Project: ZBasic, a generic toplevel impl using the full ZipCPU 6 | ## 7 | ## Purpose: Capture any global configuration parameters 8 | ## 9 | ## Creator: Dan Gisselquist, Ph.D. 10 | ## Gisselquist Technology, LLC 11 | ## 12 | ################################################################################ 13 | ## 14 | ## Copyright (C) 2015-2020, Gisselquist Technology, LLC 15 | ## 16 | ## This program is free software (firmware): you can redistribute it and/or 17 | ## modify it under the terms of the GNU General Public License as published 18 | ## by the Free Software Foundation, either version 3 of the License, or (at 19 | ## your option) any later version. 20 | ## 21 | ## This program is distributed in the hope that it will be useful, but WITHOUT 22 | ## ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 23 | ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 24 | ## for more details. 25 | ## 26 | ## You should have received a copy of the GNU General Public License along 27 | ## with this program. (It's in the $(ROOT)/doc directory. Run make with no 28 | ## target there if the PDF file isn't present.) If not, see 29 | ## for a copy. 30 | ## 31 | ## License: GPL, v3, as defined and found on www.gnu.org, 32 | ## http://www.gnu.org/licenses/gpl.html 33 | ## 34 | ## 35 | ################################################################################ 36 | ## 37 | ## 38 | @LEGAL=legalgen.txt 39 | @PROJECT=ZBasic, a generic toplevel implementation using the full ZipCPU 40 | # @XDC.FILE=nexysv.xdc 41 | # @XDC.FILE=arty.xdc 42 | # 43 | # @KEYS.TRIMLIST is a list of all string keys that need to be trimmed (have 44 | # spaces removed from either side) before being used 45 | # @KEYS.INTLIST is a list of all things that need to be converted to integers 46 | @KEYS.INTLIST= BUS_ADDRESS_WIDTH NADDR NPIC NSCOPES PIC.MAX REGS.N ID 47 | @DEFAULT.BUS=wb 48 | @REGISTER.BUS=wbu 49 | @VERILATOR_PREFIX=v 50 | @REGDEFS.H.INSERT= 51 | typedef struct { 52 | unsigned m_addr; 53 | const char *m_name; 54 | } REGNAME; 55 | 56 | extern const REGNAME *bregs; 57 | extern const int NREGS; 58 | // #define NREGS (sizeof(bregs)/sizeof(bregs[0])) 59 | 60 | extern unsigned addrdecode(const char *v); 61 | extern const char *addrname(const unsigned v); 62 | @REGDEFS.CPP.INCLUDE= 63 | #include 64 | #include 65 | #include 66 | #include 67 | @REGDEFS.CPP.INSERT= 68 | #define RAW_NREGS (sizeof(raw_bregs)/sizeof(bregs[0])) 69 | 70 | const REGNAME *bregs = raw_bregs; 71 | const int NREGS = RAW_NREGS; 72 | 73 | unsigned addrdecode(const char *v) { 74 | if (isalpha(v[0])) { 75 | for(int i=0; i for a copy. 34 | * 35 | * License: GPL, v3, as defined and found on www.gnu.org, 36 | * http://www.gnu.org/licenses/gpl.html 37 | * 38 | * 39 | /******************************************************************************* 40 | * 41 | * 42 | */ 43 | ENTRY(_start) 44 | 45 | MEMORY 46 | { 47 | /* To be listed here, a slave must be of type MEMORY. If the slave 48 | * has a defined name in its @LD.NAME tag, it will be listed here 49 | * under that name, otherwise it will be listed under it's 50 | * @$(PREFIX) tag with an underscore prepended to it. The permissions 51 | * are given by the @LD.PERM tag. Allowable permissions include 52 | * 'r' (read only), 'rx' (read and execute, but no writes), 53 | * 'wx' (read, write, and execute). If no permission tag exists, a 54 | * permission of 'r' will be assumed. 55 | */ 56 | bkram(wx) : ORIGIN = 0x00c00000, LENGTH = 0x00100000 57 | flash(rx) : ORIGIN = 0x01000000, LENGTH = 0x01000000 58 | } 59 | 60 | /* For each defined memory peripheral, we also define a pointer to that 61 | * memory. The name of this pointer is given by the @LD.NAME tag within 62 | * the memory peripheral's configuration 63 | */ 64 | _bkram = ORIGIN(bkram); 65 | _flash = ORIGIN(flash); 66 | /* LD.DEFNS from zipmaster.txt */ 67 | _kram = 0; /* No high-speed kernel RAM */ 68 | _ram = ORIGIN(bkram); 69 | _rom = ORIGIN(flash); 70 | _top_of_stack = ORIGIN(bkram) + LENGTH(bkram); 71 | 72 | 73 | /* LD.SCRIPT from zipmaster.txt */ 74 | SECTIONS 75 | { 76 | .rocode 0x01400000 : ALIGN(4) { 77 | _boot_address = .; 78 | *(.start) *(.boot) 79 | } > flash 80 | _kram_start = . ; 81 | _kram_end = . ; 82 | _ram_image_start = . ; 83 | .kernel : ALIGN_WITH_INPUT { 84 | *(.kernel) 85 | *(.text.startup) 86 | *(.text*) 87 | *(.rodata*) *(.strings) 88 | *(.data) *(COMMON) 89 | }> bkram AT> flash 90 | _ram_image_end = . ; 91 | .bss : ALIGN_WITH_INPUT { 92 | *(.bss) 93 | _bss_image_end = . ; 94 | } > bkram 95 | _top_of_heap = .; 96 | } 97 | 98 | -------------------------------------------------------------------------------- /mkdatev.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | ################################################################################ 3 | ## 4 | ## Filename: mkdatev.pl 5 | ## 6 | ## Project: ZBasic, a generic toplevel impl using the full ZipCPU 7 | ## 8 | ## Purpose: This file creates a file containing a `define DATESTAMP 9 | ## which can be used to tell when the build took place. 10 | ## 11 | ## 12 | ## Creator: Dan Gisselquist, Ph.D. 13 | ## Gisselquist Technology, LLC 14 | ## 15 | ################################################################################ 16 | ## 17 | ## Copyright (C) 2015-2020, Gisselquist Technology, LLC 18 | ## 19 | ## This program is free software (firmware): you can redistribute it and/or 20 | ## modify it under the terms of the GNU General Public License as published 21 | ## by the Free Software Foundation, either version 3 of the License, or (at 22 | ## your option) any later version. 23 | ## 24 | ## This program is distributed in the hope that it will be useful, but WITHOUT 25 | ## ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 26 | ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 27 | ## for more details. 28 | ## 29 | ## You should have received a copy of the GNU General Public License along 30 | ## with this program. (It's in the $(ROOT)/doc directory. Run make with no 31 | ## target there if the PDF file isn't present.) If not, see 32 | ## for a copy. 33 | ## 34 | ## License: GPL, v3, as defined and found on www.gnu.org, 35 | ## http://www.gnu.org/licenses/gpl.html 36 | ## 37 | ## 38 | ################################################################################ 39 | ## 40 | ## 41 | 42 | $now = time; 43 | ($sc,$mn,$nhr,$ndy,$nmo,$nyr,$nwday,$nyday,$nisdst) = localtime($now); 44 | $nyr = $nyr+1900; $nmo = $nmo+1; 45 | 46 | # And just because perl doesn't like my dollars signs ... 47 | $doc = "\$(ROOT)/doc"; 48 | 49 | print <<"EOM"; 50 | //////////////////////////////////////////////////////////////////////////////// 51 | // 52 | // Filename: builddate.v 53 | // 54 | // Project: ZBasic, a generic toplevel impl using the full ZipCPU 55 | // 56 | // Purpose: This file records the date of the last build. Running "make" 57 | // in the main directory will create this file. The `define found 58 | // within it then creates a version stamp that can be used to tell which 59 | // configuration is within an FPGA and so forth. 60 | // 61 | // Creator: Dan Gisselquist, Ph.D. 62 | // Gisselquist Technology, LLC 63 | // 64 | //////////////////////////////////////////////////////////////////////////////// 65 | // 66 | // Copyright (C) 2015-2020, Gisselquist Technology, LLC 67 | // 68 | // This program is free software (firmware): you can redistribute it and/or 69 | // modify it under the terms of the GNU General Public License as published 70 | // by the Free Software Foundation, either version 3 of the License, or (at 71 | // your option) any later version. 72 | // 73 | // This program is distributed in the hope that it will be useful, but WITHOUT 74 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 75 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 76 | // for more details. 77 | // 78 | // You should have received a copy of the GNU General Public License along 79 | // with this program. (It's in the \$(ROOT)/doc directory. Run make with no 80 | // target there if the PDF file isn't present.) If not, see 81 | // for a copy. 82 | // 83 | // License: GPL, v3, as defined and found on www.gnu.org, 84 | // http://www.gnu.org/licenses/gpl.html 85 | // 86 | // 87 | //////////////////////////////////////////////////////////////////////////////// 88 | // 89 | // 90 | `ifndef DATESTAMP 91 | EOM 92 | 93 | print "`define DATESTAMP 32\'h"; 94 | printf("%04d%02d%02d\n", $nyr, $nmo, $ndy); 95 | print "`define BUILDTIME 32\'h"; 96 | printf("%04d%02d%02d\n", $nhr, $mn, $sc); 97 | printf("`endif\n//\n"); 98 | -------------------------------------------------------------------------------- /sw/board/txfns.c: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: txfns.c 4 | // 5 | // Project: ZBasic, a generic toplevel impl using the full ZipCPU 6 | // 7 | // Purpose: These are some *very* simple UART routines, designed to support 8 | // a program before the C-library is up and running. Once the 9 | // C-library is running on a device, it is anticipated that these routines 10 | // will no longer be needed or used--since they access the raw hardware 11 | // device(s). 12 | // 13 | // Creator: Dan Gisselquist, Ph.D. 14 | // Gisselquist Technology, LLC 15 | // 16 | //////////////////////////////////////////////////////////////////////////////// 17 | // 18 | // Copyright (C) 2015-2020, Gisselquist Technology, LLC 19 | // 20 | // This program is free software (firmware): you can redistribute it and/or 21 | // modify it under the terms of the GNU General Public License as published 22 | // by the Free Software Foundation, either version 3 of the License, or (at 23 | // your option) any later version. 24 | // 25 | // This program is distributed in the hope that it will be useful, but WITHOUT 26 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 27 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 28 | // for more details. 29 | // 30 | // You should have received a copy of the GNU General Public License along 31 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 32 | // target there if the PDF file isn't present.) If not, see 33 | // for a copy. 34 | // 35 | // License: GPL, v3, as defined and found on www.gnu.org, 36 | // http://www.gnu.org/licenses/gpl.html 37 | // 38 | // 39 | //////////////////////////////////////////////////////////////////////////////// 40 | // 41 | // 42 | #include 43 | #include "board.h" 44 | #include "txfns.h" 45 | 46 | void txchr(char ch); 47 | void txhex(unsigned val); 48 | void txstr(const char *str); 49 | 50 | /* 51 | * txchr() 52 | * 53 | * This is the fundamental routine within here. It transmits one character 54 | * out of the UART, polling the UART device to determine when/if it is idle 55 | * to send the next character. 56 | * 57 | */ 58 | #define UARTTX_READY (_uart->u_fifo & 0x010000) 59 | void txchr(char val) { 60 | unsigned v = (unsigned char)val; 61 | static int last_was_cr = 0; 62 | uint8_t c; 63 | 64 | if ((0 == last_was_cr)&&(val == '\n')) { 65 | while(!UARTTX_READY) 66 | ; 67 | c = '\r'; 68 | _uart->u_tx = (unsigned)c; 69 | } 70 | 71 | while(!UARTTX_READY) 72 | ; 73 | c = v; 74 | _uart->u_tx = (unsigned)c; 75 | last_was_cr = (c == '\r')?1:0; 76 | } 77 | 78 | /* 79 | * txstr() 80 | * 81 | * Called to send a string to the UART port. This works by calling txchr to 82 | * do its real work. 83 | */ 84 | void txstr(const char *str) { 85 | const char *ptr = str; 86 | while(*ptr) 87 | txchr(*ptr++); 88 | } 89 | 90 | /* 91 | * txhex() 92 | * 93 | * Send a hexadecimal value to the output port 94 | */ 95 | void txhex(unsigned val) { 96 | for(int i=28; i>=0; i-=4) { 97 | int ch = ((val>>i)&0x0f)+'0'; 98 | if (ch > '9') 99 | ch = ch - '0'+'A'-10; 100 | txchr(ch); 101 | } 102 | } 103 | 104 | /* 105 | * txdecimal() 106 | * 107 | * Same as txhex, but for signed decimal numbers. 108 | */ 109 | void txdecimal(int val) { 110 | char tmp[16]; 111 | int nc=0, uval; 112 | 113 | if (val < 0) { 114 | uval = -val; 115 | txchr('-'); 116 | } else { 117 | uval = val; 118 | txchr(' '); 119 | } 120 | 121 | if (uval == 0) { 122 | tmp[nc++] = '0'; 123 | } else while(uval > 0) { 124 | unsigned dval, digit; 125 | dval = uval / 10; 126 | digit = (uval - dval * 10); 127 | tmp[nc++] = (digit + '0'); 128 | uval = dval; 129 | } 130 | 131 | for(unsigned i=nc; i>0; i--) 132 | txchr(tmp[i-1]); 133 | } 134 | -------------------------------------------------------------------------------- /rtl/cpu/zipcounter.v: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: zipcounter.v 4 | // 5 | // Project: Zip CPU -- a small, lightweight, RISC CPU soft core 6 | // 7 | // Purpose: 8 | // A very, _very_ simple counter. It's purpose doesn't really 9 | // include rollover, but it will interrupt on rollover. It can be set, 10 | // although my design concept is that it can be reset. It cannot be 11 | // halted. It will always produce interrupts--whether or not they are 12 | // handled interrupts is another question--that's up to the interrupt 13 | // controller. 14 | // 15 | // My intention is to use this counter for process accounting: I should 16 | // be able to use this to count clock ticks of processor time assigned to 17 | // each task by resetting the counter at the beginning of every task 18 | // interval, and reading the result at the end of the interval. As long 19 | // as the interval is less than 2^32 clocks, there should be no problem. 20 | // Similarly, this can be used to measure CPU wishbone bus stalls, 21 | // prefetch stalls, or other CPU stalls (i.e. stalling as part of a JMP 22 | // instruction, or a read from the condition codes following a write). 23 | // 24 | // 25 | // Creator: Dan Gisselquist, Ph.D. 26 | // Gisselquist Technology, LLC 27 | // 28 | //////////////////////////////////////////////////////////////////////////////// 29 | // 30 | // Copyright (C) 2015-2020, Gisselquist Technology, LLC 31 | // 32 | // This program is free software (firmware): you can redistribute it and/or 33 | // modify it under the terms of the GNU General Public License as published 34 | // by the Free Software Foundation, either version 3 of the License, or (at 35 | // your option) any later version. 36 | // 37 | // This program is distributed in the hope that it will be useful, but WITHOUT 38 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 39 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 40 | // for more details. 41 | // 42 | // You should have received a copy of the GNU General Public License along 43 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 44 | // target there if the PDF file isn't present.) If not, see 45 | // for a copy. 46 | // 47 | // License: GPL, v3, as defined and found on www.gnu.org, 48 | // http://www.gnu.org/licenses/gpl.html 49 | // 50 | // 51 | //////////////////////////////////////////////////////////////////////////////// 52 | // 53 | // 54 | `default_nettype none 55 | // 56 | module zipcounter(i_clk, i_reset, i_event, 57 | i_wb_cyc, i_wb_stb, i_wb_we, i_wb_data, 58 | o_wb_stall, o_wb_ack, o_wb_data, 59 | o_int); 60 | parameter BW = 32; 61 | input wire i_clk, i_reset, i_event; 62 | // Wishbone inputs 63 | input wire i_wb_cyc, i_wb_stb, i_wb_we; 64 | input wire [(BW-1):0] i_wb_data; 65 | // Wishbone outputs 66 | output wire o_wb_stall; 67 | output reg o_wb_ack; 68 | output reg [(BW-1):0] o_wb_data; 69 | // Interrupt line 70 | output reg o_int; 71 | 72 | initial o_int = 0; 73 | initial o_wb_data = 32'h00; 74 | always @(posedge i_clk) 75 | if (i_reset) 76 | { o_int, o_wb_data } <= 0; 77 | else if ((i_wb_stb)&&(i_wb_we)) 78 | { o_int, o_wb_data } <= { 1'b0, i_wb_data }; 79 | else if (i_event) 80 | { o_int, o_wb_data } <= o_wb_data+{{(BW-1){1'b0}},1'b1}; 81 | else 82 | o_int <= 1'b0; 83 | 84 | initial o_wb_ack = 1'b0; 85 | always @(posedge i_clk) 86 | if (i_reset) 87 | o_wb_ack <= 1'b0; 88 | else 89 | o_wb_ack <= i_wb_stb; 90 | assign o_wb_stall = 1'b0; 91 | 92 | 93 | // Make verilator happy 94 | // verilator lint_off UNUSED 95 | wire unused; 96 | assign unused = i_wb_cyc; 97 | // verilator lint_on UNUSED 98 | 99 | `ifdef FORMAL 100 | // Formal properties for this module are maintained elsewhere 101 | `endif 102 | endmodule 103 | -------------------------------------------------------------------------------- /sw/host/dumpflash.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: dumpflash.cpp 4 | // 5 | // Project: ZBasic, a generic toplevel impl using the full ZipCPU 6 | // 7 | // Purpose: Read/Empty the entire contents of the flash memory to a file. 8 | // The flash is unchanged by this process. 9 | // 10 | // Creator: Dan Gisselquist, Ph.D. 11 | // Gisselquist Technology, LLC 12 | // 13 | //////////////////////////////////////////////////////////////////////////////// 14 | // 15 | // Copyright (C) 2015-2020, Gisselquist Technology, LLC 16 | // 17 | // This program is free software (firmware): you can redistribute it and/or 18 | // modify it under the terms of the GNU General Public License as published 19 | // by the Free Software Foundation, either version 3 of the License, or (at 20 | // your option) any later version. 21 | // 22 | // This program is distributed in the hope that it will be useful, but WITHOUT 23 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 24 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 25 | // for more details. 26 | // 27 | // You should have received a copy of the GNU General Public License along 28 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 29 | // target there if the PDF file isn't present.) If not, see 30 | // for a copy. 31 | // 32 | // License: GPL, v3, as defined and found on www.gnu.org, 33 | // http://www.gnu.org/licenses/gpl.html 34 | // 35 | // 36 | //////////////////////////////////////////////////////////////////////////////// 37 | // 38 | // 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | 48 | #include "port.h" 49 | #include "regdefs.h" 50 | #include "ttybus.h" 51 | #include "byteswap.h" 52 | 53 | FPGA *m_fpga; 54 | void closeup(int v) { 55 | m_fpga->kill(); 56 | exit(0); 57 | } 58 | 59 | #define DUMPMEM FLASHBASE 60 | #define DUMPWORDS (FLASHLEN>>2) 61 | 62 | int main(int argc, char **argv) { 63 | #ifdef FLASH_ACCESS 64 | FILE *fp; 65 | const int BUFLN = FLASHLEN; 66 | char *buf = new char[FLASHLEN]; 67 | 68 | FPGAOPEN(m_fpga); 69 | fprintf(stderr, "Before starting, nread = %ld\n", 70 | m_fpga->m_total_nread); 71 | 72 | // Start with testing the version: 73 | printf("VERSION: %08x\n", m_fpga->readio(R_VERSION)); 74 | 75 | // SPI flash testing 76 | // Enable the faster (vector) reads 77 | bool vector_read = true; 78 | unsigned sz; 79 | 80 | if (vector_read) { 81 | m_fpga->readi(DUMPMEM, BUFLN>>2, (DEVBUS::BUSW *)&buf[0]); 82 | byteswapbuf(BUFLN>>2, (DEVBUS::BUSW *)&buf[0]); 83 | } else { 84 | for(int i=0; ireadio(DUMPMEM+i); 88 | 89 | buf[i ] = (word>>24) & 0x0ff; 90 | buf[i+1] = (word>>16) & 0x0ff; 91 | buf[i+2] = (word>> 8) & 0x0ff; 92 | buf[i+3] = (word ) & 0x0ff; 93 | } 94 | } 95 | printf("\nREAD-COMPLETE\n"); 96 | 97 | // Now, let's find the end 98 | sz = BUFLN-1; 99 | while((sz>0)&&((unsigned char)buf[sz] == 0xff)) 100 | sz--; 101 | sz+=1; 102 | 103 | #define FLASHFILE "qspidump.bin" 104 | 105 | if (access(FLASHFILE, F_OK)==0) { 106 | fprintf(stderr, "Cowardly refusing to overwrite %s\n", FLASHFILE); 107 | exit(EXIT_FAILURE); 108 | } 109 | 110 | fp = fopen(FLASHFILE,"w"); 111 | fwrite(buf, sizeof(buf[0]), sz, fp); 112 | fclose(fp); 113 | 114 | printf("The read was accomplished in %ld bytes over the UART\n", 115 | m_fpga->m_total_nread); 116 | 117 | if (m_fpga->poll()) 118 | printf("FPGA was interrupted\n"); 119 | delete m_fpga; 120 | #else // FLASH_ACCESS 121 | printf( 122 | "This design requires some kind of flash be available within your design.\n" 123 | "\n" 124 | "To use this dumpflash program, add a flash component in the auto-data\n" 125 | "directory, and then add that component to the AutoFPGA makefile to\n" 126 | "include it. This file should then build properly, and be able to dump\n" 127 | "the given flash device.\n"); 128 | #endif // FLASH_ACCESS 129 | } 130 | 131 | 132 | -------------------------------------------------------------------------------- /rtl/cpu/wbwatchdog.v: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: wbwatchdog.v 4 | // 5 | // Project: Zip CPU -- a small, lightweight, RISC CPU soft core 6 | // 7 | // Purpose: A Zip timer, redesigned to be a bus watchdog 8 | // 9 | // This is basically a timer, but there are some unique features to it. 10 | // 11 | // 1. There is no way to "write" the timeout to this watchdog. It is 12 | // fixed with an input (that is assumed to be constant) 13 | // 2. The counter returns to i_timer and the interrupt is cleared on any 14 | // reset. 15 | // 3. Between resets, the counter counts down to zero. Once (and if) it 16 | // hits zero, it will remain at zero until reset. 17 | // 4. Any time the counter is at zero, and until the reset that resets 18 | // the counter, the output interrupt will be set. 19 | // 20 | // 21 | // Creator: Dan Gisselquist, Ph.D. 22 | // Gisselquist Technology, LLC 23 | // 24 | //////////////////////////////////////////////////////////////////////////////// 25 | // 26 | // Copyright (C) 2015,2017-2020, Gisselquist Technology, LLC 27 | // 28 | // This program is free software (firmware): you can redistribute it and/or 29 | // modify it under the terms of the GNU General Public License as published 30 | // by the Free Software Foundation, either version 3 of the License, or (at 31 | // your option) any later version. 32 | // 33 | // This program is distributed in the hope that it will be useful, but WITHOUT 34 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 35 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 36 | // for more details. 37 | // 38 | // You should have received a copy of the GNU General Public License along 39 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 40 | // target there if the PDF file isn't present.) If not, see 41 | // for a copy. 42 | // 43 | // License: GPL, v3, as defined and found on www.gnu.org, 44 | // http://www.gnu.org/licenses/gpl.html 45 | // 46 | // 47 | //////////////////////////////////////////////////////////////////////////////// 48 | // 49 | // 50 | `default_nettype none 51 | // 52 | module wbwatchdog(i_clk, i_reset, i_timeout, o_int); 53 | parameter BW = 32; 54 | input wire i_clk, i_reset; 55 | // Inputs (these were at one time wishbone controlled ...) 56 | input wire [(BW-1):0] i_timeout; 57 | // Interrupt line 58 | output reg o_int; 59 | 60 | reg [(BW-1):0] r_value; 61 | initial r_value = {(BW){1'b1}}; 62 | always @(posedge i_clk) 63 | if (i_reset) 64 | r_value <= i_timeout[(BW-1):0]; 65 | else if (!o_int) 66 | r_value <= r_value + {(BW){1'b1}}; // r_value - 1; 67 | 68 | // Set the interrupt on our last tick. 69 | initial o_int = 1'b0; 70 | always @(posedge i_clk) 71 | if (i_reset) 72 | o_int <= 1'b0; 73 | else if (!o_int) 74 | o_int <= (r_value == { {(BW-1){1'b0}}, 1'b1 }); 75 | 76 | `ifdef FORMAL 77 | reg f_past_valid; 78 | 79 | initial f_past_valid = 1'b0; 80 | always @(posedge f_past_valid) 81 | f_past_valid <= 1'b1; 82 | 83 | /////////////////////////////////////////////// 84 | // 85 | // 86 | // Assumptions about our inputs 87 | // 88 | // 89 | /////////////////////////////////////////////// 90 | always @(*) 91 | assume(i_timeout > 1); 92 | always @(posedge i_clk) 93 | if (f_past_valid) 94 | assume(i_timeout == $past(i_timeout)); 95 | 96 | // 97 | // 98 | /////////////////////////////////////////////// 99 | // 100 | // 101 | // Assertions about our internal state and our outputs 102 | // 103 | // 104 | /////////////////////////////////////////////// 105 | // 106 | // 107 | always @(posedge i_clk) 108 | if ((f_past_valid)&&($past(o_int))&&(!$past(i_reset))) 109 | assert(o_int); 110 | 111 | always @(*) 112 | assert(o_int == (r_value == 0)); 113 | 114 | always @(posedge i_clk) 115 | if ((f_past_valid)&&(!$past(i_reset))&&(!$past(o_int))) 116 | begin 117 | assert(r_value == $past(r_value)-1'b1); 118 | end 119 | 120 | always @(posedge i_clk) 121 | if ((!f_past_valid)||($past(i_reset))) 122 | begin 123 | if (!f_past_valid) 124 | assert(r_value == {(BW){1'b1}}); 125 | else // if ($past(i_reset)) 126 | assert(r_value == $past(i_timeout)); 127 | assert(!o_int); 128 | end 129 | `endif 130 | endmodule 131 | -------------------------------------------------------------------------------- /sw/host/regdefs.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: ./regdefs.cpp 4 | // 5 | // Project: ZBasic, a generic toplevel implementation using the full ZipCPU 6 | // 7 | // DO NOT EDIT THIS FILE! 8 | // Computer Generated: This file is computer generated by AUTOFPGA. DO NOT EDIT. 9 | // DO NOT EDIT THIS FILE! 10 | // 11 | // CmdLine: autofpga autofpga -d -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 12 | // 13 | // Creator: Dan Gisselquist, Ph.D. 14 | // Gisselquist Technology, LLC 15 | // 16 | //////////////////////////////////////////////////////////////////////////////// 17 | // 18 | // Copyright (C) 2017-2020, Gisselquist Technology, LLC 19 | // 20 | // This program is free software (firmware): you can redistribute it and/or 21 | // modify it under the terms of the GNU General Public License as published 22 | // by the Free Software Foundation, either version 3 of the License, or (at 23 | // your option) any later version. 24 | // 25 | // This program is distributed in the hope that it will be useful, but WITHOUT 26 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 27 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 28 | // for more details. 29 | // 30 | // You should have received a copy of the GNU General Public License along 31 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 32 | // target there if the PDF file isn't present.) If not, see 33 | // for a copy. 34 | // 35 | // License: GPL, v3, as defined and found on www.gnu.org, 36 | // http://www.gnu.org/licenses/gpl.html 37 | // 38 | // 39 | //////////////////////////////////////////////////////////////////////////////// 40 | // 41 | // 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include "regdefs.h" 47 | 48 | const REGNAME raw_bregs[] = { 49 | { R_FLASHCFG , "FLASHCFG" }, 50 | { R_FLASHCFG , "QSPIC" }, 51 | { R_SDSPI_CTRL , "SDCARD" }, 52 | { R_SDSPI_DATA , "SDDATA" }, 53 | { R_SDSPI_FIFOA , "SDFIFOA" }, 54 | { R_SDSPI_FIFOA , "SDFIF0" }, 55 | { R_SDSPI_FIFOA , "SDFIFA" }, 56 | { R_SDSPI_FIFOB , "SDFIFOB" }, 57 | { R_SDSPI_FIFOB , "SDFIF1" }, 58 | { R_SDSPI_FIFOB , "SDFIFB" }, 59 | { R_CONSOLE_FIFO , "UFIFO" }, 60 | { R_CONSOLE_UARTRX, "RX" }, 61 | { R_CONSOLE_UARTTX, "TX" }, 62 | { R_CLOCK , "CLOCK" }, 63 | { R_TIMER , "TIMER" }, 64 | { R_STOPWATCH , "STOPWATCH" }, 65 | { R_CKALARM , "ALARM" }, 66 | { R_CKALARM , "CKALARM" }, 67 | { R_CKSPEED , "CKSPEED" }, 68 | { R_BUILDTIME , "BUILDTIME" }, 69 | { R_BUSERR , "BUSERR" }, 70 | { R_PIC , "PIC" }, 71 | { R_GPIO , "GPIO" }, 72 | { R_GPIO , "GPI" }, 73 | { R_GPIO , "GPO" }, 74 | { R_PWRCOUNT , "PWRCOUNT" }, 75 | { R_RTCDATE , "RTCDATE" }, 76 | { R_RTCDATE , "DATE" }, 77 | { R_VERSION , "VERSION" }, 78 | { R_BKRAM , "RAM" }, 79 | { R_FLASH , "FLASH" } 80 | }; 81 | 82 | // REGSDEFS.CPP.INSERT for any bus masters 83 | // And then from the peripherals 84 | // And finally any master REGS.CPP.INSERT tags 85 | #define RAW_NREGS (sizeof(raw_bregs)/sizeof(bregs[0])) 86 | 87 | const REGNAME *bregs = raw_bregs; 88 | const int NREGS = RAW_NREGS; 89 | 90 | unsigned addrdecode(const char *v) { 91 | if (isalpha(v[0])) { 92 | for(int i=0; i for a copy. 33 | ## 34 | ## License: GPL, v3, as defined and found on www.gnu.org, 35 | ## http://www.gnu.org/licenses/gpl.html 36 | ## 37 | ## 38 | ################################################################################ 39 | ## 40 | ## 41 | all: test cpudefs.h design.h 42 | YYMMDD=`date +%Y%m%d` 43 | CXX := g++ 44 | FBDIR := . 45 | VDIRFB:= $(FBDIR)/obj_dir 46 | VOBJ := obj_dir 47 | SUBMAKE := $(MAKE) --no-print-directory -C $(VOBJ) -f 48 | ifeq ($(VERILATOR_ROOT),) 49 | VERILATOR := verilator 50 | else 51 | VERILATOR := $(VERILATOR_ROOT)/bin/verilator 52 | endif 53 | VFLAGS = -Wall -Wno-TIMESCALEMOD --MMD -O3 --trace -Mdir $(VDIRFB) $(AUTOVDIRS) -cc 54 | 55 | -include make.inc 56 | 57 | .DELETE_ON_ERROR: 58 | 59 | .PHONY: test auto-test 60 | test: auto-test 61 | 62 | .PHONY: auto-test 63 | auto-test: $(VDIRFB)/Vmain__ALL.a 64 | 65 | $(VDIRFB)/Vmain__ALL.a: $(VDIRFB)/Vmain.h $(VDIRFB)/Vmain.cpp 66 | $(VDIRFB)/Vmain__ALL.a: $(VDIRFB)/Vmain.mk 67 | 68 | $(VDIRFB)/V%.cpp: $(VDIRFB)/V%.h 69 | $(VDIRFB)/V%.mk: $(VDIRFB)/V%.h 70 | $(VDIRFB)/V%.h: $(FBDIR)/%.v 71 | $(VERILATOR) $(VFLAGS) $*.v 72 | 73 | $(VDIRFB)/Vmain.cpp: $(VDIRFB)/Vmain.h 74 | $(VDIRFB)/Vmain.mk: $(VDIRFB)/Vmain.h 75 | 76 | $(VDIRFB)/Vmain.h: main.v $(VFLIST) 77 | $(VERILATOR) $(VFLAGS) main.v 78 | 79 | cpudefs.h: cpu/cpudefs.v 80 | @echo "Building cpudefs.h" 81 | @echo "// " > $@ 82 | @echo "// Do not edit this file, it is automatically generated!" >> $@ 83 | @echo "// To generate this file, \"make cpudefs.h\" in the rtl directory." >> $@ 84 | @echo "// " >> $@ 85 | @sed -e '{ s/^`/#/ }' $< | sed -e ' s/cpudefs.v/cpudefs.h/' >> $@ 86 | @echo >> $@ 87 | 88 | design.h: main.v 89 | @echo "Building design.h" 90 | @echo "// " > $@ 91 | @echo "// Do not edit this file, it is automatically generated!" >> $@ 92 | @echo "// To generate this file, \"make design.h\" in the rtl directory." >> $@ 93 | @echo "// " >> $@ 94 | @echo "#ifndef DESIGN_H" >> $@ 95 | @echo "#define DESIGN_H" >> $@ 96 | @echo >> $@ 97 | @grep "^\`" $< | grep -v default_nettype \ 98 | | grep -v include \ 99 | | grep -v timescale \ 100 | | sed -e '{ s/^`/#/ }' \ 101 | | sed -e ' s/^#elsif/#elif/' \ 102 | | sed -e ' s/main.v/design.h/' >> $@ 103 | @echo >> $@ 104 | @echo "#endif // DESIGN_H" >> $@ 105 | 106 | $(VOBJ)/V%__ALL.a: $(VOBJ)/V%.mk 107 | $(SUBMAKE) V$*.mk 108 | 109 | .PHONY: 110 | archive: 111 | tar --transform s,^,$(YYMMDD)-rtl/, -chjf $(YYMMDD)-rtl.tjz Makefile *.v cpu/*.v 112 | 113 | .PHONY: clean 114 | clean: 115 | rm -rf $(VDIRFB)/*.mk 116 | rm -rf $(VDIRFB)/*.cpp 117 | rm -rf $(VDIRFB)/*.h 118 | rm -rf $(VDIRFB)/ 119 | rm -rf design.h cpudefs.h 120 | 121 | # 122 | # Note Verilator's dependency created information, and include it here if we 123 | # can 124 | DEPS := $(wildcard $(VDIRFB)/*.d) 125 | ifneq ($(MAKECMDGOALS),clean) 126 | ifneq ($(DEPS),) 127 | include $(DEPS) 128 | endif 129 | endif 130 | -------------------------------------------------------------------------------- /rtl/wbubus/wbuoutput.v: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: wbuoutput.v 4 | // 5 | // Project: FPGA library 6 | // 7 | // Purpose: Converts 36-bit codewords into bytes to be placed on the serial 8 | // output port. The codewords themselves are the results of bus 9 | // transactions, which are then (hopefully) compressed within here and 10 | // carefully arranged into "lines" for visual viewing (if necessary). 11 | // 12 | // 13 | // Creator: Dan Gisselquist, Ph.D. 14 | // Gisselquist Technology, LLC 15 | // 16 | //////////////////////////////////////////////////////////////////////////////// 17 | // 18 | // Copyright (C) 2015-2020, Gisselquist Technology, LLC 19 | // 20 | // This program is free software (firmware): you can redistribute it and/or 21 | // modify it under the terms of the GNU General Public License as published 22 | // by the Free Software Foundation, either version 3 of the License, or (at 23 | // your option) any later version. 24 | // 25 | // This program is distributed in the hope that it will be useful, but WITHOUT 26 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 27 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 28 | // for more details. 29 | // 30 | // You should have received a copy of the GNU General Public License along 31 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 32 | // target there if the PDF file isn't present.) If not, see 33 | // for a copy. 34 | // 35 | // License: GPL, v3, as defined and found on www.gnu.org, 36 | // http://www.gnu.org/licenses/gpl.html 37 | // 38 | // 39 | //////////////////////////////////////////////////////////////////////////////// 40 | // 41 | // 42 | `default_nettype none 43 | // 44 | module wbuoutput(i_clk, i_rst, i_stb, i_codword, 45 | i_wb_cyc, i_int, i_bus_busy, 46 | o_stb, o_char, i_tx_busy, o_fifo_err); 47 | parameter LGOUTPUT_FIFO = 10; 48 | input wire i_clk, i_rst; 49 | input wire i_stb; 50 | input wire [35:0] i_codword; 51 | // Not Idle indicators 52 | input wire i_wb_cyc, i_int, i_bus_busy; 53 | // Outputs to our UART transmitter 54 | output wire o_stb; 55 | output wire [7:0] o_char; 56 | // Miscellaneous I/O: UART transmitter busy, and fifo error 57 | input wire i_tx_busy; 58 | output wire o_fifo_err; 59 | 60 | wire fifo_rd, dw_busy, fifo_empty_n, fifo_err; 61 | wire [35:0] fifo_codword; 62 | 63 | wire cw_stb, cw_busy, cp_stb, dw_stb, ln_stb, ln_busy, 64 | cp_busy, byte_busy; 65 | wire [35:0] cw_codword, cp_word; 66 | wire [6:0] dw_bits, ln_bits; 67 | 68 | generate 69 | if (LGOUTPUT_FIFO < 2) 70 | begin : NO_OUTBOUND_FIFO 71 | 72 | assign fifo_rd = i_stb; 73 | assign fifo_codword = i_codword; 74 | assign fifo_err = 1'b0; 75 | 76 | end else begin : OUTBOUND_FIFO 77 | 78 | assign fifo_rd = (fifo_empty_n)&&(!cw_busy); 79 | wbufifo #(36,LGOUTPUT_FIFO) 80 | busoutfifo(i_clk, i_rst, i_stb, i_codword, 81 | fifo_rd, fifo_codword, fifo_empty_n, 82 | fifo_err); 83 | 84 | end endgenerate 85 | 86 | assign o_fifo_err = fifo_err; 87 | 88 | wbuidleint buildcw(i_clk, fifo_rd, fifo_codword, 89 | i_wb_cyc, i_bus_busy, i_int, 90 | cw_stb, cw_codword, cw_busy, cp_stb && cp_busy); 91 | // assign o_dbg = dw_busy; // Always asserted ... ??? 92 | // assign o_dbg = { dw_busy, ln_busy, fifo_rd }; 93 | // Stuck: dw_busy and ln_busy get stuck high after read attempt, 94 | // fifo_rd is low 95 | // assign o_dbg = { fifo_rd, cp_stb, cw_stb }; 96 | // cw_stb and cp_stb get stuck high after one read 97 | 98 | // 99 | // cw_busy & cw_stb, not cp_stb, but dw_busy 100 | // 101 | 102 | // `define SKIP_COMPRESS 103 | `ifdef SKIP_COMPRESS 104 | assign cp_stb = cw_stb; 105 | assign cp_word = cw_codword; 106 | assign cp_busy = dw_busy; 107 | `else 108 | wbucompress packit(i_clk, 1'b0, cw_stb, cw_codword, dw_busy, 109 | cp_stb, cp_word, cp_busy); 110 | `endif 111 | 112 | wbudeword deword(i_clk, cp_stb, cp_word, ln_busy, 113 | dw_stb, dw_bits, dw_busy); 114 | 115 | wbucompactlines linepacker(i_clk, dw_stb, dw_bits, 116 | ln_stb, ln_bits, 117 | (i_wb_cyc||i_bus_busy||fifo_empty_n||cw_busy), 118 | byte_busy, ln_busy); 119 | 120 | wbusixchar mkbytes(i_clk, ln_stb, ln_bits, o_stb, o_char, byte_busy, i_tx_busy); 121 | 122 | endmodule 123 | -------------------------------------------------------------------------------- /sw/zlib/zipsys.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: zipsys.h 4 | // 5 | // Project: ZBasic, a generic toplevel impl using the full ZipCPU 6 | // 7 | // Purpose: Declare the capabilities and memory structure of the ZipSystem 8 | // for programs that must interact with it. 9 | // 10 | // Creator: Dan Gisselquist, Ph.D. 11 | // Gisselquist Technology, LLC 12 | // 13 | //////////////////////////////////////////////////////////////////////////////// 14 | // 15 | // Copyright (C) 2015-2020, Gisselquist Technology, LLC 16 | // 17 | // This program is free software (firmware): you can redistribute it and/or 18 | // modify it under the terms of the GNU General Public License as published 19 | // by the Free Software Foundation, either version 3 of the License, or (at 20 | // your option) any later version. 21 | // 22 | // This program is distributed in the hope that it will be useful, but WITHOUT 23 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 24 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 25 | // for more details. 26 | // 27 | // You should have received a copy of the GNU General Public License along 28 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 29 | // target there if the PDF file isn't present.) If not, see 30 | // for a copy. 31 | // 32 | // License: GPL, v3, as defined and found on www.gnu.org, 33 | // http://www.gnu.org/licenses/gpl.html 34 | // 35 | // 36 | //////////////////////////////////////////////////////////////////////////////// 37 | // 38 | // 39 | #ifndef ZIPSYS_H 40 | #define ZIPSYS_H 41 | 42 | typedef struct { 43 | unsigned ac_ck, ac_mem, ac_pf, ac_icnt; 44 | } ZIPTASKCTRS; 45 | 46 | typedef struct { 47 | int d_ctrl, d_len; 48 | int *d_rd, *d_wr; 49 | } ZIPDMA; 50 | 51 | #define DMA_TRIGGER 0x00008000 52 | #define DMACABORT 0xffed0000 53 | #define DMACLEAR 0xafed0000 54 | #define DMACCOPY 0x0fed0000 55 | #define DMACERR 0x40000000 56 | #define DMA_CONSTSRC 0x20000000 57 | #define DMA_CONSTDST 0x10000000 58 | #define DMAONEATATIME 0x0fed0001 59 | #define DMA_BUSY 0x80000000 60 | #define DMA_ERR 0x40000000 61 | #define DMA_ONINT(INT) (DMA_TRIGGER|(((INT)&15)<<10)) 62 | #define DMA_ONJIFFIES DMA_ONINT(1) 63 | #define DMA_ONTMC DMA_ONINT(2) 64 | #define DMA_ONTMB DMA_ONINT(3) 65 | #define DMA_ONTMA DMA_ONINT(4) 66 | #define DMA_ONAUX DMA_ONINT(5) 67 | 68 | #define TMR_INTERVAL 0x80000000 69 | typedef struct { 70 | int z_pic, z_wdt, z_wbus, z_apic, z_tma, z_tmb, z_tmc, 71 | z_jiffies; 72 | #ifdef _HAVE_ZIPSYS_PERFORMANCE_COUNTERS 73 | ZIPTASKCTRS z_m, z_u; 74 | #else 75 | unsigned z_nocounters[8]; 76 | #endif 77 | #ifdef _HAVE_ZIPSYS_DMA 78 | ZIPDMA z_dma; 79 | #else 80 | unsigned z_nodma[4]; 81 | #endif 82 | } ZIPSYS; 83 | 84 | #define ZIPSYS_ADDR 0xff000000 85 | 86 | #define SYSINT_DMAC 0x0001 87 | #define SYSINT_JIFFIES 0x0002 88 | #define SYSINT_TMC 0x0004 89 | #define SYSINT_TMB 0x0008 90 | #define SYSINT_TMA 0x0010 91 | #define SYSINT_AUX 0x0020 92 | // 93 | #define SYSINT(INTID) (1<<(INTID)) 94 | #define ALTINT(INTID) (1<<(INTID)) 95 | 96 | #ifdef _HAVE_ZIPSYS_PERFORMANCE_COUNTERS 97 | #define ALTINT_UIC ALTINT(0) 98 | #define ALTINT_UTC ALTINT(3) 99 | #define ALTINT_MIC ALTINT(4) 100 | #define ALTINT_MTC ALTINT(7) 101 | #endif 102 | 103 | #define INT_ENABLE 0x80008000 104 | #define EINT(A) (INT_ENABLE|((A)<<16)) 105 | #define DINT(A) ((A)<<16) 106 | #define CLEARPIC 0x7fff7fff 107 | #define DALLPIC 0x7fff0000 // Disable all PIC interrupt sources 108 | #define INTNOW 0x08000 109 | 110 | static volatile ZIPSYS *const _zip = (ZIPSYS *)(ZIPSYS_ADDR); 111 | 112 | static inline void DISABLE_INTS(void) { 113 | _zip->z_pic = 0x80000000; 114 | } 115 | 116 | static inline void ENABLE_INTS(void) { 117 | _zip->z_pic = INT_ENABLE; 118 | } 119 | 120 | typedef struct { 121 | int c_r[16]; 122 | #ifdef _HAVE_ZIPSYS_PERFORMANCE_COUNTERS 123 | unsigned long c_ck, c_mem, c_pf, c_icnt; 124 | #endif 125 | } ZSYSCONTEXT; 126 | 127 | #ifdef _HAVE_ZIPSYS_PERFORMANCE_COUNTERS 128 | void save_contextncntrs(ZSYSCONTEXT *c); 129 | void restore_contextncntrs(ZSYSCONTEXT *c); 130 | #else 131 | #define save_contextncntrs(CONTEXT) save_context((int *)CONTEXT) 132 | #define restore_contextncntrs(CONTEXT) restore_context((int *)CONTEXT) 133 | #endif 134 | 135 | #endif 136 | -------------------------------------------------------------------------------- /sw/host/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | ## 3 | ## Filename: Makefile 4 | ## 5 | ## Project: ZBasic, a generic toplevel impl using the full ZipCPU 6 | ## 7 | ## Purpose: 8 | ## Targets: 9 | ## 10 | ## Creator: Dan Gisselquist, Ph.D. 11 | ## Gisselquist Technology, LLC 12 | ## 13 | ################################################################################ 14 | ## 15 | ## Copyright (C) 2015-2020, Gisselquist Technology, LLC 16 | ## 17 | ## This program is free software (firmware): you can redistribute it and/or 18 | ## modify it under the terms of the GNU General Public License as published 19 | ## by the Free Software Foundation, either version 3 of the License, or (at 20 | ## your option) any later version. 21 | ## 22 | ## This program is distributed in the hope that it will be useful, but WITHOUT 23 | ## ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 24 | ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 25 | ## for more details. 26 | ## 27 | ## You should have received a copy of the GNU General Public License along 28 | ## with this program. (It's in the $(ROOT)/doc directory. Run make with no 29 | ## target there if the PDF file isn't present.) If not, see 30 | ## for a copy. 31 | ## 32 | ## License: GPL, v3, as defined and found on www.gnu.org, 33 | ## http://www.gnu.org/licenses/gpl.html 34 | ## 35 | ## 36 | ################################################################################ 37 | ## 38 | ## 39 | .PHONY: all 40 | PROGRAMS := wbregs netuart zipload zipstate zipdbg 41 | SCOPES := 42 | all: $(PROGRAMS) $(SCOPES) 43 | CXX := g++ 44 | OBJDIR := obj-pc 45 | FLASHDRVR := flashdrvr 46 | BUSSRCS := ttybus.cpp llcomms.cpp regdefs.cpp byteswap.cpp 47 | SOURCES := wbregs.cpp netuart.cpp $(FLASHDRVR).cpp \ 48 | $(BUSSRCS) zipload.cpp zipstate.cpp zipdbg.cpp 49 | # netsetup.cpp manping.cpp wbsettime.cpp 50 | HEADERS := llcomms.h port.h ttybus.h devbus.h 51 | OBJECTS := $(addprefix $(OBJDIR)/,$(subst .cpp,.o,$(SOURCES))) 52 | BUSOBJS := $(addprefix $(OBJDIR)/,$(subst .cpp,.o,$(BUSSRCS))) 53 | CFLAGS := -g -Wall -I. -I../../rtl 54 | LIBS := 55 | SUBMAKE := $(MAKE) --no-print-directory -C 56 | 57 | %.o: $(OBJDIR)/%.o 58 | $(OBJDIR)/%.o: %.cpp 59 | $(mk-objdir) 60 | $(CXX) $(CFLAGS) -c $< -o $@ 61 | $(OBJDIR)/%.o: %.c 62 | $(mk-objdir) 63 | $(CXX) $(CFLAGS) -c $< -o $@ 64 | 65 | .PHONY: clean 66 | clean: 67 | rm -rf $(OBJDIR)/ $(PROGRAMS) a.out 68 | 69 | $(OBJDIR)/dumpflash.o: dumpflash.cpp regdefs.h 70 | 71 | netuart: $(OBJDIR)/netuart.o 72 | $(CXX) $(CFLAGS) $^ -o $@ 73 | # 74 | # Some simple programs that just depend upon the ability to talk to the FPGA, 75 | # and little more. 76 | #manping: $(OBJDIR)/manping.o $(BUSOBJS) 77 | # $(CXX) $(CFLAGS) $^ -o $@ 78 | zipstate: $(OBJDIR)/zipstate.o $(BUSOBJS) 79 | $(CXX) $(CFLAGS) $^ $(LIBS) -o $@ 80 | netsetup: $(OBJDIR)/netsetup.o $(BUSOBJS) 81 | $(CXX) $(CFLAGS) $^ $(LIBS) -o $@ 82 | wbregs: $(OBJDIR)/wbregs.o $(BUSOBJS) 83 | $(CXX) $(CFLAGS) $^ $(LIBS) -o $@ 84 | dumpflash: $(OBJDIR)/dumpflash.o $(BUSOBJS) 85 | $(CXX) $(CFLAGS) $^ $(LIBS) -o $@ 86 | 87 | # 88 | # Programs that depend upon not just the bus objects, but the flash driver 89 | # as well. 90 | wbprogram: $(OBJDIR)/wbprogram.o $(OBJDIR)/$(FLASHDRVR).o $(BUSOBJS) 91 | $(CXX) -g $^ -o $@ 92 | zipload: $(OBJDIR)/zipload.o $(OBJDIR)/$(FLASHDRVR).o $(BUSOBJS) $(OBJDIR)/zipelf.o 93 | $(CXX) -g $^ -lelf -o $@ 94 | 95 | 96 | ## SCOPES 97 | # These depend upon the scopecls.o, the bus objects, as well as their 98 | # main file(s). 99 | 100 | 101 | # 102 | DBGSRCS := zopcodes.cpp twoc.cpp 103 | DBGOBJS := $(addprefix $(OBJDIR)/,$(subst .cpp,.o,$(DBGSRCS))) 104 | zipdbg: $(OBJDIR)/zipdbg.o $(BUSOBJS) $(DBGOBJS) 105 | $(CXX) -g $^ -lcurses -o $@ 106 | 107 | define mk-objdir 108 | @bash -c "if [ ! -e $(OBJDIR) ]; then mkdir -p $(OBJDIR); fi" 109 | endef 110 | 111 | define build-depends 112 | @echo "Building dependency file(s)" 113 | $(mk-objdir) 114 | $(CXX) $(CFLAGS) -MM $(SOURCES) > $(OBJDIR)/xdepends.txt 115 | @sed -e 's/^.*.o: /$(OBJDIR)\/&/' < $(OBJDIR)/xdepends.txt > $(OBJDIR)/depends.txt 116 | @rm $(OBJDIR)/xdepends.txt 117 | endef 118 | 119 | tags: $(SOURCES) $(HEADERS) 120 | @echo "Generating tags" 121 | @ctags $(SOURCES) $(HEADERS) 122 | 123 | .PHONY: depends 124 | depends: tags 125 | $(build-depends) 126 | 127 | $(OBJDIR)/depends.txt: $(SOURCES) $(HEADERS) 128 | $(build-depends) 129 | 130 | ifneq ($(MAKECMDGOALS),clean) 131 | -include $(OBJDIR)/depends.txt 132 | endif 133 | -------------------------------------------------------------------------------- /rtl/wbgpio.v: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: wbgpio.v 4 | // 5 | // Project: ZBasic, a generic toplevel impl using the full ZipCPU 6 | // 7 | // Purpose: This extremely simple GPIO controller, although minimally 8 | // featured, is designed to control up to sixteen general purpose 9 | // input and sixteen general purpose output lines of a module from a 10 | // single address on a 32-bit wishbone bus. 11 | // 12 | // Input GPIO values are contained in the top 16-bits. Any change in 13 | // input values will generate an interrupt. 14 | // 15 | // Output GPIO values are contained in the bottom 16-bits. To change an 16 | // output GPIO value, writes to this port must also set a bit in the 17 | // upper sixteen bits. Hence, to set GPIO output zero, one would write 18 | // a 0x010001 to the port, whereas a 0x010000 would clear the bit. This 19 | // interface makes it possible to change only the bit of interest, without 20 | // needing to capture and maintain the prior bit values--something that 21 | // might be difficult from a interrupt context within a CPU. 22 | // 23 | // Unlike other controllers, this controller offers no capability to 24 | // change input/output direction, or to implement pull-up or pull-down 25 | // resistors. It simply changes and adjusts the values going out the 26 | // output pins, while allowing a user to read the values on the input 27 | // pins. 28 | // 29 | // Any change of an input pin value will result in the generation of an 30 | // interrupt signal. 31 | // 32 | // Creator: Dan Gisselquist, Ph.D. 33 | // Gisselquist Technology, LLC 34 | // 35 | //////////////////////////////////////////////////////////////////////////////// 36 | // 37 | // Copyright (C) 2015-2020, Gisselquist Technology, LLC 38 | // 39 | // This program is free software (firmware): you can redistribute it and/or 40 | // modify it under the terms of the GNU General Public License as published 41 | // by the Free Software Foundation, either version 3 of the License, or (at 42 | // your option) any later version. 43 | // 44 | // This program is distributed in the hope that it will be useful, but WITHOUT 45 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 46 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 47 | // for more details. 48 | // 49 | // You should have received a copy of the GNU General Public License along 50 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 51 | // target there if the PDF file isn't present.) If not, see 52 | // for a copy. 53 | // 54 | // License: GPL, v3, as defined and found on www.gnu.org, 55 | // http://www.gnu.org/licenses/gpl.html 56 | // 57 | // 58 | //////////////////////////////////////////////////////////////////////////////// 59 | // 60 | // 61 | `default_nettype none 62 | // 63 | module wbgpio(i_clk, i_wb_cyc, i_wb_stb, i_wb_we, i_wb_data, i_wb_sel, 64 | o_wb_stall, o_wb_ack, o_wb_data, 65 | i_gpio, o_gpio, o_int); 66 | parameter NIN=16, NOUT=16; 67 | parameter [(NOUT-1):0] DEFAULT=0; 68 | input wire i_clk; 69 | // 70 | input wire i_wb_cyc, i_wb_stb, i_wb_we; 71 | input wire [31:0] i_wb_data; 72 | input wire [32/8-1:0] i_wb_sel; 73 | // 74 | output wire o_wb_stall; 75 | output wire o_wb_ack; 76 | output wire [31:0] o_wb_data; 77 | // 78 | input wire [(NIN-1):0] i_gpio; 79 | output reg [(NOUT-1):0] o_gpio; 80 | // 81 | output reg o_int; 82 | 83 | assign o_wb_ack = i_wb_stb; 84 | assign o_wb_stall = 1'b0; 85 | 86 | // 9LUT's, 16 FF's 87 | initial o_gpio = DEFAULT; 88 | always @(posedge i_clk) 89 | if ((i_wb_stb)&&(i_wb_we)) 90 | o_gpio <= ((o_gpio)&(~i_wb_data[(NOUT+16-1):16])) 91 | |((i_wb_data[(NOUT-1):0])&(i_wb_data[(NOUT+16-1):16])); 92 | 93 | reg [(NIN-1):0] x_gpio, q_gpio, r_gpio; 94 | // 3 LUTs, 33 FF's 95 | always @(posedge i_clk) 96 | begin 97 | { r_gpio, q_gpio, x_gpio } <= { q_gpio, x_gpio, i_gpio }; 98 | o_int <= (x_gpio != q_gpio); 99 | end 100 | 101 | wire [15:0] hi_bits, low_bits; 102 | assign hi_bits[ (NIN -1):0] = r_gpio; 103 | assign low_bits[(NOUT-1):0] = o_gpio; 104 | generate 105 | if (NIN < 16) 106 | assign hi_bits[ 15: NIN] = 0; 107 | if (NOUT < 16) 108 | assign low_bits[15:NOUT] = 0; 109 | endgenerate 110 | 111 | assign o_wb_data = { hi_bits, low_bits }; 112 | 113 | // Make Verilator happy 114 | // verilator lint_off UNUSED 115 | wire unused; 116 | assign unused = &{ 1'b0, i_wb_cyc, i_wb_data[31:0], i_wb_sel }; 117 | // verilator lint_on UNUSED 118 | endmodule 119 | -------------------------------------------------------------------------------- /sw/host/zipstate.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: zipstate.cpp 4 | // 5 | // Project: ZBasic, a generic toplevel impl using the full ZipCPU 6 | // 7 | // Purpose: To get a quick (understandable) peek at what the ZipCPU 8 | // is up to without stopping the CPU. This is basically 9 | // identical to a "wbregs cpu" command, save that the bit fields of the 10 | // result are broken out into something more human readable. 11 | // 12 | // 13 | // Creator: Dan Gisselquist, Ph.D. 14 | // Gisselquist Technology, LLC 15 | // 16 | //////////////////////////////////////////////////////////////////////////////// 17 | // 18 | // Copyright (C) 2015-2020, Gisselquist Technology, LLC 19 | // 20 | // This program is free software (firmware): you can redistribute it and/or 21 | // modify it under the terms of the GNU General Public License as published 22 | // by the Free Software Foundation, either version 3 of the License, or (at 23 | // your option) any later version. 24 | // 25 | // This program is distributed in the hope that it will be useful, but WITHOUT 26 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 27 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 28 | // for more details. 29 | // 30 | // You should have received a copy of the GNU General Public License along 31 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 32 | // target there if the PDF file isn't present.) If not, see 33 | // for a copy. 34 | // 35 | // License: GPL, v3, as defined and found on www.gnu.org, 36 | // http://www.gnu.org/licenses/gpl.html 37 | // 38 | // 39 | //////////////////////////////////////////////////////////////////////////////// 40 | // 41 | // 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | 51 | #include "port.h" 52 | #include "llcomms.h" 53 | #include "regdefs.h" 54 | #include "ttybus.h" 55 | 56 | FPGA *m_fpga; 57 | void closeup(int v) { 58 | m_fpga->kill(); 59 | exit(0); 60 | } 61 | 62 | unsigned int cmd_read(FPGA *fpga, int r) { 63 | const unsigned int MAXERR = 1000; 64 | unsigned int errcount = 0; 65 | unsigned int s; 66 | 67 | fpga->writeio(R_ZIPCTRL, CPU_HALT|(r&0x03f)); 68 | while((((s = fpga->readio(R_ZIPCTRL))&CPU_STALL)== 0)&&(errcount= MAXERR) { 71 | printf("ERR: errcount(%d) >= MAXERR on cmd_read(a=%02x)\n", 72 | errcount, r); 73 | printf("ZIPCTRL = 0x%08x", s); 74 | if ((s & 0x0200)==0) printf(" BUSY"); 75 | if (s & 0x0400) printf(" HALTED"); 76 | if ((s & 0x03000)==0x01000) 77 | printf(" SW-HALT"); 78 | else { 79 | if (s & 0x01000) printf(" SLEEPING"); 80 | if (s & 0x02000) printf(" GIE(UsrMode)"); 81 | } printf("\n"); 82 | exit(EXIT_FAILURE); 83 | } return fpga->readio(R_ZIPDATA); 84 | } 85 | 86 | void usage(void) { 87 | printf("USAGE: zipstate\n"); 88 | } 89 | 90 | int main(int argc, char **argv) { 91 | bool long_state = false; 92 | unsigned int v; 93 | int skp; 94 | 95 | skp=1; 96 | for(int argn=0; argnreadio(R_ZIPCTRL); 109 | 110 | printf("0x%08x: ", v); 111 | if (v & 0x0080) printf("PINT "); 112 | // if (v & 0x0100) printf("STEP "); // self resetting 113 | if((v & 0x00200)==0) printf("BUSY "); 114 | if (v & 0x00400) printf("HALTED "); 115 | if((v & 0x03000)==0x01000) { 116 | printf("SW-HALT"); 117 | } else { 118 | if (v & 0x01000) printf("SLEEPING "); 119 | if (v & 0x02000) printf("GIE(UsrMode) "); 120 | } 121 | // if (v & 0x0800) printf("CLR-CACHE "); 122 | printf("\n"); 123 | } else { 124 | printf("Reading the long-state ...\n"); 125 | for(int i=0; i<14; i++) { 126 | printf("sR%-2d: 0x%08x ", i, cmd_read(m_fpga, i)); 127 | if ((i&3)==3) 128 | printf("\n"); 129 | } printf("sCC : 0x%08x ", cmd_read(m_fpga, 14)); 130 | printf("sPC : 0x%08x ", cmd_read(m_fpga, 15)); 131 | printf("\n\n"); 132 | 133 | for(int i=0; i<14; i++) { 134 | printf("uR%-2d: 0x%08x ", i, cmd_read(m_fpga, i+16)); 135 | if ((i&3)==3) 136 | printf("\n"); 137 | } printf("uCC : 0x%08x ", cmd_read(m_fpga, 14+16)); 138 | printf("uPC : 0x%08x ", cmd_read(m_fpga, 15+16)); 139 | printf("\n\n"); 140 | } 141 | 142 | delete m_fpga; 143 | } 144 | 145 | -------------------------------------------------------------------------------- /rtl/wbubus/wbureadcw.v: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: wbureadcw.v 4 | // 5 | // Project: FPGA library 6 | // 7 | // Purpose: Read bytes from a serial port (i.e. the jtagser) and translate 8 | // those bytes into a 6-byte codeword. This codeword may specify 9 | // a number of values to be read, the value to be written, or an address 10 | // to read/write from, or perhaps the end of a write sequence. 11 | // 12 | // See the encoding documentation file for more information. 13 | // 14 | // 15 | // Creator: Dan Gisselquist, Ph.D. 16 | // Gisselquist Technology, LLC 17 | // 18 | //////////////////////////////////////////////////////////////////////////////// 19 | // 20 | // Copyright (C) 2015-2020, Gisselquist Technology, LLC 21 | // 22 | // This program is free software (firmware): you can redistribute it and/or 23 | // modify it under the terms of the GNU General Public License as published 24 | // by the Free Software Foundation, either version 3 of the License, or (at 25 | // your option) any later version. 26 | // 27 | // This program is distributed in the hope that it will be useful, but WITHOUT 28 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 29 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 30 | // for more details. 31 | // 32 | // You should have received a copy of the GNU General Public License along 33 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 34 | // target there if the PDF file isn't present.) If not, see 35 | // for a copy. 36 | // 37 | // License: GPL, v3, as defined and found on www.gnu.org, 38 | // http://www.gnu.org/licenses/gpl.html 39 | // 40 | // 41 | //////////////////////////////////////////////////////////////////////////////// 42 | // 43 | // 44 | `default_nettype none 45 | // 46 | // Goal: single clock pipeline, 50 slices or less 47 | // 48 | module wbureadcw(i_clk, i_stb, i_valid, i_hexbits, 49 | o_stb, o_codword); 50 | input wire i_clk, i_stb, i_valid; 51 | input wire [5:0] i_hexbits; 52 | output reg o_stb; 53 | output reg [35:0] o_codword; 54 | 55 | 56 | // Timing: 57 | // Clock 0: i_stb is high, i_valid is low 58 | // Clock 1: shiftreg[5:0] is valid, cw_len is valid 59 | // r_len = 1 60 | // Clock 2: o_stb = 1, for cw_len = 1; 61 | // o_codword is 1-byte valid 62 | // i_stb may go high again on this clock as well. 63 | // Clock 3: o_stb = 0 (cw_len=1), 64 | // cw_len = 0, 65 | // r_len = 0 (unless i_stb) 66 | // Ready for next word 67 | 68 | reg [2:0] r_len, cw_len; 69 | reg [1:0] lastcw; 70 | 71 | wire w_stb; 72 | assign w_stb = ((r_len == cw_len)&&(cw_len != 0)) 73 | ||((i_stb)&&(!i_valid)&&(lastcw == 2'b01)); 74 | 75 | // r_len is the length of the codeword as it exists 76 | // in our register 77 | initial r_len = 3'h0; 78 | always @(posedge i_clk) 79 | if ((i_stb)&&(!i_valid)) // Newline reset 80 | r_len <= 0; 81 | else if (w_stb) // reset/restart w/o newline 82 | r_len <= (i_stb)? 3'h1:3'h0; 83 | else if (i_stb) //in middle of word 84 | r_len <= r_len + 3'h1; 85 | 86 | reg [35:0] shiftreg; 87 | 88 | initial shiftreg = 0; 89 | always @(posedge i_clk) 90 | if (w_stb) 91 | shiftreg[35:30] <= i_hexbits; 92 | else if (i_stb) case(r_len) 93 | 3'b000: shiftreg[35:30] <= i_hexbits; 94 | 3'b001: shiftreg[29:24] <= i_hexbits; 95 | 3'b010: shiftreg[23:18] <= i_hexbits; 96 | 3'b011: shiftreg[17:12] <= i_hexbits; 97 | 3'b100: shiftreg[11: 6] <= i_hexbits; 98 | 3'b101: shiftreg[ 5: 0] <= i_hexbits; 99 | default: begin end 100 | endcase 101 | 102 | initial lastcw = 2'b00; 103 | always @(posedge i_clk) 104 | if (o_stb) 105 | lastcw <= o_codword[35:34]; 106 | always @(posedge i_clk) 107 | if ((i_stb)&&(!i_valid)&&(lastcw == 2'b01)) 108 | o_codword[35:30] <= 6'h2e; 109 | else 110 | o_codword <= shiftreg; 111 | 112 | // How long do we expect this codeword to be? 113 | initial cw_len = 3'b000; 114 | always @(posedge i_clk) 115 | if ((i_stb)&&(!i_valid)) 116 | cw_len <= 0; 117 | else if ((i_stb)&&((cw_len == 0)||(w_stb))) 118 | begin 119 | if (i_hexbits[5:4] == 2'b11) // 2b vector read 120 | cw_len <= 3'h2; 121 | else if (i_hexbits[5:4] == 2'b10) // 1b vector read 122 | cw_len <= 3'h1; 123 | else if (i_hexbits[5:3] == 3'b010) // 2b compressed wr 124 | cw_len <= 3'h2; 125 | else if (i_hexbits[5:3] == 3'b001) // 2b compressed addr 126 | cw_len <= 3'b010 + { 1'b0, i_hexbits[2:1] }; 127 | else // long write or set address 128 | cw_len <= 3'h6; 129 | end else if (w_stb) 130 | cw_len <= 0; 131 | 132 | initial o_stb = 1'b0; 133 | always @(posedge i_clk) 134 | o_stb <= w_stb; 135 | 136 | endmodule 137 | 138 | -------------------------------------------------------------------------------- /sw/host/ttybus.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: ttybus.h 4 | // 5 | // Project: ZBasic, a generic toplevel impl using the full ZipCPU 6 | // 7 | // Purpose: This is the C++ program on the command side that will interact 8 | // with a UART on an FPGA, to command the WISHBONE on that same 9 | // FPGA to ... whatever we wish to command it to do. 10 | // 11 | // This code does not run on an FPGA, is not a test bench, neither 12 | // is it a simulator. It is a portion of a command program 13 | // for commanding an FPGA. 14 | // 15 | // This particular implementation is a complete rewrite of the 16 | // last implementation, adding compression into the interface that 17 | // wasn't there before. 18 | // 19 | // 20 | // Creator: Dan Gisselquist, Ph.D. 21 | // Gisselquist Technology, LLC 22 | // 23 | //////////////////////////////////////////////////////////////////////////////// 24 | // 25 | // Copyright (C) 2015-2020, Gisselquist Technology, LLC 26 | // 27 | // This program is free software (firmware): you can redistribute it and/or 28 | // modify it under the terms of the GNU General Public License as published 29 | // by the Free Software Foundation, either version 3 of the License, or (at 30 | // your option) any later version. 31 | // 32 | // This program is distributed in the hope that it will be useful, but WITHOUT 33 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 34 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 35 | // for more details. 36 | // 37 | // You should have received a copy of the GNU General Public License along 38 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 39 | // target there if the PDF file isn't present.) If not, see 40 | // for a copy. 41 | // 42 | // License: GPL, v3, as defined and found on www.gnu.org, 43 | // http://www.gnu.org/licenses/gpl.html 44 | // 45 | // 46 | //////////////////////////////////////////////////////////////////////////////// 47 | // 48 | // 49 | // 50 | #ifndef TTYBUS_H 51 | #define TTYBUS_H 52 | 53 | #include "llcomms.h" 54 | #include "devbus.h" 55 | 56 | #define RDBUFLN 2048 57 | 58 | class TTYBUS : public DEVBUS { 59 | public: 60 | unsigned long m_total_nread; 61 | private: 62 | LLCOMMSI *m_dev; 63 | static const unsigned MAXRDLEN, MAXWRLEN; 64 | 65 | bool m_interrupt_flag, m_decode_err, m_addr_set, m_bus_err; 66 | unsigned int m_lastaddr; 67 | 68 | int m_buflen, m_rdfirst, m_rdlast; 69 | char *m_buf, *m_rdbuf; 70 | 71 | bool m_wrloaded; 72 | int m_rdaddr, m_wraddr; 73 | BUSW m_readtbl[1024], m_writetbl[512]; 74 | 75 | void init(void) { 76 | m_total_nread = 0; 77 | m_interrupt_flag = false; 78 | m_buflen = 0; m_buf = NULL; 79 | m_addr_set = false; 80 | bufalloc(64); 81 | m_bus_err = false; 82 | m_decode_err = false; 83 | m_wrloaded = false; 84 | 85 | m_rdfirst = m_rdlast = 0; 86 | m_rdbuf = new char[RDBUFLN]; 87 | 88 | m_rdaddr = m_wraddr = 0; 89 | } 90 | 91 | char charenc(const int sixbitval) const; 92 | unsigned chardec(const char b) const; 93 | void encode(const int fbits, const BUSW v, char *buf) const; 94 | unsigned decodestr(const char *buf) const; 95 | int decodehex(const char hx) const; 96 | void bufalloc(int len); 97 | BUSW readword(void); // Reads a word value from the bus 98 | void readv(const BUSW a, const int inc, const int len, BUSW *buf); 99 | void writev(const BUSW a, const int p, const int len, const BUSW *buf); 100 | void readidle(void); 101 | 102 | int lclread(char *buf, int len); 103 | int lclreadcode(char *buf, int len); 104 | char *encode_address(const BUSW a); 105 | char *readcmd(const int inc, const int len, char *buf); 106 | public: 107 | TTYBUS(LLCOMMSI *comms) : m_dev(comms) { init(); } 108 | virtual ~TTYBUS(void) { 109 | m_dev->close(); 110 | if (m_buf) { delete[] m_buf; m_buf = NULL; } 111 | delete m_rdbuf; m_rdbuf = NULL; 112 | delete m_dev; 113 | } 114 | 115 | void kill(void) { m_dev->close(); } 116 | void close(void) { m_dev->close(); } 117 | void writeio(const BUSW a, const BUSW v); 118 | BUSW readio(const BUSW a); 119 | void readi( const BUSW a, const int len, BUSW *buf); 120 | void readz( const BUSW a, const int len, BUSW *buf); 121 | void writei(const BUSW a, const int len, const BUSW *buf); 122 | void writez(const BUSW a, const int len, const BUSW *buf); 123 | bool poll(void) { return m_interrupt_flag; }; 124 | void usleep(unsigned msec); // Sleep until interrupt 125 | void wait(void); // Sleep until interrupt 126 | bool bus_err(void) const { return m_bus_err; }; 127 | void reset_err(void) { m_bus_err = false; } 128 | void clear(void) { m_interrupt_flag = false; } 129 | }; 130 | 131 | typedef TTYBUS FPGA; 132 | 133 | #endif 134 | -------------------------------------------------------------------------------- /rtl/wbubus/wbuidleint.v: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: wbuidleint.v 4 | // 5 | // Project: FPGA library 6 | // 7 | // Purpose: Creates an output for the interface, inserting idle words and 8 | // words indicating an interrupt has taken place into the output 9 | // stream. Henceforth, the output means more than just bus transaction 10 | // results. It may mean there is no bus transaction result to report, 11 | // or that an interrupt has taken place. 12 | // 13 | // 14 | // Creator: Dan Gisselquist, Ph.D. 15 | // Gisselquist Technology, LLC 16 | // 17 | //////////////////////////////////////////////////////////////////////////////// 18 | // 19 | // Copyright (C) 2015-2020, Gisselquist Technology, LLC 20 | // 21 | // This program is free software (firmware): you can redistribute it and/or 22 | // modify it under the terms of the GNU General Public License as published 23 | // by the Free Software Foundation, either version 3 of the License, or (at 24 | // your option) any later version. 25 | // 26 | // This program is distributed in the hope that it will be useful, but WITHOUT 27 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 28 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 29 | // for more details. 30 | // 31 | // You should have received a copy of the GNU General Public License along 32 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 33 | // target there if the PDF file isn't present.) If not, see 34 | // for a copy. 35 | // 36 | // License: GPL, v3, as defined and found on www.gnu.org, 37 | // http://www.gnu.org/licenses/gpl.html 38 | // 39 | // 40 | //////////////////////////////////////////////////////////////////////////////// 41 | // 42 | // 43 | `default_nettype none 44 | // 45 | module wbuidleint(i_clk, i_stb, i_codword, i_cyc, i_busy, i_int, 46 | o_stb, o_codword, o_busy, 47 | i_tx_busy); 48 | localparam CW_INTERRUPT = { 6'h4, 30'h0000 }; // interrupt codeword 49 | localparam CW_BUSBUSY = { 6'h1, 30'h0000 }; // bus busy, ow idle 50 | localparam CW_IDLE = { 6'h0, 30'h0000 }; // idle codeword 51 | 52 | input wire i_clk; 53 | // From the FIFO following the bus executor 54 | input wire i_stb; 55 | input wire [35:0] i_codword; 56 | // From the rest of the board 57 | input wire i_cyc, i_busy, i_int; 58 | // To the next stage 59 | output reg o_stb; 60 | output reg [35:0] o_codword; 61 | output reg o_busy; 62 | // Is the next stage busy? 63 | input wire i_tx_busy; 64 | 65 | reg int_request, int_sent; 66 | wire idle_expired; 67 | reg idle_state; 68 | reg [IDLEBITS-1:0] idle_counter; 69 | 70 | initial int_request = 1'b0; 71 | always @(posedge i_clk) 72 | if((o_stb)&&(!i_tx_busy)&&(o_codword[35:30]==6'h4)) 73 | int_request <= i_int; 74 | else 75 | int_request <= (int_request)||(i_int); 76 | 77 | `ifdef VERILATOR 78 | localparam IDLEBITS = 22; 79 | `else 80 | localparam IDLEBITS = 31; 81 | `endif 82 | // Now, for the idle counter 83 | initial idle_counter = 0; 84 | always @(posedge i_clk) 85 | if ((i_stb)||(o_stb)||(i_busy)) 86 | idle_counter <= 0; 87 | else if (!idle_counter[IDLEBITS-1]) 88 | idle_counter <= idle_counter + 1; 89 | 90 | initial idle_state = 1'b0; 91 | always @(posedge i_clk) 92 | if ((o_stb)&&(!i_tx_busy)&&(o_codword[35:30]==CW_IDLE[35:30])) 93 | // We are now idle, and can rest 94 | idle_state <= 1'b1; 95 | else if (!idle_counter[IDLEBITS-1]) 96 | // We became active, and can rest no longer 97 | idle_state <= 1'b0; 98 | 99 | assign idle_expired = (!idle_state)&&(idle_counter[IDLEBITS-1]); 100 | 101 | initial o_stb = 1'b0; 102 | always @(posedge i_clk) 103 | if(!o_stb || !i_tx_busy) 104 | begin 105 | if (i_stb) 106 | begin // On a valid output, just send it out 107 | // We'll open this strobe, even if the transmitter 108 | // is busy, just 'cause we might otherwise lose it 109 | o_stb <= 1'b1; 110 | o_codword <= i_codword; 111 | end else begin 112 | // Our indicators take a clock to reset, hence 113 | // we'll idle for one clock before sending either an 114 | // interrupt or an idle indicator. The bus busy 115 | // indicator is really only ever used to let us know 116 | // that something's broken. 117 | o_stb <= (!o_stb)&&(int_request || idle_expired); 118 | 119 | if (int_request && !int_sent) 120 | o_codword[35:30] <= CW_INTERRUPT[35:30]; 121 | else begin 122 | o_codword[35:30] <= CW_IDLE[35:30]; 123 | if (i_cyc) 124 | o_codword[35:30] <= CW_BUSBUSY[35:30]; 125 | end 126 | end 127 | end 128 | 129 | always @(*) 130 | o_busy = o_stb; 131 | 132 | initial int_sent = 1'b0; 133 | always @(posedge i_clk) 134 | if ((int_request)&&((!o_stb)&&(!o_busy)&&(!i_stb))) 135 | int_sent <= 1'b1; 136 | else if (~i_int) 137 | int_sent <= 1'b0; 138 | 139 | endmodule 140 | -------------------------------------------------------------------------------- /sim/verilated/memsim.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Filename: memsim.cpp 4 | // 5 | // Project: ZBasic, a generic toplevel impl using the full ZipCPU 6 | // 7 | // Purpose: This creates a memory like device to act on a WISHBONE bus. 8 | // It doesn't exercise the bus thoroughly, but does give some 9 | // exercise to the bus to see whether or not the bus master can control 10 | // it. 11 | // 12 | // This particular version differs from the memsim version within the 13 | // ZipCPU project in that there is a variable delay from request to 14 | // completion. 15 | // 16 | // 17 | // Creator: Dan Gisselquist, Ph.D. 18 | // Gisselquist Technology, LLC 19 | // 20 | //////////////////////////////////////////////////////////////////////////////// 21 | // 22 | // Copyright (C) 2015-2019, Gisselquist Technology, LLC 23 | // 24 | // This program is free software (firmware): you can redistribute it and/or 25 | // modify it under the terms of the GNU General Public License as published 26 | // by the Free Software Foundation, either version 3 of the License, or (at 27 | // your option) any later version. 28 | // 29 | // This program is distributed in the hope that it will be useful, but WITHOUT 30 | // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or 31 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 32 | // for more details. 33 | // 34 | // You should have received a copy of the GNU General Public License along 35 | // with this program. (It's in the $(ROOT)/doc directory. Run make with no 36 | // target there if the PDF file isn't present.) If not, see 37 | // for a copy. 38 | // 39 | // License: GPL, v3, as defined and found on www.gnu.org, 40 | // http://www.gnu.org/licenses/gpl.html 41 | // 42 | // 43 | //////////////////////////////////////////////////////////////////////////////// 44 | // 45 | // 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include "memsim.h" 51 | 52 | MEMSIM::MEMSIM(const unsigned int nwords, const unsigned int delay) { 53 | unsigned int nxt; 54 | for(nxt=1; nxt < nwords; nxt<<=1) 55 | ; 56 | m_len = nxt; m_mask = nxt-1; 57 | m_mem = new BUSW[m_len]; 58 | 59 | m_delay = delay; 60 | for(m_delay_mask=1; m_delay_mask < delay; m_delay_mask<<=1) 61 | ; 62 | m_fifo_ack = new int[m_delay_mask]; 63 | m_fifo_data = new BUSW[m_delay_mask]; 64 | for(unsigned i=0; i for a copy. 34 | ## 35 | ## License: GPL, v3, as defined and found on www.gnu.org, 36 | ## http://www.gnu.org/licenses/gpl.html 37 | ## 38 | ## 39 | ################################################################################ 40 | ## 41 | ## 42 | .PHONY: all 43 | # Make certain the "all" target is the first and therefore the default target 44 | all: 45 | CXX := g++ 46 | OBJDIR := obj-pc 47 | RTLD := ../../rtl 48 | VOBJDR := $(RTLD)/obj_dir 49 | VERILATOR_ROOT ?= $(shell bash -c 'verilator -V|grep VERILATOR_ROOT | head -1 | sed -e " s/^.*=\s*//"') 50 | VROOT := $(VERILATOR_ROOT) 51 | VDEFS := $(shell ./vversion.sh) 52 | VINCD := $(VROOT)/include 53 | VINC := -I$(VINCD) -I$(VINCD)/vltstd -I$(VOBJDR) 54 | INCS := -I../../sw/host -I$(RTLD) $(VINC) 55 | CFLAGS := -Og -g -Wall -faligned-new $(INCS) 56 | # CFLAGS := -Og -g -Wall $(INCS) -faligned-new 57 | # 58 | # A list of our sources and headers 59 | # 60 | SIMSOURCES:= flashsim.cpp sdspisim.cpp dbluartsim.cpp zipelf.cpp byteswap.cpp 61 | SIMOBJECTS:= $(addprefix $(OBJDIR)/,$(subst .cpp,.o,$(SIMSOURCES))) 62 | SIMHEADERS:= $(foreach header,$(subst .cpp,.h,$(SIMSOURCES)),$(wildcard $(header))) 63 | VOBJS := $(OBJDIR)/verilated.o $(OBJDIR)/verilated_vcd_c.o 64 | SIMOBJ := $(subst .cpp,.o,$(SIMSOURCES)) 65 | SIMOBJS:= $(addprefix $(OBJDIR)/,$(SIMOBJ)) $(VOBJS) 66 | 67 | SOURCES := $(SIMSOURCES) main_tb.cpp automaster_tb.cpp 68 | HEADERS := $(foreach header,$(subst .cpp,.h,$(SOURCES)),$(wildcard $(header))) 69 | # 70 | PROGRAMS := main_tb 71 | # Now the return to the "all" target, and fill in some details 72 | all: $(PROGRAMS) 73 | 74 | $(OBJDIR)/%.o: %.cpp 75 | $(mk-objdir) 76 | $(CXX) $(CFLAGS) $(VDEFS) $(INCS) -c $< -o $@ 77 | 78 | $(OBJDIR)/%.o: $(VINCD)/%.cpp 79 | $(mk-objdir) 80 | $(CXX) $(CFLAGS) $(INCS) -c $< -o $@ 81 | 82 | 83 | MAINOBJS := $(OBJDIR)/main_tb.o $(OBJDIR)/automaster_tb.o 84 | main_tb: $(MAINOBJS) $(SIMOBJECTS) $(VOBJS) $(VOBJDR)/Vmain__ALL.a 85 | $(CXX) $(INCS) $(VDEFS) $^ $(VOBJDR)/Vmain__ALL.a -lelf -o $@ 86 | 87 | # 88 | # Build a 64M SD-card image file that we can use for testing 89 | sdcard.img: 90 | dd if=/dev/zero of=$@ bs=512 count=131072 91 | mkfs.fat $@ 92 | # 93 | # The "test" target, running hello world 94 | # 95 | .PHONY: test 96 | test: 97 | ./main_tb -d ../../sw/board/hello 98 | 99 | # 100 | # The "clean" target, removing any and all remaining build products 101 | # 102 | .PHONY: clean 103 | clean: 104 | rm -f *.vcd 105 | rm -f $(PROGRAMS) 106 | rm -rf $(OBJDIR)/ 107 | 108 | # 109 | # The "depends" target, to know what files things depend upon. The depends 110 | # file itself is kept in $(OBJDIR)/depends.txt 111 | # 112 | define build-depends 113 | $(mk-objdir) 114 | @echo "Building dependency file" 115 | @$(CXX) $(CFLAGS) $(INCS) -MM $(SOURCES) > $(OBJDIR)/xdepends.txt 116 | @sed -e 's/^.*.o: /$(OBJDIR)\/&/' < $(OBJDIR)/xdepends.txt > $(OBJDIR)/depends.txt 117 | @rm $(OBJDIR)/xdepends.txt 118 | endef 119 | 120 | .PHONY: depends 121 | depends: tags 122 | $(build-depends) 123 | 124 | $(OBJDIR)/depends.txt: depends 125 | 126 | # 127 | define mk-objdir 128 | @bash -c "if [ ! -e $(OBJDIR) ]; then mkdir -p $(OBJDIR); fi" 129 | endef 130 | 131 | 132 | # 133 | # The "tags" target 134 | # 135 | tags: $(SOURCES) $(HEADERS) 136 | @echo "Generating tags" 137 | @ctags $(SOURCES) $(HEADERS) 138 | 139 | 140 | ifneq ($(MAKECMDGOALS),clean) 141 | -include $(OBJDIR)/depends.txt 142 | endif 143 | --------------------------------------------------------------------------------