cpubase.pas 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. {
  2. Copyright (c) 2010 by Jonas Maebe
  3. Contains the base types for the Java VM
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. { This Unit contains the base types for the Java Virtual Machine
  18. }
  19. unit cpubase;
  20. {$i fpcdefs.inc}
  21. interface
  22. uses
  23. globtype,
  24. aasmbase,cpuinfo,cgbase;
  25. {*****************************************************************************
  26. Assembler Opcodes
  27. *****************************************************************************}
  28. type
  29. TAsmOp=(A_None,
  30. a_aaload, a_aastore, a_aconst_null,
  31. a_aload, a_aload_0, a_aload_1, a_aload_2, a_aload_3,
  32. a_anewarray, a_areturn, a_arraylength,
  33. a_astore, a_astore_0, a_astore_1, a_astore_2, a_astore_3,
  34. a_athrow, a_baload, a_bastore, a_bipush, a_breakpoint,
  35. a_caload, a_castore, a_checkcast,
  36. a_d2f, a_d2i, a_d2l, a_dadd, a_daload, a_dastore, a_dcmpg, a_dcmpl,
  37. a_dconst_0, a_dconst_1, a_ddiv,
  38. a_dload, a_dload_0, a_dload_1, a_dload_2, a_dload_3,
  39. a_dmul, a_dneg, a_drem, a_dreturn,
  40. a_dstore, a_dstore_0, a_dstore_1, a_dstore_2, a_dstore_3,
  41. a_dsub,
  42. a_dup, a_dup2, a_dup2_x1, a_dup2_x2, a_dup_x1, a_dup_x2,
  43. a_f2d, a_f2i, a_f2l, a_fadd, a_faload, a_fastore, a_fcmpg, a_fcmpl,
  44. a_fconst_0, a_fconst_1, a_fconst_2, a_fdiv,
  45. a_fload, a_fload_0, a_fload_1, a_fload_2, a_fload_3,
  46. a_fmul, a_fneg, a_frem, a_freturn,
  47. a_fstore, a_fstore_0, a_fstore_1, a_fstore_2, a_fstore_3,
  48. a_fsub,
  49. a_getfield, a_getstatic,
  50. a_goto, a_goto_w,
  51. a_i2b, a_i2c, a_i2d, a_i2f, a_i2l, a_i2s,
  52. a_iadd, a_iaload, a_iand, a_iastore,
  53. a_iconst_m1, a_iconst_0, a_iconst_1, a_iconst_2, a_iconst_3,
  54. a_iconst_4, a_iconst_5,
  55. a_idiv,
  56. a_if_acmpeq, a_if_acmpne, a_if_icmpeq, a_if_icmpge, a_if_icmpgt,
  57. a_if_icmple, a_if_icmplt, a_if_icmpne,
  58. a_ifeq, a_ifge, a_ifgt, a_ifle, a_iflt, a_ifne, a_ifnonnull, a_ifnull,
  59. a_iinc,
  60. a_iload, a_iload_0, a_iload_1, a_iload_2, a_iload_3,
  61. a_imul, a_ineg,
  62. a_instanceof,
  63. a_invokeinterface, a_invokespecial, a_invokestatic, a_invokevirtual,
  64. a_ior, a_irem, a_ireturn, a_ishl, a_ishr,
  65. a_istore, a_istore_0, a_istore_1, a_istore_2, a_istore_3,
  66. a_isub, a_iushr, a_ixor,
  67. a_jsr, a_jsr_w,
  68. a_l2d, a_l2f, a_l2i, a_ladd, a_laload, a_land, a_lastore, a_lcmp,
  69. a_lconst_0, a_lconst_1,
  70. a_ldc, a_ldc2_w, a_ldc_w, a_ldiv,
  71. a_lload, a_lload_0, a_lload_1, a_lload_2, a_lload_3,
  72. a_lmul, a_lneg,
  73. a_lookupswitch,
  74. a_lor, a_lrem,
  75. a_lreturn,
  76. a_lshl, a_lshr,
  77. a_lstore, a_lstore_0, a_lstore_1, a_lstore_2, a_lstore_3,
  78. a_lsub, a_lushr, a_lxor,
  79. a_monitorenter,
  80. a_monitorexit,
  81. a_multianewarray,
  82. a_new,
  83. a_newarray,
  84. a_nop,
  85. a_pop, a_pop2,
  86. a_putfield, a_putstatic,
  87. a_ret, a_return,
  88. a_saload, a_sastore, a_sipush,
  89. a_swap,
  90. a_tableswitch,
  91. a_wide
  92. );
  93. {# This should define the array of instructions as string }
  94. op2strtable=array[tasmop] of string[8];
  95. Const
  96. {# First value of opcode enumeration }
  97. firstop = low(tasmop);
  98. {# Last value of opcode enumeration }
  99. lastop = high(tasmop);
  100. {*****************************************************************************
  101. Registers
  102. *****************************************************************************}
  103. type
  104. { Number of registers used for indexing in tables }
  105. tregisterindex=0..{$i rjvmnor.inc}-1;
  106. const
  107. { Available Superregisters }
  108. {$i rjvmsup.inc}
  109. { No Subregisters }
  110. R_SUBWHOLE = R_SUBNONE;
  111. { Available Registers }
  112. {$i rjvmcon.inc}
  113. { aliases }
  114. { used as base register in references for parameters passed to
  115. subroutines: these are passed on the evaluation stack, but this way we
  116. can use the offset field to indicate the order, which is used by ncal
  117. to sort the parameters }
  118. NR_EVAL_STACK_BASE = NR_R0;
  119. maxvarregs = 1;
  120. maxfpuvarregs = 1;
  121. { Integer Super registers first and last }
  122. first_int_imreg = 2;
  123. { Float Super register first and last }
  124. first_fpu_imreg = 2;
  125. { MM Super register first and last }
  126. first_mm_imreg = 2;
  127. regnumber_table : array[tregisterindex] of tregister = (
  128. {$i rjvmnum.inc}
  129. );
  130. EVALSTACKLOCS = [LOC_REGISTER,LOC_CREGISTER,LOC_FPUREGISTER,LOC_CFPUREGISTER,
  131. LOC_MMREGISTER,LOC_CMMREGISTER,LOC_SUBSETREG,LOC_CSUBSETREG];
  132. {*****************************************************************************
  133. References
  134. *****************************************************************************}
  135. type
  136. { array reference types }
  137. tarrayreftype = (art_none,art_indexreg,art_indexref,art_indexconst);
  138. {*****************************************************************************
  139. Conditions
  140. *****************************************************************************}
  141. type
  142. // not used by jvm target
  143. TAsmCond=(C_None);
  144. {*****************************************************************************
  145. Constants
  146. *****************************************************************************}
  147. const
  148. max_operands = 2;
  149. {*****************************************************************************
  150. Default generic sizes
  151. *****************************************************************************}
  152. {$ifdef cpu64bitaddr}
  153. {# Defines the default address size for a processor,
  154. -- fake for JVM, only influences default width of
  155. arithmetic calculations }
  156. OS_ADDR = OS_64;
  157. {# the natural int size for a processor,
  158. has to match osuinttype/ossinttype as initialized in psystem }
  159. OS_INT = OS_64;
  160. OS_SINT = OS_S64;
  161. {$else}
  162. {# Defines the default address size for a processor,
  163. -- fake for JVM, only influences default width of
  164. arithmetic calculations }
  165. OS_ADDR = OS_32;
  166. {# the natural int size for a processor,
  167. has to match osuinttype/ossinttype as initialized in psystem }
  168. OS_INT = OS_32;
  169. OS_SINT = OS_S32;
  170. {$endif}
  171. {# the maximum float size for a processor, }
  172. OS_FLOAT = OS_F64;
  173. {# the size of a vector register for a processor }
  174. OS_VECTOR = OS_M128;
  175. {*****************************************************************************
  176. Generic Register names
  177. *****************************************************************************}
  178. { dummies, not used for JVM }
  179. {# Stack pointer register }
  180. { used as base register in references to indicate that it's a local }
  181. NR_STACK_POINTER_REG = NR_R1;
  182. RS_STACK_POINTER_REG = RS_R1;
  183. {# Frame pointer register }
  184. NR_FRAME_POINTER_REG = NR_STACK_POINTER_REG;
  185. RS_FRAME_POINTER_REG = RS_STACK_POINTER_REG;
  186. { Java results are returned on the evaluation stack, not via a register }
  187. { Results are returned in this register (32-bit values) }
  188. NR_FUNCTION_RETURN_REG = NR_NO;
  189. RS_FUNCTION_RETURN_REG = RS_NO;
  190. { Low part of 64bit return value }
  191. NR_FUNCTION_RETURN64_LOW_REG = NR_NO;
  192. RS_FUNCTION_RETURN64_LOW_REG = RS_NO;
  193. { High part of 64bit return value }
  194. NR_FUNCTION_RETURN64_HIGH_REG = NR_NO;
  195. RS_FUNCTION_RETURN64_HIGH_REG = RS_NO;
  196. { The value returned from a function is available in this register }
  197. NR_FUNCTION_RESULT_REG = NR_FUNCTION_RETURN_REG;
  198. RS_FUNCTION_RESULT_REG = RS_FUNCTION_RETURN_REG;
  199. { The lowh part of 64bit value returned from a function }
  200. NR_FUNCTION_RESULT64_LOW_REG = NR_FUNCTION_RETURN64_LOW_REG;
  201. RS_FUNCTION_RESULT64_LOW_REG = RS_FUNCTION_RETURN64_LOW_REG;
  202. { The high part of 64bit value returned from a function }
  203. NR_FUNCTION_RESULT64_HIGH_REG = NR_FUNCTION_RETURN64_HIGH_REG;
  204. RS_FUNCTION_RESULT64_HIGH_REG = RS_FUNCTION_RETURN64_HIGH_REG;
  205. NR_FPU_RESULT_REG = NR_NO;
  206. NR_MM_RESULT_REG = NR_NO;
  207. { No default flags }
  208. NR_DEFAULTFLAGS = NR_NO;
  209. RS_DEFAULTFLAGS = RS_NO;
  210. {*****************************************************************************
  211. GCC /ABI linking information
  212. *****************************************************************************}
  213. { dummies, not used for JVM }
  214. {# Required parameter alignment when calling a routine
  215. }
  216. std_param_align = 1;
  217. {*****************************************************************************
  218. CPU Dependent Constants
  219. *****************************************************************************}
  220. maxfpuregs = 0;
  221. {*****************************************************************************
  222. Helpers
  223. *****************************************************************************}
  224. function cgsize2subreg(regtype: tregistertype; s:Tcgsize):Tsubregister;
  225. function reg_cgsize(const reg: tregister) : tcgsize;
  226. function std_regnum_search(const s:string):Tregister;
  227. function std_regname(r:Tregister):string;
  228. function findreg_by_number(r:Tregister):tregisterindex;
  229. function eh_return_data_regno(nr: longint): longint;
  230. { since we don't use tasmconds, don't call this routine
  231. (it will internalerror). We need it anyway to get aoptobj
  232. to compile (but it won't execute it).
  233. }
  234. function inverse_cond(const c: TAsmCond): Tasmcond; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  235. implementation
  236. uses
  237. verbose,
  238. rgbase;
  239. {*****************************************************************************
  240. Helpers
  241. *****************************************************************************}
  242. const
  243. std_regname_table : array[tregisterindex] of string[15] = (
  244. {$i rjvmstd.inc}
  245. );
  246. regnumber_index : array[tregisterindex] of tregisterindex = (
  247. {$i rjvmrni.inc}
  248. );
  249. (*
  250. std_regname_index : array[tregisterindex] of tregisterindex = (
  251. {$i rjvmsri.inc}
  252. );
  253. *)
  254. function reg_cgsize(const reg: tregister): tcgsize;
  255. begin
  256. result:=OS_NO;
  257. end;
  258. function cgsize2subreg(regtype: tregistertype; s:Tcgsize):Tsubregister;
  259. begin
  260. cgsize2subreg:=R_SUBNONE;
  261. end;
  262. function std_regnum_search(const s:string):Tregister;
  263. begin
  264. result:=NR_NO;
  265. end;
  266. function findreg_by_number(r:Tregister):tregisterindex;
  267. begin
  268. result:=findreg_by_number_table(r,regnumber_index);
  269. end;
  270. function std_regname(r:Tregister):string;
  271. var
  272. p : tregisterindex;
  273. begin
  274. p:=findreg_by_number_table(r,regnumber_index);
  275. if p<>0 then
  276. result:=std_regname_table[p]
  277. else
  278. result:=generic_regname(r);
  279. end;
  280. function eh_return_data_regno(nr: longint): longint;
  281. begin
  282. result:=-1;
  283. end;
  284. function inverse_cond(const c: TAsmCond): Tasmcond; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  285. begin
  286. result:=C_None;
  287. internalerror(2015082701);
  288. end;
  289. end.