ag386int.pas 27 KB

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