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