cgcpu.pas 85 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375
  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. cgbase,cgobj,
  23. aasmbase,aasmcpu,aasmtai,
  24. cpubase,cpuinfo,node,cg64f32,cginfo;
  25. type
  26. tcgppc = class(tcg)
  27. { passing parameters, per default the parameter is pushed }
  28. { nr gives the number of the parameter (enumerated from }
  29. { left to right), this allows to move the parameter to }
  30. { register, if the cpu supports register calling }
  31. { conventions }
  32. procedure a_param_const(list : taasmoutput;size : tcgsize;a : aword;const locpara : tparalocation);override;
  33. procedure a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;const locpara : tparalocation);override;
  34. procedure a_paramaddr_ref(list : taasmoutput;const r : treference;const locpara : tparalocation);override;
  35. procedure a_call_name(list : taasmoutput;const s : string);override;
  36. procedure a_call_reg(list : taasmoutput;reg: tregister); override;
  37. procedure a_call_ref(list : taasmoutput;const ref : treference);override;
  38. procedure a_op_const_reg(list : taasmoutput; Op: TOpCG; a: AWord; reg: TRegister); override;
  39. procedure a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; src, dst: TRegister); override;
  40. procedure a_op_const_reg_reg(list: taasmoutput; op: TOpCg;
  41. size: tcgsize; a: aword; src, dst: tregister); override;
  42. procedure a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;
  43. size: tcgsize; src1, src2, dst: tregister); override;
  44. { move instructions }
  45. procedure a_load_const_reg(list : taasmoutput; size: tcgsize; a : aword;reg : tregister);override;
  46. procedure a_load_reg_ref(list : taasmoutput; size: tcgsize; reg : tregister;const ref : treference);override;
  47. procedure a_load_ref_reg(list : taasmoutput;size : tcgsize;const Ref : treference;reg : tregister);override;
  48. procedure a_load_reg_reg(list : taasmoutput;fromsize, tosize : tcgsize;reg1,reg2 : tregister);override;
  49. { fpu move instructions }
  50. procedure a_loadfpu_reg_reg(list: taasmoutput; reg1, reg2: tregister); override;
  51. procedure a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister); override;
  52. procedure a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference); override;
  53. { comparison operations }
  54. procedure a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;reg : tregister;
  55. l : tasmlabel);override;
  56. procedure a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;reg1,reg2 : tregister;l : tasmlabel); override;
  57. procedure a_jmp_always(list : taasmoutput;l: tasmlabel); override;
  58. procedure a_jmp_flags(list : taasmoutput;const f : TResFlags;l: tasmlabel); override;
  59. procedure g_flags2reg(list: taasmoutput; size: TCgSize; const f: TResFlags; reg: TRegister); override;
  60. procedure g_stackframe_entry(list : taasmoutput;localsize : longint);override;
  61. procedure g_return_from_proc(list : taasmoutput;parasize : aword); override;
  62. procedure g_restore_frame_pointer(list : taasmoutput);override;
  63. procedure a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);override;
  64. procedure g_concatcopy(list : taasmoutput;const source,dest : treference;len : aword; delsource,loadref : boolean);override;
  65. procedure g_overflowcheck(list: taasmoutput; const p: tnode); override;
  66. { find out whether a is of the form 11..00..11b or 00..11...00. If }
  67. { that's the case, we can use rlwinm to do an AND operation }
  68. function get_rlwi_const(a: aword; var l1, l2: longint): boolean;
  69. procedure g_save_standard_registers(list : taasmoutput; usedinproc : Tsupregset);override;
  70. procedure g_restore_standard_registers(list : taasmoutput; usedinproc : Tsupregset);override;
  71. procedure g_save_all_registers(list : taasmoutput);override;
  72. procedure g_restore_all_registers(list : taasmoutput;selfused,accused,acchiused:boolean);override;
  73. procedure a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel);
  74. private
  75. procedure g_stackframe_entry_sysv(list : taasmoutput;localsize : longint);
  76. procedure g_return_from_proc_sysv(list : taasmoutput;parasize : aword);
  77. procedure g_stackframe_entry_mac(list : taasmoutput;localsize : longint);
  78. procedure g_return_from_proc_mac(list : taasmoutput;parasize : aword);
  79. { Make sure ref is a valid reference for the PowerPC and sets the }
  80. { base to the value of the index if (base = R_NO). }
  81. { Returns true if the reference contained a base, index and an }
  82. { offset or symbol, in which case the base will have been changed }
  83. { to a tempreg (which has to be freed by the caller) containing }
  84. { the sum of part of the original reference }
  85. function fixref(list: taasmoutput; var ref: treference): boolean;
  86. { returns whether a reference can be used immediately in a powerpc }
  87. { instruction }
  88. function issimpleref(const ref: treference): boolean;
  89. { contains the common code of a_load_reg_ref and a_load_ref_reg }
  90. procedure a_load_store(list:taasmoutput;op: tasmop;reg:tregister;
  91. ref: treference);
  92. { creates the correct branch instruction for a given combination }
  93. { of asmcondflags and destination addressing mode }
  94. procedure a_jmp(list: taasmoutput; op: tasmop;
  95. c: tasmcondflag; crval: longint; l: tasmlabel);
  96. end;
  97. tcg64fppc = class(tcg64f32)
  98. procedure a_op64_reg_reg(list : taasmoutput;op:TOpCG;regsrc,regdst : tregister64);override;
  99. procedure a_op64_const_reg(list : taasmoutput;op:TOpCG;value : qword;reg : tregister64);override;
  100. procedure a_op64_const_reg_reg(list: taasmoutput;op:TOpCG;value : qword;regsrc,regdst : tregister64);override;
  101. procedure a_op64_reg_reg_reg(list: taasmoutput;op:TOpCG;regsrc1,regsrc2,regdst : tregister64);override;
  102. end;
  103. const
  104. TOpCG2AsmOpConstLo: Array[topcg] of TAsmOp = (A_NONE,A_ADDI,A_ANDI_,A_DIVWU,
  105. A_DIVW,A_MULLW, A_MULLW, A_NONE,A_NONE,A_ORI,
  106. A_SRAWI,A_SLWI,A_SRWI,A_SUBI,A_XORI);
  107. TOpCG2AsmOpConstHi: Array[topcg] of TAsmOp = (A_NONE,A_ADDIS,A_ANDIS_,
  108. A_DIVWU,A_DIVW, A_MULLW,A_MULLW,A_NONE,A_NONE,
  109. A_ORIS,A_NONE, A_NONE,A_NONE,A_SUBIS,A_XORIS);
  110. TOpCmp2AsmCond: Array[topcmp] of TAsmCondFlag = (C_NONE,C_EQ,C_GT,
  111. C_LT,C_GE,C_LE,C_NE,C_LE,C_LT,C_GE,C_GT);
  112. implementation
  113. uses
  114. globtype,globals,verbose,systems,cutils,symconst,symdef,symsym,rgobj,tgobj,cpupi;
  115. { parameter passing... Still needs extra support from the processor }
  116. { independent code generator }
  117. procedure tcgppc.a_param_const(list : taasmoutput;size : tcgsize;a : aword;const locpara : tparalocation);
  118. var
  119. ref: treference;
  120. begin
  121. case locpara.loc of
  122. LOC_REGISTER,LOC_CREGISTER:
  123. a_load_const_reg(list,size,a,locpara.register);
  124. LOC_REFERENCE:
  125. begin
  126. reference_reset(ref);
  127. ref.base:=locpara.reference.index;
  128. ref.offset:=locpara.reference.offset;
  129. a_load_const_ref(list,size,a,ref);
  130. end;
  131. else
  132. internalerror(2002081101);
  133. end;
  134. if locpara.sp_fixup<>0 then
  135. internalerror(2002081102);
  136. end;
  137. procedure tcgppc.a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;const locpara : tparalocation);
  138. var
  139. ref: treference;
  140. tmpreg: tregister;
  141. begin
  142. case locpara.loc of
  143. LOC_REGISTER,LOC_CREGISTER:
  144. a_load_ref_reg(list,size,r,locpara.register);
  145. LOC_REFERENCE:
  146. begin
  147. reference_reset(ref);
  148. ref.base:=locpara.reference.index;
  149. ref.offset:=locpara.reference.offset;
  150. tmpreg := get_scratch_reg_int(list,size);
  151. a_load_ref_reg(list,size,r,tmpreg);
  152. a_load_reg_ref(list,size,tmpreg,ref);
  153. free_scratch_reg(list,tmpreg);
  154. end;
  155. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  156. case size of
  157. OS_32:
  158. a_loadfpu_ref_reg(list,OS_F32,r,locpara.register);
  159. OS_64:
  160. a_loadfpu_ref_reg(list,OS_F64,r,locpara.register);
  161. else
  162. internalerror(2002072801);
  163. end;
  164. else
  165. internalerror(2002081103);
  166. end;
  167. if locpara.sp_fixup<>0 then
  168. internalerror(2002081104);
  169. end;
  170. procedure tcgppc.a_paramaddr_ref(list : taasmoutput;const r : treference;const locpara : tparalocation);
  171. var
  172. ref: treference;
  173. tmpreg: tregister;
  174. begin
  175. case locpara.loc of
  176. LOC_REGISTER,LOC_CREGISTER:
  177. a_loadaddr_ref_reg(list,r,locpara.register);
  178. LOC_REFERENCE:
  179. begin
  180. reference_reset(ref);
  181. ref.base := locpara.reference.index;
  182. ref.offset := locpara.reference.offset;
  183. tmpreg := get_scratch_reg_address(list);
  184. a_loadaddr_ref_reg(list,r,tmpreg);
  185. a_load_reg_ref(list,OS_ADDR,tmpreg,ref);
  186. free_scratch_reg(list,tmpreg);
  187. end;
  188. else
  189. internalerror(2002080701);
  190. end;
  191. end;
  192. { calling a procedure by name }
  193. procedure tcgppc.a_call_name(list : taasmoutput;const s : string);
  194. var
  195. href : treference;
  196. begin
  197. {MacOS: The linker on MacOS (PPCLink) inserts a call to glue code,
  198. if it is a cross-TOC call. If so, it also replaces the NOP
  199. with some restore code.}
  200. list.concat(taicpu.op_sym(A_BL,objectlibrary.newasmsymbol(s)));
  201. if target_info.system=system_powerpc_macos then
  202. list.concat(taicpu.op_none(A_NOP));
  203. procinfo.flags:=procinfo.flags or pi_do_call;
  204. end;
  205. { calling a procedure by address }
  206. procedure tcgppc.a_call_reg(list : taasmoutput;reg: tregister);
  207. var
  208. tmpreg : tregister;
  209. tmpref : treference;
  210. begin
  211. if target_info.system=system_powerpc_macos then
  212. begin
  213. {Generate instruction to load the procedure address from
  214. the transition vector.}
  215. //TODO: Support cross-TOC calls.
  216. tmpreg := get_scratch_reg_int(list,OS_INT);
  217. reference_reset(tmpref);
  218. tmpref.offset := 0;
  219. //tmpref.symaddr := refs_full;
  220. tmpref.base:= reg;
  221. list.concat(taicpu.op_reg_ref(A_LWZ,tmpreg,tmpref));
  222. list.concat(taicpu.op_reg(A_MTCTR,tmpreg));
  223. free_scratch_reg(list,tmpreg);
  224. end
  225. else
  226. list.concat(taicpu.op_reg(A_MTCTR,reg));
  227. list.concat(taicpu.op_none(A_BCTRL));
  228. //if target_info.system=system_powerpc_macos then
  229. // //NOP is not needed here.
  230. // list.concat(taicpu.op_none(A_NOP));
  231. procinfo.flags:=procinfo.flags or pi_do_call;
  232. //list.concat(tai_comment.create(strpnew('***** a_call_reg')));
  233. end;
  234. { calling a procedure by address }
  235. procedure tcgppc.a_call_ref(list : taasmoutput;const ref : treference);
  236. var
  237. tmpreg : tregister;
  238. tmpref : treference;
  239. begin
  240. tmpreg := get_scratch_reg_int(list,OS_ADDR);
  241. a_load_ref_reg(list,OS_ADDR,ref,tmpreg);
  242. if target_info.system=system_powerpc_macos then
  243. begin
  244. {Generate instruction to load the procedure address from
  245. the transition vector.}
  246. //TODO: Support cross-TOC calls.
  247. reference_reset(tmpref);
  248. tmpref.offset := 0;
  249. //tmpref.symaddr := refs_full;
  250. tmpref.base:= tmpreg;
  251. list.concat(taicpu.op_reg_ref(A_LWZ,tmpreg,tmpref));
  252. end;
  253. list.concat(taicpu.op_reg(A_MTCTR,tmpreg));
  254. free_scratch_reg(list,tmpreg);
  255. list.concat(taicpu.op_none(A_BCTRL));
  256. //if target_info.system=system_powerpc_macos then
  257. // //NOP is not needed here.
  258. // list.concat(taicpu.op_none(A_NOP));
  259. procinfo.flags:=procinfo.flags or pi_do_call;
  260. //list.concat(tai_comment.create(strpnew('***** a_call_ref')));
  261. end;
  262. {********************** load instructions ********************}
  263. procedure tcgppc.a_load_const_reg(list : taasmoutput; size: TCGSize; a : aword; reg : TRegister);
  264. begin
  265. if not(size in [OS_8,OS_S8,OS_16,OS_S16,OS_32,OS_S32]) then
  266. internalerror(2002090902);
  267. if (longint(a) >= low(smallint)) and
  268. (longint(a) <= high(smallint)) then
  269. list.concat(taicpu.op_reg_const(A_LI,reg,smallint(a)))
  270. else if ((a and $ffff) <> 0) then
  271. begin
  272. list.concat(taicpu.op_reg_const(A_LI,reg,smallint(a and $ffff)));
  273. if ((a shr 16) <> 0) or
  274. (smallint(a and $ffff) < 0) then
  275. list.concat(taicpu.op_reg_reg_const(A_ADDIS,reg,reg,
  276. smallint((a shr 16)+ord(smallint(a and $ffff) < 0))))
  277. end
  278. else
  279. list.concat(taicpu.op_reg_const(A_LIS,reg,smallint(a shr 16)));
  280. end;
  281. procedure tcgppc.a_load_reg_ref(list : taasmoutput; size: TCGSize; reg : tregister;const ref : treference);
  282. const
  283. StoreInstr: Array[OS_8..OS_32,boolean, boolean] of TAsmOp =
  284. { indexed? updating?}
  285. (((A_STB,A_STBU),(A_STBX,A_STBUX)),
  286. ((A_STH,A_STHU),(A_STHX,A_STHUX)),
  287. ((A_STW,A_STWU),(A_STWX,A_STWUX)));
  288. var
  289. op: TAsmOp;
  290. ref2: TReference;
  291. freereg: boolean;
  292. begin
  293. ref2 := ref;
  294. freereg := fixref(list,ref2);
  295. if size in [OS_S8..OS_S16] then
  296. { storing is the same for signed and unsigned values }
  297. size := tcgsize(ord(size)-(ord(OS_S8)-ord(OS_8)));
  298. { 64 bit stuff should be handled separately }
  299. if size in [OS_64,OS_S64] then
  300. internalerror(200109236);
  301. op := storeinstr[tcgsize2unsigned[size],ref2.index.number<>NR_NO,false];
  302. a_load_store(list,op,reg,ref2);
  303. if freereg then
  304. cg.free_scratch_reg(list,ref2.base);
  305. End;
  306. procedure tcgppc.a_load_ref_reg(list : taasmoutput;size : tcgsize;const ref: treference;reg : tregister);
  307. const
  308. LoadInstr: Array[OS_8..OS_S32,boolean, boolean] of TAsmOp =
  309. { indexed? updating?}
  310. (((A_LBZ,A_LBZU),(A_LBZX,A_LBZUX)),
  311. ((A_LHZ,A_LHZU),(A_LHZX,A_LHZUX)),
  312. ((A_LWZ,A_LWZU),(A_LWZX,A_LWZUX)),
  313. { 64bit stuff should be handled separately }
  314. ((A_NONE,A_NONE),(A_NONE,A_NONE)),
  315. { there's no load-byte-with-sign-extend :( }
  316. ((A_LBZ,A_LBZU),(A_LBZX,A_LBZUX)),
  317. ((A_LHA,A_LHAU),(A_LHAX,A_LHAUX)),
  318. ((A_LWZ,A_LWZU),(A_LWZX,A_LWZUX)));
  319. var
  320. op: tasmop;
  321. tmpreg: tregister;
  322. ref2, tmpref: treference;
  323. freereg: boolean;
  324. begin
  325. if not(size in [OS_8,OS_S8,OS_16,OS_S16,OS_32,OS_S32]) then
  326. internalerror(2002090902);
  327. ref2 := ref;
  328. freereg := fixref(list,ref2);
  329. op := loadinstr[size,ref2.index.number<>NR_NO,false];
  330. a_load_store(list,op,reg,ref2);
  331. if freereg then
  332. free_scratch_reg(list,ref2.base);
  333. { sign extend shortint if necessary, since there is no }
  334. { load instruction that does that automatically (JM) }
  335. if size = OS_S8 then
  336. list.concat(taicpu.op_reg_reg(A_EXTSB,reg,reg));
  337. end;
  338. procedure tcgppc.a_load_reg_reg(list : taasmoutput;fromsize, tosize : tcgsize;reg1,reg2 : tregister);
  339. begin
  340. if (reg1.enum<>R_INTREGISTER) or (reg1.number = 0) then
  341. internalerror(200303101);
  342. if (reg2.enum<>R_INTREGISTER) or (reg2.number = 0) then
  343. internalerror(200303102);
  344. if (reg1.number<>reg2.number) or
  345. (tcgsize2size[tosize] < tcgsize2size[fromsize]) or
  346. ((tcgsize2size[tosize] = tcgsize2size[fromsize]) and
  347. (tosize <> fromsize) and
  348. not(fromsize in [OS_32,OS_S32])) then
  349. begin
  350. case fromsize of
  351. OS_8:
  352. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,
  353. reg2,reg1,0,31-8+1,31));
  354. OS_S8:
  355. list.concat(taicpu.op_reg_reg(A_EXTSB,reg2,reg1));
  356. OS_16:
  357. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,
  358. reg2,reg1,0,31-16+1,31));
  359. OS_S16:
  360. list.concat(taicpu.op_reg_reg(A_EXTSH,reg2,reg1));
  361. OS_32,OS_S32:
  362. list.concat(taicpu.op_reg_reg(A_MR,reg2,reg1));
  363. else internalerror(2002090901);
  364. end;
  365. end;
  366. end;
  367. procedure tcgppc.a_loadfpu_reg_reg(list: taasmoutput; reg1, reg2: tregister);
  368. begin
  369. list.concat(taicpu.op_reg_reg(A_FMR,reg2,reg1));
  370. end;
  371. procedure tcgppc.a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister);
  372. const
  373. FpuLoadInstr: Array[OS_F32..OS_F64,boolean, boolean] of TAsmOp =
  374. { indexed? updating?}
  375. (((A_LFS,A_LFSU),(A_LFSX,A_LFSUX)),
  376. ((A_LFD,A_LFDU),(A_LFDX,A_LFDUX)));
  377. var
  378. op: tasmop;
  379. ref2: treference;
  380. freereg: boolean;
  381. begin
  382. { several functions call this procedure with OS_32 or OS_64 }
  383. { so this makes life easier (FK) }
  384. case size of
  385. OS_32,OS_F32:
  386. size:=OS_F32;
  387. OS_64,OS_F64,OS_C64:
  388. size:=OS_F64;
  389. else
  390. internalerror(200201121);
  391. end;
  392. ref2 := ref;
  393. freereg := fixref(list,ref2);
  394. op := fpuloadinstr[size,ref2.index.number <> NR_NO,false];
  395. a_load_store(list,op,reg,ref2);
  396. if freereg then
  397. cg.free_scratch_reg(list,ref2.base);
  398. end;
  399. procedure tcgppc.a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference);
  400. const
  401. FpuStoreInstr: Array[OS_F32..OS_F64,boolean, boolean] of TAsmOp =
  402. { indexed? updating?}
  403. (((A_STFS,A_STFSU),(A_STFSX,A_STFSUX)),
  404. ((A_STFD,A_STFDU),(A_STFDX,A_STFDUX)));
  405. var
  406. op: tasmop;
  407. ref2: treference;
  408. freereg: boolean;
  409. begin
  410. if not(size in [OS_F32,OS_F64]) then
  411. internalerror(200201122);
  412. ref2 := ref;
  413. freereg := fixref(list,ref2);
  414. op := fpustoreinstr[size,ref2.index.number <> NR_NO,false];
  415. a_load_store(list,op,reg,ref2);
  416. if freereg then
  417. cg.free_scratch_reg(list,ref2.base);
  418. end;
  419. procedure tcgppc.a_op_const_reg(list : taasmoutput; Op: TOpCG; a: AWord; reg: TRegister);
  420. var
  421. scratch_register: TRegister;
  422. begin
  423. a_op_const_reg_reg(list,op,OS_32,a,reg,reg);
  424. end;
  425. procedure tcgppc.a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; src, dst: TRegister);
  426. begin
  427. a_op_reg_reg_reg(list,op,OS_32,src,dst,dst);
  428. end;
  429. procedure tcgppc.a_op_const_reg_reg(list: taasmoutput; op: TOpCg;
  430. size: tcgsize; a: aword; src, dst: tregister);
  431. var
  432. l1,l2: longint;
  433. oplo, ophi: tasmop;
  434. scratchreg: tregister;
  435. useReg, gotrlwi: boolean;
  436. procedure do_lo_hi;
  437. begin
  438. list.concat(taicpu.op_reg_reg_const(oplo,dst,src,word(a)));
  439. list.concat(taicpu.op_reg_reg_const(ophi,dst,dst,word(a shr 16)));
  440. end;
  441. begin
  442. if src.enum<>R_INTREGISTER then
  443. internalerror(200303102);
  444. if op = OP_SUB then
  445. begin
  446. {$ifopt q+}
  447. {$q-}
  448. {$define overflowon}
  449. {$endif}
  450. a_op_const_reg_reg(list,OP_ADD,size,aword(-a),src,dst);
  451. {$ifdef overflowon}
  452. {$q+}
  453. {$undef overflowon}
  454. {$endif}
  455. exit;
  456. end;
  457. ophi := TOpCG2AsmOpConstHi[op];
  458. oplo := TOpCG2AsmOpConstLo[op];
  459. gotrlwi := get_rlwi_const(a,l1,l2);
  460. if (op in [OP_AND,OP_OR,OP_XOR]) then
  461. begin
  462. if (a = 0) then
  463. begin
  464. if op = OP_AND then
  465. list.concat(taicpu.op_reg_const(A_LI,dst,0));
  466. exit;
  467. end
  468. else if (a = high(aword)) then
  469. begin
  470. case op of
  471. OP_OR:
  472. list.concat(taicpu.op_reg_const(A_LI,dst,-1));
  473. OP_XOR:
  474. list.concat(taicpu.op_reg_reg(A_NOT,dst,src));
  475. end;
  476. exit;
  477. end
  478. else if (a <= high(word)) and
  479. ((op <> OP_AND) or
  480. not gotrlwi) then
  481. begin
  482. list.concat(taicpu.op_reg_reg_const(oplo,dst,src,word(a)));
  483. exit;
  484. end;
  485. { all basic constant instructions also have a shifted form that }
  486. { works only on the highest 16bits, so if lo(a) is 0, we can }
  487. { use that one }
  488. if (word(a) = 0) and
  489. (not(op = OP_AND) or
  490. not gotrlwi) then
  491. begin
  492. list.concat(taicpu.op_reg_reg_const(ophi,dst,src,word(a shr 16)));
  493. exit;
  494. end;
  495. end
  496. else if (op = OP_ADD) then
  497. if a = 0 then
  498. exit
  499. else if (longint(a) >= low(smallint)) and
  500. (longint(a) <= high(smallint)) then
  501. begin
  502. list.concat(taicpu.op_reg_reg_const(A_ADDI,dst,src,smallint(a)));
  503. exit;
  504. end;
  505. { otherwise, the instructions we can generate depend on the }
  506. { operation }
  507. useReg := false;
  508. case op of
  509. OP_DIV,OP_IDIV:
  510. if (a = 0) then
  511. internalerror(200208103)
  512. else if (a = 1) then
  513. begin
  514. a_load_reg_reg(list,OS_INT,OS_INT,src,dst);
  515. exit
  516. end
  517. else if ispowerof2(a,l1) then
  518. begin
  519. case op of
  520. OP_DIV:
  521. list.concat(taicpu.op_reg_reg_const(A_SRWI,dst,src,l1));
  522. OP_IDIV:
  523. begin
  524. list.concat(taicpu.op_reg_reg_const(A_SRAWI,dst,src,l1));
  525. list.concat(taicpu.op_reg_reg(A_ADDZE,dst,dst));
  526. end;
  527. end;
  528. exit;
  529. end
  530. else
  531. usereg := true;
  532. OP_IMUL, OP_MUL:
  533. if (a = 0) then
  534. begin
  535. list.concat(taicpu.op_reg_const(A_LI,dst,0));
  536. exit
  537. end
  538. else if (a = 1) then
  539. begin
  540. a_load_reg_reg(list,OS_INT,OS_INT,src,dst);
  541. exit
  542. end
  543. else if ispowerof2(a,l1) then
  544. list.concat(taicpu.op_reg_reg_const(A_SLWI,dst,src,l1))
  545. else if (longint(a) >= low(smallint)) and
  546. (longint(a) <= high(smallint)) then
  547. list.concat(taicpu.op_reg_reg_const(A_MULLI,dst,src,smallint(a)))
  548. else
  549. usereg := true;
  550. OP_ADD:
  551. begin
  552. list.concat(taicpu.op_reg_reg_const(oplo,dst,src,smallint(a)));
  553. list.concat(taicpu.op_reg_reg_const(ophi,dst,dst,
  554. smallint((a shr 16) + ord(smallint(a) < 0))));
  555. end;
  556. OP_OR:
  557. { try to use rlwimi }
  558. if gotrlwi and
  559. (src.number = dst.number) then
  560. begin
  561. scratchreg := get_scratch_reg_int(list,OS_INT);
  562. list.concat(taicpu.op_reg_const(A_LI,scratchreg,-1));
  563. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWIMI,dst,
  564. scratchreg,0,l1,l2));
  565. free_scratch_reg(list,scratchreg);
  566. end
  567. else
  568. do_lo_hi;
  569. OP_AND:
  570. { try to use rlwinm }
  571. if gotrlwi then
  572. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,dst,
  573. src,0,l1,l2))
  574. else
  575. useReg := true;
  576. OP_XOR:
  577. do_lo_hi;
  578. OP_SHL,OP_SHR,OP_SAR:
  579. begin
  580. if (a and 31) <> 0 Then
  581. list.concat(taicpu.op_reg_reg_const(
  582. TOpCG2AsmOpConstLo[Op],dst,src,a and 31));
  583. if (a shr 5) <> 0 then
  584. internalError(68991);
  585. end
  586. else
  587. internalerror(200109091);
  588. end;
  589. { if all else failed, load the constant in a register and then }
  590. { perform the operation }
  591. if useReg then
  592. begin
  593. scratchreg := get_scratch_reg_int(list,OS_INT);
  594. a_load_const_reg(list,OS_32,a,scratchreg);
  595. a_op_reg_reg_reg(list,op,OS_32,scratchreg,src,dst);
  596. free_scratch_reg(list,scratchreg);
  597. end;
  598. end;
  599. procedure tcgppc.a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;
  600. size: tcgsize; src1, src2, dst: tregister);
  601. const
  602. op_reg_reg_opcg2asmop: array[TOpCG] of tasmop =
  603. (A_NONE,A_ADD,A_AND,A_DIVWU,A_DIVW,A_MULLW,A_MULLW,A_NEG,A_NOT,A_OR,
  604. A_SRAW,A_SLW,A_SRW,A_SUB,A_XOR);
  605. begin
  606. case op of
  607. OP_NEG,OP_NOT:
  608. list.concat(taicpu.op_reg_reg(op_reg_reg_opcg2asmop[op],dst,dst));
  609. else
  610. list.concat(taicpu.op_reg_reg_reg(op_reg_reg_opcg2asmop[op],dst,src2,src1));
  611. end;
  612. end;
  613. {*************** compare instructructions ****************}
  614. procedure tcgppc.a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;reg : tregister;
  615. l : tasmlabel);
  616. var
  617. p: taicpu;
  618. scratch_register: TRegister;
  619. signed: boolean;
  620. r:Tregister;
  621. begin
  622. signed := cmp_op in [OC_GT,OC_LT,OC_GTE,OC_LTE];
  623. { in the following case, we generate more efficient code when }
  624. { signed is true }
  625. if (cmp_op in [OC_EQ,OC_NE]) and
  626. (a > $ffff) then
  627. signed := true;
  628. r.enum:=R_CR0;
  629. if signed then
  630. if (longint(a) >= low(smallint)) and (longint(a) <= high(smallint)) Then
  631. list.concat(taicpu.op_reg_reg_const(A_CMPWI,r,reg,longint(a)))
  632. else
  633. begin
  634. scratch_register := get_scratch_reg_int(list,OS_INT);
  635. a_load_const_reg(list,OS_32,a,scratch_register);
  636. list.concat(taicpu.op_reg_reg_reg(A_CMPW,r,reg,scratch_register));
  637. free_scratch_reg(list,scratch_register);
  638. end
  639. else
  640. if (a <= $ffff) then
  641. list.concat(taicpu.op_reg_reg_const(A_CMPLWI,r,reg,a))
  642. else
  643. begin
  644. scratch_register := get_scratch_reg_int(list,OS_32);
  645. a_load_const_reg(list,OS_32,a,scratch_register);
  646. list.concat(taicpu.op_reg_reg_reg(A_CMPLW,r,reg,scratch_register));
  647. free_scratch_reg(list,scratch_register);
  648. end;
  649. a_jmp(list,A_BC,TOpCmp2AsmCond[cmp_op],0,l);
  650. end;
  651. procedure tcgppc.a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;
  652. reg1,reg2 : tregister;l : tasmlabel);
  653. var
  654. p: taicpu;
  655. op: tasmop;
  656. r:Tregister;
  657. begin
  658. if cmp_op in [OC_GT,OC_LT,OC_GTE,OC_LTE] then
  659. op := A_CMPW
  660. else op := A_CMPLW;
  661. r.enum:=R_CR0;
  662. list.concat(taicpu.op_reg_reg_reg(op,r,reg1,reg2));
  663. a_jmp(list,A_BC,TOpCmp2AsmCond[cmp_op],0,l);
  664. end;
  665. procedure tcgppc.g_save_standard_registers(list : taasmoutput; usedinproc : Tsupregset);
  666. begin
  667. {$warning FIX ME}
  668. end;
  669. procedure tcgppc.g_restore_standard_registers(list : taasmoutput; usedinproc : Tsupregset);
  670. begin
  671. {$warning FIX ME}
  672. end;
  673. procedure tcgppc.g_save_all_registers(list : taasmoutput);
  674. begin
  675. {$warning FIX ME}
  676. end;
  677. procedure tcgppc.g_restore_all_registers(list : taasmoutput;selfused,accused,acchiused:boolean);
  678. begin
  679. {$warning FIX ME}
  680. end;
  681. procedure tcgppc.a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel);
  682. begin
  683. a_jmp(list,A_BC,TOpCmp2AsmCond[cond],0,l);
  684. end;
  685. procedure tcgppc.a_jmp_always(list : taasmoutput;l: tasmlabel);
  686. begin
  687. a_jmp(list,A_B,C_None,0,l);
  688. end;
  689. procedure tcgppc.a_jmp_flags(list : taasmoutput;const f : TResFlags;l: tasmlabel);
  690. var
  691. c: tasmcond;
  692. r:Tregister;
  693. begin
  694. c := flags_to_cond(f);
  695. r.enum:=R_CR0;
  696. a_jmp(list,A_BC,c.cond,ord(c.cr)-ord(r.enum),l);
  697. end;
  698. procedure tcgppc.g_flags2reg(list: taasmoutput; size: TCgSize; const f: TResFlags; reg: TRegister);
  699. var
  700. testbit: byte;
  701. bitvalue: boolean;
  702. begin
  703. { get the bit to extract from the conditional register + its }
  704. { requested value (0 or 1) }
  705. testbit := ((ord(f.cr)-ord(R_CR0)) * 4);
  706. case f.flag of
  707. F_EQ,F_NE:
  708. bitvalue := f.flag = F_EQ;
  709. F_LT,F_GE:
  710. begin
  711. inc(testbit);
  712. bitvalue := f.flag = F_LT;
  713. end;
  714. F_GT,F_LE:
  715. begin
  716. inc(testbit,2);
  717. bitvalue := f.flag = F_GT;
  718. end;
  719. else
  720. internalerror(200112261);
  721. end;
  722. { load the conditional register in the destination reg }
  723. list.concat(taicpu.op_reg(A_MFCR,reg));
  724. { we will move the bit that has to be tested to bit 0 by rotating }
  725. { left }
  726. testbit := (32 - testbit) and 31;
  727. { extract bit }
  728. list.concat(taicpu.op_reg_reg_const_const_const(
  729. A_RLWINM,reg,reg,testbit,31,31));
  730. { if we need the inverse, xor with 1 }
  731. if not bitvalue then
  732. list.concat(taicpu.op_reg_reg_const(A_XORI,reg,reg,1));
  733. end;
  734. (*
  735. procedure tcgppc.g_cond2reg(list: taasmoutput; const f: TAsmCond; reg: TRegister);
  736. var
  737. testbit: byte;
  738. bitvalue: boolean;
  739. begin
  740. { get the bit to extract from the conditional register + its }
  741. { requested value (0 or 1) }
  742. case f.simple of
  743. false:
  744. begin
  745. { we don't generate this in the compiler }
  746. internalerror(200109062);
  747. end;
  748. true:
  749. case f.cond of
  750. C_None:
  751. internalerror(200109063);
  752. C_LT..C_NU:
  753. begin
  754. testbit := (ord(f.cr) - ord(R_CR0))*4;
  755. inc(testbit,AsmCondFlag2BI[f.cond]);
  756. bitvalue := AsmCondFlagTF[f.cond];
  757. end;
  758. C_T,C_F,C_DNZT,C_DNZF,C_DZT,C_DZF:
  759. begin
  760. testbit := f.crbit
  761. bitvalue := AsmCondFlagTF[f.cond];
  762. end;
  763. else
  764. internalerror(200109064);
  765. end;
  766. end;
  767. { load the conditional register in the destination reg }
  768. list.concat(taicpu.op_reg_reg(A_MFCR,reg));
  769. { we will move the bit that has to be tested to bit 31 -> rotate }
  770. { left by bitpos+1 (remember, this is big-endian!) }
  771. if bitpos <> 31 then
  772. inc(bitpos)
  773. else
  774. bitpos := 0;
  775. { extract bit }
  776. list.concat(taicpu.op_reg_reg_const_const_const(
  777. A_RLWINM,reg,reg,bitpos,31,31));
  778. { if we need the inverse, xor with 1 }
  779. if not bitvalue then
  780. list.concat(taicpu.op_reg_reg_const(A_XORI,reg,reg,1));
  781. end;
  782. *)
  783. { *********** entry/exit code and address loading ************ }
  784. procedure tcgppc.g_stackframe_entry(list : taasmoutput;localsize : longint);
  785. begin
  786. { if you program in assembler, you have to take care of everything }
  787. { yourself. Some things just don't work otherwise (e.g. the linux }
  788. { syscall code) (JM) }
  789. if (po_assembler in aktprocdef.procoptions) then
  790. exit;
  791. case target_info.system of
  792. system_powerpc_macos:
  793. g_stackframe_entry_mac(list,localsize);
  794. system_powerpc_linux:
  795. g_stackframe_entry_sysv(list,localsize)
  796. else
  797. internalerror(2204001);
  798. end;
  799. end;
  800. procedure tcgppc.g_return_from_proc(list : taasmoutput;parasize : aword);
  801. begin
  802. { if you program in assembler, you have to take care of everything }
  803. { yourself. Some things just don't work otherwise (e.g. the linux }
  804. { syscall code) (JM) }
  805. if (po_assembler in aktprocdef.procoptions) then
  806. begin
  807. list.concat(taicpu.op_none(A_BLR));
  808. exit;
  809. end;
  810. case target_info.system of
  811. system_powerpc_macos:
  812. g_return_from_proc_mac(list,parasize);
  813. system_powerpc_linux:
  814. g_return_from_proc_sysv(list,parasize)
  815. else
  816. internalerror(2204001);
  817. end;
  818. end;
  819. procedure tcgppc.g_stackframe_entry_sysv(list : taasmoutput;localsize : longint);
  820. { generated the entry code of a procedure/function. Note: localsize is the }
  821. { sum of the size necessary for local variables and the maximum possible }
  822. { combined size of ALL the parameters of a procedure called by the current }
  823. { one }
  824. var regcounter,firstregfpu,firstreggpr: TRegister;
  825. href : treference;
  826. usesfpr,usesgpr,gotgot : boolean;
  827. parastart : aword;
  828. offset : aword;
  829. r,r2,rsp:Tregister;
  830. regcounter2: Tsuperregister;
  831. begin
  832. { we do our own localsize calculation }
  833. localsize:=0;
  834. { CR and LR only have to be saved in case they are modified by the current }
  835. { procedure, but currently this isn't checked, so save them always }
  836. { following is the entry code as described in "Altivec Programming }
  837. { Interface Manual", bar the saving of AltiVec registers }
  838. rsp.enum:=R_INTREGISTER;
  839. rsp.number:=NR_STACK_POINTER_REG;;
  840. a_reg_alloc(list,rsp);
  841. r.enum:=R_INTREGISTER;
  842. r.number:=NR_R0;
  843. a_reg_alloc(list,r);
  844. { allocate registers containing reg parameters }
  845. r.enum := R_INTREGISTER;
  846. for regcounter2 := RS_R3 to RS_R10 do
  847. begin
  848. r.number:=regcounter2 shl 8;
  849. a_reg_alloc(list,r);
  850. end;
  851. usesfpr:=false;
  852. for regcounter.enum:=R_F14 to R_F31 do
  853. if regcounter.enum in rg.usedbyproc then
  854. begin
  855. usesfpr:=true;
  856. firstregfpu:=regcounter;
  857. break;
  858. end;
  859. usesgpr:=false;
  860. for regcounter2:=RS_R14 to RS_R31 do
  861. begin
  862. if regcounter2 in rg.usedintbyproc then
  863. begin
  864. usesgpr:=true;
  865. firstreggpr.enum := R_INTREGISTER;
  866. firstreggpr.number := regcounter2 shl 8;
  867. break;
  868. end;
  869. end;
  870. { save link register? }
  871. if (procinfo.flags and pi_do_call)<>0 then
  872. begin
  873. { save return address... }
  874. r.enum:=R_INTREGISTER;
  875. r.number:=NR_R0;
  876. list.concat(taicpu.op_reg(A_MFLR,r));
  877. { ... in caller's rframe }
  878. reference_reset_base(href,rsp,4);
  879. list.concat(taicpu.op_reg_ref(A_STW,r,href));
  880. a_reg_dealloc(list,r);
  881. end;
  882. if usesfpr or usesgpr then
  883. begin
  884. r.enum:=R_INTREGISTER;
  885. r.number:=NR_R11;
  886. a_reg_alloc(list,r);
  887. { save end of fpr save area }
  888. list.concat(taicpu.op_reg_reg(A_MR,r,rsp));
  889. end;
  890. { calculate the size of the locals }
  891. if usesgpr then
  892. inc(localsize,((NR_R31-firstreggpr.number) shr 8+1)*4);
  893. if usesfpr then
  894. inc(localsize,(ord(R_F31)-ord(firstregfpu.enum)+1)*8);
  895. { align to 16 bytes }
  896. localsize:=align(localsize,16);
  897. inc(localsize,tg.lasttemp);
  898. localsize:=align(localsize,16);
  899. tppcprocinfo(procinfo).localsize:=localsize;
  900. r.enum:=R_INTREGISTER;
  901. r.number:=NR_STACK_POINTER_REG;
  902. reference_reset_base(href,r,-localsize);
  903. a_load_store(list,A_STWU,r,href);
  904. { no GOT pointer loaded yet }
  905. gotgot:=false;
  906. if usesfpr then
  907. begin
  908. { save floating-point registers
  909. if (cs_create_pic in aktmoduleswitches) and not(usesgpr) then
  910. begin
  911. a_call_name(objectlibrary.newasmsymbol('_savefpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14)+'_g');
  912. gotgot:=true;
  913. end
  914. else
  915. a_call_name(objectlibrary.newasmsymbol('_savefpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14));
  916. }
  917. for regcounter.enum:=firstregfpu.enum to R_F31 do
  918. if regcounter.enum in rg.usedbyproc then
  919. begin
  920. { reference_reset_base(href,R_1,-localsize);
  921. a_load_store(list,A_STWU,R_1,href);
  922. }
  923. end;
  924. { compute end of gpr save area }
  925. r.enum:=R_INTREGISTER;
  926. r.number:=NR_R11;
  927. list.concat(taicpu.op_reg_reg_const(A_ADDI,r,r,-(ord(R_F31)-ord(firstregfpu.enum)+1)*8));
  928. end;
  929. { save gprs and fetch GOT pointer }
  930. if usesgpr then
  931. begin
  932. {
  933. if cs_create_pic in aktmoduleswitches then
  934. begin
  935. a_call_name(objectlibrary.newasmsymbol('_savegpr_'+tostr(ord(firstreggpr)-ord(R_14)+14)+'_g');
  936. gotgot:=true;
  937. end
  938. else
  939. a_call_name(objectlibrary.newasmsymbol('_savegpr_'+tostr(ord(firstreggpr)-ord(R_14)+14))
  940. }
  941. r.enum:=R_INTREGISTER;
  942. r.number:=NR_R11;
  943. reference_reset_base(href,r,-((NR_R31-firstreggpr.number) shr 8+1)*4);
  944. list.concat(taicpu.op_reg_ref(A_STMW,firstreggpr,href));
  945. end;
  946. r.enum:=R_INTREGISTER;
  947. r.number:=NR_R11;
  948. if usesfpr or usesgpr then
  949. a_reg_dealloc(list,r);
  950. { PIC code support, }
  951. if cs_create_pic in aktmoduleswitches then
  952. begin
  953. { if we didn't get the GOT pointer till now, we've to calculate it now }
  954. if not(gotgot) then
  955. begin
  956. {!!!!!!!!!!!!!}
  957. end;
  958. r.enum:=R_INTREGISTER;
  959. r.number:=NR_R31;
  960. r2.enum:=R_LR;
  961. a_reg_alloc(list,r);
  962. { place GOT ptr in r31 }
  963. list.concat(taicpu.op_reg_reg(A_MFSPR,r,r2));
  964. end;
  965. { save the CR if necessary ( !!! always done currently ) }
  966. { still need to find out where this has to be done for SystemV
  967. a_reg_alloc(list,R_0);
  968. list.concat(taicpu.op_reg_reg(A_MFSPR,R_0,R_CR);
  969. list.concat(taicpu.op_reg_ref(A_STW,scratch_register,
  970. new_reference(STACK_POINTER_REG,LA_CR)));
  971. a_reg_dealloc(list,R_0); }
  972. { now comes the AltiVec context save, not yet implemented !!! }
  973. end;
  974. procedure tcgppc.g_return_from_proc_sysv(list : taasmoutput;parasize : aword);
  975. var
  976. regcounter,firstregfpu,firstreggpr: TRegister;
  977. href : treference;
  978. usesfpr,usesgpr,genret : boolean;
  979. r,r2:Tregister;
  980. regcounter2:Tsuperregister;
  981. begin
  982. { release parameter registers }
  983. r.enum := R_INTREGISTER;
  984. for regcounter2 := RS_R3 to RS_R10 do
  985. begin
  986. r.number:=regcounter2 shl 8;
  987. a_reg_dealloc(list,r);
  988. end;
  989. { AltiVec context restore, not yet implemented !!! }
  990. usesfpr:=false;
  991. for regcounter.enum:=R_F14 to R_F31 do
  992. if regcounter.enum in rg.usedbyproc then
  993. begin
  994. usesfpr:=true;
  995. firstregfpu:=regcounter;
  996. break;
  997. end;
  998. usesgpr:=false;
  999. for regcounter2:=RS_R14 to RS_R30 do
  1000. begin
  1001. if regcounter2 in rg.usedintbyproc then
  1002. begin
  1003. usesgpr:=true;
  1004. firstreggpr.enum:=R_INTREGISTER;
  1005. firstreggpr.number:=regcounter2 shl 8;
  1006. break;
  1007. end;
  1008. end;
  1009. { no return (blr) generated yet }
  1010. genret:=true;
  1011. if usesgpr then
  1012. begin
  1013. { address of gpr save area to r11 }
  1014. r.enum:=R_INTREGISTER;
  1015. r.number:=NR_STACK_POINTER_REG;
  1016. r2.enum:=R_INTREGISTER;
  1017. r2.number:=NR_R11;
  1018. if usesfpr then
  1019. list.concat(taicpu.op_reg_reg_const(A_ADDI,r2,r,tppcprocinfo(procinfo).localsize-(ord(R_F31)-ord(firstregfpu.enum)+1)*8))
  1020. else
  1021. list.concat(taicpu.op_reg_reg_const(A_ADDI,r2,r,tppcprocinfo(procinfo).localsize));
  1022. { restore gprs }
  1023. { at least for now we use LMW }
  1024. {
  1025. a_call_name(objectlibrary.newasmsymbol('_restgpr_14');
  1026. }
  1027. reference_reset_base(href,r2,-((NR_R31-ord(firstreggpr.number)) shr 8+1)*4);
  1028. list.concat(taicpu.op_reg_ref(A_LMW,firstreggpr,href));
  1029. end;
  1030. { restore fprs and return }
  1031. if usesfpr then
  1032. begin
  1033. { address of fpr save area to r11 }
  1034. r.enum:=R_INTREGISTER;
  1035. r.number:=NR_R11;
  1036. list.concat(taicpu.op_reg_reg_const(A_ADDI,r,r,(ord(R_F31)-ord(firstregfpu.enum)+1)*8));
  1037. {
  1038. if (procinfo.flags and pi_do_call)<>0 then
  1039. a_call_name(objectlibrary.newasmsymbol('_restfpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14)+
  1040. '_x')
  1041. else
  1042. { leaf node => lr haven't to be restored }
  1043. a_call_name('_restfpr_'+tostr(ord(firstregfpu.enum)-ord(R_F14)+14)+
  1044. '_l');
  1045. genret:=false;
  1046. }
  1047. end;
  1048. { if we didn't generate the return code, we've to do it now }
  1049. if genret then
  1050. begin
  1051. { adjust r1 }
  1052. r.enum:=R_INTREGISTER;
  1053. r.number:=NR_R1;
  1054. a_op_const_reg(list,OP_ADD,tppcprocinfo(procinfo).localsize,r);
  1055. { load link register? }
  1056. if (procinfo.flags and pi_do_call)<>0 then
  1057. begin
  1058. r.enum:=R_INTREGISTER;
  1059. r.number:=NR_STACK_POINTER_REG;
  1060. reference_reset_base(href,r,4);
  1061. r.enum:=R_INTREGISTER;
  1062. r.number:=NR_R0;
  1063. list.concat(taicpu.op_reg_ref(A_LWZ,r,href));
  1064. list.concat(taicpu.op_reg(A_MTLR,r));
  1065. end;
  1066. list.concat(taicpu.op_none(A_BLR));
  1067. end;
  1068. end;
  1069. function save_regs(list : taasmoutput):longint;
  1070. {Generates code which saves used non-volatile registers in
  1071. the save area right below the address the stackpointer point to.
  1072. Returns the actual used save area size.}
  1073. var regcounter,firstregfpu,firstreggpr: TRegister;
  1074. usesfpr,usesgpr: boolean;
  1075. href : treference;
  1076. offset: integer;
  1077. r,r2:Tregister;
  1078. regcounter2: Tsuperregister;
  1079. begin
  1080. usesfpr:=false;
  1081. for regcounter.enum:=R_F14 to R_F31 do
  1082. if regcounter.enum in rg.usedbyproc then
  1083. begin
  1084. usesfpr:=true;
  1085. firstregfpu:=regcounter;
  1086. break;
  1087. end;
  1088. usesgpr:=false;
  1089. for regcounter2:=RS_R13 to RS_R31 do
  1090. begin
  1091. if regcounter2 in rg.usedintbyproc then
  1092. begin
  1093. usesgpr:=true;
  1094. firstreggpr.enum:=R_INTREGISTER;
  1095. firstreggpr.number:=regcounter2 shl 8;
  1096. break;
  1097. end;
  1098. end;
  1099. offset:= 0;
  1100. { save floating-point registers }
  1101. if usesfpr then
  1102. for regcounter.enum := firstregfpu.enum to R_F31 do
  1103. begin
  1104. offset:= offset - 8;
  1105. r.enum:=R_INTREGISTER;
  1106. r.number:=NR_STACK_POINTER_REG;
  1107. reference_reset_base(href, r, offset);
  1108. list.concat(taicpu.op_reg_ref(A_STFD, regcounter, href));
  1109. end;
  1110. (* Optimiztion in the future: a_call_name(list,'_savefXX'); *)
  1111. { save gprs in gpr save area }
  1112. if usesgpr then
  1113. if firstreggpr.enum < R_30 then
  1114. begin
  1115. offset:= offset - 4 * (ord(R_31) - ord(firstreggpr.enum) + 1);
  1116. r.enum:=R_INTREGISTER;
  1117. r.number:=NR_STACK_POINTER_REG;
  1118. reference_reset_base(href,r,offset);
  1119. list.concat(taicpu.op_reg_ref(A_STMW,firstreggpr,href));
  1120. {STMW stores multiple registers}
  1121. end
  1122. else
  1123. begin
  1124. r.enum:=R_INTREGISTER;
  1125. r.number:=NR_STACK_POINTER_REG;
  1126. r2 := firstreggpr;
  1127. convert_register_to_enum(firstreggpr);
  1128. for regcounter.enum := firstreggpr.enum to R_31 do
  1129. begin
  1130. offset:= offset - 4;
  1131. reference_reset_base(href, r, offset);
  1132. list.concat(taicpu.op_reg_ref(A_STW, r2, href));
  1133. inc(r2.number,NR_R1-NR_R0);
  1134. end;
  1135. end;
  1136. { now comes the AltiVec context save, not yet implemented !!! }
  1137. save_regs:= -offset;
  1138. end;
  1139. procedure restore_regs(list : taasmoutput);
  1140. {Generates code which restores used non-volatile registers from
  1141. the save area right below the address the stackpointer point to.}
  1142. var regcounter,firstregfpu,firstreggpr: TRegister;
  1143. usesfpr,usesgpr: boolean;
  1144. href : treference;
  1145. offset: integer;
  1146. r,r2:Tregister;
  1147. regcounter2: Tsuperregister;
  1148. begin
  1149. usesfpr:=false;
  1150. for regcounter.enum:=R_F14 to R_F31 do
  1151. if regcounter.enum in rg.usedbyproc then
  1152. begin
  1153. usesfpr:=true;
  1154. firstregfpu:=regcounter;
  1155. break;
  1156. end;
  1157. usesgpr:=false;
  1158. for regcounter2:=RS_R13 to RS_R31 do
  1159. begin
  1160. if regcounter2 in rg.usedintbyproc then
  1161. begin
  1162. usesgpr:=true;
  1163. firstreggpr.enum:=R_INTREGISTER;
  1164. firstreggpr.number:=regcounter2 shl 8;
  1165. break;
  1166. end;
  1167. inc(r.number,NR_R1-NR_R0);
  1168. end;
  1169. offset:= 0;
  1170. { restore fp registers }
  1171. if usesfpr then
  1172. for regcounter.enum := firstregfpu.enum to R_F31 do
  1173. begin
  1174. offset:= offset - 8;
  1175. r.enum:=R_INTREGISTER;
  1176. r.number:=NR_STACK_POINTER_REG;
  1177. reference_reset_base(href, r, offset);
  1178. list.concat(taicpu.op_reg_ref(A_LFD, regcounter, href));
  1179. end;
  1180. (* Optimiztion in the future: a_call_name(list,'_restfXX'); *)
  1181. { restore gprs }
  1182. if usesgpr then
  1183. if firstreggpr.enum < R_30 then
  1184. begin
  1185. offset:= offset - 4 * (ord(R_31) - ord(firstreggpr.enum) + 1);
  1186. r.enum:=R_INTREGISTER;
  1187. r.number:=NR_STACK_POINTER_REG;
  1188. reference_reset_base(href,r,offset); //-220
  1189. list.concat(taicpu.op_reg_ref(A_LMW,firstreggpr,href));
  1190. {LMW loads multiple registers}
  1191. end
  1192. else
  1193. begin
  1194. r.enum:=R_INTREGISTER;
  1195. r.number:=NR_STACK_POINTER_REG;
  1196. r2 := firstreggpr;
  1197. convert_register_to_enum(firstreggpr);
  1198. for regcounter.enum := firstreggpr.enum to R_31 do
  1199. begin
  1200. offset:= offset - 4;
  1201. reference_reset_base(href, r, offset);
  1202. list.concat(taicpu.op_reg_ref(A_LWZ, r2, href));
  1203. inc(r2.number,NR_R1-NR_R0);
  1204. end;
  1205. end;
  1206. { now comes the AltiVec context restore, not yet implemented !!! }
  1207. end;
  1208. procedure tcgppc.g_stackframe_entry_mac(list : taasmoutput;localsize : longint);
  1209. { generated the entry code of a procedure/function. Note: localsize is the }
  1210. { sum of the size necessary for local variables and the maximum possible }
  1211. { combined size of ALL the parameters of a procedure called by the current }
  1212. { one }
  1213. const
  1214. macosLinkageAreaSize = 24;
  1215. var regcounter: TRegister;
  1216. href : treference;
  1217. registerSaveAreaSize : longint;
  1218. r,r2,rsp:Tregister;
  1219. regcounter2: Tsuperregister;
  1220. begin
  1221. if (localsize mod 8) <> 0 then internalerror(58991);
  1222. { CR and LR only have to be saved in case they are modified by the current }
  1223. { procedure, but currently this isn't checked, so save them always }
  1224. { following is the entry code as described in "Altivec Programming }
  1225. { Interface Manual", bar the saving of AltiVec registers }
  1226. r.enum:=R_INTREGISTER;
  1227. r.number:=NR_R0;
  1228. rsp.enum:=R_INTREGISTER;
  1229. rsp.number:=NR_STACK_POINTER_REG;
  1230. a_reg_alloc(list,rsp);
  1231. a_reg_alloc(list,r);
  1232. { allocate registers containing reg parameters }
  1233. r.enum := R_INTREGISTER;
  1234. for regcounter2 := RS_R3 to RS_R10 do
  1235. begin
  1236. r.number:=regcounter2 shl 8;
  1237. a_reg_alloc(list,r);
  1238. end;
  1239. {TODO: Allocate fp and altivec parameter registers also}
  1240. { save return address in callers frame}
  1241. r2.enum:=R_LR;
  1242. list.concat(taicpu.op_reg_reg(A_MFSPR,r,r2));
  1243. { ... in caller's frame }
  1244. reference_reset_base(href,rsp,8);
  1245. list.concat(taicpu.op_reg_ref(A_STW,r,href));
  1246. a_reg_dealloc(list,r);
  1247. { save non-volatile registers in callers frame}
  1248. registerSaveAreaSize:= save_regs(list);
  1249. { save the CR if necessary in callers frame ( !!! always done currently ) }
  1250. a_reg_alloc(list,r);
  1251. r2.enum:=R_CR;
  1252. list.concat(taicpu.op_reg_reg(A_MFSPR,r,r2));
  1253. reference_reset_base(href,rsp,LA_CR);
  1254. list.concat(taicpu.op_reg_ref(A_STW,r,href));
  1255. a_reg_dealloc(list,r);
  1256. (*
  1257. { save pointer to incoming arguments }
  1258. list.concat(taicpu.op_reg_reg_const(A_ORI,R_31,STACK_POINTER_REG,0));
  1259. *)
  1260. (*
  1261. a_reg_alloc(list,R_12);
  1262. { 0 or 8 based on SP alignment }
  1263. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,
  1264. R_12,STACK_POINTER_REG,0,28,28));
  1265. { add in stack length }
  1266. list.concat(taicpu.op_reg_reg_const(A_SUBFIC,R_12,R_12,
  1267. -localsize));
  1268. { establish new alignment }
  1269. list.concat(taicpu.op_reg_reg_reg(A_STWUX,STACK_POINTER_REG,STACK_POINTER_REG,R_12));
  1270. a_reg_dealloc(list,R_12);
  1271. *)
  1272. { allocate stack frame }
  1273. localsize:= align(localsize + macosLinkageAreaSize + registerSaveAreaSize, 16);
  1274. inc(localsize,tg.lasttemp);
  1275. localsize:=align(localsize,16);
  1276. tppcprocinfo(procinfo).localsize:=localsize;
  1277. r.enum:=R_INTREGISTER;
  1278. r.number:=NR_STACK_POINTER_REG;
  1279. reference_reset_base(href,r,-localsize);
  1280. a_load_store(list,A_STWU,r,href);
  1281. { this also stores the old stack pointer in the new stack frame }
  1282. end;
  1283. procedure tcgppc.g_return_from_proc_mac(list : taasmoutput;parasize : aword);
  1284. var
  1285. regcounter: TRegister;
  1286. href : treference;
  1287. r,r2,rsp:Tregister;
  1288. regcounter2: Tsuperregister;
  1289. begin
  1290. { release parameter registers }
  1291. r.enum := R_INTREGISTER;
  1292. for regcounter2 := RS_R3 to RS_R10 do
  1293. begin
  1294. r.number := regcounter2 shl 8;
  1295. a_reg_dealloc(list,r);
  1296. end;
  1297. {TODO: Release fp and altivec parameter registers also}
  1298. r.enum:=R_INTREGISTER;
  1299. r.number:=NR_R0;
  1300. rsp.enum:=R_INTREGISTER;
  1301. rsp.number:=NR_STACK_POINTER_REG;
  1302. a_reg_alloc(list,r);
  1303. { restore stack pointer }
  1304. reference_reset_base(href,rsp,LA_SP);
  1305. list.concat(taicpu.op_reg_ref(A_LWZ,rsp,href));
  1306. (*
  1307. list.concat(taicpu.op_reg_reg_const(A_ORI,rsp,R_31,0));
  1308. *)
  1309. { restore the CR if necessary from callers frame
  1310. ( !!! always done currently ) }
  1311. reference_reset_base(href,rsp,LA_CR);
  1312. r.enum:=R_INTREGISTER;
  1313. r.number:=NR_R0;
  1314. list.concat(taicpu.op_reg_ref(A_LWZ,r,href));
  1315. r2.enum:=R_CR;
  1316. list.concat(taicpu.op_reg_reg(A_MTSPR,r,r2));
  1317. a_reg_dealloc(list,r);
  1318. (*
  1319. { restore return address from callers frame }
  1320. reference_reset_base(href,STACK_POINTER_REG,8);
  1321. list.concat(taicpu.op_reg_ref(A_LWZ,R_0,href));
  1322. *)
  1323. { restore non-volatile registers from callers frame }
  1324. restore_regs(list);
  1325. (*
  1326. { return to caller }
  1327. list.concat(taicpu.op_reg_reg(A_MTSPR,R_0,R_LR));
  1328. list.concat(taicpu.op_none(A_BLR));
  1329. *)
  1330. { restore return address from callers frame }
  1331. r.enum:=R_INTREGISTER;
  1332. r.number:=NR_R0;
  1333. r2.enum:=R_LR;
  1334. reference_reset_base(href,rsp,8);
  1335. list.concat(taicpu.op_reg_ref(A_LWZ,r,href));
  1336. { return to caller }
  1337. list.concat(taicpu.op_reg_reg(A_MTSPR,r,r2));
  1338. list.concat(taicpu.op_none(A_BLR));
  1339. end;
  1340. procedure tcgppc.g_restore_frame_pointer(list : taasmoutput);
  1341. begin
  1342. { no frame pointer on the PowerPC (maybe there is one in the SystemV ABI?)}
  1343. end;
  1344. procedure tcgppc.a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);
  1345. var
  1346. ref2, tmpref: treference;
  1347. freereg: boolean;
  1348. r2,tmpreg:Tregister;
  1349. begin
  1350. ref2 := ref;
  1351. freereg := fixref(list,ref2);
  1352. if assigned(ref2.symbol) then
  1353. begin
  1354. if target_info.system = system_powerpc_macos then
  1355. begin
  1356. if ref2.base.number <> NR_NO then
  1357. internalerror(2002103102); //TODO: Implement this if needed
  1358. if macos_direct_globals then
  1359. begin
  1360. reference_reset(tmpref);
  1361. tmpref.offset := ref2.offset;
  1362. tmpref.symbol := ref2.symbol;
  1363. tmpref.symaddr := refs_full;
  1364. tmpref.base.number := NR_NO;
  1365. r2.enum:=R_INTREGISTER;
  1366. r2.number:=NR_RTOC;
  1367. list.concat(taicpu.op_reg_reg_ref(A_ADDI,r,r2,tmpref));
  1368. end
  1369. else
  1370. begin
  1371. reference_reset(tmpref);
  1372. tmpref.symbol := ref2.symbol;
  1373. tmpref.offset := 0; //ref2.offset;
  1374. tmpref.symaddr := refs_full;
  1375. tmpref.base.enum := R_INTREGISTER;
  1376. tmpref.base.number := NR_RTOC;
  1377. if ref2.offset = 0 then
  1378. list.concat(taicpu.op_reg_ref(A_LWZ,r,tmpref))
  1379. else
  1380. begin
  1381. list.concat(taicpu.op_reg_ref(A_LWZ,r,tmpref));
  1382. reference_reset(tmpref);
  1383. tmpref.offset := ref2.offset;
  1384. tmpref.symaddr := refs_full;
  1385. tmpref.base:= r;
  1386. list.concat(taicpu.op_reg_ref(A_LA,r,tmpref));
  1387. (*
  1388. tmpreg := get_scratch_reg_address(list);
  1389. list.concat(taicpu.op_reg_ref(A_LWZ,tmpreg,tmpref));
  1390. reference_reset(tmpref);
  1391. tmpref.offset := ref2.offset;
  1392. tmpref.symaddr := refs_full;
  1393. tmpref.base:= tmpreg;
  1394. list.concat(taicpu.op_reg_ref(A_LA,r,tmpref));
  1395. free_scratch_reg(list,tmpreg);
  1396. *)
  1397. end;
  1398. end;
  1399. //list.concat(tai_comment.create(strpnew('*** a_loadaddr_ref_reg')));
  1400. end
  1401. else
  1402. begin
  1403. { add the symbol's value to the base of the reference, and if the }
  1404. { reference doesn't have a base, create one }
  1405. reference_reset(tmpref);
  1406. tmpref.offset := ref2.offset;
  1407. tmpref.symbol := ref2.symbol;
  1408. tmpref.symaddr := refs_ha;
  1409. if ref2.base .number<> NR_NO then
  1410. begin
  1411. list.concat(taicpu.op_reg_reg_ref(A_ADDIS,r,
  1412. ref2.base,tmpref));
  1413. if freereg then
  1414. begin
  1415. cg.free_scratch_reg(list,ref2.base);
  1416. freereg := false;
  1417. end;
  1418. end
  1419. else
  1420. list.concat(taicpu.op_reg_ref(A_LIS,r,tmpref));
  1421. tmpref.base.number := NR_NO;
  1422. tmpref.symaddr := refs_l;
  1423. { can be folded with one of the next instructions by the }
  1424. { optimizer probably }
  1425. list.concat(taicpu.op_reg_reg_ref(A_ADDI,r,r,tmpref));
  1426. end
  1427. end
  1428. else if ref2.offset <> 0 Then
  1429. if ref2.base.number <> NR_NO then
  1430. a_op_const_reg_reg(list,OP_ADD,OS_32,ref2.offset,ref2.base,r)
  1431. { FixRef makes sure that "(ref.index <> R_NO) and (ref.offset <> 0)" never}
  1432. { occurs, so now only ref.offset has to be loaded }
  1433. else
  1434. a_load_const_reg(list,OS_32,ref2.offset,r)
  1435. else if ref.index.number <> NR_NO Then
  1436. list.concat(taicpu.op_reg_reg_reg(A_ADD,r,ref2.base,ref2.index))
  1437. else if (ref2.base.number <> NR_NO) and
  1438. (r.number <> ref2.base.number) then
  1439. list.concat(taicpu.op_reg_reg(A_MR,r,ref2.base));
  1440. if freereg then
  1441. cg.free_scratch_reg(list,ref2.base);
  1442. end;
  1443. { ************* concatcopy ************ }
  1444. procedure tcgppc.g_concatcopy(list : taasmoutput;const source,dest : treference;len : aword; delsource,loadref : boolean);
  1445. var
  1446. countreg: TRegister;
  1447. src, dst: TReference;
  1448. lab: tasmlabel;
  1449. count, count2: aword;
  1450. orgsrc, orgdst: boolean;
  1451. r:Tregister;
  1452. begin
  1453. {$ifdef extdebug}
  1454. if len > high(longint) then
  1455. internalerror(2002072704);
  1456. {$endif extdebug}
  1457. { make sure short loads are handled as optimally as possible }
  1458. if not loadref then
  1459. if (len <= 8) and
  1460. (byte(len) in [1,2,4,8]) then
  1461. begin
  1462. if len < 8 then
  1463. begin
  1464. a_load_ref_ref(list,int_cgsize(len),source,dest);
  1465. if delsource then
  1466. reference_release(list,source);
  1467. end
  1468. else
  1469. begin
  1470. r.enum:=R_F0;
  1471. a_reg_alloc(list,r);
  1472. a_loadfpu_ref_reg(list,OS_F64,source,r);
  1473. if delsource then
  1474. reference_release(list,source);
  1475. a_loadfpu_reg_ref(list,OS_F64,r,dest);
  1476. a_reg_dealloc(list,r);
  1477. end;
  1478. exit;
  1479. end;
  1480. reference_reset(src);
  1481. reference_reset(dst);
  1482. { load the address of source into src.base }
  1483. if loadref then
  1484. begin
  1485. src.base := get_scratch_reg_address(list);
  1486. a_load_ref_reg(list,OS_32,source,src.base);
  1487. orgsrc := false;
  1488. end
  1489. else if not issimpleref(source) or
  1490. ((source.index.number <> NR_NO) and
  1491. ((source.offset + longint(len)) > high(smallint))) then
  1492. begin
  1493. src.base := get_scratch_reg_address(list);
  1494. a_loadaddr_ref_reg(list,source,src.base);
  1495. orgsrc := false;
  1496. end
  1497. else
  1498. begin
  1499. src := source;
  1500. orgsrc := true;
  1501. end;
  1502. if not orgsrc and delsource then
  1503. reference_release(list,source);
  1504. { load the address of dest into dst.base }
  1505. if not issimpleref(dest) or
  1506. ((dest.index.number <> NR_NO) and
  1507. ((dest.offset + longint(len)) > high(smallint))) then
  1508. begin
  1509. dst.base := get_scratch_reg_address(list);
  1510. a_loadaddr_ref_reg(list,dest,dst.base);
  1511. orgdst := false;
  1512. end
  1513. else
  1514. begin
  1515. dst := dest;
  1516. orgdst := true;
  1517. end;
  1518. count := len div 8;
  1519. if count > 4 then
  1520. { generate a loop }
  1521. begin
  1522. { the offsets are zero after the a_loadaddress_ref_reg and just }
  1523. { have to be set to 8. I put an Inc there so debugging may be }
  1524. { easier (should offset be different from zero here, it will be }
  1525. { easy to notice in the generated assembler }
  1526. inc(dst.offset,8);
  1527. inc(src.offset,8);
  1528. list.concat(taicpu.op_reg_reg_const(A_SUBI,src.base,src.base,8));
  1529. list.concat(taicpu.op_reg_reg_const(A_SUBI,dst.base,dst.base,8));
  1530. countreg := get_scratch_reg_int(list,OS_INT);
  1531. a_load_const_reg(list,OS_32,count,countreg);
  1532. { explicitely allocate R_0 since it can be used safely here }
  1533. { (for holding date that's being copied) }
  1534. r.enum:=R_F0;
  1535. a_reg_alloc(list,r);
  1536. objectlibrary.getlabel(lab);
  1537. a_label(list, lab);
  1538. list.concat(taicpu.op_reg_reg_const(A_SUBIC_,countreg,countreg,1));
  1539. r.enum:=R_F0;
  1540. list.concat(taicpu.op_reg_ref(A_LFDU,r,src));
  1541. list.concat(taicpu.op_reg_ref(A_STFDU,r,dst));
  1542. a_jmp(list,A_BC,C_NE,0,lab);
  1543. free_scratch_reg(list,countreg);
  1544. a_reg_dealloc(list,r);
  1545. len := len mod 8;
  1546. end;
  1547. count := len div 8;
  1548. if count > 0 then
  1549. { unrolled loop }
  1550. begin
  1551. r.enum:=R_F0;
  1552. a_reg_alloc(list,r);
  1553. for count2 := 1 to count do
  1554. begin
  1555. a_loadfpu_ref_reg(list,OS_F64,src,r);
  1556. a_loadfpu_reg_ref(list,OS_F64,r,dst);
  1557. inc(src.offset,8);
  1558. inc(dst.offset,8);
  1559. end;
  1560. a_reg_dealloc(list,r);
  1561. len := len mod 8;
  1562. end;
  1563. if (len and 4) <> 0 then
  1564. begin
  1565. r.enum:=R_INTREGISTER;
  1566. r.number:=NR_R0;
  1567. a_reg_alloc(list,r);
  1568. a_load_ref_reg(list,OS_32,src,r);
  1569. a_load_reg_ref(list,OS_32,r,dst);
  1570. inc(src.offset,4);
  1571. inc(dst.offset,4);
  1572. a_reg_dealloc(list,r);
  1573. end;
  1574. { copy the leftovers }
  1575. if (len and 2) <> 0 then
  1576. begin
  1577. r.enum:=R_INTREGISTER;
  1578. r.number:=NR_R0;
  1579. a_reg_alloc(list,r);
  1580. a_load_ref_reg(list,OS_16,src,r);
  1581. a_load_reg_ref(list,OS_16,r,dst);
  1582. inc(src.offset,2);
  1583. inc(dst.offset,2);
  1584. a_reg_dealloc(list,r);
  1585. end;
  1586. if (len and 1) <> 0 then
  1587. begin
  1588. r.enum:=R_INTREGISTER;
  1589. r.number:=NR_R0;
  1590. a_reg_alloc(list,r);
  1591. a_load_ref_reg(list,OS_8,src,r);
  1592. a_load_reg_ref(list,OS_8,r,dst);
  1593. a_reg_dealloc(list,r);
  1594. end;
  1595. if orgsrc then
  1596. begin
  1597. if delsource then
  1598. reference_release(list,source);
  1599. end
  1600. else
  1601. free_scratch_reg(list,src.base);
  1602. if not orgdst then
  1603. free_scratch_reg(list,dst.base);
  1604. end;
  1605. procedure tcgppc.g_overflowcheck(list: taasmoutput; const p: tnode);
  1606. var
  1607. hl : tasmlabel;
  1608. r:Tregister;
  1609. begin
  1610. if not(cs_check_overflow in aktlocalswitches) then
  1611. exit;
  1612. objectlibrary.getlabel(hl);
  1613. if not ((p.resulttype.def.deftype=pointerdef) or
  1614. ((p.resulttype.def.deftype=orddef) and
  1615. (torddef(p.resulttype.def).typ in [u64bit,u16bit,u32bit,u8bit,uchar,
  1616. bool8bit,bool16bit,bool32bit]))) then
  1617. begin
  1618. r.enum:=R_CR7;
  1619. list.concat(taicpu.op_reg(A_MCRXR,r));
  1620. a_jmp(list,A_BC,C_OV,7,hl)
  1621. end
  1622. else
  1623. a_jmp_cond(list,OC_AE,hl);
  1624. a_call_name(list,'FPC_OVERFLOW');
  1625. a_label(list,hl);
  1626. end;
  1627. {***************** This is private property, keep out! :) *****************}
  1628. function tcgppc.issimpleref(const ref: treference): boolean;
  1629. begin
  1630. if (ref.base.number = NR_NO) and
  1631. (ref.index.number <> NR_NO) then
  1632. internalerror(200208101);
  1633. result :=
  1634. not(assigned(ref.symbol)) and
  1635. (((ref.index.number = NR_NO) and
  1636. (ref.offset >= low(smallint)) and
  1637. (ref.offset <= high(smallint))) or
  1638. ((ref.index.number <> NR_NO) and
  1639. (ref.offset = 0)));
  1640. end;
  1641. function tcgppc.fixref(list: taasmoutput; var ref: treference): boolean;
  1642. var
  1643. tmpreg: tregister;
  1644. begin
  1645. result := false;
  1646. if (ref.base.number = NR_NO) then
  1647. ref.base := ref.index;
  1648. if (ref.base.number <> NR_NO) then
  1649. begin
  1650. if (ref.index.number <> NR_NO) and
  1651. ((ref.offset <> 0) or assigned(ref.symbol)) then
  1652. begin
  1653. result := true;
  1654. tmpreg := cg.get_scratch_reg_int(list,OS_INT);
  1655. if not assigned(ref.symbol) and
  1656. (cardinal(ref.offset-low(smallint)) <=
  1657. high(smallint)-low(smallint)) then
  1658. begin
  1659. list.concat(taicpu.op_reg_reg_const(
  1660. A_ADDI,tmpreg,ref.base,ref.offset));
  1661. ref.offset := 0;
  1662. end
  1663. else
  1664. begin
  1665. list.concat(taicpu.op_reg_reg_reg(
  1666. A_ADD,tmpreg,ref.base,ref.index));
  1667. ref.index.number := NR_NO;
  1668. end;
  1669. ref.base := tmpreg;
  1670. end
  1671. end
  1672. else
  1673. if ref.index.number <> NR_NO then
  1674. internalerror(200208102);
  1675. end;
  1676. { find out whether a is of the form 11..00..11b or 00..11...00. If }
  1677. { that's the case, we can use rlwinm to do an AND operation }
  1678. function tcgppc.get_rlwi_const(a: aword; var l1, l2: longint): boolean;
  1679. var
  1680. temp : longint;
  1681. testbit : aword;
  1682. compare: boolean;
  1683. begin
  1684. get_rlwi_const := false;
  1685. if (a = 0) or (a = $ffffffff) then
  1686. exit;
  1687. { start with the lowest bit }
  1688. testbit := 1;
  1689. { check its value }
  1690. compare := boolean(a and testbit);
  1691. { find out how long the run of bits with this value is }
  1692. { (it's impossible that all bits are 1 or 0, because in that case }
  1693. { this function wouldn't have been called) }
  1694. l1 := 31;
  1695. while (((a and testbit) <> 0) = compare) do
  1696. begin
  1697. testbit := testbit shl 1;
  1698. dec(l1);
  1699. end;
  1700. { check the length of the run of bits that comes next }
  1701. compare := not compare;
  1702. l2 := l1;
  1703. while (((a and testbit) <> 0) = compare) and
  1704. (l2 >= 0) do
  1705. begin
  1706. testbit := testbit shl 1;
  1707. dec(l2);
  1708. end;
  1709. { and finally the check whether the rest of the bits all have the }
  1710. { same value }
  1711. compare := not compare;
  1712. temp := l2;
  1713. if temp >= 0 then
  1714. if (a shr (31-temp)) <> ((-ord(compare)) shr (31-temp)) then
  1715. exit;
  1716. { we have done "not(not(compare))", so compare is back to its }
  1717. { initial value. If the lowest bit was 0, a is of the form }
  1718. { 00..11..00 and we need "rlwinm reg,reg,0,l2+1,l1", (+1 }
  1719. { because l2 now contains the position of the last zero of the }
  1720. { first run instead of that of the first 1) so switch l1 and l2 }
  1721. { in that case (we will generate "rlwinm reg,reg,0,l1,l2") }
  1722. if not compare then
  1723. begin
  1724. temp := l1;
  1725. l1 := l2+1;
  1726. l2 := temp;
  1727. end
  1728. else
  1729. { otherwise, l1 currently contains the position of the last }
  1730. { zero instead of that of the first 1 of the second run -> +1 }
  1731. inc(l1);
  1732. { the following is the same as "if l1 = -1 then l1 := 31;" }
  1733. l1 := l1 and 31;
  1734. l2 := l2 and 31;
  1735. get_rlwi_const := true;
  1736. end;
  1737. procedure tcgppc.a_load_store(list:taasmoutput;op: tasmop;reg:tregister;
  1738. ref: treference);
  1739. var
  1740. tmpreg: tregister;
  1741. tmpref: treference;
  1742. r : Tregister;
  1743. begin
  1744. tmpreg.number := NR_NO;
  1745. if assigned(ref.symbol) or
  1746. (cardinal(ref.offset-low(smallint)) >
  1747. high(smallint)-low(smallint)) then
  1748. begin
  1749. if target_info.system = system_powerpc_macos then
  1750. begin
  1751. if ref.base.number <> NR_NO then
  1752. begin
  1753. if macos_direct_globals then
  1754. begin
  1755. {Generates
  1756. add tempreg, ref.base, RTOC
  1757. op reg, symbolplusoffset, tempreg
  1758. which is eqvivalent to the more comprehensive
  1759. addi tempreg, RTOC, symbolplusoffset
  1760. add tempreg, ref.base, tempreg
  1761. op reg, tempreg
  1762. but which saves one instruction.}
  1763. tmpreg := get_scratch_reg_address(list);
  1764. reference_reset(tmpref);
  1765. tmpref.symbol := ref.symbol;
  1766. tmpref.offset := ref.offset;
  1767. tmpref.symaddr := refs_full;
  1768. tmpref.base:= tmpreg;
  1769. r.enum:=R_INTREGISTER;
  1770. r.number:=NR_RTOC;
  1771. list.concat(taicpu.op_reg_reg_reg(A_ADD,tmpreg,
  1772. ref.base,r));
  1773. list.concat(taicpu.op_reg_ref(op,reg,tmpref));
  1774. end
  1775. else
  1776. begin
  1777. tmpreg := get_scratch_reg_address(list);
  1778. reference_reset(tmpref);
  1779. tmpref.symbol := ref.symbol;
  1780. tmpref.offset := ref.offset;
  1781. tmpref.symaddr := refs_full;
  1782. tmpref.base.enum:= R_INTREGISTER;
  1783. tmpref.base.number:= NR_RTOC;
  1784. list.concat(taicpu.op_reg_ref(A_LWZ,tmpreg,tmpref));
  1785. list.concat(taicpu.op_reg_reg_reg(A_ADD,tmpreg,
  1786. ref.base,tmpreg));
  1787. reference_reset(tmpref);
  1788. tmpref.offset := 0;
  1789. tmpref.symaddr := refs_full;
  1790. tmpref.base:= tmpreg;
  1791. list.concat(taicpu.op_reg_ref(op,reg,tmpref));
  1792. end;
  1793. //list.concat(tai_comment.create(strpnew('**** a_load_store 1')));
  1794. end
  1795. else
  1796. begin
  1797. if macos_direct_globals then
  1798. begin
  1799. reference_reset(tmpref);
  1800. tmpref.symbol := ref.symbol;
  1801. tmpref.offset := ref.offset;
  1802. tmpref.symaddr := refs_full;
  1803. tmpref.base.enum:= R_INTREGISTER;
  1804. tmpref.base.number:= NR_RTOC;
  1805. list.concat(taicpu.op_reg_ref(op,reg,tmpref));
  1806. end
  1807. else
  1808. begin
  1809. tmpreg := get_scratch_reg_address(list);
  1810. reference_reset(tmpref);
  1811. tmpref.symbol := ref.symbol;
  1812. tmpref.offset := ref.offset;
  1813. tmpref.symaddr := refs_full;
  1814. tmpref.base.enum:= R_INTREGISTER;
  1815. tmpref.base.number:= NR_RTOC;
  1816. list.concat(taicpu.op_reg_ref(A_LWZ,tmpreg,tmpref));
  1817. reference_reset(tmpref);
  1818. tmpref.offset := 0;
  1819. tmpref.symaddr := refs_full;
  1820. tmpref.base:= tmpreg;
  1821. list.concat(taicpu.op_reg_ref(op,reg,tmpref));
  1822. end;
  1823. //list.concat(tai_comment.create(strpnew('*** a_load_store 2')));
  1824. end;
  1825. end
  1826. else
  1827. begin
  1828. tmpreg := get_scratch_reg_address(list);
  1829. reference_reset(tmpref);
  1830. tmpref.symbol := ref.symbol;
  1831. tmpref.offset := ref.offset;
  1832. tmpref.symaddr := refs_ha;
  1833. if ref.base.number <> NR_NO then
  1834. list.concat(taicpu.op_reg_reg_ref(A_ADDIS,tmpreg,
  1835. ref.base,tmpref))
  1836. else
  1837. list.concat(taicpu.op_reg_ref(A_LIS,tmpreg,tmpref));
  1838. ref.base := tmpreg;
  1839. ref.symaddr := refs_l;
  1840. list.concat(taicpu.op_reg_ref(op,reg,ref));
  1841. end
  1842. end
  1843. else
  1844. list.concat(taicpu.op_reg_ref(op,reg,ref));
  1845. if (tmpreg.number <> NR_NO) then
  1846. free_scratch_reg(list,tmpreg);
  1847. end;
  1848. procedure tcgppc.a_jmp(list: taasmoutput; op: tasmop; c: tasmcondflag;
  1849. crval: longint; l: tasmlabel);
  1850. var
  1851. p: taicpu;
  1852. begin
  1853. p := taicpu.op_sym(op,objectlibrary.newasmsymbol(l.name));
  1854. if op <> A_B then
  1855. create_cond_norm(c,crval,p.condition);
  1856. p.is_jmp := true;
  1857. list.concat(p)
  1858. end;
  1859. procedure tcg64fppc.a_op64_reg_reg(list : taasmoutput;op:TOpCG;regsrc,regdst : tregister64);
  1860. begin
  1861. a_op64_reg_reg_reg(list,op,regsrc,regdst,regdst);
  1862. end;
  1863. procedure tcg64fppc.a_op64_const_reg(list : taasmoutput;op:TOpCG;value : qword;reg : tregister64);
  1864. begin
  1865. a_op64_const_reg_reg(list,op,value,reg,reg);
  1866. end;
  1867. procedure tcg64fppc.a_op64_reg_reg_reg(list: taasmoutput;op:TOpCG;regsrc1,regsrc2,regdst : tregister64);
  1868. begin
  1869. case op of
  1870. OP_AND,OP_OR,OP_XOR:
  1871. begin
  1872. cg.a_op_reg_reg_reg(list,op,OS_32,regsrc1.reglo,regsrc2.reglo,regdst.reglo);
  1873. cg.a_op_reg_reg_reg(list,op,OS_32,regsrc1.reghi,regsrc2.reghi,regdst.reghi);
  1874. end;
  1875. OP_ADD:
  1876. begin
  1877. list.concat(taicpu.op_reg_reg_reg(A_ADDC,regdst.reglo,regsrc1.reglo,regsrc2.reglo));
  1878. list.concat(taicpu.op_reg_reg_reg(A_ADDE,regdst.reghi,regsrc1.reghi,regsrc2.reghi));
  1879. end;
  1880. OP_SUB:
  1881. begin
  1882. list.concat(taicpu.op_reg_reg_reg(A_SUBC,regdst.reglo,regsrc2.reglo,regsrc1.reglo));
  1883. list.concat(taicpu.op_reg_reg_reg(A_SUBFE,regdst.reghi,regsrc1.reghi,regsrc2.reghi));
  1884. end;
  1885. else
  1886. internalerror(2002072801);
  1887. end;
  1888. end;
  1889. procedure tcg64fppc.a_op64_const_reg_reg(list: taasmoutput;op:TOpCG;value : qword;regsrc,regdst : tregister64);
  1890. const
  1891. ops: array[boolean,1..3] of tasmop = ((A_ADDIC,A_ADDC,A_ADDZE),
  1892. (A_SUBIC,A_SUBC,A_ADDME));
  1893. var
  1894. tmpreg: tregister;
  1895. tmpreg64: tregister64;
  1896. issub: boolean;
  1897. begin
  1898. case op of
  1899. OP_AND,OP_OR,OP_XOR:
  1900. begin
  1901. cg.a_op_const_reg_reg(list,op,OS_32,cardinal(value),regsrc.reglo,regdst.reglo);
  1902. cg.a_op_const_reg_reg(list,op,OS_32,value shr 32,regsrc.reghi,
  1903. regdst.reghi);
  1904. end;
  1905. OP_ADD, OP_SUB:
  1906. begin
  1907. if (longint(value) <> 0) then
  1908. begin
  1909. issub := op = OP_SUB;
  1910. if (longint(value)-ord(issub) >= -32768) and
  1911. (longint(value)-ord(issub) <= 32767) then
  1912. begin
  1913. list.concat(taicpu.op_reg_reg_const(ops[issub,1],
  1914. regdst.reglo,regsrc.reglo,longint(value)));
  1915. list.concat(taicpu.op_reg_reg(ops[issub,3],
  1916. regdst.reghi,regsrc.reghi));
  1917. end
  1918. else if ((value shr 32) = 0) then
  1919. begin
  1920. tmpreg := cg.get_scratch_reg_int(list,OS_32);
  1921. cg.a_load_const_reg(list,OS_32,cardinal(value),tmpreg);
  1922. list.concat(taicpu.op_reg_reg_reg(ops[issub,2],
  1923. regdst.reglo,regsrc.reglo,tmpreg));
  1924. cg.free_scratch_reg(list,tmpreg);
  1925. list.concat(taicpu.op_reg_reg(ops[issub,3],
  1926. regdst.reghi,regsrc.reghi));
  1927. end
  1928. else
  1929. begin
  1930. tmpreg64.reglo := cg.get_scratch_reg_int(list,OS_INT);
  1931. tmpreg64.reghi := cg.get_scratch_reg_int(list,OS_INT);
  1932. a_load64_const_reg(list,value,tmpreg64);
  1933. a_op64_reg_reg_reg(list,op,tmpreg64,regsrc,regdst);
  1934. cg.free_scratch_reg(list,tmpreg64.reghi);
  1935. cg.free_scratch_reg(list,tmpreg64.reglo);
  1936. end
  1937. end
  1938. else
  1939. begin
  1940. cg.a_load_reg_reg(list,OS_INT,OS_INT,regsrc.reglo,regdst.reglo);
  1941. cg.a_op_const_reg_reg(list,op,OS_32,value shr 32,regsrc.reghi,
  1942. regdst.reghi);
  1943. end;
  1944. end;
  1945. else
  1946. internalerror(2002072802);
  1947. end;
  1948. end;
  1949. begin
  1950. cg := tcgppc.create;
  1951. cg64 :=tcg64fppc.create;
  1952. end.
  1953. {
  1954. $Log$
  1955. Revision 1.77 2003-04-06 16:39:11 jonas
  1956. * don't generate entry/exit code for assembler procedures
  1957. Revision 1.76 2003/03/22 18:01:13 jonas
  1958. * fixed linux entry/exit code generation
  1959. Revision 1.75 2003/03/19 14:26:26 jonas
  1960. * fixed R_TOC bugs introduced by new register allocator conversion
  1961. Revision 1.74 2003/03/13 22:57:45 olle
  1962. * change in a_loadaddr_ref_reg
  1963. Revision 1.73 2003/03/12 22:43:38 jonas
  1964. * more powerpc and generic fixes related to the new register allocator
  1965. Revision 1.72 2003/03/11 21:46:24 jonas
  1966. * lots of new regallocator fixes, both in generic and ppc-specific code
  1967. (ppc compiler still can't compile the linux system unit though)
  1968. Revision 1.71 2003/02/19 22:00:16 daniel
  1969. * Code generator converted to new register notation
  1970. - Horribily outdated todo.txt removed
  1971. Revision 1.70 2003/01/13 17:17:50 olle
  1972. * changed global var access, TOC now contain pointers to globals
  1973. * fixed handling of function pointers
  1974. Revision 1.69 2003/01/09 22:00:53 florian
  1975. * fixed some PowerPC issues
  1976. Revision 1.68 2003/01/08 18:43:58 daniel
  1977. * Tregister changed into a record
  1978. Revision 1.67 2002/12/15 19:22:01 florian
  1979. * fixed some crashes and a rte 201
  1980. Revision 1.66 2002/11/28 10:55:16 olle
  1981. * macos: changing code gen for references to globals
  1982. Revision 1.65 2002/11/07 15:50:23 jonas
  1983. * fixed bctr(l) problems
  1984. Revision 1.64 2002/11/04 18:24:19 olle
  1985. * macos: globals are located in TOC and relative r2, instead of absolute
  1986. Revision 1.63 2002/10/28 22:24:28 olle
  1987. * macos entry/exit: only used registers are saved
  1988. - macos entry/exit: stackptr not saved in r31 anymore
  1989. * macos entry/exit: misc fixes
  1990. Revision 1.62 2002/10/19 23:51:48 olle
  1991. * macos stack frame size computing updated
  1992. + macos epilogue: control register now restored
  1993. * macos prologue and epilogue: fp reg now saved and restored
  1994. Revision 1.61 2002/10/19 12:50:36 olle
  1995. * reorganized prologue and epilogue routines
  1996. Revision 1.60 2002/10/02 21:49:51 florian
  1997. * all A_BL instructions replaced by calls to a_call_name
  1998. Revision 1.59 2002/10/02 13:24:58 jonas
  1999. * changed a_call_* so that no superfluous code is generated anymore
  2000. Revision 1.58 2002/09/17 18:54:06 jonas
  2001. * a_load_reg_reg() now has two size parameters: source and dest. This
  2002. allows some optimizations on architectures that don't encode the
  2003. register size in the register name.
  2004. Revision 1.57 2002/09/10 21:22:25 jonas
  2005. + added some internal errors
  2006. * fixed bug in sysv exit code
  2007. Revision 1.56 2002/09/08 20:11:56 jonas
  2008. * fixed TOpCmp2AsmCond array (some unsigned equivalents were wrong)
  2009. Revision 1.55 2002/09/08 13:03:26 jonas
  2010. * several large offset-related fixes
  2011. Revision 1.54 2002/09/07 17:54:58 florian
  2012. * first part of PowerPC fixes
  2013. Revision 1.53 2002/09/07 15:25:14 peter
  2014. * old logs removed and tabs fixed
  2015. Revision 1.52 2002/09/02 10:14:51 jonas
  2016. + a_call_reg()
  2017. * small fix in a_call_ref()
  2018. Revision 1.51 2002/09/02 06:09:02 jonas
  2019. * fixed range error
  2020. Revision 1.50 2002/09/01 21:04:49 florian
  2021. * several powerpc related stuff fixed
  2022. Revision 1.49 2002/09/01 12:09:27 peter
  2023. + a_call_reg, a_call_loc added
  2024. * removed exprasmlist references
  2025. Revision 1.48 2002/08/31 21:38:02 jonas
  2026. * fixed a_call_ref (it should load ctr, not lr)
  2027. Revision 1.47 2002/08/31 21:30:45 florian
  2028. * fixed several problems caused by Jonas' commit :)
  2029. Revision 1.46 2002/08/31 19:25:50 jonas
  2030. + implemented a_call_ref()
  2031. Revision 1.45 2002/08/18 22:16:14 florian
  2032. + the ppc gas assembler writer adds now registers aliases
  2033. to the assembler file
  2034. Revision 1.44 2002/08/17 18:23:53 florian
  2035. * some assembler writer bugs fixed
  2036. Revision 1.43 2002/08/17 09:23:49 florian
  2037. * first part of procinfo rewrite
  2038. Revision 1.42 2002/08/16 14:24:59 carl
  2039. * issameref() to test if two references are the same (then emit no opcodes)
  2040. + ret_in_reg to replace ret_in_acc
  2041. (fix some register allocation bugs at the same time)
  2042. + save_std_register now has an extra parameter which is the
  2043. usedinproc registers
  2044. Revision 1.41 2002/08/15 08:13:54 carl
  2045. - a_load_sym_ofs_reg removed
  2046. * loadvmt now calls loadaddr_ref_reg instead
  2047. Revision 1.40 2002/08/11 14:32:32 peter
  2048. * renamed current_library to objectlibrary
  2049. Revision 1.39 2002/08/11 13:24:18 peter
  2050. * saving of asmsymbols in ppu supported
  2051. * asmsymbollist global is removed and moved into a new class
  2052. tasmlibrarydata that will hold the info of a .a file which
  2053. corresponds with a single module. Added librarydata to tmodule
  2054. to keep the library info stored for the module. In the future the
  2055. objectfiles will also be stored to the tasmlibrarydata class
  2056. * all getlabel/newasmsymbol and friends are moved to the new class
  2057. Revision 1.38 2002/08/11 11:39:31 jonas
  2058. + powerpc-specific genlinearlist
  2059. Revision 1.37 2002/08/10 17:15:31 jonas
  2060. * various fixes and optimizations
  2061. Revision 1.36 2002/08/06 20:55:23 florian
  2062. * first part of ppc calling conventions fix
  2063. Revision 1.35 2002/08/06 07:12:05 jonas
  2064. * fixed bug in g_flags2reg()
  2065. * and yet more constant operation fixes :)
  2066. Revision 1.34 2002/08/05 08:58:53 jonas
  2067. * fixed compilation problems
  2068. Revision 1.33 2002/08/04 12:57:55 jonas
  2069. * more misc. fixes, mostly constant-related
  2070. }