guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] 120/437: Change _ASM_SAFETY register width check to acce


From: Andy Wingo
Subject: [Guile-commits] 120/437: Change _ASM_SAFETY register width check to accept valid alternate values.
Date: Mon, 2 Jul 2018 05:13:57 -0400 (EDT)

wingo pushed a commit to branch lightning
in repository guile.

commit 8665ce16daaba48eeec7cf2f6cf0e5003cdd0bd5
Author: PCPA <address@hidden>
Date:   Sat Aug 28 03:24:27 2010 -0300

    Change _ASM_SAFETY register width check to accept valid alternate values.
    
      The checks were moved from i386/asm.h to i386/asm-{32,64}.h, as well
    as some macros from core-{32,64}.h. Now it checks if the value is in the
    range of a valid register, and in the proper register class, what should
    prevent the common mistake of calling a jit*r_x macro passing an immediate
    as argument.
      Now it pass lightning's make check in i386/x86_64, as well as all test
    cases in http://code.google.com/p/exl/source/browse/trunk/check/lightning
    when compiled with -D_ASM_SAFETY.
---
 lightning/core-common.h  |  2 ++
 lightning/i386/asm-32.h  | 54 +++++++++++++++++++++++++++++++++++++++---
 lightning/i386/asm-64.h  | 61 +++++++++++++++++++++++++++++++++++++++---------
 lightning/i386/asm.h     | 14 -----------
 lightning/i386/core-32.h |  5 ----
 lightning/i386/core-64.h |  3 ---
 6 files changed, 103 insertions(+), 36 deletions(-)

diff --git a/lightning/core-common.h b/lightning/core-common.h
index c82c26f..4182b7d 100644
--- a/lightning/core-common.h
+++ b/lightning/core-common.h
@@ -543,8 +543,10 @@ typedef union jit_code {
 #define jit_extr_i_ul(d, rs)           jit_movr_i(d, rs)
 
 /* Unary */
+#ifndef jit_movi_l
 #define jit_movi_l(d, rs)              jit_movi_i((d), (rs))
 #define jit_movr_l(d, rs)              jit_movr_i((d), (rs))
+#endif
 
 /* Stack */
 #define jit_pushr_l(rs)                        jit_pushr_i(rs)
diff --git a/lightning/i386/asm-32.h b/lightning/i386/asm-32.h
index 649ef75..c5c0f80 100644
--- a/lightning/i386/asm-32.h
+++ b/lightning/i386/asm-32.h
@@ -43,11 +43,59 @@
  *             + sr/sm         = a star preceding a register or memory
  */
 
-#if defined(_ASM_SAFETY)
-#define _r1(R)          ( ((R) & ~3) == _AL || ((R) & ~3) == _AH ? _rN(R) : 
JITFAIL( "8-bit register required"))
+#if !_ASM_SAFETY
+#  define _r1(R)               _rN(R)
+#  define _r2(R)               _rN(R)
+#  define _r4(R)               _rN(R)
+#  define _r8(R)               _rN(R)
+#  define _rM(R)               _rN(R)
+#  define _rX(R)               _rN(R)
+#else
+/* _r1() used to check only for _AL and _AH but there is
+ * usage of _CL and _DL when _*AX is already an operand */
+#  define _r1(R)                                                       \
+    /* Valid 32 bit register? */                                       \
+    ((!((R) & ~0x77)                                                   \
+       /* 32, 16 or 8 bit register? */                                 \
+       && (((_rC(R) == 0x40 || _rC(R) == 0x30 || _rC(R) == 0x10)       \
+           /* Yes. Register is _AL, _CL or _DL? */                     \
+           && (   (_rN(R) | 0x10) == _AL                               \
+               || (_rN(R) | 0x10) == _CL                               \
+               || (_rN(R) | 0x10) == _DL))                             \
+           /* No. Register is _AH? */                                  \
+       || ((_rC(R) == 0x20 && (_rN(R) | 0x20) == _AH))))               \
+       ? _rN(R) : JITFAIL("bad 8-bit register " #R))
+#  define _r2(R)                                                       \
+    /* Valid 32 bit register? */                                       \
+    ((!((R) & ~0x77)                                                   \
+       /* 32, 16 or 8 bit register? */                                 \
+       && (_rC(R) == 0x40 || _rC(R) == 0x30 || _rC(R) == 0x10))        \
+       ? _rN(R) : JITFAIL("bad 16-bit register " #R))
+#  define _r4(R)                                                       \
+    /* Valid 32 bit register? */                                       \
+    ((!((R) & ~0x77)                                                   \
+       /* 32, 16 or 8 bit register? */                                 \
+       && (_rC(R) == 0x40 || _rC(R) == 0x30 || _rC(R) == 0x10))        \
+       ? _rN(R) : JITFAIL("bad 32-bit register " #R))
+#  define _r8(R)                                                       \
+       JITFAIL("bad 64-bit register " #R)
+#  define _rM(R)                                                       \
+    /* Valid MMX register? */                                          \
+    ((!((R) & ~0x67) && _rC(R) == 0x60)                                        
\
+       ? _rN(R) : JITFAIL("bad MMX register " #R))
+#  define _rX(R)                                                       \
+    /* Valid SSE register? */                                          \
+    ((!((R) & ~0x77) && _rC(R) == 0x70)                                        
\
+       ? _rN(R) : JITFAIL("bad SSE register " #R))
 #endif
 
-#define _rA(R)          _r4(R)
+#define _rA(R)                 _r4(R)
+
+#define jit_check8(rs)         ((_rN(rs) | _AL) == _AL)
+#define jit_reg8(rs)                                                   \
+    ((jit_reg16(rs) == _SI || jit_reg16(rs) == _DI)                    \
+       ? _AL : (_rN(rs) | _AL))
+#define jit_reg16(rs)          (_rN(rs) | _AX)
 
 /* Use RIP-addressing in 64-bit mode, if possible */
 #define _r_X(   R, D,B,I,S,O)  (_r0P(I) ? (_r0P(B)    ? _r_D   (R,D            
    ) : \
diff --git a/lightning/i386/asm-64.h b/lightning/i386/asm-64.h
index 9b882f9..66680f4 100644
--- a/lightning/i386/asm-64.h
+++ b/lightning/i386/asm-64.h
@@ -43,8 +43,57 @@
  *             + sr/sm         = a star preceding a register or memory
  */
 
+#if !_ASM_SAFETY
+#  define _r1(R)               _rN(R)
+#  define _r2(R)               _rN(R)
+#  define _r4(R)               _rN(R)
+#  define _r8(R)               _rN(R)
+#  define _rM(R)               _rN(R)
+#  define _rX(R)               _rN(R)
+#else
+#  define _r1(R)                                                       \
+    /* Valid 64 bit register? */                                       \
+    ((!((R) & ~0xff)                                                   \
+       /* 64, 32, 16 or 8 bit register? */                             \
+       && (_rC(R) == 0x50 || _rC(R) == 0x40                            \
+               || _rC(R) == 0x30 || _rC(R) == 0x10))                   \
+       ? _rN(R) : JITFAIL("bad 8-bit register " #R))
+#  define _r2(R)                                                       \
+    /* Valid 64 bit register? */                                       \
+    ((!((R) & ~0xff)                                                   \
+       /* 64, 32, 16 or 8 bit register? */                             \
+       && (_rC(R) == 0x50 || _rC(R) == 0x40                            \
+               || _rC(R) == 0x30 || _rC(R) == 0x10))                   \
+       ? _rN(R) : JITFAIL("bad 16-bit register " #R))
+#  define _r4(R)                                                       \
+    /* Valid 64 bit register? */                                       \
+    ((!((R) & ~0xff)                                                   \
+       /* 64, 32, 16 or 8 bit register? */                             \
+       && (_rC(R) == 0x50 || _rC(R) == 0x40                            \
+               || _rC(R) == 0x30 || _rC(R) == 0x10))                   \
+       ? _rN(R) : JITFAIL("bad 32-bit register " #R))
+#  define _r8(R)                                                       \
+    /* Valid 64 bit register? */                                       \
+    ((!((R) & ~0xff)                                                   \
+       /* 64, 32, 16 or 8 bit register? */                             \
+       && (_rC(R) == 0x50 || _rC(R) == 0x40                            \
+               || _rC(R) == 0x30 || _rC(R) == 0x10))                   \
+       ? _rN(R) : JITFAIL("bad 64-bit register " #R))
+#  define _rM(R)                                                       \
+    /* Valid MMX* register? */                                         \
+    ((!((R) & ~0x6f) && _rC(R) == 0x60)                                        
\
+       ? _rN(R) : JITFAIL("bad MMX register " #R))
+#  define _rX(R)                                                       \
+    /* Valid SSE2 register? */                                         \
+    ((!((R) & ~0x7f) && _rC(R) == 0x70)                                        
\
+       ? _rN(R) : JITFAIL("bad SSE2 register " #R))
+#endif
+
+#define _rA(R)                 _r8(R)
 
-#define _rA(R)          _r8(R)
+#define jit_check8(rs)         1
+#define jit_reg8(rs)           (_rR(rs) | _AL)
+#define jit_reg16(rs)          (_rR(rs) | _AX)
 
 /* Use RIP-addressing in 64-bit mode, if possible */
 #if 0
@@ -125,16 +174,6 @@
 #define _R15           0x5F
 #define _RIP           -2
 
-#if defined(_ASM_SAFETY)
-#define _r1(R)          ( ((unsigned) _rC((R) - 16)) < (0x30 - 16)      ? 
_rN(R) : JITFAIL( "8-bit register required"))
-
-#if 0
-#define _r8(R)         ( (_rC(R) == 0x50)                      ? _rN(R) : 
JITFAIL("64-bit register required"))
-#else
-#define _r8(R)         ( (_rC(R) == 0x50)                      ? _rN(R) : 
_r4(R))
-#endif
-#endif
-
 #define _r1e8lP(R)     ((int)(R) >= _SPL && (int)(R) <= _DIL)
 
 #define DECWr(RD)      (_d16(), _REXLrr(0, RD),        _O_Mrm          (0xff   
        ,_b11,_b001  ,_r2(RD)                           ))
diff --git a/lightning/i386/asm.h b/lightning/i386/asm.h
index 8412ce7..237a27e 100644
--- a/lightning/i386/asm.h
+++ b/lightning/i386/asm.h
@@ -129,20 +129,6 @@ typedef _uc                jit_insn;
 #define _rN(R)         ((R) & 0x07)
 #define _rXP(R)                ((R) > 0 && _rR(R) > 7)
 
-#if !defined(_ASM_SAFETY)
-#define _r1(R)         _rN(R)
-#define _r2(R)         _rN(R)
-#define _r4(R)         _rN(R)
-#define _r8(R)         _rN(R)
-#define _rM(R)         _rN(R)
-#define _rX(R)         _rN(R)
-#else
-#define _r2(R)         ( (_rC(R) == 0x30)                      ? _rN(R) : 
JITFAIL("16-bit register required"))
-#define _r4(R)         ( (_rC(R) == 0x40)                      ? _rN(R) : 
JITFAIL("32-bit register required"))
-#define _rM(R)         ( (_rC(R) == 0x60)                      ? _rN(R) : 
JITFAIL("MMX register required"))
-#define _rX(R)         ( (_rC(R) == 0x70)                      ? _rN(R) : 
JITFAIL("SSE register required"))
-#endif
-
 #define _rbpP(R)       (_rR(R) == _rR(_EBP))
 #define _rspP(R)       (_rR(R) == _rR(_ESP))
 #define _rbp13P(R)     (_rN(R) == _rN(_EBP))
diff --git a/lightning/i386/core-32.h b/lightning/i386/core-32.h
index 313564f..6645c8f 100644
--- a/lightning/i386/core-32.h
+++ b/lightning/i386/core-32.h
@@ -122,11 +122,6 @@ struct jit_local_state {
 #define jit_patch_at(jump_pc,v)  jit_patch_long_at(jump_pc, v)
 
 /* Memory */
-
-#define jit_check8(rs)          ( (rs) <= _EBX )
-#define jit_reg8(rs)            ( ((rs) == _SI || (rs) == _DI) ? _AL : 
(_rN(rs) | _AL ))
-#define jit_reg16(rs)           ( _rN(rs) | _AX )
-
 #define jit_replace(s, rep, op)                         \
         (jit_pushr_i(rep),                              \
          MOVLrr((s), (rep)),                            \
diff --git a/lightning/i386/core-64.h b/lightning/i386/core-64.h
index 1214850..b0eff4c 100644
--- a/lightning/i386/core-64.h
+++ b/lightning/i386/core-64.h
@@ -241,9 +241,6 @@ static int jit_arg_reg_order[] = { _EDI, _ESI, _EDX, _ECX, 
_R8D, _R9D };
 /* Memory */
 
 /* Used to implement ldc, stc, ... We have SIL and friends which simplify it 
all.  */
-#define jit_check8(rs)          1
-#define jit_reg8(rs)            (_rR(rs) | _AL )
-#define jit_reg16(rs)           (_rR(rs) | _AX )
 #define jit_movbrm(rs, dd, db, di, ds)         MOVBrm(jit_reg8(rs), dd, db, 
di, ds)
 
 #define jit_ldr_c(d, rs)                MOVSBQmr(0,    (rs), 0,    0, (d))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]