cpubase.pas 11 KB

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