Re: freezes when not emulating CPU (was: MIDI input patch)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all,

Stas Sergeev has once more offered his help offlist, and he's again done a great job.  It turned out that my problems were FPU related.  Stas worked out the patch below to fix them.  The patch has been tested without problems in every day use on two machines so far, on a Pentium III ThinkPad and in a virtual Linux box in VMware on a Mac.

And here is the patch.  I hope it's good for application to the trunk.




Index: src/include/memory.h
===================================================================
--- src/include/memory.h	(revision 1905)
+++ src/include/memory.h	(working copy)
@@ -118,6 +118,10 @@
 #define INT70_OFF	0x63f0
 #define INT70_ADD	((INT70_SEG << 4) + INT70_OFF)
 
+#define INT75_SEG	ROMBIOSSEG
+#define INT75_OFF	0x7f00
+#define INT75_ADD	((INT75_SEG << 4) + INT75_OFF)
+
 #define INT1E_SEG	ROMBIOSSEG
 #define INT1E_OFF	0x6fc7
 #define INT41_SEG	ROMBIOSSEG
Index: src/base/bios/setup.c
===================================================================
--- src/base/bios/setup.c	(revision 1905)
+++ src/base/bios/setup.c	(working copy)
@@ -127,16 +127,13 @@
   SETIVEC(0x1e, INT1E_SEG, INT1E_OFF);
   SETIVEC(0x41, INT41_SEG, INT41_OFF);
   SETIVEC(0x46, INT46_SEG, INT46_OFF);
-
-  /* This is an int e7 used for FCB opens */
-  SETIVEC(0xe7, INTE7_SEG, INTE7_OFF);
-  /* End of int 0xe7 for FCB opens */
-
+  SETIVEC(0x75, INT75_SEG, INT75_OFF);
 #ifdef IPX
   /* IPX. Dummy but should not crash */
   if (config.ipxsup)
     SETIVEC(0x7a, BIOSSEG, INT_OFF(0x7a));
 #endif
+  SETIVEC(0xe7, INTE7_SEG, INTE7_OFF);
 
   /* Install new handler for video-interrupt into bios_f000_int10ptr,
    * for video initialization at f800:4200
Index: src/base/bios/bios.S
===================================================================
--- src/base/bios/bios.S	(revision 1905)
+++ src/base/bios/bios.S	(working copy)
@@ -947,7 +947,18 @@
 	iret				/* return to interrupted code	*/
 	.globl  CISH(INT08_dummy_end)
 CISH(INT08_dummy_end):
-        
+
+/* ----------------------------------------------------------------- */   
+	.org	((INT75_SEG-BIOSSEG) << 4)+INT75_OFF
+/* ======================= Addr = F800:7F00 (FFF00) */
+	xorb %al, %al
+	outb %al, $0xf0
+	movb $0x20, %al
+	outb %al, $0xa0
+	outb %al, $0x20
+	int $2		/* bochs does this */
+	iret
+
 /* COMPAS FFEF3		vector table for INT08-INT1F */
 /* COMPAS FFF23		vector table for INT70-INT77 */
 /* COMPAS FFF33-FFF53	reserved */
Index: src/base/dev/sb16/dspio.c
===================================================================
--- src/base/dev/sb16/dspio.c	(revision 1905)
+++ src/base/dev/sb16/dspio.c	(working copy)
@@ -288,7 +288,6 @@
 {
     int dma_cnt, fifo_cnt;
     unsigned long long time_dst;
-    double period;
     Bit16u buf;
 
     dma_cnt = fifo_cnt = 0;
@@ -298,7 +297,6 @@
 	state->dma.stereo = sb_dma_samp_stereo();
 	state->dma.rate = sb_get_dma_sampling_rate();
     }
-    period = pcm_samp_period(state->dma.rate, state->dma.stereo + 1);
 
     while (state->output_running && (state->output_time_cur <= time_dst ||
 				     fifo_cnt % (state->dma.stereo + 1))) {
@@ -321,7 +319,8 @@
 						     samp_signed),
 				      state->dma_strm);
 	    }
-	    state->output_time_cur += period;
+	    state->output_time_cur += pcm_samp_period(state->dma.rate,
+		    state->dma.stereo + 1);
 	    fifo_cnt++;
 	} else {
 	    if (!sb_dma_active()) {
@@ -359,7 +358,8 @@
 	    dspio_run_dma(&state->dma);
 	    dma_cnt++;
 	}
-	state->input_time_cur += period;
+	state->input_time_cur += pcm_samp_period(state->dma.rate,
+		state->dma.stereo + 1);
 	fifo_cnt++;
     }
 
@@ -368,9 +368,9 @@
 	    dspio_fill_output(state);
 
     if (fifo_cnt || dma_cnt)
-	S_printf("SB: Processed %i FIFO, %i DMA, or=%i dr=%i time=%lli period=%f\n",
+	S_printf("SB: Processed %i FIFO, %i DMA, or=%i dr=%i time=%lli\n",
 	     fifo_cnt, dma_cnt, state->output_running, state->dma.running,
-	     time_dst, period);
+	     time_dst);
 }
 
 static void dspio_process_midi(void)
Index: src/arch/linux/async/sigsegv.c
===================================================================
--- src/arch/linux/async/sigsegv.c	(revision 1905)
+++ src/arch/linux/async/sigsegv.c	(working copy)
@@ -110,6 +110,7 @@
 		 return 0;
 
       case 0x10: /* coprocessor error */
+		 print_exception_info(scp);
 		 pic_request(PIC_IRQ13); /* this is the 386 way of signalling this */
 		 return 0;
 
@@ -252,7 +253,7 @@
 
     int retcode;
     if (_trapno == 0x10) {
-      g_printf("coprocessor exception, calling IRQ13\n");
+      print_exception_info(scp);
       pic_request(PIC_IRQ13);
       dpmi_return(scp);
       return -1;
Index: src/emu-i386/cpu.c
===================================================================
--- src/emu-i386/cpu.c	(revision 1905)
+++ src/emu-i386/cpu.c	(working copy)
@@ -235,6 +235,56 @@
   REG(eflags) = 0;
 }
 
+#if 0
+static void fpu_init(void)
+{
+#ifdef __x86_64__
+  vm86_fpu_state.cwd = 0x037F;
+  vm86_fpu_state.swd = 0;
+  vm86_fpu_state.ftw = 0xFFFF;	// bochs
+#else
+  vm86_fpu_state.cw = 0x40;
+  vm86_fpu_state.sw = 0;
+  vm86_fpu_state.tag = 0xFFFF;	// bochs
+#endif
+}
+#endif
+
+static void fpu_reset(void)
+{
+#ifdef __x86_64__
+  vm86_fpu_state.cwd = 0x0040;
+  vm86_fpu_state.swd = 0;
+  vm86_fpu_state.ftw = 0x5555;	//bochs
+#else
+  vm86_fpu_state.cw = 0x40;
+  vm86_fpu_state.sw = 0;
+  vm86_fpu_state.tag = 0x5555;	// bochs
+#endif
+}
+
+static Bit8u fpu_io_read(ioport_t port)
+{
+  return 0xff;
+}
+
+static void fpu_io_write(ioport_t port, Bit8u val)
+{
+  switch (port) {
+  case 0xf0:
+    /* not sure about this */
+#ifdef __x86_64__
+    vm86_fpu_state.swd &= ~0x8000;
+#else
+    vm86_fpu_state.sw &= ~0x8000;
+#endif
+    break;
+  case 0xf1:
+    fpu_reset();
+    break;
+  }
+}
+
 /* 
  * DANG_BEGIN_FUNCTION cpu_setup
  *
@@ -247,11 +297,25 @@
  */
 void cpu_setup(void)
 {
+  emu_iodev_t io_dev;
+  io_dev.read_portb = fpu_io_read;
+  io_dev.write_portb = fpu_io_write;
+  io_dev.read_portw = NULL;
+  io_dev.write_portw = NULL;
+  io_dev.read_portd = NULL;
+  io_dev.write_portd = NULL;
+  io_dev.irq = PIC_IRQ13;
+  io_dev.fd = -1;
+  io_dev.start_addr = 0xf0;
+  io_dev.end_addr = 0xff;
+  io_dev.handler_name = "Math Coprocessor";
+  port_register_handler(io_dev, 0);
+
   int_vector_setup();
 
   cpu_reset();
-
   savefpstate(vm86_fpu_state);
+  fpu_reset();
 
 #ifdef X86_EMULATOR
   if (config.cpuemu) {


______________________________________________________
GRATIS für alle WEB.DE-Nutzer: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://movieflat.web.de

--
To unsubscribe from this list: send the line "unsubscribe linux-msdos" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Console]     [Linux Audio]     [Linux for Hams]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite Camping]     [Yosemite Hiking]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Samba]     [Linux Media]     [Fedora Users]

  Powered by Linux