ag386nsm.pas 30 KB

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