4 * (C) Copyright 1989-1995
13 * Extensions: P. Felber
19 #if defined(__APPLE__) && defined(__MACH__)
20 #include <sys/types.h>
21 #include <sys/malloc.h>
30 * The module aslist.c contains all the functions used
31 * to generate the assembler list and symbol output files.
33 * aslist.c contains the following functions:
40 * The module aslist.c contains no local/static variables
43 /*)Function VOID list()
45 * The function list() generates the listing output
46 * which includes the input source, line numbers,
47 * and generated code. Numerical output may be selected
48 * as hexadecimal, decimal, or octal.
51 * int * wp pointer to the assembled data bytes
52 * int * wpt pointer to the data byte mode
53 * int nb computed number of assembled bytes
56 * int cb[] array of assembler output values
57 * int cbt[] array of assembler relocation types
58 * describing the data in cb[]
59 * int * cp pointer to assembler output array cb[]
60 * int * cpt pointer to assembler relocation type
62 * char eb[] array of generated error codes
63 * char * ep pointer into error list
65 * char ib[] assembler-source text line
66 * FILE * lfp list output file handle
67 * int line current assembler source line number
68 * int lmode listing mode
69 * int xflag -x, listing radix flag
72 * int fprintf() c_library
73 * VOID list1() aslist.c
74 * int putc() c_library
75 * VOID slew() asslist.c
78 * Listing or symbol output updated.
89 if (lfp == NULL || lmode == NLIST)
93 * Get Correct Line Number
96 line = incline[incfil];
99 line = incline[incfil-1];
101 line = srcline[cfile];
105 line = srcline[cfile];
114 * Output a maximum of NERR error codes with listing.
116 while (ep < &eb[NERR])
118 fprintf(lfp, "%.2s", eb);
121 * Source listing only option.
123 if (lmode == SLIST) {
124 fprintf(lfp, "%24s%5u %s\n", "", line, ib);
128 if (lmode == ALIST) {
136 if (xflag == 0) { /* HEX */
140 if (lmode == ELIST) {
141 fprintf(lfp, "%18s%04X", "", laddr);
142 fprintf(lfp, " %5u %s\n", line, ib);
147 * Address (with allocation)
149 fprintf(lfp, " %04X", laddr);
150 if (lmode == ALIST || lmode == BLIST) {
151 fprintf(lfp, "%19s%5u %s\n", "", line, ib);
159 nb = (int) (cp - cb);
162 * First line of output for this source line with data.
164 list1(wp, wpt, nb, 1);
165 fprintf(lfp, " %5u %s\n", line, ib);
168 * Subsequent lines of output if more data.
170 while ((nb -= 6) > 0) {
174 fprintf(lfp, "%7s", "");
175 list1(wp, wpt, nb, 0);
180 * OCTAL output Option.
182 if (xflag == 1) { /* OCTAL */
186 if (lmode == ELIST) {
187 fprintf(lfp, "%16s%06o", "", laddr);
188 fprintf(lfp, " %5u %s\n", line, ib);
193 * Address (with allocation)
195 fprintf(lfp, " %06o", laddr);
196 if (lmode == ALIST || lmode == BLIST) {
197 fprintf(lfp, "%17s%5u %s\n", "", line, ib);
205 nb = (int) (cp - cb);
208 * First line of output for this source line with data.
210 list1(wp, wpt, nb, 1);
211 fprintf(lfp, " %5u %s\n", line, ib);
214 * Subsequent lines of output if more data.
216 while ((nb -= 4) > 0) {
220 fprintf(lfp, "%9s", "");
221 list1(wp, wpt, nb, 0);
226 * DECIMAL output Option.
228 if (xflag == 2) { /* DECIMAL */
232 if (lmode == ELIST) {
233 fprintf(lfp, "%16s%05u", "", laddr);
234 fprintf(lfp, " %5u %s\n", line, ib);
239 * Address (with allocation)
241 fprintf(lfp, " %05u", laddr);
242 if (lmode == ALIST || lmode == BLIST) {
243 fprintf(lfp, "%17s%5u %s\n", "", line, ib);
251 nb = (int) (cp - cb);
254 * First line of output for this source line with data.
256 list1(wp, wpt, nb, 1);
257 fprintf(lfp, " %5u %s\n", line, ib);
260 * Subsequent lines of output if more data.
262 while ((nb -= 4) > 0) {
266 fprintf(lfp, "%9s", "");
267 list1(wp, wpt, nb, 0);
280 if (lfp == NULL || lmode == NLIST)
284 * Get Correct Line Number
287 line = incline[incfil];
290 line = incline[incfil-1];
292 line = srcline[cfile];
296 line = srcline[cfile];
302 /* Output filename relative_address line_number */
305 fprintf(lfp, "%s ", incfn[incfil]);
308 fprintf(lfp, "%s ", srcfn[cfile]);
310 fprintf(lfp, "%u %04X\n", line, laddr);
314 nb = (int) (cp - cb);
317 * First line of output for this source line with data.
319 list1(wp, wpt, nb, 1);
320 fprintf(lfp, " %5u %s\n", line, ib);
323 * Subsequent lines of output if more data.
325 while ((nb -= 6) > 0) {
329 fprintf(lfp, "%7s", "");
330 list1(wp, wpt, nb, 0);
337 /*)Function VOID list1(wp, wpt, nw, f)
339 * int f fill blank fields (1)
340 * int nb number of data bytes
341 * int * wp pointer to data bytes
342 * int * wpt pointer to data byte mode
348 * int xflag -x, listing radix flag
351 * VOID list2() asslist.c
352 * int fprintf() c_library
355 * Data formatted and output to listing.
359 list1(wp, wpt, nb, f)
361 register int *wpt, nb, f;
368 if (xflag == 0) { /* HEX */
370 * Bound number of words to HEX maximum per line.
378 for (i=0; i<nb; ++i) {
380 fprintf(lfp, "%02X", (*wp++)&0377);
384 * Output blanks if required.
394 * OCTAL output Option.
396 if (xflag == 1) { /* OCTAL */
398 * Bound number of words to OCTAL maximum per line.
406 for (i=0; i<nb; ++i) {
408 fprintf(lfp, "%03o", (*wp++)&0377);
412 * Output blanks if required.
422 * DECIMAL output Option.
424 if (xflag == 2) { /* DECIMAL */
426 * Bound number of words to DECIMAL maximum per line.
434 for (i=0; i<nb; ++i) {
436 fprintf(lfp, "%03u", (*wp++)&0377);
440 * Output blanks if required.
451 /*)Function VOID list2(wpt)
453 * int * wpt pointer to relocation mode
455 * The function list2() outputs the selected
456 * relocation flag as specified by fflag.
459 * int c relocation flag character
460 * int t relocation mode
463 * int fflag -f(f), relocations flagged flag
466 * int putc() c_library
469 * Relocation flag output to listing file.
481 * Designate a relocatable word by `.
489 * Designate a relocatable word by its mode:
492 * operand offset p (q)
493 * relocatable symbol r (s)
497 if (t & (R_PAG0|R_PAG)) {
499 } else if (t & R_USGN) {
501 } else if (t & R_PCR) {
506 if (t & R_HIGH) c += 1;
511 * Output the selected mode.
516 /*)Function VOID slew(fp, flag)
518 * FILE * fp file handle for listing
519 * int flag enable pagination
521 * The function slew() increments the page line count.
522 * If the page overflows and pagination is enabled:
523 * 1) put out a page skip,
526 * 4) and reset the line count.
532 * char cpu[] cpu type string
533 * int lop current line number on page
534 * int page current page number
535 * char stb[] Subtitle string buffer
536 * char tb[] Title string buffer
539 * int fprintf() c_library
542 * Increments page line counter, on overflow
543 * a new page header is output to the listing file.
551 if ((lop++ >= NLPP) && flag) {
552 fprintf(fp, "\fASxxxx Assembler %s (%s), page %u.\n",
553 VERSION, cpu, ++page);
554 fprintf(fp, "%s\n", tb);
555 fprintf(fp, "%s\n\n", stb);
560 /*)Function VOID lstsym(fp)
562 * FILE * fp file handle for output
564 * The function lstsym() outputs alphabetically
565 * sorted symbol and area tables.
572 * char * ptr pointer to an id string
573 * int nmsym number of symbols
574 * int narea number of areas
575 * sym * sp pointer to symbol structure
576 * sym ** p pointer to an array of
577 * pointers to symbol structures
578 * area * ap pointer to an area structure
581 * area * areap pointer to an area structure
582 * char aretbl[] string "Area Table"
583 * sym dot defined as sym[0]
584 * char stb[] Subtitle string buffer
585 * sym * symhash[] array of pointers to NHASH
586 * linked symbol lists
587 * char symtbl[] string "Symbol Table"
588 * FILE * tfp symbol table output file handle
589 * int xflag -x, listing radix flag
592 * int fprintf() c_library
593 * int putc() c_library
594 * VOID slew() aslist.c
595 * int strcmp() c_library
596 * char * strcpy() c_library
599 * Symbol and area tables output.
606 register int c, i, j, k;
614 * Symbol Table Header
616 strcpy(stb, &symtbl[0]);
623 * Find number of symbols
626 for (i=0; i<NHASH; i++) {
638 * Allocate space for an array of pointers to symbols
641 if ((p = (struct sym **) malloc(sizeof((struct sym *) sp)*nmsym))
643 fprintf(fp, "Insufficient space to build Symbol Table.\n");
647 for (i=0; i<NHASH; i++) {
657 * Bubble Sort on Symbol Table Array
663 for (i=0; i<c; ++i) {
664 if (strcmp(&p[i]->s_id[0],&p[i+1]->s_id[0]) > 0) {
674 * Symbol Table Output
676 for (i=0; i<nmsym;) {
679 j = sp->s_area->a_ref;
681 fprintf(fp, " %2X ", j);
684 fprintf(fp, "%3o ", j);
687 fprintf(fp, "%3u ", j);
693 while (ptr < &sp->s_id[NCPS]) {
694 if ((c = *ptr++) != 0) {
700 if (sp->s_flag & S_ASG) {
705 if (sp->s_type == S_NEW) {
707 fprintf(fp, " **** ");
710 fprintf(fp, "****** ");
713 fprintf(fp, " ***** ");
718 fprintf(fp, " %04X ", j);
721 fprintf(fp, "%06o ", j);
724 fprintf(fp, " %05u ", j);
728 if (sp->s_flag & S_GBL) {
732 if (sp->s_area != NULL) {
736 if (sp->s_type == S_NEW) {
763 strcpy(stb, &aretbl[0]);
776 for (i=0; i<narea; ++i) {
778 for (j=i+1; j<narea; ++j)
782 fprintf(fp, " %2X ", j);
785 fprintf(fp, " %3o ", j);
788 fprintf(fp, " %3u ", j);
791 while (ptr < &ap->a_id[NCPS]) {
792 if ((c = *ptr++) != 0) {
801 fprintf(fp, " size %4X flags %X\n", j, k);
804 fprintf(fp, " size %6o flags %o\n", j, k);
807 fprintf(fp, " size %5u flags %u\n", j, k);