-
Notifications
You must be signed in to change notification settings - Fork 29
/
cp14.c
160 lines (121 loc) · 3.84 KB
/
cp14.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
#include "cp14.h"
/* PMNC register */
#define PMNC_E (1UL << 0)
#define PMNC_P (1UL << 1)
#define PMNC_C (1UL << 2)
#define PMNC_D (1UL << 3)
#define PMNC_INTEN (7UL << 4)
#define PMNC_INTEN_PMN0 (1UL << 4)
#define PMNC_INTEN_PMN1 (1UL << 5)
#define PMNC_INTEN_CCNT (1UL << 6)
#define PMNC_FLAG (7UL << 8)
#define PMNC_FLAG_PMN(i) (1UL << (8 + (i)))
#define PMNC_FLAG_PMN0 PMNC_FLAG_PMN(0)
#define PMNC_FLAG_PMN1 PMNC_FLAG_PMN(1)
#define PMNC_FLAG_CCNT (1UL << 10)
#define PMNC_EVTCOUNT0 (0xffUL << 12)
#define PMNC_EVTCOUNT1 (0xffUL << 20)
#define PMNC_ALL (PMNC_E|PMNC_P|PMNC_C|PMNC_D|PMNC_INTEN|PMNC_FLAG|PMNC_EVTCOUNT0|PMNC_EVTCOUNT1)
#define PMNC_UPDATE (PMNC_E|PMNC_D|PMNC_INTEN|PMNC_EVTCOUNT0|PMNC_EVTCOUNT1)
#define PMNC_EVTNUMBER(cp14,n) ((cp14->PMNC >> (12 + (n) * 8)) & 0xff)
static void cp14PrvRaiseLowerInts(ArmCP14* cp14){
pxa255icInt(cp14->ic, PXA255_I_PMU, (cp14->PMNC & (PMNC_INTEN_PMN0|PMNC_FLAG_PMN0)) == (PMNC_INTEN_PMN0|PMNC_FLAG_PMN0));
pxa255icInt(cp14->ic, PXA255_I_PMU, (cp14->PMNC & (PMNC_INTEN_PMN1|PMNC_FLAG_PMN1)) == (PMNC_INTEN_PMN1|PMNC_FLAG_PMN1));
pxa255icInt(cp14->ic, PXA255_I_PMU, (cp14->PMNC & (PMNC_INTEN_CCNT|PMNC_FLAG_CCNT)) == (PMNC_INTEN_CCNT|PMNC_FLAG_CCNT));
}
static Boolean cp14prvCoprocRegXferFunc(struct ArmCpu* cpu, void* userData, Boolean two, Boolean read, UInt8 op1, UInt8 Rx, UInt8 CRn, UInt8 CRm, UInt8 op2){
ArmCP14* cp14 = userData;
UInt32 val = 0;
if(!read) val = cpuGetRegExternal(cpu, Rx);
if(CRm == 0 && op2 == 0 && op1 == 0 && !two){
switch(CRn){
case 0: // PMNC
if(read) val = cp14->PMNC & PMNC_ALL;
else{
if((val & PMNC_E) && !(cp14->PMNC & PMNC_E)) cp14->tick = 0;
if(val & PMNC_P) cp14->PMN[0] = cp14->PMN[1] = 0;
if(val & PMNC_C) cp14->CCNT = 0;
if(val & PMNC_FLAG_PMN0) cp14->PMNC &= ~PMNC_FLAG_PMN0;
if(val & PMNC_FLAG_PMN1) cp14->PMNC &= ~PMNC_FLAG_PMN1;
if(val & PMNC_FLAG_CCNT) cp14->PMNC &= ~PMNC_FLAG_CCNT;
cp14->PMNC &= ~PMNC_UPDATE;
cp14->PMNC |= val & PMNC_UPDATE;
cp14PrvRaiseLowerInts(cp14);
}
goto success;
case 1: // CCNT
if(read) val = cp14->CCNT;
else cp14->CCNT = val;
goto success;
case 2: // PMN0
if(read) val = cp14->PMN[0];
else cp14->PMN[0] = val;
goto success;
case 3: // PMN1
if(read) val = cp14->PMN[1];
else cp14->PMN[1] = val;
goto success;
case 6: // CCLKCFG
if(read) val = 0;
else{
cp14->turbo = (val & 1) != 0;
if(val & 2){
err_str("Set speed mode");
// err_str("(CCCR + cp14 reg6) to 0x");
// err_hex(pc->CCCR);
// err_str(", 0x");
// err_hex(val);
// err_str("\r\n");
}
}
goto success;
case 7: // PWRMODE
if(read) val = cp14->turbo ? 1 : 0;
else if(val != 0){
// fprintf(stderr, "Someone tried to set processor power mode (cp14 reg7) to 0x%08lX\n", val);
}
goto success;
}
}
return false;
success:
if(read) cpuSetReg(cpu, Rx, val);
return true;
}
void cp14Init(ArmCP14* cp14, ArmCpu* cpu, Pxa255ic* ic){
ArmCoprocessor cp;
cp.regXfer = cp14prvCoprocRegXferFunc;
cp.dataProcessing = NULL;
cp.memAccess = NULL;
cp.twoRegF = NULL;
cp.userData = cp14;
__mem_zero(cp14, sizeof(ArmCP14));
cp14->cpu = cpu;
cp14->ic = ic;
cpuCoprocessorRegister(cpu, 14, &cp);
}
void cp14Deinit(ArmCP14* cp14){
cpuCoprocessorUnregister(cp14->cpu, 14);
}
void cp14Tick(ArmCP14* cp14){
if(cp14->PMNC & PMNC_E){
cp14->tick++;
if(!(cp14->PMNC & PMNC_D) || (cp14->tick & 0x0000003FUL) == 0){
cp14->CCNT++;
if(cp14->CCNT == 0) cp14->PMNC |= PMNC_FLAG_CCNT;
}
cp14PrvRaiseLowerInts(cp14);
}
}
void cp14Event(ArmCP14 *cp14, UInt8 evtnum){
UInt8 i;
if(cp14->PMNC & PMNC_E){
for(i = 0; i < 1; i++){
if(PMNC_EVTNUMBER(cp14, i) == evtnum){
cp14->PMN[i]++;
if(cp14->PMN[i] == 0) cp14->PMNC |= PMNC_FLAG_PMN(i);
}
}
cp14PrvRaiseLowerInts(cp14);
}
}