CACAO
md-os.cpp
Go to the documentation of this file.
1 /* src/vm/jit/aarch64/linux/md-os.cpp - machine dependent Aarch64 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 <cassert>
30 #include <stdint.h>
31 #include <ucontext.h>
32 
33 #include "vm/types.hpp"
34 
36 #include "vm/jit/aarch64/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  * NullPointerException signal handler for hardware null pointer check.
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->pc;
56 
57  // Handle the trap.
58  trap_handle(TRAP_SIGSEGV, xpc, _p);
59 }
60 
61 
62 /**
63  * Illegal Instruction signal handler for hardware exception checks.
64  */
65 void md_signal_handler_sigill(int sig, siginfo_t *siginfo, void *_p)
66 {
67  ucontext_t* _uc = (ucontext_t*) _p;
68  mcontext_t* _mc = &_uc->uc_mcontext;
69 
70  void* xpc = (void*) _mc->pc;
71 
72  // Handle the trap.
73  trap_handle(TRAP_SIGILL, xpc, _p);
74 }
75 
76 
77 /* md_signal_handler_sigusr2 ***************************************************
78 
79  Signal handler for profiling sampling.
80 
81 *******************************************************************************/
82 
83 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
84 {
85  threadobject *tobj;
86  ucontext_t *_uc;
87  mcontext_t *_mc;
88  u1 *pc;
89 
90  tobj = THREADOBJECT;
91 
92  _uc = (ucontext_t *) _p;
93  _mc = &_uc->uc_mcontext;
94 
95  pc = (u1 *) _mc->pc;
96 
97  tobj->pc = pc;
98 }
99 
100 
101 /* md_executionstate_read ******************************************************
102 
103  Read the given context into an executionstate.
104 
105 *******************************************************************************/
106 
107 void md_executionstate_read(executionstate_t *es, void *context)
108 {
109  ucontext_t *_uc;
110  mcontext_t *_mc;
111  int i;
112 
113  _uc = (ucontext_t *) context;
114  _mc = &_uc->uc_mcontext;
115 
116  /* read special registers */
117  es->pc = (u1 *) _mc->pc;
118  es->sp = (u1 *) _mc->regs[REG_SP];
119  es->pv = (u1 *) _mc->regs[REG_PV];
120  es->ra = (u1 *) _mc->regs[REG_LR];
121 
122  /* read integer registers */
123  for (i = 0; i < INT_REG_CNT; i++)
124  es->intregs[i] = _mc->regs[i];
125 
126  /* read float registers */
127  /* Do not use the assignment operator '=', as the type of
128  * the _mc->sc_fpregs[i] can cause invalid conversions. */
129 
130  /* float registers are in an extension section of the sigcontext (mcontext_t) */
131  struct fpsimd_context *_fc = (struct fpsimd_context *) &(_mc->__reserved);
132 
133  /* check if we found the correct extension */
134  if (_fc->head.magic == FPSIMD_MAGIC) {
135  assert(sizeof(_fc->vregs) == sizeof(es->fltregs));
136  os::memcpy(&es->fltregs, &_fc->vregs, sizeof(_fc->vregs));
137  }
138 }
139 
140 
141 /* md_executionstate_write *****************************************************
142 
143  Write the given executionstate back to the context.
144 
145 *******************************************************************************/
146 
148 {
149  ucontext_t *_uc;
150  mcontext_t *_mc;
151  int i;
152 
153  _uc = (ucontext_t *) context;
154  _mc = &_uc->uc_mcontext;
155 
156  /* write integer registers */
157  for (i = 0; i < INT_REG_CNT; i++)
158  _mc->regs[i] = es->intregs[i];
159 
160  /* write float registers */
161  /* Do not use the assignment operator '=', as the type of
162  * the _mc->sc_fpregs[i] can cause invalid conversions. */
163 
164  /* float registers are in an extension section of the sigcontext (mcontext_t) */
165  struct fpsimd_context *_fc = (struct fpsimd_context *) &(_mc->__reserved);
166 
167  /* check if we found the correct extension */
168  if (_fc->head.magic == FPSIMD_MAGIC) {
169  assert(sizeof(_fc->vregs) == sizeof(es->fltregs));
170  os::memcpy(&_fc->vregs, &es->fltregs, sizeof(_fc->vregs));
171  }
172 
173  /* write special registers */
174  _mc->pc = (ptrint) es->pc;
175  _mc->regs[REG_SP] = (ptrint) es->sp;
176  _mc->regs[REG_PV] = (ptrint) es->pv;
177  _mc->regs[REG_LR] = (ptrint) es->ra;
178 }
179 
180 
181 /*
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  * ---------------------------------------------------------------------
186  * Local variables:
187  * mode: c++
188  * indent-tabs-mode: t
189  * c-basic-offset: 4
190  * tab-width: 4
191  * End:
192  */
#define REG_SP
Definition: md-abi.hpp:53
#define REG_LR
Definition: md-abi.hpp:40
#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
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