1 /* src/vm/jit/alpha/patcher.c - Alpha code patching functions
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
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.
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.
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
32 #include "vm/jit/alpha/md.h"
34 #include "mm/memory.h"
36 #include "native/native.h"
38 #include "vm/jit/builtin.hpp"
40 #include "vm/field.hpp"
41 #include "vm/initialize.h"
42 #include "vm/options.h"
43 #include "vm/references.h"
44 #include "vm/resolve.h"
46 #include "vm/jit/asmpart.h"
47 #include "vm/jit/patcher-common.hpp"
48 #include "vm/jit/methodheader.h"
51 #define PATCH_BACK_ORIGINAL_MCODE \
52 *((u4 *) pr->mpc) = (u4) pr->mcode; \
53 md_icacheflush(NULL, 0);
56 /* patcher_patch_code **********************************************************
58 Just patches back the original machine code.
60 *******************************************************************************/
62 void patcher_patch_code(patchref_t *pr)
64 PATCH_BACK_ORIGINAL_MCODE;
68 /* patcher_resolve_classref_to_classinfo ***************************************
72 <patched call postition>
73 a61bff80 ldq a0,-128(pv)
77 <patched call position>
78 a63bff80 ldq a1,-128(pv)
80 a77bff78 ldq pv,-136(pv)
85 <patched call position>
86 a63bfe60 ldq a1,-416(pv)
87 a77bfe58 ldq pv,-424(pv)
90 *******************************************************************************/
92 bool patcher_resolve_classref_to_classinfo(patchref_t *pr)
94 constant_classref *cr;
98 /* get stuff from the stack */
100 cr = (constant_classref *) pr->ref;
101 datap = (u1 *) pr->datap;
103 /* get the classinfo */
105 if (!(c = resolve_classref_eager(cr)))
108 PATCH_BACK_ORIGINAL_MCODE;
110 /* patch the classinfo pointer */
112 *((ptrint *) datap) = (ptrint) c;
118 /* patcher_resolve_classref_to_vftbl *******************************************
123 <patched call position>
124 a7940000 ldq at,0(a4)
125 a7bbff28 ldq gp,-216(pv)
127 *******************************************************************************/
129 bool patcher_resolve_classref_to_vftbl(patchref_t *pr)
131 constant_classref *cr;
135 /* get stuff from the stack */
137 cr = (constant_classref *) pr->ref;
138 datap = (u1 *) pr->datap;
140 /* get the fieldinfo */
142 if (!(c = resolve_classref_eager(cr)))
145 PATCH_BACK_ORIGINAL_MCODE;
147 /* patch super class' vftbl */
149 *((ptrint *) datap) = (ptrint) c->vftbl;
155 /* patcher_resolve_classref_to_flags *******************************************
157 CHECKCAST/INSTANCEOF:
159 <patched call position>
161 *******************************************************************************/
163 bool patcher_resolve_classref_to_flags(patchref_t *pr)
165 constant_classref *cr;
169 /* get stuff from the stack */
171 cr = (constant_classref *) pr->ref;
172 datap = (u1 *) pr->datap;
174 /* get the fieldinfo */
176 if (!(c = resolve_classref_eager(cr)))
179 PATCH_BACK_ORIGINAL_MCODE;
181 /* patch class flags */
183 *((s4 *) datap) = (s4) c->flags;
189 /* patcher_get_putstatic *******************************************************
193 <patched call position>
194 a73bff98 ldq t11,-104(pv)
195 a2590000 ldl a2,0(t11)
197 *******************************************************************************/
199 bool patcher_get_putstatic(patchref_t *pr)
201 unresolved_field *uf;
205 /* get stuff from the stack */
207 uf = (unresolved_field *) pr->ref;
208 datap = (u1 *) pr->datap;
210 /* get the fieldinfo */
212 if (!(fi = resolve_field_eager(uf)))
215 /* check if the field's class is initialized */
217 if (!(fi->clazz->state & CLASS_INITIALIZED))
218 if (!initialize_class(fi->clazz))
221 PATCH_BACK_ORIGINAL_MCODE;
223 /* patch the field value's address */
225 *((intptr_t *) datap) = (intptr_t) fi->value;
231 /* patcher_get_putfield ********************************************************
235 <patched call position>
236 a2af0020 ldl a5,32(s6)
238 *******************************************************************************/
240 bool patcher_get_putfield(patchref_t *pr)
243 unresolved_field *uf;
247 uf = (unresolved_field *) pr->ref;
249 /* get the fieldinfo */
251 if (!(fi = resolve_field_eager(uf)))
254 PATCH_BACK_ORIGINAL_MCODE;
256 /* patch the field's offset into the instruction */
258 *((u4 *) ra) |= (s2) (fi->offset & 0x0000ffff);
260 md_icacheflush(NULL, 0);
266 /* patcher_invokestatic_special ************************************************
270 <patched call position>
271 a77bffa8 ldq pv,-88(pv)
274 ******************************************************************************/
276 bool patcher_invokestatic_special(patchref_t *pr)
278 unresolved_method *um;
282 /* get stuff from the stack */
284 um = (unresolved_method *) pr->ref;
285 datap = (u1 *) pr->datap;
287 /* get the fieldinfo */
289 if (!(m = resolve_method_eager(um)))
292 PATCH_BACK_ORIGINAL_MCODE;
294 /* patch stubroutine */
296 *((ptrint *) datap) = (ptrint) m->stubroutine;
302 /* patcher_invokevirtual *******************************************************
306 <patched call position>
307 a7900000 ldq at,0(a0)
308 a77c0100 ldq pv,256(at)
311 *******************************************************************************/
313 bool patcher_invokevirtual(patchref_t *pr)
316 unresolved_method *um;
319 /* get stuff from the stack */
322 um = (unresolved_method *) pr->ref;
324 /* get the fieldinfo */
326 if (!(m = resolve_method_eager(um)))
329 PATCH_BACK_ORIGINAL_MCODE;
331 /* patch vftbl index */
333 *((s4 *) (ra + 4)) |= (s4) ((OFFSET(vftbl_t, table[0]) +
334 sizeof(methodptr) * m->vftblindex) & 0x0000ffff);
336 md_icacheflush(NULL, 0);
342 /* patcher_invokeinterface *****************************************************
346 <patched call position>
347 a7900000 ldq at,0(a0)
348 a79cffa0 ldq at,-96(at)
349 a77c0018 ldq pv,24(at)
352 *******************************************************************************/
354 bool patcher_invokeinterface(patchref_t *pr)
357 unresolved_method *um;
360 /* get stuff from the stack */
363 um = (unresolved_method *) pr->ref;
365 /* get the fieldinfo */
367 if (!(m = resolve_method_eager(um)))
370 PATCH_BACK_ORIGINAL_MCODE;
372 /* patch interfacetable index */
374 *((s4 *) (ra + 4)) |= (s4) ((OFFSET(vftbl_t, interfacetable[0]) -
375 sizeof(methodptr*) * m->clazz->index) & 0x0000ffff);
377 /* patch method offset */
379 *((s4 *) (ra + 4 + 4)) |=
380 (s4) ((sizeof(methodptr) * (m - m->clazz->methods)) & 0x0000ffff);
382 md_icacheflush(NULL, 0);
388 /* patcher_checkcast_interface *************************************************
392 <patched call position>
393 a78e0000 ldq at,0(s5)
394 a3bc001c ldl gp,28(at)
395 23bdfffd lda gp,-3(gp)
396 efa0002e ble gp,0x00000200002bf6b0
397 a7bcffe8 ldq gp,-24(at)
399 *******************************************************************************/
401 bool patcher_checkcast_interface(patchref_t *pr)
404 constant_classref *cr;
407 /* get stuff from the stack */
410 cr = (constant_classref *) pr->ref;
412 /* get the fieldinfo */
414 if (!(c = resolve_classref_eager(cr)))
417 PATCH_BACK_ORIGINAL_MCODE;
419 /* patch super class index */
421 *((s4 *) (ra + 2 * 4)) |= (s4) (-(c->index) & 0x0000ffff);
423 *((s4 *) (ra + 5 * 4)) |= (s4) ((OFFSET(vftbl_t, interfacetable[0]) -
424 c->index * sizeof(methodptr*)) & 0x0000ffff);
426 md_icacheflush(NULL, 0);
432 /* patcher_instanceof_interface ************************************************
436 <patched call position>
437 a78e0000 ldq at,0(s5)
438 a3bc001c ldl gp,28(at)
439 23bdfffd lda gp,-3(gp)
440 efa0002e ble gp,0x00000200002bf6b0
441 a7bcffe8 ldq gp,-24(at)
443 *******************************************************************************/
445 bool patcher_instanceof_interface(patchref_t *pr)
448 constant_classref *cr;
451 /* get stuff from the stack */
454 cr = (constant_classref *) pr->ref;
456 /* get the fieldinfo */
458 if (!(c = resolve_classref_eager(cr)))
461 PATCH_BACK_ORIGINAL_MCODE;
463 /* patch super class index */
465 *((s4 *) (ra + 2 * 4)) |= (s4) (-(c->index) & 0x0000ffff);
467 *((s4 *) (ra + 4 * 4)) |= (s4) ((OFFSET(vftbl_t, interfacetable[0]) -
468 c->index * sizeof(methodptr*)) & 0x0000ffff);
470 md_icacheflush(NULL, 0);
477 * These are local overrides for various environment variables in Emacs.
478 * Please do not remove this and leave it at the end of the file, where
479 * Emacs will automagically detect them.
480 * ---------------------------------------------------------------------
483 * indent-tabs-mode: t
487 * vim:noexpandtab:sw=4:ts=4: