cgcpu.pas 104 KB

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