ncgutil.pas 109 KB

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