firewallhack.c
3.14 KB
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
/*
* Copyright (C) 1996-1998 by the Board of Trustees
* of Leland Stanford Junior University.
*
* This file is part of the SimOS distribution.
* See LICENSE file for terms of the license.
*
*/
/*****************************************************************
* firewallhack.c
*
*****************************************************************/
#include <stdio.h>
#include <time.h>
#include <assert.h>
#include <stdlib.h>
#include "mipsy.h"
#include "pcache.h"
#include "scache.h"
#include "memstat.h"
#include "memsys.h"
#include "eventcallback.h"
#include "cpu_interface.h"
#include "cpu_state.h"
#ifdef sgi
#include "bstring.h"
#endif
#ifdef sun
#include "strings.h"
#endif
#include "memory.h"
#include "string.h"
extern bool flashliteRunning;
/*
* Unlike the other memory systems we have, the flashlite memory system
* is currently a compile time option triggered by the USE_FLASHLITE
* define. If this is not defined we provide stubs so simulator can
* link without it.
*/
#if !defined(USE_FLASHLITE) || defined(SOLO)
/*
* FlashliteFirewallInit - Initalize the flashlite firewall
*/
void
FlashliteFirewallInit(void)
{
return;
}
void
FlashliteSetPageProt(int cell,unsigned int paddr, int rights)
{
return;
}
int
FlashliteDownloadFirewall(void)
{
}
#else /* is defined(USE_FLASHLITE) */
#define ERROR FLASHLITE_ERROR
#define BIG_ENDIAN
#include "simosinterface.h"
#include "flash_interface.h"
#include "mipsy_interface.h"
#include "firewall.h"
#include "firewallhack.h"
/*
* FlashliteFirewallInit - Initalize the flashlite firewall
*/
void
FlashliteFirewallInit(void)
{
/*
* If flashlite is already running we download the firewall to it;
* otherwise we will download it running init.
*/
if (flashliteRunning) {
if (FlashliteDownloadFirewall() == FALSE) {
CPUWarning("Flashlite firewall download failed.\n");
}
}
}
int
FlashliteDownloadFirewall(void)
{
LL faddr;
FLASHAddress faddr2, NOTALLOC;
int p, cpu;
if (!SIMFIREWALL_ON) return TRUE;
#ifdef notdef
if (!FlashCellLayoutOK(CPUVec.numCPUs, SimfwData.numCells, SimfwData.cpu2cell)) {
CPUWarning("Cell layout not supported by flashlite.\n");
return FALSE;
}
#endif /* notdef */
NOTALLOC.fa.node = -1;
for (p = 0; p < MEM_SIZE(0); p += FLASH_PAGE_SIZE) {
faddr = FlashAddrFromSimosAddr(0,p);
faddr2.ll = faddr;
if (faddr2.fa.node == NOTALLOC.fa.node) {
/* Must be allocated, first touch. */
continue;
}
for (cpu = 0; cpu < NUM_CPUS(0); cpu++) {
if (CPUVec.CheckFirewall(cpu, p)) {
FlashSetAccessControl(faddr, cpu, 1);
}
}
}
return TRUE;
}
void
FlashliteSetPageProt(int cell,unsigned int paddr, int rights)
{
if (!flashliteRunning)
return;
/* NOPed by jchapin since FWDIRECT now in use */
return;
#ifdef notdef
if (rights == SIMFW_READWRITE) {
writeProtect = 0;
} else {
writeProtect = 1;
}
faddr = FlashAddrFromSimosAddr(0,paddr);
for (cpu = 0; cpu < NUM_CPUS(0); cpu++) {
if (SimfwData.cpu2cell[cpu] == cell) {
FlashSetAccessControl(faddr,cpu, writeProtect);
}
}
#endif /* notdef */
}
#endif /* is defined(USE_FLASHLITE) */