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>
34 * The module aslist.c contains all the functions used
35 * to generate the assembler list and symbol output files.
37 * aslist.c contains the following functions:
44 * The module aslist.c contains no local/static variables
47 /*)Function VOID list()
49 * The function list() generates the listing output
50 * which includes the input source, line numbers,
51 * and generated code. Numerical output may be selected
52 * as hexadecimal, decimal, or octal.
55 * int * wp pointer to the assembled data bytes
56 * int * wpt pointer to the data byte mode
57 * int nb computed number of assembled bytes
60 * int cb[] array of assembler output values
61 * int cbt[] array of assembler relocation types
62 * describing the data in cb[]
63 * int * cp pointer to assembler output array cb[]
64 * int * cpt pointer to assembler relocation type
66 * char eb[] array of generated error codes
67 * char * ep pointer into error list
69 * char ib[] assembler-source text line
70 * FILE * lfp list output file handle
71 * int line current assembler source line number
72 * int lmode listing mode
73 * int xflag -x, listing radix flag
76 * int fprintf() c_library
77 * VOID list1() aslist.c
78 * int putc() c_library
79 * VOID slew() asslist.c
82 * Listing or symbol output updated.
93 if (lfp == NULL || lmode == NLIST)
97 * Get Correct Line Number
100 line = incline[incfil];
103 line = incline[incfil-1];
105 line = srcline[cfile];
109 line = srcline[cfile];
118 * Output a maximum of NERR error codes with listing.
120 while (ep < &eb[NERR])
122 fprintf(lfp, "%.2s", eb);
125 * Source listing only option.
127 if (lmode == SLIST) {
128 fprintf(lfp, "%24s%5u %s\n", "", line, ib);
132 if (lmode == ALIST) {
140 if (xflag == 0) { /* HEX */
144 if (lmode == ELIST) {
145 fprintf(lfp, "%18s%04X", "", laddr);
146 fprintf(lfp, " %5u %s\n", line, ib);
151 * Address (with allocation)
153 fprintf(lfp, " %04X", laddr);
154 if (lmode == ALIST || lmode == BLIST) {
155 fprintf(lfp, "%19s%5u %s\n", "", line, ib);
163 nb = (int) (cp - cb);
166 * First line of output for this source line with data.
168 list1(wp, wpt, nb, 1);
169 fprintf(lfp, " %5u %s\n", line, ib);
172 * Subsequent lines of output if more data.
174 while ((nb -= 6) > 0) {
178 fprintf(lfp, "%7s", "");
179 list1(wp, wpt, nb, 0);
184 * OCTAL output Option.
186 if (xflag == 1) { /* OCTAL */
190 if (lmode == ELIST) {
191 fprintf(lfp, "%16s%06o", "", laddr);
192 fprintf(lfp, " %5u %s\n", line, ib);
197 * Address (with allocation)
199 fprintf(lfp, " %06o", laddr);
200 if (lmode == ALIST || lmode == BLIST) {
201 fprintf(lfp, "%17s%5u %s\n", "", line, ib);
209 nb = (int) (cp - cb);
212 * First line of output for this source line with data.
214 list1(wp, wpt, nb, 1);
215 fprintf(lfp, " %5u %s\n", line, ib);
218 * Subsequent lines of output if more data.
220 while ((nb -= 4) > 0) {
224 fprintf(lfp, "%9s", "");
225 list1(wp, wpt, nb, 0);
230 * DECIMAL output Option.
232 if (xflag == 2) { /* DECIMAL */
236 if (lmode == ELIST) {
237 fprintf(lfp, "%16s%05u", "", laddr);
238 fprintf(lfp, " %5u %s\n", line, ib);
243 * Address (with allocation)
245 fprintf(lfp, " %05u", laddr);
246 if (lmode == ALIST || lmode == BLIST) {
247 fprintf(lfp, "%17s%5u %s\n", "", line, ib);
255 nb = (int) (cp - cb);
258 * First line of output for this source line with data.
260 list1(wp, wpt, nb, 1);
261 fprintf(lfp, " %5u %s\n", line, ib);
264 * Subsequent lines of output if more data.
266 while ((nb -= 4) > 0) {
270 fprintf(lfp, "%9s", "");
271 list1(wp, wpt, nb, 0);
284 if (lfp == NULL || lmode == NLIST)
288 * Get Correct Line Number
291 line = incline[incfil];
294 line = incline[incfil-1];
296 line = srcline[cfile];
300 line = srcline[cfile];
306 /* Output filename relative_address line_number */
309 fprintf(lfp, "%s ", incfn[incfil]);
312 fprintf(lfp, "%s ", srcfn[cfile]);
314 fprintf(lfp, "%u %04X\n", line, laddr);
318 nb = (int) (cp - cb);
321 * First line of output for this source line with data.
323 list1(wp, wpt, nb, 1);
324 fprintf(lfp, " %5u %s\n", line, ib);
327 * Subsequent lines of output if more data.
329 while ((nb -= 6) > 0) {
333 fprintf(lfp, "%7s", "");
334 list1(wp, wpt, nb, 0);
341 /*)Function VOID list1(wp, wpt, nw, f)
343 * int f fill blank fields (1)
344 * int nb number of data bytes
345 * int * wp pointer to data bytes
346 * int * wpt pointer to data byte mode
352 * int xflag -x, listing radix flag
355 * VOID list2() asslist.c
356 * int fprintf() c_library
359 * Data formatted and output to listing.
363 list1(wp, wpt, nb, f)
365 register int *wpt, nb, f;
372 if (xflag == 0) { /* HEX */
374 * Bound number of words to HEX maximum per line.
382 for (i=0; i<nb; ++i) {
384 fprintf(lfp, "%02X", (*wp++)&0377);
388 * Output blanks if required.
398 * OCTAL output Option.
400 if (xflag == 1) { /* OCTAL */
402 * Bound number of words to OCTAL maximum per line.
410 for (i=0; i<nb; ++i) {
412 fprintf(lfp, "%03o", (*wp++)&0377);
416 * Output blanks if required.
426 * DECIMAL output Option.
428 if (xflag == 2) { /* DECIMAL */
430 * Bound number of words to DECIMAL maximum per line.
438 for (i=0; i<nb; ++i) {
440 fprintf(lfp, "%03u", (*wp++)&0377);
444 * Output blanks if required.
455 /*)Function VOID list2(wpt)
457 * int * wpt pointer to relocation mode
459 * The function list2() outputs the selected
460 * relocation flag as specified by fflag.
463 * int c relocation flag character
464 * int t relocation mode
467 * int fflag -f(f), relocations flagged flag
470 * int putc() c_library
473 * Relocation flag output to listing file.
485 * Designate a relocatable word by `.
493 * Designate a relocatable word by its mode:
496 * operand offset p (q)
497 * relocatable symbol r (s)
501 if (t & (R_PAG0|R_PAG)) {
503 } else if (t & R_USGN) {
505 } else if (t & R_PCR) {
510 if (t & R_HIGH) c += 1;
515 * Output the selected mode.
520 /*)Function VOID slew(fp, flag)
522 * FILE * fp file handle for listing
523 * int flag enable pagination
525 * The function slew() increments the page line count.
526 * If the page overflows and pagination is enabled:
527 * 1) put out a page skip,
530 * 4) and reset the line count.
536 * char cpu[] cpu type string
537 * int lop current line number on page
538 * int page current page number
539 * char stb[] Subtitle string buffer
540 * char tb[] Title string buffer
543 * int fprintf() c_library
546 * Increments page line counter, on overflow
547 * a new page header is output to the listing file.
555 if ((lop++ >= NLPP) && flag) {
556 fprintf(fp, "\fASxxxx Assembler %s (%s), page %u.\n",
557 VERSION, cpu, ++page);
558 fprintf(fp, "%s\n", tb);
559 fprintf(fp, "%s\n\n", stb);
564 /*)Function VOID lstsym(fp)
566 * FILE * fp file handle for output
568 * The function lstsym() outputs alphabetically
569 * sorted symbol and area tables.
576 * char * ptr pointer to an id string
577 * int nmsym number of symbols
578 * int narea number of areas
579 * sym * sp pointer to symbol structure
580 * sym ** p pointer to an array of
581 * pointers to symbol structures
582 * area * ap pointer to an area structure
585 * area * areap pointer to an area structure
586 * char aretbl[] string "Area Table"
587 * sym dot defined as sym[0]
588 * char stb[] Subtitle string buffer
589 * sym * symhash[] array of pointers to NHASH
590 * linked symbol lists
591 * char symtbl[] string "Symbol Table"
592 * FILE * tfp symbol table output file handle
593 * int xflag -x, listing radix flag
596 * int fprintf() c_library
597 * int putc() c_library
598 * VOID slew() aslist.c
599 * int strcmp() c_library
600 * char * strcpy() c_library
603 * Symbol and area tables output.
610 register int c, i, j, k;
618 * Symbol Table Header
620 strcpy(stb, &symtbl[0]);
627 * Find number of symbols
630 for (i=0; i<NHASH; i++) {
642 * Allocate space for an array of pointers to symbols
645 if ((p = (struct sym **) malloc(sizeof((struct sym *) sp)*nmsym))
647 fprintf(fp, "Insufficient space to build Symbol Table.\n");
651 for (i=0; i<NHASH; i++) {
661 * Bubble Sort on Symbol Table Array
667 for (i=0; i<c; ++i) {
668 if (strcmp(&p[i]->s_id[0],&p[i+1]->s_id[0]) > 0) {
678 * Symbol Table Output
680 for (i=0; i<nmsym;) {
683 j = sp->s_area->a_ref;
685 fprintf(fp, " %2X ", j);
688 fprintf(fp, "%3o ", j);
691 fprintf(fp, "%3u ", j);
697 while (ptr < &sp->s_id[NCPS]) {
698 if ((c = *ptr++) != 0) {
704 if (sp->s_flag & S_ASG) {
709 if (sp->s_type == S_NEW) {
711 fprintf(fp, " **** ");
714 fprintf(fp, "****** ");
717 fprintf(fp, " ***** ");
722 fprintf(fp, " %04X ", j);
725 fprintf(fp, "%06o ", j);
728 fprintf(fp, " %05u ", j);
732 if (sp->s_flag & S_GBL) {
736 if (sp->s_area != NULL) {
740 if (sp->s_type == S_NEW) {
767 strcpy(stb, &aretbl[0]);
780 for (i=0; i<narea; ++i) {
782 for (j=i+1; j<narea; ++j)
786 fprintf(fp, " %2X ", j);
789 fprintf(fp, " %3o ", j);
792 fprintf(fp, " %3u ", j);
795 while (ptr < &ap->a_id[NCPS]) {
796 if ((c = *ptr++) != 0) {
805 fprintf(fp, " size %4X flags %X\n", j, k);
808 fprintf(fp, " size %6o flags %o\n", j, k);
811 fprintf(fp, " size %5u flags %u\n", j, k);