home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
SRC
/
unc.lzh
/
UNC
/
robj.c
< prev
next >
Wrap
Text File
|
1991-07-01
|
4KB
|
159 lines
/*
* Read object file
*
*/
#include <stdio.h>
#include "a.out.h"
#include "unc.h"
void gette(), getde(), setde(), putte(), putde();
long gettw(), getdw();
void reallst(), lclash(), nomem(), unimpl();
void addit();
char *malloc();
long lseek();
int par_entry, par_round, nmods, donedrel, donebrel;
struct commit abstab, comtab, dreltab;
long trelpos, drelpos, brelpos;
symbol lookup(), inventsymb(), getnsymb();
#define DBSIZE 100
#define STINIT 20
/*
* Read psect. Return ISFEHLER if not ok.
*/
int rtext(inf, outf)
int inf; /* input pathno */
ef_fid outf; /* Output file descriptor */
{
t_entry tstr;
register long size;
register int i, l;
unsigned short inbuf[DBSIZE/2];
/*
* Initialise fields in structure.
*/
tstr.t_type = T_UNKNOWN;
tstr.t_vins = 1; /* For the moment */
tstr.t_bdest = 0;
tstr.t_gbdest = 0;
tstr.t_lng = 1;
tstr.t_amap = 0;
tstr.t_dref = 0;
tstr.t_relsymb = NULL;
tstr.t_lab = NULL;
tstr.t_refhi = 0;
tstr.t_reflo = 0x7fffffff;
/* Read module header: */
(void) lseek(inf, 0, 0);
if (read(inf, (char *)&hdr, sizeof(hdr)) != sizeof(hdr))
clean(_errmsg(errno, "Can't read input file"));
if (hdr.fmagic != FMAGIC || ropt != 0)
{
if (hdr.fmagic != FMAGIC)
fprintf(stderr, "No module header found.. raw mode selected\n");
ismodule = 0;
a6offset=0;
hdr._mh._msize=_gs_size(inf);
hdr._mh._mname=hdr._mh._medit=0;
hdr._mh._maccess=0x555;
hdr._mh._mtylan=0x101;
hdr._mh._mattrev=0x8001;
hdr._mexec=hdr._mexcpt=0;
hdr._mdata=0x1000;
hdr._midata=0;
hdr._midref=0;
endp = hdr._mh._msize;
}
else
{
ismodule = 1;
a6offset = hdr._mh._mtylan & 0x200 != 0 ? 0x8000 : 0;
endp = hdr._midata != 0 ? hdr._midata : hdr._mh._msize;
}
(void) lseek(inf, hdr._mexec, 0);
size = endp - hdr._mexec;
while (size > 1) {
l = size > DBSIZE? DBSIZE: size;
if (read(inf, (char *)inbuf, l) != l)
return (ISFEHLER);
l /= 2;
for (i = 0; i < l; i++) {
tstr.t_contents = inbuf[i];
(void) write(outf->ef_t, (char *)&tstr, sizeof(tstr));
}
size -= l + l;
}
/*
* Extra one to cope with "etext".
*/
(void) write(outf->ef_t, (char *)&tstr, sizeof(tstr));
return (ISOK);
}
/*
* Same sort of thing for the data segment.
*/
int rdata(inf, outf)
int inf;
ef_fid outf; /* Output file descriptor */
{
d_entry dstr;
register long size;
unsigned long addr, len;
/*
* Initialise fields in structure.
*/
dstr.d_type = D_BYTE;
dstr.d_reloc = R_NONE;
dstr.d_lng = 1;
dstr.d_relsymb = NULL;
dstr.d_reldisp = 0;
dstr.d_lab = NULL;
dstr.d_initialized = 0;
for(size = 0; size < hdr._mdata; size++)
{
(void) write(outf->ef_d, (char *)&dstr, sizeof(dstr));
}
if (hdr._midata == 0)
return(ISOK);
(void) lseek(inf, hdr._midata, 0);
if (hdr._mdata != 0 && hdr._midata != 0)
while (1)
{
if (read(inf, (char *) &addr, sizeof(addr)) != sizeof(addr))
clean(_errmsg(errno, "Can't read input file"));
if (read(inf, (char *) &len, sizeof(len)) != sizeof(len))
clean(_errmsg(errno, "Can't read input file"));
if (addr == 0 || len == 0)
break;
addr += a6offset;
while(len--)
{
getde(addr, &dstr);
if (read(inf, (char *) &dstr.d_contents, 1) != 1)
clean(_errmsg(errno, "Can't read input file"));
dstr.d_initialized = 1;
putde(addr++, &dstr);
}
}
return(ISOK);
}