671301d4ef93c94f7da812d315fd4a3058c32a8c
[cacao.git] / src / vm / jit / powerpc64 / linux / md-os.c
1 /* src/vm/jit/powerpc64/linux/md-os.c - machine dependent PowerPC64 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 7311 2007-02-09 13:20:27Z 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/powerpc64/linux/md-abi.h"
38
39 #if defined(ENABLE_THREADS)
40 # include "threads/native/threads.h"
41 #endif
42
43 #include "vm/exceptions.h"
44 #include "vm/signallocal.h"
45
46 #include "vm/jit/asmpart.h"
47
48 #if defined(ENABLE_PROFILING)
49 # include "vm/jit/optimizing/profile.h"
50 #endif
51
52 #include "vm/jit/stacktrace.h"
53
54
55 /* md_signal_handler_sigsegv ***************************************************
56
57    NullPointerException signal handler for hardware null pointer
58    check.
59
60 *******************************************************************************/
61
62 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
63 {
64         ucontext_t  *_uc;
65         mcontext_t  *_mc;
66         u4           instr;
67         s4           reg;
68         ptrint       addr;
69         u1          *pv;
70         u1          *sp;
71         u1          *ra;
72         u1          *xpc;
73
74         _uc = (ucontext_t *) _p;
75         _mc = &(_uc->uc_mcontext);
76         
77         pv  = (u1 *) _mc->gp_regs[REG_PV];
78         sp  = (u1 *) _mc->gp_regs[REG_SP];
79         ra  = (u1 *) _mc->gp_regs[PT_LNK];           /* this is correct for leafs */
80         xpc = (u1 *) _mc->gp_regs[PT_NIP];
81
82         instr = *((u4 *) xpc);
83         reg   = (instr >> 16) & 0x1f;
84         addr  = _mc->gp_regs[reg];
85
86         if (addr == 0) {
87                 _mc->gp_regs[REG_ITMP1_XPTR] =
88                         (ptrint) stacktrace_hardware_nullpointerexception(pv, sp, ra, xpc);
89
90                 _mc->gp_regs[REG_ITMP2_XPC] = (ptrint) xpc;
91                 _mc->gp_regs[PT_NIP] = (ptrint) asm_handle_exception;
92         }
93         else {
94                 codegen_get_pv_from_pc(xpc);
95
96                 /* this should not happen */
97
98                 assert(0);
99         }               
100 }
101
102
103 /* md_signal_handler_sigusr2 ***************************************************
104
105    Signal handler for profiling sampling.
106
107 *******************************************************************************/
108
109 #if defined(ENABLE_THREADS)
110 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
111 {
112         threadobject *tobj;
113         ucontext_t   *_uc;
114         mcontext_t   *_mc;
115         u1           *pc;
116
117         tobj = THREADOBJECT;
118
119         _uc = (ucontext_t *) _p;
120         _mc = &(_uc->uc_mcontext);
121
122         pc = (u1 *) _mc->gp_regs[PT_NIP];
123
124         tobj->pc = pc;
125 }
126
127
128 void thread_restartcriticalsection(ucontext_t *_uc)
129 {
130         mcontext_t *_mc;
131         u1         *pc;
132         void       *critical;
133
134         _mc = &(_uc->uc_mcontext);
135
136         pc = (u1 *) _mc->gp_regs[PT_NIP];
137
138         critical = critical_find_restart_point(pc);
139
140         if (critical != NULL)
141                 _mc->gp_regs[PT_NIP] = (ptrint) critical;
142 }
143 #endif
144
145
146 /*
147  * These are local overrides for various environment variables in Emacs.
148  * Please do not remove this and leave it at the end of the file, where
149  * Emacs will automagically detect them.
150  * ---------------------------------------------------------------------
151  * Local variables:
152  * mode: c
153  * indent-tabs-mode: t
154  * c-basic-offset: 4
155  * tab-width: 4
156  * End:
157  */