mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-06 22:25:41 +12:00
[Kernel/Memory] Implement DATETIME0
This commit is contained in:
parent
61212c9341
commit
4da023c236
3 changed files with 19 additions and 1 deletions
|
@ -6,6 +6,7 @@ namespace ConfigMem {
|
|||
enum : u32 {
|
||||
KernelVersionMinor = 0x1FF80002,
|
||||
KernelVersionMajor = 0x1FF80003,
|
||||
AppMemAlloc = 0x1FF80040
|
||||
AppMemAlloc = 0x1FF80040,
|
||||
Datetime0 = 0x1FF81020
|
||||
};
|
||||
}
|
|
@ -118,6 +118,7 @@ public:
|
|||
|
||||
u32 getLinearHeapVaddr();
|
||||
u8* getFCRAM() { return fcram; }
|
||||
u64 timeSince3DSEpoch();
|
||||
|
||||
// Returns whether "addr" is aligned to a page (4096 byte) boundary
|
||||
static constexpr bool isAligned(u32 addr) {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "config_mem.hpp"
|
||||
#include "resource_limits.hpp"
|
||||
#include <cassert>
|
||||
#include <chrono> // For time since epoch
|
||||
|
||||
using namespace KernelMemoryTypes;
|
||||
|
||||
|
@ -85,7 +86,11 @@ u32 Memory::read32(u32 vaddr) {
|
|||
return *(u32*)(pointer + offset);
|
||||
} else {
|
||||
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 0x1FF81000: return 0; // TODO: Figure out what this config mem address does
|
||||
default:
|
||||
Helpers::panic("Unimplemented 32-bit read, addr: %08X", vaddr);
|
||||
break;
|
||||
|
@ -350,4 +355,15 @@ void Memory::mapGSPSharedMemory(u32 vaddr, u32 myPerms, u32 otherPerms) {
|
|||
const auto result = allocateMemory(vaddr, paddr, size, true, r, w, x);
|
||||
if (!result.has_value())
|
||||
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;
|
||||
}
|
Loading…
Add table
Reference in a new issue