aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--LICENSE24
-rw-r--r--Makefile3
-rwxr-xr-xparse-opcodes41
4 files changed, 69 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 5b578f1..9512eca 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
.*.swp
inst.chisel
+inst.go
instr-table.tex
priv-instr-table.tex
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..34f576b
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,24 @@
+Copyright (c) 2010-2017, The Regents of the University of California
+(Regents). All Rights Reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+3. Neither the name of the Regents nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING
+OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS
+BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED
+HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE
+MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
diff --git a/Makefile b/Makefile
index 114e6b5..795cb94 100644
--- a/Makefile
+++ b/Makefile
@@ -20,6 +20,9 @@ $(GAS_H) $(XCC_H): $(ALL_OPCODES) parse-opcodes
inst.chisel: $(ALL_OPCODES) parse-opcodes
cat opcodes opcodes-custom opcodes-pseudo | ./parse-opcodes -chisel > $@
+inst.go: opcodes opcodes-pseudo parse-opcodes
+ cat opcodes opcodes-pseudo | ./parse-opcodes -go > $@
+
instr-table.tex: $(ALL_OPCODES) parse-opcodes
cat opcodes opcodes-pseudo | ./parse-opcodes -tex > $@
diff --git a/parse-opcodes b/parse-opcodes
index f9d54d8..408ed0c 100755
--- a/parse-opcodes
+++ b/parse-opcodes
@@ -847,6 +847,45 @@ def make_chisel():
print ' }'
print '}'
+def signed(value, width):
+ if 0 <= value < (1<<(width-1)):
+ return value
+ else:
+ return value - (1<<width)
+
+def print_go_insn(name):
+ print '\tcase A%s:' % name.upper().replace('.', '')
+ m = match[name]
+ opcode = yank(m, 0, 7)
+ funct3 = yank(m, 12, 3)
+ rs2 = yank(m, 20, 5)
+ csr = yank(m, 20, 12)
+ funct7 = yank(m, 25, 7)
+ print '\t\treturn &inst{0x%x, 0x%x, 0x%x, %d, 0x%x}, true' % (opcode, funct3, rs2, signed(csr, 12), funct7)
+
+def make_go():
+ print '// Automatically generated by parse-opcodes'
+ print
+ print 'package riscv'
+ print
+ print 'import "cmd/internal/obj"'
+ print
+ print 'type inst struct {'
+ print '\topcode uint32'
+ print '\tfunct3 uint32'
+ print '\trs2 uint32'
+ print '\tcsr int64'
+ print '\tfunct7 uint32'
+ print '}'
+ print
+ print 'func encode(a obj.As) (i *inst, ok bool) {'
+ print '\tswitch a {'
+ for name in namelist:
+ print_go_insn(name)
+ print '\t}'
+ print '\treturn nil, false'
+ print '}'
+
for line in sys.stdin:
line = line.partition('#')
tokens = line[0].split()
@@ -920,5 +959,7 @@ elif sys.argv[1] == '-chisel':
make_chisel()
elif sys.argv[1] == '-c':
make_c(match,mask)
+elif sys.argv[1] == '-go':
+ make_go()
else:
assert 0