cpupara.pas 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  1. {
  2. Copyright (c) 2002 by Florian Klaempfl
  3. Generates the argument location information for i8086
  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 cpupara;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. globtype,
  22. aasmtai,aasmdata,cpubase,cgbase,cgutils,
  23. symconst,symtype,symsym,symdef,
  24. parabase,paramgr;
  25. type
  26. ti8086paramanager = class(tparamanager)
  27. function param_use_paraloc(const cgpara:tcgpara):boolean;override;
  28. function ret_in_param(def:tdef;pd:tabstractprocdef):boolean;override;
  29. function push_addr_param(varspez:tvarspez;def : tdef;calloption : tproccalloption) : boolean;override;
  30. function get_para_align(calloption : tproccalloption):byte;override;
  31. function get_volatile_registers_int(calloption : tproccalloption):tcpuregisterset;override;
  32. function get_volatile_registers_fpu(calloption : tproccalloption):tcpuregisterset;override;
  33. function get_volatile_registers_mm(calloption : tproccalloption):tcpuregisterset;override;
  34. { Returns the location for the nr-st 16 Bit int parameter
  35. if every parameter before is an 16 Bit int parameter as well
  36. and if the calling conventions for the helper routines of the
  37. rtl are used.
  38. TODO: This allocates 32-bit ints on other CPU architectures. Since
  39. we're small/tiny model only, for now we can get away with allocating
  40. always 16-bit int parameters, but in the future, when we implement
  41. other memory models, this mechanism has to be extended somehow to
  42. support 32-bit addresses on a 16-bit CPU.
  43. }
  44. procedure getintparaloc(pd : tabstractprocdef; nr : longint; var cgpara : tcgpara);override;
  45. function create_paraloc_info(p : tabstractprocdef; side: tcallercallee):longint;override;
  46. function create_varargs_paraloc_info(p : tabstractprocdef; varargspara:tvarargsparalist):longint;override;
  47. procedure createtempparaloc(list: TAsmList;calloption : tproccalloption;parasym : tparavarsym;can_use_final_stack_loc : boolean;var cgpara:TCGPara);override;
  48. function get_funcretloc(p : tabstractprocdef; side: tcallercallee; forcetempdef: tdef): TCGPara;override;
  49. private
  50. procedure create_stdcall_paraloc_info(p : tabstractprocdef; side: tcallercallee;paras:tparalist;var parasize:longint);
  51. procedure create_register_paraloc_info(p : tabstractprocdef; side: tcallercallee;paras:tparalist;var parareg,parasize:longint);
  52. end;
  53. implementation
  54. uses
  55. cutils,
  56. systems,verbose,
  57. symtable,
  58. defutil;
  59. const
  60. parasupregs : array[0..2] of tsuperregister = (RS_AX,RS_DX,RS_CX);
  61. {****************************************************************************
  62. ti8086paramanager
  63. ****************************************************************************}
  64. function ti8086paramanager.param_use_paraloc(const cgpara:tcgpara):boolean;
  65. var
  66. paraloc : pcgparalocation;
  67. begin
  68. if not assigned(cgpara.location) then
  69. internalerror(200410102);
  70. result:=true;
  71. { All locations are LOC_REFERENCE }
  72. paraloc:=cgpara.location;
  73. while assigned(paraloc) do
  74. begin
  75. if (paraloc^.loc<>LOC_REFERENCE) then
  76. begin
  77. result:=false;
  78. exit;
  79. end;
  80. paraloc:=paraloc^.next;
  81. end;
  82. end;
  83. function ti8086paramanager.ret_in_param(def:tdef;pd:tabstractprocdef):boolean;
  84. var
  85. size: longint;
  86. begin
  87. if handle_common_ret_in_param(def,pd,result) then
  88. exit;
  89. if (def.size > 8) and (def.typ <> floatdef) then
  90. begin
  91. result:=true;
  92. exit;
  93. end;
  94. result:=inherited ret_in_param(def,pd);
  95. end;
  96. function ti8086paramanager.push_addr_param(varspez:tvarspez;def : tdef;calloption : tproccalloption) : boolean;
  97. begin
  98. result:=false;
  99. { var,out,constref always require address }
  100. if varspez in [vs_var,vs_out,vs_constref] then
  101. begin
  102. result:=true;
  103. exit;
  104. end;
  105. { Only vs_const, vs_value here }
  106. case def.typ of
  107. variantdef :
  108. begin
  109. { variants are small enough to be passed by value except if
  110. required by the windows api
  111. variants are somethings very delphi/windows specific so do it like
  112. windows/delphi (FK)
  113. }
  114. if ((target_info.system=system_i386_win32) and
  115. (calloption in [pocall_stdcall,pocall_safecall]) and
  116. (varspez=vs_const)) or
  117. (calloption=pocall_register) then
  118. result:=true
  119. else
  120. result:=false;
  121. end;
  122. formaldef :
  123. result:=true;
  124. recorddef :
  125. begin
  126. { Delphi stdcall passes records on the stack for call by value }
  127. if (target_info.system=system_i386_win32) and
  128. (calloption=pocall_stdcall) and
  129. (varspez=vs_value) then
  130. result:=false
  131. else
  132. result:=
  133. (not(calloption in (cdecl_pocalls)) and
  134. (def.size>sizeof(aint))) or
  135. (((calloption = pocall_mwpascal) or (target_info.system=system_i386_wince)) and
  136. (varspez=vs_const));
  137. end;
  138. arraydef :
  139. begin
  140. { array of const values are pushed on the stack as
  141. well as dyn. arrays }
  142. if (calloption in cdecl_pocalls) then
  143. result:=not(is_array_of_const(def) or
  144. is_dynamic_array(def))
  145. else
  146. begin
  147. result:=(
  148. (tarraydef(def).highrange>=tarraydef(def).lowrange) and
  149. (def.size>sizeof(aint))
  150. ) or
  151. is_open_array(def) or
  152. is_array_of_const(def) or
  153. is_array_constructor(def);
  154. end;
  155. end;
  156. objectdef :
  157. result:=is_object(def);
  158. stringdef :
  159. result:= (tstringdef(def).stringtype in [st_shortstring,st_longstring]);
  160. procvardef :
  161. result:=not(calloption in cdecl_pocalls) and not tprocvardef(def).is_addressonly;
  162. setdef :
  163. result:=not(calloption in cdecl_pocalls) and (not is_smallset(def));
  164. end;
  165. end;
  166. function ti8086paramanager.get_para_align(calloption : tproccalloption):byte;
  167. begin
  168. result:=std_param_align;
  169. end;
  170. function ti8086paramanager.get_volatile_registers_int(calloption : tproccalloption):tcpuregisterset;
  171. begin
  172. case calloption of
  173. pocall_internproc :
  174. result:=[];
  175. pocall_register,
  176. pocall_safecall,
  177. pocall_stdcall,
  178. pocall_cdecl,
  179. pocall_cppdecl,
  180. pocall_mwpascal :
  181. result:=[RS_AX,RS_DX,RS_CX];
  182. pocall_far16,
  183. pocall_pascal,
  184. pocall_oldfpccall :
  185. result:=[RS_AX,RS_DX,RS_CX,RS_SI,RS_DI,RS_BX];
  186. else
  187. internalerror(200309071);
  188. end;
  189. end;
  190. function ti8086paramanager.get_volatile_registers_fpu(calloption : tproccalloption):tcpuregisterset;
  191. begin
  192. result:=[0..first_fpu_imreg-1];
  193. end;
  194. function ti8086paramanager.get_volatile_registers_mm(calloption : tproccalloption):tcpuregisterset;
  195. begin
  196. result:=[0..first_mm_imreg-1];
  197. end;
  198. procedure ti8086paramanager.getintparaloc(pd : tabstractprocdef; nr : longint; var cgpara : tcgpara);
  199. var
  200. paraloc : pcgparalocation;
  201. def : tdef;
  202. begin
  203. def:=tparavarsym(pd.paras[nr-1]).vardef;
  204. cgpara.reset;
  205. cgpara.size:=def_cgsize(def);
  206. cgpara.intsize:=tcgsize2size[cgpara.size];
  207. cgpara.alignment:=get_para_align(pd.proccalloption);
  208. cgpara.def:=def;
  209. paraloc:=cgpara.add_location;
  210. with paraloc^ do
  211. begin
  212. size:=OS_INT;
  213. if pd.proccalloption=pocall_register then
  214. begin
  215. if (nr<=length(parasupregs)) then
  216. begin
  217. if nr=0 then
  218. internalerror(200309271);
  219. loc:=LOC_REGISTER;
  220. register:=newreg(R_INTREGISTER,parasupregs[nr-1],R_SUBWHOLE);
  221. end
  222. else
  223. begin
  224. loc:=LOC_REFERENCE;
  225. reference.index:=NR_STACK_POINTER_REG;
  226. { the previous parameters didn't take up room in memory }
  227. reference.offset:=sizeof(aint)*(nr-length(parasupregs)-1)
  228. end;
  229. end
  230. else
  231. begin
  232. loc:=LOC_REFERENCE;
  233. reference.index:=NR_STACK_POINTER_REG;
  234. reference.offset:=sizeof(aint)*nr;
  235. end;
  236. end;
  237. end;
  238. function ti8086paramanager.get_funcretloc(p : tabstractprocdef; side: tcallercallee; forcetempdef: tdef): TCGPara;
  239. var
  240. retcgsize : tcgsize;
  241. paraloc : pcgparalocation;
  242. sym: tfieldvarsym;
  243. usedef: tdef;
  244. handled: boolean;
  245. begin
  246. if not assigned(forcetempdef) then
  247. usedef:=p.returndef
  248. else
  249. usedef:=forcetempdef;
  250. { on darwin/i386, if a record has only one field and that field is a
  251. single or double, it has to be returned like a single/double }
  252. if (target_info.system in [system_i386_darwin,system_i386_iphonesim]) and
  253. ((usedef.typ=recorddef) or
  254. is_object(usedef)) and
  255. tabstractrecordsymtable(tabstractrecorddef(usedef).symtable).has_single_field(sym) and
  256. (sym.vardef.typ=floatdef) and
  257. (tfloatdef(sym.vardef).floattype in [s32real,s64real]) then
  258. usedef:=sym.vardef;
  259. handled:=set_common_funcretloc_info(p,usedef,retcgsize,result);
  260. { normally forcetempdef is passed straight through to
  261. set_common_funcretloc_info and that one will correctly determine whether
  262. the location is a temporary one, but that doesn't work here because we
  263. sometimes have to change the type }
  264. result.temporary:=assigned(forcetempdef);
  265. if handled then
  266. exit;
  267. { darwin/x86 requires that results < sizeof(aint) are sign/zero
  268. extended to sizeof(aint) }
  269. if (target_info.system in [system_i386_darwin,system_i386_iphonesim]) and
  270. (side=calleeside) and
  271. (result.intsize>0) and
  272. (result.intsize<sizeof(aint)) then
  273. begin
  274. result.def:=sinttype;
  275. result.intsize:=sizeof(aint);
  276. retcgsize:=OS_SINT;
  277. result.size:=retcgsize;
  278. end;
  279. { Return in FPU register? }
  280. if result.def.typ=floatdef then
  281. begin
  282. paraloc:=result.add_location;
  283. paraloc^.loc:=LOC_FPUREGISTER;
  284. paraloc^.register:=NR_FPU_RESULT_REG;
  285. paraloc^.size:=retcgsize;
  286. end
  287. else
  288. { Return in register }
  289. begin
  290. paraloc:=result.add_location;
  291. paraloc^.loc:=LOC_REGISTER;
  292. if retcgsize in [OS_64,OS_S64] then
  293. begin
  294. { low 32bits }
  295. if side=callerside then
  296. paraloc^.register:=NR_FUNCTION_RESULT64_LOW_REG
  297. else
  298. paraloc^.register:=NR_FUNCTION_RETURN64_LOW_REG;
  299. paraloc^.size:=OS_32;
  300. { high 32bits }
  301. paraloc:=result.add_location;
  302. paraloc^.loc:=LOC_REGISTER;
  303. if side=callerside then
  304. paraloc^.register:=NR_FUNCTION_RESULT64_HIGHER_REG
  305. else
  306. paraloc^.register:=NR_FUNCTION_RETURN64_HIGHER_REG;
  307. paraloc^.size:=OS_32;
  308. end
  309. else if retcgsize in [OS_32,OS_S32] then
  310. begin
  311. { low 16bits }
  312. if side=callerside then
  313. paraloc^.register:=NR_FUNCTION_RESULT32_LOW_REG
  314. else
  315. paraloc^.register:=NR_FUNCTION_RETURN32_LOW_REG;
  316. paraloc^.size:=OS_16;
  317. { high 16bits }
  318. paraloc:=result.add_location;
  319. paraloc^.loc:=LOC_REGISTER;
  320. if side=callerside then
  321. paraloc^.register:=NR_FUNCTION_RESULT32_HIGH_REG
  322. else
  323. paraloc^.register:=NR_FUNCTION_RETURN32_HIGH_REG;
  324. paraloc^.size:=OS_16;
  325. end
  326. else
  327. begin
  328. paraloc^.size:=retcgsize;
  329. if side=callerside then
  330. paraloc^.register:=newreg(R_INTREGISTER,RS_FUNCTION_RESULT_REG,cgsize2subreg(R_INTREGISTER,retcgsize))
  331. else
  332. paraloc^.register:=newreg(R_INTREGISTER,RS_FUNCTION_RETURN_REG,cgsize2subreg(R_INTREGISTER,retcgsize));
  333. end;
  334. end;
  335. end;
  336. procedure ti8086paramanager.create_stdcall_paraloc_info(p : tabstractprocdef; side: tcallercallee;paras:tparalist;var parasize:longint);
  337. var
  338. i : integer;
  339. hp : tparavarsym;
  340. paradef : tdef;
  341. paraloc : pcgparalocation;
  342. l,
  343. paralen,
  344. varalign : longint;
  345. paraalign : shortint;
  346. pushaddr : boolean;
  347. paracgsize : tcgsize;
  348. begin
  349. paraalign:=get_para_align(p.proccalloption);
  350. { we push Flags and CS as long
  351. to cope with the IRETD
  352. and we save 6 register + 4 selectors }
  353. if po_interrupt in p.procoptions then
  354. inc(parasize,8+6*4+4*2);
  355. { Offset is calculated like:
  356. sub esp,12
  357. mov [esp+8],para3
  358. mov [esp+4],para2
  359. mov [esp],para1
  360. call function
  361. That means for pushes the para with the
  362. highest offset (see para3) needs to be pushed first
  363. }
  364. if p.proccalloption in pushleftright_pocalls then
  365. i:=paras.count-1
  366. else
  367. i:=0;
  368. while ((p.proccalloption in pushleftright_pocalls) and (i>=0)) or
  369. (not(p.proccalloption in pushleftright_pocalls) and (i<=paras.count-1)) do
  370. begin
  371. hp:=tparavarsym(paras[i]);
  372. paradef:=hp.vardef;
  373. pushaddr:=push_addr_param(hp.varspez,paradef,p.proccalloption);
  374. if pushaddr then
  375. begin
  376. paralen:=sizeof(aint);
  377. paracgsize:=OS_ADDR;
  378. paradef:=getpointerdef(paradef);
  379. end
  380. else
  381. begin
  382. paralen:=push_size(hp.varspez,paradef,p.proccalloption);
  383. { darwin/x86 requires that parameters < sizeof(aint) are sign/ }
  384. { zero extended to sizeof(aint) }
  385. if (target_info.system in [system_i386_darwin,system_i386_iphonesim]) and
  386. (side = callerside) and
  387. (paralen > 0) and
  388. (paralen < sizeof(aint)) then
  389. begin
  390. paralen:=sizeof(aint);
  391. paracgsize:=OS_SINT;
  392. paradef:=sinttype;
  393. end
  394. else
  395. paracgsize:=def_cgsize(paradef);
  396. end;
  397. hp.paraloc[side].reset;
  398. hp.paraloc[side].size:=paracgsize;
  399. hp.paraloc[side].intsize:=paralen;
  400. hp.paraloc[side].def:=paradef;
  401. hp.paraloc[side].Alignment:=paraalign;
  402. { Copy to stack? }
  403. if (paracgsize=OS_NO) or
  404. (use_fixed_stack) then
  405. begin
  406. paraloc:=hp.paraloc[side].add_location;
  407. paraloc^.loc:=LOC_REFERENCE;
  408. paraloc^.size:=paracgsize;
  409. if side=callerside then
  410. paraloc^.reference.index:=NR_STACK_POINTER_REG
  411. else
  412. paraloc^.reference.index:=NR_FRAME_POINTER_REG;
  413. varalign:=used_align(size_2_align(paralen),paraalign,paraalign);
  414. { don't let push_size return 16, because then we can }
  415. { read past the end of the heap since the value is only }
  416. { 10 bytes long (JM) }
  417. if (paracgsize = OS_F80) and
  418. (target_info.system in [system_i386_darwin,system_i386_iphonesim]) then
  419. paralen:=16;
  420. paraloc^.reference.offset:=parasize;
  421. if side=calleeside then
  422. inc(paraloc^.reference.offset,target_info.first_parm_offset);
  423. parasize:=align(parasize+paralen,varalign);
  424. end
  425. else
  426. begin
  427. if paralen=0 then
  428. internalerror(200501163);
  429. while (paralen>0) do
  430. begin
  431. paraloc:=hp.paraloc[side].add_location;
  432. paraloc^.loc:=LOC_REFERENCE;
  433. { single and double need a single location }
  434. if (paracgsize in [OS_F64,OS_F32]) then
  435. begin
  436. paraloc^.size:=paracgsize;
  437. l:=paralen;
  438. end
  439. else
  440. begin
  441. { We can allocate at maximum 32 bits per location }
  442. if paralen>sizeof(aint) then
  443. l:=sizeof(aint)
  444. else
  445. l:=paralen;
  446. paraloc^.size:=int_cgsize(l);
  447. end;
  448. if (side=callerside) or
  449. (po_nostackframe in p.procoptions) then
  450. paraloc^.reference.index:=NR_STACK_POINTER_REG
  451. else
  452. paraloc^.reference.index:=NR_FRAME_POINTER_REG;
  453. varalign:=used_align(size_2_align(l),paraalign,paraalign);
  454. paraloc^.reference.offset:=parasize;
  455. if side=calleeside then
  456. if not(po_nostackframe in p.procoptions) then
  457. inc(paraloc^.reference.offset,target_info.first_parm_offset)
  458. else
  459. { return addres }
  460. inc(paraloc^.reference.offset,4);
  461. parasize:=align(parasize+l,varalign);
  462. dec(paralen,l);
  463. end;
  464. end;
  465. if p.proccalloption in pushleftright_pocalls then
  466. dec(i)
  467. else
  468. inc(i);
  469. end;
  470. end;
  471. procedure ti8086paramanager.create_register_paraloc_info(p : tabstractprocdef; side: tcallercallee;paras:tparalist;
  472. var parareg,parasize:longint);
  473. var
  474. hp : tparavarsym;
  475. paradef : tdef;
  476. paraloc : pcgparalocation;
  477. paracgsize : tcgsize;
  478. i : integer;
  479. l,
  480. paralen,
  481. varalign : longint;
  482. pushaddr : boolean;
  483. paraalign : shortint;
  484. pass : byte;
  485. begin
  486. if paras.count=0 then
  487. exit;
  488. paraalign:=get_para_align(p.proccalloption);
  489. { clean up here so we can later detect properly if a parameter has been
  490. assigned or not
  491. }
  492. for i:=0 to paras.count-1 do
  493. tparavarsym(paras[i]).paraloc[side].reset;
  494. { Register parameters are assigned from left to right,
  495. stack parameters from right to left so assign first the
  496. register parameters in a first pass, in the second
  497. pass all unhandled parameters are done }
  498. for pass:=1 to 2 do
  499. begin
  500. if pass=1 then
  501. i:=0
  502. else
  503. i:=paras.count-1;
  504. while true do
  505. begin
  506. hp:=tparavarsym(paras[i]);
  507. paradef:=hp.vardef;
  508. if not(assigned(hp.paraloc[side].location)) then
  509. begin
  510. pushaddr:=push_addr_param(hp.varspez,hp.vardef,p.proccalloption);
  511. if pushaddr then
  512. begin
  513. paralen:=sizeof(aint);
  514. paracgsize:=OS_ADDR;
  515. paradef:=getpointerdef(paradef);
  516. end
  517. else
  518. begin
  519. paralen:=push_size(hp.varspez,hp.vardef,p.proccalloption);
  520. paracgsize:=def_cgsize(hp.vardef);
  521. end;
  522. hp.paraloc[side].size:=paracgsize;
  523. hp.paraloc[side].intsize:=paralen;
  524. hp.paraloc[side].Alignment:=paraalign;
  525. hp.paraloc[side].def:=paradef;
  526. {
  527. EAX
  528. EDX
  529. ECX
  530. Stack
  531. Stack
  532. 64bit values,floats,arrays and records are always
  533. on the stack.
  534. In case of po_delphi_nested_cc, the parent frame pointer
  535. is also always passed on the stack.
  536. }
  537. if (parareg<=high(parasupregs)) and
  538. (paralen<=sizeof(aint)) and
  539. (not(hp.vardef.typ in [floatdef,recorddef,arraydef]) or
  540. pushaddr) and
  541. (not(vo_is_parentfp in hp.varoptions) or
  542. not(po_delphi_nested_cc in p.procoptions)) then
  543. begin
  544. if pass=1 then
  545. begin
  546. paraloc:=hp.paraloc[side].add_location;
  547. paraloc^.size:=paracgsize;
  548. paraloc^.loc:=LOC_REGISTER;
  549. paraloc^.register:=newreg(R_INTREGISTER,parasupregs[parareg],cgsize2subreg(R_INTREGISTER,paracgsize));
  550. inc(parareg);
  551. end;
  552. end
  553. else
  554. if pass=2 then
  555. begin
  556. { Copy to stack? }
  557. if (use_fixed_stack) or
  558. (paracgsize=OS_NO) then
  559. begin
  560. paraloc:=hp.paraloc[side].add_location;
  561. paraloc^.loc:=LOC_REFERENCE;
  562. paraloc^.size:=paracgsize;
  563. if side=callerside then
  564. paraloc^.reference.index:=NR_STACK_POINTER_REG
  565. else
  566. paraloc^.reference.index:=NR_FRAME_POINTER_REG;
  567. varalign:=used_align(size_2_align(paralen),paraalign,paraalign);
  568. paraloc^.reference.offset:=parasize;
  569. if side=calleeside then
  570. inc(paraloc^.reference.offset,target_info.first_parm_offset);
  571. parasize:=align(parasize+paralen,varalign);
  572. end
  573. else
  574. begin
  575. if paralen=0 then
  576. internalerror(200501163);
  577. while (paralen>0) do
  578. begin
  579. paraloc:=hp.paraloc[side].add_location;
  580. paraloc^.loc:=LOC_REFERENCE;
  581. { Extended and double need a single location }
  582. if (paracgsize in [OS_F64,OS_F32]) then
  583. begin
  584. paraloc^.size:=paracgsize;
  585. l:=paralen;
  586. end
  587. else
  588. begin
  589. { We can allocate at maximum 32 bits per location }
  590. if paralen>sizeof(aint) then
  591. l:=sizeof(aint)
  592. else
  593. l:=paralen;
  594. paraloc^.size:=int_cgsize(l);
  595. end;
  596. if side=callerside then
  597. paraloc^.reference.index:=NR_STACK_POINTER_REG
  598. else
  599. paraloc^.reference.index:=NR_FRAME_POINTER_REG;
  600. varalign:=used_align(size_2_align(l),paraalign,paraalign);
  601. paraloc^.reference.offset:=parasize;
  602. if side=calleeside then
  603. inc(paraloc^.reference.offset,target_info.first_parm_offset);
  604. parasize:=align(parasize+l,varalign);
  605. dec(paralen,l);
  606. end;
  607. end;
  608. end;
  609. end;
  610. case pass of
  611. 1:
  612. begin
  613. if i=paras.count-1 then
  614. break;
  615. inc(i);
  616. end;
  617. 2:
  618. begin
  619. if i=0 then
  620. break;
  621. dec(i);
  622. end;
  623. end;
  624. end;
  625. end;
  626. end;
  627. function ti8086paramanager.create_paraloc_info(p : tabstractprocdef; side: tcallercallee):longint;
  628. var
  629. parasize,
  630. parareg : longint;
  631. begin
  632. parasize:=0;
  633. parareg:=0;
  634. case p.proccalloption of
  635. pocall_register :
  636. create_register_paraloc_info(p,side,p.paras,parareg,parasize);
  637. pocall_internproc :
  638. begin
  639. { Use default calling }
  640. {$warnings off}
  641. if (pocall_default=pocall_register) then
  642. create_register_paraloc_info(p,side,p.paras,parareg,parasize)
  643. else
  644. create_stdcall_paraloc_info(p,side,p.paras,parasize);
  645. {$warnings on}
  646. end;
  647. else
  648. create_stdcall_paraloc_info(p,side,p.paras,parasize);
  649. end;
  650. create_funcretloc_info(p,side);
  651. result:=parasize;
  652. end;
  653. function ti8086paramanager.create_varargs_paraloc_info(p : tabstractprocdef; varargspara:tvarargsparalist):longint;
  654. var
  655. parasize : longint;
  656. begin
  657. parasize:=0;
  658. { calculate the registers for the normal parameters }
  659. create_stdcall_paraloc_info(p,callerside,p.paras,parasize);
  660. { append the varargs }
  661. create_stdcall_paraloc_info(p,callerside,varargspara,parasize);
  662. result:=parasize;
  663. end;
  664. procedure ti8086paramanager.createtempparaloc(list: TAsmList;calloption : tproccalloption;parasym : tparavarsym;can_use_final_stack_loc : boolean;var cgpara:TCGPara);
  665. begin
  666. { Never a need for temps when value is pushed (calls inside parameters
  667. will simply allocate even more stack space for their parameters) }
  668. if not(use_fixed_stack) then
  669. can_use_final_stack_loc:=true;
  670. inherited createtempparaloc(list,calloption,parasym,can_use_final_stack_loc,cgpara);
  671. end;
  672. begin
  673. paramanager:=ti8086paramanager.create;
  674. end.