forked from byungwoo733/riscv-ovpsim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
riscvBus.c
176 lines (149 loc) · 3.92 KB
/
riscvBus.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
* Copyright (c) 2005-2020 Imperas Software Ltd., www.imperas.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
// Imperas header files
#include "hostapi/impAlloc.h"
// VMI header files
#include "vmi/vmiMessage.h"
#include "vmi/vmiRt.h"
// model header files
#include "riscvBus.h"
#include "riscvFunctions.h"
#include "riscvStructure.h"
#include "riscvUtils.h"
//
// Structure describing a port
//
typedef struct riscvBusPortS {
vmiBusPort desc;
riscvBusPortP next;
} riscvBusPort;
//
// Allocate a new port and append to the tail of the list
//
static riscvBusPortP newBusPort(
riscvBusPortPP *tailP,
const char *name,
vmiBusPortType type,
vmiDomainType domainType,
Uns8 min,
Uns8 max,
Uns8 unset,
Bool mustBeConnected,
const char *desc
) {
riscvBusPortPP tail = *tailP;
riscvBusPortP this = STYPE_CALLOC(riscvBusPort);
vmiBusPortP info = &this->desc;
// fill port fields
info->name = name;
info->type = type;
info->domainType = domainType;
info->addrBits.min = min;
info->addrBits.max = max;
info->addrBits.unset = unset;
info->mustBeConnected = mustBeConnected;
info->description = desc;
// append to list and update tail
this->next = *tail;
*tail = this;
*tailP = &this->next;
// return new port
return this;
}
//
// Allocate bus port specifications at root level
//
void riscvNewRootBusPorts(riscvP riscv) {
riscvBusPortPP tail = &riscv->busPorts;
Uns32 xlen = riscvGetXlenArch(riscv);
Uns32 min = 32;
Uns32 max = (xlen==32) ? RISCV_PMP_BITS_32 : RISCV_PMP_BITS_64;
Uns32 unset = max;
// instruction port
newBusPort(
&tail,
"INSTRUCTION",
vmi_BP_MASTER,
vmi_DOM_CODE,
min, max, unset,
True,
"Instruction bus"
);
// data port
newBusPort(
&tail,
"DATA",
vmi_BP_MASTER,
vmi_DOM_DATA,
min, max, unset,
False,
"Data bus"
);
}
//
// Allocate bus port specifications at leaf level
//
void riscvNewLeafBusPorts(riscvP riscv) {
riscvBusPortPP tail = &riscv->busPorts;
// add artifact CSR bus allowing external implementation of CSR registers
// if required
if(riscv->configInfo.enable_CSR_bus) {
riscv->csrPort = newBusPort(
&tail,
"CSR",
vmi_BP_MASTER,
vmi_DOM_OTHER,
16, 16, 16,
False,
"Artifact bus allowing external implementation of CSR registers"
);
}
}
//
// Free bus port specifications
//
void riscvFreeBusPorts(riscvP riscv) {
riscvBusPortP next = riscv->busPorts;
riscvBusPortP this;
while((this=next)) {
next = this->next;
STYPE_FREE(this);
}
riscv->busPorts = 0;
}
//
// Get the next bus port
//
VMI_BUS_PORT_SPECS_FN(riscvBusPortSpecs) {
riscvP riscv = (riscvP)processor;
riscvBusPortP this;
if(!prev) {
this = riscv->busPorts;
} else {
this = ((riscvBusPortP)prev)->next;
}
return this ? &this->desc : 0;
}
//
// Return any domain connected to the artifact port implementing CSRs
//
memDomainP riscvGetExternalCSRDomain(riscvP riscv) {
riscvBusPortP port = riscv->csrPort;
return port ? port->desc.domain : NULL;
}