cgcpu.pas 104 KB

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