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
5 Copyright (C) 2008, 2009 Theobroma Systems Ltd.
7 This file is part of CACAO.
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2, or (at
12 your option) any later version.
14 This program is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
31 #define ucontext broken_glibc_ucontext
32 #define ucontext_t broken_glibc_ucontext_t
37 typedef struct ucontext {
38 unsigned long uc_flags;
39 struct ucontext *uc_link;
41 struct sigcontext uc_mcontext;
45 #define scontext_t struct sigcontext
49 #include "vm/jit/arm/md.h"
50 #include "vm/jit/arm/md-abi.h"
52 #include "threads/thread.hpp"
54 #include "vm/signallocal.hpp"
56 #include "vm/jit/asmpart.h"
57 #include "vm/jit/executionstate.h"
58 #include "vm/jit/trap.hpp"
62 * Signal handler for hardware exceptions.
64 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
66 ucontext_t* _uc = (ucontext_t*) _p;
67 scontext_t* _sc = &_uc->uc_mcontext;
69 /* ATTENTION: glibc included messed up kernel headers we needed a
70 workaround for the ucontext structure. */
72 void* xpc = (u1 *) _sc->arm_pc;
75 trap_handle(TRAP_SIGSEGV, xpc, _p);
80 * Illegal instruction signal handler for hardware exception checks.
82 void md_signal_handler_sigill(int sig, siginfo_t *siginfo, void *_p)
84 ucontext_t* _uc = (ucontext_t*) _p;
85 scontext_t* _sc = &_uc->uc_mcontext;
87 /* ATTENTION: glibc included messed up kernel headers we needed a
88 workaround for the ucontext structure. */
90 void* xpc = (void*) _sc->arm_pc;
93 trap_handle(TRAP_SIGILL, xpc, _p);
97 /* md_signal_handler_sigusr1 ***************************************************
99 Signal handler for suspending threads.
101 *******************************************************************************/
103 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
104 void md_signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p)
111 _uc = (ucontext_t *) _p;
112 _sc = &_uc->uc_mcontext;
114 /* get the PC and SP for this thread */
115 pc = (u1 *) _sc->arm_pc;
116 sp = (u1 *) _sc->arm_sp;
118 /* now suspend the current thread */
119 threads_suspend_ack(pc, sp);
124 /* md_signal_handler_sigusr2 ***************************************************
126 Signal handler for profiling sampling.
128 *******************************************************************************/
130 #if defined(ENABLE_THREADS)
131 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
133 threadobject *thread;
138 thread = THREADOBJECT;
140 _uc = (ucontext_t*) _p;
141 _sc = &_uc->uc_mcontext;
143 pc = (u1 *) _sc->arm_pc;
151 * Read the given context into an executionstate.
153 * @param es execution state
154 * @param context machine context
156 void md_executionstate_read(executionstate_t *es, void *context)
162 _uc = (ucontext_t *) context;
163 _sc = &_uc->uc_mcontext;
165 /* ATTENTION: glibc included messed up kernel headers we needed a
166 workaround for the ucontext structure. */
168 /* read special registers */
170 es->pc = (u1 *) _sc->arm_pc;
171 es->sp = (u1 *) _sc->arm_sp;
172 es->pv = (u1 *) _sc->arm_ip;
173 es->ra = (u1 *) _sc->arm_lr;
175 /* read integer registers */
177 for (i = 0; i < INT_REG_CNT; i++)
178 es->intregs[i] = *((int32_t*) _sc + OFFSET(scontext_t, arm_r0)/4 + i);
180 /* read float registers */
182 for (i = 0; i < FLT_REG_CNT; i++)
183 es->fltregs[i] = 0xdeadbeefdeadbeefULL;
188 * Write the given executionstate back to the context.
190 * @param es execution state
191 * @param context machine context
193 void md_executionstate_write(executionstate_t *es, void *context)
199 _uc = (ucontext_t *) context;
200 _sc = &_uc->uc_mcontext;
202 /* ATTENTION: glibc included messed up kernel headers we needed a
203 workaround for the ucontext structure. */
205 /* write integer registers */
207 for (i = 0; i < INT_REG_CNT; i++)
208 *((int32_t*) _sc + OFFSET(scontext_t, arm_r0)/4 + i) = es->intregs[i];
210 /* write special registers */
212 _sc->arm_pc = (ptrint) es->pc;
213 _sc->arm_sp = (ptrint) es->sp;
214 _sc->arm_ip = (ptrint) es->pv;
215 _sc->arm_lr = (ptrint) es->ra;
220 * These are local overrides for various environment variables in Emacs.
221 * Please do not remove this and leave it at the end of the file, where
222 * Emacs will automagically detect them.
223 * ---------------------------------------------------------------------
226 * indent-tabs-mode: t