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)
53 lis r8,hi16(MASK(MSR_VEC)) ; Get the vector flag
54 mfmsr r0 ; Save the MSR
55 ori r8,r8,lo16(MASK(MSR_EE)|MASK(MSR_FP)) ; Add the FP flag
56 andc r0,r0,r8 ; Clear VEC, FP, DR, and EE
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)
76 lis r8,hi16(MASK(MSR_VEC)) ; Get the vector flag
77 mfmsr r0 ; Save the MSR
78 ori r8,r8,lo16(MASK(MSR_EE)|MASK(MSR_FP)) ; Add the FP flag
79 andc r0,r0,r8 ; Clear VEC, FP, DR, and EE
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)
99 lis r8,hi16(MASK(MSR_VEC)) ; Get the vector flag
100 mfmsr r7 ; Get the current MSR
101 ori r8,r8,lo16(MASK(MSR_EE)|MASK(MSR_FP)) ; Add the FP flag
102 mflr r0 ; Save the return
103 andc r7,r7,r8 ; Clear VEC and FP
106 mfsprg r8,0 ; Get the per_proc block
107 stw r0,FM_LR_SAVE(r1) ; Save return on current stack
109 lwz r9,PP_DEBSTACKPTR(r8) ; Get the debug stack
110 cmpwi r9,0 ; Are we already on it?
113 mr r9,r1 ; We are already on the stack, so use the current value
114 subi r9,r9,FM_REDZONE+FM_SIZE ; Carve some extra space here
116 cdNewDeb: li r0,0 ; Clear this out
117 stw r1,FM_ARG0(r9) ; Save the old stack pointer as if it were the first arg
119 stw r0,PP_DEBSTACKPTR(r8) ; Mark debug stack as busy
121 subi r1,r9,FM_SIZE ; Carve a new frame
122 stw r0,FM_BACKPTR(r1) ; Chain back
124 bl EXT(Call_DebuggerC) ; Call the "C" phase of this
126 lis r8,hi16(MASK(MSR_VEC)) ; Get the vector flag
127 mfmsr r0 ; Get the current MSR
128 ori r8,r8,lo16(MASK(MSR_EE)|MASK(MSR_FP)) ; Add the FP flag
129 addi r1,r1,FM_SIZE ; Pop off first stack frame
130 andc r0,r0,r8 ; Turn off all the interesting stuff
133 mfsprg r8,0 ; Get the per_proc block address
135 lwz r9,PP_DEBSTACK_TOP_SS(r8) ; Get the top of the stack
136 cmplw r1,r9 ; Have we hit the bottom of the debug stack?
137 lwz r1,FM_ARG0(r1) ; Get previous stack frame
138 lwz r0,FM_LR_SAVE(r1) ; Get return address
139 mtlr r0 ; Set the return point
140 bnelr ; Return if still on debug stack
142 stw r9,PP_DEBSTACKPTR(r8) ; Mark debug stack as free
146 /* The following routines are for C-support. They are usually
147 * inlined into the C using the specifications in proc_reg.h,
148 * but if optimisation is switched off, the inlining doesn't work
151 ENTRY(get_got, TAG_NO_FRAME_USED)
155 ENTRY(mflr, TAG_NO_FRAME_USED)
159 ENTRY(mfpvr, TAG_NO_FRAME_USED)
163 ENTRY(mtmsr, TAG_NO_FRAME_USED)
168 ENTRY(mfmsr, TAG_NO_FRAME_USED)
172 ENTRY(mtsrin, TAG_NO_FRAME_USED)
178 ENTRY(mfsrin, TAG_NO_FRAME_USED)
182 ENTRY(mtsdr1, TAG_NO_FRAME_USED)
186 ENTRY(mtdar, TAG_NO_FRAME_USED)
190 ENTRY(mfdar, TAG_NO_FRAME_USED)
194 ENTRY(mtdec, TAG_NO_FRAME_USED)
198 ENTRY(cntlzw, TAG_NO_FRAME_USED)
202 /* Decrementer frequency and realtime|timebase processor registers
203 * are different between ppc601 and ppc603/4, we define them all.
206 ENTRY(isync_mfdec, TAG_NO_FRAME_USED)
212 ENTRY(mftb, TAG_NO_FRAME_USED)
216 ENTRY(mftbu, TAG_NO_FRAME_USED)
220 ENTRY(mfrtcl, TAG_NO_FRAME_USED)
224 ENTRY(mfrtcu, TAG_NO_FRAME_USED)
228 ENTRY(tlbie, TAG_NO_FRAME_USED)
234 * Performance Monitor Register Support
237 ENTRY(mfmmcr0, TAG_NO_FRAME_USED)
241 ENTRY(mtmmcr0, TAG_NO_FRAME_USED)
245 ENTRY(mfmmcr1, TAG_NO_FRAME_USED)
249 ENTRY(mtmmcr1, TAG_NO_FRAME_USED)
253 ENTRY(mfmmcr2, TAG_NO_FRAME_USED)
257 ENTRY(mtmmcr2, TAG_NO_FRAME_USED)
261 ENTRY(mfpmc1, TAG_NO_FRAME_USED)
265 ENTRY(mtpmc1, TAG_NO_FRAME_USED)
269 ENTRY(mfpmc2, TAG_NO_FRAME_USED)
273 ENTRY(mtpmc2, TAG_NO_FRAME_USED)
277 ENTRY(mfpmc3, TAG_NO_FRAME_USED)
281 ENTRY(mtpmc3, TAG_NO_FRAME_USED)
285 ENTRY(mfpmc4, TAG_NO_FRAME_USED)
289 ENTRY(mtpmc4, TAG_NO_FRAME_USED)
293 ENTRY(mfsia, TAG_NO_FRAME_USED)
297 ENTRY(mfsda, TAG_NO_FRAME_USED)
301 .globl EXT(hid0get64)
305 mfspr r4,hid0 ; Get the HID0
306 srdi r3,r4,32 ; Move top down
307 rlwinm r4,r4,0,0,31 ; Clean top