From: Torbjorn Granlund Date: Thu, 19 Jan 1995 13:59:13 +0000 (+0000) Subject: Fix for PR 6200 (SUBC problems). X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=acae2683a9b2487b2ec93614e6ddc69de776d3ac;p=binutils-gdb.git Fix for PR 6200 (SUBC problems). --- diff --git a/sim/sh/ChangeLog b/sim/sh/ChangeLog index 034043b4c29..3dd94dd23af 100644 --- a/sim/sh/ChangeLog +++ b/sim/sh/ChangeLog @@ -1,3 +1,7 @@ +Thu Jan 19 05:50:50 1995 Torbjorn Granlund + + * gecode.c (op_tab): Replace code for ADDC and SUBC. + Mon Jan 9 15:43:53 1995 Stu Grossman (grossman@cygnus.com) * interp.c: Remove def of INLINE. This comes from bfd.h. Also, diff --git a/sim/sh/gencode.c b/sim/sh/gencode.c index 8b495e5dad1..e171848e110 100644 --- a/sim/sh/gencode.c +++ b/sim/sh/gencode.c @@ -23,13 +23,18 @@ -t prints a pretty table for the assembler manual -s generates the simulator code jump table + -d generates a define table -x generates the simulator code switch statement default generates the opcode tables */ +#include + typedef struct { +char *defs; +char *refs; char *name; char *code; char *stuff[10]; @@ -42,159 +47,171 @@ op; op tab[] = { - {"add #,", "0111nnnni8*1....", "R[n] += SEXT(i);"}, - {"add ,", "0011nnnnmmmm1100", "R[n] += R[m];"}, - {"addc ,", "0011nnnnmmmm1110", "ult = R[n]; R[n] += (R[m]+T); T = ult>R[n];"}, - {"addv ,", "0011nnnnmmmm1111", - "long ans;", - "ans = R[n] + R[m];", + {"n","","add #,", "0111nnnni8*1....", "R[n] += SEXT(i);if (i == 0) { UNDEF(n); break; } "}, + {"n","mn","add ,", "0011nnnnmmmm1100", "R[n] += R[m];"}, + {"n","mn","addc ,", "0011nnnnmmmm1110", "ult=R[n]+T;T=ult,", "0011nnnnmmmm1111", + "{long ans;", + " ans = R[n] + R[m];", "T = ((~R[n] & R[m] & ans) | (R[n] & R[m] & ~ans)) >>31;", - "R[n] = ans;"}, - - {"and #,R0", "11001001i8*1....", "R0&=i;"}, - {"and ,", "0010nnnnmmmm1001", "R[n]&=R[m];"}, - {"and.b #,@(R0,GBR)", "11001101i8*1....", "WBAT(GBR+R0, RBAT(GBR+R0) & i);"}, - - {"bf ", "10001011i8p1....", "if(T==0) {PC+=(SEXT(i)<<1)+2;C+=2;}"}, - {"bra ", "1010i12.........", "ult = PC; PC=PC+(i<<1)+2;SL(ult+2);"}, - {"bsr ", "1011i12.........", "PR = PC; PC=PC+(i<<1)+2;SL(PR+2);"}, - {"bt ", "10001001i8p1....", "if(T==1) {PC+=(SEXT(i)<<1)+2;C+=2;}"}, - {"clrmac", "0000000000101000", "MACH = MACL = 0;"}, - {"clrt", "0000000000001000", "T= 0;"}, - {"cmp/eq #,R0", "10001000i8*1....", "T = R0 == SEXT(i);"}, - {"cmp/eq ,", "0011nnnnmmmm0000", "T=R[n]==R[m];"}, - {"cmp/ge ,", "0011nnnnmmmm0011", "T=R[n]>=R[m];"}, - {"cmp/gt ,", "0011nnnnmmmm0111", "T=R[n]>R[m];"}, - {"cmp/hi ,", "0011nnnnmmmm0110", "T=UR[n]>UR[m];"}, - {"cmp/hs ,", "0011nnnnmmmm0010", "T=UR[n]>=UR[m];"}, - {"cmp/pl ", "0100nnnn00010101", "T = R[n]>0;"}, - {"cmp/pz ", "0100nnnn00010001", "T = R[n]>=0;"}, - {"cmp/str ,", "0010nnnnmmmm1100", "ult = R[n] ^ R[m]; T=((ult&0xff000000)==0) |((ult&0xff0000)==0) |((ult&0xff00)==0) |((ult&0xff)==0); "}, - {"div0s ,", "0010nnnnmmmm0111", "Q=R[n]<0; M=R[m]<0; T=M!=Q;;"}, - {"div0u", "0000000000011001", "M=Q=T=0;"}, - {"div1 ,", "0011nnnnmmmm0100", "T=div1(R,n,m,T);"}, - {"exts.b ,", "0110nnnnmmmm1110", "R[n] = SEXT(R[m]);"}, - {"exts.w ,", "0110nnnnmmmm1111", "R[n] = SEXTW(R[m]);"}, - {"extu.b ,", "0110nnnnmmmm1100", "R[n] = R[m] & 0xff;"}, - {"extu.w ,", "0110nnnnmmmm1101", "R[n] = R[m] & 0xffff;"}, - {"jmp @", "0100nnnn00101011", "ult = PC; PC=R[n]-2; SL(ult+2);"}, - {"jsr @", "0100nnnn00001011", "PR = PC; PC=R[n]-2; SL(PR+2);"}, - {"ldc ,GBR", "0100nnnn00011110", "GBR=R[n];"}, - {"ldc ,SR", "0100nnnn00001110", "SET_SR(R[n]);"}, - {"ldc ,VBR", "0100nnnn00101110", "VBR=R[n];"}, - {"ldc.l @+,GBR", "0100nnnn00010111", "GBR=RLAT(R[n]);R[n]+=4;;"}, - {"ldc.l @+,SR", "0100nnnn00000111", "SET_SR(RLAT(R[n]));R[n]+=4;;"}, - {"ldc.l @+,VBR", "0100nnnn00100111", "VBR=RLAT(R[n]);R[n]+=4;;"}, - {"lds ,MACH", "0100nnnn00001010", "MACH = SEXT(R[n]);"}, - {"lds ,MACL", "0100nnnn00011010", "MACL= R[n];"}, - {"lds ,PR", "0100nnnn00101010", "PR = R[n];"}, - {"lds.l @+,MACH", "0100nnnn00000110", "MACH = SEXT(RLAT(R[n]));R[n]+=4;"}, - {"lds.l @+,MACL", "0100nnnn00010110", "MACL = RLAT(R[n]);R[n]+=4;"}, - {"lds.l @+,PR", "0100nnnn00100110", "PR = RLAT(R[n]);R[n]+=4;;"}, - {"mac.w @+,@+", "0100nnnnmmmm1111", "abort();"}, - {"mov #,", "1110nnnni8*1....", "R[n] = SEXT(i);"}, - {"mov ,", "0110nnnnmmmm0011", "R[n] = R[m];"}, -{"mov.b ,@(R0,)", "0000nnnnmmmm0100", "WBAT(R[n]+R0, R[m]);"}, -{"mov.b ,@-", "0010nnnnmmmm0100", "R[n]--; WBAT(R[n], R[m]);"}, - {"mov.b ,@", "0010nnnnmmmm0000", "WBAT(R[n], R[m]);"}, - {"mov.b @(,),R0", "10000100mmmmi4*1", "R0=RBAT(i+R[m]);"}, - {"mov.b @(,GBR),R0", "11000100i8*1....", "R0=RBAT(i+GBR);"}, - {"mov.b @(R0,),", "0000nnnnmmmm1100", "R[n]=RBAT(R0+R[m]);"}, -{"mov.b @+,", "0110nnnnmmmm0100", "R[n] = RBAT(R[m]);R[m]++;"}, - {"mov.b @,", "0110nnnnmmmm0000", "R[n]=RBAT(R[m]);"}, - {"mov.b R0,@(,)", "10000000mmmmi4*1", "R0=RBAT(i+R[m]);"}, - {"mov.b R0,@(,GBR)", "11000000i8*1....", "R0 = RBAT(i+GBR);"}, - {"mov.l ,@(,)", "0001nnnnmmmmi4*4", "WLAT(i+R[n],R[m]);"}, - {"mov.l ,@(R0,)", "0000nnnnmmmm0110", "WLAT(R0+R[n],R[m]);"}, -{"mov.l ,@-", "0010nnnnmmmm0110", "R[n]-=4;WLAT(R[n],R[m]);"}, - {"mov.l ,@", "0010nnnnmmmm0010", "WLAT(R[n], R[m]);"}, - {"mov.l @(,),", "0101nnnnmmmmi4*4", "R[m]=RLAT(i+R[n]);"}, - {"mov.l @(,GBR),R0", "11000110i4*4", "R0=RLAT(i+GBR);"}, - {"mov.l @(,PC),", "1101nnnni8p4....", "R[n]=RLAT(i+4+PC);"}, - {"mov.l @(R0,),", "0000nnnnmmmm1110", "R[n]=RLAT(R0+R[m]);"}, -{"mov.l @+,", "0110nnnnmmmm0110", "R[n]=RLAT(R[m]);R[m]+=4;"}, - {"mov.l @,", "0110nnnnmmmm0010", "R[n]=RLAT(R[m]);"}, - {"mov.l R0,@(,GBR)", "11000010i8*4....", "R0=RLAT(R0+GBR);"}, - {"mov.w ,@(R0,)", "0000nnnnmmmm0101", "WWAT(R0+R[n],R[m]);"}, -{"mov.w ,@-", "0010nnnnmmmm0101", "R[n]-=2;WWAT(R[n],R[m]);"}, - {"mov.w ,@", "0010nnnnmmmm0001", "WWAT(R[n],R[m]);"}, - {"mov.w @(,),R0", "10000101mmmmi4*2", "R0=RSWAT(i+R[m]);"}, - {"mov.w @(,GBR),R0", "11000101i8*2....", "R0=RSWAT(i+GBR);"}, - {"mov.w @(,PC),", "1001nnnni8p2....", "R[n]=RSWAT(PC+i+4);"}, -{"mov.w @(R0,),", "0000nnnnmmmm1101", "R[n]=RSWAT(R0+R[m]);"}, -{"mov.w @+,", "0110nnnnmmmm0101", "R[n]=RSWAT(R[m]);R[m]+=2;"}, - {"mov.w @,", "0110nnnnmmmm0001", "R[n]=RSWAT(R[m]);"}, - {"mov.w R0,@(,)", "10000001mmmmi4*2", "R0=RSWAT(i+R[m]);"}, - {"mov.w R0,@(,GBR)", "11000001i8*2....", "R0=RSWAT(i+GBR);"}, - {"mova @(,PC),R0", "11000111i8p4....", "R0=i+4+PC;"}, - {"movt ", "0000nnnn00101001", "R[n]=T;"}, - {"muls ,", "0010nnnnmmmm1111", - "MACL=((long)(short)R[n])*((long)(short)R[m]);"}, -{"mulu ,","0010nnnnmmmm1110", "MACL=((unsigned long)(unsigned short)R[n])*((unsigned long)(unsigned short)R[m]);"}, - {"neg ,", "0110nnnnmmmm1011", "R[n] = - R[m];"}, - {"negc ,", "0110nnnnmmmm1010", "ult=0-R[m];R[n]=ult-T;T=SBIT(R[n])!=SBIT(ult);"}, - {"nop", "0000000000001001", ""}, - {"not ,", "0110nnnnmmmm0111", "R[n]=~R[m];"}, - {"or #,R0", "11001011i8*1....", "R0|=i;"}, - {"or ,", "0010nnnnmmmm1011", "R[n]|=R[m];"}, - {"or.b #,@(R0,GBR)", "11001111i8*1....", "WBAT(R0+GBR,RBAT(R0+GBR)|i);"}, - {"rotcl ", "0100nnnn00100100", "ult = R[n] <0;R[n] = (R[n]<<1)|T;T=ult;"}, - {"rotcr ", "0100nnnn00100101", "ult = R[n]&1;R[n]=(UR[n]>>1)|(T<<31);T=ult;"}, - {"rotl ", "0100nnnn00000100", "T=R[n]<0;R[n]<<=1;R[n]|=T;"}, - {"rotr ", "0100nnnn00000101", "T=R[n]&1;UR[n]>>=1;R[n]|=(T<<31);"}, - {"rte", "0000000000101011", "abort();"}, - {"rts", "0000000000001011", "ult=PC;PC=PR+2;SL(ult+2);"}, - {"sett", "0000000000011000", "T=1;"}, - {"shal ", "0100nnnn00100000", "T=R[n]<0; R[n]<<=1;"}, - {"shar ", "0100nnnn00100001", "T=R[n]&1; R[n]>>=1;"}, - {"shll ", "0100nnnn00000000", "T=R[n]<0; R[n]<<=1;"}, - {"shll16 ", "0100nnnn00101000", "R[n]<<=16;"}, - {"shll2 ", "0100nnnn00001000", "R[n]<<=2;"}, - {"shll8 ", "0100nnnn00011000", "R[n]<<=8;"}, - {"shlr ", "0100nnnn00000001", "T=R[n]&1;R[n]=UR[n]>>1;"}, - {"shlr16 ", "0100nnnn00101001", "R[n]=UR[n]>>16;"}, - {"shlr2 ", "0100nnnn00001001", "R[n]=UR[n]>>2;"}, - {"shlr8 ", "0100nnnn00011001", "R[n]=UR[n]>>8;"}, - {"sleep", "0000000000011011", "abort();"}, - {"stc GBR,", "0000nnnn00010010", "R[n]=GBR;"}, - {"stc SR,", "0000nnnn00000010", "R[n]=GET_SR();"}, - {"stc VBR,", "0000nnnn00100010", "R[n]=VBR;"}, - {"stc.l GBR,@-", "0100nnnn00010011", "R[n]-=4;WLAT(R[n],GBR);;"}, - {"stc.l SR,@-", "0100nnnn00000011", "R[n]-=4;WLAT(R[n],GET_SR());"}, - {"stc.l VBR,@-", "0100nnnn00100011", "R[n]-=4;WLAT(R[n],VBR);"}, - {"sts MACH,", "0000nnnn00001010", "R[n]=MACH;"}, - {"sts MACL,", "0000nnnn00011010", "R[n]=MACL;"}, - {"sts PR,", "0000nnnn00101010", "R[n]=PR;"}, - {"sts.l MACH,@-", "0100nnnn00000010", "R[n]-=4;WLAT(R[n],MACH);"}, - {"sts.l MACL,@-", "0100nnnn00010010", "R[n]-=4;WLAT(R[n],MACL);"}, - {"sts.l PR,@-", "0100nnnn00100010", "R[n]-=4;WLAT(R[n],PR);"}, - {"sub ,", "0011nnnnmmmm1000", "R[n]-=R[m];"}, - {"subc ,", "0011nnnnmmmm1010", "ult = R[n];R[n]-=R[m]+T;T=ult,", "0011nnnnmmmm1011", "abort();"}, - {"swap.b ,", "0110nnnnmmmm1000", "R[n]=((R[m]<<8)&0xff00)|((R[m]>>8)&0x00ff);"}, - {"swap.w ,", "0110nnnnmmmm1001", "R[n]=((R[m]<<16)&0xffff0000)|((R[m]>>16)&0x00ffff);"}, - {"tas.b @", "0100nnnn00011011", "ult=RBAT(R[n]);T=ult==0;WBAT(R[n],ult|0x80);"}, - {"trapa #", "11000011i8*1....", "trap(i,R);"}, - {"tst #,R0", "11001000i8*1....", "T=(R0&i)==0;"}, - {"tst ,", "0010nnnnmmmm1000", "T=(R[n]&R[m])==0;"}, - {"tst.b #,@(R0,GBR)", "11001100i8*1....", "T=(RBAT(GBR+R0)&i)==0;"}, - {"xor #,R0", "11001010i8*1....", "R0^=i;"}, - {"xor ,", "0010nnnnmmmm1010", "R[n]^=R[m];"}, - {"xor.b #,@(R0,GBR)", "11001110i8*1....", "ult=RBAT(GBR+R0);ult^=i;WBAT(GBR+R0,ult);"}, - {"xtrct ,", "0010nnnnmmmm1101", "R[n]=((R[n]>>16)&0xffff)|((R[m]<<16)&0xffff0000);"}, - + "R[n] = ans;}"}, + + {"0","","and #,R0", "11001001i8*1....", ";R0&=i;"}, + {"n","nm","and ,", "0010nnnnmmmm1001", " R[n]&=R[m];"}, + {"","0","and.b #,@(R0,GBR)", "11001101i8*1....", ";WBAT(GBR+R0, RBAT(GBR+R0) & i);"}, + + {"","","bra ", "1010i12.........", "ult = PC; PC=PC+(i<<1)+2;SL(ult+2);"}, + {"","","bsr ", "1011i12.........", "PR = PC; PC=PC+(i<<1)+2;SL(PR+2);"}, + {"","","bt ", "10001001i8p1....", "if(T) {PC+=(SEXT(i)<<1)+2;C+=2;}"}, + {"","","bf ", "10001011i8p1....", "if(T==0) {PC+=(SEXT(i)<<1)+2;C+=2;}"}, + {"","","bt.s ", "10001101i8p1....","if(T) {ult = PC; PC+=(SEXT(i)<<1)+2;C+=2;SL(ult+2);}"}, + {"","","bf.s ", "10001111i8p1....","if(!T) {ult = PC; PC+=(SEXT(i)<<1)+2;C+=2;SL(ult+2);}"}, + {"","","clrmac", "0000000000101000", "MACH = MACL = 0;"}, + {"","","clrt", "0000000000001000", "T= 0;"}, + {"","0","cmp/eq #,R0", "10001000i8*1....", ";T = R0 == SEXT(i);"}, + {"","mn","cmp/eq ,", "0011nnnnmmmm0000", "T=R[n]==R[m];"}, + {"","mn","cmp/ge ,", "0011nnnnmmmm0011", "T=R[n]>=R[m];"}, + {"","mn","cmp/gt ,", "0011nnnnmmmm0111", "T=R[n]>R[m];"}, + {"","mn","cmp/hi ,", "0011nnnnmmmm0110", "T=UR[n]>UR[m];"}, + {"","mn","cmp/hs ,", "0011nnnnmmmm0010", "T=UR[n]>=UR[m];"}, + {"","n","cmp/pl ", "0100nnnn00010101", "T = R[n]>0;"}, + {"","n","cmp/pz ", "0100nnnn00010001", "T = R[n]>=0;"}, + {"","mn","cmp/str ,", "0010nnnnmmmm1100", + "ult = R[n] ^ R[m]; T=((ult&0xff000000)==0) |((ult&0xff0000)==0) |((ult&0xff00)==0) |((ult&0xff)==0); "}, + {"","mn","div0s ,", "0010nnnnmmmm0111", "Q=(R[n]&sbit)!=0; M=(R[m]&sbit)!=0; T=M!=Q;;"}, + {"","","div0u", "0000000000011001", "M=Q=T=0;"}, + {"","","div1 ,", "0011nnnnmmmm0100", "T=div1(R,m,n,T);"}, + {"n","m","exts.b ,", "0110nnnnmmmm1110", "R[n] = SEXT(R[m]);"}, + {"n","m","exts.w ,", "0110nnnnmmmm1111", "R[n] = SEXTW(R[m]);"}, + {"n","m","extu.b ,", "0110nnnnmmmm1100", "R[n] = R[m] & 0xff;"}, + {"n","m","extu.w ,", "0110nnnnmmmm1101", "R[n] = R[m] & 0xffff;"}, + {"","n","jmp @", "0100nnnn00101011", "ult = PC; PC=R[n]-2; SL(ult+2);"}, + {"","n","jsr @", "0100nnnn00001011", "PR = PC; PC=R[n]-2; if (~doprofile) gotcall(PR,PC+2);SL(PR+2);"}, + {"","n","ldc ,GBR", "0100nnnn00011110", "GBR=R[n];"}, + {"","n","ldc ,SR", "0100nnnn00001110", "SET_SR(R[n]);"}, + {"","n","ldc ,VBR", "0100nnnn00101110", "VBR=R[n];"}, + {"","n","ldc.l @+,GBR", "0100nnnn00010111", "GBR=RLAT(R[n]);R[n]+=4;;"}, + {"","n","ldc.l @+,SR", "0100nnnn00000111", "SET_SR(RLAT(R[n]));R[n]+=4;;"}, + {"","n","ldc.l @+,VBR", "0100nnnn00100111", "VBR=RLAT(R[n]);R[n]+=4;;"}, + {"","n","lds ,MACH", "0100nnnn00001010", "MACH = R[n];"}, + {"","n","lds ,MACL", "0100nnnn00011010", "MACL= R[n];"}, + {"","n","lds ,PR", "0100nnnn00101010", "PR = R[n];"}, + {"","n","lds.l @+,MACH", "0100nnnn00000110", "MACH = SEXT(RLAT(R[n]));R[n]+=4;"}, + {"","n","lds.l @+,MACL", "0100nnnn00010110", "MACL = RLAT(R[n]);R[n]+=4;"}, + {"","n","lds.l @+,PR", "0100nnnn00100110", "PR = RLAT(R[n]);R[n]+=4;;"}, + {"","n","mac.w @+,@+", "0100nnnnmmmm1111", "abort();"}, + {"n","","mov #,", "1110nnnni8*1....", "R[n] = SEXT(i);"}, + {"n","m","mov ,", "0110nnnnmmmm0011", "R[n] = R[m];"}, + {"","mn0","mov.b ,@(R0,)", "0000nnnnmmmm0100", "WBAT(R[n]+R0, R[m]);"}, + {"","nm","mov.b ,@-", "0010nnnnmmmm0100", "R[n]--; WBAT(R[n],R[m]);"}, + {"","mn","mov.b ,@", "0010nnnnmmmm0000", "WBAT(R[n], R[m]);"}, + {"0","m","mov.b @(,),R0", "10000100mmmmi4*1", "R0=RSBAT(i+R[m]);L(0);"}, + {"0","","mov.b @(,GBR),R0", "11000100i8*1....", "R0=RSBAT(i+GBR);L(0);"}, + {"n","0m","mov.b @(R0,),", "0000nnnnmmmm1100", "R[n]=RSBAT(R0+R[m]);L(n);"}, + {"n","m","mov.b @+,", "0110nnnnmmmm0100", "R[n] = RSBAT(R[m]);L(n);R[m]++;"}, + {"n","m","mov.b @,", "0110nnnnmmmm0000", "R[n]=RSBAT(R[m]);L(n);"}, + {"","m0","mov.b R0,@(,)", "10000000mmmmi4*1", "WBAT(i+R[m],R0);"}, + {"","0","mov.b R0,@(,GBR)", "11000000i8*1....", "WBAT(i+GBR,R0);"}, + {"","nm","mov.l ,@(,)", "0001nnnnmmmmi4*4", "WLAT(i+R[n],R[m]);"}, + {"","nm0","mov.l ,@(R0,)", "0000nnnnmmmm0110", "WLAT(R0+R[n],R[m]);"}, + {"","nm","mov.l ,@-", "0010nnnnmmmm0110", "R[n]-=4;WLAT(R[n],R[m]);"}, + {"","nm","mov.l ,@", "0010nnnnmmmm0010", "WLAT(R[n], R[m]);"}, + {"n","m","mov.l @(,),","0101nnnnmmmmi4*4", "R[n]=RLAT(i+R[m]);L(n);"}, + {"0","","mov.l @(,GBR),R0", "11000110i8*4....", "R0=RLAT(i+GBR);L(0);"}, + {"n","","mov.l @(,PC),", "1101nnnni8p4....", "R[n]=RLAT((i+4+PC) & ~3);L(n);"}, + {"n","m","mov.l @(R0,),", "0000nnnnmmmm1110", "R[n]=RLAT(R0+R[m]);L(n);"}, +{"nm","m","mov.l @+,", "0110nnnnmmmm0110", "R[n]=RLAT(R[m]);R[m]+=4;L(n);"}, + {"n","m","mov.l @,", "0110nnnnmmmm0010", "R[n]=RLAT(R[m]);L(n);"}, + {"","0","mov.l R0,@(,GBR)", "11000010i8*4....", "WLAT(i+GBR,R0);"}, + {"","m0n","mov.w ,@(R0,)", "0000nnnnmmmm0101", "WWAT(R0+R[n],R[m]);"}, +{"n","mn","mov.w ,@-", "0010nnnnmmmm0101", "R[n]-=2;WWAT(R[n],R[m]);"}, + {"","nm","mov.w ,@", "0010nnnnmmmm0001", "WWAT(R[n],R[m]);"}, + {"0","m","mov.w @(,),R0", "10000101mmmmi4*2", "R0=RSWAT(i+R[m]);L(0);"}, + {"0","","mov.w @(,GBR),R0", "11000101i8*2....", "R0=RSWAT(i+GBR);L(0);"}, + {"n","","mov.w @(,PC),", "1001nnnni8p2....", "R[n]=RSWAT(PC+i+4);L(n);"}, +{"n","m0","mov.w @(R0,),", "0000nnnnmmmm1101", "R[n]=RSWAT(R0+R[m]);L(n);"}, +{"nm","n","mov.w @+,", "0110nnnnmmmm0101", "R[n]=RSWAT(R[m]);R[m]+=2;L(n);"}, + {"n","m","mov.w @,", "0110nnnnmmmm0001", "R[n]=RSWAT(R[m]);L(n);"}, + {"","0m","mov.w R0,@(,)", "10000001mmmmi4*2", "WWAT(i+R[m],R0);"}, + {"","0","mov.w R0,@(,GBR)", "11000001i8*2....", "WWAT(i+GBR,R0);"}, + {"0","","mova @(,PC),R0", "11000111i8p4....", "R0=((i+4+PC) & ~0x3);"}, + {"n","","movt ", "0000nnnn00101001", "R[n]=T;"}, + {"","mn","muls ,", "0010nnnnmmmm1111","MACL=((int)(short)R[n])*((int)(short)R[m]);"}, + {"","mn","mul.l ,","0000nnnnmmmm0111","MACL=((int)R[n])*((int)R[m]);"}, + {"","mn","mulu ,", "0010nnnnmmmm1110","MACL=((unsigned int)(unsigned short)R[n])*((unsigned int)(unsigned short)R[m]);"}, + {"n","m","neg ,", "0110nnnnmmmm1011", "R[n] = - R[m];"}, + {"n","m","negc ,", "0110nnnnmmmm1010", + "ult=R[m]; R[n]=0-R[m]-T;T=SBIT(R[n])!=SBIT(ult); "}, + {"","","nop", "0000000000001001", ""}, + {"n","m","not ,", "0110nnnnmmmm0111", "R[n]=~R[m];"}, + {"0","","or #,R0", "11001011i8*1....", "R0|=i;"}, + {"n","m","or ,", "0010nnnnmmmm1011", "R[n]|=R[m];"}, + {"","0","or.b #,@(R0,GBR)", "11001111i8*1....", "WBAT(R0+GBR,RBAT(R0+GBR)|i);"}, +{"n","n","rotcl ", "0100nnnn00100100", "ult=R[n]<0;R[n]=(R[n]<<1)|T;T=ult;"}, + {"n","n","rotcr ", "0100nnnn00100101", "ult=R[n]&1;R[n]=(UR[n]>>1)|(T<<31);T=ult;"}, + {"n","n","rotl ", "0100nnnn00000100", "T=R[n]<0;R[n]<<=1;R[n]|=T;"}, + {"n","n","rotr ", "0100nnnn00000101", "T=R[n]&1;R[n] = UR[n]>> 1;R[n]|=(T<<31);"}, + {"","","rte", "0000000000101011", + "{ int tmp = PC; PC=RLAT(R[15])+2;R[15]+=4;SET_SR(RLAT(R[15]) & 0x3f3);R[15]+=4;SL(tmp+2);}"}, + {"","","rts", "0000000000001011", "ult=PC;PC=PR+2;SL(ult+2);"}, + {"","","sett", "0000000000011000", "T=1;"}, + +/* start-sanitize-sh3 */ + {"n","mn","shad ,", "0100nnnnmmmm1100", + "R[n] = (R[m] < 0) ? (((int)R[n]) >> -(R[m]&0x1f) ): (R[n] << ((R[m]) & 0x1f)) ;"}, + + {"n","mn","shld ,", "0100nnnnmmmm1101", + "R[n] = (R[m] < 0) ? (((unsigned int)R[n]) >> -(R[m]&0x1f) ): (R[n] << ((R[m]) & 0x1f)) ;"}, +/* end-sanitize-sh3 */ + {"n","n","shal ", "0100nnnn00100000", "T=R[n]<0; R[n]<<=1;"}, + {"n","n","shar ", "0100nnnn00100001", "T=R[n]&1; R[n] = R[n] >> 1;"}, + {"n","n","shll ", "0100nnnn00000000", "T=R[n]<0; R[n]<<=1;"}, + {"n","n","shll16 ", "0100nnnn00101000", "R[n]<<=16;"}, + {"n","n","shll2 ", "0100nnnn00001000", "R[n]<<=2;"}, + {"n","n","shll8 ", "0100nnnn00011000", "R[n]<<=8;"}, + {"n","n","shlr ", "0100nnnn00000001", "T=R[n]&1;R[n]=UR[n]>>1;"}, + {"n","n","shlr16 ", "0100nnnn00101001", "R[n]=UR[n]>>16;"}, + {"n","n","shlr2 ", "0100nnnn00001001", "R[n]=UR[n]>>2;"}, + {"n","n","shlr8 ", "0100nnnn00011001", "R[n]=UR[n]>>8;"}, + {"","","sleep", "0000000000011011", "trap(0xc3,R0,memory,maskl,maskw,little_endian);PC-=2;"}, + {"n","","stc GBR,", "0000nnnn00010010", "R[n]=GBR;"}, + {"n","","stc SR,", "0000nnnn00000010", "R[n]=GET_SR();"}, + {"n","","stc VBR,", "0000nnnn00100010", "R[n]=VBR;"}, + {"n","n","stc.l GBR,@-", "0100nnnn00010011", "R[n]-=4;WLAT(R[n],GBR);;"}, + {"n","n","stc.l SR,@-", "0100nnnn00000011", "R[n]-=4;WLAT(R[n],GET_SR());"}, + {"n","n","stc.l VBR,@-", "0100nnnn00100011", "R[n]-=4;WLAT(R[n],VBR);"}, + {"n","","sts MACH,", "0000nnnn00001010", "R[n]=MACH;"}, + {"n","","sts MACL,", "0000nnnn00011010", "R[n]=MACL;"}, + {"n","","sts PR,", "0000nnnn00101010", "R[n]=PR;"}, + {"n","n","sts.l MACH,@-", "0100nnnn00000010", "R[n]-=4;WLAT(R[n],MACH);"}, + {"n","n","sts.l MACL,@-", "0100nnnn00010010", "R[n]-=4;WLAT(R[n],MACL);"}, + {"n","n","sts.l PR,@-", "0100nnnn00100010", "R[n]-=4;WLAT(R[n],PR);"}, + {"n","nm","sub ,", "0011nnnnmmmm1000", "R[n]-=R[m];"}, + {"n","nm","subc ,", "0011nnnnmmmm1010", "ult=R[n]-T;T=ult>T;ult=ult-R[m];T=T|(ult>R[m]);R[n]=ult;"}, + {"n","nm","subv ,", "0011nnnnmmmm1011", "abort();"}, + {"n","nm","swap.b ,", "0110nnnnmmmm1000", "R[n]=((R[m]<<8)&0xff00)|((R[m]>>8)&0x00ff);"}, + {"n","nm","swap.w ,", "0110nnnnmmmm1001", "R[n]=((R[m]<<16)&0xffff0000)|((R[m]>>16)&0x00ffff);"}, + {"","n","tas.b @", "0100nnnn00011011", "ult=RBAT(R[n]);T=ult==0;WBAT(R[n],ult|0x80);"}, + {"0","","trapa #", "11000011i8*1....", + "{ long imm = 0xff & i; if (i<20||i==0xc3) trap(i,R,memory,maskl,maskw,little_endian); else { R[15]-=4; WLAT(R[15],GET_SR()); R[15]-=4;WLAT(R[15],PC+2); PC=RLAT(VBR+(imm<<2))-2;}}"}, + {"","0","tst #,R0", "11001000i8*1....", "T=(R0&i)==0;"}, + {"","mn","tst ,", "0010nnnnmmmm1000", "T=(R[n]&R[m])==0;"}, + {"","0","tst.b #,@(R0,GBR)", "11001100i8*1....", "T=(RBAT(GBR+R0)&i)==0;"}, + {"","0","xor #,R0", "11001010i8*1....", "R0^=i;"}, + {"n","mn","xor ,", "0010nnnnmmmm1010", "R[n]^=R[m];"}, + {"","0","xor.b #,@(R0,GBR)", "11001110i8*1....", "ult=RBAT(GBR+R0);ult^=i;WBAT(GBR+R0,ult);"}, + {"n","nm","xtrct ,", "0010nnnnmmmm1101", "R[n]=((R[n]>>16)&0xffff)|((R[m]<<16)&0xffff0000);"}, + {"","nm","mul.l ,", "0000nnnnmmmm0111", " MACL = R[n] * R[m];"}, + {"n","n","dt ", "0100nnnn00010000", "R[n]--; T=R[n] == 0;"}, + {"","nm","dmuls.l ,", "0011nnnnmmmm1101", "dmul(1,R[n],R[m]);"}, + {"","nm","dmulu.l ,", "0011nnnnmmmm0101", "dmul(0,R[n],R[m]);"}, + {"","nm","mac.l @+,@+", "0000nnnnmmmm1111", ""}, + #if 0 -{"mul.l ,","0000nnnnmmmm0111","/* mull */"}, -{"dmuls.l ,","0011nnnnmmmm1101","/* dmuls.l */"}, -{"dmulu.l ,","0011nnnnmmmm0101",""}, -{"mac.l @+,@+","0000nnnnmmmm1111",""}, -{"bt/s ","10001101i8p1....",""}, -{"bf/s ","10001111i8p1....",""}, -{"dt ","0100nnnn00010000",""}, -{"braf @","0000nnnn00100011",""}, -{"bsrf @","0000nnnn00000011",""}, -{"mulu ,","0010nnnnmmmm1110",""}, -{"muls ,","0010nnnnmmmm1111",""}, + {"braf @", "0000nnnn00100011", ""}, + {"bsrf @", "0000nnnn00000011", ""}, + {"divs.l ,", "0100nnnnmmmm1110", "divl(0,R[n],R[m]);"}, + {"divu.l ,", "0100nnnnmmmm1101", "divl(0,R[n],R[m]);"}, #endif {0, 0}}; @@ -275,52 +292,46 @@ make_enum_list (name, s) printf ("typedef enum {\n"); while (*s) { - printf ("\t%s,\n", *s, i); + printf ("\t%s,\n", *s); s++; i++; } printf ("} %s;\n", name); } -static void -gengastab () +static int +qfunc (a, b) + op *a; + op *b; { - op *p; - sorttab (); - for (p = tab; p->name; p++) - { - printf ("%s %-30s\n", p->code, p->name); - } - + char bufa[9]; + char bufb[9]; + memcpy (bufa, a->code, 4); + memcpy (bufa + 4, a->code + 12, 4); + bufa[8] = 0; + memcpy (bufb, b->code, 4); + memcpy (bufb + 4, b->code + 12, 4); + bufb[8] = 0; + return (strcmp (bufa, bufb)); } - -static void -genopc () +static void +sorttab () { - op *p; - make_enum_list ("sh_nibble_type", nibble_type_list); - make_enum_list ("sh_arg_type", arg_type_list); + op *p = tab; + int len = 0; - printf ("typedef struct {\n"); - printf ("char *name;\n"); - printf ("sh_arg_type arg[3];\n"); - printf ("sh_nibble_type nibbles[4];\n"); - printf ("} sh_opcode_info;\n"); - printf ("#ifdef DEFINE_TABLE\n"); - printf ("sh_opcode_info sh_table[]={\n"); - for (p = tab; p->name; p++) + while (p->name) { - printf ("\n\/\* %s %-20s*/", p->code, p->name); - think (p); + p++; + len++; } - printf ("0};\n"); - printf ("#endif\n"); + qsort (tab, len, sizeof (*p), qfunc); } - -m (ptr, a, rep) +static void +printonmatch (ptr, a, rep) char **ptr; char *a; char *rep; @@ -335,10 +346,12 @@ m (ptr, a, rep) } } + +static +void think (o) op *o; { - int t; char *n; char *p; @@ -361,31 +374,31 @@ think (o) { while (*p == ',' || *p == ' ') p++; - m (&p, "#", "A_IMM"); - m (&p, "R0", "A_R0"); - m (&p, "", "A_REG_N"); - m (&p, "@+", "A_INC_N"); - m (&p, "@", "A_IND_N"); - m (&p, "@-", "A_DEC_N"); - m (&p, "", " A_REG_M"); - m (&p, "@+", "A_INC_M"); - m (&p, "@", "A_IND_M"); - m (&p, "@-", "A_DEC_M"); - m (&p, "@(,PC)", "A_DISP_PC"); - m (&p, "@(,)", "A_DISP_REG_M"); - m (&p, "@(,)", "A_DISP_REG_N"); - m (&p, "@(R0,)", "A_IND_R0_REG_N"); - m (&p, "@(R0,)", "A_IND_R0_REG_M"); - m (&p, "@(,GBR)", "A_DISP_GBR"); - m (&p, "@(R0,GBR)", "A_R0_GBR"); - m (&p, "", "A_BDISP8"); - m (&p, "", "A_BDISP12"); - m (&p, "SR", "A_SR"); - m (&p, "GBR", "A_GBR"); - m (&p, "VBR", "A_VBR"); - m (&p, "MACH", "A_MACH"); - m (&p, "MACL", "A_MACL"); - m (&p, "PR", "A_PR"); + printonmatch (&p, "#", "A_IMM"); + printonmatch (&p, "R0", "A_R0"); + printonmatch (&p, "", "A_REG_N"); + printonmatch (&p, "@+", "A_INC_N"); + printonmatch (&p, "@", "A_IND_N"); + printonmatch (&p, "@-", "A_DEC_N"); + printonmatch (&p, "", " A_REG_M"); + printonmatch (&p, "@+", "A_INC_M"); + printonmatch (&p, "@", "A_IND_M"); + printonmatch (&p, "@-", "A_DEC_M"); + printonmatch (&p, "@(,PC)", "A_DISP_PC"); + printonmatch (&p, "@(,)", "A_DISP_REG_M"); + printonmatch (&p, "@(,)", "A_DISP_REG_N"); + printonmatch (&p, "@(R0,)", "A_IND_R0_REG_N"); + printonmatch (&p, "@(R0,)", "A_IND_R0_REG_M"); + printonmatch (&p, "@(,GBR)", "A_DISP_GBR"); + printonmatch (&p, "@(R0,GBR)", "A_R0_GBR"); + printonmatch (&p, "", "A_BDISP8"); + printonmatch (&p, "", "A_BDISP12"); + printonmatch (&p, "SR", "A_SR"); + printonmatch (&p, "GBR", "A_GBR"); + printonmatch (&p, "VBR", "A_VBR"); + printonmatch (&p, "MACH", "A_MACH"); + printonmatch (&p, "MACL", "A_MACL"); + printonmatch (&p, "PR", "A_PR"); } printf ("},{"); @@ -393,72 +406,81 @@ think (o) p = o->code; while (*p) { - m (&p, "0000", "HEX_0"); - m (&p, "0001", "HEX_1"); - m (&p, "0010", "HEX_2"); - m (&p, "0011", "HEX_3"); - m (&p, "0100", "HEX_4"); - m (&p, "0101", "HEX_5"); - m (&p, "0110", "HEX_6"); - m (&p, "0111", "HEX_7"); - - m (&p, "1000", "HEX_8"); - m (&p, "1001", "HEX_9"); - m (&p, "1010", "HEX_A"); - m (&p, "1011", "HEX_B"); - m (&p, "1100", "HEX_C"); - m (&p, "1101", "HEX_D"); - m (&p, "1110", "HEX_E"); - m (&p, "1111", "HEX_F"); - m (&p, "i8*1....", "IMM_8"); - m (&p, "i4*1", "IMM_4"); - m (&p, "i8p4....", "PCRELIMM_8BY4"); - m (&p, "i8p2....", "PCRELIMM_8BY2"); - m (&p, "i8*2....", "IMM_8BY2"); - m (&p, "i4*2", "IMM_4BY2"); - m (&p, "i8*4....", "IMM_8BY4"); - m (&p, "i4*4", "IMM_4BY4"); - m (&p, "i12.........", "BRANCH_12"); - m (&p, "i8p1....", "BRANCH_8"); - m (&p, "nnnn", "REG_N"); - m (&p, "mmmm", "REG_M"); + printonmatch (&p, "0000", "HEX_0"); + printonmatch (&p, "0001", "HEX_1"); + printonmatch (&p, "0010", "HEX_2"); + printonmatch (&p, "0011", "HEX_3"); + printonmatch (&p, "0100", "HEX_4"); + printonmatch (&p, "0101", "HEX_5"); + printonmatch (&p, "0110", "HEX_6"); + printonmatch (&p, "0111", "HEX_7"); + + printonmatch (&p, "1000", "HEX_8"); + printonmatch (&p, "1001", "HEX_9"); + printonmatch (&p, "1010", "HEX_A"); + printonmatch (&p, "1011", "HEX_B"); + printonmatch (&p, "1100", "HEX_C"); + printonmatch (&p, "1101", "HEX_D"); + printonmatch (&p, "1110", "HEX_E"); + printonmatch (&p, "1111", "HEX_F"); + printonmatch (&p, "i8*1....", "IMM_8"); + printonmatch (&p, "i4*1", "IMM_4"); + printonmatch (&p, "i8p4....", "PCRELIMM_8BY4"); + printonmatch (&p, "i8p2....", "PCRELIMM_8BY2"); + printonmatch (&p, "i8*2....", "IMM_8BY2"); + printonmatch (&p, "i4*2", "IMM_4BY2"); + printonmatch (&p, "i8*4....", "IMM_8BY4"); + printonmatch (&p, "i4*4", "IMM_4BY4"); + printonmatch (&p, "i12.........", "BRANCH_12"); + printonmatch (&p, "i8p1....", "BRANCH_8"); + printonmatch (&p, "nnnn", "REG_N"); + printonmatch (&p, "mmmm", "REG_M"); } printf ("}},\n"); } -qfunc (a, b) - op *a; - op *b; +static void +gengastab () { - char bufa[9]; - char bufb[9]; - memcpy (bufa, a->code, 4); - memcpy (bufa + 4, a->code + 12, 4); - bufa[8] = 0; + op *p; + sorttab (); + for (p = tab; p->name; p++) + { + printf ("%s %-30s\n", p->code, p->name); + } + - memcpy (bufb, b->code, 4); - memcpy (bufb + 4, b->code + 12, 4); - bufb[8] = 0; - return (strcmp (bufa, bufb)); } -sorttab () +static void +genopc () { - op *p = tab; - - int len = 0; + op *p; + make_enum_list ("sh_nibble_type", nibble_type_list); + make_enum_list ("sh_arg_type", arg_type_list); - while (p->name) + printf ("typedef struct {\n"); + printf ("char *name;\n"); + printf ("sh_arg_type arg[3];\n"); + printf ("sh_nibble_type nibbles[4];\n"); + printf ("} sh_opcode_info;\n"); + printf ("#ifdef DEFINE_TABLE\n"); + printf ("sh_opcode_info sh_table[]={\n"); + for (p = tab; p->name; p++) { - p++; - len++; + printf ("\n\/\* %s %-20s*/", p->code, p->name); + think (p); } + printf ("0};\n"); + printf ("#endif\n"); +} + + + - qsort (tab, len, sizeof (*p), qfunc); -} /* Convert a string of 4 binary digits into an int */ @@ -480,12 +502,16 @@ bton (s) return n; } -static char table[1 << 16]; +static unsigned char table[1 << 16]; -/* Take an opcode expand all varying fields in it out and fill all the +/* Take an opcode expand all varying fields in it out and fill all the right entries in 'table' with the opcode index*/ - + +static void expand_opcode (shift, val, i, s) + int shift; + int val; + int i; char *s; { int j; @@ -529,9 +555,9 @@ expand_opcode (shift, val, i, s) } /* Print the jump table used to index an opcode into a switch - statement entry */ -static void + statement entry. */ +static void dumptable () { int lump = 256; @@ -542,7 +568,6 @@ dumptable () while (i < 1 << 16) { int j = 0; - int nc = 0; printf ("unsigned char sh_jump_table%x[%d]={\n", i, lump); @@ -581,7 +606,7 @@ filltable () } } -static void +static void gensim () { op *p; @@ -593,7 +618,9 @@ gensim () for (p = tab; p->name; p++) { int sextbit = -1; - + int needm = 0; + int needn = 0; + char *s = p->code; printf ("\/\* %s %s *\/\n", p->name, p->code); @@ -611,10 +638,12 @@ gensim () break; case 'n': printf ("int n = (iword >>8) & 0xf;\n"); + needn = 1; s += 4; break; case 'm': printf ("int m = (iword >>4) & 0xf;\n"); + needm = 1; s += 4; break; @@ -632,7 +661,7 @@ gensim () break; case '1': sextbit = 12; - + printf ("fff"); break; } @@ -653,11 +682,16 @@ gensim () s += 4; } } - if (sextbit>0) + if (sextbit > 0) { - printf("i = (i ^ (1<<%d))-(1<<%d);\n",sextbit-1,sextbit-1); + printf ("i = (i ^ (1<<%d))-(1<<%d);\n", sextbit - 1, sextbit - 1); } - + if (needm && needn) + printf("TB(m,n);"); + else if (needm) + printf("TL(m);"); + else if (needn) + printf("TL(n);"); for (j = 0; j < 10; j++) { if (p->stuff[j]) @@ -665,17 +699,59 @@ gensim () printf ("%s\n", p->stuff[j]); } } - printf ("break;\n", p->stuff); + + + { + /* Do the defs and refs */ + char *r; + for (r = p->refs; *r; r++) { + if (*r == '0') printf("CREF(0);\n"); + if (*r == 'n') printf("CREF(n);\n"); + if (*r == 'm') printf("CREF(m);\n"); + + } + for (r = p->defs; *r; r++) + { + if (*r == '0') printf("CDEF(0);\n"); + if (*r == 'n') printf("CDEF(n);\n"); + if (*r == 'm') printf("CDEF(m);\n"); + + } + + } + printf ("break;\n"); printf ("}\n"); } printf ("}\n}\n"); } +static void +gendefines () +{ + op *p; + filltable(); + for (p = tab; p->name; p++) + { + char *s = p->name; + printf ("#define OPC_"); + while (*s) { + if (isupper(*s)) + *s = tolower(*s); + if (isalpha(*s)) printf("%c", *s); + if (*s == ' ') printf("_"); + if (*s == '@') printf("ind_"); + if (*s == ',') printf("_"); + s++; + } + printf(" %d\n",p->index); + } +} + int main (ac, av) + int ac; char **av; - { if (ac > 1) { @@ -683,6 +759,10 @@ main (ac, av) { gengastab (); } + else if (strcmp (av[1], "-d") == 0) + { + gendefines (); + } else if (strcmp (av[1], "-s") == 0) { filltable ();