* configure.ac: New switch for disabling -O2 (--disable-optimizations).
[cacao.git] / src / vm / jit / alpha / md.h
1 /* src/vm/jit/alpha/md.h - machine dependent Alpha 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_ALPHA_MD_H
27 #define _VM_JIT_ALPHA_MD_H
28
29 #include "config.h"
30
31 #include <assert.h>
32 #include <stdint.h>
33
34 #include "vm/jit/alpha/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 /* global variables ***********************************************************/
44
45 extern bool has_ext_instr_set;
46
47
48 /* inline functions ***********************************************************/
49
50 /**
51  * Returns the size (in bytes) of the current stackframe, specified by
52  * the passed codeinfo structure.
53  */
54 inline static int32_t md_stacktrace_get_framesize(codeinfo* code)
55 {
56         // Check for the asm_vm_call_method special case.
57         if (code == NULL)
58                 return 0;
59
60         // On Alpha we use 8-byte stackslots.
61         return code->stackframesize * 8;
62 }
63
64
65 /* md_stacktrace_get_returnaddress *********************************************
66
67    Returns the return address of the current stackframe, specified by
68    the passed stack pointer and the stack frame size.
69
70 *******************************************************************************/
71
72 inline static void *md_stacktrace_get_returnaddress(void *sp, int32_t stackframesize)
73 {
74         void *ra;
75
76         /* On Alpha the return address is located on the top of the
77            stackframe. */
78
79         ra = *((void **) (((uintptr_t) sp) + stackframesize - SIZEOF_VOID_P));
80
81         return ra;
82 }
83
84
85 /* md_codegen_get_pv_from_pc ***************************************************
86
87    Machine code:
88
89    6b5b4000    jsr     (pv)
90    277afffe    ldah    pv,-2(ra)
91    237ba61c    lda     pv,-23012(pv)
92
93 *******************************************************************************/
94
95 inline static void *md_codegen_get_pv_from_pc(void *ra)
96 {
97         uint32_t *pc;
98         uint32_t  mcode;
99         int       opcode;
100         int32_t   disp;
101         void     *pv;
102
103         pc = (uint32_t *) ra;
104
105         /* Get first instruction word after jump. */
106
107         mcode = pc[0];
108
109         /* Get opcode and displacement. */
110
111         opcode = M_MEM_GET_Opcode(mcode);
112         disp   = M_MEM_GET_Memory_disp(mcode);
113
114         /* Check for short or long load (2 instructions). */
115
116         switch (opcode) {
117         case 0x08: /* LDA: TODO use define */
118                 assert((mcode >> 16) == 0x237a);
119
120                 pv = ((uint8_t *) pc) + disp;
121                 break;
122
123         case 0x09: /* LDAH: TODO use define */
124                 pv = ((uint8_t *) pc) + (disp << 16);
125
126                 /* Get displacement of second instruction (LDA). */
127
128                 mcode = pc[1];
129
130                 assert((mcode >> 16) == 0x237b);
131
132                 disp = M_MEM_GET_Memory_disp(mcode);
133
134                 pv = ((uint8_t *) pv) + disp;
135                 break;
136
137         default:
138                 vm_abort_disassemble(pc, 2, "md_codegen_get_pv_from_pc: unknown instruction %x", mcode);
139                 return NULL;
140         }
141
142         return pv;
143 }
144
145
146 /* md_cacheflush ***************************************************************
147
148    Calls the system's function to flush the instruction and data
149    cache.
150
151 *******************************************************************************/
152
153 inline static void md_cacheflush(void *addr, int nbytes)
154 {
155         asm_cacheflush(addr, nbytes);
156 }
157
158
159 /* md_icacheflush **************************************************************
160
161    Calls the system's function to flush the instruction cache.
162
163 *******************************************************************************/
164
165 inline static void md_icacheflush(void *addr, int nbytes)
166 {
167         asm_cacheflush(addr, nbytes);
168 }
169
170
171 /* md_dcacheflush **************************************************************
172
173    Calls the system's function to flush the data cache.
174
175 *******************************************************************************/
176
177 inline static void md_dcacheflush(void *addr, int nbytes)
178 {
179         /* do nothing */
180 }
181
182 #endif /* _VM_JIT_ALPHA_MD_H */
183
184
185 /*
186  * These are local overrides for various environment variables in Emacs.
187  * Please do not remove this and leave it at the end of the file, where
188  * Emacs will automagically detect them.
189  * ---------------------------------------------------------------------
190  * Local variables:
191  * mode: c
192  * indent-tabs-mode: t
193  * c-basic-offset: 4
194  * tab-width: 4
195  * End:
196  */