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