cgcpu.pas 106 KB

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