From c278f082299c4475fee1fa6b2b97c80980382ce0 Mon Sep 17 00:00:00 2001 From: ergo720 <45463469+ergo720@users.noreply.github.com> Date: Thu, 22 Aug 2024 00:28:11 +0200 Subject: [PATCH] HalBootSMCVideoMode + setup initial video mode from smc --- nboxkrnl/hal/hal.cpp | 6 +++++- nboxkrnl/hal/hal.hpp | 2 ++ nboxkrnl/hal/halp.cpp | 9 +++++++++ nboxkrnl/hal/halp.hpp | 13 +++++++++++++ nboxkrnl/ke/thunk.cpp | 2 +- 5 files changed, 30 insertions(+), 2 deletions(-) diff --git a/nboxkrnl/hal/hal.cpp b/nboxkrnl/hal/hal.cpp index ed7f815..fe20a00 100644 --- a/nboxkrnl/hal/hal.cpp +++ b/nboxkrnl/hal/hal.cpp @@ -29,13 +29,15 @@ VOID HalInitSystem() KiIdt[IDT_INT_VECTOR_BASE + 0] = ((uint64_t)0x8 << 16) | ((uint64_t)&HalpClockIsr & 0x0000FFFF) | (((uint64_t)&HalpClockIsr & 0xFFFF0000) << 32) | ((uint64_t)0x8E00 << 32); HalEnableSystemInterrupt(0, Edge); - // Connect SMBUS interrupt + // Connect the SMBUS interrupt KeInitializeEvent(&HalpSmbusLock, SynchronizationEvent, 1); KeInitializeEvent(&HalpSmbusComplete, NotificationEvent, 0); KeInitializeDpc(&HalpSmbusDpcObject, HalpSmbusDpcRoutine, nullptr); KiIdt[IDT_INT_VECTOR_BASE + 11] = ((uint64_t)0x8 << 16) | ((uint64_t)&HalpSmbusIsr & 0x0000FFFF) | (((uint64_t)&HalpSmbusIsr & 0xFFFF0000) << 32) | ((uint64_t)0x8E00 << 32); HalEnableSystemInterrupt(11, LevelSensitive); + HalpInitSMCstate(); + if (XboxType == SYSTEM_DEVKIT) { XboxHardwareInfo.Flags |= 2; } @@ -191,3 +193,5 @@ EXPORTNUM(50) NTSTATUS XBOXAPI HalWriteSMBusValue return Status; } + +EXPORTNUM(356) ULONG HalBootSMCVideoMode = SMC_VIDEO_MODE_NONE; diff --git a/nboxkrnl/hal/hal.hpp b/nboxkrnl/hal/hal.hpp index 60e3f8b..5971c5b 100644 --- a/nboxkrnl/hal/hal.hpp +++ b/nboxkrnl/hal/hal.hpp @@ -74,6 +74,8 @@ EXPORTNUM(50) DLLEXPORT NTSTATUS XBOXAPI HalWriteSMBusValue ULONG DataValue ); +EXPORTNUM(356) DLLEXPORT extern ULONG HalBootSMCVideoMode; + #ifdef __cplusplus } #endif diff --git a/nboxkrnl/hal/halp.cpp b/nboxkrnl/hal/halp.cpp index 99a2a8b..a8c9ae8 100644 --- a/nboxkrnl/hal/halp.cpp +++ b/nboxkrnl/hal/halp.cpp @@ -2,6 +2,7 @@ * ergo720 Copyright (c) 2023 */ +#include "hal.hpp" #include "halp.hpp" #include @@ -68,6 +69,14 @@ VOID HalpInitPIT() } } +VOID HalpInitSMCstate() +{ + ULONG BootVideoMode; + if (NT_SUCCESS(HalReadSMBusValue(SMC_READ_ADDR, SMC_VIDEO_MODE_COMMAND, FALSE, &BootVideoMode))) { + HalBootSMCVideoMode = BootVideoMode; + } +} + static BOOL HalpIsCmosUpdatingTime() { outb(CMOS_PORT_CMD, 0x0A); diff --git a/nboxkrnl/hal/halp.hpp b/nboxkrnl/hal/halp.hpp index 66063ee..160328e 100644 --- a/nboxkrnl/hal/halp.hpp +++ b/nboxkrnl/hal/halp.hpp @@ -64,6 +64,18 @@ // SMBUS sw addresses #define EEPROM_WRITE_ADDR 0xA8 #define EEPROM_READ_ADDR 0xA9 +#define SMC_WRITE_ADDR 0x20 +#define SMC_READ_ADDR 0x21 + +// SMC video mode values +#define SMC_VIDEO_MODE_COMMAND 0x04 +#define SMC_VIDEO_MODE_SCART 0x00 +#define SMC_VIDEO_MODE_HDTV 0x01 +#define SMC_VIDEO_MODE_VGA 0x02 +#define SMC_VIDEO_MODE_RFU 0x03 +#define SMC_VIDEO_MODE_SVIDEO 0x04 +#define SMC_VIDEO_MODE_STANDARD 0x06 +#define SMC_VIDEO_MODE_NONE 0x07 extern KDPC HalpSmbusDpcObject; @@ -122,6 +134,7 @@ inline constexpr VOID(XBOXAPI *const SwIntHandlers[])() = { [[noreturn]] VOID HalpShutdownSystem(); VOID HalpInitPIC(); VOID HalpInitPIT(); +VOID HalpInitSMCstate(); VOID HalpReadCmosTime(PTIME_FIELDS TimeFields); VOID HalpCheckUnmaskedInt(); VOID XBOXAPI HalpSmbusDpcRoutine(PKDPC Dpc, PVOID DeferredContext, PVOID SystemArgument1, PVOID SystemArgument2); diff --git a/nboxkrnl/ke/thunk.cpp b/nboxkrnl/ke/thunk.cpp index 9bde3bf..133ea0e 100644 --- a/nboxkrnl/ke/thunk.cpp +++ b/nboxkrnl/ke/thunk.cpp @@ -376,7 +376,7 @@ ULONG KernelThunkTable[379] = (ULONG)FUNC(nullptr), //(ULONG)VARIABLE(&XboxLANKey), // 0x0161 (353) (ULONG)FUNC(nullptr), //(ULONG)VARIABLE(&XboxAlternateSignatureKeys), // 0x0162 (354) (ULONG)FUNC(nullptr), //(ULONG)VARIABLE(&XePublicKeyData), // 0x0163 (355) - (ULONG)FUNC(nullptr), //(ULONG)VARIABLE(&HalBootSMCVideoMode), // 0x0164 (356) + (ULONG)VARIABLE(&HalBootSMCVideoMode), // 0x0164 (356) (ULONG)FUNC(nullptr), //(ULONG)VARIABLE(&IdexChannelObject), // 0x0165 (357) (ULONG)FUNC(nullptr), //(ULONG)FUNC(&HalIsResetOrShutdownPending), // 0x0166 (358) (ULONG)FUNC(nullptr), //(ULONG)FUNC(&IoMarkIrpMustComplete), // 0x0167 (359)