cgcpu.pas 51 KB

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