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 1782

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 1350 nogj
 
31
#ifdef HAVE_INTTYPES_H
32
#include <inttypes.h>
33
#endif
34
 
35
#include "port.h"
36
#include "config.h"
37 269 markom
 
38 1350 nogj
#include "arch.h"
39 1358 nogj
#include "sim-config.h"
40 269 markom
#include "labels.h"
41
 
42
static struct label_entry *label_hash[LABELS_HASH_SIZE];
43 557 markom
struct breakpoint_entry *breakpoints;
44 269 markom
 
45
void init_labels () {
46
  int i;
47
  for (i = 0; i < LABELS_HASH_SIZE; i++)
48
    label_hash[i] = NULL;
49
}
50
 
51 1350 nogj
void add_label (oraddr_t addr, char *name) {
52 269 markom
  struct label_entry **tmp;
53
  tmp = &(label_hash[addr % LABELS_HASH_SIZE]);
54
        for (; *tmp; tmp = &((*tmp)->next));
55
        *tmp = malloc(sizeof(**tmp));
56
        (*tmp)->name = malloc(strlen(name) + 1);
57
        (*tmp)->addr = addr;
58
        strcpy((*tmp)->name, name);
59
        (*tmp)->next = NULL;
60
}
61
 
62 1350 nogj
struct label_entry *get_label (oraddr_t addr) {
63 269 markom
  struct label_entry *tmp = label_hash[addr % LABELS_HASH_SIZE];
64
  while (tmp) {
65
    if (tmp->addr == addr)
66
      return tmp;
67
    tmp = tmp->next;
68
  }
69
  return NULL;
70
}
71
 
72
struct label_entry *find_label (char *name) {
73
  int i;
74
  for (i = 0; i < LABELS_HASH_SIZE; i++) {
75
    struct label_entry *tmp = label_hash[i % LABELS_HASH_SIZE];
76
    while (tmp) {
77
      if (strcmp (tmp->name, name) == 0)
78
        return tmp;
79
      tmp = tmp->next;
80
    }
81
  }
82
  return NULL;
83
}
84
 
85
/* Searches mem array for a particular label and returns label's address.
86
   If label does not exist, returns 0. */
87 1350 nogj
oraddr_t eval_label (char *name) {
88 269 markom
  struct label_entry *le;
89
  char *plus;
90
  char *minus;
91
  int positive_offset = 0;
92
  int negative_offset = 0;
93
 
94 1308 phoenix
  if ((plus = strchr(name, '+'))) {
95 269 markom
    *plus = '\0';
96
    positive_offset = atoi(++plus);
97
  }
98
 
99 1308 phoenix
  if ((minus = strchr(name, '-'))) {
100 269 markom
    *minus = '\0';
101
    negative_offset = atoi(++minus);
102
  }
103
  le = find_label (name);
104
  if (!le)
105
    return 0;
106
 
107
  return le->addr + positive_offset - negative_offset;
108
}
109
 
110
void init_breakpoints () {
111
  breakpoints = 0;
112
}
113
 
114 1350 nogj
void add_breakpoint (oraddr_t addr) {
115 269 markom
  struct breakpoint_entry *tmp;
116
  tmp = (struct breakpoint_entry *) malloc (sizeof (struct breakpoint_entry));
117
  tmp->next = breakpoints;
118
  tmp->addr = addr;
119
  breakpoints = tmp;
120
}
121
 
122 1350 nogj
void remove_breakpoint (oraddr_t addr) {
123 269 markom
  struct breakpoint_entry **tmp = &breakpoints;
124
  while (*tmp) {
125
    if ((*tmp)->addr == addr) {
126
      struct breakpoint_entry *t = *tmp;
127
      (*tmp) = t->next;
128
      free (t);
129
    } else
130 1350 nogj
      tmp = &((*tmp)->next);
131 269 markom
  }
132
}
133
 
134 1049 ivang
void print_breakpoints () {
135
    struct breakpoint_entry **tmp = &breakpoints;
136
    int i = 1;
137
    printf ("---[breakpoints]------------------\n");
138
    while (*tmp) {
139 1350 nogj
        printf ("Breakpoint %i at 0x%"PRIxADDR"\n", i, (*tmp)->addr);
140 1049 ivang
        tmp = &((*tmp)->next);
141
    }
142
    printf ("---[breakpoints end]--------------\n");
143
}
144
 
145 1350 nogj
inline int has_breakpoint (oraddr_t addr) {
146 269 markom
  struct breakpoint_entry *tmp = breakpoints;
147
  while (tmp) {
148
    if (tmp->addr == addr)
149
      return 1;
150
    tmp = tmp->next;
151
  }
152
  return 0;
153
}

powered by: WebSVN 2.1.0

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