From b146399a7efa1b68bc1fb4204562e57597707785 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Thu, 15 Jan 2015 16:35:38 -0500 Subject: [PATCH] Fix StripAddress when > 16 megs of ram in use. --- bin/loader.cpp | 10 ++-------- toolbox/mm.cpp | 17 ++++++++++++----- toolbox/mm.h | 4 ++-- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/bin/loader.cpp b/bin/loader.cpp index 063710e..4c2a8ef 100644 --- a/bin/loader.cpp +++ b/bin/loader.cpp @@ -390,10 +390,6 @@ void GlobalInit() // 0x0a06 - MinusOne memoryWriteLong(0xffffffff, MacOS::MinusOne); - - // todo -- expects high stack, low heap. - // the allocator currently works from the top down, - // so put stack at top of memory? // 0x0130 -- ApplLimit memoryWriteLong(Flags.memorySize - Flags.stackSize - 1, MacOS::ApplLimit); @@ -405,7 +401,7 @@ void CreateStack() // allocate stack, set A7... uint32_t address; - uint16_t error; + //uint16_t error; #if 0 Flags.stackSize = (Flags.stackSize + 3) & ~0x03; @@ -892,10 +888,8 @@ int main(int argc, char **argv) // for pre-fetch. memorySetMemory(Memory, MemorySize); - // should we subtract memory from the top - // for the stack vs allocating it? - MM::Init(Memory, MemorySize - Flags.stackSize, kGlobalSize); + MM::Init(Memory, MemorySize, kGlobalSize, Flags.stackSize); OS::Init(); MPW::Init(argc, argv, defines); diff --git a/toolbox/mm.cpp b/toolbox/mm.cpp index fced9d2..ad94556 100644 --- a/toolbox/mm.cpp +++ b/toolbox/mm.cpp @@ -50,6 +50,7 @@ namespace uint8_t *Memory; uint32_t MemorySize; + uint32_t HeapSize; // queue of free Handles std::deque HandleQueue; @@ -104,16 +105,17 @@ namespace namespace MM { - bool Init(uint8_t *memory, uint32_t memorySize, uint32_t reserved) + bool Init(uint8_t *memory, uint32_t memorySize, uint32_t globals, uint32_t stack) { int ok; Memory = memory; MemorySize = memorySize; + HeapSize = memorySize - stack; ok = mplite_init(&pool, - memory + reserved, - memorySize - reserved, + memory + globals, + memorySize - globals - stack, 32, NULL); @@ -123,6 +125,9 @@ namespace MM if (!alloc_handle_block()) return false; + + // create system handles for the stack and global space? + return true; } @@ -761,7 +766,7 @@ namespace MM // MemorySize is the top of the heap. stack is after it. - return sp - MemorySize; + return sp - HeapSize; } @@ -1446,7 +1451,9 @@ namespace MM Log("%04x StripAddress(%08x)\n", trap, address); - address &= 0x00ffffff; + if (MemorySize <= 0x00ffffff) + address &= 0x00ffffff; + return address; } diff --git a/toolbox/mm.h b/toolbox/mm.h index d50b721..6e2ad99 100644 --- a/toolbox/mm.h +++ b/toolbox/mm.h @@ -32,7 +32,7 @@ namespace MM uint16_t HUnlock(uint32_t handle); } - bool Init(uint8_t *memory, uint32_t memorySize, uint32_t reserved); + bool Init(uint8_t *memory, uint32_t memorySize, uint32_t globals, uint32_t stack); uint16_t BlockMove(uint16_t trap); @@ -69,7 +69,7 @@ namespace MM uint16_t HPurge(uint16_t trap); uint16_t HNoPurge(uint16_t trap); - + uint16_t HSetRBit(uint16_t trap); uint16_t HClrRBit(uint16_t trap);