1 /* src/vm/jit/powerpc/linux/md-os.c - machine dependent PowerPC 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
35 #include "vm/jit/powerpc/codegen.h"
36 #include "vm/jit/powerpc/md.h"
37 #include "vm/jit/powerpc/linux/md-abi.h"
39 #include "threads/thread.hpp"
41 #include "vm/signallocal.hpp"
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;
55 unsigned long* _gregs;
57 #if defined(__UCLIBC__)
58 _mc = &(_uc->uc_mcontext);
59 _gregs = _mc->regs->gpr;
61 _mc = _uc->uc_mcontext.uc_regs;
65 void* xpc = (void*) _gregs[PT_NIP];
68 trap_handle(TRAP_SIGSEGV, xpc, _p);
73 * Signal handler for patcher calls.
75 void md_signal_handler_sigill(int sig, siginfo_t* siginfo, void* _p)
77 ucontext_t* _uc = (ucontext_t*) _p;
79 unsigned long* _gregs;
81 #if defined(__UCLIBC__)
82 _mc = &(_uc->uc_mcontext);
83 _gregs = _mc->regs->gpr;
85 _mc = _uc->uc_mcontext.uc_regs;
89 void* xpc = (void*) _gregs[PT_NIP];
92 trap_handle(TRAP_SIGILL, xpc, _p);
97 * Signal handler for hardware-traps.
99 void md_signal_handler_sigtrap(int sig, siginfo_t *siginfo, void *_p)
101 ucontext_t* _uc = (ucontext_t*) _p;
103 unsigned long* _gregs;
105 #if defined(__UCLIBC__)
106 _mc = &(_uc->uc_mcontext);
107 _gregs = _mc->regs->gpr;
109 _mc = _uc->uc_mcontext.uc_regs;
113 void* xpc = (void*) _gregs[PT_NIP];
116 trap_handle(TRAP_SIGTRAP, xpc, _p);
120 /* md_signal_handler_sigusr2 ***************************************************
122 Signal handler for profiling sampling.
124 *******************************************************************************/
126 #if defined(ENABLE_THREADS)
127 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
132 unsigned long *_gregs;
137 _uc = (ucontext_t *) _p;
139 #if defined(__UCLIBC__)
140 _mc = &(_uc->uc_mcontext);
141 _gregs = _mc->regs->gpr;
143 _mc = _uc->uc_mcontext.uc_regs;
147 pc = (u1 *) _gregs[PT_NIP];
154 /* md_executionstate_read ******************************************************
156 Read the given context into an executionstate.
158 *******************************************************************************/
160 void md_executionstate_read(executionstate_t *es, void *context)
164 unsigned long *_gregs;
167 _uc = (ucontext_t *) context;
169 #if defined(__UCLIBC__)
170 #error Please port md_executionstate_read to __UCLIBC__
172 _mc = _uc->uc_mcontext.uc_regs;
176 /* read special registers */
177 es->pc = (u1 *) _gregs[PT_NIP];
178 es->sp = (u1 *) _gregs[REG_SP];
179 es->pv = (u1 *) _gregs[REG_PV];
180 es->ra = (u1 *) _gregs[PT_LNK];
182 /* read integer registers */
183 for (i = 0; i < INT_REG_CNT; i++)
184 es->intregs[i] = _gregs[i];
186 /* read float registers */
187 /* Do not use the assignment operator '=', as the type of
188 * the _mc->fpregs[i] can cause invalid conversions. */
190 assert(sizeof(_mc->fpregs.fpregs) == sizeof(es->fltregs));
191 os_memcpy(&es->fltregs, &_mc->fpregs.fpregs, sizeof(_mc->fpregs.fpregs));
195 /* md_executionstate_write *****************************************************
197 Write the given executionstate back to the context.
199 *******************************************************************************/
201 void md_executionstate_write(executionstate_t *es, void *context)
205 unsigned long *_gregs;
208 _uc = (ucontext_t *) context;
210 #if defined(__UCLIBC__)
211 #error Please port md_executionstate_write to __UCLIBC__
213 _mc = _uc->uc_mcontext.uc_regs;
217 /* write integer registers */
218 for (i = 0; i < INT_REG_CNT; i++)
219 _gregs[i] = es->intregs[i];
221 /* write float registers */
222 /* Do not use the assignment operator '=', as the type of
223 * the _mc->fpregs[i] can cause invalid conversions. */
225 assert(sizeof(_mc->fpregs.fpregs) == sizeof(es->fltregs));
226 os_memcpy(&_mc->fpregs.fpregs, &es->fltregs, sizeof(_mc->fpregs.fpregs));
228 /* write special registers */
229 _gregs[PT_NIP] = (ptrint) es->pc;
230 _gregs[REG_SP] = (ptrint) es->sp;
231 _gregs[REG_PV] = (ptrint) es->pv;
232 _gregs[PT_LNK] = (ptrint) es->ra;
237 * These are local overrides for various environment variables in Emacs.
238 * Please do not remove this and leave it at the end of the file, where
239 * Emacs will automagically detect them.
240 * ---------------------------------------------------------------------
243 * indent-tabs-mode: t