cgcpu.pas 85 KB

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