First JEM version from Nevo <sakur.deagod@gmail.com>, very buggy
[jamvm-avr32-jem.git] / src / interp / engine / interp_jem.h
blob7fa33e6b533be600ca4564007086bdfe292440ea
1 /*
2 * Copyright (C) 2003, 2004, 2005, 2006, 2007
3 * Robert Lougher <rob@lougher.org.uk>.
5 * This file is part of JamVM.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2,
10 * or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #ifndef INTERP_JEM_H_
23 #define INTERP_JEM_H_
24 #ifdef JEM
26 #define PREPARE_JEM(mb,frame) \
27 { \
28 __asm__ __volatile__( \
29 "pushm r0-r9,r11,r12,lr\n" \
30 "mov r8,%[cp] \n\t" \
31 "mov r9,%[lv0], \n\t" \
32 ::[cp]"r"(cp->orgPointer),[lv0]"r"(lvars[mb->max_locals - 1]) \
33 :"r8","r9" \
34 ); \
37 #define ENTRY_JEM(jpc) \
38 { \
39 __asm__ __volatile__( \
40 "mov lr,%[pc] \n\t" \
41 "retj " \
42 ::[pc]"r"(jpc) \
43 :"lr" \
44 );\
49 /**
50 * load trap entries to JEM trap table set when initializing JamVM
52 #define INIT_JEM_TRAPS(jtba) \
53 HANDLER_TABLE_T *jem_trap_init_tbl[2] = { \
54 &&tstart,\
55 &&tend \
56 }; \
57 int i=0; \
58 tstart: \
59 __asm__ __volatile__( \
60 "sub r11,pc,%0<<0 \n" \
61 "lsr r11,7 \n" \
62 "mfsr r10,0x54 \n" \
63 "mov r12,%1\n" \
64 "mov pc,r12" \
65 ::"r"(jtba) ,"r"((int)(*((int*)jem_trap_handlers_0_ENTRY[0])))\
66 :"memory" \
67 ); \
68 tend: \
70 for (; i < 24; i++) {\
71 memcpy(jtba + i * 0x80, (char*)(*((int*)jem_trap_init_tbl[0])), (int)(*((int*)jem_trap_init_tbl[0])) - (int)(*((char*)jem_trap_init_tbl[1])));\
72 jam_printf("%04x\n", jtba + i * 0x80);\
75 //the JEM trap table entry will automatically jump here
76 #define DEFINE_JEM_TRAP_TABLE(lvl,label) \
77 HANDLER_TABLE_T *jem_trap_handlers_##lvl##_##label[JEM_TRAP_ENTRIES] = { \
78 &&do_dispatchTrap_##lvl,\
79 &&do_javaExceptions_##lvl,\
80 &&do_stackOverflow_##lvl,\
81 &&do_stackUnderflow_##lvl,\
82 &&do_stackOverflow1_##lvl,\
83 &&do_iaf_return_##lvl,\
84 &&do_return_##lvl,\
85 &&do_ld_return_##lvl,\
86 &&do_iinc_##lvl,\
87 &&do_checkcastQuick_##lvl,\
88 &&do_instanceofQuick_##lvl,\
89 &&do_getStatic_##lvl,\
90 &&do_putStatic_##lvl,\
91 &&do_new_##lvl,\
92 &&do_invokeStatic_##lvl,\
93 &&do_invokeInterfaceQuick_##lvl,\
94 &&do_invokeVirtualQuick_##lvl,\
95 &&do_invokeStaticQuick_##lvl,\
96 &&do_invokeNonVirtualQuick_##lvl,\
97 &&do_xNewArray_##lvl,\
98 &&do_longInstrps_##lvl,\
99 &&do_floatInstrps_##lvl,\
100 &&do_doubleInstrps_##lvl,\
101 &&do_otherInstrps_##lvl,\
105 * the param level here is in the same meaning with the software interpreter,because
106 * the trap handlers is implemented by invoking the corresponding opcode handlers
107 * TODO: software DISPATCH/handlers need be modified to be able to reenter to JEM mode.
108 * TODO: ? How to provent objects from GC while still in JEM execution ???
113 #define DEFINE_JEM_TRAP_TABLES(level) \
114 DEFINE_JEM_TRAP_TABLE(level,ENTRY)
117 #define DEF_DISPATCHTRAP(level) \
118 do_dispatchTrap_##level: \
119 __asm__ __volatile__( \
120 "mov %0,r10 \n" \
121 "mov %1,r11 \n" \
122 "mov %2,lr\n" \
123 "popm r0-r9,r11,r12,lr" \
124 :"=r"(jecr),"=r"(jep),"=r"(jpc)\
125 ::"r10","r11"\
126 ); \
127 goto *((int*)jem_trap_handlers_0_ENTRY[jep+1]);
129 #define DEF_JAVAEX(level) \
130 do_javaExceptions_##level: \
131 jam_printf("[Trap %d] java exceptions %d\n",jep,jecr);\
132 goto throwException;
134 #define DEF_STACKOVERFLOW(level) \
135 do_stackOverflow_##level:\
136 jam_printf("[Trap %d] stack overflow\n",jep);\
137 exitVM(1);
139 #define DEF_STACKUNDERFLOW(level) \
140 do_stackUnderflow_##level:\
141 jam_printf("[Trap %d] stack underflow\n",jep);\
142 exitVM(1);
144 #define DEF_STACKOVERFLOW1(level) \
145 do_stackOverflow1_##level:\
146 jam_printf("[Trap %d] stack overflow1\n",jep);\
147 exitVM(1);
149 #define DEF_STACKUNDERFLOW1(level) \
150 do_stackUnderflow1_##level: \
151 jam_printf("[Trap %d] stack underflow1\n",jep);\
152 exitVM(1);
154 #define DEF_IAFRETURN(level) \
155 do_iaf_return_##level: \
156 jam_printf("[Trap %d] executing [iaf]return %x\n",jep,jecr);\
157 goto *handlers_0_ENTRY[OPC_IRETURN];
159 #define DEF_RETURN(level) \
160 do_return_##level: \
161 jam_printf("[Trap %d] executing return %x\n",jep,jecr); \
162 goto *handlers_0_ENTRY[OPC_RETURN];
164 #define DEF_LDRETURN(level) \
165 do_ld_return_##level: \
166 jam_printf("[Trap %d] executing [ld] return %x\n",jep,jecr); \
167 goto *handlers_0_ENTRY[OPC_DRETURN];
169 #define DEF_IINC(level) \
170 do_iinc_##level: \
171 jam_printf("[Trap %d] executing iinc %x\n",jep,jecr); \
172 goto *handlers_0_ENTRY[OPC_IINC];
175 #define DEF_CHECKCASTQUICK(level) \
176 do_checkcastQuick_##level:\
177 jam_printf("[Trap %d] executing checkcastQuick %x\n",jep,jecr); \
178 goto *handlers_0_ENTRY[OPC_CHECKCAST_QUICK];
181 #define DEF_INSTANCEOFQUICK(level) \
182 do_instanceofQuick_##level:\
183 jam_printf("[Trap %d] executing instanceofQuick %x\n",jep,jecr); \
184 goto *handlers_0_ENTRY[OPC_INSTANCEOF_QUICK];
187 #define DEF_GETSTATIC(level) \
188 do_getStatic_##level:\
189 jam_printf("[Trap %d] executing getStatic %x\n",jep,jecr); \
190 goto *handlers_0_ENTRY[OPC_GETSTATIC];
193 #define DEF_PUTSTATIC(level) \
194 do_putStatic_##level:\
195 jam_printf("[Trap %d] executing putStatic %x\n",jep,jecr); \
196 goto *handlers_0_ENTRY[OPC_PUTSTATIC];
199 #define DEF_NEW(level)\
200 do_new_##level:\
201 jam_printf("[Trap %d] executing new %x\n",jep,jecr); \
202 goto *handlers_0_ENTRY[OPC_NEW];
205 #define DEF_INVOKESTATIC(level) \
206 do_invokeStatic_##level:\
207 jam_printf("[Trap %d] executing invokeStatic %x\n",jep,jecr); \
208 goto *handlers_0_ENTRY[OPC_INVOKESTATIC];
211 #define DEF_INVOKEINTERFACEQUICK(level) \
212 do_invokeInterfaceQuick_##level:\
213 jam_printf("[Trap %d] executing invokeInterfaceQuick %x\n",jep,jecr); \
214 goto *handlers_0_ENTRY[OPC_INVOKEINTERFACE_QUICK];
217 #define DEF_INVOKEVIRTUALQUICK(level) \
218 do_invokeVirtualQuick_##level:\
219 jam_printf("[Trap %d] executing invokeVirtualQuick %x\n",jep,jecr); \
220 goto *handlers_0_ENTRY[OPC_INVOKEVIRTUAL_QUICK];
223 #define DEF_INVOKESTATICQUICK(level) \
224 do_invokeStaticQuick_##level:\
225 jam_printf("[Trap %d] executing invokeStaticQuick %x\n",jep,jecr); \
226 goto *handlers_0_ENTRY[OPC_INVOKESTATIC_QUICK];
228 #define DEF_INVOKENONVIRTUALQUICK(level) \
229 do_invokeNonVirtualQuick_##level:\
230 jam_printf("[Trap %d] executing invokeNonVirtualQuick %x\n",jep,jecr); \
231 goto *handlers_0_ENTRY[OPC_INVOKENONVIRTUAL_QUICK];
234 #define DEF_XNEWARRAY(level) \
235 do_xNewArray_##level:\
236 jam_printf("[Trap %d] executing array %x\n",jep,jecr); \
237 exitVM(1);
240 #define DEF_LONGINSTRPS(level) \
241 do_longInstrps_##level:\
242 jam_printf("[Trap %d] executing long instrps %x\n",jep,jecr); \
243 exitVM(1);
245 #define DEF_FLOATINSTRPS(level) \
246 do_floatInstrps_##level:\
247 jam_printf("[Trap %d] executing float instrps %x\n",jep,jecr); \
248 exitVM(1);
250 #define DEF_DOUBLEINSTRPS(level) \
251 do_doubleInstrps_##level:\
252 jam_printf("[Trap %d] executing double instrps %x\n",jep,jecr); \
253 exitVM(1);
255 #define DEF_OTHERINSTRPS(level) \
256 do_otherInstrps_##level: \
257 jam_printf("[Trap %d] executing other instrps %x\n",jep,jecr); \
258 exitVM(1);
260 #endif
261 #endif /*INTERP_JEM_H_*/