--memory-stats flag

This commit is contained in:
Kelvin Sherlock 2013-02-17 21:54:45 -05:00
parent 276b0c18eb
commit 3fc0839807
3 changed files with 56 additions and 32 deletions

View File

@ -32,12 +32,14 @@ struct {
bool traceToolBox;
bool traceMPW;
} Flags = { 16 * 1024 * 1024, 8 * 1024, 68030, false, false, false, false, false};
bool memoryStats;
} Flags = { 16 * 1024 * 1024, 8 * 1024, 68030, false, false, false, false, false, false};
const uint32_t kGlobalSize = 0x10000;
// retained to make debugging easier.
uint8_t *Memory;
uint8_t *Memory = nullptr;
uint32_t MemorySize = 0;
#if 0
@ -66,7 +68,6 @@ uint32_t EmulatedNewPtr(uint32_t size)
uint8_t ReadByte(const void *data, uint32_t offset)
{
offset &= 0xffffff;
if (offset >= MemorySize) return 0;
return ((uint8_t *)data)[offset];
}
@ -85,7 +86,6 @@ uint32_t ReadLong(const void *data, uint32_t offset)
void WriteByte(void *data, uint32_t offset, uint8_t value)
{
offset &= 0xffffff;
if (offset >= MemorySize) return;
((uint8_t *)data)[offset] = value;
}
@ -93,8 +93,6 @@ void WriteWord(void *data, uint32_t offset, uint16_t value)
{
offset &= 0xffffff;
if (offset + 1 >= MemorySize) return;
((uint8_t *)data)[offset++] = value >> 8;
((uint8_t *)data)[offset++] = value;
}
@ -103,8 +101,6 @@ void WriteLong(void *data, uint32_t offset, uint32_t value)
{
offset &= 0xffffff;
if (offset + 3 >= MemorySize) return;
((uint8_t *)data)[offset++] = value >> 24;
((uint8_t *)data)[offset++] = value >> 16;
((uint8_t *)data)[offset++] = value >> 8;
@ -648,6 +644,7 @@ int main(int argc, char **argv)
kTraceGlobals,
kTraceToolBox,
kTraceMPW,
kMemoryStats,
};
static struct option LongOpts[] =
{
@ -658,7 +655,11 @@ int main(int argc, char **argv)
{ "trace-macsbug", no_argument, NULL, kTraceMacsBug },
{ "trace-globals", no_argument, NULL, kTraceGlobals },
{ "trace-toolbox", no_argument, NULL, kTraceToolBox },
{ "trace-tools", no_argument, NULL, kTraceToolBox },
{ "trace-mpw", no_argument, NULL, kTraceMPW },
{ "memory-stats", no_argument, NULL, kMemoryStats },
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'V' },
{ NULL, 0, NULL, 0 }
@ -688,6 +689,10 @@ int main(int argc, char **argv)
case kTraceMPW:
Flags.traceMPW = true;
break;
case kMemoryStats:
Flags.memoryStats = true;
break;
case 'm':
if (!parse_number(optarg, &Flags.machine))
@ -844,6 +849,11 @@ int main(int argc, char **argv)
cpuExecuteInstruction();
}
if (Flags.memoryStats)
{
MM::Native::PrintMemoryStats();
}
uint32_t rv = MPW::ExitStatus();
if (rv > 0xff) rv = 0xff;

View File

@ -48,7 +48,8 @@ namespace
bool alloc_handle_block()
{
const unsigned HandleCount = 128;
const unsigned HandleCount = 128; // 512 bytes of handle blocks.
uint8_t *block = (uint8_t *)mplite_malloc(&pool,
sizeof(uint32_t) * HandleCount);
@ -70,8 +71,38 @@ namespace
namespace MM
{
bool Init(uint8_t *memory, uint32_t memorySize, uint32_t reserved)
{
int ok;
Memory = memory;
MemorySize = memorySize;
ok = mplite_init(&pool,
memory + reserved,
memorySize - reserved,
32,
NULL);
if (ok != MPLITE_OK) return false;
// allocate a handle master block...
if (!alloc_handle_block()) return false;
return true;
}
namespace Native {
void PrintMemoryStats()
{
mplite_print_stats(&pool, std::puts);
}
uint16_t NewPtr(uint32_t size, bool clear, uint32_t &mcptr)
{
// native pointers.
@ -113,27 +144,6 @@ namespace MM
}
bool Init(uint8_t *memory, uint32_t memorySize, uint32_t reserved)
{
int ok;
Memory = memory;
MemorySize = memorySize;
ok = mplite_init(&pool,
memory + reserved,
memorySize - reserved,
32,
NULL);
if (ok != MPLITE_OK) return false;
// allocate a handle block...
if (!alloc_handle_block()) return false;
return true;
}
uint16_t BlockMove(uint16_t trap)

View File

@ -11,11 +11,13 @@ namespace MM
memWZErr = -111,
};
bool Init(uint8_t *memory, uint32_t memorySize, uint32_t reserved);
// native functions.
namespace Native
{
void PrintMemoryStats();
uint16_t NewHandle(uint32_t size, uint32_t &handle);
uint16_t NewPtr(uint32_t size, bool clear, uint32_t &pointer);
@ -23,6 +25,8 @@ namespace MM
uint16_t DisposePtr(uint32_t pointer);
}
bool Init(uint8_t *memory, uint32_t memorySize, uint32_t reserved);
uint16_t BlockMove(uint16_t trap);
uint32_t CompactMem(uint16_t trap);