[Kernel/Memory] Implement DATETIME0

This commit is contained in:
wheremyfoodat 2022-09-24 03:57:21 +03:00
parent 61212c9341
commit 4da023c236
3 changed files with 19 additions and 1 deletions

View file

@ -6,6 +6,7 @@ namespace ConfigMem {
enum : u32 { enum : u32 {
KernelVersionMinor = 0x1FF80002, KernelVersionMinor = 0x1FF80002,
KernelVersionMajor = 0x1FF80003, KernelVersionMajor = 0x1FF80003,
AppMemAlloc = 0x1FF80040 AppMemAlloc = 0x1FF80040,
Datetime0 = 0x1FF81020
}; };
} }

View file

@ -118,6 +118,7 @@ public:
u32 getLinearHeapVaddr(); u32 getLinearHeapVaddr();
u8* getFCRAM() { return fcram; } u8* getFCRAM() { return fcram; }
u64 timeSince3DSEpoch();
// Returns whether "addr" is aligned to a page (4096 byte) boundary // Returns whether "addr" is aligned to a page (4096 byte) boundary
static constexpr bool isAligned(u32 addr) { static constexpr bool isAligned(u32 addr) {

View file

@ -2,6 +2,7 @@
#include "config_mem.hpp" #include "config_mem.hpp"
#include "resource_limits.hpp" #include "resource_limits.hpp"
#include <cassert> #include <cassert>
#include <chrono> // For time since epoch
using namespace KernelMemoryTypes; using namespace KernelMemoryTypes;
@ -85,7 +86,11 @@ u32 Memory::read32(u32 vaddr) {
return *(u32*)(pointer + offset); return *(u32*)(pointer + offset);
} else { } else {
switch (vaddr) { switch (vaddr) {
case ConfigMem::Datetime0: return u32(timeSince3DSEpoch()); // ms elapsed since Jan 1 1900, bottom 32 bits
case ConfigMem::Datetime0 + 4: return u32(timeSince3DSEpoch() >> 32); // top 32 bits
case ConfigMem::AppMemAlloc: return appResourceLimits.maxCommit; case ConfigMem::AppMemAlloc: return appResourceLimits.maxCommit;
case 0x1FF81000: return 0; // TODO: Figure out what this config mem address does
default: default:
Helpers::panic("Unimplemented 32-bit read, addr: %08X", vaddr); Helpers::panic("Unimplemented 32-bit read, addr: %08X", vaddr);
break; break;
@ -351,3 +356,14 @@ void Memory::mapGSPSharedMemory(u32 vaddr, u32 myPerms, u32 otherPerms) {
if (!result.has_value()) if (!result.has_value())
Helpers::panic("Failed to allocated GSP shared memory"); Helpers::panic("Failed to allocated GSP shared memory");
} }
// Get the number of ms since Jan 1 1900
u64 Memory::timeSince3DSEpoch() {
using namespace std::chrono;
// ms since Jan 1 1970
milliseconds ms = duration_cast<milliseconds>(system_clock::now().time_since_epoch());
// ms between Jan 1 1900 and Jan 1 1970 (2208988800 seconds elapsed between the two)
const u64 offset = 2208988800ull * 1000;
return ms.count() + offset;
}