1 /* Fault handler information subroutine. MacOSX/Darwin7/PowerPC version.
2 * Taken from gcc-3.2/boehm-gc/os_dep.c.
4 * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
5 * Copyright (c) 1991-1995 by Xerox Corporation. All rights reserved.
6 * Copyright (c) 1996-1999 by Silicon Graphics. All rights reserved.
7 * Copyright (c) 1999 by Hewlett-Packard Company. All rights reserved.
9 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
10 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
12 * Permission is hereby granted to use or copy this program
13 * for any purpose, provided the above notices are retained on all copies.
14 * Permission to modify the code and to distribute modified code is granted,
15 * provided the above notices are retained, and a notice that the code was
16 * modified is included with the above copyright notice.
21 /* Decodes the machine instruction which was responsible for the sending of the
22 SIGBUS signal. Sadly this is the only way to find the faulting address
23 because the signal handler doesn't get it directly from the kernel (although
24 it is available on the Mach level, but dropped by the BSD personality before
25 it calls our signal handler...)
26 This code should be able to deal correctly with all PPCs starting from the
27 601 up to and including the G4s (including Velocity Engine). */
28 #define EXTRACT_OP1(iw) (((iw) & 0xFC000000) >> 26)
29 #define EXTRACT_OP2(iw) (((iw) & 0x000007FE) >> 1)
30 #define EXTRACT_REGA(iw) (((iw) & 0x001F0000) >> 16)
31 #define EXTRACT_REGB(iw) (((iw) & 0x03E00000) >> 21)
32 #define EXTRACT_REGC(iw) (((iw) & 0x0000F800) >> 11)
33 #define EXTRACT_DISP(iw) ((short *) &(iw))[1]
36 get_fault_addr (siginfo_t
*sip
, ucontext_t
*ucp
)
38 unsigned int instr
= *(unsigned int *) sip
->si_addr
;
41 &ucp
->uc_mcontext
->ss
.__r0
; /* r0..r31 */
43 &ucp
->uc_mcontext
->ss
.r0
; /* r0..r31 */
47 unsigned int baseA
= 0;
48 unsigned int baseB
= 0;
50 unsigned int alignmask
= 0xFFFFFFFF;
52 switch (EXTRACT_OP1 (instr
))
65 tmp
= EXTRACT_REGA (instr
);
68 disp
= EXTRACT_DISP (instr
);
71 switch (EXTRACT_OP2 (instr
))
78 case 759: /* stfdux */
80 case 983: /* stfiwx */
81 case 695: /* stfsux */
83 case 918: /* sthbrx */
87 case 662: /* stwbrx */
88 case 150: /* stwcx. */
91 case 135: /* stvebx */
92 case 167: /* stvehx */
93 case 199: /* stvewx */
96 tmp
= EXTRACT_REGA (instr
);
99 baseB
= regs
[EXTRACT_REGC (instr
)];
100 /* Determine Altivec alignment mask. */
101 switch (EXTRACT_OP2 (instr
))
103 case 167: /* stvehx */
104 alignmask
= 0xFFFFFFFE;
106 case 199: /* stvewx */
107 alignmask
= 0xFFFFFFFC;
110 case 487: /* stvxl */
111 alignmask
= 0xFFFFFFF0;
115 case 725: /* stswi */
116 tmp
= EXTRACT_REGA (instr
);
120 default: /* ignore instruction */
124 default: /* ignore instruction */
128 addr
= (baseA
+ baseB
) + disp
;
130 return (void *) addr
;