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