CACAO
md.hpp
Go to the documentation of this file.
1 /* src/vm/jit/powerpc/md.hpp - machine dependent PowerPC 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 #ifndef VM_JIT_POWERPC_MD_HPP_
27 #define VM_JIT_POWERPC_MD_HPP_ 1
28 
29 #include "config.h"
30 
31 #include <cassert>
32 #include <stdint.h>
33 
35 
36 #include "vm/global.hpp"
37 #include "vm/vm.hpp"
38 
39 #include "vm/jit/asmpart.hpp"
40 #include "vm/jit/code.hpp"
42 
43 
44 /**
45  * Returns the size (in bytes) of the current stackframe, specified by
46  * the passed codeinfo structure.
47  */
48 inline static int32_t md_stacktrace_get_framesize(codeinfo* code)
49 {
50  // Check for the asm_vm_call_method special case.
51  if (code == NULL)
52  return 0;
53 
54  // On PowerPC we use 8-byte stackslots.
55  return code->stackframesize * 8;
56 }
57 
58 
59 /* md_stacktrace_get_returnaddress *********************************************
60 
61  Returns the return address of the current stackframe, specified by
62  the passed stack pointer and the stack frame size.
63 
64 *******************************************************************************/
65 
66 inline static void *md_stacktrace_get_returnaddress(void *sp, int32_t stackframesize)
67 {
68  void *ra;
69 
70  /* Pn PowerPC the return address is located in the linkage
71  area. */
72 
73  ra = *((void **) (((uintptr_t) sp) + stackframesize + LA_LR_OFFSET));
74 
75  return ra;
76 }
77 
78 
79 /* md_codegen_get_pv_from_pc ***************************************************
80 
81  Machine code:
82 
83  7d6802a6 mflr r11
84  39abffe0 addi r13,r11,-32
85 
86  or
87 
88  7d6802a6 mflr r11
89  3dabffff addis r13,r11,-1
90  39ad68b0 addi r13,r13,26800
91 
92 *******************************************************************************/
93 
94 inline static void* md_codegen_get_pv_from_pc(void* ra)
95 {
96  int32_t offset;
97 
98  uint32_t* pc = (uint32_t*) ra;
99 
100  /* get first instruction word after jump */
101 
102  uint32_t mcode = pc[1];
103 
104  /* check if we have 2 instructions (addis, addi) */
105 
106  if ((mcode >> 16) == 0x3dab) {
107  /* get displacement of first instruction (addis) */
108 
109  offset = (int32_t) (mcode << 16);
110 
111  /* get displacement of second instruction (addi) */
112 
113  mcode = pc[2];
114 
115  /* check for addi instruction */
116 
117  assert((mcode >> 16) == 0x39ad);
118 
119  offset += (int16_t) (mcode & 0x0000ffff);
120  }
121  else {
122  /* check for addi instruction */
123 
124  assert((mcode >> 16) == 0x39ab);
125 
126  /* get offset of first instruction (addi) */
127 
128  offset = (int16_t) (mcode & 0x0000ffff);
129  }
130 
131  /* calculate PV via RA + offset */
132 
133  void* pv = (void*) (((uintptr_t) ra) + offset);
134 
135  return pv;
136 }
137 
138 
139 /* md_cacheflush ***************************************************************
140 
141  Calls the system's function to flush the instruction and data
142  cache.
143 
144 *******************************************************************************/
145 
146 inline static void md_cacheflush(void *addr, int nbytes)
147 {
148  asm_cacheflush(addr, nbytes);
149 }
150 
151 
152 /* md_icacheflush **************************************************************
153 
154  Calls the system's function to flush the instruction cache.
155 
156 *******************************************************************************/
157 
158 inline static void md_icacheflush(void *addr, int nbytes)
159 {
160  asm_cacheflush(addr, nbytes);
161 }
162 
163 
164 /* md_dcacheflush **************************************************************
165 
166  Calls the system's function to flush the data cache.
167 
168 *******************************************************************************/
169 
170 inline static void md_dcacheflush(void *addr, int nbytes)
171 {
172  asm_cacheflush(addr, nbytes);
173 }
174 
175 #endif // VM_JIT_POWERPC_MD_HPP_
176 
177 
178 /*
179  * These are local overrides for various environment variables in Emacs.
180  * Please do not remove this and leave it at the end of the file, where
181  * Emacs will automagically detect them.
182  * ---------------------------------------------------------------------
183  * Local variables:
184  * mode: c++
185  * indent-tabs-mode: t
186  * c-basic-offset: 4
187  * tab-width: 4
188  * End:
189  * vim:noexpandtab:sw=4:ts=4:
190  */
void asm_cacheflush(void *addr, int nbytes)
#define pv
Definition: md-asm.hpp:65
#define ra
Definition: md-asm.hpp:62
int32_t stackframesize
Definition: code.hpp:88
static int32_t md_stacktrace_get_framesize(codeinfo *code)
Returns the size (in bytes) of the current stackframe, specified by the passed codeinfo structure...
Definition: md.hpp:48
#define LA_LR_OFFSET
Definition: md-abi.hpp:97
static void md_dcacheflush(void *addr, int nbytes)
Definition: md.hpp:170
static void * md_codegen_get_pv_from_pc(void *ra)
Definition: md.hpp:94
#define sp
Definition: md-asm.hpp:81
#define pc
Definition: md-asm.hpp:56
static void * md_stacktrace_get_returnaddress(void *sp, int32_t stackframesize)
Definition: md.hpp:66
static void md_icacheflush(void *addr, int nbytes)
Definition: md.hpp:151
static void md_cacheflush(void *addr, int nbytes)
Definition: md.hpp:138