1 /* src/vm/jit/powerpc64/linux/md-os.c - machine dependent PowerPC64 Linux functions
3 Copyright (C) 1996-2005, 2006, 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
34 #include "vm/jit/powerpc64/codegen.h"
35 #include "vm/jit/powerpc64/md.h"
36 #include "vm/jit/powerpc64/linux/md-abi.h"
38 #include "threads/thread.h"
40 #include "vm/builtin.h"
41 #include "vm/exceptions.h"
42 #include "vm/signallocal.h"
44 #include "vm/jit/asmpart.h"
45 #include "vm/jit/executionstate.h"
47 #if defined(ENABLE_PROFILING)
48 # include "vm/jit/optimizing/profile.h"
51 #include "vm/jit/stacktrace.h"
52 #include "vm/jit/trap.h"
55 /* md_signal_handler_sigsegv ***************************************************
57 Signal handler for hardware-exceptions.
59 *******************************************************************************/
61 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
78 _uc = (ucontext_t *) _p;
79 _mc = &(_uc->uc_mcontext);
81 /* get register values */
83 pv = (u1*) _mc->gp_regs[REG_PV];
84 sp = (u1*) _mc->gp_regs[REG_SP];
85 ra = (u1*) _mc->gp_regs[PT_LNK]; /* correct for leafs */
86 xpc =(u1*) _mc->gp_regs[PT_NIP];
88 /* get the throwing instruction */
92 s1 = M_INSTR_OP2_IMM_A(mcode);
93 disp = M_INSTR_OP2_IMM_I(mcode);
94 d = M_INSTR_OP2_IMM_D(mcode);
96 val = _mc->gp_regs[d];
99 /* We use the exception type as load displacement. */
102 if (type == TRAP_COMPILER) {
103 /* The XPC is the RA minus 1, because the RA points to the
104 instruction after the call. */
111 addr = _mc->gp_regs[s1];
115 /* Handle the trap. */
117 p = trap_handle(type, val, pv, sp, ra, xpc, _p);
124 _mc->gp_regs[REG_PV] = (uintptr_t) p;
125 _mc->gp_regs[PT_NIP] = (uintptr_t) p;
129 /* Get and set the PV from the parent Java method. */
131 pv = md_codegen_get_pv_from_pc(ra);
133 _mc->gp_regs[REG_PV] = (uintptr_t) pv;
135 /* Get the exception object. */
137 p = builtin_retrieve_exception();
150 _mc->gp_regs[REG_ITMP1_XPTR] = (uintptr_t) p;
151 _mc->gp_regs[REG_ITMP2_XPC] = (uintptr_t) xpc;
152 _mc->gp_regs[PT_NIP] = (uintptr_t) asm_handle_exception;
157 /* md_signal_handler_sigusr2 ***************************************************
159 Signal handler for profiling sampling.
161 *******************************************************************************/
163 #if defined(ENABLE_THREADS)
164 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
173 _uc = (ucontext_t *) _p;
174 _mc = &(_uc->uc_mcontext);
176 pc = (u1 *) _mc->gp_regs[PT_NIP];
183 /* md_executionstate_read ******************************************************
185 Read the given context into an executionstate.
187 *******************************************************************************/
189 void md_executionstate_read(executionstate_t *es, void *context)
194 unsigned long *_gregs;
197 _uc = (ucontext_t *) context;
199 _mc = _uc->uc_mcontext.uc_regs;
202 /* read special registers */
203 es->pc = (u1 *) _gregs[PT_NIP];
204 es->sp = (u1 *) _gregs[REG_SP];
205 es->pv = (u1 *) _gregs[REG_PV];
206 es->ra = (u1 *) _gregs[PT_LNK];
208 /* read integer registers */
209 for (i = 0; i < INT_REG_CNT; i++)
210 es->intregs[i] = _gregs[i];
212 /* read float registers */
213 /* Do not use the assignment operator '=', as the type of
214 * the _mc->fpregs[i] can cause invalid conversions. */
216 assert(sizeof(_mc->fpregs.fpregs) == sizeof(es->fltregs));
217 system_memcpy(&es->fltregs, &_mc->fpregs.fpregs, sizeof(_mc->fpregs.fpregs));
220 vm_abort("md_executionstate_read: IMPLEMENT ME!");
224 /* md_executionstate_write *****************************************************
226 Write the given executionstate back to the context.
228 *******************************************************************************/
230 void md_executionstate_write(executionstate_t *es, void *context)
235 unsigned long *_gregs;
238 _uc = (ucontext_t *) context;
240 _mc = _uc->uc_mcontext.uc_regs;
243 /* write integer registers */
244 for (i = 0; i < INT_REG_CNT; i++)
245 _gregs[i] = es->intregs[i];
247 /* write float registers */
248 /* Do not use the assignment operator '=', as the type of
249 * the _mc->fpregs[i] can cause invalid conversions. */
251 assert(sizeof(_mc->fpregs.fpregs) == sizeof(es->fltregs));
252 system_memcpy(&_mc->fpregs.fpregs, &es->fltregs, sizeof(_mc->fpregs.fpregs));
254 /* write special registers */
255 _gregs[PT_NIP] = (ptrint) es->pc;
256 _gregs[REG_SP] = (ptrint) es->sp;
257 _gregs[REG_PV] = (ptrint) es->pv;
258 _gregs[PT_LNK] = (ptrint) es->ra;
261 vm_abort("md_executionstate_write: IMPLEMENT ME!");
266 * These are local overrides for various environment variables in Emacs.
267 * Please do not remove this and leave it at the end of the file, where
268 * Emacs will automagically detect them.
269 * ---------------------------------------------------------------------
272 * indent-tabs-mode: t