Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

reboot system using C

42 views
Skip to first unread message

John E. Davis

unread,
Mar 25, 1996, 3:00:00 AM3/25/96
to
Could somebody help me out with this? I need to know how to reboot a PC
using C. Thanks for any help that you can give me.

John Davis
las...@hops.cs.jhu.edu

Jack Tackett

unread,
Mar 26, 1996, 3:00:00 AM3/26/96
to
John E. Davis (las...@hops.cs.jhu.edu) wrote:
: Could somebody help me out with this? I need to know how to reboot a PC
: using C. Thanks for any help that you can give me.

: John Davis
: las...@hops.cs.jhu.edu

HTH - jack
from the faq (of a few years ago, havent checked out a recent one either..

section 7. Other software questions and problems
================================================

Q701. How can a program reboot my PC?

You can generate a "cold" boot or a "warm" boot. A cold boot is
the same as turning the power off and on; a warm boot is the same as
Ctrl-Alt-Del and skips the power-on self test.
For a warm boot, store the hex value 1234 in the word at 0040:0072.
For a cold boot, store 0 in that word. Then, if you want to live
dangerously, jump to address FFFF:0000. Here's C code to do it:

/* WARNING: data loss possible */
void bootme(int want_warm) /* arg 0 = cold boot, 1 = warm */ {
void (far* boot)(void) = (void (far*)(void))0xFFFF0000UL;
unsigned far* type = (unsigned far*)0x00400072UL;
*type = (want_warm ? 0x1234 : 0);
(*boot)( );
}

What's wrong with that method? It will boot right away, without
closing files, flushing disk caches, etc. If you boot without
flushing a write-behind disk cache (if one is running), you could
lose data or even trash your hard drive.

There are two methods of signaling the cache to flush its buffers:
(1) simulate a keyboard Ctrl-Alt-Del in the keystroke translation
function of the BIOS (INT 15 function 4F), and (2) issue a disk
reset (DOS function 0D). Most disk-cache programs hook one or both
of those interrupts, so if you use both methods you'll probably be
safe.

When user code simulates a Ctrl-Alt-Del, one or more of the programs
that have hooked INT 15 function 4F can ask that the key be ignored by
clearing the carry flag. For example, HyperDisk does this when it
has started but not finished a cache flush. So if the carry flag
comes back cleared, the boot code has to wait a couple of cluck
ticks and then try again. (None of this matters on older machines
whose BIOS can't support 101- or 102-key keyboards; see "What is the
SysRq key for?" in section 3, "Keyboard".)

Here's C code that tries to signal the disk cache (if any) to flush:

#include <dos.h>
void bootme(int want_warm) /* arg 0 = cold boot, 1 = warm */ {
union REGS reg;
void (far* boot)(void) = (void (far*)(void))0xFFFF0000UL;
unsigned far* boottype = (unsigned far*)0x00400072UL;
char far* shiftstate = (char far*)0x00400017UL;
unsigned ticks;
int time_to_waste;
/* Simulate reception of Ctrl-Alt-Del: */
for (;;) {
*shiftstate |= 0x0C; /* turn on Ctrl & Alt */
reg.x.ax = 0x4F53; /* 0x53 = Del's scan code */
reg.x.cflag = 1; /* sentinel for ignoring key */
int86(0x15, &reg, &reg);
/* If carry flag is still set, we've finished. */
if (reg.x.cflag)
break;
/* Else waste some time before trying again: */
reg.h.ah = 0;
int86(0x1A, &reg, &reg);/* system time into CX:DX */
ticks = reg.x.dx;
for (time_to_waste = 3; time_to_waste > 0; ) {
reg.h.ah = 0;
int86(0x1A, &reg, &reg);
if (ticks != reg.x.dx)
ticks = reg.x.dx , --time_to_waste;
}
}
/* Issue a DOS disk reset request: */
reg.h.ah = 0x0D;
int86(0x21, &reg, &reg);
/* Set boot type and boot: */
*boottype = (want_warm ? 0x1234 : 0);
(*boot)( );
}


------------------------------------------------------------------------------
Jack Tackett, Jr. | Sticky Wicket - Up the bitstream without a modem
tac...@nando.net | Co-Author :
7031...@compuserve.com | The VC++ Construction Kit, Using Linux, Using VC 2
------------------------------------------------------------------------------


Alexander J Russell

unread,
Mar 26, 1996, 3:00:00 AM3/26/96
to
In article <4j6rsv$s...@blaze.cs.jhu.edu>, las...@hops.cs.jhu.edu says...

>
>Could somebody help me out with this? I need to know how to reboot a PC
>using C. Thanks for any help that you can give me.
>
>John Davis
>las...@hops.cs.jhu.edu
/*

reboot.c

Internet: ale...@icebox.iceonline.com
Copyright 1994, September 18 by Alec Russell, ALL rights reserved

Created - 1994/9/18

History:
New file - stolen from the internet

*/

#define TEST 0

/* #define MAGIC 0 /* for cold restart */
#define MAGIC 0x1234 /* for warm restart */

#define BOOT_SEG 0xffffL
#define BOOT_OFF 0x0000L
#define BOOT_ADR ((BOOT_SEG << 16) | BOOT_OFF)

#define DOS_SEG 0x0040L
#define RESET_FLAG 0x0072L
#define RESET_ADR ((DOS_SEG << 16) | RESET_FLAG)

void reboot(void)
{
void ((far *fp)()) = (void (far *)()) BOOT_ADR;

*(int far *)RESET_ADR = MAGIC;
(*fp)();

}


#if TEST


/* ---------------------- main() --------------------- September 18,1994 */
void main(void)
{
printf("Press a key to WARM BOOT\n");
getch();

reboot();
}

#endif

There is also info on this in this groups FAQ.
This example doesn't flush smartdrive etc... it just re-boots.


/* ------------------------------ EOF -------------------------------- */


--
The AnArChIsT! Anarchy! Not Chaos!
aka
Alex Russell
ale...@iceonline.com


Alfred Lee

unread,
Mar 26, 1996, 3:00:00 AM3/26/96
to
In article <4j6rsv$s...@blaze.cs.jhu.edu>,

las...@hops.cs.jhu.edu (John E. Davis) wrote:
> Could somebody help me out with this? I need to know how to reboot a PC
> using C. Thanks for any help that you can give me.
>
> John Davis
> las...@hops.cs.jhu.edu

main () {
int far *warmBootFlat;
void (far *rebootVertor) (void);

warmBootFlat = (int far *) MK_FP (0x40, 0x72);
rebootVertor = (void (far *) (void)) MK_FP (0xffff, 0);

*warmBootFlat = 0x1234;
(*rebootVertor) ();

}

There are also other solutions.

---
Alfred Lee a...@kaiwan.com
KE6KGV 'The answer is (e^iã + 1) ? "No" : "Yes"'
Silent keys: KE6LTH, KD6HNU, March 21, 1996

Szu-Wen Huang

unread,
Mar 27, 1996, 3:00:00 AM3/27/96
to
Alfred Lee (a...@kaiwan.com) wrote:
: In article <4j6rsv$s...@blaze.cs.jhu.edu>,

: las...@hops.cs.jhu.edu (John E. Davis) wrote:
: > Could somebody help me out with this? I need to know how to reboot a PC
: > using C. Thanks for any help that you can give me.

: There are also other solutions.

Switching to protected mode, don't set up the IVT, then do a divide by
zero is my personal favorite ;).

OBO Systems

unread,
Apr 1, 1996, 3:00:00 AM4/1/96
to
Szu-Wen Huang (hu...@mnsinc.com) wrote:

If you are using Turbo C 2.0 or higher, or Borland C++ you can
do it in very simple way. Just enter: __emit__(0xea,0xf0,0xff,0,0xf0).
You need to include dos.h file to use this function.
Pawel Bogdziun.


0 new messages