1 /* src/vm/jit/arm/linux/md-os.c - machine dependent ARM Linux functions
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
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.
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.
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
32 #include "vm/jit/disass.h"
34 #include "vm/jit/arm/md-abi.h"
36 #define ucontext broken_glibc_ucontext
37 #define ucontext_t broken_glibc_ucontext_t
42 typedef struct ucontext {
43 unsigned long uc_flags;
44 struct ucontext *uc_link;
46 struct sigcontext uc_mcontext;
50 #define scontext_t struct sigcontext
52 #include "threads/thread.h"
54 #include "vm/exceptions.h"
55 #include "vm/signallocal.h"
56 #include "vm/stringlocal.h"
59 #include "vm/jit/asmpart.h"
60 #include "vm/jit/stacktrace.h"
63 /* md_signal_handler_sigsegv ***************************************************
65 Signal handler for hardware exceptions.
67 *******************************************************************************/
69 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
83 _uc = (ucontext_t*) _p;
84 _sc = &_uc->uc_mcontext;
86 /* ATTENTION: glibc included messed up kernel headers we needed a
87 workaround for the ucontext structure. */
89 pv = (u1 *) _sc->arm_ip;
90 sp = (u1 *) _sc->arm_sp;
91 ra = (u1 *) _sc->arm_lr; /* this is correct for leafs */
92 xpc = (u1 *) _sc->arm_pc;
94 /* get exception-throwing instruction */
97 vm_abort("md_signal_handler_sigsegv: the program counter is NULL");
99 mcode = *((s4 *) xpc);
101 /* this is a NullPointerException */
103 addr = *((s4 *) _sc + OFFSET(scontext_t, arm_r0)/4 + ((mcode >> 16) & 0x0f));
104 type = EXCEPTION_HARDWARE_NULLPOINTER;
108 vm_abort("md_signal_handler_sigsegv: faulting address is not NULL: addr=%p", addr);
110 /* Handle the type. */
112 p = signal_handle(type, val, pv, sp, ra, xpc, _p);
116 _sc->arm_r10 = (intptr_t) p;
117 _sc->arm_fp = (intptr_t) xpc;
118 _sc->arm_pc = (intptr_t) asm_handle_exception;
122 /* md_signal_handler_sigill ****************************************************
124 Illegal Instruction signal handler for hardware exception checks.
126 *******************************************************************************/
128 void md_signal_handler_sigill(int sig, siginfo_t *siginfo, void *_p)
141 _uc = (ucontext_t*) _p;
142 _sc = &_uc->uc_mcontext;
144 /* ATTENTION: glibc included messed up kernel headers we needed a
145 workaround for the ucontext structure. */
147 pv = (u1 *) _sc->arm_ip;
148 sp = (u1 *) _sc->arm_sp;
149 ra = (u1 *) _sc->arm_lr; /* this is correct for leafs */
150 xpc = (u1 *) _sc->arm_pc;
152 /* get exception-throwing instruction */
154 mcode = *((u4 *) xpc);
156 /* check for undefined instruction we use */
158 if ((mcode & 0x0ff000f0) != 0x07f000f0) {
159 log_println("md_signal_handler_sigill: unknown illegal instruction: inst=%x", mcode);
160 #if defined(ENABLE_DISASSEMBLER)
163 vm_abort("Aborting...");
166 type = (mcode >> 8) & 0x0fff;
167 val = *((s4 *) _sc + OFFSET(scontext_t, arm_r0)/4 + (mcode & 0x0f));
169 /* Handle the type. */
171 p = signal_handle(type, val, pv, sp, ra, xpc, _p);
173 /* set registers if we have an exception, continue execution
174 otherwise (this is needed for patchers to work) */
177 _sc->arm_r10 = (intptr_t) p;
178 _sc->arm_fp = (intptr_t) xpc;
179 _sc->arm_pc = (intptr_t) asm_handle_exception;
184 /* md_signal_handler_sigusr1 ***************************************************
186 Signal handler for suspending threads.
188 *******************************************************************************/
190 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
191 void md_signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p)
198 _uc = (ucontext_t *) _p;
199 _sc = &_uc->uc_mcontext;
201 /* get the PC and SP for this thread */
202 pc = (u1 *) _sc->arm_pc;
203 sp = (u1 *) _sc->arm_sp;
205 /* now suspend the current thread */
206 threads_suspend_ack(pc, sp);
211 /* md_signal_handler_sigusr2 ***************************************************
213 Signal handler for profiling sampling.
215 *******************************************************************************/
217 #if defined(ENABLE_THREADS)
218 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
220 threadobject *thread;
225 thread = THREADOBJECT;
227 _uc = (ucontext_t*) _p;
228 _sc = &_uc->uc_mcontext;
230 pc = (u1 *) _sc->arm_pc;
237 /* md_critical_section_restart *************************************************
239 Search the critical sections tree for a matching section and set
240 the PC to the restart point, if necessary.
242 *******************************************************************************/
244 #if defined(ENABLE_THREADS)
245 void md_critical_section_restart(ucontext_t *_uc)
251 _sc = &_uc->uc_mcontext;
253 pc = (u1 *) _sc->arm_pc;
255 npc = critical_find_restart_point(pc);
258 _sc->arm_pc = (ptrint) npc;
264 * These are local overrides for various environment variables in Emacs.
265 * Please do not remove this and leave it at the end of the file, where
266 * Emacs will automagically detect them.
267 * ---------------------------------------------------------------------
270 * indent-tabs-mode: t