Commit | Line | Data |
---|---|---|
5d9f0ecf SC |
1 | /* listing.c - mainting assembly listings |
2 | Copyright (C) 1991, 1992 Free Software Foundation, Inc. | |
c593cf41 SC |
3 | |
4 | This file is part of GAS, the GNU Assembler. | |
5 | ||
6 | GAS is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2, or (at your option) | |
9 | any later version. | |
10 | ||
11 | GAS is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GAS; see the file COPYING. If not, write to | |
18 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
5d9f0ecf SC |
19 | |
20 | /* | |
c593cf41 SC |
21 | Contributed by Steve Chamberlain |
22 | sac@cygnus.com | |
23 | ||
24 | ||
25 | A listing page looks like: | |
58d4951d | 26 | |
c593cf41 SC |
27 | LISTING_HEADER sourcefilename pagenumber |
28 | TITLE LINE | |
29 | SUBTITLE LINE | |
30 | linenumber address data source | |
31 | linenumber address data source | |
32 | linenumber address data source | |
33 | linenumber address data source | |
34 | ||
35 | If not overridden, the listing commands are: | |
36 | ||
58d4951d ILT |
37 | .title "stuff" |
38 | Put "stuff" onto the title line | |
c593cf41 SC |
39 | .sbttl "stuff" |
40 | Put stuff onto the subtitle line | |
41 | ||
5d9f0ecf SC |
42 | If these commands come within 10 lines of the top of the page, they |
43 | will affect the page they are on, as well as any subsequent page | |
c593cf41 SC |
44 | |
45 | .eject | |
46 | Thow a page | |
47 | .list | |
48 | Increment the enable listing counter | |
49 | .nolist | |
50 | Decrement the enable listing counter | |
51 | ||
52 | .psize Y[,X] | |
53 | Set the paper size to X wide and Y high. Setting a psize Y of | |
54 | zero will suppress form feeds except where demanded by .eject | |
55 | ||
58d4951d | 56 | If the counter goes below zero, listing is suppressed. |
c593cf41 SC |
57 | |
58 | ||
59 | Listings are a maintained by read calling various listing_<foo> | |
60 | functions. What happens most is that the macro NO_LISTING is not | |
61 | defined (from the Makefile), then the macro LISTING_NEWLINE expands | |
62 | into a call to listing_newline. The call is done from read.c, every | |
63 | time it sees a newline, and -l is on the command line. | |
64 | ||
65 | The function listing_newline remembers the frag associated with the | |
66 | newline, and creates a new frag - note that this is wasteful, but not | |
67 | a big deal, since listing slows things down a lot anyway. The | |
68 | function also rememebers when the filename changes. | |
69 | ||
70 | When all the input has finished, and gas has had a chance to settle | |
71 | down, the listing is output. This is done by running down the list of | |
72 | frag/source file records, and opening the files as needed and printing | |
73 | out the bytes and chars associated with them. | |
74 | ||
75 | The only things which the architecture can change about the listing | |
76 | are defined in these macros: | |
77 | ||
78 | LISTING_HEADER The name of the architecture | |
79 | LISTING_WORD_SIZE The make of the number of bytes in a word, this determines | |
80 | the clumping of the output data. eg a value of | |
81 | 2 makes words look like 1234 5678, whilst 1 | |
82 | would make the same value look like 12 34 56 | |
83 | 78 | |
84 | LISTING_LHS_WIDTH Number of words of above size for the lhs | |
85 | ||
86 | LISTING_LHS_WIDTH_SECOND Number of words for the data on the lhs | |
87 | for the second line | |
88 | ||
89 | LISTING_LHS_CONT_LINES Max number of lines to use up for a continutation | |
90 | LISTING_RHS_WIDTH Number of chars from the input file to print | |
91 | on a line | |
92 | */ | |
5d9f0ecf | 93 | |
58d4951d ILT |
94 | #include <ctype.h> |
95 | ||
5d9f0ecf SC |
96 | #include "as.h" |
97 | #include <obstack.h> | |
98 | #include "input-file.h" | |
e860dfd0 | 99 | #include "subsegs.h" |
7143f43c | 100 | |
5d9f0ecf SC |
101 | #ifndef NO_LISTING |
102 | #ifndef LISTING_HEADER | |
103 | #define LISTING_HEADER "GAS LISTING" | |
104 | #endif | |
105 | #ifndef LISTING_WORD_SIZE | |
106 | #define LISTING_WORD_SIZE 4 | |
107 | #endif | |
108 | #ifndef LISTING_LHS_WIDTH | |
109 | #define LISTING_LHS_WIDTH 1 | |
110 | #endif | |
111 | #ifndef LISTING_LHS_WIDTH_SECOND | |
112 | #define LISTING_LHS_WIDTH_SECOND 1 | |
113 | #endif | |
114 | #ifndef LISTING_RHS_WIDTH | |
115 | #define LISTING_RHS_WIDTH 100 | |
116 | #endif | |
58d4951d | 117 | #ifndef LISTING_LHS_CONT_LINES |
5d9f0ecf SC |
118 | #define LISTING_LHS_CONT_LINES 4 |
119 | #endif | |
120 | ||
121 | ||
c593cf41 SC |
122 | |
123 | ||
b3ca913f | 124 | /* This structure remembers which .s were used */ |
58d4951d | 125 | typedef struct file_info_struct |
c593cf41 SC |
126 | { |
127 | char *filename; | |
128 | int linenum; | |
129 | FILE *file; | |
130 | struct file_info_struct *next; | |
bcaa9b05 | 131 | int at_end; |
58d4951d ILT |
132 | } |
133 | ||
134 | file_info_type; | |
135 | ||
136 | ||
c593cf41 SC |
137 | /* this structure rememebrs which line from which file goes into which |
138 | frag */ | |
139 | typedef struct list_info_struct | |
140 | { | |
141 | /* Frag which this line of source is nearest to */ | |
142 | fragS *frag; | |
143 | /* The actual line in the source file */ | |
144 | unsigned int line; | |
145 | /* Pointer to the file info struct for the file which this line | |
146 | belongs to */ | |
147 | file_info_type *file; | |
148 | ||
149 | /* Next in list */ | |
150 | struct list_info_struct *next; | |
a39116f1 | 151 | |
c593cf41 SC |
152 | |
153 | /* Pointer to the file info struct for the high level language | |
154 | source line that belongs here */ | |
155 | file_info_type *hll_file; | |
58d4951d | 156 | |
c593cf41 SC |
157 | /* High level language source line */ |
158 | int hll_line; | |
58d4951d | 159 | |
c593cf41 SC |
160 | |
161 | /* Pointer to any error message associated with this line */ | |
162 | char *message; | |
58d4951d ILT |
163 | |
164 | enum | |
165 | { | |
166 | EDICT_NONE, | |
167 | EDICT_SBTTL, | |
168 | EDICT_TITLE, | |
169 | EDICT_NOLIST, | |
170 | EDICT_LIST, | |
171 | EDICT_EJECT | |
172 | } edict; | |
c593cf41 | 173 | char *edict_arg; |
58d4951d ILT |
174 | |
175 | } | |
176 | ||
177 | list_info_type; | |
5d9f0ecf | 178 | |
c593cf41 | 179 | |
5d9f0ecf SC |
180 | static struct list_info_struct *head; |
181 | struct list_info_struct *listing_tail; | |
182 | extern int listing; | |
5d9f0ecf SC |
183 | extern fragS *frag_now; |
184 | ||
c593cf41 | 185 | |
5d9f0ecf SC |
186 | static int paper_width = 200; |
187 | static int paper_height = 60; | |
188 | ||
c593cf41 | 189 | |
5d9f0ecf | 190 | /* this static array is used to keep the text of data to be printed |
c593cf41 SC |
191 | before the start of the line. |
192 | It is stored so we can give a bit more info on the next line. To much, and large | |
193 | initialized arrays will use up lots of paper. | |
194 | */ | |
5d9f0ecf SC |
195 | |
196 | static char data_buffer[100]; | |
197 | static unsigned int data_buffer_size; | |
198 | ||
58d4951d ILT |
199 | |
200 | /* Prototypes. */ | |
201 | static void listing_message PARAMS ((const char *name, const char *message)); | |
202 | static file_info_type *file_info PARAMS ((const char *file_name)); | |
203 | static void new_frag PARAMS ((void)); | |
204 | static char *buffer_line PARAMS ((file_info_type *file, | |
205 | char *line, unsigned int size)); | |
206 | static void listing_page PARAMS ((list_info_type *list)); | |
207 | static unsigned int calc_hex PARAMS ((list_info_type *list)); | |
208 | static void print_lines PARAMS ((list_info_type *list, | |
209 | char *string, | |
210 | unsigned int address)); | |
211 | static void list_symbol_table PARAMS ((void)); | |
212 | static void print_source PARAMS ((file_info_type *current_file, | |
213 | list_info_type *list, | |
214 | char *buffer, | |
215 | unsigned int width)); | |
216 | static int debugging_pseudo PARAMS ((char *line)); | |
217 | static void listing_listing PARAMS ((char *name)); | |
218 | ||
219 | ||
5d9f0ecf | 220 | static void |
58d4951d ILT |
221 | listing_message (name, message) |
222 | const char *name; | |
223 | const char *message; | |
c593cf41 | 224 | { |
58d4951d ILT |
225 | unsigned int l = strlen (name) + strlen (message) + 1; |
226 | char *n = (char *) xmalloc (l); | |
227 | strcpy (n, name); | |
228 | strcat (n, message); | |
229 | if (listing_tail != (list_info_type *) NULL) | |
230 | { | |
231 | listing_tail->message = n; | |
232 | } | |
c593cf41 SC |
233 | } |
234 | ||
58d4951d ILT |
235 | void |
236 | listing_warning (message) | |
237 | const char *message; | |
5d9f0ecf | 238 | { |
58d4951d | 239 | listing_message ("Warning:", message); |
5d9f0ecf SC |
240 | } |
241 | ||
58d4951d ILT |
242 | void |
243 | listing_error (message) | |
244 | const char *message; | |
5d9f0ecf | 245 | { |
58d4951d | 246 | listing_message ("Error:", message); |
5d9f0ecf SC |
247 | } |
248 | ||
c593cf41 SC |
249 | |
250 | ||
251 | ||
5d9f0ecf SC |
252 | static file_info_type *file_info_head; |
253 | ||
254 | static file_info_type * | |
58d4951d ILT |
255 | file_info (file_name) |
256 | const char *file_name; | |
5d9f0ecf | 257 | { |
c593cf41 SC |
258 | /* Find an entry with this file name */ |
259 | file_info_type *p = file_info_head; | |
58d4951d ILT |
260 | |
261 | while (p != (file_info_type *) NULL) | |
262 | { | |
263 | if (strcmp (p->filename, file_name) == 0) | |
264 | return p; | |
265 | p = p->next; | |
266 | } | |
c593cf41 SC |
267 | |
268 | /* Make new entry */ | |
269 | ||
58d4951d | 270 | p = (file_info_type *) xmalloc (sizeof (file_info_type)); |
c593cf41 SC |
271 | p->next = file_info_head; |
272 | file_info_head = p; | |
e860dfd0 | 273 | p->filename = xmalloc ((unsigned long) strlen (file_name) + 1); |
58d4951d | 274 | strcpy (p->filename, file_name); |
c593cf41 | 275 | p->linenum = 0; |
bcaa9b05 | 276 | p->at_end = 0; |
7143f43c | 277 | |
f949f7b8 | 278 | p->file = fopen (p->filename, "r"); |
58d4951d ILT |
279 | if (p->file) |
280 | fgetc (p->file); | |
7143f43c | 281 | |
c593cf41 | 282 | return p; |
c593cf41 | 283 | } |
5d9f0ecf SC |
284 | |
285 | ||
58d4951d ILT |
286 | static void |
287 | new_frag () | |
b3ca913f | 288 | { |
58d4951d ILT |
289 | |
290 | frag_wane (frag_now); | |
291 | frag_new (0); | |
c593cf41 | 292 | |
b3ca913f SC |
293 | } |
294 | ||
58d4951d ILT |
295 | void |
296 | listing_newline (ps) | |
297 | char *ps; | |
5d9f0ecf | 298 | { |
e860dfd0 KR |
299 | char *file; |
300 | unsigned int line; | |
58d4951d | 301 | static unsigned int last_line = 0xffff; |
f949f7b8 | 302 | static char *last_file = NULL; |
c593cf41 | 303 | list_info_type *new; |
e860dfd0 KR |
304 | |
305 | as_where (&file, &line); | |
bcaa9b05 | 306 | if (line != last_line || (last_file && file && strcmp(file, last_file))) |
c593cf41 | 307 | { |
e860dfd0 | 308 | last_line = line; |
f949f7b8 | 309 | last_file = file; |
58d4951d ILT |
310 | new_frag (); |
311 | ||
312 | new = (list_info_type *) xmalloc (sizeof (list_info_type)); | |
313 | new->frag = frag_now; | |
e860dfd0 KR |
314 | new->line = line; |
315 | new->file = file_info (file); | |
58d4951d ILT |
316 | |
317 | if (listing_tail) | |
318 | { | |
319 | listing_tail->next = new; | |
320 | } | |
321 | else | |
322 | { | |
323 | head = new; | |
324 | } | |
325 | listing_tail = new; | |
326 | new->next = (list_info_type *) NULL; | |
327 | new->message = (char *) NULL; | |
328 | new->edict = EDICT_NONE; | |
329 | new->hll_file = (file_info_type *) NULL; | |
330 | new->hll_line = 0; | |
331 | new_frag (); | |
c593cf41 | 332 | } |
c593cf41 | 333 | } |
5d9f0ecf | 334 | |
e860dfd0 KR |
335 | /* Attach all current frags to the previous line instead of the |
336 | current line. This is called by the MIPS backend when it discovers | |
337 | that it needs to add some NOP instructions; the added NOP | |
338 | instructions should go with the instruction that has the delay, not | |
339 | with the new instruction. */ | |
340 | ||
341 | void | |
342 | listing_prev_line () | |
343 | { | |
344 | list_info_type *l; | |
345 | fragS *f; | |
346 | ||
347 | if (head == (list_info_type *) NULL | |
348 | || head == listing_tail) | |
349 | return; | |
350 | ||
351 | new_frag (); | |
352 | ||
353 | for (l = head; l->next != listing_tail; l = l->next) | |
354 | ; | |
355 | ||
356 | for (f = frchain_now->frch_root; f != (fragS *) NULL; f = f->fr_next) | |
357 | if (f->line == listing_tail) | |
358 | f->line = l; | |
359 | ||
360 | listing_tail->frag = frag_now; | |
361 | new_frag (); | |
362 | } | |
3340f7e5 | 363 | |
58d4951d | 364 | /* |
c593cf41 SC |
365 | This function returns the next source line from the file supplied, |
366 | truncated to size. It appends a fake line to the end of each input | |
367 | file to make | |
368 | */ | |
5d9f0ecf SC |
369 | |
370 | static char * | |
58d4951d ILT |
371 | buffer_line (file, line, size) |
372 | file_info_type * file; | |
373 | char *line; | |
374 | unsigned int size; | |
5d9f0ecf | 375 | { |
c593cf41 SC |
376 | unsigned int count = 0; |
377 | int c; | |
58d4951d | 378 | |
c593cf41 SC |
379 | char *p = line; |
380 | ||
381 | /* If we couldn't open the file, return an empty line */ | |
bcaa9b05 | 382 | if (file->file == (FILE *) NULL || file->at_end) |
58d4951d ILT |
383 | { |
384 | return ""; | |
385 | } | |
c593cf41 | 386 | |
ab737e51 | 387 | if (file->linenum == 0) |
58d4951d | 388 | rewind (file->file); |
ab737e51 | 389 | |
58d4951d ILT |
390 | c = fgetc (file->file); |
391 | ||
c593cf41 SC |
392 | size -= 1; /* leave room for null */ |
393 | ||
58d4951d ILT |
394 | while (c != EOF && c != '\n') |
395 | { | |
396 | if (count < size) | |
397 | *p++ = c; | |
398 | count++; | |
399 | ||
400 | c = fgetc (file->file); | |
401 | ||
402 | } | |
403 | if (c == EOF) | |
404 | { | |
bcaa9b05 | 405 | file->at_end = 1; |
58d4951d ILT |
406 | *p++ = '.'; |
407 | *p++ = '.'; | |
408 | *p++ = '.'; | |
409 | } | |
410 | file->linenum++; | |
c593cf41 SC |
411 | *p++ = 0; |
412 | return line; | |
413 | } | |
414 | ||
5d9f0ecf | 415 | |
58d4951d | 416 | static const char *fn; |
5d9f0ecf SC |
417 | |
418 | static unsigned int eject; /* Eject pending */ | |
58d4951d ILT |
419 | static unsigned int page; /* Current page number */ |
420 | static char *title; /* current title */ | |
5d9f0ecf | 421 | static char *subtitle; /* current subtitle */ |
58d4951d | 422 | static unsigned int on_page; /* number of lines printed on current page */ |
5d9f0ecf | 423 | |
3340f7e5 | 424 | |
c593cf41 | 425 | static void |
58d4951d ILT |
426 | listing_page (list) |
427 | list_info_type *list; | |
c593cf41 SC |
428 | { |
429 | /* Grope around, see if we can see a title or subtitle edict coming up | |
430 | soon (we look down 10 lines of the page and see if it's there)*/ | |
58d4951d | 431 | if ((eject || (on_page >= paper_height)) && paper_height != 0) |
c593cf41 | 432 | { |
58d4951d ILT |
433 | unsigned int c = 10; |
434 | int had_title = 0; | |
435 | int had_subtitle = 0; | |
c593cf41 | 436 | |
58d4951d ILT |
437 | page++; |
438 | ||
439 | while (c != 0 && list) | |
440 | { | |
441 | if (list->edict == EDICT_SBTTL && !had_subtitle) | |
442 | { | |
443 | had_subtitle = 1; | |
444 | subtitle = list->edict_arg; | |
445 | } | |
446 | if (list->edict == EDICT_TITLE && !had_title) | |
447 | { | |
448 | had_title = 1; | |
449 | title = list->edict_arg; | |
450 | } | |
451 | list = list->next; | |
452 | c--; | |
453 | } | |
454 | ||
455 | ||
456 | if (page > 1) | |
457 | { | |
458 | printf ("\f"); | |
459 | } | |
460 | ||
461 | printf ("%s %s \t\t\tpage %d\n", LISTING_HEADER, fn, page); | |
462 | printf ("%s\n", title); | |
463 | printf ("%s\n", subtitle); | |
464 | on_page = 3; | |
465 | eject = 0; | |
c593cf41 | 466 | } |
c593cf41 | 467 | } |
5d9f0ecf SC |
468 | |
469 | ||
58d4951d ILT |
470 | static unsigned int |
471 | calc_hex (list) | |
472 | list_info_type * list; | |
5d9f0ecf | 473 | { |
c593cf41 | 474 | list_info_type *first = list; |
e860dfd0 | 475 | unsigned int address = (unsigned int) ~0; |
58d4951d | 476 | |
c593cf41 SC |
477 | fragS *frag; |
478 | fragS *frag_ptr; | |
479 | ||
e860dfd0 | 480 | unsigned int byte_in_frag; |
58d4951d | 481 | |
c593cf41 SC |
482 | |
483 | /* Find first frag which says it belongs to this line */ | |
58d4951d ILT |
484 | frag = list->frag; |
485 | while (frag && frag->line != list) | |
486 | frag = frag->fr_next; | |
c593cf41 SC |
487 | |
488 | frag_ptr = frag; | |
489 | ||
490 | data_buffer_size = 0; | |
58d4951d | 491 | |
c593cf41 | 492 | /* Dump all the frags which belong to this line */ |
58d4951d | 493 | while (frag_ptr != (fragS *) NULL && frag_ptr->line == first) |
c593cf41 | 494 | { |
58d4951d | 495 | /* Print as many bytes from the fixed part as is sensible */ |
e860dfd0 | 496 | byte_in_frag = 0; |
58d4951d ILT |
497 | while (byte_in_frag < frag_ptr->fr_fix && data_buffer_size < sizeof (data_buffer) - 10) |
498 | { | |
499 | if (address == ~0) | |
500 | { | |
501 | address = frag_ptr->fr_address; | |
502 | } | |
503 | ||
504 | sprintf (data_buffer + data_buffer_size, | |
505 | "%02X", | |
506 | (frag_ptr->fr_literal[byte_in_frag]) & 0xff); | |
507 | data_buffer_size += 2; | |
508 | byte_in_frag++; | |
509 | } | |
c593cf41 | 510 | { |
58d4951d ILT |
511 | unsigned int var_rep_max = byte_in_frag; |
512 | unsigned int var_rep_idx = byte_in_frag; | |
513 | ||
514 | /* Print as many bytes from the variable part as is sensible */ | |
515 | while (byte_in_frag < frag_ptr->fr_var * frag_ptr->fr_offset | |
516 | && data_buffer_size < sizeof (data_buffer) - 10) | |
517 | { | |
518 | if (address == ~0) | |
519 | { | |
520 | address = frag_ptr->fr_address; | |
521 | } | |
522 | sprintf (data_buffer + data_buffer_size, | |
523 | "%02X", | |
524 | (frag_ptr->fr_literal[var_rep_idx]) & 0xff); | |
525 | #if 0 | |
526 | data_buffer[data_buffer_size++] = '*'; | |
527 | data_buffer[data_buffer_size++] = '*'; | |
c593cf41 | 528 | #endif |
58d4951d ILT |
529 | data_buffer_size += 2; |
530 | ||
531 | var_rep_idx++; | |
532 | byte_in_frag++; | |
533 | ||
534 | if (var_rep_idx >= frag_ptr->fr_var) | |
535 | var_rep_idx = var_rep_max; | |
536 | } | |
537 | } | |
538 | ||
539 | frag_ptr = frag_ptr->fr_next; | |
c593cf41 | 540 | } |
c593cf41 SC |
541 | data_buffer[data_buffer_size++] = 0; |
542 | return address; | |
543 | } | |
544 | ||
545 | ||
546 | ||
547 | ||
548 | ||
5d9f0ecf SC |
549 | |
550 | static void | |
58d4951d ILT |
551 | print_lines (list, string, address) |
552 | list_info_type *list; | |
553 | char *string; | |
554 | unsigned int address; | |
c593cf41 SC |
555 | { |
556 | unsigned int idx; | |
557 | unsigned int nchars; | |
558 | unsigned int lines; | |
58d4951d | 559 | unsigned int byte_in_word = 0; |
c593cf41 | 560 | char *src = data_buffer; |
58d4951d | 561 | |
c593cf41 | 562 | /* Print the stuff on the first line */ |
58d4951d ILT |
563 | listing_page (list); |
564 | nchars = (LISTING_WORD_SIZE * 2 + 1) * LISTING_LHS_WIDTH; | |
c593cf41 | 565 | /* Print the hex for the first line */ |
58d4951d | 566 | if (address == ~0) |
c593cf41 | 567 | { |
58d4951d ILT |
568 | printf ("% 4d ", list->line); |
569 | for (idx = 0; idx < nchars; idx++) | |
570 | printf (" "); | |
571 | ||
572 | printf ("\t%s\n", string ? string : ""); | |
c593cf41 | 573 | on_page++; |
58d4951d ILT |
574 | listing_page (0); |
575 | ||
c593cf41 | 576 | } |
58d4951d ILT |
577 | else |
578 | { | |
579 | if (had_errors ()) | |
580 | { | |
581 | printf ("% 4d ???? ", list->line); | |
582 | } | |
583 | else | |
584 | { | |
585 | printf ("% 4d %04x ", list->line, address); | |
586 | } | |
c593cf41 | 587 | |
58d4951d ILT |
588 | /* And the data to go along with it */ |
589 | idx = 0; | |
590 | ||
591 | while (*src && idx < nchars) | |
c593cf41 | 592 | { |
58d4951d ILT |
593 | printf ("%c%c", src[0], src[1]); |
594 | src += 2; | |
c593cf41 | 595 | byte_in_word++; |
58d4951d ILT |
596 | if (byte_in_word == LISTING_WORD_SIZE) |
597 | { | |
598 | printf (" "); | |
599 | idx++; | |
600 | byte_in_word = 0; | |
601 | } | |
602 | idx += 2; | |
c593cf41 | 603 | } |
c593cf41 | 604 | |
58d4951d ILT |
605 | for (; idx < nchars; idx++) |
606 | printf (" "); | |
607 | ||
608 | printf ("\t%s\n", string ? string : ""); | |
609 | on_page++; | |
610 | listing_page (list); | |
611 | if (list->message) | |
612 | { | |
613 | printf ("**** %s\n", list->message); | |
614 | listing_page (list); | |
615 | on_page++; | |
616 | } | |
c593cf41 | 617 | |
58d4951d ILT |
618 | for (lines = 0; |
619 | lines < LISTING_LHS_CONT_LINES | |
620 | && *src; | |
621 | lines++) | |
622 | { | |
623 | nchars = ((LISTING_WORD_SIZE * 2) + 1) * LISTING_LHS_WIDTH_SECOND - 1; | |
624 | idx = 0; | |
625 | /* Print any more lines of data, but more compactly */ | |
626 | printf ("% 4d ", list->line); | |
627 | ||
628 | while (*src && idx < nchars) | |
629 | { | |
630 | printf ("%c%c", src[0], src[1]); | |
631 | src += 2; | |
632 | idx += 2; | |
633 | byte_in_word++; | |
634 | if (byte_in_word == LISTING_WORD_SIZE) | |
635 | { | |
636 | printf (" "); | |
637 | idx++; | |
638 | byte_in_word = 0; | |
639 | } | |
640 | } | |
641 | ||
642 | printf ("\n"); | |
643 | on_page++; | |
644 | listing_page (list); | |
645 | ||
646 | } | |
647 | ||
648 | ||
649 | } | |
650 | } | |
5d9f0ecf SC |
651 | |
652 | ||
653 | static void | |
58d4951d | 654 | list_symbol_table () |
5d9f0ecf | 655 | { |
c593cf41 | 656 | extern symbolS *symbol_rootP; |
f949f7b8 | 657 | int got_some = 0; |
58d4951d ILT |
658 | |
659 | symbolS *ptr; | |
c593cf41 | 660 | eject = 1; |
58d4951d | 661 | listing_page (0); |
58d4951d ILT |
662 | |
663 | for (ptr = symbol_rootP; ptr != (symbolS *) NULL; ptr = symbol_next (ptr)) | |
c593cf41 | 664 | { |
58d4951d ILT |
665 | if (ptr->sy_frag->line) |
666 | { | |
667 | if (S_GET_NAME (ptr)) | |
668 | { | |
f949f7b8 | 669 | char buf[30], fmt[8]; |
58d4951d ILT |
670 | valueT val = S_GET_VALUE (ptr); |
671 | ||
672 | /* @@ Note that this is dependent on the compilation options, | |
673 | not solely on the target characteristics. */ | |
674 | if (sizeof (val) == 4 && sizeof (int) == 4) | |
675 | sprintf (buf, "%08lx", (unsigned long) val); | |
f949f7b8 KR |
676 | else if (sizeof (val) <= sizeof (unsigned long)) |
677 | { | |
bcaa9b05 ILT |
678 | sprintf (fmt, "%%0%lulx", |
679 | (unsigned long) (sizeof (val) * 2)); | |
f949f7b8 KR |
680 | sprintf (buf, fmt, (unsigned long) val); |
681 | } | |
682 | #if defined (BFD64) | |
58d4951d ILT |
683 | else if (sizeof (val) > 4) |
684 | { | |
685 | char buf1[30]; | |
686 | sprintf_vma (buf1, val); | |
687 | strcpy (buf, "00000000"); | |
688 | strcpy (buf + 8 - strlen (buf1), buf1); | |
689 | } | |
690 | #endif | |
691 | else | |
692 | abort (); | |
693 | ||
f949f7b8 KR |
694 | if (!got_some) |
695 | { | |
696 | printf ("DEFINED SYMBOLS\n"); | |
697 | on_page++; | |
698 | got_some = 1; | |
699 | } | |
700 | ||
58d4951d ILT |
701 | printf ("%20s:%-5d %s:%s %s\n", |
702 | ptr->sy_frag->line->file->filename, | |
703 | ptr->sy_frag->line->line, | |
704 | segment_name (S_GET_SEGMENT (ptr)), | |
705 | buf, S_GET_NAME (ptr)); | |
706 | ||
707 | on_page++; | |
708 | listing_page (0); | |
709 | } | |
710 | } | |
c593cf41 | 711 | |
c593cf41 | 712 | } |
f949f7b8 KR |
713 | if (!got_some) |
714 | { | |
715 | printf ("NO DEFINED SYMBOLS\n"); | |
716 | on_page++; | |
717 | } | |
58d4951d | 718 | printf ("\n"); |
c593cf41 | 719 | on_page++; |
58d4951d | 720 | listing_page (0); |
f949f7b8 KR |
721 | |
722 | got_some = 0; | |
58d4951d ILT |
723 | |
724 | for (ptr = symbol_rootP; ptr != (symbolS *) NULL; ptr = symbol_next (ptr)) | |
c593cf41 | 725 | { |
58d4951d ILT |
726 | if (S_GET_NAME (ptr) && strlen (S_GET_NAME (ptr)) != 0) |
727 | { | |
e860dfd0 | 728 | if (ptr->sy_frag->line == 0 |
f949f7b8 KR |
729 | #ifdef S_IS_REGISTER |
730 | && !S_IS_REGISTER (ptr) | |
731 | #endif | |
e860dfd0 | 732 | && S_GET_SEGMENT (ptr) != reg_section) |
58d4951d | 733 | { |
f949f7b8 KR |
734 | if (!got_some) |
735 | { | |
736 | got_some = 1; | |
737 | printf ("UNDEFINED SYMBOLS\n"); | |
738 | on_page++; | |
739 | listing_page (0); | |
740 | } | |
58d4951d ILT |
741 | printf ("%s\n", S_GET_NAME (ptr)); |
742 | on_page++; | |
743 | listing_page (0); | |
744 | } | |
745 | } | |
c593cf41 | 746 | } |
f949f7b8 KR |
747 | if (!got_some) |
748 | { | |
749 | printf ("NO UNDEFINED SYMBOLS\n"); | |
750 | on_page++; | |
751 | listing_page (0); | |
752 | } | |
c593cf41 | 753 | } |
5d9f0ecf | 754 | |
58d4951d ILT |
755 | static void |
756 | print_source (current_file, list, buffer, width) | |
757 | file_info_type *current_file; | |
758 | list_info_type *list; | |
759 | char *buffer; | |
760 | unsigned int width; | |
c593cf41 | 761 | { |
58d4951d ILT |
762 | if (current_file->file) |
763 | { | |
f949f7b8 | 764 | while (current_file->linenum < list->hll_line |
bcaa9b05 | 765 | && !current_file->at_end) |
58d4951d ILT |
766 | { |
767 | char *p = buffer_line (current_file, buffer, width); | |
768 | printf ("%4d:%-13s **** %s\n", current_file->linenum, current_file->filename, p); | |
769 | on_page++; | |
770 | listing_page (list); | |
771 | } | |
c593cf41 SC |
772 | } |
773 | } | |
b3ca913f | 774 | |
a39116f1 | 775 | /* Sometimes the user doesn't want to be bothered by the debugging |
58d4951d | 776 | records inserted by the compiler, see if the line is suspicious */ |
5d9f0ecf | 777 | |
a39116f1 | 778 | static int |
58d4951d ILT |
779 | debugging_pseudo (line) |
780 | char *line; | |
a39116f1 | 781 | { |
58d4951d ILT |
782 | while (isspace (*line)) |
783 | line++; | |
784 | ||
785 | if (*line != '.') | |
786 | return 0; | |
c593cf41 | 787 | |
c593cf41 SC |
788 | line++; |
789 | ||
58d4951d ILT |
790 | if (strncmp (line, "def", 3) == 0) |
791 | return 1; | |
792 | if (strncmp (line, "val", 3) == 0) | |
793 | return 1; | |
794 | if (strncmp (line, "scl", 3) == 0) | |
795 | return 1; | |
796 | if (strncmp (line, "line", 4) == 0) | |
797 | return 1; | |
798 | if (strncmp (line, "endef", 5) == 0) | |
799 | return 1; | |
800 | if (strncmp (line, "ln", 2) == 0) | |
801 | return 1; | |
802 | if (strncmp (line, "type", 4) == 0) | |
803 | return 1; | |
804 | if (strncmp (line, "size", 4) == 0) | |
805 | return 1; | |
806 | if (strncmp (line, "dim", 3) == 0) | |
807 | return 1; | |
808 | if (strncmp (line, "tag", 3) == 0) | |
809 | return 1; | |
810 | ||
811 | if (strncmp (line, "stabs", 5) == 0) | |
812 | return 1; | |
813 | if (strncmp (line, "stabn", 5) == 0) | |
814 | return 1; | |
815 | ||
c593cf41 SC |
816 | return 0; |
817 | ||
818 | } | |
5d9f0ecf | 819 | |
58d4951d ILT |
820 | static void |
821 | listing_listing (name) | |
822 | char *name; | |
c593cf41 SC |
823 | { |
824 | list_info_type *list = head; | |
58d4951d | 825 | file_info_type *current_hll_file = (file_info_type *) NULL; |
c593cf41 SC |
826 | char *message; |
827 | char *buffer; | |
828 | char *p; | |
c593cf41 SC |
829 | int show_listing = 1; |
830 | unsigned int width; | |
58d4951d ILT |
831 | |
832 | buffer = xmalloc (LISTING_RHS_WIDTH); | |
c593cf41 SC |
833 | eject = 1; |
834 | list = head; | |
835 | ||
58d4951d ILT |
836 | while (list != (list_info_type *) NULL && 0) |
837 | { | |
838 | if (list->next) | |
839 | list->frag = list->next->frag; | |
840 | list = list->next; | |
841 | ||
842 | } | |
c593cf41 | 843 | |
c593cf41 SC |
844 | list = head->next; |
845 | ||
846 | ||
58d4951d | 847 | while (list) |
c593cf41 | 848 | { |
58d4951d ILT |
849 | width = LISTING_RHS_WIDTH > paper_width ? paper_width : |
850 | LISTING_RHS_WIDTH; | |
c593cf41 | 851 | |
58d4951d ILT |
852 | switch (list->edict) |
853 | { | |
854 | case EDICT_LIST: | |
855 | show_listing++; | |
856 | break; | |
857 | case EDICT_NOLIST: | |
858 | show_listing--; | |
859 | break; | |
860 | case EDICT_EJECT: | |
861 | break; | |
862 | case EDICT_NONE: | |
863 | break; | |
864 | case EDICT_TITLE: | |
865 | title = list->edict_arg; | |
866 | break; | |
867 | case EDICT_SBTTL: | |
868 | subtitle = list->edict_arg; | |
869 | break; | |
870 | default: | |
871 | abort (); | |
872 | } | |
c593cf41 | 873 | |
58d4951d ILT |
874 | if (show_listing > 0) |
875 | { | |
876 | /* Scan down the list and print all the stuff which can be done | |
877 | with this line (or lines). */ | |
878 | message = 0; | |
879 | ||
880 | if (list->hll_file) | |
881 | { | |
882 | current_hll_file = list->hll_file; | |
883 | } | |
884 | ||
885 | if (current_hll_file && list->hll_line && listing & LISTING_HLL) | |
886 | { | |
887 | print_source (current_hll_file, list, buffer, width); | |
888 | } | |
889 | ||
f949f7b8 KR |
890 | while (list->file->file |
891 | && list->file->linenum < list->line | |
bcaa9b05 | 892 | && !list->file->at_end) |
58d4951d | 893 | { |
f949f7b8 KR |
894 | p = buffer_line (list->file, buffer, width); |
895 | ||
896 | if (!((listing & LISTING_NODEBUG) && debugging_pseudo (p))) | |
897 | { | |
898 | print_lines (list, p, calc_hex (list)); | |
899 | } | |
58d4951d ILT |
900 | } |
901 | ||
902 | if (list->edict == EDICT_EJECT) | |
903 | { | |
904 | eject = 1; | |
905 | } | |
906 | } | |
907 | else | |
908 | { | |
f949f7b8 KR |
909 | while (list->file->file |
910 | && list->file->linenum < list->line | |
bcaa9b05 | 911 | && !list->file->at_end) |
f949f7b8 | 912 | p = buffer_line (list->file, buffer, width); |
58d4951d | 913 | } |
c593cf41 | 914 | |
58d4951d | 915 | list = list->next; |
c593cf41 | 916 | } |
58d4951d | 917 | free (buffer); |
c593cf41 | 918 | } |
5d9f0ecf | 919 | |
58d4951d ILT |
920 | void |
921 | listing_print (name) | |
922 | char *name; | |
5d9f0ecf | 923 | { |
c593cf41 | 924 | title = ""; |
58d4951d ILT |
925 | subtitle = ""; |
926 | ||
927 | if (listing & LISTING_NOFORM) | |
928 | { | |
929 | paper_height = 0; | |
930 | } | |
931 | ||
932 | if (listing & LISTING_LISTING) | |
933 | { | |
934 | listing_listing (name); | |
935 | ||
936 | } | |
937 | if (listing & LISTING_SYMBOLS) | |
938 | { | |
939 | list_symbol_table (); | |
940 | } | |
941 | } | |
5d9f0ecf SC |
942 | |
943 | ||
944 | void | |
58d4951d ILT |
945 | listing_file (name) |
946 | const char *name; | |
5d9f0ecf | 947 | { |
58d4951d | 948 | fn = name; |
5d9f0ecf SC |
949 | } |
950 | ||
58d4951d | 951 | void |
e860dfd0 KR |
952 | listing_eject (ignore) |
953 | int ignore; | |
5d9f0ecf | 954 | { |
58d4951d | 955 | listing_tail->edict = EDICT_EJECT; |
5d9f0ecf SC |
956 | } |
957 | ||
958 | void | |
e860dfd0 KR |
959 | listing_flags (ignore) |
960 | int ignore; | |
5d9f0ecf | 961 | { |
58d4951d ILT |
962 | while ((*input_line_pointer++) && (*input_line_pointer != '\n')) |
963 | input_line_pointer++; | |
964 | ||
c593cf41 | 965 | } |
58d4951d | 966 | |
c593cf41 | 967 | void |
58d4951d | 968 | listing_list (on) |
e860dfd0 | 969 | int on; |
c593cf41 SC |
970 | { |
971 | listing_tail->edict = on ? EDICT_LIST : EDICT_NOLIST; | |
5d9f0ecf | 972 | } |
3340f7e5 | 973 | |
c593cf41 | 974 | |
5d9f0ecf | 975 | void |
e860dfd0 KR |
976 | listing_psize (ignore) |
977 | int ignore; | |
5d9f0ecf | 978 | { |
58d4951d | 979 | paper_height = get_absolute_expression (); |
c593cf41 | 980 | |
58d4951d ILT |
981 | if (paper_height < 0 || paper_height > 1000) |
982 | { | |
983 | paper_height = 0; | |
984 | as_warn ("strange paper height, set to no form"); | |
985 | } | |
986 | if (*input_line_pointer == ',') | |
987 | { | |
988 | input_line_pointer++; | |
989 | paper_width = get_absolute_expression (); | |
990 | } | |
5d9f0ecf SC |
991 | } |
992 | ||
993 | ||
994 | void | |
58d4951d | 995 | listing_title (depth) |
e860dfd0 | 996 | int depth; |
a39116f1 | 997 | { |
c593cf41 | 998 | char *start; |
e860dfd0 | 999 | char *ttl; |
c593cf41 | 1000 | unsigned int length; |
58d4951d ILT |
1001 | |
1002 | SKIP_WHITESPACE (); | |
1003 | if (*input_line_pointer == '\"') | |
1004 | { | |
c593cf41 SC |
1005 | input_line_pointer++; |
1006 | start = input_line_pointer; | |
58d4951d ILT |
1007 | |
1008 | while (*input_line_pointer) | |
c593cf41 | 1009 | { |
58d4951d ILT |
1010 | if (*input_line_pointer == '\"') |
1011 | { | |
1012 | length = input_line_pointer - start; | |
e860dfd0 KR |
1013 | ttl = xmalloc (length + 1); |
1014 | memcpy (ttl, start, length); | |
1015 | ttl[length] = 0; | |
58d4951d | 1016 | listing_tail->edict = depth ? EDICT_SBTTL : EDICT_TITLE; |
e860dfd0 | 1017 | listing_tail->edict_arg = ttl; |
58d4951d ILT |
1018 | input_line_pointer++; |
1019 | demand_empty_rest_of_line (); | |
1020 | return; | |
1021 | } | |
1022 | else if (*input_line_pointer == '\n') | |
1023 | { | |
1024 | as_bad ("New line in title"); | |
1025 | demand_empty_rest_of_line (); | |
1026 | return; | |
1027 | } | |
1028 | else | |
1029 | { | |
1030 | input_line_pointer++; | |
1031 | } | |
c593cf41 | 1032 | } |
c593cf41 | 1033 | } |
58d4951d ILT |
1034 | else |
1035 | { | |
1036 | as_bad ("expecting title in quotes"); | |
1037 | } | |
c593cf41 SC |
1038 | } |
1039 | ||
5d9f0ecf SC |
1040 | |
1041 | ||
1042 | void | |
58d4951d ILT |
1043 | listing_source_line (line) |
1044 | unsigned int line; | |
5d9f0ecf | 1045 | { |
58d4951d | 1046 | new_frag (); |
c593cf41 | 1047 | listing_tail->hll_line = line; |
58d4951d ILT |
1048 | new_frag (); |
1049 | ||
c593cf41 | 1050 | } |
5d9f0ecf | 1051 | |
c593cf41 | 1052 | void |
58d4951d ILT |
1053 | listing_source_file (file) |
1054 | const char *file; | |
c593cf41 | 1055 | { |
e860dfd0 KR |
1056 | if (listing_tail) |
1057 | listing_tail->hll_file = file_info (file); | |
c593cf41 | 1058 | } |
5d9f0ecf | 1059 | |
b3ca913f | 1060 | |
58d4951d | 1061 | |
c593cf41 SC |
1062 | #else |
1063 | ||
1064 | ||
1065 | /* Dummy functions for when compiled without listing enabled */ | |
1066 | ||
58d4951d | 1067 | void |
e860dfd0 KR |
1068 | listing_flags (ignore) |
1069 | int ignore; | |
c593cf41 | 1070 | { |
58d4951d | 1071 | s_ignore (0); |
c593cf41 SC |
1072 | } |
1073 | ||
58d4951d ILT |
1074 | void |
1075 | listing_list (on) | |
e860dfd0 | 1076 | int on; |
b3ca913f | 1077 | { |
58d4951d | 1078 | s_ignore (0); |
c593cf41 SC |
1079 | } |
1080 | ||
58d4951d | 1081 | void |
e860dfd0 KR |
1082 | listing_eject (ignore) |
1083 | int ignore; | |
c593cf41 | 1084 | { |
58d4951d | 1085 | s_ignore (0); |
c593cf41 | 1086 | } |
58d4951d ILT |
1087 | |
1088 | void | |
e860dfd0 KR |
1089 | listing_psize (ignore) |
1090 | int ignore; | |
c593cf41 | 1091 | { |
58d4951d | 1092 | s_ignore (0); |
c593cf41 | 1093 | } |
b3ca913f | 1094 | |
58d4951d ILT |
1095 | void |
1096 | listing_title (depth) | |
e860dfd0 | 1097 | int depth; |
c593cf41 | 1098 | { |
58d4951d | 1099 | s_ignore (0); |
c593cf41 | 1100 | } |
58d4951d | 1101 | |
b3ca913f | 1102 | void |
58d4951d ILT |
1103 | listing_file (name) |
1104 | const char *name; | |
b3ca913f | 1105 | { |
c593cf41 SC |
1106 | |
1107 | } | |
1108 | ||
58d4951d ILT |
1109 | void |
1110 | listing_newline (name) | |
1111 | char *name; | |
c593cf41 | 1112 | { |
58d4951d | 1113 | |
b3ca913f SC |
1114 | } |
1115 | ||
58d4951d ILT |
1116 | void |
1117 | listing_source_line (n) | |
1118 | unsigned int n; | |
c593cf41 | 1119 | { |
58d4951d | 1120 | |
c593cf41 | 1121 | } |
58d4951d ILT |
1122 | void |
1123 | listing_source_file (n) | |
1124 | const char *n; | |
c593cf41 | 1125 | { |
c593cf41 | 1126 | |
58d4951d | 1127 | } |
c593cf41 SC |
1128 | |
1129 | #endif |