BOOTMENU and PFDISK 1.3 (part 2/2)

Gordon W. Ross gwr at world.std.com
Sat Mar 9 11:25:21 AEST 1991


[ This was sent to comp.sources.misc on 23 Oct 90 but I hear
  that it never came out.   How can I get this archived? - gwr ]

Here is part 2 of the BOOTMENU and PFDISK 1.3 distribution.

See the README file at the beginning of part 1 for a general
description of this package.  Program documentation for both
BOOTMENU and PFDISK are at the beginning of the shar file below.

#! /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 shell archive."
# Contents:  bootmenu.doc pfdisk.doc SStor.txt bootmenu.asm
#   bootauto.asm asm2bin.bat make_msc.bat bootmenu.hex bootauto.hex
#   hex2bin.c
# Wrapped by gwr at world on Fri Mar  8 20:24:44 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f bootmenu.doc -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"bootmenu.doc\"
else
echo shar: Extracting \"bootmenu.doc\" \(3921 characters\)
sed "s/^X//" >bootmenu.doc <<'END_OF_bootmenu.doc'
X
X	BOOTMENU -- a BOOT sector program with a MENU
X	---------------------------------------------
X		by Gordon W. Ross, Aug 1990
X
X	This program is loaded by the PC ROM BIOS and is responsible
X	for selecting one of four partitions to boot from.  The normal
X	(MS-DOS) version of this program always boots the "active"
X	partition, but this version allows any partition to be
X	selected for booting, wether marked "active" or not.
X
X	Two versions of this program are now distributed:
X
X	BOOTMENU is small (less than 256 bytes of code) and compatible
X	with the SpeedStor hard disk formatting package.  (Note that
X	SpeedStor writes in several locations in the boot sector!)
X	This version, however, does not allow unattended reboots.
X	After BOOTMENU displays its partition menu, it waits
X	indefinitely for someone to select a boot partition.
X
X	BOOTAUTO (previously called "boot-hdp") is a full-featured
X	boot program which allows boot-time partition selection, but
X	also provides a default selection which is used if no user
X	input arrives within five seconds.
X
X	The behaviour of BOOTAUTO is as follows:
X
X	BOOTAUTO displays the message:
X		Booting device: hd0,
X	and then pauses for a five second delay.
X
X	If the user presses any key before the delay expires, a menu
X	of bootable partitions is displayed, and the user is prompted
X	for the number of the partition to boot from.  If no key is
X	pressed before the delay ends, the first partition marked as
X	"active" is used.  If no partition is marked as active, the
X	boot menu is presented without delay, as if a key were struck.
X	In essence, this program interprets the "active" mark (if
X	present) as a default choice indicator.
X
X	Once a partition has been selected this program displays the
X	selected partition number and loads its secondary boot
X	program.  Errors are printed if (1) the selected partition is
X	empty, (2) the secondary boot program lacks a valid signature,
X	or (3) an error occurs while reading the secondary boot sector.
X
X	Installation:
X	------------
X	The "pfdisk" utility included with this program simplifies
X	installation of BOOTAUTO into the primary boot sector.
X	Instructions for using "pfdisk" are in the pfdisk.doc file.
X
X	Limitations:
X	-----------
X	Names in the boot menu:
X
X	BOOTMENU and BOOTAUTO contain a name table that is used to
X	generate the boot menu.  This name table is recognized (using
X	a signature) and updated by pfdisk but not by other fdisk
X	programs. If another fdisk program is used to modify the
X	partition table, the name table may be left with misleading
X	entries.  Note that pfdisk only updates the name field for any
X	entry when the entry is set using the optional name field, i.e:
X
X		pfdisk> 1 4 0 127 MS-LOSS
X
X	Furthermore, the name supplied as the fourth arg. is truncated
X	to eight characters.  (Space is tight in the boot sector.)
X
X	The signature which flags the presence of a name table is
X	written into any boot sector every time the name argument is
X	given in a partition setting command (1,2,3,4).  This
X	signature occupies locations 0x1A0 -- 0x1AD which does not
X	clobber anything used by any of: UNIX or DOS boot programs,
X	SpeedStor or WesternDigital Auto-configuring controllers.
X
X	Booting inactive partitions:
X
X	MS-DOS will boot from an inactive partition without needing
X	any modifications.  Unfortunately, some systems refuse to boot
X	from a partition which is not marked as active.
X
X	ESIX (from Everex Systems) Sys.V Rel.3.2 will not (as shipped)
X	boot unless its partition is marked active.  Other versions of
X	Sys.V/386 are similar in this regard.  The easiest solution is
X	to mark the UNIX partition as active, and use BOOTMENU to
X	offer you a choice between DOS and UNIX.
X
X	If you wish, it is also possible to patch UNIX so that it will
X	boot without demanding that its partition be marked active.
X	These patches (called "esix-boot") are available from the
X	author.  Send EMAIL to gwr at world.std.com if you want them.
X
END_OF_bootmenu.doc
if test 3921 -ne `wc -c <bootmenu.doc`; then
    echo shar: \"bootmenu.doc\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f pfdisk.doc -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"pfdisk.doc\"
else
echo shar: Extracting \"pfdisk.doc\" \(6755 characters\)
sed "s/^X//" >pfdisk.doc <<'END_OF_pfdisk.doc'
X
X
X
X
X
XPFDISK(8)	      MAINTENANCE COMMANDS		PFDISK(8)
X
X
X
X
X
XNAME
X	pfdisk - partition fixed disk
X
XSYNOPSIS
X	pfdisk device
X
XDESCRIPTION
X	pfdisk partitions the fixed disk identified as device  into  (at
X	most) four parts, each of which	may be independently loaded with
X	an operating system.  The actual name of device	depends	 on  the
X	operating  system  in  use.   For ESIX (System V/386) the device
X	name is	either "/dev/rdsk/0s0" or "/dev/rdsk/1s0".   For  Minix,
X	it is "/dev/hd0" or "/dev/hd5".	 For MS-DOS it is a single digit
X	(zero or one).
X
X	pfdisk reads the hard disk partition table from	 block	zero  of
X	device	into  memory  and allows the user to examine, modify, or
X	save the partition table.  A regular file may be used instead of
X	a  real	 device	for testing purposes, though the device	geometry
X	must be	specified manually, and	some  systems  will  requrire  a
X	file-name argument with	the "R"	and "W"	commands (DOS, ESIX).
X
X	The partition table on device is NOT modified unless  the  write
X	command	(W) is used with no argument.
X
XUSAGE
X  Commands
X	All pfdisk commands  consist  of  a  command  word  followed  by
X	optional  blank-separated command arguments.  Note that	only the
X	first letter of	a command word is significant (except  for  "wq"
X	and  "q!").  All command letters are accepted in either	upper or
X	lower case.  Numeric arguments are  specified  using  C	 syntax.
X	Extra arguments	are silently ignored.
X
X	The commands are:
X
X	?	Prints a command summary (help).
X
X	1 sys_id first last sys_name
X		Set the	partition  table  entry	 for  part  one,  using:
X		sys_id	as  its	system ID code,	first as the lowest num-
X		bered cylinder it uses,	last  as  the  highest	numbered
X		cylinder  it uses, and sys_name	(optional) as the system
X		name (in the menu name table).
X
X	2|3|4 sys-id first last	sys-name
X		Similar	to 1 but sets partition	 two,  three,  or  four,
X		respectively.
X
X
X
X
X
XRelease	1.3	      Last change: Oct 1990			1
X
X
X
X
X
X
XPFDISK(8)	      MAINTENANCE COMMANDS		PFDISK(8)
X
X
X
X
X
X	A number
X		Mark partition number as active	(so it will be used  for
X		booting).   If	number	is  zero,  no  partition will be
X		active.
X
X	G cylinders heads sectors
X		Inform pfdisk what the geometry	of the device is.
X
X	I	Print a	summary	of the known ID	codes.
X
X	L	List the partition table.  See Output Format below.
X
X	Q	Quit without saving.  If the memory copy of  the  parti-
X		tion  table  was  modified, a warning will be issued and
X		the command ignored.
X
X	Q!	Quit, even if the memory copy of the partition table was
X		not saved.
X
X	R file-name
X		Read boot sector from  file-name  (if  given)  otherwise
X		read from device.
X
X	W file-name
X		Write boot sector to  file-name.  (if  given)  otherwise
X		write to device.
X
X	WQ	Same as	"write"	followed by "quit".
X
X	#	This line is a comment (to be ignored).
X
X  Output Format
X	Here is	a sample of the	output from the	L command:
X
X	# Partition table on device: /dev/rdsk/0s0
X	geometry 1222 15 34 (cyls heads	sectors)
X	#  ID  First(cyl)  Last(cyl)  Name     # start,	length (sectors)
X	1   4	   0	    127	      MS-LOSS  # 34, 65246
X	2 129	 128	    255	      Minix    # 65280,	65280
X	3   0	   0	      0		       # 0, 0
X	4  99	 256	   1220	      ESIX     # 130560, 492150
X	# note:	 last(4): phys=(1023,14,34) logical=(1220,14,34)
X	active:	4
X
X	This output format is carefully	constructed so that  it	 may  be
X	saved in a file	 (by redirecting standard output) and later used
X	as input (by redirecting standard input).  On a	UNIX system, one
X	can save this output using the command:
X
X
X
X
X
XRelease	1.3	      Last change: Oct 1990			2
X
X
X
X
X
X
XPFDISK(8)	      MAINTENANCE COMMANDS		PFDISK(8)
X
X
X
X
X
X		(echo L) | pfdisk device-name >	save-file
X
X	save-file is a complete	record of the  partition  table.   On  a
X	UNIX system, one could use save-file to	re-initialize the parti-
X	tion table using the command:
X
X		(cat save-file ; echo wq) | pfdisk device-name
X
X	Consistency of each partition table entry is checked  while  the
X	table is listed.  Any inconsistencies discovered are reported in
X	a commentary note as shown above.
X
X  Physical vs. Logical
X	Each partition table entry has both "physical" and  a  "logical"
X	fields.	  The  physical	 fields	 specify  the lowest and highest
X	cylinder,head,sector combinations to be	used in	that  partition.
X	The  logical  start  field has the total number	of sectors which
X	precede	this partition,	and the	logical	 length	 field	has  the
X	total  number  of  sectors  contained  in this partition.  These
X	fields should be self consistent unless	the disk has  more  than
X	1024 cylinders.
X
X	The physical cylinder fields are only ten-bits wide so the  con-
X	tents are limited to 1023. The logical sector fields are 32 bits
X	wide and always	show the true logical beginning	 and  length  of
X	the partition.	Generally, the physical	start field is used only
X	to locate the secondary	boot sector, and the logical  start  and
X	length fields are used to actually delimit the partition used by
X	a particular system.
X
X  Partition Names
X	The Name field in the partition	table is  treated  specially  if
X	the  bootmenu  program	is installed in	the primary boot sector.
X	(See the file bootmenu.doc for	more  information.)  pfdisk  can
X	recognize  the	name  table  used  by bootmenu and will	show the
X	actual names present in	that name table.  If any other boot pro-
X	gram  is  used	then  the  Name	 field	reflects the result of a
X	table-lookup of	the system ID.
X
X	If you provide a name when  setting  any  partition  entry,  the
X	boot-sector  is	 marked	as using a name	table, so that on subse-
X	quent uses of pfdisk you will see the partition	names  you  have
X	specified.
X
X  Boot program replacement
X	You can	replace	the boot program in  your  boot	 sector	 without
X	affecting  the	partition  table  by  using  pfdisk  as	follows.
X	First, (as always) save	a copy of the current boot sector (on  a
X
X
X
X
X
XRelease	1.3	      Last change: Oct 1990			3
X
X
X
X
X
X
XPFDISK(8)	      MAINTENANCE COMMANDS		PFDISK(8)
X
X
X
X
X
X	floppy)	using the "W file" command.  Then, use the "R file" com-
X	mand to	read the new boot program.  If the boot	program	read  in
X	is  less  than	446  bytes  long,  the	partition  table will be
X	unchanged.
X
X	Unlike the DOS or UNIX fdisk programs, pfdisk has NO  boot  pro-
X	gram  compiled	into  its  executable image.  If you wish to use
X	pfdisk to partition a newly formatted hard disk, you must have a
X	boot  program image available to read in using the "r file" com-
X	mand.  Two boot	programs, "bootmenu.bin" and "bootauto.bin"  are
X	distributed  with  pfdisk  and	should	be found with its source
X	files.	See the	file bootmenu.doc for further information  about
X	these boot programs.
X
XAUTHOR
X	Gordon W. Ross
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
XRelease	1.3	      Last change: Oct 1990			4
X
END_OF_pfdisk.doc
if test 6755 -ne `wc -c <pfdisk.doc`; then
    echo shar: \"pfdisk.doc\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f SStor.txt -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"SStor.txt\"
else
echo shar: Extracting \"SStor.txt\" \(1041 characters\)
sed "s/^X//" >SStor.txt <<'END_OF_SStor.txt'
X
XNote: SpeedStor (sstor) modifies SEVERAL locations in the boot sector!
X
XThe SpeedStor manual says it does not modify locations 0xEA -- 0x17D
XBUT THEY LIE!  If you use the "Parameter Override" feature, "sstor"
X(evidently) puts the new disk parameters in locations 0xEA -- 0xF9.
X
XIf you install BOOTAUTO and then run sstor, using the parameter
Xoverride feature, you will have clobbered the BOOTAUTO program in a
Xway such that it hangs or repeats its menu when you make a selection!
X(Yes, I learned this the hard way...)
X
XTo get around this problem, I wrote a slimmed-down version of the boot
Xprogram, called BOOTMENU, which has unused "holes" strategicly placed
Xin the locations known to be clobbered by SpeedStor.  Though this
Xversion has the advantage of SpeedStor compatibility, it does not have
Xthe ability to do automatic, unattended reboots like BOOTAUTO can.
X
XFor future reference, also note that sstor will modify locations
X0x17E -- 0x1BD if you create SpeedStor partitions.  To their credit,
Xthis is indeed mentioned in the manual.
X
END_OF_SStor.txt
if test 1041 -ne `wc -c <SStor.txt`; then
    echo shar: \"SStor.txt\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f bootmenu.asm -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"bootmenu.asm\"
else
echo shar: Extracting \"bootmenu.asm\" \(5005 characters\)
sed "s/^X//" >bootmenu.asm <<'END_OF_bootmenu.asm'
X	PAGE 60,132
X;	bootmenu: BOOT Hard Disk Partition
X;	by Gordon W. Ross, Aug 1990
X;
X;	See the file bootmenu.doc for user instructions.
X;
X;	This version of bootmenu is compatible with SpeedStor.
X;	See the file sstor-bug.txt for the gory details.
X;
X;	The following is an outline of the program:
X;
X;	Relocate self from 0x7c00 to 0x0600
X;	Display partition menu
X;	Prompt for and read user selection
X;
X;	Boot from the selected partition:
X;	(was selected by user, or was active)
X;	Read first sector of selected partition into 0x7c00
X;	Verify good second-stage boot sector (magic word)
X;	Set-up correct register values and jump to it.
X;
X
XCODEORG	equ 0600h	; offset of this code in code seg
X; All values computed from offsets in codeseg need to be
X; adjusted by adding CODEORG to each.  The obvious method,
X; using "org CODEORG" causes MASM/LINK to fill in the space.
X
Xcodeseg	segment
X	assume cs:codeseg, ds:codeseg
X
X; Initial program entry point
X; (Assembler is told this is at offset zero.)
X
Xmain:
X	; Set up the stack
X	xor	ax,ax
X	mov	si,7C00h	; just before load location
X	cli
X	mov	ss,ax
X	mov	sp,si
X	sti
X
X; Relocate this code from 0:7C00h to 0:CODEORG
X	mov	ds,ax
X	mov	es,ax
X	mov	si,7C00h	; where this program is initially loaded
X	mov	di,CODEORG
X	mov	cx,0100h
X	cld
X	rep	movsw
X
X; Jump to relocated code (0:CODEORG)
X	jmp	far ptr begin1
Xbegin	equ	$	; The above jump lands here.
X
X; Print partition menu from name table
Xmenu:
X	call	putnl		; print newline
X	mov	si, offset pnames ; no org fix-up here!
X	mov	al, '1'
Xprname:
X	push	si
X	push	ax
X
X	call	putc
X	mov	al,' '
X	call	putc
X	mov	cx,8		; maximum name length
X	call	putn
X	call	putnl
X
X	pop	ax
X	pop	si
X	add	si,8
X	inc	al
X	cmp	al,'4'
X	jbe	prname
X
X; Prompt for and read user selection
Xselect:
X	call	putnl	; print prompt
X	mov	si, offset prompt + CODEORG
X	call	puts
X
X	mov	ah,0	; Read a keystroke and print it
X	int	16h
X	push	ax
X	call	putc
X	call	putnl
X	pop	ax
X
X	sub	al,'1'	; range check and convert to index
X	cmp	al,04
X	jnb	select
X
Xboot:
X; Boot from the selected partition.
X; On entry to this section:  AL = index of ptable element
X
X	; get address of ptable element (si = & ptable[AL])
X	mov	si, offset ptable ; no org fix-up here
X	mov	cl,16	; size of array element
X	mul	cl		; ax = al * cl
X	add	si,ax
X
X; Check for valid system ID (non-zero)
X
X	mov	al,[si+4]
X	cmp	al,0
X	jnz	id_ok
X	mov	si, offset msgempty + CODEORG
X	jmp	error
Xid_ok:
X
X; Read first sector of selected partition into 0x7c00
X; Also, mark this entry active (in RAM only) in case the
X; secondary boot program looks at it (which it may).
X
X	mov	al,80h	; active flag
X	mov	[si], al
X	mov	cx,5	; retry count
Xretry:	push	cx
X	mov	dx,[si]	; drive, head
X	mov	cx,[si+2]	; cyl, sector
X	mov	bx,7C00h	; destination (es=0)
X	mov	ax,0201h	; BIOS read one sector
X	int	13h
X	jnc	rd_ok
X	xor	ax,ax	; reset disk
X	int	13h
X	pop	cx
X	loop	retry
X	mov	si, offset msgread + CODEORG
X	jmp	error
Xrd_ok:	pop	cx
X
X; Check for valid magic number in secondary boot sector
X	mov	ax, 0AA55h
X	assume	ds:seg0		; Actually, codeseg == seg0
X	cmp	ax, magic2
X	assume	ds:codeseg
X	jz	magic_ok
X	mov	si, offset msginvalid + CODEORG
X	jmp	error
Xmagic_ok:
X
X; Make sure ds:si points to the booted partition, and
X; Jump to the secondary boot program.
X	jmp	far ptr begin2
X
X; Jump here with si=error-message
Xerror:
X	call	puts
X	call	putnl
X	jmp	menu
X
X;*************************************************************
X; Subroutines
X;*************************************************************
XCR	EQU	13
XLF	EQU	10
XTAB	EQU	 9
X
Xputc	proc	near		; print char in AL
X	mov	ah, 0Eh		; uses: ax, bx
X	mov	bx, 07
X	int	10h
X	ret
Xputc	endp
X
Xputnl	proc	near		; print a newline
X	mov	al, CR		; uses: ax, bx
X	call	putc
X	mov	al, LF
X	call	putc
X	ret
Xputnl	endp
X
Xputs	proc	near		; print string at address SI
X	mov	cx,80		; Stop at null or CX chars
Xputn:	lodsb			; uses: ax, bx, cx, si
X	cmp	al,0
X	jz	puts_e
X	push	cx
X	call	putc
X	pop	cx
X	loop	putn
Xputs_e:	ret
Xputs	endp
X
X;**********************************************************
X; A little space here makes this program live happily with
X; SpeedStor, which wants to write type-override stuff here.
X;**********************************************************
X
X	org	100h
X;**********************************************************
X; Strings
X;**********************************************************
X
Xprompt		db	"Boot partition? (1-4) ",0
Xmsgempty	db	"Empty!",0
Xmsgread		db	"Read error!",0
Xmsginvalid	db	"Invalid!",0
X
Xcodeseg	ends
X
X; Declares some offsets in segment zero
Xseg0	segment	at 0
X
X	org	CODEORG + (offset begin - offset main)
Xbegin1	equ	$
X
X; Here is the name table used for the partition menu.
X; The accompanying fdisk program updates this table.
X	org	CODEORG + 180h
Xpnames	db	32 dup(?)
X
X; The locations after 1AE are (reportedly) used by some
X; Western Digital controllers in "auto-configure" mode.
X; Don't put anything critical between here and ptable.
X
X; Here is the partition table
X	org	CODEORG + 1BEh
Xptable	db	(4 * 16) dup(?)
X
X; Here is where the secondary boot sector is loaded.
X	org	7C00h
Xbegin2	equ	$
X	org	7DFEh
Xmagic2	dw	?
Xseg0	ends
X
X	end	main
END_OF_bootmenu.asm
if test 5005 -ne `wc -c <bootmenu.asm`; then
    echo shar: \"bootmenu.asm\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f bootauto.asm -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"bootauto.asm\"
else
echo shar: Extracting \"bootauto.asm\" \(6427 characters\)
sed "s/^X//" >bootauto.asm <<'END_OF_bootauto.asm'
X	PAGE 60,132
X;	bootauto:  Auto-boot version of BOOTMENU program
X;	by Gordon W. Ross, Aug 1990
X;
X;	See the file bootmenu.doc for user instructions.
X;
X;	The following is an outline of the program:
X;
X;	Relocate self from 0x7C00 to 0x0600
X;	Display message "Booting from HD0,"
X;	Search partition table for an active entry
X;	If an active partition is found,
X;		Delay while watching for key press (5 sec.)
X;		If (key pressed) GOTO menu:
X;		Else GOTO boot:
X;		EndIf
X;	Else (no active partition)
X; menu:		Display partition menu
X;		Prompt for and read user selection
X;	EndIf
X; boot:	Boot from the selected partition:
X;	(was selected by user, or was active)
X;	Read first sector of selected partition into 0x7c00
X;	Verify good second-stage boot sector (magic word)
X;	Set-up correct register values and jump to it.
X;	If (Errors during boot) { complain; GOTO menu: }
X;
X
XDELAY	equ	5*18	; in ticks (1/18 sec.)
XCODEORG	equ 0600h	; offset of this code in code seg
X; All values computed from offsets in codeseg need to be
X; adjusted by adding CODEORG to each.  The obvious method,
X; using "org CODEORG" causes MASM/LINK to fill in the space.
X
Xcodeseg	segment
X	assume cs:codeseg, ds:codeseg
X
X; Initial program entry point
X; (Assembler is told this is at offset zero.)
X
Xmain:
X	; Set up the stack
X	xor	ax,ax
X	mov	si,7C00h	; just before load location
X	cli
X	mov	ss,ax
X	mov	sp,si
X	sti
X
X; Relocate this code from 0:7C00h to 0:CODEORG
X	mov	ds,ax
X	mov	es,ax
X	mov	si,7C00h	; where this program is initially loaded
X	mov	di,CODEORG
X	mov	cx,0100h
X	cld
X	rep	movsw
X
X; Jump to relocated code (0:CODEORG)
X	jmp	far ptr begin1
Xbegin	equ	$
X	mov	bp,sp	; frame pointer = 0x7C00
X	sub	sp,4
X; 2 words of local storage:
X;	[bp-2] = ptable index [0-3]
X;	[bp-4] = temporary value
X
X; Display message "Boot device: HD0"
X	mov	si, offset bootdev + CODEORG
X	call	puts
X
X; Search partition table for an active entry
X	mov	al,0
Xsearch:
X	call	addr_pt	; si = & ptable[AL]
X	mov	DL,[si]
X	cmp	DL,80h
X	jz	found
X	inc	al
X	cmp	al,04
X	jb	search
X; Active partition not found
X	jmp	menu
X
Xfound:	; Found a partition marked active.
X	mov	[bp-2],ax	; Save the ptable array index
X
X; Delay while watching for key press (2 sec.)
X; Get start time, compute end time.
X	mov	ah,00
X	int	1Ah		; BIOS get time of day
X	add	dx, DELAY	; compute end time
X	mov	[bp-4],dx	; save expiration time
X
X; Check for key press
Xwaitkey:
X	mov	ah,1
X	int	16h		; BIOS Keyboard
X	jnz	menu	; key pressed
X
X; Check for expiration of delay
X	mov	ah,00
X	int	1Ah		; BIOS get time of day
X	sub	dx,[bp-4]
X	js	waitkey	; delay not expired
X
X; Delay has expired, so boot the active partition
X	mov	al,','
X	call	putc
X	mov	ax,[bp-2]	; ptable index
X	; the index and newline are printed later
X	jmp	boot
X
X; Display partition menu
Xmenu:
X	mov	ah,1		; flush input
X	int	16h
X	jz	fl_done
X	mov	ah,0
X	int	16h
X	jmp	menu
Xfl_done:
X
X; Print partition menu from name table
X
X	call	putnl		; print newline
X	mov	si, offset pnames ; no org fix-up here
X	mov	al, '1'
Xprname:
X	push	si
X	push	ax
X
X	call	putc
X	mov	al,' '
X	call	putc
X	mov	cx,8		; maximum name length
X	call	putn
X	call	putnl
X
X	pop	ax
X	pop	si
X	add	si,8
X	inc	al
X	cmp	al,'4'
X	jbe	prname
X
X; Prompt for and read user selection
Xselect:
X	call	putnl
X	mov	si, offset prompt + CODEORG
X	call	puts
X	; Read a key and convert it to a number
X	mov	ah,0
X	int	16h
X	sub	al,'1'
X	cmp	al,04
X	jnb	select
X	; The key and a newline are printed below
X
Xboot:
X; Boot from the selected partition.
X; On entry to this section:  AL = index of ptable element
X
X	; get address of ptable element
X	call	addr_pt	; si = & ptable[AL]
X
X	; print the parition index and a newline
X	add	al,'1'
X	call	putc
X	call	putnl
X
X; Check for valid system ID (non-zero)
X
X	mov	al,[si+4]
X	cmp	al,0
X	jnz	id_ok
X	mov	si, offset msgempty + CODEORG
X	jmp	error
Xid_ok:
X
X; Read first sector of selected partition into 0x7c00
X; Also, mark this entry active (in RAM only) in case the
X; secondary boot program looks at it (which it may).
X
X	mov	al,80h	; active flag
X	mov	[si], al
X	mov	cx,5	; retry count
Xretry:	push	cx
X	mov	dx,[si]	; drive, head
X	mov	cx,[si+2]	; cyl, sector
X	mov	bx,7C00h	; destination (es=0)
X	mov	ax,0201h	; BIOS read one sector
X	int	13h
X	jnc	rd_ok
X	xor	ax,ax	; reset disk
X	int	13h
X	pop	cx
X	loop	retry
X	mov	si, offset msgread + CODEORG
X	jmp	error
Xrd_ok:	pop	cx
X
X; Check for valid magic number in secondary boot sector
X	mov	ax, 0AA55h
X	assume	ds:seg0		; Actually, codeseg == seg0
X	cmp	ax, magic2
X	assume	ds:codeseg
X	jz	magic_ok
X	mov	si, offset msginvalid + CODEORG
X	jmp	error
Xmagic_ok:
X
X; Make sure ds:si points to the booted partition, and
X; Jump to the secondary boot program.
X	jmp	far ptr begin2
X
X; Jump here with si=error-message
Xerror:
X	call	puts
X	call	putnl
X	jmp	menu
X
X;*************************************************************
X; Subroutines
X;*************************************************************
XCR	EQU	13
XLF	EQU	10
XTAB	EQU	 9
X
Xputc	proc	near		; print char in AL
X	mov	ah, 0Eh		; uses: ax, bx
X	mov	bx, 07
X	int	10h
X	ret
Xputc	endp
X
Xputnl	proc	near		; print a newline
X	mov	al, CR		; uses: ax, bx
X	call	putc
X	mov	al, LF
X	call	putc
X	ret
Xputnl	endp
X
Xputs	proc	near		; print string at address SI
X	mov	cx,80		; Stop at null or CX chars
Xputn:	lodsb			; uses: ax, bx, cx, si
X	cmp	al,0
X	jz	puts_e
X	push	cx
X	call	putc
X	pop	cx
X	loop	putn
Xputs_e:	ret
Xputs	endp
X
Xaddr_pt	proc	near		; set SI = address of ptable[al]
X	push	ax		; uses: cx (but preserves ax)
X	mov	si, offset ptable ; no org fix-up here
X	mov	cl,16	; size of array element
X	mul	cl		; ax = al * cl
X	add	si,ax
X	pop	ax
X	ret
Xaddr_pt	endp
X
X;**********************************************************
X; Strings
X;**********************************************************
X
Xbootdev		db	"Boot device: hd0",0
Xprompt		db	"Boot partition? (1-4) ",0
Xmsgempty	db	"Empty!",0
Xmsgread		db	"Read error!",0
Xmsginvalid	db	"Invalid!",0
X	org	180h	; this pads the length (it seems)
Xcodeseg	ends
X
X; Declares some offsets in segment zero
Xseg0	segment	at 0
X
X	org	CODEORG + (offset begin - offset main)
Xbegin1	equ	$
X
X; Here is the name table used for the partition menu.
X; The accompanying fdisk program updates this table.
X	org	CODEORG + 180h
Xpnames	db	32 dup(?)
X
X; The locations after 1AE are (reportedly) used by some
X; Western Digital controllers in "auto-configure" mode.
X; Don't put anything critical between here and ptable.
X
X; Here is the partition table
X	org	CODEORG + 1BEh
Xptable	db	(4 * 16) dup(?)
X
X; Here is where the secondary boot sector is loaded.
X	org	7C00h
Xbegin2	equ	$
X
X	org	7DFEh
Xmagic2	dw	?
X
Xseg0	ends
X
X	end	main
END_OF_bootauto.asm
if test 6427 -ne `wc -c <bootauto.asm`; then
    echo shar: \"bootauto.asm\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f asm2bin.bat -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"asm2bin.bat\"
else
echo shar: Extracting \"asm2bin.bat\" \(262 characters\)
sed "s/^X//" >asm2bin.bat <<'END_OF_asm2bin.bat'
X at echo off
XREM This batch file builds file.bin from file.asm
Xif not arg%1==arg%1 goto arg
Xecho supply base name of file.asm, i.e. file
Xgoto exit
X:arg
Xecho on
Xmasm %1,,;
Xlink boot-hdp,;
X at echo Ignore the 'no stack...' warning
Xdel %1.obj
Xexe2bin %1
Xdel %1.exe
X:exit
END_OF_asm2bin.bat
if test 262 -ne `wc -c <asm2bin.bat`; then
    echo shar: \"asm2bin.bat\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f make_msc.bat -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"make_msc.bat\"
else
echo shar: Extracting \"make_msc.bat\" \(162 characters\)
sed "s/^X//" >make_msc.bat <<'END_OF_make_msc.bat'
X at echo This batch file uses Microsoft C to build pfdisk.exe
X at echo Note that only SMALL model has been tested...
Xcl -AS -o pfdisk.exe pfdisk.c syscodes.c s_msdos.c
END_OF_make_msc.bat
if test 162 -ne `wc -c <make_msc.bat`; then
    echo shar: \"make_msc.bat\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f bootmenu.hex -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"bootmenu.hex\"
else
echo shar: Extracting \"bootmenu.hex\" \(1177 characters\)
sed "s/^X//" >bootmenu.hex <<'END_OF_bootmenu.hex'
X 33 C0 BE 00 7C FA 8E D0 8B E6 FB 8E D8 8E C0 BE
X 00 7C BF 00 06 B9 00 01 FC F3 A5 EA 20 06 00 00
X E8 9E 00 BE 80 07 B0 31 56 50 E8 8C 00 B0 20 E8
X 87 00 B9 08 00 E8 97 00 E8 86 00 58 5E 83 C6 08
X FE C0 3C 34 76 E2 E8 78 00 BE 00 07 E8 7D 00 B4
X 00 CD 16 50 E8 62 00 E8 67 00 58 2C 31 3C 04 73
X E5 BE BE 07 B1 10 F6 E1 03 F0 8A 44 04 3C 00 75
X 06 BE 17 07 EB 3A 90 B0 80 88 04 B9 05 00 51 8B
X 14 8B 4C 02 BB 00 7C B8 01 02 CD 13 73 0D 33 C0
X CD 13 59 E2 E9 BE 1E 07 EB 16 90 59 B8 55 AA 3B
X 06 FE 7D 74 06 BE 2A 07 EB 06 90 EA 00 7C 00 00
X E8 19 00 E8 0B 00 E9 67 FF B4 0E BB 07 00 CD 10
X C3 B0 0D E8 F3 FF B0 0A E8 EE FF C3 B9 50 00 AC
X 3C 00 74 07 51 E8 E1 FF 59 E2 F4 C3 00 00 00 00
X 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
X 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
X 42 6F 6F 74 20 70 61 72 74 69 74 69 6F 6E 3F 20
X 28 31 2D 34 29 20 00 45 6D 70 74 79 21 00 52 65
X 61 64 20 65 72 72 6F 72 21 00 49 6E 76 61 6C 69
X 64 21 00 00 00 00 00 00 00 00 00 00 00 00 00 00
X 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
X 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
X 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
X 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
X
END_OF_bootmenu.hex
if test 1177 -ne `wc -c <bootmenu.hex`; then
    echo shar: \"bootmenu.hex\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f bootauto.hex -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"bootauto.hex\"
else
echo shar: Extracting \"bootauto.hex\" \(1177 characters\)
sed "s/^X//" >bootauto.hex <<'END_OF_bootauto.hex'
X 33 C0 BE 00 7C FA 8E D0 8B E6 FB 8E D8 8E C0 BE
X 00 7C BF 00 06 B9 00 01 FC F3 A5 EA 20 06 00 00
X 8B EC 83 EC 04 BE 35 07 E8 EE 00 B0 00 E8 F9 00
X 8A 14 80 FA 80 74 09 FE C0 3C 04 72 F0 EB 28 90
X 89 46 FE B4 00 CD 1A 83 C2 5A 89 56 FC B4 01 CD
X 16 75 14 B4 00 CD 1A 2B 56 FC 78 F1 B0 2C E8 A5
X 00 8B 46 FE EB 46 90 B4 01 CD 16 74 06 B4 00 CD
X 16 EB F4 E8 98 00 BE 80 07 B0 31 56 50 E8 86 00
X B0 20 E8 81 00 B9 08 00 E8 91 00 E8 80 00 58 5E
X 83 C6 08 FE C0 3C 34 76 E2 E8 72 00 BE 46 07 E8
X 77 00 B4 00 CD 16 2C 31 3C 04 73 ED E8 7A 00 04
X 31 E8 52 00 E8 57 00 8A 44 04 3C 00 75 06 BE 5D
X 07 EB 3A 90 B0 80 88 04 B9 05 00 51 8B 14 8B 4C
X 02 BB 00 7C B8 01 02 CD 13 73 0D 33 C0 CD 13 59
X E2 E9 BE 64 07 EB 16 90 59 B8 55 AA 3B 06 FE 7D
X 74 06 BE 70 07 EB 06 90 EA 00 7C 00 00 E8 19 00
X E8 0B 00 E9 61 FF B4 0E BB 07 00 CD 10 C3 B0 0D
X E8 F3 FF B0 0A E8 EE FF C3 B9 50 00 AC 3C 00 74
X 07 51 E8 E1 FF 59 E2 F4 C3 50 BE BE 07 B1 10 F6
X E1 03 F0 58 C3 42 6F 6F 74 20 64 65 76 69 63 65
X 3A 20 68 64 30 00 42 6F 6F 74 20 70 61 72 74 69
X 74 69 6F 6E 3F 20 28 31 2D 34 29 20 00 45 6D 70
X 74 79 21 00 52 65 61 64 20 65 72 72 6F 72 21 00
X 49 6E 76 61 6C 69 64 21 00 00 00 00 00 00 00 00
X
END_OF_bootauto.hex
if test 1177 -ne `wc -c <bootauto.hex`; then
    echo shar: \"bootauto.hex\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f hex2bin.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"hex2bin.c\"
else
echo shar: Extracting \"hex2bin.c\" \(462 characters\)
sed "s/^X//" >hex2bin.c <<'END_OF_hex2bin.c'
X/*
X * hex2bin - a simple hex to binary converter
X */
X#include <stdio.h>
Xmain(argc,argv)
Xint argc; char **argv;
X{
X  FILE *fp;
X  int c;
X#ifdef MSDOS
X  char mode = "wb";
X#else
X  char mode = "w";
X#endif
X
X  if (argc <= 1) {
X    fprintf(stderr,"Usage: %s OUTPUT-FILE\n", argv[0]);
X    exit(1);
X  }
X  if (!(fp = fopen(argv[1],mode))) {
X    fprintf(stderr,"%s: can not open for writing\n");
X    exit(1);
X  }
X
X  while (scanf("%x", &c) == 1)
X    putc(c,fp);
X
X  exit(0);
X}
END_OF_hex2bin.c
if test 462 -ne `wc -c <hex2bin.c`; then
    echo shar: \"hex2bin.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of shell archive.
exit 0
-- 
Gordon Ross	(gwr at world.std.com)



More information about the Comp.unix.sysv386 mailing list