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