t_wii.pas 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  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,cscript,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 : {');
  306. add(' PROVIDE(_SDA2_BASE_ = .);');
  307. add(' *(.sdata2)');
  308. add(' *(.sdata2.*)');
  309. add(' *(.gnu.linkonce.s2.*)');
  310. add(' }');
  311. add(' .sbss2 : { *(.sbss2) *(.sbss2.*) *(.gnu.linkonce.sb2.*) }');
  312. add(' /* Adjust the address for the data segment. We want to adjust up to');
  313. add(' the same address within the page on the next page up. */');
  314. add(' /* Ensure the __preinit_array_start label is properly aligned. We');
  315. add(' could instead move the label definition inside the section, but');
  316. add(' the linker would then create the section even if it turns out to');
  317. add(' be empty, which isn''t pretty. */');
  318. add(' . = ALIGN(32 / 8);');
  319. add(' PROVIDE (__preinit_array_start = .);');
  320. add(' .preinit_array : { *(.preinit_array) }');
  321. add(' PROVIDE (__preinit_array_end = .);');
  322. add(' PROVIDE (__init_array_start = .);');
  323. add(' .init_array : { *(.init_array) }');
  324. add(' PROVIDE (__init_array_end = .);');
  325. add(' PROVIDE (__fini_array_start = .);');
  326. add(' .fini_array : { *(.fini_array) }');
  327. add(' PROVIDE (__fini_array_end = .);');
  328. add(' .data :');
  329. add(' {');
  330. add(' *(.data)');
  331. add(' *(.data.*)');
  332. add(' *(.gnu.linkonce.d.*)');
  333. add(' SORT(CONSTRUCTORS)');
  334. add(' . = ALIGN(32); /* REQUIRED. LD is flaky without it. */');
  335. add(' }');
  336. add('');
  337. add(' .data1 : { *(.data1) }');
  338. add(' .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) }');
  339. add(' .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }');
  340. add(' .eh_frame : { KEEP (*(.eh_frame)) }');
  341. add(' .gcc_except_table : { *(.gcc_except_table) }');
  342. add(' .fixup : { *(.fixup) }');
  343. add(' .got1 : { *(.got1) }');
  344. add(' .got2 : { *(.got2) }');
  345. add(' .dynamic : { *(.dynamic) }');
  346. add('');
  347. add(' .ctors :');
  348. add(' {');
  349. add(' /* gcc uses crtbegin.o to find the start of');
  350. add(' the constructors, so we make sure it is');
  351. add(' first. Because this is a wildcard, it');
  352. add(' doesn''t matter if the user does not');
  353. add(' actually link against crtbegin.o; the');
  354. add(' linker won''t look for a file to match a');
  355. add(' wildcard. The wildcard also means that it');
  356. add(' doesn''t matter which directory crtbegin.o');
  357. add(' is in. */');
  358. add('');
  359. add(' KEEP (*crtbegin.o(.ctors))');
  360. add('');
  361. add(' /* We don''t want to include the .ctor section from');
  362. add(' from the crtend.o file until after the sorted ctors.');
  363. add(' The .ctor section from the crtend file contains the');
  364. add(' end of ctors marker and it must be last */');
  365. add('');
  366. add(' KEEP (*(EXCLUDE_FILE (*crtend.o ) .ctors))');
  367. add(' KEEP (*(SORT(.ctors.*)))');
  368. add(' KEEP (*(.ctors))');
  369. add(' . = ALIGN(32); /* REQUIRED. LD is flaky without it. */');
  370. add(' }');
  371. add('');
  372. add(' .dtors :');
  373. add(' {');
  374. add(' KEEP (*crtbegin.o(.dtors))');
  375. add(' KEEP (*(EXCLUDE_FILE (*crtend.o ) .dtors))');
  376. add(' KEEP (*(SORT(.dtors.*)))');
  377. add(' KEEP (*(.dtors))');
  378. add(' . = ALIGN(32); /* REQUIRED. LD is flaky without it. */');
  379. add(' }');
  380. add('');
  381. add(' .jcr : { KEEP (*(.jcr)) }');
  382. add(' .got : { *(.got.plt) *(.got) }');
  383. add('');
  384. add('');
  385. add(' /* We want the small data sections together, so single-instruction offsets');
  386. add(' can access them all, and initialized data all before uninitialized, so');
  387. add(' we can shorten the on-disk segment size. */');
  388. add('');
  389. add(' .sdata :');
  390. add(' {');
  391. add(' PROVIDE(_SDA_BASE_ = .);');
  392. add(' *(.sdata)');
  393. add(' *(.sdata.*)');
  394. add(' *(.gnu.linkonce.s.*)');
  395. add(' . = ALIGN(32); /* REQUIRED. LD is flaky without it. */');
  396. add(' }');
  397. add('');
  398. add(' _edata = .;');
  399. add(' PROVIDE (edata = .);');
  400. add(' ');
  401. add(' .sbss :');
  402. add(' {');
  403. add(' __sbss_start = .;');
  404. add(' PROVIDE (__sbss_start = .);');
  405. add(' PROVIDE (___sbss_start = .);');
  406. add(' *(.dynsbss)');
  407. add(' *(.sbss)');
  408. add(' *(.sbss.*)');
  409. add(' *(.gnu.linkonce.sb.*)');
  410. add(' *(.scommon)');
  411. add(' PROVIDE (__sbss_end = .);');
  412. add(' PROVIDE (___sbss_end = .);');
  413. add(' . = ALIGN(32); /* REQUIRED. LD is flaky without it. */');
  414. add(' __sbss_end = .;');
  415. add(' } :bss1');
  416. add('');
  417. add(' .bss :');
  418. add(' {');
  419. add(' __bss_start = .;');
  420. add(' PROVIDE (__bss_start = .);');
  421. add(' *(.dynbss)');
  422. add(' *(.bss)');
  423. add(' *(.bss.*)');
  424. add(' *(.gnu.linkonce.b.*)');
  425. add(' *(COMMON)');
  426. add(' /* Align here to ensure that the .bss section occupies space up to');
  427. add(' _end. Align after .bss to ensure correct alignment even if the');
  428. add(' .bss section disappears because there are no input sections. */');
  429. add('');
  430. add(' . = ALIGN(32);');
  431. add('');
  432. add(' PROVIDE (__bss_end = .);');
  433. add(' __bss_end = .;');
  434. add(' } :bss2');
  435. add('');
  436. add(' _end = .;');
  437. add(' PROVIDE(end = .);');
  438. add(' /* Stabs debugging sections. */');
  439. add(' .stab 0 : { *(.stab) }');
  440. add(' .stabstr 0 : { *(.stabstr) }');
  441. add(' .stab.excl 0 : { *(.stab.excl) }');
  442. add(' .stab.exclstr 0 : { *(.stab.exclstr) }');
  443. add(' .stab.index 0 : { *(.stab.index) }');
  444. add(' .stab.indexstr 0 : { *(.stab.indexstr) }');
  445. add(' .comment 0 : { *(.comment) }');
  446. add(' /* DWARF debug sections.');
  447. add(' Symbols in the DWARF debugging sections are relative to the beginning');
  448. add(' of the section so we begin them at 0. */');
  449. add(' /* DWARF 1 */');
  450. add(' .debug 0 : { *(.debug) }');
  451. add(' .line 0 : { *(.line) }');
  452. add(' /* GNU DWARF 1 extensions */');
  453. add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  454. add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  455. add(' /* DWARF 1.1 and DWARF 2 */');
  456. add(' .debug_aranges 0 : { *(.debug_aranges) }');
  457. add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  458. add(' /* DWARF 2 */');
  459. add(' .debug_info 0 : { *(.debug_info) }');
  460. add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  461. add(' .debug_line 0 : { *(.debug_line) }');
  462. add(' .debug_frame 0 : { *(.debug_frame) }');
  463. add(' .debug_str 0 : { *(.debug_str) }');
  464. add(' .debug_loc 0 : { *(.debug_loc) }');
  465. add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  466. add(' /* SGI/MIPS DWARF 2 extensions */');
  467. add(' .debug_weaknames 0 : { *(.debug_weaknames) }');
  468. add(' .debug_funcnames 0 : { *(.debug_funcnames) }');
  469. add(' .debug_typenames 0 : { *(.debug_typenames) }');
  470. add(' .debug_varnames 0 : { *(.debug_varnames) }');
  471. add(' /* These must appear regardless of . */');
  472. add('}');
  473. add('');
  474. add('__isIPL = 0;');
  475. add('__stack_addr = (__bss_start + SIZEOF(.bss) + 0x20000 + 7) & (-8);');
  476. add('__stack_end = (__bss_start + SIZEOF(.bss));');
  477. add('__intrstack_addr = (__stack_addr + 0x4000);');
  478. add('__intrstack_end = (__stack_addr);');
  479. add('__Arena1Lo = (__intrstack_addr + 31) & (-32);');
  480. add('__Arena1Hi = (0x817FEFF0);');
  481. add('__Arena2Lo = (0x90002000);');
  482. add('__Arena2Hi = (0x933E0000);');
  483. add('');
  484. add('__gxregs = (__Arena1Hi + 31) & (-32);');
  485. add('__ipcbufferLo = (0x933e0000);');
  486. add('__ipcbufferHi = (0x93400000);');
  487. add('');
  488. add('/* for backward compatibility with old crt0 */');
  489. add('PROVIDE (__stack = (0x817FEFF0));');
  490. add('');
  491. add('PROVIDE(__isIPL = __isIPL);');
  492. add('PROVIDE(__stack_addr = __stack_addr);');
  493. add('PROVIDE(__stack_end = __stack_end);');
  494. add('PROVIDE(__intrstack_addr = __intrstack_addr);');
  495. add('PROVIDE(__intrstack_end = __intrstack_end);');
  496. add('PROVIDE(__Arena1Lo = __Arena1Lo);');
  497. add('PROVIDE(__Arena1Hi = __Arena1Hi);');
  498. add('PROVIDE(__Arena2Lo = __Arena2Lo);');
  499. add('PROVIDE(__Arena2Hi = __Arena2Hi);');
  500. add('PROVIDE(__ipcbufferLo = __ipcbufferLo);');
  501. add('PROVIDE(__ipcbufferHi = __ipcbufferHi);');
  502. add('PROVIDE(__gxregs = __gxregs);');
  503. end;
  504. { Write and Close response }
  505. linkres.writetodisk;
  506. linkres.free;
  507. WriteResponseFile:=True;
  508. end;
  509. function TLinkerWii.MakeExecutable:boolean;
  510. var
  511. binstr,
  512. cmdstr : TCmdStr;
  513. success : boolean;
  514. StaticStr,
  515. GCSectionsStr,
  516. DynLinkStr,
  517. StripStr: string;
  518. begin
  519. StaticStr:='';
  520. StripStr:='';
  521. GCSectionsStr:='';
  522. DynLinkStr:='';
  523. if (cs_link_strip in current_settings.globalswitches) and
  524. not(cs_link_separate_dbg_file in current_settings.globalswitches) then
  525. StripStr:='-s';
  526. if (cs_link_map in current_settings.globalswitches) then
  527. StripStr:='-Map '+maybequoted(ChangeFileExt(current_module.exefilename,'.map'));
  528. if create_smartlink_sections then
  529. GCSectionsStr:='--gc-sections';
  530. if not(cs_link_nolink in current_settings.globalswitches) then
  531. Message1(exec_i_linking,current_module.exefilename);
  532. { Write used files and libraries }
  533. WriteResponseFile();
  534. { Call linker }
  535. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  536. Replace(cmdstr,'$EXE',(maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.elf')))));
  537. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  538. Replace(cmdstr,'$RES',(maybequoted(ScriptFixFileName(outputexedir+Info.ResName))));
  539. Replace(cmdstr,'$STATIC',StaticStr);
  540. Replace(cmdstr,'$STRIP',StripStr);
  541. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  542. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  543. success:=DoExec(FindUtil(utilsprefix+BinStr),cmdstr,true,false);
  544. { Remove ReponseFile }
  545. if (success) and not(cs_link_nolink in current_settings.globalswitches) then
  546. DeleteFile(outputexedir+Info.ResName);
  547. { Post process }
  548. if success then
  549. begin
  550. success:=DoExec(FindUtil('elf2dol'),ChangeFileExt(current_module.exefilename,'.elf')+' '+
  551. current_module.exefilename,true,false);
  552. end;
  553. MakeExecutable:=success; { otherwise a recursive call to link method }
  554. end;
  555. {*****************************************************************************
  556. Initialize
  557. *****************************************************************************}
  558. initialization
  559. RegisterLinker(ld_wii,TLinkerWii);
  560. RegisterTarget(system_powerpc_wii_info);
  561. end.