Last active
January 22, 2021 11:09
-
-
Save megrxu/46796fe029c84c3953c67641e561c039 to your computer and use it in GitHub Desktop.
riscv-dump
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env zsh | |
## Dump machine codes only to a Xilinx coefficient file. | |
## Usage: ./riscv-dump <.S file> > ROM.coe | |
## Tmp files | |
elf=(=()) | |
bin=(=()) | |
## Get the elf | |
riscv64-linux-gnu-as $1 -o $elf | |
## Copy the .text section to binary | |
objcopy -I elf64-little -O binary -j .text $elf $bin | |
## Write the .coe | |
echo "memory_initialization_radix=16;" | |
echo "memory_initialization_vector=" | |
od -An -t x4 -w4 -v --endian=little $bin | \ | |
paste -sd, - | \ | |
sed -e 's/$/;/' | \ | |
xargs | fold -w 40 | |
rm $elf $bin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment