cgcpu.pas 101 KB

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