|
|
Power 6/32 Unix version 1.21
/* $Header: /var/lib/cvsd/repos/cci/cci/usr/src/usr.bin/cdb/transBsd/main.c,v 1.1.1.1 2019/07/28 12:25:33 root Exp $ */
/* (C) Copyright 1985 Third Eye Software, Inc. - All Rights Reserved */
#include "tes42.h"
#include <sys/file.h>
#include <stab.h>
/* indexes */
export int vissMac, vissMax;
export int vifd, vifdMac; /* vrgFd */
export int vipdMac, vipd; /* vrgPd */
export int viline, vilineMac = 1; /* vrgLine */
export int visym, visymMac = 1; /* vrgSym */
export int visymGlobal, visymGlMac, visymGlMax;
export int viauxMac, viaux; /* vrgAux */
export int vites42Max = tesF42Low; /* vrgTesF42 */
/* flags */
export int vfBlockPending; /* true if got local */
export int vfVerbose; /* true if we want text out */
export int vfWarn; /* give certain warnings */
export int vcLinesInProc; /* count of lines in cur proc */
/* tables */
export char *vsbNewStr; /* new string table */
export int vadjust = 1; /* forces bigger tables */
export pAUXU vrgAux; /* aux table */
export pPDR vrgPd; /* proc table */
export pFDR vrgFd; /* file table */
export pLINER vrgLine; /* line no table */
export pSYMR vrgSym; /* symbol table */
export pSYMR vrgSymGlobal; /* global symbol table */
export pSYMR vrgSymBrac[100]; /* block stack for RBRAC's */
export int *vrgTesF42; /* map 42 no's to tes aux's */
/* pointers */
export char *vsbType; /* points to cur type string */
export char *vsbMax; /* next avail. in vsbNewStr */
export pSYMR vsymProc; /* current proc symbol */
export pSYMR vsymBlock; /* block sym when pending */
export pSYMR vsymFile; /* current file */
export int vfdSym; /* channel of sym file */
export long vdot; /* last known adr in TEXT space */
export int vissTag; /* iss for tag type */
export HDRR vahdr;
/* kludges */
export int viauxProcPhony; /* something for phony procs */
export int viauxGlobalPhony; /* something for unknown globals */
/* KLUDGE for SUN!! */
export pNLISTR vnlist;
/* M A I N */
main(argc, argv)
int argc;
char *argv [];
{
char *sbFile = (char *) 0;
argv++;
while (--argc) {
if (*argv [0] == '-') {
switch (argv [0] [1]) {
case 's':
vadjust = atoi(argv[0]+2);
if ((vadjust <= 0) || (vadjust > 10)) {
printf("Bad scaling parameter: %d\n", vadjust);
exit(1);
} /* if */
argv++;
continue;
case 'v':
vfVerbose++;
argv++;
continue;
case 'w':
vfWarn++;
argv++;
continue;
default:
panic("illegal option");
} /* switch */
} else {
if (sbFile)
panic("only one filename allowed");
sbFile = argv [0];
argv++;
}
} /* while */
if (sbFile == (char *) 0)
sbFile = "a.out";
Sym42Init(sbFile);
AuxBtInit();
Map();
DumpAll(sbFile);
if (vfVerbose)
PrintAll();
exit(0);
} /* main */
/* M A P */
export void Map()
{
SYMR asym;
register pSYMR sym;
register pSYMR sym1;
register int tq;
int fFirstGlobal;
int isymType, sc, st, iss;
register char *sbName;
int cbName;
pFDR fd;
pPDR pd;
static TIR ati;
fFirstGlobal = true;
vnlist = (pNLISTR) malloc(vcsym * cbNLISTR);
if (vnlist == nlistNil) {
perror("allocation for symbol table");
exit(1);
} /* if */
if (read(vfdSym, vnlist, cbNLISTR * vcsym) != cbNLISTR * vcsym) {
perror("symbol read");
exit(1);
} /* if */
/* build something for phony procedures to point at */
viauxProcPhony = AddAux(isymNil);
ati.tq0 = tqProc;
ati.bt = btInt;
AddAux(ati);
viauxGlobalPhony = AddAux(AuxFBType(btInt));
DoFile(nlistNil, "temp");
while (vcsym--) {
sbName = vsbStr + vnlist->n_un.n_strx;
/* the following code to process loader symbols depends
* on their occuring after symbol table symbols in
* the bsd42 symbol table.
*/
sc = scNil;
st = stNil;
switch (vnlist->n_type) {
case N_TEXT:
cbName = strlen(sbName);
if (sbName[cbName - 1] == 'o' && sbName[cbName - 2] == '.') {
DoFile(vnlist, sbName);
vnlist++;
continue;
} else if (sbName[0] == '-'
&& sbName[1] == 'l'
&& sbName[2] == 'g') {
DoFile(vnlist, sbName);
vnlist++;
continue;
} else {
sc = scText;
st = stLabel;
goto llocal;
} /* if */
case N_DATA:
sc = scData;
st = stGlobal;
goto llocal;
case N_ABS:
break; /* for now we throw them away */
/* sc = scAbs;
* goto llocal;
*/
case N_BSS:
sc = scBss;
st = stGlobal;
llocal:
if (*sbName == '_') sbName++;
iss = IssFSbInsert(sbName);
if (!ExistingFdSymFIss(iss)) {
sym = SymFInsert();
sym->sc = sc;
sym->st = st;
sym->value = vnlist->n_value;
sym->iss = iss;
sym->index = viauxGlobalPhony;
} /* if */
vnlist++;
continue;
case N_EXT+N_TEXT:
if (vsymProc) {
/* there was a previous proc, so end it */
sym = SymFInsert();
sym->st = stEnd;
sym->sc = scText;
sym->index = IsymFSym(vsymProc);
sym->value = vdot; /* last know text adr */
ChangeAux(vsymProc->index, visym);
vsymProc = symNil;
} /* if */
asym.sc = scText;
if (*sbName == '_') sbName++;
asym.iss = IssFSbInsert(sbName);
if ((sym = ExistingSymFSbProc(asym.iss)) != symNil) {
if (!sym->sc)
sym->sc = asym.sc;
} else {
sym = SymFInsert();
sym->sc = asym.sc;
sym->st = stProc;
sym->index = viauxProcPhony;
sym->iss = asym.iss;
ProcInsert(IsymFSym(sym), vnlist->n_value, 0);
} /* if */
sym->value = vnlist->n_value;
vnlist++;
continue;
case N_EXT+N_DATA:
asym.sc = scData;
asym.st = stGlobal;
goto ldoexternal;
case N_EXT+N_ABS:
asym.sc = scAbs;
goto ldoexternal;
case N_EXT+N_BSS:
asym.sc = scBss;
asym.st = stGlobal;
ldoexternal:
if (*sbName == '_')
sbName++;
asym.iss = IssFSbInsert(sbName);
if ((sym = ExistingSymFGlobal(&asym)) != symNil) {
if (!sym->sc)
sym->sc = asym.sc;
} else {
if (fFirstGlobal) {
EndFile(vdot);
fFirstGlobal = false;
} /* if */
sym = SymFGlobal();
sym->sc = asym.sc;
sym->iss = asym.iss;
sym->index = viauxGlobalPhony;
} /* if */
sym->value = vnlist->n_value;
sym->st = asym.st;
vnlist++;
continue;
case N_SLINE:
DoLine(vnlist);
vnlist++;
continue;
case N_SOL:
vnlist++;
continue;
case N_SO:
DoFile(vnlist, sbName);
vnlist++;
continue;
case N_LBRAC:
DoLBrac(vnlist);
vnlist++;
continue;
case N_RBRAC:
DoRBrac(vnlist);
vnlist++;
continue;
default:
DoSym(vnlist, sbName);
} /* switch */
vnlist++;
} /*while */
/* fix the damn fd's, ya happy GFW? */
vrgFd[0].ipd = -1;
vrgFd[0].iline = 0;
for (fd = vrgFd+1, pd = vrgPd; fd < vrgFd+vifdMac; fd++) {
while ((pd < vrgPd+vipdMac) && (fd->adr > pd->adr))
pd++;
fd->ipd = pd - vrgPd;
if (vrgSym[pd->isym].index == viauxProcPhony)
pd->iline = 0;
fd->iline = pd->iline; /* is this always correct? */
} /* for */
} /* Map */
/* D U M P A L L */
export void DumpAll(sbFile)
char *sbFile;
{
char sbTes[200];
int cGlobals, file;
long cbOffset;
extern struct exec vhead;
strcpy(sbTes, sbFile);
strcat(sbTes, ".cdb");
vahdr.magic = vhead.a_magic;
vahdr.vstamp = 0;
vahdr.ijokeDay = ijokeNil;
vahdr.cbText = vhead.a_text;
vahdr.cbData = vhead.a_data;
vahdr.cbBss = vhead.a_bss;
vahdr.entrypoint = vhead.a_entry;
if ((file = open(sbTes, O_WRONLY+O_CREAT, 0666)) <= -1) {
perror("can't open output file");
exit(1);
} /* if */
#define WRITE_IT(fd,buf,size,count,msg) \
if (write(fd, buf, (size) * (count)) != (size) * (count)) {\
perror(msg);\
exit(1);\
} else {\
cbOffset += (size) * (count);\
} /* if */
cbOffset = 0;
WRITE_IT(file, &vahdr, cbHDRR, 1, "header")
vahdr.ipdMax = vipdMac;
vahdr.cbPdOffset = cbOffset;
WRITE_IT(file, vrgPd, cbPDR, vipdMac, "procedures")
vahdr.ifdMax = vifdMac;
vahdr.cbFdOffset = cbOffset;
WRITE_IT(file, vrgFd, cbFDR, vifdMac, "files")
vahdr.ilineMax = vilineMac;
vahdr.cbLineOffset = cbOffset;
WRITE_IT(file, vrgLine, cbLINER, vilineMac, "lines")
vahdr.iauxMax = viauxMac;
vahdr.cbAuxOffset = cbOffset;
WRITE_IT(file, vrgAux, cbAUXU, viauxMac, "auxes")
vahdr.isymGl = visymMac;
vahdr.isymGlMax = vahdr.isymMax = visymMac + visymGlMac;
vahdr.cbSymOffset = cbOffset;
WRITE_IT(file, vrgSym, cbSYMR, visymMac, "symbols")
WRITE_IT(file, vrgSymGlobal, cbSYMR, visymGlMac, "globals")
vahdr.issMax = vissMac;
vahdr.cbSsOffset = cbOffset;
WRITE_IT(file, vsbNewStr, vissMac, 1, "strings");
lseek(file, 0L, 0);
WRITE_IT(file, &vahdr, cbHDRR, 1, "header")
} /* DumpAll */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.