From 7e6ff84a5a30e585e292126e9b7c2c47a313fd29 Mon Sep 17 00:00:00 2001
From: dtc <dtc>
Date: Thu, 19 Feb 1998 15:19:11 +0000
Subject: [PATCH] Save and reset the NPX state when a primitive halt is
 signalled so the monitor can use the NPX (for printing float objects), and
 restore the state when returning. This may be unnecessary on Linux?

---
 lisp/x86-arch.c  | 17 +++++++++++------
 lisp/x86-assem.S | 22 +++++++++++++++++++++-
 2 files changed, 32 insertions(+), 7 deletions(-)

diff --git a/lisp/x86-arch.c b/lisp/x86-arch.c
index 1918955b5..28b45c948 100644
--- a/lisp/x86-arch.c
+++ b/lisp/x86-arch.c
@@ -1,6 +1,6 @@
 /* x86-arch.c -*- Mode: C; comment-column: 40 -*-
  *
- * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/x86-arch.c,v 1.8 1997/11/30 12:04:37 dtc Exp $ 
+ * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/x86-arch.c,v 1.9 1998/02/19 15:19:11 dtc Exp $ 
  *
  */
 
@@ -215,11 +215,16 @@ sigtrap_handler(HANDLER_ARGS)
       break;
       
     case trap_Halt:
-      fake_foreign_function_call(context);
-      lose("%%primitive halt called; the party is over.\n");
-      undo_fake_foreign_function_call(context);
-      arch_skip_instruction(context);
-      break;
+      {
+	int fpu_state[27];
+	fpu_save(fpu_state);
+	fake_foreign_function_call(context);
+	lose("%%primitive halt called; the party is over.\n");
+	undo_fake_foreign_function_call(context);
+	fpu_restore(fpu_state);
+	arch_skip_instruction(context);
+	break;
+      }
       
     case trap_Error:
     case trap_Cerror:
diff --git a/lisp/x86-assem.S b/lisp/x86-assem.S
index 416c86fbe..5e7570be2 100644
--- a/lisp/x86-assem.S
+++ b/lisp/x86-assem.S
@@ -1,6 +1,6 @@
 ### x86-assem.S -*- Mode: Asm; -*-
 /**
- * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/x86-assem.S,v 1.10 1998/01/19 09:01:59 dtc Exp $
+ * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/x86-assem.S,v 1.11 1998/02/19 15:19:10 dtc Exp $
  *
  * Authors:	Paul F. Werkowski <pw@snoopy.mv.com>
  *		Douglas T. Crosher
@@ -232,6 +232,26 @@ Llra:
 	ret
 	.size	GNAME(call_into_lisp), . - GNAME(call_into_lisp)
 
+/* Support for saving and restoring the NPX state from C. */
+	.text
+	.global	GNAME(fpu_save)
+	.type	GNAME(fpu_save),@function
+	.align	2,0x90
+GNAME(fpu_save):
+	movl	4(%esp),%eax
+	fnsave	(%eax)		# Save the NPX state - Resets NPX
+	ret
+	.size	GNAME(fpu_save),.-GNAME(fpu_save)
+
+	.global	_fpu_restore
+	.type	_fpu_restore,@function
+	.align	2,0x90
+GNAME(fpu_restore):
+	movl	4(%esp),%eax
+	frstor	(%eax)		# Restore the NPX state.
+	ret
+	.size	GNAME(fpu_restore),.-GNAME(fpu_restore)
+
 /*
  * The undefined-function trampoline.
  */
-- 
GitLab