From 7a21d93fece68ad048bd03f8b14790d0a27e3658 Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Sat, 26 Aug 2023 18:25:15 +0300 Subject: [PATCH] Move TLS to system memory for now --- src/core/memory.cpp | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/core/memory.cpp b/src/core/memory.cpp index e8163bf4..628e2ad6 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -34,17 +34,10 @@ void Memory::reset() { writeTable[i] = 0; } - // Map (32 * 4) KB of FCRAM before the stack for the TLS of each thread - std::optional tlsBaseOpt = findPaddr(32 * 4_KB); - if (!tlsBaseOpt.has_value()) { // Should be unreachable but still good to have - Helpers::panic("Failed to allocate memory for thread-local storage"); - } - - u32 basePaddrForTLS = tlsBaseOpt.value(); for (u32 i = 0; i < appResourceLimits.maxThreads; i++) { + u32 index = allocateSysMemory(4_KB); u32 vaddr = VirtualAddrs::TLSBase + i * VirtualAddrs::TLSSize; - allocateMemory(vaddr, basePaddrForTLS, VirtualAddrs::TLSSize, true); - basePaddrForTLS += VirtualAddrs::TLSSize; + allocateMemory(vaddr, index, VirtualAddrs::TLSSize, true, true, true, false, false, true); } // Initialize shared memory blocks and reserve memory for them @@ -399,7 +392,7 @@ u32 Memory::allocateSysMemory(u32 size) { Helpers::panic("Memory::allocateSysMemory: Overflowed OS FCRAM"); } - const u32 pageCount = size / pageSize; // Number of pages that will be used up + const u32 pageCount = size / pageSize; // Number of pages that will be used up const u32 startIndex = FCRAM_SIZE - usedSystemMemory - size; // Starting FCRAM index const u32 startingPage = startIndex / pageSize;