A68kglb.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. /*------------------------------------------------------------------*/
  2. /* */
  3. /* MC68000 Cross Assembler */
  4. /* */
  5. /* Copyright 1985 by Brian R. Anderson */
  6. /* */
  7. /* Global variables - April 16, 1991 */
  8. /* */
  9. /* This program may be copied for personal, non-commercial use */
  10. /* only, provided that the above copyright notice is included */
  11. /* on all copies of the source code. Copying for any other use */
  12. /* without the consent of the author is prohibited. */
  13. /* */
  14. /*------------------------------------------------------------------*/
  15. /* */
  16. /* Originally published (in Modula-2) in */
  17. /* Dr. Dobb's Journal, April, May, and June 1986. */
  18. /* */
  19. /* AmigaDOS conversion copyright 1991 by Charlie Gibbs. */
  20. /* */
  21. /*------------------------------------------------------------------*/
  22. #ifdef PRIMARY
  23. #define GLOBAL
  24. #else
  25. #define GLOBAL extern
  26. #endif
  27. GLOBAL char SourceFN[MAXFN]; /* Source file name */
  28. GLOBAL char HeaderFN[MAXFN]; /* Header file name (-h) */
  29. GLOBAL char SrecFN[MAXFN]; /* Object file name (-o) */
  30. GLOBAL char InclList[MAXLINE]; /* List of directories to search (-i) */
  31. GLOBAL char IdntName[MAXLINE]; /* Program unit name */
  32. struct fs {
  33. int fd; /* File handle */
  34. char *Buf; /* Pointer to buffer */
  35. char *Ptr; /* Current position in buffer */
  36. char *Lim; /* Logical end of buffer */
  37. };
  38. GLOBAL struct fs In; /* Input file */
  39. GLOBAL struct fs Eq; /* Equate file */
  40. GLOBAL struct fs List; /* Listing file */
  41. GLOBAL struct fs Srec; /* Object file */
  42. /* Command-line options */
  43. GLOBAL int AllRelocs; /* -a Output all relocs. - added by Kevin Kofler in
  44. v.2.71.F3l */
  45. GLOBAL int DumpSym; /* -d Dump the symbol table. */
  46. GLOBAL char DumpSymList[MAXLINE]; /* -d selection list */
  47. GLOBAL int FwdProc; /* -f Special processing for forward references */
  48. GLOBAL int GlobalXREF; /* -g Make all unknown globals XREFed */
  49. GLOBAL int SuppList; /* (neither -l nor -x) Suppress listing file. */
  50. GLOBAL long DataOffset; /* -m Offset to small data base (normally 32767) */
  51. GLOBAL int NoOpt; /* -n Suppress all optimization. */
  52. GLOBAL int LnMax; /* -p Maximum number of lines per page */
  53. GLOBAL int Quiet; /* -q Line no. display interval (0 to suppress) */
  54. GLOBAL long optim; /* -r Remove optimization mask - added by Paul Froissart
  55. in v.2.71.F3c */
  56. GLOBAL int KeepTabs; /* -t Keep tabs in the listing file. */
  57. GLOBAL int Unaligned; /* -u Allow unaligned DC.W, DC.L, DCB.W, DCB.L, DS.W,
  58. DS.L and code. - added by Kevin Kofler in
  59. v.2.71.F3k */
  60. GLOBAL long HashSize; /* -w Number of entries in the hash table */
  61. GLOBAL int XrefList; /* -x Produce a cross-reference listing. */
  62. GLOBAL int HashStats; /* -y Display hashing statistics. */
  63. GLOBAL int DebugStart; /* -z Debug display starts here. */
  64. GLOBAL int DebugEnd; /* -z Debug display ends here. */
  65. GLOBAL char TTLstring[MAXLINE]; /* Title string */
  66. GLOBAL int LabLine; /* Last labeled line number */
  67. GLOBAL int LineCount; /* Source line counter */
  68. GLOBAL char Line[MAXLINE]; /* Current source line */
  69. GLOBAL char Label[MAXLINE]; /* Instruction label */
  70. GLOBAL char OpCode[MAXLINE]; /* Instruction mnemonic */
  71. GLOBAL char SrcOp[MAXLINE]; /* First (source) operand */
  72. GLOBAL char DestOp[MAXLINE]; /* Second (destination) operand */
  73. GLOBAL int LabLoc, OpLoc; /* Label and mnemonic start here */
  74. GLOBAL int SrcLoc, DestLoc; /* Operands start here. */
  75. GLOBAL int Dir, PrevDir; /* Assembler directive */
  76. GLOBAL int NumSyms; /* Number of symbols */
  77. GLOBAL long ObjOp; /* OpCode object code */
  78. GLOBAL long ObjSrc; /* Source operand object code */
  79. GLOBAL long ObjDest; /* Destination operand object code */
  80. GLOBAL char ObjString[MAXLINE]; /* String data */
  81. GLOBAL int nO, nS, nD, nX; /* Length of above components */
  82. GLOBAL int PrntAddr; /* Print AddrCnt on listing. */
  83. GLOBAL int MakeHunk; /* We must make a hunk. */
  84. GLOBAL int ListOff; /* NOLIST is supressing listing lines. */
  85. GLOBAL int LnCnt; /* Number of lines on current page */
  86. GLOBAL int PgCnt; /* Page number */
  87. GLOBAL long Hunk2; /* Hunk number (from GetValue) */
  88. GLOBAL int DefLine2; /* Definition line number */
  89. GLOBAL int SingleFlag; /* Expression consists of a single term. */
  90. GLOBAL int GotEqur; /* We have register equates. */
  91. GLOBAL int SmallData; /* Register for small data model (or -1) */
  92. GLOBAL int AnyNear; /* We got at least one NEAR directive. */
  93. GLOBAL int FwdShort; /* Forward reference could be made short. */
  94. GLOBAL int Pass2; /* Pass 2 flag */
  95. GLOBAL long AddrCnt; /* Location counter */
  96. GLOBAL long AddrAdv; /* Bump AddrCnt by this much. */
  97. GLOBAL long DupFact; /* Duplication factor for DCB, 1 otherwise */
  98. GLOBAL long OrgHigh; /* Highest address reached if we ORG backwards */
  99. GLOBAL long OrgSeek; /* Return here in Srec if we ORG backwards. */
  100. GLOBAL long EndAddr; /* END statement transfer address */
  101. GLOBAL long SectStart; /* Current section (or portion) starts here. */
  102. GLOBAL int SectLine; /* Line number where section started */
  103. GLOBAL int HunkSeq; /* Hunk sequence number */
  104. GLOBAL long HunkType; /* Current hunk type */
  105. GLOBAL long HunkFlags; /* Hunk flags (MEMF_FAST or MEMF_CHIP) */
  106. GLOBAL long CurrHunk; /* Current hunk number */
  107. GLOBAL long NextHunk; /* Next available hunk number */
  108. GLOBAL long LenPos; /* Seek position of current hunk length */
  109. GLOBAL char *LenPtr; /* Pointer to length if in buffer, else NULL */
  110. GLOBAL int InclErrs; /* Error processing INCLUDE statement(s) */
  111. GLOBAL int InnrFMac; /* An inner file has been read by a user macro. */
  112. GLOBAL int OrgFlag; /* ORG may require object file fixup. */
  113. GLOBAL int SFormat; /* Generate S-record format. */
  114. GLOBAL long StartAddr; /* Address that record starts on */
  115. GLOBAL long TempAddr; /* Address of where we are now */
  116. GLOBAL int IncStart; /* Start line number of skippable INCLUDE */
  117. GLOBAL struct InFCtl *IncPtr; /* Copy of InF for skippable INCLUDE */
  118. struct SkipEnt { /* Skippable INCLUDE description */
  119. struct SetFixup *Set1; /* Pointer to first SET fixup */
  120. int Start; /* Starting line number of INCLUDE */
  121. int Finish; /* Ending line number of INCLUDE */
  122. int MCount; /* Value of MacCount at end of INCLUDE */
  123. int LLine; /* Value of LabLine at end of INCLUDE
  124. -- added by Kevin Kofler in v.2.71.F3i */
  125. };
  126. struct SetFixup { /* SET symbol fixup entry */
  127. struct SymTab *Sym; /* Pointer to symbol table entry */
  128. long Val; /* Fixup value */
  129. long Hunk; /* Fixup hunk number */
  130. };
  131. GLOBAL struct SkipEnt *SkipLim; /* Logical end of skippable INCLUDEs */
  132. GLOBAL struct SkipEnt *SkipIdx; /* Current skippable INCLUDE entry */
  133. GLOBAL struct SetFixup *SetFixLim; /* Next available SetFixup */
  134. struct SymTab { /* Symbol table */
  135. struct SymTab *Link; /* Link to next entry in hash chain */
  136. char *Nam; /* Pointer to symbol */
  137. long Val; /* Value */
  138. long Hunk; /* Hunk number (ORed with MEMF_CHIP or MEM_FAST
  139. if applicable SECTION
  140. ~(pointer to symbol) if XREF
  141. Pointer to macro text if MACRO */
  142. int Defn; /* Line number where defined */
  143. int Flags; /* Flags bits: 0 - XREF
  144. 1 - XDEF
  145. 2 - SET
  146. 3 - MACRO (symbol is preceded by blank)
  147. 4 - SECTION (name preceded by 2 blanks
  148. and 4-digit hex sequence number)
  149. 5 - register name (EQUR)
  150. 6 - register list (REG)
  151. 7 - PUBLIC (XREF or XDEF will be set)
  152. 8 - An EQU that doesn't yet know whether
  153. it is an XREF, an XDEF, or just a
  154. plain forward reference */
  155. struct Ref *Ref1; /* Pointer to first reference entry */
  156. };
  157. GLOBAL struct SymTab *SymStart; /* The symbol table starts here. */
  158. GLOBAL struct SymTab *SymLim; /* The symbol table ends here. */
  159. GLOBAL struct SymTab *SymCurr; /* Start of current chunk of data */
  160. GLOBAL struct SymTab *Sym; /* ReadSymTab sets this up. */
  161. GLOBAL struct SymTab *Sect; /* Current section's entry */
  162. GLOBAL struct SymTab *SymChunk; /* Current symbol chunk for NextSym */
  163. GLOBAL struct SymTab *SymChLim; /* End of *SymChunk chunk */
  164. GLOBAL struct SymTab **Hash; /* Pointer to hash table */
  165. GLOBAL struct SymTab **SymSort; /* Symbol sort area */
  166. GLOBAL int *HashCount; /* Hashing summary table */
  167. struct NameChunk { /* Chunk of labels or macro text */
  168. struct NameChunk *Link; /* Link to the next chunk */
  169. char *Data[CHUNKSIZE-sizeof(struct NameChunk *)]; /* Data area */
  170. };
  171. GLOBAL struct NameChunk *NameStart; /* Start of first name chunk */
  172. GLOBAL char *NameLim; /* Next available name entry */
  173. GLOBAL struct NameChunk *NameCurr; /* Start of current name chunk */
  174. struct Ref { /* Reference entry */
  175. struct Ref *NextRef; /* Pointer to next reference entry */
  176. int RefNum[MAXREF]; /* Reference line numbers */
  177. };
  178. GLOBAL struct Ref *RefLim; /* Next available reference entry */
  179. struct RelTab { /* Relocation table entry */
  180. struct RelTab *Link; /* Link to the next entry */
  181. long Offset; /* Offset to relocatable value */
  182. long Hunk; /* Hunk type to relocate relative to */
  183. int Size; /* Size of relocatable value */
  184. int IsPC;
  185. /* added by Kevin Kofler in v.2.71.F3l: */
  186. long Target; /* Reloc target. -1 if stored at Offset. */
  187. int Negative; /* Reloc is negative. */
  188. };
  189. GLOBAL struct RelTab *RelStart; /* Relocation data starts here */
  190. GLOBAL struct RelTab *RelLim; /* Relocation data ends here */
  191. GLOBAL struct RelTab *RelCurr; /* Start of current chunk of data */
  192. GLOBAL struct RelTab *RelLast; /* Last relocation entry added */
  193. struct TermStack { /* Parser's term stack */
  194. long value; /* Value */
  195. long hunk; /* Hunk number */
  196. int oploc; /* Location in source statement */
  197. int defline; /* Line number where defined */
  198. int isaddrdiff; /* term is an address difference
  199. added by Kevin Kofler in v.2.71.F3l */
  200. };
  201. GLOBAL struct TermStack *Term; /* Term stack pointer */
  202. struct OpStack { /* Parser's operator stack */
  203. char chr; /* Operator character */
  204. int prec; /* Precedence */
  205. };
  206. GLOBAL struct OpStack *Ops; /* Operator stack pointer */
  207. GLOBAL char OpPrec[256]; /* Operator precedence look-up table */
  208. GLOBAL int InFNum; /* Current input nesting level */
  209. struct InFCtl {
  210. long Pos; /* Current position in input */
  211. char *UPtr; /* Current position in user macro or 0 */
  212. char *NPtr; /* File name stack pointer */
  213. int Line; /* Current line number in this file */
  214. int NArg; /* Number of macro arguments or -1 */
  215. int MCnt; /* Macro expansion number (for \@) */
  216. };
  217. GLOBAL struct InFCtl *InF; /* Macro/include file stack pointer */
  218. GLOBAL struct InFCtl *LowInF; /* "Low-water mark" for InF */
  219. GLOBAL char *Heap2; /* Secondary heap */
  220. GLOBAL char *NextFNS; /* Next input file path/name */
  221. GLOBAL char *High2; /* Secondary high-water mark */
  222. GLOBAL char *Low2; /* Low limit from top of heap */
  223. GLOBAL int OuterMac; /* Level number of outermost macro */
  224. GLOBAL int MacCount; /* Number of macros expanded */
  225. GLOBAL int SkipNest; /* Skipped IF/ENDC nesting count */
  226. GLOBAL char MacSize[2]; /* Macro call size ("B", "W", or "L") */
  227. struct OpConfig { /* Operand configuration */
  228. long Value; /* Value */
  229. long Hunk; /* Hunk number */
  230. int Defn; /* Line number where defined */
  231. int Mode; /* Addressing mode */
  232. int Loc; /* Location of operand on Line */
  233. int Rn; /* Register number */
  234. int Xn; /* Index register number */
  235. int Xsize; /* Size of index */
  236. int X; /* Is index Data or Address reg? */
  237. int Single; /* The operand is a single term. */
  238. /* added by Kevin Kofler in v.2.71.F3o: */
  239. int PCConv; /* Adjustment for PC-relative operand */
  240. /* added by Kevin Kofler in v.2.71.F3t: */
  241. int Unopt; /* Unoptimizable operand (hardcoded size) */
  242. };
  243. GLOBAL struct OpConfig Src, Dest; /* Source and destination operands */
  244. GLOBAL int Size; /* Size for OpCode */
  245. GLOBAL int InstSize; /* Size of instruction, including operands */
  246. GLOBAL int AdrModeA; /* Addressing modes for this instruction */
  247. GLOBAL int AdrModeB; /* ditto */
  248. GLOBAL int Op; /* Raw bit pattern for OpCode */
  249. GLOBAL struct FwdBr { /* Forward branch optimization candidates */
  250. long Loc; /* Location of Bcc instruction */
  251. struct SymTab *FwdSym; /* Pointer to target label entry */
  252. int Line; /* Line number (copied to FwdTable if OK) */
  253. } FwdBranch[64];
  254. GLOBAL struct FwdBr *FwdLim1; /* Logical end of FwdBranch */
  255. GLOBAL struct SymTab *FwdBranchFix[2048]; /* Symbol table entries to fix */
  256. /* This was: GLOBAL struct SymTab *FwdBranchFix[128];
  257. However, that won't work if one puts lots of labels at the same place.
  258. This change allows to assemble PedroM correctly.
  259. -- Kevin Kofler, v.2.71.F3k-pre1 */
  260. GLOBAL struct SymTab **FwdFixLimit; /* Logical end of fixup table */
  261. struct FwdTable {
  262. struct FwdTable *Link;
  263. int FwdLine[(FWDSIZE-sizeof(struct FwdTable *)) / sizeof (int)];
  264. };
  265. GLOBAL struct FwdTable *FwdStart; /* Start of first chunk */
  266. GLOBAL int *FwdLim2; /* Next available entry */
  267. GLOBAL struct FwdTable *FwdCurr; /* Start of current chunk */
  268. GLOBAL int *FwdPtr; /* Current position in pass 2 */
  269. GLOBAL int ErrorCount;
  270. /* Error message tables */
  271. GLOBAL int ErrLim, ErrCode[ERRMAX], ErrPos[ERRMAX];
  272. GLOBAL int isError; /* bugfix by Kevin Kofler for the TIGCC team in v.2.71.F3a */
  273. GLOBAL int noExplicitSize; /* bugfix by Kevin Kofler for the TIGCC team in v.2.71.F3b */
  274. struct AddrDiff {
  275. struct AddrDiff *Link;
  276. long paddr, phunk, naddr, nhunk;
  277. };
  278. GLOBAL struct AddrDiff * AddrDiffs; /* added by Kevin Kofler in v.2.71.F3l */