comm0.h 5.8 KB

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