cpupara.pas 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. {
  2. Copyright (c) 2002 by Florian Klaempfl
  3. PowerPC 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. unit cpupara;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. globtype,
  22. aasmtai,aasmdata,
  23. cpubase,
  24. symconst,symtype,symdef,symsym,
  25. paramgr,parabase,cgbase,cgutils;
  26. type
  27. tppcparamanager = class(tparamanager)
  28. function get_volatile_registers_int(calloption : tproccalloption):tcpuregisterset;override;
  29. function get_volatile_registers_fpu(calloption : tproccalloption):tcpuregisterset;override;
  30. function push_addr_param(varspez:tvarspez;def : tdef;calloption : tproccalloption) : boolean;override;
  31. procedure getintparaloc(calloption : tproccalloption; nr : longint;var cgpara:TCGPara);override;
  32. function create_paraloc_info(p : tabstractprocdef; side: tcallercallee):longint;override;
  33. function create_varargs_paraloc_info(p : tabstractprocdef; varargspara:tvarargsparalist):longint;override;
  34. function get_funcretloc(p : tabstractprocdef; side: tcallercallee; def: tdef): tcgpara;override;
  35. procedure create_funcretloc_info(p : tabstractprocdef; side: tcallercallee);
  36. private
  37. procedure init_values(var curintreg, curfloatreg, curmmreg: tsuperregister; var cur_stack_offset: aword);
  38. function create_paraloc_info_intern(p : tabstractprocdef; side: tcallercallee; paras:tparalist;
  39. var curintreg, curfloatreg, curmmreg: tsuperregister; var cur_stack_offset: aword; varargsparas: boolean):longint;
  40. function parseparaloc(p : tparavarsym;const s : string) : boolean;override;
  41. end;
  42. implementation
  43. uses
  44. verbose,systems,
  45. defutil,symtable,
  46. procinfo,cpupi;
  47. function tppcparamanager.get_volatile_registers_int(calloption : tproccalloption):tcpuregisterset;
  48. begin
  49. if (target_info.system = system_powerpc_darwin) then
  50. result := [RS_R0,RS_R2..RS_R12]
  51. else
  52. result := [RS_R0,RS_R3..RS_R12];
  53. end;
  54. function tppcparamanager.get_volatile_registers_fpu(calloption : tproccalloption):tcpuregisterset;
  55. begin
  56. case target_info.abi of
  57. abi_powerpc_aix,
  58. abi_powerpc_sysv:
  59. result := [RS_F0..RS_F13];
  60. else
  61. internalerror(2003091401);
  62. end;
  63. end;
  64. procedure tppcparamanager.getintparaloc(calloption : tproccalloption; nr : longint;var cgpara:TCGPara);
  65. var
  66. paraloc : pcgparalocation;
  67. begin
  68. cgpara.reset;
  69. cgpara.size:=OS_ADDR;
  70. cgpara.intsize:=sizeof(pint);
  71. cgpara.alignment:=get_para_align(calloption);
  72. paraloc:=cgpara.add_location;
  73. with paraloc^ do
  74. begin
  75. size:=OS_INT;
  76. if (nr<=8) then
  77. begin
  78. if nr=0 then
  79. internalerror(200309271);
  80. loc:=LOC_REGISTER;
  81. register:=newreg(R_INTREGISTER,RS_R2+nr,R_SUBWHOLE);
  82. end
  83. else
  84. begin
  85. loc:=LOC_REFERENCE;
  86. paraloc^.reference.index:=NR_STACK_POINTER_REG;
  87. if (target_info.abi <> abi_powerpc_aix) then
  88. reference.offset:=sizeof(pint)*(nr-8)
  89. else
  90. reference.offset:=sizeof(pint)*(nr);
  91. end;
  92. end;
  93. end;
  94. function getparaloc(p : tdef) : tcgloc;
  95. begin
  96. { Later, the LOC_REFERENCE is in most cases changed into LOC_REGISTER
  97. if push_addr_param for the def is true
  98. }
  99. case p.typ of
  100. orddef:
  101. result:=LOC_REGISTER;
  102. floatdef:
  103. result:=LOC_FPUREGISTER;
  104. enumdef:
  105. result:=LOC_REGISTER;
  106. pointerdef:
  107. result:=LOC_REGISTER;
  108. formaldef:
  109. result:=LOC_REGISTER;
  110. classrefdef:
  111. result:=LOC_REGISTER;
  112. procvardef:
  113. if (target_info.abi = abi_powerpc_aix) or
  114. (p.size = sizeof(pint)) then
  115. result:=LOC_REGISTER
  116. else
  117. result:=LOC_REFERENCE;
  118. recorddef:
  119. if not(target_info.system in systems_aix) and
  120. ((target_info.abi<>abi_powerpc_aix) or
  121. ((p.size >= 3) and
  122. ((p.size mod 4) <> 0))) then
  123. result:=LOC_REFERENCE
  124. else
  125. result:=LOC_REGISTER;
  126. objectdef:
  127. if is_object(p) then
  128. result:=LOC_REFERENCE
  129. else
  130. result:=LOC_REGISTER;
  131. stringdef:
  132. if is_shortstring(p) or is_longstring(p) then
  133. result:=LOC_REFERENCE
  134. else
  135. result:=LOC_REGISTER;
  136. filedef:
  137. result:=LOC_REGISTER;
  138. arraydef:
  139. result:=LOC_REFERENCE;
  140. setdef:
  141. if is_smallset(p) then
  142. result:=LOC_REGISTER
  143. else
  144. result:=LOC_REFERENCE;
  145. variantdef:
  146. result:=LOC_REFERENCE;
  147. { avoid problems with errornous definitions }
  148. errordef:
  149. result:=LOC_REGISTER;
  150. else
  151. internalerror(2002071001);
  152. end;
  153. end;
  154. function tppcparamanager.push_addr_param(varspez:tvarspez;def : tdef;calloption : tproccalloption) : boolean;
  155. begin
  156. result:=false;
  157. { var,out,constref always require address }
  158. if varspez in [vs_var,vs_out,vs_constref] then
  159. begin
  160. result:=true;
  161. exit;
  162. end;
  163. case def.typ of
  164. variantdef,
  165. formaldef :
  166. result:=true;
  167. { regular procvars must be passed by value, because you cannot pass
  168. the address of a local stack location when calling e.g.
  169. pthread_create with the address of a function (first of all it
  170. expects the address of the function to execute and not the address
  171. of a memory location containing that address, and secondly if you
  172. first store the address on the stack and then pass the address of
  173. this stack location, then this stack location may no longer be
  174. valid when the newly started thread accesses it.
  175. However, for "procedure of object" we must use the same calling
  176. convention as for "8 byte record" due to the need for
  177. interchangeability with the TMethod record type.
  178. }
  179. procvardef :
  180. result:=
  181. (target_info.abi <> abi_powerpc_aix) and
  182. (def.size <> sizeof(pint));
  183. recorddef :
  184. result :=
  185. (target_info.abi<>abi_powerpc_aix) or
  186. ((varspez = vs_const) and
  187. ((calloption = pocall_mwpascal) or
  188. (not (calloption in [pocall_cdecl,pocall_cppdecl]) and
  189. (def.size > 8)
  190. )
  191. )
  192. );
  193. arraydef:
  194. result:=(tarraydef(def).highrange>=tarraydef(def).lowrange) or
  195. is_open_array(def) or
  196. is_array_of_const(def) or
  197. is_array_constructor(def);
  198. objectdef :
  199. result:=is_object(def);
  200. setdef :
  201. result:=not is_smallset(def);
  202. stringdef :
  203. result:=tstringdef(def).stringtype in [st_shortstring,st_longstring];
  204. end;
  205. end;
  206. procedure tppcparamanager.init_values(var curintreg, curfloatreg, curmmreg: tsuperregister; var cur_stack_offset: aword);
  207. begin
  208. case target_info.abi of
  209. abi_powerpc_aix:
  210. cur_stack_offset:=24;
  211. abi_powerpc_sysv:
  212. cur_stack_offset:=8;
  213. else
  214. internalerror(2003051901);
  215. end;
  216. curintreg:=RS_R3;
  217. curfloatreg:=RS_F1;
  218. curmmreg:=RS_M1;
  219. end;
  220. procedure tppcparamanager.create_funcretloc_info(p : tabstractprocdef; side: tcallercallee);
  221. begin
  222. p.funcretloc[side]:=get_funcretloc(p,side,p.returndef);
  223. end;
  224. function tppcparamanager.get_funcretloc(p : tabstractprocdef; side: tcallercallee; def: tdef): tcgpara;
  225. var
  226. paraloc : pcgparalocation;
  227. retcgsize : tcgsize;
  228. begin
  229. if set_common_funcretloc_info(p,def,retcgsize,result) then
  230. exit;
  231. paraloc:=result.add_location;
  232. { Return in FPU register? }
  233. if def.typ=floatdef then
  234. begin
  235. paraloc^.loc:=LOC_FPUREGISTER;
  236. paraloc^.register:=NR_FPU_RESULT_REG;
  237. paraloc^.size:=retcgsize;
  238. end
  239. else
  240. { Return in register }
  241. begin
  242. if retcgsize in [OS_64,OS_S64] then
  243. begin
  244. { low 32bits }
  245. paraloc^.loc:=LOC_REGISTER;
  246. if side=callerside then
  247. paraloc^.register:=NR_FUNCTION_RESULT64_HIGH_REG
  248. else
  249. paraloc^.register:=NR_FUNCTION_RETURN64_HIGH_REG;
  250. paraloc^.size:=OS_32;
  251. { high 32bits }
  252. paraloc:=result.add_location;
  253. paraloc^.loc:=LOC_REGISTER;
  254. if side=callerside then
  255. paraloc^.register:=NR_FUNCTION_RESULT64_LOW_REG
  256. else
  257. paraloc^.register:=NR_FUNCTION_RETURN64_LOW_REG;
  258. paraloc^.size:=OS_32;
  259. end
  260. else
  261. begin
  262. paraloc^.loc:=LOC_REGISTER;
  263. if side=callerside then
  264. paraloc^.register:=newreg(R_INTREGISTER,RS_FUNCTION_RESULT_REG,cgsize2subreg(R_INTREGISTER,retcgsize))
  265. else
  266. paraloc^.register:=newreg(R_INTREGISTER,RS_FUNCTION_RETURN_REG,cgsize2subreg(R_INTREGISTER,retcgsize));
  267. paraloc^.size:=retcgsize;
  268. end;
  269. end;
  270. end;
  271. function tppcparamanager.create_paraloc_info(p : tabstractprocdef; side: tcallercallee):longint;
  272. var
  273. cur_stack_offset: aword;
  274. curintreg, curfloatreg, curmmreg: tsuperregister;
  275. begin
  276. init_values(curintreg,curfloatreg,curmmreg,cur_stack_offset);
  277. result := create_paraloc_info_intern(p,side,p.paras,curintreg,curfloatreg,curmmreg,cur_stack_offset,false);
  278. create_funcretloc_info(p,side);
  279. end;
  280. function tppcparamanager.create_paraloc_info_intern(p : tabstractprocdef; side: tcallercallee; paras:tparalist;
  281. var curintreg, curfloatreg, curmmreg: tsuperregister; var cur_stack_offset: aword; varargsparas: boolean):longint;
  282. var
  283. stack_offset: longint;
  284. paralen: aint;
  285. nextintreg,nextfloatreg,nextmmreg, maxfpureg : tsuperregister;
  286. paradef : tdef;
  287. paraloc : pcgparalocation;
  288. i : integer;
  289. hp : tparavarsym;
  290. loc : tcgloc;
  291. paracgsize: tcgsize;
  292. sym: tfieldvarsym;
  293. begin
  294. {$ifdef extdebug}
  295. if po_explicitparaloc in p.procoptions then
  296. internalerror(200411141);
  297. {$endif extdebug}
  298. result:=0;
  299. nextintreg := curintreg;
  300. nextfloatreg := curfloatreg;
  301. nextmmreg := curmmreg;
  302. stack_offset := cur_stack_offset;
  303. case target_info.abi of
  304. abi_powerpc_aix:
  305. maxfpureg := RS_F13;
  306. abi_powerpc_sysv:
  307. maxfpureg := RS_F8;
  308. else internalerror(2004070912);
  309. end;
  310. for i:=0 to paras.count-1 do
  311. begin
  312. hp:=tparavarsym(paras[i]);
  313. paradef := hp.vardef;
  314. { Syscall for Morphos can have already a paraloc set }
  315. if (vo_has_explicit_paraloc in hp.varoptions) then
  316. begin
  317. if not(vo_is_syscall_lib in hp.varoptions) then
  318. internalerror(200412153);
  319. continue;
  320. end;
  321. hp.paraloc[side].reset;
  322. { currently only support C-style array of const }
  323. if (p.proccalloption in [pocall_cdecl,pocall_cppdecl,pocall_mwpascal]) and
  324. is_array_of_const(paradef) then
  325. begin
  326. paraloc:=hp.paraloc[side].add_location;
  327. { hack: the paraloc must be valid, but is not actually used }
  328. paraloc^.loc := LOC_REGISTER;
  329. paraloc^.register := NR_R0;
  330. paraloc^.size := OS_ADDR;
  331. break;
  332. end;
  333. if push_addr_param(hp.varspez,paradef,p.proccalloption) then
  334. begin
  335. paradef:=getpointerdef(paradef);
  336. loc:=LOC_REGISTER;
  337. paracgsize := OS_ADDR;
  338. paralen := tcgsize2size[OS_ADDR];
  339. end
  340. else
  341. begin
  342. if not is_special_array(paradef) then
  343. paralen := paradef.size
  344. else
  345. paralen := tcgsize2size[def_cgsize(paradef)];
  346. if (target_info.abi = abi_powerpc_aix) and
  347. (paradef.typ = recorddef) and
  348. (hp.varspez in [vs_value,vs_const]) then
  349. begin
  350. { if a record has only one field and that field is }
  351. { non-composite (not array or record), it must be }
  352. { passed according to the rules of that type. }
  353. if tabstractrecordsymtable(tabstractrecorddef(paradef).symtable).has_single_field(sym) and
  354. ((sym.vardef.typ=floatdef) or
  355. ((target_info.system=system_powerpc_darwin) and
  356. (sym.vardef.typ in [orddef,enumdef]))) then
  357. begin
  358. paradef:=sym.vardef;
  359. paracgsize:=def_cgsize(paradef);
  360. end
  361. else
  362. begin
  363. paracgsize := int_cgsize(paralen);
  364. end;
  365. end
  366. else
  367. begin
  368. paracgsize:=def_cgsize(paradef);
  369. { for things like formaldef }
  370. if (paracgsize=OS_NO) then
  371. begin
  372. paracgsize:=OS_ADDR;
  373. paralen := tcgsize2size[OS_ADDR];
  374. end;
  375. end
  376. end;
  377. loc := getparaloc(paradef);
  378. if varargsparas and
  379. (target_info.abi = abi_powerpc_aix) and
  380. (paradef.typ = floatdef) then
  381. begin
  382. loc := LOC_REGISTER;
  383. if paracgsize = OS_F64 then
  384. paracgsize := OS_64
  385. else
  386. paracgsize := OS_32;
  387. end;
  388. hp.paraloc[side].alignment:=std_param_align;
  389. hp.paraloc[side].size:=paracgsize;
  390. hp.paraloc[side].intsize:=paralen;
  391. hp.paraloc[side].def:=paradef;
  392. if (target_info.abi = abi_powerpc_aix) and
  393. (paradef.typ in [recorddef,arraydef]) then
  394. hp.paraloc[side].composite:=true;
  395. {$ifndef cpu64bitaddr}
  396. if (target_info.abi=abi_powerpc_sysv) and
  397. is_64bit(paradef) and
  398. odd(nextintreg-RS_R3) then
  399. inc(nextintreg);
  400. {$endif not cpu64bitaddr}
  401. if (paralen = 0) then
  402. if (paradef.typ = recorddef) then
  403. begin
  404. paraloc:=hp.paraloc[side].add_location;
  405. paraloc^.loc := LOC_VOID;
  406. end
  407. else
  408. internalerror(2005011310);
  409. { can become < 0 for e.g. 3-byte records }
  410. while (paralen > 0) do
  411. begin
  412. paraloc:=hp.paraloc[side].add_location;
  413. { In case of po_delphi_nested_cc, the parent frame pointer
  414. is always passed on the stack. }
  415. if (loc = LOC_REGISTER) and
  416. (nextintreg <= RS_R10) and
  417. (not(vo_is_parentfp in hp.varoptions) or
  418. not(po_delphi_nested_cc in p.procoptions)) then
  419. begin
  420. paraloc^.loc := loc;
  421. { make sure we don't lose whether or not the type is signed }
  422. if (paradef.typ <> orddef) then
  423. paracgsize := int_cgsize(paralen);
  424. if (paracgsize in [OS_NO,OS_64,OS_S64,OS_128,OS_S128]) then
  425. paraloc^.size := OS_INT
  426. else
  427. paraloc^.size := paracgsize;
  428. { aix requires that record data stored in parameter
  429. registers is left-aligned }
  430. if (target_info.system in systems_aix) and
  431. (paradef.typ = recorddef) and
  432. (tcgsize2size[paraloc^.size] <> sizeof(aint)) then
  433. begin
  434. paraloc^.shiftval := (sizeof(aint)-tcgsize2size[paraloc^.size])*(-8);
  435. paraloc^.size := OS_INT;
  436. end;
  437. paraloc^.register:=newreg(R_INTREGISTER,nextintreg,R_SUBNONE);
  438. inc(nextintreg);
  439. dec(paralen,tcgsize2size[paraloc^.size]);
  440. if target_info.abi=abi_powerpc_aix then
  441. inc(stack_offset,align(tcgsize2size[paraloc^.size],4));
  442. end
  443. else if (loc = LOC_FPUREGISTER) and
  444. (nextfloatreg <= maxfpureg) then
  445. begin
  446. paraloc^.loc:=loc;
  447. paraloc^.size := paracgsize;
  448. paraloc^.register:=newreg(R_FPUREGISTER,nextfloatreg,R_SUBWHOLE);
  449. inc(nextfloatreg);
  450. dec(paralen,tcgsize2size[paraloc^.size]);
  451. { if nextfpureg > maxfpureg, all intregs are already used, since there }
  452. { are less of those available for parameter passing in the AIX abi }
  453. if target_info.abi=abi_powerpc_aix then
  454. {$ifndef cpu64bitaddr}
  455. if (paracgsize = OS_F32) then
  456. begin
  457. inc(stack_offset,4);
  458. if (nextintreg < RS_R11) then
  459. inc(nextintreg);
  460. end
  461. else
  462. begin
  463. inc(stack_offset,8);
  464. if (nextintreg < RS_R10) then
  465. inc(nextintreg,2)
  466. else
  467. nextintreg := RS_R11;
  468. end;
  469. {$else not cpu64bitaddr}
  470. begin
  471. inc(stack_offset,tcgsize2size[paracgsize]);
  472. if (nextintreg < RS_R11) then
  473. inc(nextintreg);
  474. end;
  475. {$endif not cpu64bitaddr}
  476. end
  477. else { LOC_REFERENCE }
  478. begin
  479. paraloc^.loc:=LOC_REFERENCE;
  480. case loc of
  481. LOC_FPUREGISTER:
  482. paraloc^.size:=int_float_cgsize(paralen);
  483. LOC_REGISTER,
  484. LOC_REFERENCE:
  485. paraloc^.size:=int_cgsize(paralen);
  486. else
  487. internalerror(2006011101);
  488. end;
  489. if (side = callerside) then
  490. paraloc^.reference.index:=NR_STACK_POINTER_REG
  491. else
  492. begin
  493. paraloc^.reference.index:=NR_R12;
  494. tppcprocinfo(current_procinfo).needs_frame_pointer := true;
  495. end;
  496. if not((target_info.system in systems_aix) and
  497. (paradef.typ=recorddef)) and
  498. (target_info.abi = abi_powerpc_aix) and
  499. (hp.paraloc[side].intsize < 3) then
  500. paraloc^.reference.offset:=stack_offset+(4-paralen)
  501. else
  502. paraloc^.reference.offset:=stack_offset;
  503. inc(stack_offset,align(paralen,4));
  504. while (paralen > 0) and
  505. (nextintreg < RS_R11) do
  506. begin
  507. inc(nextintreg);
  508. dec(paralen,sizeof(pint));
  509. end;
  510. paralen := 0;
  511. end;
  512. end;
  513. end;
  514. curintreg:=nextintreg;
  515. curfloatreg:=nextfloatreg;
  516. curmmreg:=nextmmreg;
  517. cur_stack_offset:=stack_offset;
  518. result:=stack_offset;
  519. end;
  520. function tppcparamanager.create_varargs_paraloc_info(p : tabstractprocdef; varargspara:tvarargsparalist):longint;
  521. var
  522. cur_stack_offset: aword;
  523. parasize, l: longint;
  524. curintreg, firstfloatreg, curfloatreg, curmmreg: tsuperregister;
  525. i : integer;
  526. hp: tparavarsym;
  527. paraloc: pcgparalocation;
  528. begin
  529. init_values(curintreg,curfloatreg,curmmreg,cur_stack_offset);
  530. firstfloatreg:=curfloatreg;
  531. result:=create_paraloc_info_intern(p,callerside,p.paras,curintreg,curfloatreg,curmmreg,cur_stack_offset, false);
  532. if (p.proccalloption in [pocall_cdecl,pocall_cppdecl,pocall_mwpascal]) then
  533. { just continue loading the parameters in the registers }
  534. begin
  535. result:=create_paraloc_info_intern(p,callerside,varargspara,curintreg,curfloatreg,curmmreg,cur_stack_offset,true);
  536. { varargs routines have to reserve at least 32 bytes for the AIX abi }
  537. if (target_info.abi = abi_powerpc_aix) and
  538. (result < 32) then
  539. result := 32;
  540. end
  541. else
  542. begin
  543. parasize:=cur_stack_offset;
  544. for i:=0 to varargspara.count-1 do
  545. begin
  546. hp:=tparavarsym(varargspara[i]);
  547. hp.paraloc[callerside].alignment:=4;
  548. paraloc:=hp.paraloc[callerside].add_location;
  549. paraloc^.loc:=LOC_REFERENCE;
  550. paraloc^.size:=def_cgsize(hp.vardef);
  551. paraloc^.reference.index:=NR_STACK_POINTER_REG;
  552. l:=push_size(hp.varspez,hp.vardef,p.proccalloption);
  553. paraloc^.reference.offset:=parasize;
  554. parasize:=parasize+l;
  555. end;
  556. result:=parasize;
  557. end;
  558. if curfloatreg<>firstfloatreg then
  559. include(varargspara.varargsinfo,va_uses_float_reg);
  560. end;
  561. function tppcparamanager.parseparaloc(p : tparavarsym;const s : string) : boolean;
  562. var
  563. paraloc : pcgparalocation;
  564. paracgsize : tcgsize;
  565. begin
  566. result:=false;
  567. case target_info.system of
  568. system_powerpc_morphos:
  569. begin
  570. paracgsize:=def_cgsize(p.vardef);
  571. p.paraloc[callerside].alignment:=4;
  572. p.paraloc[callerside].size:=paracgsize;
  573. p.paraloc[callerside].intsize:=tcgsize2size[paracgsize];
  574. paraloc:=p.paraloc[callerside].add_location;
  575. paraloc^.loc:=LOC_REFERENCE;
  576. paraloc^.size:=paracgsize;
  577. paraloc^.reference.index:=newreg(R_INTREGISTER,RS_R2,R_SUBWHOLE);
  578. { pattern is always uppercase'd }
  579. if s='D0' then
  580. paraloc^.reference.offset:=0
  581. else if s='D1' then
  582. paraloc^.reference.offset:=4
  583. else if s='D2' then
  584. paraloc^.reference.offset:=8
  585. else if s='D3' then
  586. paraloc^.reference.offset:=12
  587. else if s='D4' then
  588. paraloc^.reference.offset:=16
  589. else if s='D5' then
  590. paraloc^.reference.offset:=20
  591. else if s='D6' then
  592. paraloc^.reference.offset:=24
  593. else if s='D7' then
  594. paraloc^.reference.offset:=28
  595. else if s='A0' then
  596. paraloc^.reference.offset:=32
  597. else if s='A1' then
  598. paraloc^.reference.offset:=36
  599. else if s='A2' then
  600. paraloc^.reference.offset:=40
  601. else if s='A3' then
  602. paraloc^.reference.offset:=44
  603. else if s='A4' then
  604. paraloc^.reference.offset:=48
  605. else if s='A5' then
  606. paraloc^.reference.offset:=52
  607. { 'A6' (offset 56) is used by mossyscall as libbase, so API
  608. never passes parameters in it,
  609. Indeed, but this allows to declare libbase either explicitly
  610. or let the compiler insert it }
  611. else if s='A6' then
  612. paraloc^.reference.offset:=56
  613. { 'A7' is the stack pointer on 68k, can't be overwritten
  614. by API calls, so it has no offset }
  615. { 'R12' is special, used internally to support r12base sysv
  616. calling convention }
  617. else if s='R12' then
  618. begin
  619. paraloc^.loc:=LOC_REGISTER;
  620. paraloc^.size:=OS_ADDR;
  621. paraloc^.register:=NR_R12;
  622. end
  623. else
  624. exit;
  625. { copy to callee side }
  626. p.paraloc[calleeside].add_location^:=paraloc^;
  627. end;
  628. else
  629. internalerror(200404182);
  630. end;
  631. result:=true;
  632. end;
  633. begin
  634. paramanager:=tppcparamanager.create;
  635. end.