1 /* src/vm/jit/arm/md.c - machine dependent ARM 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
31 #include "vm/jit/arm/md.h"
32 #include "vm/jit/arm/md-abi.h"
35 /* md_init *********************************************************************
37 Do some machine dependent initialization.
39 *******************************************************************************/
47 /* md_jit_method_patch_address *************************************************
49 Gets the patch address of the currently compiled method. The offset
50 is extracted from the load instruction(s) before the jump and added
51 to the right base address (PV or REG_METHODPTR).
55 e51cc040 ldr ip, [ip, #-64]
66 How we find out the patching address to store new method pointer:
67 - loaded IP with LDR IP,[METHODPTR]?
68 yes=INVOKEVIRTUAL or INVOKEINTERFACE (things are easy!)
69 - loaded IP from data segment
70 yes=INVOKESTATIC or INVOKESPECIAL (things are complicated)
71 recompute pointer to data segment, maybe larger offset
73 *******************************************************************************/
75 void *md_jit_method_patch_address(void *pv, void *ra, void *mptr)
80 void *pa; /* patch address */
82 /* Go back to the actual load instruction. */
84 pc = ((uint32_t *) ra) - 3;
86 /* Get first instruction word on current PC. */
90 /* sanity check: are we inside jit code? */
92 assert(pc[1] == 0xe1a0e00f /*MOV LR,PC*/);
93 assert(pc[2] == 0xe1a0f00c /*MOV PC,IP*/);
95 /* get the load instruction and offset */
97 offset = (int32_t) (mcode & 0x0fff);
99 assert ((mcode & 0xff70f000) == 0xe510c000);
101 if ((mcode & 0x000f0000) == 0x000b0000) {
102 /* sanity check: offset was positive */
104 assert((mcode & 0x00800000) == 0x00800000);
106 /* return NULL if no mptr was specified (used for replacement) */
111 /* we loaded from REG_METHODPTR */
113 pa = ((uint8_t *) mptr) + offset;
116 /* sanity check: we loaded from REG_IP; offset was negative or zero */
118 assert((mcode & 0x008f0000) == 0x000c0000 ||
119 (mcode & 0x008f0fff) == 0x008c0000);
121 /* we loaded from data segment; offset can be larger */
125 /* check for "SUB IP, IP, #??, ROTL 12" */
127 if ((mcode & 0xffffff00) == 0xe24cca00)
128 offset += (int32_t) ((mcode & 0x00ff) << 12);
130 /* and get the final data segment address */
132 pa = ((uint8_t *) pv) - offset;
140 * Patch the given replacement point.
142 #if defined(ENABLE_REPLACEMENT)
143 void md_patch_replacement_point(u1 *pc, u1 *savedmcode, bool revert)
145 vm_abort("md_patch_replacement_point: IMPLEMENT ME!");
151 * These are local overrides for various environment variables in Emacs.
152 * Please do not remove this and leave it at the end of the file, where
153 * Emacs will automagically detect them.
154 * ---------------------------------------------------------------------
157 * indent-tabs-mode: t
161 * vim:noexpandtab:sw=4:ts=4: