CACAO
md.hpp
Go to the documentation of this file.
1 /* src/vm/jit/i386/md.hpp - machine dependent i386 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_I386_MD_HPP_
27 #define VM_JIT_I386_MD_HPP_ 1
28 
29 #include "config.h"
30 
31 #include <cassert>
32 #include <stdint.h>
33 
34 #include "vm/jit/code.hpp"
36 #include "vm/jit/methodtree.hpp"
37 
38 
39 /* inline functions ***********************************************************/
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  int32_t stackframesize;
48 
49  // Check for the asm_vm_call_method special case.
50  if (code == NULL)
51  return 0;
52 
53  // On i386 we use 8-byte stackslots.
54  stackframesize = code->stackframesize * 8;
55 
56  // If there is a stackframe present, we need to take the alignment
57  // compensation for the stored return address into account.
58  if (stackframesize != 0)
59  stackframesize += 4;
60 
61  return stackframesize;
62 }
63 
64 
65 /* md_stacktrace_get_returnaddress *********************************************
66 
67  Returns the return address of the current stackframe, specified by
68  the passed stack pointer and the stack frame size.
69 
70 *******************************************************************************/
71 
72 inline static void *md_stacktrace_get_returnaddress(void *sp, int32_t stackframesize)
73 {
74  void *ra;
75 
76  /* On i386 the return address is above the current stack frame. */
77 
78  ra = *((void **) (((uintptr_t) sp) + stackframesize));
79 
80  return ra;
81 }
82 
83 
84 /* md_codegen_get_pv_from_pc ***************************************************
85 
86  On this architecture just a wrapper function to
87  methodtree_find.
88 
89 *******************************************************************************/
90 
91 inline static void *md_codegen_get_pv_from_pc(void *ra)
92 {
93  void *pv;
94 
95  /* Get the start address of the function which contains this
96  address from the method table. */
97 
98  pv = methodtree_find(ra);
99 
100  return pv;
101 }
102 
103 
104 /* md_cacheflush ***************************************************************
105 
106  Calls the system's function to flush the instruction and data
107  cache.
108 
109 *******************************************************************************/
110 
111 inline static void md_cacheflush(void *addr, int nbytes)
112 {
113  // Compiler optimization barrier (see PR97).
114  __asm__ __volatile__ ("" : : : "memory");
115 }
116 
117 
118 /* md_icacheflush **************************************************************
119 
120  Calls the system's function to flush the instruction cache.
121 
122 *******************************************************************************/
123 
124 inline static void md_icacheflush(void *addr, int nbytes)
125 {
126  // Compiler optimization barrier (see PR97).
127  __asm__ __volatile__ ("" : : : "memory");
128 }
129 
130 
131 /* md_dcacheflush **************************************************************
132 
133  Calls the system's function to flush the data cache.
134 
135 *******************************************************************************/
136 
137 inline static void md_dcacheflush(void *addr, int nbytes)
138 {
139  // Compiler optimization barrier (see PR97).
140  __asm__ __volatile__ ("" : : : "memory");
141 }
142 
143 
144 /* md_get_cycle_count **********************************************************
145 
146  Get the current time-stamp counter from the CPU.
147 
148 *******************************************************************************/
149 
150 inline static uint64_t md_get_cycle_count()
151 {
152  uint64_t cycles;
153 
154  // Get current cycles count from the CPU.
155  __asm__ __volatile__ ("rdtsc" : "=A" (cycles));
156 
157  return cycles;
158 }
159 
160 #endif // VM_JIT_I386_MD_HPP_
161 
162 
163 /*
164  * These are local overrides for various environment variables in Emacs.
165  * Please do not remove this and leave it at the end of the file, where
166  * Emacs will automagically detect them.
167  * ---------------------------------------------------------------------
168  * Local variables:
169  * mode: c++
170  * indent-tabs-mode: t
171  * c-basic-offset: 4
172  * tab-width: 4
173  * End:
174  * vim:noexpandtab:sw=4:ts=4:
175  */
#define methodtree_find
Definition: md-asm.hpp:101
#define pv
Definition: md-asm.hpp:65
#define ra
Definition: md-asm.hpp:62
int32_t stackframesize
Definition: code.hpp:88
static void * md_stacktrace_get_returnaddress(void *sp, int32_t stackframesize)
Definition: md.hpp:72
static void * md_codegen_get_pv_from_pc(void *ra)
Definition: md.hpp:91
static void md_dcacheflush(void *addr, int nbytes)
Definition: md.hpp:137
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
#define sp
Definition: md-asm.hpp:81
static void md_icacheflush(void *addr, int nbytes)
Definition: md.hpp:151
static uint64_t md_get_cycle_count()
Definition: md.hpp:150
static void md_cacheflush(void *addr, int nbytes)
Definition: md.hpp:138