2006-11-13 04:33:45 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS HAL
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
2006-11-29 08:28:20 +00:00
|
|
|
* FILE: hal/halx86/generic/reboot.c
|
2006-11-13 04:33:45 +00:00
|
|
|
* PURPOSE: Reboot functions
|
|
|
|
* PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
|
2010-01-09 22:43:16 +00:00
|
|
|
* Eric Kohl
|
2001-08-21 20:18:27 +00:00
|
|
|
*/
|
|
|
|
|
2006-11-13 04:33:45 +00:00
|
|
|
/* INCLUDES ******************************************************************/
|
|
|
|
|
2002-09-08 10:23:54 +00:00
|
|
|
#include <hal.h>
|
2002-09-07 15:13:13 +00:00
|
|
|
|
2006-11-13 04:33:45 +00:00
|
|
|
/* PRIVATE FUNCTIONS *********************************************************/
|
|
|
|
|
2023-06-20 20:28:31 +00:00
|
|
|
static VOID
|
2006-11-13 04:33:45 +00:00
|
|
|
HalpWriteResetCommand(VOID)
|
|
|
|
{
|
|
|
|
/* Generate RESET signal via keyboard controller */
|
|
|
|
WRITE_PORT_UCHAR((PUCHAR)0x64, 0xFE);
|
|
|
|
};
|
2001-08-21 20:18:27 +00:00
|
|
|
|
2023-06-20 20:28:31 +00:00
|
|
|
DECLSPEC_NORETURN
|
- Stub out DbgKdWriteVirtualMemoryApi, DbgKdReadPhysicalMemoryApi, DbgKdWritePhysicalMemoryApi, DbgKdWriteBreakPointExApi, DbgKdRestoreBreakPointExApi, DbgKdSearchMemoryApi and DbgKdFillMemoryApi cases more properly.
- Fail on physical memory write like we do for read too.
- Don't handle OldVlm1/2 as they appear to be deprecated and unhandled in Windows.
- Implement HalHaltSystem to halt execution in a portable way. Default to xHalHaltSystem, a simple infinite loop, if we get called before HAL has initialized. Use this in KiBugCheckDebugBreak and the system shutdown handler instead of x86/AMD64/ARM intrinsics.
- Don't try to halt the CPU if KeBugCheck has been called 3 times or more -- if this happens, something has gone very wrong, and we shouldn't try to do anything special. Just loop infinitely.
- Fix KiBugCheckDebugBreak -- it shouldn't halt execution when called for the first chance as bugcheck callbacks have not been invoked at this point (nor has the BSOD been displayed). Use SEH to protect against a crash instead of checking KdDebuggerNotPresent as the debugger, if it is present, *could* disconnect while the trap is being handled. Also, don't halt execution if the debugger handled the breakpoint, just break again.
- Don't call MmMapIoSpace from HalpReboot! The reboot might take place at elevated IRQL (as high as HIGH_LEVEL if called from KeBugCheck), and thus can't use any Mm support routines. Use a PTE from the reserved HAL region and map it ourselves instead as done in the BIOS call code.
- Acquire the display ownership in HalReturnToFirmware in case the caller hasn't done so (as done in the KD reboot routine, for example).
- Just include ntndk.h in hal.h instead of including 6 NDK headers (which turns into more than half of the NDK anyway since those headers include other NDK headers).
- Crashing and rebooting from KD now works properly.
svn path=/trunk/; revision=43380
2009-10-11 20:16:45 +00:00
|
|
|
VOID
|
2006-11-13 04:33:45 +00:00
|
|
|
HalpReboot(VOID)
|
2001-08-21 20:18:27 +00:00
|
|
|
{
|
2018-04-03 21:13:17 +00:00
|
|
|
PHYSICAL_ADDRESS PhysicalAddress;
|
2006-11-13 04:33:45 +00:00
|
|
|
UCHAR Data;
|
- Stub out DbgKdWriteVirtualMemoryApi, DbgKdReadPhysicalMemoryApi, DbgKdWritePhysicalMemoryApi, DbgKdWriteBreakPointExApi, DbgKdRestoreBreakPointExApi, DbgKdSearchMemoryApi and DbgKdFillMemoryApi cases more properly.
- Fail on physical memory write like we do for read too.
- Don't handle OldVlm1/2 as they appear to be deprecated and unhandled in Windows.
- Implement HalHaltSystem to halt execution in a portable way. Default to xHalHaltSystem, a simple infinite loop, if we get called before HAL has initialized. Use this in KiBugCheckDebugBreak and the system shutdown handler instead of x86/AMD64/ARM intrinsics.
- Don't try to halt the CPU if KeBugCheck has been called 3 times or more -- if this happens, something has gone very wrong, and we shouldn't try to do anything special. Just loop infinitely.
- Fix KiBugCheckDebugBreak -- it shouldn't halt execution when called for the first chance as bugcheck callbacks have not been invoked at this point (nor has the BSOD been displayed). Use SEH to protect against a crash instead of checking KdDebuggerNotPresent as the debugger, if it is present, *could* disconnect while the trap is being handled. Also, don't halt execution if the debugger handled the breakpoint, just break again.
- Don't call MmMapIoSpace from HalpReboot! The reboot might take place at elevated IRQL (as high as HIGH_LEVEL if called from KeBugCheck), and thus can't use any Mm support routines. Use a PTE from the reserved HAL region and map it ourselves instead as done in the BIOS call code.
- Acquire the display ownership in HalReturnToFirmware in case the caller hasn't done so (as done in the KD reboot routine, for example).
- Just include ntndk.h in hal.h instead of including 6 NDK headers (which turns into more than half of the NDK anyway since those headers include other NDK headers).
- Crashing and rebooting from KD now works properly.
svn path=/trunk/; revision=43380
2009-10-11 20:16:45 +00:00
|
|
|
PVOID ZeroPageMapping;
|
|
|
|
|
2018-04-03 21:13:17 +00:00
|
|
|
/* Map the first physical page */
|
|
|
|
PhysicalAddress.QuadPart = 0;
|
|
|
|
ZeroPageMapping = HalpMapPhysicalMemory64(PhysicalAddress, 1);
|
2001-08-21 20:18:27 +00:00
|
|
|
|
2006-11-13 04:33:45 +00:00
|
|
|
/* Enable warm reboot */
|
- Stub out DbgKdWriteVirtualMemoryApi, DbgKdReadPhysicalMemoryApi, DbgKdWritePhysicalMemoryApi, DbgKdWriteBreakPointExApi, DbgKdRestoreBreakPointExApi, DbgKdSearchMemoryApi and DbgKdFillMemoryApi cases more properly.
- Fail on physical memory write like we do for read too.
- Don't handle OldVlm1/2 as they appear to be deprecated and unhandled in Windows.
- Implement HalHaltSystem to halt execution in a portable way. Default to xHalHaltSystem, a simple infinite loop, if we get called before HAL has initialized. Use this in KiBugCheckDebugBreak and the system shutdown handler instead of x86/AMD64/ARM intrinsics.
- Don't try to halt the CPU if KeBugCheck has been called 3 times or more -- if this happens, something has gone very wrong, and we shouldn't try to do anything special. Just loop infinitely.
- Fix KiBugCheckDebugBreak -- it shouldn't halt execution when called for the first chance as bugcheck callbacks have not been invoked at this point (nor has the BSOD been displayed). Use SEH to protect against a crash instead of checking KdDebuggerNotPresent as the debugger, if it is present, *could* disconnect while the trap is being handled. Also, don't halt execution if the debugger handled the breakpoint, just break again.
- Don't call MmMapIoSpace from HalpReboot! The reboot might take place at elevated IRQL (as high as HIGH_LEVEL if called from KeBugCheck), and thus can't use any Mm support routines. Use a PTE from the reserved HAL region and map it ourselves instead as done in the BIOS call code.
- Acquire the display ownership in HalReturnToFirmware in case the caller hasn't done so (as done in the KD reboot routine, for example).
- Just include ntndk.h in hal.h instead of including 6 NDK headers (which turns into more than half of the NDK anyway since those headers include other NDK headers).
- Crashing and rebooting from KD now works properly.
svn path=/trunk/; revision=43380
2009-10-11 20:16:45 +00:00
|
|
|
((PUSHORT)ZeroPageMapping)[0x239] = 0x1234;
|
2001-08-21 20:18:27 +00:00
|
|
|
|
2009-11-04 21:57:32 +00:00
|
|
|
/* Lock CMOS Access (and disable interrupts) */
|
2011-09-07 10:14:48 +00:00
|
|
|
HalpAcquireCmosSpinLock();
|
2001-08-21 20:18:27 +00:00
|
|
|
|
2006-11-13 04:33:45 +00:00
|
|
|
/* Setup control register B */
|
|
|
|
WRITE_PORT_UCHAR((PUCHAR)0x70, 0x0B);
|
|
|
|
KeStallExecutionProcessor(1);
|
2001-08-21 20:18:27 +00:00
|
|
|
|
2006-11-13 04:33:45 +00:00
|
|
|
/* Read periodic register and clear the interrupt enable */
|
|
|
|
Data = READ_PORT_UCHAR((PUCHAR)0x71);
|
2007-01-07 06:49:00 +00:00
|
|
|
WRITE_PORT_UCHAR((PUCHAR)0x71, Data & ~0x40);
|
2006-11-13 04:33:45 +00:00
|
|
|
KeStallExecutionProcessor(1);
|
2001-08-21 20:18:27 +00:00
|
|
|
|
2006-11-13 04:33:45 +00:00
|
|
|
/* Setup control register A */
|
|
|
|
WRITE_PORT_UCHAR((PUCHAR)0x70, 0x0A);
|
|
|
|
KeStallExecutionProcessor(1);
|
|
|
|
|
|
|
|
/* Read divider rate and reset it */
|
|
|
|
Data = READ_PORT_UCHAR((PUCHAR)0x71);
|
2007-01-07 06:49:00 +00:00
|
|
|
WRITE_PORT_UCHAR((PUCHAR)0x71, (Data & ~0x9) | 0x06);
|
2006-11-13 04:33:45 +00:00
|
|
|
KeStallExecutionProcessor(1);
|
|
|
|
|
|
|
|
/* Reset neutral CMOS address */
|
2001-08-21 20:18:27 +00:00
|
|
|
WRITE_PORT_UCHAR((PUCHAR)0x70, 0x15);
|
2006-11-13 04:33:45 +00:00
|
|
|
KeStallExecutionProcessor(1);
|
2001-08-21 20:18:27 +00:00
|
|
|
|
2006-11-13 04:33:45 +00:00
|
|
|
/* Flush write buffers and send the reset command */
|
|
|
|
KeFlushWriteBuffer();
|
|
|
|
HalpWriteResetCommand();
|
2001-08-21 20:18:27 +00:00
|
|
|
|
2006-11-13 04:33:45 +00:00
|
|
|
/* Halt the CPU */
|
2009-09-27 10:09:38 +00:00
|
|
|
__halt();
|
2023-06-20 20:28:31 +00:00
|
|
|
UNREACHABLE;
|
2001-08-21 20:18:27 +00:00
|
|
|
}
|
|
|
|
|
2006-11-13 04:33:45 +00:00
|
|
|
/* PUBLIC FUNCTIONS **********************************************************/
|
2001-08-21 20:18:27 +00:00
|
|
|
|
2023-06-20 20:28:31 +00:00
|
|
|
#ifndef _MINIHAL_
|
2006-11-13 04:33:45 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
VOID
|
|
|
|
NTAPI
|
2023-06-20 20:28:31 +00:00
|
|
|
HalReturnToFirmware(
|
|
|
|
_In_ FIRMWARE_REENTRY Action)
|
2001-08-21 20:18:27 +00:00
|
|
|
{
|
- Stub out DbgKdWriteVirtualMemoryApi, DbgKdReadPhysicalMemoryApi, DbgKdWritePhysicalMemoryApi, DbgKdWriteBreakPointExApi, DbgKdRestoreBreakPointExApi, DbgKdSearchMemoryApi and DbgKdFillMemoryApi cases more properly.
- Fail on physical memory write like we do for read too.
- Don't handle OldVlm1/2 as they appear to be deprecated and unhandled in Windows.
- Implement HalHaltSystem to halt execution in a portable way. Default to xHalHaltSystem, a simple infinite loop, if we get called before HAL has initialized. Use this in KiBugCheckDebugBreak and the system shutdown handler instead of x86/AMD64/ARM intrinsics.
- Don't try to halt the CPU if KeBugCheck has been called 3 times or more -- if this happens, something has gone very wrong, and we shouldn't try to do anything special. Just loop infinitely.
- Fix KiBugCheckDebugBreak -- it shouldn't halt execution when called for the first chance as bugcheck callbacks have not been invoked at this point (nor has the BSOD been displayed). Use SEH to protect against a crash instead of checking KdDebuggerNotPresent as the debugger, if it is present, *could* disconnect while the trap is being handled. Also, don't halt execution if the debugger handled the breakpoint, just break again.
- Don't call MmMapIoSpace from HalpReboot! The reboot might take place at elevated IRQL (as high as HIGH_LEVEL if called from KeBugCheck), and thus can't use any Mm support routines. Use a PTE from the reserved HAL region and map it ourselves instead as done in the BIOS call code.
- Acquire the display ownership in HalReturnToFirmware in case the caller hasn't done so (as done in the KD reboot routine, for example).
- Just include ntndk.h in hal.h instead of including 6 NDK headers (which turns into more than half of the NDK anyway since those headers include other NDK headers).
- Crashing and rebooting from KD now works properly.
svn path=/trunk/; revision=43380
2009-10-11 20:16:45 +00:00
|
|
|
/* Check what kind of action this is */
|
2006-11-13 04:33:45 +00:00
|
|
|
switch (Action)
|
2001-08-21 20:18:27 +00:00
|
|
|
{
|
2006-11-13 04:33:45 +00:00
|
|
|
/* All recognized actions */
|
|
|
|
case HalHaltRoutine:
|
2023-06-20 20:28:31 +00:00
|
|
|
case HalPowerDownRoutine:
|
|
|
|
case HalRestartRoutine:
|
2006-11-13 04:33:45 +00:00
|
|
|
case HalRebootRoutine:
|
2023-06-20 20:28:31 +00:00
|
|
|
{
|
- Stub out DbgKdWriteVirtualMemoryApi, DbgKdReadPhysicalMemoryApi, DbgKdWritePhysicalMemoryApi, DbgKdWriteBreakPointExApi, DbgKdRestoreBreakPointExApi, DbgKdSearchMemoryApi and DbgKdFillMemoryApi cases more properly.
- Fail on physical memory write like we do for read too.
- Don't handle OldVlm1/2 as they appear to be deprecated and unhandled in Windows.
- Implement HalHaltSystem to halt execution in a portable way. Default to xHalHaltSystem, a simple infinite loop, if we get called before HAL has initialized. Use this in KiBugCheckDebugBreak and the system shutdown handler instead of x86/AMD64/ARM intrinsics.
- Don't try to halt the CPU if KeBugCheck has been called 3 times or more -- if this happens, something has gone very wrong, and we shouldn't try to do anything special. Just loop infinitely.
- Fix KiBugCheckDebugBreak -- it shouldn't halt execution when called for the first chance as bugcheck callbacks have not been invoked at this point (nor has the BSOD been displayed). Use SEH to protect against a crash instead of checking KdDebuggerNotPresent as the debugger, if it is present, *could* disconnect while the trap is being handled. Also, don't halt execution if the debugger handled the breakpoint, just break again.
- Don't call MmMapIoSpace from HalpReboot! The reboot might take place at elevated IRQL (as high as HIGH_LEVEL if called from KeBugCheck), and thus can't use any Mm support routines. Use a PTE from the reserved HAL region and map it ourselves instead as done in the BIOS call code.
- Acquire the display ownership in HalReturnToFirmware in case the caller hasn't done so (as done in the KD reboot routine, for example).
- Just include ntndk.h in hal.h instead of including 6 NDK headers (which turns into more than half of the NDK anyway since those headers include other NDK headers).
- Crashing and rebooting from KD now works properly.
svn path=/trunk/; revision=43380
2009-10-11 20:16:45 +00:00
|
|
|
/* Acquire the display */
|
|
|
|
InbvAcquireDisplayOwnership();
|
|
|
|
|
2006-11-13 04:33:45 +00:00
|
|
|
/* Call the internal reboot function */
|
|
|
|
HalpReboot();
|
2023-06-20 20:28:31 +00:00
|
|
|
}
|
2006-11-13 04:33:45 +00:00
|
|
|
|
|
|
|
/* Anything else */
|
|
|
|
default:
|
2023-06-20 20:28:31 +00:00
|
|
|
{
|
2006-11-13 04:33:45 +00:00
|
|
|
/* Print message and break */
|
|
|
|
DbgPrint("HalReturnToFirmware called!\n");
|
|
|
|
DbgBreakPoint();
|
2023-06-20 20:28:31 +00:00
|
|
|
}
|
2001-08-21 20:18:27 +00:00
|
|
|
}
|
|
|
|
}
|
2023-06-20 20:28:31 +00:00
|
|
|
#endif // _MINIHAL_
|
2001-08-21 20:18:27 +00:00
|
|
|
|
|
|
|
/* EOF */
|