worsley@ditmela.oz (Andrew Worsley) (05/18/89)
#! /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 10 (of 10)."
# Contents: toolsdif/build.c.cdif
# Wrapped by sys@besplex on Sun Mar 26 06:34:43 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'toolsdif/build.c.cdif' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'toolsdif/build.c.cdif'\"
else
echo shar: Extracting \"'toolsdif/build.c.cdif'\" \(16217 characters\)
sed "s/^X//" >'toolsdif/build.c.cdif' <<'END_OF_FILE'
X*** tools-1.3/build.c Tue Nov 22 03:39:10 1988
X--- tools/build.c Wed Mar 22 04:55:54 1989
X***************
X*** 13,17 ****
X * begins directly after it. The kernel, mm, fs, init, and fsck are each
X! * padded out to a multiple of 16 bytes, and then concatenated into a
X * single file beginning 512 bytes into the file. The first byte of sector 1
X * contains executable code for the kernel. There is no header present.
X *
X--- 13,19 ----
X * begins directly after it. The kernel, mm, fs, init, and fsck are each
X! * padded out to a multiple of clicksize bytes, and then concatenated into a
X * single file beginning 512 bytes into the file. The first byte of sector 1
X * contains executable code for the kernel. There is no header present.
X+ * Clicksize is the CLICK_SIZE which the kernel, mm and fs files were
X+ * compiled with, and is encoded in bytes 2-3 of the kernel code segment.
X *
X***************
X*** 43,45 ****
X--- 45,59 ----
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+ BDE 8 Feb 89. CLICK_SIZE 256 instead of 16.
X+ BDE 2 Mar 89. CLICK_SIZE and CLICK_SHIFT variables clicksize, click_shift.
X+ */
X+
X+
X #define PROGRAMS 5 /* kernel + mm + fs + init + fsck = 5 */
X***************
X*** 47,48 ****
X--- 61,63 ----
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*** 51,53 ****
X #define FS_D_MAGIC 0xDADA /* identifies fs data space */
X! #define CLICK_SHIFT 4
X #define KERN 0
X--- 66,69 ----
X #define FS_D_MAGIC 0xDADA /* identifies fs data space */
X! #define DATA_ALIGNMENT 16 /* minimum alignment of separate I&D data */
X! #define HCLICK_SHIFT 4
X #define KERN 0
X***************
X*** 66,67 ****
X--- 82,84 ----
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*** 83,84 ****
X--- 100,105 ----
X
X+ unsigned click_shift; /* CLICK_SHIFT used to compile kernel/mm/fs */
X+ unsigned clicksize; /* CLICK_SIZE used to compile kernel/mm/fs */
X+ /* grrr, click_size would be ambiguous */
X+
X struct sizes {
X***************
X*** 87,88 ****
X--- 108,110 ----
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--- 178,184 ----
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 clicksize, if need
X! * be. The individual pieces need not be multiples of clicksize bytes,
X! * except for the text size when separate I & D is in use.
X */
X***************
X*** 166,170 ****
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--- 187,190 ----
X unsigned text_bytes, data_bytes, bss_bytes, rest, filler;
X+ unsigned file_text_bytes, sym_bytes;
X long tot_bytes;
X
X***************
X*** 173,178 ****
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! /* Pad the total size to a 16-byte multiple, if needed. */
X! if (sepid && ((text_bytes % 16) != 0) ) {
X pexit("separate I & D but text size not multiple of 16 bytes. File: ",
X--- 193,216 ----
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! /* If the kernel, determine click_shift and clicksize. */
X! if (num == 0) {
X! long lseek();
X! unsigned char click_buf[4];
X!
X! if (read(fd, click_buf, sizeof click_buf) != sizeof click_buf)
X! pexit("can't read click_shift in ", file_name);
X! if (lseek(fd, (long) -sizeof click_buf, 1) < 0)
X! pexit("can't seek before click_shift in ", file_name);
X! click_shift = click_buf[2] + (click_buf[3] << 8);
X! if (click_shift == 0)
X! click_shift = HCLICK_SHIFT; /* old kernel */
X! else if (click_shift < HCLICK_SHIFT)
X! pexit("kernel click_shift must be >= 4", "");
X! clicksize = 1 << click_shift;
X! }
X!
X! /* Pad the total size to a clicksize-byte multiple, if needed. */
X! if (sepid && ((text_bytes % DATA_ALIGNMENT) != 0) ) {
X pexit("separate I & D but text size not multiple of 16 bytes. File: ",
X***************
X*** 180,184 ****
X }
X! tot_bytes = (long)text_bytes + data_bytes + bss_bytes;
X! rest = tot_bytes % 16;
X! filler = (rest > 0 ? 16 - rest : 0);
X bss_bytes += filler;
X--- 218,225 ----
X }
X! file_text_bytes = text_bytes;
X! if (sepid)
X! text_bytes = (text_bytes + clicksize - 1) & ~(clicksize - 1);
X! tot_bytes = (long) text_bytes + (data_bytes + bss_bytes) + sym_bytes;
X! rest = tot_bytes % clicksize;
X! filler = (rest > 0 ? clicksize - rest : 0);
X bss_bytes += filler;
X***************
X*** 192,193 ****
X--- 233,235 ----
X sizes[num].bss_size = bss_bytes;
X+ sizes[num].sym_size = sym_bytes;
X sizes[num].sep_id = sepid;
X***************
X*** 203,213 ****
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 /* Write the bss to output. */
X--- 245,257 ----
X /* Read in the text and data segments, and copy them to output. */
X! copy3(fd, file_text_bytes, file_name);
X
X+ /* Oops, pad the text segment in the middle of this. */
X+ text_bytes -= file_text_bytes; /* remainder now */
X+ while (text_bytes != 0) {
X+ count = (text_bytes < SECTOR_SIZE ? text_bytes : SECTOR_SIZE);
X+ wr_out(zero, count);
X+ text_bytes -= count;
X+ }
X+ copy3(fd, data_bytes, file_name);
X+
X /* Write the bss to output. */
X***************
X*** 218,219 ****
X--- 262,267 ----
X }
X+
X+ /* Copy symbol table to output. */
X+ copy3(fd, sym_bytes, file_name);
X+
X close(fd);
X***************
X*** 222,228 ****
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 {
X /* Read the header and check the magic number. The standard Monix header
X--- 270,301 ----
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 /* Read the header and check the magic number. The standard Monix header
X***************
X*** 243,248 ****
X--- 316,349 ----
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--- 364,367 ----
X *bss_bytes = (unsigned) head[BSS_POS];
X+ *sym_bytes = (unsigned) head[SYM_POS];
X+ #endif
X }
X***************
X*** 333,340 ****
X
X! if (cum_size % 16 != 0) pexit("MINIX is not multiple of 16 bytes", "");
X fsck_org = PROG_ORG + cum_size; /* where does fsck begin */
X ip = 0;
X! cs = fsck_org >> CLICK_SHIFT;
X if (sizes[FSCK].sep_id)
X! ds = cs + (sizes[FSCK].text_size >> CLICK_SHIFT);
X else
X--- 436,444 ----
X
X! if (cum_size % clicksize != 0)
X! pexit("MINIX is not multiple of clicksize bytes", "");
X fsck_org = PROG_ORG + cum_size; /* where does fsck begin */
X ip = 0;
X! cs = fsck_org >> HCLICK_SHIFT;
X if (sizes[FSCK].sep_id)
X! ds = cs + (sizes[FSCK].text_size >> HCLICK_SHIFT);
X else
X***************
X*** 344,348 ****
X sectrs = (unsigned) (all_size / 512L);
X
X read_block(0, ubuf); /* read in boot block */
X! ubuf[(SECTOR_SIZE/2) - 4] = sectrs + 1;
X ubuf[(SECTOR_SIZE/2) - 3] = ds;
X--- 448,454 ----
X sectrs = (unsigned) (all_size / 512L);
X+ if (all_size % 512 != 0)
X+ ++sectrs;
X
X read_block(0, ubuf); /* read in boot block */
X! ubuf[(SECTOR_SIZE/2) - 4] = sectrs;
X ubuf[(SECTOR_SIZE/2) - 3] = ds;
X***************
X*** 367,368 ****
X--- 473,477 ----
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--- 479,485 ----
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--- 494,504 ----
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--- 508,510 ----
X put_byte(data_offset + 4*i + 3L, (data_clicks>>8) & 0377);
X+ text_offset += (unsigned long) t + d + b + s;
X }
X***************
X*** 399,403 ****
X if (sizes[KERN].sep_id == 0)
X! ds = PROG_ORG >> CLICK_SHIFT; /* combined I & D space */
X else
X! ds = (PROG_ORG + sizes[KERN].text_size) >> CLICK_SHIFT; /* separate */
X put_byte(512L + DS_OFFSET, ds & 0377);
X--- 513,517 ----
X if (sizes[KERN].sep_id == 0)
X! ds = PROG_ORG >> HCLICK_SHIFT; /* combined I & D space */
X else
X! ds = (PROG_ORG + sizes[KERN].text_size) >> HCLICK_SHIFT; /* separate */
X put_byte(512L + DS_OFFSET, ds & 0377);
X***************
X*** 419,430 ****
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 if (sizes[INIT].sep_id == 0) {
X--- 533,546 ----
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 if (sizes[INIT].sep_id == 0) {
X***************
X*** 433,436 ****
X }
X! init_text_size = init_text_size >> CLICK_SHIFT;
X! init_data_size = init_data_size >> CLICK_SHIFT;
X
X--- 549,552 ----
X }
X! init_text_size = init_text_size >> click_shift;
X! init_data_size = init_data_size >> click_shift;
X
X***************
X*** 450,453 ****
X--- 566,575 ----
X if (mag != FS_D_MAGIC) pexit("mm data space: no magic #","");
X+ mag = (get_byte(mm_data+3L) << 8) + get_byte(mm_data+2L);
X+ if (mag == 0) mag = HCLICK_SHIFT; /* old mm */
X+ if (mag != click_shift) pexit("mm click_shift does not match kernel's", "");
X mag = (get_byte(fbase+1L) << 8) + get_byte(fbase+0L);
X if (mag != FS_D_MAGIC) pexit("fs data space: no magic #","");
X+ mag = (get_byte(fbase+3L) << 8) + get_byte(fbase+2L);
X+ if (mag == 0) mag = HCLICK_SHIFT; /* old fs */
X+ if (mag != click_shift) pexit("fs click_shift does not match kernel's", "");
X
X***************
X*** 496,497 ****
X--- 618,628 ----
X
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
END_OF_FILE
if test 16217 -ne `wc -c <'toolsdif/build.c.cdif'`; then
echo shar: \"'toolsdif/build.c.cdif'\" unpacked with wrong size!
fi
# end of 'toolsdif/build.c.cdif'
fi
echo shar: End of archive 10 \(of 10\).
cp /dev/null ark10isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 10 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have unpacked all 10 archives.
rm -f ark[1-9]isdone ark[1-9][0-9]isdone
else
echo You still need to unpack the following archives:
echo " " ${MISSING}
fi
## End of shell archive.
exit 0
--
Division of Information Technology (Melbourne), Phone +61 3 347 8644
C.S.I.R.O. Fax +61 3 347 8987
55 Barry St. Telex AA 152914
Carlton, Vic, 3053, Australia E-mail: worsley@ditmela.oz.au