t_embed.pas 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453
  1. {
  2. This unit implements support import,export,link routines
  3. for the (arm) GameBoy Advance target
  4. Copyright (c) 2001-2002 by Peter Vreman
  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_embed;
  19. {$i fpcdefs.inc}
  20. interface
  21. implementation
  22. uses
  23. SysUtils,
  24. cutils,cfileutl,cclasses,
  25. globtype,globals,systems,verbose,comphook,script,fmodule,i_embed,link,
  26. cpuinfo;
  27. type
  28. TlinkerEmbedded=class(texternallinker)
  29. private
  30. Function WriteResponseFile: Boolean;
  31. public
  32. constructor Create; override;
  33. procedure SetDefaultInfo; override;
  34. function MakeExecutable:boolean; override;
  35. function postprocessexecutable(const fn : string;isdll:boolean):boolean;
  36. end;
  37. {*****************************************************************************
  38. TlinkerEmbedded
  39. *****************************************************************************}
  40. Constructor TlinkerEmbedded.Create;
  41. begin
  42. Inherited Create;
  43. SharedLibFiles.doubles:=true;
  44. StaticLibFiles.doubles:=true;
  45. end;
  46. procedure TlinkerEmbedded.SetDefaultInfo;
  47. const
  48. {$ifdef mips}
  49. {$ifdef mipsel}
  50. platform_select='-EL';
  51. {$else}
  52. platform_select='-EB';
  53. {$endif}
  54. {$else}
  55. platform_select='';
  56. {$endif}
  57. begin
  58. with Info do
  59. begin
  60. ExeCmd[1]:='ld -g '+platform_select+' $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP -L. -o $EXE -T $RES';
  61. end;
  62. end;
  63. Function TlinkerEmbedded.WriteResponseFile: Boolean;
  64. Var
  65. linkres : TLinkRes;
  66. i : longint;
  67. HPath : TCmdStrListItem;
  68. s,s1,s2 : TCmdStr;
  69. prtobj,
  70. cprtobj : string[80];
  71. linklibc : boolean;
  72. found1,
  73. found2 : boolean;
  74. {$if defined(ARM)}
  75. LinkStr : string;
  76. {$endif}
  77. begin
  78. WriteResponseFile:=False;
  79. linklibc:=(SharedLibFiles.Find('c')<>nil);
  80. {$if defined(ARM) or defined(i386) or defined(AVR) or defined(MIPSEL)}
  81. prtobj:='';
  82. {$else}
  83. prtobj:='prt0';
  84. {$endif}
  85. cprtobj:='cprt0';
  86. if linklibc then
  87. prtobj:=cprtobj;
  88. { Open link.res file }
  89. LinkRes:=TLinkRes.Create(outputexedir+Info.ResName,true);
  90. { Write path to search libraries }
  91. HPath:=TCmdStrListItem(current_module.locallibrarysearchpath.First);
  92. while assigned(HPath) do
  93. begin
  94. s:=HPath.Str;
  95. if (cs_link_on_target in current_settings.globalswitches) then
  96. s:=ScriptFixFileName(s);
  97. LinkRes.Add('-L'+s);
  98. HPath:=TCmdStrListItem(HPath.Next);
  99. end;
  100. HPath:=TCmdStrListItem(LibrarySearchPath.First);
  101. while assigned(HPath) do
  102. begin
  103. s:=HPath.Str;
  104. if s<>'' then
  105. LinkRes.Add('SEARCH_DIR("'+s+'")');
  106. HPath:=TCmdStrListItem(HPath.Next);
  107. end;
  108. LinkRes.Add('INPUT (');
  109. { add objectfiles, start with prt0 always }
  110. //s:=FindObjectFile('prt0','',false);
  111. if prtobj<>'' then
  112. begin
  113. s:=FindObjectFile(prtobj,'',false);
  114. LinkRes.AddFileName(s);
  115. end;
  116. { try to add crti and crtbegin if linking to C }
  117. if linklibc then
  118. begin
  119. if librarysearchpath.FindFile('crtbegin.o',false,s) then
  120. LinkRes.AddFileName(s);
  121. if librarysearchpath.FindFile('crti.o',false,s) then
  122. LinkRes.AddFileName(s);
  123. end;
  124. while not ObjectFiles.Empty do
  125. begin
  126. s:=ObjectFiles.GetFirst;
  127. if s<>'' then
  128. begin
  129. { vlink doesn't use SEARCH_DIR for object files }
  130. if not(cs_link_on_target in current_settings.globalswitches) then
  131. s:=FindObjectFile(s,'',false);
  132. LinkRes.AddFileName((maybequoted(s)));
  133. end;
  134. end;
  135. { Write staticlibraries }
  136. if not StaticLibFiles.Empty then
  137. begin
  138. { vlink doesn't need, and doesn't support GROUP }
  139. if (cs_link_on_target in current_settings.globalswitches) then
  140. begin
  141. LinkRes.Add(')');
  142. LinkRes.Add('GROUP(');
  143. end;
  144. while not StaticLibFiles.Empty do
  145. begin
  146. S:=StaticLibFiles.GetFirst;
  147. LinkRes.AddFileName((maybequoted(s)));
  148. end;
  149. end;
  150. if (cs_link_on_target in current_settings.globalswitches) then
  151. begin
  152. LinkRes.Add(')');
  153. { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
  154. here to be sure that it gets linked this is needed for glibc2 systems (PFV) }
  155. linklibc:=false;
  156. while not SharedLibFiles.Empty do
  157. begin
  158. S:=SharedLibFiles.GetFirst;
  159. if s<>'c' then
  160. begin
  161. i:=Pos(target_info.sharedlibext,S);
  162. if i>0 then
  163. Delete(S,i,255);
  164. LinkRes.Add('-l'+s);
  165. end
  166. else
  167. begin
  168. LinkRes.Add('-l'+s);
  169. linklibc:=true;
  170. end;
  171. end;
  172. { be sure that libc&libgcc is the last lib }
  173. if linklibc then
  174. begin
  175. LinkRes.Add('-lc');
  176. LinkRes.Add('-lgcc');
  177. end;
  178. end
  179. else
  180. begin
  181. while not SharedLibFiles.Empty do
  182. begin
  183. S:=SharedLibFiles.GetFirst;
  184. LinkRes.Add('lib'+s+target_info.staticlibext);
  185. end;
  186. LinkRes.Add(')');
  187. end;
  188. { objects which must be at the end }
  189. if linklibc then
  190. begin
  191. found1:=librarysearchpath.FindFile('crtend.o',false,s1);
  192. found2:=librarysearchpath.FindFile('crtn.o',false,s2);
  193. if found1 or found2 then
  194. begin
  195. LinkRes.Add('INPUT(');
  196. if found1 then
  197. LinkRes.AddFileName(s1);
  198. if found2 then
  199. LinkRes.AddFileName(s2);
  200. LinkRes.Add(')');
  201. end;
  202. end;
  203. {$ifdef ARM}
  204. case current_settings.controllertype of
  205. ct_none:
  206. begin
  207. end;
  208. ct_lpc810m021fn8,
  209. ct_lpc811m001fdh16,
  210. ct_lpc812m101fdh16,
  211. ct_lpc812m101fd20,
  212. ct_lpc812m101fdh20,
  213. ct_lpc1110fd20,
  214. ct_lpc1111fdh20_002,
  215. ct_lpc1111fhn33_101,
  216. ct_lpc1111fhn33_102,
  217. ct_lpc1111fhn33_103,
  218. ct_lpc1111fhn33_201,
  219. ct_lpc1111fhn33_202,
  220. ct_lpc1111fhn33_203,
  221. ct_lpc1112fd20_102,
  222. ct_lpc1112fdh20_102,
  223. ct_lpc1112fdh28_102,
  224. ct_lpc1112fhn33_101,
  225. ct_lpc1112fhn33_102,
  226. ct_lpc1112fhn33_103,
  227. ct_lpc1112fhn33_201,
  228. ct_lpc1112fhn24_202,
  229. ct_lpc1112fhn33_202,
  230. ct_lpc1112fhn33_203,
  231. ct_lpc1112fhi33_202,
  232. ct_lpc1112fhi33_203,
  233. ct_lpc1113fhn33_201,
  234. ct_lpc1113fhn33_202,
  235. ct_lpc1113fhn33_203,
  236. ct_lpc1113fhn33_301,
  237. ct_lpc1113fhn33_302,
  238. ct_lpc1113fhn33_303,
  239. ct_lpc1113bfd48_301,
  240. ct_lpc1113bfd48_302,
  241. ct_lpc1113bfd48_303,
  242. ct_lpc1114fdh28_102,
  243. ct_lpc1114fn28_102,
  244. ct_lpc1114fhn33_201,
  245. ct_lpc1114fhn33_202,
  246. ct_lpc1114fhn33_203,
  247. ct_lpc1114fhn33_301,
  248. ct_lpc1114fhn33_302,
  249. ct_lpc1114fhn33_303,
  250. ct_lpc1114fhn33_333,
  251. ct_lpc1114fhi33_302,
  252. ct_lpc1114fhi33_303,
  253. ct_lpc1114bfd48_301,
  254. ct_lpc1114bfd48_302,
  255. ct_lpc1114bfd48_303,
  256. ct_lpc1114bfd48_323,
  257. ct_lpc1114bfd48_333,
  258. ct_lpc1115bfd48_303,
  259. ct_lpc11c12fd48_301,
  260. ct_lpc11c14fd48_301,
  261. ct_lpc11c22fd48_301,
  262. ct_lpc11c24fd48_301,
  263. ct_lpc11d24fd48_301,
  264. ct_lpc1224fbd48_101,
  265. ct_lpc1224fbd48_121,
  266. ct_lpc1224fbd64_101,
  267. ct_lpc1224fbd64_121,
  268. ct_lpc1225fbd48_301,
  269. ct_lpc1225fbd48_321,
  270. ct_lpc1225fbd64_301,
  271. ct_lpc1225fbd64_321,
  272. ct_lpc1226fbd48_301,
  273. ct_lpc1226fbd64_301,
  274. ct_lpc1227fbd48_301,
  275. ct_lpc1227fbd64_301,
  276. ct_lpc12d27fbd100_301,
  277. ct_lpc1311fhn33,
  278. ct_lpc1311fhn33_01,
  279. ct_lpc1313fhn33,
  280. ct_lpc1313fhn33_01,
  281. ct_lpc1313fbd48,
  282. ct_lpc1313fbd48_01,
  283. ct_lpc1315fhn33,
  284. ct_lpc1315fbd48,
  285. ct_lpc1316fhn33,
  286. ct_lpc1316fbd48,
  287. ct_lpc1317fhn33,
  288. ct_lpc1317fbd48,
  289. ct_lpc1317fbd64,
  290. ct_lpc1342fhn33,
  291. ct_lpc1342fbd48,
  292. ct_lpc1343fhn33,
  293. ct_lpc1343fbd48,
  294. ct_lpc1345fhn33,
  295. ct_lpc1345fbd48,
  296. ct_lpc1346fhn33,
  297. ct_lpc1346fbd48,
  298. ct_lpc1347fhn33,
  299. ct_lpc1347fbd48,
  300. ct_lpc1347fbd64,
  301. ct_lpc2114,
  302. ct_lpc2124,
  303. ct_lpc2194,
  304. ct_lpc1768,
  305. ct_at91sam7s256,
  306. ct_at91sam7se256,
  307. ct_at91sam7x256,
  308. ct_at91sam7xc256,
  309. ct_stm32f030c6,
  310. ct_stm32f030c8,
  311. ct_stm32f030f4,
  312. ct_stm32f030k6,
  313. ct_stm32f030r8,
  314. ct_stm32f050c4,
  315. ct_stm32f050c6,
  316. ct_stm32f050f4,
  317. ct_stm32f050f6,
  318. ct_stm32f050g4,
  319. ct_stm32f050g6,
  320. ct_stm32f050k4,
  321. ct_stm32f050k6,
  322. ct_stm32f051c4,
  323. ct_stm32f051c6,
  324. ct_stm32f051c8,
  325. ct_stm32f051k4,
  326. ct_stm32f051k6,
  327. ct_stm32f051k8,
  328. ct_stm32f051r4,
  329. ct_stm32f051r6,
  330. ct_stm32f051r8,
  331. ct_stm32f100x4,
  332. ct_stm32f100x6,
  333. ct_stm32f100x8,
  334. ct_stm32f100xB,
  335. ct_stm32f100xC,
  336. ct_stm32f100xD,
  337. ct_stm32f100xE,
  338. ct_stm32f101x4,
  339. ct_stm32f101x6,
  340. ct_stm32f101x8,
  341. ct_stm32f101xB,
  342. ct_stm32f101xC,
  343. ct_stm32f101xD,
  344. ct_stm32f101xE,
  345. ct_stm32f101xF,
  346. ct_stm32f101xG,
  347. ct_stm32f102x4,
  348. ct_stm32f102x6,
  349. ct_stm32f102x8,
  350. ct_stm32f102xB,
  351. ct_stm32f103x4,
  352. ct_stm32f103x6,
  353. ct_stm32f103x8,
  354. ct_stm32f103xB,
  355. ct_stm32f103xC,
  356. ct_stm32f103xD,
  357. ct_stm32f103xE,
  358. ct_stm32f103xF,
  359. ct_stm32f103xG,
  360. ct_stm32f107x8,
  361. ct_stm32f107xB,
  362. ct_stm32f107xC,
  363. ct_stm32f105r8,
  364. ct_stm32f105rb,
  365. ct_stm32f105rc,
  366. ct_stm32f105v8,
  367. ct_stm32f105vb,
  368. ct_stm32f105vc,
  369. ct_stm32f107rb,
  370. ct_stm32f107rc,
  371. ct_stm32f107vb,
  372. ct_stm32f107vc,
  373. ct_stm32f401cb,
  374. ct_stm32f401rb,
  375. ct_stm32f401vb,
  376. ct_stm32f401cc,
  377. ct_stm32f401rc,
  378. ct_stm32f401vc,
  379. ct_discoveryf401vc,
  380. ct_stm32f401cd,
  381. ct_stm32f401rd,
  382. ct_stm32f401vd,
  383. ct_stm32f401ce,
  384. ct_stm32f401re,
  385. ct_nucleof401re,
  386. ct_stm32f401ve,
  387. ct_stm32f407vg,
  388. ct_discoveryf407vg,
  389. ct_stm32f407ig,
  390. ct_stm32f407zg,
  391. ct_stm32f407ve,
  392. ct_stm32f407ze,
  393. ct_stm32f407ie,
  394. ct_stm32f411cc,
  395. ct_stm32f411rc,
  396. ct_stm32f411vc,
  397. ct_stm32f411ce,
  398. ct_stm32f411re,
  399. ct_nucleof411re,
  400. ct_stm32f411ve,
  401. ct_discoveryf411ve,
  402. ct_stm32f429vg,
  403. ct_stm32f429zg,
  404. ct_stm32f429ig,
  405. ct_stm32f429vi,
  406. ct_stm32f429zi,
  407. ct_discoveryf429zi,
  408. ct_stm32f429ii,
  409. ct_stm32f429ve,
  410. ct_stm32f429ze,
  411. ct_stm32f429ie,
  412. ct_stm32f429bg,
  413. ct_stm32f429bi,
  414. ct_stm32f429be,
  415. ct_stm32f429ng,
  416. ct_stm32f429ni,
  417. ct_stm32f429ne,
  418. ct_stm32f446mc,
  419. ct_stm32f446rc,
  420. ct_stm32f446vc,
  421. ct_stm32f446zc,
  422. ct_stm32f446me,
  423. ct_stm32f446re,
  424. ct_nucleof446re,
  425. ct_stm32f446ve,
  426. ct_stm32f446ze,
  427. ct_stm32f745xe,
  428. ct_stm32f745xg,
  429. ct_stm32f746xe,
  430. ct_stm32f746xg,
  431. ct_stm32f756xe,
  432. ct_stm32f756xg,
  433. { TI - 64 K Flash, 16 K SRAM Devices }
  434. ct_lm3s1110,
  435. ct_lm3s1133,
  436. ct_lm3s1138,
  437. ct_lm3s1150,
  438. ct_lm3s1162,
  439. ct_lm3s1165,
  440. ct_lm3s1166,
  441. ct_lm3s2110,
  442. ct_lm3s2139,
  443. ct_lm3s6100,
  444. ct_lm3s6110,
  445. { TI 128 K Flash, 32 K SRAM devices - Fury Class }
  446. ct_lm3s1601,
  447. ct_lm3s1608,
  448. ct_lm3s1620,
  449. ct_lm3s1635,
  450. ct_lm3s1636,
  451. ct_lm3s1637,
  452. ct_lm3s1651,
  453. ct_lm3s2601,
  454. ct_lm3s2608,
  455. ct_lm3s2620,
  456. ct_lm3s2637,
  457. ct_lm3s2651,
  458. ct_lm3s6610,
  459. ct_lm3s6611,
  460. ct_lm3s6618,
  461. ct_lm3s6633,
  462. ct_lm3s6637,
  463. ct_lm3s8630,
  464. { TI 256 K Flase, 32 K SRAM devices - Fury Class }
  465. ct_lm3s1911,
  466. ct_lm3s1918,
  467. ct_lm3s1937,
  468. ct_lm3s1958,
  469. ct_lm3s1960,
  470. ct_lm3s1968,
  471. ct_lm3s1969,
  472. ct_lm3s2911,
  473. ct_lm3s2918,
  474. ct_lm3s2919,
  475. ct_lm3s2939,
  476. ct_lm3s2948,
  477. ct_lm3s2950,
  478. ct_lm3s2965,
  479. ct_lm3s6911,
  480. ct_lm3s6918,
  481. ct_lm3s6938,
  482. ct_lm3s6950,
  483. ct_lm3s6952,
  484. ct_lm3s6965,
  485. ct_lm3s8930,
  486. ct_lm3s8933,
  487. ct_lm3s8938,
  488. ct_lm3s8962,
  489. ct_lm3s8970,
  490. ct_lm3s8971,
  491. { TI - Tempest Tempest - 256 K Flash, 64 K SRAM }
  492. ct_lm3s5951,
  493. ct_lm3s5956,
  494. ct_lm3s1b21,
  495. ct_lm3s2b93,
  496. ct_lm3s5b91,
  497. ct_lm3s9b81,
  498. ct_lm3s9b90,
  499. ct_lm3s9b92,
  500. ct_lm3s9b95,
  501. ct_lm3s9b96,
  502. ct_lm3s5d51,
  503. { TI - Stellaris something }
  504. ct_lm4f120h5,
  505. { Infineon }
  506. ct_xmc4500x1024,
  507. ct_xmc4500x768,
  508. ct_xmc4502x768,
  509. ct_xmc4504x512,
  510. { Allwinner }
  511. ct_allwinner_a20,
  512. { Freescale }
  513. ct_mk20dx128vfm5,
  514. ct_mk20dx128vft5,
  515. ct_mk20dx128vlf5,
  516. ct_mk20dx128vlh5,
  517. ct_teensy30,
  518. ct_mk20dx128vmp5,
  519. ct_mk20dx32vfm5,
  520. ct_mk20dx32vft5,
  521. ct_mk20dx32vlf5,
  522. ct_mk20dx32vlh5,
  523. ct_mk20dx32vmp5,
  524. ct_mk20dx64vfm5,
  525. ct_mk20dx64vft5,
  526. ct_mk20dx64vlf5,
  527. ct_mk20dx64vlh5,
  528. ct_mk20dx64vmp5,
  529. ct_mk20dx128vlh7,
  530. ct_mk20dx128vlk7,
  531. ct_mk20dx128vll7,
  532. ct_mk20dx128vmc7,
  533. ct_mk20dx256vlh7,
  534. ct_mk20dx256vlk7,
  535. ct_mk20dx256vll7,
  536. ct_mk20dx256vmc7,
  537. ct_teensy31,
  538. ct_teensy32,
  539. ct_mk20dx64vlh7,
  540. ct_mk20dx64vlk7,
  541. ct_mk20dx64vmc7,
  542. ct_mk22fn512cap12,
  543. ct_mk22fn512cbp12,
  544. ct_mk22fn512vdc12,
  545. ct_mk22fn512vlh12,
  546. ct_mk22fn512vll12,
  547. ct_mk22fn512vmp12,
  548. ct_freedom_k22f,
  549. { Atmel }
  550. ct_sam3x8e,
  551. ct_arduino_due,
  552. ct_flip_n_click,
  553. ct_sc32442b,
  554. ct_thumb2bare:
  555. begin
  556. with embedded_controllers[current_settings.controllertype] do
  557. with linkres do
  558. begin
  559. if (embedded_controllers[current_settings.controllertype].controllerunitstr='MK20D5')
  560. or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK20D7')
  561. or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK22F51212')
  562. or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK64F12') then
  563. Add('ENTRY(_LOWLEVELSTART)')
  564. else
  565. Add('ENTRY(_START)');
  566. Add('MEMORY');
  567. Add('{');
  568. if flashsize<>0 then
  569. begin
  570. LinkStr := ' flash : ORIGIN = 0x' + IntToHex(flashbase,8)
  571. + ', LENGTH = 0x' + IntToHex(flashsize,8);
  572. Add(LinkStr);
  573. end;
  574. LinkStr := ' ram : ORIGIN = 0x' + IntToHex(srambase,8)
  575. + ', LENGTH = 0x' + IntToHex(sramsize,8);
  576. Add(LinkStr);
  577. Add('}');
  578. Add('_stack_top = 0x' + IntToHex(sramsize+srambase,8) + ';');
  579. // Add Checksum Calculation for LPC Controllers so that the bootloader starts the uploaded binary
  580. writeln(controllerunitstr);
  581. if (controllerunitstr = 'LPC8xx') or (controllerunitstr = 'LPC11XX') or (controllerunitstr = 'LPC122X') then
  582. Add('Startup_Checksum = 0 - (_stack_top + _START + 1 + NonMaskableInt_interrupt + 1 + Hardfault_interrupt + 1);');
  583. if (controllerunitstr = 'LPC13XX') then
  584. Add('Startup_Checksum = 0 - (_stack_top + _START + 1 + NonMaskableInt_interrupt + 1 + MemoryManagement_interrupt + 1 + BusFault_interrupt + 1 + UsageFault_interrupt + 1);');
  585. end;
  586. end
  587. else
  588. if not (cs_link_nolink in current_settings.globalswitches) then
  589. internalerror(200902011);
  590. end;
  591. with linkres do
  592. begin
  593. Add('SECTIONS');
  594. Add('{');
  595. Add(' .text :');
  596. Add(' {');
  597. Add(' _text_start = .;');
  598. Add(' KEEP(*(.init, .init.*))');
  599. if (embedded_controllers[current_settings.controllertype].controllerunitstr='MK20D5')
  600. or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK20D7')
  601. or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK22F51212')
  602. or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK64F12') then
  603. begin
  604. Add(' . = 0x400;');
  605. Add(' KEEP(*(.flash_config, *.flash_config.*))');
  606. end;
  607. Add(' *(.text, .text.*)');
  608. Add(' *(.strings)');
  609. Add(' *(.rodata, .rodata.*)');
  610. Add(' *(.comment)');
  611. Add(' _etext = .;');
  612. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  613. begin
  614. Add(' } >flash');
  615. Add(' .note.gnu.build-id : { *(.note.gnu.build-id) } >flash ');
  616. end
  617. else
  618. begin
  619. Add(' } >ram');
  620. Add(' .note.gnu.build-id : { *(.note.gnu.build-id) } >ram ');
  621. end;
  622. Add(' .data :');
  623. Add(' {');
  624. Add(' _data = .;');
  625. Add(' *(.data, .data.*)');
  626. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  627. Add(' _edata = .;');
  628. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  629. begin
  630. Add(' } >ram AT >flash');
  631. end
  632. else
  633. begin
  634. Add(' } >ram');
  635. end;
  636. Add(' .bss :');
  637. Add(' {');
  638. Add(' _bss_start = .;');
  639. Add(' *(.bss, .bss.*)');
  640. Add(' *(COMMON)');
  641. Add(' } >ram');
  642. Add('. = ALIGN(4);');
  643. Add('_bss_end = . ;');
  644. Add('}');
  645. Add('_end = .;');
  646. end;
  647. {$endif ARM}
  648. {$ifdef i386}
  649. with linkres do
  650. begin
  651. Add('ENTRY(_START)');
  652. Add('SECTIONS');
  653. Add('{');
  654. Add(' . = 0x100000;');
  655. Add(' .text ALIGN (0x1000) :');
  656. Add(' {');
  657. Add(' _text = .;');
  658. Add(' KEEP(*(.init, .init.*))');
  659. Add(' *(.text, .text.*)');
  660. Add(' *(.strings)');
  661. Add(' *(.rodata, .rodata.*)');
  662. Add(' *(.comment)');
  663. Add(' _etext = .;');
  664. Add(' }');
  665. Add(' .data ALIGN (0x1000) :');
  666. Add(' {');
  667. Add(' _data = .;');
  668. Add(' *(.data, .data.*)');
  669. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  670. Add(' _edata = .;');
  671. Add(' }');
  672. Add(' . = ALIGN(4);');
  673. Add(' .bss :');
  674. Add(' {');
  675. Add(' _bss_start = .;');
  676. Add(' *(.bss, .bss.*)');
  677. Add(' *(COMMON)');
  678. Add(' }');
  679. Add('_bss_end = . ;');
  680. Add('}');
  681. Add('_end = .;');
  682. end;
  683. {$endif i386}
  684. {$ifdef AVR}
  685. with linkres do
  686. begin
  687. { linker script from ld 2.19 }
  688. Add('ENTRY(_START)');
  689. Add('OUTPUT_FORMAT("elf32-avr","elf32-avr","elf32-avr")');
  690. case current_settings.cputype of
  691. cpu_avr1:
  692. Add('OUTPUT_ARCH(avr:1)');
  693. cpu_avr2:
  694. Add('OUTPUT_ARCH(avr:2)');
  695. cpu_avr25:
  696. Add('OUTPUT_ARCH(avr:25)');
  697. cpu_avr3:
  698. Add('OUTPUT_ARCH(avr:3)');
  699. cpu_avr31:
  700. Add('OUTPUT_ARCH(avr:31)');
  701. cpu_avr35:
  702. Add('OUTPUT_ARCH(avr:35)');
  703. cpu_avr4:
  704. Add('OUTPUT_ARCH(avr:4)');
  705. cpu_avr5:
  706. Add('OUTPUT_ARCH(avr:5)');
  707. cpu_avr51:
  708. Add('OUTPUT_ARCH(avr:51)');
  709. cpu_avr6:
  710. Add('OUTPUT_ARCH(avr:6)');
  711. else
  712. Internalerror(2015072701);
  713. end;
  714. Add('MEMORY');
  715. with embedded_controllers[current_settings.controllertype] do
  716. begin
  717. Add('{');
  718. Add(' text (rx) : ORIGIN = 0, LENGTH = 0x'+IntToHex(flashsize,6));
  719. Add(' data (rw!x) : ORIGIN = 0x'+IntToHex($800000+srambase,6)+', LENGTH = 0x'+IntToHex(sramsize,6));
  720. Add(' eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = 0x'+IntToHex(eepromsize,6));
  721. Add(' fuse (rw!x) : ORIGIN = 0x820000, LENGTH = 1K');
  722. Add(' lock (rw!x) : ORIGIN = 0x830000, LENGTH = 1K');
  723. Add(' signature (rw!x) : ORIGIN = 0x840000, LENGTH = 1K');
  724. Add('}');
  725. Add('_stack_top = 0x' + IntToHex(srambase+sramsize-1,4) + ';');
  726. end;
  727. Add('SECTIONS');
  728. Add('{');
  729. Add(' /* Read-only sections, merged into text segment: */');
  730. Add(' .hash : { *(.hash) }');
  731. Add(' .dynsym : { *(.dynsym) }');
  732. Add(' .dynstr : { *(.dynstr) }');
  733. Add(' .gnu.version : { *(.gnu.version) }');
  734. Add(' .gnu.version_d : { *(.gnu.version_d) }');
  735. Add(' .gnu.version_r : { *(.gnu.version_r) }');
  736. Add(' .rel.init : { *(.rel.init) }');
  737. Add(' .rela.init : { *(.rela.init) }');
  738. Add(' .rel.text :');
  739. Add(' {');
  740. Add(' *(.rel.text)');
  741. Add(' *(.rel.text.*)');
  742. Add(' *(.rel.gnu.linkonce.t*)');
  743. Add(' }');
  744. Add(' .rela.text :');
  745. Add(' {');
  746. Add(' *(.rela.text)');
  747. Add(' *(.rela.text.*)');
  748. Add(' *(.rela.gnu.linkonce.t*)');
  749. Add(' }');
  750. Add(' .rel.fini : { *(.rel.fini) }');
  751. Add(' .rela.fini : { *(.rela.fini) }');
  752. Add(' .rel.rodata :');
  753. Add(' {');
  754. Add(' *(.rel.rodata)');
  755. Add(' *(.rel.rodata.*)');
  756. Add(' *(.rel.gnu.linkonce.r*)');
  757. Add(' }');
  758. Add(' .rela.rodata :');
  759. Add(' {');
  760. Add(' *(.rela.rodata)');
  761. Add(' *(.rela.rodata.*)');
  762. Add(' *(.rela.gnu.linkonce.r*)');
  763. Add(' }');
  764. Add(' .rel.data :');
  765. Add(' {');
  766. Add(' *(.rel.data)');
  767. Add(' *(.rel.data.*)');
  768. Add(' *(.rel.gnu.linkonce.d*)');
  769. Add(' }');
  770. Add(' .rela.data :');
  771. Add(' {');
  772. Add(' *(.rela.data)');
  773. Add(' *(.rela.data.*)');
  774. Add(' *(.rela.gnu.linkonce.d*)');
  775. Add(' }');
  776. Add(' .rel.ctors : { *(.rel.ctors) }');
  777. Add(' .rela.ctors : { *(.rela.ctors) }');
  778. Add(' .rel.dtors : { *(.rel.dtors) }');
  779. Add(' .rela.dtors : { *(.rela.dtors) }');
  780. Add(' .rel.got : { *(.rel.got) }');
  781. Add(' .rela.got : { *(.rela.got) }');
  782. Add(' .rel.bss : { *(.rel.bss) }');
  783. Add(' .rela.bss : { *(.rela.bss) }');
  784. Add(' .rel.plt : { *(.rel.plt) }');
  785. Add(' .rela.plt : { *(.rela.plt) }');
  786. Add(' /* Internal text space or external memory. */');
  787. Add(' .text :');
  788. Add(' {');
  789. Add(' KEEP(*(.init, .init.*))');
  790. Add(' /* For data that needs to reside in the lower 64k of progmem. */');
  791. Add(' *(.progmem.gcc*)');
  792. Add(' *(.progmem*)');
  793. Add(' . = ALIGN(2);');
  794. Add(' __trampolines_start = . ;');
  795. Add(' /* The jump trampolines for the 16-bit limited relocs will reside here. */');
  796. Add(' *(.trampolines)');
  797. Add(' *(.trampolines*)');
  798. Add(' __trampolines_end = . ;');
  799. Add(' /* For future tablejump instruction arrays for 3 byte pc devices.');
  800. Add(' We don''t relax jump/call instructions within these sections. */');
  801. Add(' *(.jumptables)');
  802. Add(' *(.jumptables*)');
  803. Add(' /* For code that needs to reside in the lower 128k progmem. */');
  804. Add(' *(.lowtext)');
  805. Add(' *(.lowtext*)');
  806. Add(' __ctors_start = . ;');
  807. Add(' *(.ctors)');
  808. Add(' __ctors_end = . ;');
  809. Add(' __dtors_start = . ;');
  810. Add(' *(.dtors)');
  811. Add(' __dtors_end = . ;');
  812. Add(' KEEP(SORT(*)(.ctors))');
  813. Add(' KEEP(SORT(*)(.dtors))');
  814. Add(' /* From this point on, we don''t bother about wether the insns are');
  815. Add(' below or above the 16 bits boundary. */');
  816. Add(' *(.init0) /* Start here after reset. */');
  817. Add(' KEEP (*(.init0))');
  818. Add(' *(.init1)');
  819. Add(' KEEP (*(.init1))');
  820. Add(' *(.init2) /* Clear __zero_reg__, set up stack pointer. */');
  821. Add(' KEEP (*(.init2))');
  822. Add(' *(.init3)');
  823. Add(' KEEP (*(.init3))');
  824. Add(' *(.init4) /* Initialize data and BSS. */');
  825. Add(' KEEP (*(.init4))');
  826. Add(' *(.init5)');
  827. Add(' KEEP (*(.init5))');
  828. Add(' *(.init6) /* C++ constructors. */');
  829. Add(' KEEP (*(.init6))');
  830. Add(' *(.init7)');
  831. Add(' KEEP (*(.init7))');
  832. Add(' *(.init8)');
  833. Add(' KEEP (*(.init8))');
  834. Add(' *(.init9) /* Call main(). */');
  835. Add(' KEEP (*(.init9))');
  836. Add(' *(.text)');
  837. Add(' . = ALIGN(2);');
  838. Add(' *(.text.*)');
  839. Add(' . = ALIGN(2);');
  840. Add(' *(.fini9) /* _exit() starts here. */');
  841. Add(' KEEP (*(.fini9))');
  842. Add(' *(.fini8)');
  843. Add(' KEEP (*(.fini8))');
  844. Add(' *(.fini7)');
  845. Add(' KEEP (*(.fini7))');
  846. Add(' *(.fini6) /* C++ destructors. */');
  847. Add(' KEEP (*(.fini6))');
  848. Add(' *(.fini5)');
  849. Add(' KEEP (*(.fini5))');
  850. Add(' *(.fini4)');
  851. Add(' KEEP (*(.fini4))');
  852. Add(' *(.fini3)');
  853. Add(' KEEP (*(.fini3))');
  854. Add(' *(.fini2)');
  855. Add(' KEEP (*(.fini2))');
  856. Add(' *(.fini1)');
  857. Add(' KEEP (*(.fini1))');
  858. Add(' *(.fini0) /* Infinite loop after program termination. */');
  859. Add(' KEEP (*(.fini0))');
  860. Add(' _etext = . ;');
  861. Add(' } > text');
  862. Add(' .data : AT (ADDR (.text) + SIZEOF (.text))');
  863. Add(' {');
  864. Add(' PROVIDE (__data_start = .) ;');
  865. Add(' *(.data)');
  866. Add(' *(.data*)');
  867. Add(' *(.rodata) /* We need to include .rodata here if gcc is used */');
  868. Add(' *(.rodata*) /* with -fdata-sections. */');
  869. Add(' *(.gnu.linkonce.d*)');
  870. Add(' . = ALIGN(2);');
  871. Add(' _edata = . ;');
  872. Add(' PROVIDE (__data_end = .) ;');
  873. Add(' } > data');
  874. Add(' .bss : AT (ADDR (.bss))');
  875. Add(' {');
  876. Add(' PROVIDE (__bss_start = .) ;');
  877. Add(' *(.bss)');
  878. Add(' *(.bss*)');
  879. Add(' *(COMMON)');
  880. Add(' PROVIDE (__bss_end = .) ;');
  881. Add(' } > data');
  882. Add(' __data_load_start = LOADADDR(.data);');
  883. Add(' __data_load_end = __data_load_start + SIZEOF(.data);');
  884. Add(' /* Global data not cleared after reset. */');
  885. Add(' .noinit :');
  886. Add(' {');
  887. Add(' PROVIDE (__noinit_start = .) ;');
  888. Add(' *(.noinit*)');
  889. Add(' PROVIDE (__noinit_end = .) ;');
  890. Add(' _end = . ;');
  891. Add(' PROVIDE (__heap_start = .) ;');
  892. Add(' } > data');
  893. Add(' .eeprom :');
  894. Add(' {');
  895. Add(' *(.eeprom*)');
  896. Add(' __eeprom_end = . ;');
  897. Add(' } > eeprom');
  898. Add(' .fuse :');
  899. Add(' {');
  900. Add(' KEEP(*(.fuse))');
  901. Add(' KEEP(*(.lfuse))');
  902. Add(' KEEP(*(.hfuse))');
  903. Add(' KEEP(*(.efuse))');
  904. Add(' } > fuse');
  905. Add(' .lock :');
  906. Add(' {');
  907. Add(' KEEP(*(.lock*))');
  908. Add(' } > lock');
  909. Add(' .signature :');
  910. Add(' {');
  911. Add(' KEEP(*(.signature*))');
  912. Add(' } > signature');
  913. Add(' /* Stabs debugging sections. */');
  914. Add(' .stab 0 : { *(.stab) }');
  915. Add(' .stabstr 0 : { *(.stabstr) }');
  916. Add(' .stab.excl 0 : { *(.stab.excl) }');
  917. Add(' .stab.exclstr 0 : { *(.stab.exclstr) }');
  918. Add(' .stab.index 0 : { *(.stab.index) }');
  919. Add(' .stab.indexstr 0 : { *(.stab.indexstr) }');
  920. Add(' .comment 0 : { *(.comment) }');
  921. Add(' /* DWARF debug sections.');
  922. Add(' Symbols in the DWARF debugging sections are relative to the beginning');
  923. Add(' of the section so we begin them at 0. */');
  924. Add(' /* DWARF 1 */');
  925. Add(' .debug 0 : { *(.debug) }');
  926. Add(' .line 0 : { *(.line) }');
  927. Add(' /* GNU DWARF 1 extensions */');
  928. Add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  929. Add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  930. Add(' /* DWARF 1.1 and DWARF 2 */');
  931. Add(' .debug_aranges 0 : { *(.debug_aranges) }');
  932. Add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  933. Add(' /* DWARF 2 */');
  934. Add(' .debug_info 0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }');
  935. Add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  936. Add(' .debug_line 0 : { *(.debug_line) }');
  937. Add(' .debug_frame 0 : { *(.debug_frame) }');
  938. Add(' .debug_str 0 : { *(.debug_str) }');
  939. Add(' .debug_loc 0 : { *(.debug_loc) }');
  940. Add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  941. Add('}');
  942. end;
  943. {$endif AVR}
  944. {$ifdef MIPSEL}
  945. case current_settings.controllertype of
  946. ct_none:
  947. begin
  948. end;
  949. ct_pic32mx110f016b,
  950. ct_pic32mx110f016c,
  951. ct_pic32mx110f016d,
  952. ct_pic32mx120f032b,
  953. ct_pic32mx120f032c,
  954. ct_pic32mx120f032d,
  955. ct_pic32mx130f064b,
  956. ct_pic32mx130f064c,
  957. ct_pic32mx130f064d,
  958. ct_pic32mx150f128b,
  959. ct_pic32mx150f128c,
  960. ct_pic32mx150f128d,
  961. ct_pic32mx210f016b,
  962. ct_pic32mx210f016c,
  963. ct_pic32mx210f016d,
  964. ct_pic32mx220f032b,
  965. ct_pic32mx220f032c,
  966. ct_pic32mx220f032d,
  967. ct_pic32mx230f064b,
  968. ct_pic32mx230f064c,
  969. ct_pic32mx230f064d,
  970. ct_pic32mx250f128b,
  971. ct_pic32mx250f128c,
  972. ct_pic32mx250f128d,
  973. ct_pic32mx775f256h,
  974. ct_pic32mx775f256l,
  975. ct_pic32mx775f512h,
  976. ct_pic32mx775f512l,
  977. ct_pic32mx795f512h,
  978. ct_pic32mx795f512l:
  979. begin
  980. with embedded_controllers[current_settings.controllertype] do
  981. with linkres do
  982. begin
  983. Add('OUTPUT_FORMAT("elf32-tradlittlemips")');
  984. Add('OUTPUT_ARCH(pic32mx)');
  985. Add('ENTRY(_reset)');
  986. Add('PROVIDE(_vector_spacing = 0x00000001);');
  987. Add('_ebase_address = 0x'+IntToHex(flashbase,8)+';');
  988. Add('_RESET_ADDR = 0xBFC00000;');
  989. Add('_BEV_EXCPT_ADDR = 0xBFC00380;');
  990. Add('_DBG_EXCPT_ADDR = 0xBFC00480;');
  991. Add('_GEN_EXCPT_ADDR = _ebase_address + 0x180;');
  992. Add('MEMORY');
  993. Add('{');
  994. if flashsize<>0 then
  995. begin
  996. Add(' kseg0_program_mem : ORIGIN = 0x'+IntToHex(flashbase,8)+', LENGTH = 0x'+IntToHex(flashsize,8));
  997. //TODO This should better be placed into the controllertype records
  998. Add(' kseg1_boot_mem : ORIGIN = 0xBFC00000, LENGTH = 0xbef');
  999. Add(' config3 : ORIGIN = 0xBFC00BF0, LENGTH = 0x4');
  1000. Add(' config2 : ORIGIN = 0xBFC00BF4, LENGTH = 0x4');
  1001. Add(' config1 : ORIGIN = 0xBFC00BF8, LENGTH = 0x4');
  1002. Add(' config0 : ORIGIN = 0xBFC00BFC, LENGTH = 0x4');
  1003. end;
  1004. Add(' ram : ORIGIN = 0x' + IntToHex(srambase,8)
  1005. + ', LENGTH = 0x' + IntToHex(sramsize,8));
  1006. Add('}');
  1007. Add('_stack_top = 0x' + IntToHex(sramsize+srambase,8) + ';');
  1008. end;
  1009. end
  1010. else
  1011. if not (cs_link_nolink in current_settings.globalswitches) then
  1012. internalerror(200902011);
  1013. end;
  1014. with linkres do
  1015. begin
  1016. Add('SECTIONS');
  1017. Add('{');
  1018. Add(' .reset _RESET_ADDR :');
  1019. Add(' {');
  1020. Add(' KEEP(*(.reset .reset.*))');
  1021. Add(' KEEP(*(.startup .startup.*))');
  1022. Add(' } > kseg1_boot_mem');
  1023. Add(' .bev_excpt _BEV_EXCPT_ADDR :');
  1024. Add(' {');
  1025. Add(' KEEP(*(.bev_handler))');
  1026. Add(' } > kseg1_boot_mem');
  1027. Add(' .text :');
  1028. Add(' {');
  1029. Add(' _text_start = .;');
  1030. Add(' . = _text_start + 0x180;');
  1031. Add(' KEEP(*(.gen_handler))');
  1032. Add(' . = _text_start + 0x200;');
  1033. Add(' KEEP(*(.init .init.*))');
  1034. Add(' *(.text .text.*)');
  1035. Add(' *(.strings)');
  1036. Add(' *(.rodata .rodata.*)');
  1037. Add(' *(.comment)');
  1038. Add(' _etext = .;');
  1039. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  1040. begin
  1041. Add(' } >kseg0_program_mem');
  1042. end
  1043. else
  1044. begin
  1045. Add(' } >ram');
  1046. end;
  1047. Add(' .note.gnu.build-id : { *(.note.gnu.build-id) }');
  1048. Add(' .data :');
  1049. Add(' {');
  1050. Add(' _data = .;');
  1051. Add(' *(.data .data.*)');
  1052. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  1053. Add(' . = .;');
  1054. Add(' _gp = ALIGN(16) + 0x7ff0;');
  1055. Add(' _edata = .;');
  1056. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  1057. begin
  1058. Add(' } >ram AT >kseg0_program_mem');
  1059. end
  1060. else
  1061. begin
  1062. Add(' } >ram');
  1063. end;
  1064. Add(' .config_BFC00BF0 : {');
  1065. Add(' KEEP(*(.config_BFC00BF0))');
  1066. Add(' } > config3');
  1067. Add(' .config_BFC00BF4 : {');
  1068. Add(' KEEP(*(.config_BFC00BF4))');
  1069. Add(' } > config2');
  1070. Add(' .config_BFC00BF8 : {');
  1071. Add(' KEEP(*(.config_BFC00BF8))');
  1072. Add(' } > config1');
  1073. Add(' .config_BFC00BFC : {');
  1074. Add(' KEEP(*(.config_BFC00BFC))');
  1075. Add(' } > config0');
  1076. Add(' .bss :');
  1077. Add(' {');
  1078. Add(' _bss_start = .;');
  1079. Add(' *(.bss, .bss.*)');
  1080. Add(' *(COMMON)');
  1081. Add(' } >ram');
  1082. Add('. = ALIGN(4);');
  1083. Add('_bss_end = . ;');
  1084. Add(' .comment 0 : { *(.comment) }');
  1085. Add(' /* DWARF debug sections.');
  1086. Add(' Symbols in the DWARF debugging sections are relative to the beginning');
  1087. Add(' of the section so we begin them at 0. */');
  1088. Add(' /* DWARF 1 */');
  1089. Add(' .debug 0 : { *(.debug) }');
  1090. Add(' .line 0 : { *(.line) }');
  1091. Add(' /* GNU DWARF 1 extensions */');
  1092. Add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  1093. Add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  1094. Add(' /* DWARF 1.1 and DWARF 2 */');
  1095. Add(' .debug_aranges 0 : { *(.debug_aranges) }');
  1096. Add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  1097. Add(' /* DWARF 2 */');
  1098. Add(' .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }');
  1099. Add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  1100. Add(' /DISCARD/ : { *(.debug_line) }');
  1101. Add(' .debug_frame 0 : { *(.debug_frame) }');
  1102. Add(' .debug_str 0 : { *(.debug_str) }');
  1103. Add(' /DISCARD/ : { *(.debug_loc) }');
  1104. Add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  1105. Add(' /* SGI/MIPS DWARF 2 extensions */');
  1106. Add(' .debug_weaknames 0 : { *(.debug_weaknames) }');
  1107. Add(' .debug_funcnames 0 : { *(.debug_funcnames) }');
  1108. Add(' .debug_typenames 0 : { *(.debug_typenames) }');
  1109. Add(' .debug_varnames 0 : { *(.debug_varnames) }');
  1110. Add(' /* DWARF 3 */');
  1111. Add(' .debug_pubtypes 0 : { *(.debug_pubtypes) }');
  1112. Add(' .debug_ranges 0 : { *(.debug_ranges) }');
  1113. Add(' .gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }');
  1114. Add(' .gptab.sdata : { *(.gptab.data) *(.gptab.sdata) }');
  1115. Add(' .gptab.sbss : { *(.gptab.bss) *(.gptab.sbss) }');
  1116. Add(' .mdebug.abi32 : { KEEP(*(.mdebug.abi32)) }');
  1117. Add(' .mdebug.abiN32 : { KEEP(*(.mdebug.abiN32)) }');
  1118. Add(' .mdebug.abi64 : { KEEP(*(.mdebug.abi64)) }');
  1119. Add(' .mdebug.abiO64 : { KEEP(*(.mdebug.abiO64)) }');
  1120. Add(' .mdebug.eabi32 : { KEEP(*(.mdebug.eabi32)) }');
  1121. Add(' .mdebug.eabi64 : { KEEP(*(.mdebug.eabi64)) }');
  1122. Add(' /DISCARD/ : { *(.rel.dyn) }');
  1123. Add(' /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }');
  1124. Add('}');
  1125. Add('_end = .;');
  1126. end;
  1127. {$endif MIPSEL}
  1128. { Write and Close response }
  1129. linkres.writetodisk;
  1130. linkres.free;
  1131. WriteResponseFile:=True;
  1132. end;
  1133. function TlinkerEmbedded.MakeExecutable:boolean;
  1134. var
  1135. binstr,
  1136. cmdstr : TCmdStr;
  1137. success : boolean;
  1138. StaticStr,
  1139. GCSectionsStr,
  1140. DynLinkStr,
  1141. StripStr: string;
  1142. begin
  1143. { for future use }
  1144. StaticStr:='';
  1145. StripStr:='';
  1146. DynLinkStr:='';
  1147. GCSectionsStr:='--gc-sections';
  1148. //if not(cs_link_extern in current_settings.globalswitches) then
  1149. if not(cs_link_nolink in current_settings.globalswitches) then
  1150. Message1(exec_i_linking,current_module.exefilename);
  1151. { Write used files and libraries }
  1152. WriteResponseFile();
  1153. { Call linker }
  1154. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  1155. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  1156. if not(cs_link_on_target in current_settings.globalswitches) then
  1157. begin
  1158. Replace(cmdstr,'$EXE',(maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.elf')))));
  1159. Replace(cmdstr,'$RES',(maybequoted(ScriptFixFileName(outputexedir+Info.ResName))));
  1160. Replace(cmdstr,'$STATIC',StaticStr);
  1161. Replace(cmdstr,'$STRIP',StripStr);
  1162. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  1163. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  1164. end
  1165. else
  1166. begin
  1167. Replace(cmdstr,'$EXE',maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.elf'))));
  1168. Replace(cmdstr,'$RES',maybequoted(ScriptFixFileName(outputexedir+Info.ResName)));
  1169. Replace(cmdstr,'$STATIC',StaticStr);
  1170. Replace(cmdstr,'$STRIP',StripStr);
  1171. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  1172. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  1173. end;
  1174. success:=DoExec(FindUtil(utilsprefix+BinStr),cmdstr,true,false);
  1175. { Remove ReponseFile }
  1176. if success and not(cs_link_nolink in current_settings.globalswitches) then
  1177. DeleteFile(outputexedir+Info.ResName);
  1178. { Post process }
  1179. if success and not(cs_link_nolink in current_settings.globalswitches) then
  1180. success:=PostProcessExecutable(current_module.exefilename+'.elf',false);
  1181. if success and (target_info.system in [system_arm_embedded,system_avr_embedded,system_mipsel_embedded]) then
  1182. begin
  1183. success:=DoExec(FindUtil(utilsprefix+'objcopy'),'-O ihex '+
  1184. ChangeFileExt(current_module.exefilename,'.elf')+' '+
  1185. ChangeFileExt(current_module.exefilename,'.hex'),true,false);
  1186. if success then
  1187. success:=DoExec(FindUtil(utilsprefix+'objcopy'),'-O binary '+
  1188. ChangeFileExt(current_module.exefilename,'.elf')+' '+
  1189. ChangeFileExt(current_module.exefilename,'.bin'),true,false);
  1190. end;
  1191. MakeExecutable:=success; { otherwise a recursive call to link method }
  1192. end;
  1193. function TLinkerEmbedded.postprocessexecutable(const fn : string;isdll:boolean):boolean;
  1194. type
  1195. TElf32header=packed record
  1196. magic0123 : longint;
  1197. file_class : byte;
  1198. data_encoding : byte;
  1199. file_version : byte;
  1200. padding : array[$07..$0f] of byte;
  1201. e_type : word;
  1202. e_machine : word;
  1203. e_version : longint;
  1204. e_entry : longint; { entrypoint }
  1205. e_phoff : longint; { program header offset }
  1206. e_shoff : longint; { sections header offset }
  1207. e_flags : longint;
  1208. e_ehsize : word; { elf header size in bytes }
  1209. e_phentsize : word; { size of an entry in the program header array }
  1210. e_phnum : word; { 0..e_phnum-1 of entrys }
  1211. e_shentsize : word; { size of an entry in sections header array }
  1212. e_shnum : word; { 0..e_shnum-1 of entrys }
  1213. e_shstrndx : word; { index of string section header }
  1214. end;
  1215. TElf32sechdr=packed record
  1216. sh_name : longint;
  1217. sh_type : longint;
  1218. sh_flags : longint;
  1219. sh_addr : longint;
  1220. sh_offset : longint;
  1221. sh_size : longint;
  1222. sh_link : longint;
  1223. sh_info : longint;
  1224. sh_addralign : longint;
  1225. sh_entsize : longint;
  1226. end;
  1227. function MayBeSwapHeader(h : telf32header) : telf32header;
  1228. begin
  1229. result:=h;
  1230. if source_info.endian<>target_info.endian then
  1231. with h do
  1232. begin
  1233. result.e_type:=swapendian(e_type);
  1234. result.e_machine:=swapendian(e_machine);
  1235. result.e_version:=swapendian(e_version);
  1236. result.e_entry:=swapendian(e_entry);
  1237. result.e_phoff:=swapendian(e_phoff);
  1238. result.e_shoff:=swapendian(e_shoff);
  1239. result.e_flags:=swapendian(e_flags);
  1240. result.e_ehsize:=swapendian(e_ehsize);
  1241. result.e_phentsize:=swapendian(e_phentsize);
  1242. result.e_phnum:=swapendian(e_phnum);
  1243. result.e_shentsize:=swapendian(e_shentsize);
  1244. result.e_shnum:=swapendian(e_shnum);
  1245. result.e_shstrndx:=swapendian(e_shstrndx);
  1246. end;
  1247. end;
  1248. function MaybeSwapSecHeader(h : telf32sechdr) : telf32sechdr;
  1249. begin
  1250. result:=h;
  1251. if source_info.endian<>target_info.endian then
  1252. with h do
  1253. begin
  1254. result.sh_name:=swapendian(sh_name);
  1255. result.sh_type:=swapendian(sh_type);
  1256. result.sh_flags:=swapendian(sh_flags);
  1257. result.sh_addr:=swapendian(sh_addr);
  1258. result.sh_offset:=swapendian(sh_offset);
  1259. result.sh_size:=swapendian(sh_size);
  1260. result.sh_link:=swapendian(sh_link);
  1261. result.sh_info:=swapendian(sh_info);
  1262. result.sh_addralign:=swapendian(sh_addralign);
  1263. result.sh_entsize:=swapendian(sh_entsize);
  1264. end;
  1265. end;
  1266. var
  1267. f : file;
  1268. function ReadSectionName(pos : longint) : String;
  1269. var
  1270. oldpos : longint;
  1271. c : char;
  1272. begin
  1273. oldpos:=filepos(f);
  1274. seek(f,pos);
  1275. Result:='';
  1276. while true do
  1277. begin
  1278. blockread(f,c,1);
  1279. if c=#0 then
  1280. break;
  1281. Result:=Result+c;
  1282. end;
  1283. seek(f,oldpos);
  1284. end;
  1285. var
  1286. elfheader : TElf32header;
  1287. secheader : TElf32sechdr;
  1288. i : longint;
  1289. stringoffset : longint;
  1290. secname : string;
  1291. begin
  1292. postprocessexecutable:=false;
  1293. { open file }
  1294. assign(f,fn);
  1295. {$push}{$I-}
  1296. reset(f,1);
  1297. if ioresult<>0 then
  1298. Message1(execinfo_f_cant_open_executable,fn);
  1299. { read header }
  1300. blockread(f,elfheader,sizeof(tElf32header));
  1301. elfheader:=MayBeSwapHeader(elfheader);
  1302. seek(f,elfheader.e_shoff);
  1303. { read string section header }
  1304. seek(f,elfheader.e_shoff+sizeof(TElf32sechdr)*elfheader.e_shstrndx);
  1305. blockread(f,secheader,sizeof(secheader));
  1306. secheader:=MaybeSwapSecHeader(secheader);
  1307. stringoffset:=secheader.sh_offset;
  1308. seek(f,elfheader.e_shoff);
  1309. status.datasize:=0;
  1310. for i:=0 to elfheader.e_shnum-1 do
  1311. begin
  1312. blockread(f,secheader,sizeof(secheader));
  1313. secheader:=MaybeSwapSecHeader(secheader);
  1314. secname:=ReadSectionName(stringoffset+secheader.sh_name);
  1315. if secname='.text' then
  1316. begin
  1317. Message1(execinfo_x_codesize,tostr(secheader.sh_size));
  1318. status.codesize:=secheader.sh_size;
  1319. end
  1320. else if secname='.data' then
  1321. begin
  1322. Message1(execinfo_x_initdatasize,tostr(secheader.sh_size));
  1323. inc(status.datasize,secheader.sh_size);
  1324. end
  1325. else if secname='.bss' then
  1326. begin
  1327. Message1(execinfo_x_uninitdatasize,tostr(secheader.sh_size));
  1328. inc(status.datasize,secheader.sh_size);
  1329. end;
  1330. end;
  1331. close(f);
  1332. {$pop}
  1333. if ioresult<>0 then
  1334. ;
  1335. postprocessexecutable:=true;
  1336. end;
  1337. {*****************************************************************************
  1338. Initialize
  1339. *****************************************************************************}
  1340. initialization
  1341. {$ifdef arm}
  1342. RegisterLinker(ld_embedded,TLinkerEmbedded);
  1343. RegisterTarget(system_arm_embedded_info);
  1344. {$endif arm}
  1345. {$ifdef avr}
  1346. RegisterLinker(ld_embedded,TLinkerEmbedded);
  1347. RegisterTarget(system_avr_embedded_info);
  1348. {$endif avr}
  1349. {$ifdef i386}
  1350. RegisterLinker(ld_embedded,TLinkerEmbedded);
  1351. RegisterTarget(system_i386_embedded_info);
  1352. {$endif i386}
  1353. {$ifdef mipsel}
  1354. RegisterLinker(ld_embedded,TLinkerEmbedded);
  1355. RegisterTarget(system_mipsel_embedded_info);
  1356. {$endif mipsel}
  1357. end.