cgcpu.pas 104 KB

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