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

Bug in memory size determination in pc386



There is a bug in the memory size determination code for the pc386
BSP.  It assumes that the complete size of the image, including the
code, data, and BSS, is less than 1M.  Our image is over 2M, and this
led to an occasional problem which took quite a long time to track
down.

The bug is that the code which checks the memory size clobbers memory,
and does not restore it afterward.  The effect is to clobber a few
selected bytes in the image.

Here is a patch to c/src/lib/libbsp/i386/pc386/startup/bspstart.c.

Ian

Index: c/src/lib/libbsp/i386/pc386/startup/bspstart.c
===================================================================
RCS file: /home/cvsfiles/devo/rtems/c/src/lib/libbsp/i386/pc386/startup/bspstart.c,v
retrieving revision 1.1.1.4
diff -u -r1.1.1.4 bspstart.c
--- bspstart.c	1998/10/17 18:51:51	1.1.1.4
+++ bspstart.c	1999/12/06 22:18:16
@@ -82,7 +82,7 @@
 +--------------------------------------------------------------------------*/
 void bsp_pretasking_hook(void)
 {
-  rtems_unsigned32 topAddr, val;
+  rtems_unsigned32 topAddr, oldval, newval;
   int i;
   
   
@@ -92,26 +92,23 @@
   if(_heap_size == 0)
     {
       /* 
-       * We have to dynamically size memory. Memory size can be anything
-       * between 2M and 2048M.
-       * let us first write
+       * We have to dynamically size memory.
+       * We could get it from the BIOS, but we just calculate it ourselves.
+       * We assume a multiple of 1M, and at least 2M.
        */
-      for(i=2048; i>=2; i--)
+      i = 2;
+      while (1)
 	{
-	  topAddr = i*1024*1024 - 4;
-	  *(volatile rtems_unsigned32 *)topAddr = topAddr;
+	  topAddr = i * 1024 * 1024 - 4;
+	  oldval = *(volatile rtems_unsigned32 *) topAddr;
+	  *(volatile rtems_unsigned32 *) topAddr = topAddr;
+	  newval = *(volatile rtems_unsigned32 *) topAddr;
+	  *(volatile rtems_unsigned32 *) topAddr = oldval;
+	  if (newval != topAddr)
+	    break;
+	  ++i;
 	}
 
-      for(i=2; i<=2048; i++)
-	{
-	  topAddr = i*1024*1024 - 4;
-	  val =  *(rtems_unsigned32 *)topAddr;
-	  if(val != topAddr)
-	    {
-	      break;
-	    }
-	}
-      
       topAddr = (i-1)*1024*1024 - 4;
 
       _heap_size = topAddr - rtemsFreeMemStart;