Line data Source code
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 :
34 : #include "vm/jit/codegen-common.hpp"
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 11461738 : inline static int32_t md_stacktrace_get_framesize(codeinfo* code)
46 : {
47 : // Check for the asm_vm_call_method special case.
48 11461738 : if (code == NULL)
49 60 : return 0;
50 :
51 : // On x86_64 we use 8-byte stackslots.
52 11461678 : 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 5389782 : 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 5389782 : ra = *((void **) (((uintptr_t) sp) + stackframesize));
71 :
72 5389782 : 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 2123007 : 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 2123007 : pv = methodtree_find(ra);
90 :
91 2123008 : 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 648398 : inline static void md_cacheflush(void* addr, int nbytes)
103 : {
104 : // Compiler optimization barrier (see PR97).
105 648398 : __asm__ __volatile__ ("" : : : "memory");
106 648398 : }
107 :
108 :
109 : /* md_icacheflush **************************************************************
110 :
111 : Calls the system's function to flush the instruction cache.
112 :
113 : *******************************************************************************/
114 :
115 84488 : inline static void md_icacheflush(void* addr, int nbytes)
116 : {
117 : // Compiler optimization barrier (see PR97).
118 84488 : __asm__ __volatile__ ("" : : : "memory");
119 84488 : }
120 :
121 :
122 : /* md_dcacheflush **************************************************************
123 :
124 : Calls the system's function to flush the data cache.
125 :
126 : *******************************************************************************/
127 :
128 55695 : inline static void md_dcacheflush(void* addr, int nbytes)
129 : {
130 : // Compiler optimization barrier (see PR97).
131 55695 : __asm__ __volatile__ ("" : : : "memory");
132 55695 : }
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 : */
|