summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--twasm/README.md86
-rw-r--r--twasm/asm/main.asm132
2 files changed, 99 insertions, 119 deletions
diff --git a/twasm/README.md b/twasm/README.md
index 8d0ce3b..3ec90b6 100644
--- a/twasm/README.md
+++ b/twasm/README.md
@@ -230,11 +230,11 @@ entries are as follows:
16 bytes
+------------------------------+
| 0 operand operators |
-+------------------------------+
-| 127 96 |
-+------------------------------+
-| reserved |
-+------------------------------+
++---------+--------------------+
+| 127 120 | 119 96 |
++---------+--------------------+
+| flags | reserved |
++---------+--------------------+
| 95 64 |
+------------------------------+
| reserved |
@@ -249,39 +249,39 @@ entries are as follows:
+----------+--------+----------+
16 bytes
-+-------------------------------------------------------------+
-| 1 operand operators |
-+-------------------------------------------------------------+
-| 127 96 |
-+-------------------------------------------------------------+
-| reserved |
-+----------+-------+-------+-------+-------+----------+-------+
-| 95 88 | 87 84 | 83 80 | 79 76 | 75 72 | 71 68 | 67 64 |
-+----------+-------+-------+-------+-------+----------+-------+
-| reserved | op5&8 | op4&8 | op3&8 | op2&8 | reserved | op0&8 |
-+----------+-------+-------+-------+-------+----------+-------+
-| 63 56 | 55 48 | 47 40 | 39 32 |
-+----------+---------------+---------------+------------------+
-| opcode | opcode | opcode | opcode |
-| dst=rel8 | dst=rel | dst=imm8 | dst=imm |
-+----------+---------------+---------------+------------------+
-| 31 24 | 23 16 | 15 0 |
-+----------+---------------+----------------------------------+
-| reserved | opcode | token ID |
-| | dst=r/m | |
-+----------+---------------+----------------------------------+
++------------------------------------------+
+| 1 operand operators |
++----------+----------+----------+---------+
+| 127 120 | 119 112 | 111 104 | 103 96 |
++----------+----------+----------+---------+
+| flags | reserved | flags5 | flags4 |
++----------+----------+----------+---------+
+| 95 88 | 87 80 | 79 72 | 71 64 |
++----------+----------+----------+---------+
+| flags3 | flags2 | reserved | flags0 |
++----------+----------+----------+---------+
+| 63 56 | 55 48 | 47 40 | 39 32 |
++----------+----------+----------+---------+
+| opcode | opcode | opcode | opcode |
+| dst=rel8 | dst=rel | dst=imm8 | dst=imm |
++----------+----------+----------+---------+
+| 31 24 | 23 16 | 15 0 |
++----------+----------+--------------------+
+| reserved | opcode | token ID |
+| | dst=r/m | |
++----------+----------+--------------------+
16 bytes
+-----------------------------------------------+
| 2 operand operators |
-+-----------------------------------------------+
-| 127 96 |
-+-----------------------------------------------+
-| reserved |
-+---------+----------+-------+-------+----------+
-| 95 88 | 87 80 | 79 76 | 75 72 | 71 64 |
-+---------+----------+-------+-------+----------+
-| flags | reserved | op3&8 | op2&8 | reserved |
++---------+-------------------------------------+
+| 127 120 | 119 96 |
++---------+-------------------------------------+
+| flags | reserved |
++---------+----------+--------------------------+
+| 95 88 | 87 80 | 79 64 |
++---------+----------+--------------------------+
+| flags3 | flags2 | reserved |
+---------+----------+-------+-------+----------+
| 63 48 | 47 40 | 39 32 |
+--------------------+---------------+----------+
@@ -305,9 +305,23 @@ entries are as follows:
| reserved | 8bit |
+----------+------+
+1 byte
++----------------------------------------------------+
+| flagsX byte |
++----------+-----------+-------------+---------------+
+| 7 5 | 4 | 3 | 2 0 |
++----------+-----------+-------------+---------------+
+| reserved | no ModR/M | 0x0F prefix | operator flag |
++----------+-----------+-------------+---------------+
+
; flags key:
8bit ; tte has opcodes for r/m8 and r8 instead of r/m and r respectively
+; flagsX key:
+no ModR/M ; there is no ModR/M byte for this opcode
+0x0F prefix ; there is a 0x0F prefix for this opcode
+operator flag ; contents of `reg` if applicable
+
; key:
r/m ; r/m 16/32/64
r/m8 ; r/m 8
@@ -317,10 +331,6 @@ imm ; imm 16/32
imm8 ; imm 8
rel ; rel 16/32
rel8 ; rel 8
-
-opX&8 ; low 8 bits are the operator flag that goes with opcode at offset X from
- ; the first opcode in the table entry. High bit is (somewhat confusingly)
- ; a flag for whether or not the operator comes with an `0F` prefix
```
note much room to expand. If an opcode doesn't exist, it should be 0x00
diff --git a/twasm/asm/main.asm b/twasm/asm/main.asm
index 2a0cf2a..6ffe830 100644
--- a/twasm/asm/main.asm
+++ b/twasm/asm/main.asm
@@ -1083,9 +1083,7 @@ get_ModRM:
;
; returned:
; al = opcode; the rest of rax is zeroed.
-; dl = lower 3 bits: op flag, if applicable.
-; 4th bit: 0x0F prefix flag
-; the rest of rdx is zeroed.
+; dl = flags
; ------------------------------------------------------------------------------
get_opcode:
@@ -1114,7 +1112,7 @@ get_opcode:
.maybe_found:
shl eax, 4
- mov cl, [opcodes.by_id + 11 + eax]
+ mov cl, [opcodes.by_id + 15 + eax]
shr eax, 4
cmp cl, bl
je .found
@@ -1127,18 +1125,9 @@ get_opcode:
ret
.found:
shl eax, 4
- push rsi
- shr esi, 1
mov dl, [esi + 8 + opcodes.by_id + eax]
- pop rsi
-
- test esi, 1 ; check if offset is odd
- jz .found_continue
- shr edx, 4 ; if so, upper part of dl byte
- .found_continue:
mov al, [esi + 2 + opcodes.by_id + eax]
and eax, 0xFF
- and edx, 0x0F
ret
; ------------------------------------------------------------------------------
@@ -2800,23 +2789,18 @@ opcodes:
db 0x83 ; r/m <- imm8
dw 0x0000
- dd 0x00006600 ; 00:
- ; 6: r/m <- imm16/32 op flag
- ; 6: r/m <- imm8 op flag
- ; 0x0000:
+ dw 0x0000
+ db 0x06 ; 6: r/m <- imm16/32 op flag
+ db 0x06 ; 6: r/m <- imm8 op flag
- dd 0x00000000 ; reserved
+ dd 0x00000000
; inc
dw 0x0054
db 0xFF ; r/m
db 0x00
-
dd 0x00000000
-
- dd 0x00000000 ; 0: r/m op flag
- ; 0000000:
-
+ dd 0x00000000
dd 0x00000000
; dec
@@ -2826,8 +2810,10 @@ opcodes:
dd 0x00000000
- dd 0x00000001 ; 1: r/m op flag
- ; 0000000:
+ db 0x01 ; r/m op byte
+ db 0x00
+ dw 0x0000
+
dd 0x00000000
; mov
@@ -2839,10 +2825,7 @@ opcodes:
db 0x00
dw 0x0000
- dd 0x00000000 ; 00:
- ; 0: r/m <- imm16/32 op flag
- ; 00000:
-
+ dd 0x00000000
dd 0x00000000
; mov bit8
@@ -2854,13 +2837,12 @@ opcodes:
db 0xC6 ; r/m8 <- imm8
dw 0x0000
- dd 0x01000000 ; 000:
- ; 0: r/m8 <- imm8 op flag
- ; 00:
- ; 01: bit8 flag
-
dd 0x00000000
+ dw 0x0000
+ db 0x00
+ db 0x01 ; bit8 flag
+
; add
dw 0x0057
db 0x01 ; r/m <- r
@@ -2870,11 +2852,7 @@ opcodes:
db 0x83 ; r/m <- imm8
dw 0x0000
- dd 0x00000000 ; 00:
- ; 0: r/m <- imm16/32 op flag
- ; 0: r/m <- imm8 op flag
- ; 0000:
-
+ dd 0x00000000
dd 0x00000000
; sub
@@ -2886,10 +2864,9 @@ opcodes:
db 0x83 ; r/m <- imm8
dw 0x0000
- dd 0x00005500 ; 00:
- ; 5: r/m <- imm16/32 op flag
- ; 5: r/m <- imm8 op flag
- ; 0000:
+ dw 0x0000
+ db 0x05 ; 5: r/m <- imm16/32 op flag
+ db 0x05 ; 5: r/m <- imm8 op flag
dd 0x00000000
@@ -2902,8 +2879,9 @@ opcodes:
db 0xE8 ; rel16/32
db 0x00
- dd 0x00000002 ; 2: r/m op flag
- ; 0000000:
+ db 0x02 ; 2: r/m op flag
+ db 0x00
+ dw 0x0000
dd 0x00000000
@@ -2924,10 +2902,9 @@ opcodes:
db 0x83 ; r/m <- imm8
dw 0x0000
- dd 0x00007700 ; 00:
- ; 7: r/m <- imm16/32 op flag
- ; 7: r/m <- imm8 op flag
- ; 0000:
+ dw 0x0000
+ db 0x07 ; 7: r/m <- imm16/32 op flag
+ db 0x07 ; 7: r/m <- imm8 op flag
dd 0x00000000
@@ -2940,27 +2917,26 @@ opcodes:
db 0x80 ; r/m8 <- imm8
dw 0x0000
- dd 0x01007000 ; 000:
- ; 7: r/m8 <- imm8 op flag
- ; 00:
- ; 01: bit8 flag
+ dw 0x0000
+ db 0x00
+ db 0x07 ; 7: r/m8 <- imm8 op flag
- dd 0x00000000
+ dw 0x0000
+ db 0x00
+ db 0x01 ; bit8 flag
; jmp
dw 0x005C
- db 0xFF ; r/m
+ db 0xFF ; r/m
db 0x00
dw 0x0000
- db 0xE9 ; rel16/32
- db 0xEB ; rel8
+ db 0xE9 ; rel16/32
+ db 0xEB ; rel8
- dd 0x00000004 ; 4: r/m
- ; 000:
- ; 0: rel16/32
- ; 0: rel8
- ; 00:
+ db 0x04 ; r/m
+ db 0x00
+ dw 0x0000
dd 0x00000000
@@ -2972,26 +2948,26 @@ opcodes:
db 0x84 ; rel16/32
db 0x74 ; rel8
- dd 0x00080000 ; 0000:
- ; 8: rel16/32 0x0F flag
- ; 000:
-
dd 0x00000000
+ db 0x08 ; 8: rel16/32 0x0F flag
+ db 0x00
+ dw 0x0000
+
; jne
dw 0x005E
dw 0x0000
dw 0x0000
- db 0x00 ; TODO figure out the 0x0F prefix this will need
+ db 0x85 ; rel16/32
db 0x75 ; rel8
- dd 0x00000000 ; 00000:
- ; 0: rel8
- ; 00:
-
dd 0x00000000
+ db 0x08 ; 8: rel16/32 0x0F flag
+ db 0x00
+ dw 0x0000
+
; push
; TODO add support for the +r variation
dw 0x005F
@@ -3002,11 +2978,9 @@ opcodes:
db 0x6A ; imm8
dw 0x0000
- dd 0x00000006 ; 6: r/m
- ; 0:
- ; 0: imm16/32
- ; 0: imm8
- ; 0000:
+ db 0x06 ; 6: r/m
+ db 0x00
+ dw 0x0000
dd 0x00000000
@@ -3015,12 +2989,8 @@ opcodes:
dw 0x0060
db 0x8F ; r/m
db 0x00
-
dd 0x00000000
-
- dd 0x00000000 ; 0: r/m
- ; 0000000:
-
+ dd 0x00000000
dd 0x00000000
; out