cgcpu.pas 104 KB

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