Skip to content

Commit

Permalink
Add support for riscv64 blobs
Browse files Browse the repository at this point in the history
  • Loading branch information
smaeul committed May 30, 2021
1 parent cb5e7de commit 851eac0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
# See LICENSE in the project directory for license terms.
#

ARCH_arisc = or1k
ARCH_nbrom = arm
ARCH_rvbrom = riscv64
ARCH_sbrom = arm

CROSS_aarch64 = aarch64-linux-musl-
CROSS_arm = arm-linux-musleabi-
CROSS_or1k = or1k-linux-musl-
CROSS_riscv64 = riscv64-linux-musl-

BLOB ?= */*
BLOBS = $(sort $(wildcard $(BLOB)/blob.hex))
Expand All @@ -16,7 +22,7 @@ OUTPUT = $(foreach d,$(DIRS),$(d)annotated.s $(d)blob.s $(d)callgraph.svg)
SECTIONS = $(addsuffix sections,$(DIRS))
SYMBOLS = $(addsuffix symbols,$(DIRS))

arch = $(if $(findstring arisc,$(lastword $(1:/= ))),or1k,arm)
arch = $(ARCH_$(firstword $(subst _, ,$(notdir $1))))
cross_compile = $(CROSS_$(call arch,$(1)))
env = env ARCH=$(call arch,$(1)) CROSS_COMPILE=$(call cross_compile,$(1))

Expand Down
6 changes: 5 additions & 1 deletion scripts/bin2elf
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ case "$ARCH" in
*) WORDSIZE=32 ;;
esac
case "$ARCH" in
arm) BFDNAME=elf${WORDSIZE}-${ENDIANNESS}${ARCH} ;;
riscv*) ARCH=riscv ;;
esac
case "$ARCH" in
arm|riscv)
BFDNAME=elf${WORDSIZE}-${ENDIANNESS}${ARCH} ;;
*) BFDNAME=elf${WORDSIZE}-${ARCH} ;;
esac

Expand Down
21 changes: 12 additions & 9 deletions scripts/callgraph
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ CROSS_COMPILE=${CROSS_COMPILE:-${ARCH}-linux-musl-}
# Generated, but might need adjustment
case "$ARCH" in
arm)
CALL_INSN=bl
TAIL_INSN=b
CALL_INSN="bl "
TAIL_INSN="b "
;;
or1k)
CALL_INSN=l.jal
TAIL_INSN=l.j
CALL_INSN="l.jal "
TAIL_INSN="l.j "
;;
riscv*)
CALL_INSN="jal ra,"
TAIL_INSN="j "
esac

# Command-line parameters
Expand All @@ -39,17 +42,17 @@ strict digraph calls {
EOF
grep -F -e '>:' -e "$CALL_INSN" -e "$TAIL_INSN" "$input_file" |
while read -r line; do
if [[ $line =~ ^[[:xdigit:]]{8}\ \<([[:alnum:]_]+)\>:$ ]]; then
if [[ $line =~ ^[[:xdigit:]]{8,16}\ \<([[:alnum:]_]+)\>:$ ]]; then
caller=${BASH_REMATCH[1]}
[[ $caller =~ ^__.+si3$ || $caller =~ ^nop_ ]] && continue
printf ' %s\n' "$caller" >> "$output_file"
elif [[ $line =~ ^.*\ ${CALL_INSN}\ +[[:xdigit:]]+\ \<([[:alnum:]_]+)\>$ ]]; then
elif [[ $line =~ ^.*\ ${CALL_INSN}+[[:xdigit:]]+\ \<([[:alnum:]_]+)\>$ ]]; then
callee=${BASH_REMATCH[1]}
[[ $callee =~ ^__.+si3$ || $callee =~ printf$ ]] && continue
[[ $callee =~ ^__.+si3$ || $callee =~ printf$ || $callee =~ pwrstate$ ]] && continue
printf ' %s -> %s\n' "$caller" "$callee" >> "$output_file"
elif [[ $line =~ ^.*\ ${TAIL_INSN}\ +[[:xdigit:]]+\ \<([[:alnum:]_]+)\>$ ]]; then
elif [[ $line =~ ^.*\ ${TAIL_INSN}+[[:xdigit:]]+\ \<([[:alnum:]_]+)\>$ ]]; then
callee=${BASH_REMATCH[1]}
[[ $callee =~ ^__.+si3$ || $callee =~ printf$ ]] && continue
[[ $callee =~ ^__.+si3$ || $callee =~ printf$ || $callee =~ pwrstate$ ]] && continue
printf ' %s -> %s [style = dashed]\n' "$caller" "$callee" >> "$output_file"
fi
done
Expand Down

0 comments on commit 851eac0

Please sign in to comment.