4 * (C) Copyright 1989-1995
13 * Extensions: P. Felber
20 //#include "newalloc.h"
31 * The module aslist.c contains all the functions used
32 * to generate the assembler list and symbol output files.
34 * aslist.c contains the following functions:
41 * The module aslist.c contains no local/static variables
44 /*)Function VOID list()
46 * The function list() generates the listing output
47 * which includes the input source, line numbers,
48 * and generated code. Numerical output may be selected
49 * as hexadecimal, decimal, or octal.
52 * int * wp pointer to the assembled data bytes
53 * int * wpt pointer to the data byte mode
54 * int nb computed number of assembled bytes
57 * int cb[] array of assembler output values
58 * int cbt[] array of assembler relocation types
59 * describing the data in cb[]
60 * int * cp pointer to assembler output array cb[]
61 * int * cpt pointer to assembler relocation type
63 * char eb[] array of generated error codes
64 * char * ep pointer into error list
66 * char ib[] assembler-source text line
67 * FILE * lfp list output file handle
68 * int line current assembler source line number
69 * int lmode listing mode
70 * int xflag -x, listing radix flag
73 * int fprintf() c_library
74 * VOID list1() aslist.c
75 * int putc() c_library
76 * VOID slew() asslist.c
79 * Listing or symbol output updated.
90 if (lfp == NULL || lmode == NLIST)
94 * Get Correct Line Number
97 line = incline[incfil];
100 line = incline[incfil-1];
102 line = srcline[cfile];
106 line = srcline[cfile];
115 * Output a maximum of NERR error codes with listing.
117 while (ep < &eb[NERR])
119 fprintf(lfp, "%.2s", eb);
122 * Source listing only option.
124 if (lmode == SLIST) {
125 fprintf(lfp, "%24s%5u %s\n", "", line, ib);
129 if (lmode == ALIST) {
137 if (xflag == 0) { /* HEX */
141 if (lmode == ELIST) {
142 fprintf(lfp, "%18s%04X", "", laddr);
143 fprintf(lfp, " %5u %s\n", line, ib);
148 * Address (with allocation)
150 fprintf(lfp, " %04X", laddr);
151 if (lmode == ALIST || lmode == BLIST) {
152 fprintf(lfp, "%19s%5u %s\n", "", line, ib);
160 nb = (int) (cp - cb);
163 * First line of output for this source line with data.
165 list1(wp, wpt, nb, 1);
166 fprintf(lfp, " %5u %s\n", line, ib);
169 * Subsequent lines of output if more data.
171 while ((nb -= 6) > 0) {
175 fprintf(lfp, "%7s", "");
176 list1(wp, wpt, nb, 0);
181 * OCTAL output Option.
183 if (xflag == 1) { /* OCTAL */
187 if (lmode == ELIST) {
188 fprintf(lfp, "%16s%06o", "", laddr);
189 fprintf(lfp, " %5u %s\n", line, ib);
194 * Address (with allocation)
196 fprintf(lfp, " %06o", laddr);
197 if (lmode == ALIST || lmode == BLIST) {
198 fprintf(lfp, "%17s%5u %s\n", "", line, ib);
206 nb = (int) (cp - cb);
209 * First line of output for this source line with data.
211 list1(wp, wpt, nb, 1);
212 fprintf(lfp, " %5u %s\n", line, ib);
215 * Subsequent lines of output if more data.
217 while ((nb -= 4) > 0) {
221 fprintf(lfp, "%9s", "");
222 list1(wp, wpt, nb, 0);
227 * DECIMAL output Option.
229 if (xflag == 2) { /* DECIMAL */
233 if (lmode == ELIST) {
234 fprintf(lfp, "%16s%05u", "", laddr);
235 fprintf(lfp, " %5u %s\n", line, ib);
240 * Address (with allocation)
242 fprintf(lfp, " %05u", laddr);
243 if (lmode == ALIST || lmode == BLIST) {
244 fprintf(lfp, "%17s%5u %s\n", "", line, ib);
252 nb = (int) (cp - cb);
255 * First line of output for this source line with data.
257 list1(wp, wpt, nb, 1);
258 fprintf(lfp, " %5u %s\n", line, ib);
261 * Subsequent lines of output if more data.
263 while ((nb -= 4) > 0) {
267 fprintf(lfp, "%9s", "");
268 list1(wp, wpt, nb, 0);
281 if (lfp == NULL || lmode == NLIST)
285 * Get Correct Line Number
288 line = incline[incfil];
291 line = incline[incfil-1];
293 line = srcline[cfile];
297 line = srcline[cfile];
303 /* Output filename relative_address line_number */
306 fprintf(lfp, "%s ", incfn[incfil]);
309 fprintf(lfp, "%s ", srcfn[cfile]);
311 fprintf(lfp, "%u %04X\n", line, laddr);
315 nb = (int) (cp - cb);
318 * First line of output for this source line with data.
320 list1(wp, wpt, nb, 1);
321 fprintf(lfp, " %5u %s\n", line, ib);
324 * Subsequent lines of output if more data.
326 while ((nb -= 6) > 0) {
330 fprintf(lfp, "%7s", "");
331 list1(wp, wpt, nb, 0);
338 /*)Function VOID list1(wp, wpt, nw, f)
340 * int f fill blank fields (1)
341 * int nb number of data bytes
342 * int * wp pointer to data bytes
343 * int * wpt pointer to data byte mode
349 * int xflag -x, listing radix flag
352 * VOID list2() asslist.c
353 * int fprintf() c_library
356 * Data formatted and output to listing.
360 list1(wp, wpt, nb, f)
362 register int *wpt, nb, f;
369 if (xflag == 0) { /* HEX */
371 * Bound number of words to HEX maximum per line.
379 for (i=0; i<nb; ++i) {
381 fprintf(lfp, "%02X", (*wp++)&0377);
385 * Output blanks if required.
395 * OCTAL output Option.
397 if (xflag == 1) { /* OCTAL */
399 * Bound number of words to OCTAL maximum per line.
407 for (i=0; i<nb; ++i) {
409 fprintf(lfp, "%03o", (*wp++)&0377);
413 * Output blanks if required.
423 * DECIMAL output Option.
425 if (xflag == 2) { /* DECIMAL */
427 * Bound number of words to DECIMAL maximum per line.
435 for (i=0; i<nb; ++i) {
437 fprintf(lfp, "%03u", (*wp++)&0377);
441 * Output blanks if required.
452 /*)Function VOID list2(wpt)
454 * int * wpt pointer to relocation mode
456 * The function list2() outputs the selected
457 * relocation flag as specified by fflag.
460 * int c relocation flag character
461 * int t relocation mode
464 * int fflag -f(f), relocations flagged flag
467 * int putc() c_library
470 * Relocation flag output to listing file.
482 * Designate a relocatable word by `.
490 * Designate a relocatable word by its mode:
493 * operand offset p (q)
494 * relocatable symbol r (s)
498 if (t & (R_PAG0|R_PAG)) {
500 } else if (t & R_USGN) {
502 } else if (t & R_PCR) {
507 if (t & R_HIGH) c += 1;
512 * Output the selected mode.
517 /*)Function VOID slew(fp, flag)
519 * FILE * fp file handle for listing
520 * int flag enable pagination
522 * The function slew() increments the page line count.
523 * If the page overflows and pagination is enabled:
524 * 1) put out a page skip,
527 * 4) and reset the line count.
533 * char cpu[] cpu type string
534 * int lop current line number on page
535 * int page current page number
536 * char stb[] Subtitle string buffer
537 * char tb[] Title string buffer
540 * int fprintf() c_library
543 * Increments page line counter, on overflow
544 * a new page header is output to the listing file.
552 if ((lop++ >= NLPP) && flag) {
553 fprintf(fp, "\fASxxxx Assembler %s (%s), page %u.\n",
554 VERSION, cpu, ++page);
555 fprintf(fp, "%s\n", tb);
556 fprintf(fp, "%s\n\n", stb);
561 /*)Function VOID lstsym(fp)
563 * FILE * fp file handle for output
565 * The function lstsym() outputs alphabetically
566 * sorted symbol and area tables.
573 * char * ptr pointer to an id string
574 * int nmsym number of symbols
575 * int narea number of areas
576 * sym * sp pointer to symbol structure
577 * sym ** p pointer to an array of
578 * pointers to symbol structures
579 * area * ap pointer to an area structure
582 * area * areap pointer to an area structure
583 * char aretbl[] string "Area Table"
584 * sym dot defined as sym[0]
585 * char stb[] Subtitle string buffer
586 * sym * symhash[] array of pointers to NHASH
587 * linked symbol lists
588 * char symtbl[] string "Symbol Table"
589 * FILE * tfp symbol table output file handle
590 * int xflag -x, listing radix flag
593 * int fprintf() c_library
594 * int putc() c_library
595 * VOID slew() aslist.c
596 * int strcmp() c_library
597 * char * strcpy() c_library
600 * Symbol and area tables output.
607 register int c, i, j, k;
615 * Symbol Table Header
617 strcpy(stb, &symtbl[0]);
624 * Find number of symbols
627 for (i=0; i<NHASH; i++) {
639 * Allocate space for an array of pointers to symbols
642 if ((p = (struct sym **) malloc(sizeof((struct sym *) sp)*nmsym))
644 fprintf(fp, "Insufficient space to build Symbol Table.\n");
648 for (i=0; i<NHASH; i++) {
658 * Bubble Sort on Symbol Table Array
664 for (i=0; i<c; ++i) {
665 if (strcmp(&p[i]->s_id[0],&p[i+1]->s_id[0]) > 0) {
675 * Symbol Table Output
677 for (i=0; i<nmsym;) {
680 j = sp->s_area->a_ref;
682 fprintf(fp, " %2X ", j);
685 fprintf(fp, "%3o ", j);
688 fprintf(fp, "%3u ", j);
694 while (ptr < &sp->s_id[NCPS]) {
695 if ((c = *ptr++) != 0) {
701 if (sp->s_flag & S_ASG) {
706 if (sp->s_type == S_NEW) {
708 fprintf(fp, " **** ");
711 fprintf(fp, "****** ");
714 fprintf(fp, " ***** ");
719 fprintf(fp, " %04X ", j);
722 fprintf(fp, "%06o ", j);
725 fprintf(fp, " %05u ", j);
729 if (sp->s_flag & S_GBL) {
733 if (sp->s_area != NULL) {
737 if (sp->s_type == S_NEW) {
764 strcpy(stb, &aretbl[0]);
777 for (i=0; i<narea; ++i) {
779 for (j=i+1; j<narea; ++j)
783 fprintf(fp, " %2X ", j);
786 fprintf(fp, " %3o ", j);
789 fprintf(fp, " %3u ", j);
792 while (ptr < &ap->a_id[NCPS]) {
793 if ((c = *ptr++) != 0) {
802 fprintf(fp, " size %4X flags %X\n", j, k);
805 fprintf(fp, " size %6o flags %o\n", j, k);
808 fprintf(fp, " size %5u flags %u\n", j, k);