OSDN Git Service

* ps.cc (prog_name): New global variable.
[pf3gnuchains/pf3gnuchains3x.git] / utils / amd-udi / mondfe / dump.c
1 static char _[] = " @(#)dump.c  5.20 93/07/30 16:38:27, Srini, AMD ";
2 /******************************************************************************
3  * Copyright 1991 Advanced Micro Devices, Inc.
4  *
5  * This software is the property of Advanced Micro Devices, Inc  (AMD)  which
6  * specifically  grants the user the right to modify, use and distribute this
7  * software provided this notice is not removed or altered.  All other rights
8  * are reserved by AMD.
9  *
10  * AMD MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS
11  * SOFTWARE.  IN NO EVENT SHALL AMD BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL
12  * DAMAGES IN CONNECTION WITH OR ARISING FROM THE FURNISHING, PERFORMANCE, OR
13  * USE OF THIS SOFTWARE.
14  *
15  * So that all may benefit from your experience, please report  any  problems
16  * or  suggestions about this software to the 29K Technical Support Center at
17  * 800-29-29-AMD (800-292-9263) in the USA, or 0800-89-1131  in  the  UK,  or
18  * 0031-11-1129 in Japan, toll free.  The direct dial number is 512-462-4118.
19  *
20  * Advanced Micro Devices, Inc.
21  * 29K Support Products
22  * Mail Stop 573
23  * 5900 E. Ben White Blvd.
24  * Austin, TX 78741
25  * 800-292-9263
26  *****************************************************************************
27  *      Engineer: Srini Subramanian.
28  *****************************************************************************
29  ** 
30  **       This code provides dump routines to output data in
31  **       hex / ASCII formats. 
32  **
33  *****************************************************************************
34  */
35
36 #include <stdio.h>
37 #include <ctype.h>
38 #include <memory.h>
39 #include "main.h"
40 #include "macros.h"
41 #include "monitor.h"
42 #include "miniint.h"
43 #include "memspcs.h"
44 #include "error.h"
45
46
47 #ifdef MSDOS
48 #include <stdlib.h>
49 #include <string.h>
50 #else
51 #include <string.h>
52 #endif
53
54 int   get_addr_29k PARAMS((char *, struct addr_29k_t *));
55 int   addr_29k_ok PARAMS((struct addr_29k_t *));
56 int   print_addr_29k PARAMS((INT32, ADDR32));
57
58 int   dump_mem_word PARAMS((INT32 mspace, ADDR32 addr, INT32 bytes, BYTE *buf));
59 int   dump_reg_word PARAMS((INT32 mspace, ADDR32 addr, INT32 bytes, BYTE *buf));
60 int   dump_mem_half PARAMS((INT32 mspace, ADDR32 addr, INT32 bytes, BYTE *buf));
61 int   dump_reg_half PARAMS((INT32 mspace, ADDR32 addr, INT32 bytes, BYTE *buf));
62 int   dump_mem_byte PARAMS((INT32 mspace, ADDR32 addr, INT32 bytes, BYTE *buf));
63 int   dump_reg_byte PARAMS((INT32 mspace, ADDR32 addr, INT32 bytes, BYTE *buf));
64 int   dump_mem_float PARAMS((INT32 mspace, ADDR32 addr, INT32 bytes, BYTE *buf));
65 int   dump_reg_float PARAMS((INT32 mspace, ADDR32 addr, INT32 bytes, BYTE *buf));
66 int   dump_mem_double PARAMS((INT32 mspace, ADDR32 addr, INT32 bytes, BYTE *buf));
67 int   dump_reg_double PARAMS((INT32 mspace, ADDR32 addr, INT32 bytes, BYTE *buf));
68
69 int   get_data PARAMS((BYTE *, BYTE *, int));
70 int   dump_ASCII PARAMS((char *, int, BYTE *, int));
71
72
73 /*
74 ** The function below is used in dumping data.  This function is
75 ** called in the main command loop parser of the monitor.  The
76 ** parameters passed to this function are:
77 **
78 ** token - This is an array of pointers to strings.  Each string
79 **         referenced by this array is a "token" of the user's
80 **         input, translated to lower case.
81 **
82 ** token_count - This is the number of tokens in "token".
83 **
84 ** This function reduces the tokens to three parameters:
85 ** memory_space, address and byte_count.  The address parameter is
86 ** aligned as follows:
87 **
88 **    - All register accesses are byte aligned.  The address,
89 **      however, accesses 32 bit words.  The valued in these
90 **      registers are displayed in formats determined by the
91 **      first token.
92 **
93 **    - Memory addresses are aligned and displayed according
94 **      to the dump format as specified in the first token.
95 ** 
96 **
97 */
98
99
100 INT32
101 dump_cmd(token, token_count)
102    char   *token[];
103    int     token_count;
104    {
105    static INT32  memory_space=D_MEM;
106    static ADDR32 address=0;
107    INT32  byte_count=64;
108    int    result;
109    struct addr_29k_t addr_29k_start;
110    struct addr_29k_t addr_29k_end;
111    int    dump_format;
112    int    object_size;
113    ADDR32 align_mask;
114
115    INT32        retval;
116    INT32        hostendian;
117    INT32        bytes_returned;
118    BYTE         *read_buffer;
119
120    /*
121    ** What is the dump format?
122    */
123
124    if ((strcmp(token[0], "d") == 0) ||
125        (strcmp(token[0], "dw") == 0)) {
126       dump_format = WORD_FORMAT;
127       object_size = sizeof(INT32);
128       align_mask = 0xfffffffc;
129       }
130    else
131    if (strcmp(token[0], "dh") == 0) {
132       dump_format = HALF_FORMAT;
133       object_size = sizeof(INT16);
134       align_mask = 0xfffffffe;
135       }
136    else
137    if (strcmp(token[0], "db") == 0) {
138       dump_format = BYTE_FORMAT;
139       object_size = sizeof(BYTE);
140       align_mask = 0xffffffff;
141       }
142    else
143    if (strcmp(token[0], "df") == 0) {
144       dump_format = FLOAT_FORMAT;
145       object_size = sizeof(float);
146       align_mask = 0xfffffffc;
147       }
148    else
149    if (strcmp(token[0], "dd") == 0) {
150       dump_format = DOUBLE_FORMAT;
151       object_size = sizeof(double);
152       align_mask = 0xfffffff8;
153       }
154    else
155       return(EMSYNTAX);
156
157    /*
158    ** Get start address and byte count
159    */
160
161    if (token_count == 1) {
162       if (ISREG(memory_space))
163          address = address + (byte_count/4);
164       else
165       if (ISMEM(memory_space))
166          address = address + byte_count;
167       else
168          return(EMBADADDR);
169       /* Check the start address */
170       addr_29k_start.address = address;
171       addr_29k_start.memory_space = memory_space;
172       result = addr_29k_ok(&addr_29k_start);
173       if (result != 0)
174          return (result);
175       }
176    else
177    if (token_count == 2) {
178       result = get_addr_29k(token[1], &addr_29k_start);
179       if (result != 0)
180          return (EMSYNTAX);
181       /* Check the start address */
182       result = addr_29k_ok(&addr_29k_start);
183       if (result != 0)
184          return (result);
185
186       memory_space = addr_29k_start.memory_space;
187       /* Make sure we have an even multiple of object_size */
188       if (ISREG(memory_space)) {
189          address = addr_29k_start.address;
190          byte_count = (byte_count + (object_size - 1)) & 0xfffffffc;
191          }
192       else
193       if (ISMEM(memory_space)) {
194          address = addr_29k_start.address & align_mask;
195          byte_count = (byte_count + (object_size - 1)) & align_mask;
196          }
197       else
198          return(EMBADADDR);
199       }
200    else
201    if (token_count == 3) {
202       result = get_addr_29k(token[1], &addr_29k_start);
203       if (result != 0)
204          return (EMSYNTAX);
205       /* Only check the start address */
206       result = addr_29k_ok(&addr_29k_start);
207       if (result != 0)
208          return (result);
209       result = get_addr_29k(token[2], &addr_29k_end);
210       if (result != 0)
211          return (EMSYNTAX);
212
213       if (addr_29k_start.memory_space != addr_29k_end.memory_space)
214          return (EMBADADDR);
215       if (addr_29k_start.address > addr_29k_end.address)
216          return (EMBADADDR);
217
218       memory_space = addr_29k_start.memory_space;
219       if (ISREG(memory_space)) {
220          address = addr_29k_start.address;
221          byte_count = (addr_29k_end.address -
222                        addr_29k_start.address + 1) * 4;
223          }
224       else
225       if (ISMEM(memory_space)) {
226          address = addr_29k_start.address & align_mask;
227          byte_count = ((addr_29k_end.address & align_mask) -
228                        (addr_29k_start.address & align_mask) +
229                       object_size);
230          }
231       else
232          return(EMBADADDR);
233
234       }
235    else
236    /* Too many args */
237       return (EMSYNTAX);
238
239
240    /*
241    ** Get data
242    */
243
244    /* Will the data overflow the message buffer? Done by TIP ??*/
245    if ((read_buffer = (BYTE *) malloc((unsigned int) byte_count)) == NULL) {
246        warning(EMALLOC);
247        return(FAILURE);
248    };
249
250    hostendian = FALSE;
251    if ((retval = Mini_read_req(memory_space,
252                                 address,
253                                 byte_count / object_size,
254                                 (INT16) object_size, 
255                                 &bytes_returned,
256                                 read_buffer,
257                                 hostendian)) != SUCCESS) {
258         return(FAILURE);
259    };
260   
261    bytes_returned = bytes_returned * object_size;
262     
263     /* Continue if SUCCESSful */
264     
265    /*
266    ** Call data format routines
267    */
268
269    if ISMEM(memory_space) {
270       if (dump_format == WORD_FORMAT)
271          result = dump_mem_word(memory_space,
272                                 address,
273                                 bytes_returned,
274                                 read_buffer);
275       else
276       if (dump_format == HALF_FORMAT)
277          result = dump_mem_half(memory_space,
278                                 address,
279                                 bytes_returned,
280                                 read_buffer);
281       else
282       if (dump_format == BYTE_FORMAT)
283          result = dump_mem_byte(memory_space,
284                                 address,
285                                 bytes_returned,
286                                 read_buffer);
287       else
288       if (dump_format == FLOAT_FORMAT)
289          result = dump_mem_float(memory_space,
290                                 address,
291                                 bytes_returned,
292                                 read_buffer);
293       else
294       if (dump_format == DOUBLE_FORMAT)
295          result = dump_mem_double(memory_space,
296                                 address,
297                                 bytes_returned,
298                                 read_buffer);
299       }
300    else
301    if ISREG(memory_space) {
302       if (dump_format == WORD_FORMAT)
303          result = dump_reg_word(memory_space,
304                                 address,
305                                 bytes_returned,
306                                 read_buffer);
307       else
308       if (dump_format == HALF_FORMAT)
309          result = dump_reg_half(memory_space,
310                                 address,
311                                 bytes_returned,
312                                 read_buffer);
313       else
314       if (dump_format == BYTE_FORMAT)
315          result = dump_reg_byte(memory_space,
316                                 address,
317                                 bytes_returned,
318                                 read_buffer);
319       else
320       if (dump_format == FLOAT_FORMAT)
321          result = dump_reg_float(memory_space,
322                                 address,
323                                 bytes_returned,
324                                 read_buffer);
325       else
326       if (dump_format == DOUBLE_FORMAT)
327          result = dump_reg_double(memory_space,
328                                 address,
329                                 bytes_returned,
330                                 read_buffer);
331       }
332    else
333       return(EMBADADDR);
334
335    (void) free ((char *) read_buffer);
336    return (result);
337
338    }  /* end dump_cmd() */
339
340
341
342 /*
343 ** Functions used by dump_cmd()
344 */
345
346
347 /*
348 ** This function is used to dump 32 bit words of data.
349 ** the address is printed, followed by the data, grouped
350 ** into 8 character long strings, each representing one
351 ** 32 bit word.  Space for four 32-bit words is reserved
352 ** on each line.  Following the hex data, an ASCII
353 ** representation of the data is printed.
354 */
355
356 int
357 dump_mem_word(memory_space, read_address, bytes_returned, read_buffer)
358    INT32  memory_space;
359    ADDR32 read_address;
360    INT32  bytes_returned;
361    BYTE   *read_buffer;
362    {
363    int      result;
364    ADDR32   address;
365    ADDR32   start_address;
366    ADDR32   end_address;
367    ADDR32   last_print_address;
368    ADDR32   address_mask;
369    INT32    byte_count;
370    INT32    data_word;
371    struct   addr_29k_t addr_29k;
372    int      ASCII_index;
373    char     ASCII_buffer[20];
374
375    byte_count = 0;
376    ASCII_index = 0;
377    ASCII_buffer[0] = '\0';
378
379    address_mask = 0xfffffff0;
380    start_address = read_address;
381    end_address = read_address + bytes_returned;
382    last_print_address = (end_address + 0xf) & address_mask;
383    address = start_address & address_mask;
384
385    /*
386    ** Loop while data available
387    */
388
389    while (address <= last_print_address) {
390
391       /* Exit if address not valid */
392       addr_29k.memory_space = memory_space;
393       addr_29k.address = address;
394       result = addr_29k_ok(&addr_29k);
395       if (result != 0) {
396          if (io_config.echo_mode == (INT32) TRUE)
397          fprintf(io_config.echo_file, "\n\n");
398          fprintf(stderr, "\n\n");
399          return (0);
400          }
401
402       /* Print out ASCII data */
403       if ((address & address_mask) == address) {
404          fprintf(stderr, "  %s\n", ASCII_buffer);
405          if (io_config.echo_mode == (INT32) TRUE)
406          fprintf(io_config.echo_file, "  %s\n", ASCII_buffer);
407          ASCII_index = 0;
408          }
409
410       /* Print address in margin */
411       if (((address & address_mask) == address) &&
412           (address  != last_print_address)) {
413          result = print_addr_29k(memory_space, address);
414          if (result != 0)
415             return (EMBADADDR);
416          }
417
418       /* Do leading and trailing spaces (if necessary) */
419       if ((address < start_address) ||
420           (address >= end_address)) {
421          fprintf(stderr, "         ");
422          if (io_config.echo_mode == (INT32) TRUE)
423          fprintf(io_config.echo_file, "         ");
424          result = dump_ASCII(ASCII_buffer, ASCII_index,
425                              (BYTE *) NULL, sizeof(INT32)); 
426          ASCII_index = ASCII_index + sizeof(INT32);
427          address = address + sizeof(INT32);
428          }
429
430       /* Print out hex data */
431       if ((address >= start_address) &&
432           (address < end_address)) {
433
434          result = get_data((BYTE *)&data_word,
435                            &read_buffer[byte_count],
436                            sizeof(INT32));
437          if (result != 0)
438             return (EMBADADDR);
439
440          fprintf(stderr, "%08lx ", data_word);
441          if (io_config.echo_mode == (INT32) TRUE)
442          fprintf(io_config.echo_file, "%08lx ", data_word);
443
444          /* Build ASCII srting */
445          result = dump_ASCII(ASCII_buffer,
446                              ASCII_index,
447                              &read_buffer[byte_count],
448                              sizeof(INT32)); 
449          ASCII_index = ASCII_index + sizeof(INT32);
450
451          address = address + sizeof(INT32);
452
453          byte_count = byte_count + sizeof(INT32);
454
455          }  /* end if */
456
457       }  /* end while */
458
459    fprintf(stderr, "\n");
460    if (io_config.echo_mode == (INT32) TRUE)
461    fprintf(io_config.echo_file, "\n");
462
463    return (0);
464
465    }  /* end dump_mem_word() */
466
467
468 int
469 dump_reg_word(memory_space, read_address, bytes_returned, read_buffer)
470    INT32  memory_space;
471    ADDR32 read_address;
472    INT32  bytes_returned;
473    BYTE   *read_buffer;
474    {
475    int      result;
476    ADDR32   address;
477    ADDR32   start_address;
478    ADDR32   end_address;
479    ADDR32   last_print_address;
480    ADDR32   address_mask;
481    INT32    byte_count;
482    INT32    data_word;
483    struct   addr_29k_t addr_29k;
484    int      ASCII_index;
485    char     ASCII_buffer[20];
486
487    byte_count = 0;
488    ASCII_index = 0;
489    ASCII_buffer[0] = '\0';
490
491    address_mask = 0xfffffffc;
492    start_address = read_address;
493    end_address = read_address + (bytes_returned / 4);
494    last_print_address = (end_address + 0x3) & address_mask;
495    address = start_address & address_mask;
496
497    /*
498    ** Loop while data available
499    */
500
501    while (address <= last_print_address) {
502
503       /* Exit if address not valid */
504       addr_29k.memory_space = memory_space;
505       addr_29k.address = address;
506       result = addr_29k_ok(&addr_29k);
507       if (result != 0) {
508          fprintf(stderr, "\n\n");
509          if (io_config.echo_mode == (INT32) TRUE)
510          fprintf(io_config.echo_file, "\n\n");
511          return (0);
512          }
513
514       /* Print out ASCII data */
515       if ((address & address_mask) == address) {
516          fprintf(stderr, "  %s\n", ASCII_buffer);
517          if (io_config.echo_mode == (INT32) TRUE)
518          fprintf(io_config.echo_file, "  %s\n", ASCII_buffer);
519          ASCII_index = 0;
520          }
521
522       /* Print address in margin */
523       if (((address & address_mask) == address) &&
524           (address  != last_print_address)) {
525          result = print_addr_29k(memory_space, address);
526          if (result != 0)
527             return (EMBADADDR);
528          }
529
530       /* Do leading and trailing spaces (if necessary) */
531       if ((address < start_address) ||
532           (address >= end_address)) {
533          fprintf(stderr, "         ");
534          if (io_config.echo_mode == (INT32) TRUE)
535          fprintf(io_config.echo_file, "         ");
536          result = dump_ASCII(ASCII_buffer, ASCII_index,
537                              (BYTE *) NULL, sizeof(INT32)); 
538          ASCII_index = ASCII_index + sizeof(INT32);
539          address = address + 1;
540          }
541
542       /* Print out hex data */
543       if ((address >= start_address) &&
544           (address < end_address)) {
545
546          result = get_data((BYTE *)&data_word,
547                            &read_buffer[byte_count],
548                            sizeof(INT32));
549          if (result != 0)
550             return (EMBADADDR);
551
552          fprintf(stderr, "%08lx ", data_word);
553          if (io_config.echo_mode == (INT32) TRUE)
554          fprintf(io_config.echo_file, "%08lx ", data_word);
555
556          /* Build ASCII srting */
557          result = dump_ASCII(ASCII_buffer,
558                              ASCII_index,
559                              &read_buffer[byte_count],
560                              sizeof(INT32)); 
561          ASCII_index = ASCII_index + sizeof(INT32);
562
563          address = address + 1;
564
565          byte_count = byte_count + sizeof(INT32);
566
567          }  /* end if */
568
569       }  /* end while */
570
571    fprintf(stderr, "\n");
572    if (io_config.echo_mode == (INT32) TRUE)
573    fprintf(io_config.echo_file, "\n");
574
575    return (0);
576
577    }  /* end dump_reg_word() */
578
579
580
581 /*
582 ** This function is used to dump memory as half words.
583 */
584
585 int
586 dump_mem_half(memory_space, read_address, bytes_returned, read_buffer)
587    INT32  memory_space;
588    ADDR32 read_address;
589    INT32  bytes_returned;
590    BYTE   *read_buffer;
591    {
592    int      result;
593    ADDR32   address;
594    ADDR32   start_address;
595    ADDR32   end_address;
596    ADDR32   last_print_address;
597    ADDR32   address_mask;
598    INT32    byte_count;
599    INT16    data_half;
600    INT32    data_word;
601    struct   addr_29k_t addr_29k;
602    int      ASCII_index;
603    char     ASCII_buffer[20];
604
605    byte_count = 0;
606    ASCII_index = 0;
607    ASCII_buffer[0] = '\0';
608
609    address_mask = 0xfffffff0;
610    start_address = read_address;
611    end_address = read_address + bytes_returned;
612    last_print_address = (end_address + 0xf) & address_mask;
613    address = start_address & address_mask;
614
615    /*
616    ** Loop while data available
617    */
618
619    while (address <= last_print_address) {
620
621       /* Exit if address not valid */
622       addr_29k.memory_space = memory_space;
623       addr_29k.address = address;
624       result = addr_29k_ok(&addr_29k);
625       if (result != 0) {
626          fprintf(stderr, "\n\n");
627          if (io_config.echo_mode == (INT32) TRUE)
628          fprintf(io_config.echo_file, "\n\n");
629          return (0);
630          }
631
632       /* Print out ASCII data */
633       if ((address & address_mask) == address) {
634          fprintf(stderr, "  %s\n", ASCII_buffer);
635          if (io_config.echo_mode == (INT32) TRUE)
636          fprintf(io_config.echo_file, "  %s\n", ASCII_buffer);
637          ASCII_index = 0;
638          }
639
640       /* Print address in margin */
641       if (((address & address_mask) == address) &&
642           (address != last_print_address)) {
643          result = print_addr_29k(memory_space, address);
644          if (result != 0)
645             return (EMBADADDR);
646          }
647
648       /* Do leading and trailing spaces (if necessary) */
649       if ((address < start_address) ||
650           (address >= end_address)) {
651          fprintf(stderr, "     ");
652          if (io_config.echo_mode == (INT32) TRUE)
653          fprintf(io_config.echo_file, "     ");
654          result = dump_ASCII(ASCII_buffer, ASCII_index,
655                              (BYTE *) NULL, sizeof(INT16));
656          ASCII_index = ASCII_index + sizeof(INT16);
657          address = address + sizeof(INT16);
658          }
659
660       /* Print out hex data */
661       if ((address >= start_address) &&
662           (address < end_address)) {
663
664          result = get_data((BYTE *)&data_half,
665                            &read_buffer[byte_count],
666                            sizeof(INT16));
667          if (result != 0)
668             return (EMBADADDR);
669
670          /* We have to cast to INT32 to print out a hex halfword */
671          /* (the Sun libraries sign extend to 32 bits) */
672          data_word = (INT32) data_half;
673          data_word = (data_word & 0x0000ffff);
674          fprintf(stderr, "%04x ", data_word);
675          if (io_config.echo_mode == (INT32) TRUE)
676          fprintf(io_config.echo_file, "%04x ", data_word);
677
678          /* Build ASCII srting */
679          result = dump_ASCII(ASCII_buffer,
680                              ASCII_index,
681                              &read_buffer[byte_count],
682                              sizeof(INT16)); 
683          ASCII_index = ASCII_index + sizeof(INT16);
684
685          address = address + sizeof(INT16);
686
687          byte_count = byte_count + sizeof(INT16);
688
689          }  /* end if */
690
691       }  /* end while */
692
693    fprintf(stderr, "\n");
694    if (io_config.echo_mode == (INT32) TRUE)
695    fprintf(io_config.echo_file, "\n");
696
697    return (0);
698    }  /* end dump_mem_half() */
699
700
701
702 /*
703 ** This function is used to dump registers as half words.
704 */
705
706 int
707 dump_reg_half(memory_space, read_address, bytes_returned, read_buffer)
708    INT32  memory_space;
709    ADDR32 read_address;
710    INT32  bytes_returned;
711    BYTE   *read_buffer;
712    {
713    int      result;
714    ADDR32   address;
715    ADDR32   start_address;
716    ADDR32   end_address;
717    ADDR32   last_print_address;
718    ADDR32   address_mask;
719    INT32    byte_count;
720    INT32    data_word;
721    struct   addr_29k_t addr_29k;
722    int      ASCII_index;
723    char     ASCII_buffer[20];
724
725    byte_count = 0;
726    ASCII_index = 0;
727    ASCII_buffer[0] = '\0';
728
729    address_mask = 0xfffffffc;
730    start_address = read_address;
731    end_address = read_address + (bytes_returned / 4);
732    last_print_address = (end_address + 0x3) & address_mask;
733    address = start_address & address_mask;
734
735    /*
736    ** Loop while data available
737    */
738
739    while (address <= last_print_address) {
740
741       /* Exit if address not valid */
742       addr_29k.memory_space = memory_space;
743       addr_29k.address = address;
744       result = addr_29k_ok(&addr_29k);
745       if (result != 0) {
746          fprintf(stderr, "\n\n");
747          if (io_config.echo_mode == (INT32) TRUE)
748          fprintf(io_config.echo_file, "\n\n");
749          return (0);
750          }
751
752       /* Print out ASCII data */
753       if ((address & address_mask) == address) {
754          fprintf(stderr, "  %s\n", ASCII_buffer);
755          if (io_config.echo_mode == (INT32) TRUE)
756          fprintf(io_config.echo_file, "  %s\n", ASCII_buffer);
757          ASCII_index = 0;
758          }
759
760       /* Print address in margin */
761       if (((address & address_mask) == address) &&
762           (address != last_print_address)) {
763          result = print_addr_29k(memory_space, address);
764          if (result != 0)
765             return (EMBADADDR);
766          }
767
768       /* Do leading and trailing spaces (if necessary) */
769       if ((address < start_address) ||
770           (address >= end_address)) {
771          fprintf(stderr, "         ");
772          if (io_config.echo_mode == (INT32) TRUE)
773          fprintf(io_config.echo_file, "         ");
774          result = dump_ASCII(ASCII_buffer, ASCII_index,
775                              (BYTE *) NULL, sizeof(INT16));
776          ASCII_index = ASCII_index + sizeof(INT16);
777
778          address = address + 1;
779          }
780
781       /* Print out hex data */
782       if ((address >= start_address) &&
783           (address < end_address)) {
784
785          result = get_data((BYTE *)&data_word,
786                            &read_buffer[byte_count],
787                            sizeof(INT32));
788          if (result != 0)
789             return (EMBADADDR);
790
791          fprintf(stderr, "%04lx %04lx ",
792                 ((data_word >> 16) & 0xffff),
793                 (data_word & 0xffff));
794          if (io_config.echo_mode == (INT32) TRUE)
795          fprintf(io_config.echo_file, "%04lx %04lx ",
796                 ((data_word >> 16) & 0xffff),
797                 (data_word & 0xffff));
798
799          /* Build ASCII srting */
800          result = dump_ASCII(ASCII_buffer,
801                              ASCII_index,
802                              &read_buffer[byte_count],
803                              sizeof(INT32));
804          ASCII_index = ASCII_index + sizeof(INT32);
805
806          address = address + 1;
807
808          byte_count = byte_count + sizeof(INT32);
809
810          }  /* end if */
811
812       }  /* end while */
813
814    fprintf(stderr, "\n");
815    if (io_config.echo_mode == (INT32) TRUE)
816    fprintf(io_config.echo_file, "\n");
817
818    return (0);
819    }  /* end dump_reg_half() */
820
821
822
823 /*
824 ** This function is used to dump memory as bytes.
825 */
826
827 int
828 dump_mem_byte(memory_space, read_address, bytes_returned, read_buffer)
829    INT32  memory_space;
830    ADDR32 read_address;
831    INT32  bytes_returned;
832    BYTE   *read_buffer;
833    {
834    int      result;
835    ADDR32   address;
836    ADDR32   start_address;
837    ADDR32   end_address;
838    ADDR32   last_print_address;
839    ADDR32   address_mask;
840    INT32    byte_count;
841    BYTE     data_byte;
842    struct   addr_29k_t addr_29k;
843    int      ASCII_index;
844    char     ASCII_buffer[20];
845
846    byte_count = 0;
847    ASCII_index = 0;
848    ASCII_buffer[0] = '\0';
849
850    address_mask = 0xfffffff0;
851    start_address = read_address;
852    end_address = read_address + bytes_returned;
853    last_print_address = (end_address + 0xf) & address_mask;
854    address = start_address & address_mask;
855
856    /*
857    ** Loop while data available
858    */
859
860    while (address <= last_print_address) {
861
862       /* Exit if address not valid */
863       addr_29k.memory_space = memory_space;
864       addr_29k.address = address;
865       result = addr_29k_ok(&addr_29k);
866       if (result != 0) {
867          fprintf(stderr, "\n\n");
868          if (io_config.echo_mode == (INT32) TRUE)
869          fprintf(io_config.echo_file, "\n\n");
870          return (0);
871          }
872
873       /* Print out ASCII data */
874       if ((address & address_mask) == address) {
875          fprintf(stderr, "  %s\n", ASCII_buffer);
876          if (io_config.echo_mode == (INT32) TRUE)
877          fprintf(io_config.echo_file, "  %s\n", ASCII_buffer);
878          ASCII_index = 0;
879          }
880
881       /* Print address in margin */
882       if (((address & address_mask) == address) &&
883           (address != last_print_address)) {
884          result = print_addr_29k(memory_space, address);
885          if (result != 0)
886             return (EMBADADDR);
887          }
888
889       /* Do leading and trailing spaces (if necessary) */
890       if ((address < start_address) ||
891           (address >= end_address)) {
892          fprintf(stderr, "   ");
893          if (io_config.echo_mode == (INT32) TRUE)
894          fprintf(io_config.echo_file, "   ");
895          result = dump_ASCII(ASCII_buffer, ASCII_index,
896                              (BYTE *) NULL, sizeof(BYTE));
897          ASCII_index = ASCII_index + sizeof(BYTE);
898          address = address + sizeof(BYTE);
899          }
900
901       /* Print out hex data */
902       if ((address >= start_address) &&
903           (address < end_address)) {
904
905          result = get_data((BYTE *)&data_byte,
906                            &read_buffer[byte_count],
907                            sizeof(BYTE));
908          if (result != 0)
909             return (EMBADADDR);
910
911          fprintf(stderr, "%02x ", data_byte);
912          if (io_config.echo_mode == (INT32) TRUE)
913          fprintf(io_config.echo_file, "%02x ", data_byte);
914
915          /* Build ASCII srting */
916          result = dump_ASCII(ASCII_buffer,
917                              ASCII_index,
918                              &read_buffer[byte_count],
919                              sizeof(BYTE)); 
920          ASCII_index = ASCII_index + sizeof(BYTE);
921
922          address = address + sizeof(BYTE);
923
924          byte_count = byte_count + sizeof(BYTE);
925
926          }  /* end if */
927
928       }  /* end while */
929
930    fprintf(stderr, "\n");
931    if (io_config.echo_mode == (INT32) TRUE)
932    fprintf(io_config.echo_file, "\n");
933
934    return (0);
935    }  /* end dump_mem_byte() */
936
937
938
939 /*
940 ** This function is used to dump registers as bytes.
941 */
942
943 int
944 dump_reg_byte(memory_space, read_address, bytes_returned, read_buffer)
945    INT32  memory_space;
946    ADDR32 read_address;
947    INT32  bytes_returned;
948    BYTE   *read_buffer;
949    {
950    int      result;
951    ADDR32   address;
952    ADDR32   start_address;
953    ADDR32   end_address;
954    ADDR32   last_print_address;
955    ADDR32   address_mask;
956    INT32    byte_count;
957    INT32    data_word;
958    struct   addr_29k_t addr_29k;
959    int      ASCII_index;
960    char     ASCII_buffer[20];
961
962    byte_count = 0;
963    ASCII_index = 0;
964    ASCII_buffer[0] = '\0';
965
966    address_mask = 0xfffffffc;
967    start_address = read_address;
968    end_address = read_address + (bytes_returned / 4);
969    last_print_address = (end_address + 0x3) & address_mask;
970    address = start_address & address_mask;
971
972    /*
973    ** Loop while data available
974    */
975
976    while (address <= last_print_address) {
977
978       /* Exit if address not valid */
979       addr_29k.memory_space = memory_space;
980       addr_29k.address = address;
981       result = addr_29k_ok(&addr_29k);
982       if (result != 0) {
983          fprintf(stderr, "\n\n");
984          if (io_config.echo_mode == (INT32) TRUE)
985          fprintf(io_config.echo_file, "\n\n");
986          return (0);
987          }
988
989       /* Print out ASCII data */
990       if ((address & address_mask) == address) {
991          fprintf(stderr, "  %s\n", ASCII_buffer);
992          if (io_config.echo_mode == (INT32) TRUE)
993          fprintf(io_config.echo_file, "  %s\n", ASCII_buffer);
994          ASCII_index = 0;
995          }
996
997       /* Print address in margin */
998       if (((address & address_mask) == address) &&
999           (address != last_print_address)) {
1000          result = print_addr_29k(memory_space, address);
1001          if (result != 0)
1002             return (EMBADADDR);
1003          }
1004
1005       /* Do leading and trailing spaces (if necessary) */
1006       if ((address < start_address) ||
1007           (address >= end_address)) {
1008          fprintf(stderr, "            ");
1009          if (io_config.echo_mode == (INT32) TRUE)
1010          fprintf(io_config.echo_file, "            ");
1011          result = dump_ASCII(ASCII_buffer, ASCII_index,
1012                              (BYTE *) NULL, sizeof(INT32));
1013          ASCII_index = ASCII_index + sizeof(INT32);
1014
1015          address = address + 1;
1016          }
1017
1018       /* Print out hex data */
1019       if ((address >= start_address) &&
1020           (address < end_address)) {
1021
1022          result = get_data((BYTE *)&data_word,
1023                            &read_buffer[byte_count],
1024                            sizeof(INT32));
1025          if (result != 0)
1026             return (EMBADADDR);
1027
1028          if (io_config.echo_mode == (INT32) TRUE)
1029          fprintf(io_config.echo_file, "%02lx %02lx %02lx %02lx ",
1030                 ((data_word >> 24) & 0xff),
1031                 ((data_word >> 16) & 0xff),
1032                 ((data_word >> 8) & 0xff),
1033                 (data_word & 0xff));
1034          fprintf(stderr, "%02lx %02lx %02lx %02lx ",
1035                 ((data_word >> 24) & 0xff),
1036                 ((data_word >> 16) & 0xff),
1037                 ((data_word >> 8) & 0xff),
1038                 (data_word & 0xff));
1039
1040          /* Build ASCII srting */
1041          result = dump_ASCII(ASCII_buffer,
1042                              ASCII_index,
1043                              &read_buffer[byte_count],
1044                              sizeof(INT32)); 
1045          ASCII_index = ASCII_index + sizeof(INT32);
1046
1047          address = address + 1;
1048
1049          byte_count = byte_count + sizeof(INT32);
1050
1051          }  /* end if */
1052
1053       }  /* end while */
1054
1055    fprintf(stderr, "\n");
1056    if (io_config.echo_mode == (INT32) TRUE)
1057    fprintf(io_config.echo_file, "\n");
1058
1059    return (0);
1060    }  /* end dump_reg_byte() */
1061
1062
1063
1064 /*
1065 ** This function is used to dump memory as floats.
1066 */
1067
1068 int
1069 dump_mem_float(memory_space, read_address, bytes_returned, read_buffer)
1070    INT32  memory_space;
1071    ADDR32 read_address;
1072    INT32  bytes_returned;
1073    BYTE   *read_buffer;
1074    {
1075    int      result;
1076    ADDR32   address;
1077    ADDR32   start_address;
1078    ADDR32   end_address;
1079    ADDR32   last_print_address;
1080    ADDR32   address_mask;
1081    INT32    byte_count;
1082    float    data_float;
1083    struct   addr_29k_t addr_29k;
1084
1085    byte_count = 0;
1086
1087    address_mask = 0xfffffff0;
1088    start_address = read_address;
1089    end_address = read_address + bytes_returned;
1090    last_print_address = (end_address + 0xf) & address_mask;
1091    address = start_address & address_mask;
1092
1093    /*
1094    ** Loop while data available
1095    */
1096
1097    while (address <= last_print_address) {
1098
1099       /* Exit if address not valid */
1100       addr_29k.memory_space = memory_space;
1101       addr_29k.address = address;
1102       result = addr_29k_ok(&addr_29k);
1103       if (result != 0) {
1104          fprintf(stderr, "\n\n");
1105          if (io_config.echo_mode == (INT32) TRUE)
1106          fprintf(io_config.echo_file, "\n\n");
1107          return (0);
1108          }
1109
1110       /* Print address in margin */
1111       if (((address & address_mask) == address) &&
1112           (address != last_print_address)) {
1113          fprintf(stderr, "\n");
1114          if (io_config.echo_mode == (INT32) TRUE)
1115          fprintf(io_config.echo_file, "\n");
1116          result = print_addr_29k(memory_space, address);
1117          if (result != 0)
1118             return (EMBADADDR);
1119          }
1120
1121       /* Do leading and trailing spaces (if necessary) */
1122       if ((address < start_address) ||
1123           (address >= end_address)) {
1124          fprintf(stderr, "               ");
1125          if (io_config.echo_mode == (INT32) TRUE)
1126          fprintf(io_config.echo_file, "               ");
1127          address = address + sizeof(float);
1128          }
1129
1130       /* Print out hex data */
1131       if ((address >= start_address) &&
1132           (address < end_address)) {
1133
1134          result = get_data((BYTE *)&data_float,
1135                            &read_buffer[byte_count],
1136                            sizeof(float));
1137          if (result != 0)
1138             return (EMBADADDR);
1139
1140          fprintf(stderr, "%+1.6e ", (double) data_float);
1141          if (io_config.echo_mode == (INT32) TRUE)
1142          fprintf(io_config.echo_file, "%+1.6e ", (double) data_float);
1143
1144          address = address + sizeof(float);
1145
1146          byte_count = byte_count + sizeof(float);
1147
1148          }  /* end if */
1149
1150       }  /* end while */
1151
1152    fprintf(stderr, "\n");
1153    if (io_config.echo_mode == (INT32) TRUE)
1154    fprintf(io_config.echo_file, "\n");
1155
1156    return (0);
1157    }  /* end dump_mem_float() */
1158
1159
1160
1161
1162 /*
1163 ** This function is used to dump registers as floats.
1164 */
1165
1166 int
1167 dump_reg_float(memory_space, read_address, bytes_returned, read_buffer)
1168    INT32  memory_space;
1169    ADDR32 read_address;
1170    INT32  bytes_returned;
1171    BYTE   *read_buffer;
1172    {
1173    int      result;
1174    ADDR32   address;
1175    ADDR32   start_address;
1176    ADDR32   end_address;
1177    ADDR32   last_print_address;
1178    ADDR32   address_mask;
1179    INT32    byte_count;
1180    float    data_float;
1181    struct   addr_29k_t addr_29k;
1182
1183    byte_count = 0;
1184
1185    address_mask = 0xfffffffc;
1186    start_address = read_address;
1187    end_address = read_address + (bytes_returned / 4);
1188    last_print_address = (end_address + 0x3) & address_mask;
1189    address = start_address & address_mask;
1190
1191    /*
1192    ** Loop while data available
1193    */
1194
1195    while (address <= last_print_address) {
1196
1197       /* Exit if address not valid */
1198       addr_29k.memory_space = memory_space;
1199       addr_29k.address = address;
1200       result = addr_29k_ok(&addr_29k);
1201       if (result != 0) {
1202          fprintf(stderr, "\n\n");
1203          if (io_config.echo_mode == (INT32) TRUE)
1204          fprintf(io_config.echo_file, "\n\n");
1205          return (0);
1206          }
1207
1208       /* Print address in margin */
1209       if (((address & address_mask) == address) &&
1210           (address != last_print_address)) {
1211          fprintf(stderr, "\n");
1212          if (io_config.echo_mode == (INT32) TRUE)
1213          fprintf(io_config.echo_file, "\n");
1214          result = print_addr_29k(memory_space, address);
1215          if (result != 0)
1216             return (EMBADADDR);
1217          }
1218
1219       /* Do leading and trailing spaces (if necessary) */
1220       if ((address < start_address) ||
1221           (address >= end_address)) {
1222          fprintf(stderr, "               ");
1223          if (io_config.echo_mode == (INT32) TRUE)
1224          fprintf(io_config.echo_file, "               ");
1225          address = address + 1;
1226          }
1227
1228       /* Print out hex data */
1229       if ((address >= start_address) &&
1230           (address < end_address)) {
1231
1232          result = get_data((BYTE *)&data_float,
1233                            &read_buffer[byte_count],
1234                            sizeof(float));
1235          if (result != 0)
1236             return (EMBADADDR);
1237
1238          fprintf(stderr, "%+1.6e ", (double) data_float);
1239          if (io_config.echo_mode == (INT32) TRUE)
1240          fprintf(io_config.echo_file, "%+1.6e ", (double) data_float);
1241
1242          address = address + 1;
1243
1244          byte_count = byte_count + sizeof(float);
1245
1246          }  /* end if */
1247
1248       }  /* end while */
1249
1250    fprintf(stderr, "\n");
1251    if (io_config.echo_mode == (INT32) TRUE)
1252    fprintf(io_config.echo_file, "\n");
1253
1254    return (0);
1255    }  /* end dump_reg_float() */
1256
1257
1258
1259
1260 /*
1261 ** This function is used to dump memory as doubles.
1262 */
1263
1264 int
1265 dump_mem_double(memory_space, read_address, bytes_returned, read_buffer)
1266    INT32  memory_space;
1267    ADDR32 read_address;
1268    INT32  bytes_returned;
1269    BYTE   *read_buffer;
1270    {
1271    int      result;
1272    ADDR32   address;
1273    ADDR32   start_address;
1274    ADDR32   end_address;
1275    ADDR32   last_print_address;
1276    ADDR32   address_mask;
1277    INT32    byte_count;
1278    double   data_double;
1279    struct   addr_29k_t addr_29k;
1280
1281    byte_count = 0;
1282
1283    address_mask = 0xfffffff0;
1284    start_address = read_address;
1285    end_address = read_address + bytes_returned;
1286    last_print_address = (end_address + 0xf) & address_mask;
1287    address = start_address & address_mask;
1288
1289    /*
1290    ** Loop while data available
1291    */
1292
1293    while (address <= last_print_address) {
1294
1295       /* Exit if address not valid */
1296       addr_29k.memory_space = memory_space;
1297       addr_29k.address = address;
1298       result = addr_29k_ok(&addr_29k);
1299       if (result != 0) {
1300          fprintf(stderr, "\n\n");
1301          if (io_config.echo_mode == (INT32) TRUE)
1302          fprintf(io_config.echo_file, "\n\n");
1303          return (0);
1304          }
1305
1306       /* Print address in margin */
1307       if (((address & address_mask) == address) &&
1308           (address != last_print_address)) {
1309          fprintf(stderr, "\n");
1310          if (io_config.echo_mode == (INT32) TRUE)
1311          fprintf(io_config.echo_file, "\n");
1312          result = print_addr_29k(memory_space, address);
1313          if (result != 0)
1314             return (EMBADADDR);
1315          }
1316
1317       /* Do leading and trailing spaces (if necessary) */
1318       if ((address < start_address) ||
1319           (address >= end_address)) {
1320          fprintf(stderr, "                        ");
1321          if (io_config.echo_mode == (INT32) TRUE)
1322          fprintf(io_config.echo_file, "                        ");
1323          address = address + sizeof(double);
1324          }
1325
1326       /* Print out hex data */
1327       if ((address >= start_address) &&
1328           (address < end_address)) {
1329
1330          result = get_data((BYTE *)&data_double,
1331                            &read_buffer[byte_count],
1332                            sizeof(double));
1333          if (result != 0)
1334             return (EMBADADDR);
1335
1336          fprintf(stderr, "%+1.15e ", data_double);
1337          if (io_config.echo_mode == (INT32) TRUE)
1338          fprintf(io_config.echo_file, "%+1.15e ", data_double);
1339
1340          address = address + sizeof(double);
1341
1342          byte_count = byte_count + sizeof(double);
1343
1344          }  /* end if */
1345
1346       }  /* end while */
1347
1348    fprintf(stderr, "\n");
1349    if (io_config.echo_mode == (INT32) TRUE)
1350    fprintf(io_config.echo_file, "\n");
1351
1352    return (0);
1353    }  /* end dump_mem_double() */
1354
1355
1356
1357
1358 /*
1359 ** This function is used to dump registers as doubles.
1360 */
1361
1362 int
1363 dump_reg_double(memory_space, read_address, bytes_returned, read_buffer)
1364    INT32  memory_space;
1365    ADDR32 read_address;
1366    INT32  bytes_returned;
1367    BYTE   *read_buffer;
1368    {
1369    int      result;
1370    ADDR32   address;
1371    ADDR32   start_address;
1372    ADDR32   end_address;
1373    ADDR32   last_print_address;
1374    ADDR32   address_mask;
1375    INT32    byte_count;
1376    double   data_double;
1377    struct   addr_29k_t addr_29k;
1378
1379    byte_count = 0;
1380
1381    address_mask = 0xfffffffc;
1382    start_address = read_address;
1383    end_address = read_address + (bytes_returned / 4);
1384    last_print_address = (end_address + 0x3) & address_mask;
1385    address = start_address & address_mask;
1386
1387    /*
1388    ** Loop while data available
1389    */
1390
1391    while (address <= last_print_address) {
1392
1393       /* Exit if address not valid */
1394       addr_29k.memory_space = memory_space;
1395       addr_29k.address = address;
1396       result = addr_29k_ok(&addr_29k);
1397       if (result != 0) {
1398          fprintf(stderr, "\n\n");
1399          if (io_config.echo_mode == (INT32) TRUE)
1400          fprintf(io_config.echo_file, "\n\n");
1401          return (0);
1402          }
1403
1404       /* Print address in margin */
1405       if (((address & address_mask) == address) &&
1406           (address != last_print_address)) {
1407          fprintf(stderr, "\n");
1408          if (io_config.echo_mode == (INT32) TRUE)
1409          fprintf(io_config.echo_file, "\n");
1410          result = print_addr_29k(memory_space, address);
1411          if (result != 0)
1412             return (EMBADADDR);
1413          }
1414
1415       /* Do leading and trailing spaces (if necessary) */
1416       if ((address < start_address) ||
1417           (address >= end_address)) {
1418          fprintf(stderr, "                        ");
1419          if (io_config.echo_mode == (INT32) TRUE)
1420          fprintf(io_config.echo_file, "                        ");
1421          address = address + 2;
1422          }
1423
1424       /* Print out hex data */
1425       if ((address >= start_address) &&
1426           (address < end_address)) {
1427
1428          result = get_data((BYTE *)&data_double,
1429                            &read_buffer[byte_count],
1430                            sizeof(double));
1431          if (result != 0)
1432             return (EMBADADDR);
1433
1434          fprintf(stderr, "%+1.15e ", data_double);
1435          if (io_config.echo_mode == (INT32) TRUE)
1436          fprintf(io_config.echo_file, "%+1.15e ", data_double);
1437
1438          address = address + (sizeof(double) / sizeof(INT32));
1439
1440          byte_count = byte_count + sizeof(double);
1441
1442          }  /* end if */
1443
1444       }  /* end while */
1445
1446    fprintf(stderr, "\n");
1447    if (io_config.echo_mode == (INT32) TRUE)
1448    fprintf(io_config.echo_file, "\n");
1449
1450    return (0);
1451    }  /* end dump_reg_double() */
1452
1453 /*
1454 ** This function fills in a buffer with a character
1455 ** representation of the dumped data.
1456 */
1457
1458 int
1459 dump_ASCII(buffer, index, data, size)
1460    char    *buffer;
1461    int      index;
1462    BYTE    *data;
1463    int      size;
1464    {
1465    INT32    i;
1466
1467    /* Do ASCII dump */
1468    for (i=0; i<size; i=i+1)
1469       if (data == NULL)
1470          buffer[index+i] = ' ';
1471       else
1472          if (isprint(data[i]))
1473             buffer[index+i] = data[i];
1474             else
1475                buffer[index+i] = '.';
1476
1477    buffer[index+i] = '\0';  /* Null terminate */
1478
1479    return (0);
1480
1481    }  /* end dump_ASCII() */
1482