static char sccsid
[] = "@(#)setup.c 5.4 (Berkeley) %G%";
* adb - routines to read a.out and core files at startup
static struct exec filhdr
;
/* NB. the following works only with letter (alpha) variables */
#define setavar(name, value) (var[(name) - 'a' + 10] = (value))
register struct nlist
*sp
;
txtmap
.ufd
= symfile
.fd
= getfile(1);
if (read(symfile
.fd
, (char *)&filhdr
, sizeof(filhdr
)) != sizeof(filhdr
) ||
bzero((char *)&filhdr
, sizeof(filhdr
));
txtmap
.m1
.e
= -(addr_t
)1;
loc
= filhdr
.a_text
+ filhdr
.a_data
;
txtmap
.m1
.f
= txtmap
.m2
.f
= N_TXTOFF(filhdr
);
switch ((int)filhdr
.a_magic
) {
/* text map 1 is empty; map 2 goes from 0 to loc */
/* text map 1 maps text segment, map 2 maps data */
txtmap
.m1
.e
= filhdr
.a_text
;
txtmap
.m2
.b
= dbase
= roundup(filhdr
.a_text
, CLBYTES
);
txtmap
.m2
.e
= dbase
+ filhdr
.a_data
;
txtmap
.m2
.f
+= txtmap
.m1
.e
;
/* save data segment base in variable b */
if (filhdr
.a_syms
!= 0) {
symtab
= (struct nlist
*)malloc((u_int
)filhdr
.a_syms
);
esymtab
= &symtab
[filhdr
.a_syms
/ sizeof(struct nlist
)];
(void) lseek(symfile
.fd
, loc
, L_SET
);
if (read(symfile.fd, (char *)(a), (int)(n)) != (n)) \
rd(symtab
, filhdr
.a_syms
);
rd(&strsize
, sizeof(strsize
));
* offsets in the string table are relative to the offset
* of the number we just read; we adjust for it here.
strsize
-= sizeof(strsize
);
if ((strtab
= malloc((u_int
)strsize
)) == NULL
)
for (sp
= symtab
; sp
< esymtab
; sp
++) {
if (sp
->n_un
.n_strx
== 0)
sp
->n_un
.n_strx
-= sizeof(strsize
);
if ((u_long
)sp
->n_un
.n_strx
>= strsize
) {
adbprintf("bad string index %D in symtab\n",
(expr_t
)sp
->n_un
.n_strx
);
sp
->n_un
.n_name
= strtab
+ sp
->n_un
.n_strx
;
if (INKERNEL(filhdr
.a_entry
)) {
txtmap
.m1
.b
+= KERNTEXTOFF
;
txtmap
.m1
.e
+= KERNTEXTOFF
;
txtmap
.m2
.b
+= KERNTEXTOFF
;
txtmap
.m2
.e
+= KERNTEXTOFF
;
prints("Error reading symbol|string table (old format a.out?)\n");
prints("Not enough space for symbol|string table\n");
datmap
.m1
.e
= -(addr_t
)1;
if ((datmap
.ufd
= corefile
.fd
= getfile(2)) < 0)
if (kernel
&& INKERNEL(filhdr
.a_entry
) && getkcore()) {
if (read(corefile
.fd
, (char *)&u
, ctob(UPAGES
)) != ctob(UPAGES
) ||
adbprintf("not core file = %s\n", corefile
.name
);
filhdr
.a_text
= ctob(u
.u_tsize
);
filhdr
.a_data
= ctob(u
.u_dsize
);
stacksize
= ctob(u
.u_ssize
);
switch ((int)filhdr
.a_magic
) {
datmap
.m1
.e
= filhdr
.a_text
+ filhdr
.a_data
;
datmap
.m2
.f
= ctob(UPAGES
) + datmap
.m1
.e
;
datmap
.m1
.b
= roundup(filhdr
.a_text
, CLBYTES
);
datmap
.m1
.e
= datmap
.m1
.b
+ filhdr
.a_data
;
datmap
.m2
.f
= ctob(UPAGES
) + filhdr
.a_data
;
/* save (possibly new) data segment base, and save stack size */
setavar('b', datmap
.m1
.b
);
datmap
.m1
.f
= ctob(UPAGES
);
datmap
.m2
.b
= KERNBASE
- ctob(UPAGES
) - stacksize
;
datmap
.m2
.e
= KERNBASE
- ctob(UPAGES
);
u
.u_ar0
= (int *)((caddr_t
)&u
+ ctob(UPAGES
)); /* XXX */
setavar('d', filhdr
.a_data
);
setavar('e', filhdr
.a_entry
);
setavar('m', filhdr
.a_magic
);
setavar('t', filhdr
.a_text
);