libstrat: namespace remaining non-namespaced code. more new-ipc updates

This commit is contained in:
Michael Scire 2019-10-19 17:42:53 -07:00 committed by SciresM
parent ae2fa2fa60
commit 0b22af1206
68 changed files with 1257 additions and 2118 deletions

View file

@ -36,7 +36,7 @@ namespace sts::boot {
/* Helpers. */
bool IsUsbClockValid() {
uintptr_t car_regs = GetIoMapping(0x60006000ul, 0x1000);
uintptr_t car_regs = dd::GetIoMapping(0x60006000ul, 0x1000);
const u32 pllu = reg::Read(car_regs + 0xC0);
const u32 utmip = reg::Read(car_regs + 0x480);

View file

@ -79,12 +79,12 @@ namespace sts::boot {
/* Helper functions. */
void InitializeRegisterBaseAddresses() {
g_disp1_regs = GetIoMapping(Disp1Base, Disp1Size);
g_dsi_regs = GetIoMapping(DsiBase, DsiSize);
g_clk_rst_regs = GetIoMapping(ClkRstBase, ClkRstSize);
g_gpio_regs = GetIoMapping(GpioBase, GpioSize);
g_apb_misc_regs = GetIoMapping(ApbMiscBase, ApbMiscSize);
g_mipi_cal_regs = GetIoMapping(MipiCalBase, MipiCalSize);
g_disp1_regs = dd::GetIoMapping(Disp1Base, Disp1Size);
g_dsi_regs = dd::GetIoMapping(DsiBase, DsiSize);
g_clk_rst_regs = dd::GetIoMapping(ClkRstBase, ClkRstSize);
g_gpio_regs = dd::GetIoMapping(GpioBase, GpioSize);
g_apb_misc_regs = dd::GetIoMapping(ApbMiscBase, ApbMiscSize);
g_mipi_cal_regs = dd::GetIoMapping(MipiCalBase, MipiCalSize);
}
inline void DoRegisterWrites(uintptr_t base_address, const RegisterWrite *reg_writes, size_t num_writes) {
@ -418,7 +418,7 @@ namespace sts::boot {
/* Nintendo waits 5 frames before continuing. */
{
const uintptr_t host1x_vaddr = GetIoMapping(0x500030a4, 4);
const uintptr_t host1x_vaddr = dd::GetIoMapping(0x500030a4, 4);
const u32 start_val = reg::Read(host1x_vaddr);
while (reg::Read(host1x_vaddr) < start_val + 5) {
/* spinlock here. */

View file

@ -59,18 +59,23 @@ extern "C" {
alignas(16) u8 __nx_exception_stack[0x1000];
u64 __nx_exception_stack_size = sizeof(__nx_exception_stack);
void __libnx_exception_handler(ThreadExceptionDump *ctx);
void __libstratosphere_exception_handler(AtmosphereFatalErrorContext *ctx);
}
sts::ncm::TitleId __stratosphere_title_id = sts::ncm::TitleId::Boot;
namespace sts::ams {
ncm::TitleId StratosphereTitleId = ncm::TitleId::Boot;
void ExceptionHandler(FatalErrorContext *ctx) {
/* We're boot sysmodule, so manually reboot to fatal error. */
boot::RebootForFatalError(ctx);
}
}
using namespace sts;
void __libnx_exception_handler(ThreadExceptionDump *ctx) {
StratosphereCrashHandler(ctx);
}
void __libstratosphere_exception_handler(AtmosphereFatalErrorContext *ctx) {
/* We're boot sysmodule, so manually reboot to fatal error. */
boot::RebootForFatalError(ctx);
ams::CrashHandler(ctx);
}
void __libnx_initheap(void) {
@ -89,13 +94,13 @@ void __appInit(void) {
hos::SetVersionForLibnx();
/* Initialize services we need (TODO: NCM) */
DoWithSmSession([&]() {
sm::DoWithSession([&]() {
R_ASSERT(fsInitialize());
R_ASSERT(splInitialize());
R_ASSERT(pmshellInitialize());
});
CheckAtmosphereVersion(CURRENT_ATMOSPHERE_VERSION);
ams::CheckApiVersion();
}
void __appExit(void) {

View file

@ -13,7 +13,8 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stratosphere/spl.hpp>
#include <stratosphere/spl/smc/spl_smc.hpp>
#include "boot_pmc_wrapper.hpp"
namespace sts::boot {
@ -31,29 +32,22 @@ namespace sts::boot {
return (phys_addr & 3) == 0 && PmcPhysStart <= phys_addr && phys_addr <= PmcPhysEnd;
}
inline u32 SmcAtmosphereReadWriteRegister(u32 phys_addr, u32 value, u32 mask) {
SecmonArgs args;
args.X[0] = SmcFunctionId_AtmosphereReadWriteRegister;
args.X[1] = phys_addr;
args.X[2] = mask;
args.X[3] = value;
R_ASSERT(svcCallSecureMonitor(&args));
STS_ASSERT(args.X[0] == 0);
return static_cast<u32>(args.X[1]);
inline u32 ReadWriteRegisterImpl(uintptr_t phys_addr, u32 value, u32 mask) {
u32 out_value;
R_ASSERT(spl::smc::ConvertResult(spl::smc::AtmosphereReadWriteRegister(phys_addr, mask, value, &out_value)));
return out_value;
}
}
u32 ReadPmcRegister(u32 phys_addr) {
STS_ASSERT(IsValidPmcAddress(phys_addr));
return SmcAtmosphereReadWriteRegister(phys_addr, 0, 0);
return ReadWriteRegisterImpl(phys_addr, 0, 0);
}
void WritePmcRegister(u32 phys_addr, u32 value, u32 mask) {
STS_ASSERT(IsValidPmcAddress(phys_addr));
SmcAtmosphereReadWriteRegister(phys_addr, value, mask);
ReadWriteRegisterImpl(phys_addr, value, mask);
}
}

View file

@ -37,22 +37,22 @@ namespace sts::boot {
/* Helpers. */
void ClearIram() {
/* Make page FFs. */
memset(g_work_page, 0xFF, sizeof(g_work_page));
std::memset(g_work_page, 0xFF, sizeof(g_work_page));
/* Overwrite all of IRAM with FFs. */
for (size_t ofs = 0; ofs < IramSize; ofs += sizeof(g_work_page)) {
CopyToIram(IramBase + ofs, g_work_page, sizeof(g_work_page));
ams::CopyToIram(IramBase + ofs, g_work_page, sizeof(g_work_page));
}
}
void DoRebootToPayload(AtmosphereFatalErrorContext *ctx) {
void DoRebootToPayload(ams::FatalErrorContext *ctx) {
/* Ensure clean IRAM state. */
ClearIram();
/* Copy in payload. */
for (size_t ofs = 0; ofs < fusee_primary_bin_size; ofs += 0x1000) {
std::memcpy(g_work_page, &fusee_primary_bin[ofs], std::min(static_cast<size_t>(fusee_primary_bin_size - ofs), size_t(0x1000)));
CopyToIram(IramPayloadBase + ofs, g_work_page, 0x1000);
ams::CopyToIram(IramPayloadBase + ofs, g_work_page, 0x1000);
}
@ -60,10 +60,10 @@ namespace sts::boot {
if (ctx != nullptr) {
std::memset(g_work_page, 0xCC, sizeof(g_work_page));
std::memcpy(g_work_page, ctx, sizeof(*ctx));
CopyToIram(IramPayloadBase + IramPayloadMaxSize, g_work_page, sizeof(g_work_page));
ams::CopyToIram(IramPayloadBase + IramPayloadMaxSize, g_work_page, sizeof(g_work_page));
}
RebootToIramPayload();
ams::ForceRebootToIramPayload();
}
}
@ -72,7 +72,7 @@ namespace sts::boot {
DoRebootToPayload(nullptr);
}
void RebootForFatalError(AtmosphereFatalErrorContext *ctx) {
void RebootForFatalError(ams::FatalErrorContext *ctx) {
DoRebootToPayload(ctx);
}

View file

@ -25,6 +25,6 @@ namespace sts::boot {
void ShutdownSystem();
/* Atmosphere power utilities. */
void RebootForFatalError(AtmosphereFatalErrorContext *ctx);
void RebootForFatalError(ams::FatalErrorContext *ctx);
}

View file

@ -39,7 +39,7 @@ namespace sts::gpio {
uintptr_t GetBaseAddress() {
if (!g_initialized_gpio_vaddr) {
g_gpio_vaddr = GetIoMapping(PhysicalBase, 0x1000);
g_gpio_vaddr = dd::GetIoMapping(PhysicalBase, 0x1000);
g_initialized_gpio_vaddr = true;
}
return g_gpio_vaddr;

View file

@ -88,7 +88,7 @@ namespace sts::i2c::driver::impl {
12, 22, 3, 7, 15, 6
};
const uintptr_t registers = GetIoMapping(0x60006000ul, 0x1000);
const uintptr_t registers = dd::GetIoMapping(0x60006000ul, 0x1000);
const size_t idx = ConvertToIndex(bus);
this->clk_src_reg = registers + s_clk_src_offsets[idx];
this->clk_en_reg = registers + s_clk_en_offsets[idx];
@ -102,7 +102,7 @@ namespace sts::i2c::driver::impl {
0x0000, 0x0400, 0x0500, 0x0700, 0x1000, 0x1100
};
const uintptr_t registers = GetIoMapping(0x7000c000ul, 0x2000) + s_offsets[ConvertToIndex(bus)];
const uintptr_t registers = dd::GetIoMapping(0x7000c000ul, 0x2000) + s_offsets[ConvertToIndex(bus)];
return reinterpret_cast<Registers *>(registers);
}

View file

@ -44,7 +44,7 @@ namespace sts::pinmux {
uintptr_t GetBaseAddress() {
if (!g_initialized_pinmux_vaddr) {
g_pinmux_vaddr = GetIoMapping(ApbMiscPhysicalBase, 0x4000);
g_pinmux_vaddr = dd::GetIoMapping(ApbMiscPhysicalBase, 0x4000);
g_initialized_pinmux_vaddr = true;
}
return g_pinmux_vaddr;