mirror of
https://github.com/dreamlayers/netbsd-mopd.git
synced 2026-04-26 03:57:20 +00:00
Application of mopd-2.5.3-elf.patch:
* Sun Nov 17 2002 Maciej W. Rozycki <macro@ds2.pg.gda.pl> 2.5.3-15 - modified Makefiles to improve portability: specify "-lelf" last for the linker, define LIBELF in the top-level Makefile to permit overriding (elf) * Sun Nov 11 2001 Maciej W. Rozycki <macro@ds2.pg.gda.pl> 2.5.3-13 - a bug affecting multisegment ELF files again, sigh... (elf) * Sun Nov 11 2001 Maciej W. Rozycki <macro@ds2.pg.gda.pl> - 64-bit ELF support (elf) * Sun Nov 11 2001 Maciej W. Rozycki <macro@ds2.pg.gda.pl> - pass the entry point address as is as it's more flexible; print ELF file information; bug fixes (elf) * Sat Nov 10 2001 Maciej W. Rozycki <macro@ds2.pg.gda.pl> - reject dynamically linked executables; calculate a physical entry point address from the virtual one; bug fixes (elf) * Fri Nov 9 2001 Maciej W. Rozycki <macro@ds2.pg.gda.pl> - map ELF segments by their physical addresses to facilitate systems which boot with their memory mapping different from the final one; sort phdrs by ascending addresses; bug fixes (elf) * Thu Nov 8 2001 Maciej W. Rozycki <macro@ds2.pg.gda.pl> - took the header block count of MOP images into account (elf) - addedd handling of MOP images with a null block count or size specified in the header (elf) * Sun Oct 28 2001 Maciej W. Rozycki <macro@ds2.pg.gda.pl> - fixed a stupid bug causing multisegment ELF files not to be sent properly (elf) * Fri Oct 26 2001 Maciej W. Rozycki <macro@ds2.pg.gda.pl> - added ELF support (elf) Downloaded from: ftp://ftp.linux-mips.org/pub/linux/mips/people/macro/mopd/mopd-2.5.3-elf.patch.gz .patch SHA256 = f63818152cd74e551068ea7856e0cc872ddd2f78485cda08a77b3d81a1aa845c Patch history copied from: ftp://ftp.linux-mips.org/pub/linux/mips/people/macro/mopd/mopd-2.5.3-15.spec
This commit is contained in:
committed by
Boris Gjenero
parent
3b606eb2af
commit
8920dbffcd
4
Makefile
4
Makefile
@@ -4,6 +4,7 @@ RANLIB = ranlib
|
|||||||
|
|
||||||
CFLAGS = -O2 -g
|
CFLAGS = -O2 -g
|
||||||
LDFLAGS =
|
LDFLAGS =
|
||||||
|
LIBELF = -lelf
|
||||||
|
|
||||||
SUBDIRS = common mopd mopchk mopprobe moptrace
|
SUBDIRS = common mopd mopchk mopprobe moptrace
|
||||||
|
|
||||||
@@ -11,6 +12,7 @@ all clean:
|
|||||||
@for dir in $(SUBDIRS); do \
|
@for dir in $(SUBDIRS); do \
|
||||||
(cd $$dir && \
|
(cd $$dir && \
|
||||||
$(MAKE) "AR=$(AR)" "CC=$(CC)" "RANLIB=$(RANLIB)" \
|
$(MAKE) "AR=$(AR)" "CC=$(CC)" "RANLIB=$(RANLIB)" \
|
||||||
"CFLAGS=$(CFLAGS)" "LDFLAGS=$(LDFLAGS)" $@) || \
|
"CFLAGS=$(CFLAGS)" "LDFLAGS=$(LDFLAGS)" \
|
||||||
|
"LIBELF=$(LIBELF)" $@) || \
|
||||||
exit 1; \
|
exit 1; \
|
||||||
done
|
done
|
||||||
|
|||||||
@@ -71,6 +71,28 @@ struct if_info {
|
|||||||
#define DL_STATUS_SENT_MLD 2
|
#define DL_STATUS_SENT_MLD 2
|
||||||
#define DL_STATUS_SENT_PLT 3
|
#define DL_STATUS_SENT_PLT 3
|
||||||
|
|
||||||
|
#define FTYPE_NONE 0 /* unindentified image */
|
||||||
|
#define FTYPE_MOP 1 /* DEC MOP image */
|
||||||
|
#define FTYPE_AOUT 2 /* a.out executable */
|
||||||
|
#define FTYPE_COFF 3 /* COFF executable */
|
||||||
|
#define FTYPE_ELF 4 /* ELF executable */
|
||||||
|
|
||||||
|
#define SEG_TEXT 0 /* Segment table entry numbers */
|
||||||
|
#define SEG_DATA 1 /* for file types that use */
|
||||||
|
#define SEG_BSS 2 /* fixed segments */
|
||||||
|
|
||||||
|
#define MAXSEG 16 /* Max. number of program segments */
|
||||||
|
|
||||||
|
struct seg {
|
||||||
|
off_t seek; /* File offset of segment */
|
||||||
|
u_long data; /* Size of segment data */
|
||||||
|
u_long fill; /* Size of segment fill */
|
||||||
|
};
|
||||||
|
|
||||||
|
struct segs {
|
||||||
|
struct seg s[MAXSEG]; /* File segments */
|
||||||
|
};
|
||||||
|
|
||||||
struct dllist {
|
struct dllist {
|
||||||
u_char status; /* Status byte */
|
u_char status; /* Status byte */
|
||||||
struct if_info *ii; /* interface pointer */
|
struct if_info *ii; /* interface pointer */
|
||||||
@@ -82,15 +104,9 @@ struct dllist {
|
|||||||
u_long loadaddr; /* Load Address */
|
u_long loadaddr; /* Load Address */
|
||||||
u_long xferaddr; /* Transfer Address */
|
u_long xferaddr; /* Transfer Address */
|
||||||
u_long nloadaddr; /* Next Load Address */
|
u_long nloadaddr; /* Next Load Address */
|
||||||
long lseek; /* Seek before last read */
|
int ftype; /* File type */
|
||||||
int aout; /* Is it an a.out file */
|
struct segs seg; /* File segments */
|
||||||
u_long a_text; /* Size of text segment */
|
u_long addr; /* Current relative address */
|
||||||
u_long a_text_fill; /* Size of text segment fill */
|
|
||||||
u_long a_data; /* Size of data segment */
|
|
||||||
u_long a_data_fill; /* Size of data segment fill */
|
|
||||||
u_long a_bss; /* Size of bss segment */
|
|
||||||
u_long a_bss_fill; /* Size of bss segment fill */
|
|
||||||
long a_lseek; /* Keep track of pos in newfile */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif _COMMON_H_
|
#endif _COMMON_H_
|
||||||
|
|||||||
502
common/file.c
502
common/file.c
@@ -72,6 +72,22 @@ static char rcsid[] = "$Id: file.c,v 1.4 1996/08/16 22:39:22 moj Exp $";
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef NOELF
|
||||||
|
#include <libelf/libelf.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct mopphdr {
|
||||||
|
off_t offset;
|
||||||
|
u_long paddr;
|
||||||
|
u_long filesz;
|
||||||
|
u_long memsz;
|
||||||
|
u_long fill;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct mopphdrs {
|
||||||
|
struct mopphdr p[MAXSEG];
|
||||||
|
};
|
||||||
|
|
||||||
int fileinfo;
|
int fileinfo;
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -178,13 +194,15 @@ CheckMopFile(fd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
GetMopFileInfo(fd, load, xfr)
|
GetMopFileInfo(fd, load, xfr, ftype, seg)
|
||||||
int fd;
|
int fd, *ftype;
|
||||||
u_long *load, *xfr;
|
u_long *load, *xfr;
|
||||||
|
struct segs *seg;
|
||||||
{
|
{
|
||||||
u_char header[512];
|
u_char header[512];
|
||||||
short image_type;
|
short image_type;
|
||||||
u_long load_addr, xfr_addr, isd, iha, hbcnt, isize;
|
u_long load_addr, xfr_addr, isd, iha;
|
||||||
|
off_t hbcnt, isize;
|
||||||
|
|
||||||
(void)lseek(fd, (off_t) 0, SEEK_SET);
|
(void)lseek(fd, (off_t) 0, SEEK_SET);
|
||||||
|
|
||||||
@@ -309,6 +327,26 @@ GetMopFileInfo(fd, load, xfr)
|
|||||||
*xfr = xfr_addr;
|
*xfr = xfr_addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (seg != NULL) {
|
||||||
|
off_t hsize;
|
||||||
|
|
||||||
|
hsize = hbcnt * 512;
|
||||||
|
if (!hsize || !isize) {
|
||||||
|
hsize = 512;
|
||||||
|
isize = lseek(fd, (off_t) 0, SEEK_END);
|
||||||
|
if (isize < 0)
|
||||||
|
return(-1);
|
||||||
|
isize -= hsize;
|
||||||
|
}
|
||||||
|
|
||||||
|
seg->s[SEG_TEXT].seek = hsize;
|
||||||
|
seg->s[SEG_TEXT].data = isize;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ftype != NULL) {
|
||||||
|
*ftype = FTYPE_MOP;
|
||||||
|
}
|
||||||
|
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -463,11 +501,10 @@ CheckAOutFile(fd)
|
|||||||
|
|
||||||
/*###440 [cc] syntax error before `int'%%%*/
|
/*###440 [cc] syntax error before `int'%%%*/
|
||||||
int
|
int
|
||||||
GetAOutFileInfo(fd, load, xfr, a_text, a_text_fill,
|
GetAOutFileInfo(fd, load, xfr, ftype, seg)
|
||||||
a_data, a_data_fill, a_bss, a_bss_fill, aout)
|
int fd, *ftype;
|
||||||
int fd, *aout;
|
u_long *load, *xfr;
|
||||||
u_long *load, *xfr, *a_text, *a_text_fill;
|
struct segs *seg;
|
||||||
u_long *a_data, *a_data_fill, *a_bss, *a_bss_fill;
|
|
||||||
{
|
{
|
||||||
#ifdef NOAOUT
|
#ifdef NOAOUT
|
||||||
return(-1);
|
return(-1);
|
||||||
@@ -631,7 +668,7 @@ GetAOutFileInfo(fd, load, xfr, a_text, a_text_fill,
|
|||||||
|
|
||||||
/*###608 [cc] `load' undeclared (first use this function)%%%*/
|
/*###608 [cc] `load' undeclared (first use this function)%%%*/
|
||||||
if (load != NULL) {
|
if (load != NULL) {
|
||||||
*load = 0;
|
*load = N_TXTADDR(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*###612 [cc] `xfr' undeclared (first use this function)%%%*/
|
/*###612 [cc] `xfr' undeclared (first use this function)%%%*/
|
||||||
@@ -639,106 +676,321 @@ GetAOutFileInfo(fd, load, xfr, a_text, a_text_fill,
|
|||||||
*xfr = ex.a_entry;
|
*xfr = ex.a_entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*###616 [cc] `a_text' undeclared (first use this function)%%%*/
|
/*###616 [cc] `seg' undeclared (first use this function)%%%*/
|
||||||
if (a_text != NULL) {
|
if (seg != NULL) {
|
||||||
*a_text = ex.a_text;
|
u_long fill;
|
||||||
}
|
|
||||||
|
|
||||||
/*###620 [cc] `a_text_fill' undeclared (first use this function)%%%*/
|
seg->s[SEG_TEXT].seek = N_TXTOFF(ex);
|
||||||
if (a_text_fill != NULL) {
|
seg->s[SEG_TEXT].data = ex.a_text;
|
||||||
if (magic == ZMAGIC || magic == NMAGIC) {
|
if (magic == ZMAGIC || magic == NMAGIC) {
|
||||||
*a_text_fill = clbytes - (ex.a_text & clofset);
|
fill = clbytes - (ex.a_text & clofset);
|
||||||
if (*a_text_fill == clbytes) {
|
if (fill == clbytes) {
|
||||||
*a_text_fill = 0;
|
fill = 0;
|
||||||
}
|
}
|
||||||
} else {
|
seg->s[SEG_TEXT].fill = fill;
|
||||||
*a_text_fill = 0;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*###631 [cc] `a_data' undeclared (first use this function)%%%*/
|
seg->s[SEG_DATA].seek = N_DATOFF(ex);
|
||||||
if (a_data != NULL) {
|
seg->s[SEG_DATA].data = ex.a_data;
|
||||||
*a_data = ex.a_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*###635 [cc] `a_data_fill' undeclared (first use this function)%%%*/
|
|
||||||
if (a_data_fill != NULL) {
|
|
||||||
if (magic == ZMAGIC || magic == NMAGIC) {
|
if (magic == ZMAGIC || magic == NMAGIC) {
|
||||||
*a_data_fill = clbytes - (ex.a_data & clofset);
|
fill = clbytes - (ex.a_data & clofset);
|
||||||
if (*a_data_fill == clbytes) {
|
if (fill == clbytes) {
|
||||||
*a_data_fill = 0;
|
fill = 0;
|
||||||
}
|
}
|
||||||
} else {
|
seg->s[SEG_DATA].fill = fill;
|
||||||
*a_data_fill = 0;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*###646 [cc] `a_bss' undeclared (first use this function)%%%*/
|
|
||||||
if (a_bss != NULL) {
|
|
||||||
*a_bss = ex.a_bss;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*###650 [cc] `a_bss_fill' undeclared (first use this function)%%%*/
|
|
||||||
if (a_bss_fill != NULL) {
|
|
||||||
if (magic == ZMAGIC || magic == NMAGIC) {
|
if (magic == ZMAGIC || magic == NMAGIC) {
|
||||||
*a_bss_fill = clbytes - (ex.a_bss & clofset);
|
fill = clbytes - (ex.a_bss & clofset);
|
||||||
if (*a_bss_fill == clbytes) {
|
} else {
|
||||||
*a_bss_fill = 0;
|
fill = clbytes -
|
||||||
}
|
((ex.a_text + ex.a_data + ex.a_bss) & clofset);
|
||||||
} else {
|
|
||||||
*a_bss_fill = clbytes -
|
|
||||||
((ex.a_text+ex.a_data+ex.a_bss) & clofset);
|
|
||||||
if (*a_text_fill == clbytes) {
|
|
||||||
*a_text_fill = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (fill == clbytes) {
|
||||||
|
fill = 0;
|
||||||
|
}
|
||||||
|
seg->s[SEG_BSS].fill = ex.a_bss + fill;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*###665 [cc] `aout' undeclared (first use this function)%%%*/
|
/*###665 [cc] `ftype' undeclared (first use this function)%%%*/
|
||||||
if (aout != NULL) {
|
if (ftype != NULL) {
|
||||||
*aout = mid;
|
*ftype = FTYPE_AOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
return(0);
|
return(0);
|
||||||
#endif NOAOUT
|
#endif NOAOUT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef NOELF
|
||||||
|
void
|
||||||
|
sortELFphdrs(p, l, r)
|
||||||
|
struct mopphdrs *p;
|
||||||
|
int l, r;
|
||||||
|
{
|
||||||
|
struct mopphdr tmp;
|
||||||
|
int lp = l, rp = r, mp = (l + r) / 2;
|
||||||
|
|
||||||
|
do {
|
||||||
|
while (p->p[lp].paddr < p->p[mp].paddr)
|
||||||
|
lp++;
|
||||||
|
while (p->p[mp].paddr < p->p[rp].paddr)
|
||||||
|
rp--;
|
||||||
|
if (lp <= rp) {
|
||||||
|
tmp = p->p[lp];
|
||||||
|
p->p[lp] = p->p[rp];
|
||||||
|
p->p[rp] = tmp;
|
||||||
|
lp++;
|
||||||
|
rp--;
|
||||||
|
}
|
||||||
|
} while (lp <= rp);
|
||||||
|
if (l < rp)
|
||||||
|
sortELFphdrs(p, l, rp);
|
||||||
|
if (lp < r)
|
||||||
|
sortELFphdrs(p, lp, r);
|
||||||
|
}
|
||||||
|
#endif /* NOELF */
|
||||||
|
|
||||||
|
int
|
||||||
|
CheckELFFile(fd)
|
||||||
|
int fd;
|
||||||
|
{
|
||||||
|
#ifdef NOELF
|
||||||
|
return(-1);
|
||||||
|
#else
|
||||||
|
Elf *elf;
|
||||||
|
|
||||||
|
if (elf_version(EV_CURRENT) == EV_NONE)
|
||||||
|
return(-1);
|
||||||
|
|
||||||
|
elf = elf_begin(fd, ELF_C_READ, NULL);
|
||||||
|
if (!elf)
|
||||||
|
return(-1);
|
||||||
|
|
||||||
|
if (elf_kind(elf) != ELF_K_ELF) {
|
||||||
|
elf_end(elf);
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
elf_end(elf);
|
||||||
|
return(0);
|
||||||
|
#endif /* NOELF */
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
GetELFFileInfo(fd, load, xfr, ftype, seg)
|
||||||
|
int fd, *ftype;
|
||||||
|
u_long *load, *xfr;
|
||||||
|
struct segs *seg;
|
||||||
|
{
|
||||||
|
#ifdef NOELF
|
||||||
|
return(-1);
|
||||||
|
#else
|
||||||
|
struct mopphdrs p;
|
||||||
|
Elf *elf;
|
||||||
|
Elf32_Ehdr *ehdr;
|
||||||
|
Elf32_Phdr *phdr;
|
||||||
|
Elf64_Ehdr *e64hdr;
|
||||||
|
Elf64_Phdr *p64hdr;
|
||||||
|
char ei_class;
|
||||||
|
char ei_data;
|
||||||
|
int e_type;
|
||||||
|
u_long e_entry;
|
||||||
|
int e_phnum;
|
||||||
|
long p_type;
|
||||||
|
int i, j;
|
||||||
|
|
||||||
|
elf = elf_begin(fd, ELF_C_READ, NULL);
|
||||||
|
if (!elf)
|
||||||
|
return(-1);
|
||||||
|
|
||||||
|
ehdr = elf32_getehdr(elf);
|
||||||
|
phdr = elf32_getphdr(elf);
|
||||||
|
e64hdr = elf64_getehdr(elf);
|
||||||
|
p64hdr = elf64_getphdr(elf);
|
||||||
|
|
||||||
|
if ((!ehdr || !phdr) && (!e64hdr || !p64hdr)) {
|
||||||
|
elf_end(elf);
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
e_type = ehdr ? ehdr->e_type : e64hdr->e_type;
|
||||||
|
if (e_type != ET_EXEC) {
|
||||||
|
if (fileinfo)
|
||||||
|
printf("ELF non-executable, not supported\n");
|
||||||
|
elf_end(elf);
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
e_entry = ehdr ? ehdr->e_entry : e64hdr->e_entry;
|
||||||
|
|
||||||
|
bzero(&p, sizeof(p));
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
j = 0;
|
||||||
|
e_phnum = ehdr ? ehdr->e_phnum : e64hdr->e_phnum;
|
||||||
|
while (i < e_phnum) {
|
||||||
|
|
||||||
|
p_type = phdr ? phdr->p_type : p64hdr->p_type;
|
||||||
|
if (p_type == PT_DYNAMIC) {
|
||||||
|
if (fileinfo)
|
||||||
|
printf("ELF dynamic executable, "
|
||||||
|
"not supported\n");
|
||||||
|
elf_end(elf);
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p_type == PT_LOAD) {
|
||||||
|
|
||||||
|
if (j >= MAXSEG) {
|
||||||
|
if (fileinfo)
|
||||||
|
printf("ELF executable, "
|
||||||
|
"over %u segments, "
|
||||||
|
"not supported\n", MAXSEG);
|
||||||
|
elf_end(elf);
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (phdr) {
|
||||||
|
p.p[j].offset = phdr->p_offset;
|
||||||
|
p.p[j].paddr = phdr->p_paddr;
|
||||||
|
p.p[j].filesz = phdr->p_filesz;
|
||||||
|
p.p[j].memsz = phdr->p_memsz;
|
||||||
|
} else {
|
||||||
|
p.p[j].offset = p64hdr->p_offset;
|
||||||
|
p.p[j].paddr = p64hdr->p_paddr;
|
||||||
|
p.p[j].filesz = p64hdr->p_filesz;
|
||||||
|
p.p[j].memsz = p64hdr->p_memsz;
|
||||||
|
}
|
||||||
|
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (phdr)
|
||||||
|
phdr++;
|
||||||
|
else
|
||||||
|
p64hdr++;
|
||||||
|
i++;
|
||||||
|
};
|
||||||
|
if (!j) {
|
||||||
|
if (fileinfo)
|
||||||
|
printf("ELF executable, no segments to load\n");
|
||||||
|
elf_end(elf);
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
sortELFphdrs(&p, 0, j - 1);
|
||||||
|
|
||||||
|
for (i = 0; i < j; i++) {
|
||||||
|
p.p[i].fill = p.p[i].memsz - p.p[i].filesz;
|
||||||
|
if (i > 0)
|
||||||
|
p.p[i - 1].fill += p.p[i].paddr -
|
||||||
|
(p.p[i - 1].paddr +
|
||||||
|
p.p[i - 1].memsz);
|
||||||
|
if (seg != NULL) {
|
||||||
|
seg->s[i].seek = p.p[i].offset;
|
||||||
|
seg->s[i].data = p.p[i].filesz;
|
||||||
|
seg->s[i].fill = p.p[i].fill;
|
||||||
|
if (i > 0)
|
||||||
|
seg->s[i - 1].fill = p.p[i - 1].fill;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (load != NULL) {
|
||||||
|
*load = p.p[0].paddr;
|
||||||
|
}
|
||||||
|
if (xfr != NULL) {
|
||||||
|
*xfr = e_entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fileinfo) {
|
||||||
|
char *clstr = "";
|
||||||
|
char *dtstr = "";
|
||||||
|
|
||||||
|
ei_class = ehdr ? ehdr->e_ident[EI_CLASS] :
|
||||||
|
e64hdr->e_ident[EI_CLASS];
|
||||||
|
ei_data = ehdr ? ehdr->e_ident[EI_DATA] :
|
||||||
|
e64hdr->e_ident[EI_DATA];
|
||||||
|
switch (ei_class) {
|
||||||
|
case ELFCLASS32:
|
||||||
|
clstr = " 32-bit";
|
||||||
|
break;
|
||||||
|
case ELFCLASS64:
|
||||||
|
clstr = " 64-bit";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
;
|
||||||
|
}
|
||||||
|
switch (ei_data) {
|
||||||
|
case ELFDATA2LSB:
|
||||||
|
dtstr = " LSB";
|
||||||
|
break;
|
||||||
|
case ELFDATA2MSB:
|
||||||
|
dtstr = " MSB";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
;
|
||||||
|
}
|
||||||
|
printf("ELF%s%s executable\n", clstr, dtstr);
|
||||||
|
for (i = 0; i < j; i++)
|
||||||
|
printf("Size of seg #%02d: %08x (+ %08x fill)\n",
|
||||||
|
i, p.p[i].filesz, p.p[i].fill);
|
||||||
|
printf("Load Address: %08x\n", p.p[0].paddr);
|
||||||
|
printf("Transfer Address: %08x\n", e_entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ftype != NULL) {
|
||||||
|
*ftype = FTYPE_ELF;
|
||||||
|
}
|
||||||
|
|
||||||
|
elf_end(elf);
|
||||||
|
|
||||||
|
return(0);
|
||||||
|
#endif /* NOELF */
|
||||||
|
}
|
||||||
|
|
||||||
/*###673 [cc] syntax error before `int'%%%*/
|
/*###673 [cc] syntax error before `int'%%%*/
|
||||||
int
|
int
|
||||||
GetFileInfo(fd, load, xfr, aout,
|
GetFileInfo(fd, load, xfr, ftype, seg)
|
||||||
a_text, a_text_fill, a_data, a_data_fill, a_bss, a_bss_fill)
|
int fd, *ftype;
|
||||||
int fd, *aout;
|
u_long *load, *xfr;
|
||||||
u_long *load, *xfr, *a_text, *a_text_fill;
|
struct segs *seg;
|
||||||
u_long *a_data, *a_data_fill, *a_bss, *a_bss_fill;
|
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
*ftype = FTYPE_NONE;
|
||||||
|
bzero(seg, sizeof(*seg));
|
||||||
|
|
||||||
|
err = CheckELFFile(fd);
|
||||||
|
|
||||||
|
if (err == 0) {
|
||||||
|
err = GetELFFileInfo(fd, load, xfr, ftype, seg);
|
||||||
|
if (err != 0) {
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
err = CheckAOutFile(fd);
|
err = CheckAOutFile(fd);
|
||||||
|
|
||||||
if (err == 0) {
|
if (err == 0) {
|
||||||
err = GetAOutFileInfo(fd, load, xfr,
|
err = GetAOutFileInfo(fd, load, xfr, ftype, seg);
|
||||||
a_text, a_text_fill,
|
|
||||||
a_data, a_data_fill,
|
|
||||||
a_bss, a_bss_fill,
|
|
||||||
aout);
|
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
} else {
|
return(0);
|
||||||
err = CheckMopFile(fd);
|
|
||||||
|
|
||||||
if (err == 0) {
|
|
||||||
err = GetMopFileInfo(fd, load, xfr);
|
|
||||||
if (err != 0) {
|
|
||||||
return(-1);
|
|
||||||
}
|
|
||||||
*aout = -1;
|
|
||||||
} else {
|
|
||||||
return(-1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return(0);
|
err = CheckMopFile(fd);
|
||||||
|
|
||||||
|
if (err == 0) {
|
||||||
|
err = GetMopFileInfo(fd, load, xfr, ftype, seg);
|
||||||
|
if (err != 0) {
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t
|
ssize_t
|
||||||
@@ -748,20 +1000,20 @@ mopFileRead(dlslot, buf)
|
|||||||
u_char *buf;
|
u_char *buf;
|
||||||
{
|
{
|
||||||
ssize_t len, outlen;
|
ssize_t len, outlen;
|
||||||
int bsz;
|
int bsz, i;
|
||||||
long pos, notdone, total;
|
long pos, notdone, total;
|
||||||
|
|
||||||
/*###719 [cc] `dlslot' undeclared (first use this function)%%%*/
|
bsz = dlslot->dl_bsz;
|
||||||
if (dlslot->aout == -1) {
|
pos = dlslot->addr;
|
||||||
/*###720 [cc] `buf' undeclared (first use this function)%%%*/
|
total = 0;
|
||||||
len = read(dlslot->ldfd,buf,dlslot->dl_bsz);
|
len = 0;
|
||||||
} else {
|
|
||||||
bsz = dlslot->dl_bsz;
|
|
||||||
pos = dlslot->a_lseek;
|
|
||||||
len = 0;
|
|
||||||
|
|
||||||
total = dlslot->a_text;
|
i = 0;
|
||||||
|
while (i < MAXSEG) {
|
||||||
|
if (pos == total)
|
||||||
|
lseek(dlslot->ldfd, dlslot->seg.s[i].seek, SEEK_SET);
|
||||||
|
|
||||||
|
total += dlslot->seg.s[i].data;
|
||||||
if (pos < total) {
|
if (pos < total) {
|
||||||
notdone = total - pos;
|
notdone = total - pos;
|
||||||
if (notdone <= bsz) {
|
if (notdone <= bsz) {
|
||||||
@@ -776,8 +1028,11 @@ mopFileRead(dlslot, buf)
|
|||||||
bsz = bsz - outlen;
|
bsz = bsz - outlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
total = total + dlslot->a_text_fill;
|
dlslot->addr = pos;
|
||||||
|
if (!bsz)
|
||||||
|
break;
|
||||||
|
|
||||||
|
total += dlslot->seg.s[i].fill;
|
||||||
if ((bsz > 0) && (pos < total)) {
|
if ((bsz > 0) && (pos < total)) {
|
||||||
notdone = total - pos;
|
notdone = total - pos;
|
||||||
if (notdone <= bsz) {
|
if (notdone <= bsz) {
|
||||||
@@ -792,72 +1047,11 @@ mopFileRead(dlslot, buf)
|
|||||||
bsz = bsz - outlen;
|
bsz = bsz - outlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
total = total + dlslot->a_data;
|
dlslot->addr = pos;
|
||||||
|
if (!bsz)
|
||||||
if ((bsz > 0) && (pos < total)) {
|
break;
|
||||||
notdone = total - pos;
|
|
||||||
if (notdone <= bsz) {
|
|
||||||
/*###760 [cc] subscripted value is neither array nor pointer%%%*/
|
|
||||||
outlen = read(dlslot->ldfd,&buf[len],notdone);
|
|
||||||
} else {
|
|
||||||
/*###762 [cc] subscripted value is neither array nor pointer%%%*/
|
|
||||||
outlen = read(dlslot->ldfd,&buf[len],bsz);
|
|
||||||
}
|
|
||||||
len = len + outlen;
|
|
||||||
pos = pos + outlen;
|
|
||||||
bsz = bsz - outlen;
|
|
||||||
}
|
|
||||||
|
|
||||||
total = total + dlslot->a_data_fill;
|
|
||||||
|
|
||||||
if ((bsz > 0) && (pos < total)) {
|
|
||||||
notdone = total - pos;
|
|
||||||
if (notdone <= bsz) {
|
|
||||||
outlen = notdone;
|
|
||||||
} else {
|
|
||||||
outlen = bsz;
|
|
||||||
}
|
|
||||||
/*###778 [cc] subscripted value is neither array nor pointer%%%*/
|
|
||||||
bzero(&buf[len],outlen);
|
|
||||||
len = len + outlen;
|
|
||||||
pos = pos + outlen;
|
|
||||||
bsz = bsz - outlen;
|
|
||||||
}
|
|
||||||
|
|
||||||
total = total + dlslot->a_bss;
|
|
||||||
|
|
||||||
if ((bsz > 0) && (pos < total)) {
|
|
||||||
notdone = total - pos;
|
|
||||||
if (notdone <= bsz) {
|
|
||||||
outlen = notdone;
|
|
||||||
} else {
|
|
||||||
outlen = bsz;
|
|
||||||
}
|
|
||||||
/*###793 [cc] subscripted value is neither array nor pointer%%%*/
|
|
||||||
bzero(&buf[len],outlen);
|
|
||||||
len = len + outlen;
|
|
||||||
pos = pos + outlen;
|
|
||||||
bsz = bsz - outlen;
|
|
||||||
}
|
|
||||||
|
|
||||||
total = total + dlslot->a_bss_fill;
|
|
||||||
|
|
||||||
if ((bsz > 0) && (pos < total)) {
|
|
||||||
notdone = total - pos;
|
|
||||||
if (notdone <= bsz) {
|
|
||||||
outlen = notdone;
|
|
||||||
} else {
|
|
||||||
outlen = bsz;
|
|
||||||
}
|
|
||||||
/*###808 [cc] subscripted value is neither array nor pointer%%%*/
|
|
||||||
bzero(&buf[len],outlen);
|
|
||||||
len = len + outlen;
|
|
||||||
pos = pos + outlen;
|
|
||||||
bsz = bsz - outlen;
|
|
||||||
}
|
|
||||||
|
|
||||||
dlslot->a_lseek = pos;
|
|
||||||
|
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return(len);
|
return(len);
|
||||||
|
|||||||
@@ -42,12 +42,12 @@ u_long mopFileGetLX (/* u_char *, int, int */);
|
|||||||
u_long mopFileGetBX (/* u_char *, int, int */);
|
u_long mopFileGetBX (/* u_char *, int, int */);
|
||||||
void mopFileSwapX (/* u_char *, int, int */);
|
void mopFileSwapX (/* u_char *, int, int */);
|
||||||
int CheckMopFile (/* int */);
|
int CheckMopFile (/* int */);
|
||||||
int GetMopFileInfo (/* int, u_long *, u_long * */);
|
int GetMopFileInfo (/* int, u_long *, u_long *, int *, struct segs * */);
|
||||||
int CheckAOutFile (/* int */);
|
int CheckAOutFile (/* int */);
|
||||||
int GetAOutFileInfo(/* int, u_long *, u_long *, u_long *, u_long *,
|
int GetAOutFileInfo(/* int, u_long *, u_long *, int *, struct segs * */);
|
||||||
u_long *, u_long *, u_long *, u_long * */);
|
int CheckELFFile (/* int */);
|
||||||
int GetFileInfo (/* int, u_long *, u_long *, int *, u_long *, u_long *,
|
int GetELFFileInfo (/* int, u_long *, u_long *, int *, struct segs * */);
|
||||||
u_long *, u_long *, u_long *, u_long * */);
|
int GetFileInfo (/* int, u_long *, u_long *, int *, struct segs * */);
|
||||||
#else
|
#else
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
void mopFilePutLX __P((u_char *, int, u_long, int));
|
void mopFilePutLX __P((u_char *, int, u_long, int));
|
||||||
@@ -56,13 +56,12 @@ u_long mopFileGetLX __P((u_char *, int, int));
|
|||||||
u_long mopFileGetBX __P((u_char *, int, int));
|
u_long mopFileGetBX __P((u_char *, int, int));
|
||||||
void mopFileSwapX __P((u_char *, int, int));
|
void mopFileSwapX __P((u_char *, int, int));
|
||||||
int CheckMopFile __P((int));
|
int CheckMopFile __P((int));
|
||||||
int GetMopFileInfo __P((int, u_long *, u_long *));
|
int GetMopFileInfo __P((int, u_long *, u_long *, int *, struct segs *));
|
||||||
int CheckAOutFile __P((int));
|
int CheckAOutFile __P((int));
|
||||||
int GetAOutFileInfo __P((int, u_long *, u_long *, u_long *, u_long *,
|
int GetAOutFileInfo __P((int, u_long *, u_long *, int *, struct segs *));
|
||||||
u_long *, u_long *, u_long *, u_long *, int *));
|
int CheckELFFile __P((int));
|
||||||
int GetFileInfo __P((int, u_long *, u_long *, int *,
|
int GetELFFileInfo __P((int, u_long *, u_long *, int *, struct segs *));
|
||||||
u_long *, u_long *, u_long *, u_long *,
|
int GetFileInfo __P((int, u_long *, u_long *, int *, struct segs *));
|
||||||
u_long *, u_long *));
|
|
||||||
__END_DECLS
|
__END_DECLS
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
PROGS = mopchk
|
PROGS = mopchk
|
||||||
OBJS = mopchk.o
|
OBJS = mopchk.o
|
||||||
LIBS = ../common/libcommon.a
|
LIBS = ../common/libcommon.a
|
||||||
|
LIBELF = -lelf
|
||||||
|
|
||||||
CPPFLAGS = -I..
|
CPPFLAGS = -I..
|
||||||
|
|
||||||
all: $(PROGS)
|
all: $(PROGS)
|
||||||
|
|
||||||
mopchk: $(OBJS) $(LIBS)
|
mopchk: $(OBJS) $(LIBS)
|
||||||
$(CC) $(CFLAGS) $(LDFLAGS) -o mopchk $(OBJS) $(LIBS)
|
$(CC) $(CFLAGS) $(LDFLAGS) -o mopchk $(OBJS) $(LIBS) $(LIBELF)
|
||||||
|
|
||||||
../common/libcommon.a:
|
../common/libcommon.a:
|
||||||
cd ../common && $(MAKE) libcommon.a
|
cd ../common && $(MAKE) libcommon.a
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ main(argc, argv)
|
|||||||
int op, i, fd;
|
int op, i, fd;
|
||||||
char *filename;
|
char *filename;
|
||||||
struct if_info *ii;
|
struct if_info *ii;
|
||||||
int err, aout;
|
int err;
|
||||||
|
|
||||||
extern int optind, opterr;
|
extern int optind, opterr;
|
||||||
|
|
||||||
@@ -138,25 +138,31 @@ main(argc, argv)
|
|||||||
fd = open(filename, O_RDONLY, 0);
|
fd = open(filename, O_RDONLY, 0);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
printf("Unknown file.\n");
|
printf("Unknown file.\n");
|
||||||
} else {
|
continue;
|
||||||
err = CheckAOutFile(fd);
|
|
||||||
if (err == 0) {
|
|
||||||
if (GetAOutFileInfo(fd, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, &aout) < 0) {
|
|
||||||
printf("Some failure in GetAOutFileInfo\n");
|
|
||||||
aout = -1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
aout = -1;
|
|
||||||
}
|
|
||||||
if (aout == -1)
|
|
||||||
err = CheckMopFile(fd);
|
|
||||||
if (aout == -1 && err == 0) {
|
|
||||||
if (GetMopFileInfo(fd, 0, 0) < 0) {
|
|
||||||
printf("Some failure in GetMopFileInfo\n");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = CheckELFFile(fd);
|
||||||
|
if (err == 0) {
|
||||||
|
if (GetELFFileInfo(fd, 0, 0, 0, 0) < 0) {
|
||||||
|
printf("Some failure in GetELFFileInfo\n");
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = CheckAOutFile(fd);
|
||||||
|
if (err == 0) {
|
||||||
|
if (GetAOutFileInfo(fd, 0, 0, 0, 0) < 0) {
|
||||||
|
printf("Some failure in GetAOutFileInfo\n");
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = CheckMopFile(fd);
|
||||||
|
if (err == 0) {
|
||||||
|
if (GetMopFileInfo(fd, 0, 0, 0, 0) < 0) {
|
||||||
|
printf("Some failure in GetMopFileInfo\n");
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
PROGS = mopd
|
PROGS = mopd
|
||||||
OBJS = mopd.o process.o
|
OBJS = mopd.o process.o
|
||||||
LIBS = ../common/libcommon.a
|
LIBS = ../common/libcommon.a
|
||||||
|
LIBELF = -lelf
|
||||||
|
|
||||||
CPPFLAGS = -I..
|
CPPFLAGS = -I..
|
||||||
|
|
||||||
all: $(PROGS)
|
all: $(PROGS)
|
||||||
|
|
||||||
mopd: $(OBJS) $(LIBS)
|
mopd: $(OBJS) $(LIBS)
|
||||||
$(CC) $(CFLAGS) $(LDFLAGS) -o mopd $(OBJS) $(LIBS)
|
$(CC) $(CFLAGS) $(LDFLAGS) -o mopd $(OBJS) $(LIBS) $(LIBELF)
|
||||||
|
|
||||||
../common/libcommon.a:
|
../common/libcommon.a:
|
||||||
cd ../common && $(MAKE) libcommon.a
|
cd ../common && $(MAKE) libcommon.a
|
||||||
|
|||||||
@@ -266,14 +266,11 @@ mopStartLoad(dst, src, dl_rpr, trans)
|
|||||||
GetFileInfo(dllist[slot].ldfd,
|
GetFileInfo(dllist[slot].ldfd,
|
||||||
&dllist[slot].loadaddr,
|
&dllist[slot].loadaddr,
|
||||||
&dllist[slot].xferaddr,
|
&dllist[slot].xferaddr,
|
||||||
&dllist[slot].aout,
|
&dllist[slot].ftype,
|
||||||
&dllist[slot].a_text, &dllist[slot].a_text_fill,
|
&dllist[slot].seg);
|
||||||
&dllist[slot].a_data, &dllist[slot].a_data_fill,
|
|
||||||
&dllist[slot].a_bss, &dllist[slot].a_bss_fill);
|
|
||||||
|
|
||||||
dllist[slot].nloadaddr = dllist[slot].loadaddr;
|
dllist[slot].nloadaddr = dllist[slot].loadaddr;
|
||||||
dllist[slot].lseek = lseek(dllist[slot].ldfd,0L,SEEK_CUR);
|
dllist[slot].addr = 0;
|
||||||
dllist[slot].a_lseek = 0;
|
|
||||||
|
|
||||||
dllist[slot].count = 0;
|
dllist[slot].count = 0;
|
||||||
if (dllist[slot].dl_bsz >= MAX_ETH_PAYLOAD)
|
if (dllist[slot].dl_bsz >= MAX_ETH_PAYLOAD)
|
||||||
@@ -375,8 +372,6 @@ mopNextLoad(dst, src, new_count, trans)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dllist[slot].lseek = lseek(dllist[slot].ldfd,0L,SEEK_CUR);
|
|
||||||
|
|
||||||
if (dllist[slot].dl_bsz >= MAX_ETH_PAYLOAD)
|
if (dllist[slot].dl_bsz >= MAX_ETH_PAYLOAD)
|
||||||
dllist[slot].dl_bsz = MAX_ETH_PAYLOAD;
|
dllist[slot].dl_bsz = MAX_ETH_PAYLOAD;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user