1 /* src/vm/jit/x86_64/linux/md-os.c - machine dependent x86_64 Linux functions
3 Copyright (C) 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
37 #include "vm/jit/x86_64/codegen.h"
38 #include "vm/jit/x86_64/md.h"
40 #include "threads/thread.hpp"
42 #include "vm/signallocal.hpp"
44 #include "vm/jit/asmpart.h"
45 #include "vm/jit/executionstate.h"
46 #include "vm/jit/trap.hpp"
50 * Signal handler for hardware exception.
52 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
54 ucontext_t* _uc = (ucontext_t *) _p;
55 mcontext_t* _mc = &_uc->uc_mcontext;
57 /* ATTENTION: Don't use CACAO's internal REG_* defines as they are
58 different to the ones in <ucontext.h>. */
60 void* xpc = (void*) _mc->gregs[REG_RIP];
63 trap_handle(TRAP_SIGSEGV, xpc, _p);
68 * ArithmeticException signal handler for hardware divide by zero
71 void md_signal_handler_sigfpe(int sig, siginfo_t *siginfo, void *_p)
73 ucontext_t* _uc = (ucontext_t *) _p;
74 mcontext_t* _mc = &_uc->uc_mcontext;
76 /* ATTENTION: Don't use CACAO's internal REG_* defines as they are
77 different to the ones in <ucontext.h>. */
79 void* xpc = (void*) _mc->gregs[REG_RIP];
82 trap_handle(TRAP_SIGFPE, xpc, _p);
87 * Signal handler for patchers.
89 void md_signal_handler_sigill(int sig, siginfo_t *siginfo, void *_p)
91 ucontext_t* _uc = (ucontext_t *) _p;
92 mcontext_t* _mc = &_uc->uc_mcontext;
94 /* ATTENTION: Don't use CACAO's internal REG_* defines as they are
95 different to the ones in <ucontext.h>. */
97 void* xpc = (void*) _mc->gregs[REG_RIP];
100 trap_handle(TRAP_SIGILL, xpc, _p);
104 /* md_signal_handler_sigusr2 ***************************************************
106 Signal handler for profiling sampling.
108 *******************************************************************************/
110 #if defined(ENABLE_THREADS)
111 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
120 _uc = (ucontext_t *) _p;
121 _mc = &_uc->uc_mcontext;
123 /* ATTENTION: Don't use CACAO's internal REG_* defines as they are
124 different to the ones in <ucontext.h>. */
126 pc = (u1 *) _mc->gregs[REG_RIP];
133 /* md_executionstate_read ******************************************************
135 Read the given context into an executionstate.
137 *******************************************************************************/
139 void md_executionstate_read(executionstate_t *es, void *context)
146 _uc = (ucontext_t *) context;
147 _mc = &_uc->uc_mcontext;
149 /* ATTENTION: Don't use CACAO's internal REG_* defines as they are
150 different to the ones in <ucontext.h>. */
152 /* read special registers */
153 es->pc = (u1 *) _mc->gregs[REG_RIP];
154 es->sp = (u1 *) _mc->gregs[REG_RSP];
157 /* read integer registers */
158 for (i = 0; i < INT_REG_CNT; i++) {
162 case 0: /* REG_RAX == 13 */
165 case 1: /* REG_RCX == 14 */
168 case 2: /* REG_RDX == 12 */
171 case 3: /* REG_RBX == 11 */
174 case 4: /* REG_RSP == 15 */
177 case 5: /* REG_RBP == 10 */
180 case 6: /* REG_RSI == 9 */
183 case 7: /* REG_RDI == 8 */
186 case 8: /* REG_R8 == 0 */
187 case 9: /* REG_R9 == 1 */
188 case 10: /* REG_R10 == 2 */
189 case 11: /* REG_R11 == 3 */
190 case 12: /* REG_R12 == 4 */
191 case 13: /* REG_R13 == 5 */
192 case 14: /* REG_R14 == 6 */
193 case 15: /* REG_R15 == 7 */
198 es->intregs[i] = _mc->gregs[d];
201 /* read float registers */
202 for (i = 0; i < FLT_REG_CNT; i++)
203 es->fltregs[i] = 0xdeadbeefdeadbeefL;
207 /* md_executionstate_write *****************************************************
209 Write the given executionstate back to the context.
211 *******************************************************************************/
213 void md_executionstate_write(executionstate_t *es, void *context)
220 _uc = (ucontext_t *) context;
221 _mc = &_uc->uc_mcontext;
223 /* ATTENTION: Don't use CACAO's internal REG_* defines as they are
224 different to the ones in <ucontext.h>. */
226 /* write integer registers */
227 for (i = 0; i < INT_REG_CNT; i++) {
231 case 0: /* REG_RAX == 13 */
234 case 1: /* REG_RCX == 14 */
237 case 2: /* REG_RDX == 12 */
240 case 3: /* REG_RBX == 11 */
243 case 4: /* REG_RSP == 15 */
246 case 5: /* REG_RBP == 10 */
249 case 6: /* REG_RSI == 9 */
252 case 7: /* REG_RDI == 8 */
255 case 8: /* REG_R8 == 0 */
256 case 9: /* REG_R9 == 1 */
257 case 10: /* REG_R10 == 2 */
258 case 11: /* REG_R11 == 3 */
259 case 12: /* REG_R12 == 4 */
260 case 13: /* REG_R13 == 5 */
261 case 14: /* REG_R14 == 6 */
262 case 15: /* REG_R15 == 7 */
267 _mc->gregs[d] = es->intregs[i];
270 /* write special registers */
271 _mc->gregs[REG_RIP] = (ptrint) es->pc;
272 _mc->gregs[REG_RSP] = (ptrint) es->sp;
277 * These are local overrides for various environment variables in Emacs.
278 * Please do not remove this and leave it at the end of the file, where
279 * Emacs will automagically detect them.
280 * ---------------------------------------------------------------------
283 * indent-tabs-mode: t
287 * vim:noexpandtab:sw=4:ts=4: