2
0

cpubase.pas 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. Contains the base types for the m68k
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. { This Unit contains the base types for the m68k
  19. }
  20. unit cpubase;
  21. {$i fpcdefs.inc}
  22. interface
  23. uses
  24. strings,cutils,cclasses,aasmbase,cpuinfo,cginfo;
  25. {*****************************************************************************
  26. Assembler Opcodes
  27. *****************************************************************************}
  28. type
  29. { warning: CPU32 opcodes are not fully compatible with the MC68020. }
  30. { 68000 only opcodes }
  31. tasmop = (a_abcd,
  32. a_add,a_adda,a_addi,a_addq,a_addx,a_and,a_andi,
  33. a_asl,a_asr,a_bcc,a_bcs,a_beq,a_bge,a_bgt,a_bhi,
  34. a_ble,a_bls,a_blt,a_bmi,a_bne,a_bpl,a_bvc,a_bvs,
  35. a_bchg,a_bclr,a_bra,a_bset,a_bsr,a_btst,a_chk,
  36. a_clr,a_cmp,a_cmpa,a_cmpi,a_cmpm,a_dbcc,a_dbcs,a_dbeq,a_dbge,
  37. a_dbgt,a_dbhi,a_dble,a_dbls,a_dblt,a_dbmi,a_dbne,a_dbra,
  38. a_dbpl,a_dbt,a_dbvc,a_dbvs,a_dbf,a_divs,a_divu,
  39. a_eor,a_eori,a_exg,a_illegal,a_ext,a_jmp,a_jsr,
  40. a_lea,a_link,a_lsl,a_lsr,a_move,a_movea,a_movei,a_moveq,
  41. a_movem,a_movep,a_muls,a_mulu,a_nbcd,a_neg,a_negx,
  42. a_nop,a_not,a_or,a_ori,a_pea,a_rol,a_ror,a_roxl,
  43. a_roxr,a_rtr,a_rts,a_sbcd,a_scc,a_scs,a_seq,a_sge,
  44. a_sgt,a_shi,a_sle,a_sls,a_slt,a_smi,a_sne,
  45. a_spl,a_st,a_svc,a_svs,a_sf,a_sub,a_suba,a_subi,a_subq,
  46. a_subx,a_swap,a_tas,a_trap,a_trapv,a_tst,a_unlk,
  47. a_rte,a_reset,a_stop,
  48. { mc68010 instructions }
  49. a_bkpt,a_movec,a_moves,a_rtd,
  50. { mc68020 instructions }
  51. a_bfchg,a_bfclr,a_bfexts,a_bfextu,a_bfffo,
  52. a_bfins,a_bfset,a_bftst,a_callm,a_cas,a_cas2,
  53. a_chk2,a_cmp2,a_divsl,a_divul,a_extb,a_pack,a_rtm,
  54. a_trapcc,a_tracs,a_trapeq,a_trapf,a_trapge,a_trapgt,
  55. a_traphi,a_traple,a_trapls,a_traplt,a_trapmi,a_trapne,
  56. a_trappl,a_trapt,a_trapvc,a_trapvs,a_unpk,
  57. { fpu processor instructions - directly supported only. }
  58. { ieee aware and misc. condition codes not supported }
  59. a_fabs,a_fadd,
  60. a_fbeq,a_fbne,a_fbngt,a_fbgt,a_fbge,a_fbnge,
  61. a_fblt,a_fbnlt,a_fble,a_fbgl,a_fbngl,a_fbgle,a_fbngle,
  62. a_fdbeq,a_fdbne,a_fdbgt,a_fdbngt,a_fdbge,a_fdbnge,
  63. a_fdblt,a_fdbnlt,a_fdble,a_fdbgl,a_fdbngl,a_fdbgle,a_fdbngle,
  64. a_fseq,a_fsne,a_fsgt,a_fsngt,a_fsge,a_fsnge,
  65. a_fslt,a_fsnlt,a_fsle,a_fsgl,a_fsngl,a_fsgle,a_fsngle,
  66. a_fcmp,a_fdiv,a_fmove,a_fmovem,
  67. a_fmul,a_fneg,a_fnop,a_fsqrt,a_fsub,a_fsgldiv,
  68. a_fsflmul,a_ftst,
  69. a_ftrapeq,a_ftrapne,a_ftrapgt,a_ftrapngt,a_ftrapge,a_ftrapnge,
  70. a_ftraplt,a_ftrapnlt,a_ftraple,a_ftrapgl,a_ftrapngl,a_ftrapgle,a_ftrapngle,
  71. { protected instructions }
  72. a_cprestore,a_cpsave,
  73. { fpu unit protected instructions }
  74. { and 68030/68851 common mmu instructions }
  75. { (this may include 68040 mmu instructions) }
  76. a_frestore,a_fsave,a_pflush,a_pflusha,a_pload,a_pmove,a_ptest,
  77. { useful for assembly language output }
  78. a_label,a_none,a_dbxx,a_sxx,a_bxx,a_fbxx);
  79. {# This should define the array of instructions as string }
  80. op2strtable=array[tasmop] of string[11];
  81. Const
  82. {# First value of opcode enumeration }
  83. firstop = low(tasmop);
  84. {# Last value of opcode enumeration }
  85. lastop = high(tasmop);
  86. {*****************************************************************************
  87. Registers
  88. *****************************************************************************}
  89. {$packenum 1}
  90. type
  91. Toldregister = (
  92. R_NO,R_D0,R_D1,R_D2,R_D3,R_D4,R_D5,R_D6,R_D7,
  93. R_A0,R_A1,R_A2,R_A3,R_A4,R_A5,R_A6,R_SP,
  94. { PUSH/PULL- quick and dirty hack }
  95. R_SPPUSH,R_SPPULL,
  96. { misc. }
  97. R_CCR,R_FP0,R_FP1,R_FP2,R_FP3,R_FP4,R_FP5,R_FP6,
  98. R_FP7,R_FPCR,R_SR,R_SSP,R_DFC,R_SFC,R_VBR,R_FPSR,
  99. R_INTREGISTER,R_FLOATREGISTER);
  100. Tnewregister=word;
  101. Tregister=record
  102. enum:Toldregister;
  103. number:word;
  104. end;
  105. Tsuperregister=byte;
  106. Tsubregister=byte;
  107. {# Set type definition for registers }
  108. tregisterset = set of Toldregister;
  109. Tsupregset = set of Tsuperregister;
  110. {$packenum normal}
  111. { A type to store register locations for 64 Bit values. }
  112. tregister64 = packed record
  113. reglo,reghi : tregister;
  114. end;
  115. { alias for compact code }
  116. treg64 = tregister64;
  117. {New register coding:}
  118. {Special registers:}
  119. const
  120. NR_NO = $0000; {Invalid register}
  121. {Normal registers:}
  122. {General purpose registers:}
  123. NR_D0 = $0100; NR_D1 = $0200; NR_D2 = $0300;
  124. NR_D3 = $0400; NR_D4 = $0500; NR_D5 = $0600;
  125. NR_D6 = $0700; NR_D7 = $0800; NR_A0 = $0900;
  126. NR_A1 = $0A00; NR_A2 = $0B00; NR_A3 = $0C00;
  127. NR_A4 = $0D00; NR_A5 = $0E00; NR_A6 = $0F00;
  128. NR_A7 = $1000;
  129. {Super registers.}
  130. RS_D0 = $01; RS_D1 = $02; RS_D2 = $03;
  131. RS_D3 = $04; RS_D4 = $05; RS_D5 = $06;
  132. RS_D6 = $07; RS_D7 = $08; RS_A0 = $09;
  133. RS_A1 = $0A; RS_A2 = $0B; RS_A3 = $0C;
  134. RS_A4 = $0D; RS_A5 = $0E; RS_A6 = $0F;
  135. RS_A7 = $10;
  136. {Sub register numbers:}
  137. R_SUBL = $00; {8 bits}
  138. R_SUBW = $01; {16 bits}
  139. R_SUBD = $02; {32 bits}
  140. {The subregister that specifies the entire register.}
  141. R_SUBWHOLE = R_SUBD; {i386}
  142. {R_SUBWHOLE = R_SUBQ;} {Hammer}
  143. {Number of first and last superregister.}
  144. first_supreg = $01;
  145. last_supreg = $10;
  146. {$warning FIXME!!!}
  147. { integer registers which may be destroyed by calls }
  148. VOLATILE_INTREGISTERS = [first_supreg..last_supreg];
  149. {$warning FIXME!!!}
  150. { fpu registers which may be destroyed by calls }
  151. VOLATILE_FPUREGISTERS = [first_supreg..last_supreg];
  152. first_imreg = $11;
  153. last_imreg = $ff;
  154. {# First register in the tregister enumeration }
  155. firstreg = low(Toldregister);
  156. {# Last register in the tregister enumeration }
  157. lastreg = R_FPSR;
  158. type
  159. {# Type definition for the array of string of register nnames }
  160. reg2strtable = array[firstreg..lastreg] of string[7];
  161. regname2regnumrec = record
  162. name:string[6];
  163. number:Tnewregister;
  164. end;
  165. const
  166. std_reg2str : reg2strtable =
  167. ('', 'd0','d1','d2','d3','d4','d5','d6','d7',
  168. 'a0','a1','a2','a3','a4','a5','a6','sp',
  169. '-(sp)','(sp)+',
  170. 'ccr','fp0','fp1','fp2','fp3','fp4','fp5',
  171. 'fp6','fp7','fpcr','sr','ssp','dfc',
  172. 'sfc','vbr','fpsr');
  173. {*****************************************************************************
  174. Conditions
  175. *****************************************************************************}
  176. {*****************************************************************************
  177. Conditions
  178. *****************************************************************************}
  179. type
  180. TAsmCond=(C_None,
  181. C_CC,C_LS,C_CS,C_LT,C_EQ,C_MI,C_F,C_NE,
  182. C_GE,C_PL,C_GT,C_T,C_HI,C_VC,C_LE,C_VS
  183. );
  184. const
  185. cond2str:array[TAsmCond] of string[3]=('',
  186. 'cc','ls','cs','lt','eq','mi','f','ne',
  187. 'ge','pl','gt','t','hi','vc','le','vs'
  188. );
  189. {*****************************************************************************
  190. Flags
  191. *****************************************************************************}
  192. type
  193. TResFlags = (
  194. F_E,F_NE,
  195. F_G,F_L,F_GE,F_LE,F_C,F_NC,F_A,F_AE,F_B,F_BE);
  196. {*****************************************************************************
  197. Reference
  198. *****************************************************************************}
  199. type
  200. trefoptions=(ref_none,ref_parafixup,ref_localfixup,ref_selffixup);
  201. { direction of address register : }
  202. { (An) (An)+ -(An) }
  203. tdirection = (dir_none,dir_inc,dir_dec);
  204. { reference record }
  205. preference = ^treference;
  206. treference = packed record
  207. base,
  208. index : tregister;
  209. scalefactor : byte;
  210. offset : longint;
  211. symbol : tasmsymbol;
  212. offsetfixup : longint;
  213. options : trefoptions;
  214. { indexed increment and decrement mode }
  215. { (An)+ and -(An) }
  216. direction : tdirection;
  217. end;
  218. { reference record }
  219. pparareference = ^tparareference;
  220. tparareference = packed record
  221. index : tregister;
  222. offset : longint;
  223. end;
  224. {*****************************************************************************
  225. Operands
  226. *****************************************************************************}
  227. { Types of operand }
  228. toptype=(top_none,top_reg,top_ref,top_const,top_symbol,top_reglist);
  229. tregisterlist = set of Toldregister;
  230. toper=record
  231. ot : longint;
  232. case typ : toptype of
  233. top_none : ();
  234. top_reg : (reg:tregister);
  235. top_ref : (ref:preference);
  236. top_const : (val:aword);
  237. top_symbol : (sym:tasmsymbol;symofs:longint);
  238. { used for pushing/popping multiple registers }
  239. top_reglist : (registerlist:Tsupregset);
  240. end;
  241. {*****************************************************************************
  242. Generic Location
  243. *****************************************************************************}
  244. type
  245. { tparamlocation describes where a parameter for a procedure is stored.
  246. References are given from the caller's point of view. The usual
  247. TLocation isn't used, because contains a lot of unnessary fields.
  248. }
  249. tparalocation = packed record
  250. size : TCGSize;
  251. loc : TCGLoc;
  252. sp_fixup : longint;
  253. case TCGLoc of
  254. LOC_REFERENCE : (reference : tparareference);
  255. { segment in reference at the same place as in loc_register }
  256. LOC_REGISTER,LOC_CREGISTER : (
  257. case longint of
  258. 1 : (register,registerhigh : tregister);
  259. { overlay a registerlow }
  260. 2 : (registerlow : tregister);
  261. { overlay a 64 Bit register type }
  262. 3 : (reg64 : tregister64);
  263. 4 : (register64 : tregister64);
  264. );
  265. end;
  266. tlocation = packed record
  267. loc : TCGLoc;
  268. size : TCGSize;
  269. case TCGLoc of
  270. LOC_FLAGS : (resflags : tresflags);
  271. LOC_CONSTANT : (
  272. case longint of
  273. 1 : (value : AWord);
  274. { can't do this, this layout depends on the host cpu. Use }
  275. { lo(valueqword)/hi(valueqword) instead (JM) }
  276. { 2 : (valuelow, valuehigh:AWord); }
  277. { overlay a complete 64 Bit value }
  278. 3 : (valueqword : qword);
  279. );
  280. LOC_CREFERENCE,
  281. LOC_REFERENCE : (reference : treference);
  282. { segment in reference at the same place as in loc_register }
  283. LOC_REGISTER,LOC_CREGISTER : (
  284. case longint of
  285. 1 : (register,registerhigh,segment : tregister);
  286. { overlay a registerlow }
  287. 2 : (registerlow : tregister);
  288. { overlay a 64 Bit register type }
  289. 3 : (reg64 : tregister64);
  290. 4 : (register64 : tregister64);
  291. );
  292. end;
  293. {*****************************************************************************
  294. Operand Sizes
  295. *****************************************************************************}
  296. { S_NO = No Size of operand }
  297. { S_B = 8-bit size operand }
  298. { S_W = 16-bit size operand }
  299. { S_L = 32-bit size operand }
  300. { Floating point types }
  301. { S_FS = single type (32 bit) }
  302. { S_FD = double/64bit integer }
  303. { S_FX = Extended type }
  304. topsize = (S_NO,S_B,S_W,S_L,S_FS,S_FD,S_FX,S_IQ);
  305. {*****************************************************************************
  306. Constants
  307. *****************************************************************************}
  308. const
  309. {# maximum number of operands in assembler instruction }
  310. max_operands = 4;
  311. lvaluelocations = [LOC_REFERENCE,LOC_CFPUREGISTER,LOC_CREGISTER];
  312. general_registers = [R_D0..R_D7];
  313. general_superregisters = [RS_D0..RS_D7];
  314. {# low and high of the available maximum width integer general purpose }
  315. { registers }
  316. LoGPReg = R_D0;
  317. HiGPReg = R_D7;
  318. {# low and high of every possible width general purpose register (same as }
  319. { above on most architctures apart from the 80x86) }
  320. LoReg = LoGPReg;
  321. HiReg = HiGPReg;
  322. { Table of registers which can be allocated by the code generator
  323. internally, when generating the code.
  324. legend:
  325. xxxregs = set of all possibly used registers of that type in the code
  326. generator
  327. usableregsxxx = set of all 32bit components of registers that can be
  328. possible allocated to a regvar or using getregisterxxx (this
  329. excludes registers which can be only used for parameter
  330. passing on ABI's that define this)
  331. c_countusableregsxxx = amount of registers in the usableregsxxx set }
  332. maxintregs = 8;
  333. { to determine how many registers to use for regvars }
  334. maxintscratchregs = 1;
  335. intregs = [R_D0..R_D7];
  336. usableregsint = [RS_D2..RS_D7];
  337. c_countusableregsint = 6;
  338. maxfpuregs = 8;
  339. fpuregs = [R_FP0..R_FP7];
  340. usableregsfpu = [R_FP2..R_FP7];
  341. c_countusableregsfpu = 6;
  342. mmregs = [];
  343. usableregsmm = [];
  344. c_countusableregsmm = 0;
  345. maxaddrregs = 8;
  346. addrregs = [R_A0..R_SP];
  347. usableregsaddr = [RS_A2..RS_A4];
  348. c_countusableregsaddr = 3;
  349. { The first register in the usableregsint array }
  350. firstsaveintreg = RS_D2;
  351. { The last register in the usableregsint array }
  352. lastsaveintreg = RS_D7;
  353. { The first register in the usableregsfpu array }
  354. firstsavefpureg = R_FP2;
  355. { The last register in the usableregsfpu array }
  356. lastsavefpureg = R_FP7;
  357. { these constants are m68k specific }
  358. { The first register in the usableregsaddr array }
  359. firstsaveaddrreg = RS_A2;
  360. { The last register in the usableregsaddr array }
  361. lastsaveaddrreg = RS_A4;
  362. firstsavemmreg = R_NO;
  363. lastsavemmreg = R_NO;
  364. {
  365. Defines the maxinum number of integer registers which can be used as variable registers
  366. }
  367. maxvarregs = 6;
  368. { Array of integer registers which can be used as variable registers }
  369. varregs : Array [1..maxvarregs] of Toldregister =
  370. (R_D2,R_D3,R_D4,R_D5,R_D6,R_D7);
  371. {
  372. Defines the maxinum number of float registers which can be used as variable registers
  373. }
  374. maxfpuvarregs = 6;
  375. { Array of float registers which can be used as variable registers }
  376. fpuvarregs : Array [1..maxfpuvarregs] of Toldregister =
  377. (R_FP2,R_FP3,R_FP4,R_FP5,R_FP6,R_FP7);
  378. {
  379. Defines the number of integer registers which are used in the ABI to pass parameters
  380. (might be empty on systems which use the stack to pass parameters)
  381. }
  382. max_param_regs_int = 0;
  383. {param_regs_int: Array[1..max_param_regs_int] of tregister =
  384. (R_3,R_4,R_5,R_6,R_7,R_8,R_9,R_10);}
  385. {
  386. Defines the number of float registers which are used in the ABI to pass parameters
  387. (might be empty on systems which use the stack to pass parameters)
  388. }
  389. max_param_regs_fpu = 0;
  390. {param_regs_fpu: Array[1..max_param_regs_fpu] of tregister =
  391. (R_F1,R_F2,R_F3,R_F4,R_F5,R_F6,R_F7,R_F8,R_F9,R_F10,R_F11,R_F12,R_F13);}
  392. {
  393. Defines the number of mmx registers which are used in the ABI to pass parameters
  394. (might be empty on systems which use the stack to pass parameters)
  395. }
  396. max_param_regs_mm = 0;
  397. {param_regs_mm: Array[1..max_param_regs_mm] of tregister =
  398. (R_M1,R_M2,R_M3,R_M4,R_M5,R_M6,R_M7,R_M8,R_M9,R_M10,R_M11,R_M12,R_M13);}
  399. {# Registers which are defined as scratch integer and no need to save across
  400. routine calls or in assembler blocks.
  401. }
  402. max_scratch_regs = 4;
  403. scratch_regs: Array[1..max_scratch_regs] of Tsuperregister = (RS_D0,RS_D1,RS_A0,RS_A1);
  404. {*****************************************************************************
  405. Default generic sizes
  406. *****************************************************************************}
  407. {# Defines the default address size for a processor, }
  408. OS_ADDR = OS_32;
  409. {# the natural int size for a processor, }
  410. OS_INT = OS_32;
  411. {# the maximum float size for a processor, }
  412. OS_FLOAT = OS_F64;
  413. {# the size of a vector register for a processor }
  414. OS_VECTOR = OS_M128;
  415. {*****************************************************************************
  416. GDB Information
  417. *****************************************************************************}
  418. {# Register indexes for stabs information, when some
  419. parameters or variables are stored in registers.
  420. Taken from m68kelf.h (DBX_REGISTER_NUMBER)
  421. from GCC 3.x source code.
  422. This is not compatible with the m68k-sun
  423. implementation.
  424. }
  425. stab_regindex : array[firstreg..lastreg] of shortint =
  426. (-1, { R_NO }
  427. 0,1,2,3,4,5,6,7, { R_D0..R_D7 }
  428. 8,9,10,11,12,13,14,15, { R_A0..R_A7 }
  429. -1,-1,-1, { R_SPPUSH, R_SPPULL, R_CCR }
  430. 18,19,20,21,22,23,24,25, { R_FP0..R_FP7 }
  431. -1,-1,-1,-1,-1,-1,-1);
  432. {*****************************************************************************
  433. Generic Register names
  434. *****************************************************************************}
  435. {# Stack pointer register }
  436. stack_pointer_reg = R_SP;
  437. NR_STACK_POINTER_REG = NR_A7;
  438. RS_STACK_POINTER_REG = RS_A7;
  439. {# Frame pointer register }
  440. frame_pointer_reg = R_A6;
  441. NR_FRAME_POINTER_REG = NR_A6;
  442. RS_FRAME_POINTER_REG = RS_A6;
  443. {# Self pointer register : contains the instance address of an
  444. object or class. }
  445. self_pointer_reg = R_A5;
  446. NR_SELF_POINTER_REG = NR_A5;
  447. RS_SELF_POINTER_REG = RS_A5;
  448. {# Register for addressing absolute data in a position independant way,
  449. such as in PIC code. The exact meaning is ABI specific. For
  450. further information look at GCC source : PIC_OFFSET_TABLE_REGNUM
  451. }
  452. pic_offset_reg = R_A5;
  453. {# Results are returned in this register (32-bit values) }
  454. accumulator = R_D0;
  455. NR_ACCUMULATOR = NR_D0;
  456. RS_ACCUMULATOR = RS_D0;
  457. {the return_result_reg, is used inside the called function to store its return
  458. value when that is a scalar value otherwise a pointer to the address of the
  459. result is placed inside it}
  460. return_result_reg = accumulator;
  461. NR_RETURN_RESULT_REG = NR_ACCUMULATOR;
  462. RS_RETURN_RESULT_REG = RS_ACCUMULATOR;
  463. {the function_result_reg contains the function result after a call to a scalar
  464. function othewise it contains a pointer to the returned result}
  465. function_result_reg = accumulator;
  466. {# Hi-Results are returned in this register (64-bit value high register) }
  467. accumulatorhigh = R_D1;
  468. NR_ACCUMULATORHIGH = NR_D1;
  469. RS_ACCUMULATORHIGH = RS_D1;
  470. {# Floating point results will be placed into this register }
  471. FPU_RESULT_REG = R_FP0;
  472. mmresultreg = R_NO;
  473. {*****************************************************************************
  474. GCC /ABI linking information
  475. *****************************************************************************}
  476. {# Registers which must be saved when calling a routine declared as
  477. cppdecl, cdecl, stdcall, safecall, palmossyscall. The registers
  478. saved should be the ones as defined in the target ABI and / or GCC.
  479. This value can be deduced from CALLED_USED_REGISTERS array in the
  480. GCC source.
  481. }
  482. std_saved_registers = [RS_D2..RS_D7,RS_A2..RS_A5];
  483. {# Required parameter alignment when calling a routine declared as
  484. stdcall and cdecl. The alignment value should be the one defined
  485. by GCC or the target ABI.
  486. The value of this constant is equal to the constant
  487. PARM_BOUNDARY / BITS_PER_UNIT in the GCC source.
  488. }
  489. std_param_align = 4; { for 32-bit version only }
  490. {*****************************************************************************
  491. CPU Dependent Constants
  492. *****************************************************************************}
  493. {*****************************************************************************
  494. Helpers
  495. *****************************************************************************}
  496. function is_calljmp(o:tasmop):boolean;
  497. procedure inverse_flags(var r : TResFlags);
  498. function flags_to_cond(const f: TResFlags) : TAsmCond;
  499. procedure convert_register_to_enum(var r:Tregister);
  500. function cgsize2subreg(s:Tcgsize):Tsubregister;
  501. function supreg_name(r:Tsuperregister):string;
  502. implementation
  503. uses
  504. verbose;
  505. {*****************************************************************************
  506. Helpers
  507. *****************************************************************************}
  508. function is_calljmp(o:tasmop):boolean;
  509. begin
  510. is_calljmp := false;
  511. if o in [A_BXX,A_FBXX,A_DBXX,A_BCC..A_BVS,A_DBCC..A_DBVS,A_FBEQ..A_FSNGLE,
  512. A_JSR,A_BSR,A_JMP] then
  513. is_calljmp := true;
  514. end;
  515. procedure inverse_flags(var r: TResFlags);
  516. const flagsinvers : array[F_E..F_BE] of tresflags =
  517. (F_NE,F_E,
  518. F_LE,F_GE,
  519. F_L,F_G,
  520. F_NC,F_C,
  521. F_BE,F_B,
  522. F_AE,F_A);
  523. begin
  524. r:=flagsinvers[r];
  525. end;
  526. function flags_to_cond(const f: TResFlags) : TAsmCond;
  527. const flags2cond: array[tresflags] of tasmcond = (
  528. C_EQ,{F_E equal}
  529. C_NE,{F_NE not equal}
  530. C_GT,{F_G gt signed}
  531. C_LT,{F_L lt signed}
  532. C_GE,{F_GE ge signed}
  533. C_LE,{F_LE le signed}
  534. C_CS,{F_C carry set}
  535. C_CC,{F_NC carry clear}
  536. C_HI,{F_A gt unsigned}
  537. C_CC,{F_AE ge unsigned}
  538. C_CS,{F_B lt unsigned}
  539. C_LS);{F_BE le unsigned}
  540. begin
  541. flags_to_cond := flags2cond[f];
  542. end;
  543. procedure convert_register_to_enum(var r:Tregister);
  544. begin
  545. if r.enum = R_INTREGISTER then
  546. case r.number of
  547. NR_NO: r.enum:= R_NO;
  548. NR_D0: r.enum:= R_D0;
  549. NR_D1: r.enum:= R_D1;
  550. NR_D2: r.enum:= R_D2;
  551. NR_D3: r.enum:= R_D3;
  552. NR_D4: r.enum:= R_D4;
  553. NR_D5: r.enum:= R_D5;
  554. NR_D6: r.enum:= R_D6;
  555. NR_D7: r.enum:= R_D7;
  556. NR_A0: r.enum:= R_A0;
  557. NR_A1: r.enum:= R_A1;
  558. NR_A2: r.enum:= R_A2;
  559. NR_A3: r.enum:= R_A3;
  560. NR_A4: r.enum:= R_A4;
  561. NR_A5: r.enum:= R_A5;
  562. NR_A6: r.enum:= R_A6;
  563. NR_A7: r.enum:= R_SP;
  564. else
  565. internalerror(200301082);
  566. end;
  567. end;
  568. function cgsize2subreg(s:Tcgsize):Tsubregister;
  569. begin
  570. case s of
  571. OS_8,OS_S8:
  572. cgsize2subreg:=R_SUBL;
  573. OS_16,OS_S16:
  574. cgsize2subreg:=R_SUBW;
  575. OS_32,OS_S32:
  576. cgsize2subreg:=R_SUBD;
  577. else
  578. internalerror(200301231);
  579. end;
  580. end;
  581. function supreg_name(r:Tsuperregister):string;
  582. var s:string[4];
  583. const supreg_names:array[0..last_supreg] of string[4]=
  584. ('INV',
  585. 'd0','d1','d2','d3','d4','d5','d6','d7',
  586. 'a0','a1','a2','a3','a4','a5','a6','sp');
  587. begin
  588. if r in [0..last_supreg] then
  589. supreg_name:=supreg_names[r]
  590. else
  591. begin
  592. str(r,s);
  593. supreg_name:='reg'+s;
  594. end;
  595. end;
  596. end.
  597. {
  598. $Log$
  599. Revision 1.23 2003-08-17 16:59:20 jonas
  600. * fixed regvars so they work with newra (at least for ppc)
  601. * fixed some volatile register bugs
  602. + -dnotranslation option for -dnewra, which causes the registers not to
  603. be translated from virtual to normal registers. Requires support in
  604. the assembler writer as well, which is only implemented in aggas/
  605. agppcgas currently
  606. Revision 1.22 2003/06/17 16:34:44 jonas
  607. * lots of newra fixes (need getfuncretparaloc implementation for i386)!
  608. * renamed all_intregisters to volatile_intregisters and made it
  609. processor dependent
  610. Revision 1.21 2003/06/03 13:01:59 daniel
  611. * Register allocator finished
  612. Revision 1.20 2003/04/23 13:40:33 peter
  613. * fix m68k compile
  614. Revision 1.19 2003/04/23 12:35:35 florian
  615. * fixed several issues with powerpc
  616. + applied a patch from Jonas for nested function calls (PowerPC only)
  617. * ...
  618. Revision 1.18 2003/02/19 22:00:16 daniel
  619. * Code generator converted to new register notation
  620. - Horribily outdated todo.txt removed
  621. Revision 1.17 2003/02/02 19:25:54 carl
  622. * Several bugfixes for m68k target (register alloc., opcode emission)
  623. + VIS target
  624. + Generic add more complete (still not verified)
  625. Revision 1.16 2003/01/09 15:49:56 daniel
  626. * Added register conversion
  627. Revision 1.15 2003/01/08 18:43:57 daniel
  628. * Tregister changed into a record
  629. Revision 1.14 2002/11/30 23:33:03 carl
  630. * merges from Pierre's fixes in m68k fixes branch
  631. Revision 1.13 2002/11/17 18:26:16 mazen
  632. * fixed a compilation bug accmulator-->accumulator, in definition of return_result_reg
  633. Revision 1.12 2002/11/17 17:49:09 mazen
  634. + return_result_reg and function_result_reg are now used, in all plateforms, to pass functions result between called function and its caller. See the explanation of each one
  635. Revision 1.11 2002/10/14 16:32:36 carl
  636. + flag_2_cond implemented
  637. Revision 1.10 2002/08/18 09:02:12 florian
  638. * fixed compilation problems
  639. Revision 1.9 2002/08/15 08:13:54 carl
  640. - a_load_sym_ofs_reg removed
  641. * loadvmt now calls loadaddr_ref_reg instead
  642. Revision 1.8 2002/08/14 18:41:47 jonas
  643. - remove valuelow/valuehigh fields from tlocation, because they depend
  644. on the endianess of the host operating system -> difficult to get
  645. right. Use lo/hi(location.valueqword) instead (remember to use
  646. valueqword and not value!!)
  647. Revision 1.7 2002/08/13 21:40:58 florian
  648. * more fixes for ppc calling conventions
  649. Revision 1.6 2002/08/13 18:58:54 carl
  650. + m68k problems with cvs fixed?()!
  651. Revision 1.4 2002/08/12 15:08:44 carl
  652. + stab register indexes for powerpc (moved from gdb to cpubase)
  653. + tprocessor enumeration moved to cpuinfo
  654. + linker in target_info is now a class
  655. * many many updates for m68k (will soon start to compile)
  656. - removed some ifdef or correct them for correct cpu
  657. Revision 1.3 2002/07/29 17:51:32 carl
  658. + restart m68k support
  659. }