diff options
| author | Alejandro Soto <alejandro@34project.org> | 2022-11-17 08:17:04 -0600 |
|---|---|---|
| committer | Alejandro Soto <alejandro@34project.org> | 2022-11-17 08:53:38 -0600 |
| commit | 3b62a23705e93f3786402157fc95fd256d850041 (patch) | |
| tree | bccc8e2a835fccaee23804fe2028ee05efa454ae | |
| parent | 61bf2100fbd5e0a5f4bd1f013d70d8027604bbba (diff) | |
Implement sim test: descifrador
| -rw-r--r-- | tb/const.hpp | 38 | ||||
| -rw-r--r-- | tb/sim/descifrador.py | 20 | ||||
| -rwxr-xr-x | tb/sim/sim.py | 6 | ||||
| -rw-r--r-- | tb/top/conspiracion.cpp | 82 |
4 files changed, 144 insertions, 2 deletions
diff --git a/tb/const.hpp b/tb/const.hpp new file mode 100644 index 0000000..4ccad3e --- /dev/null +++ b/tb/const.hpp @@ -0,0 +1,38 @@ +#ifndef TALLER_CONST_HPP +#define TALLER_CONST_HPP + +#include <cstdint> +#include <memory> + +#include "avalon.hpp" + +namespace taller::avalon +{ + class const_map : public slave + { + public: + inline const_map(std::uint32_t addr, std::uint32_t value, std::uint32_t size = 4) noexcept + : slave(addr, size, 4), + value(value) + {} + + inline virtual bool read(std::uint32_t addr, std::uint32_t &data) final override + { + data = value; + return true; + } + + inline virtual bool write + ( + std::uint32_t addr, std::uint32_t data, unsigned byte_enable = 0b1111 + ) final override + { + return true; + } + + private: + std::uint32_t value; + }; +} + +#endif diff --git a/tb/sim/descifrador.py b/tb/sim/descifrador.py index 8fda8b8..2253e6f 100644 --- a/tb/sim/descifrador.py +++ b/tb/sim/descifrador.py @@ -1,2 +1,20 @@ +FILE = 'image_processing/out_file' +SIZE = 640 * 480 * 4 +START = 0x10000 + +loads = {START: FILE} +consts = {0x30050000: 1, 0x30060000: 0} +cycles = 10000000 +mem_dumps = [range(START, START + SIZE)] + def final(): - pass
\ No newline at end of file + words = [] + i = 0 + with open(FILE, 'rb') as file: + while data := file.read(4): + words.append(int.from_bytes(data, 'little') ^ 0x00ffffff) + i += 1 + if i == 10: + break + + assert_mem(START, words) diff --git a/tb/sim/sim.py b/tb/sim/sim.py index 0c8b023..b14e0fd 100755 --- a/tb/sim/sim.py +++ b/tb/sim/sim.py @@ -261,6 +261,12 @@ for rng in mem_dumps: for r, value in init_regs.items(): exec_args.extend(['--init-reg', f'{r}={value}']) +for addr, const in module_get('consts', {}).items(): + exec_args.extend(['--const', f'{addr},{const}']) + +for addr, filename in module_get('loads', {}).items(): + exec_args.extend(['--load', f'{addr},{filename}']) + init_regs = None exec_args.append(image) diff --git a/tb/top/conspiracion.cpp b/tb/top/conspiracion.cpp index 8e81c84..c87d09c 100644 --- a/tb/top/conspiracion.cpp +++ b/tb/top/conspiracion.cpp @@ -4,6 +4,7 @@ #include <cstring> #include <iostream> #include <string> +#include <vector> #include <verilated.h> #include <verilated_vcd_c.h> @@ -21,6 +22,7 @@ #include "../args.hxx" #include "../avalon.hpp" +#include "../const.hpp" #include "../mem.hpp" #include "../jtag_uart.hpp" #include "../null.hpp" @@ -75,6 +77,18 @@ namespace std::uint32_t value; }; + struct mem_init + { + std::uint32_t addr; + std::uint32_t value; + }; + + struct file_load + { + std::uint32_t addr; + std::string filename; + }; + std::istream &operator>>(std::istream &stream, mem_region ®ion) { stream >> region.start; @@ -89,6 +103,34 @@ namespace return stream; } + std::istream &operator>>(std::istream &stream, mem_init &init) + { + stream >> init.addr; + if(stream.get() == ',') + { + stream >> init.value; + } else + { + stream.setstate(std::istream::failbit); + } + + return stream; + } + + std::istream &operator>>(std::istream &stream, file_load &load) + { + stream >> load.addr; + if(stream.get() == ',') + { + stream >> load.filename; + } else + { + stream.setstate(std::istream::failbit); + } + + return stream; + } + std::istream &operator>>(std::istream &stream, reg_init &init) { char name[16]; @@ -159,6 +201,16 @@ int main(int argc, char **argv) parser, "addr,length", "Dump a memory region", {"dump-mem"} ); + args::ValueFlagList<mem_init> const_ + ( + parser, "addr,value", "Add a constant map", {"const"} + ); + + args::ValueFlagList<file_load> loads + ( + parser, "addr,filename", "Load a file", {"load"} + ); + args::Positional<std::string> image ( parser, "image", "Executable image to run", args::Options::Required @@ -199,16 +251,27 @@ int main(int argc, char **argv) mem<std::uint32_t> hps_ddr3(0x0000'0000, 512 << 20); jtag_uart ttyj0(0x3000'0000); - mem<std::uint16_t> vram(0x3800'0000, 64 << 20); + mem<std::uint32_t> vram(0x3800'0000, 64 << 20); null vram_null(0x3800'0000, 64 << 20, 2); window vram_window(vram, 0x0000'0000); display<Vconspiracion_vga_domain> vga(*top.conspiracion->plat->vga, 25'175'000); + std::vector<const_map> consts; + for(const auto &init : *const_) + { + consts.emplace_back(init.addr, init.value); + } + bool enable_video = !headless; avl.attach(hps_ddr3); avl.attach(ttyj0); + for(auto &slave : consts) + { + avl.attach(slave); + } + if(enable_video) { avl.attach(vram); @@ -232,6 +295,23 @@ int main(int argc, char **argv) std::fclose(img_file); + for(const auto &load : *loads) + { + FILE *img_file = std::fopen(load.filename.c_str(), "rb"); + if(!img_file) + { + std::perror("fopen()"); + return EXIT_FAILURE; + } + + hps_ddr3.load([&](std::uint32_t *buffer, std::size_t words) + { + return std::fread(buffer, 4, words, img_file); + }, load.addr); + + std::fclose(img_file); + } + for(const auto &init : init_regs) { auto ®s = *top.conspiracion->core->regs; |
