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