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@
27 #include <mach_kgdb.h>
28 #include <mach_debug.h>
31 #include <ppc/proc_reg.h>
32 #include <mach/ppc/vm_param.h>
35 * vm_offset_t getrpc(void) - Return address of the function
36 * that called the current function
39 /* By using this function, we force the caller to save its LR in a known
40 * location, which we can pick up and return. See PowerPC ELF specs.
42 ENTRY(getrpc, TAG_NO_FRAME_USED)
43 lwz ARG0, FM_BACKPTR(r1) /* Load our backchain ptr */
44 lwz ARG0, FM_LR_SAVE(ARG0) /* Load previously saved LR */
48 /* Mask and unmask interrupts at the processor level */
49 ENTRY(interrupt_disable, TAG_NO_FRAME_USED)
51 rlwinm r0,r0,0,MSR_FP_BIT+1,MSR_FP_BIT-1 ; Force floating point off
52 rlwinm r0,r0,0,MSR_VEC_BIT+1,MSR_VEC_BIT-1 ; Force vectors off
53 rlwinm r0, r0, 0, MSR_EE_BIT+1, MSR_EE_BIT-1
58 ENTRY(interrupt_enable, TAG_NO_FRAME_USED)
61 ori r0, r0, MASK(MSR_EE)
67 * Kernel debugger versions of the spl*() functions. This allows breakpoints
68 * in the spl*() functions.
71 /* Mask and unmask interrupts at the processor level */
72 ENTRY(db_interrupt_disable, TAG_NO_FRAME_USED)
74 rlwinm r0,r0,0,MSR_FP_BIT+1,MSR_FP_BIT-1 ; Force floating point off
75 rlwinm r0,r0,0,MSR_VEC_BIT+1,MSR_VEC_BIT-1 ; Force vectors off
76 rlwinm r0, r0, 0, MSR_EE_BIT+1, MSR_EE_BIT-1
81 ENTRY(db_interrupt_enable, TAG_NO_FRAME_USED)
83 ori r0, r0, MASK(MSR_EE)
89 * General entry for all debuggers. This gets us onto the debug stack and
90 * then back off at exit. We need to pass back R3 to caller.
93 ENTRY(Call_Debugger, TAG_NO_FRAME_USED)
95 mfmsr r7 ; Get the current MSR
96 rlwinm r7,r7,0,MSR_FP_BIT+1,MSR_FP_BIT-1 ; Force floating point off
97 rlwinm r7,r7,0,MSR_VEC_BIT+1,MSR_VEC_BIT-1 ; Force vectors off
98 mflr r0 ; Save the return
99 rlwinm r7,r7,0,MSR_EE_BIT+1,MSR_EE_BIT-1 ; Turn off interruptions
102 mfsprg r8,0 ; Get the per_proc block
103 stw r0,FM_LR_SAVE(r1) ; Save return on current stack
105 lwz r9,PP_DEBSTACKPTR(r8) ; Get the debug stack
106 cmpwi r9,0 ; Are we already on it?
109 mr r9,r1 ; We are already on the stack, so use the current value
110 subi r9,r9,FM_REDZONE+FM_SIZE ; Carve some extra space here
112 cdNewDeb: li r0,0 ; Clear this out
113 stw r1,FM_ARG0(r9) ; Save the old stack pointer as if it were the first arg
115 stw r0,PP_DEBSTACKPTR(r8) ; Mark debug stack as busy
117 subi r1,r9,FM_SIZE ; Carve a new frame
118 stw r0,FM_BACKPTR(r1) ; Chain back
120 bl EXT(Call_DebuggerC) ; Call the "C" phase of this
122 mfmsr r0 ; Get the MSR just in case it was enabled
123 addi r1,r1,FM_SIZE ; Pop off first stack frame
124 rlwinm r0,r0,0,MSR_EE_BIT+1,MSR_EE_BIT-1 ; Turn off interruptions enable bit
127 mfsprg r8,0 ; Get the per_proc block address
129 lwz r9,PP_DEBSTACK_TOP_SS(r8) ; Get the top of the stack
130 cmplw r1,r9 ; Have we hit the bottom of the debug stack?
131 lwz r1,FM_ARG0(r1) ; Get previous stack frame
132 lwz r0,FM_LR_SAVE(r1) ; Get return address
133 mtlr r0 ; Set the return point
134 bnelr ; Return if still on debug stack
136 stw r9,PP_DEBSTACKPTR(r8) ; Mark debug stack as free
140 /* The following routines are for C-support. They are usually
141 * inlined into the C using the specifications in proc_reg.h,
142 * but if optimisation is switched off, the inlining doesn't work
145 ENTRY(get_got, TAG_NO_FRAME_USED)
149 ENTRY(mflr, TAG_NO_FRAME_USED)
153 ENTRY(mfpvr, TAG_NO_FRAME_USED)
157 ENTRY(mtmsr, TAG_NO_FRAME_USED)
162 ENTRY(mfmsr, TAG_NO_FRAME_USED)
166 ENTRY(mtsrin, TAG_NO_FRAME_USED)
172 ENTRY(mfsrin, TAG_NO_FRAME_USED)
176 ENTRY(mtsdr1, TAG_NO_FRAME_USED)
180 ENTRY(mtdar, TAG_NO_FRAME_USED)
184 ENTRY(mfdar, TAG_NO_FRAME_USED)
188 ENTRY(mtdec, TAG_NO_FRAME_USED)
192 /* Decrementer frequency and realtime|timebase processor registers
193 * are different between ppc601 and ppc603/4, we define them all.
196 ENTRY(isync_mfdec, TAG_NO_FRAME_USED)
202 ENTRY(mftb, TAG_NO_FRAME_USED)
206 ENTRY(mftbu, TAG_NO_FRAME_USED)
210 ENTRY(mfrtcl, TAG_NO_FRAME_USED)
214 ENTRY(mfrtcu, TAG_NO_FRAME_USED)
218 ENTRY(tlbie, TAG_NO_FRAME_USED)
224 * Performance Monitor Register Support
227 ENTRY(mfmmcr0, TAG_NO_FRAME_USED)
231 ENTRY(mtmmcr0, TAG_NO_FRAME_USED)
235 ENTRY(mfmmcr1, TAG_NO_FRAME_USED)
239 ENTRY(mtmmcr1, TAG_NO_FRAME_USED)
243 ENTRY(mfmmcr2, TAG_NO_FRAME_USED)
247 ENTRY(mtmmcr2, TAG_NO_FRAME_USED)
251 ENTRY(mfpmc1, TAG_NO_FRAME_USED)
255 ENTRY(mtpmc1, TAG_NO_FRAME_USED)
259 ENTRY(mfpmc2, TAG_NO_FRAME_USED)
263 ENTRY(mtpmc2, TAG_NO_FRAME_USED)
267 ENTRY(mfpmc3, TAG_NO_FRAME_USED)
271 ENTRY(mtpmc3, TAG_NO_FRAME_USED)
275 ENTRY(mfpmc4, TAG_NO_FRAME_USED)
279 ENTRY(mtpmc4, TAG_NO_FRAME_USED)
283 ENTRY(mfsia, TAG_NO_FRAME_USED)
287 ENTRY(mfsda, TAG_NO_FRAME_USED)