merged volatile memory barriers
[cacao.git] / src / vm / jit / patcher-common.hpp
1 /* src/vm/jit/patcher-common.hpp - architecture independent code patching stuff
2
3    Copyright (C) 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 _PATCHER_COMMON_HPP
27 #define _PATCHER_COMMON_HPP
28
29 /* forward typedefs ***********************************************************/
30
31 typedef struct patchref_t patchref_t;
32
33 #include "config.h"
34 #include "vm/types.h"
35
36 #include "toolbox/list.hpp"
37
38 #include "vm/global.h"
39
40 #include "vm/jit/jit.hpp"
41
42
43 /* patchref_t ******************************************************************
44
45    A patcher reference contains information about a code position
46    which needs additional code patching during runtime.
47
48 *******************************************************************************/
49
50 struct patchref_t {
51         uintptr_t    mpc;           /* absolute position in code segment          */
52         uintptr_t    datap;         /* absolute position in data segment          */
53         int32_t      disp;          /* displacement of ref in the data segment    */
54         int32_t      disp_mb;       /* auxiliary code displacement (for membar)   */
55         functionptr  patcher;       /* patcher function to call                   */
56         void*        ref;           /* reference passed                           */
57         uint32_t     mcode;         /* machine code to be patched back in         */
58         bool         done;          /* XXX preliminary: patch already applied?    */
59 };
60
61
62 /* macros *********************************************************************/
63
64
65 /* function prototypes ********************************************************/
66
67 #ifdef __cplusplus
68 extern "C" {
69 #endif
70
71 void patcher_list_create(codeinfo *code);
72 void patcher_list_reset(codeinfo *code);
73 void patcher_list_free(codeinfo *code);
74
75 #if !defined(NDEBUG)
76 void patcher_list_show(codeinfo *code);
77 #endif
78
79 patchref_t *patcher_add_patch_ref(jitdata *jd, functionptr patcher, void* ref, s4 disp);
80
81 void patcher_resolve(jitdata* jd);
82
83 bool patcher_is_patched(patchref_t* pr);
84 bool patcher_is_patched_at(void* pc);
85
86 // MD function.
87 bool patcher_is_valid_trap_instruction_at(void* pc);
88
89 bool patcher_handler(u1 *pc);
90
91
92 /* empty patcher (just patches back original mcode) ***************************/
93
94 void patcher_patch_code(patchref_t *pr);
95
96
97 /* patcher prototypes and macros **********************************************/
98
99 /* new patcher functions */
100
101 bool patcher_resolve_class(patchref_t *pr);
102 #define PATCHER_resolve_class (functionptr) patcher_resolve_class
103
104 bool patcher_initialize_class(patchref_t *pr);
105 #define PATCHER_initialize_class (functionptr) patcher_initialize_class
106
107 bool patcher_resolve_classref_to_classinfo(patchref_t *pr);
108 #define PATCHER_resolve_classref_to_classinfo (functionptr) patcher_resolve_classref_to_classinfo
109
110 bool patcher_resolve_classref_to_vftbl(patchref_t *pr);
111 #define PATCHER_resolve_classref_to_vftbl (functionptr) patcher_resolve_classref_to_vftbl
112
113 bool patcher_resolve_classref_to_index(patchref_t *pr);
114 #define PATCHER_resolve_classref_to_index (functionptr) patcher_resolve_classref_to_index
115
116 bool patcher_resolve_classref_to_flags(patchref_t *pr);
117 #define PATCHER_resolve_classref_to_flags (functionptr) patcher_resolve_classref_to_flags
118
119 bool patcher_resolve_native_function(patchref_t *pr);
120 #define PATCHER_resolve_native_function (functionptr) patcher_resolve_native_function
121
122 bool patcher_breakpoint(patchref_t *pr);
123 #define PATCHER_breakpoint (functionptr) patcher_breakpoint
124
125 /* old patcher functions */
126
127 bool patcher_get_putstatic(patchref_t *pr);
128 #define PATCHER_get_putstatic (functionptr) patcher_get_putstatic
129
130 #if defined(__I386__)
131
132 bool patcher_getfield(patchref_t *pr);
133 #define PATCHER_getfield (functionptr) patcher_getfield
134
135 bool patcher_putfield(patchref_t *pr);
136 #define PATCHER_putfield (functionptr) patcher_putfield
137
138 #else
139
140 bool patcher_get_putfield(patchref_t *pr);
141 #define PATCHER_get_putfield (functionptr) patcher_get_putfield
142
143 #endif /* defined(__I386__) */
144
145 #if defined(__I386__) || defined(__X86_64__)
146
147 bool patcher_putfieldconst(patchref_t *pr);
148 #define PATCHER_putfieldconst (functionptr) patcher_putfieldconst
149
150 #endif /* defined(__I386__) || defined(__X86_64__) */
151
152 bool patcher_invokestatic_special(patchref_t *pr);
153 #define PATCHER_invokestatic_special (functionptr) patcher_invokestatic_special
154
155 bool patcher_invokevirtual(patchref_t *pr);
156 #define PATCHER_invokevirtual (functionptr) patcher_invokevirtual
157
158 bool patcher_invokeinterface(patchref_t *pr);
159 #define PATCHER_invokeinterface (functionptr) patcher_invokeinterface
160
161 #if defined(__ALPHA__) || defined(__I386__) || defined(__MIPS__) || defined(__POWERPC__) || defined(__POWERPC64__) || defined(__S390__) || defined(__X86_64__) || defined(__M68K__)
162
163 bool patcher_checkcast_interface(patchref_t *pr);
164 #define PATCHER_checkcast_interface (functionptr) patcher_checkcast_interface
165
166 bool patcher_instanceof_interface(patchref_t *pr);
167 #define PATCHER_instanceof_interface (functionptr) patcher_instanceof_interface
168
169 #endif /* defined(__ALPHA__) || defined(__I386__) || defined(__MIPS__) || defined(__POWERPC__) || defined(__POWERPC64__) || defined(__S390__) || defined(__X86_64__) || defined(__M68K__) */
170
171 #if defined(__S390__)
172
173 bool patcher_checkcast_instanceof_interface(patchref_t *pr);
174 #define PATCHER_checkcast_instanceof_interface (functionptr) patcher_checkcast_instanceof_interface
175
176 #endif /* defined(__S390__) */
177
178 #if defined(__I386__)
179
180 bool patcher_aconst(patchref_t *pr);
181 #define PATCHER_aconst (functionptr) patcher_aconst
182
183 bool patcher_builtin_multianewarray(patchref_t *pr);
184 #define PATCHER_builtin_multianewarray (functionptr) patcher_builtin_multianewarray
185
186 bool patcher_builtin_arraycheckcast(patchref_t *pr);
187 #define PATCHER_builtin_arraycheckcast (functionptr) patcher_builtin_arraycheckcast
188
189 bool patcher_checkcast_instanceof_flags(patchref_t *pr);
190 #define PATCHER_checkcast_instanceof_flags (functionptr) patcher_checkcast_instanceof_flags
191
192 bool patcher_checkcast_class(patchref_t *pr);
193 #define PATCHER_checkcast_class (functionptr) patcher_checkcast_class
194
195 bool patcher_instanceof_class(patchref_t *pr);
196 #define PATCHER_instanceof_class (functionptr) patcher_instanceof_class
197
198 #endif /* defined(__I386__) */
199
200 #ifdef __cplusplus
201 } // extern "C"
202 #endif
203
204 #endif // _PATCHER_COMMON_HPP
205
206
207 /*
208  * These are local overrides for various environment variables in Emacs.
209  * Please do not remove this and leave it at the end of the file, where
210  * Emacs will automagically detect them.
211  * ---------------------------------------------------------------------
212  * Local variables:
213  * mode: c++
214  * indent-tabs-mode: t
215  * c-basic-offset: 4
216  * tab-width: 4
217  * End:
218  * vim:noexpandtab:sw=4:ts=4:
219  */