Merge from subtype.
[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
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 /* md_stacktrace_get_returnaddress *********************************************
41
42    Returns the return address of the current stackframe, specified by
43    the passed stack pointer and the stack frame size.
44
45 *******************************************************************************/
46
47 inline static void *md_stacktrace_get_returnaddress(void *sp, int32_t stackframesize)
48 {
49         void *ra;
50
51         /* On x86_64 the return address is above the current stack
52            frame. */
53
54         ra = *((void **) (((uintptr_t) sp) + stackframesize));
55
56         return ra;
57 }
58
59
60 /* md_codegen_get_pv_from_pc ***************************************************
61
62    On this architecture this is just a wrapper to methodtree_find.
63
64 *******************************************************************************/
65
66 inline static void *md_codegen_get_pv_from_pc(void *ra)
67 {
68         void *pv;
69
70         /* Get the start address of the function which contains this
71        address from the method tree. */
72
73         pv = methodtree_find(ra);
74
75         return pv;
76 }
77
78
79 /* md_cacheflush ***************************************************************
80
81    Calls the system's function to flush the instruction and data
82    cache.
83
84 *******************************************************************************/
85
86 inline static void md_cacheflush(void* addr, int nbytes)
87 {
88         // Compiler optimization barrier (see PR97).
89         __asm__ __volatile__ ("" : : : "memory");
90 }
91
92
93 /* md_icacheflush **************************************************************
94
95    Calls the system's function to flush the instruction cache.
96
97 *******************************************************************************/
98
99 inline static void md_icacheflush(void* addr, int nbytes)
100 {
101         // Compiler optimization barrier (see PR97).
102         __asm__ __volatile__ ("" : : : "memory");
103 }
104
105
106 /* md_dcacheflush **************************************************************
107
108    Calls the system's function to flush the data cache.
109
110 *******************************************************************************/
111
112 inline static void md_dcacheflush(void* addr, int nbytes)
113 {
114         // Compiler optimization barrier (see PR97).
115         __asm__ __volatile__ ("" : : : "memory");
116 }
117
118 #endif /* _VM_JIT_X86_64_MD_H */
119
120
121 /*
122  * These are local overrides for various environment variables in Emacs.
123  * Please do not remove this and leave it at the end of the file, where
124  * Emacs will automagically detect them.
125  * ---------------------------------------------------------------------
126  * Local variables:
127  * mode: c
128  * indent-tabs-mode: t
129  * c-basic-offset: 4
130  * tab-width: 4
131  * End:
132  * vim:noexpandtab:sw=4:ts=4:
133  */