cgcpu.pas 85 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209
  1. {
  2. Copyright (c) 1998-2002 by the FPC team
  3. This unit implements the code generator for the 680x0
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit cgcpu;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cgbase,cgobj,globtype,
  22. aasmbase,aasmtai,aasmdata,aasmcpu,
  23. cpubase,cpuinfo,
  24. parabase,cpupara,
  25. node,symconst,symtype,symdef,
  26. cgutils,cg64f32;
  27. type
  28. tcg68k = class(tcg)
  29. procedure init_register_allocators;override;
  30. procedure done_register_allocators;override;
  31. procedure a_load_reg_cgpara(list : TAsmList;size : tcgsize;r : tregister;const cgpara : tcgpara);override;
  32. procedure a_load_const_cgpara(list : TAsmList;size : tcgsize;a : tcgint;const cgpara : tcgpara);override;
  33. procedure a_load_ref_cgpara(list : TAsmList;size : tcgsize;const r : treference;const cgpara : tcgpara);override;
  34. procedure a_loadaddr_ref_cgpara(list : TAsmList;const r : treference;const cgpara : tcgpara);override;
  35. procedure a_call_name(list : TAsmList;const s : string; weak: boolean);override;
  36. procedure a_call_reg(list : TAsmList;reg : tregister);override;
  37. procedure a_load_const_reg(list : TAsmList;size : tcgsize;a : tcgint;register : tregister);override;
  38. procedure a_load_const_ref(list : TAsmList; tosize: tcgsize; a : tcgint;const ref : treference);override;
  39. procedure a_load_reg_ref(list : TAsmList;fromsize,tosize : tcgsize;register : tregister;const ref : treference);override;
  40. procedure a_load_reg_reg(list : TAsmList;fromsize,tosize : tcgsize;reg1,reg2 : tregister);override;
  41. procedure a_load_ref_reg(list : TAsmList;fromsize,tosize : tcgsize;const ref : treference;register : tregister);override;
  42. procedure a_load_ref_ref(list : TAsmList;fromsize,tosize : tcgsize;const sref : treference;const dref : treference);override;
  43. procedure a_loadaddr_ref_reg(list : TAsmList;const ref : treference;r : tregister);override;
  44. procedure a_loadfpu_reg_reg(list: TAsmList; fromsize, tosize: tcgsize; reg1, reg2: tregister); override;
  45. procedure a_loadfpu_ref_reg(list: TAsmList; fromsize, tosize: tcgsize; const ref: treference; reg: tregister); override;
  46. procedure a_loadfpu_reg_ref(list: TAsmList; fromsize, tosize: tcgsize; reg: tregister; const ref: treference); override;
  47. procedure a_loadfpu_ref_cgpara(list : TAsmList; size : tcgsize;const ref : treference;const cgpara : TCGPara);override;
  48. procedure a_op_const_reg(list : TAsmList; Op: TOpCG; size: tcgsize; a: tcgint; reg: TRegister); override;
  49. procedure a_op_const_ref(list : TAsmList; Op: TOpCG; size: TCGSize; a: tcgint; const ref: TReference); override;
  50. procedure a_op_reg_reg(list : TAsmList; Op: TOpCG; size: TCGSize; src, dst: TRegister); override;
  51. procedure a_op_reg_ref(list : TAsmList; Op: TOpCG; size: TCGSize; reg: TRegister; const ref: TReference); override;
  52. procedure a_cmp_const_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;a : tcgint;reg : tregister; l : tasmlabel);override;
  53. procedure a_cmp_const_ref_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;a : tcgint;const ref : treference; l : tasmlabel); override;
  54. procedure a_cmp_reg_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;reg1,reg2 : tregister;l : tasmlabel); override;
  55. procedure a_jmp_name(list : TAsmList;const s : string); override;
  56. procedure a_jmp_always(list : TAsmList;l: tasmlabel); override;
  57. procedure a_jmp_flags(list : TAsmList;const f : TResFlags;l: tasmlabel); override;
  58. procedure g_flags2reg(list: TAsmList; size: TCgSize; const f: tresflags; reg: TRegister); override;
  59. procedure g_concatcopy(list : TAsmList;const source,dest : treference;len : tcgint);override;
  60. { generates overflow checking code for a node }
  61. procedure g_overflowcheck(list: TAsmList; const l:tlocation; def:tdef); override;
  62. procedure g_proc_entry(list : TAsmList;localsize : longint;nostackframe:boolean);override;
  63. procedure g_proc_exit(list : TAsmList;parasize:longint;nostackframe:boolean);override;
  64. procedure g_save_registers(list:TAsmList);override;
  65. procedure g_restore_registers(list:TAsmList);override;
  66. procedure g_adjust_self_value(list:TAsmList;procdef:tprocdef;ioffset:tcgint);override;
  67. procedure g_intf_wrapper(list: TAsmList; procdef: tprocdef; const labelname: string; ioffset: longint);override;
  68. { # Sign or zero extend the register to a full 32-bit value.
  69. The new value is left in the same register.
  70. }
  71. procedure sign_extend(list: TAsmList;_oldsize : tcgsize; reg: tregister);
  72. procedure sign_extend(list: TAsmList;_oldsize : tcgsize; _newsize : tcgsize; reg: tregister);
  73. procedure g_stackpointer_alloc(list : TAsmList;localsize : longint);override;
  74. function fixref(list: TAsmList; var ref: treference): boolean;
  75. protected
  76. procedure call_rtl_mul_const_reg(list:tasmlist;size:tcgsize;a:tcgint;reg:tregister;const name:string);
  77. procedure call_rtl_mul_reg_reg(list:tasmlist;reg1,reg2:tregister;const name:string);
  78. private
  79. procedure a_jmp_cond(list : TAsmList;cond : TOpCmp;l: tasmlabel);
  80. function force_to_dataregister(list: TAsmList; size: TCGSize; reg: TRegister): TRegister;
  81. procedure move_if_needed(list: TAsmList; size: TCGSize; src: TRegister; dest: TRegister);
  82. end;
  83. tcg64f68k = class(tcg64f32)
  84. procedure a_op64_reg_reg(list : TAsmList;op:TOpCG; size: tcgsize; regsrc,regdst : tregister64);override;
  85. procedure a_op64_const_reg(list : TAsmList;op:TOpCG; size: tcgsize; value : int64;regdst : tregister64);override;
  86. procedure a_op64_ref_reg(list : TAsmList;op:TOpCG;size : tcgsize;const ref : treference;reg : tregister64);override;
  87. end;
  88. { This function returns true if the reference+offset is valid.
  89. Otherwise extra code must be generated to solve the reference.
  90. On the m68k, this verifies that the reference is valid
  91. (e.g : if index register is used, then the max displacement
  92. is 256 bytes, if only base is used, then max displacement
  93. is 32K
  94. }
  95. function isvalidrefoffset(const ref: treference): boolean;
  96. function isvalidreference(const ref: treference): boolean;
  97. procedure create_codegen;
  98. implementation
  99. uses
  100. globals,verbose,systems,cutils,
  101. symsym,symtable,defutil,paramgr,procinfo,
  102. rgobj,tgobj,rgcpu,fmodule;
  103. const
  104. { opcode table lookup }
  105. topcg2tasmop: Array[topcg] of tasmop =
  106. (
  107. A_NONE,
  108. A_MOVE,
  109. A_ADD,
  110. A_AND,
  111. A_DIVU,
  112. A_DIVS,
  113. A_MULS,
  114. A_MULU,
  115. A_NEG,
  116. A_NOT,
  117. A_OR,
  118. A_ASR,
  119. A_LSL,
  120. A_LSR,
  121. A_SUB,
  122. A_EOR,
  123. A_ROL,
  124. A_ROR
  125. );
  126. { opcode with extend bits table lookup, used by 64bit cg }
  127. topcg2tasmopx: Array[topcg] of tasmop =
  128. (
  129. A_NONE,
  130. A_NONE,
  131. A_ADDX,
  132. A_NONE,
  133. A_NONE,
  134. A_NONE,
  135. A_NONE,
  136. A_NONE,
  137. A_NEGX,
  138. A_NONE,
  139. A_NONE,
  140. A_NONE,
  141. A_NONE,
  142. A_NONE,
  143. A_SUBX,
  144. A_NONE,
  145. A_NONE,
  146. A_NONE
  147. );
  148. TOpCmp2AsmCond: Array[topcmp] of TAsmCond =
  149. (
  150. C_NONE,
  151. C_EQ,
  152. C_GT,
  153. C_LT,
  154. C_GE,
  155. C_LE,
  156. C_NE,
  157. C_LS,
  158. C_CS,
  159. C_CC,
  160. C_HI
  161. );
  162. function isvalidreference(const ref: treference): boolean;
  163. begin
  164. isvalidreference:=isvalidrefoffset(ref) and
  165. { don't try to generate addressing with symbol and base reg and offset
  166. it might fail in linking stage if the symbol is more than 32k away (KB) }
  167. not (assigned(ref.symbol) and (ref.base <> NR_NO) and (ref.offset <> 0)) and
  168. { coldfire and 68000 cannot handle non-addressregs as bases }
  169. not ((current_settings.cputype in cpu_coldfire+[cpu_mc68000]) and
  170. not isaddressregister(ref.base));
  171. end;
  172. function isvalidrefoffset(const ref: treference): boolean;
  173. begin
  174. isvalidrefoffset := true;
  175. if ref.index <> NR_NO then
  176. begin
  177. // if ref.base <> NR_NO then
  178. // internalerror(2002081401);
  179. if (ref.offset < low(shortint)) or (ref.offset > high(shortint)) then
  180. isvalidrefoffset := false
  181. end
  182. else
  183. begin
  184. if (ref.offset < low(smallint)) or (ref.offset > high(smallint)) then
  185. isvalidrefoffset := false;
  186. end;
  187. end;
  188. {****************************************************************************}
  189. { TCG68K }
  190. {****************************************************************************}
  191. function use_push(const cgpara:tcgpara):boolean;
  192. begin
  193. result:=(not paramanager.use_fixed_stack) and
  194. assigned(cgpara.location) and
  195. (cgpara.location^.loc=LOC_REFERENCE) and
  196. (cgpara.location^.reference.index=NR_STACK_POINTER_REG);
  197. end;
  198. procedure tcg68k.init_register_allocators;
  199. var
  200. reg: TSuperRegister;
  201. address_regs: array of TSuperRegister;
  202. begin
  203. inherited init_register_allocators;
  204. address_regs:=nil;
  205. rg[R_INTREGISTER]:=trgcpu.create(R_INTREGISTER,R_SUBWHOLE,
  206. [RS_D0,RS_D1,RS_D2,RS_D3,RS_D4,RS_D5,RS_D6,RS_D7],
  207. first_int_imreg,[]);
  208. { set up the array of address registers to use }
  209. for reg:=RS_A0 to RS_A6 do
  210. begin
  211. { don't hardwire the frame pointer register, because it can vary between target OS }
  212. if assigned(current_procinfo) and (current_procinfo.framepointer = NR_FRAME_POINTER_REG)
  213. and (reg = RS_FRAME_POINTER_REG) then
  214. continue;
  215. setlength(address_regs,length(address_regs)+1);
  216. address_regs[length(address_regs)-1]:=reg;
  217. end;
  218. rg[R_ADDRESSREGISTER]:=trgcpu.create(R_ADDRESSREGISTER,R_SUBWHOLE,
  219. address_regs, first_addr_imreg, []);
  220. rg[R_FPUREGISTER]:=trgcpu.create(R_FPUREGISTER,R_SUBNONE,
  221. [RS_FP0,RS_FP1,RS_FP2,RS_FP3,RS_FP4,RS_FP5,RS_FP6,RS_FP7],
  222. first_fpu_imreg,[]);
  223. end;
  224. procedure tcg68k.done_register_allocators;
  225. begin
  226. rg[R_INTREGISTER].free;
  227. rg[R_FPUREGISTER].free;
  228. rg[R_ADDRESSREGISTER].free;
  229. inherited done_register_allocators;
  230. end;
  231. procedure tcg68k.a_load_reg_cgpara(list : TAsmList;size : tcgsize;r : tregister;const cgpara : tcgpara);
  232. var
  233. pushsize : tcgsize;
  234. ref : treference;
  235. begin
  236. { it's probably necessary to port this from x86 later, or provide an m68k solution (KB) }
  237. { TODO: FIX ME! check_register_size()}
  238. // check_register_size(size,r);
  239. if use_push(cgpara) then
  240. begin
  241. cgpara.check_simple_location;
  242. if tcgsize2size[cgpara.location^.size]>cgpara.alignment then
  243. pushsize:=cgpara.location^.size
  244. else
  245. pushsize:=int_cgsize(cgpara.alignment);
  246. reference_reset_base(ref, NR_STACK_POINTER_REG, 0, cgpara.alignment);
  247. ref.direction := dir_dec;
  248. list.concat(taicpu.op_reg_ref(A_MOVE,tcgsize2opsize[pushsize],makeregsize(list,r,pushsize),ref));
  249. end
  250. else
  251. inherited a_load_reg_cgpara(list,size,r,cgpara);
  252. end;
  253. procedure tcg68k.a_load_const_cgpara(list : TAsmList;size : tcgsize;a : tcgint;const cgpara : tcgpara);
  254. var
  255. pushsize : tcgsize;
  256. ref : treference;
  257. begin
  258. if use_push(cgpara) then
  259. begin
  260. cgpara.check_simple_location;
  261. if tcgsize2size[cgpara.location^.size]>cgpara.alignment then
  262. pushsize:=cgpara.location^.size
  263. else
  264. pushsize:=int_cgsize(cgpara.alignment);
  265. reference_reset_base(ref, NR_STACK_POINTER_REG, 0, cgpara.alignment);
  266. ref.direction := dir_dec;
  267. list.concat(taicpu.op_const_ref(A_MOVE,tcgsize2opsize[pushsize],a,ref));
  268. end
  269. else
  270. inherited a_load_const_cgpara(list,size,a,cgpara);
  271. end;
  272. procedure tcg68k.a_load_ref_cgpara(list : TAsmList;size : tcgsize;const r : treference;const cgpara : tcgpara);
  273. procedure pushdata(paraloc:pcgparalocation;ofs:tcgint);
  274. var
  275. pushsize : tcgsize;
  276. tmpreg : tregister;
  277. href : treference;
  278. ref : treference;
  279. begin
  280. if not assigned(paraloc) then
  281. exit;
  282. { TODO: FIX ME!!! this also triggers location bug }
  283. {if (paraloc^.loc<>LOC_REFERENCE) or
  284. (paraloc^.reference.index<>NR_STACK_POINTER_REG) or
  285. (tcgsize2size[paraloc^.size]>sizeof(tcgint)) then
  286. internalerror(200501162);}
  287. { Pushes are needed in reverse order, add the size of the
  288. current location to the offset where to load from. This
  289. prevents wrong calculations for the last location when
  290. the size is not a power of 2 }
  291. if assigned(paraloc^.next) then
  292. pushdata(paraloc^.next,ofs+tcgsize2size[paraloc^.size]);
  293. { Push the data starting at ofs }
  294. href:=r;
  295. inc(href.offset,ofs);
  296. fixref(list,href);
  297. if tcgsize2size[paraloc^.size]>cgpara.alignment then
  298. pushsize:=paraloc^.size
  299. else
  300. pushsize:=int_cgsize(cgpara.alignment);
  301. reference_reset_base(ref, NR_STACK_POINTER_REG, 0, tcgsize2size[pushsize]);
  302. ref.direction := dir_dec;
  303. if tcgsize2size[paraloc^.size]<cgpara.alignment then
  304. begin
  305. tmpreg:=getintregister(list,pushsize);
  306. a_load_ref_reg(list,paraloc^.size,pushsize,href,tmpreg);
  307. list.concat(taicpu.op_reg_ref(A_MOVE,tcgsize2opsize[pushsize],tmpreg,ref));
  308. end
  309. else
  310. list.concat(taicpu.op_ref_ref(A_MOVE,tcgsize2opsize[pushsize],href,ref));
  311. end;
  312. var
  313. len : tcgint;
  314. href : treference;
  315. begin
  316. { cgpara.size=OS_NO requires a copy on the stack }
  317. if use_push(cgpara) then
  318. begin
  319. { Record copy? }
  320. if (cgpara.size in [OS_NO,OS_F64]) or (size=OS_NO) then
  321. begin
  322. cgpara.check_simple_location;
  323. len:=align(cgpara.intsize,cgpara.alignment);
  324. g_stackpointer_alloc(list,len);
  325. reference_reset_base(href,NR_STACK_POINTER_REG,0,cgpara.alignment);
  326. g_concatcopy(list,r,href,len);
  327. end
  328. else
  329. begin
  330. if tcgsize2size[cgpara.size]<>tcgsize2size[size] then
  331. internalerror(200501161);
  332. { We need to push the data in reverse order,
  333. therefor we use a recursive algorithm }
  334. pushdata(cgpara.location,0);
  335. end
  336. end
  337. else
  338. inherited a_load_ref_cgpara(list,size,r,cgpara);
  339. end;
  340. procedure tcg68k.a_loadaddr_ref_cgpara(list : TAsmList;const r : treference;const cgpara : tcgpara);
  341. var
  342. tmpref : treference;
  343. begin
  344. { 68k always passes arguments on the stack }
  345. if use_push(cgpara) then
  346. begin
  347. //list.concat(tai_comment.create(strpnew('a_loadaddr_ref_cgpara: PEA')));
  348. cgpara.check_simple_location;
  349. tmpref:=r;
  350. fixref(list,tmpref);
  351. list.concat(taicpu.op_ref(A_PEA,S_NO,tmpref));
  352. end
  353. else
  354. inherited a_loadaddr_ref_cgpara(list,r,cgpara);
  355. end;
  356. function tcg68k.fixref(list: TAsmList; var ref: treference): boolean;
  357. var
  358. hreg,idxreg : tregister;
  359. href : treference;
  360. instr : taicpu;
  361. scale : aint;
  362. begin
  363. result:=false;
  364. { The MC68020+ has extended
  365. addressing capabilities with a 32-bit
  366. displacement.
  367. }
  368. { first ensure that base is an address register }
  369. if ((ref.base<>NR_NO) and (ref.index<>NR_NO)) and
  370. (not isaddressregister(ref.base) and isaddressregister(ref.index)) and
  371. (ref.scalefactor < 2) then
  372. begin
  373. { if we have both base and index registers, but base is data and index
  374. is address, we can just swap them, as FPC always uses long index.
  375. but we can only do this, if the index has no scalefactor }
  376. hreg:=ref.base;
  377. ref.base:=ref.index;
  378. ref.index:=hreg;
  379. //list.concat(tai_comment.create(strpnew('fixref: base and index swapped')));
  380. end;
  381. if (not assigned (ref.symbol) and (current_settings.cputype<>cpu_MC68000)) and
  382. (ref.base<>NR_NO) and not isaddressregister(ref.base) then
  383. begin
  384. hreg:=getaddressregister(list);
  385. instr:=taicpu.op_reg_reg(A_MOVE,S_L,ref.base,hreg);
  386. add_move_instruction(instr);
  387. list.concat(instr);
  388. fixref:=true;
  389. ref.base:=hreg;
  390. end;
  391. if (current_settings.cputype=cpu_MC68020) then
  392. exit;
  393. { ToDo: check which constraints of Coldfire also apply to MC68000 }
  394. case current_settings.cputype of
  395. cpu_MC68000:
  396. begin
  397. if (ref.base<>NR_NO) then
  398. begin
  399. if (ref.index<>NR_NO) and assigned(ref.symbol) then
  400. begin
  401. hreg:=getaddressregister(list);
  402. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,ref.base,hreg));
  403. list.concat(taicpu.op_reg_reg(A_ADD,S_L,ref.index,hreg));
  404. ref.index:=NR_NO;
  405. ref.base:=hreg;
  406. end;
  407. { base + reg }
  408. if ref.index <> NR_NO then
  409. begin
  410. { base + reg + offset }
  411. if (ref.offset < low(shortint)) or (ref.offset > high(shortint)) then
  412. begin
  413. hreg:=getaddressregister(list);
  414. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,ref.base,hreg));
  415. list.concat(taicpu.op_const_reg(A_ADD,S_L,ref.offset,hreg));
  416. fixref:=true;
  417. ref.offset:=0;
  418. ref.base:=hreg;
  419. exit;
  420. end;
  421. end
  422. else
  423. { base + offset }
  424. if (ref.offset < low(smallint)) or (ref.offset > high(smallint)) then
  425. begin
  426. hreg:=getaddressregister(list);
  427. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,ref.base,hreg));
  428. list.concat(taicpu.op_const_reg(A_ADD,S_L,ref.offset,hreg));
  429. fixref:=true;
  430. ref.offset:=0;
  431. ref.base:=hreg;
  432. exit;
  433. end;
  434. if assigned(ref.symbol) then
  435. begin
  436. hreg:=getaddressregister(list);
  437. idxreg:=ref.base;
  438. ref.base:=NR_NO;
  439. list.concat(taicpu.op_ref_reg(A_LEA,S_L,ref,hreg));
  440. reference_reset_base(ref,hreg,0,ref.alignment);
  441. fixref:=true;
  442. ref.index:=idxreg;
  443. end
  444. else if not isaddressregister(ref.base) then
  445. begin
  446. hreg:=getaddressregister(list);
  447. instr:=taicpu.op_reg_reg(A_MOVE,S_L,ref.base,hreg);
  448. //add_move_instruction(instr);
  449. list.concat(instr);
  450. fixref:=true;
  451. ref.base:=hreg;
  452. end;
  453. end
  454. else
  455. { Note: symbol -> ref would be supported as long as ref does not
  456. contain a offset or index... (maybe something for the
  457. optimizer) }
  458. if Assigned(ref.symbol) and (ref.index<>NR_NO) then
  459. begin
  460. hreg:=cg.getaddressregister(list);
  461. idxreg:=ref.index;
  462. ref.index:=NR_NO;
  463. list.concat(taicpu.op_ref_reg(A_LEA,S_L,ref,hreg));
  464. reference_reset_base(ref,hreg,0,ref.alignment);
  465. ref.index:=idxreg;
  466. fixref:=true;
  467. end;
  468. end;
  469. cpu_isa_a,
  470. cpu_isa_a_p,
  471. cpu_isa_b,
  472. cpu_isa_c:
  473. begin
  474. if (ref.base<>NR_NO) then
  475. begin
  476. if assigned(ref.symbol) then
  477. begin
  478. //list.concat(tai_comment.create(strpnew('fixref: symbol')));
  479. hreg:=cg.getaddressregister(list);
  480. reference_reset_symbol(href,ref.symbol,ref.offset,ref.alignment);
  481. list.concat(taicpu.op_ref_reg(A_LEA,S_L,href,hreg));
  482. if ref.index<>NR_NO then
  483. begin
  484. { fold the symbol + offset into the base, not the base into the index,
  485. because that might screw up the scalefactor of the reference }
  486. //list.concat(tai_comment.create(strpnew('fixref: symbol + offset (index + base)')));
  487. idxreg:=getaddressregister(list);
  488. reference_reset_base(href,ref.base,0,ref.alignment);
  489. href.index:=hreg;
  490. hreg:=getaddressregister(list);
  491. list.concat(taicpu.op_ref_reg(A_LEA,S_L,href,hreg));
  492. ref.base:=hreg;
  493. end
  494. else
  495. ref.index:=hreg;
  496. ref.offset:=0;
  497. ref.symbol:=nil;
  498. fixref:=true;
  499. end
  500. else
  501. { base + reg }
  502. if ref.index <> NR_NO then
  503. begin
  504. { base + reg + offset }
  505. if (ref.offset < low(shortint)) or (ref.offset > high(shortint)) then
  506. begin
  507. hreg:=getaddressregister(list);
  508. if (ref.offset < low(smallint)) or (ref.offset > high(smallint)) then
  509. begin
  510. instr:=taicpu.op_reg_reg(A_MOVE,S_L,ref.base,hreg);
  511. //add_move_instruction(instr);
  512. list.concat(instr);
  513. list.concat(taicpu.op_const_reg(A_ADD,S_L,ref.offset,hreg));
  514. end
  515. else
  516. begin
  517. //list.concat(tai_comment.create(strpnew('fixref: base + reg + offset lea')));
  518. reference_reset_base(href,ref.base,ref.offset,ref.alignment);
  519. list.concat(taicpu.op_ref_reg(A_LEA,S_NO,href,hreg));
  520. end;
  521. fixref:=true;
  522. ref.base:=hreg;
  523. ref.offset:=0;
  524. exit;
  525. end;
  526. end
  527. else
  528. { base + offset }
  529. if (ref.offset < low(smallint)) or (ref.offset > high(smallint)) then
  530. begin
  531. hreg:=getaddressregister(list);
  532. instr:=taicpu.op_reg_reg(A_MOVE,S_L,ref.base,hreg);
  533. //add_move_instruction(instr);
  534. list.concat(instr);
  535. list.concat(taicpu.op_const_reg(A_ADD,S_L,ref.offset,hreg));
  536. fixref:=true;
  537. ref.offset:=0;
  538. ref.base:=hreg;
  539. exit;
  540. end;
  541. end
  542. else
  543. { Note: symbol -> ref would be supported as long as ref does not
  544. contain a offset or index... (maybe something for the
  545. optimizer) }
  546. if Assigned(ref.symbol) {and (ref.index<>NR_NO)} then
  547. begin
  548. hreg:=cg.getaddressregister(list);
  549. idxreg:=ref.index;
  550. scale:=ref.scalefactor;
  551. ref.index:=NR_NO;
  552. list.concat(taicpu.op_ref_reg(A_LEA,S_L,ref,hreg));
  553. reference_reset_base(ref,hreg,0,ref.alignment);
  554. ref.index:=idxreg;
  555. ref.scalefactor:=scale;
  556. fixref:=true;
  557. end;
  558. end;
  559. end;
  560. end;
  561. procedure tcg68k.call_rtl_mul_const_reg(list:tasmlist;size:tcgsize;a:tcgint;reg:tregister;const name:string);
  562. var
  563. paraloc1,paraloc2,paraloc3 : tcgpara;
  564. pd : tprocdef;
  565. begin
  566. pd:=search_system_proc(name);
  567. paraloc1.init;
  568. paraloc2.init;
  569. paraloc3.init;
  570. paramanager.getintparaloc(pd,1,paraloc1);
  571. paramanager.getintparaloc(pd,2,paraloc2);
  572. paramanager.getintparaloc(pd,3,paraloc3);
  573. a_load_const_cgpara(list,OS_8,0,paraloc3);
  574. a_load_const_cgpara(list,size,a,paraloc2);
  575. a_load_reg_cgpara(list,OS_32,reg,paraloc1);
  576. paramanager.freecgpara(list,paraloc3);
  577. paramanager.freecgpara(list,paraloc2);
  578. paramanager.freecgpara(list,paraloc1);
  579. alloccpuregisters(list,R_ADDRESSREGISTER,paramanager.get_volatile_registers_address(pocall_default));
  580. alloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  581. a_call_name(list,name,false);
  582. dealloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  583. dealloccpuregisters(list,R_ADDRESSREGISTER,paramanager.get_volatile_registers_address(pocall_default));
  584. cg.a_reg_alloc(list,NR_FUNCTION_RESULT_REG);
  585. cg.a_load_reg_reg(list,OS_32,OS_32,NR_FUNCTION_RESULT_REG,reg);
  586. paraloc3.done;
  587. paraloc2.done;
  588. paraloc1.done;
  589. end;
  590. procedure tcg68k.call_rtl_mul_reg_reg(list:tasmlist;reg1,reg2:tregister;const name:string);
  591. var
  592. paraloc1,paraloc2,paraloc3 : tcgpara;
  593. pd : tprocdef;
  594. begin
  595. pd:=search_system_proc(name);
  596. paraloc1.init;
  597. paraloc2.init;
  598. paraloc3.init;
  599. paramanager.getintparaloc(pd,1,paraloc1);
  600. paramanager.getintparaloc(pd,2,paraloc2);
  601. paramanager.getintparaloc(pd,3,paraloc3);
  602. a_load_const_cgpara(list,OS_8,0,paraloc3);
  603. a_load_reg_cgpara(list,OS_32,reg1,paraloc2);
  604. a_load_reg_cgpara(list,OS_32,reg2,paraloc1);
  605. paramanager.freecgpara(list,paraloc3);
  606. paramanager.freecgpara(list,paraloc2);
  607. paramanager.freecgpara(list,paraloc1);
  608. alloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  609. alloccpuregisters(list,R_ADDRESSREGISTER,paramanager.get_volatile_registers_address(pocall_default));
  610. a_call_name(list,name,false);
  611. dealloccpuregisters(list,R_ADDRESSREGISTER,paramanager.get_volatile_registers_address(pocall_default));
  612. dealloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  613. cg.a_reg_alloc(list,NR_FUNCTION_RESULT_REG);
  614. cg.a_load_reg_reg(list,OS_32,OS_32,NR_FUNCTION_RESULT_REG,reg2);
  615. paraloc3.done;
  616. paraloc2.done;
  617. paraloc1.done;
  618. end;
  619. procedure tcg68k.a_call_name(list : TAsmList;const s : string; weak: boolean);
  620. var
  621. sym: tasmsymbol;
  622. begin
  623. if not(weak) then
  624. sym:=current_asmdata.RefAsmSymbol(s)
  625. else
  626. sym:=current_asmdata.WeakRefAsmSymbol(s);
  627. list.concat(taicpu.op_sym(A_JSR,S_NO,sym));
  628. end;
  629. procedure tcg68k.a_call_reg(list : TAsmList;reg: tregister);
  630. var
  631. tmpref : treference;
  632. tmpreg : tregister;
  633. instr : taicpu;
  634. begin
  635. if isaddressregister(reg) then
  636. begin
  637. { if we have an address register, we can jump to the address directly }
  638. reference_reset_base(tmpref,reg,0,4);
  639. end
  640. else
  641. begin
  642. { if we have a data register, we need to move it to an address register first }
  643. tmpreg:=getaddressregister(list);
  644. reference_reset_base(tmpref,tmpreg,0,4);
  645. instr:=taicpu.op_reg_reg(A_MOVE,S_L,reg,tmpreg);
  646. add_move_instruction(instr);
  647. list.concat(instr);
  648. end;
  649. list.concat(taicpu.op_ref(A_JSR,S_NO,tmpref));
  650. end;
  651. procedure tcg68k.a_load_const_reg(list : TAsmList;size : tcgsize;a : tcgint;register : tregister);
  652. var
  653. opsize: topsize;
  654. begin
  655. opsize:=tcgsize2opsize[size];
  656. if isaddressregister(register) then
  657. begin
  658. { an m68k manual I have recommends SUB Ax,Ax to be used instead of CLR for address regs }
  659. if a = 0 then
  660. list.concat(taicpu.op_reg_reg(A_SUB,S_L,register,register))
  661. else
  662. { ISA B/C Coldfire has MOV3Q which can move -1 or 1..7 to any reg }
  663. if (current_settings.cputype in [cpu_isa_b,cpu_isa_c]) and
  664. ((longint(a) = -1) or ((longint(a) > 0) and (longint(a) < 8))) then
  665. list.concat(taicpu.op_const_reg(A_MOV3Q,S_L,longint(a),register))
  666. else
  667. { We don't have to specify the size here, the assembler will decide the size of
  668. the operand it needs. If this ends up as a MOVEA.W, that will sign extend the
  669. value in the dest. reg to full 32 bits (specific to Ax regs only) }
  670. list.concat(taicpu.op_const_reg(A_MOVEA,S_NO,longint(a),register));
  671. end
  672. else
  673. if a = 0 then
  674. list.concat(taicpu.op_reg(A_CLR,S_L,register))
  675. else
  676. begin
  677. if (longint(a) >= low(shortint)) and (longint(a) <= high(shortint)) then
  678. list.concat(taicpu.op_const_reg(A_MOVEQ,S_L,longint(a),register))
  679. else
  680. begin
  681. { ISA B/C Coldfire has sign extend/zero extend moves }
  682. if (current_settings.cputype in [cpu_isa_b,cpu_isa_c]) and
  683. (size in [OS_16, OS_8, OS_S16, OS_S8]) and
  684. ((longint(a) >= low(smallint)) and (longint(a) <= high(smallint))) then
  685. begin
  686. if size in [OS_16, OS_8] then
  687. list.concat(taicpu.op_const_reg(A_MVZ,opsize,longint(a),register))
  688. else
  689. list.concat(taicpu.op_const_reg(A_MVS,opsize,longint(a),register));
  690. end
  691. else
  692. begin
  693. { clear the register first, for unsigned and positive values, so
  694. we don't need to zero extend after }
  695. if (size in [OS_16,OS_8]) or
  696. ((size in [OS_S16,OS_S8]) and (a > 0)) then
  697. list.concat(taicpu.op_reg(A_CLR,S_L,register));
  698. list.concat(taicpu.op_const_reg(A_MOVE,opsize,longint(a),register));
  699. { only sign extend if we need to, zero extension is not necessary because the CLR.L above }
  700. if (size in [OS_S16,OS_S8]) and (a < 0) then
  701. sign_extend(list,size,register);
  702. end;
  703. end;
  704. end;
  705. end;
  706. procedure tcg68k.a_load_const_ref(list : TAsmList; tosize: tcgsize; a : tcgint;const ref : treference);
  707. var
  708. hreg : tregister;
  709. href : treference;
  710. begin
  711. href:=ref;
  712. fixref(list,href);
  713. { for coldfire we need to go through a temporary register if we have a
  714. offset, index or symbol given }
  715. if (current_settings.cputype in cpu_coldfire) and
  716. (
  717. (href.offset<>0) or
  718. { TODO : check whether we really need this second condition }
  719. (href.index<>NR_NO) or
  720. assigned(href.symbol)
  721. ) then
  722. begin
  723. hreg:=getintregister(list,tosize);
  724. a_load_const_reg(list,tosize,a,hreg);
  725. list.concat(taicpu.op_reg_ref(A_MOVE,tcgsize2opsize[tosize],hreg,href));
  726. end
  727. else
  728. list.concat(taicpu.op_const_ref(A_MOVE,tcgsize2opsize[tosize],longint(a),href));
  729. end;
  730. procedure tcg68k.a_load_reg_ref(list : TAsmList;fromsize,tosize : tcgsize;register : tregister;const ref : treference);
  731. var
  732. href : treference;
  733. begin
  734. href := ref;
  735. fixref(list,href);
  736. if tcgsize2size[fromsize]<tcgsize2size[tosize] then
  737. a_load_reg_reg(list,fromsize,tosize,register,register);
  738. { move to destination reference }
  739. list.concat(taicpu.op_reg_ref(A_MOVE,TCGSize2OpSize[tosize],register,href));
  740. end;
  741. procedure tcg68k.a_load_ref_ref(list : TAsmList;fromsize,tosize : tcgsize;const sref : treference;const dref : treference);
  742. var
  743. aref: treference;
  744. bref: treference;
  745. tmpref : treference;
  746. dofix : boolean;
  747. hreg: TRegister;
  748. begin
  749. aref := sref;
  750. bref := dref;
  751. fixref(list,aref);
  752. fixref(list,bref);
  753. if TCGSize2OpSize[fromsize]<>TCGSize2OpSize[tosize] then
  754. begin
  755. { if we need to change the size then always use a temporary
  756. register }
  757. hreg:=getintregister(list,fromsize);
  758. list.concat(taicpu.op_ref_reg(A_MOVE,TCGSize2OpSize[fromsize],aref,hreg));
  759. sign_extend(list,fromsize,tosize,hreg);
  760. list.concat(taicpu.op_reg_ref(A_MOVE,TCGSize2OpSize[tosize],hreg,bref));
  761. exit;
  762. end;
  763. { Coldfire dislikes certain move combinations }
  764. if current_settings.cputype in cpu_coldfire then
  765. begin
  766. { TODO : move.b/w only allowed in newer coldfires... (ISA_B+) }
  767. dofix:=false;
  768. if { (d16,Ax) and (d8,Ax,Xi) }
  769. (
  770. (aref.base<>NR_NO) and
  771. (
  772. (aref.index<>NR_NO) or
  773. (aref.offset<>0)
  774. )
  775. ) or
  776. { (xxx) }
  777. assigned(aref.symbol) then
  778. begin
  779. if aref.index<>NR_NO then
  780. begin
  781. dofix:={ (d16,Ax) and (d8,Ax,Xi) }
  782. (
  783. (bref.base<>NR_NO) and
  784. (
  785. (bref.index<>NR_NO) or
  786. (bref.offset<>0)
  787. )
  788. ) or
  789. { (xxx) }
  790. assigned(bref.symbol);
  791. end
  792. else
  793. { offset <> 0, but no index }
  794. begin
  795. dofix:={ (d8,Ax,Xi) }
  796. (
  797. (bref.base<>NR_NO) and
  798. (bref.index<>NR_NO)
  799. ) or
  800. { (xxx) }
  801. assigned(bref.symbol);
  802. end;
  803. end;
  804. if dofix then
  805. begin
  806. hreg:=getaddressregister(list);
  807. reference_reset_base(tmpref,hreg,0,0);
  808. list.concat(taicpu.op_ref_reg(A_LEA,S_L,aref,hreg));
  809. list.concat(taicpu.op_ref_ref(A_MOVE,TCGSize2OpSize[fromsize],tmpref,bref));
  810. exit;
  811. end;
  812. end;
  813. list.concat(taicpu.op_ref_ref(A_MOVE,TCGSize2OpSize[fromsize],aref,bref));
  814. end;
  815. procedure tcg68k.a_load_reg_reg(list : TAsmList;fromsize,tosize : tcgsize;reg1,reg2 : tregister);
  816. var
  817. instr : taicpu;
  818. begin
  819. { move to destination register }
  820. instr:=taicpu.op_reg_reg(A_MOVE,TCGSize2OpSize[fromsize],reg1,reg2);
  821. add_move_instruction(instr);
  822. list.concat(instr);
  823. sign_extend(list, fromsize, reg2);
  824. end;
  825. procedure tcg68k.a_load_ref_reg(list : TAsmList;fromsize,tosize : tcgsize;const ref : treference;register : tregister);
  826. var
  827. href : treference;
  828. size : tcgsize;
  829. begin
  830. href:=ref;
  831. fixref(list,href);
  832. if tcgsize2size[fromsize]<tcgsize2size[tosize] then
  833. size:=fromsize
  834. else
  835. size:=tosize;
  836. list.concat(taicpu.op_ref_reg(A_MOVE,TCGSize2OpSize[size],href,register));
  837. { extend the value in the register }
  838. sign_extend(list, size, register);
  839. end;
  840. procedure tcg68k.a_loadaddr_ref_reg(list : TAsmList;const ref : treference;r : tregister);
  841. var
  842. href : treference;
  843. begin
  844. href:=ref;
  845. fixref(list, href);
  846. list.concat(taicpu.op_ref_reg(A_LEA,S_L,href,r));
  847. end;
  848. procedure tcg68k.a_loadfpu_reg_reg(list: TAsmList; fromsize, tosize: tcgsize; reg1, reg2: tregister);
  849. var
  850. instr : taicpu;
  851. begin
  852. { in emulation mode, only 32-bit single is supported }
  853. if (cs_fp_emulation in current_settings.moduleswitches) or (current_settings.fputype=fpu_soft) then
  854. instr:=taicpu.op_reg_reg(A_MOVE,S_L,reg1,reg2)
  855. else
  856. instr:=taicpu.op_reg_reg(A_FMOVE,tcgsize2opsize[tosize],reg1,reg2);
  857. add_move_instruction(instr);
  858. list.concat(instr);
  859. end;
  860. procedure tcg68k.a_loadfpu_ref_reg(list: TAsmList; fromsize, tosize: tcgsize; const ref: treference; reg: tregister);
  861. var
  862. opsize : topsize;
  863. href : treference;
  864. begin
  865. opsize := tcgsize2opsize[fromsize];
  866. { extended is not supported, since it is not available on Coldfire }
  867. if opsize = S_FX then
  868. internalerror(20020729);
  869. href := ref;
  870. fixref(list,href);
  871. { in emulation mode, only 32-bit single is supported }
  872. if (cs_fp_emulation in current_settings.moduleswitches) or (current_settings.fputype=fpu_soft) then
  873. list.concat(taicpu.op_ref_reg(A_MOVE,S_L,href,reg))
  874. else
  875. begin
  876. list.concat(taicpu.op_ref_reg(A_FMOVE,opsize,href,reg));
  877. if (tosize < fromsize) then
  878. a_loadfpu_reg_reg(list,fromsize,tosize,reg,reg);
  879. end;
  880. end;
  881. procedure tcg68k.a_loadfpu_reg_ref(list: TAsmList; fromsize,tosize: tcgsize; reg: tregister; const ref: treference);
  882. var
  883. opsize : topsize;
  884. begin
  885. opsize := tcgsize2opsize[tosize];
  886. { extended is not supported, since it is not available on Coldfire }
  887. if opsize = S_FX then
  888. internalerror(20020729);
  889. { in emulation mode, only 32-bit single is supported }
  890. if (cs_fp_emulation in current_settings.moduleswitches) or (current_settings.fputype=fpu_soft) then
  891. list.concat(taicpu.op_reg_ref(A_MOVE,S_L,reg, ref))
  892. else
  893. list.concat(taicpu.op_reg_ref(A_FMOVE,opsize,reg, ref));
  894. end;
  895. procedure tcg68k.a_loadfpu_ref_cgpara(list : TAsmList; size : tcgsize;const ref : treference;const cgpara : TCGPara);
  896. begin
  897. case cgpara.location^.loc of
  898. LOC_REFERENCE,LOC_CREFERENCE:
  899. begin
  900. case size of
  901. OS_F64:
  902. cg64.a_load64_ref_cgpara(list,ref,cgpara);
  903. OS_F32:
  904. a_load_ref_cgpara(list,size,ref,cgpara);
  905. else
  906. internalerror(2013021201);
  907. end;
  908. end;
  909. else
  910. inherited a_loadfpu_ref_cgpara(list,size,ref,cgpara);
  911. end;
  912. end;
  913. procedure tcg68k.a_op_const_reg(list : TAsmList; Op: TOpCG; size: tcgsize; a: tcgint; reg: TRegister);
  914. var
  915. scratch_reg : tregister;
  916. scratch_reg2: tregister;
  917. opcode : tasmop;
  918. begin
  919. optimize_op_const(size, op, a);
  920. opcode := topcg2tasmop[op];
  921. case op of
  922. OP_NONE :
  923. begin
  924. { Opcode is optimized away }
  925. end;
  926. OP_MOVE :
  927. begin
  928. { Optimized, replaced with a simple load }
  929. a_load_const_reg(list,size,a,reg);
  930. end;
  931. OP_ADD,
  932. OP_SUB:
  933. begin
  934. { add/sub works the same way, so have it unified here }
  935. if (a >= 1) and (a <= 8) then
  936. if (op = OP_ADD) then
  937. opcode:=A_ADDQ
  938. else
  939. opcode:=A_SUBQ;
  940. list.concat(taicpu.op_const_reg(opcode, S_L, a, reg));
  941. end;
  942. OP_AND,
  943. OP_OR,
  944. OP_XOR:
  945. begin
  946. scratch_reg := force_to_dataregister(list, size, reg);
  947. list.concat(taicpu.op_const_reg(opcode, S_L, a, scratch_reg));
  948. move_if_needed(list, size, scratch_reg, reg);
  949. end;
  950. OP_DIV,
  951. OP_IDIV:
  952. begin
  953. internalerror(20020816);
  954. end;
  955. OP_MUL,
  956. OP_IMUL:
  957. begin
  958. { NOTE: better have this as fast as possible on every CPU in all cases,
  959. because the compiler uses OP_IMUL for array indexing... (KB) }
  960. { ColdFire doesn't support MULS/MULU <imm>,dX }
  961. if current_settings.cputype in cpu_coldfire then
  962. begin
  963. { move const to a register first }
  964. scratch_reg := getintregister(list,OS_INT);
  965. a_load_const_reg(list, size, a, scratch_reg);
  966. { do the multiplication }
  967. scratch_reg2 := force_to_dataregister(list, size, reg);
  968. sign_extend(list, size, scratch_reg2);
  969. list.concat(taicpu.op_reg_reg(opcode,S_L,scratch_reg,scratch_reg2));
  970. { move the value back to the original register }
  971. move_if_needed(list, size, scratch_reg2, reg);
  972. end
  973. else
  974. begin
  975. if current_settings.cputype = cpu_mc68020 then
  976. begin
  977. { do the multiplication }
  978. scratch_reg := force_to_dataregister(list, size, reg);
  979. sign_extend(list, size, scratch_reg);
  980. list.concat(taicpu.op_const_reg(opcode,S_L,a,scratch_reg));
  981. { move the value back to the original register }
  982. move_if_needed(list, size, scratch_reg, reg);
  983. end
  984. else
  985. { Fallback branch, plain 68000 for now }
  986. { FIX ME: this is slow as hell, but original 68000 doesn't have 32x32 -> 32bit MUL (KB) }
  987. if op = OP_MUL then
  988. call_rtl_mul_const_reg(list, size, a, reg,'fpc_mul_dword')
  989. else
  990. call_rtl_mul_const_reg(list, size, a, reg,'fpc_mul_longint');
  991. end;
  992. end;
  993. OP_ROL,
  994. OP_ROR,
  995. OP_SAR,
  996. OP_SHL,
  997. OP_SHR :
  998. begin
  999. scratch_reg := force_to_dataregister(list, size, reg);
  1000. sign_extend(list, size, scratch_reg);
  1001. if (a >= 1) and (a <= 8) then
  1002. begin
  1003. list.concat(taicpu.op_const_reg(opcode, S_L, a, scratch_reg));
  1004. end
  1005. else
  1006. begin
  1007. { move const to a register first }
  1008. scratch_reg2 := getintregister(list,OS_INT);
  1009. a_load_const_reg(list, size, a, scratch_reg2);
  1010. { do the operation }
  1011. list.concat(taicpu.op_reg_reg(opcode, S_L, scratch_reg2, scratch_reg));
  1012. end;
  1013. { move the value back to the original register }
  1014. move_if_needed(list, size, scratch_reg, reg);
  1015. end;
  1016. else
  1017. internalerror(20020729);
  1018. end;
  1019. end;
  1020. procedure tcg68k.a_op_const_ref(list : TAsmList; Op: TOpCG; size: TCGSize; a: tcgint; const ref: TReference);
  1021. var
  1022. opcode: tasmop;
  1023. opsize: topsize;
  1024. href : treference;
  1025. begin
  1026. optimize_op_const(size, op, a);
  1027. opcode := topcg2tasmop[op];
  1028. opsize := TCGSize2OpSize[size];
  1029. { on ColdFire all arithmetic operations are only possible on 32bit }
  1030. if ((current_settings.cputype in cpu_coldfire) and (opsize <> S_L)
  1031. and not (op in [OP_NONE,OP_MOVE])) then
  1032. begin
  1033. inherited;
  1034. exit;
  1035. end;
  1036. case op of
  1037. OP_NONE :
  1038. begin
  1039. { opcode was optimized away }
  1040. end;
  1041. OP_MOVE :
  1042. begin
  1043. { Optimized, replaced with a simple load }
  1044. a_load_const_ref(list,size,a,ref);
  1045. end;
  1046. OP_ADD,
  1047. OP_SUB :
  1048. begin
  1049. href:=ref;
  1050. fixref(list,href);
  1051. { add/sub works the same way, so have it unified here }
  1052. if (a >= 1) and (a <= 8) then
  1053. begin
  1054. if (op = OP_ADD) then
  1055. opcode:=A_ADDQ
  1056. else
  1057. opcode:=A_SUBQ;
  1058. list.concat(taicpu.op_const_ref(opcode, opsize, a, href));
  1059. end
  1060. else
  1061. if not(current_settings.cputype in cpu_coldfire) then
  1062. list.concat(taicpu.op_const_ref(opcode, opsize, a, href))
  1063. else
  1064. { on ColdFire, ADDI/SUBI cannot act on memory
  1065. so we can only go through a register }
  1066. inherited;
  1067. end;
  1068. else begin
  1069. // list.concat(tai_comment.create(strpnew('a_op_const_ref inherited')));
  1070. inherited;
  1071. end;
  1072. end;
  1073. end;
  1074. procedure tcg68k.a_op_reg_reg(list : TAsmList; Op: TOpCG; size: TCGSize; src, dst: TRegister);
  1075. var
  1076. hreg1, hreg2: tregister;
  1077. opcode : tasmop;
  1078. opsize : topsize;
  1079. begin
  1080. opcode := topcg2tasmop[op];
  1081. if current_settings.cputype in cpu_coldfire then
  1082. opsize := S_L
  1083. else
  1084. opsize := TCGSize2OpSize[size];
  1085. case op of
  1086. OP_ADD,
  1087. OP_SUB:
  1088. begin
  1089. if current_settings.cputype in cpu_coldfire then
  1090. begin
  1091. { operation only allowed only a longword }
  1092. sign_extend(list, size, src);
  1093. sign_extend(list, size, dst);
  1094. end;
  1095. list.concat(taicpu.op_reg_reg(opcode, opsize, src, dst));
  1096. end;
  1097. OP_AND,OP_OR,
  1098. OP_SAR,OP_SHL,
  1099. OP_SHR,OP_XOR:
  1100. begin
  1101. { load to data registers }
  1102. hreg1 := force_to_dataregister(list, size, src);
  1103. hreg2 := force_to_dataregister(list, size, dst);
  1104. if current_settings.cputype in cpu_coldfire then
  1105. begin
  1106. { operation only allowed only a longword }
  1107. {!***************************************
  1108. in the case of shifts, the value to
  1109. shift by, should already be valid, so
  1110. no need to sign extend the value
  1111. !
  1112. }
  1113. if op in [OP_AND,OP_OR,OP_XOR] then
  1114. sign_extend(list, size, hreg1);
  1115. sign_extend(list, size, hreg2);
  1116. end;
  1117. list.concat(taicpu.op_reg_reg(opcode, opsize, hreg1, hreg2));
  1118. { move back result into destination register }
  1119. move_if_needed(list, size, hreg2, dst);
  1120. end;
  1121. OP_DIV,
  1122. OP_IDIV :
  1123. begin
  1124. internalerror(20020816);
  1125. end;
  1126. OP_MUL,
  1127. OP_IMUL:
  1128. begin
  1129. if (current_settings.cputype <> cpu_mc68020) and
  1130. (not (current_settings.cputype in cpu_coldfire)) then
  1131. if op = OP_MUL then
  1132. call_rtl_mul_reg_reg(list,src,dst,'fpc_mul_dword')
  1133. else
  1134. call_rtl_mul_reg_reg(list,src,dst,'fpc_mul_longint')
  1135. else
  1136. begin
  1137. { 68020+ and ColdFire codepath, probably could be improved }
  1138. hreg1 := force_to_dataregister(list, size, src);
  1139. hreg2 := force_to_dataregister(list, size, dst);
  1140. sign_extend(list, size, hreg1);
  1141. sign_extend(list, size, hreg2);
  1142. list.concat(taicpu.op_reg_reg(opcode, opsize, hreg1, hreg2));
  1143. { move back result into destination register }
  1144. move_if_needed(list, size, hreg2, dst);
  1145. end;
  1146. end;
  1147. OP_NEG,
  1148. OP_NOT :
  1149. begin
  1150. { if there are two operands, move the register,
  1151. since the operation will only be done on the result
  1152. register. }
  1153. if (src<>dst) then
  1154. a_load_reg_reg(list,size,size,src,dst);
  1155. hreg2 := force_to_dataregister(list, size, dst);
  1156. { coldfire only supports long version }
  1157. if current_settings.cputype in cpu_ColdFire then
  1158. sign_extend(list, size, hreg2);
  1159. list.concat(taicpu.op_reg(opcode, opsize, hreg2));
  1160. { move back the result to the result register if needed }
  1161. move_if_needed(list, size, hreg2, dst);
  1162. end;
  1163. else
  1164. internalerror(20020729);
  1165. end;
  1166. end;
  1167. procedure tcg68k.a_op_reg_ref(list : TAsmList; Op: TOpCG; size: TCGSize; reg: TRegister; const ref: TReference);
  1168. var
  1169. opcode : tasmop;
  1170. opsize : topsize;
  1171. href : treference;
  1172. begin
  1173. opcode := topcg2tasmop[op];
  1174. opsize := TCGSize2OpSize[size];
  1175. { on ColdFire all arithmetic operations are only possible on 32bit
  1176. and addressing modes are limited }
  1177. if ((current_settings.cputype in cpu_coldfire) and (opsize <> S_L)) then
  1178. begin
  1179. inherited;
  1180. exit;
  1181. end;
  1182. case op of
  1183. OP_ADD,
  1184. OP_SUB :
  1185. begin
  1186. href:=ref;
  1187. fixref(list,href);
  1188. { add/sub works the same way, so have it unified here }
  1189. list.concat(taicpu.op_reg_ref(opcode, opsize, reg, href));
  1190. end;
  1191. else begin
  1192. // list.concat(tai_comment.create(strpnew('a_op_reg_ref inherited')));
  1193. inherited;
  1194. end;
  1195. end;
  1196. end;
  1197. procedure tcg68k.a_cmp_const_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;a : tcgint;reg : tregister;
  1198. l : tasmlabel);
  1199. var
  1200. hregister : tregister;
  1201. instr : taicpu;
  1202. need_temp_reg : boolean;
  1203. temp_size: topsize;
  1204. begin
  1205. need_temp_reg := false;
  1206. { plain 68000 doesn't support address registers for TST }
  1207. need_temp_reg := (current_settings.cputype = cpu_mc68000) and
  1208. (a = 0) and isaddressregister(reg);
  1209. { ColdFire doesn't support address registers for CMPI }
  1210. need_temp_reg := need_temp_reg or ((current_settings.cputype in cpu_coldfire)
  1211. and (a <> 0) and isaddressregister(reg));
  1212. if need_temp_reg then
  1213. begin
  1214. hregister := getintregister(list,OS_INT);
  1215. temp_size := TCGSize2OpSize[size];
  1216. if temp_size < S_W then
  1217. temp_size := S_W;
  1218. instr:=taicpu.op_reg_reg(A_MOVE,temp_size,reg,hregister);
  1219. add_move_instruction(instr);
  1220. list.concat(instr);
  1221. reg := hregister;
  1222. { do sign extension if size had to be modified }
  1223. if temp_size <> TCGSize2OpSize[size] then
  1224. begin
  1225. sign_extend(list, size, reg);
  1226. size:=OS_INT;
  1227. end;
  1228. end;
  1229. if a = 0 then
  1230. list.concat(taicpu.op_reg(A_TST,TCGSize2OpSize[size],reg))
  1231. else
  1232. begin
  1233. { ColdFire ISA A also needs S_L for CMPI }
  1234. { Note: older QEMU pukes from CMPI sizes <> .L even on ISA B/C, but
  1235. it's actually *LEGAL*, see CFPRM, page 4-30, the bug also seems
  1236. fixed in recent QEMU, but only when CPU cfv4e is forced, not by
  1237. default. (KB) }
  1238. if current_settings.cputype in cpu_coldfire{-[cpu_isa_b,cpu_isa_c]} then
  1239. begin
  1240. sign_extend(list, size, reg);
  1241. size:=OS_INT;
  1242. end;
  1243. list.concat(taicpu.op_const_reg(A_CMPI,TCGSize2OpSize[size],a,reg));
  1244. end;
  1245. { emit the actual jump to the label }
  1246. a_jmp_cond(list,cmp_op,l);
  1247. end;
  1248. procedure tcg68k.a_cmp_const_ref_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;a : tcgint;const ref : treference; l : tasmlabel);
  1249. var
  1250. tmpref: treference;
  1251. begin
  1252. { optimize for usage of TST here, so ref compares against zero, which is the
  1253. most common case by far in the RTL code at least (KB) }
  1254. if (a = 0) then
  1255. begin
  1256. //list.concat(tai_comment.create(strpnew('a_cmp_const_ref_label with TST')));
  1257. tmpref:=ref;
  1258. fixref(list,tmpref);
  1259. list.concat(taicpu.op_ref(A_TST,tcgsize2opsize[size],tmpref));
  1260. a_jmp_cond(list,cmp_op,l);
  1261. end
  1262. else
  1263. begin
  1264. //list.concat(tai_comment.create(strpnew('a_cmp_const_ref_label inherited')));
  1265. inherited;
  1266. end;
  1267. end;
  1268. procedure tcg68k.a_cmp_reg_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;reg1,reg2 : tregister;l : tasmlabel);
  1269. begin
  1270. list.concat(taicpu.op_reg_reg(A_CMP,tcgsize2opsize[size],reg1,reg2));
  1271. { emit the actual jump to the label }
  1272. a_jmp_cond(list,cmp_op,l);
  1273. end;
  1274. procedure tcg68k.a_jmp_name(list: TAsmList; const s: string);
  1275. var
  1276. ai: taicpu;
  1277. begin
  1278. ai := Taicpu.op_sym(A_JMP,S_NO,current_asmdata.RefAsmSymbol(s));
  1279. ai.is_jmp := true;
  1280. list.concat(ai);
  1281. end;
  1282. procedure tcg68k.a_jmp_always(list : TAsmList;l: tasmlabel);
  1283. var
  1284. ai: taicpu;
  1285. begin
  1286. ai := Taicpu.op_sym(A_JMP,S_NO,l);
  1287. ai.is_jmp := true;
  1288. list.concat(ai);
  1289. end;
  1290. procedure tcg68k.a_jmp_flags(list : TAsmList;const f : TResFlags;l: tasmlabel);
  1291. var
  1292. ai : taicpu;
  1293. begin
  1294. ai := Taicpu.op_sym(A_BXX,S_NO,l);
  1295. ai.SetCondition(flags_to_cond(f));
  1296. ai.is_jmp := true;
  1297. list.concat(ai);
  1298. end;
  1299. procedure tcg68k.g_flags2reg(list: TAsmList; size: TCgSize; const f: tresflags; reg: TRegister);
  1300. var
  1301. ai : taicpu;
  1302. hreg : tregister;
  1303. instr : taicpu;
  1304. begin
  1305. { move to a Dx register? }
  1306. if (isaddressregister(reg)) then
  1307. hreg:=getintregister(list,OS_INT)
  1308. else
  1309. hreg:=reg;
  1310. ai:=Taicpu.Op_reg(A_Sxx,S_B,hreg);
  1311. ai.SetCondition(flags_to_cond(f));
  1312. list.concat(ai);
  1313. { Scc stores a complete byte of 1s, but the compiler expects only one
  1314. bit set, so ensure this is the case }
  1315. list.concat(taicpu.op_const_reg(A_AND,S_L,1,hreg));
  1316. if hreg<>reg then
  1317. begin
  1318. instr:=taicpu.op_reg_reg(A_MOVE,S_L,hreg,reg);
  1319. add_move_instruction(instr);
  1320. list.concat(instr);
  1321. end;
  1322. end;
  1323. procedure tcg68k.g_concatcopy(list : TAsmList;const source,dest : treference;len : tcgint);
  1324. var
  1325. helpsize : longint;
  1326. i : byte;
  1327. hregister : tregister;
  1328. iregister : tregister;
  1329. jregister : tregister;
  1330. hp1 : treference;
  1331. hp2 : treference;
  1332. hl : tasmlabel;
  1333. srcref,dstref : treference;
  1334. orglen : tcgint;
  1335. begin
  1336. hregister := getintregister(list,OS_INT);
  1337. orglen:=len;
  1338. { from 12 bytes movs is being used }
  1339. if ((len<=8) or (not(cs_opt_size in current_settings.optimizerswitches) and (len<=12))) then
  1340. begin
  1341. srcref := source;
  1342. dstref := dest;
  1343. helpsize:=len div 4;
  1344. { move a dword x times }
  1345. for i:=1 to helpsize do
  1346. begin
  1347. a_load_ref_reg(list,OS_INT,OS_INT,srcref,hregister);
  1348. a_load_reg_ref(list,OS_INT,OS_INT,hregister,dstref);
  1349. inc(srcref.offset,4);
  1350. inc(dstref.offset,4);
  1351. dec(len,4);
  1352. end;
  1353. { move a word }
  1354. if len>1 then
  1355. begin
  1356. a_load_ref_reg(list,OS_16,OS_16,srcref,hregister);
  1357. a_load_reg_ref(list,OS_16,OS_16,hregister,dstref);
  1358. inc(srcref.offset,2);
  1359. inc(dstref.offset,2);
  1360. dec(len,2);
  1361. end;
  1362. { move a single byte }
  1363. if len>0 then
  1364. begin
  1365. a_load_ref_reg(list,OS_8,OS_8,srcref,hregister);
  1366. a_load_reg_ref(list,OS_8,OS_8,hregister,dstref);
  1367. end
  1368. end
  1369. else
  1370. begin
  1371. iregister:=getaddressregister(list);
  1372. jregister:=getaddressregister(list);
  1373. { reference for move (An)+,(An)+ }
  1374. reference_reset(hp1,source.alignment);
  1375. hp1.base := iregister; { source register }
  1376. hp1.direction := dir_inc;
  1377. reference_reset(hp2,dest.alignment);
  1378. hp2.base := jregister;
  1379. hp2.direction := dir_inc;
  1380. { iregister = source }
  1381. { jregister = destination }
  1382. a_loadaddr_ref_reg(list,source,iregister);
  1383. a_loadaddr_ref_reg(list,dest,jregister);
  1384. { double word move only on 68020+ machines }
  1385. { because of possible alignment problems }
  1386. { use fast loop mode }
  1387. if (current_settings.cputype=cpu_MC68020) then
  1388. begin
  1389. //list.concat(tai_comment.create(strpnew('g_concatcopy tight copy loop 020+')));
  1390. helpsize := len - len mod 4;
  1391. len := len mod 4;
  1392. a_load_const_reg(list,OS_INT,(helpsize div 4)-1,hregister);
  1393. current_asmdata.getjumplabel(hl);
  1394. a_label(list,hl);
  1395. list.concat(taicpu.op_ref_ref(A_MOVE,S_L,hp1,hp2));
  1396. list.concat(taicpu.op_reg_sym(A_DBRA,S_L,hregister,hl));
  1397. if len > 1 then
  1398. begin
  1399. dec(len,2);
  1400. list.concat(taicpu.op_ref_ref(A_MOVE,S_W,hp1,hp2));
  1401. end;
  1402. if len = 1 then
  1403. list.concat(taicpu.op_ref_ref(A_MOVE,S_B,hp1,hp2));
  1404. end
  1405. else
  1406. begin
  1407. { Fast 68010 loop mode with no possible alignment problems }
  1408. //list.concat(tai_comment.create(strpnew('g_concatcopy tight byte copy loop')));
  1409. a_load_const_reg(list,OS_INT,len - 1,hregister);
  1410. current_asmdata.getjumplabel(hl);
  1411. a_label(list,hl);
  1412. list.concat(taicpu.op_ref_ref(A_MOVE,S_B,hp1,hp2));
  1413. if current_settings.cputype in cpu_coldfire then
  1414. begin
  1415. { Coldfire does not support DBRA }
  1416. list.concat(taicpu.op_const_reg(A_SUBQ,S_L,1,hregister));
  1417. list.concat(taicpu.op_sym(A_BPL,S_NO,hl));
  1418. end
  1419. else
  1420. list.concat(taicpu.op_reg_sym(A_DBRA,S_L,hregister,hl));
  1421. end;
  1422. end;
  1423. end;
  1424. procedure tcg68k.g_overflowcheck(list: TAsmList; const l:tlocation; def:tdef);
  1425. var
  1426. hl : tasmlabel;
  1427. ai : taicpu;
  1428. cond : TAsmCond;
  1429. begin
  1430. if not(cs_check_overflow in current_settings.localswitches) then
  1431. exit;
  1432. current_asmdata.getjumplabel(hl);
  1433. if not ((def.typ=pointerdef) or
  1434. ((def.typ=orddef) and
  1435. (torddef(def).ordtype in [u64bit,u16bit,u32bit,u8bit,uchar,
  1436. pasbool8,pasbool16,pasbool32,pasbool64]))) then
  1437. cond:=C_VC
  1438. else
  1439. cond:=C_CC;
  1440. ai:=Taicpu.Op_Sym(A_Bxx,S_NO,hl);
  1441. ai.SetCondition(cond);
  1442. ai.is_jmp:=true;
  1443. list.concat(ai);
  1444. a_call_name(list,'FPC_OVERFLOW',false);
  1445. a_label(list,hl);
  1446. end;
  1447. procedure tcg68k.g_proc_entry(list: TAsmList; localsize: longint; nostackframe:boolean);
  1448. begin
  1449. { Carl's original code used 2x MOVE instead of LINK when localsize = 0.
  1450. However, a LINK seems faster than two moves on everything from 68000
  1451. to '060, so the two move branch here was dropped. (KB) }
  1452. if not nostackframe then
  1453. begin
  1454. { size can't be negative }
  1455. if (localsize < 0) then
  1456. internalerror(2006122601);
  1457. { Not to complicate the code generator too much, and since some }
  1458. { of the systems only support this format, the localsize cannot }
  1459. { exceed 32K in size. }
  1460. if (localsize > high(smallint)) then
  1461. CGMessage(cg_e_localsize_too_big);
  1462. list.concat(taicpu.op_reg_const(A_LINK,S_W,NR_FRAME_POINTER_REG,-localsize));
  1463. end;
  1464. end;
  1465. procedure tcg68k.g_proc_exit(list : TAsmList; parasize: longint; nostackframe: boolean);
  1466. var
  1467. r,hregister : TRegister;
  1468. ref : TReference;
  1469. ref2: TReference;
  1470. begin
  1471. if not nostackframe then
  1472. begin
  1473. list.concat(taicpu.op_reg(A_UNLK,S_NO,NR_FRAME_POINTER_REG));
  1474. { if parasize is less than zero here, we probably have a cdecl function.
  1475. According to the info here: http://www.makestuff.eu/wordpress/gcc-68000-abi/
  1476. 68k GCC uses two different methods to free the stack, depending if the target
  1477. architecture supports RTD or not, and one does callee side, the other does
  1478. caller side free, which looks like a PITA to support. We have to figure this
  1479. out later. More info welcomed. (KB) }
  1480. if (parasize > 0) and not (current_procinfo.procdef.proccalloption in clearstack_pocalls) then
  1481. begin
  1482. if current_settings.cputype=cpu_mc68020 then
  1483. list.concat(taicpu.op_const(A_RTD,S_NO,parasize))
  1484. else
  1485. begin
  1486. { We must pull the PC Counter from the stack, before }
  1487. { restoring the stack pointer, otherwise the PC would }
  1488. { point to nowhere! }
  1489. { Instead of doing a slow copy of the return address while trying }
  1490. { to feed it to the RTS instruction, load the PC to A0 (scratch reg) }
  1491. { then free up the stack allocated for paras, then use a JMP (A0) to }
  1492. { return to the caller with the paras freed. (KB) }
  1493. hregister:=NR_A0;
  1494. cg.a_reg_alloc(list,hregister);
  1495. reference_reset_base(ref,NR_STACK_POINTER_REG,0,4);
  1496. list.concat(taicpu.op_ref_reg(A_MOVE,S_L,ref,hregister));
  1497. { instead of using a postincrement above (which also writes the }
  1498. { stackpointer reg) simply add 4 to the parasize, the instructions }
  1499. { below then take that size into account as well, so SP reg is only }
  1500. { written once (KB) }
  1501. parasize:=parasize+4;
  1502. r:=NR_SP;
  1503. { can we do a quick addition ... }
  1504. if (parasize < 9) then
  1505. list.concat(taicpu.op_const_reg(A_ADDQ,S_L,parasize,r))
  1506. else { nope ... }
  1507. begin
  1508. reference_reset_base(ref2,NR_STACK_POINTER_REG,parasize,4);
  1509. list.concat(taicpu.op_ref_reg(A_LEA,S_NO,ref2,r));
  1510. end;
  1511. reference_reset_base(ref,hregister,0,4);
  1512. list.concat(taicpu.op_ref(A_JMP,S_NO,ref));
  1513. end;
  1514. end
  1515. else
  1516. list.concat(taicpu.op_none(A_RTS,S_NO));
  1517. end
  1518. else
  1519. begin
  1520. list.concat(taicpu.op_none(A_RTS,S_NO));
  1521. end;
  1522. { Routines with the poclearstack flag set use only a ret.
  1523. also routines with parasize=0 }
  1524. { TODO: figure out if these are still relevant to us (KB) }
  1525. (*
  1526. if current_procinfo.procdef.proccalloption in clearstack_pocalls then
  1527. begin
  1528. { complex return values are removed from stack in C code PM }
  1529. if paramanager.ret_in_param(current_procinfo.procdef.returndef,current_procinfo.procdef) then
  1530. list.concat(taicpu.op_const(A_RTD,S_NO,4))
  1531. else
  1532. list.concat(taicpu.op_none(A_RTS,S_NO));
  1533. end
  1534. else if (parasize=0) then
  1535. begin
  1536. list.concat(taicpu.op_none(A_RTS,S_NO));
  1537. end
  1538. else
  1539. *)
  1540. end;
  1541. procedure tcg68k.g_save_registers(list:TAsmList);
  1542. var
  1543. dataregs: tcpuregisterset;
  1544. addrregs: tcpuregisterset;
  1545. href : treference;
  1546. hreg : tregister;
  1547. size : longint;
  1548. r : integer;
  1549. begin
  1550. { The code generated by the section below, particularly the movem.l
  1551. instruction is known to cause an issue when compiled by some GNU
  1552. assembler versions (I had it with 2.17, while 2.24 seems OK.)
  1553. when you run into this problem, just call inherited here instead
  1554. to skip the movem.l generation. But better just use working GNU
  1555. AS version instead. (KB) }
  1556. dataregs:=[];
  1557. addrregs:=[];
  1558. { calculate temp. size }
  1559. size:=0;
  1560. for r:=low(saved_standard_registers) to high(saved_standard_registers) do
  1561. if saved_standard_registers[r] in rg[R_INTREGISTER].used_in_proc then
  1562. begin
  1563. hreg:=newreg(R_INTREGISTER,saved_address_registers[r],R_SUBWHOLE);
  1564. inc(size,sizeof(aint));
  1565. dataregs:=dataregs + [saved_standard_registers[r]];
  1566. end;
  1567. if uses_registers(R_ADDRESSREGISTER) then
  1568. for r:=low(saved_address_registers) to high(saved_address_registers) do
  1569. if saved_address_registers[r] in rg[R_ADDRESSREGISTER].used_in_proc then
  1570. begin
  1571. hreg:=newreg(R_ADDRESSREGISTER,saved_address_registers[r],R_SUBWHOLE);
  1572. inc(size,sizeof(aint));
  1573. addrregs:=addrregs + [saved_address_registers[r]];
  1574. end;
  1575. { 68k has no MM registers }
  1576. if uses_registers(R_MMREGISTER) then
  1577. internalerror(2014030201);
  1578. if size>0 then
  1579. begin
  1580. tg.GetTemp(list,size,sizeof(aint),tt_noreuse,current_procinfo.save_regs_ref);
  1581. include(current_procinfo.flags,pi_has_saved_regs);
  1582. { Copy registers to temp }
  1583. href:=current_procinfo.save_regs_ref;
  1584. if size = sizeof(aint) then
  1585. a_load_reg_ref(list, OS_32, OS_32, hreg, href)
  1586. else
  1587. list.concat(taicpu.op_regset_ref(A_MOVEM,S_L,dataregs,addrregs,href));
  1588. end;
  1589. end;
  1590. procedure tcg68k.g_restore_registers(list:TAsmList);
  1591. var
  1592. dataregs: tcpuregisterset;
  1593. addrregs: tcpuregisterset;
  1594. href : treference;
  1595. r : integer;
  1596. hreg : tregister;
  1597. size : longint;
  1598. begin
  1599. { see the remark about buggy GNU AS versions in g_save_registers() (KB) }
  1600. dataregs:=[];
  1601. addrregs:=[];
  1602. if not(pi_has_saved_regs in current_procinfo.flags) then
  1603. exit;
  1604. { Copy registers from temp }
  1605. size:=0;
  1606. for r:=low(saved_standard_registers) to high(saved_standard_registers) do
  1607. if saved_standard_registers[r] in rg[R_INTREGISTER].used_in_proc then
  1608. begin
  1609. inc(size,sizeof(aint));
  1610. hreg:=newreg(R_INTREGISTER,saved_standard_registers[r],R_SUBWHOLE);
  1611. { Allocate register so the optimizer does not remove the load }
  1612. a_reg_alloc(list,hreg);
  1613. dataregs:=dataregs + [saved_standard_registers[r]];
  1614. end;
  1615. if uses_registers(R_ADDRESSREGISTER) then
  1616. for r:=low(saved_address_registers) to high(saved_address_registers) do
  1617. if saved_address_registers[r] in rg[R_ADDRESSREGISTER].used_in_proc then
  1618. begin
  1619. inc(size,sizeof(aint));
  1620. hreg:=newreg(R_ADDRESSREGISTER,saved_address_registers[r],R_SUBWHOLE);
  1621. { Allocate register so the optimizer does not remove the load }
  1622. a_reg_alloc(list,hreg);
  1623. addrregs:=addrregs + [saved_address_registers[r]];
  1624. end;
  1625. { 68k has no MM registers }
  1626. if uses_registers(R_MMREGISTER) then
  1627. internalerror(2014030202);
  1628. { Restore registers from temp }
  1629. href:=current_procinfo.save_regs_ref;
  1630. if size = sizeof(aint) then
  1631. a_load_ref_reg(list, OS_32, OS_32, href, hreg)
  1632. else
  1633. list.concat(taicpu.op_ref_regset(A_MOVEM,S_L,href,dataregs,addrregs));
  1634. tg.UnGetTemp(list,current_procinfo.save_regs_ref);
  1635. end;
  1636. procedure tcg68k.sign_extend(list: TAsmList;_oldsize : tcgsize; _newsize : tcgsize; reg: tregister);
  1637. begin
  1638. case _newsize of
  1639. OS_S16, OS_16:
  1640. case _oldsize of
  1641. OS_S8:
  1642. begin { 8 -> 16 bit sign extend }
  1643. if (isaddressregister(reg)) then
  1644. internalerror(2014031201);
  1645. list.concat(taicpu.op_reg(A_EXT,S_W,reg));
  1646. end;
  1647. OS_8: { 8 -> 16 bit zero extend }
  1648. begin
  1649. if (current_settings.cputype in cpu_coldfire) then
  1650. { ColdFire has no ANDI.W }
  1651. list.concat(taicpu.op_const_reg(A_AND,S_L,$FF,reg))
  1652. else
  1653. list.concat(taicpu.op_const_reg(A_AND,S_W,$FF,reg));
  1654. end;
  1655. end;
  1656. OS_S32, OS_32:
  1657. case _oldsize of
  1658. OS_S8:
  1659. begin { 8 -> 32 bit sign extend }
  1660. if (isaddressregister(reg)) then
  1661. internalerror(2014031202);
  1662. if (current_settings.cputype = cpu_MC68000) then
  1663. begin
  1664. list.concat(taicpu.op_reg(A_EXT,S_W,reg));
  1665. list.concat(taicpu.op_reg(A_EXT,S_L,reg));
  1666. end
  1667. else
  1668. begin
  1669. //list.concat(tai_comment.create(strpnew('sign extend byte')));
  1670. list.concat(taicpu.op_reg(A_EXTB,S_L,reg));
  1671. end;
  1672. end;
  1673. OS_8: { 8 -> 32 bit zero extend }
  1674. begin
  1675. //list.concat(tai_comment.create(strpnew('zero extend byte')));
  1676. list.concat(taicpu.op_const_reg(A_AND,S_L,$FF,reg));
  1677. end;
  1678. OS_S16: { 16 -> 32 bit sign extend }
  1679. begin
  1680. if (isaddressregister(reg)) then
  1681. internalerror(2014031203);
  1682. //list.concat(tai_comment.create(strpnew('sign extend word')));
  1683. list.concat(taicpu.op_reg(A_EXT,S_L,reg));
  1684. end;
  1685. OS_16:
  1686. begin
  1687. //list.concat(tai_comment.create(strpnew('zero extend byte')));
  1688. list.concat(taicpu.op_const_reg(A_AND,S_L,$FFFF,reg));
  1689. end;
  1690. end;
  1691. end; { otherwise the size is already correct }
  1692. end;
  1693. procedure tcg68k.sign_extend(list: TAsmList;_oldsize : tcgsize; reg: tregister);
  1694. begin
  1695. sign_extend(list, _oldsize, OS_INT, reg);
  1696. end;
  1697. procedure tcg68k.a_jmp_cond(list : TAsmList;cond : TOpCmp;l: tasmlabel);
  1698. var
  1699. ai : taicpu;
  1700. begin
  1701. if cond=OC_None then
  1702. ai := Taicpu.Op_sym(A_JMP,S_NO,l)
  1703. else
  1704. begin
  1705. ai:=Taicpu.Op_sym(A_Bxx,S_NO,l);
  1706. ai.SetCondition(TOpCmp2AsmCond[cond]);
  1707. end;
  1708. ai.is_jmp:=true;
  1709. list.concat(ai);
  1710. end;
  1711. { ensures a register is a dataregister. this is often used, as 68k can't do lots of
  1712. operations on an address register. if the register is a dataregister anyway, it
  1713. just returns it untouched.}
  1714. function tcg68k.force_to_dataregister(list: TAsmList; size: TCGSize; reg: TRegister): TRegister;
  1715. var
  1716. scratch_reg: TRegister;
  1717. instr: Taicpu;
  1718. begin
  1719. if isaddressregister(reg) then
  1720. begin
  1721. scratch_reg:=getintregister(list,OS_INT);
  1722. instr:=taicpu.op_reg_reg(A_MOVE,S_L,reg,scratch_reg);
  1723. add_move_instruction(instr);
  1724. list.concat(instr);
  1725. result:=scratch_reg;
  1726. end
  1727. else
  1728. result:=reg;
  1729. end;
  1730. { moves source register to destination register, if the two are not the same. can be used in pair
  1731. with force_to_dataregister() }
  1732. procedure tcg68k.move_if_needed(list: TAsmList; size: TCGSize; src: TRegister; dest: TRegister);
  1733. var
  1734. instr: Taicpu;
  1735. begin
  1736. if (src <> dest) then
  1737. begin
  1738. instr:=taicpu.op_reg_reg(A_MOVE,S_L,src,dest);
  1739. add_move_instruction(instr);
  1740. list.concat(instr);
  1741. end;
  1742. end;
  1743. procedure tcg68k.g_adjust_self_value(list:TAsmList;procdef: tprocdef;ioffset: tcgint);
  1744. var
  1745. hsym : tsym;
  1746. href : treference;
  1747. paraloc : Pcgparalocation;
  1748. begin
  1749. { calculate the parameter info for the procdef }
  1750. procdef.init_paraloc_info(callerside);
  1751. hsym:=tsym(procdef.parast.Find('self'));
  1752. if not(assigned(hsym) and
  1753. (hsym.typ=paravarsym)) then
  1754. internalerror(2013100702);
  1755. paraloc:=tparavarsym(hsym).paraloc[callerside].location;
  1756. while paraloc<>nil do
  1757. with paraloc^ do
  1758. begin
  1759. case loc of
  1760. LOC_REGISTER:
  1761. a_op_const_reg(list,OP_SUB,size,ioffset,register);
  1762. LOC_REFERENCE:
  1763. begin
  1764. { offset in the wrapper needs to be adjusted for the stored
  1765. return address }
  1766. reference_reset_base(href,reference.index,reference.offset+sizeof(pint),sizeof(pint));
  1767. { plain 68k could use SUBI on href directly, but this way it works on Coldfire too
  1768. and it's probably smaller code for the majority of cases (if ioffset small, the
  1769. load will use MOVEQ) (KB) }
  1770. a_load_const_reg(list,OS_ADDR,ioffset,NR_D0);
  1771. list.concat(taicpu.op_reg_ref(A_SUB,S_L,NR_D0,href));
  1772. end
  1773. else
  1774. internalerror(2013100703);
  1775. end;
  1776. paraloc:=next;
  1777. end;
  1778. end;
  1779. procedure tcg68k.g_intf_wrapper(list: TAsmList; procdef: tprocdef; const labelname: string; ioffset: longint);
  1780. procedure getselftoa0(offs:longint);
  1781. var
  1782. href : treference;
  1783. selfoffsetfromsp : longint;
  1784. begin
  1785. { move.l offset(%sp),%a0 }
  1786. { framepointer is pushed for nested procs }
  1787. if procdef.parast.symtablelevel>normal_function_level then
  1788. selfoffsetfromsp:=sizeof(aint)
  1789. else
  1790. selfoffsetfromsp:=0;
  1791. reference_reset_base(href,NR_SP,selfoffsetfromsp+offs,4);
  1792. cg.a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,NR_A0);
  1793. end;
  1794. procedure loadvmttoa0;
  1795. var
  1796. href : treference;
  1797. begin
  1798. { move.l (%a0),%a0 ; load vmt}
  1799. reference_reset_base(href,NR_A0,0,4);
  1800. cg.a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,NR_A0);
  1801. end;
  1802. procedure op_ona0methodaddr;
  1803. var
  1804. href : treference;
  1805. begin
  1806. if (procdef.extnumber=$ffff) then
  1807. Internalerror(2013100701);
  1808. reference_reset_base(href,NR_A0,tobjectdef(procdef.struct).vmtmethodoffset(procdef.extnumber),4);
  1809. list.concat(taicpu.op_ref_reg(A_MOVE,S_L,href,NR_A0));
  1810. reference_reset_base(href,NR_A0,0,4);
  1811. list.concat(taicpu.op_ref(A_JMP,S_NO,href));
  1812. end;
  1813. var
  1814. make_global : boolean;
  1815. begin
  1816. if not(procdef.proctypeoption in [potype_function,potype_procedure]) then
  1817. Internalerror(200006137);
  1818. if not assigned(procdef.struct) or
  1819. (procdef.procoptions*[po_classmethod, po_staticmethod,
  1820. po_methodpointer, po_interrupt, po_iocheck]<>[]) then
  1821. Internalerror(200006138);
  1822. if procdef.owner.symtabletype<>ObjectSymtable then
  1823. Internalerror(200109191);
  1824. make_global:=false;
  1825. if (not current_module.is_unit) or
  1826. create_smartlink or
  1827. (procdef.owner.defowner.owner.symtabletype=globalsymtable) then
  1828. make_global:=true;
  1829. if make_global then
  1830. List.concat(Tai_symbol.Createname_global(labelname,AT_FUNCTION,0))
  1831. else
  1832. List.concat(Tai_symbol.Createname(labelname,AT_FUNCTION,0));
  1833. { set param1 interface to self }
  1834. g_adjust_self_value(list,procdef,ioffset);
  1835. { case 4 }
  1836. if (po_virtualmethod in procdef.procoptions) and
  1837. not is_objectpascal_helper(procdef.struct) then
  1838. begin
  1839. getselftoa0(4);
  1840. loadvmttoa0;
  1841. op_ona0methodaddr;
  1842. end
  1843. { case 0 }
  1844. else
  1845. list.concat(taicpu.op_sym(A_JMP,S_NO,current_asmdata.RefAsmSymbol(procdef.mangledname)));
  1846. List.concat(Tai_symbol_end.Createname(labelname));
  1847. end;
  1848. procedure tcg68k.g_stackpointer_alloc(list : TAsmList;localsize : longint);
  1849. begin
  1850. list.concat(taicpu.op_const_reg(A_SUB,S_L,localsize,NR_STACK_POINTER_REG));
  1851. end;
  1852. {****************************************************************************}
  1853. { TCG64F68K }
  1854. {****************************************************************************}
  1855. procedure tcg64f68k.a_op64_reg_reg(list : TAsmList;op:TOpCG;size: tcgsize; regsrc,regdst : tregister64);
  1856. var
  1857. opcode : tasmop;
  1858. xopcode : tasmop;
  1859. instr : taicpu;
  1860. begin
  1861. opcode := topcg2tasmop[op];
  1862. xopcode := topcg2tasmopx[op];
  1863. case op of
  1864. OP_ADD,OP_SUB:
  1865. begin
  1866. { if one of these three registers is an address
  1867. register, we'll really get into problems! }
  1868. if isaddressregister(regdst.reglo) or
  1869. isaddressregister(regdst.reghi) or
  1870. isaddressregister(regsrc.reghi) then
  1871. internalerror(2014030101);
  1872. list.concat(taicpu.op_reg_reg(opcode,S_L,regsrc.reglo,regdst.reglo));
  1873. list.concat(taicpu.op_reg_reg(xopcode,S_L,regsrc.reghi,regdst.reghi));
  1874. end;
  1875. OP_AND,OP_OR:
  1876. begin
  1877. { at least one of the registers must be a data register }
  1878. if (isaddressregister(regdst.reglo) and
  1879. isaddressregister(regsrc.reglo)) or
  1880. (isaddressregister(regsrc.reghi) and
  1881. isaddressregister(regdst.reghi)) then
  1882. internalerror(2014030102);
  1883. cg.a_op_reg_reg(list,op,OS_32,regsrc.reglo,regdst.reglo);
  1884. cg.a_op_reg_reg(list,op,OS_32,regsrc.reghi,regdst.reghi);
  1885. end;
  1886. { this is handled in 1st pass for 32-bit cpu's (helper call) }
  1887. OP_IDIV,OP_DIV,
  1888. OP_IMUL,OP_MUL:
  1889. internalerror(2002081701);
  1890. { this is also handled in 1st pass for 32-bit cpu's (helper call) }
  1891. OP_SAR,OP_SHL,OP_SHR:
  1892. internalerror(2002081702);
  1893. OP_XOR:
  1894. begin
  1895. if isaddressregister(regdst.reglo) or
  1896. isaddressregister(regsrc.reglo) or
  1897. isaddressregister(regsrc.reghi) or
  1898. isaddressregister(regdst.reghi) then
  1899. internalerror(2014030103);
  1900. cg.a_op_reg_reg(list,op,OS_32,regsrc.reglo,regdst.reglo);
  1901. cg.a_op_reg_reg(list,op,OS_32,regsrc.reghi,regdst.reghi);
  1902. end;
  1903. OP_NEG,OP_NOT:
  1904. begin
  1905. if isaddressregister(regdst.reglo) or
  1906. isaddressregister(regdst.reghi) then
  1907. internalerror(2014030104);
  1908. instr:=taicpu.op_reg_reg(A_MOVE,S_L,regsrc.reglo,regdst.reglo);
  1909. cg.add_move_instruction(instr);
  1910. list.concat(instr);
  1911. instr:=taicpu.op_reg_reg(A_MOVE,S_L,regsrc.reghi,regdst.reghi);
  1912. cg.add_move_instruction(instr);
  1913. list.concat(instr);
  1914. if (op = OP_NOT) then
  1915. xopcode:=opcode;
  1916. list.concat(taicpu.op_reg(opcode,S_L,regdst.reglo));
  1917. list.concat(taicpu.op_reg(xopcode,S_L,regdst.reghi));
  1918. end;
  1919. end; { end case }
  1920. end;
  1921. procedure tcg64f68k.a_op64_ref_reg(list : TAsmList;op:TOpCG;size : tcgsize;const ref : treference;reg : tregister64);
  1922. var
  1923. tempref : treference;
  1924. begin
  1925. case op of
  1926. OP_NEG,OP_NOT:
  1927. begin
  1928. a_load64_ref_reg(list,ref,reg);
  1929. a_op64_reg_reg(list,op,size,reg,reg);
  1930. end;
  1931. OP_AND,OP_OR:
  1932. begin
  1933. tempref:=ref;
  1934. tcg68k(cg).fixref(list,tempref);
  1935. inc(tempref.offset,4);
  1936. list.concat(taicpu.op_ref_reg(topcg2tasmop[op],S_L,tempref,reg.reglo));
  1937. dec(tempref.offset,4);
  1938. list.concat(taicpu.op_ref_reg(topcg2tasmop[op],S_L,tempref,reg.reghi));
  1939. end;
  1940. else
  1941. { XOR does not allow reference for source; ADD/SUB do not allow reference for
  1942. high dword, although low dword can still be handled directly. }
  1943. inherited a_op64_ref_reg(list,op,size,ref,reg);
  1944. end;
  1945. end;
  1946. procedure tcg64f68k.a_op64_const_reg(list : TAsmList;op:TOpCG;size: tcgsize; value : int64;regdst : tregister64);
  1947. var
  1948. lowvalue : cardinal;
  1949. highvalue : cardinal;
  1950. opcode : tasmop;
  1951. xopcode : tasmop;
  1952. hreg : tregister;
  1953. begin
  1954. { is it optimized out ? }
  1955. { optimize64_op_const_reg doesn't seem to be used in any cg64f32 right now. why? (KB) }
  1956. { if cg.optimize64_op_const_reg(list,op,value,reg) then
  1957. exit; }
  1958. lowvalue := cardinal(value);
  1959. highvalue := value shr 32;
  1960. opcode := topcg2tasmop[op];
  1961. xopcode := topcg2tasmopx[op];
  1962. { the destination registers must be data registers }
  1963. if isaddressregister(regdst.reglo) or
  1964. isaddressregister(regdst.reghi) then
  1965. internalerror(2014030105);
  1966. case op of
  1967. OP_ADD,OP_SUB:
  1968. begin
  1969. hreg:=cg.getintregister(list,OS_INT);
  1970. { cg.a_load_const_reg provides optimized loading to register for special cases }
  1971. cg.a_load_const_reg(list,OS_S32,longint(highvalue),hreg);
  1972. { don't use cg.a_op_const_reg() here, because a possible optimized
  1973. ADDQ/SUBQ wouldn't set the eXtend bit }
  1974. list.concat(taicpu.op_const_reg(opcode,S_L,lowvalue,regdst.reglo));
  1975. list.concat(taicpu.op_reg_reg(xopcode,S_L,hreg,regdst.reghi));
  1976. end;
  1977. OP_AND,OP_OR,OP_XOR:
  1978. begin
  1979. cg.a_op_const_reg(list,op,OS_S32,longint(lowvalue),regdst.reglo);
  1980. cg.a_op_const_reg(list,op,OS_S32,longint(highvalue),regdst.reghi);
  1981. end;
  1982. { this is handled in 1st pass for 32-bit cpus (helper call) }
  1983. OP_IDIV,OP_DIV,
  1984. OP_IMUL,OP_MUL:
  1985. internalerror(2002081701);
  1986. { this is also handled in 1st pass for 32-bit cpus (helper call) }
  1987. OP_SAR,OP_SHL,OP_SHR:
  1988. internalerror(2002081702);
  1989. { these should have been handled already by earlier passes }
  1990. OP_NOT,OP_NEG:
  1991. internalerror(2012110403);
  1992. end; { end case }
  1993. end;
  1994. procedure create_codegen;
  1995. begin
  1996. cg := tcg68k.create;
  1997. cg64 :=tcg64f68k.create;
  1998. end;
  1999. end.