home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
SRC
/
unc.lzh
/
UNC
/
prin.c
< prev
next >
Wrap
Text File
|
1991-06-10
|
6KB
|
295 lines
/*
* SCCS: %W% %G% %U%
* Print stuff.
*
*EMACS_MODES:c
*/
#include <stdio.h>
#include "a.out.h"
#include "unc.h"
#include <ctype.h>
#define LINELNG 70
void gette(), getde();
long gettw(), getdw();
void prinst();
char noabs; /* No non-global absolutes */
extern int rel; /* File being analysed is relocatable */
int lpos;
extern struct commit abstab, comtab;
#ifdef COFF
extern char shlibout;
#endif /* COFF */
void gopos(x)
int x;
{
do /* mindestens 1 Space ausgeben */
xp += printf(" ");
while(xp < x);
}
void go1st()
{
xp = 0;
if (popt) gopos(PFIRST);
xp = 0;
}
/*
* Print absolute and common values.
*/
void pabs()
{
register int i;
register symbol cs;
for (i = 0; i < abstab.c_int; i++)
for (i = 0; i < abstab.c_int; i++) {
cs = abstab.c_symb[i];
xp += printf("#\tglobal\t%s\n", cs->s_name);
xp += printf("# %s\t= 0x%lx\n", cs->s_name, cs->s_value);
}
for (i = 0; i < comtab.c_int; i++) {
cs = comtab.c_symb[i];
xp += printf("\tcomm\t%s,%d\n", cs->s_name, cs->s_value);
xp += printf("\t.globl\t%s\n", cs->s_name);
xp += printf("%s\t=\t0x%lx\n", cs->s_name, cs->s_value);
}
for (i = 0; i < comtab.c_int; i++) {
cs = comtab.c_symb[i];
xp += printf("\t.comm\t%s,%d\n", cs->s_name, cs->s_value);
}
}
void phdr()
{
char *s;
go1st();
xp += printf("Ed");
gopos(OPCODE);
xp += printf("equ");
gopos(ARGUMENT);
xp += printf("%d\n", hdr._mh._medit);
go1st();
xp += printf("Typ_Lang");
gopos(OPCODE);
xp += printf("equ");
gopos(ARGUMENT);
xp += printf("$%x\n", 0xFFFF & hdr._mh._mtylan);
go1st();
xp += printf("Attr_Rev");
gopos(OPCODE);
xp += printf("equ");
gopos(ARGUMENT);
xp += printf("$%x\n", 0xFFFF & hdr._mh._mattrev);
go1st();
xp += printf("stk");
gopos(OPCODE);
xp += printf("equ");
gopos(ARGUMENT);
xp += printf("$%x\n\n", hdr._mstack);
go1st();
gopos(OPCODE);
xp += printf("psect");
gopos(ARGUMENT);
xp += printf("disas,Typ_Lang,Attr_Rev,Ed,stk,start\n\n");
}
/*
* print Addr & contents
*/
void pconts(pos)
long pos;
{
int len;
t_entry tent;
xp = 0;
gette(pos, &tent);
xp = printf("%05x %04x", pos, tent.t_contents);
for (len = tent.t_lng; len > 1; len--)
{
pos += 2;
gette(pos, &tent);
xp += printf("%04x", tent.t_contents);
}
do
xp += printf(" ");
while (xp < PFIRST);
}
/*
* Print out labels.
*/
void plabs(ls, seg)
register symbol ls;
int seg;
{
for (; ls != NULL; ls = ls->s_link) {
/* hcz !!!!! if (ls->s_type != seg)
continue; */
xp += printf("%s:", ls->s_name);
}
}
void addchar(s, c)
char *s;
char c;
{
char s1[2];
c &= '\xff';
strcpy(s1, " ");
if (isprint(c))
s1[0] = c;
strcat(s, s1);
}
/*
* Print out text.
*/
void ptext(fid)
register ef_fid fid;
{
register long tpos;
t_entry tstr;
char s[20];
int len, i;
tpos = hdr._mexec;
if (ismodule)
phdr();
for (; tpos < endp; tpos += len)
{
xp = 0;
if (popt > 0)
pconts(tpos);
xp = 0;
gette(tpos, &tstr);
plabs(tstr.t_lab, TEXT);
gopos(OPCODE);
gette(tpos, &tstr);
if (tstr.t_type == T_OPCODE)
{
prinst(&tstr, tpos);
len = tstr.t_lng << 1;
}
else
{
xp += printf("dc.w");
gopos(ARGUMENT);
s[0] = '\0';
xp += printf("$%x", tstr.t_contents);
addchar(s, (char) (tstr.t_contents >> 8));
addchar(s, (char) tstr.t_contents);
for (i = 2; i < 8; i += 2)
{
gette (tpos + i, &tstr);
if (tstr.t_type != T_OPCODE)
{
xp += printf(",$%x", tstr.t_contents);
addchar(s, (char) (tstr.t_contents >> 8));
addchar(s, (char) tstr.t_contents);
}
else
break;
}
gopos(STRING);
xp += printf("'%s'\n", s);
len = i;
}
}
/*
* Print out any trailing label.
*/
gette(tpos, &tstr);
plabs(tstr.t_lab, TEXT);
}
/*
* Print out data.
*/
void pdata(fid)
register ef_fid fid;
{
long beg, addr, len;
int init;
d_entry dent;
if (hdr._mdata == 0)
return;
printf("\n");
go1st();
gopos(OPCODE);
xp += printf("vsect\n");
go1st();
xp += printf("vstart:");
gopos(OPCODE);
xp += printf("ds.b");
init = 0;
gopos(ARGUMENT);
for (len = 0, beg = addr = a6offset; addr < a6offset + hdr._mdata;
len++, addr++ )
{
getde(addr, &dent);
if (dent.d_lab != NULL)
{
if (init == 0)
xp += printf("%d", len);
gopos(COMMENT);
xp += printf("$%x(a6)\n", beg);
len = 0;
beg = addr;
go1st();
xp += printf("%s", dent.d_lab->s_name);
gopos(OPCODE);
if ((init = dent.d_initialized) != 0)
{
xp += printf("dc.b");
gopos(ARGUMENT);
xp += printf("$%x", dent.d_contents & 0xff);
}
else
{
xp += printf("ds.b");
gopos(ARGUMENT);
}
}
else if (init)
xp += printf(",$%x", dent.d_contents);
}
if ((init = dent.d_initialized) == 0)
xp += printf("%d", len);
gopos(COMMENT);
xp += printf("$%x(a6)\n", beg);
go1st();
gopos(OPCODE);
xp += printf("ends\n\n");
go1st();
gopos(OPCODE);
xp += printf("ends");
xp = 0;
}