add 8 bit opcode support

This commit is contained in:
andromeda
2026-03-31 22:20:30 +02:00
parent ad9be1029c
commit 395c42dff4
4 changed files with 122 additions and 27 deletions

View File

@@ -374,8 +374,8 @@ assemble:
and al, 11b ; al = register width
cmp al, 00b ; 8 bit
je .unexpected_token ; TODO handle 8 bit opcodes
cmp al, 00b ; 8 bit
je .operator_2_register_8
cmp al, 01b ; 16 bit
je .operator_2_register_16
@@ -385,11 +385,16 @@ assemble:
cmp al, 11b ; 64 bit
je .operator_2_register_64
.operator_2_register_8:
mov bl, 1b ; operator flag 8bit
jmp .operator_2_register_continue
.operator_2_register_16:
xor ebx, ebx ; no operator flags
mov al, 0x66
call .push_byte
jmp .operator_2_register_continue
.operator_2_register_64:
xor ebx, ebx ; no operator flags
mov al, 0x48
call .push_byte
jmp .operator_2_register_continue
@@ -430,6 +435,7 @@ assemble:
push rsi
mov di, cx ; di = tte of operator
mov sil, 1 ; dst = reg
mov bl, 1 ; bl = operator flag byte
call get_opcode
; al = opcode
; dl = op flag
@@ -484,6 +490,7 @@ assemble:
push rsi
mov di, cx ; di = tte of operator
mov sil, 1 ; dst = reg
; bl = operator flag byte
call get_opcode
; al = opcode
; dl = op flag
@@ -606,6 +613,17 @@ assemble:
push rsi
mov di, cx ; di = tte of operator
mov sil, 2 ; dst=r/m,src=imm
; bl = operator flag byte
; TODO change sil based on whether bl is 8 bit or not
push rbx
and ebx, 1
cmp bl, 1 ; bit8 flag
pop rbx
je .operator_2_register_const_get_opcode_8
jmp .operator_2_register_const_get_opcode_continue
.operator_2_register_const_get_opcode_8:
mov sil, 3 ; dst=r/m,src=imm8
.operator_2_register_const_get_opcode_continue:
call get_opcode
; al = opcode
; dl = op flag
@@ -616,6 +634,12 @@ assemble:
call .next_token
jge .break
push rbx
and ebx, 1
cmp bl, 1 ; bit8 flag
pop rbx
je .operator_2_register_const_8
push rdi
push rsi
mov edi, .buffer_end - .buffer ; length of buffer
@@ -639,6 +663,11 @@ assemble:
je .operator_2_register_const_16
jmp .operator_2_register_const_32
.operator_2_register_const_8:
mov ecx, [.tokens_processed]
mov al, [TOKEN_TABLE_ADDR + 2 * rcx] ; get the next byte from the tt
call .write_byte ; and add it to the buffer
jmp .operator_2_register_const_continue
.operator_2_register_const_16:
mov ecx, [.tokens_processed]
mov ax, [TOKEN_TABLE_ADDR + 2 * rcx] ; get the next 2 bytes from the tt
@@ -981,6 +1010,7 @@ get_ModRM:
; di = token table entry
; sil = offset within opcode entry. 0 is the first opcode, 1 the second, and so
; on
; bl = flag byte
;
; returned:
; al = opcode; the rest of rax is zeroed.
@@ -989,6 +1019,7 @@ get_ModRM:
get_opcode:
and edi, 0xFFFF ; di = token table entry
and ebx, 0xFF ; bl = flag byte
add esi, 2
and esi, 111b ; offset within opcode entry
@@ -1005,10 +1036,20 @@ get_opcode:
shr eax, 4
cmp cx, di
je .found
je .maybe_found
inc eax
jmp .loop
.maybe_found:
shl eax, 4
mov cl, [opcodes.by_id + 11 + eax]
shr eax, 4
cmp cl, bl
je .found
inc eax
jmp .loop
.not_found:
xor eax, eax
mov eax, UNRECOGNISED_ID_OPCODE
@@ -2677,6 +2718,22 @@ opcodes:
dd 0x00000000
; mov bit8
dw 0x0056
db 0x88 ; r/m8 <- r8
db 0x8A ; r8 <- r/m8
db 0x00
db 0xC6 ; r/m8 <- imm8
dw 0x0000
dd 0x01000000 ; 000:
; 0: r/m8 <- imm8 op flag
; 00:
; 01: bit8 flag
dd 0x00000000
; add
dw 0x0057
db 0x01 ; r/m <- r
@@ -2747,6 +2804,20 @@ opcodes:
dd 0x00000000
; cmp bit8
dw 0x005B
db 0x38 ; r/m8 <- r8
db 0x3A ; r8 <- r/m8
db 0x00
db 0x80 ; r/m8 <- imm8
dw 0x0000
dd 0x01007000 ; 000:
; 7: r/m8 <- imm8 op flag
; 00:
; 01: bit8 flag
; jmp
dw 0x005C
db 0xFF ; r/m