summaryrefslogtreecommitdiffstats
path: root/private/ntos/fw/mips/j3trap.s
blob: 2e4f7fabeb5259aa779a113df092a26ae314462f (plain) (blame)
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#if defined(JAZZ) && defined(R3000)

/*++

Copyright (c) 1990  Microsoft Corporation

Module Name:

        j3trap.s

Abstract:

	This module will handle exceptions
	It will save the state of the processor, check jump table
	to see if it should dispatch somewhere, and then return to 
	monitor.

Author:

	John Cooper (johncoop) 4-Oct-90

Environment:

	Kernel mode

Revision History:


--*/
//
// include header file
//

#include "ksmips.h"
#include "selfmap.h"
#include "led.h"
#define PROM_BASE (KSEG1_BASE | 0x1fc00000)
#define PROM_ENTRY(x) (PROM_BASE + ((x) * 8))

.set noat
.set noreorder
.text



	.globl	ExceptionDispatch
ExceptionDispatch:
/*++

Routine Description:

	This routine will use a lookup table based on the exception 
	cause, to call an exception handler. If the value in
	lookup table is zero, the state of the machine is saved,
	and control is passed to monitor.
	The return value of the exception handler indicates where
	control should go when the exception condition is cleared.

Arguments:

    K1 - Contains the cause register.

Return Value:

    None.

--*/
	//
	// Need to save return address before calling an exec. handler.
	//

	li	k0,GLOBAL_DATA_BASE	// base of saved state
	sw	ra, 0x7C(k0)		// save ra
	
	//
	// Get jump vector from lookup table based on cause.
	// Call handler if value is non-zero
	//
	li	k0,EXCEPTION_JUMP_TABLE	// base of jump table
	addu	k0,k0,k1		// add offset to base
	lw	k1,0(k0)		// get jump vector from tbl
	li	k0,GOTO_MONITOR		// go back to monitor by default
	beq	k1,zero,ExceptionReturn // go save state and call mon.
	li	ra,COMMONEXCEPTION	// load this value into ra.
					// this will get passed as
					// argument to MonitorInit()
					// which will then print a message
					// saying a COMMONEXCEPTION occured.
					// COMMON EXCEPTION is an unaligned #.
					// if k1 != zero the jal reloads ra
	jal	k1			// with the right value.
	nop				// control will pass to the 
					// Exception Return routine next.
					// return value from handler
					// should be returned in k0.
					// this is passed as argument 
					// to ExceptionReturn.

	.globl ExceptionReturn
ExceptionReturn:

/*++

Routine Description:

	This routine will restore any registers that have been modified
	by the trap handler. Control is then passed back to one
	of three places. Either the monitor, the location stored in the
	EPC, or the value supplied in the argumnet k0.

Arguments:

	k0 - supplies indication of where to go after clearing exception.
		if bits [1:0] are 00B then go to location indicated 
		in k0. if bits [1:0] are GOTO_MONITOR, then control
		is passed to MonitorReInit(). if bits are GOTO_EPC then
		control is returned to location where exception occured.

Return Value:

    None.

--*/


	//
	// Return value from exec. handler is in k0.
	// if low bits are 00, then return to value in k0
	// if low bits are 01, then return to Err PC
	// if low bits are 10, then return to monitor
	//
	andi	k1,k0,3 		// k1 = k0 & 3
	beq	k1,zero,returntok0	// go if return code is 0
	andi	k1,k0,GOTO_EPC		// k1 = k0 & 1
	bne	k1,zero,returntoEPC	// if bit1=1 then GOTO_EPC
	andi	k1,k0,GOTO_MONITOR	// k1 = k0 & 2
	bne	k1,zero,returntomonitor // if bit2=1  then GOTO_MONITOR
	nop
	b	returntomonitor		// default return action
	nop
returntok0:

	//
	// restore value to ra
	//

	li	k1,GLOBAL_DATA_BASE	// base of saved state
	lw	ra, 0x7C(k1)	       // restore ra

	//
	// return to value in k0 when clearing exception condition
	// do this by putting k0 in EPC
	//
	j	k0			// return to k0
	rfe				// restore pre-exc state
returntoEPC:

	//
	// restore value to ra
	//

	li	k1,GLOBAL_DATA_BASE	// base of saved state

	//
	// return to location where exeception was caused
	//
	mfc0	k0,epc			// get return PC from cop0
	lw	ra, 0x7C(k1)		// restore ra
	j	k0			// jump to (EPC)
	rfe				// clear exception condition

returntomonitor:

	//
	// return to monitor by calling MonitorReInit()
	//
        //li      k0,MONITOR_LINK_ADDRESS
        //j       k0
        //rfe                             // restore pre-exc state
        li      k0,PROM_ENTRY(14)
        lui     a0,LED_BLINK
        jal     k0
        ori     a0,a0,0xFC

	.globl TLBMiss
TLBMiss:

/*++

Routine Description:

	This routine will modifiy the TLB when a miss occurs.
	It will take the failed virtual address and place it
	in the TLB as a physical address. This will make
	a one to one mapping between virtual and physical.
	If the address is E2000000 - E3FFFFFF, then routine
	will subtract off 52000000 for eisa spaces.
	This routine is only expected to be used for the R3000

	Note that the control from the exception vector is passed
	to the dispatch routine. The dispatch routine calls this 
	routine - control is passed back to the dispatch routine.

Arguments:

    None.

Return Value:

    None.

--*/

	//
	// load bad virtual address - the address that missed in TLB
	//

	mfc0	k0,badvaddr

	//
	// mask out page offset to get virtual page number.
	// offset differs in size between R4000 and R3000
	//

	li		k1,0xFFFFF000

	and	k0,k0,k1

	//
	// store bad virtual address in the EntryHi register to 
	//

	mtc0	k0,entryhi

	//
	// check if value is between E2000000 - E3FFFFFF
	// set bits in range (01FFFFFF) and compare to E3FFFFFF
	//

	li	k1,0x01FFFFFF
	or	k0,k0,k1
	li	k1,0xE3FFFFFF

	bne	k1,k0,noteisa

	//
	// subtract off 52000000
	//

	mfc0	k0,entryhi
	li	k1,0x52000000
	sub	k0,k0,k1
	nop

noteisa:
	//
	// set non-cached, dirty, valid, and global bits
	//
	//

	li	k1,(1<<ENTRYLO_D) + (1<<ENTRYLO_V) + (1<<ENTRYLO_G) + (1<<ENTRYLO_N)
	or	k0,k0,k1
	mtc0	k0,entrylo

	//
	// set index to 63 to write the 63 entry. always replace this
	// entry to preserve all the other entries.
	//

	li	k0,(63<<INDEX_INDEX)
	mtc0	k0,index
	nop

	//
	// write the tlb entry.
	//

	tlbwi
	nop

	//
	// return from exception - tell dispatch to go to EPC
	//

	j	ra
	li	k0,GOTO_EPC

#endif // R3000 && JAZZ