Browse Source

+ added range checking for the imm4 operand of NEC V20/V30's instructions
'EXT reg8,imm4' and 'INS reg8,imm4'

git-svn-id: trunk@33321 -

nickysn 9 years ago
parent
commit
0be6d062ac
3 changed files with 13 additions and 6 deletions
  1. 2 2
      compiler/i8086/i8086tab.inc
  2. 9 2
      compiler/x86/aasmcpu.pas
  3. 2 2
      compiler/x86/x86ins.dat

+ 2 - 2
compiler/i8086/i8086tab.inc

@@ -13004,7 +13004,7 @@
     ops     : 2;
     ops     : 2;
     optypes : (ot_reg8,ot_immediate,ot_none,ot_none);
     optypes : (ot_reg8,ot_immediate,ot_none,ot_none);
     code    : #2#15#59#128#21;
     code    : #2#15#59#128#21;
-    flags   : if_nec or if_sb or if_16bitonly
+    flags   : if_nec or if_sb or if_imm4 or if_16bitonly
   ),
   ),
   (
   (
     opcode  : A_INS;
     opcode  : A_INS;
@@ -13018,7 +13018,7 @@
     ops     : 2;
     ops     : 2;
     optypes : (ot_reg8,ot_immediate,ot_none,ot_none);
     optypes : (ot_reg8,ot_immediate,ot_none,ot_none);
     code    : #2#15#57#128#21;
     code    : #2#15#57#128#21;
-    flags   : if_nec or if_sb or if_16bitonly
+    flags   : if_nec or if_sb or if_imm4 or if_16bitonly
   ),
   ),
   (
   (
     opcode  : A_NOT1;
     opcode  : A_NOT1;

+ 9 - 2
compiler/x86/aasmcpu.pas

@@ -480,6 +480,7 @@ implementation
        { added flags }
        { added flags }
        IF_PRE    = $40000000;  { it's a prefix instruction }
        IF_PRE    = $40000000;  { it's a prefix instruction }
        IF_PASS2  = $80000000;  { if the instruction can change in a second pass }
        IF_PASS2  = $80000000;  { if the instruction can change in a second pass }
+       IF_IMM4   = $100000000; { immediate operand is a nibble (must be in range [0..15]) }
 
 
      type
      type
        TInsTabCache=array[TasmOp] of longint;
        TInsTabCache=array[TasmOp] of longint;
@@ -2968,8 +2969,14 @@ implementation
             &24,&25,&26,&27 :
             &24,&25,&26,&27 :
               begin
               begin
                 getvalsym(c-&24);
                 getvalsym(c-&24);
-                if (currval<0) or (currval>255) then
-                 Message2(asmw_e_value_exceeds_bounds,'unsigned byte',tostr(currval));
+                if (insentry^.flags and IF_IMM4)<>0 then
+                  begin
+                    if (currval<0) or (currval>15) then
+                      Message2(asmw_e_value_exceeds_bounds,'unsigned nibble',tostr(currval));
+                  end
+                else
+                  if (currval<0) or (currval>255) then
+                    Message2(asmw_e_value_exceeds_bounds,'unsigned byte',tostr(currval));
                 if assigned(currsym) then
                 if assigned(currsym) then
                  objdata_writereloc(currval,1,currsym,currabsreloc)
                  objdata_writereloc(currval,1,currsym,currabsreloc)
                 else
                 else

+ 2 - 2
compiler/x86/x86ins.dat

@@ -5038,14 +5038,14 @@ void                                  \2\x0F\x26                          NEC,16
 [EXT]
 [EXT]
 (Ch_All, Ch_None, Ch_None)
 (Ch_All, Ch_None, Ch_None)
 reg8,reg8                             \2\x0F\x33\101                      NEC,16BITONLY
 reg8,reg8                             \2\x0F\x33\101                      NEC,16BITONLY
-reg8,imm                              \2\x0F\x3B\200\25                   NEC,SB,16BITONLY
+reg8,imm                              \2\x0F\x3B\200\25                   NEC,SB,IMM4,16BITONLY
 
 
 ;[FPO2]
 ;[FPO2]
 
 
 [INS]
 [INS]
 (Ch_All, Ch_None, Ch_None)
 (Ch_All, Ch_None, Ch_None)
 reg8,reg8                             \2\x0F\x31\101                      NEC,16BITONLY
 reg8,reg8                             \2\x0F\x31\101                      NEC,16BITONLY
-reg8,imm                              \2\x0F\x39\200\25                   NEC,SB,16BITONLY
+reg8,imm                              \2\x0F\x39\200\25                   NEC,SB,IMM4,16BITONLY
 
 
 [NOT1]
 [NOT1]
 (Ch_Mop2, Ch_Rop1, Ch_None)
 (Ch_Mop2, Ch_Rop1, Ch_None)