How can a program reboot my PC

本文介绍了如何通过程序实现计算机的冷启动和热启动,并提供了C语言代码示例。讨论了直接重启可能导致的数据丢失风险,以及如何通过模拟Ctrl-Alt-Del操作或发出磁盘重置指令来触发磁盘缓存刷新。
 Subject: <Q:08.01> - How can a program reboot my PC?
Date: 8 Feb 2002 20:16:09 -0400

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
trash the file allocation table in 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 AH=4F; but see notes below)

(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 AH=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 clock ticks and then try
again. (None of this matters on older machines whose BIOS can't support
101- or 102-key keyboards; see the discussion of INT 21 AH=4F in
<Q:04.07> [What is the SysRq key for?])

C code that tries to signal the disk cache (if any) to flush is given
below. Turbo Pascal code by Timo Salmi that does more or less the same
job may be found at question 49 (as of this writing) in the Turbo Pascal
FAQ in comp.lang.pascal, and is downloadable as file FAQPAS2.TXT, which
is part of: <ftp://garbo.uwasa.fi/pc/link/>

Here's C code that reboots after trying to signal the disk cache:

#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.h.ah = 0x4F; /* see notes below */
reg.h.al = 0x53; /* 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)( );
}

Reader Timo Salmi reported (26 July 1993) that the INT 15 AH=4F call may
not work on older PCs (below AT, XT2, XT286), according to Ralf Brown's
interrupt list (<Q:02.03> [What and where is Ralf Brown's interrupt
list?]).

Reader Roger Fulton reported (1 July 1993) that INT 15 AH=4F hangs even
a modern PC "ONLY when ANSI.SYS [is] loaded high using EMM386.EXE.
(Other things loaded high with EMM386.EXE were OK; ANSI.SYS loaded high
with QEMM386.SYS was OK; ANSI.SYS loaded low with EMM386.EXE installed
was OK.)" His solution was to use only the disk reset, INT 21 AH=0D,
which does flush SMARTDRV, then wait five seconds in hopes that any
other disk-caching software would have time to flush its queue.

Reader Per Bergland reported (10 Sep 1993) that the jump to FFFF:0000
will not work in Windows or other protected-mode programs. (For example,
when the above reboot code ran in a DOS session under Windows, a box
with "waiting for system shutdown" appeared. The PC hung and had to be
reset by cycling power.) His solution, which does a cold boot not a warm
boot, is to pulse pin 0 of the 8042 keyboard controller, which is
connected to the CPU's "reset" line.

He has tested the following code on various Compaqs, and expects it will
work for any AT-class machine; he cautions that you must first flush the
disk cache as indicated above.

cli
(AT) (AT) WaitOutReady: ; Busy-wait until 8042 ready for new command
in al,64h ; read 8042 status byte
test al,00000010b ; this bit indicates input buffer full
jnz (AT) (AT) WaitOutReady
mov al,0FEh ; Pulse "reset" = 8042 pin 0
out 64h,al ; The PC will reboot now
基于径向基函数神经网络RBFNN的自适应滑模控制学习(Matlab代码实现)内容概要:本文介绍了基于径向基函数神经网络(RBFNN)的自适应滑模控制方法,并提供了相应的Matlab代码实现。该方法结合了RBF神经网络的非线性逼近能力和滑模控制的强鲁棒性,用于解决复杂系统的控制问题,尤其适用于存在不确定性和外部干扰的动态系统。文中详细阐述了控制算法的设计思路、RBFNN的结构与权重更新机制、滑模面的构建以及自适应律的推导过程,并通过Matlab仿真验证了所提方法的有效性和稳定性。此外,文档还列举了大量相关的科研方向和技术应用,涵盖智能优化算法、机器学习、电力系统、路径规划等多个领域,展示了该技术的广泛应用前景。; 适合人群:具备一定自动控制理论基础和Matlab编程能力的研究生、科研人员及工程技术人员,特别是从事智能控制、非线性系统控制及相关领域的研究人员; 使用场景及目标:①学习和掌握RBF神经网络与滑模控制相结合的自适应控制策略设计方法;②应用于电机控制、机器人轨迹跟踪、电力电子系统等存在模型不确定性或外界扰动的实际控制系统中,提升控制精度与鲁棒性; 阅读建议:建议读者结合提供的Matlab代码进行仿真实践,深入理解算法实现细节,同时可参考文中提及的相关技术方向拓展研究思路,注重理论分析与仿真验证相结合。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值