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_sigusr2 ***************************************************
99 Signal handler for profiling sampling.
101 *******************************************************************************/
103 #if defined(ENABLE_THREADS)
104 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
106 threadobject *thread;
111 thread = THREADOBJECT;
113 _uc = (ucontext_t*) _p;
114 _sc = &_uc->uc_mcontext;
116 pc = (u1 *) _sc->arm_pc;
124 * Read the given context into an executionstate.
126 * @param es execution state
127 * @param context machine context
129 void md_executionstate_read(executionstate_t *es, void *context)
135 _uc = (ucontext_t *) context;
136 _sc = &_uc->uc_mcontext;
138 /* ATTENTION: glibc included messed up kernel headers we needed a
139 workaround for the ucontext structure. */
141 /* read special registers */
143 es->pc = (u1 *) _sc->arm_pc;
144 es->sp = (u1 *) _sc->arm_sp;
145 es->pv = (u1 *) _sc->arm_ip;
146 es->ra = (u1 *) _sc->arm_lr;
148 /* read integer registers */
150 for (i = 0; i < INT_REG_CNT; i++)
151 es->intregs[i] = *((int32_t*) _sc + OFFSET(scontext_t, arm_r0)/4 + i);
153 /* read float registers */
155 for (i = 0; i < FLT_REG_CNT; i++)
156 es->fltregs[i] = 0xdeadbeefdeadbeefULL;
161 * Write the given executionstate back to the context.
163 * @param es execution state
164 * @param context machine context
166 void md_executionstate_write(executionstate_t *es, void *context)
172 _uc = (ucontext_t *) context;
173 _sc = &_uc->uc_mcontext;
175 /* ATTENTION: glibc included messed up kernel headers we needed a
176 workaround for the ucontext structure. */
178 /* write integer registers */
180 for (i = 0; i < INT_REG_CNT; i++)
181 *((int32_t*) _sc + OFFSET(scontext_t, arm_r0)/4 + i) = es->intregs[i];
183 /* write special registers */
185 _sc->arm_pc = (ptrint) es->pc;
186 _sc->arm_sp = (ptrint) es->sp;
187 _sc->arm_ip = (ptrint) es->pv;
188 _sc->arm_lr = (ptrint) es->ra;
193 * These are local overrides for various environment variables in Emacs.
194 * Please do not remove this and leave it at the end of the file, where
195 * Emacs will automagically detect them.
196 * ---------------------------------------------------------------------
199 * indent-tabs-mode: t