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