#include <signal.h>
#include <sys/stat.h>
#include <sys/file.h>
-#include <a.out.h>
-#include <ar.h>
-#include <ranlib.h>
#include <vmf.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include "archive.h"
-#include "krcompat.h"
-#ifdef pdp11
-#include <sys/types.h>
-#define OFF_T off_t
-#define INT int
+#ifdef CROSS
+#include "cross/a.out.h"
+#include "cross/ar.h"
+#include "cross/ranlib.h"
+#include "cross/sys/types.h"
#else
-#include <stdint.h>
-#define OFF_T int32_t
-#define INT int16_t
+#include <a.out.h>
+#include <ar.h>
+#include <ranlib.h>
+#include <sys/types.h>
+#define cross_ar_hdr ar_hdr
+#define cross_exec exec
+#define cross_int_t int
+#define cross_nlist nlist
+#define cross_off_t off_t
+#define cross_ranlib ranlib
+#define cross_xexec xexec
#endif
/*
typedef struct
{
union {
-#ifdef pdp11
+#ifndef CROSS
int *iptr;
#endif
char *cptr;
int bsize; /* MUST be a power of 2 */
int *buff;
} STREAM;
-#ifdef pdp11
+#ifndef CROSS
#define Iptr ptr.iptr
#endif
#define Cptr ptr.cptr
/*
* Header from the a.out and the archive it is from (if any).
*/
- struct xexec filhdr;
+ struct cross_xexec filhdr;
CHDR chdr;
/* symbol management */
char *ofilename = "l.out";
int infil; /* current input file descriptor */
char *filname; /* and its name */
-#if pdp11
- char tfname[14]; /*[] = "/tmp/ldaXXXXX";*/
-#else
- char tfname[15]; /*[] = "/tmp/ldaXXXXXX"; linux requires 6 X's */
-#endif
+ char tfname[15]; /*[] = "/tmp/ldaXXXXXX";*/
FILE *toutb, *doutb, *troutb, *droutb, *soutb, *voutb;
char *rstrtab; /* ranlib string table pointer */
-int main PARAMS((int argc, char **argv));
-int delexit PARAMS((void));
-void endload PARAMS((int argc, char **argv));
-VADDR sym2va PARAMS((int x));
-void load1arg PARAMS((register char *cp, int flag));
-int step PARAMS((OFF_T nloc));
-int ldrand PARAMS((int totnum, OFF_T sloc));
-void mgets PARAMS((register char *buf, int maxlen, int which));
-int load1 PARAMS((int libflg, OFF_T loc));
-void middle PARAMS((void));
-void ldrsym PARAMS((int ix, u_int val, int type));
-void setupout PARAMS((void));
-void load2arg PARAMS((char *acp, int flag));
-void load2 PARAMS((long loc));
-void load2td PARAMS((struct local *lp, u_int creloc, FILE *b1, FILE *b2));
-void finishout PARAMS((void));
-long rnd8k PARAMS((u_int siz));
-void mkfsym PARAMS((char *s));
-void mget PARAMS((register char *loc, int an, int which));
-void dseek PARAMS((int which, OFF_T aloc, int s));
-int get PARAMS((int which));
-int getfile PARAMS((char *acp, int flag, int phase));
-int libopen PARAMS((char *name, int oflags));
-short *lookup PARAMS((void));
-short *slookup PARAMS((char *s));
-int enter PARAMS((short *hp));
-void error PARAMS((int n, char *s));
-void readhdr PARAMS((OFF_T loc));
-void tcreat PARAMS((FILE **fpp, int tempflg));
-int adrof PARAMS((char *s));
-void copy PARAMS((register FILE *fp));
-short *lookloc PARAMS((struct local *alp, int r));
-void roundov PARAMS((void));
-u_int add PARAMS((int a, int b, char *s));
-int get_arobj PARAMS((int fd));
-OFF_T skip PARAMS((void));
-void inistr PARAMS((int which));
-
-static void hreset PARAMS((void));
+#ifndef __P
+#ifdef __STDC__
+#define __P(params) params
+#else
+#define __P(params) ()
+#endif
+#endif
+
+int main __P((int argc, char **argv));
+int delexit __P((void));
+void endload __P((int argc, char **argv));
+VADDR sym2va __P((int x));
+void load1arg __P((register char *cp, int flag));
+int step __P((cross_off_t nloc));
+int ldrand __P((int totnum, cross_off_t sloc));
+void mgets __P((register char *buf, int maxlen, int which));
+int load1 __P((int libflg, cross_off_t loc));
+static void hreset __P((void));
+void middle __P((void));
+void ldrsym __P((int ix, u_int val, int type));
+void setupout __P((void));
+void load2arg __P((char *acp, int flag));
+void load2 __P((long loc));
+void load2td __P((struct local *lp, u_int creloc, FILE *b1, FILE *b2));
+void finishout __P((void));
+long rnd8k __P((u_int siz));
+void mkfsym __P((char *s));
+void mget __P((register char *loc, int an, int which));
+void dseek __P((int which, cross_off_t aloc, int s));
+int get __P((int which));
+int getfile __P((char *acp, int flag, int phase));
+int libopen __P((char *name, int oflags));
+short *lookup __P((void));
+short *slookup __P((char *s));
+int enter __P((short *hp));
+void error __P((int n, char *s));
+void readhdr __P((cross_off_t loc));
+void tcreat __P((FILE **fpp, int tempflg));
+int adrof __P((char *s));
+void copy __P((register FILE *fp));
+short *lookloc __P((struct local *alp, int r));
+void roundov __P((void));
+u_int add __P((int a, int b, char *s));
+int get_arobj __P((int fd));
+cross_off_t skip __P((void));
+void inistr __P((int which));
int main(argc, argv) int argc; char **argv; {
register int c, i;
case 'D':
for (dnum = atoi(*p);dorigin < dnum; dorigin += 2) {
-#ifdef pdp11
- putw(0, doutb);
-#else
+#ifdef CROSS
putc(0, doutb);
putc(0, doutb);
+#else
+ putw(0, doutb);
#endif
if (rflag) {
-#ifdef pdp11
- putw(0, droutb);
-#else
+#ifdef CROSS
putc(0, droutb);
putc(0, droutb);
+#else
+ putw(0, droutb);
#endif
}
}
* Scan file to find defined symbols.
*/
void load1arg(cp, flag) register char *cp; int flag; {
- OFF_T nloc;
+ cross_off_t nloc;
int kind, tnum;
- OFF_T ltnum, strsize;
-#ifndef pdp11
- char temp[sizeof (OFF_T)];
-#endif
+ cross_off_t ltnum, strsize;
kind = getfile(cp, flag, 1);
if (Mflag)
* when there is a table of contents!)
*/
case 2:
- nloc = SARMAG + sizeof (struct ar_hdr) + chdr.lname;
+ nloc = SARMAG + sizeof (struct cross_ar_hdr) + chdr.lname;
lseek(infil, (off_t)nloc, L_SET);
/*
* Read the size of the ranlib structures (a long).
*/
-#ifdef pdp11
- read(infil, <num, sizeof (OFF_T));
-#else
- read(infil, temp, sizeof (OFF_T));
- ltnum = ((temp[0] & 0xffL) << 16) | ((temp[1] & 0xffL) << 24) |
- (temp[2] & 0xffL) | ((temp[3] & 0xffL) << 8);
+ read(infil, <num, sizeof (cross_off_t));
+#ifdef CROSS
+ ltnum = cross_read_off_t((char *)<num);
#endif
/*fprintf(stderr, "ltnum=%08lx\n", ltnum);*/
/*
*/
nloc += (sizeof (ltnum) + ltnum);
/*fprintf(stderr, "nloc=%08lx\n", nloc);*/
- tnum = ltnum / sizeof (struct ranlib);
+ tnum = ltnum / sizeof (struct cross_ranlib);
rstrtab = NULL;
lseek(infil, (off_t)nloc, L_SET);
-#ifdef pdp11
- read(infil, &strsize, sizeof (OFF_T));
-#else
- read(infil, temp, sizeof (OFF_T));
- strsize = ((temp[0] & 0xffL) << 16) | ((temp[1] & 0xffL) << 24) |
- (temp[2] & 0xffL) | ((temp[3] & 0xffL) << 8);
+ read(infil, &strsize, sizeof (cross_off_t));
+#ifdef CROSS
+ strsize = cross_read_off_t((char *)&strsize);
#endif
/*fprintf(stderr, "strsize=%08lx\n", strsize);*/
if (strsize <= 8192L)
* is useful, record its location in the liblist structure
* for use in pass2. Mark the end of the archive in libilst with a -1.
*/
-int step(nloc) OFF_T nloc; {
+int step(nloc) cross_off_t nloc; {
lseek(infil, (off_t)nloc, L_SET);
if (get_arobj(infil) <= 0)
{
libp++;
return (0);
}
- if (load1(1, nloc + sizeof (struct ar_hdr) + chdr.lname))
+ if (load1(1, nloc + sizeof (struct cross_ar_hdr) + chdr.lname))
{
libp->loc = nloc;
libp++;
return (1);
}
-int ldrand(totnum, sloc) int totnum; OFF_T sloc; {
+int ldrand(totnum, sloc) int totnum; cross_off_t sloc; {
register int ntab;
SYMBOL *sp;
short *hp;
VADDR vsym;
LIBLIST *oldp = libp;
int amt, tnum = totnum;
- OFF_T loc;
+ cross_off_t loc;
/*fprintf(stderr, "totnum=%d sloc=%08lx\n", tnum, sloc);*/
/*
* 'ar' header + member header + SYMDEF table.of.contents + long filename
*/
- OFF_T opos = (OFF_T)SARMAG + sizeof (struct ar_hdr) + sizeof (OFF_T) +
+ cross_off_t opos = (cross_off_t)SARMAG + sizeof (struct cross_ar_hdr) + sizeof (cross_off_t) +
chdr.lname;
#define TABSZ 64
char localname[NNAMESIZE];
- register struct ranlib *tp;
- struct ranlib tab[TABSZ], *tplast;
-#ifndef pdp11
- char buf[TABSZ * sizeof (struct ranlib)], *temp;
-#endif
+ register struct cross_ranlib *tp;
+ struct cross_ranlib tab[TABSZ], *tplast;
while (tnum)
{
/*fprintf(stderr, "ntab=%d opos=%08lx\n", ntab, opos);*/
tplast = &tab[ntab - 1];
(void)lseek(infil, (off_t)opos, L_SET);
- amt = ntab * sizeof (struct ranlib);
-#ifdef pdp11
+ amt = ntab * sizeof (struct cross_ranlib);
if (read(infil, tab, amt) != amt)
error(1, "EOF in ldrand");
-#else
- if (read(infil, buf, amt) != amt)
- error(1, "EOF in ldrand");
- temp = buf;
- for (tp = tab; tp <= tplast; tp++)
- {
- tp->ran_un.ran_strx = ((temp[0] & 0xffL) << 16) | ((temp[1] & 0xffL) << 24) |
- (temp[2] & 0xffL) | ((temp[3] & 0xffL) << 8);
- tp->ran_off = ((temp[4] & 0xffL) << 16) | ((temp[5] & 0xffL) << 24) |
- (temp[6] & 0xffL) | ((temp[7] & 0xffL) << 8);
- temp += sizeof (struct ranlib);
- }
-#endif
tnum -= ntab;
opos += amt;
for (tp = tab; tp <= tplast; tp++)
{
+#ifdef CROSS
+ tp->ran_un.ran_strx = cross_read_off_t((char *)&tp->ran_un.ran_strx);
+ tp->ran_off = cross_read_off_t((char *)&tp->ran_off);
+#endif
/*
* This is slower and uglier than we would like, but it is not always
* possible to hold the entire string table in memory. Need to add
* an extra increment to skip over the string table size longword.
*/
- /*fprintf(stderr, "ran_strx=%ld\n", tp->ran_un.ran_strx);*/
+ /*fprintf(stderr, "ran_strx=%ld ran_off=%ld\n", tp->ran_un.ran_strx, tp->ran_off);*/
if (rstrtab)
strncpy(localname, (int)tp->ran_un.ran_strx +
rstrtab, NNAMESIZE);
else
{
dseek(STRINGS2, tp->ran_un.ran_strx + sloc +
- sizeof (OFF_T), 07777);
+ sizeof (cross_off_t), 07777);
mgets(localname, NNAMESIZE, STRINGS2);
}
/*fprintf(stderr, "localname=%s\n", localname);*/
{
if (--sp->nibuf < 0)
{
- dseek(which, (OFF_T)(sp->bno + 1) * sp->bsize, 077777);
+ dseek(which, (cross_off_t)(sp->bno + 1) * sp->bsize, 077777);
sp->nibuf--;
}
if ((*buf++ = *sp->Cptr++) == 0)
/*
* Examine a single file or archive member on pass 1.
*/
-int load1(libflg, loc) int libflg; OFF_T loc; {
+int load1(libflg, loc) int libflg; cross_off_t loc; {
register SYMBOL *sp;
int savindex;
int ndef, type, mtype;
long nlocal;
VADDR vsym;
-#ifndef pdp11
- /* note: must be at least as large as OFF_T */
- char temp[sizeof (struct nlist)];
-#endif
- struct nlist objsym;
- OFF_T strloc;
- OFF_T strsize;
+ struct cross_nlist objsym;
+ cross_off_t strloc;
+ cross_off_t strsize;
char *strtab;
register struct vseg *seg;
strloc = loc + N_STROFF(filhdr);
lseek(infil, (off_t)strloc, L_SET);
-#ifdef pdp11
- read(infil, &strsize, sizeof (OFF_T));
-#else
- read(infil, temp, sizeof (OFF_T));
- strsize = ((temp[0] & 0xffL) << 16) | ((temp[1] & 0xffL) << 24) |
- (temp[2] & 0xffL) | ((temp[3] & 0xffL) << 8);
+ read(infil, &strsize, sizeof (cross_off_t));
+#ifdef CROSS
+ strsize = cross_read_off_t((char *)&strsize);
#endif
strtab = NULL;
if (strsize <= 8192L)
inistr(STRINGS);
while (Input[SYMBOLS].nsize > 0) {
-#ifdef pdp11
mget((char *)&objsym, sizeof objsym, SYMBOLS);
-#else
- mget(temp, sizeof objsym, SYMBOLS);
- objsym.n_un.n_strx = ((temp[0] & 0xffL) << 16) | ((temp[1] & 0xffL) << 24) |
- (temp[2] & 0xffL) | ((temp[3] & 0xffL) << 8);
- objsym.n_type = temp[4] & 0xff;
- objsym.n_ovly = temp[5] & 0xff;
- objsym.n_value = (temp[6] & 0xff) | ((temp[7] & 0xff) << 8);
+#ifdef CROSS
+ objsym.n_un.n_strx = cross_read_off_t((char *)&objsym.n_un.n_strx);
+ objsym.n_value = cross_read_uint((char *)&objsym.n_value);
#endif
type = objsym.n_type;
if (Sflag) {
* to place the strings in the same order as the symbols - so effectively
* we are doing a sequential read of the string table.
*/
- /*fprintf(stderr, "n_strx=%ld\n", objsym.n_un.n_strx);*/
+ /*fprintf(stderr, "n_strx=%ld n_type=%d n_ovly=%d n_value=%ld\n", objsym.n_un.n_strx, objsym.n_type, objsym.n_ovly, objsym.n_value);*/
if (strtab)
strncpy(cursym.n_name, (int)objsym.n_un.n_strx +
- strtab - sizeof (OFF_T), NNAMESIZE);
+ strtab - sizeof (cross_off_t), NNAMESIZE);
else
{
dseek(STRINGS, objsym.n_un.n_strx + strloc, 077777);
void setupout() {
VADDR vsym;
register SYMBOL *sp;
-#ifndef pdp11
- /* note: must be at least as large as struct exec */
- char temp[sizeof (struct ovlhdr)];
+#ifdef CROSS
+ struct cross_xexec temp_filhdr;
int i;
#endif
filhdr.e.a_text = tsize;
filhdr.e.a_data = dsize;
filhdr.e.a_bss = bsize;
- ssize = sflag? 0 : (ssize + (sizeof (struct nlist)) * symindex);
+ ssize = sflag? 0 : (ssize + (sizeof (struct cross_nlist)) * symindex);
/*
* This is an estimate, the real size is computed later and the
* a.out header rewritten with the correct value.
} else
filhdr.e.a_entry = 0;
filhdr.e.a_flag = (rflag==0);
-#ifdef pdp11
- fwrite(&filhdr.e, sizeof (filhdr.e), 1, toutb);
+#ifdef CROSS
+ cross_write_int((char *)&temp_filhdr.e.a_magic, filhdr.e.a_magic);
+ cross_write_uint((char *)&temp_filhdr.e.a_text, filhdr.e.a_text);
+ cross_write_uint((char *)&temp_filhdr.e.a_data, filhdr.e.a_data);
+ cross_write_uint((char *)&temp_filhdr.e.a_bss, filhdr.e.a_bss);
+ cross_write_uint((char *)&temp_filhdr.e.a_syms, filhdr.e.a_syms);
+ cross_write_uint((char *)&temp_filhdr.e.a_entry, filhdr.e.a_entry);
+ cross_write_uint((char *)&temp_filhdr.e.a_unused, filhdr.e.a_unused);
+ cross_write_uint((char *)&temp_filhdr.e.a_flag, filhdr.e.a_flag);
+ fwrite(&temp_filhdr.e, sizeof (filhdr.e), 1, toutb);
#else
- temp[0] = filhdr.e.a_magic & 0xff;
- temp[1] = (filhdr.e.a_magic >> 8) & 0xff;
- temp[2] = filhdr.e.a_text & 0xff;
- temp[3] = (filhdr.e.a_text >> 8) & 0xff;
- temp[4] = filhdr.e.a_data & 0xff;
- temp[5] = (filhdr.e.a_data >> 8) & 0xff;
- temp[6] = filhdr.e.a_bss & 0xff;
- temp[7] = (filhdr.e.a_bss >> 8) & 0xff;
- temp[8] = filhdr.e.a_syms & 0xff;
- temp[9] = (filhdr.e.a_syms >> 8) & 0xff;
- temp[10] = filhdr.e.a_entry & 0xff;
- temp[11] = (filhdr.e.a_entry >> 8) & 0xff;
- temp[12] = filhdr.e.a_unused & 0xff;
- temp[13] = (filhdr.e.a_unused >> 8) & 0xff;
- temp[14] = filhdr.e.a_flag & 0xff;
- temp[15] = (filhdr.e.a_flag >> 8) & 0xff;
- fwrite(temp, sizeof (filhdr.e), 1, toutb);
+ fwrite(&filhdr.e, sizeof (filhdr.e), 1, toutb);
#endif
if (numov) {
-#ifdef pdp11
- fwrite(&filhdr.o, sizeof (filhdr.o), 1, toutb);
+#ifdef CROSS
+ cross_write_int((char *)&temp_filhdr.o.max_ovl, filhdr.o.max_ovl);
+ for (i = 0; i < NOVL; ++i)
+ cross_write_uint((char *)(temp_filhdr.o.ov_siz + i), filhdr.o.ov_siz[i]);
+ fwrite(&temp_filhdr.o, sizeof (filhdr.o), 1, toutb);
#else
- temp[0] = filhdr.o.max_ovl & 0xff;
- temp[1] = (filhdr.o.max_ovl >> 8) & 0xff;
- for (i = 0; i < NOVL; ++i) {
- temp[i * 2 + 2] = filhdr.o.ov_siz[i] & 0xff;
- temp[i * 2 + 3] = (filhdr.o.ov_siz[i] >> 8) & 0xff;
- }
- fwrite(temp, sizeof (filhdr.o), 1, toutb);
+ fwrite(&filhdr.o, sizeof (filhdr.o), 1, toutb);
#endif
}
}
lseek(infil, (off_t)lp->loc, L_SET);
get_arobj(infil);
mkfsym(chdr.name);
- load2(lp->loc + sizeof (struct ar_hdr) +
+ load2(lp->loc + sizeof (struct cross_ar_hdr) +
chdr.lname);
}
libp = ++lp;
int type, mtype;
VADDR vsym;
short i;
- struct nlist objsym;
- OFF_T stroff;
+ struct cross_nlist objsym;
+ cross_off_t stroff;
char *strtab;
- OFF_T strsize;
-#ifndef pdp11
- /* note: must be at least as large as OFF_T */
- char temp[sizeof (struct nlist)];
-#endif
+ cross_off_t strsize;
readhdr(loc);
ctrel = torigin;
stroff = loc + N_STROFF(filhdr);
lseek(infil, (off_t)stroff, L_SET);
-#ifdef pdp11
- read(infil, &strsize, sizeof (OFF_T));
-#else
- read(infil, temp, sizeof (OFF_T));
- strsize = ((temp[0] & 0xffL) << 16) | ((temp[1] & 0xffL) << 24) |
- (temp[2] & 0xffL) | ((temp[3] & 0xffL) << 8);
+ read(infil, &strsize, sizeof (cross_off_t));
+#ifdef CROSS
+ strsize = cross_read_off_t((char *)&strsize);
#endif
strtab = NULL;
if (strsize <= 8192L)
while (Input[SYMBOLS].nsize > 0) {
symno++;
-#ifdef pdp11
mget((char *)&objsym, sizeof objsym, SYMBOLS);
-#else
- mget(temp, sizeof objsym, SYMBOLS);
- objsym.n_un.n_strx = ((temp[0] & 0xffL) << 16) | ((temp[1] & 0xffL) << 24) |
- (temp[2] & 0xffL) | ((temp[3] & 0xffL) << 8);
- objsym.n_type = temp[4] & 0xff;
- objsym.n_ovly = temp[5] & 0xff;
- objsym.n_value = (temp[6] & 0xff) | ((temp[7] & 0xff) << 8);
+#ifdef CROSS
+ objsym.n_un.n_strx = cross_read_off_t((char *)&objsym.n_un.n_strx);
+ objsym.n_value = cross_read_uint((char *)&objsym.n_value);
#endif
+ /*fprintf(stderr, "n_strx=%ld n_type=%d n_ovly=%d n_value=%ld\n", objsym.n_un.n_strx, objsym.n_type, objsym.n_ovly, objsym.n_value);*/
if (strtab)
strncpy(cursym.n_name, (int)objsym.n_un.n_strx +
- strtab - sizeof (OFF_T), NNAMESIZE);
+ strtab - sizeof (cross_off_t), NNAMESIZE);
else
{
dseek(STRINGS, objsym.n_un.n_strx + stroff, 07777);
mgets(cursym.n_name, NNAMESIZE, STRINGS);
}
+ /*fprintf(stderr, "n_name=%s\n", cursym.n_name);*/
cursym.n_type = objsym.n_type;
cursym.n_value = objsym.n_value;
cursym.n_ovly = objsym.n_ovly;
Input[TEXT].nsize++;
t = get(TEXT);
} else {
-#ifdef pdp11
- t = *Input[TEXT].Iptr++;
-#else
+#ifdef CROSS
t = *Input[TEXT].Cptr++ & 0xff;
- t |= (*Input[TEXT].Cptr++ & 0xff) << 8;
+ t |= (*Input[TEXT].Cptr++ & 0xff) << 8;
+#else
+ t = *Input[TEXT].Iptr++;
#endif
}
Input[RELOC].nsize++;
r = get(RELOC);
} else {
-#ifdef pdp11
- r = *Input[RELOC].Iptr++;
-#else
+#ifdef CROSS
r = *Input[RELOC].Cptr++ & 0xff;
- r |= (*Input[RELOC].Cptr++ & 0xff) << 8;
+ r |= (*Input[RELOC].Cptr++ & 0xff) << 8;
+#else
+ r = *Input[RELOC].Iptr++;
#endif
}
#if 0
}
if (r&01)
t -= creloc;
-#ifdef pdp11
- putw(t, b1);
-#else
+#ifdef CROSS
putc(t & 0xff, b1);
putc((t >> 8) & 0xff, b1);
+#else
+ putw(t, b1);
#endif
if (rflag) {
-#ifdef pdp11
- putw(r, b2);
-#else
+#ifdef CROSS
putc(r & 0xff, b2);
putc((r >> 8) & 0xff, b2);
+#else
+ putw(r, b2);
#endif
}
}
void finishout() {
register u_int n;
register SYMBOL *sp;
- struct nlist objsym;
+ struct cross_nlist objsym;
VADDR vsym;
int type, len;
- OFF_T stroff;
+ cross_off_t stroff;
long dtotal, ovrnd;
- INT thunk[THUNKSIZ / sizeof (INT)];
-#ifndef pdp11
- /* note: must be at least as large as struct nlist, THUNKSIZ, OFF_T */
- char temp[sizeof (struct exec)];
+ cross_int_t thunk[THUNKSIZ / sizeof (cross_int_t)];
+#ifdef CROSS
+ cross_off_t temp_stroff;
+ struct cross_xexec temp_filhdr;
#endif
if (numov) {
thunk[1] = sp->sovalue + 4;
thunk[2] = 04537; /* jsr r5, ovhndlrx */
thunk[3] = aovhndlr[sp->n_ovly];
-#ifdef pdp11
- fwrite(thunk, THUNKSIZ, 1, toutb);
-#else
- temp[0] = thunk[0] & 0xff;
- temp[1] = (thunk[0] >> 8) & 0xff;
- temp[2] = thunk[1] & 0xff;
- temp[3] = (thunk[1] >> 8) & 0xff;
- temp[4] = thunk[2] & 0xff;
- temp[5] = (thunk[2] >> 8) & 0xff;
- temp[6] = thunk[3] & 0xff;
- temp[7] = (thunk[3] >> 8) & 0xff;
- fwrite(temp, THUNKSIZ, 1, toutb);
+#ifdef CROSS
+ cross_write_int((char *)thunk, thunk[0]);
+ cross_write_int((char *)(thunk + 1), thunk[1]);
+ cross_write_int((char *)(thunk + 2), thunk[2]);
+ cross_write_int((char *)(thunk + 3), thunk[3]);
#endif
+ fwrite(thunk, THUNKSIZ, 1, toutb);
torigin += THUNKSIZ;
}
}
n = torigin;
while (n&077) {
n += 2;
-#ifdef pdp11
- putw(0, toutb);
-#else
+#ifdef CROSS
putc(0, toutb);
putc(0, toutb);
+#else
+ putw(0, toutb);
#endif
if (rflag) {
-#ifdef pdp11
- putw(0, troutb);
-#else
+#ifdef CROSS
putc(0, troutb);
putc(0, troutb);
+#else
+ putw(0, troutb);
#endif
}
}
tcreat(&doutb, 1);
nsym = 0;
- stroff = sizeof (OFF_T); /* string table size */
+ stroff = sizeof (cross_off_t); /* string table size */
if (xflag == 0)
{
fflush(soutb); /* flush local symbol file */
fwrite(cursym.n_name, 1, len, doutb);
fputc('\0', doutb);
stroff += (len + 1);
-#ifdef pdp11
- fwrite(&objsym, sizeof (objsym), 1, toutb);
-#else
- temp[0] = (objsym.n_un.n_strx >> 16) & 0xff;
- temp[1] = (objsym.n_un.n_strx >> 24) & 0xff;
- temp[2] = objsym.n_un.n_strx & 0xff;
- temp[3] = (objsym.n_un.n_strx >> 8) & 0xff;
- temp[4] = objsym.n_type & 0xff;
- temp[5] = objsym.n_ovly & 0xff;
- temp[6] = objsym.n_value & 0xff;
- temp[7] = (objsym.n_value >> 8) & 0xff;
- fwrite(temp, sizeof (objsym), 1, toutb);
+#ifdef CROSS
+ cross_write_off_t((char *)&objsym.n_un.n_strx, objsym.n_un.n_strx);
+ cross_write_uint((char *)&objsym.n_value, objsym.n_value);
#endif
+ fwrite(&objsym, sizeof (objsym), 1, toutb);
nsym++;
}
fclose(soutb);
fwrite(sp->n_name, 1, len, doutb);
fputc('\0', doutb);
stroff += (len + 1);
-#ifdef pdp11
- fwrite(&objsym, sizeof (objsym), 1, toutb);
-#else
- temp[0] = (objsym.n_un.n_strx >> 16) & 0xff;
- temp[1] = (objsym.n_un.n_strx >> 24) & 0xff;
- temp[2] = objsym.n_un.n_strx & 0xff;
- temp[3] = (objsym.n_un.n_strx >> 8) & 0xff;
- temp[4] = objsym.n_type & 0xff;
- temp[5] = objsym.n_ovly & 0xff;
- temp[6] = objsym.n_value & 0xff;
- temp[7] = (objsym.n_value >> 8) & 0xff;
- fwrite(temp, sizeof (objsym), 1, toutb);
+#ifdef CROSS
+ cross_write_off_t((char *)&objsym.n_un.n_strx, objsym.n_un.n_strx);
+ cross_write_uint((char *)&objsym.n_value, objsym.n_value);
#endif
+ fwrite(&objsym, sizeof (objsym), 1, toutb);
nsym++;
}
#ifdef whybother
* Now write the length of the string table out. Then copy the temp
* file containing the strings to the image being built.
*/
-#ifdef pdp11
- fwrite(&stroff, sizeof (OFF_T), 1, toutb);
+#ifdef CROSS
+ cross_write_off_t((char *)&temp_stroff, stroff);
+ fwrite(&temp_stroff, sizeof (cross_off_t), 1, toutb);
#else
- temp[0] = (stroff >> 16) & 0xff;
- temp[1] = (stroff >> 24) & 0xff;
- temp[2] = stroff & 0xff;
- temp[3] = (stroff >> 8) & 0xff;
- fwrite(temp, sizeof (OFF_T), 1, toutb);
+ fwrite(&stroff, sizeof (cross_off_t), 1, toutb);
#endif
copy(doutb);
}
*/
fflush(toutb);
rewind(toutb);
-#ifdef pdp11
fread(&filhdr.e, sizeof (filhdr.e), 1, toutb);
-#else
- fread(temp, sizeof (filhdr.e), 1, toutb);
- /*filhdr.e.a_magic = (temp[0] & 0xff) | ((temp[1] & 0xff) << 8);
- filhdr.e.a_text = (temp[2] & 0xff) | ((temp[3] & 0xff) << 8);
- filhdr.e.a_data = (temp[4] & 0xff) | ((temp[5] & 0xff) << 8);
- filhdr.e.a_bss = (temp[6] & 0xff) | ((temp[7] & 0xff) << 8);
- filhdr.e.a_syms = (temp[8] & 0xff) | ((temp[9] & 0xff) << 8);
- filhdr.e.a_entry = (temp[10] & 0xff) | ((temp[11] & 0xff) << 8);
- filhdr.e.a_unused = (temp[12] & 0xff) | ((temp[13] & 0xff) << 8);
- filhdr.e.a_flag = (temp[14] & 0xff) | ((temp[15] & 0xff) << 8);*/
+#ifdef CROSS
+ filhdr.e.a_magic = cross_read_int((char *)&filhdr.e.a_magic);
+ filhdr.e.a_text = cross_read_uint((char *)&filhdr.e.a_text);
+ filhdr.e.a_data = cross_read_uint((char *)&filhdr.e.a_data);
+ filhdr.e.a_bss = cross_read_uint((char *)&filhdr.e.a_bss);
+ /*filhdr.e.a_syms = cross_read_uint((char *)&filhdr.e.a_syms);*/
+ filhdr.e.a_entry = cross_read_uint((char *)&filhdr.e.a_entry);
+ filhdr.e.a_unused = cross_read_uint((char *)&filhdr.e.a_unused);
+ filhdr.e.a_flag = cross_read_uint((char *)&filhdr.e.a_flag);
#endif
filhdr.e.a_syms = nsym * sizeof (objsym);
rewind(toutb);
-#ifdef pdp11
- fwrite(&filhdr.e, sizeof (filhdr.e), 1, toutb);
+#ifdef CROSS
+ cross_write_int((char *)&temp_filhdr.e.a_magic, filhdr.e.a_magic);
+ cross_write_uint((char *)&temp_filhdr.e.a_text, filhdr.e.a_text);
+ cross_write_uint((char *)&temp_filhdr.e.a_data, filhdr.e.a_data);
+ cross_write_uint((char *)&temp_filhdr.e.a_bss, filhdr.e.a_bss);
+ cross_write_uint((char *)&temp_filhdr.e.a_syms, filhdr.e.a_syms);
+ cross_write_uint((char *)&temp_filhdr.e.a_entry, filhdr.e.a_entry);
+ cross_write_uint((char *)&temp_filhdr.e.a_unused, filhdr.e.a_unused);
+ cross_write_uint((char *)&temp_filhdr.e.a_flag, filhdr.e.a_flag);
+ fwrite(&temp_filhdr.e, sizeof (filhdr.e), 1, toutb);
#else
- /*temp[0] = filhdr.e.a_magic & 0xff;
- temp[1] = (filhdr.e.a_magic >> 8) & 0xff;
- temp[2] = filhdr.e.a_text & 0xff;
- temp[3] = (filhdr.e.a_text >> 8) & 0xff;
- temp[4] = filhdr.e.a_data & 0xff;
- temp[5] = (filhdr.e.a_data >> 8) & 0xff;
- temp[6] = filhdr.e.a_bss & 0xff;
- temp[7] = (filhdr.e.a_bss >> 8) & 0xff;*/
- temp[8] = filhdr.e.a_syms & 0xff;
- temp[9] = (filhdr.e.a_syms >> 8) & 0xff;
- /*temp[10] = filhdr.e.a_entry & 0xff;
- temp[11] = (filhdr.e.a_entry >> 8) & 0xff;
- temp[12] = filhdr.e.a_unused & 0xff;
- temp[13] = (filhdr.e.a_unused >> 8) & 0xff;
- temp[14] = filhdr.e.a_flag & 0xff;
- temp[15] = (filhdr.e.a_flag >> 8) & 0xff;*/
- fwrite(temp, sizeof (filhdr.e), 1, toutb);
+ fwrite(&filhdr.e, sizeof (filhdr.e), 1, toutb);
#endif
fclose(toutb);
tp->Cptr += tp->nibuf * 2;
loc += tp->nibuf * 2;
n -= tp->nibuf;
- dseek(which, (OFF_T)(tp->bno + 1) * tp->bsize, -1);
+ dseek(which, (cross_off_t)(tp->bno + 1) * tp->bsize, -1);
}
bcopy(tp->Cptr, loc, n * 2);
tp->Cptr += n * 2;
#endif
}
-void dseek(which, aloc, s) int which; OFF_T aloc; int s; {
+void dseek(which, aloc, s) int which; cross_off_t aloc; int s; {
register STREAM *sp = &Input[which];
register u_int b, o;
int n;
o = aloc & (sp->bsize - 1);
if (sp->bno != b)
{
- (void)lseek(infil, (OFF_T)sp->bsize * b, L_SET);
+ (void)lseek(infil, (cross_off_t)sp->bsize * b, L_SET);
if ((n = read(infil, (char *)sp->buff, sp->bsize)) < 0)
n = 0;
sp->bno = b;
int get(which) int which; {
register STREAM *sp = &Input[which];
-#ifndef pdp11
+#ifdef CROSS
register int temp;
#endif
if (--sp->nibuf < 0) {
- dseek(which, (OFF_T)(sp->bno + 1) * sp->bsize, -1);
+ dseek(which, (cross_off_t)(sp->bno + 1) * sp->bsize, -1);
--sp->nibuf;
}
if (--sp->nsize <= 0) {
if (sp->nsize < 0)
error(1, "premature EOF#1");
}
-#ifdef pdp11
- return(*sp->Iptr++);
-#else
+#ifdef CROSS
temp = *sp->Cptr++ & 0xff;
- return temp | ((*sp->Cptr++ & 0xff) << 8);
+ return temp | ((*sp->Cptr++ & 0xff) << 8);
+#else
+ return(*sp->Iptr++);
#endif
}
Input[RELOC].bno = -1;
Input[SYMBOLS].bno = -1;
Input[STRINGS].bno = -1;
- dseek(TEXT, (OFF_T)0L, SARMAG);
+ dseek(TEXT, (cross_off_t)0L, SARMAG);
if (Input[TEXT].nsize <= 0)
error(1, "premature EOF#2");
mget(arcmag, SARMAG, TEXT);
arcmag[SARMAG] = 0;
if (strcmp(arcmag, ARMAG))
return(0);
- lseek(infil, (OFF_T)SARMAG, L_SET);
+ lseek(infil, (cross_off_t)SARMAG, L_SET);
if (get_arobj(infil) <= 0)
return(1);
if (strcmp(chdr.name, RANLIBMAG))
errlev = 2;
}
-void readhdr(loc) OFF_T loc; {
+void readhdr(loc) cross_off_t loc; {
/*fprintf(stderr, "loc=%08lx\n", loc);*/
-#ifndef pdp11
- char temp[sizeof (struct exec)];
-#endif
-
dseek(TEXT, loc, sizeof filhdr);
-#ifdef pdp11
mget((char *)&filhdr.e, sizeof filhdr.e, TEXT);
-#else
- mget(temp, sizeof filhdr.e, TEXT);
- filhdr.e.a_magic = (temp[0] & 0xff) | ((temp[1] & 0xff) << 8);
- filhdr.e.a_text = (temp[2] & 0xff) | ((temp[3] & 0xff) << 8);
- filhdr.e.a_data = (temp[4] & 0xff) | ((temp[5] & 0xff) << 8);
- filhdr.e.a_bss = (temp[6] & 0xff) | ((temp[7] & 0xff) << 8);
- filhdr.e.a_syms = (temp[8] & 0xff) | ((temp[9] & 0xff) << 8);
- filhdr.e.a_entry = (temp[10] & 0xff) | ((temp[11] & 0xff) << 8);
- filhdr.e.a_unused = (temp[12] & 0xff) | ((temp[13] & 0xff) << 8);
- filhdr.e.a_flag = (temp[14] & 0xff) | ((temp[15] & 0xff) << 8);
+#ifdef CROSS
+ filhdr.e.a_magic = cross_read_int((char *)&filhdr.e.a_magic);
+ filhdr.e.a_text = cross_read_uint((char *)&filhdr.e.a_text);
+ filhdr.e.a_data = cross_read_uint((char *)&filhdr.e.a_data);
+ filhdr.e.a_bss = cross_read_uint((char *)&filhdr.e.a_bss);
+ filhdr.e.a_syms = cross_read_uint((char *)&filhdr.e.a_syms);
+ filhdr.e.a_entry = cross_read_uint((char *)&filhdr.e.a_entry);
+ filhdr.e.a_unused = cross_read_uint((char *)&filhdr.e.a_unused);
+ filhdr.e.a_flag = cross_read_uint((char *)&filhdr.e.a_flag);
#endif
if (filhdr.e.a_magic != A_MAGIC1)
error(1, "bad magic number");
#if 1
if (tempflg) {
- /* note: we have to refresh the template each time, because
- * linux actually checks that it ends with 6 X's, and worse,
- * leaves it in an undefined state if something goes wrong
- */
-#if pdp11
- strcpy(tfname, "/tmp/ldaXXXXX");
-#else
- strcpy(tfname, "/tmp/ldaXXXXXX"); /* linux requires 6 X's */
-#endif
+ strcpy(tfname, "/tmp/ldaXXXXXX");
if ((ufd = mkstemp(tfname)) < 0)
error(2, "cannot create temp");
unlink(tfname);
void roundov() {
while (torigin & 077)
{
-#ifdef pdp11
- putw(0, voutb);
-#else
+#ifdef CROSS
putc(0, voutb);
putc(0, voutb);
+#else
+ putw(0, voutb);
#endif
torigin += 2;
}
* and the rest of 'ld' figures out what to do.
*/
-typedef struct ar_hdr HDR;
+typedef struct cross_ar_hdr HDR;
static char hb[sizeof(HDR) + 1]; /* real header */
/* Convert ar header field to an integer. */
/*
* skip - where to seek for next archive member.
*/
-OFF_T skip() {
- OFF_T len;
+cross_off_t skip() {
+ cross_off_t len;
len = chdr.size + (chdr.size + chdr.lname & 1);
len += sizeof (HDR);
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)CTIME.c 1.1 (Berkeley) 3/25/87";
+static char sccsid[] = "@(#)cross_ctime.c 1.1 (Berkeley) 3/25/87";
#endif
#include <fcntl.h>
#include "cross/sys/types.h"
#include "cross/time.h"
#include "cross/tzfile.h"
-#define _MAXPATHLEN CROSS_MAXPATHLEN
-#define ASCTIME cross_asctime
-#define CTIME cross_ctime
-#define GMTIME cross_gmtime
-#define LOCALTIME cross_localtime
-#define OFFTIME cross_offtime
-#define STRUCT_TM struct cross_tm
-#define STRUCT_TZHEAD struct cross_tzhead
-#define TIMEZONE cross_timezone
-#define TIME_T cross_time_t
-#define TZNAME cross_tzname
-#define TZSET cross_tzset
-#define TZTAB cross_tztab
#else
#include <sys/param.h>
#include <sys/types.h>
#include <time.h>
#include <tzfile.h>
-#define _MAXPATHLEN MAXPATHLEN
-#define ASCTIME asctime
-#define CTIME ctime
-#define LOCALTIME localtime
-#define GMTIME gmtime
-#define OFFTIME offtime
-#define STRUCT_TM struct tm
-#define STRUCT_TZHEAD struct tzhead
-#define TIMEZONE timezone
-#define TIME_T time_t
-#define TZNAME tzname
-#define TZSET tzset
-#define TZTAB tztab
+#define CROSS_MAXPATHLEN MAXPATHLEN
+#define cross_asctime asctime
+#define cross_ctime ctime
+#define cross_localtime localtime
+#define cross_gmtime gmtime
+#define cross_offtime offtime
+#define cross_tm tm
+#define cross_tzhead tzhead
+#define cross_timezone timezone
+#define cross_time_t time_t
+#define cross_tzname tzname
+#define cross_tzset tzset
+#define cross_tztab tztab
#endif
-#ifndef __P
-#ifdef __STDC__
-#define __P(params) params
-#else
-#define __P(params) ()
-#endif
-#endif
-
-/* ctime.c */
-char *CTIME __P((TIME_T *t));
-char *ASCTIME __P((register STRUCT_TM *timeptr));
-void TZSET __P((void));
-STRUCT_TM *LOCALTIME __P((TIME_T *timep));
-STRUCT_TM *GMTIME __P((TIME_T *clock));
-STRUCT_TM *OFFTIME __P((TIME_T *clock, long offset));
-/* timezone.c */
-char *TIMEZONE __P((int zone, int dst));
-char *TZTAB __P((register int zone, int dst));
-
-char *CTIME(t) TIME_T *t; {
- return(ASCTIME(LOCALTIME(t)));
+char *cross_ctime(t) cross_time_t *t; {
+ return(cross_asctime(cross_localtime(t)));
}
/*
** A la X3J11
*/
-char *ASCTIME(timeptr) register STRUCT_TM *timeptr; {
+char *cross_asctime(timeptr) register struct cross_tm *timeptr; {
static char wday_name[DAYS_PER_WEEK][3] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
};
#define FALSE 0
#endif /* !TRUE */
-STRUCT_TM * OFFTIME();
+struct cross_tm * cross_offtime();
struct ttinfo { /* time type information */
long tt_gmtoff; /* GMT offset in seconds */
int timecnt;
int typecnt;
int charcnt;
- TIME_T ats[TZ_MAX_TIMES];
+ cross_time_t ats[TZ_MAX_TIMES];
unsigned char types[TZ_MAX_TIMES];
struct ttinfo ttis[TZ_MAX_TYPES];
char chars[TZ_MAX_CHARS + 1];
static int tz_is_set;
-char * TZNAME[2] = {
+char * cross_tzname[2] = {
"GMT",
"GMT"
};
#ifdef USG_COMPAT
-TIME_T timezone = 0;
+cross_time_t timezone = 0;
int daylight = 0;
#endif /* USG_COMPAT */
{
register char * p;
register int doaccess;
- char fullname[_MAXPATHLEN];
+ char fullname[CROSS_MAXPATHLEN];
doaccess = name[0] == '/';
if (!doaccess) {
}
{
register char * p;
- register STRUCT_TZHEAD * tzhp;
+ register struct cross_tzhead * tzhp;
char buf[sizeof s];
i = read(fid, buf, sizeof buf);
if (close(fid) != 0 || i < sizeof *tzhp)
return -1;
- tzhp = (STRUCT_TZHEAD *) buf;
+ tzhp = (struct cross_tzhead *) buf;
s.timecnt = (int) detzcode(tzhp->tzh_timecnt);
s.typecnt = (int) detzcode(tzhp->tzh_typecnt);
s.charcnt = (int) detzcode(tzhp->tzh_charcnt);
if (s.ttis[i].tt_abbrind >= s.charcnt)
return -1;
/*
- ** Set TZNAME elements to initial values.
+ ** Set cross_tzname elements to initial values.
*/
- TZNAME[0] = TZNAME[1] = &s.chars[0];
+ cross_tzname[0] = cross_tzname[1] = &s.chars[0];
#ifdef USG_COMPAT
timezone = s.ttis[0].tt_gmtoff;
daylight = 0;
ttisp = &s.ttis[i];
if (ttisp->tt_isdst) {
- TZNAME[1] = &s.chars[ttisp->tt_abbrind];
+ cross_tzname[1] = &s.chars[ttisp->tt_abbrind];
#ifdef USG_COMPAT
daylight = 1;
#endif /* USG_COMPAT */
} else {
- TZNAME[0] = &s.chars[ttisp->tt_abbrind];
+ cross_tzname[0] = &s.chars[ttisp->tt_abbrind];
#ifdef USG_COMPAT
timezone = ttisp->tt_gmtoff;
#endif /* USG_COMPAT */
s.timecnt = 0; /* UNIX counts *west* of Greenwich */
s.ttis[0].tt_gmtoff = tz.tz_minuteswest * -SECS_PER_MIN;
s.ttis[0].tt_abbrind = 0;
- (void)strcpy(s.chars, TZTAB(tz.tz_minuteswest, 0));
- TZNAME[0] = TZNAME[1] = s.chars;
+ (void)strcpy(s.chars, cross_tztab(tz.tz_minuteswest, 0));
+ cross_tzname[0] = cross_tzname[1] = s.chars;
#ifdef USG_COMPAT
timezone = tz.tz_minuteswest * 60;
daylight = tz.tz_dsttime;
s.ttis[0].tt_gmtoff = 0;
s.ttis[0].tt_abbrind = 0;
(void) strcpy(s.chars, "GMT");
- TZNAME[0] = TZNAME[1] = s.chars;
+ cross_tzname[0] = cross_tzname[1] = s.chars;
#ifdef USG_COMPAT
timezone = 0;
daylight = 0;
#endif /* USG_COMPAT */
}
-void TZSET() {
+void cross_tzset() {
register char * name;
tz_is_set = TRUE;
tzsetgmt(); /* GMT is default */
}
-STRUCT_TM *LOCALTIME(timep) TIME_T *timep; {
+struct cross_tm *cross_localtime(timep) cross_time_t *timep; {
register struct ttinfo * ttisp;
- register STRUCT_TM * tmp;
+ register struct cross_tm * tmp;
register int i;
- TIME_T t;
+ cross_time_t t;
if (!tz_is_set)
- (void) TZSET();
+ (void) cross_tzset();
t = *timep;
if (s.timecnt == 0 || t < s.ats[0]) {
i = 0;
/*
** To get (wrong) behavior that's compatible with System V Release 2.0
** you'd replace the statement below with
- ** tmp = OFFTIME((TIME_T) (t + ttisp->tt_gmtoff), 0L);
+ ** tmp = cross_offtime((cross_time_t) (t + ttisp->tt_gmtoff), 0L);
*/
- tmp = OFFTIME(&t, ttisp->tt_gmtoff);
+ tmp = cross_offtime(&t, ttisp->tt_gmtoff);
tmp->tm_isdst = ttisp->tt_isdst;
- TZNAME[tmp->tm_isdst] = &s.chars[ttisp->tt_abbrind];
+ cross_tzname[tmp->tm_isdst] = &s.chars[ttisp->tt_abbrind];
tmp->tm_zone = &s.chars[ttisp->tt_abbrind];
return tmp;
}
-STRUCT_TM *GMTIME(clock) TIME_T *clock; {
- register STRUCT_TM * tmp;
+struct cross_tm *cross_gmtime(clock) cross_time_t *clock; {
+ register struct cross_tm * tmp;
- tmp = OFFTIME(clock, 0L);
- TZNAME[0] = "GMT";
+ tmp = cross_offtime(clock, 0L);
+ cross_tzname[0] = "GMT";
tmp->tm_zone = "GMT"; /* UCT ? */
return tmp;
}
DAYS_PER_NYEAR, DAYS_PER_LYEAR
};
-STRUCT_TM *OFFTIME(clock, offset) TIME_T *clock; long offset; {
- register STRUCT_TM * tmp;
+struct cross_tm *cross_offtime(clock, offset) cross_time_t *clock; cross_long_t offset; {
+ register struct cross_tm * tmp;
register long days;
register long rem;
register int y;
register int yleap;
register int * ip;
- static STRUCT_TM tm;
+ static struct cross_tm tm;
tmp = &tm;
days = *clock / SECS_PER_DAY;