JAVAINT.C 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. /* javaint.c: Copyright (C) Codemist Ltd., 1996. */
  2. #include <stdio.h>
  3. /* #include <stdlib.h> */
  4. #include <string.h>
  5. #include "machine.h"
  6. #include "tags.h"
  7. #include "cslerror.h"
  8. #include "externs.h"
  9. #include "read.h"
  10. #include "stream.h"
  11. #include "arith.h"
  12. #include "entries.h"
  13. #include "javahost.h"
  14. #include "javaops.h"
  15. #include "javaglb.h"
  16. /* integers representing exceptions (map to Java exceptions in javaint(). */
  17. #define E_NegativeArraySizeException 1
  18. #define E_OutOfMemoryError 2
  19. #define E_NullPointerException 3
  20. #define E_ArrayIndexOutOfBoundsException 4
  21. #define JSTK_MAX 10000
  22. #ifdef DOWNWARD_STACK /* need to fix up locals too! */
  23. #define push_(sp,v) (*--(sp)=(v))
  24. #define pop_(sp) (*(sp)++)
  25. #define lose_(sp,k) ((sp)+=(k))
  26. #define stk_(sp,k) ((sp)[k])
  27. #define STLO 0
  28. #define STHI 1
  29. #define loc_(lv,k) (*((lv)-(k)))
  30. #else
  31. #define push_(sp,v) (*++(sp)=(v))
  32. #define pop_(sp) (*(sp)--)
  33. #define lose_(sp,k) ((sp)-=(k))
  34. #define stk_(sp,k) (*((sp)-(k)))
  35. #define STLO 1
  36. #define STHI 0
  37. #define loc_(lv,k) ((lv)[k])
  38. #endif
  39. static void jraise(int E_whatever)
  40. { jsyserr("Exceptions unimplemented");
  41. }
  42. static int java_sizeof(int32 t)
  43. { switch (t)
  44. { default: jsyserr("bad type code to newarray()");
  45. case T_BOOLEAN: return 1;
  46. case T_CHAR: return 1;
  47. case T_FLOAT: return 4;
  48. case T_DOUBLE: return 8;
  49. case T_BYTE: return 1;
  50. case T_SHORT: return 2;
  51. case T_INT: return 4;
  52. case T_LONG: return 8;
  53. case -1: return 4; /* for anewarray */
  54. }
  55. }
  56. typedef struct JavaArray
  57. { unsigned32 length;
  58. /* access long/double by stream as maybe not aligned */
  59. union { int8 elts8[1]; unsigned8 eltu8[1];
  60. int16 elts16[1]; unsigned16 eltu16[1]; int32 elt32[1]; } u;
  61. } JavaArray;
  62. static int32 java_newarray(int32 *sp, int32 flavour, int32 refclass, int32 k)
  63. { /* Note that 'k' is (number of dimensions)-1. */
  64. /* Caller loses junk when k>0 (j_multinewarray). */
  65. /* k>0 not supported yet. */
  66. JavaArray *res;
  67. int32 nelts = stk_(sp,0), csize;
  68. if (nelts < 0) return E_NegativeArraySizeException;
  69. csize = java_sizeof(flavour)*nelts + sizeof(int32);
  70. res = (JavaArray *)jmalloc(csize);
  71. if (res == 0) return E_OutOfMemoryError;
  72. memset(res, 0, csize); /* @@@ beware 0 = HR_NULL assumed! */
  73. res->length = nelts;
  74. stk_(sp,k) = (int32)res; /*ALPHA*/
  75. return 0;
  76. }
  77. /* beware host/java rep issues here */
  78. #define HR_NULL 0 /* Host Representation? */
  79. static const union { struct { double d[2]; float f[3]; } s;
  80. int32 r[7];
  81. } hostflttab = { 0.0, 1.0, 0.0f, 1.0f, 2.0f };
  82. /* Remember many of the following are zero (optimise?) */
  83. #define HR_D0W1 hostflttab.r[0]
  84. #define HR_D0W2 hostflttab.r[1]
  85. #define HR_D1W1 hostflttab.r[2]
  86. #define HR_D1W2 hostflttab.r[3]
  87. #define HR_F0 hostflttab.r[4]
  88. #define HR_F1 hostflttab.r[5]
  89. #define HR_F2 hostflttab.r[6]
  90. typedef union DbleRep { int32 irep[2]; double d; } DbleRep;
  91. /* Some of the following optimise if we know double's only need to be */
  92. /* 32-bit aligned. */
  93. static int32 *sim_i2d(int32 *sp)
  94. { DbleRep u;
  95. u.d = (double)stk_(sp,0);
  96. stk_(sp,0) = u.irep[STHI];
  97. push_(sp, u.irep[STLO]);
  98. return sp;
  99. }
  100. static int32 *sim_d2i(int32 *sp)
  101. { DbleRep u;
  102. u.irep[STLO] = pop_(sp);
  103. u.irep[STHI] = stk_(sp,0);
  104. stk_(sp,0) = (int32)u.d;
  105. return sp;
  106. }
  107. static int32 *sim_l2d(int32 *sp) { jsyserr("l2d"); return sp;}
  108. static int32 *sim_d2l(int32 *sp) { jsyserr("d2l"); return sp;}
  109. static int32 *sim_f2l(int32 *sp) { jsyserr("f2l"); lose_(sp,1); return sp;}
  110. static int32 *sim_l2f(int32 *sp) { jsyserr("l2f"); push_(sp,0); return sp;}
  111. static int32 *sim_f2d(int32 *sp)
  112. { DbleRep u;
  113. u.d = (double)stk_((float *)sp,0);
  114. stk_(sp,0) = u.irep[STHI];
  115. push_(sp, u.irep[STLO]);
  116. return sp;
  117. }
  118. static int32 *sim_d2f(int32 *sp)
  119. { DbleRep u;
  120. u.irep[STLO] = pop_(sp);
  121. u.irep[STHI] = stk_(sp,0);
  122. stk_((float *)sp,0) = (float)u.d;
  123. return sp;
  124. }
  125. static Code_Attribute *findcodeattr(Attribute_Info *v, unsigned32 n)
  126. { int i;
  127. for (i = 0; i<n; i++)
  128. if (v[i].sort == ATT_Code)
  129. return v[i].uattr.code;
  130. return 0;
  131. }
  132. #define case3(a,b,c) case a: case b: case c
  133. #define case2(a,b) case a: case b
  134. void javaint(ClassFile *cf)
  135. {
  136. int32 *sp, *lv;
  137. int32 *spbase;
  138. int8 *pc; /* @@@ */
  139. Cp_Info *cp; /* litpool */ /* @@@ init */
  140. int32 t1, t2, t3; /* make more local? */
  141. int32 pb; /* beware live round main loop (see j_wide) */
  142. int32 sv; /* stack val */
  143. JavaArray *sv_qua_array;
  144. int32 ao; /* array index (tidy?) */
  145. int32 op;
  146. int32 r1,r2;
  147. unsigned32 r1u;
  148. lv = (int32 *)jmalloc(JSTK_MAX * sizeof(*sp));
  149. loc_(lv,0) = HR_NULL; /* arg[] */
  150. sp = lv;
  151. spbase = lv+1; /* !DOWNWARD_STACK */
  152. /* Provisional placing of following block (maybe share with 'invoke'). */
  153. cp = cf->constant_pool;
  154. { int i;
  155. for (i = 0; i < cf->methods_count; i++)
  156. { unsigned32 n = cf->methods[i].name_index;
  157. if (0 < n && n < cf->constant_pool_count &&
  158. cp[n].tag == CONSTANT_Utf8 &&
  159. memcmp(cp[n].u.utf8, "main", 4) == 0)
  160. { Code_Attribute *p = findcodeattr(cf->methods[i].attributes,
  161. cf->methods[i].attributes_count);
  162. if (p == 0) jsyserr("no code for main");
  163. pc = (int8 *)p->code; goto foundmain;
  164. }
  165. }
  166. jsyserr("no main()");
  167. return;
  168. }
  169. foundmain:
  170. jdebug("Execution...");
  171. #define u8i_(pc) (*(pc)++ & 255)
  172. #define s8i_(pc) (*(pc)++)
  173. #define s16i_(pc) (t1 = s8i_(pc), t1<<8 | u8i_(pc))
  174. #define u16i_(pc) (t1 = u8i_(pc), t1<<8 | u8i_(pc))
  175. #define s32i_(pc) (t1 = s8i_(pc), t1 = t1<<8 | u8i_(pc), \
  176. t1 = t1<<8 | u8i_(pc), t1<<8 | u8i_(pc))
  177. #define cp_maybe_string_(d) \
  178. (cp[d].tag == CONSTANT_String ? cp[cp[d].u.val].u.val : cp[d].u.val)
  179. #define cp1_(d) (cp[d].u.val)
  180. #define cp2_(d) (cp[(d)+1].u.val)
  181. for (pb = 0;;) switch (jdebug("trace %d", op = u8i_(pc)), op)
  182. {
  183. default: jsyserr("Illegal java op %d/%s", op, jdecodeopname(op));
  184. break;
  185. unimp: jsyserr("Unimplemented java op %d/%s", op, jdecodeopname(op));
  186. break;
  187. case j_bipush: push_(sp, s8i_(pc)); break;
  188. case j_sipush: push_(sp, s16i_(pc)); break;
  189. case j_ldc1: t2 = u8i_(pc); push_(sp, cp_maybe_string_(t2)); break;
  190. case j_ldc2: t2 = u16i_(pc); push_(sp, cp_maybe_string_(t2)); break;
  191. case j_ldc2w: t2 = u16i_(pc); push_(sp, cp1_(t2)); push_(sp, cp2_(t2)); break;
  192. case j_aconst_null: push_(sp, HR_NULL); break;
  193. case j_iconst_m1: push_(sp, -1); break;
  194. case j_iconst_0: push_(sp, 0); break;
  195. case j_iconst_1: push_(sp, 1); break;
  196. case j_iconst_2: push_(sp, 2); break;
  197. case j_iconst_3: push_(sp, 3); break;
  198. case j_iconst_4: push_(sp, 4); break;
  199. case j_iconst_5: push_(sp, 5); break;
  200. case j_lconst_0: push_(sp, 0); push_(sp, 0); break;
  201. case j_lconst_1: push_(sp, 0); push_(sp, 0); break;
  202. case j_fconst_0: push_(sp, HR_F0); break;
  203. case j_fconst_1: push_(sp, HR_F1); break;
  204. case j_fconst_2: push_(sp, HR_F2); break;
  205. case j_dconst_0: push_(sp, HR_D0W1); push_(sp, HR_D0W2); break;
  206. case j_dconst_1: push_(sp, HR_D1W1); push_(sp, HR_D1W2); break;
  207. case3(j_iload,j_fload,j_aload):
  208. push_(sp, loc_(lv,pb+u8i_(pc))); pb = 0; break;
  209. case3(j_iload_0,j_fload_0,j_aload_0): push_(sp, loc_(lv,0)); break;
  210. case3(j_iload_1,j_fload_1,j_aload_1): push_(sp, loc_(lv,1)); break;
  211. case3(j_iload_2,j_fload_2,j_aload_2): push_(sp, loc_(lv,2)); break;
  212. case3(j_iload_3,j_fload_3,j_aload_3): push_(sp, loc_(lv,3)); break;
  213. /* Could use sv1,sv2 if lots of registers on my target. */
  214. case2(j_lload,j_dload): pb += u8i_(pc); /* STHI, STLO */
  215. sv = loc_(lv, pb+0); push_(sp, sv);
  216. sv = loc_(lv, pb+1); push_(sp, sv); pb = 0; break;
  217. case2(j_lload_0,j_dload_0): push_(sp, loc_(lv,0)); push_(sp, loc_(lv,1)); break;
  218. case2(j_lload_1,j_dload_1): push_(sp, loc_(lv,1)); push_(sp, loc_(lv,2)); break;
  219. case2(j_lload_2,j_dload_2): push_(sp, loc_(lv,2)); push_(sp, loc_(lv,3)); break;
  220. case2(j_lload_3,j_dload_3): push_(sp, loc_(lv,3)); push_(sp, loc_(lv,4)); break;
  221. case3(j_istore,j_fstore,j_astore):
  222. loc_(lv, pb+u8i_(pc)) = pop_(sp); pb = 0; break;
  223. case3(j_istore_0,j_fstore_0,j_astore_0): loc_(lv,0) = pop_(sp); break;
  224. case3(j_istore_1,j_fstore_1,j_astore_1): loc_(lv,1) = pop_(sp); break;
  225. case3(j_istore_2,j_fstore_2,j_astore_2): loc_(lv,2) = pop_(sp); break;
  226. case3(j_istore_3,j_fstore_3,j_astore_3): loc_(lv,3) = pop_(sp); break;
  227. /* Could use sv1,sv2 if lots of registers on my target. */
  228. case2(j_lstore,j_dstore): pb += u8i_(pc); /* STHI, STLO */
  229. sv = pop_(sp); loc_(lv, pb+1) = sv;
  230. sv = pop_(sp); loc_(lv, pb+0) = sv; pb = 0; break;
  231. case2(j_lstore_0,j_dstore_0): loc_(lv,1)=pop_(sp); loc_(lv,0)=pop_(sp); break;
  232. case2(j_lstore_1,j_dstore_1): loc_(lv,2)=pop_(sp); loc_(lv,1)=pop_(sp); break;
  233. case2(j_lstore_2,j_dstore_2): loc_(lv,3)=pop_(sp); loc_(lv,2)=pop_(sp); break;
  234. case2(j_lstore_3,j_dstore_3): loc_(lv,4)=pop_(sp); loc_(lv,3)=pop_(sp); break;
  235. case j_iinc: pb += u8i_(pc); loc_(lv, pb) += s8i_(pc); pb = 0; break;
  236. case j_wide: pb = u8i_(pc) << 8; break;
  237. case j_newarray: if ((t1 = java_newarray(sp, u8i_(pc), 0, 0)) != 0)
  238. { jraise(t1);
  239. }
  240. break;
  241. case j_anewarray: t2 = u16i_(pc);
  242. if ((t1 = java_newarray(sp, -1, cp1_(t2), 0)) != 0)
  243. { jraise(t1);
  244. }
  245. break;
  246. case j_multinewarray: t2 = u16i_(pc); t3 = u8i_(pc)-1;
  247. t1 = java_newarray(sp, -1, cp1_(t2), t3);
  248. sp += t3;
  249. if (t1 != 0)
  250. { jraise(t1);
  251. }
  252. break;
  253. case j_arraylength:
  254. if ((sv_qua_array = (JavaArray *)stk_(sp,0)) == HR_NULL) /*ALPHA*/
  255. { jraise(E_NullPointerException);
  256. }
  257. stk_(sp,0) = sv_qua_array->length;
  258. break;
  259. case3(j_iaload,j_faload,j_aaload):
  260. ao = pop_(sp);
  261. if ((sv_qua_array = (JavaArray *)stk_(sp,0)) == HR_NULL) /*ALPHA*/
  262. { jraise(E_NullPointerException);
  263. }
  264. if ((unsigned32)ao >= sv_qua_array->length)
  265. { jraise(E_ArrayIndexOutOfBoundsException);
  266. }
  267. stk_(sp,0) = sv_qua_array->u.elt32[ao];
  268. break;
  269. case2(j_laload,j_daload):
  270. ao = pop_(sp);
  271. if ((sv_qua_array = (JavaArray *)stk_(sp,0)) == HR_NULL) /*ALPHA*/
  272. { jraise(E_NullPointerException);
  273. }
  274. if ((unsigned32)ao >= sv_qua_array->length)
  275. { jraise(E_ArrayIndexOutOfBoundsException);
  276. }
  277. stk_(sp,0) = sv_qua_array->u.elt32[2*ao+STHI];
  278. push_(sp, sv_qua_array->u.elt32[2*ao+STLO]);
  279. break;
  280. case j_baload: ao = pop_(sp);
  281. if ((sv_qua_array = (JavaArray *)stk_(sp,0)) == HR_NULL) /*ALPHA*/
  282. { jraise(E_NullPointerException);
  283. }
  284. if ((unsigned32)ao >= sv_qua_array->length)
  285. { jraise(E_ArrayIndexOutOfBoundsException);
  286. }
  287. stk_(sp,0) = sv_qua_array->u.elts8[ao];
  288. break;
  289. case j_caload: ao = pop_(sp);
  290. if ((sv_qua_array = (JavaArray *)stk_(sp,0)) == HR_NULL) /*ALPHA*/
  291. { jraise(E_NullPointerException);
  292. }
  293. if ((unsigned32)ao >= sv_qua_array->length)
  294. { jraise(E_ArrayIndexOutOfBoundsException);
  295. }
  296. stk_(sp,0) = sv_qua_array->u.eltu16[ao];
  297. break;
  298. case j_saload: ao = pop_(sp);
  299. if ((sv_qua_array = (JavaArray *)stk_(sp,0)) == HR_NULL) /*ALPHA*/
  300. { jraise(E_NullPointerException);
  301. }
  302. if ((unsigned32)ao >= sv_qua_array->length)
  303. { jraise(E_ArrayIndexOutOfBoundsException);
  304. }
  305. stk_(sp,0) = sv_qua_array->u.elts16[ao];
  306. break;
  307. case3(j_iastore,j_fastore,j_aastore):
  308. if ((sv_qua_array = (JavaArray *)stk_(sp,2)) == HR_NULL) /*ALPHA*/
  309. { jraise(E_NullPointerException);
  310. }
  311. if ((unsigned32)(ao = stk_(sp,1)) >= sv_qua_array->length)
  312. { jraise(E_ArrayIndexOutOfBoundsException);
  313. }
  314. sv_qua_array->u.elt32[ao] = stk_(sp,0);
  315. lose_(sp,3);
  316. break;
  317. case2(j_lastore,j_dastore):
  318. if ((sv_qua_array = (JavaArray *)stk_(sp,3)) == HR_NULL) /*ALPHA*/
  319. { jraise(E_NullPointerException);
  320. }
  321. if ((unsigned32)(ao = stk_(sp,2)) >= sv_qua_array->length)
  322. { jraise(E_ArrayIndexOutOfBoundsException);
  323. }
  324. sv_qua_array->u.elt32[2*ao+STLO] = stk_(sp,0);
  325. sv_qua_array->u.elt32[2*ao+STHI] = stk_(sp,1);
  326. lose_(sp,4);
  327. break;
  328. case j_bastore:
  329. if ((sv_qua_array = (JavaArray *)stk_(sp,2)) == HR_NULL) /*ALPHA*/
  330. { jraise(E_NullPointerException);
  331. }
  332. if ((unsigned32)(ao = stk_(sp,1)) >= sv_qua_array->length)
  333. { jraise(E_ArrayIndexOutOfBoundsException);
  334. }
  335. sv_qua_array->u.eltu8[ao] = stk_(sp,0);
  336. lose_(sp,3);
  337. break;
  338. case2(j_sastore,j_castore):
  339. if ((sv_qua_array = (JavaArray *)stk_(sp,2)) == HR_NULL) /*ALPHA*/
  340. { jraise(E_NullPointerException);
  341. }
  342. if ((unsigned32)(ao = stk_(sp,1)) >= sv_qua_array->length)
  343. { jraise(E_ArrayIndexOutOfBoundsException);
  344. }
  345. sv_qua_array->u.eltu16[ao] = stk_(sp,0);
  346. lose_(sp,3);
  347. break;
  348. case j_nop: break;
  349. case j_pop: lose_(sp,1); break;
  350. case j_pop2: lose_(sp,2); break;
  351. case j_dup: sv = stk_(sp, 0); push_(sp, sv); break;
  352. case j_dup2: sv = stk_(sp, 1); push_(sp, sv);
  353. sv = stk_(sp, 1); push_(sp, sv); break;
  354. case j_dup_x1: sv = stk_(sp, 0); stk_(sp, 0) = stk_(sp, 1);
  355. stk_(sp, 1) = sv; push_(sp, sv); break;
  356. case j_dup2_x1: r1 = stk_(sp, 0); r2 = stk_(sp, 1); stk_(sp,0) = stk_(sp,2);
  357. stk_(sp,1) = r1; stk_(sp,2) = r2; push_(sp, r2); push_(sp,r1);
  358. break;
  359. case j_dup_x2: sv = stk_(sp, 0); push_(sp, sv); stk_(sp,1) = stk_(sp,2);
  360. stk_(sp,2) = stk_(sp,3); stk_(sp,3) = sv; break;
  361. case j_dup2_x2: sv = stk_(sp, 1); push_(sp, sv); stk_(sp,2) = stk_(sp,4);
  362. stk_(sp,4) = sv;
  363. sv = stk_(sp, 1); push_(sp, sv); stk_(sp,2) = stk_(sp,4);
  364. stk_(sp,4) = sv; break;
  365. case j_swap: sv = stk_(sp, 0); stk_(sp, 0) = stk_(sp, 1);
  366. stk_(sp, 1) = sv; break;
  367. case j_iadd: r1 = pop_(sp); stk_(sp,0) += r1; break;
  368. case j_ladd: goto unimp;
  369. case j_fadd: goto unimp;
  370. case j_dadd: goto unimp;
  371. case j_isub: r1 = pop_(sp); stk_(sp,0) -= r1; break;
  372. case j_lsub: goto unimp;
  373. case j_fsub: goto unimp;
  374. case j_dsub: goto unimp;
  375. case j_imul: r1 = pop_(sp); stk_(sp,0) *= r1; break;
  376. case j_lmul: goto unimp;
  377. case j_fmul: goto unimp;
  378. case j_dmul: goto unimp;
  379. case j_idiv: r1 = pop_(sp); stk_(sp,0) /= r1; break;
  380. case j_ldiv: goto unimp;
  381. case j_fdiv: goto unimp;
  382. case j_ddiv: goto unimp;
  383. case j_irem: r1 = pop_(sp); stk_(sp,0) %= r1; break;
  384. case j_lrem: goto unimp;
  385. case j_frem: goto unimp;
  386. case j_drem: goto unimp;
  387. case j_ineg: stk_(sp,0) = -stk_(sp,0); break;
  388. case j_lneg: goto unimp;
  389. case j_fneg: goto unimp;
  390. case j_dneg: goto unimp;
  391. case j_ishl: r1 = pop_(sp); stk_(sp,0) <<= r1&31; break;
  392. #ifdef HOST_SHIFT_SIGNED
  393. case j_ishr: r1 = pop_(sp); stk_(sp,0) >>= r1&31; break;
  394. #else
  395. case j_ishr: goto unimp;
  396. #endif
  397. case j_iushr: r1 = pop_(sp); stk_(sp,0) = (unsigned32)stk_(sp,0) >> r1&31; break;
  398. case j_lshl: goto unimp;
  399. case j_lshr: goto unimp;
  400. case j_lushr: goto unimp;
  401. case j_iand: r1 = pop_(sp); stk_(sp,0) &= r1; break;
  402. case j_land: stk_(sp,2) &= stk_(sp,0); stk_(sp,3) &= stk_(sp,1);
  403. lose_(sp,2); break;
  404. case j_ior: r1 = pop_(sp); stk_(sp,0) |= r1; break;
  405. case j_lor: stk_(sp,2) |= stk_(sp,0); stk_(sp,3) |= stk_(sp,1);
  406. lose_(sp,2); break;
  407. case j_ixor: r1 = pop_(sp); stk_(sp,0) ^= r1; break;
  408. case j_lxor: stk_(sp,2) ^= stk_(sp,0); stk_(sp,3) ^= stk_(sp,1);
  409. lose_(sp,2); break;
  410. case j_i2l: r1u = stk_(sp,0); push_(sp, -(r1u >> 31)); break;
  411. case j_i2f: stk_((float *)sp,0) = (float)stk_(sp,0); break;
  412. case j_i2d: sp = sim_i2d(sp); break;
  413. case j_l2i: lose_(sp,1); break;
  414. case j_l2f: sp = sim_l2f(sp); break;
  415. case j_l2d: sp = sim_l2d(sp); break;
  416. case j_f2i: stk_(sp,0) = (int32)stk_((float *)sp,0); break;
  417. case j_f2l: sp = sim_f2l(sp); break;
  418. case j_f2d: sp = sim_f2d(sp); break;
  419. case j_d2i: sp = sim_d2i(sp); break;
  420. case j_d2l: sp = sim_d2l(sp); break;
  421. case j_d2f: sp = sim_d2f(sp); break;
  422. #define signext_(w,n) ((((w) & (1<<n)-1) ^ (1<<n-1)) - (1<<n-1))
  423. case j_int2byte: stk_(sp,0) = signext_(stk_(sp,0), 8); break;
  424. case j_int2char: stk_(sp,0) = stk_(sp,0) & 0xffff; break;
  425. case j_int2short: stk_(sp,0) = signext_(stk_(sp,0), 16); break;
  426. #define condbr(TEST) t2 = s16i_(pc); if (TEST) pc += t2-3
  427. case j_ifeq: condbr(pop_(sp) == 0); break;
  428. case j_ifnull: condbr(pop_(sp) == HR_NULL); break;
  429. case j_iflt: condbr(pop_(sp) < 0); break;
  430. case j_ifle: condbr(pop_(sp) <= 0); break;
  431. case j_ifne: condbr(pop_(sp) != 0); break;
  432. case j_ifnonnull: condbr(pop_(sp) != HR_NULL); break;
  433. case j_ifgt: condbr(pop_(sp) > 0); break;
  434. case j_ifge: condbr(pop_(sp) >= 0); break;
  435. case j_if_icmpeq: sv = pop_(sp); condbr(pop_(sp) == sv); break;
  436. case j_if_icmpne: sv = pop_(sp); condbr(pop_(sp) != sv); break;
  437. case j_if_icmplt: sv = pop_(sp); condbr(pop_(sp) < sv); break;
  438. case j_if_icmpgt: sv = pop_(sp); condbr(pop_(sp) > sv); break;
  439. case j_if_icmple: sv = pop_(sp); condbr(pop_(sp) <= sv); break;
  440. case j_if_icmpge: sv = pop_(sp); condbr(pop_(sp) >= sv); break;
  441. case j_lcmp:
  442. case j_fcmpl:
  443. case j_fcmpg:
  444. case j_dcmpl:
  445. case j_dcmpg:
  446. case j_if_acmpeq:
  447. case j_if_acmpne:
  448. case j_goto: t2 = s16i_(pc); pc += t2-3; break;
  449. case j_goto_w: t2 = s32i_(pc); pc += t2-5; break;
  450. case j_jsr: t2 = s16i_(pc); push_(sp,(int32)pc); pc += t2-3; break; /*ALPHA*/
  451. case j_jsr_w: t2 = s32i_(pc); push_(sp,(int32)pc); pc += t2-5; break; /*ALPHA*/
  452. case j_ret: t2 = u8i_(pc); pc = (int8 *)stk_(sp, t2); break; /*ALPHA*/
  453. case j_ret_w: t2 = u16i_(pc); pc = (int8 *)stk_(sp, t2); break; /*ALPHA*/
  454. case j_ireturn:
  455. case j_lreturn:
  456. case j_freturn:
  457. case j_dreturn:
  458. case j_areturn:
  459. case j_return:
  460. case j_breakpoint:
  461. case j_tableswitch:
  462. case j_lookupswitch:
  463. case j_putfield: goto unimp;
  464. case j_getfield:
  465. if ((sv_qua_array = (JavaArray *)stk_(sp,0)) == HR_NULL) /*ALPHA*/
  466. { jraise(E_NullPointerException);
  467. }
  468. case j_putstatic: goto unimp;
  469. case j_getstatic: t2 = u16i_(pc);
  470. push_(sp, (int32)&java_PrintStream); /* @@@ */
  471. break; /* @@@ */
  472. case j_invokevirtual: t2 = u16i_(pc);
  473. cf = (ClassFile *)*spbase;
  474. if (cf != &java_PrintStream)
  475. jsyserr("invokevirtual");
  476. if (cf->methods_count == 1 && /* @@@ */
  477. cf->methods[0].access_flags & ACC_NATIVE)
  478. { sp = ((JavaBuiltin)(cf->methods[0].attributes))(spbase);
  479. }
  480. else
  481. { lv = spbase;
  482. spbase = sp+1;
  483. goto unimp;
  484. }
  485. break;
  486. case j_invokenonvirtual: goto unimp;
  487. case j_invokestatic: goto unimp;
  488. case j_invokeinterface: goto unimp;
  489. case j_athrow: goto unimp;
  490. case j_new: t2 = u16i_(pc);
  491. term_printf("NEW %d %d %.8x\n",
  492. t2, cp[t2].tag, cp_maybe_string_(t2));
  493. goto unimp;
  494. case j_checkcast: goto unimp;
  495. case j_instanceof: goto unimp;
  496. case j_monitorenter: goto unimp;
  497. case j_monitorexit: goto unimp;
  498. }
  499. }
  500.