e912e7efe96583ea873a14dc7a4028acf7a71b15
[cacao.git] / src / vm / jit / sparc64 / md.c
1
2 #include "config.h"
3
4 #include "vm/types.h"
5
6 #include "vm/jit/sparc64/md-abi.h"
7
8 #include "vm/exceptions.h"
9 #include "vm/stringlocal.h"
10 #include "vm/jit/asmpart.h"
11 #include "vm/jit/stacktrace.h"
12
13
14 /* md_init *********************************************************************
15
16    Do some machine dependent initialization.
17
18 *******************************************************************************/
19
20 void md_init(void)
21 {
22         /* do nothing */
23 }
24
25
26 /* md_stacktrace_get_returnaddress *********************************************
27
28    Returns the return address of the current stackframe, specified by
29    the passed stack pointer and the stack frame size.
30
31 *******************************************************************************/
32
33 u1 *md_stacktrace_get_returnaddress(u1 *sp, u4 framesize)
34 {
35         /* where's it gonna be ? */
36
37         return 0;
38 }
39
40
41 /* md_codegen_findmethod *******************************************************
42
43
44    This reconstructs and returns the PV of a method given a return address
45    pointer. (basically, same was as the generated code following the jump does)
46    
47    Machine code:
48
49    6b5b4000    jsr     (pv)
50    277afffe    ldah    pv,-2(ra)
51    237ba61c    lda     pv,-23012(pv)
52
53 *******************************************************************************/
54
55 u1 *md_codegen_findmethod(u1 *ra)
56 {
57         u1 *pv;
58         u4  mcode;
59         s4  offset;
60
61         pv = ra;
62
63         /* get first instruction word after jump */
64
65         mcode = *((u4 *) ra);
66
67         /* check if we have 2 instructions (ldah, lda) */
68
69         if ((mcode >> 16) == 0x277a) {
70                 /* get displacement of first instruction (ldah) */
71
72                 offset = (s4) (mcode << 16);
73                 pv += offset;
74
75                 /* get displacement of second instruction (lda) */
76
77                 mcode = *((u4 *) (ra + 1 * 4));
78
79                 assert((mcode >> 16) == 0x237b);
80
81                 offset = (s2) (mcode & 0x0000ffff);
82                 pv += offset;
83
84         } else {
85                 /* get displacement of first instruction (lda) */
86
87                 assert((mcode >> 16) == 0x237a);
88
89                 offset = (s2) (mcode & 0x0000ffff);
90                 pv += offset;
91         }
92
93         return pv;
94 }
95
96
97 /* md_cacheflush ***************************************************************
98
99    Calls the system's function to flush the instruction and data
100    cache.
101
102 *******************************************************************************/
103
104 void md_cacheflush(u1 *addr, s4 nbytes)
105 {
106         /* don't know yet */    
107 }
108
109
110 /* md_icacheflush **************************************************************
111
112    Calls the system's function to flush the instruction cache.
113
114 *******************************************************************************/
115
116 void md_icacheflush(u1 *addr, s4 nbytes)
117 {
118         /* don't know yet */    
119 }
120
121
122 /* md_patch_replacement_point **************************************************
123
124    Patch the given replacement point.
125
126 *******************************************************************************/
127
128 void md_patch_replacement_point(rplpoint *rp)
129 {
130     u8 mcode;
131
132         /* save the current machine code */
133         mcode = *(u4*)rp->pc;
134
135         /* write the new machine code */
136     *(u4*)(rp->pc) = (u4) rp->mcode;
137
138         /* store saved mcode */
139         rp->mcode = mcode;
140         
141 #if !defined(NDEBUG) && defined(ENABLE_DISASSEMBLER)
142         {
143                 u1* u1ptr = rp->pc;
144                 DISASSINSTR(u1ptr);
145                 fflush(stdout);
146         }
147 #endif
148                         
149         /* flush instruction cache */
150     /* md_icacheflush(rp->pc,4); */
151 }
152
153 /*
154  * These are local overrides for various environment variables in Emacs.
155  * Please do not remove this and leave it at the end of the file, where
156  * Emacs will automagically detect them.
157  * ---------------------------------------------------------------------
158  * Local variables:
159  * mode: c
160  * indent-tabs-mode: t
161  * c-basic-offset: 4
162  * tab-width: 4
163  * End:
164  * vim:noexpandtab:sw=4:ts=4:
165  */