coff-sh.c

来自「基于4个mips核的noc设计」· C语言 代码 · 共 2,052 行 · 第 1/5 页

C
2,052
字号
  PARAMS ((unsigned int, const struct sh_opcode *, unsigned int));static boolean sh_insn_uses_or_sets_freg  PARAMS ((unsigned int, const struct sh_opcode *, unsigned int));static boolean sh_insns_conflict  PARAMS ((unsigned int, const struct sh_opcode *, unsigned int,	   const struct sh_opcode *));static boolean sh_load_use  PARAMS ((unsigned int, const struct sh_opcode *, unsigned int,	   const struct sh_opcode *));#endif/* The opcode maps.  */#define MAP(a) a, sizeof a / sizeof a[0]static const struct sh_opcode sh_opcode00[] ={  { 0x0008, SETSSP },			/* clrt */  { 0x0009, 0 },			/* nop */  { 0x000b, BRANCH | DELAY | USESSP },	/* rts */  { 0x0018, SETSSP },			/* sett */  { 0x0019, SETSSP },			/* div0u */  { 0x001b, 0 },			/* sleep */  { 0x0028, SETSSP },			/* clrmac */  { 0x002b, BRANCH | DELAY | SETSSP },	/* rte */  { 0x0038, USESSP | SETSSP },		/* ldtlb */  { 0x0048, SETSSP },			/* clrs */  { 0x0058, SETSSP }			/* sets */};static const struct sh_opcode sh_opcode01[] ={  { 0x0003, BRANCH | DELAY | USES1 | SETSSP },	/* bsrf rn */  { 0x000a, SETS1 | USESSP },			/* sts mach,rn */  { 0x001a, SETS1 | USESSP },			/* sts macl,rn */  { 0x0023, BRANCH | DELAY | USES1 },		/* braf rn */  { 0x0029, SETS1 | USESSP },			/* movt rn */  { 0x002a, SETS1 | USESSP },			/* sts pr,rn */  { 0x005a, SETS1 | USESSP },			/* sts fpul,rn */  { 0x006a, SETS1 | USESSP },			/* sts fpscr,rn / sts dsr,rn */  { 0x0083, LOAD | USES1 },			/* pref @rn */  { 0x007a, SETS1 | USESSP },			/* sts a0,rn */  { 0x008a, SETS1 | USESSP },			/* sts x0,rn */  { 0x009a, SETS1 | USESSP },			/* sts x1,rn */  { 0x00aa, SETS1 | USESSP },			/* sts y0,rn */  { 0x00ba, SETS1 | USESSP }			/* sts y1,rn */};/* These sixteen instructions can be handled with one table entry below.  */#if 0  { 0x0002, SETS1 | USESSP },			/* stc sr,rn */  { 0x0012, SETS1 | USESSP },			/* stc gbr,rn */  { 0x0022, SETS1 | USESSP },			/* stc vbr,rn */  { 0x0032, SETS1 | USESSP },			/* stc ssr,rn */  { 0x0042, SETS1 | USESSP },			/* stc spc,rn */  { 0x0052, SETS1 | USESSP },			/* stc mod,rn */  { 0x0062, SETS1 | USESSP },			/* stc rs,rn */  { 0x0072, SETS1 | USESSP },			/* stc re,rn */  { 0x0082, SETS1 | USESSP },			/* stc r0_bank,rn */  { 0x0092, SETS1 | USESSP },			/* stc r1_bank,rn */  { 0x00a2, SETS1 | USESSP },			/* stc r2_bank,rn */  { 0x00b2, SETS1 | USESSP },			/* stc r3_bank,rn */  { 0x00c2, SETS1 | USESSP },			/* stc r4_bank,rn */  { 0x00d2, SETS1 | USESSP },			/* stc r5_bank,rn */  { 0x00e2, SETS1 | USESSP },			/* stc r6_bank,rn */  { 0x00f2, SETS1 | USESSP }			/* stc r7_bank,rn */#endifstatic const struct sh_opcode sh_opcode02[] ={  { 0x0002, SETS1 | USESSP },			/* stc <special_reg>,rn */  { 0x0004, STORE | USES1 | USES2 | USESR0 },	/* mov.b rm,@(r0,rn) */  { 0x0005, STORE | USES1 | USES2 | USESR0 },	/* mov.w rm,@(r0,rn) */  { 0x0006, STORE | USES1 | USES2 | USESR0 },	/* mov.l rm,@(r0,rn) */  { 0x0007, SETSSP | USES1 | USES2 },		/* mul.l rm,rn */  { 0x000c, LOAD | SETS1 | USES2 | USESR0 },	/* mov.b @(r0,rm),rn */  { 0x000d, LOAD | SETS1 | USES2 | USESR0 },	/* mov.w @(r0,rm),rn */  { 0x000e, LOAD | SETS1 | USES2 | USESR0 },	/* mov.l @(r0,rm),rn */  { 0x000f, LOAD|SETS1|SETS2|SETSSP|USES1|USES2|USESSP }, /* mac.l @rm+,@rn+ */};static const struct sh_minor_opcode sh_opcode0[] ={  { MAP (sh_opcode00), 0xffff },  { MAP (sh_opcode01), 0xf0ff },  { MAP (sh_opcode02), 0xf00f }};static const struct sh_opcode sh_opcode10[] ={  { 0x1000, STORE | USES1 | USES2 }	/* mov.l rm,@(disp,rn) */};static const struct sh_minor_opcode sh_opcode1[] ={  { MAP (sh_opcode10), 0xf000 }};static const struct sh_opcode sh_opcode20[] ={  { 0x2000, STORE | USES1 | USES2 },		/* mov.b rm,@rn */  { 0x2001, STORE | USES1 | USES2 },		/* mov.w rm,@rn */  { 0x2002, STORE | USES1 | USES2 },		/* mov.l rm,@rn */  { 0x2004, STORE | SETS1 | USES1 | USES2 },	/* mov.b rm,@-rn */  { 0x2005, STORE | SETS1 | USES1 | USES2 },	/* mov.w rm,@-rn */  { 0x2006, STORE | SETS1 | USES1 | USES2 },	/* mov.l rm,@-rn */  { 0x2007, SETSSP | USES1 | USES2 | USESSP },	/* div0s */  { 0x2008, SETSSP | USES1 | USES2 },		/* tst rm,rn */  { 0x2009, SETS1 | USES1 | USES2 },		/* and rm,rn */  { 0x200a, SETS1 | USES1 | USES2 },		/* xor rm,rn */  { 0x200b, SETS1 | USES1 | USES2 },		/* or rm,rn */  { 0x200c, SETSSP | USES1 | USES2 },		/* cmp/str rm,rn */  { 0x200d, SETS1 | USES1 | USES2 },		/* xtrct rm,rn */  { 0x200e, SETSSP | USES1 | USES2 },		/* mulu.w rm,rn */  { 0x200f, SETSSP | USES1 | USES2 }		/* muls.w rm,rn */};static const struct sh_minor_opcode sh_opcode2[] ={  { MAP (sh_opcode20), 0xf00f }};static const struct sh_opcode sh_opcode30[] ={  { 0x3000, SETSSP | USES1 | USES2 },		/* cmp/eq rm,rn */  { 0x3002, SETSSP | USES1 | USES2 },		/* cmp/hs rm,rn */  { 0x3003, SETSSP | USES1 | USES2 },		/* cmp/ge rm,rn */  { 0x3004, SETSSP | USESSP | USES1 | USES2 },	/* div1 rm,rn */  { 0x3005, SETSSP | USES1 | USES2 },		/* dmulu.l rm,rn */  { 0x3006, SETSSP | USES1 | USES2 },		/* cmp/hi rm,rn */  { 0x3007, SETSSP | USES1 | USES2 },		/* cmp/gt rm,rn */  { 0x3008, SETS1 | USES1 | USES2 },		/* sub rm,rn */  { 0x300a, SETS1 | SETSSP | USES1 | USES2 | USESSP }, /* subc rm,rn */  { 0x300b, SETS1 | SETSSP | USES1 | USES2 },	/* subv rm,rn */  { 0x300c, SETS1 | USES1 | USES2 },		/* add rm,rn */  { 0x300d, SETSSP | USES1 | USES2 },		/* dmuls.l rm,rn */  { 0x300e, SETS1 | SETSSP | USES1 | USES2 | USESSP }, /* addc rm,rn */  { 0x300f, SETS1 | SETSSP | USES1 | USES2 }	/* addv rm,rn */};static const struct sh_minor_opcode sh_opcode3[] ={  { MAP (sh_opcode30), 0xf00f }};static const struct sh_opcode sh_opcode40[] ={  { 0x4000, SETS1 | SETSSP | USES1 },		/* shll rn */  { 0x4001, SETS1 | SETSSP | USES1 },		/* shlr rn */  { 0x4002, STORE | SETS1 | USES1 | USESSP },	/* sts.l mach,@-rn */  { 0x4004, SETS1 | SETSSP | USES1 },		/* rotl rn */  { 0x4005, SETS1 | SETSSP | USES1 },		/* rotr rn */  { 0x4006, LOAD | SETS1 | SETSSP | USES1 },	/* lds.l @rm+,mach */  { 0x4008, SETS1 | USES1 },			/* shll2 rn */  { 0x4009, SETS1 | USES1 },			/* shlr2 rn */  { 0x400a, SETSSP | USES1 },			/* lds rm,mach */  { 0x400b, BRANCH | DELAY | USES1 },		/* jsr @rn */  { 0x4010, SETS1 | SETSSP | USES1 },		/* dt rn */  { 0x4011, SETSSP | USES1 },			/* cmp/pz rn */  { 0x4012, STORE | SETS1 | USES1 | USESSP },	/* sts.l macl,@-rn */  { 0x4014, SETSSP | USES1 },			/* setrc rm */  { 0x4015, SETSSP | USES1 },			/* cmp/pl rn */  { 0x4016, LOAD | SETS1 | SETSSP | USES1 },	/* lds.l @rm+,macl */  { 0x4018, SETS1 | USES1 },			/* shll8 rn */  { 0x4019, SETS1 | USES1 },			/* shlr8 rn */  { 0x401a, SETSSP | USES1 },			/* lds rm,macl */  { 0x401b, LOAD | SETSSP | USES1 },		/* tas.b @rn */  { 0x4020, SETS1 | SETSSP | USES1 },		/* shal rn */  { 0x4021, SETS1 | SETSSP | USES1 },		/* shar rn */  { 0x4022, STORE | SETS1 | USES1 | USESSP },	/* sts.l pr,@-rn */  { 0x4024, SETS1 | SETSSP | USES1 | USESSP },	/* rotcl rn */  { 0x4025, SETS1 | SETSSP | USES1 | USESSP },	/* rotcr rn */  { 0x4026, LOAD | SETS1 | SETSSP | USES1 },	/* lds.l @rm+,pr */  { 0x4028, SETS1 | USES1 },			/* shll16 rn */  { 0x4029, SETS1 | USES1 },			/* shlr16 rn */  { 0x402a, SETSSP | USES1 },			/* lds rm,pr */  { 0x402b, BRANCH | DELAY | USES1 },		/* jmp @rn */  { 0x4052, STORE | SETS1 | USES1 | USESSP },	/* sts.l fpul,@-rn */  { 0x4056, LOAD | SETS1 | SETSSP | USES1 },	/* lds.l @rm+,fpul */  { 0x405a, SETSSP | USES1 },			/* lds.l rm,fpul */  { 0x4062, STORE | SETS1 | USES1 | USESSP },	/* sts.l fpscr / dsr,@-rn */  { 0x4066, LOAD | SETS1 | SETSSP | USES1 },	/* lds.l @rm+,fpscr / dsr */  { 0x406a, SETSSP | USES1 },			/* lds rm,fpscr / lds rm,dsr */  { 0x4072, STORE | SETS1 | USES1 | USESSP },	/* sts.l a0,@-rn */  { 0x4076, LOAD | SETS1 | SETSSP | USES1 },	/* lds.l @rm+,a0 */  { 0x407a, SETSSP | USES1 },			/* lds.l rm,a0 */  { 0x4082, STORE | SETS1 | USES1 | USESSP },	/* sts.l x0,@-rn */  { 0x4086, LOAD | SETS1 | SETSSP | USES1 },	/* lds.l @rm+,x0 */  { 0x408a, SETSSP | USES1 },			/* lds.l rm,x0 */  { 0x4092, STORE | SETS1 | USES1 | USESSP },	/* sts.l x1,@-rn */  { 0x4096, LOAD | SETS1 | SETSSP | USES1 },	/* lds.l @rm+,x1 */  { 0x409a, SETSSP | USES1 },			/* lds.l rm,x1 */  { 0x40a2, STORE | SETS1 | USES1 | USESSP },	/* sts.l y0,@-rn */  { 0x40a6, LOAD | SETS1 | SETSSP | USES1 },	/* lds.l @rm+,y0 */  { 0x40aa, SETSSP | USES1 },			/* lds.l rm,y0 */  { 0x40b2, STORE | SETS1 | USES1 | USESSP },	/* sts.l y1,@-rn */  { 0x40b6, LOAD | SETS1 | SETSSP | USES1 },	/* lds.l @rm+,y1 */  { 0x40ba, SETSSP | USES1 }			/* lds.l rm,y1 */#if 0 /* These groups sixteen insns can be         handled with one table entry each below.  */  { 0x4003, STORE | SETS1 | USES1 | USESSP },	/* stc.l sr,@-rn */  { 0x4013, STORE | SETS1 | USES1 | USESSP },	/* stc.l gbr,@-rn */  { 0x4023, STORE | SETS1 | USES1 | USESSP },	/* stc.l vbr,@-rn */  { 0x4033, STORE | SETS1 | USES1 | USESSP },	/* stc.l ssr,@-rn */  { 0x4043, STORE | SETS1 | USES1 | USESSP },	/* stc.l spc,@-rn */  { 0x4053, STORE | SETS1 | USES1 | USESSP },	/* stc.l mod,@-rn */  { 0x4063, STORE | SETS1 | USES1 | USESSP },	/* stc.l rs,@-rn */  { 0x4073, STORE | SETS1 | USES1 | USESSP },	/* stc.l re,@-rn */  { 0x4083, STORE | SETS1 | USES1 | USESSP },	/* stc.l r0_bank,@-rn */  ..  { 0x40f3, STORE | SETS1 | USES1 | USESSP },	/* stc.l r7_bank,@-rn */  { 0x4007, LOAD | SETS1 | SETSSP | USES1 },	/* ldc.l @rm+,sr */  { 0x4017, LOAD | SETS1 | SETSSP | USES1 },	/* ldc.l @rm+,gbr */  { 0x4027, LOAD | SETS1 | SETSSP | USES1 },	/* ldc.l @rm+,vbr */  { 0x4037, LOAD | SETS1 | SETSSP | USES1 },	/* ldc.l @rm+,ssr */  { 0x4047, LOAD | SETS1 | SETSSP | USES1 },	/* ldc.l @rm+,spc */  { 0x4057, LOAD | SETS1 | SETSSP | USES1 },	/* ldc.l @rm+,mod */  { 0x4067, LOAD | SETS1 | SETSSP | USES1 },	/* ldc.l @rm+,rs */  { 0x4077, LOAD | SETS1 | SETSSP | USES1 },	/* ldc.l @rm+,re */  { 0x4087, LOAD | SETS1 | SETSSP | USES1 },	/* ldc.l @rm+,r0_bank */  ..  { 0x40f7, LOAD | SETS1 | SETSSP | USES1 },	/* ldc.l @rm+,r7_bank */  { 0x400e, SETSSP | USES1 },			/* ldc rm,sr */  { 0x401e, SETSSP | USES1 },			/* ldc rm,gbr */  { 0x402e, SETSSP | USES1 },			/* ldc rm,vbr */  { 0x403e, SETSSP | USES1 },			/* ldc rm,ssr */  { 0x404e, SETSSP | USES1 },			/* ldc rm,spc */  { 0x405e, SETSSP | USES1 },			/* ldc rm,mod */  { 0x406e, SETSSP | USES1 },			/* ldc rm,rs */  { 0x407e, SETSSP | USES1 }			/* ldc rm,re */  { 0x408e, SETSSP | USES1 }			/* ldc rm,r0_bank */  ..  { 0x40fe, SETSSP | USES1 }			/* ldc rm,r7_bank */#endif};static const struct sh_opcode sh_opcode41[] ={  { 0x4003, STORE | SETS1 | USES1 | USESSP },	/* stc.l <special_reg>,@-rn */  { 0x4007, LOAD | SETS1 | SETSSP | USES1 },	/* ldc.l @rm+,<special_reg> */  { 0x400c, SETS1 | USES1 | USES2 },		/* shad rm,rn */  { 0x400d, SETS1 | USES1 | USES2 },		/* shld rm,rn */  { 0x400e, SETSSP | USES1 },			/* ldc rm,<special_reg> */  { 0x400f, LOAD|SETS1|SETS2|SETSSP|USES1|USES2|USESSP }, /* mac.w @rm+,@rn+ */};static const struct sh_minor_opcode sh_opcode4[] ={  { MAP (sh_opcode40), 0xf0ff },  { MAP (sh_opcode41), 0xf00f }};static const struct sh_opcode sh_opcode50[] ={  { 0x5000, LOAD | SETS1 | USES2 }	/* mov.l @(disp,rm),rn */};static const struct sh_minor_opcode sh_opcode5[] ={  { MAP (sh_opcode50), 0xf000 }};static const struct sh_opcode sh_opcode60[] ={  { 0x6000, LOAD | SETS1 | USES2 },		/* mov.b @rm,rn */  { 0x6001, LOAD | SETS1 | USES2 },		/* mov.w @rm,rn */  { 0x6002, LOAD | SETS1 | USES2 },		/* mov.l @rm,rn */  { 0x6003, SETS1 | USES2 },			/* mov rm,rn */  { 0x6004, LOAD | SETS1 | SETS2 | USES2 },	/* mov.b @rm+,rn */  { 0x6005, LOAD | SETS1 | SETS2 | USES2 },	/* mov.w @rm+,rn */  { 0x6006, LOAD | SETS1 | SETS2 | USES2 },	/* mov.l @rm+,rn */  { 0x6007, SETS1 | USES2 },			/* not rm,rn */  { 0x6008, SETS1 | USES2 },			/* swap.b rm,rn */  { 0x6009, SETS1 | USES2 },			/* swap.w rm,rn */  { 0x600a, SETS1 | SETSSP | USES2 | USESSP },	/* negc rm,rn */  { 0x600b, SETS1 | USES2 },			/* neg rm,rn */  { 0x600c, SETS1 | USES2 },			/* extu.b rm,rn */  { 0x600d, SETS1 | USES2 },			/* extu.w rm,rn */  { 0x600e, SETS1 | USES2 },			/* exts.b rm,rn */  { 0x600f, SETS1 | USES2 }			/* exts.w rm,rn */};static const struct sh_minor_opcode sh_opcode6[] ={  { MAP (sh_opcode60), 0xf00f }};static const struct sh_opcode sh_opcode70[] ={  { 0x7000, SETS1 | USES1 }		/* add #imm,rn */};static const struct sh_minor_opcode sh_opcode7[] ={  { MAP (sh_opcode70), 0xf000 }};static const struct sh_opcode sh_opcode80[] ={  { 0x8000, STORE | USES2 | USESR0 },	/* mov.b r0,@(disp,rn) */  { 0x8100, STORE | USES2 | USESR0 },	/* mov.w r0,@(disp,rn) */  { 0x8200, SETSSP },			/* setrc #imm */  { 0x8400, LOAD | SETSR0 | USES2 },	/* mov.b @(disp,rm),r0 */  { 0x8500, LOAD | SETSR0 | USES2 },	/* mov.w @(disp,rn),r0 */  { 0x8800, SETSSP | USESR0 },		/* cmp/eq #imm,r0 */  { 0x8900, BRANCH | USESSP },		/* bt label */  { 0x8b00, BRANCH | USESSP },		/* bf label */  { 0x8c00, SETSSP },			/* ldrs @(disp,pc) */  { 0x8d00, BRANCH | DELAY | USESSP },	/* bt/s label */  { 0x8e00, SETSSP },			/* ldre @(disp,pc) */  { 0x8f00, BRANCH | DELAY | USESSP }	/* bf/s label */};static const struct sh_minor_opcode sh_opcode8[] ={  { MAP (sh_opcode80), 0xff00 }};static const struct sh_opcode sh_opcode90[] ={  { 0x9000, LOAD | SETS1 }	/* mov.w @(disp,pc),rn */};static const struct sh_minor_opcode sh_opcode9[] ={  { MAP (sh_opcode90), 0xf000 }};static const struct sh_opcode sh_opcodea0[] ={  { 0xa000, BRANCH | DELAY }	/* bra label */};static const struct sh_minor_opcode sh_opcodea[] ={  { MAP (sh_opcodea0), 0xf000 }};static const struct sh_opcode sh_opcodeb0[] ={  { 0xb000, BRANCH | DELAY }	/* bsr label */};static const struct sh_minor_opcode sh_opcodeb[] ={  { MAP (sh_opcodeb0), 0xf000 }};static const struct sh_opcode sh_opcodec0[] ={  { 0xc000, STORE | USESR0 | USESSP },		/* mov.b r0,@(disp,gbr) */  { 0xc100, STORE | USESR0 | USESSP },		/* mov.w r0,@(disp,gbr) */  { 0xc200, STORE | USESR0 | USESSP },		/* mov.l r0,@(disp,gbr) */  { 0xc300, BRANCH | USESSP },			/* trapa #imm */  { 0xc400, LOAD | SETSR0 | USESSP },		/* mov.b @(disp,gbr),r0 */  { 0xc500, LOAD | SETSR0 | USESSP },		/* mov.w @(disp,gbr),r0 */  { 0xc600, LOAD | SETSR0 | USESSP },		/* mov.l @(disp,gbr),r0 */  { 0xc700, SETSR0 },				/* mova @(disp,pc),r0 */  { 0xc800, SETSSP | USESR0 },			/* tst #imm,r0 */  { 0xc900, SETSR0 | USESR0 },			/* and #imm,r0 */  { 0xca00, SETSR0 | USESR0 },			/* xor #imm,r0 */  { 0xcb00, SETSR0 | USESR0 },			/* or #imm,r0 */  { 0xcc00, LOAD | SETSSP | USESR0 | USESSP },	/* tst.b #imm,@(r0,gbr) */  { 0xcd00, LOAD | STORE | USESR0 | USESSP },	/* and.b #imm,@(r0,gbr) */  { 0xce00, LOAD | STORE | USESR0 | USESSP },	/* xor.b #imm,@(r0,gbr) */  { 0xcf00, LOAD | STORE | USESR0 | USESSP }	/* or.b #imm,@(r0,gbr) */};static const struct sh_minor_opcode sh_opcodec[] ={  { MAP (sh_opcodec0), 0xff00 }};static const struct sh_opcode sh_opcoded0[] ={  { 0xd000, LOAD | SETS1 }		/* mov.l @(disp,pc),rn */};static const struct sh_minor_opcode sh_opcoded[] ={  { MAP (sh_opcoded0), 0xf000 }};static const struct sh_opcode sh_opcodee0[] ={  { 0xe000, SETS1 }		/* mov #imm,rn */};static const struct sh_minor_opcode sh_opcodee[] ={  { MAP (sh_opcodee0), 0xf000 }};static const struct sh_opcode sh_opcodef0[] ={  { 0xf000, SETSF1 | USESF1 | USESF2 },		/* fadd fm,fn */  { 0xf001, SETSF1 | USESF1 | USESF2 },		/* fsub fm,fn */  { 0xf002, SETSF1 | USESF1 | USESF2 },		/* fmul fm,fn */  { 0xf003, SETSF1 | USESF1 | USESF2 },		/* fdiv fm,fn */  { 0xf004, SETSSP | USESF1 | USESF2 },		/* fcmp/eq fm,fn */  { 0xf005, SETSSP | USESF1 | USESF2 },		/* fcmp/gt fm,fn */  { 0xf006, LOAD | SETSF1 | USES2 | USESR0 },	/* fmov.s @(r0,rm),fn */  { 0xf007, STORE | USES1 | USESF2 | USESR0 },	/* fmov.s fm,@(r0,rn) */  { 0xf008, LOAD | SETSF1 | USES2 },		/* fmov.s @rm,fn */  { 0xf009, LOAD | SETS2 | SETSF1 | USES2 },	/* fmov.s @rm+,fn */  { 0xf00a, STORE | USES1 | USESF2 },		/* fmov.s fm,@rn */  { 0xf00b, STORE | SETS1 | 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?