ag68kgas.pas 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  1. {
  2. $Id$
  3. Copyright (c) 1998 by the FPC development team
  4. This unit implements an asmoutput class for MOTOROLA syntax with
  5. Motorola 68000 (for GAS v2.52 AND HIGER)
  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. { R- Necessary for the in [] }
  20. {$ifdef TP}
  21. {$N+,E+,R-}
  22. {$endif}
  23. unit ag68kgas;
  24. interface
  25. uses cobjects,aasm,assemble;
  26. type
  27. pm68kgasasmlist=^tm68kgasasmlist;
  28. tm68kgasasmlist = object(tasmlist)
  29. procedure WriteTree(p:paasmoutput);virtual;
  30. procedure WriteAsmList;virtual;
  31. {$ifdef GDB}
  32. procedure WriteFileLineInfo(var fileinfo : tfileposinfo);
  33. {$endif}
  34. end;
  35. implementation
  36. uses
  37. globtype,systems,
  38. dos,globals,m68k,
  39. strings,files,verbose
  40. {$ifdef GDB}
  41. ,gdb
  42. {$endif GDB}
  43. ;
  44. const
  45. line_length = 70;
  46. var
  47. {$ifdef GDB}
  48. n_line : byte; { different types of source lines }
  49. linecount,
  50. includecount : longint;
  51. funcname : pchar;
  52. stabslastfileinfo : tfileposinfo;
  53. {$endif}
  54. lastsec : tsection; { last section type written }
  55. lastsecidx,
  56. lastfileindex,
  57. lastline : longint;
  58. function double2str(d : double) : string;
  59. var
  60. hs : string;
  61. begin
  62. str(d,hs);
  63. { replace space with + }
  64. if hs[1]=' ' then
  65. hs[1]:='+';
  66. double2str:='0d'+hs
  67. end;
  68. (* TO SUPPORT SOONER OR LATER!!!
  69. function comp2str(d : bestreal) : string;
  70. type
  71. pdouble = ^double;
  72. var
  73. c : comp;
  74. dd : pdouble;
  75. begin
  76. {$ifdef TP}
  77. c:=d;
  78. {$else}
  79. c:=comp(d);
  80. {$endif}
  81. dd:=pdouble(@c); { this makes a bitwise copy of c into a double }
  82. comp2str:=double2str(dd^);
  83. end; *)
  84. function getreferencestring(const ref : treference) : string;
  85. var
  86. s,basestr,indexstr : string;
  87. begin
  88. s:='';
  89. if ref.isintvalue then
  90. s:='#'+tostr(ref.offset)
  91. else
  92. with ref do
  93. begin
  94. if target_info.target=target_m68k_PalmOS then
  95. begin
  96. basestr:=gasPalmOS_reg2str[base];
  97. indexstr:=gasPalmOS_reg2str[index];
  98. end
  99. else
  100. begin
  101. basestr:=gas_reg2str[base];
  102. indexstr:=gas_reg2str[index];
  103. end;
  104. if assigned(symbol) then
  105. s:=s+symbol^;
  106. if offset<0 then s:=s+tostr(offset)
  107. else if (offset>0) then
  108. begin
  109. if (symbol=nil) then s:=tostr(offset)
  110. else s:=s+'+'+tostr(offset);
  111. end;
  112. if (index<>R_NO) and (base=R_NO) and (direction=dir_none) then
  113. begin
  114. if (scalefactor = 1) or (scalefactor = 0) then
  115. s:=s+'(,'+indexstr+'.l)'
  116. else
  117. s:=s+'(,'+indexstr+'.l*'+tostr(scalefactor)+')'
  118. end
  119. else if (index=R_NO) and (base<>R_NO) and (direction=dir_inc) then
  120. begin
  121. if (scalefactor = 1) or (scalefactor = 0) then
  122. s:=s+'('+basestr+')+'
  123. else
  124. InternalError(10002);
  125. end
  126. else if (index=R_NO) and (base<>R_NO) and (direction=dir_dec) then
  127. begin
  128. if (scalefactor = 1) or (scalefactor = 0) then
  129. s:=s+'-('+basestr+')'
  130. else
  131. InternalError(10003);
  132. end
  133. else if (index=R_NO) and (base<>R_NO) and (direction=dir_none) then
  134. begin
  135. s:=s+'('+basestr+')'
  136. end
  137. else if (index<>R_NO) and (base<>R_NO) and (direction=dir_none) then
  138. begin
  139. if (scalefactor = 1) or (scalefactor = 0) then
  140. s:=s+'('+basestr+','+indexstr+'.l)'
  141. else
  142. s:=s+'('+basestr+','+indexstr+'.l*'+tostr(scalefactor)+')';
  143. end;
  144. end; { end with }
  145. getreferencestring:=s;
  146. end;
  147. function getopstr(t : byte;o : pointer) : string;
  148. var
  149. hs : string;
  150. i: tregister;
  151. begin
  152. case t of
  153. top_reg : if target_info.target=target_m68k_PalmOS then
  154. getopstr:=gasPalmOS_reg2str[tregister(o)]
  155. else
  156. getopstr:=gas_reg2str[tregister(o)];
  157. top_ref : getopstr:=getreferencestring(preference(o)^);
  158. top_reglist : begin
  159. hs:='';
  160. for i:=R_NO to R_FPSR do
  161. begin
  162. if i in tregisterlist(o^) then
  163. hs:=hs+gas_reg2str[i]+'/';
  164. end;
  165. delete(hs,length(hs),1);
  166. getopstr := hs;
  167. end;
  168. top_const : getopstr:='#'+tostr(longint(o));
  169. top_symbol :
  170. { compare with i386, where a symbol is considered }
  171. { a constant. }
  172. begin
  173. hs[0]:=chr(strlen(pchar(pcsymbol(o)^.symbol)));
  174. move(pchar(pcsymbol(o)^.symbol)^,hs[1],byte(hs[0]));
  175. { inc(byte(hs[0]));}
  176. if pcsymbol(o)^.offset>0 then
  177. hs:=hs+'+'+tostr(pcsymbol(o)^.offset)
  178. else if pcsymbol(o)^.offset<0 then
  179. hs:=hs+tostr(pcsymbol(o)^.offset);
  180. getopstr:=hs;
  181. end;
  182. else internalerror(10001);
  183. end;
  184. end;
  185. function getopstr_jmp(t : byte;o : pointer) : string;
  186. var
  187. hs : string;
  188. begin
  189. case t of
  190. top_reg : getopstr_jmp:=gas_reg2str[tregister(o)];
  191. top_ref : getopstr_jmp:=getreferencestring(preference(o)^);
  192. top_const : getopstr_jmp:=tostr(longint(o));
  193. top_symbol : begin
  194. hs[0]:=chr(strlen(pchar(pcsymbol(o)^.symbol)));
  195. move(pchar(pcsymbol(o)^.symbol)^,hs[1],byte(hs[0]));
  196. if pcsymbol(o)^.offset>0 then
  197. hs:=hs+'+'+tostr(pcsymbol(o)^.offset)
  198. else if pcsymbol(o)^.offset<0 then
  199. hs:=hs+tostr(pcsymbol(o)^.offset);
  200. getopstr_jmp:=hs;
  201. end;
  202. else internalerror(10001);
  203. end;
  204. end;
  205. {****************************************************************************
  206. T68kGASASMOUTPUT
  207. ****************************************************************************}
  208. const
  209. ait_const2str:array[ait_const_32bit..ait_const_8bit] of string[8]=
  210. (#9'.long'#9,#9'.short'#9,#9'.byte'#9);
  211. function ait_section2str(s:tsection):string;
  212. begin
  213. case s of
  214. sec_code : ait_section2str:='.text';
  215. sec_data : ait_section2str:='.data';
  216. sec_bss : ait_section2str:='.bss';
  217. else
  218. ait_section2str:='';
  219. end;
  220. LastSec:=s;
  221. end;
  222. {$ifdef GDB}
  223. var
  224. curr_n : byte;
  225. infile : pinputfile;
  226. procedure tm68kgasasmlist.WriteFileLineInfo(var fileinfo : tfileposinfo);
  227. begin
  228. if not (cs_debuginfo in aktmoduleswitches) then
  229. exit;
  230. { file changed ? (must be before line info) }
  231. if lastfileindex<>fileinfo.fileindex then
  232. begin
  233. infile:=current_module^.sourcefiles^.get_file(fileinfo.fileindex);
  234. if includecount=0 then
  235. curr_n:=n_sourcefile
  236. else
  237. curr_n:=n_includefile;
  238. if (infile^.path^<>'') then
  239. begin
  240. AsmWriteLn(#9'.stabs "'+lower(BsToSlash(FixPath(infile^.path^,false)))+'",'+
  241. tostr(curr_n)+',0,0,'+'Ltext'+ToStr(IncludeCount));
  242. end;
  243. AsmWriteLn(#9'.stabs "'+lower(FixFileName(infile^.name^))+'",'+
  244. tostr(curr_n)+',0,0,'+'Ltext'+ToStr(IncludeCount));
  245. AsmWriteLn('Ltext'+ToStr(IncludeCount)+':');
  246. inc(includecount);
  247. lastfileindex:=fileinfo.fileindex;
  248. end;
  249. { line changed ? }
  250. if (fileinfo.line<>lastline) and (fileinfo.line<>0) then
  251. begin
  252. if (n_line=n_textline) and assigned(funcname) and
  253. (target_os.use_function_relative_addresses) then
  254. begin
  255. AsmWriteLn(target_asm.labelprefix+'l'+tostr(linecount)+':');
  256. AsmWrite(#9'.stabn '+tostr(n_line)+',0,'+tostr(fileinfo.line)+','+
  257. target_asm.labelprefix+'l'+tostr(linecount)+' - ');
  258. AsmWritePChar(FuncName);
  259. AsmLn;
  260. inc(linecount);
  261. end
  262. else
  263. AsmWriteLn(#9'.stabd'#9+tostr(n_line)+',0,'+tostr(fileinfo.line));
  264. lastline:=fileinfo.line;
  265. end;
  266. end;
  267. {$endif GDB}
  268. procedure tm68kgasasmlist.WriteTree(p:paasmoutput);
  269. type
  270. twowords=record
  271. word1,word2:word;
  272. end;
  273. textendedarray = array[0..9] of byte; { last longint will be and $ffff }
  274. var
  275. hp : pai;
  276. ch : char;
  277. consttyp : tait;
  278. s : string;
  279. pos,l,i : longint;
  280. found : boolean;
  281. begin
  282. if not assigned(p) then
  283. exit;
  284. hp:=pai(p^.first);
  285. while assigned(hp) do
  286. begin
  287. { write debugger informations }
  288. {$ifdef GDB}
  289. if cs_debuginfo in aktmoduleswitches then
  290. begin
  291. if not (hp^.typ in [ait_external,ait_stabn,ait_stabs,
  292. ait_label,ait_cut,ait_align,ait_stab_function_name]) then
  293. WriteFileLineInfo(hp^.fileinfo);
  294. end;
  295. {$endif GDB}
  296. case hp^.typ of
  297. ait_external : ; { external is ignored }
  298. ait_comment : Begin
  299. AsmWrite(target_asm.comment);
  300. AsmWritePChar(pai_asm_comment(hp)^.str);
  301. AsmLn;
  302. End;
  303. {$ifdef DREGALLOC}
  304. ait_regalloc : AsmWriteLn(target_asm.comment+'Register '+att_reg2str[pairegalloc(hp)^.reg]+' allocated');
  305. ait_regdealloc : AsmWriteLn(target_asm.comment+'Register '+att_reg2str[pairegalloc(hp)^.reg]+' released');
  306. {$endif DREGALLOC}
  307. ait_align : AsmWriteLn(#9'.align '+tostr(pai_align(hp)^.aligntype));
  308. ait_section : begin
  309. if pai_section(hp)^.sec<>sec_none then
  310. begin
  311. AsmLn;
  312. AsmWrite(ait_section2str(pai_section(hp)^.sec));
  313. if pai_section(hp)^.idataidx>0 then
  314. AsmWrite('$'+tostr(pai_section(hp)^.idataidx));
  315. AsmLn;
  316. {$ifdef GDB}
  317. case pai_section(hp)^.sec of
  318. sec_code : n_line:=n_textline;
  319. sec_data : n_line:=n_dataline;
  320. sec_bss : n_line:=n_bssline;
  321. end;
  322. {$endif GDB}
  323. end;
  324. LastSec:=pai_section(hp)^.sec;
  325. end;
  326. ait_datablock : begin
  327. { ------------------------------------------------------- }
  328. { ----------- ALIGNMENT FOR ANY NON-BYTE VALUE ---------- }
  329. { ------------- REQUIREMENT FOR 680x0 ------------------- }
  330. { ------------------------------------------------------- }
  331. if pai_datablock(hp)^.size <> 1 then
  332. begin
  333. if not(cs_littlesize in aktglobalswitches) then
  334. AsmWriteLn(#9#9'.align 4')
  335. else
  336. AsmWriteLn(#9#9'.align 2');
  337. end;
  338. if pai_datablock(hp)^.is_global then
  339. AsmWrite(#9'.comm'#9)
  340. else
  341. AsmWrite(#9'.lcomm'#9);
  342. AsmWriteLn(StrPas(pai_datablock(hp)^.name)+','+tostr(pai_datablock(hp)^.size));
  343. end;
  344. ait_const_32bit, { alignment is required for 16/32 bit data! }
  345. ait_const_16bit: begin
  346. AsmWrite(ait_const2str[hp^.typ]+tostr(pai_const(hp)^.value));
  347. consttyp:=hp^.typ;
  348. l:=0;
  349. repeat
  350. found:=(not (Pai(hp^.next)=nil)) and (Pai(hp^.next)^.typ=consttyp);
  351. if found then
  352. begin
  353. hp:=Pai(hp^.next);
  354. s:=','+tostr(pai_const(hp)^.value);
  355. AsmWrite(s);
  356. inc(l,length(s));
  357. end;
  358. until (not found) or (l>line_length);
  359. AsmLn;
  360. end;
  361. ait_const_8bit : begin
  362. AsmWrite(ait_const2str[hp^.typ]+tostr(pai_const(hp)^.value));
  363. consttyp:=hp^.typ;
  364. l:=0;
  365. repeat
  366. found:=(not (Pai(hp^.next)=nil)) and (Pai(hp^.next)^.typ=consttyp);
  367. if found then
  368. begin
  369. hp:=Pai(hp^.next);
  370. s:=','+tostr(pai_const(hp)^.value);
  371. AsmWrite(s);
  372. inc(l,length(s));
  373. end;
  374. until (not found) or (l>line_length);
  375. AsmLn;
  376. end;
  377. ait_const_symbol : Begin
  378. AsmWriteLn(#9'.long'#9+StrPas(pchar(pai_const(hp)^.value)));
  379. end;
  380. ait_const_symbol_offset :
  381. Begin
  382. AsmWrite(#9'.long'#9);
  383. AsmWritePChar(pai_const_symbol_offset(hp)^.name);
  384. if pai_const_symbol_offset(hp)^.offset>0 then
  385. AsmWrite('+'+tostr(pai_const_symbol_offset(hp)^.offset))
  386. else if pai_const_symbol_offset(hp)^.offset<0 then
  387. AsmWrite(tostr(pai_const_symbol_offset(hp)^.offset));
  388. AsmLn;
  389. end;
  390. ait_real_64bit : Begin
  391. AsmWriteLn(#9'.double'#9+double2str(pai_double(hp)^.value));
  392. end;
  393. ait_real_32bit : Begin
  394. AsmWriteLn(#9'.single'#9+double2str(pai_single(hp)^.value));
  395. end;
  396. ait_real_extended : Begin
  397. AsmWriteLn(#9'.extend'#9+double2str(pai_extended(hp)^.value));
  398. { comp type is difficult to write so use double }
  399. end;
  400. { TO SUPPORT SOONER OR LATER!!!
  401. ait_comp : Begin
  402. AsmWriteLn(#9'.double'#9+comp2str(pai_extended(hp)^.value));
  403. end; }
  404. ait_direct : begin
  405. AsmWritePChar(pai_direct(hp)^.str);
  406. AsmLn;
  407. {$IfDef GDB}
  408. if strpos(pai_direct(hp)^.str,'.data')<>nil then
  409. n_line:=n_dataline
  410. else if strpos(pai_direct(hp)^.str,'.text')<>nil then
  411. n_line:=n_textline
  412. else if strpos(pai_direct(hp)^.str,'.bss')<>nil then
  413. n_line:=n_bssline;
  414. {$endif GDB}
  415. end;
  416. ait_string : begin
  417. pos:=0;
  418. for i:=1 to pai_string(hp)^.len do
  419. begin
  420. if pos=0 then
  421. begin
  422. AsmWrite(#9'.ascii'#9'"');
  423. pos:=20;
  424. end;
  425. ch:=pai_string(hp)^.str[i-1];
  426. case ch of
  427. #0, {This can't be done by range, because a bug in FPC}
  428. #1..#31,
  429. #128..#255 : s:='\'+tostr(ord(ch) shr 6)+tostr((ord(ch) and 63) shr 3)+tostr(ord(ch) and 7);
  430. '"' : s:='\"';
  431. '\' : s:='\\';
  432. else
  433. s:=ch;
  434. end;
  435. AsmWrite(s);
  436. inc(pos,length(s));
  437. if (pos>line_length) or (i=pai_string(hp)^.len) then
  438. begin
  439. AsmWriteLn('"');
  440. pos:=0;
  441. end;
  442. end;
  443. end;
  444. ait_label : begin
  445. if assigned(hp^.next) and (pai(hp^.next)^.typ in
  446. [ait_const_32bit,ait_const_16bit,ait_const_8bit,
  447. ait_const_symbol,ait_const_symbol_offset,
  448. ait_real_64bit,ait_real_32bit,ait_string]) then
  449. begin
  450. if not(cs_littlesize in aktglobalswitches) then
  451. AsmWriteLn(#9#9'.align 4')
  452. else
  453. AsmWriteLn(#9#9'.align 2');
  454. end;
  455. if (pai_label(hp)^.l^.is_used) then
  456. AsmWriteLn(lab2str(pai_label(hp)^.l)+':');
  457. end;
  458. ait_labeled_instruction : begin
  459. { labeled operand }
  460. if pai_labeled(hp)^._op1 = R_NO then
  461. AsmWriteLn(#9+mot_op2str[pai_labeled(hp)^._operator]+#9+lab2str(pai_labeled(hp)^.lab))
  462. else
  463. { labeled operand with register }
  464. begin
  465. if target_info.target=target_m68k_PalmOS then
  466. AsmWriteLn(#9+mot_op2str[pai_labeled(hp)^._operator]+#9+
  467. gasPalmOS_reg2str[pai_labeled(hp)^._op1]+','+lab2str(pai_labeled(hp)^.lab))
  468. else
  469. AsmWriteLn(#9+mot_op2str[pai_labeled(hp)^._operator]+#9+
  470. gas_reg2str[pai_labeled(hp)^._op1]+','+lab2str(pai_labeled(hp)^.lab))
  471. end;
  472. end;
  473. ait_symbol : begin
  474. { ------------------------------------------------------- }
  475. { ----------- ALIGNMENT FOR ANY NON-BYTE VALUE ---------- }
  476. { ------------- REQUIREMENT FOR 680x0 ------------------- }
  477. { ------------------------------------------------------- }
  478. if assigned(hp^.next) and (pai(hp^.next)^.typ in
  479. [ait_const_32bit,ait_const_16bit,ait_const_8bit,
  480. ait_const_symbol,ait_const_symbol_offset,
  481. ait_real_64bit,ait_real_32bit,ait_string]) then
  482. begin
  483. if not(cs_littlesize in aktglobalswitches) then
  484. AsmWriteLn(#9#9'.align 4')
  485. else
  486. AsmWriteLn(#9#9'.align 2');
  487. end;
  488. if pai_symbol(hp)^.is_global then
  489. AsmWriteLn('.globl '+StrPas(pai_symbol(hp)^.name));
  490. AsmWriteLn(StrPas(pai_symbol(hp)^.name)+':');
  491. end;
  492. ait_instruction : begin
  493. { old versions of GAS don't like PEA.L and LEA.L }
  494. if (pai68k(hp)^._operator in [
  495. A_LEA,A_PEA,A_ABCD,A_BCHG,A_BCLR,A_BSET,A_BTST,
  496. A_EXG,A_NBCD,A_SBCD,A_SWAP,A_TAS,A_SCC,A_SCS,
  497. A_SEQ,A_SGE,A_SGT,A_SHI,A_SLE,A_SLS,A_SLT,A_SMI,
  498. A_SNE,A_SPL,A_ST,A_SVC,A_SVS,A_SF]) then
  499. s:=#9+mot_op2str[pai68k(hp)^._operator]
  500. else
  501. if target_info.target=target_m68k_PalmOS then
  502. s:=#9+mot_op2str[pai68k(hp)^._operator]+gas_opsize2str[pai68k(hp)^.size]
  503. else
  504. s:=#9+mot_op2str[pai68k(hp)^._operator]+mit_opsize2str[pai68k(hp)^.size];
  505. if pai68k(hp)^.op1t<>top_none then
  506. begin
  507. { call and jmp need an extra handling }
  508. { this code is only callded if jmp isn't a labeled instruction }
  509. if pai68k(hp)^._operator in [A_JSR,A_JMP] then
  510. s:=s+#9+getopstr_jmp(pai68k(hp)^.op1t,pai68k(hp)^.op1)
  511. else
  512. if pai68k(hp)^.op1t = top_reglist then
  513. s:=s+#9+getopstr(pai68k(hp)^.op1t,@(pai68k(hp)^.reglist))
  514. else
  515. s:=s+#9+getopstr(pai68k(hp)^.op1t,pai68k(hp)^.op1);
  516. if pai68k(hp)^.op2t<>top_none then
  517. begin
  518. if pai68k(hp)^.op2t = top_reglist then
  519. s:=s+','+getopstr(pai68k(hp)^.op2t,@pai68k(hp)^.reglist)
  520. else
  521. s:=s+','+getopstr(pai68k(hp)^.op2t,pai68k(hp)^.op2);
  522. { three operands }
  523. if pai68k(hp)^.op3t<>top_none then
  524. begin
  525. if (pai68k(hp)^._operator = A_DIVSL) or
  526. (pai68k(hp)^._operator = A_DIVUL) or
  527. (pai68k(hp)^._operator = A_MULU) or
  528. (pai68k(hp)^._operator = A_MULS) or
  529. (pai68k(hp)^._operator = A_DIVS) or
  530. (pai68k(hp)^._operator = A_DIVU) then
  531. s:=s+':'+getopstr(pai68k(hp)^.op3t,pai68k(hp)^.op3)
  532. else
  533. s:=s+','+getopstr(pai68k(hp)^.op3t,pai68k(hp)^.op3);
  534. end;
  535. end;
  536. end;
  537. AsmWriteLn(s);
  538. end;
  539. {$ifdef GDB}
  540. ait_stabs : begin
  541. AsmWrite(#9'.stabs ');
  542. AsmWritePChar(pai_stabs(hp)^.str);
  543. AsmLn;
  544. end;
  545. ait_stabn : begin
  546. AsmWrite(#9'.stabn ');
  547. AsmWritePChar(pai_stabn(hp)^.str);
  548. AsmLn;
  549. end;
  550. ait_force_line : begin
  551. stabslastfileinfo.line:=0;
  552. end;
  553. ait_stab_function_name : funcname:=pai_stab_function_name(hp)^.str;
  554. {$endif GDB}
  555. ait_cut : begin
  556. { only reset buffer if nothing has changed }
  557. if AsmSize=AsmStartSize then
  558. AsmClear
  559. else
  560. begin
  561. AsmClose;
  562. DoAssemble;
  563. AsmCreate;
  564. end;
  565. { avoid empty files }
  566. while assigned(hp^.next) and (pai(hp^.next)^.typ in [ait_cut,ait_section,ait_comment]) do
  567. begin
  568. if pai(hp^.next)^.typ=ait_section then
  569. begin
  570. lastsec:=pai_section(hp^.next)^.sec;
  571. lastsecidx:=pai_section(hp^.next)^.idataidx;
  572. {$ifdef GDB}
  573. { this is needed for line info in data }
  574. case pai_section(hp^.next)^.sec of
  575. sec_code : n_line:=n_textline;
  576. sec_data : n_line:=n_dataline;
  577. sec_bss : n_line:=n_bssline;
  578. end;
  579. {$endif GDB}
  580. end;
  581. hp:=pai(hp^.next);
  582. end;
  583. {$ifdef GDB}
  584. { force write of filename }
  585. lastfileindex:=0;
  586. includecount:=0;
  587. funcname:=nil;
  588. WriteFileLineInfo(hp^.fileinfo);
  589. {$endif GDB}
  590. if lastsec<>sec_none then
  591. AsmWriteLn(ait_section2str(lastsec));
  592. AsmStartSize:=AsmSize;
  593. end;
  594. ait_marker : ;
  595. else
  596. internalerror(10000);
  597. end;
  598. hp:=pai(hp^.next);
  599. end;
  600. end;
  601. procedure tm68kgasasmlist.WriteAsmList;
  602. var
  603. p:dirstr;
  604. n:namestr;
  605. e:extstr;
  606. {$ifdef GDB}
  607. fileinfo : tfileposinfo;
  608. {$endif GDB}
  609. begin
  610. {$ifdef EXTDEBUG}
  611. if assigned(current_module^.mainsource) then
  612. comment(v_info,'Start writing gas-styled assembler output for '+current_module^.mainsource^);
  613. {$endif}
  614. LastSec:=sec_none;
  615. if assigned(current_module^.mainsource) then
  616. fsplit(current_module^.mainsource^,p,n,e)
  617. else
  618. begin
  619. p:=inputdir;
  620. n:=inputfile;
  621. e:=inputextension;
  622. end;
  623. { to get symify to work }
  624. AsmWriteLn(#9'.file "'+FixFileName(n+e)+'"');
  625. {$ifdef GDB}
  626. includecount:=0;
  627. n_line:=n_bssline;
  628. lastline:=0;
  629. lastfileindex:=0;
  630. funcname:=nil;
  631. linecount:=1;
  632. fileinfo.fileindex:=1;
  633. fileinfo.line:=1;
  634. { Write main file }
  635. WriteFileLineInfo(fileinfo);
  636. {$endif GDB}
  637. AsmStartSize:=AsmSize;
  638. countlabelref:=false;
  639. { there should be nothing but externals so we don't need to process
  640. WriteTree(externals); }
  641. WriteTree(debuglist);
  642. WriteTree(codesegment);
  643. WriteTree(datasegment);
  644. WriteTree(consts);
  645. WriteTree(rttilist);
  646. WriteTree(bsssegment);
  647. Writetree(importssection);
  648. Writetree(exportssection);
  649. Writetree(resourcesection);
  650. countlabelref:=true;
  651. AsmLn;
  652. {$ifdef EXTDEBUG}
  653. if assigned(current_module^.mainsource) then
  654. comment(v_info,'Done writing gas-styled assembler output for '+current_module^.mainsource^);
  655. {$endif EXTDEBUG}
  656. end;
  657. end.
  658. {
  659. $Log$
  660. Revision 1.21 1998-12-11 00:02:39 peter
  661. + globtype,tokens,version unit splitted from globals
  662. Revision 1.20 1998/11/12 11:19:35 pierre
  663. * fix for first line of function break
  664. Revision 1.19 1998/10/29 11:35:36 florian
  665. * some dll support for win32
  666. * fixed assembler writing for PalmOS
  667. Revision 1.18 1998/10/14 15:56:39 pierre
  668. * all references to comp suppressed for m68k
  669. Revision 1.17 1998/10/13 13:10:08 peter
  670. * new style for m68k/i386 infos and enums
  671. Revision 1.16 1998/10/12 12:27:44 pierre
  672. * typo error for tai_const_symbol_offset corrected
  673. Revision 1.15 1998/10/12 12:20:43 pierre
  674. + added tai_const_symbol_offset
  675. for r : pointer = @var.field;
  676. * better message for different arg names on implementation
  677. of function
  678. Revision 1.14 1998/10/06 17:16:36 pierre
  679. * some memory leaks fixed (thanks to Peter for heaptrc !)
  680. Revision 1.13 1998/10/01 20:19:08 jonas
  681. + ait_marker support
  682. Revision 1.12 1998/09/28 16:57:09 pierre
  683. * changed all length(p^.value_str^) into str_length(p)
  684. to get it work with and without ansistrings
  685. * changed sourcefiles field of tmodule to a pointer
  686. Revision 1.11 1998/09/16 01:07:13 carl
  687. * alignment fix for bytes
  688. Revision 1.10 1998/09/01 09:07:08 peter
  689. * m68k fixes, splitted cg68k like cgi386
  690. Revision 1.9 1998/08/31 12:26:20 peter
  691. * m68k and palmos updates from surebugfixes
  692. Revision 1.8 1998/08/10 14:49:36 peter
  693. + localswitches, moduleswitches, globalswitches splitting
  694. Revision 1.7 1998/07/14 14:46:38 peter
  695. * released NEWINPUT
  696. Revision 1.6 1998/07/10 10:50:54 peter
  697. * m68k updates
  698. Revision 1.5 1998/06/05 17:46:04 peter
  699. * tp doesn't like comp() typecast
  700. Revision 1.4 1998/06/04 23:51:28 peter
  701. * m68k compiles
  702. + .def file creation moved to gendef.pas so it could also be used
  703. for win32
  704. }