t_embed.pas 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864
  1. {
  2. Copyright (c) 2005-2017 by Free Pascal Compiler team
  3. This unit implements support import, export, link routines
  4. for the Embedded 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_embed;
  19. {$i fpcdefs.inc}
  20. interface
  21. implementation
  22. uses
  23. SysUtils,
  24. cutils,cfileutl,cclasses,
  25. globtype,globals,systems,verbose,comphook,cscript,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 $MAP -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(x86_64) or defined(AVR) or defined(MIPSEL) or defined(RISCV32) or defined(XTENSA)}
  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_stm32f091cc,
  332. ct_stm32f091cb,
  333. ct_stm32f091rc,
  334. ct_stm32f091rb,
  335. ct_stm32f091vc,
  336. ct_stm32f091vb,
  337. ct_stm32f100x4,
  338. ct_stm32f100x6,
  339. ct_stm32f100x8,
  340. ct_stm32f100xB,
  341. ct_stm32f100xC,
  342. ct_stm32f100xD,
  343. ct_stm32f100xE,
  344. ct_stm32f101x4,
  345. ct_stm32f101x6,
  346. ct_stm32f101x8,
  347. ct_stm32f101xB,
  348. ct_stm32f101xC,
  349. ct_stm32f101xD,
  350. ct_stm32f101xE,
  351. ct_stm32f101xF,
  352. ct_stm32f101xG,
  353. ct_stm32f102x4,
  354. ct_stm32f102x6,
  355. ct_stm32f102x8,
  356. ct_stm32f102xB,
  357. ct_stm32f103x4,
  358. ct_stm32f103x6,
  359. ct_stm32f103x8,
  360. ct_stm32f103xB,
  361. ct_stm32f103xC,
  362. ct_stm32f103xD,
  363. ct_stm32f103xE,
  364. ct_stm32f103xF,
  365. ct_stm32f103xG,
  366. ct_stm32f107x8,
  367. ct_stm32f107xB,
  368. ct_stm32f107xC,
  369. ct_stm32f105r8,
  370. ct_stm32f105rb,
  371. ct_stm32f105rc,
  372. ct_stm32f105v8,
  373. ct_stm32f105vb,
  374. ct_stm32f105vc,
  375. ct_stm32f107rb,
  376. ct_stm32f107rc,
  377. ct_stm32f107vb,
  378. ct_stm32f107vc,
  379. ct_stm32f401cb,
  380. ct_stm32f401rb,
  381. ct_stm32f401vb,
  382. ct_stm32f401cc,
  383. ct_stm32f401rc,
  384. ct_stm32f401vc,
  385. ct_discoveryf401vc,
  386. ct_stm32f401cd,
  387. ct_stm32f401rd,
  388. ct_stm32f401vd,
  389. ct_stm32f401ce,
  390. ct_stm32f401re,
  391. ct_nucleof401re,
  392. ct_stm32f401ve,
  393. ct_stm32f407vg,
  394. ct_discoveryf407vg,
  395. ct_stm32f407ig,
  396. ct_stm32f407zg,
  397. ct_stm32f407ve,
  398. ct_stm32f407ze,
  399. ct_stm32f407ie,
  400. ct_stm32f411cc,
  401. ct_stm32f411rc,
  402. ct_stm32f411vc,
  403. ct_stm32f411ce,
  404. ct_stm32f411re,
  405. ct_nucleof411re,
  406. ct_stm32f411ve,
  407. ct_discoveryf411ve,
  408. ct_stm32f429vg,
  409. ct_stm32f429zg,
  410. ct_stm32f429ig,
  411. ct_stm32f429vi,
  412. ct_stm32f429zi,
  413. ct_discoveryf429zi,
  414. ct_stm32f429ii,
  415. ct_stm32f429ve,
  416. ct_stm32f429ze,
  417. ct_stm32f429ie,
  418. ct_stm32f429bg,
  419. ct_stm32f429bi,
  420. ct_stm32f429be,
  421. ct_stm32f429ng,
  422. ct_stm32f429ni,
  423. ct_stm32f429ne,
  424. ct_stm32f446mc,
  425. ct_stm32f446rc,
  426. ct_stm32f446vc,
  427. ct_stm32f446zc,
  428. ct_stm32f446me,
  429. ct_stm32f446re,
  430. ct_nucleof446re,
  431. ct_stm32f446ve,
  432. ct_stm32f446ze,
  433. ct_stm32f745xe,
  434. ct_stm32f745xg,
  435. ct_stm32f746xe,
  436. ct_stm32f746xg,
  437. ct_stm32f756xe,
  438. ct_stm32f756xg,
  439. ct_stm32g071rb,
  440. ct_nucleog071rb,
  441. { TI - 64 K Flash, 16 K SRAM Devices }
  442. ct_lm3s1110,
  443. ct_lm3s1133,
  444. ct_lm3s1138,
  445. ct_lm3s1150,
  446. ct_lm3s1162,
  447. ct_lm3s1165,
  448. ct_lm3s1166,
  449. ct_lm3s2110,
  450. ct_lm3s2139,
  451. ct_lm3s6100,
  452. ct_lm3s6110,
  453. { TI 128 K Flash, 32 K SRAM devices - Fury Class }
  454. ct_lm3s1601,
  455. ct_lm3s1608,
  456. ct_lm3s1620,
  457. ct_lm3s1635,
  458. ct_lm3s1636,
  459. ct_lm3s1637,
  460. ct_lm3s1651,
  461. ct_lm3s2601,
  462. ct_lm3s2608,
  463. ct_lm3s2620,
  464. ct_lm3s2637,
  465. ct_lm3s2651,
  466. ct_lm3s6610,
  467. ct_lm3s6611,
  468. ct_lm3s6618,
  469. ct_lm3s6633,
  470. ct_lm3s6637,
  471. ct_lm3s8630,
  472. { TI 256 K Flase, 32 K SRAM devices - Fury Class }
  473. ct_lm3s1911,
  474. ct_lm3s1918,
  475. ct_lm3s1937,
  476. ct_lm3s1958,
  477. ct_lm3s1960,
  478. ct_lm3s1968,
  479. ct_lm3s1969,
  480. ct_lm3s2911,
  481. ct_lm3s2918,
  482. ct_lm3s2919,
  483. ct_lm3s2939,
  484. ct_lm3s2948,
  485. ct_lm3s2950,
  486. ct_lm3s2965,
  487. ct_lm3s6911,
  488. ct_lm3s6918,
  489. ct_lm3s6938,
  490. ct_lm3s6950,
  491. ct_lm3s6952,
  492. ct_lm3s6965,
  493. ct_lm3s8930,
  494. ct_lm3s8933,
  495. ct_lm3s8938,
  496. ct_lm3s8962,
  497. ct_lm3s8970,
  498. ct_lm3s8971,
  499. { TI - Tempest Tempest - 256 K Flash, 64 K SRAM }
  500. ct_lm3s5951,
  501. ct_lm3s5956,
  502. ct_lm3s1b21,
  503. ct_lm3s2b93,
  504. ct_lm3s5b91,
  505. ct_lm3s9b81,
  506. ct_lm3s9b90,
  507. ct_lm3s9b92,
  508. ct_lm3s9b95,
  509. ct_lm3s9b96,
  510. ct_lm3s5d51,
  511. { TI - Stellaris something }
  512. ct_lm4f120h5,
  513. { Infineon }
  514. ct_xmc4500x1024,
  515. ct_xmc4500x768,
  516. ct_xmc4502x768,
  517. ct_xmc4504x512,
  518. { Allwinner }
  519. ct_allwinner_a20,
  520. { Freescale }
  521. ct_mk20dx128vfm5,
  522. ct_mk20dx128vft5,
  523. ct_mk20dx128vlf5,
  524. ct_mk20dx128vlh5,
  525. ct_teensy30,
  526. ct_mk20dx128vmp5,
  527. ct_mk20dx32vfm5,
  528. ct_mk20dx32vft5,
  529. ct_mk20dx32vlf5,
  530. ct_mk20dx32vlh5,
  531. ct_mk20dx32vmp5,
  532. ct_mk20dx64vfm5,
  533. ct_mk20dx64vft5,
  534. ct_mk20dx64vlf5,
  535. ct_mk20dx64vlh5,
  536. ct_mk20dx64vmp5,
  537. ct_mk20dx128vlh7,
  538. ct_mk20dx128vlk7,
  539. ct_mk20dx128vll7,
  540. ct_mk20dx128vmc7,
  541. ct_mk20dx256vlh7,
  542. ct_mk20dx256vlk7,
  543. ct_mk20dx256vll7,
  544. ct_mk20dx256vmc7,
  545. ct_teensy31,
  546. ct_teensy32,
  547. ct_mk20dx64vlh7,
  548. ct_mk20dx64vlk7,
  549. ct_mk20dx64vmc7,
  550. ct_mk22fn512cap12,
  551. ct_mk22fn512cbp12,
  552. ct_mk22fn512vdc12,
  553. ct_mk22fn512vlh12,
  554. ct_mk22fn512vll12,
  555. ct_mk22fn512vmp12,
  556. ct_freedom_k22f,
  557. { Atmel }
  558. ct_sam3x8e,
  559. ct_arduino_due,
  560. ct_flip_n_click,
  561. { Nordic Semiconductor }
  562. ct_nrf51422_xxaa,
  563. ct_nrf51422_xxab,
  564. ct_nrf51422_xxac,
  565. ct_nrf51822_xxaa,
  566. ct_nrf51822_xxab,
  567. ct_nrf51822_xxac,
  568. ct_nrf52832_xxaa,
  569. ct_nrf52840_xxaa,
  570. ct_sc32442b,
  571. { Raspberry Pi 2 }
  572. ct_raspi2,
  573. ct_thumb2bare:
  574. begin
  575. with embedded_controllers[current_settings.controllertype] do
  576. with linkres do
  577. begin
  578. if (embedded_controllers[current_settings.controllertype].controllerunitstr='MK20D5')
  579. or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK20D7')
  580. or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK22F51212')
  581. or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK64F12') then
  582. Add('ENTRY(_LOWLEVELSTART)')
  583. else
  584. Add('ENTRY(_START)');
  585. Add('MEMORY');
  586. Add('{');
  587. if flashsize<>0 then
  588. begin
  589. LinkStr := ' flash : ORIGIN = 0x' + IntToHex(flashbase,8)
  590. + ', LENGTH = 0x' + IntToHex(flashsize,8);
  591. Add(LinkStr);
  592. end;
  593. LinkStr := ' ram : ORIGIN = 0x' + IntToHex(srambase,8)
  594. + ', LENGTH = 0x' + IntToHex(sramsize,8);
  595. Add(LinkStr);
  596. Add('}');
  597. Add('_stack_top = 0x' + IntToHex(sramsize+srambase,8) + ';');
  598. // Add Checksum Calculation for LPC Controllers so that the bootloader starts the uploaded binary
  599. writeln(controllerunitstr);
  600. if (controllerunitstr = 'LPC8xx') or (controllerunitstr = 'LPC11XX') or (controllerunitstr = 'LPC122X') then
  601. Add('Startup_Checksum = 0 - (_stack_top + _START + 1 + NonMaskableInt_interrupt + 1 + Hardfault_interrupt + 1);');
  602. if (controllerunitstr = 'LPC13XX') then
  603. Add('Startup_Checksum = 0 - (_stack_top + _START + 1 + NonMaskableInt_interrupt + 1 + MemoryManagement_interrupt + 1 + BusFault_interrupt + 1 + UsageFault_interrupt + 1);');
  604. end;
  605. end
  606. else
  607. if not (cs_link_nolink in current_settings.globalswitches) then
  608. internalerror(200902011);
  609. end;
  610. with linkres do
  611. begin
  612. Add('SECTIONS');
  613. Add('{');
  614. Add(' .text :');
  615. Add(' {');
  616. Add(' _text_start = .;');
  617. Add(' KEEP(*(.init .init.*))');
  618. if (embedded_controllers[current_settings.controllertype].controllerunitstr='MK20D5')
  619. or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK20D7')
  620. or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK22F51212')
  621. or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK64F12') then
  622. begin
  623. Add(' . = 0x400;');
  624. Add(' KEEP(*(.flash_config *.flash_config.*))');
  625. end;
  626. Add(' *(.text .text.*)');
  627. Add(' *(.strings)');
  628. Add(' *(.rodata .rodata.*)');
  629. Add(' *(.comment)');
  630. Add(' . = ALIGN(4);');
  631. Add(' _etext = .;');
  632. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  633. begin
  634. Add(' } >flash');
  635. Add(' .note.gnu.build-id : { *(.note.gnu.build-id) } >flash ');
  636. end
  637. else
  638. begin
  639. Add(' } >ram');
  640. Add(' .note.gnu.build-id : { *(.note.gnu.build-id) } >ram ');
  641. end;
  642. Add(' .data :');
  643. Add(' {');
  644. Add(' _data = .;');
  645. Add(' *(.data .data.*)');
  646. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  647. Add(' _edata = .;');
  648. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  649. begin
  650. Add(' } >ram AT >flash');
  651. end
  652. else
  653. begin
  654. Add(' } >ram');
  655. end;
  656. Add(' .bss :');
  657. Add(' {');
  658. Add(' _bss_start = .;');
  659. Add(' *(.bss .bss.*)');
  660. Add(' *(COMMON)');
  661. Add(' } >ram');
  662. Add('. = ALIGN(4);');
  663. Add('_bss_end = . ;');
  664. Add('}');
  665. Add('_end = .;');
  666. end;
  667. {$endif ARM}
  668. {$ifdef i386}
  669. with linkres do
  670. begin
  671. Add('ENTRY(_START)');
  672. Add('SECTIONS');
  673. Add('{');
  674. Add(' . = 0x100000;');
  675. Add(' .text ALIGN (0x1000) :');
  676. Add(' {');
  677. Add(' _text = .;');
  678. Add(' KEEP(*(.init .init.*))');
  679. Add(' *(.text .text.*)');
  680. Add(' *(.strings)');
  681. Add(' *(.rodata .rodata.*)');
  682. Add(' *(.comment)');
  683. Add(' _etext = .;');
  684. Add(' }');
  685. Add(' .data ALIGN (0x1000) :');
  686. Add(' {');
  687. Add(' _data = .;');
  688. Add(' *(.data .data.*)');
  689. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  690. Add(' _edata = .;');
  691. Add(' }');
  692. Add(' . = ALIGN(4);');
  693. Add(' .bss :');
  694. Add(' {');
  695. Add(' _bss_start = .;');
  696. Add(' *(.bss .bss.*)');
  697. Add(' *(COMMON)');
  698. Add(' }');
  699. Add('_bss_end = . ;');
  700. Add('}');
  701. Add('_end = .;');
  702. end;
  703. {$endif i386}
  704. {$ifdef x86_64}
  705. with linkres do
  706. begin
  707. Add('ENTRY(_START)');
  708. Add('SECTIONS');
  709. Add('{');
  710. Add(' . = 0x100000;');
  711. Add(' .text ALIGN (0x1000) :');
  712. Add(' {');
  713. Add(' _text = .;');
  714. Add(' KEEP(*(.init .init.*))');
  715. Add(' *(.text .text.*)');
  716. Add(' *(.strings)');
  717. Add(' *(.rodata .rodata.*)');
  718. Add(' *(.comment)');
  719. Add(' _etext = .;');
  720. Add(' }');
  721. Add(' .data ALIGN (0x1000) :');
  722. Add(' {');
  723. Add(' _data = .;');
  724. Add(' *(.data .data.*)');
  725. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  726. Add(' _edata = .;');
  727. Add(' }');
  728. Add(' . = ALIGN(4);');
  729. Add(' .bss :');
  730. Add(' {');
  731. Add(' _bss_start = .;');
  732. Add(' *(.bss .bss.*)');
  733. Add(' *(COMMON)');
  734. Add(' }');
  735. Add('_bss_end = . ;');
  736. Add('}');
  737. Add('_end = .;');
  738. end;
  739. {$endif x86_64}
  740. {$ifdef AVR}
  741. with linkres do
  742. begin
  743. { linker script from ld 2.19 }
  744. Add('ENTRY(_START)');
  745. Add('OUTPUT_FORMAT("elf32-avr","elf32-avr","elf32-avr")');
  746. case current_settings.cputype of
  747. cpu_avr1:
  748. Add('OUTPUT_ARCH(avr:1)');
  749. cpu_avr2:
  750. Add('OUTPUT_ARCH(avr:2)');
  751. cpu_avr25:
  752. Add('OUTPUT_ARCH(avr:25)');
  753. cpu_avr3:
  754. Add('OUTPUT_ARCH(avr:3)');
  755. cpu_avr31:
  756. Add('OUTPUT_ARCH(avr:31)');
  757. cpu_avr35:
  758. Add('OUTPUT_ARCH(avr:35)');
  759. cpu_avr4:
  760. Add('OUTPUT_ARCH(avr:4)');
  761. cpu_avr5:
  762. Add('OUTPUT_ARCH(avr:5)');
  763. cpu_avr51:
  764. Add('OUTPUT_ARCH(avr:51)');
  765. cpu_avr6:
  766. Add('OUTPUT_ARCH(avr:6)');
  767. cpu_avrxmega3:
  768. Add('OUTPUT_ARCH(avr:103)');
  769. cpu_avrtiny:
  770. Add('OUTPUT_ARCH(avr:100)');
  771. else
  772. Internalerror(2015072701);
  773. end;
  774. Add('MEMORY');
  775. with embedded_controllers[current_settings.controllertype] do
  776. begin
  777. Add('{');
  778. Add(' text (rx) : ORIGIN = 0, LENGTH = 0x'+IntToHex(flashsize,6));
  779. Add(' data (rw!x) : ORIGIN = 0x'+IntToHex($800000+srambase,6)+', LENGTH = 0x'+IntToHex(sramsize,6));
  780. Add(' eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = 0x'+IntToHex(eepromsize,6));
  781. Add(' fuse (rw!x) : ORIGIN = 0x820000, LENGTH = 1K');
  782. Add(' lock (rw!x) : ORIGIN = 0x830000, LENGTH = 1K');
  783. Add(' signature (rw!x) : ORIGIN = 0x840000, LENGTH = 1K');
  784. Add('}');
  785. Add('_stack_top = 0x' + IntToHex(srambase+sramsize-1,4) + ';');
  786. end;
  787. Add('SECTIONS');
  788. Add('{');
  789. Add(' /* Read-only sections, merged into text segment: */');
  790. Add(' .hash : { *(.hash) }');
  791. Add(' .dynsym : { *(.dynsym) }');
  792. Add(' .dynstr : { *(.dynstr) }');
  793. Add(' .gnu.version : { *(.gnu.version) }');
  794. Add(' .gnu.version_d : { *(.gnu.version_d) }');
  795. Add(' .gnu.version_r : { *(.gnu.version_r) }');
  796. Add(' .rel.init : { *(.rel.init) }');
  797. Add(' .rela.init : { *(.rela.init) }');
  798. Add(' .rel.text :');
  799. Add(' {');
  800. Add(' *(.rel.text)');
  801. Add(' *(.rel.text.*)');
  802. Add(' *(.rel.gnu.linkonce.t*)');
  803. Add(' }');
  804. Add(' .rela.text :');
  805. Add(' {');
  806. Add(' *(.rela.text)');
  807. Add(' *(.rela.text.*)');
  808. Add(' *(.rela.gnu.linkonce.t*)');
  809. Add(' }');
  810. Add(' .rel.fini : { *(.rel.fini) }');
  811. Add(' .rela.fini : { *(.rela.fini) }');
  812. Add(' .rel.rodata :');
  813. Add(' {');
  814. Add(' *(.rel.rodata)');
  815. Add(' *(.rel.rodata.*)');
  816. Add(' *(.rel.gnu.linkonce.r*)');
  817. Add(' }');
  818. Add(' .rela.rodata :');
  819. Add(' {');
  820. Add(' *(.rela.rodata)');
  821. Add(' *(.rela.rodata.*)');
  822. Add(' *(.rela.gnu.linkonce.r*)');
  823. Add(' }');
  824. Add(' .rel.data :');
  825. Add(' {');
  826. Add(' *(.rel.data)');
  827. Add(' *(.rel.data.*)');
  828. Add(' *(.rel.gnu.linkonce.d*)');
  829. Add(' }');
  830. Add(' .rela.data :');
  831. Add(' {');
  832. Add(' *(.rela.data)');
  833. Add(' *(.rela.data.*)');
  834. Add(' *(.rela.gnu.linkonce.d*)');
  835. Add(' }');
  836. Add(' .rel.ctors : { *(.rel.ctors) }');
  837. Add(' .rela.ctors : { *(.rela.ctors) }');
  838. Add(' .rel.dtors : { *(.rel.dtors) }');
  839. Add(' .rela.dtors : { *(.rela.dtors) }');
  840. Add(' .rel.got : { *(.rel.got) }');
  841. Add(' .rela.got : { *(.rela.got) }');
  842. Add(' .rel.bss : { *(.rel.bss) }');
  843. Add(' .rela.bss : { *(.rela.bss) }');
  844. Add(' .rel.plt : { *(.rel.plt) }');
  845. Add(' .rela.plt : { *(.rela.plt) }');
  846. Add(' /* Internal text space or external memory. */');
  847. Add(' .text :');
  848. Add(' {');
  849. Add(' KEEP(*(.init .init.*))');
  850. Add(' /* For data that needs to reside in the lower 64k of progmem. */');
  851. Add(' *(.progmem.gcc*)');
  852. Add(' *(.progmem*)');
  853. Add(' . = ALIGN(2);');
  854. Add(' __trampolines_start = . ;');
  855. Add(' /* The jump trampolines for the 16-bit limited relocs will reside here. */');
  856. Add(' *(.trampolines)');
  857. Add(' *(.trampolines*)');
  858. Add(' __trampolines_end = . ;');
  859. Add(' /* For future tablejump instruction arrays for 3 byte pc devices.');
  860. Add(' We don''t relax jump/call instructions within these sections. */');
  861. Add(' *(.jumptables)');
  862. Add(' *(.jumptables*)');
  863. Add(' /* For code that needs to reside in the lower 128k progmem. */');
  864. Add(' *(.lowtext)');
  865. Add(' *(.lowtext*)');
  866. Add(' __ctors_start = . ;');
  867. Add(' *(.ctors)');
  868. Add(' __ctors_end = . ;');
  869. Add(' __dtors_start = . ;');
  870. Add(' *(.dtors)');
  871. Add(' __dtors_end = . ;');
  872. Add(' KEEP(SORT(*)(.ctors))');
  873. Add(' KEEP(SORT(*)(.dtors))');
  874. Add(' /* From this point on, we don''t bother about wether the insns are');
  875. Add(' below or above the 16 bits boundary. */');
  876. Add(' *(.init0) /* Start here after reset. */');
  877. Add(' KEEP (*(.init0))');
  878. Add(' *(.init1)');
  879. Add(' KEEP (*(.init1))');
  880. Add(' *(.init2) /* Clear __zero_reg__, set up stack pointer. */');
  881. Add(' KEEP (*(.init2))');
  882. Add(' *(.init3)');
  883. Add(' KEEP (*(.init3))');
  884. Add(' *(.init4) /* Initialize data and BSS. */');
  885. Add(' KEEP (*(.init4))');
  886. Add(' *(.init5)');
  887. Add(' KEEP (*(.init5))');
  888. Add(' *(.init6) /* C++ constructors. */');
  889. Add(' KEEP (*(.init6))');
  890. Add(' *(.init7)');
  891. Add(' KEEP (*(.init7))');
  892. Add(' *(.init8)');
  893. Add(' KEEP (*(.init8))');
  894. Add(' *(.init9) /* Call main(). */');
  895. Add(' KEEP (*(.init9))');
  896. Add(' *(.text)');
  897. Add(' . = ALIGN(2);');
  898. Add(' *(.text.*)');
  899. Add(' . = ALIGN(2);');
  900. Add(' *(.fini9) /* _exit() starts here. */');
  901. Add(' KEEP (*(.fini9))');
  902. Add(' *(.fini8)');
  903. Add(' KEEP (*(.fini8))');
  904. Add(' *(.fini7)');
  905. Add(' KEEP (*(.fini7))');
  906. Add(' *(.fini6) /* C++ destructors. */');
  907. Add(' KEEP (*(.fini6))');
  908. Add(' *(.fini5)');
  909. Add(' KEEP (*(.fini5))');
  910. Add(' *(.fini4)');
  911. Add(' KEEP (*(.fini4))');
  912. Add(' *(.fini3)');
  913. Add(' KEEP (*(.fini3))');
  914. Add(' *(.fini2)');
  915. Add(' KEEP (*(.fini2))');
  916. Add(' *(.fini1)');
  917. Add(' KEEP (*(.fini1))');
  918. Add(' *(.fini0) /* Infinite loop after program termination. */');
  919. Add(' KEEP (*(.fini0))');
  920. Add(' _etext = . ;');
  921. Add(' } > text');
  922. Add(' .data : AT (ADDR (.text) + SIZEOF (.text))');
  923. Add(' {');
  924. Add(' PROVIDE (__data_start = .) ;');
  925. Add(' *(.data)');
  926. Add(' *(.data*)');
  927. Add(' *(.rodata) /* We need to include .rodata here if gcc is used */');
  928. Add(' *(.rodata*) /* with -fdata-sections. */');
  929. Add(' *(.gnu.linkonce.d*)');
  930. Add(' . = ALIGN(2);');
  931. Add(' _edata = . ;');
  932. Add(' PROVIDE (__data_end = .) ;');
  933. Add(' } > data');
  934. Add(' .bss : AT (ADDR (.bss))');
  935. Add(' {');
  936. Add(' PROVIDE (__bss_start = .) ;');
  937. Add(' *(.bss)');
  938. Add(' *(.bss*)');
  939. Add(' *(COMMON)');
  940. Add(' PROVIDE (__bss_end = .) ;');
  941. Add(' } > data');
  942. Add(' __data_load_start = LOADADDR(.data);');
  943. Add(' __data_load_end = __data_load_start + SIZEOF(.data);');
  944. Add(' /* Global data not cleared after reset. */');
  945. Add(' .noinit :');
  946. Add(' {');
  947. Add(' PROVIDE (__noinit_start = .) ;');
  948. Add(' *(.noinit*)');
  949. Add(' PROVIDE (__noinit_end = .) ;');
  950. Add(' _end = . ;');
  951. Add(' PROVIDE (__heap_start = .) ;');
  952. Add(' } > data');
  953. Add(' .eeprom :');
  954. Add(' {');
  955. Add(' *(.eeprom*)');
  956. Add(' __eeprom_end = . ;');
  957. Add(' } > eeprom');
  958. Add(' .fuse :');
  959. Add(' {');
  960. Add(' KEEP(*(.fuse))');
  961. Add(' KEEP(*(.lfuse))');
  962. Add(' KEEP(*(.hfuse))');
  963. Add(' KEEP(*(.efuse))');
  964. Add(' } > fuse');
  965. Add(' .lock :');
  966. Add(' {');
  967. Add(' KEEP(*(.lock*))');
  968. Add(' } > lock');
  969. Add(' .signature :');
  970. Add(' {');
  971. Add(' KEEP(*(.signature*))');
  972. Add(' } > signature');
  973. Add(' /* Stabs debugging sections. */');
  974. Add(' .stab 0 : { *(.stab) }');
  975. Add(' .stabstr 0 : { *(.stabstr) }');
  976. Add(' .stab.excl 0 : { *(.stab.excl) }');
  977. Add(' .stab.exclstr 0 : { *(.stab.exclstr) }');
  978. Add(' .stab.index 0 : { *(.stab.index) }');
  979. Add(' .stab.indexstr 0 : { *(.stab.indexstr) }');
  980. Add(' .comment 0 : { *(.comment) }');
  981. Add(' /* DWARF debug sections.');
  982. Add(' Symbols in the DWARF debugging sections are relative to the beginning');
  983. Add(' of the section so we begin them at 0. */');
  984. Add(' /* DWARF 1 */');
  985. Add(' .debug 0 : { *(.debug) }');
  986. Add(' .line 0 : { *(.line) }');
  987. Add(' /* GNU DWARF 1 extensions */');
  988. Add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  989. Add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  990. Add(' /* DWARF 1.1 and DWARF 2 */');
  991. Add(' .debug_aranges 0 : { *(.debug_aranges) }');
  992. Add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  993. Add(' /* DWARF 2 */');
  994. Add(' .debug_info 0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }');
  995. Add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  996. Add(' .debug_line 0 : { *(.debug_line) }');
  997. Add(' .debug_frame 0 : { *(.debug_frame) }');
  998. Add(' .debug_str 0 : { *(.debug_str) }');
  999. Add(' .debug_loc 0 : { *(.debug_loc) }');
  1000. Add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  1001. Add('}');
  1002. end;
  1003. {$endif AVR}
  1004. {$ifdef MIPSEL}
  1005. case current_settings.controllertype of
  1006. ct_none:
  1007. begin
  1008. end;
  1009. ct_pic32mx110f016b,
  1010. ct_pic32mx110f016c,
  1011. ct_pic32mx110f016d,
  1012. ct_pic32mx120f032b,
  1013. ct_pic32mx120f032c,
  1014. ct_pic32mx120f032d,
  1015. ct_pic32mx130f064b,
  1016. ct_pic32mx130f064c,
  1017. ct_pic32mx130f064d,
  1018. ct_pic32mx150f128b,
  1019. ct_pic32mx150f128c,
  1020. ct_pic32mx150f128d,
  1021. ct_pic32mx210f016b,
  1022. ct_pic32mx210f016c,
  1023. ct_pic32mx210f016d,
  1024. ct_pic32mx220f032b,
  1025. ct_pic32mx220f032c,
  1026. ct_pic32mx220f032d,
  1027. ct_pic32mx230f064b,
  1028. ct_pic32mx230f064c,
  1029. ct_pic32mx230f064d,
  1030. ct_pic32mx250f128b,
  1031. ct_pic32mx250f128c,
  1032. ct_pic32mx250f128d,
  1033. ct_pic32mx775f256h,
  1034. ct_pic32mx775f256l,
  1035. ct_pic32mx775f512h,
  1036. ct_pic32mx775f512l,
  1037. ct_pic32mx795f512h,
  1038. ct_pic32mx795f512l:
  1039. begin
  1040. with embedded_controllers[current_settings.controllertype] do
  1041. with linkres do
  1042. begin
  1043. Add('OUTPUT_FORMAT("elf32-tradlittlemips")');
  1044. Add('OUTPUT_ARCH(pic32mx)');
  1045. Add('ENTRY(_reset)');
  1046. Add('PROVIDE(_vector_spacing = 0x00000001);');
  1047. Add('_ebase_address = 0x'+IntToHex(flashbase,8)+';');
  1048. Add('_RESET_ADDR = 0xBFC00000;');
  1049. Add('_BEV_EXCPT_ADDR = 0xBFC00380;');
  1050. Add('_DBG_EXCPT_ADDR = 0xBFC00480;');
  1051. Add('_GEN_EXCPT_ADDR = _ebase_address + 0x180;');
  1052. Add('MEMORY');
  1053. Add('{');
  1054. if flashsize<>0 then
  1055. begin
  1056. Add(' kseg0_program_mem : ORIGIN = 0x'+IntToHex(flashbase,8)+', LENGTH = 0x'+IntToHex(flashsize,8));
  1057. //TODO This should better be placed into the controllertype records
  1058. Add(' kseg1_boot_mem : ORIGIN = 0xBFC00000, LENGTH = 0xbef');
  1059. Add(' config3 : ORIGIN = 0xBFC00BF0, LENGTH = 0x4');
  1060. Add(' config2 : ORIGIN = 0xBFC00BF4, LENGTH = 0x4');
  1061. Add(' config1 : ORIGIN = 0xBFC00BF8, LENGTH = 0x4');
  1062. Add(' config0 : ORIGIN = 0xBFC00BFC, LENGTH = 0x4');
  1063. end;
  1064. Add(' ram : ORIGIN = 0x' + IntToHex(srambase,8)
  1065. + ', LENGTH = 0x' + IntToHex(sramsize,8));
  1066. Add('}');
  1067. Add('_stack_top = 0x' + IntToHex(sramsize+srambase,8) + ';');
  1068. end;
  1069. end
  1070. end;
  1071. with linkres do
  1072. begin
  1073. Add('SECTIONS');
  1074. Add('{');
  1075. Add(' .reset _RESET_ADDR :');
  1076. Add(' {');
  1077. Add(' KEEP(*(.reset .reset.*))');
  1078. Add(' KEEP(*(.startup .startup.*))');
  1079. Add(' } > kseg1_boot_mem');
  1080. Add(' .bev_excpt _BEV_EXCPT_ADDR :');
  1081. Add(' {');
  1082. Add(' KEEP(*(.bev_handler))');
  1083. Add(' } > kseg1_boot_mem');
  1084. Add(' .text :');
  1085. Add(' {');
  1086. Add(' _text_start = .;');
  1087. Add(' . = _text_start + 0x180;');
  1088. Add(' KEEP(*(.gen_handler))');
  1089. Add(' . = _text_start + 0x200;');
  1090. Add(' KEEP(*(.init .init.*))');
  1091. Add(' *(.text .text.*)');
  1092. Add(' *(.strings)');
  1093. Add(' *(.rodata .rodata.*)');
  1094. Add(' *(.comment)');
  1095. Add(' _etext = .;');
  1096. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  1097. begin
  1098. Add(' } >kseg0_program_mem');
  1099. end
  1100. else
  1101. begin
  1102. Add(' } >ram');
  1103. end;
  1104. Add(' .note.gnu.build-id : { *(.note.gnu.build-id) }');
  1105. Add(' .data :');
  1106. Add(' {');
  1107. Add(' _data = .;');
  1108. Add(' *(.data .data.*)');
  1109. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  1110. Add(' . = .;');
  1111. Add(' _gp = ALIGN(16) + 0x7ff0;');
  1112. Add(' _edata = .;');
  1113. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  1114. begin
  1115. Add(' } >ram AT >kseg0_program_mem');
  1116. end
  1117. else
  1118. begin
  1119. Add(' } >ram');
  1120. end;
  1121. Add(' .config_BFC00BF0 : {');
  1122. Add(' KEEP(*(.config_BFC00BF0))');
  1123. Add(' } > config3');
  1124. Add(' .config_BFC00BF4 : {');
  1125. Add(' KEEP(*(.config_BFC00BF4))');
  1126. Add(' } > config2');
  1127. Add(' .config_BFC00BF8 : {');
  1128. Add(' KEEP(*(.config_BFC00BF8))');
  1129. Add(' } > config1');
  1130. Add(' .config_BFC00BFC : {');
  1131. Add(' KEEP(*(.config_BFC00BFC))');
  1132. Add(' } > config0');
  1133. Add(' .bss :');
  1134. Add(' {');
  1135. Add(' _bss_start = .;');
  1136. Add(' *(.bss .bss.*)');
  1137. Add(' *(COMMON)');
  1138. Add(' } >ram');
  1139. Add('. = ALIGN(4);');
  1140. Add('_bss_end = . ;');
  1141. Add(' .comment 0 : { *(.comment) }');
  1142. Add(' /* DWARF debug sections.');
  1143. Add(' Symbols in the DWARF debugging sections are relative to the beginning');
  1144. Add(' of the section so we begin them at 0. */');
  1145. Add(' /* DWARF 1 */');
  1146. Add(' .debug 0 : { *(.debug) }');
  1147. Add(' .line 0 : { *(.line) }');
  1148. Add(' /* GNU DWARF 1 extensions */');
  1149. Add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  1150. Add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  1151. Add(' /* DWARF 1.1 and DWARF 2 */');
  1152. Add(' .debug_aranges 0 : { *(.debug_aranges) }');
  1153. Add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  1154. Add(' /* DWARF 2 */');
  1155. Add(' .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }');
  1156. Add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  1157. Add(' /DISCARD/ : { *(.debug_line) }');
  1158. Add(' .debug_frame 0 : { *(.debug_frame) }');
  1159. Add(' .debug_str 0 : { *(.debug_str) }');
  1160. Add(' /DISCARD/ : { *(.debug_loc) }');
  1161. Add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  1162. Add(' /* SGI/MIPS DWARF 2 extensions */');
  1163. Add(' .debug_weaknames 0 : { *(.debug_weaknames) }');
  1164. Add(' .debug_funcnames 0 : { *(.debug_funcnames) }');
  1165. Add(' .debug_typenames 0 : { *(.debug_typenames) }');
  1166. Add(' .debug_varnames 0 : { *(.debug_varnames) }');
  1167. Add(' /* DWARF 3 */');
  1168. Add(' .debug_pubtypes 0 : { *(.debug_pubtypes) }');
  1169. Add(' .debug_ranges 0 : { *(.debug_ranges) }');
  1170. Add(' .gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }');
  1171. Add(' .gptab.sdata : { *(.gptab.data) *(.gptab.sdata) }');
  1172. Add(' .gptab.sbss : { *(.gptab.bss) *(.gptab.sbss) }');
  1173. Add(' .mdebug.abi32 : { KEEP(*(.mdebug.abi32)) }');
  1174. Add(' .mdebug.abiN32 : { KEEP(*(.mdebug.abiN32)) }');
  1175. Add(' .mdebug.abi64 : { KEEP(*(.mdebug.abi64)) }');
  1176. Add(' .mdebug.abiO64 : { KEEP(*(.mdebug.abiO64)) }');
  1177. Add(' .mdebug.eabi32 : { KEEP(*(.mdebug.eabi32)) }');
  1178. Add(' .mdebug.eabi64 : { KEEP(*(.mdebug.eabi64)) }');
  1179. Add(' /DISCARD/ : { *(.rel.dyn) }');
  1180. Add(' /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }');
  1181. Add('}');
  1182. Add('_end = .;');
  1183. end;
  1184. {$endif MIPSEL}
  1185. {$ifdef RISCV32}
  1186. with linkres do
  1187. begin
  1188. Add('OUTPUT_ARCH("riscv")');
  1189. Add('ENTRY(_START)');
  1190. Add('MEMORY');
  1191. with embedded_controllers[current_settings.controllertype] do
  1192. begin
  1193. Add('{');
  1194. Add(' flash (rx) : ORIGIN = 0x'+IntToHex(flashbase,6)+', LENGTH = 0x'+IntToHex(flashsize,6));
  1195. Add(' ram (rw!x) : ORIGIN = 0x'+IntToHex(srambase,6)+', LENGTH = 0x'+IntToHex(sramsize,6));
  1196. Add('}');
  1197. Add('_stack_top = 0x' + IntToHex(srambase+sramsize-1,4) + ';');
  1198. end;
  1199. Add('SECTIONS');
  1200. Add('{');
  1201. Add(' .text :');
  1202. Add(' {');
  1203. Add(' _text_start = .;');
  1204. Add(' KEEP(*(.init .init.*))');
  1205. Add(' *(.text .text.*)');
  1206. Add(' *(.strings)');
  1207. Add(' *(.rodata .rodata.*)');
  1208. Add(' *(.comment)');
  1209. Add(' . = ALIGN(4);');
  1210. Add(' _etext = .;');
  1211. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  1212. begin
  1213. Add(' } >flash');
  1214. //Add(' .note.gnu.build-id : { *(.note.gnu.build-id) } >flash ');
  1215. end
  1216. else
  1217. begin
  1218. Add(' } >ram');
  1219. //Add(' .note.gnu.build-id : { *(.note.gnu.build-id) } >ram ');
  1220. end;
  1221. Add(' .data :');
  1222. Add(' {');
  1223. Add(' _data = .;');
  1224. Add(' *(.data .data.*)');
  1225. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  1226. Add(' _edata = .;');
  1227. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  1228. begin
  1229. Add(' } >ram AT >flash');
  1230. end
  1231. else
  1232. begin
  1233. Add(' } >ram');
  1234. end;
  1235. Add(' .bss :');
  1236. Add(' {');
  1237. Add(' _bss_start = .;');
  1238. Add(' *(.bss .bss.*)');
  1239. Add(' *(COMMON)');
  1240. Add(' } >ram');
  1241. Add(' . = ALIGN(4);');
  1242. Add(' _bss_end = . ;');
  1243. Add(' /* Stabs debugging sections. */');
  1244. Add(' .stab 0 : { *(.stab) }');
  1245. Add(' .stabstr 0 : { *(.stabstr) }');
  1246. Add(' .stab.excl 0 : { *(.stab.excl) }');
  1247. Add(' .stab.exclstr 0 : { *(.stab.exclstr) }');
  1248. Add(' .stab.index 0 : { *(.stab.index) }');
  1249. Add(' .stab.indexstr 0 : { *(.stab.indexstr) }');
  1250. Add(' .comment 0 : { *(.comment) }');
  1251. Add(' /* DWARF debug sections.');
  1252. Add(' Symbols in the DWARF debugging sections are relative to the beginning');
  1253. Add(' of the section so we begin them at 0. */');
  1254. Add(' /* DWARF 1 */');
  1255. Add(' .debug 0 : { *(.debug) }');
  1256. Add(' .line 0 : { *(.line) }');
  1257. Add(' /* GNU DWARF 1 extensions */');
  1258. Add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  1259. Add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  1260. Add(' /* DWARF 1.1 and DWARF 2 */');
  1261. Add(' .debug_aranges 0 : { *(.debug_aranges) }');
  1262. Add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  1263. Add(' /* DWARF 2 */');
  1264. Add(' .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }');
  1265. Add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  1266. Add(' .debug_line 0 : { *(.debug_line) }');
  1267. Add(' .debug_frame 0 : { *(.debug_frame) }');
  1268. Add(' .debug_str 0 : { *(.debug_str) }');
  1269. Add(' .debug_loc 0 : { *(.debug_loc) }');
  1270. Add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  1271. Add(' /* SGI/MIPS DWARF 2 extensions */');
  1272. Add(' .debug_weaknames 0 : { *(.debug_weaknames) }');
  1273. Add(' .debug_funcnames 0 : { *(.debug_funcnames) }');
  1274. Add(' .debug_typenames 0 : { *(.debug_typenames) }');
  1275. Add(' .debug_varnames 0 : { *(.debug_varnames) }');
  1276. Add(' /* DWARF 3 */');
  1277. Add(' .debug_pubtypes 0 : { *(.debug_pubtypes) }');
  1278. Add(' .debug_ranges 0 : { *(.debug_ranges) }');
  1279. Add('}');
  1280. Add('_end = .;');
  1281. end;
  1282. {$endif RISCV32}
  1283. {$ifdef XTENSA}
  1284. with linkres do
  1285. begin
  1286. Add('/* Script for -z combreloc: combine and sort reloc sections */');
  1287. Add('/* Copyright (C) 2014-2018 Free Software Foundation, Inc.');
  1288. Add(' Copying and distribution of this script, with or without modification,');
  1289. Add(' are permitted in any medium without royalty provided the copyright');
  1290. Add(' notice and this notice are preserved. */');
  1291. Add('ENTRY(_start)');
  1292. Add('SEARCH_DIR("=/builds/idf/crosstool-NG/builds/xtensa-esp32-elf/xtensa-esp32-elf/lib"); SEARCH_DIR("=/usr/local/lib"); SEARCH_DIR("=/lib"); SEARCH_DIR("=/usr/lib");');
  1293. Add('SECTIONS');
  1294. Add('{');
  1295. Add(' /* Read-only sections, merged into text segment: */');
  1296. Add(' PROVIDE (__executable_start = 0x400000); . = 0x400000 + SIZEOF_HEADERS;');
  1297. Add(' .interp : { *(.interp) }');
  1298. Add(' .note.gnu.build-id : { *(.note.gnu.build-id) }');
  1299. Add(' .hash : { *(.hash) }');
  1300. Add(' .gnu.hash : { *(.gnu.hash) }');
  1301. Add(' .dynsym : { *(.dynsym) }');
  1302. Add(' .dynstr : { *(.dynstr) }');
  1303. Add(' .gnu.version : { *(.gnu.version) }');
  1304. Add(' .gnu.version_d : { *(.gnu.version_d) }');
  1305. Add(' .gnu.version_r : { *(.gnu.version_r) }');
  1306. Add(' .rela.dyn :');
  1307. Add(' {');
  1308. Add(' *(.rela.init)');
  1309. Add(' *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)');
  1310. Add(' *(.rela.fini)');
  1311. Add(' *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)');
  1312. Add(' *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)');
  1313. Add(' *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)');
  1314. Add(' *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)');
  1315. Add(' *(.rela.ctors)');
  1316. Add(' *(.rela.dtors)');
  1317. Add(' *(.rela.got)');
  1318. Add(' *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)');
  1319. Add(' }');
  1320. Add(' .rela.plt : { *(.rela.plt) }');
  1321. Add(' /* .plt* sections are embedded in .text */');
  1322. Add(' .text :');
  1323. Add(' {');
  1324. Add(' *(.got.plt* .plt*)');
  1325. Add(' KEEP (*(.init.literal))');
  1326. Add(' KEEP (*(SORT_NONE(.init)))');
  1327. Add(' *(.literal .text .stub .literal.* .text.* .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)');
  1328. Add(' /* .gnu.warning sections are handled specially by elf32.em. */');
  1329. Add(' *(.gnu.warning)');
  1330. Add(' KEEP (*(.fini.literal))');
  1331. Add(' KEEP (*(SORT_NONE(.fini)))');
  1332. Add(' } =0');
  1333. Add(' PROVIDE (__etext = .);');
  1334. Add(' PROVIDE (_etext = .);');
  1335. Add(' PROVIDE (etext = .);');
  1336. Add(' .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }');
  1337. Add(' .rodata1 : { *(.rodata1) }');
  1338. Add(' .got.loc : { *(.got.loc) }');
  1339. Add(' .xt_except_table : ONLY_IF_RO { KEEP (*(.xt_except_table .xt_except_table.* .gnu.linkonce.e.*)) }');
  1340. Add(' .eh_frame_hdr : { *(.eh_frame_hdr) }');
  1341. Add(' .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) }');
  1342. Add(' .gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }');
  1343. Add(' /* Adjust the address for the data segment. We want to adjust up to');
  1344. Add(' the same address within the page on the next page up. */');
  1345. Add(' . = ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1));');
  1346. Add(' /* Exception handling */');
  1347. Add(' .eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) }');
  1348. Add(' .gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }');
  1349. Add(' /* Thread Local Storage sections */');
  1350. Add(' .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) }');
  1351. Add(' .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }');
  1352. Add(' .preinit_array :');
  1353. Add(' {');
  1354. Add(' PROVIDE_HIDDEN (__preinit_array_start = .);');
  1355. Add(' KEEP (*(.preinit_array))');
  1356. Add(' PROVIDE_HIDDEN (__preinit_array_end = .);');
  1357. Add(' }');
  1358. Add(' .init_array :');
  1359. Add(' {');
  1360. Add(' PROVIDE_HIDDEN (__init_array_start = .);');
  1361. Add(' KEEP (*(SORT(.init_array.*)))');
  1362. Add(' KEEP (*(.init_array))');
  1363. Add(' PROVIDE_HIDDEN (__init_array_end = .);');
  1364. Add(' }');
  1365. Add(' .fini_array :');
  1366. Add(' {');
  1367. Add(' PROVIDE_HIDDEN (__fini_array_start = .);');
  1368. Add(' KEEP (*(SORT(.fini_array.*)))');
  1369. Add(' KEEP (*(.fini_array))');
  1370. Add(' PROVIDE_HIDDEN (__fini_array_end = .);');
  1371. Add(' }');
  1372. Add(' .ctors :');
  1373. Add(' {');
  1374. Add(' /* gcc uses crtbegin.o to find the start of');
  1375. Add(' the constructors, so we make sure it is');
  1376. Add(' first. Because this is a wildcard, it');
  1377. Add(' doesn''t matter if the user does not');
  1378. Add(' actually link against crtbegin.o; the');
  1379. Add(' linker won''t look for a file to match a');
  1380. Add(' wildcard. The wildcard also means that it');
  1381. Add(' doesn''t matter which directory crtbegin.o');
  1382. Add(' is in. */');
  1383. Add(' KEEP (*crtbegin.o(.ctors))');
  1384. Add(' KEEP (*crtbegin?.o(.ctors))');
  1385. Add(' /* We don''t want to include the .ctor section from');
  1386. Add(' the crtend.o file until after the sorted ctors.');
  1387. Add(' The .ctor section from the crtend file contains the');
  1388. Add(' end of ctors marker and it must be last */');
  1389. Add(' KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))');
  1390. Add(' KEEP (*(SORT(.ctors.*)))');
  1391. Add(' KEEP (*(.ctors))');
  1392. Add(' }');
  1393. Add(' .dtors :');
  1394. Add(' {');
  1395. Add(' KEEP (*crtbegin.o(.dtors))');
  1396. Add(' KEEP (*crtbegin?.o(.dtors))');
  1397. Add(' KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))');
  1398. Add(' KEEP (*(SORT(.dtors.*)))');
  1399. Add(' KEEP (*(.dtors))');
  1400. Add(' }');
  1401. Add(' .jcr : { KEEP (*(.jcr)) }');
  1402. Add(' .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }');
  1403. Add(' .xt_except_table : ONLY_IF_RW { KEEP (*(.xt_except_table .xt_except_table.* .gnu.linkonce.e.*)) }');
  1404. Add(' .dynamic : { *(.dynamic) }');
  1405. Add(' .got : { *(.got) }');
  1406. Add(' .data :');
  1407. Add(' {');
  1408. Add(' *(.data .data.* .gnu.linkonce.d.*)');
  1409. Add(' SORT(CONSTRUCTORS)');
  1410. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  1411. Add(' }');
  1412. Add(' .data1 : { *(.data1) }');
  1413. Add(' .xt_except_desc :');
  1414. Add(' {');
  1415. Add(' *(.xt_except_desc .xt_except_desc.* .gnu.linkonce.h.*)');
  1416. Add(' *(.xt_except_desc_end)');
  1417. Add(' }');
  1418. Add(' .lit4 :');
  1419. Add(' {');
  1420. Add(' PROVIDE (_lit4_start = .);');
  1421. Add(' *(.lit4 .lit4.* .gnu.linkonce.lit4.*)');
  1422. Add(' PROVIDE (_lit4_end = .);');
  1423. Add(' }');
  1424. Add(' _edata = .; PROVIDE (edata = .);');
  1425. Add(' __bss_start = .;');
  1426. Add(' .bss :');
  1427. Add(' {');
  1428. Add(' *(.dynbss)');
  1429. Add(' *(.bss .bss.* .gnu.linkonce.b.*)');
  1430. Add(' *(COMMON)');
  1431. Add(' /* Align here to ensure that the .bss section occupies space up to');
  1432. Add(' _end. Align after .bss to ensure correct alignment even if the');
  1433. Add(' .bss section disappears because there are no input sections.');
  1434. Add(' FIXME: Why do we need it? When there is no .bss section, we don''t');
  1435. Add(' pad the .data section. */');
  1436. Add(' . = ALIGN(. != 0 ? 32 / 8 : 1);');
  1437. Add(' }');
  1438. Add(' . = ALIGN(32 / 8);');
  1439. Add(' . = ALIGN(32 / 8);');
  1440. Add(' _end = .; PROVIDE (end = .);');
  1441. Add(' /* Stabs debugging sections. */');
  1442. Add(' .stab 0 : { *(.stab) }');
  1443. Add(' .stabstr 0 : { *(.stabstr) }');
  1444. Add(' .stab.excl 0 : { *(.stab.excl) }');
  1445. Add(' .stab.exclstr 0 : { *(.stab.exclstr) }');
  1446. Add(' .stab.index 0 : { *(.stab.index) }');
  1447. Add(' .stab.indexstr 0 : { *(.stab.indexstr) }');
  1448. Add(' .comment 0 : { *(.comment) }');
  1449. Add(' /* DWARF debug sections.');
  1450. Add(' Symbols in the DWARF debugging sections are relative to the beginning');
  1451. Add(' of the section so we begin them at 0. */');
  1452. Add(' /* DWARF 1 */');
  1453. Add(' .debug 0 : { *(.debug) }');
  1454. Add(' .line 0 : { *(.line) }');
  1455. Add(' /* GNU DWARF 1 extensions */');
  1456. Add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  1457. Add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  1458. Add(' /* DWARF 1.1 and DWARF 2 */');
  1459. Add(' .debug_aranges 0 : { *(.debug_aranges) }');
  1460. Add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  1461. Add(' /* DWARF 2 */');
  1462. Add(' .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }');
  1463. Add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  1464. Add(' .debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end ) }');
  1465. Add(' .debug_frame 0 : { *(.debug_frame) }');
  1466. Add(' .debug_str 0 : { *(.debug_str) }');
  1467. Add(' .debug_loc 0 : { *(.debug_loc) }');
  1468. Add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  1469. Add(' /* SGI/MIPS DWARF 2 extensions */');
  1470. Add(' .debug_weaknames 0 : { *(.debug_weaknames) }');
  1471. Add(' .debug_funcnames 0 : { *(.debug_funcnames) }');
  1472. Add(' .debug_typenames 0 : { *(.debug_typenames) }');
  1473. Add(' .debug_varnames 0 : { *(.debug_varnames) }');
  1474. Add(' /* DWARF 3 */');
  1475. Add(' .debug_pubtypes 0 : { *(.debug_pubtypes) }');
  1476. Add(' .debug_ranges 0 : { *(.debug_ranges) }');
  1477. Add(' /* DWARF Extension. */');
  1478. Add(' .debug_macro 0 : { *(.debug_macro) }');
  1479. Add(' .debug_addr 0 : { *(.debug_addr) }');
  1480. Add(' .gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }');
  1481. Add(' .xt.lit 0 : { KEEP (*(.xt.lit .xt.lit.* .gnu.linkonce.p.*)) }');
  1482. Add(' .xt.insn 0 : { KEEP (*(.xt.insn .gnu.linkonce.x.*)) }');
  1483. Add(' .xt.prop 0 : { KEEP (*(.xt.prop .xt.prop.* .gnu.linkonce.prop.*)) }');
  1484. Add(' /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }');
  1485. Add('}');
  1486. end;
  1487. {$endif XTENSA}
  1488. { Write and Close response }
  1489. linkres.writetodisk;
  1490. linkres.free;
  1491. WriteResponseFile:=True;
  1492. end;
  1493. function TlinkerEmbedded.MakeExecutable:boolean;
  1494. var
  1495. binstr,
  1496. cmdstr,
  1497. mapstr: TCmdStr;
  1498. success : boolean;
  1499. StaticStr,
  1500. GCSectionsStr,
  1501. DynLinkStr,
  1502. StripStr,
  1503. FixedExeFileName: string;
  1504. begin
  1505. { for future use }
  1506. StaticStr:='';
  1507. StripStr:='';
  1508. mapstr:='';
  1509. DynLinkStr:='';
  1510. FixedExeFileName:=maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.elf')));
  1511. GCSectionsStr:='--gc-sections';
  1512. //if not(cs_link_extern in current_settings.globalswitches) then
  1513. if not(cs_link_nolink in current_settings.globalswitches) then
  1514. Message1(exec_i_linking,current_module.exefilename);
  1515. if (cs_link_map in current_settings.globalswitches) then
  1516. mapstr:='-Map '+maybequoted(ChangeFileExt(current_module.exefilename,'.map'));
  1517. { Write used files and libraries }
  1518. WriteResponseFile();
  1519. { Call linker }
  1520. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  1521. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  1522. if not(cs_link_on_target in current_settings.globalswitches) then
  1523. begin
  1524. Replace(cmdstr,'$EXE',FixedExeFileName);
  1525. Replace(cmdstr,'$RES',(maybequoted(ScriptFixFileName(outputexedir+Info.ResName))));
  1526. Replace(cmdstr,'$STATIC',StaticStr);
  1527. Replace(cmdstr,'$STRIP',StripStr);
  1528. Replace(cmdstr,'$MAP',mapstr);
  1529. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  1530. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  1531. end
  1532. else
  1533. begin
  1534. Replace(cmdstr,'$EXE',FixedExeFileName);
  1535. Replace(cmdstr,'$RES',maybequoted(ScriptFixFileName(outputexedir+Info.ResName)));
  1536. Replace(cmdstr,'$STATIC',StaticStr);
  1537. Replace(cmdstr,'$STRIP',StripStr);
  1538. Replace(cmdstr,'$MAP',mapstr);
  1539. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  1540. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  1541. end;
  1542. success:=DoExec(FindUtil(utilsprefix+BinStr),cmdstr,true,false);
  1543. { Remove ReponseFile }
  1544. if success and not(cs_link_nolink in current_settings.globalswitches) then
  1545. DeleteFile(outputexedir+Info.ResName);
  1546. { Post process }
  1547. if success and not(cs_link_nolink in current_settings.globalswitches) then
  1548. success:=PostProcessExecutable(FixedExeFileName,false);
  1549. if success and (target_info.system in [system_arm_embedded,system_avr_embedded,system_mipsel_embedded,system_xtensa_embedded]) then
  1550. begin
  1551. success:=DoExec(FindUtil(utilsprefix+'objcopy'),'-O ihex '+
  1552. FixedExeFileName+' '+
  1553. maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.hex'))),true,false);
  1554. if success then
  1555. success:=DoExec(FindUtil(utilsprefix+'objcopy'),'-O binary '+
  1556. FixedExeFileName+' '+
  1557. maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.bin'))),true,false);
  1558. end;
  1559. MakeExecutable:=success; { otherwise a recursive call to link method }
  1560. end;
  1561. function TLinkerEmbedded.postprocessexecutable(const fn : string;isdll:boolean):boolean;
  1562. type
  1563. TElf32header=packed record
  1564. magic0123 : longint;
  1565. file_class : byte;
  1566. data_encoding : byte;
  1567. file_version : byte;
  1568. padding : array[$07..$0f] of byte;
  1569. e_type : word;
  1570. e_machine : word;
  1571. e_version : longint;
  1572. e_entry : longint; { entrypoint }
  1573. e_phoff : longint; { program header offset }
  1574. e_shoff : longint; { sections header offset }
  1575. e_flags : longint;
  1576. e_ehsize : word; { elf header size in bytes }
  1577. e_phentsize : word; { size of an entry in the program header array }
  1578. e_phnum : word; { 0..e_phnum-1 of entrys }
  1579. e_shentsize : word; { size of an entry in sections header array }
  1580. e_shnum : word; { 0..e_shnum-1 of entrys }
  1581. e_shstrndx : word; { index of string section header }
  1582. end;
  1583. TElf32sechdr=packed record
  1584. sh_name : longint;
  1585. sh_type : longint;
  1586. sh_flags : longint;
  1587. sh_addr : longint;
  1588. sh_offset : longint;
  1589. sh_size : longint;
  1590. sh_link : longint;
  1591. sh_info : longint;
  1592. sh_addralign : longint;
  1593. sh_entsize : longint;
  1594. end;
  1595. function MayBeSwapHeader(h : telf32header) : telf32header;
  1596. begin
  1597. result:=h;
  1598. if source_info.endian<>target_info.endian then
  1599. with h do
  1600. begin
  1601. result.e_type:=swapendian(e_type);
  1602. result.e_machine:=swapendian(e_machine);
  1603. result.e_version:=swapendian(e_version);
  1604. result.e_entry:=swapendian(e_entry);
  1605. result.e_phoff:=swapendian(e_phoff);
  1606. result.e_shoff:=swapendian(e_shoff);
  1607. result.e_flags:=swapendian(e_flags);
  1608. result.e_ehsize:=swapendian(e_ehsize);
  1609. result.e_phentsize:=swapendian(e_phentsize);
  1610. result.e_phnum:=swapendian(e_phnum);
  1611. result.e_shentsize:=swapendian(e_shentsize);
  1612. result.e_shnum:=swapendian(e_shnum);
  1613. result.e_shstrndx:=swapendian(e_shstrndx);
  1614. end;
  1615. end;
  1616. function MaybeSwapSecHeader(h : telf32sechdr) : telf32sechdr;
  1617. begin
  1618. result:=h;
  1619. if source_info.endian<>target_info.endian then
  1620. with h do
  1621. begin
  1622. result.sh_name:=swapendian(sh_name);
  1623. result.sh_type:=swapendian(sh_type);
  1624. result.sh_flags:=swapendian(sh_flags);
  1625. result.sh_addr:=swapendian(sh_addr);
  1626. result.sh_offset:=swapendian(sh_offset);
  1627. result.sh_size:=swapendian(sh_size);
  1628. result.sh_link:=swapendian(sh_link);
  1629. result.sh_info:=swapendian(sh_info);
  1630. result.sh_addralign:=swapendian(sh_addralign);
  1631. result.sh_entsize:=swapendian(sh_entsize);
  1632. end;
  1633. end;
  1634. var
  1635. f : file;
  1636. function ReadSectionName(pos : longint) : String;
  1637. var
  1638. oldpos : longint;
  1639. c : char;
  1640. begin
  1641. oldpos:=filepos(f);
  1642. seek(f,pos);
  1643. Result:='';
  1644. while true do
  1645. begin
  1646. blockread(f,c,1);
  1647. if c=#0 then
  1648. break;
  1649. Result:=Result+c;
  1650. end;
  1651. seek(f,oldpos);
  1652. end;
  1653. var
  1654. elfheader : TElf32header;
  1655. secheader : TElf32sechdr;
  1656. i : longint;
  1657. stringoffset : longint;
  1658. secname : string;
  1659. begin
  1660. postprocessexecutable:=false;
  1661. { open file }
  1662. assign(f,fn);
  1663. {$push}{$I-}
  1664. reset(f,1);
  1665. if ioresult<>0 then
  1666. Message1(execinfo_f_cant_open_executable,fn);
  1667. { read header }
  1668. blockread(f,elfheader,sizeof(tElf32header));
  1669. elfheader:=MayBeSwapHeader(elfheader);
  1670. seek(f,elfheader.e_shoff);
  1671. { read string section header }
  1672. seek(f,elfheader.e_shoff+sizeof(TElf32sechdr)*elfheader.e_shstrndx);
  1673. blockread(f,secheader,sizeof(secheader));
  1674. secheader:=MaybeSwapSecHeader(secheader);
  1675. stringoffset:=secheader.sh_offset;
  1676. seek(f,elfheader.e_shoff);
  1677. status.datasize:=0;
  1678. for i:=0 to elfheader.e_shnum-1 do
  1679. begin
  1680. blockread(f,secheader,sizeof(secheader));
  1681. secheader:=MaybeSwapSecHeader(secheader);
  1682. secname:=ReadSectionName(stringoffset+secheader.sh_name);
  1683. if secname='.text' then
  1684. begin
  1685. Message1(execinfo_x_codesize,tostr(secheader.sh_size));
  1686. status.codesize:=secheader.sh_size;
  1687. end
  1688. else if secname='.data' then
  1689. begin
  1690. Message1(execinfo_x_initdatasize,tostr(secheader.sh_size));
  1691. inc(status.datasize,secheader.sh_size);
  1692. end
  1693. else if secname='.bss' then
  1694. begin
  1695. Message1(execinfo_x_uninitdatasize,tostr(secheader.sh_size));
  1696. inc(status.datasize,secheader.sh_size);
  1697. end;
  1698. end;
  1699. close(f);
  1700. {$pop}
  1701. if ioresult<>0 then
  1702. ;
  1703. postprocessexecutable:=true;
  1704. end;
  1705. {*****************************************************************************
  1706. Initialize
  1707. *****************************************************************************}
  1708. initialization
  1709. {$ifdef arm}
  1710. RegisterLinker(ld_embedded,TLinkerEmbedded);
  1711. RegisterTarget(system_arm_embedded_info);
  1712. {$endif arm}
  1713. {$ifdef avr}
  1714. RegisterLinker(ld_embedded,TLinkerEmbedded);
  1715. RegisterTarget(system_avr_embedded_info);
  1716. {$endif avr}
  1717. {$ifdef i386}
  1718. RegisterLinker(ld_embedded,TLinkerEmbedded);
  1719. RegisterTarget(system_i386_embedded_info);
  1720. {$endif i386}
  1721. {$ifdef x86_64}
  1722. RegisterLinker(ld_embedded,TLinkerEmbedded);
  1723. RegisterTarget(system_x86_64_embedded_info);
  1724. {$endif x86_64}
  1725. {$ifdef i8086}
  1726. { no need to register linker ld_embedded, because i8086_embedded uses the
  1727. regular msdos linker. In case a flat binary, relocated for a specific
  1728. segment address is needed (e.g. for a BIOS or a real mode bootloader), it
  1729. can be produced post-compilation with exe2bin or a similar tool. }
  1730. RegisterTarget(system_i8086_embedded_info);
  1731. {$endif i8086}
  1732. {$ifdef mipsel}
  1733. RegisterLinker(ld_embedded,TLinkerEmbedded);
  1734. RegisterTarget(system_mipsel_embedded_info);
  1735. {$endif mipsel}
  1736. {$ifdef m68k}
  1737. RegisterLinker(ld_embedded,TLinkerEmbedded);
  1738. RegisterTarget(system_m68k_embedded_info);
  1739. {$endif m68k}
  1740. {$ifdef riscv32}
  1741. RegisterLinker(ld_embedded,TLinkerEmbedded);
  1742. RegisterTarget(system_riscv32_embedded_info);
  1743. {$endif riscv32}
  1744. {$ifdef riscv64}
  1745. RegisterLinker(ld_embedded,TLinkerEmbedded);
  1746. RegisterTarget(system_riscv64_embedded_info);
  1747. {$endif riscv64}
  1748. {$ifdef xtensa}
  1749. RegisterLinker(ld_embedded,TLinkerEmbedded);
  1750. RegisterTarget(system_xtensa_embedded_info);
  1751. {$endif xtensa}
  1752. end.