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