2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
26 /* Low level routines dealing with exception entry and exit.
27 * There are various types of exception:
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).
33 * The code for the FPU disabled handler (lazy fpu) is in cswtch.s
37 #include <mach_assert.h>
38 #include <mach/exception_types.h>
39 #include <mach/ppc/vm_param.h>
44 #include <ppc/proc_reg.h>
46 #include <ppc/exception.h>
47 #include <ppc/savearea.h>
57 * ENTRY: VM switched ON
59 * R3 contains exception code
60 * R4 points to the saved context (virtual address)
61 * Everything is saved in savearea
65 * If pcb.ksp == 0 then the kernel stack is already busy,
66 * we make a stack frame
67 * leaving enough space for the 'red zone' in case the
68 * trapped thread was in the middle of saving state below
71 * otherwise we make a stack frame and
72 * the kernel stack (setting pcb.ksp to 0)
74 * on return, we do the reverse, the last state is popped from the pcb
75 * and pcb.ksp is set to the top of stack
78 /* TRAP_SPACE_NEEDED is the space assumed free on the kernel stack when
79 * another trap is taken. We need at least enough space for a saved state
80 * structure plus two small backpointer frames, and we add a few
81 * hundred bytes for the space needed by the C (which may be less but
82 * may be much more). We're trying to catch kernel stack overflows :-)
85 #define TRAP_SPACE_NEEDED FM_REDZONE+(2*FM_SIZE)+256
91 LEXT(thandler) ; Trap handler
93 mfsprg r25,0 ; Get the per_proc
95 lwz r1,PP_ISTACKPTR(r25) ; Get interrupt stack pointer
97 cmpwi cr0,r1,0 ; Are we on interrupt stack?
98 lwz r6,PP_ACTIVE_THREAD(r25) ; Get the pointer to the currently active thread
99 beq- cr0,EXT(ihandler) ; If on interrupt stack, treat this as interrupt...
100 lwz r13,THREAD_TOP_ACT(r6) ; Point to the active activation
101 lwz r26,ACT_MACT_SPF(r13) ; Get special flags
102 lwz r8,ACT_MACT_PCB(r13) ; Get the last savearea used
103 rlwinm. r26,r26,0,bbThreadbit,bbThreadbit ; Do we have Blue Box Assist active?
104 lwz r1,ACT_MACT_KSP(r13) ; Get the top of kernel stack
105 bnel- checkassist ; See if we should assist this
106 stw r4,ACT_MACT_PCB(r13) ; Point to our savearea
107 stw r8,SAVprev(r4) ; Queue the new save area in the front
110 bl versave ; (TEST/DEBUG)
113 lwz r9,THREAD_KERNEL_STACK(r6) ; Get our kernel stack start
114 cmpwi cr1,r1,0 ; Are we already on kernel stack?
115 stw r13,SAVact(r4) ; Mark the savearea as belonging to this activation
116 lwz r26,saver1(r4) ; Get the stack at interrupt time
118 bne+ cr1,.L_kstackfree ; We are not on kernel stack yet...
120 subi r1,r26,FM_REDZONE ; Make a red zone on interrupt time kernel stack
123 lwz r7,savesrr1(r4) ; Pick up the entry MSR
124 sub r9,r1,r9 ; Get displacment into the kernel stack
125 li r0,0 ; Make this 0
126 cmplwi cr2,r9,KERNEL_STACK_SIZE ; Do we still have room on the stack?
127 beq cr1,.L_state_on_kstack ; using above test for pcb/stack
129 stw r0,ACT_MACT_KSP(r13) ; Show that we have taken the stack
132 lwz r9,savevrsave(r4) ; Get the VRSAVE register
133 rlwinm. r6,r7,0,MSR_VEC_BIT,MSR_VEC_BIT ; Was vector on?
134 subi r1,r1,FM_SIZE ; Push a header onto the current stack
135 bgt- cr2,kernelStackBad ; Kernel stack is bogus...
137 kernelStackNotBad: ; Vector was off
138 beq+ tvecoff ; Vector off, do not save vrsave...
139 stw r9,liveVRS(r25) ; Set the live value
141 tvecoff: stw r26,FM_BACKPTR(r1) ; Link back to the previous frame
144 /* If debugging, we need two frames, the first being a dummy
145 * which links back to the trapped routine. The second is
146 * that which the C routine below will need
148 lwz r3,savesrr0(r4) ; Get the point of interruption
149 stw r3,FM_LR_SAVE(r1) ; save old instr ptr as LR value
150 stwu r1, -FM_SIZE(r1) ; and make new frame
154 /* call trap handler proper, with
155 * ARG0 = type (not yet, holds pcb ptr)
156 * ARG1 = saved_state ptr (already there)
157 * ARG2 = dsisr (already there)
158 * ARG3 = dar (already there)
162 lwz r3,saveexception(r4) ; Get the exception code
163 lwz r0,ACT_MACT_SPF(r13) ; Get the special flags
165 addi r5,r3,-T_DATA_ACCESS ; Adjust to start of range
166 rlwinm. r0,r0,0,runningVMbit,runningVMbit ; Are we in VM state? (cr0_eq == 0 if yes)
167 cmplwi cr2,r5,T_TRACE-T_DATA_ACCESS ; Are we still in range? (cr_gt if not)
169 lwz r5,savedsisr(r4) ; Get the saved DSISR
171 crnor cr7_eq,cr0_eq,cr2_gt ; We should intercept if in VM and is a true trap (cr7_eq == 1 if yes)
172 rlwinm. r0,r7,0,MSR_PR_BIT,MSR_PR_BIT ; Are we trapping from supervisor state? (cr0_eq == 1 if yes)
174 cmpi cr2,r3,T_PREEMPT ; Is this a preemption?
176 crandc cr0_eq,cr7_eq,cr0_eq ; Do not intercept if we are in the kernel (cr0_eq == 1 if yes)
178 lwz r6,savedar(r4) ; Get the DAR
180 beq- cr2, .L_call_trap ; Do not turn on interrupts for T_PREEMPT
181 beq- exitFromVM ; Any true trap but T_MACHINE_CHECK exits us from the VM...
183 /* syscall exception might warp here if there's nothing left
184 * to do except generate a trap
191 mfmsr r7 ; Get the MSR
192 rlwinm r7,r7,0,MSR_FP_BIT+1,MSR_FP_BIT-1 ; Force floating point off
193 rlwinm r7,r7,0,MSR_VEC_BIT+1,MSR_VEC_BIT-1 ; Force vectors off
194 rlwinm r7,r7,0,MSR_EE_BIT+1,MSR_EE_BIT-1 ; Clear the interrupt enable mask
195 mtmsr r7 ; Disable for interrupts
196 mfsprg r10,0 ; Restore the per_proc info
198 * This is also the point where new threads come when they are created.
199 * The new thread is setup to look like a thread that took an
200 * interrupt and went immediatly into trap.
204 lwz r4,SAVprev(r3) ; Pick up the previous savearea
205 lwz r11,SAVflags(r3) ; Get the flags of the current savearea
206 lwz r8,savesrr1(r3) ; Get the MSR we are going to
207 rlwinm r11,r11,0,15,13 ; Clear the syscall flag
208 lwz r1,PP_ACTIVE_THREAD(r10) ; Get the active thread
209 rlwinm. r8,r8,0,MSR_PR_BIT,MSR_PR_BIT ; Are we going to the user?
210 mfsprg r8,1 ; Get the current activation
211 stw r11,SAVflags(r3) ; Save back the flags (with reset stack cleared)
213 stw r4,ACT_MACT_PCB(r8) ; Point to the previous savearea (or 0 if none)
215 beq- chkfac ; We are not leaving the kernel yet...
217 lwz r5,THREAD_KERNEL_STACK(r1) ; Get the base pointer to the stack
218 addi r5,r5,KERNEL_STACK_SIZE-FM_SIZE ; Reset to empty
219 stw r5,ACT_MACT_KSP(r8) ; Save the empty stack pointer
220 b chkfac ; Go end it all...
224 ; Here is where we go when we detect that the kernel stack is all messed up.
225 ; We just try to dump some info and get into the debugger.
230 lwz r3,PP_DEBSTACK_TOP_SS(r25) ; Pick up debug stack top
231 subi r3,r3,KERNEL_STACK_SIZE-FM_SIZE ; Adjust to start of stack
232 sub r3,r1,r3 ; Get displacement into debug stack
233 cmplwi cr2,r3,KERNEL_STACK_SIZE-FM_SIZE ; Check if we are on debug stack
234 blt+ cr2,kernelStackNotBad ; Yeah, that is ok too...
236 lis r0,hi16(Choke) ; Choke code
237 ori r0,r0,lo16(Choke) ; and the rest
238 li r3,failStack ; Bad stack code
245 * ENTRY: VM switched ON
247 * R3 contains exception code
248 * R4 points to the saved context (virtual address)
249 * Everything is saved in savearea
253 * If pcb.ksp == 0 then the kernel stack is already busy,
254 * this is an error - jump to the debugger entry
256 * otherwise depending upon the type of
257 * syscall, look it up in the kernel table
258 * or pass it to the server.
260 * on return, we do the reverse, the state is popped from the pcb
261 * and pcb.ksp is set to the top of stack.
266 * mach system calls are negative
267 * BSD system calls are low positive
268 * PPC-only system calls are in the range 0x6xxx
269 * PPC-only "fast" traps are in the range 0x7xxx
274 LEXT(shandler) ; System call handler
276 mfsprg r25,0 ; Get the per proc area
277 lwz r0,saver0(r4) ; Get the original syscall number
278 lwz r17,PP_ISTACKPTR(r25) ; Get interrupt stack pointer
279 rlwinm r15,r0,0,0,19 ; Clear the bottom of call number for fast check
280 mr. r17,r17 ; Are we on interrupt stack?
281 lwz r7,savesrr1(r4) ; Get the SRR1 value
282 beq- EXT(ihandler) ; On interrupt stack, not allowed...
283 lwz r9,savevrsave(r4) ; Get the VRsave register
284 rlwinm. r6,r7,0,MSR_VEC_BIT,MSR_VEC_BIT ; Was vector on?
285 lwz r16,PP_ACTIVE_THREAD(r25) ; Get the thread pointer
286 mfsprg r13,1 ; Pick up the active thread
288 beq+ svecoff ; Vector off, do not save vrsave...
289 stw r9,liveVRS(r25) ; Set the live value
291 ; Check if SCs are being redirected for the BlueBox or to VMM
294 svecoff: lwz r6,ACT_MACT_SPF(r13) ; Pick up activation special flags
295 mtcrf 0x41,r6 ; Check special flags
296 crmove cr6_eq,runningVMbit ; Remember if we are in VMM
297 bne cr6,sVMchecked ; Not running VM
298 lwz r18,spcFlags(r25) ; Load per_proc special flags
299 rlwinm. r18,r18,0,FamVMmodebit,FamVMmodebit ; Is FamVMmodebit set?
300 beq sVMchecked ; Not in FAM
301 cmpwi r0,0x6004 ; Is it vmm_dispatch syscall:
303 lwz r26,saver3(r4) ; Get the original syscall number
304 cmpwi cr6,r26,kvmmExitToHost ; vmm_exit_to_host request
306 bf+ bbNoMachSCbit,noassist ; Take branch if SCs are not redirected
307 lwz r26,ACT_MACT_BEDA(r13) ; Pick up the pointer to the blue box exception area
308 b EXT(atomic_switch_syscall) ; Go to the assist...
310 noassist: cmplwi r15,0x7000 ; Do we have a fast path trap?
311 lwz r14,ACT_MACT_PCB(r13) ; Now point to the PCB
312 beql+ fastpath ; We think it is a fastpath...
314 lwz r1,ACT_MACT_KSP(r13) ; Get the kernel stack pointer
316 mr. r1,r1 ; Are we already on the kernel stack?
317 li r3,T_SYSTEM_CALL ; Yup, pretend we had an interrupt...
318 beq- EXT(ihandler) ; Bad boy, bad boy... What cha gonna do when they come for you?
321 stw r4,ACT_MACT_PCB(r13) ; Point to our savearea
322 li r0,0 ; Clear this out
323 stw r14,SAVprev(r4) ; Queue the new save area in the front
324 stw r13,SAVact(r4) ; Point the savearea at its activation
327 bl versave ; (TEST/DEBUG)
330 mr r30,r4 ; Save pointer to the new context savearea
331 lwz r15,saver1(r4) ; Grab interrupt time stack
332 stw r0,ACT_MACT_KSP(r13) ; Mark stack as busy with 0 val
333 stw r15,FM_BACKPTR(r1) ; Link stack frame backwards
336 /* If debugging, we need two frames, the first being a dummy
337 * which links back to the trapped routine. The second is
338 * that which the C routine below will need
340 lwz r8,savesrr0(r30) ; Get the point of interruption
341 stw r8,FM_LR_SAVE(r1) ; Save old instr ptr as LR value
342 stwu r1, -FM_SIZE(r1) ; and make new frame
345 mfmsr r11 ; Get the MSR
346 lwz r15,SAVflags(r30) ; Get the savearea flags
347 ori r11,r11,lo16(MASK(MSR_EE)) ; Turn on interruption enabled bit
348 lwz r0,saver0(r30) ; Get R0 back
349 oris r15,r15,SAVsyscall >> 16 ; Mark that it this is a syscall
350 rlwinm r10,r0,0,0,19 ; Keep only the top part
351 stwu r1,-(FM_SIZE+ARG_SIZE)(r1) ; Make a stack frame
352 cmplwi r10,0x6000 ; Is it the special ppc-only guy?
353 stw r15,SAVflags(r30) ; Save syscall marker
354 beq- cr6,exitFromVM ; It is time to exit from alternate context...
356 beq- ppcscall ; Call the ppc-only system call handler...
358 mtmsr r11 ; Enable interruptions
360 lwz r0,saver0(r30) ; Get the system call selector
361 mr. r0,r0 ; What kind is it?
362 blt- .L_kernel_syscall ; System call number if negative, this is a mach call...
364 cmpwi cr0,r0,0x7FFA ; Special blue box call?
365 beq- .L_notify_interrupt_syscall ; Yeah, call it...
367 lwz r8,ACT_TASK(r13) ; Get our task
368 lis r10,hi16(EXT(c_syscalls_unix)) ; Get top half of counter address
369 lwz r7,TASK_SYSCALLS_UNIX(r8) ; Get the current count
370 ori r10,r10,lo16(EXT(c_syscalls_unix)) ; Get low half of counter address
371 addi r7,r7,1 ; Bump it
372 lwz r9,0(r10) ; Get counter
373 stw r7,TASK_SYSCALLS_UNIX(r8) ; Save it
374 mr r3,r30 ; Get PCB/savearea
375 mr r4,r13 ; current activation
377 stw r9,0(r10) ; Save it back
378 bl EXT(unix_syscall) ; Check out unix...
380 .L_call_server_syscall_exception:
381 li r3,EXC_SYSCALL ; doexception(EXC_SYSCALL, num, 1)
383 .L_call_server_exception:
384 mr r4,r0 ; Set syscall selector
386 b EXT(doexception) ; Go away, never to return...
388 .L_notify_interrupt_syscall:
389 lwz r3,saver3(r30) ; Get the new PC address to pass in
390 bl EXT(syscall_notify_interrupt)
394 ; Handle PPC-only system call interface
395 ; These are called with interruptions disabled
396 ; and the savearea/pcb as the first parameter.
397 ; It is up to the callee to enable interruptions if
398 ; they should be. We are in a state here where
399 ; both interrupts and preemption is ok, but because we could
400 ; be calling diagnostic code we will not enable.
402 ; Also, the callee is responsible for finding any parameters
403 ; in the savearea/pcb. It also must set saver3 with any return
404 ; code before returning.
406 ; There are 3 possible return codes:
407 ; 0 the call is disabled or something, we treat this like it was bogus
408 ; + the call finished ok, check for AST
409 ; - the call finished ok, do not check for AST
411 ; Note: the last option is intended for special diagnostics calls that
412 ; want the thread to return and execute before checking for preemption.
414 ; NOTE: Both R16 (thread) and R30 (savearea) need to be preserved over this call!!!!
419 ppcscall: rlwinm r11,r0,2,18,29 ; Make an index into the table
420 lis r10,hi16(EXT(PPCcalls)) ; Get PPC-only system call table
421 cmplwi r11,PPCcallmax ; See if we are too big
422 ori r10,r10,lo16(EXT(PPCcalls)) ; Merge in low half
423 bgt- .L_call_server_syscall_exception ; Bogus call...
424 lwzx r11,r10,r11 ; Get function address
427 ; Note: make sure we do not change the savearea in R30 to
428 ; a different register without checking. Some of the PPCcalls
429 ; depend upon it being there.
432 mr r3,r30 ; Pass the savearea
433 mr r4,r13 ; Pass the activation
434 mr. r11,r11 ; See if there is a function here
435 mtlr r11 ; Set the function address
436 beq- .L_call_server_syscall_exception ; Disabled call...
442 mr. r3,r3 ; See what we should do
443 mr r31,r16 ; Restore the current thread pointer
444 bgt+ .L_thread_syscall_ret_check_ast ; Take normal AST checking return....
445 mfsprg r10,0 ; Get the per_proc
446 blt+ .L_thread_syscall_return ; Return, but no ASTs....
447 lwz r0,saver0(r30) ; Restore the system call number
448 b .L_call_server_syscall_exception ; Go to common exit...
451 /* Once here, we know that the syscall was -ve
452 * we should still have r1=ksp,
453 * r16 = pointer to current thread,
454 * r13 = pointer to top activation,
455 * r0 = syscall number
456 * r30 = pointer to saved state (in pcb)
463 ; Call a function that can print out our syscall info
464 ; Note that we don t care about any volatiles yet
467 bl EXT(syscall_trace)
468 lwz r0,saver0(r30) ; Get the system call selector */
469 neg r31,r0 ; Make system call number positive and put in r31
470 lis r29,hi16(EXT(mach_trap_count)) ; High part of valid trap number
471 ori r29,r29,lo16(EXT(mach_trap_count)) ; Low part of valid trap number
472 lis r28,hi16(EXT(mach_trap_table)) ; High part of trap table
473 lwz r29,0(r29) ; Get the first invalid system call number
474 ori r28,r28,lo16(EXT(mach_trap_table)) ; Low part of trap table
476 cmplw r31,r29 ; See if we have a valid system call number
477 slwi r31,r31,MACH_TRAP_OFFSET_POW2 ; Get offset into table
479 bge- .L_call_server_syscall_exception ; System call number of bogus
481 add r31,r31,r28 ; Point to the system call entry
482 lis r28,hi16(EXT(kern_invalid)) ; Get the high invalid routine address
483 lwz r0,MACH_TRAP_FUNCTION(r31) ; Grab the system call routine address
484 ori r28,r28,lo16(EXT(kern_invalid)) ; Get the low part of the invalid routine address
485 lwz r29,MACH_TRAP_ARGC(r31) ; Get the number of arguments in the call
486 cmplw r0,r28 ; Is this an invalid entry?
487 beq- .L_call_server_syscall_exception ; Yes, it is invalid...
489 /* get arg count. If argc > 8 then not all args were in regs,
490 * so we must perform copyin.
492 cmpwi cr0,r29,8 ; Do we have more than 8 arguments?
493 ble+ .L_syscall_got_args ; Nope, no copy in needed...
495 /* argc > 8 - perform a copyin */
496 /* if the syscall came from kernel space, we can just copy */
498 lwz r0,savesrr1(r30) ; Pick up exception time MSR
499 andi. r0,r0,MASK(MSR_PR) ; Check the priv bit
500 bne+ .L_syscall_arg_copyin ; We are not priviliged...
502 /* we came from a privilaged task, just do a copy */
503 /* get user's stack pointer */
505 lwz r28,saver1(r30) ; Get the stack pointer
507 subi r29,r29,8 ; Get the number of arguments to copy
509 addi r28,r28,COPYIN_ARG0_OFFSET-4 ; Point to source - 4
510 addi r27,r1,FM_ARG0-4 ; Point to sink - 4
512 .L_syscall_copy_word_loop:
513 addic. r29,r29,-1 ; Count down the number of arguments left
514 lwz r0,4(r28) ; Pick up the argument from the stack
515 addi r28,r28,4 ; Point to the next source
516 stw r0,4(r27) ; Store the argument
517 addi r27,r27,4 ; Point to the next sink
518 bne+ .L_syscall_copy_word_loop ; Move all arguments...
519 b .L_syscall_got_args ; Go call it now...
522 /* we came from a user task, pay the price of a real copyin */
523 /* set recovery point */
527 .L_syscall_arg_copyin:
528 lwz r8,ACT_VMMAP(r13) ; Get the vm_map for this activation
529 lis r28,hi16(.L_syscall_copyin_recover)
530 lwz r8,VMMAP_PMAP(r8) ; Get the pmap
531 ori r28,r28,lo16(.L_syscall_copyin_recover)
532 addi r8,r8,PMAP_SEGS ; Point to the pmap SR slots
533 stw r28,THREAD_RECOVER(r16) ; R16 still holds thread ptr
535 /* We can manipulate the COPYIN segment register quite easily
536 * here, but we've also got to make sure we don't go over a
537 * segment boundary - hence some mess.
538 * Registers from 12-29 are free for our use.
542 lwz r28,saver1(r30) ; Get the stack pointer
543 subi r29,r29,8 ; Get the number of arguments to copy
544 addi r28,r28,COPYIN_ARG0_OFFSET ; Set source in user land
546 /* set up SR_COPYIN to allow us to copy, we may need to loop
547 * around if we change segments. We know that this previously
548 * pointed to user space, so the sid doesn't need setting.
551 rlwinm r7,r28,6,26,29 ; Get index to the segment slot
553 .L_syscall_copyin_seg_loop:
554 lwzx r10,r8,r7 ; Get the source SR value
555 rlwinm r26,r28,0,4,31 ; Clear the segment number from source address
556 mtsr SR_COPYIN,r10 ; Set the copyin SR
559 oris r26,r26,(SR_COPYIN_NUM << (28-16)) ; Insert the copyin segment number into source address
561 addi r27,r1,FM_ARG0-4 ; Point to area - 4 where we will store the arguments
563 .L_syscall_copyin_word_loop:
564 lwz r0,0(r26) ; MAY CAUSE PAGE FAULT!
565 subi r29,r29,1 ; Decrement count
566 addi r26,r26,4 ; Bump input
567 stw r0,4(r27) ; Save the copied in word
568 mr. r29,r29 ; Are they all moved?
569 addi r27,r27,4 ; Bump output
570 beq+ .L_syscall_copyin_done ; Escape if we are done...
572 rlwinm. r0,r26,0,4,29 ; Did we just step into a new segment?
573 addi r28,r28,4 ; Bump up user state address also
574 bne+ .L_syscall_copyin_word_loop ; We are still on the same segment...
576 addi r7,r7,4 ; Bump to next slot
577 b .L_syscall_copyin_seg_loop ; On new segment! remap
579 /* Don't bother restoring SR_COPYIN, we can leave it trashed */
580 /* clear thread recovery as we're done touching user data */
584 .L_syscall_copyin_done:
586 stw r0,THREAD_RECOVER(r16) ; R16 still holds thread ptr
589 lwz r0,MACH_TRAP_FUNCTION(r31) ; Get function address
590 lwz r8,ACT_TASK(r13) ; Get our task
591 lis r10,hi16(EXT(c_syscalls_mach)) ; Get top half of counter address
592 lwz r7,TASK_SYSCALLS_MACH(r8) ; Get the current count
593 lwz r3,saver3(r30) ; Restore r3
594 addi r7,r7,1 ; Bump it
595 ori r10,r10,lo16(EXT(c_syscalls_mach)) ; Get low half of counter address
596 stw r7,TASK_SYSCALLS_MACH(r8) ; Save it
597 lwz r4,saver4(r30) ; Restore r4
598 lwz r9,0(r10) ; Get counter
599 mtctr r0 ; Set function address
600 lwz r5,saver5(r30) ; Restore r5
601 lwz r6,saver6(r30) ; Restore r6
603 lwz r7,saver7(r30) ; Restore r7
604 lwz r8,saver8(r30) ; Restore r8
605 stw r9,0(r10) ; Save it back
606 lwz r9,saver9(r30) ; Restore r9
607 lwz r10,saver10(r30) ; Restore r10
611 ; Note that all arguments from the system call are passed into the function
614 bctrl ; Perform the actual syscall
616 /* 'standard' syscall returns here - INTERRUPTS ARE STILL ON */
618 /* r3 contains value that we're going to return to the user
622 * Ok, return from C function, R3 = return value
624 * get the active thread's PCB pointer and thus pointer to user state
625 * saved state is still in R30 and the active thread is in R16 .
628 /* Store return value into saved state structure, since
629 * we need to pick up the value from here later - the
630 * 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
636 /* When we are here, r16 should point to the current thread,
637 * r30 should point to the current pcb
640 /* save off return value, we must load it
641 * back anyway for thread_exception_return
645 mr r31,r16 ; Move the current thread pointer
646 stw r3,saver3(r30) ; Stash the return code
648 mr r4,r30 ; Pass in the savearea
649 bl EXT(syscall_trace_end) ; Trace the exit of the system call
651 .L_thread_syscall_ret_check_ast:
652 mfmsr r12 ; Get the current MSR
653 rlwinm r12,r12,0,MSR_FP_BIT+1,MSR_FP_BIT-1 ; Force floating point off
654 rlwinm r12,r12,0,MSR_VEC_BIT+1,MSR_VEC_BIT-1 ; Force vectors off
655 rlwinm r12,r12,0,MSR_EE_BIT+1,MSR_EE_BIT-1 ; Turn off interruptions enable bit
656 mtmsr r12 ; Turn interruptions off
658 mfsprg r10,0 ; Get the per_processor block
660 /* Check to see if there's an outstanding AST */
662 lwz r4,PP_NEED_AST(r10) ; Get the pointer to the ast requests
663 lwz r4,0(r4) ; Get the flags
664 cmpi cr0,r4, 0 ; Any pending asts?
665 beq+ cr0,.L_syscall_no_ast ; Nope...
667 /* Yes there is, call ast_taken
668 * pretending that the user thread took an AST exception here,
669 * ast_taken will save all state and bring us back here
673 /* debug assert - make sure that we're not returning to kernel */
675 andi. r3,r3,MASK(MSR_PR)
676 bne+ scrnotkern ; returning to user level, check
678 lis r0,hi16(Choke) ; Choke code
679 ori r0,r0,lo16(Choke) ; and the rest
680 li r3,failContext ; Bad state code
686 li r3,AST_ALL ; Set ast flags
687 li r4,1 ; Set interrupt allowed
688 bl EXT(ast_taken) ; Process the pending ast
689 b .L_thread_syscall_ret_check_ast ; Go see if there was another...
691 /* thread_exception_return returns to here, almost all
692 * registers intact. It expects a full context restore
693 * of what it hasn't restored itself (ie. what we use).
695 * In particular for us,
696 * we still have r31 points to the current thread,
697 * r30 points to the current pcb
703 .L_thread_syscall_return:
705 mr r3,r30 ; Get savearea to the correct register for common exit
706 mfsprg r8,1 ; Now find the current activation
708 lwz r11,SAVflags(r30) ; Get the flags
709 lwz r5,THREAD_KERNEL_STACK(r31) ; Get the base pointer to the stack
710 rlwinm r11,r11,0,15,13 ; Clear the syscall flag
711 lwz r4,SAVprev(r30) ; Get the previous save area
712 stw r11,SAVflags(r30) ; Stick back the flags
713 addi r5,r5,KERNEL_STACK_SIZE-FM_SIZE ; Reset to empty
714 stw r4,ACT_MACT_PCB(r8) ; Save previous save area
715 stw r5,ACT_MACT_KSP(r8) ; Save the empty stack pointer
716 b chkfac ; Go end it all...
720 .L_syscall_copyin_recover:
722 /* This is the catcher for any data faults in the copyin
723 * of arguments from the user's stack.
724 * r30 still holds a pointer to the PCB
726 * call syscall_error(EXC_BAD_ACCESS, EXC_PPC_VM_PROT_READ, sp, ssp),
728 * we already had a frame so we can do this
731 li r3,EXC_BAD_ACCESS ; Set bad access code
732 li r4,EXC_PPC_VM_PROT_READ ; Set protection exception
733 lwz r5,saver1(r30) ; Point to the stack
734 mr r6,r30 ; Pass savearea
736 bl EXT(syscall_error) ; Generate error...
737 b .L_syscall_return ; Continue out...
741 * thread_exception_return()
743 * Return to user mode directly from within a system call.
747 .globl EXT(thread_bootstrap_return)
748 LEXT(thread_bootstrap_return) ; NOTE: THIS IS GOING AWAY IN A FEW DAYS....
750 .globl EXT(thread_exception_return)
751 LEXT(thread_exception_return) ; Directly return to user mode
753 .L_thread_exc_ret_check_ast:
754 mfmsr r3 ; Get the MSR
755 rlwinm r3,r3,0,MSR_FP_BIT+1,MSR_FP_BIT-1 ; Force floating point off
756 rlwinm r3,r3,0,MSR_VEC_BIT+1,MSR_VEC_BIT-1 ; Force vectors off
757 rlwinm r3,r3,0,MSR_EE_BIT+1,MSR_EE_BIT-1 ; Clear EE
758 mtmsr r3 ; Disable interrupts
760 /* Check to see if there's an outstanding AST */
761 /* We don't bother establishing a call frame even though CHECK_AST
762 can invoke ast_taken(), because it can just borrow our caller's
763 frame, given that we're not going to return.
766 mfsprg r10,0 ; Get the per_processor block
767 lwz r4,PP_NEED_AST(r10)
770 beq cr0,.L_exc_ret_no_ast
772 /* Yes there is, call ast_taken
773 * pretending that the user thread took an AST exception here,
774 * ast_taken will save all state and bring us back here
781 b .L_thread_exc_ret_check_ast ; check for a second AST (rare)
783 /* arriving here, interrupts should be disabled */
784 /* Get the active thread's PCB pointer to restore regs
788 mfsprg r30,1 ; Get the currrent activation
789 lwz r31,ACT_THREAD(r30) ; Get the current thread
791 lwz r30,ACT_MACT_PCB(r30)
792 mr. r30,r30 ; Is there any context yet?
793 beq- makeDummyCtx ; No, hack one up...
796 * debug assert - make sure that we're not returning to kernel
797 * get the active thread's PCB pointer and thus pointer to user state
801 andi. r3,r3,MASK(MSR_PR)
802 bne+ ret_user2 ; We are ok...
804 lis r0,hi16(Choke) ; Choke code
805 ori r0,r0,lo16(Choke) ; and the rest
806 li r3,failContext ; Bad state code
812 /* If the system call flag isn't set, then we came from a trap,
813 * so warp into the return_from_trap (thread_return) routine,
814 * which takes PCB pointer in R3, not in r30!
816 lwz r0,SAVflags(r30) ; Grab the savearea flags
817 mr r3,r30 ; Copy pcb pointer into r3 in case we need it
818 andis. r0,r0,SAVsyscall>>16 ; Are we returning from a syscall?
819 beq- cr0,thread_return ; Nope, must be a thread return...
820 b .L_thread_syscall_return ; Join up with the system call return...
823 ; This is where we handle someone trying who did a thread_create followed
824 ; by a thread_resume with no intervening thread_set_state. Just make an
825 ; empty context, initialize it to trash and let em execute at 0...
831 bl EXT(save_get) ; Get a save_area
832 li r4,SAVgeneral ; Get the general context type
834 stb r4,SAVflags+2(r3) ; Set type
835 addi r2,r3,savevscr ; Point past what we are clearing
836 mr r4,r3 ; Save the start
838 cleardummy: stw r0,0(r4) ; Clear stuff
839 addi r4,r4,4 ; Next word
840 cmplw r4,r2 ; Still some more?
841 blt+ cleardummy ; Yeah...
843 lis r2,hi16(MSR_EXPORT_MASK_SET) ; Set the high part of the user MSR
844 ori r2,r2,lo16(MSR_EXPORT_MASK_SET) ; And the low part
845 stw r2,savesrr1(r3) ; Set the default user MSR
847 b thread_return ; Go let em try to execute, hah!
852 * ENTRY: VM switched ON
854 * R3 contains exception code
855 * R4 points to the saved context (virtual address)
856 * Everything is saved in savearea
862 LEXT(ihandler) ; Interrupt handler */
865 * get the value of istackptr, if it's zero then we're already on the
869 lwz r10,savesrr1(r4) ; Get SRR1
870 lwz r7,savevrsave(r4) ; Get the VRSAVE register
871 mfsprg r25,0 ; Get the per_proc block
872 li r14,0 ; Zero this for now
873 rlwinm. r13,r10,0,MSR_VEC_BIT,MSR_VEC_BIT ; Was vector on?
874 lwz r1,PP_ISTACKPTR(r25) ; Get the interrupt stack
875 li r13,0 ; Zero this for now
876 lwz r16,PP_ACTIVE_THREAD(r25) ; Get the thread pointer
878 beq+ ivecoff ; Vector off, do not save vrsave...
879 stw r7,liveVRS(r25) ; Set the live value
881 ivecoff: li r0,0 ; Get a constant 0
882 cmplwi cr1,r16,0 ; Are we still booting?
884 ifpoff: mr. r1,r1 ; Is it active?
885 beq- cr1,ihboot1 ; We are still coming up...
886 lwz r13,THREAD_TOP_ACT(r16) ; Pick up the active thread
887 lwz r14,ACT_MACT_PCB(r13) ; Now point to the PCB
889 ihboot1: lwz r9,saver1(r4) ; Pick up the rupt time stack
890 stw r14,SAVprev(r4) ; Queue the new save area in the front
891 stw r13,SAVact(r4) ; Point the savearea at its activation
892 beq- cr1,ihboot4 ; We are still coming up...
893 stw r4,ACT_MACT_PCB(r13) ; Point to our savearea
895 ihboot4: bne .L_istackfree ; Nope...
897 /* We're already on the interrupt stack, get back the old
898 * stack pointer and make room for a frame
901 lwz r10,PP_INTSTACK_TOP_SS(r25) ; Get the top of the interrupt stack
902 addi r5,r9,INTSTACK_SIZE-FM_SIZE ; Shift stack for bounds check
903 subi r1,r9,FM_REDZONE ; Back up beyond the red zone
904 sub r5,r5,r10 ; Get displacement into stack
905 cmplwi r5,INTSTACK_SIZE-FM_SIZE ; Is the stack actually invalid?
906 blt+ ihsetback ; The stack is ok...
908 lwz r5,PP_DEBSTACK_TOP_SS(r25) ; Pick up debug stack top
909 subi r5,r5,KERNEL_STACK_SIZE-FM_SIZE ; Adjust to start of stack
910 sub r5,r1,r5 ; Get displacement into debug stack
911 cmplwi cr2,r5,KERNEL_STACK_SIZE-FM_SIZE ; Check if we are on debug stack
912 blt+ ihsetback ; Yeah, that is ok too...
914 lis r0,hi16(Choke) ; Choke code
915 ori r0,r0,lo16(Choke) ; and the rest
916 li r3,failStack ; Bad stack code
923 stw r0,PP_ISTACKPTR(r25) ; Mark the stack in use
924 oris r10,r10,HIGH_ADDR(SAVrststk) ; Indicate we reset stack when we return from this one
925 stw r10,SAVflags(r4) ; Stick it back
928 * To summarize, when we reach here, the state has been saved and
929 * the stack is marked as busy. We now generate a small
930 * stack frame with backpointers to follow the calling
931 * conventions. We set up the backpointers to the trapped
932 * routine allowing us to backtrace.
935 ihsetback: subi r1,r1,FM_SIZE ; Make a new frame
936 stw r9,FM_BACKPTR(r1) ; Point back to previous stackptr
939 beq- cr1,ihbootnover ; (TEST/DEBUG)
940 bl versave ; (TEST/DEBUG)
941 ihbootnover: ; (TEST/DEBUG)
945 /* If debugging, we need two frames, the first being a dummy
946 * which links back to the trapped routine. The second is
947 * that which the C routine below will need
949 lwz r5,savesrr0(r4) ; Get interrupt address
950 stw r5,FM_LR_SAVE(r1) ; save old instr ptr as LR value
951 stwu r1,-FM_SIZE(r1) ; Make another new frame for C routine
954 lwz r5,savedsisr(r4) ; Get the DSISR
955 lwz r6,savedar(r4) ; Get the DAR
960 /* interrupt() returns a pointer to the saved state in r3
962 * Ok, back from C. Disable interrupts while we restore things
964 .globl EXT(ihandler_ret)
966 LEXT(ihandler_ret) ; Marks our return point from debugger entry
968 mfmsr r0 ; Get our MSR
969 rlwinm r0,r0,0,MSR_FP_BIT+1,MSR_FP_BIT-1 ; Force floating point off
970 rlwinm r0,r0,0,MSR_VEC_BIT+1,MSR_VEC_BIT-1 ; Force vectors off
971 rlwinm r0,r0,0,MSR_EE_BIT+1,MSR_EE_BIT-1 ; Flip off the interrupt enabled bit
972 mtmsr r0 ; Make sure interrupts are disabled
973 mfsprg r10,0 ; Get the per_proc block
975 lwz r7,SAVflags(r3) ; Pick up the flags
976 lwz r8,PP_ACTIVE_THREAD(r10) ; and the active thread
977 lwz r9,SAVprev(r3) ; Get previous save area
978 cmplwi cr1,r8,0 ; Are we still initializing?
979 lwz r12,savesrr1(r3) ; Get the MSR we will load on return
980 beq- cr1,ihboot2 ; Skip if we are still in init...
981 lwz r8,THREAD_TOP_ACT(r8) ; Pick up the active thread
983 ihboot2: andis. r11,r7,hi16(SAVrststk) ; Is this the first on the stack?
984 beq- cr1,ihboot3 ; Skip if we are still in init...
985 stw r9,ACT_MACT_PCB(r8) ; Point to previous context savearea
987 ihboot3: mr r4,r3 ; Move the savearea pointer
988 beq .L_no_int_ast2 ; Get going if not the top-o-stack...
991 /* We're the last frame on the stack. Restore istackptr to empty state.
993 * Check for ASTs if one of the below is true:
994 * returning to user mode
995 * returning to a kloaded server
997 lwz r9,PP_INTSTACK_TOP_SS(r10) ; Get the empty stack value
998 andc r7,r7,r11 ; Remove the stack reset bit in case we pass this one
999 stw r9,PP_ISTACKPTR(r10) ; Save that saved state ptr
1000 lwz r3,PP_PREEMPT_CNT(r10) ; Get preemption level
1001 stw r7,SAVflags(r4) ; Save the flags
1002 cmplwi r3, 0 ; Check for preemption
1003 bne .L_no_int_ast ; Do not preempt if level is not zero
1004 andi. r6,r12,MASK(MSR_PR) ; privilege mode
1005 lwz r11,PP_NEED_AST(r10) ; Get the AST request address
1006 lwz r11,0(r11) ; Get the request
1007 beq- .L_kernel_int_ast ; In kernel space, AST_URGENT check
1008 li r3,T_AST ; Assume the worst
1009 mr. r11,r11 ; Are there any pending?
1010 beq .L_no_int_ast ; Nope...
1014 andi. r11,r11,AST_URGENT ; Do we have AST_URGENT?
1015 li r3,T_PREEMPT ; Assume the worst
1016 beq .L_no_int_ast ; Nope...
1019 * There is a pending AST. Massage things to make it look like
1020 * we took a trap and jump into the trap handler. To do this
1021 * we essentially pretend to return from the interrupt but
1022 * at the last minute jump into the trap handler with an AST
1023 * trap instead of performing an rfi.
1027 stw r3,saveexception(r4) ; Set the exception code to T_AST/T_PREEMPT
1028 b EXT(thandler) ; We need to preempt so treat like a trap...
1031 mr r3,r4 ; Get into the right register for common code
1034 rlwinm r7,r7,0,15,13 ; Clear the syscall flag
1035 li r4,0 ; Assume for a moment that we are in init
1036 stw r7,SAVflags(r3) ; Set the flags with cleared syscall flag
1037 beq- cr1,chkfac ; Jump away if we are in init...
1039 lwz r4,ACT_MACT_PCB(r8) ; Get the new level marker
1043 ; This section is common to all exception exits. It throws away vector
1044 ; and floating point saveareas as the exception level of a thread is
1047 ; It also enables the facility if its context is live
1049 ; R3 = Savearea to be released (virtual)
1050 ; R4 = New top of savearea stack (could be 0)
1051 ; R8 = pointer to activation
1052 ; R10 = per_proc block
1054 ; Note that barring unforseen crashes, there is no escape from this point
1055 ; on. We WILL call exception_exit and launch this context. No worries
1056 ; about preemption or interruptions here.
1058 ; Note that we will set up R26 with whatever context we will be launching,
1059 ; so it will indicate the current, or the deferred it it is set and we
1060 ; are going to user state. CR2_eq will be set to indicate deferred.
1063 chkfac: mr r31,r10 ; Move per_proc address
1064 mr r30,r4 ; Preserve new level
1065 lwz r29,savesrr1(r3) ; Get the current MSR
1066 mr. r28,r8 ; Are we still in boot?
1067 mr r27,r3 ; Save the old level
1068 beq- chkenax ; Yeah, skip it all...
1070 rlwinm. r0,r29,0,MSR_PR_BIT,MSR_PR_BIT ; Are we going into user state?
1073 beq+ lllll ; (TEST/DEBUG)
1074 BREAKPOINT_TRAP ; (TEST/DEBUG)
1078 lwz r20,curctx(r28) ; Get our current context
1079 lwz r26,deferctx(r28) ; Get any deferred context switch
1080 rlwinm r29,r29,0,MSR_FP_BIT+1,MSR_FP_BIT-1 ; Turn off floating point for now
1081 lwz r21,FPUlevel(r20) ; Get the facility level
1082 cmplwi cr2,r26,0 ; Are we going into a deferred context later?
1083 rlwinm r29,r29,0,MSR_VEC_BIT+1,MSR_VEC_BIT-1 ; Turn off vector for now
1084 crnor cr2_eq,cr0_eq,cr2_eq ; Set cr2_eq if going to user state and there is deferred
1085 cmplw r27,r21 ; Are we returning from the active level?
1086 lhz r19,PP_CPU_NUMBER(r31) ; Get our CPU number
1087 bne+ fpuchkena ; Nope...
1090 ; First clean up any live context we are returning from
1093 lwz r22,FPUcpu(r20) ; Get CPU this context was last dispatched on
1095 stw r19,FPUcpu(r20) ; Claim context for us
1097 eieio ; Make sure this gets out before owner clear
1099 lis r23,hi16(EXT(per_proc_info)) ; Set base per_proc
1100 mulli r22,r22,ppSize ; Find offset to the owner per_proc
1101 ori r23,r23,lo16(EXT(per_proc_info)) ; Set base per_proc
1102 li r24,FPUowner ; Displacement to FPU owner
1103 add r22,r23,r22 ; Point to the owner per_proc
1104 li r0,0 ; We need this in a bit
1106 fpuinvothr: lwarx r23,r24,r22 ; Get the owner
1107 cmplw r23,r20 ; Does he still have this context?
1108 bne fpuinvoths ; Nope...
1109 stwcx. r0,r24,r22 ; Try to invalidate it
1110 bne- fpuinvothr ; Try again if there was a collision...
1115 ; Now if there is a savearea associated with the popped context, release it.
1116 ; Either way, pop the level to the top stacked context.
1119 lwz r22,FPUsave(r20) ; Get pointer to the first savearea
1120 li r21,0 ; Assume we popped all the way out
1121 mr. r22,r22 ; Is there anything there?
1122 beq+ fpusetlvl ; No, see if we need to enable...
1124 lwz r21,SAVlevel(r22) ; Get the level of that savearea
1125 cmplw r21,r27 ; Is this the saved copy of the live stuff?
1126 bne fpusetlvl ; No, leave as is...
1128 lwz r24,SAVprev(r22) ; Pick up the previous area
1129 li r21,0 ; Assume we popped all the way out
1130 mr. r24,r24 ; Any more context stacked?
1131 beq- fpuonlyone ; Nope...
1132 lwz r21,SAVlevel(r24) ; Get the level associated with save
1134 fpuonlyone: stw r24,FPUsave(r20) ; Dequeue this savearea
1136 rlwinm r3,r22,0,0,19 ; Find main savearea header
1137 lwz r3,SACvrswap(r3) ; Get the virtual to real conversion
1138 la r9,quickfret(r31) ; Point to the quickfret chain header
1139 xor r3,r22,r3 ; Convert to physical
1142 lis r0,HIGH_ADDR(CutTrace) ; (TEST/DEBUG)
1143 li r2,0x3301 ; (TEST/DEBUG)
1144 oris r0,r0,LOW_ADDR(CutTrace) ; (TEST/DEBUG)
1148 fpufpucdq: lwarx r0,0,r9 ; Pick up the old chain head
1149 stw r0,SAVprev(r22) ; Move it to the current guy
1150 stwcx. r3,0,r9 ; Save it
1151 bne- fpufpucdq ; Someone chaged the list...
1153 fpusetlvl: stw r21,FPUlevel(r20) ; Save the level
1156 ; Here we check if we are at the right level
1157 ; We need to check the level we are entering, not the one we are exiting.
1158 ; Therefore, we will use the defer level if it is non-zero and we are
1159 ; going into user state.
1162 fpuchkena: bt- cr2_eq,fpuhasdfrd ; Skip if deferred, R26 already set up...
1163 mr r26,r20 ; Use the non-deferred value
1165 fpuhasdfrd: lwz r21,FPUowner(r31) ; Get the ID of the live context
1166 lwz r23,FPUlevel(r26) ; Get the level ID
1167 cmplw cr3,r26,r21 ; Do we have the live context?
1168 lwz r24,FPUcpu(r26) ; Get the CPU that the context was last dispatched on
1169 bne- cr3,chkvec ; No, can not possibly enable...
1170 cmplw r30,r23 ; Are we about to launch the live level?
1171 cmplw cr1,r19,r24 ; Was facility used on this processor last?
1172 bne- chkvec ; No, not live...
1173 bne- cr1,chkvec ; No, wrong cpu, have to enable later....
1175 lwz r24,FPUsave(r26) ; Get the first savearea
1176 mr. r24,r24 ; Any savearea?
1177 beq+ fpuena ; Nope...
1178 lwz r25,SAVlevel(r24) ; Get the level of savearea
1179 lwz r0,SAVprev(r24) ; Get the previous
1180 cmplw r30,r25 ; Is savearea for the level we are launching?
1181 bne+ fpuena ; No, just go enable...
1183 stw r0,FPUsave(r26) ; Pop the chain
1185 rlwinm r3,r24,0,0,19 ; Find main savearea header
1186 lwz r3,SACvrswap(r3) ; Get the virtual to real conversion
1187 la r9,quickfret(r31) ; Point to the quickfret chain header
1188 xor r3,r24,r3 ; Convert to physical
1191 lis r0,HIGH_ADDR(CutTrace) ; (TEST/DEBUG)
1192 li r2,0x3302 ; (TEST/DEBUG)
1193 oris r0,r0,LOW_ADDR(CutTrace) ; (TEST/DEBUG)
1197 fpuhascdq: lwarx r0,0,r9 ; Pick up the old chain head
1198 stw r0,SAVprev(r24) ; Move it to the current guy
1199 stwcx. r3,0,r9 ; Save it
1200 bne- fpuhascdq ; Someone chaged the list...
1202 fpuena: ori r29,r29,lo16(MASK(MSR_FP)) ; Enable facility
1207 rlwinm. r21,r29,0,MSR_PR_BIT,MSR_PR_BIT ; (TEST/DEBUG)
1208 beq+ ppppp ; (TEST/DEBUG)
1209 lwz r21,FPUlevel(r26) ; (TEST/DEBUG)
1210 mr. r21,r21 ; (TEST/DEBUG)
1211 bne- qqqqq ; (TEST/DEBUG)
1212 lwz r21,FPUsave(r26) ; (TEST/DEBUG)
1213 mr. r21,r21 ; (TEST/DEBUG)
1214 beq+ ppppp ; (TEST/DEBUG)
1215 lwz r22,SAVlevel(r21) ; (TEST/DEBUG)
1216 mr. r22,r22 ; (TEST/DEBUG)
1217 beq+ ppppp ; (TEST/DEBUG)
1219 BREAKPOINT_TRAP ; (TEST/DEBUG)
1221 ppppp: ; (TEST/DEBUG)
1224 lwz r21,VMXlevel(r20) ; Get the facility level
1226 cmplw r27,r21 ; Are we returning from the active level?
1227 bne+ vmxchkena ; Nope...
1231 ; First clean up any live context we are returning from
1234 lwz r22,VMXcpu(r20) ; Get CPU this context was last dispatched on
1236 stw r19,VMXcpu(r20) ; Claim context for us
1238 eieio ; Make sure this gets out before owner clear
1240 lis r23,hi16(EXT(per_proc_info)) ; Set base per_proc
1241 mulli r22,r22,ppSize ; Find offset to the owner per_proc
1242 ori r23,r23,lo16(EXT(per_proc_info)) ; Set base per_proc
1243 li r24,VMXowner ; Displacement to VMX owner
1244 add r22,r23,r22 ; Point to the owner per_proc
1245 li r0,0 ; We need this in a bit
1247 vmxinvothr: lwarx r23,r24,r22 ; Get the owner
1248 cmplw r23,r20 ; Does he still have this context?
1249 bne vmxinvoths ; Nope...
1250 stwcx. r0,r24,r22 ; Try to invalidate it
1251 bne- vmxinvothr ; Try again if there was a collision...
1256 ; Now if there is a savearea associated with the popped context, release it.
1257 ; Either way, pop the level to the top stacked context.
1260 lwz r22,VMXsave(r20) ; Get pointer to the first savearea
1261 li r21,0 ; Assume we popped all the way out
1262 mr. r22,r22 ; Is there anything there?
1263 beq+ vmxsetlvl ; No, see if we need to enable...
1265 lwz r21,SAVlevel(r22) ; Get the level of that savearea
1266 cmplw r21,r27 ; Is this the saved copy of the live stuff?
1267 bne vmxsetlvl ; No, leave as is...
1269 lwz r24,SAVprev(r22) ; Pick up the previous area
1270 li r21,0 ; Assume we popped all the way out
1271 mr. r24,r24 ; Any more context?
1272 beq- vmxonlyone ; Nope...
1273 lwz r21,SAVlevel(r24) ; Get the level associated with save
1275 vmxonlyone: stw r24,VMXsave(r20) ; Dequeue this savearea
1277 rlwinm r3,r22,0,0,19 ; Find main savearea header
1278 lwz r3,SACvrswap(r3) ; Get the virtual to real conversion
1279 la r9,quickfret(r31) ; Point to the quickfret chain header
1280 xor r3,r22,r3 ; Convert to physical
1283 lis r0,HIGH_ADDR(CutTrace) ; (TEST/DEBUG)
1284 li r2,0x3401 ; (TEST/DEBUG)
1285 oris r0,r0,LOW_ADDR(CutTrace) ; (TEST/DEBUG)
1289 vmxhscdq: lwarx r0,0,r9 ; Pick up the old chain head
1290 stw r0,SAVprev(r22) ; Move it to the current guy
1291 stwcx. r3,0,r9 ; Save it
1292 bne- vmxhscdq ; Someone chaged the list...
1294 vmxsetlvl: stw r21,VMXlevel(r20) ; Save the level
1297 ; Here we check if we are at the right level
1300 vmxchkena: lwz r21,VMXowner(r31) ; Get the ID of the live context
1301 lwz r23,VMXlevel(r26) ; Get the level ID
1302 cmplw r26,r21 ; Do we have the live context?
1303 lwz r24,VMXcpu(r26) ; Get the CPU that the context was last dispatched on
1304 bne- setena ; No, can not possibly enable...
1305 cmplw r30,r23 ; Are we about to launch the live level?
1306 cmplw cr1,r19,r24 ; Was facility used on this processor last?
1307 bne- setena ; No, not live...
1308 bne- cr1,setena ; No, wrong cpu, have to enable later....
1310 lwz r24,VMXsave(r26) ; Get the first savearea
1311 mr. r24,r24 ; Any savearea?
1312 beq+ vmxena ; Nope...
1313 lwz r25,SAVlevel(r24) ; Get the level of savearea
1314 lwz r0,SAVprev(r24) ; Get the previous
1315 cmplw r30,r25 ; Is savearea for the level we are launching?
1316 bne+ vmxena ; No, just go enable...
1318 stw r0,VMXsave(r26) ; Pop the chain
1320 rlwinm r3,r24,0,0,19 ; Find main savearea header
1321 lwz r3,SACvrswap(r3) ; Get the virtual to real conversion
1322 la r9,quickfret(r31) ; Point to the quickfret chain header
1323 xor r3,r24,r3 ; Convert to physical
1326 lis r0,HIGH_ADDR(CutTrace) ; (TEST/DEBUG)
1327 li r2,0x3402 ; (TEST/DEBUG)
1328 oris r0,r0,LOW_ADDR(CutTrace) ; (TEST/DEBUG)
1332 vmxckcdq: lwarx r0,0,r9 ; Pick up the old chain head
1333 stw r0,SAVprev(r24) ; Move it to the current guy
1334 stwcx. r3,0,r9 ; Save it
1335 bne- vmxckcdq ; Someone chaged the list...
1337 vmxena: oris r29,r29,hi16(MASK(MSR_VEC)) ; Enable facility
1340 setena: rlwinm. r0,r29,0,MSR_PR_BIT,MSR_PR_BIT ; Are we about to launch user state?
1341 rlwinm r20,r29,(((31-vectorCngbit)+(MSR_VEC_BIT+1))&31),vectorCngbit,vectorCngbit ; Set flag if we enabled vector
1342 stw r29,savesrr1(r27) ; Turn facility on or off
1343 crmove cr7_eq,cr0_eq ; Remember if we are going to user state
1344 lwz r19,deferctx(r28) ; Get any deferred facility context switch
1345 rlwimi. r20,r29,(((31-floatCngbit)+(MSR_FP_BIT+1))&31),floatCngbit,floatCngbit ; Set flag if we enabled floats
1346 beq setenaa ; Neither float nor vector turned on....
1348 lwz r5,ACT_MACT_SPF(r28) ; Get activation copy
1349 lwz r6,spcFlags(r31) ; Get per_proc copy
1350 or r5,r5,r20 ; Set vector/float changed bits in activation
1351 or r6,r6,r20 ; Set vector/float changed bits in per_proc
1352 stw r5,ACT_MACT_SPF(r28) ; Set activation copy
1353 stw r6,spcFlags(r31) ; Set per_proc copy
1355 setenaa: mfdec r24 ; Get decrementer
1356 bf+ cr2_eq,nodefer ; No deferred to switch to...
1358 li r20,0 ; Clear this
1359 stw r26,curctx(r28) ; Make the facility context current
1360 stw r20,deferctx(r28) ; Clear deferred context
1362 nodefer: lwz r22,qactTimer(r28) ; Get high order quick activation timer
1363 mr. r24,r24 ; See if it has popped already...
1364 lwz r23,qactTimer+4(r28) ; Get low order qact timer
1365 ble- chkenax ; We have popped or are just about to...
1367 segtb: mftbu r20 ; Get the upper time base
1368 mftb r21 ; Get the low
1369 mftbu r19 ; Get upper again
1370 or. r0,r22,r23 ; Any time set?
1371 cmplw cr1,r20,r19 ; Did they change?
1372 beq+ chkenax ; No time set....
1373 bne- cr1,segtb ; Timebase ticked, get them again...
1375 subfc r6,r21,r23 ; Subtract current from qact time
1377 subfe r5,r20,r22 ; Finish subtract
1378 subfze r0,r0 ; Get a 0 if qact was bigger than current, -1 otherwise
1379 andc. r12,r5,r0 ; Set 0 if qact has passed
1380 andc r13,r6,r0 ; Set 0 if qact has passed
1381 bne chkenax ; If high order is non-zero, this is too big for a decrementer
1382 cmplw r13,r24 ; Is this earlier than the decrementer? (logical compare takes care of high bit on)
1383 bge+ chkenax ; No, do not reset decrementer...
1385 mtdec r13 ; Set our value
1391 lwz r20,SAVact(r27) ; (TEST/DEBUG) Make sure our restore
1392 lwz r21,PP_ACTIVE_THREAD(r31) ; (TEST/DEBUG) with the current act.
1393 cmpwi r21,0 ; (TEST/DEBUG)
1394 beq- yeswereok ; (TEST/DEBUG)
1395 lwz r21,THREAD_TOP_ACT(r21) ; (TEST/DEBUG)
1396 cmplw r21,r20 ; (TEST/DEBUG)
1397 beq+ yeswereok ; (TEST/DEBUG)
1399 lis r0,hi16(Choke) ; (TEST/DEBUG) Choke code
1400 ori r0,r0,lo16(Choke) ; (TEST/DEBUG) and the rest
1401 mr r21,r27 ; (TEST/DEBUG) Save the savearea address
1402 li r3,failContext ; (TEST/DEBUG) Bad state code
1403 sc ; (TEST/DEBUG) System ABEND
1408 rlwinm r5,r27,0,0,19 ; Round savearea down to page bndry
1409 lwz r5,SACvrswap(r5) ; Get the conversion from virtual to real
1410 xor r3,r27,r5 ; Flip to physical address
1411 b EXT(exception_exit) ; We are all done now...
1416 * Here's where we handle the fastpath stuff
1417 * We'll do what we can here because registers are already
1418 * loaded and it will be less confusing that moving them around.
1419 * If we need to though, we'll branch off somewhere's else.
1421 * Registers when we get here:
1423 * r0 = syscall number
1426 * r14 = previous savearea (if any)
1433 fastpath: cmplwi cr3,r0,0x7FF1 ; Is it CthreadSetSelfNumber?
1434 bnelr- cr3 ; Not a fast path...
1437 * void cthread_set_self(cproc_t p)
1439 * set's thread state "user_value"
1441 * This op is invoked as follows:
1442 * li r0, CthreadSetSelfNumber // load the fast-trap number
1443 * sc // invoke fast-trap
1448 CthreadSetSelfNumber:
1450 lwz r5,saver3(r4) /* Retrieve the self number */
1451 stw r5,CTHREAD_SELF(r13) /* Remember it */
1452 stw r5,UAW(r25) /* Prime the per_proc_info with it */
1455 .globl EXT(fastexit)
1457 rlwinm r9,r4,0,0,19 /* Round down to the base savearea block */
1458 lwz r9,SACvrswap(r9) /* Get the conversion from virtual to real */
1459 xor r3,r4,r9 /* Switch savearea to physical addressing */
1460 b EXT(exception_exit) /* Go back to the caller... */
1464 * Here's where we check for a hit on the Blue Box Assist
1465 * Most registers are non-volatile, so be careful here. If we don't
1466 * recognize the trap instruction we go back for regular processing.
1467 * Otherwise we transfer to the assist code.
1473 lwz r0,saveexception(r4) ; Get the exception code
1474 lwz r23,savesrr1(r4) ; Get the interrupted MSR
1475 lwz r26,ACT_MACT_BEDA(r13) ; Get Blue Box Descriptor Area
1476 mtcrf 0x18,r23 ; Check what SRR1 says
1477 lwz r24,ACT_MACT_BTS(r13) ; Get the table start
1478 cmplwi r0,T_AST ; Check for T_AST trap
1479 lwz r27,savesrr0(r4) ; Get trapped address
1480 crnand cr1_eq,SRR1_PRG_TRAP_BIT,MSR_PR_BIT ; We need both trap and user state
1481 sub r24,r27,r24 ; See how far into it we are
1482 cror cr0_eq,cr0_eq,cr1_eq ; Need to bail if AST or not trap or not user state
1483 cmplwi cr1,r24,BB_MAX_TRAP ; Do we fit in the list?
1484 cror cr0_eq,cr0_eq,cr1_gt ; Also leave it trap not in range
1485 btlr- cr0_eq ; No assist if AST or not trap or not user state or trap not in range
1486 b EXT(atomic_switch_trap) ; Go to the assist...
1489 ; Virtual Machine Monitor
1490 ; Here is where we exit from the emulated context
1491 ; Note that most registers get trashed here
1492 ; R3 and R30 are preserved across the call and hold the activation
1493 ; and savearea respectivily.
1498 exitFromVM: mr r30,r4 ; Get the savearea
1499 mr r3,r13 ; Get the activation
1501 b EXT(vmm_exit) ; Do it to it
1504 .globl EXT(retFromVM)
1507 mfsprg r10,0 ; Restore the per_proc info
1508 mr r8,r3 ; Get the activation
1509 lwz r4,SAVprev(r30) ; Pick up the previous savearea
1510 mr r3,r30 ; Put savearea in proper register for common code
1511 lwz r11,SAVflags(r30) ; Get the flags of the current savearea
1512 rlwinm r11,r11,0,15,13 ; Clear the syscall flag
1513 lwz r1,ACT_THREAD(r8) ; and the active thread
1514 stw r11,SAVflags(r3) ; Save back the flags (with reset stack cleared)
1516 stw r4,ACT_MACT_PCB(r8) ; Point to the previous savearea (or 0 if none)
1518 lwz r5,THREAD_KERNEL_STACK(r1) ; Get the base pointer to the stack
1519 addi r5,r5,KERNEL_STACK_SIZE-FM_SIZE ; Reset to empty
1520 stw r5,ACT_MACT_KSP(r8) ; Save the empty stack pointer
1521 b chkfac ; Go end it all...
1525 ; chandler (note: not a candle maker or tallow merchant)
1527 ; Here is the system choke handler. This is where the system goes
1530 ; We get here as a result of a T_CHOKE exception which is generated
1531 ; by the Choke firmware call or by lowmem_vectors when it detects a
1532 ; fatal error. Examples of where this may be used is when we detect
1533 ; problems in low-level mapping chains, trashed savearea free chains,
1534 ; or stack guardpage violations.
1536 ; Note that we can not set a back chain in the stack when we come
1537 ; here because we are probably here because the chain was corrupt.
1542 .globl EXT(chandler)
1543 LEXT(chandler) /* Choke handler */
1545 lis r25,hi16(EXT(trcWork)) ; (TEST/DEBUG)
1546 li r31,0 ; (TEST/DEBUG)
1547 ori r25,r25,lo16(EXT(trcWork)) ; (TEST/DEBUG)
1548 stw r31,traceMask(r25) ; (TEST/DEBUG)
1551 mfsprg r25,0 ; Get the per_proc
1553 lwz r1,PP_DEBSTACKPTR(r25) ; Get debug stack pointer
1554 cmpwi r1,-1 ; Are we already choking?
1555 bne chokefirst ; Nope...
1557 chokespin: addi r31,r31,1 ; Spin and hope for an analyzer connection...
1558 addi r31,r31,1 ; Spin and hope for an analyzer connection...
1559 addi r31,r31,1 ; Spin and hope for an analyzer connection...
1560 addi r31,r31,1 ; Spin and hope for an analyzer connection...
1561 addi r31,r31,1 ; Spin and hope for an analyzer connection...
1562 addi r31,r31,1 ; Spin and hope for an analyzer connection...
1563 b chokespin ; Spin and hope for an analyzer connection...
1565 chokefirst: li r0,-1 ; Set choke value
1566 mr. r1,r1 ; See if we are on debug stack yet
1567 lwz r10,saver1(r4) ;
1568 stw r0,PP_DEBSTACKPTR(r25) ; Show we are choking
1569 bne chokestart ; We are not on the debug stack yet...
1571 lwz r2,PP_DEBSTACK_TOP_SS(r25) ; Get debug stack top
1572 sub r11,r2,r10 ; Get stack depth
1574 cmplwi r11,KERNEL_STACK_SIZE-FM_SIZE-TRAP_SPACE_NEEDED ; Check if stack pointer is ok
1575 bgt chokespin ; Bad stack pointer or too little left, just die...
1577 subi r1,r10,FM_REDZONE ; Make a red zone
1579 chokestart: li r0,0 ; Get a zero
1580 stw r0,FM_BACKPTR(r1) ; We now have terminated the back chain
1582 bl EXT(SysChoked) ; Call the "C" phase of this
1583 b chokespin ; Should not be here so just go spin...
1588 ; Savearea chain verification
1594 ; Make sure that all savearea chains have the right type on them
1597 lis r28,hi16(EXT(default_pset)) ; (TEST/DEBUG)
1598 lis r27,hi16(EXT(DebugWork)) ; (TEST/DEBUG)
1599 ori r28,r28,lo16(EXT(default_pset)) ; (TEST/DEBUG)
1600 ori r27,r27,lo16(EXT(DebugWork)) ; (TEST/DEBUG)
1601 li r20,0 ; (TEST/DEBUG)
1602 lwz r26,0(r27) ; (TEST/DEBUG)
1603 lwz r27,psthreadcnt(r28) ; (TEST/DEBUG)
1604 mr. r26,r26 ; (TEST/DEBUG) Have we locked the test out?
1605 lwz r28,psthreads(r28) ; (TEST/DEBUG)
1606 mflr r31 ; (TEST/DEBUG) Save return
1607 bnelr- ; (TEST/DEBUG) Test already triggered, skip...
1608 b fckgo ; (TEST/DEBUG) Join up...
1610 fcknext: mr. r27,r27 ; (TEST/DEBUG) Any more threads?
1611 bne+ fckxxx ; (TEST/DEBUG) Yes...
1613 mtlr r31 ; (TEST/DEBUG) Restore return
1614 blr ; (TEST/DEBUG) Leave...
1616 fckxxx: lwz r28,THREAD_PSTHRN(r28) ; (TEST/DEBUG) Get next thread
1618 fckgo: subi r27,r27,1 ; (TEST/DEBUG) Decrement thread count
1619 lwz r24,THREAD_TOP_ACT(r28) ; (TEST/DEBUG) Get activation for the thread
1620 lwz r20,ACT_MACT_PCB(r24) ; (TEST/DEBUG) Get the normal context
1621 li r21,SAVgeneral ; (TEST/DEBUG) Make sure this is all general context
1622 bl versavetype ; (TEST/DEBUG) Check the chain
1624 lwz r20,facctx+FPUsave(r24) ; (TEST/DEBUG) Get regular floating point
1625 li r21,SAVfloat ; (TEST/DEBUG) Make sure this is all floating point
1626 bl versavetype ; (TEST/DEBUG) Check the chain
1628 lwz r20,facctx+VMXsave(r24) ; (TEST/DEBUG) Get regular vector point
1629 li r21,SAVvector ; (TEST/DEBUG) Make sure this is all vector
1630 bl versavetype ; (TEST/DEBUG) Check the chain
1632 lwz r29,vmmControl(r24) ; (TEST/DEBUG) Get the virtual machine control blocks
1633 mr. r29,r29 ; (TEST/DEBUG) Are there any?
1634 beq+ fcknext ; (TEST/DEBUG) Nope, next thread...
1636 li r22,kVmmMaxContextsPerThread ; (TEST/DEBUG) Get the number of control blocks
1637 subi r29,r29,vmmCEntrySize ; (TEST/DEBUG) Get running start
1639 fcknvmm: subi r22,r22,1 ; (TEST/DEBUG) Do all of them
1640 mr. r22,r22 ; (TEST/DEBUG) Are we all done?
1641 addi r29,r29,vmmCEntrySize ; (TEST/DEBUG) Get the next entry
1642 blt- fcknext ; (TEST/DEBUG) Yes, check next thread...
1644 lwz r23,vmmFlags(r29) ; (TEST/DEBUG) Get entry flags
1645 rlwinm. r23,r23,0,0,0 ; (TEST/DEBUG) Is this in use?
1646 beq+ fcknvmm ; (TEST/DEBUG) Not in use...
1648 lwz r20,vmmFacCtx+FPUsave(r29) ; (TEST/DEBUG) Get regular floating point
1649 li r21,SAVfloat ; (TEST/DEBUG) Make sure this is all floating point
1650 bl versavetype ; (TEST/DEBUG) Check the chain
1652 lwz r20,vmmFacCtx+VMXsave(r29) ; (TEST/DEBUG) Get regular vector point
1653 li r21,SAVvector ; (TEST/DEBUG) Make sure this is all vector
1654 bl versavetype ; (TEST/DEBUG) Check the chain
1655 b fcknvmm ; (TEST/DEBUG) Get then vmm block...
1658 mr. r20,r20 ; (TEST/DEBUG) Chain done?
1659 beqlr- ; (TEST/DEBUG) Yes...
1661 lwz r23,SAVflags(r20) ; (TEST/DEBUG) Get the flags
1662 rlwinm r23,r23,24,24,31 ; (TEST/DEBUG) Position it
1663 cmplw r23,r21 ; (TEST/DEBUG) Are we the correct type?
1664 beq+ versvok ; (TEST/DEBUG) This one is ok...
1666 lis r22,hi16(EXT(DebugWork)) ; (TEST/DEBUG)
1667 ori r22,r22,lo16(EXT(DebugWork)) ; (TEST/DEBUG)
1668 stw r22,0(r22) ; (TEST/DEBUG) Lock out more checks
1669 BREAKPOINT_TRAP ; (TEST/DEBUG) Get into debugger
1671 versvok: lwz r20,SAVprev(r20) ; (TEST/DEBUG) Get the previous one
1672 b versavetype ; (TEST/DEBUG) Go check its type...
1677 ; Make sure there are no circular links in the float chain
1678 ; And that FP is marked busy in it.
1679 ; And the only the top is marked invalid.
1680 ; And that the owning PCB is correct.
1683 lis r28,hi16(EXT(default_pset)) ; (TEST/DEBUG)
1684 lis r27,hi16(EXT(DebugWork)) ; (TEST/DEBUG)
1685 ori r28,r28,lo16(EXT(default_pset)) ; (TEST/DEBUG)
1686 ori r27,r27,lo16(EXT(DebugWork)) ; (TEST/DEBUG)
1687 li r20,0 ; (TEST/DEBUG)
1688 lwz r26,0(r27) ; (TEST/DEBUG)
1689 lwz r27,psthreadcnt(r28) ; (TEST/DEBUG)
1690 mr. r26,r26 ; (TEST/DEBUG)
1691 lwz r28,psthreads(r28) ; (TEST/DEBUG)
1692 bnelr- ; (TEST/DEBUG)
1694 fcknxtth: mr. r27,r27 ; (TEST/DEBUG)
1695 beqlr- ; (TEST/DEBUG)
1697 lwz r26,THREAD_TOP_ACT(r28) ; (TEST/DEBUG)
1699 fckact: mr. r26,r26 ; (TEST/DEBUG)
1700 bne+ fckact2 ; (TEST/DEBUG)
1702 lwz r28,THREAD_PSTHRN(r28) ; (TEST/DEBUG) Next in line
1703 subi r27,r27,1 ; (TEST/DEBUG)
1704 b fcknxtth ; (TEST/DEBUG)
1706 fckact2: lwz r20,ACT_MACT_FPU(r26) ; (TEST/DEBUG) Get FPU chain
1707 li r29,1 ; (TEST/DEBUG)
1708 li r22,0 ; (TEST/DEBUG)
1710 fckact3: mr. r20,r20 ; (TEST/DEBUG) Are there any?
1711 beq+ fckact5 ; (TEST/DEBUG) No...
1713 addi r22,r22,1 ; (TEST/DEBUG) Count chain depth
1715 lwz r21,SAVflags(r20) ; (TEST/DEBUG) Get the flags
1716 rlwinm. r21,r21,0,1,1 ; (TEST/DEBUG) FP busy?
1717 bne+ fckact3a ; (TEST/DEBUG) Yeah...
1718 lis r27,hi16(EXT(DebugWork)) ; (TEST/DEBUG)
1719 ori r27,r27,lo16(EXT(DebugWork)) ; (TEST/DEBUG)
1720 stw r27,0(r27) ; (TEST/DEBUG)
1721 BREAKPOINT_TRAP ; (TEST/DEBUG) Die
1723 fckact3a: cmplwi r22,1 ; (TEST/DEBUG) At first SA?
1724 beq+ fckact3b ; (TEST/DEBUG) Yeah, invalid is ok...
1725 lwz r21,SAVlvlfp(r20) ; (TEST/DEBUG) Get level
1726 cmplwi r21,1 ; (TEST/DEBUG) Is it invalid?
1727 bne+ fckact3b ; (TEST/DEBUG) Nope, it is ok...
1728 lis r27,hi16(EXT(DebugWork)) ; (TEST/DEBUG)
1729 ori r27,r27,lo16(EXT(DebugWork)) ; (TEST/DEBUG)
1730 stw r27,0(r27) ; (TEST/DEBUG)
1731 BREAKPOINT_TRAP ; (TEST/DEBUG) Die
1733 fckact3b: lwz r21,SAVact(r20) ; (TEST/DEBUG) Get the owner
1734 cmplw r21,r26 ; (TEST/DEBUG) Correct activation?
1735 beq+ fckact3c ; (TEST/DEBUG) Yup...
1736 lis r27,hi16(EXT(DebugWork)) ; (TEST/DEBUG)
1737 ori r27,r27,lo16(EXT(DebugWork)) ; (TEST/DEBUG)
1738 stw r27,0(r27) ; (TEST/DEBUG)
1739 BREAKPOINT_TRAP ; (TEST/DEBUG) Die
1741 fckact3c: ; (TEST/DEBUG)
1742 lbz r21,SAVflags+3(r20) ; (TEST/DEBUG) Pick up the test byte
1743 mr. r21,r21 ; (TEST/DEBUG) marked?
1744 beq+ fckact4 ; (TEST/DEBUG) No, good...
1746 lis r27,hi16(EXT(DebugWork)) ; (TEST/DEBUG)
1747 ori r27,r27,lo16(EXT(DebugWork)) ; (TEST/DEBUG)
1748 stw r27,0(r27) ; (TEST/DEBUG)
1749 BREAKPOINT_TRAP ; (TEST/DEBUG)
1751 fckact4: stb r29,SAVflags+3(r20) ; (TEST/DEBUG) Set the test byte
1752 lwz r20,SAVprefp(r20) ; (TEST/DEBUG) Next in list
1753 b fckact3 ; (TEST/DEBUG) Try it...
1755 fckact5: lwz r20,ACT_MACT_FPU(r26) ; (TEST/DEBUG) Get FPU chain
1756 li r29,0 ; (TEST/DEBUG)
1758 fckact6: mr. r20,r20 ; (TEST/DEBUG) Are there any?
1759 beq+ fcknact ; (TEST/DEBUG) No...
1761 stb r29,SAVflags+3(r20) ; (TEST/DEBUG) Clear the test byte
1762 lwz r20,SAVprefp(r20) ; (TEST/DEBUG) Next in list
1763 b fckact6 ; (TEST/DEBUG) Try it...
1765 fcknact: lwz r26,ACT_LOWER(r26) ; (TEST/DEBUG) Next activation
1766 b fckact ; (TEST/DEBUG)
1772 ; Make sure in use count matches found savearea. This is
1773 ; not always accurate. There is a variable "fuzz" factor in count.
1775 lis r28,hi16(EXT(default_pset)) ; (TEST/DEBUG)
1776 lis r27,hi16(EXT(DebugWork)) ; (TEST/DEBUG)
1777 ori r28,r28,lo16(EXT(default_pset)) ; (TEST/DEBUG)
1778 ori r27,r27,lo16(EXT(DebugWork)) ; (TEST/DEBUG)
1779 li r20,0 ; (TEST/DEBUG)
1780 lwz r26,0(r27) ; (TEST/DEBUG)
1781 lwz r27,psthreadcnt(r28) ; (TEST/DEBUG)
1782 mr. r26,r26 ; (TEST/DEBUG)
1783 lwz r28,psthreads(r28) ; (TEST/DEBUG)
1784 bnelr- ; (TEST/DEBUG)
1786 cknxtth: mr. r27,r27 ; (TEST/DEBUG)
1787 beq- cktotal ; (TEST/DEBUG)
1789 lwz r26,THREAD_TOP_ACT(r28) ; (TEST/DEBUG)
1791 ckact: mr. r26,r26 ; (TEST/DEBUG)
1792 bne+ ckact2 ; (TEST/DEBUG)
1794 lwz r28,THREAD_PSTHRN(r28) ; (TEST/DEBUG) Next in line
1795 subi r27,r27,1 ; (TEST/DEBUG)
1796 b cknxtth ; (TEST/DEBUG)
1798 ckact2: lwz r29,ACT_MACT_PCB(r26) ; (TEST/DEBUG)
1800 cknorm: mr. r29,r29 ; (TEST/DEBUG)
1801 beq- cknormd ; (TEST/DEBUG)
1803 addi r20,r20,1 ; (TEST/DEBUG) Count normal savearea
1805 lwz r29,SAVprev(r29) ; (TEST/DEBUG)
1806 b cknorm ; (TEST/DEBUG)
1808 cknormd: lwz r29,ACT_MACT_FPU(r26) ; (TEST/DEBUG)
1810 ckfpu: mr. r29,r29 ; (TEST/DEBUG)
1811 beq- ckfpud ; (TEST/DEBUG)
1813 lwz r21,SAVflags(r29) ; (TEST/DEBUG)
1814 rlwinm. r21,r21,0,0,0 ; (TEST/DEBUG) See if already counted
1815 bne- cknfpu ; (TEST/DEBUG)
1817 addi r20,r20,1 ; (TEST/DEBUG) Count fpu savearea
1819 cknfpu: lwz r29,SAVprefp(r29) ; (TEST/DEBUG)
1820 b ckfpu ; (TEST/DEBUG)
1822 ckfpud: lwz r29,ACT_MACT_VMX(r26) ; (TEST/DEBUG)
1824 ckvmx: mr. r29,r29 ; (TEST/DEBUG)
1825 beq- ckvmxd ; (TEST/DEBUG)
1827 lwz r21,SAVflags(r29) ; (TEST/DEBUG)
1828 rlwinm. r21,r21,0,0,1 ; (TEST/DEBUG) See if already counted
1829 bne- cknvmx ; (TEST/DEBUG)
1831 addi r20,r20,1 ; (TEST/DEBUG) Count vector savearea
1833 cknvmx: lwz r29,SAVprevec(r29) ; (TEST/DEBUG)
1834 b ckvmx ; (TEST/DEBUG)
1836 ckvmxd: lwz r26,ACT_LOWER(r26) ; (TEST/DEBUG) Next activation
1837 b ckact ; (TEST/DEBUG)
1839 cktotal: lis r28,hi16(EXT(saveanchor)) ; (TEST/DEBUG)
1840 lis r27,hi16(EXT(real_ncpus)) ; (TEST/DEBUG)
1841 ori r28,r28,lo16(EXT(saveanchor)) ; (TEST/DEBUG)
1842 ori r27,r27,lo16(EXT(real_ncpus)) ; (TEST/DEBUG)
1844 lwz r21,SVinuse(r28) ; (TEST/DEBUG)
1845 lwz r27,0(r27) ; (TEST/DEBUG) Get the number of CPUs
1846 sub. r29,r21,r20 ; (TEST/DEBUG) Get number accounted for
1847 blt- badsave ; (TEST/DEBUG) Have too many in use...
1848 sub r26,r29,r27 ; (TEST/DEBUG) Should be 1 unaccounted for for each processor
1849 cmpwi r26,10 ; (TEST/DEBUG) Allow a 10 area slop factor
1850 bltlr+ ; (TEST/DEBUG)
1852 badsave: lis r27,hi16(EXT(DebugWork)) ; (TEST/DEBUG)
1853 ori r27,r27,lo16(EXT(DebugWork)) ; (TEST/DEBUG)
1854 stw r27,0(r27) ; (TEST/DEBUG)
1855 BREAKPOINT_TRAP ; (TEST/DEBUG)