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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_47/] [or1ksim/] [cpu/] [common/] [labels.c] - Blame information for rev 269

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

Line No. Rev Author Line
1 269 markom
/* abstract.c -- Abstract entities, handling labels
2
   Copyright (C) 2001 Marko Mlinar, markom@opencores.org
3
 
4
This file is part of OpenRISC 1000 Architectural Simulator.
5
 
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
10
 
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
GNU General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
 
20
/* Abstract memory and routines that go with this. I need to
21
add all sorts of other abstract entities. Currently we have
22
only memory. */
23
 
24
#include <stdlib.h>
25
#include <stdio.h>
26
#include <ctype.h>
27
#include <string.h>
28
 
29
#include "config.h"
30
#include "sim-config.h"
31
 
32
#include "labels.h"
33
 
34
static struct label_entry *label_hash[LABELS_HASH_SIZE];
35
static struct breakpoint_entry *breakpoints;
36
 
37
void init_labels () {
38
  int i;
39
  for (i = 0; i < LABELS_HASH_SIZE; i++)
40
    label_hash[i] = NULL;
41
}
42
 
43
void add_label (unsigned long addr, char *name) {
44
  struct label_entry **tmp;
45
  tmp = &(label_hash[addr % LABELS_HASH_SIZE]);
46
        for (; *tmp; tmp = &((*tmp)->next));
47
        *tmp = malloc(sizeof(**tmp));
48
        (*tmp)->name = malloc(strlen(name) + 1);
49
        (*tmp)->addr = addr;
50
        strcpy((*tmp)->name, name);
51
        (*tmp)->next = NULL;
52
}
53
 
54
struct label_entry *get_label (unsigned long addr) {
55
  struct label_entry *tmp = label_hash[addr % LABELS_HASH_SIZE];
56
  while (tmp) {
57
    if (tmp->addr == addr)
58
      return tmp;
59
    tmp = tmp->next;
60
  }
61
  return NULL;
62
}
63
 
64
struct label_entry *find_label (char *name) {
65
  int i;
66
  for (i = 0; i < LABELS_HASH_SIZE; i++) {
67
    struct label_entry *tmp = label_hash[i % LABELS_HASH_SIZE];
68
    while (tmp) {
69
      if (strcmp (tmp->name, name) == 0)
70
        return tmp;
71
      tmp = tmp->next;
72
    }
73
  }
74
  return NULL;
75
}
76
 
77
/* Searches mem array for a particular label and returns label's address.
78
   If label does not exist, returns 0. */
79
unsigned long eval_label (char *name) {
80
  struct label_entry *le;
81
  char *plus;
82
  char *minus;
83
  int positive_offset = 0;
84
  int negative_offset = 0;
85
 
86
  if (plus = strchr(name, '+')) {
87
    *plus = '\0';
88
    positive_offset = atoi(++plus);
89
  }
90
 
91
  if (minus = strchr(name, '-')) {
92
    *minus = '\0';
93
    negative_offset = atoi(++minus);
94
  }
95
  le = find_label (name);
96
  if (!le)
97
    return 0;
98
 
99
  return le->addr + positive_offset - negative_offset;
100
}
101
 
102
void init_breakpoints () {
103
  breakpoints = 0;
104
}
105
 
106
void add_breakpoint (unsigned long addr) {
107
  struct breakpoint_entry *tmp;
108
  tmp = (struct breakpoint_entry *) malloc (sizeof (struct breakpoint_entry));
109
  tmp->next = breakpoints;
110
  tmp->addr = addr;
111
  breakpoints = tmp;
112
}
113
 
114
void remove_breakpoint (unsigned long addr) {
115
  struct breakpoint_entry **tmp = &breakpoints;
116
  while (*tmp) {
117
    if ((*tmp)->addr == addr) {
118
      struct breakpoint_entry *t = *tmp;
119
      (*tmp) = t->next;
120
      free (t);
121
    } else
122
      tmp = &((*tmp)->next);
123
  }
124
}
125
 
126
inline int has_breakpoint (unsigned long addr) {
127
  struct breakpoint_entry *tmp = breakpoints;
128
  while (tmp) {
129
    if (tmp->addr == addr)
130
      return 1;
131
    tmp = tmp->next;
132
  }
133
  return 0;
134
}

powered by: WebSVN 2.1.0

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