1 /* src/vm/jit/arm/linux/md-os.c - machine dependent arm linux functions
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
8 This file is part of CACAO.
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.
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.
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
25 $Id: md.c 166 2006-01-22 23:38:44Z twisti $
36 #include "vm/jit/arm/md-abi.h"
38 #define ucontext broken_glibc_ucontext
39 #define ucontext_t broken_glibc_ucontext_t
44 typedef struct ucontext {
45 unsigned long uc_flags;
46 struct ucontext *uc_link;
48 struct sigcontext uc_mcontext;
52 #define scontext_t struct sigcontext
54 #if defined(ENABLE_THREADS)
55 # include "threads/native/threads.h"
58 #include "vm/exceptions.h"
59 #include "vm/signallocal.h"
60 #include "vm/stringlocal.h"
62 #include "vm/jit/asmpart.h"
63 #include "vm/jit/stacktrace.h"
66 /* md_signal_handler_sigsegv ***************************************************
68 Signal handler for hardware exceptions.
70 *******************************************************************************/
72 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
86 _uc = (ucontext_t*) _p;
87 _sc = &_uc->uc_mcontext;
89 /* ATTENTION: glibc included messed up kernel headers we needed a
90 workaround for the ucontext structure. */
92 pv = (u1 *) _sc->arm_ip;
93 sp = (u1 *) _sc->arm_sp;
94 ra = (u1 *) _sc->arm_lr; /* this is correct for leafs */
95 xpc = (u1 *) _sc->arm_pc;
97 /* get exception-throwing instruction */
99 mcode = *((s4 *) xpc);
101 /* this is a NullPointerException */
103 /* addr = _mc->gregs[s1]; */
104 addr = *((s4 *) _sc + OFFSET(scontext_t, arm_r0)/4 + ((mcode >> 16) & 0x0f));
105 type = EXCEPTION_HARDWARE_NULLPOINTER;
109 vm_abort("md_signal_handler_sigsegv: faulting address is not NULL: addr=%p", addr);
111 /* generate appropriate exception */
113 o = exceptions_new_hardware_exception(pv, sp, ra, xpc, type, val);
117 _sc->arm_r10 = (ptrint) o;
118 _sc->arm_fp = (ptrint) xpc;
119 _sc->arm_pc = (ptrint) asm_handle_exception;
123 /* md_signal_handler_sigill ****************************************************
125 Illegal Instruction signal handler for hardware exception checks.
127 *******************************************************************************/
129 void md_signal_handler_sigill(int sig, siginfo_t *siginfo, void *_p)
140 java_objectheader *o;
142 _uc = (ucontext_t*) _p;
143 _sc = &_uc->uc_mcontext;
145 /* ATTENTION: glibc included messed up kernel headers we needed a
146 workaround for the ucontext structure. */
148 pv = (u1 *) _sc->arm_ip;
149 sp = (u1 *) _sc->arm_sp;
150 ra = (u1 *) _sc->arm_lr; /* this is correct for leafs */
151 xpc = (u1 *) _sc->arm_pc;
153 /* get exception-throwing instruction */
155 mcode = *((u4 *) xpc);
157 /* check for undefined instruction we use */
159 if ((mcode & 0x0ff000f0) != 0x07f000f0)
160 vm_abort("md_signal_handler_sigill: unknown illegal instruction");
162 type = (mcode >> 8) & 0x0fff;
163 val = *((s4 *) _sc + OFFSET(scontext_t, arm_r0)/4 + (mcode & 0x0f));
165 /* generate appropriate exception */
167 o = exceptions_new_hardware_exception(pv, sp, ra, xpc, type, val);
171 _sc->arm_r10 = (ptrint) o;
172 _sc->arm_fp = (ptrint) xpc;
173 _sc->arm_pc = (ptrint) asm_handle_exception;
177 /* md_signal_handler_sigusr2 ***************************************************
179 Signal handler for profiling sampling.
181 *******************************************************************************/
183 #if defined(ENABLE_THREADS)
184 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
186 threadobject *thread;
191 thread = THREADOBJECT;
193 _uc = (ucontext_t*) _p;
194 _sc = &_uc->uc_mcontext;
196 pc = (u1 *) _sc->arm_pc;
203 /* thread_restartcriticalsection ***********************************************
207 *******************************************************************************/
209 #if defined(ENABLE_THREADS)
210 void thread_restartcriticalsection(ucontext_t *_uc)
215 _sc = &_uc->uc_mcontext;
217 critical = critical_find_restart_point((void *) _sc->arm_pc);
220 _sc->arm_pc = (ptrint) critical;
226 * These are local overrides for various environment variables in Emacs.
227 * Please do not remove this and leave it at the end of the file, where
228 * Emacs will automagically detect them.
229 * ---------------------------------------------------------------------
232 * indent-tabs-mode: t