2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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 License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
33 #include <mach_kgdb.h>
34 #include <mach_debug.h>
37 #include <ppc/proc_reg.h>
38 #include <mach/ppc/vm_param.h>
41 * vm_offset_t getrpc(void) - Return address of the function
42 * that called the current function
45 /* By using this function, we force the caller to save its LR in a known
46 * location, which we can pick up and return. See PowerPC ELF specs.
48 ENTRY(getrpc, TAG_NO_FRAME_USED)
49 lwz ARG0, FM_BACKPTR(r1) /* Load our backchain ptr */
50 lwz ARG0, FM_LR_SAVE(ARG0) /* Load previously saved LR */
55 * General entry for all debuggers. This gets us onto the debug stack and
56 * then back off at exit. We need to pass back R3 to caller.
59 ENTRY(Call_Debugger, TAG_NO_FRAME_USED)
62 lis r8,hi16(MASK(MSR_VEC)) ; Get the vector flag
63 mfmsr r7 ; Get the current MSR
64 ori r8,r8,lo16(MASK(MSR_EE)|MASK(MSR_FP)) ; Add the FP flag
65 mflr r0 ; Save the return
66 andc r7,r7,r8 ; Clear VEC and FP
69 mfsprg r8,1 ; Get the current activation
70 lwz r8,ACT_PER_PROC(r8) ; Get the per_proc block
71 stw r0,FM_LR_SAVE(r1) ; Save return on current stack
73 lwz r9,PP_DEBSTACKPTR(r8) ; Get the debug stack
74 cmpwi r9,0 ; Are we already on it?
77 mr r9,r1 ; We are already on the stack, so use the current value
78 subi r9,r9,FM_REDZONE+FM_SIZE ; Carve some extra space here
80 cdNewDeb: li r0,0 ; Clear this out
81 stw r1,FM_ARG0(r9) ; Save the old stack pointer as if it were the first arg
83 stw r0,PP_DEBSTACKPTR(r8) ; Mark debug stack as busy
85 subi r1,r9,FM_SIZE ; Carve a new frame
86 stw r0,FM_BACKPTR(r1) ; Chain back
88 bl EXT(Call_DebuggerC) ; Call the "C" phase of this
90 lis r8,hi16(MASK(MSR_VEC)) ; Get the vector flag
91 mfmsr r0 ; Get the current MSR
92 ori r8,r8,lo16(MASK(MSR_EE)|MASK(MSR_FP)) ; Add the FP flag
93 addi r1,r1,FM_SIZE ; Pop off first stack frame
94 andc r0,r0,r8 ; Turn off all the interesting stuff
97 mfsprg r8,1 ; Get the current activation
98 lwz r8,ACT_PER_PROC(r8) ; Get the per_proc block
100 lwz r9,PP_DEBSTACK_TOP_SS(r8) ; Get the top of the stack
101 cmplw r1,r9 ; Have we hit the bottom of the debug stack?
102 lwz r1,FM_ARG0(r1) ; Get previous stack frame
103 lwz r0,FM_LR_SAVE(r1) ; Get return address
104 mtlr r0 ; Set the return point
105 bnelr ; Return if still on debug stack
107 stw r9,PP_DEBSTACKPTR(r8) ; Mark debug stack as free
111 /* The following routines are for C-support. They are usually
112 * inlined into the C using the specifications in proc_reg.h,
113 * but if optimisation is switched off, the inlining doesn't work
116 ENTRY(get_got, TAG_NO_FRAME_USED)
120 ENTRY(mflr, TAG_NO_FRAME_USED)
124 ENTRY(mfpvr, TAG_NO_FRAME_USED)
128 ENTRY(mtmsr, TAG_NO_FRAME_USED)
133 ENTRY(mfmsr, TAG_NO_FRAME_USED)
137 ENTRY(mtsrin, TAG_NO_FRAME_USED)
143 ENTRY(mfsrin, TAG_NO_FRAME_USED)
147 ENTRY(mtsdr1, TAG_NO_FRAME_USED)
151 ENTRY(mtdar, TAG_NO_FRAME_USED)
155 ENTRY(mfdar, TAG_NO_FRAME_USED)
159 ENTRY(mtdec, TAG_NO_FRAME_USED)
163 ENTRY(cntlzw, TAG_NO_FRAME_USED)
167 /* Decrementer frequency and realtime|timebase processor registers
168 * are different between ppc601 and ppc603/4, we define them all.
171 ENTRY(isync_mfdec, TAG_NO_FRAME_USED)
177 ENTRY(mftb, TAG_NO_FRAME_USED)
181 ENTRY(mftbu, TAG_NO_FRAME_USED)
185 ENTRY(mfrtcl, TAG_NO_FRAME_USED)
189 ENTRY(mfrtcu, TAG_NO_FRAME_USED)
193 ENTRY(tlbie, TAG_NO_FRAME_USED)
199 * Performance Monitor Register Support
202 ENTRY(mfmmcr0, TAG_NO_FRAME_USED)
206 ENTRY(mtmmcr0, TAG_NO_FRAME_USED)
210 ENTRY(mfmmcr1, TAG_NO_FRAME_USED)
214 ENTRY(mtmmcr1, TAG_NO_FRAME_USED)
218 ENTRY(mfmmcr2, TAG_NO_FRAME_USED)
222 ENTRY(mtmmcr2, TAG_NO_FRAME_USED)
226 ENTRY(mfpmc1, TAG_NO_FRAME_USED)
230 ENTRY(mtpmc1, TAG_NO_FRAME_USED)
234 ENTRY(mfpmc2, TAG_NO_FRAME_USED)
238 ENTRY(mtpmc2, TAG_NO_FRAME_USED)
242 ENTRY(mfpmc3, TAG_NO_FRAME_USED)
246 ENTRY(mtpmc3, TAG_NO_FRAME_USED)
250 ENTRY(mfpmc4, TAG_NO_FRAME_USED)
254 ENTRY(mtpmc4, TAG_NO_FRAME_USED)
258 ENTRY(mfsia, TAG_NO_FRAME_USED)
262 ENTRY(mfsda, TAG_NO_FRAME_USED)
269 mfspr r3,hid1 ; Get the HID1
272 .globl EXT(hid0get64)
275 mfspr r4,hid0 ; Get the HID0
276 srdi r3,r4,32 ; Move top down
277 rlwinm r4,r4,0,0,31 ; Clean top
280 .globl EXT(hid5set64)
283 rlwinm r3,r3,0,1,0 ; Copy low 32 int high 32
284 rlwimi r3,r4,0,0,31 ; Inser the low part behind top
285 mtspr hid5,r3 ; Set it