cgcpu.pas 107 KB

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