#ifdef	ournix
#include "ournix.h"
#endif
char sccsID[] = "@(#) reset.c V1.3 Copyright Julian H. Stacey July 88.\n" ;

#ifdef	MSDOS	/* { */
/* Function:
	A) Stops a Symmetric Unix, or
	B) Reboots an ibm compatible at or pc running msdos,
	Although control alt del creates a reboot, 
	this program can be run remote when the machine is being controlled
	from a serial port, & human is not adjacent to keyboard 
	
Syntax:	reset	or	reset -n
	the -n suppresses user verification, reboots without asking user.
*/
#endif		/* } */

#include <stdio.h>

#ifdef	unix	/* { */
#include <sys/reboot.h>
#endif		/* } */
char	**ARGV ;

main(argc,argv)
	int argc ; char **argv ;
	{
	int cc ;
#ifdef	MSDOS	/* { */
	int (far * fred)() ;
#endif		/* } */

	ARGV = argv ;
#ifdef	VSL	/* { */
#include	"../../include/vsl.h"
#endif		/* } */

	if (!((argc == 2) && (**++argv == '-') && (*++*argv == 'n') ))
		{
		printf("Do you want to instantly reboot the whole computer ? ");
		if ( ( cc = getchar()) == EOF ) exit(1) ;
		cc &= 0x7F ;
		if (( cc >= 'A') && ( cc <= 'Z')) cc -= 'A' - 'a' ;
		if ( cc != 'y') exit(0) ;
		}
#ifdef	MSDOS	/* { */
	/*
	Basis: when an Intel 8086 starts, first op code executed is 0xFFFF0.
	Exepack should not be used as it makes the executable bigger
		(from 3345 to 3496 ).
	Compilation: with Microsoft V4 small model compiler
		- ignore the different levels of indirection warning.
	   Tried & doesnt work: 0xFFFF0 & 0xFFFF0L 
	   Tried & does work: 0xFFFF0000 - correct microsoft large model syntax 
					to represent 0xFFFF0 
	   Idea: 0xFFFF0000 probably becomes FFFF:0000, (= 0xFFFF0)
	   So these should also work: F000:FFF0,FF00:0FF0,FFF0:00F0,FFFF:0000
	   which become 0xF000FFF0, 0xFF000FF0, 0xFFF000F0, 0xFFFF0000
	*/
	fred = 0xFFFF0000 ; (*fred)() ;
	/*
	Limitations: a similar program written by Herr Grossman R&S for an AT 
	with protected mode switched on in order to implement extended memory 
	&/or an intel above board failed to reboot properly,
	because the at looks in battery backed cmos ram to see if it was 
	a real reboot or not.
	Write to IO byte loc 0x64 with 0xF0 should work better cos will reset
	hardware glue logic registers.
	*/
#endif		/* } */
#ifdef	unix	/* { */
	system("cp /dev/null /fastboot");
	/*
	sync() ; sleep(3) ;
			not actually necessary as there is a sync in reboot,
			but wont do any harm 
	*/
	reboot(RB_HALT);
	printf("If you see this, %s program binary needs SUID 0\n",*ARGV);	
#endif		/* } */
	exit(1) ;
	}
