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