CACAO
md.hpp
Go to the documentation of this file.
1 /* src/vm/jit/arm/md.hpp - machine dependent Arm 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_ARM_MD_HPP_
27 #define VM_JIT_ARM_MD_HPP_
28 
29 #include "config.h"
30 
31 #include <cassert>
32 #include <stdint.h>
33 
34 #include "vm/types.hpp"
35 
36 #include "vm/jit/asmpart.hpp"
37 #include "vm/jit/code.hpp"
39 
40 
41 /**
42  * Returns the size (in bytes) of the current stackframe, specified by
43  * the passed codeinfo structure.
44  */
45 inline static int32_t md_stacktrace_get_framesize(codeinfo* code)
46 {
47  // Check for the asm_vm_call_method special case.
48  if (code == NULL)
49  return 0;
50 
51  // On ARM we use 8-byte stackslots.
52  return code->stackframesize * 8;
53 }
54 
55 
56 /* md_stacktrace_get_returnaddress *********************************************
57 
58  Returns the return address of the current stackframe, specified by
59  the passed stack pointer and the stack frame size.
60 
61 *******************************************************************************/
62 
63 inline static void *md_stacktrace_get_returnaddress(void *sp, int32_t stackframesize)
64 {
65  void *ra;
66 
67  /* On ARM the return address is located on the top of the
68  stackframe. */
69  /* ATTENTION: This is only true for non-leaf methods!!! */
70 
71  ra = *((void **) (((uintptr_t) sp) + stackframesize - SIZEOF_VOID_P));
72 
73  return ra;
74 }
75 
76 
77 /* md_codegen_get_pv_from_pc ***************************************************
78 
79  TODO: document me
80 
81 *******************************************************************************/
82 
83 inline static void* md_codegen_get_pv_from_pc(void* ra)
84 {
85  uint32_t* pc;
86  uintptr_t pv;
87  uint32_t mcode;
88  int mcode_idx;
89 
90  pc = (uint32_t*) ra;
91  pv = (uintptr_t) ra;
92 
93  /* this can either be a RECOMPUTE_IP in JIT code or a fake in asm_calljavafunction */
94  mcode_idx = 0;
95  mcode = pc[0];
96 
97  /* if this was shifted by 18 bits, we have to load additional instructions */
98  if ((mcode & 0xfff0ff00) == 0xe240c700 /*sub ip,??,#__*/) {
99  pv -= (uintptr_t) ((mcode & 0x000000ff) << 18);
100  mcode = pc[++mcode_idx];
101  }
102 
103  /* if this was shifted by 10 bits, we have to load additional instructions */
104  if ((mcode & 0xfff0ff00) == 0xe240cb00 /*sub ip,??,#__*/) {
105  pv -= (uintptr_t) ((mcode & 0x000000ff) << 10);
106  mcode = pc[++mcode_idx];
107  }
108 
109  /* this is the default path with just one instruction, shifted by 2 or no bits */
110  if ((mcode & 0xfff0ff00) == 0xe240cf00 /*sub ip,??,#__*/)
111  pv -= (uintptr_t) ((mcode & 0x000000ff) << 2);
112  else if ((mcode & 0xffffff00) == 0xe24fc000 /*sub ip,pc,#__*/)
113  pv -= (uintptr_t) (mcode & 0x000000ff);
114  else {
115  /* if this happens, we got an unexpected instruction at (*ra) */
116  vm_abort("Unable to find method: %p (instr=%x)", ra, mcode);
117  }
118 
119  /* we used PC-relative adressing; but now it is LR-relative */
120  pv += 8;
121 
122  /* if we found our method the data segment has to be valid */
123  /* we check this by looking up the IsLeaf field, which has to be boolean */
124 /* assert( *((s4*)pv-8) == (s4)true || *((s4*)pv-8) == (s4)false ); */
125 
126  return (void*) pv;
127 }
128 
129 
130 /* md_cacheflush ***************************************************************
131 
132  Calls the system's function to flush the instruction and data
133  cache.
134 
135 *******************************************************************************/
136 
137 inline static void md_cacheflush(void *addr, int nbytes)
138 {
139  asm_cacheflush(addr, nbytes);
140 }
141 
142 
143 /* md_icacheflush **************************************************************
144 
145  Calls the system's function to flush the instruction cache.
146 
147 *******************************************************************************/
148 
149 inline static void md_icacheflush(void *addr, int nbytes)
150 {
151  asm_cacheflush(addr, nbytes);
152 }
153 
154 
155 /* md_dcacheflush **************************************************************
156 
157  Calls the system's function to flush the data cache.
158 
159 *******************************************************************************/
160 
161 inline static void md_dcacheflush(void *addr, int nbytes)
162 {
163  // Compiler optimization barrier (see PR97).
164  __asm__ __volatile__ ("" : : : "memory");
165 }
166 
167 #endif // VM_JIT_ARM_MD_HPP_
168 
169 
170 /*
171  * These are local overrides for various environment variables in Emacs.
172  * Please do not remove this and leave it at the end of the file, where
173  * Emacs will automagically detect them.
174  * ---------------------------------------------------------------------
175  * Local variables:
176  * mode: c++
177  * indent-tabs-mode: t
178  * c-basic-offset: 4
179  * tab-width: 4
180  * End:
181  * vim:noexpandtab:sw=4:ts=4:
182  */
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 void * md_codegen_get_pv_from_pc(void *ra)
Definition: md.hpp:83
static void md_dcacheflush(void *addr, int nbytes)
Definition: md.hpp:161
void vm_abort(const char *text,...)
Definition: vm.cpp:2586
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:45
static void * md_stacktrace_get_returnaddress(void *sp, int32_t stackframesize)
Definition: md.hpp:63
#define sp
Definition: md-asm.hpp:81
#define pc
Definition: md-asm.hpp:56
static void md_icacheflush(void *addr, int nbytes)
Definition: md.hpp:151
static void md_cacheflush(void *addr, int nbytes)
Definition: md.hpp:138