ncgutil.pas 108 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Helper routines for all code generators
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit ncgutil;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,cpuinfo,
  22. globtype,
  23. cpubase,cgbase,parabase,cgutils,
  24. aasmbase,aasmtai,aasmdata,aasmcpu,
  25. symconst,symbase,symdef,symsym,symtype,symtable
  26. {$ifndef cpu64bit}
  27. ,cg64f32
  28. {$endif cpu64bit}
  29. ;
  30. type
  31. tloadregvars = (lr_dont_load_regvars, lr_load_regvars);
  32. pusedregvars = ^tusedregvars;
  33. tusedregvars = record
  34. intregvars, fpuregvars, mmregvars: Tsuperregisterworklist;
  35. end;
  36. {
  37. Not used currently, implemented because I thought we had to
  38. synchronise around if/then/else as well, but not needed. May
  39. still be useful for SSA once we get around to implementing
  40. that (JM)
  41. pusedregvarscommon = ^tusedregvarscommon;
  42. tusedregvarscommon = record
  43. allregvars, commonregvars, myregvars: tusedregvars;
  44. end;
  45. }
  46. procedure firstcomplex(p : tbinarynode);
  47. procedure maketojumpbool(list:TAsmList; p : tnode; loadregvars: tloadregvars);
  48. // procedure remove_non_regvars_from_loc(const t: tlocation; var regs:Tsuperregisterset);
  49. procedure location_force_reg(list:TAsmList;var l:tlocation;dst_size:TCGSize;maybeconst:boolean);
  50. procedure location_force_fpureg(list:TAsmList;var l: tlocation;maybeconst:boolean);
  51. procedure location_force_mem(list:TAsmList;var l:tlocation);
  52. procedure location_force_mmregscalar(list:TAsmList;var l: tlocation;maybeconst:boolean);
  53. procedure location_force_mmreg(list:TAsmList;var l: tlocation;maybeconst:boolean);
  54. { Retrieve the location of the data pointed to in location l, when the location is
  55. a register it is expected to contain the address of the data }
  56. procedure location_get_data_ref(list:TAsmList;const l:tlocation;var ref:treference;loadref:boolean);
  57. function maybe_pushfpu(list:TAsmList;needed : byte;var l:tlocation) : boolean;
  58. procedure alloc_proc_symbol(pd: tprocdef);
  59. procedure gen_proc_symbol(list:TAsmList);
  60. procedure gen_proc_symbol_end(list:TAsmList);
  61. procedure gen_proc_entry_code(list:TAsmList);
  62. procedure gen_proc_exit_code(list:TAsmList);
  63. procedure gen_stack_check_size_para(list:TAsmList);
  64. procedure gen_stack_check_call(list:TAsmList);
  65. procedure gen_save_used_regs(list:TAsmList);
  66. procedure gen_restore_used_regs(list:TAsmList);
  67. procedure gen_initialize_code(list:TAsmList);
  68. procedure gen_finalize_code(list:TAsmList);
  69. procedure gen_entry_code(list:TAsmList);
  70. procedure gen_exit_code(list:TAsmList);
  71. procedure gen_load_para_value(list:TAsmList);
  72. procedure gen_load_return_value(list:TAsmList);
  73. procedure gen_external_stub(list:TAsmList;pd:tprocdef;const externalname:string);
  74. procedure gen_intf_wrappers(list:TAsmList;st:TSymtable);
  75. procedure gen_load_vmt_register(list:TAsmList;objdef:tobjectdef;selfloc:tlocation;var vmtreg:tregister);
  76. procedure get_used_regvars(n: tnode; var rv: tusedregvars);
  77. { adds the regvars used in n and its children to rv.allregvars,
  78. those which were already in rv.allregvars to rv.commonregvars and
  79. uses rv.myregvars as scratch (so that two uses of the same regvar
  80. in a single tree to make it appear in commonregvars). Useful to
  81. find out which regvars are used in two different node trees
  82. (e.g. in the "else" and "then" path, or in various case blocks }
  83. // procedure get_used_regvars_common(n: tnode; var rv: tusedregvarscommon);
  84. procedure gen_sync_regvars(list:TAsmList; var rv: tusedregvars);
  85. { if the result of n is a LOC_C(..)REGISTER, try to find the corresponding }
  86. { loadn and change its location to a new register (= SSA). In case reload }
  87. { is true, transfer the old to the new register }
  88. procedure maybechangeloadnodereg(list: TAsmList; var n: tnode; reload: boolean);
  89. {#
  90. Allocate the buffers for exception management and setjmp environment.
  91. Return a pointer to these buffers, send them to the utility routine
  92. so they are registered, and then call setjmp.
  93. Then compare the result of setjmp with 0, and if not equal
  94. to zero, then jump to exceptlabel.
  95. Also store the result of setjmp to a temporary space by calling g_save_exception_reason
  96. It is to note that this routine may be called *after* the stackframe of a
  97. routine has been called, therefore on machines where the stack cannot
  98. be modified, all temps should be allocated on the heap instead of the
  99. stack.
  100. }
  101. const
  102. EXCEPT_BUF_SIZE = 3*sizeof(aint);
  103. type
  104. texceptiontemps=record
  105. jmpbuf,
  106. envbuf,
  107. reasonbuf : treference;
  108. end;
  109. procedure get_exception_temps(list:TAsmList;var t:texceptiontemps);
  110. procedure unget_exception_temps(list:TAsmList;const t:texceptiontemps);
  111. procedure new_exception(list:TAsmList;const t:texceptiontemps;exceptlabel:tasmlabel);
  112. procedure free_exception(list:TAsmList;const t:texceptiontemps;a:aint;endexceptlabel:tasmlabel;onlyfree:boolean);
  113. procedure insertbssdata(sym : tglobalvarsym);
  114. procedure gen_alloc_symtable(list:TAsmList;st:TSymtable);
  115. procedure gen_free_symtable(list:TAsmList;st:TSymtable);
  116. procedure location_free(list: TAsmList; const location : TLocation);
  117. function getprocalign : shortint;
  118. procedure gen_pic_helpers(list : TAsmList);
  119. procedure gen_got_load(list : TAsmList);
  120. implementation
  121. uses
  122. version,
  123. cutils,cclasses,
  124. globals,systems,verbose,
  125. ppu,defutil,
  126. procinfo,paramgr,fmodule,
  127. regvars,dbgbase,
  128. pass_1,pass_2,
  129. nbas,ncon,nld,nmem,nutils,
  130. tgobj,cgobj
  131. {$ifdef powerpc}
  132. , cpupi
  133. {$endif}
  134. {$ifdef powerpc64}
  135. , cpupi
  136. {$endif}
  137. {$ifdef SUPPORT_MMX}
  138. , cgx86
  139. {$endif SUPPORT_MMX}
  140. ;
  141. {*****************************************************************************
  142. Misc Helpers
  143. *****************************************************************************}
  144. procedure location_free(list: TAsmList; const location : TLocation);
  145. begin
  146. case location.loc of
  147. LOC_VOID:
  148. ;
  149. LOC_REGISTER,
  150. LOC_CREGISTER:
  151. begin
  152. if getsupreg(location.register)<first_int_imreg then
  153. cg.ungetcpuregister(list,location.register);
  154. end;
  155. LOC_FPUREGISTER,
  156. LOC_CFPUREGISTER:
  157. begin
  158. if getsupreg(location.register)<first_fpu_imreg then
  159. cg.ungetcpuregister(list,location.register);
  160. end;
  161. LOC_MMREGISTER,
  162. LOC_CMMREGISTER :
  163. begin
  164. if getsupreg(location.register)<first_mm_imreg then
  165. cg.ungetcpuregister(list,location.register);
  166. end;
  167. LOC_REFERENCE,
  168. LOC_CREFERENCE :
  169. begin
  170. if use_fixed_stack then
  171. location_freetemp(list,location);
  172. end;
  173. else
  174. internalerror(2004110211);
  175. end;
  176. end;
  177. { DO NOT RELY on the fact that the tnode is not yet swaped
  178. because of inlining code PM }
  179. procedure firstcomplex(p : tbinarynode);
  180. var
  181. hp : tnode;
  182. begin
  183. { always calculate boolean AND and OR from left to right }
  184. if (p.nodetype in [orn,andn]) and
  185. is_boolean(p.left.resultdef) then
  186. begin
  187. if nf_swaped in p.flags then
  188. internalerror(234234);
  189. end
  190. else
  191. if (
  192. (p.expectloc=LOC_FPUREGISTER) and
  193. (p.right.registersfpu > p.left.registersfpu)
  194. ) or
  195. (
  196. (
  197. (
  198. ((p.left.registersfpu = 0) and (p.right.registersfpu = 0)) or
  199. (p.expectloc<>LOC_FPUREGISTER)
  200. ) and
  201. (p.left.registersint<p.right.registersint)
  202. )
  203. ) then
  204. begin
  205. hp:=p.left;
  206. p.left:=p.right;
  207. p.right:=hp;
  208. if nf_swaped in p.flags then
  209. exclude(p.flags,nf_swaped)
  210. else
  211. include(p.flags,nf_swaped);
  212. end;
  213. end;
  214. procedure maketojumpbool(list:TAsmList; p : tnode; loadregvars: tloadregvars);
  215. {
  216. produces jumps to true respectively false labels using boolean expressions
  217. depending on whether the loading of regvars is currently being
  218. synchronized manually (such as in an if-node) or automatically (most of
  219. the other cases where this procedure is called), loadregvars can be
  220. "lr_load_regvars" or "lr_dont_load_regvars"
  221. }
  222. var
  223. opsize : tcgsize;
  224. storepos : tfileposinfo;
  225. tmpreg : tregister;
  226. begin
  227. if nf_error in p.flags then
  228. exit;
  229. storepos:=current_filepos;
  230. current_filepos:=p.fileinfo;
  231. if is_boolean(p.resultdef) then
  232. begin
  233. {$ifdef OLDREGVARS}
  234. if loadregvars = lr_load_regvars then
  235. load_all_regvars(list);
  236. {$endif OLDREGVARS}
  237. if is_constboolnode(p) then
  238. begin
  239. if tordconstnode(p).value<>0 then
  240. cg.a_jmp_always(list,current_procinfo.CurrTrueLabel)
  241. else
  242. cg.a_jmp_always(list,current_procinfo.CurrFalseLabel)
  243. end
  244. else
  245. begin
  246. opsize:=def_cgsize(p.resultdef);
  247. case p.location.loc of
  248. LOC_SUBSETREG,LOC_CSUBSETREG,
  249. LOC_SUBSETREF,LOC_CSUBSETREF:
  250. begin
  251. tmpreg := cg.getintregister(list,OS_INT);
  252. cg.a_load_loc_reg(list,OS_INT,p.location,tmpreg);
  253. cg.a_cmp_const_reg_label(list,OS_INT,OC_NE,0,tmpreg,current_procinfo.CurrTrueLabel);
  254. cg.a_jmp_always(list,current_procinfo.CurrFalseLabel);
  255. end;
  256. LOC_CREGISTER,LOC_REGISTER,LOC_CREFERENCE,LOC_REFERENCE :
  257. begin
  258. cg.a_cmp_const_loc_label(list,opsize,OC_NE,0,p.location,current_procinfo.CurrTrueLabel);
  259. cg.a_jmp_always(list,current_procinfo.CurrFalseLabel);
  260. end;
  261. LOC_JUMP:
  262. ;
  263. {$ifdef cpuflags}
  264. LOC_FLAGS :
  265. begin
  266. cg.a_jmp_flags(list,p.location.resflags,current_procinfo.CurrTrueLabel);
  267. cg.a_jmp_always(list,current_procinfo.CurrFalseLabel);
  268. end;
  269. {$endif cpuflags}
  270. else
  271. begin
  272. printnode(output,p);
  273. internalerror(200308241);
  274. end;
  275. end;
  276. end;
  277. end
  278. else
  279. internalerror(200112305);
  280. current_filepos:=storepos;
  281. end;
  282. (*
  283. This code needs fixing. It is not safe to use rgint; on the m68000 it
  284. would be rgaddr.
  285. procedure remove_non_regvars_from_loc(const t: tlocation; var regs:Tsuperregisterset);
  286. begin
  287. case t.loc of
  288. LOC_REGISTER:
  289. begin
  290. { can't be a regvar, since it would be LOC_CREGISTER then }
  291. exclude(regs,getsupreg(t.register));
  292. if t.register64.reghi<>NR_NO then
  293. exclude(regs,getsupreg(t.register64.reghi));
  294. end;
  295. LOC_CREFERENCE,LOC_REFERENCE:
  296. begin
  297. if not(cs_opt_regvar in current_settings.optimizerswitches) or
  298. (getsupreg(t.reference.base) in cg.rgint.usableregs) then
  299. exclude(regs,getsupreg(t.reference.base));
  300. if not(cs_opt_regvar in current_settings.optimizerswitches) or
  301. (getsupreg(t.reference.index) in cg.rgint.usableregs) then
  302. exclude(regs,getsupreg(t.reference.index));
  303. end;
  304. end;
  305. end;
  306. *)
  307. {*****************************************************************************
  308. EXCEPTION MANAGEMENT
  309. *****************************************************************************}
  310. procedure get_exception_temps(list:TAsmList;var t:texceptiontemps);
  311. var
  312. srsym : ttypesym;
  313. begin
  314. if jmp_buf_size=-1 then
  315. begin
  316. srsym:=search_system_type('JMP_BUF');
  317. jmp_buf_size:=srsym.typedef.size;
  318. end;
  319. tg.GetTemp(list,EXCEPT_BUF_SIZE,tt_persistent,t.envbuf);
  320. tg.GetTemp(list,jmp_buf_size,tt_persistent,t.jmpbuf);
  321. tg.GetTemp(list,sizeof(aint),tt_persistent,t.reasonbuf);
  322. end;
  323. procedure unget_exception_temps(list:TAsmList;const t:texceptiontemps);
  324. begin
  325. tg.Ungettemp(list,t.jmpbuf);
  326. tg.ungettemp(list,t.envbuf);
  327. tg.ungettemp(list,t.reasonbuf);
  328. end;
  329. procedure new_exception(list:TAsmList;const t:texceptiontemps;exceptlabel:tasmlabel);
  330. var
  331. paraloc1,paraloc2,paraloc3 : tcgpara;
  332. begin
  333. paraloc1.init;
  334. paraloc2.init;
  335. paraloc3.init;
  336. paramanager.getintparaloc(pocall_default,1,paraloc1);
  337. paramanager.getintparaloc(pocall_default,2,paraloc2);
  338. paramanager.getintparaloc(pocall_default,3,paraloc3);
  339. paramanager.allocparaloc(list,paraloc3);
  340. cg.a_paramaddr_ref(list,t.envbuf,paraloc3);
  341. paramanager.allocparaloc(list,paraloc2);
  342. cg.a_paramaddr_ref(list,t.jmpbuf,paraloc2);
  343. { push type of exceptionframe }
  344. paramanager.allocparaloc(list,paraloc1);
  345. cg.a_param_const(list,OS_S32,1,paraloc1);
  346. paramanager.freeparaloc(list,paraloc3);
  347. paramanager.freeparaloc(list,paraloc2);
  348. paramanager.freeparaloc(list,paraloc1);
  349. cg.allocallcpuregisters(list);
  350. cg.a_call_name(list,'FPC_PUSHEXCEPTADDR');
  351. cg.deallocallcpuregisters(list);
  352. paramanager.getintparaloc(pocall_default,1,paraloc1);
  353. paramanager.allocparaloc(list,paraloc1);
  354. cg.a_param_reg(list,OS_ADDR,NR_FUNCTION_RESULT_REG,paraloc1);
  355. paramanager.freeparaloc(list,paraloc1);
  356. cg.allocallcpuregisters(list);
  357. cg.a_call_name(list,'FPC_SETJMP');
  358. cg.deallocallcpuregisters(list);
  359. cg.alloccpuregisters(list,R_INTREGISTER,[RS_FUNCTION_RESULT_REG]);
  360. cg.g_exception_reason_save(list, t.reasonbuf);
  361. cg.a_cmp_const_reg_label(list,OS_S32,OC_NE,0,cg.makeregsize(list,NR_FUNCTION_RESULT_REG,OS_S32),exceptlabel);
  362. cg.dealloccpuregisters(list,R_INTREGISTER,[RS_FUNCTION_RESULT_REG]);
  363. paraloc1.done;
  364. paraloc2.done;
  365. paraloc3.done;
  366. end;
  367. procedure free_exception(list:TAsmList;const t:texceptiontemps;a:aint;endexceptlabel:tasmlabel;onlyfree:boolean);
  368. begin
  369. cg.allocallcpuregisters(list);
  370. cg.a_call_name(list,'FPC_POPADDRSTACK');
  371. cg.deallocallcpuregisters(list);
  372. if not onlyfree then
  373. begin
  374. cg.alloccpuregisters(list,R_INTREGISTER,[RS_FUNCTION_RESULT_REG]);
  375. cg.g_exception_reason_load(list, t.reasonbuf);
  376. cg.a_cmp_const_reg_label(list,OS_INT,OC_EQ,a,NR_FUNCTION_RESULT_REG,endexceptlabel);
  377. cg.dealloccpuregisters(list,R_INTREGISTER,[RS_FUNCTION_RESULT_REG]);
  378. end;
  379. end;
  380. {*****************************************************************************
  381. TLocation
  382. *****************************************************************************}
  383. {$ifndef cpu64bit}
  384. { 32-bit version }
  385. procedure location_force_reg(list:TAsmList;var l:tlocation;dst_size:TCGSize;maybeconst:boolean);
  386. var
  387. hregister,
  388. hregisterhi : tregister;
  389. hreg64 : tregister64;
  390. hl : tasmlabel;
  391. oldloc : tlocation;
  392. const_location: boolean;
  393. begin
  394. oldloc:=l;
  395. if dst_size=OS_NO then
  396. internalerror(200309144);
  397. { handle transformations to 64bit separate }
  398. if dst_size in [OS_64,OS_S64] then
  399. begin
  400. if not (l.size in [OS_64,OS_S64]) then
  401. begin
  402. { load a smaller size to OS_64 }
  403. if l.loc=LOC_REGISTER then
  404. begin
  405. hregister:=cg.makeregsize(list,l.register64.reglo,OS_32);
  406. cg.a_load_reg_reg(list,l.size,OS_32,l.register64.reglo,hregister);
  407. end
  408. else
  409. hregister:=cg.getintregister(list,OS_INT);
  410. { load value in low register }
  411. case l.loc of
  412. LOC_FLAGS :
  413. cg.g_flags2reg(list,OS_INT,l.resflags,hregister);
  414. LOC_JUMP :
  415. begin
  416. cg.a_label(list,current_procinfo.CurrTrueLabel);
  417. cg.a_load_const_reg(list,OS_INT,1,hregister);
  418. current_asmdata.getjumplabel(hl);
  419. cg.a_jmp_always(list,hl);
  420. cg.a_label(list,current_procinfo.CurrFalseLabel);
  421. cg.a_load_const_reg(list,OS_INT,0,hregister);
  422. cg.a_label(list,hl);
  423. end;
  424. else
  425. cg.a_load_loc_reg(list,OS_INT,l,hregister);
  426. end;
  427. { reset hi part, take care of the signed bit of the current value }
  428. hregisterhi:=cg.getintregister(list,OS_INT);
  429. if (l.size in [OS_S8,OS_S16,OS_S32]) then
  430. begin
  431. if l.loc=LOC_CONSTANT then
  432. begin
  433. if (longint(l.value)<0) then
  434. cg.a_load_const_reg(list,OS_32,aint($ffffffff),hregisterhi)
  435. else
  436. cg.a_load_const_reg(list,OS_32,0,hregisterhi);
  437. end
  438. else
  439. begin
  440. cg.a_op_const_reg_reg(list,OP_SAR,OS_32,31,hregister,
  441. hregisterhi);
  442. end;
  443. end
  444. else
  445. cg.a_load_const_reg(list,OS_32,0,hregisterhi);
  446. location_reset(l,LOC_REGISTER,dst_size);
  447. l.register64.reglo:=hregister;
  448. l.register64.reghi:=hregisterhi;
  449. end
  450. else
  451. begin
  452. { 64bit to 64bit }
  453. if ((l.loc=LOC_CREGISTER) and maybeconst) then
  454. begin
  455. hregister:=l.register64.reglo;
  456. hregisterhi:=l.register64.reghi;
  457. const_location := true;
  458. end
  459. else
  460. begin
  461. hregister:=cg.getintregister(list,OS_INT);
  462. hregisterhi:=cg.getintregister(list,OS_INT);
  463. const_location := false;
  464. end;
  465. hreg64.reglo:=hregister;
  466. hreg64.reghi:=hregisterhi;
  467. { load value in new register }
  468. cg64.a_load64_loc_reg(list,l,hreg64);
  469. if not const_location then
  470. location_reset(l,LOC_REGISTER,dst_size)
  471. else
  472. location_reset(l,LOC_CREGISTER,dst_size);
  473. l.register64.reglo:=hregister;
  474. l.register64.reghi:=hregisterhi;
  475. end;
  476. end
  477. else
  478. begin
  479. {Do not bother to recycle the existing register. The register
  480. allocator eliminates unnecessary moves, so it's not needed
  481. and trying to recycle registers can cause problems because
  482. the registers changes size and may need aditional constraints.
  483. Not if it's about LOC_CREGISTER's (JM)
  484. }
  485. const_location :=
  486. (maybeconst) and
  487. (l.loc = LOC_CREGISTER) and
  488. (TCGSize2Size[l.size] = TCGSize2Size[dst_size]) and
  489. ((l.size = dst_size) or
  490. (TCGSize2Size[l.size] = TCGSize2Size[OS_INT]));
  491. if not const_location then
  492. hregister:=cg.getintregister(list,dst_size)
  493. else
  494. hregister := l.register;
  495. { load value in new register }
  496. case l.loc of
  497. LOC_FLAGS :
  498. cg.g_flags2reg(list,dst_size,l.resflags,hregister);
  499. LOC_JUMP :
  500. begin
  501. cg.a_label(list,current_procinfo.CurrTrueLabel);
  502. cg.a_load_const_reg(list,dst_size,1,hregister);
  503. current_asmdata.getjumplabel(hl);
  504. cg.a_jmp_always(list,hl);
  505. cg.a_label(list,current_procinfo.CurrFalseLabel);
  506. cg.a_load_const_reg(list,dst_size,0,hregister);
  507. cg.a_label(list,hl);
  508. end;
  509. else
  510. begin
  511. { load_loc_reg can only handle size >= l.size, when the
  512. new size is smaller then we need to adjust the size
  513. of the orignal and maybe recalculate l.register for i386 }
  514. if (TCGSize2Size[dst_size]<TCGSize2Size[l.size]) then
  515. begin
  516. if (l.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  517. l.register:=cg.makeregsize(list,l.register,dst_size);
  518. { for big endian systems, the reference's offset must }
  519. { be increased in this case, since they have the }
  520. { MSB first in memory and e.g. byte(word_var) should }
  521. { return the second byte in this case (JM) }
  522. if (target_info.endian = ENDIAN_BIG) and
  523. (l.loc in [LOC_REFERENCE,LOC_CREFERENCE,LOC_SUBSETREF,LOC_CSUBSETREF]) then
  524. inc(l.reference.offset,TCGSize2Size[l.size]-TCGSize2Size[dst_size]);
  525. {$ifdef x86}
  526. if not (l.loc in [LOC_SUBSETREG,LOC_CSUBSETREG]) then
  527. l.size:=dst_size;
  528. {$endif x86}
  529. end;
  530. cg.a_load_loc_reg(list,dst_size,l,hregister);
  531. if (TCGSize2Size[dst_size]<TCGSize2Size[l.size])
  532. {$ifdef x86}
  533. and (l.loc in [LOC_SUBSETREG,LOC_CSUBSETREG])
  534. {$endif x86}
  535. then
  536. l.size:=dst_size;
  537. end;
  538. end;
  539. if not const_location then
  540. location_reset(l,LOC_REGISTER,dst_size)
  541. else
  542. location_reset(l,LOC_CREGISTER,dst_size);
  543. l.register:=hregister;
  544. end;
  545. { Release temp when it was a reference }
  546. if oldloc.loc=LOC_REFERENCE then
  547. location_freetemp(list,oldloc);
  548. end;
  549. {$else cpu64bit}
  550. { 64-bit version }
  551. procedure location_force_reg(list:TAsmList;var l:tlocation;dst_size:TCGSize;maybeconst:boolean);
  552. var
  553. hregister : tregister;
  554. hl : tasmlabel;
  555. oldloc : tlocation;
  556. begin
  557. oldloc:=l;
  558. hregister:=cg.getintregister(list,dst_size);
  559. { load value in new register }
  560. case l.loc of
  561. LOC_FLAGS :
  562. cg.g_flags2reg(list,dst_size,l.resflags,hregister);
  563. LOC_JUMP :
  564. begin
  565. cg.a_label(list,current_procinfo.CurrTrueLabel);
  566. cg.a_load_const_reg(list,dst_size,1,hregister);
  567. current_asmdata.getjumplabel(hl);
  568. cg.a_jmp_always(list,hl);
  569. cg.a_label(list,current_procinfo.CurrFalseLabel);
  570. cg.a_load_const_reg(list,dst_size,0,hregister);
  571. cg.a_label(list,hl);
  572. end;
  573. else
  574. begin
  575. { load_loc_reg can only handle size >= l.size, when the
  576. new size is smaller then we need to adjust the size
  577. of the orignal and maybe recalculate l.register for i386 }
  578. if (TCGSize2Size[dst_size]<TCGSize2Size[l.size]) then
  579. begin
  580. if (l.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  581. l.register:=cg.makeregsize(list,l.register,dst_size);
  582. { for big endian systems, the reference's offset must }
  583. { be increased in this case, since they have the }
  584. { MSB first in memory and e.g. byte(word_var) should }
  585. { return the second byte in this case (JM) }
  586. if (target_info.endian = ENDIAN_BIG) and
  587. (l.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  588. inc(l.reference.offset,TCGSize2Size[l.size]-TCGSize2Size[dst_size]);
  589. {$ifdef x86}
  590. l.size:=dst_size;
  591. {$endif x86}
  592. end;
  593. cg.a_load_loc_reg(list,dst_size,l,hregister);
  594. {$ifndef x86}
  595. if (TCGSize2Size[dst_size]<TCGSize2Size[l.size]) then
  596. l.size:=dst_size;
  597. {$endif not x86}
  598. end;
  599. end;
  600. if (l.loc <> LOC_CREGISTER) or
  601. not maybeconst then
  602. location_reset(l,LOC_REGISTER,dst_size)
  603. else
  604. location_reset(l,LOC_CREGISTER,dst_size);
  605. l.register:=hregister;
  606. { Release temp when it was a reference }
  607. if oldloc.loc=LOC_REFERENCE then
  608. location_freetemp(list,oldloc);
  609. end;
  610. {$endif cpu64bit}
  611. procedure location_force_fpureg(list:TAsmList;var l: tlocation;maybeconst:boolean);
  612. var
  613. reg : tregister;
  614. href : treference;
  615. begin
  616. if (l.loc<>LOC_FPUREGISTER) and
  617. ((l.loc<>LOC_CFPUREGISTER) or (not maybeconst)) then
  618. begin
  619. { if it's in an mm register, store to memory first }
  620. if (l.loc in [LOC_MMREGISTER,LOC_CMMREGISTER]) then
  621. begin
  622. tg.GetTemp(list,tcgsize2size[l.size],tt_normal,href);
  623. cg.a_loadmm_reg_ref(list,l.size,l.size,l.register,href,mms_movescalar);
  624. location_reset(l,LOC_REFERENCE,l.size);
  625. l.reference:=href;
  626. end;
  627. reg:=cg.getfpuregister(list,l.size);
  628. cg.a_loadfpu_loc_reg(list,l,reg);
  629. location_freetemp(list,l);
  630. location_reset(l,LOC_FPUREGISTER,l.size);
  631. l.register:=reg;
  632. end;
  633. end;
  634. procedure location_force_mmregscalar(list:TAsmList;var l: tlocation;maybeconst:boolean);
  635. var
  636. reg : tregister;
  637. href : treference;
  638. begin
  639. if (l.loc<>LOC_MMREGISTER) and
  640. ((l.loc<>LOC_CMMREGISTER) or (not maybeconst)) then
  641. begin
  642. { if it's in an fpu register, store to memory first }
  643. if (l.loc in [LOC_FPUREGISTER,LOC_CFPUREGISTER]) then
  644. begin
  645. tg.GetTemp(list,tcgsize2size[l.size],tt_normal,href);
  646. cg.a_loadfpu_reg_ref(list,l.size,l.register,href);
  647. location_reset(l,LOC_REFERENCE,l.size);
  648. l.reference:=href;
  649. end;
  650. reg:=cg.getmmregister(list,l.size);
  651. cg.a_loadmm_loc_reg(list,l.size,l,reg,mms_movescalar);
  652. location_freetemp(list,l);
  653. location_reset(l,LOC_MMREGISTER,l.size);
  654. l.register:=reg;
  655. end;
  656. end;
  657. procedure location_force_mmreg(list:TAsmList;var l: tlocation;maybeconst:boolean);
  658. var
  659. reg : tregister;
  660. href : treference;
  661. begin
  662. if (l.loc<>LOC_MMREGISTER) and
  663. ((l.loc<>LOC_CMMREGISTER) or (not maybeconst)) then
  664. begin
  665. reg:=cg.getmmregister(list,OS_VECTOR);
  666. cg.a_loadmm_loc_reg(list,OS_VECTOR,l,reg,nil);
  667. location_freetemp(list,l);
  668. location_reset(l,LOC_MMREGISTER,OS_VECTOR);
  669. l.register:=reg;
  670. end;
  671. end;
  672. procedure location_force_mem(list:TAsmList;var l:tlocation);
  673. var
  674. r : treference;
  675. begin
  676. case l.loc of
  677. LOC_FPUREGISTER,
  678. LOC_CFPUREGISTER :
  679. begin
  680. tg.GetTemp(list,TCGSize2Size[l.size],tt_normal,r);
  681. cg.a_loadfpu_reg_ref(list,l.size,l.register,r);
  682. location_reset(l,LOC_REFERENCE,l.size);
  683. l.reference:=r;
  684. end;
  685. LOC_MMREGISTER,
  686. LOC_CMMREGISTER:
  687. begin
  688. tg.GetTemp(list,TCGSize2Size[l.size],tt_normal,r);
  689. cg.a_loadmm_reg_ref(list,l.size,l.size,l.register,r,mms_movescalar);
  690. location_reset(l,LOC_REFERENCE,l.size);
  691. l.reference:=r;
  692. end;
  693. LOC_CONSTANT,
  694. LOC_REGISTER,
  695. LOC_CREGISTER :
  696. begin
  697. tg.GetTemp(list,TCGSize2Size[l.size],tt_normal,r);
  698. {$ifndef cpu64bit}
  699. if l.size in [OS_64,OS_S64] then
  700. cg64.a_load64_loc_ref(list,l,r)
  701. else
  702. {$endif cpu64bit}
  703. cg.a_load_loc_ref(list,l.size,l,r);
  704. location_reset(l,LOC_REFERENCE,l.size);
  705. l.reference:=r;
  706. end;
  707. LOC_SUBSETREG,
  708. LOC_CSUBSETREG,
  709. LOC_SUBSETREF,
  710. LOC_CSUBSETREF:
  711. begin
  712. tg.GetTemp(list,TCGSize2Size[l.size],tt_normal,r);
  713. cg.a_load_loc_ref(list,l.size,l,r);
  714. location_reset(l,LOC_REFERENCE,l.size);
  715. l.reference:=r;
  716. end;
  717. LOC_CREFERENCE,
  718. LOC_REFERENCE : ;
  719. else
  720. internalerror(200203219);
  721. end;
  722. end;
  723. procedure location_get_data_ref(list:TAsmList;const l:tlocation;var ref:treference;loadref:boolean);
  724. begin
  725. case l.loc of
  726. LOC_REGISTER,
  727. LOC_CREGISTER :
  728. begin
  729. if not loadref then
  730. internalerror(200410231);
  731. reference_reset_base(ref,l.register,0);
  732. end;
  733. LOC_REFERENCE,
  734. LOC_CREFERENCE :
  735. begin
  736. if loadref then
  737. begin
  738. reference_reset_base(ref,cg.getaddressregister(list),0);
  739. cg.a_load_ref_reg(list,OS_ADDR,OS_ADDR,l.reference,ref.base);
  740. end
  741. else
  742. ref:=l.reference;
  743. end;
  744. else
  745. internalerror(200309181);
  746. end;
  747. end;
  748. {*****************************************************************************
  749. Maybe_Save
  750. *****************************************************************************}
  751. function maybe_pushfpu(list:TAsmList;needed : byte;var l:tlocation) : boolean;
  752. begin
  753. {$ifdef i386}
  754. if (needed>=maxfpuregs) and
  755. (l.loc = LOC_FPUREGISTER) then
  756. begin
  757. location_force_mem(list,l);
  758. maybe_pushfpu:=true;
  759. end
  760. else
  761. maybe_pushfpu:=false;
  762. {$else i386}
  763. maybe_pushfpu:=false;
  764. {$endif i386}
  765. end;
  766. {****************************************************************************
  767. Init/Finalize Code
  768. ****************************************************************************}
  769. procedure copyvalueparas(p:TObject;arg:pointer);
  770. var
  771. href : treference;
  772. hreg : tregister;
  773. list : TAsmList;
  774. hsym : tparavarsym;
  775. l : longint;
  776. localcopyloc : tlocation;
  777. begin
  778. list:=TAsmList(arg);
  779. if (tsym(p).typ=paravarsym) and
  780. (tparavarsym(p).varspez=vs_value) and
  781. (paramanager.push_addr_param(tparavarsym(p).varspez,tparavarsym(p).vardef,current_procinfo.procdef.proccalloption)) then
  782. begin
  783. location_get_data_ref(list,tparavarsym(p).initialloc,href,true);
  784. if is_open_array(tparavarsym(p).vardef) or
  785. is_array_of_const(tparavarsym(p).vardef) then
  786. begin
  787. { cdecl functions don't have a high pointer so it is not possible to generate
  788. a local copy }
  789. if not(current_procinfo.procdef.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  790. begin
  791. hsym:=tparavarsym(tsym(p).owner.Find('high'+tsym(p).name));
  792. if not assigned(hsym) then
  793. internalerror(200306061);
  794. hreg:=cg.getaddressregister(list);
  795. if not is_packed_array(tparavarsym(p).vardef) then
  796. cg.g_copyvaluepara_openarray(list,href,hsym.initialloc,tarraydef(tparavarsym(p).vardef).elesize,hreg)
  797. else
  798. internalerror(2006080401);
  799. // cg.g_copyvaluepara_packedopenarray(list,href,hsym.intialloc,tarraydef(tparavarsym(p).vardef).elepackedbitsize,hreg);
  800. cg.a_load_reg_loc(list,OS_ADDR,hreg,tparavarsym(p).initialloc);
  801. end;
  802. end
  803. else
  804. begin
  805. { Allocate space for the local copy }
  806. l:=tparavarsym(p).getsize;
  807. localcopyloc.loc:=LOC_REFERENCE;
  808. localcopyloc.size:=int_cgsize(l);
  809. tg.GetLocal(list,l,tparavarsym(p).vardef,localcopyloc.reference);
  810. { Copy data }
  811. if is_shortstring(tparavarsym(p).vardef) then
  812. begin
  813. { this code is only executed before the code for the body and the entry/exit code is generated
  814. so we're allowed to include pi_do_call here; after pass1 is run, this isn't allowed anymore
  815. }
  816. include(current_procinfo.flags,pi_do_call);
  817. cg.g_copyshortstring(list,href,localcopyloc.reference,tstringdef(tparavarsym(p).vardef).len)
  818. end
  819. else
  820. begin
  821. { pass proper alignment info }
  822. localcopyloc.reference.alignment:=tparavarsym(p).vardef.alignment;
  823. cg.g_concatcopy(list,href,localcopyloc.reference,tparavarsym(p).vardef.size);
  824. end;
  825. { update localloc of varsym }
  826. tg.Ungetlocal(list,tparavarsym(p).localloc.reference);
  827. tparavarsym(p).localloc:=localcopyloc;
  828. tparavarsym(p).initialloc:=localcopyloc;
  829. end;
  830. end;
  831. end;
  832. const
  833. {$ifdef cpu64bit}
  834. trashintvalues: array[0..nroftrashvalues-1] of aint = ($5555555555555555,aint($AAAAAAAAAAAAAAAA),aint($EFEFEFEFEFEFEFEF),0);
  835. {$else cpu64bit}
  836. trashintvalues: array[0..nroftrashvalues-1] of aint = ($55555555,aint($AAAAAAAA),aint($EFEFEFEF),0);
  837. {$endif cpu64bit}
  838. procedure trash_reference(list: TAsmList; const ref: treference; size: aint);
  839. var
  840. countreg, valuereg: tregister;
  841. hl: tasmlabel;
  842. trashintval: aint;
  843. tmpref: treference;
  844. begin
  845. trashintval := trashintvalues[localvartrashing];
  846. case size of
  847. 0: ; { empty record }
  848. 1: cg.a_load_const_ref(list,OS_8,byte(trashintval),ref);
  849. 2: cg.a_load_const_ref(list,OS_16,word(trashintval),ref);
  850. 4: cg.a_load_const_ref(list,OS_32,longint(trashintval),ref);
  851. {$ifdef cpu64bit}
  852. 8: cg.a_load_const_ref(list,OS_64,int64(trashintval),ref);
  853. {$endif cpu64bit}
  854. else
  855. begin
  856. countreg := cg.getintregister(list,OS_ADDR);
  857. valuereg := cg.getintregister(list,OS_8);
  858. cg.a_load_const_reg(list,OS_INT,size,countreg);
  859. cg.a_load_const_reg(list,OS_8,byte(trashintval),valuereg);
  860. current_asmdata.getjumplabel(hl);
  861. tmpref := ref;
  862. if (tmpref.index <> NR_NO) then
  863. internalerror(200607201);
  864. tmpref.index := countreg;
  865. dec(tmpref.offset);
  866. cg.a_label(list,hl);
  867. cg.a_load_reg_ref(list,OS_8,OS_8,valuereg,tmpref);
  868. cg.a_op_const_reg(list,OP_SUB,OS_INT,1,countreg);
  869. cg.a_cmp_const_reg_label(list,OS_INT,OC_NE,0,countreg,hl);
  870. cg.a_reg_sync(list,tmpref.base);
  871. cg.a_reg_sync(list,valuereg);
  872. end;
  873. end;
  874. end;
  875. { trash contents of local variables or parameters (function result) }
  876. procedure trash_variable(p:TObject;arg:pointer);
  877. var
  878. trashintval: aint;
  879. list: TAsmList absolute arg;
  880. begin
  881. if (tsym(p).typ=localvarsym) or
  882. ((tsym(p).typ=paravarsym) and
  883. (vo_is_funcret in tparavarsym(p).varoptions)) then
  884. begin
  885. trashintval := trashintvalues[localvartrashing];
  886. case tabstractnormalvarsym(p).initialloc.loc of
  887. LOC_CREGISTER :
  888. {$ifopt q+}
  889. {$define overflowon}
  890. {$q-}
  891. {$endif}
  892. cg.a_load_const_reg(list,reg_cgsize(tabstractnormalvarsym(p).initialloc.register),
  893. trashintval and (aint(1) shl (tcgsize2size[reg_cgsize(tabstractnormalvarsym(p).initialloc.register)] * 8) - 1),
  894. tabstractnormalvarsym(p).initialloc.register);
  895. {$ifdef overflowon}
  896. {$undef overflowon}
  897. {$q+}
  898. {$endif}
  899. LOC_REFERENCE :
  900. begin
  901. if ((tsym(p).typ=localvarsym) and
  902. not(vo_is_funcret in tabstractvarsym(p).varoptions)) or
  903. not is_shortstring(tabstractnormalvarsym(p).vardef) then
  904. trash_reference(list,tabstractnormalvarsym(p).initialloc.reference,
  905. tlocalvarsym(p).getsize)
  906. else
  907. { may be an open string, even if is_open_string() returns }
  908. { false for some helpers in the system unit }
  909. { an open string has at least size 2 }
  910. trash_reference(list,tabstractnormalvarsym(p).initialloc.reference,
  911. 2);
  912. end;
  913. LOC_CMMREGISTER :
  914. ;
  915. LOC_CFPUREGISTER :
  916. ;
  917. else
  918. internalerror(200410124);
  919. end;
  920. end;
  921. end;
  922. { initializes the regvars from staticsymtable with 0 }
  923. procedure initialize_regvars(p:TObject;arg:pointer);
  924. begin
  925. if (tsym(p).typ=globalvarsym) then
  926. begin
  927. case tglobalvarsym(p).initialloc.loc of
  928. LOC_CREGISTER :
  929. begin
  930. {$ifndef cpu64bit}
  931. if (tglobalvarsym(p).initialloc.size in [OS_64,OS_S64]) then
  932. cg64.a_load64_const_reg(TAsmList(arg),0,tglobalvarsym(p).initialloc.register64)
  933. else
  934. {$endif not cpu64bit}
  935. cg.a_load_const_reg(TAsmList(arg),reg_cgsize(tglobalvarsym(p).initialloc.register),0,
  936. tglobalvarsym(p).initialloc.register);
  937. end;
  938. LOC_REFERENCE : ;
  939. LOC_CMMREGISTER :
  940. { clear the whole register }
  941. cg.a_opmm_reg_reg(TAsmList(arg),OP_XOR,reg_cgsize(tglobalvarsym(p).initialloc.register),
  942. tglobalvarsym(p).initialloc.register,
  943. tglobalvarsym(p).initialloc.register,
  944. nil);
  945. LOC_CFPUREGISTER :
  946. ;
  947. else
  948. internalerror(200410124);
  949. end;
  950. end;
  951. end;
  952. { generates the code for initialisation of local data }
  953. procedure initialize_data(p:TObject;arg:pointer);
  954. var
  955. OldAsmList : TAsmList;
  956. hp : tnode;
  957. begin
  958. if (tsym(p).typ in [globalvarsym,localvarsym]) and
  959. (tabstractvarsym(p).refs>0) and
  960. not(vo_is_external in tabstractvarsym(p).varoptions) and
  961. not(is_class(tabstractvarsym(p).vardef)) and
  962. tabstractvarsym(p).vardef.needs_inittable then
  963. begin
  964. OldAsmList:=current_asmdata.CurrAsmList;
  965. current_asmdata.CurrAsmList:=TAsmList(arg);
  966. hp:=initialize_data_node(cloadnode.create(tsym(p),tsym(p).owner));
  967. firstpass(hp);
  968. secondpass(hp);
  969. hp.free;
  970. current_asmdata.CurrAsmList:=OldAsmList;
  971. end;
  972. end;
  973. procedure finalize_sym(asmlist:TAsmList;sym:tsym);
  974. var
  975. hp : tnode;
  976. OldAsmList : TAsmList;
  977. begin
  978. include(current_procinfo.flags,pi_needs_implicit_finally);
  979. OldAsmList:=current_asmdata.CurrAsmList;
  980. current_asmdata.CurrAsmList:=asmlist;
  981. hp:=finalize_data_node(cloadnode.create(sym,sym.owner));
  982. firstpass(hp);
  983. secondpass(hp);
  984. hp.free;
  985. current_asmdata.CurrAsmList:=OldAsmList;
  986. end;
  987. { generates the code for finalisation of local variables }
  988. procedure finalize_local_vars(p:TObject;arg:pointer);
  989. begin
  990. if (tsym(p).typ=localvarsym) and
  991. (tlocalvarsym(p).refs>0) and
  992. not(vo_is_external in tlocalvarsym(p).varoptions) and
  993. not(vo_is_funcret in tlocalvarsym(p).varoptions) and
  994. not(is_class(tlocalvarsym(p).vardef)) and
  995. tlocalvarsym(p).vardef.needs_inittable then
  996. finalize_sym(TAsmList(arg),tsym(p));
  997. end;
  998. { generates the code for finalisation of local typedconsts }
  999. procedure finalize_local_typedconst(p:TObject;arg:pointer);
  1000. var
  1001. i : longint;
  1002. pd : tprocdef;
  1003. begin
  1004. case tsym(p).typ of
  1005. typedconstsym :
  1006. begin
  1007. if ttypedconstsym(p).is_writable and
  1008. ttypedconstsym(p).typedconstdef.needs_inittable then
  1009. finalize_sym(TAsmList(arg),tsym(p));
  1010. end;
  1011. procsym :
  1012. begin
  1013. for i:=0 to tprocsym(p).ProcdefList.Count-1 do
  1014. begin
  1015. pd:=tprocdef(tprocsym(p).ProcdefList[i]);
  1016. if assigned(pd.localst) and
  1017. (pd.procsym=tprocsym(p)) and
  1018. (pd.localst.symtabletype<>staticsymtable) then
  1019. pd.localst.SymList.ForEachCall(@finalize_local_typedconst,arg);
  1020. end;
  1021. end;
  1022. end;
  1023. end;
  1024. { generates the code for finalization of static symtable and
  1025. all local (static) typedconsts }
  1026. procedure finalize_static_data(p:TObject;arg:pointer);
  1027. var
  1028. i : longint;
  1029. pd : tprocdef;
  1030. begin
  1031. case tsym(p).typ of
  1032. globalvarsym :
  1033. begin
  1034. if (tglobalvarsym(p).refs>0) and
  1035. not(vo_is_funcret in tglobalvarsym(p).varoptions) and
  1036. not(vo_is_external in tglobalvarsym(p).varoptions) and
  1037. not(is_class(tglobalvarsym(p).vardef)) and
  1038. tglobalvarsym(p).vardef.needs_inittable then
  1039. finalize_sym(TAsmList(arg),tsym(p));
  1040. end;
  1041. typedconstsym :
  1042. begin
  1043. if ttypedconstsym(p).is_writable and
  1044. ttypedconstsym(p).typedconstdef.needs_inittable then
  1045. finalize_sym(TAsmList(arg),tsym(p));
  1046. end;
  1047. procsym :
  1048. begin
  1049. for i:=0 to tprocsym(p).ProcdefList.Count-1 do
  1050. begin
  1051. pd:=tprocdef(tprocsym(p).ProcdefList[i]);
  1052. if assigned(pd.localst) and
  1053. (pd.procsym=tprocsym(p)) and
  1054. (pd.localst.symtabletype<>staticsymtable) then
  1055. pd.localst.SymList.ForEachCall(@finalize_local_typedconst,arg);
  1056. end;
  1057. end;
  1058. end;
  1059. end;
  1060. { generates the code for incrementing the reference count of parameters and
  1061. initialize out parameters }
  1062. procedure init_paras(p:TObject;arg:pointer);
  1063. var
  1064. href : treference;
  1065. tmpreg : tregister;
  1066. list : TAsmList;
  1067. needs_inittable: boolean;
  1068. begin
  1069. list:=TAsmList(arg);
  1070. if (tsym(p).typ=paravarsym) then
  1071. begin
  1072. needs_inittable :=
  1073. not is_class_or_interface(tparavarsym(p).vardef) and
  1074. tparavarsym(p).vardef.needs_inittable;
  1075. case tparavarsym(p).varspez of
  1076. vs_value :
  1077. if needs_inittable then
  1078. begin
  1079. location_get_data_ref(list,tparavarsym(p).initialloc,href,is_open_array(tparavarsym(p).vardef));
  1080. cg.g_incrrefcount(list,tparavarsym(p).vardef,href);
  1081. end;
  1082. vs_out :
  1083. begin
  1084. if (needs_inittable) or
  1085. (localvartrashing <> -1) then
  1086. begin
  1087. tmpreg:=cg.getaddressregister(list);
  1088. cg.a_load_loc_reg(list,OS_ADDR,tparavarsym(p).initialloc,tmpreg);
  1089. reference_reset_base(href,tmpreg,0);
  1090. if (localvartrashing <> -1) and
  1091. { needs separate implementation to trash open arrays }
  1092. { since their size is only known at run time }
  1093. not is_special_array(tparavarsym(p).vardef) then
  1094. trash_reference(list,href,tparavarsym(p).vardef.size);
  1095. if needs_inittable then
  1096. cg.g_initialize(list,tparavarsym(p).vardef,href);
  1097. end;
  1098. end;
  1099. else if (localvartrashing <> -1) and
  1100. ([vo_is_funcret,vo_is_hidden_para] * tparavarsym(p).varoptions = [vo_is_funcret,vo_is_hidden_para]) then
  1101. begin
  1102. tmpreg:=cg.getaddressregister(list);
  1103. cg.a_load_loc_reg(list,OS_ADDR,tparavarsym(p).initialloc,tmpreg);
  1104. reference_reset_base(href,tmpreg,0);
  1105. { may be an open string, even if is_open_string() returns }
  1106. { false for some helpers in the system unit }
  1107. if not is_shortstring(tparavarsym(p).vardef) then
  1108. trash_reference(list,href,tparavarsym(p).vardef.size)
  1109. else
  1110. { an open string has at least size 2 }
  1111. trash_reference(list,href,2);
  1112. end
  1113. end;
  1114. end;
  1115. end;
  1116. { generates the code for decrementing the reference count of parameters }
  1117. procedure final_paras(p:TObject;arg:pointer);
  1118. var
  1119. list : TAsmList;
  1120. href : treference;
  1121. begin
  1122. if not(tsym(p).typ=paravarsym) then
  1123. exit;
  1124. list:=TAsmList(arg);
  1125. if not is_class_or_interface(tparavarsym(p).vardef) and
  1126. tparavarsym(p).vardef.needs_inittable then
  1127. begin
  1128. if (tparavarsym(p).varspez=vs_value) then
  1129. begin
  1130. include(current_procinfo.flags,pi_needs_implicit_finally);
  1131. location_get_data_ref(list,tparavarsym(p).localloc,href,is_open_array(tparavarsym(p).vardef));
  1132. cg.g_decrrefcount(list,tparavarsym(p).vardef,href);
  1133. end;
  1134. end
  1135. else
  1136. if (tparavarsym(p).varspez=vs_value) and
  1137. (is_open_array(tparavarsym(p).vardef) or
  1138. is_array_of_const(tparavarsym(p).vardef)) then
  1139. begin
  1140. { cdecl functions don't have a high pointer so it is not possible to generate
  1141. a local copy }
  1142. if not(current_procinfo.procdef.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  1143. cg.g_releasevaluepara_openarray(list,tparavarsym(p).localloc);
  1144. end;
  1145. end;
  1146. { Initialize temp ansi/widestrings,interfaces }
  1147. procedure inittempvariables(list:TAsmList);
  1148. var
  1149. hp : ptemprecord;
  1150. href : treference;
  1151. begin
  1152. hp:=tg.templist;
  1153. while assigned(hp) do
  1154. begin
  1155. if assigned(hp^.def) and
  1156. hp^.def.needs_inittable then
  1157. begin
  1158. reference_reset_base(href,current_procinfo.framepointer,hp^.pos);
  1159. cg.g_initialize(list,hp^.def,href);
  1160. end;
  1161. hp:=hp^.next;
  1162. end;
  1163. end;
  1164. procedure finalizetempvariables(list:TAsmList);
  1165. var
  1166. hp : ptemprecord;
  1167. href : treference;
  1168. begin
  1169. hp:=tg.templist;
  1170. while assigned(hp) do
  1171. begin
  1172. if assigned(hp^.def) and
  1173. hp^.def.needs_inittable then
  1174. begin
  1175. include(current_procinfo.flags,pi_needs_implicit_finally);
  1176. reference_reset_base(href,current_procinfo.framepointer,hp^.pos);
  1177. cg.g_finalize(list,hp^.def,href);
  1178. end;
  1179. hp:=hp^.next;
  1180. end;
  1181. end;
  1182. procedure gen_load_return_value(list:TAsmList);
  1183. var
  1184. {$ifndef cpu64bit}
  1185. href : treference;
  1186. {$endif cpu64bit}
  1187. ressym : tabstractnormalvarsym;
  1188. resloc,
  1189. restmploc : tlocation;
  1190. hreg : tregister;
  1191. funcretloc : tlocation;
  1192. begin
  1193. { Is the loading needed? }
  1194. if (current_procinfo.procdef.funcretloc[calleeside].loc=LOC_VOID) or
  1195. (
  1196. (po_assembler in current_procinfo.procdef.procoptions) and
  1197. (not(assigned(current_procinfo.procdef.funcretsym)) or
  1198. (tabstractvarsym(current_procinfo.procdef.funcretsym).refs=0))
  1199. ) then
  1200. exit;
  1201. funcretloc:=current_procinfo.procdef.funcretloc[calleeside];
  1202. { constructors return self }
  1203. if (current_procinfo.procdef.proctypeoption=potype_constructor) then
  1204. ressym:=tabstractnormalvarsym(current_procinfo.procdef.parast.Find('self'))
  1205. else
  1206. ressym:=tabstractnormalvarsym(current_procinfo.procdef.funcretsym);
  1207. if (ressym.refs>0) then
  1208. begin
  1209. {$ifdef OLDREGVARS}
  1210. case ressym.localloc.loc of
  1211. LOC_CFPUREGISTER,
  1212. LOC_FPUREGISTER:
  1213. begin
  1214. location_reset(restmploc,LOC_CFPUREGISTER,funcretloc^.size);
  1215. restmploc.register:=ressym.localloc.register;
  1216. end;
  1217. LOC_CREGISTER,
  1218. LOC_REGISTER:
  1219. begin
  1220. location_reset(restmploc,LOC_CREGISTER,funcretloc^.size);
  1221. restmploc.register:=ressym.localloc.register;
  1222. end;
  1223. LOC_MMREGISTER:
  1224. begin
  1225. location_reset(restmploc,LOC_CMMREGISTER,funcretloc^.size);
  1226. restmploc.register:=ressym.localloc.register;
  1227. end;
  1228. LOC_REFERENCE:
  1229. begin
  1230. location_reset(restmploc,LOC_REFERENCE,funcretloc^.size);
  1231. restmploc.reference:=ressym.localloc.reference;
  1232. end;
  1233. else
  1234. internalerror(200309184);
  1235. end;
  1236. {$else}
  1237. restmploc:=ressym.localloc;
  1238. {$endif}
  1239. { Here, we return the function result. In most architectures, the value is
  1240. passed into the FUNCTION_RETURN_REG, but in a windowed architecure like sparc a
  1241. function returns in a register and the caller receives it in an other one }
  1242. case funcretloc.loc of
  1243. LOC_REGISTER:
  1244. begin
  1245. {$ifndef cpu64bit}
  1246. if current_procinfo.procdef.funcretloc[calleeside].size in [OS_64,OS_S64] then
  1247. begin
  1248. resloc:=current_procinfo.procdef.funcretloc[calleeside];
  1249. if resloc.loc<>LOC_REGISTER then
  1250. internalerror(200409141);
  1251. { Load low and high register separate to generate better register
  1252. allocation info }
  1253. if getsupreg(resloc.register64.reglo)<first_int_imreg then
  1254. begin
  1255. cg.getcpuregister(list,resloc.register64.reglo);
  1256. end;
  1257. case restmploc.loc of
  1258. LOC_REFERENCE :
  1259. begin
  1260. href:=restmploc.reference;
  1261. if target_info.endian=ENDIAN_BIG then
  1262. inc(href.offset,4);
  1263. cg.a_load_ref_reg(list,OS_32,OS_32,href,resloc.register64.reglo);
  1264. end;
  1265. LOC_CREGISTER :
  1266. cg.a_load_reg_reg(list,OS_32,OS_32,restmploc.register64.reglo,resloc.register64.reglo);
  1267. else
  1268. internalerror(200409203);
  1269. end;
  1270. if getsupreg(resloc.register64.reghi)<first_int_imreg then
  1271. begin
  1272. cg.getcpuregister(list,resloc.register64.reghi);
  1273. end;
  1274. case restmploc.loc of
  1275. LOC_REFERENCE :
  1276. begin
  1277. href:=restmploc.reference;
  1278. if target_info.endian=ENDIAN_LITTLE then
  1279. inc(href.offset,4);
  1280. cg.a_load_ref_reg(list,OS_32,OS_32,href,resloc.register64.reghi);
  1281. end;
  1282. LOC_CREGISTER :
  1283. cg.a_load_reg_reg(list,OS_32,OS_32,restmploc.register64.reghi,resloc.register64.reghi);
  1284. else
  1285. internalerror(200409204);
  1286. end;
  1287. end
  1288. else
  1289. {$endif cpu64bit}
  1290. begin
  1291. hreg:=cg.makeregsize(list,funcretloc.register,funcretloc.size);
  1292. if getsupreg(funcretloc.register)<first_int_imreg then
  1293. begin
  1294. cg.getcpuregister(list,funcretloc.register);
  1295. end;
  1296. { it could be that a structure is passed in memory but the function is expected to
  1297. return a pointer to this memory }
  1298. if paramanager.ret_in_param(current_procinfo.procdef.returndef,current_procinfo.procdef.proccalloption) then
  1299. cg.a_load_loc_reg(list,OS_ADDR,restmploc,hreg)
  1300. else
  1301. cg.a_load_loc_reg(list,restmploc.size,restmploc,hreg);
  1302. end;
  1303. end;
  1304. LOC_FPUREGISTER:
  1305. begin
  1306. if getsupreg(funcretloc.register)<first_fpu_imreg then
  1307. begin
  1308. cg.getcpuregister(list,funcretloc.register);
  1309. end;
  1310. { we can't do direct moves between fpu and mm registers }
  1311. if restmploc.loc in [LOC_MMREGISTER,LOC_CMMREGISTER] then
  1312. location_force_fpureg(list,restmploc,false);
  1313. cg.a_loadfpu_loc_reg(list,restmploc,funcretloc.register);
  1314. end;
  1315. LOC_MMREGISTER:
  1316. begin
  1317. if getsupreg(funcretloc.register)<first_mm_imreg then
  1318. begin
  1319. cg.getcpuregister(list,funcretloc.register);
  1320. end;
  1321. cg.a_loadmm_loc_reg(list,restmploc.size,restmploc,funcretloc.register,mms_movescalar);
  1322. end;
  1323. LOC_INVALID,
  1324. LOC_REFERENCE:
  1325. ;
  1326. else
  1327. internalerror(200405025);
  1328. end;
  1329. end
  1330. {$ifdef x86}
  1331. else
  1332. begin
  1333. { the caller will pop a value off the cpu stack }
  1334. if (funcretloc.loc = LOC_FPUREGISTER) then
  1335. list.concat(taicpu.op_none(A_FLDZ));
  1336. end;
  1337. {$endif x86}
  1338. end;
  1339. procedure gen_alloc_regvar(list:TAsmList;sym: tabstractnormalvarsym);
  1340. begin
  1341. case sym.initialloc.loc of
  1342. LOC_CREGISTER:
  1343. begin
  1344. {$ifndef cpu64bit}
  1345. if sym.initialloc.size in [OS_64,OS_S64] then
  1346. begin
  1347. sym.initialloc.register64.reglo:=cg.getintregister(list,OS_32);
  1348. sym.initialloc.register64.reghi:=cg.getintregister(list,OS_32);
  1349. end
  1350. else
  1351. {$endif cpu64bit}
  1352. sym.initialloc.register:=cg.getintregister(list,sym.initialloc.size);
  1353. end;
  1354. LOC_CFPUREGISTER:
  1355. begin
  1356. sym.initialloc.register:=cg.getfpuregister(list,sym.initialloc.size);
  1357. end;
  1358. LOC_CMMREGISTER:
  1359. begin
  1360. sym.initialloc.register:=cg.getmmregister(list,sym.localloc.size);
  1361. end;
  1362. end;
  1363. if (pi_has_goto in current_procinfo.flags) then
  1364. begin
  1365. { Allocate register already, to prevent first allocation to be
  1366. inside a loop }
  1367. {$ifndef cpu64bit}
  1368. if sym.initialloc.size in [OS_64,OS_S64] then
  1369. begin
  1370. cg.a_reg_sync(list,sym.initialloc.register64.reglo);
  1371. cg.a_reg_sync(list,sym.initialloc.register64.reghi);
  1372. end
  1373. else
  1374. {$endif cpu64bit}
  1375. cg.a_reg_sync(list,sym.initialloc.register);
  1376. end;
  1377. sym.localloc:=sym.initialloc;
  1378. end;
  1379. procedure gen_load_para_value(list:TAsmList);
  1380. procedure get_para(const paraloc:TCGParaLocation);
  1381. begin
  1382. case paraloc.loc of
  1383. LOC_REGISTER :
  1384. begin
  1385. if getsupreg(paraloc.register)<first_int_imreg then
  1386. cg.getcpuregister(list,paraloc.register);
  1387. end;
  1388. LOC_MMREGISTER :
  1389. begin
  1390. if getsupreg(paraloc.register)<first_mm_imreg then
  1391. cg.getcpuregister(list,paraloc.register);
  1392. end;
  1393. LOC_FPUREGISTER :
  1394. begin
  1395. if getsupreg(paraloc.register)<first_fpu_imreg then
  1396. cg.getcpuregister(list,paraloc.register);
  1397. end;
  1398. end;
  1399. end;
  1400. procedure unget_para(const paraloc:TCGParaLocation);
  1401. begin
  1402. case paraloc.loc of
  1403. LOC_REGISTER :
  1404. begin
  1405. if getsupreg(paraloc.register)<first_int_imreg then
  1406. cg.ungetcpuregister(list,paraloc.register);
  1407. end;
  1408. LOC_MMREGISTER :
  1409. begin
  1410. if getsupreg(paraloc.register)<first_mm_imreg then
  1411. cg.ungetcpuregister(list,paraloc.register);
  1412. end;
  1413. LOC_FPUREGISTER :
  1414. begin
  1415. if getsupreg(paraloc.register)<first_fpu_imreg then
  1416. cg.ungetcpuregister(list,paraloc.register);
  1417. end;
  1418. end;
  1419. end;
  1420. procedure gen_load_ref(const paraloc:TCGParaLocation;const ref:treference;sizeleft:aint);
  1421. var
  1422. href : treference;
  1423. begin
  1424. case paraloc.loc of
  1425. LOC_REGISTER :
  1426. begin
  1427. {$IFDEF POWERPC64}
  1428. if (paraloc.shiftval <> 0) then
  1429. cg.a_op_const_reg_reg(list, OP_SHL, OS_INT, paraloc.shiftval, paraloc.register, paraloc.register);
  1430. {$ENDIF POWERPC64}
  1431. cg.a_load_reg_ref(list,paraloc.size,paraloc.size,paraloc.register,ref);
  1432. end;
  1433. LOC_MMREGISTER :
  1434. cg.a_loadmm_reg_ref(list,paraloc.size,paraloc.size,paraloc.register,ref,mms_movescalar);
  1435. LOC_FPUREGISTER :
  1436. cg.a_loadfpu_reg_ref(list,paraloc.size,paraloc.register,ref);
  1437. LOC_REFERENCE :
  1438. begin
  1439. reference_reset_base(href,paraloc.reference.index,paraloc.reference.offset);
  1440. { use concatcopy, because it can also be a float which fails when
  1441. load_ref_ref is used. Don't copy data when the references are equal }
  1442. if not((href.base=ref.base) and (href.offset=ref.offset)) then
  1443. cg.g_concatcopy(list,href,ref,sizeleft);
  1444. end;
  1445. else
  1446. internalerror(2002081302);
  1447. end;
  1448. end;
  1449. procedure gen_load_reg(const paraloc:TCGParaLocation;reg:tregister);
  1450. var
  1451. href : treference;
  1452. begin
  1453. case paraloc.loc of
  1454. LOC_REGISTER :
  1455. cg.a_load_reg_reg(list,paraloc.size,paraloc.size,paraloc.register,reg);
  1456. LOC_MMREGISTER :
  1457. cg.a_loadmm_reg_reg(list,paraloc.size,paraloc.size,paraloc.register,reg,mms_movescalar);
  1458. LOC_FPUREGISTER :
  1459. cg.a_loadfpu_reg_reg(list,paraloc.size,paraloc.register,reg);
  1460. LOC_REFERENCE :
  1461. begin
  1462. reference_reset_base(href,paraloc.reference.index,paraloc.reference.offset);
  1463. case getregtype(reg) of
  1464. R_INTREGISTER :
  1465. cg.a_load_ref_reg(list,paraloc.size,paraloc.size,href,reg);
  1466. R_FPUREGISTER :
  1467. cg.a_loadfpu_ref_reg(list,paraloc.size,href,reg);
  1468. R_MMREGISTER :
  1469. cg.a_loadmm_ref_reg(list,paraloc.size,paraloc.size,href,reg,mms_movescalar);
  1470. else
  1471. internalerror(2004101012);
  1472. end;
  1473. end;
  1474. else
  1475. internalerror(2002081302);
  1476. end;
  1477. end;
  1478. var
  1479. i : longint;
  1480. currpara : tparavarsym;
  1481. paraloc : pcgparalocation;
  1482. href : treference;
  1483. sizeleft : aint;
  1484. {$if defined(sparc) or defined(arm)}
  1485. tempref : treference;
  1486. {$endif sparc}
  1487. begin
  1488. if (po_assembler in current_procinfo.procdef.procoptions) then
  1489. exit;
  1490. { Allocate registers used by parameters }
  1491. for i:=0 to current_procinfo.procdef.paras.count-1 do
  1492. begin
  1493. currpara:=tparavarsym(current_procinfo.procdef.paras[i]);
  1494. paraloc:=currpara.paraloc[calleeside].location;
  1495. while assigned(paraloc) do
  1496. begin
  1497. if paraloc^.loc in [LOC_REGISTER,LOC_FPUREGISTER,LOC_MMREGISTER] then
  1498. get_para(paraloc^);
  1499. paraloc:=paraloc^.next;
  1500. end;
  1501. end;
  1502. { Copy parameters to local references/registers }
  1503. for i:=0 to current_procinfo.procdef.paras.count-1 do
  1504. begin
  1505. currpara:=tparavarsym(current_procinfo.procdef.paras[i]);
  1506. paraloc:=currpara.paraloc[calleeside].location;
  1507. { skip e.g. empty records }
  1508. if not assigned(paraloc) then
  1509. internalerror(200408203);
  1510. if (paraloc^.loc = LOC_VOID) then
  1511. continue;
  1512. case currpara.initialloc.loc of
  1513. LOC_REFERENCE :
  1514. begin
  1515. { If the parameter location is reused we don't need to copy
  1516. anything }
  1517. if not paramanager.param_use_paraloc(currpara.paraloc[calleeside]) then
  1518. begin
  1519. href:=currpara.initialloc.reference;
  1520. sizeleft:=currpara.paraloc[calleeside].intsize;
  1521. while assigned(paraloc) do
  1522. begin
  1523. unget_para(paraloc^);
  1524. if (paraloc^.size=OS_NO) then
  1525. begin
  1526. { Can only be a reference that contains the rest
  1527. of the parameter }
  1528. if (paraloc^.loc<>LOC_REFERENCE) or
  1529. assigned(paraloc^.next) then
  1530. internalerror(2005013010);
  1531. gen_load_ref(paraloc^,href,sizeleft);
  1532. inc(href.offset,sizeleft);
  1533. sizeleft:=0;
  1534. end
  1535. else
  1536. begin
  1537. gen_load_ref(paraloc^,href,tcgsize2size[paraloc^.size]);
  1538. inc(href.offset,TCGSize2Size[paraloc^.size]);
  1539. dec(sizeleft,TCGSize2Size[paraloc^.size]);
  1540. end;
  1541. paraloc:=paraloc^.next;
  1542. end;
  1543. end;
  1544. end;
  1545. LOC_CREGISTER :
  1546. begin
  1547. {$ifndef cpu64bit}
  1548. if (currpara.paraloc[calleeside].size in [OS_64,OS_S64]) and
  1549. is_64bit(currpara.vardef) then
  1550. begin
  1551. case paraloc^.loc of
  1552. LOC_REGISTER:
  1553. begin
  1554. if not assigned(paraloc^.next) then
  1555. internalerror(200410104);
  1556. if (target_info.endian=ENDIAN_BIG) then
  1557. begin
  1558. { paraloc^ -> high
  1559. paraloc^.next -> low }
  1560. unget_para(paraloc^);
  1561. gen_alloc_regvar(list,currpara);
  1562. gen_load_reg(paraloc^,currpara.initialloc.register64.reghi);
  1563. unget_para(paraloc^.next^);
  1564. gen_load_reg(paraloc^.next^,currpara.initialloc.register64.reglo);
  1565. end
  1566. else
  1567. begin
  1568. { paraloc^ -> low
  1569. paraloc^.next -> high }
  1570. unget_para(paraloc^);
  1571. gen_alloc_regvar(list,currpara);
  1572. gen_load_reg(paraloc^,currpara.initialloc.register64.reglo);
  1573. unget_para(paraloc^.next^);
  1574. gen_load_reg(paraloc^.next^,currpara.initialloc.register64.reghi);
  1575. end;
  1576. end;
  1577. LOC_REFERENCE:
  1578. begin
  1579. gen_alloc_regvar(list,currpara);
  1580. reference_reset_base(href,paraloc^.reference.index,paraloc^.reference.offset);
  1581. cg64.a_load64_ref_reg(list,href,currpara.initialloc.register64);
  1582. unget_para(paraloc^);
  1583. end;
  1584. else
  1585. internalerror(2005101501);
  1586. end
  1587. end
  1588. else
  1589. {$endif cpu64bit}
  1590. begin
  1591. if assigned(paraloc^.next) then
  1592. internalerror(200410105);
  1593. unget_para(paraloc^);
  1594. gen_alloc_regvar(list,currpara);
  1595. gen_load_reg(paraloc^,currpara.initialloc.register);
  1596. end;
  1597. end;
  1598. LOC_CFPUREGISTER :
  1599. begin
  1600. {$if defined(sparc) or defined(arm)}
  1601. { Arm and Sparc passes floats in int registers, when loading to fpu register
  1602. we need a temp }
  1603. sizeleft := TCGSize2Size[currpara.initialloc.size];
  1604. tg.GetTemp(list,sizeleft,tt_normal,tempref);
  1605. href:=tempref;
  1606. while assigned(paraloc) do
  1607. begin
  1608. unget_para(paraloc^);
  1609. gen_load_ref(paraloc^,href,sizeleft);
  1610. inc(href.offset,TCGSize2Size[paraloc^.size]);
  1611. dec(sizeleft,TCGSize2Size[paraloc^.size]);
  1612. paraloc:=paraloc^.next;
  1613. end;
  1614. gen_alloc_regvar(list,currpara);
  1615. cg.a_loadfpu_ref_reg(list,currpara.initialloc.size,tempref,currpara.initialloc.register);
  1616. tg.UnGetTemp(list,tempref);
  1617. {$else sparc}
  1618. unget_para(paraloc^);
  1619. gen_alloc_regvar(list,currpara);
  1620. gen_load_reg(paraloc^,currpara.initialloc.register);
  1621. if assigned(paraloc^.next) then
  1622. internalerror(200410109);
  1623. {$endif sparc}
  1624. end;
  1625. LOC_CMMREGISTER :
  1626. begin
  1627. unget_para(paraloc^);
  1628. gen_alloc_regvar(list,currpara);
  1629. gen_load_reg(paraloc^,currpara.initialloc.register);
  1630. { data could come in two memory locations, for now
  1631. we simply ignore the sanity check (FK)
  1632. if assigned(paraloc^.next) then
  1633. internalerror(200410108);
  1634. }
  1635. end;
  1636. end;
  1637. end;
  1638. { generate copies of call by value parameters, must be done before
  1639. the initialization and body is parsed because the refcounts are
  1640. incremented using the local copies }
  1641. current_procinfo.procdef.parast.SymList.ForEachCall(@copyvalueparas,list);
  1642. {$ifdef powerpc}
  1643. { unget the register that contains the stack pointer before the procedure entry, }
  1644. { which is used to access the parameters in their original callee-side location }
  1645. if (tppcprocinfo(current_procinfo).needs_frame_pointer) then
  1646. cg.a_reg_dealloc(list,NR_R12);
  1647. {$endif powerpc}
  1648. {$ifdef powerpc64}
  1649. { unget the register that contains the stack pointer before the procedure entry, }
  1650. { which is used to access the parameters in their original callee-side location }
  1651. if (tppcprocinfo(current_procinfo).needs_frame_pointer) then
  1652. cg.a_reg_dealloc(list, NR_OLD_STACK_POINTER_REG);
  1653. {$endif powerpc64}
  1654. end;
  1655. procedure gen_initialize_code(list:TAsmList);
  1656. begin
  1657. { initialize local data like ansistrings }
  1658. case current_procinfo.procdef.proctypeoption of
  1659. potype_unitinit:
  1660. begin
  1661. { this is also used for initialization of variables in a
  1662. program which does not have a globalsymtable }
  1663. if assigned(current_module.globalsymtable) then
  1664. TSymtable(current_module.globalsymtable).SymList.ForEachCall(@initialize_data,list);
  1665. TSymtable(current_module.localsymtable).SymList.ForEachCall(@initialize_data,list);
  1666. TSymtable(current_module.localsymtable).SymList.ForEachCall(@initialize_regvars,list);
  1667. end;
  1668. { units have seperate code for initilization and finalization }
  1669. potype_unitfinalize: ;
  1670. { program init/final is generated in separate procedure }
  1671. potype_proginit:
  1672. begin
  1673. TSymtable(current_module.localsymtable).SymList.ForEachCall(@initialize_regvars,list);
  1674. end;
  1675. else
  1676. begin
  1677. if (localvartrashing <> -1) and
  1678. not(po_assembler in current_procinfo.procdef.procoptions) then
  1679. current_procinfo.procdef.localst.SymList.ForEachCall(@trash_variable,list);
  1680. current_procinfo.procdef.localst.SymList.ForEachCall(@initialize_data,list);
  1681. end;
  1682. end;
  1683. { initialisizes temp. ansi/wide string data }
  1684. inittempvariables(list);
  1685. { initialize ansi/widesstring para's }
  1686. if not(po_assembler in current_procinfo.procdef.procoptions) then
  1687. current_procinfo.procdef.parast.SymList.ForEachCall(@init_paras,list);
  1688. {$ifdef OLDREGVARS}
  1689. load_regvars(list,nil);
  1690. {$endif OLDREGVARS}
  1691. end;
  1692. procedure gen_finalize_code(list:TAsmList);
  1693. begin
  1694. {$ifdef OLDREGVARS}
  1695. cleanup_regvars(list);
  1696. {$endif OLDREGVARS}
  1697. { finalize temporary data }
  1698. finalizetempvariables(list);
  1699. { finalize local data like ansistrings}
  1700. case current_procinfo.procdef.proctypeoption of
  1701. potype_unitfinalize:
  1702. begin
  1703. { this is also used for initialization of variables in a
  1704. program which does not have a globalsymtable }
  1705. if assigned(current_module.globalsymtable) then
  1706. TSymtable(current_module.globalsymtable).SymList.ForEachCall(@finalize_static_data,list);
  1707. TSymtable(current_module.localsymtable).SymList.ForEachCall(@finalize_static_data,list);
  1708. end;
  1709. { units/progs have separate code for initialization and finalization }
  1710. potype_unitinit: ;
  1711. { program init/final is generated in separate procedure }
  1712. potype_proginit: ;
  1713. else
  1714. current_procinfo.procdef.localst.SymList.ForEachCall(@finalize_local_vars,list);
  1715. end;
  1716. { finalize paras data }
  1717. if assigned(current_procinfo.procdef.parast) and
  1718. not(po_assembler in current_procinfo.procdef.procoptions) then
  1719. current_procinfo.procdef.parast.SymList.ForEachCall(@final_paras,list);
  1720. end;
  1721. procedure gen_entry_code(list:TAsmList);
  1722. var
  1723. paraloc1,
  1724. paraloc2 : tcgpara;
  1725. begin
  1726. paraloc1.init;
  1727. paraloc2.init;
  1728. { the actual profile code can clobber some registers,
  1729. therefore if the context must be saved, do it before
  1730. the actual call to the profile code
  1731. }
  1732. if (cs_profile in current_settings.moduleswitches) and
  1733. not(po_assembler in current_procinfo.procdef.procoptions) then
  1734. begin
  1735. { non-win32 can call mcout even in main }
  1736. if not (target_info.system in [system_i386_win32,system_i386_wdosx]) or
  1737. not (current_procinfo.procdef.proctypeoption=potype_proginit) then
  1738. begin
  1739. cg.g_profilecode(list);
  1740. end;
  1741. end;
  1742. { call startup helpers from main program }
  1743. if (current_procinfo.procdef.proctypeoption=potype_proginit) then
  1744. begin
  1745. { initialize units }
  1746. cg.allocallcpuregisters(list);
  1747. cg.a_call_name(list,'FPC_INITIALIZEUNITS');
  1748. cg.deallocallcpuregisters(list);
  1749. end;
  1750. list.concat(Tai_force_line.Create);
  1751. {$ifdef OLDREGVARS}
  1752. load_regvars(list,nil);
  1753. {$endif OLDREGVARS}
  1754. paraloc1.done;
  1755. paraloc2.done;
  1756. end;
  1757. procedure gen_exit_code(list:TAsmList);
  1758. begin
  1759. { call __EXIT for main program }
  1760. if (not DLLsource) and
  1761. (current_procinfo.procdef.proctypeoption=potype_proginit) then
  1762. cg.a_call_name(list,'FPC_DO_EXIT');
  1763. end;
  1764. {****************************************************************************
  1765. Entry/Exit
  1766. ****************************************************************************}
  1767. procedure alloc_proc_symbol(pd: tprocdef);
  1768. var
  1769. item: tstringlistitem;
  1770. begin
  1771. item := tstringlistitem(pd.aliasnames.first);
  1772. while assigned(item) do
  1773. begin
  1774. current_asmdata.DefineAsmSymbol(item.str,AB_GLOBAL,AT_FUNCTION);
  1775. item := tstringlistitem(item.next);
  1776. end;
  1777. end;
  1778. procedure gen_proc_symbol(list:TAsmList);
  1779. var
  1780. hs : string;
  1781. begin
  1782. repeat
  1783. hs:=current_procinfo.procdef.aliasnames.getfirst;
  1784. if hs='' then
  1785. break;
  1786. if (cs_profile in current_settings.moduleswitches) or
  1787. (po_global in current_procinfo.procdef.procoptions) then
  1788. list.concat(Tai_symbol.createname_global(hs,AT_FUNCTION,0))
  1789. else
  1790. list.concat(Tai_symbol.createname(hs,AT_FUNCTION,0));
  1791. if tf_use_function_relative_addresses in target_info.flags then
  1792. list.concat(Tai_function_name.create(hs));
  1793. until false;
  1794. current_procinfo.procdef.procstarttai:=tai(list.last);
  1795. end;
  1796. procedure gen_proc_symbol_end(list:TAsmList);
  1797. begin
  1798. list.concat(Tai_symbol_end.Createname(current_procinfo.procdef.mangledname));
  1799. current_procinfo.procdef.procendtai:=tai(list.last);
  1800. { finalisation marker for Mac OS X }
  1801. if (target_info.system in [system_powerpc_darwin,system_i386_darwin]) and
  1802. (current_module.islibrary) and
  1803. (((current_module.flags and uf_finalize)<>0) or
  1804. (current_procinfo.procdef.proctypeoption = potype_proginit)) then
  1805. begin
  1806. if (current_procinfo.procdef.proctypeoption = potype_proginit) then
  1807. list.concat(tai_directive.create(asd_mod_init_func,''))
  1808. else
  1809. list.concat(tai_directive.create(asd_mod_term_func,''));
  1810. list.concat(tai_align.create(4));
  1811. list.concat(Tai_const.Createname(current_procinfo.procdef.mangledname,0));
  1812. end;
  1813. if (current_procinfo.procdef.proctypeoption=potype_proginit) then
  1814. begin
  1815. if (target_info.system in [system_powerpc_darwin,system_i386_darwin,system_powerpc_macos]) and
  1816. not(current_module.islibrary) then
  1817. begin
  1818. list.concat(tai_section.create(sec_code,'',4));
  1819. list.concat(tai_symbol.createname_global(
  1820. target_info.cprefix+mainaliasname,AT_FUNCTION,0));
  1821. { keep argc, argv and envp properly on the stack }
  1822. cg.a_jmp_name(list,target_info.cprefix+'FPC_SYSTEMMAIN');
  1823. end;
  1824. end;
  1825. end;
  1826. procedure gen_proc_entry_code(list:TAsmList);
  1827. var
  1828. hitemp,
  1829. lotemp : longint;
  1830. begin
  1831. { generate call frame marker for dwarf call frame info }
  1832. current_asmdata.asmcfi.start_frame(list);
  1833. { All temps are know, write offsets used for information }
  1834. if (cs_asm_source in current_settings.globalswitches) then
  1835. begin
  1836. if tg.direction>0 then
  1837. begin
  1838. lotemp:=current_procinfo.tempstart;
  1839. hitemp:=tg.lasttemp;
  1840. end
  1841. else
  1842. begin
  1843. lotemp:=tg.lasttemp;
  1844. hitemp:=current_procinfo.tempstart;
  1845. end;
  1846. list.concat(Tai_comment.Create(strpnew('Temps allocated between '+std_regname(current_procinfo.framepointer)+
  1847. tostr_with_plus(lotemp)+' and '+std_regname(current_procinfo.framepointer)+tostr_with_plus(hitemp))));
  1848. end;
  1849. { generate target specific proc entry code }
  1850. cg.g_proc_entry(list,current_procinfo.calc_stackframe_size,(po_nostackframe in current_procinfo.procdef.procoptions));
  1851. end;
  1852. procedure gen_proc_exit_code(list:TAsmList);
  1853. var
  1854. parasize : longint;
  1855. begin
  1856. { c style clearstack does not need to remove parameters from the stack, only the
  1857. return value when it was pushed by arguments }
  1858. if current_procinfo.procdef.proccalloption in clearstack_pocalls then
  1859. begin
  1860. parasize:=0;
  1861. if paramanager.ret_in_param(current_procinfo.procdef.returndef,current_procinfo.procdef.proccalloption) then
  1862. inc(parasize,sizeof(aint));
  1863. end
  1864. else
  1865. parasize:=current_procinfo.para_stack_size;
  1866. { generate target specific proc exit code }
  1867. cg.g_proc_exit(list,parasize,(po_nostackframe in current_procinfo.procdef.procoptions));
  1868. { release return registers, needed for optimizer }
  1869. if not is_void(current_procinfo.procdef.returndef) then
  1870. location_free(list,current_procinfo.procdef.funcretloc[calleeside]);
  1871. { end of frame marker for call frame info }
  1872. current_asmdata.asmcfi.end_frame(list);
  1873. end;
  1874. procedure gen_stack_check_size_para(list:TAsmList);
  1875. var
  1876. paraloc1 : tcgpara;
  1877. begin
  1878. paraloc1.init;
  1879. paramanager.getintparaloc(pocall_default,1,paraloc1);
  1880. paramanager.allocparaloc(list,paraloc1);
  1881. cg.a_param_const(list,OS_INT,current_procinfo.calc_stackframe_size,paraloc1);
  1882. paramanager.freeparaloc(list,paraloc1);
  1883. paraloc1.done;
  1884. end;
  1885. procedure gen_stack_check_call(list:TAsmList);
  1886. var
  1887. paraloc1 : tcgpara;
  1888. begin
  1889. paraloc1.init;
  1890. { Also alloc the register needed for the parameter }
  1891. paramanager.getintparaloc(pocall_default,1,paraloc1);
  1892. paramanager.allocparaloc(list,paraloc1);
  1893. paramanager.freeparaloc(list,paraloc1);
  1894. { Call the helper }
  1895. cg.allocallcpuregisters(list);
  1896. cg.a_call_name(list,'FPC_STACKCHECK');
  1897. cg.deallocallcpuregisters(list);
  1898. paraloc1.done;
  1899. end;
  1900. procedure gen_save_used_regs(list:TAsmList);
  1901. begin
  1902. { Pure assembler routines need to save the registers themselves }
  1903. if (po_assembler in current_procinfo.procdef.procoptions) then
  1904. exit;
  1905. { oldfpccall expects all registers to be destroyed }
  1906. if current_procinfo.procdef.proccalloption<>pocall_oldfpccall then
  1907. cg.g_save_standard_registers(list);
  1908. end;
  1909. procedure gen_restore_used_regs(list:TAsmList);
  1910. begin
  1911. { Pure assembler routines need to save the registers themselves }
  1912. if (po_assembler in current_procinfo.procdef.procoptions) then
  1913. exit;
  1914. { oldfpccall expects all registers to be destroyed }
  1915. if current_procinfo.procdef.proccalloption<>pocall_oldfpccall then
  1916. cg.g_restore_standard_registers(list);
  1917. end;
  1918. procedure gen_got_load(list : TAsmList);
  1919. begin
  1920. { if loading got is necessary for more cpus, it can be moved
  1921. to the cg }
  1922. {$ifdef i386}
  1923. { allocate PIC register }
  1924. if (cs_create_pic in current_settings.moduleswitches) and
  1925. (tf_pic_uses_got in target_info.flags) and
  1926. (pi_needs_got in current_procinfo.flags) and
  1927. not(po_kylixlocal in current_procinfo.procdef.procoptions) then
  1928. begin
  1929. current_module.requires_ebx_pic_helper:=true;
  1930. cg.a_call_name_static(list,'fpc_geteipasebx');
  1931. list.concat(taicpu.op_sym_ofs_reg(A_ADD,S_L,current_asmdata.RefAsmSymbol('_GLOBAL_OFFSET_TABLE_'),0,NR_PIC_OFFSET_REG));
  1932. list.concat(tai_regalloc.alloc(NR_PIC_OFFSET_REG,nil));
  1933. { ecx could be used in leave procedures }
  1934. current_procinfo.got:=NR_EBX;
  1935. end;
  1936. {$endif i386}
  1937. end;
  1938. {****************************************************************************
  1939. External handling
  1940. ****************************************************************************}
  1941. procedure gen_external_stub(list:TAsmList;pd:tprocdef;const externalname:string);
  1942. var
  1943. ref : treference;
  1944. sym : tasmsymbol;
  1945. begin
  1946. { add the procedure to the al_procedures }
  1947. maybe_new_object_file(list);
  1948. new_section(list,sec_code,lower(pd.mangledname),current_settings.alignment.procalign);
  1949. list.concat(Tai_align.create(current_settings.alignment.procalign));
  1950. if (po_global in pd.procoptions) then
  1951. list.concat(Tai_symbol.createname_global(pd.mangledname,AT_FUNCTION,0))
  1952. else
  1953. list.concat(Tai_symbol.createname(pd.mangledname,AT_FUNCTION,0));
  1954. {$ifdef x86}
  1955. { fix this for other CPUs as well }
  1956. sym:=current_asmdata.RefAsmSymbol(externalname);
  1957. reference_reset_symbol(ref,sym,0);
  1958. { create pic'ed? }
  1959. if cs_create_pic in current_settings.moduleswitches then
  1960. begin
  1961. { it could be that we're called from a procedure not having the
  1962. got loaded
  1963. }
  1964. gen_got_load(list);
  1965. ref.refaddr:=addr_pic;
  1966. end
  1967. else
  1968. ref.refaddr:=addr_full;
  1969. list.concat(taicpu.op_ref(A_JMP,S_NO,ref));
  1970. {$else x86}
  1971. cg.a_jmp_name(list,externalname);
  1972. {$endif x86}
  1973. end;
  1974. {****************************************************************************
  1975. Const Data
  1976. ****************************************************************************}
  1977. procedure insertbssdata(sym : tglobalvarsym);
  1978. var
  1979. l : aint;
  1980. varalign : shortint;
  1981. storefilepos : tfileposinfo;
  1982. list : TAsmList;
  1983. sectype : TAsmSectiontype;
  1984. begin
  1985. storefilepos:=current_filepos;
  1986. current_filepos:=sym.fileinfo;
  1987. l:=sym.getsize;
  1988. if tf_section_threadvars in target_info.flags then
  1989. begin
  1990. if (vo_is_thread_var in sym.varoptions) then
  1991. begin
  1992. list:=current_asmdata.asmlists[al_threadvars];
  1993. sectype:=sec_threadvar;
  1994. end
  1995. else
  1996. begin
  1997. list:=current_asmdata.asmlists[al_globals];
  1998. sectype:=sec_bss;
  1999. end;
  2000. end
  2001. else
  2002. begin
  2003. if (vo_is_thread_var in sym.varoptions) then
  2004. inc(l,sizeof(aint));
  2005. list:=current_asmdata.asmlists[al_globals];
  2006. sectype:=sec_bss;
  2007. end;
  2008. varalign:=var_align(size_2_align(l));
  2009. maybe_new_object_file(list);
  2010. new_section(list,sectype,lower(sym.mangledname),varalign);
  2011. if (sym.owner.symtabletype=globalsymtable) or
  2012. maybe_smartlink_symbol or
  2013. DLLSource or
  2014. (assigned(current_procinfo) and
  2015. (po_inline in current_procinfo.procdef.procoptions)) or
  2016. (vo_is_exported in sym.varoptions) or
  2017. (vo_is_C_var in sym.varoptions) then
  2018. list.concat(Tai_datablock.create_global(sym.mangledname,l))
  2019. else
  2020. list.concat(Tai_datablock.create(sym.mangledname,l));
  2021. current_filepos:=storefilepos;
  2022. end;
  2023. procedure init_regvar_loc(sym:tabstractnormalvarsym;cgsize:tcgsize);
  2024. begin
  2025. with sym do
  2026. begin
  2027. initialloc.size:=cgsize;
  2028. localloc.size:=initialloc.size;
  2029. case varregable of
  2030. vr_intreg,
  2031. vr_addr :
  2032. begin
  2033. initialloc.loc:=LOC_CREGISTER;
  2034. end;
  2035. vr_fpureg :
  2036. begin
  2037. initialloc.loc:=LOC_CFPUREGISTER;
  2038. end;
  2039. vr_mmreg :
  2040. begin
  2041. initialloc.loc:=LOC_CMMREGISTER;
  2042. end;
  2043. else
  2044. internalerror(2004101010);
  2045. end;
  2046. localloc.loc:=initialloc.loc;
  2047. end;
  2048. end;
  2049. procedure gen_alloc_symtable(list:TAsmList;st:TSymtable);
  2050. var
  2051. i : longint;
  2052. sym : tsym;
  2053. isaddr : boolean;
  2054. cgsize : tcgsize;
  2055. begin
  2056. for i:=0 to st.SymList.Count-1 do
  2057. begin
  2058. sym:=tsym(st.SymList[i]);
  2059. if (sym.typ in [globalvarsym,localvarsym,paravarsym]) then
  2060. begin
  2061. with tabstractnormalvarsym(sym) do
  2062. begin
  2063. { Parameters passed to assembler procedures need to be kept
  2064. in the original location }
  2065. if (sym.typ=paravarsym) and
  2066. (po_assembler in current_procinfo.procdef.procoptions) then
  2067. begin
  2068. tparavarsym(sym).paraloc[calleeside].get_location(initialloc);
  2069. localloc:=initialloc;
  2070. end
  2071. else
  2072. begin
  2073. isaddr:=(st.symtabletype=parasymtable) and
  2074. paramanager.push_addr_param(varspez,vardef,current_procinfo.procdef.proccalloption);
  2075. if isaddr then
  2076. cgsize:=OS_ADDR
  2077. else
  2078. cgsize:=def_cgsize(vardef);
  2079. {$ifndef OLDREGVARS}
  2080. { When there is assembler code we can't use regvars }
  2081. if is_regvar(isaddr) then
  2082. begin
  2083. init_regvar_loc(tabstractnormalvarsym(sym),cgsize);
  2084. if (st.symtabletype <> parasymtable) then
  2085. gen_alloc_regvar(list,tabstractnormalvarsym(sym));
  2086. end
  2087. else
  2088. {$endif NOT OLDREGVARS}
  2089. begin
  2090. initialloc.loc:=LOC_REFERENCE;
  2091. initialloc.size:=cgsize;
  2092. case st.symtabletype of
  2093. parasymtable :
  2094. begin
  2095. { Reuse the parameter location for values to are at a single location on the stack }
  2096. if paramanager.param_use_paraloc(tparavarsym(sym).paraloc[calleeside]) then
  2097. begin
  2098. reference_reset_base(initialloc.reference,tparavarsym(sym).paraloc[calleeside].location^.reference.index,
  2099. tparavarsym(sym).paraloc[calleeside].location^.reference.offset);
  2100. end
  2101. else
  2102. begin
  2103. if isaddr then
  2104. tg.GetLocal(list,sizeof(aint),voidpointertype,initialloc.reference)
  2105. else
  2106. tg.GetLocal(list,getsize,tparavarsym(sym).paraloc[calleeside].alignment,vardef,initialloc.reference);
  2107. end;
  2108. end;
  2109. localsymtable,
  2110. stt_excepTSymtable :
  2111. begin
  2112. tg.GetLocal(list,getsize,vardef,initialloc.reference);
  2113. end;
  2114. staticsymtable :
  2115. begin
  2116. { PIC, DLL and Threadvar need extra code and are handled in ncgld }
  2117. if not(vo_is_dll_var in varoptions) and ((tf_section_threadvars in target_info.flags) or
  2118. not(vo_is_thread_var in varoptions)) then
  2119. reference_reset_symbol(initialloc.reference,current_asmdata.RefAsmSymbol(mangledname),0);
  2120. end;
  2121. else
  2122. internalerror(200410103);
  2123. end;
  2124. end;
  2125. end;
  2126. if cs_asm_source in current_settings.globalswitches then
  2127. begin
  2128. case initialloc.loc of
  2129. LOC_REFERENCE :
  2130. begin
  2131. if not assigned(initialloc.reference.symbol) then
  2132. list.concat(Tai_comment.Create(strpnew('Var '+realname+' located at '+
  2133. std_regname(initialloc.reference.base)+tostr_with_plus(initialloc.reference.offset))));
  2134. end;
  2135. end;
  2136. end;
  2137. localloc:=initialloc;
  2138. end;
  2139. end;
  2140. end;
  2141. end;
  2142. procedure add_regvars(var rv: tusedregvars; const location: tlocation);
  2143. begin
  2144. case location.loc of
  2145. LOC_CREGISTER:
  2146. {$ifndef cpu64bit}
  2147. if location.size in [OS_64,OS_S64] then
  2148. begin
  2149. rv.intregvars.addnodup(getsupreg(location.register64.reglo));
  2150. rv.intregvars.addnodup(getsupreg(location.register64.reghi));
  2151. end
  2152. else
  2153. {$endif cpu64bit}
  2154. rv.intregvars.addnodup(getsupreg(location.register));
  2155. LOC_CFPUREGISTER:
  2156. rv.fpuregvars.addnodup(getsupreg(location.register));
  2157. LOC_CMMREGISTER:
  2158. rv.mmregvars.addnodup(getsupreg(location.register));
  2159. end;
  2160. end;
  2161. function do_get_used_regvars(var n: tnode; arg: pointer): foreachnoderesult;
  2162. var
  2163. rv: pusedregvars absolute arg;
  2164. begin
  2165. case (n.nodetype) of
  2166. temprefn:
  2167. { We only have to synchronise a tempnode before a loop if it is }
  2168. { not created inside the loop, and only synchronise after the }
  2169. { loop if it's not destroyed inside the loop. If it's created }
  2170. { before the loop and not yet destroyed, then before the loop }
  2171. { is secondpassed tempinfo^.valid will be true, and we get the }
  2172. { correct registers. If it's not destroyed inside the loop, }
  2173. { then after the loop has been secondpassed tempinfo^.valid }
  2174. { be true and we also get the right registers. In other cases, }
  2175. { tempinfo^.valid will be false and so we do not add }
  2176. { unnecessary registers. This way, we don't have to look at }
  2177. { tempcreate and tempdestroy nodes to get this info (JM) }
  2178. if (ttemprefnode(n).tempinfo^.valid) then
  2179. add_regvars(rv^,ttemprefnode(n).tempinfo^.location);
  2180. loadn:
  2181. if (tloadnode(n).symtableentry.typ in [globalvarsym,localvarsym,paravarsym]) then
  2182. add_regvars(rv^,tabstractnormalvarsym(tloadnode(n).symtableentry).localloc);
  2183. vecn:
  2184. { range checks sometimes need the high parameter }
  2185. if (cs_check_range in current_settings.localswitches) and
  2186. (is_open_array(tvecnode(n).left.resultdef) or
  2187. is_array_of_const(tvecnode(n).left.resultdef)) and
  2188. not(current_procinfo.procdef.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  2189. add_regvars(rv^,tabstractnormalvarsym(get_high_value_sym(tparavarsym(tloadnode(tvecnode(n).left).symtableentry))).localloc)
  2190. end;
  2191. result := fen_true;
  2192. end;
  2193. procedure get_used_regvars(n: tnode; var rv: tusedregvars);
  2194. begin
  2195. foreachnodestatic(n,@do_get_used_regvars,@rv);
  2196. end;
  2197. (*
  2198. See comments at declaration of pusedregvarscommon
  2199. function do_get_used_regvars_common(var n: tnode; arg: pointer): foreachnoderesult;
  2200. var
  2201. rv: pusedregvarscommon absolute arg;
  2202. begin
  2203. if (n.nodetype = loadn) and
  2204. (tloadnode(n).symtableentry.typ in [globalvarsym,localvarsym,paravarsym]) then
  2205. with tabstractnormalvarsym(tloadnode(n).symtableentry).localloc do
  2206. case loc of
  2207. LOC_CREGISTER:
  2208. { if not yet encountered in this node tree }
  2209. if (rv^.myregvars.intregvars.addnodup(getsupreg(register))) and
  2210. { but nevertheless already encountered somewhere }
  2211. not(rv^.allregvars.intregvars.addnodup(getsupreg(register))) then
  2212. { then it's a regvar used in two or more node trees }
  2213. rv^.commonregvars.intregvars.addnodup(getsupreg(register));
  2214. LOC_CFPUREGISTER:
  2215. if (rv^.myregvars.intregvars.addnodup(getsupreg(register))) and
  2216. not(rv^.allregvars.intregvars.addnodup(getsupreg(register))) then
  2217. rv^.commonregvars.intregvars.addnodup(getsupreg(register));
  2218. LOC_CMMREGISTER:
  2219. if (rv^.myregvars.intregvars.addnodup(getsupreg(register))) and
  2220. not(rv^.allregvars.intregvars.addnodup(getsupreg(register))) then
  2221. rv^.commonregvars.intregvars.addnodup(getsupreg(register));
  2222. end;
  2223. result := fen_true;
  2224. end;
  2225. procedure get_used_regvars_common(n: tnode; var rv: tusedregvarscommon);
  2226. begin
  2227. rv.myregvars.intregvars.clear;
  2228. rv.myregvars.fpuregvars.clear;
  2229. rv.myregvars.mmregvars.clear;
  2230. foreachnodestatic(n,@do_get_used_regvars_common,@rv);
  2231. end;
  2232. *)
  2233. procedure gen_sync_regvars(list:TAsmList; var rv: tusedregvars);
  2234. var
  2235. count: longint;
  2236. begin
  2237. for count := 1 to rv.intregvars.length do
  2238. cg.a_reg_sync(list,newreg(R_INTREGISTER,rv.intregvars.readidx(count-1),R_SUBWHOLE));
  2239. for count := 1 to rv.fpuregvars.length do
  2240. cg.a_reg_sync(list,newreg(R_FPUREGISTER,rv.fpuregvars.readidx(count-1),R_SUBWHOLE));
  2241. for count := 1 to rv.mmregvars.length do
  2242. cg.a_reg_sync(list,newreg(R_MMREGISTER,rv.mmregvars.readidx(count-1),R_SUBWHOLE));
  2243. end;
  2244. {*****************************************************************************
  2245. SSA support
  2246. *****************************************************************************}
  2247. type
  2248. preplaceregrec = ^treplaceregrec;
  2249. treplaceregrec = record
  2250. old, new: tregister;
  2251. {$ifndef cpu64bit}
  2252. oldhi, newhi: tregister;
  2253. {$endif cpu64bit}
  2254. ressym: tsym;
  2255. end;
  2256. function doreplace(var n: tnode; para: pointer): foreachnoderesult;
  2257. var
  2258. rr: preplaceregrec absolute para;
  2259. begin
  2260. result := fen_false;
  2261. case n.nodetype of
  2262. loadn:
  2263. begin
  2264. if (tabstractvarsym(tloadnode(n).symtableentry).varoptions * [vo_is_dll_var, vo_is_thread_var] = []) and
  2265. not assigned(tloadnode(n).left) and
  2266. (((tloadnode(n).symtableentry <> rr^.ressym) and
  2267. not(vo_is_funcret in tabstractvarsym(tloadnode(n).symtableentry).varoptions)) or
  2268. not(fc_exit in flowcontrol)) and
  2269. (tabstractnormalvarsym(tloadnode(n).symtableentry).localloc.loc in [LOC_CREGISTER,LOC_CFPUREGISTER,LOC_CMMXREGISTER,LOC_CMMREGISTER]) and
  2270. (tabstractnormalvarsym(tloadnode(n).symtableentry).localloc.register = rr^.old) then
  2271. begin
  2272. {$ifndef cpu64bit}
  2273. { it's possible a 64 bit location was shifted and/xor typecasted }
  2274. { in a 32 bit value, so only 1 register was left in the location }
  2275. if (tabstractnormalvarsym(tloadnode(n).symtableentry).localloc.size in [OS_64,OS_S64]) then
  2276. if (tabstractnormalvarsym(tloadnode(n).symtableentry).localloc.register64.reghi = rr^.oldhi) then
  2277. tabstractnormalvarsym(tloadnode(n).symtableentry).localloc.register64.reghi := rr^.newhi
  2278. else
  2279. exit;
  2280. {$endif cpu64bit}
  2281. tabstractnormalvarsym(tloadnode(n).symtableentry).localloc.register := rr^.new;
  2282. result := fen_norecurse_true;
  2283. end;
  2284. end;
  2285. temprefn:
  2286. begin
  2287. if (ttemprefnode(n).tempinfo^.valid) and
  2288. (ttemprefnode(n).tempinfo^.location.loc in [LOC_CREGISTER,LOC_CFPUREGISTER,LOC_CMMXREGISTER,LOC_CMMREGISTER]) and
  2289. (ttemprefnode(n).tempinfo^.location.register = rr^.old) then
  2290. begin
  2291. {$ifndef cpu64bit}
  2292. { it's possible a 64 bit location was shifted and/xor typecasted }
  2293. { in a 32 bit value, so only 1 register was left in the location }
  2294. if (ttemprefnode(n).tempinfo^.location.size in [OS_64,OS_S64]) then
  2295. if (ttemprefnode(n).tempinfo^.location.register64.reghi = rr^.oldhi) then
  2296. ttemprefnode(n).tempinfo^.location.register64.reghi := rr^.newhi
  2297. else
  2298. exit;
  2299. {$endif cpu64bit}
  2300. ttemprefnode(n).tempinfo^.location.register := rr^.new;
  2301. result := fen_norecurse_true;
  2302. end;
  2303. end;
  2304. { optimize the searching a bit }
  2305. derefn,addrn,
  2306. calln,inlinen,casen,
  2307. addn,subn,muln,
  2308. andn,orn,xorn,
  2309. ltn,lten,gtn,gten,equaln,unequaln,
  2310. slashn,divn,shrn,shln,notn,
  2311. inn,
  2312. asn,isn:
  2313. result := fen_norecurse_false;
  2314. end;
  2315. end;
  2316. procedure maybechangeloadnodereg(list: TAsmList; var n: tnode; reload: boolean);
  2317. var
  2318. rr: treplaceregrec;
  2319. begin
  2320. if not (n.location.loc in [LOC_CREGISTER,LOC_CFPUREGISTER,LOC_CMMXREGISTER,LOC_CMMREGISTER]) or
  2321. ([fc_inflowcontrol,fc_gotolabel] * flowcontrol <> []) then
  2322. exit;
  2323. rr.old := n.location.register;
  2324. rr.ressym := nil;
  2325. {$ifndef cpu64bit}
  2326. rr.oldhi := NR_NO;
  2327. {$endif cpu64bit}
  2328. case n.location.loc of
  2329. LOC_CREGISTER:
  2330. begin
  2331. {$ifndef cpu64bit}
  2332. if (n.location.size in [OS_64,OS_S64]) then
  2333. begin
  2334. rr.oldhi := n.location.register64.reghi;
  2335. rr.new := cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  2336. rr.newhi := cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  2337. end
  2338. else
  2339. {$endif cpu64bit}
  2340. rr.new := cg.getintregister(current_asmdata.CurrAsmList,n.location.size);
  2341. end;
  2342. LOC_CFPUREGISTER:
  2343. rr.new := cg.getfpuregister(current_asmdata.CurrAsmList,n.location.size);
  2344. {$ifdef SUPPORT_MMX}
  2345. LOC_CMMXREGISTER:
  2346. rr.new := tcgx86(cg).getmmxregister(current_asmdata.CurrAsmList);
  2347. {$endif SUPPORT_MMX}
  2348. LOC_CMMREGISTER:
  2349. rr.new := cg.getmmregister(current_asmdata.CurrAsmList,n.location.size);
  2350. else
  2351. exit;
  2352. end;
  2353. if (current_procinfo.procdef.funcretloc[calleeside].loc<>LOC_VOID) and
  2354. assigned(current_procinfo.procdef.funcretsym) and
  2355. (tabstractvarsym(current_procinfo.procdef.funcretsym).refs <> 0) then
  2356. if (current_procinfo.procdef.proctypeoption=potype_constructor) then
  2357. rr.ressym:=tsym(current_procinfo.procdef.parast.Find('self'))
  2358. else
  2359. rr.ressym:=current_procinfo.procdef.funcretsym;
  2360. if not foreachnodestatic(n,@doreplace,@rr) then
  2361. exit;
  2362. if reload then
  2363. case n.location.loc of
  2364. LOC_CREGISTER:
  2365. begin
  2366. {$ifndef cpu64bit}
  2367. if (n.location.size in [OS_64,OS_S64]) then
  2368. cg64.a_load64_reg_reg(list,n.location.register64,joinreg64(rr.new,rr.newhi))
  2369. else
  2370. {$endif cpu64bit}
  2371. cg.a_load_reg_reg(list,n.location.size,n.location.size,n.location.register,rr.new);
  2372. end;
  2373. LOC_CFPUREGISTER:
  2374. cg.a_loadfpu_reg_reg(list,n.location.size,n.location.register,rr.new);
  2375. {$ifdef SUPPORT_MMX}
  2376. LOC_CMMXREGISTER:
  2377. cg.a_loadmm_reg_reg(list,OS_M64,OS_M64,n.location.register,rr.new,nil);
  2378. {$endif SUPPORT_MMX}
  2379. LOC_CMMREGISTER:
  2380. cg.a_loadmm_reg_reg(list,n.location.size,n.location.size,n.location.register,rr.new,nil);
  2381. else
  2382. internalerror(2006090920);
  2383. end;
  2384. { now that we've change the loadn/temp, also change the node result location }
  2385. {$ifndef cpu64bit}
  2386. if (n.location.size in [OS_64,OS_S64]) then
  2387. begin
  2388. n.location.register64.reglo := rr.new;
  2389. n.location.register64.reghi := rr.newhi;
  2390. end
  2391. else
  2392. {$endif cpu64bit}
  2393. n.location.register := rr.new;
  2394. end;
  2395. procedure gen_free_symtable(list:TAsmList;st:TSymtable);
  2396. var
  2397. i : longint;
  2398. sym : tsym;
  2399. begin
  2400. for i:=0 to st.SymList.Count-1 do
  2401. begin
  2402. sym:=tsym(st.SymList[i]);
  2403. if (sym.typ in [globalvarsym,localvarsym,paravarsym]) then
  2404. begin
  2405. with tabstractnormalvarsym(sym) do
  2406. begin
  2407. { Note: We need to keep the data available in memory
  2408. for the sub procedures that can access local data
  2409. in the parent procedures }
  2410. case localloc.loc of
  2411. LOC_CREGISTER :
  2412. {$ifndef cpu64bit}
  2413. if (pi_has_goto in current_procinfo.flags) then
  2414. if def_cgsize(vardef) in [OS_64,OS_S64] then
  2415. begin
  2416. cg.a_reg_sync(list,localloc.register64.reglo);
  2417. cg.a_reg_sync(list,localloc.register64.reghi);
  2418. end
  2419. else
  2420. {$endif cpu64bit}
  2421. cg.a_reg_sync(list,localloc.register);
  2422. LOC_CFPUREGISTER,
  2423. LOC_CMMREGISTER:
  2424. if (pi_has_goto in current_procinfo.flags) then
  2425. cg.a_reg_sync(list,localloc.register);
  2426. LOC_REFERENCE :
  2427. begin
  2428. case st.symtabletype of
  2429. localsymtable,
  2430. parasymtable,
  2431. stt_excepTSymtable :
  2432. tg.Ungetlocal(list,localloc.reference);
  2433. end;
  2434. end;
  2435. end;
  2436. end;
  2437. end;
  2438. end;
  2439. end;
  2440. procedure gen_intf_wrapper(list:TAsmList;_class:tobjectdef);
  2441. var
  2442. i,j : longint;
  2443. tmps : string;
  2444. pd : TProcdef;
  2445. ImplIntf : TImplementedInterface;
  2446. begin
  2447. for i:=0 to _class.ImplementedInterfaces.count-1 do
  2448. begin
  2449. ImplIntf:=TImplementedInterface(_class.ImplementedInterfaces[i]);
  2450. if (ImplIntf=ImplIntf.VtblImplIntf) and
  2451. assigned(ImplIntf.ProcDefs) then
  2452. begin
  2453. for j:=0 to ImplIntf.ProcDefs.Count-1 do
  2454. begin
  2455. pd:=TProcdef(ImplIntf.ProcDefs[j]);
  2456. tmps:=make_mangledname('WRPR',_class.owner,_class.objname^+'_$_'+
  2457. ImplIntf.IntfDef.objname^+'_$_'+tostr(j)+'_$_'+pd.mangledname);
  2458. { create wrapper code }
  2459. new_section(list,sec_code,tmps,0);
  2460. cg.init_register_allocators;
  2461. cg.g_intf_wrapper(list,pd,tmps,ImplIntf.ioffset);
  2462. cg.done_register_allocators;
  2463. end;
  2464. end;
  2465. end;
  2466. end;
  2467. procedure gen_intf_wrappers(list:TAsmList;st:TSymtable);
  2468. var
  2469. i : longint;
  2470. def : tdef;
  2471. begin
  2472. for i:=0 to st.DefList.Count-1 do
  2473. begin
  2474. def:=tdef(st.DefList[i]);
  2475. if is_class(def) then
  2476. gen_intf_wrapper(list,tobjectdef(def));
  2477. end;
  2478. end;
  2479. procedure gen_load_vmt_register(list:TAsmList;objdef:tobjectdef;selfloc:tlocation;var vmtreg:tregister);
  2480. var
  2481. href : treference;
  2482. begin
  2483. if is_object(objdef) then
  2484. begin
  2485. case selfloc.loc of
  2486. LOC_CREFERENCE,
  2487. LOC_REFERENCE:
  2488. begin
  2489. reference_reset_base(href,cg.getaddressregister(list),objdef.vmt_offset);
  2490. cg.a_loadaddr_ref_reg(list,selfloc.reference,href.base);
  2491. end;
  2492. else
  2493. internalerror(200305056);
  2494. end;
  2495. end
  2496. else
  2497. begin
  2498. case selfloc.loc of
  2499. LOC_REGISTER:
  2500. begin
  2501. {$ifdef cpu_uses_separate_address_registers}
  2502. if getregtype(left.location.register)<>R_ADDRESSREGISTER then
  2503. begin
  2504. reference_reset_base(href,cg.getaddressregister(list),objdef.vmt_offset);
  2505. cg.a_load_reg_reg(list,OS_ADDR,OS_ADDR,selfloc.register,href.base);
  2506. end
  2507. else
  2508. {$endif cpu_uses_separate_address_registers}
  2509. reference_reset_base(href,selfloc.register,objdef.vmt_offset);
  2510. end;
  2511. LOC_CREGISTER,
  2512. LOC_CREFERENCE,
  2513. LOC_REFERENCE:
  2514. begin
  2515. reference_reset_base(href,cg.getaddressregister(list),objdef.vmt_offset);
  2516. cg.a_load_loc_reg(list,OS_ADDR,selfloc,href.base);
  2517. end;
  2518. else
  2519. internalerror(200305057);
  2520. end;
  2521. end;
  2522. vmtreg:=cg.getaddressregister(list);
  2523. cg.g_maybe_testself(list,href.base);
  2524. cg.a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,vmtreg);
  2525. { test validity of VMT }
  2526. if not(is_interface(objdef)) and
  2527. not(is_cppclass(objdef)) then
  2528. cg.g_maybe_testvmt(list,vmtreg,objdef);
  2529. end;
  2530. function getprocalign : shortint;
  2531. begin
  2532. { gprof uses 16 byte granularity }
  2533. if (cs_profile in current_settings.moduleswitches) then
  2534. result:=16
  2535. else
  2536. result:=current_settings.alignment.procalign;
  2537. end;
  2538. procedure gen_pic_helpers(list : TAsmList);
  2539. var
  2540. href : treference;
  2541. begin
  2542. { if other cpus require such helpers as well, it can be solved more cleaner }
  2543. {$ifdef i386}
  2544. if current_module.requires_ebx_pic_helper then
  2545. begin
  2546. new_section(list,sec_code,'fpc_geteipasebx',0);
  2547. list.concat(tai_symbol.Createname('fpc_geteipasebx',AT_FUNCTION,getprocalign));
  2548. reference_reset(href);
  2549. href.base:=NR_ESP;
  2550. list.concat(taicpu.op_ref_reg(A_MOV,S_L,href,NR_EBX));
  2551. list.concat(taicpu.op_none(A_RET,S_NO));
  2552. end;
  2553. if current_module.requires_ecx_pic_helper then
  2554. begin
  2555. new_section(list,sec_code,'fpc_geteipasecx',0);
  2556. list.concat(tai_symbol.Createname('fpc_geteipasecx',AT_FUNCTION,getprocalign));
  2557. reference_reset(href);
  2558. href.base:=NR_ESP;
  2559. list.concat(taicpu.op_ref_reg(A_MOV,S_L,href,NR_ECX));
  2560. list.concat(taicpu.op_none(A_RET,S_NO));
  2561. end;
  2562. {$endif i386}
  2563. end;
  2564. end.