Use ARC-Path to boot ReactOS
authorEric Kohl <eric.kohl@reactos.org>
Fri, 8 Jun 2001 17:46:52 +0000 (17:46 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Fri, 8 Jun 2001 17:46:52 +0000 (17:46 +0000)
svn path=/trunk/; revision=1952

freeldr/FREELDR.INI
freeldr/freeldr/multiboot.h
freeldr/freeldr/rosboot.c
freeldr/freeldr/stdlib.c
freeldr/freeldr/stdlib.h
freeldr/install.bat

index 2a48ce1..c54291d 100644 (file)
@@ -60,6 +60,9 @@
 
 # [ReactOS OSType] Section Commands:
 #
 
 # [ReactOS OSType] Section Commands:
 #
+# SystemPath   - sets the system root path (must be a valid ARC - Path):
+#                      multi(0)disk(0)rdisk(0)partition(1)\reactos
+#                      multi(0)disk(0)fdisk(0)
 # Options              - sets the command line options for the kernel being booted
 # Kernel               - sets the kernel filename
 # Driver               - sets the name of one or more drivers to be loaded (one entry per driver)
 # Options              - sets the command line options for the kernel being booted
 # Kernel               - sets the kernel filename
 # Driver               - sets the name of one or more drivers to be loaded (one entry per driver)
@@ -86,7 +89,8 @@ MenuColor=Blue
 TextColor=Yellow
 SelectedTextColor=Black
 SelectedColor=Gray
 TextColor=Yellow
 SelectedTextColor=Black
 SelectedColor=Gray
-#OS=ReactOS
+OS=ReactOS (HD)
+OS=ReactOS (Floppy)
 #OS=ReactOS (Debug)
 #OS=Linux
 OS=3« Floppy (A:)
 #OS=ReactOS (Debug)
 #OS=Linux
 OS=3« Floppy (A:)
@@ -94,13 +98,24 @@ OS=Microsoft Windows (C:)
 OS=Drive D:
 #TimeOut=0
 
 OS=Drive D:
 #TimeOut=0
 
-#[ReactOS]
-#BootType=ReactOS
-#BootDrive=0
-#Options=/DEBUGPORT=SCREEN
-#Kernel=\NTOSKRNL.EXE
-#Driver=\DRIVERS\IDE.SYS
-#Driver=\DRIVERS\VFATFS.SYS
+# Load ReactOS from harddisk (drive C:)
+#  - does not work on large harddisks
+[ReactOS (HD)]
+BootType=ReactOS
+SystemPath=multi(0)disk(0)rdisk(0)partition(1)\reactos
+Options=/DEBUGPORT=SCREEN
+Kernel=NTOSKRNL.EXE
+Driver=IDE.SYS
+Driver=VFATFS.SYS
+
+# Load ReactOS from floppy (drive A:)
+[ReactOS (Floppy)]
+BootType=ReactOS
+SystemPath=multi(0)disk(0)fdisk(0)
+Options=/DEBUGPORT=SCREEN
+Kernel=NTOSKRNL.EXE
+Driver=IDE.SYS
+Driver=VFATFS.SYS
 
 #[ReactOS (Debug)]
 #BootType=ReactOS
 
 #[ReactOS (Debug)]
 #BootType=ReactOS
index cb73ccd..fbd5879 100644 (file)
@@ -119,11 +119,11 @@ typedef struct memory_map
 #endif /* ! ASM */
 
 
 #endif /* ! ASM */
 
 
-multiboot_header_t             mb_header;                                                      // Multiboot header structure defined in kernel image file
-multiboot_info_t               mb_info;                                                        // Multiboot info structure passed to kernel
-char                                   multiboot_kernel_cmdline[255];          // Command line passed to kernel
-module_t                               multiboot_modules[64];                          // Array to hold boot module info loaded for the kernel
-char                                   multiboot_module_strings[64][256];      // Array to hold module names
+multiboot_header_t     mb_header;                              // Multiboot header structure defined in kernel image file
+multiboot_info_t       mb_info;                                // Multiboot info structure passed to kernel
+char                   multiboot_kernel_cmdline[255];          // Command line passed to kernel
+module_t               multiboot_modules[64];                  // Array to hold boot module info loaded for the kernel
+char                   multiboot_module_strings[64][256];      // Array to hold module names
 
 
 #endif // defined __MULTIBOOT_H
\ No newline at end of file
 
 
 #endif // defined __MULTIBOOT_H
\ No newline at end of file
index 6b0756b..e875082 100644 (file)
@@ -17,7 +17,7 @@
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
-       
+
 #include "freeldr.h"
 #include "asmcode.h"
 #include "rosboot.h"
 #include "freeldr.h"
 #include "asmcode.h"
 #include "rosboot.h"
 #include "tui.h"
 #include "multiboot.h"
 
 #include "tui.h"
 #include "multiboot.h"
 
+
+static BOOL
+DissectArcPath(char *ArcPath, char *BootPath, unsigned int *BootDrive, unsigned int *BootPartition);
+
+
 unsigned long                          next_module_load_base = 0;
 
 void LoadAndBootReactOS(char *OperatingSystemName)
 {
 unsigned long                          next_module_load_base = 0;
 
 void LoadAndBootReactOS(char *OperatingSystemName)
 {
-       FILE            file;
-       char            name[1024];
-       char            value[1024];
-       char            szFileName[1024];
+       FILE    file;
+       char    name[1024];
+       char    value[1024];
+       char    szFileName[1024];
+       char    szBootPath[256];
        int                     i;
        int                     nNumDriverFiles=0;
        int                     nNumFilesLoaded=0;
        int                     i;
        int                     nNumDriverFiles=0;
        int                     nNumFilesLoaded=0;
+       char MsgBuffer[256];
 
        /*
         * Setup multiboot information structure
 
        /*
         * Setup multiboot information structure
@@ -51,49 +58,66 @@ void LoadAndBootReactOS(char *OperatingSystemName)
        mb_info.mmap_length = 0;
        mb_info.mmap_addr = 0;
 
        mb_info.mmap_length = 0;
        mb_info.mmap_addr = 0;
 
+
        /*
        /*
-        * Read the optional kernel parameters (if any)
+        * Make sure the system path is set in the .ini file
         */
         */
-       ReadSectionSettingByName(OperatingSystemName, "Options", name, multiboot_kernel_cmdline);
+       if(!ReadSectionSettingByName(OperatingSystemName, "SystemPath", name, value))
+       {
+               MessageBox("System path not specified for selected operating system.");
+               return;
+       }
 
        /*
 
        /*
-        * Find the kernel image name
+        * Verify system path
         */
         */
-       if(!ReadSectionSettingByName(OperatingSystemName, "Kernel", name, value))
+       if(!DissectArcPath(value, szBootPath, &BootDrive, &BootPartition))
        {
        {
-               MessageBox("Kernel image file not specified for selected operating system.");
+               sprintf(MsgBuffer,"Invalid system path: '%s'", value);
+               MessageBox(MsgBuffer);
                return;
        }
 
                return;
        }
 
+
+       /* set boot drive and partition */
+       ((char *)(&mb_info.boot_device))[0] = (char)BootDrive;
+       ((char *)(&mb_info.boot_device))[1] = (char)BootPartition;
+
+       /* copy ARC path into kernel command line */
+       strcpy(multiboot_kernel_cmdline, value);
+
        /*
        /*
-        * Get the boot partition
+        * Read the optional kernel parameters (if any)
         */
         */
-       BootPartition = 0;
-       if (ReadSectionSettingByName(OperatingSystemName, "BootPartition", name, value))
+       if (ReadSectionSettingByName(OperatingSystemName, "Options", name, value))
        {
        {
-               BootPartition = atoi(value);
+               strcat(multiboot_kernel_cmdline, " ");
+               strcat(multiboot_kernel_cmdline, value);
        }
        }
-       ((char *)(&mb_info.boot_device))[1] = (char)BootPartition;
-       
+
+       /* append a backslash */
+       if ((strlen(szBootPath)==0) ||
+           szBootPath[strlen(szBootPath)] != '\\')
+               strcat(szBootPath, "\\");
+
        /*
        /*
-        * Make sure the boot drive is set in the .ini file
+        * Find the kernel image name
         */
         */
-       if(!ReadSectionSettingByName(OperatingSystemName, "BootDrive", name, value))
+       if(!ReadSectionSettingByName(OperatingSystemName, "Kernel", name, value))
        {
        {
-               MessageBox("Boot drive not specified for selected operating system.");
+               MessageBox("Kernel image file not specified for selected operating system.");
                return;
        }
 
                return;
        }
 
+
        DrawBackdrop();
 
        DrawStatusText(" Loading...");
        DrawProgressBar(0);
 
        /*
        DrawBackdrop();
 
        DrawStatusText(" Loading...");
        DrawProgressBar(0);
 
        /*
-        * Set the boot drive and try to open it
+        * Try to open boot drive
         */
         */
-       BootDrive = atoi(value);
-       ((char *)(&mb_info.boot_device))[0] = (char)BootDrive;
        if (!OpenDiskDrive(BootDrive, BootPartition))
        {
                MessageBox("Failed to open boot drive.");
        if (!OpenDiskDrive(BootDrive, BootPartition))
        {
                MessageBox("Failed to open boot drive.");
@@ -122,7 +146,8 @@ void LoadAndBootReactOS(char *OperatingSystemName)
                /*
                 * Set the name and try to open the PE image
                 */
                /*
                 * Set the name and try to open the PE image
                 */
-               strcpy(szFileName, value);
+               strcpy(szFileName, szBootPath);
+               strcat(szFileName, value);
                if (!OpenFile(szFileName, &file))
                {
                        strcat(value, " not found.");
                if (!OpenFile(szFileName, &file))
                {
                        strcat(value, " not found.");
@@ -337,3 +362,55 @@ BOOL MultiBootLoadModule(FILE *ModuleImage, char *ModuleName)
 
        return TRUE;
 }
 
        return TRUE;
 }
+
+
+static BOOL
+DissectArcPath(char *ArcPath, char *BootPath, unsigned int *BootDrive, unsigned int *BootPartition)
+{
+       char *p;
+
+       if (_strnicmp(ArcPath, "multi(0)disk(0)", 15) != 0)
+               return FALSE;
+
+       p = ArcPath + 15;
+       if (_strnicmp(p, "fdisk(", 6) == 0)
+       {
+               /*
+                * floppy disk path:
+                *  multi(0)disk(0)fdisk(x)\path
+                */
+               p = p + 6;
+               *BootDrive = atoi(p);
+               p = strchr(p, ')');
+               if (p == NULL)
+                       return FALSE;
+               p++;
+               *BootPartition = 0;
+       }
+       else if (_strnicmp(p, "rdisk(", 6) == 0)
+       {
+               /*
+                * hard disk path:
+                *  multi(0)disk(0)rdisk(x)partition(y)\path
+                */
+               p = p + 6;
+               *BootDrive = atoi(p) + 0x80;
+               p = strchr(p, ')');
+               if ((p == NULL) || (_strnicmp(p, ")partition(", 11) != 0))
+                       return FALSE;
+               p = p + 11;
+               *BootPartition = atoi(p);
+               p = strchr(p, ')');
+               if ((p == NULL) || (*BootPartition == 0))
+                       return FALSE;
+               p++;
+       }
+       else
+       {
+               return FALSE;
+       }
+
+       strcpy(BootPath, p);
+
+       return TRUE;
+}
index e90a7eb..6f6c345 100644 (file)
@@ -116,7 +116,57 @@ void printf(char *format, ... )
          }
     }
 }
          }
     }
 }
-       
+
+void sprintf(char *buffer, char *format, ... )
+{
+  int *dataptr = (int *) &format;
+  char c, *ptr, str[16];
+  char *p = buffer;
+
+  dataptr++;
+
+  while ((c = *(format++)))
+    {
+      if (c != '%')
+      {
+       *p = c;
+       p++;
+      }
+      else
+       switch (c = *(format++))
+         {
+         case 'd': case 'u': case 'x':
+           *convert_to_ascii(str, c, *((unsigned long *) dataptr++)) = 0;
+
+           ptr = str;
+
+           while (*ptr)
+           {
+             *p = *(ptr++);
+             p++;
+           }
+           break;
+
+         case 'c':
+           *p = (*(dataptr++))&0xff;
+           p++;
+           break;
+
+         case 's':
+           ptr = (char *)(*(dataptr++));
+
+           while ((c = *(ptr++)))
+           {
+             *p = c;
+             p++;
+           }
+           break;
+         }
+    }
+  *p=0;
+}
+
+
 int strlen(char *str)
 {
        int     len;
 int strlen(char *str)
 {
        int     len;
@@ -217,6 +267,20 @@ char *strcat(char *dest, char *src)
        return ret;
 }
 
        return ret;
 }
 
+char *strchr(const char *s, int c)
+{
+       char cc = c;
+       while (*s)
+       {
+               if (*s == cc)
+                       return (char *)s;
+               s++;
+       }
+       if (cc == 0)
+               return (char *)s;
+       return 0;
+}
+
 int strcmp(const char *string1, const char *string2)
 {
        while(*string1 == *string2)
 int strcmp(const char *string1, const char *string2)
 {
        while(*string1 == *string2)
@@ -245,6 +309,21 @@ int stricmp(const char *string1, const char *string2)
        return (int)tolower(*string1) - (int)tolower(*string2);
 }
 
        return (int)tolower(*string1) - (int)tolower(*string2);
 }
 
+int _strnicmp(const char *string1, const char *string2, size_t length)
+{
+       if (length == 0)
+               return 0;
+       do
+       {
+               if (toupper(*string1) != toupper(*string2++))
+                       return toupper(*(unsigned const char *)string1) - toupper(*(unsigned const char *)--string2);
+               if (*string1++ == 0)
+                       break;
+       }
+       while (--length != 0);
+       return 0;
+}
+
 char *fgets(char *string, int n, FILE *stream)
 {
        int     i;
 char *fgets(char *string, int n, FILE *stream)
 {
        int     i;
@@ -272,9 +351,8 @@ char *fgets(char *string, int n, FILE *stream)
 
 int atoi(char *string)
 {
 
 int atoi(char *string)
 {
-       int             i, j;
-       int             base;
-       int             result = 0;
+       int     base;
+       int     result = 0;
        char    *str;
 
        if((string[0] == '0') && (string[1] == 'x'))
        char    *str;
 
        if((string[0] == '0') && (string[1] == 'x'))
@@ -288,18 +366,14 @@ int atoi(char *string)
                str = string;
        }
 
                str = string;
        }
 
-       for(i=strlen(str)-1,j=1; i>=0; i--)
+       while(1)
        {
        {
-               if((str[i] < '0') || (str[i] > '9'))
+               if((*str < '0') || (*str > '9'))
                        break;
 
                        break;
 
-               if(i == (strlen(str)-1))
-                       result += (str[i] - '0');
-               else
-               {
-                       result += (str[i] - '0') * (j * base);
-                       j *= base;
-               }
+               result *= base;
+               result += (*str - '0');
+               str++;
        }
 
        return result;
        }
 
        return result;
index e222b5c..01cbe83 100644 (file)
@@ -38,29 +38,32 @@ void        showcursor(void);               // Implemented in asmcode.S
 int            wherex(void);                   // Implemented in asmcode.S
 int            wherey(void);                   // Implemented in asmcode.S
 
 int            wherex(void);                   // Implemented in asmcode.S
 int            wherey(void);                   // Implemented in asmcode.S
 
-int            strlen(char *str);
+int    strlen(char *str);
 char   *strcpy(char *dest, char *src);
 char   *strcat(char *dest, char *src);
 char   *strcpy(char *dest, char *src);
 char   *strcat(char *dest, char *src);
-int            strcmp(const char *string1, const char *string2);
-int            stricmp(const char *string1, const char *string2);
+char   *strchr(const char *s, int c);
+int    strcmp(const char *string1, const char *string2);
+int    stricmp(const char *string1, const char *string2);
+int    _strnicmp(const char *string1, const char *string2, size_t length);
 char   *itoa(int value, char *string, int radix);
 char   *itoa(int value, char *string, int radix);
-int            toupper(int c);
-int            tolower(int c);
-int            memcmp(const void *buf1, const void *buf2, size_t count);
+int    toupper(int c);
+int    tolower(int c);
+int    memcmp(const void *buf1, const void *buf2, size_t count);
 void   *memcpy(void *dest, const void *src, size_t count);
 void   *memset(void *dest, int c, size_t count);
 char   *fgets(char *string, int n, FILE *stream);
 void   *memcpy(void *dest, const void *src, size_t count);
 void   *memset(void *dest, int c, size_t count);
 char   *fgets(char *string, int n, FILE *stream);
-int            atoi(char *string);
+int    atoi(char *string);
 
 
 void   print(char *str);
 void   printf(char *fmt, ...);
 
 
 void   print(char *str);
 void   printf(char *fmt, ...);
+void   sprintf(char *buffer, char *format, ...);
 
 
-int            biosdisk(int cmd, int drive, int head, int track, int sector, int nsects, void *buffer); // Implemented in asmcode.S
-void   stop_floppy(void);                      // Implemented in asmcode.S
-int            get_heads(int drive);           // Implemented in asmcode.S
-int            get_cylinders(int drive);       // Implemented in asmcode.S
-int            get_sectors(int drive);         // Implemented in asmcode.S
+int    biosdisk(int cmd, int drive, int head, int track, int sector, int nsects, void *buffer); // Implemented in asmcode.S
+void   stop_floppy(void);              // Implemented in asmcode.S
+int    get_heads(int drive);           // Implemented in asmcode.S
+int    get_cylinders(int drive);       // Implemented in asmcode.S
+int    get_sectors(int drive);         // Implemented in asmcode.S
 
 /* Values for biosdisk() */
 #define _DISK_RESET            0       // Unimplemented
 
 /* Values for biosdisk() */
 #define _DISK_RESET            0       // Unimplemented
index 4abeb52..03c4ee8 100644 (file)
@@ -1,5 +1,5 @@
 cd bootsect
 call install.bat
 cd..
 cd bootsect
 call install.bat
 cd..
-copy freeldr.sys a:\
-copy freeldr.ini a:\
\ No newline at end of file
+copy freeldr.sys a:\FREELDR.SYS
+copy freeldr.ini a:\FREELDR.INI
\ No newline at end of file