2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
30 #include <mach_kgdb.h>
31 #include <mach_debug.h>
34 #include <ppc/proc_reg.h>
35 #include <mach/ppc/vm_param.h>
38 * vm_offset_t getrpc(void) - Return address of the function
39 * that called the current function
42 /* By using this function, we force the caller to save its LR in a known
43 * location, which we can pick up and return. See PowerPC ELF specs.
45 ENTRY(getrpc, TAG_NO_FRAME_USED)
46 lwz ARG0, FM_BACKPTR(r1) /* Load our backchain ptr */
47 lwz ARG0, FM_LR_SAVE(ARG0) /* Load previously saved LR */
51 /* Mask and unmask interrupts at the processor level */
52 ENTRY(interrupt_disable, TAG_NO_FRAME_USED)
54 rlwinm r0,r0,0,MSR_FP_BIT+1,MSR_FP_BIT-1 ; Force floating point off
55 rlwinm r0,r0,0,MSR_VEC_BIT+1,MSR_VEC_BIT-1 ; Force vectors off
56 rlwinm r0, r0, 0, MSR_EE_BIT+1, MSR_EE_BIT-1
61 ENTRY(interrupt_enable, TAG_NO_FRAME_USED)
64 ori r0, r0, MASK(MSR_EE)
70 * Kernel debugger versions of the spl*() functions. This allows breakpoints
71 * in the spl*() functions.
74 /* Mask and unmask interrupts at the processor level */
75 ENTRY(db_interrupt_disable, TAG_NO_FRAME_USED)
77 rlwinm r0,r0,0,MSR_FP_BIT+1,MSR_FP_BIT-1 ; Force floating point off
78 rlwinm r0,r0,0,MSR_VEC_BIT+1,MSR_VEC_BIT-1 ; Force vectors off
79 rlwinm r0, r0, 0, MSR_EE_BIT+1, MSR_EE_BIT-1
84 ENTRY(db_interrupt_enable, TAG_NO_FRAME_USED)
86 ori r0, r0, MASK(MSR_EE)
92 * General entry for all debuggers. This gets us onto the debug stack and
93 * then back off at exit. We need to pass back R3 to caller.
96 ENTRY(Call_Debugger, TAG_NO_FRAME_USED)
98 mfmsr r7 ; Get the current MSR
99 rlwinm r7,r7,0,MSR_FP_BIT+1,MSR_FP_BIT-1 ; Force floating point off
100 rlwinm r7,r7,0,MSR_VEC_BIT+1,MSR_VEC_BIT-1 ; Force vectors off
101 mflr r0 ; Save the return
102 rlwinm r7,r7,0,MSR_EE_BIT+1,MSR_EE_BIT-1 ; Turn off interruptions
105 mfsprg r8,0 ; Get the per_proc block
106 stw r0,FM_LR_SAVE(r1) ; Save return on current stack
108 lwz r9,PP_DEBSTACKPTR(r8) ; Get the debug stack
109 cmpwi r9,0 ; Are we already on it?
112 mr r9,r1 ; We are already on the stack, so use the current value
113 subi r9,r9,FM_REDZONE+FM_SIZE ; Carve some extra space here
115 cdNewDeb: li r0,0 ; Clear this out
116 stw r1,FM_ARG0(r9) ; Save the old stack pointer as if it were the first arg
118 stw r0,PP_DEBSTACKPTR(r8) ; Mark debug stack as busy
120 subi r1,r9,FM_SIZE ; Carve a new frame
121 stw r0,FM_BACKPTR(r1) ; Chain back
123 bl EXT(Call_DebuggerC) ; Call the "C" phase of this
125 mfmsr r0 ; Get the MSR just in case it was enabled
126 addi r1,r1,FM_SIZE ; Pop off first stack frame
127 rlwinm r0,r0,0,MSR_EE_BIT+1,MSR_EE_BIT-1 ; Turn off interruptions enable bit
130 mfsprg r8,0 ; Get the per_proc block address
132 lwz r9,PP_DEBSTACK_TOP_SS(r8) ; Get the top of the stack
133 cmplw r1,r9 ; Have we hit the bottom of the debug stack?
134 lwz r1,FM_ARG0(r1) ; Get previous stack frame
135 lwz r0,FM_LR_SAVE(r1) ; Get return address
136 mtlr r0 ; Set the return point
137 bnelr ; Return if still on debug stack
139 stw r9,PP_DEBSTACKPTR(r8) ; Mark debug stack as free
143 /* The following routines are for C-support. They are usually
144 * inlined into the C using the specifications in proc_reg.h,
145 * but if optimisation is switched off, the inlining doesn't work
148 ENTRY(get_got, TAG_NO_FRAME_USED)
152 ENTRY(mflr, TAG_NO_FRAME_USED)
156 ENTRY(mfpvr, TAG_NO_FRAME_USED)
160 ENTRY(mtmsr, TAG_NO_FRAME_USED)
165 ENTRY(mfmsr, TAG_NO_FRAME_USED)
169 ENTRY(mtsrin, TAG_NO_FRAME_USED)
175 ENTRY(mfsrin, TAG_NO_FRAME_USED)
179 ENTRY(mtsdr1, TAG_NO_FRAME_USED)
183 ENTRY(mtdar, TAG_NO_FRAME_USED)
187 ENTRY(mfdar, TAG_NO_FRAME_USED)
191 ENTRY(mtdec, TAG_NO_FRAME_USED)
195 /* Decrementer frequency and realtime|timebase processor registers
196 * are different between ppc601 and ppc603/4, we define them all.
199 ENTRY(isync_mfdec, TAG_NO_FRAME_USED)
205 ENTRY(mftb, TAG_NO_FRAME_USED)
209 ENTRY(mftbu, TAG_NO_FRAME_USED)
213 ENTRY(mfrtcl, TAG_NO_FRAME_USED)
217 ENTRY(mfrtcu, TAG_NO_FRAME_USED)
221 ENTRY(tlbie, TAG_NO_FRAME_USED)
227 * Performance Monitor Register Support
230 ENTRY(mfmmcr0, TAG_NO_FRAME_USED)
234 ENTRY(mtmmcr0, TAG_NO_FRAME_USED)
238 ENTRY(mfmmcr1, TAG_NO_FRAME_USED)
242 ENTRY(mtmmcr1, TAG_NO_FRAME_USED)
246 ENTRY(mfmmcr2, TAG_NO_FRAME_USED)
250 ENTRY(mtmmcr2, TAG_NO_FRAME_USED)
254 ENTRY(mfpmc1, TAG_NO_FRAME_USED)
258 ENTRY(mtpmc1, TAG_NO_FRAME_USED)
262 ENTRY(mfpmc2, TAG_NO_FRAME_USED)
266 ENTRY(mtpmc2, TAG_NO_FRAME_USED)
270 ENTRY(mfpmc3, TAG_NO_FRAME_USED)
274 ENTRY(mtpmc3, TAG_NO_FRAME_USED)
278 ENTRY(mfpmc4, TAG_NO_FRAME_USED)
282 ENTRY(mtpmc4, TAG_NO_FRAME_USED)
286 ENTRY(mfsia, TAG_NO_FRAME_USED)
290 ENTRY(mfsda, TAG_NO_FRAME_USED)