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.hpp"
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/trap.h"
54 /* md_signal_handler_sigsegv ***************************************************
56 Signal handler for hardware-exceptions.
58 *******************************************************************************/
60 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
77 _uc = (ucontext_t *) _p;
78 _mc = &(_uc->uc_mcontext);
80 /* get register values */
82 pv = (u1*) _mc->gp_regs[REG_PV];
83 sp = (u1*) _mc->gp_regs[REG_SP];
84 ra = (u1*) _mc->gp_regs[PT_LNK]; /* correct for leafs */
85 xpc =(u1*) _mc->gp_regs[PT_NIP];
87 /* get the throwing instruction */
91 s1 = M_INSTR_OP2_IMM_A(mcode);
92 disp = M_INSTR_OP2_IMM_I(mcode);
93 d = M_INSTR_OP2_IMM_D(mcode);
95 val = _mc->gp_regs[d];
98 /* We use the exception type as load displacement. */
101 if (type == TRAP_COMPILER) {
102 /* The XPC is the RA minus 1, because the RA points to the
103 instruction after the call. */
110 addr = _mc->gp_regs[s1];
114 /* Handle the trap. */
116 p = trap_handle(type, val, pv, sp, ra, xpc, _p);
123 _mc->gp_regs[REG_PV] = (uintptr_t) p;
124 _mc->gp_regs[PT_NIP] = (uintptr_t) p;
128 /* Get and set the PV from the parent Java method. */
130 pv = md_codegen_get_pv_from_pc(ra);
132 _mc->gp_regs[REG_PV] = (uintptr_t) pv;
134 /* Get the exception object. */
136 p = builtin_retrieve_exception();
149 _mc->gp_regs[REG_ITMP1_XPTR] = (uintptr_t) p;
150 _mc->gp_regs[REG_ITMP2_XPC] = (uintptr_t) xpc;
151 _mc->gp_regs[PT_NIP] = (uintptr_t) asm_handle_exception;
156 /* md_signal_handler_sigusr2 ***************************************************
158 Signal handler for profiling sampling.
160 *******************************************************************************/
162 #if defined(ENABLE_THREADS)
163 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
172 _uc = (ucontext_t *) _p;
173 _mc = &(_uc->uc_mcontext);
175 pc = (u1 *) _mc->gp_regs[PT_NIP];
182 /* md_executionstate_read ******************************************************
184 Read the given context into an executionstate.
186 *******************************************************************************/
188 void md_executionstate_read(executionstate_t *es, void *context)
193 unsigned long *_gregs;
196 _uc = (ucontext_t *) context;
198 _mc = _uc->uc_mcontext.uc_regs;
201 /* read special registers */
202 es->pc = (u1 *) _gregs[PT_NIP];
203 es->sp = (u1 *) _gregs[REG_SP];
204 es->pv = (u1 *) _gregs[REG_PV];
205 es->ra = (u1 *) _gregs[PT_LNK];
207 /* read integer registers */
208 for (i = 0; i < INT_REG_CNT; i++)
209 es->intregs[i] = _gregs[i];
211 /* read float registers */
212 /* Do not use the assignment operator '=', as the type of
213 * the _mc->fpregs[i] can cause invalid conversions. */
215 assert(sizeof(_mc->fpregs.fpregs) == sizeof(es->fltregs));
216 system_memcpy(&es->fltregs, &_mc->fpregs.fpregs, sizeof(_mc->fpregs.fpregs));
219 vm_abort("md_executionstate_read: IMPLEMENT ME!");
223 /* md_executionstate_write *****************************************************
225 Write the given executionstate back to the context.
227 *******************************************************************************/
229 void md_executionstate_write(executionstate_t *es, void *context)
234 unsigned long *_gregs;
237 _uc = (ucontext_t *) context;
239 _mc = _uc->uc_mcontext.uc_regs;
242 /* write integer registers */
243 for (i = 0; i < INT_REG_CNT; i++)
244 _gregs[i] = es->intregs[i];
246 /* write float registers */
247 /* Do not use the assignment operator '=', as the type of
248 * the _mc->fpregs[i] can cause invalid conversions. */
250 assert(sizeof(_mc->fpregs.fpregs) == sizeof(es->fltregs));
251 system_memcpy(&_mc->fpregs.fpregs, &es->fltregs, sizeof(_mc->fpregs.fpregs));
253 /* write special registers */
254 _gregs[PT_NIP] = (ptrint) es->pc;
255 _gregs[REG_SP] = (ptrint) es->sp;
256 _gregs[REG_PV] = (ptrint) es->pv;
257 _gregs[PT_LNK] = (ptrint) es->ra;
260 vm_abort("md_executionstate_write: IMPLEMENT ME!");
265 * These are local overrides for various environment variables in Emacs.
266 * Please do not remove this and leave it at the end of the file, where
267 * Emacs will automagically detect them.
268 * ---------------------------------------------------------------------
271 * indent-tabs-mode: t