t_wii.pas 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  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,true);
  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("'+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(' bss1 PT_LOAD;');
  214. Add(' bss2 PT_LOAD;');
  215. Add('');
  216. Add('}');
  217. Add('');
  218. Add('SECTIONS');
  219. Add('{');
  220. Add(' /* stub is loaded at physical address 0x00003400 (though both 0x80003400 and 0x00003400 are equivalent for IOS) */');
  221. Add(' /* This can also be used to load an arbitrary standalone stub at an arbitrary address in memory, for any purpose */');
  222. Add(' /* Use -Wl,--section-start,.stub=0xADDRESS to change */');
  223. Add(' . = 0x00003400;');
  224. Add('');
  225. Add(' .stub :');
  226. Add(' {');
  227. Add(' KEEP(*(.stub))');
  228. Add(' } :stub = 0');
  229. Add('');
  230. Add(' /* default base address */');
  231. Add(' /* use -Wl,--section-start,.init=0xADDRESS to change */');
  232. Add(' . = 0x80004000;');
  233. Add('');
  234. Add(' /* Program */');
  235. Add(' .init :');
  236. Add(' {');
  237. Add(' KEEP (*crt0.o(*.init))');
  238. Add(' KEEP (*(.init))');
  239. Add(' } :text = 0');
  240. Add(' .plt : { *(.plt) }');
  241. Add(' .interp : { *(.interp) }');
  242. Add(' .hash : { *(.hash) }');
  243. Add(' .dynsym : { *(.dynsym) }');
  244. Add(' .dynstr : { *(.dynstr) }');
  245. Add(' .gnu.version : { *(.gnu.version) }');
  246. Add(' .gnu.version_d : { *(.gnu.version_d) }');
  247. Add(' .gnu.version_r : { *(.gnu.version_r) }');
  248. Add(' .rel.init : { *(.rel.init) }');
  249. Add(' .rela.init : { *(.rela.init) }');
  250. Add(' .rel.text : { *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*) }');
  251. Add(' .rela.text : { *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*) }');
  252. Add(' .rel.fini : { *(.rel.fini) }');
  253. Add(' .rela.fini : { *(.rela.fini) }');
  254. Add(' .rel.rodata : { *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*) }');
  255. Add(' .rela.rodata : { *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*) }');
  256. Add(' .rel.data : { *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*) }');
  257. Add(' .rela.data : { *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*) }');
  258. Add(' .rel.tdata : { *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*) }');
  259. Add(' .rela.tdata : { *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*) }');
  260. Add(' .rel.tbss : { *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*) }');
  261. Add(' .rela.tbss : { *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*) }');
  262. Add(' .rel.ctors : { *(.rel.ctors) }');
  263. Add(' .rela.ctors : { *(.rela.ctors) }');
  264. Add(' .rel.dtors : { *(.rel.dtors) }');
  265. Add(' .rela.dtors : { *(.rela.dtors) }');
  266. Add(' .rel.got : { *(.rel.got) }');
  267. Add(' .rela.got : { *(.rela.got) }');
  268. Add(' .rela.got1 : { *(.rela.got1) }');
  269. Add(' .rela.got2 : { *(.rela.got2) }');
  270. Add(' .rel.sdata : { *(.rel.sdata .rel.sdata.* .rel.gnu.linkonce.s.*) }');
  271. Add(' .rela.sdata : { *(.rela.sdata .rela.sdata.* .rela.gnu.linkonce.s.*) }');
  272. Add(' .rel.sbss : { *(.rel.sbss .rel.sbss.* .rel.gnu.linkonce.sb.*) }');
  273. Add(' .rela.sbss : { *(.rela.sbss .rela.sbss.* .rel.gnu.linkonce.sb.*) }');
  274. Add(' .rel.sdata2 : { *(.rel.sdata2 .rel.sdata2.* .rel.gnu.linkonce.s2.*) }');
  275. Add(' .rela.sdata2 : { *(.rela.sdata2 .rela.sdata2.* .rela.gnu.linkonce.s2.*) }');
  276. Add(' .rel.sbss2 : { *(.rel.sbss2 .rel.sbss2.* .rel.gnu.linkonce.sb2.*) }');
  277. Add(' .rela.sbss2 : { *(.rela.sbss2 .rela.sbss2.* .rela.gnu.linkonce.sb2.*) }');
  278. Add(' .rel.bss : { *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*) }');
  279. Add(' .rela.bss : { *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*) }');
  280. Add(' .rel.plt : { *(.rel.plt) }');
  281. Add(' .rela.plt : { *(.rela.plt) }');
  282. Add('');
  283. Add(' .text :');
  284. Add(' {');
  285. Add(' *(.text)');
  286. Add(' *(.text.*)');
  287. Add(' /* .gnu.warning sections are handled specially by elf32.em. */');
  288. Add(' *(.gnu.warning)');
  289. Add(' *(.gnu.linkonce.t.*)');
  290. Add(' . = ALIGN(32); /* REQUIRED. LD is flaky without it. */');
  291. Add(' } = 0');
  292. Add('');
  293. Add(' .fini :');
  294. Add(' {');
  295. Add(' KEEP (*(.fini))');
  296. Add(' . = ALIGN(32); /* REQUIRED. LD is flaky without it. */');
  297. Add(' } = 0');
  298. Add(' ');
  299. Add(' PROVIDE (__etext = .);');
  300. Add(' PROVIDE (_etext = .);');
  301. Add(' PROVIDE (etext = .);');
  302. Add('');
  303. Add(' .rodata : { *(.rodata) *(.rodata.*) *(.gnu.linkonce.r.*) } :data');
  304. Add(' .rodata1 : { *(.rodata1) }');
  305. Add(' .sdata2 : { *(.sdata2) *(.sdata2.*) *(.gnu.linkonce.s2.*) }');
  306. Add(' .sbss2 : { *(.sbss2) *(.sbss2.*) *(.gnu.linkonce.sb2.*) }');
  307. Add(' /* Adjust the address for the data segment. We want to adjust up to');
  308. Add(' the same address within the page on the next page up. */');
  309. Add(' /* Ensure the __preinit_array_start label is properly aligned. We');
  310. Add(' could instead move the label definition inside the section, but');
  311. Add(' the linker would then create the section even if it turns out to');
  312. Add(' be empty, which isn''t pretty. */');
  313. Add(' . = ALIGN(32 / 8);');
  314. Add(' PROVIDE (__preinit_array_start = .);');
  315. Add(' .preinit_array : { *(.preinit_array) }');
  316. Add(' PROVIDE (__preinit_array_end = .);');
  317. Add(' PROVIDE (__init_array_start = .);');
  318. Add(' .init_array : { *(.init_array) }');
  319. Add(' PROVIDE (__init_array_end = .);');
  320. Add(' PROVIDE (__fini_array_start = .);');
  321. Add(' .fini_array : { *(.fini_array) }');
  322. Add(' PROVIDE (__fini_array_end = .);');
  323. Add(' .data :');
  324. Add(' {');
  325. Add(' *(.data)');
  326. Add(' *(.data.*)');
  327. Add(' *(.gnu.linkonce.d.*)');
  328. Add(' SORT(CONSTRUCTORS)');
  329. Add(' . = ALIGN(32); /* REQUIRED. LD is flaky without it. */');
  330. Add(' }');
  331. Add('');
  332. Add(' .data1 : { *(.data1) }');
  333. Add(' .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) }');
  334. Add(' .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }');
  335. Add(' .eh_frame : { KEEP (*(.eh_frame)) }');
  336. Add(' .gcc_except_table : { *(.gcc_except_table) }');
  337. Add(' .fixup : { *(.fixup) }');
  338. Add(' .got1 : { *(.got1) }');
  339. Add(' .got2 : { *(.got2) }');
  340. Add(' .dynamic : { *(.dynamic) }');
  341. Add('');
  342. Add(' .ctors :');
  343. Add(' {');
  344. Add(' /* gcc uses crtbegin.o to find the start of');
  345. Add(' the constructors, so we make sure it is');
  346. Add(' first. Because this is a wildcard, it');
  347. Add(' doesn''t matter if the user does not');
  348. Add(' actually link against crtbegin.o; the');
  349. Add(' linker won''t look for a file to match a');
  350. Add(' wildcard. The wildcard also means that it');
  351. Add(' doesn''t matter which directory crtbegin.o');
  352. Add(' is in. */');
  353. Add('');
  354. Add(' KEEP (*crtbegin.o(.ctors))');
  355. Add('');
  356. Add(' /* We don''t want to include the .ctor section from');
  357. Add(' from the crtend.o file until after the sorted ctors.');
  358. Add(' The .ctor section from the crtend file contains the');
  359. Add(' end of ctors marker and it must be last */');
  360. Add('');
  361. Add(' KEEP (*(EXCLUDE_FILE (*crtend.o ) .ctors))');
  362. Add(' KEEP (*(SORT(.ctors.*)))');
  363. Add(' KEEP (*(.ctors))');
  364. Add(' . = ALIGN(32); /* REQUIRED. LD is flaky without it. */');
  365. Add(' }');
  366. Add('');
  367. Add(' .dtors :');
  368. Add(' {');
  369. Add(' KEEP (*crtbegin.o(.dtors))');
  370. Add(' KEEP (*(EXCLUDE_FILE (*crtend.o ) .dtors))');
  371. Add(' KEEP (*(SORT(.dtors.*)))');
  372. Add(' KEEP (*(.dtors))');
  373. Add(' . = ALIGN(32); /* REQUIRED. LD is flaky without it. */');
  374. Add(' }');
  375. Add('');
  376. Add(' .jcr : { KEEP (*(.jcr)) }');
  377. Add(' .got : { *(.got.plt) *(.got) }');
  378. Add('');
  379. Add('');
  380. Add(' /* We want the small data sections together, so single-instruction offsets');
  381. Add(' can access them all, and initialized data all before uninitialized, so');
  382. Add(' we can shorten the on-disk segment size. */');
  383. Add('');
  384. Add(' .sdata :');
  385. Add(' {');
  386. Add(' *(.sdata)');
  387. Add(' *(.sdata.*)');
  388. Add(' *(.gnu.linkonce.s.*)');
  389. Add(' . = ALIGN(32); /* REQUIRED. LD is flaky without it. */');
  390. Add(' }');
  391. Add('');
  392. Add(' _edata = .;');
  393. Add(' PROVIDE (edata = .);');
  394. Add(' ');
  395. Add(' .sbss :');
  396. Add(' {');
  397. Add(' __sbss_start = .;');
  398. Add(' PROVIDE (__sbss_start = .);');
  399. Add(' PROVIDE (___sbss_start = .);');
  400. Add(' *(.dynsbss)');
  401. Add(' *(.sbss)');
  402. Add(' *(.sbss.*)');
  403. Add(' *(.gnu.linkonce.sb.*)');
  404. Add(' *(.scommon)');
  405. Add(' PROVIDE (__sbss_end = .);');
  406. Add(' PROVIDE (___sbss_end = .);');
  407. Add(' . = ALIGN(32); /* REQUIRED. LD is flaky without it. */');
  408. Add(' __sbss_end = .;');
  409. Add(' } :bss1');
  410. Add('');
  411. Add(' .bss :');
  412. Add(' {');
  413. Add(' __bss_start = .;');
  414. Add(' PROVIDE (__bss_start = .);');
  415. Add(' *(.dynbss)');
  416. Add(' *(.bss)');
  417. Add(' *(.bss.*)');
  418. Add(' *(.gnu.linkonce.b.*)');
  419. Add(' *(COMMON)');
  420. Add(' /* Align here to ensure that the .bss section occupies space up to');
  421. Add(' _end. Align after .bss to ensure correct alignment even if the');
  422. Add(' .bss section disappears because there are no input sections. */');
  423. Add('');
  424. Add(' . = ALIGN(32);');
  425. Add('');
  426. Add(' PROVIDE (__bss_end = .);');
  427. Add(' __bss_end = .;');
  428. Add(' } :bss2');
  429. Add('');
  430. Add(' _end = .;');
  431. Add(' PROVIDE(end = .);');
  432. Add(' /* Stabs debugging sections. */');
  433. Add(' .stab 0 : { *(.stab) }');
  434. Add(' .stabstr 0 : { *(.stabstr) }');
  435. Add(' .stab.excl 0 : { *(.stab.excl) }');
  436. Add(' .stab.exclstr 0 : { *(.stab.exclstr) }');
  437. Add(' .stab.index 0 : { *(.stab.index) }');
  438. Add(' .stab.indexstr 0 : { *(.stab.indexstr) }');
  439. Add(' .comment 0 : { *(.comment) }');
  440. Add(' /* DWARF debug sections.');
  441. Add(' Symbols in the DWARF debugging sections are relative to the beginning');
  442. Add(' of the section so we begin them at 0. */');
  443. Add(' /* DWARF 1 */');
  444. Add(' .debug 0 : { *(.debug) }');
  445. Add(' .line 0 : { *(.line) }');
  446. Add(' /* GNU DWARF 1 extensions */');
  447. Add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  448. Add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  449. Add(' /* DWARF 1.1 and DWARF 2 */');
  450. Add(' .debug_aranges 0 : { *(.debug_aranges) }');
  451. Add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  452. Add(' /* DWARF 2 */');
  453. Add(' .debug_info 0 : { *(.debug_info) }');
  454. Add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  455. Add(' .debug_line 0 : { *(.debug_line) }');
  456. Add(' .debug_frame 0 : { *(.debug_frame) }');
  457. Add(' .debug_str 0 : { *(.debug_str) }');
  458. Add(' .debug_loc 0 : { *(.debug_loc) }');
  459. Add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  460. Add(' /* SGI/MIPS DWARF 2 extensions */');
  461. Add(' .debug_weaknames 0 : { *(.debug_weaknames) }');
  462. Add(' .debug_funcnames 0 : { *(.debug_funcnames) }');
  463. Add(' .debug_typenames 0 : { *(.debug_typenames) }');
  464. Add(' .debug_varnames 0 : { *(.debug_varnames) }');
  465. Add(' /* These must appear regardless of . */');
  466. Add('}');
  467. Add('');
  468. Add('__isIPL = 0;');
  469. Add('__stack_addr = (__bss_start + SIZEOF(.bss) + 0x20000 + 7) & (-8);');
  470. Add('__stack_end = (__bss_start + SIZEOF(.bss));');
  471. Add('__intrstack_addr = (__stack_addr + 0x4000);');
  472. Add('__intrstack_end = (__stack_addr);');
  473. Add('__Arena1Lo = (__intrstack_addr + 31) & (-32);');
  474. Add('__Arena1Hi = (0x817FEFF0);');
  475. Add('__Arena2Lo = (0x90002000);');
  476. Add('__Arena2Hi = (0x933E0000);');
  477. Add('');
  478. Add('__gxregs = (__Arena1Hi + 31) & (-32);');
  479. Add('__ipcbufferLo = (0x933e0000);');
  480. Add('__ipcbufferHi = (0x93400000);');
  481. Add('');
  482. Add('/* for backward compatibility with old crt0 */');
  483. Add('PROVIDE (__stack = (0x817FEFF0));');
  484. Add('');
  485. Add('PROVIDE(__isIPL = __isIPL);');
  486. Add('PROVIDE(__stack_addr = __stack_addr);');
  487. Add('PROVIDE(__stack_end = __stack_end);');
  488. Add('PROVIDE(__intrstack_addr = __intrstack_addr);');
  489. Add('PROVIDE(__intrstack_end = __intrstack_end);');
  490. Add('PROVIDE(__Arena1Lo = __Arena1Lo);');
  491. Add('PROVIDE(__Arena1Hi = __Arena1Hi);');
  492. Add('PROVIDE(__Arena2Lo = __Arena2Lo);');
  493. Add('PROVIDE(__Arena2Hi = __Arena2Hi);');
  494. Add('PROVIDE(__ipcbufferLo = __ipcbufferLo);');
  495. Add('PROVIDE(__ipcbufferHi = __ipcbufferHi);');
  496. Add('PROVIDE(__gxregs = __gxregs);');
  497. end;
  498. { Write and Close response }
  499. linkres.writetodisk;
  500. linkres.free;
  501. WriteResponseFile:=True;
  502. end;
  503. function TLinkerWii.MakeExecutable:boolean;
  504. var
  505. binstr,
  506. cmdstr : TCmdStr;
  507. success : boolean;
  508. StaticStr,
  509. GCSectionsStr,
  510. DynLinkStr,
  511. StripStr: string;
  512. begin
  513. StaticStr:='';
  514. StripStr:='';
  515. GCSectionsStr:='';
  516. DynLinkStr:='';
  517. if (cs_link_strip in current_settings.globalswitches) and
  518. not(cs_link_separate_dbg_file in current_settings.globalswitches) then
  519. StripStr:='-s';
  520. if (cs_link_map in current_settings.globalswitches) then
  521. StripStr:='-Map '+maybequoted(ChangeFileExt(current_module.exefilename,'.map'));
  522. if create_smartlink_sections then
  523. GCSectionsStr:='--gc-sections';
  524. if not(cs_link_nolink in current_settings.globalswitches) then
  525. Message1(exec_i_linking,current_module.exefilename);
  526. { Write used files and libraries }
  527. WriteResponseFile();
  528. { Call linker }
  529. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  530. Replace(cmdstr,'$EXE',(maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.elf')))));
  531. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  532. Replace(cmdstr,'$RES',(maybequoted(ScriptFixFileName(outputexedir+Info.ResName))));
  533. Replace(cmdstr,'$STATIC',StaticStr);
  534. Replace(cmdstr,'$STRIP',StripStr);
  535. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  536. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  537. success:=DoExec(FindUtil(utilsprefix+BinStr),cmdstr,true,false);
  538. { Remove ReponseFile }
  539. if (success) and not(cs_link_nolink in current_settings.globalswitches) then
  540. DeleteFile(outputexedir+Info.ResName);
  541. { Post process }
  542. if success then
  543. begin
  544. success:=DoExec(FindUtil('elf2dol'),ChangeFileExt(current_module.exefilename,'.elf')+' '+
  545. current_module.exefilename,true,false);
  546. end;
  547. MakeExecutable:=success; { otherwise a recursive call to link method }
  548. end;
  549. {*****************************************************************************
  550. Initialize
  551. *****************************************************************************}
  552. initialization
  553. RegisterLinker(ld_wii,TLinkerWii);
  554. RegisterTarget(system_powerpc_wii_info);
  555. end.