blob: a2f59d8fa3beea40333beff189e2965c5b3e3162 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
/* Fault handler information subroutine. MacOSX/Darwin5/PowerPC version.
* Taken from gcc-3.2/boehm-gc/os_dep.c.
*
* Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
* Copyright (c) 1991-1995 by Xerox Corporation. All rights reserved.
* Copyright (c) 1996-1999 by Silicon Graphics. All rights reserved.
* Copyright (c) 1999 by Hewlett-Packard Company. All rights reserved.
*
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
*
* Permission is hereby granted to use or copy this program
* for any purpose, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*/
/* Decodes the machine instruction which was responsible for the sending of the
SIGBUS signal. Sadly this is the only way to find the faulting address
because the signal handler doesn't get it directly from the kernel (although
it is available on the Mach level, but dropped by the BSD personality before
it calls our signal handler...)
This code should be able to deal correctly with all PPCs starting from the
601 up to and including the G4s (including Velocity Engine). */
#define EXTRACT_OP1(iw) (((iw) & 0xFC000000) >> 26)
#define EXTRACT_OP2(iw) (((iw) & 0x000007FE) >> 1)
#define EXTRACT_REGA(iw) (((iw) & 0x001F0000) >> 16)
#define EXTRACT_REGB(iw) (((iw) & 0x03E00000) >> 21)
#define EXTRACT_REGC(iw) (((iw) & 0x0000F800) >> 11)
#define EXTRACT_DISP(iw) ((short *) &(iw))[1]
static void *
get_fault_addr (struct sigcontext *scp)
{
unsigned int instr = *((unsigned int *) scp->sc_ir);
unsigned int *regs = &((unsigned int *) scp->sc_regs)[2];
int disp = 0;
int tmp;
unsigned int baseA = 0;
unsigned int baseB = 0;
unsigned int addr;
unsigned int alignmask = 0xFFFFFFFF;
switch (EXTRACT_OP1 (instr))
{
case 38: /* stb */
case 39: /* stbu */
case 54: /* stfd */
case 55: /* stfdu */
case 52: /* stfs */
case 53: /* stfsu */
case 44: /* sth */
case 45: /* sthu */
case 47: /* stmw */
case 36: /* stw */
case 37: /* stwu */
tmp = EXTRACT_REGA (instr);
if (tmp > 0)
baseA = regs[tmp];
disp = EXTRACT_DISP (instr);
break;
case 31:
switch (EXTRACT_OP2 (instr))
{
case 86: /* dcbf */
case 54: /* dcbst */
case 1014: /* dcbz */
case 247: /* stbux */
case 215: /* stbx */
case 759: /* stfdux */
case 727: /* stfdx */
case 983: /* stfiwx */
case 695: /* stfsux */
case 663: /* stfsx */
case 918: /* sthbrx */
case 439: /* sthux */
case 407: /* sthx */
case 661: /* stswx */
case 662: /* stwbrx */
case 150: /* stwcx. */
case 183: /* stwux */
case 151: /* stwx */
case 135: /* stvebx */
case 167: /* stvehx */
case 199: /* stvewx */
case 231: /* stvx */
case 487: /* stvxl */
tmp = EXTRACT_REGA (instr);
if (tmp > 0)
baseA = regs[tmp];
baseB = regs[EXTRACT_REGC (instr)];
/* Determine Altivec alignment mask. */
switch (EXTRACT_OP2 (instr))
{
case 167: /* stvehx */
alignmask = 0xFFFFFFFE;
break;
case 199: /* stvewx */
alignmask = 0xFFFFFFFC;
break;
case 231: /* stvx */
case 487: /* stvxl */
alignmask = 0xFFFFFFF0;
break;
}
break;
case 725: /* stswi */
tmp = EXTRACT_REGA (instr);
if (tmp > 0)
baseA = regs[tmp];
break;
default: /* ignore instruction */
return (void *) 0;
}
break;
default: /* ignore instruction */
return (void *) 0;
}
addr = (baseA + baseB) + disp;
addr &= alignmask;
return (void *) addr;
}
|