-/*************** Recording stack ***********/
-
-static void *first_frame_address(void) {
-#if 0
- return __builtin_frame_address(1);
-#elif defined(__ppc__)
- void *addr;
-#warning __builtin_frame_address IS BROKEN IN BEAKER: RADAR #2340421
- __asm__ volatile("mr %0, r1" : "=r" (addr));
- return addr;
-#else
-#warning first_frame_address WILL NOT BE FUNCTIONAL ON THIS ARCHITECTURE
- return NULL;
-#endif
-}
-
-static void *next_frame_address(void *addr) {
- void *ret;
-#if defined(__MACH__) && defined(__i386__)
- __asm__ volatile("movl (%1),%0" : "=r" (ret) : "r" (addr));
-#elif defined(__MACH__) && defined(__ppc__)
- __asm__ volatile("lwz %0,0x0(%1)" : "=r" (ret) : "b" (addr));
-#elif defined(__hpux__)
- __asm__ volatile("ldw 0x0(%1),%0" : "=r" (ret) : "r" (addr));
-#elif defined(__svr4__)
- __asm__ volatile("ta 0x3");
- __asm__ volatile("ld [%1 + 56],%0" : "=r" (ret) : "r" (addr));
-#else
-#error Unknown architecture
-#endif
- return ret;
-}
-
-#if defined(__i386__) || defined (__m68k__)
-#define FP_LINK_OFFSET 1
-#elif defined(__ppc__)
-#define FP_LINK_OFFSET 2
-#elif defined(__hppa__)
-#define FP_LINK_OFFSET -5
-#elif defined(__sparc__)
-#define FP_LINK_OFFSET 14
-#else
-#error ********** Unimplemented architecture
-#endif
-
-void thread_stack_pcs(vm_address_t *buffer, unsigned max, unsigned *nb) {
- void *addr;
- addr = first_frame_address();
- *nb = 0;
- while ((addr >= (void *)0x800) && (max--)) {
- vm_address_t fp_link = (vm_address_t)(((unsigned *)addr)+FP_LINK_OFFSET);
- void *addr2;
- buffer[*nb] = *((vm_address_t *)fp_link);
- (*nb)++;
- addr2 = next_frame_address(addr);
-#if defined(__ppc__)
- if ((unsigned)addr2 <= (unsigned)addr) break; // catch bozo frames
-#endif
- addr = addr2;
- }
-}
-