2 * Copyright (c) 2000-2004 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@
29 #include <mach/mach_types.h>
30 #include <mach/exception_types.h>
31 #include <ppc/exception.h>
32 #include <ppc/proc_reg.h>
33 #include <kdp/kdp_internal.h>
34 #include <ppc/savearea.h>
35 #include <kern/debug.h>
36 #include <IOKit/IOPlatformExpert.h>
39 #include <kern/thread.h>
40 #include <ppc/thread.h>
41 #include <vm/vm_map.h>
44 #define KDP_TEST_HARNESS 0
46 #define dprintf(x) kprintf x
51 void print_saved_state(void *);
53 void kdp_trap( unsigned int, struct savearea
*saved_state
);
55 boolean_t
kdp_call_kdb(void);
57 extern pmap_t kdp_pmap
;
58 extern uint32_t kdp_src_high32
;
61 extern unsigned kdp_vm_read(caddr_t src
, caddr_t dst
, unsigned len
);
64 machine_trace_thread(thread_t thread
, uint32_t tracepos
, uint32_t tracebound
, int nframes
, boolean_t user_p
);
67 machine_trace_thread64(thread_t thread
, uint32_t tracepos
, uint32_t tracebound
, int nframes
, boolean_t user_p
);
70 machine_read64(addr64_t srcaddr
, caddr_t dstaddr
, uint32_t len
);
76 unsigned short *remote_port
,
77 unsigned int exception
,
86 kdp_exception_t
*rq
= (kdp_exception_t
*)&aligned_pkt
;
88 bcopy((char *)pkt
, (char *)rq
, sizeof(*rq
));
89 rq
->hdr
.request
= KDP_EXCEPTION
;
91 rq
->hdr
.seq
= kdp
.exception_seq
;
93 rq
->hdr
.len
= sizeof (*rq
) + sizeof(kdp_exc_info_t
);
96 rq
->exc_info
[0].cpu
= 0;
97 rq
->exc_info
[0].exception
= exception
;
98 rq
->exc_info
[0].code
= code
;
99 rq
->exc_info
[0].subcode
= subcode
;
101 rq
->hdr
.len
+= rq
->n_exc_info
* sizeof (kdp_exc_info_t
);
103 bcopy((char *)rq
, (char *)pkt
, rq
->hdr
.len
);
105 kdp
.exception_ack_needed
= TRUE
;
107 *remote_port
= kdp
.exception_port
;
117 kdp_exception_ack_t aligned_pkt
;
118 kdp_exception_ack_t
*rq
= (kdp_exception_ack_t
*)&aligned_pkt
;
120 if (len
< sizeof (*rq
))
123 bcopy((char *)pkt
, (char *)rq
, sizeof(*rq
));
125 if (!rq
->hdr
.is_reply
|| rq
->hdr
.request
!= KDP_EXCEPTION
)
128 dprintf(("kdp_exception_ack seq %x %x\n", rq
->hdr
.seq
, kdp
.exception_seq
));
130 if (rq
->hdr
.seq
== kdp
.exception_seq
) {
131 kdp
.exception_ack_needed
= FALSE
;
139 struct ppc_thread_state
*state
142 struct savearea
*saved_state
;
144 saved_state
= kdp
.saved_state
;
146 bzero((char *)state
,sizeof (struct ppc_thread_state
)) ;
148 state
->srr0
= (unsigned int)saved_state
->save_srr0
;
149 state
->srr1
= (unsigned int)saved_state
->save_srr1
;
150 state
->r0
= (unsigned int)saved_state
->save_r0
;
151 state
->r1
= (unsigned int)saved_state
->save_r1
;
152 state
->r2
= (unsigned int)saved_state
->save_r2
;
153 state
->r3
= (unsigned int)saved_state
->save_r3
;
154 state
->r4
= (unsigned int)saved_state
->save_r4
;
155 state
->r5
= (unsigned int)saved_state
->save_r5
;
156 state
->r6
= (unsigned int)saved_state
->save_r6
;
157 state
->r7
= (unsigned int)saved_state
->save_r7
;
158 state
->r8
= (unsigned int)saved_state
->save_r8
;
159 state
->r9
= (unsigned int)saved_state
->save_r9
;
160 state
->r10
= (unsigned int)saved_state
->save_r10
;
161 state
->r11
= (unsigned int)saved_state
->save_r11
;
162 state
->r12
= (unsigned int)saved_state
->save_r12
;
163 state
->r13
= (unsigned int)saved_state
->save_r13
;
164 state
->r14
= (unsigned int)saved_state
->save_r14
;
165 state
->r15
= (unsigned int)saved_state
->save_r15
;
166 state
->r16
= (unsigned int)saved_state
->save_r16
;
167 state
->r17
= (unsigned int)saved_state
->save_r17
;
168 state
->r18
= (unsigned int)saved_state
->save_r18
;
169 state
->r19
= (unsigned int)saved_state
->save_r19
;
170 state
->r20
= (unsigned int)saved_state
->save_r20
;
171 state
->r21
= (unsigned int)saved_state
->save_r21
;
172 state
->r22
= (unsigned int)saved_state
->save_r22
;
173 state
->r23
= (unsigned int)saved_state
->save_r23
;
174 state
->r24
= (unsigned int)saved_state
->save_r24
;
175 state
->r25
= (unsigned int)saved_state
->save_r25
;
176 state
->r26
= (unsigned int)saved_state
->save_r26
;
177 state
->r27
= (unsigned int)saved_state
->save_r27
;
178 state
->r28
= (unsigned int)saved_state
->save_r28
;
179 state
->r29
= (unsigned int)saved_state
->save_r29
;
180 state
->r30
= (unsigned int)saved_state
->save_r30
;
181 state
->r31
= (unsigned int)saved_state
->save_r31
;
182 state
->cr
= (unsigned int)saved_state
->save_cr
;
183 state
->xer
= (unsigned int)saved_state
->save_xer
;
184 state
->lr
= (unsigned int)saved_state
->save_lr
;
185 state
->ctr
= (unsigned int)saved_state
->save_ctr
;
189 kdp_getintegerstate64(
190 struct ppc_thread_state64
*state
193 struct savearea
*saved_state
;
195 saved_state
= kdp
.saved_state
;
197 bzero((char *)state
,sizeof (struct ppc_thread_state64
)) ;
199 state
->srr0
= saved_state
->save_srr0
;
200 state
->srr1
= saved_state
->save_srr1
;
201 state
->r0
= saved_state
->save_r0
;
202 state
->r1
= saved_state
->save_r1
;
203 state
->r2
= saved_state
->save_r2
;
204 state
->r3
= saved_state
->save_r3
;
205 state
->r4
= saved_state
->save_r4
;
206 state
->r5
= saved_state
->save_r5
;
207 state
->r6
= saved_state
->save_r6
;
208 state
->r7
= saved_state
->save_r7
;
209 state
->r8
= saved_state
->save_r8
;
210 state
->r9
= saved_state
->save_r9
;
211 state
->r10
= saved_state
->save_r10
;
212 state
->r11
= saved_state
->save_r11
;
213 state
->r12
= saved_state
->save_r12
;
214 state
->r13
= saved_state
->save_r13
;
215 state
->r14
= saved_state
->save_r14
;
216 state
->r15
= saved_state
->save_r15
;
217 state
->r16
= saved_state
->save_r16
;
218 state
->r17
= saved_state
->save_r17
;
219 state
->r18
= saved_state
->save_r18
;
220 state
->r19
= saved_state
->save_r19
;
221 state
->r20
= saved_state
->save_r20
;
222 state
->r21
= saved_state
->save_r21
;
223 state
->r22
= saved_state
->save_r22
;
224 state
->r23
= saved_state
->save_r23
;
225 state
->r24
= saved_state
->save_r24
;
226 state
->r25
= saved_state
->save_r25
;
227 state
->r26
= saved_state
->save_r26
;
228 state
->r27
= saved_state
->save_r27
;
229 state
->r28
= saved_state
->save_r28
;
230 state
->r29
= saved_state
->save_r29
;
231 state
->r30
= saved_state
->save_r30
;
232 state
->r31
= saved_state
->save_r31
;
233 state
->cr
= saved_state
->save_cr
;
234 state
->xer
= saved_state
->save_xer
;
235 state
->lr
= saved_state
->save_lr
;
236 state
->ctr
= saved_state
->save_ctr
;
240 kdp_machine_read_regs(
249 case PPC_THREAD_STATE
:
250 dprintf(("kdp_readregs THREAD_STATE\n"));
251 kdp_getintegerstate((struct ppc_thread_state
*)data
);
252 *size
= PPC_THREAD_STATE_COUNT
* sizeof(int);
253 return KDPERR_NO_ERROR
;
255 case PPC_THREAD_STATE64
:
256 dprintf(("kdp_readregs THREAD_STATE\n"));
257 kdp_getintegerstate64((struct ppc_thread_state64
*)data
);
258 *size
= PPC_THREAD_STATE64_COUNT
* sizeof(int);
259 return KDPERR_NO_ERROR
;
261 case PPC_FLOAT_STATE
:
262 dprintf(("kdp_readregs THREAD_FPSTATE\n"));
263 bzero((char *)data
,sizeof(struct ppc_float_state
));
264 *size
= PPC_FLOAT_STATE_COUNT
* sizeof(int);
265 return KDPERR_NO_ERROR
;
268 dprintf(("kdp_readregs bad flavor %d\n"));
269 return KDPERR_BADFLAVOR
;
275 struct ppc_thread_state
*state
278 struct savearea
*saved_state
;
280 saved_state
= kdp
.saved_state
;
282 saved_state
->save_srr0
= state
->srr0
;
283 saved_state
->save_srr1
= state
->srr1
;
284 saved_state
->save_r0
= state
->r0
;
285 saved_state
->save_r1
= state
->r1
;
286 saved_state
->save_r2
= state
->r2
;
287 saved_state
->save_r3
= state
->r3
;
288 saved_state
->save_r4
= state
->r4
;
289 saved_state
->save_r5
= state
->r5
;
290 saved_state
->save_r6
= state
->r6
;
291 saved_state
->save_r7
= state
->r7
;
292 saved_state
->save_r8
= state
->r8
;
293 saved_state
->save_r9
= state
->r9
;
294 saved_state
->save_r10
= state
->r10
;
295 saved_state
->save_r11
= state
->r11
;
296 saved_state
->save_r12
= state
->r12
;
297 saved_state
->save_r13
= state
->r13
;
298 saved_state
->save_r14
= state
->r14
;
299 saved_state
->save_r15
= state
->r15
;
300 saved_state
->save_r16
= state
->r16
;
301 saved_state
->save_r17
= state
->r17
;
302 saved_state
->save_r18
= state
->r18
;
303 saved_state
->save_r19
= state
->r19
;
304 saved_state
->save_r20
= state
->r20
;
305 saved_state
->save_r21
= state
->r21
;
306 saved_state
->save_r22
= state
->r22
;
307 saved_state
->save_r23
= state
->r23
;
308 saved_state
->save_r24
= state
->r24
;
309 saved_state
->save_r25
= state
->r25
;
310 saved_state
->save_r26
= state
->r26
;
311 saved_state
->save_r27
= state
->r27
;
312 saved_state
->save_r28
= state
->r28
;
313 saved_state
->save_r29
= state
->r29
;
314 saved_state
->save_r30
= state
->r30
;
315 saved_state
->save_r31
= state
->r31
;
316 saved_state
->save_cr
= state
->cr
;
317 saved_state
->save_xer
= state
->xer
;
318 saved_state
->save_lr
= state
->lr
;
319 saved_state
->save_ctr
= state
->ctr
;
323 kdp_setintegerstate64(
324 struct ppc_thread_state64
*state
327 struct savearea
*saved_state
;
329 saved_state
= kdp
.saved_state
;
331 saved_state
->save_srr0
= state
->srr0
;
332 saved_state
->save_srr1
= state
->srr1
;
333 saved_state
->save_r0
= state
->r0
;
334 saved_state
->save_r1
= state
->r1
;
335 saved_state
->save_r2
= state
->r2
;
336 saved_state
->save_r3
= state
->r3
;
337 saved_state
->save_r4
= state
->r4
;
338 saved_state
->save_r5
= state
->r5
;
339 saved_state
->save_r6
= state
->r6
;
340 saved_state
->save_r7
= state
->r7
;
341 saved_state
->save_r8
= state
->r8
;
342 saved_state
->save_r9
= state
->r9
;
343 saved_state
->save_r10
= state
->r10
;
344 saved_state
->save_r11
= state
->r11
;
345 saved_state
->save_r12
= state
->r12
;
346 saved_state
->save_r13
= state
->r13
;
347 saved_state
->save_r14
= state
->r14
;
348 saved_state
->save_r15
= state
->r15
;
349 saved_state
->save_r16
= state
->r16
;
350 saved_state
->save_r17
= state
->r17
;
351 saved_state
->save_r18
= state
->r18
;
352 saved_state
->save_r19
= state
->r19
;
353 saved_state
->save_r20
= state
->r20
;
354 saved_state
->save_r21
= state
->r21
;
355 saved_state
->save_r22
= state
->r22
;
356 saved_state
->save_r23
= state
->r23
;
357 saved_state
->save_r24
= state
->r24
;
358 saved_state
->save_r25
= state
->r25
;
359 saved_state
->save_r26
= state
->r26
;
360 saved_state
->save_r27
= state
->r27
;
361 saved_state
->save_r28
= state
->r28
;
362 saved_state
->save_r29
= state
->r29
;
363 saved_state
->save_r30
= state
->r30
;
364 saved_state
->save_r31
= state
->r31
;
365 saved_state
->save_cr
= state
->cr
;
366 saved_state
->save_xer
= state
->xer
;
367 saved_state
->save_lr
= state
->lr
;
368 saved_state
->save_ctr
= state
->ctr
;
372 kdp_machine_write_regs(
381 case PPC_THREAD_STATE
:
382 dprintf(("kdp_writeregs THREAD_STATE\n"));
383 kdp_setintegerstate((struct ppc_thread_state
*)data
);
386 DumpTheSave((struct savearea
*)data
); /* (TEST/DEBUG) */
388 return KDPERR_NO_ERROR
;
390 case PPC_THREAD_STATE64
:
391 dprintf(("kdp_writeregs THREAD_STATE64\n"));
392 kdp_setintegerstate64((struct ppc_thread_state64
*)data
);
395 DumpTheSave((struct savearea
*)data
); /* (TEST/DEBUG) */
397 return KDPERR_NO_ERROR
;
398 case PPC_FLOAT_STATE
:
399 dprintf(("kdp_writeregs THREAD_FPSTATE\n"));
400 return KDPERR_NO_ERROR
;
403 dprintf(("kdp_writeregs bad flavor %d\n"));
404 return KDPERR_BADFLAVOR
;
409 kdp_machine_hostinfo(
410 kdp_hostinfo_t
*hostinfo
415 hostinfo
->cpus_mask
= 0;
416 hostinfo
->cpu_type
= 0;
418 for (i
= 0; i
< machine_info
.max_cpus
; i
++) {
419 if ((PerProcTable
[i
].ppe_vaddr
== (struct per_proc_info
*)NULL
) ||
420 !(PerProcTable
[i
].ppe_vaddr
->running
))
423 hostinfo
->cpus_mask
|= (1 << i
);
424 if (hostinfo
->cpu_type
== 0) {
425 hostinfo
->cpu_type
= slot_type(i
);
426 hostinfo
->cpu_subtype
= slot_subtype(i
);
436 printf("kdp panic: %s\n", msg
);
444 printf("Attempting system restart...");
445 /* Call the platform specific restart*/
447 (*PE_halt_restart
)(kPERestartCPU
);
448 /* If we do reach this, give up */
465 kdp_us_spin(int usec
)
467 extern void delay(int);
472 void print_saved_state(void *state
)
474 struct ppc_thread_state
*saved_state
;
478 printf("pc = 0x%x\n", saved_state
->srr0
);
479 printf("msr = 0x%x\n", saved_state
->srr1
);
480 printf("rp = 0x%x\n", saved_state
->lr
);
481 printf("sp = 0x%x\n", saved_state
->r1
);
488 Debugger("inline call to debugger(machine_startup)");
492 * table to convert system specific code to generic codes for kdb
494 int kdp_trap_codes
[] = {
495 EXC_BAD_ACCESS
, /* 0x0000 INVALID EXCEPTION */
496 EXC_BAD_ACCESS
, /* 0x0100 System reset */
497 EXC_BAD_ACCESS
, /* 0x0200 Machine check */
498 EXC_BAD_ACCESS
, /* 0x0300 Data access */
499 EXC_BAD_ACCESS
, /* 0x0400 Instruction access */
500 EXC_BAD_ACCESS
, /* 0x0500 External interrupt */
501 EXC_BAD_ACCESS
, /* 0x0600 Alignment */
502 EXC_BREAKPOINT
, /* 0x0700 Program - fp exc, ill/priv instr, trap */
503 EXC_ARITHMETIC
, /* 0x0800 Floating point disabled */
504 EXC_SOFTWARE
, /* 0x0900 Decrementer */
505 EXC_BAD_ACCESS
, /* 0x0A00 I/O controller interface */
506 EXC_BAD_ACCESS
, /* 0x0B00 INVALID EXCEPTION */
507 EXC_SOFTWARE
, /* 0x0C00 System call exception */
508 EXC_BREAKPOINT
, /* 0x0D00 Trace */
509 EXC_SOFTWARE
, /* 0x0E00 FP assist */
510 EXC_SOFTWARE
, /* 0x0F00 Performance monitoring */
511 EXC_ARITHMETIC
, /* 0x0F20 Altivec disabled */
512 EXC_BAD_ACCESS
, /* 0x1000 Instruction PTE miss */
513 EXC_BAD_ACCESS
, /* 0x1100 Data load PTE miss */
514 EXC_BAD_ACCESS
, /* 0x1200 Data store PTE miss */
515 EXC_BREAKPOINT
, /* 0x1300 Instruction bkpt */
516 EXC_SOFTWARE
, /* 0x1400 System management */
517 EXC_BAD_ACCESS
, /* 0x1500 INVALID EXCEPTION */
518 EXC_ARITHMETIC
, /* 0x1600 Altivec Assist */
519 EXC_BAD_ACCESS
, /* 0x1700 INVALID EXCEPTION */
520 EXC_BAD_ACCESS
, /* 0x1800 INVALID EXCEPTION */
521 EXC_BAD_ACCESS
, /* 0x1900 INVALID EXCEPTION */
522 EXC_BAD_ACCESS
, /* 0x1A00 INVALID EXCEPTION */
523 EXC_BAD_ACCESS
, /* 0x1B00 INVALID EXCEPTION */
524 EXC_BAD_ACCESS
, /* 0x1C00 INVALID EXCEPTION */
525 EXC_BAD_ACCESS
, /* 0x1D00 INVALID EXCEPTION */
526 EXC_BAD_ACCESS
, /* 0x1E00 INVALID EXCEPTION */
527 EXC_BAD_ACCESS
, /* 0x1F00 INVALID EXCEPTION */
528 EXC_BREAKPOINT
, /* 0x2000 Run Mode/Trace */
529 EXC_BAD_ACCESS
, /* 0x2100 INVALID EXCEPTION */
530 EXC_BAD_ACCESS
, /* 0x2200 INVALID EXCEPTION */
531 EXC_BAD_ACCESS
, /* 0x2300 INVALID EXCEPTION */
532 EXC_BAD_ACCESS
, /* 0x2400 INVALID EXCEPTION */
533 EXC_BAD_ACCESS
, /* 0x2500 INVALID EXCEPTION */
534 EXC_BAD_ACCESS
, /* 0x2600 INVALID EXCEPTION */
535 EXC_BAD_ACCESS
, /* 0x2700 INVALID EXCEPTION */
536 EXC_BAD_ACCESS
, /* 0x2800 INVALID EXCEPTION */
537 EXC_BAD_ACCESS
, /* 0x2900 INVALID EXCEPTION */
538 EXC_BAD_ACCESS
, /* 0x2A00 INVALID EXCEPTION */
539 EXC_BAD_ACCESS
, /* 0x2B00 INVALID EXCEPTION */
540 EXC_BAD_ACCESS
, /* 0x2C00 INVALID EXCEPTION */
541 EXC_BAD_ACCESS
, /* 0x2D00 INVALID EXCEPTION */
542 EXC_BAD_ACCESS
, /* 0x2E00 INVALID EXCEPTION */
543 EXC_BAD_ACCESS
, /* 0x2F00 INVALID EXCEPTION */
544 EXC_SOFTWARE
/* 0x3000 AST trap (software) */
558 #define kdp_code(x) kdp_trap_codes[((x)==T_AST?0x31:(x)/T_VECTOR_SIZE)]
562 unsigned int exception
,
563 struct savearea
*saved_state
568 struct savearea
*state
;
572 printf("\nvector=%x, \n", exception
/4);
573 sp
= saved_state
->save_r1
;
574 printf("stack backtrace - sp(%x) ", sp
);
575 fp
= (unsigned int *) *((unsigned int *)sp
);
577 printf("0x%08x ", fp
[2]);
578 fp
= (unsigned int *)*fp
;
584 dump_segment_registers();
588 printf("vector=%d ", exception
/4);
590 kdp_raise_exception(kdp_code(exception
), 0, 0, saved_state
);
593 printf("kdp_trap: kdp_raise_exception() ret\n");
595 if ((unsigned int)(saved_state
->save_srr0
) == 0x7c800008)
596 saved_state
->save_srr0
+= 4; /* BKPT_SIZE */
598 if(saved_state
->save_srr1
& (MASK(MSR_SE
) | MASK(MSR_BE
))) { /* Are we just stepping or continuing */
599 db_run_mode
= STEP_ONCE
; /* We are stepping */
601 else db_run_mode
= STEP_CONTINUE
; /* Otherwise we are continuing */
604 mtspr(dabr
, kdp_dabr
);
616 void kdp_print_registers(struct savearea
*state
)
619 for (i
=0; i
<32; i
++) {
622 printf(" %08x",*(&state
->save_r0
+i
));
625 printf("cr = 0x%08x\t\t",state
->save_cr
);
626 printf("xer = 0x%08x\n",state
->save_xer
);
627 printf("lr = 0x%08x\t\t",state
->save_lr
);
628 printf("ctr = 0x%08x\n",state
->save_ctr
);
629 printf("srr0(iar) = 0x%08x\t\t",state
->save_srr0
);
630 printf("srr1(msr) = 0x%08B\n",state
->save_srr1
,
631 "\x10\x11""EE\x12PR\x13""FP\x14ME\x15""FE0\x16SE\x18"
632 "FE1\x19""AL\x1a""EP\x1bIT\x1c""DT");
638 unsigned int exception
,
639 struct savearea
*saved_state
)
641 extern void kdp_print_registers(struct savearea
*);
642 extern void print_backtrace(struct savearea
*);
644 disableDebugOuput
= FALSE
;
646 printf("re-entering kdp:\n");
647 printf("vector=%x, \n", exception
/4);
648 kdp_print_registers(saved_state
);
649 print_backtrace(saved_state
);
650 printf("panic: We are hanging here...\n");
654 unsigned int kdp_ml_get_breakinsn(void)
659 #define LR_OFFSET64 16
662 machine_trace_thread(thread_t thread
, uint32_t tracepos
, uint32_t tracebound
, int nframes
, boolean_t user_p
)
664 uint32_t *tracebuf
= (uint32_t *)tracepos
;
666 uint32_t stackptr
= 0;
667 uint32_t stacklimit
= 0xb0000000;
669 uint32_t init_srr0
= 0;
671 uint32_t framesize
= 2 * sizeof(vm_offset_t
);
674 /* Examine the user savearea */
675 init_srr0
= thread
->machine
.upcb
->save_srr0
;
676 stackptr
= thread
->machine
.upcb
->save_r1
;
677 /* This bound isn't useful, but it doesn't hinder us */
678 stacklimit
= 0xffffffff;
679 kdp_pmap
= thread
->task
->map
->pmap
;
682 stackptr
= thread
->machine
.pcb
->save_r1
;
683 init_srr0
= thread
->machine
.pcb
->save_srr0
;
685 /* Fill in the "current" program counter */
686 *tracebuf
++ = init_srr0
;
688 for (framecount
= 0; framecount
< nframes
; framecount
++) {
690 if ((tracebound
- ((uint32_t) tracebuf
)) < (4 * framesize
)) {
695 *tracebuf
++ = stackptr
;
696 /* Invalid frame, or hit fence */
697 if (!stackptr
|| (stackptr
== fence
)) {
700 /* Stack grows downward */
701 if (stackptr
< prevsp
) {
704 /* Unaligned frame */
705 if (stackptr
& 0x000000F) {
708 if (stackptr
> stacklimit
) {
711 /* Assume there's a saved link register, and read it */
712 if (kdp_vm_read((caddr_t
) (stackptr
+ LR_OFFSET
), (caddr_t
) tracebuf
, sizeof(caddr_t
)) != sizeof(caddr_t
)) {
719 if (kdp_vm_read((caddr_t
) stackptr
, (caddr_t
) &stackptr
, sizeof(caddr_t
)) != sizeof(caddr_t
)) {
724 /* Reset the target pmap */
726 return ((uint32_t) tracebuf
- tracepos
);
729 /* Routine to encapsulate the 64-bit address read hack*/
731 machine_read64(addr64_t srcaddr
, caddr_t dstaddr
, uint32_t len
)
733 uint32_t kdp_vm_read_low32
;
736 kdp_src_high32
= srcaddr
>> 32;
737 kdp_vm_read_low32
= srcaddr
& 0x00000000FFFFFFFFUL
;
738 retval
= kdp_vm_read((caddr_t
)kdp_vm_read_low32
, dstaddr
, len
);
744 machine_trace_thread64(thread_t thread
, uint32_t tracepos
, uint32_t tracebound
, int nframes
, boolean_t user_p
)
746 uint64_t *tracebuf
= (uint64_t *)tracepos
;
748 addr64_t stackptr
= 0;
749 uint64_t stacklimit
= 0xb0000000;
751 addr64_t init_srr0
= 0;
753 unsigned framesize
= 2 * sizeof(addr64_t
);
756 init_srr0
= thread
->machine
.upcb
->save_srr0
;
757 stackptr
= thread
->machine
.upcb
->save_r1
;
758 stacklimit
= 0xffffffffffffffffULL
;
759 kdp_pmap
= thread
->task
->map
->pmap
;
762 stackptr
= thread
->machine
.pcb
->save_r1
;
763 init_srr0
= thread
->machine
.pcb
->save_srr0
;
766 *tracebuf
++ = init_srr0
;
768 for (framecount
= 0; framecount
< nframes
; framecount
++) {
770 if ((tracebound
- ((uint32_t) tracebuf
)) < (4 * framesize
)) {
775 *tracebuf
++ = stackptr
;
777 if (!stackptr
|| (stackptr
== fence
)){
780 if (stackptr
< prevsp
) {
783 if (stackptr
& 0x000000F) {
786 if (stackptr
> stacklimit
) {
790 if (machine_read64(stackptr
+LR_OFFSET64
, (caddr_t
) tracebuf
, sizeof(addr64_t
)) != sizeof(addr64_t
)) {
796 if (machine_read64(stackptr
, (caddr_t
) &stackptr
, sizeof(addr64_t
)) != sizeof(addr64_t
)) {
804 return ((uint32_t) tracebuf
- tracepos
);