From d8c3157bf889f3d57f014805417172d7f227b5fc Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Thu, 16 Jul 2015 11:10:02 +0200 Subject: [PATCH] Improved firmware for vivado "system" example --- Makefile | 2 +- dhrystone/Makefile | 2 +- firmware/makehex.py | 9 ++++++--- scripts/vivado/Makefile | 6 +++--- scripts/vivado/firmware.c | 31 ++++++++++++++++++++++++++++++- 5 files changed, 41 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 897f5cb..b5244ce 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,7 @@ synth.v: picorv32.v scripts/yosys/synth_sim.ys yosys -qv3 -l synth.log scripts/yosys/synth_sim.ys firmware/firmware.hex: firmware/firmware.bin firmware/makehex.py - python3 firmware/makehex.py $< > $@ + python3 firmware/makehex.py $< 16384 > $@ firmware/firmware.bin: firmware/firmware.elf $(TOOLCHAIN_PREFIX)objcopy -O binary $< $@ diff --git a/dhrystone/Makefile b/dhrystone/Makefile index 7e077b1..e799037 100644 --- a/dhrystone/Makefile +++ b/dhrystone/Makefile @@ -18,7 +18,7 @@ timing.exe: testbench.v ../picorv32.v chmod -x timing.exe dhry.hex: dhry.bin ../firmware/makehex.py - python3 ../firmware/makehex.py $< > $@ + python3 ../firmware/makehex.py $< 16384 > $@ dhry.bin: dhry.elf riscv64-unknown-elf-objcopy -O binary $< $@ diff --git a/firmware/makehex.py b/firmware/makehex.py index 1735d86..70282c2 100644 --- a/firmware/makehex.py +++ b/firmware/makehex.py @@ -9,13 +9,16 @@ from sys import argv -with open(argv[1], "rb") as f: +binfile = argv[1] +nwords = int(argv[2]) + +with open(binfile, "rb") as f: bindata = f.read() -assert len(bindata) < 60*1024 +assert len(bindata) < 4*nwords assert len(bindata) % 4 == 0 -for i in range(64*1024//4): +for i in range(nwords): if i < len(bindata) // 4: w = bindata[4*i : 4*i+4] print("%02x%02x%02x%02x" % (w[3], w[2], w[1], w[0])) diff --git a/scripts/vivado/Makefile b/scripts/vivado/Makefile index 3b46bf3..71de1a9 100644 --- a/scripts/vivado/Makefile +++ b/scripts/vivado/Makefile @@ -38,9 +38,9 @@ sim_system: firmware.hex: firmware.S firmware.c firmware.lds $(TOOLCHAIN_PREFIX)gcc -Os -m32 -ffreestanding -nostdlib -o firmware.elf firmware.S firmware.c \ - -Wl,-Bstatic,-T,firmware.lds,-Map,firmware.map,--strip-debug -lgcc + --std=gnu99 -Wl,-Bstatic,-T,firmware.lds,-Map,firmware.map,--strip-debug -lgcc $(TOOLCHAIN_PREFIX)objcopy -O binary firmware.elf firmware.bin - python3 ../../firmware/makehex.py firmware.bin > firmware.hex + python3 ../../firmware/makehex.py firmware.bin 4096 > firmware.hex tab_%/results.txt: bash tabtest.sh $@ @@ -58,5 +58,5 @@ table.txt: clean: rm -rf .Xil/ firmware.bin firmware.elf firmware.hex firmware.map synth_*.log rm -rf synth_*.mmi synth_*.bit synth_system.v table.txt tab_*/ webtalk.jou - rm -rf webtalk.log webtalk_*.jou webtalk_*.log xelab.* xsim.* xvlog.* + rm -rf webtalk.log webtalk_*.jou webtalk_*.log xelab.* xsim[._]* xvlog.* diff --git a/scripts/vivado/firmware.c b/scripts/vivado/firmware.c index 95aa8de..6c62169 100644 --- a/scripts/vivado/firmware.c +++ b/scripts/vivado/firmware.c @@ -8,7 +8,36 @@ void puts(const char *s) while (*s) putc(*s++); } +void *memcpy(void *dest, const void *src, int n) +{ + while (n) { + n--; + ((char*)dest)[n] = ((char*)src)[n]; + } + return dest; +} + void main() { - puts("Hello World!\n"); + char message[] = "$Uryyb+Jbeyq!+Vs+lbh+pna+ernq+guvf+zrffntr+gura$gur+CvpbEI32+PCH" + "+frrzf+gb+or+jbexvat+whfg+svar.$$++++++++++++++++GRFG+CNFFRQ!$$"; + for (int i = 0; message[i]; i++) + switch (message[i]) + { + case 'a' ... 'm': + case 'A' ... 'M': + message[i] += 13; + break; + case 'n' ... 'z': + case 'N' ... 'Z': + message[i] -= 13; + break; + case '$': + message[i] = '\n'; + break; + case '+': + message[i] = ' '; + break; + } + puts(message); }