cpubase.pas 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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. totherregisterset = set of tregisterindex;
  107. const
  108. { Available Superregisters }
  109. {$i rjvmsup.inc}
  110. { No Subregisters }
  111. R_SUBWHOLE = R_SUBNONE;
  112. { Available Registers }
  113. {$i rjvmcon.inc}
  114. { aliases }
  115. { used as base register in references for parameters passed to
  116. subroutines: these are passed on the evaluation stack, but this way we
  117. can use the offset field to indicate the order, which is used by ncal
  118. to sort the parameters }
  119. NR_EVAL_STACK_BASE = NR_R0;
  120. maxvarregs = 1;
  121. maxfpuvarregs = 1;
  122. { Integer Super registers first and last }
  123. first_int_imreg = 2;
  124. { Float Super register first and last }
  125. first_fpu_imreg = 2;
  126. { MM Super register first and last }
  127. first_mm_imreg = 2;
  128. regnumber_table : array[tregisterindex] of tregister = (
  129. {$i rjvmnum.inc}
  130. );
  131. EVALSTACKLOCS = [LOC_REGISTER,LOC_CREGISTER,LOC_FPUREGISTER,LOC_CFPUREGISTER,
  132. LOC_MMREGISTER,LOC_CMMREGISTER,LOC_SUBSETREG,LOC_CSUBSETREG];
  133. {*****************************************************************************
  134. References
  135. *****************************************************************************}
  136. type
  137. { array reference types }
  138. tarrayreftype = (art_none,art_indexreg,art_indexref,art_indexconst);
  139. {*****************************************************************************
  140. Conditions
  141. *****************************************************************************}
  142. type
  143. // not used by jvm target
  144. TAsmCond=(C_None);
  145. {*****************************************************************************
  146. Constants
  147. *****************************************************************************}
  148. const
  149. max_operands = 2;
  150. {*****************************************************************************
  151. Default generic sizes
  152. *****************************************************************************}
  153. {$ifdef cpu64bitaddr}
  154. {# Defines the default address size for a processor,
  155. -- fake for JVM, only influences default width of
  156. arithmetic calculations }
  157. OS_ADDR = OS_64;
  158. {# the natural int size for a processor,
  159. has to match osuinttype/ossinttype as initialized in psystem }
  160. OS_INT = OS_64;
  161. OS_SINT = OS_S64;
  162. {$else}
  163. {# Defines the default address size for a processor,
  164. -- fake for JVM, only influences default width of
  165. arithmetic calculations }
  166. OS_ADDR = OS_32;
  167. {# the natural int size for a processor,
  168. has to match osuinttype/ossinttype as initialized in psystem }
  169. OS_INT = OS_32;
  170. OS_SINT = OS_S32;
  171. {$endif}
  172. {# the maximum float size for a processor, }
  173. OS_FLOAT = OS_F64;
  174. {# the size of a vector register for a processor }
  175. OS_VECTOR = OS_M128;
  176. {*****************************************************************************
  177. Generic Register names
  178. *****************************************************************************}
  179. { dummies, not used for JVM }
  180. {# Stack pointer register }
  181. { used as base register in references to indicate that it's a local }
  182. NR_STACK_POINTER_REG = NR_R1;
  183. RS_STACK_POINTER_REG = RS_R1;
  184. {# Frame pointer register }
  185. NR_FRAME_POINTER_REG = NR_STACK_POINTER_REG;
  186. RS_FRAME_POINTER_REG = RS_STACK_POINTER_REG;
  187. { Java results are returned on the evaluation stack, not via a register }
  188. { Results are returned in this register (32-bit values) }
  189. NR_FUNCTION_RETURN_REG = NR_NO;
  190. RS_FUNCTION_RETURN_REG = RS_NO;
  191. { Low part of 64bit return value }
  192. NR_FUNCTION_RETURN64_LOW_REG = NR_NO;
  193. RS_FUNCTION_RETURN64_LOW_REG = RS_NO;
  194. { High part of 64bit return value }
  195. NR_FUNCTION_RETURN64_HIGH_REG = NR_NO;
  196. RS_FUNCTION_RETURN64_HIGH_REG = RS_NO;
  197. { The value returned from a function is available in this register }
  198. NR_FUNCTION_RESULT_REG = NR_FUNCTION_RETURN_REG;
  199. RS_FUNCTION_RESULT_REG = RS_FUNCTION_RETURN_REG;
  200. { The lowh part of 64bit value returned from a function }
  201. NR_FUNCTION_RESULT64_LOW_REG = NR_FUNCTION_RETURN64_LOW_REG;
  202. RS_FUNCTION_RESULT64_LOW_REG = RS_FUNCTION_RETURN64_LOW_REG;
  203. { The high part of 64bit value returned from a function }
  204. NR_FUNCTION_RESULT64_HIGH_REG = NR_FUNCTION_RETURN64_HIGH_REG;
  205. RS_FUNCTION_RESULT64_HIGH_REG = RS_FUNCTION_RETURN64_HIGH_REG;
  206. NR_FPU_RESULT_REG = NR_NO;
  207. NR_MM_RESULT_REG = NR_NO;
  208. {*****************************************************************************
  209. GCC /ABI linking information
  210. *****************************************************************************}
  211. { dummies, not used for JVM }
  212. {# Registers which must be saved when calling a routine
  213. }
  214. saved_standard_registers : array[0..0] of tsuperregister = (
  215. RS_NO
  216. );
  217. { this is only for the generic code which is not used for this architecture }
  218. saved_address_registers : array[0..0] of tsuperregister = (RS_INVALID);
  219. saved_mm_registers : array[0..0] of tsuperregister = (RS_INVALID);
  220. {# Required parameter alignment when calling a routine
  221. }
  222. std_param_align = 1;
  223. {*****************************************************************************
  224. CPU Dependent Constants
  225. *****************************************************************************}
  226. maxfpuregs = 0;
  227. {*****************************************************************************
  228. Helpers
  229. *****************************************************************************}
  230. function cgsize2subreg(regtype: tregistertype; s:Tcgsize):Tsubregister;
  231. function reg_cgsize(const reg: tregister) : tcgsize;
  232. function std_regnum_search(const s:string):Tregister;
  233. function std_regname(r:Tregister):string;
  234. function findreg_by_number(r:Tregister):tregisterindex;
  235. implementation
  236. uses
  237. rgbase;
  238. {*****************************************************************************
  239. Helpers
  240. *****************************************************************************}
  241. const
  242. std_regname_table : array[tregisterindex] of string[15] = (
  243. {$i rjvmstd.inc}
  244. );
  245. regnumber_index : array[tregisterindex] of tregisterindex = (
  246. {$i rjvmrni.inc}
  247. );
  248. std_regname_index : array[tregisterindex] of tregisterindex = (
  249. {$i rjvmsri.inc}
  250. );
  251. function reg_cgsize(const reg: tregister): tcgsize;
  252. begin
  253. result:=OS_NO;
  254. end;
  255. function cgsize2subreg(regtype: tregistertype; s:Tcgsize):Tsubregister;
  256. begin
  257. cgsize2subreg:=R_SUBNONE;
  258. end;
  259. function std_regnum_search(const s:string):Tregister;
  260. begin
  261. result:=NR_NO;
  262. end;
  263. function findreg_by_number(r:Tregister):tregisterindex;
  264. begin
  265. result:=findreg_by_number_table(r,regnumber_index);
  266. end;
  267. function std_regname(r:Tregister):string;
  268. var
  269. p : tregisterindex;
  270. begin
  271. p:=findreg_by_number_table(r,regnumber_index);
  272. if p<>0 then
  273. result:=std_regname_table[p]
  274. else
  275. result:=generic_regname(r);
  276. end;
  277. end.