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