Re: [hatari-devel] Re: Hatari debugging help with WinUAE CPU core

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Hi,

On perjantai 24 tammikuu 2014, Nicolas Pomarède wrote:
> Le 23/01/2014 23:16, Eero Tamminen a écrit :
> > Attached patch implements that and adds several new exception points
> > for old UAE CPU core.  It's help looks following:
> > -------------------------------------------
> > $ src/hatari --exceptions help
> 
> regarding "--exceptions" I think it has a too broad meaning,

That's what "hatari --help" option is there for:
-------------------
....
Debug options:
  --debug or -D           Toggle whether CPU exceptions invoke debugger
  --exceptions <flags>    Which exceptions invoke debugger, see '--
exceptions help'
-------------------


> maybe you could use "--exception_debug" instead ?

That's way too long, it would make Hatari "--help" output too
wide for 80 cols console.  If you want it changed, please suggest
something more specific that's not longer than "--exceptions"
(current option & help already goes to 80 cols).

Already existing --debug options has also very broad meaning,
how I should rename that?


> Also, regarding the change in uae-cpu/newcpu.c, I think it adds too much
> debug code and can hide the real work in the exception emulation, making
> the code less clear.
> 
> I think you should leave unchanged :
> 
> -      case 2: M68000_AddCycles(50); break;	/* Bus error */
> -      case 3: M68000_AddCycles(50); break;	/* Address error */
> -      case 4: M68000_AddCycles(34); break;	/* Illegal instruction */
> -      case 5: M68000_AddCycles(38); break;	/* Div by zero */
> -      case 6: M68000_AddCycles(40); break;	/* CHK */
> -      case 7: M68000_AddCycles(34); break;	/* TRAPV */
> -      case 8: M68000_AddCycles(34); break;	/* Privilege violation */
> -      case 9: M68000_AddCycles(34); break;	/* Trace */
> -      case 10: M68000_AddCycles(34); break;	/* Line-A - probably wrong
> */ -      case 11: M68000_AddCycles(34); break;	/* Line-F - probably
> wrong */
> 
> 
> And add just after a call like :
> 
> if ( ( nr>=2 ) && ( nr<=11) && ( ExceptionDebugMask ) )
> 	DebugUI_Check_Interrupt_Mask ( nr );

I'm assuming you're more worried about modifying existing code
lines than adding single block of code there.  If that's true,
does the attached patch look better?


> Also, maybe make those modifications to cpu/newcpuc too ? It will be
> easier to merge both cpu later if they are as close as possible.

When looking WinUAE CPU code for:
1. Exception_ce000()
2. Exception_mmu()
3. Exception_normal()

Why 1) calls VDI emulation after MakeSR(),
3) before it, and 2) not at all?

And why there's debugger activation in Exception(),
instead of in exception_debug() that's called from
above listed functions (i.e. like it's done in old
UAE CPU core)?


(Exception handling there looks completely different, i.e. I don't
think adding exception debugging there to affect merging in either
direction.)


	- Eero
diff -r 32fe6f0bf5c3 src/uae-cpu/newcpu.c
--- a/src/uae-cpu/newcpu.c	Mon Jan 20 01:56:24 2014 +0200
+++ b/src/uae-cpu/newcpu.c	Fri Jan 24 23:54:46 2014 +0200
@@ -987,7 +987,7 @@
 	    put_long (m68k_areg(regs, 7)+2, last_fault_for_exception_3);
 	    put_word (m68k_areg(regs, 7)+6, last_op_for_exception_3);
 	    put_long (m68k_areg(regs, 7)+10, last_addr_for_exception_3);
-	    if (bExceptionDebugging) {
+	    if (ExceptionDebugMask & EXCEPT_ADDRESS) {
 	      fprintf(stderr,"Address Error at address $%x, PC=$%x\n",last_fault_for_exception_3,currpc);
 	      DebugUI(REASON_CPU_EXCEPTION);
 	    }
@@ -1014,7 +1014,7 @@
 	      fprintf(stderr, "Detected double bus error at address $%x, PC=$%lx => CPU halted!\n",
 	              BusErrorAddress, (long)currpc);
 	      unset_special(SPCFLAG_BUSERROR);
-	      if (bExceptionDebugging)
+	      if (ExceptionDebugMask & EXCEPT_BUS)
 	        DebugUI(REASON_CPU_EXCEPTION);
 	      else
 		DlgAlert_Notice("Detected double bus error => CPU halted!\nEmulation needs to be reset.\n");
@@ -1022,7 +1022,7 @@
 	      m68k_setstopped(true);
 	      return;
 	    }
-	    if (bExceptionDebugging && BusErrorAddress!=0xff8a00) {
+	    if ((ExceptionDebugMask & EXCEPT_BUS) && BusErrorAddress!=0xff8a00) {
 	      fprintf(stderr,"Bus Error at address $%x, PC=$%lx\n", BusErrorAddress, (long)currpc);
 	      DebugUI(REASON_CPU_EXCEPTION);
 	    }
@@ -1030,8 +1030,8 @@
     }
 
     /* Set PC and flags */
-    if (bExceptionDebugging && get_long (regs.vbr + 4*nr) == 0) {
-        write_log("Uninitialized exception handler #%i!\n", nr);
+    if ((ExceptionDebugMask & EXCEPT_NOHANDLER) && (regs.vbr + 4*nr) == 0) {
+        fprintf(stderr,"Uninitialized exception handler #%i!\n", nr);
 	DebugUI(REASON_CPU_EXCEPTION);
     }
     newpc = get_long (regs.vbr + 4*nr);
@@ -1039,8 +1039,11 @@
       {
         if ( nr==2 || nr==3 )			/* address error during bus/address error -> stop emulation */
             {
-		fprintf(stderr,"Address Error during exception 2/3, aborting new PC=$%x\n",newpc);
-		DebugUI(REASON_CPU_EXCEPTION);
+	      fprintf(stderr,"Address Error during exception 2/3, aborting new PC=$%x\n",newpc);
+	      if (ExceptionDebugMask & (EXCEPT_BUS|EXCEPT_ADDRESS))
+	        DebugUI(REASON_CPU_EXCEPTION);
+	      else
+		DlgAlert_Notice("Address Error during exception 2/3 => CPU halted!\nEmulation needs to be reset.\n");
             }
         else
             {
@@ -1049,6 +1052,22 @@
             }
         return;
       }
+    /* handle debugger invocation for rest of exceptions */
+    if (ExceptionDebugMask && nr > 3 && nr < 9)
+    {
+      static struct { int flag; const char *name; } ex[] = {
+        { EXCEPT_ILLEGAL,   "Illegal instruction" },	/* 4 */
+        { EXCEPT_ZERODIV,   "Div by zero" },		/* 5 */
+        { EXCEPT_CHK,       "CHK" },			/* 6 */
+        { EXCEPT_TRAPV,     "TRAPV" },			/* 7 */
+        { EXCEPT_PRIVILEGE, "Privilege violation" }	/* 8 */
+      };
+      if (ExceptionDebugMask & ex[nr-4].flag)
+      {
+        fprintf(stderr,"%s exception at 0x%lx!\n", ex[nr-4].name, (long)currpc);
+        DebugUI(REASON_CPU_EXCEPTION);
+      }
+    }
 
     m68k_setpc (get_long (regs.vbr + 4*nr));
     fill_prefetch_0 ();


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/