cgcpu.pas 108 KB

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