Skip to content

Commit

Permalink
Add --get-elf-class for march-to-cpu-opt
Browse files Browse the repository at this point in the history
  • Loading branch information
kito-cheng committed Apr 24, 2023
1 parent 22f2d28 commit 5da0026
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
19 changes: 16 additions & 3 deletions scripts/march-to-cpu-opt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def parse_opt(argv):
parser.add_argument('-march', '--with-arch', type=str, dest='march')
parser.add_argument('-selftest', action='store_true')
parser.add_argument('--get-riscv-tag', type=str)
parser.add_argument('--get-elf-class', type=str)
opt = parser.parse_args()
return opt

Expand Down Expand Up @@ -160,11 +161,19 @@ class TestArchStringParse(unittest.TestCase):
def selftest():
unittest.main(argv=sys.argv[1:])

def read_arch_attr (path):
def open_elf(path):
try:
elffile = elftools.elf.elffile.ELFFile(open(path, 'rb'))
except elftools.common.exceptions.ELFError:
raise Exception("%s is not ELF file!" % path)
return elffile

def read_elf_class(path):
elffile = open_elf(path)
return elffile.elfclass

def read_arch_attr (path):
elffile = open_elf(path)

attr_sec = elffile.get_section_by_name(".riscv.attributes")
if attr_sec:
Expand Down Expand Up @@ -200,8 +209,12 @@ def main(argv):
if opt.selftest:
selftest()
return 0
if (opt.with_elf):
march = read_arch_attr (opt.with_elf)
if (opt.get_elf_class):
elf_class = read_elf_class (opt.get_elf_class)
print (elf_class)
return
if (opt.get_riscv_tag):
march = read_arch_attr (opt.get_riscv_tag)
else:
march = opt.march
cpu_opt = conver_arch_to_qemu_cpu_opt(march)
Expand Down
2 changes: 1 addition & 1 deletion scripts/wrapper/qemu/riscv64-unknown-linux-gnu-run
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ do
shift
done

xlen="$(readelf -h $1 | grep 'Class' | cut -d: -f 2 | xargs echo | sed 's/^ELF//')"
xlen="$(march-to-cpu-opt --get-elf-class $1)"

QEMU_CPU="$(march-to-cpu-opt --get-riscv-tag $1)" qemu-riscv$xlen -r 5.10 "${qemu_args[@]}" -L ${RISC_V_SYSROOT} "$@"

0 comments on commit 5da0026

Please sign in to comment.