ogrel.pas 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  1. {
  2. Copyright (c) 2020 by Nikolay Nikolov
  3. Contains the ASCII relocatable object file format (*.rel) reader and writer
  4. This is the object format used on the Z80 platforms.
  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 ogrel;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. { common }
  23. cclasses,globtype,
  24. { target }
  25. systems,
  26. { assembler }
  27. cpuinfo,cpubase,aasmbase,assemble,link,
  28. { output }
  29. ogbase,
  30. owbase;
  31. type
  32. TRelRelocationFlag=(
  33. rrfByte, { bit 0 }
  34. rrfSymbol, { bit 1 }
  35. rrfPcRelative, { bit 2 }
  36. rrfTwoByteObjectFormatForByteData, { bit 3 }
  37. rrfUnsignedByteData, { bit 4 }
  38. rrfPage0Reference, { bit 5 }
  39. rrfPageNNNReference, { bit 6 }
  40. rrfMSBWith2ByteMode, { bit 7 }
  41. rrfThreeByteObjectFormatForByteData, { bit 8 }
  42. rrfRealMSBForThreeByteMode, { bit 9 }
  43. rrfReserved10, { bit 10 }
  44. rrfReserved11); { bit 11 }
  45. TRelRelocationFlags=set of TRelRelocationFlag;
  46. { TRelRelocation }
  47. TRelRelocation = class(TObjRelocation)
  48. private
  49. function GetSecOrSymIdx: longint;
  50. public
  51. RelFlags: TRelRelocationFlags;
  52. HiByte: Byte;
  53. constructor CreateSymbol(ADataOffset:TObjSectionOfs;s:TObjSymbol;Atyp:TObjRelocationType);
  54. constructor CreateSection(ADataOffset:TObjSectionOfs;aobjsec:TObjSection;Atyp:TObjRelocationType);
  55. function EncodeFlags: string;
  56. property SecOrSymIdx: longint read GetSecOrSymIdx;
  57. end;
  58. { TRelObjData }
  59. TRelObjData = class(TObjData)
  60. public
  61. function sectionname(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder):string;override;
  62. function sectiontype2align(atype:TAsmSectiontype):longint;override;
  63. procedure writeReloc(Data:TRelocDataInt;len:aword;p:TObjSymbol;Reloctype:TObjRelocationType);override;
  64. end;
  65. { TRelObjOutput }
  66. TRelObjOutput = class(tObjOutput)
  67. private
  68. procedure writeString(const S: ansistring);
  69. procedure writeLine(const S: ansistring);
  70. procedure WriteAreaContentAndRelocations(sec: TObjSection);
  71. protected
  72. function writeData(Data:TObjData):boolean;override;
  73. public
  74. constructor create(AWriter:TObjectWriter);override;
  75. end;
  76. { TRelAssembler }
  77. TRelAssembler = class(tinternalassembler)
  78. constructor create(info: pasminfo; smart:boolean);override;
  79. end;
  80. { TRelObjInput }
  81. TRelObjInput = class(TObjInput)
  82. public
  83. constructor create;override;
  84. function ReadObjData(AReader:TObjectreader;out Data:TObjData):boolean;override;
  85. class function CanReadObjData(AReader:TObjectreader):boolean;override;
  86. end;
  87. { TIntelHexExeOutput }
  88. TIntelHexExeOutput = class(TExeOutput)
  89. protected
  90. function writeData:boolean;override;
  91. procedure DoRelocationFixup(objsec:TObjSection);override;
  92. end;
  93. implementation
  94. uses
  95. SysUtils,
  96. cutils,verbose,globals,
  97. fmodule,aasmtai,aasmdata,
  98. ogmap,owar,
  99. version
  100. ;
  101. function tohex(q: qword): string;
  102. begin
  103. result:=HexStr(q,16);
  104. while (Length(result)>1) and (result[1]='0') do
  105. delete(result,1,1);
  106. end;
  107. {*****************************************************************************
  108. TRelRelocation
  109. *****************************************************************************}
  110. function TRelRelocation.GetSecOrSymIdx: longint;
  111. begin
  112. if assigned(symbol) then
  113. result:=symbol.symidx
  114. else if assigned(objsection) then
  115. result:=objsection.SecSymIdx
  116. else
  117. internalerror(2020050502);
  118. end;
  119. constructor TRelRelocation.CreateSymbol(ADataOffset: TObjSectionOfs; s: TObjSymbol; Atyp: TObjRelocationType);
  120. begin
  121. inherited;
  122. case Atyp of
  123. RELOC_ABSOLUTE_HI8:
  124. begin
  125. size:=1;
  126. RelFlags:=[rrfSymbol,rrfByte,rrfTwoByteObjectFormatForByteData,rrfMSBWith2ByteMode];
  127. end;
  128. RELOC_ABSOLUTE_LO8:
  129. begin
  130. size:=1;
  131. RelFlags:=[rrfSymbol,rrfByte,rrfTwoByteObjectFormatForByteData];
  132. end;
  133. RELOC_ABSOLUTE:
  134. begin
  135. size:=2;
  136. RelFlags:=[rrfSymbol];
  137. end;
  138. else
  139. internalerror(2020050601);
  140. end;
  141. end;
  142. constructor TRelRelocation.CreateSection(ADataOffset: TObjSectionOfs; aobjsec: TObjSection; Atyp: TObjRelocationType);
  143. begin
  144. inherited;
  145. case Atyp of
  146. RELOC_ABSOLUTE_HI8:
  147. begin
  148. size:=1;
  149. RelFlags:=[rrfByte,rrfTwoByteObjectFormatForByteData,rrfMSBWith2ByteMode];
  150. end;
  151. RELOC_ABSOLUTE_LO8:
  152. begin
  153. size:=1;
  154. RelFlags:=[rrfByte,rrfTwoByteObjectFormatForByteData];
  155. end;
  156. RELOC_ABSOLUTE:
  157. begin
  158. size:=2;
  159. RelFlags:=[];
  160. end;
  161. else
  162. internalerror(2020050601);
  163. end;
  164. end;
  165. function TRelRelocation.EncodeFlags: string;
  166. var
  167. FlagsWord: Word;
  168. begin
  169. FlagsWord:=0;
  170. if rrfByte in RelFlags then
  171. Inc(FlagsWord,1);
  172. if rrfSymbol in RelFlags then
  173. Inc(FlagsWord,2);
  174. if rrfPcRelative in RelFlags then
  175. Inc(FlagsWord,4);
  176. if rrfTwoByteObjectFormatForByteData in RelFlags then
  177. Inc(FlagsWord,8);
  178. if rrfUnsignedByteData in RelFlags then
  179. Inc(FlagsWord,16);
  180. if rrfPage0Reference in RelFlags then
  181. Inc(FlagsWord,32);
  182. if rrfPageNNNReference in RelFlags then
  183. Inc(FlagsWord,64);
  184. if rrfMSBWith2ByteMode in RelFlags then
  185. Inc(FlagsWord,128);
  186. if rrfThreeByteObjectFormatForByteData in RelFlags then
  187. Inc(FlagsWord,256);
  188. if rrfRealMSBForThreeByteMode in RelFlags then
  189. Inc(FlagsWord,512);
  190. if rrfReserved10 in RelFlags then
  191. Inc(FlagsWord,1024);
  192. if rrfReserved11 in RelFlags then
  193. Inc(FlagsWord,2048);
  194. if (FlagsWord<=255) and ((FlagsWord and $F0)<>$F0) then
  195. Result:=HexStr(FlagsWord,2)
  196. else
  197. Result:=HexStr($F0 or Byte(FlagsWord shr 8),2)+' '+HexStr(Byte(FlagsWord),2);
  198. end;
  199. {*****************************************************************************
  200. TRelObjData
  201. *****************************************************************************}
  202. function TRelObjData.sectionname(atype: TAsmSectiontype; const aname: string; aorder: TAsmSectionOrder): string;
  203. const
  204. secnames : array[TAsmSectiontype] of string[length('__DATA, __datacoal_nt,coalesced')] = ('','',
  205. '_CODE',
  206. '_DATA',
  207. '_DATA',
  208. '.rodata',
  209. '.bss',
  210. '.threadvar',
  211. '.pdata',
  212. '', { stubs }
  213. '__DATA,__nl_symbol_ptr',
  214. '__DATA,__la_symbol_ptr',
  215. '__DATA,__mod_init_func',
  216. '__DATA,__mod_term_func',
  217. '.stab',
  218. '.stabstr',
  219. '.idata$2','.idata$4','.idata$5','.idata$6','.idata$7','.edata',
  220. '.eh_frame',
  221. '.debug_frame','.debug_info','.debug_line','.debug_abbrev','.debug_aranges','.debug_ranges',
  222. '.fpc',
  223. '.toc',
  224. '.init',
  225. '.fini',
  226. '.objc_class',
  227. '.objc_meta_class',
  228. '.objc_cat_cls_meth',
  229. '.objc_cat_inst_meth',
  230. '.objc_protocol',
  231. '.objc_string_object',
  232. '.objc_cls_meth',
  233. '.objc_inst_meth',
  234. '.objc_cls_refs',
  235. '.objc_message_refs',
  236. '.objc_symbols',
  237. '.objc_category',
  238. '.objc_class_vars',
  239. '.objc_instance_vars',
  240. '.objc_module_info',
  241. '.objc_class_names',
  242. '.objc_meth_var_types',
  243. '.objc_meth_var_names',
  244. '.objc_selector_strs',
  245. '.objc_protocol_ext',
  246. '.objc_class_ext',
  247. '.objc_property',
  248. '.objc_image_info',
  249. '.objc_cstring_object',
  250. '.objc_sel_fixup',
  251. '__DATA,__objc_data',
  252. '__DATA,__objc_const',
  253. '.objc_superrefs',
  254. '__DATA, __datacoal_nt,coalesced',
  255. '.objc_classlist',
  256. '.objc_nlclasslist',
  257. '.objc_catlist',
  258. '.obcj_nlcatlist',
  259. '.objc_protolist',
  260. '.stack',
  261. '.heap',
  262. '.gcc_except_table',
  263. '.ARM.attributes'
  264. );
  265. begin
  266. result:=secnames[atype];
  267. end;
  268. function TRelObjData.sectiontype2align(atype:TAsmSectiontype):longint;
  269. begin
  270. result:=1;
  271. end;
  272. procedure TRelObjData.writeReloc(Data: TRelocDataInt; len: aword; p: TObjSymbol; Reloctype: TObjRelocationType);
  273. var
  274. bytes: array [0..1] of Byte;
  275. symaddr: QWord;
  276. objreloc: TRelRelocation;
  277. begin
  278. if CurrObjSec=nil then
  279. internalerror(200403072);
  280. objreloc:=nil;
  281. if assigned(p) then
  282. begin
  283. { real address of the symbol }
  284. symaddr:=p.address;
  285. if p.bind=AB_EXTERNAL then
  286. begin
  287. objreloc:=TRelRelocation.CreateSymbol(CurrObjSec.Size,p,Reloctype);
  288. if Reloctype in [RELOC_ABSOLUTE_HI8,RELOC_ABSOLUTE_LO8] then
  289. objreloc.HiByte:=Byte(Data shr 8);
  290. CurrObjSec.ObjRelocations.Add(objreloc);
  291. end
  292. { relative relocations within the same section can be calculated directly,
  293. without the need to emit a relocation entry }
  294. else if (p.objsection=CurrObjSec) and
  295. (p.bind<>AB_COMMON) and
  296. (Reloctype=RELOC_RELATIVE) then
  297. begin
  298. data:=data+symaddr-len-CurrObjSec.Size;
  299. end
  300. else
  301. begin
  302. objreloc:=TRelRelocation.CreateSection(CurrObjSec.Size,p.objsection,Reloctype);
  303. inc(data,symaddr);
  304. if Reloctype in [RELOC_ABSOLUTE_HI8,RELOC_ABSOLUTE_LO8] then
  305. objreloc.HiByte:=Byte(Data shr 8);
  306. CurrObjSec.ObjRelocations.Add(objreloc);
  307. end;
  308. end;
  309. case len of
  310. 2:
  311. begin
  312. bytes[0]:=Byte(Data);
  313. bytes[1]:=Byte(Data shr 8);
  314. writebytes(bytes,2);
  315. end;
  316. 1:
  317. begin
  318. bytes[0]:=Byte(Data);
  319. writebytes(bytes,1);
  320. end;
  321. else
  322. internalerror(2020050423);
  323. end;
  324. end;
  325. {*****************************************************************************
  326. TRelObjOutput
  327. *****************************************************************************}
  328. procedure TRelObjOutput.writeString(const S: ansistring);
  329. begin
  330. FWriter.write(S[1],Length(S));
  331. end;
  332. procedure TRelObjOutput.writeLine(const S: ansistring);
  333. begin
  334. writeString(S+#10)
  335. end;
  336. procedure TRelObjOutput.WriteAreaContentAndRelocations(sec: TObjSection);
  337. const
  338. MaxChunkSize={14}7;
  339. var
  340. ChunkStart,ChunkLen, i: LongWord;
  341. ChunkFixupStart,ChunkFixupEnd, j, st_ofs: Integer;
  342. st,sr: ansistring;
  343. buf: array [0..MaxChunkSize-1] of Byte;
  344. reloc: TRelRelocation;
  345. begin
  346. if (oso_data in sec.SecOptions) and (sec.Data=nil) then
  347. internalerror(200403073);
  348. if assigned(sec.data) then
  349. sec.data.seek(0);
  350. ChunkFixupStart:=0;
  351. ChunkFixupEnd:=-1;
  352. ChunkStart:=0;
  353. ChunkLen:=Min(MaxChunkSize, sec.size-ChunkStart);
  354. while ChunkLen>0 do
  355. begin
  356. { find last fixup in the chunk }
  357. while (ChunkFixupEnd<(sec.ObjRelocations.Count-1)) and
  358. (TRelRelocation(sec.ObjRelocations[ChunkFixupEnd+1]).DataOffset<(ChunkStart+ChunkLen)) do
  359. inc(ChunkFixupEnd);
  360. { check if last chunk is crossing the chunk boundary, and trim ChunkLen if necessary }
  361. if (ChunkFixupEnd>=ChunkFixupStart) and
  362. ((TRelRelocation(sec.ObjRelocations[ChunkFixupEnd]).DataOffset+
  363. TRelRelocation(sec.ObjRelocations[ChunkFixupEnd]).size)>(ChunkStart+ChunkLen)) then
  364. begin
  365. ChunkLen:=TRelRelocation(sec.ObjRelocations[ChunkFixupEnd]).DataOffset-ChunkStart;
  366. Dec(ChunkFixupEnd);
  367. end;
  368. if ChunkLen>SizeOf(buf) then
  369. internalerror(2020050501);
  370. st:='T '+HexStr(Byte(ChunkStart),2)+' '+HexStr(Byte(ChunkStart shr 8),2);
  371. sr:='R 00 00 '+HexStr(Byte(sec.SecSymIdx),2)+' '+HexStr(Byte(sec.SecSymIdx shr 8),2);
  372. if assigned(sec.Data) then
  373. sec.Data.read(buf,ChunkLen)
  374. else
  375. FillChar(buf,ChunkLen,0);
  376. st_ofs:=1;
  377. { relocations present in the current chunk? }
  378. if ChunkFixupEnd>=ChunkFixupStart then
  379. begin
  380. j:=ChunkFixupStart;
  381. reloc:=TRelRelocation(sec.ObjRelocations[j]);
  382. end
  383. else
  384. begin
  385. j:=-1;
  386. reloc:=nil;
  387. end;
  388. for i:=0 to ChunkLen-1 do
  389. begin
  390. st:=st+' '+HexStr(buf[i],2);
  391. Inc(st_ofs);
  392. if assigned(reloc) then
  393. begin
  394. { advance to the current relocation }
  395. while (reloc.DataOffset<(ChunkStart+i)) and (j<ChunkFixupEnd) do
  396. begin
  397. Inc(j);
  398. reloc:=TRelRelocation(sec.ObjRelocations[j]);
  399. end;
  400. { is there a relocation at the current position? }
  401. if reloc.DataOffset=(ChunkStart+i) then
  402. begin
  403. sr:=sr+' '+reloc.EncodeFlags+' '+HexStr(st_ofs,2)+' '+HexStr(Byte(reloc.SecOrSymIdx),2)+' '+HexStr(Byte(reloc.SecOrSymIdx shr 8),2);
  404. if reloc.typ in [RELOC_ABSOLUTE_HI8,RELOC_ABSOLUTE_LO8] then
  405. begin
  406. st:=st+' '+HexStr(reloc.HiByte,2);
  407. Inc(st_ofs);
  408. end;
  409. end;
  410. end;
  411. end;
  412. writeLine(st);
  413. writeLine(sr);
  414. { prepare next chunk }
  415. Inc(ChunkStart, ChunkLen);
  416. ChunkLen:=Min(MaxChunkSize, sec.size-ChunkStart);
  417. ChunkFixupStart:=ChunkFixupEnd+1;
  418. end;
  419. end;
  420. function TRelObjOutput.writeData(Data: TObjData): boolean;
  421. var
  422. global_symbols_count: Integer = 0;
  423. secidx, idx, i, j: Integer;
  424. objsym: TObjSymbol;
  425. objsec: TObjSection;
  426. begin
  427. global_symbols_count:=0;
  428. for i:=0 to Data.ObjSymbolList.Count-1 do
  429. begin
  430. objsym:=TObjSymbol(Data.ObjSymbolList[i]);
  431. if objsym.bind in [AB_EXTERNAL,AB_GLOBAL] then
  432. Inc(global_symbols_count);
  433. end;
  434. writeLine('XL2');
  435. writeLine('H '+tohex(data.ObjSectionList.Count)+' areas '+tohex(global_symbols_count)+' global symbols');
  436. idx:=0;
  437. for i:=0 to Data.ObjSymbolList.Count-1 do
  438. begin
  439. objsym:=TObjSymbol(Data.ObjSymbolList[i]);
  440. if objsym.bind=AB_EXTERNAL then
  441. begin
  442. writeLine('S '+ApplyAsmSymbolRestrictions(objsym.Name)+' Ref0000');
  443. objsym.symidx:=idx;
  444. Inc(idx);
  445. end;
  446. end;
  447. secidx:=0;
  448. for i:=0 to Data.ObjSectionList.Count-1 do
  449. begin
  450. objsec:=TObjSection(Data.ObjSectionList[i]);
  451. writeLine('A '+objsec.Name+' size '+tohex(objsec.Size)+' flags 0 addr 0');
  452. objsec.SecSymIdx:=secidx;
  453. Inc(secidx);
  454. for j:=0 to Data.ObjSymbolList.Count-1 do
  455. begin
  456. objsym:=TObjSymbol(Data.ObjSymbolList[j]);
  457. if (objsym.bind=AB_GLOBAL) and (objsym.objsection=objsec) then
  458. begin
  459. writeLine('S '+ApplyAsmSymbolRestrictions(objsym.Name)+' Def'+HexStr(objsym.offset,4));
  460. objsym.symidx:=idx;
  461. Inc(idx);
  462. end;
  463. end;
  464. end;
  465. for i:=0 to Data.ObjSectionList.Count-1 do
  466. begin
  467. objsec:=TObjSection(Data.ObjSectionList[i]);
  468. WriteAreaContentAndRelocations(objsec);
  469. end;
  470. result:=true;
  471. end;
  472. constructor TRelObjOutput.create(AWriter: TObjectWriter);
  473. begin
  474. inherited;
  475. cobjdata:=TRelObjData;
  476. end;
  477. {*****************************************************************************
  478. TRelAssembler
  479. *****************************************************************************}
  480. constructor TRelAssembler.create(info: pasminfo; smart: boolean);
  481. begin
  482. inherited;
  483. CObjOutput:=TRelObjOutput;
  484. CInternalAr:=tarobjectwriter;
  485. end;
  486. {*****************************************************************************
  487. TRelObjInput
  488. *****************************************************************************}
  489. constructor TRelObjInput.create;
  490. begin
  491. inherited create;
  492. cobjdata:=TRelObjData;
  493. end;
  494. function TRelObjInput.ReadObjData(AReader: TObjectreader; out Data: TObjData): boolean;
  495. begin
  496. result:=false;
  497. end;
  498. class function TRelObjInput.CanReadObjData(AReader: TObjectreader): boolean;
  499. const
  500. MaxBufSize=512;
  501. var
  502. Buf: array [0..MaxBufSize-1] of Char;
  503. BufSize: Integer = 0;
  504. BufPos: Integer = 0;
  505. function FillBuf: boolean;
  506. begin
  507. BufPos:=0;
  508. BufSize:=min(AReader.size-AReader.Pos,MaxBufSize);
  509. if BufSize>0 then
  510. result:=AReader.read(Buf,BufSize)
  511. else
  512. result:=true;
  513. end;
  514. function AtEndOfBuf: boolean;
  515. begin
  516. result:=BufPos=BufSize;
  517. end;
  518. function AtEoF: boolean;
  519. begin
  520. result:=AtEndOfBuf and (AReader.Pos=AReader.size);
  521. end;
  522. function ReadChar(out c: char): boolean;
  523. begin
  524. c:=#0;
  525. if AtEndOfBuf then
  526. begin
  527. result:=FillBuf;
  528. if not result then
  529. exit;
  530. end;
  531. if not AtEndOfBuf then
  532. begin
  533. c:=Buf[BufPos];
  534. Inc(BufPos);
  535. result:=true;
  536. end
  537. else
  538. result:=false;
  539. end;
  540. function PeekChar(out c: char): boolean;
  541. begin
  542. c:=#0;
  543. if AtEndOfBuf then
  544. begin
  545. result:=FillBuf;
  546. if not result then
  547. exit;
  548. end;
  549. if not AtEndOfBuf then
  550. begin
  551. c:=Buf[BufPos];
  552. result:=true;
  553. end
  554. else
  555. result:=false;
  556. end;
  557. function ReadLine(out s: string): boolean;
  558. var
  559. c: Char;
  560. begin
  561. s:='';
  562. if AtEoF then
  563. begin
  564. result:=false;
  565. exit;
  566. end;
  567. repeat
  568. if not AtEoF then
  569. begin
  570. if not ReadChar(c) then
  571. begin
  572. result:=false;
  573. exit;
  574. end;
  575. if not (c in [#13,#10]) then
  576. s:=s+c;
  577. end;
  578. until (c in [#13,#10]) or AtEoF;
  579. if (c=#13) and not AtEoF then
  580. begin
  581. if not PeekChar(c) then
  582. begin
  583. result:=false;
  584. exit;
  585. end;
  586. if c=#10 then
  587. begin
  588. if not ReadChar(c) then
  589. begin
  590. result:=false;
  591. exit;
  592. end;
  593. end;
  594. end;
  595. result:=true;
  596. end;
  597. var
  598. s: string;
  599. begin
  600. result:=false;
  601. while not AtEoF do
  602. begin
  603. if not ReadLine(s) then
  604. exit;
  605. s:=Trim(s);
  606. if s<>'' then
  607. begin
  608. result:=s='XL2';
  609. exit;
  610. end;
  611. end;
  612. end;
  613. {*****************************************************************************
  614. TIntelHexExeOutput
  615. *****************************************************************************}
  616. function TIntelHexExeOutput.writeData: boolean;
  617. begin
  618. result:=false;
  619. end;
  620. procedure TIntelHexExeOutput.DoRelocationFixup(objsec: TObjSection);
  621. begin
  622. end;
  623. {*****************************************************************************
  624. Initialize
  625. *****************************************************************************}
  626. const
  627. as_z80_rel_info : tasminfo =
  628. (
  629. id : as_z80_rel;
  630. idtxt : 'REL';
  631. asmbin : '';
  632. asmcmd : '';
  633. supported_targets : [system_z80_embedded,system_z80_zxspectrum];
  634. flags : [af_outputbinary,af_smartlink_sections];
  635. labelprefix : '..@';
  636. labelmaxlen : 79;
  637. comment : '; ';
  638. dollarsign: '$';
  639. );
  640. initialization
  641. RegisterAssembler(as_z80_rel_info,TRelAssembler);
  642. end.