ass00.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /*
  2. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. * See the copyright notice in the ACK home directory, in the file "Copyright".
  4. */
  5. #include <stdio.h>
  6. #include <em_spec.h>
  7. #include <as_spec.h>
  8. #include <em_flag.h>
  9. #include <arch.h>
  10. #include <local.h>
  11. #define RCS_ASS "$Id$"
  12. /*
  13. * compile time options
  14. */
  15. #define DUMP 1 /* dump between passes */
  16. /* #define TIMING 1 /* some timing measurements */
  17. #define JOHAN 1 /* dump the loaded instructions */
  18. #define MEMUSE 1 /* print memory usage statistics */
  19. #ifndef DUMP
  20. #define dump(x) /* nothing */
  21. #endif
  22. #ifndef TIMING
  23. #define timing() /* nothing */
  24. #endif
  25. #ifndef MEMUSE
  26. #define memuse() /* nothing */
  27. #endif
  28. /* Used to clear the upper byte(s) of characters.
  29. Not nessecary if your C-compiler does not sign-extend char's
  30. */
  31. #ifdef CPM
  32. # define LC(ch) ( ((ch)<'A' | (ch)>'Z' ) ? (ch) : ((ch)-('A'-'a')))
  33. #else
  34. # define LC(ch) (ch)
  35. #endif
  36. #define ctrunc(val) ( (val)&0377 )
  37. #define odd(n) ((n)&1) /* Boolean odd function */
  38. #define lnp_cast (line_t *)
  39. #define gbp_cast (glob_t *)
  40. #define lbp_cast (locl_t *)
  41. #define prp_cast (proc_t *)
  42. #define ptp_cast (ptab_t *)
  43. #define rlp_cast (relc_t *)
  44. #define pst_cast (stat_t *)
  45. #define chp_cast (char *)
  46. #define ipp_cast (int **)
  47. #define iip_cast (int *)
  48. #define int_cast (int )
  49. typedef struct lines line_t;
  50. typedef struct loc_label locl_t;
  51. typedef struct glob_label glob_t;
  52. typedef struct rel relc_t;
  53. typedef struct procstat stat_t;
  54. typedef struct sizes siz_t;
  55. typedef struct ar_hdr arch_t;
  56. typedef struct procs proc_t;
  57. typedef struct proctab ptab_t;
  58. typedef char * area_t;
  59. typedef long cons_t;
  60. typedef union {
  61. cons_t ad_i;
  62. locl_t *ad_lp;
  63. glob_t *ad_gp;
  64. proc_t *ad_pp;
  65. struct sad_ln {
  66. short ln_extra;
  67. short ln_first;
  68. } ad_ln ;
  69. struct sad_df {
  70. cons_t df_i;
  71. glob_t *df_gp;
  72. } ad_df;
  73. } addr_u;
  74. typedef union {
  75. cons_t rel_i;
  76. locl_t *rel_lp;
  77. glob_t *rel_gp;
  78. } rel_u;
  79. #define FOFFSET long /* offset into file */
  80. /*
  81. * Global variables and definitions for EM1-assembler/loader
  82. */
  83. #define DEFINING 0 /* parameters for glolookup */
  84. #define OCCURRING 1
  85. #define INTERNING 2
  86. #define EXTERNING 3
  87. #define SEARCHING 4
  88. #define ENTERING 5
  89. #define PRO_OCC 0 /* parameters for prolookup */
  90. #define PRO_DEF 1
  91. #define PRO_INT 2
  92. #define PRO_EXT 3
  93. #define TRUE 1
  94. #define FALSE 0
  95. #define MAXBYTE 255
  96. #define MAXSTRING 200 /* Maximum string length accepted */
  97. #define LOCLABSIZE 128 /* size of local label hash table */
  98. /* may not be smaller */
  99. #define ABSSIZE 8
  100. struct lines {
  101. char instr_num; /* index into mnemon[] */
  102. char type1; /* see below */
  103. line_t *l_next; /* next in chain */
  104. char *opoff; /* pointer into opchoice[] */
  105. addr_u ad; /* depending on type, various pointers */
  106. };
  107. /* contents of type1 */
  108. #define MISSING 0 /* no operand */
  109. #define CONST 1 /* ad contains operand */
  110. #define PROCNAME 2 /* ad contains struct procs pointer */
  111. #define GLOSYM 3 /* ad contains pointer into mproc[] */
  112. #define LOCSYM 4 /* ad contains pointer into locs[] */
  113. #define GLOOFF 5 /* ad contains CONST and GLOSYM in ad_df */
  114. #define LINES 6 /* Line number setting, only param of pseudo*/
  115. #define VALLOW 7 /* value's between LOW and HIGH are x-MID */
  116. #define VALMID 50
  117. #define VALHIGH 127 /* to avoid sign extension problems */
  118. #define VAL1(x) ((x)-VALMID)
  119. /* Used to indicate a invalid contents of opoff */
  120. #define NO_OFF ((char *)-1)
  121. struct loc_label {
  122. locl_t *l_chain; /* The next label with same low order bits */
  123. char l_hinum; /* high bits of number of label */
  124. char l_defined; /* see below */
  125. int l_min,l_max; /* boundaries of value */
  126. };
  127. /* The structure containing procedure pertinent data */
  128. /* Used for environment stacking for nested PRO's */
  129. struct procstat {
  130. line_t *s_fline; /* points to first line of procedure */
  131. locl_t (*s_locl)[1]; /* pointer to local labels */
  132. proc_t *s_curpro; /* identifies current procedure */
  133. relc_t *s_fdata; /* last datareloc before procedure */
  134. stat_t *s_prevstat; /* backward chain of nested procedures */
  135. } ;
  136. /* contents of l_defined */
  137. #define EMPTY 0 /* Empty slot */
  138. #define NO 1 /* not defined yet */
  139. #define YES 2 /* defined */
  140. #define SEEN 3 /* intermediate state */
  141. #define NOTPRESENT 4 /* Undefined and error message given */
  142. struct glob_label {
  143. char *g_name;
  144. char g_status; /* see below */
  145. union {
  146. cons_t g_addr; /* value if status&DEF */
  147. struct glob_label *g_gp; /* ref. to xglobs */
  148. } g_val ;
  149. };
  150. #define glostring(gl) ((gl)->g_name)
  151. /* contents of g_status */
  152. #define DEF 01 /* defined */
  153. #define OCC 02 /* used */
  154. #define EXT 04 /* external */
  155. struct rel { /* for relocation tables */
  156. relc_t *r_next; /* chain */
  157. FOFFSET r_off; /* offset in text/data of word to relocate */
  158. rel_u r_val; /* constant or pointer to global symbol */
  159. int r_typ; /* different use in text or data */
  160. };
  161. /*
  162. * When used with textrelocation r_typ contains the flag bits as defined
  163. * in ip_spec.h together with the RELMNS bit if r_val contains an integer
  164. */
  165. #define RELMNS 020000 /* indicates integer i.s.o. glob */
  166. /* Contents of r_typ when used with data relocation */
  167. #define RELNULL 0
  168. #define RELGLO 1
  169. #define RELHEAD 2
  170. #define RELLOC 3
  171. #define RELADR 4
  172. /* modes of data output */
  173. #define DATA_NUL 0
  174. #define DATA_REP 1
  175. #define DATA_CONST 2
  176. #define DATA_BSS 3
  177. #define DATA_DPTR 4
  178. #define DATA_IPTR 5
  179. #define DATA_ICON 6
  180. #define DATA_UCON 7
  181. #define DATA_FCON 8
  182. #define DATA_BYTES 9
  183. /* name of procedure to be called first */
  184. #define MAIN "_m_a_i_n"
  185. /* headers of datablocks written */
  186. #define HEADREP 0
  187. #define HEADBSS 1
  188. #define HEADBYTE 2
  189. #define HEADCONST 3
  190. #define HEADDPTR 4
  191. #define HEADIPTR 5
  192. #define HEADICON 6
  193. #define HEADUCON 7
  194. #define HEADFCON 8
  195. #define NDEFAULT 4 /* number of different sizes available */
  196. struct sizes {
  197. int n_mlab; /* # of global labels per module */
  198. int n_glab; /* # of extern global labels */
  199. int n_mproc; /* # of local procs per module */
  200. int n_xproc; /* # of external procs */
  201. int n_proc; /* total # of procedures */
  202. };
  203. struct procs { /* format of mprocs[] and xprocs[] */
  204. char *p_name;
  205. char p_status; /* same bits as g_status except REL */
  206. int p_num; /* unique procedure descriptor */
  207. };
  208. struct proctab {
  209. cons_t pr_off; /* distance from pb */
  210. cons_t pr_loc; /* number of bytes locals */
  211. };