Merged revisions 7501-7598 via svnmerge from
[cacao.git] / src / vm / jit / powerpc / darwin / md-os.c
1 /* src/vm/jit/powerpc/darwin/md-os.c - machine dependent PowerPC Darwin functions
2
3    Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
4    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6    J. Wenninger, Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25    Contact: cacao@cacaojvm.org
26
27    Authors: Christian Thalinger
28
29    $Id: md-os.c 7596 2007-03-28 21:05:53Z twisti $
30
31 */
32
33
34 #include "config.h"
35
36 #include <assert.h>
37 #include <signal.h>
38 #include <ucontext.h>
39
40 #include "vm/types.h"
41
42 #include "vm/jit/powerpc/codegen.h"
43 #include "vm/jit/powerpc/darwin/md-abi.h"
44
45 #include "vm/exceptions.h"
46 #include "vm/global.h"
47 #include "vm/signallocal.h"
48 #include "vm/stringlocal.h"
49 #include "vm/jit/asmpart.h"
50 #include "vm/jit/stacktrace.h"
51
52
53 /* md_signal_handler_sigsegv ***************************************************
54
55    NullPointerException signal handler for hardware null pointer
56    check.
57
58 *******************************************************************************/
59
60 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
61 {
62         ucontext_t         *_uc;
63         mcontext_t          _mc;
64         ppc_thread_state_t *_ss;
65         u1                 *pv;
66         u1                 *sp;
67         u1                 *ra;
68         u1                 *xpc;
69         u4                  mcode;
70         s4                  s1;
71         s4                  disp;
72         s4                  d;
73         ptrint             *gregs;
74         ptrint              addr;
75         ptrint              val;
76         java_objectheader  *e;
77
78         _uc = (ucontext_t *) _p;
79         _mc = _uc->uc_mcontext;
80         _ss = &_mc->ss;
81
82         /* get register values */
83
84         pv  = (u1 *) _ss->r13;
85         sp  = (u1 *) _ss->r1;
86         ra  = (u1 *) _ss->lr;                    /* this is correct for leafs */
87         xpc = (u1 *) _ss->srr0;
88
89         /* get exception-throwing instruction */
90
91         mcode = *((u4 *) xpc);
92
93         s1   = M_INSTR_OP2_IMM_A(mcode);
94         disp = M_INSTR_OP2_IMM_I(mcode);
95         d    = M_INSTR_OP2_IMM_D(mcode);
96
97         gregs = &_ss->r0;
98         addr  = gregs[s1];
99         val   = gregs[d];
100
101         e = exceptions_new_hardware_exception(pv, sp, ra, xpc, s1, disp, addr, val);
102
103         /* set registers */
104
105         _ss->r11  = (ptrint) e;
106         _ss->r12  = (ptrint) xpc;
107         _ss->srr0 = (ptrint) asm_handle_exception;
108 }
109
110
111 /* md_signal_handler_sigusr2 ***************************************************
112
113    Signal handler for profiling sampling.
114
115 *******************************************************************************/
116
117 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
118 {
119         threadobject       *t;
120         ucontext_t         *_uc;
121         mcontext_t          _mc;
122         ppc_thread_state_t *_ss;
123         u1                 *pc;
124
125         t = THREADOBJECT;
126
127         _uc = (ucontext_t *) _p;
128         _mc = _uc->uc_mcontext;
129         _ss = &_mc->ss;
130
131         pc = (u1 *) _ss->srr0;
132
133         t->pc = pc;
134 }
135
136
137 #if defined(ENABLE_THREADS)
138 void thread_restartcriticalsection(ucontext_t *_uc)
139 {
140         mcontext_t          _mc;
141         ppc_thread_state_t *_ss;
142         void               *critical;
143
144         _mc = _uc->uc_mcontext;
145         _ss = &_mc->ss;
146
147         critical = critical_find_restart_point((void *) _ss->srr0);
148
149         if (critical)
150                 _ss->srr0 = (ptrint) critical;
151 }
152 #endif
153
154
155 /*
156  * These are local overrides for various environment variables in Emacs.
157  * Please do not remove this and leave it at the end of the file, where
158  * Emacs will automagically detect them.
159  * ---------------------------------------------------------------------
160  * Local variables:
161  * mode: c
162  * indent-tabs-mode: t
163  * c-basic-offset: 4
164  * tab-width: 4
165  * End:
166  */