[comp.sys.nsc.32k] ten days with Minix

kls@ditka.UUCP (Karl Swartz) (09/10/90)

In the past ten days I've spent a lot of time working on and
with Minix, and I'm still as impressed as last time I wrote.
But the road is far from smooth.  Here is a condensation of
my notes which hopefully will help guide others along the path.

disk partitions
    I've kept the partitions as Bruce built them, using hd3
    as my / (root) filesystem (you'll need to patch the kernel
    to make this the default) and hd4 for /u (home directories
    for users).  I kept the initial mini-system in hd2, safe
    in case I need it to save my butt, and hd5 is a scratch
    area.  (I've configured in additional partitions beyond
    hd5 for more scratch space.)

    One gotcha is that the ROM monitor talks about physical
    blocks on the drive, which are 512 bytes long, while the
    numbers in the partition table are in 1024 byte logical
    blocks.  Some day I'll learn but I still end up being
    very puzzled every time I look at this until I again
    learn this.  For reference, here is a list of partitions
    and where the ROM monitor thinks they live:

	/dev	start	size (hex/dec)	phys block
	hd0	   0	 9d40 / 40256	      0
	hd1	   0	  100 /   256	      0
	hd2	 100	 2710 / 10000	    200
	hd3	2810	 2710 / 10000	   5020
	hd4	4f20	 2710 / 10000	   9e40
	hd5	7630	 2710 / 10000	   ec60

multiple kernel images
    You've got room for several kernels in the hd1 partition
    so it's a nice idea to make a duplicate in case you screw
    something up.  Use the ROM monitor to do this:

	Command (? for help): read 0 2000 80
	Command (? for help): write 100 2000 80

    To run one of the kernels enter

	Command (? for help): read X 2000 80
	Command (? for help): run 2000

    where X is either 0 or 100 depending on where you want
    the main or the backup kernel image.

loading the rest of the files

    I did this step from Bruce's "install" notes two pieces
    at a time, saving one piece to hd4 (write to 9e40) and
    the other to hd5 (write to ec60) in each pass.  It still
    is tedious, but with half as many reboots it's gotta be
    better.

include files
    Like any sane individual I immediately started tinkering
    with my new system, bypassing the documentation and most
    of the README files.  (Documentation?!  We don't need no
    steenking documentation!)

    Unfortunately, this means you'll probably miss a critical
    step -- some important include files.  Go read the README
    in /usr/src, or wherever your sources ended up, and make
    the appropriate links.

important utilities
    Take a look in /usr/src/commands for several utilities you
    will want to compile and install in /etc.  Amongst these,
    bpt and fsck will be particularly desireable.  You'll also
    want to recompile postmort and replace the version that's
    already in /usr/bin as it has a bad path wired into it.

increase size of disk cache
    Dave Rand suggested increasing the size of the disk cache
    from 128 KB to 1 MB.  Assuming your Minix kernel source
    lives in /usr/src/minix like mine does, look in fs/const.h
    for a line like

	#define NR_BUFS	128

    and change 128 to 1024.  Make sure that you do this in the
    else part of the conditional.

    Rebuilding this kernel from scratch took about ten and a
    half minutes, 10:29 to be precise.  After booting this new
    kernel (see next two sections) I cleaned the slate and built
    the same kernel again.  This time the time was 2:10!  This
    is a big win, folks!

building a kernel
    Before typing make, you need to make a few chanes to the
    Makefile in /usr/src/minix.  First, unless you have an OMTI
    controller like Bruce, you'll want to comment out the rule
    for "all" and the next couple of lines.  Add a new line that
    says simply "all: dist" and life will be much easier.

    Also, the four lines that tell make where to find various
    tools (as, cc, ld, nm) have a comment saying to comment them
    out on the pc532.  Unfortunately make doesn't know about at
    least one of them (probably nm but I've forgotten) so just
    change the path on each one to /usr/bin.

installing your new kernel
    If you followed the hints I offered above, it's easy.  Just
    follow these steps:

	$ su
	Password:
	# cat image >/dev/hd1
	# sync; bpt

	   ... hardware reset

	Command (? for help): read 0 2000 80
	Command (? for help): run 2000

    If something went awry, just go back and read the backup
    kernel from block 100.  (You did make one didn't you?)

setting the real-time clock
    Bruce's instructions for setting the clock use his floppy
    drive.  If you don't have a floppy (like me), just use a
    scratch partition on your hard disk.  Assuming hd5 is
    free for this use, do this after editing rtc.s:

	$ as rtc.s
	$ su
	Password:
	# cat image >/dev/hd5
	# sync; bpt

	   ... hardware reset

	Command (? for help): read ec60 2000-30 2

    Then continue with Bruce's directions.

tailoring boot options once and for all
    If you have a clock chip and normally boot from hd3 as I
    do, you'll want to change several lines in kernel/mpx32k.s:

	_have_rtc::	double	1
	ROOT_MINOR:	.equ	3

tty driver drops NUL characters
    The tty driver throws away incoming NULs even in raw mode,
    which is hell on communications protocols like uucp.  To
    correct this, look in file kernel/tty.c near the top of the
    in_char() routine.  Find the line

	if (ch == 0) return;

    and delete it.

multiple tty lines
    The distributed tty driver appears to have a bug that hangs
    the system if both ports on the same DUART are active at the
    same time.  With 4 DUARTs available just use a different one.
    You'll have to make some device files though since only the
    first two ports are in the distributed system:

	# su
	Password:
	# for i in 2 3 4 5 6 7; do
	? mknod /dev/tty$i c 3 $i
	? done
	#

    Set the protection and ownership of the new files to match
    /dev/tty1.

increasing number of processes
    With the disk cache increased it's almost reasonable to try
    doing other work while make is running in the background.
    But the stock kernel is only built for 16 processes, which
    can quickly be used up.  Edit h/const.h; change the define
    for NR_PROCS as desired.  (I set mine to 32.)

large partitions
    I have one of the Miniscribe 9380S drives (after plunking
    down a check for 50 of them you better believe I got one
    for myself!) and of course wanted to use big partitions.
    A 30,000 block partition worked fine, but 60,000 resulted
    in a panic as soon as I tried to mount it.  The "obvious"
    solution was to increase ZMAP_SLOTS (in fs/const.h) but
    this resulted in a kernel that wouldn't boot -- somewhere
    near when I'd expect the disk mounts to be done it simply
    did a breakpoint trap back to the ROM monitor.

    Until somebody works on this, don't expect big partitions
    to work.

startup and shutdown
    There's some cleanup you should probably do on startup and
    shutdown of the system.  The shell archive at the end of
    this message includes an /etc/shutdown and a new /etc/rc
    script that do a few more desireable things.  Note that rc
    says "Invalid errno" when it clears /etc/wtmp but it still
    works.

more include files
    Several include files that one would expect to find with
    GCC are missing.  I've included two in the attached shell
    archive that came from the 3B1 GCC but appear to be proper
    for a pc532.  We still need float.h.

floating point library routines
    Neither printf() nor scanf() seem to work correctly.  I'll
    take a look at these as soon as I get the sources.

    The libm.a library should have a fabs() routine but does
    not.  I wrote the obvious C routine but didn't like the
    code generated by GCC so wrote it myself; this is in the
    attached archive.  Other routines probably are missing ...

uucp
    I've gotten the uucp from the NLMUG working and added many
    enhancements, though it still doesn't know how to dial out.
    A fully functional version is waiting on some fixes to the
    tty driver which Dave is working on.

    If anybody wants what I have now let me know and I'll send
    cdiffs for the affected files, or post them to the mailing
    list if there's enough interest.

mail, smail2.5
    I've also gotten both of these running.  I'll include notes
    with the uucp stuff.

Well, that's probably enough for one night.  I hope this helps
a few of you out there.  (Appended to this message is the shell
archive of files mentioned above.)

--
Karl Swartz			 |UUCP	uunet!apple!zygot!ditka!kls
1-408/223-1308			 |INet	zygot!ditka!kls@apple.com
"I never let my schooling get in |BIX	kswartz
the way of my education."(Twain) |Snail	1738 Deer Creek Ct., San Jose CA 95148

--- cut here ---
#!/bin/sh
#
# This is a shell archive.  Feed it to /bin/sh to unpack these files:
#
#	./etc/rc
#	./etc/shutdown
#	./usr/include/stdarg.h
#	./usr/include/stddef.h
#	./usr/src/libm/fabs.s
#
echo "creating ./etc/rc"
sed -e 's/^@//' <<EOF >./etc/rc
@#!/bin/sh
@
@#
@# Disk management
@#
@#substitute your root device for "/dev/fd0" in the next line
@echo "/dev/hd3 is mounted on /" >/etc/mtab
@mount /dev/hd4 /u
@rm -f /tmp/*
@
@#
@# Set date, clear wtmp, and display boot message
@#
@#/bin/date -q </dev/tty
@cat /dev/null >/usr/adm/wtmp
@cat /etc/message
@
@#
@# Start daemons
@#
@/etc/update &
EOF
echo "creating ./etc/shutdown"
sed -e 's/^@//' <<EOF >./etc/shutdown
@#!/bin/sh
@
@PATH=/bin
@
@#
@# Dismount all filesystems.
@#
@cd /
@cat /etc/mtab \
@| while read dev x1 x2 x3 dir; do
@    case "$dir" in
@        /)
@            ;;
@        /*)
@            echo "/etc/umount $dev ($dir)"
@            #/etc/umount $dev
@            ;;
@        *)
@            echo "shutdown: bad mtab entry: $dev $x1 $x2 $x3 $dir"
@            ;;
@    esac
@done
@
@#
@# Flush remaining disk buffers and get out.
@#
@sync
@sync
@sync
@/etc/bpt
EOF
echo "creating ./usr/include/stdarg.h"
sed -e 's/^@//' <<EOF >./usr/include/stdarg.h
@#ifndef _STDARG_H
@#define _STDARG_H
@
@typedef char *va_list;
@
@/* Amount of space required in an argument list for an arg of type TYPE.
@   TYPE may alternatively be an expression whose type is used.  */
@
@#define __va_rounded_size(TYPE)  \
@  (((sizeof (TYPE) + sizeof (int) - 1) / sizeof (int)) * sizeof (int))
@
@#ifndef __sparc__
@#define va_start(AP, LASTARG) 						\
@ (AP = ((char *) &(LASTARG) + __va_rounded_size (LASTARG)))
@#else
@#define va_start(AP, LASTARG) 						\
@ (__builtin_saveregs (),						\
@  AP = ((char *) &(LASTARG) + __va_rounded_size (LASTARG)))
@#endif
@
@void va_end (va_list);		/* Defined in gnulib */
@#define va_end(AP)
@
@#define va_arg(AP, TYPE)						\
@ (AP += __va_rounded_size (TYPE),					\
@  *((TYPE *) (AP - __va_rounded_size (TYPE))))
@
@#endif /* _STDARG_H */
EOF
echo "creating ./usr/include/stddef.h"
sed -e 's/^@//' <<EOF >./usr/include/stddef.h
@#ifndef _STDDEF_H
@#define _STDDEF_H
@
@/* Signed type of difference of two pointers.  */
@
@typedef long ptrdiff_t;
@
@/* Unsigned type of `sizeof' something.  */
@
@#ifndef _SIZE_T	/* in case <sys/types.h> has defined it. */
@#define _SIZE_T
@typedef unsigned long size_t;
@#endif /* _SIZE_T */
@
@/* A null pointer constant.  */
@
@#undef NULL		/* in case <stdio.h> has defined it. */
@#define NULL ((void *)0)
@
@/* Offset of member MEMBER in a struct of type TYPE.  */
@
@#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
@
@#endif /* _STDDEF_H */
EOF
echo "creating ./usr/src/libm/fabs.s"
sed -e 's/^@//' <<EOF >./usr/src/libm/fabs.s
@.text
@	.align 2
@.globl _fabs
@_fabs:
@	absl	4(sp),f0
@	ret	0
EOF

evans@syd.dit.CSIRO.AU (Bruce.Evans) (09/10/90)

In article <9009100320.AA22237@ditka.UUCP> kls@ditka.UUCP (Karl Swartz) writes:
>    A 30,000 block partition worked fine, but 60,000 resulted
>    in a panic as soon as I tried to mount it.  The "obvious"
>    solution was to increase ZMAP_SLOTS (in fs/const.h) but

I fixed this for 1.5.10 (PC version). ZMAP_SLOTS and I_MAP_SLOTS are now 8.
The counting of bufs_in_use was doubled up for mounting. mkfs, df and fsck
had overflow bugs. The limit is now 65535 blocks.

>floating point library routines
>    Neither printf() nor scanf() seem to work correctly.  I'll
>    take a look at these as soon as I get the sources.

Earl Chew wrote a good version of stdio. Portable, but with Minix as a
principal target. We spent a long time attempting to make printf and scanf
ANSI-compliant and fast.
-- 
Bruce Evans		evans@syd.dit.csiro.au

dlr@daver.bungi.com (Dave Rand) (09/10/90)

[In the message entitled "ten days with Minix" on Sep 10,  3:20, Karl Swartz writes:]
> In the past ten days I've spent a lot of time working on and
> with Minix, and I'm still as impressed as last time I wrote.

Let me second this. George and I have been hacking on it this weekend
(George got an LED driver working, I fixed up part of the TTY code and
SCSI code). _Very_ nice. For those of you that are skeptics - please
go out and buy a copy. It does work, quite well!

With this in mind, and the number of people working on the code, I've
decided to set up YAML (Yet Another Mailing List). This mailing list
will be a source-code only distribution of patches, new code, and the like.
George has pointed out that the MINIX distribution clearly states that
the code may be transfered among non-commercial interested parties; I
think we fall into that catagory. I still believe that everyone should
purchase a copy of MINIX, though.

This mailing list will not be gated to usenet. If you would like to
join, please send your request to:

pc532-src-request@daver.bungi.com


-- 
Dave Rand
{pyramid|mips|bct|vsi1}!daver!dlr	Internet: dlr@daver.bungi.com

news@daver.bungi.com (09/11/90)

Good article, Karl.  
 
> In the past ten days I've spent a lot of time working on and
> with Minix, and I'm still as impressed as last time I wrote.
> But the road is far from smooth.  Here is a condensation of
> my notes which hopefully will help guide others along the path.
> 
> disk partitions
>     I've kept the partitions as Bruce built them, using hd3
[ stuff deleted ]

An additional suggestion:  Layout your partitions without regard
to the Version 1.3 32 Mbyte partition size limit.  That is if 
you ultimately want say several 50 Mbyte partitions, create 
a 30000 block partition, followed by a 20000 block gap, etc.
Hopefully, this will make the transformation to larger paritions
with verion 1.5 easier.

> multiple kernel images
>     You've got room for several kernels in the hd1 partition
>     so it's a nice idea to make a duplicate in case you screw
>     something up.  Use the ROM monitor to do this:
> 
> 	Command (? for help): read 0 2000 80
> 	Command (? for help): write 100 2000 80
> 
>     To run one of the kernels enter
> 
> 	Command (? for help): read X 2000 80
> 	Command (? for help): run 2000
> 
>     where X is either 0 or 100 depending on where you want
>     the main or the backup kernel image.

I consider this an absolute must at this point in time -- particularly
if you are modifing OS code.  The last thing you want is to find
out our new image will not run and you have on good OS images on-line.
The implication, of course, is to leave sufficent room at the 
beginning of the disk to hold two or more images each beginning
at convient block number.

> increase size of disk cache
>     Dave Rand suggested increasing the size of the disk cache
>     from 128 KB to 1 MB.  Assuming your Minix kernel source
>     lives in /usr/src/minix like mine does, look in fs/const.h
>     for a line like
> 
> 	#define NR_BUFS	128
> 
>     and change 128 to 1024.  Make sure that you do this in the
>     else part of the conditional.

You might want to also increase NR_BUFS_HASH accordingly.  I am 
not sure of what the best value is for NR_BUFS = 1024.  I arbitrarly
set mine to 1024.  Bruce Evans, a PC-Minix wizard from oz, has
NR_BUF = 320 and NR_HASH_BUF = 512 in his 32-bit 386 release.

> multiple tty lines

If you have a second terminal, you might want to direct printk
to this terminal.  It makes debugging or monitoring OS activity a 
lot cleaner. 

Best regards,
johnc


-- 

news@daver.bungi.com (09/14/90)

Dave:
...
> go out and buy a copy. It does work, quite well!

Now that 1.5 is released, all the more reason!  You can make a PC using
a (shudder) 286 CPU into a reasonable machine even (tho not as fast
as a pc532)

> With this in mind, and the number of people working on the code, I've
> decided to set up YAML (Yet Another Mailing List). This mailing list
> will be a source-code only distribution of patches, new code, and the like.

You know there is comp.os.minix...

> George has pointed out that the MINIX distribution clearly states that
> the code may be transfered among non-commercial interested parties; I
> think we fall into that catagory. I still believe that everyone should
> purchase a copy of MINIX, though.
> 
> This mailing list will not be gated to usenet. If you would like to
> join, please send your request to:
> 
> pc532-src-request@daver.bungi.com

Again, I don't seem to be able to use addresses with '@'s in them.  I
would like to join, and I seem to be able to *reply*, but if I send mail
I have to use uunet!snerdly!foobar!glortch format.

Dunno why.  Maybe after I get the pc532 up with Minix and uucp all my problems
will be solved.