News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Program crashes on memory access!

Started by indiocolifa, September 30, 2005, 06:19:27 AM

Previous topic - Next topic

indiocolifa

I'm progessing nicely with my 6502 emulator (a few opcodes are I think, properly emulated)...

the problem is that I'm trying to implement a step-by-step execution command. The preliminary code is:


/*----------------------------------------------------------------

   s : Step-by-step execution
   
  ---------------------------------------------------------------*/
procedure stepexec  (memptr     :   DWORD;
                     var regs   :   cpuRegs;
                     var clk    :   sysclk);@NODISPLAY;
var
    addr : WORD;
    dummy:WORD;
begin stepexec;

    push (ebx);
    mov (regs,ebx);

    IF (esi == 1) THEN    // use program counter as start
        mov (REGS_PTR.PC, addr);
     ELSE
        parsewArgs      (addr,dummy);
        IF (esi == $FFFF_FFFF) THEN jmp exitcmd; ENDIF;
        mov (addr, REGS_PTR.PC); // modify PC
    ENDIF;

exitcmd:   
    pop (ebx);
end stepexec;


Since I need to modify the processor registers, I pass regs:cpuRegs as reference, but when I want to modify the program counter:

mov (addr,REGS_PTR.PC);

the program crashes without reason.
(REGS_PTR is defined as a text equate = "(type cpuRegs[ebx])"

To give more information, the calling sequence before stepexec procedure is:

At main HLA module:


STATIC regs       : cpuRegs;
...
startMonitor    (regs, memBasePtr, clock);
...
// in StartMonitor procedure if 's' command is entered I call:

stepexec (memptr, regs, clk);



Here's the definition of startMonitor procedure:

procedure       startMonitor (var regs:cpuRegs; memptr : DWORD; var clk:sysclk);@nodisplay;



Thank you in advance for ya help!

Sevag.K

Quote from: indiocolifa on September 30, 2005, 06:19:27 AM

/*----------------------------------------------------------------

   s : Step-by-step execution
   
  ---------------------------------------------------------------*/
procedure stepexec  (memptr     :   DWORD;
                     var regs   :   cpuRegs;
                     var clk    :   sysclk);@NODISPLAY;
var
    addr : WORD;
    dummy:WORD;
begin stepexec;

    push (ebx);
    mov (regs,ebx);

    IF (esi == 1) THEN    // use program counter as start
        mov (REGS_PTR.PC, addr);
...


If the program works at this point... (make sure you are getting the proper reg ptr into addr)...

Quote
Since I need to modify the processor registers, I pass regs:cpuRegs as reference, but when I want to modify the program counter:

mov (addr,REGS_PTR.PC);

the program crashes without reason.
(REGS_PTR is defined as a text equate = "(type cpuRegs[ebx])"

... and crashes here, then the primary resaon such a thing happens is if EBX changes somehow between the point that it works and the point that it crashes.  Make sure any procedure you call preserves EBX.



indiocolifa

mmmm.. Maybe the parsewArgs procedure does not preserve EBX....

I'll check that and tell you the results.

Cheers

Hernan

indiocolifa

Yess....  :red

parsewargs pushes

PUSH(EAX);
PUSH(EBX);

...

and pops:

POP(EAX);
POP(EBX);

pops in incorrect order and does mess with regs...  :toothy

thank you ... Those are the very simple errors you can't distinguish when you're coding at 4:00 AM.
:8)