1 /* src/vm/jit/powerpc64/linux/md-os.c - machine dependent PowerPC64 Linux functions
3 Copyright (C) 1996-2005, 2006, 2007, 2008, 2009
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 Copyright (C) 2008 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
35 #include "vm/jit/powerpc64/codegen.h"
36 #include "vm/jit/powerpc64/md.h"
37 #include "vm/jit/powerpc64/linux/md-abi.h"
39 #include "threads/thread.hpp"
41 #include "vm/signallocal.hpp"
43 #include "vm/jit/asmpart.h"
44 #include "vm/jit/executionstate.h"
45 #include "vm/jit/trap.hpp"
49 * Signal handler for hardware-exceptions.
51 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
53 ucontext_t* _uc = (ucontext_t *) _p;
54 mcontext_t* _mc = &(_uc->uc_mcontext);
56 void* xpc = (void*) _mc->gp_regs[PT_NIP];
59 trap_handle(TRAP_SIGSEGV, xpc, _p);
64 * Signal handler for patcher calls.
66 void md_signal_handler_sigill(int sig, siginfo_t* siginfo, void* _p)
68 ucontext_t* _uc = (ucontext_t*) _p;
69 mcontext_t* _mc = &(_uc->uc_mcontext);
71 void* xpc =(void*) _mc->gp_regs[PT_NIP];
74 trap_handle(TRAP_SIGILL, xpc, _p);
78 /* md_signal_handler_sigusr2 ***************************************************
80 Signal handler for profiling sampling.
82 *******************************************************************************/
84 #if defined(ENABLE_THREADS)
85 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
94 _uc = (ucontext_t *) _p;
95 _mc = &(_uc->uc_mcontext);
97 pc = (u1 *) _mc->gp_regs[PT_NIP];
104 /* md_executionstate_read ******************************************************
106 Read the given context into an executionstate.
108 *******************************************************************************/
110 void md_executionstate_read(executionstate_t *es, void *context)
116 _uc = (ucontext_t *) context;
117 _mc = &(_uc->uc_mcontext);
119 /* read special registers */
120 es->pc = (u1 *) _mc->gp_regs[PT_NIP];
121 es->sp = (u1 *) _mc->gp_regs[REG_SP];
122 es->pv = (u1 *) _mc->gp_regs[REG_PV];
123 es->ra = (u1 *) _mc->gp_regs[PT_LNK];
125 /* read integer registers */
126 for (i = 0; i < INT_REG_CNT; i++)
127 es->intregs[i] = _mc->gp_regs[i];
129 /* read float registers */
130 /* Do not use the assignment operator '=', as the type of
131 * the _mc->fpregs[i] can cause invalid conversions. */
133 // The assertion below will fail because _mc->fp_regs[] also
134 // contains the "fpscr" register.
135 //assert(sizeof(_mc->fp_regs) == sizeof(es->fltregs));
136 os_memcpy(&es->fltregs, &_mc->fp_regs, sizeof(es->fltregs));
140 /* md_executionstate_write *****************************************************
142 Write the given executionstate back to the context.
144 *******************************************************************************/
146 void md_executionstate_write(executionstate_t *es, void *context)
152 _uc = (ucontext_t *) context;
153 _mc = &(_uc->uc_mcontext);
155 /* write integer registers */
156 for (i = 0; i < INT_REG_CNT; i++)
157 _mc->gp_regs[i] = es->intregs[i];
159 /* write float registers */
160 /* Do not use the assignment operator '=', as the type of
161 * the _mc->fpregs[i] can cause invalid conversions. */
163 // The assertion below will fail because _mc->fp_regs[] also
164 // contains the "fpscr" register.
165 //assert(sizeof(_mc->fp_regs) == sizeof(es->fltregs));
166 os_memcpy(&_mc->fp_regs, &es->fltregs, sizeof(es->fltregs));
168 /* write special registers */
169 _mc->gp_regs[PT_NIP] = (ptrint) es->pc;
170 _mc->gp_regs[REG_SP] = (ptrint) es->sp;
171 _mc->gp_regs[REG_PV] = (ptrint) es->pv;
172 _mc->gp_regs[PT_LNK] = (ptrint) es->ra;
177 * These are local overrides for various environment variables in Emacs.
178 * Please do not remove this and leave it at the end of the file, where
179 * Emacs will automagically detect them.
180 * ---------------------------------------------------------------------
183 * indent-tabs-mode: t