CACAO
md.hpp
Go to the documentation of this file.
1 /* src/vm/jit/powerpc64/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_POWERPC64_MD_HPP_
27 #define VM_JIT_POWERPC64_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"
41 #include "vm/jit/jit.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 PowerPC64 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  /* On PowerPC64 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  39cbffe0 addi r14,r11,-32
85 
86  or
87 
88  7d6802a6 mflr r11
89  3dcbffff addis r14,r11,-1
90  39ce68b0 addi r14,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) == 0x3dcb) {
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) == 0x39ce);
118 
119  offset += (int16_t) (mcode & 0x0000ffff);
120  }
121  else if ((mcode >> 16) == 0x39cb) {
122  /* get offset of first instruction (addi) */
123 
124  offset = (int16_t) (mcode & 0x0000ffff);
125  }
126  else {
127  vm_abort("md_codegen_get_pv_from_pc: unknown instruction %x", mcode);
128 
129  /* keep compiler happy */
130 
131  offset = 0;
132  }
133 
134  /* calculate PV via RA + offset */
135 
136  void* pv = (void*) (((uintptr_t) ra) + offset);
137 
138  return pv;
139 }
140 
141 
142 /* md_cacheflush ***************************************************************
143 
144  Calls the system's function to flush the instruction and data
145  cache.
146 
147 *******************************************************************************/
148 
149 inline static void md_cacheflush(void *addr, int nbytes)
150 {
151  asm_cacheflush(addr, nbytes);
152 }
153 
154 
155 /* md_icacheflush **************************************************************
156 
157  Calls the system's function to flush the instruction cache.
158 
159 *******************************************************************************/
160 
161 inline static void md_icacheflush(void *addr, int nbytes)
162 {
163  asm_cacheflush(addr, nbytes);
164 }
165 
166 
167 /* md_dcacheflush **************************************************************
168 
169  Calls the system's function to flush the data cache.
170 
171 *******************************************************************************/
172 
173 inline static void md_dcacheflush(void *addr, int nbytes)
174 {
175  asm_cacheflush(addr, nbytes);
176 }
177 
178 #endif // VM_JIT_POWERPC64_MD_HPP_
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  * vim:noexpandtab:sw=4:ts=4:
193  */
void asm_cacheflush(void *addr, int nbytes)
#define pv
Definition: md-asm.hpp:65
#define ra
Definition: md-asm.hpp:62
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
int32_t stackframesize
Definition: code.hpp:88
static void * md_stacktrace_get_returnaddress(void *sp, int32_t stackframesize)
Definition: md.hpp:66
#define LA_LR_OFFSET
Definition: md-abi.hpp:97
void vm_abort(const char *text,...)
Definition: vm.cpp:2586
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_dcacheflush(void *addr, int nbytes)
Definition: md.hpp:173
static void md_icacheflush(void *addr, int nbytes)
Definition: md.hpp:151
static void md_cacheflush(void *addr, int nbytes)
Definition: md.hpp:138