cgcpu.pas 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340
  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. cgbase,cgobj,
  23. aasmbase,aasmcpu,aasmtai,
  24. cpubase,cpuinfo,node,cg64f32,cginfo;
  25. type
  26. tcgppc = class(tcg)
  27. { passing parameters, per default the parameter is pushed }
  28. { nr gives the number of the parameter (enumerated from }
  29. { left to right), this allows to move the parameter to }
  30. { register, if the cpu supports register calling }
  31. { conventions }
  32. procedure a_param_const(list : taasmoutput;size : tcgsize;a : aword;const locpara : tparalocation);override;
  33. procedure a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;const locpara : tparalocation);override;
  34. procedure a_paramaddr_ref(list : taasmoutput;const r : treference;const locpara : tparalocation);override;
  35. procedure a_call_name(list : taasmoutput;const s : string);override;
  36. procedure a_call_reg(list : taasmoutput;reg: tregister); override;
  37. procedure a_call_ref(list : taasmoutput;const ref : treference);override;
  38. procedure a_op_const_reg(list : taasmoutput; Op: TOpCG; a: AWord; reg: TRegister); override;
  39. procedure a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; src, dst: TRegister); override;
  40. procedure a_op_const_reg_reg(list: taasmoutput; op: TOpCg;
  41. size: tcgsize; a: aword; src, dst: tregister); override;
  42. procedure a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;
  43. size: tcgsize; src1, src2, dst: tregister); override;
  44. { move instructions }
  45. procedure a_load_const_reg(list : taasmoutput; size: tcgsize; a : aword;reg : tregister);override;
  46. procedure a_load_reg_ref(list : taasmoutput; size: tcgsize; reg : tregister;const ref : treference);override;
  47. procedure a_load_ref_reg(list : taasmoutput;size : tcgsize;const Ref : treference;reg : tregister);override;
  48. procedure a_load_reg_reg(list : taasmoutput;fromsize, tosize : tcgsize;reg1,reg2 : tregister);override;
  49. { fpu move instructions }
  50. procedure a_loadfpu_reg_reg(list: taasmoutput; reg1, reg2: tregister); override;
  51. procedure a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister); override;
  52. procedure a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference); override;
  53. { comparison operations }
  54. procedure a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;reg : tregister;
  55. l : tasmlabel);override;
  56. procedure a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;reg1,reg2 : tregister;l : tasmlabel); override;
  57. procedure a_jmp_always(list : taasmoutput;l: tasmlabel); override;
  58. procedure a_jmp_flags(list : taasmoutput;const f : TResFlags;l: tasmlabel); override;
  59. procedure g_flags2reg(list: taasmoutput; size: TCgSize; const f: TResFlags; reg: TRegister); override;
  60. procedure g_stackframe_entry(list : taasmoutput;localsize : longint);override;
  61. procedure g_return_from_proc(list : taasmoutput;parasize : aword); override;
  62. procedure g_restore_frame_pointer(list : taasmoutput);override;
  63. procedure a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);override;
  64. procedure g_concatcopy(list : taasmoutput;const source,dest : treference;len : aword; delsource,loadref : boolean);override;
  65. procedure g_overflowcheck(list: taasmoutput; const p: tnode); override;
  66. { find out whether a is of the form 11..00..11b or 00..11...00. If }
  67. { that's the case, we can use rlwinm to do an AND operation }
  68. function get_rlwi_const(a: aword; var l1, l2: longint): boolean;
  69. procedure g_save_standard_registers(list : taasmoutput; usedinproc : Tsupregset);override;
  70. procedure g_restore_standard_registers(list : taasmoutput; usedinproc : Tsupregset);override;
  71. procedure g_save_all_registers(list : taasmoutput);override;
  72. procedure g_restore_all_registers(list : taasmoutput;selfused,accused,acchiused:boolean);override;
  73. procedure a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel);
  74. private
  75. procedure g_stackframe_entry_sysv(list : taasmoutput;localsize : longint);
  76. procedure g_return_from_proc_sysv(list : taasmoutput;parasize : aword);
  77. procedure g_stackframe_entry_mac(list : taasmoutput;localsize : longint);
  78. procedure g_return_from_proc_mac(list : taasmoutput;parasize : aword);
  79. { Make sure ref is a valid reference for the PowerPC and sets the }
  80. { base to the value of the index if (base = R_NO). }
  81. { Returns true if the reference contained a base, index and an }
  82. { offset or symbol, in which case the base will have been changed }
  83. { to a tempreg (which has to be freed by the caller) containing }
  84. { the sum of part of the original reference }
  85. function fixref(list: taasmoutput; var ref: treference): boolean;
  86. { returns whether a reference can be used immediately in a powerpc }
  87. { instruction }
  88. function issimpleref(const ref: treference): boolean;
  89. { contains the common code of a_load_reg_ref and a_load_ref_reg }
  90. procedure a_load_store(list:taasmoutput;op: tasmop;reg:tregister;
  91. ref: treference);
  92. { creates the correct branch instruction for a given combination }
  93. { of asmcondflags and destination addressing mode }
  94. procedure a_jmp(list: taasmoutput; op: tasmop;
  95. c: tasmcondflag; crval: longint; l: tasmlabel);
  96. end;
  97. tcg64fppc = class(tcg64f32)
  98. procedure a_op64_reg_reg(list : taasmoutput;op:TOpCG;regsrc,regdst : tregister64);override;
  99. procedure a_op64_const_reg(list : taasmoutput;op:TOpCG;value : qword;reg : tregister64);override;
  100. procedure a_op64_const_reg_reg(list: taasmoutput;op:TOpCG;value : qword;regsrc,regdst : tregister64);override;
  101. procedure a_op64_reg_reg_reg(list: taasmoutput;op:TOpCG;regsrc1,regsrc2,regdst : tregister64);override;
  102. end;
  103. const
  104. TOpCG2AsmOpConstLo: Array[topcg] of TAsmOp = (A_NONE,A_ADDI,A_ANDI_,A_DIVWU,
  105. A_DIVW,A_MULLW, A_MULLW, A_NONE,A_NONE,A_ORI,
  106. A_SRAWI,A_SLWI,A_SRWI,A_SUBI,A_XORI);
  107. TOpCG2AsmOpConstHi: Array[topcg] of TAsmOp = (A_NONE,A_ADDIS,A_ANDIS_,
  108. A_DIVWU,A_DIVW, A_MULLW,A_MULLW,A_NONE,A_NONE,
  109. A_ORIS,A_NONE, A_NONE,A_NONE,A_SUBIS,A_XORIS);
  110. TOpCmp2AsmCond: Array[topcmp] of TAsmCondFlag = (C_NONE,C_EQ,C_GT,
  111. C_LT,C_GE,C_LE,C_NE,C_LE,C_LT,C_GE,C_GT);
  112. implementation
  113. uses
  114. globtype,globals,verbose,systems,cutils,symconst,symdef,rgobj,tgobj,cpupi;
  115. { parameter passing... Still needs extra support from the processor }
  116. { independent code generator }
  117. procedure tcgppc.a_param_const(list : taasmoutput;size : tcgsize;a : aword;const locpara : tparalocation);
  118. var
  119. ref: treference;
  120. begin
  121. case locpara.loc of
  122. LOC_REGISTER,LOC_CREGISTER:
  123. a_load_const_reg(list,size,a,locpara.register);
  124. LOC_REFERENCE:
  125. begin
  126. reference_reset(ref);
  127. ref.base:=locpara.reference.index;
  128. ref.offset:=locpara.reference.offset;
  129. a_load_const_ref(list,size,a,ref);
  130. end;
  131. else
  132. internalerror(2002081101);
  133. end;
  134. if locpara.sp_fixup<>0 then
  135. internalerror(2002081102);
  136. end;
  137. procedure tcgppc.a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;const locpara : tparalocation);
  138. var
  139. ref: treference;
  140. tmpreg: tregister;
  141. begin
  142. case locpara.loc of
  143. LOC_REGISTER,LOC_CREGISTER:
  144. a_load_ref_reg(list,size,r,locpara.register);
  145. LOC_REFERENCE:
  146. begin
  147. reference_reset(ref);
  148. ref.base:=locpara.reference.index;
  149. ref.offset:=locpara.reference.offset;
  150. tmpreg := get_scratch_reg_int(list,size);
  151. a_load_ref_reg(list,size,r,tmpreg);
  152. a_load_reg_ref(list,size,tmpreg,ref);
  153. free_scratch_reg(list,tmpreg);
  154. end;
  155. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  156. case size of
  157. OS_32:
  158. a_loadfpu_ref_reg(list,OS_F32,r,locpara.register);
  159. OS_64:
  160. a_loadfpu_ref_reg(list,OS_F64,r,locpara.register);
  161. else
  162. internalerror(2002072801);
  163. end;
  164. else
  165. internalerror(2002081103);
  166. end;
  167. if locpara.sp_fixup<>0 then
  168. internalerror(2002081104);
  169. end;
  170. procedure tcgppc.a_paramaddr_ref(list : taasmoutput;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_loadaddr_ref_reg(list,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 := get_scratch_reg_address(list);
  184. a_loadaddr_ref_reg(list,r,tmpreg);
  185. a_load_reg_ref(list,OS_ADDR,tmpreg,ref);
  186. free_scratch_reg(list,tmpreg);
  187. end;
  188. else
  189. internalerror(2002080701);
  190. end;
  191. end;
  192. { calling a procedure by name }
  193. procedure tcgppc.a_call_name(list : taasmoutput;const s : string);
  194. var
  195. href : treference;
  196. begin
  197. {MacOS: The linker on MacOS (PPCLink) inserts a call to glue code,
  198. if it is a cross-TOC call. If so, it also replaces the NOP
  199. with some restore code.}
  200. list.concat(taicpu.op_sym(A_BL,objectlibrary.newasmsymbol(s)));
  201. if target_info.system=system_powerpc_macos then
  202. list.concat(taicpu.op_none(A_NOP));
  203. procinfo.flags:=procinfo.flags or pi_do_call;
  204. end;
  205. { calling a procedure by address }
  206. procedure tcgppc.a_call_reg(list : taasmoutput;reg: tregister);
  207. var
  208. tmpreg : tregister;
  209. tmpref : treference;
  210. begin
  211. if target_info.system=system_powerpc_macos then
  212. begin
  213. {Generate instruction to load the procedure address from
  214. the transition vector.}
  215. //TODO: Support cross-TOC calls.
  216. tmpreg := get_scratch_reg_int(list,OS_INT);
  217. reference_reset(tmpref);
  218. tmpref.offset := 0;
  219. //tmpref.symaddr := refs_full;
  220. tmpref.base:= reg;
  221. list.concat(taicpu.op_reg_ref(A_LWZ,tmpreg,tmpref));
  222. list.concat(taicpu.op_reg(A_MTCTR,tmpreg));
  223. free_scratch_reg(list,tmpreg);
  224. end
  225. else
  226. list.concat(taicpu.op_reg(A_MTCTR,reg));
  227. list.concat(taicpu.op_none(A_BCTRL));
  228. //if target_info.system=system_powerpc_macos then
  229. // //NOP is not needed here.
  230. // list.concat(taicpu.op_none(A_NOP));
  231. procinfo.flags:=procinfo.flags or pi_do_call;
  232. //list.concat(tai_comment.create(strpnew('***** a_call_reg')));
  233. end;
  234. { calling a procedure by address }
  235. procedure tcgppc.a_call_ref(list : taasmoutput;const ref : treference);
  236. var
  237. tmpreg : tregister;
  238. tmpref : treference;
  239. begin
  240. tmpreg := get_scratch_reg_int(list,OS_ADDR);
  241. a_load_ref_reg(list,OS_ADDR,ref,tmpreg);
  242. if target_info.system=system_powerpc_macos then
  243. begin
  244. {Generate instruction to load the procedure address from
  245. the transition vector.}
  246. //TODO: Support cross-TOC calls.
  247. reference_reset(tmpref);
  248. tmpref.offset := 0;
  249. //tmpref.symaddr := refs_full;
  250. tmpref.base:= tmpreg;
  251. list.concat(taicpu.op_reg_ref(A_LWZ,tmpreg,tmpref));
  252. end;
  253. list.concat(taicpu.op_reg(A_MTCTR,tmpreg));
  254. free_scratch_reg(list,tmpreg);
  255. list.concat(taicpu.op_none(A_BCTRL));
  256. //if target_info.system=system_powerpc_macos then
  257. // //NOP is not needed here.
  258. // list.concat(taicpu.op_none(A_NOP));
  259. procinfo.flags:=procinfo.flags or pi_do_call;
  260. //list.concat(tai_comment.create(strpnew('***** a_call_ref')));
  261. end;
  262. {********************** load instructions ********************}
  263. procedure tcgppc.a_load_const_reg(list : taasmoutput; size: TCGSize; a : aword; reg : TRegister);
  264. begin
  265. if not(size in [OS_8,OS_S8,OS_16,OS_S16,OS_32,OS_S32]) then
  266. internalerror(2002090902);
  267. if (longint(a) >= low(smallint)) and
  268. (longint(a) <= high(smallint)) then
  269. list.concat(taicpu.op_reg_const(A_LI,reg,smallint(a)))
  270. else if ((a and $ffff) <> 0) then
  271. begin
  272. list.concat(taicpu.op_reg_const(A_LI,reg,smallint(a and $ffff)));
  273. if ((a shr 16) <> 0) or
  274. (smallint(a and $ffff) < 0) then
  275. list.concat(taicpu.op_reg_reg_const(A_ADDIS,reg,reg,
  276. smallint((a shr 16)+ord(smallint(a and $ffff) < 0))))
  277. end
  278. else
  279. list.concat(taicpu.op_reg_const(A_LIS,reg,smallint(a shr 16)));
  280. end;
  281. procedure tcgppc.a_load_reg_ref(list : taasmoutput; size: TCGSize; reg : tregister;const ref : treference);
  282. const
  283. StoreInstr: Array[OS_8..OS_32,boolean, boolean] of TAsmOp =
  284. { indexed? updating?}
  285. (((A_STB,A_STBU),(A_STBX,A_STBUX)),
  286. ((A_STH,A_STHU),(A_STHX,A_STHUX)),
  287. ((A_STW,A_STWU),(A_STWX,A_STWUX)));
  288. var
  289. op: TAsmOp;
  290. ref2: TReference;
  291. freereg: boolean;
  292. begin
  293. ref2 := ref;
  294. freereg := fixref(list,ref2);
  295. if size in [OS_S8..OS_S16] then
  296. { storing is the same for signed and unsigned values }
  297. size := tcgsize(ord(size)-(ord(OS_S8)-ord(OS_8)));
  298. { 64 bit stuff should be handled separately }
  299. if size in [OS_64,OS_S64] then
  300. internalerror(200109236);
  301. op := storeinstr[tcgsize2unsigned[size],ref2.index.number<>NR_NO,false];
  302. a_load_store(list,op,reg,ref2);
  303. if freereg then
  304. cg.free_scratch_reg(list,ref2.base);
  305. End;
  306. procedure tcgppc.a_load_ref_reg(list : taasmoutput;size : tcgsize;const ref: treference;reg : tregister);
  307. const
  308. LoadInstr: Array[OS_8..OS_S32,boolean, boolean] of TAsmOp =
  309. { indexed? updating?}
  310. (((A_LBZ,A_LBZU),(A_LBZX,A_LBZUX)),
  311. ((A_LHZ,A_LHZU),(A_LHZX,A_LHZUX)),
  312. ((A_LWZ,A_LWZU),(A_LWZX,A_LWZUX)),
  313. { 64bit stuff should be handled separately }
  314. ((A_NONE,A_NONE),(A_NONE,A_NONE)),
  315. { there's no load-byte-with-sign-extend :( }
  316. ((A_LBZ,A_LBZU),(A_LBZX,A_LBZUX)),
  317. ((A_LHA,A_LHAU),(A_LHAX,A_LHAUX)),
  318. ((A_LWZ,A_LWZU),(A_LWZX,A_LWZUX)));
  319. var
  320. op: tasmop;
  321. tmpreg: tregister;
  322. ref2, tmpref: treference;
  323. freereg: boolean;
  324. begin
  325. if not(size in [OS_8,OS_S8,OS_16,OS_S16,OS_32,OS_S32]) then
  326. internalerror(2002090902);
  327. ref2 := ref;
  328. freereg := fixref(list,ref2);
  329. op := loadinstr[size,ref2.index.number<>NR_NO,false];
  330. a_load_store(list,op,reg,ref2);
  331. if freereg then
  332. free_scratch_reg(list,ref2.base);
  333. { sign extend shortint if necessary, since there is no }
  334. { load instruction that does that automatically (JM) }
  335. if size = OS_S8 then
  336. list.concat(taicpu.op_reg_reg(A_EXTSB,reg,reg));
  337. end;
  338. procedure tcgppc.a_load_reg_reg(list : taasmoutput;fromsize, tosize : tcgsize;reg1,reg2 : tregister);
  339. begin
  340. if reg1.enum<>R_INTREGISTER then
  341. internalerror(200303101);
  342. if reg2.enum<>R_INTREGISTER then
  343. internalerror(200303102);
  344. if (reg1.number<>reg2.number) or
  345. (tcgsize2size[tosize] < tcgsize2size[fromsize]) or
  346. ((tcgsize2size[tosize] = tcgsize2size[fromsize]) and
  347. (tosize <> fromsize) and
  348. not(fromsize in [OS_32,OS_S32])) then
  349. begin
  350. case fromsize of
  351. OS_8:
  352. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,
  353. reg2,reg1,0,31-8+1,31));
  354. OS_S8:
  355. list.concat(taicpu.op_reg_reg(A_EXTSB,reg2,reg1));
  356. OS_16:
  357. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,
  358. reg2,reg1,0,31-16+1,31));
  359. OS_S16:
  360. list.concat(taicpu.op_reg_reg(A_EXTSH,reg2,reg1));
  361. OS_32,OS_S32:
  362. list.concat(taicpu.op_reg_reg(A_MR,reg2,reg1));
  363. else internalerror(2002090901);
  364. end;
  365. end;
  366. end;
  367. procedure tcgppc.a_loadfpu_reg_reg(list: taasmoutput; reg1, reg2: tregister);
  368. begin
  369. list.concat(taicpu.op_reg_reg(A_FMR,reg2,reg1));
  370. end;
  371. procedure tcgppc.a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister);
  372. const
  373. FpuLoadInstr: Array[OS_F32..OS_F64,boolean, boolean] of TAsmOp =
  374. { indexed? updating?}
  375. (((A_LFS,A_LFSU),(A_LFSX,A_LFSUX)),
  376. ((A_LFD,A_LFDU),(A_LFDX,A_LFDUX)));
  377. var
  378. op: tasmop;
  379. ref2: treference;
  380. freereg: boolean;
  381. begin
  382. { several functions call this procedure with OS_32 or OS_64 }
  383. { so this makes life easier (FK) }
  384. case size of
  385. OS_32,OS_F32:
  386. size:=OS_F32;
  387. OS_64,OS_F64,OS_C64:
  388. size:=OS_F64;
  389. else
  390. internalerror(200201121);
  391. end;
  392. ref2 := ref;
  393. freereg := fixref(list,ref2);
  394. op := fpuloadinstr[size,ref2.index.number <> NR_NO,false];
  395. a_load_store(list,op,reg,ref2);
  396. if freereg then
  397. cg.free_scratch_reg(list,ref2.base);
  398. end;
  399. procedure tcgppc.a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference);
  400. const
  401. FpuStoreInstr: Array[OS_F32..OS_F64,boolean, boolean] of TAsmOp =
  402. { indexed? updating?}
  403. (((A_STFS,A_STFSU),(A_STFSX,A_STFSUX)),
  404. ((A_STFD,A_STFDU),(A_STFDX,A_STFDUX)));
  405. var
  406. op: tasmop;
  407. ref2: treference;
  408. freereg: boolean;
  409. begin
  410. if not(size in [OS_F32,OS_F64]) then
  411. internalerror(200201122);
  412. ref2 := ref;
  413. freereg := fixref(list,ref2);
  414. op := fpustoreinstr[size,ref2.index.number <> NR_NO,false];
  415. a_load_store(list,op,reg,ref2);
  416. if freereg then
  417. cg.free_scratch_reg(list,ref2.base);
  418. end;
  419. procedure tcgppc.a_op_const_reg(list : taasmoutput; Op: TOpCG; a: AWord; reg: TRegister);
  420. var
  421. scratch_register: TRegister;
  422. begin
  423. a_op_const_reg_reg(list,op,OS_32,a,reg,reg);
  424. end;
  425. procedure tcgppc.a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; src, dst: TRegister);
  426. begin
  427. a_op_reg_reg_reg(list,op,OS_32,src,dst,dst);
  428. end;
  429. procedure tcgppc.a_op_const_reg_reg(list: taasmoutput; op: TOpCg;
  430. size: tcgsize; a: aword; src, dst: tregister);
  431. var
  432. l1,l2: longint;
  433. oplo, ophi: tasmop;
  434. scratchreg: tregister;
  435. useReg, gotrlwi: boolean;
  436. procedure do_lo_hi;
  437. begin
  438. list.concat(taicpu.op_reg_reg_const(oplo,dst,src,word(a)));
  439. list.concat(taicpu.op_reg_reg_const(ophi,dst,dst,word(a shr 16)));
  440. end;
  441. begin
  442. if src.enum<>R_INTREGISTER then
  443. internalerror(200303102);
  444. if op = OP_SUB then
  445. begin
  446. {$ifopt q+}
  447. {$q-}
  448. {$define overflowon}
  449. {$endif}
  450. a_op_const_reg_reg(list,OP_ADD,size,aword(-a),src,dst);
  451. {$ifdef overflowon}
  452. {$q+}
  453. {$undef overflowon}
  454. {$endif}
  455. exit;
  456. end;
  457. ophi := TOpCG2AsmOpConstHi[op];
  458. oplo := TOpCG2AsmOpConstLo[op];
  459. gotrlwi := get_rlwi_const(a,l1,l2);
  460. if (op in [OP_AND,OP_OR,OP_XOR]) then
  461. begin
  462. if (a = 0) then
  463. begin
  464. if op = OP_AND then
  465. list.concat(taicpu.op_reg_const(A_LI,dst,0));
  466. exit;
  467. end
  468. else if (a = high(aword)) then
  469. begin
  470. case op of
  471. OP_OR:
  472. list.concat(taicpu.op_reg_const(A_LI,dst,-1));
  473. OP_XOR:
  474. list.concat(taicpu.op_reg_reg(A_NOT,dst,src));
  475. end;
  476. exit;
  477. end
  478. else if (a <= high(word)) and
  479. ((op <> OP_AND) or
  480. not gotrlwi) then
  481. begin
  482. list.concat(taicpu.op_reg_reg_const(oplo,dst,src,word(a)));
  483. exit;
  484. end;
  485. { all basic constant instructions also have a shifted form that }
  486. { works only on the highest 16bits, so if lo(a) is 0, we can }
  487. { use that one }
  488. if (word(a) = 0) and
  489. (not(op = OP_AND) or
  490. not gotrlwi) then
  491. begin
  492. list.concat(taicpu.op_reg_reg_const(ophi,dst,src,word(a shr 16)));
  493. exit;
  494. end;
  495. end
  496. else if (op = OP_ADD) then
  497. if a = 0 then
  498. exit
  499. else if (longint(a) >= low(smallint)) and
  500. (longint(a) <= high(smallint)) then
  501. begin
  502. list.concat(taicpu.op_reg_reg_const(A_ADDI,dst,src,smallint(a)));
  503. exit;
  504. end;
  505. { otherwise, the instructions we can generate depend on the }
  506. { operation }
  507. useReg := false;
  508. case op of
  509. OP_DIV,OP_IDIV:
  510. if (a = 0) then
  511. internalerror(200208103)
  512. else if (a = 1) then
  513. begin
  514. a_load_reg_reg(list,OS_INT,OS_INT,src,dst);
  515. exit
  516. end
  517. else if ispowerof2(a,l1) then
  518. begin
  519. case op of
  520. OP_DIV:
  521. list.concat(taicpu.op_reg_reg_const(A_SRWI,dst,src,l1));
  522. OP_IDIV:
  523. begin
  524. list.concat(taicpu.op_reg_reg_const(A_SRAWI,dst,src,l1));
  525. list.concat(taicpu.op_reg_reg(A_ADDZE,dst,dst));
  526. end;
  527. end;
  528. exit;
  529. end
  530. else
  531. usereg := true;
  532. OP_IMUL, OP_MUL:
  533. if (a = 0) then
  534. begin
  535. list.concat(taicpu.op_reg_const(A_LI,dst,0));
  536. exit
  537. end
  538. else if (a = 1) then
  539. begin
  540. a_load_reg_reg(list,OS_INT,OS_INT,src,dst);
  541. exit
  542. end
  543. else if ispowerof2(a,l1) then
  544. list.concat(taicpu.op_reg_reg_const(A_SLWI,dst,src,l1))
  545. else if (longint(a) >= low(smallint)) and
  546. (longint(a) <= high(smallint)) then
  547. list.concat(taicpu.op_reg_reg_const(A_MULLI,dst,src,smallint(a)))
  548. else
  549. usereg := true;
  550. OP_ADD:
  551. begin
  552. list.concat(taicpu.op_reg_reg_const(oplo,dst,src,smallint(a)));
  553. list.concat(taicpu.op_reg_reg_const(ophi,dst,dst,
  554. smallint((a shr 16) + ord(smallint(a) < 0))));
  555. end;
  556. OP_OR:
  557. { try to use rlwimi }
  558. if gotrlwi and
  559. (src.number = dst.number) then
  560. begin
  561. scratchreg := get_scratch_reg_int(list,OS_INT);
  562. list.concat(taicpu.op_reg_const(A_LI,scratchreg,-1));
  563. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWIMI,dst,
  564. scratchreg,0,l1,l2));
  565. free_scratch_reg(list,scratchreg);
  566. end
  567. else
  568. do_lo_hi;
  569. OP_AND:
  570. { try to use rlwinm }
  571. if gotrlwi then
  572. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,dst,
  573. src,0,l1,l2))
  574. else
  575. useReg := true;
  576. OP_XOR:
  577. do_lo_hi;
  578. OP_SHL,OP_SHR,OP_SAR:
  579. begin
  580. if (a and 31) <> 0 Then
  581. list.concat(taicpu.op_reg_reg_const(
  582. TOpCG2AsmOpConstLo[Op],dst,src,a and 31));
  583. if (a shr 5) <> 0 then
  584. internalError(68991);
  585. end
  586. else
  587. internalerror(200109091);
  588. end;
  589. { if all else failed, load the constant in a register and then }
  590. { perform the operation }
  591. if useReg then
  592. begin
  593. scratchreg := get_scratch_reg_int(list,OS_INT);
  594. a_load_const_reg(list,OS_32,a,scratchreg);
  595. a_op_reg_reg_reg(list,op,OS_32,scratchreg,src,dst);
  596. free_scratch_reg(list,scratchreg);
  597. end;
  598. end;
  599. procedure tcgppc.a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;
  600. size: tcgsize; src1, src2, dst: tregister);
  601. const
  602. op_reg_reg_opcg2asmop: array[TOpCG] of tasmop =
  603. (A_NONE,A_ADD,A_AND,A_DIVWU,A_DIVW,A_MULLW,A_MULLW,A_NEG,A_NOT,A_OR,
  604. A_SRAW,A_SLW,A_SRW,A_SUB,A_XOR);
  605. begin
  606. case op of
  607. OP_NEG,OP_NOT:
  608. list.concat(taicpu.op_reg_reg(op_reg_reg_opcg2asmop[op],dst,dst));
  609. else
  610. list.concat(taicpu.op_reg_reg_reg(op_reg_reg_opcg2asmop[op],dst,src2,src1));
  611. end;
  612. end;
  613. {*************** compare instructructions ****************}
  614. procedure tcgppc.a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;reg : tregister;
  615. l : tasmlabel);
  616. var
  617. p: taicpu;
  618. scratch_register: TRegister;
  619. signed: boolean;
  620. r:Tregister;
  621. begin
  622. signed := cmp_op in [OC_GT,OC_LT,OC_GTE,OC_LTE];
  623. { in the following case, we generate more efficient code when }
  624. { signed is true }
  625. if (cmp_op in [OC_EQ,OC_NE]) and
  626. (a > $ffff) then
  627. signed := true;
  628. r.enum:=R_CR0;
  629. if signed then
  630. if (longint(a) >= low(smallint)) and (longint(a) <= high(smallint)) Then
  631. list.concat(taicpu.op_reg_reg_const(A_CMPWI,r,reg,longint(a)))
  632. else
  633. begin
  634. scratch_register := get_scratch_reg_int(list,OS_INT);
  635. a_load_const_reg(list,OS_32,a,scratch_register);
  636. list.concat(taicpu.op_reg_reg_reg(A_CMPW,r,reg,scratch_register));
  637. free_scratch_reg(list,scratch_register);
  638. end
  639. else
  640. if (a <= $ffff) then
  641. list.concat(taicpu.op_reg_reg_const(A_CMPLWI,r,reg,a))
  642. else
  643. begin
  644. scratch_register := get_scratch_reg_int(list,OS_32);
  645. a_load_const_reg(list,OS_32,a,scratch_register);
  646. list.concat(taicpu.op_reg_reg_reg(A_CMPLW,r,reg,scratch_register));
  647. free_scratch_reg(list,scratch_register);
  648. end;
  649. a_jmp(list,A_BC,TOpCmp2AsmCond[cmp_op],0,l);
  650. end;
  651. procedure tcgppc.a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;
  652. reg1,reg2 : tregister;l : tasmlabel);
  653. var
  654. p: taicpu;
  655. op: tasmop;
  656. r:Tregister;
  657. begin
  658. if cmp_op in [OC_GT,OC_LT,OC_GTE,OC_LTE] then
  659. op := A_CMPW
  660. else op := A_CMPLW;
  661. r.enum:=R_CR0;
  662. list.concat(taicpu.op_reg_reg_reg(op,r,reg1,reg2));
  663. a_jmp(list,A_BC,TOpCmp2AsmCond[cmp_op],0,l);
  664. end;
  665. procedure tcgppc.g_save_standard_registers(list : taasmoutput; usedinproc : Tsupregset);
  666. begin
  667. {$warning FIX ME}
  668. end;
  669. procedure tcgppc.g_restore_standard_registers(list : taasmoutput; usedinproc : Tsupregset);
  670. begin
  671. {$warning FIX ME}
  672. end;
  673. procedure tcgppc.g_save_all_registers(list : taasmoutput);
  674. begin
  675. {$warning FIX ME}
  676. end;
  677. procedure tcgppc.g_restore_all_registers(list : taasmoutput;selfused,accused,acchiused:boolean);
  678. begin
  679. {$warning FIX ME}
  680. end;
  681. procedure tcgppc.a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel);
  682. begin
  683. a_jmp(list,A_BC,TOpCmp2AsmCond[cond],0,l);
  684. end;
  685. procedure tcgppc.a_jmp_always(list : taasmoutput;l: tasmlabel);
  686. begin
  687. a_jmp(list,A_B,C_None,0,l);
  688. end;
  689. procedure tcgppc.a_jmp_flags(list : taasmoutput;const f : TResFlags;l: tasmlabel);
  690. var
  691. c: tasmcond;
  692. r:Tregister;
  693. begin
  694. c := flags_to_cond(f);
  695. r.enum:=R_CR0;
  696. a_jmp(list,A_BC,c.cond,ord(c.cr)-ord(r.enum),l);
  697. end;
  698. procedure tcgppc.g_flags2reg(list: taasmoutput; size: TCgSize; const f: TResFlags; reg: TRegister);
  699. var
  700. testbit: byte;
  701. bitvalue: boolean;
  702. begin
  703. { get the bit to extract from the conditional register + its }
  704. { requested value (0 or 1) }
  705. testbit := ((ord(f.cr)-ord(R_CR0)) * 4);
  706. case f.flag of
  707. F_EQ,F_NE:
  708. bitvalue := f.flag = F_EQ;
  709. F_LT,F_GE:
  710. begin
  711. inc(testbit);
  712. bitvalue := f.flag = F_LT;
  713. end;
  714. F_GT,F_LE:
  715. begin
  716. inc(testbit,2);
  717. bitvalue := f.flag = F_GT;
  718. end;
  719. else
  720. internalerror(200112261);
  721. end;
  722. { load the conditional register in the destination reg }
  723. list.concat(taicpu.op_reg(A_MFCR,reg));
  724. { we will move the bit that has to be tested to bit 0 by rotating }
  725. { left }
  726. testbit := (32 - testbit) and 31;
  727. { extract bit }
  728. list.concat(taicpu.op_reg_reg_const_const_const(
  729. A_RLWINM,reg,reg,testbit,31,31));
  730. { if we need the inverse, xor with 1 }
  731. if not bitvalue then
  732. list.concat(taicpu.op_reg_reg_const(A_XORI,reg,reg,1));
  733. end;
  734. (*
  735. procedure tcgppc.g_cond2reg(list: taasmoutput; const f: TAsmCond; reg: TRegister);
  736. var
  737. testbit: byte;
  738. bitvalue: boolean;
  739. begin
  740. { get the bit to extract from the conditional register + its }
  741. { requested value (0 or 1) }
  742. case f.simple of
  743. false:
  744. begin
  745. { we don't generate this in the compiler }
  746. internalerror(200109062);
  747. end;
  748. true:
  749. case f.cond of
  750. C_None:
  751. internalerror(200109063);
  752. C_LT..C_NU:
  753. begin
  754. testbit := (ord(f.cr) - ord(R_CR0))*4;
  755. inc(testbit,AsmCondFlag2BI[f.cond]);
  756. bitvalue := AsmCondFlagTF[f.cond];
  757. end;
  758. C_T,C_F,C_DNZT,C_DNZF,C_DZT,C_DZF:
  759. begin
  760. testbit := f.crbit
  761. bitvalue := AsmCondFlagTF[f.cond];
  762. end;
  763. else
  764. internalerror(200109064);
  765. end;
  766. end;
  767. { load the conditional register in the destination reg }
  768. list.concat(taicpu.op_reg_reg(A_MFCR,reg));
  769. { we will move the bit that has to be tested to bit 31 -> rotate }
  770. { left by bitpos+1 (remember, this is big-endian!) }
  771. if bitpos <> 31 then
  772. inc(bitpos)
  773. else
  774. bitpos := 0;
  775. { extract bit }
  776. list.concat(taicpu.op_reg_reg_const_const_const(
  777. A_RLWINM,reg,reg,bitpos,31,31));
  778. { if we need the inverse, xor with 1 }
  779. if not bitvalue then
  780. list.concat(taicpu.op_reg_reg_const(A_XORI,reg,reg,1));
  781. end;
  782. *)
  783. { *********** entry/exit code and address loading ************ }
  784. procedure tcgppc.g_stackframe_entry(list : taasmoutput;localsize : longint);
  785. begin
  786. case target_info.system of
  787. system_powerpc_macos:
  788. g_stackframe_entry_mac(list,localsize);
  789. system_powerpc_linux:
  790. g_stackframe_entry_sysv(list,localsize)
  791. else
  792. internalerror(2204001);
  793. end;
  794. end;
  795. procedure tcgppc.g_return_from_proc(list : taasmoutput;parasize : aword);
  796. begin
  797. case target_info.system of
  798. system_powerpc_macos:
  799. g_return_from_proc_mac(list,parasize);
  800. system_powerpc_linux:
  801. g_return_from_proc_sysv(list,parasize)
  802. else
  803. internalerror(2204001);
  804. end;
  805. end;
  806. procedure tcgppc.g_stackframe_entry_sysv(list : taasmoutput;localsize : longint);
  807. { generated the entry code of a procedure/function. Note: localsize is the }
  808. { sum of the size necessary for local variables and the maximum possible }
  809. { combined size of ALL the parameters of a procedure called by the current }
  810. { one }
  811. var regcounter,firstregfpu,firstreggpr, regcounter2 : TRegister;
  812. href : treference;
  813. usesfpr,usesgpr,gotgot : boolean;
  814. parastart : aword;
  815. offset : aword;
  816. r,r2,rsp:Tregister;
  817. begin
  818. { we do our own localsize calculation }
  819. localsize:=0;
  820. { CR and LR only have to be saved in case they are modified by the current }
  821. { procedure, but currently this isn't checked, so save them always }
  822. { following is the entry code as described in "Altivec Programming }
  823. { Interface Manual", bar the saving of AltiVec registers }
  824. rsp.enum:=R_INTREGISTER;
  825. rsp.number:=NR_STACK_POINTER_REG;;
  826. a_reg_alloc(list,rsp);
  827. r.enum:=R_INTREGISTER;
  828. r.number:=NR_R0;
  829. a_reg_alloc(list,r);
  830. { allocate registers containing reg parameters }
  831. regcounter2.enum := R_INTREGISTER;
  832. regcounter2.number := NR_R3;
  833. for regcounter.enum := R_3 to R_10 do
  834. begin
  835. a_reg_alloc(list,regcounter2);
  836. inc(regcounter2.number,NR_R1-NR_R0);
  837. end;
  838. usesfpr:=false;
  839. for regcounter.enum:=R_F14 to R_F31 do
  840. if regcounter.enum in rg.usedbyproc then
  841. begin
  842. usesfpr:=true;
  843. firstregfpu:=regcounter;
  844. break;
  845. end;
  846. usesgpr:=false;
  847. regcounter2.enum := R_INTREGISTER;
  848. regcounter2.number := NR_R14;
  849. for regcounter.enum:=R_14 to R_31 do
  850. begin
  851. if regcounter.enum in rg.usedbyproc then
  852. begin
  853. usesgpr:=true;
  854. firstreggpr:=regcounter;
  855. break;
  856. end;
  857. inc(regcounter2.number,NR_R1-NR_R0);
  858. end;
  859. { save link register? }
  860. if (procinfo.flags and pi_do_call)<>0 then
  861. begin
  862. { save return address... }
  863. r.enum:=R_INTREGISTER;
  864. r.number:=NR_R0;
  865. list.concat(taicpu.op_reg(A_MFLR,r));
  866. { ... in caller's rframe }
  867. reference_reset_base(href,rsp,4);
  868. list.concat(taicpu.op_reg_ref(A_STW,r,href));
  869. a_reg_dealloc(list,r);
  870. end;
  871. if usesfpr or usesgpr then
  872. begin
  873. r.enum:=R_INTREGISTER;
  874. r.number:=NR_R11;
  875. a_reg_alloc(list,r);
  876. { save end of fpr save area }
  877. list.concat(taicpu.op_reg_reg_const(A_ORI,r,rsp,0));
  878. end;
  879. { calculate the size of the locals }
  880. if usesgpr then
  881. inc(localsize,(NR_R31-firstreggpr.number+1)*4);
  882. if usesfpr then
  883. inc(localsize,(ord(R_F31)-ord(firstregfpu.enum)+1)*8);
  884. { align to 16 bytes }
  885. localsize:=align(localsize,16);
  886. inc(localsize,tg.lasttemp);
  887. localsize:=align(localsize,16);
  888. tppcprocinfo(procinfo).localsize:=localsize;
  889. r.enum:=R_INTREGISTER;
  890. r.number:=NR_STACK_POINTER_REG;
  891. reference_reset_base(href,r,-localsize);
  892. a_load_store(list,A_STWU,r,href);
  893. { no GOT pointer loaded yet }
  894. gotgot:=false;
  895. if usesfpr then
  896. begin
  897. { save floating-point registers
  898. if (cs_create_pic in aktmoduleswitches) and not(usesgpr) then
  899. begin
  900. a_call_name(objectlibrary.newasmsymbol('_savefpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14)+'_g');
  901. gotgot:=true;
  902. end
  903. else
  904. a_call_name(objectlibrary.newasmsymbol('_savefpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14));
  905. }
  906. for regcounter.enum:=firstregfpu.enum to R_F31 do
  907. if regcounter.enum in rg.usedbyproc then
  908. begin
  909. { reference_reset_base(href,R_1,-localsize);
  910. a_load_store(list,A_STWU,R_1,href);
  911. }
  912. end;
  913. { compute end of gpr save area }
  914. r.enum:=R_INTREGISTER;
  915. r.number:=NR_R11;
  916. list.concat(taicpu.op_reg_reg_const(A_ADDI,r,r,-(ord(R_F31)-ord(firstregfpu.enum)+1)*8));
  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. r.enum:=R_INTREGISTER;
  931. r.number:=NR_R11;
  932. reference_reset_base(href,r,-((NR_R31-firstreggpr.number) div (NR_R1-NR_R0)+1)*4);
  933. list.concat(taicpu.op_reg_ref(A_STMW,firstreggpr,href));
  934. end;
  935. r.enum:=R_INTREGISTER;
  936. r.number:=NR_R11;
  937. if usesfpr or usesgpr then
  938. a_reg_dealloc(list,r);
  939. { PIC code support, }
  940. if cs_create_pic in aktmoduleswitches then
  941. begin
  942. { if we didn't get the GOT pointer till now, we've to calculate it now }
  943. if not(gotgot) then
  944. begin
  945. {!!!!!!!!!!!!!}
  946. end;
  947. r.enum:=R_INTREGISTER;
  948. r.number:=NR_R31;
  949. r2.enum:=R_LR;
  950. a_reg_alloc(list,r);
  951. { place GOT ptr in r31 }
  952. list.concat(taicpu.op_reg_reg(A_MFSPR,r,r2));
  953. end;
  954. { save the CR if necessary ( !!! always done currently ) }
  955. { still need to find out where this has to be done for SystemV
  956. a_reg_alloc(list,R_0);
  957. list.concat(taicpu.op_reg_reg(A_MFSPR,R_0,R_CR);
  958. list.concat(taicpu.op_reg_ref(A_STW,scratch_register,
  959. new_reference(STACK_POINTER_REG,LA_CR)));
  960. a_reg_dealloc(list,R_0); }
  961. { now comes the AltiVec context save, not yet implemented !!! }
  962. end;
  963. procedure tcgppc.g_return_from_proc_sysv(list : taasmoutput;parasize : aword);
  964. var
  965. regcounter,firstregfpu,firstreggpr, regcounter2 : TRegister;
  966. href : treference;
  967. usesfpr,usesgpr,genret : boolean;
  968. r,r2:Tregister;
  969. begin
  970. { release parameter registers }
  971. regcounter2.enum := R_INTREGISTER;
  972. regcounter2.number := NR_R3;
  973. for regcounter.enum := R_3 to R_10 do
  974. begin
  975. a_reg_dealloc(list,regcounter2);
  976. inc(regcounter2.number,NR_R1-NR_R0);
  977. end;
  978. { AltiVec context restore, not yet implemented !!! }
  979. usesfpr:=false;
  980. for regcounter.enum:=R_F14 to R_F31 do
  981. if regcounter.enum in rg.usedbyproc then
  982. begin
  983. usesfpr:=true;
  984. firstregfpu:=regcounter;
  985. break;
  986. end;
  987. usesgpr:=false;
  988. regcounter2.enum := R_INTREGISTER;
  989. regcounter2.number := NR_R14;
  990. for regcounter.enum:=R_14 to R_30 do
  991. begin
  992. if regcounter.enum in rg.usedbyproc then
  993. begin
  994. usesgpr:=true;
  995. firstreggpr:=regcounter2;
  996. break;
  997. end;
  998. inc(regcounter2.number,NR_R1-NR_R0);
  999. end;
  1000. { no return (blr) generated yet }
  1001. genret:=true;
  1002. if usesgpr then
  1003. begin
  1004. { address of gpr save area to r11 }
  1005. r.enum:=R_INTREGISTER;
  1006. r.number:=NR_STACK_POINTER_REG;
  1007. r2.enum:=R_INTREGISTER;
  1008. r2.number:=NR_R11;
  1009. if usesfpr then
  1010. list.concat(taicpu.op_reg_reg_const(A_ADDI,r2,r,tppcprocinfo(procinfo).localsize-(ord(R_F31)-ord(firstregfpu.enum)+1)*8))
  1011. else
  1012. list.concat(taicpu.op_reg_reg_const(A_ADDI,r2,r,tppcprocinfo(procinfo).localsize));
  1013. { restore gprs }
  1014. { at least for now we use LMW }
  1015. {
  1016. a_call_name(objectlibrary.newasmsymbol('_restgpr_14');
  1017. }
  1018. reference_reset_base(href,r2,-(ord(R_31)-ord(firstreggpr.enum)+1)*4);
  1019. list.concat(taicpu.op_reg_ref(A_LMW,firstreggpr,href));
  1020. end;
  1021. { restore fprs and return }
  1022. if usesfpr then
  1023. begin
  1024. { address of fpr save area to r11 }
  1025. r.enum:=R_INTREGISTER;
  1026. r.number:=NR_R11;
  1027. list.concat(taicpu.op_reg_reg_const(A_ADDI,r,r,(ord(R_F31)-ord(firstregfpu.enum)+1)*8));
  1028. {
  1029. if (procinfo.flags and pi_do_call)<>0 then
  1030. a_call_name(objectlibrary.newasmsymbol('_restfpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14)+
  1031. '_x')
  1032. else
  1033. { leaf node => lr haven't to be restored }
  1034. a_call_name('_restfpr_'+tostr(ord(firstregfpu.enum)-ord(R_F14)+14)+
  1035. '_l');
  1036. genret:=false;
  1037. }
  1038. end;
  1039. { if we didn't generate the return code, we've to do it now }
  1040. if genret then
  1041. begin
  1042. { adjust r1 }
  1043. r.enum:=R_INTREGISTER;
  1044. r.number:=NR_R1;
  1045. a_op_const_reg(list,OP_ADD,tppcprocinfo(procinfo).localsize,r);
  1046. { load link register? }
  1047. if (procinfo.flags and pi_do_call)<>0 then
  1048. begin
  1049. r.enum:=R_INTREGISTER;
  1050. r.number:=NR_STACK_POINTER_REG;
  1051. reference_reset_base(href,r,4);
  1052. r.enum:=R_INTREGISTER;
  1053. r.number:=NR_R0;
  1054. list.concat(taicpu.op_reg_ref(A_LWZ,r,href));
  1055. list.concat(taicpu.op_reg(A_MTLR,r));
  1056. end;
  1057. list.concat(taicpu.op_none(A_BLR));
  1058. end;
  1059. end;
  1060. function save_regs(list : taasmoutput):longint;
  1061. {Generates code which saves used non-volatile registers in
  1062. the save area right below the address the stackpointer point to.
  1063. Returns the actual used save area size.}
  1064. var regcounter,firstregfpu,firstreggpr, regcounter2: TRegister;
  1065. usesfpr,usesgpr: boolean;
  1066. href : treference;
  1067. offset: integer;
  1068. r:Tregister;
  1069. begin
  1070. usesfpr:=false;
  1071. for regcounter.enum:=R_F14 to R_F31 do
  1072. if regcounter.enum in rg.usedbyproc then
  1073. begin
  1074. usesfpr:=true;
  1075. firstregfpu:=regcounter;
  1076. break;
  1077. end;
  1078. usesgpr:=false;
  1079. r.enum := R_INTREGISTER;
  1080. r.number := NR_R13;
  1081. for regcounter.enum:=R_13 to R_31 do
  1082. begin
  1083. if regcounter.enum in rg.usedbyproc then
  1084. begin
  1085. usesgpr:=true;
  1086. firstreggpr:=r;
  1087. break;
  1088. end;
  1089. inc(r.number,NR_R1-NR_R0);
  1090. end;
  1091. offset:= 0;
  1092. { save floating-point registers }
  1093. if usesfpr then
  1094. for regcounter.enum := firstregfpu.enum to R_F31 do
  1095. begin
  1096. offset:= offset - 8;
  1097. r.enum:=R_INTREGISTER;
  1098. r.number:=NR_STACK_POINTER_REG;
  1099. reference_reset_base(href, r, offset);
  1100. list.concat(taicpu.op_reg_ref(A_STFD, regcounter, href));
  1101. end;
  1102. (* Optimiztion in the future: a_call_name(list,'_savefXX'); *)
  1103. { save gprs in gpr save area }
  1104. if usesgpr then
  1105. if firstreggpr.enum < R_30 then
  1106. begin
  1107. offset:= offset - 4 * (ord(R_31) - ord(firstreggpr.enum) + 1);
  1108. r.enum:=R_INTREGISTER;
  1109. r.number:=NR_STACK_POINTER_REG;
  1110. reference_reset_base(href,r,offset);
  1111. list.concat(taicpu.op_reg_ref(A_STMW,firstreggpr,href));
  1112. {STMW stores multiple registers}
  1113. end
  1114. else
  1115. begin
  1116. regcounter2 := firstreggpr;
  1117. convert_register_to_enum(firstreggpr);
  1118. for regcounter.enum := firstreggpr.enum to R_31 do
  1119. begin
  1120. offset:= offset - 4;
  1121. r.enum:=R_INTREGISTER;
  1122. r.number:=NR_STACK_POINTER_REG;
  1123. reference_reset_base(href, r, offset);
  1124. list.concat(taicpu.op_reg_ref(A_STW, regcounter2, href));
  1125. inc(regcounter2.number,NR_R1-NR_R0);
  1126. end;
  1127. end;
  1128. { now comes the AltiVec context save, not yet implemented !!! }
  1129. save_regs:= -offset;
  1130. end;
  1131. procedure restore_regs(list : taasmoutput);
  1132. {Generates code which restores used non-volatile registers from
  1133. the save area right below the address the stackpointer point to.}
  1134. var regcounter,firstregfpu,firstreggpr,regcounter2: TRegister;
  1135. usesfpr,usesgpr: boolean;
  1136. href : treference;
  1137. offset: integer;
  1138. r:Tregister;
  1139. begin
  1140. usesfpr:=false;
  1141. for regcounter.enum:=R_F14 to R_F31 do
  1142. if regcounter.enum in rg.usedbyproc then
  1143. begin
  1144. usesfpr:=true;
  1145. firstregfpu:=regcounter;
  1146. break;
  1147. end;
  1148. usesgpr:=false;
  1149. r.enum := R_INTREGISTER;
  1150. r.number := NR_R13;
  1151. for regcounter.enum:=R_13 to R_31 do
  1152. begin
  1153. if regcounter.enum in rg.usedbyproc then
  1154. begin
  1155. usesgpr:=true;
  1156. firstreggpr:=r;
  1157. break;
  1158. end;
  1159. inc(r.number,NR_R1-NR_R0);
  1160. end;
  1161. offset:= 0;
  1162. { restore fp registers }
  1163. if usesfpr then
  1164. for regcounter.enum := firstregfpu.enum to R_F31 do
  1165. begin
  1166. offset:= offset - 8;
  1167. r.enum:=R_INTREGISTER;
  1168. r.number:=NR_STACK_POINTER_REG;
  1169. reference_reset_base(href, r, offset);
  1170. list.concat(taicpu.op_reg_ref(A_LFD, regcounter, href));
  1171. end;
  1172. (* Optimiztion in the future: a_call_name(list,'_restfXX'); *)
  1173. { restore gprs }
  1174. if usesgpr then
  1175. if firstreggpr.enum < R_30 then
  1176. begin
  1177. offset:= offset - 4 * (ord(R_31) - ord(firstreggpr.enum) + 1);
  1178. r.enum:=R_INTREGISTER;
  1179. r.number:=NR_STACK_POINTER_REG;
  1180. reference_reset_base(href,r,offset); //-220
  1181. list.concat(taicpu.op_reg_ref(A_LMW,firstreggpr,href));
  1182. {LMW loads multiple registers}
  1183. end
  1184. else
  1185. begin
  1186. regcounter2 := firstreggpr;
  1187. convert_register_to_enum(firstreggpr);
  1188. for regcounter.enum := firstreggpr.enum to R_31 do
  1189. begin
  1190. offset:= offset - 4;
  1191. r.enum:=R_INTREGISTER;
  1192. r.number:=NR_STACK_POINTER_REG;
  1193. reference_reset_base(href, r, offset);
  1194. list.concat(taicpu.op_reg_ref(A_LWZ, regcounter2, href));
  1195. inc(regcounter2.number,NR_R1-NR_R0);
  1196. end;
  1197. end;
  1198. { now comes the AltiVec context restore, not yet implemented !!! }
  1199. end;
  1200. procedure tcgppc.g_stackframe_entry_mac(list : taasmoutput;localsize : longint);
  1201. { generated the entry code of a procedure/function. Note: localsize is the }
  1202. { sum of the size necessary for local variables and the maximum possible }
  1203. { combined size of ALL the parameters of a procedure called by the current }
  1204. { one }
  1205. const
  1206. macosLinkageAreaSize = 24;
  1207. var regcounter,regcounter2: TRegister;
  1208. href : treference;
  1209. registerSaveAreaSize : longint;
  1210. r,r2,rsp:Tregister;
  1211. begin
  1212. if (localsize mod 8) <> 0 then internalerror(58991);
  1213. { CR and LR only have to be saved in case they are modified by the current }
  1214. { procedure, but currently this isn't checked, so save them always }
  1215. { following is the entry code as described in "Altivec Programming }
  1216. { Interface Manual", bar the saving of AltiVec registers }
  1217. r.enum:=R_INTREGISTER;
  1218. r.number:=NR_R0;
  1219. rsp.enum:=R_INTREGISTER;
  1220. rsp.number:=NR_STACK_POINTER_REG;
  1221. a_reg_alloc(list,rsp);
  1222. a_reg_alloc(list,r);
  1223. { allocate registers containing reg parameters }
  1224. regcounter2.enum := R_INTREGISTER;
  1225. regcounter2.number := NR_R3;
  1226. for regcounter.enum := R_3 to R_10 do
  1227. begin
  1228. a_reg_alloc(list,regcounter2);
  1229. inc(regcounter2.number,NR_R1-NR_R0);
  1230. end;
  1231. {TODO: Allocate fp and altivec parameter registers also}
  1232. { save return address in callers frame}
  1233. r2.enum:=R_LR;
  1234. list.concat(taicpu.op_reg_reg(A_MFSPR,r,r2));
  1235. { ... in caller's frame }
  1236. reference_reset_base(href,rsp,8);
  1237. list.concat(taicpu.op_reg_ref(A_STW,r,href));
  1238. a_reg_dealloc(list,r);
  1239. { save non-volatile registers in callers frame}
  1240. registerSaveAreaSize:= save_regs(list);
  1241. { save the CR if necessary in callers frame ( !!! always done currently ) }
  1242. a_reg_alloc(list,r);
  1243. r2.enum:=R_CR;
  1244. list.concat(taicpu.op_reg_reg(A_MFSPR,r,r2));
  1245. reference_reset_base(href,rsp,LA_CR);
  1246. list.concat(taicpu.op_reg_ref(A_STW,r,href));
  1247. a_reg_dealloc(list,r);
  1248. (*
  1249. { save pointer to incoming arguments }
  1250. list.concat(taicpu.op_reg_reg_const(A_ORI,R_31,STACK_POINTER_REG,0));
  1251. *)
  1252. (*
  1253. a_reg_alloc(list,R_12);
  1254. { 0 or 8 based on SP alignment }
  1255. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,
  1256. R_12,STACK_POINTER_REG,0,28,28));
  1257. { add in stack length }
  1258. list.concat(taicpu.op_reg_reg_const(A_SUBFIC,R_12,R_12,
  1259. -localsize));
  1260. { establish new alignment }
  1261. list.concat(taicpu.op_reg_reg_reg(A_STWUX,STACK_POINTER_REG,STACK_POINTER_REG,R_12));
  1262. a_reg_dealloc(list,R_12);
  1263. *)
  1264. { allocate stack frame }
  1265. localsize:= align(localsize + macosLinkageAreaSize + registerSaveAreaSize, 16);
  1266. inc(localsize,tg.lasttemp);
  1267. localsize:=align(localsize,16);
  1268. tppcprocinfo(procinfo).localsize:=localsize;
  1269. r.enum:=R_INTREGISTER;
  1270. r.number:=NR_STACK_POINTER_REG;
  1271. reference_reset_base(href,r,-localsize);
  1272. a_load_store(list,A_STWU,r,href);
  1273. { this also stores the old stack pointer in the new stack frame }
  1274. end;
  1275. procedure tcgppc.g_return_from_proc_mac(list : taasmoutput;parasize : aword);
  1276. var
  1277. regcounter, regcounter2: TRegister;
  1278. href : treference;
  1279. r,r2,rsp:Tregister;
  1280. begin
  1281. { release parameter registers }
  1282. regcounter2.enum := R_INTREGISTER;
  1283. regcounter2.number := NR_R3;
  1284. for regcounter.enum := R_3 to R_10 do
  1285. begin
  1286. a_reg_dealloc(list,regcounter2);
  1287. inc(regcounter2.number,NR_R1-NR_R0);
  1288. end;
  1289. {TODO: Release fp and altivec parameter registers also}
  1290. r.enum:=R_INTREGISTER;
  1291. r.number:=NR_R0;
  1292. rsp.enum:=R_INTREGISTER;
  1293. rsp.number:=NR_STACK_POINTER_REG;
  1294. a_reg_alloc(list,r);
  1295. { restore stack pointer }
  1296. reference_reset_base(href,rsp,LA_SP);
  1297. list.concat(taicpu.op_reg_ref(A_LWZ,rsp,href));
  1298. (*
  1299. list.concat(taicpu.op_reg_reg_const(A_ORI,rsp,R_31,0));
  1300. *)
  1301. { restore the CR if necessary from callers frame
  1302. ( !!! always done currently ) }
  1303. reference_reset_base(href,rsp,LA_CR);
  1304. r.enum:=R_INTREGISTER;
  1305. r.number:=NR_R0;
  1306. list.concat(taicpu.op_reg_ref(A_LWZ,r,href));
  1307. r2.enum:=R_CR;
  1308. list.concat(taicpu.op_reg_reg(A_MTSPR,r,r2));
  1309. a_reg_dealloc(list,r);
  1310. (*
  1311. { restore return address from callers frame }
  1312. reference_reset_base(href,STACK_POINTER_REG,8);
  1313. list.concat(taicpu.op_reg_ref(A_LWZ,R_0,href));
  1314. *)
  1315. { restore non-volatile registers from callers frame }
  1316. restore_regs(list);
  1317. (*
  1318. { return to caller }
  1319. list.concat(taicpu.op_reg_reg(A_MTSPR,R_0,R_LR));
  1320. list.concat(taicpu.op_none(A_BLR));
  1321. *)
  1322. { restore return address from callers frame }
  1323. r.enum:=R_INTREGISTER;
  1324. r.number:=NR_R0;
  1325. r2.enum:=R_LR;
  1326. reference_reset_base(href,rsp,8);
  1327. list.concat(taicpu.op_reg_ref(A_LWZ,r,href));
  1328. { return to caller }
  1329. list.concat(taicpu.op_reg_reg(A_MTSPR,r,r2));
  1330. list.concat(taicpu.op_none(A_BLR));
  1331. end;
  1332. procedure tcgppc.g_restore_frame_pointer(list : taasmoutput);
  1333. begin
  1334. { no frame pointer on the PowerPC (maybe there is one in the SystemV ABI?)}
  1335. end;
  1336. procedure tcgppc.a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);
  1337. var
  1338. ref2, tmpref: treference;
  1339. freereg: boolean;
  1340. r2,tmpreg:Tregister;
  1341. begin
  1342. ref2 := ref;
  1343. freereg := fixref(list,ref2);
  1344. if assigned(ref2.symbol) then
  1345. begin
  1346. if target_info.system = system_powerpc_macos then
  1347. begin
  1348. if ref2.base.number <> NR_NO then
  1349. internalerror(2002103102); //TODO: Implement this if needed
  1350. if macos_direct_globals then
  1351. begin
  1352. reference_reset(tmpref);
  1353. tmpref.offset := ref2.offset;
  1354. tmpref.symbol := ref2.symbol;
  1355. tmpref.symaddr := refs_full;
  1356. tmpref.base.number := NR_NO;
  1357. r2.enum:=R_INTREGISTER;
  1358. r2.number:=NR_RTOC;
  1359. list.concat(taicpu.op_reg_reg_ref(A_ADDI,r,r2,tmpref));
  1360. end
  1361. else
  1362. begin
  1363. tmpreg := get_scratch_reg_address(list);
  1364. reference_reset(tmpref);
  1365. tmpref.symbol := ref2.symbol;
  1366. tmpref.offset := ref2.offset;
  1367. tmpref.symaddr := refs_full;
  1368. tmpref.base.enum := R_INTREGISTER;
  1369. tmpref.base.number := NR_RTOC;
  1370. list.concat(taicpu.op_reg_ref(A_LWZ,tmpreg,tmpref));
  1371. reference_reset(tmpref);
  1372. tmpref.offset := 0;
  1373. tmpref.symaddr := refs_full;
  1374. tmpref.base:= tmpreg;
  1375. list.concat(taicpu.op_reg_ref(A_LA,r,tmpref));
  1376. free_scratch_reg(list,tmpreg);
  1377. end;
  1378. //list.concat(tai_comment.create(strpnew('*** a_loadaddr_ref_reg')));
  1379. end
  1380. else
  1381. begin
  1382. { add the symbol's value to the base of the reference, and if the }
  1383. { reference doesn't have a base, create one }
  1384. reference_reset(tmpref);
  1385. tmpref.offset := ref2.offset;
  1386. tmpref.symbol := ref2.symbol;
  1387. tmpref.symaddr := refs_ha;
  1388. if ref2.base .number<> NR_NO then
  1389. begin
  1390. list.concat(taicpu.op_reg_reg_ref(A_ADDIS,r,
  1391. ref2.base,tmpref));
  1392. if freereg then
  1393. begin
  1394. cg.free_scratch_reg(list,ref2.base);
  1395. freereg := false;
  1396. end;
  1397. end
  1398. else
  1399. list.concat(taicpu.op_reg_ref(A_LIS,r,tmpref));
  1400. tmpref.base.number := NR_NO;
  1401. tmpref.symaddr := refs_l;
  1402. { can be folded with one of the next instructions by the }
  1403. { optimizer probably }
  1404. list.concat(taicpu.op_reg_reg_ref(A_ADDI,r,r,tmpref));
  1405. end
  1406. end
  1407. else if ref2.offset <> 0 Then
  1408. if ref2.base.number <> NR_NO then
  1409. a_op_const_reg_reg(list,OP_ADD,OS_32,ref2.offset,ref2.base,r)
  1410. { FixRef makes sure that "(ref.index <> R_NO) and (ref.offset <> 0)" never}
  1411. { occurs, so now only ref.offset has to be loaded }
  1412. else
  1413. a_load_const_reg(list,OS_32,ref2.offset,r)
  1414. else if ref.index.number <> NR_NO Then
  1415. list.concat(taicpu.op_reg_reg_reg(A_ADD,r,ref2.base,ref2.index))
  1416. else if (ref2.base.number <> NR_NO) and
  1417. (r.number <> ref2.base.number) then
  1418. list.concat(taicpu.op_reg_reg(A_MR,r,ref2.base));
  1419. if freereg then
  1420. cg.free_scratch_reg(list,ref2.base);
  1421. end;
  1422. { ************* concatcopy ************ }
  1423. procedure tcgppc.g_concatcopy(list : taasmoutput;const source,dest : treference;len : aword; delsource,loadref : boolean);
  1424. var
  1425. countreg: TRegister;
  1426. src, dst: TReference;
  1427. lab: tasmlabel;
  1428. count, count2: aword;
  1429. orgsrc, orgdst: boolean;
  1430. r:Tregister;
  1431. begin
  1432. {$ifdef extdebug}
  1433. if len > high(longint) then
  1434. internalerror(2002072704);
  1435. {$endif extdebug}
  1436. { make sure short loads are handled as optimally as possible }
  1437. if not loadref then
  1438. if (len <= 8) and
  1439. (byte(len) in [1,2,4,8]) then
  1440. begin
  1441. if len < 8 then
  1442. begin
  1443. a_load_ref_ref(list,int_cgsize(len),source,dest);
  1444. if delsource then
  1445. reference_release(list,source);
  1446. end
  1447. else
  1448. begin
  1449. r.enum:=R_F0;
  1450. a_reg_alloc(list,r);
  1451. a_loadfpu_ref_reg(list,OS_F64,source,r);
  1452. if delsource then
  1453. reference_release(list,source);
  1454. a_loadfpu_reg_ref(list,OS_F64,r,dest);
  1455. a_reg_dealloc(list,r);
  1456. end;
  1457. exit;
  1458. end;
  1459. reference_reset(src);
  1460. reference_reset(dst);
  1461. { load the address of source into src.base }
  1462. if loadref then
  1463. begin
  1464. src.base := get_scratch_reg_address(list);
  1465. a_load_ref_reg(list,OS_32,source,src.base);
  1466. orgsrc := false;
  1467. end
  1468. else if not issimpleref(source) or
  1469. ((source.index.number <> NR_NO) and
  1470. ((source.offset + longint(len)) > high(smallint))) then
  1471. begin
  1472. src.base := get_scratch_reg_address(list);
  1473. a_loadaddr_ref_reg(list,source,src.base);
  1474. orgsrc := false;
  1475. end
  1476. else
  1477. begin
  1478. src := source;
  1479. orgsrc := true;
  1480. end;
  1481. if not orgsrc and delsource then
  1482. reference_release(list,source);
  1483. { load the address of dest into dst.base }
  1484. if not issimpleref(dest) or
  1485. ((dest.index.number <> NR_NO) and
  1486. ((dest.offset + longint(len)) > high(smallint))) then
  1487. begin
  1488. dst.base := get_scratch_reg_address(list);
  1489. a_loadaddr_ref_reg(list,dest,dst.base);
  1490. orgdst := false;
  1491. end
  1492. else
  1493. begin
  1494. dst := dest;
  1495. orgdst := true;
  1496. end;
  1497. count := len div 8;
  1498. if count > 4 then
  1499. { generate a loop }
  1500. begin
  1501. { the offsets are zero after the a_loadaddress_ref_reg and just }
  1502. { have to be set to 8. I put an Inc there so debugging may be }
  1503. { easier (should offset be different from zero here, it will be }
  1504. { easy to notice in the generated assembler }
  1505. inc(dst.offset,8);
  1506. inc(src.offset,8);
  1507. list.concat(taicpu.op_reg_reg_const(A_SUBI,src.base,src.base,8));
  1508. list.concat(taicpu.op_reg_reg_const(A_SUBI,dst.base,dst.base,8));
  1509. countreg := get_scratch_reg_int(list,OS_INT);
  1510. a_load_const_reg(list,OS_32,count,countreg);
  1511. { explicitely allocate R_0 since it can be used safely here }
  1512. { (for holding date that's being copied) }
  1513. r.enum:=R_F0;
  1514. a_reg_alloc(list,r);
  1515. objectlibrary.getlabel(lab);
  1516. a_label(list, lab);
  1517. list.concat(taicpu.op_reg_reg_const(A_SUBIC_,countreg,countreg,1));
  1518. r.enum:=R_F0;
  1519. list.concat(taicpu.op_reg_ref(A_LFDU,r,src));
  1520. list.concat(taicpu.op_reg_ref(A_STFDU,r,dst));
  1521. a_jmp(list,A_BC,C_NE,0,lab);
  1522. free_scratch_reg(list,countreg);
  1523. a_reg_dealloc(list,r);
  1524. len := len mod 8;
  1525. end;
  1526. count := len div 8;
  1527. if count > 0 then
  1528. { unrolled loop }
  1529. begin
  1530. r.enum:=R_F0;
  1531. a_reg_alloc(list,r);
  1532. for count2 := 1 to count do
  1533. begin
  1534. a_loadfpu_ref_reg(list,OS_F64,src,r);
  1535. a_loadfpu_reg_ref(list,OS_F64,r,dst);
  1536. inc(src.offset,8);
  1537. inc(dst.offset,8);
  1538. end;
  1539. a_reg_dealloc(list,r);
  1540. len := len mod 8;
  1541. end;
  1542. if (len and 4) <> 0 then
  1543. begin
  1544. r.enum:=R_INTREGISTER;
  1545. r.number:=NR_R0;
  1546. a_reg_alloc(list,r);
  1547. a_load_ref_reg(list,OS_32,src,r);
  1548. a_load_reg_ref(list,OS_32,r,dst);
  1549. inc(src.offset,4);
  1550. inc(dst.offset,4);
  1551. a_reg_dealloc(list,r);
  1552. end;
  1553. { copy the leftovers }
  1554. if (len and 2) <> 0 then
  1555. begin
  1556. r.enum:=R_INTREGISTER;
  1557. r.number:=NR_R0;
  1558. a_reg_alloc(list,r);
  1559. a_load_ref_reg(list,OS_16,src,r);
  1560. a_load_reg_ref(list,OS_16,r,dst);
  1561. inc(src.offset,2);
  1562. inc(dst.offset,2);
  1563. a_reg_dealloc(list,r);
  1564. end;
  1565. if (len and 1) <> 0 then
  1566. begin
  1567. r.enum:=R_INTREGISTER;
  1568. r.number:=NR_R0;
  1569. a_reg_alloc(list,r);
  1570. a_load_ref_reg(list,OS_8,src,r);
  1571. a_load_reg_ref(list,OS_8,r,dst);
  1572. a_reg_dealloc(list,r);
  1573. end;
  1574. if orgsrc then
  1575. begin
  1576. if delsource then
  1577. reference_release(list,source);
  1578. end
  1579. else
  1580. free_scratch_reg(list,src.base);
  1581. if not orgdst then
  1582. free_scratch_reg(list,dst.base);
  1583. end;
  1584. procedure tcgppc.g_overflowcheck(list: taasmoutput; const p: tnode);
  1585. var
  1586. hl : tasmlabel;
  1587. r:Tregister;
  1588. begin
  1589. if not(cs_check_overflow in aktlocalswitches) then
  1590. exit;
  1591. objectlibrary.getlabel(hl);
  1592. if not ((p.resulttype.def.deftype=pointerdef) or
  1593. ((p.resulttype.def.deftype=orddef) and
  1594. (torddef(p.resulttype.def).typ in [u64bit,u16bit,u32bit,u8bit,uchar,
  1595. bool8bit,bool16bit,bool32bit]))) then
  1596. begin
  1597. r.enum:=R_CR7;
  1598. list.concat(taicpu.op_reg(A_MCRXR,r));
  1599. a_jmp(list,A_BC,C_OV,7,hl)
  1600. end
  1601. else
  1602. a_jmp_cond(list,OC_AE,hl);
  1603. a_call_name(list,'FPC_OVERFLOW');
  1604. a_label(list,hl);
  1605. end;
  1606. {***************** This is private property, keep out! :) *****************}
  1607. function tcgppc.issimpleref(const ref: treference): boolean;
  1608. begin
  1609. if (ref.base.number = NR_NO) and
  1610. (ref.index.number <> NR_NO) then
  1611. internalerror(200208101);
  1612. result :=
  1613. not(assigned(ref.symbol)) and
  1614. (((ref.index.number = NR_NO) and
  1615. (ref.offset >= low(smallint)) and
  1616. (ref.offset <= high(smallint))) or
  1617. ((ref.index.number <> NR_NO) and
  1618. (ref.offset = 0)));
  1619. end;
  1620. function tcgppc.fixref(list: taasmoutput; var ref: treference): boolean;
  1621. var
  1622. tmpreg: tregister;
  1623. begin
  1624. result := false;
  1625. if (ref.base.number = NR_NO) then
  1626. ref.base := ref.index;
  1627. if (ref.base.number <> NR_NO) then
  1628. begin
  1629. if (ref.index.number <> NR_NO) and
  1630. ((ref.offset <> 0) or assigned(ref.symbol)) then
  1631. begin
  1632. result := true;
  1633. tmpreg := cg.get_scratch_reg_int(list,OS_INT);
  1634. if not assigned(ref.symbol) and
  1635. (cardinal(ref.offset-low(smallint)) <=
  1636. high(smallint)-low(smallint)) then
  1637. begin
  1638. list.concat(taicpu.op_reg_reg_const(
  1639. A_ADDI,tmpreg,ref.base,ref.offset));
  1640. ref.offset := 0;
  1641. end
  1642. else
  1643. begin
  1644. list.concat(taicpu.op_reg_reg_reg(
  1645. A_ADD,tmpreg,ref.base,ref.index));
  1646. ref.index.number := NR_NO;
  1647. end;
  1648. ref.base := tmpreg;
  1649. end
  1650. end
  1651. else
  1652. if ref.index.number <> NR_NO then
  1653. internalerror(200208102);
  1654. end;
  1655. { find out whether a is of the form 11..00..11b or 00..11...00. If }
  1656. { that's the case, we can use rlwinm to do an AND operation }
  1657. function tcgppc.get_rlwi_const(a: aword; var l1, l2: longint): boolean;
  1658. var
  1659. temp : longint;
  1660. testbit : aword;
  1661. compare: boolean;
  1662. begin
  1663. get_rlwi_const := false;
  1664. if (a = 0) or (a = $ffffffff) then
  1665. exit;
  1666. { start with the lowest bit }
  1667. testbit := 1;
  1668. { check its value }
  1669. compare := boolean(a and testbit);
  1670. { find out how long the run of bits with this value is }
  1671. { (it's impossible that all bits are 1 or 0, because in that case }
  1672. { this function wouldn't have been called) }
  1673. l1 := 31;
  1674. while (((a and testbit) <> 0) = compare) do
  1675. begin
  1676. testbit := testbit shl 1;
  1677. dec(l1);
  1678. end;
  1679. { check the length of the run of bits that comes next }
  1680. compare := not compare;
  1681. l2 := l1;
  1682. while (((a and testbit) <> 0) = compare) and
  1683. (l2 >= 0) do
  1684. begin
  1685. testbit := testbit shl 1;
  1686. dec(l2);
  1687. end;
  1688. { and finally the check whether the rest of the bits all have the }
  1689. { same value }
  1690. compare := not compare;
  1691. temp := l2;
  1692. if temp >= 0 then
  1693. if (a shr (31-temp)) <> ((-ord(compare)) shr (31-temp)) then
  1694. exit;
  1695. { we have done "not(not(compare))", so compare is back to its }
  1696. { initial value. If the lowest bit was 0, a is of the form }
  1697. { 00..11..00 and we need "rlwinm reg,reg,0,l2+1,l1", (+1 }
  1698. { because l2 now contains the position of the last zero of the }
  1699. { first run instead of that of the first 1) so switch l1 and l2 }
  1700. { in that case (we will generate "rlwinm reg,reg,0,l1,l2") }
  1701. if not compare then
  1702. begin
  1703. temp := l1;
  1704. l1 := l2+1;
  1705. l2 := temp;
  1706. end
  1707. else
  1708. { otherwise, l1 currently contains the position of the last }
  1709. { zero instead of that of the first 1 of the second run -> +1 }
  1710. inc(l1);
  1711. { the following is the same as "if l1 = -1 then l1 := 31;" }
  1712. l1 := l1 and 31;
  1713. l2 := l2 and 31;
  1714. get_rlwi_const := true;
  1715. end;
  1716. procedure tcgppc.a_load_store(list:taasmoutput;op: tasmop;reg:tregister;
  1717. ref: treference);
  1718. var
  1719. tmpreg: tregister;
  1720. tmpref: treference;
  1721. r : Tregister;
  1722. begin
  1723. tmpreg.number := NR_NO;
  1724. if assigned(ref.symbol) or
  1725. (cardinal(ref.offset-low(smallint)) >
  1726. high(smallint)-low(smallint)) then
  1727. begin
  1728. if target_info.system = system_powerpc_macos then
  1729. begin
  1730. if ref.base.number <> NR_NO then
  1731. begin
  1732. if macos_direct_globals then
  1733. begin
  1734. {Generates
  1735. add tempreg, ref.base, RTOC
  1736. op reg, symbolplusoffset, tempreg
  1737. which is eqvivalent to the more comprehensive
  1738. addi tempreg, RTOC, symbolplusoffset
  1739. add tempreg, ref.base, tempreg
  1740. op reg, tempreg
  1741. but which saves one instruction.}
  1742. tmpreg := get_scratch_reg_address(list);
  1743. reference_reset(tmpref);
  1744. tmpref.symbol := ref.symbol;
  1745. tmpref.offset := ref.offset;
  1746. tmpref.symaddr := refs_full;
  1747. tmpref.base:= tmpreg;
  1748. r.enum:=R_INTREGISTER;
  1749. r.number:=NR_RTOC;
  1750. list.concat(taicpu.op_reg_reg_reg(A_ADD,tmpreg,
  1751. ref.base,r));
  1752. list.concat(taicpu.op_reg_ref(op,reg,tmpref));
  1753. end
  1754. else
  1755. begin
  1756. tmpreg := get_scratch_reg_address(list);
  1757. reference_reset(tmpref);
  1758. tmpref.symbol := ref.symbol;
  1759. tmpref.offset := ref.offset;
  1760. tmpref.symaddr := refs_full;
  1761. tmpref.base.enum:= R_INTREGISTER;
  1762. tmpref.base.number:= NR_RTOC;
  1763. list.concat(taicpu.op_reg_ref(A_LWZ,tmpreg,tmpref));
  1764. list.concat(taicpu.op_reg_reg_reg(A_ADD,tmpreg,
  1765. ref.base,tmpreg));
  1766. reference_reset(tmpref);
  1767. tmpref.offset := 0;
  1768. tmpref.symaddr := refs_full;
  1769. tmpref.base:= tmpreg;
  1770. list.concat(taicpu.op_reg_ref(op,reg,tmpref));
  1771. end;
  1772. //list.concat(tai_comment.create(strpnew('**** a_load_store 1')));
  1773. end
  1774. else
  1775. begin
  1776. if macos_direct_globals then
  1777. begin
  1778. reference_reset(tmpref);
  1779. tmpref.symbol := ref.symbol;
  1780. tmpref.offset := ref.offset;
  1781. tmpref.symaddr := refs_full;
  1782. tmpref.base.enum:= R_INTREGISTER;
  1783. tmpref.base.number:= NR_RTOC;
  1784. list.concat(taicpu.op_reg_ref(op,reg,tmpref));
  1785. end
  1786. else
  1787. begin
  1788. tmpreg := get_scratch_reg_address(list);
  1789. reference_reset(tmpref);
  1790. tmpref.symbol := ref.symbol;
  1791. tmpref.offset := ref.offset;
  1792. tmpref.symaddr := refs_full;
  1793. tmpref.base.enum:= R_INTREGISTER;
  1794. tmpref.base.number:= NR_R0;
  1795. list.concat(taicpu.op_reg_ref(A_LWZ,tmpreg,tmpref));
  1796. reference_reset(tmpref);
  1797. tmpref.offset := 0;
  1798. tmpref.symaddr := refs_full;
  1799. tmpref.base:= tmpreg;
  1800. list.concat(taicpu.op_reg_ref(op,reg,tmpref));
  1801. end;
  1802. //list.concat(tai_comment.create(strpnew('*** a_load_store 2')));
  1803. end;
  1804. end
  1805. else
  1806. begin
  1807. tmpreg := get_scratch_reg_address(list);
  1808. reference_reset(tmpref);
  1809. tmpref.symbol := ref.symbol;
  1810. tmpref.offset := ref.offset;
  1811. tmpref.symaddr := refs_ha;
  1812. if ref.base.number <> NR_NO then
  1813. list.concat(taicpu.op_reg_reg_ref(A_ADDIS,tmpreg,
  1814. ref.base,tmpref))
  1815. else
  1816. list.concat(taicpu.op_reg_ref(A_LIS,tmpreg,tmpref));
  1817. ref.base := tmpreg;
  1818. ref.symaddr := refs_l;
  1819. list.concat(taicpu.op_reg_ref(op,reg,ref));
  1820. end
  1821. end
  1822. else
  1823. list.concat(taicpu.op_reg_ref(op,reg,ref));
  1824. if (tmpreg.number <> NR_NO) then
  1825. free_scratch_reg(list,tmpreg);
  1826. end;
  1827. procedure tcgppc.a_jmp(list: taasmoutput; op: tasmop; c: tasmcondflag;
  1828. crval: longint; l: tasmlabel);
  1829. var
  1830. p: taicpu;
  1831. begin
  1832. p := taicpu.op_sym(op,objectlibrary.newasmsymbol(l.name));
  1833. if op <> A_B then
  1834. create_cond_norm(c,crval,p.condition);
  1835. p.is_jmp := true;
  1836. list.concat(p)
  1837. end;
  1838. procedure tcg64fppc.a_op64_reg_reg(list : taasmoutput;op:TOpCG;regsrc,regdst : tregister64);
  1839. begin
  1840. a_op64_reg_reg_reg(list,op,regsrc,regdst,regdst);
  1841. end;
  1842. procedure tcg64fppc.a_op64_const_reg(list : taasmoutput;op:TOpCG;value : qword;reg : tregister64);
  1843. begin
  1844. a_op64_const_reg_reg(list,op,value,reg,reg);
  1845. end;
  1846. procedure tcg64fppc.a_op64_reg_reg_reg(list: taasmoutput;op:TOpCG;regsrc1,regsrc2,regdst : tregister64);
  1847. begin
  1848. case op of
  1849. OP_AND,OP_OR,OP_XOR:
  1850. begin
  1851. cg.a_op_reg_reg_reg(list,op,OS_32,regsrc1.reglo,regsrc2.reglo,regdst.reglo);
  1852. cg.a_op_reg_reg_reg(list,op,OS_32,regsrc1.reghi,regsrc2.reghi,regdst.reghi);
  1853. end;
  1854. OP_ADD:
  1855. begin
  1856. list.concat(taicpu.op_reg_reg_reg(A_ADDC,regdst.reglo,regsrc1.reglo,regsrc2.reglo));
  1857. list.concat(taicpu.op_reg_reg_reg(A_ADDE,regdst.reghi,regsrc1.reghi,regsrc2.reghi));
  1858. end;
  1859. OP_SUB:
  1860. begin
  1861. list.concat(taicpu.op_reg_reg_reg(A_SUBC,regdst.reglo,regsrc2.reglo,regsrc1.reglo));
  1862. list.concat(taicpu.op_reg_reg_reg(A_SUBFE,regdst.reghi,regsrc1.reghi,regsrc2.reghi));
  1863. end;
  1864. else
  1865. internalerror(2002072801);
  1866. end;
  1867. end;
  1868. procedure tcg64fppc.a_op64_const_reg_reg(list: taasmoutput;op:TOpCG;value : qword;regsrc,regdst : tregister64);
  1869. const
  1870. ops: array[boolean,1..3] of tasmop = ((A_ADDIC,A_ADDC,A_ADDZE),
  1871. (A_SUBIC,A_SUBC,A_ADDME));
  1872. var
  1873. tmpreg: tregister;
  1874. tmpreg64: tregister64;
  1875. issub: boolean;
  1876. begin
  1877. case op of
  1878. OP_AND,OP_OR,OP_XOR:
  1879. begin
  1880. cg.a_op_const_reg_reg(list,op,OS_32,cardinal(value),regsrc.reglo,regdst.reglo);
  1881. cg.a_op_const_reg_reg(list,op,OS_32,value shr 32,regsrc.reghi,
  1882. regdst.reghi);
  1883. end;
  1884. OP_ADD, OP_SUB:
  1885. begin
  1886. if (longint(value) <> 0) then
  1887. begin
  1888. issub := op = OP_SUB;
  1889. if (longint(value)-ord(issub) >= -32768) and
  1890. (longint(value)-ord(issub) <= 32767) then
  1891. begin
  1892. list.concat(taicpu.op_reg_reg_const(ops[issub,1],
  1893. regdst.reglo,regsrc.reglo,longint(value)));
  1894. list.concat(taicpu.op_reg_reg(ops[issub,3],
  1895. regdst.reghi,regsrc.reghi));
  1896. end
  1897. else if ((value shr 32) = 0) then
  1898. begin
  1899. tmpreg := cg.get_scratch_reg_int(list,OS_32);
  1900. cg.a_load_const_reg(list,OS_32,cardinal(value),tmpreg);
  1901. list.concat(taicpu.op_reg_reg_reg(ops[issub,2],
  1902. regdst.reglo,regsrc.reglo,tmpreg));
  1903. cg.free_scratch_reg(list,tmpreg);
  1904. list.concat(taicpu.op_reg_reg(ops[issub,3],
  1905. regdst.reghi,regsrc.reghi));
  1906. end
  1907. else
  1908. begin
  1909. tmpreg64.reglo := cg.get_scratch_reg_int(list,OS_INT);
  1910. tmpreg64.reghi := cg.get_scratch_reg_int(list,OS_INT);
  1911. a_load64_const_reg(list,value,tmpreg64);
  1912. a_op64_reg_reg_reg(list,op,tmpreg64,regsrc,regdst);
  1913. cg.free_scratch_reg(list,tmpreg64.reghi);
  1914. cg.free_scratch_reg(list,tmpreg64.reglo);
  1915. end
  1916. end
  1917. else
  1918. begin
  1919. cg.a_load_reg_reg(list,OS_INT,OS_INT,regsrc.reglo,regdst.reglo);
  1920. cg.a_op_const_reg_reg(list,op,OS_32,value shr 32,regsrc.reghi,
  1921. regdst.reghi);
  1922. end;
  1923. end;
  1924. else
  1925. internalerror(2002072802);
  1926. end;
  1927. end;
  1928. begin
  1929. cg := tcgppc.create;
  1930. cg64 :=tcg64fppc.create;
  1931. end.
  1932. {
  1933. $Log$
  1934. Revision 1.72 2003-03-11 21:46:24 jonas
  1935. * lots of new regallocator fixes, both in generic and ppc-specific code
  1936. (ppc compiler still can't compile the linux system unit though)
  1937. Revision 1.71 2003/02/19 22:00:16 daniel
  1938. * Code generator converted to new register notation
  1939. - Horribily outdated todo.txt removed
  1940. Revision 1.70 2003/01/13 17:17:50 olle
  1941. * changed global var access, TOC now contain pointers to globals
  1942. * fixed handling of function pointers
  1943. Revision 1.69 2003/01/09 22:00:53 florian
  1944. * fixed some PowerPC issues
  1945. Revision 1.68 2003/01/08 18:43:58 daniel
  1946. * Tregister changed into a record
  1947. Revision 1.67 2002/12/15 19:22:01 florian
  1948. * fixed some crashes and a rte 201
  1949. Revision 1.66 2002/11/28 10:55:16 olle
  1950. * macos: changing code gen for references to globals
  1951. Revision 1.65 2002/11/07 15:50:23 jonas
  1952. * fixed bctr(l) problems
  1953. Revision 1.64 2002/11/04 18:24:19 olle
  1954. * macos: globals are located in TOC and relative r2, instead of absolute
  1955. Revision 1.63 2002/10/28 22:24:28 olle
  1956. * macos entry/exit: only used registers are saved
  1957. - macos entry/exit: stackptr not saved in r31 anymore
  1958. * macos entry/exit: misc fixes
  1959. Revision 1.62 2002/10/19 23:51:48 olle
  1960. * macos stack frame size computing updated
  1961. + macos epilogue: control register now restored
  1962. * macos prologue and epilogue: fp reg now saved and restored
  1963. Revision 1.61 2002/10/19 12:50:36 olle
  1964. * reorganized prologue and epilogue routines
  1965. Revision 1.60 2002/10/02 21:49:51 florian
  1966. * all A_BL instructions replaced by calls to a_call_name
  1967. Revision 1.59 2002/10/02 13:24:58 jonas
  1968. * changed a_call_* so that no superfluous code is generated anymore
  1969. Revision 1.58 2002/09/17 18:54:06 jonas
  1970. * a_load_reg_reg() now has two size parameters: source and dest. This
  1971. allows some optimizations on architectures that don't encode the
  1972. register size in the register name.
  1973. Revision 1.57 2002/09/10 21:22:25 jonas
  1974. + added some internal errors
  1975. * fixed bug in sysv exit code
  1976. Revision 1.56 2002/09/08 20:11:56 jonas
  1977. * fixed TOpCmp2AsmCond array (some unsigned equivalents were wrong)
  1978. Revision 1.55 2002/09/08 13:03:26 jonas
  1979. * several large offset-related fixes
  1980. Revision 1.54 2002/09/07 17:54:58 florian
  1981. * first part of PowerPC fixes
  1982. Revision 1.53 2002/09/07 15:25:14 peter
  1983. * old logs removed and tabs fixed
  1984. Revision 1.52 2002/09/02 10:14:51 jonas
  1985. + a_call_reg()
  1986. * small fix in a_call_ref()
  1987. Revision 1.51 2002/09/02 06:09:02 jonas
  1988. * fixed range error
  1989. Revision 1.50 2002/09/01 21:04:49 florian
  1990. * several powerpc related stuff fixed
  1991. Revision 1.49 2002/09/01 12:09:27 peter
  1992. + a_call_reg, a_call_loc added
  1993. * removed exprasmlist references
  1994. Revision 1.48 2002/08/31 21:38:02 jonas
  1995. * fixed a_call_ref (it should load ctr, not lr)
  1996. Revision 1.47 2002/08/31 21:30:45 florian
  1997. * fixed several problems caused by Jonas' commit :)
  1998. Revision 1.46 2002/08/31 19:25:50 jonas
  1999. + implemented a_call_ref()
  2000. Revision 1.45 2002/08/18 22:16:14 florian
  2001. + the ppc gas assembler writer adds now registers aliases
  2002. to the assembler file
  2003. Revision 1.44 2002/08/17 18:23:53 florian
  2004. * some assembler writer bugs fixed
  2005. Revision 1.43 2002/08/17 09:23:49 florian
  2006. * first part of procinfo rewrite
  2007. Revision 1.42 2002/08/16 14:24:59 carl
  2008. * issameref() to test if two references are the same (then emit no opcodes)
  2009. + ret_in_reg to replace ret_in_acc
  2010. (fix some register allocation bugs at the same time)
  2011. + save_std_register now has an extra parameter which is the
  2012. usedinproc registers
  2013. Revision 1.41 2002/08/15 08:13:54 carl
  2014. - a_load_sym_ofs_reg removed
  2015. * loadvmt now calls loadaddr_ref_reg instead
  2016. Revision 1.40 2002/08/11 14:32:32 peter
  2017. * renamed current_library to objectlibrary
  2018. Revision 1.39 2002/08/11 13:24:18 peter
  2019. * saving of asmsymbols in ppu supported
  2020. * asmsymbollist global is removed and moved into a new class
  2021. tasmlibrarydata that will hold the info of a .a file which
  2022. corresponds with a single module. Added librarydata to tmodule
  2023. to keep the library info stored for the module. In the future the
  2024. objectfiles will also be stored to the tasmlibrarydata class
  2025. * all getlabel/newasmsymbol and friends are moved to the new class
  2026. Revision 1.38 2002/08/11 11:39:31 jonas
  2027. + powerpc-specific genlinearlist
  2028. Revision 1.37 2002/08/10 17:15:31 jonas
  2029. * various fixes and optimizations
  2030. Revision 1.36 2002/08/06 20:55:23 florian
  2031. * first part of ppc calling conventions fix
  2032. Revision 1.35 2002/08/06 07:12:05 jonas
  2033. * fixed bug in g_flags2reg()
  2034. * and yet more constant operation fixes :)
  2035. Revision 1.34 2002/08/05 08:58:53 jonas
  2036. * fixed compilation problems
  2037. Revision 1.33 2002/08/04 12:57:55 jonas
  2038. * more misc. fixes, mostly constant-related
  2039. }