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

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

This is the debugger (db) I have been writing and using for the last
year on various Minix programs, mostly the kernel. It has worked with
a PC, an AT and a 386 running both DOS and Minix, and a 188 running a
(non-PC) BIOS.

It is safest to unpack this into a temporary directory. Subdirectories
will be made as necessary.

#! /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 1 (of 7)."
# Contents:  bin bin/mungmon commands commands/mung.c kernel
#   kernel/const.h.cdif kernel/db kernel/db/CRCLIST kernel/db/INSTALL
#   kernel/db/README kernel/db/chars.h kernel/db/const.h
#   kernel/db/keyboard.h kernel/db/makefile kernel/db/pcio.c
#   kernel/db/type.h kernel/db/var.h kernel/main.c.cdif
#   kernel/makefile.cdif lib lib/IBM_PC lib/IBM_PC/head.s tools
#   tools/bootblok.s.cdi
# Wrapped by sys@besplex on Sat Nov 26 06:00:08 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test ! -d 'bin' ; then
    echo shar: Creating directory \"'bin'\"
    mkdir 'bin'
fi
if test -f 'bin/mungmon' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'bin/mungmon'\"
else
echo shar: Extracting \"'bin/mungmon'\" \(97 characters\)
sed "s/^X//" >'bin/mungmon' <<'END_OF_FILE'
Xtemp=/usr/tmp/$1
Xcp $1 $temp
Xmung $temp 36 67
Xmung $temp 37 67
Xmung $temp 38 204
Xchmod a+x $temp
END_OF_FILE
if test 97 -ne `wc -c <'bin/mungmon'`; then
    echo shar: \"'bin/mungmon'\" unpacked with wrong size!
fi
chmod +x 'bin/mungmon'
# end of 'bin/mungmon'
fi
if test ! -d 'commands' ; then
    echo shar: Creating directory \"'commands'\"
    mkdir 'commands'
fi
if test -f 'commands/mung.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'commands/mung.c'\"
else
echo shar: Extracting \"'commands/mung.c'\" \(759 characters\)
sed "s/^X//" >'commands/mung.c' <<'END_OF_FILE'
X/* mung.c - write 1 byte in the middle of an existing file */
X
X#include <stdio.h>
X
Xlong atol();
Xlong lseek();
X
Xmain( argc, argv )
Xint argc;
Xchar **argv;
X{
X	char buf[1];
X	int fd;
X	long pos;
X
X	if ( argc != 4 )
X	{
X		printf( "Usage: %s file offset byte\n", argv[0] );
X		exit( 1 );
X	}
X	if ( (fd = open( argv[1], 2 )) < 0 )
X	{
X		printf( "%s: can't open %s\n", argv[0], argv[1] );
X		exit( 1 );
X	}
X	pos = atol( argv[2] );
X	if ( lseek( fd, pos, 0 ) != pos )
X	{
X		printf( "%s: can't seek in %s\n", argv[0], argv[1] );
X		exit( 1 );
X	}
X	buf[0] = atoi( argv[3] );
X	if ( write( fd, buf, 1 ) != 1 )
X	{
X		printf( "%s: can't write to %s\n", argv[0], argv[1] );
X		exit( 1 );
X	}
X	if ( close( fd ) < 0 )
X	{
X		printf( "%s: can't close %s\n", argv[0], argv[1] );
X		exit( 1 );
X	}
X}
END_OF_FILE
if test 759 -ne `wc -c <'commands/mung.c'`; then
    echo shar: \"'commands/mung.c'\" unpacked with wrong size!
fi
# end of 'commands/mung.c'
fi
if test ! -d 'kernel' ; then
    echo shar: Creating directory \"'kernel'\"
    mkdir 'kernel'
fi
if test -f 'kernel/const.h.cdif' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kernel/const.h.cdif'\"
else
echo shar: Extracting \"'kernel/const.h.cdif'\" \(375 characters\)
sed "s/^X//" >'kernel/const.h.cdif' <<'END_OF_FILE'
X*** orig/const.h	Thu Oct  6 21:07:12 1988
X--- const.h	Sun Nov 20 22:17:23 1988
X***************
X*** 6,8 ****
X  #define INIT_PSW      0x0200	/* initial psw */
X! #define INIT_SP (int*)0x0010	/* initial sp: 3 words pushed by kernel */
X  
X--- 6,8 ----
X  #define INIT_PSW      0x0200	/* initial psw */
X! #define INIT_SP (int*)0x001C	/* initial sp: see lib/head.s for details */
X  
END_OF_FILE
if test 375 -ne `wc -c <'kernel/const.h.cdif'`; then
    echo shar: \"'kernel/const.h.cdif'\" unpacked with wrong size!
fi
# end of 'kernel/const.h.cdif'
fi
if test ! -d 'kernel/db' ; then
    echo shar: Creating directory \"'kernel/db'\"
    mkdir 'kernel/db'
fi
if test -f 'kernel/db/CRCLIST' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kernel/db/CRCLIST'\"
else
echo shar: Extracting \"'kernel/db/CRCLIST'\" \(905 characters\)
sed "s/^X//" >'kernel/db/CRCLIST' <<'END_OF_FILE'
X47528     97 bin/mungmon
X54224    759 commands/mung.c
X31566   4764 kernel/console.c.cdif
X02612    375 kernel/const.h.cdif
X10650   1024 kernel/main.c.cdif
X23980    788 kernel/makefile.cdif
X18186   5195 kernel/mpx88.s.cdif
X40793   3429 kernel/db/README
X22672   2562 kernel/db/INSTALL
X58497   1359 kernel/db/chars.h
X31074   1761 kernel/db/const.h
X41897  17761 kernel/db/db.c
X35539   5915 kernel/db/db.doc
X43029   4216 kernel/db/getline.c
X25377   6686 kernel/db/int88.s
X34833   6668 kernel/db/int88dos.s
X23940  11682 kernel/db/io.c
X47350  10418 kernel/db/keyboard.c
X16770   1421 kernel/db/keyboard.h
X59253  12769 kernel/db/lib88.s
X25948    910 kernel/db/makefile
X17408   2583 kernel/db/pcio.c
X55311   7256 kernel/db/sym.c
X49713   2526 kernel/db/type.h
X54900  24851 kernel/db/unasm.c
X29775    161 kernel/db/var.h
X21793    842 lib/IBM_PC/head.s
X60315    581 tools/bootblok.s.cdi
X37316  10647 tools/build.c.cdif
END_OF_FILE
if test 905 -ne `wc -c <'kernel/db/CRCLIST'`; then
    echo shar: \"'kernel/db/CRCLIST'\" unpacked with wrong size!
fi
# end of 'kernel/db/CRCLIST'
fi
if test -f 'kernel/db/INSTALL' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kernel/db/INSTALL'\"
else
echo shar: Extracting \"'kernel/db/INSTALL'\" \(2562 characters\)
sed "s/^X//" >'kernel/db/INSTALL' <<'END_OF_FILE'
X(1) Use a temporary directory to unpack the shars. Subdirectories bin,
Xcommands, kernel, kernel/db, lib, lib/IBM_PC and tools will be created
Xif necessary.
X
X(2) Move the db subdirectory the real kernel and cd to it.
X
X(3) Make db.com. This makes a DOS version of db which can be tried out
Ximmediately. The DOS version is much simpler to make because it can use
Xbetter documented hooks into the system and doesn't implement symbol
Xtables. It is a TSR program with hotkey CTRL-ALT-LEFTSHIFT. Run it and
Xtry the hotkey and ESC a few times. This had better work or the
Xinstallation is not worth proceeding with. DOS's above 3.0 at least are
Xreentrant enough to give no trouble.
X
X(4) Make. This compiles the db files not used in the DOS version.
X
X(5) Move up to the kernel directory and move all the kernel files from
Xthe temporary directory. Apply the diffs for console.c and makefile only.
X(You can apply all the diffs discussed below if you want. The step by
Xstep approach is to show the dependencies and make things simpler if
Xsomething goes wrong.) The diffs are relative to 1.3c. Older versions
Xwill need minor editing. Re-make the kernel. Note it is _much_ bigger
Xand has to be separate I&D.
X
X(6) Boot with the new kernel. Everything should be as usual except the F10
Xkey should enter db and the big kernel may leave too little space for some
Xprograms. A RAM disk inside 640K can't really be afforded with db. Try F10
Xand ESC a few times. db should be fully operational now except no symbol
Xtables have been loaded, save() and restart() can't be traced, and initial
Xentry via F10 is essential for correct initialization.
X
X(7) Replace head.s in the appropiate lib directory and/or lib/IBM_PC, and
Xrecompile mm, fs and init. This just gives them the necessary extra initial
Xstack space and they remain compatible with old kernels. Put symbols tables
Xin them at the same time, like the new kernel makefile does it.
X
X(8) Patch kernel/const.h. Make -t so everything doesn't get recompiled.
XPatch kernel/main.c and kernel/mpx88.s. Re-make the kernel.
X
X(9) Try out the new kernel. Everything should be safe now but there are
Xno symbols.
X
X(10) Patch tools/bootblok.s and tools/build.c and make bootblok and build.
XUse the new build to make an image with symbols.
X
X(11) Try out the new kernel. Inspect the symbol tables for each piece of
Xthe system.
X
X(12) Compile commands/mung.c and put the resulting mung with mungmon in
X/usr/bin. These are used to put a breakpoint early in a user program. Try
Xthis. mungmon may need editing to put the binary elsewhere than/usr/tmp.
END_OF_FILE
if test 2562 -ne `wc -c <'kernel/db/INSTALL'`; then
    echo shar: \"'kernel/db/INSTALL'\" unpacked with wrong size!
fi
# end of 'kernel/db/INSTALL'
fi
if test -f 'kernel/db/README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kernel/db/README'\"
else
echo shar: Extracting \"'kernel/db/README'\" \(3429 characters\)
sed "s/^X//" >'kernel/db/README' <<'END_OF_FILE'
X			db Version 1.0
X		Copyright (c) 1988, Bruce Evans
X
XThis software may be copied and redistributed provided you don't try to
Xmake money off it and this sentence is included and remains effective.
X
XThis is the debugger (db) I have been writing and using for the last
Xyear on various Minix programs, mostly the kernel. It has worked with
Xa PC, an AT and a 386 running both DOS and Minix, and a 188 running a
X(non-PC) BIOS.
X
XIt is written to be almost independent of the system it is running on.
XThis rules out all i/o through the file system and makes it impractical
Xto debug at source level. Symbol tables for the system files can be
Xloaded at boot time.
X
XThere are a couple of things here which may be useful outside of db.
Xgetline() is a line editor, far better than the one in the shell
X(really the kernel). parsecode() is a PC scan code converter which was
Xoriginally supposed to be faster and simpler than the one in the console
Xdriver (by being table driven). Unfortunately, making it _correct_ led
Xto lots of complications (the escape sequences for the AT keyboard are
Xawful). puti() is a disassembler which handles 8087 and 80386 as well
Xas 8086 code. It is based on the one in adb for Minix posted by Don
XDugger. It is much smaller than dis88.
X
XThere is some support for 386 protected mode, not all included. db
Xitself only works in real mode.
X
XAlthough db is almost independent of Minix, a number of system files
Xneed to be changed for best performance and safety.
X
Xkernel/console.c: This needs a hot key to call db. F10 is used. To let
Xdb use the debugging routines already in the kernel, the putc routine
Xis vectorized. The usual console putc routine cannot be trusted and
Xwould print on the wrong screen. A worse problem is saving and restoring
Xthe video state. This is done, for text mode only, at the expense of
Xputting information functions into console.c (CGA/EGA hardware won't say).
XA better way would be to move all debugging stuff, such as in dmp.c and
Xpanics, into db. The console driver could be built on top of db to
Xsave space.
X
Xkernel/const.h and lib/IBM_PC/head.s: The initial stack given to FS was
Xtoo small. It was too small for separate I&D even without db!
X
Xkernel/makefile: Call the new one makefile.db. Note that the db directory
Xhas to be made separately. I don't know a good way to do this in the
Xmakefile.
X
Xkernel/main.c: This needs to call db at panics and other critical points.
XIt also initializes the breakpoint interrupt. This merely avoids getting
Xa trap message from the kernel since all traps are terminated with a call
Xto db.
X
Xkernel/mpx88.s: The save()/restart() code had to be rewritten because it
Xwas non-reentrant and couldn't be traced (it points the stack in the
Xproc table :-(). The stack instructions are faster but the code was so
Xtangled up that more straightforward code is both shorter and faster,
Xespecially on AT's where instruction timings are bunched closer.
X
Xtools/bootblok.s: The relocation of the boot block failed for images
Xlarger than 192K.
X
Xtools/build.c: This is enhanced to load symbol tables. I have 3 different
Xways to boot and the one through build is the least preferred (others
Xare too large and/or messy to post here). So I converted build.c by
Xadding pieces of another program. It seems OK but hasn't been used much.
XIt is a difficult program to modify because of too much duplicated code.
XThis build.c also has #ifdef's to handle 16 bit Xenix headers.
END_OF_FILE
if test 3429 -ne `wc -c <'kernel/db/README'`; then
    echo shar: \"'kernel/db/README'\" unpacked with wrong size!
fi
# end of 'kernel/db/README'
fi
if test -f 'kernel/db/chars.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kernel/db/chars.h'\"
else
echo shar: Extracting \"'kernel/db/chars.h'\" \(1359 characters\)
sed "s/^X//" >'kernel/db/chars.h' <<'END_OF_FILE'
X/* chars.h */
X
X/* extended character codes for special PC keys */
X
X#define CLEFTARROW 0x7300
X#define CPGUP 0x8400
X#define CRIGHTARROW 0x7400
X#define HOME 0x4700
X#define DEL 0x5300
X#define DOWNARROW 0x5000
X#define CPGDN 0x7600
X#define END 0x4f00
X#define F1 0x3b00
X#define F2 0x3c00
X#define F3 0x3d00
X#define F4 0x3e00
X#define F5 0x3f00
X#define F6 0x4000
X#define F7 0x4100
X#define F8 0x4200
X#define F9 0x4300
X#define F10 0x4400
X#define INS 0x5200
X#define LEFTARROW 0x4b00
X#define PGDN 0x5100
X#define PGUP 0x4900
X#define RIGHTARROW 0x4d00
X#define UPARROW 0x4800
X
X#define ETOA( c ) (((unsigned) ((c) - FIRST_EXTENDED_CHAR) >> 8) + 0x80)
X#define FIRST_EXTENDED_CHAR 0x3b00
X
X/* general editing keys */
X
X#define ASCII_DEL 127
X#define BACKSPACE1 8
X#define DEL1 7              /* ^G */
X#define DEL2 ASCII_DEL
X#define DOWN1 24            /* ^X */
X#define DOWN2 DOWNARROW
X#define END1 18             /* ^R */
X#define END2 END
X#define ESCAPE 27
X#define INS1 22             /* ^V */
X#define INS2 INS
X#define LEFT1 19            /* ^S */
X#define LEFT2 LEFTARROW
X#define RIGHT1 4            /* ^D */
X#define RIGHT2 RIGHTARROW
X#define START1 23           /* ^W */
X#define START2 HOME
X#define UP1 5               /* ^E */
X#define UP2 UPARROW
X#define WORDLEFT1 1         /* ^A */
X#define WORDLEFT2 CLEFTARROW
X#define WORDRIGHT1 6        /* ^F */
X#define WORDRIGHT2 CRIGHTARROW
END_OF_FILE
if test 1359 -ne `wc -c <'kernel/db/chars.h'`; then
    echo shar: \"'kernel/db/chars.h'\" unpacked with wrong size!
fi
# end of 'kernel/db/chars.h'
fi
if test -f 'kernel/db/const.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kernel/db/const.h'\"
else
echo shar: Extracting \"'kernel/db/const.h'\" \(1761 characters\)
sed "s/^X//" >'kernel/db/const.h' <<'END_OF_FILE'
X/* const.h - constants for db */
X
X/* general constants */
X
X#define FALSE 0
X#define NULL  0
X#define TRUE  1
X
X/* C tricks */
X
X#define EXTERN  extern
X#define FORWARD
X#define PRIVATE static
X#define PUBLIC
X
X/* ASCII codes */
X
X#define CAN  24
X#define CR   13
X#define EOF  (-1)
X#define LF   10
X#define XOFF 19
X
X/* hardware processor-specific for 8088 through 80386 */
X
X#define CLICK_SIZE     0x10
X#define IF           0x0200     /* interrupt disable bit in flags */
X#define INT_BREAKPOINT 0xcc     /* byte for breakpoint interrupt */
X#define TF           0x0100     /* trap bit in flags */
X
X/* use hardware codes for segments for simplest decoding */
X
X#define CSEG 0x2E               /* 8088 through 80386 */
X#define DSEG 0x3E
X#define ESEG 0x26
X#define FSEG 0x64
X#define GSEG 0x65               /* 80386 only */
X#define SSEG 0x36
X
X/* hardware machine-specific for PC family */
X
X#define I_COMMAND_PORT 0x20     /* interrupt command port (attached to 8259) */
X#  define I_DATA_READY 0x80     /* bit to signal polled data ready */
X#  define I_EOI        0x20     /* bits to signal end of interrupt (or poll) */
X#  define I_KBD           2     /* 2^(interrupt number of keyboard for 8259) */
X#  define I_OCW3          8     /* bit to select OCW3 */
X#  define I_POLL          4     /* bit to select polling in OCW3 */
X#define I_MASK_PORT    0x21     /* interrupt mask port */
X
X/* software machine-specific for PC family */
X
X#define BIOS_DATA_SEG  0x40
X#  define KB_FLAG      0x17     /* offset to 16-bits of keyboard shift flags */
X
X/* switches to handle non-conforming compilers */
X
X#define void int                /* compiler has no void type */
X#define UCHAR_BUG		/* compiler converts unsigned chars wrong */
X
X#ifdef UCHAR_BUG
X#  define UCHAR( x )   ((x) & 0xFF)
X#endif
END_OF_FILE
if test 1761 -ne `wc -c <'kernel/db/const.h'`; then
    echo shar: \"'kernel/db/const.h'\" unpacked with wrong size!
fi
# end of 'kernel/db/const.h'
fi
if test -f 'kernel/db/keyboard.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kernel/db/keyboard.h'\"
else
echo shar: Extracting \"'kernel/db/keyboard.h'\" \(1421 characters\)
sed "s/^X//" >'kernel/db/keyboard.h' <<'END_OF_FILE'
X/* keyboard.h */
X
X/*
X  Shift state bits.
X  Bits (1<<0) to (1<<7) match the BIOS KB_FLAG byte.
X  Bits (1<<11) to (1<<15) match the BIOS KB_FLAG_1.
X  The BIOS HOLD (bit 10) is not supported.
X  New bits for right ALTs and CTRLs.
X  NB  RIGHT_ALT / LEFT_ALT  must equal  RIGHT_CTRL / LEFT_CTRL.
X      CAPS_SHIFT / CAPS_LOCK  must equal  INS_SHIFT / INS_LOCK
X      and also the NUM and SCROLL ratios.
X*/
X
X#define RIGHT_ALT    (1<<9)     /* new */
X#define RIGHT_CTRL   (1<<8)     /* new */
X
X#define CAPS_SHIFT   (1<<14)
X#define CAPS_LOCK    (1<<6)
X#define INS_SHIFT    (1<<15)
X#define INS_LOCK     (1<<7)
X#define LEFT_ALT     (1<<3)
X#define LEFT_CTRL    (1<<2)
X#define LEFT_SHIFT   (1<<1)
X#define NUM_SHIFT    (1<<13)
X#define NUM_LOCK     (1<<5)
X#define RIGHT_SHIFT  (1<<0)
X#define SCROLL_SHIFT (1<<12)
X#define SCROLL_LOCK  (1<<4)
X
X/* area numbers, 0 is normal */
X
X#define CKEY          3         /* separate cursor key */
X#define FKEY          6         /* function key */
X#define NKEY         14         /* numeric keypad */
X#define OKEY         15         /* other */
X#define RKEY         18         /* key release */
X
Xtypedef unsigned char area_t;
Xtypedef unsigned scancode_pt;
Xtypedef unsigned shift_pt;
Xtypedef unsigned short shift_t;
X
Xstruct echar_s
X{
X  area_t area;
X  unsigned char ch;             /* unsigned for special ASCII comparisons */
X  shift_pt shift;
X  unsigned state;
X};
X
XFORWARD scancode_pt scan_keyboard();
END_OF_FILE
if test 1421 -ne `wc -c <'kernel/db/keyboard.h'`; then
    echo shar: \"'kernel/db/keyboard.h'\" unpacked with wrong size!
fi
# end of 'kernel/db/keyboard.h'
fi
if test -f 'kernel/db/makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kernel/db/makefile'\"
else
echo shar: Extracting \"'kernel/db/makefile'\" \(910 characters\)
sed "s/^X//" >'kernel/db/makefile' <<'END_OF_FILE'
XCFLAGS =
XEND = /usr/lib/end.s
XLD = asld
XLDFLAGS =
XLINTFLAGS = -a -b -h -n -u -x -DLINT -DUNUSED_FUNCTIONS
XLIBS = /usr/lib/libc.a
X
XCSRCS = db.c getline.c io.c keyboard.c pcio.c sym.c unasm.c
X
XDOSOBJS = int88dos.s dbdos.s
XMINOBJS = int88.s db.s sym.s
XOBJS = getline.s io.s keyboard.s lib88.s pcio.s unasm.s
X
Xminobjs: $(MINOBJS) $(OBJS)
X
Xall: minobjs db.com
X
Xdb.com: $(DOSOBJS) $(OBJS)
X	$(LD) $(LDFLAGS) $(DOSOBJS) $(OBJS) $(LIBS) $(END) -s >db.sym
X	dd if=a.out of=db.com bs=288 skip=1
X	rm a.out
X
Xlint:
X	lint $(LINTFLAGS) $(CSRCS)
X
Xdb.s: const.h type.h chars.h var.h
Xdbdos.s: db.c const.h type.h chars.h var.h
X	cp db.c dbdos.c
X	$(CC) -DDOS $(CFLAGS) -S dbdos.c
X	rm dbdos.c
Xgetline.s: const.h type.h chars.h var.h
Xio.s: const.h type.h var.h
Xkeyboard.s: const.h keyboard.h
Xpcio.s: const.h type.h keyboard.h chars.h
Xsym.s: const.h type.h var.h /usr/include/a.out.h
Xunasm.s: const.h type.h var.h /usr/include/a.out.h
END_OF_FILE
if test 910 -ne `wc -c <'kernel/db/makefile'`; then
    echo shar: \"'kernel/db/makefile'\" unpacked with wrong size!
fi
# end of 'kernel/db/makefile'
fi
if test -f 'kernel/db/pcio.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kernel/db/pcio.c'\"
else
echo shar: Extracting \"'kernel/db/pcio.c'\" \(2583 characters\)
sed "s/^X//" >'kernel/db/pcio.c' <<'END_OF_FILE'
X/* pcio.c */
X
X#include "const.h"
X#include "type.h"
X#include "keyboard.h"
X#include "chars.h"
X
XPUBLIC void kbdclose()
X{
X  /* turn off BIOS CTRL-ALT-LEFT_SHIFT since we stole the key release codes */
X  pokeb( BIOS_DATA_SEG, KB_FLAG, peekb( BIOS_DATA_SEG, KB_FLAG ) &
X                                 ~(LEFT_SHIFT | LEFT_CTRL | LEFT_ALT) );
X}
X
X/*
X  Input char from keyboard, return EOF if none.
X  Interrupts must be off when this is called.
X  The complexity and machine-dependency of kbdin compared with ttyin
X  is most annoying.
X*/
X
XPUBLIC char_pt kbdin()
X{
X  char_pt ch;
X  static struct echar_s ech;
X  u8_pt old_i_mask;
X
X  /* Clear any unacknowledged interrupt. Unfortunate effect on int handlers? */
X  oportb( I_COMMAND_PORT, I_EOI );
X
X  /* put interrupt controller in polling mode */
X  old_i_mask = inportb( I_MASK_PORT );
X  oportb( I_COMMAND_PORT, I_OCW3 | I_POLL );
X
X  /* allow keyboard poll (only) */
X  oportb( I_MASK_PORT, ~I_KBD );
X
X  /* prepare for no data */
X  ch = EOF;
X
X  /* do the poll (this simultaneously disables further polling */
X  if ( inportb( I_COMMAND_PORT ) & I_DATA_READY )
X  {
X    /* got a key, process it as for the interrupt routines */
X    parsecode( scan_keyboard(), &ech );
X
X    /*
X      Reenable interrupt controller (what a pain).
X      This is not done by keyboard() which relies on a centralized reenable.
X    */
X    oportb( I_COMMAND_PORT, I_EOI );
X
X    /* do some conversions to make it look like a PC BIOS key */
X    if ( ech.area != RKEY )
X    {
X      if ( (ch = ech.ch) == ASCII_DEL && ech.shift & (LEFT_CTRL | RIGHT_CTRL)
X           && ech.shift & (LEFT_ALT | RIGHT_ALT) )
X        reboot();
X      if ( ech.area == FKEY && ch <= 'J' )
X        ch = (ch + (59 - 'A')) << 8;
X      else if ( ech.area == CKEY || ech.area == NKEY )
X        switch( ch )
X        {
X        case '2': ch = DOWNARROW; break;
X        case '1': ch = END; break;
X        case '7': ch = HOME; break;
X	case '0': ch = INS; break;
X        case '4':
X          ch = LEFTARROW;
X          if ( ech.shift & (LEFT_CTRL | RIGHT_CTRL) )
X            ch = CLEFTARROW;
X          break;
X        case '6':
X          ch = RIGHTARROW;
X          if ( ech.shift & (LEFT_CTRL | RIGHT_CTRL) )
X            ch = CRIGHTARROW;
X          break;
X        case '8': ch = UPARROW; break;
X        }
X    }
X  }
X  /* restore mask */
X  oportb( I_MASK_PORT, old_i_mask );
X
X  return ch;
X}
X
X/* ARGSUSED */
XPUBLIC void kbdioctl( command )
Xint command;
X{
X}
X
XPUBLIC void kbdopen()
X{
X  /* stop keyboard hanging when keyboard interrupt is traced */
X  scan_keyboard();
X}
X
X/* ARGSUSED */
XPUBLIC void kbdout( c )
Xint c;
X{
X}
END_OF_FILE
if test 2583 -ne `wc -c <'kernel/db/pcio.c'`; then
    echo shar: \"'kernel/db/pcio.c'\" unpacked with wrong size!
fi
# end of 'kernel/db/pcio.c'
fi
if test -f 'kernel/db/type.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kernel/db/type.h'\"
else
echo shar: Extracting \"'kernel/db/type.h'\" \(2526 characters\)
sed "s/^X//" >'kernel/db/type.h' <<'END_OF_FILE'
X/* type.h - types for db */
X
Xtypedef unsigned long bigcount_t;
Xtypedef unsigned long flags_t;
Xtypedef int bool_pt;
Xtypedef char bool_t;
Xtypedef int char_pt;
Xtypedef int char16_t;           /* ASCII character possibly with scan code */
Xtypedef unsigned count_t;
Xtypedef unsigned long offset_t;
Xtypedef unsigned opcode_pt;     /* promote to unsigned and not int */
Xtypedef int (*pfi_t)();
Xtypedef void (*pfv_t)();
Xtypedef unsigned long physoff_t;
Xtypedef unsigned peekboff_t;
Xtypedef unsigned peekoff_t;
Xtypedef int peekseg_t;
Xtypedef unsigned port_t;
Xtypedef int reg_pt;
Xtypedef unsigned char reg_t;
Xtypedef unsigned segment_t;
Xtypedef long soffset_t;
Xtypedef unsigned u4_pt;         /* promote to unsigned and not int */
Xtypedef unsigned char u8_t;
Xtypedef unsigned u8_pt;
Xtypedef unsigned u16_t;
Xtypedef unsigned long u32_t;
X
Xstruct adr
X{
X	offset_t off;
X	segment_t seg;
X};
X
Xstruct regs
X{
X	offset_t ax;
X	offset_t bx;
X	offset_t cx;
X	offset_t dx;
X	offset_t si;
X	offset_t di;
X	offset_t bp;
X	segment_t ds;
X	segment_t es;
X	offset_t sp;
X	segment_t ss;
X	offset_t ip;
X	segment_t cs;
X	flags_t f;
X};
X
X/* these functions are defined in assembler */
X
XFORWARD segment_t codeseg();
XFORWARD segment_t dataseg();		/* may be obsolete */
XFORWARD unsigned get_processor();	/* used by asm routines only */
XFORWARD u8_pt inportb();
XFORWARD void oportb();
XFORWARD u8_pt peek8();
XFORWARD u8_pt peekb();
XFORWARD u16_t peek16();
XFORWARD u16_t peekw();
XFORWARD u32_t peek32();
XFORWARD void poke8();
XFORWARD void pokeb();
XFORWARD void poke16();
XFORWARD void pokew();			/* may be obsolete */
XFORWARD void poke32();
XFORWARD void scrclose();
XFORWARD char_pt scrin();
XFORWARD void scrioctl();
XFORWARD void scropen();
XFORWARD void scrout();
XFORWARD void symswap();
XFORWARD void ttyclose();
XFORWARD char_pt ttyin();
XFORWARD void ttyioctl();
XFORWARD void ttyopen();
XFORWARD void ttyout();
X
X/* these functions are defined in C (int functions are NOT declared here) */
X
XFORWARD struct nlist *findsname();
XFORWARD struct nlist *findsval();
XFORWARD u8_pt get8();
XFORWARD u16_t get16();
XFORWARD u32_t get32();
XFORWARD char *getline();
XFORWARD void kbdclose();
XFORWARD char_pt kbdin();
XFORWARD void kbdioctl();
XFORWARD void kbdopen();
XFORWARD void kbdout();
XFORWARD count_t stringtab();
X
X/* these are the ONLY library functions used (apart from low level arith) */
X
XFORWARD char *memcpy();
XFORWARD int strlen();
X
X/* these Minix kernel functions are used */
X
XFORWARD void get_con_state();
XFORWARD void map_dmp();
XFORWARD void p_dmp();
XFORWARD void reset_con_state();
END_OF_FILE
if test 2526 -ne `wc -c <'kernel/db/type.h'`; then
    echo shar: \"'kernel/db/type.h'\" unpacked with wrong size!
fi
# end of 'kernel/db/type.h'
fi
if test -f 'kernel/db/var.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kernel/db/var.h'\"
else
echo shar: Extracting \"'kernel/db/var.h'\" \(161 characters\)
sed "s/^X//" >'kernel/db/var.h' <<'END_OF_FILE'
X/* var.h - variables for monitor */
X
XEXTERN bool_t bits32;
XEXTERN unsigned db_processor;
XEXTERN char_pt prompt;
XEXTERN bool_t protected;
XEXTERN struct adr uptr;
END_OF_FILE
if test 161 -ne `wc -c <'kernel/db/var.h'`; then
    echo shar: \"'kernel/db/var.h'\" unpacked with wrong size!
fi
# end of 'kernel/db/var.h'
fi
if test -f 'kernel/main.c.cdif' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kernel/main.c.cdif'\"
else
echo shar: Extracting \"'kernel/main.c.cdif'\" \(1024 characters\)
sed "s/^X//" >'kernel/main.c.cdif' <<'END_OF_FILE'
X*** orig/main.c	Thu Oct  6 21:07:39 1988
X--- main.c	Sun Nov 20 19:10:48 1988
X***************
X*** 70,71 ****
X--- 70,75 ----
X  
X+ #ifdef DEBUG_STARTUP
X+   db();
X+ #endif
X+ 
X  #ifdef AM_KERNEL
X***************
X*** 159,160 ****
X--- 163,167 ----
X  
X+ #ifdef DEBUGGER
X+   dbinit();
X+ #endif
X    set_vec(SYS_VECTOR, s_call, base_click);
X***************
X*** 197,198 ****
X--- 204,208 ----
X    /* Now go to the assembly code to start running the current process. */
X+ #ifdef DEBUG_RESTART
X+   db();
X+ #endif
X    restart();
X***************
X*** 218,219 ****
X--- 228,233 ----
X  					proc_ptr->p_map[D].mem_len<<4);
X+ #ifdef DEBUGGER
X+   if (vecnr != DIVIDE_VECTOR)	/* should be unnecessary, all should signal */
X+ 	db();
X+ #endif
X  }
X***************
X*** 233,234 ****
X--- 247,251 ----
X    printf("library routine that is trying to make a system call.\n");
X+ #ifdef DEBUGGER
X+   db();
X+ #endif
X  }
X***************
X*** 255,256 ****
X--- 272,276 ----
X    printf("\nType space to reboot\n");
X+ #ifdef DEBUGGER
X+   db();
X+ #endif
X    wreboot();
END_OF_FILE
if test 1024 -ne `wc -c <'kernel/main.c.cdif'`; then
    echo shar: \"'kernel/main.c.cdif'\" unpacked with wrong size!
fi
# end of 'kernel/main.c.cdif'
fi
if test -f 'kernel/makefile.cdif' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kernel/makefile.cdif'\"
else
echo shar: Extracting \"'kernel/makefile.cdif'\" \(788 characters\)
sed "s/^X//" >'kernel/makefile.cdif' <<'END_OF_FILE'
X*** orig/makefile	Fri Oct  7 21:00:27 1988
X--- makefile	Tue Nov 22 02:48:41 1988
X***************
X*** 13,15 ****
X  #
X! CFLAGS= -Di8088 -F -T.
X  h=../h
X--- 13,15 ----
X  #
X! CFLAGS= -Di8088 -F -T. -DDEBUGGER # -DDEBUG_STARTUP -DDEBUG_RESTART
X  h=../h
X***************
X*** 23,27 ****
X  
X! kernel:	makefile $(obj) $l/libc.a
X! 	@echo "Start linking Kernel."
X! 	@asld -o kernel -T. $(obj) $l/libc.a $l/end.s
X  	@echo "Kernel done.  "
X--- 23,32 ----
X  
X! dbobjs = db/int88.s db/db.s db/getline.s db/io.s db/keyboard.s db/lib88.s \
X! 	db/pcio.s db/sym.s db/unasm.s
X! 
X! kernel:	makefile $(obj) $(dbobjs) $l/libc.a
X! 	@echo "Start linking Kernel."
X! 	@asld -i -o kernel -T. $(obj) $(dbobjs) $l/libc.a $l/end.s -s > kernel.sym
X! 	@ast -X kernel kernel.sym
X! 	@rm kernel.sym
X  	@echo "Kernel done.  "
END_OF_FILE
if test 788 -ne `wc -c <'kernel/makefile.cdif'`; then
    echo shar: \"'kernel/makefile.cdif'\" unpacked with wrong size!
fi
# end of 'kernel/makefile.cdif'
fi
if test ! -d 'lib' ; then
    echo shar: Creating directory \"'lib'\"
    mkdir 'lib'
fi
if test ! -d 'lib/IBM_PC' ; then
    echo shar: Creating directory \"'lib/IBM_PC'\"
    mkdir 'lib/IBM_PC'
fi
if test -f 'lib/IBM_PC/head.s' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'lib/IBM_PC/head.s'\"
else
echo shar: Extracting \"'lib/IBM_PC/head.s'\" \(842 characters\)
sed "s/^X//" >'lib/IBM_PC/head.s' <<'END_OF_FILE'
X.globl _main, _stackpt, begtext, begdata, begbss, _data_org, _exit
X.text
Xbegtext:
X	jmp L0
X	.zerow 13		| stack for inital IRET when common I&D
X				| also padding to make INIT_SP same as
X				| for separate I&D
XL0:	mov sp,_stackpt
X	call _main
XL1:	jmp L1			| this will never be executed
X_exit:	jmp _exit		| this will never be executed either
X.data
Xbegdata:
X_data_org:			| fs needs to know where build stuffed table
X.word 0xDADA			| magic number for build
X.word 0				| spare
X.word 0,0,0			| used by FS only for sizes of init
X				| stack for separate I&D follows
X.word 0,0,0			| for ip:ss:f pushed by debugger traps
X.word 0,0,0			| for cs:ds:ret adr in save()
X				| this was missing - a bug as late as V1.3c
X				| for ds for new restart() as well
X.word 0,0,0			| for ip:ss:f built by restart()
X				| so INIT_SP in const.h must be 0x1C
X.bss
Xbegbss:
END_OF_FILE
if test 842 -ne `wc -c <'lib/IBM_PC/head.s'`; then
    echo shar: \"'lib/IBM_PC/head.s'\" unpacked with wrong size!
fi
# end of 'lib/IBM_PC/head.s'
fi
if test ! -d 'tools' ; then
    echo shar: Creating directory \"'tools'\"
    mkdir 'tools'
fi
if test -f 'tools/bootblok.s.cdi' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'tools/bootblok.s.cdi'\"
else
echo shar: Extracting \"'tools/bootblok.s.cdi'\" \(581 characters\)
sed "s/^X//" >'tools/bootblok.s.cdi' <<'END_OF_FILE'
X*** orig/bootblok.s	Sat Oct 29 06:11:26 1988
X--- bootblok.s	Mon Nov 21 21:39:41 1988
X***************
X*** 24,26 ****
X          BIOSSEG = 0x07C0         | here the boot block itself is loaded
X!         BOOTSEG = 0x2FE0         | here it will copy itself (192K-512b)
X          DSKBASE = 120            | 120 = 4 * 0x1E = ptr to disk parameters
X--- 24,26 ----
X          BIOSSEG = 0x07C0         | here the boot block itself is loaded
X!         BOOTSEG = 0x7FE0         | here it will copy itself (512K-512b)
X          DSKBASE = 120            | 120 = 4 * 0x1E = ptr to disk parameters
END_OF_FILE
if test 581 -ne `wc -c <'tools/bootblok.s.cdi'`; then
    echo shar: \"'tools/bootblok.s.cdi'\" unpacked with wrong size!
fi
# end of 'tools/bootblok.s.cdi'
fi
echo shar: End of archive 1 \(of 7\).
cp /dev/null ark1isdone
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