1 /* src/vm/jit/arm/md.c - machine dependent Arm functions
3 Copyright (C) 1996-2005, 2006, 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
8 This file is part of CACAO.
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.
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.
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
33 #include "vm/jit/arm/md.h"
34 #include "vm/jit/arm/md-abi.h"
37 /* md_init *********************************************************************
39 Do some machine dependent initialization.
41 *******************************************************************************/
49 /* md_jit_method_patch_address *************************************************
51 Gets the patch address of the currently compiled method. The offset
52 is extracted from the load instruction(s) before the jump and added
53 to the right base address (PV or REG_METHODPTR).
57 e51cc040 ldr ip, [ip, #-64]
68 How we find out the patching address to store new method pointer:
69 - loaded IP with LDR IP,[METHODPTR]?
70 yes=INVOKEVIRTUAL or INVOKEINTERFACE (things are easy!)
71 - loaded IP from data segment
72 yes=INVOKESTATIC or INVOKESPECIAL (things are complicated)
73 recompute pointer to data segment, maybe larger offset
75 *******************************************************************************/
77 void *md_jit_method_patch_address(void *pv, void *ra, void *mptr)
82 void *pa; /* patch address */
84 /* Go back to the actual load instruction. */
86 pc = ((uint32_t *) ra) - 3;
88 /* Get first instruction word on current PC. */
92 /* sanity check: are we inside jit code? */
94 assert(pc[1] == 0xe1a0e00f /*MOV LR,PC*/);
95 assert(pc[2] == 0xe1a0f00c /*MOV PC,IP*/);
97 /* get the load instruction and offset */
99 offset = (int32_t) (mcode & 0x0fff);
101 assert ((mcode & 0xff70f000) == 0xe510c000);
103 if ((mcode & 0x000f0000) == 0x000b0000) {
104 /* sanity check: offset was positive */
106 assert((mcode & 0x00800000) == 0x00800000);
108 /* return NULL if no mptr was specified (used for replacement) */
113 /* we loaded from REG_METHODPTR */
115 pa = ((uint8_t *) mptr) + offset;
118 /* sanity check: we loaded from REG_IP; offset was negative or zero */
120 assert((mcode & 0x008f0000) == 0x000c0000 ||
121 (mcode & 0x008f0fff) == 0x008c0000);
123 /* we loaded from data segment; offset can be larger */
127 /* check for "SUB IP, IP, #??, ROTL 12" */
129 if ((mcode & 0xffffff00) == 0xe24cca00)
130 offset += (int32_t) ((mcode & 0x00ff) << 12);
132 /* and get the final data segment address */
134 pa = ((uint8_t *) pv) - offset;
141 void *md_asm_codegen_get_pv_from_pc(void *ra)
143 return md_codegen_get_pv_from_pc(ra);
148 * These are local overrides for various environment variables in Emacs.
149 * Please do not remove this and leave it at the end of the file, where
150 * Emacs will automagically detect them.
151 * ---------------------------------------------------------------------
154 * indent-tabs-mode: t
158 * vim:noexpandtab:sw=4:ts=4: