4 * (C) Copyright 1989-1995
13 * Extensions: P. Felber
20 #if defined(__APPLE__) && defined(__MACH__)
21 #include <sys/types.h>
22 #include <sys/malloc.h>
32 * The module aslist.c contains all the functions used
33 * to generate the assembler list and symbol output files.
35 * aslist.c contains the following functions:
42 * The module aslist.c contains no local/static variables
45 /*)Function VOID list()
47 * The function list() generates the listing output
48 * which includes the input source, line numbers,
49 * and generated code. Numerical output may be selected
50 * as hexadecimal, decimal, or octal.
53 * int * wp pointer to the assembled data bytes
54 * int * wpt pointer to the data byte mode
55 * int nb computed number of assembled bytes
58 * int cb[] array of assembler output values
59 * int cbt[] array of assembler relocation types
60 * describing the data in cb[]
61 * int * cp pointer to assembler output array cb[]
62 * int * cpt pointer to assembler relocation type
64 * char eb[] array of generated error codes
65 * char * ep pointer into error list
67 * char ib[] assembler-source text line
68 * FILE * lfp list output file handle
69 * int line current assembler source line number
70 * int lmode listing mode
71 * int xflag -x, listing radix flag
74 * int fprintf() c_library
75 * VOID list1() aslist.c
76 * int putc() c_library
77 * VOID slew() asslist.c
80 * Listing or symbol output updated.
91 if (lfp == NULL || lmode == NLIST)
95 * Get Correct Line Number
98 line = incline[incfil];
101 line = incline[incfil-1];
103 line = srcline[cfile];
107 line = srcline[cfile];
116 * Output a maximum of NERR error codes with listing.
118 while (ep < &eb[NERR])
120 fprintf(lfp, "%.2s", eb);
123 * Source listing only option.
125 if (lmode == SLIST) {
126 fprintf(lfp, "%24s%5u %s\n", "", line, ib);
130 if (lmode == ALIST) {
138 if (xflag == 0) { /* HEX */
142 if (lmode == ELIST) {
143 fprintf(lfp, "%18s%04X", "", laddr);
144 fprintf(lfp, " %5u %s\n", line, ib);
149 * Address (with allocation)
151 fprintf(lfp, " %04X", laddr);
152 if (lmode == ALIST || lmode == BLIST) {
153 fprintf(lfp, "%19s%5u %s\n", "", line, ib);
161 nb = (int) (cp - cb);
164 * First line of output for this source line with data.
166 list1(wp, wpt, nb, 1);
167 fprintf(lfp, " %5u %s\n", line, ib);
170 * Subsequent lines of output if more data.
172 while ((nb -= 6) > 0) {
176 fprintf(lfp, "%7s", "");
177 list1(wp, wpt, nb, 0);
182 * OCTAL output Option.
184 if (xflag == 1) { /* OCTAL */
188 if (lmode == ELIST) {
189 fprintf(lfp, "%16s%06o", "", laddr);
190 fprintf(lfp, " %5u %s\n", line, ib);
195 * Address (with allocation)
197 fprintf(lfp, " %06o", laddr);
198 if (lmode == ALIST || lmode == BLIST) {
199 fprintf(lfp, "%17s%5u %s\n", "", line, ib);
207 nb = (int) (cp - cb);
210 * First line of output for this source line with data.
212 list1(wp, wpt, nb, 1);
213 fprintf(lfp, " %5u %s\n", line, ib);
216 * Subsequent lines of output if more data.
218 while ((nb -= 4) > 0) {
222 fprintf(lfp, "%9s", "");
223 list1(wp, wpt, nb, 0);
228 * DECIMAL output Option.
230 if (xflag == 2) { /* DECIMAL */
234 if (lmode == ELIST) {
235 fprintf(lfp, "%16s%05u", "", laddr);
236 fprintf(lfp, " %5u %s\n", line, ib);
241 * Address (with allocation)
243 fprintf(lfp, " %05u", laddr);
244 if (lmode == ALIST || lmode == BLIST) {
245 fprintf(lfp, "%17s%5u %s\n", "", line, ib);
253 nb = (int) (cp - cb);
256 * First line of output for this source line with data.
258 list1(wp, wpt, nb, 1);
259 fprintf(lfp, " %5u %s\n", line, ib);
262 * Subsequent lines of output if more data.
264 while ((nb -= 4) > 0) {
268 fprintf(lfp, "%9s", "");
269 list1(wp, wpt, nb, 0);
282 if (lfp == NULL || lmode == NLIST)
286 * Get Correct Line Number
289 line = incline[incfil];
292 line = incline[incfil-1];
294 line = srcline[cfile];
298 line = srcline[cfile];
304 /* Output filename relative_address line_number */
307 fprintf(lfp, "%s ", incfn[incfil]);
310 fprintf(lfp, "%s ", srcfn[cfile]);
312 fprintf(lfp, "%u %04X\n", line, laddr);
316 nb = (int) (cp - cb);
319 * First line of output for this source line with data.
321 list1(wp, wpt, nb, 1);
322 fprintf(lfp, " %5u %s\n", line, ib);
325 * Subsequent lines of output if more data.
327 while ((nb -= 6) > 0) {
331 fprintf(lfp, "%7s", "");
332 list1(wp, wpt, nb, 0);
339 /*)Function VOID list1(wp, wpt, nw, f)
341 * int f fill blank fields (1)
342 * int nb number of data bytes
343 * int * wp pointer to data bytes
344 * int * wpt pointer to data byte mode
350 * int xflag -x, listing radix flag
353 * VOID list2() asslist.c
354 * int fprintf() c_library
357 * Data formatted and output to listing.
361 list1(wp, wpt, nb, f)
363 register int *wpt, nb, f;
370 if (xflag == 0) { /* HEX */
372 * Bound number of words to HEX maximum per line.
380 for (i=0; i<nb; ++i) {
382 fprintf(lfp, "%02X", (*wp++)&0377);
386 * Output blanks if required.
396 * OCTAL output Option.
398 if (xflag == 1) { /* OCTAL */
400 * Bound number of words to OCTAL maximum per line.
408 for (i=0; i<nb; ++i) {
410 fprintf(lfp, "%03o", (*wp++)&0377);
414 * Output blanks if required.
424 * DECIMAL output Option.
426 if (xflag == 2) { /* DECIMAL */
428 * Bound number of words to DECIMAL maximum per line.
436 for (i=0; i<nb; ++i) {
438 fprintf(lfp, "%03u", (*wp++)&0377);
442 * Output blanks if required.
453 /*)Function VOID list2(wpt)
455 * int * wpt pointer to relocation mode
457 * The function list2() outputs the selected
458 * relocation flag as specified by fflag.
461 * int c relocation flag character
462 * int t relocation mode
465 * int fflag -f(f), relocations flagged flag
468 * int putc() c_library
471 * Relocation flag output to listing file.
483 * Designate a relocatable word by `.
491 * Designate a relocatable word by its mode:
494 * operand offset p (q)
495 * relocatable symbol r (s)
499 if (t & (R_PAG0|R_PAG)) {
501 } else if (t & R_USGN) {
503 } else if (t & R_PCR) {
508 if (t & R_HIGH) c += 1;
513 * Output the selected mode.
518 /*)Function VOID slew(fp, flag)
520 * FILE * fp file handle for listing
521 * int flag enable pagination
523 * The function slew() increments the page line count.
524 * If the page overflows and pagination is enabled:
525 * 1) put out a page skip,
528 * 4) and reset the line count.
534 * char cpu[] cpu type string
535 * int lop current line number on page
536 * int page current page number
537 * char stb[] Subtitle string buffer
538 * char tb[] Title string buffer
541 * int fprintf() c_library
544 * Increments page line counter, on overflow
545 * a new page header is output to the listing file.
553 if ((lop++ >= NLPP) && flag) {
554 fprintf(fp, "\fASxxxx Assembler %s (%s), page %u.\n",
555 VERSION, cpu, ++page);
556 fprintf(fp, "%s\n", tb);
557 fprintf(fp, "%s\n\n", stb);
562 /*)Function VOID lstsym(fp)
564 * FILE * fp file handle for output
566 * The function lstsym() outputs alphabetically
567 * sorted symbol and area tables.
574 * char * ptr pointer to an id string
575 * int nmsym number of symbols
576 * int narea number of areas
577 * sym * sp pointer to symbol structure
578 * sym ** p pointer to an array of
579 * pointers to symbol structures
580 * area * ap pointer to an area structure
583 * area * areap pointer to an area structure
584 * char aretbl[] string "Area Table"
585 * sym dot defined as sym[0]
586 * char stb[] Subtitle string buffer
587 * sym * symhash[] array of pointers to NHASH
588 * linked symbol lists
589 * char symtbl[] string "Symbol Table"
590 * FILE * tfp symbol table output file handle
591 * int xflag -x, listing radix flag
594 * int fprintf() c_library
595 * int putc() c_library
596 * VOID slew() aslist.c
597 * int strcmp() c_library
598 * char * strcpy() c_library
601 * Symbol and area tables output.
608 register int c, i, j, k;
616 * Symbol Table Header
618 strcpy(stb, &symtbl[0]);
625 * Find number of symbols
628 for (i=0; i<NHASH; i++) {
640 * Allocate space for an array of pointers to symbols
643 if ((p = (struct sym **) malloc(sizeof((struct sym *) sp)*nmsym))
645 fprintf(fp, "Insufficient space to build Symbol Table.\n");
649 for (i=0; i<NHASH; i++) {
659 * Bubble Sort on Symbol Table Array
665 for (i=0; i<c; ++i) {
666 if (strcmp(&p[i]->s_id[0],&p[i+1]->s_id[0]) > 0) {
676 * Symbol Table Output
678 for (i=0; i<nmsym;) {
681 j = sp->s_area->a_ref;
683 fprintf(fp, " %2X ", j);
686 fprintf(fp, "%3o ", j);
689 fprintf(fp, "%3u ", j);
695 while (ptr < &sp->s_id[NCPS]) {
696 if ((c = *ptr++) != 0) {
702 if (sp->s_flag & S_ASG) {
707 if (sp->s_type == S_NEW) {
709 fprintf(fp, " **** ");
712 fprintf(fp, "****** ");
715 fprintf(fp, " ***** ");
720 fprintf(fp, " %04X ", j);
723 fprintf(fp, "%06o ", j);
726 fprintf(fp, " %05u ", j);
730 if (sp->s_flag & S_GBL) {
734 if (sp->s_area != NULL) {
738 if (sp->s_type == S_NEW) {
765 strcpy(stb, &aretbl[0]);
778 for (i=0; i<narea; ++i) {
780 for (j=i+1; j<narea; ++j)
784 fprintf(fp, " %2X ", j);
787 fprintf(fp, " %3o ", j);
790 fprintf(fp, " %3u ", j);
793 while (ptr < &ap->a_id[NCPS]) {
794 if ((c = *ptr++) != 0) {
803 fprintf(fp, " size %4X flags %X\n", j, k);
806 fprintf(fp, " size %6o flags %o\n", j, k);
809 fprintf(fp, " size %5u flags %u\n", j, k);