2
0

cpupara.pas 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. {
  2. Copyright (c) 2013-2014 by Jonas Maebe, Florian Klaempfl and others
  3. AArch64 specific calling conventions
  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. { AArch64 specific calling conventions are handled by this unit
  18. }
  19. unit cpupara;
  20. {$i fpcdefs.inc}
  21. interface
  22. uses
  23. globtype,globals,
  24. aasmtai,aasmdata,
  25. cpuinfo,cpubase,cgbase,cgutils,
  26. symconst,symbase,symtype,symdef,parabase,paramgr,armpara;
  27. type
  28. tcpuparamanager = class(tarmgenparamanager)
  29. function get_volatile_registers_int(calloption: tproccalloption): tcpuregisterset; override;
  30. function get_volatile_registers_fpu(calloption: tproccalloption): tcpuregisterset; override;
  31. function get_volatile_registers_mm(calloption: tproccalloption): tcpuregisterset; override;
  32. function get_saved_registers_int(calloption: tproccalloption): tcpuregisterarray; override;
  33. function get_saved_registers_mm(calloption: tproccalloption): tcpuregisterarray; override;
  34. function push_addr_param(varspez: tvarspez; def: tdef; calloption: tproccalloption): boolean; override;
  35. function ret_in_param(def: tdef; pd: tabstractprocdef):boolean;override;
  36. function create_paraloc_info(p: tabstractprocdef; side: tcallercallee):longint;override;
  37. function create_varargs_paraloc_info(p: tabstractprocdef; side: tcallercallee; varargspara: tvarargsparalist):longint;override;
  38. function get_funcretloc(p: tabstractprocdef; side: tcallercallee; forcetempdef: tdef): tcgpara;override;
  39. function param_use_paraloc(const cgpara: tcgpara): boolean; override;
  40. private
  41. curintreg,
  42. curmmreg: tsuperregister;
  43. curstackoffset: aword;
  44. procedure init_para_alloc_values;
  45. procedure alloc_para(out result: tcgpara; p: tabstractprocdef; varspez: tvarspez; side: tcallercallee; paradef: tdef; isvariadic, isdelphinestedcc: boolean);
  46. function getparaloc(calloption: tproccalloption; p: tdef): tcgloc;
  47. procedure create_paraloc_info_intern(p: tabstractprocdef; side: tcallercallee; paras: tparalist; isvariadic: boolean);
  48. end;
  49. implementation
  50. uses
  51. verbose,systems,cutils,
  52. rgobj,
  53. defutil,symsym,symtable;
  54. const
  55. RS_FIRST_INT_PARAM_SUPREG = RS_X0;
  56. RS_LAST_INT_PARAM_SUPREG = RS_X7;
  57. { Q0/D0/S0/H0/B0 all have the same superregister number }
  58. RS_FIRST_MM_PARAM_SUPREG = RS_D0;
  59. RS_LAST_MM_PARAM_SUPREG = RS_D7;
  60. function tcpuparamanager.get_volatile_registers_int(calloption : tproccalloption):tcpuregisterset;
  61. begin
  62. result:=VOLATILE_INTREGISTERS
  63. end;
  64. function tcpuparamanager.get_volatile_registers_fpu(calloption : tproccalloption):tcpuregisterset;
  65. begin
  66. result:=[];
  67. end;
  68. function tcpuparamanager.get_volatile_registers_mm(calloption: tproccalloption): tcpuregisterset;
  69. begin
  70. result:=VOLATILE_MMREGISTERS;
  71. end;
  72. function tcpuparamanager.get_saved_registers_int(calloption: tproccalloption): tcpuregisterarray;
  73. const
  74. saved_regs : array[0..9] of tsuperregister =
  75. (RS_X19,RS_X20,RS_X21,RS_X22,RS_X23,RS_X24,RS_X25,RS_X26,RS_X27,RS_X28);
  76. begin
  77. result:=saved_regs;
  78. end;
  79. function tcpuparamanager.get_saved_registers_mm(calloption: tproccalloption): tcpuregisterarray;
  80. const
  81. saved_mm_regs : array[0..7] of tsuperregister = (RS_D8,RS_D9,RS_D10,RS_D11,RS_D12,RS_D13,RS_D14,RS_D15);
  82. begin
  83. result:=saved_mm_regs;
  84. end;
  85. function tcpuparamanager.getparaloc(calloption: tproccalloption; p: tdef): tcgloc;
  86. var
  87. hfabasedef: tdef;
  88. begin
  89. { Later, the LOC_REFERENCE is in most cases changed into LOC_REGISTER
  90. if push_addr_param for the def is true
  91. }
  92. case p.typ of
  93. orddef:
  94. getparaloc:=LOC_REGISTER;
  95. floatdef:
  96. getparaloc:=LOC_MMREGISTER;
  97. enumdef:
  98. getparaloc:=LOC_REGISTER;
  99. pointerdef:
  100. getparaloc:=LOC_REGISTER;
  101. formaldef:
  102. getparaloc:=LOC_REGISTER;
  103. classrefdef:
  104. getparaloc:=LOC_REGISTER;
  105. recorddef:
  106. if not is_hfa(p,hfabasedef) then
  107. getparaloc:=LOC_REGISTER
  108. else
  109. getparaloc:=LOC_MMREGISTER;
  110. objectdef:
  111. getparaloc:=LOC_REGISTER;
  112. stringdef:
  113. if is_shortstring(p) or is_longstring(p) then
  114. getparaloc:=LOC_REFERENCE
  115. else
  116. getparaloc:=LOC_REGISTER;
  117. procvardef:
  118. getparaloc:=LOC_REGISTER;
  119. filedef:
  120. getparaloc:=LOC_REGISTER;
  121. arraydef:
  122. if not is_hfa(p,hfabasedef) then
  123. getparaloc:=LOC_REGISTER
  124. else
  125. getparaloc:=LOC_MMREGISTER;
  126. setdef:
  127. getparaloc:=LOC_REGISTER;
  128. variantdef:
  129. getparaloc:=LOC_REGISTER;
  130. { avoid problems with errornous definitions }
  131. errordef:
  132. getparaloc:=LOC_REGISTER;
  133. else
  134. internalerror(2002071001);
  135. end;
  136. end;
  137. function tcpuparamanager.push_addr_param(varspez: tvarspez; def :tdef; calloption: tproccalloption): boolean;
  138. var
  139. hfabasedef: tdef;
  140. begin
  141. result:=false;
  142. if varspez in [vs_var,vs_out,vs_constref] then
  143. begin
  144. result:=true;
  145. exit;
  146. end;
  147. case def.typ of
  148. objectdef:
  149. result:=is_object(def);
  150. recorddef:
  151. { ABI: any composite > 16 bytes that not a hfa/hva
  152. Special case: MWPascal, which passes all const parameters by
  153. reference for compatibility reasons
  154. }
  155. result:=
  156. ((varspez=vs_const) and
  157. (calloption=pocall_mwpascal)) or
  158. (not is_hfa(def,hfabasedef) and
  159. (def.size>16));
  160. variantdef,
  161. formaldef:
  162. result:=true;
  163. { arrays are composites and hence treated the same as records by the
  164. ABI (watch out for C, where an array is a pointer)
  165. Also: all other platforms pass const arrays by reference. Do the
  166. same here, because there is too much hacky code out there that
  167. relies on this ("array[0..0] of x" passed as const parameter and
  168. then indexed beyond its bounds) }
  169. arraydef:
  170. result:=
  171. ((calloption in cdecl_pocalls) and
  172. not is_dynamic_array(def)) or
  173. is_open_array(def) or
  174. is_array_of_const(def) or
  175. is_array_constructor(def) or
  176. ((tarraydef(def).highrange>=tarraydef(def).lowrange) and
  177. ((varspez=vs_const) or
  178. (not is_hfa(def,hfabasedef) and
  179. (def.size>16))));
  180. setdef :
  181. result:=def.size>16;
  182. stringdef :
  183. result:=tstringdef(def).stringtype in [st_shortstring,st_longstring];
  184. end;
  185. end;
  186. function tcpuparamanager.ret_in_param(def: tdef; pd: tabstractprocdef): boolean;
  187. begin
  188. if handle_common_ret_in_param(def,pd,result) then
  189. exit;
  190. { ABI: if the parameter would be passed in registers, it is returned
  191. in those registers; otherwise, it's returned by reference }
  192. result:=push_addr_param(vs_value,def,pd.proccalloption);
  193. end;
  194. procedure tcpuparamanager.create_paraloc_info_intern(p : tabstractprocdef; side: tcallercallee; paras: tparalist; isvariadic: boolean);
  195. var
  196. hp: tparavarsym;
  197. i: longint;
  198. begin
  199. for i:=0 to paras.count-1 do
  200. begin
  201. hp:=tparavarsym(paras[i]);
  202. { hidden function result parameter is passed in X8 (doesn't have to
  203. be valid on return) according to the ABI
  204. -- don't follow the ABI for managed types, because
  205. a) they are passed in registers as parameters, so we should also
  206. return them in a register to be ABI-compliant (which we can't
  207. because the entire compiler is built around the idea that
  208. they are returned by reference, for ref-counting performance
  209. and Delphi-compatibility reasons)
  210. b) there are hacks in the system unit that expect that you can
  211. call
  212. function f: com_interface;
  213. as
  214. procedure p(out o: obj);
  215. That can only work in case we do not use x8 to return them
  216. from the function, but the regular first parameter register.
  217. As the ABI says this behaviour is ok for C++ classes with a
  218. non-trivial copy constructor or destructor, it seems reasonable
  219. for us to do this for managed types as well.}
  220. if (vo_is_funcret in hp.varoptions) and
  221. not is_managed_type(hp.vardef) then
  222. begin
  223. hp.paraloc[side].reset;
  224. hp.paraloc[side].size:=OS_ADDR;
  225. hp.paraloc[side].alignment:=voidpointertype.alignment;
  226. hp.paraloc[side].intsize:=voidpointertype.size;
  227. hp.paraloc[side].def:=cpointerdef.getreusable_no_free(hp.vardef);
  228. with hp.paraloc[side].add_location^ do
  229. begin
  230. size:=OS_ADDR;
  231. def:=hp.paraloc[side].def;
  232. loc:=LOC_REGISTER;
  233. register:=NR_X8;
  234. end
  235. end
  236. else
  237. alloc_para(hp.paraloc[side],p,hp.varspez,side,hp.vardef,isvariadic,
  238. (vo_is_parentfp in hp.varoptions) and
  239. (po_delphi_nested_cc in p.procoptions));
  240. end;
  241. end;
  242. function tcpuparamanager.get_funcretloc(p : tabstractprocdef; side: tcallercallee; forcetempdef: tdef): tcgpara;
  243. var
  244. retcgsize: tcgsize;
  245. begin
  246. if set_common_funcretloc_info(p,forcetempdef,retcgsize,result) then
  247. exit;
  248. { in this case, it must be returned in registers as if it were passed
  249. as the first parameter }
  250. init_para_alloc_values;
  251. alloc_para(result,p,vs_value,side,result.def,false,false);
  252. { sanity check (LOC_VOID for empty records) }
  253. if not assigned(result.location) or
  254. not(result.location^.loc in [LOC_REGISTER,LOC_MMREGISTER,LOC_VOID]) then
  255. internalerror(2014113001);
  256. {
  257. According to ARM64 ABI: "If the size of the argument is less than 8 bytes then
  258. the size of the argument is set to 8 bytes. The effect is as if the argument
  259. was copied to the least significant bits of a 64-bit register and the remaining
  260. bits filled with unspecified values."
  261. Therefore at caller side force the ordinal result to be always 64-bit, so it
  262. will be stripped to the required size and uneeded bits are discarded.
  263. This is not required for iOS, where the result is zero/sign extended.
  264. }
  265. if (target_info.abi<>abi_aarch64_darwin) and
  266. (side=callerside) and (result.location^.loc = LOC_REGISTER) and
  267. (result.def.size<8) and is_ordinal(result.def) then
  268. begin
  269. result.location^.size:=OS_64;
  270. result.location^.def:=u64inttype;
  271. end;
  272. end;
  273. function tcpuparamanager.param_use_paraloc(const cgpara: tcgpara): boolean;
  274. begin
  275. { we always set up a stack frame -> we can always access the parameters
  276. this way }
  277. result:=
  278. (cgpara.location^.loc=LOC_REFERENCE) and
  279. not assigned(cgpara.location^.next);
  280. end;
  281. procedure tcpuparamanager.init_para_alloc_values;
  282. begin
  283. curintreg:=RS_FIRST_INT_PARAM_SUPREG;
  284. curmmreg:=RS_FIRST_MM_PARAM_SUPREG;
  285. curstackoffset:=0;
  286. end;
  287. procedure tcpuparamanager.alloc_para(out result: tcgpara; p: tabstractprocdef; varspez: tvarspez; side: tcallercallee; paradef: tdef; isvariadic, isdelphinestedcc: boolean);
  288. var
  289. hfabasedef, locdef: tdef;
  290. paraloc: pcgparalocation;
  291. paralen, stackslotlen: asizeint;
  292. loc: tcgloc;
  293. paracgsize, locsize: tcgsize;
  294. firstparaloc: boolean;
  295. begin
  296. result.reset;
  297. { currently only support C-style array of const,
  298. there should be no location assigned to the vararg array itself }
  299. if (p.proccalloption in cstylearrayofconst) and
  300. is_array_of_const(paradef) then
  301. begin
  302. result.size:=OS_NO;
  303. result.def:=paradef;
  304. result.alignment:=std_param_align;
  305. result.intsize:=0;
  306. paraloc:=result.add_location;
  307. { hack: the paraloc must be valid, but is not actually used }
  308. paraloc^.loc:=LOC_REGISTER;
  309. paraloc^.register:=NR_X0;
  310. paraloc^.size:=OS_ADDR;
  311. paraloc^.def:=paradef;
  312. exit;
  313. end;
  314. if push_addr_param(varspez,paradef,p.proccalloption) then
  315. begin
  316. paradef:=cpointerdef.getreusable_no_free(paradef);
  317. loc:=LOC_REGISTER;
  318. paracgsize:=OS_ADDR;
  319. paralen:=tcgsize2size[OS_ADDR];
  320. end
  321. else
  322. begin
  323. if not is_special_array(paradef) then
  324. paralen:=paradef.size
  325. else
  326. paralen:=tcgsize2size[def_cgsize(paradef)];
  327. loc:=getparaloc(p.proccalloption,paradef);
  328. if (paradef.typ in [objectdef,arraydef,recorddef]) and
  329. not is_special_array(paradef) and
  330. (varspez in [vs_value,vs_const]) then
  331. paracgsize:=int_cgsize(paralen)
  332. else
  333. begin
  334. paracgsize:=def_cgsize(paradef);
  335. { for things like formaldef }
  336. if paracgsize=OS_NO then
  337. begin
  338. paracgsize:=OS_ADDR;
  339. paralen:=tcgsize2size[OS_ADDR];
  340. paradef:=voidpointertype;
  341. end;
  342. end
  343. end;
  344. { get hfa basedef if applicable }
  345. if not is_hfa(paradef,hfabasedef) then
  346. hfabasedef:=nil;
  347. result.size:=paracgsize;
  348. result.alignment:=std_param_align;
  349. result.intsize:=paralen;
  350. result.def:=paradef;
  351. { empty record: skipped (explicitly defined by Apple ABI, undefined
  352. by general ABI; libffi also skips them in all cases) }
  353. if not is_special_array(paradef) and
  354. (paradef.size=0) then
  355. begin
  356. paraloc:=result.add_location;
  357. paraloc^.loc:=LOC_VOID;
  358. paraloc^.def:=paradef;
  359. paraloc^.size:=OS_NO;
  360. exit;
  361. end;
  362. { sufficient registers left? }
  363. case loc of
  364. LOC_REGISTER:
  365. begin
  366. { In case of po_delphi_nested_cc, the parent frame pointer
  367. is always passed on the stack. }
  368. if isdelphinestedcc then
  369. loc:=LOC_REFERENCE
  370. else if curintreg+((paralen-1) shr 3)>RS_LAST_INT_PARAM_SUPREG then
  371. begin
  372. { not enough integer registers left -> no more register
  373. parameters, copy all to stack
  374. }
  375. curintreg:=succ(RS_LAST_INT_PARAM_SUPREG);
  376. loc:=LOC_REFERENCE;
  377. end;
  378. end;
  379. LOC_MMREGISTER:
  380. begin;
  381. { every hfa element must be passed in a separate register }
  382. if (assigned(hfabasedef) and
  383. (curmmreg+((paralen-1) div hfabasedef.size)>RS_LAST_MM_PARAM_SUPREG)) or
  384. (curmmreg+((paralen-1) shr 3)>RS_LAST_MM_PARAM_SUPREG) then
  385. begin
  386. { not enough mm registers left -> no more register
  387. parameters, copy all to stack
  388. }
  389. curmmreg:=succ(RS_LAST_MM_PARAM_SUPREG);
  390. loc:=LOC_REFERENCE;
  391. end;
  392. end;
  393. end;
  394. { allocate registers/stack locations }
  395. firstparaloc:=true;
  396. repeat
  397. paraloc:=result.add_location;
  398. { set paraloc size/def }
  399. if assigned(hfabasedef) then
  400. begin
  401. locsize:=def_cgsize(hfabasedef);
  402. locdef:=hfabasedef;
  403. end
  404. { make sure we don't lose whether or not the type is signed }
  405. else if (loc=LOC_REGISTER) and
  406. (paradef.typ<>orddef) then
  407. begin
  408. locsize:=int_cgsize(paralen);
  409. locdef:=get_paraloc_def(paradef,paralen,firstparaloc);
  410. end
  411. else
  412. begin
  413. locsize:=paracgsize;
  414. locdef:=paradef;
  415. end;
  416. if locsize in [OS_NO,OS_128,OS_S128] then
  417. begin
  418. if paralen>4 then
  419. begin
  420. paraloc^.size:=OS_INT;
  421. paraloc^.def:=u64inttype;
  422. end
  423. else
  424. begin
  425. { for 3-byte records }
  426. paraloc^.size:=OS_32;
  427. paraloc^.def:=u32inttype;
  428. end;
  429. end
  430. else
  431. begin
  432. {$ifndef llvm}
  433. paraloc^.size:=locsize;
  434. paraloc^.def:=locdef;
  435. {$else llvm}
  436. case locsize of
  437. OS_8,OS_16,OS_32:
  438. begin
  439. paraloc^.size:=OS_64;
  440. paraloc^.def:=u64inttype;
  441. end;
  442. OS_S8,OS_S16,OS_S32:
  443. begin
  444. paraloc^.size:=OS_S64;
  445. paraloc^.def:=s64inttype;
  446. end;
  447. OS_F32:
  448. begin
  449. paraloc^.size:=OS_F32;
  450. paraloc^.def:=s32floattype;
  451. end;
  452. OS_F64:
  453. begin
  454. paraloc^.size:=OS_F64;
  455. paraloc^.def:=s64floattype;
  456. end;
  457. else
  458. begin
  459. if is_record(locdef) or
  460. ((locdef.typ=arraydef) and
  461. not is_special_array(locdef)) then
  462. begin
  463. paraloc^.size:=OS_64;
  464. paraloc^.def:=u64inttype;
  465. end
  466. else
  467. begin
  468. paraloc^.size:=locsize;
  469. paraloc^.def:=locdef;
  470. end;
  471. end;
  472. end;
  473. {$endif llvm}
  474. end;
  475. { paraloc loc }
  476. paraloc^.loc:=loc;
  477. { assign register/stack address }
  478. case loc of
  479. LOC_REGISTER:
  480. begin
  481. paraloc^.register:=newreg(R_INTREGISTER,curintreg,cgsize2subreg(R_INTREGISTER,paraloc^.size));
  482. inc(curintreg);
  483. dec(paralen,tcgsize2size[paraloc^.size]);
  484. { "The general ABI specifies that it is the callee's
  485. responsibility to sign or zero-extend arguments having fewer
  486. than 32 bits, and that unused bits in a register are
  487. unspecified. In iOS, however, the caller must perform such
  488. extensions, up to 32 bits."
  489. Zero extend an argument at caller side for iOS and
  490. ignore the argument's unspecified high bits at callee side for
  491. all other platforms. }
  492. if (paradef.size<4) and is_ordinal(paradef) then
  493. begin
  494. if target_info.abi=abi_aarch64_darwin then
  495. begin
  496. if side=callerside then
  497. begin
  498. paraloc^.size:=OS_32;
  499. paraloc^.def:=u32inttype;
  500. end;
  501. end
  502. else
  503. begin
  504. if side=calleeside then
  505. begin
  506. paraloc^.size:=OS_32;
  507. paraloc^.def:=u32inttype;
  508. end;
  509. end;
  510. end;
  511. { in case it's a composite, "The argument is passed as though
  512. it had been loaded into the registers from a double-word-
  513. aligned address with an appropriate sequence of LDR
  514. instructions loading consecutive registers from memory" ->
  515. in case of big endian, values in not completely filled
  516. registers must be shifted to the top bits }
  517. if (target_info.endian=endian_big) and
  518. not(paraloc^.size in [OS_64,OS_S64]) and
  519. (paradef.typ in [setdef,recorddef,arraydef,objectdef]) then
  520. paraloc^.shiftval:=-(8-tcgsize2size[paraloc^.size])*8;
  521. end;
  522. LOC_MMREGISTER:
  523. begin
  524. paraloc^.register:=newreg(R_MMREGISTER,curmmreg,cgsize2subreg(R_MMREGISTER,paraloc^.size));
  525. inc(curmmreg);
  526. dec(paralen,tcgsize2size[paraloc^.size]);
  527. end;
  528. LOC_REFERENCE:
  529. begin
  530. paraloc^.size:=paracgsize;
  531. paraloc^.loc:=LOC_REFERENCE;
  532. { the current stack offset may not be properly aligned in
  533. case we're on Darwin and have allocated a non-variadic argument
  534. < 8 bytes previously }
  535. if target_info.abi=abi_aarch64_darwin then
  536. curstackoffset:=align(curstackoffset,paraloc^.def.alignment);
  537. { on Darwin, non-variadic arguments take up their actual size
  538. on the stack; on other platforms, they take up a multiple of
  539. 8 bytes }
  540. if (target_info.abi=abi_aarch64_darwin) and
  541. not isvariadic then
  542. stackslotlen:=paralen
  543. else
  544. stackslotlen:=align(paralen,8);
  545. { from the ABI: if arguments occupy partial stack space, they
  546. have to occupy the lowest significant bits of a register
  547. containing that value which is then stored to memory ->
  548. in case of big endian, skip the alignment bytes (if any) }
  549. if target_info.endian=endian_little then
  550. paraloc^.reference.offset:=curstackoffset
  551. else
  552. paraloc^.reference.offset:=curstackoffset+stackslotlen-paralen;
  553. if side=callerside then
  554. paraloc^.reference.index:=NR_STACK_POINTER_REG
  555. else
  556. begin
  557. paraloc^.reference.index:=NR_FRAME_POINTER_REG;
  558. inc(paraloc^.reference.offset,16);
  559. end;
  560. inc(curstackoffset,stackslotlen);
  561. paralen:=0
  562. end;
  563. else
  564. internalerror(2002071002);
  565. end;
  566. firstparaloc:=false;
  567. { <=0 for sign/zero-extended locations }
  568. until paralen<=0;
  569. end;
  570. function tcpuparamanager.create_paraloc_info(p: tabstractprocdef; side: tcallercallee):longint;
  571. begin
  572. init_para_alloc_values;
  573. create_paraloc_info_intern(p,side,p.paras,false);
  574. result:=curstackoffset;
  575. create_funcretloc_info(p,side);
  576. end;
  577. function tcpuparamanager.create_varargs_paraloc_info(p: tabstractprocdef; side: tcallercallee; varargspara: tvarargsparalist):longint;
  578. begin
  579. init_para_alloc_values;
  580. { non-variadic parameters }
  581. create_paraloc_info_intern(p,side,p.paras,false);
  582. if p.proccalloption in cstylearrayofconst then
  583. begin
  584. { on Darwin, we cannot use any registers for variadic parameters }
  585. if target_info.abi=abi_aarch64_darwin then
  586. begin
  587. curintreg:=succ(RS_LAST_INT_PARAM_SUPREG);
  588. curmmreg:=succ(RS_LAST_MM_PARAM_SUPREG);
  589. end;
  590. { continue loading the parameters }
  591. if assigned(varargspara) then
  592. begin
  593. if side=callerside then
  594. create_paraloc_info_intern(p,side,varargspara,true)
  595. else
  596. internalerror(2019021916);
  597. end;
  598. result:=curstackoffset;
  599. end
  600. else
  601. internalerror(200410231);
  602. create_funcretloc_info(p,side);
  603. end;
  604. begin
  605. paramanager:=tcpuparamanager.create;
  606. end.