cgcpu.pas 101 KB

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