comm0.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /* $Id$ */
  2. /*
  3. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  4. * See the copyright notice in the ACK home directory, in the file "Copyright".
  5. */
  6. /* @(#)comm0.h 1.8 */
  7. /*
  8. * All preprocessor based options/constants/functions
  9. */
  10. /* ========== ON/OFF options (use #define in mach0.c) ========== */
  11. /*
  12. * The following options are available, to be set/removed in "mach0.c":
  13. * THREE_PASS: three passes needed for branch optimization
  14. * BYTES_REVERSED: lowest target address for word high-order byte
  15. * WORDS_REVERSED: lowest target address for long high-order byte
  16. * LISTING: include listing facilities
  17. * RELOCATION: relocatable code generated
  18. * DEBUG: for debugging purposes only
  19. * TMPDIR: directory for temporary files
  20. * ASLD: combined assembler/linker
  21. */
  22. /* ========== constants (use #undef, #define in mach0.c) ========== */
  23. /* table sizes */
  24. #define STRINGMAX 200 /* <= 256 */
  25. #define SECTMAX 64
  26. #define NAMEMAX 80
  27. #define MEMINCR 2048
  28. /* Some character constants for parsing */
  29. #define ASC_LPAR '['
  30. #define ASC_RPAR ']'
  31. #define ASC_SQUO '\''
  32. #define ASC_DQUO '"'
  33. #define ASC_COMM '!'
  34. #define ISALPHA(c) (isalpha(c) || (c) == '_' || (c) == '.')
  35. #define ISALNUM(c) (isalnum(c) || (c) == '_')
  36. #define GENLAB "I" /* compiler generated labels */
  37. #define valu_t short /* type of expression values */
  38. #define ADDR_T unsigned short /* type of dot */
  39. #define word_t short /* type of keyword value */
  40. /*
  41. * NOTE: word_t is introduced to reduce the tokenfile size for machines
  42. * with large expressions but smaller opcodes (68000)
  43. */
  44. #define ALIGNWORD 1
  45. #define ALIGNSECT 1
  46. #define machstart(x) /* nothing */
  47. #define machfinish(x) /* nothing */
  48. #define SETBASE(sp) ((long)(sp)->s_base)
  49. #define VALWIDTH 4
  50. /* ========== Machine dependent option/constant settings ========== */
  51. #include "mach0.c"
  52. /* ========== default option setting ========== */
  53. #ifndef ASLD
  54. #ifndef RELOCATION
  55. separate linker only possible if relocation info produced
  56. #endif /* RELOCATION */
  57. #endif /* ASLD */
  58. #ifndef DEBUG
  59. #define DEBUG 1
  60. #endif
  61. /* ========== Machine independent type declarations ========== */
  62. #ifdef _include
  63. _include <stdlib.h>
  64. _include <stdio.h>
  65. _include <string.h>
  66. _include <ctype.h>
  67. _include <signal.h>
  68. #else
  69. #include <stdlib.h>
  70. #include <stdio.h>
  71. #include <string.h>
  72. #include <ctype.h>
  73. #include <signal.h>
  74. #endif
  75. #ifdef ASLD
  76. #include "arch.h"
  77. #endif
  78. #include "out.h"
  79. #if DEBUG == 0
  80. #define assert(ex) /* nothing */
  81. #endif
  82. #if DEBUG == 1
  83. #define assert(ex) {if (!(ex)) assert1();}
  84. #endif
  85. #if DEBUG == 2
  86. #define assert(ex) {if (!(ex)) assert2(__FILE__, __LINE__);}
  87. #endif
  88. #define CTRL(x) ((x) & 037)
  89. #define lowb(z) ((int)(z) & 0xFF)
  90. #define loww(z) ((int)(z) & 0xFFFF)
  91. #define fitb(x) ((((x) + 0x80) & ~((int)0xFF)) == 0)
  92. #define fitw(x) ((((x) + 0x8000L) & ~0xFFFFL) == 0)
  93. #define fit(x) if (!(x)) nofit()
  94. #define PASS_1 0
  95. #define PASS_2 1
  96. #define PASS_3 2
  97. #ifdef THREE_PASS
  98. #define PASS_SYMB (pass != PASS_1)
  99. #define PASS_RELO (pass != PASS_1)
  100. #else
  101. #define PASS_SYMB 1
  102. #define PASS_RELO 1
  103. #endif /* THREE_PASS */
  104. #ifdef ASLD
  105. #define RELOMOVE(a,b) /* empty */
  106. #else
  107. #define RELOMOVE(a,b) {a = b; b = 0;}
  108. #endif
  109. /* symbol table management */
  110. #define H_SIZE 307 /* hash size, must be od */
  111. #define H_KEY (0*H_SIZE) /* key symbol headers */
  112. #define H_LOCAL (1*H_SIZE) /* module symbol headers */
  113. #ifdef ASLD
  114. #define H_GLOBAL (2*H_SIZE) /* external symbol headers */
  115. #define H_TOTAL (3*H_SIZE)
  116. #else
  117. #define H_TOTAL (2*H_SIZE)
  118. #endif
  119. /* numeric label table management */
  120. #define FB_SIZE 10
  121. #define FB_HEAD (0*FB_SIZE)
  122. #define FB_TAIL (1*FB_SIZE)
  123. #define FB_BACK (2*FB_SIZE)
  124. #define FB_FORW (3*FB_SIZE)
  125. /* miscellaneous */
  126. #define KEYDEFINE 0
  127. #define KEYSECT 12
  128. #define DOTGAIN DOTSCT->s_gain
  129. /* ========== type declarations ========== */
  130. struct expr_t {
  131. short typ;
  132. valu_t val;
  133. };
  134. typedef struct expr_t expr_t;
  135. struct item_t {
  136. struct item_t *
  137. i_next; /* linked lists with same hash value */
  138. short i_type;
  139. /*
  140. * the i_type field is used for two different purposes:
  141. * - the token type for keywords, returned by yylex()
  142. * - the symbol type for IDENT and FBSYM tokens
  143. */
  144. valu_t i_valu; /* symbol value */
  145. char *i_name; /* symbol name */
  146. };
  147. struct common_t {
  148. struct common_t *
  149. c_next;
  150. struct item_t *c_it;
  151. #ifndef ASLD
  152. valu_t c_size;
  153. #endif
  154. };
  155. typedef struct common_t common_t;
  156. typedef struct item_t item_t;
  157. struct sect_t {
  158. short s_flag; /* some flag bits */
  159. ADDR_T s_base; /* section base */
  160. ADDR_T s_size; /* section size */
  161. ADDR_T s_comm; /* length of commons */
  162. ADDR_T s_zero; /* delayed emit1(0) */
  163. ADDR_T s_lign; /* section alignment */
  164. long s_foff; /* section file offset */
  165. item_t *s_item; /* points to section name */
  166. #ifdef THREE_PASS
  167. ADDR_T s_gain; /* gain in PASS_2 */
  168. #endif
  169. };
  170. typedef struct sect_t sect_t;
  171. /* ========== flag field bits ========== */
  172. /* s_flag bits: */
  173. #define BASED 1 /* at fixed position */
  174. /* sflag bits: */
  175. #define SYM_EXT 001 /* external symbols */
  176. #define SYM_LOC 002 /* local symbols */
  177. #define SYM_LAB 004 /* local, compiler-generated labels */
  178. #define SYM_SMB 010 /* .symb symbols */
  179. #define SYM_LIN 020 /* .line and .file */
  180. #define SYM_SCT 040 /* section names */
  181. #define SYM_DEF 073 /* default value */
  182. /*
  183. * extra type bits out of S_ETC, internal use only
  184. * S_VAR:
  185. * - type not known at end of PASS_1 (S_VAR|S_UND)
  186. * - value not known at end of PASS_2 (S_VAR|S_ABS)
  187. * S_DOT:
  188. * - dot expression
  189. */
  190. #define S_VAR 0x0200
  191. #define S_DOT 0x0400
  192. /* should be tested by preprocessor
  193. * due to error in preprocessor it cannot
  194. * test performed at compiletime by a switch now
  195. * #if (S_ETC|S_COM|S_VAR|S_DOT) != S_ETC
  196. * incorrect type bits
  197. * #endif
  198. */
  199. /* parts of the a.out file */
  200. #define PARTEMIT 0
  201. #define PARTRELO 1
  202. #define PARTNAME 2
  203. #define PARTCHAR 3
  204. #define PARTS 4
  205. #ifdef BYTES_REVERSED
  206. #ifdef WORDS_REVERSED
  207. #define MACHREL_BWR (RELBR|RELWR)
  208. #else
  209. #define MACHREL_BWR (RELBR)
  210. #endif
  211. #else
  212. #ifdef WORDS_REVERSED
  213. #define MACHREL_BWR (RELWR)
  214. #else
  215. #define MACHREL_BWR (0)
  216. #endif
  217. #endif
  218. extern FILE *fopen(); /* some systems don't have this in stdio.h */