ag386nsm.pas 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839
  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) or ((t and OT_FPUREG)=OT_FPUREG) then
  149. getopstr:=int_nasmreg2str[tregister(o)]
  150. else
  151. if (t and OT_SYMBOL)=OT_SYMBOL then
  152. begin
  153. hs:='dword '+preference(o)^.symbol^.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) or ((t and OT_FPUREG)=OT_FPUREG) then
  206. getopstr_jmp:=int_nasmreg2str[tregister(o)]
  207. else
  208. if (t and OT_SYMBOL)=OT_SYMBOL then
  209. begin
  210. hs:=preference(o)^.symbol^.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',
  315. '.idata2','.idata4','.idata5','.idata6','.idata7','.edata',
  316. '.stab','.stabstr','');
  317. Function PadTabs(const p:string;addch:char):string;
  318. var
  319. s : string;
  320. i : longint;
  321. begin
  322. i:=length(p);
  323. if addch<>#0 then
  324. begin
  325. inc(i);
  326. s:=p+addch;
  327. end
  328. else
  329. s:=p;
  330. if i<8 then
  331. PadTabs:=s+#9#9
  332. else
  333. PadTabs:=s+#9;
  334. end;
  335. procedure ti386nasmasmlist.WriteTree(p:paasmoutput);
  336. type
  337. twowords=record
  338. word1,word2:word;
  339. end;
  340. var
  341. s,
  342. prefix,
  343. suffix : string;
  344. hp : pai;
  345. counter,
  346. lines,
  347. i,j,l : longint;
  348. op : tasmop;
  349. consttyp : tait;
  350. found,
  351. quoted : boolean;
  352. {$ifdef AG386Bin}
  353. sep : char;
  354. {$endif}
  355. begin
  356. if not assigned(p) then
  357. exit;
  358. hp:=pai(p^.first);
  359. while assigned(hp) do
  360. begin
  361. case hp^.typ of
  362. ait_comment : Begin
  363. AsmWrite(target_asm.comment);
  364. AsmWritePChar(pai_asm_comment(hp)^.str);
  365. AsmLn;
  366. End;
  367. ait_regalloc,
  368. ait_regdealloc :;
  369. ait_section : begin
  370. if pai_section(hp)^.sec<>sec_none then
  371. begin
  372. AsmLn;
  373. AsmWriteLn('SECTION '+ait_section2nasmstr[pai_section(hp)^.sec]);
  374. end;
  375. LastSec:=pai_section(hp)^.sec;
  376. end;
  377. ait_align : AsmWriteLn(#9'ALIGN '+tostr(pai_align(hp)^.aligntype));
  378. ait_external : AsmWriteLn('EXTERN '+pai_external(hp)^.sym^.name);
  379. ait_datablock : begin
  380. if pai_datablock(hp)^.is_global then
  381. AsmWriteLn(#9'GLOBAL '+pai_datablock(hp)^.sym^.name);
  382. AsmWriteLn(PadTabs(pai_datablock(hp)^.sym^.name,':')+'RESB'#9+tostr(pai_datablock(hp)^.size));
  383. end;
  384. ait_const_32bit,
  385. ait_const_8bit,
  386. ait_const_16bit : begin
  387. AsmWrite(ait_const2str[hp^.typ]+tostr(pai_const(hp)^.value));
  388. consttyp:=hp^.typ;
  389. l:=0;
  390. repeat
  391. found:=(not (Pai(hp^.next)=nil)) and (Pai(hp^.next)^.typ=consttyp);
  392. if found then
  393. begin
  394. hp:=Pai(hp^.next);
  395. s:=','+tostr(pai_const(hp)^.value);
  396. AsmWrite(s);
  397. inc(l,length(s));
  398. end;
  399. until (not found) or (l>line_length);
  400. AsmLn;
  401. end;
  402. ait_const_symbol : begin
  403. AsmWriteLn(#9#9'DD'#9+pai_const_symbol(hp)^.sym^.name);
  404. if pai_const_symbol(hp)^.offset>0 then
  405. AsmWrite('+'+tostr(pai_const_symbol(hp)^.offset))
  406. else if pai_const_symbol(hp)^.offset<0 then
  407. AsmWrite(tostr(pai_const_symbol(hp)^.offset));
  408. AsmLn;
  409. end;
  410. ait_const_rva : begin
  411. AsmWriteLn(#9#9'RVA'#9+pai_const_symbol(hp)^.sym^.name);
  412. end;
  413. ait_real_32bit : AsmWriteLn(#9#9'DD'#9+double2str(pai_single(hp)^.value));
  414. ait_real_64bit : AsmWriteLn(#9#9'DQ'#9+double2str(pai_double(hp)^.value));
  415. ait_real_extended : AsmWriteLn(#9#9'DT'#9+extended2str(pai_extended(hp)^.value));
  416. ait_comp : AsmWriteLn(#9#9'DQ'#9+comp2str(pai_extended(hp)^.value));
  417. ait_string : begin
  418. counter := 0;
  419. lines := pai_string(hp)^.len div line_length;
  420. { separate lines in different parts }
  421. if pai_string(hp)^.len > 0 then
  422. Begin
  423. for j := 0 to lines-1 do
  424. begin
  425. AsmWrite(#9#9'DB'#9);
  426. quoted:=false;
  427. for i:=counter to counter+line_length do
  428. begin
  429. { it is an ascii character. }
  430. if (ord(pai_string(hp)^.str[i])>31) and
  431. (ord(pai_string(hp)^.str[i])<128) and
  432. (pai_string(hp)^.str[i]<>'"') then
  433. begin
  434. if not(quoted) then
  435. begin
  436. if i>counter then
  437. AsmWrite(',');
  438. AsmWrite('"');
  439. end;
  440. AsmWrite(pai_string(hp)^.str[i]);
  441. quoted:=true;
  442. end { if > 31 and < 128 and ord('"') }
  443. else
  444. begin
  445. if quoted then
  446. AsmWrite('"');
  447. if i>counter then
  448. AsmWrite(',');
  449. quoted:=false;
  450. AsmWrite(tostr(ord(pai_string(hp)^.str[i])));
  451. end;
  452. end; { end for i:=0 to... }
  453. if quoted then AsmWrite('"');
  454. AsmWrite(target_os.newline);
  455. counter := counter+line_length;
  456. end; { end for j:=0 ... }
  457. { do last line of lines }
  458. AsmWrite(#9#9'DB'#9);
  459. quoted:=false;
  460. for i:=counter to pai_string(hp)^.len-1 do
  461. begin
  462. { it is an ascii character. }
  463. if (ord(pai_string(hp)^.str[i])>31) and
  464. (ord(pai_string(hp)^.str[i])<128) and
  465. (pai_string(hp)^.str[i]<>'"') then
  466. begin
  467. if not(quoted) then
  468. begin
  469. if i>counter then
  470. AsmWrite(',');
  471. AsmWrite('"');
  472. end;
  473. AsmWrite(pai_string(hp)^.str[i]);
  474. quoted:=true;
  475. end { if > 31 and < 128 and " }
  476. else
  477. begin
  478. if quoted then
  479. AsmWrite('"');
  480. if i>counter then
  481. AsmWrite(',');
  482. quoted:=false;
  483. AsmWrite(tostr(ord(pai_string(hp)^.str[i])));
  484. end;
  485. end; { end for i:=0 to... }
  486. if quoted then
  487. AsmWrite('"');
  488. end;
  489. AsmLn;
  490. end;
  491. ait_label : begin
  492. if pai_label(hp)^.l^.is_used then
  493. AsmWriteLn(lab2str(pai_label(hp)^.l)+':');
  494. end;
  495. ait_direct : begin
  496. AsmWritePChar(pai_direct(hp)^.str);
  497. AsmLn;
  498. end;
  499. ait_labeled_instruction :
  500. begin
  501. op:=pai386_labeled(hp)^.opcode;
  502. if not((op=A_JMP) or (op=A_LOOP) or (op=A_LOOPZ) or
  503. (op=A_LOOPE) or (op=A_LOOPNZ) or (op=A_LOOPNE) or
  504. (op=A_JCXZ) or (op=A_JECXZ)) then
  505. AsmWriteLn(#9#9+int_op2str[pai386_labeled(hp)^.opcode]+#9+'near '+lab2str(pai386_labeled(hp)^.lab))
  506. else
  507. AsmWriteLn(#9#9+int_op2str[pai386_labeled(hp)^.opcode]+#9+lab2str(pai386_labeled(hp)^.lab));
  508. end;
  509. ait_symbol : begin
  510. if pai_symbol(hp)^.is_global then
  511. AsmWriteLn(#9'GLOBAL '+pai_symbol(hp)^.sym^.name);
  512. AsmWrite(pai_symbol(hp)^.sym^.name);
  513. if assigned(hp^.next) and not(pai(hp^.next)^.typ in
  514. [ait_const_32bit,ait_const_16bit,ait_const_8bit,
  515. ait_const_symbol,ait_const_rva,
  516. ait_real_64bit,ait_string]) then
  517. AsmWriteLn(':')
  518. end;
  519. ait_instruction : begin
  520. suffix:='';
  521. prefix:='';
  522. {$ifdef AG386BIN}
  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]+
  568. cond2str[pai386_labeled(hp)^.condition]+suffix+s);
  569. {$else}
  570. { added prefix instructions, must be on same line as opcode }
  571. if (pai386(hp)^.op1t = top_none) and
  572. ((pai386(hp)^.opcode = A_REP) or
  573. (pai386(hp)^.opcode = A_LOCK) or
  574. (pai386(hp)^.opcode = A_REPE) or
  575. (pai386(hp)^.opcode = A_REPNE)) then
  576. Begin
  577. prefix:=int_op2str[pai386(hp)^.opcode]+#9;
  578. hp:=Pai(hp^.next);
  579. { this is theorically impossible... }
  580. if hp=nil then
  581. begin
  582. s:=#9#9+prefix;
  583. AsmWriteLn(s);
  584. break;
  585. end;
  586. { nasm prefers prefix on a line alone }
  587. AsmWriteln(#9#9+prefix);
  588. prefix:='';
  589. end
  590. else
  591. prefix:= '';
  592. { A_FNSTS need the w as suffix at least for nasm}
  593. if (pai386(hp)^.opcode = A_FNSTS) then
  594. pai386(hp)^.opcode:=A_FNSTSW
  595. else
  596. if (pai386(hp)^.opcode = A_FSTS) then
  597. pai386(hp)^.opcode:=A_FSTSW;
  598. if pai386(hp)^.op1t<>top_none then
  599. begin
  600. if pai386(hp)^.opcode=A_CALL then
  601. s:=getopstr_jmp(pai386(hp)^.op1t,pai386(hp)^.op1,pai386(hp)^.op1ofs)
  602. else
  603. begin
  604. s:=getopstr(pai386(hp)^.op1t,pai386(hp)^.op1,pai386(hp)^.op1ofs,
  605. pai386(hp)^.opsize,pai386(hp)^.opcode,false);
  606. if pai386(hp)^.op3t<>top_none then
  607. begin
  608. if pai386(hp)^.op2t<>top_none then
  609. s:=getopstr(pai386(hp)^.op2t,pointer(longint(twowords(pai386(hp)^.op2).word1)),0,
  610. pai386(hp)^.opsize,pai386(hp)^.opcode,true)+','+s;
  611. s:=getopstr(pai386(hp)^.op3t,pointer(longint(twowords(pai386(hp)^.op2).word2)),0,
  612. pai386(hp)^.opsize,pai386(hp)^.opcode,false)+','+s;
  613. end
  614. else
  615. if pai386(hp)^.op2t<>top_none then
  616. s:=getopstr(pai386(hp)^.op2t,pai386(hp)^.op2,0,pai386(hp)^.opsize,
  617. pai386(hp)^.opcode,true)+','+s;
  618. end;
  619. s:=#9+s;
  620. end
  621. else
  622. begin
  623. { check if string instruction }
  624. { long form, otherwise may give range check errors }
  625. { in turbo pascal... }
  626. if ((pai386(hp)^.opcode = A_CMPS) or
  627. (pai386(hp)^.opcode = A_INS) or
  628. (pai386(hp)^.opcode = A_OUTS) or
  629. (pai386(hp)^.opcode = A_SCAS) or
  630. (pai386(hp)^.opcode = A_STOS) or
  631. (pai386(hp)^.opcode = A_MOVS) or
  632. (pai386(hp)^.opcode = A_LODS) or
  633. (pai386(hp)^.opcode = A_XLAT)) then
  634. Begin
  635. case pai386(hp)^.opsize of
  636. S_B: suffix:='b';
  637. S_W: suffix:='w';
  638. S_L: suffix:='d';
  639. else
  640. Message(assem_f_invalid_suffix_intel);
  641. end;
  642. end;
  643. s:='';
  644. end;
  645. if pai386(hp)^.opcode=A_FWAIT then
  646. AsmWriteln(#9#9'DB'#9'09bh')
  647. else
  648. AsmWriteLn(#9#9+prefix+int_op2str[pai386(hp)^.opcode]+suffix+s);
  649. {$endif AG386BIN}
  650. end;
  651. {$ifdef GDB}
  652. ait_stabn,
  653. ait_stabs,
  654. ait_force_line,
  655. ait_stab_function_name : ;
  656. {$endif GDB}
  657. ait_cut : begin
  658. { only reset buffer if nothing has changed }
  659. if AsmSize=AsmStartSize then
  660. AsmClear
  661. else
  662. begin
  663. AsmClose;
  664. DoAssemble;
  665. if pai_cut(hp)^.EndName then
  666. IsEndFile:=true;
  667. AsmCreate;
  668. end;
  669. { avoid empty files }
  670. while assigned(hp^.next) and (pai(hp^.next)^.typ in [ait_cut,ait_section,ait_comment]) do
  671. begin
  672. if pai(hp^.next)^.typ=ait_section then
  673. lastsec:=pai_section(hp^.next)^.sec;
  674. hp:=pai(hp^.next);
  675. end;
  676. if lastsec<>sec_none then
  677. AsmWriteLn('SECTION '+ait_section2nasmstr[lastsec]);
  678. AsmStartSize:=AsmSize;
  679. end;
  680. ait_marker : ;
  681. else
  682. internalerror(10000);
  683. end;
  684. hp:=pai(hp^.next);
  685. end;
  686. end;
  687. procedure ti386nasmasmlist.WriteAsmList;
  688. begin
  689. {$ifdef EXTDEBUG}
  690. if assigned(current_module^.mainsource) then
  691. comment(v_info,'Start writing nasm-styled assembler output for '+current_module^.mainsource^);
  692. {$endif}
  693. LastSec:=sec_none;
  694. AsmWriteLn('BITS 32');
  695. AsmLn;
  696. countlabelref:=false;
  697. WriteTree(externals);
  698. { Nasm doesn't support stabs
  699. WriteTree(debuglist);}
  700. WriteTree(codesegment);
  701. WriteTree(datasegment);
  702. WriteTree(consts);
  703. WriteTree(rttilist);
  704. WriteTree(bsssegment);
  705. countlabelref:=true;
  706. AsmLn;
  707. {$ifdef EXTDEBUG}
  708. if assigned(current_module^.mainsource) then
  709. comment(v_info,'Done writing nasm-styled assembler output for '+current_module^.mainsource^);
  710. {$endif EXTDEBUG}
  711. end;
  712. end.
  713. {
  714. $Log$
  715. Revision 1.22 1999-03-02 02:56:11 peter
  716. + stabs support for binary writers
  717. * more fixes and missing updates from the previous commit :(
  718. Revision 1.21 1999/03/01 15:46:17 peter
  719. * ag386bin finally make cycles correct
  720. * prefixes are now also normal opcodes
  721. Revision 1.20 1999/02/26 00:48:14 peter
  722. * assembler writers fixed for ag386bin
  723. Revision 1.19 1999/02/25 21:02:19 peter
  724. * ag386bin updates
  725. + coff writer
  726. Revision 1.18 1999/02/22 02:15:00 peter
  727. * updates for ag386bin
  728. Revision 1.17 1998/12/20 16:21:23 peter
  729. * smartlinking doesn't crash anymore
  730. Revision 1.16 1998/12/16 00:27:18 peter
  731. * removed some obsolete version checks
  732. Revision 1.15 1998/12/01 11:19:39 peter
  733. * fixed range problem with in [tasmop]
  734. Revision 1.14 1998/11/30 09:42:56 pierre
  735. * some range check bugs fixed (still not working !)
  736. + added DLL writing support for win32 (also accepts variables)
  737. + TempAnsi for code that could be used for Temporary ansi strings
  738. handling
  739. Revision 1.13 1998/11/17 00:26:10 peter
  740. * fixed for $H+
  741. Revision 1.12 1998/11/12 11:19:34 pierre
  742. * fix for first line of function break
  743. Revision 1.11 1998/10/12 12:20:42 pierre
  744. + added tai_const_symbol_offset
  745. for r : pointer = @var.field;
  746. * better message for different arg names on implementation
  747. of function
  748. Revision 1.10 1998/10/06 17:16:34 pierre
  749. * some memory leaks fixed (thanks to Peter for heaptrc !)
  750. Revision 1.9 1998/10/01 20:19:07 jonas
  751. + ait_marker support
  752. Revision 1.8 1998/09/20 17:11:22 jonas
  753. * released REGALLOC
  754. Revision 1.7 1998/08/11 14:01:43 peter
  755. * fixed fwait bug using direct opcode
  756. Revision 1.6 1998/08/10 15:49:39 peter
  757. * small fixes for 0.99.5
  758. Revision 1.5 1998/08/08 10:19:18 florian
  759. * small fixes to write the extended type correct
  760. Revision 1.4 1998/06/05 17:46:03 peter
  761. * tp doesn't like comp() typecast
  762. Revision 1.3 1998/05/28 17:24:27 peter
  763. - $R- for tp to solve range errors with in[]
  764. Revision 1.2 1998/05/25 17:11:37 pierre
  765. * firstpasscount bug fixed
  766. now all is already set correctly the first time
  767. under EXTDEBUG try -gp to skip all other firstpasses
  768. it works !!
  769. * small bug fixes
  770. - for smallsets with -dTESTSMALLSET
  771. - some warnings removed (by correcting code !)
  772. Revision 1.1 1998/05/23 01:20:56 peter
  773. + aktasmmode, aktoptprocessor, aktoutputformat
  774. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  775. + $LIBNAME to set the library name where the unit will be put in
  776. * splitted cgi386 a bit (codeseg to large for bp7)
  777. * nasm, tasm works again. nasm moved to ag386nsm.pas
  778. }