1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-23 20:18:04 +11:00

tools/emul: add "Min SP" debug value

This gives the maximum size of the stack at any given moment during the
execution of the program. It's useful to figure out if the stack gets
dangerously close to the heap.
This commit is contained in:
Virgil Dupras 2019-12-02 17:44:54 -05:00
parent 2f07d849a8
commit 66dacd1816
4 changed files with 19 additions and 4 deletions

View File

@ -186,5 +186,6 @@ int main()
termInfo.c_lflag |= ECHO;
termInfo.c_lflag |= ICANON;
tcsetattr(0, TCSAFLUSH, &termInfo);
emul_printdebug();
return 0;
}

View File

@ -48,6 +48,7 @@ Machine* emul_init()
{
memset(m.mem, 0, 0x10000);
m.ramstart = 0;
m.minsp = 0xffff;
for (int i=0; i<0x100; i++) {
m.iord[i] = NULL;
m.iowr[i] = NULL;
@ -65,6 +66,10 @@ bool emul_step()
{
if (!m.cpu.halted) {
Z80Execute(&m.cpu);
ushort newsp = m.cpu.R1.wr.SP;
if (newsp != 0 && newsp < m.minsp) {
m.minsp = newsp;
}
return true;
} else {
return false;
@ -75,3 +80,8 @@ void emul_loop()
{
while (emul_step());
}
void emul_printdebug()
{
fprintf(stderr, "Min SP: %04x\n", m.minsp);
}

View File

@ -2,15 +2,17 @@
#include <stdbool.h>
#include "libz80/z80.h"
typedef uint8_t (*IORD) ();
typedef void (*IOWR) (uint8_t data);
typedef byte (*IORD) ();
typedef void (*IOWR) (byte data);
typedef struct {
Z80Context cpu;
uint8_t mem[0x10000];
byte mem[0x10000];
// Set to non-zero to specify where ROM ends. Any memory write attempt
// below ramstart will trigger a warning.
uint16_t ramstart;
ushort ramstart;
// The minimum value reached by SP at any point during execution.
ushort minsp;
// Array of 0x100 function pointers to IO read and write routines. Leave to
// NULL when IO port is unhandled.
IORD iord[0x100];
@ -20,3 +22,4 @@ typedef struct {
Machine* emul_init();
bool emul_step();
void emul_loop();
void emul_printdebug();

View File

@ -186,5 +186,6 @@ int main()
termInfo.c_lflag |= ECHO;
termInfo.c_lflag |= ICANON;
tcsetattr(0, TCSAFLUSH, &termInfo);
emul_printdebug();
return 0;
}