agas.pas 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl
  4. This unit implements an asm for the PowerPC
  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. unit agas;
  19. interface
  20. uses
  21. dos,globals,systems,errors,cobjects,aasm,alpha,strings,files
  22. {$ifdef GDB}
  23. ,gdb
  24. {$endif GDB}
  25. ;
  26. type
  27. paicpuattasmlist=^taicpuattasmlist;
  28. taicpuattasmlist=object(tasmlist)
  29. function getreferencestring(var ref : treference) : string; Virtual;
  30. function getopstr_jmp(const o:toper) : string; Virtual;
  31. procedure WriteInstruction (P : Pai); virtual;
  32. procedure cond2str(op: tasnop; c: tasmcond): string;
  33. { to construct the output for conditional branches }
  34. function branchmode(o: tasmop): string[4];
  35. end;
  36. implementation
  37. const
  38. att_op2str : array[tasmop] of string[14] = ('<none>',
  39. 'add','add.','addo','addo.','addc','addc.','addco','addco.,
  40. 'adde','adde.','addeo','addeo.','addi','addic','addic.','addis,
  41. 'addme','addme.','addmeo','addmeo.','addze','addze.','addzeo,
  42. 'addzeo.','and','and.','andc','andc.','andi.','andis.','b,
  43. 'ba','bl','bla','bc','bca','bcl','bcla','bcctr','bcctrl','bclr,
  44. 'bclrl','cmp','cmpi','cmpl','cmpli','cntlzw','cntlzw.','crand,
  45. 'crandc','creqv','crnand','crnor','cror','crorc','crxor','dcba,
  46. 'dcbf','dcbi','dcbst','dcbt','divw','divw.','divwo','divwo.,
  47. 'divwu','divwu.','divwuo','divwuo.','eciwx','ecowx','eieio','eqv,
  48. 'eqv.','extsb','extsb.','extsh','extsh.','fabs','fabs.','fadd,
  49. 'fadd.','fadds','fadds.','fcompo','fcmpu','fctiw','fctw.','fctwz,
  50. 'fctwz.','fdiv','fdiv.','fdivs','fdivs.','fmadd','fmadd.','fmadds,
  51. 'fmadds.','fmr','fmsub','fmsub.','fmsubs','fmsubs.','fmul','fmul.,
  52. 'fmuls','fmuls.','fnabs','fnabs.','fneg','fneg.','fnmadd,
  53. 'fnmadd.','fnmadds','fnmadds.','fnmsub','fnmsub.','fnmsubs,
  54. 'fnmsubs.','fres','fres.','frsp','frsp.','frsqrte','frsqrte.,
  55. 'fsel','fsel.','fsqrt','fsqrt.','fsqrts','fsqrts.','fsub','fsub.,
  56. 'fsubs','fsubs.','icbi','isync','lbz','lbzu','lbzux','lbzx,
  57. 'lfd','lfdu','lfdux','lfdx','lfs','lfsu','lfsux','lfsx','lha,
  58. 'lhau','lhaux','lhax','hbrx','lhz','lhzu','lhzux','lhzx','lmw,
  59. 'lswi','lswx','lwarx','lwbrx','lwz','lwzu','lwzux','lwzx','mcrf,
  60. 'mcrfs','lcrxe','mfcr','mffs','maffs.','mfmsr','mfspr','mfsr,
  61. 'mfsrin','mftb','mtfcrf','mtfd0','mtfsb1','mtfsf','mtfsf.,
  62. 'mtfsfi','mtfsfi.','mtmsr','mtspr','mtsr','mtsrin','mulhw,
  63. 'mulhw.','mulhwu','mulhwu.','mulli','mullh','mullw.','mullwo,
  64. 'mullwo.','nand','nand.','neg','neg.','nego','nego.','nor','nor.,
  65. 'or','or.','orc','orc.','ori','oris', 'rfi', 'rlwimi', 'rlwimi.',
  66. 'rlwinm', 'tlwinm.','rlwnm','sc','slw', 'slw.', 'sraw', 'sraw.,
  67. 'srawi', 'srawi.','srw', 'srw.', 'stb', 'stbu', 'stbux','stbx','stfd',
  68. 'stfdu', 'stfdux', 'stfdx', 'stfiwx', 'stfs', 'stfsu', 'stfsux', 'stfsx',
  69. 'sth', 'sthbrx', 'sthu', 'sthux', 'sthx', 'stmw', 'stswi', 'stswx', 'stw',
  70. 'stwbrx', 'stwx.', 'stwu', 'stwux', 'stwx', 'subf', 'subf.', 'subfo',
  71. 'subfo.', 'subfc', 'subc.', 'subfco', 'subfco.', 'subfe', 'subfe.',
  72. 'subfeo', 'subfeo.', 'subfic', 'subfme', 'subfme.', 'subfmeo', 'subfmeo.,
  73. 'subfze', 'subfze.', 'subfzeo', 'subfzeo.', 'sync', 'tlbia', 'tlbie,
  74. 'tlbsync', 'tw', 'twi', 'xor', 'xor.', 'xori', 'xoris',
  75. { some simplified mnemonics }
  76. 'subi', 'subis', 'subic', 'subic.', 'sub', 'sub.', 'subo', 'subo.',
  77. 'subc', 'subc.', 'subco', '.subco.', 'cmpwi', 'cmpw', 'cmplwi', 'cmplw',
  78. 'extlwi', 'extlwi.', 'extrwi', 'extrwi.', 'inslwi', 'inslwi.', 'insrwi',
  79. 'insrwi.', 'rotlwi', 'rotlwi.', 'rotlw', 'rotlw.', 'slwi', 'slwi.',
  80. 'srwi', 'srwi.', 'clrlwi', 'clrlwi.', 'clrrwi', 'clrrwi.', 'clrslwi',
  81. 'clrslwi.', 'blr', 'bctr', 'blrl', 'bctrl', 'crset', 'crclr', 'crmove',
  82. 'crnot', 'mt', 'mf','nop', 'li', 'la', 'mr','not', 'mtcr');
  83. function taicpuattasmlist.getreferencestring(var ref : treference) : string;
  84. var
  85. s : string;
  86. begin
  87. if ref.is_immediate then
  88. begin
  89. internalerror(1000101);
  90. exit;
  91. end
  92. else
  93. begin
  94. with ref do
  95. begin
  96. inc(offset,offsetfixup);
  97. if (offset < -32768) or (offset > 32767) then
  98. internalerror(19991);
  99. s:='';
  100. if assigned(symbol) then
  101. s:=s+symbol^.name + symaddr2str[symaddr];
  102. if offset<0 then
  103. s:=s+tostr(offset)
  104. else
  105. if (offset>0) then
  106. begin
  107. if assigned(symbol) then
  108. s:=s+'+'+tostr(offset)
  109. else
  110. s:=s+tostr(offset);
  111. end;
  112. if (index=R_NO) and (base<>R_NO) then
  113. s:=s+'('+att_reg2str[base]+')'
  114. else if (index<>R_NO) and (base<>R_NO) and (offset = 0) then
  115. s:=s+att_reg2str[base]+','+att_reg2str[index]
  116. else if (index<>R_NO) or (base<>R_NO)) then
  117. internalerror(19992);
  118. end;
  119. end;
  120. getreferencestring:=s;
  121. end;
  122. function taicpuattasmlist.getopstr_jmp(const o:toper) : string;
  123. var
  124. hs : string;
  125. begin
  126. case o.typ of
  127. top_reg :
  128. getopstr_jmp:=att_reg2str[o.reg];
  129. { no top_ref jumping for powerpc }
  130. top_const :
  131. getopstr_jmp:=tostr(o.val);
  132. top_symbol :
  133. begin
  134. hs:=o.sym^.name;
  135. if o.symofs>0 then
  136. hs:=hs+'+'+tostr(o.symofs)
  137. else
  138. if o.symofs<0 then
  139. hs:=hs+tostr(o.symofs);
  140. getopstr_jmp:=hs;
  141. end;
  142. else
  143. internalerror(10001);
  144. end;
  145. end;
  146. Procedure taicpuattasmlist.WriteInstruction (P : Pai);
  147. var op: TAsmOp;
  148. s: string;
  149. i: byte;
  150. begin
  151. op:=paicpu(hp)^.opcode;
  152. if not is_calljmp(o) then
  153. s:=#9+att_op2str[op];
  154. else
  155. { direct BO/BI in op[0] and op[1] not supported, put them in condition! }
  156. s:=s+cond2str(op,paicpu(hp)^.condition)+
  157. getopstr_jmp(paicpu(hp)^.oper[0])
  158. else
  159. { process operands }
  160. begin
  161. if paicpu(hp)^.ops<>0 then
  162. begin
  163. if not is_calljmp(op) then
  164. sep := ','
  165. else sep := '#9';
  166. for i:=0 to paicpu(hp)^.ops-1 do
  167. begin
  168. s:=s+sep+getopstr(paicpu(hp)^.oper[i])
  169. sep:=',';
  170. end;
  171. end;
  172. end;
  173. AsmWriteLn(s);
  174. end;
  175. procedure taicpuattasmlist.cond2str(op: tasmop; c: tasmcond): string;
  176. { note: no checking is performed whether the given combination of }
  177. { conditions is valid }
  178. var tempstr: sintrg;
  179. begin
  180. tempstr := '#9';
  181. case c.simple of
  182. false: cond2str := tempstr+att_op2str[op]+'#9'+tostr(c.bo)+','+
  183. tostr(c.bi);
  184. true:
  185. if (op >= A_B) and (op <= A_BCLRL) then
  186. case c.cond of
  187. { unconditional branch }
  188. CF_NONE: condstr := tempstr+op2str(op);
  189. { bdnzt etc }
  190. else
  191. begin
  192. tempstr := tempstr+'b'+asmcondflag2str[c.cond]+
  193. branchmode(op)+'#9';
  194. case op of
  195. CF_LT..CF_NU:
  196. cond2str := tempstr+att_reg2str[c.cr];
  197. CF_T..CF_DZF:
  198. cond2str := tempstr+tostr(c.crbit);
  199. end;
  200. end;
  201. end
  202. { we have a trap instruction }
  203. { not yet implementer !!!!!!!!!!!!!!!!!!!!! }
  204. { else
  205. begin
  206. case tempstr := 'tw';}
  207. end;
  208. end;
  209. function taicpuattasmlist.branchmode(o: tasmop): string[4];
  210. var tempstr: string[4];
  211. begin
  212. tempstr := '';
  213. case o of
  214. A_BCCTR,A_BCCTRL: tempstr := 'ctr'
  215. A_BCLR,A_BCLRL: tempstr := 'lr'
  216. case o of
  217. A_BL,A_BLA,A_BCL,A_BCLA,A_BCCTRL,A_BCLRL: tempstr := tempstr+'l';
  218. end;
  219. case o of
  220. A_BA,A_BLA,A_BCA,A_BCLA: tempstr:=tempstr+'a';
  221. end;
  222. branchmode := tempstr;
  223. end;
  224. end.
  225. {
  226. $Log$
  227. Revision 1.4 2000-01-07 01:14:57 peter
  228. * updated copyright to 2000
  229. Revision 1.3 1999/09/03 13:15:47 jonas
  230. + implemented most necessary methods
  231. Revision 1.2 1999/08/25 12:00:22 jonas
  232. * changed pai386, paippc and paiapha (same for tai*) to paicpu (taicpu)
  233. Revision 1.1 1999/08/03 23:37:52 jonas
  234. + initial implementation for PowerPC based on the Alpha stuff
  235. }