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

Subversion Repositories or1k

[/] [or1k/] [tags/] [or1k-1_0/] [or1ksim/] [cpu/] [common/] [abstract.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 cvs
/* abstract.c -- Abstract entities
2
   Copyright (C) 1999 Damjan Lampret, lampret@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 goes with this. I need to
21
add all sorts of other abstract entities. Currently we have
22
only memory. */
23
 
24
#include <stdio.h>
25
#include <ctype.h>
26
#include <string.h>
27
 
28
#include "parse.h"
29
#include "abstract.h"
30
#include "arch.h"
31
#include "trace.h"
32
#include "execute.h"
33
 
34
extern unsigned long reg[];
35
 
36
/* This is an abstract memory array rather than physical memory array */
37
struct mem_entry mem[MEMORY_LEN];
38
 
39
void dumpmemory(unsigned int from, unsigned int to)
40
{
41
        unsigned int i;
42
 
43
        for(i = from; i < to; i++)
44
                if (strlen(mem[i].insn)) {
45
                        printf("\n%.4x:  ", i);
46
                        if (strlen(mem[i].label))
47
                                printf("%s%s\n", mem[i].label, LABELEND_CHAR);
48
                        printf("\t\t%s\t%s", mem[i].insn, mem[i].op1);
49
                        if (strlen(mem[i].op2))
50
                                printf("%s%s", OPERAND_DELIM, mem[i].op2);
51
                        if (strlen(mem[i].op3))
52
                                printf("%s%s", OPERAND_DELIM, mem[i].op3);
53
                        if (strlen(mem[i].op4))
54
                                printf("%s%s", OPERAND_DELIM, mem[i].op4);
55
                        i += 3; /* insn long 4 bytes */
56
                } else
57
                {
58
                        if (i % 8 == 0)
59
                                printf("\n%.4x:  ", i);
60
 
61
                        /* don't print ascii chars below 0x20. */
62
                        if (mem[i].data < 0x20)
63
                                printf("0x%.2x     ", (unsigned char)mem[i].data);
64
                        else
65
                                printf("0x%.2x'%c'  ", (unsigned char)mem[i].data, mem[i].data);
66
 
67
                }
68
}
69
 
70
/* Searches mem array for a particular label and returns label's address.
71
   If label does not exist, returns 0. */
72
 
73
unsigned long eval_label(char *label)
74
{
75
        int i;
76
 
77
        for(i = 0; i < MEMORY_LEN; i++)
78
                if (strcmp(label, mem[i].label) == 0)
79
                        return i;
80
 
81
        printf("\nINTERNAL ERROR: undefined label %s\n", label);
82
        cont_run = 0;
83
        return 0;
84
 
85
}
86
 
87
/* Returns 32-bit values from mem array. Big endian version. */
88
 
89
unsigned long eval_mem32(unsigned long memaddr)
90
{
91
        unsigned long temp;
92
 
93
        if (memaddr < MEMORY_LEN) {
94
/*              temp = ((unsigned long)(mem[memaddr].data << 24) & 0xff000000);
95
                temp += ((unsigned long)(mem[memaddr + 1].data << 16) & 0x00ff0000);
96
                temp += ((unsigned long)(mem[memaddr + 2].data << 8) & 0x0000ff00);
97
                temp += ((unsigned long)mem[memaddr + 3].data & 0x000000ff); */
98
                temp = mem[memaddr].data << 24;
99
                temp += mem[memaddr + 1].data << 16;
100
                temp += mem[memaddr + 2].data << 8;
101
                temp += mem[memaddr + 3].data;
102
 
103
        } else {
104
                printf("EXCEPTION: read out of memory (32-bit access to %.8lx)\n", memaddr);
105
                cont_run = 0;
106
                temp = ((unsigned long)(mem[0].data << 24) & 0xff000000);
107
                temp += ((unsigned long)(mem[1].data << 16) & 0x00ff0000);
108
                temp += ((unsigned long)(mem[2].data << 8) & 0x0000ff00);
109
                temp += ((unsigned long)mem[3].data & 0x000000ff);
110
        }
111
        return temp;
112
}
113
 
114
/* Returns 16-bit values from mem array. Big endian version. */
115
 
116
unsigned short eval_mem16(unsigned long memaddr)
117
{
118
        unsigned short temp;
119
 
120
        if (memaddr < MEMORY_LEN) {
121
                temp = ((unsigned short)(mem[memaddr].data << 8) & 0xff00);
122
                temp += ((unsigned short)mem[memaddr + 1].data & 0x00ff);
123
        } else {
124
                printf("EXCEPTION: read out of memory (16-bit access to %.8lx)\n", memaddr);
125
                cont_run = 0;
126
                temp = ((unsigned short)(mem[0].data << 8) & 0xff00);
127
                temp += ((unsigned short)mem[1].data & 0x00ff);
128
        }
129
        return temp;
130
}
131
 
132
 
133
/* Returns 8-bit values from mem array. Big endian version. */
134
 
135
unsigned char eval_mem8(unsigned long memaddr)
136
{
137
        if (memaddr < MEMORY_LEN) {
138
                return (unsigned char)mem[memaddr].data;
139
        } else {
140
                printf("EXCEPTION: read out of memory (16-bit access to %.8lx)\n", memaddr);
141
                cont_run = 0;
142
                return (unsigned char)mem[0].data;
143
        }
144
}
145
 
146
/* Set mem, 32-bit. Big endian version. */
147
 
148
void set_mem32(unsigned long memaddr, unsigned long value)
149
{
150
        if (memaddr < MEMORY_LEN) {
151
                mem[memaddr].data = (value >> 24);
152
                mem[memaddr + 1].data = (char)(value >> 16);
153
                mem[memaddr + 2].data = (char)(value >> 8);
154
                mem[memaddr + 3].data = (char)(value);
155
        } else {
156
                printf("EXCEPTION: write out of memory (32-bit access to %.8lx)\n", memaddr);
157
                cont_run = 0;
158
        }
159
 
160
        return;
161
}
162
 
163
/* Set mem, 16-bit. Big endian version. */
164
 
165
void set_mem16(unsigned long memaddr, unsigned short value)
166
{
167
        if (memaddr < MEMORY_LEN) {
168
                mem[memaddr].data = (value >> 8);
169
                mem[memaddr + 1].data = (char)(value);
170
        } else {
171
                printf("EXCEPTION: write out of memory (16-bit access to %.8lx)\n", memaddr);
172
                cont_run = 0;
173
        }
174
 
175
        return;
176
}
177
 
178
/* Set mem, 8-bit. Big endian version. */
179
 
180
void set_mem8(unsigned long memaddr, unsigned char value)
181
{
182
        if (memaddr < MEMORY_LEN) {
183
                mem[memaddr].data = value;
184
        } else {
185
                printf("EXCEPTION: write out of memory (8-bit access to %.8lx)\n", memaddr);
186
                cont_run = 0;
187
        }
188
 
189
        return;
190
}

powered by: WebSVN 2.1.0

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