File: bkpt.c

package info (click to toggle)
pm3 1.1.13-11
  • links: PTS
  • area: main
  • in suites: potato
  • size: 174,164 kB
  • ctags: 133,819
  • sloc: ansic: 982,617; modula3: 548,483; cpp: 57,119; exp: 21,673; sh: 17,053; lisp: 13,693; makefile: 13,492; asm: 11,795; yacc: 8,575; sed: 1,100; objc: 476; csh: 254; awk: 223; pascal: 95; fortran: 5
file content (474 lines) | stat: -rw-r--r-- 11,924 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
static char _[] = " @(#)bkpt.c	5.20 93/07/30 16:38:20, Srini, AMD ";
/******************************************************************************
 * Copyright 1991 Advanced Micro Devices, Inc.
 *
 * This software is the property of Advanced Micro Devices, Inc  (AMD)  which
 * specifically  grants the user the right to modify, use and distribute this
 * software provided this notice is not removed or altered.  All other rights
 * are reserved by AMD.
 *
 * AMD MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS
 * SOFTWARE.  IN NO EVENT SHALL AMD BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL
 * DAMAGES IN CONNECTION WITH OR ARISING FROM THE FURNISHING, PERFORMANCE, OR
 * USE OF THIS SOFTWARE.
 *
 * So that all may benefit from your experience, please report  any  problems
 * or  suggestions about this software to the 29K Technical Support Center at
 * 800-29-29-AMD (800-292-9263) in the USA, or 0800-89-1131  in  the  UK,  or
 * 0031-11-1129 in Japan, toll free.  The direct dial number is 512-462-4118.
 *
 * Advanced Micro Devices, Inc.
 * 29K Support Products
 * Mail Stop 573
 * 5900 E. Ben White Blvd.
 * Austin, TX 78741
 * 800-292-9263
 *****************************************************************************
 *      Engineer: Srini Subramanian.
 *****************************************************************************
 **       This module contains the functions used to provide breakpointing
 **	  capability.
 *****************************************************************************
 */

#include <stdio.h>
#include <ctype.h>
#include "memspcs.h"
#include "main.h"
#include "monitor.h"
#include "miniint.h"
#include "error.h"

#ifdef	MSDOS
#include <stdlib.h>
#include <string.h>

#else
#include <strings.h>

#endif

/*
** Definitions
*/

int   get_addr_29k_m PARAMS((char *, struct addr_29k_t *, INT32));
int   addr_29k_ok PARAMS((struct addr_29k_t *));
int   get_word PARAMS((char *, INT32 *));
int   get_word_decimal PARAMS((char *, INT32 *));

INT32   clear_table PARAMS((void));
INT32   clear_bkpt PARAMS((struct addr_29k_t));
INT32   show_table PARAMS((void));
INT32   set_bkpt PARAMS((struct addr_29k_t,
			 INT32, 
			 INT32));

INT32 match_entry PARAMS((ADDR32 offset,
			  INT32 space,
			  int *id));
INT32 remove_from_table PARAMS((int id));

INT32 add_to_table PARAMS((ADDR32 offset, 
			   INT32 space,
			   INT32 passcnt,
			   INT32 bktype,
			   int id));

extern	struct	bkpt_t	*bkpt_table;

/*
** The function below is used in manipulating breakpoints.
** This function is called in the main command loop parser
** of the monitor.  The parameters passed to this function
** are:
**
** token - This is an array of pointers to strings.  Each string
**         referenced by this array is a "token" of the user's
**         input, translated to lower case.
**
** token_count - This is the number of tokens in "token".
**
*/


INT32
bkpt_cmd(token, token_count)
   char   *token[];
   int     token_count;
   {
   INT32    result;
   struct addr_29k_t addr_29k;
   INT32  pass_count;
   INT32  bkpt_type;

   /*
   ** Clear breakpoint(s)
   */
   if (strcmp(token[0], "bc") == 0) {
      if (token_count == 1) {
         result = clear_table();
         return (result);
         }
      else

      /* Clear a specific breakpoints */
      if (token_count == 2) {
         result = get_addr_29k_m(token[1], &addr_29k, I_MEM);
         if (result != 0)
            return (result);
         result = addr_29k_ok(&addr_29k);
         if (result != 0)
            return (result);
	 if (addr_29k.memory_space == (INT32) GENERIC_SPACE)
	    addr_29k.memory_space = (INT32) I_MEM;
         result = clear_bkpt(addr_29k);
         return (result);
         }
      else  /* token_count != 1 or 2 */
         return (EMSYNTAX);
      }
   else

   /*
   ** Set breakpoint(s)
   */

   if ((strcmp(token[0], "b") == 0) ||
       (strcmp(token[0], "b050p") == 0) ||
       (strcmp(token[0], "b050v") == 0) ||
       (strcmp(token[0], "b050") == 0)) { /* b050 defaults to b050p */

      if (strcmp(token[0], "b") == 0)
         bkpt_type = BKPT_29000;
      else
      if (strcmp(token[0], "b050p") == 0)
         bkpt_type = BKPT_29050_BTE_0;	/* translation disabled */
      else
      if (strcmp(token[0], "b050v") == 0)
         bkpt_type = BKPT_29050_BTE_1;
      else
      if (strcmp(token[0], "b050") == 0)
         bkpt_type = BKPT_29050_BTE_0;	/* translation disabled */
      else
         return (EMSYNTAX);

      if (token_count == 1) {
         result = show_table();
         return (result);
         }
      else

      /* Set breakpoint with pass count of 1 */
      if (token_count == 2) {
         result = get_addr_29k_m(token[1], &addr_29k, I_MEM);
         if (result != 0)
            return (result);
         result = addr_29k_ok(&addr_29k);
         if (result != 0)
            return (result);
         /* The TIP checks the memory space for acceptance */
	 if (addr_29k.memory_space == (INT32) GENERIC_SPACE)
	    addr_29k.memory_space = (INT32) I_MEM;
         result = set_bkpt(addr_29k, (INT32) 1, bkpt_type);
         return (result);
         }
      else

      /* Set breakpoint with pass count */
      if (token_count == 3) {
         result = get_addr_29k_m(token[1], &addr_29k, I_MEM);
         if (result != 0)
            return (result);
         result = addr_29k_ok(&addr_29k);
         if (result != 0)
            return (result);
         result = get_word_decimal(token[2], &pass_count);
         if (result != 0)
            return (EMSYNTAX);
	 if (addr_29k.memory_space == (INT32) GENERIC_SPACE)
	    addr_29k.memory_space = (INT32) I_MEM;
         result = set_bkpt(addr_29k, pass_count, bkpt_type);
         return (result);
         }
      else  /* too many parms for set breakpoint */
      return (EMSYNTAX);
      }
   else /* not a proper 'b" command */
      return (EMSYNTAX);

   }  /* end bkpt_cmd() */



/*
** Functions used by bkpt_cmd()
*/


/*
** This function is used to remove a breakpoint from the
** target and from the host breakpoint table.
*/

INT32
clear_bkpt(addr_29k)
   struct addr_29k_t  addr_29k;
{
   int	breakid;
   INT32	retval;

   (void) match_entry (addr_29k.address, 
		       addr_29k.memory_space,
		       &breakid);

   /* Did we find the breakpoint? */
   if (breakid <= (int) 0) {
      warning (EMBKPTRM);
      return (FAILURE);
   };

   /* if a valid breakpoint entry is found */
   if ((retval = Mini_bkpt_rm (breakid))  != SUCCESS) {
      return(FAILURE);
   } else if (retval == SUCCESS) {
      /* remove breakpoint from table */
      if (remove_from_table(breakid) != SUCCESS) {
	 /* this shouldn't occur */
	 return(FAILURE);
      };
      return(SUCCESS);
   };

}  /* end clear_bkpt() */



/*
** This function is used to set a breakpoint on the
** target and in the host breakpoint table.
*/

INT32
set_bkpt(addr_29k, pass_count, bkpt_type)
   struct   addr_29k_t addr_29k;
   INT32    pass_count;
   INT32    bkpt_type;
   {
   INT32	retval;
   int	breakid;

   /* is there one already at the same place */
   (void) match_entry(addr_29k.address, 
		      addr_29k.memory_space,
		      &breakid);

   if (breakid > (int) 0) {
      warning (EMBKPTUSED);
      return (FAILURE);
   };

   /* else set the breakpoint */
   breakid = (int) 0;
   if ((retval = Mini_bkpt_set (addr_29k.memory_space,
				addr_29k.address,
				pass_count,
				bkpt_type,
				&breakid)) != SUCCESS) {
       return(FAILURE);
   } else  {
      /* Add breakpoint to table */
      if (breakid > (int) 0) { /* double checking */
	 return (add_to_table(addr_29k.address,
		      addr_29k.memory_space,
		      pass_count,
		      bkpt_type,
		      breakid));
      };
      return(FAILURE);
   };
}  /* end set_bkpt() */



INT32
add_to_table(offset, space, passcnt, bktype, id )
ADDR32	offset;
INT32	space;
INT32	passcnt;
INT32	bktype;
int	id;
{
  struct   bkpt_t  *temp, *temp2;

  if ((temp = (struct bkpt_t *) malloc (sizeof(struct bkpt_t))) == NULL) {
     return(EMALLOC);
  } else {
    temp->break_id = id;
    temp->memory_space =  space;
    temp->address = offset;
    temp->pass_count = passcnt;
    temp->curr_count = passcnt;
    temp->bkpt_type = bktype;
    temp->next = NULL;
  };

  if (bkpt_table == NULL) { /* first element */
     bkpt_table = temp;
  } else { /* add at end */
     temp2 = bkpt_table;
     while (temp2->next != NULL)
       temp2 = temp2->next;
     temp2->next = temp;   /* add */
  }
  return(SUCCESS);
}

INT32
match_entry(offset, space, id)
ADDR32	offset;
INT32	space;
int	*id;
{
  struct  bkpt_t  *temp;

  if (bkpt_table == NULL) { /* empty, so no match */
    *id = (int) 0;
    return(SUCCESS);
  } else {
    temp = bkpt_table;
    if ((temp->address == offset) && 
		     (temp->memory_space == space)) { /* match */
       *id = temp->break_id;
       return(SUCCESS);
    } else {
       while (temp->next != NULL) {
	  if ((temp->next->address == offset) && 
	      (temp->next->memory_space == space)) {
	     *id = temp->next->break_id;
	     return(SUCCESS);
	  } else {
	     temp = temp->next;
	  };
       }
       *id = (int) 0;
       return(SUCCESS);
    };
  };
}

INT32
remove_from_table(id)
int   id;
{
  struct  bkpt_t  *temp;

  if (bkpt_table == NULL) { /* empty table */
     return(FAILURE);
  } else {
     temp = bkpt_table;
     if (bkpt_table->break_id == id) { /* remove first element */
	bkpt_table = bkpt_table->next;
	return(SUCCESS);
     } else {
	while (temp->next != NULL) {
	  if (temp->next->break_id == id) {
	     temp->next = temp->next->next;
	     return(SUCCESS);
	  } else {
	     temp = temp->next;
	  };
	}
	return(FAILURE);
     };
  }
}

INT32
clear_table()
{
  struct bkpt_t  *tmp;
  INT32	retval;


  if (bkpt_table == NULL) { /* no entries */
    fprintf(stderr, "no breakpoints in use.\n");
    if (io_config.echo_mode == (INT32) TRUE)
       fprintf(io_config.echo_file, "no breakpoints in use.\n");
  } else {
     while (bkpt_table) {
        if ((retval = Mini_bkpt_rm (bkpt_table->break_id))  != SUCCESS) {
           return(FAILURE);
        } else if (retval == SUCCESS) {
           /* remove breakpoint from table */
	   tmp = bkpt_table;
           bkpt_table = bkpt_table->next;
	   (void) free ((char *) tmp);
        };
     };
  }
  return(SUCCESS);
}

INT32
show_table()
{
  struct  bkpt_t  *temp;
   INT32	retval;
   ADDR32	temp_addr;
   INT32	temp_space;
   INT32	curr_count;
   INT32	temp_passcnt, temp_bktype;
   int		i;

  if (bkpt_table == NULL) { /* no entries */
  } else {
    do {
       temp = bkpt_table;
       bkpt_table = bkpt_table->next;
       (void) free ((char *) temp);
    } while (bkpt_table != NULL);
  };

  for (i = 1;1;i++) {
     retval = Mini_bkpt_stat( i,
			      &temp_addr,
			      &temp_space,
			      &temp_passcnt,
			      &temp_bktype,
			      &curr_count);
     if ((retval == (INT32) MONBreakInvalid) ||
         (retval == (INT32) FAILURE)) {
	continue;
     } else if (retval == (INT32) MONBreakNoMore) {
	return (SUCCESS);
     } else {
	 /* add entry in the table */
	 if ((retval = add_to_table ((ADDR32) temp_addr,
		       		(INT32) temp_space,
		       		(INT32) temp_passcnt,
		       		(INT32) temp_bktype,
		       		i)) != SUCCESS)
		return (retval);
         /* Mark Am29050 breakpoints with a '*' */
         if (temp_bktype == BKPT_29050)
             fprintf(stderr, "*");
         else
             fprintf(stderr, " ");
         fprintf(stderr, "(%#05d: %#08lx[%#02d])\n", i, 
			       temp_addr, 
			       temp_passcnt);
	 if (io_config.echo_mode == (INT32) TRUE)  {
             if (temp_bktype == BKPT_29050)
                 fprintf(io_config.echo_file, "*");
             else
                fprintf(io_config.echo_file, " ");
             fprintf(io_config.echo_file, "(%#05d: %#08lx[%#02d])\n", i, 
				       temp_addr, 
				       temp_passcnt);
	 }
     };
  }
  return(SUCCESS);
}