ag386int.pas 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl
  4. This unit implements an asmoutput class for Intel syntax with Intel i386+
  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 ag386int;
  19. {$i defines.inc}
  20. interface
  21. uses aasm,assemble;
  22. type
  23. pi386intasmlist=^ti386intasmlist;
  24. ti386intasmlist = object(tasmlist)
  25. procedure WriteTree(p:TAAsmoutput);virtual;
  26. procedure WriteAsmList;virtual;
  27. procedure WriteExternals;
  28. end;
  29. implementation
  30. uses
  31. {$ifdef delphi}
  32. sysutils,
  33. {$endif}
  34. cutils,globtype,globals,systems,cobjects,
  35. verbose,cpubase,cpuasm,finput,fmodule
  36. ;
  37. const
  38. line_length = 70;
  39. function single2str(d : single) : string;
  40. var
  41. hs : string;
  42. p : byte;
  43. begin
  44. str(d,hs);
  45. { nasm expects a lowercase e }
  46. p:=pos('E',hs);
  47. if p>0 then
  48. hs[p]:='e';
  49. p:=pos('+',hs);
  50. if p>0 then
  51. delete(hs,p,1);
  52. single2str:=lower(hs);
  53. end;
  54. function double2str(d : double) : string;
  55. var
  56. hs : string;
  57. p : byte;
  58. begin
  59. str(d,hs);
  60. { nasm expects a lowercase e }
  61. p:=pos('E',hs);
  62. if p>0 then
  63. hs[p]:='e';
  64. p:=pos('+',hs);
  65. if p>0 then
  66. delete(hs,p,1);
  67. double2str:=lower(hs);
  68. end;
  69. function extended2str(e : extended) : string;
  70. var
  71. hs : string;
  72. p : byte;
  73. begin
  74. str(e,hs);
  75. { nasm expects a lowercase e }
  76. p:=pos('E',hs);
  77. if p>0 then
  78. hs[p]:='e';
  79. p:=pos('+',hs);
  80. if p>0 then
  81. delete(hs,p,1);
  82. extended2str:=lower(hs);
  83. end;
  84. function comp2str(d : bestreal) : string;
  85. type
  86. pdouble = ^double;
  87. var
  88. c : comp;
  89. dd : pdouble;
  90. begin
  91. {$ifdef FPC}
  92. c:=comp(d);
  93. {$else}
  94. c:=d;
  95. {$endif}
  96. dd:=pdouble(@c); { this makes a bitwise copy of c into a double }
  97. comp2str:=double2str(dd^);
  98. end;
  99. function getreferencestring(var ref : treference) : string;
  100. var
  101. s : string;
  102. first : boolean;
  103. begin
  104. if ref.is_immediate then
  105. begin
  106. getreferencestring:=tostr(ref.offset);
  107. exit;
  108. end
  109. else
  110. with ref do
  111. begin
  112. first:=true;
  113. inc(offset,offsetfixup);
  114. offsetfixup:=0;
  115. if ref.segment<>R_NO then
  116. s:=int_reg2str[segment]+':['
  117. else
  118. s:='[';
  119. if assigned(symbol) then
  120. begin
  121. if (aktoutputformat = as_i386_tasm) then
  122. s:=s+'dword ptr ';
  123. s:=s+symbol^.name;
  124. first:=false;
  125. end;
  126. if (base<>R_NO) then
  127. begin
  128. if not(first) then
  129. s:=s+'+'
  130. else
  131. first:=false;
  132. s:=s+int_reg2str[base];
  133. end;
  134. if (index<>R_NO) then
  135. begin
  136. if not(first) then
  137. s:=s+'+'
  138. else
  139. first:=false;
  140. s:=s+int_reg2str[index];
  141. if scalefactor<>0 then
  142. s:=s+'*'+tostr(scalefactor);
  143. end;
  144. if offset<0 then
  145. s:=s+tostr(offset)
  146. else if (offset>0) then
  147. s:=s+'+'+tostr(offset);
  148. s:=s+']';
  149. end;
  150. getreferencestring:=s;
  151. end;
  152. function getopstr(const o:toper;s : topsize; opcode: tasmop;dest : boolean) : string;
  153. var
  154. hs : string;
  155. begin
  156. case o.typ of
  157. top_reg :
  158. getopstr:=int_reg2str[o.reg];
  159. top_const :
  160. getopstr:=tostr(o.val);
  161. top_symbol :
  162. begin
  163. if assigned(o.sym) then
  164. hs:='offset '+o.sym^.name
  165. else
  166. hs:='offset ';
  167. if o.symofs>0 then
  168. hs:=hs+'+'+tostr(o.symofs)
  169. else
  170. if o.symofs<0 then
  171. hs:=hs+tostr(o.symofs)
  172. else
  173. if not(assigned(o.sym)) then
  174. hs:=hs+'0';
  175. getopstr:=hs;
  176. end;
  177. top_ref :
  178. begin
  179. hs:=getreferencestring(o.ref^);
  180. if ((opcode <> A_LGS) and (opcode <> A_LSS) and
  181. (opcode <> A_LFS) and (opcode <> A_LDS) and
  182. (opcode <> A_LES)) then
  183. Begin
  184. case s of
  185. S_B : hs:='byte ptr '+hs;
  186. S_W : hs:='word ptr '+hs;
  187. S_L : hs:='dword ptr '+hs;
  188. S_IS : hs:='word ptr '+hs;
  189. S_IL : hs:='dword ptr '+hs;
  190. S_IQ : hs:='qword ptr '+hs;
  191. S_FS : hs:='dword ptr '+hs;
  192. S_FL : hs:='qword ptr '+hs;
  193. S_FX : hs:='tbyte ptr '+hs;
  194. S_BW : if dest then
  195. hs:='word ptr '+hs
  196. else
  197. hs:='byte ptr '+hs;
  198. S_BL : if dest then
  199. hs:='dword ptr '+hs
  200. else
  201. hs:='byte ptr '+hs;
  202. S_WL : if dest then
  203. hs:='dword ptr '+hs
  204. else
  205. hs:='word ptr '+hs;
  206. end;
  207. end;
  208. getopstr:=hs;
  209. end;
  210. else
  211. internalerror(10001);
  212. end;
  213. end;
  214. function getopstr_jmp(const o:toper;s : topsize) : string;
  215. var
  216. hs : string;
  217. begin
  218. case o.typ of
  219. top_reg :
  220. getopstr_jmp:=int_reg2str[o.reg];
  221. top_const :
  222. getopstr_jmp:=tostr(o.val);
  223. top_symbol :
  224. begin
  225. hs:=o.sym^.name;
  226. if o.symofs>0 then
  227. hs:=hs+'+'+tostr(o.symofs)
  228. else
  229. if o.symofs<0 then
  230. hs:=hs+tostr(o.symofs);
  231. getopstr_jmp:=hs;
  232. end;
  233. top_ref :
  234. { what about lcall or ljmp ??? }
  235. begin
  236. if (aktoutputformat = as_i386_tasm) then
  237. hs:=''
  238. else
  239. begin
  240. if s=S_FAR then
  241. hs:='far ptr '
  242. else
  243. hs:='near ptr ';
  244. end;
  245. getopstr_jmp:=hs+getreferencestring(o.ref^);
  246. end;
  247. else
  248. internalerror(10001);
  249. end;
  250. end;
  251. function fixline(s:string):string;
  252. {
  253. return s with all leading and ending spaces and tabs removed
  254. }
  255. var
  256. i,j,k : longint;
  257. begin
  258. i:=length(s);
  259. while (i>0) and (s[i] in [#9,' ']) do
  260. dec(i);
  261. j:=1;
  262. while (j<i) and (s[j] in [#9,' ']) do
  263. inc(j);
  264. for k:=j to i do
  265. if s[k] in [#0..#31,#127..#255] then
  266. s[k]:='.';
  267. fixline:=Copy(s,j,i-j+1);
  268. end;
  269. {****************************************************************************
  270. TI386INTASMLIST
  271. ****************************************************************************}
  272. var
  273. LastSec : tsection;
  274. lastfileinfo : tfileposinfo;
  275. infile,
  276. lastinfile : tinputfile;
  277. const
  278. ait_const2str:array[ait_const_32bit..ait_const_8bit] of string[8]=
  279. (#9'DD'#9,#9'DW'#9,#9'DB'#9);
  280. Function PadTabs(const p:string;addch:char):string;
  281. var
  282. s : string;
  283. i : longint;
  284. begin
  285. i:=length(p);
  286. if addch<>#0 then
  287. begin
  288. inc(i);
  289. s:=p+addch;
  290. end
  291. else
  292. s:=p;
  293. if i<8 then
  294. PadTabs:=s+#9#9
  295. else
  296. PadTabs:=s+#9;
  297. end;
  298. procedure ti386intasmlist.WriteTree(p:TAAsmoutput);
  299. const
  300. allocstr : array[boolean] of string[10]=(' released',' allocated');
  301. var
  302. s,
  303. prefix,
  304. suffix : string;
  305. hp : tai;
  306. counter,
  307. lines,
  308. InlineLevel : longint;
  309. i,j,l : longint;
  310. consttyp : tait;
  311. found,
  312. do_line,
  313. quoted : boolean;
  314. sep : char;
  315. begin
  316. if not assigned(p) then
  317. exit;
  318. { lineinfo is only needed for codesegment (PFV) }
  319. do_line:=((cs_asm_source in aktglobalswitches) or
  320. (cs_lineinfo in aktmoduleswitches))
  321. and (p=codesegment);
  322. InlineLevel:=0;
  323. hp:=tai(p.first);
  324. while assigned(hp) do
  325. begin
  326. if do_line then
  327. begin
  328. { load infile }
  329. if lastfileinfo.fileindex<>hp.fileinfo.fileindex then
  330. begin
  331. infile:=current_module.sourcefiles.get_file(hp.fileinfo.fileindex);
  332. if assigned(infile) then
  333. begin
  334. { open only if needed !! }
  335. if (cs_asm_source in aktglobalswitches) then
  336. infile.open;
  337. end;
  338. { avoid unnecessary reopens of the same file !! }
  339. lastfileinfo.fileindex:=hp.fileinfo.fileindex;
  340. { be sure to change line !! }
  341. lastfileinfo.line:=-1;
  342. end;
  343. { write source }
  344. if (cs_asm_source in aktglobalswitches) and
  345. assigned(infile) then
  346. begin
  347. if (infile<>lastinfile) then
  348. begin
  349. AsmWriteLn(target_asm.comment+'['+infile.name^+']');
  350. if assigned(lastinfile) then
  351. lastinfile.close;
  352. end;
  353. if (hp.fileinfo.line<>lastfileinfo.line) and
  354. ((hp.fileinfo.line<infile.maxlinebuf) or (InlineLevel>0)) then
  355. begin
  356. if (hp.fileinfo.line<>0) and
  357. ((infile.linebuf^[hp.fileinfo.line]>=0) or (InlineLevel>0)) then
  358. AsmWriteLn(target_asm.comment+'['+tostr(hp.fileinfo.line)+'] '+
  359. fixline(infile.GetLineStr(hp.fileinfo.line)));
  360. { set it to a negative value !
  361. to make that is has been read already !! PM }
  362. if (infile.linebuf^[hp.fileinfo.line]>=0) then
  363. infile.linebuf^[hp.fileinfo.line]:=-infile.linebuf^[hp.fileinfo.line]-1;
  364. end;
  365. end;
  366. lastfileinfo:=hp.fileinfo;
  367. lastinfile:=infile;
  368. end;
  369. case hp.typ of
  370. ait_comment : Begin
  371. AsmWrite(target_asm.comment);
  372. AsmWritePChar(tai_asm_comment(hp).str);
  373. AsmLn;
  374. End;
  375. ait_regalloc,
  376. ait_tempalloc : ;
  377. ait_section : begin
  378. if LastSec<>sec_none then
  379. AsmWriteLn('_'+target_asm.secnames[LastSec]+#9#9'ENDS');
  380. if tai_section(hp).sec<>sec_none then
  381. begin
  382. AsmLn;
  383. AsmWriteLn('_'+target_asm.secnames[tai_section(hp).sec]+#9#9+
  384. 'SEGMENT'#9'PARA PUBLIC USE32 '''+
  385. target_asm.secnames[tai_section(hp).sec]+'''');
  386. end;
  387. LastSec:=tai_section(hp).sec;
  388. end;
  389. ait_align : begin
  390. { CAUSES PROBLEMS WITH THE SEGMENT DEFINITION }
  391. { SEGMENT DEFINITION SHOULD MATCH TYPE OF ALIGN }
  392. { HERE UNDER TASM! }
  393. AsmWriteLn(#9'ALIGN '+tostr(tai_align(hp).aligntype));
  394. end;
  395. ait_datablock : begin
  396. if tai_datablock(hp).is_global then
  397. AsmWriteLn(#9'PUBLIC'#9+tai_datablock(hp).sym^.name);
  398. AsmWriteLn(PadTabs(tai_datablock(hp).sym^.name,#0)+'DB'#9+tostr(tai_datablock(hp).size)+' DUP(?)');
  399. end;
  400. ait_const_32bit,
  401. ait_const_8bit,
  402. ait_const_16bit : begin
  403. AsmWrite(ait_const2str[hp.typ]+tostr(tai_const(hp).value));
  404. consttyp:=hp.typ;
  405. l:=0;
  406. repeat
  407. found:=(not (tai(hp.next)=nil)) and (tai(hp.next).typ=consttyp);
  408. if found then
  409. begin
  410. hp:=tai(hp.next);
  411. s:=','+tostr(tai_const(hp).value);
  412. AsmWrite(s);
  413. inc(l,length(s));
  414. end;
  415. until (not found) or (l>line_length);
  416. AsmLn;
  417. end;
  418. ait_const_symbol : begin
  419. AsmWriteLn(#9#9'DD'#9'offset '+tai_const_symbol(hp).sym^.name);
  420. if tai_const_symbol(hp).offset>0 then
  421. AsmWrite('+'+tostr(tai_const_symbol(hp).offset))
  422. else if tai_const_symbol(hp).offset<0 then
  423. AsmWrite(tostr(tai_const_symbol(hp).offset));
  424. AsmLn;
  425. end;
  426. ait_const_rva : begin
  427. AsmWriteLn(#9#9'RVA'#9+tai_const_symbol(hp).sym^.name);
  428. end;
  429. ait_real_32bit : AsmWriteLn(#9#9'DD'#9+single2str(tai_real_32bit(hp).value));
  430. ait_real_64bit : AsmWriteLn(#9#9'DQ'#9+double2str(tai_real_64bit(hp).value));
  431. ait_real_80bit : AsmWriteLn(#9#9'DT'#9+extended2str(tai_real_80bit(hp).value));
  432. ait_comp_64bit : AsmWriteLn(#9#9'DQ'#9+comp2str(tai_real_80bit(hp).value));
  433. ait_string : begin
  434. counter := 0;
  435. lines := tai_string(hp).len div line_length;
  436. { separate lines in different parts }
  437. if tai_string(hp).len > 0 then
  438. Begin
  439. for j := 0 to lines-1 do
  440. begin
  441. AsmWrite(#9#9'DB'#9);
  442. quoted:=false;
  443. for i:=counter to counter+line_length do
  444. begin
  445. { it is an ascii character. }
  446. if (ord(tai_string(hp).str[i])>31) and
  447. (ord(tai_string(hp).str[i])<128) and
  448. (tai_string(hp).str[i]<>'"') then
  449. begin
  450. if not(quoted) then
  451. begin
  452. if i>counter then
  453. AsmWrite(',');
  454. AsmWrite('"');
  455. end;
  456. AsmWrite(tai_string(hp).str[i]);
  457. quoted:=true;
  458. end { if > 31 and < 128 and ord('"') }
  459. else
  460. begin
  461. if quoted then
  462. AsmWrite('"');
  463. if i>counter then
  464. AsmWrite(',');
  465. quoted:=false;
  466. AsmWrite(tostr(ord(tai_string(hp).str[i])));
  467. end;
  468. end; { end for i:=0 to... }
  469. if quoted then AsmWrite('"');
  470. AsmWrite(target_os.newline);
  471. counter := counter+line_length;
  472. end; { end for j:=0 ... }
  473. { do last line of lines }
  474. AsmWrite(#9#9'DB'#9);
  475. quoted:=false;
  476. for i:=counter to tai_string(hp).len-1 do
  477. begin
  478. { it is an ascii character. }
  479. if (ord(tai_string(hp).str[i])>31) and
  480. (ord(tai_string(hp).str[i])<128) and
  481. (tai_string(hp).str[i]<>'"') then
  482. begin
  483. if not(quoted) then
  484. begin
  485. if i>counter then
  486. AsmWrite(',');
  487. AsmWrite('"');
  488. end;
  489. AsmWrite(tai_string(hp).str[i]);
  490. quoted:=true;
  491. end { if > 31 and < 128 and " }
  492. else
  493. begin
  494. if quoted then
  495. AsmWrite('"');
  496. if i>counter then
  497. AsmWrite(',');
  498. quoted:=false;
  499. AsmWrite(tostr(ord(tai_string(hp).str[i])));
  500. end;
  501. end; { end for i:=0 to... }
  502. if quoted then
  503. AsmWrite('"');
  504. end;
  505. AsmLn;
  506. end;
  507. ait_label : begin
  508. if tai_label(hp).l^.is_used then
  509. begin
  510. AsmWrite(tai_label(hp).l^.name);
  511. if assigned(hp.next) and not(tai(hp.next).typ in
  512. [ait_const_32bit,ait_const_16bit,ait_const_8bit,
  513. ait_const_symbol,ait_const_rva,
  514. ait_real_32bit,ait_real_64bit,ait_real_80bit,ait_comp_64bit,ait_string]) then
  515. AsmWriteLn(':');
  516. end;
  517. end;
  518. ait_direct : begin
  519. AsmWritePChar(tai_direct(hp).str);
  520. AsmLn;
  521. end;
  522. ait_symbol : begin
  523. if tai_symbol(hp).is_global then
  524. AsmWriteLn(#9'PUBLIC'#9+tai_symbol(hp).sym^.name);
  525. AsmWrite(tai_symbol(hp).sym^.name);
  526. if assigned(hp.next) and not(tai(hp.next).typ in
  527. [ait_const_32bit,ait_const_16bit,ait_const_8bit,
  528. ait_const_symbol,ait_const_rva,
  529. ait_real_32bit,ait_real_64bit,ait_real_80bit,ait_comp_64bit,ait_string]) then
  530. AsmWriteLn(':')
  531. end;
  532. ait_symbol_end : begin
  533. end;
  534. ait_instruction : begin
  535. { Must be done with args in ATT order }
  536. taicpu(hp).SetOperandOrder(op_att);
  537. taicpu(hp).CheckNonCommutativeOpcodes;
  538. { We need intel order, no At&t }
  539. taicpu(hp).SetOperandOrder(op_intel);
  540. { Reset }
  541. suffix:='';
  542. prefix:= '';
  543. s:='';
  544. { We need to explicitely set
  545. word prefix to get selectors
  546. to be pushed in 2 bytes PM }
  547. if (taicpu(hp).opsize=S_W) and
  548. ((taicpu(hp).opcode=A_PUSH) or
  549. (taicpu(hp).opcode=A_POP)) and
  550. (taicpu(hp).oper[0].typ=top_reg) and
  551. ((taicpu(hp).oper[0].reg>=firstsreg) and
  552. (taicpu(hp).oper[0].reg<=lastsreg)) then
  553. AsmWriteln(#9#9'DB'#9'066h');
  554. { added prefix instructions, must be on same line as opcode }
  555. if (taicpu(hp).ops = 0) and
  556. ((taicpu(hp).opcode = A_REP) or
  557. (taicpu(hp).opcode = A_LOCK) or
  558. (taicpu(hp).opcode = A_REPE) or
  559. (taicpu(hp).opcode = A_REPNZ) or
  560. (taicpu(hp).opcode = A_REPZ) or
  561. (taicpu(hp).opcode = A_REPNE)) then
  562. Begin
  563. prefix:=int_op2str[taicpu(hp).opcode]+#9;
  564. hp:=tai(hp.next);
  565. { this is theorically impossible... }
  566. if hp=nil then
  567. begin
  568. s:=#9#9+prefix;
  569. AsmWriteLn(s);
  570. break;
  571. end;
  572. { nasm prefers prefix on a line alone
  573. AsmWriteln(#9#9+prefix); but not masm PM
  574. prefix:=''; }
  575. end
  576. else
  577. prefix:= '';
  578. if taicpu(hp).ops<>0 then
  579. begin
  580. if is_calljmp(taicpu(hp).opcode) then
  581. s:=#9+getopstr_jmp(taicpu(hp).oper[0],taicpu(hp).opsize)
  582. else
  583. begin
  584. for i:=0to taicpu(hp).ops-1 do
  585. begin
  586. if i=0 then
  587. sep:=#9
  588. else
  589. sep:=',';
  590. s:=s+sep+getopstr(taicpu(hp).oper[i],taicpu(hp).opsize,taicpu(hp).opcode,(i=2));
  591. end;
  592. end;
  593. end;
  594. AsmWriteLn(#9#9+prefix+int_op2str[taicpu(hp).opcode]+cond2str[taicpu(hp).condition]+suffix+s);
  595. end;
  596. {$ifdef GDB}
  597. ait_stabn,
  598. ait_stabs,
  599. ait_force_line,
  600. ait_stab_function_name : ;
  601. {$endif GDB}
  602. ait_cut : begin
  603. { only reset buffer if nothing has changed }
  604. if AsmSize=AsmStartSize then
  605. AsmClear
  606. else
  607. begin
  608. if LastSec<>sec_none then
  609. AsmWriteLn('_'+target_asm.secnames[LastSec]+#9#9'ENDS');
  610. AsmLn;
  611. AsmWriteLn(#9'END');
  612. AsmClose;
  613. DoAssemble;
  614. AsmCreate(tai_cut(hp).place);
  615. end;
  616. { avoid empty files }
  617. while assigned(hp.next) and (tai(hp.next).typ in [ait_cut,ait_section,ait_comment]) do
  618. begin
  619. if tai(hp.next).typ=ait_section then
  620. begin
  621. lastsec:=tai_section(hp.next).sec;
  622. end;
  623. hp:=tai(hp.next);
  624. end;
  625. AsmWriteLn(#9'.386p');
  626. { I was told that this isn't necesarry because }
  627. { the labels generated by FPC are unique (FK) }
  628. { AsmWriteLn(#9'LOCALS '+target_asm.labelprefix); }
  629. if lastsec<>sec_none then
  630. AsmWriteLn('_'+target_asm.secnames[lastsec]+#9#9+
  631. 'SEGMENT'#9'PARA PUBLIC USE32 '''+
  632. target_asm.secnames[lastsec]+'''');
  633. AsmStartSize:=AsmSize;
  634. end;
  635. ait_marker :
  636. begin
  637. if tai_marker(hp).kind=InlineStart then
  638. inc(InlineLevel)
  639. else if tai_marker(hp).kind=InlineEnd then
  640. dec(InlineLevel);
  641. end;
  642. else
  643. internalerror(10000);
  644. end;
  645. hp:=tai(hp.next);
  646. end;
  647. end;
  648. var
  649. currentasmlist : PAsmList;
  650. procedure writeexternal(p:pnamedindexobject);
  651. begin
  652. if pasmsymbol(p)^.defbind=AB_EXTERNAL then
  653. begin
  654. if (aktoutputformat = as_i386_masm) then
  655. currentasmlist^.AsmWriteln(#9'EXTRN'#9+p^.name
  656. +': NEAR')
  657. else
  658. currentasmlist^.AsmWriteln(#9'EXTRN'#9+p^.name);
  659. end;
  660. end;
  661. procedure ti386intasmlist.WriteExternals;
  662. begin
  663. currentasmlist:=@self;
  664. AsmSymbolList^.foreach({$ifdef fpcprocvar}@{$endif}writeexternal);
  665. end;
  666. procedure ti386intasmlist.WriteAsmList;
  667. begin
  668. {$ifdef EXTDEBUG}
  669. if assigned(current_module.mainsource) then
  670. comment(v_info,'Start writing intel-styled assembler output for '+current_module.mainsource^);
  671. {$endif}
  672. LastSec:=sec_none;
  673. AsmWriteLn(#9'.386p');
  674. { masm 6.11 does not seem to like LOCALS PM }
  675. if (aktoutputformat = as_i386_tasm) then
  676. begin
  677. AsmWriteLn(#9'LOCALS '+target_asm.labelprefix);
  678. end;
  679. AsmWriteLn('DGROUP'#9'GROUP'#9'_BSS,_DATA');
  680. AsmWriteLn(#9'ASSUME'#9'CS:_CODE,ES:DGROUP,DS:DGROUP,SS:DGROUP');
  681. AsmLn;
  682. countlabelref:=false;
  683. WriteExternals;
  684. { INTEL ASM doesn't support stabs
  685. WriteTree(debuglist);}
  686. WriteTree(codesegment);
  687. WriteTree(datasegment);
  688. WriteTree(consts);
  689. WriteTree(rttilist);
  690. WriteTree(resourcestringlist);
  691. WriteTree(bsssegment);
  692. countlabelref:=true;
  693. AsmWriteLn(#9'END');
  694. AsmLn;
  695. {$ifdef EXTDEBUG}
  696. if assigned(current_module.mainsource) then
  697. comment(v_info,'Done writing intel-styled assembler output for '+current_module.mainsource^);
  698. {$endif EXTDEBUG}
  699. end;
  700. end.
  701. {
  702. $Log$
  703. Revision 1.6 2001-02-20 21:36:39 peter
  704. * tasm/masm fixes merged
  705. Revision 1.5 2001/01/13 20:24:24 peter
  706. * fixed operand order that got mixed up for external writers after
  707. my previous assembler block valid instruction check
  708. Revision 1.4 2000/12/25 00:07:31 peter
  709. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  710. tlinkedlist objects)
  711. Revision 1.3 2000/12/18 21:56:52 peter
  712. * extdebug fixes
  713. Revision 1.2 2000/11/29 00:30:43 florian
  714. * unused units removed from uses clause
  715. * some changes for widestrings
  716. Revision 1.1 2000/10/15 09:47:42 peter
  717. * moved to i386/
  718. Revision 1.6 2000/09/24 15:06:10 peter
  719. * use defines.inc
  720. Revision 1.5 2000/08/27 16:11:49 peter
  721. * moved some util functions from globals,cobjects to cutils
  722. * splitted files into finput,fmodule
  723. Revision 1.4 2000/08/20 17:38:21 peter
  724. * smartlinking fixed for linux (merged)
  725. Revision 1.3 2000/07/13 12:08:24 michael
  726. + patched to 1.1.0 with former 1.09patch from peter
  727. Revision 1.2 2000/07/13 11:32:30 michael
  728. + removed logs
  729. }