* Merged in new atomic instructions (twisti branch).
[cacao.git] / src / vm / jit / arm / md.h
1 /* src/vm/jit/arm/md.h - machine dependent Arm functions
2
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
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 _VM_JIT_ARM_MD_H
29 #define _VM_JIT_ARM_MD_H
30
31 #include "config.h"
32
33 #include <assert.h>
34 #include <stdint.h>
35
36 #include "vm/types.h"
37
38 #include "vm/jit/asmpart.h"
39 #include "vm/jit/codegen-common.h"
40
41
42 /* md_stacktrace_get_returnaddress *********************************************
43
44    Returns the return address of the current stackframe, specified by
45    the passed stack pointer and the stack frame size.
46
47 *******************************************************************************/
48
49 inline static void *md_stacktrace_get_returnaddress(void *sp, int32_t stackframesize)
50 {
51         void *ra;
52
53         /* On ARM the return address is located on the top of the
54            stackframe. */
55         /* ATTENTION: This is only true for non-leaf methods!!! */
56
57         ra = *((void **) (((uintptr_t) sp) + stackframesize - SIZEOF_VOID_P));
58
59         return ra;
60 }
61
62
63 /* md_codegen_get_pv_from_pc ***************************************************
64
65    TODO: document me
66
67 *******************************************************************************/
68
69 inline static u1 *md_codegen_get_pv_from_pc(u1 *ra)
70 {
71         u1 *pv;
72         u4  mcode1, mcode2, mcode3;
73
74         pv = ra;
75
76         /* this can either be a RECOMPUTE_IP in JIT code or a fake in asm_calljavafunction */
77         mcode1 = *((u4*) ra);
78         if ((mcode1 & 0xffffff00) == 0xe24fcf00 /*sub ip,pc,#__*/)
79                 pv -= (s4) ((mcode1 & 0x000000ff) <<  2);
80         else if ((mcode1 & 0xffffff00) == 0xe24fc000 /*sub ip,pc,#__*/)
81                 pv -= (s4) (mcode1 & 0x000000ff);
82         else {
83                 /* if this happens, we got an unexpected instruction at (*ra) */
84                 vm_abort("Unable to find method: %p (instr=%x)", ra, mcode1);
85         }
86
87         /* if we have a RECOMPUTE_IP there can be more than one instruction */
88         mcode2 = *((u4*) (ra + 4));
89         mcode3 = *((u4*) (ra + 8));
90         if ((mcode2 & 0xffffff00) == 0xe24ccb00 /*sub ip,ip,#__*/)
91                 pv -= (s4) ((mcode2 & 0x000000ff) << 10);
92         if ((mcode3 & 0xffffff00) == 0xe24cc700 /*sub ip,ip,#__*/)
93                 pv -= (s4) ((mcode3 & 0x000000ff) << 18);
94
95         /* we used PC-relative adressing; but now it is LR-relative */
96         pv += 8;
97
98         /* if we found our method the data segment has to be valid */
99         /* we check this by looking up the IsLeaf field, which has to be boolean */
100 /*      assert( *((s4*)pv-8) == (s4)true || *((s4*)pv-8) == (s4)false );  */
101
102         return pv;
103 }
104
105
106 /* md_cacheflush ***************************************************************
107
108    Calls the system's function to flush the instruction and data
109    cache.
110
111 *******************************************************************************/
112
113 inline static void md_cacheflush(void *addr, int nbytes)
114 {
115         asm_cacheflush(addr, nbytes);
116 }
117
118
119 /* md_icacheflush **************************************************************
120
121    Calls the system's function to flush the instruction cache.
122
123 *******************************************************************************/
124
125 inline static void md_icacheflush(void *addr, int nbytes)
126 {
127         asm_cacheflush(addr, nbytes);
128 }
129
130
131 /* md_dcacheflush **************************************************************
132
133    Calls the system's function to flush the data cache.
134
135 *******************************************************************************/
136
137 inline static void md_dcacheflush(void *addr, int nbytes)
138 {
139         /* do nothing */
140 }
141
142 #endif /* _VM_JIT_ARM_MD_H */
143
144
145 /*
146  * These are local overrides for various environment variables in Emacs.
147  * Please do not remove this and leave it at the end of the file, where
148  * Emacs will automagically detect them.
149  * ---------------------------------------------------------------------
150  * Local variables:
151  * mode: c
152  * indent-tabs-mode: t
153  * c-basic-offset: 4
154  * tab-width: 4
155  * End:
156  * vim:noexpandtab:sw=4:ts=4:
157  */