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_EE_BIT+1, MSR_EE_BIT-1
55 ENTRY(interrupt_enable, TAG_NO_FRAME_USED)
58 ori r0, r0, MASK(MSR_EE)
64 * Kernel debugger versions of the spl*() functions. This allows breakpoints
65 * in the spl*() functions.
68 /* Mask and unmask interrupts at the processor level */
69 ENTRY(db_interrupt_disable, TAG_NO_FRAME_USED)
71 rlwinm r0, r0, 0, MSR_EE_BIT+1, MSR_EE_BIT-1
75 ENTRY(db_interrupt_enable, TAG_NO_FRAME_USED)
77 ori r0, r0, MASK(MSR_EE)
83 * General entry for all debuggers. This gets us onto the debug stack and
84 * then back off at exit. We need to pass back R3 to caller.
87 ENTRY(Call_Debugger, TAG_NO_FRAME_USED)
89 mfmsr r7 ; Get the current MSR
90 mflr r0 ; Save the return
91 rlwinm r7,r7,0,MSR_EE_BIT+1,MSR_EE_BIT-1 ; Turn off interruptions
93 mfsprg r8,0 ; Get the per_proc block
94 stw r0,FM_LR_SAVE(r1) ; Save return on current stack
96 lwz r9,PP_DEBSTACKPTR(r8) ; Get the debug stack
97 cmpwi r9,0 ; Are we already on it?
100 mr r9,r1 ; We are already on the stack, so use the current value
101 subi r9,r9,FM_REDZONE+FM_SIZE ; Carve some extra space here
103 cdNewDeb: li r0,0 ; Clear this out
104 stw r1,FM_ARG0(r9) ; Save the old stack pointer as if it were the first arg
106 stw r0,PP_DEBSTACKPTR(r8) ; Mark debug stack as busy
108 subi r1,r9,FM_SIZE ; Carve a new frame
109 stw r0,FM_BACKPTR(r1) ; Chain back
111 bl EXT(Call_DebuggerC) ; Call the "C" phase of this
113 mfmsr r0 ; Get the MSR just in case it was enabled
114 addi r1,r1,FM_SIZE ; Pop off first stack frame
115 rlwinm r0,r0,0,MSR_EE_BIT+1,MSR_EE_BIT-1 ; Turn off interruptions enable bit
118 mfsprg r8,0 ; Get the per_proc block address
120 lwz r9,PP_DEBSTACK_TOP_SS(r8) ; Get the top of the stack
121 cmplw r1,r9 ; Have we hit the bottom of the debug stack?
122 lwz r1,FM_ARG0(r1) ; Get previous stack frame
123 lwz r0,FM_LR_SAVE(r1) ; Get return address
124 mtlr r0 ; Set the return point
125 bnelr ; Return if still on debug stack
127 stw r9,PP_DEBSTACKPTR(r8) ; Mark debug stack as free
131 /* The following routines are for C-support. They are usually
132 * inlined into the C using the specifications in proc_reg.h,
133 * but if optimisation is switched off, the inlining doesn't work
136 ENTRY(get_got, TAG_NO_FRAME_USED)
140 ENTRY(mflr, TAG_NO_FRAME_USED)
144 ENTRY(mfpvr, TAG_NO_FRAME_USED)
148 ENTRY(mtmsr, TAG_NO_FRAME_USED)
153 ENTRY(mfmsr, TAG_NO_FRAME_USED)
157 ENTRY(mtsrin, TAG_NO_FRAME_USED)
163 ENTRY(mfsrin, TAG_NO_FRAME_USED)
167 ENTRY(mtsdr1, TAG_NO_FRAME_USED)
171 ENTRY(mtdar, TAG_NO_FRAME_USED)
175 ENTRY(mfdar, TAG_NO_FRAME_USED)
179 ENTRY(mtdec, TAG_NO_FRAME_USED)
183 /* Decrementer frequency and realtime|timebase processor registers
184 * are different between ppc601 and ppc603/4, we define them all.
187 ENTRY(isync_mfdec, TAG_NO_FRAME_USED)
193 ENTRY(mftb, TAG_NO_FRAME_USED)
197 ENTRY(mftbu, TAG_NO_FRAME_USED)
201 ENTRY(mfrtcl, TAG_NO_FRAME_USED)
205 ENTRY(mfrtcu, TAG_NO_FRAME_USED)
209 ENTRY(tlbie, TAG_NO_FRAME_USED)
215 * Performance Monitor Register Support
218 ENTRY(mfmmcr0, TAG_NO_FRAME_USED)
222 ENTRY(mtmmcr0, TAG_NO_FRAME_USED)
226 ENTRY(mfmmcr1, TAG_NO_FRAME_USED)
230 ENTRY(mtmmcr1, TAG_NO_FRAME_USED)
234 ENTRY(mfmmcr2, TAG_NO_FRAME_USED)
238 ENTRY(mtmmcr2, TAG_NO_FRAME_USED)
242 ENTRY(mfpmc1, TAG_NO_FRAME_USED)
246 ENTRY(mtpmc1, TAG_NO_FRAME_USED)
250 ENTRY(mfpmc2, TAG_NO_FRAME_USED)
254 ENTRY(mtpmc2, TAG_NO_FRAME_USED)
258 ENTRY(mfpmc3, TAG_NO_FRAME_USED)
262 ENTRY(mtpmc3, TAG_NO_FRAME_USED)
266 ENTRY(mfpmc4, TAG_NO_FRAME_USED)
270 ENTRY(mtpmc4, TAG_NO_FRAME_USED)
274 ENTRY(mfsia, TAG_NO_FRAME_USED)
278 ENTRY(mfsda, TAG_NO_FRAME_USED)