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