agppcmpw.pas 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392
  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 agppcmpw;
  22. {$i fpcdefs.inc}
  23. interface
  24. uses
  25. globals,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. {$ifdef GDB}
  47. procedure WriteFileLineInfo(var fileinfo : tfileposinfo);
  48. procedure WriteFileEndInfo;
  49. {$endif}
  50. procedure WriteAsmFileHeader;
  51. private
  52. procedure GenProcedureHeader(var hp:tai);
  53. end;
  54. implementation
  55. uses
  56. {$ifdef delphi}
  57. sysutils,
  58. {$endif}
  59. cutils,globtype,systems,cclasses,
  60. verbose,finput,fmodule,script,cpuinfo
  61. ;
  62. const
  63. line_length = 70;
  64. {Whether internal procedure references should be xxx[PR]: }
  65. use_PR = false;
  66. const_storage_class = '[RW]';
  67. {$ifdef GDB}
  68. var
  69. n_line : byte; { different types of source lines }
  70. linecount,
  71. includecount : longint;
  72. funcname : pchar;
  73. stabslastfileinfo : tfileposinfo;
  74. isInFunction: Boolean;
  75. firstLineInFunction: longint;
  76. {$endif}
  77. function ReplaceForbiddenChars(var s: string):Boolean;
  78. {Returns wheater a replacement has occured.}
  79. var
  80. i:Integer;
  81. {The dollar sign is not allowed in MPW PPCAsm}
  82. begin
  83. ReplaceForbiddenChars:=false;
  84. for i:=1 to Length(s) do
  85. if s[i]='$' then
  86. begin
  87. s[i]:='s';
  88. ReplaceForbiddenChars:=true;
  89. end;
  90. end;
  91. const
  92. {*** From here is copyed from agppcgas.pp, except where marked with CHANGED.
  93. Perhaps put in a third common file. ***}
  94. op2str : array[tasmop] of string[14] = ('<none>',
  95. 'add','add.','addo','addo.','addc','addc.','addco','addco.',
  96. 'adde','adde.','addeo','addeo.','addi','addic','addic.','addis',
  97. 'addme','addme.','addmeo','addmeo.','addze','addze.','addzeo',
  98. 'addzeo.','and','and.','andc','andc.','andi.','andis.','b',
  99. 'ba','bl','bla','bc','bca','bcl','bcla','bcctr','bcctrl','bclr',
  100. 'bclrl','cmp','cmpi','cmpl','cmpli','cntlzw','cntlzw.','crand',
  101. 'crandc','creqv','crnand','crnor','cror','crorc','crxor','dcba',
  102. 'dcbf','dcbi','dcbst','dcbt','divw','divw.','divwo','divwo.',
  103. 'divwu','divwu.','divwuo','divwuo.','eciwx','ecowx','eieio','eqv',
  104. 'eqv.','extsb','extsb.','extsh','extsh.','fabs','fabs.','fadd',
  105. 'fadd.','fadds','fadds.','fcmpo','fcmpu','fctiw','fctw.','fctwz',
  106. 'fctwz.','fdiv','fdiv.','fdivs','fdivs.','fmadd','fmadd.','fmadds',
  107. 'fmadds.','fmr','fmsub','fmsub.','fmsubs','fmsubs.','fmul','fmul.',
  108. 'fmuls','fmuls.','fnabs','fnabs.','fneg','fneg.','fnmadd',
  109. 'fnmadd.','fnmadds','fnmadds.','fnmsub','fnmsub.','fnmsubs',
  110. 'fnmsubs.','fres','fres.','frsp','frsp.','frsqrte','frsqrte.',
  111. 'fsel','fsel.','fsqrt','fsqrt.','fsqrts','fsqrts.','fsub','fsub.',
  112. 'fsubs','fsubs.','icbi','isync','lbz','lbzu','lbzux','lbzx',
  113. 'lfd','lfdu','lfdux','lfdx','lfs','lfsu','lfsux','lfsx','lha',
  114. 'lhau','lhaux','lhax','hbrx','lhz','lhzu','lhzux','lhzx','lmw',
  115. 'lswi','lswx','lwarx','lwbrx','lwz','lwzu','lwzux','lwzx','mcrf',
  116. 'mcrfs','mcrxr','lcrxe','mfcr','mffs','maffs.','mfmsr','mfspr','mfsr',
  117. 'mfsrin','mftb','mtfcrf','mtfd0','mtfsb1','mtfsf','mtfsf.',
  118. 'mtfsfi','mtfsfi.','mtmsr','mtspr','mtsr','mtsrin','mulhw',
  119. 'mulhw.','mulhwu','mulhwu.','mulli','mullw','mullw.','mullwo',
  120. 'mullwo.','nand','nand.','neg','neg.','nego','nego.','nor','nor.',
  121. 'or','or.','orc','orc.','ori','oris', 'rfi', 'rlwimi', 'rlwimi.',
  122. 'rlwinm', 'rlwinm.','rlwnm','sc','slw', 'slw.', 'sraw', 'sraw.',
  123. 'srawi', 'srawi.','srw', 'srw.', 'stb', 'stbu', 'stbux','stbx','stfd',
  124. 'stfdu', 'stfdux', 'stfdx', 'stfiwx', 'stfs', 'stfsu', 'stfsux', 'stfsx',
  125. 'sth', 'sthbrx', 'sthu', 'sthux', 'sthx', 'stmw', 'stswi', 'stswx', 'stw',
  126. 'stwbrx', 'stwx.', 'stwu', 'stwux', 'stwx', 'subf', 'subf.', 'subfo',
  127. 'subfo.', 'subfc', 'subc.', 'subfco', 'subfco.', 'subfe', 'subfe.',
  128. 'subfeo', 'subfeo.', 'subfic', 'subfme', 'subfme.', 'subfmeo', 'subfmeo.',
  129. 'subfze', 'subfze.', 'subfzeo', 'subfzeo.', 'sync', 'tlbia', 'tlbie',
  130. 'tlbsync', 'tw', 'twi', 'xor', 'xor.', 'xori', 'xoris',
  131. { some simplified mnemonics }
  132. 'subi', 'subis', 'subic', 'subic.', 'sub', 'sub.', 'subo', 'subo.',
  133. 'subc', 'subc.', 'subco', 'subco.', 'cmpwi', 'cmpw', 'cmplwi', 'cmplw',
  134. 'extlwi', 'extlwi.', 'extrwi', 'extrwi.', 'inslwi', 'inslwi.', 'insrwi',
  135. 'insrwi.', 'rotlwi', 'rotlwi.', 'rotlw', 'rotlw.', 'slwi', 'slwi.',
  136. 'srwi', 'srwi.', 'clrlwi', 'clrlwi.', 'clrrwi', 'clrrwi.', 'clrslwi',
  137. 'clrslwi.', 'blr', 'bctr', 'blrl', 'bctrl', 'crset', 'crclr', 'crmove',
  138. 'crnot', 'mt', 'mf','nop', 'li', 'lis', 'la', 'mr','mr.','not', 'mtcr', 'mtlr', 'mflr',
  139. 'mtctr', 'mfctr');
  140. function getreferencestring(var ref : treference) : string;
  141. var
  142. s : string;
  143. begin
  144. with ref do
  145. begin
  146. inc(offset,offsetfixup);
  147. if (symaddr <> refs_full) then
  148. InternalError(2002110301)
  149. else if ((offset < -32768) or (offset > 32767)) then
  150. InternalError(19991);
  151. if assigned(symbol) then
  152. begin
  153. s:= symbol.name;
  154. ReplaceForbiddenChars(s);
  155. {if symbol.typ = AT_FUNCTION then
  156. ;}
  157. s:= s+'[TC]' {ref to TOC entry }
  158. end
  159. else
  160. s:= '';
  161. if offset<0 then
  162. s:=s+tostr(offset)
  163. else
  164. if (offset>0) then
  165. begin
  166. if assigned(symbol) then
  167. s:=s+'+'+tostr(offset)
  168. else
  169. s:=s+tostr(offset);
  170. end;
  171. if (index.enum=R_NO) and (base.enum<>R_NO) then
  172. begin
  173. if offset=0 then
  174. if not assigned(symbol) then
  175. s:=s+'0';
  176. s:=s+'('+mpw_reg2str[base.enum]+')'
  177. end
  178. else if (index.enum<>R_NO) and (base.enum<>R_NO) and (offset=0) then
  179. s:=s+mpw_reg2str[base.enum]+','+mpw_reg2str[index.enum]
  180. else if ((index.enum<>R_NO) or (base.enum<>R_NO)) then
  181. internalerror(19992);
  182. end;
  183. getreferencestring:=s;
  184. end;
  185. function getopstr_jmp(const o:toper) : string;
  186. var
  187. hs : string;
  188. begin
  189. case o.typ of
  190. top_reg :
  191. getopstr_jmp:=mpw_reg2str[o.reg.enum];
  192. { no top_ref jumping for powerpc }
  193. top_const :
  194. getopstr_jmp:=tostr(o.val);
  195. top_symbol :
  196. begin
  197. hs:=o.sym.name;
  198. ReplaceForbiddenChars(hs);
  199. if o.symofs>0 then
  200. hs:=hs+'+'+tostr(o.symofs)
  201. else
  202. if o.symofs<0 then
  203. hs:=hs+tostr(o.symofs);
  204. getopstr_jmp:=hs;
  205. end;
  206. top_none:
  207. getopstr_jmp:='';
  208. else
  209. {$ifndef testing}
  210. internalerror(2002070603);
  211. {$else testing}
  212. begin
  213. writeln('internalerror 10001');
  214. halt(1);
  215. end;
  216. {$endif testing}
  217. end;
  218. end;
  219. function getopstr(const o:toper) : string;
  220. var
  221. hs : string;
  222. begin
  223. case o.typ of
  224. top_reg:
  225. getopstr:=mpw_reg2str[o.reg.enum];
  226. { no top_ref jumping for powerpc }
  227. top_const:
  228. getopstr:=tostr(longint(o.val));
  229. top_ref:
  230. getopstr:=getreferencestring(o.ref^);
  231. top_symbol:
  232. begin
  233. hs:=o.sym.name;
  234. ReplaceForbiddenChars(hs);
  235. if o.symofs>0 then
  236. hs:=hs+'+'+tostr(o.symofs)
  237. else
  238. if o.symofs<0 then
  239. hs:=hs+tostr(o.symofs);
  240. getopstr:=hs;
  241. end;
  242. else
  243. {$ifndef testing}
  244. internalerror(2002070604);
  245. {$else testing}
  246. begin
  247. writeln('internalerror 10001');
  248. halt(1);
  249. end;
  250. {$endif testing}
  251. end;
  252. end;
  253. function branchmode(o: tasmop): string[4];
  254. var tempstr: string[4];
  255. begin
  256. tempstr := '';
  257. case o of
  258. A_BCCTR,A_BCCTRL: tempstr := 'ctr';
  259. A_BCLR,A_BCLRL: tempstr := 'lr';
  260. end;
  261. case o of
  262. A_BL,A_BLA,A_BCL,A_BCLA,A_BCCTRL,A_BCLRL: tempstr := tempstr+'l';
  263. end;
  264. case o of
  265. A_BA,A_BLA,A_BCA,A_BCLA: tempstr:=tempstr+'a';
  266. end;
  267. branchmode := tempstr;
  268. end;
  269. function cond2str(op: tasmop; c: tasmcond): string;
  270. { note: no checking is performed whether the given combination of }
  271. { conditions is valid }
  272. var tempstr: string;
  273. begin
  274. tempstr:=#9;
  275. case c.simple of
  276. false: cond2str := tempstr+op2str[op]+#9+tostr(c.bo)+','+
  277. tostr(c.bi);
  278. true:
  279. if (op >= A_B) and (op <= A_BCLRL) then
  280. case c.cond of
  281. { unconditional branch }
  282. C_NONE:
  283. cond2str := tempstr+op2str[op];
  284. { bdnzt etc }
  285. else
  286. begin
  287. tempstr := tempstr+'b'+asmcondflag2str[c.cond]+
  288. branchmode(op)+#9;
  289. case c.cond of
  290. C_LT..C_NU:
  291. cond2str := tempstr+mpw_reg2str[c.cr];
  292. C_T..C_DZF:
  293. cond2str := tempstr+tostr(c.crbit);
  294. end;
  295. end;
  296. end
  297. { we have a trap instruction }
  298. else
  299. begin
  300. internalerror(2002070601);
  301. { not yet implemented !!!!!!!!!!!!!!!!!!!!! }
  302. { case tempstr := 'tw';}
  303. end;
  304. end;
  305. end;
  306. Function GetInstruction(hp : tai):string; {CHANGED from method to proc}
  307. var op: TAsmOp;
  308. s: string;
  309. i: byte;
  310. sep: string[3];
  311. begin
  312. op:=taicpu(hp).opcode;
  313. if is_calljmp(op) then
  314. begin
  315. { direct BO/BI in op[0] and op[1] not supported, put them in condition! }
  316. case op of
  317. A_B,A_BA,A_BLA:
  318. s:=#9+op2str[op]+#9;
  319. A_BCTR,A_BCTRL,A_BLR,A_BLRL:
  320. s:=#9+op2str[op];
  321. A_BL:
  322. s:=#9+op2str[op]+#9'.';
  323. else
  324. s:=cond2str(op,taicpu(hp).condition)+',';
  325. end;
  326. if (taicpu(hp).oper[0].typ <> top_none) then
  327. s:=s+getopstr_jmp(taicpu(hp).oper[0]);
  328. if use_PR then
  329. if op=A_BL then
  330. s:=s+'[PR]';
  331. end
  332. else
  333. { process operands }
  334. begin
  335. case op of
  336. A_MFSPR:
  337. case taicpu(hp).oper[1].reg.enum of
  338. R_CR:
  339. begin
  340. op:=A_MFCR;
  341. taicpu(hp).ops:=1;
  342. end;
  343. R_LR:
  344. begin
  345. op:=A_MFLR;
  346. taicpu(hp).ops:=1;
  347. end;
  348. else
  349. internalerror(2002100701);
  350. end;
  351. A_MTSPR:
  352. case taicpu(hp).oper[1].reg.enum of
  353. R_CR:
  354. begin
  355. op:=A_MTCR;
  356. taicpu(hp).ops:=1;
  357. end;
  358. R_LR:
  359. begin
  360. op:=A_MTLR;
  361. taicpu(hp).ops:=1;
  362. end;
  363. else
  364. internalerror(2002100701);
  365. end;
  366. end;
  367. s:=#9+op2str[op];
  368. if taicpu(hp).ops<>0 then
  369. begin
  370. sep:=#9;
  371. for i:=0 to taicpu(hp).ops-1 do
  372. begin
  373. s:=s+sep+getopstr(taicpu(hp).oper[i]);
  374. sep:=',';
  375. end;
  376. end;
  377. end;
  378. GetInstruction:=s;
  379. end;
  380. {*** Until here is copyed from agppcgas.pp. ***}
  381. function single2str(d : single) : string;
  382. var
  383. hs : string;
  384. p : byte;
  385. begin
  386. str(d,hs);
  387. { nasm expects a lowercase e }
  388. p:=pos('E',hs);
  389. if p>0 then
  390. hs[p]:='e';
  391. p:=pos('+',hs);
  392. if p>0 then
  393. delete(hs,p,1);
  394. single2str:=lower(hs);
  395. end;
  396. function double2str(d : double) : string;
  397. var
  398. hs : string;
  399. p : byte;
  400. begin
  401. str(d,hs);
  402. { nasm expects a lowercase e }
  403. p:=pos('E',hs);
  404. if p>0 then
  405. hs[p]:='e';
  406. p:=pos('+',hs);
  407. if p>0 then
  408. delete(hs,p,1);
  409. double2str:=lower(hs);
  410. end;
  411. function fixline(s:string):string;
  412. {
  413. return s with all leading and ending spaces and tabs removed
  414. }
  415. var
  416. i,j,k : longint;
  417. begin
  418. i:=length(s);
  419. while (i>0) and (s[i] in [#9,' ']) do
  420. dec(i);
  421. j:=1;
  422. while (j<i) and (s[j] in [#9,' ']) do
  423. inc(j);
  424. for k:=j to i do
  425. if s[k] in [#0..#31,#127..#255] then
  426. s[k]:='.';
  427. fixline:=Copy(s,j,i-j+1);
  428. end;
  429. {****************************************************************************
  430. PowerPC MPW Assembler
  431. ****************************************************************************}
  432. procedure TPPCMPWAssembler.GenProcedureHeader(var hp:tai);
  433. {Returns the current hp where the caller should continue from}
  434. {For multiple entry procedures, only the last is exported as xxx[PR]
  435. (if use_PR is set) }
  436. procedure WriteExportHeader(hp:tai);
  437. var
  438. s: string;
  439. replaced: boolean;
  440. begin
  441. s:= tai_symbol(hp).sym.name;
  442. replaced:= ReplaceForbiddenChars(s);
  443. if replaced then
  444. begin
  445. if not use_PR then
  446. AsmWriteLn(#9'export'#9'.'+s+' => ''.'+tai_symbol(hp).sym.name+'''');
  447. AsmWriteLn(#9'export'#9+s+'[DS] => '''+tai_symbol(hp).sym.name+'[DS]''');
  448. end
  449. else
  450. begin
  451. if not use_PR then
  452. AsmWriteLn(#9'export'#9'.'+s);
  453. AsmWriteLn(#9'export'#9+s+'[DS]');
  454. end;
  455. {Entry in transition vector: }
  456. AsmWriteLn(#9'csect'#9+s+'[DS]');
  457. AsmWriteLn(#9'dc.l'#9'.'+s);
  458. AsmWriteln(#9'dc.l'#9'TOC[tc0]');
  459. {Entry in TOC: }
  460. AsmWriteLn(#9'toc');
  461. AsmWriteLn(#9'tc'#9+s+'[TC],'+s+'[DS]');
  462. end;
  463. function GetAdjacentTaiSymbol(var hp:tai):Boolean;
  464. begin
  465. GetAdjacentTaiSymbol:= false;
  466. while assigned(hp.next) do
  467. case tai(hp.next).typ of
  468. ait_symbol:
  469. begin
  470. hp:=tai(hp.next);
  471. GetAdjacentTaiSymbol:= true;
  472. Break;
  473. end;
  474. ait_stab_function_name:
  475. hp:=tai(hp.next);
  476. else
  477. begin
  478. //AsmWriteln(' ;#*#*# ' + tostr(Ord(tai(hp.next).typ)));
  479. Break;
  480. end;
  481. end;
  482. end;
  483. var
  484. first,last: tai;
  485. s: string;
  486. replaced: boolean;
  487. begin
  488. s:= tai_symbol(hp).sym.name;
  489. {Write all headers}
  490. first:= hp;
  491. repeat
  492. WriteExportHeader(hp);
  493. last:= hp;
  494. until not GetAdjacentTaiSymbol(hp);
  495. {Start the section of the body of the proc: }
  496. s:= tai_symbol(last).sym.name;
  497. replaced:= ReplaceForbiddenChars(s);
  498. if use_PR then
  499. if replaced then
  500. AsmWriteLn(#9'export'#9'.'+s+'[PR] => ''.'+tai_symbol(last).sym.name+'[PR]''')
  501. else
  502. AsmWriteLn(#9'export'#9'.'+s+'[PR]');
  503. AsmWriteLn(#9'csect'#9'.'+s+'[PR]'); //starts the section
  504. AsmWriteLn(#9'function'#9'.'+s+'[PR]'); //info for debugger
  505. {$ifdef GDB}
  506. if ((cs_debuginfo in aktmoduleswitches) or
  507. (cs_gdb_lineinfo in aktglobalswitches)) then
  508. begin
  509. //info for debuggers:
  510. firstLineInFunction:= stabslastfileinfo.line;
  511. AsmWriteLn(#9'beginf ' + tostr(firstLineInFunction));
  512. isInFunction:= true;
  513. end;
  514. {$endif}
  515. {Write all labels: }
  516. hp:= first;
  517. repeat
  518. s:= tai_symbol(hp).sym.name;
  519. ReplaceForbiddenChars(s);
  520. AsmWriteLn('.'+s+':');
  521. until not GetAdjacentTaiSymbol(hp);
  522. end;
  523. (*
  524. procedure TPPCMPWAssembler.GenProcedureHeader(hp:tai);
  525. var
  526. s: string;
  527. replaced: boolean;
  528. begin
  529. s:= tai_symbol(hp).sym.name;
  530. replaced:= ReplaceForbiddenChars(s);
  531. if replaced then
  532. begin
  533. AsmWriteLn(#9'export'#9'.'+s+'[PR] => ''.'+tai_symbol(hp).sym.name+'[PR]''');
  534. AsmWriteLn(#9'export'#9+s+'[DS] => '''+tai_symbol(hp).sym.name+'[DS]''');
  535. end
  536. else
  537. begin
  538. AsmWriteLn(#9'export'#9'.'+s+'[PR]');
  539. AsmWriteLn(#9'export'#9+s+'[DS]');
  540. end;
  541. {Entry in transition vector: }
  542. AsmWriteLn(#9'csect'#9+s+'[DS]');
  543. AsmWriteLn(#9'dc.l'#9'.'+s);
  544. AsmWriteln(#9'dc.l'#9'TOC[tc0]');
  545. {Entry in TOC: }
  546. AsmWriteLn(#9'toc');
  547. AsmWriteLn(#9'tc'#9+s+'[TC],'+s+'[DS]');
  548. {Start the section of the body of the proc: }
  549. AsmWriteLn(#9'csect'#9'.'+s+'[PR]');
  550. AsmWriteLn('.'+s+':');
  551. end;
  552. *)
  553. var
  554. LasTSec : TSection;
  555. lastfileinfo : tfileposinfo;
  556. infile,
  557. lastinfile : tinputfile;
  558. const
  559. ait_const2str:array[ait_const_32bit..ait_const_8bit] of string[8]=
  560. (#9'dc.l'#9,#9'dc.w'#9,#9'dc.b'#9);
  561. Function PadTabs(const p:string;addch:char):string;
  562. var
  563. s : string;
  564. i : longint;
  565. begin
  566. i:=length(p);
  567. if addch<>#0 then
  568. begin
  569. inc(i);
  570. s:=p+addch;
  571. end
  572. else
  573. s:=p;
  574. if i<8 then
  575. PadTabs:=s+#9#9
  576. else
  577. PadTabs:=s+#9;
  578. end;
  579. {$ifdef GDB}
  580. procedure TPPCMPWAssembler.WriteFileLineInfo(var fileinfo : tfileposinfo);
  581. var
  582. curr_n : byte;
  583. begin
  584. if not ((cs_debuginfo in aktmoduleswitches) or
  585. (cs_gdb_lineinfo in aktglobalswitches)) then
  586. exit;
  587. { file changed ? (must be before line info) }
  588. if (fileinfo.fileindex<>0) and
  589. (stabslastfileinfo.fileindex<>fileinfo.fileindex) then
  590. begin
  591. infile:=current_module.sourcefiles.get_file(fileinfo.fileindex);
  592. if assigned(infile) then
  593. begin
  594. (*
  595. if includecount=0 then
  596. curr_n:=n_sourcefile
  597. else
  598. curr_n:=n_includefile;
  599. if (infile.path^<>'') then
  600. begin
  601. AsmWriteLn(#9'.stabs "'+lower(BsToSlash(FixPath(infile.path^,false)))+'",'+
  602. tostr(curr_n)+',0,0,'+target_asm.labelprefix+'text'+ToStr(IncludeCount));
  603. end;
  604. AsmWriteLn(#9'.stabs "'+lower(FixFileName(infile.name^))+'",'+
  605. tostr(curr_n)+',0,0,'+target_asm.labelprefix+'text'+ToStr(IncludeCount));
  606. *)
  607. AsmWriteLn(#9'file '''+lower(FixFileName(infile.name^))+'''');
  608. (*
  609. AsmWriteLn(target_asm.labelprefix+'text'+ToStr(IncludeCount)+':');
  610. *)
  611. inc(includecount);
  612. { force new line info }
  613. stabslastfileinfo.line:=-1;
  614. end;
  615. end;
  616. { line changed ? }
  617. if (stabslastfileinfo.line<>fileinfo.line) and (fileinfo.line<>0) then
  618. begin
  619. (*
  620. if (n_line=n_textline) and assigned(funcname) and
  621. (target_info.use_function_relative_addresses) then
  622. begin
  623. AsmWriteLn(target_asm.labelprefix+'l'+tostr(linecount)+':');
  624. AsmWrite(#9'.stabn '+tostr(n_line)+',0,'+tostr(fileinfo.line)+','+
  625. target_asm.labelprefix+'l'+tostr(linecount)+' - ');
  626. AsmWritePChar(FuncName);
  627. AsmLn;
  628. inc(linecount);
  629. end
  630. else
  631. AsmWriteLn(#9'.stabd'#9+tostr(n_line)+',0,'+tostr(fileinfo.line));
  632. *)
  633. if isInFunction then
  634. AsmWriteln(#9'line '+ tostr(fileinfo.line - firstLineInFunction - 1));
  635. end;
  636. stabslastfileinfo:=fileinfo;
  637. end;
  638. procedure TPPCMPWAssembler.WriteFileEndInfo;
  639. begin
  640. if not ((cs_debuginfo in aktmoduleswitches) or
  641. (cs_gdb_lineinfo in aktglobalswitches)) then
  642. exit;
  643. AsmLn;
  644. (*
  645. AsmWriteLn(ait_section2str(sec_code));
  646. AsmWriteLn(#9'.stabs "",'+tostr(n_sourcefile)+',0,0,'+target_asm.labelprefix+'etext');
  647. AsmWriteLn(target_asm.labelprefix+'etext:');
  648. *)
  649. end;
  650. {$endif}
  651. procedure TPPCMPWAssembler.WriteTree(p:TAAsmoutput);
  652. var
  653. s,
  654. prefix,
  655. suffix : string;
  656. hp : tai;
  657. hp1 : tailineinfo;
  658. counter,
  659. lines,
  660. InlineLevel : longint;
  661. i,j,l : longint;
  662. consttyp : taitype;
  663. found,
  664. do_line,DoNotSplitLine,
  665. quoted : boolean;
  666. sep : char;
  667. replaced : boolean;
  668. begin
  669. if not assigned(p) then
  670. exit;
  671. InlineLevel:=0;
  672. { lineinfo is only needed for codesegment (PFV) }
  673. do_line:=((cs_asm_source in aktglobalswitches) or
  674. (cs_lineinfo in aktmoduleswitches))
  675. and (p=codesegment);
  676. DoNotSplitLine:=false;
  677. hp:=tai(p.first);
  678. while assigned(hp) do
  679. begin
  680. if not(hp.typ in SkipLineInfo) and
  681. not DoNotSplitLine then
  682. begin
  683. hp1 := hp as tailineinfo;
  684. {$ifdef GDB}
  685. { write debug info }
  686. if (cs_debuginfo in aktmoduleswitches) or
  687. (cs_gdb_lineinfo in aktglobalswitches) then
  688. WriteFileLineInfo(hp1.fileinfo);
  689. {$endif GDB}
  690. if do_line then
  691. begin
  692. { load infile }
  693. if lastfileinfo.fileindex<>hp1.fileinfo.fileindex then
  694. begin
  695. infile:=current_module.sourcefiles.get_file(hp1.fileinfo.fileindex);
  696. if assigned(infile) then
  697. begin
  698. { open only if needed !! }
  699. if (cs_asm_source in aktglobalswitches) then
  700. infile.open;
  701. end;
  702. { avoid unnecessary reopens of the same file !! }
  703. lastfileinfo.fileindex:=hp1.fileinfo.fileindex;
  704. { be sure to change line !! }
  705. lastfileinfo.line:=-1;
  706. end;
  707. { write source }
  708. if (cs_asm_source in aktglobalswitches) and
  709. assigned(infile) then
  710. begin
  711. if (infile<>lastinfile) then
  712. begin
  713. AsmWriteLn(target_asm.comment+'['+infile.name^+']');
  714. if assigned(lastinfile) then
  715. lastinfile.close;
  716. end;
  717. if (hp1.fileinfo.line<>lastfileinfo.line) and
  718. ((hp1.fileinfo.line<infile.maxlinebuf) or (InlineLevel>0)) then
  719. begin
  720. if (hp1.fileinfo.line<>0) and
  721. ((infile.linebuf^[hp1.fileinfo.line]>=0) or (InlineLevel>0)) then
  722. AsmWriteLn(target_asm.comment+'['+tostr(hp1.fileinfo.line)+'] '+
  723. fixline(infile.GetLineStr(hp1.fileinfo.line)));
  724. { set it to a negative value !
  725. to make that is has been read already !! PM }
  726. if (infile.linebuf^[hp1.fileinfo.line]>=0) then
  727. infile.linebuf^[hp1.fileinfo.line]:=-infile.linebuf^[hp1.fileinfo.line]-1;
  728. end;
  729. end;
  730. lastfileinfo:=hp1.fileinfo;
  731. lastinfile:=infile;
  732. end;
  733. end;
  734. DoNotSplitLine:=false;
  735. case hp.typ of
  736. ait_comment:
  737. begin
  738. AsmWrite(target_asm.comment);
  739. AsmWritePChar(tai_comment(hp).str);
  740. AsmLn;
  741. end;
  742. ait_regalloc,
  743. ait_tempalloc:
  744. ;
  745. ait_section:
  746. begin
  747. {if LasTSec<>sec_none then
  748. AsmWriteLn('_'+target_asm.secnames[LasTSec]+#9#9'ENDS');}
  749. if tai_section(hp).sec<>sec_none then
  750. begin
  751. AsmLn;
  752. AsmWriteLn(#9+target_asm.secnames[tai_section(hp).sec]);
  753. {$ifdef GDB}
  754. lastfileinfo.line:=-1;
  755. {$endif GDB}
  756. end;
  757. LasTSec:=tai_section(hp).sec;
  758. end;
  759. ait_align:
  760. begin
  761. case tai_align(hp).aligntype of
  762. 1:AsmWriteLn(#9'align 0');
  763. 2:AsmWriteLn(#9'align 1');
  764. 4:AsmWriteLn(#9'align 2');
  765. otherwise internalerror(2002110302);
  766. end;
  767. end;
  768. ait_datablock:
  769. begin
  770. s:= tai_datablock(hp).sym.name;
  771. replaced:= ReplaceForbiddenChars(s);
  772. if tai_datablock(hp).is_global then
  773. if replaced then
  774. AsmWriteLn(#9'export'#9+s+'[RW] => '''+tai_datablock(hp).sym.name+'''')
  775. else
  776. AsmWriteLn(#9'export'#9+s+'[RW]');
  777. if not macos_direct_globals then
  778. begin
  779. AsmWriteLn(#9'toc');
  780. AsmWriteLn(#9'tc'#9+s+'[TC], '+s+'[RW]');
  781. AsmWriteLn(#9'csect'#9+s+'[RW]');
  782. AsmWriteLn(#9'ds.b '+tostr(tai_datablock(hp).size));
  783. end
  784. else
  785. begin
  786. AsmWriteLn(#9'csect'#9+s+'[TC]');
  787. AsmWriteLn(PadTabs(s+':',#0)+'ds.b '+tostr(tai_datablock(hp).size));
  788. {TODO: ? PadTabs(s,#0) }
  789. end;
  790. end;
  791. ait_const_32bit,
  792. ait_const_8bit,
  793. ait_const_16bit :
  794. begin
  795. AsmWrite(ait_const2str[hp.typ]+tostr(tai_const(hp).value));
  796. consttyp:=hp.typ;
  797. l:=0;
  798. repeat
  799. found:=(not (tai(hp.next)=nil)) and (tai(hp.next).typ=consttyp);
  800. if found then
  801. begin
  802. hp:=tai(hp.next);
  803. s:=','+tostr(tai_const(hp).value);
  804. AsmWrite(s);
  805. inc(l,length(s));
  806. end;
  807. until (not found) or (l>line_length);
  808. AsmLn;
  809. end;
  810. ait_const_symbol:
  811. begin
  812. (*
  813. AsmWriteLn(#9#9'dd'#9'offset '+tai_const_symbol(hp).sym.name);
  814. if tai_const_symbol(hp).offset>0 then
  815. AsmWrite('+'+tostr(tai_const_symbol(hp).offset))
  816. else if tai_const_symbol(hp).offset<0 then
  817. AsmWrite(tostr(tai_const_symbol(hp).offset));
  818. AsmLn;
  819. *)
  820. s:= tai_const_symbol(hp).sym.name;
  821. ReplaceForbiddenChars(s);
  822. if tai_const_symbol(hp).sym.typ = AT_FUNCTION then
  823. begin
  824. if use_PR then
  825. AsmWriteLn(#9'dc.l'#9'.'+ s +'[PR]')
  826. else
  827. AsmWriteLn(#9'dc.l'#9 + s + '[DS]')
  828. end
  829. else
  830. begin
  831. if macos_direct_globals then
  832. AsmWriteLn(#9'dc.l'#9+s)
  833. else
  834. AsmWriteLn(#9'dc.l'#9+s+const_storage_class);
  835. end;
  836. (* TODO: the following might need to be included. Temporaily we
  837. generate an error
  838. if tai_const_symbol(hp).offset>0 then
  839. AsmWrite('+'+tostr(tai_const_symbol(hp).offset))
  840. else if tai_const_symbol(hp).offset<0 then
  841. AsmWrite(tostr(tai_const_symbol(hp).offset));
  842. *)
  843. if tai_const_symbol(hp).offset <> 0 then
  844. InternalError(2002110101);
  845. AsmLn;
  846. end;
  847. ait_real_32bit:
  848. AsmWriteLn(#9'dc.l'#9'"'+single2str(tai_real_32bit(hp).value)+'"');
  849. ait_real_64bit:
  850. AsmWriteLn(#9'dc.d'#9'"'+double2str(tai_real_64bit(hp).value)+'"');
  851. ait_string:
  852. begin
  853. {NOTE When a single quote char is encountered, it is
  854. replaced with a numeric ascii value. It could also
  855. have been replaced with the escape seq of double quotes.}
  856. counter := 0;
  857. lines := tai_string(hp).len div line_length;
  858. { separate lines in different parts }
  859. if tai_string(hp).len > 0 then
  860. Begin
  861. for j := 0 to lines-1 do
  862. begin
  863. AsmWrite(#9'dc.b'#9);
  864. quoted:=false;
  865. for i:=counter to counter+line_length do
  866. begin
  867. { it is an ascii character. }
  868. if (ord(tai_string(hp).str[i])>31) and
  869. (ord(tai_string(hp).str[i])<128) and
  870. (tai_string(hp).str[i]<>'''') then
  871. begin
  872. if not(quoted) then
  873. begin
  874. if i>counter then
  875. AsmWrite(',');
  876. AsmWrite('''');
  877. end;
  878. AsmWrite(tai_string(hp).str[i]);
  879. quoted:=true;
  880. end { if > 31 and < 128 and ord('"') }
  881. else
  882. begin
  883. if quoted then
  884. AsmWrite('''');
  885. if i>counter then
  886. AsmWrite(',');
  887. quoted:=false;
  888. AsmWrite(tostr(ord(tai_string(hp).str[i])));
  889. end;
  890. end; { end for i:=0 to... }
  891. if quoted then AsmWrite('''');
  892. AsmWrite(target_info.newline);
  893. counter := counter+line_length;
  894. end; { end for j:=0 ... }
  895. { do last line of lines }
  896. AsmWrite(#9'dc.b'#9);
  897. quoted:=false;
  898. for i:=counter to tai_string(hp).len-1 do
  899. begin
  900. { it is an ascii character. }
  901. if (ord(tai_string(hp).str[i])>31) and
  902. (ord(tai_string(hp).str[i])<128) and
  903. (tai_string(hp).str[i]<>'''') then
  904. begin
  905. if not(quoted) then
  906. begin
  907. if i>counter then
  908. AsmWrite(',');
  909. AsmWrite('''');
  910. end;
  911. AsmWrite(tai_string(hp).str[i]);
  912. quoted:=true;
  913. end { if > 31 and < 128 and " }
  914. else
  915. begin
  916. if quoted then
  917. AsmWrite('''');
  918. if i>counter then
  919. AsmWrite(',');
  920. quoted:=false;
  921. AsmWrite(tostr(ord(tai_string(hp).str[i])));
  922. end;
  923. end; { end for i:=0 to... }
  924. if quoted then
  925. AsmWrite('''');
  926. end;
  927. AsmLn;
  928. end;
  929. ait_label:
  930. begin
  931. if tai_label(hp).l.is_used then
  932. begin
  933. s:= tai_label(hp).l.name;
  934. ReplaceForbiddenChars(s);
  935. if s[1] = '@' then
  936. AsmWriteLn(s+':')
  937. else
  938. begin
  939. if not macos_direct_globals then
  940. begin
  941. AsmWriteLn(#9'toc');
  942. AsmWriteLn(#9'tc'#9+s+'[TC], '+s+const_storage_class);
  943. AsmWriteLn(#9'csect'#9+s+const_storage_class);
  944. end
  945. else
  946. begin
  947. AsmWriteLn(#9'csect'#9+s+'[TC]');
  948. AsmWriteLn(PadTabs(s+':',#0));
  949. end;
  950. end;
  951. end;
  952. end;
  953. ait_direct:
  954. begin
  955. AsmWritePChar(tai_direct(hp).str);
  956. AsmLn;
  957. end;
  958. ait_symbol:
  959. begin
  960. if tai_symbol(hp).sym.typ=AT_FUNCTION then
  961. GenProcedureHeader(hp)
  962. else if tai_symbol(hp).sym.typ=AT_DATA then
  963. begin
  964. s:= tai_symbol(hp).sym.name;
  965. replaced:= ReplaceForbiddenChars(s);
  966. if tai_symbol(hp).is_global then
  967. if replaced then
  968. AsmWriteLn(#9'export'#9+s+'[RW] => '''+tai_symbol(hp).sym.name+'''')
  969. else
  970. AsmWriteLn(#9'export'#9+s+'[RW]');
  971. if not macos_direct_globals then
  972. begin
  973. AsmWriteLn(#9'toc');
  974. AsmWriteLn(#9'tc'#9+s+'[TC], '+s+ const_storage_class);
  975. AsmWriteLn(#9'csect'#9+s+ const_storage_class);
  976. end
  977. else
  978. begin
  979. AsmWriteLn(#9'csect'#9+s+'[TC]');
  980. AsmWriteLn(s+':');
  981. end;
  982. end
  983. else
  984. InternalError(2003071301);
  985. end;
  986. ait_symbol_end:
  987. {$ifdef GDB}
  988. if isInFunction then
  989. if ((cs_debuginfo in aktmoduleswitches) or
  990. (cs_gdb_lineinfo in aktglobalswitches)) then
  991. begin
  992. //info for debuggers:
  993. AsmWriteLn(#9'endf ' + tostr(stabslastfileinfo.line));
  994. isInFunction:= false;
  995. end
  996. {$endif GDB}
  997. ;
  998. ait_instruction:
  999. AsmWriteLn(GetInstruction(hp));
  1000. {$ifdef GDB}
  1001. ait_stabn: ;
  1002. ait_stabs: ;
  1003. ait_force_line :
  1004. stabslastfileinfo.line:=0;
  1005. ait_stab_function_name: ;
  1006. {$endif GDB}
  1007. ait_cut :
  1008. begin
  1009. { only reset buffer if nothing has changed }
  1010. if AsmSize=AsmStartSize then
  1011. AsmClear
  1012. else
  1013. begin
  1014. {
  1015. if LasTSec<>sec_none then
  1016. AsmWriteLn('_'+target_asm.secnames[LasTSec]+#9#9'ends');
  1017. AsmLn;
  1018. }
  1019. AsmWriteLn(#9'end');
  1020. AsmClose;
  1021. DoAssemble;
  1022. AsmCreate(tai_cut(hp).place);
  1023. end;
  1024. { avoid empty files }
  1025. while assigned(hp.next) and (tai(hp.next).typ in [ait_cut,ait_section,ait_comment]) do
  1026. begin
  1027. if tai(hp.next).typ=ait_section then
  1028. begin
  1029. lasTSec:=tai_section(hp.next).sec;
  1030. end;
  1031. hp:=tai(hp.next);
  1032. end;
  1033. WriteAsmFileHeader;
  1034. if lasTSec<>sec_none then
  1035. AsmWriteLn(#9+target_asm.secnames[lasTSec]);
  1036. { AsmWriteLn('_'+target_asm.secnames[lasTSec]+#9#9+
  1037. 'SEGMENT'#9'PARA PUBLIC USE32 '''+
  1038. target_asm.secnames[lasTSec]+'''');
  1039. }
  1040. AsmStartSize:=AsmSize;
  1041. end;
  1042. ait_marker :
  1043. begin
  1044. if tai_marker(hp).kind=InlineStart then
  1045. inc(InlineLevel)
  1046. else if tai_marker(hp).kind=InlineEnd then
  1047. dec(InlineLevel);
  1048. end;
  1049. else
  1050. internalerror(2002110303);
  1051. end;
  1052. hp:=tai(hp.next);
  1053. end;
  1054. end;
  1055. var
  1056. currentasmlist : TExternalAssembler;
  1057. procedure writeexternal(p:tnamedindexitem;arg:pointer);
  1058. var
  1059. s:string;
  1060. begin
  1061. if tasmsymbol(p).defbind=AB_EXTERNAL then
  1062. begin
  1063. //Writeln('ZZZ ',p.name,' ',p.classname,' ',Ord(tasmsymbol(p).typ));
  1064. s:= p.name;
  1065. case tasmsymbol(p).typ of
  1066. AT_FUNCTION:
  1067. begin
  1068. if ReplaceForbiddenChars(s) then
  1069. begin
  1070. if not use_PR then
  1071. currentasmlist.AsmWriteLn(#9'import'#9'.'+s+' <= ''.'+p.name+'''')
  1072. else
  1073. currentasmlist.AsmWriteLn(#9'import'#9'.'+s+'[PR] <= ''.'+p.name+'[PR]''');
  1074. currentasmlist.AsmWriteLn(#9'import'#9+s+'[DS] <= '''+p.name+'[DS]''');
  1075. end
  1076. else
  1077. begin
  1078. if not use_PR then
  1079. currentasmlist.AsmWriteLn(#9'import'#9'.'+s)
  1080. else
  1081. currentasmlist.AsmWriteLn(#9'import'#9'.'+s+'[PR]');
  1082. currentasmlist.AsmWriteLn(#9'import'#9+s+'[DS]');
  1083. end;
  1084. currentasmlist.AsmWriteLn(#9'toc');
  1085. currentasmlist.AsmWriteLn(#9'tc'#9+s+'[TC],'+s+'[DS]');
  1086. end
  1087. else
  1088. begin
  1089. if ReplaceForbiddenChars(s) then
  1090. currentasmlist.AsmWriteLn(#9'import'#9+s+'[RW] <= '''+p.name+'''')
  1091. else
  1092. currentasmlist.AsmWriteLn(#9'import'#9+s+'[RW]');
  1093. currentasmlist.AsmWriteLn(#9'toc');
  1094. currentasmlist.AsmWriteLn(#9'tc'#9+s+'[TC],'+s+'[RW]');
  1095. end;
  1096. end;
  1097. end;
  1098. end;
  1099. procedure TPPCMPWAssembler.WriteExternals;
  1100. begin
  1101. currentasmlist:=self;
  1102. objectlibrary.symbolsearch.foreach_static({$ifdef fpcprocvar}@{$endif}writeexternal,nil);
  1103. end;
  1104. function TPPCMPWAssembler.DoAssemble : boolean;
  1105. var f : file;
  1106. begin
  1107. DoAssemble:=Inherited DoAssemble;
  1108. (*
  1109. { masm does not seem to recognize specific extensions and uses .obj allways PM }
  1110. if (aktoutputformat = as_i386_masm) then
  1111. begin
  1112. if not(cs_asm_extern in aktglobalswitches) then
  1113. begin
  1114. if Not FileExists(objfile) and
  1115. FileExists(ForceExtension(objfile,'.obj')) then
  1116. begin
  1117. Assign(F,ForceExtension(objfile,'.obj'));
  1118. Rename(F,objfile);
  1119. end;
  1120. end
  1121. else
  1122. AsmRes.AddAsmCommand('mv',ForceExtension(objfile,'.obj')+' '+objfile,objfile);
  1123. end;
  1124. *)
  1125. end;
  1126. procedure TPPCMPWAssembler.WriteAsmFileHeader;
  1127. begin
  1128. (*
  1129. AsmWriteLn(#9'.386p');
  1130. { masm 6.11 does not seem to like LOCALS PM }
  1131. if (aktoutputformat = as_i386_tasm) then
  1132. begin
  1133. AsmWriteLn(#9'LOCALS '+target_asm.labelprefix);
  1134. end;
  1135. AsmWriteLn('DGROUP'#9'GROUP'#9'_BSS,_DATA');
  1136. AsmWriteLn(#9'ASSUME'#9'CS:_CODE,ES:DGROUP,DS:DGROUP,SS:DGROUP');
  1137. AsmLn;
  1138. *)
  1139. AsmWriteLn(#9'string asis'); {Interpret strings just to be the content between the quotes.}
  1140. AsmLn;
  1141. end;
  1142. procedure TPPCMPWAssembler.WriteAsmList;
  1143. {$ifdef GDB}
  1144. var
  1145. fileinfo : tfileposinfo;
  1146. {$endif GDB}
  1147. begin
  1148. {$ifdef EXTDEBUG}
  1149. if assigned(current_module.mainsource) then
  1150. comment(v_info,'Start writing MPW-styled assembler output for '+current_module.mainsource^);
  1151. {$endif}
  1152. LasTSec:=sec_none;
  1153. {$ifdef GDB}
  1154. FillChar(stabslastfileinfo,sizeof(stabslastfileinfo),0);
  1155. {$endif GDB}
  1156. {$ifdef GDB}
  1157. //n_line:=n_bssline;
  1158. funcname:=nil;
  1159. linecount:=1;
  1160. includecount:=0;
  1161. fileinfo.fileindex:=1;
  1162. fileinfo.line:=1;
  1163. isInFunction:= false;
  1164. firstLineInFunction:= 0;
  1165. { Write main file }
  1166. WriteFileLineInfo(fileinfo);
  1167. {$endif GDB}
  1168. WriteAsmFileHeader;
  1169. WriteExternals;
  1170. { PowerPC MPW ASM doesn't support stabs, as we now.
  1171. WriteTree(debuglist);}
  1172. WriteTree(codesegment);
  1173. WriteTree(datasegment);
  1174. WriteTree(consts);
  1175. WriteTree(rttilist);
  1176. WriteTree(resourcestringlist);
  1177. WriteTree(bsssegment);
  1178. {$ifdef GDB}
  1179. WriteFileEndInfo;
  1180. {$ENDIF}
  1181. AsmWriteLn(#9'end');
  1182. AsmLn;
  1183. {$ifdef EXTDEBUG}
  1184. if assigned(current_module.mainsource) then
  1185. comment(v_info,'Done writing MPW-styled assembler output for '+current_module.mainsource^);
  1186. {$endif EXTDEBUG}
  1187. end;
  1188. {*****************************************************************************
  1189. Initialize
  1190. *****************************************************************************}
  1191. const
  1192. as_powerpc_mpw_info : tasminfo =
  1193. (
  1194. id : as_powerpc_mpw;
  1195. idtxt : 'MPW';
  1196. asmbin : 'PPCAsm';
  1197. asmcmd : '';
  1198. supported_target : system_any; { what should I write here ?? }
  1199. outputbinary: false;
  1200. allowdirect : true;
  1201. needar : true;
  1202. labelprefix_only_inside_procedure : true;
  1203. labelprefix : '@';
  1204. comment : '; ';
  1205. secnames : ('',
  1206. 'csect','csect [TC]','csect [TC]', {TODO: Perhaps use other section types.}
  1207. '','','','','','',
  1208. '','','')
  1209. );
  1210. initialization
  1211. RegisterAssembler(as_powerpc_mpw_info,TPPCMPWAssembler);
  1212. end.
  1213. {
  1214. $Log$
  1215. Revision 1.20 2002-10-01 05:17:27 olle
  1216. * minor fix
  1217. Revision 1.19 2003/04/06 21:01:40 olle
  1218. + line numbers are now emitted in the assembler code
  1219. * bug in export and import directive fixed
  1220. * made code more in sync with aggas.pas
  1221. Revision 1.18 2003/01/13 17:17:50 olle
  1222. * changed global var access, TOC now contain pointers to globals
  1223. * fixed handling of function pointers
  1224. Revision 1.17 2003/01/08 18:43:57 daniel
  1225. * Tregister changed into a record
  1226. Revision 1.16 2002/11/28 10:56:07 olle
  1227. * changed proc ref from .xxx[PR] (refering to its section)
  1228. to .xxx (refering to its label) to allow for multiple ref to a proc.
  1229. Revision 1.15 2002/11/17 16:31:59 carl
  1230. * memory optimization (3-4%) : cleanup of tai fields,
  1231. cleanup of tdef and tsym fields.
  1232. * make it work for m68k
  1233. Revision 1.14 2002/11/07 15:50:23 jonas
  1234. * fixed bctr(l) problems
  1235. Revision 1.13 2002/11/04 18:24:53 olle
  1236. * globals are located in TOC and relative r2, instead of absolute
  1237. * symbols which only differs in case are treated as a single symbol
  1238. + tai_const_symbol supported
  1239. * only refs_full accepted
  1240. Revision 1.12 2002/10/23 15:31:01 olle
  1241. * branch b does not jump to dotted symbol now
  1242. Revision 1.11 2002/10/19 23:52:40 olle
  1243. * import directive changed
  1244. Revision 1.10 2002/10/10 19:39:37 florian
  1245. * changes from Olle to get simple programs compiled and assembled
  1246. Revision 1.9 2002/10/07 21:19:53 florian
  1247. * more mpw fixes
  1248. Revision 1.8 2002/10/06 22:46:20 florian
  1249. * fixed function exporting
  1250. Revision 1.7 2002/10/02 22:14:15 florian
  1251. * improve function imports
  1252. Revision 1.6 2002/09/27 21:09:49 florian
  1253. + readed because previous version was broken
  1254. Revision 1.2 2002/08/31 12:43:31 florian
  1255. * ppc compilation fixed
  1256. Revision 1.1 2002/08/20 21:40:44 florian
  1257. + target macos for ppc added
  1258. + frame work for mpw assembler output
  1259. }