diff --git a/freeldr/FREELDR.INI b/freeldr/FREELDR.INI index 2a48ce11659..c54291dd8de 100644 --- a/freeldr/FREELDR.INI +++ b/freeldr/FREELDR.INI @@ -60,6 +60,9 @@ # [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) @@ -86,7 +89,8 @@ MenuColor=Blue TextColor=Yellow SelectedTextColor=Black SelectedColor=Gray -#OS=ReactOS +OS=ReactOS (HD) +OS=ReactOS (Floppy) #OS=ReactOS (Debug) #OS=Linux OS=3« Floppy (A:) @@ -94,13 +98,24 @@ OS=Microsoft Windows (C:) 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 diff --git a/freeldr/freeldr/multiboot.h b/freeldr/freeldr/multiboot.h index cb73ccd14a6..fbd58790076 100644 --- a/freeldr/freeldr/multiboot.h +++ b/freeldr/freeldr/multiboot.h @@ -119,11 +119,11 @@ typedef struct memory_map #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 diff --git a/freeldr/freeldr/rosboot.c b/freeldr/freeldr/rosboot.c index 6b0756b820f..e875082bf16 100644 --- a/freeldr/freeldr/rosboot.c +++ b/freeldr/freeldr/rosboot.c @@ -17,7 +17,7 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - + #include "freeldr.h" #include "asmcode.h" #include "rosboot.h" @@ -26,17 +26,24 @@ #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) { - 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; + char MsgBuffer[256]; /* * Setup multiboot information structure @@ -51,10 +58,47 @@ void LoadAndBootReactOS(char *OperatingSystemName) mb_info.mmap_length = 0; mb_info.mmap_addr = 0; + + /* + * Make sure the system path is set in the .ini file + */ + if(!ReadSectionSettingByName(OperatingSystemName, "SystemPath", name, value)) + { + MessageBox("System path not specified for selected operating system."); + return; + } + + /* + * Verify system path + */ + if(!DissectArcPath(value, szBootPath, &BootDrive, &BootPartition)) + { + sprintf(MsgBuffer,"Invalid system path: '%s'", value); + MessageBox(MsgBuffer); + 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); + /* * Read the optional kernel parameters (if any) */ - ReadSectionSettingByName(OperatingSystemName, "Options", name, multiboot_kernel_cmdline); + if (ReadSectionSettingByName(OperatingSystemName, "Options", name, value)) + { + strcat(multiboot_kernel_cmdline, " "); + strcat(multiboot_kernel_cmdline, value); + } + + /* append a backslash */ + if ((strlen(szBootPath)==0) || + szBootPath[strlen(szBootPath)] != '\\') + strcat(szBootPath, "\\"); /* * Find the kernel image name @@ -65,24 +109,6 @@ void LoadAndBootReactOS(char *OperatingSystemName) return; } - /* - * Get the boot partition - */ - BootPartition = 0; - if (ReadSectionSettingByName(OperatingSystemName, "BootPartition", name, value)) - { - BootPartition = atoi(value); - } - ((char *)(&mb_info.boot_device))[1] = (char)BootPartition; - - /* - * Make sure the boot drive is set in the .ini file - */ - if(!ReadSectionSettingByName(OperatingSystemName, "BootDrive", name, value)) - { - MessageBox("Boot drive not specified for selected operating system."); - return; - } DrawBackdrop(); @@ -90,10 +116,8 @@ void LoadAndBootReactOS(char *OperatingSystemName) 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."); @@ -122,7 +146,8 @@ void LoadAndBootReactOS(char *OperatingSystemName) /* * 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."); @@ -337,3 +362,55 @@ BOOL MultiBootLoadModule(FILE *ModuleImage, char *ModuleName) 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; +} diff --git a/freeldr/freeldr/stdlib.c b/freeldr/freeldr/stdlib.c index e90a7eba390..6f6c345ac67 100644 --- a/freeldr/freeldr/stdlib.c +++ b/freeldr/freeldr/stdlib.c @@ -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; @@ -217,6 +267,20 @@ char *strcat(char *dest, char *src) 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) @@ -245,6 +309,21 @@ int stricmp(const char *string1, const char *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; @@ -272,9 +351,8 @@ char *fgets(char *string, int n, FILE *stream) 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')) @@ -288,18 +366,14 @@ int atoi(char *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; - 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; diff --git a/freeldr/freeldr/stdlib.h b/freeldr/freeldr/stdlib.h index e222b5c9d4a..01cbe83af68 100644 --- a/freeldr/freeldr/stdlib.h +++ b/freeldr/freeldr/stdlib.h @@ -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 strlen(char *str); +int strlen(char *str); 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); -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); -int atoi(char *string); +int atoi(char *string); 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 diff --git a/freeldr/install.bat b/freeldr/install.bat index 4abeb52e495..03c4ee8dbea 100644 --- a/freeldr/install.bat +++ b/freeldr/install.bat @@ -1,5 +1,5 @@ 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