ref: a98aac17201df8612313d56b400094919b8deec8
parent: 5eaa64cb0a375db8c155b3af9bead075fd5dce98
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Sep 27 08:10:13 EDT 2017
[as-x86] Use unified file for instructions It is easier to use flags and filter with that flags instead of creating individual files per cpu.
--- a/as/common.dat
+++ /dev/null
@@ -1,6 +1,0 @@
-# Tab 16, tabs 16, :set ts=16
-# op args size bytes format
-DB imm8+ 0 none defb
-DW imm16+ 0 none defw
-DD imm32+ 0 none defd
-DQ imm64+ 0 none defq
--- a/as/target/i386/target.mk
+++ b/as/target/i386/target.mk
@@ -1,15 +1,13 @@
-I386_TBL = common.dat \
- target/x86/i386.dat
target/i386/ins.o: target/i386/ins.h
target/i386/instbl.o: target/i386/ins.h
-target/i386/instbl.c: target/x86/gen.awk $(I386_TBL)
+target/i386/instbl.c: target/x86/gen.awk target/x86/x86.dat
set -e ;\
rm -f $@;\
trap "rm -f $$$$.c" 0 2 3; \
- cat $(I386_TBL) | \
- awk -f target/x86/gen.awk > $$$$.c && mv $$$$.c $@
+ awk -v bits=BITS32 -f target/x86/gen.awk \
+ < target/x86/x86.dat > $$$$.c && mv $$$$.c $@
OBJ-i386 = $(OBJ) \
target/i386/instbl.o \
--- a/as/target/x86/gen.awk
+++ b/as/target/x86/gen.awk
@@ -1,59 +1,65 @@
-BEGIN {
- FS = "\t"
- printf "#include \"../../../inc/scc.h\"\n"\
- "#include \"../../as.h\"\n"\
- "#include \"../x86/proc.h\"\n"\
- "#include \"ins.h\"\n\n"
- nop = 0; nvar = 0
+BEGIN {
+ print "bits=",bits > "/dev/stderr"
+ FS = "\t"
+ printf "#include \"../../../inc/scc.h\"\n"\
+ "#include \"../../as.h\"\n"\
+ "#include \"../x86/proc.h\"\n"\
+ "#include \"ins.h\"\n\n"
+ nop = 0; nvar = 0
}
- {sub(/#.*/,"")}
-/^$/ {next}
- {
- if (opstart[$1] == 0) {
- opstart[$1] = nvar
- opnames[nop++] = $1
- }
- opcount[$1]++
- opargs[nvar] = $2
- opsize[nvar] = $3
- opbytes[nvar] = ($4 == "none") ? "" : $4
- opformat[nvar++] = $5
- formats[$5] = 1
+ {sub(/#.*/,"")}
+
+$6 !~ bits {next}
+
+/^$/ {next}
+
+ {
+ if (opstart[$1] == 0) {
+ opstart[$1] = nvar
+ opnames[nop++] = $1
+ }
+ opcount[$1]++
+ opargs[nvar] = $2
+ opsize[nvar] = $3
+ opbytes[nvar] = ($4 == "none") ? "" : $4
+ opformat[nvar++] = $5
+ formats[$5] = 1
}
-END {
- for (i in formats)
- printf "Format %s;\n", i
+END {
+ for (i in formats)
+ printf "Format %s;\n", i
- printf "int nr_ins = %d;\n\n", nop
- print "struct ins instab[] = {"
- for (i = 0; i < nop; i++) {
- n = opnames[i]
- start = opstart[n]
- end = start + opcount[n]
- printf "\t{.str = \"%s\", .begin = %d, .end = %d},\n",
- n, start, end | "sort"
- }
- close("sort")
- printf "};\n\n"
+ printf "int nr_ins = %d;\n\n", nop
+ print "struct ins instab[] = {"
+ for (i = 0; i < nop; i++) {
+ n = opnames[i]
+ start = opstart[n]
+ end = start + opcount[n]
+ printf "\t{.str = \"%s\", .begin = %d, .end = %d},\n",
+ n, start, end | "sort"
+ }
+ close("sort")
+ printf "};\n\n"
- print "struct op optab[] = {"
- for (i = 0; i < nvar; i++) {
- printf "\t{\n" \
- "\t\t.size = %d,\n"\
- "\t\t.format = %s,\n",
- opsize[i], opformat[i]
+ print "struct op optab[] = {"
+ for (i = 0; i < nvar; i++) {
+ printf "\t{\n" \
+ "\t\t.size = %d,\n"\
+ "\t\t.format = %s,\n",
+ opsize[i], opformat[i]
- if (opbytes[i] != "")
- printf "\t\t.bytes = (char []) {%s},\n", opbytes[i]
+ if (opbytes[i] != "")
+ printf "\t\t.bytes = (char []) {%s},\n",
+ opbytes[i]
- a = str2args(opargs[i])
- if (a != "")
- printf "\t\t.args = (char []) {%s}\n", a
+ a = str2args(opargs[i])
+ if (a != "")
+ printf "\t\t.args = (char []) {%s}\n", a
- print "\t},"
- }
- print "};"
+ print "\t},"
+ }
+ print "};"
}
function str2args(s, args, i, out)
--- a/as/target/x86/i386.dat
+++ /dev/null
@@ -1,5 +1,0 @@
-# Tab 16, tabs 16, :set ts=16
-# op args size bytes format
-EQU imm32 0 none equ
-NOP none 1 0x90 direct
-RET none 1 0xc3 direct
--- /dev/null
+++ b/as/target/x86/x86.dat
@@ -1,0 +1,11 @@
+# Tab 16, tabs 16, :set ts=16
+# op args size bytes format cpu
+DB imm8+ 0 none defb BITS16,BITS32,BITS64
+DW imm16+ 0 none defw BITS16,BITS32,BITS64
+DD imm32+ 0 none defd BITS16,BITS32,BITS64
+DQ imm64+ 0 none defq BITS16,BITS32,BITS64
+EQU imm16 0 none equ BITS16
+EQU imm32 0 none equ BITS32
+EQU imm64 0 none equ BITS64
+NOP none 1 0x90 direct BITS16,BITS32,BITS64
+RET none 1 0xc3 direct BITS16,BITS32,BITS64