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
35 #include "vm/jit/arm/md-abi.h"
37 #define ucontext broken_glibc_ucontext
38 #define ucontext_t broken_glibc_ucontext_t
43 typedef struct ucontext {
44 unsigned long uc_flags;
45 struct ucontext *uc_link;
47 struct sigcontext uc_mcontext;
51 #define scontext_t struct sigcontext
53 #if defined(ENABLE_THREADS)
54 # include "threads/native/threads.h"
57 #include "vm/exceptions.h"
58 #include "vm/signallocal.h"
59 #include "vm/stringlocal.h"
61 #include "vm/jit/asmpart.h"
62 #include "vm/jit/stacktrace.h"
65 /* md_signal_handler_sigsegv ***************************************************
67 Signal handler for hardware exceptions.
69 *******************************************************************************/
71 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 */
100 vm_abort("md_signal_handler_sigsegv: the program counter is NULL");
102 mcode = *((s4 *) xpc);
104 /* this is a NullPointerException */
106 addr = *((s4 *) _sc + OFFSET(scontext_t, arm_r0)/4 + ((mcode >> 16) & 0x0f));
107 type = EXCEPTION_HARDWARE_NULLPOINTER;
111 vm_abort("md_signal_handler_sigsegv: faulting address is not NULL: addr=%p", addr);
113 /* create stackframeinfo */
115 stacktrace_create_extern_stackframeinfo(&sfi, pv, sp, ra, xpc);
117 /* Handle the type. */
119 p = signal_handle(xpc, type, val);
121 /* remove stackframeinfo */
123 stacktrace_remove_stackframeinfo(&sfi);
127 _sc->arm_r10 = (intptr_t) p;
128 _sc->arm_fp = (intptr_t) xpc;
129 _sc->arm_pc = (intptr_t) asm_handle_exception;
133 /* md_signal_handler_sigill ****************************************************
135 Illegal Instruction signal handler for hardware exception checks.
137 *******************************************************************************/
139 void md_signal_handler_sigill(int sig, siginfo_t *siginfo, void *_p)
153 _uc = (ucontext_t*) _p;
154 _sc = &_uc->uc_mcontext;
156 /* ATTENTION: glibc included messed up kernel headers we needed a
157 workaround for the ucontext structure. */
159 pv = (u1 *) _sc->arm_ip;
160 sp = (u1 *) _sc->arm_sp;
161 ra = (u1 *) _sc->arm_lr; /* this is correct for leafs */
162 xpc = (u1 *) _sc->arm_pc;
164 /* get exception-throwing instruction */
166 mcode = *((u4 *) xpc);
168 /* check for undefined instruction we use */
170 if ((mcode & 0x0ff000f0) != 0x07f000f0)
171 vm_abort("md_signal_handler_sigill: unknown illegal instruction");
173 type = (mcode >> 8) & 0x0fff;
174 val = *((s4 *) _sc + OFFSET(scontext_t, arm_r0)/4 + (mcode & 0x0f));
176 /* create stackframeinfo */
178 stacktrace_create_extern_stackframeinfo(&sfi, pv, sp, ra, xpc);
180 /* Handle the type. */
182 p = signal_handle(xpc, type, val);
184 /* remove stackframeinfo */
186 stacktrace_remove_stackframeinfo(&sfi);
188 /* set registers if we have an exception, return continue execution
189 otherwise (this is needed for patchers to work) */
192 _sc->arm_r10 = (intptr_t) p;
193 _sc->arm_fp = (intptr_t) xpc;
194 _sc->arm_pc = (intptr_t) asm_handle_exception;
199 /* md_signal_handler_sigusr2 ***************************************************
201 Signal handler for profiling sampling.
203 *******************************************************************************/
205 #if defined(ENABLE_THREADS)
206 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
208 threadobject *thread;
213 thread = THREADOBJECT;
215 _uc = (ucontext_t*) _p;
216 _sc = &_uc->uc_mcontext;
218 pc = (u1 *) _sc->arm_pc;
225 /* md_critical_section_restart *************************************************
227 Search the critical sections tree for a matching section and set
228 the PC to the restart point, if necessary.
230 *******************************************************************************/
232 #if defined(ENABLE_THREADS)
233 void md_critical_section_restart(ucontext_t *_uc)
239 _sc = &_uc->uc_mcontext;
241 pc = (u1 *) _sc->arm_pc;
243 npc = critical_find_restart_point(pc);
246 _sc->arm_pc = (ptrint) npc;
252 * These are local overrides for various environment variables in Emacs.
253 * Please do not remove this and leave it at the end of the file, where
254 * Emacs will automagically detect them.
255 * ---------------------------------------------------------------------
258 * indent-tabs-mode: t