cgcpu.pas 106 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. This unit implements the code generator for the PowerPC
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit cgcpu;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. symtype,
  23. cgbase,cgobj,
  24. aasmbase,aasmcpu,aasmtai,
  25. cpubase,cpuinfo,node,cg64f32,cginfo;
  26. type
  27. tcgppc = class(tcg)
  28. { passing parameters, per default the parameter is pushed }
  29. { nr gives the number of the parameter (enumerated from }
  30. { left to right), this allows to move the parameter to }
  31. { register, if the cpu supports register calling }
  32. { conventions }
  33. procedure a_param_const(list : taasmoutput;size : tcgsize;a : aword;const locpara : tparalocation);override;
  34. procedure a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;const locpara : tparalocation);override;
  35. procedure a_paramaddr_ref(list : taasmoutput;const r : treference;const locpara : tparalocation);override;
  36. procedure a_call_name(list : taasmoutput;const s : string);override;
  37. procedure a_call_reg(list : taasmoutput;reg: tregister); override;
  38. procedure a_call_ref(list : taasmoutput;const ref : treference);override;
  39. procedure a_op_const_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; a: AWord; reg: TRegister); override;
  40. procedure a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; src, dst: TRegister); override;
  41. procedure a_op_const_reg_reg(list: taasmoutput; op: TOpCg;
  42. size: tcgsize; a: aword; src, dst: tregister); override;
  43. procedure a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;
  44. size: tcgsize; src1, src2, dst: tregister); override;
  45. { move instructions }
  46. procedure a_load_const_reg(list : taasmoutput; size: tcgsize; a : aword;reg : tregister);override;
  47. procedure a_load_reg_ref(list : taasmoutput; fromsize, tosize: tcgsize; reg : tregister;const ref : treference);override;
  48. procedure a_load_ref_reg(list : taasmoutput; fromsize, tosize : tcgsize;const Ref : treference;reg : tregister);override;
  49. procedure a_load_reg_reg(list : taasmoutput; fromsize, tosize : tcgsize;reg1,reg2 : tregister);override;
  50. { fpu move instructions }
  51. procedure a_loadfpu_reg_reg(list: taasmoutput; size: tcgsize; reg1, reg2: tregister); override;
  52. procedure a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister); override;
  53. procedure a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference); override;
  54. { comparison operations }
  55. procedure a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;reg : tregister;
  56. l : tasmlabel);override;
  57. procedure a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;reg1,reg2 : tregister;l : tasmlabel); override;
  58. procedure a_jmp_always(list : taasmoutput;l: tasmlabel); override;
  59. procedure a_jmp_flags(list : taasmoutput;const f : TResFlags;l: tasmlabel); override;
  60. procedure g_flags2reg(list: taasmoutput; size: TCgSize; const f: TResFlags; reg: TRegister); override;
  61. procedure g_copyvaluepara_openarray(list : taasmoutput;const ref, lenref:treference;elesize:integer);override;
  62. procedure g_stackframe_entry(list : taasmoutput;localsize : longint);override;
  63. procedure g_return_from_proc(list : taasmoutput;parasize : aword); override;
  64. procedure g_restore_frame_pointer(list : taasmoutput);override;
  65. procedure a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);override;
  66. procedure g_concatcopy(list : taasmoutput;const source,dest : treference;len : aword; delsource,loadref : boolean);override;
  67. procedure g_overflowcheck(list: taasmoutput; const l: tlocation; def: tdef); override;
  68. { find out whether a is of the form 11..00..11b or 00..11...00. If }
  69. { that's the case, we can use rlwinm to do an AND operation }
  70. function get_rlwi_const(a: aword; var l1, l2: longint): boolean;
  71. procedure g_save_standard_registers(list : taasmoutput; usedinproc : Tsupregset);override;
  72. procedure g_restore_standard_registers(list : taasmoutput; usedinproc : Tsupregset);override;
  73. procedure g_save_all_registers(list : taasmoutput);override;
  74. procedure g_restore_all_registers(list : taasmoutput;accused,acchiused:boolean);override;
  75. procedure a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel);
  76. private
  77. procedure g_stackframe_entry_sysv(list : taasmoutput;localsize : longint);
  78. procedure g_return_from_proc_sysv(list : taasmoutput;parasize : aword);
  79. procedure g_stackframe_entry_aix(list : taasmoutput;localsize : longint);
  80. procedure g_return_from_proc_aix(list : taasmoutput;parasize : aword);
  81. procedure g_stackframe_entry_mac(list : taasmoutput;localsize : longint);
  82. procedure g_return_from_proc_mac(list : taasmoutput;parasize : aword);
  83. { Make sure ref is a valid reference for the PowerPC and sets the }
  84. { base to the value of the index if (base = R_NO). }
  85. { Returns true if the reference contained a base, index and an }
  86. { offset or symbol, in which case the base will have been changed }
  87. { to a tempreg (which has to be freed by the caller) containing }
  88. { the sum of part of the original reference }
  89. function fixref(list: taasmoutput; var ref: treference): boolean;
  90. { returns whether a reference can be used immediately in a powerpc }
  91. { instruction }
  92. function issimpleref(const ref: treference): boolean;
  93. { contains the common code of a_load_reg_ref and a_load_ref_reg }
  94. procedure a_load_store(list:taasmoutput;op: tasmop;reg:tregister;
  95. ref: treference);
  96. { creates the correct branch instruction for a given combination }
  97. { of asmcondflags and destination addressing mode }
  98. procedure a_jmp(list: taasmoutput; op: tasmop;
  99. c: tasmcondflag; crval: longint; l: tasmlabel);
  100. end;
  101. tcg64fppc = class(tcg64f32)
  102. procedure a_op64_reg_reg(list : taasmoutput;op:TOpCG;regsrc,regdst : tregister64);override;
  103. procedure a_op64_const_reg(list : taasmoutput;op:TOpCG;value : qword;reg : tregister64);override;
  104. procedure a_op64_const_reg_reg(list: taasmoutput;op:TOpCG;value : qword;regsrc,regdst : tregister64);override;
  105. procedure a_op64_reg_reg_reg(list: taasmoutput;op:TOpCG;regsrc1,regsrc2,regdst : tregister64);override;
  106. end;
  107. const
  108. TOpCG2AsmOpConstLo: Array[topcg] of TAsmOp = (A_NONE,A_ADDI,A_ANDI_,A_DIVWU,
  109. A_DIVW,A_MULLW, A_MULLW, A_NONE,A_NONE,A_ORI,
  110. A_SRAWI,A_SLWI,A_SRWI,A_SUBI,A_XORI);
  111. TOpCG2AsmOpConstHi: Array[topcg] of TAsmOp = (A_NONE,A_ADDIS,A_ANDIS_,
  112. A_DIVWU,A_DIVW, A_MULLW,A_MULLW,A_NONE,A_NONE,
  113. A_ORIS,A_NONE, A_NONE,A_NONE,A_SUBIS,A_XORIS);
  114. TOpCmp2AsmCond: Array[topcmp] of TAsmCondFlag = (C_NONE,C_EQ,C_GT,
  115. C_LT,C_GE,C_LE,C_NE,C_LE,C_LT,C_GE,C_GT);
  116. implementation
  117. uses
  118. globtype,globals,verbose,systems,cutils,symconst,symdef,symsym,rgobj,tgobj,cpupi;
  119. { parameter passing... Still needs extra support from the processor }
  120. { independent code generator }
  121. procedure tcgppc.a_param_const(list : taasmoutput;size : tcgsize;a : aword;const locpara : tparalocation);
  122. var
  123. ref: treference;
  124. begin
  125. case locpara.loc of
  126. LOC_REGISTER,LOC_CREGISTER:
  127. a_load_const_reg(list,size,a,locpara.register);
  128. LOC_REFERENCE:
  129. begin
  130. reference_reset(ref);
  131. ref.base:=locpara.reference.index;
  132. ref.offset:=locpara.reference.offset;
  133. a_load_const_ref(list,size,a,ref);
  134. end;
  135. else
  136. internalerror(2002081101);
  137. end;
  138. if locpara.sp_fixup<>0 then
  139. internalerror(2002081102);
  140. end;
  141. procedure tcgppc.a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;const locpara : tparalocation);
  142. var
  143. ref: treference;
  144. tmpreg: tregister;
  145. begin
  146. case locpara.loc of
  147. LOC_REGISTER,LOC_CREGISTER:
  148. a_load_ref_reg(list,size,size,r,locpara.register);
  149. LOC_REFERENCE:
  150. begin
  151. reference_reset(ref);
  152. ref.base:=locpara.reference.index;
  153. ref.offset:=locpara.reference.offset;
  154. {$ifndef newra}
  155. tmpreg := get_scratch_reg_int(list,size);
  156. {$else newra}
  157. tmpreg := rg.getregisterint(list,size);
  158. {$endif newra}
  159. a_load_ref_reg(list,size,size,r,tmpreg);
  160. a_load_reg_ref(list,size,size,tmpreg,ref);
  161. {$ifndef newra}
  162. free_scratch_reg(list,tmpreg);
  163. {$else newra}
  164. rg.ungetregisterint(list,tmpreg);
  165. {$endif newra}
  166. end;
  167. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  168. case size of
  169. OS_F32, OS_F64:
  170. a_loadfpu_ref_reg(list,size,r,locpara.register);
  171. else
  172. internalerror(2002072801);
  173. end;
  174. else
  175. internalerror(2002081103);
  176. end;
  177. if locpara.sp_fixup<>0 then
  178. internalerror(2002081104);
  179. end;
  180. procedure tcgppc.a_paramaddr_ref(list : taasmoutput;const r : treference;const locpara : tparalocation);
  181. var
  182. ref: treference;
  183. tmpreg: tregister;
  184. begin
  185. case locpara.loc of
  186. LOC_REGISTER,LOC_CREGISTER:
  187. a_loadaddr_ref_reg(list,r,locpara.register);
  188. LOC_REFERENCE:
  189. begin
  190. reference_reset(ref);
  191. ref.base := locpara.reference.index;
  192. ref.offset := locpara.reference.offset;
  193. {$ifndef newra}
  194. tmpreg := get_scratch_reg_address(list);
  195. {$else newra}
  196. tmpreg := rg.getregisterint(list,OS_ADDR);
  197. {$endif newra}
  198. a_loadaddr_ref_reg(list,r,tmpreg);
  199. a_load_reg_ref(list,OS_ADDR,OS_ADDR,tmpreg,ref);
  200. {$ifndef newra}
  201. free_scratch_reg(list,tmpreg);
  202. {$else newra}
  203. rg.ungetregisterint(list,tmpreg);
  204. {$endif newra}
  205. end;
  206. else
  207. internalerror(2002080701);
  208. end;
  209. end;
  210. { calling a procedure by name }
  211. procedure tcgppc.a_call_name(list : taasmoutput;const s : string);
  212. var
  213. href : treference;
  214. begin
  215. { MacOS: The linker on MacOS (PPCLink) inserts a call to glue code,
  216. if it is a cross-TOC call. If so, it also replaces the NOP
  217. with some restore code.}
  218. list.concat(taicpu.op_sym(A_BL,objectlibrary.newasmsymbol(s)));
  219. if target_info.system=system_powerpc_macos then
  220. list.concat(taicpu.op_none(A_NOP));
  221. if not(pi_do_call in current_procinfo.flags) then
  222. internalerror(2003060703);
  223. end;
  224. { calling a procedure by address }
  225. procedure tcgppc.a_call_reg(list : taasmoutput;reg: tregister);
  226. var
  227. tmpreg : tregister;
  228. tmpref : treference;
  229. begin
  230. if target_info.system=system_powerpc_macos then
  231. begin
  232. {Generate instruction to load the procedure address from
  233. the transition vector.}
  234. //TODO: Support cross-TOC calls.
  235. {$ifndef newra}
  236. tmpreg := get_scratch_reg_int(list,OS_INT);
  237. {$else newra}
  238. tmpreg := rg.getregisterint(list,OS_INT);
  239. {$endif newra}
  240. reference_reset(tmpref);
  241. tmpref.offset := 0;
  242. //tmpref.symaddr := refs_full;
  243. tmpref.base:= reg;
  244. list.concat(taicpu.op_reg_ref(A_LWZ,tmpreg,tmpref));
  245. list.concat(taicpu.op_reg(A_MTCTR,tmpreg));
  246. {$ifndef newra}
  247. free_scratch_reg(list,tmpreg);
  248. {$else newra}
  249. rg.ungetregisterint(list,tmpreg);
  250. {$endif newra}
  251. end
  252. else
  253. list.concat(taicpu.op_reg(A_MTCTR,reg));
  254. list.concat(taicpu.op_none(A_BCTRL));
  255. //if target_info.system=system_powerpc_macos then
  256. // //NOP is not needed here.
  257. // list.concat(taicpu.op_none(A_NOP));
  258. if not(pi_do_call in current_procinfo.flags) then
  259. internalerror(2003060704);
  260. //list.concat(tai_comment.create(strpnew('***** a_call_reg')));
  261. end;
  262. { calling a procedure by address }
  263. procedure tcgppc.a_call_ref(list : taasmoutput;const ref : treference);
  264. var
  265. tmpreg : tregister;
  266. tmpref : treference;
  267. begin
  268. {$ifndef newra}
  269. tmpreg := get_scratch_reg_int(list,OS_ADDR);
  270. {$else newra}
  271. tmpreg := rg.getregisterint(list,OS_ADDR);
  272. {$endif newra}
  273. a_load_ref_reg(list,OS_ADDR,OS_ADDR,ref,tmpreg);
  274. if target_info.system=system_powerpc_macos then
  275. begin
  276. {Generate instruction to load the procedure address from
  277. the transition vector.}
  278. //TODO: Support cross-TOC calls.
  279. reference_reset(tmpref);
  280. tmpref.offset := 0;
  281. //tmpref.symaddr := refs_full;
  282. tmpref.base:= tmpreg;
  283. list.concat(taicpu.op_reg_ref(A_LWZ,tmpreg,tmpref));
  284. end;
  285. list.concat(taicpu.op_reg(A_MTCTR,tmpreg));
  286. {$ifndef newra}
  287. free_scratch_reg(list,tmpreg);
  288. {$else newra}
  289. rg.ungetregisterint(list,tmpreg);
  290. {$endif newra}
  291. list.concat(taicpu.op_none(A_BCTRL));
  292. //if target_info.system=system_powerpc_macos then
  293. // //NOP is not needed here.
  294. // list.concat(taicpu.op_none(A_NOP));
  295. if not(pi_do_call in current_procinfo.flags) then
  296. internalerror(2003060705);
  297. //list.concat(tai_comment.create(strpnew('***** a_call_ref')));
  298. end;
  299. {********************** load instructions ********************}
  300. procedure tcgppc.a_load_const_reg(list : taasmoutput; size: TCGSize; a : aword; reg : TRegister);
  301. begin
  302. if not(size in [OS_8,OS_S8,OS_16,OS_S16,OS_32,OS_S32]) then
  303. internalerror(2002090902);
  304. if (longint(a) >= low(smallint)) and
  305. (longint(a) <= high(smallint)) then
  306. list.concat(taicpu.op_reg_const(A_LI,reg,smallint(a)))
  307. else if ((a and $ffff) <> 0) then
  308. begin
  309. list.concat(taicpu.op_reg_const(A_LI,reg,smallint(a and $ffff)));
  310. if ((a shr 16) <> 0) or
  311. (smallint(a and $ffff) < 0) then
  312. list.concat(taicpu.op_reg_reg_const(A_ADDIS,reg,reg,
  313. smallint((a shr 16)+ord(smallint(a and $ffff) < 0))))
  314. end
  315. else
  316. list.concat(taicpu.op_reg_const(A_LIS,reg,smallint(a shr 16)));
  317. end;
  318. procedure tcgppc.a_load_reg_ref(list : taasmoutput; fromsize, tosize: TCGSize; reg : tregister;const ref : treference);
  319. const
  320. StoreInstr: Array[OS_8..OS_32,boolean, boolean] of TAsmOp =
  321. { indexed? updating?}
  322. (((A_STB,A_STBU),(A_STBX,A_STBUX)),
  323. ((A_STH,A_STHU),(A_STHX,A_STHUX)),
  324. ((A_STW,A_STWU),(A_STWX,A_STWUX)));
  325. var
  326. op: TAsmOp;
  327. ref2: TReference;
  328. freereg: boolean;
  329. begin
  330. ref2 := ref;
  331. freereg := fixref(list,ref2);
  332. if tosize in [OS_S8..OS_S16] then
  333. { storing is the same for signed and unsigned values }
  334. tosize := tcgsize(ord(tosize)-(ord(OS_S8)-ord(OS_8)));
  335. { 64 bit stuff should be handled separately }
  336. if tosize in [OS_64,OS_S64] then
  337. internalerror(200109236);
  338. op := storeinstr[tcgsize2unsigned[tosize],ref2.index.number<>NR_NO,false];
  339. a_load_store(list,op,reg,ref2);
  340. if freereg then
  341. {$ifndef newra}
  342. cg.free_scratch_reg(list,ref2.base);
  343. {$else newra}
  344. rg.ungetregisterint(list,ref2.base);
  345. {$endif newra}
  346. End;
  347. procedure tcgppc.a_load_ref_reg(list : taasmoutput; fromsize,tosize : tcgsize;const ref: treference;reg : tregister);
  348. const
  349. LoadInstr: Array[OS_8..OS_S32,boolean, boolean] of TAsmOp =
  350. { indexed? updating?}
  351. (((A_LBZ,A_LBZU),(A_LBZX,A_LBZUX)),
  352. ((A_LHZ,A_LHZU),(A_LHZX,A_LHZUX)),
  353. ((A_LWZ,A_LWZU),(A_LWZX,A_LWZUX)),
  354. { 64bit stuff should be handled separately }
  355. ((A_NONE,A_NONE),(A_NONE,A_NONE)),
  356. { there's no load-byte-with-sign-extend :( }
  357. ((A_LBZ,A_LBZU),(A_LBZX,A_LBZUX)),
  358. ((A_LHA,A_LHAU),(A_LHAX,A_LHAUX)),
  359. ((A_LWZ,A_LWZU),(A_LWZX,A_LWZUX)));
  360. var
  361. op: tasmop;
  362. tmpreg: tregister;
  363. ref2, tmpref: treference;
  364. freereg: boolean;
  365. begin
  366. { TODO: optimize/take into consideration fromsize/tosize. Will }
  367. { probably only matter for OS_S8 loads though }
  368. if not(fromsize in [OS_8,OS_S8,OS_16,OS_S16,OS_32,OS_S32]) then
  369. internalerror(2002090902);
  370. ref2 := ref;
  371. freereg := fixref(list,ref2);
  372. op := loadinstr[fromsize,ref2.index.number<>NR_NO,false];
  373. a_load_store(list,op,reg,ref2);
  374. if freereg then
  375. {$ifndef newra}
  376. free_scratch_reg(list,ref2.base);
  377. {$else newra}
  378. rg.ungetregisterint(list,ref2.base);
  379. {$endif newra}
  380. { sign extend shortint if necessary, since there is no }
  381. { load instruction that does that automatically (JM) }
  382. if fromsize = OS_S8 then
  383. list.concat(taicpu.op_reg_reg(A_EXTSB,reg,reg));
  384. end;
  385. procedure tcgppc.a_load_reg_reg(list : taasmoutput;fromsize, tosize : tcgsize;reg1,reg2 : tregister);
  386. begin
  387. if (reg1.enum<>R_INTREGISTER) or (reg1.number = 0) then
  388. internalerror(200303101);
  389. if (reg2.enum<>R_INTREGISTER) or (reg2.number = 0) then
  390. internalerror(200303102);
  391. if (reg1.number<>reg2.number) or
  392. (tcgsize2size[tosize] < tcgsize2size[fromsize]) or
  393. ((tcgsize2size[tosize] = tcgsize2size[fromsize]) and
  394. (tosize <> fromsize) and
  395. not(fromsize in [OS_32,OS_S32])) then
  396. begin
  397. case tosize of
  398. OS_8:
  399. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,
  400. reg2,reg1,0,31-8+1,31));
  401. OS_S8:
  402. list.concat(taicpu.op_reg_reg(A_EXTSB,reg2,reg1));
  403. OS_16:
  404. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,
  405. reg2,reg1,0,31-16+1,31));
  406. OS_S16:
  407. list.concat(taicpu.op_reg_reg(A_EXTSH,reg2,reg1));
  408. OS_32,OS_S32:
  409. list.concat(taicpu.op_reg_reg(A_MR,reg2,reg1));
  410. else internalerror(2002090901);
  411. end;
  412. end;
  413. end;
  414. procedure tcgppc.a_loadfpu_reg_reg(list: taasmoutput; size: tcgsize; reg1, reg2: tregister);
  415. begin
  416. list.concat(taicpu.op_reg_reg(A_FMR,reg2,reg1));
  417. end;
  418. procedure tcgppc.a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister);
  419. const
  420. FpuLoadInstr: Array[OS_F32..OS_F64,boolean, boolean] of TAsmOp =
  421. { indexed? updating?}
  422. (((A_LFS,A_LFSU),(A_LFSX,A_LFSUX)),
  423. ((A_LFD,A_LFDU),(A_LFDX,A_LFDUX)));
  424. var
  425. op: tasmop;
  426. ref2: treference;
  427. freereg: boolean;
  428. begin
  429. { several functions call this procedure with OS_32 or OS_64 }
  430. { so this makes life easier (FK) }
  431. case size of
  432. OS_32,OS_F32:
  433. size:=OS_F32;
  434. OS_64,OS_F64,OS_C64:
  435. size:=OS_F64;
  436. else
  437. internalerror(200201121);
  438. end;
  439. ref2 := ref;
  440. freereg := fixref(list,ref2);
  441. op := fpuloadinstr[size,ref2.index.number <> NR_NO,false];
  442. a_load_store(list,op,reg,ref2);
  443. if freereg then
  444. {$ifndef newra}
  445. cg.free_scratch_reg(list,ref2.base);
  446. {$else newra}
  447. rg.ungetregisterint(list,ref2.base);
  448. {$endif newra}
  449. end;
  450. procedure tcgppc.a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference);
  451. const
  452. FpuStoreInstr: Array[OS_F32..OS_F64,boolean, boolean] of TAsmOp =
  453. { indexed? updating?}
  454. (((A_STFS,A_STFSU),(A_STFSX,A_STFSUX)),
  455. ((A_STFD,A_STFDU),(A_STFDX,A_STFDUX)));
  456. var
  457. op: tasmop;
  458. ref2: treference;
  459. freereg: boolean;
  460. begin
  461. if not(size in [OS_F32,OS_F64]) then
  462. internalerror(200201122);
  463. ref2 := ref;
  464. freereg := fixref(list,ref2);
  465. op := fpustoreinstr[size,ref2.index.number <> NR_NO,false];
  466. a_load_store(list,op,reg,ref2);
  467. if freereg then
  468. {$ifndef newra}
  469. cg.free_scratch_reg(list,ref2.base);
  470. {$else newra}
  471. rg.ungetregisterint(list,ref2.base);
  472. {$endif newra}
  473. end;
  474. procedure tcgppc.a_op_const_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; a: AWord; reg: TRegister);
  475. begin
  476. a_op_const_reg_reg(list,op,OS_32,a,reg,reg);
  477. end;
  478. procedure tcgppc.a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; src, dst: TRegister);
  479. begin
  480. a_op_reg_reg_reg(list,op,OS_32,src,dst,dst);
  481. end;
  482. procedure tcgppc.a_op_const_reg_reg(list: taasmoutput; op: TOpCg;
  483. size: tcgsize; a: aword; src, dst: tregister);
  484. var
  485. l1,l2: longint;
  486. oplo, ophi: tasmop;
  487. scratchreg: tregister;
  488. useReg, gotrlwi: boolean;
  489. procedure do_lo_hi;
  490. begin
  491. list.concat(taicpu.op_reg_reg_const(oplo,dst,src,word(a)));
  492. list.concat(taicpu.op_reg_reg_const(ophi,dst,dst,word(a shr 16)));
  493. end;
  494. begin
  495. if src.enum<>R_INTREGISTER then
  496. internalerror(200303102);
  497. if op = OP_SUB then
  498. begin
  499. {$ifopt q+}
  500. {$q-}
  501. {$define overflowon}
  502. {$endif}
  503. a_op_const_reg_reg(list,OP_ADD,size,aword(-longint(a)),src,dst);
  504. {$ifdef overflowon}
  505. {$q+}
  506. {$undef overflowon}
  507. {$endif}
  508. exit;
  509. end;
  510. ophi := TOpCG2AsmOpConstHi[op];
  511. oplo := TOpCG2AsmOpConstLo[op];
  512. gotrlwi := get_rlwi_const(a,l1,l2);
  513. if (op in [OP_AND,OP_OR,OP_XOR]) then
  514. begin
  515. if (a = 0) then
  516. begin
  517. if op = OP_AND then
  518. list.concat(taicpu.op_reg_const(A_LI,dst,0))
  519. else
  520. a_load_reg_reg(list,size,size,src,dst);
  521. exit;
  522. end
  523. else if (a = high(aword)) then
  524. begin
  525. case op of
  526. OP_OR:
  527. list.concat(taicpu.op_reg_const(A_LI,dst,-1));
  528. OP_XOR:
  529. list.concat(taicpu.op_reg_reg(A_NOT,dst,src));
  530. OP_AND:
  531. a_load_reg_reg(list,size,size,src,dst);
  532. end;
  533. exit;
  534. end
  535. else if (a <= high(word)) and
  536. ((op <> OP_AND) or
  537. not gotrlwi) then
  538. begin
  539. list.concat(taicpu.op_reg_reg_const(oplo,dst,src,word(a)));
  540. exit;
  541. end;
  542. { all basic constant instructions also have a shifted form that }
  543. { works only on the highest 16bits, so if lo(a) is 0, we can }
  544. { use that one }
  545. if (word(a) = 0) and
  546. (not(op = OP_AND) or
  547. not gotrlwi) then
  548. begin
  549. list.concat(taicpu.op_reg_reg_const(ophi,dst,src,word(a shr 16)));
  550. exit;
  551. end;
  552. end
  553. else if (op = OP_ADD) then
  554. if a = 0 then
  555. exit
  556. else if (longint(a) >= low(smallint)) and
  557. (longint(a) <= high(smallint)) then
  558. begin
  559. list.concat(taicpu.op_reg_reg_const(A_ADDI,dst,src,smallint(a)));
  560. exit;
  561. end;
  562. { otherwise, the instructions we can generate depend on the }
  563. { operation }
  564. useReg := false;
  565. case op of
  566. OP_DIV,OP_IDIV:
  567. if (a = 0) then
  568. internalerror(200208103)
  569. else if (a = 1) then
  570. begin
  571. a_load_reg_reg(list,OS_INT,OS_INT,src,dst);
  572. exit
  573. end
  574. else if ispowerof2(a,l1) then
  575. begin
  576. case op of
  577. OP_DIV:
  578. list.concat(taicpu.op_reg_reg_const(A_SRWI,dst,src,l1));
  579. OP_IDIV:
  580. begin
  581. list.concat(taicpu.op_reg_reg_const(A_SRAWI,dst,src,l1));
  582. list.concat(taicpu.op_reg_reg(A_ADDZE,dst,dst));
  583. end;
  584. end;
  585. exit;
  586. end
  587. else
  588. usereg := true;
  589. OP_IMUL, OP_MUL:
  590. if (a = 0) then
  591. begin
  592. list.concat(taicpu.op_reg_const(A_LI,dst,0));
  593. exit
  594. end
  595. else if (a = 1) then
  596. begin
  597. a_load_reg_reg(list,OS_INT,OS_INT,src,dst);
  598. exit
  599. end
  600. else if ispowerof2(a,l1) then
  601. list.concat(taicpu.op_reg_reg_const(A_SLWI,dst,src,l1))
  602. else if (longint(a) >= low(smallint)) and
  603. (longint(a) <= high(smallint)) then
  604. list.concat(taicpu.op_reg_reg_const(A_MULLI,dst,src,smallint(a)))
  605. else
  606. usereg := true;
  607. OP_ADD:
  608. begin
  609. list.concat(taicpu.op_reg_reg_const(oplo,dst,src,smallint(a)));
  610. list.concat(taicpu.op_reg_reg_const(ophi,dst,dst,
  611. smallint((a shr 16) + ord(smallint(a) < 0))));
  612. end;
  613. OP_OR:
  614. { try to use rlwimi }
  615. if gotrlwi and
  616. (src.number = dst.number) then
  617. begin
  618. {$ifndef newra}
  619. scratchreg := get_scratch_reg_int(list,OS_INT);
  620. {$else newra}
  621. scratchreg := rg.getregisterint(list,OS_INT);
  622. {$endif newra}
  623. list.concat(taicpu.op_reg_const(A_LI,scratchreg,-1));
  624. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWIMI,dst,
  625. scratchreg,0,l1,l2));
  626. {$ifndef newra}
  627. free_scratch_reg(list,scratchreg);
  628. {$else newra}
  629. rg.ungetregisterint(list,scratchreg);
  630. {$endif newra}
  631. end
  632. else
  633. do_lo_hi;
  634. OP_AND:
  635. { try to use rlwinm }
  636. if gotrlwi then
  637. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,dst,
  638. src,0,l1,l2))
  639. else
  640. useReg := true;
  641. OP_XOR:
  642. do_lo_hi;
  643. OP_SHL,OP_SHR,OP_SAR:
  644. begin
  645. if (a and 31) <> 0 Then
  646. list.concat(taicpu.op_reg_reg_const(
  647. TOpCG2AsmOpConstLo[Op],dst,src,a and 31))
  648. else
  649. a_load_reg_reg(list,size,size,src,dst);
  650. if (a shr 5) <> 0 then
  651. internalError(68991);
  652. end
  653. else
  654. internalerror(200109091);
  655. end;
  656. { if all else failed, load the constant in a register and then }
  657. { perform the operation }
  658. if useReg then
  659. begin
  660. {$ifndef newra}
  661. scratchreg := get_scratch_reg_int(list,OS_INT);
  662. {$else newra}
  663. scratchreg := rg.getregisterint(list,OS_INT);
  664. {$endif newra}
  665. a_load_const_reg(list,OS_32,a,scratchreg);
  666. a_op_reg_reg_reg(list,op,OS_32,scratchreg,src,dst);
  667. {$ifndef newra}
  668. free_scratch_reg(list,scratchreg);
  669. {$else newra}
  670. rg.ungetregisterint(list,scratchreg);
  671. {$endif newra}
  672. end;
  673. end;
  674. procedure tcgppc.a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;
  675. size: tcgsize; src1, src2, dst: tregister);
  676. const
  677. op_reg_reg_opcg2asmop: array[TOpCG] of tasmop =
  678. (A_NONE,A_ADD,A_AND,A_DIVWU,A_DIVW,A_MULLW,A_MULLW,A_NEG,A_NOT,A_OR,
  679. A_SRAW,A_SLW,A_SRW,A_SUB,A_XOR);
  680. begin
  681. case op of
  682. OP_NEG,OP_NOT:
  683. list.concat(taicpu.op_reg_reg(op_reg_reg_opcg2asmop[op],dst,dst));
  684. else
  685. list.concat(taicpu.op_reg_reg_reg(op_reg_reg_opcg2asmop[op],dst,src2,src1));
  686. end;
  687. end;
  688. {*************** compare instructructions ****************}
  689. procedure tcgppc.a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;reg : tregister;
  690. l : tasmlabel);
  691. var
  692. p: taicpu;
  693. scratch_register: TRegister;
  694. signed: boolean;
  695. r:Tregister;
  696. begin
  697. signed := cmp_op in [OC_GT,OC_LT,OC_GTE,OC_LTE];
  698. { in the following case, we generate more efficient code when }
  699. { signed is true }
  700. if (cmp_op in [OC_EQ,OC_NE]) and
  701. (a > $ffff) then
  702. signed := true;
  703. r.enum:=R_CR0;
  704. if signed then
  705. if (longint(a) >= low(smallint)) and (longint(a) <= high(smallint)) Then
  706. list.concat(taicpu.op_reg_reg_const(A_CMPWI,r,reg,longint(a)))
  707. else
  708. begin
  709. {$ifndef newra}
  710. scratch_register := get_scratch_reg_int(list,OS_INT);
  711. {$else newra}
  712. scratch_register := rg.getregisterint(list,OS_INT);
  713. {$endif newra}
  714. a_load_const_reg(list,OS_32,a,scratch_register);
  715. list.concat(taicpu.op_reg_reg_reg(A_CMPW,r,reg,scratch_register));
  716. {$ifndef newra}
  717. free_scratch_reg(list,scratch_register);
  718. {$else newra}
  719. rg.ungetregisterint(list,scratch_register);
  720. {$endif newra}
  721. end
  722. else
  723. if (a <= $ffff) then
  724. list.concat(taicpu.op_reg_reg_const(A_CMPLWI,r,reg,a))
  725. else
  726. begin
  727. {$ifndef newra}
  728. scratch_register := get_scratch_reg_int(list,OS_32);
  729. {$else newra}
  730. scratch_register := rg.getregisterint(list,OS_INT);
  731. {$endif newra}
  732. a_load_const_reg(list,OS_32,a,scratch_register);
  733. list.concat(taicpu.op_reg_reg_reg(A_CMPLW,r,reg,scratch_register));
  734. {$ifndef newra}
  735. free_scratch_reg(list,scratch_register);
  736. {$else newra}
  737. rg.ungetregisterint(list,scratch_register);
  738. {$endif newra}
  739. end;
  740. a_jmp(list,A_BC,TOpCmp2AsmCond[cmp_op],0,l);
  741. end;
  742. procedure tcgppc.a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;
  743. reg1,reg2 : tregister;l : tasmlabel);
  744. var
  745. p: taicpu;
  746. op: tasmop;
  747. r:Tregister;
  748. begin
  749. if cmp_op in [OC_GT,OC_LT,OC_GTE,OC_LTE] then
  750. op := A_CMPW
  751. else op := A_CMPLW;
  752. r.enum:=R_CR0;
  753. list.concat(taicpu.op_reg_reg_reg(op,r,reg2,reg1));
  754. a_jmp(list,A_BC,TOpCmp2AsmCond[cmp_op],0,l);
  755. end;
  756. procedure tcgppc.g_save_standard_registers(list : taasmoutput; usedinproc : Tsupregset);
  757. begin
  758. {$warning FIX ME}
  759. end;
  760. procedure tcgppc.g_restore_standard_registers(list : taasmoutput; usedinproc : Tsupregset);
  761. begin
  762. {$warning FIX ME}
  763. end;
  764. procedure tcgppc.g_save_all_registers(list : taasmoutput);
  765. begin
  766. {$warning FIX ME}
  767. end;
  768. procedure tcgppc.g_restore_all_registers(list : taasmoutput;accused,acchiused:boolean);
  769. begin
  770. {$warning FIX ME}
  771. end;
  772. procedure tcgppc.a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel);
  773. begin
  774. a_jmp(list,A_BC,TOpCmp2AsmCond[cond],0,l);
  775. end;
  776. procedure tcgppc.a_jmp_always(list : taasmoutput;l: tasmlabel);
  777. begin
  778. a_jmp(list,A_B,C_None,0,l);
  779. end;
  780. procedure tcgppc.a_jmp_flags(list : taasmoutput;const f : TResFlags;l: tasmlabel);
  781. var
  782. c: tasmcond;
  783. r:Tregister;
  784. begin
  785. c := flags_to_cond(f);
  786. r.enum:=R_CR0;
  787. a_jmp(list,A_BC,c.cond,ord(c.cr)-ord(r.enum),l);
  788. end;
  789. procedure tcgppc.g_flags2reg(list: taasmoutput; size: TCgSize; const f: TResFlags; reg: TRegister);
  790. var
  791. testbit: byte;
  792. bitvalue: boolean;
  793. begin
  794. { get the bit to extract from the conditional register + its }
  795. { requested value (0 or 1) }
  796. testbit := ((ord(f.cr)-ord(R_CR0)) * 4);
  797. case f.flag of
  798. F_EQ,F_NE:
  799. begin
  800. inc(testbit,2);
  801. bitvalue := f.flag = F_EQ;
  802. end;
  803. F_LT,F_GE:
  804. begin
  805. bitvalue := f.flag = F_LT;
  806. end;
  807. F_GT,F_LE:
  808. begin
  809. inc(testbit);
  810. bitvalue := f.flag = F_GT;
  811. end;
  812. else
  813. internalerror(200112261);
  814. end;
  815. { load the conditional register in the destination reg }
  816. list.concat(taicpu.op_reg(A_MFCR,reg));
  817. { we will move the bit that has to be tested to bit 0 by rotating }
  818. { left }
  819. testbit := (testbit + 1) and 31;
  820. { extract bit }
  821. list.concat(taicpu.op_reg_reg_const_const_const(
  822. A_RLWINM,reg,reg,testbit,31,31));
  823. { if we need the inverse, xor with 1 }
  824. if not bitvalue then
  825. list.concat(taicpu.op_reg_reg_const(A_XORI,reg,reg,1));
  826. end;
  827. (*
  828. procedure tcgppc.g_cond2reg(list: taasmoutput; const f: TAsmCond; reg: TRegister);
  829. var
  830. testbit: byte;
  831. bitvalue: boolean;
  832. begin
  833. { get the bit to extract from the conditional register + its }
  834. { requested value (0 or 1) }
  835. case f.simple of
  836. false:
  837. begin
  838. { we don't generate this in the compiler }
  839. internalerror(200109062);
  840. end;
  841. true:
  842. case f.cond of
  843. C_None:
  844. internalerror(200109063);
  845. C_LT..C_NU:
  846. begin
  847. testbit := (ord(f.cr) - ord(R_CR0))*4;
  848. inc(testbit,AsmCondFlag2BI[f.cond]);
  849. bitvalue := AsmCondFlagTF[f.cond];
  850. end;
  851. C_T,C_F,C_DNZT,C_DNZF,C_DZT,C_DZF:
  852. begin
  853. testbit := f.crbit
  854. bitvalue := AsmCondFlagTF[f.cond];
  855. end;
  856. else
  857. internalerror(200109064);
  858. end;
  859. end;
  860. { load the conditional register in the destination reg }
  861. list.concat(taicpu.op_reg_reg(A_MFCR,reg));
  862. { we will move the bit that has to be tested to bit 31 -> rotate }
  863. { left by bitpos+1 (remember, this is big-endian!) }
  864. if bitpos <> 31 then
  865. inc(bitpos)
  866. else
  867. bitpos := 0;
  868. { extract bit }
  869. list.concat(taicpu.op_reg_reg_const_const_const(
  870. A_RLWINM,reg,reg,bitpos,31,31));
  871. { if we need the inverse, xor with 1 }
  872. if not bitvalue then
  873. list.concat(taicpu.op_reg_reg_const(A_XORI,reg,reg,1));
  874. end;
  875. *)
  876. { *********** entry/exit code and address loading ************ }
  877. procedure tcgppc.g_stackframe_entry(list : taasmoutput;localsize : longint);
  878. begin
  879. case target_info.abi of
  880. abi_powerpc_macos:
  881. g_stackframe_entry_mac(list,localsize);
  882. abi_powerpc_sysv:
  883. g_stackframe_entry_sysv(list,localsize);
  884. abi_powerpc_aix:
  885. g_stackframe_entry_aix(list,localsize);
  886. else
  887. internalerror(2204001);
  888. end;
  889. end;
  890. procedure tcgppc.g_return_from_proc(list : taasmoutput;parasize : aword);
  891. begin
  892. case target_info.abi of
  893. abi_powerpc_macos:
  894. g_return_from_proc_mac(list,parasize);
  895. abi_powerpc_sysv:
  896. g_return_from_proc_sysv(list,parasize);
  897. abi_powerpc_aix:
  898. g_return_from_proc_aix(list,parasize);
  899. else
  900. internalerror(2204001);
  901. end;
  902. end;
  903. procedure tcgppc.g_stackframe_entry_aix(list : taasmoutput;localsize : longint);
  904. begin
  905. g_stackframe_entry_sysv(list,localsize);
  906. end;
  907. procedure tcgppc.g_stackframe_entry_sysv(list : taasmoutput;localsize : longint);
  908. { generated the entry code of a procedure/function. Note: localsize is the }
  909. { sum of the size necessary for local variables and the maximum possible }
  910. { combined size of ALL the parameters of a procedure called by the current }
  911. { one }
  912. var regcounter,firstregfpu,firstreggpr: TRegister;
  913. href,href2 : treference;
  914. usesfpr,usesgpr,gotgot : boolean;
  915. parastart : aword;
  916. offset : aword;
  917. r,r2,rsp:Tregister;
  918. regcounter2: Tsuperregister;
  919. hp: tparaitem;
  920. begin
  921. { we do our own localsize calculation }
  922. localsize:=0;
  923. { CR and LR only have to be saved in case they are modified by the current }
  924. { procedure, but currently this isn't checked, so save them always }
  925. { following is the entry code as described in "Altivec Programming }
  926. { Interface Manual", bar the saving of AltiVec registers }
  927. rsp.enum:=R_INTREGISTER;
  928. rsp.number:=NR_STACK_POINTER_REG;
  929. a_reg_alloc(list,rsp);
  930. r.enum:=R_INTREGISTER;
  931. r.number:=NR_R0;
  932. a_reg_alloc(list,r);
  933. if current_procinfo.procdef.parast.symtablelevel>1 then
  934. begin
  935. r.enum:=R_INTREGISTER;
  936. r.number:=NR_R11;
  937. a_reg_alloc(list,r);
  938. end;
  939. usesfpr:=false;
  940. if not (po_assembler in current_procinfo.procdef.procoptions) then
  941. for regcounter.enum:=R_F14 to R_F31 do
  942. if regcounter.enum in rg.used_in_proc_other then
  943. begin
  944. usesfpr:= true;
  945. firstregfpu:=regcounter;
  946. break;
  947. end;
  948. usesgpr:=false;
  949. if not (po_assembler in current_procinfo.procdef.procoptions) then
  950. for regcounter2:=firstsaveintreg to RS_R31 do
  951. begin
  952. if regcounter2 in rg.used_in_proc_int then
  953. begin
  954. usesgpr:=true;
  955. firstreggpr.enum := R_INTREGISTER;
  956. firstreggpr.number := regcounter2 shl 8;
  957. break;
  958. end;
  959. end;
  960. { save link register? }
  961. if not (po_assembler in current_procinfo.procdef.procoptions) then
  962. if (pi_do_call in current_procinfo.flags) then
  963. begin
  964. { save return address... }
  965. r.enum:=R_INTREGISTER;
  966. r.number:=NR_R0;
  967. list.concat(taicpu.op_reg(A_MFLR,r));
  968. { ... in caller's rframe }
  969. reference_reset_base(href,rsp,4);
  970. list.concat(taicpu.op_reg_ref(A_STW,r,href));
  971. a_reg_dealloc(list,r);
  972. end;
  973. { !!! always allocate space for all registers for now !!! }
  974. if not (po_assembler in current_procinfo.procdef.procoptions) then
  975. { if usesfpr or usesgpr then }
  976. begin
  977. r.enum:=R_INTREGISTER;
  978. r.number:=NR_R12;
  979. a_reg_alloc(list,r);
  980. { save end of fpr save area }
  981. list.concat(taicpu.op_reg_reg(A_MR,r,rsp));
  982. end;
  983. { calculate the size of the locals }
  984. {
  985. if usesgpr then
  986. inc(localsize,((NR_R31-firstreggpr.number) shr 8+1)*4);
  987. if usesfpr then
  988. inc(localsize,(ord(R_F31)-ord(firstregfpu.enum)+1)*8);
  989. }
  990. { !!! always allocate space for all registers for now !!! }
  991. if not (po_assembler in current_procinfo.procdef.procoptions) then
  992. inc(localsize,(31-13+1)*4+(31-14+1)*8);
  993. { align to 16 bytes }
  994. localsize:=align(localsize,16);
  995. inc(localsize,tg.lasttemp);
  996. localsize:=align(localsize,16);
  997. tppcprocinfo(current_procinfo).localsize:=localsize;
  998. if (localsize <> 0) then
  999. begin
  1000. r.enum:=R_INTREGISTER;
  1001. r.number:=NR_STACK_POINTER_REG;
  1002. if (localsize <= high(smallint)) then
  1003. begin
  1004. reference_reset_base(href,r,-localsize);
  1005. a_load_store(list,A_STWU,r,href);
  1006. end
  1007. else
  1008. begin
  1009. reference_reset_base(href,r,0);
  1010. {$ifndef newra}
  1011. href.index := get_scratch_reg_int(list,OS_32);
  1012. {$else newra}
  1013. href.index := rg.getregisterint(list,OS_32);
  1014. {$endif newra}
  1015. a_load_const_reg(list,OS_S32,-localsize,href.index);
  1016. a_load_store(list,A_STWUX,r,href);
  1017. {$ifndef newra}
  1018. free_scratch_reg(list,href.index);
  1019. {$else newra}
  1020. rg.ungetregisterint(list,href.index);
  1021. {$endif newra}
  1022. end;
  1023. end;
  1024. { no GOT pointer loaded yet }
  1025. gotgot:=false;
  1026. r.enum := R_INTREGISTER;
  1027. r.NUMBER := NR_R12;
  1028. if usesfpr then
  1029. begin
  1030. { save floating-point registers
  1031. if (cs_create_pic in aktmoduleswitches) and not(usesgpr) then
  1032. begin
  1033. a_call_name(objectlibrary.newasmsymbol('_savefpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14)+'_g');
  1034. gotgot:=true;
  1035. end
  1036. else
  1037. a_call_name(objectlibrary.newasmsymbol('_savefpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14));
  1038. }
  1039. reference_reset_base(href,r,-8);
  1040. for regcounter.enum:=firstregfpu.enum to R_F31 do
  1041. if regcounter.enum in rg.used_in_proc_other then
  1042. begin
  1043. a_loadfpu_reg_ref(list,OS_F64,regcounter,href);
  1044. dec(href.offset,8);
  1045. end;
  1046. { compute end of gpr save area }
  1047. a_op_const_reg(list,OP_ADD,OS_ADDR,aword(href.offset+8),r);
  1048. end;
  1049. { save gprs and fetch GOT pointer }
  1050. if usesgpr then
  1051. begin
  1052. {
  1053. if cs_create_pic in aktmoduleswitches then
  1054. begin
  1055. a_call_name(objectlibrary.newasmsymbol('_savegpr_'+tostr(ord(firstreggpr)-ord(R_14)+14)+'_g');
  1056. gotgot:=true;
  1057. end
  1058. else
  1059. a_call_name(objectlibrary.newasmsymbol('_savegpr_'+tostr(ord(firstreggpr)-ord(R_14)+14))
  1060. }
  1061. reference_reset_base(href,r,-4);
  1062. for regcounter2:=firstsaveintreg to RS_R31 do
  1063. begin
  1064. if regcounter2 in rg.used_in_proc_int then
  1065. begin
  1066. usesgpr:=true;
  1067. r.enum := R_INTREGISTER;
  1068. r.number := regcounter2 shl 8;
  1069. a_load_reg_ref(list,OS_INT,OS_INT,r,href);
  1070. dec(href.offset,4);
  1071. end;
  1072. end;
  1073. {
  1074. r.enum:=R_INTREGISTER;
  1075. r.number:=NR_R12;
  1076. reference_reset_base(href,r,-((NR_R31-firstreggpr.number) shr 8+1)*4);
  1077. list.concat(taicpu.op_reg_ref(A_STMW,firstreggpr,href));
  1078. }
  1079. end;
  1080. if assigned(current_procinfo.procdef.parast) then
  1081. begin
  1082. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1083. begin
  1084. { copy memory parameters to local parast }
  1085. r.enum:=R_INTREGISTER;
  1086. r.number:=NR_R12;
  1087. hp:=tparaitem(current_procinfo.procdef.para.first);
  1088. while assigned(hp) do
  1089. begin
  1090. if (hp.calleeparaloc.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  1091. begin
  1092. reference_reset_base(href,current_procinfo.framepointer,tvarsym(hp.parasym).adjusted_address);
  1093. reference_reset_base(href2,r,hp.callerparaloc.reference.offset);
  1094. cg.a_load_ref_ref(list,hp.calleeparaloc.size,hp.calleeparaloc.size,href2,href);
  1095. end;
  1096. hp := tparaitem(hp.next);
  1097. end;
  1098. end;
  1099. end;
  1100. r.enum:=R_INTREGISTER;
  1101. r.number:=NR_R12;
  1102. if usesfpr or usesgpr then
  1103. a_reg_dealloc(list,r);
  1104. { PIC code support, }
  1105. if cs_create_pic in aktmoduleswitches then
  1106. begin
  1107. { if we didn't get the GOT pointer till now, we've to calculate it now }
  1108. if not(gotgot) then
  1109. begin
  1110. {!!!!!!!!!!!!!}
  1111. end;
  1112. r.enum:=R_INTREGISTER;
  1113. r.number:=NR_R31;
  1114. r2.enum:=R_LR;
  1115. a_reg_alloc(list,r);
  1116. { place GOT ptr in r31 }
  1117. list.concat(taicpu.op_reg_reg(A_MFSPR,r,r2));
  1118. end;
  1119. { save the CR if necessary ( !!! always done currently ) }
  1120. { still need to find out where this has to be done for SystemV
  1121. a_reg_alloc(list,R_0);
  1122. list.concat(taicpu.op_reg_reg(A_MFSPR,R_0,R_CR);
  1123. list.concat(taicpu.op_reg_ref(A_STW,scratch_register,
  1124. new_reference(STACK_POINTER_REG,LA_CR)));
  1125. a_reg_dealloc(list,R_0); }
  1126. { now comes the AltiVec context save, not yet implemented !!! }
  1127. { if we're in a nested procedure, we've to save R11 }
  1128. if current_procinfo.procdef.parast.symtablelevel>2 then
  1129. begin
  1130. r.enum:=R_INTREGISTER;
  1131. r.number:=NR_R11;
  1132. reference_reset_base(href,rsp,current_procinfo.framepointer_offset);
  1133. list.concat(taicpu.op_reg_ref(A_STW,r,href));
  1134. end;
  1135. end;
  1136. procedure tcgppc.g_return_from_proc_aix(list : taasmoutput;parasize : aword);
  1137. begin
  1138. g_return_from_proc_sysv(list,parasize);
  1139. end;
  1140. procedure tcgppc.g_return_from_proc_sysv(list : taasmoutput;parasize : aword);
  1141. var
  1142. regcounter,firstregfpu,firstreggpr: TRegister;
  1143. href : treference;
  1144. usesfpr,usesgpr,genret : boolean;
  1145. r,r2:Tregister;
  1146. regcounter2:Tsuperregister;
  1147. localsize: aword;
  1148. begin
  1149. localsize := 0;
  1150. { AltiVec context restore, not yet implemented !!! }
  1151. usesfpr:=false;
  1152. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1153. for regcounter.enum:=R_F14 to R_F31 do
  1154. if regcounter.enum in rg.used_in_proc_other then
  1155. begin
  1156. usesfpr:=true;
  1157. firstregfpu:=regcounter;
  1158. break;
  1159. end;
  1160. usesgpr:=false;
  1161. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1162. for regcounter2:=firstsaveintreg to RS_R31 do
  1163. begin
  1164. if regcounter2 in rg.used_in_proc_int then
  1165. begin
  1166. usesgpr:=true;
  1167. firstreggpr.enum:=R_INTREGISTER;
  1168. firstreggpr.number:=regcounter2 shl 8;
  1169. break;
  1170. end;
  1171. end;
  1172. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1173. inc(localsize,(31-13+1)*4+(31-14+1)*8);
  1174. { align to 16 bytes }
  1175. localsize:=align(localsize,16);
  1176. inc(localsize,tg.lasttemp);
  1177. localsize:=align(localsize,16);
  1178. tppcprocinfo(current_procinfo).localsize:=localsize;
  1179. { no return (blr) generated yet }
  1180. genret:=true;
  1181. if usesgpr or usesfpr then
  1182. begin
  1183. { address of gpr save area to r11 }
  1184. r.enum:=R_INTREGISTER;
  1185. r.number:=NR_STACK_POINTER_REG;
  1186. r2.enum:=R_INTREGISTER;
  1187. r2.number:=NR_R12;
  1188. a_op_const_reg_reg(list,OP_ADD,OS_ADDR,tppcprocinfo(current_procinfo).localsize,r,r2);
  1189. if usesfpr then
  1190. begin
  1191. reference_reset_base(href,r2,-8);
  1192. for regcounter.enum := firstregfpu.enum to R_F31 do
  1193. if (regcounter.enum in rg.used_in_proc_other) then
  1194. begin
  1195. a_loadfpu_ref_reg(list,OS_F64,href,regcounter);
  1196. dec(href.offset,8);
  1197. end;
  1198. inc(href.offset,4);
  1199. end
  1200. else
  1201. reference_reset_base(href,r2,-4);
  1202. for regcounter2:=firstsaveintreg to RS_R31 do
  1203. begin
  1204. if regcounter2 in rg.used_in_proc_int then
  1205. begin
  1206. usesgpr:=true;
  1207. r.enum := R_INTREGISTER;
  1208. r.number := regcounter2 shl 8;
  1209. a_load_ref_reg(list,OS_INT,OS_INT,href,r);
  1210. dec(href.offset,4);
  1211. end;
  1212. end;
  1213. (*
  1214. reference_reset_base(href,r2,-((NR_R31-ord(firstreggpr.number)) shr 8+1)*4);
  1215. list.concat(taicpu.op_reg_ref(A_LMW,firstreggpr,href));
  1216. *)
  1217. end;
  1218. (*
  1219. { restore fprs and return }
  1220. if usesfpr then
  1221. begin
  1222. { address of fpr save area to r11 }
  1223. r.enum:=R_INTREGISTER;
  1224. r.number:=NR_R12;
  1225. list.concat(taicpu.op_reg_reg_const(A_ADDI,r,r,(ord(R_F31)-ord(firstregfpu.enum)+1)*8));
  1226. {
  1227. if (pi_do_call in current_procinfo.flags) then
  1228. a_call_name(objectlibrary.newasmsymbol('_restfpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14)+
  1229. '_x')
  1230. else
  1231. { leaf node => lr haven't to be restored }
  1232. a_call_name('_restfpr_'+tostr(ord(firstregfpu.enum)-ord(R_F14)+14)+
  1233. '_l');
  1234. genret:=false;
  1235. }
  1236. end;
  1237. *)
  1238. { if we didn't generate the return code, we've to do it now }
  1239. if genret then
  1240. begin
  1241. { adjust r1 }
  1242. r.enum:=R_INTREGISTER;
  1243. r.number:=NR_R1;
  1244. a_op_const_reg(list,OP_ADD,OS_ADDR,tppcprocinfo(current_procinfo).localsize,r);
  1245. { load link register? }
  1246. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1247. if (pi_do_call in current_procinfo.flags) then
  1248. begin
  1249. r.enum:=R_INTREGISTER;
  1250. r.number:=NR_STACK_POINTER_REG;
  1251. reference_reset_base(href,r,4);
  1252. r.enum:=R_INTREGISTER;
  1253. r.number:=NR_R0;
  1254. list.concat(taicpu.op_reg_ref(A_LWZ,r,href));
  1255. list.concat(taicpu.op_reg(A_MTLR,r));
  1256. end;
  1257. list.concat(taicpu.op_none(A_BLR));
  1258. end;
  1259. end;
  1260. function save_regs(list : taasmoutput):longint;
  1261. {Generates code which saves used non-volatile registers in
  1262. the save area right below the address the stackpointer point to.
  1263. Returns the actual used save area size.}
  1264. var regcounter,firstregfpu,firstreggpr: TRegister;
  1265. usesfpr,usesgpr: boolean;
  1266. href : treference;
  1267. offset: integer;
  1268. r,r2:Tregister;
  1269. regcounter2: Tsuperregister;
  1270. begin
  1271. usesfpr:=false;
  1272. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1273. for regcounter.enum:=R_F14 to R_F31 do
  1274. if regcounter.enum in rg.used_in_proc_other then
  1275. begin
  1276. usesfpr:=true;
  1277. firstregfpu:=regcounter;
  1278. break;
  1279. end;
  1280. usesgpr:=false;
  1281. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1282. for regcounter2:=firstsaveintreg to RS_R31 do
  1283. begin
  1284. if regcounter2 in rg.used_in_proc_int then
  1285. begin
  1286. usesgpr:=true;
  1287. firstreggpr.enum:=R_INTREGISTER;
  1288. firstreggpr.number:=regcounter2 shl 8;
  1289. break;
  1290. end;
  1291. end;
  1292. offset:= 0;
  1293. { save floating-point registers }
  1294. if usesfpr then
  1295. for regcounter.enum := firstregfpu.enum to R_F31 do
  1296. begin
  1297. offset:= offset - 8;
  1298. r.enum:=R_INTREGISTER;
  1299. r.number:=NR_STACK_POINTER_REG;
  1300. reference_reset_base(href, r, offset);
  1301. list.concat(taicpu.op_reg_ref(A_STFD, regcounter, href));
  1302. end;
  1303. (* Optimiztion in the future: a_call_name(list,'_savefXX'); *)
  1304. { save gprs in gpr save area }
  1305. if usesgpr then
  1306. if firstreggpr.enum < R_30 then
  1307. begin
  1308. offset:= offset - 4 * (ord(R_31) - ord(firstreggpr.enum) + 1);
  1309. r.enum:=R_INTREGISTER;
  1310. r.number:=NR_STACK_POINTER_REG;
  1311. reference_reset_base(href,r,offset);
  1312. list.concat(taicpu.op_reg_ref(A_STMW,firstreggpr,href));
  1313. {STMW stores multiple registers}
  1314. end
  1315. else
  1316. begin
  1317. r.enum:=R_INTREGISTER;
  1318. r.number:=NR_STACK_POINTER_REG;
  1319. r2 := firstreggpr;
  1320. convert_register_to_enum(firstreggpr);
  1321. for regcounter.enum := firstreggpr.enum to R_31 do
  1322. begin
  1323. offset:= offset - 4;
  1324. reference_reset_base(href, r, offset);
  1325. list.concat(taicpu.op_reg_ref(A_STW, r2, href));
  1326. inc(r2.number,NR_R1-NR_R0);
  1327. end;
  1328. end;
  1329. { now comes the AltiVec context save, not yet implemented !!! }
  1330. save_regs:= -offset;
  1331. end;
  1332. procedure restore_regs(list : taasmoutput);
  1333. {Generates code which restores used non-volatile registers from
  1334. the save area right below the address the stackpointer point to.}
  1335. var regcounter,firstregfpu,firstreggpr: TRegister;
  1336. usesfpr,usesgpr: boolean;
  1337. href : treference;
  1338. offset: integer;
  1339. r,r2:Tregister;
  1340. regcounter2: Tsuperregister;
  1341. begin
  1342. usesfpr:=false;
  1343. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1344. for regcounter.enum:=R_F14 to R_F31 do
  1345. if regcounter.enum in rg.used_in_proc_other then
  1346. begin
  1347. usesfpr:=true;
  1348. firstregfpu:=regcounter;
  1349. break;
  1350. end;
  1351. usesgpr:=false;
  1352. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1353. for regcounter2:=RS_R13 to RS_R31 do
  1354. begin
  1355. if regcounter2 in rg.used_in_proc_int then
  1356. begin
  1357. usesgpr:=true;
  1358. firstreggpr.enum:=R_INTREGISTER;
  1359. firstreggpr.number:=regcounter2 shl 8;
  1360. break;
  1361. end;
  1362. end;
  1363. offset:= 0;
  1364. { restore fp registers }
  1365. if usesfpr then
  1366. for regcounter.enum := firstregfpu.enum to R_F31 do
  1367. begin
  1368. offset:= offset - 8;
  1369. r.enum:=R_INTREGISTER;
  1370. r.number:=NR_STACK_POINTER_REG;
  1371. reference_reset_base(href, r, offset);
  1372. list.concat(taicpu.op_reg_ref(A_LFD, regcounter, href));
  1373. end;
  1374. (* Optimiztion in the future: a_call_name(list,'_restfXX'); *)
  1375. { restore gprs }
  1376. if usesgpr then
  1377. if firstreggpr.enum < R_30 then
  1378. begin
  1379. offset:= offset - 4 * (ord(R_31) - ord(firstreggpr.enum) + 1);
  1380. r.enum:=R_INTREGISTER;
  1381. r.number:=NR_STACK_POINTER_REG;
  1382. reference_reset_base(href,r,offset); //-220
  1383. list.concat(taicpu.op_reg_ref(A_LMW,firstreggpr,href));
  1384. {LMW loads multiple registers}
  1385. end
  1386. else
  1387. begin
  1388. r.enum:=R_INTREGISTER;
  1389. r.number:=NR_STACK_POINTER_REG;
  1390. r2 := firstreggpr;
  1391. convert_register_to_enum(firstreggpr);
  1392. for regcounter.enum := firstreggpr.enum to R_31 do
  1393. begin
  1394. offset:= offset - 4;
  1395. reference_reset_base(href, r, offset);
  1396. list.concat(taicpu.op_reg_ref(A_LWZ, r2, href));
  1397. inc(r2.number,NR_R1-NR_R0);
  1398. end;
  1399. end;
  1400. { now comes the AltiVec context restore, not yet implemented !!! }
  1401. end;
  1402. procedure tcgppc.g_stackframe_entry_mac(list : taasmoutput;localsize : longint);
  1403. { generated the entry code of a procedure/function. Note: localsize is the }
  1404. { sum of the size necessary for local variables and the maximum possible }
  1405. { combined size of ALL the parameters of a procedure called by the current }
  1406. { one }
  1407. const
  1408. macosLinkageAreaSize = 24;
  1409. var regcounter: TRegister;
  1410. href : treference;
  1411. registerSaveAreaSize : longint;
  1412. r,r2,rsp:Tregister;
  1413. regcounter2: Tsuperregister;
  1414. begin
  1415. if (localsize mod 8) <> 0 then internalerror(58991);
  1416. { CR and LR only have to be saved in case they are modified by the current }
  1417. { procedure, but currently this isn't checked, so save them always }
  1418. { following is the entry code as described in "Altivec Programming }
  1419. { Interface Manual", bar the saving of AltiVec registers }
  1420. r.enum:=R_INTREGISTER;
  1421. r.number:=NR_R0;
  1422. rsp.enum:=R_INTREGISTER;
  1423. rsp.number:=NR_STACK_POINTER_REG;
  1424. a_reg_alloc(list,rsp);
  1425. a_reg_alloc(list,r);
  1426. { save return address in callers frame}
  1427. r2.enum:=R_LR;
  1428. list.concat(taicpu.op_reg_reg(A_MFSPR,r,r2));
  1429. { ... in caller's frame }
  1430. reference_reset_base(href,rsp,8);
  1431. list.concat(taicpu.op_reg_ref(A_STW,r,href));
  1432. a_reg_dealloc(list,r);
  1433. { save non-volatile registers in callers frame}
  1434. registerSaveAreaSize:= save_regs(list);
  1435. { save the CR if necessary in callers frame ( !!! always done currently ) }
  1436. a_reg_alloc(list,r);
  1437. r2.enum:=R_CR;
  1438. list.concat(taicpu.op_reg_reg(A_MFSPR,r,r2));
  1439. reference_reset_base(href,rsp,LA_CR);
  1440. list.concat(taicpu.op_reg_ref(A_STW,r,href));
  1441. a_reg_dealloc(list,r);
  1442. (*
  1443. { save pointer to incoming arguments }
  1444. list.concat(taicpu.op_reg_reg_const(A_ORI,R_31,STACK_POINTER_REG,0));
  1445. *)
  1446. (*
  1447. a_reg_alloc(list,R_12);
  1448. { 0 or 8 based on SP alignment }
  1449. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,
  1450. R_12,STACK_POINTER_REG,0,28,28));
  1451. { add in stack length }
  1452. list.concat(taicpu.op_reg_reg_const(A_SUBFIC,R_12,R_12,
  1453. -localsize));
  1454. { establish new alignment }
  1455. list.concat(taicpu.op_reg_reg_reg(A_STWUX,STACK_POINTER_REG,STACK_POINTER_REG,R_12));
  1456. a_reg_dealloc(list,R_12);
  1457. *)
  1458. { allocate stack frame }
  1459. localsize:= align(localsize + macosLinkageAreaSize + registerSaveAreaSize, 16);
  1460. inc(localsize,tg.lasttemp);
  1461. localsize:=align(localsize,16);
  1462. tppcprocinfo(current_procinfo).localsize:=localsize;
  1463. if (localsize <> 0) then
  1464. begin
  1465. r.enum:=R_INTREGISTER;
  1466. r.number:=NR_STACK_POINTER_REG;
  1467. if (localsize <= high(smallint)) then
  1468. begin
  1469. reference_reset_base(href,r,-localsize);
  1470. a_load_store(list,A_STWU,r,href);
  1471. end
  1472. else
  1473. begin
  1474. reference_reset_base(href,r,0);
  1475. {$ifndef newra}
  1476. href.index := get_scratch_reg_int(list,OS_32);
  1477. {$else newra}
  1478. href.index := rg.getregisterint(list,OS_ADDR);
  1479. {$endif newra}
  1480. a_load_const_reg(list,OS_S32,-localsize,href.index);
  1481. a_load_store(list,A_STWUX,r,href);
  1482. {$ifndef newra}
  1483. free_scratch_reg(list,href.index);
  1484. {$else newra}
  1485. rg.ungetregisterint(list,href.index);
  1486. {$endif newra}
  1487. end;
  1488. end;
  1489. end;
  1490. procedure tcgppc.g_return_from_proc_mac(list : taasmoutput;parasize : aword);
  1491. var
  1492. regcounter: TRegister;
  1493. href : treference;
  1494. r,r2,rsp:Tregister;
  1495. regcounter2: Tsuperregister;
  1496. begin
  1497. r.enum:=R_INTREGISTER;
  1498. r.number:=NR_R0;
  1499. rsp.enum:=R_INTREGISTER;
  1500. rsp.number:=NR_STACK_POINTER_REG;
  1501. a_reg_alloc(list,r);
  1502. { restore stack pointer }
  1503. reference_reset_base(href,rsp,LA_SP);
  1504. list.concat(taicpu.op_reg_ref(A_LWZ,rsp,href));
  1505. (*
  1506. list.concat(taicpu.op_reg_reg_const(A_ORI,rsp,R_31,0));
  1507. *)
  1508. { restore the CR if necessary from callers frame
  1509. ( !!! always done currently ) }
  1510. reference_reset_base(href,rsp,LA_CR);
  1511. r.enum:=R_INTREGISTER;
  1512. r.number:=NR_R0;
  1513. list.concat(taicpu.op_reg_ref(A_LWZ,r,href));
  1514. r2.enum:=R_CR;
  1515. list.concat(taicpu.op_reg_reg(A_MTSPR,r,r2));
  1516. a_reg_dealloc(list,r);
  1517. (*
  1518. { restore return address from callers frame }
  1519. reference_reset_base(href,STACK_POINTER_REG,8);
  1520. list.concat(taicpu.op_reg_ref(A_LWZ,R_0,href));
  1521. *)
  1522. { restore non-volatile registers from callers frame }
  1523. restore_regs(list);
  1524. (*
  1525. { return to caller }
  1526. list.concat(taicpu.op_reg_reg(A_MTSPR,R_0,R_LR));
  1527. list.concat(taicpu.op_none(A_BLR));
  1528. *)
  1529. { restore return address from callers frame }
  1530. r.enum:=R_INTREGISTER;
  1531. r.number:=NR_R0;
  1532. r2.enum:=R_LR;
  1533. reference_reset_base(href,rsp,8);
  1534. list.concat(taicpu.op_reg_ref(A_LWZ,r,href));
  1535. { return to caller }
  1536. list.concat(taicpu.op_reg_reg(A_MTSPR,r,r2));
  1537. list.concat(taicpu.op_none(A_BLR));
  1538. end;
  1539. procedure tcgppc.g_restore_frame_pointer(list : taasmoutput);
  1540. begin
  1541. { no frame pointer on the PowerPC (maybe there is one in the SystemV ABI?)}
  1542. end;
  1543. procedure tcgppc.a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);
  1544. var
  1545. ref2, tmpref: treference;
  1546. freereg: boolean;
  1547. r2,tmpreg:Tregister;
  1548. begin
  1549. ref2 := ref;
  1550. freereg := fixref(list,ref2);
  1551. if assigned(ref2.symbol) then
  1552. begin
  1553. if target_info.system = system_powerpc_macos then
  1554. begin
  1555. if macos_direct_globals then
  1556. begin
  1557. reference_reset(tmpref);
  1558. tmpref.offset := ref2.offset;
  1559. tmpref.symbol := ref2.symbol;
  1560. tmpref.symaddr := refs_full;
  1561. tmpref.base.number := NR_NO;
  1562. r2.enum:=R_INTREGISTER;
  1563. r2.number:=NR_RTOC;
  1564. list.concat(taicpu.op_reg_reg_ref(A_ADDI,r,r2,tmpref));
  1565. if ref2.base.number <> NR_NO then
  1566. list.concat(taicpu.op_reg_reg_reg(A_ADD,r,r,ref2.base));
  1567. end
  1568. else
  1569. begin
  1570. reference_reset(tmpref);
  1571. tmpref.symbol := ref2.symbol;
  1572. tmpref.offset := 0;
  1573. tmpref.symaddr := refs_full;
  1574. tmpref.base.enum := R_INTREGISTER;
  1575. tmpref.base.number := NR_RTOC;
  1576. list.concat(taicpu.op_reg_ref(A_LWZ,r,tmpref));
  1577. if ref2.base.number <> NR_NO then
  1578. begin
  1579. list.concat(taicpu.op_reg_reg_reg(A_ADD,r,r,ref2.base));
  1580. end;
  1581. if ref2.offset <> 0 then
  1582. begin
  1583. reference_reset(tmpref);
  1584. tmpref.offset := ref2.offset;
  1585. tmpref.symaddr := refs_full;
  1586. tmpref.base:= r;
  1587. list.concat(taicpu.op_reg_ref(A_LA,r,tmpref));
  1588. end;
  1589. end;
  1590. //list.concat(tai_comment.create(strpnew('*** a_loadaddr_ref_reg')));
  1591. end
  1592. else
  1593. begin
  1594. { add the symbol's value to the base of the reference, and if the }
  1595. { reference doesn't have a base, create one }
  1596. reference_reset(tmpref);
  1597. tmpref.offset := ref2.offset;
  1598. tmpref.symbol := ref2.symbol;
  1599. tmpref.symaddr := refs_ha;
  1600. if ref2.base.number<> NR_NO then
  1601. begin
  1602. list.concat(taicpu.op_reg_reg_ref(A_ADDIS,r,
  1603. ref2.base,tmpref));
  1604. if freereg then
  1605. begin
  1606. {$ifndef newra}
  1607. cg.free_scratch_reg(list,ref2.base);
  1608. {$else newra}
  1609. rg.ungetregisterint(list,ref2.base);
  1610. {$endif newra}
  1611. freereg := false;
  1612. end;
  1613. end
  1614. else
  1615. list.concat(taicpu.op_reg_ref(A_LIS,r,tmpref));
  1616. tmpref.base.number := NR_NO;
  1617. tmpref.symaddr := refs_l;
  1618. { can be folded with one of the next instructions by the }
  1619. { optimizer probably }
  1620. list.concat(taicpu.op_reg_reg_ref(A_ADDI,r,r,tmpref));
  1621. end
  1622. end
  1623. else if ref2.offset <> 0 Then
  1624. if ref2.base.number <> NR_NO then
  1625. a_op_const_reg_reg(list,OP_ADD,OS_32,aword(ref2.offset),ref2.base,r)
  1626. { FixRef makes sure that "(ref.index <> R_NO) and (ref.offset <> 0)" never}
  1627. { occurs, so now only ref.offset has to be loaded }
  1628. else
  1629. a_load_const_reg(list,OS_32,ref2.offset,r)
  1630. else if ref.index.number <> NR_NO Then
  1631. list.concat(taicpu.op_reg_reg_reg(A_ADD,r,ref2.base,ref2.index))
  1632. else if (ref2.base.number <> NR_NO) and
  1633. (r.number <> ref2.base.number) then
  1634. list.concat(taicpu.op_reg_reg(A_MR,r,ref2.base));
  1635. if freereg then
  1636. {$ifndef newra}
  1637. cg.free_scratch_reg(list,ref2.base);
  1638. {$else newra}
  1639. rg.ungetregisterint(list,ref2.base);
  1640. {$endif newra}
  1641. end;
  1642. { ************* concatcopy ************ }
  1643. {$ifndef ppc603}
  1644. const
  1645. maxmoveunit = 8;
  1646. {$else ppc603}
  1647. const
  1648. maxmoveunit = 4;
  1649. {$endif ppc603}
  1650. procedure tcgppc.g_concatcopy(list : taasmoutput;const source,dest : treference;len : aword; delsource,loadref : boolean);
  1651. var
  1652. countreg: TRegister;
  1653. src, dst: TReference;
  1654. lab: tasmlabel;
  1655. count, count2: aword;
  1656. orgsrc, orgdst: boolean;
  1657. r:Tregister;
  1658. size: tcgsize;
  1659. begin
  1660. {$ifdef extdebug}
  1661. if len > high(longint) then
  1662. internalerror(2002072704);
  1663. {$endif extdebug}
  1664. { make sure short loads are handled as optimally as possible }
  1665. if not loadref then
  1666. if (len <= maxmoveunit) and
  1667. (byte(len) in [1,2,4,8]) then
  1668. begin
  1669. if len < 8 then
  1670. begin
  1671. size := int_cgsize(len);
  1672. a_load_ref_ref(list,size,size,source,dest);
  1673. if delsource then
  1674. begin
  1675. reference_release(list,source);
  1676. tg.ungetiftemp(list,source);
  1677. end;
  1678. end
  1679. else
  1680. begin
  1681. r.enum:=R_F0;
  1682. a_reg_alloc(list,r);
  1683. a_loadfpu_ref_reg(list,OS_F64,source,r);
  1684. if delsource then
  1685. begin
  1686. reference_release(list,source);
  1687. tg.ungetiftemp(list,source);
  1688. end;
  1689. a_loadfpu_reg_ref(list,OS_F64,r,dest);
  1690. a_reg_dealloc(list,r);
  1691. end;
  1692. exit;
  1693. end;
  1694. count := len div maxmoveunit;
  1695. reference_reset(src);
  1696. reference_reset(dst);
  1697. { load the address of source into src.base }
  1698. if loadref then
  1699. begin
  1700. {$ifndef newra}
  1701. src.base := get_scratch_reg_address(list);
  1702. {$else newra}
  1703. src.base := rg.getregisterint(list,OS_ADDR);
  1704. {$endif newra}
  1705. a_load_ref_reg(list,OS_32,OS_32,source,src.base);
  1706. orgsrc := false;
  1707. end
  1708. else if (count > 4) or
  1709. not issimpleref(source) or
  1710. ((source.index.number <> NR_NO) and
  1711. ((source.offset + longint(len)) > high(smallint))) then
  1712. begin
  1713. {$ifndef newra}
  1714. src.base := get_scratch_reg_address(list);
  1715. {$else newra}
  1716. src.base := rg.getregisterint(list,OS_ADDR);
  1717. {$endif newra}
  1718. a_loadaddr_ref_reg(list,source,src.base);
  1719. orgsrc := false;
  1720. end
  1721. else
  1722. begin
  1723. src := source;
  1724. orgsrc := true;
  1725. end;
  1726. if not orgsrc and delsource then
  1727. reference_release(list,source);
  1728. { load the address of dest into dst.base }
  1729. if (count > 4) or
  1730. not issimpleref(dest) or
  1731. ((dest.index.number <> NR_NO) and
  1732. ((dest.offset + longint(len)) > high(smallint))) then
  1733. begin
  1734. {$ifndef newra}
  1735. dst.base := get_scratch_reg_address(list);
  1736. {$else newra}
  1737. dst.base := rg.getregisterint(list,OS_ADDR);
  1738. {$endif newra}
  1739. a_loadaddr_ref_reg(list,dest,dst.base);
  1740. orgdst := false;
  1741. end
  1742. else
  1743. begin
  1744. dst := dest;
  1745. orgdst := true;
  1746. end;
  1747. {$ifndef ppc603}
  1748. if count > 4 then
  1749. { generate a loop }
  1750. begin
  1751. { the offsets are zero after the a_loadaddress_ref_reg and just }
  1752. { have to be set to 8. I put an Inc there so debugging may be }
  1753. { easier (should offset be different from zero here, it will be }
  1754. { easy to notice in the generated assembler }
  1755. inc(dst.offset,8);
  1756. inc(src.offset,8);
  1757. list.concat(taicpu.op_reg_reg_const(A_SUBI,src.base,src.base,8));
  1758. list.concat(taicpu.op_reg_reg_const(A_SUBI,dst.base,dst.base,8));
  1759. {$ifndef newra}
  1760. countreg := get_scratch_reg_int(list,OS_INT);
  1761. {$else newra}
  1762. countreg := rg.getregisterint(list,OS_INT);
  1763. {$endif newra}
  1764. a_load_const_reg(list,OS_32,count,countreg);
  1765. { explicitely allocate R_0 since it can be used safely here }
  1766. { (for holding date that's being copied) }
  1767. r.enum:=R_F0;
  1768. a_reg_alloc(list,r);
  1769. objectlibrary.getlabel(lab);
  1770. a_label(list, lab);
  1771. list.concat(taicpu.op_reg_reg_const(A_SUBIC_,countreg,countreg,1));
  1772. r.enum:=R_F0;
  1773. list.concat(taicpu.op_reg_ref(A_LFDU,r,src));
  1774. list.concat(taicpu.op_reg_ref(A_STFDU,r,dst));
  1775. a_jmp(list,A_BC,C_NE,0,lab);
  1776. {$ifndef newra}
  1777. free_scratch_reg(list,countreg);
  1778. {$else newra}
  1779. rg.ungetregisterint(list,countreg);
  1780. {$endif newra}
  1781. a_reg_dealloc(list,r);
  1782. len := len mod 8;
  1783. end;
  1784. count := len div 8;
  1785. if count > 0 then
  1786. { unrolled loop }
  1787. begin
  1788. r.enum:=R_F0;
  1789. a_reg_alloc(list,r);
  1790. for count2 := 1 to count do
  1791. begin
  1792. a_loadfpu_ref_reg(list,OS_F64,src,r);
  1793. a_loadfpu_reg_ref(list,OS_F64,r,dst);
  1794. inc(src.offset,8);
  1795. inc(dst.offset,8);
  1796. end;
  1797. a_reg_dealloc(list,r);
  1798. len := len mod 8;
  1799. end;
  1800. if (len and 4) <> 0 then
  1801. begin
  1802. r.enum:=R_INTREGISTER;
  1803. r.number:=NR_R0;
  1804. a_reg_alloc(list,r);
  1805. a_load_ref_reg(list,OS_32,OS_32,src,r);
  1806. a_load_reg_ref(list,OS_32,OS_32,r,dst);
  1807. inc(src.offset,4);
  1808. inc(dst.offset,4);
  1809. a_reg_dealloc(list,r);
  1810. end;
  1811. {$else not ppc603}
  1812. if count > 4 then
  1813. { generate a loop }
  1814. begin
  1815. { the offsets are zero after the a_loadaddress_ref_reg and just }
  1816. { have to be set to 4. I put an Inc there so debugging may be }
  1817. { easier (should offset be different from zero here, it will be }
  1818. { easy to notice in the generated assembler }
  1819. inc(dst.offset,4);
  1820. inc(src.offset,4);
  1821. list.concat(taicpu.op_reg_reg_const(A_SUBI,src.base,src.base,4));
  1822. list.concat(taicpu.op_reg_reg_const(A_SUBI,dst.base,dst.base,4));
  1823. {$ifndef newra}
  1824. countreg := get_scratch_reg_int(list,OS_INT);
  1825. {$else newra}
  1826. countreg := rg.getregisterint(list,OS_INT);
  1827. {$endif newra}
  1828. a_load_const_reg(list,OS_32,count,countreg);
  1829. { explicitely allocate R_0 since it can be used safely here }
  1830. { (for holding date that's being copied) }
  1831. r.enum:=R_INTREGISTER;
  1832. r.number:=NR_R0;
  1833. a_reg_alloc(list,r);
  1834. objectlibrary.getlabel(lab);
  1835. a_label(list, lab);
  1836. list.concat(taicpu.op_reg_reg_const(A_SUBIC_,countreg,countreg,1));
  1837. list.concat(taicpu.op_reg_ref(A_LWZU,r,src));
  1838. list.concat(taicpu.op_reg_ref(A_STWU,r,dst));
  1839. a_jmp(list,A_BC,C_NE,0,lab);
  1840. {$ifndef newra}
  1841. free_scratch_reg(list,countreg);
  1842. {$else newra}
  1843. rg.ungetregisterint(list,countreg);
  1844. {$endif newra}
  1845. a_reg_dealloc(list,r);
  1846. len := len mod 4;
  1847. end;
  1848. count := len div 4;
  1849. if count > 0 then
  1850. { unrolled loop }
  1851. begin
  1852. r.enum:=R_INTREGISTER;
  1853. r.number:=NR_R0;
  1854. a_reg_alloc(list,r);
  1855. for count2 := 1 to count do
  1856. begin
  1857. a_load_ref_reg(list,OS_32,OS_32,src,r);
  1858. a_load_reg_ref(list,OS_32,OS_32,r,dst);
  1859. inc(src.offset,4);
  1860. inc(dst.offset,4);
  1861. end;
  1862. a_reg_dealloc(list,r);
  1863. len := len mod 4;
  1864. end;
  1865. {$endif not ppc603}
  1866. { copy the leftovers }
  1867. if (len and 2) <> 0 then
  1868. begin
  1869. r.enum:=R_INTREGISTER;
  1870. r.number:=NR_R0;
  1871. a_reg_alloc(list,r);
  1872. a_load_ref_reg(list,OS_16,OS_16,src,r);
  1873. a_load_reg_ref(list,OS_16,OS_16,r,dst);
  1874. inc(src.offset,2);
  1875. inc(dst.offset,2);
  1876. a_reg_dealloc(list,r);
  1877. end;
  1878. if (len and 1) <> 0 then
  1879. begin
  1880. r.enum:=R_INTREGISTER;
  1881. r.number:=NR_R0;
  1882. a_reg_alloc(list,r);
  1883. a_load_ref_reg(list,OS_8,OS_8,src,r);
  1884. a_load_reg_ref(list,OS_8,OS_8,r,dst);
  1885. a_reg_dealloc(list,r);
  1886. end;
  1887. if orgsrc then
  1888. begin
  1889. if delsource then
  1890. reference_release(list,source);
  1891. end
  1892. else
  1893. {$ifndef newra}
  1894. free_scratch_reg(list,src.base);
  1895. {$else newra}
  1896. rg.ungetregisterint(list,src.base);
  1897. {$endif newra}
  1898. if not orgdst then
  1899. {$ifndef newra}
  1900. free_scratch_reg(list,dst.base);
  1901. {$else newra}
  1902. rg.ungetregisterint(list,dest.base);
  1903. {$endif newra}
  1904. if delsource then
  1905. tg.ungetiftemp(list,source);
  1906. end;
  1907. procedure tcgppc.g_copyvaluepara_openarray(list : taasmoutput;const ref, lenref:treference;elesize:integer);
  1908. var
  1909. power,len : longint;
  1910. {$ifndef __NOWINPECOFF__}
  1911. again,ok : tasmlabel;
  1912. {$endif}
  1913. r,r2,rsp:Tregister;
  1914. begin
  1915. {$warning !!!! FIX ME !!!!}
  1916. internalerror(200305231);
  1917. {!!!!
  1918. lenref:=ref;
  1919. inc(lenref.offset,4);
  1920. { get stack space }
  1921. r.enum:=R_INTREGISTER;
  1922. r.number:=NR_EDI;
  1923. rsp.enum:=R_INTREGISTER;
  1924. rsp.number:=NR_ESP;
  1925. r2.enum:=R_INTREGISTER;
  1926. rg.getexplicitregisterint(list,NR_EDI);
  1927. list.concat(Taicpu.op_ref_reg(A_MOV,S_L,lenref,r));
  1928. list.concat(Taicpu.op_reg(A_INC,S_L,r));
  1929. if (elesize<>1) then
  1930. begin
  1931. if ispowerof2(elesize, power) then
  1932. list.concat(Taicpu.op_const_reg(A_SHL,S_L,power,r))
  1933. else
  1934. list.concat(Taicpu.op_const_reg(A_IMUL,S_L,elesize,r));
  1935. end;
  1936. {$ifndef __NOWINPECOFF__}
  1937. { windows guards only a few pages for stack growing, }
  1938. { so we have to access every page first }
  1939. if target_info.system=system_i386_win32 then
  1940. begin
  1941. objectlibrary.getlabel(again);
  1942. objectlibrary.getlabel(ok);
  1943. a_label(list,again);
  1944. list.concat(Taicpu.op_const_reg(A_CMP,S_L,winstackpagesize,r));
  1945. a_jmp_cond(list,OC_B,ok);
  1946. list.concat(Taicpu.op_const_reg(A_SUB,S_L,winstackpagesize-4,rsp));
  1947. r2.number:=NR_EAX;
  1948. list.concat(Taicpu.op_reg(A_PUSH,S_L,r));
  1949. list.concat(Taicpu.op_const_reg(A_SUB,S_L,winstackpagesize,r));
  1950. a_jmp_always(list,again);
  1951. a_label(list,ok);
  1952. list.concat(Taicpu.op_reg_reg(A_SUB,S_L,r,rsp));
  1953. rg.ungetregisterint(list,r);
  1954. { now reload EDI }
  1955. rg.getexplicitregisterint(list,NR_EDI);
  1956. list.concat(Taicpu.op_ref_reg(A_MOV,S_L,lenref,r));
  1957. list.concat(Taicpu.op_reg(A_INC,S_L,r));
  1958. if (elesize<>1) then
  1959. begin
  1960. if ispowerof2(elesize, power) then
  1961. list.concat(Taicpu.op_const_reg(A_SHL,S_L,power,r))
  1962. else
  1963. list.concat(Taicpu.op_const_reg(A_IMUL,S_L,elesize,r));
  1964. end;
  1965. end
  1966. else
  1967. {$endif __NOWINPECOFF__}
  1968. list.concat(Taicpu.op_reg_reg(A_SUB,S_L,r,rsp));
  1969. { align stack on 4 bytes }
  1970. list.concat(Taicpu.op_const_reg(A_AND,S_L,$fffffff4,rsp));
  1971. { load destination }
  1972. a_load_reg_reg(list,OS_INT,OS_INT,rsp,r);
  1973. { don't destroy the registers! }
  1974. r2.number:=NR_ECX;
  1975. list.concat(Taicpu.op_reg(A_PUSH,S_L,r2));
  1976. r2.number:=NR_ESI;
  1977. list.concat(Taicpu.op_reg(A_PUSH,S_L,r2));
  1978. { load count }
  1979. r2.number:=NR_ECX;
  1980. a_load_ref_reg(list,OS_INT,lenref,r2);
  1981. { load source }
  1982. r2.number:=NR_ESI;
  1983. a_load_ref_reg(list,OS_INT,ref,r2);
  1984. { scheduled .... }
  1985. r2.number:=NR_ECX;
  1986. list.concat(Taicpu.op_reg(A_INC,S_L,r2));
  1987. { calculate size }
  1988. len:=elesize;
  1989. opsize:=S_B;
  1990. if (len and 3)=0 then
  1991. begin
  1992. opsize:=S_L;
  1993. len:=len shr 2;
  1994. end
  1995. else
  1996. if (len and 1)=0 then
  1997. begin
  1998. opsize:=S_W;
  1999. len:=len shr 1;
  2000. end;
  2001. if ispowerof2(len, power) then
  2002. list.concat(Taicpu.op_const_reg(A_SHL,S_L,power,r2))
  2003. else
  2004. list.concat(Taicpu.op_const_reg(A_IMUL,S_L,len,r2));
  2005. list.concat(Taicpu.op_none(A_REP,S_NO));
  2006. case opsize of
  2007. S_B : list.concat(Taicpu.Op_none(A_MOVSB,S_NO));
  2008. S_W : list.concat(Taicpu.Op_none(A_MOVSW,S_NO));
  2009. S_L : list.concat(Taicpu.Op_none(A_MOVSD,S_NO));
  2010. end;
  2011. rg.ungetregisterint(list,r);
  2012. r2.number:=NR_ESI;
  2013. list.concat(Taicpu.op_reg(A_POP,S_L,r2));
  2014. r2.number:=NR_ECX;
  2015. list.concat(Taicpu.op_reg(A_POP,S_L,r2));
  2016. { patch the new address }
  2017. a_load_reg_ref(list,OS_INT,rsp,ref);
  2018. !!!!}
  2019. end;
  2020. procedure tcgppc.g_overflowcheck(list: taasmoutput; const l: tlocation; def: tdef);
  2021. var
  2022. hl : tasmlabel;
  2023. r:Tregister;
  2024. begin
  2025. if not(cs_check_overflow in aktlocalswitches) then
  2026. exit;
  2027. objectlibrary.getlabel(hl);
  2028. if not ((def.deftype=pointerdef) or
  2029. ((def.deftype=orddef) and
  2030. (torddef(def).typ in [u64bit,u16bit,u32bit,u8bit,uchar,
  2031. bool8bit,bool16bit,bool32bit]))) then
  2032. begin
  2033. r.enum:=R_CR7;
  2034. list.concat(taicpu.op_reg(A_MCRXR,r));
  2035. a_jmp(list,A_BC,C_OV,7,hl)
  2036. end
  2037. else
  2038. a_jmp_cond(list,OC_AE,hl);
  2039. a_call_name(list,'FPC_OVERFLOW');
  2040. a_label(list,hl);
  2041. end;
  2042. {***************** This is private property, keep out! :) *****************}
  2043. function tcgppc.issimpleref(const ref: treference): boolean;
  2044. begin
  2045. if (ref.base.number = NR_NO) and
  2046. (ref.index.number <> NR_NO) then
  2047. internalerror(200208101);
  2048. result :=
  2049. not(assigned(ref.symbol)) and
  2050. (((ref.index.number = NR_NO) and
  2051. (ref.offset >= low(smallint)) and
  2052. (ref.offset <= high(smallint))) or
  2053. ((ref.index.number <> NR_NO) and
  2054. (ref.offset = 0)));
  2055. end;
  2056. function tcgppc.fixref(list: taasmoutput; var ref: treference): boolean;
  2057. var
  2058. tmpreg: tregister;
  2059. begin
  2060. result := false;
  2061. if (ref.base.number = NR_NO) then
  2062. begin
  2063. ref.base := ref.index;
  2064. ref.base.number := NR_NO;
  2065. end;
  2066. if (ref.base.number <> NR_NO) then
  2067. begin
  2068. if (ref.index.number <> NR_NO) and
  2069. ((ref.offset <> 0) or assigned(ref.symbol)) then
  2070. begin
  2071. result := true;
  2072. {$ifndef newra}
  2073. tmpreg := cg.get_scratch_reg_int(list,OS_INT);
  2074. {$else newra}
  2075. tmpreg := rg.getregisterint(list,OS_INT);
  2076. {$endif newra}
  2077. if not assigned(ref.symbol) and
  2078. (cardinal(ref.offset-low(smallint)) <=
  2079. high(smallint)-low(smallint)) then
  2080. begin
  2081. list.concat(taicpu.op_reg_reg_const(
  2082. A_ADDI,tmpreg,ref.base,ref.offset));
  2083. ref.offset := 0;
  2084. end
  2085. else
  2086. begin
  2087. list.concat(taicpu.op_reg_reg_reg(
  2088. A_ADD,tmpreg,ref.base,ref.index));
  2089. ref.index.number := NR_NO;
  2090. end;
  2091. ref.base := tmpreg;
  2092. end
  2093. end
  2094. else
  2095. if ref.index.number <> NR_NO then
  2096. internalerror(200208102);
  2097. end;
  2098. { find out whether a is of the form 11..00..11b or 00..11...00. If }
  2099. { that's the case, we can use rlwinm to do an AND operation }
  2100. function tcgppc.get_rlwi_const(a: aword; var l1, l2: longint): boolean;
  2101. var
  2102. temp : longint;
  2103. testbit : aword;
  2104. compare: boolean;
  2105. begin
  2106. get_rlwi_const := false;
  2107. if (a = 0) or (a = $ffffffff) then
  2108. exit;
  2109. { start with the lowest bit }
  2110. testbit := 1;
  2111. { check its value }
  2112. compare := boolean(a and testbit);
  2113. { find out how long the run of bits with this value is }
  2114. { (it's impossible that all bits are 1 or 0, because in that case }
  2115. { this function wouldn't have been called) }
  2116. l1 := 31;
  2117. while (((a and testbit) <> 0) = compare) do
  2118. begin
  2119. testbit := testbit shl 1;
  2120. dec(l1);
  2121. end;
  2122. { check the length of the run of bits that comes next }
  2123. compare := not compare;
  2124. l2 := l1;
  2125. while (((a and testbit) <> 0) = compare) and
  2126. (l2 >= 0) do
  2127. begin
  2128. testbit := testbit shl 1;
  2129. dec(l2);
  2130. end;
  2131. { and finally the check whether the rest of the bits all have the }
  2132. { same value }
  2133. compare := not compare;
  2134. temp := l2;
  2135. if temp >= 0 then
  2136. if (a shr (31-temp)) <> ((-ord(compare)) shr (31-temp)) then
  2137. exit;
  2138. { we have done "not(not(compare))", so compare is back to its }
  2139. { initial value. If the lowest bit was 0, a is of the form }
  2140. { 00..11..00 and we need "rlwinm reg,reg,0,l2+1,l1", (+1 }
  2141. { because l2 now contains the position of the last zero of the }
  2142. { first run instead of that of the first 1) so switch l1 and l2 }
  2143. { in that case (we will generate "rlwinm reg,reg,0,l1,l2") }
  2144. if not compare then
  2145. begin
  2146. temp := l1;
  2147. l1 := l2+1;
  2148. l2 := temp;
  2149. end
  2150. else
  2151. { otherwise, l1 currently contains the position of the last }
  2152. { zero instead of that of the first 1 of the second run -> +1 }
  2153. inc(l1);
  2154. { the following is the same as "if l1 = -1 then l1 := 31;" }
  2155. l1 := l1 and 31;
  2156. l2 := l2 and 31;
  2157. get_rlwi_const := true;
  2158. end;
  2159. procedure tcgppc.a_load_store(list:taasmoutput;op: tasmop;reg:tregister;
  2160. ref: treference);
  2161. var
  2162. tmpreg: tregister;
  2163. tmpref: treference;
  2164. r : Tregister;
  2165. begin
  2166. tmpreg.number := NR_NO;
  2167. if assigned(ref.symbol) or
  2168. (cardinal(ref.offset-low(smallint)) >
  2169. high(smallint)-low(smallint)) then
  2170. begin
  2171. if target_info.system = system_powerpc_macos then
  2172. begin
  2173. if ref.base.number <> NR_NO then
  2174. begin
  2175. if macos_direct_globals then
  2176. begin
  2177. {Generates
  2178. add tempreg, ref.base, RTOC
  2179. op reg, symbolplusoffset, tempreg
  2180. which is eqvivalent to the more comprehensive
  2181. addi tempreg, RTOC, symbolplusoffset
  2182. add tempreg, ref.base, tempreg
  2183. op reg, tempreg
  2184. but which saves one instruction.}
  2185. {$ifndef newra}
  2186. tmpreg := get_scratch_reg_address(list);
  2187. {$else newra}
  2188. tmpreg := rg.getregisterint(list,OS_ADDR);
  2189. {$endif newra}
  2190. reference_reset(tmpref);
  2191. tmpref.symbol := ref.symbol;
  2192. tmpref.offset := ref.offset;
  2193. tmpref.symaddr := refs_full;
  2194. tmpref.base:= tmpreg;
  2195. r.enum:=R_INTREGISTER;
  2196. r.number:=NR_RTOC;
  2197. list.concat(taicpu.op_reg_reg_reg(A_ADD,tmpreg,
  2198. ref.base,r));
  2199. list.concat(taicpu.op_reg_ref(op,reg,tmpref));
  2200. end
  2201. else
  2202. begin
  2203. {$ifndef newra}
  2204. tmpreg := get_scratch_reg_address(list);
  2205. {$else newra}
  2206. tmpreg := rg.getregisterint(list,OS_ADDR);
  2207. {$endif newra}
  2208. reference_reset(tmpref);
  2209. tmpref.symbol := ref.symbol;
  2210. tmpref.offset := 0;
  2211. tmpref.symaddr := refs_full;
  2212. tmpref.base.enum:= R_INTREGISTER;
  2213. tmpref.base.number:= NR_RTOC;
  2214. list.concat(taicpu.op_reg_ref(A_LWZ,tmpreg,tmpref));
  2215. list.concat(taicpu.op_reg_reg_reg(A_ADD,tmpreg,
  2216. ref.base,tmpreg));
  2217. reference_reset(tmpref);
  2218. tmpref.offset := ref.offset;
  2219. tmpref.symaddr := refs_full;
  2220. tmpref.base:= tmpreg;
  2221. list.concat(taicpu.op_reg_ref(op,reg,tmpref));
  2222. end;
  2223. //list.concat(tai_comment.create(strpnew('**** a_load_store 1')));
  2224. end
  2225. else
  2226. begin
  2227. if macos_direct_globals then
  2228. begin
  2229. reference_reset(tmpref);
  2230. tmpref.symbol := ref.symbol;
  2231. tmpref.offset := ref.offset;
  2232. tmpref.symaddr := refs_full;
  2233. tmpref.base.enum:= R_INTREGISTER;
  2234. tmpref.base.number:= NR_RTOC;
  2235. list.concat(taicpu.op_reg_ref(op,reg,tmpref));
  2236. end
  2237. else
  2238. begin
  2239. {$ifndef newra}
  2240. tmpreg := get_scratch_reg_address(list);
  2241. {$else newra}
  2242. tmpreg := rg.getregisterint(list,OS_ADDR);
  2243. {$endif newra}
  2244. reference_reset(tmpref);
  2245. tmpref.symbol := ref.symbol;
  2246. tmpref.offset := 0;
  2247. tmpref.symaddr := refs_full;
  2248. tmpref.base.enum:= R_INTREGISTER;
  2249. tmpref.base.number:= NR_RTOC;
  2250. list.concat(taicpu.op_reg_ref(A_LWZ,tmpreg,tmpref));
  2251. reference_reset(tmpref);
  2252. tmpref.offset := ref.offset;
  2253. tmpref.symaddr := refs_full;
  2254. tmpref.base:= tmpreg;
  2255. list.concat(taicpu.op_reg_ref(op,reg,tmpref));
  2256. end;
  2257. //list.concat(tai_comment.create(strpnew('*** a_load_store 2')));
  2258. end;
  2259. end
  2260. else
  2261. begin
  2262. {$ifndef newra}
  2263. tmpreg := get_scratch_reg_address(list);
  2264. {$else newra}
  2265. tmpreg := rg.getregisterint(list,OS_ADDR);
  2266. {$endif newra}
  2267. reference_reset(tmpref);
  2268. tmpref.symbol := ref.symbol;
  2269. tmpref.offset := ref.offset;
  2270. tmpref.symaddr := refs_ha;
  2271. if ref.base.number <> NR_NO then
  2272. list.concat(taicpu.op_reg_reg_ref(A_ADDIS,tmpreg,
  2273. ref.base,tmpref))
  2274. else
  2275. list.concat(taicpu.op_reg_ref(A_LIS,tmpreg,tmpref));
  2276. ref.base := tmpreg;
  2277. ref.symaddr := refs_l;
  2278. list.concat(taicpu.op_reg_ref(op,reg,ref));
  2279. end
  2280. end
  2281. else
  2282. list.concat(taicpu.op_reg_ref(op,reg,ref));
  2283. if (tmpreg.number <> NR_NO) then
  2284. {$ifndef newra}
  2285. free_scratch_reg(list,tmpreg);
  2286. {$else newra}
  2287. rg.ungetregisterint(list,tmpreg);
  2288. {$endif newra}
  2289. end;
  2290. procedure tcgppc.a_jmp(list: taasmoutput; op: tasmop; c: tasmcondflag;
  2291. crval: longint; l: tasmlabel);
  2292. var
  2293. p: taicpu;
  2294. begin
  2295. p := taicpu.op_sym(op,objectlibrary.newasmsymbol(l.name));
  2296. if op <> A_B then
  2297. create_cond_norm(c,crval,p.condition);
  2298. p.is_jmp := true;
  2299. list.concat(p)
  2300. end;
  2301. procedure tcg64fppc.a_op64_reg_reg(list : taasmoutput;op:TOpCG;regsrc,regdst : tregister64);
  2302. begin
  2303. a_op64_reg_reg_reg(list,op,regsrc,regdst,regdst);
  2304. end;
  2305. procedure tcg64fppc.a_op64_const_reg(list : taasmoutput;op:TOpCG;value : qword;reg : tregister64);
  2306. begin
  2307. a_op64_const_reg_reg(list,op,value,reg,reg);
  2308. end;
  2309. procedure tcg64fppc.a_op64_reg_reg_reg(list: taasmoutput;op:TOpCG;regsrc1,regsrc2,regdst : tregister64);
  2310. begin
  2311. case op of
  2312. OP_AND,OP_OR,OP_XOR:
  2313. begin
  2314. cg.a_op_reg_reg_reg(list,op,OS_32,regsrc1.reglo,regsrc2.reglo,regdst.reglo);
  2315. cg.a_op_reg_reg_reg(list,op,OS_32,regsrc1.reghi,regsrc2.reghi,regdst.reghi);
  2316. end;
  2317. OP_ADD:
  2318. begin
  2319. list.concat(taicpu.op_reg_reg_reg(A_ADDC,regdst.reglo,regsrc1.reglo,regsrc2.reglo));
  2320. list.concat(taicpu.op_reg_reg_reg(A_ADDE,regdst.reghi,regsrc1.reghi,regsrc2.reghi));
  2321. end;
  2322. OP_SUB:
  2323. begin
  2324. list.concat(taicpu.op_reg_reg_reg(A_SUBC,regdst.reglo,regsrc2.reglo,regsrc1.reglo));
  2325. list.concat(taicpu.op_reg_reg_reg(A_SUBFE,regdst.reghi,regsrc1.reghi,regsrc2.reghi));
  2326. end;
  2327. else
  2328. internalerror(2002072801);
  2329. end;
  2330. end;
  2331. procedure tcg64fppc.a_op64_const_reg_reg(list: taasmoutput;op:TOpCG;value : qword;regsrc,regdst : tregister64);
  2332. const
  2333. ops: array[boolean,1..3] of tasmop = ((A_ADDIC,A_ADDC,A_ADDZE),
  2334. (A_SUBIC,A_SUBC,A_ADDME));
  2335. var
  2336. tmpreg: tregister;
  2337. tmpreg64: tregister64;
  2338. newop: TOpCG;
  2339. issub: boolean;
  2340. begin
  2341. case op of
  2342. OP_AND,OP_OR,OP_XOR:
  2343. begin
  2344. cg.a_op_const_reg_reg(list,op,OS_32,aword(value),regsrc.reglo,regdst.reglo);
  2345. cg.a_op_const_reg_reg(list,op,OS_32,aword(value shr 32),regsrc.reghi,
  2346. regdst.reghi);
  2347. end;
  2348. OP_ADD, OP_SUB:
  2349. begin
  2350. if (int64(value) < 0) then
  2351. begin
  2352. if op = OP_ADD then
  2353. op := OP_SUB
  2354. else
  2355. op := OP_ADD;
  2356. int64(value) := -int64(value);
  2357. end;
  2358. if (longint(value) <> 0) then
  2359. begin
  2360. issub := op = OP_SUB;
  2361. if (int64(value) > 0) and
  2362. (int64(value)-ord(issub) <= 32767) then
  2363. begin
  2364. list.concat(taicpu.op_reg_reg_const(ops[issub,1],
  2365. regdst.reglo,regsrc.reglo,longint(value)));
  2366. list.concat(taicpu.op_reg_reg(ops[issub,3],
  2367. regdst.reghi,regsrc.reghi));
  2368. end
  2369. else if ((value shr 32) = 0) then
  2370. begin
  2371. {$ifndef newra}
  2372. tmpreg := cg.get_scratch_reg_int(list,OS_32);
  2373. {$else newra}
  2374. tmpreg := rg.getregisterint(list,OS_32);
  2375. {$endif newra}
  2376. cg.a_load_const_reg(list,OS_32,cardinal(value),tmpreg);
  2377. list.concat(taicpu.op_reg_reg_reg(ops[issub,2],
  2378. regdst.reglo,regsrc.reglo,tmpreg));
  2379. {$ifndef newra}
  2380. cg.free_scratch_reg(list,tmpreg);
  2381. {$else newra}
  2382. rg.ungetregisterint(list,tmpreg);
  2383. {$endif newra}
  2384. list.concat(taicpu.op_reg_reg(ops[issub,3],
  2385. regdst.reghi,regsrc.reghi));
  2386. end
  2387. else
  2388. begin
  2389. {$ifndef newra}
  2390. tmpreg64.reglo := cg.get_scratch_reg_int(list,OS_32);
  2391. tmpreg64.reghi := cg.get_scratch_reg_int(list,OS_32);
  2392. {$else newra}
  2393. tmpreg64.reglo := rg.getregisterint(list,OS_32);
  2394. tmpreg64.reghi := rg.getregisterint(list,OS_32);
  2395. {$endif newra}
  2396. a_load64_const_reg(list,value,tmpreg64);
  2397. a_op64_reg_reg_reg(list,op,tmpreg64,regsrc,regdst);
  2398. {$ifndef newra}
  2399. cg.free_scratch_reg(list,tmpreg64.reghi);
  2400. cg.free_scratch_reg(list,tmpreg64.reglo);
  2401. {$else newra}
  2402. rg.ungetregisterint(list,tmpreg64.reglo);
  2403. rg.ungetregisterint(list,tmpreg64.reghi);
  2404. {$endif newra}
  2405. end
  2406. end
  2407. else
  2408. begin
  2409. cg.a_load_reg_reg(list,OS_INT,OS_INT,regsrc.reglo,regdst.reglo);
  2410. cg.a_op_const_reg_reg(list,op,OS_32,aword(value shr 32),regsrc.reghi,
  2411. regdst.reghi);
  2412. end;
  2413. end;
  2414. else
  2415. internalerror(2002072802);
  2416. end;
  2417. end;
  2418. begin
  2419. cg := tcgppc.create;
  2420. cg64 :=tcg64fppc.create;
  2421. end.
  2422. {
  2423. $Log$
  2424. Revision 1.112 2003-07-05 20:11:42 jonas
  2425. * create_paraloc_info() is now called separately for the caller and
  2426. callee info
  2427. * fixed ppc cycle
  2428. Revision 1.111 2003/07/02 22:18:04 peter
  2429. * paraloc splitted in callerparaloc,calleeparaloc
  2430. * sparc calling convention updates
  2431. Revision 1.110 2003/06/18 10:12:36 olle
  2432. * macos: fixes of loading-code
  2433. Revision 1.109 2003/06/14 22:32:43 jonas
  2434. * ppc compiles with -dnewra, haven't tried to compile anything with it
  2435. yet though
  2436. Revision 1.108 2003/06/13 21:19:31 peter
  2437. * current_procdef removed, use current_procinfo.procdef instead
  2438. Revision 1.107 2003/06/09 14:54:26 jonas
  2439. * (de)allocation of registers for parameters is now performed properly
  2440. (and checked on the ppc)
  2441. - removed obsolete allocation of all parameter registers at the start
  2442. of a procedure (and deallocation at the end)
  2443. Revision 1.106 2003/06/08 18:19:27 jonas
  2444. - removed duplicate identifier
  2445. Revision 1.105 2003/06/07 18:57:04 jonas
  2446. + added freeintparaloc
  2447. * ppc get/freeintparaloc now check whether the parameter regs are
  2448. properly allocated/deallocated (and get an extra list para)
  2449. * ppc a_call_* now internalerrors if pi_do_call is not yet set
  2450. * fixed lot of missing pi_do_call's
  2451. Revision 1.104 2003/06/04 11:58:58 jonas
  2452. * calculate localsize also in g_return_from_proc since it's now called
  2453. before g_stackframe_entry (still have to fix macos)
  2454. * compilation fixes (cycle doesn't work yet though)
  2455. Revision 1.103 2003/06/01 21:38:06 peter
  2456. * getregisterfpu size parameter added
  2457. * op_const_reg size parameter added
  2458. * sparc updates
  2459. Revision 1.102 2003/06/01 13:42:18 jonas
  2460. * fix for bug in fixref that Peter found during the Sparc conversion
  2461. Revision 1.101 2003/05/30 18:52:10 jonas
  2462. * fixed bug with intregvars
  2463. * locapara.loc can also be LOC_CFPUREGISTER -> also fixed
  2464. rcgppc.a_param_ref, which previously got bogus size values
  2465. Revision 1.100 2003/05/29 21:17:27 jonas
  2466. * compile with -dppc603 to not use unaligned float loads in move() and
  2467. g_concatcopy, because the 603 and 604 take an exception for those
  2468. (and netbsd doesn't even handle those in the kernel). There are
  2469. still some of those left that could cause problems though (e.g.
  2470. in the set helpers)
  2471. Revision 1.99 2003/05/29 10:06:09 jonas
  2472. * also free temps in g_concatcopy if delsource is true
  2473. Revision 1.98 2003/05/28 23:58:18 jonas
  2474. * added missing initialization of rg.usedint{in,by}proc
  2475. * ppc now also saves/restores used fpu registers
  2476. * ncgcal doesn't add used registers to usedby/inproc anymore, except for
  2477. i386
  2478. Revision 1.97 2003/05/28 23:18:31 florian
  2479. * started to fix and clean up the sparc port
  2480. Revision 1.96 2003/05/24 11:59:42 jonas
  2481. * fixed integer typeconversion problems
  2482. Revision 1.95 2003/05/23 18:51:26 jonas
  2483. * fixed support for nested procedures and more parameters than those
  2484. which fit in registers (untested/probably not working: calling a
  2485. nested procedure from a deeper nested procedure)
  2486. Revision 1.94 2003/05/20 23:54:00 florian
  2487. + basic darwin support added
  2488. Revision 1.93 2003/05/15 22:14:42 florian
  2489. * fixed last commit, changing lastsaveintreg to r31 caused some strange problems
  2490. Revision 1.92 2003/05/15 21:37:00 florian
  2491. * sysv entry code saves r13 now as well
  2492. Revision 1.91 2003/05/15 19:39:09 florian
  2493. * fixed ppc compiler which was broken by Peter's changes
  2494. Revision 1.90 2003/05/12 18:43:50 jonas
  2495. * fixed g_concatcopy
  2496. Revision 1.89 2003/05/11 20:59:23 jonas
  2497. * fixed bug with large offsets in entrycode
  2498. Revision 1.88 2003/05/11 11:45:08 jonas
  2499. * fixed shifts
  2500. Revision 1.87 2003/05/11 11:07:33 jonas
  2501. * fixed optimizations in a_op_const_reg_reg()
  2502. Revision 1.86 2003/04/27 11:21:36 peter
  2503. * aktprocdef renamed to current_procinfo.procdef
  2504. * procinfo renamed to current_procinfo
  2505. * procinfo will now be stored in current_module so it can be
  2506. cleaned up properly
  2507. * gen_main_procsym changed to create_main_proc and release_main_proc
  2508. to also generate a tprocinfo structure
  2509. * fixed unit implicit initfinal
  2510. Revision 1.85 2003/04/26 22:56:11 jonas
  2511. * fix to a_op64_const_reg_reg
  2512. Revision 1.84 2003/04/26 16:08:41 jonas
  2513. * fixed g_flags2reg
  2514. Revision 1.83 2003/04/26 15:25:29 florian
  2515. * fixed cmp_reg_reg_reg, cmp operands were emitted in the wrong order
  2516. Revision 1.82 2003/04/25 20:55:34 florian
  2517. * stack frame calculations are now completly done using the code generator
  2518. routines instead of generating directly assembler so also large stack frames
  2519. are handle properly
  2520. Revision 1.81 2003/04/24 11:24:00 florian
  2521. * fixed several issues with nested procedures
  2522. Revision 1.80 2003/04/23 22:18:01 peter
  2523. * fixes to get rtl compiled
  2524. Revision 1.79 2003/04/23 12:35:35 florian
  2525. * fixed several issues with powerpc
  2526. + applied a patch from Jonas for nested function calls (PowerPC only)
  2527. * ...
  2528. Revision 1.78 2003/04/16 09:26:55 jonas
  2529. * assembler procedures now again get a stackframe if they have local
  2530. variables. No space is reserved for a function result however.
  2531. Also, the register parameters aren't automatically saved on the stack
  2532. anymore in assembler procedures.
  2533. Revision 1.77 2003/04/06 16:39:11 jonas
  2534. * don't generate entry/exit code for assembler procedures
  2535. Revision 1.76 2003/03/22 18:01:13 jonas
  2536. * fixed linux entry/exit code generation
  2537. Revision 1.75 2003/03/19 14:26:26 jonas
  2538. * fixed R_TOC bugs introduced by new register allocator conversion
  2539. Revision 1.74 2003/03/13 22:57:45 olle
  2540. * change in a_loadaddr_ref_reg
  2541. Revision 1.73 2003/03/12 22:43:38 jonas
  2542. * more powerpc and generic fixes related to the new register allocator
  2543. Revision 1.72 2003/03/11 21:46:24 jonas
  2544. * lots of new regallocator fixes, both in generic and ppc-specific code
  2545. (ppc compiler still can't compile the linux system unit though)
  2546. Revision 1.71 2003/02/19 22:00:16 daniel
  2547. * Code generator converted to new register notation
  2548. - Horribily outdated todo.txt removed
  2549. Revision 1.70 2003/01/13 17:17:50 olle
  2550. * changed global var access, TOC now contain pointers to globals
  2551. * fixed handling of function pointers
  2552. Revision 1.69 2003/01/09 22:00:53 florian
  2553. * fixed some PowerPC issues
  2554. Revision 1.68 2003/01/08 18:43:58 daniel
  2555. * Tregister changed into a record
  2556. Revision 1.67 2002/12/15 19:22:01 florian
  2557. * fixed some crashes and a rte 201
  2558. Revision 1.66 2002/11/28 10:55:16 olle
  2559. * macos: changing code gen for references to globals
  2560. Revision 1.65 2002/11/07 15:50:23 jonas
  2561. * fixed bctr(l) problems
  2562. Revision 1.64 2002/11/04 18:24:19 olle
  2563. * macos: globals are located in TOC and relative r2, instead of absolute
  2564. Revision 1.63 2002/10/28 22:24:28 olle
  2565. * macos entry/exit: only used registers are saved
  2566. - macos entry/exit: stackptr not saved in r31 anymore
  2567. * macos entry/exit: misc fixes
  2568. Revision 1.62 2002/10/19 23:51:48 olle
  2569. * macos stack frame size computing updated
  2570. + macos epilogue: control register now restored
  2571. * macos prologue and epilogue: fp reg now saved and restored
  2572. Revision 1.61 2002/10/19 12:50:36 olle
  2573. * reorganized prologue and epilogue routines
  2574. Revision 1.60 2002/10/02 21:49:51 florian
  2575. * all A_BL instructions replaced by calls to a_call_name
  2576. Revision 1.59 2002/10/02 13:24:58 jonas
  2577. * changed a_call_* so that no superfluous code is generated anymore
  2578. Revision 1.58 2002/09/17 18:54:06 jonas
  2579. * a_load_reg_reg() now has two size parameters: source and dest. This
  2580. allows some optimizations on architectures that don't encode the
  2581. register size in the register name.
  2582. Revision 1.57 2002/09/10 21:22:25 jonas
  2583. + added some internal errors
  2584. * fixed bug in sysv exit code
  2585. Revision 1.56 2002/09/08 20:11:56 jonas
  2586. * fixed TOpCmp2AsmCond array (some unsigned equivalents were wrong)
  2587. Revision 1.55 2002/09/08 13:03:26 jonas
  2588. * several large offset-related fixes
  2589. Revision 1.54 2002/09/07 17:54:58 florian
  2590. * first part of PowerPC fixes
  2591. Revision 1.53 2002/09/07 15:25:14 peter
  2592. * old logs removed and tabs fixed
  2593. Revision 1.52 2002/09/02 10:14:51 jonas
  2594. + a_call_reg()
  2595. * small fix in a_call_ref()
  2596. Revision 1.51 2002/09/02 06:09:02 jonas
  2597. * fixed range error
  2598. Revision 1.50 2002/09/01 21:04:49 florian
  2599. * several powerpc related stuff fixed
  2600. Revision 1.49 2002/09/01 12:09:27 peter
  2601. + a_call_reg, a_call_loc added
  2602. * removed exprasmlist references
  2603. Revision 1.48 2002/08/31 21:38:02 jonas
  2604. * fixed a_call_ref (it should load ctr, not lr)
  2605. Revision 1.47 2002/08/31 21:30:45 florian
  2606. * fixed several problems caused by Jonas' commit :)
  2607. Revision 1.46 2002/08/31 19:25:50 jonas
  2608. + implemented a_call_ref()
  2609. Revision 1.45 2002/08/18 22:16:14 florian
  2610. + the ppc gas assembler writer adds now registers aliases
  2611. to the assembler file
  2612. Revision 1.44 2002/08/17 18:23:53 florian
  2613. * some assembler writer bugs fixed
  2614. Revision 1.43 2002/08/17 09:23:49 florian
  2615. * first part of procinfo rewrite
  2616. Revision 1.42 2002/08/16 14:24:59 carl
  2617. * issameref() to test if two references are the same (then emit no opcodes)
  2618. + ret_in_reg to replace ret_in_acc
  2619. (fix some register allocation bugs at the same time)
  2620. + save_std_register now has an extra parameter which is the
  2621. usedinproc registers
  2622. Revision 1.41 2002/08/15 08:13:54 carl
  2623. - a_load_sym_ofs_reg removed
  2624. * loadvmt now calls loadaddr_ref_reg instead
  2625. Revision 1.40 2002/08/11 14:32:32 peter
  2626. * renamed current_library to objectlibrary
  2627. Revision 1.39 2002/08/11 13:24:18 peter
  2628. * saving of asmsymbols in ppu supported
  2629. * asmsymbollist global is removed and moved into a new class
  2630. tasmlibrarydata that will hold the info of a .a file which
  2631. corresponds with a single module. Added librarydata to tmodule
  2632. to keep the library info stored for the module. In the future the
  2633. objectfiles will also be stored to the tasmlibrarydata class
  2634. * all getlabel/newasmsymbol and friends are moved to the new class
  2635. Revision 1.38 2002/08/11 11:39:31 jonas
  2636. + powerpc-specific genlinearlist
  2637. Revision 1.37 2002/08/10 17:15:31 jonas
  2638. * various fixes and optimizations
  2639. Revision 1.36 2002/08/06 20:55:23 florian
  2640. * first part of ppc calling conventions fix
  2641. Revision 1.35 2002/08/06 07:12:05 jonas
  2642. * fixed bug in g_flags2reg()
  2643. * and yet more constant operation fixes :)
  2644. Revision 1.34 2002/08/05 08:58:53 jonas
  2645. * fixed compilation problems
  2646. Revision 1.33 2002/08/04 12:57:55 jonas
  2647. * more misc. fixes, mostly constant-related
  2648. }