de87abbb124ba0fca88d420b5c1bbcb9943a86dd
[cacao.git] / src / vm / jit / m68k / md.h
1 /*      src/vm/jit/m68k/md.h
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_M68K_MD_H
29 #define _VM_JIT_M68K_MD_H
30
31 #include "config.h"
32
33 #include <assert.h>
34 #include <stdint.h>
35
36 #include "vm/jit/codegen-common.h"
37
38
39 /* md_stacktrace_get_returnaddress *********************************************
40
41    Returns the return address of the current stackframe, specified by
42    the passed stack pointer and the stack frame size.
43
44 *******************************************************************************/
45
46 inline static void *md_stacktrace_get_returnaddress(void *sp, int32_t stackframesize)
47 {
48         void *ra;
49
50         /* return address is above stackpointer */
51
52         ra = *((void **) (((uintptr_t) sp) + stackframesize));
53         
54         /* XXX: This helps for now, but it's a ugly hack
55          * the problem _may_ be: the link instruction is used
56          * by some gcc generated code, and we get an additional word
57          * on the stack, the old framepointer. Its address is somewhere
58          * near sp, but that all depends the code generated by the compiler.
59          * I'm unsure about a clean solution.
60          */
61 #if 0
62         if (!(ra > 0x40000000 && ra < 0x80000000))      {
63                 ra = *((u1**)(sp + framesize + 4));
64         }
65 #endif
66
67         /* assert(ra > 0x40000000 && ra < 0x80000000);
68         printf("XXXXXX=%x\n", ra);
69          */
70
71         return ra;
72 }
73
74
75 /* md_codegen_get_pv_from_pc ***************************************************
76
77    On this architecture just a wrapper function to
78    codegen_get_pv_from_pc.
79
80 *******************************************************************************/
81
82 inline static void *md_codegen_get_pv_from_pc(void *ra)
83 {
84         void *pv;
85
86         pv = codegen_get_pv_from_pc(ra);
87
88         return pv;
89 }
90
91
92 /* XXX i can't find a definition of cacheflush in any installed header files but i can find the symbol in libc */
93 /* lets extract the signature from the assembler code*/
94 /*
95     000e7158 <cacheflush>:
96     e7158:       707b            moveq #123,%d0
97     e715a:       2f04            movel %d4,%sp@-
98     e715c:       282f 0014       movel %sp@(20),%d4                     arg 
99     e7160:       2243            moveal %d3,%a1
100     e7162:       262f 0010       movel %sp@(16),%d3                     arg 
101     e7166:       2042            moveal %d2,%a0
102     e7168:       242f 000c       movel %sp@(12),%d2                     arg 
103     e716c:       222f 0008       movel %sp@(8),%d1                      arg 
104     e7170:       4e40            trap #0                                traps into system i guess
105     e7172:       2408            movel %a0,%d2
106     e7174:       2609            movel %a1,%d3
107     e7176:       281f            movel %sp@+,%d4
108     e7178:       223c ffff f001  movel #-4095,%d1
109     e717e:       b081            cmpl %d1,%d0
110     e7180:       6402            bccs e7184 <cacheflush+0x2c>
111     e7182:       4e75            rts
112     e7184:       4480            negl %d0
113     e7186:       2f00            movel %d0,%sp@-
114     e7188:       61ff fff3 82e2  bsrl 1f46c <D_MAX_EXP+0x1ec6d>
115     e718e:       209f            movel %sp@+,%a0@
116     e7190:       70ff            moveq #-1,%d0
117     e7192:       2040            moveal %d0,%a0
118     e7194:       4e75            rts
119     e7196:       4e75            rts
120                                                                         */
121
122 /* seems to have 4 arguments */
123 /* best guess: it is this syscall */
124 /* asmlinkage int sys_cacheflush (unsigned long addr, int scope, int cache, unsigned long len) */
125 /* kernel 2.6.10 with freescale patches (the one I develop against) needs a patch of */
126 /* arch/m68k/kernel/sys_m68k.c(sys_cacheflush) */
127 /* evil hack: */
128 /*
129 void DcacheFlushInvalidateCacheBlock(void *start, unsigned long size);
130 void IcacheInvalidateCacheBlock(void *start, unsigned long size);
131
132 asmlinkage int
133 sys_cacheflush (unsigned long addr, int scope, int cache, unsigned long len)
134 {
135         lock_kernel();
136         DcacheFlushInvalidateCacheBlock(addr, len);
137         IcacheInvalidateCacheBlock(addr, len);
138         unlock_kernel();
139         return 0;
140 }
141 */
142
143 extern int cacheflush(unsigned long addr, int scope, int cache, unsigned long len);
144
145 #include "asm/cachectl.h"       /* found more traces of the cacheflush function */
146 #include "errno.h"
147
148
149 /* md_cacheflush ***************************************************************
150
151    Calls the system's function to flush the instruction and data
152    cache.
153
154 *******************************************************************************/
155
156 inline static void md_cacheflush(void *addr, int nbytes)
157 {
158         cacheflush((unsigned long)addr, FLUSH_SCOPE_PAGE, FLUSH_CACHE_BOTH, nbytes);
159 }
160
161
162 /* md_icacheflush **************************************************************
163
164    Calls the system's function to flush the instruction cache.
165
166 *******************************************************************************/
167
168 inline static void md_icacheflush(void *addr, int nbytes)
169 {
170         cacheflush((unsigned long)addr, FLUSH_SCOPE_LINE, FLUSH_CACHE_INSN, nbytes);
171 }
172
173
174 /* md_dcacheflush **************************************************************
175
176    Calls the system's function to flush the data cache.
177
178 *******************************************************************************/
179
180 inline static void md_dcacheflush(void *addr, int nbytes)
181 {
182         cacheflush((unsigned long)addr, FLUSH_SCOPE_PAGE, FLUSH_CACHE_DATA, nbytes);
183 }
184
185 #endif /* _VM_JIT_M68K_MD_H */
186
187
188 /*
189  * These are local overrides for various environment variables in Emacs.
190  * Please do not remove this and leave it at the end of the file, where
191  * Emacs will automagically detect them.
192  * ---------------------------------------------------------------------
193  * Local variables:
194  * mode: c
195  * indent-tabs-mode: t
196  * c-basic-offset: 4
197  * tab-width: 4
198  * End:
199  * vim:noexpandtab:sw=4:ts=4:
200  */