home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 363_01 / asm.h < prev    next >
C/C++ Source or Header  |  1991-12-17  |  10KB  |  288 lines

  1. /***********************************************************************
  2.  *
  3.  *      ASM.H
  4.  *      Global Definitions for 68000 Assembler
  5.  *
  6.  *      Author: Paul McKee
  7.  *      ECE492    North Carolina State University
  8.  *
  9.  *        Date: 12/13/86
  10.  *
  11.  *      Modified: A.E. Romer
  12.  *          April 1991: "Invalid label" error code added
  13.  *          30 April 1991: Upgrade to 68020
  14.  *          Autumn 1991: "Invalid quick constant" error code added
  15.  *
  16.  ************************************************************************/
  17.  
  18.  
  19. /* include system header files for prototype checking */
  20. #include <stdio.h>
  21. #include <string.h>
  22. #include <process.h>
  23. #include <stdlib.h>
  24. /* #include <malloc.h>      required for Microsoft, but not for
  25.                                                         Zortech compiler */
  26.  
  27. #define     CHAR_DELIMITER      '\''
  28.                     /* Character and string delimiter in data constants */
  29. #define     LBUF_SIZE           256
  30.                     /* size of input line buffer */
  31.  
  32. /* extension word bit values */
  33. #define     XREG_IS_An      0x8000
  34. #define     XREG_NUM(x)     (x) << 12
  35. #define     XSIZE_LONG      0x0800
  36. #define     SCALE_EIGHT     0x0600
  37. #define     SCALE_FOUR      0x0400
  38. #define     SCALE_TWO       0x0200
  39. #define     FULL_FORMAT     0x0100
  40. #define     BASE_SUPPRESS   0x0080
  41. #define     X_SUPPRESS      0x0040
  42. #define     BASE_LONG       0x0030
  43. #define     BASE_WORD       0x0020
  44. #define     BASE_NULL       0x0010
  45. #define     POST_X          0x0004
  46. #define     PRE_X           0x0000               /* included for symmetry */
  47. #define     OUTER_LONG      0x0003
  48. #define     OUTER_WORD      0x0002
  49. #define     OUTER_NULL      0x0001
  50.  
  51. /* extension word bit masks */
  52. #define     BASE            0x0030
  53. #define     OUTER           0x0003
  54.  
  55. /* Status values */
  56.  
  57. /* These status values are 12 bits long with
  58.    a severity code in the upper 4 bits */
  59.  
  60. #define     OK                  0x00
  61.  
  62. /* Severe errors */
  63. #define     SEVERE              0x400
  64. #define     SYNTAX              0x401
  65. #define     INV_OPCODE          0x402
  66. #define     INV_ADDR_MODE       0x403
  67. #define     LABEL_REQUIRED      0x404
  68. #define     PHASE_ERROR         0x405
  69. #define     UNIMPLEMENTED       0x406
  70. #define     INV_SHORT_BRANCH    0x407
  71.  
  72. /* Errors */
  73. #define     ERROR               0x300
  74. #define     UNDEFINED           0x301
  75. #define     DIV_BY_ZERO         0x302
  76. #define     MULTIPLE_DEFS       0x303
  77. #define     REG_MULT_DEFS       0x304
  78. #define     REG_LIST_UNDEF      0x305
  79. #define     INV_FORWARD_REF     0x306
  80. #define     INV_LENGTH          0x307
  81.  
  82. /* Minor errors */
  83. #define     MINOR               0x200
  84. #define     INV_SIZE_CODE       0x201
  85. #define     INV_VECTOR_NUM      0x202
  86. #define     INV_BRANCH_DISP     0x203
  87. #define     INV_DISP            0x204
  88. #define     INV_ABS_ADDRESS     0x205
  89. #define     INV_3_BIT_DATA      0x206
  90. #define     INV_8_BIT_DATA      0x207
  91. #define     INV_16_BIT_DATA     0x208
  92. #define     ODD_ADDRESS         0x209
  93. #define     NOT_REG_LIST        0x20a
  94. #define     REG_LIST_SPEC       0x20b
  95. #define     INV_SHIFT_COUNT     0x20c
  96. #define     INV_LABEL           0x20d
  97.  
  98. /* Warnings */
  99. #define     WARNING             0x100
  100. #define     ASCII_TOO_BIG       0x101
  101. #define     NUMBER_TOO_BIG      0x102
  102. #define     INCOMPLETE          0x103
  103. #define     EXCESSIVE_SIZE      0x104
  104. #define     UNSIZED             0x105
  105. #define     IGNORED_SIZE        0x106
  106. #define     CORRECTED_SIZE      0x107
  107. #define     INV_QUICK_CONST     0x108
  108. #define     INV_MOVEQ_CONST     0x109
  109.  
  110. #define     SEVERITY            0xf00
  111.  
  112. /* The NEWERROR macro updates the error variable var only if the
  113.    new error code is more severe than all previous errors.  Throughout
  114.    ASM this is the standard means of reporting errors. */
  115.  
  116. #define     NEWERROR(var, code) if ((code & SEVERITY) > var) var = code
  117.  
  118. /* Symbol table definitions */
  119.  
  120. /* Significant length of a symbol */
  121. #define     SIGCHARS            8
  122.  
  123. /* Structure for operand descriptors */
  124. typedef struct
  125.     {
  126.     long mode;                          /* addressing mode code (see below) */
  127.     long data;        /* Immediate value, displacement, or absolute address */
  128.     char reg;                                 /* Base register number (0-7) */
  129.     char size;        /* Size of absolute address (WORD or LONG, see below) */
  130.     int  xtenWord;             /* first extension word in indexed operation */
  131.     int  bfXtenWord;                            /* bit field extension word */
  132.     long outDisp;                     /* outer displacement, for 68020 only */
  133.     char backRef;                      /* True if data is known on 1st pass */
  134.     char odBackRef;      /* True if outer displacement is known on 1st pass */
  135.     } opDescriptor;
  136.  
  137.  
  138. /* Structure for a symbol table entry */
  139. typedef struct symbolEntry
  140.     {
  141.     long int value;                           /* 32-bit value of the symbol */
  142.     struct symbolEntry *next;      /* Pointer to next symbol in linked list */
  143.     char flags;                                        /* Flags (see below) */
  144.     char name[SIGCHARS+1];                                          /* Name */
  145.     } symbolDef;
  146.  
  147.  
  148. /* Flag values for the "flags" field of a symbol */
  149.  
  150. #define     BACKREF             0x01
  151.                           /* Set when the symbol is defined on the 2nd pass
  152.                            * so that the following references know the symbol
  153.                            * has been defined */
  154. #define     REDEFINABLE         0x02
  155.                             /* Set for symbols defined by the SET directive */
  156. #define     REG_LIST_SYM        0x04
  157.                             /* Set for symbols defined by the REG directive */
  158. #define     MULTDEF             0x08
  159.                                     /* set if multiple definition attempted */
  160.  
  161.  
  162. /* Instruction table definitions */
  163.  
  164. /* Structure to describe one "variant" of an instruction */
  165.  
  166. typedef struct
  167.     {
  168.     long int source;                   /* Bit masks for the legal source... */
  169.     long int dest;                     /*  and destination addressing modes */
  170.     char sizes;                             /* Bit mask for the legal sizes */
  171.     int (*exec)(int, int, opDescriptor *, opDescriptor *, int *);
  172.                              /* Pointer to routine to build the instruction */
  173.     short int bytemask;      /* Skeleton instruction masks for byte size... */
  174.     short int wordmask;                                  /*  word size, ... */
  175.     short int longmask;               /*  and long sizes of the instruction */
  176.     } variant;
  177.  
  178.  
  179. /* Structure for the instruction table */
  180. typedef struct INSTR
  181.     {
  182.     char *mnemonic;                                             /* Mnemonic */
  183.     variant *variantPtr;                         /* Pointer to variant list */
  184.     char variantCount;                /* Number of variants in variant list */
  185.     char parseFlag;                /* Should assemble() parse the operands? */
  186.     int (*exec)(struct INSTR *, int, char *, char *, int *);
  187.                               /* Routine to be called if parseFlag is FALSE */
  188.     } instruction;
  189.  
  190.  
  191. /* Addressing mode codes/bitmasks */
  192.  
  193. #define     DnDirect            0x0000001
  194. #define     AnDirect            0x0000002
  195. #define     AnInd               0x0000004
  196. #define     AnIndPost           0x0000008
  197. #define     AnIndPre            0x0000010
  198. #define     AnIndDisp           0x0000020
  199. #define     AnIndIndex          0x0000040
  200. #define     AbsShort            0x0000080
  201. #define     AbsLong             0x0000100
  202. #define     PCDisp              0x0000200
  203. #define     PCIndex             0x0000400
  204. #define     Immediate           0x0000800
  205. #define     SRDirect            0x0001000
  206. #define     CCRDirect           0x0002000
  207. #define     USPDirect           0x0004000
  208. #define     SFCDirect           0x0008000
  209. #define     DFCDirect           0x0010000
  210. #define     VBRDirect           0x0020000
  211.  
  212. /* Addressing mode codes/bitmasks specific to the 68020 only */
  213.  
  214. #define     CACRDirect          0x0040000
  215. #define     CAARDirect          0x0080000
  216. #define     MSPDirect           0x0100000
  217. #define     ISPDirect           0x0200000
  218. #define     MemIndPostinx       0x0400000
  219. #define     MemIndPreinx        0x0800000
  220. #define     PCMemIndPostinx     0x1000000
  221. #define     PCMemIndPreinx      0x2000000
  222.  
  223. /* Definitions of addressing mode masks for various classes of references */
  224.  
  225. #define Data    (DnDirect | AnInd | AnIndPost | AnIndPre | AnIndDisp \
  226.         | AnIndIndex | AbsShort | AbsLong | PCDisp | PCIndex | Immediate \
  227. \
  228.                 /* additional modes specific to the 68020 only */ \
  229. \
  230.         | MemIndPostinx | MemIndPreinx | PCMemIndPostinx | PCMemIndPreinx)
  231.  
  232. #define Memory  (AnInd | AnIndPost | AnIndPre | AnIndDisp \
  233.         | AnIndIndex | AbsShort | AbsLong | PCDisp | PCIndex | Immediate \
  234. \
  235.                 /* additional modes specific to the 68020 only */ \
  236. \
  237.         | MemIndPostinx | MemIndPreinx | PCMemIndPostinx | PCMemIndPreinx)
  238. \
  239.  
  240. #define Control (AnInd | AnIndDisp | AnIndIndex | AbsShort | AbsLong | PCDisp \
  241.         | PCIndex \
  242. \
  243.                 /* additional modes specific to the 68020 only */ \
  244. \
  245.         | MemIndPostinx | MemIndPreinx | PCMemIndPostinx | PCMemIndPreinx)
  246.  
  247.  
  248. #define Alter   (DnDirect | AnDirect | AnInd | AnIndPost | AnIndPre | \
  249.         AnIndDisp | AnIndIndex | AbsShort | AbsLong \
  250. \
  251.                 /* additional modes specific to the 68020 only */ \
  252. \
  253.         | MemIndPostinx | MemIndPreinx)
  254.  
  255.  
  256. #define All         (Data | Memory | Control | Alter)
  257. #define DataAlt     (Data & Alter)
  258. #define CtrAlt      (Control & Alter)
  259. #define MemAlt      (Memory & Alter)
  260. #define Absolute    (AbsLong | AbsShort)
  261. #define GenReg      (DnDirect | AnDirect)
  262.  
  263.  
  264. /* Register, absolute address,  and operation size codes/bitmasks */
  265.  
  266. #define     BYTE                ((int) 1)
  267. #define     WORD                ((int) 2)
  268. #define     LONG                ((int) 4)
  269. #define     SHORT               ((int) 8)
  270.  
  271.  
  272. /* added for PC port -- 7/8/1988 */
  273.  
  274. #define     TRUE                -1
  275. #define     FALSE               0
  276.  
  277.  
  278. /* function return codes */
  279.  
  280. #define     NORMAL              0
  281.  
  282.  
  283.  
  284. /* function prototype definitions */
  285. #include    "proto.h"
  286.  
  287. /*************** end asm.h *******************/
  288.