OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [or1ksim/] [cpu/] [common/] [labels.c] - Blame information for rev 159

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

Line No. Rev Author Line
1 101 jeremybenn
/* labels.c -- Abstract entities, handling labels
2 19 jeremybenn
 
3
   Copyright (C) 2001 Marko Mlinar, markom@opencores.org
4
   Copyright (C) 2008 Embecosm Limited
5
 
6
   Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
7
 
8
   This file is part of Or1ksim, the OpenRISC 1000 Architectural Simulator.
9
 
10
   This program is free software; you can redistribute it and/or modify it
11
   under the terms of the GNU General Public License as published by the Free
12
   Software Foundation; either version 3 of the License, or (at your option)
13
   any later version.
14
 
15
   This program is distributed in the hope that it will be useful, but WITHOUT
16
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
18
   more details.
19
 
20
   You should have received a copy of the GNU General Public License along
21
   with this program.  If not, see <http://www.gnu.org/licenses/>.  */
22
 
23
/* This program is commented throughout in a fashion suitable for processing
24
   with Doxygen. */
25
 
26
/* Abstract memory and routines that go with this. I need to add all sorts of
27
   other abstract entities. Currently we have only memory. */
28
 
29
 
30
/* Autoconf and/or portability configuration */
31
#include "config.h"
32
#include "port.h"
33
 
34
/* System includes */
35
#include <stdlib.h>
36
 
37
/* Package includes */
38
#include "labels.h"
39
 
40
#define LABELS_HASH_SIZE 119
41
 
42
/* Globally visible list of breakpoints */
43
struct breakpoint_entry *breakpoints;
44
 
45
/* Local list of labels (symbols) */
46
static struct label_entry *label_hash[LABELS_HASH_SIZE];
47
 
48
 
49
void
50
init_labels ()
51
{
52
  int i;
53
  for (i = 0; i < LABELS_HASH_SIZE; i++)
54
    label_hash[i] = NULL;
55
}
56
 
57
void
58
add_label (oraddr_t addr, char *name)
59
{
60
  struct label_entry **tmp;
61 101 jeremybenn
  tmp = &(label_hash[addr % LABELS_HASH_SIZE]);
62 100 julius
  for (; *tmp; tmp = &((*tmp)->next)); // Find the next NULL label entry pointer (loop while the pointer de-refernce is non-NULL)
63
  *tmp = malloc (sizeof (**tmp)); // allocate space for the pointer to the hash entry pointer
64
  (*tmp)->name = malloc (strlen (name) + 1); // now allocate space for the name string
65 19 jeremybenn
  (*tmp)->addr = addr;
66
  strcpy ((*tmp)->name, name);
67
  (*tmp)->next = NULL;
68
}
69
 
70
struct label_entry *
71
get_label (oraddr_t addr)
72
{
73
  struct label_entry *tmp = label_hash[addr % LABELS_HASH_SIZE];
74
  while (tmp)
75
    {
76
      if (tmp->addr == addr)
77
        return tmp;
78
      tmp = tmp->next;
79
    }
80
  return NULL;
81
}
82
 
83
struct label_entry *
84
find_label (char *name)
85
{
86
  int i;
87
  for (i = 0; i < LABELS_HASH_SIZE; i++)
88
    {
89
      struct label_entry *tmp = label_hash[i % LABELS_HASH_SIZE];
90
      while (tmp)
91
        {
92
          if (strcmp (tmp->name, name) == 0)
93
            return tmp;
94
          tmp = tmp->next;
95
        }
96
    }
97
  return NULL;
98
}
99
 
100
/* Searches mem array for a particular label and returns label's address.
101
   If label does not exist, returns 0. */
102
oraddr_t
103
eval_label (char *name)
104
{
105
  struct label_entry *le;
106
  char *plus;
107
  char *minus;
108
  int positive_offset = 0;
109
  int negative_offset = 0;
110
 
111
  if ((plus = strchr (name, '+')))
112
    {
113
      *plus = '\0';
114
      positive_offset = atoi (++plus);
115
    }
116
 
117
  if ((minus = strchr (name, '-')))
118
    {
119
      *minus = '\0';
120
      negative_offset = atoi (++minus);
121
    }
122
  le = find_label (name);
123
  if (!le)
124
    return 0;
125
 
126
  return le->addr + positive_offset - negative_offset;
127
}
128
 
129
void
130
init_breakpoints ()
131
{
132
  breakpoints = 0;
133
}
134
 
135
void
136
add_breakpoint (oraddr_t addr)
137
{
138
  struct breakpoint_entry *tmp;
139
  tmp = (struct breakpoint_entry *) malloc (sizeof (struct breakpoint_entry));
140
  tmp->next = breakpoints;
141
  tmp->addr = addr;
142
  breakpoints = tmp;
143
}
144
 
145
void
146
remove_breakpoint (oraddr_t addr)
147
{
148
  struct breakpoint_entry **tmp = &breakpoints;
149
  while (*tmp)
150
    {
151
      if ((*tmp)->addr == addr)
152
        {
153
          struct breakpoint_entry *t = *tmp;
154
          (*tmp) = t->next;
155
          free (t);
156
        }
157
      else
158
        tmp = &((*tmp)->next);
159
    }
160
}
161
 
162
void
163
print_breakpoints ()
164
{
165
  struct breakpoint_entry **tmp = &breakpoints;
166
  int i = 1;
167
  printf ("---[breakpoints]------------------\n");
168
  while (*tmp)
169
    {
170
      printf ("Breakpoint %i at 0x%" PRIxADDR "\n", i, (*tmp)->addr);
171
      tmp = &((*tmp)->next);
172
    }
173
  printf ("---[breakpoints end]--------------\n");
174
}
175
 
176
int
177
has_breakpoint (oraddr_t addr)
178
{
179
  struct breakpoint_entry *tmp = breakpoints;
180
  while (tmp)
181
    {
182
      if (tmp->addr == addr)
183
        return 1;
184
      tmp = tmp->next;
185
    }
186
  return 0;
187
}

powered by: WebSVN 2.1.0

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