Skip to content

Commit

Permalink
HalBootSMCVideoMode + setup initial video mode from smc
Browse files Browse the repository at this point in the history
  • Loading branch information
ergo720 committed Aug 21, 2024
1 parent ed40a1a commit c278f08
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
6 changes: 5 additions & 1 deletion nboxkrnl/hal/hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -191,3 +193,5 @@ EXPORTNUM(50) NTSTATUS XBOXAPI HalWriteSMBusValue

return Status;
}

EXPORTNUM(356) ULONG HalBootSMCVideoMode = SMC_VIDEO_MODE_NONE;
2 changes: 2 additions & 0 deletions nboxkrnl/hal/hal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ EXPORTNUM(50) DLLEXPORT NTSTATUS XBOXAPI HalWriteSMBusValue
ULONG DataValue
);

EXPORTNUM(356) DLLEXPORT extern ULONG HalBootSMCVideoMode;

#ifdef __cplusplus
}
#endif
Expand Down
9 changes: 9 additions & 0 deletions nboxkrnl/hal/halp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* ergo720 Copyright (c) 2023
*/

#include "hal.hpp"
#include "halp.hpp"
#include <string.h>

Expand Down Expand Up @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions nboxkrnl/hal/halp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion nboxkrnl/ke/thunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c278f08

Please sign in to comment.