4a559964e33d2fc312f1646c7cf1397450c90d98
[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 7638 2007-04-02 21:24:59Z twisti $
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         ucontext_t        *_uc;
61         mcontext_t        *_mc;
62         u1                *pv;
63         u1                *sp;
64         u1                *ra;
65         u1                *xpc;
66         u4                 mcode;
67         s4                 d;
68         s4                 s1;
69         s4                 disp;
70         ptrint             val;
71         ptrint             addr;
72         s4                 type;
73         java_objectheader *e;
74
75         _uc = (ucontext_t *) _p;
76         _mc = &_uc->uc_mcontext;
77
78         pv  = (u1 *) _mc->sc_regs[REG_PV];
79         sp  = (u1 *) _mc->sc_regs[REG_SP];
80         ra  = (u1 *) _mc->sc_regs[REG_RA];           /* this is correct for leafs */
81         xpc = (u1 *) _mc->sc_pc;
82
83         /* get exception-throwing instruction */
84
85         mcode = *((u4 *) xpc);
86
87         d    = M_MEM_GET_A(mcode);
88         s1   = M_MEM_GET_B(mcode);
89         disp = M_MEM_GET_DISP(mcode);
90
91         val   = _mc->sc_regs[d];
92
93         /* check for special-load */
94
95         if (s1 == REG_ZERO) {
96                 /* we use the exception type as load displacement */
97
98                 type = disp;
99         }
100         else {
101                 /* This is a normal NPE: addr must be NULL and the NPE-type
102                    define is 0. */
103
104                 addr = _mc->sc_regs[s1];
105                 type = (s4) addr;
106         }
107
108         /* generate appropriate exception */
109
110         e = exceptions_new_hardware_exception(pv, sp, ra, xpc, type, val);
111
112         /* set registers */
113
114         _mc->sc_regs[REG_ITMP1_XPTR] = (ptrint) e;
115         _mc->sc_regs[REG_ITMP2_XPC]  = (ptrint) xpc;
116         _mc->sc_pc                   = (ptrint) asm_handle_exception;
117 }
118
119
120 /* md_signal_handler_sigusr2 ***************************************************
121
122    Signal handler for profiling sampling.
123
124 *******************************************************************************/
125
126 #if defined(ENABLE_THREADS)
127 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
128 {
129         threadobject *tobj;
130         ucontext_t   *_uc;
131         mcontext_t   *_mc;
132         u1           *pc;
133
134         tobj = THREADOBJECT;
135
136         _uc = (ucontext_t *) _p;
137         _mc = &_uc->uc_mcontext;
138
139         pc = (u1 *) _mc->sc_pc;
140
141         tobj->pc = pc;
142 }
143 #endif
144
145
146 #if defined(ENABLE_THREADS)
147 void thread_restartcriticalsection(ucontext_t *_uc)
148 {
149         mcontext_t *_mc;
150         u1         *pc;
151         u1         *npc;
152
153         _mc = &_uc->uc_mcontext;
154
155         pc = (u1 *) _mc->sc_pc;
156
157         npc = critical_find_restart_point(pc);
158
159         if (npc != NULL)
160                 _mc->sc_pc = (ptrint) npc;
161 }
162 #endif
163
164
165 /*
166  * These are local overrides for various environment variables in Emacs.
167  * Please do not remove this and leave it at the end of the file, where
168  * Emacs will automagically detect them.
169  * ---------------------------------------------------------------------
170  * Local variables:
171  * mode: c
172  * indent-tabs-mode: t
173  * c-basic-offset: 4
174  * tab-width: 4
175  * End:
176  */