]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
3a60a9f5 | 2 | * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved. |
1c79356b | 3 | * |
8ad349bb | 4 | * @APPLE_LICENSE_OSREFERENCE_HEADER_START@ |
1c79356b | 5 | * |
8ad349bb A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the | |
10 | * License may not be used to create, or enable the creation or | |
11 | * redistribution of, unlawful or unlicensed copies of an Apple operating | |
12 | * system, or to circumvent, violate, or enable the circumvention or | |
13 | * violation of, any terms of an Apple operating system software license | |
14 | * agreement. | |
15 | * | |
16 | * Please obtain a copy of the License at | |
17 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
18 | * file. | |
19 | * | |
20 | * The Original Code and all software distributed under the License are | |
21 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
22 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
23 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
24 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
25 | * Please see the License for the specific language governing rights and | |
26 | * limitations under the License. | |
27 | * | |
28 | * @APPLE_LICENSE_OSREFERENCE_HEADER_END@ | |
1c79356b A |
29 | */ |
30 | /* | |
31 | * @OSF_COPYRIGHT@ | |
32 | */ | |
33 | ||
34 | /* Low level routines dealing with exception entry and exit. | |
35 | * There are various types of exception: | |
36 | * | |
37 | * Interrupt, trap, system call and debugger entry. Each has it's own | |
38 | * handler since the state save routine is different for each. The | |
39 | * code is very similar (a lot of cut and paste). | |
40 | * | |
41 | * The code for the FPU disabled handler (lazy fpu) is in cswtch.s | |
42 | */ | |
43 | ||
44 | #include <debug.h> | |
45 | #include <mach_assert.h> | |
46 | #include <mach/exception_types.h> | |
55e303ae | 47 | #include <mach/kern_return.h> |
1c79356b A |
48 | #include <mach/ppc/vm_param.h> |
49 | ||
50 | #include <assym.s> | |
51 | ||
52 | #include <ppc/asm.h> | |
53 | #include <ppc/proc_reg.h> | |
54 | #include <ppc/trap.h> | |
55 | #include <ppc/exception.h> | |
9bccf70c | 56 | #include <ppc/savearea.h> |
1c79356b A |
57 | |
58 | ||
59 | #define VERIFYSAVE 0 | |
60 | #define FPVECDBG 0 | |
b36670ce | 61 | #define FPFLOOD 0 |
55e303ae A |
62 | #define INSTRUMENT 0 |
63 | ||
1c79356b A |
64 | /* |
65 | * thandler(type) | |
66 | * | |
67 | * ENTRY: VM switched ON | |
68 | * Interrupts OFF | |
69 | * R3 contains exception code | |
70 | * R4 points to the saved context (virtual address) | |
71 | * Everything is saved in savearea | |
72 | */ | |
73 | ||
74 | /* | |
75 | * If pcb.ksp == 0 then the kernel stack is already busy, | |
9bccf70c | 76 | * we make a stack frame |
1c79356b A |
77 | * leaving enough space for the 'red zone' in case the |
78 | * trapped thread was in the middle of saving state below | |
79 | * its stack pointer. | |
80 | * | |
9bccf70c | 81 | * otherwise we make a stack frame and |
1c79356b A |
82 | * the kernel stack (setting pcb.ksp to 0) |
83 | * | |
84 | * on return, we do the reverse, the last state is popped from the pcb | |
85 | * and pcb.ksp is set to the top of stack | |
86 | */ | |
87 | ||
1c79356b A |
88 | /* TRAP_SPACE_NEEDED is the space assumed free on the kernel stack when |
89 | * another trap is taken. We need at least enough space for a saved state | |
90 | * structure plus two small backpointer frames, and we add a few | |
91 | * hundred bytes for the space needed by the C (which may be less but | |
92 | * may be much more). We're trying to catch kernel stack overflows :-) | |
93 | */ | |
94 | ||
95 | #define TRAP_SPACE_NEEDED FM_REDZONE+(2*FM_SIZE)+256 | |
96 | ||
1c79356b A |
97 | .text |
98 | ||
0b4e3aa0 A |
99 | .align 5 |
100 | .globl EXT(thandler) | |
9bccf70c | 101 | LEXT(thandler) ; Trap handler |
0b4e3aa0 | 102 | |
91447636 A |
103 | mfsprg r13,1 ; Get the current activation |
104 | lwz r25,ACT_PER_PROC(r13) ; Get the per_proc block | |
1c79356b | 105 | |
9bccf70c | 106 | lwz r1,PP_ISTACKPTR(r25) ; Get interrupt stack pointer |
1c79356b | 107 | |
9bccf70c | 108 | cmpwi cr0,r1,0 ; Are we on interrupt stack? |
91447636 | 109 | mr r6,r13 |
9bccf70c | 110 | beq- cr0,EXT(ihandler) ; If on interrupt stack, treat this as interrupt... |
9bccf70c A |
111 | lwz r26,ACT_MACT_SPF(r13) ; Get special flags |
112 | lwz r8,ACT_MACT_PCB(r13) ; Get the last savearea used | |
0b4e3aa0 | 113 | rlwinm. r26,r26,0,bbThreadbit,bbThreadbit ; Do we have Blue Box Assist active? |
9bccf70c A |
114 | lwz r1,ACT_MACT_KSP(r13) ; Get the top of kernel stack |
115 | bnel- checkassist ; See if we should assist this | |
116 | stw r4,ACT_MACT_PCB(r13) ; Point to our savearea | |
55e303ae | 117 | stw r8,SAVprev+4(r4) ; Queue the new save area in the front |
1c79356b A |
118 | |
119 | #if VERIFYSAVE | |
9bccf70c | 120 | bl versave ; (TEST/DEBUG) |
1c79356b A |
121 | #endif |
122 | ||
9bccf70c A |
123 | lwz r9,THREAD_KERNEL_STACK(r6) ; Get our kernel stack start |
124 | cmpwi cr1,r1,0 ; Are we already on kernel stack? | |
125 | stw r13,SAVact(r4) ; Mark the savearea as belonging to this activation | |
55e303ae | 126 | lwz r26,saver1+4(r4) ; Get the stack at interrupt time |
1c79356b | 127 | |
9bccf70c | 128 | bne+ cr1,.L_kstackfree ; We are not on kernel stack yet... |
1c79356b | 129 | |
9bccf70c | 130 | subi r1,r26,FM_REDZONE ; Make a red zone on interrupt time kernel stack |
1c79356b A |
131 | |
132 | .L_kstackfree: | |
91447636 | 133 | lwz r31,savesrr1+4(r4) ; Pick up the entry MSR |
9bccf70c A |
134 | sub r9,r1,r9 ; Get displacment into the kernel stack |
135 | li r0,0 ; Make this 0 | |
55e303ae | 136 | rlwinm. r0,r9,0,28,31 ; Verify that we have a 16-byte aligned stack (and get a 0) |
9bccf70c A |
137 | cmplwi cr2,r9,KERNEL_STACK_SIZE ; Do we still have room on the stack? |
138 | beq cr1,.L_state_on_kstack ; using above test for pcb/stack | |
1c79356b | 139 | |
9bccf70c | 140 | stw r0,ACT_MACT_KSP(r13) ; Show that we have taken the stack |
1c79356b A |
141 | |
142 | .L_state_on_kstack: | |
9bccf70c | 143 | lwz r9,savevrsave(r4) ; Get the VRSAVE register |
55e303ae | 144 | bne-- kernelStackUnaligned ; Stack is unaligned... |
91447636 | 145 | rlwinm. r6,r31,0,MSR_VEC_BIT,MSR_VEC_BIT ; Was vector on? |
9bccf70c | 146 | subi r1,r1,FM_SIZE ; Push a header onto the current stack |
55e303ae | 147 | bgt-- cr2,kernelStackBad ; Kernel stack is bogus... |
9bccf70c A |
148 | |
149 | kernelStackNotBad: ; Vector was off | |
55e303ae | 150 | beq++ tvecoff ; Vector off, do not save vrsave... |
9bccf70c A |
151 | stw r9,liveVRS(r25) ; Set the live value |
152 | ||
153 | tvecoff: stw r26,FM_BACKPTR(r1) ; Link back to the previous frame | |
1c79356b A |
154 | |
155 | #if DEBUG | |
156 | /* If debugging, we need two frames, the first being a dummy | |
157 | * which links back to the trapped routine. The second is | |
158 | * that which the C routine below will need | |
159 | */ | |
55e303ae | 160 | lwz r3,savesrr0+4(r4) ; Get the point of interruption |
9bccf70c A |
161 | stw r3,FM_LR_SAVE(r1) ; save old instr ptr as LR value |
162 | stwu r1, -FM_SIZE(r1) ; and make new frame | |
1c79356b A |
163 | #endif /* DEBUG */ |
164 | ||
91447636 A |
165 | mr r30,r4 |
166 | lwz r3,SAVtime+4(r4) | |
167 | addi r4,r13,SYSTEM_TIMER | |
168 | bl EXT(timer_event) | |
1c79356b A |
169 | |
170 | /* call trap handler proper, with | |
91447636 A |
171 | * ARG0 = type |
172 | * ARG1 = saved_state ptr | |
173 | * ARG2 = dsisr | |
174 | * ARG3 = dar | |
1c79356b A |
175 | */ |
176 | ||
91447636 A |
177 | mr r4,r30 |
178 | lwz r3,saveexception(r30) ; Get the exception code | |
9bccf70c | 179 | lwz r0,ACT_MACT_SPF(r13) ; Get the special flags |
1c79356b | 180 | |
9bccf70c | 181 | addi r5,r3,-T_DATA_ACCESS ; Adjust to start of range |
1c79356b | 182 | rlwinm. r0,r0,0,runningVMbit,runningVMbit ; Are we in VM state? (cr0_eq == 0 if yes) |
9bccf70c | 183 | cmplwi cr2,r5,T_TRACE-T_DATA_ACCESS ; Are we still in range? (cr_gt if not) |
1c79356b | 184 | |
9bccf70c | 185 | lwz r5,savedsisr(r4) ; Get the saved DSISR |
1c79356b | 186 | |
9bccf70c | 187 | crnor cr7_eq,cr0_eq,cr2_gt ; We should intercept if in VM and is a true trap (cr7_eq == 1 if yes) |
91447636 | 188 | rlwinm. r0,r31,0,MSR_PR_BIT,MSR_PR_BIT ; Are we trapping from supervisor state? (cr0_eq == 1 if yes) |
1c79356b | 189 | |
9bccf70c | 190 | cmpi cr2,r3,T_PREEMPT ; Is this a preemption? |
55e303ae A |
191 | |
192 | beq-- .L_check_VM | |
193 | stw r4,ACT_MACT_UPCB(r13) ; Store user savearea | |
194 | .L_check_VM: | |
1c79356b | 195 | |
9bccf70c | 196 | crandc cr0_eq,cr7_eq,cr0_eq ; Do not intercept if we are in the kernel (cr0_eq == 1 if yes) |
1c79356b | 197 | |
55e303ae A |
198 | lwz r6,savedar(r4) ; Get the DAR (top) |
199 | lwz r7,savedar+4(r4) ; Get the DAR (bottom) | |
1c79356b | 200 | |
55e303ae | 201 | beq- cr2,.L_call_trap ; Do not turn on interrupts for T_PREEMPT |
9bccf70c | 202 | beq- exitFromVM ; Any true trap but T_MACHINE_CHECK exits us from the VM... |
1c79356b A |
203 | |
204 | /* syscall exception might warp here if there's nothing left | |
205 | * to do except generate a trap | |
206 | */ | |
207 | ||
208 | .L_call_trap: | |
1c79356b | 209 | |
b36670ce A |
210 | #if FPFLOOD |
211 | stfd f31,emfp31(r25) ; (TEST/DEBUG) | |
212 | #endif | |
213 | ||
1c79356b A |
214 | bl EXT(trap) |
215 | ||
55e303ae | 216 | lis r10,hi16(MASK(MSR_VEC)) ; Get the vector enable |
9bccf70c | 217 | mfmsr r7 ; Get the MSR |
55e303ae A |
218 | ori r10,r10,lo16(MASK(MSR_FP)|MASK(MSR_EE)) ; Add in FP and EE |
219 | andc r7,r7,r10 ; Turn off VEC, FP, and EE | |
9bccf70c | 220 | mtmsr r7 ; Disable for interrupts |
91447636 A |
221 | mfsprg r8,1 ; Get the current activation |
222 | lwz r10,ACT_PER_PROC(r8) ; Get the per_proc block | |
1c79356b | 223 | /* |
1c79356b A |
224 | * This is also the point where new threads come when they are created. |
225 | * The new thread is setup to look like a thread that took an | |
226 | * interrupt and went immediatly into trap. | |
1c79356b A |
227 | */ |
228 | ||
229 | thread_return: | |
9bccf70c | 230 | lwz r11,SAVflags(r3) ; Get the flags of the current savearea |
55e303ae A |
231 | lwz r0,savesrr1+4(r3) ; Get the MSR we are going to |
232 | lwz r4,SAVprev+4(r3) ; Pick up the previous savearea | |
233 | mfsprg r8,1 ; Get the current thread | |
d7e50217 | 234 | rlwinm r11,r11,0,15,13 ; Clear the syscall flag |
55e303ae | 235 | rlwinm. r0,r0,0,MSR_PR_BIT,MSR_PR_BIT ; Are we going to the user? |
91447636 | 236 | mr r1,r8 |
9bccf70c | 237 | stw r11,SAVflags(r3) ; Save back the flags (with reset stack cleared) |
55e303ae A |
238 | |
239 | lwz r5,THREAD_KERNEL_STACK(r1) ; Get the base pointer to the stack | |
9bccf70c | 240 | stw r4,ACT_MACT_PCB(r8) ; Point to the previous savearea (or 0 if none) |
55e303ae | 241 | addi r5,r5,KERNEL_STACK_SIZE-FM_SIZE ; Reset to empty |
1c79356b | 242 | |
55e303ae | 243 | beq-- chkfac ; We are not leaving the kernel yet... |
1c79356b | 244 | |
9bccf70c A |
245 | stw r5,ACT_MACT_KSP(r8) ; Save the empty stack pointer |
246 | b chkfac ; Go end it all... | |
1c79356b A |
247 | |
248 | ||
0b4e3aa0 A |
249 | ; |
250 | ; Here is where we go when we detect that the kernel stack is all messed up. | |
251 | ; We just try to dump some info and get into the debugger. | |
252 | ; | |
253 | ||
254 | kernelStackBad: | |
255 | ||
9bccf70c | 256 | lwz r3,PP_DEBSTACK_TOP_SS(r25) ; Pick up debug stack top |
0b4e3aa0 | 257 | subi r3,r3,KERNEL_STACK_SIZE-FM_SIZE ; Adjust to start of stack |
9bccf70c | 258 | sub r3,r1,r3 ; Get displacement into debug stack |
0b4e3aa0 | 259 | cmplwi cr2,r3,KERNEL_STACK_SIZE-FM_SIZE ; Check if we are on debug stack |
9bccf70c | 260 | blt+ cr2,kernelStackNotBad ; Yeah, that is ok too... |
0b4e3aa0 | 261 | |
9bccf70c A |
262 | lis r0,hi16(Choke) ; Choke code |
263 | ori r0,r0,lo16(Choke) ; and the rest | |
264 | li r3,failStack ; Bad stack code | |
265 | sc ; System ABEND | |
0b4e3aa0 | 266 | |
55e303ae A |
267 | kernelStackUnaligned: |
268 | lis r0,hi16(Choke) ; Choke code | |
269 | ori r0,r0,lo16(Choke) ; and the rest | |
270 | li r3,failUnalignedStk ; Unaligned stack code | |
271 | sc ; System ABEND | |
272 | ||
1c79356b A |
273 | |
274 | /* | |
275 | * shandler(type) | |
276 | * | |
277 | * ENTRY: VM switched ON | |
278 | * Interrupts OFF | |
279 | * R3 contains exception code | |
280 | * R4 points to the saved context (virtual address) | |
281 | * Everything is saved in savearea | |
282 | */ | |
283 | ||
284 | /* | |
285 | * If pcb.ksp == 0 then the kernel stack is already busy, | |
286 | * this is an error - jump to the debugger entry | |
287 | * | |
288 | * otherwise depending upon the type of | |
289 | * syscall, look it up in the kernel table | |
290 | * or pass it to the server. | |
291 | * | |
292 | * on return, we do the reverse, the state is popped from the pcb | |
293 | * and pcb.ksp is set to the top of stack. | |
294 | */ | |
295 | ||
296 | /* | |
297 | * NOTE: | |
298 | * mach system calls are negative | |
299 | * BSD system calls are low positive | |
300 | * PPC-only system calls are in the range 0x6xxx | |
301 | * PPC-only "fast" traps are in the range 0x7xxx | |
302 | */ | |
303 | ||
0b4e3aa0 A |
304 | .align 5 |
305 | .globl EXT(shandler) | |
9bccf70c A |
306 | LEXT(shandler) ; System call handler |
307 | ||
55e303ae | 308 | lwz r7,savesrr1+4(r4) ; Get the SRR1 value |
91447636 A |
309 | mfsprg r13,1 ; Get the current activation |
310 | lwz r25,ACT_PER_PROC(r13) ; Get the per_proc block | |
55e303ae | 311 | lwz r0,saver0+4(r4) ; Get the original syscall number |
9bccf70c A |
312 | lwz r17,PP_ISTACKPTR(r25) ; Get interrupt stack pointer |
313 | rlwinm r15,r0,0,0,19 ; Clear the bottom of call number for fast check | |
314 | mr. r17,r17 ; Are we on interrupt stack? | |
9bccf70c | 315 | lwz r9,savevrsave(r4) ; Get the VRsave register |
55e303ae | 316 | beq-- EXT(ihandler) ; On interrupt stack, not allowed... |
1c79356b | 317 | rlwinm. r6,r7,0,MSR_VEC_BIT,MSR_VEC_BIT ; Was vector on? |
91447636 | 318 | mr r16,r13 |
1c79356b | 319 | |
55e303ae | 320 | beq++ svecoff ; Vector off, do not save vrsave... |
9bccf70c A |
321 | stw r9,liveVRS(r25) ; Set the live value |
322 | ; | |
1c79356b | 323 | ; Check if SCs are being redirected for the BlueBox or to VMM |
9bccf70c | 324 | ; |
1c79356b | 325 | |
9bccf70c | 326 | svecoff: lwz r6,ACT_MACT_SPF(r13) ; Pick up activation special flags |
55e303ae A |
327 | mtcrf 0x40,r6 ; Check special flags |
328 | mtcrf 0x01,r6 ; Check special flags | |
9bccf70c | 329 | crmove cr6_eq,runningVMbit ; Remember if we are in VMM |
55e303ae | 330 | bne++ cr6,sVMchecked ; Not running VM |
d7e50217 A |
331 | lwz r18,spcFlags(r25) ; Load per_proc special flags |
332 | rlwinm. r18,r18,0,FamVMmodebit,FamVMmodebit ; Is FamVMmodebit set? | |
333 | beq sVMchecked ; Not in FAM | |
334 | cmpwi r0,0x6004 ; Is it vmm_dispatch syscall: | |
335 | bne sVMchecked | |
55e303ae | 336 | lwz r26,saver3+4(r4) ; Get the original syscall number |
d7e50217 A |
337 | cmpwi cr6,r26,kvmmExitToHost ; vmm_exit_to_host request |
338 | sVMchecked: | |
55e303ae | 339 | bf++ bbNoMachSCbit,noassist ; Take branch if SCs are not redirected |
9bccf70c A |
340 | lwz r26,ACT_MACT_BEDA(r13) ; Pick up the pointer to the blue box exception area |
341 | b EXT(atomic_switch_syscall) ; Go to the assist... | |
1c79356b | 342 | |
9bccf70c A |
343 | noassist: cmplwi r15,0x7000 ; Do we have a fast path trap? |
344 | lwz r14,ACT_MACT_PCB(r13) ; Now point to the PCB | |
55e303ae | 345 | beql fastpath ; We think it is a fastpath... |
1c79356b | 346 | |
9bccf70c | 347 | lwz r1,ACT_MACT_KSP(r13) ; Get the kernel stack pointer |
1c79356b | 348 | #if DEBUG |
9bccf70c A |
349 | mr. r1,r1 ; Are we already on the kernel stack? |
350 | li r3,T_SYSTEM_CALL ; Yup, pretend we had an interrupt... | |
351 | beq- EXT(ihandler) ; Bad boy, bad boy... What cha gonna do when they come for you? | |
1c79356b A |
352 | #endif /* DEBUG */ |
353 | ||
9bccf70c | 354 | stw r4,ACT_MACT_PCB(r13) ; Point to our savearea |
55e303ae | 355 | stw r4,ACT_MACT_UPCB(r13) ; Store user savearea |
9bccf70c | 356 | li r0,0 ; Clear this out |
55e303ae | 357 | stw r14,SAVprev+4(r4) ; Queue the new save area in the front |
9bccf70c | 358 | stw r13,SAVact(r4) ; Point the savearea at its activation |
1c79356b A |
359 | |
360 | #if VERIFYSAVE | |
9bccf70c | 361 | bl versave ; (TEST/DEBUG) |
1c79356b A |
362 | #endif |
363 | ||
55e303ae | 364 | lwz r15,saver1+4(r4) ; Grab interrupt time stack |
9bccf70c | 365 | mr r30,r4 ; Save pointer to the new context savearea |
9bccf70c A |
366 | stw r0,ACT_MACT_KSP(r13) ; Mark stack as busy with 0 val |
367 | stw r15,FM_BACKPTR(r1) ; Link stack frame backwards | |
91447636 A |
368 | |
369 | lwz r3,SAVtime+4(r30) | |
370 | addi r4,r13,SYSTEM_TIMER | |
371 | bl EXT(timer_event) | |
1c79356b A |
372 | |
373 | #if DEBUG | |
9bccf70c A |
374 | /* If debugging, we need two frames, the first being a dummy |
375 | * which links back to the trapped routine. The second is | |
376 | * that which the C routine below will need | |
377 | */ | |
55e303ae | 378 | lwz r8,savesrr0+4(r30) ; Get the point of interruption |
9bccf70c A |
379 | stw r8,FM_LR_SAVE(r1) ; Save old instr ptr as LR value |
380 | stwu r1, -FM_SIZE(r1) ; and make new frame | |
1c79356b A |
381 | #endif /* DEBUG */ |
382 | ||
91447636 A |
383 | mr r4,r30 |
384 | ||
de355530 | 385 | lwz r15,SAVflags(r30) ; Get the savearea flags |
55e303ae A |
386 | lwz r0,saver0+4(r30) ; Get R0 back |
387 | mfmsr r11 ; Get the MSR | |
91447636 | 388 | stwu r1,-(FM_SIZE+ARG_SIZE+MUNGE_ARGS_SIZE)(r1) ; Make a stack frame |
9bccf70c | 389 | ori r11,r11,lo16(MASK(MSR_EE)) ; Turn on interruption enabled bit |
de355530 | 390 | rlwinm r10,r0,0,0,19 ; Keep only the top part |
55e303ae | 391 | oris r15,r15,SAVsyscall >> 16 ; Mark that it this is a syscall |
9bccf70c A |
392 | cmplwi r10,0x6000 ; Is it the special ppc-only guy? |
393 | stw r15,SAVflags(r30) ; Save syscall marker | |
55e303ae | 394 | beq-- cr6,exitFromVM ; It is time to exit from alternate context... |
9bccf70c | 395 | |
55e303ae | 396 | beq-- ppcscall ; Call the ppc-only system call handler... |
9bccf70c | 397 | |
55e303ae | 398 | mr. r0,r0 ; What kind is it? |
9bccf70c A |
399 | mtmsr r11 ; Enable interruptions |
400 | ||
55e303ae | 401 | blt-- .L_kernel_syscall ; System call number if negative, this is a mach call... |
9bccf70c | 402 | |
55e303ae | 403 | lwz r8,ACT_TASK(r13) ; Get our task |
9bccf70c | 404 | cmpwi cr0,r0,0x7FFA ; Special blue box call? |
55e303ae | 405 | beq-- .L_notify_interrupt_syscall ; Yeah, call it... |
9bccf70c | 406 | |
9bccf70c | 407 | lwz r7,TASK_SYSCALLS_UNIX(r8) ; Get the current count |
9bccf70c A |
408 | mr r3,r30 ; Get PCB/savearea |
409 | mr r4,r13 ; current activation | |
55e303ae A |
410 | addi r7,r7,1 ; Bump it |
411 | stw r7,TASK_SYSCALLS_UNIX(r8) ; Save it | |
b36670ce A |
412 | |
413 | #if FPFLOOD | |
414 | stfd f31,emfp31(r25) ; (TEST/DEBUG) | |
415 | #endif | |
416 | ||
9bccf70c | 417 | bl EXT(unix_syscall) ; Check out unix... |
1c79356b A |
418 | |
419 | .L_call_server_syscall_exception: | |
9bccf70c | 420 | li r3,EXC_SYSCALL ; doexception(EXC_SYSCALL, num, 1) |
1c79356b A |
421 | |
422 | .L_call_server_exception: | |
9bccf70c | 423 | mr r4,r0 ; Set syscall selector |
1c79356b | 424 | li r5,1 |
9bccf70c | 425 | b EXT(doexception) ; Go away, never to return... |
1c79356b A |
426 | |
427 | .L_notify_interrupt_syscall: | |
55e303ae | 428 | lwz r3,saver3+4(r30) ; Get the new PC address to pass in |
1c79356b | 429 | bl EXT(syscall_notify_interrupt) |
55e303ae A |
430 | /* |
431 | * Ok, return from C function, R3 = return value | |
432 | * | |
433 | * saved state is still in R30 and the active thread is in R16 . | |
434 | */ | |
435 | mr r31,r16 ; Move the current thread pointer | |
436 | stw r3,saver3+4(r30) ; Stash the return code | |
437 | b .L_thread_syscall_ret_check_ast | |
1c79356b A |
438 | |
439 | ; | |
440 | ; Handle PPC-only system call interface | |
441 | ; These are called with interruptions disabled | |
442 | ; and the savearea/pcb as the first parameter. | |
443 | ; It is up to the callee to enable interruptions if | |
444 | ; they should be. We are in a state here where | |
3a60a9f5 | 445 | ; both interrupts and preemption are ok, but because we could |
1c79356b A |
446 | ; be calling diagnostic code we will not enable. |
447 | ; | |
448 | ; Also, the callee is responsible for finding any parameters | |
449 | ; in the savearea/pcb. It also must set saver3 with any return | |
450 | ; code before returning. | |
451 | ; | |
452 | ; There are 3 possible return codes: | |
453 | ; 0 the call is disabled or something, we treat this like it was bogus | |
454 | ; + the call finished ok, check for AST | |
455 | ; - the call finished ok, do not check for AST | |
456 | ; | |
457 | ; Note: the last option is intended for special diagnostics calls that | |
458 | ; want the thread to return and execute before checking for preemption. | |
459 | ; | |
9bccf70c A |
460 | ; NOTE: Both R16 (thread) and R30 (savearea) need to be preserved over this call!!!! |
461 | ; | |
462 | ||
463 | .align 5 | |
1c79356b | 464 | |
9bccf70c A |
465 | ppcscall: rlwinm r11,r0,2,18,29 ; Make an index into the table |
466 | lis r10,hi16(EXT(PPCcalls)) ; Get PPC-only system call table | |
467 | cmplwi r11,PPCcallmax ; See if we are too big | |
468 | ori r10,r10,lo16(EXT(PPCcalls)) ; Merge in low half | |
1c79356b | 469 | bgt- .L_call_server_syscall_exception ; Bogus call... |
9bccf70c | 470 | lwzx r11,r10,r11 ; Get function address |
1c79356b A |
471 | |
472 | ; | |
473 | ; Note: make sure we do not change the savearea in R30 to | |
474 | ; a different register without checking. Some of the PPCcalls | |
475 | ; depend upon it being there. | |
476 | ; | |
477 | ||
9bccf70c A |
478 | mr r3,r30 ; Pass the savearea |
479 | mr r4,r13 ; Pass the activation | |
480 | mr. r11,r11 ; See if there is a function here | |
55e303ae | 481 | mtctr r11 ; Set the function address |
1c79356b | 482 | beq- .L_call_server_syscall_exception ; Disabled call... |
55e303ae A |
483 | #if INSTRUMENT |
484 | mfspr r4,pmc1 ; Get stamp | |
485 | stw r4,0x6100+(9*16)+0x0(0) ; Save it | |
486 | mfspr r4,pmc2 ; Get stamp | |
487 | stw r4,0x6100+(9*16)+0x4(0) ; Save it | |
488 | mfspr r4,pmc3 ; Get stamp | |
489 | stw r4,0x6100+(9*16)+0x8(0) ; Save it | |
490 | mfspr r4,pmc4 ; Get stamp | |
491 | stw r4,0x6100+(9*16)+0xC(0) ; Save it | |
492 | #endif | |
493 | bctrl ; Call it | |
9bccf70c | 494 | |
1c79356b | 495 | .globl EXT(ppcscret) |
9bccf70c | 496 | |
1c79356b | 497 | LEXT(ppcscret) |
9bccf70c A |
498 | mr. r3,r3 ; See what we should do |
499 | mr r31,r16 ; Restore the current thread pointer | |
1c79356b | 500 | bgt+ .L_thread_syscall_ret_check_ast ; Take normal AST checking return.... |
91447636 A |
501 | mfsprg r10,1 ; Get the current activation |
502 | lwz r10,ACT_PER_PROC(r10) ; Get the per_proc block | |
9bccf70c | 503 | blt+ .L_thread_syscall_return ; Return, but no ASTs.... |
55e303ae | 504 | lwz r0,saver0+4(r30) ; Restore the system call number |
1c79356b A |
505 | b .L_call_server_syscall_exception ; Go to common exit... |
506 | ||
507 | ||
55e303ae A |
508 | |
509 | /* | |
510 | * we get here for mach system calls | |
511 | * when kdebug tracing is enabled | |
512 | */ | |
513 | ||
514 | ksystrace: | |
3a60a9f5 | 515 | mr r4,r30 ; Pass in saved state |
55e303ae A |
516 | bl EXT(syscall_trace) |
517 | ||
3a60a9f5 A |
518 | cmplw r31,r29 ; Is this syscall in the table? |
519 | add r31,r27,r28 ; Point right to the syscall table entry | |
55e303ae A |
520 | |
521 | bge- .L_call_server_syscall_exception ; The syscall number is invalid | |
522 | ||
91447636 A |
523 | lwz r0,savesrr1(r30) ; Get the saved srr1 |
524 | rlwinm. r0,r0,0,MSR_SF_BIT,MSR_SF_BIT ; Test for 64 bit caller | |
525 | lwz r0,MACH_TRAP_ARG_MUNGE32(r31) ; Pick up the 32 bit munge function address | |
526 | beq-- .L_ksystrace_munge | |
527 | lwz r0,MACH_TRAP_ARG_MUNGE64(r31) ; Pick up the 64 bit munge function address | |
528 | ||
529 | .L_ksystrace_munge: | |
530 | cmplwi r0,0 ; do we have a munger to call? | |
3a60a9f5 A |
531 | mtctr r0 ; Set the function call address |
532 | addi r3,r30,saver3 ; Pointer to args from save area | |
533 | addi r4,r1,FM_ARG0+ARG_SIZE ; Pointer for munged args | |
91447636 | 534 | beq-- .L_ksystrace_trapcall ; just make the trap call |
3a60a9f5 | 535 | bctrl ; Call the munge function |
91447636 A |
536 | |
537 | .L_ksystrace_trapcall: | |
3a60a9f5 A |
538 | lwz r0,MACH_TRAP_FUNCTION(r31) ; Pick up the function address |
539 | mtctr r0 ; Set the function call address | |
540 | addi r3,r1,FM_ARG0+ARG_SIZE ; Pointer to munged args | |
91447636 A |
541 | bctrl |
542 | ||
3a60a9f5 A |
543 | mr r4,r30 ; Pass in the savearea |
544 | bl EXT(syscall_trace_end) ; Trace the exit of the system call | |
55e303ae A |
545 | b .L_mach_return |
546 | ||
547 | ||
548 | ||
1c79356b A |
549 | /* Once here, we know that the syscall was -ve |
550 | * we should still have r1=ksp, | |
551 | * r16 = pointer to current thread, | |
552 | * r13 = pointer to top activation, | |
553 | * r0 = syscall number | |
554 | * r30 = pointer to saved state (in pcb) | |
555 | */ | |
1c79356b | 556 | |
55e303ae | 557 | .align 5 |
1c79356b | 558 | |
9bccf70c A |
559 | .L_kernel_syscall: |
560 | ; | |
561 | ; Call a function that can print out our syscall info | |
562 | ; Note that we don t care about any volatiles yet | |
563 | ; | |
3a60a9f5 | 564 | lwz r10,ACT_TASK(r13) ; Get our task |
55e303ae | 565 | lwz r0,saver0+4(r30) |
3a60a9f5 | 566 | lis r8,hi16(EXT(kdebug_enable)) ; Get top of kdebug_enable |
55e303ae A |
567 | lis r28,hi16(EXT(mach_trap_table)) ; Get address of table |
568 | ori r8,r8,lo16(EXT(kdebug_enable)) ; Get bottom of kdebug_enable | |
3a60a9f5 | 569 | lwz r8,0(r8) ; Get kdebug_enable |
55e303ae | 570 | |
3a60a9f5 A |
571 | lwz r7,TASK_SYSCALLS_MACH(r10) ; Get the current count |
572 | neg r31,r0 ; Make this positive | |
573 | mr r3,r31 ; save it | |
574 | slwi r27,r3,4 ; multiply by 16 | |
575 | slwi r3,r3,2 ; and the original by 4 | |
55e303ae | 576 | ori r28,r28,lo16(EXT(mach_trap_table)) ; Get address of table |
3a60a9f5 A |
577 | add r27,r27,r3 ; for a total of 20x (5 words/entry) |
578 | addi r7,r7,1 ; Bump TASK_SYSCALLS_MACH count | |
579 | cmplwi r8,0 ; Is kdebug_enable non-zero | |
580 | stw r7,TASK_SYSCALLS_MACH(r10) ; Save count | |
581 | bne-- ksystrace ; yes, tracing enabled | |
55e303ae | 582 | |
3a60a9f5 A |
583 | cmplwi r31,MACH_TRAP_TABLE_COUNT ; Is this syscall in the table? |
584 | add r31,r27,r28 ; Point right to the syscall table entry | |
55e303ae A |
585 | |
586 | bge-- .L_call_server_syscall_exception ; The syscall number is invalid | |
de355530 | 587 | |
91447636 A |
588 | lwz r0,savesrr1(r30) ; Get the saved srr1 |
589 | rlwinm. r0,r0,0,MSR_SF_BIT,MSR_SF_BIT ; Test for 64 bit caller | |
590 | lwz r0,MACH_TRAP_ARG_MUNGE32(r31) ; Pick up the 32 bit munge function address | |
591 | beq-- .L_kernel_syscall_munge | |
592 | lwz r0,MACH_TRAP_ARG_MUNGE64(r31) ; Pick up the 64 bit munge function address | |
593 | ||
594 | .L_kernel_syscall_munge: | |
595 | cmplwi r0,0 ; test for null munger | |
b36670ce | 596 | mtctr r0 ; Set the function call address |
3a60a9f5 A |
597 | addi r3,r30,saver3 ; Pointer to args from save area |
598 | addi r4,r1,FM_ARG0+ARG_SIZE ; Pointer for munged args | |
599 | beq-- .L_kernel_syscall_trapcall ; null munger - skip to trap call | |
600 | bctrl ; Call the munge function | |
91447636 A |
601 | |
602 | .L_kernel_syscall_trapcall: | |
3a60a9f5 A |
603 | lwz r0,MACH_TRAP_FUNCTION(r31) ; Pick up the function address |
604 | mtctr r0 ; Set the function call address | |
605 | addi r3,r1,FM_ARG0+ARG_SIZE ; Pointer to munged args | |
b36670ce A |
606 | |
607 | #if FPFLOOD | |
608 | stfd f31,emfp31(r25) ; (TEST/DEBUG) | |
609 | #endif | |
610 | ||
91447636 A |
611 | bctrl |
612 | ||
1c79356b A |
613 | |
614 | /* | |
9bccf70c | 615 | * Ok, return from C function, R3 = return value |
1c79356b A |
616 | * |
617 | * get the active thread's PCB pointer and thus pointer to user state | |
55e303ae | 618 | * saved state is still in R30 and the active thread is in R16 |
1c79356b A |
619 | */ |
620 | ||
91447636 | 621 | .L_mach_return: |
3a60a9f5 A |
622 | srawi r0,r3,31 ; properly extend the return code |
623 | cmpi cr0,r3,KERN_INVALID_ARGUMENT ; deal with invalid system calls | |
624 | mr r31,r16 ; Move the current thread pointer | |
625 | stw r0, saver3(r30) ; stash the high part of the return code | |
626 | stw r3,saver3+4(r30) ; Stash the low part of the return code | |
627 | beq-- cr0,.L_mach_invalid_ret ; otherwise fall through into the normal return path | |
55e303ae A |
628 | .L_mach_invalid_arg: |
629 | ||
630 | ||
631 | /* 'standard' syscall returns here - INTERRUPTS ARE STILL ON | |
632 | * the syscall may perform a thread_set_syscall_return | |
1c79356b A |
633 | * followed by a thread_exception_return, ending up |
634 | * at thread_syscall_return below, with SS_R3 having | |
635 | * been set up already | |
55e303ae A |
636 | * |
637 | * When we are here, r31 should point to the current thread, | |
1c79356b | 638 | * r30 should point to the current pcb |
55e303ae A |
639 | * r3 contains value that we're going to return to the user |
640 | * which has already been stored back into the save area | |
1c79356b | 641 | */ |
55e303ae | 642 | |
1c79356b | 643 | .L_thread_syscall_ret_check_ast: |
55e303ae | 644 | lis r10,hi16(MASK(MSR_VEC)) ; Get the vector enable |
9bccf70c | 645 | mfmsr r12 ; Get the current MSR |
55e303ae A |
646 | ori r10,r10,lo16(MASK(MSR_FP)|MASK(MSR_EE)) ; Add in FP and EE |
647 | andc r12,r12,r10 ; Turn off VEC, FP, and EE | |
9bccf70c | 648 | mtmsr r12 ; Turn interruptions off |
1c79356b | 649 | |
91447636 A |
650 | mfsprg r10,1 ; Get the current activation |
651 | lwz r10,ACT_PER_PROC(r10) ; Get the per_proc block | |
1c79356b A |
652 | |
653 | /* Check to see if there's an outstanding AST */ | |
654 | ||
91447636 | 655 | lwz r4,PP_PENDING_AST(r10) |
9bccf70c | 656 | cmpi cr0,r4, 0 ; Any pending asts? |
55e303ae | 657 | beq++ cr0,.L_syscall_no_ast ; Nope... |
1c79356b A |
658 | |
659 | /* Yes there is, call ast_taken | |
660 | * pretending that the user thread took an AST exception here, | |
661 | * ast_taken will save all state and bring us back here | |
662 | */ | |
663 | ||
664 | #if DEBUG | |
665 | /* debug assert - make sure that we're not returning to kernel */ | |
55e303ae | 666 | lwz r3,savesrr1+4(r30) |
1c79356b | 667 | andi. r3,r3,MASK(MSR_PR) |
55e303ae | 668 | bne++ scrnotkern ; returning to user level, check |
1c79356b | 669 | |
9bccf70c A |
670 | lis r0,hi16(Choke) ; Choke code |
671 | ori r0,r0,lo16(Choke) ; and the rest | |
672 | li r3,failContext ; Bad state code | |
673 | sc ; System ABEND | |
0b4e3aa0 | 674 | |
9bccf70c | 675 | scrnotkern: |
1c79356b A |
676 | #endif /* DEBUG */ |
677 | ||
91447636 | 678 | lis r3,hi16(AST_ALL) ; Set ast flags |
9bccf70c | 679 | li r4,1 ; Set interrupt allowed |
91447636 | 680 | ori r3,r3,lo16(AST_ALL) |
9bccf70c A |
681 | bl EXT(ast_taken) ; Process the pending ast |
682 | b .L_thread_syscall_ret_check_ast ; Go see if there was another... | |
1c79356b | 683 | |
55e303ae A |
684 | .L_mach_invalid_ret: |
685 | /* | |
686 | * need to figure out why we got an KERN_INVALID_ARG | |
687 | * if it was due to a non-existent system call | |
688 | * then we want to throw an exception... otherwise | |
689 | * we want to pass the error code back to the caller | |
690 | */ | |
91447636 | 691 | lwz r0,saver0+4(r30) ; reload the original syscall number |
3a60a9f5 A |
692 | neg r28,r0 ; Make this positive |
693 | mr r4,r28 ; save a copy | |
694 | slwi r27,r4,4 ; multiply by 16 | |
695 | slwi r4,r4,2 ; and another 4 | |
55e303ae | 696 | lis r28,hi16(EXT(mach_trap_table)) ; Get address of table |
3a60a9f5 | 697 | add r27,r27,r4 ; for a total of 20x (5 words/entry) |
55e303ae A |
698 | ori r28,r28,lo16(EXT(mach_trap_table)) ; Get address of table |
699 | add r28,r27,r28 ; Point right to the syscall table entry | |
700 | lwz r27,MACH_TRAP_FUNCTION(r28) ; Pick up the function address | |
701 | lis r28,hi16(EXT(kern_invalid)) ; Get high half of invalid syscall function | |
702 | ori r28,r28,lo16(EXT(kern_invalid)) ; Get low half of invalid syscall function | |
703 | cmpw cr0,r27,r28 ; Check if this is an invalid system call | |
704 | beq-- .L_call_server_syscall_exception ; We have a bad system call | |
705 | b .L_mach_invalid_arg ; a system call returned KERN_INVALID_ARG | |
706 | ||
707 | ||
1c79356b A |
708 | /* thread_exception_return returns to here, almost all |
709 | * registers intact. It expects a full context restore | |
710 | * of what it hasn't restored itself (ie. what we use). | |
711 | * | |
712 | * In particular for us, | |
713 | * we still have r31 points to the current thread, | |
714 | * r30 points to the current pcb | |
715 | */ | |
716 | ||
9bccf70c A |
717 | .align 5 |
718 | ||
1c79356b A |
719 | .L_syscall_no_ast: |
720 | .L_thread_syscall_return: | |
721 | ||
9bccf70c | 722 | mr r3,r30 ; Get savearea to the correct register for common exit |
de355530 A |
723 | |
724 | lwz r11,SAVflags(r30) ; Get the flags | |
725 | lwz r5,THREAD_KERNEL_STACK(r31) ; Get the base pointer to the stack | |
55e303ae | 726 | lwz r4,SAVprev+4(r30) ; Get the previous save area |
de355530 | 727 | rlwinm r11,r11,0,15,13 ; Clear the syscall flag |
55e303ae | 728 | mfsprg r8,1 ; Now find the current activation |
9bccf70c | 729 | addi r5,r5,KERNEL_STACK_SIZE-FM_SIZE ; Reset to empty |
55e303ae | 730 | stw r11,SAVflags(r30) ; Stick back the flags |
9bccf70c | 731 | stw r5,ACT_MACT_KSP(r8) ; Save the empty stack pointer |
55e303ae | 732 | stw r4,ACT_MACT_PCB(r8) ; Save previous save area |
9bccf70c | 733 | b chkfac ; Go end it all... |
1c79356b | 734 | |
1c79356b A |
735 | /* |
736 | * thread_exception_return() | |
737 | * | |
738 | * Return to user mode directly from within a system call. | |
739 | */ | |
740 | ||
0b4e3aa0 A |
741 | .align 5 |
742 | .globl EXT(thread_bootstrap_return) | |
743 | LEXT(thread_bootstrap_return) ; NOTE: THIS IS GOING AWAY IN A FEW DAYS.... | |
744 | ||
745 | .globl EXT(thread_exception_return) | |
746 | LEXT(thread_exception_return) ; Directly return to user mode | |
1c79356b A |
747 | |
748 | .L_thread_exc_ret_check_ast: | |
55e303ae | 749 | lis r10,hi16(MASK(MSR_VEC)) ; Get the vector enable |
9bccf70c | 750 | mfmsr r3 ; Get the MSR |
55e303ae A |
751 | ori r10,r10,lo16(MASK(MSR_FP)|MASK(MSR_EE)) ; Add in FP and EE |
752 | andc r3,r3,r10 ; Turn off VEC, FP, and EE | |
9bccf70c | 753 | mtmsr r3 ; Disable interrupts |
1c79356b A |
754 | |
755 | /* Check to see if there's an outstanding AST */ | |
756 | /* We don't bother establishing a call frame even though CHECK_AST | |
757 | can invoke ast_taken(), because it can just borrow our caller's | |
758 | frame, given that we're not going to return. | |
759 | */ | |
760 | ||
91447636 A |
761 | mfsprg r10,1 ; Get the current activation |
762 | lwz r10,ACT_PER_PROC(r10) ; Get the per_proc block | |
763 | lwz r4,PP_PENDING_AST(r10) | |
1c79356b | 764 | cmpi cr0,r4, 0 |
55e303ae | 765 | beq+ cr0,.L_exc_ret_no_ast |
1c79356b | 766 | |
9bccf70c A |
767 | /* Yes there is, call ast_taken |
768 | * pretending that the user thread took an AST exception here, | |
769 | * ast_taken will save all state and bring us back here | |
770 | */ | |
de355530 | 771 | |
91447636 | 772 | lis r3,hi16(AST_ALL) |
de355530 | 773 | li r4,1 |
91447636 | 774 | ori r3,r3,lo16(AST_ALL) |
1c79356b A |
775 | |
776 | bl EXT(ast_taken) | |
9bccf70c | 777 | b .L_thread_exc_ret_check_ast ; check for a second AST (rare) |
1c79356b A |
778 | |
779 | /* arriving here, interrupts should be disabled */ | |
780 | /* Get the active thread's PCB pointer to restore regs | |
781 | */ | |
782 | .L_exc_ret_no_ast: | |
783 | ||
9bccf70c | 784 | mfsprg r30,1 ; Get the currrent activation |
91447636 | 785 | mr r31,r30 |
9bccf70c | 786 | |
1c79356b | 787 | lwz r30,ACT_MACT_PCB(r30) |
9bccf70c A |
788 | mr. r30,r30 ; Is there any context yet? |
789 | beq- makeDummyCtx ; No, hack one up... | |
1c79356b A |
790 | #if DEBUG |
791 | /* | |
792 | * debug assert - make sure that we're not returning to kernel | |
793 | * get the active thread's PCB pointer and thus pointer to user state | |
794 | */ | |
795 | ||
55e303ae | 796 | lwz r3,savesrr1+4(r30) |
1c79356b | 797 | andi. r3,r3,MASK(MSR_PR) |
9bccf70c | 798 | bne+ ret_user2 ; We are ok... |
1c79356b | 799 | |
9bccf70c A |
800 | lis r0,hi16(Choke) ; Choke code |
801 | ori r0,r0,lo16(Choke) ; and the rest | |
802 | li r3,failContext ; Bad state code | |
803 | sc ; System ABEND | |
0b4e3aa0 | 804 | |
1c79356b A |
805 | ret_user2: |
806 | #endif /* DEBUG */ | |
807 | ||
9bccf70c | 808 | /* If the system call flag isn't set, then we came from a trap, |
1c79356b A |
809 | * so warp into the return_from_trap (thread_return) routine, |
810 | * which takes PCB pointer in R3, not in r30! | |
811 | */ | |
9bccf70c | 812 | lwz r0,SAVflags(r30) ; Grab the savearea flags |
de355530 | 813 | andis. r0,r0,SAVsyscall>>16 ; Are we returning from a syscall? |
55e303ae A |
814 | mr r3,r30 ; Copy pcb pointer into r3 in case we need it |
815 | beq-- cr0,thread_return ; Nope, must be a thread return... | |
9bccf70c | 816 | b .L_thread_syscall_return ; Join up with the system call return... |
1c79356b A |
817 | |
818 | ; | |
819 | ; This is where we handle someone trying who did a thread_create followed | |
820 | ; by a thread_resume with no intervening thread_set_state. Just make an | |
821 | ; empty context, initialize it to trash and let em execute at 0... | |
9bccf70c A |
822 | ; |
823 | ||
824 | .align 5 | |
1c79356b A |
825 | |
826 | makeDummyCtx: | |
9bccf70c A |
827 | bl EXT(save_get) ; Get a save_area |
828 | li r4,SAVgeneral ; Get the general context type | |
829 | li r0,0 ; Get a 0 | |
830 | stb r4,SAVflags+2(r3) ; Set type | |
55e303ae | 831 | addi r2,r3,savefpscr+4 ; Point past what we are clearing |
9bccf70c | 832 | mr r4,r3 ; Save the start |
1c79356b | 833 | |
9bccf70c A |
834 | cleardummy: stw r0,0(r4) ; Clear stuff |
835 | addi r4,r4,4 ; Next word | |
836 | cmplw r4,r2 ; Still some more? | |
837 | blt+ cleardummy ; Yeah... | |
1c79356b A |
838 | |
839 | lis r2,hi16(MSR_EXPORT_MASK_SET) ; Set the high part of the user MSR | |
840 | ori r2,r2,lo16(MSR_EXPORT_MASK_SET) ; And the low part | |
55e303ae | 841 | stw r2,savesrr1+4(r3) ; Set the default user MSR |
1c79356b | 842 | |
9bccf70c | 843 | b thread_return ; Go let em try to execute, hah! |
1c79356b A |
844 | |
845 | /* | |
846 | * ihandler(type) | |
847 | * | |
848 | * ENTRY: VM switched ON | |
849 | * Interrupts OFF | |
850 | * R3 contains exception code | |
851 | * R4 points to the saved context (virtual address) | |
852 | * Everything is saved in savearea | |
853 | * | |
854 | */ | |
855 | ||
0b4e3aa0 A |
856 | .align 5 |
857 | .globl EXT(ihandler) | |
9bccf70c | 858 | LEXT(ihandler) ; Interrupt handler */ |
1c79356b A |
859 | |
860 | /* | |
861 | * get the value of istackptr, if it's zero then we're already on the | |
9bccf70c | 862 | * interrupt stack. |
1c79356b A |
863 | */ |
864 | ||
55e303ae | 865 | lwz r10,savesrr1+4(r4) ; Get SRR1 |
9bccf70c | 866 | lwz r7,savevrsave(r4) ; Get the VRSAVE register |
91447636 A |
867 | mfsprg r13,1 ; Get the current activation |
868 | lwz r25,ACT_PER_PROC(r13) ; Get the per_proc block | |
9bccf70c | 869 | li r14,0 ; Zero this for now |
91447636 | 870 | rlwinm. r16,r10,0,MSR_VEC_BIT,MSR_VEC_BIT ; Was vector on? |
9bccf70c | 871 | lwz r1,PP_ISTACKPTR(r25) ; Get the interrupt stack |
55e303ae | 872 | li r16,0 ; Zero this for now |
9bccf70c A |
873 | |
874 | beq+ ivecoff ; Vector off, do not save vrsave... | |
875 | stw r7,liveVRS(r25) ; Set the live value | |
876 | ||
de355530 | 877 | ivecoff: li r0,0 ; Get a constant 0 |
55e303ae A |
878 | rlwinm r5,r10,0,MSR_PR_BIT,MSR_PR_BIT ; Are we trapping from supervisor state? |
879 | mr. r1,r1 ; Is it active? | |
880 | cmplwi cr2,r5,0 ; cr2_eq == 1 if yes | |
91447636 | 881 | mr r16,r13 |
9bccf70c | 882 | lwz r14,ACT_MACT_PCB(r13) ; Now point to the PCB |
55e303ae A |
883 | lwz r9,saver1+4(r4) ; Pick up the rupt time stack |
884 | stw r14,SAVprev+4(r4) ; Queue the new save area in the front | |
9bccf70c | 885 | stw r13,SAVact(r4) ; Point the savearea at its activation |
9bccf70c | 886 | stw r4,ACT_MACT_PCB(r13) ; Point to our savearea |
55e303ae A |
887 | beq cr2,ifromk |
888 | stw r4,ACT_MACT_UPCB(r13) ; Store user savearea | |
9bccf70c | 889 | |
55e303ae | 890 | ifromk: bne .L_istackfree ; Nope... |
1c79356b A |
891 | |
892 | /* We're already on the interrupt stack, get back the old | |
893 | * stack pointer and make room for a frame | |
894 | */ | |
895 | ||
9bccf70c A |
896 | lwz r10,PP_INTSTACK_TOP_SS(r25) ; Get the top of the interrupt stack |
897 | addi r5,r9,INTSTACK_SIZE-FM_SIZE ; Shift stack for bounds check | |
898 | subi r1,r9,FM_REDZONE ; Back up beyond the red zone | |
899 | sub r5,r5,r10 ; Get displacement into stack | |
900 | cmplwi r5,INTSTACK_SIZE-FM_SIZE ; Is the stack actually invalid? | |
901 | blt+ ihsetback ; The stack is ok... | |
0b4e3aa0 | 902 | |
9bccf70c | 903 | lwz r5,PP_DEBSTACK_TOP_SS(r25) ; Pick up debug stack top |
0b4e3aa0 | 904 | subi r5,r5,KERNEL_STACK_SIZE-FM_SIZE ; Adjust to start of stack |
9bccf70c | 905 | sub r5,r1,r5 ; Get displacement into debug stack |
0b4e3aa0 | 906 | cmplwi cr2,r5,KERNEL_STACK_SIZE-FM_SIZE ; Check if we are on debug stack |
55e303ae | 907 | blt+ cr2,ihsetback ; Yeah, that is ok too... |
0b4e3aa0 | 908 | |
9bccf70c A |
909 | lis r0,hi16(Choke) ; Choke code |
910 | ori r0,r0,lo16(Choke) ; and the rest | |
911 | li r3,failStack ; Bad stack code | |
912 | sc ; System ABEND | |
0b4e3aa0 | 913 | |
55e303ae A |
914 | intUnalignedStk: |
915 | lis r0,hi16(Choke) ; Choke code | |
916 | ori r0,r0,lo16(Choke) ; and the rest | |
917 | li r3,failUnalignedStk ; Unaligned stack code | |
918 | sc ; System ABEND | |
919 | ||
0b4e3aa0 A |
920 | .align 5 |
921 | ||
1c79356b | 922 | .L_istackfree: |
55e303ae A |
923 | rlwinm. r0,r1,0,28,31 ; Check if stack is aligned (and get 0) |
924 | lwz r10,SAVflags(r4) ; Get savearea flags | |
925 | bne-- intUnalignedStk ; Stack is unaligned... | |
9bccf70c | 926 | stw r0,PP_ISTACKPTR(r25) ; Mark the stack in use |
55e303ae | 927 | oris r10,r10,hi16(SAVrststk) ; Indicate we reset stack when we return from this one |
9bccf70c | 928 | stw r10,SAVflags(r4) ; Stick it back |
1c79356b | 929 | |
9bccf70c A |
930 | /* |
931 | * To summarize, when we reach here, the state has been saved and | |
932 | * the stack is marked as busy. We now generate a small | |
933 | * stack frame with backpointers to follow the calling | |
934 | * conventions. We set up the backpointers to the trapped | |
935 | * routine allowing us to backtrace. | |
936 | */ | |
1c79356b | 937 | |
9bccf70c A |
938 | ihsetback: subi r1,r1,FM_SIZE ; Make a new frame |
939 | stw r9,FM_BACKPTR(r1) ; Point back to previous stackptr | |
1c79356b A |
940 | |
941 | #if VERIFYSAVE | |
9bccf70c A |
942 | beq- cr1,ihbootnover ; (TEST/DEBUG) |
943 | bl versave ; (TEST/DEBUG) | |
944 | ihbootnover: ; (TEST/DEBUG) | |
1c79356b A |
945 | #endif |
946 | ||
947 | #if DEBUG | |
948 | /* If debugging, we need two frames, the first being a dummy | |
949 | * which links back to the trapped routine. The second is | |
950 | * that which the C routine below will need | |
951 | */ | |
55e303ae | 952 | lwz r5,savesrr0+4(r4) ; Get interrupt address |
9bccf70c A |
953 | stw r5,FM_LR_SAVE(r1) ; save old instr ptr as LR value |
954 | stwu r1,-FM_SIZE(r1) ; Make another new frame for C routine | |
1c79356b A |
955 | #endif /* DEBUG */ |
956 | ||
91447636 A |
957 | mr r31,r3 |
958 | mr r30,r4 | |
959 | ||
960 | lwz r3,SAVtime+4(r4) | |
961 | addi r4,r13,SYSTEM_TIMER | |
962 | bl EXT(timer_event) | |
963 | ||
964 | mr r3,r31 | |
965 | mr r4,r30 | |
966 | lwz r5,savedsisr(r30) ; Get the DSISR | |
967 | lwz r6,savedar+4(r30) ; Get the DAR | |
3a60a9f5 | 968 | |
b36670ce A |
969 | #if FPFLOOD |
970 | stfd f31,emfp31(r25) ; (TEST/DEBUG) | |
971 | #endif | |
972 | ||
1c79356b A |
973 | bl EXT(interrupt) |
974 | ||
975 | ||
976 | /* interrupt() returns a pointer to the saved state in r3 | |
977 | * | |
978 | * Ok, back from C. Disable interrupts while we restore things | |
979 | */ | |
980 | .globl EXT(ihandler_ret) | |
981 | ||
9bccf70c | 982 | LEXT(ihandler_ret) ; Marks our return point from debugger entry |
1c79356b | 983 | |
55e303ae | 984 | lis r10,hi16(MASK(MSR_VEC)) ; Get the vector enable |
9bccf70c | 985 | mfmsr r0 ; Get our MSR |
55e303ae A |
986 | ori r10,r10,lo16(MASK(MSR_FP)|MASK(MSR_EE)) ; Add in FP and EE |
987 | andc r0,r0,r10 ; Turn off VEC, FP, and EE | |
9bccf70c | 988 | mtmsr r0 ; Make sure interrupts are disabled |
91447636 A |
989 | mfsprg r8,1 ; Get the current activation |
990 | lwz r10,ACT_PER_PROC(r8) ; Get the per_proc block | |
1c79356b | 991 | |
9bccf70c | 992 | lwz r7,SAVflags(r3) ; Pick up the flags |
3a60a9f5 | 993 | lwz r9,SAVprev+4(r3) ; Get previous save area |
9bccf70c | 994 | cmplwi cr1,r8,0 ; Are we still initializing? |
55e303ae | 995 | lwz r12,savesrr1+4(r3) ; Get the MSR we will load on return |
55e303ae | 996 | andis. r11,r7,hi16(SAVrststk) ; Is this the first on the stack? |
9bccf70c | 997 | stw r9,ACT_MACT_PCB(r8) ; Point to previous context savearea |
55e303ae | 998 | mr r4,r3 ; Move the savearea pointer |
9bccf70c | 999 | beq .L_no_int_ast2 ; Get going if not the top-o-stack... |
1c79356b A |
1000 | |
1001 | ||
1002 | /* We're the last frame on the stack. Restore istackptr to empty state. | |
1003 | * | |
1004 | * Check for ASTs if one of the below is true: | |
1005 | * returning to user mode | |
1006 | * returning to a kloaded server | |
1007 | */ | |
9bccf70c A |
1008 | lwz r9,PP_INTSTACK_TOP_SS(r10) ; Get the empty stack value |
1009 | andc r7,r7,r11 ; Remove the stack reset bit in case we pass this one | |
1010 | stw r9,PP_ISTACKPTR(r10) ; Save that saved state ptr | |
55e303ae | 1011 | lwz r3,ACT_PREEMPT_CNT(r8) ; Get preemption level |
9bccf70c A |
1012 | stw r7,SAVflags(r4) ; Save the flags |
1013 | cmplwi r3, 0 ; Check for preemption | |
1014 | bne .L_no_int_ast ; Do not preempt if level is not zero | |
1015 | andi. r6,r12,MASK(MSR_PR) ; privilege mode | |
91447636 | 1016 | lwz r11,PP_PENDING_AST(r10) ; Get the pending AST mask |
9bccf70c A |
1017 | beq- .L_kernel_int_ast ; In kernel space, AST_URGENT check |
1018 | li r3,T_AST ; Assume the worst | |
1019 | mr. r11,r11 ; Are there any pending? | |
1020 | beq .L_no_int_ast ; Nope... | |
1c79356b A |
1021 | b .L_call_thandler |
1022 | ||
1023 | .L_kernel_int_ast: | |
9bccf70c A |
1024 | andi. r11,r11,AST_URGENT ; Do we have AST_URGENT? |
1025 | li r3,T_PREEMPT ; Assume the worst | |
1026 | beq .L_no_int_ast ; Nope... | |
1c79356b A |
1027 | |
1028 | /* | |
1029 | * There is a pending AST. Massage things to make it look like | |
1030 | * we took a trap and jump into the trap handler. To do this | |
1031 | * we essentially pretend to return from the interrupt but | |
1032 | * at the last minute jump into the trap handler with an AST | |
1033 | * trap instead of performing an rfi. | |
1034 | */ | |
1035 | ||
9bccf70c A |
1036 | .L_call_thandler: |
1037 | stw r3,saveexception(r4) ; Set the exception code to T_AST/T_PREEMPT | |
1038 | b EXT(thandler) ; We need to preempt so treat like a trap... | |
1c79356b A |
1039 | |
1040 | .L_no_int_ast: | |
9bccf70c A |
1041 | mr r3,r4 ; Get into the right register for common code |
1042 | ||
1c79356b | 1043 | .L_no_int_ast2: |
9bccf70c A |
1044 | rlwinm r7,r7,0,15,13 ; Clear the syscall flag |
1045 | li r4,0 ; Assume for a moment that we are in init | |
1046 | stw r7,SAVflags(r3) ; Set the flags with cleared syscall flag | |
55e303ae | 1047 | beq-- cr1,chkfac ; Jump away if we are in init... |
9bccf70c A |
1048 | |
1049 | lwz r4,ACT_MACT_PCB(r8) ; Get the new level marker | |
1c79356b A |
1050 | |
1051 | ||
1052 | ; | |
1053 | ; This section is common to all exception exits. It throws away vector | |
1054 | ; and floating point saveareas as the exception level of a thread is | |
1055 | ; exited. | |
1056 | ; | |
1057 | ; It also enables the facility if its context is live | |
1058 | ; Requires: | |
1059 | ; R3 = Savearea to be released (virtual) | |
1060 | ; R4 = New top of savearea stack (could be 0) | |
1061 | ; R8 = pointer to activation | |
1062 | ; R10 = per_proc block | |
1063 | ; | |
9bccf70c A |
1064 | ; Note that barring unforseen crashes, there is no escape from this point |
1065 | ; on. We WILL call exception_exit and launch this context. No worries | |
1066 | ; about preemption or interruptions here. | |
1067 | ; | |
1068 | ; Note that we will set up R26 with whatever context we will be launching, | |
1069 | ; so it will indicate the current, or the deferred it it is set and we | |
1070 | ; are going to user state. CR2_eq will be set to indicate deferred. | |
1071 | ; | |
1c79356b | 1072 | |
55e303ae | 1073 | chkfac: lwz r29,savesrr1+4(r3) ; Get the current MSR |
de355530 | 1074 | mr. r28,r8 ; Are we still in boot? |
55e303ae A |
1075 | mr r31,r10 ; Move per_proc address |
1076 | mr r30,r4 ; Preserve new level | |
9bccf70c | 1077 | mr r27,r3 ; Save the old level |
55e303ae | 1078 | beq-- chkenax ; Yeah, skip it all... |
1c79356b | 1079 | |
9bccf70c A |
1080 | rlwinm. r0,r29,0,MSR_PR_BIT,MSR_PR_BIT ; Are we going into user state? |
1081 | ||
9bccf70c A |
1082 | lwz r20,curctx(r28) ; Get our current context |
1083 | lwz r26,deferctx(r28) ; Get any deferred context switch | |
55e303ae | 1084 | li r0,1 ; Get set to hold off quickfret |
9bccf70c A |
1085 | rlwinm r29,r29,0,MSR_FP_BIT+1,MSR_FP_BIT-1 ; Turn off floating point for now |
1086 | lwz r21,FPUlevel(r20) ; Get the facility level | |
1087 | cmplwi cr2,r26,0 ; Are we going into a deferred context later? | |
1088 | rlwinm r29,r29,0,MSR_VEC_BIT+1,MSR_VEC_BIT-1 ; Turn off vector for now | |
1089 | crnor cr2_eq,cr0_eq,cr2_eq ; Set cr2_eq if going to user state and there is deferred | |
de355530 | 1090 | lhz r19,PP_CPU_NUMBER(r31) ; Get our CPU number |
55e303ae A |
1091 | cmplw r27,r21 ; Are we returning from the active level? |
1092 | stw r0,holdQFret(r31) ; Make sure we hold off releasing quickfret | |
1093 | bne++ fpuchkena ; Nope... | |
1c79356b | 1094 | |
9bccf70c A |
1095 | ; |
1096 | ; First clean up any live context we are returning from | |
1097 | ; | |
1098 | ||
1099 | lwz r22,FPUcpu(r20) ; Get CPU this context was last dispatched on | |
1100 | ||
1101 | stw r19,FPUcpu(r20) ; Claim context for us | |
1102 | ||
1103 | eieio ; Make sure this gets out before owner clear | |
1104 | ||
91447636 A |
1105 | #if ppeSize != 16 |
1106 | #error per_proc_entry is not 16bytes in size | |
55e303ae A |
1107 | #endif |
1108 | ||
91447636 A |
1109 | lis r23,hi16(EXT(PerProcTable)) ; Set base PerProcTable |
1110 | slwi r22,r22,4 ; Find offset to the owner per_proc_entry | |
1111 | ori r23,r23,lo16(EXT(PerProcTable)) ; Set base PerProcTable | |
1112 | li r24,FPUowner ; Displacement to float owner | |
1113 | add r22,r23,r22 ; Point to the owner per_proc_entry | |
1114 | lwz r22,ppe_vaddr(r22) ; Point to the owner per_proc | |
0b4e3aa0 | 1115 | |
9bccf70c | 1116 | fpuinvothr: lwarx r23,r24,r22 ; Get the owner |
55e303ae A |
1117 | |
1118 | sub r0,r23,r20 ; Subtract one from the other | |
1119 | sub r21,r20,r23 ; Subtract the other from the one | |
1120 | or r21,r21,r0 ; Combine them | |
1121 | srawi r21,r21,31 ; Get a 0 if equal or -1 of not | |
1122 | and r23,r23,r21 ; Make 0 if same, unchanged if not | |
1123 | stwcx. r23,r24,r22 ; Try to invalidate it | |
1124 | bne-- fpuinvothr ; Try again if there was a collision... | |
1125 | ||
1126 | isync | |
0b4e3aa0 | 1127 | |
9bccf70c A |
1128 | ; |
1129 | ; Now if there is a savearea associated with the popped context, release it. | |
1130 | ; Either way, pop the level to the top stacked context. | |
1131 | ; | |
0b4e3aa0 | 1132 | |
9bccf70c A |
1133 | lwz r22,FPUsave(r20) ; Get pointer to the first savearea |
1134 | li r21,0 ; Assume we popped all the way out | |
1135 | mr. r22,r22 ; Is there anything there? | |
55e303ae | 1136 | beq++ fpusetlvl ; No, see if we need to enable... |
9bccf70c A |
1137 | |
1138 | lwz r21,SAVlevel(r22) ; Get the level of that savearea | |
1139 | cmplw r21,r27 ; Is this the saved copy of the live stuff? | |
1140 | bne fpusetlvl ; No, leave as is... | |
1141 | ||
55e303ae | 1142 | lwz r24,SAVprev+4(r22) ; Pick up the previous area |
9bccf70c A |
1143 | li r21,0 ; Assume we popped all the way out |
1144 | mr. r24,r24 ; Any more context stacked? | |
55e303ae | 1145 | beq-- fpuonlyone ; Nope... |
9bccf70c A |
1146 | lwz r21,SAVlevel(r24) ; Get the level associated with save |
1147 | ||
1148 | fpuonlyone: stw r24,FPUsave(r20) ; Dequeue this savearea | |
1149 | ||
1150 | rlwinm r3,r22,0,0,19 ; Find main savearea header | |
55e303ae A |
1151 | |
1152 | lwz r8,quickfret(r31) ; Get the first in quickfret list (top) | |
1153 | lwz r9,quickfret+4(r31) ; Get the first in quickfret list (bottom) | |
1154 | lwz r2,SACvrswap(r3) ; Get the virtual to real conversion (top) | |
1155 | lwz r3,SACvrswap+4(r3) ; Get the virtual to real conversion (bottom) | |
1156 | stw r8,SAVprev(r22) ; Link the old in (top) | |
1157 | stw r9,SAVprev+4(r22) ; Link the old in (bottom) | |
9bccf70c | 1158 | xor r3,r22,r3 ; Convert to physical |
55e303ae A |
1159 | stw r2,quickfret(r31) ; Set the first in quickfret list (top) |
1160 | stw r3,quickfret+4(r31) ; Set the first in quickfret list (bottom) | |
9bccf70c A |
1161 | |
1162 | #if FPVECDBG | |
1163 | lis r0,HIGH_ADDR(CutTrace) ; (TEST/DEBUG) | |
1164 | li r2,0x3301 ; (TEST/DEBUG) | |
1165 | oris r0,r0,LOW_ADDR(CutTrace) ; (TEST/DEBUG) | |
1166 | sc ; (TEST/DEBUG) | |
1167 | #endif | |
1168 | ||
9bccf70c A |
1169 | fpusetlvl: stw r21,FPUlevel(r20) ; Save the level |
1170 | ||
1c79356b | 1171 | ; |
9bccf70c A |
1172 | ; Here we check if we are at the right level |
1173 | ; We need to check the level we are entering, not the one we are exiting. | |
1174 | ; Therefore, we will use the defer level if it is non-zero and we are | |
1175 | ; going into user state. | |
1c79356b | 1176 | ; |
0b4e3aa0 | 1177 | |
55e303ae | 1178 | fpuchkena: bt-- cr2_eq,fpuhasdfrd ; Skip if deferred, R26 already set up... |
9bccf70c A |
1179 | mr r26,r20 ; Use the non-deferred value |
1180 | ||
55e303ae A |
1181 | fpuhasdfrd: |
1182 | #if 0 | |
1183 | rlwinm. r0,r29,0,MSR_PR_BIT,MSR_PR_BIT ; (TEST/DEBUG) Going into user state? | |
1184 | beq fpunusrstt ; (TEST/DEBUG) Nope... | |
1185 | lwz r23,FPUlevel(r26) ; (TEST/DEBUG) Get the level ID | |
1186 | lwz r24,FPUsave(r26) ; (TEST/DEBUG) Get the first savearea | |
1187 | mr. r23,r23 ; (TEST/DEBUG) Should be level 0 | |
1188 | beq++ fpulvl0 ; (TEST/DEBUG) Yes... | |
b36670ce A |
1189 | |
1190 | lis r0,hi16(Choke) ; (TEST/DEBUG) Choke code | |
1191 | ori r0,r0,lo16(Choke) ; (TEST/DEBUG) and the rest | |
1192 | sc ; (TEST/DEBUG) System ABEND | |
55e303ae A |
1193 | |
1194 | fpulvl0: mr. r24,r24 ; (TEST/DEBUG) Any context? | |
1195 | beq fpunusrstt ; (TEST/DEBUG) No... | |
1196 | lwz r23,SAVlevel(r24) ; (TEST/DEBUG) Get level of context | |
1197 | lwz r21,SAVprev+4(r24) ; (TEST/DEBUG) Get previous pointer | |
1198 | mr. r23,r23 ; (TEST/DEBUG) Is this our user context? | |
1199 | beq++ fpulvl0b ; (TEST/DEBUG) Yes... | |
b36670ce A |
1200 | |
1201 | lis r0,hi16(Choke) ; (TEST/DEBUG) Choke code | |
1202 | ori r0,r0,lo16(Choke) ; (TEST/DEBUG) and the rest | |
1203 | sc ; (TEST/DEBUG) System ABEND | |
55e303ae A |
1204 | |
1205 | fpulvl0b: mr. r21,r21 ; (TEST/DEBUG) Is there a forward chain? | |
1206 | beq++ fpunusrstt ; (TEST/DEBUG) Nope... | |
b36670ce A |
1207 | |
1208 | lis r0,hi16(Choke) ; (TEST/DEBUG) Choke code | |
1209 | ori r0,r0,lo16(Choke) ; (TEST/DEBUG) and the rest | |
1210 | sc ; (TEST/DEBUG) System ABEND | |
55e303ae A |
1211 | |
1212 | fpunusrstt: ; (TEST/DEBUG) | |
1213 | #endif | |
1214 | ||
1215 | lwz r21,FPUowner(r31) ; Get the ID of the live context | |
9bccf70c | 1216 | lwz r23,FPUlevel(r26) ; Get the level ID |
de355530 | 1217 | lwz r24,FPUcpu(r26) ; Get the CPU that the context was last dispatched on |
55e303ae | 1218 | cmplw cr3,r26,r21 ; Do we have the live context? |
9bccf70c | 1219 | cmplw r30,r23 ; Are we about to launch the live level? |
55e303ae | 1220 | bne-- cr3,chkvec ; No, can not possibly enable... |
9bccf70c | 1221 | cmplw cr1,r19,r24 ; Was facility used on this processor last? |
55e303ae A |
1222 | bne-- chkvec ; No, not live... |
1223 | bne-- cr1,chkvec ; No, wrong cpu, have to enable later.... | |
9bccf70c A |
1224 | |
1225 | lwz r24,FPUsave(r26) ; Get the first savearea | |
1226 | mr. r24,r24 ; Any savearea? | |
55e303ae | 1227 | beq++ fpuena ; Nope... |
9bccf70c | 1228 | lwz r25,SAVlevel(r24) ; Get the level of savearea |
55e303ae | 1229 | lwz r0,SAVprev+4(r24) ; Get the previous |
b36670ce | 1230 | |
9bccf70c | 1231 | cmplw r30,r25 ; Is savearea for the level we are launching? |
55e303ae | 1232 | bne++ fpuena ; No, just go enable... |
9bccf70c A |
1233 | |
1234 | stw r0,FPUsave(r26) ; Pop the chain | |
1235 | ||
1236 | rlwinm r3,r24,0,0,19 ; Find main savearea header | |
55e303ae A |
1237 | |
1238 | lwz r8,quickfret(r31) ; Get the first in quickfret list (top) | |
1239 | lwz r9,quickfret+4(r31) ; Get the first in quickfret list (bottom) | |
1240 | lwz r2,SACvrswap(r3) ; Get the virtual to real conversion (top) | |
1241 | lwz r3,SACvrswap+4(r3) ; Get the virtual to real conversion (bottom) | |
1242 | stw r8,SAVprev(r24) ; Link the old in (top) | |
1243 | stw r9,SAVprev+4(r24) ; Link the old in (bottom) | |
9bccf70c | 1244 | xor r3,r24,r3 ; Convert to physical |
55e303ae A |
1245 | stw r2,quickfret(r31) ; Set the first in quickfret list (top) |
1246 | stw r3,quickfret+4(r31) ; Set the first in quickfret list (bottom) | |
1c79356b A |
1247 | |
1248 | #if FPVECDBG | |
9bccf70c A |
1249 | lis r0,HIGH_ADDR(CutTrace) ; (TEST/DEBUG) |
1250 | li r2,0x3302 ; (TEST/DEBUG) | |
1251 | oris r0,r0,LOW_ADDR(CutTrace) ; (TEST/DEBUG) | |
1252 | sc ; (TEST/DEBUG) | |
1253 | #endif | |
1c79356b | 1254 | |
9bccf70c | 1255 | fpuena: ori r29,r29,lo16(MASK(MSR_FP)) ; Enable facility |
1c79356b | 1256 | |
9bccf70c | 1257 | chkvec: |
1c79356b | 1258 | |
9bccf70c A |
1259 | lwz r21,VMXlevel(r20) ; Get the facility level |
1260 | ||
1261 | cmplw r27,r21 ; Are we returning from the active level? | |
1262 | bne+ vmxchkena ; Nope... | |
1263 | ||
1264 | ||
1265 | ; | |
1266 | ; First clean up any live context we are returning from | |
1267 | ; | |
1c79356b | 1268 | |
9bccf70c A |
1269 | lwz r22,VMXcpu(r20) ; Get CPU this context was last dispatched on |
1270 | ||
1271 | stw r19,VMXcpu(r20) ; Claim context for us | |
1272 | ||
1273 | eieio ; Make sure this gets out before owner clear | |
1274 | ||
91447636 A |
1275 | lis r23,hi16(EXT(PerProcTable)) ; Set base PerProcTable |
1276 | slwi r22,r22,4 ; Find offset to the owner per_proc_entry | |
1277 | ori r23,r23,lo16(EXT(PerProcTable)) ; Set base PerProcTable | |
1278 | li r24,VMXowner ; Displacement to float owner | |
1279 | add r22,r23,r22 ; Point to the owner per_proc_entry | |
1280 | lwz r22,ppe_vaddr(r22) ; Point to the owner per_proc | |
9bccf70c A |
1281 | |
1282 | vmxinvothr: lwarx r23,r24,r22 ; Get the owner | |
55e303ae A |
1283 | |
1284 | sub r0,r23,r20 ; Subtract one from the other | |
1285 | sub r21,r20,r23 ; Subtract the other from the one | |
1286 | or r21,r21,r0 ; Combine them | |
1287 | srawi r21,r21,31 ; Get a 0 if equal or -1 of not | |
1288 | and r23,r23,r21 ; Make 0 if same, unchanged if not | |
1289 | stwcx. r23,r24,r22 ; Try to invalidate it | |
1290 | bne-- vmxinvothr ; Try again if there was a collision... | |
1291 | ||
1292 | isync | |
0b4e3aa0 | 1293 | |
9bccf70c A |
1294 | ; |
1295 | ; Now if there is a savearea associated with the popped context, release it. | |
1296 | ; Either way, pop the level to the top stacked context. | |
1297 | ; | |
1298 | ||
1299 | lwz r22,VMXsave(r20) ; Get pointer to the first savearea | |
1300 | li r21,0 ; Assume we popped all the way out | |
1301 | mr. r22,r22 ; Is there anything there? | |
55e303ae | 1302 | beq++ vmxsetlvl ; No, see if we need to enable... |
9bccf70c A |
1303 | |
1304 | lwz r21,SAVlevel(r22) ; Get the level of that savearea | |
1305 | cmplw r21,r27 ; Is this the saved copy of the live stuff? | |
1306 | bne vmxsetlvl ; No, leave as is... | |
1307 | ||
55e303ae | 1308 | lwz r24,SAVprev+4(r22) ; Pick up the previous area |
9bccf70c A |
1309 | li r21,0 ; Assume we popped all the way out |
1310 | mr. r24,r24 ; Any more context? | |
55e303ae | 1311 | beq-- vmxonlyone ; Nope... |
9bccf70c A |
1312 | lwz r21,SAVlevel(r24) ; Get the level associated with save |
1313 | ||
1314 | vmxonlyone: stw r24,VMXsave(r20) ; Dequeue this savearea | |
1315 | ||
1316 | rlwinm r3,r22,0,0,19 ; Find main savearea header | |
55e303ae A |
1317 | |
1318 | lwz r8,quickfret(r31) ; Get the first in quickfret list (top) | |
1319 | lwz r9,quickfret+4(r31) ; Get the first in quickfret list (bottom) | |
1320 | lwz r2,SACvrswap(r3) ; Get the virtual to real conversion (top) | |
1321 | lwz r3,SACvrswap+4(r3) ; Get the virtual to real conversion (bottom) | |
1322 | stw r8,SAVprev(r22) ; Link the old in (top) | |
1323 | stw r9,SAVprev+4(r22) ; Link the old in (bottom) | |
ab86ba33 | 1324 | xor r3,r22,r3 ; Convert to physical |
55e303ae A |
1325 | stw r2,quickfret(r31) ; Set the first in quickfret list (top) |
1326 | stw r3,quickfret+4(r31) ; Set the first in quickfret list (bottom) | |
9bccf70c A |
1327 | |
1328 | #if FPVECDBG | |
1329 | lis r0,HIGH_ADDR(CutTrace) ; (TEST/DEBUG) | |
1330 | li r2,0x3401 ; (TEST/DEBUG) | |
1331 | oris r0,r0,LOW_ADDR(CutTrace) ; (TEST/DEBUG) | |
1332 | sc ; (TEST/DEBUG) | |
1333 | #endif | |
9bccf70c A |
1334 | |
1335 | vmxsetlvl: stw r21,VMXlevel(r20) ; Save the level | |
0b4e3aa0 | 1336 | |
9bccf70c A |
1337 | ; |
1338 | ; Here we check if we are at the right level | |
1339 | ; | |
1340 | ||
1341 | vmxchkena: lwz r21,VMXowner(r31) ; Get the ID of the live context | |
1342 | lwz r23,VMXlevel(r26) ; Get the level ID | |
1343 | cmplw r26,r21 ; Do we have the live context? | |
1344 | lwz r24,VMXcpu(r26) ; Get the CPU that the context was last dispatched on | |
55e303ae | 1345 | bne-- setena ; No, can not possibly enable... |
9bccf70c A |
1346 | cmplw r30,r23 ; Are we about to launch the live level? |
1347 | cmplw cr1,r19,r24 ; Was facility used on this processor last? | |
55e303ae A |
1348 | bne-- setena ; No, not live... |
1349 | bne-- cr1,setena ; No, wrong cpu, have to enable later.... | |
9bccf70c A |
1350 | |
1351 | lwz r24,VMXsave(r26) ; Get the first savearea | |
1352 | mr. r24,r24 ; Any savearea? | |
55e303ae | 1353 | beq++ vmxena ; Nope... |
9bccf70c | 1354 | lwz r25,SAVlevel(r24) ; Get the level of savearea |
55e303ae | 1355 | lwz r0,SAVprev+4(r24) ; Get the previous |
9bccf70c | 1356 | cmplw r30,r25 ; Is savearea for the level we are launching? |
55e303ae | 1357 | bne++ vmxena ; No, just go enable... |
9bccf70c A |
1358 | |
1359 | stw r0,VMXsave(r26) ; Pop the chain | |
1360 | ||
1361 | rlwinm r3,r24,0,0,19 ; Find main savearea header | |
55e303ae A |
1362 | |
1363 | lwz r8,quickfret(r31) ; Get the first in quickfret list (top) | |
1364 | lwz r9,quickfret+4(r31) ; Get the first in quickfret list (bottom) | |
1365 | lwz r2,SACvrswap(r3) ; Get the virtual to real conversion (top) | |
1366 | lwz r3,SACvrswap+4(r3) ; Get the virtual to real conversion (bottom) | |
1367 | stw r8,SAVprev(r24) ; Link the old in (top) | |
1368 | stw r9,SAVprev+4(r24) ; Link the old in (bottom) | |
9bccf70c | 1369 | xor r3,r24,r3 ; Convert to physical |
55e303ae A |
1370 | stw r2,quickfret(r31) ; Set the first in quickfret list (top) |
1371 | stw r3,quickfret+4(r31) ; Set the first in quickfret list (bottom) | |
9bccf70c A |
1372 | |
1373 | #if FPVECDBG | |
1374 | lis r0,HIGH_ADDR(CutTrace) ; (TEST/DEBUG) | |
1375 | li r2,0x3402 ; (TEST/DEBUG) | |
1376 | oris r0,r0,LOW_ADDR(CutTrace) ; (TEST/DEBUG) | |
1377 | sc ; (TEST/DEBUG) | |
1378 | #endif | |
1379 | ||
9bccf70c | 1380 | vmxena: oris r29,r29,hi16(MASK(MSR_VEC)) ; Enable facility |
0b4e3aa0 | 1381 | |
91447636 | 1382 | setena: lwz r18,umwSpace(r28) ; Get the space ID in case we are launching user |
55e303ae A |
1383 | rlwinm. r0,r29,0,MSR_PR_BIT,MSR_PR_BIT ; Are we about to launch user state? |
1384 | li r0,0 ; Get set to release quickfret holdoff | |
9bccf70c | 1385 | crmove cr7_eq,cr0_eq ; Remember if we are going to user state |
de355530 | 1386 | rlwimi. r20,r29,(((31-floatCngbit)+(MSR_FP_BIT+1))&31),floatCngbit,floatCngbit ; Set flag if we enabled floats |
55e303ae A |
1387 | lwz r19,deferctx(r28) ; Get any deferred facility context switch |
1388 | rlwinm r20,r29,(((31-vectorCngbit)+(MSR_VEC_BIT+1))&31),vectorCngbit,vectorCngbit ; Set flag if we enabled vector | |
1389 | stw r29,savesrr1+4(r27) ; Turn facility on or off | |
1390 | stw r0,holdQFret(r31) ; Release quickfret | |
91447636 | 1391 | oris r18,r18,hi16(umwSwitchAway) ; Set the switch-away bit in case we go to user |
55e303ae | 1392 | |
9bccf70c A |
1393 | beq setenaa ; Neither float nor vector turned on.... |
1394 | ||
1395 | lwz r5,ACT_MACT_SPF(r28) ; Get activation copy | |
1396 | lwz r6,spcFlags(r31) ; Get per_proc copy | |
1397 | or r5,r5,r20 ; Set vector/float changed bits in activation | |
1398 | or r6,r6,r20 ; Set vector/float changed bits in per_proc | |
1399 | stw r5,ACT_MACT_SPF(r28) ; Set activation copy | |
1400 | stw r6,spcFlags(r31) ; Set per_proc copy | |
1401 | ||
1402 | setenaa: mfdec r24 ; Get decrementer | |
1403 | bf+ cr2_eq,nodefer ; No deferred to switch to... | |
1404 | ||
1405 | li r20,0 ; Clear this | |
1406 | stw r26,curctx(r28) ; Make the facility context current | |
1407 | stw r20,deferctx(r28) ; Clear deferred context | |
1408 | ||
1409 | nodefer: lwz r22,qactTimer(r28) ; Get high order quick activation timer | |
1410 | mr. r24,r24 ; See if it has popped already... | |
1411 | lwz r23,qactTimer+4(r28) ; Get low order qact timer | |
55e303ae | 1412 | ble- chkifuser ; We have popped or are just about to... |
9bccf70c A |
1413 | |
1414 | segtb: mftbu r20 ; Get the upper time base | |
1415 | mftb r21 ; Get the low | |
1416 | mftbu r19 ; Get upper again | |
1417 | or. r0,r22,r23 ; Any time set? | |
1418 | cmplw cr1,r20,r19 ; Did they change? | |
55e303ae A |
1419 | beq++ chkifuser ; No time set.... |
1420 | bne-- cr1,segtb ; Timebase ticked, get them again... | |
9bccf70c A |
1421 | |
1422 | subfc r6,r21,r23 ; Subtract current from qact time | |
1423 | li r0,0 ; Make a 0 | |
1424 | subfe r5,r20,r22 ; Finish subtract | |
1425 | subfze r0,r0 ; Get a 0 if qact was bigger than current, -1 otherwise | |
1426 | andc. r12,r5,r0 ; Set 0 if qact has passed | |
1427 | andc r13,r6,r0 ; Set 0 if qact has passed | |
55e303ae | 1428 | bne chkifuser ; If high order is non-zero, this is too big for a decrementer |
9bccf70c | 1429 | cmplw r13,r24 ; Is this earlier than the decrementer? (logical compare takes care of high bit on) |
55e303ae | 1430 | bge++ chkifuser ; No, do not reset decrementer... |
1c79356b | 1431 | |
9bccf70c | 1432 | mtdec r13 ; Set our value |
1c79356b | 1433 | |
91447636 A |
1434 | chkifuser: addi r4,r28,SYSTEM_TIMER |
1435 | mftb r3 | |
1436 | beq-- cr7,chkifuser1 ; Skip this if we are going to kernel... | |
1437 | stw r18,umwSpace(r28) ; Half-invalidate to force MapUserAddressWindow to reload SRs | |
1438 | addi r4,r28,USER_TIMER | |
1439 | ||
1440 | chkifuser1: bl EXT(timer_event) | |
55e303ae | 1441 | |
9bccf70c | 1442 | chkenax: |
1c79356b | 1443 | |
1c79356b | 1444 | #if DEBUG |
9bccf70c | 1445 | lwz r20,SAVact(r27) ; (TEST/DEBUG) Make sure our restore |
55e303ae | 1446 | mfsprg r21, 1 ; (TEST/DEBUG) with the current act. |
9bccf70c | 1447 | cmpwi r21,0 ; (TEST/DEBUG) |
55e303ae | 1448 | beq-- yeswereok ; (TEST/DEBUG) |
9bccf70c | 1449 | cmplw r21,r20 ; (TEST/DEBUG) |
55e303ae | 1450 | beq++ yeswereok ; (TEST/DEBUG) |
9bccf70c A |
1451 | |
1452 | lis r0,hi16(Choke) ; (TEST/DEBUG) Choke code | |
1453 | ori r0,r0,lo16(Choke) ; (TEST/DEBUG) and the rest | |
1454 | mr r21,r27 ; (TEST/DEBUG) Save the savearea address | |
1455 | li r3,failContext ; (TEST/DEBUG) Bad state code | |
1456 | sc ; (TEST/DEBUG) System ABEND | |
1c79356b A |
1457 | |
1458 | yeswereok: | |
1459 | #endif | |
1460 | ||
55e303ae | 1461 | mr r3,r27 ; Pass savearea back |
9bccf70c | 1462 | b EXT(exception_exit) ; We are all done now... |
1c79356b A |
1463 | |
1464 | ||
1465 | ||
55e303ae A |
1466 | ; |
1467 | ; Null PPC call - performance testing, does absolutely nothing | |
1468 | ; | |
1469 | ||
1470 | .align 5 | |
1471 | ||
1472 | .globl EXT(ppcNull) | |
1473 | ||
1474 | LEXT(ppcNull) | |
1475 | ||
1476 | li r3,-1 ; Make sure we test no asts | |
1477 | blr | |
1478 | ||
1479 | ||
1480 | ; | |
1481 | ; Instrumented null PPC call - performance testing, does absolutely nothing | |
1482 | ; Forces various timestamps to be returned. | |
1483 | ; | |
1484 | ||
1485 | .align 5 | |
1486 | ||
1487 | .globl EXT(ppcNullinst) | |
1488 | ||
1489 | LEXT(ppcNullinst) | |
1490 | ||
1491 | li r3,-1 ; Make sure we test no asts | |
1492 | blr | |
1493 | ||
1494 | ||
1c79356b A |
1495 | /* |
1496 | * Here's where we handle the fastpath stuff | |
1497 | * We'll do what we can here because registers are already | |
1498 | * loaded and it will be less confusing that moving them around. | |
1499 | * If we need to though, we'll branch off somewhere's else. | |
1500 | * | |
1501 | * Registers when we get here: | |
1502 | * | |
1503 | * r0 = syscall number | |
1504 | * r4 = savearea/pcb | |
1505 | * r13 = activation | |
1506 | * r14 = previous savearea (if any) | |
1507 | * r16 = thread | |
1508 | * r25 = per_proc | |
1509 | */ | |
1510 | ||
0b4e3aa0 A |
1511 | .align 5 |
1512 | ||
55e303ae A |
1513 | fastpath: cmplwi cr3,r0,0x7FF5 ; Is this a null fastpath? |
1514 | beq-- cr3,fastexutl ; Yes, bail fast... | |
1515 | cmplwi cr3,r0,0x7FF1 ; Is it CthreadSetSelfNumber? | |
1516 | bnelr-- cr3 ; Not a fast path... | |
1c79356b A |
1517 | |
1518 | /* | |
1519 | * void cthread_set_self(cproc_t p) | |
1520 | * | |
91447636 A |
1521 | * Set's thread state "user_value". In practice this is the thread-local-data-pointer (TLDP), |
1522 | * though we do not interpret it. This call is mostly used by 32-bit tasks, but we save all 64 bits | |
1523 | * in case a 64-bit task wants to use this facility. They normally do not, because the 64-bit | |
1524 | * ABI reserves r13 for the TLDP. | |
1c79356b A |
1525 | * |
1526 | * This op is invoked as follows: | |
1527 | * li r0, CthreadSetSelfNumber // load the fast-trap number | |
1528 | * sc // invoke fast-trap | |
1529 | * blr | |
1c79356b A |
1530 | */ |
1531 | ||
1532 | CthreadSetSelfNumber: | |
91447636 A |
1533 | lwz r3,saver3+0(r4) /* get the TLDP passed in r3 */ |
1534 | lwz r5,saver3+4(r4) /* (all 64 bits, in case this is a 64-bit task) */ | |
1535 | stw r3,CTHREAD_SELF+0(r13) /* Remember it in the activation... */ | |
1536 | stw r5,CTHREAD_SELF+4(r13) | |
1537 | stw r3,UAW+0(r25) /* ...and in the per-proc */ | |
1538 | stw r5,UAW+4(r25) | |
1c79356b A |
1539 | |
1540 | ||
1541 | .globl EXT(fastexit) | |
1542 | EXT(fastexit): | |
55e303ae A |
1543 | fastexutl: mr r3,r4 ; Pass back savearea |
1544 | b EXT(exception_exit) ; Go back to the caller... | |
1c79356b A |
1545 | |
1546 | ||
1547 | /* | |
1548 | * Here's where we check for a hit on the Blue Box Assist | |
1549 | * Most registers are non-volatile, so be careful here. If we don't | |
1550 | * recognize the trap instruction we go back for regular processing. | |
1551 | * Otherwise we transfer to the assist code. | |
1552 | */ | |
1553 | ||
0b4e3aa0 A |
1554 | .align 5 |
1555 | ||
1c79356b | 1556 | checkassist: |
0b4e3aa0 | 1557 | lwz r0,saveexception(r4) ; Get the exception code |
55e303ae | 1558 | lwz r23,savesrr1+4(r4) ; Get the interrupted MSR |
0b4e3aa0 A |
1559 | lwz r26,ACT_MACT_BEDA(r13) ; Get Blue Box Descriptor Area |
1560 | mtcrf 0x18,r23 ; Check what SRR1 says | |
1561 | lwz r24,ACT_MACT_BTS(r13) ; Get the table start | |
1562 | cmplwi r0,T_AST ; Check for T_AST trap | |
55e303ae | 1563 | lwz r27,savesrr0+4(r4) ; Get trapped address |
0b4e3aa0 A |
1564 | crnand cr1_eq,SRR1_PRG_TRAP_BIT,MSR_PR_BIT ; We need both trap and user state |
1565 | sub r24,r27,r24 ; See how far into it we are | |
1566 | cror cr0_eq,cr0_eq,cr1_eq ; Need to bail if AST or not trap or not user state | |
1567 | cmplwi cr1,r24,BB_MAX_TRAP ; Do we fit in the list? | |
1568 | cror cr0_eq,cr0_eq,cr1_gt ; Also leave it trap not in range | |
1569 | btlr- cr0_eq ; No assist if AST or not trap or not user state or trap not in range | |
1570 | b EXT(atomic_switch_trap) ; Go to the assist... | |
1c79356b A |
1571 | |
1572 | ; | |
1573 | ; Virtual Machine Monitor | |
1574 | ; Here is where we exit from the emulated context | |
1575 | ; Note that most registers get trashed here | |
1576 | ; R3 and R30 are preserved across the call and hold the activation | |
1577 | ; and savearea respectivily. | |
1578 | ; | |
1579 | ||
0b4e3aa0 A |
1580 | .align 5 |
1581 | ||
1c79356b A |
1582 | exitFromVM: mr r30,r4 ; Get the savearea |
1583 | mr r3,r13 ; Get the activation | |
1584 | ||
1585 | b EXT(vmm_exit) ; Do it to it | |
1586 | ||
1587 | .align 5 | |
1588 | .globl EXT(retFromVM) | |
1589 | ||
1590 | LEXT(retFromVM) | |
91447636 A |
1591 | mfsprg r10,1 ; Get the current activation |
1592 | lwz r10,ACT_PER_PROC(r10) ; Get the per_proc block | |
1c79356b | 1593 | mr r8,r3 ; Get the activation |
55e303ae | 1594 | lwz r4,SAVprev+4(r30) ; Pick up the previous savearea |
1c79356b A |
1595 | mr r3,r30 ; Put savearea in proper register for common code |
1596 | lwz r11,SAVflags(r30) ; Get the flags of the current savearea | |
1597 | rlwinm r11,r11,0,15,13 ; Clear the syscall flag | |
91447636 | 1598 | mr r1,r8 |
1c79356b A |
1599 | stw r11,SAVflags(r3) ; Save back the flags (with reset stack cleared) |
1600 | ||
1601 | stw r4,ACT_MACT_PCB(r8) ; Point to the previous savearea (or 0 if none) | |
1602 | ||
1603 | lwz r5,THREAD_KERNEL_STACK(r1) ; Get the base pointer to the stack | |
1604 | addi r5,r5,KERNEL_STACK_SIZE-FM_SIZE ; Reset to empty | |
1605 | stw r5,ACT_MACT_KSP(r8) ; Save the empty stack pointer | |
1606 | b chkfac ; Go end it all... | |
1607 | ||
1608 | ||
0b4e3aa0 A |
1609 | ; |
1610 | ; chandler (note: not a candle maker or tallow merchant) | |
1611 | ; | |
1612 | ; Here is the system choke handler. This is where the system goes | |
1613 | ; to die. | |
1614 | ; | |
1615 | ; We get here as a result of a T_CHOKE exception which is generated | |
1616 | ; by the Choke firmware call or by lowmem_vectors when it detects a | |
1617 | ; fatal error. Examples of where this may be used is when we detect | |
1618 | ; problems in low-level mapping chains, trashed savearea free chains, | |
1619 | ; or stack guardpage violations. | |
1620 | ; | |
1621 | ; Note that we can not set a back chain in the stack when we come | |
1622 | ; here because we are probably here because the chain was corrupt. | |
1623 | ; | |
1c79356b | 1624 | |
0b4e3aa0 A |
1625 | |
1626 | .align 5 | |
1627 | .globl EXT(chandler) | |
55e303ae | 1628 | LEXT(chandler) ; Choke handler |
0b4e3aa0 | 1629 | |
55e303ae | 1630 | li r31,0 ; Get a 0 |
91447636 A |
1631 | mfsprg r25,1 ; Get the current activation |
1632 | lwz r25,ACT_PER_PROC(r25) ; Get the per_proc block | |
55e303ae | 1633 | stw r31,traceMask(0) ; Force tracing off right now |
0b4e3aa0 A |
1634 | |
1635 | ||
0b4e3aa0 A |
1636 | |
1637 | lwz r1,PP_DEBSTACKPTR(r25) ; Get debug stack pointer | |
1638 | cmpwi r1,-1 ; Are we already choking? | |
1639 | bne chokefirst ; Nope... | |
1c79356b | 1640 | |
0b4e3aa0 A |
1641 | chokespin: addi r31,r31,1 ; Spin and hope for an analyzer connection... |
1642 | addi r31,r31,1 ; Spin and hope for an analyzer connection... | |
1643 | addi r31,r31,1 ; Spin and hope for an analyzer connection... | |
1644 | addi r31,r31,1 ; Spin and hope for an analyzer connection... | |
1645 | addi r31,r31,1 ; Spin and hope for an analyzer connection... | |
1646 | addi r31,r31,1 ; Spin and hope for an analyzer connection... | |
1647 | b chokespin ; Spin and hope for an analyzer connection... | |
1c79356b | 1648 | |
0b4e3aa0 A |
1649 | chokefirst: li r0,-1 ; Set choke value |
1650 | mr. r1,r1 ; See if we are on debug stack yet | |
55e303ae | 1651 | lwz r10,saver1+4(r4) ; |
0b4e3aa0 A |
1652 | stw r0,PP_DEBSTACKPTR(r25) ; Show we are choking |
1653 | bne chokestart ; We are not on the debug stack yet... | |
1c79356b | 1654 | |
0b4e3aa0 A |
1655 | lwz r2,PP_DEBSTACK_TOP_SS(r25) ; Get debug stack top |
1656 | sub r11,r2,r10 ; Get stack depth | |
1c79356b | 1657 | |
0b4e3aa0 A |
1658 | cmplwi r11,KERNEL_STACK_SIZE-FM_SIZE-TRAP_SPACE_NEEDED ; Check if stack pointer is ok |
1659 | bgt chokespin ; Bad stack pointer or too little left, just die... | |
1c79356b | 1660 | |
0b4e3aa0 A |
1661 | subi r1,r10,FM_REDZONE ; Make a red zone |
1662 | ||
1663 | chokestart: li r0,0 ; Get a zero | |
1664 | stw r0,FM_BACKPTR(r1) ; We now have terminated the back chain | |
1665 | ||
1666 | bl EXT(SysChoked) ; Call the "C" phase of this | |
1667 | b chokespin ; Should not be here so just go spin... | |
1668 | ||
1c79356b A |
1669 | |
1670 | #if VERIFYSAVE | |
1671 | ; | |
1672 | ; Savearea chain verification | |
1673 | ; | |
1674 | ||
1675 | versave: | |
55e303ae A |
1676 | #if 0 |
1677 | lis r22,hi16(EXT(DebugWork)) ; (TEST/DEBUG) | |
1678 | ori r22,r22,lo16(EXT(DebugWork)) ; (TEST/DEBUG) | |
1679 | lwz r23,0(r22) ; (TEST/DEBUG) | |
1680 | mr. r23,r23 ; (TEST/DEBUG) | |
1681 | beqlr- ; (TEST/DEBUG) | |
91447636 A |
1682 | mfsprg r20,1 ; Get the current activation |
1683 | lwz r20,ACT_PER_PROC(r20) ; Get the per_proc block | |
55e303ae A |
1684 | lwz r21,pfAvailable(r20) ; (TEST/DEBUG) |
1685 | mr. r21,r21 ; (TEST/DEBUG) | |
1686 | bnelr+ ; (TEST/DEBUG) | |
1687 | ||
1688 | stw r22,0(r22) ; (TEST/DEBUG) Lock out more checks | |
1689 | BREAKPOINT_TRAP ; (TEST/DEBUG) Get into debugger | |
1690 | #endif | |
1691 | ||
1692 | #if 0 | |
1693 | ;; This code is broken and migration will make the matter even worse | |
1c79356b | 1694 | ; |
9bccf70c | 1695 | ; Make sure that all savearea chains have the right type on them |
1c79356b A |
1696 | ; |
1697 | ||
1698 | lis r28,hi16(EXT(default_pset)) ; (TEST/DEBUG) | |
1699 | lis r27,hi16(EXT(DebugWork)) ; (TEST/DEBUG) | |
1700 | ori r28,r28,lo16(EXT(default_pset)) ; (TEST/DEBUG) | |
1701 | ori r27,r27,lo16(EXT(DebugWork)) ; (TEST/DEBUG) | |
1702 | li r20,0 ; (TEST/DEBUG) | |
1703 | lwz r26,0(r27) ; (TEST/DEBUG) | |
1704 | lwz r27,psthreadcnt(r28) ; (TEST/DEBUG) | |
9bccf70c | 1705 | mr. r26,r26 ; (TEST/DEBUG) Have we locked the test out? |
1c79356b | 1706 | lwz r28,psthreads(r28) ; (TEST/DEBUG) |
9bccf70c A |
1707 | mflr r31 ; (TEST/DEBUG) Save return |
1708 | bnelr- ; (TEST/DEBUG) Test already triggered, skip... | |
1709 | b fckgo ; (TEST/DEBUG) Join up... | |
1c79356b | 1710 | |
9bccf70c A |
1711 | fcknext: mr. r27,r27 ; (TEST/DEBUG) Any more threads? |
1712 | bne+ fckxxx ; (TEST/DEBUG) Yes... | |
1713 | ||
1714 | mtlr r31 ; (TEST/DEBUG) Restore return | |
1715 | blr ; (TEST/DEBUG) Leave... | |
1c79356b | 1716 | |
9bccf70c | 1717 | fckxxx: lwz r28,THREAD_PSTHRN(r28) ; (TEST/DEBUG) Get next thread |
1c79356b | 1718 | |
9bccf70c A |
1719 | fckgo: subi r27,r27,1 ; (TEST/DEBUG) Decrement thread count |
1720 | lwz r24,THREAD_TOP_ACT(r28) ; (TEST/DEBUG) Get activation for the thread | |
1721 | lwz r20,ACT_MACT_PCB(r24) ; (TEST/DEBUG) Get the normal context | |
1722 | li r21,SAVgeneral ; (TEST/DEBUG) Make sure this is all general context | |
1723 | bl versavetype ; (TEST/DEBUG) Check the chain | |
1c79356b | 1724 | |
9bccf70c A |
1725 | lwz r20,facctx+FPUsave(r24) ; (TEST/DEBUG) Get regular floating point |
1726 | li r21,SAVfloat ; (TEST/DEBUG) Make sure this is all floating point | |
1727 | bl versavetype ; (TEST/DEBUG) Check the chain | |
1c79356b | 1728 | |
9bccf70c A |
1729 | lwz r20,facctx+VMXsave(r24) ; (TEST/DEBUG) Get regular vector point |
1730 | li r21,SAVvector ; (TEST/DEBUG) Make sure this is all vector | |
1731 | bl versavetype ; (TEST/DEBUG) Check the chain | |
1c79356b | 1732 | |
9bccf70c A |
1733 | lwz r29,vmmControl(r24) ; (TEST/DEBUG) Get the virtual machine control blocks |
1734 | mr. r29,r29 ; (TEST/DEBUG) Are there any? | |
1735 | beq+ fcknext ; (TEST/DEBUG) Nope, next thread... | |
1c79356b | 1736 | |
9bccf70c A |
1737 | li r22,kVmmMaxContextsPerThread ; (TEST/DEBUG) Get the number of control blocks |
1738 | subi r29,r29,vmmCEntrySize ; (TEST/DEBUG) Get running start | |
1739 | ||
1740 | fcknvmm: subi r22,r22,1 ; (TEST/DEBUG) Do all of them | |
1741 | mr. r22,r22 ; (TEST/DEBUG) Are we all done? | |
1742 | addi r29,r29,vmmCEntrySize ; (TEST/DEBUG) Get the next entry | |
1743 | blt- fcknext ; (TEST/DEBUG) Yes, check next thread... | |
1744 | ||
1745 | lwz r23,vmmFlags(r29) ; (TEST/DEBUG) Get entry flags | |
1746 | rlwinm. r23,r23,0,0,0 ; (TEST/DEBUG) Is this in use? | |
1747 | beq+ fcknvmm ; (TEST/DEBUG) Not in use... | |
1748 | ||
1749 | lwz r20,vmmFacCtx+FPUsave(r29) ; (TEST/DEBUG) Get regular floating point | |
1750 | li r21,SAVfloat ; (TEST/DEBUG) Make sure this is all floating point | |
1751 | bl versavetype ; (TEST/DEBUG) Check the chain | |
1752 | ||
1753 | lwz r20,vmmFacCtx+VMXsave(r29) ; (TEST/DEBUG) Get regular vector point | |
1754 | li r21,SAVvector ; (TEST/DEBUG) Make sure this is all vector | |
1755 | bl versavetype ; (TEST/DEBUG) Check the chain | |
1756 | b fcknvmm ; (TEST/DEBUG) Get then vmm block... | |
1757 | ||
1758 | versavetype: | |
1759 | mr. r20,r20 ; (TEST/DEBUG) Chain done? | |
1760 | beqlr- ; (TEST/DEBUG) Yes... | |
1761 | ||
1762 | lwz r23,SAVflags(r20) ; (TEST/DEBUG) Get the flags | |
1763 | rlwinm r23,r23,24,24,31 ; (TEST/DEBUG) Position it | |
1764 | cmplw r23,r21 ; (TEST/DEBUG) Are we the correct type? | |
1765 | beq+ versvok ; (TEST/DEBUG) This one is ok... | |
1766 | ||
1767 | lis r22,hi16(EXT(DebugWork)) ; (TEST/DEBUG) | |
1768 | ori r22,r22,lo16(EXT(DebugWork)) ; (TEST/DEBUG) | |
1769 | stw r22,0(r22) ; (TEST/DEBUG) Lock out more checks | |
1770 | BREAKPOINT_TRAP ; (TEST/DEBUG) Get into debugger | |
1771 | ||
55e303ae | 1772 | versvok: lwz r20,SAVprev+4(r20) ; (TEST/DEBUG) Get the previous one |
9bccf70c | 1773 | b versavetype ; (TEST/DEBUG) Go check its type... |
1c79356b A |
1774 | #endif |
1775 | ||
de355530 | 1776 | |
1c79356b | 1777 | #endif |