1 /* src/vm/jit/powerpc/darwin/md-os.c - machine dependent PowerPC Darwin functions
3 Copyright (C) 1996-2005, 2006, 2007, 2008, 2009
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
35 #include "vm/jit/powerpc/codegen.h"
36 #include "vm/jit/powerpc/darwin/md-abi.h"
38 #include "threads/thread.hpp"
40 #include "vm/signallocal.hpp"
42 #include "vm/jit/trap.hpp"
54 * Signal handler for hardware-exceptions.
56 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
58 ucontext_t* _uc = (ucontext_t *) _p;
59 mcontext_t _mc = _uc->uc_mcontext;
60 ppc_thread_state_t* _ss = &(_mc->__ss);
62 void* xpc = (void*) _ss->__srr0;
65 trap_handle(TRAP_SIGSEGV, xpc, _p);
70 * Signal handler for hardware-traps.
72 void md_signal_handler_sigtrap(int sig, siginfo_t *siginfo, void *_p)
74 ucontext_t* _uc = (ucontext_t *) _p;
75 mcontext_t _mc = _uc->uc_mcontext;
76 ppc_thread_state_t* _ss = &(_mc->__ss);
78 void* xpc = (void*) _ss->__srr0;
81 trap_handle(TRAP_SIGTRAP, xpc, _p);
86 * Signal handler for hardware-patchers.
88 void md_signal_handler_sigill(int sig, siginfo_t *siginfo, void *_p)
90 ucontext_t* _uc = (ucontext_t *) _p;
91 mcontext_t _mc = _uc->uc_mcontext;
92 ppc_thread_state_t* _ss = &(_mc->__ss);
94 void* xpc = (void*) _ss->__srr0;
97 trap_handle(TRAP_SIGILL, xpc, _p);
101 /* md_signal_handler_sigusr2 ***************************************************
103 Signal handler for profiling sampling.
105 *******************************************************************************/
107 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
112 ppc_thread_state_t *_ss;
117 _uc = (ucontext_t *) _p;
118 _mc = _uc->uc_mcontext;
121 pc = (u1 *) _ss->__srr0;
127 /* md_executionstate_read ******************************************************
129 Read the given context into an executionstate.
131 *******************************************************************************/
133 void md_executionstate_read(executionstate_t *es, void *context)
135 ucontext_t* _uc = (ucontext_t *) context;
136 mcontext_t _mc = _uc->uc_mcontext;
137 ppc_thread_state_t* _ss = &(_mc->__ss);
139 /* read special registers */
140 es->pc = (uint8_t*) _ss->__srr0;
141 es->sp = (uint8_t*) _ss->__r1;
142 es->pv = (uint8_t*) _ss->__r13;
143 es->ra = (uint8_t*) _ss->__lr;
145 /* read integer registers */
146 unsigned int* regs = &(_ss->__r0);
147 for (int i = 0; i < INT_REG_CNT; i++)
148 es->intregs[i] = regs[i];
150 /* read float registers */
151 for (int i = 0; i < FLT_REG_CNT; i++)
152 es->fltregs[i] = 0xdeadbeefdeadbeefULL;
156 /* md_executionstate_write *****************************************************
158 Write the given executionstate back to the context.
160 *******************************************************************************/
162 void md_executionstate_write(executionstate_t *es, void *context)
164 ucontext_t* _uc = (ucontext_t *) context;
165 mcontext_t _mc = _uc->uc_mcontext;
166 ppc_thread_state_t* _ss = &(_mc->__ss);
168 /* write integer registers */
169 unsigned int* regs = &(_ss->__r0);
170 for (int i = 0; i < INT_REG_CNT; i++)
171 regs[i] = es->intregs[i];
173 /* write special registers */
174 _ss->__srr0 = (intptr_t) es->pc;
175 _ss->__r1 = (intptr_t) es->sp;
176 _ss->__r13 = (intptr_t) es->pv;
177 _ss->__lr = (intptr_t) es->ra;
182 * These are local overrides for various environment variables in Emacs.
183 * Please do not remove this and leave it at the end of the file, where
184 * Emacs will automagically detect them.
185 * ---------------------------------------------------------------------
188 * indent-tabs-mode: t