* src/vm/jit/alpha/codegen.c (codegen_emit): ICMD_BUILTIN now calls stubs.
[cacao.git] / src / vm / jit / alpha / linux / md-os.c
1 /* src/vm/jit/alpha/linux/md-os.c - machine dependent Alpha Linux functions
2
3    Copyright (C) 1996-2005, 2006, 2007 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    $Id: md-os.c 8188 2007-07-06 00:31:03Z michi $
26
27 */
28
29
30 #include "config.h"
31
32 #include <assert.h>
33 #include <ucontext.h>
34
35 #include "vm/types.h"
36
37 #include "vm/jit/alpha/codegen.h"
38 #include "vm/jit/alpha/md-abi.h"
39
40 #if defined(ENABLE_THREADS)
41 # include "threads/native/threads.h"
42 #endif
43
44 #include "vm/exceptions.h"
45 #include "vm/signallocal.h"
46
47 #include "vm/jit/asmpart.h"
48 #include "vm/jit/stacktrace.h"
49
50
51 /* md_signal_handler_sigsegv ***************************************************
52
53    NullPointerException signal handler for hardware null pointer
54    check.
55
56 *******************************************************************************/
57
58 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
59 {
60         stackframeinfo     sfi;
61         ucontext_t        *_uc;
62         mcontext_t        *_mc;
63         u1                *pv;
64         u1                *sp;
65         u1                *ra;
66         u1                *xpc;
67         u4                 mcode;
68         s4                 d;
69         s4                 s1;
70         s4                 disp;
71         ptrint             val;
72         ptrint             addr;
73         s4                 type;
74         java_objectheader *e;
75
76         _uc = (ucontext_t *) _p;
77         _mc = &_uc->uc_mcontext;
78
79         pv  = (u1 *) _mc->sc_regs[REG_PV];
80         sp  = (u1 *) _mc->sc_regs[REG_SP];
81         ra  = (u1 *) _mc->sc_regs[REG_RA];           /* this is correct for leafs */
82         xpc = (u1 *) _mc->sc_pc;
83
84         /* get exception-throwing instruction */
85
86         mcode = *((u4 *) xpc);
87
88         d    = M_MEM_GET_A(mcode);
89         s1   = M_MEM_GET_B(mcode);
90         disp = M_MEM_GET_DISP(mcode);
91
92         val   = _mc->sc_regs[d];
93
94         /* check for special-load */
95
96         if (s1 == REG_ZERO) {
97                 /* we use the exception type as load displacement */
98
99                 type = disp;
100         }
101         else {
102                 /* This is a normal NPE: addr must be NULL and the NPE-type
103                    define is 0. */
104
105                 addr = _mc->sc_regs[s1];
106                 type = (s4) addr;
107         }
108
109         /* generate appropriate exception */
110
111         e = exceptions_new_hardware_exception(pv, sp, ra, xpc, type, val, &sfi);
112
113         /* set registers */
114
115         if (e != NULL) {
116                 _mc->sc_regs[REG_ITMP1_XPTR] = (ptrint) e;
117                 _mc->sc_regs[REG_ITMP2_XPC]  = (ptrint) xpc;
118                 _mc->sc_pc                   = (ptrint) asm_handle_exception;
119         }
120 }
121
122
123 /* md_signal_handler_sigusr1 ***************************************************
124
125    Signal handler for suspending threads.
126
127 *******************************************************************************/
128
129 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
130 void md_signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p)
131 {
132         ucontext_t *_uc;
133         mcontext_t *_mc;
134         u1         *pc;
135         u1         *sp;
136
137         _uc = (ucontext_t *) _p;
138         _mc = &_uc->uc_mcontext;
139
140         /* get the PC and SP for this thread */
141         pc = (u1 *) _mc->sc_pc;
142         sp = (u1 *) _mc->sc_regs[REG_SP];
143
144         /* now suspend the current thread */
145         threads_suspend_ack(pc, sp);
146 }
147 #endif
148
149
150 /* md_signal_handler_sigusr2 ***************************************************
151
152    Signal handler for profiling sampling.
153
154 *******************************************************************************/
155
156 #if defined(ENABLE_THREADS)
157 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
158 {
159         threadobject *tobj;
160         ucontext_t   *_uc;
161         mcontext_t   *_mc;
162         u1           *pc;
163
164         tobj = THREADOBJECT;
165
166         _uc = (ucontext_t *) _p;
167         _mc = &_uc->uc_mcontext;
168
169         pc = (u1 *) _mc->sc_pc;
170
171         tobj->pc = pc;
172 }
173 #endif
174
175
176 /* md_critical_section_restart *************************************************
177
178    Search the critical sections tree for a matching section and set
179    the PC to the restart point, if necessary.
180
181 *******************************************************************************/
182
183 #if defined(ENABLE_THREADS)
184 void md_critical_section_restart(ucontext_t *_uc)
185 {
186         mcontext_t *_mc;
187         u1         *pc;
188         u1         *npc;
189
190         _mc = &_uc->uc_mcontext;
191
192         pc = (u1 *) _mc->sc_pc;
193
194         npc = critical_find_restart_point(pc);
195
196         if (npc != NULL)
197                 _mc->sc_pc = (ptrint) npc;
198 }
199 #endif
200
201
202 /*
203  * These are local overrides for various environment variables in Emacs.
204  * Please do not remove this and leave it at the end of the file, where
205  * Emacs will automagically detect them.
206  * ---------------------------------------------------------------------
207  * Local variables:
208  * mode: c
209  * indent-tabs-mode: t
210  * c-basic-offset: 4
211  * tab-width: 4
212  * End:
213  */