cgcpu.pas 105 KB

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