CACAO
md-os.cpp
Go to the documentation of this file.
1 /* src/vm/jit/powerpc64/linux/md-os.cpp - machine dependent PowerPC64 Linux functions
2 
3  Copyright (C) 1996-2013
4  CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5  Copyright (C) 2008 Theobroma Systems Ltd.
6 
7  This file is part of CACAO.
8 
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.
13 
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.
18 
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
22  02110-1301, USA.
23 
24 */
25 
26 
27 #include "config.h"
28 
29 #include <cassert>
30 #include <stdint.h>
31 #include <ucontext.h>
32 
33 #include "vm/types.hpp"
34 
36 #include "vm/jit/powerpc64/md.hpp"
38 
39 #include "threads/thread.hpp"
40 
41 #include "vm/signallocal.hpp"
42 
43 #include "vm/jit/asmpart.hpp"
45 #include "vm/jit/trap.hpp"
46 
47 
48 /**
49  * Signal handler for hardware-exceptions.
50  */
51 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
52 {
53  ucontext_t* _uc = (ucontext_t *) _p;
54  mcontext_t* _mc = &(_uc->uc_mcontext);
55 
56  void* xpc = (void*) _mc->gp_regs[PT_NIP];
57 
58  // Handle the trap.
59  trap_handle(TRAP_SIGSEGV, xpc, _p);
60 }
61 
62 
63 /**
64  * Signal handler for patcher calls.
65  */
66 void md_signal_handler_sigill(int sig, siginfo_t* siginfo, void* _p)
67 {
68  ucontext_t* _uc = (ucontext_t*) _p;
69  mcontext_t* _mc = &(_uc->uc_mcontext);
70 
71  void* xpc =(void*) _mc->gp_regs[PT_NIP];
72 
73  // Handle the trap.
74  trap_handle(TRAP_SIGILL, xpc, _p);
75 }
76 
77 
78 /* md_signal_handler_sigusr2 ***************************************************
79 
80  Signal handler for profiling sampling.
81 
82 *******************************************************************************/
83 
84 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
85 {
86  threadobject *tobj;
87  ucontext_t *_uc;
88  mcontext_t *_mc;
89  u1 *pc;
90 
91  tobj = THREADOBJECT;
92 
93  _uc = (ucontext_t *) _p;
94  _mc = &(_uc->uc_mcontext);
95 
96  pc = (u1 *) _mc->gp_regs[PT_NIP];
97 
98  tobj->pc = pc;
99 }
100 
101 
102 /* md_executionstate_read ******************************************************
103 
104  Read the given context into an executionstate.
105 
106 *******************************************************************************/
107 
108 void md_executionstate_read(executionstate_t *es, void *context)
109 {
110  ucontext_t *_uc;
111  mcontext_t *_mc;
112  s4 i;
113 
114  _uc = (ucontext_t *) context;
115  _mc = &(_uc->uc_mcontext);
116 
117  /* read special registers */
118  es->pc = (u1 *) _mc->gp_regs[PT_NIP];
119  es->sp = (u1 *) _mc->gp_regs[REG_SP];
120  es->pv = (u1 *) _mc->gp_regs[REG_PV];
121  es->ra = (u1 *) _mc->gp_regs[PT_LNK];
122 
123  /* read integer registers */
124  for (i = 0; i < INT_REG_CNT; i++)
125  es->intregs[i] = _mc->gp_regs[i];
126 
127  /* read float registers */
128  /* Do not use the assignment operator '=', as the type of
129  * the _mc->fpregs[i] can cause invalid conversions. */
130 
131  // The assertion below will fail because _mc->fp_regs[] also
132  // contains the "fpscr" register.
133  //assert(sizeof(_mc->fp_regs) == sizeof(es->fltregs));
134  os::memcpy(&es->fltregs, &_mc->fp_regs, sizeof(es->fltregs));
135 }
136 
137 
138 /* md_executionstate_write *****************************************************
139 
140  Write the given executionstate back to the context.
141 
142 *******************************************************************************/
143 
145 {
146  ucontext_t *_uc;
147  mcontext_t *_mc;
148  s4 i;
149 
150  _uc = (ucontext_t *) context;
151  _mc = &(_uc->uc_mcontext);
152 
153  /* write integer registers */
154  for (i = 0; i < INT_REG_CNT; i++)
155  _mc->gp_regs[i] = es->intregs[i];
156 
157  /* write float registers */
158  /* Do not use the assignment operator '=', as the type of
159  * the _mc->fpregs[i] can cause invalid conversions. */
160 
161  // The assertion below will fail because _mc->fp_regs[] also
162  // contains the "fpscr" register.
163  //assert(sizeof(_mc->fp_regs) == sizeof(es->fltregs));
164  os::memcpy(&_mc->fp_regs, &es->fltregs, sizeof(es->fltregs));
165 
166  /* write special registers */
167  _mc->gp_regs[PT_NIP] = (ptrint) es->pc;
168  _mc->gp_regs[REG_SP] = (ptrint) es->sp;
169  _mc->gp_regs[REG_PV] = (ptrint) es->pv;
170  _mc->gp_regs[PT_LNK] = (ptrint) es->ra;
171 }
172 
173 
174 /*
175  * These are local overrides for various environment variables in Emacs.
176  * Please do not remove this and leave it at the end of the file, where
177  * Emacs will automagically detect them.
178  * ---------------------------------------------------------------------
179  * Local variables:
180  * mode: c++
181  * indent-tabs-mode: t
182  * c-basic-offset: 4
183  * tab-width: 4
184  * End:
185  */
#define REG_SP
Definition: md-abi.hpp:53
#define REG_PV
Definition: md-abi.hpp:42
void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
NullPointerException signal handler for hardware null pointer check.
Definition: md-os.cpp:50
void md_signal_handler_sigill(int sig, siginfo_t *siginfo, void *_p)
Illegal Instruction signal handler for hardware exception checks.
Definition: md-os.cpp:65
struct sigcontext uc_mcontext
Definition: md-os.cpp:42
#define INT_REG_CNT
Definition: md-abi.hpp:72
uint8_t u1
Definition: types.hpp:40
#define xpc
Definition: md-asm.hpp:51
void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
Definition: md-os.cpp:83
MIIterator i
int32_t s4
Definition: types.hpp:45
static void * memcpy(void *dest, const void *src, size_t n)
Definition: os.hpp:492
void md_executionstate_write(executionstate_t *es, void *context)
Definition: md-os.cpp:147
CONTEXT mcontext_t
Definition: ucontext.h:27
#define pc
Definition: md-asm.hpp:56
void md_executionstate_read(executionstate_t *es, void *context)
Definition: md-os.cpp:107
void trap_handle(int sig, void *xpc, void *context)
Handles the signal which is generated by trap instructions, caught by a signal handler and calls the ...
Definition: trap.cpp:101
uintptr_t intregs[INT_REG_CNT]
uintptr_t ptrint
Definition: types.hpp:54
double fltregs[FLT_REG_CNT]
#define THREADOBJECT
Definition: thread-none.hpp:47