File: 603.S

package info (click to toggle)
mol 0.9.61-6
  • links: PTS
  • area: contrib
  • in suites: woody
  • size: 6,140 kB
  • ctags: 8,491
  • sloc: ansic: 50,560; asm: 2,826; sh: 458; makefile: 373; perl: 165; lex: 135; yacc: 131
file content (218 lines) | stat: -rw-r--r-- 6,864 bytes parent folder | download | duplicates (4)
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/* 
 *   Creation Date: <2001/06/15 20:10:49 samuel>
 *   Time-stamp: <2001/06/16 15:35:22 samuel>
 *   
 *	<603.S>
 *	
 *	603 MMU support
 *   
 *   Copyright (C) 2001 Samuel Rydh (samuel@ibrium.se)
 *   
 *   This program is free software; you can redistribute it and/or
 *   modify it under the terms of the GNU General Public License
 *   as published by the Free Software Foundation
 *   
 */

#define P603_USE_G_BIT
#define P603_USE_R_BIT
#define P603_USE_C_BIT

/* NOTE: The 603 vectors are called with ctr saved in r0.
 * Secondary interrupts are not detected automatically.
 */
	
/************************************************************************/
/*	Instruction TLB Miss (603 specific vector)			*/
/************************************************************************/
	
VECTOR_603( 0x1000, "Instruction TLB Miss - 603" )
//	mfctr   r0				// Need to save this - CTR can't be touched!
	mfspr   r2,HASH1			// Get PTE pointer
	mfspr   r3,ICMP				// Partial item compare value
00:     li      r1,8				// 8 items / bucket
	mtctr   r1
	subi    r2,r2,8				// Preset pointer
10:     lwzu    r1,8(r2)			// Get next PTE
	cmp     0,r1,r3				// Found entry yet?
	bdnzf   2,10b				// Jump back if not, until CTR==0
	bne     30f				// Try secondary hash if CTR==0
	lwz     r1,4(r2)			// Get second word of entry
#ifdef P603_USE_G_BIT
	andi.	r3,r1,8				// check G-bit
	bne	DoISI_603_G			// if guarded, take an ISI
#endif
	mtctr   r0				// Restore CTR
	mfspr   r3,SRR1				// Need to restore CR0
	mtcrf   0x80,r3
	mfspr   r0,IMISS			// Set to update TLB
	mtspr   RPA,r1
#ifdef P603_USE_R_BIT
	ori	r1,r1,0x100			// Set reference bit
	srwi	r1,r1,8				// Get byte 7 of pte
	tlbli   r0				// Load the ITLB
	stb	r1,6(r2)			// update page table
#else
	tlbli   r0				// Load the ITLB
#endif
	rfi					// All done

	// Secondary hash
30:     andi.   r1,r3,0x40			// Already doing secondary hash?
	bne     DoISI_603			// Yes - item not in hash table
	mfspr   r2,HASH2			// Get hash table pointer
	ori     r3,r3,0x40			// Set secondary hash
	b       00b				// Try lookup again

	
/************************************************************************/
/*	Data Store TLB Miss (603 specific vector)			*/
/************************************************************************/
	
VECTOR_603( 0x1200, "Data Store TLB Miss - 603" )
//	mfctr	r0				// Need to save this - CTR can't be touched!
	mfspr	r2,HASH1			// Get PTE pointer
	mfspr	r3,DCMP				// Partial item compare value
00:	li	r1,8				// 8 items / bucket
	mtctr	r1
	subi	r2,r2,8				// Preset pointer
10:	lwzu	r1,8(r2)			// Get next PTE
	cmp	0,r1,r3				// Found entry yet?
	bdnzf	2,10b				// Jump back if not, until CTR==0
	bne	30f				// Try secondary hash if CTR==0
	lwz	r1,4(r2)			// Get second word of entry
#ifdef P603_USE_C_BIT
	andi.	r3,r1,0x80			// Check the C-bit
	beq	CheckProt_603
16:
#endif	
20:	mtctr	r0				// Restore CTR
	mfspr	r3,SRR1				// Need to restore CR0
	mtcrf	0x80,r3
	mfspr	r0,DMISS			// Set to update TLB
	mtspr	RPA,r1
	tlbld	r0
	rfi					// All done  

	// Secondary hash
30:	andi.	r1,r3,0x40			// Already doing secondary hash?
	bne	DoDSI_603			// Yes - item not in hash table
	mfspr	r2,HASH2			// Get hash table pointer
	ori	r3,r3,0x40      		// Set secondary hash
	b	00b				// Try lookup again

#ifdef P603_USE_C_BIT
	// Entry found and PTE[c] == 0. Check protection before setting PTE[c]
	// r0 = saved ctr, r1 = second word of PTE, r2 = pointer to pteg, r3 = trash
CheckProt_603:
	rlwinm.	r3,r1,30,0,1			// test PP
	bge-	50f				// if (PP == 00 or PP == 01) goto 50
	andi.	r3,r1,1				// test PP[0]
	beq+	60f				// return if PP[0] == 0
	b	DoDSI_603_P			// else DSI_P, (PP==11, read-only)

50:	mfspr	r3,SRR1				// get old msr
	andis.	r3,r3,0x0008			// test the KEY bit (SRR1-bit 12)
	beq	60f				// if KEY==0, goto 60
	b	DoDSI_603_P			// else DSI_P

60:	ori	r1,r1,0x180			// set reference and change bit
	sth	r1,6(r2)			// update page table
	b	16b				// and back we go
#endif

	
/************************************************************************/
/*	Data Load TLB Miss (603 specific vector)			*/
/************************************************************************/
		
VECTOR_603( 0x1100, "Data Load TLB Miss - 603" )
//	mfctr	r0				// Need to save this - CTR can't be touched!
	mfspr	r2,HASH1			// Get PTE pointer
	mfspr	r3,DCMP				// Partial item compare value
00:	li	r1,8				// 8 items / bucket
	mtctr	r1
	subi	r2,r2,8				// Preset pointer
10:	lwzu	r1,8(r2)			// Get next PTE
	cmp	0,r1,r3				// Found entry yet?
	bdnzf	2,10b				// Jump back if not, until CTR==0
	bne	30f				// Try secondary hash if CTR==0
	lwz	r1,4(r2)			// Get second word of entry
20:     mtctr	r0				// Restore CTR
	mfspr	r3,SRR1				// Need to restore CR0
	mtcrf	0x80,r3
	mfspr	r0,DMISS			// Set to update TLB
	mtspr	RPA,r1
#ifdef P603_USE_R_BIT
	ori	r1,r1,0x100			// set reference bit
	srwi	r1,r1,8
	tlbld	r0
	stb	r1,6(r2)
#else
	tlbld	r0
#endif
	rfi					// All done
	
// Secondary hash
30:	andi.	r1,r3,0x40			// Already doing secondary hash?
	bne	DoDSI_603			// Yes - item not in hash table
	mfspr	r2,HASH2			// Get hash table pointer
	ori	r3,r3,0x40			// Set secondary hash
	b	00b				// Try lookup again


/************************************************************************/
/*	Synthesize an ISI Exception					*/
/************************************************************************/

DoISI_603:
	mfspr   r3,SRR1
	andi.   r2,r3,0xFFFF			// Clear upper bits of SRR1
	addis   r2,r2,0x4000			// Set bit 1 -> PTE not found (in HTAB)
	mtctr   r0				// Restore CTR
40:	mtspr   SRR1,r2
	mfmsr   r0				// Restore "normal" registers
	xoris   r0,r0,MSR_TGPR>>16
	mtcrf   0x80,r3				// Restore CR0
	sync					// Some chip revs have problems here...
	mtmsr   r0
	SOFT_VECTOR_ENTRY_603( 0x400 )		// Jump to the ISI vector


#ifdef P603_USE_G_BIT
DoISI_603_G:
	mfspr	r3,SRR1
	andi.	r2,r3,0xFFFF			// Clear upper bits of SRR1
//	addis	r2,r2,0x0800			// Page protection violation
	addis	r2,r2,0x1000			// Guarded memory access
	b	40b
#endif

	
/************************************************************************/
/*	Synthesize a DSI exception					*/
/************************************************************************/
	
DoDSI_603:
	mfspr	r3,SRR1
	rlwinm	r1,r3,9,6,6     		// Get load/store bit
	addis	r1,r1,0x4000			// Set bit 1 -> PTE not found

10:	mtspr	DSISR,r1
	mtctr	r0				// Restore CTR
	andi.	r2,r3,0xFFFF			// Clear upper bits of SRR1
	mtspr	SRR1,r2
	mfspr	r1,DMISS			// Get failing address
	mtspr	DAR,r1				// Set fault address
	mfmsr	r0				// Restore "normal" registers
	xoris   r0,r0,MSR_TGPR>>16
	mtcrf   0x80,r3				// Restore CR0
	sync					// Some chip revs have problems here...
	mtmsr   r0
	SOFT_VECTOR_ENTRY_603( 0x300 )		// Jump to the DSI vector

DoDSI_603_P:
	mfspr	r3,SRR1
	rlwinm	r1,r3,9,6,6			// get load/store bit
	addis	r1,r1,0x800			// Set bit 4 (prot. violation)
	b	10b