www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1999/01/10/16:04:19

Message-ID: <3698D60E.13C6D0BA@gmx.net>
Date: Sun, 10 Jan 1999 15:32:14 -0100
From: Robert Hoehne <robert DOT hoehne AT gmx DOT net>
Organization: none provided
X-Mailer: Mozilla 4.07 [de] (Win95; I)
MIME-Version: 1.0
To: djgpp-workers <djgpp-workers AT delorie DOT com>
Subject: FPU support in dbgcom.c
Reply-To: djgpp-workers AT delorie DOT com

OK, here now the patch(es) for saving/restoring the
FPU state in dbgcom.c. This is mainly no new code, but
only a liitle bit moved (mostly from the FSDB sources).

--- src/debug/fsdb/fullscr.h~	Wed Jan 24 21:53:44 1996
+++ src/debug/fsdb/fullscr.h	Sun Jan 10 15:10:08 1999
@@ -2,26 +2,6 @@
 /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
 #define V2DBG 1
 
-typedef struct {
-  word16 sig0;
-  word16 sig1;
-  word16 sig2;
-  word16 sig3;
-  word16 exponent:15;
-  word16 sign:1;
-} NPXREG;
-
-typedef struct {
-  word32 control;
-  word32 status;
-  word32 tag;
-  word32 eip;
-  word32 cs;
-  word32 dataptr;
-  word32 datasel;
-  NPXREG reg[8];
-} NPX;
-
 typedef struct GDT_S {
 word16 lim0;
 word16 base0;
--- include/debug/dbgcom.h~	Tue Aug 13 01:08:04 1996
+++ include/debug/dbgcom.h	Sun Jan 10 15:14:46 1999
@@ -23,6 +23,31 @@
 
 extern ExternalDebuggerInfo edi;
 
+typedef struct {
+  unsigned short sig0;
+  unsigned short sig1;
+  unsigned short sig2;
+  unsigned short sig3;
+  unsigned short exponent:15;
+  unsigned short sign:1;
+} NPXREG;
+
+typedef struct {
+  unsigned int control;
+  unsigned int status;
+  unsigned int tag;
+  unsigned int eip;
+  unsigned int cs;
+  unsigned int dataptr;
+  unsigned int datasel;
+  NPXREG reg[8];
+} NPX;
+
+extern NPX npx;
+
+void save_npx (void); /* Save the FPU of the debugged program */
+void load_npx (void); /* Restore the FPU of the debugged program */
+
 void run_child(void);
 int read_child(unsigned child_addr, void *buf, unsigned len);
 int write_child(unsigned child_addr, void *buf, unsigned len);
--- src/debug/fsdb/fullscr.c~	Mon Sep  7 17:53:08 1998
+++ src/debug/fsdb/fullscr.c	Sun Jan 10 15:19:24 1999
@@ -110,7 +110,6 @@
 #define MAXINSTLEN 16
 static int first_step;
 static word32 main_entry;
-static NPX npx;
 static void redraw (int);
 static const char hexchars[] = "0123456789abcdef";
 static int dpmi;
@@ -388,35 +387,6 @@
 }
 #endif
 /* ------------------------------------------------------------------------- */
-/* Store the contents of the NPX in the global variable `npx'.  */
-
-static inline void
-save_npx (void)
-{
-  asm ("inb	$0xa0, %%al
-	testb	$0x20, %%al
-	jz	1f
-	xorb	%%al, %%al
-	outb	%%al, $0xf0
-	movb	$0x20, %%al
-	outb	%%al, $0xa0
-	outb	%%al, $0x20
-1:
-	fnsave	%0
-	fwait"
-       : "=m" (npx)
-       : /* No input */
-       : "%eax");
-}
-/* ------------------------------------------------------------------------- */
-/* Reload the contents of the NPX from the global variable `npx'.  */
-
-static inline void
-load_npx (void)
-{
-  asm ("frstor %0" : "=m" (npx));
-}
-/* ------------------------------------------------------------------------- */
 /* Evaluate EXPR and return the result.  Set OKP to 1 if and if only the
    expression was sucessfully evaluated.  Display an error message if not.  */
 
@@ -1243,7 +1213,6 @@
     {
       char *reason;
 
-      save_npx ();
       if ((npx.status & 0x0241) == 0x0241)
 	reason = "stack overflow";
       else if ((npx.status & 0x0241) == 0x0041)
@@ -1264,7 +1233,6 @@
 	reason = "?";
       message (CL_Error, "Numeric Exception (%s) at eip=0x%08lx",
 	       reason, npx.eip);
-      load_npx ();
     }
   else if (i == 8 || (i >= 10 && i <= 14) || i == 17)
     message (CL_Error, "Exception %d (0x%02x) occurred, error code=%#lx",
@@ -1597,7 +1565,6 @@
     int i, y = 1, width = cols - 19;
     static char *rtype[] = { "Near", "-Inf", "+Inf", "Zero" };
 
-    save_npx ();
     sprintf (buf,
 	     "Control: %04lx PR=%s UN=%s OV=%s ZD=%s DN=%s IV=%s Rnd=%s",
 	     npx.control & 0xffff,
@@ -1687,7 +1654,6 @@
       }
     while (y <= toplines)
       putl (1, y++, width, "");
-    load_npx ();
   }
 
   if (stack_pane_active)
@@ -3016,7 +2982,6 @@
   int reg = no - base, rotreg, tag;
   int regp = (reg >= 0);
 
-  save_npx ();
   rotreg = (reg + (npx.status >> 11)) & 7;
   tag = (npx.tag >> (rotreg * 2)) & 3;
 
@@ -3088,7 +3053,6 @@
       }
   if (regp)
     npx.tag = (npx.tag & ~(3 << (rotreg * 2))) | (tag << (rotreg * 2));
-  load_npx ();
   redraw (0);
 }
 /* ------------------------------------------------------------------------- */
--- src/debug/common/dbgcom.c~	Sun Jun 28 22:37:44 1998
+++ src/debug/common/dbgcom.c	Sun Jan 10 15:29:12 1999
@@ -29,6 +29,35 @@
 long mem_handles[MEM_HANDLE_COUNT];
 unsigned short descriptors[DESCRIPTOR_COUNT];
 unsigned short dos_descriptors[DOS_DESCRIPTOR_COUNT];
+NPX npx;
+
+/* ------------------------------------------------------------------------- */
+/* Store the contents of the NPX in the global variable `npx'.  */
+
+void save_npx (void)
+{
+  asm ("inb	$0xa0, %%al
+	testb	$0x20, %%al
+	jz	1f
+	xorb	%%al, %%al
+	outb	%%al, $0xf0
+	movb	$0x20, %%al
+	outb	%%al, $0xa0
+	outb	%%al, $0x20
+1:
+	fnsave	%0
+	fwait"
+       : "=m" (npx)
+       : /* No input */
+       : "%eax");
+}
+/* ------------------------------------------------------------------------- */
+/* Reload the contents of the NPX from the global variable `npx'.  */
+
+void load_npx (void)
+{
+  asm ("frstor %0" : "=m" (npx));
+}
 
 /* ARGSUSED */
 char **
@@ -172,6 +201,7 @@
   {
     __dpmi_set_protected_mode_interrupt_vector(0x09, &user_i9);
     __dpmi_set_protected_mode_interrupt_vector(0x08, &user_i8);
+    load_npx();
   }
 }
 
@@ -497,6 +527,7 @@
 
 static void unhook_dpmi(void)
 {
+  save_npx();
   __dpmi_set_protected_mode_interrupt_vector(0x31, &old_i31);
   __dpmi_set_protected_mode_interrupt_vector(0x21, &old_i21);

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019