tlbnocache.c
1.83 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
#include <R4300.h>
#include <ultra64.h>
/*
#include "setjmp.h"
*/
#include "cpu.h"
static u32 va[sizeof(int)] = {
KUBASE,
KUBASE|0x20000000,
K2BASE,
K2BASE|0x20000000
};
static jmp_buf faultbuf;
s32
tlbNocache(s32 *pt, u32 *uncachedp, u32 *cachedp)
{
u32 cachepat = 0x87654321;
int error = 0;
int i;
u32 mempat = 0x12345678;
u32 tlb_attrib = TLBLO_V | TLBLO_D;
u32 tlbpat;
XDEBUG(PRINTF("TLB cached bit test\n"));
for (i = 0; i < NTLBENTRIES; i++) {
u32 addr = va[i & (sizeof(int) - 1)];
tlbwired(i, 0, addr,
(pt[0] >> 6) | tlb_attrib | TLBLO_NONCOHRNT,
(pt[1] >> 6) | tlb_attrib | TLBLO_NONCOHRNT);
if (__osSetJmp((u32 *)faultbuf)) {
XDEBUG(PRINTF("ERR: Test failed %d\n",i));
return ++error;
}
RegisterNoFault((u32 *)faultbuf);
*(volatile u32 *)cachedp = cachepat;
*(volatile u32 *)uncachedp = mempat;
tlbpat = *(u32 *)addr;
ClearNoFault();
if (tlbpat != cachepat) {
XDEBUG(PRINTF(
"ERR: Cached TLB, Exp: 0x%08x, Act: 0x%08x\n",
cachepat, tlbpat));
error++;
}
osUnmapTLB(i);
}
for (i = 0; i < NTLBENTRIES; i++) {
tlbwired(i, 0, 0,
(pt[0] >> 6) | tlb_attrib | TLBLO_UNCACHED,
(pt[1] >> 6) | tlb_attrib | TLBLO_UNCACHED);
if (__osSetJmp((u32 *)faultbuf)) {
XDEBUG(PRINTF("ERR: Test failed %d\n",i));
return ++error;
}
RegisterNoFault((u32 *)faultbuf);
*(volatile u32 *)cachedp = cachepat;
*(volatile u32 *)uncachedp = mempat;
/*
* the test may not work without this second write due to a
* possible R4000 bug
*/
*(volatile u32 *)uncachedp = mempat;
tlbpat = *(u32 *)0;
ClearNoFault();
if (tlbpat != mempat) {
XDEBUG(PRINTF(
"ERR: Uncached TLB, Exp: 0x%08x, Act: 0x%08x\n",
mempat, tlbpat));
error++;
}
osUnmapTLB(i);
}
XDEBUG(PRINTF("******** Test DONE with %d errors ********\n",
error));
return error;
}