ag386nsm.pas 31 KB

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