cpubase.pas 11 KB

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