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