t_embed.pas 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981
  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. { TlinkerEmbedded_SdccSdld - the sdld linker from the SDCC project ( http://sdcc.sourceforge.net/ ) }
  38. TlinkerEmbedded_SdccSdld=class(texternallinker)
  39. private
  40. Function WriteResponseFile: Boolean;
  41. public
  42. { constructor Create; override;}
  43. procedure SetDefaultInfo; override;
  44. function MakeExecutable:boolean; override;
  45. { function postprocessexecutable(const fn : string;isdll:boolean):boolean;}
  46. end;
  47. {*****************************************************************************
  48. TlinkerEmbedded
  49. *****************************************************************************}
  50. Constructor TlinkerEmbedded.Create;
  51. begin
  52. Inherited Create;
  53. SharedLibFiles.doubles:=true;
  54. StaticLibFiles.doubles:=true;
  55. end;
  56. procedure TlinkerEmbedded.SetDefaultInfo;
  57. const
  58. {$ifdef mips}
  59. {$ifdef mipsel}
  60. platform_select='-EL';
  61. {$else}
  62. platform_select='-EB';
  63. {$endif}
  64. {$else}
  65. platform_select='';
  66. {$endif}
  67. begin
  68. with Info do
  69. begin
  70. ExeCmd[1]:='ld -g '+platform_select+' $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP $MAP -L. -o $EXE -T $RES';
  71. end;
  72. end;
  73. Function TlinkerEmbedded.WriteResponseFile: Boolean;
  74. Var
  75. linkres : TLinkRes;
  76. i : longint;
  77. HPath : TCmdStrListItem;
  78. s,s1,s2 : TCmdStr;
  79. prtobj,
  80. cprtobj : string[80];
  81. linklibc : boolean;
  82. found1,
  83. found2 : boolean;
  84. {$if defined(ARM)}
  85. LinkStr : string;
  86. {$endif}
  87. begin
  88. WriteResponseFile:=False;
  89. linklibc:=(SharedLibFiles.Find('c')<>nil);
  90. {$if defined(ARM) or defined(i386) or defined(x86_64) or defined(AVR) or defined(MIPSEL) or defined(RISCV32) or defined(XTENSA)}
  91. prtobj:='';
  92. {$else}
  93. prtobj:='prt0';
  94. {$endif}
  95. cprtobj:='cprt0';
  96. if linklibc then
  97. prtobj:=cprtobj;
  98. { Open link.res file }
  99. LinkRes:=TLinkRes.Create(outputexedir+Info.ResName,true);
  100. { Write path to search libraries }
  101. HPath:=TCmdStrListItem(current_module.locallibrarysearchpath.First);
  102. while assigned(HPath) do
  103. begin
  104. s:=HPath.Str;
  105. if (cs_link_on_target in current_settings.globalswitches) then
  106. s:=ScriptFixFileName(s);
  107. LinkRes.Add('-L'+s);
  108. HPath:=TCmdStrListItem(HPath.Next);
  109. end;
  110. HPath:=TCmdStrListItem(LibrarySearchPath.First);
  111. while assigned(HPath) do
  112. begin
  113. s:=HPath.Str;
  114. if s<>'' then
  115. LinkRes.Add('SEARCH_DIR("'+s+'")');
  116. HPath:=TCmdStrListItem(HPath.Next);
  117. end;
  118. LinkRes.Add('INPUT (');
  119. { add objectfiles, start with prt0 always }
  120. //s:=FindObjectFile('prt0','',false);
  121. if prtobj<>'' then
  122. begin
  123. s:=FindObjectFile(prtobj,'',false);
  124. LinkRes.AddFileName(s);
  125. end;
  126. { try to add crti and crtbegin if linking to C }
  127. if linklibc then
  128. begin
  129. if librarysearchpath.FindFile('crtbegin.o',false,s) then
  130. LinkRes.AddFileName(s);
  131. if librarysearchpath.FindFile('crti.o',false,s) then
  132. LinkRes.AddFileName(s);
  133. end;
  134. while not ObjectFiles.Empty do
  135. begin
  136. s:=ObjectFiles.GetFirst;
  137. if s<>'' then
  138. begin
  139. { vlink doesn't use SEARCH_DIR for object files }
  140. if not(cs_link_on_target in current_settings.globalswitches) then
  141. s:=FindObjectFile(s,'',false);
  142. LinkRes.AddFileName((maybequoted(s)));
  143. end;
  144. end;
  145. { Write staticlibraries }
  146. if not StaticLibFiles.Empty then
  147. begin
  148. { vlink doesn't need, and doesn't support GROUP }
  149. if (cs_link_on_target in current_settings.globalswitches) then
  150. begin
  151. LinkRes.Add(')');
  152. LinkRes.Add('GROUP(');
  153. end;
  154. while not StaticLibFiles.Empty do
  155. begin
  156. S:=StaticLibFiles.GetFirst;
  157. LinkRes.AddFileName((maybequoted(s)));
  158. end;
  159. end;
  160. if (cs_link_on_target in current_settings.globalswitches) then
  161. begin
  162. LinkRes.Add(')');
  163. { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
  164. here to be sure that it gets linked this is needed for glibc2 systems (PFV) }
  165. linklibc:=false;
  166. while not SharedLibFiles.Empty do
  167. begin
  168. S:=SharedLibFiles.GetFirst;
  169. if s<>'c' then
  170. begin
  171. i:=Pos(target_info.sharedlibext,S);
  172. if i>0 then
  173. Delete(S,i,255);
  174. LinkRes.Add('-l'+s);
  175. end
  176. else
  177. begin
  178. LinkRes.Add('-l'+s);
  179. linklibc:=true;
  180. end;
  181. end;
  182. { be sure that libc&libgcc is the last lib }
  183. if linklibc then
  184. begin
  185. LinkRes.Add('-lc');
  186. LinkRes.Add('-lgcc');
  187. end;
  188. end
  189. else
  190. begin
  191. while not SharedLibFiles.Empty do
  192. begin
  193. S:=SharedLibFiles.GetFirst;
  194. LinkRes.Add('lib'+s+target_info.staticlibext);
  195. end;
  196. LinkRes.Add(')');
  197. end;
  198. { objects which must be at the end }
  199. if linklibc then
  200. begin
  201. found1:=librarysearchpath.FindFile('crtend.o',false,s1);
  202. found2:=librarysearchpath.FindFile('crtn.o',false,s2);
  203. if found1 or found2 then
  204. begin
  205. LinkRes.Add('INPUT(');
  206. if found1 then
  207. LinkRes.AddFileName(s1);
  208. if found2 then
  209. LinkRes.AddFileName(s2);
  210. LinkRes.Add(')');
  211. end;
  212. end;
  213. {$ifdef ARM}
  214. case current_settings.controllertype of
  215. ct_none:
  216. begin
  217. end;
  218. ct_lpc810m021fn8,
  219. ct_lpc811m001fdh16,
  220. ct_lpc812m101fdh16,
  221. ct_lpc812m101fd20,
  222. ct_lpc812m101fdh20,
  223. ct_lpc1110fd20,
  224. ct_lpc1111fdh20_002,
  225. ct_lpc1111fhn33_101,
  226. ct_lpc1111fhn33_102,
  227. ct_lpc1111fhn33_103,
  228. ct_lpc1111fhn33_201,
  229. ct_lpc1111fhn33_202,
  230. ct_lpc1111fhn33_203,
  231. ct_lpc1112fd20_102,
  232. ct_lpc1112fdh20_102,
  233. ct_lpc1112fdh28_102,
  234. ct_lpc1112fhn33_101,
  235. ct_lpc1112fhn33_102,
  236. ct_lpc1112fhn33_103,
  237. ct_lpc1112fhn33_201,
  238. ct_lpc1112fhn24_202,
  239. ct_lpc1112fhn33_202,
  240. ct_lpc1112fhn33_203,
  241. ct_lpc1112fhi33_202,
  242. ct_lpc1112fhi33_203,
  243. ct_lpc1113fhn33_201,
  244. ct_lpc1113fhn33_202,
  245. ct_lpc1113fhn33_203,
  246. ct_lpc1113fhn33_301,
  247. ct_lpc1113fhn33_302,
  248. ct_lpc1113fhn33_303,
  249. ct_lpc1113bfd48_301,
  250. ct_lpc1113bfd48_302,
  251. ct_lpc1113bfd48_303,
  252. ct_lpc1114fdh28_102,
  253. ct_lpc1114fn28_102,
  254. ct_lpc1114fhn33_201,
  255. ct_lpc1114fhn33_202,
  256. ct_lpc1114fhn33_203,
  257. ct_lpc1114fhn33_301,
  258. ct_lpc1114fhn33_302,
  259. ct_lpc1114fhn33_303,
  260. ct_lpc1114fhn33_333,
  261. ct_lpc1114fhi33_302,
  262. ct_lpc1114fhi33_303,
  263. ct_lpc1114bfd48_301,
  264. ct_lpc1114bfd48_302,
  265. ct_lpc1114bfd48_303,
  266. ct_lpc1114bfd48_323,
  267. ct_lpc1114bfd48_333,
  268. ct_lpc1115bfd48_303,
  269. ct_lpc11c12fd48_301,
  270. ct_lpc11c14fd48_301,
  271. ct_lpc11c22fd48_301,
  272. ct_lpc11c24fd48_301,
  273. ct_lpc11d24fd48_301,
  274. ct_lpc1224fbd48_101,
  275. ct_lpc1224fbd48_121,
  276. ct_lpc1224fbd64_101,
  277. ct_lpc1224fbd64_121,
  278. ct_lpc1225fbd48_301,
  279. ct_lpc1225fbd48_321,
  280. ct_lpc1225fbd64_301,
  281. ct_lpc1225fbd64_321,
  282. ct_lpc1226fbd48_301,
  283. ct_lpc1226fbd64_301,
  284. ct_lpc1227fbd48_301,
  285. ct_lpc1227fbd64_301,
  286. ct_lpc12d27fbd100_301,
  287. ct_lpc1311fhn33,
  288. ct_lpc1311fhn33_01,
  289. ct_lpc1313fhn33,
  290. ct_lpc1313fhn33_01,
  291. ct_lpc1313fbd48,
  292. ct_lpc1313fbd48_01,
  293. ct_lpc1315fhn33,
  294. ct_lpc1315fbd48,
  295. ct_lpc1316fhn33,
  296. ct_lpc1316fbd48,
  297. ct_lpc1317fhn33,
  298. ct_lpc1317fbd48,
  299. ct_lpc1317fbd64,
  300. ct_lpc1342fhn33,
  301. ct_lpc1342fbd48,
  302. ct_lpc1343fhn33,
  303. ct_lpc1343fbd48,
  304. ct_lpc1345fhn33,
  305. ct_lpc1345fbd48,
  306. ct_lpc1346fhn33,
  307. ct_lpc1346fbd48,
  308. ct_lpc1347fhn33,
  309. ct_lpc1347fbd48,
  310. ct_lpc1347fbd64,
  311. ct_lpc2114,
  312. ct_lpc2124,
  313. ct_lpc2194,
  314. ct_lpc1768,
  315. ct_at91sam7s256,
  316. ct_at91sam7se256,
  317. ct_at91sam7x256,
  318. ct_at91sam7xc256,
  319. ct_stm32f030c6,
  320. ct_stm32f030c8,
  321. ct_stm32f030f4,
  322. ct_stm32f030k6,
  323. ct_stm32f030r8,
  324. ct_stm32f050c4,
  325. ct_stm32f050c6,
  326. ct_stm32f050f4,
  327. ct_stm32f050f6,
  328. ct_stm32f050g4,
  329. ct_stm32f050g6,
  330. ct_stm32f050k4,
  331. ct_stm32f050k6,
  332. ct_stm32f051c4,
  333. ct_stm32f051c6,
  334. ct_stm32f051c8,
  335. ct_stm32f051k4,
  336. ct_stm32f051k6,
  337. ct_stm32f051k8,
  338. ct_stm32f051r4,
  339. ct_stm32f051r6,
  340. ct_stm32f051r8,
  341. ct_stm32f091cc,
  342. ct_stm32f091cb,
  343. ct_stm32f091rc,
  344. ct_stm32f091rb,
  345. ct_stm32f091vc,
  346. ct_stm32f091vb,
  347. ct_stm32f100x4,
  348. ct_stm32f100x6,
  349. ct_stm32f100x8,
  350. ct_stm32f100xB,
  351. ct_stm32f100xC,
  352. ct_stm32f100xD,
  353. ct_stm32f100xE,
  354. ct_stm32f101x4,
  355. ct_stm32f101x6,
  356. ct_stm32f101x8,
  357. ct_stm32f101xB,
  358. ct_stm32f101xC,
  359. ct_stm32f101xD,
  360. ct_stm32f101xE,
  361. ct_stm32f101xF,
  362. ct_stm32f101xG,
  363. ct_stm32f102x4,
  364. ct_stm32f102x6,
  365. ct_stm32f102x8,
  366. ct_stm32f102xB,
  367. ct_stm32f103x4,
  368. ct_stm32f103x6,
  369. ct_stm32f103x8,
  370. ct_stm32f103xB,
  371. ct_stm32f103xC,
  372. ct_stm32f103xD,
  373. ct_stm32f103xE,
  374. ct_stm32f103xF,
  375. ct_stm32f103xG,
  376. ct_stm32f107x8,
  377. ct_stm32f107xB,
  378. ct_stm32f107xC,
  379. ct_stm32f105r8,
  380. ct_stm32f105rb,
  381. ct_stm32f105rc,
  382. ct_stm32f105v8,
  383. ct_stm32f105vb,
  384. ct_stm32f105vc,
  385. ct_stm32f107rb,
  386. ct_stm32f107rc,
  387. ct_stm32f107vb,
  388. ct_stm32f107vc,
  389. ct_stm32f401cb,
  390. ct_stm32f401rb,
  391. ct_stm32f401vb,
  392. ct_stm32f401cc,
  393. ct_stm32f401rc,
  394. ct_stm32f401vc,
  395. ct_discoveryf401vc,
  396. ct_stm32f401cd,
  397. ct_stm32f401rd,
  398. ct_stm32f401vd,
  399. ct_stm32f401ce,
  400. ct_stm32f401re,
  401. ct_nucleof401re,
  402. ct_stm32f401ve,
  403. ct_stm32f407vg,
  404. ct_discoveryf407vg,
  405. ct_stm32f407ig,
  406. ct_stm32f407zg,
  407. ct_stm32f407ve,
  408. ct_stm32f407ze,
  409. ct_stm32f407ie,
  410. ct_stm32f411cc,
  411. ct_stm32f411rc,
  412. ct_stm32f411vc,
  413. ct_stm32f411ce,
  414. ct_stm32f411re,
  415. ct_nucleof411re,
  416. ct_stm32f411ve,
  417. ct_discoveryf411ve,
  418. ct_stm32f429vg,
  419. ct_stm32f429zg,
  420. ct_stm32f429ig,
  421. ct_stm32f429vi,
  422. ct_stm32f429zi,
  423. ct_discoveryf429zi,
  424. ct_stm32f429ii,
  425. ct_stm32f429ve,
  426. ct_stm32f429ze,
  427. ct_stm32f429ie,
  428. ct_stm32f429bg,
  429. ct_stm32f429bi,
  430. ct_stm32f429be,
  431. ct_stm32f429ng,
  432. ct_stm32f429ni,
  433. ct_stm32f429ne,
  434. ct_stm32f446mc,
  435. ct_stm32f446rc,
  436. ct_stm32f446vc,
  437. ct_stm32f446zc,
  438. ct_stm32f446me,
  439. ct_stm32f446re,
  440. ct_nucleof446re,
  441. ct_stm32f446ve,
  442. ct_stm32f446ze,
  443. ct_stm32f745xe,
  444. ct_stm32f745xg,
  445. ct_stm32f746xe,
  446. ct_stm32f746xg,
  447. ct_stm32f756xe,
  448. ct_stm32f756xg,
  449. ct_stm32g071rb,
  450. ct_nucleog071rb,
  451. { TI - 64 K Flash, 16 K SRAM Devices }
  452. ct_lm3s1110,
  453. ct_lm3s1133,
  454. ct_lm3s1138,
  455. ct_lm3s1150,
  456. ct_lm3s1162,
  457. ct_lm3s1165,
  458. ct_lm3s1166,
  459. ct_lm3s2110,
  460. ct_lm3s2139,
  461. ct_lm3s6100,
  462. ct_lm3s6110,
  463. { TI 128 K Flash, 32 K SRAM devices - Fury Class }
  464. ct_lm3s1601,
  465. ct_lm3s1608,
  466. ct_lm3s1620,
  467. ct_lm3s1635,
  468. ct_lm3s1636,
  469. ct_lm3s1637,
  470. ct_lm3s1651,
  471. ct_lm3s2601,
  472. ct_lm3s2608,
  473. ct_lm3s2620,
  474. ct_lm3s2637,
  475. ct_lm3s2651,
  476. ct_lm3s6610,
  477. ct_lm3s6611,
  478. ct_lm3s6618,
  479. ct_lm3s6633,
  480. ct_lm3s6637,
  481. ct_lm3s8630,
  482. { TI 256 K Flase, 32 K SRAM devices - Fury Class }
  483. ct_lm3s1911,
  484. ct_lm3s1918,
  485. ct_lm3s1937,
  486. ct_lm3s1958,
  487. ct_lm3s1960,
  488. ct_lm3s1968,
  489. ct_lm3s1969,
  490. ct_lm3s2911,
  491. ct_lm3s2918,
  492. ct_lm3s2919,
  493. ct_lm3s2939,
  494. ct_lm3s2948,
  495. ct_lm3s2950,
  496. ct_lm3s2965,
  497. ct_lm3s6911,
  498. ct_lm3s6918,
  499. ct_lm3s6938,
  500. ct_lm3s6950,
  501. ct_lm3s6952,
  502. ct_lm3s6965,
  503. ct_lm3s8930,
  504. ct_lm3s8933,
  505. ct_lm3s8938,
  506. ct_lm3s8962,
  507. ct_lm3s8970,
  508. ct_lm3s8971,
  509. { TI - Tempest Tempest - 256 K Flash, 64 K SRAM }
  510. ct_lm3s5951,
  511. ct_lm3s5956,
  512. ct_lm3s1b21,
  513. ct_lm3s2b93,
  514. ct_lm3s5b91,
  515. ct_lm3s9b81,
  516. ct_lm3s9b90,
  517. ct_lm3s9b92,
  518. ct_lm3s9b95,
  519. ct_lm3s9b96,
  520. ct_lm3s5d51,
  521. { TI - Stellaris something }
  522. ct_lm4f120h5,
  523. { Infineon }
  524. ct_xmc4500x1024,
  525. ct_xmc4500x768,
  526. ct_xmc4502x768,
  527. ct_xmc4504x512,
  528. { Allwinner }
  529. ct_allwinner_a20,
  530. { Freescale }
  531. ct_mk20dx128vfm5,
  532. ct_mk20dx128vft5,
  533. ct_mk20dx128vlf5,
  534. ct_mk20dx128vlh5,
  535. ct_teensy30,
  536. ct_mk20dx128vmp5,
  537. ct_mk20dx32vfm5,
  538. ct_mk20dx32vft5,
  539. ct_mk20dx32vlf5,
  540. ct_mk20dx32vlh5,
  541. ct_mk20dx32vmp5,
  542. ct_mk20dx64vfm5,
  543. ct_mk20dx64vft5,
  544. ct_mk20dx64vlf5,
  545. ct_mk20dx64vlh5,
  546. ct_mk20dx64vmp5,
  547. ct_mk20dx128vlh7,
  548. ct_mk20dx128vlk7,
  549. ct_mk20dx128vll7,
  550. ct_mk20dx128vmc7,
  551. ct_mk20dx256vlh7,
  552. ct_mk20dx256vlk7,
  553. ct_mk20dx256vll7,
  554. ct_mk20dx256vmc7,
  555. ct_teensy31,
  556. ct_teensy32,
  557. ct_mk20dx64vlh7,
  558. ct_mk20dx64vlk7,
  559. ct_mk20dx64vmc7,
  560. ct_mk22fn512cap12,
  561. ct_mk22fn512cbp12,
  562. ct_mk22fn512vdc12,
  563. ct_mk22fn512vlh12,
  564. ct_mk22fn512vll12,
  565. ct_mk22fn512vmp12,
  566. ct_freedom_k22f,
  567. { Atmel }
  568. ct_sam3x8e,
  569. ct_arduino_due,
  570. ct_flip_n_click,
  571. { Nordic Semiconductor }
  572. ct_nrf51422_xxaa,
  573. ct_nrf51422_xxab,
  574. ct_nrf51422_xxac,
  575. ct_nrf51822_xxaa,
  576. ct_nrf51822_xxab,
  577. ct_nrf51822_xxac,
  578. ct_nrf52832_xxaa,
  579. ct_nrf52840_xxaa,
  580. ct_sc32442b,
  581. { Raspberry Pi 2 }
  582. ct_raspi2,
  583. ct_thumb2bare:
  584. begin
  585. with embedded_controllers[current_settings.controllertype] do
  586. with linkres do
  587. begin
  588. if (embedded_controllers[current_settings.controllertype].controllerunitstr='MK20D5')
  589. or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK20D7')
  590. or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK22F51212')
  591. or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK64F12') then
  592. Add('ENTRY(_LOWLEVELSTART)')
  593. else
  594. Add('ENTRY(_START)');
  595. Add('MEMORY');
  596. Add('{');
  597. if flashsize<>0 then
  598. begin
  599. LinkStr := ' flash : ORIGIN = 0x' + IntToHex(flashbase,8)
  600. + ', LENGTH = 0x' + IntToHex(flashsize,8);
  601. Add(LinkStr);
  602. end;
  603. LinkStr := ' ram : ORIGIN = 0x' + IntToHex(srambase,8)
  604. + ', LENGTH = 0x' + IntToHex(sramsize,8);
  605. Add(LinkStr);
  606. Add('}');
  607. Add('_stack_top = 0x' + IntToHex(sramsize+srambase,8) + ';');
  608. // Add Checksum Calculation for LPC Controllers so that the bootloader starts the uploaded binary
  609. writeln(controllerunitstr);
  610. if (controllerunitstr = 'LPC8xx') or (controllerunitstr = 'LPC11XX') or (controllerunitstr = 'LPC122X') then
  611. Add('Startup_Checksum = 0 - (_stack_top + _START + 1 + NonMaskableInt_interrupt + 1 + Hardfault_interrupt + 1);');
  612. if (controllerunitstr = 'LPC13XX') then
  613. Add('Startup_Checksum = 0 - (_stack_top + _START + 1 + NonMaskableInt_interrupt + 1 + MemoryManagement_interrupt + 1 + BusFault_interrupt + 1 + UsageFault_interrupt + 1);');
  614. end;
  615. end
  616. else
  617. if not (cs_link_nolink in current_settings.globalswitches) then
  618. internalerror(200902011);
  619. end;
  620. with linkres do
  621. begin
  622. Add('SECTIONS');
  623. Add('{');
  624. Add(' .text :');
  625. Add(' {');
  626. Add(' _text_start = .;');
  627. Add(' KEEP(*(.init .init.*))');
  628. if (embedded_controllers[current_settings.controllertype].controllerunitstr='MK20D5')
  629. or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK20D7')
  630. or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK22F51212')
  631. or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK64F12') then
  632. begin
  633. Add(' . = 0x400;');
  634. Add(' KEEP(*(.flash_config *.flash_config.*))');
  635. end;
  636. Add(' *(.text .text.*)');
  637. Add(' *(.strings)');
  638. Add(' *(.rodata .rodata.*)');
  639. Add(' *(.comment)');
  640. Add(' . = ALIGN(4);');
  641. Add(' _etext = .;');
  642. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  643. begin
  644. Add(' } >flash');
  645. Add(' .note.gnu.build-id : { *(.note.gnu.build-id) } >flash ');
  646. end
  647. else
  648. begin
  649. Add(' } >ram');
  650. Add(' .note.gnu.build-id : { *(.note.gnu.build-id) } >ram ');
  651. end;
  652. Add(' .data :');
  653. Add(' {');
  654. Add(' _data = .;');
  655. Add(' *(.data .data.*)');
  656. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  657. Add(' _edata = .;');
  658. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  659. begin
  660. Add(' } >ram AT >flash');
  661. end
  662. else
  663. begin
  664. Add(' } >ram');
  665. end;
  666. Add(' .bss :');
  667. Add(' {');
  668. Add(' _bss_start = .;');
  669. Add(' *(.bss .bss.*)');
  670. Add(' *(COMMON)');
  671. Add(' } >ram');
  672. Add('. = ALIGN(4);');
  673. Add('_bss_end = . ;');
  674. Add('}');
  675. Add('_end = .;');
  676. end;
  677. {$endif ARM}
  678. {$ifdef i386}
  679. with linkres do
  680. begin
  681. Add('ENTRY(_START)');
  682. Add('SECTIONS');
  683. Add('{');
  684. Add(' . = 0x100000;');
  685. Add(' .text ALIGN (0x1000) :');
  686. Add(' {');
  687. Add(' _text = .;');
  688. Add(' KEEP(*(.init .init.*))');
  689. Add(' *(.text .text.*)');
  690. Add(' *(.strings)');
  691. Add(' *(.rodata .rodata.*)');
  692. Add(' *(.comment)');
  693. Add(' _etext = .;');
  694. Add(' }');
  695. Add(' .data ALIGN (0x1000) :');
  696. Add(' {');
  697. Add(' _data = .;');
  698. Add(' *(.data .data.*)');
  699. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  700. Add(' _edata = .;');
  701. Add(' }');
  702. Add(' . = ALIGN(4);');
  703. Add(' .bss :');
  704. Add(' {');
  705. Add(' _bss_start = .;');
  706. Add(' *(.bss .bss.*)');
  707. Add(' *(COMMON)');
  708. Add(' }');
  709. Add('_bss_end = . ;');
  710. Add('}');
  711. Add('_end = .;');
  712. end;
  713. {$endif i386}
  714. {$ifdef x86_64}
  715. with linkres do
  716. begin
  717. Add('ENTRY(_START)');
  718. Add('SECTIONS');
  719. Add('{');
  720. Add(' . = 0x100000;');
  721. Add(' .text ALIGN (0x1000) :');
  722. Add(' {');
  723. Add(' _text = .;');
  724. Add(' KEEP(*(.init .init.*))');
  725. Add(' *(.text .text.*)');
  726. Add(' *(.strings)');
  727. Add(' *(.rodata .rodata.*)');
  728. Add(' *(.comment)');
  729. Add(' _etext = .;');
  730. Add(' }');
  731. Add(' .data ALIGN (0x1000) :');
  732. Add(' {');
  733. Add(' _data = .;');
  734. Add(' *(.data .data.*)');
  735. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  736. Add(' _edata = .;');
  737. Add(' }');
  738. Add(' . = ALIGN(4);');
  739. Add(' .bss :');
  740. Add(' {');
  741. Add(' _bss_start = .;');
  742. Add(' *(.bss .bss.*)');
  743. Add(' *(COMMON)');
  744. Add(' }');
  745. Add('_bss_end = . ;');
  746. Add('}');
  747. Add('_end = .;');
  748. end;
  749. {$endif x86_64}
  750. {$ifdef AVR}
  751. with linkres do
  752. begin
  753. { linker script from ld 2.19 }
  754. Add('ENTRY(_START)');
  755. Add('OUTPUT_FORMAT("elf32-avr","elf32-avr","elf32-avr")');
  756. case current_settings.cputype of
  757. cpu_avr1:
  758. Add('OUTPUT_ARCH(avr:1)');
  759. cpu_avr2:
  760. Add('OUTPUT_ARCH(avr:2)');
  761. cpu_avr25:
  762. Add('OUTPUT_ARCH(avr:25)');
  763. cpu_avr3:
  764. Add('OUTPUT_ARCH(avr:3)');
  765. cpu_avr31:
  766. Add('OUTPUT_ARCH(avr:31)');
  767. cpu_avr35:
  768. Add('OUTPUT_ARCH(avr:35)');
  769. cpu_avr4:
  770. Add('OUTPUT_ARCH(avr:4)');
  771. cpu_avr5:
  772. Add('OUTPUT_ARCH(avr:5)');
  773. cpu_avr51:
  774. Add('OUTPUT_ARCH(avr:51)');
  775. cpu_avr6:
  776. Add('OUTPUT_ARCH(avr:6)');
  777. cpu_avrxmega3:
  778. Add('OUTPUT_ARCH(avr:103)');
  779. cpu_avrtiny:
  780. Add('OUTPUT_ARCH(avr:100)');
  781. else
  782. Internalerror(2015072701);
  783. end;
  784. Add('MEMORY');
  785. with embedded_controllers[current_settings.controllertype] do
  786. begin
  787. Add('{');
  788. Add(' text (rx) : ORIGIN = 0, LENGTH = 0x'+IntToHex(flashsize,6));
  789. Add(' data (rw!x) : ORIGIN = 0x'+IntToHex($800000+srambase,6)+', LENGTH = 0x'+IntToHex(sramsize,6));
  790. Add(' eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = 0x'+IntToHex(eepromsize,6));
  791. Add(' fuse (rw!x) : ORIGIN = 0x820000, LENGTH = 1K');
  792. Add(' lock (rw!x) : ORIGIN = 0x830000, LENGTH = 1K');
  793. Add(' signature (rw!x) : ORIGIN = 0x840000, LENGTH = 1K');
  794. Add('}');
  795. Add('_stack_top = 0x' + IntToHex(srambase+sramsize-1,4) + ';');
  796. end;
  797. Add('SECTIONS');
  798. Add('{');
  799. Add(' /* Read-only sections, merged into text segment: */');
  800. Add(' .hash : { *(.hash) }');
  801. Add(' .dynsym : { *(.dynsym) }');
  802. Add(' .dynstr : { *(.dynstr) }');
  803. Add(' .gnu.version : { *(.gnu.version) }');
  804. Add(' .gnu.version_d : { *(.gnu.version_d) }');
  805. Add(' .gnu.version_r : { *(.gnu.version_r) }');
  806. Add(' .rel.init : { *(.rel.init) }');
  807. Add(' .rela.init : { *(.rela.init) }');
  808. Add(' .rel.text :');
  809. Add(' {');
  810. Add(' *(.rel.text)');
  811. Add(' *(.rel.text.*)');
  812. Add(' *(.rel.gnu.linkonce.t*)');
  813. Add(' }');
  814. Add(' .rela.text :');
  815. Add(' {');
  816. Add(' *(.rela.text)');
  817. Add(' *(.rela.text.*)');
  818. Add(' *(.rela.gnu.linkonce.t*)');
  819. Add(' }');
  820. Add(' .rel.fini : { *(.rel.fini) }');
  821. Add(' .rela.fini : { *(.rela.fini) }');
  822. Add(' .rel.rodata :');
  823. Add(' {');
  824. Add(' *(.rel.rodata)');
  825. Add(' *(.rel.rodata.*)');
  826. Add(' *(.rel.gnu.linkonce.r*)');
  827. Add(' }');
  828. Add(' .rela.rodata :');
  829. Add(' {');
  830. Add(' *(.rela.rodata)');
  831. Add(' *(.rela.rodata.*)');
  832. Add(' *(.rela.gnu.linkonce.r*)');
  833. Add(' }');
  834. Add(' .rel.data :');
  835. Add(' {');
  836. Add(' *(.rel.data)');
  837. Add(' *(.rel.data.*)');
  838. Add(' *(.rel.gnu.linkonce.d*)');
  839. Add(' }');
  840. Add(' .rela.data :');
  841. Add(' {');
  842. Add(' *(.rela.data)');
  843. Add(' *(.rela.data.*)');
  844. Add(' *(.rela.gnu.linkonce.d*)');
  845. Add(' }');
  846. Add(' .rel.ctors : { *(.rel.ctors) }');
  847. Add(' .rela.ctors : { *(.rela.ctors) }');
  848. Add(' .rel.dtors : { *(.rel.dtors) }');
  849. Add(' .rela.dtors : { *(.rela.dtors) }');
  850. Add(' .rel.got : { *(.rel.got) }');
  851. Add(' .rela.got : { *(.rela.got) }');
  852. Add(' .rel.bss : { *(.rel.bss) }');
  853. Add(' .rela.bss : { *(.rela.bss) }');
  854. Add(' .rel.plt : { *(.rel.plt) }');
  855. Add(' .rela.plt : { *(.rela.plt) }');
  856. Add(' /* Internal text space or external memory. */');
  857. Add(' .text :');
  858. Add(' {');
  859. Add(' KEEP(*(.init .init.*))');
  860. Add(' /* For data that needs to reside in the lower 64k of progmem. */');
  861. Add(' *(.progmem.gcc*)');
  862. Add(' *(.progmem*)');
  863. Add(' . = ALIGN(2);');
  864. Add(' __trampolines_start = . ;');
  865. Add(' /* The jump trampolines for the 16-bit limited relocs will reside here. */');
  866. Add(' *(.trampolines)');
  867. Add(' *(.trampolines*)');
  868. Add(' __trampolines_end = . ;');
  869. Add(' /* For future tablejump instruction arrays for 3 byte pc devices.');
  870. Add(' We don''t relax jump/call instructions within these sections. */');
  871. Add(' *(.jumptables)');
  872. Add(' *(.jumptables*)');
  873. Add(' /* For code that needs to reside in the lower 128k progmem. */');
  874. Add(' *(.lowtext)');
  875. Add(' *(.lowtext*)');
  876. Add(' __ctors_start = . ;');
  877. Add(' *(.ctors)');
  878. Add(' __ctors_end = . ;');
  879. Add(' __dtors_start = . ;');
  880. Add(' *(.dtors)');
  881. Add(' __dtors_end = . ;');
  882. Add(' KEEP(SORT(*)(.ctors))');
  883. Add(' KEEP(SORT(*)(.dtors))');
  884. Add(' /* From this point on, we don''t bother about wether the insns are');
  885. Add(' below or above the 16 bits boundary. */');
  886. Add(' *(.init0) /* Start here after reset. */');
  887. Add(' KEEP (*(.init0))');
  888. Add(' *(.init1)');
  889. Add(' KEEP (*(.init1))');
  890. Add(' *(.init2) /* Clear __zero_reg__, set up stack pointer. */');
  891. Add(' KEEP (*(.init2))');
  892. Add(' *(.init3)');
  893. Add(' KEEP (*(.init3))');
  894. Add(' *(.init4) /* Initialize data and BSS. */');
  895. Add(' KEEP (*(.init4))');
  896. Add(' *(.init5)');
  897. Add(' KEEP (*(.init5))');
  898. Add(' *(.init6) /* C++ constructors. */');
  899. Add(' KEEP (*(.init6))');
  900. Add(' *(.init7)');
  901. Add(' KEEP (*(.init7))');
  902. Add(' *(.init8)');
  903. Add(' KEEP (*(.init8))');
  904. Add(' *(.init9) /* Call main(). */');
  905. Add(' KEEP (*(.init9))');
  906. Add(' *(.text)');
  907. Add(' . = ALIGN(2);');
  908. Add(' *(.text.*)');
  909. Add(' . = ALIGN(2);');
  910. Add(' *(.fini9) /* _exit() starts here. */');
  911. Add(' KEEP (*(.fini9))');
  912. Add(' *(.fini8)');
  913. Add(' KEEP (*(.fini8))');
  914. Add(' *(.fini7)');
  915. Add(' KEEP (*(.fini7))');
  916. Add(' *(.fini6) /* C++ destructors. */');
  917. Add(' KEEP (*(.fini6))');
  918. Add(' *(.fini5)');
  919. Add(' KEEP (*(.fini5))');
  920. Add(' *(.fini4)');
  921. Add(' KEEP (*(.fini4))');
  922. Add(' *(.fini3)');
  923. Add(' KEEP (*(.fini3))');
  924. Add(' *(.fini2)');
  925. Add(' KEEP (*(.fini2))');
  926. Add(' *(.fini1)');
  927. Add(' KEEP (*(.fini1))');
  928. Add(' *(.fini0) /* Infinite loop after program termination. */');
  929. Add(' KEEP (*(.fini0))');
  930. Add(' _etext = . ;');
  931. Add(' } > text');
  932. Add(' .data : AT (ADDR (.text) + SIZEOF (.text))');
  933. Add(' {');
  934. Add(' PROVIDE (__data_start = .) ;');
  935. Add(' *(.data)');
  936. Add(' *(.data*)');
  937. Add(' *(.rodata) /* We need to include .rodata here if gcc is used */');
  938. Add(' *(.rodata*) /* with -fdata-sections. */');
  939. Add(' *(.gnu.linkonce.d*)');
  940. Add(' . = ALIGN(2);');
  941. Add(' _edata = . ;');
  942. Add(' PROVIDE (__data_end = .) ;');
  943. Add(' } > data');
  944. Add(' .bss : AT (ADDR (.bss))');
  945. Add(' {');
  946. Add(' PROVIDE (__bss_start = .) ;');
  947. Add(' *(.bss)');
  948. Add(' *(.bss*)');
  949. Add(' *(COMMON)');
  950. Add(' PROVIDE (__bss_end = .) ;');
  951. Add(' } > data');
  952. Add(' __data_load_start = LOADADDR(.data);');
  953. Add(' __data_load_end = __data_load_start + SIZEOF(.data);');
  954. Add(' /* Global data not cleared after reset. */');
  955. Add(' .noinit :');
  956. Add(' {');
  957. Add(' PROVIDE (__noinit_start = .) ;');
  958. Add(' *(.noinit*)');
  959. Add(' PROVIDE (__noinit_end = .) ;');
  960. Add(' _end = . ;');
  961. Add(' PROVIDE (__heap_start = .) ;');
  962. Add(' } > data');
  963. Add(' .eeprom :');
  964. Add(' {');
  965. Add(' *(.eeprom*)');
  966. Add(' __eeprom_end = . ;');
  967. Add(' } > eeprom');
  968. Add(' .fuse :');
  969. Add(' {');
  970. Add(' KEEP(*(.fuse))');
  971. Add(' KEEP(*(.lfuse))');
  972. Add(' KEEP(*(.hfuse))');
  973. Add(' KEEP(*(.efuse))');
  974. Add(' } > fuse');
  975. Add(' .lock :');
  976. Add(' {');
  977. Add(' KEEP(*(.lock*))');
  978. Add(' } > lock');
  979. Add(' .signature :');
  980. Add(' {');
  981. Add(' KEEP(*(.signature*))');
  982. Add(' } > signature');
  983. Add(' /* Stabs debugging sections. */');
  984. Add(' .stab 0 : { *(.stab) }');
  985. Add(' .stabstr 0 : { *(.stabstr) }');
  986. Add(' .stab.excl 0 : { *(.stab.excl) }');
  987. Add(' .stab.exclstr 0 : { *(.stab.exclstr) }');
  988. Add(' .stab.index 0 : { *(.stab.index) }');
  989. Add(' .stab.indexstr 0 : { *(.stab.indexstr) }');
  990. Add(' .comment 0 : { *(.comment) }');
  991. Add(' /* DWARF debug sections.');
  992. Add(' Symbols in the DWARF debugging sections are relative to the beginning');
  993. Add(' of the section so we begin them at 0. */');
  994. Add(' /* DWARF 1 */');
  995. Add(' .debug 0 : { *(.debug) }');
  996. Add(' .line 0 : { *(.line) }');
  997. Add(' /* GNU DWARF 1 extensions */');
  998. Add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  999. Add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  1000. Add(' /* DWARF 1.1 and DWARF 2 */');
  1001. Add(' .debug_aranges 0 : { *(.debug_aranges) }');
  1002. Add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  1003. Add(' /* DWARF 2 */');
  1004. Add(' .debug_info 0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }');
  1005. Add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  1006. Add(' .debug_line 0 : { *(.debug_line) }');
  1007. Add(' .debug_frame 0 : { *(.debug_frame) }');
  1008. Add(' .debug_str 0 : { *(.debug_str) }');
  1009. Add(' .debug_loc 0 : { *(.debug_loc) }');
  1010. Add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  1011. Add('}');
  1012. end;
  1013. {$endif AVR}
  1014. {$ifdef MIPSEL}
  1015. case current_settings.controllertype of
  1016. ct_none:
  1017. begin
  1018. end;
  1019. ct_pic32mx110f016b,
  1020. ct_pic32mx110f016c,
  1021. ct_pic32mx110f016d,
  1022. ct_pic32mx120f032b,
  1023. ct_pic32mx120f032c,
  1024. ct_pic32mx120f032d,
  1025. ct_pic32mx130f064b,
  1026. ct_pic32mx130f064c,
  1027. ct_pic32mx130f064d,
  1028. ct_pic32mx150f128b,
  1029. ct_pic32mx150f128c,
  1030. ct_pic32mx150f128d,
  1031. ct_pic32mx210f016b,
  1032. ct_pic32mx210f016c,
  1033. ct_pic32mx210f016d,
  1034. ct_pic32mx220f032b,
  1035. ct_pic32mx220f032c,
  1036. ct_pic32mx220f032d,
  1037. ct_pic32mx230f064b,
  1038. ct_pic32mx230f064c,
  1039. ct_pic32mx230f064d,
  1040. ct_pic32mx250f128b,
  1041. ct_pic32mx250f128c,
  1042. ct_pic32mx250f128d,
  1043. ct_pic32mx775f256h,
  1044. ct_pic32mx775f256l,
  1045. ct_pic32mx775f512h,
  1046. ct_pic32mx775f512l,
  1047. ct_pic32mx795f512h,
  1048. ct_pic32mx795f512l:
  1049. begin
  1050. with embedded_controllers[current_settings.controllertype] do
  1051. with linkres do
  1052. begin
  1053. Add('OUTPUT_FORMAT("elf32-tradlittlemips")');
  1054. Add('OUTPUT_ARCH(pic32mx)');
  1055. Add('ENTRY(_reset)');
  1056. Add('PROVIDE(_vector_spacing = 0x00000001);');
  1057. Add('_ebase_address = 0x'+IntToHex(flashbase,8)+';');
  1058. Add('_RESET_ADDR = 0xBFC00000;');
  1059. Add('_BEV_EXCPT_ADDR = 0xBFC00380;');
  1060. Add('_DBG_EXCPT_ADDR = 0xBFC00480;');
  1061. Add('_GEN_EXCPT_ADDR = _ebase_address + 0x180;');
  1062. Add('MEMORY');
  1063. Add('{');
  1064. if flashsize<>0 then
  1065. begin
  1066. Add(' kseg0_program_mem : ORIGIN = 0x'+IntToHex(flashbase,8)+', LENGTH = 0x'+IntToHex(flashsize,8));
  1067. //TODO This should better be placed into the controllertype records
  1068. Add(' kseg1_boot_mem : ORIGIN = 0xBFC00000, LENGTH = 0xbef');
  1069. Add(' config3 : ORIGIN = 0xBFC00BF0, LENGTH = 0x4');
  1070. Add(' config2 : ORIGIN = 0xBFC00BF4, LENGTH = 0x4');
  1071. Add(' config1 : ORIGIN = 0xBFC00BF8, LENGTH = 0x4');
  1072. Add(' config0 : ORIGIN = 0xBFC00BFC, LENGTH = 0x4');
  1073. end;
  1074. Add(' ram : ORIGIN = 0x' + IntToHex(srambase,8)
  1075. + ', LENGTH = 0x' + IntToHex(sramsize,8));
  1076. Add('}');
  1077. Add('_stack_top = 0x' + IntToHex(sramsize+srambase,8) + ';');
  1078. end;
  1079. end
  1080. end;
  1081. with linkres do
  1082. begin
  1083. Add('SECTIONS');
  1084. Add('{');
  1085. Add(' .reset _RESET_ADDR :');
  1086. Add(' {');
  1087. Add(' KEEP(*(.reset .reset.*))');
  1088. Add(' KEEP(*(.startup .startup.*))');
  1089. Add(' } > kseg1_boot_mem');
  1090. Add(' .bev_excpt _BEV_EXCPT_ADDR :');
  1091. Add(' {');
  1092. Add(' KEEP(*(.bev_handler))');
  1093. Add(' } > kseg1_boot_mem');
  1094. Add(' .text :');
  1095. Add(' {');
  1096. Add(' _text_start = .;');
  1097. Add(' . = _text_start + 0x180;');
  1098. Add(' KEEP(*(.gen_handler))');
  1099. Add(' . = _text_start + 0x200;');
  1100. Add(' KEEP(*(.init .init.*))');
  1101. Add(' *(.text .text.*)');
  1102. Add(' *(.strings)');
  1103. Add(' *(.rodata .rodata.*)');
  1104. Add(' *(.comment)');
  1105. Add(' _etext = .;');
  1106. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  1107. begin
  1108. Add(' } >kseg0_program_mem');
  1109. end
  1110. else
  1111. begin
  1112. Add(' } >ram');
  1113. end;
  1114. Add(' .note.gnu.build-id : { *(.note.gnu.build-id) }');
  1115. Add(' .data :');
  1116. Add(' {');
  1117. Add(' _data = .;');
  1118. Add(' *(.data .data.*)');
  1119. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  1120. Add(' . = .;');
  1121. Add(' _gp = ALIGN(16) + 0x7ff0;');
  1122. Add(' _edata = .;');
  1123. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  1124. begin
  1125. Add(' } >ram AT >kseg0_program_mem');
  1126. end
  1127. else
  1128. begin
  1129. Add(' } >ram');
  1130. end;
  1131. Add(' .config_BFC00BF0 : {');
  1132. Add(' KEEP(*(.config_BFC00BF0))');
  1133. Add(' } > config3');
  1134. Add(' .config_BFC00BF4 : {');
  1135. Add(' KEEP(*(.config_BFC00BF4))');
  1136. Add(' } > config2');
  1137. Add(' .config_BFC00BF8 : {');
  1138. Add(' KEEP(*(.config_BFC00BF8))');
  1139. Add(' } > config1');
  1140. Add(' .config_BFC00BFC : {');
  1141. Add(' KEEP(*(.config_BFC00BFC))');
  1142. Add(' } > config0');
  1143. Add(' .bss :');
  1144. Add(' {');
  1145. Add(' _bss_start = .;');
  1146. Add(' *(.bss .bss.*)');
  1147. Add(' *(COMMON)');
  1148. Add(' } >ram');
  1149. Add('. = ALIGN(4);');
  1150. Add('_bss_end = . ;');
  1151. Add(' .comment 0 : { *(.comment) }');
  1152. Add(' /* DWARF debug sections.');
  1153. Add(' Symbols in the DWARF debugging sections are relative to the beginning');
  1154. Add(' of the section so we begin them at 0. */');
  1155. Add(' /* DWARF 1 */');
  1156. Add(' .debug 0 : { *(.debug) }');
  1157. Add(' .line 0 : { *(.line) }');
  1158. Add(' /* GNU DWARF 1 extensions */');
  1159. Add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  1160. Add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  1161. Add(' /* DWARF 1.1 and DWARF 2 */');
  1162. Add(' .debug_aranges 0 : { *(.debug_aranges) }');
  1163. Add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  1164. Add(' /* DWARF 2 */');
  1165. Add(' .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }');
  1166. Add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  1167. Add(' /DISCARD/ : { *(.debug_line) }');
  1168. Add(' .debug_frame 0 : { *(.debug_frame) }');
  1169. Add(' .debug_str 0 : { *(.debug_str) }');
  1170. Add(' /DISCARD/ : { *(.debug_loc) }');
  1171. Add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  1172. Add(' /* SGI/MIPS DWARF 2 extensions */');
  1173. Add(' .debug_weaknames 0 : { *(.debug_weaknames) }');
  1174. Add(' .debug_funcnames 0 : { *(.debug_funcnames) }');
  1175. Add(' .debug_typenames 0 : { *(.debug_typenames) }');
  1176. Add(' .debug_varnames 0 : { *(.debug_varnames) }');
  1177. Add(' /* DWARF 3 */');
  1178. Add(' .debug_pubtypes 0 : { *(.debug_pubtypes) }');
  1179. Add(' .debug_ranges 0 : { *(.debug_ranges) }');
  1180. Add(' .gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }');
  1181. Add(' .gptab.sdata : { *(.gptab.data) *(.gptab.sdata) }');
  1182. Add(' .gptab.sbss : { *(.gptab.bss) *(.gptab.sbss) }');
  1183. Add(' .mdebug.abi32 : { KEEP(*(.mdebug.abi32)) }');
  1184. Add(' .mdebug.abiN32 : { KEEP(*(.mdebug.abiN32)) }');
  1185. Add(' .mdebug.abi64 : { KEEP(*(.mdebug.abi64)) }');
  1186. Add(' .mdebug.abiO64 : { KEEP(*(.mdebug.abiO64)) }');
  1187. Add(' .mdebug.eabi32 : { KEEP(*(.mdebug.eabi32)) }');
  1188. Add(' .mdebug.eabi64 : { KEEP(*(.mdebug.eabi64)) }');
  1189. Add(' /DISCARD/ : { *(.rel.dyn) }');
  1190. Add(' /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }');
  1191. Add('}');
  1192. Add('_end = .;');
  1193. end;
  1194. {$endif MIPSEL}
  1195. {$ifdef RISCV32}
  1196. with linkres do
  1197. begin
  1198. Add('OUTPUT_ARCH("riscv")');
  1199. Add('ENTRY(_START)');
  1200. Add('MEMORY');
  1201. with embedded_controllers[current_settings.controllertype] do
  1202. begin
  1203. Add('{');
  1204. Add(' flash (rx) : ORIGIN = 0x'+IntToHex(flashbase,6)+', LENGTH = 0x'+IntToHex(flashsize,6));
  1205. Add(' ram (rw!x) : ORIGIN = 0x'+IntToHex(srambase,6)+', LENGTH = 0x'+IntToHex(sramsize,6));
  1206. Add('}');
  1207. Add('_stack_top = 0x' + IntToHex(srambase+sramsize-1,4) + ';');
  1208. end;
  1209. Add('SECTIONS');
  1210. Add('{');
  1211. Add(' .text :');
  1212. Add(' {');
  1213. Add(' _text_start = .;');
  1214. Add(' KEEP(*(.init .init.*))');
  1215. Add(' *(.text .text.*)');
  1216. Add(' *(.strings)');
  1217. Add(' *(.rodata .rodata.*)');
  1218. Add(' *(.comment)');
  1219. Add(' . = ALIGN(4);');
  1220. Add(' _etext = .;');
  1221. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  1222. begin
  1223. Add(' } >flash');
  1224. //Add(' .note.gnu.build-id : { *(.note.gnu.build-id) } >flash ');
  1225. end
  1226. else
  1227. begin
  1228. Add(' } >ram');
  1229. //Add(' .note.gnu.build-id : { *(.note.gnu.build-id) } >ram ');
  1230. end;
  1231. Add(' .data :');
  1232. Add(' {');
  1233. Add(' _data = .;');
  1234. Add(' *(.data .data.*)');
  1235. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  1236. Add(' _edata = .;');
  1237. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  1238. begin
  1239. Add(' } >ram AT >flash');
  1240. end
  1241. else
  1242. begin
  1243. Add(' } >ram');
  1244. end;
  1245. Add(' .bss :');
  1246. Add(' {');
  1247. Add(' _bss_start = .;');
  1248. Add(' *(.bss .bss.*)');
  1249. Add(' *(COMMON)');
  1250. Add(' } >ram');
  1251. Add(' . = ALIGN(4);');
  1252. Add(' _bss_end = . ;');
  1253. Add(' /* Stabs debugging sections. */');
  1254. Add(' .stab 0 : { *(.stab) }');
  1255. Add(' .stabstr 0 : { *(.stabstr) }');
  1256. Add(' .stab.excl 0 : { *(.stab.excl) }');
  1257. Add(' .stab.exclstr 0 : { *(.stab.exclstr) }');
  1258. Add(' .stab.index 0 : { *(.stab.index) }');
  1259. Add(' .stab.indexstr 0 : { *(.stab.indexstr) }');
  1260. Add(' .comment 0 : { *(.comment) }');
  1261. Add(' /* DWARF debug sections.');
  1262. Add(' Symbols in the DWARF debugging sections are relative to the beginning');
  1263. Add(' of the section so we begin them at 0. */');
  1264. Add(' /* DWARF 1 */');
  1265. Add(' .debug 0 : { *(.debug) }');
  1266. Add(' .line 0 : { *(.line) }');
  1267. Add(' /* GNU DWARF 1 extensions */');
  1268. Add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  1269. Add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  1270. Add(' /* DWARF 1.1 and DWARF 2 */');
  1271. Add(' .debug_aranges 0 : { *(.debug_aranges) }');
  1272. Add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  1273. Add(' /* DWARF 2 */');
  1274. Add(' .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }');
  1275. Add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  1276. Add(' .debug_line 0 : { *(.debug_line) }');
  1277. Add(' .debug_frame 0 : { *(.debug_frame) }');
  1278. Add(' .debug_str 0 : { *(.debug_str) }');
  1279. Add(' .debug_loc 0 : { *(.debug_loc) }');
  1280. Add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  1281. Add(' /* SGI/MIPS DWARF 2 extensions */');
  1282. Add(' .debug_weaknames 0 : { *(.debug_weaknames) }');
  1283. Add(' .debug_funcnames 0 : { *(.debug_funcnames) }');
  1284. Add(' .debug_typenames 0 : { *(.debug_typenames) }');
  1285. Add(' .debug_varnames 0 : { *(.debug_varnames) }');
  1286. Add(' /* DWARF 3 */');
  1287. Add(' .debug_pubtypes 0 : { *(.debug_pubtypes) }');
  1288. Add(' .debug_ranges 0 : { *(.debug_ranges) }');
  1289. Add('}');
  1290. Add('_end = .;');
  1291. end;
  1292. {$endif RISCV32}
  1293. {$ifdef XTENSA}
  1294. with linkres do
  1295. begin
  1296. Add('/* Script for -z combreloc: combine and sort reloc sections */');
  1297. Add('/* Copyright (C) 2014-2018 Free Software Foundation, Inc.');
  1298. Add(' Copying and distribution of this script, with or without modification,');
  1299. Add(' are permitted in any medium without royalty provided the copyright');
  1300. Add(' notice and this notice are preserved. */');
  1301. Add('ENTRY(_start)');
  1302. 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");');
  1303. Add('SECTIONS');
  1304. Add('{');
  1305. Add(' /* Read-only sections, merged into text segment: */');
  1306. Add(' PROVIDE (__executable_start = 0x400000); . = 0x400000 + SIZEOF_HEADERS;');
  1307. Add(' .interp : { *(.interp) }');
  1308. Add(' .note.gnu.build-id : { *(.note.gnu.build-id) }');
  1309. Add(' .hash : { *(.hash) }');
  1310. Add(' .gnu.hash : { *(.gnu.hash) }');
  1311. Add(' .dynsym : { *(.dynsym) }');
  1312. Add(' .dynstr : { *(.dynstr) }');
  1313. Add(' .gnu.version : { *(.gnu.version) }');
  1314. Add(' .gnu.version_d : { *(.gnu.version_d) }');
  1315. Add(' .gnu.version_r : { *(.gnu.version_r) }');
  1316. Add(' .rela.dyn :');
  1317. Add(' {');
  1318. Add(' *(.rela.init)');
  1319. Add(' *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)');
  1320. Add(' *(.rela.fini)');
  1321. Add(' *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)');
  1322. Add(' *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)');
  1323. Add(' *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)');
  1324. Add(' *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)');
  1325. Add(' *(.rela.ctors)');
  1326. Add(' *(.rela.dtors)');
  1327. Add(' *(.rela.got)');
  1328. Add(' *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)');
  1329. Add(' }');
  1330. Add(' .rela.plt : { *(.rela.plt) }');
  1331. Add(' /* .plt* sections are embedded in .text */');
  1332. Add(' .text :');
  1333. Add(' {');
  1334. Add(' *(.got.plt* .plt*)');
  1335. Add(' KEEP (*(.init.literal))');
  1336. Add(' KEEP (*(SORT_NONE(.init)))');
  1337. Add(' *(.literal .text .stub .literal.* .text.* .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)');
  1338. Add(' /* .gnu.warning sections are handled specially by elf32.em. */');
  1339. Add(' *(.gnu.warning)');
  1340. Add(' KEEP (*(.fini.literal))');
  1341. Add(' KEEP (*(SORT_NONE(.fini)))');
  1342. Add(' } =0');
  1343. Add(' PROVIDE (__etext = .);');
  1344. Add(' PROVIDE (_etext = .);');
  1345. Add(' PROVIDE (etext = .);');
  1346. Add(' .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }');
  1347. Add(' .rodata1 : { *(.rodata1) }');
  1348. Add(' .got.loc : { *(.got.loc) }');
  1349. Add(' .xt_except_table : ONLY_IF_RO { KEEP (*(.xt_except_table .xt_except_table.* .gnu.linkonce.e.*)) }');
  1350. Add(' .eh_frame_hdr : { *(.eh_frame_hdr) }');
  1351. Add(' .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) }');
  1352. Add(' .gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }');
  1353. Add(' /* Adjust the address for the data segment. We want to adjust up to');
  1354. Add(' the same address within the page on the next page up. */');
  1355. Add(' . = ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1));');
  1356. Add(' /* Exception handling */');
  1357. Add(' .eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) }');
  1358. Add(' .gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }');
  1359. Add(' /* Thread Local Storage sections */');
  1360. Add(' .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) }');
  1361. Add(' .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }');
  1362. Add(' .preinit_array :');
  1363. Add(' {');
  1364. Add(' PROVIDE_HIDDEN (__preinit_array_start = .);');
  1365. Add(' KEEP (*(.preinit_array))');
  1366. Add(' PROVIDE_HIDDEN (__preinit_array_end = .);');
  1367. Add(' }');
  1368. Add(' .init_array :');
  1369. Add(' {');
  1370. Add(' PROVIDE_HIDDEN (__init_array_start = .);');
  1371. Add(' KEEP (*(SORT(.init_array.*)))');
  1372. Add(' KEEP (*(.init_array))');
  1373. Add(' PROVIDE_HIDDEN (__init_array_end = .);');
  1374. Add(' }');
  1375. Add(' .fini_array :');
  1376. Add(' {');
  1377. Add(' PROVIDE_HIDDEN (__fini_array_start = .);');
  1378. Add(' KEEP (*(SORT(.fini_array.*)))');
  1379. Add(' KEEP (*(.fini_array))');
  1380. Add(' PROVIDE_HIDDEN (__fini_array_end = .);');
  1381. Add(' }');
  1382. Add(' .ctors :');
  1383. Add(' {');
  1384. Add(' /* gcc uses crtbegin.o to find the start of');
  1385. Add(' the constructors, so we make sure it is');
  1386. Add(' first. Because this is a wildcard, it');
  1387. Add(' doesn''t matter if the user does not');
  1388. Add(' actually link against crtbegin.o; the');
  1389. Add(' linker won''t look for a file to match a');
  1390. Add(' wildcard. The wildcard also means that it');
  1391. Add(' doesn''t matter which directory crtbegin.o');
  1392. Add(' is in. */');
  1393. Add(' KEEP (*crtbegin.o(.ctors))');
  1394. Add(' KEEP (*crtbegin?.o(.ctors))');
  1395. Add(' /* We don''t want to include the .ctor section from');
  1396. Add(' the crtend.o file until after the sorted ctors.');
  1397. Add(' The .ctor section from the crtend file contains the');
  1398. Add(' end of ctors marker and it must be last */');
  1399. Add(' KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))');
  1400. Add(' KEEP (*(SORT(.ctors.*)))');
  1401. Add(' KEEP (*(.ctors))');
  1402. Add(' }');
  1403. Add(' .dtors :');
  1404. Add(' {');
  1405. Add(' KEEP (*crtbegin.o(.dtors))');
  1406. Add(' KEEP (*crtbegin?.o(.dtors))');
  1407. Add(' KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))');
  1408. Add(' KEEP (*(SORT(.dtors.*)))');
  1409. Add(' KEEP (*(.dtors))');
  1410. Add(' }');
  1411. Add(' .jcr : { KEEP (*(.jcr)) }');
  1412. 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.*) }');
  1413. Add(' .xt_except_table : ONLY_IF_RW { KEEP (*(.xt_except_table .xt_except_table.* .gnu.linkonce.e.*)) }');
  1414. Add(' .dynamic : { *(.dynamic) }');
  1415. Add(' .got : { *(.got) }');
  1416. Add(' .data :');
  1417. Add(' {');
  1418. Add(' *(.data .data.* .gnu.linkonce.d.*)');
  1419. Add(' SORT(CONSTRUCTORS)');
  1420. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  1421. Add(' }');
  1422. Add(' .data1 : { *(.data1) }');
  1423. Add(' .xt_except_desc :');
  1424. Add(' {');
  1425. Add(' *(.xt_except_desc .xt_except_desc.* .gnu.linkonce.h.*)');
  1426. Add(' *(.xt_except_desc_end)');
  1427. Add(' }');
  1428. Add(' .lit4 :');
  1429. Add(' {');
  1430. Add(' PROVIDE (_lit4_start = .);');
  1431. Add(' *(.lit4 .lit4.* .gnu.linkonce.lit4.*)');
  1432. Add(' PROVIDE (_lit4_end = .);');
  1433. Add(' }');
  1434. Add(' _edata = .; PROVIDE (edata = .);');
  1435. Add(' __bss_start = .;');
  1436. Add(' .bss :');
  1437. Add(' {');
  1438. Add(' *(.dynbss)');
  1439. Add(' *(.bss .bss.* .gnu.linkonce.b.*)');
  1440. Add(' *(COMMON)');
  1441. Add(' /* Align here to ensure that the .bss section occupies space up to');
  1442. Add(' _end. Align after .bss to ensure correct alignment even if the');
  1443. Add(' .bss section disappears because there are no input sections.');
  1444. Add(' FIXME: Why do we need it? When there is no .bss section, we don''t');
  1445. Add(' pad the .data section. */');
  1446. Add(' . = ALIGN(. != 0 ? 32 / 8 : 1);');
  1447. Add(' }');
  1448. Add(' . = ALIGN(32 / 8);');
  1449. Add(' . = ALIGN(32 / 8);');
  1450. Add(' _end = .; PROVIDE (end = .);');
  1451. Add(' /* Stabs debugging sections. */');
  1452. Add(' .stab 0 : { *(.stab) }');
  1453. Add(' .stabstr 0 : { *(.stabstr) }');
  1454. Add(' .stab.excl 0 : { *(.stab.excl) }');
  1455. Add(' .stab.exclstr 0 : { *(.stab.exclstr) }');
  1456. Add(' .stab.index 0 : { *(.stab.index) }');
  1457. Add(' .stab.indexstr 0 : { *(.stab.indexstr) }');
  1458. Add(' .comment 0 : { *(.comment) }');
  1459. Add(' /* DWARF debug sections.');
  1460. Add(' Symbols in the DWARF debugging sections are relative to the beginning');
  1461. Add(' of the section so we begin them at 0. */');
  1462. Add(' /* DWARF 1 */');
  1463. Add(' .debug 0 : { *(.debug) }');
  1464. Add(' .line 0 : { *(.line) }');
  1465. Add(' /* GNU DWARF 1 extensions */');
  1466. Add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  1467. Add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  1468. Add(' /* DWARF 1.1 and DWARF 2 */');
  1469. Add(' .debug_aranges 0 : { *(.debug_aranges) }');
  1470. Add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  1471. Add(' /* DWARF 2 */');
  1472. Add(' .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }');
  1473. Add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  1474. Add(' .debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end ) }');
  1475. Add(' .debug_frame 0 : { *(.debug_frame) }');
  1476. Add(' .debug_str 0 : { *(.debug_str) }');
  1477. Add(' .debug_loc 0 : { *(.debug_loc) }');
  1478. Add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  1479. Add(' /* SGI/MIPS DWARF 2 extensions */');
  1480. Add(' .debug_weaknames 0 : { *(.debug_weaknames) }');
  1481. Add(' .debug_funcnames 0 : { *(.debug_funcnames) }');
  1482. Add(' .debug_typenames 0 : { *(.debug_typenames) }');
  1483. Add(' .debug_varnames 0 : { *(.debug_varnames) }');
  1484. Add(' /* DWARF 3 */');
  1485. Add(' .debug_pubtypes 0 : { *(.debug_pubtypes) }');
  1486. Add(' .debug_ranges 0 : { *(.debug_ranges) }');
  1487. Add(' /* DWARF Extension. */');
  1488. Add(' .debug_macro 0 : { *(.debug_macro) }');
  1489. Add(' .debug_addr 0 : { *(.debug_addr) }');
  1490. Add(' .gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }');
  1491. Add(' .xt.lit 0 : { KEEP (*(.xt.lit .xt.lit.* .gnu.linkonce.p.*)) }');
  1492. Add(' .xt.insn 0 : { KEEP (*(.xt.insn .gnu.linkonce.x.*)) }');
  1493. Add(' .xt.prop 0 : { KEEP (*(.xt.prop .xt.prop.* .gnu.linkonce.prop.*)) }');
  1494. Add(' /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }');
  1495. Add('}');
  1496. end;
  1497. {$endif XTENSA}
  1498. { Write and Close response }
  1499. linkres.writetodisk;
  1500. linkres.free;
  1501. WriteResponseFile:=True;
  1502. end;
  1503. function TlinkerEmbedded.MakeExecutable:boolean;
  1504. var
  1505. binstr,
  1506. cmdstr,
  1507. mapstr: TCmdStr;
  1508. success : boolean;
  1509. StaticStr,
  1510. GCSectionsStr,
  1511. DynLinkStr,
  1512. StripStr,
  1513. FixedExeFileName: string;
  1514. begin
  1515. { for future use }
  1516. StaticStr:='';
  1517. StripStr:='';
  1518. mapstr:='';
  1519. DynLinkStr:='';
  1520. FixedExeFileName:=maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.elf')));
  1521. GCSectionsStr:='--gc-sections';
  1522. //if not(cs_link_extern in current_settings.globalswitches) then
  1523. if not(cs_link_nolink in current_settings.globalswitches) then
  1524. Message1(exec_i_linking,current_module.exefilename);
  1525. if (cs_link_map in current_settings.globalswitches) then
  1526. mapstr:='-Map '+maybequoted(ChangeFileExt(current_module.exefilename,'.map'));
  1527. { Write used files and libraries }
  1528. WriteResponseFile();
  1529. { Call linker }
  1530. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  1531. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  1532. if not(cs_link_on_target in current_settings.globalswitches) then
  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. else
  1543. begin
  1544. Replace(cmdstr,'$EXE',FixedExeFileName);
  1545. Replace(cmdstr,'$RES',maybequoted(ScriptFixFileName(outputexedir+Info.ResName)));
  1546. Replace(cmdstr,'$STATIC',StaticStr);
  1547. Replace(cmdstr,'$STRIP',StripStr);
  1548. Replace(cmdstr,'$MAP',mapstr);
  1549. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  1550. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  1551. end;
  1552. success:=DoExec(FindUtil(utilsprefix+BinStr),cmdstr,true,false);
  1553. { Remove ReponseFile }
  1554. if success and not(cs_link_nolink in current_settings.globalswitches) then
  1555. DeleteFile(outputexedir+Info.ResName);
  1556. { Post process }
  1557. if success and not(cs_link_nolink in current_settings.globalswitches) then
  1558. success:=PostProcessExecutable(FixedExeFileName,false);
  1559. if success and (target_info.system in [system_arm_embedded,system_avr_embedded,system_mipsel_embedded,system_xtensa_embedded]) then
  1560. begin
  1561. success:=DoExec(FindUtil(utilsprefix+'objcopy'),'-O ihex '+
  1562. FixedExeFileName+' '+
  1563. maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.hex'))),true,false);
  1564. if success then
  1565. success:=DoExec(FindUtil(utilsprefix+'objcopy'),'-O binary '+
  1566. FixedExeFileName+' '+
  1567. maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.bin'))),true,false);
  1568. {$ifdef ARM}
  1569. if success and (current_settings.controllertype = ct_raspi2) then
  1570. success:=DoExec(FindUtil(utilsprefix+'objcopy'),'-O binary '+ FixedExeFileName + ' kernel7.img',true,false);
  1571. {$endif ARM}
  1572. end;
  1573. MakeExecutable:=success; { otherwise a recursive call to link method }
  1574. end;
  1575. function TLinkerEmbedded.postprocessexecutable(const fn : string;isdll:boolean):boolean;
  1576. begin
  1577. Result:=PostProcessELFExecutable(fn,isdll);
  1578. end;
  1579. {*****************************************************************************
  1580. TlinkerEmbedded_SdccSdld
  1581. *****************************************************************************}
  1582. function TlinkerEmbedded_SdccSdld.WriteResponseFile: Boolean;
  1583. Var
  1584. linkres : TLinkRes;
  1585. //i : longint;
  1586. //HPath : TCmdStrListItem;
  1587. s{,s1,s2} : TCmdStr;
  1588. prtobj,
  1589. cprtobj : string[80];
  1590. linklibc : boolean;
  1591. //found1,
  1592. //found2 : boolean;
  1593. begin
  1594. WriteResponseFile:=False;
  1595. linklibc:=(SharedLibFiles.Find('c')<>nil);
  1596. prtobj:='prt0';
  1597. cprtobj:='cprt0';
  1598. if linklibc then
  1599. prtobj:=cprtobj;
  1600. { Open link.res file }
  1601. LinkRes:=TLinkRes.Create(outputexedir+Info.ResName,true);
  1602. { Write path to search libraries }
  1603. (* HPath:=TCmdStrListItem(current_module.locallibrarysearchpath.First);
  1604. while assigned(HPath) do
  1605. begin
  1606. s:=HPath.Str;
  1607. if (cs_link_on_target in current_settings.globalswitches) then
  1608. s:=ScriptFixFileName(s);
  1609. LinkRes.Add('-L'+s);
  1610. HPath:=TCmdStrListItem(HPath.Next);
  1611. end;
  1612. HPath:=TCmdStrListItem(LibrarySearchPath.First);
  1613. while assigned(HPath) do
  1614. begin
  1615. s:=HPath.Str;
  1616. if s<>'' then
  1617. LinkRes.Add('SEARCH_DIR("'+s+'")');
  1618. HPath:=TCmdStrListItem(HPath.Next);
  1619. end;
  1620. LinkRes.Add('INPUT (');
  1621. { add objectfiles, start with prt0 always }*)
  1622. //s:=FindObjectFile('prt0','',false);
  1623. if prtobj<>'' then
  1624. begin
  1625. s:=FindObjectFile(prtobj,'',false);
  1626. LinkRes.AddFileName(s);
  1627. end;
  1628. { try to add crti and crtbegin if linking to C }
  1629. if linklibc then
  1630. begin
  1631. if librarysearchpath.FindFile('crtbegin.o',false,s) then
  1632. LinkRes.AddFileName(s);
  1633. if librarysearchpath.FindFile('crti.o',false,s) then
  1634. LinkRes.AddFileName(s);
  1635. end;
  1636. while not ObjectFiles.Empty do
  1637. begin
  1638. s:=ObjectFiles.GetFirst;
  1639. if s<>'' then
  1640. begin
  1641. { vlink doesn't use SEARCH_DIR for object files }
  1642. if not(cs_link_on_target in current_settings.globalswitches) then
  1643. s:=FindObjectFile(s,'',false);
  1644. LinkRes.AddFileName((maybequoted(s)));
  1645. end;
  1646. end;
  1647. { Write staticlibraries }
  1648. if not StaticLibFiles.Empty then
  1649. begin
  1650. { vlink doesn't need, and doesn't support GROUP }
  1651. { if (cs_link_on_target in current_settings.globalswitches) then
  1652. begin
  1653. LinkRes.Add(')');
  1654. LinkRes.Add('GROUP(');
  1655. end;}
  1656. while not StaticLibFiles.Empty do
  1657. begin
  1658. S:=StaticLibFiles.GetFirst;
  1659. LinkRes.Add('-l'+maybequoted(s));
  1660. end;
  1661. end;
  1662. (* if (cs_link_on_target in current_settings.globalswitches) then
  1663. begin
  1664. LinkRes.Add(')');
  1665. { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
  1666. here to be sure that it gets linked this is needed for glibc2 systems (PFV) }
  1667. linklibc:=false;
  1668. while not SharedLibFiles.Empty do
  1669. begin
  1670. S:=SharedLibFiles.GetFirst;
  1671. if s<>'c' then
  1672. begin
  1673. i:=Pos(target_info.sharedlibext,S);
  1674. if i>0 then
  1675. Delete(S,i,255);
  1676. LinkRes.Add('-l'+s);
  1677. end
  1678. else
  1679. begin
  1680. LinkRes.Add('-l'+s);
  1681. linklibc:=true;
  1682. end;
  1683. end;
  1684. { be sure that libc&libgcc is the last lib }
  1685. if linklibc then
  1686. begin
  1687. LinkRes.Add('-lc');
  1688. LinkRes.Add('-lgcc');
  1689. end;
  1690. end
  1691. else
  1692. begin
  1693. while not SharedLibFiles.Empty do
  1694. begin
  1695. S:=SharedLibFiles.GetFirst;
  1696. LinkRes.Add('lib'+s+target_info.staticlibext);
  1697. end;
  1698. LinkRes.Add(')');
  1699. end;*)
  1700. { objects which must be at the end }
  1701. (*if linklibc then
  1702. begin
  1703. found1:=librarysearchpath.FindFile('crtend.o',false,s1);
  1704. found2:=librarysearchpath.FindFile('crtn.o',false,s2);
  1705. if found1 or found2 then
  1706. begin
  1707. LinkRes.Add('INPUT(');
  1708. if found1 then
  1709. LinkRes.AddFileName(s1);
  1710. if found2 then
  1711. LinkRes.AddFileName(s2);
  1712. LinkRes.Add(')');
  1713. end;
  1714. end;*)
  1715. { Write and Close response }
  1716. linkres.writetodisk;
  1717. linkres.free;
  1718. WriteResponseFile:=True;
  1719. end;
  1720. procedure TlinkerEmbedded_SdccSdld.SetDefaultInfo;
  1721. const
  1722. {$if defined(Z80)}
  1723. ExeName='sdldz80';
  1724. {$else}
  1725. ExeName='sdld';
  1726. {$endif}
  1727. begin
  1728. with Info do
  1729. begin
  1730. ExeCmd[1]:=ExeName+' -n $OPT -i $MAP $EXE -f $RES'
  1731. //-g '+platform_select+' $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP $MAP -L. -o $EXE -T $RES';
  1732. end;
  1733. end;
  1734. function TlinkerEmbedded_SdccSdld.MakeExecutable: boolean;
  1735. var
  1736. binstr,
  1737. cmdstr,
  1738. mapstr: TCmdStr;
  1739. success : boolean;
  1740. StaticStr,
  1741. // GCSectionsStr,
  1742. DynLinkStr,
  1743. StripStr,
  1744. FixedExeFileName: string;
  1745. begin
  1746. { for future use }
  1747. StaticStr:='';
  1748. StripStr:='';
  1749. mapstr:='';
  1750. DynLinkStr:='';
  1751. FixedExeFileName:=maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.ihx')));
  1752. (* GCSectionsStr:='--gc-sections';
  1753. //if not(cs_link_extern in current_settings.globalswitches) then
  1754. if not(cs_link_nolink in current_settings.globalswitches) then
  1755. Message1(exec_i_linking,current_module.exefilename);*)
  1756. if (cs_link_map in current_settings.globalswitches) then
  1757. mapstr:='-mw';
  1758. { Write used files and libraries }
  1759. WriteResponseFile();
  1760. { Call linker }
  1761. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  1762. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  1763. if not(cs_link_on_target in current_settings.globalswitches) then
  1764. begin
  1765. Replace(cmdstr,'$EXE',FixedExeFileName);
  1766. Replace(cmdstr,'$RES',(maybequoted(ScriptFixFileName(outputexedir+Info.ResName))));
  1767. Replace(cmdstr,'$STATIC',StaticStr);
  1768. Replace(cmdstr,'$STRIP',StripStr);
  1769. Replace(cmdstr,'$MAP',mapstr);
  1770. // Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  1771. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  1772. end
  1773. else
  1774. begin
  1775. Replace(cmdstr,'$EXE',FixedExeFileName);
  1776. Replace(cmdstr,'$RES',maybequoted(ScriptFixFileName(outputexedir+Info.ResName)));
  1777. Replace(cmdstr,'$STATIC',StaticStr);
  1778. Replace(cmdstr,'$STRIP',StripStr);
  1779. Replace(cmdstr,'$MAP',mapstr);
  1780. // Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  1781. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  1782. end;
  1783. success:=DoExec(FindUtil(utilsprefix+BinStr),cmdstr,true,false);
  1784. { Remove ReponseFile }
  1785. if success and not(cs_link_nolink in current_settings.globalswitches) then
  1786. DeleteFile(outputexedir+Info.ResName);
  1787. (* { Post process }
  1788. if success and not(cs_link_nolink in current_settings.globalswitches) then
  1789. success:=PostProcessExecutable(FixedExeFileName,false);
  1790. if success and (target_info.system in [system_arm_embedded,system_avr_embedded,system_mipsel_embedded,system_xtensa_embedded]) then
  1791. begin
  1792. success:=DoExec(FindUtil(utilsprefix+'objcopy'),'-O ihex '+
  1793. FixedExeFileName+' '+
  1794. maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.hex'))),true,false);
  1795. if success then
  1796. success:=DoExec(FindUtil(utilsprefix+'objcopy'),'-O binary '+
  1797. FixedExeFileName+' '+
  1798. maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.bin'))),true,false);
  1799. end;*)
  1800. MakeExecutable:=success; { otherwise a recursive call to link method }
  1801. end;
  1802. {*****************************************************************************
  1803. Initialize
  1804. *****************************************************************************}
  1805. initialization
  1806. {$ifdef arm}
  1807. RegisterLinker(ld_embedded,TLinkerEmbedded);
  1808. RegisterTarget(system_arm_embedded_info);
  1809. {$endif arm}
  1810. {$ifdef avr}
  1811. RegisterLinker(ld_embedded,TLinkerEmbedded);
  1812. RegisterTarget(system_avr_embedded_info);
  1813. {$endif avr}
  1814. {$ifdef i386}
  1815. RegisterLinker(ld_embedded,TLinkerEmbedded);
  1816. RegisterTarget(system_i386_embedded_info);
  1817. {$endif i386}
  1818. {$ifdef x86_64}
  1819. RegisterLinker(ld_embedded,TLinkerEmbedded);
  1820. RegisterTarget(system_x86_64_embedded_info);
  1821. {$endif x86_64}
  1822. {$ifdef i8086}
  1823. { no need to register linker ld_embedded, because i8086_embedded uses the
  1824. regular msdos linker. In case a flat binary, relocated for a specific
  1825. segment address is needed (e.g. for a BIOS or a real mode bootloader), it
  1826. can be produced post-compilation with exe2bin or a similar tool. }
  1827. RegisterTarget(system_i8086_embedded_info);
  1828. {$endif i8086}
  1829. {$ifdef mipsel}
  1830. RegisterLinker(ld_embedded,TLinkerEmbedded);
  1831. RegisterTarget(system_mipsel_embedded_info);
  1832. {$endif mipsel}
  1833. {$ifdef m68k}
  1834. RegisterLinker(ld_embedded,TLinkerEmbedded);
  1835. RegisterTarget(system_m68k_embedded_info);
  1836. {$endif m68k}
  1837. {$ifdef riscv32}
  1838. RegisterLinker(ld_embedded,TLinkerEmbedded);
  1839. RegisterTarget(system_riscv32_embedded_info);
  1840. {$endif riscv32}
  1841. {$ifdef riscv64}
  1842. RegisterLinker(ld_embedded,TLinkerEmbedded);
  1843. RegisterTarget(system_riscv64_embedded_info);
  1844. {$endif riscv64}
  1845. {$ifdef xtensa}
  1846. RegisterLinker(ld_embedded,TLinkerEmbedded);
  1847. RegisterTarget(system_xtensa_embedded_info);
  1848. {$endif xtensa}
  1849. {$ifdef z80}
  1850. RegisterLinker(ld_embedded,TlinkerEmbedded_SdccSdld);
  1851. RegisterTarget(system_z80_embedded_info);
  1852. {$endif z80}
  1853. end.