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

Subversion Repositories or1k

[/] [or1k/] [tags/] [rel-0-3-0-rc2/] [or1ksim/] [cpu/] [common/] [labels.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 269 markom
/* abstract.c -- Abstract entities, handling labels
2 1748 jeremybenn
 
3 269 markom
   Copyright (C) 2001 Marko Mlinar, markom@opencores.org
4 1748 jeremybenn
   Copyright (C) 2008 Embecosm Limited
5 269 markom
 
6 1748 jeremybenn
   Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
7 269 markom
 
8 1748 jeremybenn
   This file is part of Or1ksim, the OpenRISC 1000 Architectural Simulator.
9 269 markom
 
10 1748 jeremybenn
   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 269 markom
 
15 1748 jeremybenn
   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 269 markom
 
20 1748 jeremybenn
   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 269 markom
 
23 1748 jeremybenn
/* This program is commented throughout in a fashion suitable for processing
24
   with Doxygen. */
25 269 markom
 
26 1748 jeremybenn
/* 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 1350 nogj
 
29
 
30 1748 jeremybenn
/* Autoconf and/or portability configuration */
31
#include "config.h"
32 1350 nogj
#include "port.h"
33 269 markom
 
34 1748 jeremybenn
/* System includes */
35
#include <stdlib.h>
36
 
37
/* Package includes */
38 269 markom
#include "labels.h"
39
 
40 1748 jeremybenn
#define LABELS_HASH_SIZE 119
41
 
42
/* Globally visible list of breakpoints */
43 557 markom
struct breakpoint_entry *breakpoints;
44 269 markom
 
45 1748 jeremybenn
/* Local list of labels (symbols) */
46
static struct label_entry *label_hash[LABELS_HASH_SIZE];
47
 
48
 
49
void
50
init_labels ()
51
{
52 269 markom
  int i;
53
  for (i = 0; i < LABELS_HASH_SIZE; i++)
54
    label_hash[i] = NULL;
55
}
56
 
57 1748 jeremybenn
void
58
add_label (oraddr_t addr, char *name)
59
{
60 269 markom
  struct label_entry **tmp;
61
  tmp = &(label_hash[addr % LABELS_HASH_SIZE]);
62 1748 jeremybenn
  for (; *tmp; tmp = &((*tmp)->next));
63
  *tmp = malloc (sizeof (**tmp));
64
  (*tmp)->name = malloc (strlen (name) + 1);
65
  (*tmp)->addr = addr;
66
  strcpy ((*tmp)->name, name);
67
  (*tmp)->next = NULL;
68 269 markom
}
69
 
70 1748 jeremybenn
struct label_entry *
71
get_label (oraddr_t addr)
72
{
73 269 markom
  struct label_entry *tmp = label_hash[addr % LABELS_HASH_SIZE];
74 1748 jeremybenn
  while (tmp)
75
    {
76
      if (tmp->addr == addr)
77
        return tmp;
78
      tmp = tmp->next;
79
    }
80 269 markom
  return NULL;
81
}
82
 
83 1748 jeremybenn
struct label_entry *
84
find_label (char *name)
85
{
86 269 markom
  int i;
87 1748 jeremybenn
  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 269 markom
    }
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 1748 jeremybenn
oraddr_t
103
eval_label (char *name)
104
{
105 269 markom
  struct label_entry *le;
106
  char *plus;
107
  char *minus;
108
  int positive_offset = 0;
109
  int negative_offset = 0;
110
 
111 1748 jeremybenn
  if ((plus = strchr (name, '+')))
112
    {
113
      *plus = '\0';
114
      positive_offset = atoi (++plus);
115
    }
116 269 markom
 
117 1748 jeremybenn
  if ((minus = strchr (name, '-')))
118
    {
119
      *minus = '\0';
120
      negative_offset = atoi (++minus);
121
    }
122 269 markom
  le = find_label (name);
123
  if (!le)
124
    return 0;
125 1748 jeremybenn
 
126 269 markom
  return le->addr + positive_offset - negative_offset;
127
}
128
 
129 1748 jeremybenn
void
130
init_breakpoints ()
131
{
132 269 markom
  breakpoints = 0;
133
}
134
 
135 1748 jeremybenn
void
136
add_breakpoint (oraddr_t addr)
137
{
138 269 markom
  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 1748 jeremybenn
void
146
remove_breakpoint (oraddr_t addr)
147
{
148 269 markom
  struct breakpoint_entry **tmp = &breakpoints;
149 1748 jeremybenn
  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 269 markom
}
161
 
162 1748 jeremybenn
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 1049 ivang
    }
173 1748 jeremybenn
  printf ("---[breakpoints end]--------------\n");
174 1049 ivang
}
175
 
176 1748 jeremybenn
int
177
has_breakpoint (oraddr_t addr)
178
{
179 269 markom
  struct breakpoint_entry *tmp = breakpoints;
180 1748 jeremybenn
  while (tmp)
181
    {
182
      if (tmp->addr == addr)
183
        return 1;
184
      tmp = tmp->next;
185
    }
186 269 markom
  return 0;
187
}

powered by: WebSVN 2.1.0

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