From 1a4295c3da5f40fa9bc89185889adc533bdb50f7 Mon Sep 17 00:00:00 2001 From: ergo720 Date: Mon, 22 Jan 2018 16:06:17 +0100 Subject: [PATCH] HalIsResetOrShutdownPending implementation --- src/CxbxKrnl/EmuKrnlHal.cpp | 14 +++++++++++--- src/devices/SMCDevice.cpp | 14 ++++++++++++++ src/devices/SMCDevice.h | 6 ++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/CxbxKrnl/EmuKrnlHal.cpp b/src/CxbxKrnl/EmuKrnlHal.cpp index ac4b91247..216fd8ec2 100644 --- a/src/CxbxKrnl/EmuKrnlHal.cpp +++ b/src/CxbxKrnl/EmuKrnlHal.cpp @@ -684,9 +684,14 @@ XBSYSAPI EXPORTNUM(358) xboxkrnl::BOOLEAN NTAPI xboxkrnl::HalIsResetOrShutdownPe { LOG_FUNC(); - LOG_UNIMPLEMENTED(); + BOOLEAN ret = FALSE; + uint8_t CommandCode; + uint32_t DataValue; + g_SMC->GetResetOrShutdownCode(&CommandCode, &DataValue); - RETURN(FALSE); + if (CommandCode != 0) { ret = TRUE; } + + RETURN(ret); } // ****************************************************************** @@ -699,7 +704,10 @@ XBSYSAPI EXPORTNUM(360) xboxkrnl::NTSTATUS NTAPI xboxkrnl::HalInitiateShutdown { LOG_FUNC(); - xboxkrnl::HalWriteSMBusValue(SMBUS_SMC_SLAVE_ADDRESS, SMC_COMMAND_RESET, 0, SMC_RESET_ASSERT_SHUTDOWN); + uint8_t CommandCode = SMC_COMMAND_RESET; + uint32_t DataValue = SMC_RESET_ASSERT_SHUTDOWN; + g_SMC->SetResetOrShutdownCode(&CommandCode, &DataValue); + xboxkrnl::HalWriteSMBusValue(SMBUS_SMC_SLAVE_ADDRESS, CommandCode, 0, DataValue); RETURN(S_OK); } diff --git a/src/devices/SMCDevice.cpp b/src/devices/SMCDevice.cpp index 026e9e3bb..3b83ba6d1 100644 --- a/src/devices/SMCDevice.cpp +++ b/src/devices/SMCDevice.cpp @@ -75,6 +75,8 @@ void SMCDevice::Init() buffer[SMC_COMMAND_AV_PACK] = AV_PACK_HDTV; // see http://xboxdevwiki.net/PIC#The_AV_Pack buffer[SMC_COMMAND_LED_SEQUENCE] = LED::GREEN; buffer[SMC_COMMAND_SCRATCH] = 0; // http://xboxdevwiki.net/PIC#Scratch_register_values + ResetOrShutdownCommandCode.store(0); + ResetOrShutdownDataValue.store(0); } void SMCDevice::Reset() @@ -209,3 +211,15 @@ void SMCDevice::WriteBlock(uint8_t command, uint8_t* data, int length) { // TODO } + +void SMCDevice::GetResetOrShutdownCode(uint8_t* CommandCode, uint32_t* DataValue) +{ + *CommandCode = ResetOrShutdownCommandCode.load(); + *DataValue = ResetOrShutdownDataValue.load(); +} + +void SMCDevice::SetResetOrShutdownCode(uint8_t* CommandCode, uint32_t* DataValue) +{ + ResetOrShutdownCommandCode.store(*CommandCode); + ResetOrShutdownDataValue.store(*DataValue); +} diff --git a/src/devices/SMCDevice.h b/src/devices/SMCDevice.h index dd0cfabbb..a43cc0d40 100644 --- a/src/devices/SMCDevice.h +++ b/src/devices/SMCDevice.h @@ -36,6 +36,7 @@ #pragma once #include "SMDevice.h" +#include // This https://upload.wikimedia.org/wikipedia/commons/9/94/Xbox-Motherboard-FR.jpg shows : // PIC16LC63A-04/SO @@ -119,10 +120,15 @@ public: void WriteByte(uint8_t command, uint8_t value); void WriteWord(uint8_t command, uint16_t value); void WriteBlock(uint8_t command, uint8_t* data, int length); + void GetResetOrShutdownCode(uint8_t* CommandCode, uint32_t* DataValue); + void SetResetOrShutdownCode(uint8_t* CommandCode, uint32_t* DataValue); private: HardwareModel m_HardwareModel; int m_PICVersionStringIndex = 0; uint8_t buffer[256] = {}; + // variables used by the SMC to know a reset / shutdown is pending + std::atomic ResetOrShutdownCommandCode; + std::atomic ResetOrShutdownDataValue; }; extern SMCDevice* g_SMC;