ag386nsm.pas 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856
  1. {
  2. $Id$
  3. Copyright (c) 1996,97 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. end;
  31. implementation
  32. uses
  33. dos,globals,systems,cobjects,
  34. {$ifndef OLDASM}
  35. i386base,i386asm,
  36. {$else}
  37. i386,
  38. {$endif}
  39. strings,files,verbose
  40. {$ifdef GDB}
  41. ,gdb
  42. {$endif GDB}
  43. ;
  44. const
  45. line_length = 70;
  46. extstr : array[EXT_NEAR..EXT_ABS] of String[8] =
  47. ('NEAR','FAR','PROC','BYTE','WORD','DWORD',
  48. 'CODEPTR','DATAPTR','FWORD','PWORD','QWORD','TBYTE','ABS');
  49. function double2str(d : double) : string;
  50. var
  51. hs : string;
  52. p : byte;
  53. begin
  54. str(d,hs);
  55. { nasm expects a lowercase e }
  56. p:=pos('E',hs);
  57. if p>0 then
  58. hs[p]:='e';
  59. p:=pos('+',hs);
  60. if p>0 then
  61. delete(hs,p,1);
  62. double2str:=lower(hs);
  63. end;
  64. function extended2str(e : extended) : string;
  65. var
  66. hs : string;
  67. p : byte;
  68. begin
  69. str(e,hs);
  70. { nasm expects a lowercase e }
  71. p:=pos('E',hs);
  72. if p>0 then
  73. hs[p]:='e';
  74. p:=pos('+',hs);
  75. if p>0 then
  76. delete(hs,p,1);
  77. extended2str:=lower(hs);
  78. end;
  79. function comp2str(d : bestreal) : string;
  80. type
  81. pdouble = ^double;
  82. var
  83. c : comp;
  84. dd : pdouble;
  85. begin
  86. {$ifdef TP}
  87. c:=d;
  88. {$else}
  89. c:=comp(d);
  90. {$endif}
  91. dd:=pdouble(@c); { this makes a bitwise copy of c into a double }
  92. comp2str:=double2str(dd^);
  93. end;
  94. function getreferencestring(const ref : treference) : string;
  95. var
  96. s : string;
  97. first : boolean;
  98. begin
  99. if ref.is_immediate then
  100. begin
  101. getreferencestring:=tostr(ref.offset);
  102. exit;
  103. end
  104. else
  105. with ref do
  106. begin
  107. first:=true;
  108. if ref.segment<>R_DEFAULT_SEG then
  109. s:='['+int_reg2str[segment]+':'
  110. else
  111. s:='[';
  112. if assigned(symbol) then
  113. begin
  114. s:=s+symbol^.name;
  115. first:=false;
  116. end;
  117. if (base<>R_NO) then
  118. begin
  119. if not(first) then
  120. s:=s+'+'
  121. else
  122. first:=false;
  123. s:=s+int_reg2str[base];
  124. end;
  125. if (index<>R_NO) then
  126. begin
  127. if not(first) then
  128. s:=s+'+'
  129. else
  130. first:=false;
  131. s:=s+int_reg2str[index];
  132. if scalefactor<>0 then
  133. s:=s+'*'+tostr(scalefactor);
  134. end;
  135. if offset<0 then
  136. s:=s+tostr(offset)
  137. else if (offset>0) then
  138. s:=s+'+'+tostr(offset);
  139. s:=s+']';
  140. end;
  141. getreferencestring:=s;
  142. end;
  143. {$ifndef OLDASM}
  144. function getopstr(const o:toper;s : topsize; opcode: tasmop;dest : boolean) : string;
  145. var
  146. hs : string;
  147. begin
  148. case o.typ of
  149. top_reg :
  150. getopstr:=int_nasmreg2str[o.reg];
  151. top_const :
  152. getopstr:=tostr(o.val);
  153. top_symbol :
  154. begin
  155. hs:='dword '+o.sym^.name;
  156. if o.symofs>0 then
  157. hs:=hs+'+'+tostr(o.symofs)
  158. else
  159. if o.symofs<0 then
  160. hs:=hs+tostr(o.symofs);
  161. getopstr:=hs;
  162. end;
  163. top_ref :
  164. begin
  165. hs:=getreferencestring(o.ref^);
  166. if not ((opcode = A_LEA) or (opcode = A_LGS) or
  167. (opcode = A_LSS) or (opcode = A_LFS) or
  168. (opcode = A_LES) or (opcode = A_LDS) or
  169. (opcode = A_SHR) or (opcode = A_SHL) or
  170. (opcode = A_SAR) or (opcode = A_SAL) or
  171. (opcode = A_OUT) or (opcode = A_IN)) then
  172. begin
  173. case s of
  174. S_B : hs:='byte '+hs;
  175. S_W : hs:='word '+hs;
  176. S_L : hs:='dword '+hs;
  177. S_IS : hs:='word '+hs;
  178. S_IL : hs:='dword '+hs;
  179. S_IQ : hs:='qword '+hs;
  180. S_FS : hs:='dword '+hs;
  181. S_FL : hs:='qword '+hs;
  182. S_FX : hs:='tword '+hs;
  183. S_BW : if dest then
  184. hs:='word '+hs
  185. else
  186. hs:='byte '+hs;
  187. S_BL : if dest then
  188. hs:='dword '+hs
  189. else
  190. hs:='byte '+hs;
  191. S_WL : if dest then
  192. hs:='dword '+hs
  193. else
  194. hs:='word '+hs;
  195. end
  196. end;
  197. getopstr:=hs;
  198. end;
  199. else
  200. internalerror(10001);
  201. end;
  202. end;
  203. function getopstr_jmp(const o:toper) : string;
  204. var
  205. hs : string;
  206. begin
  207. case o.typ of
  208. top_reg :
  209. getopstr_jmp:=int_nasmreg2str[o.reg];
  210. top_ref :
  211. getopstr_jmp:=getreferencestring(o.ref^);
  212. top_const :
  213. getopstr_jmp:=tostr(o.val);
  214. top_symbol :
  215. begin
  216. hs:=o.sym^.name;
  217. if o.symofs>0 then
  218. hs:=hs+'+'+tostr(o.symofs)
  219. else
  220. if o.symofs<0 then
  221. hs:=hs+tostr(o.symofs);
  222. getopstr_jmp:=hs;
  223. end;
  224. else
  225. internalerror(10001);
  226. end;
  227. end;
  228. {$else}
  229. function getopstr(t : byte;o : pointer;opofs:longint;s : topsize; opcode: tasmop;dest : boolean) : string;
  230. var
  231. hs : string;
  232. begin
  233. case t of
  234. top_reg : getopstr:=int_nasmreg2str[tregister(o)];
  235. top_const,
  236. top_ref : begin
  237. if t=top_const then
  238. hs := tostr(longint(o))
  239. else
  240. hs:=getreferencestring(preference(o)^);
  241. if not ((opcode = A_LEA) or (opcode = A_LGS) or
  242. (opcode = A_LSS) or (opcode = A_LFS) or
  243. (opcode = A_LES) or (opcode = A_LDS) or
  244. (opcode = A_SHR) or (opcode = A_SHL) or
  245. (opcode = A_SAR) or (opcode = A_SAL) or
  246. (opcode = A_OUT) or (opcode = A_IN)) then
  247. begin
  248. case s of
  249. S_B : hs:='byte '+hs;
  250. S_W : hs:='word '+hs;
  251. S_L : hs:='dword '+hs;
  252. S_IS : hs:='word '+hs;
  253. S_IL : hs:='dword '+hs;
  254. S_IQ : hs:='qword '+hs;
  255. S_FS : hs:='dword '+hs;
  256. S_FL : hs:='qword '+hs;
  257. S_FX : hs:='tword '+hs;
  258. S_BW : if dest then
  259. hs:='word '+hs
  260. else
  261. hs:='byte '+hs;
  262. S_BL : if dest then
  263. hs:='dword '+hs
  264. else
  265. hs:='byte '+hs;
  266. S_WL : if dest then
  267. hs:='dword '+hs
  268. else
  269. hs:='word '+hs;
  270. end
  271. end;
  272. getopstr:=hs;
  273. end;
  274. top_symbol : begin
  275. hs:='dword '+pasmsymbol(o)^.name;
  276. if opofs>0 then
  277. hs:=hs+'+'+tostr(opofs)
  278. else
  279. if opofs<0 then
  280. hs:=hs+tostr(opofs);
  281. getopstr:=hs;
  282. end;
  283. else
  284. internalerror(10001);
  285. end;
  286. end;
  287. function getopstr_jmp(t : byte;o : pointer;opofs:longint) : string;
  288. var
  289. hs : string;
  290. begin
  291. case t of
  292. top_reg : getopstr_jmp:=int_reg2str[tregister(o)];
  293. top_ref : getopstr_jmp:=getreferencestring(preference(o)^);
  294. top_const : getopstr_jmp:=tostr(longint(o));
  295. top_symbol : begin
  296. hs:=pasmsymbol(o)^.name;
  297. if opofs>0 then
  298. hs:=hs+'+'+tostr(opofs)
  299. else
  300. if opofs<0 then
  301. hs:=hs+tostr(opofs);
  302. getopstr_jmp:=hs;
  303. end;
  304. else
  305. internalerror(10001);
  306. end;
  307. end;
  308. {$endif}
  309. {****************************************************************************
  310. Ti386nasmasmlist
  311. ****************************************************************************}
  312. var
  313. LastSec : tsection;
  314. const
  315. ait_const2str:array[ait_const_32bit..ait_const_8bit] of string[8]=
  316. (#9'DD'#9,#9'DW'#9,#9'DB'#9);
  317. ait_section2nasmstr : array[tsection] of string[8]=
  318. ('','.text','.data','.bss',
  319. '.stab','.stabstr',
  320. '.idata2','.idata4','.idata5','.idata6','.idata7','.edata',
  321. '');
  322. Function PadTabs(const p:string;addch:char):string;
  323. var
  324. s : string;
  325. i : longint;
  326. begin
  327. i:=length(p);
  328. if addch<>#0 then
  329. begin
  330. inc(i);
  331. s:=p+addch;
  332. end
  333. else
  334. s:=p;
  335. if i<8 then
  336. PadTabs:=s+#9#9
  337. else
  338. PadTabs:=s+#9;
  339. end;
  340. procedure ti386nasmasmlist.WriteTree(p:paasmoutput);
  341. type
  342. twowords=record
  343. word1,word2:word;
  344. end;
  345. var
  346. s,
  347. prefix,
  348. suffix : string;
  349. hp : pai;
  350. counter,
  351. lines,
  352. i,j,l : longint;
  353. op : tasmop;
  354. consttyp : tait;
  355. found,
  356. quoted : boolean;
  357. {$ifndef OLDASM}
  358. sep : char;
  359. {$endif}
  360. begin
  361. if not assigned(p) then
  362. exit;
  363. hp:=pai(p^.first);
  364. while assigned(hp) do
  365. begin
  366. case hp^.typ of
  367. ait_comment : Begin
  368. AsmWrite(target_asm.comment);
  369. AsmWritePChar(pai_asm_comment(hp)^.str);
  370. AsmLn;
  371. End;
  372. ait_regalloc,
  373. ait_tempalloc : ;
  374. ait_section : begin
  375. if pai_section(hp)^.sec<>sec_none then
  376. begin
  377. AsmLn;
  378. AsmWriteLn('SECTION '+ait_section2nasmstr[pai_section(hp)^.sec]);
  379. end;
  380. LastSec:=pai_section(hp)^.sec;
  381. end;
  382. ait_align : AsmWriteLn(#9'ALIGN '+tostr(pai_align(hp)^.aligntype));
  383. ait_external : AsmWriteLn('EXTERN '+pai_external(hp)^.sym^.name);
  384. ait_datablock : begin
  385. if pai_datablock(hp)^.is_global then
  386. AsmWriteLn(#9'GLOBAL '+pai_datablock(hp)^.sym^.name);
  387. AsmWriteLn(PadTabs(pai_datablock(hp)^.sym^.name,':')+'RESB'#9+tostr(pai_datablock(hp)^.size));
  388. end;
  389. ait_const_32bit,
  390. ait_const_8bit,
  391. ait_const_16bit : begin
  392. AsmWrite(ait_const2str[hp^.typ]+tostr(pai_const(hp)^.value));
  393. consttyp:=hp^.typ;
  394. l:=0;
  395. repeat
  396. found:=(not (Pai(hp^.next)=nil)) and (Pai(hp^.next)^.typ=consttyp);
  397. if found then
  398. begin
  399. hp:=Pai(hp^.next);
  400. s:=','+tostr(pai_const(hp)^.value);
  401. AsmWrite(s);
  402. inc(l,length(s));
  403. end;
  404. until (not found) or (l>line_length);
  405. AsmLn;
  406. end;
  407. ait_const_symbol : begin
  408. AsmWriteLn(#9#9'DD'#9+pai_const_symbol(hp)^.sym^.name);
  409. if pai_const_symbol(hp)^.offset>0 then
  410. AsmWrite('+'+tostr(pai_const_symbol(hp)^.offset))
  411. else if pai_const_symbol(hp)^.offset<0 then
  412. AsmWrite(tostr(pai_const_symbol(hp)^.offset));
  413. AsmLn;
  414. end;
  415. ait_const_rva : begin
  416. AsmWriteLn(#9#9'RVA'#9+pai_const_symbol(hp)^.sym^.name);
  417. end;
  418. ait_real_32bit : AsmWriteLn(#9#9'DD'#9+double2str(pai_single(hp)^.value));
  419. ait_real_64bit : AsmWriteLn(#9#9'DQ'#9+double2str(pai_double(hp)^.value));
  420. ait_real_extended : AsmWriteLn(#9#9'DT'#9+extended2str(pai_extended(hp)^.value));
  421. ait_comp : AsmWriteLn(#9#9'DQ'#9+comp2str(pai_extended(hp)^.value));
  422. ait_string : begin
  423. counter := 0;
  424. lines := pai_string(hp)^.len div line_length;
  425. { separate lines in different parts }
  426. if pai_string(hp)^.len > 0 then
  427. Begin
  428. for j := 0 to lines-1 do
  429. begin
  430. AsmWrite(#9#9'DB'#9);
  431. quoted:=false;
  432. for i:=counter to counter+line_length do
  433. begin
  434. { it is an ascii character. }
  435. if (ord(pai_string(hp)^.str[i])>31) and
  436. (ord(pai_string(hp)^.str[i])<128) and
  437. (pai_string(hp)^.str[i]<>'"') then
  438. begin
  439. if not(quoted) then
  440. begin
  441. if i>counter then
  442. AsmWrite(',');
  443. AsmWrite('"');
  444. end;
  445. AsmWrite(pai_string(hp)^.str[i]);
  446. quoted:=true;
  447. end { if > 31 and < 128 and ord('"') }
  448. else
  449. begin
  450. if quoted then
  451. AsmWrite('"');
  452. if i>counter then
  453. AsmWrite(',');
  454. quoted:=false;
  455. AsmWrite(tostr(ord(pai_string(hp)^.str[i])));
  456. end;
  457. end; { end for i:=0 to... }
  458. if quoted then AsmWrite('"');
  459. AsmWrite(target_os.newline);
  460. counter := counter+line_length;
  461. end; { end for j:=0 ... }
  462. { do last line of lines }
  463. AsmWrite(#9#9'DB'#9);
  464. quoted:=false;
  465. for i:=counter to pai_string(hp)^.len-1 do
  466. begin
  467. { it is an ascii character. }
  468. if (ord(pai_string(hp)^.str[i])>31) and
  469. (ord(pai_string(hp)^.str[i])<128) and
  470. (pai_string(hp)^.str[i]<>'"') then
  471. begin
  472. if not(quoted) then
  473. begin
  474. if i>counter then
  475. AsmWrite(',');
  476. AsmWrite('"');
  477. end;
  478. AsmWrite(pai_string(hp)^.str[i]);
  479. quoted:=true;
  480. end { if > 31 and < 128 and " }
  481. else
  482. begin
  483. if quoted then
  484. AsmWrite('"');
  485. if i>counter then
  486. AsmWrite(',');
  487. quoted:=false;
  488. AsmWrite(tostr(ord(pai_string(hp)^.str[i])));
  489. end;
  490. end; { end for i:=0 to... }
  491. if quoted then
  492. AsmWrite('"');
  493. end;
  494. AsmLn;
  495. end;
  496. ait_label : begin
  497. if pai_label(hp)^.l^.is_used then
  498. AsmWriteLn(lab2str(pai_label(hp)^.l)+':');
  499. end;
  500. ait_direct : begin
  501. AsmWritePChar(pai_direct(hp)^.str);
  502. AsmLn;
  503. end;
  504. ait_labeled_instruction :
  505. begin
  506. op:=pai386_labeled(hp)^.opcode;
  507. if not((op=A_JMP) or (op=A_LOOP) or (op=A_LOOPZ) or
  508. (op=A_LOOPE) or (op=A_LOOPNZ) or (op=A_LOOPNE) or
  509. (op=A_JCXZ) or (op=A_JECXZ)) then
  510. AsmWriteLn(#9#9+int_op2str[pai386_labeled(hp)^.opcode]+#9+'near '+lab2str(pai386_labeled(hp)^.lab))
  511. else
  512. AsmWriteLn(#9#9+int_op2str[pai386_labeled(hp)^.opcode]+#9+lab2str(pai386_labeled(hp)^.lab));
  513. end;
  514. ait_symbol : begin
  515. if pai_symbol(hp)^.is_global then
  516. AsmWriteLn(#9'GLOBAL '+pai_symbol(hp)^.sym^.name);
  517. AsmWrite(pai_symbol(hp)^.sym^.name);
  518. if assigned(hp^.next) and not(pai(hp^.next)^.typ in
  519. [ait_const_32bit,ait_const_16bit,ait_const_8bit,
  520. ait_const_symbol,ait_const_rva,
  521. ait_real_64bit,ait_string]) then
  522. AsmWriteLn(':')
  523. end;
  524. ait_instruction : begin
  525. suffix:='';
  526. prefix:='';
  527. {$ifndef OLDASM}
  528. if pai386(hp)^.ops<>0 then
  529. begin
  530. if pai386(hp)^.opcode=A_CALL then
  531. s:=#9+getopstr_jmp(pai386(hp)^.oper[0])
  532. else
  533. begin
  534. for i:=0to pai386(hp)^.ops-1 do
  535. begin
  536. if i=0 then
  537. sep:=#9
  538. else
  539. sep:=',';
  540. s:=s+sep+getopstr(pai386(hp)^.oper[i],pai386(hp)^.opsize,pai386(hp)^.opcode,(i=1));
  541. end;
  542. end;
  543. end
  544. else
  545. s:='';
  546. if pai386(hp)^.opcode=A_FWAIT then
  547. AsmWriteln(#9#9'DB'#9'09bh')
  548. else
  549. AsmWriteLn(#9#9+prefix+int_op2str[pai386(hp)^.opcode]+
  550. cond2str[pai386_labeled(hp)^.condition]+suffix+s);
  551. {$else}
  552. { added prefix instructions, must be on same line as opcode }
  553. if (pai386(hp)^.op1t = top_none) and
  554. ((pai386(hp)^.opcode = A_REP) or
  555. (pai386(hp)^.opcode = A_LOCK) or
  556. (pai386(hp)^.opcode = A_REPE) or
  557. (pai386(hp)^.opcode = A_REPNE)) then
  558. Begin
  559. prefix:=int_op2str[pai386(hp)^.opcode]+#9;
  560. hp:=Pai(hp^.next);
  561. { this is theorically impossible... }
  562. if hp=nil then
  563. begin
  564. s:=#9#9+prefix;
  565. AsmWriteLn(s);
  566. break;
  567. end;
  568. { nasm prefers prefix on a line alone }
  569. AsmWriteln(#9#9+prefix);
  570. prefix:='';
  571. end
  572. else
  573. prefix:= '';
  574. { A_FNSTS need the w as suffix at least for nasm}
  575. if (pai386(hp)^.opcode = A_FNSTS) then
  576. pai386(hp)^.opcode:=A_FNSTSW
  577. else
  578. if (pai386(hp)^.opcode = A_FSTS) then
  579. pai386(hp)^.opcode:=A_FSTSW;
  580. if pai386(hp)^.op1t<>top_none then
  581. begin
  582. if pai386(hp)^.opcode=A_CALL then
  583. s:=getopstr_jmp(pai386(hp)^.op1t,pai386(hp)^.op1,pai386(hp)^.op1ofs)
  584. else
  585. begin
  586. s:=getopstr(pai386(hp)^.op1t,pai386(hp)^.op1,pai386(hp)^.op1ofs,
  587. pai386(hp)^.opsize,pai386(hp)^.opcode,false);
  588. if pai386(hp)^.op3t<>top_none then
  589. begin
  590. if pai386(hp)^.op2t<>top_none then
  591. {$ifdef NO_OP3}
  592. s:=getopstr(pai386(hp)^.op2t,pointer(longint(twowords(pai386(hp)^.op2).word1)),0,
  593. pai386(hp)^.opsize,pai386(hp)^.opcode,true)+','+s;
  594. s:=getopstr(pai386(hp)^.op3t,pointer(longint(twowords(pai386(hp)^.op2).word2)),0,
  595. pai386(hp)^.opsize,pai386(hp)^.opcode,false)+','+s;
  596. {$else NO_OP3}
  597. s:=getopstr(pai386(hp)^.op2t,pai386(hp)^.op2,0,
  598. pai386(hp)^.opsize,pai386(hp)^.opcode,true)+','+s;
  599. s:=getopstr(pai386(hp)^.op3t,pai386(hp)^.op3,0,
  600. pai386(hp)^.opsize,pai386(hp)^.opcode,false)+','+s;
  601. {$endif NO_OP3}
  602. end
  603. else
  604. if pai386(hp)^.op2t<>top_none then
  605. s:=getopstr(pai386(hp)^.op2t,pai386(hp)^.op2,0,pai386(hp)^.opsize,
  606. pai386(hp)^.opcode,true)+','+s;
  607. end;
  608. s:=#9+s;
  609. end
  610. else
  611. begin
  612. { check if string instruction }
  613. { long form, otherwise may give range check errors }
  614. { in turbo pascal... }
  615. if ((pai386(hp)^.opcode = A_CMPS) or
  616. (pai386(hp)^.opcode = A_INS) or
  617. (pai386(hp)^.opcode = A_OUTS) or
  618. (pai386(hp)^.opcode = A_SCAS) or
  619. (pai386(hp)^.opcode = A_STOS) or
  620. (pai386(hp)^.opcode = A_MOVS) or
  621. (pai386(hp)^.opcode = A_LODS) or
  622. (pai386(hp)^.opcode = A_XLAT)) then
  623. Begin
  624. case pai386(hp)^.opsize of
  625. S_B: suffix:='b';
  626. S_W: suffix:='w';
  627. S_L: suffix:='d';
  628. else
  629. Message(assem_f_invalid_suffix_intel);
  630. end;
  631. end;
  632. s:='';
  633. end;
  634. if pai386(hp)^.opcode=A_FWAIT then
  635. AsmWriteln(#9#9'DB'#9'09bh')
  636. else
  637. AsmWriteLn(#9#9+prefix+int_op2str[pai386(hp)^.opcode]+suffix+s);
  638. {$endif AG386BIN}
  639. end;
  640. {$ifdef GDB}
  641. ait_stabn,
  642. ait_stabs,
  643. ait_force_line,
  644. ait_stab_function_name : ;
  645. {$endif GDB}
  646. ait_cut : begin
  647. { only reset buffer if nothing has changed }
  648. if AsmSize=AsmStartSize then
  649. AsmClear
  650. else
  651. begin
  652. AsmClose;
  653. DoAssemble;
  654. if pai_cut(hp)^.EndName then
  655. IsEndFile:=true;
  656. AsmCreate;
  657. end;
  658. { avoid empty files }
  659. while assigned(hp^.next) and (pai(hp^.next)^.typ in [ait_cut,ait_section,ait_comment]) do
  660. begin
  661. if pai(hp^.next)^.typ=ait_section then
  662. lastsec:=pai_section(hp^.next)^.sec;
  663. hp:=pai(hp^.next);
  664. end;
  665. if lastsec<>sec_none then
  666. AsmWriteLn('SECTION '+ait_section2nasmstr[lastsec]);
  667. AsmStartSize:=AsmSize;
  668. end;
  669. ait_marker : ;
  670. else
  671. internalerror(10000);
  672. end;
  673. hp:=pai(hp^.next);
  674. end;
  675. end;
  676. procedure ti386nasmasmlist.WriteAsmList;
  677. begin
  678. {$ifdef EXTDEBUG}
  679. if assigned(current_module^.mainsource) then
  680. comment(v_info,'Start writing nasm-styled assembler output for '+current_module^.mainsource^);
  681. {$endif}
  682. LastSec:=sec_none;
  683. AsmWriteLn('BITS 32');
  684. AsmLn;
  685. countlabelref:=false;
  686. WriteTree(externals);
  687. { Nasm doesn't support stabs
  688. WriteTree(debuglist);}
  689. WriteTree(codesegment);
  690. WriteTree(datasegment);
  691. WriteTree(consts);
  692. WriteTree(rttilist);
  693. WriteTree(bsssegment);
  694. countlabelref:=true;
  695. AsmLn;
  696. {$ifdef EXTDEBUG}
  697. if assigned(current_module^.mainsource) then
  698. comment(v_info,'Done writing nasm-styled assembler output for '+current_module^.mainsource^);
  699. {$endif EXTDEBUG}
  700. end;
  701. end.
  702. {
  703. $Log$
  704. Revision 1.29 1999-05-01 13:23:59 peter
  705. * merged nasm compiler
  706. * old asm moved to oldasm/
  707. Revision 1.28 1999/04/17 22:17:06 pierre
  708. * ifdef USE_OP3 released (changed into ifndef NO_OP3)
  709. * SHRD and SHLD first operand (ATT syntax) can only be CL reg or immediate const
  710. Revision 1.27 1999/04/16 11:49:40 peter
  711. + tempalloc
  712. + -at to show temp alloc info in .s file
  713. Revision 1.26 1999/04/16 10:00:56 pierre
  714. + ifdef USE_OP3 code :
  715. added all missing op_... constructors for tai386 needed
  716. for SHRD,SHLD and IMUL code in assembler readers
  717. (check in tests/tbs0123.pp)
  718. Revision 1.25 1999/03/29 16:05:44 peter
  719. * optimizer working for ag386bin
  720. Revision 1.24 1999/03/10 13:25:44 pierre
  721. section order changed to get closer output from coff writer
  722. Revision 1.23 1999/03/04 13:55:39 pierre
  723. * some m68k fixes (still not compilable !)
  724. * new(tobj) does not give warning if tobj has no VMT !
  725. Revision 1.22 1999/03/02 02:56:11 peter
  726. + stabs support for binary writers
  727. * more fixes and missing updates from the previous commit :(
  728. Revision 1.21 1999/03/01 15:46:17 peter
  729. * ag386bin finally make cycles correct
  730. * prefixes are now also normal opcodes
  731. Revision 1.20 1999/02/26 00:48:14 peter
  732. * assembler writers fixed for ag386bin
  733. Revision 1.19 1999/02/25 21:02:19 peter
  734. * ag386bin updates
  735. + coff writer
  736. Revision 1.18 1999/02/22 02:15:00 peter
  737. * updates for ag386bin
  738. Revision 1.17 1998/12/20 16:21:23 peter
  739. * smartlinking doesn't crash anymore
  740. Revision 1.16 1998/12/16 00:27:18 peter
  741. * removed some obsolete version checks
  742. Revision 1.15 1998/12/01 11:19:39 peter
  743. * fixed range problem with in [tasmop]
  744. Revision 1.14 1998/11/30 09:42:56 pierre
  745. * some range check bugs fixed (still not working !)
  746. + added DLL writing support for win32 (also accepts variables)
  747. + TempAnsi for code that could be used for Temporary ansi strings
  748. handling
  749. Revision 1.13 1998/11/17 00:26:10 peter
  750. * fixed for $H+
  751. Revision 1.12 1998/11/12 11:19:34 pierre
  752. * fix for first line of function break
  753. Revision 1.11 1998/10/12 12:20:42 pierre
  754. + added tai_const_symbol_offset
  755. for r : pointer = @var.field;
  756. * better message for different arg names on implementation
  757. of function
  758. Revision 1.10 1998/10/06 17:16:34 pierre
  759. * some memory leaks fixed (thanks to Peter for heaptrc !)
  760. Revision 1.9 1998/10/01 20:19:07 jonas
  761. + ait_marker support
  762. Revision 1.8 1998/09/20 17:11:22 jonas
  763. * released REGALLOC
  764. Revision 1.7 1998/08/11 14:01:43 peter
  765. * fixed fwait bug using direct opcode
  766. Revision 1.6 1998/08/10 15:49:39 peter
  767. * small fixes for 0.99.5
  768. Revision 1.5 1998/08/08 10:19:18 florian
  769. * small fixes to write the extended type correct
  770. Revision 1.4 1998/06/05 17:46:03 peter
  771. * tp doesn't like comp() typecast
  772. Revision 1.3 1998/05/28 17:24:27 peter
  773. - $R- for tp to solve range errors with in[]
  774. Revision 1.2 1998/05/25 17:11:37 pierre
  775. * firstpasscount bug fixed
  776. now all is already set correctly the first time
  777. under EXTDEBUG try -gp to skip all other firstpasses
  778. it works !!
  779. * small bug fixes
  780. - for smallsets with -dTESTSMALLSET
  781. - some warnings removed (by correcting code !)
  782. Revision 1.1 1998/05/23 01:20:56 peter
  783. + aktasmmode, aktoptprocessor, aktoutputformat
  784. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  785. + $LIBNAME to set the library name where the unit will be put in
  786. * splitted cgi386 a bit (codeseg to large for bp7)
  787. * nasm, tasm works again. nasm moved to ag386nsm.pas
  788. }