CACAO
md-os.cpp
Go to the documentation of this file.
1 /* src/vm/jit/arm/linux/md-os.cpp - machine dependent ARM Linux functions
2 
3  Copyright (C) 1996-2013
4  CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5  Copyright (C) 2008, 2009 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 <stdint.h>
30 #include "mm/memory.hpp"
31 
32 #define ucontext broken_glibc_ucontext
33 #define ucontext_t broken_glibc_ucontext_t
34 #include <ucontext.h>
35 #undef ucontext
36 #undef ucontext_t
37 
38 typedef struct ucontext {
39  unsigned long uc_flags;
40  struct ucontext *uc_link;
43  sigset_t uc_sigmask;
44 } ucontext_t;
45 
46 #define scontext_t struct sigcontext
47 
48 #include "vm/types.hpp"
49 
50 #include "vm/jit/arm/md.hpp"
51 #include "vm/jit/arm/md-abi.hpp"
52 
53 #include "threads/thread.hpp"
54 
55 #include "vm/signallocal.hpp"
56 
57 #include "vm/jit/asmpart.hpp"
59 #include "vm/jit/trap.hpp"
60 
61 
62 /**
63  * Signal handler for hardware exceptions.
64  */
65 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
66 {
67  ucontext_t* _uc = (ucontext_t*) _p;
68  scontext_t* _sc = &_uc->uc_mcontext;
69 
70  /* ATTENTION: glibc included messed up kernel headers we needed a
71  workaround for the ucontext structure. */
72 
73  void* xpc = (u1 *) _sc->arm_pc;
74 
75  // Handle the trap.
76  trap_handle(TRAP_SIGSEGV, xpc, _p);
77 }
78 
79 
80 /**
81  * Illegal instruction signal handler for hardware exception checks.
82  */
83 void md_signal_handler_sigill(int sig, siginfo_t *siginfo, void *_p)
84 {
85  ucontext_t* _uc = (ucontext_t*) _p;
86  scontext_t* _sc = &_uc->uc_mcontext;
87 
88  /* ATTENTION: glibc included messed up kernel headers we needed a
89  workaround for the ucontext structure. */
90 
91  void* xpc = (void*) _sc->arm_pc;
92 
93  // Handle the trap.
94  trap_handle(TRAP_SIGILL, xpc, _p);
95 }
96 
97 
98 /* md_signal_handler_sigusr2 ***************************************************
99 
100  Signal handler for profiling sampling.
101 
102 *******************************************************************************/
103 
104 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
105 {
107  ucontext_t *_uc;
108  scontext_t *_sc;
109  u1 *pc;
110 
111  thread = THREADOBJECT;
112 
113  _uc = (ucontext_t*) _p;
114  _sc = &_uc->uc_mcontext;
115 
116  pc = (u1 *) _sc->arm_pc;
117 
118  thread->pc = pc;
119 }
120 
121 
122 /**
123  * Read the given context into an executionstate.
124  *
125  * @param es execution state
126  * @param context machine context
127  */
128 void md_executionstate_read(executionstate_t *es, void *context)
129 {
130  ucontext_t *_uc;
131  scontext_t *_sc;
132  int i;
133 
134  _uc = (ucontext_t *) context;
135  _sc = &_uc->uc_mcontext;
136 
137  /* ATTENTION: glibc included messed up kernel headers we needed a
138  workaround for the ucontext structure. */
139 
140  /* read special registers */
141 
142  es->pc = (u1 *) _sc->arm_pc;
143  es->sp = (u1 *) _sc->arm_sp;
144  es->pv = (u1 *) _sc->arm_ip;
145  es->ra = (u1 *) _sc->arm_lr;
146 
147  /* read integer registers */
148 
149  for (i = 0; i < INT_REG_CNT; i++)
150  es->intregs[i] = *((int32_t*) _sc + OFFSET(scontext_t, arm_r0)/4 + i);
151 
152  /* read float registers */
153 
154  for (i = 0; i < FLT_REG_CNT; i++)
155  es->fltregs[i] = 0xdeadbeefdeadbeefULL;
156 }
157 
158 
159 /**
160  * Write the given executionstate back to the context.
161  *
162  * @param es execution state
163  * @param context machine context
164  */
166 {
167  ucontext_t *_uc;
168  scontext_t *_sc;
169  int i;
170 
171  _uc = (ucontext_t *) context;
172  _sc = &_uc->uc_mcontext;
173 
174  /* ATTENTION: glibc included messed up kernel headers we needed a
175  workaround for the ucontext structure. */
176 
177  /* write integer registers */
178 
179  for (i = 0; i < INT_REG_CNT; i++)
180  *((int32_t*) _sc + OFFSET(scontext_t, arm_r0)/4 + i) = es->intregs[i];
181 
182  /* write special registers */
183 
184  _sc->arm_pc = (ptrint) es->pc;
185  _sc->arm_sp = (ptrint) es->sp;
186  _sc->arm_ip = (ptrint) es->pv;
187  _sc->arm_lr = (ptrint) es->ra;
188 }
189 
190 
191 /*
192  * These are local overrides for various environment variables in Emacs.
193  * Please do not remove this and leave it at the end of the file, where
194  * Emacs will automagically detect them.
195  * ---------------------------------------------------------------------
196  * Local variables:
197  * mode: c++
198  * indent-tabs-mode: t
199  * c-basic-offset: 4
200  * tab-width: 4
201  * End:
202  */
203 
stack_t uc_stack
Definition: md-os.cpp:41
struct ucontext * uc_link
Definition: md-os.cpp:40
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
unsigned long uc_flags
Definition: md-os.cpp:39
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 ucontext_t
Definition: md-os.cpp:33
sigset_t uc_sigmask
Definition: md-os.cpp:43
#define xpc
Definition: md-asm.hpp:51
void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
Definition: md-os.cpp:83
struct sigcontext sigcontext
Definition: md-os.cpp:44
JNIEnv jthread thread
Definition: jvmti.h:207
MIIterator i
void md_executionstate_write(executionstate_t *es, void *context)
Definition: md-os.cpp:147
#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 OFFSET(s, el)
Definition: memory.hpp:90
#define THREADOBJECT
Definition: thread-none.hpp:47
#define FLT_REG_CNT
Definition: md-abi.hpp:79
#define scontext_t
Definition: md-os.cpp:46