ag386nsm.pas 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl
  4. This unit implements an asmoutput class for the Nasm assembler with
  5. Intel syntax for the i386+
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. ****************************************************************************
  18. }
  19. {$ifdef TP}
  20. {$N+,E+}
  21. {$endif}
  22. unit ag386nsm;
  23. interface
  24. uses aasm,assemble;
  25. type
  26. pi386nasmasmlist=^ti386nasmasmlist;
  27. ti386nasmasmlist = object(tasmlist)
  28. procedure WriteTree(p:paasmoutput);virtual;
  29. procedure WriteAsmList;virtual;
  30. procedure WriteExternals;
  31. end;
  32. implementation
  33. uses
  34. strings,
  35. globtype,globals,systems,cobjects,
  36. files,verbose,cpubase,cpuasm
  37. {$ifdef GDB}
  38. ,gdb
  39. {$endif GDB}
  40. ;
  41. const
  42. line_length = 64;
  43. var
  44. lastfileinfo : tfileposinfo;
  45. infile,
  46. lastinfile : pinputfile;
  47. {$ifdef EXTTYPE}
  48. extstr : array[EXT_NEAR..EXT_ABS] of String[8] =
  49. ('NEAR','FAR','PROC','BYTE','WORD','DWORD',
  50. 'CODEPTR','DATAPTR','FWORD','PWORD','QWORD','TBYTE','ABS');
  51. {$endif}
  52. function fixline(s:string):string;
  53. {
  54. return s with all leading and ending spaces and tabs removed
  55. }
  56. var
  57. i,j,k : longint;
  58. begin
  59. i:=length(s);
  60. while (i>0) and (s[i] in [#9,' ']) do
  61. dec(i);
  62. j:=1;
  63. while (j<i) and (s[j] in [#9,' ']) do
  64. inc(j);
  65. for k:=j to i do
  66. if s[k] in [#0..#31,#127..#255] then
  67. s[k]:='.';
  68. fixline:=Copy(s,j,i-j+1);
  69. end;
  70. function single2str(d : single) : string;
  71. var
  72. hs : string;
  73. p : byte;
  74. begin
  75. str(d,hs);
  76. { nasm expects a lowercase e }
  77. p:=pos('E',hs);
  78. if p>0 then
  79. hs[p]:='e';
  80. p:=pos('+',hs);
  81. if p>0 then
  82. delete(hs,p,1);
  83. single2str:=lower(hs);
  84. end;
  85. function double2str(d : double) : string;
  86. var
  87. hs : string;
  88. p : byte;
  89. begin
  90. str(d,hs);
  91. { nasm expects a lowercase e }
  92. p:=pos('E',hs);
  93. if p>0 then
  94. hs[p]:='e';
  95. p:=pos('+',hs);
  96. if p>0 then
  97. delete(hs,p,1);
  98. double2str:=lower(hs);
  99. end;
  100. function extended2str(e : extended) : string;
  101. var
  102. hs : string;
  103. p : byte;
  104. begin
  105. str(e,hs);
  106. { nasm expects a lowercase e }
  107. p:=pos('E',hs);
  108. if p>0 then
  109. hs[p]:='e';
  110. p:=pos('+',hs);
  111. if p>0 then
  112. delete(hs,p,1);
  113. extended2str:=lower(hs);
  114. end;
  115. function comp2str(d : bestreal) : string;
  116. type
  117. pdouble = ^double;
  118. var
  119. c : comp;
  120. dd : pdouble;
  121. begin
  122. {$ifdef FPC}
  123. c:=comp(d);
  124. {$else}
  125. c:=d;
  126. {$endif}
  127. dd:=pdouble(@c); { this makes a bitwise copy of c into a double }
  128. comp2str:=double2str(dd^);
  129. end;
  130. function getreferencestring(var ref : treference) : string;
  131. var
  132. s : string;
  133. first : boolean;
  134. begin
  135. if ref.is_immediate then
  136. begin
  137. getreferencestring:=tostr(ref.offset);
  138. exit;
  139. end
  140. else
  141. with ref do
  142. begin
  143. first:=true;
  144. inc(offset,offsetfixup);
  145. offsetfixup:=0;
  146. if ref.segment<>R_NO then
  147. s:='['+int_reg2str[segment]+':'
  148. else
  149. s:='[';
  150. if assigned(symbol) then
  151. begin
  152. s:=s+symbol^.name;
  153. first:=false;
  154. end;
  155. if (base<>R_NO) then
  156. begin
  157. if not(first) then
  158. s:=s+'+'
  159. else
  160. first:=false;
  161. s:=s+int_reg2str[base];
  162. end;
  163. if (index<>R_NO) then
  164. begin
  165. if not(first) then
  166. s:=s+'+'
  167. else
  168. first:=false;
  169. s:=s+int_reg2str[index];
  170. if scalefactor<>0 then
  171. s:=s+'*'+tostr(scalefactor);
  172. end;
  173. if offset<0 then
  174. s:=s+tostr(offset)
  175. else if (offset>0) then
  176. s:=s+'+'+tostr(offset);
  177. s:=s+']';
  178. end;
  179. getreferencestring:=s;
  180. end;
  181. function sizestr(s:topsize;dest:boolean):string;
  182. begin
  183. case s of
  184. S_B : sizestr:='byte ';
  185. S_W : sizestr:='word ';
  186. S_L : sizestr:='dword ';
  187. S_IS : sizestr:='word ';
  188. S_IL : sizestr:='dword ';
  189. S_IQ : sizestr:='qword ';
  190. S_FS : sizestr:='dword ';
  191. S_FL : sizestr:='qword ';
  192. S_FX : sizestr:='tword ';
  193. S_BW : if dest then
  194. sizestr:='word '
  195. else
  196. sizestr:='byte ';
  197. S_BL : if dest then
  198. sizestr:='dword '
  199. else
  200. sizestr:='byte ';
  201. S_WL : if dest then
  202. sizestr:='dword '
  203. else
  204. sizestr:='word ';
  205. else { S_NO }
  206. sizestr:='';
  207. end;
  208. end;
  209. function getopstr(const o:toper;s : topsize; opcode: tasmop;ops:longint;dest : boolean) : string;
  210. var
  211. hs : string;
  212. begin
  213. case o.typ of
  214. top_reg :
  215. getopstr:=int_nasmreg2str[o.reg];
  216. top_const :
  217. begin
  218. if (ops=1) and (opcode<>A_RET) then
  219. getopstr:=sizestr(s,dest)+tostr(o.val)
  220. else
  221. getopstr:=tostr(o.val);
  222. end;
  223. top_symbol :
  224. begin
  225. if assigned(o.sym) then
  226. hs:='dword '+o.sym^.name
  227. else
  228. hs:='dword ';
  229. if o.symofs>0 then
  230. hs:=hs+'+'+tostr(o.symofs)
  231. else
  232. if o.symofs<0 then
  233. hs:=hs+tostr(o.symofs)
  234. else
  235. if not(assigned(o.sym)) then
  236. hs:=hs+'0';
  237. getopstr:=hs;
  238. end;
  239. top_ref :
  240. begin
  241. hs:=getreferencestring(o.ref^);
  242. if not ((opcode = A_LEA) or (opcode = A_LGS) or
  243. (opcode = A_LSS) or (opcode = A_LFS) or
  244. (opcode = A_LES) or (opcode = A_LDS) or
  245. (opcode = A_SHR) or (opcode = A_SHL) or
  246. (opcode = A_SAR) or (opcode = A_SAL) or
  247. (opcode = A_OUT) or (opcode = A_IN)) then
  248. begin
  249. hs:=sizestr(s,dest)+hs;
  250. end;
  251. getopstr:=hs;
  252. end;
  253. else
  254. internalerror(10001);
  255. end;
  256. end;
  257. function getopstr_jmp(const o:toper; op : tasmop) : string;
  258. var
  259. hs : string;
  260. begin
  261. case o.typ of
  262. top_reg :
  263. getopstr_jmp:=int_nasmreg2str[o.reg];
  264. top_ref :
  265. getopstr_jmp:=getreferencestring(o.ref^);
  266. top_const :
  267. getopstr_jmp:=tostr(o.val);
  268. top_symbol :
  269. begin
  270. hs:=o.sym^.name;
  271. if o.symofs>0 then
  272. hs:=hs+'+'+tostr(o.symofs)
  273. else
  274. if o.symofs<0 then
  275. hs:=hs+tostr(o.symofs);
  276. if (op=A_JCXZ) or (op=A_JECXZ) or
  277. (op=A_LOOP) or (op=A_LOOPE) or
  278. (op=A_LOOPNE) or (op=A_LOOPNZ) or
  279. (op=A_LOOPZ) then
  280. getopstr_jmp:=hs
  281. else
  282. getopstr_jmp:='NEAR '+hs;
  283. end;
  284. else
  285. internalerror(10001);
  286. end;
  287. end;
  288. {****************************************************************************
  289. Ti386nasmasmlist
  290. ****************************************************************************}
  291. var
  292. LastSec : tsection;
  293. const
  294. ait_const2str:array[ait_const_32bit..ait_const_8bit] of string[8]=
  295. (#9'DD'#9,#9'DW'#9,#9'DB'#9);
  296. Function PadTabs(const p:string;addch:char):string;
  297. var
  298. s : string;
  299. i : longint;
  300. begin
  301. i:=length(p);
  302. if addch<>#0 then
  303. begin
  304. inc(i);
  305. s:=p+addch;
  306. end
  307. else
  308. s:=p;
  309. if i<8 then
  310. PadTabs:=s+#9#9
  311. else
  312. PadTabs:=s+#9;
  313. end;
  314. procedure ti386nasmasmlist.WriteTree(p:paasmoutput);
  315. const
  316. allocstr : array[boolean] of string[10]=(' released',' allocated');
  317. nolinetai =[ait_label,
  318. ait_regalloc,ait_tempalloc,
  319. ait_stabn,ait_stabs,ait_section,
  320. ait_cut,ait_marker,ait_align,ait_stab_function_name];
  321. var
  322. s : string;
  323. {prefix,
  324. suffix : string; no need here }
  325. hp : pai;
  326. counter,
  327. lines,
  328. i,j,l : longint;
  329. InlineLevel : longint;
  330. consttyp : tait;
  331. found,
  332. do_line,
  333. quoted : boolean;
  334. sep : char;
  335. begin
  336. if not assigned(p) then
  337. exit;
  338. InlineLevel:=0;
  339. { lineinfo is only needed for codesegment (PFV) }
  340. do_line:=(cs_asm_source in aktglobalswitches) or
  341. ((cs_lineinfo in aktmoduleswitches)
  342. and (p=codesegment));
  343. hp:=pai(p^.first);
  344. while assigned(hp) do
  345. begin
  346. aktfilepos:=hp^.fileinfo;
  347. if not(hp^.typ in nolinetai) then
  348. begin
  349. if do_line then
  350. begin
  351. { load infile }
  352. if lastfileinfo.fileindex<>hp^.fileinfo.fileindex then
  353. begin
  354. infile:=current_module^.sourcefiles^.get_file(hp^.fileinfo.fileindex);
  355. if assigned(infile) then
  356. begin
  357. { open only if needed !! }
  358. if (cs_asm_source in aktglobalswitches) then
  359. infile^.open;
  360. end;
  361. { avoid unnecessary reopens of the same file !! }
  362. lastfileinfo.fileindex:=hp^.fileinfo.fileindex;
  363. { be sure to change line !! }
  364. lastfileinfo.line:=-1;
  365. end;
  366. { write source }
  367. if (cs_asm_source in aktglobalswitches) and
  368. assigned(infile) then
  369. begin
  370. if (infile<>lastinfile) then
  371. begin
  372. AsmWriteLn(target_asm.comment+'['+infile^.name^+']');
  373. if assigned(lastinfile) then
  374. lastinfile^.close;
  375. end;
  376. if (hp^.fileinfo.line<>lastfileinfo.line) and
  377. ((hp^.fileinfo.line<infile^.maxlinebuf) or (InlineLevel>0)) then
  378. begin
  379. if (hp^.fileinfo.line<>0) and
  380. ((infile^.linebuf^[hp^.fileinfo.line]>=0) or (InlineLevel>0)) then
  381. AsmWriteLn(target_asm.comment+'['+tostr(hp^.fileinfo.line)+'] '+
  382. fixline(infile^.GetLineStr(hp^.fileinfo.line)));
  383. { set it to a negative value !
  384. to make that is has been read already !! PM }
  385. if (infile^.linebuf^[hp^.fileinfo.line]>=0) then
  386. infile^.linebuf^[hp^.fileinfo.line]:=-infile^.linebuf^[hp^.fileinfo.line]-1;
  387. end;
  388. end;
  389. lastfileinfo:=hp^.fileinfo;
  390. lastinfile:=infile;
  391. end;
  392. end;
  393. case hp^.typ of
  394. ait_comment :
  395. Begin
  396. AsmWrite(target_asm.comment);
  397. AsmWritePChar(pai_asm_comment(hp)^.str);
  398. AsmLn;
  399. End;
  400. ait_regalloc :
  401. begin
  402. if (cs_asm_regalloc in aktglobalswitches) then
  403. AsmWriteLn(target_asm.comment+'Register '+att_reg2str[pairegalloc(hp)^.reg]+
  404. allocstr[pairegalloc(hp)^.allocation]);
  405. end;
  406. ait_tempalloc :
  407. begin
  408. if (cs_asm_tempalloc in aktglobalswitches) then
  409. AsmWriteLn(target_asm.comment+'Temp '+tostr(paitempalloc(hp)^.temppos)+','+
  410. tostr(paitempalloc(hp)^.tempsize)+allocstr[paitempalloc(hp)^.allocation]);
  411. end;
  412. ait_section :
  413. begin
  414. if pai_section(hp)^.sec<>sec_none then
  415. begin
  416. AsmLn;
  417. AsmWriteLn('SECTION '+target_asm.secnames[pai_section(hp)^.sec]);
  418. end;
  419. LastSec:=pai_section(hp)^.sec;
  420. end;
  421. ait_align :
  422. AsmWriteLn(#9'ALIGN '+tostr(pai_align(hp)^.aligntype));
  423. ait_datablock :
  424. begin
  425. if pai_datablock(hp)^.is_global then
  426. begin
  427. AsmWrite(#9'GLOBAL ');
  428. AsmWriteLn(pai_datablock(hp)^.sym^.name);
  429. end;
  430. AsmWrite(PadTabs(pai_datablock(hp)^.sym^.name,':'));
  431. AsmWriteLn('RESB'#9+tostr(pai_datablock(hp)^.size));
  432. end;
  433. ait_const_32bit,
  434. ait_const_16bit,
  435. ait_const_8bit :
  436. begin
  437. AsmWrite(ait_const2str[hp^.typ]+tostr(pai_const(hp)^.value));
  438. consttyp:=hp^.typ;
  439. l:=0;
  440. repeat
  441. found:=(not (Pai(hp^.next)=nil)) and (Pai(hp^.next)^.typ=consttyp);
  442. if found then
  443. begin
  444. hp:=Pai(hp^.next);
  445. s:=','+tostr(pai_const(hp)^.value);
  446. AsmWrite(s);
  447. inc(l,length(s));
  448. end;
  449. until (not found) or (l>line_length);
  450. AsmLn;
  451. end;
  452. ait_const_symbol :
  453. begin
  454. AsmWrite(#9#9'DD'#9);
  455. AsmWrite(pai_const_symbol(hp)^.sym^.name);
  456. if pai_const_symbol(hp)^.offset>0 then
  457. AsmWrite('+'+tostr(pai_const_symbol(hp)^.offset))
  458. else if pai_const_symbol(hp)^.offset<0 then
  459. AsmWrite(tostr(pai_const_symbol(hp)^.offset));
  460. AsmLn;
  461. end;
  462. ait_const_rva :
  463. begin
  464. AsmWrite(#9#9'RVA'#9);
  465. AsmWriteLn(pai_const_symbol(hp)^.sym^.name);
  466. end;
  467. ait_real_32bit :
  468. AsmWriteLn(#9#9'DD'#9+single2str(pai_real_32bit(hp)^.value));
  469. ait_real_64bit :
  470. AsmWriteLn(#9#9'DQ'#9+double2str(pai_real_64bit(hp)^.value));
  471. ait_real_80bit :
  472. AsmWriteLn(#9#9'DT'#9+extended2str(pai_real_80bit(hp)^.value));
  473. ait_comp_64bit :
  474. AsmWriteLn(#9#9'DQ'#9+comp2str(pai_real_80bit(hp)^.value));
  475. ait_string :
  476. begin
  477. counter := 0;
  478. lines := pai_string(hp)^.len div line_length;
  479. { separate lines in different parts }
  480. if pai_string(hp)^.len > 0 then
  481. Begin
  482. for j := 0 to lines-1 do
  483. begin
  484. AsmWrite(#9#9'DB'#9);
  485. quoted:=false;
  486. for i:=counter to counter+line_length-1 do
  487. begin
  488. { it is an ascii character. }
  489. if (ord(pai_string(hp)^.str[i])>31) and
  490. (ord(pai_string(hp)^.str[i])<128) and
  491. (pai_string(hp)^.str[i]<>'"') then
  492. begin
  493. if not(quoted) then
  494. begin
  495. if i>counter then
  496. AsmWrite(',');
  497. AsmWrite('"');
  498. end;
  499. AsmWrite(pai_string(hp)^.str[i]);
  500. quoted:=true;
  501. end { if > 31 and < 128 and ord('"') }
  502. else
  503. begin
  504. if quoted then
  505. AsmWrite('"');
  506. if i>counter then
  507. AsmWrite(',');
  508. quoted:=false;
  509. AsmWrite(tostr(ord(pai_string(hp)^.str[i])));
  510. end;
  511. end; { end for i:=0 to... }
  512. if quoted then AsmWrite('"');
  513. AsmWrite(target_os.newline);
  514. inc(counter,line_length);
  515. end; { end for j:=0 ... }
  516. { do last line of lines }
  517. if counter<pai_string(hp)^.len then
  518. AsmWrite(#9#9'DB'#9);
  519. quoted:=false;
  520. for i:=counter to pai_string(hp)^.len-1 do
  521. begin
  522. { it is an ascii character. }
  523. if (ord(pai_string(hp)^.str[i])>31) and
  524. (ord(pai_string(hp)^.str[i])<128) and
  525. (pai_string(hp)^.str[i]<>'"') then
  526. begin
  527. if not(quoted) then
  528. begin
  529. if i>counter then
  530. AsmWrite(',');
  531. AsmWrite('"');
  532. end;
  533. AsmWrite(pai_string(hp)^.str[i]);
  534. quoted:=true;
  535. end { if > 31 and < 128 and " }
  536. else
  537. begin
  538. if quoted then
  539. AsmWrite('"');
  540. if i>counter then
  541. AsmWrite(',');
  542. quoted:=false;
  543. AsmWrite(tostr(ord(pai_string(hp)^.str[i])));
  544. end;
  545. end; { end for i:=0 to... }
  546. if quoted then
  547. AsmWrite('"');
  548. end;
  549. AsmLn;
  550. end;
  551. ait_label :
  552. begin
  553. if pai_label(hp)^.l^.is_used then
  554. AsmWriteLn(pai_label(hp)^.l^.name+':');
  555. end;
  556. ait_direct :
  557. begin
  558. AsmWritePChar(pai_direct(hp)^.str);
  559. AsmLn;
  560. end;
  561. ait_symbol :
  562. begin
  563. if pai_symbol(hp)^.is_global then
  564. begin
  565. AsmWrite(#9'GLOBAL ');
  566. AsmWriteLn(pai_symbol(hp)^.sym^.name);
  567. end;
  568. AsmWrite(pai_symbol(hp)^.sym^.name);
  569. if assigned(hp^.next) and not(pai(hp^.next)^.typ in
  570. [ait_const_32bit,ait_const_16bit,ait_const_8bit,
  571. ait_const_symbol,ait_const_rva,
  572. ait_real_32bit,ait_real_64bit,ait_real_80bit,ait_comp_64bit,ait_string]) then
  573. AsmWriteLn(':')
  574. end;
  575. ait_symbol_end :
  576. begin
  577. end;
  578. ait_instruction :
  579. begin
  580. { We need intel order, no At&t }
  581. paicpu(hp)^.SwapOperands;
  582. { Reset
  583. suffix:='';
  584. prefix:='';}
  585. s:='';
  586. if paicpu(hp)^.ops<>0 then
  587. begin
  588. if is_calljmp(paicpu(hp)^.opcode) then
  589. s:=#9+getopstr_jmp(paicpu(hp)^.oper[0],paicpu(hp)^.opcode)
  590. else
  591. begin
  592. for i:=0to paicpu(hp)^.ops-1 do
  593. begin
  594. if i=0 then
  595. sep:=#9
  596. else
  597. sep:=',';
  598. s:=s+sep+getopstr(paicpu(hp)^.oper[i],paicpu(hp)^.opsize,paicpu(hp)^.opcode,
  599. paicpu(hp)^.ops,(i=2));
  600. end;
  601. end;
  602. end;
  603. if paicpu(hp)^.opcode=A_FWAIT then
  604. AsmWriteln(#9#9'DB'#9'09bh')
  605. else
  606. AsmWriteLn(#9#9+{prefix+}int_op2str[paicpu(hp)^.opcode]+
  607. cond2str[paicpu(hp)^.condition]+{suffix+}s);
  608. end;
  609. {$ifdef GDB}
  610. ait_stabn,
  611. ait_stabs,
  612. ait_force_line,
  613. ait_stab_function_name : ;
  614. {$endif GDB}
  615. ait_cut :
  616. begin
  617. { only reset buffer if nothing has changed }
  618. if AsmSize=AsmStartSize then
  619. AsmClear
  620. else
  621. begin
  622. AsmClose;
  623. DoAssemble;
  624. AsmCreate(pai_cut(hp)^.place);
  625. end;
  626. { avoid empty files }
  627. while assigned(hp^.next) and (pai(hp^.next)^.typ in [ait_cut,ait_section,ait_comment]) do
  628. begin
  629. if pai(hp^.next)^.typ=ait_section then
  630. lastsec:=pai_section(hp^.next)^.sec;
  631. hp:=pai(hp^.next);
  632. end;
  633. if lastsec<>sec_none then
  634. AsmWriteLn('SECTION '+target_asm.secnames[lastsec]);
  635. AsmStartSize:=AsmSize;
  636. end;
  637. ait_marker :
  638. if pai_marker(hp)^.kind=InlineStart then
  639. inc(InlineLevel)
  640. else if pai_marker(hp)^.kind=InlineEnd then
  641. dec(InlineLevel);
  642. else
  643. internalerror(10000);
  644. end;
  645. hp:=pai(hp^.next);
  646. end;
  647. end;
  648. var
  649. currentasmlist : PAsmList;
  650. procedure writeexternal(p:pnamedindexobject);{$ifndef FPC}far;{$endif}
  651. begin
  652. if pasmsymbol(p)^.typ=AS_EXTERNAL then
  653. currentasmlist^.AsmWriteln('EXTERN'#9+p^.name);
  654. end;
  655. procedure ti386nasmasmlist.WriteExternals;
  656. begin
  657. currentasmlist:=@self;
  658. AsmSymbolList^.foreach({$ifndef TP}@{$endif}writeexternal);
  659. end;
  660. procedure ti386nasmasmlist.WriteAsmList;
  661. begin
  662. {$ifdef EXTDEBUG}
  663. if assigned(current_module^.mainsource) then
  664. comment(v_info,'Start writing nasm-styled assembler output for '+current_module^.mainsource^);
  665. {$endif}
  666. LastSec:=sec_none;
  667. AsmWriteLn('BITS 32');
  668. AsmLn;
  669. countlabelref:=false;
  670. lastfileinfo.line:=-1;
  671. lastfileinfo.fileindex:=0;
  672. lastinfile:=nil;
  673. WriteExternals;
  674. { Nasm doesn't support stabs
  675. WriteTree(debuglist);}
  676. WriteTree(codesegment);
  677. WriteTree(datasegment);
  678. WriteTree(consts);
  679. WriteTree(rttilist);
  680. WriteTree(resourcestringlist);
  681. WriteTree(bsssegment);
  682. countlabelref:=true;
  683. AsmLn;
  684. {$ifdef EXTDEBUG}
  685. if assigned(current_module^.mainsource) then
  686. comment(v_info,'Done writing nasm-styled assembler output for '+current_module^.mainsource^);
  687. {$endif EXTDEBUG}
  688. end;
  689. end.
  690. {
  691. $Log$
  692. Revision 1.57 2000-04-06 07:09:15 pierre
  693. * handle offset fixup
  694. + add source lines
  695. * no NEAR for opcodes that only support short jumps
  696. Revision 1.56 2000/02/09 13:22:43 peter
  697. * log truncated
  698. Revision 1.55 2000/01/07 01:14:18 peter
  699. * updated copyright to 2000
  700. Revision 1.54 1999/11/06 14:34:16 peter
  701. * truncated log to 20 revs
  702. Revision 1.53 1999/11/02 15:06:56 peter
  703. * import library fixes for win32
  704. * alignment works again
  705. Revision 1.52 1999/09/13 16:27:24 peter
  706. * fix for jmps to be always near
  707. * string writing fixed
  708. Revision 1.51 1999/09/10 15:41:18 peter
  709. * added symbol_end
  710. Revision 1.50 1999/09/02 18:47:43 daniel
  711. * Could not compile with TP, some arrays moved to heap
  712. * NOAG386BIN default for TP
  713. * AG386* files were not compatible with TP, fixed.
  714. Revision 1.49 1999/08/25 11:59:38 jonas
  715. * changed pai386, paippc and paiapha (same for tai*) to paicpu (taicpu)
  716. Revision 1.48 1999/08/04 00:22:37 florian
  717. * renamed i386asm and i386base to cpuasm and cpubase
  718. Revision 1.47 1999/08/01 18:28:10 florian
  719. * modifications for the new code generator
  720. Revision 1.46 1999/07/22 09:37:33 florian
  721. + resourcestring implemented
  722. + start of longstring support
  723. }