cgcpu.pas 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794
  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. {DEFINE DEBUG_CHARLIE}
  18. {$IFNDEF DEBUG_CHARLIE}
  19. {$WARNINGS OFF}
  20. {$ENDIF}
  21. unit cgcpu;
  22. {$i fpcdefs.inc}
  23. interface
  24. uses
  25. cgbase,cgobj,globtype,
  26. aasmbase,aasmtai,aasmdata,aasmcpu,
  27. cpubase,cpuinfo,
  28. parabase,cpupara,
  29. node,symconst,symtype,symdef,
  30. cgutils,cg64f32;
  31. type
  32. tcg68k = class(tcg)
  33. procedure init_register_allocators;override;
  34. procedure done_register_allocators;override;
  35. procedure a_load_reg_cgpara(list : TAsmList;size : tcgsize;r : tregister;const cgpara : tcgpara);override;
  36. procedure a_load_const_cgpara(list : TAsmList;size : tcgsize;a : tcgint;const cgpara : tcgpara);override;
  37. procedure a_load_ref_cgpara(list : TAsmList;size : tcgsize;const r : treference;const cgpara : tcgpara);override;
  38. procedure a_loadaddr_ref_cgpara(list : TAsmList;const r : treference;const cgpara : tcgpara);override;
  39. procedure a_call_name(list : TAsmList;const s : string; weak: boolean);override;
  40. procedure a_call_reg(list : TAsmList;reg : tregister);override;
  41. procedure a_load_const_reg(list : TAsmList;size : tcgsize;a : tcgint;register : tregister);override;
  42. procedure a_load_const_ref(list : TAsmList; tosize: tcgsize; a : tcgint;const ref : treference);override;
  43. procedure a_load_reg_ref(list : TAsmList;fromsize,tosize : tcgsize;register : tregister;const ref : treference);override;
  44. procedure a_load_reg_reg(list : TAsmList;fromsize,tosize : tcgsize;reg1,reg2 : tregister);override;
  45. procedure a_load_ref_reg(list : TAsmList;fromsize,tosize : tcgsize;const ref : treference;register : tregister);override;
  46. procedure a_load_ref_ref(list : TAsmList;fromsize,tosize : tcgsize;const sref : treference;const dref : treference);override;
  47. procedure a_loadaddr_ref_reg(list : TAsmList;const ref : treference;r : tregister);override;
  48. procedure a_loadfpu_reg_reg(list: TAsmList; fromsize, tosize: tcgsize; reg1, reg2: tregister); override;
  49. procedure a_loadfpu_ref_reg(list: TAsmList; fromsize, tosize: tcgsize; const ref: treference; reg: tregister); override;
  50. procedure a_loadfpu_reg_ref(list: TAsmList; fromsize, tosize: tcgsize; reg: tregister; const ref: treference); override;
  51. procedure a_loadmm_reg_reg(list: TAsmList;fromsize,tosize : tcgsize; reg1, reg2: tregister;shuffle : pmmshuffle); override;
  52. procedure a_loadmm_ref_reg(list: TAsmList;fromsize,tosize : tcgsize; const ref: treference; reg: tregister;shuffle : pmmshuffle); override;
  53. procedure a_loadmm_reg_ref(list: TAsmList;fromsize,tosize : tcgsize; reg: tregister; const ref: treference;shuffle : pmmshuffle); override;
  54. procedure a_loadmm_reg_cgpara(list: TAsmList; size: tcgsize; reg: tregister;const locpara : TCGPara;shuffle : pmmshuffle); override;
  55. procedure a_op_const_reg(list : TAsmList; Op: TOpCG; size: tcgsize; a: tcgint; reg: TRegister); override;
  56. // procedure a_op_const_ref(list : TAsmList; Op: TOpCG; size: TCGSize; a: tcgint; const ref: TReference); override;
  57. procedure a_op_reg_reg(list : TAsmList; Op: TOpCG; size: TCGSize; reg1, reg2: TRegister); override;
  58. procedure a_cmp_const_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;a : tcgint;reg : tregister;
  59. l : tasmlabel);override;
  60. procedure a_cmp_reg_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;reg1,reg2 : tregister;l : tasmlabel); override;
  61. procedure a_jmp_name(list : TAsmList;const s : string); override;
  62. procedure a_jmp_always(list : TAsmList;l: tasmlabel); override;
  63. procedure a_jmp_flags(list : TAsmList;const f : TResFlags;l: tasmlabel); override;
  64. procedure g_flags2reg(list: TAsmList; size: TCgSize; const f: tresflags; reg: TRegister); override;
  65. procedure g_concatcopy(list : TAsmList;const source,dest : treference;len : tcgint);override;
  66. { generates overflow checking code for a node }
  67. procedure g_overflowcheck(list: TAsmList; const l:tlocation; def:tdef); override;
  68. procedure g_proc_entry(list : TAsmList;localsize : longint;nostackframe:boolean);override;
  69. procedure g_proc_exit(list : TAsmList;parasize:longint;nostackframe:boolean);override;
  70. // procedure g_restore_frame_pointer(list : TAsmList);override;
  71. // procedure g_return_from_proc(list : TAsmList;parasize : tcgint);override;
  72. procedure g_restore_registers(list:TAsmList);override;
  73. procedure g_save_registers(list:TAsmList);override;
  74. // procedure g_save_all_registers(list : TAsmList);override;
  75. // procedure g_restore_all_registers(list : TAsmList;const funcretparaloc:TCGPara);override;
  76. procedure g_intf_wrapper(list: TAsmList; procdef: tprocdef; const labelname: string; ioffset: longint);override;
  77. protected
  78. function fixref(list: TAsmList; var ref: treference): boolean;
  79. private
  80. { # Sign or zero extend the register to a full 32-bit value.
  81. The new value is left in the same register.
  82. }
  83. procedure sign_extend(list: TAsmList;_oldsize : tcgsize; reg: tregister);
  84. procedure a_jmp_cond(list : TAsmList;cond : TOpCmp;l: tasmlabel);
  85. end;
  86. tcg64f68k = class(tcg64f32)
  87. procedure a_op64_reg_reg(list : TAsmList;op:TOpCG; size: tcgsize; regsrc,regdst : tregister64);override;
  88. procedure a_op64_const_reg(list : TAsmList;op:TOpCG; size: tcgsize; value : int64;regdst : tregister64);override;
  89. end;
  90. { This function returns true if the reference+offset is valid.
  91. Otherwise extra code must be generated to solve the reference.
  92. On the m68k, this verifies that the reference is valid
  93. (e.g : if index register is used, then the max displacement
  94. is 256 bytes, if only base is used, then max displacement
  95. is 32K
  96. }
  97. function isvalidrefoffset(const ref: treference): boolean;
  98. const
  99. TCGSize2OpSize: Array[tcgsize] of topsize =
  100. (S_NO,S_B,S_W,S_L,S_L,S_NO,S_B,S_W,S_L,S_L,S_NO,
  101. S_FS,S_FD,S_FX,S_NO,S_NO,
  102. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,
  103. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO);
  104. procedure create_codegen;
  105. implementation
  106. uses
  107. globals,verbose,systems,cutils,
  108. symsym,defutil,paramgr,procinfo,
  109. rgobj,tgobj,rgcpu,fmodule;
  110. const
  111. { opcode table lookup }
  112. topcg2tasmop: Array[topcg] of tasmop =
  113. (
  114. A_NONE,
  115. A_MOVE,
  116. A_ADD,
  117. A_AND,
  118. A_DIVU,
  119. A_DIVS,
  120. A_MULS,
  121. A_MULU,
  122. A_NEG,
  123. A_NOT,
  124. A_OR,
  125. A_ASR,
  126. A_LSL,
  127. A_LSR,
  128. A_SUB,
  129. A_EOR,
  130. A_NONE,
  131. A_NONE
  132. );
  133. TOpCmp2AsmCond: Array[topcmp] of TAsmCond =
  134. (
  135. C_NONE,
  136. C_EQ,
  137. C_GT,
  138. C_LT,
  139. C_GE,
  140. C_LE,
  141. C_NE,
  142. C_LS,
  143. C_CS,
  144. C_CC,
  145. C_HI
  146. );
  147. function isvalidrefoffset(const ref: treference): boolean;
  148. begin
  149. isvalidrefoffset := true;
  150. if ref.index <> NR_NO then
  151. begin
  152. if ref.base <> NR_NO then
  153. internalerror(20020814);
  154. if (ref.offset < low(shortint)) or (ref.offset > high(shortint)) then
  155. isvalidrefoffset := false
  156. end
  157. else
  158. begin
  159. if (ref.offset < low(smallint)) or (ref.offset > high(smallint)) then
  160. isvalidrefoffset := false;
  161. end;
  162. end;
  163. {****************************************************************************}
  164. { TCG68K }
  165. {****************************************************************************}
  166. function use_push(const cgpara:tcgpara):boolean;
  167. begin
  168. result:=(not paramanager.use_fixed_stack) and
  169. assigned(cgpara.location) and
  170. (cgpara.location^.loc=LOC_REFERENCE) and
  171. (cgpara.location^.reference.index=NR_STACK_POINTER_REG);
  172. end;
  173. procedure tcg68k.init_register_allocators;
  174. begin
  175. inherited init_register_allocators;
  176. rg[R_INTREGISTER]:=trgcpu.create(R_INTREGISTER,R_SUBWHOLE,
  177. [RS_D0,RS_D1,RS_D2,RS_D3,RS_D4,RS_D5,RS_D6,RS_D7],
  178. first_int_imreg,[]);
  179. rg[R_ADDRESSREGISTER]:=trgcpu.create(R_ADDRESSREGISTER,R_SUBWHOLE,
  180. [RS_A0,RS_A1,RS_A2,RS_A3,RS_A4,RS_A5,RS_A6],
  181. first_addr_imreg,[]);
  182. rg[R_FPUREGISTER]:=trgcpu.create(R_FPUREGISTER,R_SUBNONE,
  183. [RS_FP0,RS_FP1,RS_FP2,RS_FP3,RS_FP4,RS_FP5,RS_FP6,RS_FP7],
  184. first_fpu_imreg,[]);
  185. end;
  186. procedure tcg68k.done_register_allocators;
  187. begin
  188. rg[R_INTREGISTER].free;
  189. rg[R_FPUREGISTER].free;
  190. rg[R_ADDRESSREGISTER].free;
  191. inherited done_register_allocators;
  192. end;
  193. procedure tcg68k.a_load_reg_cgpara(list : TAsmList;size : tcgsize;r : tregister;const cgpara : tcgpara);
  194. var
  195. pushsize : tcgsize;
  196. ref : treference;
  197. begin
  198. {$ifdef DEBUG_CHARLIE}
  199. // writeln('a_load_reg');_cgpara
  200. {$endif DEBUG_CHARLIE}
  201. { it's probably necessary to port this from x86 later, or provide an m68k solution (KB) }
  202. { TODO: FIX ME! check_register_size()}
  203. // check_register_size(size,r);
  204. if use_push(cgpara) then
  205. begin
  206. cgpara.check_simple_location;
  207. if tcgsize2size[cgpara.location^.size]>cgpara.alignment then
  208. pushsize:=cgpara.location^.size
  209. else
  210. pushsize:=int_cgsize(cgpara.alignment);
  211. reference_reset_base(ref, NR_STACK_POINTER_REG, 0, cgpara.alignment);
  212. ref.direction := dir_dec;
  213. list.concat(taicpu.op_reg_ref(A_MOVE,tcgsize2opsize[pushsize],makeregsize(list,r,pushsize),ref));
  214. end
  215. else
  216. inherited a_load_reg_cgpara(list,size,r,cgpara);
  217. end;
  218. procedure tcg68k.a_load_const_cgpara(list : TAsmList;size : tcgsize;a : tcgint;const cgpara : tcgpara);
  219. var
  220. pushsize : tcgsize;
  221. ref : treference;
  222. begin
  223. {$ifdef DEBUG_CHARLIE}
  224. // writeln('a_load_const');_cgpara
  225. {$endif DEBUG_CHARLIE}
  226. if use_push(cgpara) then
  227. begin
  228. cgpara.check_simple_location;
  229. if tcgsize2size[cgpara.location^.size]>cgpara.alignment then
  230. pushsize:=cgpara.location^.size
  231. else
  232. pushsize:=int_cgsize(cgpara.alignment);
  233. reference_reset_base(ref, NR_STACK_POINTER_REG, 0, cgpara.alignment);
  234. ref.direction := dir_dec;
  235. list.concat(taicpu.op_const_ref(A_MOVE,tcgsize2opsize[pushsize],a,ref));
  236. end
  237. else
  238. inherited a_load_const_cgpara(list,size,a,cgpara);
  239. end;
  240. procedure tcg68k.a_load_ref_cgpara(list : TAsmList;size : tcgsize;const r : treference;const cgpara : tcgpara);
  241. procedure pushdata(paraloc:pcgparalocation;ofs:tcgint);
  242. var
  243. pushsize : tcgsize;
  244. tmpreg : tregister;
  245. href : treference;
  246. ref : treference;
  247. begin
  248. if not assigned(paraloc) then
  249. exit;
  250. { TODO: FIX ME!!! this also triggers location bug }
  251. {if (paraloc^.loc<>LOC_REFERENCE) or
  252. (paraloc^.reference.index<>NR_STACK_POINTER_REG) or
  253. (tcgsize2size[paraloc^.size]>sizeof(tcgint)) then
  254. internalerror(200501162);}
  255. { Pushes are needed in reverse order, add the size of the
  256. current location to the offset where to load from. This
  257. prevents wrong calculations for the last location when
  258. the size is not a power of 2 }
  259. if assigned(paraloc^.next) then
  260. pushdata(paraloc^.next,ofs+tcgsize2size[paraloc^.size]);
  261. { Push the data starting at ofs }
  262. href:=r;
  263. inc(href.offset,ofs);
  264. if tcgsize2size[paraloc^.size]>cgpara.alignment then
  265. pushsize:=paraloc^.size
  266. else
  267. pushsize:=int_cgsize(cgpara.alignment);
  268. reference_reset_base(ref, NR_STACK_POINTER_REG, 0, tcgsize2size[paraloc^.size]);
  269. ref.direction := dir_dec;
  270. if tcgsize2size[paraloc^.size]<cgpara.alignment then
  271. begin
  272. tmpreg:=getintregister(list,pushsize);
  273. a_load_ref_reg(list,paraloc^.size,pushsize,href,tmpreg);
  274. list.concat(taicpu.op_reg_ref(A_MOVE,tcgsize2opsize[pushsize],tmpreg,ref));
  275. end
  276. else
  277. list.concat(taicpu.op_ref_ref(A_MOVE,tcgsize2opsize[pushsize],href,ref));
  278. end;
  279. var
  280. len : tcgint;
  281. href : treference;
  282. begin
  283. {$ifdef DEBUG_CHARLIE}
  284. // writeln('a_load_ref');_cgpara
  285. {$endif DEBUG_CHARLIE}
  286. { cgpara.size=OS_NO requires a copy on the stack }
  287. if use_push(cgpara) then
  288. begin
  289. { Record copy? }
  290. if (cgpara.size in [OS_NO,OS_F64]) or (size=OS_NO) then
  291. begin
  292. cgpara.check_simple_location;
  293. len:=align(cgpara.intsize,cgpara.alignment);
  294. g_stackpointer_alloc(list,len);
  295. reference_reset_base(href,NR_STACK_POINTER_REG,0,cgpara.alignment);
  296. g_concatcopy(list,r,href,len);
  297. end
  298. else
  299. begin
  300. if tcgsize2size[cgpara.size]<>tcgsize2size[size] then
  301. internalerror(200501161);
  302. { We need to push the data in reverse order,
  303. therefor we use a recursive algorithm }
  304. pushdata(cgpara.location,0);
  305. end
  306. end
  307. else
  308. inherited a_load_ref_cgpara(list,size,r,cgpara);
  309. end;
  310. procedure tcg68k.a_loadaddr_ref_cgpara(list : TAsmList;const r : treference;const cgpara : tcgpara);
  311. var
  312. tmpreg : tregister;
  313. opsize : topsize;
  314. begin
  315. {$ifdef DEBUG_CHARLIE}
  316. // writeln('a_loadaddr_ref');_cgpara
  317. {$endif DEBUG_CHARLIE}
  318. with r do
  319. begin
  320. { i suppose this is not required for m68k (KB) }
  321. // if (segment<>NR_NO) then
  322. // cgmessage(cg_e_cant_use_far_pointer_there);
  323. if not use_push(cgpara) then
  324. begin
  325. cgpara.check_simple_location;
  326. opsize:=tcgsize2opsize[OS_ADDR];
  327. if (segment=NR_NO) and (base=NR_NO) and (index=NR_NO) then
  328. begin
  329. if assigned(symbol) then
  330. // list.concat(Taicpu.Op_sym_ofs(A_PUSH,opsize,symbol,offset))
  331. else;
  332. // list.concat(Taicpu.Op_const(A_PUSH,opsize,offset));
  333. end
  334. else if (segment=NR_NO) and (base=NR_NO) and (index<>NR_NO) and
  335. (offset=0) and (scalefactor=0) and (symbol=nil) then
  336. // list.concat(Taicpu.Op_reg(A_PUSH,opsize,index))
  337. else if (segment=NR_NO) and (base<>NR_NO) and (index=NR_NO) and
  338. (offset=0) and (symbol=nil) then
  339. // list.concat(Taicpu.Op_reg(A_PUSH,opsize,base))
  340. else
  341. begin
  342. tmpreg:=getaddressregister(list);
  343. a_loadaddr_ref_reg(list,r,tmpreg);
  344. // list.concat(taicpu.op_reg(A_PUSH,opsize,tmpreg));
  345. end;
  346. end
  347. else
  348. inherited a_loadaddr_ref_cgpara(list,r,cgpara);
  349. end;
  350. end;
  351. function tcg68k.fixref(list: TAsmList; var ref: treference): boolean;
  352. begin
  353. result:=false;
  354. { The Coldfire and MC68020+ have extended
  355. addressing capabilities with a 32-bit
  356. displacement.
  357. }
  358. if (current_settings.cputype<>cpu_MC68000) then
  359. exit;
  360. if (ref.base<>NR_NO) then
  361. begin
  362. if (ref.index <> NR_NO) and assigned(ref.symbol) then
  363. internalerror(20020814);
  364. { base + reg }
  365. if ref.index <> NR_NO then
  366. begin
  367. { base + reg + offset }
  368. if (ref.offset < low(shortint)) or (ref.offset > high(shortint)) then
  369. begin
  370. list.concat(taicpu.op_const_reg(A_ADD,S_L,ref.offset,ref.base));
  371. fixref := true;
  372. ref.offset := 0;
  373. exit;
  374. end;
  375. end
  376. else
  377. { base + offset }
  378. if (ref.offset < low(smallint)) or (ref.offset > high(smallint)) then
  379. begin
  380. list.concat(taicpu.op_const_reg(A_ADD,S_L,ref.offset,ref.base));
  381. fixref := true;
  382. ref.offset := 0;
  383. exit;
  384. end;
  385. end;
  386. end;
  387. procedure tcg68k.a_call_name(list : TAsmList;const s : string; weak: boolean);
  388. var
  389. sym: tasmsymbol;
  390. begin
  391. if not(weak) then
  392. sym:=current_asmdata.RefAsmSymbol(s)
  393. else
  394. sym:=current_asmdata.WeakRefAsmSymbol(s);
  395. list.concat(taicpu.op_sym(A_JSR,S_NO,current_asmdata.RefAsmSymbol(s)));
  396. end;
  397. procedure tcg68k.a_call_reg(list : TAsmList;reg: tregister);
  398. var
  399. tmpref : treference;
  400. tmpreg : tregister;
  401. begin
  402. {$ifdef DEBUG_CHARLIE}
  403. list.concat(tai_comment.create(strpnew('a_call_reg')));
  404. {$endif}
  405. if isaddressregister(reg) then
  406. begin
  407. { if we have an address register, we can jump to the address directly }
  408. reference_reset_base(tmpref,reg,0,4);
  409. end
  410. else
  411. begin
  412. { if we have a data register, we need to move it to an address register first }
  413. tmpreg:=getaddressregister(list);
  414. reference_reset_base(tmpref,tmpreg,0,4);
  415. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg,tmpreg));
  416. end;
  417. list.concat(taicpu.op_ref(A_JSR,S_NO,tmpref));
  418. end;
  419. procedure tcg68k.a_load_const_reg(list : TAsmList;size : tcgsize;a : tcgint;register : tregister);
  420. begin
  421. {$ifdef DEBUG_CHARLIE}
  422. // writeln('a_load_const_reg');
  423. {$endif DEBUG_CHARLIE}
  424. if isaddressregister(register) then
  425. begin
  426. list.concat(taicpu.op_const_reg(A_MOVE,S_L,longint(a),register))
  427. end
  428. else
  429. if a = 0 then
  430. list.concat(taicpu.op_reg(A_CLR,S_L,register))
  431. else
  432. begin
  433. if (longint(a) >= low(shortint)) and (longint(a) <= high(shortint)) then
  434. list.concat(taicpu.op_const_reg(A_MOVEQ,S_L,longint(a),register))
  435. else
  436. list.concat(taicpu.op_const_reg(A_MOVE,S_L,longint(a),register))
  437. end;
  438. end;
  439. procedure tcg68k.a_load_const_ref(list : TAsmList; tosize: tcgsize; a : tcgint;const ref : treference);
  440. begin
  441. {$ifdef DEBUG_CHARLIE}
  442. list.concat(tai_comment.create(strpnew('a_load_const_ref')));
  443. {$endif DEBUG_CHARLIE}
  444. list.concat(taicpu.op_const_ref(A_MOVE,S_L,longint(a),ref));
  445. end;
  446. procedure tcg68k.a_load_reg_ref(list : TAsmList;fromsize,tosize : tcgsize;register : tregister;const ref : treference);
  447. var
  448. href : treference;
  449. begin
  450. href := ref;
  451. fixref(list,href);
  452. {$ifdef DEBUG_CHARLIE}
  453. list.concat(tai_comment.create(strpnew('a_load_reg_ref')));
  454. {$endif DEBUG_CHARLIE}
  455. { move to destination reference }
  456. list.concat(taicpu.op_reg_ref(A_MOVE,TCGSize2OpSize[fromsize],register,href));
  457. end;
  458. procedure tcg68k.a_load_ref_ref(list : TAsmList;fromsize,tosize : tcgsize;const sref : treference;const dref : treference);
  459. var
  460. aref: treference;
  461. bref: treference;
  462. begin
  463. aref := sref;
  464. bref := dref;
  465. fixref(list,aref);
  466. fixref(list,bref);
  467. {$ifdef DEBUG_CHARLIE}
  468. // writeln('a_load_ref_ref');
  469. {$endif DEBUG_CHARLIE}
  470. list.concat(taicpu.op_ref_ref(A_MOVE,TCGSize2OpSize[fromsize],aref,bref));
  471. end;
  472. procedure tcg68k.a_load_reg_reg(list : TAsmList;fromsize,tosize : tcgsize;reg1,reg2 : tregister);
  473. begin
  474. { move to destination register }
  475. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg1,reg2));
  476. { zero/sign extend register to 32-bit }
  477. sign_extend(list, fromsize, reg2);
  478. end;
  479. procedure tcg68k.a_load_ref_reg(list : TAsmList;fromsize,tosize : tcgsize;const ref : treference;register : tregister);
  480. var
  481. href : treference;
  482. begin
  483. href := ref;
  484. fixref(list,href);
  485. list.concat(taicpu.op_ref_reg(A_MOVE,TCGSize2OpSize[fromsize],href,register));
  486. { extend the value in the register }
  487. sign_extend(list, tosize, register);
  488. end;
  489. procedure tcg68k.a_loadaddr_ref_reg(list : TAsmList;const ref : treference;r : tregister);
  490. var
  491. href : treference;
  492. // p: pointer;
  493. begin
  494. { TODO: FIX ME!!! take a look on this mess again...}
  495. // if getregtype(r)=R_ADDRESSREGISTER then
  496. // begin
  497. // writeln('address reg?!?');
  498. // p:=nil; dword(p^):=0; {DEBUG CODE... :D )
  499. // internalerror(2002072901);
  500. // end;
  501. href:=ref;
  502. fixref(list, href);
  503. list.concat(taicpu.op_ref_reg(A_LEA,S_L,href,r));
  504. end;
  505. procedure tcg68k.a_loadfpu_reg_reg(list: TAsmList; fromsize, tosize: tcgsize; reg1, reg2: tregister);
  506. begin
  507. { in emulation mode, only 32-bit single is supported }
  508. if cs_fp_emulation in current_settings.moduleswitches then
  509. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg1,reg2))
  510. else
  511. list.concat(taicpu.op_reg_reg(A_FMOVE,tcgsize2opsize[tosize],reg1,reg2));
  512. end;
  513. procedure tcg68k.a_loadfpu_ref_reg(list: TAsmList; fromsize, tosize: tcgsize; const ref: treference; reg: tregister);
  514. var
  515. opsize : topsize;
  516. href : treference;
  517. tmpreg : tregister;
  518. begin
  519. opsize := tcgsize2opsize[fromsize];
  520. { extended is not supported, since it is not available on Coldfire }
  521. if opsize = S_FX then
  522. internalerror(20020729);
  523. href := ref;
  524. fixref(list,href);
  525. { in emulation mode, only 32-bit single is supported }
  526. if cs_fp_emulation in current_settings.moduleswitches then
  527. list.concat(taicpu.op_ref_reg(A_MOVE,S_L,href,reg))
  528. else
  529. begin
  530. list.concat(taicpu.op_ref_reg(A_FMOVE,opsize,href,reg));
  531. if (tosize < fromsize) then
  532. a_loadfpu_reg_reg(list,fromsize,tosize,reg,reg);
  533. end;
  534. end;
  535. procedure tcg68k.a_loadfpu_reg_ref(list: TAsmList; fromsize,tosize: tcgsize; reg: tregister; const ref: treference);
  536. var
  537. opsize : topsize;
  538. begin
  539. opsize := tcgsize2opsize[tosize];
  540. { extended is not supported, since it is not available on Coldfire }
  541. if opsize = S_FX then
  542. internalerror(20020729);
  543. { in emulation mode, only 32-bit single is supported }
  544. if cs_fp_emulation in current_settings.moduleswitches then
  545. list.concat(taicpu.op_reg_ref(A_MOVE,S_L,reg, ref))
  546. else
  547. list.concat(taicpu.op_reg_ref(A_FMOVE,opsize,reg, ref));
  548. end;
  549. procedure tcg68k.a_loadmm_reg_reg(list: TAsmList;fromsize,tosize : tcgsize; reg1, reg2: tregister;shuffle : pmmshuffle);
  550. begin
  551. internalerror(20020729);
  552. end;
  553. procedure tcg68k.a_loadmm_ref_reg(list: TAsmList;fromsize,tosize : tcgsize; const ref: treference; reg: tregister;shuffle : pmmshuffle);
  554. begin
  555. internalerror(20020729);
  556. end;
  557. procedure tcg68k.a_loadmm_reg_ref(list: TAsmList;fromsize,tosize : tcgsize; reg: tregister; const ref: treference;shuffle : pmmshuffle);
  558. begin
  559. internalerror(20020729);
  560. end;
  561. procedure tcg68k.a_loadmm_reg_cgpara(list: TAsmList; size: tcgsize; reg: tregister;const locpara : TCGPara;shuffle : pmmshuffle);
  562. begin
  563. internalerror(20020729);
  564. end;
  565. procedure tcg68k.a_op_const_reg(list : TAsmList; Op: TOpCG; size: tcgsize; a: tcgint; reg: TRegister);
  566. var
  567. scratch_reg : tregister;
  568. scratch_reg2: tregister;
  569. opcode : tasmop;
  570. r,r2 : Tregister;
  571. begin
  572. optimize_op_const(op, a);
  573. opcode := topcg2tasmop[op];
  574. case op of
  575. OP_NONE :
  576. begin
  577. { Opcode is optimized away }
  578. end;
  579. OP_MOVE :
  580. begin
  581. { Optimized, replaced with a simple load }
  582. a_load_const_reg(list,size,a,reg);
  583. end;
  584. OP_ADD :
  585. begin
  586. if (a >= 1) and (a <= 8) then
  587. list.concat(taicpu.op_const_reg(A_ADDQ,S_L,a, reg))
  588. else
  589. begin
  590. { all others, including coldfire }
  591. list.concat(taicpu.op_const_reg(A_ADD,S_L,a, reg));
  592. end;
  593. end;
  594. OP_AND,
  595. OP_OR:
  596. begin
  597. if isaddressregister(reg) then
  598. begin
  599. { use scratch register (there is a anda/ora though...) }
  600. scratch_reg:=getintregister(list,OS_INT);
  601. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg,scratch_reg));
  602. list.concat(taicpu.op_const_reg(opcode,S_L,longint(a),scratch_reg));
  603. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,scratch_reg,reg));
  604. end
  605. else
  606. list.concat(taicpu.op_const_reg(topcg2tasmop[op],S_L,longint(a), reg));
  607. end;
  608. OP_DIV :
  609. begin
  610. internalerror(20020816);
  611. end;
  612. OP_IDIV :
  613. begin
  614. internalerror(20020816);
  615. end;
  616. OP_IMUL :
  617. begin
  618. if current_settings.cputype = cpu_MC68000 then
  619. begin
  620. r:=NR_D0;
  621. r2:=NR_D1;
  622. cg.getcpuregister(list,NR_D0);
  623. cg.getcpuregister(list,NR_D1);
  624. list.concat(taicpu.op_const_reg(A_MOVE,S_L,a, r));
  625. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg, r2));
  626. cg.a_call_name(list,'FPC_MUL_LONGINT',false);
  627. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,r, reg));
  628. cg.ungetcpuregister(list,r);
  629. cg.ungetcpuregister(list,r2);
  630. end
  631. else
  632. begin
  633. if (isaddressregister(reg)) then
  634. begin
  635. scratch_reg := getintregister(list,OS_INT);
  636. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg, scratch_reg));
  637. list.concat(taicpu.op_const_reg(A_MULS,S_L,a,scratch_reg));
  638. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,scratch_reg,reg));
  639. end
  640. else
  641. list.concat(taicpu.op_const_reg(A_MULS,S_L,a,reg));
  642. end;
  643. end;
  644. OP_MUL :
  645. begin
  646. if current_settings.cputype = cpu_MC68000 then
  647. begin
  648. r:=NR_D0;
  649. r2:=NR_D1;
  650. cg.getcpuregister(list,NR_D0);
  651. cg.getcpuregister(list,NR_D1);
  652. list.concat(taicpu.op_const_reg(A_MOVE,S_L,a, r));
  653. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg, r2));
  654. cg.a_call_name(list,'FPC_MUL_LONGWORD',false);
  655. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,r, reg));
  656. cg.ungetcpuregister(list,r);
  657. cg.ungetcpuregister(list,r2);
  658. end
  659. else
  660. begin
  661. if (isaddressregister(reg)) then
  662. begin
  663. scratch_reg := getintregister(list,OS_INT);
  664. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg, scratch_reg));
  665. list.concat(taicpu.op_const_reg(A_MULU,S_L,a,scratch_reg));
  666. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,scratch_reg,reg));
  667. end
  668. else
  669. list.concat(taicpu.op_const_reg(A_MULU,S_L,a,reg));
  670. end;
  671. end;
  672. OP_SAR,
  673. OP_SHL,
  674. OP_SHR :
  675. begin
  676. if (a >= 1) and (a <= 8) then
  677. begin
  678. { now allowed to shift an address register }
  679. if (isaddressregister(reg)) then
  680. begin
  681. scratch_reg := getintregister(list,OS_INT);
  682. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg, scratch_reg));
  683. list.concat(taicpu.op_const_reg(opcode,S_L,a, scratch_reg));
  684. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,scratch_reg,reg));
  685. end
  686. else
  687. list.concat(taicpu.op_const_reg(opcode,S_L,a, reg));
  688. end
  689. else
  690. begin
  691. { we must load the data into a register ... :() }
  692. scratch_reg := cg.getintregister(list,OS_INT);
  693. list.concat(taicpu.op_const_reg(A_MOVE,S_L,a, scratch_reg));
  694. { again... since shifting with address register is not allowed }
  695. if (isaddressregister(reg)) then
  696. begin
  697. scratch_reg2 := cg.getintregister(list,OS_INT);
  698. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg, scratch_reg2));
  699. list.concat(taicpu.op_reg_reg(opcode,S_L,scratch_reg, scratch_reg2));
  700. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,scratch_reg2,reg));
  701. end
  702. else
  703. list.concat(taicpu.op_reg_reg(opcode,S_L,scratch_reg, reg));
  704. end;
  705. end;
  706. OP_SUB :
  707. begin
  708. if (a >= 1) and (a <= 8) then
  709. list.concat(taicpu.op_const_reg(A_SUBQ,S_L,a,reg))
  710. else
  711. begin
  712. { all others, including coldfire }
  713. list.concat(taicpu.op_const_reg(A_SUB,S_L,a, reg));
  714. end;
  715. end;
  716. OP_XOR :
  717. begin
  718. list.concat(taicpu.op_const_reg(A_EORI,S_L,a, reg));
  719. end;
  720. else
  721. internalerror(20020729);
  722. end;
  723. end;
  724. {
  725. procedure tcg68k.a_op_const_ref(list : TAsmList; Op: TOpCG; size: TCGSize; a: tcgint; const ref: TReference);
  726. var
  727. opcode: tasmop;
  728. begin
  729. writeln('a_op_const_ref');
  730. optimize_op_const(op, a);
  731. opcode := topcg2tasmop[op];
  732. case op of
  733. OP_NONE :
  734. begin
  735. { opcode was optimized away }
  736. end;
  737. OP_MOVE :
  738. begin
  739. { Optimized, replaced with a simple load }
  740. a_load_const_ref(list,size,a,ref);
  741. end;
  742. else
  743. begin
  744. internalerror(2007010101);
  745. end;
  746. end;
  747. end;
  748. }
  749. procedure tcg68k.a_op_reg_reg(list : TAsmList; Op: TOpCG; size: TCGSize; reg1, reg2: TRegister);
  750. var
  751. hreg1,hreg2,r,r2: tregister;
  752. begin
  753. case op of
  754. OP_ADD :
  755. begin
  756. if current_settings.cputype = cpu_ColdFire then
  757. begin
  758. { operation only allowed only a longword }
  759. sign_extend(list, size, reg1);
  760. sign_extend(list, size, reg2);
  761. list.concat(taicpu.op_reg_reg(A_ADD,S_L,reg1, reg2));
  762. end
  763. else
  764. begin
  765. list.concat(taicpu.op_reg_reg(A_ADD,TCGSize2OpSize[size],reg1, reg2));
  766. end;
  767. end;
  768. OP_AND,OP_OR,
  769. OP_SAR,OP_SHL,
  770. OP_SHR,OP_SUB,OP_XOR :
  771. begin
  772. { load to data registers }
  773. if (isaddressregister(reg1)) then
  774. begin
  775. hreg1 := getintregister(list,OS_INT);
  776. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg1,hreg1));
  777. end
  778. else
  779. hreg1 := reg1;
  780. if (isaddressregister(reg2)) then
  781. begin
  782. hreg2:= getintregister(list,OS_INT);
  783. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg2,hreg2));
  784. end
  785. else
  786. hreg2 := reg2;
  787. if current_settings.cputype = cpu_ColdFire then
  788. begin
  789. { operation only allowed only a longword }
  790. {!***************************************
  791. in the case of shifts, the value to
  792. shift by, should already be valid, so
  793. no need to sign extend the value
  794. !
  795. }
  796. if op in [OP_AND,OP_OR,OP_SUB,OP_XOR] then
  797. sign_extend(list, size, hreg1);
  798. sign_extend(list, size, hreg2);
  799. list.concat(taicpu.op_reg_reg(topcg2tasmop[op],S_L,hreg1, hreg2));
  800. end
  801. else
  802. begin
  803. list.concat(taicpu.op_reg_reg(topcg2tasmop[op],TCGSize2OpSize[size],hreg1, hreg2));
  804. end;
  805. { move back result into destination register }
  806. if reg2 <> hreg2 then
  807. begin
  808. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,hreg2,reg2));
  809. end;
  810. end;
  811. OP_DIV :
  812. begin
  813. internalerror(20020816);
  814. end;
  815. OP_IDIV :
  816. begin
  817. internalerror(20020816);
  818. end;
  819. OP_IMUL :
  820. begin
  821. sign_extend(list, size,reg1);
  822. sign_extend(list, size,reg2);
  823. if current_settings.cputype = cpu_MC68000 then
  824. begin
  825. r:=NR_D0;
  826. r2:=NR_D1;
  827. cg.getcpuregister(list,NR_D0);
  828. cg.getcpuregister(list,NR_D1);
  829. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg1, r));
  830. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg2, r2));
  831. cg.a_call_name(list,'FPC_MUL_LONGINT',false);
  832. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,r, reg2));
  833. cg.ungetcpuregister(list,r);
  834. cg.ungetcpuregister(list,r2);
  835. end
  836. else
  837. begin
  838. // writeln('doing 68020');
  839. if (isaddressregister(reg1)) then
  840. hreg1 := getintregister(list,OS_INT)
  841. else
  842. hreg1 := reg1;
  843. if (isaddressregister(reg2)) then
  844. hreg2:= getintregister(list,OS_INT)
  845. else
  846. hreg2 := reg2;
  847. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg1,hreg1));
  848. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg2,hreg2));
  849. list.concat(taicpu.op_reg_reg(A_MULS,S_L,reg1,reg2));
  850. { move back result into destination register }
  851. if reg2 <> hreg2 then
  852. begin
  853. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,hreg2,reg2));
  854. end;
  855. end;
  856. end;
  857. OP_MUL :
  858. begin
  859. sign_extend(list, size,reg1);
  860. sign_extend(list, size,reg2);
  861. if current_settings.cputype = cpu_MC68000 then
  862. begin
  863. r:=NR_D0;
  864. r2:=NR_D1;
  865. cg.getcpuregister(list,NR_D0);
  866. cg.getcpuregister(list,NR_D1);
  867. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg1, r));
  868. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg2, r2));
  869. cg.a_call_name(list,'FPC_MUL_LONGWORD',false);
  870. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,r, reg2));
  871. cg.ungetcpuregister(list,r);
  872. cg.ungetcpuregister(list,r2);
  873. end
  874. else
  875. begin
  876. if (isaddressregister(reg1)) then
  877. begin
  878. hreg1 := cg.getintregister(list,OS_INT);
  879. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg1,hreg1));
  880. end
  881. else
  882. hreg1 := reg1;
  883. if (isaddressregister(reg2)) then
  884. begin
  885. hreg2:= cg.getintregister(list,OS_INT);
  886. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg2,hreg2));
  887. end
  888. else
  889. hreg2 := reg2;
  890. list.concat(taicpu.op_reg_reg(A_MULU,S_L,reg1,reg2));
  891. { move back result into destination register }
  892. if reg2<>hreg2 then
  893. begin
  894. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,hreg2,reg2));
  895. end;
  896. end;
  897. end;
  898. OP_NEG,
  899. OP_NOT :
  900. Begin
  901. { if there are two operands, move the register,
  902. since the operation will only be done on the result
  903. register.
  904. }
  905. if reg1 <> NR_NO then
  906. cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_INT,OS_INT,reg1,reg2);
  907. if (isaddressregister(reg2)) then
  908. begin
  909. hreg2 := getintregister(list,OS_INT);
  910. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg2,hreg2));
  911. end
  912. else
  913. hreg2 := reg2;
  914. { coldfire only supports long version }
  915. if current_settings.cputype = cpu_ColdFire then
  916. begin
  917. sign_extend(list, size,hreg2);
  918. list.concat(taicpu.op_reg(topcg2tasmop[op],S_L,hreg2));
  919. end
  920. else
  921. begin
  922. list.concat(taicpu.op_reg(topcg2tasmop[op],TCGSize2OpSize[size],hreg2));
  923. end;
  924. if reg2 <> hreg2 then
  925. begin
  926. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,hreg2,reg2));
  927. end;
  928. end;
  929. else
  930. internalerror(20020729);
  931. end;
  932. end;
  933. procedure tcg68k.a_cmp_const_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;a : tcgint;reg : tregister;
  934. l : tasmlabel);
  935. var
  936. hregister : tregister;
  937. begin
  938. if a = 0 then
  939. begin
  940. list.concat(taicpu.op_reg(A_TST,TCGSize2OpSize[size],reg));
  941. end
  942. else
  943. begin
  944. if (current_settings.cputype = cpu_ColdFire) then
  945. begin
  946. {
  947. only longword comparison is supported,
  948. and only on data registers.
  949. }
  950. hregister := getintregister(list,OS_INT);
  951. { always move to a data register }
  952. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,reg,hregister));
  953. { sign/zero extend the register }
  954. sign_extend(list, size,hregister);
  955. list.concat(taicpu.op_const_reg(A_CMPI,S_L,a,hregister));
  956. end
  957. else
  958. begin
  959. list.concat(taicpu.op_const_reg(A_CMPI,TCGSize2OpSize[size],a,reg));
  960. end;
  961. end;
  962. { emit the actual jump to the label }
  963. a_jmp_cond(list,cmp_op,l);
  964. end;
  965. procedure tcg68k.a_cmp_reg_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;reg1,reg2 : tregister;l : tasmlabel);
  966. begin
  967. list.concat(taicpu.op_reg_reg(A_CMP,tcgsize2opsize[size],reg1,reg2));
  968. { emit the actual jump to the label }
  969. a_jmp_cond(list,cmp_op,l);
  970. end;
  971. procedure tcg68k.a_jmp_name(list: TAsmList; const s: string);
  972. var
  973. ai: taicpu;
  974. begin
  975. ai := Taicpu.op_sym(A_JMP,S_NO,current_asmdata.RefAsmSymbol(s));
  976. ai.is_jmp := true;
  977. list.concat(ai);
  978. end;
  979. procedure tcg68k.a_jmp_always(list : TAsmList;l: tasmlabel);
  980. var
  981. ai: taicpu;
  982. begin
  983. ai := Taicpu.op_sym(A_JMP,S_NO,l);
  984. ai.is_jmp := true;
  985. list.concat(ai);
  986. end;
  987. procedure tcg68k.a_jmp_flags(list : TAsmList;const f : TResFlags;l: tasmlabel);
  988. var
  989. ai : taicpu;
  990. begin
  991. ai := Taicpu.op_sym(A_BXX,S_NO,l);
  992. ai.SetCondition(flags_to_cond(f));
  993. ai.is_jmp := true;
  994. list.concat(ai);
  995. end;
  996. procedure tcg68k.g_flags2reg(list: TAsmList; size: TCgSize; const f: tresflags; reg: TRegister);
  997. var
  998. ai : taicpu;
  999. hreg : tregister;
  1000. begin
  1001. { move to a Dx register? }
  1002. if (isaddressregister(reg)) then
  1003. begin
  1004. hreg := getintregister(list,OS_INT);
  1005. a_load_const_reg(list,size,0,hreg);
  1006. ai:=Taicpu.Op_reg(A_Sxx,S_B,hreg);
  1007. ai.SetCondition(flags_to_cond(f));
  1008. list.concat(ai);
  1009. if (current_settings.cputype = cpu_ColdFire) then
  1010. begin
  1011. { neg.b does not exist on the Coldfire
  1012. so we need to sign extend the value
  1013. before doing a neg.l
  1014. }
  1015. list.concat(taicpu.op_reg(A_EXTB,S_L,hreg));
  1016. list.concat(taicpu.op_reg(A_NEG,S_L,hreg));
  1017. end
  1018. else
  1019. begin
  1020. list.concat(taicpu.op_reg(A_NEG,S_B,hreg));
  1021. end;
  1022. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,hreg,reg));
  1023. end
  1024. else
  1025. begin
  1026. a_load_const_reg(list,size,0,reg);
  1027. ai:=Taicpu.Op_reg(A_Sxx,S_B,reg);
  1028. ai.SetCondition(flags_to_cond(f));
  1029. list.concat(ai);
  1030. if (current_settings.cputype = cpu_ColdFire) then
  1031. begin
  1032. { neg.b does not exist on the Coldfire
  1033. so we need to sign extend the value
  1034. before doing a neg.l
  1035. }
  1036. list.concat(taicpu.op_reg(A_EXTB,S_L,reg));
  1037. list.concat(taicpu.op_reg(A_NEG,S_L,reg));
  1038. end
  1039. else
  1040. begin
  1041. list.concat(taicpu.op_reg(A_NEG,S_B,reg));
  1042. end;
  1043. end;
  1044. end;
  1045. procedure tcg68k.g_concatcopy(list : TAsmList;const source,dest : treference;len : tcgint);
  1046. var
  1047. helpsize : longint;
  1048. i : byte;
  1049. reg8,reg32 : tregister;
  1050. swap : boolean;
  1051. hregister : tregister;
  1052. iregister : tregister;
  1053. jregister : tregister;
  1054. hp1 : treference;
  1055. hp2 : treference;
  1056. hl : tasmlabel;
  1057. hl2: tasmlabel;
  1058. popaddress : boolean;
  1059. srcref,dstref : treference;
  1060. begin
  1061. popaddress := false;
  1062. // writeln('concatcopy:',len);
  1063. { this should never occur }
  1064. if len > 65535 then
  1065. internalerror(0);
  1066. hregister := getintregister(list,OS_INT);
  1067. // if delsource then
  1068. // reference_release(list,source);
  1069. { from 12 bytes movs is being used }
  1070. if {(not loadref) and} ((len<=8) or (not(cs_opt_size in current_settings.optimizerswitches) and (len<=12))) then
  1071. begin
  1072. srcref := source;
  1073. dstref := dest;
  1074. helpsize:=len div 4;
  1075. { move a dword x times }
  1076. for i:=1 to helpsize do
  1077. begin
  1078. a_load_ref_reg(list,OS_INT,OS_INT,srcref,hregister);
  1079. a_load_reg_ref(list,OS_INT,OS_INT,hregister,dstref);
  1080. inc(srcref.offset,4);
  1081. inc(dstref.offset,4);
  1082. dec(len,4);
  1083. end;
  1084. { move a word }
  1085. if len>1 then
  1086. begin
  1087. a_load_ref_reg(list,OS_16,OS_16,srcref,hregister);
  1088. a_load_reg_ref(list,OS_16,OS_16,hregister,dstref);
  1089. inc(srcref.offset,2);
  1090. inc(dstref.offset,2);
  1091. dec(len,2);
  1092. end;
  1093. { move a single byte }
  1094. if len>0 then
  1095. begin
  1096. a_load_ref_reg(list,OS_8,OS_8,srcref,hregister);
  1097. a_load_reg_ref(list,OS_8,OS_8,hregister,dstref);
  1098. end
  1099. end
  1100. else
  1101. begin
  1102. iregister:=getaddressregister(list);
  1103. jregister:=getaddressregister(list);
  1104. { reference for move (An)+,(An)+ }
  1105. reference_reset(hp1,source.alignment);
  1106. hp1.base := iregister; { source register }
  1107. hp1.direction := dir_inc;
  1108. reference_reset(hp2,dest.alignment);
  1109. hp2.base := jregister;
  1110. hp2.direction := dir_inc;
  1111. { iregister = source }
  1112. { jregister = destination }
  1113. { if loadref then
  1114. cg.a_load_ref_reg(list,OS_INT,OS_INT,source,iregister)
  1115. else}
  1116. a_loadaddr_ref_reg(list,source,iregister);
  1117. a_loadaddr_ref_reg(list,dest,jregister);
  1118. { double word move only on 68020+ machines }
  1119. { because of possible alignment problems }
  1120. { use fast loop mode }
  1121. if (current_settings.cputype=cpu_MC68020) then
  1122. begin
  1123. helpsize := len - len mod 4;
  1124. len := len mod 4;
  1125. list.concat(taicpu.op_const_reg(A_MOVE,S_L,helpsize div 4,hregister));
  1126. current_asmdata.getjumplabel(hl2);
  1127. a_jmp_always(list,hl2);
  1128. current_asmdata.getjumplabel(hl);
  1129. a_label(list,hl);
  1130. list.concat(taicpu.op_ref_ref(A_MOVE,S_L,hp1,hp2));
  1131. a_label(list,hl2);
  1132. list.concat(taicpu.op_reg_sym(A_DBRA,S_L,hregister,hl));
  1133. if len > 1 then
  1134. begin
  1135. dec(len,2);
  1136. list.concat(taicpu.op_ref_ref(A_MOVE,S_W,hp1,hp2));
  1137. end;
  1138. if len = 1 then
  1139. list.concat(taicpu.op_ref_ref(A_MOVE,S_B,hp1,hp2));
  1140. end
  1141. else
  1142. begin
  1143. { Fast 68010 loop mode with no possible alignment problems }
  1144. helpsize := len;
  1145. list.concat(taicpu.op_const_reg(A_MOVE,S_L,helpsize,hregister));
  1146. current_asmdata.getjumplabel(hl2);
  1147. a_jmp_always(list,hl2);
  1148. current_asmdata.getjumplabel(hl);
  1149. a_label(list,hl);
  1150. list.concat(taicpu.op_ref_ref(A_MOVE,S_B,hp1,hp2));
  1151. a_label(list,hl2);
  1152. list.concat(taicpu.op_reg_sym(A_DBRA,S_L,hregister,hl));
  1153. end;
  1154. { restore the registers that we have just used olny if they are used! }
  1155. if jregister = NR_A1 then
  1156. hp2.base := NR_NO;
  1157. if iregister = NR_A0 then
  1158. hp1.base := NR_NO;
  1159. // reference_release(list,hp1);
  1160. // reference_release(list,hp2);
  1161. end;
  1162. // if delsource then
  1163. // tg.ungetiftemp(list,source);
  1164. end;
  1165. procedure tcg68k.g_overflowcheck(list: TAsmList; const l:tlocation; def:tdef);
  1166. begin
  1167. end;
  1168. procedure tcg68k.g_proc_entry(list: TAsmList; localsize: longint; nostackframe:boolean);
  1169. var
  1170. r,rsp: TRegister;
  1171. ref : TReference;
  1172. begin
  1173. {$ifdef DEBUG_CHARLIE}
  1174. // writeln('proc entry, localsize:',localsize);
  1175. {$endif DEBUG_CHARLIE}
  1176. if not nostackframe then
  1177. begin
  1178. if localsize<>0 then
  1179. begin
  1180. { size can't be negative }
  1181. if (localsize < 0) then
  1182. internalerror(2006122601);
  1183. { Not to complicate the code generator too much, and since some }
  1184. { of the systems only support this format, the localsize cannot }
  1185. { exceed 32K in size. }
  1186. if (localsize > high(smallint)) then
  1187. CGMessage(cg_e_localsize_too_big);
  1188. list.concat(taicpu.op_reg_const(A_LINK,S_W,NR_FRAME_POINTER_REG,-localsize));
  1189. end
  1190. else
  1191. begin
  1192. list.concat(taicpu.op_reg_const(A_LINK,S_W,NR_FRAME_POINTER_REG,0));
  1193. (*
  1194. { FIXME! - Carl's original code uses this method. However,
  1195. according to the 68060 users manual, a LINK is faster than
  1196. two moves. So, use a link in #0 case too, for now. I'm not
  1197. really sure tho', that LINK supports #0 disposition, but i
  1198. see no reason why it shouldn't support it. (KB) }
  1199. { when localsize = 0, use two moves, instead of link }
  1200. r:=NR_FRAME_POINTER_REG;
  1201. rsp:=NR_STACK_POINTER_REG;
  1202. reference_reset_base(ref,NR_STACK_POINTER_REG,0);
  1203. ref.direction:=dir_dec;
  1204. list.concat(taicpu.op_reg_ref(A_MOVE,S_L,r,ref));
  1205. list.concat(taicpu.op_reg_reg(A_MOVE,S_L,rsp,r));
  1206. *)
  1207. end;
  1208. end;
  1209. end;
  1210. { procedure tcg68k.g_restore_frame_pointer(list : TAsmList);
  1211. var
  1212. r:Tregister;
  1213. begin
  1214. r:=NR_FRAME_POINTER_REG;
  1215. list.concat(taicpu.op_reg(A_UNLK,S_NO,r));
  1216. end;
  1217. }
  1218. procedure tcg68k.g_proc_exit(list : TAsmList; parasize: longint; nostackframe: boolean);
  1219. var
  1220. r,hregister : TRegister;
  1221. localsize: tcgint;
  1222. spr : TRegister;
  1223. fpr : TRegister;
  1224. ref : TReference;
  1225. begin
  1226. if not nostackframe then
  1227. begin
  1228. localsize := current_procinfo.calc_stackframe_size;
  1229. {$ifdef DEBUG_CHARLIE}
  1230. // writeln('proc exit with stackframe, size:',localsize,' parasize:',parasize);
  1231. {$endif DEBUG_CHARLIE}
  1232. list.concat(taicpu.op_reg(A_UNLK,S_NO,NR_FRAME_POINTER_REG));
  1233. parasize := parasize - target_info.first_parm_offset; { i'm still not 100% confident that this is
  1234. correct here, but at least it looks less
  1235. hacky, and makes some sense (KB) }
  1236. if (parasize<>0) then
  1237. begin
  1238. { only 68020+ supports RTD, so this needs another code path
  1239. for 68000 and Coldfire (KB) }
  1240. { TODO: 68020+ only code generation, without fallback}
  1241. if current_settings.cputype=cpu_mc68020 then
  1242. list.concat(taicpu.op_const(A_RTD,S_NO,parasize))
  1243. else
  1244. begin
  1245. { We must pull the PC Counter from the stack, before }
  1246. { restoring the stack pointer, otherwise the PC would }
  1247. { point to nowhere! }
  1248. { save the PC counter (pop it from the stack) }
  1249. //hregister:=cg.getaddressregister(list);
  1250. hregister:=NR_A3;
  1251. cg.a_reg_alloc(list,hregister);
  1252. reference_reset_base(ref,NR_STACK_POINTER_REG,0,4);
  1253. ref.direction:=dir_inc;
  1254. list.concat(taicpu.op_ref_reg(A_MOVE,S_L,ref,hregister));
  1255. { can we do a quick addition ... }
  1256. r:=NR_SP;
  1257. if (parasize > 0) and (parasize < 9) then
  1258. list.concat(taicpu.op_const_reg(A_ADDQ,S_L,parasize,r))
  1259. else { nope ... }
  1260. list.concat(taicpu.op_const_reg(A_ADD,S_L,parasize,r));
  1261. { restore the PC counter (push it on the stack) }
  1262. reference_reset_base(ref,NR_STACK_POINTER_REG,0,4);
  1263. ref.direction:=dir_dec;
  1264. cg.a_reg_alloc(list,hregister);
  1265. list.concat(taicpu.op_reg_ref(A_MOVE,S_L,hregister,ref));
  1266. list.concat(taicpu.op_none(A_RTS,S_NO));
  1267. end;
  1268. end
  1269. else
  1270. list.concat(taicpu.op_none(A_RTS,S_NO));
  1271. end
  1272. else
  1273. begin
  1274. {$ifdef DEBUG_CHARLIE}
  1275. // writeln('proc exit, no stackframe');
  1276. {$endif DEBUG_CHARLIE}
  1277. list.concat(taicpu.op_none(A_RTS,S_NO));
  1278. end;
  1279. // writeln('g_proc_exit');
  1280. { Routines with the poclearstack flag set use only a ret.
  1281. also routines with parasize=0 }
  1282. (*
  1283. if current_procinfo.procdef.proccalloption in clearstack_pocalls then
  1284. begin
  1285. { complex return values are removed from stack in C code PM }
  1286. if paramanager.ret_in_param(current_procinfo.procdef.returndef,current_procinfo.procdef.proccalloption) then
  1287. list.concat(taicpu.op_const(A_RTD,S_NO,4))
  1288. else
  1289. list.concat(taicpu.op_none(A_RTS,S_NO));
  1290. end
  1291. else if (parasize=0) then
  1292. begin
  1293. list.concat(taicpu.op_none(A_RTS,S_NO));
  1294. end
  1295. else
  1296. begin
  1297. { return with immediate size possible here
  1298. signed!
  1299. RTD is not supported on the coldfire }
  1300. if (current_settings.cputype=cpu_MC68020) and (parasize<$7FFF) then
  1301. list.concat(taicpu.op_const(A_RTD,S_NO,parasize))
  1302. { manually restore the stack }
  1303. else
  1304. begin
  1305. { We must pull the PC Counter from the stack, before }
  1306. { restoring the stack pointer, otherwise the PC would }
  1307. { point to nowhere! }
  1308. { save the PC counter (pop it from the stack) }
  1309. hregister:=NR_A3;
  1310. cg.a_reg_alloc(list,hregister);
  1311. reference_reset_base(ref,NR_STACK_POINTER_REG,0);
  1312. ref.direction:=dir_inc;
  1313. list.concat(taicpu.op_ref_reg(A_MOVE,S_L,ref,hregister));
  1314. { can we do a quick addition ... }
  1315. r:=NR_SP;
  1316. if (parasize > 0) and (parasize < 9) then
  1317. list.concat(taicpu.op_const_reg(A_ADDQ,S_L,parasize,r))
  1318. else { nope ... }
  1319. list.concat(taicpu.op_const_reg(A_ADD,S_L,parasize,r));
  1320. { restore the PC counter (push it on the stack) }
  1321. reference_reset_base(ref,NR_STACK_POINTER_REG,0);
  1322. ref.direction:=dir_dec;
  1323. cg.a_reg_alloc(list,hregister);
  1324. list.concat(taicpu.op_reg_ref(A_MOVE,S_L,hregister,ref));
  1325. list.concat(taicpu.op_none(A_RTS,S_NO));
  1326. end;
  1327. end;
  1328. *)
  1329. end;
  1330. procedure Tcg68k.g_save_registers(list:TAsmList);
  1331. var
  1332. tosave : tcpuregisterset;
  1333. ref : treference;
  1334. begin
  1335. {!!!!!
  1336. tosave:=std_saved_registers;
  1337. { only save the registers which are not used and must be saved }
  1338. tosave:=tosave*(rg[R_INTREGISTER].used_in_proc+rg[R_ADDRESSREGISTER].used_in_proc);
  1339. reference_reset_base(ref,NR_STACK_POINTER_REG,0);
  1340. ref.direction:=dir_dec;
  1341. if tosave<>[] then
  1342. list.concat(taicpu.op_regset_ref(A_MOVEM,S_L,tosave,ref));
  1343. }
  1344. end;
  1345. procedure Tcg68k.g_restore_registers(list:TAsmList);
  1346. var
  1347. torestore : tcpuregisterset;
  1348. r:Tregister;
  1349. ref : treference;
  1350. begin
  1351. {!!!!!!!!
  1352. torestore:=std_saved_registers;
  1353. { should be intersected with used regs, no ? }
  1354. torestore:=torestore*(rg[R_INTREGISTER].used_in_proc+rg[R_ADDRESSREGISTER].used_in_proc);
  1355. reference_reset_base(ref,NR_STACK_POINTER_REG,0);
  1356. ref.direction:=dir_inc;
  1357. if torestore<>[] then
  1358. list.concat(taicpu.op_ref_regset(A_MOVEM,S_L,ref,torestore));
  1359. }
  1360. end;
  1361. {
  1362. procedure tcg68k.g_save_all_registers(list : TAsmList);
  1363. begin
  1364. end;
  1365. procedure tcg68k.g_restore_all_registers(list : TAsmList;const funcretparaloc:TCGPara);
  1366. begin
  1367. end;
  1368. }
  1369. procedure tcg68k.sign_extend(list: TAsmList;_oldsize : tcgsize; reg: tregister);
  1370. begin
  1371. case _oldsize of
  1372. { sign extend }
  1373. OS_S8:
  1374. begin
  1375. if (isaddressregister(reg)) then
  1376. internalerror(20020729);
  1377. if (current_settings.cputype = cpu_MC68000) then
  1378. begin
  1379. list.concat(taicpu.op_reg(A_EXT,S_W,reg));
  1380. list.concat(taicpu.op_reg(A_EXT,S_L,reg));
  1381. end
  1382. else
  1383. begin
  1384. // list.concat(tai_comment.create(strpnew('sign extend byte')));
  1385. list.concat(taicpu.op_reg(A_EXTB,S_L,reg));
  1386. end;
  1387. end;
  1388. OS_S16:
  1389. begin
  1390. if (isaddressregister(reg)) then
  1391. internalerror(20020729);
  1392. // list.concat(tai_comment.create(strpnew('sign extend word')));
  1393. list.concat(taicpu.op_reg(A_EXT,S_L,reg));
  1394. end;
  1395. { zero extend }
  1396. OS_8:
  1397. begin
  1398. // list.concat(tai_comment.create(strpnew('zero extend byte')));
  1399. list.concat(taicpu.op_const_reg(A_AND,S_L,$FF,reg));
  1400. end;
  1401. OS_16:
  1402. begin
  1403. // list.concat(tai_comment.create(strpnew('zero extend word')));
  1404. list.concat(taicpu.op_const_reg(A_AND,S_L,$FFFF,reg));
  1405. end;
  1406. end; { otherwise the size is already correct }
  1407. end;
  1408. procedure tcg68k.a_jmp_cond(list : TAsmList;cond : TOpCmp;l: tasmlabel);
  1409. var
  1410. ai : taicpu;
  1411. begin
  1412. if cond=OC_None then
  1413. ai := Taicpu.Op_sym(A_JMP,S_NO,l)
  1414. else
  1415. begin
  1416. ai:=Taicpu.Op_sym(A_Bxx,S_NO,l);
  1417. ai.SetCondition(TOpCmp2AsmCond[cond]);
  1418. end;
  1419. ai.is_jmp:=true;
  1420. list.concat(ai);
  1421. end;
  1422. procedure tcg68k.g_intf_wrapper(list: TAsmList; procdef: tprocdef; const labelname: string; ioffset: longint);
  1423. {
  1424. procedure loadvmttor11;
  1425. var
  1426. href : treference;
  1427. begin
  1428. reference_reset_base(href,NR_R3,0);
  1429. cg.a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,NR_R11);
  1430. end;
  1431. procedure op_onr11methodaddr;
  1432. var
  1433. href : treference;
  1434. begin
  1435. if (procdef.extnumber=$ffff) then
  1436. Internalerror(200006139);
  1437. { call/jmp vmtoffs(%eax) ; method offs }
  1438. reference_reset_base(href,NR_R11,tobjectdef(procdef.struct).vmtmethodoffset(procdef.extnumber));
  1439. if not((longint(href.offset) >= low(smallint)) and
  1440. (longint(href.offset) <= high(smallint))) then
  1441. begin
  1442. list.concat(taicpu.op_reg_reg_const(A_ADDIS,NR_R11,NR_R11,
  1443. smallint((href.offset shr 16)+ord(smallint(href.offset and $ffff) < 0))));
  1444. href.offset := smallint(href.offset and $ffff);
  1445. end;
  1446. list.concat(taicpu.op_reg_ref(A_LWZ,NR_R11,href));
  1447. list.concat(taicpu.op_reg(A_MTCTR,NR_R11));
  1448. list.concat(taicpu.op_none(A_BCTR));
  1449. end;
  1450. }
  1451. var
  1452. make_global : boolean;
  1453. begin
  1454. if not(procdef.proctypeoption in [potype_function,potype_procedure]) then
  1455. Internalerror(200006137);
  1456. if not assigned(procdef.struct) or
  1457. (procdef.procoptions*[po_classmethod, po_staticmethod,
  1458. po_methodpointer, po_interrupt, po_iocheck]<>[]) then
  1459. Internalerror(200006138);
  1460. if procdef.owner.symtabletype<>ObjectSymtable then
  1461. Internalerror(200109191);
  1462. make_global:=false;
  1463. if (not current_module.is_unit) or
  1464. create_smartlink or
  1465. (procdef.owner.defowner.owner.symtabletype=globalsymtable) then
  1466. make_global:=true;
  1467. if make_global then
  1468. List.concat(Tai_symbol.Createname_global(labelname,AT_FUNCTION,0))
  1469. else
  1470. List.concat(Tai_symbol.Createname(labelname,AT_FUNCTION,0));
  1471. { set param1 interface to self }
  1472. // g_adjust_self_value(list,procdef,ioffset);
  1473. { case 4 }
  1474. if (po_virtualmethod in procdef.procoptions) and
  1475. not is_objectpascal_helper(procdef.struct) then
  1476. begin
  1477. // loadvmttor11;
  1478. // op_onr11methodaddr;
  1479. end
  1480. { case 0 }
  1481. else
  1482. // list.concat(taicpu.op_sym(A_B,current_asmdata.RefAsmSymbol(procdef.mangledname)));
  1483. List.concat(Tai_symbol_end.Createname(labelname));
  1484. end;
  1485. {****************************************************************************}
  1486. { TCG64F68K }
  1487. {****************************************************************************}
  1488. procedure tcg64f68k.a_op64_reg_reg(list : TAsmList;op:TOpCG;size: tcgsize; regsrc,regdst : tregister64);
  1489. var
  1490. hreg1, hreg2 : tregister;
  1491. opcode : tasmop;
  1492. begin
  1493. // writeln('a_op64_reg_reg');
  1494. opcode := topcg2tasmop[op];
  1495. case op of
  1496. OP_ADD :
  1497. begin
  1498. { if one of these three registers is an address
  1499. register, we'll really get into problems!
  1500. }
  1501. if isaddressregister(regdst.reglo) or
  1502. isaddressregister(regdst.reghi) or
  1503. isaddressregister(regsrc.reghi) then
  1504. internalerror(20020817);
  1505. list.concat(taicpu.op_reg_reg(A_ADD,S_L,regsrc.reglo,regdst.reglo));
  1506. list.concat(taicpu.op_reg_reg(A_ADDX,S_L,regsrc.reghi,regdst.reghi));
  1507. end;
  1508. OP_AND,OP_OR :
  1509. begin
  1510. { at least one of the registers must be a data register }
  1511. if (isaddressregister(regdst.reglo) and
  1512. isaddressregister(regsrc.reglo)) or
  1513. (isaddressregister(regsrc.reghi) and
  1514. isaddressregister(regdst.reghi))
  1515. then
  1516. internalerror(20020817);
  1517. cg.a_op_reg_reg(list,op,OS_32,regsrc.reglo,regdst.reglo);
  1518. cg.a_op_reg_reg(list,op,OS_32,regsrc.reghi,regdst.reghi);
  1519. end;
  1520. { this is handled in 1st pass for 32-bit cpu's (helper call) }
  1521. OP_IDIV,OP_DIV,
  1522. OP_IMUL,OP_MUL: internalerror(2002081701);
  1523. { this is also handled in 1st pass for 32-bit cpu's (helper call) }
  1524. OP_SAR,OP_SHL,OP_SHR: internalerror(2002081702);
  1525. OP_SUB:
  1526. begin
  1527. { if one of these three registers is an address
  1528. register, we'll really get into problems!
  1529. }
  1530. if isaddressregister(regdst.reglo) or
  1531. isaddressregister(regdst.reghi) or
  1532. isaddressregister(regsrc.reghi) then
  1533. internalerror(20020817);
  1534. list.concat(taicpu.op_reg_reg(A_SUB,S_L,regsrc.reglo,regdst.reglo));
  1535. list.concat(taicpu.op_reg_reg(A_SUBX,S_L,regsrc.reghi,regdst.reghi));
  1536. end;
  1537. OP_XOR:
  1538. begin
  1539. if isaddressregister(regdst.reglo) or
  1540. isaddressregister(regsrc.reglo) or
  1541. isaddressregister(regsrc.reghi) or
  1542. isaddressregister(regdst.reghi) then
  1543. internalerror(20020817);
  1544. list.concat(taicpu.op_reg_reg(A_EOR,S_L,regsrc.reglo,regdst.reglo));
  1545. list.concat(taicpu.op_reg_reg(A_EOR,S_L,regsrc.reghi,regdst.reghi));
  1546. end;
  1547. end; { end case }
  1548. end;
  1549. procedure tcg64f68k.a_op64_const_reg(list : TAsmList;op:TOpCG;size: tcgsize; value : int64;regdst : tregister64);
  1550. var
  1551. lowvalue : cardinal;
  1552. highvalue : cardinal;
  1553. hreg : tregister;
  1554. begin
  1555. // writeln('a_op64_const_reg');
  1556. { is it optimized out ? }
  1557. // if cg.optimize64_op_const_reg(list,op,value,reg) then
  1558. // exit;
  1559. lowvalue := cardinal(value);
  1560. highvalue:= value shr 32;
  1561. { the destination registers must be data registers }
  1562. if isaddressregister(regdst.reglo) or
  1563. isaddressregister(regdst.reghi) then
  1564. internalerror(20020817);
  1565. case op of
  1566. OP_ADD :
  1567. begin
  1568. hreg:=cg.getintregister(list,OS_INT);
  1569. list.concat(taicpu.op_const_reg(A_MOVE,S_L,highvalue,hreg));
  1570. list.concat(taicpu.op_const_reg(A_ADD,S_L,lowvalue,regdst.reglo));
  1571. list.concat(taicpu.op_reg_reg(A_ADDX,S_L,hreg,regdst.reglo));
  1572. end;
  1573. OP_AND :
  1574. begin
  1575. list.concat(taicpu.op_const_reg(A_AND,S_L,lowvalue,regdst.reglo));
  1576. list.concat(taicpu.op_const_reg(A_AND,S_L,highvalue,regdst.reglo));
  1577. end;
  1578. OP_OR :
  1579. begin
  1580. list.concat(taicpu.op_const_reg(A_OR,S_L,lowvalue,regdst.reglo));
  1581. list.concat(taicpu.op_const_reg(A_OR,S_L,highvalue,regdst.reglo));
  1582. end;
  1583. { this is handled in 1st pass for 32-bit cpus (helper call) }
  1584. OP_IDIV,OP_DIV,
  1585. OP_IMUL,OP_MUL: internalerror(2002081701);
  1586. { this is also handled in 1st pass for 32-bit cpus (helper call) }
  1587. OP_SAR,OP_SHL,OP_SHR: internalerror(2002081702);
  1588. OP_SUB:
  1589. begin
  1590. hreg:=cg.getintregister(list,OS_INT);
  1591. list.concat(taicpu.op_const_reg(A_MOVE,S_L,highvalue,hreg));
  1592. list.concat(taicpu.op_const_reg(A_SUB,S_L,lowvalue,regdst.reglo));
  1593. list.concat(taicpu.op_reg_reg(A_SUBX,S_L,hreg,regdst.reglo));
  1594. end;
  1595. OP_XOR:
  1596. begin
  1597. list.concat(taicpu.op_const_reg(A_EOR,S_L,lowvalue,regdst.reglo));
  1598. list.concat(taicpu.op_const_reg(A_EOR,S_L,highvalue,regdst.reglo));
  1599. end;
  1600. end; { end case }
  1601. end;
  1602. procedure create_codegen;
  1603. begin
  1604. cg := tcg68k.create;
  1605. cg64 :=tcg64f68k.create;
  1606. end;
  1607. end.