cgcpu.pas 106 KB

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