* Removed all Id tags.
[cacao.git] / src / vm / jit / patcher-common.h
1 /* src/vm/jit/patcher-common.h - architecture independent code patching stuff
2
3    Copyright (C) 2007 R. Grafl, A. Krall, C. Kruegel,
4    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6    J. Wenninger, Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25 */
26
27
28 #ifndef _PATCHER_COMMON_H
29 #define _PATCHER_COMMON_H
30
31 /* forward typedefs ***********************************************************/
32
33 #include "config.h"
34 #include "vm/types.h"
35
36 #include "toolbox/list.h"
37
38 #include "vm/global.h"
39
40 #include "vm/jit/jit.h"
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 typedef struct patchref_t {
51         ptrint       mpc;           /* absolute position in code segment          */
52         ptrint       datap;         /* absolute position in data segment          */
53         s4           disp;          /* displacement of ref in the data segment    */
54         functionptr  patcher;       /* patcher function to call                   */
55         voidptr      ref;           /* reference passed                           */
56         u8           mcode;         /* machine code to be patched back in         */
57         bool         done;          /* XXX preliminary: patch already applied?    */
58         listnode_t   linkage;
59 } patchref_t;
60
61
62 /* macros *********************************************************************/
63
64
65 /* function prototypes ********************************************************/
66
67 void patcher_list_create(codeinfo *code);
68 void patcher_list_reset(codeinfo *code);
69 void patcher_list_free(codeinfo *code);
70
71 void patcher_add_patch_ref(jitdata *jd, functionptr patcher, voidptr ref,
72                            s4 disp);
73
74 java_handle_t *patcher_handler(u1 *pc);
75
76
77 /* patcher prototypes and macros **********************************************/
78
79 #if defined(__ALPHA__) || defined(__ARM__) || defined(__MIPS__) || defined(__POWERPC__) || defined (__S390__)
80
81 /* new patcher functions */
82
83 bool patcher_resolve_class(patchref_t *pr);
84 #define PATCHER_resolve_class (functionptr) patcher_resolve_class
85
86 bool patcher_initialize_class(patchref_t *pr);
87 #define PATCHER_initialize_class (functionptr) patcher_initialize_class
88
89 bool patcher_resolve_classref_to_classinfo(patchref_t *pr);
90 #define PATCHER_resolve_classref_to_classinfo (functionptr) patcher_resolve_classref_to_classinfo
91
92 bool patcher_resolve_classref_to_vftbl(patchref_t *pr);
93 #define PATCHER_resolve_classref_to_vftbl (functionptr) patcher_resolve_classref_to_vftbl
94
95 bool patcher_resolve_classref_to_index(patchref_t *pr);
96 #define PATCHER_resolve_classref_to_index (functionptr) patcher_resolve_classref_to_index
97
98 bool patcher_resolve_classref_to_flags(patchref_t *pr);
99 #define PATCHER_resolve_classref_to_flags (functionptr) patcher_resolve_classref_to_flags
100
101 #if !defined(WITH_STATIC_CLASSPATH)
102 bool patcher_resolve_native_function(patchref_t *pr);
103 #define PATCHER_resolve_native_function (functionptr) patcher_resolve_native_function
104 #endif
105
106 /* old patcher functions */
107
108 bool patcher_get_putstatic(patchref_t *pr);
109 #define PATCHER_get_putstatic (functionptr) patcher_get_putstatic
110
111 #if defined(__I386__)
112
113 bool patcher_getfield(patchref_t *pr);
114 #define PATCHER_getfield (functionptr) patcher_getfield
115
116 bool patcher_putfield(patchref_t *pr);
117 #define PATCHER_putfield (functionptr) patcher_putfield
118
119 #else
120
121 bool patcher_get_putfield(patchref_t *pr);
122 #define PATCHER_get_putfield (functionptr) patcher_get_putfield
123
124 #endif /* defined(__I386__) */
125
126 #if defined(__I386__) || defined(__X86_64__)
127
128 bool patcher_putfieldconst(patchref_t *pr);
129 #define PATCHER_putfieldconst (functionptr) patcher_putfieldconst
130
131 #endif /* defined(__I386__) || defined(__X86_64__) */
132
133 bool patcher_invokestatic_special(patchref_t *pr);
134 #define PATCHER_invokestatic_special (functionptr) patcher_invokestatic_special
135
136 bool patcher_invokevirtual(patchref_t *pr);
137 #define PATCHER_invokevirtual (functionptr) patcher_invokevirtual
138
139 bool patcher_invokeinterface(patchref_t *pr);
140 #define PATCHER_invokeinterface (functionptr) patcher_invokeinterface
141
142 #if defined(__ALPHA__) || defined(__MIPS__) || defined(__POWERPC__) || defined(__S390__) 
143
144 bool patcher_checkcast_interface(patchref_t *pr);
145 #define PATCHER_checkcast_interface (functionptr) patcher_checkcast_interface
146
147 bool patcher_instanceof_interface(patchref_t *pr);
148 #define PATCHER_instanceof_interface (functionptr) patcher_instanceof_interface
149
150 #endif /* defined(__ALPHA__) || defined(__MIPS__) || defined(__POWERPC__) || defined(__S390__) */
151
152 /* very old patcher functions */
153 /* XXX use newer patcher function names above! */
154
155 #if defined(__S390__)
156
157 bool patcher_clinit(patchref_t *pr);
158 #define PATCHER_clinit (functionptr) patcher_clinit
159
160 bool patcher_athrow_areturn(patchref_t *pr);
161 #define PATCHER_athrow_areturn (functionptr) patcher_athrow_areturn
162
163 bool patcher_checkcast_instanceof_interface(patchref_t *pr);
164 #define PATCHER_checkcast_instanceof_interface (functionptr) patcher_checkcast_instanceof_interface
165
166 #endif /* defined (__S390__) */
167
168 #endif /* architecture list */
169
170
171 #endif /* _PATCHER_COMMON_H */
172
173
174 /*
175  * These are local overrides for various environment variables in Emacs.
176  * Please do not remove this and leave it at the end of the file, where
177  * Emacs will automagically detect them.
178  * ---------------------------------------------------------------------
179  * Local variables:
180  * mode: c
181  * indent-tabs-mode: t
182  * c-basic-offset: 4
183  * tab-width: 4
184  * End:
185  * vim:noexpandtab:sw=4:ts=4:
186  */