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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [cygmon/] [v2_0/] [misc/] [bplist-dynamic.c] - Blame information for rev 234

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

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//      bplist-dynamic.c
4
//
5
//      Breakpoint list using dynamic memory.
6
//
7
//==========================================================================
8
//####ECOSGPLCOPYRIGHTBEGIN####
9
// -------------------------------------------
10
// This file is part of eCos, the Embedded Configurable Operating System.
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under
14
// the terms of the GNU General Public License as published by the Free
15
// Software Foundation; either version 2 or (at your option) any later version.
16
//
17
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20
// for more details.
21
//
22
// You should have received a copy of the GNU General Public License along
23
// with eCos; if not, write to the Free Software Foundation, Inc.,
24
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25
//
26
// As a special exception, if other files instantiate templates or use macros
27
// or inline functions from this file, or you compile this file and link it
28
// with other works to produce a work based on this file, this file does not
29
// by itself cause the resulting work to be covered by the GNU General Public
30
// License. However the source code for this file must still be made available
31
// in accordance with section (3) of the GNU General Public License.
32
//
33
// This exception does not invalidate any other reasons why a work based on
34
// this file might be covered by the GNU General Public License.
35
//
36
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37
// at http://sources.redhat.com/ecos/ecos-license/
38
// -------------------------------------------
39
//####ECOSGPLCOPYRIGHTEND####
40
//==========================================================================
41
//#####DESCRIPTIONBEGIN####
42
//
43
// Author(s):    
44
// Contributors: gthomas
45
// Date:         1999-10-20
46
// Purpose:      Breakpoint list using dynamic memory.
47
// Description:  
48
//               
49
//
50
//####DESCRIPTIONEND####
51
//
52
//=========================================================================
53
 
54
#include "board.h"
55
 
56
#ifndef USE_ECOS_HAL_BREAKPOINTS
57
 
58
#include <stdlib.h>
59
 
60
#ifndef NO_MALLOC
61
#ifndef NO_MALLOC_H
62
#include "malloc.h"
63
#else
64
void free ();
65
char *malloc ();
66
#endif
67
#endif
68
 
69
#ifdef __ECOS__
70
#include <cyg/hal/plf_stub.h>
71
#endif /* __ECOS__ */
72
 
73
/*
74
 * A simple target breakpoint list using malloc.
75
 * To use this package, you must define TRAP_SIZE to be the size
76
 * in bytes of a trap instruction (max if there's more than one),
77
 * and export a char array called _breakinst that contains a
78
 * breakpoint trap.  This package will copy trap instructions
79
 * from _breakinst into the breakpoint locations.
80
 */
81
 
82
static struct breakpoint_list {
83
  target_register_t  addr;
84
  char old_contents [TRAP_SIZE];
85
  struct breakpoint_list *next;
86
  char in_memory;
87
} *breakpoint_list = NULL;
88
 
89
#ifdef NO_MALLOC
90
static struct breakpoint_list bp_list [MAX_BP_NUM];
91
static struct breakpoint_list *free_bp_list = NULL;
92
static int curr_bp_num = 0;
93
#endif
94
 
95
#ifndef BREAKINST_DEFINED
96
#define BREAKINST_DEFINED
97
extern unsigned char _breakinst[];
98
#endif
99
 
100
int
101
__set_breakpoint (target_register_t addr)
102
{
103
  struct breakpoint_list **addent = &breakpoint_list;
104
  struct breakpoint_list *l = breakpoint_list;
105
  struct breakpoint_list *newent;
106
 
107
  while (l != NULL && l->addr < addr)
108
    {
109
      addent = &l->next;
110
      l =  l->next;
111
    }
112
 
113
  if (l != NULL && l->addr == addr)
114
    return 2;
115
 
116
#ifdef NO_MALLOC
117
  if (free_bp_list != NULL)
118
    {
119
      newent = free_bp_list;
120
      free_bp_list = free_bp_list->next;
121
    }
122
  else
123
    {
124
      if (curr_bp_num < MAX_BP_NUM)
125
        {
126
          newent = &bp_list[curr_bp_num++];
127
        }
128
      else
129
        {
130
          return 1;
131
        }
132
    }
133
#else
134
  newent = (struct breakpoint_list *) malloc (sizeof (struct breakpoint_list));
135
#endif
136
  newent->addr = addr;
137
  newent->in_memory = 0;
138
  newent->next = l;
139
  *addent = newent;
140
  return 0;
141
}
142
 
143
int
144
__remove_breakpoint (target_register_t addr)
145
{
146
  struct breakpoint_list *l = breakpoint_list;
147
  struct breakpoint_list *prev = NULL;
148
 
149
  while (l != NULL && l->addr < addr)
150
    {
151
      prev = l;
152
      l = l->next;
153
    }
154
 
155
  if (l == NULL)
156
    return 1;
157
 
158
  if (l->in_memory)
159
    {
160
      __write_mem_safe (&l->old_contents[0],
161
                        (void*)l->addr,
162
                        sizeof (l->old_contents));
163
    }
164
 
165
  if (prev == NULL)
166
    breakpoint_list = l->next;
167
  else
168
    prev->next = l->next;
169
 
170
#ifdef NO_MALLOC
171
  l->next = free_bp_list;
172
  free_bp_list = l;
173
#else
174
  free (l);
175
#endif
176
  return 0;
177
}
178
 
179
#include <cyg/hal/generic-stub.h>
180
#include <cyg/hal/hal_stub.h>
181
void
182
__cygmon_install_breakpoints (void)
183
{
184
  struct breakpoint_list *l = breakpoint_list;
185
 
186
  while (l != NULL)
187
    {
188
      if (! l->in_memory)
189
        {
190
          int len = sizeof (l->old_contents);
191
 
192
          if (__read_mem_safe (&l->old_contents[0], (void*)l->addr, len) == len)
193
            {
194
#ifdef WRITE_MEM_IS_MEMCPY
195
              if (__write_mem_safe (_breakinst, (void*)l->addr, len) == (void*)l->addr)
196
#else
197
              if (__write_mem_safe (_breakinst, (void*)l->addr, len) == len)
198
#endif
199
                {
200
                  l->in_memory = 1;
201
                }
202
            }
203
        }
204
      l = l->next;
205
    }
206
  flush_i_cache ();
207
}
208
 
209
void
210
__cygmon_clear_breakpoints (void)
211
{
212
  struct breakpoint_list *l = breakpoint_list;
213
 
214
  while (l != NULL)
215
    {
216
      if (l->in_memory)
217
        {
218
          int len = sizeof (l->old_contents);
219
 
220
#ifdef WRITE_MEM_IS_MEMCPY
221
      if (__write_mem_safe (_breakinst, (void*)l->addr, len) == (void*)l->addr)
222
#else
223
          if (__write_mem_safe (&l->old_contents[0], (void*)l->addr, len) == len)
224
#endif
225
            {
226
              l->in_memory = 0;
227
            }
228
        }
229
      l = l->next;
230
    }
231
  flush_i_cache ();
232
}
233
 
234
#endif // USE_ECOS_HAL_BREAKPOINTS

powered by: WebSVN 2.1.0

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