Author: hpoussin
Date: Tue Dec 30 11:53:09 2014
New Revision: 65905

URL: http://svn.reactos.org/svn/reactos?rev=65905&view=rev
Log:
[FREELDR] Make the disk read buffer size dynamic

CORE-8772 CORE-8899 #resolve #comment Should be fixed in r65904. Thanks for 
reporting.

Modified:
    trunk/reactos/boot/freeldr/freeldr/arch/i386/hwdisk.c
    trunk/reactos/boot/freeldr/freeldr/arch/i386/pcmem.c
    trunk/reactos/boot/freeldr/freeldr/arch/i386/xboxhw.c
    trunk/reactos/boot/freeldr/freeldr/include/arch/pc/machpc.h
    trunk/reactos/boot/freeldr/freeldr/include/arch/pc/x86common.h

Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/hwdisk.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/i386/hwdisk.c?rev=65905&r1=65904&r2=65905&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/arch/i386/hwdisk.c       [iso-8859-1] 
(original)
+++ trunk/reactos/boot/freeldr/freeldr/arch/i386/hwdisk.c       [iso-8859-1] 
Tue Dec 30 11:53:09 2014
@@ -119,7 +119,7 @@
     ULONGLONG SectorOffset;
 
     TotalSectors = (N + Context->SectorSize - 1) / Context->SectorSize;
-    MaxSectors   = DISKREADBUFFER_SIZE / Context->SectorSize;
+    MaxSectors   = PcDiskReadBufferSize / Context->SectorSize;
     SectorOffset = Context->SectorNumber + Context->SectorOffset;
 
     ret = 1;

Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/pcmem.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/i386/pcmem.c?rev=65905&r1=65904&r2=65905&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/arch/i386/pcmem.c        [iso-8859-1] 
(original)
+++ trunk/reactos/boot/freeldr/freeldr/arch/i386/pcmem.c        [iso-8859-1] 
Tue Dec 30 11:53:09 2014
@@ -40,6 +40,7 @@
 
 BIOS_MEMORY_MAP PcBiosMemoryMap[MAX_BIOS_DESCRIPTORS];
 ULONG PcBiosMapCount;
+ULONG PcDiskReadBufferSize;
 
 FREELDR_MEMORY_DESCRIPTOR PcMemoryMap[MAX_BIOS_DESCRIPTORS + 1] =
 {
@@ -201,7 +202,7 @@
        bit value at address 0x413 inside the BDA, which gives us the usable 
size
        in KB */
     Size = (*(PUSHORT)(ULONG_PTR)0x413) * 1024;
-    if (Size < MEMORY_MARGIN)
+    if (Size < DISKREADBUFFER || Size - DISKREADBUFFER < 
MIN_DISKREADBUFFER_SIZE)
     {
         FrLdrBugCheckWithMessage(
             MEMORY_INIT_FAILURE,
@@ -211,6 +212,12 @@
             "If you see this, please report to the ReactOS team!",
             Size);
     }
+    PcDiskReadBufferSize = (Size - DISKREADBUFFER) & ~0xfff;
+    if (PcDiskReadBufferSize > MAX_DISKREADBUFFER_SIZE)
+    {
+        PcDiskReadBufferSize = MAX_DISKREADBUFFER_SIZE;
+    }
+    TRACE("PcDiskReadBufferSize=0x%x\n", PcDiskReadBufferSize);
 
     /* Get the address of the Extended BIOS Data Area (EBDA).
      * Int 15h, AH=C1h
@@ -229,7 +236,7 @@
     {
         /* Check if this is high enough */
         ULONG EbdaBase = (ULONG)Regs.w.es << 4;
-        if (EbdaBase < MEMORY_MARGIN)
+        if (EbdaBase < DISKREADBUFFER || EbdaBase - DISKREADBUFFER < 
MIN_DISKREADBUFFER_SIZE)
         {
             FrLdrBugCheckWithMessage(
                 MEMORY_INIT_FAILURE,
@@ -238,6 +245,11 @@
                 "The location of your EBDA is 0x%lx, which is too low!\n\n"
                 "If you see this, please report to the ReactOS team!",
                 EbdaBase);
+        }
+        if (((EbdaBase - DISKREADBUFFER) & ~0xfff) < PcDiskReadBufferSize)
+        {
+            PcDiskReadBufferSize = (EbdaBase - DISKREADBUFFER) & ~0xfff;
+            TRACE("After EBDA check, PcDiskReadBufferSize=0x%x\n", 
PcDiskReadBufferSize);
         }
 
         /* Calculate the (max) size of the EBDA */

Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/xboxhw.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/i386/xboxhw.c?rev=65905&r1=65904&r2=65905&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/arch/i386/xboxhw.c       [iso-8859-1] 
(original)
+++ trunk/reactos/boot/freeldr/freeldr/arch/i386/xboxhw.c       [iso-8859-1] 
Tue Dec 30 11:53:09 2014
@@ -198,8 +198,8 @@
     while (N > 0)
     {
         Length = N;
-        if (Length > DISKREADBUFFER_SIZE)
-            Length = DISKREADBUFFER_SIZE;
+        if (Length > PcDiskReadBufferSize)
+            Length = PcDiskReadBufferSize;
         Sectors = (Length + Context->SectorSize - 1) / Context->SectorSize;
         ret = MachDiskReadLogicalSectors(
                   Context->DriveNumber,
@@ -351,11 +351,11 @@
         * harddisks. So, we set the buffer to known contents first, then try to
         * read. If the BIOS reports success but the buffer contents haven't
         * changed then we fail anyway */
-    memset((PVOID) DISKREADBUFFER, 0xcd, DISKREADBUFFER_SIZE);
+    memset((PVOID) DISKREADBUFFER, 0xcd, PcDiskReadBufferSize);
     while (MachDiskReadLogicalSectors(0x80 + DiskCount, 0ULL, 1, 
(PVOID)DISKREADBUFFER))
     {
         Changed = FALSE;
-        for (i = 0; ! Changed && i < DISKREADBUFFER_SIZE; i++)
+        for (i = 0; ! Changed && i < PcDiskReadBufferSize; i++)
         {
             Changed = ((PUCHAR)DISKREADBUFFER)[i] != 0xcd;
         }
@@ -366,7 +366,7 @@
             break;
         }
         DiskCount++;
-        memset((PVOID) DISKREADBUFFER, 0xcd, DISKREADBUFFER_SIZE);
+        memset((PVOID) DISKREADBUFFER, 0xcd, PcDiskReadBufferSize);
     }
     DiskReportError(TRUE);
     TRACE("BIOS reports %d harddisk%s\n",

Modified: trunk/reactos/boot/freeldr/freeldr/include/arch/pc/machpc.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/include/arch/pc/machpc.h?rev=65905&r1=65904&r2=65905&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/include/arch/pc/machpc.h [iso-8859-1] 
(original)
+++ trunk/reactos/boot/freeldr/freeldr/include/arch/pc/machpc.h [iso-8859-1] 
Tue Dec 30 11:53:09 2014
@@ -63,5 +63,6 @@
 
 extern BIOS_MEMORY_MAP PcBiosMemoryMap[];
 extern ULONG PcBiosMapCount;
+extern ULONG PcDiskReadBufferSize;
 
 /* EOF */

Modified: trunk/reactos/boot/freeldr/freeldr/include/arch/pc/x86common.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/include/arch/pc/x86common.h?rev=65905&r1=65904&r2=65905&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/include/arch/pc/x86common.h      
[iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/include/arch/pc/x86common.h      
[iso-8859-1] Tue Dec 30 11:53:09 2014
@@ -17,14 +17,14 @@
 #define FREELDR_BASE        HEX(F800)
 #define FREELDR_PE_BASE    HEX(10000)
 #define DISKREADBUFFER     HEX(8E000) /* Buffer to store data read in from the 
disk via the BIOS */
-#define MEMORY_MARGIN      HEX(9A000) /* Highest usable address */
 /* 9F000- 9FFFF is reserved for the EBDA */
 
 #define BIOSCALLBUFSEGMENT (BIOSCALLBUFFER/16) /* Buffer to store temporary 
data for any Int386() call */
 #define BIOSCALLBUFOFFSET   HEX(0000) /* Buffer to store temporary data for 
any Int386() call */
 #define BIOSCALLBUFSIZE     PAGE_SIZE /* max is sizeof(VESA_SVGA_INFO) = 512 */
 #define MAX_FREELDR_PE_SIZE (DISKREADBUFFER - FREELDR_PE_BASE)
-#define DISKREADBUFFER_SIZE (MEMORY_MARGIN - DISKREADBUFFER)
+#define MIN_DISKREADBUFFER_SIZE HEX(1000)
+#define MAX_DISKREADBUFFER_SIZE HEX(20000)
 
 /* These addresses specify the realmode "BSS section" layout */
 #define BSS_RealModeEntry        (BSS_START +  0)


Reply via email to