cgcpu.pas 105 KB

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