text.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. Accessing the program text
  3. */
  4. /* $Id$ */
  5. #define text_loc(a) (*(text + (p2i(a))))
  6. /* The bytes in the text segment are unsigned, and this is what is
  7. implemented by the macros btol() and btou(). Some operands,
  8. however, are signed; this is indicated in the table by P or N.
  9. When an operand is positive, it is guaranteed that the leftmost
  10. bit is 0, so we can get the value by doing sign extension. Likewise,
  11. when the operand is negative the leftmost bit will be 1 and again sign
  12. extension yields the right value.
  13. Actually we should test if this guarantee is indeed upheld, but that
  14. is just too expensive.
  15. */
  16. /* Reading the opcode.
  17. */
  18. #define nextPCbyte() (PC+=1, btou(text_loc(PC-1)))
  19. /* Shortie arguments consist of the high order value, derived from
  20. the opcode and passed as a parameter, and the following byte.
  21. */
  22. #define S_arg(h) (PC+=1, ((h)<<8) + btol(text_loc(PC-1)))
  23. /* Two-byte arguments consist of the following two bytes.
  24. */
  25. #define L_arg_2() (PC+=2, (btol(text_loc(PC-1)) | \
  26. (btos(text_loc(PC-2)) << 8)))
  27. #define P_arg_2() (PC+=2, (btol(text_loc(PC-1)) | \
  28. (btos(text_loc(PC-2)) << 8)))/* should test */
  29. #define N_arg_2() (PC+=2, (btol(text_loc(PC-1)) | \
  30. (btos(text_loc(PC-2)) << 8)))/* should test */
  31. #define U_arg() (PC+=2, (btol(text_loc(PC-1)) | \
  32. (btol(text_loc(PC-2)) << 8)))
  33. /* The L-, P-, and N-4-bytes #defines are all equal, because
  34. we assume our longs to be 4 bytes long.
  35. */
  36. #define L_arg_4() (PC+=4, (btol(text_loc(PC-1)) | \
  37. (btol(text_loc(PC-2)) << 8) | \
  38. (btol(text_loc(PC-3)) << 16) | \
  39. (btos(text_loc(PC-4)) << 24)))
  40. #define P_arg_4() (PC+=4, (btol(text_loc(PC-1)) | \
  41. (btol(text_loc(PC-2)) << 8) | \
  42. (btol(text_loc(PC-3)) << 16) | \
  43. (btos(text_loc(PC-4)) << 24)))/* should test */
  44. #define N_arg_4() (PC+=4, (btol(text_loc(PC-1)) | \
  45. (btol(text_loc(PC-2)) << 8) | \
  46. (btol(text_loc(PC-3)) << 16) | \
  47. (btos(text_loc(PC-4)) << 24)))/* should test */
  48. /*
  49. * #defines for argument checks.
  50. */
  51. #define arg_c(n) ((n < i_minsw || n > i_maxsw) ? \
  52. (wtrap(WARGC, EILLINS), 0) : n)
  53. #define arg_d(n) ((wsize > 2) ? (wtrap(WARGD, EILLINS), 0) : n)
  54. #define arg_l(n) ((n < min_off || n > max_off) ? \
  55. (wtrap(WARGL, EILLINS), 0) : n)
  56. #define arg_g(p) ((p >= HB) ? (wtrap(WARGG, EILLINS), i2p(0)) : p)
  57. #define arg_f(n) ((n < min_off || n > max_off) ? \
  58. (wtrap(WARGF, EILLINS), 0) : n)
  59. #define arg_n(u) ((u > i_maxuw) ? (wtrap(WARGL, EILLINS), 0) : u)
  60. #define arg_s(s) ((s <= 0 || s > max_off || (s & wsizem1)) ? \
  61. (trap(EODDZ), s) : s)
  62. #define arg_z(s) ((s < 0 || s > max_off || (s & wsizem1)) ? \
  63. (trap(EODDZ), s) : s)
  64. #define arg_o(s) ((s < 0 || s > max_off || ((s&wsizem1) && wsize%s)) ? \
  65. (trap(EODDZ), s) : s)
  66. #define arg_w(s) ((s <= 0 || s > max_off || (s & wsizem1)) ? \
  67. (trap(EODDZ), s) : s)
  68. #define arg_p(l) ((l >= NProc) ? (wtrap(WARGP, EILLINS), 0) : l)
  69. #define arg_r(n) ((n < 0 || n > 2) ? (wtrap(WARGR, EILLINS), 0) : n)
  70. /* tests on widths */
  71. #define arg_wn(s) ((s != 1 && s != 2 && s != 4) ? \
  72. (trap(EODDZ), s) : s)
  73. #define arg_wf(s) ((s != 4 && s != 8) ? (trap(EODDZ), s) : s)
  74. #define arg_wi(s) (((s != 2 && s != 4) || (s & wsizem1)) ? \
  75. (trap(EODDZ), s) : s)
  76. /* special tests */
  77. #define arg_lae(p) ((p > ML) ? (trap(EBADLAE), p) : p)
  78. #define arg_gto(p) ((p>=HB) ? (wtrap(WGTOSTACK, EBADGTO), p) : p)
  79. #define arg_lin(u) ((u > NLINE) ? (trap(EBADLIN), u) : u)