[comp.os.minix] PC-AT-386 debugger source 4 of 7

brucee@runx.ips.oz (Bruce Evans) (11/26/88)

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 4 (of 7)."
# Contents:  kernel/db/io.c tools/build.c.cdif
# Wrapped by sys@besplex on Sat Nov 26 06:00:22 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'kernel/db/io.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kernel/db/io.c'\"
else
echo shar: Extracting \"'kernel/db/io.c'\" \(11682 characters\)
sed "s/^X//" >'kernel/db/io.c' <<'END_OF_FILE'
X/* io.c */
X
X#include "const.h"
X#include "type.h"
X#include "var.h"
X
X#define NDEV 3
X#define KEYDEV 0
X#define TTYDEV 1
X#define SCRDEV 2
X
X#define IOCCOFF 0		/* cursor on (these s.b. in header file) */
X#define IOCCON  1		/* cursor off */
X#define IOCUSER 2		/* copy user state */
X
Xstruct dev
X{
X	bool_t inopen;
X	bool_t outopen;
X	pfv_t close;
X	pfi_t in;
X	pfv_t ioctl;
X	pfv_t open;
X	pfv_t out;
X};
X
XPRIVATE struct dev devtable[NDEV] =
X{
X	{ TRUE, FALSE, kbdclose, kbdin, kbdioctl, kbdopen, kbdout },
X	{ TRUE, FALSE, ttyclose, ttyin, ttyioctl, ttyopen, ttyout },
X	{ FALSE, TRUE, scrclose, scrin, scrioctl, scropen, scrout }
X};
X
XPRIVATE bool_t forceupper;
XPRIVATE bool_t pause = FALSE;
XPRIVATE bool_t someupper = TRUE;
XPRIVATE count_t stringcount = 0;
XPRIVATE char *string_ptr = NULL;	/* stringptr ambiguous at 8th char */
XPRIVATE char *stringstart = NULL;
X
X/* cancel input device */
X
XPUBLIC void can_input( devptr )
Xstruct dev *devptr;
X{
X	if ( devptr->inopen )
X	{
X		if ( !devptr->outopen )
X			(*devptr->close)();
X		devptr->inopen = FALSE;
X	}
X}
X
X/* cancel output device */
X
XPUBLIC void can_output( devptr )
Xstruct dev *devptr;
X{
X	if ( devptr->outopen )
X	{
X		if ( !devptr->inopen )
X			(*devptr->close)();
X		devptr->outopen = FALSE;
X	}
X}
X
X/* cancel keyboard device */
X
XPUBLIC void can_keyboard()
X{
X	can_input( &devtable[KEYDEV] );
X}
X
X/* cancel screen device */
X
XPUBLIC void can_screen()
X{
X	can_output( &devtable[SCRDEV] );
X}
X
X/* cancel tty input device */
X
XPUBLIC void can_itty()
X{
X	can_input( &devtable[TTYDEV] );
X}
X
X/* cancel tty output device */
X
XPUBLIC void can_otty()
X{
X	can_output( &devtable[TTYDEV] );
X}
X
X/* close all devices */
X
XPUBLIC void closeio()
X{
X	struct dev *devptr;
X
X	for ( devptr = &devtable[0]; devptr < &devtable[NDEV]; ++devptr )
X		if ( devptr->inopen || devptr->outopen )
X			(*devptr->close)();
X}
X
X/* close string device */
X
XPUBLIC void closestring()
X{
X	stringcount = 0;
X	stringstart = string_ptr = NULL;
X}
X
X/* enable input device */
X
XPUBLIC void enab_input( devptr )
Xstruct dev *devptr;
X{
X	if ( !devptr->inopen )
X	{
X		if ( !devptr->outopen )
X			(*devptr->open)();
X		devptr->inopen = TRUE;
X	}
X}
X
X/* enable output device */
X
XPUBLIC void enab_output( devptr )
Xstruct dev *devptr;
X{
X	if ( !devptr->outopen )
X	{
X		if ( !devptr->inopen )
X			(*devptr->open)();
X		devptr->outopen = TRUE;
X	}
X}
X
X/* enable keyboard device */
X
XPUBLIC void enab_keyboard()
X{
X	enab_input( &devtable[KEYDEV] );
X}
X
X/* enable screen device */
X
XPUBLIC void enab_screen()
X{
X	enab_output( &devtable[SCRDEV] );
X}
X
X/* enable tty input device */
X
XPUBLIC void enab_itty()
X{
X	enab_input( &devtable[TTYDEV] );
X}
X
X/* enable tty output device */
X
XPUBLIC void enab_otty()
X{
X	enab_output( &devtable[TTYDEV] );
X}
X
XPUBLIC void flipcase()
X{
X	someupper = TRUE - someupper;
X}
X
X/* get 8 bits current instruction pointer and advance pointer */
X
XPUBLIC u8_pt get8()
X{
X	u8_pt temp;
X
X	temp = peek8( &uptr );
X	++uptr.off;
X	return temp;
X}
X
X/* get 16 bits from current instruction pointer and advance pointer */
X
XPUBLIC u16_t get16()
X{
X	u16_t temp;
X
X	temp = peek16( &uptr );
X	uptr.off += 2;
X	return temp;
X}
X
X/* get 32 bits from current instruction pointer and advance pointer */
X
XPUBLIC u32_t get32()
X{
X	u32_t temp;
X
X	temp = peek32( &uptr );
X	uptr.off += 4;
X	return temp;
X}
X
X/* input char from one of currently open input devices */
X
XPUBLIC char16_t inchar()
X{
X	char16_t ch;
X
X	ioctlio( IOCCON );
X	while ( (ch = testchar()) == EOF )
X		;
X	ioctlio( IOCCOFF );
X	return ch;
X}
X
X/* perform ioctl for all devices */
X
XPUBLIC void ioctlio( command )
Xbool_pt command;
X{
X	struct dev *devptr;
X
X	for ( devptr = &devtable[0]; devptr < &devtable[NDEV]; ++devptr )
X		if ( devptr->inopen || devptr->outopen )
X			(*devptr->ioctl)( command );
X}
X
X/* convert char to lower case */
X
XPUBLIC char_pt mytolower( ch )
Xchar_pt ch;
X{
X	if ( ch >= 'A' && ch <= 'Z' )
X	/*
X	if ( (ch - 'A') <= 'Z' - 'A' )
X	*/
X		ch += 'a' - 'A';
X	return ch;
X}
X
X/* open all devices */
X
XPUBLIC void openio()
X{
X	struct dev *devptr;
X
X	for ( devptr = &devtable[0]; devptr < &devtable[NDEV]; ++devptr )
X		if ( devptr->inopen || devptr->outopen )
X			(*devptr->open)();
X	pause = FALSE;
X}
X
X/* open string device */
X
XPUBLIC void openstring( string )
Xchar *string;
X{
X	stringcount = 0;
X	stringstart = string_ptr = string;
X}
X
X/* print 2 spaces */
X
XPUBLIC void out2space()
X{
X	outspace();
X	outspace();
X}
X
X/* print char to currently open output devices */
X
XPUBLIC void outbyte( byte )
Xchar_pt byte;
X{
X	struct dev *devptr;
X
X	if ( forceupper && byte >= 'a' && byte <= 'z' )
X		byte += 'A' - 'a';
X	if ( string_ptr != NULL )
X	{
X		if ( (*string_ptr++ = byte) == '\t' )
X			stringcount = 8 * (stringcount / 8 + 1);
X		else
X			++stringcount;
X	}
X	else
X		for ( devptr = &devtable[0]; devptr < &devtable[NDEV]; ++devptr )
X			if ( devptr->outopen )
X				(*devptr->out)( byte );
X}
X
X/* print colon */
X
XPUBLIC void outcolon()
X{
X	outbyte( ':' );
X}
X
X/* print comma */
X
XPUBLIC void outcomma()
X{
X	outbyte( ',' );
X}
X
X/* get 8 bit offset and print in hex */
X
XPUBLIC void outget8()
X{
X	outh8( get8() );
X}
X
X/* get 16 bit offset and print in hex */
X
XPUBLIC void outget16()
X{
X	outh16( get16() );
X}
X
X/* print 4 bits hex */
X
XPUBLIC void outh4( num )
Xu4_pt num;
X{
X	static char hexdigits[] = "0123456789abcdef";
X
X	forceupper = someupper;
X	outbyte( hexdigits[num % 16] );
X	forceupper = FALSE;
X}
X
X/* print 8 bits hex */
X
XPUBLIC void outh8( num )
Xu8_pt num;
X{
X	outh4( num / 16 );
X	outh4( num );
X}
X
X/* print 8 bits hex and 1 space */
X
XPUBLIC void outh8s( num )
Xu8_pt num;
X{
X	outh8( num );
X	outspace();
X}
X
X/* print 16 bits hex */
X
XPUBLIC void outh16( num )
Xu16_t num;
X{
X	outh8( num / 256 );
X	outh8( num );
X}
X
X/* print 32 bits hex */
X
XPUBLIC void outh32( num )
Xu32_t num;
X{
X	outh16( (u16_t) (num >> 16) );
X	outh16( (u16_t) num );
X}
X
X#ifdef UNUSED_FUNCTIONS
X
X/* print offset, hex format */
X
XPUBLIC void outhex( num )
Xoffset_t num;
X{
X#ifdef HEXSTARTCHAR
X	if ( num >= 10 )
X		outbyte( HEXSTARTCHAR );
X#endif
X	outhexdigs( num );
X#ifdef HEXENDCHAR
X	if ( num >= 10 )
X		outbyte( HEXENDCHAR );
X#endif
X}
X
X#endif
X
X#ifdef UNUSED_FUNCTIONS
X
X/* print 8 bit offset, hex format */
X
XPUBLIC void outhex8( num )
Xu8_pt num;
X{
X#ifdef HEXSTARTCHAR
X	outbyte( HEXSTARTCHAR );
X#endif
X	outh8( num );
X#ifdef HEXENDCHAR
X	outbyte( HEXENDCHAR );
X#endif
X}
X
X#endif
X
X#ifdef UNUSED_FUNCTIONS
X
X/* print 16 bit offset, hex format */
X
XPUBLIC void outhex16( num )
Xu16_t num;
X{
X#ifdef HEXSTARTCHAR
X	outbyte( HEXSTARTCHAR );
X#endif
X	outh16( num );
X#ifdef HEXENDCHAR
X	outbyte( HEXENDCHAR );
X#endif
X}
X
X#endif
X
X#ifdef UNUSED_FUNCTIONS
X
X/* print offset, hex format with digits only (no hex designator) */
X
XPUBLIC void outhexdigs( num )
Xregister offset_t num;
X{
X	if ( num >= 16 )
X	{
X		outhexdigs( num / 16 );
X		num %= 16;
X	}
X	outhdigit( num );
X}
X
X#endif
X
X#ifdef UNUSED_FUNCTIONS
X
X/* print character, then newline */
X
XPUBLIC void outnbyte( byte )
Xchar_pt byte;
X{
X	outbyte( byte );
X	outnl();
X}
X
X#endif
X
X#ifdef UNUSED_FUNCTIONS
X
X/* print offset, hex format, then newline */
X
XPUBLIC void outnhex( num )
Xoffset_t num;
X{
X	outhex( num );
X	outnl();
X}
X
X#endif
X
X/* print newline */
X
XPUBLIC bool_pt outnl()
X{
X	char_pt ch;
X
X	outstr( "\015\012" );
X	if ( !pause )
X	{
X		if ( (ch = testchar()) == CAN )
X			return FALSE;
X		if ( ch != XOFF )
X			return TRUE;
X	}
X	pause = FALSE;
X	if ( (ch = inchar()) == XOFF )
X		pause = TRUE;
X	return ch - CAN;
X}
X
X/* print string, then newline */
X
XPUBLIC bool_pt outnstr( s )
Xchar *s;
X{
X	outstr( s );
X	return outnl();
X}
X
X#ifdef UNUSED_FUNCTIONS
X
X/* print plus sign */
X
XPUBLIC void outplus()
X{
X	outbyte( '+' );
X}
X
X#endif
X
X/* print segmented address */
X
XPUBLIC void outsegadr( adr )
Xstruct adr *adr;
X{
X	outh16( adr->seg );
X	outcolon();
X	if ( db_processor == 386 )
X		outh32( adr->off );
X	else
X		outh16( (u16_t) adr->off );
X}
X
X/* print 32 bit segmented address and 2 spaces */
X
XPUBLIC void outssegadr( adr )
Xstruct adr *adr;
X{
X	outsegadr( adr );
X	out2space();
X}
X
X#ifdef UNUSED_FUNCTIONS
X
X/* print signed, hex format */
X
XPUBLIC void outshex( num )
Xoffset_t num;
X{
X	if ( (soffset_t) num < 0 )
X	{
X		outbyte( '-' );
X		num = -num;
X	}
X	outhex( num );
X}
X
X#endif
X
X/* print space */
X
XPUBLIC void outspace()
X{
X	outbyte( ' ' );
X}
X
X/* print string */
X
XPUBLIC void outstr( s )
Xregister char *s;
X{
X	while ( *s )
X		outbyte( *s++ );
X}
X
X/* print tab */
X
XPUBLIC void outtab()
X{
X	outbyte( '\t' );
X}
X
X/* print string, perhaps converting case to upper */
X
XPUBLIC void outustr( s )
Xregister char *s;
X{
X	forceupper = someupper;
X	while ( *s )
X		outbyte( *s++ );
X	forceupper = FALSE;
X}
X
X#ifdef UNUSED_FUNCTIONS
X
X/* print offset, decimal format */
X
XPUBLIC void outudec( num )
Xregister offset_t num;
X{
X	if ( num >= 10 )
X	{
X		register offset_t reduction;
X
X		outudec( reduction = num / 10 );
X		num -= 10 * reduction;
X	}
X	outbyte( (char_pt) num + '0' );
X}
X
X#endif
X
X/* set tty parameters from user */
X
XPUBLIC void set_tty()
X{
X	ioctlio( IOCUSER );
X}
X
X/* flip to the db screen (flip to user by closing */
X
XPUBLIC void show_db_screen()
X{
X	if ( devtable[SCRDEV].outopen )
X		(*devtable[SCRDEV].open)();
X}
X
X/* flip to the user screen */
X
XPUBLIC void show_user_screen()
X{
X	if ( devtable[SCRDEV].outopen )
X		(*devtable[SCRDEV].close)();
X}
X
X/* return current offset of string device */
X
XPUBLIC count_t stringpos()
X{
X	return string_ptr - stringstart;
X}
X
X/* return current "tab" spot of string device */
X
XPUBLIC count_t stringtab()
X{
X	return stringcount;
X}
X
X/* test for char from one of currently open input devices */
X
XPUBLIC char_pt testchar()
X{
X	char_pt ch;
X	struct dev *devptr;
X
X	for ( devptr = &devtable[0]; devptr < &devtable[NDEV]; ++devptr )
X		if ( devptr->inopen && (ch = (*devptr->in)()) != EOF )
X			return ch;
X	return EOF;
X}
X
X#ifdef LINT
X
X/* prototypes, perhaps out of date */
X/* prototypes for assembler functions */
X
X/* ARGSUSED */
XPUBLIC segment_t codeseg() { return 1; }
X/* ARGSUSED */
XPUBLIC segment_t dataseg() { return 1; }
X/* ARGSUSED */
XPUBLIC unsigned get_processor() { return 1; }
X/* ARGSUSED */
XPUBLIC u8_pt inportb( port ) port_t port; { return 1; }
X/* ARGSUSED */
XPUBLIC void oportb( port, val ) port_t port; u8_pt val; {}
X/* ARGSUSED */
XPUBLIC u8_pt peek8( adr ) struct adr *adr; { return 1; }
X/* ARGSUSED */
XPUBLIC u8_pt peekb( seg, off ) segment_t seg; u8_t *off; { return 1; }
X/* ARGSUSED */
XPUBLIC u16_t peek16( adr ) struct adr *adr; { return 1; }
X/* ARGSUSED */
XPUBLIC u16_t peekw( seg, off ) segment_t seg; u16_t *off; { return 1; }
X/* ARGSUSED */
XPUBLIC u32_t peek32( adr ) struct adr *adr; { return 1; }
X/* ARGSUSED */
XPUBLIC void poke8( adr, value ) struct adr *adr; u8_pt value; {}
X/* ARGSUSED */
XPUBLIC void pokeb( seg, off, val ) segment_t seg, u8_t *off, u8_pt val; {}
X/* ARGSUSED */
XPUBLIC void poke16( adr, value ) struct adr *adr; u16_t value; {}
X/* ARGSUSED */
XPUBLIC void pokew( seg, off, val ) segment_t seg, u16_t *off, u16_t val; {}
X/* ARGSUSED */
XPUBLIC void poke32( adr, value ) struct adr *adr; u32_t value; {}
XPUBLIC void scrclose() {}
XPUBLIC char_pt scrin() {}
X/* ARGSUSED */
XPUBLIC void scrioctl( c ) char_pt c; {}
XPUBLIC void scropen() {}
X/* ARGSUSED */
XPUBLIC void scrout( c ) char_pt c; {}
XPUBLIC void symswap();
XPUBLIC void symswap( left, right, tableseg, length )
Xstruct nlist *left; struct nlist *right; segment_t tableseg; unsigned length;
X{}
XPUBLIC void ttyclose() {}
XPUBLIC char_pt ttyin() { return (char) 1; }
X/* ARGSUSED */
XPUBLIC void ttyioctl( c ) char_pt c; {}
XPUBLIC void ttyopen() {}
X/* ARGSUSED */
XPUBLIC void ttyout( c ) char_pt c; {}
X
X/* prototypes for library functions */
X
X/* ARGSUSED */
XPUBLIC char *memcpy( t, s, n ) char *s; char *t; unsigned n; { return t; }
X/* ARGSUSED */
XPUBLIC int strlen( s ) char *s; { return 1; }
X
X/* prototypes for Minix kernel functions */
X
XPUBLIC segment_t codeseg() { return 1; }
XPUBLIC void get_con_state() {}
XPUBLIC void map_dmp() {}
XPUBLIC void p_dmp() {}
XPUBLIC void reset_con_state() {}
X
X#endif /* LINT */
END_OF_FILE
if test 11682 -ne `wc -c <'kernel/db/io.c'`; then
    echo shar: \"'kernel/db/io.c'\" unpacked with wrong size!
fi
# end of 'kernel/db/io.c'
fi
if test -f 'tools/build.c.cdif' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'tools/build.c.cdif'\"
else
echo shar: Extracting \"'tools/build.c.cdif'\" \(10647 characters\)
sed "s/^X//" >'tools/build.c.cdif' <<'END_OF_FILE'
X*** orig/build.c	Wed Aug  3 21:28:56 1988
X--- build.c	Mon Nov 21 21:56:38 1988
X***************
X*** 43,44 ****
X--- 43,53 ----
X  
X+ /* Modified by Bruce Evans, 21 Nov 88 to load symbol tables for debugger.
X+    For each piece of the kernel, the symbol table is loaded at the end of
X+    the bss. A pointer to it is placed in the spare word at location 2 in
X+    the code segment. The sizes array is adjusted so that the symbol table
X+    is effectively part of the data segment.
X+    It would be better for everything to load the exec headers and chain
X+    them together.
X+  */
X+ 
X  
X***************
X*** 47,48 ****
X--- 56,58 ----
X  #define DS_OFFSET 4L            /* position of DS written in kernel text seg */
X+ #define SYM_OFFSET 2L		/* position of syms writ in kernel text seg */
X  #define SECTOR_SIZE 512         /* size of buf */
X***************
X*** 66,67 ****
X--- 76,78 ----
X  #define BSS_POS 2               /* where is bss size in header */
X+ #define SYM_POS 5               /* where is sym size in header */
X  #define SEP_ID_BIT 0x20         /* bit that tells if file is separate I & D */
X***************
X*** 87,88 ****
X--- 98,100 ----
X    unsigned bss_size;            /* size in bytes */
X+   unsigned sym_size;            /* size in bytes */
X    int sep_id;                   /* 1 if separate, 0 if not */
X***************
X*** 156,163 ****
X  /* Open and read a file, copying it to output.  First read the header,
X!  * to get the text, data, and bss sizes.  Also see if it is separate I & D.
X!  * write the text, data, and bss to output.  The sum of these three pieces
X!  * must be padded upwards to a multiple of 16, if need be.  The individual
X!  * pieces need not be multiples of 16 bytes, except for the text size when
X!  * separate I & D is in use.  The total size must be less than 64K, even
X!  * when separate I & D space is used.
X   */
X--- 168,174 ----
X  /* Open and read a file, copying it to output.  First read the header,
X!  * to get the text, data, bss and symbol sizes.  Also see if it is separate
X!  * I & D. Write the text, data, bss and symbols to output.  The sum of these
X!  * four pieces must be padded upwards to a multiple of 16, if need be.  The
X!  * individual pieces need not be multiples of 16 bytes, except for the text
X!  * size when separate I & D is in use.
X   */
X***************
X*** 165,170 ****
X    int fd, sepid, bytes_read, count;
X!   unsigned text_bytes, data_bytes, bss_bytes, rest, filler;
X!   long tot_bytes;
X!   unsigned left_to_read;
X!   char inbuf[READ_UNIT];
X    
X--- 176,179 ----
X    int fd, sepid, bytes_read, count;
X!   unsigned text_bytes, data_bytes, bss_bytes, sym_bytes, rest, filler;
X!   long tot_bytes;
X    
X***************
X*** 173,175 ****
X    /* Read the header to see how big the segments are. */
X!   read_header(fd, &sepid, &text_bytes, &data_bytes, &bss_bytes, file_name);
X  
X--- 182,185 ----
X    /* Read the header to see how big the segments are. */
X!   read_header(fd, &sepid, &text_bytes, &data_bytes, &bss_bytes, &sym_bytes,
X!               file_name);
X  
X***************
X*** 180,182 ****
X    }
X!   tot_bytes = (long)text_bytes + data_bytes + bss_bytes;
X    rest = tot_bytes % 16;
X--- 190,192 ----
X    }
X!   tot_bytes = (long) text_bytes + (data_bytes + bss_bytes) + sym_bytes;
X    rest = tot_bytes % 16;
X***************
X*** 192,193 ****
X--- 202,204 ----
X    sizes[num].bss_size  = bss_bytes;
X+   sizes[num].sym_size  = sym_bytes;
X    sizes[num].sep_id    = sepid;
X***************
X*** 203,212 ****
X    /* Read in the text and data segments, and copy them to output. */
X!   left_to_read = text_bytes + data_bytes;
X!   while (left_to_read > 0) {
X!         count = (left_to_read < READ_UNIT ? left_to_read : READ_UNIT);
X!         bytes_read = read(fd, inbuf, count);
X!         if (bytes_read < 0) pexit("read error on file ", file_name);
X!         if (bytes_read > 0) wr_out(inbuf, bytes_read);
X!         left_to_read -= count;
X!   }
X  
X--- 214,217 ----
X    /* Read in the text and data segments, and copy them to output. */
X!   copy3(fd, text_bytes, file_name);
X!   copy3(fd, data_bytes, file_name);
X  
X***************
X*** 215,219 ****
X          count = (bss_bytes < SECTOR_SIZE ? bss_bytes : SECTOR_SIZE);
X!         wr_out(zero, count);
X!         bss_bytes -= count;
X!   }
X    close(fd);
X--- 220,228 ----
X          count = (bss_bytes < SECTOR_SIZE ? bss_bytes : SECTOR_SIZE);
X!         wr_out(&zero, count);
X!         bss_bytes -= count;
X!   }
X! 
X!   /* Copy symbol table to output. */
X!   copy3(fd, sym_bytes, file_name);
X! 
X    close(fd);
X***************
X*** 222,226 ****
X  
X! read_header(fd, sepid, text_bytes, data_bytes, bss_bytes, file_name)
X! int fd, *sepid;
X! unsigned *text_bytes, *data_bytes, *bss_bytes;
X  char *file_name;
X--- 231,260 ----
X  
X! copy3(fd, left_to_read, file_name)
X! int fd;
X! unsigned left_to_read;
X! char *file_name;
X! {
X!   int bytes_read;
X!   int count;
X!   char inbuf[READ_UNIT];
X! 
X!   while (left_to_read != 0)
X!   {
X!     if ( (unsigned) (count = left_to_read) > READ_UNIT)
X!       count = READ_UNIT;
X!     if ( (bytes_read = read(fd, &inbuf, count)) <= 0)
X!       pexit("read error on file ", file_name);
X!     wr_out(&inbuf, bytes_read);
X!     left_to_read -= count;
X!   }
X! }
X! 
X! 
X! #ifdef XENIX_HEADER
X! # include </usr/include/sys/a.out.h>
X! #endif
X! 
X! read_header(fd, sepid, text_bytes, data_bytes, bss_bytes, sym_bytes,file_name)
X! int fd, *sepid;
X! unsigned *text_bytes, *data_bytes, *bss_bytes, *sym_bytes;
X  char *file_name;
X***************
X*** 243,248 ****
X  
X!   long head[12];
X!   unsigned short hd[4];
X!   int n, header_len;
X! 
X    /* Read first 8 bytes of header to get header length. */
X--- 277,310 ----
X  
X! #ifdef XENIX_HEADER
X!   struct  aexec a_header;
X! #else
X!   long head[12];
X!   unsigned short hd[4];
X! #endif
X!   int n, header_len;
X! 
X! #ifdef XENIX_HEADER
X!   /*
X!     Do it right, read header *structure* to get header length.
X!     Fortunately header has no longs so we don't have to worry about
X!     swapped words, not to mention swapped bytes.
X!   */
X!   if ((n = read(fd, &a_header, sizeof a_header)) != sizeof a_header)
X!   {
X!     printf("expected %d, got %d\n", sizeof a_header, n);
X!     pexit("file header too short: ", file_name);
X!   }
X!   if (a_header.xa_magic == FMAGIC)
X!     *sepid = 0;
X!   else if (a_header.xa_magic == IMAGIC)
X!     *sepid = 1;
X!   else
X!     pexit("not Xenix a.out FMAGIC or IMAGIC. FIle: ", file_name);
X!   if (a_header.xa_entry != 0)
X!     pexit("nonzero entry point. FIle: ", file_name);
X!   *text_bytes = a_header.xa_text;
X!   *data_bytes = a_header.xa_data;
X!   *bss_bytes  = a_header.xa_bss;
X!   *sym_bytes  = a_header.xa_syms;
X! #else
X    /* Read first 8 bytes of header to get header length. */
X***************
X*** 263,264 ****
X--- 325,328 ----
X    *bss_bytes  = (unsigned) head[BSS_POS];
X+   *sym_bytes  = (unsigned) head[SYM_POS];
X+ #endif
X  }
X***************
X*** 367,368 ****
X--- 431,435 ----
X   * can't load DS from data space, but it can load DS from text space.
X+  * Write the offset of the symbol table for each progam into location 2 of
X+  * its code space, for the debugger. No one was expecting this, but is is
X+  * the only available unused space.
X   */
X***************
X*** 370,375 ****
X    int i, j;
X!   unsigned short t, d, b, text_clicks, data_clicks, ds;
X!   long data_offset;
X! 
X!   /* See if the magic number is where it should be in the kernel. */
X    data_offset = 512L + (long)sizes[KERN].text_size;    /* start of kernel data */
X--- 437,443 ----
X    int i, j;
X!   unsigned short t, d, b, s, text_clicks, data_clicks, ds;
X!   long text_offset, data_offset;
X! 
X!   /* See if the magic number is where it should be in the kernel. */
X!   text_offset = 512L;
X    data_offset = 512L + (long)sizes[KERN].text_size;    /* start of kernel data */
X***************
X*** 384,391 ****
X          b = sizes[i].bss_size;
X!         if (sizes[i].sep_id) {
X!                 text_clicks = t >> CLICK_SHIFT;
X!                 data_clicks = ((unsigned long)d + b) >> CLICK_SHIFT;
X!         } else {
X!                 text_clicks = 0;
X!                 data_clicks = ((unsigned long)t + d + b) >> CLICK_SHIFT;
X          }
X--- 452,462 ----
X          b = sizes[i].bss_size;
X! 	s = sizes[i].sym_size;
X!         if (sizes[i].sep_id) {
X!                 text_clicks = t >> CLICK_SHIFT;
X!                 data_clicks = ((unsigned long) d + b + s) >> CLICK_SHIFT;
X! 		put_word(text_offset + SYM_OFFSET, d + b);
X!         } else {
X!                 text_clicks = 0;
X!                 data_clicks = ((unsigned long) t + d + b + s) >> CLICK_SHIFT;
X! 		put_word(text_offset + SYM_OFFSET, t + d + b);
X          }
X***************
X*** 395,396 ****
X--- 466,468 ----
X          put_byte(data_offset + 4*i + 3L, (data_clicks>>8) & 0377);
X+         text_offset += (unsigned long) t + d + b + s;
X    }
X***************
X*** 419,429 ****
X    init_org  = PROG_ORG;
X!   init_org += (long)sizes[KERN].text_size+sizes[KERN].data_size+sizes[KERN].bss_size;
X!   mm_data = init_org - PROG_ORG +512L;	/* offset of mm in file */
X!   mm_data += (long) sizes[MM].text_size;
X!   init_org += (long)sizes[MM].text_size + sizes[MM].data_size + sizes[MM].bss_size;
X!   fs_org = init_org - PROG_ORG + 512L;   /* offset of fs-text into file */
X!   fs_org +=  (long) sizes[FS].text_size;
X!   init_org += (long)sizes[FS].text_size + sizes[FS].data_size + sizes[FS].bss_size;
X!   init_text_size = sizes[INIT].text_size;
X!   init_data_size = sizes[INIT].data_size + sizes[INIT].bss_size;
X    init_org  = init_org >> CLICK_SHIFT;  /* convert to clicks */
X--- 491,503 ----
X    init_org  = PROG_ORG;
X!   init_org += (long)sizes[KERN].text_size+sizes[KERN].data_size+sizes[KERN].bss_size + sizes[KERN].sym_size;
X!   /* this code was awful and is worse after adding sym_sizes */
X!   mm_data = init_org - PROG_ORG +512L;	/* offset of mm in file */
X!   mm_data += (long) sizes[MM].text_size;
X!   init_org += (long)sizes[MM].text_size + sizes[MM].data_size + sizes[MM].bss_size + sizes[MM].sym_size;
X!   fs_org = init_org - PROG_ORG + 512L;   /* offset of fs-text into file */
X!   fs_org +=  (long) sizes[FS].text_size;
X!   init_org += (long)sizes[FS].text_size + sizes[FS].data_size + sizes[FS].bss_size + sizes[FS].sym_size;
X!   init_text_size = sizes[INIT].text_size;
X!   init_data_size = sizes[INIT].data_size + sizes[INIT].bss_size
X!                  + sizes[INIT].sym_size;
X    init_org  = init_org >> CLICK_SHIFT;  /* convert to clicks */
X***************
X*** 497,498 ****
X--- 571,581 ----
X  
X+ /* this should be used instead of paired put_byte()'s */
X+ put_word(offset, word_value)
X+ long offset;
X+ unsigned word_value;
X+ {
X+   put_byte(offset, word_value % 256);
X+   put_byte(offset + 1, word_value / 256);
X+ }
X+ 
X  
END_OF_FILE
if test 10647 -ne `wc -c <'tools/build.c.cdif'`; then
    echo shar: \"'tools/build.c.cdif'\" unpacked with wrong size!
fi
# end of 'tools/build.c.cdif'
fi
echo shar: End of archive 4 \(of 7\).
cp /dev/null ark4isdone
MISSING=""
for I in 1 2 3 4 5 6 7 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 7 archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0

Bruce Evans
Internet: brucee@runx.ips.oz.au    UUCP: uunet!runx.ips.oz.au!brucee