cgcpu.pas 85 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384
  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. case target_info.system of
  787. system_powerpc_macos:
  788. g_stackframe_entry_mac(list,localsize);
  789. system_powerpc_linux:
  790. g_stackframe_entry_sysv(list,localsize)
  791. else
  792. internalerror(2204001);
  793. end;
  794. end;
  795. procedure tcgppc.g_return_from_proc(list : taasmoutput;parasize : aword);
  796. begin
  797. case target_info.system of
  798. system_powerpc_macos:
  799. g_return_from_proc_mac(list,parasize);
  800. system_powerpc_linux:
  801. g_return_from_proc_sysv(list,parasize)
  802. else
  803. internalerror(2204001);
  804. end;
  805. end;
  806. procedure tcgppc.g_stackframe_entry_sysv(list : taasmoutput;localsize : longint);
  807. { generated the entry code of a procedure/function. Note: localsize is the }
  808. { sum of the size necessary for local variables and the maximum possible }
  809. { combined size of ALL the parameters of a procedure called by the current }
  810. { one }
  811. var regcounter,firstregfpu,firstreggpr: TRegister;
  812. href : treference;
  813. usesfpr,usesgpr,gotgot : boolean;
  814. parastart : aword;
  815. offset : aword;
  816. r,r2,rsp:Tregister;
  817. regcounter2: Tsuperregister;
  818. begin
  819. { we do our own localsize calculation }
  820. localsize:=0;
  821. { CR and LR only have to be saved in case they are modified by the current }
  822. { procedure, but currently this isn't checked, so save them always }
  823. { following is the entry code as described in "Altivec Programming }
  824. { Interface Manual", bar the saving of AltiVec registers }
  825. rsp.enum:=R_INTREGISTER;
  826. rsp.number:=NR_STACK_POINTER_REG;;
  827. a_reg_alloc(list,rsp);
  828. r.enum:=R_INTREGISTER;
  829. r.number:=NR_R0;
  830. a_reg_alloc(list,r);
  831. { allocate registers containing reg parameters }
  832. r.enum := R_INTREGISTER;
  833. for regcounter2 := RS_R3 to RS_R10 do
  834. begin
  835. r.number:=regcounter2 shl 8;
  836. a_reg_alloc(list,r);
  837. end;
  838. usesfpr:=false;
  839. if not (po_assembler in aktprocdef.procoptions) then
  840. for regcounter.enum:=R_F14 to R_F31 do
  841. if regcounter.enum in rg.usedbyproc then
  842. begin
  843. usesfpr:= true;
  844. firstregfpu:=regcounter;
  845. break;
  846. end;
  847. usesgpr:=false;
  848. if not (po_assembler in aktprocdef.procoptions) then
  849. for regcounter2:=RS_R14 to RS_R31 do
  850. begin
  851. if regcounter2 in rg.usedintbyproc then
  852. begin
  853. usesgpr:=true;
  854. firstreggpr.enum := R_INTREGISTER;
  855. firstreggpr.number := regcounter2 shl 8;
  856. break;
  857. end;
  858. end;
  859. { save link register? }
  860. if not (po_assembler in aktprocdef.procoptions) then
  861. if (procinfo.flags and pi_do_call)<>0 then
  862. begin
  863. { save return address... }
  864. r.enum:=R_INTREGISTER;
  865. r.number:=NR_R0;
  866. list.concat(taicpu.op_reg(A_MFLR,r));
  867. { ... in caller's rframe }
  868. reference_reset_base(href,rsp,4);
  869. list.concat(taicpu.op_reg_ref(A_STW,r,href));
  870. a_reg_dealloc(list,r);
  871. end;
  872. if usesfpr or usesgpr then
  873. begin
  874. r.enum:=R_INTREGISTER;
  875. r.number:=NR_R11;
  876. a_reg_alloc(list,r);
  877. { save end of fpr save area }
  878. list.concat(taicpu.op_reg_reg(A_MR,r,rsp));
  879. end;
  880. { calculate the size of the locals }
  881. if usesgpr then
  882. inc(localsize,((NR_R31-firstreggpr.number) shr 8+1)*4);
  883. if usesfpr then
  884. inc(localsize,(ord(R_F31)-ord(firstregfpu.enum)+1)*8);
  885. { align to 16 bytes }
  886. localsize:=align(localsize,16);
  887. inc(localsize,tg.lasttemp);
  888. localsize:=align(localsize,16);
  889. tppcprocinfo(procinfo).localsize:=localsize;
  890. if (localsize <> 0) then
  891. begin
  892. r.enum:=R_INTREGISTER;
  893. r.number:=NR_STACK_POINTER_REG;
  894. reference_reset_base(href,r,-localsize);
  895. a_load_store(list,A_STWU,r,href);
  896. end;
  897. { no GOT pointer loaded yet }
  898. gotgot:=false;
  899. if usesfpr then
  900. begin
  901. { save floating-point registers
  902. if (cs_create_pic in aktmoduleswitches) and not(usesgpr) then
  903. begin
  904. a_call_name(objectlibrary.newasmsymbol('_savefpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14)+'_g');
  905. gotgot:=true;
  906. end
  907. else
  908. a_call_name(objectlibrary.newasmsymbol('_savefpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14));
  909. }
  910. for regcounter.enum:=firstregfpu.enum to R_F31 do
  911. if regcounter.enum in rg.usedbyproc then
  912. begin
  913. { reference_reset_base(href,R_1,-localsize);
  914. a_load_store(list,A_STWU,R_1,href);
  915. }
  916. end;
  917. { compute end of gpr save area }
  918. r.enum:=R_INTREGISTER;
  919. r.number:=NR_R11;
  920. list.concat(taicpu.op_reg_reg_const(A_ADDI,r,r,-(ord(R_F31)-ord(firstregfpu.enum)+1)*8));
  921. end;
  922. { save gprs and fetch GOT pointer }
  923. if usesgpr then
  924. begin
  925. {
  926. if cs_create_pic in aktmoduleswitches then
  927. begin
  928. a_call_name(objectlibrary.newasmsymbol('_savegpr_'+tostr(ord(firstreggpr)-ord(R_14)+14)+'_g');
  929. gotgot:=true;
  930. end
  931. else
  932. a_call_name(objectlibrary.newasmsymbol('_savegpr_'+tostr(ord(firstreggpr)-ord(R_14)+14))
  933. }
  934. r.enum:=R_INTREGISTER;
  935. r.number:=NR_R11;
  936. reference_reset_base(href,r,-((NR_R31-firstreggpr.number) shr 8+1)*4);
  937. list.concat(taicpu.op_reg_ref(A_STMW,firstreggpr,href));
  938. end;
  939. r.enum:=R_INTREGISTER;
  940. r.number:=NR_R11;
  941. if usesfpr or usesgpr then
  942. a_reg_dealloc(list,r);
  943. { PIC code support, }
  944. if cs_create_pic in aktmoduleswitches then
  945. begin
  946. { if we didn't get the GOT pointer till now, we've to calculate it now }
  947. if not(gotgot) then
  948. begin
  949. {!!!!!!!!!!!!!}
  950. end;
  951. r.enum:=R_INTREGISTER;
  952. r.number:=NR_R31;
  953. r2.enum:=R_LR;
  954. a_reg_alloc(list,r);
  955. { place GOT ptr in r31 }
  956. list.concat(taicpu.op_reg_reg(A_MFSPR,r,r2));
  957. end;
  958. { save the CR if necessary ( !!! always done currently ) }
  959. { still need to find out where this has to be done for SystemV
  960. a_reg_alloc(list,R_0);
  961. list.concat(taicpu.op_reg_reg(A_MFSPR,R_0,R_CR);
  962. list.concat(taicpu.op_reg_ref(A_STW,scratch_register,
  963. new_reference(STACK_POINTER_REG,LA_CR)));
  964. a_reg_dealloc(list,R_0); }
  965. { now comes the AltiVec context save, not yet implemented !!! }
  966. end;
  967. procedure tcgppc.g_return_from_proc_sysv(list : taasmoutput;parasize : aword);
  968. var
  969. regcounter,firstregfpu,firstreggpr: TRegister;
  970. href : treference;
  971. usesfpr,usesgpr,genret : boolean;
  972. r,r2:Tregister;
  973. regcounter2:Tsuperregister;
  974. begin
  975. { release parameter registers }
  976. r.enum := R_INTREGISTER;
  977. for regcounter2 := RS_R3 to RS_R10 do
  978. begin
  979. r.number:=regcounter2 shl 8;
  980. a_reg_dealloc(list,r);
  981. end;
  982. { AltiVec context restore, not yet implemented !!! }
  983. usesfpr:=false;
  984. if not (po_assembler in aktprocdef.procoptions) then
  985. for regcounter.enum:=R_F14 to R_F31 do
  986. if regcounter.enum in rg.usedbyproc then
  987. begin
  988. usesfpr:=true;
  989. firstregfpu:=regcounter;
  990. break;
  991. end;
  992. usesgpr:=false;
  993. if not (po_assembler in aktprocdef.procoptions) then
  994. for regcounter2:=RS_R14 to RS_R30 do
  995. begin
  996. if regcounter2 in rg.usedintbyproc then
  997. begin
  998. usesgpr:=true;
  999. firstreggpr.enum:=R_INTREGISTER;
  1000. firstreggpr.number:=regcounter2 shl 8;
  1001. break;
  1002. end;
  1003. end;
  1004. { no return (blr) generated yet }
  1005. genret:=true;
  1006. if usesgpr then
  1007. begin
  1008. { address of gpr save area to r11 }
  1009. r.enum:=R_INTREGISTER;
  1010. r.number:=NR_STACK_POINTER_REG;
  1011. r2.enum:=R_INTREGISTER;
  1012. r2.number:=NR_R11;
  1013. if usesfpr then
  1014. list.concat(taicpu.op_reg_reg_const(A_ADDI,r2,r,tppcprocinfo(procinfo).localsize-(ord(R_F31)-ord(firstregfpu.enum)+1)*8))
  1015. else
  1016. list.concat(taicpu.op_reg_reg_const(A_ADDI,r2,r,tppcprocinfo(procinfo).localsize));
  1017. { restore gprs }
  1018. { at least for now we use LMW }
  1019. {
  1020. a_call_name(objectlibrary.newasmsymbol('_restgpr_14');
  1021. }
  1022. reference_reset_base(href,r2,-((NR_R31-ord(firstreggpr.number)) shr 8+1)*4);
  1023. list.concat(taicpu.op_reg_ref(A_LMW,firstreggpr,href));
  1024. end;
  1025. { restore fprs and return }
  1026. if usesfpr then
  1027. begin
  1028. { address of fpr save area to r11 }
  1029. r.enum:=R_INTREGISTER;
  1030. r.number:=NR_R11;
  1031. list.concat(taicpu.op_reg_reg_const(A_ADDI,r,r,(ord(R_F31)-ord(firstregfpu.enum)+1)*8));
  1032. {
  1033. if (procinfo.flags and pi_do_call)<>0 then
  1034. a_call_name(objectlibrary.newasmsymbol('_restfpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14)+
  1035. '_x')
  1036. else
  1037. { leaf node => lr haven't to be restored }
  1038. a_call_name('_restfpr_'+tostr(ord(firstregfpu.enum)-ord(R_F14)+14)+
  1039. '_l');
  1040. genret:=false;
  1041. }
  1042. end;
  1043. { if we didn't generate the return code, we've to do it now }
  1044. if genret then
  1045. begin
  1046. { adjust r1 }
  1047. r.enum:=R_INTREGISTER;
  1048. r.number:=NR_R1;
  1049. a_op_const_reg(list,OP_ADD,tppcprocinfo(procinfo).localsize,r);
  1050. { load link register? }
  1051. if not (po_assembler in aktprocdef.procoptions) then
  1052. if (procinfo.flags and pi_do_call)<>0 then
  1053. begin
  1054. r.enum:=R_INTREGISTER;
  1055. r.number:=NR_STACK_POINTER_REG;
  1056. reference_reset_base(href,r,4);
  1057. r.enum:=R_INTREGISTER;
  1058. r.number:=NR_R0;
  1059. list.concat(taicpu.op_reg_ref(A_LWZ,r,href));
  1060. list.concat(taicpu.op_reg(A_MTLR,r));
  1061. end;
  1062. list.concat(taicpu.op_none(A_BLR));
  1063. end;
  1064. end;
  1065. function save_regs(list : taasmoutput):longint;
  1066. {Generates code which saves used non-volatile registers in
  1067. the save area right below the address the stackpointer point to.
  1068. Returns the actual used save area size.}
  1069. var regcounter,firstregfpu,firstreggpr: TRegister;
  1070. usesfpr,usesgpr: boolean;
  1071. href : treference;
  1072. offset: integer;
  1073. r,r2:Tregister;
  1074. regcounter2: Tsuperregister;
  1075. begin
  1076. usesfpr:=false;
  1077. if not (po_assembler in aktprocdef.procoptions) then
  1078. for regcounter.enum:=R_F14 to R_F31 do
  1079. if regcounter.enum in rg.usedbyproc then
  1080. begin
  1081. usesfpr:=true;
  1082. firstregfpu:=regcounter;
  1083. break;
  1084. end;
  1085. usesgpr:=false;
  1086. if not (po_assembler in aktprocdef.procoptions) then
  1087. for regcounter2:=RS_R13 to RS_R31 do
  1088. begin
  1089. if regcounter2 in rg.usedintbyproc then
  1090. begin
  1091. usesgpr:=true;
  1092. firstreggpr.enum:=R_INTREGISTER;
  1093. firstreggpr.number:=regcounter2 shl 8;
  1094. break;
  1095. end;
  1096. end;
  1097. offset:= 0;
  1098. { save floating-point registers }
  1099. if usesfpr then
  1100. for regcounter.enum := firstregfpu.enum to R_F31 do
  1101. begin
  1102. offset:= offset - 8;
  1103. r.enum:=R_INTREGISTER;
  1104. r.number:=NR_STACK_POINTER_REG;
  1105. reference_reset_base(href, r, offset);
  1106. list.concat(taicpu.op_reg_ref(A_STFD, regcounter, href));
  1107. end;
  1108. (* Optimiztion in the future: a_call_name(list,'_savefXX'); *)
  1109. { save gprs in gpr save area }
  1110. if usesgpr then
  1111. if firstreggpr.enum < R_30 then
  1112. begin
  1113. offset:= offset - 4 * (ord(R_31) - ord(firstreggpr.enum) + 1);
  1114. r.enum:=R_INTREGISTER;
  1115. r.number:=NR_STACK_POINTER_REG;
  1116. reference_reset_base(href,r,offset);
  1117. list.concat(taicpu.op_reg_ref(A_STMW,firstreggpr,href));
  1118. {STMW stores multiple registers}
  1119. end
  1120. else
  1121. begin
  1122. r.enum:=R_INTREGISTER;
  1123. r.number:=NR_STACK_POINTER_REG;
  1124. r2 := firstreggpr;
  1125. convert_register_to_enum(firstreggpr);
  1126. for regcounter.enum := firstreggpr.enum to R_31 do
  1127. begin
  1128. offset:= offset - 4;
  1129. reference_reset_base(href, r, offset);
  1130. list.concat(taicpu.op_reg_ref(A_STW, r2, href));
  1131. inc(r2.number,NR_R1-NR_R0);
  1132. end;
  1133. end;
  1134. { now comes the AltiVec context save, not yet implemented !!! }
  1135. save_regs:= -offset;
  1136. end;
  1137. procedure restore_regs(list : taasmoutput);
  1138. {Generates code which restores used non-volatile registers from
  1139. the save area right below the address the stackpointer point to.}
  1140. var regcounter,firstregfpu,firstreggpr: TRegister;
  1141. usesfpr,usesgpr: boolean;
  1142. href : treference;
  1143. offset: integer;
  1144. r,r2:Tregister;
  1145. regcounter2: Tsuperregister;
  1146. begin
  1147. usesfpr:=false;
  1148. if not (po_assembler in aktprocdef.procoptions) then
  1149. for regcounter.enum:=R_F14 to R_F31 do
  1150. if regcounter.enum in rg.usedbyproc then
  1151. begin
  1152. usesfpr:=true;
  1153. firstregfpu:=regcounter;
  1154. break;
  1155. end;
  1156. usesgpr:=false;
  1157. if not (po_assembler in aktprocdef.procoptions) then
  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. if (localsize <> 0) then
  1278. begin
  1279. r.enum:=R_INTREGISTER;
  1280. r.number:=NR_STACK_POINTER_REG;
  1281. reference_reset_base(href,r,-localsize);
  1282. a_load_store(list,A_STWU,r,href);
  1283. { this also stores the old stack pointer in the new stack frame }
  1284. end;
  1285. end;
  1286. procedure tcgppc.g_return_from_proc_mac(list : taasmoutput;parasize : aword);
  1287. var
  1288. regcounter: TRegister;
  1289. href : treference;
  1290. r,r2,rsp:Tregister;
  1291. regcounter2: Tsuperregister;
  1292. begin
  1293. { release parameter registers }
  1294. r.enum := R_INTREGISTER;
  1295. for regcounter2 := RS_R3 to RS_R10 do
  1296. begin
  1297. r.number := regcounter2 shl 8;
  1298. a_reg_dealloc(list,r);
  1299. end;
  1300. {TODO: Release fp and altivec parameter registers also}
  1301. r.enum:=R_INTREGISTER;
  1302. r.number:=NR_R0;
  1303. rsp.enum:=R_INTREGISTER;
  1304. rsp.number:=NR_STACK_POINTER_REG;
  1305. a_reg_alloc(list,r);
  1306. { restore stack pointer }
  1307. reference_reset_base(href,rsp,LA_SP);
  1308. list.concat(taicpu.op_reg_ref(A_LWZ,rsp,href));
  1309. (*
  1310. list.concat(taicpu.op_reg_reg_const(A_ORI,rsp,R_31,0));
  1311. *)
  1312. { restore the CR if necessary from callers frame
  1313. ( !!! always done currently ) }
  1314. reference_reset_base(href,rsp,LA_CR);
  1315. r.enum:=R_INTREGISTER;
  1316. r.number:=NR_R0;
  1317. list.concat(taicpu.op_reg_ref(A_LWZ,r,href));
  1318. r2.enum:=R_CR;
  1319. list.concat(taicpu.op_reg_reg(A_MTSPR,r,r2));
  1320. a_reg_dealloc(list,r);
  1321. (*
  1322. { restore return address from callers frame }
  1323. reference_reset_base(href,STACK_POINTER_REG,8);
  1324. list.concat(taicpu.op_reg_ref(A_LWZ,R_0,href));
  1325. *)
  1326. { restore non-volatile registers from callers frame }
  1327. restore_regs(list);
  1328. (*
  1329. { return to caller }
  1330. list.concat(taicpu.op_reg_reg(A_MTSPR,R_0,R_LR));
  1331. list.concat(taicpu.op_none(A_BLR));
  1332. *)
  1333. { restore return address from callers frame }
  1334. r.enum:=R_INTREGISTER;
  1335. r.number:=NR_R0;
  1336. r2.enum:=R_LR;
  1337. reference_reset_base(href,rsp,8);
  1338. list.concat(taicpu.op_reg_ref(A_LWZ,r,href));
  1339. { return to caller }
  1340. list.concat(taicpu.op_reg_reg(A_MTSPR,r,r2));
  1341. list.concat(taicpu.op_none(A_BLR));
  1342. end;
  1343. procedure tcgppc.g_restore_frame_pointer(list : taasmoutput);
  1344. begin
  1345. { no frame pointer on the PowerPC (maybe there is one in the SystemV ABI?)}
  1346. end;
  1347. procedure tcgppc.a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);
  1348. var
  1349. ref2, tmpref: treference;
  1350. freereg: boolean;
  1351. r2,tmpreg:Tregister;
  1352. begin
  1353. ref2 := ref;
  1354. freereg := fixref(list,ref2);
  1355. if assigned(ref2.symbol) then
  1356. begin
  1357. if target_info.system = system_powerpc_macos then
  1358. begin
  1359. if ref2.base.number <> NR_NO then
  1360. internalerror(2002103102); //TODO: Implement this if needed
  1361. if macos_direct_globals then
  1362. begin
  1363. reference_reset(tmpref);
  1364. tmpref.offset := ref2.offset;
  1365. tmpref.symbol := ref2.symbol;
  1366. tmpref.symaddr := refs_full;
  1367. tmpref.base.number := NR_NO;
  1368. r2.enum:=R_INTREGISTER;
  1369. r2.number:=NR_RTOC;
  1370. list.concat(taicpu.op_reg_reg_ref(A_ADDI,r,r2,tmpref));
  1371. end
  1372. else
  1373. begin
  1374. reference_reset(tmpref);
  1375. tmpref.symbol := ref2.symbol;
  1376. tmpref.offset := 0; //ref2.offset;
  1377. tmpref.symaddr := refs_full;
  1378. tmpref.base.enum := R_INTREGISTER;
  1379. tmpref.base.number := NR_RTOC;
  1380. if ref2.offset = 0 then
  1381. list.concat(taicpu.op_reg_ref(A_LWZ,r,tmpref))
  1382. else
  1383. begin
  1384. list.concat(taicpu.op_reg_ref(A_LWZ,r,tmpref));
  1385. reference_reset(tmpref);
  1386. tmpref.offset := ref2.offset;
  1387. tmpref.symaddr := refs_full;
  1388. tmpref.base:= r;
  1389. list.concat(taicpu.op_reg_ref(A_LA,r,tmpref));
  1390. (*
  1391. tmpreg := get_scratch_reg_address(list);
  1392. list.concat(taicpu.op_reg_ref(A_LWZ,tmpreg,tmpref));
  1393. reference_reset(tmpref);
  1394. tmpref.offset := ref2.offset;
  1395. tmpref.symaddr := refs_full;
  1396. tmpref.base:= tmpreg;
  1397. list.concat(taicpu.op_reg_ref(A_LA,r,tmpref));
  1398. free_scratch_reg(list,tmpreg);
  1399. *)
  1400. end;
  1401. end;
  1402. //list.concat(tai_comment.create(strpnew('*** a_loadaddr_ref_reg')));
  1403. end
  1404. else
  1405. begin
  1406. { add the symbol's value to the base of the reference, and if the }
  1407. { reference doesn't have a base, create one }
  1408. reference_reset(tmpref);
  1409. tmpref.offset := ref2.offset;
  1410. tmpref.symbol := ref2.symbol;
  1411. tmpref.symaddr := refs_ha;
  1412. if ref2.base .number<> NR_NO then
  1413. begin
  1414. list.concat(taicpu.op_reg_reg_ref(A_ADDIS,r,
  1415. ref2.base,tmpref));
  1416. if freereg then
  1417. begin
  1418. cg.free_scratch_reg(list,ref2.base);
  1419. freereg := false;
  1420. end;
  1421. end
  1422. else
  1423. list.concat(taicpu.op_reg_ref(A_LIS,r,tmpref));
  1424. tmpref.base.number := NR_NO;
  1425. tmpref.symaddr := refs_l;
  1426. { can be folded with one of the next instructions by the }
  1427. { optimizer probably }
  1428. list.concat(taicpu.op_reg_reg_ref(A_ADDI,r,r,tmpref));
  1429. end
  1430. end
  1431. else if ref2.offset <> 0 Then
  1432. if ref2.base.number <> NR_NO then
  1433. a_op_const_reg_reg(list,OP_ADD,OS_32,ref2.offset,ref2.base,r)
  1434. { FixRef makes sure that "(ref.index <> R_NO) and (ref.offset <> 0)" never}
  1435. { occurs, so now only ref.offset has to be loaded }
  1436. else
  1437. a_load_const_reg(list,OS_32,ref2.offset,r)
  1438. else if ref.index.number <> NR_NO Then
  1439. list.concat(taicpu.op_reg_reg_reg(A_ADD,r,ref2.base,ref2.index))
  1440. else if (ref2.base.number <> NR_NO) and
  1441. (r.number <> ref2.base.number) then
  1442. list.concat(taicpu.op_reg_reg(A_MR,r,ref2.base));
  1443. if freereg then
  1444. cg.free_scratch_reg(list,ref2.base);
  1445. end;
  1446. { ************* concatcopy ************ }
  1447. procedure tcgppc.g_concatcopy(list : taasmoutput;const source,dest : treference;len : aword; delsource,loadref : boolean);
  1448. var
  1449. countreg: TRegister;
  1450. src, dst: TReference;
  1451. lab: tasmlabel;
  1452. count, count2: aword;
  1453. orgsrc, orgdst: boolean;
  1454. r:Tregister;
  1455. begin
  1456. {$ifdef extdebug}
  1457. if len > high(longint) then
  1458. internalerror(2002072704);
  1459. {$endif extdebug}
  1460. { make sure short loads are handled as optimally as possible }
  1461. if not loadref then
  1462. if (len <= 8) and
  1463. (byte(len) in [1,2,4,8]) then
  1464. begin
  1465. if len < 8 then
  1466. begin
  1467. a_load_ref_ref(list,int_cgsize(len),source,dest);
  1468. if delsource then
  1469. reference_release(list,source);
  1470. end
  1471. else
  1472. begin
  1473. r.enum:=R_F0;
  1474. a_reg_alloc(list,r);
  1475. a_loadfpu_ref_reg(list,OS_F64,source,r);
  1476. if delsource then
  1477. reference_release(list,source);
  1478. a_loadfpu_reg_ref(list,OS_F64,r,dest);
  1479. a_reg_dealloc(list,r);
  1480. end;
  1481. exit;
  1482. end;
  1483. reference_reset(src);
  1484. reference_reset(dst);
  1485. { load the address of source into src.base }
  1486. if loadref then
  1487. begin
  1488. src.base := get_scratch_reg_address(list);
  1489. a_load_ref_reg(list,OS_32,source,src.base);
  1490. orgsrc := false;
  1491. end
  1492. else if not issimpleref(source) or
  1493. ((source.index.number <> NR_NO) and
  1494. ((source.offset + longint(len)) > high(smallint))) then
  1495. begin
  1496. src.base := get_scratch_reg_address(list);
  1497. a_loadaddr_ref_reg(list,source,src.base);
  1498. orgsrc := false;
  1499. end
  1500. else
  1501. begin
  1502. src := source;
  1503. orgsrc := true;
  1504. end;
  1505. if not orgsrc and delsource then
  1506. reference_release(list,source);
  1507. { load the address of dest into dst.base }
  1508. if not issimpleref(dest) or
  1509. ((dest.index.number <> NR_NO) and
  1510. ((dest.offset + longint(len)) > high(smallint))) then
  1511. begin
  1512. dst.base := get_scratch_reg_address(list);
  1513. a_loadaddr_ref_reg(list,dest,dst.base);
  1514. orgdst := false;
  1515. end
  1516. else
  1517. begin
  1518. dst := dest;
  1519. orgdst := true;
  1520. end;
  1521. count := len div 8;
  1522. if count > 4 then
  1523. { generate a loop }
  1524. begin
  1525. { the offsets are zero after the a_loadaddress_ref_reg and just }
  1526. { have to be set to 8. I put an Inc there so debugging may be }
  1527. { easier (should offset be different from zero here, it will be }
  1528. { easy to notice in the generated assembler }
  1529. inc(dst.offset,8);
  1530. inc(src.offset,8);
  1531. list.concat(taicpu.op_reg_reg_const(A_SUBI,src.base,src.base,8));
  1532. list.concat(taicpu.op_reg_reg_const(A_SUBI,dst.base,dst.base,8));
  1533. countreg := get_scratch_reg_int(list,OS_INT);
  1534. a_load_const_reg(list,OS_32,count,countreg);
  1535. { explicitely allocate R_0 since it can be used safely here }
  1536. { (for holding date that's being copied) }
  1537. r.enum:=R_F0;
  1538. a_reg_alloc(list,r);
  1539. objectlibrary.getlabel(lab);
  1540. a_label(list, lab);
  1541. list.concat(taicpu.op_reg_reg_const(A_SUBIC_,countreg,countreg,1));
  1542. r.enum:=R_F0;
  1543. list.concat(taicpu.op_reg_ref(A_LFDU,r,src));
  1544. list.concat(taicpu.op_reg_ref(A_STFDU,r,dst));
  1545. a_jmp(list,A_BC,C_NE,0,lab);
  1546. free_scratch_reg(list,countreg);
  1547. a_reg_dealloc(list,r);
  1548. len := len mod 8;
  1549. end;
  1550. count := len div 8;
  1551. if count > 0 then
  1552. { unrolled loop }
  1553. begin
  1554. r.enum:=R_F0;
  1555. a_reg_alloc(list,r);
  1556. for count2 := 1 to count do
  1557. begin
  1558. a_loadfpu_ref_reg(list,OS_F64,src,r);
  1559. a_loadfpu_reg_ref(list,OS_F64,r,dst);
  1560. inc(src.offset,8);
  1561. inc(dst.offset,8);
  1562. end;
  1563. a_reg_dealloc(list,r);
  1564. len := len mod 8;
  1565. end;
  1566. if (len and 4) <> 0 then
  1567. begin
  1568. r.enum:=R_INTREGISTER;
  1569. r.number:=NR_R0;
  1570. a_reg_alloc(list,r);
  1571. a_load_ref_reg(list,OS_32,src,r);
  1572. a_load_reg_ref(list,OS_32,r,dst);
  1573. inc(src.offset,4);
  1574. inc(dst.offset,4);
  1575. a_reg_dealloc(list,r);
  1576. end;
  1577. { copy the leftovers }
  1578. if (len and 2) <> 0 then
  1579. begin
  1580. r.enum:=R_INTREGISTER;
  1581. r.number:=NR_R0;
  1582. a_reg_alloc(list,r);
  1583. a_load_ref_reg(list,OS_16,src,r);
  1584. a_load_reg_ref(list,OS_16,r,dst);
  1585. inc(src.offset,2);
  1586. inc(dst.offset,2);
  1587. a_reg_dealloc(list,r);
  1588. end;
  1589. if (len and 1) <> 0 then
  1590. begin
  1591. r.enum:=R_INTREGISTER;
  1592. r.number:=NR_R0;
  1593. a_reg_alloc(list,r);
  1594. a_load_ref_reg(list,OS_8,src,r);
  1595. a_load_reg_ref(list,OS_8,r,dst);
  1596. a_reg_dealloc(list,r);
  1597. end;
  1598. if orgsrc then
  1599. begin
  1600. if delsource then
  1601. reference_release(list,source);
  1602. end
  1603. else
  1604. free_scratch_reg(list,src.base);
  1605. if not orgdst then
  1606. free_scratch_reg(list,dst.base);
  1607. end;
  1608. procedure tcgppc.g_overflowcheck(list: taasmoutput; const p: tnode);
  1609. var
  1610. hl : tasmlabel;
  1611. r:Tregister;
  1612. begin
  1613. if not(cs_check_overflow in aktlocalswitches) then
  1614. exit;
  1615. objectlibrary.getlabel(hl);
  1616. if not ((p.resulttype.def.deftype=pointerdef) or
  1617. ((p.resulttype.def.deftype=orddef) and
  1618. (torddef(p.resulttype.def).typ in [u64bit,u16bit,u32bit,u8bit,uchar,
  1619. bool8bit,bool16bit,bool32bit]))) then
  1620. begin
  1621. r.enum:=R_CR7;
  1622. list.concat(taicpu.op_reg(A_MCRXR,r));
  1623. a_jmp(list,A_BC,C_OV,7,hl)
  1624. end
  1625. else
  1626. a_jmp_cond(list,OC_AE,hl);
  1627. a_call_name(list,'FPC_OVERFLOW');
  1628. a_label(list,hl);
  1629. end;
  1630. {***************** This is private property, keep out! :) *****************}
  1631. function tcgppc.issimpleref(const ref: treference): boolean;
  1632. begin
  1633. if (ref.base.number = NR_NO) and
  1634. (ref.index.number <> NR_NO) then
  1635. internalerror(200208101);
  1636. result :=
  1637. not(assigned(ref.symbol)) and
  1638. (((ref.index.number = NR_NO) and
  1639. (ref.offset >= low(smallint)) and
  1640. (ref.offset <= high(smallint))) or
  1641. ((ref.index.number <> NR_NO) and
  1642. (ref.offset = 0)));
  1643. end;
  1644. function tcgppc.fixref(list: taasmoutput; var ref: treference): boolean;
  1645. var
  1646. tmpreg: tregister;
  1647. begin
  1648. result := false;
  1649. if (ref.base.number = NR_NO) then
  1650. ref.base := ref.index;
  1651. if (ref.base.number <> NR_NO) then
  1652. begin
  1653. if (ref.index.number <> NR_NO) and
  1654. ((ref.offset <> 0) or assigned(ref.symbol)) then
  1655. begin
  1656. result := true;
  1657. tmpreg := cg.get_scratch_reg_int(list,OS_INT);
  1658. if not assigned(ref.symbol) and
  1659. (cardinal(ref.offset-low(smallint)) <=
  1660. high(smallint)-low(smallint)) then
  1661. begin
  1662. list.concat(taicpu.op_reg_reg_const(
  1663. A_ADDI,tmpreg,ref.base,ref.offset));
  1664. ref.offset := 0;
  1665. end
  1666. else
  1667. begin
  1668. list.concat(taicpu.op_reg_reg_reg(
  1669. A_ADD,tmpreg,ref.base,ref.index));
  1670. ref.index.number := NR_NO;
  1671. end;
  1672. ref.base := tmpreg;
  1673. end
  1674. end
  1675. else
  1676. if ref.index.number <> NR_NO then
  1677. internalerror(200208102);
  1678. end;
  1679. { find out whether a is of the form 11..00..11b or 00..11...00. If }
  1680. { that's the case, we can use rlwinm to do an AND operation }
  1681. function tcgppc.get_rlwi_const(a: aword; var l1, l2: longint): boolean;
  1682. var
  1683. temp : longint;
  1684. testbit : aword;
  1685. compare: boolean;
  1686. begin
  1687. get_rlwi_const := false;
  1688. if (a = 0) or (a = $ffffffff) then
  1689. exit;
  1690. { start with the lowest bit }
  1691. testbit := 1;
  1692. { check its value }
  1693. compare := boolean(a and testbit);
  1694. { find out how long the run of bits with this value is }
  1695. { (it's impossible that all bits are 1 or 0, because in that case }
  1696. { this function wouldn't have been called) }
  1697. l1 := 31;
  1698. while (((a and testbit) <> 0) = compare) do
  1699. begin
  1700. testbit := testbit shl 1;
  1701. dec(l1);
  1702. end;
  1703. { check the length of the run of bits that comes next }
  1704. compare := not compare;
  1705. l2 := l1;
  1706. while (((a and testbit) <> 0) = compare) and
  1707. (l2 >= 0) do
  1708. begin
  1709. testbit := testbit shl 1;
  1710. dec(l2);
  1711. end;
  1712. { and finally the check whether the rest of the bits all have the }
  1713. { same value }
  1714. compare := not compare;
  1715. temp := l2;
  1716. if temp >= 0 then
  1717. if (a shr (31-temp)) <> ((-ord(compare)) shr (31-temp)) then
  1718. exit;
  1719. { we have done "not(not(compare))", so compare is back to its }
  1720. { initial value. If the lowest bit was 0, a is of the form }
  1721. { 00..11..00 and we need "rlwinm reg,reg,0,l2+1,l1", (+1 }
  1722. { because l2 now contains the position of the last zero of the }
  1723. { first run instead of that of the first 1) so switch l1 and l2 }
  1724. { in that case (we will generate "rlwinm reg,reg,0,l1,l2") }
  1725. if not compare then
  1726. begin
  1727. temp := l1;
  1728. l1 := l2+1;
  1729. l2 := temp;
  1730. end
  1731. else
  1732. { otherwise, l1 currently contains the position of the last }
  1733. { zero instead of that of the first 1 of the second run -> +1 }
  1734. inc(l1);
  1735. { the following is the same as "if l1 = -1 then l1 := 31;" }
  1736. l1 := l1 and 31;
  1737. l2 := l2 and 31;
  1738. get_rlwi_const := true;
  1739. end;
  1740. procedure tcgppc.a_load_store(list:taasmoutput;op: tasmop;reg:tregister;
  1741. ref: treference);
  1742. var
  1743. tmpreg: tregister;
  1744. tmpref: treference;
  1745. r : Tregister;
  1746. begin
  1747. tmpreg.number := NR_NO;
  1748. if assigned(ref.symbol) or
  1749. (cardinal(ref.offset-low(smallint)) >
  1750. high(smallint)-low(smallint)) then
  1751. begin
  1752. if target_info.system = system_powerpc_macos then
  1753. begin
  1754. if ref.base.number <> NR_NO then
  1755. begin
  1756. if macos_direct_globals then
  1757. begin
  1758. {Generates
  1759. add tempreg, ref.base, RTOC
  1760. op reg, symbolplusoffset, tempreg
  1761. which is eqvivalent to the more comprehensive
  1762. addi tempreg, RTOC, symbolplusoffset
  1763. add tempreg, ref.base, tempreg
  1764. op reg, tempreg
  1765. but which saves one instruction.}
  1766. tmpreg := get_scratch_reg_address(list);
  1767. reference_reset(tmpref);
  1768. tmpref.symbol := ref.symbol;
  1769. tmpref.offset := ref.offset;
  1770. tmpref.symaddr := refs_full;
  1771. tmpref.base:= tmpreg;
  1772. r.enum:=R_INTREGISTER;
  1773. r.number:=NR_RTOC;
  1774. list.concat(taicpu.op_reg_reg_reg(A_ADD,tmpreg,
  1775. ref.base,r));
  1776. list.concat(taicpu.op_reg_ref(op,reg,tmpref));
  1777. end
  1778. else
  1779. begin
  1780. tmpreg := get_scratch_reg_address(list);
  1781. reference_reset(tmpref);
  1782. tmpref.symbol := ref.symbol;
  1783. tmpref.offset := ref.offset;
  1784. tmpref.symaddr := refs_full;
  1785. tmpref.base.enum:= R_INTREGISTER;
  1786. tmpref.base.number:= NR_RTOC;
  1787. list.concat(taicpu.op_reg_ref(A_LWZ,tmpreg,tmpref));
  1788. list.concat(taicpu.op_reg_reg_reg(A_ADD,tmpreg,
  1789. ref.base,tmpreg));
  1790. reference_reset(tmpref);
  1791. tmpref.offset := 0;
  1792. tmpref.symaddr := refs_full;
  1793. tmpref.base:= tmpreg;
  1794. list.concat(taicpu.op_reg_ref(op,reg,tmpref));
  1795. end;
  1796. //list.concat(tai_comment.create(strpnew('**** a_load_store 1')));
  1797. end
  1798. else
  1799. begin
  1800. if macos_direct_globals then
  1801. begin
  1802. reference_reset(tmpref);
  1803. tmpref.symbol := ref.symbol;
  1804. tmpref.offset := ref.offset;
  1805. tmpref.symaddr := refs_full;
  1806. tmpref.base.enum:= R_INTREGISTER;
  1807. tmpref.base.number:= NR_RTOC;
  1808. list.concat(taicpu.op_reg_ref(op,reg,tmpref));
  1809. end
  1810. else
  1811. begin
  1812. tmpreg := get_scratch_reg_address(list);
  1813. reference_reset(tmpref);
  1814. tmpref.symbol := ref.symbol;
  1815. tmpref.offset := ref.offset;
  1816. tmpref.symaddr := refs_full;
  1817. tmpref.base.enum:= R_INTREGISTER;
  1818. tmpref.base.number:= NR_RTOC;
  1819. list.concat(taicpu.op_reg_ref(A_LWZ,tmpreg,tmpref));
  1820. reference_reset(tmpref);
  1821. tmpref.offset := 0;
  1822. tmpref.symaddr := refs_full;
  1823. tmpref.base:= tmpreg;
  1824. list.concat(taicpu.op_reg_ref(op,reg,tmpref));
  1825. end;
  1826. //list.concat(tai_comment.create(strpnew('*** a_load_store 2')));
  1827. end;
  1828. end
  1829. else
  1830. begin
  1831. tmpreg := get_scratch_reg_address(list);
  1832. reference_reset(tmpref);
  1833. tmpref.symbol := ref.symbol;
  1834. tmpref.offset := ref.offset;
  1835. tmpref.symaddr := refs_ha;
  1836. if ref.base.number <> NR_NO then
  1837. list.concat(taicpu.op_reg_reg_ref(A_ADDIS,tmpreg,
  1838. ref.base,tmpref))
  1839. else
  1840. list.concat(taicpu.op_reg_ref(A_LIS,tmpreg,tmpref));
  1841. ref.base := tmpreg;
  1842. ref.symaddr := refs_l;
  1843. list.concat(taicpu.op_reg_ref(op,reg,ref));
  1844. end
  1845. end
  1846. else
  1847. list.concat(taicpu.op_reg_ref(op,reg,ref));
  1848. if (tmpreg.number <> NR_NO) then
  1849. free_scratch_reg(list,tmpreg);
  1850. end;
  1851. procedure tcgppc.a_jmp(list: taasmoutput; op: tasmop; c: tasmcondflag;
  1852. crval: longint; l: tasmlabel);
  1853. var
  1854. p: taicpu;
  1855. begin
  1856. p := taicpu.op_sym(op,objectlibrary.newasmsymbol(l.name));
  1857. if op <> A_B then
  1858. create_cond_norm(c,crval,p.condition);
  1859. p.is_jmp := true;
  1860. list.concat(p)
  1861. end;
  1862. procedure tcg64fppc.a_op64_reg_reg(list : taasmoutput;op:TOpCG;regsrc,regdst : tregister64);
  1863. begin
  1864. a_op64_reg_reg_reg(list,op,regsrc,regdst,regdst);
  1865. end;
  1866. procedure tcg64fppc.a_op64_const_reg(list : taasmoutput;op:TOpCG;value : qword;reg : tregister64);
  1867. begin
  1868. a_op64_const_reg_reg(list,op,value,reg,reg);
  1869. end;
  1870. procedure tcg64fppc.a_op64_reg_reg_reg(list: taasmoutput;op:TOpCG;regsrc1,regsrc2,regdst : tregister64);
  1871. begin
  1872. case op of
  1873. OP_AND,OP_OR,OP_XOR:
  1874. begin
  1875. cg.a_op_reg_reg_reg(list,op,OS_32,regsrc1.reglo,regsrc2.reglo,regdst.reglo);
  1876. cg.a_op_reg_reg_reg(list,op,OS_32,regsrc1.reghi,regsrc2.reghi,regdst.reghi);
  1877. end;
  1878. OP_ADD:
  1879. begin
  1880. list.concat(taicpu.op_reg_reg_reg(A_ADDC,regdst.reglo,regsrc1.reglo,regsrc2.reglo));
  1881. list.concat(taicpu.op_reg_reg_reg(A_ADDE,regdst.reghi,regsrc1.reghi,regsrc2.reghi));
  1882. end;
  1883. OP_SUB:
  1884. begin
  1885. list.concat(taicpu.op_reg_reg_reg(A_SUBC,regdst.reglo,regsrc2.reglo,regsrc1.reglo));
  1886. list.concat(taicpu.op_reg_reg_reg(A_SUBFE,regdst.reghi,regsrc1.reghi,regsrc2.reghi));
  1887. end;
  1888. else
  1889. internalerror(2002072801);
  1890. end;
  1891. end;
  1892. procedure tcg64fppc.a_op64_const_reg_reg(list: taasmoutput;op:TOpCG;value : qword;regsrc,regdst : tregister64);
  1893. const
  1894. ops: array[boolean,1..3] of tasmop = ((A_ADDIC,A_ADDC,A_ADDZE),
  1895. (A_SUBIC,A_SUBC,A_ADDME));
  1896. var
  1897. tmpreg: tregister;
  1898. tmpreg64: tregister64;
  1899. issub: boolean;
  1900. begin
  1901. case op of
  1902. OP_AND,OP_OR,OP_XOR:
  1903. begin
  1904. cg.a_op_const_reg_reg(list,op,OS_32,cardinal(value),regsrc.reglo,regdst.reglo);
  1905. cg.a_op_const_reg_reg(list,op,OS_32,value shr 32,regsrc.reghi,
  1906. regdst.reghi);
  1907. end;
  1908. OP_ADD, OP_SUB:
  1909. begin
  1910. if (longint(value) <> 0) then
  1911. begin
  1912. issub := op = OP_SUB;
  1913. if (longint(value)-ord(issub) >= -32768) and
  1914. (longint(value)-ord(issub) <= 32767) then
  1915. begin
  1916. list.concat(taicpu.op_reg_reg_const(ops[issub,1],
  1917. regdst.reglo,regsrc.reglo,longint(value)));
  1918. list.concat(taicpu.op_reg_reg(ops[issub,3],
  1919. regdst.reghi,regsrc.reghi));
  1920. end
  1921. else if ((value shr 32) = 0) then
  1922. begin
  1923. tmpreg := cg.get_scratch_reg_int(list,OS_32);
  1924. cg.a_load_const_reg(list,OS_32,cardinal(value),tmpreg);
  1925. list.concat(taicpu.op_reg_reg_reg(ops[issub,2],
  1926. regdst.reglo,regsrc.reglo,tmpreg));
  1927. cg.free_scratch_reg(list,tmpreg);
  1928. list.concat(taicpu.op_reg_reg(ops[issub,3],
  1929. regdst.reghi,regsrc.reghi));
  1930. end
  1931. else
  1932. begin
  1933. tmpreg64.reglo := cg.get_scratch_reg_int(list,OS_INT);
  1934. tmpreg64.reghi := cg.get_scratch_reg_int(list,OS_INT);
  1935. a_load64_const_reg(list,value,tmpreg64);
  1936. a_op64_reg_reg_reg(list,op,tmpreg64,regsrc,regdst);
  1937. cg.free_scratch_reg(list,tmpreg64.reghi);
  1938. cg.free_scratch_reg(list,tmpreg64.reglo);
  1939. end
  1940. end
  1941. else
  1942. begin
  1943. cg.a_load_reg_reg(list,OS_INT,OS_INT,regsrc.reglo,regdst.reglo);
  1944. cg.a_op_const_reg_reg(list,op,OS_32,value shr 32,regsrc.reghi,
  1945. regdst.reghi);
  1946. end;
  1947. end;
  1948. else
  1949. internalerror(2002072802);
  1950. end;
  1951. end;
  1952. begin
  1953. cg := tcgppc.create;
  1954. cg64 :=tcg64fppc.create;
  1955. end.
  1956. {
  1957. $Log$
  1958. Revision 1.78 2003-04-16 09:26:55 jonas
  1959. * assembler procedures now again get a stackframe if they have local
  1960. variables. No space is reserved for a function result however.
  1961. Also, the register parameters aren't automatically saved on the stack
  1962. anymore in assembler procedures.
  1963. Revision 1.77 2003/04/06 16:39:11 jonas
  1964. * don't generate entry/exit code for assembler procedures
  1965. Revision 1.76 2003/03/22 18:01:13 jonas
  1966. * fixed linux entry/exit code generation
  1967. Revision 1.75 2003/03/19 14:26:26 jonas
  1968. * fixed R_TOC bugs introduced by new register allocator conversion
  1969. Revision 1.74 2003/03/13 22:57:45 olle
  1970. * change in a_loadaddr_ref_reg
  1971. Revision 1.73 2003/03/12 22:43:38 jonas
  1972. * more powerpc and generic fixes related to the new register allocator
  1973. Revision 1.72 2003/03/11 21:46:24 jonas
  1974. * lots of new regallocator fixes, both in generic and ppc-specific code
  1975. (ppc compiler still can't compile the linux system unit though)
  1976. Revision 1.71 2003/02/19 22:00:16 daniel
  1977. * Code generator converted to new register notation
  1978. - Horribily outdated todo.txt removed
  1979. Revision 1.70 2003/01/13 17:17:50 olle
  1980. * changed global var access, TOC now contain pointers to globals
  1981. * fixed handling of function pointers
  1982. Revision 1.69 2003/01/09 22:00:53 florian
  1983. * fixed some PowerPC issues
  1984. Revision 1.68 2003/01/08 18:43:58 daniel
  1985. * Tregister changed into a record
  1986. Revision 1.67 2002/12/15 19:22:01 florian
  1987. * fixed some crashes and a rte 201
  1988. Revision 1.66 2002/11/28 10:55:16 olle
  1989. * macos: changing code gen for references to globals
  1990. Revision 1.65 2002/11/07 15:50:23 jonas
  1991. * fixed bctr(l) problems
  1992. Revision 1.64 2002/11/04 18:24:19 olle
  1993. * macos: globals are located in TOC and relative r2, instead of absolute
  1994. Revision 1.63 2002/10/28 22:24:28 olle
  1995. * macos entry/exit: only used registers are saved
  1996. - macos entry/exit: stackptr not saved in r31 anymore
  1997. * macos entry/exit: misc fixes
  1998. Revision 1.62 2002/10/19 23:51:48 olle
  1999. * macos stack frame size computing updated
  2000. + macos epilogue: control register now restored
  2001. * macos prologue and epilogue: fp reg now saved and restored
  2002. Revision 1.61 2002/10/19 12:50:36 olle
  2003. * reorganized prologue and epilogue routines
  2004. Revision 1.60 2002/10/02 21:49:51 florian
  2005. * all A_BL instructions replaced by calls to a_call_name
  2006. Revision 1.59 2002/10/02 13:24:58 jonas
  2007. * changed a_call_* so that no superfluous code is generated anymore
  2008. Revision 1.58 2002/09/17 18:54:06 jonas
  2009. * a_load_reg_reg() now has two size parameters: source and dest. This
  2010. allows some optimizations on architectures that don't encode the
  2011. register size in the register name.
  2012. Revision 1.57 2002/09/10 21:22:25 jonas
  2013. + added some internal errors
  2014. * fixed bug in sysv exit code
  2015. Revision 1.56 2002/09/08 20:11:56 jonas
  2016. * fixed TOpCmp2AsmCond array (some unsigned equivalents were wrong)
  2017. Revision 1.55 2002/09/08 13:03:26 jonas
  2018. * several large offset-related fixes
  2019. Revision 1.54 2002/09/07 17:54:58 florian
  2020. * first part of PowerPC fixes
  2021. Revision 1.53 2002/09/07 15:25:14 peter
  2022. * old logs removed and tabs fixed
  2023. Revision 1.52 2002/09/02 10:14:51 jonas
  2024. + a_call_reg()
  2025. * small fix in a_call_ref()
  2026. Revision 1.51 2002/09/02 06:09:02 jonas
  2027. * fixed range error
  2028. Revision 1.50 2002/09/01 21:04:49 florian
  2029. * several powerpc related stuff fixed
  2030. Revision 1.49 2002/09/01 12:09:27 peter
  2031. + a_call_reg, a_call_loc added
  2032. * removed exprasmlist references
  2033. Revision 1.48 2002/08/31 21:38:02 jonas
  2034. * fixed a_call_ref (it should load ctr, not lr)
  2035. Revision 1.47 2002/08/31 21:30:45 florian
  2036. * fixed several problems caused by Jonas' commit :)
  2037. Revision 1.46 2002/08/31 19:25:50 jonas
  2038. + implemented a_call_ref()
  2039. Revision 1.45 2002/08/18 22:16:14 florian
  2040. + the ppc gas assembler writer adds now registers aliases
  2041. to the assembler file
  2042. Revision 1.44 2002/08/17 18:23:53 florian
  2043. * some assembler writer bugs fixed
  2044. Revision 1.43 2002/08/17 09:23:49 florian
  2045. * first part of procinfo rewrite
  2046. Revision 1.42 2002/08/16 14:24:59 carl
  2047. * issameref() to test if two references are the same (then emit no opcodes)
  2048. + ret_in_reg to replace ret_in_acc
  2049. (fix some register allocation bugs at the same time)
  2050. + save_std_register now has an extra parameter which is the
  2051. usedinproc registers
  2052. Revision 1.41 2002/08/15 08:13:54 carl
  2053. - a_load_sym_ofs_reg removed
  2054. * loadvmt now calls loadaddr_ref_reg instead
  2055. Revision 1.40 2002/08/11 14:32:32 peter
  2056. * renamed current_library to objectlibrary
  2057. Revision 1.39 2002/08/11 13:24:18 peter
  2058. * saving of asmsymbols in ppu supported
  2059. * asmsymbollist global is removed and moved into a new class
  2060. tasmlibrarydata that will hold the info of a .a file which
  2061. corresponds with a single module. Added librarydata to tmodule
  2062. to keep the library info stored for the module. In the future the
  2063. objectfiles will also be stored to the tasmlibrarydata class
  2064. * all getlabel/newasmsymbol and friends are moved to the new class
  2065. Revision 1.38 2002/08/11 11:39:31 jonas
  2066. + powerpc-specific genlinearlist
  2067. Revision 1.37 2002/08/10 17:15:31 jonas
  2068. * various fixes and optimizations
  2069. Revision 1.36 2002/08/06 20:55:23 florian
  2070. * first part of ppc calling conventions fix
  2071. Revision 1.35 2002/08/06 07:12:05 jonas
  2072. * fixed bug in g_flags2reg()
  2073. * and yet more constant operation fixes :)
  2074. Revision 1.34 2002/08/05 08:58:53 jonas
  2075. * fixed compilation problems
  2076. Revision 1.33 2002/08/04 12:57:55 jonas
  2077. * more misc. fixes, mostly constant-related
  2078. }