fusee/exo: support dynamic control of invert flag for logging

This commit is contained in:
Michael Scire 2020-12-11 03:18:21 -08:00
parent 54872f504c
commit 245b159b98
4 changed files with 15 additions and 24 deletions

View File

@ -35,7 +35,7 @@ namespace ams::log {
#endif #endif
void Initialize(); void Initialize();
void Initialize(uart::Port port, u32 baud_rate); void Initialize(uart::Port port, u32 baud_rate, u32 flags);
void Finalize(); void Finalize();
void Printf(const char *fmt, ...) __attribute__((format(printf, 1, 2))); void Printf(const char *fmt, ...) __attribute__((format(printf, 1, 2)));

View File

@ -120,6 +120,10 @@ namespace ams::secmon {
return GetSecmonConfiguration().GetLogPort(); return GetSecmonConfiguration().GetLogPort();
} }
ALWAYS_INLINE u8 GetLogFlags() {
return GetSecmonConfiguration().GetLogFlags();
}
ALWAYS_INLINE u32 GetLogBaudRate() { ALWAYS_INLINE u32 GetLogBaudRate() {
return GetSecmonConfiguration().GetLogBaudRate(); return GetSecmonConfiguration().GetLogBaudRate();
} }

View File

@ -40,8 +40,8 @@ namespace ams::secmon {
ams::TargetFirmware target_firmware; ams::TargetFirmware target_firmware;
u32 flags[2]; u32 flags[2];
u16 lcd_vendor; u16 lcd_vendor;
u8 reserved0;
u8 log_port; u8 log_port;
u8 log_flags;
u32 log_baud_rate; u32 log_baud_rate;
u32 reserved1[2]; u32 reserved1[2];
EmummcConfiguration emummc_cfg; EmummcConfiguration emummc_cfg;
@ -60,7 +60,8 @@ namespace ams::secmon {
u8 log_port; u8 log_port;
u32 flags[2]; u32 flags[2];
u16 lcd_vendor; u16 lcd_vendor;
u16 reserved0; u8 log_flags;
u8 reserved0;
u32 log_baud_rate; u32 log_baud_rate;
u32 reserved1[(0x80 - 0x1C) / sizeof(u32)]; u32 reserved1[(0x80 - 0x1C) / sizeof(u32)];
@ -70,6 +71,7 @@ namespace ams::secmon {
this->flags[1] = storage.flags[1]; this->flags[1] = storage.flags[1];
this->lcd_vendor = storage.lcd_vendor; this->lcd_vendor = storage.lcd_vendor;
this->log_port = storage.log_port; this->log_port = storage.log_port;
this->log_flags = storage.log_flags;
this->log_baud_rate = storage.log_baud_rate != 0 ? storage.log_baud_rate : 115200; this->log_baud_rate = storage.log_baud_rate != 0 ? storage.log_baud_rate : 115200;
} }
@ -85,6 +87,7 @@ namespace ams::secmon {
constexpr fuse::SocType GetSocType() const { return static_cast<fuse::SocType>(this->soc_type); } constexpr fuse::SocType GetSocType() const { return static_cast<fuse::SocType>(this->soc_type); }
constexpr fuse::HardwareState GetHardwareState() const { return static_cast<fuse::HardwareState>(this->hardware_state); } constexpr fuse::HardwareState GetHardwareState() const { return static_cast<fuse::HardwareState>(this->hardware_state); }
constexpr uart::Port GetLogPort() const { return static_cast<uart::Port>(this->log_port); } constexpr uart::Port GetLogPort() const { return static_cast<uart::Port>(this->log_port); }
constexpr u8 GetLogFlags() const { return this->log_flags; }
constexpr u16 GetLcdVendor() const { return this->lcd_vendor; } constexpr u16 GetLcdVendor() const { return this->lcd_vendor; }
@ -113,6 +116,7 @@ namespace ams::secmon {
.log_port = uart::Port_ReservedDebug, .log_port = uart::Port_ReservedDebug,
.flags = { SecureMonitorConfigurationFlag_Default, SecureMonitorConfigurationFlag_None }, .flags = { SecureMonitorConfigurationFlag_Default, SecureMonitorConfigurationFlag_None },
.lcd_vendor = {}, .lcd_vendor = {},
.log_flags = {},
.reserved0 = {}, .reserved0 = {},
.log_baud_rate = 115200, .log_baud_rate = 115200,
.reserved1 = {}, .reserved1 = {},

View File

@ -20,28 +20,11 @@ namespace ams::log {
namespace { namespace {
constexpr inline uart::Port DefaultLogPort = uart::Port_ReservedDebug; constexpr inline uart::Port DefaultLogPort = uart::Port_ReservedDebug;
constexpr inline u32 DefaultLogFlags = static_cast<u32>(uart::Flag_None);
constexpr inline int DefaultBaudRate = 115200; constexpr inline int DefaultBaudRate = 115200;
constinit uart::Port g_log_port = DefaultLogPort; constinit uart::Port g_log_port = DefaultLogPort;
constinit bool g_initialized_uart = false; constinit bool g_initialized_uart = false;
ALWAYS_INLINE u32 GetPortFlags(uart::Port port) {
switch (port) {
case uart::Port_ReservedDebug:
/* Logging to the debug port. */
/* Don't invert transactions. */
return uart::Flag_None;
case uart::Port_LeftJoyCon:
/* Logging to left joy-con (e.g. with Joyless). */
/* Invert transactions. */
return uart::Flag_Inverted;
case uart::Port_RightJoyCon:
/* Logging to right joy-con (e.g. with Joyless). */
/* Invert transactions. */
return uart::Flag_Inverted;
AMS_UNREACHABLE_DEFAULT_CASE();
}
}
ALWAYS_INLINE void SetupUartClock(uart::Port port) { ALWAYS_INLINE void SetupUartClock(uart::Port port) {
/* The debug port must always be set up, for compatibility with official hos. */ /* The debug port must always be set up, for compatibility with official hos. */
pinmux::SetupUartA(); pinmux::SetupUartA();
@ -64,15 +47,15 @@ namespace ams::log {
} }
void Initialize() { void Initialize() {
return Initialize(DefaultLogPort, DefaultBaudRate); return Initialize(DefaultLogPort, DefaultBaudRate, DefaultLogFlags);
} }
void Initialize(uart::Port port, u32 baud_rate) { void Initialize(uart::Port port, u32 baud_rate, u32 flags) {
/* Initialize pinmux and clock for the target uart port. */ /* Initialize pinmux and clock for the target uart port. */
SetupUartClock(port); SetupUartClock(port);
/* Initialize the target uart port. */ /* Initialize the target uart port. */
uart::Initialize(port, baud_rate, GetPortFlags(port)); uart::Initialize(port, baud_rate, flags);
/* Note that we've initialized. */ /* Note that we've initialized. */
g_log_port = port; g_log_port = port;