CACAO
md-os.cpp
Go to the documentation of this file.
1 /* src/vm/jit/i386/solaris/md-os.cpp - machine dependent i386 Solaris functions
2 
3  Copyright (C) 1996-2013
4  CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 
6  This file is part of CACAO.
7 
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.
12 
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.
17 
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
21  02110-1301, USA.
22 
23 */
24 
25 
26 #include "config.h"
27 
28 #include <stdint.h>
29 #include <ucontext.h>
30 
31 #include "vm/types.hpp"
32 #include "vm/os.hpp"
33 
34 #define SKIP_REG_DEFS 1
35 
36 #include "vm/jit/i386/codegen.hpp"
37 #include "vm/jit/i386/md.hpp"
38 
39 #include "threads/thread.hpp"
40 
41 #include "vm/signallocal.hpp"
42 
44 #include "vm/jit/trap.hpp"
45 
46 
47 /**
48  * Signal handler for hardware exceptions.
49  */
50 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
51 {
52  ucontext_t *_uc = (ucontext_t *) _p;
53  mcontext_t *_mc = &_uc->uc_mcontext;
54 
55  void* xpc = (void*) _mc->gregs[EIP];
56 
57  // Handle the trap.
58  trap_handle(TRAP_SIGSEGV, xpc, _p);
59 }
60 
61 
62 /**
63  * Signal handler for hardware divide by zero (ArithmeticException)
64  * check.
65  */
66 void md_signal_handler_sigfpe(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->gregs[EIP];
72 
73  // Handle the trap.
74  trap_handle(TRAP_SIGFPE, xpc, _p);
75 }
76 
77 
78 /**
79  * Signal handler for hardware patcher traps (ud2).
80  */
81 void md_signal_handler_sigill(int sig, siginfo_t *siginfo, void *_p)
82 {
83  ucontext_t *_uc = (ucontext_t *) _p;
84  mcontext_t *_mc = &_uc->uc_mcontext;
85 
86  void* xpc = (void*) _mc->gregs[EIP];
87 
88  // Handle the trap.
89  trap_handle(TRAP_SIGILL, xpc, _p);
90 }
91 
92 
93 /* md_signal_handler_sigusr2 ***************************************************
94 
95  Signal handler for profiling sampling.
96 
97 *******************************************************************************/
98 
99 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
100 {
101  threadobject *t;
102  ucontext_t *_uc;
103  mcontext_t *_mc;
104  u1 *pc;
105 
106  t = THREADOBJECT;
107 
108  _uc = (ucontext_t *) _p;
109  _mc = &_uc->uc_mcontext;
110 
111  pc = (u1 *) _mc->gregs[EIP];
112 
113  t->pc = pc;
114 }
115 
116 
117 /* md_executionstate_read ******************************************************
118 
119  Read the given context into an executionstate for Replacement.
120 
121 *******************************************************************************/
122 
123 void md_executionstate_read(executionstate_t *es, void *context)
124 {
125  ucontext_t *_uc;
126  mcontext_t *_mc;
127  s4 i;
128 
129  _uc = (ucontext_t *) context;
130  _mc = &_uc->uc_mcontext;
131 
132  /* read special registers */
133  es->pc = (u1 *) _mc->gregs[EIP];
134  es->sp = (u1 *) _mc->gregs[UESP];
135  es->pv = NULL; /* pv must be looked up via AVL tree */
136 
137  /* read integer registers */
138  for (i = 0; i < INT_REG_CNT; i++)
139  es->intregs[i] = _mc->gregs[EAX - i];
140 
141  /* read float registers */
142  for (i = 0; i < FLT_REG_CNT; i++)
143  es->fltregs[i] = 0xdeadbeefdeadbeefULL;
144 }
145 
146 
147 /* md_executionstate_write *****************************************************
148 
149  Write the given executionstate back to the context for Replacement.
150 
151 *******************************************************************************/
152 
154 {
155  ucontext_t *_uc;
156  mcontext_t *_mc;
157  s4 i;
158 
159  _uc = (ucontext_t *) context;
160  _mc = &_uc->uc_mcontext;
161 
162  /* write integer registers */
163  for (i = 0; i < INT_REG_CNT; i++)
164  _mc->gregs[EAX - i] = es->intregs[i];
165 
166  /* write special registers */
167  _mc->gregs[EIP] = (ptrint) es->pc;
168  _mc->gregs[UESP] = (ptrint) es->sp;
169 }
170 
171 
172 /*
173  * These are local overrides for various environment variables in Emacs.
174  * Please do not remove this and leave it at the end of the file, where
175  * Emacs will automagically detect them.
176  * ---------------------------------------------------------------------
177  * Local variables:
178  * mode: c++
179  * indent-tabs-mode: t
180  * c-basic-offset: 4
181  * tab-width: 4
182  * End:
183  */
#define EAX
Definition: arch.hpp:51
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
void md_signal_handler_sigfpe(int sig, siginfo_t *siginfo, void *_p)
Definition: md-os.cpp:59
#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
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
#define FLT_REG_CNT
Definition: md-abi.hpp:79