]>
git.saurik.com Git - apple/bootx.git/blob - bootx.tproj/libclite.subproj/printf.c
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@
25 * Copyright (c) 1998-2002 Apple Computer, Inc.
32 int printf(const char *format
, ...)
36 prf(format
, (unsigned int *)ap
, putchar
, 0);
46 // ctx and id optional
47 void dump_backtrace(char *ctx
, int id
)
59 cnt
= OSBacktrace_ppc(bt
, BTLEN
);
60 while(cnt
<= BTLEN
&& cnt
--)
61 printf("bt[%d]: %x\n", cnt
, bt
[cnt
]);
64 // ported from xnu/libkern/gen/OSDebug.cpp
65 // (non-__ppc__ #if branches and min/maxstackaddr checks omitted)
66 unsigned OSBacktrace_ppc(void **bt
, unsigned maxAddrs
)
71 uint32_t stackptr
, stackptr_prev
;
72 const uint32_t * const mem
= (uint32_t *) 0;
75 __asm__
volatile("mflr %0" : "=r" (stackptr
));
76 bt
[i
++] = (void *) stackptr
;
78 __asm__
volatile("mr %0,r1" : "=r" (stackptr
));
79 for ( ; i
< maxAddrs
; i
++) {
80 // Validate we have a reasonable stackptr
81 if ( /* !(minstackaddr <= stackptr && stackptr < maxstackaddr)
85 stackptr_prev
= stackptr
;
86 stackptr
= mem
[stackptr_prev
>> 2];
87 if ((stackptr_prev
^ stackptr
) > 8 * 1024) // Sanity check
90 uint32_t addr
= mem
[(stackptr
>> 2) + 2];
91 if ((addr
& 3) || (addr
< 0x8000)) // More sanity checks
93 bt
[i
] = (void *) addr
;
97 for ( ; i
< maxAddrs
; i
++)
100 #warning "BootX's OSBacktrace_ppc() not intended for other architectures"