2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
32 /* Low level routines dealing with exception entry and exit.
33 * There are various types of exception:
35 * Interrupt, trap, system call and debugger entry. Each has it's own
36 * handler since the state save routine is different for each. The
37 * code is very similar (a lot of cut and paste).
39 * The code for the FPU disabled handler (lazy fpu) is in cswtch.s
43 #include <mach_assert.h>
44 #include <mach/exception_types.h>
45 #include <mach/kern_return.h>
46 #include <mach/ppc/vm_param.h>
51 #include <ppc/proc_reg.h>
53 #include <ppc/exception.h>
54 #include <ppc/savearea.h>
65 * ENTRY: VM switched ON
67 * R3 contains exception code
68 * R4 points to the saved context (virtual address)
69 * Everything is saved in savearea
73 * If pcb.ksp == 0 then the kernel stack is already busy,
74 * we make a stack frame
75 * leaving enough space for the 'red zone' in case the
76 * trapped thread was in the middle of saving state below
79 * otherwise we make a stack frame and
80 * the kernel stack (setting pcb.ksp to 0)
82 * on return, we do the reverse, the last state is popped from the pcb
83 * and pcb.ksp is set to the top of stack
86 /* TRAP_SPACE_NEEDED is the space assumed free on the kernel stack when
87 * another trap is taken. We need at least enough space for a saved state
88 * structure plus two small backpointer frames, and we add a few
89 * hundred bytes for the space needed by the C (which may be less but
90 * may be much more). We're trying to catch kernel stack overflows :-)
93 #define TRAP_SPACE_NEEDED FM_REDZONE+(2*FM_SIZE)+256
99 LEXT(thandler) ; Trap handler
101 mfsprg r13,1 ; Get the current activation
102 lwz r25,ACT_PER_PROC(r13) ; Get the per_proc block
104 lwz r1,PP_ISTACKPTR(r25) ; Get interrupt stack pointer
106 cmpwi cr0,r1,0 ; Are we on interrupt stack?
108 beq- cr0,EXT(ihandler) ; If on interrupt stack, treat this as interrupt...
109 lwz r26,ACT_MACT_SPF(r13) ; Get special flags
110 lwz r8,ACT_MACT_PCB(r13) ; Get the last savearea used
111 rlwinm. r26,r26,0,bbThreadbit,bbThreadbit ; Do we have Blue Box Assist active?
112 lwz r1,ACT_MACT_KSP(r13) ; Get the top of kernel stack
113 bnel- checkassist ; See if we should assist this
114 stw r4,ACT_MACT_PCB(r13) ; Point to our savearea
115 stw r8,SAVprev+4(r4) ; Queue the new save area in the front
118 bl versave ; (TEST/DEBUG)
121 lwz r9,THREAD_KERNEL_STACK(r6) ; Get our kernel stack start
122 cmpwi cr1,r1,0 ; Are we already on kernel stack?
123 stw r13,SAVact(r4) ; Mark the savearea as belonging to this activation
124 lwz r26,saver1+4(r4) ; Get the stack at interrupt time
126 bne+ cr1,.L_kstackfree ; We are not on kernel stack yet...
128 subi r1,r26,FM_REDZONE ; Make a red zone on interrupt time kernel stack
131 lwz r31,savesrr1+4(r4) ; Pick up the entry MSR
132 sub r9,r1,r9 ; Get displacment into the kernel stack
133 li r0,0 ; Make this 0
134 rlwinm. r0,r9,0,28,31 ; Verify that we have a 16-byte aligned stack (and get a 0)
135 cmplwi cr2,r9,KERNEL_STACK_SIZE ; Do we still have room on the stack?
136 beq cr1,.L_state_on_kstack ; using above test for pcb/stack
138 stw r0,ACT_MACT_KSP(r13) ; Show that we have taken the stack
141 lwz r9,savevrsave(r4) ; Get the VRSAVE register
142 bne-- kernelStackUnaligned ; Stack is unaligned...
143 rlwinm. r6,r31,0,MSR_VEC_BIT,MSR_VEC_BIT ; Was vector on?
144 subi r1,r1,FM_SIZE ; Push a header onto the current stack
145 bgt-- cr2,kernelStackBad ; Kernel stack is bogus...
147 kernelStackNotBad: ; Vector was off
148 beq++ tvecoff ; Vector off, do not save vrsave...
149 stw r9,liveVRS(r25) ; Set the live value
151 tvecoff: stw r26,FM_BACKPTR(r1) ; Link back to the previous frame
154 /* If debugging, we need two frames, the first being a dummy
155 * which links back to the trapped routine. The second is
156 * that which the C routine below will need
158 lwz r3,savesrr0+4(r4) ; Get the point of interruption
159 stw r3,FM_LR_SAVE(r1) ; save old instr ptr as LR value
160 stwu r1, -FM_SIZE(r1) ; and make new frame
165 addi r4,r13,SYSTEM_TIMER
168 /* call trap handler proper, with
170 * ARG1 = saved_state ptr
176 lwz r3,saveexception(r30) ; Get the exception code
177 lwz r0,ACT_MACT_SPF(r13) ; Get the special flags
179 addi r5,r3,-T_DATA_ACCESS ; Adjust to start of range
180 rlwinm. r0,r0,0,runningVMbit,runningVMbit ; Are we in VM state? (cr0_eq == 0 if yes)
181 cmplwi cr2,r5,T_TRACE-T_DATA_ACCESS ; Are we still in range? (cr_gt if not)
183 lwz r5,savedsisr(r4) ; Get the saved DSISR
185 crnor cr7_eq,cr0_eq,cr2_gt ; We should intercept if in VM and is a true trap (cr7_eq == 1 if yes)
186 rlwinm. r0,r31,0,MSR_PR_BIT,MSR_PR_BIT ; Are we trapping from supervisor state? (cr0_eq == 1 if yes)
188 cmpi cr2,r3,T_PREEMPT ; Is this a preemption?
191 stw r4,ACT_MACT_UPCB(r13) ; Store user savearea
194 crandc cr0_eq,cr7_eq,cr0_eq ; Do not intercept if we are in the kernel (cr0_eq == 1 if yes)
196 lwz r6,savedar(r4) ; Get the DAR (top)
197 lwz r7,savedar+4(r4) ; Get the DAR (bottom)
199 beq- cr2,.L_call_trap ; Do not turn on interrupts for T_PREEMPT
200 beq- exitFromVM ; Any true trap but T_MACHINE_CHECK exits us from the VM...
202 /* syscall exception might warp here if there's nothing left
203 * to do except generate a trap
209 stfd f31,emfp31(r25) ; (TEST/DEBUG)
214 lis r10,hi16(MASK(MSR_VEC)) ; Get the vector enable
215 mfmsr r7 ; Get the MSR
216 ori r10,r10,lo16(MASK(MSR_FP)|MASK(MSR_EE)) ; Add in FP and EE
217 andc r7,r7,r10 ; Turn off VEC, FP, and EE
218 mtmsr r7 ; Disable for interrupts
219 mfsprg r8,1 ; Get the current activation
220 lwz r10,ACT_PER_PROC(r8) ; Get the per_proc block
222 * This is also the point where new threads come when they are created.
223 * The new thread is setup to look like a thread that took an
224 * interrupt and went immediatly into trap.
228 lwz r11,SAVflags(r3) ; Get the flags of the current savearea
229 lwz r0,savesrr1+4(r3) ; Get the MSR we are going to
230 lwz r4,SAVprev+4(r3) ; Pick up the previous savearea
231 mfsprg r8,1 ; Get the current thread
232 rlwinm r11,r11,0,15,13 ; Clear the syscall flag
233 rlwinm. r0,r0,0,MSR_PR_BIT,MSR_PR_BIT ; Are we going to the user?
235 stw r11,SAVflags(r3) ; Save back the flags (with reset stack cleared)
237 lwz r5,THREAD_KERNEL_STACK(r1) ; Get the base pointer to the stack
238 stw r4,ACT_MACT_PCB(r8) ; Point to the previous savearea (or 0 if none)
239 addi r5,r5,KERNEL_STACK_SIZE-FM_SIZE ; Reset to empty
241 beq-- chkfac ; We are not leaving the kernel yet...
243 stw r5,ACT_MACT_KSP(r8) ; Save the empty stack pointer
244 b chkfac ; Go end it all...
248 ; Here is where we go when we detect that the kernel stack is all messed up.
249 ; We just try to dump some info and get into the debugger.
254 lwz r3,PP_DEBSTACK_TOP_SS(r25) ; Pick up debug stack top
255 subi r3,r3,KERNEL_STACK_SIZE-FM_SIZE ; Adjust to start of stack
256 sub r3,r1,r3 ; Get displacement into debug stack
257 cmplwi cr2,r3,KERNEL_STACK_SIZE-FM_SIZE ; Check if we are on debug stack
258 blt+ cr2,kernelStackNotBad ; Yeah, that is ok too...
260 lis r0,hi16(Choke) ; Choke code
261 ori r0,r0,lo16(Choke) ; and the rest
262 li r3,failStack ; Bad stack code
265 kernelStackUnaligned:
266 lis r0,hi16(Choke) ; Choke code
267 ori r0,r0,lo16(Choke) ; and the rest
268 li r3,failUnalignedStk ; Unaligned stack code
275 * ENTRY: VM switched ON
277 * R3 contains exception code
278 * R4 points to the saved context (virtual address)
279 * Everything is saved in savearea
283 * If pcb.ksp == 0 then the kernel stack is already busy,
284 * this is an error - jump to the debugger entry
286 * otherwise depending upon the type of
287 * syscall, look it up in the kernel table
288 * or pass it to the server.
290 * on return, we do the reverse, the state is popped from the pcb
291 * and pcb.ksp is set to the top of stack.
296 * mach system calls are negative
297 * BSD system calls are low positive
298 * PPC-only system calls are in the range 0x6xxx
299 * PPC-only "fast" traps are in the range 0x7xxx
304 LEXT(shandler) ; System call handler
306 lwz r7,savesrr1+4(r4) ; Get the SRR1 value
307 mfsprg r13,1 ; Get the current activation
308 lwz r25,ACT_PER_PROC(r13) ; Get the per_proc block
309 lwz r0,saver0+4(r4) ; Get the original syscall number
310 lwz r17,PP_ISTACKPTR(r25) ; Get interrupt stack pointer
311 rlwinm r15,r0,0,0,19 ; Clear the bottom of call number for fast check
312 mr. r17,r17 ; Are we on interrupt stack?
313 lwz r9,savevrsave(r4) ; Get the VRsave register
314 beq-- EXT(ihandler) ; On interrupt stack, not allowed...
315 rlwinm. r6,r7,0,MSR_VEC_BIT,MSR_VEC_BIT ; Was vector on?
318 beq++ svecoff ; Vector off, do not save vrsave...
319 stw r9,liveVRS(r25) ; Set the live value
321 ; Check if SCs are being redirected for the BlueBox or to VMM
324 svecoff: lwz r6,ACT_MACT_SPF(r13) ; Pick up activation special flags
325 mtcrf 0x40,r6 ; Check special flags
326 mtcrf 0x01,r6 ; Check special flags
327 crmove cr6_eq,runningVMbit ; Remember if we are in VMM
328 bne++ cr6,sVMchecked ; Not running VM
329 lwz r18,spcFlags(r25) ; Load per_proc special flags
330 rlwinm. r18,r18,0,FamVMmodebit,FamVMmodebit ; Is FamVMmodebit set?
331 beq sVMchecked ; Not in FAM
332 cmpwi r0,0x6004 ; Is it vmm_dispatch syscall:
334 lwz r26,saver3+4(r4) ; Get the original syscall number
335 cmpwi cr6,r26,kvmmExitToHost ; vmm_exit_to_host request
337 bf++ bbNoMachSCbit,noassist ; Take branch if SCs are not redirected
338 lwz r26,ACT_MACT_BEDA(r13) ; Pick up the pointer to the blue box exception area
339 b EXT(atomic_switch_syscall) ; Go to the assist...
341 noassist: cmplwi r15,0x7000 ; Do we have a fast path trap?
342 lwz r14,ACT_MACT_PCB(r13) ; Now point to the PCB
343 beql fastpath ; We think it is a fastpath...
345 lwz r1,ACT_MACT_KSP(r13) ; Get the kernel stack pointer
347 mr. r1,r1 ; Are we already on the kernel stack?
348 li r3,T_SYSTEM_CALL ; Yup, pretend we had an interrupt...
349 beq- EXT(ihandler) ; Bad boy, bad boy... What cha gonna do when they come for you?
352 stw r4,ACT_MACT_PCB(r13) ; Point to our savearea
353 stw r4,ACT_MACT_UPCB(r13) ; Store user savearea
354 li r0,0 ; Clear this out
355 stw r14,SAVprev+4(r4) ; Queue the new save area in the front
356 stw r13,SAVact(r4) ; Point the savearea at its activation
359 bl versave ; (TEST/DEBUG)
362 lwz r15,saver1+4(r4) ; Grab interrupt time stack
363 mr r30,r4 ; Save pointer to the new context savearea
364 stw r0,ACT_MACT_KSP(r13) ; Mark stack as busy with 0 val
365 stw r15,FM_BACKPTR(r1) ; Link stack frame backwards
367 lwz r3,SAVtime+4(r30)
368 addi r4,r13,SYSTEM_TIMER
372 /* If debugging, we need two frames, the first being a dummy
373 * which links back to the trapped routine. The second is
374 * that which the C routine below will need
376 lwz r8,savesrr0+4(r30) ; Get the point of interruption
377 stw r8,FM_LR_SAVE(r1) ; Save old instr ptr as LR value
378 stwu r1, -FM_SIZE(r1) ; and make new frame
383 lwz r15,SAVflags(r30) ; Get the savearea flags
384 lwz r0,saver0+4(r30) ; Get R0 back
385 mfmsr r11 ; Get the MSR
386 stwu r1,-(FM_SIZE+ARG_SIZE+MUNGE_ARGS_SIZE)(r1) ; Make a stack frame
387 ori r11,r11,lo16(MASK(MSR_EE)) ; Turn on interruption enabled bit
388 rlwinm r10,r0,0,0,19 ; Keep only the top part
389 oris r15,r15,SAVsyscall >> 16 ; Mark that it this is a syscall
390 cmplwi r10,0x6000 ; Is it the special ppc-only guy?
391 stw r15,SAVflags(r30) ; Save syscall marker
392 beq-- cr6,exitFromVM ; It is time to exit from alternate context...
394 beq-- ppcscall ; Call the ppc-only system call handler...
396 mr. r0,r0 ; What kind is it?
397 mtmsr r11 ; Enable interruptions
399 blt-- .L_kernel_syscall ; System call number if negative, this is a mach call...
401 lwz r8,ACT_TASK(r13) ; Get our task
402 cmpwi cr0,r0,0x7FFA ; Special blue box call?
403 beq-- .L_notify_interrupt_syscall ; Yeah, call it...
405 lwz r7,TASK_SYSCALLS_UNIX(r8) ; Get the current count
406 mr r3,r30 ; Get PCB/savearea
407 mr r4,r13 ; current activation
408 addi r7,r7,1 ; Bump it
409 stw r7,TASK_SYSCALLS_UNIX(r8) ; Save it
412 stfd f31,emfp31(r25) ; (TEST/DEBUG)
415 bl EXT(unix_syscall) ; Check out unix...
417 .L_call_server_syscall_exception:
418 li r3,EXC_SYSCALL ; doexception(EXC_SYSCALL, num, 1)
420 .L_call_server_exception:
421 mr r4,r0 ; Set syscall selector
423 b EXT(doexception) ; Go away, never to return...
425 .L_notify_interrupt_syscall:
426 lwz r3,saver3+4(r30) ; Get the new PC address to pass in
427 bl EXT(syscall_notify_interrupt)
429 * Ok, return from C function, R3 = return value
431 * saved state is still in R30 and the active thread is in R16 .
433 mr r31,r16 ; Move the current thread pointer
434 stw r3,saver3+4(r30) ; Stash the return code
435 b .L_thread_syscall_ret_check_ast
438 ; Handle PPC-only system call interface
439 ; These are called with interruptions disabled
440 ; and the savearea/pcb as the first parameter.
441 ; It is up to the callee to enable interruptions if
442 ; they should be. We are in a state here where
443 ; both interrupts and preemption are ok, but because we could
444 ; be calling diagnostic code we will not enable.
446 ; Also, the callee is responsible for finding any parameters
447 ; in the savearea/pcb. It also must set saver3 with any return
448 ; code before returning.
450 ; There are 3 possible return codes:
451 ; 0 the call is disabled or something, we treat this like it was bogus
452 ; + the call finished ok, check for AST
453 ; - the call finished ok, do not check for AST
455 ; Note: the last option is intended for special diagnostics calls that
456 ; want the thread to return and execute before checking for preemption.
458 ; NOTE: Both R16 (thread) and R30 (savearea) need to be preserved over this call!!!!
463 ppcscall: rlwinm r11,r0,2,18,29 ; Make an index into the table
464 lis r10,hi16(EXT(PPCcalls)) ; Get PPC-only system call table
465 cmplwi r11,PPCcallmax ; See if we are too big
466 ori r10,r10,lo16(EXT(PPCcalls)) ; Merge in low half
467 bgt- .L_call_server_syscall_exception ; Bogus call...
468 lwzx r11,r10,r11 ; Get function address
471 ; Note: make sure we do not change the savearea in R30 to
472 ; a different register without checking. Some of the PPCcalls
473 ; depend upon it being there.
476 mr r3,r30 ; Pass the savearea
477 mr r4,r13 ; Pass the activation
478 mr. r11,r11 ; See if there is a function here
479 mtctr r11 ; Set the function address
480 beq- .L_call_server_syscall_exception ; Disabled call...
482 mfspr r4,pmc1 ; Get stamp
483 stw r4,0x6100+(9*16)+0x0(0) ; Save it
484 mfspr r4,pmc2 ; Get stamp
485 stw r4,0x6100+(9*16)+0x4(0) ; Save it
486 mfspr r4,pmc3 ; Get stamp
487 stw r4,0x6100+(9*16)+0x8(0) ; Save it
488 mfspr r4,pmc4 ; Get stamp
489 stw r4,0x6100+(9*16)+0xC(0) ; Save it
496 mr. r3,r3 ; See what we should do
497 mr r31,r16 ; Restore the current thread pointer
498 bgt+ .L_thread_syscall_ret_check_ast ; Take normal AST checking return....
499 mfsprg r10,1 ; Get the current activation
500 lwz r10,ACT_PER_PROC(r10) ; Get the per_proc block
501 blt+ .L_thread_syscall_return ; Return, but no ASTs....
502 lwz r0,saver0+4(r30) ; Restore the system call number
503 b .L_call_server_syscall_exception ; Go to common exit...
508 * we get here for mach system calls
509 * when kdebug tracing is enabled
513 mr r4,r30 ; Pass in saved state
514 bl EXT(syscall_trace)
516 cmplw r31,r29 ; Is this syscall in the table?
517 add r31,r27,r28 ; Point right to the syscall table entry
519 bge- .L_call_server_syscall_exception ; The syscall number is invalid
521 lwz r0,savesrr1(r30) ; Get the saved srr1
522 rlwinm. r0,r0,0,MSR_SF_BIT,MSR_SF_BIT ; Test for 64 bit caller
523 lwz r0,MACH_TRAP_ARG_MUNGE32(r31) ; Pick up the 32 bit munge function address
524 beq-- .L_ksystrace_munge
525 lwz r0,MACH_TRAP_ARG_MUNGE64(r31) ; Pick up the 64 bit munge function address
528 cmplwi r0,0 ; do we have a munger to call?
529 mtctr r0 ; Set the function call address
530 addi r3,r30,saver3 ; Pointer to args from save area
531 addi r4,r1,FM_ARG0+ARG_SIZE ; Pointer for munged args
532 beq-- .L_ksystrace_trapcall ; just make the trap call
533 bctrl ; Call the munge function
535 .L_ksystrace_trapcall:
536 lwz r0,MACH_TRAP_FUNCTION(r31) ; Pick up the function address
537 mtctr r0 ; Set the function call address
538 addi r3,r1,FM_ARG0+ARG_SIZE ; Pointer to munged args
541 mr r4,r30 ; Pass in the savearea
542 bl EXT(syscall_trace_end) ; Trace the exit of the system call
547 /* Once here, we know that the syscall was -ve
548 * we should still have r1=ksp,
549 * r16 = pointer to current thread,
550 * r13 = pointer to top activation,
551 * r0 = syscall number
552 * r30 = pointer to saved state (in pcb)
559 ; Call a function that can print out our syscall info
560 ; Note that we don t care about any volatiles yet
562 lwz r10,ACT_TASK(r13) ; Get our task
564 lis r8,hi16(EXT(kdebug_enable)) ; Get top of kdebug_enable
565 lis r28,hi16(EXT(mach_trap_table)) ; Get address of table
566 ori r8,r8,lo16(EXT(kdebug_enable)) ; Get bottom of kdebug_enable
567 lwz r8,0(r8) ; Get kdebug_enable
569 lwz r7,TASK_SYSCALLS_MACH(r10) ; Get the current count
570 neg r31,r0 ; Make this positive
572 slwi r27,r3,4 ; multiply by 16
573 slwi r3,r3,2 ; and the original by 4
574 ori r28,r28,lo16(EXT(mach_trap_table)) ; Get address of table
575 add r27,r27,r3 ; for a total of 20x (5 words/entry)
576 addi r7,r7,1 ; Bump TASK_SYSCALLS_MACH count
577 cmplwi r8,0 ; Is kdebug_enable non-zero
578 stw r7,TASK_SYSCALLS_MACH(r10) ; Save count
579 bne-- ksystrace ; yes, tracing enabled
581 cmplwi r31,MACH_TRAP_TABLE_COUNT ; Is this syscall in the table?
582 add r31,r27,r28 ; Point right to the syscall table entry
584 bge-- .L_call_server_syscall_exception ; The syscall number is invalid
586 lwz r0,savesrr1(r30) ; Get the saved srr1
587 rlwinm. r0,r0,0,MSR_SF_BIT,MSR_SF_BIT ; Test for 64 bit caller
588 lwz r0,MACH_TRAP_ARG_MUNGE32(r31) ; Pick up the 32 bit munge function address
589 beq-- .L_kernel_syscall_munge
590 lwz r0,MACH_TRAP_ARG_MUNGE64(r31) ; Pick up the 64 bit munge function address
592 .L_kernel_syscall_munge:
593 cmplwi r0,0 ; test for null munger
594 mtctr r0 ; Set the function call address
595 addi r3,r30,saver3 ; Pointer to args from save area
596 addi r4,r1,FM_ARG0+ARG_SIZE ; Pointer for munged args
597 beq-- .L_kernel_syscall_trapcall ; null munger - skip to trap call
598 bctrl ; Call the munge function
600 .L_kernel_syscall_trapcall:
601 lwz r0,MACH_TRAP_FUNCTION(r31) ; Pick up the function address
602 mtctr r0 ; Set the function call address
603 addi r3,r1,FM_ARG0+ARG_SIZE ; Pointer to munged args
606 stfd f31,emfp31(r25) ; (TEST/DEBUG)
613 * Ok, return from C function, R3 = return value
615 * get the active thread's PCB pointer and thus pointer to user state
616 * saved state is still in R30 and the active thread is in R16
620 srawi r0,r3,31 ; properly extend the return code
621 cmpi cr0,r3,KERN_INVALID_ARGUMENT ; deal with invalid system calls
622 mr r31,r16 ; Move the current thread pointer
623 stw r0, saver3(r30) ; stash the high part of the return code
624 stw r3,saver3+4(r30) ; Stash the low part of the return code
625 beq-- cr0,.L_mach_invalid_ret ; otherwise fall through into the normal return path
629 /* 'standard' syscall returns here - INTERRUPTS ARE STILL ON
630 * the syscall may perform a thread_set_syscall_return
631 * followed by a thread_exception_return, ending up
632 * at thread_syscall_return below, with SS_R3 having
633 * been set up already
635 * When we are here, r31 should point to the current thread,
636 * r30 should point to the current pcb
637 * r3 contains value that we're going to return to the user
638 * which has already been stored back into the save area
641 .L_thread_syscall_ret_check_ast:
642 lis r10,hi16(MASK(MSR_VEC)) ; Get the vector enable
643 mfmsr r12 ; Get the current MSR
644 ori r10,r10,lo16(MASK(MSR_FP)|MASK(MSR_EE)) ; Add in FP and EE
645 andc r12,r12,r10 ; Turn off VEC, FP, and EE
646 mtmsr r12 ; Turn interruptions off
648 mfsprg r10,1 ; Get the current activation
649 lwz r10,ACT_PER_PROC(r10) ; Get the per_proc block
651 /* Check to see if there's an outstanding AST */
653 lwz r4,PP_PENDING_AST(r10)
654 cmpi cr0,r4, 0 ; Any pending asts?
655 beq++ cr0,.L_syscall_no_ast ; Nope...
657 /* Yes there is, call ast_taken
658 * pretending that the user thread took an AST exception here,
659 * ast_taken will save all state and bring us back here
663 /* debug assert - make sure that we're not returning to kernel */
664 lwz r3,savesrr1+4(r30)
665 andi. r3,r3,MASK(MSR_PR)
666 bne++ scrnotkern ; returning to user level, check
668 lis r0,hi16(Choke) ; Choke code
669 ori r0,r0,lo16(Choke) ; and the rest
670 li r3,failContext ; Bad state code
676 lis r3,hi16(AST_ALL) ; Set ast flags
677 li r4,1 ; Set interrupt allowed
678 ori r3,r3,lo16(AST_ALL)
679 bl EXT(ast_taken) ; Process the pending ast
680 b .L_thread_syscall_ret_check_ast ; Go see if there was another...
684 * need to figure out why we got an KERN_INVALID_ARG
685 * if it was due to a non-existent system call
686 * then we want to throw an exception... otherwise
687 * we want to pass the error code back to the caller
689 lwz r0,saver0+4(r30) ; reload the original syscall number
690 neg r28,r0 ; Make this positive
691 mr r4,r28 ; save a copy
692 slwi r27,r4,4 ; multiply by 16
693 slwi r4,r4,2 ; and another 4
694 lis r28,hi16(EXT(mach_trap_table)) ; Get address of table
695 add r27,r27,r4 ; for a total of 20x (5 words/entry)
696 ori r28,r28,lo16(EXT(mach_trap_table)) ; Get address of table
697 add r28,r27,r28 ; Point right to the syscall table entry
698 lwz r27,MACH_TRAP_FUNCTION(r28) ; Pick up the function address
699 lis r28,hi16(EXT(kern_invalid)) ; Get high half of invalid syscall function
700 ori r28,r28,lo16(EXT(kern_invalid)) ; Get low half of invalid syscall function
701 cmpw cr0,r27,r28 ; Check if this is an invalid system call
702 beq-- .L_call_server_syscall_exception ; We have a bad system call
703 b .L_mach_invalid_arg ; a system call returned KERN_INVALID_ARG
706 /* thread_exception_return returns to here, almost all
707 * registers intact. It expects a full context restore
708 * of what it hasn't restored itself (ie. what we use).
710 * In particular for us,
711 * we still have r31 points to the current thread,
712 * r30 points to the current pcb
718 .L_thread_syscall_return:
720 mr r3,r30 ; Get savearea to the correct register for common exit
722 lwz r11,SAVflags(r30) ; Get the flags
723 lwz r5,THREAD_KERNEL_STACK(r31) ; Get the base pointer to the stack
724 lwz r4,SAVprev+4(r30) ; Get the previous save area
725 rlwinm r11,r11,0,15,13 ; Clear the syscall flag
726 mfsprg r8,1 ; Now find the current activation
727 addi r5,r5,KERNEL_STACK_SIZE-FM_SIZE ; Reset to empty
728 stw r11,SAVflags(r30) ; Stick back the flags
729 stw r5,ACT_MACT_KSP(r8) ; Save the empty stack pointer
730 stw r4,ACT_MACT_PCB(r8) ; Save previous save area
731 b chkfac ; Go end it all...
734 * thread_exception_return()
736 * Return to user mode directly from within a system call.
740 .globl EXT(thread_bootstrap_return)
741 LEXT(thread_bootstrap_return) ; NOTE: THIS IS GOING AWAY IN A FEW DAYS....
743 .globl EXT(thread_exception_return)
744 LEXT(thread_exception_return) ; Directly return to user mode
746 .L_thread_exc_ret_check_ast:
747 lis r10,hi16(MASK(MSR_VEC)) ; Get the vector enable
748 mfmsr r3 ; Get the MSR
749 ori r10,r10,lo16(MASK(MSR_FP)|MASK(MSR_EE)) ; Add in FP and EE
750 andc r3,r3,r10 ; Turn off VEC, FP, and EE
751 mtmsr r3 ; Disable interrupts
753 /* Check to see if there's an outstanding AST */
754 /* We don't bother establishing a call frame even though CHECK_AST
755 can invoke ast_taken(), because it can just borrow our caller's
756 frame, given that we're not going to return.
759 mfsprg r10,1 ; Get the current activation
760 lwz r10,ACT_PER_PROC(r10) ; Get the per_proc block
761 lwz r4,PP_PENDING_AST(r10)
763 beq+ cr0,.L_exc_ret_no_ast
765 /* Yes there is, call ast_taken
766 * pretending that the user thread took an AST exception here,
767 * ast_taken will save all state and bring us back here
772 ori r3,r3,lo16(AST_ALL)
775 b .L_thread_exc_ret_check_ast ; check for a second AST (rare)
777 /* arriving here, interrupts should be disabled */
778 /* Get the active thread's PCB pointer to restore regs
782 mfsprg r30,1 ; Get the currrent activation
785 lwz r30,ACT_MACT_PCB(r30)
786 mr. r30,r30 ; Is there any context yet?
787 beq- makeDummyCtx ; No, hack one up...
790 * debug assert - make sure that we're not returning to kernel
791 * get the active thread's PCB pointer and thus pointer to user state
794 lwz r3,savesrr1+4(r30)
795 andi. r3,r3,MASK(MSR_PR)
796 bne+ ret_user2 ; We are ok...
798 lis r0,hi16(Choke) ; Choke code
799 ori r0,r0,lo16(Choke) ; and the rest
800 li r3,failContext ; Bad state code
806 /* If the system call flag isn't set, then we came from a trap,
807 * so warp into the return_from_trap (thread_return) routine,
808 * which takes PCB pointer in R3, not in r30!
810 lwz r0,SAVflags(r30) ; Grab the savearea flags
811 andis. r0,r0,SAVsyscall>>16 ; Are we returning from a syscall?
812 mr r3,r30 ; Copy pcb pointer into r3 in case we need it
813 beq-- cr0,thread_return ; Nope, must be a thread return...
814 b .L_thread_syscall_return ; Join up with the system call return...
817 ; This is where we handle someone trying who did a thread_create followed
818 ; by a thread_resume with no intervening thread_set_state. Just make an
819 ; empty context, initialize it to trash and let em execute at 0...
825 bl EXT(save_get) ; Get a save_area
826 li r4,SAVgeneral ; Get the general context type
828 stb r4,SAVflags+2(r3) ; Set type
829 addi r2,r3,savefpscr+4 ; Point past what we are clearing
830 mr r4,r3 ; Save the start
832 cleardummy: stw r0,0(r4) ; Clear stuff
833 addi r4,r4,4 ; Next word
834 cmplw r4,r2 ; Still some more?
835 blt+ cleardummy ; Yeah...
837 lis r2,hi16(MSR_EXPORT_MASK_SET) ; Set the high part of the user MSR
838 ori r2,r2,lo16(MSR_EXPORT_MASK_SET) ; And the low part
839 stw r2,savesrr1+4(r3) ; Set the default user MSR
841 b thread_return ; Go let em try to execute, hah!
846 * ENTRY: VM switched ON
848 * R3 contains exception code
849 * R4 points to the saved context (virtual address)
850 * Everything is saved in savearea
856 LEXT(ihandler) ; Interrupt handler */
859 * get the value of istackptr, if it's zero then we're already on the
863 lwz r10,savesrr1+4(r4) ; Get SRR1
864 lwz r7,savevrsave(r4) ; Get the VRSAVE register
865 mfsprg r13,1 ; Get the current activation
866 lwz r25,ACT_PER_PROC(r13) ; Get the per_proc block
867 li r14,0 ; Zero this for now
868 rlwinm. r16,r10,0,MSR_VEC_BIT,MSR_VEC_BIT ; Was vector on?
869 lwz r1,PP_ISTACKPTR(r25) ; Get the interrupt stack
870 li r16,0 ; Zero this for now
872 beq+ ivecoff ; Vector off, do not save vrsave...
873 stw r7,liveVRS(r25) ; Set the live value
875 ivecoff: li r0,0 ; Get a constant 0
876 rlwinm r5,r10,0,MSR_PR_BIT,MSR_PR_BIT ; Are we trapping from supervisor state?
877 mr. r1,r1 ; Is it active?
878 cmplwi cr2,r5,0 ; cr2_eq == 1 if yes
880 lwz r14,ACT_MACT_PCB(r13) ; Now point to the PCB
881 lwz r9,saver1+4(r4) ; Pick up the rupt time stack
882 stw r14,SAVprev+4(r4) ; Queue the new save area in the front
883 stw r13,SAVact(r4) ; Point the savearea at its activation
884 stw r4,ACT_MACT_PCB(r13) ; Point to our savearea
886 stw r4,ACT_MACT_UPCB(r13) ; Store user savearea
888 ifromk: bne .L_istackfree ; Nope...
890 /* We're already on the interrupt stack, get back the old
891 * stack pointer and make room for a frame
894 lwz r10,PP_INTSTACK_TOP_SS(r25) ; Get the top of the interrupt stack
895 addi r5,r9,INTSTACK_SIZE-FM_SIZE ; Shift stack for bounds check
896 subi r1,r9,FM_REDZONE ; Back up beyond the red zone
897 sub r5,r5,r10 ; Get displacement into stack
898 cmplwi r5,INTSTACK_SIZE-FM_SIZE ; Is the stack actually invalid?
899 blt+ ihsetback ; The stack is ok...
901 lwz r5,PP_DEBSTACK_TOP_SS(r25) ; Pick up debug stack top
902 subi r5,r5,KERNEL_STACK_SIZE-FM_SIZE ; Adjust to start of stack
903 sub r5,r1,r5 ; Get displacement into debug stack
904 cmplwi cr2,r5,KERNEL_STACK_SIZE-FM_SIZE ; Check if we are on debug stack
905 blt+ cr2,ihsetback ; Yeah, that is ok too...
907 lis r0,hi16(Choke) ; Choke code
908 ori r0,r0,lo16(Choke) ; and the rest
909 li r3,failStack ; Bad stack code
913 lis r0,hi16(Choke) ; Choke code
914 ori r0,r0,lo16(Choke) ; and the rest
915 li r3,failUnalignedStk ; Unaligned stack code
921 rlwinm. r0,r1,0,28,31 ; Check if stack is aligned (and get 0)
922 lwz r10,SAVflags(r4) ; Get savearea flags
923 bne-- intUnalignedStk ; Stack is unaligned...
924 stw r0,PP_ISTACKPTR(r25) ; Mark the stack in use
925 oris r10,r10,hi16(SAVrststk) ; Indicate we reset stack when we return from this one
926 stw r10,SAVflags(r4) ; Stick it back
929 * To summarize, when we reach here, the state has been saved and
930 * the stack is marked as busy. We now generate a small
931 * stack frame with backpointers to follow the calling
932 * conventions. We set up the backpointers to the trapped
933 * routine allowing us to backtrace.
936 ihsetback: subi r1,r1,FM_SIZE ; Make a new frame
937 stw r9,FM_BACKPTR(r1) ; Point back to previous stackptr
940 beq- cr1,ihbootnover ; (TEST/DEBUG)
941 bl versave ; (TEST/DEBUG)
942 ihbootnover: ; (TEST/DEBUG)
946 /* If debugging, we need two frames, the first being a dummy
947 * which links back to the trapped routine. The second is
948 * that which the C routine below will need
950 lwz r5,savesrr0+4(r4) ; Get interrupt address
951 stw r5,FM_LR_SAVE(r1) ; save old instr ptr as LR value
952 stwu r1,-FM_SIZE(r1) ; Make another new frame for C routine
959 addi r4,r13,SYSTEM_TIMER
964 lwz r5,savedsisr(r30) ; Get the DSISR
965 lwz r6,savedar+4(r30) ; Get the DAR
968 stfd f31,emfp31(r25) ; (TEST/DEBUG)
974 /* interrupt() returns a pointer to the saved state in r3
976 * Ok, back from C. Disable interrupts while we restore things
978 .globl EXT(ihandler_ret)
980 LEXT(ihandler_ret) ; Marks our return point from debugger entry
982 lis r10,hi16(MASK(MSR_VEC)) ; Get the vector enable
983 mfmsr r0 ; Get our MSR
984 ori r10,r10,lo16(MASK(MSR_FP)|MASK(MSR_EE)) ; Add in FP and EE
985 andc r0,r0,r10 ; Turn off VEC, FP, and EE
986 mtmsr r0 ; Make sure interrupts are disabled
987 mfsprg r8,1 ; Get the current activation
988 lwz r10,ACT_PER_PROC(r8) ; Get the per_proc block
990 lwz r7,SAVflags(r3) ; Pick up the flags
991 lwz r9,SAVprev+4(r3) ; Get previous save area
992 cmplwi cr1,r8,0 ; Are we still initializing?
993 lwz r12,savesrr1+4(r3) ; Get the MSR we will load on return
994 andis. r11,r7,hi16(SAVrststk) ; Is this the first on the stack?
995 stw r9,ACT_MACT_PCB(r8) ; Point to previous context savearea
996 mr r4,r3 ; Move the savearea pointer
997 beq .L_no_int_ast2 ; Get going if not the top-o-stack...
1000 /* We're the last frame on the stack. Restore istackptr to empty state.
1002 * Check for ASTs if one of the below is true:
1003 * returning to user mode
1004 * returning to a kloaded server
1006 lwz r9,PP_INTSTACK_TOP_SS(r10) ; Get the empty stack value
1007 andc r7,r7,r11 ; Remove the stack reset bit in case we pass this one
1008 stw r9,PP_ISTACKPTR(r10) ; Save that saved state ptr
1009 lwz r3,ACT_PREEMPT_CNT(r8) ; Get preemption level
1010 stw r7,SAVflags(r4) ; Save the flags
1011 cmplwi r3, 0 ; Check for preemption
1012 bne .L_no_int_ast ; Do not preempt if level is not zero
1013 andi. r6,r12,MASK(MSR_PR) ; privilege mode
1014 lwz r11,PP_PENDING_AST(r10) ; Get the pending AST mask
1015 beq- .L_kernel_int_ast ; In kernel space, AST_URGENT check
1016 li r3,T_AST ; Assume the worst
1017 mr. r11,r11 ; Are there any pending?
1018 beq .L_no_int_ast ; Nope...
1022 andi. r11,r11,AST_URGENT ; Do we have AST_URGENT?
1023 li r3,T_PREEMPT ; Assume the worst
1024 beq .L_no_int_ast ; Nope...
1027 * There is a pending AST. Massage things to make it look like
1028 * we took a trap and jump into the trap handler. To do this
1029 * we essentially pretend to return from the interrupt but
1030 * at the last minute jump into the trap handler with an AST
1031 * trap instead of performing an rfi.
1035 stw r3,saveexception(r4) ; Set the exception code to T_AST/T_PREEMPT
1036 b EXT(thandler) ; We need to preempt so treat like a trap...
1039 mr r3,r4 ; Get into the right register for common code
1042 rlwinm r7,r7,0,15,13 ; Clear the syscall flag
1043 li r4,0 ; Assume for a moment that we are in init
1044 stw r7,SAVflags(r3) ; Set the flags with cleared syscall flag
1045 beq-- cr1,chkfac ; Jump away if we are in init...
1047 lwz r4,ACT_MACT_PCB(r8) ; Get the new level marker
1051 ; This section is common to all exception exits. It throws away vector
1052 ; and floating point saveareas as the exception level of a thread is
1055 ; It also enables the facility if its context is live
1057 ; R3 = Savearea to be released (virtual)
1058 ; R4 = New top of savearea stack (could be 0)
1059 ; R8 = pointer to activation
1060 ; R10 = per_proc block
1062 ; Note that barring unforseen crashes, there is no escape from this point
1063 ; on. We WILL call exception_exit and launch this context. No worries
1064 ; about preemption or interruptions here.
1066 ; Note that we will set up R26 with whatever context we will be launching,
1067 ; so it will indicate the current, or the deferred it it is set and we
1068 ; are going to user state. CR2_eq will be set to indicate deferred.
1071 chkfac: lwz r29,savesrr1+4(r3) ; Get the current MSR
1072 mr. r28,r8 ; Are we still in boot?
1073 mr r31,r10 ; Move per_proc address
1074 mr r30,r4 ; Preserve new level
1075 mr r27,r3 ; Save the old level
1076 beq-- chkenax ; Yeah, skip it all...
1078 rlwinm. r0,r29,0,MSR_PR_BIT,MSR_PR_BIT ; Are we going into user state?
1080 lwz r20,curctx(r28) ; Get our current context
1081 lwz r26,deferctx(r28) ; Get any deferred context switch
1082 li r0,1 ; Get set to hold off quickfret
1083 rlwinm r29,r29,0,MSR_FP_BIT+1,MSR_FP_BIT-1 ; Turn off floating point for now
1084 lwz r21,FPUlevel(r20) ; Get the facility level
1085 cmplwi cr2,r26,0 ; Are we going into a deferred context later?
1086 rlwinm r29,r29,0,MSR_VEC_BIT+1,MSR_VEC_BIT-1 ; Turn off vector for now
1087 crnor cr2_eq,cr0_eq,cr2_eq ; Set cr2_eq if going to user state and there is deferred
1088 lhz r19,PP_CPU_NUMBER(r31) ; Get our CPU number
1089 cmplw r27,r21 ; Are we returning from the active level?
1090 stw r0,holdQFret(r31) ; Make sure we hold off releasing quickfret
1091 bne++ fpuchkena ; Nope...
1094 ; First clean up any live context we are returning from
1097 lwz r22,FPUcpu(r20) ; Get CPU this context was last dispatched on
1099 stw r19,FPUcpu(r20) ; Claim context for us
1101 eieio ; Make sure this gets out before owner clear
1104 #error per_proc_entry is not 16bytes in size
1107 lis r23,hi16(EXT(PerProcTable)) ; Set base PerProcTable
1108 slwi r22,r22,4 ; Find offset to the owner per_proc_entry
1109 ori r23,r23,lo16(EXT(PerProcTable)) ; Set base PerProcTable
1110 li r24,FPUowner ; Displacement to float owner
1111 add r22,r23,r22 ; Point to the owner per_proc_entry
1112 lwz r22,ppe_vaddr(r22) ; Point to the owner per_proc
1114 fpuinvothr: lwarx r23,r24,r22 ; Get the owner
1116 sub r0,r23,r20 ; Subtract one from the other
1117 sub r21,r20,r23 ; Subtract the other from the one
1118 or r21,r21,r0 ; Combine them
1119 srawi r21,r21,31 ; Get a 0 if equal or -1 of not
1120 and r23,r23,r21 ; Make 0 if same, unchanged if not
1121 stwcx. r23,r24,r22 ; Try to invalidate it
1122 bne-- fpuinvothr ; Try again if there was a collision...
1127 ; Now if there is a savearea associated with the popped context, release it.
1128 ; Either way, pop the level to the top stacked context.
1131 lwz r22,FPUsave(r20) ; Get pointer to the first savearea
1132 li r21,0 ; Assume we popped all the way out
1133 mr. r22,r22 ; Is there anything there?
1134 beq++ fpusetlvl ; No, see if we need to enable...
1136 lwz r21,SAVlevel(r22) ; Get the level of that savearea
1137 cmplw r21,r27 ; Is this the saved copy of the live stuff?
1138 bne fpusetlvl ; No, leave as is...
1140 lwz r24,SAVprev+4(r22) ; Pick up the previous area
1141 li r21,0 ; Assume we popped all the way out
1142 mr. r24,r24 ; Any more context stacked?
1143 beq-- fpuonlyone ; Nope...
1144 lwz r21,SAVlevel(r24) ; Get the level associated with save
1146 fpuonlyone: stw r24,FPUsave(r20) ; Dequeue this savearea
1148 rlwinm r3,r22,0,0,19 ; Find main savearea header
1150 lwz r8,quickfret(r31) ; Get the first in quickfret list (top)
1151 lwz r9,quickfret+4(r31) ; Get the first in quickfret list (bottom)
1152 lwz r2,SACvrswap(r3) ; Get the virtual to real conversion (top)
1153 lwz r3,SACvrswap+4(r3) ; Get the virtual to real conversion (bottom)
1154 stw r8,SAVprev(r22) ; Link the old in (top)
1155 stw r9,SAVprev+4(r22) ; Link the old in (bottom)
1156 xor r3,r22,r3 ; Convert to physical
1157 stw r2,quickfret(r31) ; Set the first in quickfret list (top)
1158 stw r3,quickfret+4(r31) ; Set the first in quickfret list (bottom)
1161 lis r0,HIGH_ADDR(CutTrace) ; (TEST/DEBUG)
1162 li r2,0x3301 ; (TEST/DEBUG)
1163 oris r0,r0,LOW_ADDR(CutTrace) ; (TEST/DEBUG)
1167 fpusetlvl: stw r21,FPUlevel(r20) ; Save the level
1170 ; Here we check if we are at the right level
1171 ; We need to check the level we are entering, not the one we are exiting.
1172 ; Therefore, we will use the defer level if it is non-zero and we are
1173 ; going into user state.
1176 fpuchkena: bt-- cr2_eq,fpuhasdfrd ; Skip if deferred, R26 already set up...
1177 mr r26,r20 ; Use the non-deferred value
1181 rlwinm. r0,r29,0,MSR_PR_BIT,MSR_PR_BIT ; (TEST/DEBUG) Going into user state?
1182 beq fpunusrstt ; (TEST/DEBUG) Nope...
1183 lwz r23,FPUlevel(r26) ; (TEST/DEBUG) Get the level ID
1184 lwz r24,FPUsave(r26) ; (TEST/DEBUG) Get the first savearea
1185 mr. r23,r23 ; (TEST/DEBUG) Should be level 0
1186 beq++ fpulvl0 ; (TEST/DEBUG) Yes...
1188 lis r0,hi16(Choke) ; (TEST/DEBUG) Choke code
1189 ori r0,r0,lo16(Choke) ; (TEST/DEBUG) and the rest
1190 sc ; (TEST/DEBUG) System ABEND
1192 fpulvl0: mr. r24,r24 ; (TEST/DEBUG) Any context?
1193 beq fpunusrstt ; (TEST/DEBUG) No...
1194 lwz r23,SAVlevel(r24) ; (TEST/DEBUG) Get level of context
1195 lwz r21,SAVprev+4(r24) ; (TEST/DEBUG) Get previous pointer
1196 mr. r23,r23 ; (TEST/DEBUG) Is this our user context?
1197 beq++ fpulvl0b ; (TEST/DEBUG) Yes...
1199 lis r0,hi16(Choke) ; (TEST/DEBUG) Choke code
1200 ori r0,r0,lo16(Choke) ; (TEST/DEBUG) and the rest
1201 sc ; (TEST/DEBUG) System ABEND
1203 fpulvl0b: mr. r21,r21 ; (TEST/DEBUG) Is there a forward chain?
1204 beq++ fpunusrstt ; (TEST/DEBUG) Nope...
1206 lis r0,hi16(Choke) ; (TEST/DEBUG) Choke code
1207 ori r0,r0,lo16(Choke) ; (TEST/DEBUG) and the rest
1208 sc ; (TEST/DEBUG) System ABEND
1210 fpunusrstt: ; (TEST/DEBUG)
1213 lwz r21,FPUowner(r31) ; Get the ID of the live context
1214 lwz r23,FPUlevel(r26) ; Get the level ID
1215 lwz r24,FPUcpu(r26) ; Get the CPU that the context was last dispatched on
1216 cmplw cr3,r26,r21 ; Do we have the live context?
1217 cmplw r30,r23 ; Are we about to launch the live level?
1218 bne-- cr3,chkvec ; No, can not possibly enable...
1219 cmplw cr1,r19,r24 ; Was facility used on this processor last?
1220 bne-- chkvec ; No, not live...
1221 bne-- cr1,chkvec ; No, wrong cpu, have to enable later....
1223 lwz r24,FPUsave(r26) ; Get the first savearea
1224 mr. r24,r24 ; Any savearea?
1225 beq++ fpuena ; Nope...
1226 lwz r25,SAVlevel(r24) ; Get the level of savearea
1227 lwz r0,SAVprev+4(r24) ; Get the previous
1229 cmplw r30,r25 ; Is savearea for the level we are launching?
1230 bne++ fpuena ; No, just go enable...
1232 stw r0,FPUsave(r26) ; Pop the chain
1234 rlwinm r3,r24,0,0,19 ; Find main savearea header
1236 lwz r8,quickfret(r31) ; Get the first in quickfret list (top)
1237 lwz r9,quickfret+4(r31) ; Get the first in quickfret list (bottom)
1238 lwz r2,SACvrswap(r3) ; Get the virtual to real conversion (top)
1239 lwz r3,SACvrswap+4(r3) ; Get the virtual to real conversion (bottom)
1240 stw r8,SAVprev(r24) ; Link the old in (top)
1241 stw r9,SAVprev+4(r24) ; Link the old in (bottom)
1242 xor r3,r24,r3 ; Convert to physical
1243 stw r2,quickfret(r31) ; Set the first in quickfret list (top)
1244 stw r3,quickfret+4(r31) ; Set the first in quickfret list (bottom)
1247 lis r0,HIGH_ADDR(CutTrace) ; (TEST/DEBUG)
1248 li r2,0x3302 ; (TEST/DEBUG)
1249 oris r0,r0,LOW_ADDR(CutTrace) ; (TEST/DEBUG)
1253 fpuena: ori r29,r29,lo16(MASK(MSR_FP)) ; Enable facility
1257 lwz r21,VMXlevel(r20) ; Get the facility level
1259 cmplw r27,r21 ; Are we returning from the active level?
1260 bne+ vmxchkena ; Nope...
1264 ; First clean up any live context we are returning from
1267 lwz r22,VMXcpu(r20) ; Get CPU this context was last dispatched on
1269 stw r19,VMXcpu(r20) ; Claim context for us
1271 eieio ; Make sure this gets out before owner clear
1273 lis r23,hi16(EXT(PerProcTable)) ; Set base PerProcTable
1274 slwi r22,r22,4 ; Find offset to the owner per_proc_entry
1275 ori r23,r23,lo16(EXT(PerProcTable)) ; Set base PerProcTable
1276 li r24,VMXowner ; Displacement to float owner
1277 add r22,r23,r22 ; Point to the owner per_proc_entry
1278 lwz r22,ppe_vaddr(r22) ; Point to the owner per_proc
1280 vmxinvothr: lwarx r23,r24,r22 ; Get the owner
1282 sub r0,r23,r20 ; Subtract one from the other
1283 sub r21,r20,r23 ; Subtract the other from the one
1284 or r21,r21,r0 ; Combine them
1285 srawi r21,r21,31 ; Get a 0 if equal or -1 of not
1286 and r23,r23,r21 ; Make 0 if same, unchanged if not
1287 stwcx. r23,r24,r22 ; Try to invalidate it
1288 bne-- vmxinvothr ; Try again if there was a collision...
1293 ; Now if there is a savearea associated with the popped context, release it.
1294 ; Either way, pop the level to the top stacked context.
1297 lwz r22,VMXsave(r20) ; Get pointer to the first savearea
1298 li r21,0 ; Assume we popped all the way out
1299 mr. r22,r22 ; Is there anything there?
1300 beq++ vmxsetlvl ; No, see if we need to enable...
1302 lwz r21,SAVlevel(r22) ; Get the level of that savearea
1303 cmplw r21,r27 ; Is this the saved copy of the live stuff?
1304 bne vmxsetlvl ; No, leave as is...
1306 lwz r24,SAVprev+4(r22) ; Pick up the previous area
1307 li r21,0 ; Assume we popped all the way out
1308 mr. r24,r24 ; Any more context?
1309 beq-- vmxonlyone ; Nope...
1310 lwz r21,SAVlevel(r24) ; Get the level associated with save
1312 vmxonlyone: stw r24,VMXsave(r20) ; Dequeue this savearea
1314 rlwinm r3,r22,0,0,19 ; Find main savearea header
1316 lwz r8,quickfret(r31) ; Get the first in quickfret list (top)
1317 lwz r9,quickfret+4(r31) ; Get the first in quickfret list (bottom)
1318 lwz r2,SACvrswap(r3) ; Get the virtual to real conversion (top)
1319 lwz r3,SACvrswap+4(r3) ; Get the virtual to real conversion (bottom)
1320 stw r8,SAVprev(r22) ; Link the old in (top)
1321 stw r9,SAVprev+4(r22) ; Link the old in (bottom)
1322 xor r3,r22,r3 ; Convert to physical
1323 stw r2,quickfret(r31) ; Set the first in quickfret list (top)
1324 stw r3,quickfret+4(r31) ; Set the first in quickfret list (bottom)
1327 lis r0,HIGH_ADDR(CutTrace) ; (TEST/DEBUG)
1328 li r2,0x3401 ; (TEST/DEBUG)
1329 oris r0,r0,LOW_ADDR(CutTrace) ; (TEST/DEBUG)
1333 vmxsetlvl: stw r21,VMXlevel(r20) ; Save the level
1336 ; Here we check if we are at the right level
1339 vmxchkena: lwz r21,VMXowner(r31) ; Get the ID of the live context
1340 lwz r23,VMXlevel(r26) ; Get the level ID
1341 cmplw r26,r21 ; Do we have the live context?
1342 lwz r24,VMXcpu(r26) ; Get the CPU that the context was last dispatched on
1343 bne-- setena ; No, can not possibly enable...
1344 cmplw r30,r23 ; Are we about to launch the live level?
1345 cmplw cr1,r19,r24 ; Was facility used on this processor last?
1346 bne-- setena ; No, not live...
1347 bne-- cr1,setena ; No, wrong cpu, have to enable later....
1349 lwz r24,VMXsave(r26) ; Get the first savearea
1350 mr. r24,r24 ; Any savearea?
1351 beq++ vmxena ; Nope...
1352 lwz r25,SAVlevel(r24) ; Get the level of savearea
1353 lwz r0,SAVprev+4(r24) ; Get the previous
1354 cmplw r30,r25 ; Is savearea for the level we are launching?
1355 bne++ vmxena ; No, just go enable...
1357 stw r0,VMXsave(r26) ; Pop the chain
1359 rlwinm r3,r24,0,0,19 ; Find main savearea header
1361 lwz r8,quickfret(r31) ; Get the first in quickfret list (top)
1362 lwz r9,quickfret+4(r31) ; Get the first in quickfret list (bottom)
1363 lwz r2,SACvrswap(r3) ; Get the virtual to real conversion (top)
1364 lwz r3,SACvrswap+4(r3) ; Get the virtual to real conversion (bottom)
1365 stw r8,SAVprev(r24) ; Link the old in (top)
1366 stw r9,SAVprev+4(r24) ; Link the old in (bottom)
1367 xor r3,r24,r3 ; Convert to physical
1368 stw r2,quickfret(r31) ; Set the first in quickfret list (top)
1369 stw r3,quickfret+4(r31) ; Set the first in quickfret list (bottom)
1372 lis r0,HIGH_ADDR(CutTrace) ; (TEST/DEBUG)
1373 li r2,0x3402 ; (TEST/DEBUG)
1374 oris r0,r0,LOW_ADDR(CutTrace) ; (TEST/DEBUG)
1378 vmxena: oris r29,r29,hi16(MASK(MSR_VEC)) ; Enable facility
1380 setena: lwz r18,umwSpace(r28) ; Get the space ID in case we are launching user
1381 rlwinm. r0,r29,0,MSR_PR_BIT,MSR_PR_BIT ; Are we about to launch user state?
1382 li r0,0 ; Get set to release quickfret holdoff
1383 crmove cr7_eq,cr0_eq ; Remember if we are going to user state
1384 rlwimi. r20,r29,(((31-floatCngbit)+(MSR_FP_BIT+1))&31),floatCngbit,floatCngbit ; Set flag if we enabled floats
1385 lwz r19,deferctx(r28) ; Get any deferred facility context switch
1386 rlwinm r20,r29,(((31-vectorCngbit)+(MSR_VEC_BIT+1))&31),vectorCngbit,vectorCngbit ; Set flag if we enabled vector
1387 stw r29,savesrr1+4(r27) ; Turn facility on or off
1388 stw r0,holdQFret(r31) ; Release quickfret
1389 oris r18,r18,hi16(umwSwitchAway) ; Set the switch-away bit in case we go to user
1391 beq setenaa ; Neither float nor vector turned on....
1393 lwz r5,ACT_MACT_SPF(r28) ; Get activation copy
1394 lwz r6,spcFlags(r31) ; Get per_proc copy
1395 or r5,r5,r20 ; Set vector/float changed bits in activation
1396 or r6,r6,r20 ; Set vector/float changed bits in per_proc
1397 stw r5,ACT_MACT_SPF(r28) ; Set activation copy
1398 stw r6,spcFlags(r31) ; Set per_proc copy
1400 setenaa: mfdec r24 ; Get decrementer
1401 bf+ cr2_eq,nodefer ; No deferred to switch to...
1403 li r20,0 ; Clear this
1404 stw r26,curctx(r28) ; Make the facility context current
1405 stw r20,deferctx(r28) ; Clear deferred context
1407 nodefer: lwz r22,qactTimer(r28) ; Get high order quick activation timer
1408 mr. r24,r24 ; See if it has popped already...
1409 lwz r23,qactTimer+4(r28) ; Get low order qact timer
1410 ble- chkifuser ; We have popped or are just about to...
1412 segtb: mftbu r20 ; Get the upper time base
1413 mftb r21 ; Get the low
1414 mftbu r19 ; Get upper again
1415 or. r0,r22,r23 ; Any time set?
1416 cmplw cr1,r20,r19 ; Did they change?
1417 beq++ chkifuser ; No time set....
1418 bne-- cr1,segtb ; Timebase ticked, get them again...
1420 subfc r6,r21,r23 ; Subtract current from qact time
1422 subfe r5,r20,r22 ; Finish subtract
1423 subfze r0,r0 ; Get a 0 if qact was bigger than current, -1 otherwise
1424 andc. r12,r5,r0 ; Set 0 if qact has passed
1425 andc r13,r6,r0 ; Set 0 if qact has passed
1426 bne chkifuser ; If high order is non-zero, this is too big for a decrementer
1427 cmplw r13,r24 ; Is this earlier than the decrementer? (logical compare takes care of high bit on)
1428 bge++ chkifuser ; No, do not reset decrementer...
1430 mtdec r13 ; Set our value
1432 chkifuser: addi r4,r28,SYSTEM_TIMER
1434 beq-- cr7,chkifuser1 ; Skip this if we are going to kernel...
1435 stw r18,umwSpace(r28) ; Half-invalidate to force MapUserAddressWindow to reload SRs
1436 addi r4,r28,USER_TIMER
1438 chkifuser1: bl EXT(timer_event)
1443 lwz r20,SAVact(r27) ; (TEST/DEBUG) Make sure our restore
1444 mfsprg r21, 1 ; (TEST/DEBUG) with the current act.
1445 cmpwi r21,0 ; (TEST/DEBUG)
1446 beq-- yeswereok ; (TEST/DEBUG)
1447 cmplw r21,r20 ; (TEST/DEBUG)
1448 beq++ yeswereok ; (TEST/DEBUG)
1450 lis r0,hi16(Choke) ; (TEST/DEBUG) Choke code
1451 ori r0,r0,lo16(Choke) ; (TEST/DEBUG) and the rest
1452 mr r21,r27 ; (TEST/DEBUG) Save the savearea address
1453 li r3,failContext ; (TEST/DEBUG) Bad state code
1454 sc ; (TEST/DEBUG) System ABEND
1459 mr r3,r27 ; Pass savearea back
1460 b EXT(exception_exit) ; We are all done now...
1465 ; Null PPC call - performance testing, does absolutely nothing
1474 li r3,-1 ; Make sure we test no asts
1479 ; Instrumented null PPC call - performance testing, does absolutely nothing
1480 ; Forces various timestamps to be returned.
1485 .globl EXT(ppcNullinst)
1489 li r3,-1 ; Make sure we test no asts
1494 * Here's where we handle the fastpath stuff
1495 * We'll do what we can here because registers are already
1496 * loaded and it will be less confusing that moving them around.
1497 * If we need to though, we'll branch off somewhere's else.
1499 * Registers when we get here:
1501 * r0 = syscall number
1504 * r14 = previous savearea (if any)
1511 fastpath: cmplwi cr3,r0,0x7FF5 ; Is this a null fastpath?
1512 beq-- cr3,fastexutl ; Yes, bail fast...
1513 cmplwi cr3,r0,0x7FF1 ; Is it CthreadSetSelfNumber?
1514 bnelr-- cr3 ; Not a fast path...
1517 * void cthread_set_self(cproc_t p)
1519 * Set's thread state "user_value". In practice this is the thread-local-data-pointer (TLDP),
1520 * though we do not interpret it. This call is mostly used by 32-bit tasks, but we save all 64 bits
1521 * in case a 64-bit task wants to use this facility. They normally do not, because the 64-bit
1522 * ABI reserves r13 for the TLDP.
1524 * This op is invoked as follows:
1525 * li r0, CthreadSetSelfNumber // load the fast-trap number
1526 * sc // invoke fast-trap
1530 CthreadSetSelfNumber:
1531 lwz r3,saver3+0(r4) /* get the TLDP passed in r3 */
1532 lwz r5,saver3+4(r4) /* (all 64 bits, in case this is a 64-bit task) */
1533 stw r3,CTHREAD_SELF+0(r13) /* Remember it in the activation... */
1534 stw r5,CTHREAD_SELF+4(r13)
1535 stw r3,UAW+0(r25) /* ...and in the per-proc */
1539 .globl EXT(fastexit)
1541 fastexutl: mr r3,r4 ; Pass back savearea
1542 b EXT(exception_exit) ; Go back to the caller...
1546 * Here's where we check for a hit on the Blue Box Assist
1547 * Most registers are non-volatile, so be careful here. If we don't
1548 * recognize the trap instruction we go back for regular processing.
1549 * Otherwise we transfer to the assist code.
1555 lwz r0,saveexception(r4) ; Get the exception code
1556 lwz r23,savesrr1+4(r4) ; Get the interrupted MSR
1557 lwz r26,ACT_MACT_BEDA(r13) ; Get Blue Box Descriptor Area
1558 mtcrf 0x18,r23 ; Check what SRR1 says
1559 lwz r24,ACT_MACT_BTS(r13) ; Get the table start
1560 cmplwi r0,T_AST ; Check for T_AST trap
1561 lwz r27,savesrr0+4(r4) ; Get trapped address
1562 crnand cr1_eq,SRR1_PRG_TRAP_BIT,MSR_PR_BIT ; We need both trap and user state
1563 sub r24,r27,r24 ; See how far into it we are
1564 cror cr0_eq,cr0_eq,cr1_eq ; Need to bail if AST or not trap or not user state
1565 cmplwi cr1,r24,BB_MAX_TRAP ; Do we fit in the list?
1566 cror cr0_eq,cr0_eq,cr1_gt ; Also leave it trap not in range
1567 btlr- cr0_eq ; No assist if AST or not trap or not user state or trap not in range
1568 b EXT(atomic_switch_trap) ; Go to the assist...
1571 ; Virtual Machine Monitor
1572 ; Here is where we exit from the emulated context
1573 ; Note that most registers get trashed here
1574 ; R3 and R30 are preserved across the call and hold the activation
1575 ; and savearea respectivily.
1580 exitFromVM: mr r30,r4 ; Get the savearea
1581 mr r3,r13 ; Get the activation
1583 b EXT(vmm_exit) ; Do it to it
1586 .globl EXT(retFromVM)
1589 mfsprg r10,1 ; Get the current activation
1590 lwz r10,ACT_PER_PROC(r10) ; Get the per_proc block
1591 mr r8,r3 ; Get the activation
1592 lwz r4,SAVprev+4(r30) ; Pick up the previous savearea
1593 mr r3,r30 ; Put savearea in proper register for common code
1594 lwz r11,SAVflags(r30) ; Get the flags of the current savearea
1595 rlwinm r11,r11,0,15,13 ; Clear the syscall flag
1597 stw r11,SAVflags(r3) ; Save back the flags (with reset stack cleared)
1599 stw r4,ACT_MACT_PCB(r8) ; Point to the previous savearea (or 0 if none)
1601 lwz r5,THREAD_KERNEL_STACK(r1) ; Get the base pointer to the stack
1602 addi r5,r5,KERNEL_STACK_SIZE-FM_SIZE ; Reset to empty
1603 stw r5,ACT_MACT_KSP(r8) ; Save the empty stack pointer
1604 b chkfac ; Go end it all...
1608 ; chandler (note: not a candle maker or tallow merchant)
1610 ; Here is the system choke handler. This is where the system goes
1613 ; We get here as a result of a T_CHOKE exception which is generated
1614 ; by the Choke firmware call or by lowmem_vectors when it detects a
1615 ; fatal error. Examples of where this may be used is when we detect
1616 ; problems in low-level mapping chains, trashed savearea free chains,
1617 ; or stack guardpage violations.
1619 ; Note that we can not set a back chain in the stack when we come
1620 ; here because we are probably here because the chain was corrupt.
1625 .globl EXT(chandler)
1626 LEXT(chandler) ; Choke handler
1629 mfsprg r25,1 ; Get the current activation
1630 lwz r25,ACT_PER_PROC(r25) ; Get the per_proc block
1631 stw r31,traceMask(0) ; Force tracing off right now
1635 lwz r1,PP_DEBSTACKPTR(r25) ; Get debug stack pointer
1636 cmpwi r1,-1 ; Are we already choking?
1637 bne chokefirst ; Nope...
1639 chokespin: addi r31,r31,1 ; Spin and hope for an analyzer connection...
1640 addi r31,r31,1 ; Spin and hope for an analyzer connection...
1641 addi r31,r31,1 ; Spin and hope for an analyzer connection...
1642 addi r31,r31,1 ; Spin and hope for an analyzer connection...
1643 addi r31,r31,1 ; Spin and hope for an analyzer connection...
1644 addi r31,r31,1 ; Spin and hope for an analyzer connection...
1645 b chokespin ; Spin and hope for an analyzer connection...
1647 chokefirst: li r0,-1 ; Set choke value
1648 mr. r1,r1 ; See if we are on debug stack yet
1649 lwz r10,saver1+4(r4) ;
1650 stw r0,PP_DEBSTACKPTR(r25) ; Show we are choking
1651 bne chokestart ; We are not on the debug stack yet...
1653 lwz r2,PP_DEBSTACK_TOP_SS(r25) ; Get debug stack top
1654 sub r11,r2,r10 ; Get stack depth
1656 cmplwi r11,KERNEL_STACK_SIZE-FM_SIZE-TRAP_SPACE_NEEDED ; Check if stack pointer is ok
1657 bgt chokespin ; Bad stack pointer or too little left, just die...
1659 subi r1,r10,FM_REDZONE ; Make a red zone
1661 chokestart: li r0,0 ; Get a zero
1662 stw r0,FM_BACKPTR(r1) ; We now have terminated the back chain
1664 bl EXT(SysChoked) ; Call the "C" phase of this
1665 b chokespin ; Should not be here so just go spin...
1670 ; Savearea chain verification
1675 lis r22,hi16(EXT(DebugWork)) ; (TEST/DEBUG)
1676 ori r22,r22,lo16(EXT(DebugWork)) ; (TEST/DEBUG)
1677 lwz r23,0(r22) ; (TEST/DEBUG)
1678 mr. r23,r23 ; (TEST/DEBUG)
1679 beqlr- ; (TEST/DEBUG)
1680 mfsprg r20,1 ; Get the current activation
1681 lwz r20,ACT_PER_PROC(r20) ; Get the per_proc block
1682 lwz r21,pfAvailable(r20) ; (TEST/DEBUG)
1683 mr. r21,r21 ; (TEST/DEBUG)
1684 bnelr+ ; (TEST/DEBUG)
1686 stw r22,0(r22) ; (TEST/DEBUG) Lock out more checks
1687 BREAKPOINT_TRAP ; (TEST/DEBUG) Get into debugger
1691 ;; This code is broken and migration will make the matter even worse
1693 ; Make sure that all savearea chains have the right type on them
1696 lis r28,hi16(EXT(default_pset)) ; (TEST/DEBUG)
1697 lis r27,hi16(EXT(DebugWork)) ; (TEST/DEBUG)
1698 ori r28,r28,lo16(EXT(default_pset)) ; (TEST/DEBUG)
1699 ori r27,r27,lo16(EXT(DebugWork)) ; (TEST/DEBUG)
1700 li r20,0 ; (TEST/DEBUG)
1701 lwz r26,0(r27) ; (TEST/DEBUG)
1702 lwz r27,psthreadcnt(r28) ; (TEST/DEBUG)
1703 mr. r26,r26 ; (TEST/DEBUG) Have we locked the test out?
1704 lwz r28,psthreads(r28) ; (TEST/DEBUG)
1705 mflr r31 ; (TEST/DEBUG) Save return
1706 bnelr- ; (TEST/DEBUG) Test already triggered, skip...
1707 b fckgo ; (TEST/DEBUG) Join up...
1709 fcknext: mr. r27,r27 ; (TEST/DEBUG) Any more threads?
1710 bne+ fckxxx ; (TEST/DEBUG) Yes...
1712 mtlr r31 ; (TEST/DEBUG) Restore return
1713 blr ; (TEST/DEBUG) Leave...
1715 fckxxx: lwz r28,THREAD_PSTHRN(r28) ; (TEST/DEBUG) Get next thread
1717 fckgo: subi r27,r27,1 ; (TEST/DEBUG) Decrement thread count
1718 lwz r24,THREAD_TOP_ACT(r28) ; (TEST/DEBUG) Get activation for the thread
1719 lwz r20,ACT_MACT_PCB(r24) ; (TEST/DEBUG) Get the normal context
1720 li r21,SAVgeneral ; (TEST/DEBUG) Make sure this is all general context
1721 bl versavetype ; (TEST/DEBUG) Check the chain
1723 lwz r20,facctx+FPUsave(r24) ; (TEST/DEBUG) Get regular floating point
1724 li r21,SAVfloat ; (TEST/DEBUG) Make sure this is all floating point
1725 bl versavetype ; (TEST/DEBUG) Check the chain
1727 lwz r20,facctx+VMXsave(r24) ; (TEST/DEBUG) Get regular vector point
1728 li r21,SAVvector ; (TEST/DEBUG) Make sure this is all vector
1729 bl versavetype ; (TEST/DEBUG) Check the chain
1731 lwz r29,vmmControl(r24) ; (TEST/DEBUG) Get the virtual machine control blocks
1732 mr. r29,r29 ; (TEST/DEBUG) Are there any?
1733 beq+ fcknext ; (TEST/DEBUG) Nope, next thread...
1735 li r22,kVmmMaxContextsPerThread ; (TEST/DEBUG) Get the number of control blocks
1736 subi r29,r29,vmmCEntrySize ; (TEST/DEBUG) Get running start
1738 fcknvmm: subi r22,r22,1 ; (TEST/DEBUG) Do all of them
1739 mr. r22,r22 ; (TEST/DEBUG) Are we all done?
1740 addi r29,r29,vmmCEntrySize ; (TEST/DEBUG) Get the next entry
1741 blt- fcknext ; (TEST/DEBUG) Yes, check next thread...
1743 lwz r23,vmmFlags(r29) ; (TEST/DEBUG) Get entry flags
1744 rlwinm. r23,r23,0,0,0 ; (TEST/DEBUG) Is this in use?
1745 beq+ fcknvmm ; (TEST/DEBUG) Not in use...
1747 lwz r20,vmmFacCtx+FPUsave(r29) ; (TEST/DEBUG) Get regular floating point
1748 li r21,SAVfloat ; (TEST/DEBUG) Make sure this is all floating point
1749 bl versavetype ; (TEST/DEBUG) Check the chain
1751 lwz r20,vmmFacCtx+VMXsave(r29) ; (TEST/DEBUG) Get regular vector point
1752 li r21,SAVvector ; (TEST/DEBUG) Make sure this is all vector
1753 bl versavetype ; (TEST/DEBUG) Check the chain
1754 b fcknvmm ; (TEST/DEBUG) Get then vmm block...
1757 mr. r20,r20 ; (TEST/DEBUG) Chain done?
1758 beqlr- ; (TEST/DEBUG) Yes...
1760 lwz r23,SAVflags(r20) ; (TEST/DEBUG) Get the flags
1761 rlwinm r23,r23,24,24,31 ; (TEST/DEBUG) Position it
1762 cmplw r23,r21 ; (TEST/DEBUG) Are we the correct type?
1763 beq+ versvok ; (TEST/DEBUG) This one is ok...
1765 lis r22,hi16(EXT(DebugWork)) ; (TEST/DEBUG)
1766 ori r22,r22,lo16(EXT(DebugWork)) ; (TEST/DEBUG)
1767 stw r22,0(r22) ; (TEST/DEBUG) Lock out more checks
1768 BREAKPOINT_TRAP ; (TEST/DEBUG) Get into debugger
1770 versvok: lwz r20,SAVprev+4(r20) ; (TEST/DEBUG) Get the previous one
1771 b versavetype ; (TEST/DEBUG) Go check its type...