From 491e8f77c1e8fb1d2dce0df5e7f12000ce1da859 Mon Sep 17 00:00:00 2001 From: Andrew Waterman Date: Sun, 18 Jul 2010 18:28:05 -0700 Subject: Reorganized directory structure Moved cross-compiler to /xcc/ rather than / Added ISA sim in /sim/ Added Proxy Kernel in /pk/ (to be cleaned up) Added opcode map to /opcodes/ (ditto) Added documentation to /doc/ --- opcodes | 148 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ parse-opcodes | 115 ++++++++++++++++++++++++++++++++++++++++++++ update-opcodes | 4 ++ 3 files changed, 267 insertions(+) create mode 100644 opcodes create mode 100755 parse-opcodes create mode 100755 update-opcodes diff --git a/opcodes b/opcodes new file mode 100644 index 0000000..cdf6118 --- /dev/null +++ b/opcodes @@ -0,0 +1,148 @@ +synci 001 +j 002 +jal 003 +beq 004 +bne 005 + +addi 010 +slti 012 +sltiu 013 +andi 014 +ori 015 +xori 016 +lui 017 + +blt 024 +bltu 025 +ble 026 +bleu 027 + +daddi 030 + +lb 040 +lh 041 +lw 043 +lbu 044 +lhu 045 +lwu 047 + +sb 050 +sh 051 +sw 053 + +l.s 061 +l.d 065 +ld 067 + +s.s 071 +s.d 075 +sd 077 + + + + + +unimp 000 000 +sll 000 001 +srl 000 002 +sra 000 003 +sllv 000 005 +srlv 000 006 +srav 000 007 + +jalr 000 011 +movz 000 012 +movn 000 013 +syscall 000 014 +break 000 015 +rdhwr 000 016 +sync 000 017 + +dsll 000 021 +dsrl 000 022 +dsra 000 023 +dsllv 000 025 +dsrlv 000 026 +dsrav 000 027 + +dsll32 000 031 +dsrl32 000 032 +dsra32 000 033 + +add 000 040 +sub 000 041 +slt 000 042 +sltu 000 043 +and 000 044 +or 000 045 +xor 000 046 +nor 000 047 + +mul 000 050 + +dadd 000 060 +dsub 000 061 + +dmul 000 070 + + + +ei 020 000 +di 020 001 +eret 020 002 + +mfc0 020 030 +dmfc0 020 031 +mtc0 020 034 +dmtc0 020 035 + +add.fmt 021 000 +sub.fmt 021 001 +mul.fmt 021 002 +div.fmt 021 003 +sqrt.fmt 021 004 +abs.fmt 021 005 +mov.fmt 021 006 +neg.fmt 021 007 + +round.l.fmt 021 010 +trunc.l.fmt 021 011 +ceil.l.fmt 021 012 +floor.l.fmt 021 013 +round.w.fmt 021 014 +trunc.w.fmt 021 015 +ceil.w.fmt 021 016 +floor.w.fmt 021 017 + +mfc1 021 030 +dmfc1 021 031 +cfc1 021 032 +mfhc1 021 033 +mtc1 021 034 +dmtc1 021 035 +ctc1 021 036 +mthc1 021 037 + +cvt.s.fmt 021 040 +cvt.d.fmt 021 041 +cvt.w.fmt 021 044 +cvt.l.fmt 021 045 + +c.f.fmt 021 060 +c.un.fmt 021 061 +c.eq.fmt 021 062 +c.ueq.fmt 021 063 +c.olt.fmt 021 064 +c.ult.fmt 021 065 +c.ole.fmt 021 066 +c.ule.fmt 021 067 + +c.sf.fmt 021 070 +c.ngle.fmt 021 071 +c.seq.fmt 021 072 +c.ngl.fmt 021 073 +c.lt.fmt 021 074 +c.nge.fmt 021 075 +c.le.fmt 021 076 +c.ngt.fmt 021 077 + diff --git a/parse-opcodes b/parse-opcodes new file mode 100755 index 0000000..6c735d3 --- /dev/null +++ b/parse-opcodes @@ -0,0 +1,115 @@ +#!/usr/bin/python + +import math +import sys +import tokenize + +opcode_base = 26 +opcode_size = 6 +funct_base = 0 +funct_size = 6 + +nopcode = 1 << opcode_size +nfunct = 1 << funct_size +opcodes = nopcode*[None] + +def binary(n, digits=0): + rep = bin(n)[2:] + return rep if digits == 0 else ('0' * (digits - len(rep))) + rep + +def make_latex_table(opcodes, captions, labels, upper_opcode=None): + if upper_opcode is None: print '% Automatically generated by parse-opcodes' + print '\\begin{table}[h]' + print '\\begin{center}' + print '\\begin{tabular}{r|c|c|c|c|c|c|c|c|}' + cols = 8 + print '\\multicolumn{1}{r}{}&', + for i in range(cols): + print '\\multicolumn{1}{c}{%s}' % binary(i,int(math.log(cols,2))),('&' if i < cols-1 else '\\\\\n'), + print '\\cline{2-%d}' % (cols+1) + for opcode, insn in enumerate(opcodes): + if not opcode % cols: print binary(opcode/cols,int(math.log(nopcode/cols,2))),'&', + if isinstance(insn, list): + print 'Table \\ref{table:%s}' % labels[1] % {'opcode':opcode}, + else: + print ' ' if insn is None else insn, + print '&' if (opcode+1) % cols else '\\\\\\cline{2-%d}\n' % (cols+1), + print '\\end{tabular}' + print '\\end{center}' + print '\\caption{%s}' % captions[0] % {'opcode':upper_opcode} + print '\\label{table:%s}' % labels[0] % {'opcode':upper_opcode} + print '\\end{table}' + + for opcode, insn in enumerate(opcodes): + if isinstance(insn, list): + make_latex_table(insn, captions[1:], labels[1:], opcode) + +def make_disasm_table(opcodes, upper_opcode=None): + if upper_opcode is None: print '/* Automatically generated by parse-opcodes */' + for opcode, insn in enumerate(opcodes): + if isinstance(insn, list): + make_disasm_table(insn, opcode) + elif isinstance(insn, basestring): + mask = ((1 << opcode_size)-1) << opcode_base + if upper_opcode is None: + match = opcode << opcode_base + else: + mask |= ((1 << funct_size)-1) << funct_base + match = (upper_opcode << opcode_base) | (opcode << funct_base) + insn = insn.upper().replace('.','_') + print '#define MATCH_%s %s' % (insn, hex(match)) + print '#define MASK_%s %s' % (insn, hex(mask)) + +def make_switch(opcodes, upper_opcode=None): + if upper_opcode is None: print '/* Automatically generated by parse-opcodes */' + pad = '' if upper_opcode is None else ' ' + print '%sswitch(%s)' % (pad,'opcode' if upper_opcode is None else 'funct') + print '%s{' % pad + for opcode, insn in enumerate(opcodes): + if insn is None: continue + print '%s case %d:' % (pad,opcode) + print '%s {' % pad + if isinstance(insn, list): + make_switch(insn, opcode) + else: + insn = insn.lower().replace('.','_') + print '%s #include "insns/%s.h"' % (pad,insn) + print '%s }' % pad + print '%s break;' % pad + print '%s default:' % pad + print '%s {' % pad + print '%s #include "insns/unimp.h"' % pad + print '%s }' % pad + print '%s break;' % pad + print '%s }' % pad + +for line in sys.stdin: + line = line.partition('#') + tokens = line[0].split() + + if len(tokens) == 0: + continue + assert len(tokens) in [2,3] + + opcode = int(tokens[1],0) + name = tokens[0].strip() + assert opcode < nopcode + assert not isinstance(opcodes[opcode], basestring) + + if len(tokens) == 3: + funct = int(tokens[2],0) + if opcodes[opcode] is None: + opcodes[opcode] = nfunct*[None] + assert not isinstance(opcodes[opcode][funct], basestring) + opcodes[opcode][funct] = name + else: + opcodes[opcode] = name + +if sys.argv[1] == '-tex': + make_latex_table(opcodes, ['Instructions encoded by opcode field','Instructions encoded by funct field when opcode = %(opcode)d'], ['opcodes','opcode%(opcode)d']) +elif sys.argv[1] == '-disasm': + make_disasm_table(opcodes) +elif sys.argv[1] == '-switch': + make_switch(opcodes) +else: + assert 0 diff --git a/update-opcodes b/update-opcodes new file mode 100755 index 0000000..a546d05 --- /dev/null +++ b/update-opcodes @@ -0,0 +1,4 @@ +#!/bin/bash +./parse-opcodes -tex < opcodes > ../doc/opcodes.tex +./parse-opcodes -disasm < opcodes > ../xcc/src/include/opcode/mips-riscv-opc.h +./parse-opcodes -switch < opcodes > ../sim/riscv/execute.h -- cgit v1.2.3