t_wii.pas 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. {
  2. Copyright (c) 2011 by Francesco Lombardi
  3. This unit implements support import, export, link routines
  4. for the Wii (PowerPC) target
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit t_wii;
  19. {$i fpcdefs.inc}
  20. interface
  21. implementation
  22. uses
  23. aasmbase,
  24. SysUtils,
  25. cutils,cfileutl,cclasses,
  26. globtype,globals,systems,verbose,script,fmodule,i_wii,link;
  27. type
  28. TlinkerWii=class(texternallinker)
  29. private
  30. Function WriteResponseFile: Boolean;
  31. public
  32. constructor Create; override;
  33. procedure SetDefaultInfo; override;
  34. function MakeExecutable:boolean; override;
  35. end;
  36. {****************************************************************************
  37. TLinkerWii
  38. ****************************************************************************}
  39. Constructor TLinkerWii.Create;
  40. begin
  41. Inherited Create;
  42. SharedLibFiles.doubles:=true;
  43. StaticLibFiles.doubles:=true;
  44. end;
  45. procedure TLinkerWii.SetDefaultInfo;
  46. begin
  47. with Info do
  48. begin
  49. ExeCmd[1]:='ld -g $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP -L. -o $EXE -T $RES';
  50. end;
  51. end;
  52. Function TLinkerWii.WriteResponseFile : Boolean;
  53. Var
  54. linkres : TLinkRes;
  55. i : longint;
  56. HPath : TCmdStrListItem;
  57. s,s1,s2 : TCmdStr;
  58. linklibc,
  59. linklibgcc : boolean;
  60. found1,
  61. found2 : boolean;
  62. begin
  63. WriteResponseFile:=False;
  64. linklibc:=(SharedLibFiles.Find('c')<>nil);
  65. linklibgcc:=(SharedLibFiles.Find('gcc')<>nil);
  66. LinkRes:=TLinkRes.Create(outputexedir+Info.ResName);
  67. { Write path to search libraries }
  68. HPath:=TCmdStrListItem(current_module.locallibrarysearchpath.First);
  69. while assigned(HPath) do
  70. begin
  71. s:=HPath.Str;
  72. if (cs_link_on_target in current_settings.globalswitches) then
  73. s:=ScriptFixFileName(s);
  74. LinkRes.Add('-L'+s);
  75. HPath:=TCmdStrListItem(HPath.Next);
  76. end;
  77. HPath:=TCmdStrListItem(LibrarySearchPath.First);
  78. while assigned(HPath) do
  79. begin
  80. s:=HPath.Str;
  81. if s<>'' then
  82. LinkRes.Add('SEARCH_DIR('+(maybequoted(s))+')');
  83. HPath:=TCmdStrListItem(HPath.Next);
  84. end;
  85. LinkRes.Add('INPUT (');
  86. { add objectfiles, start with prt0 always }
  87. // s:=FindObjectFile('prt0','',false);
  88. // LinkRes.AddFileName(s);
  89. { try to add crti and crtbegin if linking to C }
  90. if linklibc then
  91. begin
  92. if librarysearchpath.FindFile('ecrti.o',false,s) then
  93. LinkRes.AddFileName(s);
  94. end;
  95. if linklibgcc then
  96. begin
  97. if librarysearchpath.FindFile('crtbegin.o',false,s) then
  98. LinkRes.AddFileName(s);
  99. end;
  100. if linklibc or linklibgcc then
  101. begin
  102. if librarysearchpath.FindFile('crtmain.o',false,s) then
  103. LinkRes.AddFileName(s);
  104. end;
  105. while not ObjectFiles.Empty do
  106. begin
  107. s:=ObjectFiles.GetFirst;
  108. if s<>'' then
  109. begin
  110. { vlink doesn't use SEARCH_DIR for object files }
  111. if not(cs_link_on_target in current_settings.globalswitches) then
  112. s:=FindObjectFile(s,'',false);
  113. LinkRes.AddFileName((maybequoted(s)));
  114. end;
  115. end;
  116. { Write staticlibraries }
  117. if not StaticLibFiles.Empty then
  118. begin
  119. { vlink doesn't need, and doesn't support GROUP }
  120. if (cs_link_on_target in current_settings.globalswitches) then
  121. begin
  122. LinkRes.Add(')');
  123. LinkRes.Add('GROUP(');
  124. end;
  125. while not StaticLibFiles.Empty do
  126. begin
  127. S:=StaticLibFiles.GetFirst;
  128. LinkRes.AddFileName((maybequoted(s)));
  129. end;
  130. end;
  131. if (cs_link_on_target in current_settings.globalswitches) then
  132. begin
  133. LinkRes.Add(')');
  134. { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
  135. here to be sure that it gets linked this is needed for glibc2 systems (PFV) }
  136. linklibc:=false;
  137. linklibgcc:=false;
  138. while not SharedLibFiles.Empty do
  139. begin
  140. S:=SharedLibFiles.GetFirst;
  141. if s<>'c' then
  142. begin
  143. i:=Pos(target_info.sharedlibext,S);
  144. if i>0 then
  145. Delete(S,i,255);
  146. LinkRes.Add('-l'+s);
  147. end
  148. else
  149. begin
  150. LinkRes.Add('-l'+s);
  151. linklibc:=true;
  152. linklibgcc:=true;
  153. end;
  154. end;
  155. { be sure that libc&libgcc is the last lib }
  156. if linklibgcc then
  157. begin
  158. LinkRes.Add('-lgcc');
  159. end;
  160. if linklibc then
  161. begin
  162. LinkRes.Add('-lc');
  163. end;
  164. end
  165. else
  166. begin
  167. while not SharedLibFiles.Empty do
  168. begin
  169. S:=SharedLibFiles.GetFirst;
  170. LinkRes.Add('lib'+s+target_info.staticlibext);
  171. end;
  172. LinkRes.Add(')');
  173. end;
  174. { objects which must be at the end }
  175. if linklibgcc then
  176. begin
  177. found1:=librarysearchpath.FindFile('crtend.o',false,s1);
  178. if found1 then
  179. begin
  180. LinkRes.Add('INPUT(');
  181. if found1 then
  182. LinkRes.AddFileName(s1);
  183. LinkRes.Add(')');
  184. end;
  185. end;
  186. if linklibc then
  187. begin
  188. found2:=librarysearchpath.FindFile('ecrtn.o',false,s2);
  189. if found2 then
  190. begin
  191. LinkRes.Add('INPUT(');
  192. if found2 then
  193. LinkRes.AddFileName(s2);
  194. LinkRes.Add(')');
  195. end;
  196. end;
  197. with linkres do
  198. begin
  199. Add('/*');
  200. Add(' * Linkscript for Wii');
  201. Add(' */');
  202. Add('');
  203. Add('OUTPUT_FORMAT("elf32-powerpc", "elf32-powerpc", "elf32-powerpc");');
  204. Add('OUTPUT_ARCH(powerpc:common);');
  205. Add('EXTERN(_start);');
  206. Add('ENTRY(_start);');
  207. Add('');
  208. Add('PHDRS');
  209. Add('{');
  210. Add(' stub PT_LOAD FLAGS(5);');
  211. Add(' text PT_LOAD FLAGS(5);');
  212. Add(' data PT_LOAD FLAGS(6);');
  213. Add('}');
  214. Add('');
  215. Add('SECTIONS');
  216. Add('{');
  217. Add(' /* stub is loaded at physical address 0x00003400 (though both 0x80003400 and 0x00003400 are equivalent for IOS) */');
  218. Add(' /* This can also be used to load an arbitrary standalone stub at an arbitrary address in memory, for any purpose */');
  219. Add(' /* Use -Wl,--section-start,.stub=0xADDRESS to change */');
  220. Add(' . = 0x00003400;');
  221. Add('');
  222. Add(' .stub :');
  223. Add(' {');
  224. Add(' KEEP(*(.stub))');
  225. Add(' } :stub = 0');
  226. Add('');
  227. Add(' /* default base address */');
  228. Add(' /* use -Wl,--section-start,.init=0xADDRESS to change */');
  229. Add(' . = 0x80004000;');
  230. Add('');
  231. Add(' /* Program */');
  232. Add(' .init :');
  233. Add(' {');
  234. Add(' KEEP (*crt0.o(*.init))');
  235. Add(' KEEP (*(.init))');
  236. Add(' } :text = 0');
  237. Add(' .plt : { *(.plt) }');
  238. Add(' .interp : { *(.interp) }');
  239. Add(' .hash : { *(.hash) }');
  240. Add(' .dynsym : { *(.dynsym) }');
  241. Add(' .dynstr : { *(.dynstr) }');
  242. Add(' .gnu.version : { *(.gnu.version) }');
  243. Add(' .gnu.version_d : { *(.gnu.version_d) }');
  244. Add(' .gnu.version_r : { *(.gnu.version_r) }');
  245. Add(' .rel.init : { *(.rel.init) }');
  246. Add(' .rela.init : { *(.rela.init) }');
  247. Add(' .rel.text : { *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*) }');
  248. Add(' .rela.text : { *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*) }');
  249. Add(' .rel.fini : { *(.rel.fini) }');
  250. Add(' .rela.fini : { *(.rela.fini) }');
  251. Add(' .rel.rodata : { *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*) }');
  252. Add(' .rela.rodata : { *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*) }');
  253. Add(' .rel.data : { *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*) }');
  254. Add(' .rela.data : { *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*) }');
  255. Add(' .rel.tdata : { *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*) }');
  256. Add(' .rela.tdata : { *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*) }');
  257. Add(' .rel.tbss : { *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*) }');
  258. Add(' .rela.tbss : { *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*) }');
  259. Add(' .rel.ctors : { *(.rel.ctors) }');
  260. Add(' .rela.ctors : { *(.rela.ctors) }');
  261. Add(' .rel.dtors : { *(.rel.dtors) }');
  262. Add(' .rela.dtors : { *(.rela.dtors) }');
  263. Add(' .rel.got : { *(.rel.got) }');
  264. Add(' .rela.got : { *(.rela.got) }');
  265. Add(' .rela.got1 : { *(.rela.got1) }');
  266. Add(' .rela.got2 : { *(.rela.got2) }');
  267. Add(' .rel.sdata : { *(.rel.sdata .rel.sdata.* .rel.gnu.linkonce.s.*) }');
  268. Add(' .rela.sdata : { *(.rela.sdata .rela.sdata.* .rela.gnu.linkonce.s.*) }');
  269. Add(' .rel.sbss : { *(.rel.sbss .rel.sbss.* .rel.gnu.linkonce.sb.*) }');
  270. Add(' .rela.sbss : { *(.rela.sbss .rela.sbss.* .rel.gnu.linkonce.sb.*) }');
  271. Add(' .rel.sdata2 : { *(.rel.sdata2 .rel.sdata2.* .rel.gnu.linkonce.s2.*) }');
  272. Add(' .rela.sdata2 : { *(.rela.sdata2 .rela.sdata2.* .rela.gnu.linkonce.s2.*) }');
  273. Add(' .rel.sbss2 : { *(.rel.sbss2 .rel.sbss2.* .rel.gnu.linkonce.sb2.*) }');
  274. Add(' .rela.sbss2 : { *(.rela.sbss2 .rela.sbss2.* .rela.gnu.linkonce.sb2.*) }');
  275. Add(' .rel.bss : { *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*) }');
  276. Add(' .rela.bss : { *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*) }');
  277. Add(' .rel.plt : { *(.rel.plt) }');
  278. Add(' .rela.plt : { *(.rela.plt) }');
  279. Add('');
  280. Add(' .text :');
  281. Add(' {');
  282. Add(' *(.text)');
  283. Add(' *(.text.*)');
  284. Add(' /* .gnu.warning sections are handled specially by elf32.em. */');
  285. Add(' *(.gnu.warning)');
  286. Add(' *(.gnu.linkonce.t.*)');
  287. Add(' . = ALIGN(32); /* REQUIRED. LD is flaky without it. */');
  288. Add(' } = 0');
  289. Add('');
  290. Add(' .fini :');
  291. Add(' {');
  292. Add(' KEEP (*(.fini))');
  293. Add(' . = ALIGN(32); /* REQUIRED. LD is flaky without it. */');
  294. Add(' } = 0');
  295. Add(' ');
  296. Add(' PROVIDE (__etext = .);');
  297. Add(' PROVIDE (_etext = .);');
  298. Add(' PROVIDE (etext = .);');
  299. Add('');
  300. Add(' .rodata : { *(.rodata) *(.rodata.*) *(.gnu.linkonce.r.*) } :data');
  301. Add(' .rodata1 : { *(.rodata1) }');
  302. Add(' .sdata2 : { *(.sdata2) *(.sdata2.*) *(.gnu.linkonce.s2.*) }');
  303. Add(' .sbss2 : { *(.sbss2) *(.sbss2.*) *(.gnu.linkonce.sb2.*) }');
  304. Add(' /* Adjust the address for the data segment. We want to adjust up to');
  305. Add(' the same address within the page on the next page up. */');
  306. Add(' /* Ensure the __preinit_array_start label is properly aligned. We');
  307. Add(' could instead move the label definition inside the section, but');
  308. Add(' the linker would then create the section even if it turns out to');
  309. Add(' be empty, which isn''t pretty. */');
  310. Add(' . = ALIGN(32 / 8);');
  311. Add(' PROVIDE (__preinit_array_start = .);');
  312. Add(' .preinit_array : { *(.preinit_array) }');
  313. Add(' PROVIDE (__preinit_array_end = .);');
  314. Add(' PROVIDE (__init_array_start = .);');
  315. Add(' .init_array : { *(.init_array) }');
  316. Add(' PROVIDE (__init_array_end = .);');
  317. Add(' PROVIDE (__fini_array_start = .);');
  318. Add(' .fini_array : { *(.fini_array) }');
  319. Add(' PROVIDE (__fini_array_end = .);');
  320. Add(' .data :');
  321. Add(' {');
  322. Add(' *(.data)');
  323. Add(' *(.data.*)');
  324. Add(' *(.gnu.linkonce.d.*)');
  325. Add(' SORT(CONSTRUCTORS)');
  326. Add(' . = ALIGN(32); /* REQUIRED. LD is flaky without it. */');
  327. Add(' }');
  328. Add('');
  329. Add(' .data1 : { *(.data1) }');
  330. Add(' .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) }');
  331. Add(' .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }');
  332. Add(' .eh_frame : { KEEP (*(.eh_frame)) }');
  333. Add(' .gcc_except_table : { *(.gcc_except_table) }');
  334. Add(' .fixup : { *(.fixup) }');
  335. Add(' .got1 : { *(.got1) }');
  336. Add(' .got2 : { *(.got2) }');
  337. Add(' .dynamic : { *(.dynamic) }');
  338. Add('');
  339. Add(' .ctors :');
  340. Add(' {');
  341. Add(' /* gcc uses crtbegin.o to find the start of');
  342. Add(' the constructors, so we make sure it is');
  343. Add(' first. Because this is a wildcard, it');
  344. Add(' doesn''t matter if the user does not');
  345. Add(' actually link against crtbegin.o; the');
  346. Add(' linker won''t look for a file to match a');
  347. Add(' wildcard. The wildcard also means that it');
  348. Add(' doesn''t matter which directory crtbegin.o');
  349. Add(' is in. */');
  350. Add('');
  351. Add(' KEEP (*crtbegin.o(.ctors))');
  352. Add('');
  353. Add(' /* We don''t want to include the .ctor section from');
  354. Add(' from the crtend.o file until after the sorted ctors.');
  355. Add(' The .ctor section from the crtend file contains the');
  356. Add(' end of ctors marker and it must be last */');
  357. Add('');
  358. Add(' KEEP (*(EXCLUDE_FILE (*crtend.o ) .ctors))');
  359. Add(' KEEP (*(SORT(.ctors.*)))');
  360. Add(' KEEP (*(.ctors))');
  361. Add(' . = ALIGN(32); /* REQUIRED. LD is flaky without it. */');
  362. Add(' }');
  363. Add('');
  364. Add(' .dtors :');
  365. Add(' {');
  366. Add(' KEEP (*crtbegin.o(.dtors))');
  367. Add(' KEEP (*(EXCLUDE_FILE (*crtend.o ) .dtors))');
  368. Add(' KEEP (*(SORT(.dtors.*)))');
  369. Add(' KEEP (*(.dtors))');
  370. Add(' . = ALIGN(32); /* REQUIRED. LD is flaky without it. */');
  371. Add(' }');
  372. Add('');
  373. Add(' .jcr : { KEEP (*(.jcr)) }');
  374. Add(' .got : { *(.got.plt) *(.got) }');
  375. Add('');
  376. Add('');
  377. Add(' /* We want the small data sections together, so single-instruction offsets');
  378. Add(' can access them all, and initialized data all before uninitialized, so');
  379. Add(' we can shorten the on-disk segment size. */');
  380. Add('');
  381. Add(' .sdata :');
  382. Add(' {');
  383. Add(' *(.sdata)');
  384. Add(' *(.sdata.*)');
  385. Add(' *(.gnu.linkonce.s.*)');
  386. Add(' . = ALIGN(32); /* REQUIRED. LD is flaky without it. */');
  387. Add(' }');
  388. Add('');
  389. Add(' _edata = .;');
  390. Add(' PROVIDE (edata = .);');
  391. Add(' ');
  392. Add(' .sbss :');
  393. Add(' {');
  394. Add(' __sbss_start = .;');
  395. Add(' PROVIDE (__sbss_start = .);');
  396. Add(' PROVIDE (___sbss_start = .);');
  397. Add(' *(.dynsbss)');
  398. Add(' *(.sbss)');
  399. Add(' *(.sbss.*)');
  400. Add(' *(.gnu.linkonce.sb.*)');
  401. Add(' *(.scommon)');
  402. Add(' PROVIDE (__sbss_end = .);');
  403. Add(' PROVIDE (___sbss_end = .);');
  404. Add(' . = ALIGN(32); /* REQUIRED. LD is flaky without it. */');
  405. Add(' __sbss_end = .;');
  406. Add(' }');
  407. Add('');
  408. Add(' .bss :');
  409. Add(' {');
  410. Add(' __bss_start = .;');
  411. Add(' PROVIDE (__bss_start = .);');
  412. Add(' *(.dynbss)');
  413. Add(' *(.bss)');
  414. Add(' *(.bss.*)');
  415. Add(' *(.gnu.linkonce.b.*)');
  416. Add(' *(COMMON)');
  417. Add(' /* Align here to ensure that the .bss section occupies space up to');
  418. Add(' _end. Align after .bss to ensure correct alignment even if the');
  419. Add(' .bss section disappears because there are no input sections. */');
  420. Add('');
  421. Add(' . = ALIGN(32);');
  422. Add('');
  423. Add(' PROVIDE (__bss_end = .);');
  424. Add(' __bss_end = .;');
  425. Add(' }');
  426. Add('');
  427. Add(' _end = .;');
  428. Add(' PROVIDE(end = .);');
  429. Add(' /* Stabs debugging sections. */');
  430. Add(' .stab 0 : { *(.stab) }');
  431. Add(' .stabstr 0 : { *(.stabstr) }');
  432. Add(' .stab.excl 0 : { *(.stab.excl) }');
  433. Add(' .stab.exclstr 0 : { *(.stab.exclstr) }');
  434. Add(' .stab.index 0 : { *(.stab.index) }');
  435. Add(' .stab.indexstr 0 : { *(.stab.indexstr) }');
  436. Add(' .comment 0 : { *(.comment) }');
  437. Add(' /* DWARF debug sections.');
  438. Add(' Symbols in the DWARF debugging sections are relative to the beginning');
  439. Add(' of the section so we begin them at 0. */');
  440. Add(' /* DWARF 1 */');
  441. Add(' .debug 0 : { *(.debug) }');
  442. Add(' .line 0 : { *(.line) }');
  443. Add(' /* GNU DWARF 1 extensions */');
  444. Add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  445. Add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  446. Add(' /* DWARF 1.1 and DWARF 2 */');
  447. Add(' .debug_aranges 0 : { *(.debug_aranges) }');
  448. Add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  449. Add(' /* DWARF 2 */');
  450. Add(' .debug_info 0 : { *(.debug_info) }');
  451. Add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  452. Add(' .debug_line 0 : { *(.debug_line) }');
  453. Add(' .debug_frame 0 : { *(.debug_frame) }');
  454. Add(' .debug_str 0 : { *(.debug_str) }');
  455. Add(' .debug_loc 0 : { *(.debug_loc) }');
  456. Add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  457. Add(' /* SGI/MIPS DWARF 2 extensions */');
  458. Add(' .debug_weaknames 0 : { *(.debug_weaknames) }');
  459. Add(' .debug_funcnames 0 : { *(.debug_funcnames) }');
  460. Add(' .debug_typenames 0 : { *(.debug_typenames) }');
  461. Add(' .debug_varnames 0 : { *(.debug_varnames) }');
  462. Add(' /* These must appear regardless of . */');
  463. Add('}');
  464. Add('');
  465. Add('__isIPL = 0;');
  466. Add('__stack_addr = (__bss_start + SIZEOF(.bss) + 0x20000 + 7) & (-8);');
  467. Add('__stack_end = (__bss_start + SIZEOF(.bss));');
  468. Add('__intrstack_addr = (__stack_addr + 0x4000);');
  469. Add('__intrstack_end = (__stack_addr);');
  470. Add('__Arena1Lo = (__intrstack_addr + 31) & (-32);');
  471. Add('__Arena1Hi = (0x817FEFF0);');
  472. Add('__Arena2Lo = (0x90002000);');
  473. Add('__Arena2Hi = (0x933E0000);');
  474. Add('');
  475. Add('__gxregs = (__Arena1Hi + 31) & (-32);');
  476. Add('__ipcbufferLo = (0x933e0000);');
  477. Add('__ipcbufferHi = (0x93400000);');
  478. Add('');
  479. Add('/* for backward compatibility with old crt0 */');
  480. Add('PROVIDE (__stack = (0x817FEFF0));');
  481. Add('');
  482. Add('PROVIDE(__isIPL = __isIPL);');
  483. Add('PROVIDE(__stack_addr = __stack_addr);');
  484. Add('PROVIDE(__stack_end = __stack_end);');
  485. Add('PROVIDE(__intrstack_addr = __intrstack_addr);');
  486. Add('PROVIDE(__intrstack_end = __intrstack_end);');
  487. Add('PROVIDE(__Arena1Lo = __Arena1Lo);');
  488. Add('PROVIDE(__Arena1Hi = __Arena1Hi);');
  489. Add('PROVIDE(__Arena2Lo = __Arena2Lo);');
  490. Add('PROVIDE(__Arena2Hi = __Arena2Hi);');
  491. Add('PROVIDE(__ipcbufferLo = __ipcbufferLo);');
  492. Add('PROVIDE(__ipcbufferHi = __ipcbufferHi);');
  493. Add('PROVIDE(__gxregs = __gxregs);');
  494. end;
  495. { Write and Close response }
  496. linkres.writetodisk;
  497. linkres.free;
  498. WriteResponseFile:=True;
  499. end;
  500. function TLinkerWii.MakeExecutable:boolean;
  501. var
  502. binstr,
  503. cmdstr : TCmdStr;
  504. success : boolean;
  505. StaticStr,
  506. GCSectionsStr,
  507. DynLinkStr,
  508. StripStr: string;
  509. begin
  510. StaticStr:='';
  511. StripStr:='';
  512. GCSectionsStr:='';
  513. DynLinkStr:='';
  514. if (cs_link_strip in current_settings.globalswitches) and
  515. not(cs_link_separate_dbg_file in current_settings.globalswitches) then
  516. StripStr:='-s';
  517. if (cs_link_map in current_settings.globalswitches) then
  518. StripStr:='-Map '+maybequoted(ChangeFileExt(current_module.exefilename^,'.map'));
  519. if create_smartlink_sections then
  520. GCSectionsStr:='--gc-sections';
  521. if not(cs_link_nolink in current_settings.globalswitches) then
  522. Message1(exec_i_linking,current_module.exefilename^);
  523. { Write used files and libraries }
  524. WriteResponseFile();
  525. { Call linker }
  526. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  527. Replace(cmdstr,'$EXE',(maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename^,'.elf')))));
  528. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  529. Replace(cmdstr,'$RES',(maybequoted(ScriptFixFileName(outputexedir+Info.ResName))));
  530. Replace(cmdstr,'$STATIC',StaticStr);
  531. Replace(cmdstr,'$STRIP',StripStr);
  532. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  533. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  534. success:=DoExec(FindUtil(utilsprefix+BinStr),cmdstr,true,false);
  535. { Remove ReponseFile }
  536. if (success) and not(cs_link_nolink in current_settings.globalswitches) then
  537. DeleteFile(outputexedir+Info.ResName);
  538. { Post process }
  539. if success then
  540. begin
  541. success:=DoExec(FindUtil('elf2dol'),ChangeFileExt(current_module.exefilename^,'.elf')+' '+
  542. current_module.exefilename^,true,false);
  543. end;
  544. MakeExecutable:=success; { otherwise a recursive call to link method }
  545. end;
  546. {*****************************************************************************
  547. Initialize
  548. *****************************************************************************}
  549. initialization
  550. RegisterExternalLinker(system_powerpc_wii_info,TLinkerWii);
  551. RegisterTarget(system_powerpc_wii_info);
  552. end.