📄 ns32k.c
字号:
as_warn("Invalid syntax in External addressing mode"); return(0); } str[j]='\000'; /* null terminate disp[0] */ addr_modeP->disp[1]=str+j+2; addr_modeP->mode=22; return (-1); } } break; default:; } strl=strlen(str); switch(strl) { case 2: switch (str[0]) { case'f':addr_modeP->float_flag=1; case'r': if (str[1]>='0' && str[1]<'8') { addr_modeP->mode=str[1]-'0'; return (-1); } } case 3: if (!strncmp(str,"tos",3)) { addr_modeP->mode=23; /* TopOfStack */ return (-1); } default:; } if (strl>4) { if (str[strl-1]==')') { if (str[strl-2]==')') { if (!strncmp(&str[strl-5],"(fp",3)) { mode=16; /* Memory Relative */ } if (!strncmp(&str[strl-5],"(sp",3)) { mode=17; } if (!strncmp(&str[strl-5],"(sb",3)) { mode=18; } if (mode!=DEFAULT) { /* memory relative */ addr_modeP->mode=mode; j=strl-5; /* temp for end of disp[0] */ i=0; do { strl-=1; if (str[strl]==')') i++; if (str[strl]=='(') i--; } while (strl>-1 && i!=0); if (i!=0) { as_warn("Invalid syntax in Memory Relative addressing mode"); return(0); } addr_modeP->disp[1]=str; addr_modeP->disp[0]=str+strl+1; str[j]='\000'; /* null terminate disp[0] */ str[strl]='\000'; /* null terminate disp[1] */ return (-1); } } switch (str[strl-3]) { case'r':case'R': if (str[strl-2]>='0' && str[strl-2]<'8' && str[strl-4]=='(') { addr_modeP->mode=str[strl-2]-'0'+8; addr_modeP->disp[0]=str; str[strl-4]=0; return (-1); /* reg rel */ } default: if (!strncmp(&str[strl-4],"(fp",3)) { mode=24; } if (!strncmp(&str[strl-4],"(sp",3)) { mode=25; } if (!strncmp(&str[strl-4],"(sb",3)) { mode=26; } if (!strncmp(&str[strl-4],"(pc",3)) { mode=27; } if (mode!=DEFAULT) { addr_modeP->mode=mode; addr_modeP->disp[0]=str; str[strl-4]='\0'; return (-1); /* memory space */ } } } /* no trailing ')' do we have a ']' ? */ if (str[strl-1]==']') { switch (str[strl-2]) { case'b':mode=28;break; case'w':mode=29;break; case'd':mode=30;break; case'q':mode=31;break; default:; as_warn("Invalid scaled-indexed mode, use (b,w,d,q)"); if (str[strl-3]!=':' || str[strl-6]!='[' || str[strl-5]=='r' || str[strl-4]<'0' || str[strl-4]>'7') { as_warn("Syntax in scaled-indexed mode, use [Rn:m] where n=[0..7] m={b,w,d,q}"); } } /* scaled index */ { if (recursive_level>0) { as_warn("Scaled-indexed addressing mode combined with scaled-index"); return(0); } addr_modeP->am_size+=1; /* scaled index byte */ j=str[strl-4]-'0'; /* store temporary */ str[strl-6]='\000'; /* nullterminate for recursive call */ i=addr_mode(str,addr_modeP,1); if (!i || addr_modeP->mode==20) { as_warn("Invalid or illegal addressing mode combined with scaled-index"); return(0); } addr_modeP->scaled_mode=addr_modeP->mode; /* store the inferior mode */ addr_modeP->mode=mode; addr_modeP->scaled_reg=j+1; return (-1); } } } addr_modeP->mode = DEFAULT; /* default to whatever */ addr_modeP->disp[0]=str; return (-1);}/* ptr points at string addr_modeP points at struct with result This routine calls addr_mode to determine the general addr.mode of the operand. When this is ready it parses the displacements for size specifying suffixes and determines size of immediate mode via ns32k-opcode. Also builds index bytes if needed. */int get_addr_mode(ptr,addr_modeP) char *ptr; addr_modeS *addr_modeP;{ int tmp; addr_mode(ptr,addr_modeP,0); if (addr_modeP->mode == DEFAULT || addr_modeP->scaled_mode == -1) { /* resolve ambigious operands, this shouldn't be necessary if one uses standard NSC operand syntax. But the sequent compiler doesn't!!! This finds a proper addressinging mode if it is implicitly stated. See ns32k-opcode.h */ (void)evaluate_expr(&exprP,ptr); /* this call takes time Sigh! */ if (addr_modeP->mode == DEFAULT) { if (exprP.X_add_symbol || exprP.X_subtract_symbol) { addr_modeP->mode=desc->default_model; /* we have a label */ } else { addr_modeP->mode=desc->default_modec; /* we have a constant */ } } else { if (exprP.X_add_symbol || exprP.X_subtract_symbol) { addr_modeP->scaled_mode=desc->default_model; } else { addr_modeP->scaled_mode=desc->default_modec; } } /* must put this mess down in addr_mode to handle the scaled case better */ } /* It appears as the sequent compiler wants an absolute when we have a label without @. Constants becomes immediates besides the addr case. Think it does so with local labels too, not optimum, pcrel is better. When I have time I will make gas check this and select pcrel when possible Actually that is trivial. */ if (tmp=addr_modeP->scaled_reg) { /* build indexbyte */ tmp--; /* remember regnumber comes incremented for flagpurpose */ tmp|=addr_modeP->scaled_mode<<3; addr_modeP->index_byte=(char)tmp; addr_modeP->am_size+=1; } if (disp_test[addr_modeP->mode]) { /* there was a displacement, probe for length specifying suffix*/ { register char c; register char suffix; register char suffix_sub; register int i; register char *toP; register char *fromP; addr_modeP->pcrel=0; if (disp_test[addr_modeP->mode]) { /* there is a displacement */ if (addr_modeP->mode==27 || addr_modeP->scaled_mode==27) { /* do we have pcrel. mode */ addr_modeP->pcrel=1; } addr_modeP->im_disp=1; for(i=0;i<2;i++) { suffix_sub=suffix=0; if (toP=addr_modeP->disp[i]) { /* suffix of expression, the largest size rules */ fromP=toP; while (c = *fromP++) { *toP++=c; if (c==':') { switch (*fromP) { case '\0': as_warn("Premature end of suffix--Defaulting to d"); suffix=4; continue; case 'b':suffix_sub=1;break; case 'w':suffix_sub=2;break; case 'd':suffix_sub=4;break; default: as_warn("Bad suffix after ':' use {b|w|d} Defaulting to d"); suffix=4; } fromP++; toP--; /* So we write over the ':' */ if (suffix<suffix_sub) suffix=suffix_sub; } } *toP='\0'; /* terminate properly */ addr_modeP->disp_suffix[i]=suffix; addr_modeP->am_size+=suffix ? suffix : 4; } } } } } else { if (addr_modeP->mode==20) { /* look in ns32k_opcode for size */ addr_modeP->disp_suffix[0]=addr_modeP->am_size=desc->im_size; addr_modeP->im_disp=0; } } return addr_modeP->mode;}/* read an optionlist */void optlist(str,optionP,default_map) char *str; /* the string to extract options from */ struct option *optionP; /* how to search the string */ unsigned long *default_map; /* default pattern and output */{ register int i,j,k,strlen1,strlen2; register char *patternP,*strP; strlen1=strlen(str); if (strlen1<1) { as_fatal("Very short instr to option, ie you can't do it on a NULLstr"); } for (i=0;optionP[i].pattern!=0;i++) { strlen2=strlen(optionP[i].pattern); for (j=0;j<strlen1;j++) { patternP=optionP[i].pattern; strP = &str[j]; for (k=0;k<strlen2;k++) { if (*(strP++)!=*(patternP++)) break; } if (k==strlen2) { /* match */ *default_map|=optionP[i].or; *default_map&=optionP[i].and; } } }}/* search struct for symbols This function is used to get the short integer form of reg names in the instructions lmr, smr, lpr, spr return true if str is found in list */int list_search(str,optionP,default_map) char *str; /* the string to match */ struct option *optionP; /* list to search */ unsigned long *default_map; /* default pattern and output */{ register int i; for (i=0;optionP[i].pattern!=0;i++) { if (!strncmp(optionP[i].pattern,str,20)) { /* use strncmp to be safe */ *default_map|=optionP[i].or; *default_map&=optionP[i].and; return -1; } } as_warn("No such entry in list. (cpu/mmu register)"); return 0;}segT evaluate_expr(resultP,ptr)expressionS *resultP;char *ptr;{ register char *tmp_line; register segT segment; tmp_line=input_line_pointer; input_line_pointer=ptr; segment=expression(&exprP); input_line_pointer=tmp_line; return (segment);}/* Convert operands to iif-format and adds bitfields to the opcode. Operands are parsed in such an order that the opcode is updated from its most significant bit, that is when the operand need to alter the opcode. Be carefull not to put to objects in the same iif-slot. */encode_operand(argc,argv,operandsP,suffixP,im_size,opcode_bit_ptr) int argc; char **argv; char *operandsP; char *suffixP; char im_size; char opcode_bit_ptr;{ register int i,j; int pcrel,tmp,b,loop,pcrel_adjust; for(loop=0;loop<argc;loop++) { i=operandsP[loop<<1]-'1'; /* what operand are we supposed to work on */ if (i>3) as_fatal("Internal error check ns32k-opcode.h"); pcrel=0; pcrel_adjust=0; tmp=0; switch (operandsP[(loop<<1)+1]) { case 'f': /* operand of sfsr turns out to be a nasty specialcase */ opcode_bit_ptr-=5; case 'F': /* 32 bit float general form */ case 'L': /* 64 bit float */ case 'Q': /* quad-word */ case 'B': /* byte */ case 'W': /* word */ case 'D': /* double-word */ case 'A': /* double-word gen-address-form ie no regs allowed */ get_addr_mode(argv[i],&addr_modeP); iif.instr_size+=addr_modeP.am_size; if (opcode_bit_ptr==desc->opcode_size) b=4; else b=6; for (j=b;j<(b+2);j++) { if (addr_modeP.disp[j-b]) { IIF(j, 2, addr_modeP.disp_suffix[j-b], (unsigned long)addr_modeP.disp[j-b], 0, addr_modeP.pcrel, iif.instr_size-addr_modeP.am_size, /* this aint used (now) */ addr_modeP.im_disp, IND(BRANCH,BYTE), NULL, addr_modeP.scaled_reg ? addr_modeP.scaled_mode:addr_modeP.mode, 0); } } opcode_bit_ptr-=5; iif.iifP[1].object|=((long)addr_modeP.mode)<<opcode_bit_ptr; if (addr_modeP.scaled_reg) { j=b/2; IIF(j,1,1, (unsigned long)addr_modeP.index_byte,0,0,0,0,0, NULL,-1,0); } break; case 'b': /* multiple instruction disp */ freeptr++; /* OVE:this is an useful hack */ tmp=(int)sprintf(freeptr,"((%s-1)*%d)\000",argv[i],desc->im_size); argv[i]=freeptr; freeptr=(char*)tmp; pcrel-=1; /* make pcrel 0 inspite of what case 'p': wants */ /* fall thru */ case 'p': /* displacement - pc relative addressing */ pcrel+=1; /* fall thru */ case 'd': /* displacement */ iif.instr_size+=suffixP[i] ? suffixP[i] : 4; IIF(12, 2, suffixP[i], (unsigned long)argv[i], 0, pcrel, pcrel_adjust, 1, IND(BRANCH,BYTE), NULL,-1,0); break; case 'H': /* sequent-hack: the linker wants a bit set when bsr */ pcrel=1; iif.instr_size+=suffixP[i] ? suffixP[i] : 4; IIF(12, 2, suffixP[i], (unsigned long)argv[i], 0, pcrel, pcrel_adjust, 1, IND(BRANCH,BYTE), NULL,-1,1);break; case 'q': /* quick */ opcode_bit_ptr-=4; IIF(11,2,42,(unsigned long)argv[i],0,0,0,0,0, bit_fix_new(4,opcode_bit_ptr,-8,7,0,1,0),-1,0); break; case 'r': /* register number (3 bits) */ list_search(argv[i],opt6,&tmp); opcode_bit_ptr-=3; iif.iifP[1].object|=tmp<<opcode_bit_ptr; break; case 'O': /* setcfg instruction optionslist */ optlist(argv[i],opt3,&tmp); opcode_bit_ptr-=4; iif.iifP[1].object|=tmp<<15; break; case 'C': /* cinv instruction optionslist */ optlist(argv[i],opt4,&tmp); opcode_bit_ptr-=4; iif.iifP[1].object|=tmp<<15;/*insert the regtype in opcode */ break; case 'S': /* stringinstruction optionslist */ optlist(argv[i],opt5,&tmp); opcode_bit_ptr-=4; iif.iifP[1].object|=tmp<<15; break; case 'u':case 'U': /* registerlist */ IIF(10,1,1,0,0,0,0,0,0,NULL,-1,0); switch (operandsP[(i<<1)+1]) { case 'u': /* restore, exit */ optlist(argv[i],opt1,&iif.iifP[10].object); break; case 'U': /* save,enter */ optlist(argv[i],opt2,&iif.iifP[10].object); break; } iif.instr_size+=1; break; case 'M': /* mmu register */ list_search(argv[i],mmureg,&tmp); opcode_bit_ptr-=4; iif.iifP[1].object|=tmp<<opcode_bit_ptr; break; case 'P': /* cpu register */ list_search(argv[i],cpureg,&tmp); opcode_bit_ptr-=4; iif.iifP[1].object|=tmp<<opcode_bit_ptr; break; case 'g': /* inss exts */ iif.instr_size+=1; /* 1 byte is allocated after the opcode */ IIF(10,2,1, (unsigned long)argv[i], /* i always 2 here */ 0,0,0,0,0, bit_fix_new(3,5,0,7,0,0,0), /* a bit_fix is targeted to the byte */ -1,0); case 'G': IIF(11,2,42, (unsigned long)argv[i], /* i always 3 here */ 0,0,0,0,0, bit_fix_new(5,0,1,32,-1,0,-1),-1,0); break; case 'i': iif.instr_size+=1; b=2+i; /* put the extension byte after opcode */ IIF(b,2,1,0,0,0,0,0,0,0,-1,0); default: as_fatal("Bad opcode-table-option, check in file ns32k-opcode.h"); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -