From: Dmitry Selyutin Date: Thu, 21 Sep 2023 20:39:12 +0000 (+0300) Subject: caveat: generate ecall.h X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=97e66b71006a8e1ea9957c7cb80078abbc01d9e3;p=cavatools.git caveat: generate ecall.h --- diff --git a/caveat/.gitignore b/caveat/.gitignore index 101bf1d..7436ae8 100644 --- a/caveat/.gitignore +++ b/caveat/.gitignore @@ -2,6 +2,6 @@ build decode_insn.h disasm_insn.h execute_insn.h -ecall_nums.h +ecall.h opcodes.h opcodes_attr.h diff --git a/caveat/Makefile b/caveat/Makefile index bb149a3..0a36d83 100644 --- a/caveat/Makefile +++ b/caveat/Makefile @@ -38,7 +38,7 @@ install: all .PHONY: clean clean: - rm -f decode_insn.h disasm_insn.h execute_insn.h ecall_nums.h opcodes.h opcodes_attr.h *.o *~ ./#*# + rm -f decode_insn.h disasm_insn.h execute_insn.h ecall.h opcodes.h opcodes_attr.h *.o *~ ./#*# rm -rf build @@ -56,7 +56,7 @@ $(aobj): $(incf) $(cobj): $(incf) $B/slow_sim.o $B/fast_sim.o: sim_body.h execute_insn.h caveat_fp.h core.h -$B/ecall.o: core.h ecall_nums.h +$B/ecall.o: core.h ecall.h $B/insn.o: decode_insn.h disasm_insn.h $B/trace.o: fifo.h @@ -82,7 +82,12 @@ $B/%.o : %.cc opcodes.h opcodes_attr.h decode_insn.h execute_insn.h disasm_insn.h constants.c: crunch_isa.py Instructions.def python3 crunch_isa.py -ecall.h: ecall_nums.h opcodes.h insn.h core.h - -ecall_nums.h: make_ecall_tbl.py - python3 make_ecall_tbl.py +ecall.h: opcodes.h insn.h core.h + echo -n > $@ + echo '#include ' >> $@ + echo '#include ' >> $@ + echo '#include ' >> $@ + echo '#include "opcodes.h"' >> $@ + echo '#include "insn.h"' >> $@ + echo '#include "core.h"' >> $@ + python3 -m openpower.syscalls ecall riscv64 amd64 >> $@ diff --git a/caveat/ecall.h b/caveat/ecall.h deleted file mode 100644 index a5aed4c..0000000 --- a/caveat/ecall.h +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -#include -#include -#include - -struct ecall_entry { - long number; - char const *name; -}; - -#include "opcodes.h" -#include "insn.h" -#include "core.h" - -#include "ecall_nums.h" - -static inline struct ecall_entry const * -ecall_entry(long id) { - return &rv_to_host[id]; -} - -static inline long -ecall_fetch(struct core_t const *cpu, long arguments[6]) { - arguments[0] = cpu->reg[10].l; - arguments[1] = cpu->reg[11].l; - arguments[2] = cpu->reg[12].l; - arguments[3] = cpu->reg[13].l; - arguments[4] = cpu->reg[14].l; - arguments[5] = cpu->reg[15].l; - - return cpu->reg[17].l; -} - -static inline void -ecall_store(long const arguments[6], struct core_t *cpu) -{ - cpu->reg[10].l = arguments[0]; - cpu->reg[11].l = arguments[1]; - cpu->reg[12].l = arguments[2]; - cpu->reg[13].l = arguments[3]; - cpu->reg[14].l = arguments[4]; - cpu->reg[15].l = arguments[5]; -} diff --git a/caveat/make_ecall_tbl.py b/caveat/make_ecall_tbl.py deleted file mode 100644 index 59a78df..0000000 --- a/caveat/make_ecall_tbl.py +++ /dev/null @@ -1,62 +0,0 @@ -# -# Copyright (c) 2020 Peter Hsu. All Rights Reserved. See LICENCE file for details. -# - -import re -import os - -PKpattern = re.compile(r'#define\s+SYS_(\S+)\s+(\d+)') -RVpattern = re.compile(r'#define\s+TARGET_NR_(\S+)\s+(\d+)') - -# Algorith is we make table of RISC-V system call names and record -# their numbers, create a C file of names, include the host x86 -# 'asm/unistd_64.h' file to get the correct mapping. - -ecall = {} -enames = {} -highest = -1 -rv = open('../include/pk-syscall.h', 'r') -for line in rv: - m = PKpattern.match(line) - if m: - name, num = m.groups() - num = int(num) - ecall[num] = name - enames[name] = num - highest = max(num, highest) -rv.close() - -rv = open('../include/syscall64_nr.h', 'r') -for line in rv: - m = RVpattern.match(line) - if m: - name, num = m.groups() - num = int(num) - if num in ecall and name != ecall[num]: - print('libc {:s} override pk {:s} ecall'.format(name, ecall[num])) - ecall[num] = name - enames[name] = num - highest = max(num, highest) - -en = open('ecall_nums.h', 'w') -en.write("#pragma once\n") - -for name in sorted(enames.keys()): - en.write('#ifndef __NR_{:s}\n'.format(name)) - en.write('#define __NR_{:s} -2\n'.format(name)) - en.write('#endif\n') - -en.write("""\n -static struct ecall_entry const rv_to_host[] = { -""") - -for n in range(0, highest+1): - if n in ecall: - name = ecall[n] - en.write(' /* {:5d} */ {{ __NR_{:s}, "{:s}" }},\n'.format(n, name, name)) - else: - en.write(' /* {:5d} */ {{ -1, 0 }},\n'.format(n)) - -en.write('};\n\n') -en.write('const int rv_syscall_entries = {:d};\n\n'.format(highest+1)) -en.close()