tlb1.c
3.66 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include <ultra64.h>
#include <R4300.h>
#include <os_internal.h>
#include "corefunc.h"
#define MAX_PAGESIZE (64*1024)
#define MAX_PAGESHIFT 16
#define MIN_PAGESHIFT 12
static char testBuffer[4*MAX_PAGESIZE];
/*
* tlb1
*
* Tests for:
* osMapTLB (asid argument)
* osSetTLBASID
*
* Assumed working:
*
* osUnmapTLB
* osUnmapTLBAll
* osVirtualToPhysical
* osWritebackDCache
* osInvalDCache
*
* Description:
*/
void
printTLB(void)
{
s32 index;
osSyncPrintf("TLB ASID = %d (0x%x)\n", __osGetTLBASID(), __osGetTLBASID());
for (index = 0; index < 1; index++) {
osSyncPrintf("%02d. pagemask 0x%08x hi 0x%08x lo0 0x%08x lo1 0x%08x\n",
index, __osGetTLBPageMask(index), __osGetTLBHi(index),
__osGetTLBLo0(index), __osGetTLBLo1(index));
}
}
int
tlb1(void)
{
int numFailures = 0;
u32 paddr;
u8 *evenVaddr, *oddVaddr;
unsigned int expectedValue, actualValue;
s32 i, j;
paddr = osVirtualToPhysical(buffer);
evenVaddr = (u8 *)(2*4096);
oddVaddr = (u8 *)(3*4096);
/*
* Check that global mappings work regardless of the ASID
*/
for (i = 0; i < 0x100; i++) {
osSetTLBASID(i);
/*
* Map the even and odd pages one physical page apart.
*/
osMapTLB(0, OS_PM_4K, evenVaddr, paddr, paddr + 2 * 4096, -1);
/*
* Verify the even page address.
*/
expectedValue = paddr;
actualValue = osVirtualToPhysical(evenVaddr);
if (expectedValue != actualValue) {
osSyncPrintf("tlb1: expected physical address 0x%x, actual 0x%x\n",
expectedValue, actualValue);
numFailures++;
}
/*
* Verify the odd page address.
*/
expectedValue = paddr + 2 * 4096;
actualValue = osVirtualToPhysical(oddVaddr);
if (expectedValue != actualValue) {
osSyncPrintf("tlb1: expected physical address 0x%x, actual 0x%x\n",
expectedValue, actualValue);
numFailures++;
}
osUnmapTLB(0);
}
/*
* Check that non-global mappings work only when the correct ASID is set.
*/
for (i = 0; i < 0x100; i++) {
/*
* Map the even and odd pages one physical page apart.
*/
osMapTLB(0, OS_PM_4K, evenVaddr, paddr, paddr + 2 * 4096, i);
for (j = 0; j < 0x100; j++) {
osSetTLBASID(j);
/*
* Map, unmap another TLB entry here to test if ASID gets modified
*/
osMapTLB(1, OS_PM_4K, evenVaddr+(2*4096),
paddr, paddr + 2 * 4096, i);
osUnmapTLB(1);
if (i == j) {
/*
* Verify the even page address.
*/
expectedValue = paddr;
actualValue = osVirtualToPhysical(evenVaddr);
if (expectedValue != actualValue) {
osSyncPrintf(
"tlb1: expected physical address 0x%x, actual 0x%x\n",
expectedValue, actualValue);
numFailures++;
printTLB();
}
/*
* Verify the odd page address.
*/
expectedValue = paddr + 2 * 4096;
actualValue = osVirtualToPhysical(oddVaddr);
if (expectedValue != actualValue) {
osSyncPrintf(
"tlb1: expected physical address 0x%x, actual 0x%x\n",
expectedValue, actualValue);
numFailures++;
printTLB();
}
} else {
/*
* Verify the even page address is not mapped.
*/
expectedValue = (u32)-1;
actualValue = osVirtualToPhysical(evenVaddr);
if (expectedValue != actualValue) {
osSyncPrintf(
"tlb1: expected return value 0x%x, actual 0x%x\n",
expectedValue, actualValue);
numFailures++;
printTLB();
}
/*
* Verify the odd page address is not mapped.
*/
expectedValue = (u32)-1;
actualValue = osVirtualToPhysical(oddVaddr);
if (expectedValue != actualValue) {
osSyncPrintf(
"tlb1: expected return value 0x%x, actual 0x%x\n",
expectedValue, actualValue);
numFailures++;
printTLB();
}
}
}
osUnmapTLB(0);
}
return(numFailures);
}