Skip to content

Instantly share code, notes, and snippets.

@megrxu
Last active January 22, 2021 11:09
Show Gist options
  • Save megrxu/46796fe029c84c3953c67641e561c039 to your computer and use it in GitHub Desktop.
Save megrxu/46796fe029c84c3953c67641e561c039 to your computer and use it in GitHub Desktop.
riscv-dump
#!/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