add get_direct_addressing_ModRM and test_*, fix a couple bugs/typos, add 'reg value' as register metadata
This commit is contained in:
@@ -127,13 +127,15 @@ type metadata for the different types is as follows:
|
||||
```
|
||||
|
||||
```
|
||||
+------------------+
|
||||
| type 0x2 |
|
||||
+----------+-------+
|
||||
| 31 26 | 25 24 |
|
||||
+----------+-------+
|
||||
| reserved | width |
|
||||
+----------+-------+
|
||||
+------------------------------+
|
||||
| type 0x2 |
|
||||
+----------+-----------+-------+
|
||||
| 31 29 | 28 26 | 25 24 |
|
||||
+----------+-----------+-------+
|
||||
| reserved | reg value | width |
|
||||
+----------+-----------+-------+
|
||||
|
||||
; reg is the value that cooresponds to the register in the ModR/M byte
|
||||
|
||||
; width:
|
||||
00b ; 8 bit
|
||||
|
||||
@@ -187,6 +187,63 @@ get_tte_typed_metadata:
|
||||
mov al, [3 + tokens.by_id + rax * 4]
|
||||
ret
|
||||
|
||||
; ------------------------------------------------------------------------------
|
||||
; get_direct_addressing_ModRM
|
||||
;
|
||||
; description:
|
||||
; given 2 register tokens, returns the ModR/M byte in direct addressing
|
||||
; (mod = 11b) mode
|
||||
;
|
||||
; parameters:
|
||||
; di = token table entry `reg`
|
||||
; si = token table entry `R/M`
|
||||
;
|
||||
; returned:
|
||||
; al = ModR/M byte
|
||||
; ------------------------------------------------------------------------------
|
||||
|
||||
get_direct_addressing_ModRM:
|
||||
; TODO something is backwards in this function but I don't see it. If the test
|
||||
; suite fails, it's too far gone; rewrite it.
|
||||
push rdi
|
||||
push rsi
|
||||
; get metadata of reg
|
||||
call get_tte_typed_metadata
|
||||
; al = typed metadata of reg
|
||||
pop rsi
|
||||
pop rdi
|
||||
|
||||
mov bl, al ; bl = metadata of reg
|
||||
|
||||
push rdi
|
||||
push rsi
|
||||
push rbx
|
||||
|
||||
; get metadata of R/M
|
||||
mov di, si
|
||||
call get_tte_typed_metadata
|
||||
; al = typed metadata of R/M
|
||||
|
||||
pop rbx
|
||||
pop rsi
|
||||
pop rdi
|
||||
|
||||
mov dl, al
|
||||
|
||||
shr dl, 2
|
||||
and dl, 111b ; mask
|
||||
|
||||
shr bl, 2
|
||||
and bl, 111b ; mask
|
||||
shl bl, 3
|
||||
|
||||
xor eax, eax
|
||||
or al, 11b << 6 ; mod bits
|
||||
or al, dl ; reg bits
|
||||
or al, bl ; R/M bits
|
||||
and rax, 0xFF ; mask for byte
|
||||
ret
|
||||
|
||||
; ------------------------------------------------------------------------------
|
||||
; tokenising
|
||||
; ------------------------------------------------------------------------------
|
||||
@@ -872,30 +929,33 @@ tokens:
|
||||
dw 0x0059
|
||||
.by_name_5:
|
||||
.by_id:
|
||||
dw 0x0010 ; eax
|
||||
db 0x02 ; type: register
|
||||
db 00000010b ; reg: 000b
|
||||
; width: 10b (32 bits)
|
||||
|
||||
dw 0x0000 ; rax
|
||||
db 0x02 ; type: register
|
||||
db 00000011b ; reg: 000b
|
||||
; width: 11b (64 bits)
|
||||
|
||||
dw 0x0003 ; rdx
|
||||
db 0x02 ; type: register
|
||||
db 00001011b ; reg: 010b
|
||||
; width: 11b (64 bits)
|
||||
|
||||
dw 0x0053 ; xor
|
||||
db 0x01 ; type: operator
|
||||
db 0x02 ; # operands
|
||||
|
||||
dw 0x0010 ; eax
|
||||
db 0x02 ; type: register
|
||||
db 0x02 ; width: 32 bit
|
||||
|
||||
dw 0x0054 ; inc
|
||||
db 0x01 ; type: operator
|
||||
db 0x01 ; # operands
|
||||
|
||||
dw 0x0000 ; rax
|
||||
db 0x02 ; type: register
|
||||
db 0x03 ; width: 64 bit
|
||||
|
||||
dw 0x0056 ; mov
|
||||
db 0x01 ; type: operator
|
||||
db 0x02 ; # operands
|
||||
|
||||
dw 0x0003 ; rdx
|
||||
db 0x02 ; type: register
|
||||
db 0x03 ; width: 64 bit
|
||||
|
||||
dw 0x004F ; hlt
|
||||
db 0x01 ; type: operator
|
||||
db 0x00 ; # operands
|
||||
|
||||
@@ -34,6 +34,9 @@ run_tests:
|
||||
call clear_test_arena
|
||||
call test_get_tte_typed_metadata
|
||||
|
||||
call clear_test_arena
|
||||
call test_get_direct_addressing_ModRM
|
||||
|
||||
ret
|
||||
.msg db "running test suite...", 0x0A, 0x00
|
||||
|
||||
@@ -441,7 +444,8 @@ test_get_tte_typed_metadata:
|
||||
|
||||
mov di, 0x0003 ; rdx
|
||||
call get_tte_typed_metadata
|
||||
cmp al, 0x03 ; width: 64 bits
|
||||
cmp al, 00001011b ; reg: 010b
|
||||
; width: 11b (64 bits)
|
||||
jne .fail
|
||||
|
||||
mov di, 0x0056 ; mov
|
||||
@@ -462,7 +466,52 @@ test_get_tte_typed_metadata:
|
||||
mov rsi, msg_fail
|
||||
call print
|
||||
ret
|
||||
.msg db "test_get_tte_type...", 0x00
|
||||
.msg db "test_get_tte_typed_metadata...", 0x00
|
||||
|
||||
; ------------------------------------------------------------------------------
|
||||
; test_get_direct_addressing_ModRM
|
||||
;
|
||||
; description:
|
||||
; tests get_direct_addressing_ModRM described functionality
|
||||
; ------------------------------------------------------------------------------
|
||||
|
||||
test_get_direct_addressing_ModRM:
|
||||
mov rsi, .msg
|
||||
call print
|
||||
|
||||
mov di, 0x0000 ; rax
|
||||
mov si, 0x0000 ; rax
|
||||
call get_direct_addressing_ModRM
|
||||
cmp al, 11000000b ; Mod Reg R/M: 11b 000b 000b
|
||||
jne .fail
|
||||
|
||||
mov di, 0x0000 ; rax
|
||||
mov si, 0x0003 ; rdx
|
||||
call get_direct_addressing_ModRM
|
||||
cmp al, 11000010b ; Mod Reg R/M: 11b 000b 010b
|
||||
jne .fail
|
||||
|
||||
mov di, 0x0003 ; rdx
|
||||
mov si, 0x0000 ; rax
|
||||
call get_direct_addressing_ModRM
|
||||
cmp al, 11010000b ; Mod Reg R/M: 11b 010b 000b
|
||||
jne .fail
|
||||
|
||||
mov di, 0x0003 ; rdx
|
||||
mov si, 0x0003 ; rdx
|
||||
call get_direct_addressing_ModRM
|
||||
cmp al, 11010010b ; Mod Reg R/M 11b 010b 010b
|
||||
jne .fail
|
||||
|
||||
.pass:
|
||||
mov rsi, msg_pass
|
||||
call print
|
||||
ret
|
||||
.fail:
|
||||
mov rsi, msg_fail
|
||||
call print
|
||||
ret
|
||||
.msg db "test_get_direct_addressing_ModRM...", 0x00
|
||||
|
||||
msg_pass:
|
||||
db 0x0A
|
||||
|
||||
Reference in New Issue
Block a user