]> git.saurik.com Git - apple/xnu.git/blame - osfmk/ppc/misc_asm.s
xnu-792.6.76.tar.gz
[apple/xnu.git] / osfmk / ppc / misc_asm.s
CommitLineData
1c79356b 1/*
3a60a9f5 2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
1c79356b
A
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
37839358
A
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.
1c79356b 11 *
37839358
A
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
1c79356b
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
37839358
A
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
1c79356b
A
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22/*
23 * @OSF_COPYRIGHT@
24 */
25
26#include <mach_kdb.h>
27#include <mach_kgdb.h>
28#include <mach_debug.h>
29#include <assym.s>
30#include <ppc/asm.h>
31#include <ppc/proc_reg.h>
32#include <mach/ppc/vm_param.h>
33
34/*
35 * vm_offset_t getrpc(void) - Return address of the function
36 * that called the current function
37 */
38
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.
41 */
42ENTRY(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 */
45 blr /* And return */
46
47
1c79356b
A
48/*
49 * General entry for all debuggers. This gets us onto the debug stack and
50 * then back off at exit. We need to pass back R3 to caller.
51 */
52
53ENTRY(Call_Debugger, TAG_NO_FRAME_USED)
54
55e303ae
A
55
56 lis r8,hi16(MASK(MSR_VEC)) ; Get the vector flag
1c79356b 57 mfmsr r7 ; Get the current MSR
55e303ae 58 ori r8,r8,lo16(MASK(MSR_EE)|MASK(MSR_FP)) ; Add the FP flag
1c79356b 59 mflr r0 ; Save the return
55e303ae 60 andc r7,r7,r8 ; Clear VEC and FP
1c79356b 61 mtmsr r7 ; Do it
9bccf70c 62 isync
91447636
A
63 mfsprg r8,1 ; Get the current activation
64 lwz r8,ACT_PER_PROC(r8) ; Get the per_proc block
1c79356b
A
65 stw r0,FM_LR_SAVE(r1) ; Save return on current stack
66
67 lwz r9,PP_DEBSTACKPTR(r8) ; Get the debug stack
68 cmpwi r9,0 ; Are we already on it?
69 bne cdNewDeb ; No...
70
71 mr r9,r1 ; We are already on the stack, so use the current value
72 subi r9,r9,FM_REDZONE+FM_SIZE ; Carve some extra space here
73
74cdNewDeb: li r0,0 ; Clear this out
75 stw r1,FM_ARG0(r9) ; Save the old stack pointer as if it were the first arg
76
77 stw r0,PP_DEBSTACKPTR(r8) ; Mark debug stack as busy
78
79 subi r1,r9,FM_SIZE ; Carve a new frame
80 stw r0,FM_BACKPTR(r1) ; Chain back
81
82 bl EXT(Call_DebuggerC) ; Call the "C" phase of this
83
55e303ae
A
84 lis r8,hi16(MASK(MSR_VEC)) ; Get the vector flag
85 mfmsr r0 ; Get the current MSR
86 ori r8,r8,lo16(MASK(MSR_EE)|MASK(MSR_FP)) ; Add the FP flag
1c79356b 87 addi r1,r1,FM_SIZE ; Pop off first stack frame
55e303ae 88 andc r0,r0,r8 ; Turn off all the interesting stuff
1c79356b
A
89 mtmsr r0
90
91447636
A
91 mfsprg r8,1 ; Get the current activation
92 lwz r8,ACT_PER_PROC(r8) ; Get the per_proc block
1c79356b
A
93
94 lwz r9,PP_DEBSTACK_TOP_SS(r8) ; Get the top of the stack
95 cmplw r1,r9 ; Have we hit the bottom of the debug stack?
96 lwz r1,FM_ARG0(r1) ; Get previous stack frame
97 lwz r0,FM_LR_SAVE(r1) ; Get return address
98 mtlr r0 ; Set the return point
99 bnelr ; Return if still on debug stack
100
101 stw r9,PP_DEBSTACKPTR(r8) ; Mark debug stack as free
102 blr
103
104
105/* The following routines are for C-support. They are usually
106 * inlined into the C using the specifications in proc_reg.h,
107 * but if optimisation is switched off, the inlining doesn't work
108 */
109
110ENTRY(get_got, TAG_NO_FRAME_USED)
111 mr ARG0, r2
112 blr
113
114ENTRY(mflr, TAG_NO_FRAME_USED)
115 mflr ARG0
116 blr
117
118ENTRY(mfpvr, TAG_NO_FRAME_USED)
119 mfpvr ARG0
120 blr
121
122ENTRY(mtmsr, TAG_NO_FRAME_USED)
123 mtmsr ARG0
124 isync
125 blr
126
127ENTRY(mfmsr, TAG_NO_FRAME_USED)
128 mfmsr ARG0
129 blr
130
131ENTRY(mtsrin, TAG_NO_FRAME_USED)
132 isync
133 mtsrin ARG0, ARG1
134 isync
135 blr
136
137ENTRY(mfsrin, TAG_NO_FRAME_USED)
138 mfsrin ARG0, ARG0
139 blr
140
141ENTRY(mtsdr1, TAG_NO_FRAME_USED)
142 mtsdr1 ARG0
143 blr
144
145ENTRY(mtdar, TAG_NO_FRAME_USED)
146 mtdar ARG0
147 blr
148
149ENTRY(mfdar, TAG_NO_FRAME_USED)
150 mfdar ARG0
151 blr
152
153ENTRY(mtdec, TAG_NO_FRAME_USED)
154 mtdec ARG0
155 blr
156
55e303ae
A
157ENTRY(cntlzw, TAG_NO_FRAME_USED)
158 cntlzw r3,r3
159 blr
160
1c79356b
A
161/* Decrementer frequency and realtime|timebase processor registers
162 * are different between ppc601 and ppc603/4, we define them all.
163 */
164
165ENTRY(isync_mfdec, TAG_NO_FRAME_USED)
166 isync
167 mfdec ARG0
168 blr
169
170
171ENTRY(mftb, TAG_NO_FRAME_USED)
172 mftb ARG0
173 blr
174
175ENTRY(mftbu, TAG_NO_FRAME_USED)
176 mftbu ARG0
177 blr
178
179ENTRY(mfrtcl, TAG_NO_FRAME_USED)
180 mfspr ARG0, 5
181 blr
182
183ENTRY(mfrtcu, TAG_NO_FRAME_USED)
184 mfspr ARG0, 4
185 blr
186
187ENTRY(tlbie, TAG_NO_FRAME_USED)
188 tlbie ARG0
189 blr
190
191
192/*
193 * Performance Monitor Register Support
194 */
195
196ENTRY(mfmmcr0, TAG_NO_FRAME_USED)
197 mfspr r3,mmcr0
198 blr
199
200ENTRY(mtmmcr0, TAG_NO_FRAME_USED)
201 mtspr mmcr0,r3
202 blr
203
204ENTRY(mfmmcr1, TAG_NO_FRAME_USED)
205 mfspr r3,mmcr1
206 blr
207
208ENTRY(mtmmcr1, TAG_NO_FRAME_USED)
209 mtspr mmcr1,r3
210 blr
211
212ENTRY(mfmmcr2, TAG_NO_FRAME_USED)
213 mfspr r3,mmcr2
214 blr
215
216ENTRY(mtmmcr2, TAG_NO_FRAME_USED)
217 mtspr mmcr2,r3
218 blr
219
220ENTRY(mfpmc1, TAG_NO_FRAME_USED)
221 mfspr r3,pmc1
222 blr
223
224ENTRY(mtpmc1, TAG_NO_FRAME_USED)
225 mtspr pmc1,r3
226 blr
227
228ENTRY(mfpmc2, TAG_NO_FRAME_USED)
229 mfspr r3,pmc2
230 blr
231
232ENTRY(mtpmc2, TAG_NO_FRAME_USED)
233 mtspr pmc2,r3
234 blr
235
236ENTRY(mfpmc3, TAG_NO_FRAME_USED)
237 mfspr r3,pmc3
238 blr
239
240ENTRY(mtpmc3, TAG_NO_FRAME_USED)
241 mtspr pmc3,r3
242 blr
243
244ENTRY(mfpmc4, TAG_NO_FRAME_USED)
245 mfspr r3,pmc4
246 blr
247
248ENTRY(mtpmc4, TAG_NO_FRAME_USED)
249 mtspr pmc4,r3
250 blr
251
252ENTRY(mfsia, TAG_NO_FRAME_USED)
253 mfspr r3,sia
254 blr
255
256ENTRY(mfsda, TAG_NO_FRAME_USED)
257 mfspr r3,sda
258 blr
259
3a60a9f5
A
260 .globl EXT(hid1get)
261LEXT(hid1get)
262
263 mfspr r3,hid1 ; Get the HID1
264 blr
265
55e303ae 266 .globl EXT(hid0get64)
55e303ae
A
267LEXT(hid0get64)
268
269 mfspr r4,hid0 ; Get the HID0
270 srdi r3,r4,32 ; Move top down
271 rlwinm r4,r4,0,0,31 ; Clean top
272 blr
e5568f75
A
273
274 .globl EXT(hid5set64)
275LEXT(hid5set64)
276
277 rlwinm r3,r3,0,1,0 ; Copy low 32 int high 32
278 rlwimi r3,r4,0,0,31 ; Inser the low part behind top
279 mtspr hid5,r3 ; Set it
280 isync ; Wait for it
281 blr