* configure.ac [ENABLE_STATICVM] (AC_CHECK_LIB(dl)): Only perform the
[cacao.git] / src / vm / jit / arm / linux / md-os.c
1 /* src/vm/jit/arm/linux/md.c - machine dependent arm linux 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: Michael Starzinger
28
29    Changes: Christian Thalinger
30
31    $Id: md.c 166 2006-01-22 23:38:44Z twisti $
32
33 */
34
35
36 #include "config.h"
37
38 #include "vm/types.h"
39
40 #include "vm/jit/arm/md-abi.h"
41
42 #define ucontext broken_glibc_ucontext
43 #define ucontext_t broken_glibc_ucontext_t
44 #include <ucontext.h>
45 #undef ucontext
46 #undef ucontext_t
47
48 typedef struct ucontext {
49    unsigned long     uc_flags;
50    struct ucontext  *uc_link;
51    stack_t           uc_stack;
52    struct sigcontext uc_mcontext;
53    sigset_t          uc_sigmask;
54 } ucontext_t;
55
56 #define scontext_t struct sigcontext
57
58 #include "mm/memory.h"
59 #include "vm/exceptions.h"
60 #include "vm/signallocal.h"
61 #include "vm/stringlocal.h"
62 #include "vm/jit/asmpart.h"
63 #include "vm/jit/stacktrace.h"
64
65
66 /* md_signal_handler_sigsegv ***************************************************
67
68    NullPointerException signal handler for hardware null pointer
69    check.
70
71 *******************************************************************************/
72
73 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
74 {
75         ucontext_t *_uc;
76         /*mcontext_t *_mc;*/
77         scontext_t *_sc;
78         u4          instr;
79         ptrint      addr;
80         ptrint      base;
81         u1          *pv;
82         u1          *sp;
83         u1          *ra;
84         u1          *xpc;
85
86         _uc = (ucontext_t*) _p;
87         _sc = &_uc->uc_mcontext;
88
89         /* ATTENTION: glibc included messed up kernel headers */
90         /* we needed a workaround for the ucontext structure */
91
92         addr = (ptrint) siginfo->si_addr;
93         /*xpc = (u1*) _mc->gregs[REG_PC];*/
94         xpc = (u1*) _sc->arm_pc;
95
96         instr = *((s4*) xpc);
97         base = *((s4*) _sc + OFFSET(scontext_t, arm_r0)/4 + ((instr >> 16) & 0x0f));
98
99         if (base == 0) {
100                 pv  = (u1*) _sc->arm_ip;
101                 sp  = (u1*) _sc->arm_sp;
102                 ra  = (u1*) _sc->arm_lr; /* this is correct for leafs */
103
104                 _sc->arm_r10 = (ptrint) stacktrace_hardware_nullpointerexception(pv, sp, ra, xpc);
105                 _sc->arm_fp = (ptrint) xpc;
106                 _sc->arm_pc = (ptrint) asm_handle_exception;
107         } else {
108                 throw_cacao_exception_exit(string_java_lang_InternalError,
109                    "Segmentation fault: %p (pc=%p, instr=%x, base=%p)\n",
110                    addr, xpc, instr, base);
111         }
112 }
113
114
115 /* thread_restartcriticalsection ***********************************************
116
117    TODO: document me
118
119 *******************************************************************************/
120
121 #if defined(ENABLE_THREADS)
122 void thread_restartcriticalsection(ucontext_t *_uc)
123 {
124         scontext_t *_sc;
125         void       *critical;
126
127         _sc = &_uc->uc_mcontext;
128
129         critical = critical_find_restart_point((void *) _sc->arm_pc);
130
131         if (critical)
132                 _sc->arm_pc = (ptrint) critical;
133 }
134 #endif
135
136
137 /*
138  * These are local overrides for various environment variables in Emacs.
139  * Please do not remove this and leave it at the end of the file, where
140  * Emacs will automagically detect them.
141  * ---------------------------------------------------------------------
142  * Local variables:
143  * mode: c
144  * indent-tabs-mode: t
145  * c-basic-offset: 4
146  * tab-width: 4
147  * End:
148  */
149