ag386nsm.pas 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868
  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 FPC}
  87. c:=comp(d);
  88. {$else}
  89. c:=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. 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. {$ifndef OLDASM}
  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_tempalloc : ;
  369. ait_section : begin
  370. if pai_section(hp)^.sec<>sec_none then
  371. begin
  372. AsmLn;
  373. AsmWriteLn('SECTION '+target_asm.secnames[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_80bit : 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. s:='';
  523. {$ifndef OLDASM}
  524. if pai386(hp)^.ops<>0 then
  525. begin
  526. if pai386(hp)^.opcode=A_CALL then
  527. s:=#9+getopstr_jmp(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)^.oper[i],pai386(hp)^.opsize,pai386(hp)^.opcode,(i=1));
  537. end;
  538. end;
  539. end;
  540. if pai386(hp)^.opcode=A_FWAIT then
  541. AsmWriteln(#9#9'DB'#9'09bh')
  542. else
  543. AsmWriteLn(#9#9+prefix+int_op2str[pai386(hp)^.opcode]+
  544. cond2str[pai386_labeled(hp)^.condition]+suffix+s);
  545. {$else}
  546. { added prefix instructions, must be on same line as opcode }
  547. if (pai386(hp)^.op1t = top_none) and
  548. ((pai386(hp)^.opcode = A_REP) or
  549. (pai386(hp)^.opcode = A_LOCK) or
  550. (pai386(hp)^.opcode = A_REPE) or
  551. (pai386(hp)^.opcode = A_REPNE)) then
  552. Begin
  553. prefix:=int_op2str[pai386(hp)^.opcode]+#9;
  554. hp:=Pai(hp^.next);
  555. { this is theorically impossible... }
  556. if hp=nil then
  557. begin
  558. s:=#9#9+prefix;
  559. AsmWriteLn(s);
  560. break;
  561. end;
  562. { nasm prefers prefix on a line alone }
  563. AsmWriteln(#9#9+prefix);
  564. prefix:='';
  565. end
  566. else
  567. prefix:= '';
  568. { A_FNSTS need the w as suffix at least for nasm}
  569. if (pai386(hp)^.opcode = A_FNSTS) then
  570. pai386(hp)^.opcode:=A_FNSTSW
  571. else
  572. if (pai386(hp)^.opcode = A_FSTS) then
  573. pai386(hp)^.opcode:=A_FSTSW;
  574. if pai386(hp)^.op1t<>top_none then
  575. begin
  576. if pai386(hp)^.opcode=A_CALL then
  577. s:=getopstr_jmp(pai386(hp)^.op1t,pai386(hp)^.op1,pai386(hp)^.op1ofs)
  578. else
  579. begin
  580. s:=getopstr(pai386(hp)^.op1t,pai386(hp)^.op1,pai386(hp)^.op1ofs,
  581. pai386(hp)^.opsize,pai386(hp)^.opcode,false);
  582. if pai386(hp)^.op3t<>top_none then
  583. begin
  584. if pai386(hp)^.op2t<>top_none then
  585. {$ifdef NO_OP3}
  586. s:=getopstr(pai386(hp)^.op2t,pointer(longint(twowords(pai386(hp)^.op2).word1)),0,
  587. pai386(hp)^.opsize,pai386(hp)^.opcode,true)+','+s;
  588. s:=getopstr(pai386(hp)^.op3t,pointer(longint(twowords(pai386(hp)^.op2).word2)),0,
  589. pai386(hp)^.opsize,pai386(hp)^.opcode,false)+','+s;
  590. {$else NO_OP3}
  591. s:=getopstr(pai386(hp)^.op2t,pai386(hp)^.op2,0,
  592. pai386(hp)^.opsize,pai386(hp)^.opcode,true)+','+s;
  593. s:=getopstr(pai386(hp)^.op3t,pai386(hp)^.op3,0,
  594. pai386(hp)^.opsize,pai386(hp)^.opcode,false)+','+s;
  595. {$endif NO_OP3}
  596. end
  597. else
  598. if pai386(hp)^.op2t<>top_none then
  599. s:=getopstr(pai386(hp)^.op2t,pai386(hp)^.op2,0,pai386(hp)^.opsize,
  600. pai386(hp)^.opcode,true)+','+s;
  601. end;
  602. s:=#9+s;
  603. end
  604. else
  605. begin
  606. { check if string instruction }
  607. { long form, otherwise may give range check errors }
  608. { in turbo pascal... }
  609. if ((pai386(hp)^.opcode = A_CMPS) or
  610. (pai386(hp)^.opcode = A_INS) or
  611. (pai386(hp)^.opcode = A_OUTS) or
  612. (pai386(hp)^.opcode = A_SCAS) or
  613. (pai386(hp)^.opcode = A_STOS) or
  614. (pai386(hp)^.opcode = A_MOVS) or
  615. (pai386(hp)^.opcode = A_LODS) or
  616. (pai386(hp)^.opcode = A_XLAT)) then
  617. Begin
  618. case pai386(hp)^.opsize of
  619. S_B: suffix:='b';
  620. S_W: suffix:='w';
  621. S_L: suffix:='d';
  622. else
  623. Message(assem_f_invalid_suffix_intel);
  624. end;
  625. end;
  626. s:='';
  627. end;
  628. if pai386(hp)^.opcode=A_FWAIT then
  629. AsmWriteln(#9#9'DB'#9'09bh')
  630. else
  631. AsmWriteLn(#9#9+prefix+int_op2str[pai386(hp)^.opcode]+suffix+s);
  632. {$endif OLDASM}
  633. end;
  634. {$ifdef GDB}
  635. ait_stabn,
  636. ait_stabs,
  637. ait_force_line,
  638. ait_stab_function_name : ;
  639. {$endif GDB}
  640. ait_cut : begin
  641. { only reset buffer if nothing has changed }
  642. if AsmSize=AsmStartSize then
  643. AsmClear
  644. else
  645. begin
  646. AsmClose;
  647. DoAssemble;
  648. if pai_cut(hp)^.EndName then
  649. IsEndFile:=true;
  650. AsmCreate;
  651. end;
  652. { avoid empty files }
  653. while assigned(hp^.next) and (pai(hp^.next)^.typ in [ait_cut,ait_section,ait_comment]) do
  654. begin
  655. if pai(hp^.next)^.typ=ait_section then
  656. lastsec:=pai_section(hp^.next)^.sec;
  657. hp:=pai(hp^.next);
  658. end;
  659. if lastsec<>sec_none then
  660. AsmWriteLn('SECTION '+target_asm.secnames[lastsec]);
  661. AsmStartSize:=AsmSize;
  662. end;
  663. ait_marker : ;
  664. else
  665. internalerror(10000);
  666. end;
  667. hp:=pai(hp^.next);
  668. end;
  669. end;
  670. procedure ti386nasmasmlist.WriteAsmList;
  671. begin
  672. {$ifdef EXTDEBUG}
  673. if assigned(current_module^.mainsource) then
  674. comment(v_info,'Start writing nasm-styled assembler output for '+current_module^.mainsource^);
  675. {$endif}
  676. LastSec:=sec_none;
  677. AsmWriteLn('BITS 32');
  678. AsmLn;
  679. countlabelref:=false;
  680. WriteTree(externals);
  681. { Nasm doesn't support stabs
  682. WriteTree(debuglist);}
  683. WriteTree(codesegment);
  684. WriteTree(datasegment);
  685. WriteTree(consts);
  686. WriteTree(rttilist);
  687. WriteTree(bsssegment);
  688. countlabelref:=true;
  689. AsmLn;
  690. {$ifdef EXTDEBUG}
  691. if assigned(current_module^.mainsource) then
  692. comment(v_info,'Done writing nasm-styled assembler output for '+current_module^.mainsource^);
  693. {$endif EXTDEBUG}
  694. end;
  695. end.
  696. {
  697. $Log$
  698. Revision 1.34 1999-05-08 19:52:34 peter
  699. + MessagePos() which is enhanced Message() function but also gets the
  700. position info
  701. * Removed comp warnings
  702. Revision 1.33 1999/05/07 00:08:48 pierre
  703. * AG386BIN cond -> OLDASM, only cosmetic
  704. Revision 1.32 1999/05/06 09:05:11 peter
  705. * generic write_float and str_float
  706. * fixed constant float conversions
  707. Revision 1.31 1999/05/04 21:44:32 florian
  708. * changes to compile it with Delphi 4.0
  709. Revision 1.30 1999/05/02 22:41:50 peter
  710. * moved section names to systems
  711. * fixed nasm,intel writer
  712. Revision 1.29 1999/05/01 13:23:59 peter
  713. * merged nasm compiler
  714. * old asm moved to oldasm/
  715. Revision 1.28 1999/04/17 22:17:06 pierre
  716. * ifdef USE_OP3 released (changed into ifndef NO_OP3)
  717. * SHRD and SHLD first operand (ATT syntax) can only be CL reg or immediate const
  718. Revision 1.27 1999/04/16 11:49:40 peter
  719. + tempalloc
  720. + -at to show temp alloc info in .s file
  721. Revision 1.26 1999/04/16 10:00:56 pierre
  722. + ifdef USE_OP3 code :
  723. added all missing op_... constructors for tai386 needed
  724. for SHRD,SHLD and IMUL code in assembler readers
  725. (check in tests/tbs0123.pp)
  726. Revision 1.25 1999/03/29 16:05:44 peter
  727. * optimizer working for ag386bin
  728. Revision 1.24 1999/03/10 13:25:44 pierre
  729. section order changed to get closer output from coff writer
  730. Revision 1.23 1999/03/04 13:55:39 pierre
  731. * some m68k fixes (still not compilable !)
  732. * new(tobj) does not give warning if tobj has no VMT !
  733. Revision 1.22 1999/03/02 02:56:11 peter
  734. + stabs support for binary writers
  735. * more fixes and missing updates from the previous commit :(
  736. Revision 1.21 1999/03/01 15:46:17 peter
  737. * ag386bin finally make cycles correct
  738. * prefixes are now also normal opcodes
  739. Revision 1.20 1999/02/26 00:48:14 peter
  740. * assembler writers fixed for ag386bin
  741. Revision 1.19 1999/02/25 21:02:19 peter
  742. * ag386bin updates
  743. + coff writer
  744. Revision 1.18 1999/02/22 02:15:00 peter
  745. * updates for ag386bin
  746. Revision 1.17 1998/12/20 16:21:23 peter
  747. * smartlinking doesn't crash anymore
  748. Revision 1.16 1998/12/16 00:27:18 peter
  749. * removed some obsolete version checks
  750. Revision 1.15 1998/12/01 11:19:39 peter
  751. * fixed range problem with in [tasmop]
  752. Revision 1.14 1998/11/30 09:42:56 pierre
  753. * some range check bugs fixed (still not working !)
  754. + added DLL writing support for win32 (also accepts variables)
  755. + TempAnsi for code that could be used for Temporary ansi strings
  756. handling
  757. Revision 1.13 1998/11/17 00:26:10 peter
  758. * fixed for $H+
  759. Revision 1.12 1998/11/12 11:19:34 pierre
  760. * fix for first line of function break
  761. Revision 1.11 1998/10/12 12:20:42 pierre
  762. + added tai_const_symbol_offset
  763. for r : pointer = @var.field;
  764. * better message for different arg names on implementation
  765. of function
  766. Revision 1.10 1998/10/06 17:16:34 pierre
  767. * some memory leaks fixed (thanks to Peter for heaptrc !)
  768. Revision 1.9 1998/10/01 20:19:07 jonas
  769. + ait_marker support
  770. Revision 1.8 1998/09/20 17:11:22 jonas
  771. * released REGALLOC
  772. Revision 1.7 1998/08/11 14:01:43 peter
  773. * fixed fwait bug using direct opcode
  774. Revision 1.6 1998/08/10 15:49:39 peter
  775. * small fixes for 0.99.5
  776. Revision 1.5 1998/08/08 10:19:18 florian
  777. * small fixes to write the extended type correct
  778. Revision 1.4 1998/06/05 17:46:03 peter
  779. * tp doesn't like comp() typecast
  780. Revision 1.3 1998/05/28 17:24:27 peter
  781. - $R- for tp to solve range errors with in[]
  782. Revision 1.2 1998/05/25 17:11:37 pierre
  783. * firstpasscount bug fixed
  784. now all is already set correctly the first time
  785. under EXTDEBUG try -gp to skip all other firstpasses
  786. it works !!
  787. * small bug fixes
  788. - for smallsets with -dTESTSMALLSET
  789. - some warnings removed (by correcting code !)
  790. Revision 1.1 1998/05/23 01:20:56 peter
  791. + aktasmmode, aktoptprocessor, aktoutputformat
  792. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  793. + $LIBNAME to set the library name where the unit will be put in
  794. * splitted cgi386 a bit (codeseg to large for bp7)
  795. * nasm, tasm works again. nasm moved to ag386nsm.pas
  796. }