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