Significant progress to getting pl1$pl1 to compile something, implemented many necess...
[multics_sim.git] / definition_dcls.h
1 #ifndef _DEFINITION_DCLS_H
2 #define _DEFINITION_DCLS_H
3
4 #include <stdint.h>
5
6 // see pl1/definition_dcls.incl.pl1
7
8 /* everything for the definition section */
9
10 // declare (
11 enum {
12   // CLASS_TEXT init (0), /* text section definition */
13   CLASS_TEXT = 0,
14   // CLASS_LINKAGE init (1), /* linkage section definition */
15   CLASS_LINKAGE = 1,
16   // CLASS_SYMBOL init (2), /* symbol section definition */
17   CLASS_SYMBOL = 2,
18   // CLASS_SEGNAME init (3), /* segment name definition */
19   CLASS_SEGNAME = 3,
20   // CLASS_STATIC init (4), /* static section definition */
21   CLASS_STATIC = 4,
22   // CLASS_SYSTEM init (5), /* valid only in self links, not def class */
23   CLASS_SYSTEM = 5,
24   // CLASS_HEAP init (6) /* valid only in self links, not def class */
25   CLASS_HEAP = 6
26 // ) fixed bin (3) unsigned internal static options (constant);
27 };
28
29 // declare CLASS_NAMES (0:6) character (12) internal static options (constant)
30 // init ("text", "linkage", "symbol", "segname", "static", "system", "heap");
31 extern char *class_names[7];
32
33 // declare SYMBOLIC_SECTION_NAMES (0:6) character (8)
34 // init ("*text", "*link", "*symbol", *, "*static", "*system", "*heap") internal static
35 // options (constant);
36 extern char *symbolic_section_names[7];
37
38 // declare 1 definition_flags unaligned based,
39 //   2 new bit (1), /* should be "1"b */
40 //   2 ignore bit (1), /* cannot snap link to this */
41 //   2 entry bit (1), /* can tra here */
42 //   2 retain bit (1), /* binder respects this */
43 //   2 argcount bit (1), /* OBSOLETE */
44 //   2 descriptors bit (1), /* OBSOLETE */
45 //   2 indirect bit (1), /* target is a pointer to actual target */
46 //   2 unused bit (8); /* Must be zero */
47
48 /* Header of the definition section */
49
50 // declare def_header_ptr pointer;
51 // declare 1 definition_header aligned based (def_header_ptr),
52 struct definition_header {
53   // 2 def_list_relp fixed bin (18) unsigned unaligned,
54   // /* first definition, reloc def18 */
55   // 2 msf_map_relp fixed bin (18) unsigned unaligned,
56   // /* msf_map if any, or 0 if none. reloc def18 unless none */
57   uint64_t msf_map_relp : 18;
58   uint64_t def_list_relp : 18;
59   uint64_t dummy0 : 28;
60
61   // 2 hash_table_relp fixed bin (18) unsigned unaligned,
62   // /* def hash table, if any, or 0 if none. reloc def18 unless none */
63   // 2 flags unaligned like definition_flags;
64   // /* both new and ignore must be "1"b here */
65   uint64_t dummy1 : 3;
66   uint64_t flags_unused : 8;
67   uint64_t flags_indirect : 1;
68   uint64_t flags_descriptors : 1;
69   uint64_t flags_argcount : 1;
70   uint64_t flags_retain : 1;
71   uint64_t flags_entry : 1;
72   uint64_t flags_ignore : 1;
73   uint64_t flags_new : 1;
74   uint64_t hash_table_relp : 18;
75   uint64_t dummy2 : 28;
76 };
77
78 /* A non class=3 definition. See segname_definition below for class=3 */
79
80 // declare def_ptr pointer;
81 // declare 1 definition aligned based (def_ptr),
82 struct definition {
83   // 2 forward_relp unal fixed bin (18) unsigned,
84   // /* offset of next def */
85   // 2 backward_relp unal fixed bin (18) unsigned,
86   // /* offset of previous def */
87   uint64_t backward_relp : 18;
88   uint64_t forward_relp : 18;
89   uint64_t dummy0 : 28;
90
91   // 2 thing_relp unal fixed bin (18) unsigned,
92   // /* offset in section specified by class of thing this defines */
93   // 2 flags unaligned like definition_flags,
94   // 2 class unal fixed bin (3) unsigned,
95   // /* Type of definition */
96   uint64_t class : 3;
97   uint64_t flags_unused : 8;
98   uint64_t flags_indirect : 1;
99   uint64_t flags_descriptors : 1;
100   uint64_t flags_argcount : 1;
101   uint64_t flags_retain : 1;
102   uint64_t flags_entry : 1;
103   uint64_t flags_ignore : 1;
104   uint64_t flags_new : 1;
105   uint64_t thing_relp : 18;
106   uint64_t dummy1 : 28;
107
108   // 2 name_relp unal fixed bin (18) unsigned,
109   // /* offset of ACC for symbol */
110   // 2 segname_relp unal fixed bin (18) unsigned;
111   // /* offset of segname def to which this belongs */
112   uint64_t segname_relp : 18;
113   uint64_t name_relp : 18;
114   uint64_t dummy2 : 28;
115 };
116
117 /* Class=3, segname definition */
118
119 // declare segname_ptr pointer;
120 // declare 1 segname_definition aligned based (segname_ptr),
121 struct segname_definition {
122   // 2 forward_relp unal fixed bin (18) unsigned,
123   // /* offset of next def */
124   // 2 backward_relp unal fixed bin (18) unsigned,
125   // /* offset of previous def */
126   uint64_t backward_relp : 18;
127   uint64_t forward_relp : 18;
128   uint64_t dummy0 : 28;
129
130   // 2 next_segname_relp unal fixed bin (18) unsigned,
131   // /* offset of next segname def */
132   // 2 flags unaligned like definition_flags,
133   // 2 class unal fixed bin (3) unsigned,
134   // /* 3 for segname */
135   uint64_t class : 3;
136   uint64_t flags_unused : 8;
137   uint64_t flags_indirect : 1;
138   uint64_t flags_descriptors : 1;
139   uint64_t flags_argcount : 1;
140   uint64_t flags_retain : 1;
141   uint64_t flags_entry : 1;
142   uint64_t flags_ignore : 1;
143   uint64_t flags_new : 1;
144   uint64_t next_segname_relp : 18;
145   uint64_t dummy1 : 28;
146
147   // 2 name_relp unal fixed bin (18) unsigned,
148   // /* offset of ACC for symbol */
149   // 2 first_relp unal fixed bin (18) unsigned;
150   // /* see following : */
151   uint64_t first_relp : 18;
152   uint64_t name_relp : 18;
153   uint64_t dummy2 : 28;
154 };
155
156 /* Definition blocks are chained off of segname definitions.
157 segname_definition.first_relp is one of three things:
158 (1) the def section offset of the first ordinary (class^=3) definition
159 belonging to this segname block. In the case where there are more than
160 one segname's on a block, all their first_relp will point
161 to the same place.
162
163 (2) if there are no ordinary definitions associated with this segname,
164 then it is the def section offset of the next segname. 
165
166 (3) if there are no ordinary definitions in the block, and it
167 is the last block, then it points to a word containing 0.
168
169 Thus the end of a list of synonym segnames can be detected by forward_relp
170 pointing to a class=3 definition whose first_relp is not the same as
171 the current definitions first_relp.
172 */
173
174 /* All the definitions are linked through the forward and
175 backward thread variables. The end of the chain can is indicated
176 by forward pointing to a zero word. */
177
178 // declare exp_ptr pointer;
179 // declare 1 exp_word based (exp_ptr) aligned, /* expression word in link definition */
180 struct exp_word {
181   // 2 type_relp fixed bin (18) unsigned unal,
182   // /* pointer (rel to defs) of type pair structure */
183   // 2 expression fixed bin (17) unal; /* constant expression to be added in when snapping link */
184   int64_t expression : 18;
185   uint64_t type_relp : 18;
186   uint64_t dummy1 : 28;
187 };
188
189 // declare (
190 enum {
191   // LINK_SELF_BASE init (1), /* *section|0+expression,modifier */
192   // /* which section determined by segname_relp */
193   LINK_SELF_BASE = 1,
194   // LINK_OBSOLETE_2 init (2), /* not used */
195   LINK_OBSOLETE = 2,
196   // LINK_REFNAME_BASE init (3), /* refname|0+expression,modifier */
197   LINK_REFNAME_BASE = 3,
198   // LINK_REFNAME_OFFSETNAME init (4), /* refname|offsetname+expression,modifier */
199   LINK_REFNAME_OFFSETNAME = 4,
200   // LINK_SELF_OFFSETNAME init (5), /* *section|offsetname+expression,modifier */
201   LINK_SELF_OFFSETNAME = 5,
202   // LINK_CREATE_IF_NOT_FOUND init (6), /* OBSOLETE: like LINK_REFNAME_OFFSETNAME except that it will create instead of taking linkage_error */
203   LINK_CREATE_IF_NOT_FOUND = 6,
204   // SECTION_TEXT init (0), /* *text */
205   SECTION_TEXT = 0,
206   // SECTION_LINK init (1), /* *link */
207   SECTION_LINK = 1,
208   // SECTION_SYMBOL init (2), /* *symbol */
209   SECTION_SYMBOL = 2,
210   // SECTION_UNUSED init (3), /* reserved */
211   SECTION_UNUSED = 3,
212   // SECTION_STATIC init (4), /* *static */
213   SECTION_STATIC = 4,
214   // SECTION_SYSTEM init (5), /* *system */
215   SECTION_SYSTEM = 5,
216   // SECTION_HEAP init (6) /* *heap */
217   SECTION_HEAP = 6
218 // ) fixed bin (18) unsigned unaligned internal static options (constant);
219 };
220
221 /* use CLASS_NAMES for section names */
222
223 // declare LINK_TYPE_NAMES (1:6)
224 // init ("absolute in section", "unused", "absolute off of refname",
225 // "symbolic off of refname", "symbolic in section", "symbolic off of refname; create")
226 // character (32) varying internal static options (constant);
227 extern char *link_type_names[6];
228
229 // declare type_ptr pointer;
230 // declare 1 type_pair based (type_ptr) aligned,/* type pair in link definition */
231 struct type_pair {
232   // 2 type fixed bin (18) unsigned unal,
233   // /* see above */
234   // 2 trap_relp fixed bin (18) unsigned unal,
235   // /* pointer (rel to defs) to the trap word */
236   // /* unless LINK_SELF_OFFSETNAME off of *system or create link */
237   uint64_t trap_relp : 18;
238   uint64_t type : 18;
239   uint64_t dummy0 : 28;
240
241   // 2 segname_relp fixed bin (18) unsigned unal,
242   // /* pointer (rel to defs) to ACC reference name for segment referenced, 
243   // /*or section code for SELF links */
244   // 2 offsetname_relp fixed bin (18) unsigned unal;
245   // /* for OFFSETNAME links, ACC string of name of location. */
246   // /* for others, must be ZERO */
247   uint64_t offsetname_relp : 18;
248   uint64_t segname_relp : 18;
249   uint64_t dummy1 : 28;
250 };
251
252 /* Link Trap Pair */
253
254 // declare link_trap_ptr pointer;
255 // declare 1 link_trap_pair aligned based (link_trap_ptr),
256 struct link_trap_pair {
257   // 2 call_relp fixed bin (18) unsigned unaligned,
258   // /* LINK18, link to thing to call */
259   // 2 info_relp fixed bin (18) unsigned unaligned;
260   // /* LINK18, link to argument list */
261   uint64_t info_relp : 18;
262   uint64_t call_relp : 18;
263   uint64_t dummy0 : 28;
264 };
265
266 /* initialization info for *system or *heap link */
267
268 /* NOTE --------------------------------------------------
269 the following structures defining initialization information are also
270 defined in fortran_storage.incl.pl1 system_link_init_info.incl.pl1
271 and should be kept equivalent
272 -------------------------------------------------------
273 */
274
275 // declare (
276 enum {
277   // INIT_NO_INIT init (0),
278   INIT_NO_INIT = 0,
279   // INIT_COPY_INFO init (3),
280   INIT_COPY_INFO = 3,
281   // INIT_DEFINE_AREA init (4),
282   INIT_DEFINE_AREA = 4,
283   // INIT_LIST_TEMPLATE init (5),
284   INIT_LIST_TEMPLATE = 5,
285   // INIT_DEFERRED init (6)
286   INIT_DEFERRED = 6
287 // ) fixed bin internal static options (constant);
288 };
289
290 /* for type = 0 or 4 */
291
292 // declare link_init_ptr pointer;
293 // declare 1 link_init aligned based (link_init_ptr),
294 struct link_init {
295   // 2 n_words fixed bin (35), /* number to invent */
296   // 2 type fixed bin; /* see types above */
297   int64_t n_words : 36;
298   uint64_t dummy0 : 28;
299   uint64_t dummy1 : 18;
300   uint64_t type : 18;
301   uint64_t dummy2 : 28;
302 };
303
304 /* for type=3, there is data to copy */
305
306 // declare 1 link_init_copy_info aligned based (link_init_ptr),
307 struct link_init_copy_info {
308   // 2 header aligned like link_init,
309   int64_t header_n_words : 36;
310   uint64_t dummy0 : 28;
311   uint64_t dummy1 : 18;
312   uint64_t header_type : 18;
313   uint64_t dummy2 : 28;
314
315   // 2 initial_data (link_init_n_words refer (link_init_copy_info.header.n_words)) bit (36) aligned;
316   uint64_t initial_data[];
317 };
318
319 // declare link_init_n_words fixed bin;
320
321 /* for type = 5, there is a list template to copy */
322
323 /* A list template consists of a series of entries with the following
324 description, concatenated together. n_bits and datum are bit items,
325 to permit a wide range of inputs.
326
327 1. A 'repeat' of '0' signifies skipping of 'n_bits' bits.
328 2. A 'n_bits' of '0' signifies the last item of the list.
329
330 COMMON, VLA's, and LA's are presumed to start at the base pointer
331 of their particular storage section. */
332
333 // declare 1 list_template_entry aligned based,
334 struct list_template_entry {
335   // 2 n_bits fixed bin (35) aligned, /* size of datum */
336   // 2 mbz bit (3) unaligned, /* future expansion */
337   // 2 init_type fixed bin (3) unsigned unaligned, /* 0 normal init, 1 ptr init, 2 packed ptr init */
338   // 2 repeat fixed bin (30) unsigned unaligned,
339   // /* number of times to repeat datum */
340   // 2 datum bit (link_init_n_bits_in_datum refer (list_template_entry.n_bits));
341   int64_t n_bits : 36;
342   uint64_t dummy0 : 28;
343   uint64_t mbz : 3;
344   uint64_t init_type : 3;
345   uint64_t repeat0 : 24;
346   uint64_t repeat1 : 6;
347   uint64_t datum : 30;
348   uint64_t dummy1 : 28;
349 };
350
351 // declare 1 link_init_list_template
352 // aligned based (link_init_ptr),
353 struct link_init_list_template {
354   // 2 header aligned like link_init,
355   // 2 pad bit (18) unaligned,
356   int64_t header_n_words : 36;
357   uint64_t dummy0 : 28;
358   uint64_t header_pad_bit : 18;
359   uint64_t type : 18;
360   uint64_t header_dummy1 : 28;
361
362   // 2 n_words_in_list fixed bin (18) unsigned unaligned,
363   uint64_t dummy2 : 18;
364   uint64_t n_words_in_list : 18;
365   uint64_t dummy3 : 28;
366
367   // 2 template (link_init_n_words_in_list refer (link_init_list_template.n_words_in_list));
368   struct list_template_entry template[];
369 };
370
371 // declare link_init_n_words_in_list
372 // fixed bin;
373
374 /* the pointer_init_template represents the initialization information
375 for ITS and packed pointers. Both pointer types require the entire
376 72 bit structure.
377 */
378
379 // dcl 1 pointer_init_template based,
380 struct pointer_init {
381   // 2 ptr_type fixed bin (18) unsigned unaligned, /* 0 text section, 1 linkage section, 2 static section */
382   // 2 section_offset fixed bin (18) unsigned unaligned, /* offset to item in specified section */
383   uint64_t section_offset : 18;
384   uint64_t ptr_type : 18;
385   uint64_t dummy0 : 28;
386
387   // 2 word_offset fixed bin (18) unsigned unaligned, /* offset from section item to target in words */
388   // 2 mbz bit (12) unaligned,
389   // 2 bit_offset fixed bin (6) unsigned unaligned; /* offset from section item|word offset to target in bits */
390   uint64_t bit_offset : 6;
391   uint64_t mbz : 12;
392   uint64_t word_offset : 18;
393   uint64_t dummy1 : 28;
394 };
395
396 // declare link_init_n_bits_in_datum
397 // fixed bin (35);
398
399 /* for type = 6, the init_info resides in another MSF component */
400 /* target_relp is a linkage section offset to a partial link to */
401 /* the base of the linkage section of the component containing */
402 /* the actual init_info. link_relp is the offset of the actual */
403 /* link within that linkage section. */
404
405 // declare 1 link_init_deferred aligned based (link_init_ptr),
406 struct link_init_deferred_aligned {
407   // 2 header aligned like link_init,
408   // 2 target_relp fixed bin (18) unsigned unaligned,
409   int64_t n_words : 36;
410   uint64_t dummy0 : 28;
411   uint64_t target_relp : 18;
412   uint64_t type : 18;
413   uint64_t dummy1 : 28;
414
415   // 2 link_relp fixed bin (18) unsigned unaligned;
416   uint64_t dummy2 : 18;
417   uint64_t link_relp : 18;
418   uint64_t dummy3 : 28;
419 };
420
421 /* Definition section hash table */
422
423 // declare def_ht_ptr pointer;
424 // declare 1 definition_ht aligned based (def_ht_ptr),
425 struct definition_ht {
426   // 2 n_entries fixed bin,
427   uint64_t dummy0 : 18;
428   int64_t n_entries : 18;
429   uint64_t dummy1 : 28;
430
431   // 2 table (def_ht_n_entries refer (definition_ht.n_entries)) aligned,
432   struct {
433     // 3 def_relp fixed bin (18) unsigned unaligned,
434     // 3 unused bit (18) unaligned;
435     uint64_t unused : 18;
436     uint64_t def_relp : 18;
437     uint64_t dummy0 : 28;
438   } table[];
439 };
440
441 // declare def_ht_n_entries fixed bin;
442
443 // /* Component name ht */
444 // declare comp_ht_ptr pointer;
445 // declare 1 component_ht aligned based (comp_ht_ptr),
446 struct component_ht {
447   // 2 n_entries fixed bin,
448   uint64_t dummy0 : 18;
449   int64_t n_entries : 18;
450   uint64_t dummy1 : 28;
451
452   // 2 table (comp_ht_n_entries refer (component_ht.n_entries)) aligned,
453   struct {
454     // 3 def_relp fixed bin (18) unsigned unaligned,
455     // /* hashed segname */
456     // 3 block_hdr_relp fixed bin (18) unsigned unaligned;
457     // /* first segname def of block containing def_relp */
458     uint64_t block_hdr_relp : 18;
459     uint64_t def_relp : 18;
460     uint64_t dummy0 : 28;
461   } table[];
462 };
463
464 // declare comp_ht_n_entries fixed bin;
465
466 /* Duplicate name table */
467
468 // declare dup_table_ptr pointer;
469 // declare 1 duplicate_table aligned based (dup_table_ptr),
470 struct duplicate_table {
471   // 2 mbz bit (18) unaligned, /* to tell it from a definition */
472   // 2 n_names fixed bin (18) unsigned unaligned,
473   // /* n in table */
474   uint64_t n_names : 18;
475   uint64_t mbz : 18;
476   uint64_t dummy0 : 28;
477
478   // 2 table (dup_table_n_names refer (duplicate_table.n_names)) aligned,
479   struct {
480     // 3 def_relp fixed bin (18) unsigned unaligned,
481     // 3 block_hdr_relp fixed bin (18) unsigned unaligned;
482     uint64_t block_hdr_relp : 18;
483     uint64_t def_relp : 18;
484     uint64_t dummy0 : 28;
485   } table[];
486 };
487
488 // declare dup_table_n_names fixed bin;
489
490 /* The msf_map is found in the definition section of an */
491 /* object MSF component. It is used by the linker to */
492 /* determine whether a segment is a component of an object */
493 /* MSF or a standard single-segment object. */
494
495 // dcl msf_map_ptr ptr;
496 // dcl 01 msf_map aligned based (msf_map_ptr),
497 struct msf_map {
498   // 02 version char (8),
499   uint64_t version[2];
500
501   // 02 component_count fixed bin (15) unsigned,
502   uint64_t component_count : 15;
503   uint64_t dummy0 : 49;
504
505   // 02 my_component fixed bin (15) unsigned;
506   uint64_t my_component : 15;
507   uint64_t dummy1 : 49;
508 };
509
510 // dcl msf_map_version_1 char (8) static options (constant)
511 // init ("msfmp1.0");
512
513 // declare acc_string_ptr pointer;
514 // declare 1 acc_string aligned based (acc_string_ptr),
515 //   2 count fixed bin (9) unsigned unaligned,
516 //   2 string character (max (3, acc_string_length) refer (acc_string.count)) unaligned,
517 //   2 mbz bit (0) aligned; /* this causes the statement */
518 //   /* unspec (acc_string) = ""b to zero out */
519 //   /* the last word, if the string is not of length 0mod4 */
520
521 // declare acc_string_length fixed bin (21);
522
523 #endif