/* abstract.c -- Abstract entities, handling labels
|
/* abstract.c -- Abstract entities, handling labels
|
Copyright (C) 2001 Marko Mlinar, markom@opencores.org
|
Copyright (C) 2001 Marko Mlinar, markom@opencores.org
|
|
|
This file is part of OpenRISC 1000 Architectural Simulator.
|
This file is part of OpenRISC 1000 Architectural Simulator.
|
|
|
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
the Free Software Foundation; either version 2 of the License, or
|
the Free Software Foundation; either version 2 of the License, or
|
(at your option) any later version.
|
(at your option) any later version.
|
|
|
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
GNU General Public License for more details.
|
GNU General Public License for more details.
|
|
|
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
|
|
/* Abstract memory and routines that go with this. I need to
|
/* Abstract memory and routines that go with this. I need to
|
add all sorts of other abstract entities. Currently we have
|
add all sorts of other abstract entities. Currently we have
|
only memory. */
|
only memory. */
|
|
|
#include <stdlib.h>
|
#include <stdlib.h>
|
#include <stdio.h>
|
#include <stdio.h>
|
#include <ctype.h>
|
#include <ctype.h>
|
#include <string.h>
|
#include <string.h>
|
|
|
#include "config.h"
|
#include "config.h"
|
|
|
#ifdef HAVE_INTTYPES_H
|
#ifdef HAVE_INTTYPES_H
|
#include <inttypes.h>
|
#include <inttypes.h>
|
#endif
|
#endif
|
|
|
#include "port.h"
|
#include "port.h"
|
#include "config.h"
|
#include "config.h"
|
|
|
#include "arch.h"
|
#include "arch.h"
|
#include "sim-config.h"
|
#include "sim-config.h"
|
#include "labels.h"
|
#include "labels.h"
|
|
|
static struct label_entry *label_hash[LABELS_HASH_SIZE];
|
static struct label_entry *label_hash[LABELS_HASH_SIZE];
|
struct breakpoint_entry *breakpoints;
|
struct breakpoint_entry *breakpoints;
|
|
|
void init_labels () {
|
void init_labels () {
|
int i;
|
int i;
|
for (i = 0; i < LABELS_HASH_SIZE; i++)
|
for (i = 0; i < LABELS_HASH_SIZE; i++)
|
label_hash[i] = NULL;
|
label_hash[i] = NULL;
|
}
|
}
|
|
|
void add_label (oraddr_t addr, char *name) {
|
void add_label (oraddr_t addr, char *name) {
|
struct label_entry **tmp;
|
struct label_entry **tmp;
|
tmp = &(label_hash[addr % LABELS_HASH_SIZE]);
|
tmp = &(label_hash[addr % LABELS_HASH_SIZE]);
|
for (; *tmp; tmp = &((*tmp)->next));
|
for (; *tmp; tmp = &((*tmp)->next));
|
*tmp = malloc(sizeof(**tmp));
|
*tmp = malloc(sizeof(**tmp));
|
(*tmp)->name = malloc(strlen(name) + 1);
|
(*tmp)->name = malloc(strlen(name) + 1);
|
(*tmp)->addr = addr;
|
(*tmp)->addr = addr;
|
strcpy((*tmp)->name, name);
|
strcpy((*tmp)->name, name);
|
(*tmp)->next = NULL;
|
(*tmp)->next = NULL;
|
}
|
}
|
|
|
struct label_entry *get_label (oraddr_t addr) {
|
struct label_entry *get_label (oraddr_t addr) {
|
struct label_entry *tmp = label_hash[addr % LABELS_HASH_SIZE];
|
struct label_entry *tmp = label_hash[addr % LABELS_HASH_SIZE];
|
while (tmp) {
|
while (tmp) {
|
if (tmp->addr == addr)
|
if (tmp->addr == addr)
|
return tmp;
|
return tmp;
|
tmp = tmp->next;
|
tmp = tmp->next;
|
}
|
}
|
return NULL;
|
return NULL;
|
}
|
}
|
|
|
struct label_entry *find_label (char *name) {
|
struct label_entry *find_label (char *name) {
|
int i;
|
int i;
|
for (i = 0; i < LABELS_HASH_SIZE; i++) {
|
for (i = 0; i < LABELS_HASH_SIZE; i++) {
|
struct label_entry *tmp = label_hash[i % LABELS_HASH_SIZE];
|
struct label_entry *tmp = label_hash[i % LABELS_HASH_SIZE];
|
while (tmp) {
|
while (tmp) {
|
if (strcmp (tmp->name, name) == 0)
|
if (strcmp (tmp->name, name) == 0)
|
return tmp;
|
return tmp;
|
tmp = tmp->next;
|
tmp = tmp->next;
|
}
|
}
|
}
|
}
|
return NULL;
|
return NULL;
|
}
|
}
|
|
|
/* Searches mem array for a particular label and returns label's address.
|
/* Searches mem array for a particular label and returns label's address.
|
If label does not exist, returns 0. */
|
If label does not exist, returns 0. */
|
oraddr_t eval_label (char *name) {
|
oraddr_t eval_label (char *name) {
|
struct label_entry *le;
|
struct label_entry *le;
|
char *plus;
|
char *plus;
|
char *minus;
|
char *minus;
|
int positive_offset = 0;
|
int positive_offset = 0;
|
int negative_offset = 0;
|
int negative_offset = 0;
|
|
|
if ((plus = strchr(name, '+'))) {
|
if ((plus = strchr(name, '+'))) {
|
*plus = '\0';
|
*plus = '\0';
|
positive_offset = atoi(++plus);
|
positive_offset = atoi(++plus);
|
}
|
}
|
|
|
if ((minus = strchr(name, '-'))) {
|
if ((minus = strchr(name, '-'))) {
|
*minus = '\0';
|
*minus = '\0';
|
negative_offset = atoi(++minus);
|
negative_offset = atoi(++minus);
|
}
|
}
|
le = find_label (name);
|
le = find_label (name);
|
if (!le)
|
if (!le)
|
return 0;
|
return 0;
|
|
|
return le->addr + positive_offset - negative_offset;
|
return le->addr + positive_offset - negative_offset;
|
}
|
}
|
|
|
void init_breakpoints () {
|
void init_breakpoints () {
|
breakpoints = 0;
|
breakpoints = 0;
|
}
|
}
|
|
|
void add_breakpoint (oraddr_t addr) {
|
void add_breakpoint (oraddr_t addr) {
|
struct breakpoint_entry *tmp;
|
struct breakpoint_entry *tmp;
|
tmp = (struct breakpoint_entry *) malloc (sizeof (struct breakpoint_entry));
|
tmp = (struct breakpoint_entry *) malloc (sizeof (struct breakpoint_entry));
|
tmp->next = breakpoints;
|
tmp->next = breakpoints;
|
tmp->addr = addr;
|
tmp->addr = addr;
|
breakpoints = tmp;
|
breakpoints = tmp;
|
}
|
}
|
|
|
void remove_breakpoint (oraddr_t addr) {
|
void remove_breakpoint (oraddr_t addr) {
|
struct breakpoint_entry **tmp = &breakpoints;
|
struct breakpoint_entry **tmp = &breakpoints;
|
while (*tmp) {
|
while (*tmp) {
|
if ((*tmp)->addr == addr) {
|
if ((*tmp)->addr == addr) {
|
struct breakpoint_entry *t = *tmp;
|
struct breakpoint_entry *t = *tmp;
|
(*tmp) = t->next;
|
(*tmp) = t->next;
|
free (t);
|
free (t);
|
} else
|
} else
|
tmp = &((*tmp)->next);
|
tmp = &((*tmp)->next);
|
}
|
}
|
}
|
}
|
|
|
void print_breakpoints () {
|
void print_breakpoints () {
|
struct breakpoint_entry **tmp = &breakpoints;
|
struct breakpoint_entry **tmp = &breakpoints;
|
int i = 1;
|
int i = 1;
|
printf ("---[breakpoints]------------------\n");
|
printf ("---[breakpoints]------------------\n");
|
while (*tmp) {
|
while (*tmp) {
|
printf ("Breakpoint %i at 0x%"PRIxADDR"\n", i, (*tmp)->addr);
|
printf ("Breakpoint %i at 0x%"PRIxADDR"\n", i, (*tmp)->addr);
|
tmp = &((*tmp)->next);
|
tmp = &((*tmp)->next);
|
}
|
}
|
printf ("---[breakpoints end]--------------\n");
|
printf ("---[breakpoints end]--------------\n");
|
}
|
}
|
|
|
inline int has_breakpoint (oraddr_t addr) {
|
inline int has_breakpoint (oraddr_t addr) {
|
struct breakpoint_entry *tmp = breakpoints;
|
struct breakpoint_entry *tmp = breakpoints;
|
while (tmp) {
|
while (tmp) {
|
if (tmp->addr == addr)
|
if (tmp->addr == addr)
|
return 1;
|
return 1;
|
tmp = tmp->next;
|
tmp = tmp->next;
|
}
|
}
|
return 0;
|
return 0;
|
}
|
}
|
|
|