OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [start/] [gdb-5.0/] [utils/] [amd-udi/] [mondfe/] [getdata.c] - Blame information for rev 1778

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 106 markom
static char _[] = "@(#)getdata.c        5.21 93/07/30 16:38:33, 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 file contains functions used to parse strings into
31
 **       various data structures.
32
 **
33
 *****************************************************************************
34
 */
35
 
36
#include <stdio.h>
37
#include <ctype.h>
38
#include "memspcs.h"
39
#include "main.h"
40
#include "opcodes.h"
41
#include "macros.h"
42
#include "error.h"
43
 
44
#ifdef MSDOS
45
#include <string.h>
46
#else
47
#include <string.h>
48
#endif
49
 
50
/* Function declarations */
51
int get_data PARAMS(( BYTE  *out_data, BYTE  *in_data, int    size));
52
int set_data PARAMS((BYTE *out_data, BYTE *in_data, int size));
53
int get_word_decimal PARAMS((char *buffer, INT32 *data_word));
54
int get_double PARAMS((char *buffer, double *data_double));
55
int get_float PARAMS((char *buffer, float *data_float));
56
int get_byte PARAMS((char *buffer, BYTE  *data_byte));
57
int get_half PARAMS((char *buffer, INT16 *data_half));
58
int get_word PARAMS((char *buffer, INT32 *data_word));
59
int get_alias_29k PARAMS((char  *reg_str, struct addr_29k_t *addr_29k));
60
int get_register_29k PARAMS((char *reg_str,struct addr_29k_t *addr_29k));
61
int get_memory_29k PARAMS((char *memory_str, struct addr_29k_t *addr_29k, INT32 default_space));
62
int print_addr_29k PARAMS((INT32 memory_space, ADDR32 address));
63
int addr_29k_ok PARAMS((struct addr_29k_t *addr_29k));
64
int get_addr_29k PARAMS((char *addr_str, struct addr_29k_t *addr_29k));
65
int get_addr_29k_m PARAMS((char *addr_str, struct addr_29k_t *addr_29k, INT32 default_space));
66
void convert16 PARAMS(( BYTE *byte));
67
void convert32 PARAMS(( BYTE *byte));
68
 
69
 
70
/*
71
** This function is used to parse a string into the
72
** memory space / address pair used by the Am29000.
73
** the memory spaces supported are in the "memspcs.h"
74
** file.
75
**
76
** The strings parsed are:
77
**
78
**    lr0 to gr127  (Local registers)
79
**    gr0 to gr127  (Global registers)
80
**    sr0 to sr127  (Special registers)
81
**    tr0 to tr127  (TLB registers)
82
**    xr0 to xr32   (Coprocessor registers)
83
**       and
84
**    <hex_addr>{i|r|d}
85
**
86
** If successful, the Am29000 memory space / address pair
87
** pointed to by addr_29k is filled in and zero is returned.
88
** If unsuccessful, a -1 is returned and the values in
89
** addr_29k are undefined.
90
**
91
** Note:  This function expects an unpadded, lower case
92
**        ASCII string.
93
*/
94
 
95
 
96
int
97
get_addr_29k(addr_str, addr_29k)
98
   char   *addr_str;
99
   struct  addr_29k_t  *addr_29k;
100
   {
101
   /* defaults memory addresses to D_MEM */
102
   return(get_addr_29k_m(addr_str, addr_29k, D_MEM));
103
   }
104
 
105
 
106
int
107
get_addr_29k_m(addr_str, addr_29k, default_space)
108
   char   *addr_str;
109
   struct  addr_29k_t  *addr_29k;
110
   INT32   default_space;       /* for default if no space given in string */
111
   {
112
   int  result;
113
 
114
   result = get_memory_29k(addr_str, addr_29k, default_space);
115
 
116
   if (result != 0)
117
      result = get_register_29k(addr_str, addr_29k);
118
 
119
   if (result != 0)
120
      result = get_alias_29k(addr_str, addr_29k);
121
 
122
   return (result);
123
   }  /* end get_addr_29k() */
124
 
125
 
126
/*
127
** This function is used to verify that an Am29000
128
** memory space / address pair contains a valid address.
129
** The memory spaces supported are those defined in the
130
** "memspcs.h" header file.
131
**
132
** The global structure "target_config" is also used to
133
** do range checking.
134
**
135
** If successful, a 0 is returned, otherwise -1 is
136
** returned.
137
*/
138
 
139
 
140
int
141
addr_29k_ok(addr_29k)
142
   struct  addr_29k_t  *addr_29k;
143
   {
144
   int     return_code;
145
   ADDR32  start_addr;
146
   ADDR32  end_addr;
147
 
148
   return_code = 0;
149
 
150
   if (addr_29k->memory_space == LOCAL_REG) {
151
      if (addr_29k->address > 127)
152
         return_code = EMBADREG;
153
      }
154
   else
155
   if (addr_29k->memory_space == ABSOLUTE_REG) {
156
        if ((addr_29k->address >= 0) && (addr_29k->address <= 255))
157
           return (0);
158
        else
159
           return (EMBADREG);
160
      }
161
   else
162
   if (addr_29k->memory_space == GLOBAL_REG) {
163
      if (PROCESSOR(target_config.processor_id) == PROC_AM29050) {
164
         if ( ((addr_29k->address > 3) &&
165
              (addr_29k->address < 64)) ||
166
 
167
              (addr_29k->address > 127))
168
            return_code = EMBADREG;
169
      } else {
170
         if ( ((addr_29k->address > 1) &&
171
              (addr_29k->address < 64)) ||
172
 
173
              (addr_29k->address > 127))
174
            return_code = EMBADREG;
175
       }
176
   } else /* Note:  Am29xxx procesors have different SPECIAL_REGs */
177
   if ((addr_29k->memory_space == SPECIAL_REG) ||
178
      (addr_29k->memory_space == A_SPCL_REG)) {
179
 
180
      if ((PROCESSOR(target_config.processor_id) == PROC_AM29030) ||
181
         (PROCESSOR(target_config.processor_id) == PROC_AM29240) ||
182
         (PROCESSOR(target_config.processor_id) == PROC_AM29035)) {
183
 
184
         if (((addr_29k->address > 14) &&
185
              (addr_29k->address < 29)) ||
186
 
187
             ((addr_29k->address > 30) &&
188
              (addr_29k->address < 128)) ||
189
 
190
             ((addr_29k->address > 135) &&
191
              (addr_29k->address < 160)) ||
192
 
193
             ((addr_29k->address > 162) &&
194
              (addr_29k->address < 164)) ||
195
 
196
              (addr_29k->address > 164))
197
            return_code = EMBADREG;
198
         }
199
      else
200
      if (PROCESSOR(target_config.processor_id) == PROC_AM29050) {
201
 
202
         if (((addr_29k->address > 26) &&
203
              (addr_29k->address < 128)) ||
204
 
205
             ((addr_29k->address > 135) &&
206
              (addr_29k->address < 160)) ||
207
 
208
              (addr_29k->address > 164))
209
            return_code = EMBADREG;
210
         }
211
      else      /* default */
212
         if (((addr_29k->address > 14) &&
213
              (addr_29k->address < 128)) ||
214
 
215
             ((addr_29k->address > 135) &&
216
              (addr_29k->address < 160)) ||
217
 
218
             ((addr_29k->address > 162) &&
219
              (addr_29k->address < 164)) ||
220
 
221
              (addr_29k->address > 164))
222
            return_code = EMBADREG;
223
      }  /* end if (SPECIAL_REG) */
224
   else
225
   if (addr_29k->memory_space == TLB_REG) {
226
      if (addr_29k->address > 127)
227
         return_code = EMBADREG;
228
      }
229
   else
230
   if (addr_29k->memory_space == COPROC_REG) {
231
      if (target_config.coprocessor != 0)
232
         return_code = EMBADREG;
233
      if (addr_29k->address > 32)
234
         return_code = EMBADREG;
235
      }
236
   else
237
   if (addr_29k->memory_space == PC_SPACE) {
238
      return (0);
239
     }
240
   else
241
   if (addr_29k->memory_space == GENERIC_SPACE) {
242
      return (0);
243
     }
244
   else
245
   if (addr_29k->memory_space == I_MEM) {
246
      start_addr = target_config.I_mem_start;
247
      end_addr = start_addr + (ADDR32) target_config.I_mem_size;
248
      if ((addr_29k->address < start_addr) ||
249
          (addr_29k->address > end_addr))
250
         return_code = EMBADADDR;
251
      }
252
   else
253
   if (addr_29k->memory_space == D_MEM) {
254
      start_addr = target_config.D_mem_start;
255
      end_addr = start_addr + (ADDR32) target_config.D_mem_size;
256
      if ((addr_29k->address < start_addr) ||
257
          (addr_29k->address > end_addr))
258
         return_code = EMBADADDR;
259
      }
260
   else
261
   if (addr_29k->memory_space == I_ROM) {
262
      start_addr = target_config.ROM_start;
263
      end_addr = start_addr + (ADDR32) target_config.ROM_size;
264
      if ((addr_29k->address < start_addr) ||
265
          (addr_29k->address > end_addr))
266
         return_code = EMBADADDR;
267
      }
268
   else
269
   if (addr_29k->memory_space == D_ROM) {
270
         return_code = EMBADADDR;  /* We don't use this memory space */
271
      }
272
   else
273
   if (addr_29k->memory_space == I_O) {
274
      return (0);  /* No checking on I/O space */
275
      }
276
   else
277
      return_code = EMBADADDR;  /* Unknown memory space */
278
 
279
   return (return_code);
280
 
281
   }  /* end addr_29k_ok() */
282
 
283
 
284
 
285
 
286
 
287
/*
288
** This function is used to print out an address.  The
289
** parameters are a memory_space and an address.  This
290
** function returns a 0 if the command was successful and
291
** a -1 on failure.
292
**
293
** The strings printed are:
294
**
295
**    lr0 to gr127  (Local registers)
296
**    gr0 to gr127  (Global registers)
297
**    sr0 to sr127  (Special registers)
298
**    tr0 to tr127  (TLB registers)
299
**    xr0 to xr32   (Coprocessor registers)
300
**    <hex_addr>    (Data memory)
301
**    <hex_addr>i   (instruction memory)
302
**       and
303
**    <hex_addr>r   (ROM memory)
304
**
305
*/
306
 
307
 
308
int
309
print_addr_29k(memory_space, address)
310
   INT32   memory_space;
311
   ADDR32  address;
312
   {
313
   char         buf[80];
314
 
315
   if (memory_space == LOCAL_REG)
316
      sprintf(&buf[0], "lr%03ld      ", address);
317
   else
318
   if (memory_space == ABSOLUTE_REG)
319
      sprintf(&buf[0], "ar%03ld      ", address);
320
   else
321
   if (memory_space == GLOBAL_REG)
322
      sprintf(&buf[0], "gr%03ld      ", address);
323
   else
324
   if ((memory_space == SPECIAL_REG) || (memory_space == A_SPCL_REG))
325
      sprintf(&buf[0], "sr%03ld      ", address);
326
   else
327
   if (memory_space == PC_SPACE)
328
      sprintf(&buf[0], "pc%03ld      ", address);
329
   else
330
   if (memory_space == TLB_REG)
331
      sprintf(&buf[0], "tr%03ld      ", address);
332
   else
333
   if (memory_space == COPROC_REG)
334
      sprintf(&buf[0], "xr%03ld      ", address);
335
   else
336
   if (memory_space == I_MEM)
337
      sprintf(&buf[0], "%08lxi  ", address);
338
   else
339
   if (memory_space == D_MEM)
340
      sprintf(&buf[0], "%08lx   ", address);
341
   else
342
   if (memory_space == GENERIC_SPACE)
343
      sprintf(&buf[0], "%08lx   ", address);
344
   else
345
   if (memory_space == I_ROM)
346
      sprintf(&buf[0], "%08lxr  ", address);
347
   else
348
   if (memory_space == D_ROM)
349
      sprintf(&buf[0], "%08ldr  ", address);
350
   else
351
   if (memory_space == I_O)
352
      sprintf(&buf[0], "%08lx(i/o)", address);
353
   else
354
      return (-1);
355
 
356
   fprintf (stderr, "%s", &buf[0]);
357
   if (io_config.echo_mode == (INT32) TRUE)
358
       fprintf (io_config.echo_file, "%s", &buf[0]);
359
   return (0);
360
   }  /* end print_addr_29k() */
361
 
362
 
363
 
364
/*
365
** This function is used to convert a string denoting a
366
** 29k address into an addr_29k_t memory space / address pair.
367
** This function recognizes the registers described in
368
** get_addr_29k() above.
369
*/
370
 
371
int
372
get_memory_29k(memory_str, addr_29k, default_space)
373
   char   *memory_str;
374
   struct  addr_29k_t  *addr_29k;
375
   INT32   default_space;
376
   {
377
   int     i;
378
   int     fields;
379
   int     string_length;
380
   ADDR32  addr;
381
   char    i_r;
382
   char    error;
383
 
384
   addr_29k->memory_space = -1;
385
   addr_29k->address = -1;
386
 
387
   addr = 0;
388
   i_r = '\0';
389
   error = '\0';
390
 
391
   /* Get rid of leading "0x" */
392
   if ((strlen(memory_str) > 2) &&
393
       (strncmp(memory_str, "0x", 2) == 0))
394
      memory_str = &(memory_str[2]);
395
 
396
   string_length = strlen(memory_str);
397
 
398
   if ((string_length > 10) || (string_length < 1))
399
      return (EMBADADDR);
400
 
401
   if (memory_str[0] == '.') {/* relative offset */
402
     fields = sscanf(&memory_str[1], "%lx%c%c", &addr, &i_r, &error);
403
      addr_29k->memory_space = PC_RELATIVE;
404
      addr_29k->address = addr;
405
      return (0);
406
   }
407
 
408
   for (i=1; i<(string_length-1); i=i+1)
409
    if (isxdigit(memory_str[i]) == 0)
410
       return (EMBADADDR);
411
 
412
   if ((isxdigit(memory_str[(string_length-1)]) == 0) &&
413
       (memory_str[(string_length-1)] != 'i') &&
414
       (memory_str[(string_length-1)] != 'm') &&
415
       (memory_str[(string_length-1)] != 'u') &&
416
       (memory_str[(string_length-1)] != 'p') &&
417
       (memory_str[(string_length-1)] != 'r'))
418
      return (EMBADADDR);
419
 
420
   fields = sscanf(memory_str, "%lx%c%c", &addr, &i_r, &error);
421
 
422
   addr_29k->address = addr;
423
 
424
   if (fields == 1) {
425
      addr_29k->memory_space = default_space;
426
      }
427
   else
428
   if (fields == 2) {
429
      if ((i_r == '\0') || (i_r == 'm'))
430
         addr_29k->memory_space = D_MEM;
431
      else
432
      if (i_r == 'r')
433
         addr_29k->memory_space = I_ROM;
434
      else
435
      if (i_r == 'i')
436
         addr_29k->memory_space = I_MEM;
437
      else
438
      if (i_r == 'p')
439
         if ((target_config.processor_id & 0xf1) >= 0x50)
440
            addr_29k->memory_space = GENERIC_SPACE;
441
         else
442
            addr_29k->memory_space = I_O;
443
      else
444
      if (i_r == 'u')
445
         addr_29k->memory_space = GENERIC_SPACE;
446
      else
447
         return (EMBADADDR);
448
      }
449
   else
450
      return (EMBADADDR);
451
 
452
   return (0);
453
   }  /* end get_memory_29k() */
454
 
455
 
456
 
457
/*
458
** This function is used to convert a string denoting an
459
** 29k register into an addr_29k_t memory space / address pair.
460
*/
461
 
462
int
463
get_register_29k(reg_str, addr_29k)
464
   char   *reg_str;
465
   struct  addr_29k_t  *addr_29k;
466
   {
467
   int     fields;
468
   ADDR32  reg_number;
469
   char    error;
470
 
471
   addr_29k->memory_space = -1;
472
   addr_29k->address = -1;
473
 
474
   reg_number = 0;
475
   error = '\0';
476
 
477
   if (strlen(reg_str) > 8)
478
      return (EMBADREG);
479
 
480
   if (strncmp(reg_str, "lr", 2) == 0)
481
      addr_29k->memory_space = LOCAL_REG;
482
   else
483
   if (strncmp(reg_str, "ar", 2) == 0)
484
      addr_29k->memory_space = ABSOLUTE_REG;
485
   else
486
   if (strncmp(reg_str, "gr", 2) == 0)
487
      addr_29k->memory_space = GLOBAL_REG;
488
   else
489
   if (strncmp(reg_str, "sr", 2) == 0)
490
      addr_29k->memory_space = A_SPCL_REG;
491
   else
492
   if (strncmp(reg_str, "tr", 2) == 0)
493
      addr_29k->memory_space = TLB_REG;
494
   else
495
   if (strncmp(reg_str, "xr", 2) == 0)
496
     addr_29k->memory_space = COPROC_REG;
497
 
498
   /* Get register number */
499
   if (addr_29k->memory_space != -1) {
500
      fields = sscanf(&(reg_str[2]), "%ld%c", &reg_number, &error);
501
      if ((fields == 1) &&
502
          (error == '\0'))
503
         addr_29k->address = reg_number;
504
         else
505
            addr_29k->memory_space = -1;
506
      }
507
 
508
   if (addr_29k->memory_space == -1)
509
      return (EMBADREG);
510
      else
511
         return (0);
512
   }  /* end get_register_29k() */
513
 
514
 
515
 
516
 
517
/*
518
** This function is used to get the special register aliases
519
** ("cps", "vab", "ops", etc ...) in addition to the registers
520
** described in get_addr_29k() above.
521
*/
522
 
523
int
524
get_alias_29k(reg_str, addr_29k)
525
   char   *reg_str;
526
   struct  addr_29k_t  *addr_29k;
527
   {
528
   int     i;
529
   int     result;
530
   int     found;
531
 
532
   addr_29k->memory_space = -1;
533
   addr_29k->address = -1;
534
 
535
   if (strlen(reg_str) > 8)
536
      return (EMBADREG);
537
 
538
   /* Check for logical PC */
539
   if ((strcmp("pc", reg_str) == 0) ||
540
       (strcmp("PC", reg_str) == 0)) {
541
         addr_29k->memory_space = PC_SPACE;
542
         addr_29k->address = (ADDR32) 0;
543
         return (0);
544
   }
545
   /* Search for a special register alias */
546
   i=0;
547
   found = FALSE;
548
   while ((i<256) && (found != TRUE)) {
549
      result = strcmp(spreg[i], reg_str);
550
      if (result == 0) {
551
         found = TRUE;
552
         addr_29k->memory_space = A_SPCL_REG;
553
         addr_29k->address = (ADDR32) i;
554
         }
555
      i = i + 1;
556
      }  /* end while */
557
 
558
   if (found == TRUE)
559
      return (0);
560
      else
561
         return (EMBADREG);
562
 
563
   }  /* end get_alias_29k() */
564
 
565
 
566
 
567
 
568
 
569
/*
570
** This function is used to read in a 32 bit hex word.
571
** This word is input as an ASCII string and converted
572
** into an INT32 data_word.  If the conversion is successful,
573
** a zero is returned, otherwise a -1 is returned.
574
*/
575
 
576
int
577
get_word(buffer, data_word)
578
   char    *buffer;
579
   INT32   *data_word;
580
   {
581
   int      fields;
582
   char     error;
583
 
584
   /* No more than eight (hex) characters */
585
   if (strlen(buffer) > 8)
586
      return (EMSYNTAX);
587
 
588
   fields = sscanf(buffer, "%lx%c", data_word, &error);
589
 
590
   if (fields != 1)
591
      return (EMSYNTAX);
592
 
593
   return (0);
594
 
595
   }  /* end get_word() */
596
 
597
 
598
 
599
int
600
get_half(buffer, data_half)
601
   char    *buffer;
602
   INT16   *data_half;
603
   {
604
   int      fields;
605
   char     error;
606
   INT16      temp_int;
607
 
608
   /* No more than four (hex) characters */
609
   if (strlen(buffer) > 4)
610
      return (EMSYNTAX);
611
 
612
   fields = sscanf(buffer, "%hx%c", &temp_int, &error);
613
 
614
   if (fields != 1)
615
      return (EMSYNTAX);
616
 
617
   *data_half = (INT16) temp_int;
618
 
619
   return (0);
620
 
621
   }  /* end get_half() */
622
 
623
 
624
int
625
get_byte(buffer, data_byte)
626
   char    *buffer;
627
   BYTE    *data_byte;
628
   {
629
   int      fields;
630
   char     error;
631
   int      temp_int;
632
 
633
   /* No more than two (hex) characters */
634
   if (strlen(buffer) > 2)
635
      return (EMSYNTAX);
636
 
637
   fields = sscanf(buffer, "%x%c", &temp_int, &error);
638
 
639
   if (fields != 1)
640
      return (EMSYNTAX);
641
 
642
   *data_byte = (BYTE) temp_int;
643
 
644
   return (0);
645
 
646
   }  /* end get_byte() */
647
 
648
 
649
int
650
get_float(buffer, data_float)
651
   char    *buffer;
652
   float   *data_float;
653
   {
654
   int      fields;
655
   char     error;
656
 
657
   fields = sscanf(buffer, "%f%c", data_float, &error);
658
 
659
   if (fields != 1)
660
      return (EMSYNTAX);
661
 
662
   return (0);
663
 
664
   }  /* end get_float() */
665
 
666
 
667
int
668
get_double(buffer, data_double)
669
   char    *buffer;
670
   double  *data_double;
671
   {
672
   int      fields;
673
   char     error;
674
 
675
   fields = sscanf(buffer, "%lf%c", data_double, &error);
676
 
677
   if (fields != 1)
678
      return (EMSYNTAX);
679
 
680
   return (0);
681
 
682
 
683
   }  /* end get_double() */
684
 
685
 
686
 
687
 
688
/*
689
** This function is used to read in a 32 bit decimal word.
690
** This word is input as an ASCII string and converted
691
** into an INT32 data_word.  If the conversion is successful,
692
** a zero is returned, otherwise a -1 is returned.
693
** This function is very similar to get_word().
694
*/
695
 
696
int
697
get_word_decimal(buffer, data_word)
698
   char    *buffer;
699
   INT32   *data_word;
700
   {
701
   int      fields;
702
   char     error;
703
 
704
   /* No more than eight (hex) characters */
705
   if (strlen(buffer) > 8)
706
      return (EMSYNTAX);
707
 
708
   fields = sscanf(buffer, "%ld%c", data_word, &error);
709
 
710
   if (fields != 1)
711
      return (EMSYNTAX);
712
 
713
   return (0);
714
 
715
   }  /* end get_word_decimal() */
716
 
717
 
718
/*
719
** This function is used to copy data from into and out
720
** of the message buffers.  If necessary, endian
721
** conversion is performed.
722
*/
723
 
724
int
725
set_data(out_data, in_data, size)
726
   BYTE  *out_data;
727
   BYTE  *in_data;
728
   int    size;
729
   {
730
   int  i;
731
 
732
   if (host_config.host_endian == host_config.target_endian)
733
      for (i=0; i<size; i=i+1)
734
         out_data[i] = in_data[i];
735
      else
736
         for (i=0; i<size; i=i+1)
737
            out_data[i] = in_data[((size-1)-i)];
738
 
739
   return (0);
740
   }  /* end set_data() */
741
 
742
 
743
 
744
 
745
/*
746
** This function is used to get data.
747
** If necessary, endian conversion is performed.
748
*/
749
 
750
int
751
get_data(out_data, in_data, size)
752
   BYTE  *out_data;
753
   BYTE  *in_data;
754
   int    size;
755
   {
756
   int  i;
757
 
758
   if (host_config.host_endian == host_config.target_endian)
759
      for (i=0; i<size; i=i+1)
760
         out_data[i] = in_data[i];
761
      else
762
         for (i=0; i<size; i=i+1)
763
            out_data[i] = in_data[((size-1)-i)];
764
 
765
   return (0);
766
   }  /* end get_data() */
767
 
768
 
769
 
770
/*
771
** This function is used to swap the bytes in a 32 bit
772
** word.  This will convert "little endian" (IBM-PC / Intel)
773
** words to "big endian" (Sun / Motorola) words.
774
*/
775
 
776
void
777
convert32(byte)
778
   BYTE *byte;
779
   {
780
   BYTE temp;
781
 
782
   temp = byte[0];  /* Swap bytes 0 and 3 */
783
   byte[0] = byte[3];
784
   byte[3] = temp;
785
   temp = byte[1];  /* Swap bytes 1 and 2 */
786
   byte[1] = byte[2];
787
   byte[2] = temp;
788
   }   /* end convert32() */
789
 
790
 
791
/*
792
** This function is used to swap the bytes in a 16 bit
793
** word.  This will convert "little endian" (IBM-PC / Intel)
794
** half words to "big endian" (Sun / Motorola) half words.
795
*/
796
 
797
void
798
convert16(byte)
799
   BYTE *byte;
800
   {
801
   BYTE temp;
802
 
803
   temp = byte[0];  /* Swap bytes 0 and 1 */
804
   byte[0] = byte[1];
805
   byte[1] = temp;
806
 
807
   }   /* end convert16() */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.