{"id":511,"date":"2013-05-18T19:11:29","date_gmt":"2013-05-18T19:11:29","guid":{"rendered":"http:\/\/retroramblings.net\/?p=511"},"modified":"2026-08-14T12:56:44","modified_gmt":"2026-08-14T12:56:44","slug":"and-now-the-fun-begins","status":"publish","type":"post","link":"http:\/\/retroramblings.net\/?p=511","title":{"rendered":"And now the fun begins!"},"content":{"rendered":"<p>Things are getting interesting with the ZPU core, and it&#8217;s now pretty much where I want it for inclusion into other projects.<br \/>\n<a href=\"http:\/\/retroramblings.net\/wp-content\/uploads\/2013\/05\/dhry.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/retroramblings.net\/wp-content\/uploads\/2013\/05\/dhry.jpg\" alt=\"dhry\" width=\"667\" height=\"500\" class=\"alignnone size-full wp-image-512\" srcset=\"http:\/\/retroramblings.net\/wp-content\/uploads\/2013\/05\/dhry.jpg 667w, http:\/\/retroramblings.net\/wp-content\/uploads\/2013\/05\/dhry-300x224.jpg 300w, http:\/\/retroramblings.net\/wp-content\/uploads\/2013\/05\/dhry-400x300.jpg 400w\" sizes=\"auto, (max-width: 667px) 100vw, 667px\" \/><\/a><br \/>\n<!--more--><br \/>\nFor use as a ROM loader in the PACE project I needed something that wouldn&#8217;t eat either too many logic elements or Block RAMs, and the ZPU looked to be the ideal candidate.  It may also be possible to use it as an IDE-to-SD Card bridge for certain older projects that expect to run from Compact Flash card, but time will tell.<\/p>\n<p>My first experiments with loading files from SD card worked out fairly well, but the code size was quite large &#8211; I was struggling to stay within 8KB (16 M4K blocks!), and had not a hope of squeezing it into 4KB.  A big part of the problem was the emulation block at the beginning of the ROM.  The first kilobyte or so in a ZPU program is devoted to software implementations of the optional instructions.  Whether this code is ever used depends upon which variant of the CPU core is in use, and also which compiler flags are supplied when building the program, so my goal over the last few days has been to eliminate the need for emulated instructions in the Boot ROM without bloating the ZPU itself too much.<\/p>\n<p>It&#8217;s possible to prevent the compiler emitting some of the optional instructions, by way of the -mno-??? switches.  A complete list can be found by typing &#8220;zpu-elf-gcc &#8211;target-help&#8221;.<\/p>\n<p>The first snag is that the pre-compiled toolchain has a bug which prevents the -mno-neg switch from working.  I&#8217;ve submitted a patch, and the <a href=\"http:\/\/repo.or.cz\/w\/zpugcc.git\">repo here<\/a> contains the fix, but there&#8217;s no fixed binary as yet.<\/p>\n<p>The -mno-*shift* flags also don&#8217;t work, and cause GCC to throw an internal error instead of emitting equivalent code.  This means that in order to remove the emulation table I have no choice but to implement the shift instructions in HDL.  This I have now done, along with a few other instructions.  If I ask the compiler not to emit a select few instructions, like so:<\/p>\n<pre>-mno-poppcrel -mno-pushspadd -mno-callpcrel -mno-byteop -mno-shortop -mno-neg<\/pre>\n<p>Then I can get away with omitting the exception table, provided I don&#8217;t use division or modulo in the Boot ROM.<br \/>\nIn combination with enabling &#8220;relaxation&#8221; while linking, by supplying the following argument to the linker:<\/p>\n<pre>-Wl,--relax<\/pre>\n<p>the Boot ROM is now under 4k.<\/p>\n<p>The Boot ROM currently loads a splash screen into SDRAM, then loads and runs dhry.bin, which does a Dhrystone benchmark and prints the result to the RS232 serial port.<\/p>\n<p>The CPU itself now takes just under 965 logic elements, runs at 133Mhz and turns in a shade over 1.5 DMIPS when running from uncached SDRAM.<br \/>\nThe entire SoC with CPU, SDRAM controller, VGA controller, SPI and UART takes 2001 logic elements.<\/p>\n<p>For anyone interested in playing with this, source is on my GitHub page, and I&#8217;ve also made a <a href=\"http:\/\/retroramblings.net\/snapshots\/ZPUTest_Snapshot_20130518.zip\">binary snapshot<\/a> for the DE1 board, based on <a href=\"https:\/\/github.com\/robinsonb5\/ZPUTest\/tree\/20130518\">this tag<\/a>.<br \/>\n(Put dhry.bin and splash.raw on an SD card, and upload the .sof file to the DE1 board.)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Things are getting interesting with the ZPU core, and it&#8217;s now pretty much where I want it for inclusion into other projects.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-511","post","type-post","status-publish","format-standard","hentry","category-fpga"],"_links":{"self":[{"href":"http:\/\/retroramblings.net\/index.php?rest_route=\/wp\/v2\/posts\/511","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/retroramblings.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/retroramblings.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/retroramblings.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/retroramblings.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=511"}],"version-history":[{"count":4,"href":"http:\/\/retroramblings.net\/index.php?rest_route=\/wp\/v2\/posts\/511\/revisions"}],"predecessor-version":[{"id":2122,"href":"http:\/\/retroramblings.net\/index.php?rest_route=\/wp\/v2\/posts\/511\/revisions\/2122"}],"wp:attachment":[{"href":"http:\/\/retroramblings.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=511"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/retroramblings.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=511"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/retroramblings.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=511"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}