comm0.h 6.0 KB

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