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