cgcpu.pas 104 KB

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