1 /* src/vm/jit/x86_64/md.c - machine dependent x86_64 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/x86_64/md-abi.h"
36 #include "vm/jit/codegen-common.hpp"
37 #include "vm/jit/jit.hpp"
40 /* md_init *********************************************************************
42 Do some machine dependent initialization.
44 *******************************************************************************/
52 /* md_jit_method_patch_address *************************************************
54 Gets the patch address of the currently compiled method. The offset
55 is extracted from the load instruction(s) before the jump and added
56 to the right base address (PV or REG_METHODPTR).
60 4d 8b 15 e2 fe ff ff mov -286(%rip),%r10
61 49 ff d2 rex64Z callq *%r10
65 4c 8b 17 mov (%rdi),%r10
66 49 8b 82 00 00 00 00 mov 0x0(%r10),%rax
67 48 ff d3 rex64 callq *%rax
71 4c 8b 17 mov (%rdi),%r10
72 4d 8b 92 00 00 00 00 mov 0x0(%r10),%r10
73 49 8b 82 00 00 00 00 mov 0x0(%r10),%rax
74 48 ff d3 rex64 callq *%r11
76 *******************************************************************************/
78 void *md_jit_method_patch_address(void *pv, void *ra, void *mptr)
83 void *pa; /* patch address */
85 /* go back to the actual call instruction (3-bytes) */
87 pc = ((uint8_t *) ra) - 3;
89 /* get the last byte of the call */
93 /* check for the different calls */
96 /* INVOKESTATIC/SPECIAL */
98 /* Get the offset from the instruction (the offset address is
99 4-bytes before the call instruction). */
101 offset = *((int32_t *) (pc - 4));
103 /* add the offset to the return address (IP-relative addressing) */
107 else if (mcode == 0xd3) {
108 /* INVOKEVIRTUAL/INTERFACE */
110 /* return NULL if no mptr was specified (used for replacement) */
115 /* Get the offset from the instruction (the offset address is
116 4-bytes before the call instruction). */
118 offset = *((int32_t *) (pc - 4));
120 /* add the offset to the method pointer */
122 pa = ((uint8_t *) mptr) + offset;
125 /* catch any problems */
127 vm_abort("md_jit_method_patch_address: unknown instruction %x", mcode);
129 /* keep compiler happy */
138 /* md_patch_replacement_point **************************************************
140 Patch the given replacement point.
142 *******************************************************************************/
144 #if defined(ENABLE_REPLACEMENT)
145 void md_patch_replacement_point(u1 *pc, u1 *savedmcode, bool revert)
150 /* write saved machine code */
151 *(u2*)(pc) = *(u2*)(savedmcode);
154 /* save the current machine code */
155 *(u2*)(savedmcode) = *(u2*)(pc);
157 /* build the machine code for the patch */
160 /* write new machine code */
161 *(u2*)(pc) = (u2) mcode;
164 /* XXX if required asm_cacheflush(pc,8); */
166 #endif /* defined(ENABLE_REPLACEMENT) */
170 * These are local overrides for various environment variables in Emacs.
171 * Please do not remove this and leave it at the end of the file, where
172 * Emacs will automagically detect them.
173 * ---------------------------------------------------------------------
176 * indent-tabs-mode: t
180 * vim:noexpandtab:sw=4:ts=4: