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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [cygmon/] [current/] [misc/] [bplist-dynamic.c] - Blame information for rev 786

Details | Compare with Previous | View Log

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