* src/vm/jit/md.h: Removed.
[cacao.git] / src / vm / jit / mips / md.h
1 /* src/vm/jit/mips/md.h - machine dependent MIPS 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_MIPS_MD_H
29 #define _VM_JIT_MIPS_MD_H
30
31 #include "config.h"
32
33 #include <assert.h>
34 #include <stdint.h>
35 #include <unistd.h>
36 #include <sys/cachectl.h>
37
38 #include "vm/types.h"
39
40 #include "vm/vm.h"
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 MIPS the return address is located on the top of the
55            stackframe. */
56
57         ra = *((void **) (((uintptr_t) sp) + stackframesize - 8));
58
59         return ra;
60 }
61
62
63 /* md_codegen_get_pv_from_pc ***************************************************
64
65    Machine code:
66
67    03c0f809    jalr     s8
68    00000000    nop
69    27feff9c    addiu    s8,ra,-100
70
71 *******************************************************************************/
72
73 inline static u1 *md_codegen_get_pv_from_pc(u1 *ra)
74 {
75         u1 *pv;
76         u4  mcode;
77         s4  offset;
78
79         /* get the offset of the instructions */
80
81         /* get first instruction word after jump */
82
83         mcode = *((u4 *) ra);
84
85         /* check if we have 2 instructions (lui, daddiu) */
86
87         if ((mcode >> 16) == 0x3c19) {
88                 /* get displacement of first instruction (lui) */
89
90                 offset = (s4) (mcode << 16);
91
92                 /* get displacement of second instruction (daddiu) */
93
94                 mcode = *((u4 *) (ra + 1 * 4));
95
96 #if SIZEOF_VOID_P == 8
97                 assert((mcode >> 16) == 0x6739);
98 #else
99                 assert((mcode >> 16) == 0x2739);
100 #endif
101
102                 offset += (s2) (mcode & 0x0000ffff);
103         }
104         else {
105                 /* get offset of first instruction (daddiu) */
106
107                 mcode = *((u4 *) ra);
108
109 #if SIZEOF_VOID_P == 8
110                 assert((mcode >> 16) == 0x67fe);
111 #else
112                 assert((mcode >> 16) == 0x27fe);
113 #endif
114
115                 offset = (s2) (mcode & 0x0000ffff);
116         }
117
118         /* calculate PV via RA + offset */
119
120         pv = 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         cacheflush(addr, nbytes, BCACHE);
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         cacheflush(addr, nbytes, ICACHE);
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         cacheflush(addr, nbytes, DCACHE);
160 }
161
162 #endif /* _VM_JIT_MIPS_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  */