📄 assyms.c
字号:
case JXALIGN: return("align"); case JXQUESTIONABLE: return("jxquestionable"); case JXINACTIVE: return("inactive"); case JXTUNNEL: return("tunnel"); case OBSOLETE: return("obsolete"); case IGNOREBOUND: return("ignorebound"); case FORWARDSTAB: return("forwardstab"); case FLOATINGSTAB: return("floatingstab"); case FIXEDSTAB: return("fixedstab"); case LABELID: return("labelid"); case OKTOBUMP: return("oktobump"); case ISET: return("iset"); case ILSYM: return("ilsym"); default: sprintf(tagbuff,"%d", tag); return(tagbuff); }}#endif /* DEBUG */htaballoc(){ register struct hashdallop *new; new = (struct hashdallop *)ClearCalloc(1, sizeof (struct hashdallop)); if (htab == 0) htab = new; else { /* add AFTER the 1st slot */ new->h_next = htab->h_next; htab->h_next = new; }}#define HASHCLOGGED (NHASH / 2)/* * Lookup a symbol stored in extern yytext. * All strings passed in via extern yytext had better have * a trailing null. Strings are placed in yytext for hashing by * syminstall() and by yylex(); * * We take pains to avoid function calls; this functdion * is called quite frequently, and the calls overhead * in the vax contributes significantly to the overall * execution speed of as. */struct symtab **lookup(instflg) int instflg; /* 0: don't install */{ static int initialprobe; register struct symtab **hp; register char *from; register char *to; register int len; register int nprobes; static struct hashdallop *hdallop; static struct symtab **emptyslot; static struct hashdallop *emptyhd; static struct symtab **hp_ub; emptyslot = 0; for (nprobes = 0, from = yytext; *from; nprobes <<= 2, nprobes += *from++) continue; nprobes += from[-1] << 5; nprobes %= NHASH; if (nprobes < 0) nprobes += NHASH; initialprobe = nprobes; for (hdallop = htab; hdallop != 0; hdallop = hdallop->h_next){ for (hp = &(hdallop->h_htab[initialprobe]), nprobes = 1, hp_ub = &(hdallop->h_htab[NHASH]); (*hp) && (nprobes < NHASH); hp += nprobes, hp -= (hp >= hp_ub) ? NHASH:0, nprobes += 2) { from = yytext; to = FETCHNAME(*hp); while (*from && *to) if (*from++ != *to++) goto nextprobe; if (*to == *from) /*assert both are == 0*/ return(hp); nextprobe: ; } if (*hp == 0 && emptyslot == 0 && hdallop->h_nused < HASHCLOGGED) { emptyslot = hp; emptyhd = hdallop; } } if (emptyslot == 0) { htaballoc(); hdallop = htab->h_next; /* aren't we smart! */ hp = &hdallop->h_htab[initialprobe]; } else { hdallop = emptyhd; hp = emptyslot; } if (instflg) { *hp = symalloc(); hdallop->h_nused++; for (from = yytext, len = 0; *from++; len++) continue; (*hp)->s_name = (char *)savestr(yytext, len + 1, STR_BOTH); } return(hp);} /*end of lookup*//* * save a string str with len in the places indicated by place */struct strdesc *savestr(str, len, place) char *str; int len; int place;{ reg struct strdesc *res; int tlen; /* * Compute the total length of the record to live in core */ tlen = sizeof(struct strdesc) - sizeof(res->sd_string); if (place & STR_CORE) tlen += len; /* * See if there is enough space for the record, * and allocate the record. */ if (tlen >= (STRPOOLDALLOP - strplhead->str_nalloc)) strpoolalloc(); res = (struct strdesc *)(strplhead->str_names + strplhead->str_nalloc); /* * Save the string information that is always present */ res->sd_stroff = strfilepos; res->sd_strlen = len; res->sd_place = place; /* * Now, save the string itself. If str is null, then * the characters have already been dumped to the file */ if ((place & STR_CORE) && str) movestr(res[0].sd_string, str, len); if (place & STR_FILE){ if (str){ fwrite(str, 1, len, strfile); } strfilepos += len; } /* * Adjust the in core string pool size */ strplhead->str_nalloc += tlen; return(res);}/* * The relocation information is saved internally in an array of * lists of relocation buffers. The relocation buffers are * exactly the same size as a token buffer; if we use VM for the * temporary file we reclaim this storage, otherwise we create * them by mallocing. */#define RELBUFLG TOKBUFLG#define NRELOC ((TOKBUFLG - \ (sizeof (int) + sizeof (struct relbufdesc *)) \ ) / (sizeof (struct relocation_info)))struct relbufdesc{ int rel_count; struct relbufdesc *rel_next; struct relocation_info rel_reloc[NRELOC];};extern struct relbufdesc *tok_free;#define rel_free tok_freestatic struct relbufdesc *rel_temp;struct relocation_info r_can_1PC;struct relocation_info r_can_0PC;initoutrel(){ r_can_0PC.r_address = 0; r_can_0PC.r_symbolnum = 0; r_can_0PC.r_pcrel = 0; r_can_0PC.r_length = 0; r_can_0PC.r_extern = 0; r_can_1PC = r_can_0PC; r_can_1PC.r_pcrel = 1;}outrel(xp, reloc_how) register struct exp *xp; int reloc_how; /* TYPB..TYPH + (possibly)RELOC_PCREL */{ struct relocation_info reloc; register int x_type_mask; int pcrel; x_type_mask = xp->e_xtype & ~XFORW; pcrel = reloc_how & RELOC_PCREL; reloc_how &= ~RELOC_PCREL; if (bitoff&07) yyerror("Padding error"); if (x_type_mask == XUNDEF) yyerror("Undefined reference"); if ( (x_type_mask != XABS) || pcrel ) { if (ty_NORELOC[reloc_how]) yyerror("Illegal Relocation of floating or large int number."); reloc = pcrel ? r_can_1PC : r_can_0PC; reloc.r_address = dotp->e_xvalue - ( (dotp < &usedot[NLOC] || readonlydata) ? 0 : datbase ); reloc.r_length = ty_nlg[reloc_how]; switch(x_type_mask){ case XXTRN | XUNDEF: reloc.r_symbolnum = xp->e_xname->s_index; reloc.r_extern = 1; break; default: if (readonlydata && (x_type_mask&~XXTRN) == XDATA) x_type_mask = XTEXT | (x_type_mask&XXTRN); reloc.r_symbolnum = x_type_mask; break; } if ( (relfil == 0) || (relfil->rel_count >= NRELOC) ){ if (rel_free){ rel_temp = rel_free; rel_free = rel_temp->rel_next; } else { rel_temp = (struct relbufdesc *) Calloc(1,sizeof (struct relbufdesc)); } rel_temp->rel_count = 0; rel_temp->rel_next = relfil; relfil = rusefile[dotp - &usedot[0]] = rel_temp; } relfil->rel_reloc[relfil->rel_count++] = reloc; } /* * write the unrelocated value to the text file */ dotp->e_xvalue += ty_nbyte[reloc_how]; if (pcrel) xp->e_xvalue -= dotp->e_xvalue; switch(reloc_how){ case TYPO: case TYPQ: case TYPF: case TYPD: case TYPG: case TYPH: bignumwrite(xp->e_number, reloc_how); break; default: bwrite((char *)&(xp->e_xvalue), ty_nbyte[reloc_how], txtfil); break; }}/* * Flush out all of the relocation information. * Note that the individual lists of buffers are in * reverse order, so we must reverse them */off_t closeoutrel(relocfile) BFILE *relocfile;{ int locindex; u_long Closeoutrel(); trsize = 0; for (locindex = 0; locindex < NLOC; locindex++){ trsize += Closeoutrel(rusefile[locindex], relocfile); } drsize = 0; for (locindex = 0; locindex < NLOC; locindex++){ drsize += Closeoutrel(rusefile[NLOC + locindex], relocfile); } return(trsize + drsize);}u_long Closeoutrel(relfil, relocfile) struct relbufdesc *relfil; BFILE *relocfile;{ u_long tail; if (relfil == 0) return(0L); tail = Closeoutrel(relfil->rel_next, relocfile); bwrite((char *)&relfil->rel_reloc[0], relfil->rel_count * sizeof (struct relocation_info), relocfile); return(tail + relfil->rel_count * sizeof (struct relocation_info));}#define NOUTSYMS (nsyms - njxxx - nforgotten - (savelabels ? 0 : nlabels))int sizesymtab(){ return (sizeof (struct nlist) * NOUTSYMS);}/* * Write out n symbols to file f, beginning at p * ignoring symbols that are obsolete, jxxx instructions, and * possibly, labels */int symwrite(symfile) BFILE *symfile;{ int symsout; /*those actually written*/ int symsdesired = NOUTSYMS; reg struct symtab *sp, *ub; char *name; /* temp to save the name */ int totalstr; /* * We use sp->s_index to hold the length of the * name; it isn't used for anything else */ register struct allocbox *allocwalk; symsout = 0; totalstr = sizeof(totalstr); DECLITERATE(allocwalk, sp, ub) { if (sp->s_tag >= IGNOREBOUND) continue; if (ISLABEL(sp)) continue; symsout++; name = sp->s_name; /* save pointer */ /* * the length of the symbol table string * always includes the trailing null; * blast the pointer to its a.out value. */ if (sp->s_name && (sp->s_index = STRLEN(sp))){ sp->s_nmx = totalstr; totalstr += sp->s_index; } else { sp->s_nmx = 0; } if (sp->s_ptype != 0) sp->s_type = sp->s_ptype; else sp->s_type = (sp->s_type & (~XFORW)); if (readonlydata && (sp->s_type&~N_EXT) == N_DATA) sp->s_type = N_TEXT | (sp->s_type & N_EXT); bwrite((char *)&sp->s_nm, sizeof (struct nlist), symfile); sp->s_name = name; /* restore pointer */ } if (symsout != symsdesired) yyerror("INTERNAL ERROR: Wrote %d symbols, wanted to write %d symbols\n", symsout, symsdesired); /* * Construct the string pool from the symbols that were written, * possibly fetching from the string file if the string * is not core resident. */ bwrite(&totalstr, sizeof(totalstr), symfile); symsout = 0; DECLITERATE(allocwalk, sp, ub) { if (sp->s_tag >= IGNOREBOUND) continue; if (ISLABEL(sp)) continue; symsout++; if (STRLEN(sp) > 0){ if (STRPLACE(sp) & STR_CORE){ bwrite(FETCHNAME(sp), STRLEN(sp), symfile); } else if (STRPLACE(sp) & STR_FILE){ char rbuf[2048]; int left, nread; fseek(strfile, STROFF(sp), 0); for (left = STRLEN(sp); left > 0; left -= nread){ nread = fread(rbuf, sizeof(char), min(sizeof(rbuf), left), strfile); if (nread == 0) break; bwrite(rbuf, nread, symfile); } } } } if (symsout != symsdesired) yyerror("INTERNAL ERROR: Wrote %d strings, wanted %d\n", symsout, symsdesired);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -