1 |
gbeauche |
1.1 |
/* |
2 |
|
|
* sigregs.h - Extract machine registers from a signal frame |
3 |
|
|
* |
4 |
gbeauche |
1.2 |
* SheepShaver (C) 1997-2008 Christian Bauer and Marc Hellwig |
5 |
gbeauche |
1.1 |
* |
6 |
|
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
|
* it under the terms of the GNU General Public License as published by |
8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
9 |
|
|
* (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* This program is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the GNU General Public License |
17 |
|
|
* along with this program; if not, write to the Free Software |
18 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
|
|
*/ |
20 |
|
|
|
21 |
|
|
#ifndef SIGREGS_H |
22 |
|
|
#define SIGREGS_H |
23 |
|
|
|
24 |
|
|
#ifndef EMULATED_PPC |
25 |
|
|
|
26 |
|
|
// Common representation of machine registers |
27 |
|
|
struct sigregs { |
28 |
|
|
uint32 nip; |
29 |
|
|
uint32 link; |
30 |
|
|
uint32 ctr; |
31 |
|
|
uint32 msr; |
32 |
|
|
uint32 xer; |
33 |
|
|
uint32 ccr; |
34 |
|
|
uint32 gpr[32]; |
35 |
|
|
}; |
36 |
|
|
|
37 |
|
|
// Extract machine registers from Linux signal frame |
38 |
|
|
#if defined(__linux__) |
39 |
|
|
#include <sys/ucontext.h> |
40 |
|
|
#define MACHINE_REGISTERS(scp) ((machine_regs *)(((ucontext_t *)scp)->uc_mcontext.regs)) |
41 |
|
|
|
42 |
|
|
struct machine_regs : public pt_regs |
43 |
|
|
{ |
44 |
|
|
u_long & cr() { return pt_regs::ccr; } |
45 |
|
|
uint32 cr() const { return pt_regs::ccr; } |
46 |
|
|
uint32 lr() const { return pt_regs::link; } |
47 |
|
|
uint32 ctr() const { return pt_regs::ctr; } |
48 |
|
|
uint32 xer() const { return pt_regs::xer; } |
49 |
|
|
uint32 msr() const { return pt_regs::msr; } |
50 |
|
|
uint32 dar() const { return pt_regs::dar; } |
51 |
|
|
u_long & pc() { return pt_regs::nip; } |
52 |
|
|
uint32 pc() const { return pt_regs::nip; } |
53 |
|
|
u_long & gpr(int i) { return pt_regs::gpr[i]; } |
54 |
|
|
uint32 gpr(int i) const { return pt_regs::gpr[i]; } |
55 |
|
|
}; |
56 |
|
|
#endif |
57 |
|
|
|
58 |
|
|
// Extract machine registers from NetBSD signal frame |
59 |
|
|
#if defined(__NetBSD__) |
60 |
|
|
#include <sys/ucontext.h> |
61 |
|
|
#define MACHINE_REGISTERS(scp) ((machine_regs *)&(((ucontext_t *)scp)->uc_mcontext)) |
62 |
|
|
|
63 |
|
|
struct machine_regs : public mcontext_t |
64 |
|
|
{ |
65 |
|
|
long & cr() { return __gregs[_REG_CR]; } |
66 |
|
|
uint32 cr() const { return __gregs[_REG_CR]; } |
67 |
|
|
uint32 lr() const { return __gregs[_REG_LR]; } |
68 |
|
|
uint32 ctr() const { return __gregs[_REG_CTR]; } |
69 |
|
|
uint32 xer() const { return __gregs[_REG_XER]; } |
70 |
|
|
uint32 msr() const { return __gregs[_REG_MSR]; } |
71 |
|
|
uint32 dar() const { return (uint32)(((siginfo_t *)(((unsigned long)this) - offsetof(ucontext_t, uc_mcontext))) - 1)->si_addr; } /* HACK */ |
72 |
|
|
long & pc() { return __gregs[_REG_PC]; } |
73 |
|
|
uint32 pc() const { return __gregs[_REG_PC]; } |
74 |
|
|
long & gpr(int i) { return __gregs[_REG_R0 + i]; } |
75 |
|
|
uint32 gpr(int i) const { return __gregs[_REG_R0 + i]; } |
76 |
|
|
}; |
77 |
|
|
#endif |
78 |
|
|
|
79 |
|
|
// Extract machine registers from Darwin signal frame |
80 |
|
|
#if defined(__APPLE__) && defined(__MACH__) |
81 |
|
|
#include <sys/signal.h> |
82 |
|
|
extern "C" int sigaltstack(const struct sigaltstack *ss, struct sigaltstack *oss); |
83 |
|
|
|
84 |
|
|
#include <sys/ucontext.h> |
85 |
|
|
#define MACHINE_REGISTERS(scp) ((machine_regs *)(((ucontext_t *)scp)->uc_mcontext)) |
86 |
|
|
|
87 |
|
|
struct machine_regs : public mcontext |
88 |
|
|
{ |
89 |
|
|
uint32 & cr() { return ss.cr; } |
90 |
|
|
uint32 cr() const { return ss.cr; } |
91 |
|
|
uint32 lr() const { return ss.lr; } |
92 |
|
|
uint32 ctr() const { return ss.ctr; } |
93 |
|
|
uint32 xer() const { return ss.xer; } |
94 |
|
|
uint32 msr() const { return ss.srr1; } |
95 |
|
|
uint32 dar() const { return es.dar; } |
96 |
|
|
uint32 & pc() { return ss.srr0; } |
97 |
|
|
uint32 pc() const { return ss.srr0; } |
98 |
|
|
uint32 & gpr(int i) { return (&ss.r0)[i]; } |
99 |
|
|
uint32 gpr(int i) const { return (&ss.r0)[i]; } |
100 |
|
|
}; |
101 |
|
|
#endif |
102 |
|
|
|
103 |
|
|
// Convert system-dependent machine registers to generic sigregs |
104 |
|
|
static void build_sigregs(sigregs *srp, machine_regs *mrp) |
105 |
|
|
{ |
106 |
|
|
srp->nip = mrp->pc(); |
107 |
|
|
srp->link = mrp->lr(); |
108 |
|
|
srp->ctr = mrp->ctr(); |
109 |
|
|
srp->msr = mrp->msr(); |
110 |
|
|
srp->xer = mrp->xer(); |
111 |
|
|
srp->ccr = mrp->cr(); |
112 |
|
|
for (int i = 0; i < 32; i++) |
113 |
|
|
srp->gpr[i] = mrp->gpr(i); |
114 |
|
|
} |
115 |
|
|
|
116 |
|
|
#endif |
117 |
|
|
|
118 |
|
|
#endif /* SIGREGS_H */ |