4 * (C) Copyright 1989-1995
12 * - lstsym: show s_id as string rather than array [NCPS]
18 //#if !defined(_MSC_VER)
26 * The module aslist.c contains all the functions used
27 * to generate the assembler list and symbol output files.
29 * aslist.c contains the following functions:
36 * The module aslist.c contains no local/static variables
39 /*)Function VOID list()
41 * The function list() generates the listing output
42 * which includes the input source, line numbers,
43 * and generated code. Numerical output may be selected
44 * as hexadecimal, decimal, or octal.
47 * int * wp pointer to the assembled data bytes
48 * int * wpt pointer to the data byte mode
49 * int nb computed number of assembled bytes
52 * int cb[] array of assembler output values
53 * int cbt[] array of assembler relocation types
54 * describing the data in cb[]
55 * int * cp pointer to assembler output array cb[]
56 * int * cpt pointer to assembler relocation type
58 * char eb[] array of generated error codes
59 * char * ep pointer into error list
61 * char ib[] assembler-source text line
62 * FILE * lfp list output file handle
63 * int line current assembler source line number
64 * int lmode listing mode
65 * int xflag -x, listing radix flag
68 * int fprintf() c_library
69 * VOID list1() aslist.c
70 * int putc() c_library
71 * VOID slew() asslist.c
74 * Listing or symbol output updated.
84 if (lfp == NULL || lmode == NLIST)
88 * Get Correct Line Number
91 line = incline[incfil];
94 line = incline[incfil-1];
96 line = srcline[cfile];
100 line = srcline[cfile];
109 * Output a maximum of NERR error codes with listing.
111 while (ep < &eb[NERR])
113 fprintf(lfp, "%.2s", eb);
116 * Source listing only option.
118 if (lmode == SLIST) {
119 fprintf(lfp, "%24s%5u %s\n", "", line, ib);
122 if (lmode == ALIST) {
129 if (xflag == 0) { /* HEX */
133 if (lmode == ELIST) {
134 fprintf(lfp, "%18s%04X", "", laddr);
135 fprintf(lfp, " %5u %s\n", line, ib);
140 * Address (with allocation)
142 fprintf(lfp, " %04X", laddr);
143 if (lmode == ALIST || lmode == BLIST) {
144 fprintf(lfp, "%19s%5u %s\n", "", line, ib);
150 nb = (int) (cp - cb);
153 * First line of output for this source line with data.
155 list1(wp, wpt, nb, 1);
156 fprintf(lfp, " %5u %s\n", line, ib);
159 * Subsequent lines of output if more data.
161 while ((nb -= 6) > 0) {
165 fprintf(lfp, "%7s", "");
166 list1(wp, wpt, nb, 0);
171 * OCTAL output Option.
173 if (xflag == 1) { /* OCTAL */
177 if (lmode == ELIST) {
178 fprintf(lfp, "%16s%06o", "", laddr);
179 fprintf(lfp, " %5u %s\n", line, ib);
184 * Address (with allocation)
186 fprintf(lfp, " %06o", laddr);
187 if (lmode == ALIST || lmode == BLIST) {
188 fprintf(lfp, "%17s%5u %s\n", "", line, ib);
194 nb = (int) (cp - cb);
197 * First line of output for this source line with data.
199 list1(wp, wpt, nb, 1);
200 fprintf(lfp, " %5u %s\n", line, ib);
203 * Subsequent lines of output if more data.
205 while ((nb -= 4) > 0) {
209 fprintf(lfp, "%9s", "");
210 list1(wp, wpt, nb, 0);
215 * DECIMAL output Option.
217 if (xflag == 2) { /* DECIMAL */
221 if (lmode == ELIST) {
222 fprintf(lfp, "%16s%05u", "", laddr);
223 fprintf(lfp, " %5u %s\n", line, ib);
228 * Address (with allocation)
230 fprintf(lfp, " %05u", laddr);
231 if (lmode == ALIST || lmode == BLIST) {
232 fprintf(lfp, "%17s%5u %s\n", "", line, ib);
238 nb = (int) (cp - cb);
241 * First line of output for this source line with data.
243 list1(wp, wpt, nb, 1);
244 fprintf(lfp, " %5u %s\n", line, ib);
247 * Subsequent lines of output if more data.
249 while ((nb -= 4) > 0) {
253 fprintf(lfp, "%9s", "");
254 list1(wp, wpt, nb, 0);
260 /*)Function VOID list1(wp, wpt, nw, f)
262 * int f fill blank fields (1)
263 * int nb number of data bytes
264 * int * wp pointer to data bytes
265 * int * wpt pointer to data byte mode
271 * int xflag -x, listing radix flag
274 * VOID list2() asslist.c
275 * int fprintf() c_library
278 * Data formatted and output to listing.
282 list1(wp, wpt, nb, f)
284 register int *wpt, nb, f;
291 if (xflag == 0) { /* HEX */
293 * Bound number of words to HEX maximum per line.
301 for (i=0; i<nb; ++i) {
303 fprintf(lfp, "%02X", (*wp++)&0377);
307 * Output blanks if required.
317 * OCTAL output Option.
319 if (xflag == 1) { /* OCTAL */
321 * Bound number of words to OCTAL maximum per line.
329 for (i=0; i<nb; ++i) {
331 fprintf(lfp, "%03o", (*wp++)&0377);
335 * Output blanks if required.
345 * DECIMAL output Option.
347 if (xflag == 2) { /* DECIMAL */
349 * Bound number of words to DECIMAL maximum per line.
357 for (i=0; i<nb; ++i) {
359 fprintf(lfp, "%03u", (*wp++)&0377);
363 * Output blanks if required.
374 /*)Function VOID list2(wpt)
376 * int * wpt pointer to relocation mode
378 * The function list2() outputs the selected
379 * relocation flag as specified by fflag.
382 * int c relocation flag character
383 * int t relocation mode
386 * int fflag -f(f), relocations flagged flag
389 * int putc() c_library
392 * Relocation flag output to listing file.
404 * Designate a relocatable word by `.
412 * Designate a relocatable word by its mode:
415 * operand offset p (q)
416 * relocatable symbol r (s)
420 if (t & (R_PAG0|R_PAG)) {
422 } else if (t & R_USGN) {
424 } else if (t & R_PCR) {
429 if (t & R_HIGH) c += 1;
434 * Output the selected mode.
439 /*)Function VOID slew(fp, flag)
441 * FILE * fp file handle for listing
442 * int flag enable pagination
444 * The function slew() increments the page line count.
445 * If the page overflows and pagination is enabled:
446 * 1) put out a page skip,
449 * 4) and reset the line count.
455 * char cpu[] cpu type string
456 * int lop current line number on page
457 * int page current page number
458 * char stb[] Subtitle string buffer
459 * char tb[] Title string buffer
462 * int fprintf() c_library
465 * Increments page line counter, on overflow
466 * a new page header is output to the listing file.
474 if ((lop++ >= NLPP) && flag) {
475 fprintf(fp, "\fASxxxx Assembler %s (%s), page %u.\n",
476 VERSION, cpu, ++page);
477 fprintf(fp, "%s\n", tb);
478 fprintf(fp, "%s\n\n", stb);
483 /* Used for qsort call in lstsym */
484 static int _cmpSym(const void *p1, const void *p2)
486 struct sym **s1 = (struct sym **)(p1);
487 struct sym **s2 = (struct sym **)(p2);
488 return strcmp((*s1)->s_id,(*s2)->s_id);
491 /*)Function VOID lstsym(fp)
493 * FILE * fp file handle for output
495 * The function lstsym() outputs alphabetically
496 * sorted symbol and area tables.
503 * char * ptr pointer to an id string
504 * int nmsym number of symbols
505 * int narea number of areas
506 * sym * sp pointer to symbol structure
507 * sym ** p pointer to an array of
508 * pointers to symbol structures
509 * area * ap pointer to an area structure
512 * area * areap pointer to an area structure
513 * char aretbl[] string "Area Table"
514 * sym dot defined as sym[0]
515 * char stb[] Subtitle string buffer
516 * sym * symhash[] array of pointers to NHASH
517 * linked symbol lists
518 * char symtbl[] string "Symbol Table"
519 * FILE * tfp symbol table output file handle
520 * int xflag -x, listing radix flag
523 * int fprintf() c_library
524 * int putc() c_library
525 * VOID slew() aslist.c
526 * int strcmp() c_library
527 * char * strcpy() c_library
530 * Symbol and area tables output.
537 register int c, i, j, k;
545 * Symbol Table Header
547 strcpy(stb, &symtbl[0]);
554 * Find number of symbols
557 for (i=0; i<NHASH; i++) {
569 * Allocate space for an array of pointers to symbols
572 if ((p = (struct sym **) malloc(sizeof((struct sym *) sp)*nmsym))
574 fprintf(fp, "Insufficient space to build Symbol Table.\n");
578 for (i=0; i<NHASH; i++) {
588 /* BUBBLE SORT?? WTF??? */
590 * Bubble Sort on Symbol Table Array
596 for (i=0; i<c; ++i) {
597 if (strcmp(&p[i]->s_id[0],&p[i+1]->s_id[0]) > 0) {
607 qsort(p, nmsym, sizeof(struct sym *), _cmpSym);
611 * Symbol Table Output
613 for (i=0; i<nmsym;) {
616 j = sp->s_area->a_ref;
618 fprintf(fp, " %2X ", j);
621 fprintf(fp, "%3o ", j);
624 fprintf(fp, "%3u ", j);
630 fprintf(fp, "%-60s", ptr ); /* JLH */
632 if (sp->s_flag & S_ASG) {
637 if (sp->s_type == S_NEW) {
639 fprintf(fp, " **** ");
642 fprintf(fp, "****** ");
645 fprintf(fp, " ***** ");
650 fprintf(fp, " %04X ", j);
653 fprintf(fp, "%06o ", j);
656 fprintf(fp, " %05u ", j);
660 if (sp->s_flag & S_GBL) {
664 if (sp->s_area != NULL) {
668 if (sp->s_type == S_NEW) {
695 strcpy(stb, &aretbl[0]);
708 for (i=0; i<narea; ++i) {
710 for (j=i+1; j<narea; ++j)
714 fprintf(fp, " %2X ", j);
717 fprintf(fp, " %3o ", j);
720 fprintf(fp, " %3u ", j);
723 while (ptr < &ap->a_id[NCPS]) {
724 if ((c = *ptr++) != 0) {
733 fprintf(fp, " size %4X flags %X\n", j, k);
736 fprintf(fp, " size %6o flags %o\n", j, k);
739 fprintf(fp, " size %5u flags %u\n", j, k);