CACAO
md-os.cpp
Go to the documentation of this file.
1 /* src/vm/jit/sparc64/solaris/md-os.cpp - machine dependent SPARC 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 <cassert>
29 #include <stdint.h>
30 #include <ucontext.h>
31 
32 /* work around name clash */
33 #undef REG_SP
34 
35 #include "vm/types.hpp"
36 
39 
40 #include "vm/signallocal.hpp"
41 
42 #include "vm/jit/asmpart.hpp"
43 #include "vm/jit/stacktrace.hpp"
44 #include "vm/jit/trap.hpp"
45 
46 
48 {
49  ptrint val;
50  s8 *window;
51 
52 
53  /* return 0 for REG_ZERO */
54 
55  if (rindex == 0)
56  return 0;
57 
58 
59  if (rindex <= 15) {
60 
61  /* register is in global or out range, available in context */
62  val = _mc->gregs[rindex + 3];
63 
64  }
65  else {
66  assert(rindex <= 31);
67 
68  /* register is local or in, need to fetch from regsave area on stack */
69 
70  window = (s8 *) (_mc->gregs[REG_O6] + BIAS);
71  val = window[rindex - 16];
72 
73  }
74 
75  return val;
76 }
77 
78 
79 /* md_signal_handler_sigsegv ***************************************************
80 
81  NullPointerException signal handler for hardware null pointer
82  check.
83 
84 *******************************************************************************/
85 
86 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
87 {
88  ucontext_t *_uc;
89  mcontext_t *_mc;
90  ptrint addr;
91  u1 *pv;
92  u1 *sp;
93  u1 *ra;
94  u1 *xpc;
95  u4 mcode;
96  int d;
97  int s1;
98  int16_t disp;
99  intptr_t val;
100  int type;
101  void *p;
102 
103  _uc = (ucontext_t *) _p;
104  _mc = &_uc->uc_mcontext;
105 
107  sp = (u1 *) _mc->gregs[REG_O6];
109  xpc = (u1 *) _mc->gregs[REG_PC];
110 
111 
112  /* get exception-throwing instruction */
113 
114  mcode = *((u4 *) xpc);
115 
116  d = M_OP3_GET_RD(mcode);
117  s1 = M_OP3_GET_RS(mcode);
118  disp = M_OP3_GET_IMM(mcode);
119 
120  /* flush register windows? */
121 
122  val = md_get_reg_from_context(_mc, d);
123 
124  /* check for special-load */
125 
126  if (s1 == REG_ZERO) {
127  /* we use the exception type as load displacement */
128 
129  type = disp;
130  }
131  else {
132  /* This is a normal NPE: addr must be NULL and the NPE-type
133  define is 0. */
134 
135  addr = md_get_reg_from_context(_mc, s1);
136  type = (int) addr;
137  }
138 
139  /* Handle the trap. */
140 
141  p = trap_handle(type, val, pv, sp, ra, xpc, _p);
142 
143  /* Set registers. */
144 
145  _mc->gregs[REG_G2] = (uintptr_t) p; /* REG_ITMP2_XPTR */
146  _mc->gregs[REG_G3] = (uintptr_t) xpc; /* REG_ITMP3_XPC */
147  _mc->gregs[REG_PC] = (uintptr_t) asm_handle_exception;
148  _mc->gregs[REG_nPC] = (uintptr_t) asm_handle_exception + 4;
149 }
150 
151 
152 /* md_icacheflush **************************************************************
153 
154  Calls the system's function to flush the instruction cache.
155 
156 *******************************************************************************/
157 
158 void md_icacheflush(u1 *addr, s4 nbytes)
159 {
160  u1* end;
161 
162  end = addr + nbytes;
163 
164  /* zero the least significant 3 bits to align on a 64-bit boundary */
165  addr = (u1 *) (((ptrint) addr) & -8l);
166 
167  while (addr < end) {
168  __asm__ (
169  "flush %0"
170  :
171  : "r"(addr)
172  );
173  addr += 8;
174  }
175 }
176 
177 
178 
179 
180 /*
181  * These are local overrides for various environment variables in Emacs.
182  * Please do not remove this and leave it at the end of the file, where
183  * Emacs will automagically detect them.
184  * ---------------------------------------------------------------------
185  * Local variables:
186  * mode: c++
187  * indent-tabs-mode: t
188  * c-basic-offset: 4
189  * tab-width: 4
190  * End:
191  */
#define pv
Definition: md-asm.hpp:65
#define ra
Definition: md-asm.hpp:62
ptrint md_get_reg_from_context(sigcontext *ctx, u4 rindex)
Definition: md-os.cpp:46
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
#define BIAS
Definition: md-abi.hpp:107
#define REG_PC
Definition: md-abi.hpp:42
struct sigcontext uc_mcontext
Definition: md-os.cpp:42
uint8_t u1
Definition: types.hpp:40
int64_t s8
Definition: types.hpp:48
#define xpc
Definition: md-asm.hpp:51
#define REG_RA_CALLEE
Definition: md-abi.hpp:41
int32_t s4
Definition: types.hpp:45
#define M_OP3_GET_RS(x)
Definition: codegen.hpp:126
void asm_handle_exception(void)
uint32_t u4
Definition: types.hpp:46
CONTEXT mcontext_t
Definition: ucontext.h:27
#define sp
Definition: md-asm.hpp:81
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
int8_t s1
Definition: types.hpp:39
#define REG_ZERO
Definition: md-abi.hpp:54
#define M_OP3_GET_IMM(x)
Definition: codegen.hpp:127
#define REG_PV_CALLEE
Definition: md-abi.hpp:44
uintptr_t ptrint
Definition: types.hpp:54
static void md_icacheflush(void *addr, int nbytes)
Definition: md.hpp:151
#define M_OP3_GET_RD(x)
Definition: codegen.hpp:125