* Merged with tip.
[cacao.git] / src / vm / jit / powerpc / netbsd / md-os.c
1 /* src/vm/jit/powerpc/netbsd/md-os.c - machine dependent PowerPC NetBSD functions
2
3    Copyright (C) 1996-2005, 2006, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #include "config.h"
27
28 #include <ucontext.h>
29
30 #include "vm/types.h"
31
32 #include "vm/jit/powerpc/netbsd/md-abi.h"
33
34 #include "vm/exceptions.h"
35 #include "vm/signallocal.h"
36 #include "vm/stringlocal.h"
37 #include "vm/jit/asmpart.h"
38 #include "vm/jit/stacktrace.h"
39
40
41 /* md_signal_handle_sigsegv ****************************************************
42
43    NullPointerException signal handler for hardware null pointer
44    check.
45
46 *******************************************************************************/
47
48 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
49 {
50         ucontext_t  *_uc;
51         mcontext_t  *_mc;
52         u4           instr;
53         s4           reg;
54         ptrint       addr;
55         u1          *pv;
56         u1          *sp;
57         u1          *ra;
58         u1          *xpc;
59
60         _uc = (ucontext_t *) _p;
61         _mc = _uc->uc_mcontext.uc_regs;
62
63         instr = *((u4 *) _mc->gregs[PT_NIP]);
64         reg = (instr >> 16) & 0x1f;
65         addr = _mc->gregs[reg];
66
67         if (addr == 0) {
68                 pv  = (u1 *) _mc->gregs[REG_PV];
69                 sp  = (u1 *) _mc->gregs[REG_SP];
70                 ra  = (u1 *) _mc->gregs[PT_LNK];         /* this is correct for leafs */
71                 xpc = (u1 *) _mc->gregs[PT_NIP];
72
73                 _mc->gregs[REG_ITMP1_XPTR] =
74                         (ptrint) stacktrace_hardware_nullpointerexception(pv, sp, ra, xpc);
75
76                 _mc->gregs[REG_ITMP2_XPC] = (ptrint) xpc;
77                 _mc->gregs[PT_NIP] = (ptrint) asm_handle_exception;
78
79         } else {
80                 throw_cacao_exception_exit(string_java_lang_InternalError,
81                                                                    "Segmentation fault: 0x%08lx at 0x%08lx",
82                                                                    addr, _mc->gregs[PT_NIP]);
83         }               
84 }
85
86
87 /*
88  * These are local overrides for various environment variables in Emacs.
89  * Please do not remove this and leave it at the end of the file, where
90  * Emacs will automagically detect them.
91  * ---------------------------------------------------------------------
92  * Local variables:
93  * mode: c
94  * indent-tabs-mode: t
95  * c-basic-offset: 4
96  * tab-width: 4
97  * End:
98  */