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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [common/] [v2_0/] [src/] [bplist-dynamic.c] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//      bplist-dynamic.c
4
//
5
//      Dynamic breakpoint list.
6
//      Currently only statically allocated.  (ie NO_MALLOC is assumed)
7
//
8
//==========================================================================
9
//####ECOSGPLCOPYRIGHTBEGIN####
10
// -------------------------------------------
11
// This file is part of eCos, the Embedded Configurable Operating System.
12
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
13
//
14
// eCos is free software; you can redistribute it and/or modify it under
15
// the terms of the GNU General Public License as published by the Free
16
// Software Foundation; either version 2 or (at your option) any later version.
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
19
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
21
// for more details.
22
//
23
// You should have received a copy of the GNU General Public License along
24
// with eCos; if not, write to the Free Software Foundation, Inc.,
25
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26
//
27
// As a special exception, if other files instantiate templates or use macros
28
// or inline functions from this file, or you compile this file and link it
29
// with other works to produce a work based on this file, this file does not
30
// by itself cause the resulting work to be covered by the GNU General Public
31
// License. However the source code for this file must still be made available
32
// in accordance with section (3) of the GNU General Public License.
33
//
34
// This exception does not invalidate any other reasons why a work based on
35
// this file might be covered by the GNU General Public License.
36
//
37
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
38
// at http://sources.redhat.com/ecos/ecos-license/
39
// -------------------------------------------
40
//####ECOSGPLCOPYRIGHTEND####
41
//==========================================================================
42
//#####DESCRIPTIONBEGIN####
43
//
44
// Author(s):    
45
// Contributors: dmoseley
46
// Date:         2000-07-11
47
// Purpose:      Dynamic breakpoint list.
48
// Description:  
49
//               
50
//
51
//####DESCRIPTIONEND####
52
//
53
//=========================================================================
54
 
55
#include <pkgconf/system.h>
56
#include <pkgconf/hal.h>
57
 
58
#if defined(CYGNUM_HAL_BREAKPOINT_LIST_SIZE) && (CYGNUM_HAL_BREAKPOINT_LIST_SIZE > 0) && defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS)
59
 
60
#define CYGARC_HAL_COMMON_EXPORT_CPU_MACROS
61
#include <cyg/hal/hal_stub.h>
62
#include <cyg/hal/hal_arch.h>
63
#include <cyg/hal/hal_cache.h>
64
 
65
#ifdef TARGET_HAS_HARVARD_MEMORY
66
#define __read_mem_safe __read_progmem_safe
67
#define __write_mem_safe __write_progmem_safe
68
#endif
69
 
70
/*
71
 * A simple target breakpoint list without using malloc.
72
 * To use this package, you must define HAL_BREAKINST_SIZE to be the size
73
 * in bytes of a trap instruction (max if there's more than one),
74
 * HAL_BREAKINST to the opcode value of the instruction, and
75
 * HAL_BREAKINST_TYPE to be the type necessary to hold the opcode value.
76
 */
77
 
78
struct breakpoint_list {
79
  target_register_t  addr;
80
  char old_contents [HAL_BREAKINST_SIZE];
81
  struct breakpoint_list *next;
82
  char in_memory;
83
  char length;
84
} *breakpoint_list = NULL;
85
 
86
#ifndef HAL_BREAKINST_ADDR
87
static HAL_BREAKINST_TYPE break_inst = HAL_BREAKINST;
88
#define HAL_BREAKINST_ADDR(x) ((void*)&break_inst)
89
#endif
90
 
91
static struct breakpoint_list bp_list [CYGNUM_HAL_BREAKPOINT_LIST_SIZE];
92
static struct breakpoint_list *free_bp_list = NULL;
93
static int curr_bp_num = 0;
94
 
95
int
96
__set_breakpoint (target_register_t addr, target_register_t len)
97
{
98
  struct breakpoint_list **addent = &breakpoint_list;
99
  struct breakpoint_list *l = breakpoint_list;
100
  struct breakpoint_list *newent;
101
 
102
  while (l != NULL && l->addr < addr)
103
    {
104
      addent = &l->next;
105
      l =  l->next;
106
    }
107
 
108
  if (l != NULL && l->addr == addr)
109
    return 2;
110
 
111
  if (free_bp_list != NULL)
112
    {
113
      newent = free_bp_list;
114
      free_bp_list = free_bp_list->next;
115
    }
116
  else
117
    {
118
      if (curr_bp_num < CYGNUM_HAL_BREAKPOINT_LIST_SIZE)
119
        {
120
          newent = &bp_list[curr_bp_num++];
121
        }
122
      else
123
        {
124
          return 1;
125
        }
126
    }
127
 
128
  newent->addr = addr;
129
  newent->in_memory = 0;
130
  newent->next = l;
131
  newent->length = len;
132
  *addent = newent;
133
 
134
  return 0;
135
}
136
 
137
int
138
__remove_breakpoint (target_register_t addr, target_register_t len)
139
{
140
  struct breakpoint_list *l = breakpoint_list;
141
  struct breakpoint_list *prev = NULL;
142
 
143
  while (l != NULL && l->addr < addr)
144
    {
145
      prev = l;
146
      l = l->next;
147
    }
148
 
149
  if ((l == NULL) || (l->addr != addr))
150
    return 1;
151
 
152
  if (l->in_memory)
153
    {
154
      __write_mem_safe (&l->old_contents[0],
155
                        (void*)l->addr,
156
                        sizeof (l->old_contents));
157
    }
158
 
159
  if (prev == NULL)
160
    breakpoint_list = l->next;
161
  else
162
    prev->next = l->next;
163
 
164
  l->next = free_bp_list;
165
  free_bp_list = l;
166
 
167
  return 0;
168
}
169
 
170
#if defined(HAL_STUB_HW_BREAKPOINT_LIST_SIZE) && (HAL_STUB_HW_BREAKPOINT_LIST_SIZE > 0)
171
#ifndef HAL_STUB_HW_BREAKPOINT
172
#error "Must define HAL_STUB_HW_BREAKPOINT"
173
#endif
174
struct hw_breakpoint_list {
175
  target_register_t  addr;
176
  target_register_t  len;
177
  char used;
178
  char installed;
179
};
180
static struct hw_breakpoint_list hw_bp_list [HAL_STUB_HW_BREAKPOINT_LIST_SIZE];
181
 
182
int
183
__set_hw_breakpoint (target_register_t addr, target_register_t len)
184
{
185
  int i;
186
 
187
  for (i = 0; i < HAL_STUB_HW_BREAKPOINT_LIST_SIZE; i++)
188
    {
189
      if (hw_bp_list[i].used == 0)
190
        {
191
          hw_bp_list[i].addr = addr;
192
          hw_bp_list[i].len = len;
193
          hw_bp_list[i].used = 1;
194
          hw_bp_list[i].installed = 0;
195
          return 0;
196
        }
197
    }
198
  return -1;
199
}
200
 
201
int
202
__remove_hw_breakpoint (target_register_t addr, target_register_t len)
203
{
204
  int i;
205
 
206
  for (i = 0; i < HAL_STUB_HW_BREAKPOINT_LIST_SIZE; i++)
207
    {
208
      if (hw_bp_list[i].used && hw_bp_list[i].addr == addr
209
          && hw_bp_list[i].len == len)
210
        {
211
          if (hw_bp_list[i].installed)
212
            HAL_STUB_HW_BREAKPOINT(0, (void *)addr, (int)len);
213
          hw_bp_list[i].used = 0;
214
          return 0;
215
        }
216
    }
217
  return -1;
218
}
219
 
220
static void
221
__install_hw_breakpoint_list (void)
222
{
223
  int i;
224
 
225
  for (i = 0; i < HAL_STUB_HW_BREAKPOINT_LIST_SIZE; i++)
226
    {
227
      if (hw_bp_list[i].used && hw_bp_list[i].installed == 0)
228
        {
229
          HAL_STUB_HW_BREAKPOINT(1, (void *)hw_bp_list[i].addr,
230
                                 (int)hw_bp_list[i].len);
231
          hw_bp_list[i].installed = 1;
232
        }
233
    }
234
}
235
 
236
static void
237
__clear_hw_breakpoint_list (void)
238
{
239
  int i;
240
 
241
  for (i = 0; i < HAL_STUB_HW_BREAKPOINT_LIST_SIZE; i++)
242
    {
243
      if (hw_bp_list[i].used && hw_bp_list[i].installed)
244
        {
245
          HAL_STUB_HW_BREAKPOINT(0, (void *)hw_bp_list[i].addr,
246
                                 (int)hw_bp_list[i].len);
247
          hw_bp_list[i].installed = 0;
248
        }
249
    }
250
}
251
#endif // HAL_STUB_HW_BREAKPOINT_LIST_SIZE
252
 
253
#if defined(HAL_STUB_HW_WATCHPOINT_LIST_SIZE) && (HAL_STUB_HW_WATCHPOINT_LIST_SIZE > 0)
254
#ifndef HAL_STUB_HW_WATCHPOINT
255
#error "Must define HAL_STUB_HW_WATCHPOINT"
256
#endif
257
struct hw_watchpoint_list {
258
  target_register_t  addr;
259
  target_register_t  len;
260
  int ztype;
261
  char used;
262
  char installed;
263
};
264
static struct hw_watchpoint_list hw_wp_list [HAL_STUB_HW_WATCHPOINT_LIST_SIZE];
265
 
266
int
267
__set_hw_watchpoint (target_register_t addr, target_register_t len, int ztype)
268
{
269
  int i;
270
 
271
  for (i = 0; i < HAL_STUB_HW_WATCHPOINT_LIST_SIZE; i++)
272
    {
273
      if (hw_wp_list[i].used == 0)
274
        {
275
          hw_wp_list[i].addr = addr;
276
          hw_wp_list[i].len = len;
277
          hw_wp_list[i].ztype = ztype;
278
          hw_wp_list[i].used = 1;
279
          hw_wp_list[i].installed = 0;
280
          return 0;
281
        }
282
    }
283
  return -1;
284
}
285
 
286
int
287
__remove_hw_watchpoint (target_register_t addr, target_register_t len, int ztype)
288
{
289
  int i;
290
 
291
  for (i = 0; i < HAL_STUB_HW_WATCHPOINT_LIST_SIZE; i++)
292
    {
293
      if (hw_wp_list[i].used && hw_wp_list[i].addr == addr
294
          && hw_wp_list[i].len == len && hw_wp_list[i].ztype == ztype )
295
        {
296
          if (hw_wp_list[i].installed)
297
            HAL_STUB_HW_WATCHPOINT(0, (void *)addr, (int)len, ztype);
298
          hw_wp_list[i].used = 0;
299
          return 0;
300
        }
301
    }
302
  return -1;
303
}
304
 
305
static void
306
__install_hw_watchpoint_list (void)
307
{
308
  int i;
309
 
310
  for (i = 0; i < HAL_STUB_HW_WATCHPOINT_LIST_SIZE; i++)
311
    {
312
      if (hw_wp_list[i].used && hw_wp_list[i].installed == 0)
313
        {
314
          HAL_STUB_HW_WATCHPOINT(1, (void *)hw_wp_list[i].addr,
315
                                 (int)hw_wp_list[i].len, hw_wp_list[i].ztype);
316
          hw_wp_list[i].installed = 1;
317
        }
318
    }
319
}
320
 
321
static void
322
__clear_hw_watchpoint_list (void)
323
{
324
  int i;
325
 
326
  for (i = 0; i < HAL_STUB_HW_WATCHPOINT_LIST_SIZE; i++)
327
    {
328
      if (hw_wp_list[i].used && hw_wp_list[i].installed)
329
        {
330
          HAL_STUB_HW_WATCHPOINT(0, (void *)hw_wp_list[i].addr,
331
                                 (int)hw_wp_list[i].len, hw_wp_list[i].ztype);
332
          hw_wp_list[i].installed = 0;
333
        }
334
    }
335
}
336
#endif // HAL_STUB_HW_WATCHPOINT_LIST_SIZE
337
 
338
 
339
 
340
void
341
__install_breakpoint_list (void)
342
{
343
  struct breakpoint_list *l = breakpoint_list;
344
 
345
  while (l != NULL)
346
    {
347
      if (! l->in_memory)
348
        {
349
          int len = sizeof (l->old_contents);
350
          if (__read_mem_safe (&l->old_contents[0], (void*)l->addr, len) == len)
351
            {
352
              if (__write_mem_safe (HAL_BREAKINST_ADDR(l->length),
353
                                    (void*)l->addr, l->length) == l->length)
354
                {
355
                  l->in_memory = 1;
356
                }
357
            }
358
        }
359
      l = l->next;
360
    }
361
#if defined(HAL_STUB_HW_BREAKPOINT_LIST_SIZE) && (HAL_STUB_HW_BREAKPOINT_LIST_SIZE > 0)
362
  __install_hw_breakpoint_list();
363
#endif
364
#if defined(HAL_STUB_HW_WATCHPOINT_LIST_SIZE) && (HAL_STUB_HW_WATCHPOINT_LIST_SIZE > 0)
365
  __install_hw_watchpoint_list();
366
#endif
367
  HAL_ICACHE_SYNC();
368
}
369
 
370
void
371
__clear_breakpoint_list (void)
372
{
373
  struct breakpoint_list *l = breakpoint_list;
374
 
375
  while (l != NULL)
376
    {
377
      if (l->in_memory)
378
        {
379
          int len = sizeof (l->old_contents);
380
          if (__write_mem_safe (&l->old_contents[0], (void*)l->addr, len) == len)
381
            {
382
              l->in_memory = 0;
383
            }
384
        }
385
      l = l->next;
386
    }
387
#if defined(HAL_STUB_HW_BREAKPOINT_LIST_SIZE) && (HAL_STUB_HW_BREAKPOINT_LIST_SIZE > 0)
388
  __clear_hw_breakpoint_list();
389
#endif
390
#if defined(HAL_STUB_HW_WATCHPOINT_LIST_SIZE) && (HAL_STUB_HW_WATCHPOINT_LIST_SIZE > 0)
391
  __clear_hw_watchpoint_list();
392
#endif
393
  HAL_ICACHE_INVALIDATE_ALL();
394
}
395
 
396
int
397
__display_breakpoint_list (void (*print_func)(target_register_t))
398
{
399
  struct breakpoint_list *l = breakpoint_list;
400
 
401
  while (l != NULL)
402
    {
403
      print_func(l->addr);
404
      l = l->next;
405
    }
406
 
407
  return 0;
408
}
409
#else  // (CYGNUM_HAL_BREAKPOINT_LIST_SIZE == 0) or UNDEFINED
410
 
411
#include <cyg/hal/hal_stub.h>           // Our header
412
 
413
#ifndef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
414
// We don't know that type target_register_t is yet.
415
// Let's just pick a type so we can compile.  Since
416
// these versions of the functions don't actually do
417
// anything with the parameters, the actualy types
418
// don't matter.
419
typedef unsigned long target_register_t;
420
#endif
421
 
422
int
423
__set_breakpoint (target_register_t addr, target_register_t len)
424
{
425
  return 1;
426
}
427
 
428
int
429
__remove_breakpoint (target_register_t addr, target_register_t len)
430
{
431
  return 1;
432
}
433
 
434
void
435
__install_breakpoint_list (void)
436
{
437
}
438
 
439
void
440
__clear_breakpoint_list (void)
441
{
442
}
443
 
444
int
445
__display_breakpoint_list (void (*print_func)(target_register_t))
446
{
447
    return 0;
448
}
449
#endif // (CYGNUM_HAL_BREAKPOINT_LIST_SIZE > 0)
450
 

powered by: WebSVN 2.1.0

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