home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 6 / FreshFish_September1994.bin / new / dev / c / hce / hcesource / top / source / inst.h < prev    next >
C/C++ Source or Header  |  1992-09-02  |  5KB  |  159 lines

  1. /* Copyright (c) 1988,1991 by Sozobon, Limited.  Author: Tony Andrews
  2.  *
  3.  * Permission is granted to anyone to use this software for any purpose
  4.  * on any computer system, and to redistribute it freely, with the
  5.  * following restrictions:
  6.  * 1) No charge may be made other than reasonable charges for reproduction.
  7.  * 2) Modified versions must be clearly marked as such.
  8.  * 3) The authors are not responsible for any harmful consequences
  9.  *    of using this software, even if they result from defects in it.
  10.  *
  11.  * Changed by Detlef Wuerkner fo Amiga
  12.  * Changes marked with TETISOFT
  13.  */
  14.  
  15. /*
  16.  * Misc. define's, etc. for instruction parsing.
  17.  */
  18.  
  19. struct    opnd {
  20.     unsigned char    amode;    /* addressing mode used */
  21.     unsigned char    areg;    /* primary register */
  22.     unsigned char    ireg;    /* index register, if applicable */
  23.     union {
  24.         long    i_disp;        /* also used for immediate data */
  25.         char    *i_astr;    /* pointer to any symbol present */
  26.     } i_data;
  27. };
  28. #define    disp    i_data.i_disp
  29. #define    astr    i_data.i_astr
  30.  
  31. /*
  32.  * is_astr(m)    macro to determine, based on the amode field, whether
  33.  *        the 'astr' field of the structure is active.
  34.  */
  35. #define    is_astr(m)    (((m) == ABS) || ((m) == (IMM|SYMB)))
  36.  
  37. /*
  38.  * Addressing modes (in 'amode')
  39.  */
  40. #define    NONE    0        /* operand unused */
  41. #define    REG    1        /* register direct */
  42. #define    IMM    2        /* immediate */
  43. #define    ABS    3        /* absolute */
  44. #define    REGI    4        /* reg. indirect */
  45. #define    REGID    5        /* reg. indirect, w/ displacement */
  46. #define    REGIDX    6        /* reg. indirect, w/ displacement & index */
  47. #define    PCD    7        /* PC relative, w/ displacement */
  48. #define    PCDX    8        /* PC relative, w/ displacement & index */
  49.  
  50. #define    XLONG    0x10        /* long index register used */
  51. #define    SYMB    0x20        /* symbol used, not constant */
  52. #define    INC    0x40        /* auto-increment */
  53. #define    DEC    0x80        /* auto-decrement */
  54.  
  55. #define    MMASK    0x0f        /* mode mask */
  56. #define    FMASK    0xf0        /* flag mask */
  57.  
  58. #define    M(x)    ((x) & MMASK)
  59. #define    F(x)    ((x) & FMASK)
  60.  
  61. /*
  62.  * Registers
  63.  */
  64.  
  65. #define    FIRSTREG    0
  66. #define    A0    0
  67. #define    A1    1
  68. #define    A2    2
  69. #define    A3    3
  70. #define    A4    4
  71. #define    A5    5
  72. #define    A6    6
  73. #define    A7    7
  74. #define    SP    7    /* alias for A7 */
  75. #define    D0    8
  76. #define    D1    9
  77. #define    D2    10
  78. #define    D3    11
  79. #define    D4    12
  80. #define    D5    13
  81. #define    D6    14
  82. #define    D7    15
  83. #define    LASTREG    15
  84.  
  85. /* ADDED BY TETISOFT */
  86. /* For use with cclib.library, which destroys A6, A5 must be used as pointer
  87.  * to the local stack. D3 cannot be used for registerized variables, since
  88.  * the library also destroys it. You must set this flags in the same manner
  89.  * than you did in PARAM.H for the compiler itself. If you change this flags,
  90.  * reg.c and data.c have to be recompiled, otherwise no registerizing is
  91.  * possible.
  92.  *
  93.  * 15-01-91 TetiSoft Changed DRV_START from D4 back to D3
  94.  *          (CClib.library V3.0 seems to keep D3)
  95.  *
  96.  * 20-05-91 TetiSoft Added A2 as register variable
  97.  *
  98.  * Register Usage of HCC is now as follows:
  99.  * D0,D1,A0,A1 Scratch
  100.  * D2 Temporary Register for Data Shifts (ASL etc)
  101.  * D3,D4,D5,D6,D7 Register Variables
  102.  * A2,A3,A4 Register Variables
  103.  * A5 Local Stack Frame
  104.  * A6 Base Addr for Library Calls AND Temporary Reg for Structure Assignments
  105.  * A7 Stack Pointer
  106.  *
  107.  * Temporary registers are not saved between function or library calls,
  108.  * even if CClib.library V3.0 saves D2 , the routines in lmath.asm,
  109.  * the stub codes generated by FD2Stubs and the code generated by HCC
  110.  * destroy it.
  111.  * Register variables are saved on function or library entry and restored 
  112.  * at exit. If you write assembler subroutines for HCC, you MUST save these
  113.  * registers!
  114.  * Since CClib.library calls require parameters on stack AND library base in
  115.  * A6, it would be very difficult to create stub codes that saves A6 without
  116.  * changing A7. Also the execution speed gain of this function calls would be
  117.  * lost. So I decided to give up A6 as local stack pointer and use A5 instead.
  118.  * This resulted in the fact that only A3 and A4 were address register
  119.  * variables. Therefore I changed the register usage for structure assignments
  120.  * from A2 to A6 to gain another register variable.
  121.  */
  122. #define    FRAMEP        A5
  123. #define    DRV_START    D3
  124. #define    CCLIB        1
  125.  
  126. #define    ISD(x)    ((x) >= D0 && (x) <= D7)    /* is 'x' a  D reg. */
  127. #define    ISA(x)    ((x) >= A0 && (x) <= A7)    /* is 'x' an A reg. */
  128. #define    RM(x)    (1 << (x))            /* form a register mask */
  129.  
  130. /*
  131.  * DOK(x) - evaluates TRUE if 'x' is okay for a displacement value.
  132.  *
  133.  * 'x' must be of type "long"
  134.  */
  135. #define    DOK(x)    (((x) >= -32768L) && ((x) <= 32767L))
  136.  
  137. /*
  138.  * D8OK(x) - like DOK but for 8-bit displacements
  139.  */
  140. #define    D8OK(x)    (((x) >= -128) && ((x) <= 127))
  141.  
  142. struct    inst {
  143.     char    opcode;            /* type of instruction */
  144.     char    flags;            /* length, etc. */
  145.     struct    opnd    src, dst;    /* optional operands */
  146.     int    rref, rset;
  147.     int    live;            /* regs. live after this inst. */
  148.     struct    inst    *next;
  149.     struct    inst    *prev;
  150. };
  151.  
  152. /*
  153.  * Instruction flags
  154.  */
  155.  
  156. #define    LENB    0x01
  157. #define    LENW    0x02
  158. #define    LENL    0x04
  159.