History

x86-asm: Reject some invalid arith imm8 instruction

There were two errors in the arithmetic imm8 instruction. They accept only REGW, and in case the user write a xxxb opcode that variant needs to be rejected as well (it's not automatically rejected by REGW in case the destination is memory).

Michael Matz committed 10 years ago

Commit f2a4cb01 parent 0f36f604 files · +25 −2Browse files

Unified · Split

4 files
  1. i386-asm.c +7 −0
  2. i386-asm.h +1 −1
  3. tests/asmtest.S +16 −0
  4. x86_64-asm.h +1 −1
i386-asm.c+7−0
@@ -552,7 +552,14 @@ ST_FUNC void asm_opcode(TCCState *s1, int opcode) · 551 unmodified lines
552 continue;552 continue;
553 s = (opcode - pa->sym) % NBWLX;553 s = (opcode - pa->sym) % NBWLX;
554 if ((pa->instr_type & OPC_BWLX) == OPC_WLX)554 if ((pa->instr_type & OPC_BWLX) == OPC_WLX)
555 {
556 /* We need to reject the xxxb opcodes that we accepted above.
557 Note that pa->sym for WLX opcodes is the 'w' token,
558 to get the 'b' token subtract one. */
559 if (((opcode - pa->sym + 1) % NBWLX) == 0)
560 continue;
555 s++;561 s++;
562 }
556 } else if (pa->instr_type & OPC_SHIFT) {563 } else if (pa->instr_type & OPC_SHIFT) {
557 if (!(opcode >= pa->sym && opcode < pa->sym + 7*NBWLX))564 if (!(opcode >= pa->sym && opcode < pa->sym + 7*NBWLX))
558 continue;565 continue;
i386-asm.h+1−1
@@ -157,7 +157,7 @@ ALT(DEF_ASM_OP2(lgs, 0x0fb5, 0, OPC_MODRM, OPT_EA, OPT_REG32)) · 156 unmodified lines
157ALT(DEF_ASM_OP2(addb, 0x00, 0, OPC_ARITH | OPC_MODRM | OPC_BWLX, OPT_REG, OPT_EA | OPT_REG)) /* XXX: use D bit ? */157ALT(DEF_ASM_OP2(addb, 0x00, 0, OPC_ARITH | OPC_MODRM | OPC_BWLX, OPT_REG, OPT_EA | OPT_REG)) /* XXX: use D bit ? */
158ALT(DEF_ASM_OP2(addb, 0x02, 0, OPC_ARITH | OPC_MODRM | OPC_BWLX, OPT_EA | OPT_REG, OPT_REG))158ALT(DEF_ASM_OP2(addb, 0x02, 0, OPC_ARITH | OPC_MODRM | OPC_BWLX, OPT_EA | OPT_REG, OPT_REG))
159ALT(DEF_ASM_OP2(addb, 0x04, 0, OPC_ARITH | OPC_BWLX, OPT_IM, OPT_EAX))159ALT(DEF_ASM_OP2(addb, 0x04, 0, OPC_ARITH | OPC_BWLX, OPT_IM, OPT_EAX))
160ALT(DEF_ASM_OP2(addw, 0x83, 0, OPC_ARITH | OPC_MODRM | OPC_WLX, OPT_IM8S, OPT_EA | OPT_REG))160ALT(DEF_ASM_OP2(addw, 0x83, 0, OPC_ARITH | OPC_MODRM | OPC_WLX, OPT_IM8S, OPT_EA | OPT_REGW))
161ALT(DEF_ASM_OP2(addb, 0x80, 0, OPC_ARITH | OPC_MODRM | OPC_BWLX, OPT_IM, OPT_EA | OPT_REG))161ALT(DEF_ASM_OP2(addb, 0x80, 0, OPC_ARITH | OPC_MODRM | OPC_BWLX, OPT_IM, OPT_EA | OPT_REG))
162 162
163ALT(DEF_ASM_OP2(testb, 0x84, 0, OPC_MODRM | OPC_BWLX, OPT_REG, OPT_EA | OPT_REG))163ALT(DEF_ASM_OP2(testb, 0x84, 0, OPC_MODRM | OPC_BWLX, OPT_REG, OPT_EA | OPT_REG))
tests/asmtest.S+16−0
@@ -158,6 +158,22 @@ addl $0x123, %eax · 157 unmodified lines
158add $0x123, %ebx158add $0x123, %ebx
159add $-16, %ecx159add $-16, %ecx
160add $-0x123, %esi160add $-0x123, %esi
161add $1, %bx
162add $1, %ebx
163add $-1, %bx
164add $-1, %ebx
165add $127, %bx
166addl $127, %ebx
167addl $-128, %ebx
168addl $-128, %ebx
169addl $-129, %ebx
170addl $128, %ebx
171addl $255, %ebx
172addl $256, %ebx
173andb $0xf, %ah
174andb $-15, %cl
175xorb $127, %dh
176cmpb $42, (%eax)
161addl $0x123, 0x100177addl $0x123, 0x100
162addl $0x123, 0x100(%ebx)178addl $0x123, 0x100(%ebx)
163addl $0x123, 0x100(%ebx,%edx,2)179addl $0x123, 0x100(%ebx,%edx,2)
x86_64-asm.h+1−1
@@ -166,7 +166,7 @@ ALT(DEF_ASM_OP2(lgs, 0x0fb5, 0, OPC_MODRM, OPT_EA, OPT_REG32)) · 165 unmodified lines
166ALT(DEF_ASM_OP2(addb, 0x00, 0, OPC_ARITH | OPC_MODRM | OPC_BWLX, OPT_REG, OPT_EA | OPT_REG)) /* XXX: use D bit ? */166ALT(DEF_ASM_OP2(addb, 0x00, 0, OPC_ARITH | OPC_MODRM | OPC_BWLX, OPT_REG, OPT_EA | OPT_REG)) /* XXX: use D bit ? */
167ALT(DEF_ASM_OP2(addb, 0x02, 0, OPC_ARITH | OPC_MODRM | OPC_BWLX, OPT_EA | OPT_REG, OPT_REG))167ALT(DEF_ASM_OP2(addb, 0x02, 0, OPC_ARITH | OPC_MODRM | OPC_BWLX, OPT_EA | OPT_REG, OPT_REG))
168ALT(DEF_ASM_OP2(addb, 0x04, 0, OPC_ARITH | OPC_BWLX, OPT_IM, OPT_EAX))168ALT(DEF_ASM_OP2(addb, 0x04, 0, OPC_ARITH | OPC_BWLX, OPT_IM, OPT_EAX))
169ALT(DEF_ASM_OP2(addw, 0x83, 0, OPC_ARITH | OPC_MODRM | OPC_WLX, OPT_IM8S, OPT_EA | OPT_REG))169ALT(DEF_ASM_OP2(addw, 0x83, 0, OPC_ARITH | OPC_MODRM | OPC_WLX, OPT_IM8S, OPT_EA | OPT_REGW))
170ALT(DEF_ASM_OP2(addb, 0x80, 0, OPC_ARITH | OPC_MODRM | OPC_BWLX, OPT_IM, OPT_EA | OPT_REG))170ALT(DEF_ASM_OP2(addb, 0x80, 0, OPC_ARITH | OPC_MODRM | OPC_BWLX, OPT_IM, OPT_EA | OPT_REG))
171 171
172ALT(DEF_ASM_OP2(testb, 0x84, 0, OPC_MODRM | OPC_BWLX, OPT_REG, OPT_EA | OPT_REG))172ALT(DEF_ASM_OP2(testb, 0x84, 0, OPC_MODRM | OPC_BWLX, OPT_REG, OPT_EA | OPT_REG))

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t