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"
61 #include "vm/jit/trap.h"
64 /* md_signal_handler_sigsegv ***************************************************
66 Signal handler for hardware exceptions.
68 *******************************************************************************/
70 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
84 _uc = (ucontext_t*) _p;
85 _sc = &_uc->uc_mcontext;
87 /* ATTENTION: glibc included messed up kernel headers we needed a
88 workaround for the ucontext structure. */
90 pv = (u1 *) _sc->arm_ip;
91 sp = (u1 *) _sc->arm_sp;
92 ra = (u1 *) _sc->arm_lr; /* this is correct for leafs */
93 xpc = (u1 *) _sc->arm_pc;
95 /* get exception-throwing instruction */
98 vm_abort("md_signal_handler_sigsegv: the program counter is NULL");
100 mcode = *((s4 *) xpc);
102 /* This is a NullPointerException. */
104 addr = *((s4 *) _sc + OFFSET(scontext_t, arm_r0)/4 + ((mcode >> 16) & 0x0f));
108 /* Handle the trap. */
110 p = trap_handle(type, val, pv, sp, ra, xpc, _p);
114 _sc->arm_r10 = (uintptr_t) p;
115 _sc->arm_fp = (uintptr_t) xpc;
116 _sc->arm_pc = (uintptr_t) asm_handle_exception;
120 /* md_signal_handler_sigill ****************************************************
122 Illegal Instruction signal handler for hardware exception checks.
124 *******************************************************************************/
126 void md_signal_handler_sigill(int sig, siginfo_t *siginfo, void *_p)
139 _uc = (ucontext_t*) _p;
140 _sc = &_uc->uc_mcontext;
142 /* ATTENTION: glibc included messed up kernel headers we needed a
143 workaround for the ucontext structure. */
145 pv = (u1 *) _sc->arm_ip;
146 sp = (u1 *) _sc->arm_sp;
147 ra = (u1 *) _sc->arm_lr; /* this is correct for leafs */
148 xpc = (u1 *) _sc->arm_pc;
150 /* get exception-throwing instruction */
152 mcode = *((u4 *) xpc);
154 /* check for undefined instruction we use */
156 if ((mcode & 0x0ff000f0) != 0x07f000f0) {
157 log_println("md_signal_handler_sigill: unknown illegal instruction: inst=%x", mcode);
158 #if defined(ENABLE_DISASSEMBLER)
161 vm_abort("Aborting...");
164 type = (mcode >> 8) & 0x0fff;
165 val = *((s4 *) _sc + OFFSET(scontext_t, arm_r0)/4 + (mcode & 0x0f));
167 /* Handle the trap. */
169 p = trap_handle(type, val, pv, sp, ra, xpc, _p);
171 /* set registers if we have an exception, continue execution
172 otherwise (this is needed for patchers to work) */
175 _sc->arm_r10 = (uintptr_t) p;
176 _sc->arm_fp = (uintptr_t) xpc;
177 _sc->arm_pc = (uintptr_t) asm_handle_exception;
182 /* md_signal_handler_sigusr1 ***************************************************
184 Signal handler for suspending threads.
186 *******************************************************************************/
188 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
189 void md_signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p)
196 _uc = (ucontext_t *) _p;
197 _sc = &_uc->uc_mcontext;
199 /* get the PC and SP for this thread */
200 pc = (u1 *) _sc->arm_pc;
201 sp = (u1 *) _sc->arm_sp;
203 /* now suspend the current thread */
204 threads_suspend_ack(pc, sp);
209 /* md_signal_handler_sigusr2 ***************************************************
211 Signal handler for profiling sampling.
213 *******************************************************************************/
215 #if defined(ENABLE_THREADS)
216 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
218 threadobject *thread;
223 thread = THREADOBJECT;
225 _uc = (ucontext_t*) _p;
226 _sc = &_uc->uc_mcontext;
228 pc = (u1 *) _sc->arm_pc;
235 /* md_critical_section_restart *************************************************
237 Search the critical sections tree for a matching section and set
238 the PC to the restart point, if necessary.
240 *******************************************************************************/
242 #if defined(ENABLE_THREADS)
243 void md_critical_section_restart(ucontext_t *_uc)
249 _sc = &_uc->uc_mcontext;
251 pc = (u1 *) _sc->arm_pc;
253 npc = critical_find_restart_point(pc);
256 _sc->arm_pc = (ptrint) npc;
262 * These are local overrides for various environment variables in Emacs.
263 * Please do not remove this and leave it at the end of the file, where
264 * Emacs will automagically detect them.
265 * ---------------------------------------------------------------------
268 * indent-tabs-mode: t