summaryrefslogtreecommitdiff
path: root/parse-opcodes
diff options
context:
space:
mode:
Diffstat (limited to 'parse-opcodes')
-rwxr-xr-xparse-opcodes87
1 files changed, 71 insertions, 16 deletions
diff --git a/parse-opcodes b/parse-opcodes
index 3117b8e..6c12a16 100755
--- a/parse-opcodes
+++ b/parse-opcodes
@@ -40,6 +40,35 @@ arglut['cimm6'] = (15,10)
arglut['cimm10'] = (14,5)
arglut['cimm5'] = (9,5)
+csrs = [
+ (0x001, 'fflags'),
+ (0x002, 'frm'),
+ (0x003, 'fcsr'),
+ (0x500, 'sup0'),
+ (0x501, 'sup1'),
+ (0x502, 'epc'),
+ (0x503, 'badvaddr'),
+ (0x504, 'ptbr'),
+ (0x505, 'asid'),
+ (0x506, 'count'),
+ (0x507, 'compare'),
+ (0x508, 'evec'),
+ (0x509, 'cause'),
+ (0x50A, 'status'),
+ (0x50B, 'hartid'),
+ (0x50C, 'impl'),
+ (0x50D, 'fatc'),
+ (0x50E, 'send_ipi'),
+ (0x50F, 'clear_ipi'),
+ (0x51C, 'stats'), # XXX
+ (0x51D, 'reset'),
+ (0x51E, 'tohost'),
+ (0x51F, 'fromhost'),
+ (0xC00, 'cycle'),
+ (0xC01, 'time'),
+ (0xC02, 'instret'),
+]
+
opcode_base = 0
opcode_size = 7
funct_base = 12
@@ -49,17 +78,28 @@ def binary(n, digits=0):
rep = bin(n)[2:]
return rep if digits == 0 else ('0' * (digits - len(rep))) + rep
-def make_disasm_table(match,mask):
+def make_c(match,mask):
print '/* Automatically generated by parse-opcodes */'
- for name,match in match.iteritems():
+ print '#ifndef RISCV_ENCODING_H'
+ print '#define RISCV_ENCODING_H'
+ for name in match.iterkeys():
name2 = name.upper().replace('.','_')
- print '#define MATCH_%s %s' % (name2, hex(match))
- print '#define MASK_%s %s' % (name2, hex(mask[name]))
+ print '#define MATCH_%s %s' % (name2, hex(match[name]))
+ print '#define MASK_%s %s' % (name2, hex(mask[name]))
+ for num, name in csrs:
+ print '#define CSR_%s %s' % (name.upper(), hex(num))
+ print '#endif'
-def make_isasim(match, mask):
+ print '#ifdef DECLARE_INSN'
for name in match.iterkeys():
name2 = name.replace('.','_')
- print 'DECLARE_INSN(%s, 0x%x, 0x%x)' % (name2, match[name], mask[name])
+ print 'DECLARE_INSN(%s, MATCH_%s, MASK_%s)' % (name2, name2.upper(), name2.upper())
+ print '#endif'
+
+ print '#ifdef DECLARE_CSR'
+ for num, name in csrs:
+ print 'DECLARE_CSR(%s, CSR_%s)' % (name, name.upper())
+ print '#endif'
def yank(num,start,len):
return (num >> start) & ((1 << len) - 1)
@@ -490,7 +530,7 @@ def make_latex_table():
print_insts('addi', 'slti', 'sltiu', 'xori', 'ori', 'andi', 'slli', 'srli', 'srai')
print_insts('add', 'sub', 'sll', 'slt', 'sltu', 'xor', 'srl', 'sra', 'or', 'and')
print_insts('fence', 'fence.i')
- print_insts('syscall', 'break', 'rdcycle', 'rdtime', 'rdinstret')
+ print_insts('scall', 'sbreak', 'rdcycle', 'rdtime', 'rdinstret')
print_footer(0)
print_header('r','a','i','s')
@@ -524,7 +564,8 @@ def make_latex_table():
print_insts('fcvt.s.w', 'fcvt.s.wu', 'fmv.s.x')
print_insts('fcvt.w.s', 'fcvt.wu.s', 'fmv.x.s')
print_insts('feq.s', 'flt.s', 'fle.s')
- print_insts('fssr', 'frsr')
+ print_insts('frcsr', 'frrm', 'frflags')
+ print_insts('fscsr', 'fsrm', 'fsflags')
print_footer(0)
print_header('r','r4','i','s')
@@ -555,9 +596,21 @@ def print_chisel_insn(name):
print s + "\")"
def make_chisel():
- print ' /* Automatically generated by parse-opcodes */'
+ print '/* Automatically generated by parse-opcodes */'
+ print 'object Instructions {'
for name in namelist:
print_chisel_insn(name)
+ print '}'
+ print 'object CSRs {'
+ for num, name in csrs:
+ print ' val %s = %s' % (name, hex(num))
+ print ' val all = {'
+ print ' val res = collection.mutable.ArrayBuffer[Int]()'
+ for num, name in csrs:
+ print ' res += %s' % (name)
+ print ' res.toArray'
+ print ' }'
+ print '}'
for line in sys.stdin:
line = line.partition('#')
@@ -568,6 +621,9 @@ for line in sys.stdin:
assert len(tokens) >= 2
name = tokens[0]
+ pseudo = name[0] == '@'
+ if pseudo:
+ name = name[1:]
mymatch = 0
mymask = 0
cover = 0
@@ -610,9 +666,10 @@ for line in sys.stdin:
if not (cover == 0xFFFFFFFF or cover == 0xFFFF):
sys.exit("%s: not all bits are covered" % name)
- for name2,match2 in match.iteritems():
- if (match2 & mymask) == mymatch:
- sys.exit("%s and %s overlap" % (name,name2))
+ if not pseudo:
+ for name2,match2 in match.iteritems():
+ if (match2 & mymask) == mymatch:
+ sys.exit("%s and %s overlap" % (name,name2))
mask[name] = mymask
match[name] = mymatch
@@ -622,9 +679,7 @@ if sys.argv[1] == '-tex':
make_latex_table()
elif sys.argv[1] == '-chisel':
make_chisel()
-elif sys.argv[1] == '-disasm':
- make_disasm_table(match,mask)
-elif sys.argv[1] == '-isasim':
- make_isasim(match,mask)
+elif sys.argv[1] == '-c':
+ make_c(match,mask)
else:
assert 0