comm0.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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. _include <unistd.h>
  69. #else
  70. #include <stdlib.h>
  71. #include <stdio.h>
  72. #include <string.h>
  73. #include <stdarg.h>
  74. #include <errno.h>
  75. #include <ctype.h>
  76. #include <signal.h>
  77. #include <unistd.h>
  78. #endif
  79. #ifdef ASLD
  80. #include "arch.h"
  81. #endif
  82. #include "missing_proto.h"
  83. #include "object.h"
  84. #include "out.h"
  85. #if DEBUG == 0
  86. #define assert(ex) /* nothing */
  87. #endif
  88. #if DEBUG == 1
  89. #define assert(ex) {if (!(ex)) assert1();}
  90. #endif
  91. #if DEBUG == 2
  92. #define assert(ex) {if (!(ex)) assert2(__FILE__, __LINE__);}
  93. #endif
  94. #define CTRL(x) ((x) & 037)
  95. #define lowb(z) ((int)(z) & 0xFF)
  96. #define loww(z) ((int)(z) & 0xFFFF)
  97. #define fitb(x) ((((x) + 0x80) & ~((int)0xFF)) == 0)
  98. #define fitw(x) ((((x) + 0x8000L) & ~0xFFFFL) == 0)
  99. #define fit(x) if (!(x)) nofit()
  100. #define PASS_1 0
  101. #define PASS_2 1
  102. #define PASS_3 2
  103. #ifdef THREE_PASS
  104. #define PASS_SYMB (pass != PASS_1)
  105. #define PASS_RELO (pass != PASS_1)
  106. #else
  107. #define PASS_SYMB 1
  108. #define PASS_RELO 1
  109. #endif /* THREE_PASS */
  110. #ifdef ASLD
  111. #define RELOMOVE(a,b) /* empty */
  112. #else
  113. #define RELOMOVE(a,b) {a = b; b = 0;}
  114. #endif
  115. /* symbol table management */
  116. #define H_SIZE 307 /* hash size, must be od */
  117. #define H_KEY (0*H_SIZE) /* key symbol headers */
  118. #define H_LOCAL (1*H_SIZE) /* module symbol headers */
  119. #ifdef ASLD
  120. #define H_GLOBAL (2*H_SIZE) /* external symbol headers */
  121. #define H_TOTAL (3*H_SIZE)
  122. #else
  123. #define H_TOTAL (2*H_SIZE)
  124. #endif
  125. /* numeric label table management */
  126. #define FB_SIZE 10
  127. #define FB_HEAD (0*FB_SIZE)
  128. #define FB_TAIL (1*FB_SIZE)
  129. #define FB_BACK (2*FB_SIZE)
  130. #define FB_FORW (3*FB_SIZE)
  131. /* miscellaneous */
  132. #define KEYDEFINE 0
  133. #define KEYSECT 12
  134. #define DOTGAIN DOTSCT->s_gain
  135. /* ========== type declarations ========== */
  136. struct expr_t {
  137. short typ;
  138. valu_t val;
  139. };
  140. typedef struct expr_t expr_t;
  141. struct item_t {
  142. struct item_t *
  143. i_next; /* linked lists with same hash value */
  144. short i_type;
  145. /*
  146. * the i_type field is used for two different purposes:
  147. * - the token type for keywords, returned by yylex()
  148. * - the symbol type for IDENT and FBSYM tokens
  149. */
  150. valu_t i_valu; /* symbol value */
  151. char *i_name; /* symbol name */
  152. };
  153. struct common_t {
  154. struct common_t *
  155. c_next;
  156. struct item_t *c_it;
  157. #ifndef ASLD
  158. valu_t c_size;
  159. #endif
  160. };
  161. typedef struct common_t common_t;
  162. typedef struct item_t item_t;
  163. struct sect_t {
  164. short s_flag; /* some flag bits */
  165. ADDR_T s_base; /* section base */
  166. ADDR_T s_size; /* section size */
  167. ADDR_T s_comm; /* length of commons */
  168. ADDR_T s_zero; /* delayed emit1(0) */
  169. ADDR_T s_lign; /* section alignment */
  170. long s_foff; /* section file offset */
  171. item_t *s_item; /* points to section name */
  172. #ifdef THREE_PASS
  173. ADDR_T s_gain; /* gain in PASS_2 */
  174. #endif
  175. };
  176. typedef struct sect_t sect_t;
  177. /* ========== flag field bits ========== */
  178. /* s_flag bits: */
  179. #define BASED 1 /* at fixed position */
  180. /* sflag bits: */
  181. #define SYM_EXT 001 /* external symbols */
  182. #define SYM_LOC 002 /* local symbols */
  183. #define SYM_LAB 004 /* local, compiler-generated labels */
  184. #define SYM_SMB 010 /* .symb symbols */
  185. #define SYM_LIN 020 /* .line and .file */
  186. #define SYM_SCT 040 /* section names */
  187. #define SYM_DEF 073 /* default value */
  188. /*
  189. * extra type bits out of S_ETC, internal use only
  190. * S_VAR:
  191. * - type not known at end of PASS_1 (S_VAR|S_UND)
  192. * - value not known at end of PASS_2 (S_VAR|S_ABS)
  193. * S_DOT:
  194. * - dot expression
  195. */
  196. #define S_VAR 0x0200
  197. #define S_DOT 0x0400
  198. /* should be tested by preprocessor
  199. * due to error in preprocessor it cannot
  200. * test performed at compiletime by a switch now
  201. * #if (S_ETC|S_COM|S_VAR|S_DOT) != S_ETC
  202. * incorrect type bits
  203. * #endif
  204. */
  205. /* parts of the a.out file */
  206. #define PARTEMIT 0
  207. #define PARTRELO 1
  208. #define PARTNAME 2
  209. #define PARTCHAR 3
  210. #define PARTS 4
  211. #ifdef BYTES_REVERSED
  212. #ifdef WORDS_REVERSED
  213. #define MACHREL_BWR (RELBR|RELWR)
  214. #else
  215. #define MACHREL_BWR (RELBR)
  216. #endif
  217. #else
  218. #ifdef WORDS_REVERSED
  219. #define MACHREL_BWR (RELWR)
  220. #else
  221. #define MACHREL_BWR (0)
  222. #endif
  223. #endif