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

Subversion Repositories or1k

[/] [or1k/] [tags/] [start/] [gdb-5.0/] [utils/] [amd-udi/] [montip/] [mtip.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 106 markom
static char _[] = "@(#)mtip.c   2.14 92/01/13 18:04:36, 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
 *      Engineers: MINIMON DEVELOPMENT TEAM MEMBERS, AMD.
28
 */
29
 
30
#include <stdio.h>
31
#include <string.h>
32
#include <malloc.h>
33
#include "messages.h"
34
#include "coff.h"
35
#include "memspcs.h"
36
#include "mtip.h"
37
#include "macros.h"
38
 
39
/* TIP Breakpoint table */
40
typedef unsigned int    BreakIdType;
41
 
42
static struct break_table {
43
  BreakIdType           id;
44
  INT32         space;
45
  ADDR32        offset;
46
  INT32         count;
47
  INT32         type;
48
  ADDR32        BreakInst;      /* actual instruction */
49
  struct break_table *next;
50
};
51
 
52
struct break_table  *bp_table=NULL;
53
 
54
#define BUFFER_SIZE     1024
55
 
56
static BYTE     buffer[BUFFER_SIZE];
57
 
58
int     Mini_core_load PARAMS((char *corefile, INT32 space,
59
                               INT32 sects, int syms));
60
void    add_to_bp_table PARAMS((BreakIdType *id, INT32 space,
61
                        ADDR32 offset, INT32 count, INT32 type, ADDR32 inst));
62
int     get_from_bp_table PARAMS((BreakIdType id, INT32 *space,
63
                                 ADDR32 *offset, INT32 *count,
64
                                 INT32 *type, ADDR32 *inst));
65
int     remove_from_bp_table PARAMS((BreakIdType id));
66
int     is_breakpt_at PARAMS((INT32 space, ADDR32 offset));
67
 
68
/*
69
** Breakpoint code
70
*/
71
 
72
void
73
add_to_bp_table(id, space, offset, count, type, inst)
74
BreakIdType     *id;
75
INT32   space;
76
ADDR32  offset;
77
INT32   count;
78
INT32   type;
79
ADDR32  inst;
80
{
81
  static BreakIdType    current_break_id=1;
82
  struct break_table    *temp, *temp2;
83
 
84
  if (bp_table == NULL) { /* first element */
85
    bp_table = (struct break_table *) malloc (sizeof(struct break_table));
86
    bp_table->id = current_break_id;
87
    bp_table->offset = offset;
88
    bp_table->space = space;
89
    bp_table->count = count;
90
    bp_table->type = type;
91
    bp_table->BreakInst = inst;
92
    bp_table->next = NULL;
93
  } else {
94
    temp2 = bp_table;
95
    temp = (struct break_table *) malloc (sizeof(struct break_table));
96
    temp->id = current_break_id;
97
    temp->offset = offset;
98
    temp->space = space;
99
    temp->count = count;
100
    temp->type = type;
101
    temp->BreakInst = inst;
102
    temp->next = NULL;
103
    while (temp2->next != NULL)
104
      temp2 = temp2->next;
105
    temp2->next = temp;
106
  };
107
  *id = current_break_id;
108
  current_break_id++;
109
}
110
 
111
int
112
get_from_bp_table(id, space, offset, count, type, inst)
113
BreakIdType     id;
114
INT32   *space;
115
ADDR32  *offset;
116
INT32   *count;
117
INT32   *type;
118
ADDR32  *inst;
119
{
120
  struct break_table  *temp;
121
 
122
  temp = bp_table;
123
 
124
  while (temp != NULL) {
125
    if (temp->id == id) {
126
       *offset = temp->offset;
127
       *space = temp->space;
128
       *count = temp->count;
129
       *type = temp->type;
130
       *inst = temp->BreakInst;
131
       return(0);
132
    } else {
133
      temp = temp->next;
134
    };
135
  }
136
  return(-1);
137
}
138
 
139
int
140
remove_from_bp_table(id)
141
BreakIdType     id;
142
{
143
  struct  break_table   *temp, *temp2;
144
 
145
  if (bp_table == NULL)
146
     return (-1);
147
  else {
148
    temp = bp_table;
149
    if (temp->id == id) { /* head of list */
150
       bp_table = bp_table->next;
151
       (void) free (temp);
152
       return (0); /* success */
153
    } else {
154
       while (temp->next != NULL) {
155
          if (temp->next->id == id) {
156
             temp2 = temp->next;
157
             temp->next = temp->next->next;
158
             (void) free (temp2);
159
             return (0); /* success */
160
          } else {
161
            temp = temp->next;
162
          }
163
       };
164
    }
165
  };
166
  return (-1);  /* failed */
167
}
168
 
169
int
170
is_breakpt_at(space, offset)
171
INT32   space;
172
ADDR32  offset;
173
{
174
  struct break_table  *temp;
175
 
176
  temp = bp_table;
177
 
178
  while (temp != NULL) {
179
    if ((temp->space == space) && (temp->offset == offset)) {
180
       return(1); /* TRUE */
181
    } else {
182
      temp = temp->next;
183
    };
184
  }
185
  return(0); /* FALSE */
186
}
187
 
188
/*
189
** Miscellaneous functions.
190
*/
191
 
192
int
193
Mini_core_load(filename, space, sects, syms)
194
char *filename;
195
INT32   space;
196
INT32   sects;
197
int     syms;
198
  {
199
 
200
   FILE  *coff_in;
201
   INT32  COFF_sections;
202
   INT32  i;
203
   int    read_count;
204
   int    section_type;
205
   int    host_endian;
206
   INT32  flags;
207
   INT32  memory_space;
208
   INT32  address;
209
   INT32  byte_count;
210
   INT32        write_count;
211
   INT32  temp_byte_count;
212
   INT16  temp_magic;
213
   INT16  temp_sections;
214
 
215
   struct  filehdr      COFF_header;
216
   struct  aouthdr      COFF_aout_header;
217
   struct  scnhdr      *COFF_section_header;
218
   struct  scnhdr      *temp_COFF_section_header;
219
 
220
   /* Open the COFF input file (if we can) */
221
   coff_in = fopen(filename, FILE_OPEN_FLAG);
222
   if (coff_in == NULL) {
223
      /* warning (EMOPEN);  */
224
      return(-1);
225
   }
226
 
227
   /*
228
   ** Process COFF header(s)
229
   */
230
 
231
   /* Read in COFF header information */
232
   read_count = fread((char *)&COFF_header,
233
                      sizeof(struct filehdr),
234
                      1, coff_in);
235
 
236
   /* Did we get it all? */
237
   if (read_count != 1) {
238
      fclose(coff_in);
239
      /* warning(EMHDR); */
240
      return (-1);
241
      }
242
 
243
   /* Is it an Am29000 COFF File? */
244
   temp_magic = COFF_header.f_magic;
245
   tip_convert16((BYTE *) &temp_magic);
246
   if (COFF_header.f_magic == SIPFBOMAGIC) {
247
      host_endian = TRUE;
248
      }
249
   else
250
   if (temp_magic == SIPFBOMAGIC) {
251
      host_endian = FALSE;
252
      }
253
   else
254
      {
255
      fclose(coff_in);
256
      /* warning (EMMAGIC); */
257
      return (-1);
258
      }
259
 
260
   /* Get number of COFF sections */
261
   temp_sections = COFF_header.f_nscns;
262
   if (host_endian == FALSE)
263
      tip_convert16((BYTE *) &temp_sections);
264
   COFF_sections = (INT32) temp_sections;
265
 
266
   /* Read in COFF a.out header information (if we can) */
267
   if (COFF_header.f_opthdr > 0) {
268
      read_count = fread((char *)&COFF_aout_header,
269
                         sizeof(struct aouthdr),
270
                         1, coff_in);
271
 
272
      /* Did we get it all? */
273
      if (read_count != 1) {
274
         fclose(coff_in);
275
         /* warning (EMAOUT); */
276
         return (-1);
277
         }
278
 
279
      }
280
 
281
   /*
282
   ** Process COFF section headers
283
   */
284
 
285
   /* Allocate space for section headers */
286
   (char *)COFF_section_header = (char *)
287
       malloc((unsigned) (COFF_sections * sizeof(struct scnhdr)));
288
 
289
   if (COFF_section_header == NULL) {
290
      fclose(coff_in);
291
      /* warning (EMALLOC); */
292
      return (-1);
293
      }
294
 
295
   /* Save the pointer to the malloc'ed data, so
296
   ** we can free it later. */
297
   temp_COFF_section_header = COFF_section_header;
298
 
299
   read_count = fread((char *)COFF_section_header,
300
                      sizeof(struct scnhdr),
301
                      (int) COFF_sections, coff_in);
302
 
303
   /* Did we get it all? */
304
   if (read_count != (int) COFF_sections) {
305
      fclose(coff_in);
306
      /*  warning (EMSCNHDR); */
307
      return (-1);
308
      }
309
 
310
 
311
   /* Process all sections */
312
   for (i=0; i<COFF_sections; i=i+1) {
313
 
314
      address = COFF_section_header->s_paddr;
315
      byte_count = COFF_section_header->s_size;
316
      flags = COFF_section_header->s_flags;
317
 
318
      if (host_endian == FALSE) {
319
         tip_convert32((BYTE *) &address);
320
         tip_convert32((BYTE *) &byte_count);
321
         tip_convert32((BYTE *) &flags);
322
         }
323
 
324
      /* Print downloading messages (if necessary) */
325
      if ((flags == STYP_TEXT) ||
326
          (flags == (STYP_TEXT | STYP_ABS))) {
327
         section_type = TEXT_SECTION;
328
         memory_space = I_MEM;
329
         }
330
      else
331
      if ((flags == STYP_DATA) ||
332
          (flags == (STYP_DATA | STYP_ABS))) {
333
         section_type = DATA_SECTION;
334
         memory_space = D_MEM;
335
         }
336
      else
337
      if ((flags == STYP_LIT) ||
338
          (flags == (STYP_LIT | STYP_ABS))) {
339
         section_type = LIT_SECTION;
340
         memory_space = D_MEM;
341
         }
342
      else
343
      if ((flags == STYP_BSS) ||
344
          (flags == (STYP_BSS | STYP_ABS))) {
345
         section_type = BSS_SECTION;
346
         memory_space = D_MEM;
347
         }
348
      else {
349
         section_type = UNKNOWN_SECTION;
350
      }
351
 
352
      /* Clear BSS sections in 29K data memory */
353
      if (section_type == BSS_SECTION) {
354
         (void) memset ((char *) buffer, (int) '\0', sizeof(buffer));
355
         while (byte_count > 0) {
356
           write_count = (byte_count < (INT32) sizeof(buffer)) ?
357
                                byte_count : (INT32) sizeof (buffer);
358
           if(Mini_write_memory ((INT32) memory_space,
359
                              (ADDR32) address,
360
                              (INT32) write_count,
361
                              (BYTE *) buffer) != SUCCESS) {
362
                (void) fclose(coff_in);
363
                return(-1);
364
           }
365
           address = address + write_count;
366
           byte_count = byte_count - write_count;
367
         }
368
       } else
369
 
370
      /* Else send data to the target */
371
      while (byte_count > 0) {
372
 
373
         temp_byte_count = MIN(byte_count, (INT32) sizeof(buffer));
374
 
375
         read_count = fread((char *) buffer,
376
                            (int) temp_byte_count,
377
                            1, coff_in);
378
 
379
         /* Did we get it all? */
380
         if (read_count != 1) {
381
            fclose(coff_in);
382
            /* warning (EMSCN); */
383
            return (-1);
384
            }
385
 
386
         /* Write to 29K memory*/
387
         if (section_type != UNKNOWN_SECTION) {
388
           if (Mini_write_memory ((INT32)  memory_space,
389
                                (ADDR32) address,
390
                                (INT32)  temp_byte_count,
391
                                (BYTE *) buffer) != SUCCESS) {
392
             /* warning(EMWRITE); */
393
             (void) fclose(coff_in);
394
             return(-1);
395
           };
396
         }
397
 
398
         address = address + temp_byte_count;
399
 
400
         byte_count = byte_count - temp_byte_count;
401
 
402
         }  /* end while */
403
 
404
      COFF_section_header++;
405
 
406
   }  /* end for loop */
407
 
408
   (void) free((char *)temp_COFF_section_header);
409
   (void) fclose(coff_in);
410
 
411
   return (0);
412
 
413
   }   /* end Mini_loadcoff() */
414
 

powered by: WebSVN 2.1.0

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