cgcpu.pas 102 KB

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