* src/vm/jit/codegen-common.c: Moved to .cpp.
[cacao.git] / src / vm / jit / powerpc / md.h
1 /* src/vm/jit/powerpc/md.h - machine dependent PowerPC 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_POWERPC_MD_H
27 #define _VM_JIT_POWERPC_MD_H
28
29 #include "config.h"
30
31 #include <assert.h>
32 #include <stdint.h>
33
34 #include "vm/jit/powerpc/codegen.h"
35
36 #include "vm/global.h"
37 #include "vm/vm.hpp"
38
39 #include "vm/jit/asmpart.h"
40 #include "vm/jit/codegen-common.hpp"
41
42
43 /* md_stacktrace_get_returnaddress *********************************************
44
45    Returns the return address of the current stackframe, specified by
46    the passed stack pointer and the stack frame size.
47
48 *******************************************************************************/
49
50 inline static void *md_stacktrace_get_returnaddress(void *sp, int32_t stackframesize)
51 {
52         void *ra;
53
54         /* Pn PowerPC the return address is located in the linkage
55            area. */
56
57         ra = *((void **) (((uintptr_t) sp) + stackframesize + LA_LR_OFFSET));
58
59         return ra;
60 }
61
62
63 /* md_codegen_get_pv_from_pc ***************************************************
64
65    Machine code:
66
67    7d6802a6    mflr    r11
68    39abffe0    addi    r13,r11,-32
69
70    or
71
72    7d6802a6    mflr    r11
73    3dabffff    addis   r13,r11,-1
74    39ad68b0    addi    r13,r13,26800
75
76 *******************************************************************************/
77
78 inline static void* md_codegen_get_pv_from_pc(void* ra)
79 {
80         int32_t offset;
81
82         uint32_t* pc = (uint32_t*) ra;
83
84         /* get first instruction word after jump */
85
86         uint32_t mcode = pc[1];
87
88         /* check if we have 2 instructions (addis, addi) */
89
90         if ((mcode >> 16) == 0x3dab) {
91                 /* get displacement of first instruction (addis) */
92
93                 offset = (int32_t) (mcode << 16);
94
95                 /* get displacement of second instruction (addi) */
96
97                 mcode = pc[2];
98
99                 /* check for addi instruction */
100
101                 assert((mcode >> 16) == 0x39ad);
102
103                 offset += (int16_t) (mcode & 0x0000ffff);
104         }
105         else {
106                 /* check for addi instruction */
107
108                 assert((mcode >> 16) == 0x39ab);
109
110                 /* get offset of first instruction (addi) */
111
112                 offset = (int16_t) (mcode & 0x0000ffff);
113         }
114
115         /* calculate PV via RA + offset */
116
117         void* pv = (void*) (((uintptr_t) ra) + offset);
118
119         return pv;
120 }
121
122
123 /* md_cacheflush ***************************************************************
124
125    Calls the system's function to flush the instruction and data
126    cache.
127
128 *******************************************************************************/
129
130 inline static void md_cacheflush(void *addr, int nbytes)
131 {
132         asm_cacheflush(addr, nbytes);
133 }
134
135
136 /* md_icacheflush **************************************************************
137
138    Calls the system's function to flush the instruction cache.
139
140 *******************************************************************************/
141
142 inline static void md_icacheflush(void *addr, int nbytes)
143 {
144         asm_cacheflush(addr, nbytes);
145 }
146
147
148 /* md_dcacheflush **************************************************************
149
150    Calls the system's function to flush the data cache.
151
152 *******************************************************************************/
153
154 inline static void md_dcacheflush(void *addr, int nbytes)
155 {
156         asm_cacheflush(addr, nbytes);
157 }
158
159 #endif /* _VM_JIT_POWERPC_MD_H */
160
161
162 /*
163  * These are local overrides for various environment variables in Emacs.
164  * Please do not remove this and leave it at the end of the file, where
165  * Emacs will automagically detect them.
166  * ---------------------------------------------------------------------
167  * Local variables:
168  * mode: c
169  * indent-tabs-mode: t
170  * c-basic-offset: 4
171  * tab-width: 4
172  * End:
173  * vim:noexpandtab:sw=4:ts=4:
174  */