b70509f86130e849b1ef14677104dc89303e045c
[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, 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_POWERPC64_MD_H
27 #define _VM_JIT_POWERPC64_MD_H
28
29 #include "config.h"
30
31 #include <assert.h>
32 #include <stdint.h>
33
34 #include "vm/jit/powerpc64/codegen.h"
35
36 #include "vm/global.h"
37 #include "vm/vm.hpp"
38
39 #include "vm/jit/asmpart.h"
40 #include "vm/jit/jit.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         /* On PowerPC64 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    39cbffe0    addi    r14,r11,-32
69
70    or
71
72    7d6802a6    mflr    r11
73    3dcbffff    addis   r14,r11,-1
74    39ce68b0    addi    r14,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) == 0x3dcb) {
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) == 0x39ce);
102
103                 offset += (int16_t) (mcode & 0x0000ffff);
104         }
105         else if ((mcode >> 16) == 0x39cb) {
106                 /* get offset of first instruction (addi) */
107
108                 offset = (int16_t) (mcode & 0x0000ffff);
109         }
110         else {
111                 vm_abort("md_codegen_get_pv_from_pc: unknown instruction %x", mcode);
112
113                 /* keep compiler happy */
114
115                 offset = 0;
116         }
117
118         /* calculate PV via RA + offset */
119
120         void* pv = (void*) (((uintptr_t) ra) + offset);
121
122         return pv;
123 }
124
125
126 /* md_cacheflush ***************************************************************
127
128    Calls the system's function to flush the instruction and data
129    cache.
130
131 *******************************************************************************/
132
133 inline static void md_cacheflush(void *addr, int nbytes)
134 {
135         asm_cacheflush(addr, nbytes);
136 }
137
138
139 /* md_icacheflush **************************************************************
140
141    Calls the system's function to flush the instruction cache.
142
143 *******************************************************************************/
144
145 inline static void md_icacheflush(void *addr, int nbytes)
146 {
147         asm_cacheflush(addr, nbytes);
148 }
149
150
151 /* md_dcacheflush **************************************************************
152
153    Calls the system's function to flush the data cache.
154
155 *******************************************************************************/
156
157 inline static void md_dcacheflush(void *addr, int nbytes)
158 {
159         asm_cacheflush(addr, nbytes);
160 }
161
162 #endif /* _VM_JIT_POWERPC64_MD_H */
163
164
165 /*
166  * These are local overrides for various environment variables in Emacs.
167  * Please do not remove this and leave it at the end of the file, where
168  * Emacs will automagically detect them.
169  * ---------------------------------------------------------------------
170  * Local variables:
171  * mode: c
172  * indent-tabs-mode: t
173  * c-basic-offset: 4
174  * tab-width: 4
175  * End:
176  * vim:noexpandtab:sw=4:ts=4:
177  */