cgcpu.pas 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by the FPC team
  4. This unit implements the code generator for the 680x0
  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. unit cgcpu;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. cginfo,cgbase,cgobj,
  23. aasmbase,aasmtai,aasmcpu,
  24. cpubase,cpuinfo,cpupara,
  25. node,symconst,cg64f32;
  26. type
  27. tcg68k = class(tcg)
  28. procedure a_call_name(list : taasmoutput;const s : string);override;
  29. procedure a_call_ref(list : taasmoutput;const ref : treference);override;
  30. procedure a_call_reg(list : taasmoutput;reg : tregister);override;
  31. procedure a_load_const_reg(list : taasmoutput;size : tcgsize;a : aword;register : tregister);override;
  32. procedure a_load_reg_ref(list : taasmoutput;size : tcgsize;register : tregister;const ref : treference);override;
  33. procedure a_load_reg_reg(list : taasmoutput;fromsize,tosize : tcgsize;reg1,reg2 : tregister);override;
  34. procedure a_load_ref_reg(list : taasmoutput;size : tcgsize;const ref : treference;register : tregister);override;
  35. procedure a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);override;
  36. procedure a_loadfpu_reg_reg(list: taasmoutput; reg1, reg2: tregister); override;
  37. procedure a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister); override;
  38. procedure a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference); override;
  39. procedure a_loadmm_reg_reg(list: taasmoutput; reg1, reg2: tregister); override;
  40. procedure a_loadmm_ref_reg(list: taasmoutput; const ref: treference; reg: tregister); override;
  41. procedure a_loadmm_reg_ref(list: taasmoutput; reg: tregister; const ref: treference); override;
  42. procedure a_parammm_reg(list: taasmoutput; reg: tregister); override;
  43. procedure a_op_const_reg(list : taasmoutput; Op: TOpCG; a: AWord; reg: TRegister); override;
  44. procedure a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; reg1, reg2: TRegister); override;
  45. procedure a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;reg : tregister;
  46. l : tasmlabel);override;
  47. procedure a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;reg1,reg2 : tregister;l : tasmlabel); override;
  48. procedure a_jmp_always(list : taasmoutput;l: tasmlabel); override;
  49. procedure a_jmp_flags(list : taasmoutput;const f : TResFlags;l: tasmlabel); override;
  50. procedure g_flags2reg(list: taasmoutput; size: TCgSize; const f: tresflags; reg: TRegister); override;
  51. procedure g_concatcopy(list : taasmoutput;const source,dest : treference;len : aword;delsource,loadref : boolean);override;
  52. { generates overflow checking code for a node }
  53. procedure g_overflowcheck(list: taasmoutput; const p: tnode); override;
  54. procedure g_copyvaluepara_openarray(list : taasmoutput;const ref:treference;elesize:integer); override;
  55. procedure g_stackframe_entry(list : taasmoutput;localsize : longint);override;
  56. procedure g_restore_frame_pointer(list : taasmoutput);override;
  57. procedure g_return_from_proc(list : taasmoutput;parasize : aword);override;
  58. procedure g_save_standard_registers(list : taasmoutput; usedinproc : tregisterset);override;
  59. procedure g_restore_standard_registers(list : taasmoutput; usedinproc : tregisterset);override;
  60. procedure g_save_all_registers(list : taasmoutput);override;
  61. procedure g_restore_all_registers(list : taasmoutput;selfused,accused,acchiused:boolean);override;
  62. protected
  63. function fixref(list: taasmoutput; var ref: treference): boolean;
  64. private
  65. { # Sign or zero extend the register to a full 32-bit value.
  66. The new value is left in the same register.
  67. }
  68. procedure sign_extend(list: taasmoutput;_oldsize : tcgsize; reg: tregister);
  69. procedure a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel);
  70. end;
  71. tcg64f68k = class(tcg64f32)
  72. procedure a_op64_reg_reg(list : taasmoutput;op:TOpCG;regsrc,regdst : tregister64);override;
  73. procedure a_op64_const_reg(list : taasmoutput;op:TOpCG;value : qword;reg : tregister64);override;
  74. end;
  75. { This function returns true if the reference+offset is valid.
  76. Otherwise extra code must be generated to solve the reference.
  77. On the m68k, this verifies that the reference is valid
  78. (e.g : if index register is used, then the max displacement
  79. is 256 bytes, if only base is used, then max displacement
  80. is 32K
  81. }
  82. function isvalidrefoffset(const ref: treference): boolean;
  83. const
  84. TCGSize2OpSize: Array[tcgsize] of topsize =
  85. (S_NO,S_B,S_W,S_L,S_L,S_B,S_W,S_L,S_L,
  86. S_FS,S_FD,S_FX,S_NO,
  87. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO);
  88. Implementation
  89. uses
  90. globtype,globals,verbose,systems,cutils,
  91. symdef,symsym,defbase,paramgr,
  92. rgobj,tgobj,rgcpu;
  93. const
  94. { opcode table lookup }
  95. topcg2tasmop: Array[topcg] of tasmop =
  96. (
  97. A_NONE,
  98. A_ADD,
  99. A_AND,
  100. A_DIVU,
  101. A_DIVS,
  102. A_MULS,
  103. A_MULU,
  104. A_NEG,
  105. A_NOT,
  106. A_OR,
  107. A_ASR,
  108. A_LSL,
  109. A_LSR,
  110. A_SUB,
  111. A_EOR
  112. );
  113. TOpCmp2AsmCond: Array[topcmp] of TAsmCond =
  114. (
  115. C_NONE,
  116. C_EQ,
  117. C_GT,
  118. C_LT,
  119. C_GE,
  120. C_LE,
  121. C_NE,
  122. C_LS,
  123. C_CS,
  124. C_CC,
  125. C_HI
  126. );
  127. function isvalidrefoffset(const ref: treference): boolean;
  128. begin
  129. isvalidrefoffset := true;
  130. if ref.index <> R_NO then
  131. begin
  132. if ref.base <> R_NO then
  133. internalerror(20020814);
  134. if (ref.offset < low(shortint)) or (ref.offset > high(shortint)) then
  135. isvalidrefoffset := false
  136. end
  137. else
  138. begin
  139. if (ref.offset < low(smallint)) or (ref.offset > high(smallint)) then
  140. isvalidrefoffset := false;
  141. end;
  142. end;
  143. {****************************************************************************}
  144. { TCG68K }
  145. {****************************************************************************}
  146. function tcg68k.fixref(list: taasmoutput; var ref: treference): boolean;
  147. var
  148. tmpreg: tregister;
  149. begin
  150. result := false;
  151. if (ref.base <> R_NO) then
  152. begin
  153. if (ref.index <> R_NO) and assigned(ref.symbol) then
  154. internalerror(20020814);
  155. { base + reg }
  156. if ref.index <> R_NO then
  157. begin
  158. { base + reg + offset }
  159. if (ref.offset < low(shortint)) or (ref.offset > high(shortint)) then
  160. begin
  161. list.concat(taicpu.op_const_reg(A_ADD,S_L,ref.offset,ref.base));
  162. fixref := true;
  163. ref.offset := 0;
  164. exit;
  165. end;
  166. end
  167. else
  168. { base + offset }
  169. if (ref.offset < low(smallint)) or (ref.offset > high(smallint)) then
  170. begin
  171. list.concat(taicpu.op_const_reg(A_ADD,S_L,ref.offset,ref.base));
  172. fixref := true;
  173. ref.offset := 0;
  174. exit;
  175. end;
  176. end;
  177. end;
  178. procedure tcg68k.a_call_name(list : taasmoutput;const s : string);
  179. begin
  180. list.concat(taicpu.op_sym(A_JSR,S_NO,objectlibrary.newasmsymbol(s)));
  181. end;
  182. procedure tcg68k.a_call_ref(list : taasmoutput;const ref : treference);
  183. var
  184. href : treference;
  185. begin
  186. href := ref;
  187. fixref(list,href);
  188. list.concat(taicpu.op_ref(A_JSR,S_NO,href));
  189. end;
  190. procedure tcg68k.a_call_reg(list : taasmoutput;reg : tregister);
  191. var
  192. href : treference;
  193. begin
  194. reference_reset_base(href, reg, 0);
  195. a_call_ref(href);
  196. end;
  197. procedure tcg68k.a_load_const_reg(list : taasmoutput;size : tcgsize;a : aword;register : tregister);
  198. begin
  199. if (rg.isaddressregister(register)) then
  200. begin
  201. list.concat(taicpu.op_const_reg(A_MOVE,S_L,a,register))
  202. end
  203. else
  204. if a = 0 then
  205. list.concat(taicpu.op_reg(A_CLR,S_L,register))
  206. else
  207. begin
  208. if (longint(a) >= low(shortint)) and (longint(a) <= high(shortint)) then
  209. list.concat(taicpu.op_const_reg(A_MOVEQ,S_L,a,register))
  210. else
  211. list.concat(taicpu.op_const_reg(A_MOVE,S_L,a,register))
  212. end;
  213. end;
  214. procedure tcg68k.a_load_reg_ref(list : taasmoutput;size : tcgsize;register : tregister;const ref : treference);
  215. var
  216. href : treference;
  217. begin
  218. href := ref;
  219. fixref(list,href);
  220. { move to destination reference }
  221. list.concat(taicpu.op_reg_ref(A_MOVE,TCGSize2OpSize[size],register,href));
  222. end;
  223. procedure tcg68k.a_load_reg_reg(list : taasmoutput;fromsize,tosize : tcgsize;reg1,reg2 : tregister);
  224. begin
  225. { move to destination register }
  226. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg1,reg2));
  227. { zero/sign extend register to 32-bit }
  228. sign_extend(list, fromsize, reg2);
  229. end;
  230. procedure tcg68k.a_load_ref_reg(list : taasmoutput;size : tcgsize;const ref : treference;register : tregister);
  231. var
  232. href : treference;
  233. begin
  234. href := ref;
  235. fixref(list,href);
  236. list.concat(taicpu.op_ref_reg(A_MOVE,TCGSize2OpSize[size],href,register));
  237. { extend the value in the register }
  238. sign_extend(list, size, register);
  239. end;
  240. procedure tcg68k.a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);
  241. var
  242. href : treference;
  243. begin
  244. if (not rg.isaddressregister(r)) then
  245. begin
  246. internalerror(2002072901);
  247. end;
  248. href:=ref;
  249. fixref(list, href);
  250. list.concat(taicpu.op_ref_reg(A_LEA,S_L,href,r));
  251. end;
  252. procedure tcg68k.a_loadfpu_reg_reg(list: taasmoutput; reg1, reg2: tregister);
  253. begin
  254. { in emulation mode, only 32-bit single is supported }
  255. if cs_fp_emulation in aktmoduleswitches then
  256. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg1,reg2))
  257. else
  258. list.concat(taicpu.op_reg_reg(A_FMOVE,S_FD,reg1,reg2));
  259. end;
  260. procedure tcg68k.a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister);
  261. var
  262. opsize : topsize;
  263. href : treference;
  264. begin
  265. opsize := tcgsize2opsize[size];
  266. { extended is not supported, since it is not available on Coldfire }
  267. if opsize = S_FX then
  268. internalerror(20020729);
  269. fixref(list,href);
  270. { in emulation mode, only 32-bit single is supported }
  271. if cs_fp_emulation in aktmoduleswitches then
  272. list.concat(taicpu.op_ref_reg(A_MOVE,S_L,href,reg))
  273. else
  274. list.concat(taicpu.op_ref_reg(A_FMOVE,opsize,href,reg));
  275. end;
  276. procedure tcg68k.a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference);
  277. var
  278. opsize : topsize;
  279. begin
  280. opsize := tcgsize2opsize[size];
  281. { extended is not supported, since it is not available on Coldfire }
  282. if opsize = S_FX then
  283. internalerror(20020729);
  284. { in emulation mode, only 32-bit single is supported }
  285. if cs_fp_emulation in aktmoduleswitches then
  286. list.concat(taicpu.op_reg_ref(A_MOVE,S_L,reg, ref))
  287. else
  288. list.concat(taicpu.op_reg_ref(A_FMOVE,opsize,reg, ref));
  289. end;
  290. procedure tcg68k.a_loadmm_reg_reg(list: taasmoutput; reg1, reg2: tregister);
  291. begin
  292. internalerror(20020729);
  293. end;
  294. procedure tcg68k.a_loadmm_ref_reg(list: taasmoutput; const ref: treference; reg: tregister);
  295. begin
  296. internalerror(20020729);
  297. end;
  298. procedure tcg68k.a_loadmm_reg_ref(list: taasmoutput; reg: tregister; const ref: treference);
  299. begin
  300. internalerror(20020729);
  301. end;
  302. procedure tcg68k.a_parammm_reg(list: taasmoutput; reg: tregister);
  303. begin
  304. internalerror(20020729);
  305. end;
  306. procedure tcg68k.a_op_const_reg(list : taasmoutput; Op: TOpCG; a: AWord; reg: TRegister);
  307. var
  308. scratch_reg : tregister;
  309. scratch_reg2: tregister;
  310. opcode : tasmop;
  311. begin
  312. { need to emit opcode? }
  313. if optimize_op_const_reg(list, op, a, reg) then
  314. exit;
  315. opcode := topcg2tasmop[op];
  316. case op of
  317. OP_ADD :
  318. Begin
  319. if (a >= 1) and (a <= 8) then
  320. list.concat(taicpu.op_const_reg(A_ADDQ,S_L,a, reg))
  321. else
  322. begin
  323. { all others, including coldfire }
  324. list.concat(taicpu.op_const_reg(A_ADD,S_L,a, reg));
  325. end;
  326. end;
  327. OP_AND,
  328. OP_OR:
  329. Begin
  330. list.concat(taicpu.op_const_reg(topcg2tasmop[op],S_L,a, reg));
  331. end;
  332. OP_DIV :
  333. Begin
  334. internalerror(20020816);
  335. end;
  336. OP_IDIV :
  337. Begin
  338. internalerror(20020816);
  339. end;
  340. OP_IMUL :
  341. Begin
  342. if aktoptprocessor = MC68000 then
  343. begin
  344. rg.getexplicitregisterint(list,R_D0);
  345. rg.getexplicitregisterint(list,R_D1);
  346. list.concat(taicpu.op_const_reg(A_MOVE,S_L,a, R_D0));
  347. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg, R_D1));
  348. cg.a_call_name(list,'FPC_MUL_LONGINT');
  349. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,R_D0, reg));
  350. rg.ungetregisterint(list,R_D0);
  351. rg.ungetregisterint(list,R_D1);
  352. end
  353. else
  354. begin
  355. if (rg.isaddressregister(reg)) then
  356. begin
  357. scratch_reg := cg.get_scratch_reg_int(list);
  358. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg, scratch_reg));
  359. list.concat(taicpu.op_const_reg(A_MULS,S_L,a,scratch_reg));
  360. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,scratch_reg,reg));
  361. cg.free_scratch_reg(list,scratch_reg);
  362. end
  363. else
  364. list.concat(taicpu.op_const_reg(A_MULS,S_L,a,reg));
  365. end;
  366. end;
  367. OP_MUL :
  368. Begin
  369. if aktoptprocessor = MC68000 then
  370. begin
  371. rg.getexplicitregisterint(list,R_D0);
  372. rg.getexplicitregisterint(list,R_D1);
  373. list.concat(taicpu.op_const_reg(A_MOVE,S_L,a, R_D0));
  374. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg, R_D1));
  375. cg.a_call_name(list,'FPC_MUL_LONGWORD');
  376. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,R_D0, reg));
  377. rg.ungetregisterint(list,R_D0);
  378. rg.ungetregisterint(list,R_D1);
  379. end
  380. else
  381. begin
  382. if (rg.isaddressregister(reg)) then
  383. begin
  384. scratch_reg := cg.get_scratch_reg_int(list);
  385. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg, scratch_reg));
  386. list.concat(taicpu.op_const_reg(A_MULU,S_L,a,scratch_reg));
  387. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,scratch_reg,reg));
  388. cg.free_scratch_reg(list,scratch_reg);
  389. end
  390. else
  391. list.concat(taicpu.op_const_reg(A_MULU,S_L,a,reg));
  392. end;
  393. end;
  394. OP_SAR,
  395. OP_SHL,
  396. OP_SHR :
  397. Begin
  398. if (a >= 1) and (a <= 8) then
  399. begin
  400. { now allowed to shift an address register }
  401. if (rg.isaddressregister(reg)) then
  402. begin
  403. scratch_reg := cg.get_scratch_reg_int(list);
  404. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg, scratch_reg));
  405. list.concat(taicpu.op_const_reg(opcode,S_L,a, scratch_reg));
  406. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,scratch_reg,reg));
  407. cg.free_scratch_reg(list,scratch_reg);
  408. end
  409. else
  410. list.concat(taicpu.op_const_reg(opcode,S_L,a, reg));
  411. end
  412. else
  413. begin
  414. { we must load the data into a register ... :() }
  415. scratch_reg := cg.get_scratch_reg_int(list);
  416. list.concat(taicpu.op_const_reg(A_MOVE,S_L,a, scratch_reg));
  417. { again... since shifting with address register is not allowed }
  418. if (rg.isaddressregister(reg)) then
  419. begin
  420. scratch_reg2 := cg.get_scratch_reg_int(list);
  421. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg, scratch_reg2));
  422. list.concat(taicpu.op_reg_reg(opcode,S_L,scratch_reg, scratch_reg2));
  423. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,scratch_reg2,reg));
  424. cg.free_scratch_reg(list,scratch_reg2);
  425. end
  426. else
  427. list.concat(taicpu.op_reg_reg(opcode,S_L,scratch_reg, reg));
  428. cg.free_scratch_reg(list,scratch_reg);
  429. end;
  430. end;
  431. OP_SUB :
  432. Begin
  433. if (a >= 1) and (a <= 8) then
  434. list.concat(taicpu.op_const_reg(A_SUBQ,S_L,a,reg))
  435. else
  436. begin
  437. { all others, including coldfire }
  438. list.concat(taicpu.op_const_reg(A_SUB,S_L,a, reg));
  439. end;
  440. end;
  441. OP_XOR :
  442. Begin
  443. list.concat(taicpu.op_const_reg(A_EORI,S_L,a, reg));
  444. end;
  445. else
  446. internalerror(20020729);
  447. end;
  448. end;
  449. procedure tcg68k.a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; reg1, reg2: TRegister);
  450. var
  451. hreg1,hreg2: tregister;
  452. begin
  453. case op of
  454. OP_ADD :
  455. Begin
  456. if aktoptprocessor = ColdFire then
  457. begin
  458. { operation only allowed only a longword }
  459. sign_extend(list, size, reg1);
  460. sign_extend(list, size, reg2);
  461. list.concat(taicpu.op_reg_reg(A_ADD,S_L,reg1, reg2));
  462. end
  463. else
  464. begin
  465. list.concat(taicpu.op_reg_reg(A_ADD,TCGSize2OpSize[size],reg1, reg2));
  466. end;
  467. end;
  468. OP_AND,OP_OR,
  469. OP_SAR,OP_SHL,
  470. OP_SHR,OP_SUB,OP_XOR :
  471. Begin
  472. { load to data registers }
  473. if (rg.isaddressregister(reg1)) then
  474. begin
  475. hreg1 := cg.get_scratch_reg_int(list);
  476. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg1,hreg1));
  477. end
  478. else
  479. hreg1 := reg1;
  480. if (rg.isaddressregister(reg2)) then
  481. begin
  482. hreg2:= cg.get_scratch_reg_int(list);
  483. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg2,hreg2));
  484. end
  485. else
  486. hreg2 := reg2;
  487. if aktoptprocessor = ColdFire then
  488. begin
  489. { operation only allowed only a longword }
  490. {!***************************************
  491. in the case of shifts, the value to
  492. shift by, should already be valid, so
  493. no need to sign extend the value
  494. !
  495. }
  496. if op in [OP_AND,OP_OR,OP_SUB,OP_XOR] then
  497. sign_extend(list, size, hreg1);
  498. sign_extend(list, size, hreg2);
  499. list.concat(taicpu.op_reg_reg(topcg2tasmop[op],S_L,hreg1, hreg2));
  500. end
  501. else
  502. begin
  503. list.concat(taicpu.op_reg_reg(topcg2tasmop[op],TCGSize2OpSize[size],hreg1, hreg2));
  504. end;
  505. if reg1 <> hreg1 then
  506. cg.free_scratch_reg(list,hreg1);
  507. { move back result into destination register }
  508. if reg2 <> hreg2 then
  509. begin
  510. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,hreg2,reg2));
  511. cg.free_scratch_reg(list,hreg2);
  512. end;
  513. end;
  514. OP_DIV :
  515. Begin
  516. internalerror(20020816);
  517. end;
  518. OP_IDIV :
  519. Begin
  520. internalerror(20020816);
  521. end;
  522. OP_IMUL :
  523. Begin
  524. sign_extend(list, size,reg1);
  525. sign_extend(list, size,reg2);
  526. if aktoptprocessor = MC68000 then
  527. begin
  528. rg.getexplicitregisterint(list,R_D0);
  529. rg.getexplicitregisterint(list,R_D1);
  530. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg1, R_D0));
  531. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg2, R_D1));
  532. cg.a_call_name(list,'FPC_MUL_LONGINT');
  533. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,R_D0, reg2));
  534. rg.ungetregisterint(list,R_D0);
  535. rg.ungetregisterint(list,R_D1);
  536. end
  537. else
  538. begin
  539. if (rg.isaddressregister(reg1)) then
  540. hreg1 := cg.get_scratch_reg_int(list)
  541. else
  542. hreg1 := reg1;
  543. if (rg.isaddressregister(reg2)) then
  544. hreg2:= cg.get_scratch_reg_int(list)
  545. else
  546. hreg2 := reg2;
  547. if reg1 <> hreg1 then
  548. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg1,hreg1));
  549. if reg2 <> hreg2 then
  550. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg2,hreg2));
  551. list.concat(taicpu.op_reg_reg(A_MULS,S_L,reg1,reg2));
  552. if reg1 <> hreg1 then
  553. cg.free_scratch_reg(list,hreg1);
  554. { move back result into destination register }
  555. if reg2 <> hreg2 then
  556. begin
  557. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,hreg2,reg2));
  558. cg.free_scratch_reg(list,hreg2);
  559. end;
  560. end;
  561. end;
  562. OP_MUL :
  563. Begin
  564. sign_extend(list, size,reg1);
  565. sign_extend(list, size,reg2);
  566. if aktoptprocessor = MC68000 then
  567. begin
  568. rg.getexplicitregisterint(list,R_D0);
  569. rg.getexplicitregisterint(list,R_D1);
  570. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg1, R_D0));
  571. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg2, R_D1));
  572. cg.a_call_name(list,'FPC_MUL_LONGWORD');
  573. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,R_D0, reg2));
  574. rg.ungetregisterint(list,R_D0);
  575. rg.ungetregisterint(list,R_D1);
  576. end
  577. else
  578. begin
  579. if (rg.isaddressregister(reg1)) then
  580. begin
  581. hreg1 := cg.get_scratch_reg_int(list);
  582. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg1,hreg1));
  583. end
  584. else
  585. hreg1 := reg1;
  586. if (rg.isaddressregister(reg2)) then
  587. begin
  588. hreg2:= cg.get_scratch_reg_int(list);
  589. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg2,hreg2));
  590. end
  591. else
  592. hreg2 := reg2;
  593. list.concat(taicpu.op_reg_reg(A_MULU,S_L,reg1,reg2));
  594. if reg1 <> hreg1 then
  595. cg.free_scratch_reg(list,hreg1);
  596. { move back result into destination register }
  597. if reg2 <> hreg2 then
  598. begin
  599. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,hreg2,reg2));
  600. cg.free_scratch_reg(list,hreg2);
  601. end;
  602. end;
  603. end;
  604. OP_NEG,
  605. OP_NOT :
  606. Begin
  607. if reg1 <> R_NO then
  608. internalerror(200112291);
  609. if (rg.isaddressregister(reg2)) then
  610. begin
  611. hreg2 := cg.get_scratch_reg_int(list);
  612. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg2,hreg2));
  613. end
  614. else
  615. hreg2 := reg2;
  616. { coldfire only supports long version }
  617. if aktoptprocessor = ColdFire then
  618. begin
  619. sign_extend(list, size,hreg2);
  620. list.concat(taicpu.op_reg(topcg2tasmop[op],S_L,hreg2));
  621. end
  622. else
  623. begin
  624. list.concat(taicpu.op_reg(topcg2tasmop[op],TCGSize2OpSize[size],hreg2));
  625. end;
  626. if reg2 <> hreg2 then
  627. begin
  628. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,hreg2,reg2));
  629. cg.free_scratch_reg(list,hreg2);
  630. end;
  631. end;
  632. else
  633. internalerror(20020729);
  634. end;
  635. end;
  636. procedure tcg68k.a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;reg : tregister;
  637. l : tasmlabel);
  638. var
  639. hregister : tregister;
  640. begin
  641. if a = 0 then
  642. begin
  643. list.concat(taicpu.op_reg(A_TST,TCGSize2OpSize[size],reg));
  644. end
  645. else
  646. begin
  647. if (aktoptprocessor = ColdFire) then
  648. begin
  649. {
  650. only longword comparison is supported,
  651. and only on data registers.
  652. }
  653. hregister := cg.get_scratch_reg_int(list);
  654. { always move to a data register }
  655. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg,hregister));
  656. { sign/zero extend the register }
  657. sign_extend(list, size,hregister);
  658. list.concat(taicpu.op_const_reg(A_CMPI,S_L,a,hregister));
  659. cg.free_scratch_reg(list,hregister);
  660. end
  661. else
  662. begin
  663. list.concat(taicpu.op_const_reg(A_CMPI,TCGSize2OpSize[size],a,reg));
  664. end;
  665. end;
  666. { emit the actual jump to the label }
  667. a_jmp_cond(list,cmp_op,l);
  668. end;
  669. procedure tcg68k.a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;reg1,reg2 : tregister;l : tasmlabel);
  670. begin
  671. list.concat(taicpu.op_reg_reg(A_CMP,tcgsize2opsize[size],reg1,reg2));
  672. { emit the actual jump to the label }
  673. a_jmp_cond(list,cmp_op,l);
  674. end;
  675. procedure tcg68k.a_jmp_always(list : taasmoutput;l: tasmlabel);
  676. var
  677. ai: taicpu;
  678. begin
  679. ai := Taicpu.op_sym(A_JMP,S_NO,l);
  680. ai.is_jmp := true;
  681. list.concat(ai);
  682. end;
  683. procedure tcg68k.a_jmp_flags(list : taasmoutput;const f : TResFlags;l: tasmlabel);
  684. var
  685. ai : taicpu;
  686. begin
  687. ai := Taicpu.op_sym(A_BXX,S_NO,l);
  688. ai.SetCondition(flags_to_cond(f));
  689. ai.is_jmp := true;
  690. list.concat(ai);
  691. end;
  692. procedure tcg68k.g_flags2reg(list: taasmoutput; size: TCgSize; const f: tresflags; reg: TRegister);
  693. var
  694. ai : taicpu;
  695. hreg : tregister;
  696. begin
  697. { move to a Dx register? }
  698. if (rg.isaddressregister(reg)) then
  699. begin
  700. hreg := get_scratch_reg_int(list);
  701. a_load_const_reg(list,size,0,hreg);
  702. ai:=Taicpu.Op_reg(A_Sxx,S_B,hreg);
  703. ai.SetCondition(flags_to_cond(f));
  704. list.concat(ai);
  705. if (aktoptprocessor = ColdFire) then
  706. begin
  707. { neg.b does not exist on the Coldfire
  708. so we need to sign extend the value
  709. before doing a neg.l
  710. }
  711. list.concat(taicpu.op_reg(A_EXTB,S_L,hreg));
  712. list.concat(taicpu.op_reg(A_NEG,S_L,hreg));
  713. end
  714. else
  715. begin
  716. list.concat(taicpu.op_reg(A_NEG,S_B,hreg));
  717. end;
  718. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,hreg,reg));
  719. free_scratch_reg(list,hreg);
  720. end
  721. else
  722. begin
  723. a_load_const_reg(list,size,0,reg);
  724. ai:=Taicpu.Op_reg(A_Sxx,S_B,reg);
  725. ai.SetCondition(flags_to_cond(f));
  726. list.concat(ai);
  727. if (aktoptprocessor = ColdFire) then
  728. begin
  729. { neg.b does not exist on the Coldfire
  730. so we need to sign extend the value
  731. before doing a neg.l
  732. }
  733. list.concat(taicpu.op_reg(A_EXTB,S_L,reg));
  734. list.concat(taicpu.op_reg(A_NEG,S_L,reg));
  735. end
  736. else
  737. begin
  738. list.concat(taicpu.op_reg(A_NEG,S_B,reg));
  739. end;
  740. end;
  741. end;
  742. procedure tcg68k.g_concatcopy(list : taasmoutput;const source,dest : treference;len : aword;delsource,loadref : boolean);
  743. var
  744. helpsize : longint;
  745. i : byte;
  746. reg8,reg32 : tregister;
  747. swap : boolean;
  748. hregister : tregister;
  749. iregister : tregister;
  750. jregister : tregister;
  751. hp1 : treference;
  752. hp2 : treference;
  753. hl : tasmlabel;
  754. hl2: tasmlabel;
  755. popaddress : boolean;
  756. srcref,dstref : treference;
  757. begin
  758. popaddress := false;
  759. { this should never occur }
  760. if len > 65535 then
  761. internalerror(0);
  762. hregister := get_scratch_reg_int(list);
  763. if delsource then
  764. reference_release(list,source);
  765. { from 12 bytes movs is being used }
  766. if (not loadref) and ((len<=8) or (not(cs_littlesize in aktglobalswitches) and (len<=12))) then
  767. begin
  768. srcref := source;
  769. dstref := dest;
  770. helpsize:=len div 4;
  771. { move a dword x times }
  772. for i:=1 to helpsize do
  773. begin
  774. a_load_ref_reg(list,OS_INT,srcref,hregister);
  775. a_load_reg_ref(list,OS_INT,hregister,dstref);
  776. inc(srcref.offset,4);
  777. inc(dstref.offset,4);
  778. dec(len,4);
  779. end;
  780. { move a word }
  781. if len>1 then
  782. begin
  783. a_load_ref_reg(list,OS_16,srcref,hregister);
  784. a_load_reg_ref(list,OS_16,hregister,dstref);
  785. inc(srcref.offset,2);
  786. inc(dstref.offset,2);
  787. dec(len,2);
  788. end;
  789. { move a single byte }
  790. if len>0 then
  791. begin
  792. a_load_ref_reg(list,OS_8,srcref,hregister);
  793. a_load_reg_ref(list,OS_8,hregister,dstref);
  794. end
  795. end
  796. else
  797. begin
  798. iregister := get_scratch_reg_address(list);
  799. jregister := get_scratch_reg_address(list);
  800. { reference for move (An)+,(An)+ }
  801. reference_reset(hp1);
  802. hp1.base := iregister; { source register }
  803. hp1.direction := dir_inc;
  804. reference_reset(hp2);
  805. hp2.base := jregister;
  806. hp2.direction := dir_inc;
  807. { iregister = source }
  808. { jregister = destination }
  809. if loadref then
  810. a_load_ref_reg(list,OS_INT,source,iregister)
  811. else
  812. a_loadaddr_ref_reg(list,source,iregister);
  813. a_loadaddr_ref_reg(list,dest,jregister);
  814. { double word move only on 68020+ machines }
  815. { because of possible alignment problems }
  816. { use fast loop mode }
  817. if (aktoptprocessor=MC68020) then
  818. begin
  819. helpsize := len - len mod 4;
  820. len := len mod 4;
  821. list.concat(taicpu.op_const_reg(A_MOVE,S_L,helpsize div 4,hregister));
  822. objectlibrary.getlabel(hl2);
  823. a_jmp_always(list,hl2);
  824. objectlibrary.getlabel(hl);
  825. a_label(list,hl);
  826. list.concat(taicpu.op_ref_ref(A_MOVE,S_L,hp1,hp2));
  827. cg.a_label(list,hl2);
  828. list.concat(taicpu.op_reg_sym(A_DBRA,S_L,hregister,hl));
  829. if len > 1 then
  830. begin
  831. dec(len,2);
  832. list.concat(taicpu.op_ref_ref(A_MOVE,S_W,hp1,hp2));
  833. end;
  834. if len = 1 then
  835. list.concat(taicpu.op_ref_ref(A_MOVE,S_B,hp1,hp2));
  836. end
  837. else
  838. begin
  839. { Fast 68010 loop mode with no possible alignment problems }
  840. helpsize := len;
  841. list.concat(taicpu.op_const_reg(A_MOVE,S_L,helpsize,hregister));
  842. objectlibrary.getlabel(hl2);
  843. a_jmp_always(list,hl2);
  844. objectlibrary.getlabel(hl);
  845. a_label(list,hl);
  846. list.concat(taicpu.op_ref_ref(A_MOVE,S_B,hp1,hp2));
  847. a_label(list,hl2);
  848. list.concat(taicpu.op_reg_sym(A_DBRA,S_L,hregister,hl));
  849. end;
  850. { restore the registers that we have just used olny if they are used! }
  851. if jregister = R_A1 then
  852. hp2.base := R_NO;
  853. if iregister = R_A0 then
  854. hp1.base := R_NO;
  855. reference_release(list,hp1);
  856. reference_release(list,hp2);
  857. end;
  858. { loading SELF-reference again }
  859. g_maybe_loadself(list);
  860. if delsource then
  861. tg.ungetiftemp(list,source);
  862. free_scratch_reg(list,hregister);
  863. end;
  864. procedure tcg68k.g_overflowcheck(list: taasmoutput; const p: tnode);
  865. begin
  866. end;
  867. procedure tcg68k.g_copyvaluepara_openarray(list : taasmoutput;const ref:treference;elesize:integer);
  868. begin
  869. end;
  870. procedure tcg68k.g_stackframe_entry(list : taasmoutput;localsize : longint);
  871. begin
  872. if localsize<>0 then
  873. begin
  874. { Not to complicate the code generator too much, and since some }
  875. { of the systems only support this format, the localsize cannot }
  876. { exceed 32K in size. }
  877. if (localsize < low(smallint)) or (localsize > high(smallint)) then
  878. CGMessage(cg_e_stacklimit_in_local_routine);
  879. list.concat(taicpu.op_reg_const(A_LINK,S_W,frame_pointer_reg,-localsize));
  880. end { endif localsize <> 0 }
  881. else
  882. begin
  883. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,frame_pointer_reg,R_SPPUSH));
  884. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,stack_pointer_reg,frame_pointer_reg));
  885. end;
  886. end;
  887. procedure tcg68k.g_restore_frame_pointer(list : taasmoutput);
  888. begin
  889. list.concat(taicpu.op_reg(A_UNLK,S_NO,frame_pointer_reg));
  890. end;
  891. procedure tcg68k.g_return_from_proc(list : taasmoutput;parasize : aword);
  892. var
  893. hregister : tregister;
  894. begin
  895. {Routines with the poclearstack flag set use only a ret.}
  896. { also routines with parasize=0 }
  897. if (po_clearstack in aktprocdef.procoptions) then
  898. begin
  899. { complex return values are removed from stack in C code PM }
  900. if paramanager.ret_in_param(aktprocdef.rettype.def) then
  901. list.concat(taicpu.op_const(A_RTD,S_NO,4))
  902. else
  903. list.concat(taicpu.op_none(A_RTS,S_NO));
  904. end
  905. else if (parasize=0) then
  906. begin
  907. list.concat(taicpu.op_none(A_RTS,S_NO));
  908. end
  909. else
  910. begin
  911. { return with immediate size possible here }
  912. { signed! }
  913. { RTD is not supported on the coldfire }
  914. if (aktoptprocessor = MC68020) and (parasize < $7FFF) then
  915. list.concat(taicpu.op_const(A_RTD,S_NO,parasize))
  916. { manually restore the stack }
  917. else
  918. begin
  919. { We must pull the PC Counter from the stack, before }
  920. { restoring the stack pointer, otherwise the PC would }
  921. { point to nowhere! }
  922. { save the PC counter (pop it from the stack) }
  923. hregister := get_scratch_reg_address(list);
  924. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,R_SPPULL,hregister));
  925. { can we do a quick addition ... }
  926. if (parasize > 0) and (parasize < 9) then
  927. list.concat(taicpu.op_const_reg(A_ADDQ,S_L,parasize,R_SP))
  928. else { nope ... }
  929. list.concat(taicpu.op_const_reg(A_ADD,S_L,parasize,R_SP));
  930. { restore the PC counter (push it on the stack) }
  931. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,hregister,R_SPPUSH));
  932. list.concat(taicpu.op_none(A_RTS,S_NO));
  933. free_scratch_reg(list,hregister);
  934. end;
  935. end;
  936. end;
  937. procedure tcg68k.g_save_standard_registers(list : taasmoutput; usedinproc : tregisterset);
  938. var
  939. tosave : tregisterlist;
  940. begin
  941. tosave:=std_saved_registers;
  942. { only save the registers which are not used and must be saved }
  943. tosave:=tosave*usedinproc;
  944. if tosave<>[] then
  945. list.concat(taicpu.op_reglist_reg(A_MOVEM,S_L,tosave,R_SPPUSH));
  946. end;
  947. procedure tcg68k.g_restore_standard_registers(list : taasmoutput; usedinproc : tregisterset);
  948. var
  949. torestore : tregisterset;
  950. begin
  951. torestore:=std_saved_registers;
  952. { should be intersected with used regs, no ? }
  953. torestore:=torestore*usedinproc;
  954. if torestore<>[] then
  955. list.concat(taicpu.op_reg_reglist(A_MOVEM,S_L,R_SPPULL,torestore));
  956. end;
  957. procedure tcg68k.g_save_all_registers(list : taasmoutput);
  958. begin
  959. end;
  960. procedure tcg68k.g_restore_all_registers(list : taasmoutput;selfused,accused,acchiused:boolean);
  961. begin
  962. end;
  963. procedure tcg68k.sign_extend(list: taasmoutput;_oldsize : tcgsize; reg: tregister);
  964. begin
  965. case _oldsize of
  966. { sign extend }
  967. OS_S8:
  968. begin
  969. if (rg.isaddressregister(reg)) then
  970. internalerror(20020729);
  971. if (aktoptprocessor = MC68000) then
  972. begin
  973. list.concat(taicpu.op_reg(A_EXT,S_W,reg));
  974. list.concat(taicpu.op_reg(A_EXT,S_L,reg));
  975. end
  976. else
  977. begin
  978. list.concat(taicpu.op_reg(A_EXTB,S_L,reg));
  979. end;
  980. end;
  981. OS_S16:
  982. begin
  983. if (rg.isaddressregister(reg)) then
  984. internalerror(20020729);
  985. list.concat(taicpu.op_reg(A_EXT,S_L,reg));
  986. end;
  987. { zero extend }
  988. OS_8:
  989. begin
  990. if (rg.isaddressregister(reg)) then
  991. internalerror(20020729);
  992. list.concat(taicpu.op_const_reg(A_AND,S_L,$FF,reg));
  993. end;
  994. OS_16:
  995. begin
  996. if (rg.isaddressregister(reg)) then
  997. internalerror(20020729);
  998. list.concat(taicpu.op_const_reg(A_AND,S_L,$FFFF,reg));
  999. end;
  1000. end; { otherwise the size is already correct }
  1001. end;
  1002. procedure tcg68k.a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel);
  1003. var
  1004. ai : taicpu;
  1005. begin
  1006. if cond=OC_None then
  1007. ai := Taicpu.Op_sym(A_JMP,S_NO,l)
  1008. else
  1009. begin
  1010. ai:=Taicpu.Op_sym(A_Bxx,S_NO,l);
  1011. ai.SetCondition(TOpCmp2AsmCond[cond]);
  1012. end;
  1013. ai.is_jmp:=true;
  1014. list.concat(ai);
  1015. end;
  1016. {****************************************************************************}
  1017. { TCG64F68K }
  1018. {****************************************************************************}
  1019. procedure tcg64f68k.a_op64_reg_reg(list : taasmoutput;op:TOpCG;regsrc,regdst : tregister64);
  1020. var
  1021. hreg1, hreg2 : tregister;
  1022. opcode : tasmop;
  1023. begin
  1024. opcode := topcg2tasmop[op];
  1025. case op of
  1026. OP_ADD :
  1027. begin
  1028. { if one of these three registers is an address
  1029. register, we'll really get into problems!
  1030. }
  1031. if rg.isaddressregister(regdst.reglo) or
  1032. rg.isaddressregister(regdst.reghi) or
  1033. rg.isaddressregister(regsrc.reghi) then
  1034. internalerror(20020817);
  1035. list.concat(taicpu.op_reg_reg(A_ADD,S_L,regsrc.reglo,regdst.reglo));
  1036. list.concat(taicpu.op_reg_reg(A_ADDX,S_L,regsrc.reghi,regdst.reghi));
  1037. end;
  1038. OP_AND,OP_OR :
  1039. begin
  1040. { at least one of the registers must be a data register }
  1041. if (rg.isaddressregister(regdst.reglo) and
  1042. rg.isaddressregister(regsrc.reglo)) or
  1043. (rg.isaddressregister(regsrc.reghi) and
  1044. rg.isaddressregister(regdst.reghi))
  1045. then
  1046. internalerror(20020817);
  1047. cg.a_op_reg_reg(list,op,OS_32,regsrc.reglo,regdst.reglo);
  1048. cg.a_op_reg_reg(list,op,OS_32,regsrc.reghi,regdst.reghi);
  1049. end;
  1050. { this is handled in 1st pass for 32-bit cpu's (helper call) }
  1051. OP_IDIV,OP_DIV,
  1052. OP_IMUL,OP_MUL: internalerror(2002081701);
  1053. { this is also handled in 1st pass for 32-bit cpu's (helper call) }
  1054. OP_SAR,OP_SHL,OP_SHR: internalerror(2002081702);
  1055. OP_SUB:
  1056. begin
  1057. { if one of these three registers is an address
  1058. register, we'll really get into problems!
  1059. }
  1060. if rg.isaddressregister(regdst.reglo) or
  1061. rg.isaddressregister(regdst.reghi) or
  1062. rg.isaddressregister(regsrc.reghi) then
  1063. internalerror(20020817);
  1064. list.concat(taicpu.op_reg_reg(A_SUB,S_L,regsrc.reglo,regdst.reglo));
  1065. list.concat(taicpu.op_reg_reg(A_SUBX,S_L,regsrc.reghi,regdst.reghi));
  1066. end;
  1067. OP_XOR:
  1068. begin
  1069. if rg.isaddressregister(regdst.reglo) or
  1070. rg.isaddressregister(regsrc.reglo) or
  1071. rg.isaddressregister(regsrc.reghi) or
  1072. rg.isaddressregister(regdst.reghi) then
  1073. internalerror(20020817);
  1074. list.concat(taicpu.op_reg_reg(A_EOR,S_L,regsrc.reglo,regdst.reglo));
  1075. list.concat(taicpu.op_reg_reg(A_EOR,S_L,regsrc.reghi,regdst.reghi));
  1076. end;
  1077. end; { end case }
  1078. end;
  1079. procedure tcg64f68k.a_op64_const_reg(list : taasmoutput;op:TOpCG;value : qword;reg : tregister64);
  1080. var
  1081. lowvalue : cardinal;
  1082. highvalue : cardinal;
  1083. begin
  1084. { is it optimized out ? }
  1085. if optimize64_op_const_reg(list,op,value,reg) then
  1086. exit;
  1087. lowvalue := cardinal(value);
  1088. highvalue:= value shr 32;
  1089. { the destination registers must be data registers }
  1090. if rg.isaddressregister(reg.reglo) or
  1091. rg.isaddressregister(reg.reghi) then
  1092. internalerror(20020817);
  1093. case op of
  1094. OP_ADD :
  1095. begin
  1096. list.concat(taicpu.op_const_reg(A_ADD,S_L,lowvalue,reg.reglo));
  1097. list.concat(taicpu.op_const_reg(A_ADDX,S_L,highvalue,reg.reglo));
  1098. end;
  1099. OP_AND :
  1100. begin
  1101. { should already be optimized out }
  1102. internalerror(2002081801);
  1103. end;
  1104. OP_OR :
  1105. begin
  1106. { should already be optimized out }
  1107. internalerror(2002081802);
  1108. end;
  1109. { this is handled in 1st pass for 32-bit cpu's (helper call) }
  1110. OP_IDIV,OP_DIV,
  1111. OP_IMUL,OP_MUL: internalerror(2002081701);
  1112. { this is also handled in 1st pass for 32-bit cpu's (helper call) }
  1113. OP_SAR,OP_SHL,OP_SHR: internalerror(2002081702);
  1114. OP_SUB:
  1115. begin
  1116. list.concat(taicpu.op_const_reg(A_SUB,S_L,lowvalue,reg.reglo));
  1117. list.concat(taicpu.op_const_reg(A_SUBX,S_L,highvalue,reg.reglo));
  1118. end;
  1119. OP_XOR:
  1120. begin
  1121. list.concat(taicpu.op_const_reg(A_EOR,S_L,lowvalue,reg.reglo));
  1122. list.concat(taicpu.op_const_reg(A_EOR,S_L,highvalue,reg.reglo));
  1123. end;
  1124. end; { end case }
  1125. end;
  1126. begin
  1127. cg := tcg68k.create;
  1128. cg64 :=tcg64f68k.create;
  1129. end.
  1130. {
  1131. $Log$
  1132. Revision 1.9 2002-09-17 18:54:05 jonas
  1133. * a_load_reg_reg() now has two size parameters: source and dest. This
  1134. allows some optimizations on architectures that don't encode the
  1135. register size in the register name.
  1136. Revision 1.8 2002/09/08 15:12:45 carl
  1137. + a_call_reg
  1138. Revision 1.7 2002/09/07 20:53:28 carl
  1139. * cardinal -> longword
  1140. Revision 1.6 2002/09/07 15:25:12 peter
  1141. * old logs removed and tabs fixed
  1142. Revision 1.5 2002/08/19 18:17:48 carl
  1143. + optimize64_op_const_reg implemented (optimizes 64-bit constant opcodes)
  1144. * more fixes to m68k for 64-bit operations
  1145. Revision 1.4 2002/08/16 14:24:59 carl
  1146. * issameref() to test if two references are the same (then emit no opcodes)
  1147. + ret_in_reg to replace ret_in_acc
  1148. (fix some register allocation bugs at the same time)
  1149. + save_std_register now has an extra parameter which is the
  1150. usedinproc registers
  1151. Revision 1.3 2002/08/15 08:13:54 carl
  1152. - a_load_sym_ofs_reg removed
  1153. * loadvmt now calls loadaddr_ref_reg instead
  1154. Revision 1.2 2002/08/14 19:16:34 carl
  1155. + m68k type conversion nodes
  1156. + started some mathematical nodes
  1157. * out of bound references should now be handled correctly
  1158. Revision 1.1 2002/08/13 18:30:22 carl
  1159. * rename swatoperands to swapoperands
  1160. + m68k first compilable version (still needs a lot of testing):
  1161. assembler generator, system information , inline
  1162. assembler reader.
  1163. Revision 1.5 2002/08/12 15:08:43 carl
  1164. + stab register indexes for powerpc (moved from gdb to cpubase)
  1165. + tprocessor enumeration moved to cpuinfo
  1166. + linker in target_info is now a class
  1167. * many many updates for m68k (will soon start to compile)
  1168. - removed some ifdef or correct them for correct cpu
  1169. Revision 1.2 2002/08/05 17:27:52 carl
  1170. + updated m68k
  1171. Revision 1.1 2002/07/29 17:51:32 carl
  1172. + restart m68k support
  1173. }