123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- {
- $Id$
- Copyright (c) 1998-2002 by Florian Klaempfl
- This unit implements an asm for the PowerPC
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- ****************************************************************************
- }
- unit agas;
- interface
- uses
- cpubase,dos,globals,systems,{errors,}cobjects,aasm,strings,files,
- agatt
- {$ifdef GDB}
- ,gdb
- {$endif GDB}
- ;
- type
- paicpuattasmlist=^taicpuattasmlist;
- taicpuattasmlist=object(tattasmlist)
- function getreferencestring(var ref : treference) : string; Virtual;
- function getopstr_jmp(const o:toper) : string; Virtual;
- procedure WriteInstruction (HP : Pai); virtual;
- function cond2str(op: tasmop; c: tasmcond): string;
- { to construct the output for conditional branches }
- function branchmode(o: tasmop): string[4];
- end;
- implementation
- uses cpuasm;
- const
- gas_op2str : array[tasmop] of string[14] = ('<none>',
- 'add','add.','addo','addo.','addc','addc.','addco','addco.',
- 'adde','adde.','addeo','addeo.','addi','addic','addic.','addis',
- 'addme','addme.','addmeo','addmeo.','addze','addze.','addzeo',
- 'addzeo.','and','and.','andc','andc.','andi.','andis.','b',
- 'ba','bl','bla','bc','bca','bcl','bcla','bcctr','bcctrl','bclr',
- 'bclrl','cmp','cmpi','cmpl','cmpli','cntlzw','cntlzw.','crand',
- 'crandc','creqv','crnand','crnor','cror','crorc','crxor','dcba',
- 'dcbf','dcbi','dcbst','dcbt','divw','divw.','divwo','divwo.',
- 'divwu','divwu.','divwuo','divwuo.','eciwx','ecowx','eieio','eqv',
- 'eqv.','extsb','extsb.','extsh','extsh.','fabs','fabs.','fadd',
- 'fadd.','fadds','fadds.','fcompo','fcmpu','fctiw','fctw.','fctwz',
- 'fctwz.','fdiv','fdiv.','fdivs','fdivs.','fmadd','fmadd.','fmadds',
- 'fmadds.','fmr','fmsub','fmsub.','fmsubs','fmsubs.','fmul','fmul.',
- 'fmuls','fmuls.','fnabs','fnabs.','fneg','fneg.','fnmadd',
- 'fnmadd.','fnmadds','fnmadds.','fnmsub','fnmsub.','fnmsubs',
- 'fnmsubs.','fres','fres.','frsp','frsp.','frsqrte','frsqrte.',
- 'fsel','fsel.','fsqrt','fsqrt.','fsqrts','fsqrts.','fsub','fsub.',
- 'fsubs','fsubs.','icbi','isync','lbz','lbzu','lbzux','lbzx',
- 'lfd','lfdu','lfdux','lfdx','lfs','lfsu','lfsux','lfsx','lha',
- 'lhau','lhaux','lhax','hbrx','lhz','lhzu','lhzux','lhzx','lmw',
- 'lswi','lswx','lwarx','lwbrx','lwz','lwzu','lwzux','lwzx','mcrf',
- 'mcrfs','mcrxr','lcrxe','mfcr','mffs','maffs.','mfmsr','mfspr','mfsr',
- 'mfsrin','mftb','mtfcrf','mtfd0','mtfsb1','mtfsf','mtfsf.',
- 'mtfsfi','mtfsfi.','mtmsr','mtspr','mtsr','mtsrin','mulhw',
- 'mulhw.','mulhwu','mulhwu.','mulli','mullh','mullw.','mullwo',
- 'mullwo.','nand','nand.','neg','neg.','nego','nego.','nor','nor.',
- 'or','or.','orc','orc.','ori','oris', 'rfi', 'rlwimi', 'rlwimi.',
- 'rlwinm', 'tlwinm.','rlwnm','sc','slw', 'slw.', 'sraw', 'sraw.',
- 'srawi', 'srawi.','srw', 'srw.', 'stb', 'stbu', 'stbux','stbx','stfd',
- 'stfdu', 'stfdux', 'stfdx', 'stfiwx', 'stfs', 'stfsu', 'stfsux', 'stfsx',
- 'sth', 'sthbrx', 'sthu', 'sthux', 'sthx', 'stmw', 'stswi', 'stswx', 'stw',
- 'stwbrx', 'stwx.', 'stwu', 'stwux', 'stwx', 'subf', 'subf.', 'subfo',
- 'subfo.', 'subfc', 'subc.', 'subfco', 'subfco.', 'subfe', 'subfe.',
- 'subfeo', 'subfeo.', 'subfic', 'subfme', 'subfme.', 'subfmeo', 'subfmeo.',
- 'subfze', 'subfze.', 'subfzeo', 'subfzeo.', 'sync', 'tlbia', 'tlbie',
- 'tlbsync', 'tw', 'twi', 'xor', 'xor.', 'xori', 'xoris',
- { some simplified mnemonics }
- 'subi', 'subis', 'subic', 'subic.', 'sub', 'sub.', 'subo', 'subo.',
- 'subc', 'subc.', 'subco', '.subco.', 'cmpwi', 'cmpw', 'cmplwi', 'cmplw',
- 'extlwi', 'extlwi.', 'extrwi', 'extrwi.', 'inslwi', 'inslwi.', 'insrwi',
- 'insrwi.', 'rotlwi', 'rotlwi.', 'rotlw', 'rotlw.', 'slwi', 'slwi.',
- 'srwi', 'srwi.', 'clrlwi', 'clrlwi.', 'clrrwi', 'clrrwi.', 'clrslwi',
- 'clrslwi.', 'blr', 'bctr', 'blrl', 'bctrl', 'crset', 'crclr', 'crmove',
- 'crnot', 'mt', 'mf','nop', 'li', 'lis', 'la', 'mr','not', 'mtcr');
- function taicpuattasmlist.getreferencestring(var ref : treference) : string;
- var
- s : string;
- begin
- if ref.is_immediate then
- begin
- {$ifndef testing}
- internalerror(1000101);
- exit;
- {$else testing}
- writeln('internalerror 1000101');
- halt(1);
- {$endif testing}
- end
- else
- begin
- with ref do
- begin
- inc(offset,offsetfixup);
- if (offset < -32768) or (offset > 32767) then
- {$ifndef testing}
- internalerror(19991);
- {$else testing}
- begin
- writeln('internalerror 19991');
- halt(1);
- end;
- {$endif testing}
- s:='';
- if assigned(symbol) then
- s:=s+symbol^.name + symaddr2str[symaddr];
- if offset<0 then
- s:=s+tostr(offset)
- else
- if (offset>0) then
- begin
- if assigned(symbol) then
- s:=s+'+'+tostr(offset)
- else
- s:=s+tostr(offset);
- end;
- if (index=R_NO) and (base<>R_NO) then
- s:=s+'('+att_reg2str[base]+')'
- else if (index<>R_NO) and (base<>R_NO) and (offset = 0) then
- s:=s+att_reg2str[base]+','+att_reg2str[index]
- else if ((index<>R_NO) or (base<>R_NO)) then
- {$ifndef testing}
- internalerror(19992);
- {$else testing}
- begin
- writeln('internalerror 19992');
- halt(1);
- end;
- {$endif testing}
- end;
- end;
- getreferencestring:=s;
- end;
- function taicpuattasmlist.getopstr_jmp(const o:toper) : string;
- var
- hs : string;
- begin
- case o.typ of
- top_reg :
- getopstr_jmp:=att_reg2str[o.reg];
- { no top_ref jumping for powerpc }
- top_const :
- getopstr_jmp:=tostr(o.val);
- top_symbol :
- begin
- hs:=o.sym^.name;
- if o.symofs>0 then
- hs:=hs+'+'+tostr(o.symofs)
- else
- if o.symofs<0 then
- hs:=hs+tostr(o.symofs);
- getopstr_jmp:=hs;
- end;
- else
- {$ifndef testing}
- internalerror(10001);
- {$else testing}
- begin
- writeln('internalerror 10001');
- halt(1);
- end;
- {$endif testing}
- end;
- end;
- Procedure taicpuattasmlist.WriteInstruction (HP : Pai);
- var op: TAsmOp;
- s: string;
- i: byte;
- sep: string[3];
- begin
- op:=paicpu(hp)^.opcode;
- if is_calljmp(op) then
- { direct BO/BI in op[0] and op[1] not supported, put them in condition! }
- s:=s+cond2str(op,paicpu(hp)^.condition)+
- getopstr_jmp(paicpu(hp)^.oper[0])
- else
- { process operands }
- begin
- s:=#9+gas_op2str[op];
- if paicpu(hp)^.ops<>0 then
- begin
- if not is_calljmp(op) then
- sep := ','
- else sep := '#9';
- for i:=0 to paicpu(hp)^.ops-1 do
- begin
- s:=s+sep+getopstr(paicpu(hp)^.oper[i])
- sep:=',';
- end;
- end;
- end;
- AsmWriteLn(s);
- end;
- function taicpuattasmlist.cond2str(op: tasmop; c: tasmcond): string;
- { note: no checking is performed whether the given combination of }
- { conditions is valid }
- var tempstr: sintrg;
- begin
- tempstr := '#9';
- case c.simple of
- false: cond2str := tempstr+gas_op2str[op]+'#9'+tostr(c.bo)+','+
- tostr(c.bi);
- true:
- if (op >= A_B) and (op <= A_BCLRL) then
- case c.cond of
- { unconditional branch }
- CF_NONE: condstr := tempstr+op2str(op);
- { bdnzt etc }
- else
- begin
- tempstr := tempstr+'b'+asmcondflag2str[c.cond]+
- branchmode(op)+'#9';
- case op of
- CF_LT..CF_NU:
- cond2str := tempstr+att_reg2str[c.cr];
- CF_T..CF_DZF:
- cond2str := tempstr+tostr(c.crbit);
- end;
- end;
- end
- { we have a trap instruction }
- { not yet implementer !!!!!!!!!!!!!!!!!!!!! }
- { else
- begin
- case tempstr := 'tw';}
- end;
- end;
- function taicpuattasmlist.branchmode(o: tasmop): string[4];
- var tempstr: string[4];
- begin
- tempstr := '';
- case o of
- A_BCCTR,A_BCCTRL: tempstr := 'ctr'
- A_BCLR,A_BCLRL: tempstr := 'lr'
- case o of
- A_BL,A_BLA,A_BCL,A_BCLA,A_BCCTRL,A_BCLRL: tempstr := tempstr+'l';
- end;
- case o of
- A_BA,A_BLA,A_BCA,A_BCLA: tempstr:=tempstr+'a';
- end;
- branchmode := tempstr;
- end;
- end.
- {
- $Log$
- Revision 1.6 2002-05-18 13:34:26 peter
- * readded missing revisions
- Revision 1.5 2002/05/16 19:46:52 carl
- + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
- + try to fix temp allocation (still in ifdef)
- + generic constructor calls
- + start of tassembler / tmodulebase class cleanup
- Revision 1.3 2002/04/20 21:41:51 carl
- * renamed some constants
- Revision 1.2 2002/04/06 18:13:01 jonas
- * several powerpc-related additions and fixes
- }
|