agppcmpw.pas 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. {
  2. $Id$
  3. Copyright (c) 2002 by Florian Klaempfl
  4. This unit implements an asmoutput class for PowerPC with MPW syntax
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. {
  19. This unit implements an asmoutput class for PowerPC with MPW syntax
  20. }
  21. unit agppcmpwt;
  22. {$i fpcdefs.inc}
  23. interface
  24. uses
  25. aasmbase,aasmtai,aasmcpu,assemble,
  26. cpubase;
  27. const
  28. mpw_reg2str : treg2strtable = ('',
  29. 'r0','r1','r2','r3','r4','r5','r6','r7','r8','r9','r10','r11','r12','r13','r14','r15','r16',
  30. 'r17','r18','r19','r20','r21','r22','r23','r24','r25','r26','r27','r28','r29','r30','r31',
  31. 'f0','f1','f2','f3','f4','f5','f6','f7', 'f8','f9','f10','f11','f12',
  32. 'f13','f14','f15','f16','f17', 'f18','f19','f20','f21','f22', 'f23','f24',
  33. 'f25','f26','f27','f28','f29','f30','f31',
  34. 'v0','v1','v2','v3','v4','v5','v6','v7','v8','v9','v10','v11','v12',
  35. 'v13','v14','v15','v16','v17','v18','v19','v20','v21','v22', 'v23','v24',
  36. 'v25','v26','v27','v28','v29','v30','v31',
  37. 'cR','cr0','cr1','cr2','cr3','cr4','cr5','cr6','cr7',
  38. 'xer','lr','ctr','fpscr'
  39. );
  40. type
  41. TPPCMPWAssembler = class(TExternalAssembler)
  42. procedure WriteTree(p:TAAsmoutput);override;
  43. procedure WriteAsmList;override;
  44. Function DoAssemble:boolean;override;
  45. procedure WriteExternals;
  46. end;
  47. implementation
  48. uses
  49. {$ifdef delphi}
  50. sysutils,
  51. {$endif}
  52. cutils,globtype,globals,systems,cclasses,
  53. verbose,finput,fmodule,script,cpuinfo
  54. ;
  55. const
  56. line_length = 70;
  57. function single2str(d : single) : string;
  58. var
  59. hs : string;
  60. p : byte;
  61. begin
  62. str(d,hs);
  63. { nasm expects a lowercase e }
  64. p:=pos('E',hs);
  65. if p>0 then
  66. hs[p]:='e';
  67. p:=pos('+',hs);
  68. if p>0 then
  69. delete(hs,p,1);
  70. single2str:=lower(hs);
  71. end;
  72. function double2str(d : double) : string;
  73. var
  74. hs : string;
  75. p : byte;
  76. begin
  77. str(d,hs);
  78. { nasm expects a lowercase e }
  79. p:=pos('E',hs);
  80. if p>0 then
  81. hs[p]:='e';
  82. p:=pos('+',hs);
  83. if p>0 then
  84. delete(hs,p,1);
  85. double2str:=lower(hs);
  86. end;
  87. function extended2str(e : extended) : string;
  88. var
  89. hs : string;
  90. p : byte;
  91. begin
  92. str(e,hs);
  93. { nasm expects a lowercase e }
  94. p:=pos('E',hs);
  95. if p>0 then
  96. hs[p]:='e';
  97. p:=pos('+',hs);
  98. if p>0 then
  99. delete(hs,p,1);
  100. extended2str:=lower(hs);
  101. end;
  102. function comp2str(d : bestreal) : string;
  103. type
  104. pdouble = ^double;
  105. var
  106. c : comp;
  107. dd : pdouble;
  108. begin
  109. {$ifdef FPC}
  110. c:=comp(d);
  111. {$else}
  112. c:=d;
  113. {$endif}
  114. dd:=pdouble(@c); { this makes a bitwise copy of c into a double }
  115. comp2str:=double2str(dd^);
  116. end;
  117. function getreferencestring(var ref : treference) : string;
  118. var
  119. s : string;
  120. first : boolean;
  121. begin
  122. getreferencestring:=s;
  123. end;
  124. function getopstr(const o:toper) : string;
  125. var
  126. hs : string;
  127. begin
  128. case o.typ of
  129. top_reg:
  130. getopstr:=mpw_reg2str[o.reg];
  131. { no top_ref jumping for powerpc }
  132. top_const:
  133. getopstr:=tostr(longint(o.val));
  134. top_ref:
  135. getopstr:=getreferencestring(o.ref^);
  136. top_symbol:
  137. begin
  138. hs:=o.sym.name;
  139. if o.symofs>0 then
  140. hs:=hs+'+'+tostr(o.symofs)
  141. else
  142. if o.symofs<0 then
  143. hs:=hs+tostr(o.symofs);
  144. getopstr:=hs;
  145. end;
  146. else
  147. {$ifndef testing}
  148. internalerror(2002070604);
  149. {$else testing}
  150. begin
  151. writeln('internalerror 10001');
  152. halt(1);
  153. end;
  154. {$endif testing}
  155. end;
  156. end;
  157. function getopstr_jmp(const o:toper) : string;
  158. var
  159. hs : string;
  160. begin
  161. case o.typ of
  162. top_reg :
  163. getopstr_jmp:=mpw_reg2str[o.reg];
  164. { no top_ref jumping for powerpc }
  165. top_const :
  166. getopstr_jmp:=tostr(o.val);
  167. top_symbol :
  168. begin
  169. hs:=o.sym.name;
  170. if o.symofs>0 then
  171. hs:=hs+'+'+tostr(o.symofs)
  172. else
  173. if o.symofs<0 then
  174. hs:=hs+tostr(o.symofs);
  175. getopstr_jmp:=hs;
  176. end;
  177. else
  178. {$ifndef testing}
  179. internalerror(2002070603);
  180. {$else testing}
  181. begin
  182. writeln('internalerror 10001');
  183. halt(1);
  184. end;
  185. {$endif testing}
  186. end;
  187. end;
  188. function fixline(s:string):string;
  189. {
  190. return s with all leading and ending spaces and tabs removed
  191. }
  192. var
  193. i,j,k : longint;
  194. begin
  195. i:=length(s);
  196. while (i>0) and (s[i] in [#9,' ']) do
  197. dec(i);
  198. j:=1;
  199. while (j<i) and (s[j] in [#9,' ']) do
  200. inc(j);
  201. for k:=j to i do
  202. if s[k] in [#0..#31,#127..#255] then
  203. s[k]:='.';
  204. fixline:=Copy(s,j,i-j+1);
  205. end;
  206. {****************************************************************************
  207. T386IntelAssembler
  208. ****************************************************************************}
  209. var
  210. LasTSec : TSection;
  211. lastfileinfo : tfileposinfo;
  212. infile,
  213. lastinfile : tinputfile;
  214. const
  215. ait_const2str:array[ait_const_32bit..ait_const_8bit] of string[8]=
  216. (#9'DD'#9,#9'DW'#9,#9'DB'#9);
  217. Function PadTabs(const p:string;addch:char):string;
  218. var
  219. s : string;
  220. i : longint;
  221. begin
  222. i:=length(p);
  223. if addch<>#0 then
  224. begin
  225. inc(i);
  226. s:=p+addch;
  227. end
  228. else
  229. s:=p;
  230. if i<8 then
  231. PadTabs:=s+#9#9
  232. else
  233. PadTabs:=s+#9;
  234. end;
  235. procedure TPPCMPWAssembler.WriteTree(p:TAAsmoutput);
  236. const
  237. nolinetai =[ait_label,
  238. ait_regalloc,ait_tempalloc,
  239. {$ifdef GDB}
  240. ait_stabn,ait_stabs,ait_stab_function_name,
  241. {$endif GDB}
  242. ait_cut,ait_marker,ait_align,ait_section];
  243. var
  244. s,
  245. prefix,
  246. suffix : string;
  247. hp : tai;
  248. counter,
  249. lines,
  250. InlineLevel : longint;
  251. i,j,l : longint;
  252. consttyp : taitype;
  253. found,
  254. do_line,DoNotSplitLine,
  255. quoted : boolean;
  256. sep : char;
  257. begin
  258. if not assigned(p) then
  259. exit;
  260. { lineinfo is only needed for codesegment (PFV) }
  261. do_line:=((cs_asm_source in aktglobalswitches) or
  262. (cs_lineinfo in aktmoduleswitches))
  263. and (p=codesegment);
  264. InlineLevel:=0;
  265. DoNotSplitLine:=false;
  266. hp:=tai(p.first);
  267. while assigned(hp) do
  268. begin
  269. if do_line and not(hp.typ in nolinetai) and
  270. not DoNotSplitLine then
  271. begin
  272. { load infile }
  273. if lastfileinfo.fileindex<>hp.fileinfo.fileindex then
  274. begin
  275. infile:=current_module.sourcefiles.get_file(hp.fileinfo.fileindex);
  276. if assigned(infile) then
  277. begin
  278. { open only if needed !! }
  279. if (cs_asm_source in aktglobalswitches) then
  280. infile.open;
  281. end;
  282. { avoid unnecessary reopens of the same file !! }
  283. lastfileinfo.fileindex:=hp.fileinfo.fileindex;
  284. { be sure to change line !! }
  285. lastfileinfo.line:=-1;
  286. end;
  287. { write source }
  288. if (cs_asm_source in aktglobalswitches) and
  289. assigned(infile) then
  290. begin
  291. if (infile<>lastinfile) then
  292. begin
  293. AsmWriteLn(target_asm.comment+'['+infile.name^+']');
  294. if assigned(lastinfile) then
  295. lastinfile.close;
  296. end;
  297. if (hp.fileinfo.line<>lastfileinfo.line) and
  298. ((hp.fileinfo.line<infile.maxlinebuf) or (InlineLevel>0)) then
  299. begin
  300. if (hp.fileinfo.line<>0) and
  301. ((infile.linebuf^[hp.fileinfo.line]>=0) or (InlineLevel>0)) then
  302. AsmWriteLn(target_asm.comment+'['+tostr(hp.fileinfo.line)+'] '+
  303. fixline(infile.GetLineStr(hp.fileinfo.line)));
  304. { set it to a negative value !
  305. to make that is has been read already !! PM }
  306. if (infile.linebuf^[hp.fileinfo.line]>=0) then
  307. infile.linebuf^[hp.fileinfo.line]:=-infile.linebuf^[hp.fileinfo.line]-1;
  308. end;
  309. end;
  310. lastfileinfo:=hp.fileinfo;
  311. lastinfile:=infile;
  312. end;
  313. DoNotSplitLine:=false;
  314. case hp.typ of
  315. ait_comment:
  316. begin
  317. AsmWrite(target_asm.comment);
  318. AsmWritePChar(tai_comment(hp).str);
  319. AsmLn;
  320. end;
  321. ait_regalloc,
  322. ait_tempalloc:
  323. ;
  324. ait_section:
  325. begin
  326. if LasTSec<>sec_none then
  327. AsmWriteLn('_'+target_asm.secnames[LasTSec]+#9#9'ENDS');
  328. if tai_section(hp).sec<>sec_none then
  329. begin
  330. AsmLn;
  331. AsmWriteLn('_'+target_asm.secnames[tai_section(hp).sec]+#9#9+
  332. 'SEGMENT'#9'PARA PUBLIC USE32 '''+
  333. target_asm.secnames[tai_section(hp).sec]+'''');
  334. end;
  335. LasTSec:=tai_section(hp).sec;
  336. end;
  337. ait_align:
  338. begin
  339. AsmWriteLn(#9'ALIGN '+tostr(tai_align(hp).aligntype));
  340. end;
  341. ait_datablock:
  342. begin
  343. if tai_datablock(hp).is_global then
  344. AsmWriteLn(#9'PUBLIC'#9+tai_datablock(hp).sym.name);
  345. AsmWriteLn(PadTabs(tai_datablock(hp).sym.name,#0)+'DB'#9+tostr(tai_datablock(hp).size)+' DUP(?)');
  346. end;
  347. ait_const_32bit,
  348. ait_const_8bit,
  349. ait_const_16bit : begin
  350. AsmWrite(ait_const2str[hp.typ]+tostr(tai_const(hp).value));
  351. consttyp:=hp.typ;
  352. l:=0;
  353. repeat
  354. found:=(not (tai(hp.next)=nil)) and (tai(hp.next).typ=consttyp);
  355. if found then
  356. begin
  357. hp:=tai(hp.next);
  358. s:=','+tostr(tai_const(hp).value);
  359. AsmWrite(s);
  360. inc(l,length(s));
  361. end;
  362. until (not found) or (l>line_length);
  363. AsmLn;
  364. end;
  365. ait_const_symbol : begin
  366. AsmWriteLn(#9#9'DD'#9'offset '+tai_const_symbol(hp).sym.name);
  367. if tai_const_symbol(hp).offset>0 then
  368. AsmWrite('+'+tostr(tai_const_symbol(hp).offset))
  369. else if tai_const_symbol(hp).offset<0 then
  370. AsmWrite(tostr(tai_const_symbol(hp).offset));
  371. AsmLn;
  372. end;
  373. ait_const_rva : begin
  374. AsmWriteLn(#9#9'RVA'#9+tai_const_symbol(hp).sym.name);
  375. end;
  376. ait_real_32bit : AsmWriteLn(#9#9'DD'#9+single2str(tai_real_32bit(hp).value));
  377. ait_real_64bit : AsmWriteLn(#9#9'DQ'#9+double2str(tai_real_64bit(hp).value));
  378. ait_real_80bit : AsmWriteLn(#9#9'DT'#9+extended2str(tai_real_80bit(hp).value));
  379. ait_comp_64bit : AsmWriteLn(#9#9'DQ'#9+comp2str(tai_real_80bit(hp).value));
  380. ait_string : begin
  381. counter := 0;
  382. lines := tai_string(hp).len div line_length;
  383. { separate lines in different parts }
  384. if tai_string(hp).len > 0 then
  385. Begin
  386. for j := 0 to lines-1 do
  387. begin
  388. AsmWrite(#9#9'DB'#9);
  389. quoted:=false;
  390. for i:=counter to counter+line_length do
  391. begin
  392. { it is an ascii character. }
  393. if (ord(tai_string(hp).str[i])>31) and
  394. (ord(tai_string(hp).str[i])<128) and
  395. (tai_string(hp).str[i]<>'"') then
  396. begin
  397. if not(quoted) then
  398. begin
  399. if i>counter then
  400. AsmWrite(',');
  401. AsmWrite('"');
  402. end;
  403. AsmWrite(tai_string(hp).str[i]);
  404. quoted:=true;
  405. end { if > 31 and < 128 and ord('"') }
  406. else
  407. begin
  408. if quoted then
  409. AsmWrite('"');
  410. if i>counter then
  411. AsmWrite(',');
  412. quoted:=false;
  413. AsmWrite(tostr(ord(tai_string(hp).str[i])));
  414. end;
  415. end; { end for i:=0 to... }
  416. if quoted then AsmWrite('"');
  417. AsmWrite(target_info.newline);
  418. counter := counter+line_length;
  419. end; { end for j:=0 ... }
  420. { do last line of lines }
  421. AsmWrite(#9#9'DB'#9);
  422. quoted:=false;
  423. for i:=counter to tai_string(hp).len-1 do
  424. begin
  425. { it is an ascii character. }
  426. if (ord(tai_string(hp).str[i])>31) and
  427. (ord(tai_string(hp).str[i])<128) and
  428. (tai_string(hp).str[i]<>'"') then
  429. begin
  430. if not(quoted) then
  431. begin
  432. if i>counter then
  433. AsmWrite(',');
  434. AsmWrite('"');
  435. end;
  436. AsmWrite(tai_string(hp).str[i]);
  437. quoted:=true;
  438. end { if > 31 and < 128 and " }
  439. else
  440. begin
  441. if quoted then
  442. AsmWrite('"');
  443. if i>counter then
  444. AsmWrite(',');
  445. quoted:=false;
  446. AsmWrite(tostr(ord(tai_string(hp).str[i])));
  447. end;
  448. end; { end for i:=0 to... }
  449. if quoted then
  450. AsmWrite('"');
  451. end;
  452. AsmLn;
  453. end;
  454. ait_label : begin
  455. if tai_label(hp).l.is_used then
  456. begin
  457. AsmWrite(tai_label(hp).l.name);
  458. if assigned(hp.next) and not(tai(hp.next).typ in
  459. [ait_const_32bit,ait_const_16bit,ait_const_8bit,
  460. ait_const_symbol,ait_const_rva,
  461. ait_real_32bit,ait_real_64bit,ait_real_80bit,ait_comp_64bit,ait_string]) then
  462. AsmWriteLn(':')
  463. else
  464. DoNotSplitLine:=true;
  465. end;
  466. end;
  467. ait_direct : begin
  468. AsmWritePChar(tai_direct(hp).str);
  469. AsmLn;
  470. end;
  471. ait_symbol : begin
  472. if tai_symbol(hp).is_global then
  473. AsmWriteLn(#9'PUBLIC'#9+tai_symbol(hp).sym.name);
  474. AsmWrite(tai_symbol(hp).sym.name);
  475. if assigned(hp.next) and not(tai(hp.next).typ in
  476. [ait_const_32bit,ait_const_16bit,ait_const_8bit,
  477. ait_const_symbol,ait_const_rva,
  478. ait_real_32bit,ait_real_64bit,ait_real_80bit,ait_comp_64bit,ait_string]) then
  479. AsmWriteLn(':')
  480. end;
  481. ait_symbol_end : begin
  482. end;
  483. ait_instruction : begin
  484. {!!!!
  485. { Must be done with args in ATT order }
  486. taicpu(hp).SetOperandOrder(op_att);
  487. taicpu(hp).CheckNonCommutativeOpcodes;
  488. { We need intel order, no At&t }
  489. taicpu(hp).SetOperandOrder(op_intel);
  490. { Reset }
  491. suffix:='';
  492. prefix:= '';
  493. s:='';
  494. { We need to explicitely set
  495. word prefix to get selectors
  496. to be pushed in 2 bytes PM }
  497. if (taicpu(hp).opsize=S_W) and
  498. ((taicpu(hp).opcode=A_PUSH) or
  499. (taicpu(hp).opcode=A_POP)) and
  500. (taicpu(hp).oper[0].typ=top_reg) and
  501. ((taicpu(hp).oper[0].reg>=firstsreg) and
  502. (taicpu(hp).oper[0].reg<=lastsreg)) then
  503. AsmWriteln(#9#9'DB'#9'066h');
  504. { added prefix instructions, must be on same line as opcode }
  505. if (taicpu(hp).ops = 0) and
  506. ((taicpu(hp).opcode = A_REP) or
  507. (taicpu(hp).opcode = A_LOCK) or
  508. (taicpu(hp).opcode = A_REPE) or
  509. (taicpu(hp).opcode = A_REPNZ) or
  510. (taicpu(hp).opcode = A_REPZ) or
  511. (taicpu(hp).opcode = A_REPNE)) then
  512. Begin
  513. prefix:=std_op2str[taicpu(hp).opcode]+#9;
  514. hp:=tai(hp.next);
  515. { this is theorically impossible... }
  516. if hp=nil then
  517. begin
  518. s:=#9#9+prefix;
  519. AsmWriteLn(s);
  520. break;
  521. end;
  522. { nasm prefers prefix on a line alone
  523. AsmWriteln(#9#9+prefix); but not masm PM
  524. prefix:=''; }
  525. if (aktoutputformat = as_i386_masm) then
  526. begin
  527. AsmWriteln(s);
  528. prefix:='';
  529. end;
  530. end
  531. else
  532. prefix:= '';
  533. if taicpu(hp).ops<>0 then
  534. begin
  535. if is_calljmp(taicpu(hp).opcode) then
  536. s:=#9+getopstr_jmp(taicpu(hp).oper[0],taicpu(hp).opsize)
  537. else
  538. begin
  539. for i:=0to taicpu(hp).ops-1 do
  540. begin
  541. if i=0 then
  542. sep:=#9
  543. else
  544. sep:=',';
  545. s:=s+sep+getopstr(taicpu(hp).oper[i],taicpu(hp).opsize,taicpu(hp).opcode,(i=2));
  546. end;
  547. end;
  548. end;
  549. AsmWriteLn(#9#9+prefix+std_op2str[taicpu(hp).opcode]+cond2str[taicpu(hp).condition]+suffix+s);
  550. }
  551. end;
  552. {$ifdef GDB}
  553. ait_stabn,
  554. ait_stabs,
  555. ait_force_line,
  556. ait_stab_function_name : ;
  557. {$endif GDB}
  558. ait_cut : begin
  559. { only reset buffer if nothing has changed }
  560. if AsmSize=AsmStartSize then
  561. AsmClear
  562. else
  563. begin
  564. if LasTSec<>sec_none then
  565. AsmWriteLn('_'+target_asm.secnames[LasTSec]+#9#9'ENDS');
  566. AsmLn;
  567. AsmWriteLn(#9'END');
  568. AsmClose;
  569. DoAssemble;
  570. AsmCreate(tai_cut(hp).place);
  571. end;
  572. { avoid empty files }
  573. while assigned(hp.next) and (tai(hp.next).typ in [ait_cut,ait_section,ait_comment]) do
  574. begin
  575. if tai(hp.next).typ=ait_section then
  576. begin
  577. lasTSec:=tai_section(hp.next).sec;
  578. end;
  579. hp:=tai(hp.next);
  580. end;
  581. AsmWriteLn(#9'.386p');
  582. AsmWriteLn('DGROUP'#9'GROUP'#9'_BSS,_DATA');
  583. AsmWriteLn(#9'ASSUME'#9'CS:_CODE,ES:DGROUP,DS:DGROUP,SS:DGROUP');
  584. { I was told that this isn't necesarry because }
  585. { the labels generated by FPC are unique (FK) }
  586. { AsmWriteLn(#9'LOCALS '+target_asm.labelprefix); }
  587. if lasTSec<>sec_none then
  588. AsmWriteLn('_'+target_asm.secnames[lasTSec]+#9#9+
  589. 'SEGMENT'#9'PARA PUBLIC USE32 '''+
  590. target_asm.secnames[lasTSec]+'''');
  591. AsmStartSize:=AsmSize;
  592. end;
  593. ait_marker :
  594. begin
  595. if tai_marker(hp).kind=InlineStart then
  596. inc(InlineLevel)
  597. else if tai_marker(hp).kind=InlineEnd then
  598. dec(InlineLevel);
  599. end;
  600. else
  601. internalerror(10000);
  602. end;
  603. hp:=tai(hp.next);
  604. end;
  605. end;
  606. var
  607. currentasmlist : TExternalAssembler;
  608. procedure writeexternal(p:tnamedindexitem;arg:pointer);
  609. begin
  610. if tasmsymbol(p).defbind=AB_EXTERNAL then
  611. currentasmlist.AsmWriteln(#9'EXTRN'#9+p.name);
  612. end;
  613. procedure TPPCMPWAssembler.WriteExternals;
  614. begin
  615. currentasmlist:=self;
  616. objectlibrary.symbolsearch.foreach_static({$ifdef fpcprocvar}@{$endif}writeexternal,nil);
  617. end;
  618. function TPPCMPWAssembler.DoAssemble : boolean;
  619. var f : file;
  620. begin
  621. DoAssemble:=Inherited DoAssemble;
  622. { masm does not seem to recognize specific extensions and uses .obj allways PM }
  623. if (aktoutputformat = as_i386_masm) then
  624. begin
  625. if not(cs_asm_extern in aktglobalswitches) then
  626. begin
  627. if Not FileExists(objfile) and
  628. FileExists(ForceExtension(objfile,'.obj')) then
  629. begin
  630. Assign(F,ForceExtension(objfile,'.obj'));
  631. Rename(F,objfile);
  632. end;
  633. end
  634. else
  635. AsmRes.AddAsmCommand('mv',ForceExtension(objfile,'.obj')+' '+objfile,objfile);
  636. end;
  637. end;
  638. procedure TPPCMPWAssembler.WriteAsmList;
  639. begin
  640. {$ifdef EXTDEBUG}
  641. if assigned(current_module.mainsource) then
  642. comment(v_info,'Start writingMPW-styled assembler output for '+current_module.mainsource^);
  643. {$endif}
  644. LasTSec:=sec_none;
  645. AsmWriteLn(#9'.386p');
  646. { masm 6.11 does not seem to like LOCALS PM }
  647. if (aktoutputformat = as_i386_tasm) then
  648. begin
  649. AsmWriteLn(#9'LOCALS '+target_asm.labelprefix);
  650. end;
  651. AsmWriteLn('DGROUP'#9'GROUP'#9'_BSS,_DATA');
  652. AsmWriteLn(#9'ASSUME'#9'CS:_CODE,ES:DGROUP,DS:DGROUP,SS:DGROUP');
  653. AsmLn;
  654. WriteExternals;
  655. { INTEL ASM doesn't support stabs
  656. WriteTree(debuglist);}
  657. WriteTree(codesegment);
  658. WriteTree(datasegment);
  659. WriteTree(consts);
  660. WriteTree(rttilist);
  661. WriteTree(resourcestringlist);
  662. WriteTree(bsssegment);
  663. AsmWriteLn(#9'END');
  664. AsmLn;
  665. {$ifdef EXTDEBUG}
  666. if assigned(current_module.mainsource) then
  667. comment(v_info,'Done writing MPW-styled assembler output for '+current_module.mainsource^);
  668. {$endif EXTDEBUG}
  669. end;
  670. {*****************************************************************************
  671. Initialize
  672. *****************************************************************************}
  673. const
  674. as_powerpc_mpw_info : tasminfo =
  675. (
  676. id : as_powerpc_mpw;
  677. idtxt : 'MPW';
  678. asmbin : 'ppcasm';
  679. asmcmd : '';
  680. supported_target : system_any; { what should I write here ?? }
  681. outputbinary: false;
  682. allowdirect : true;
  683. needar : true;
  684. labelprefix_only_inside_procedure : true;
  685. labelprefix : '@@';
  686. comment : '; ';
  687. secnames : ('',
  688. 'CODE','DATA','BSS',
  689. '','','','','','',
  690. '','','')
  691. );
  692. initialization
  693. RegisterAssembler(as_powerpc_mpw_info,TPPCMPWAssembler);
  694. end.
  695. {
  696. $Log$
  697. Revision 1.1 2002-08-20 21:40:44 florian
  698. + target macos for ppc added
  699. + frame work for mpw assembler output
  700. }