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