cgcpu.pas 103 KB

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