From a9450f5a72b1144ea62e17a1548af1ab7c183e40 Mon Sep 17 00:00:00 2001 From: Brian Palmer Date: Thu, 25 Apr 2002 02:48:15 +0000 Subject: [PATCH] FreeLoader version 1.0! Supports booting Linux bzImage kernels No initrd support (yet) No zImage support (yet) No ext2 file system support (yet) Forward slashes '/' as well as backslashes '\' can be used for path names in FAT & ISO-9660 Fixed bug in LBA code where is was only reading one sector even if you asked for more Fixed bug in FAT code, was also present in ISO-9660 code svn path=/trunk/; revision=2867 --- freeldr/FREELDR.INI | 16 +- freeldr/bootsect/Makefile | 6 +- freeldr/build.bat | 7 - freeldr/freeldr/arch/i386/boot.S | 22 ++- freeldr/freeldr/debug.c | 100 ++++++++++- freeldr/freeldr/debug.h | 9 +- freeldr/freeldr/disk/disk.c | 2 +- freeldr/freeldr/disk/partition.c | 5 +- freeldr/freeldr/freeldr.c | 2 +- freeldr/freeldr/freeldr.h | 6 +- freeldr/freeldr/fs/fat.c | 12 +- freeldr/freeldr/fs/iso.c | 10 +- freeldr/freeldr/linux.c | 282 ++++++++++++++++++++++++++----- freeldr/freeldr/linux.h | 101 ++++++++++- freeldr/freeldr/mm/mm.c | 1 + freeldr/install.bat | 5 - freeldr/notes.txt | 17 +- 17 files changed, 494 insertions(+), 109 deletions(-) delete mode 100644 freeldr/build.bat delete mode 100644 freeldr/install.bat diff --git a/freeldr/FREELDR.INI b/freeldr/FREELDR.INI index da0b10f4940..a4bf43d643a 100644 --- a/freeldr/FREELDR.INI +++ b/freeldr/FREELDR.INI @@ -71,13 +71,13 @@ [FREELOADER] MessageLine=Welcome to FreeLoader! -MessageLine=Copyright (c) 2001 by Brian Palmer +MessageLine=Copyright (c) 2002 by Brian Palmer MessageLine= MessageBox=Edit your FREELDR.INI file to change your boot settings. OS=ReactOS (HD) OS=ReactOS (Floppy) ;OS=ReactOS (Debug) -;OS=Linux +OS=Linux OS=3« Floppy (A:) OS=Microsoft Windows (C:) OS=Drive D: @@ -134,12 +134,12 @@ Driver=\reactos\VFATFS.SYS ;Driver=\DRIVERS\IDE.SYS ;Driver=\DRIVERS\VFATFS.SYS -;[Linux] -;Name="Linux" -; Linux boot type not implemented yet -;BootType=Partition -;BootDrive=0x80 -;BootPartition=2 +[Linux] +Name="Debian Linux 2.2.17" +BootType=Partition +BootDrive=0 +Kernel=/vmlinuz +CommandLine=root=/dev/sdb1 [3« Floppy (A:)] Name="3« Floppy (A:)" diff --git a/freeldr/bootsect/Makefile b/freeldr/bootsect/Makefile index 432caab5618..cd5fc2050da 100644 --- a/freeldr/bootsect/Makefile +++ b/freeldr/bootsect/Makefile @@ -44,6 +44,6 @@ bin2c.exe: bin2c.c $(CC) -o bin2c.exe bin2c.c clean: - $(RM) *.bin - $(RM) *.exe - $(RM) *.h + - $(RM) *.bin + - $(RM) *.exe + - $(RM) *.h diff --git a/freeldr/build.bat b/freeldr/build.bat deleted file mode 100644 index d845e83e68b..00000000000 --- a/freeldr/build.bat +++ /dev/null @@ -1,7 +0,0 @@ -cd bootsect -call make.bat -cd.. -cd freeldr -make -copy freeldr.sys .. -cd .. diff --git a/freeldr/freeldr/arch/i386/boot.S b/freeldr/freeldr/arch/i386/boot.S index ea8c8c231e0..1063f7c7e55 100644 --- a/freeldr/freeldr/arch/i386/boot.S +++ b/freeldr/freeldr/arch/i386/boot.S @@ -33,6 +33,16 @@ EXTERN(_JumpToBootCode) /* Set the boot drive */ movb (_BootDrive),%dl + /* Load segment registers */ + cli + movw $0x0000,%bx + movw %bx,%ds + movw %bx,%es + movw %bx,%fs + movw %bx,%gs + movw %bx,%ss + movw $0x7C00,%sp + ljmpl $0x0000,$0x7C00 @@ -44,4 +54,14 @@ EXTERN(_JumpToLinuxBootCode) /* Set the boot drive */ movb (_BootDrive),%dl - ljmpl $0x0200,$0x9000 + /* Load segment registers */ + cli + movw $0x9000,%bx + movw %bx,%ds + movw %bx,%es + movw %bx,%fs + movw %bx,%gs + movw %bx,%ss + movw $0x8FF4,%sp + + ljmpl $0x9020,$0x0000 diff --git a/freeldr/freeldr/debug.c b/freeldr/freeldr/debug.c index b94189193d1..e623a7c57a1 100644 --- a/freeldr/freeldr/debug.c +++ b/freeldr/freeldr/debug.c @@ -25,9 +25,10 @@ #ifdef DEBUG //ULONG DebugPrintMask = DPRINT_WARNING | DPRINT_MEMORY | DPRINT_FILESYSTEM | -// DPRINT_UI | DPRINT_DISK | DPRINT_CACHE; -ULONG DebugPrintMask = DPRINT_WARNING | DPRINT_MEMORY | DPRINT_FILESYSTEM | - DPRINT_UI | DPRINT_DISK; +// DPRINT_UI | DPRINT_DISK | DPRINT_CACHE | DPRINT_REACTOS | +// DPRINT_LINUX; +ULONG DebugPrintMask = DPRINT_WARNING | /*DPRINT_FILESYSTEM | + DPRINT_CACHE |*/ DPRINT_LINUX; //ULONG DebugPrintMask = DPRINT_INIFILE; #define SCREEN 0 @@ -153,6 +154,26 @@ VOID DebugPrintHeader(ULONG Mask) DebugPrintChar(':'); DebugPrintChar(' '); break; + case DPRINT_REACTOS: + DebugPrintChar('R'); + DebugPrintChar('E'); + DebugPrintChar('A'); + DebugPrintChar('C'); + DebugPrintChar('T'); + DebugPrintChar('O'); + DebugPrintChar('S'); + DebugPrintChar(':'); + DebugPrintChar(' '); + break; + case DPRINT_LINUX: + DebugPrintChar('L'); + DebugPrintChar('I'); + DebugPrintChar('N'); + DebugPrintChar('U'); + DebugPrintChar('X'); + DebugPrintChar(':'); + DebugPrintChar(' '); + break; default: DebugPrintChar('U'); DebugPrintChar('N'); @@ -235,4 +256,77 @@ VOID DebugPrint(ULONG Mask, char *format, ...) } +VOID DebugDumpBuffer(ULONG Mask, PVOID Buffer, ULONG Length) +{ + PUCHAR BufPtr = (PUCHAR)Buffer; + ULONG Idx; + ULONG Idx2; + + // Mask out unwanted debug messages + if (!(Mask & DebugPrintMask)) + { + return; + } + + DebugStartOfLine = FALSE; // We don't want line headers + DebugPrint(Mask, "Dumping buffer at 0x%x with length of %d bytes:\n", Buffer, Length); + + for (Idx=0; Idx 20) && (BufPtr[Idx] < 0x80)) + { + DebugPrint(Mask, "%c", BufPtr[Idx]); + } + else + { + DebugPrint(Mask, "."); + } + } + + DebugPrint(Mask, "\n"); + } +} + #endif // defined DEBUG diff --git a/freeldr/freeldr/debug.h b/freeldr/freeldr/debug.h index 7ae8c0f062c..69457835d31 100644 --- a/freeldr/freeldr/debug.h +++ b/freeldr/freeldr/debug.h @@ -30,17 +30,22 @@ #define DPRINT_UI 0x00000010 // OR this with DebugPrintMask to enable user interface messages #define DPRINT_DISK 0x00000020 // OR this with DebugPrintMask to enable disk messages #define DPRINT_CACHE 0x00000040 // OR this with DebugPrintMask to enable cache messages + #define DPRINT_REACTOS 0x00000080 // OR this with DebugPrintMask to enable ReactOS messages + #define DPRINT_LINUX 0x00000100 // OR this with DebugPrintMask to enable Linux messages VOID DebugInit(VOID); VOID DebugPrint(ULONG Mask, char *format, ...); + VOID DebugDumpBuffer(ULONG Mask, PVOID Buffer, ULONG Length); - #define DbgPrint(_x_) DebugPrint _x_ - #define BugCheck(_x_) { DebugPrint(DPRINT_WARNING, "Fatal Error: %s:%d\n", __FILE__, __LINE__); DebugPrint _x_ ; for (;;); } + #define DbgPrint(_x_) DebugPrint _x_ + #define BugCheck(_x_) { DebugPrint(DPRINT_WARNING, "Fatal Error: %s:%d\n", __FILE__, __LINE__); DebugPrint _x_ ; for (;;); } + #define DbgDumpBuffer(_x_, _y_, _z_) DebugDumpBuffer(_x_, _y_, _z_) #else #define DbgPrint(_x_) #define BugCheck(_x_) + #define DbgDumpBuffer(_x_, _y_, _z_) #endif // defined DEBUG diff --git a/freeldr/freeldr/disk/disk.c b/freeldr/freeldr/disk/disk.c index f9da77e7068..93f0580245a 100644 --- a/freeldr/freeldr/disk/disk.c +++ b/freeldr/freeldr/disk/disk.c @@ -73,7 +73,7 @@ BOOL DiskReadLogicalSectors(ULONG DriveNumber, ULONG SectorNumber, ULONG SectorC // LBA is easy, nothing to calculate // Just do the read // - if (!BiosInt13ReadExtended(DriveNumber, SectorNumber, 1, Buffer)) + if (!BiosInt13ReadExtended(DriveNumber, SectorNumber, SectorCount, Buffer)) { DiskError("Disk read error."); return FALSE; diff --git a/freeldr/freeldr/disk/partition.c b/freeldr/freeldr/disk/partition.c index 3df892a51cd..821f8f78afc 100644 --- a/freeldr/freeldr/disk/partition.c +++ b/freeldr/freeldr/disk/partition.c @@ -43,7 +43,7 @@ BOOL DiskIsDriveRemovable(ULONG DriveNumber) BOOL DiskIsDriveCdRom(ULONG DriveNumber) { - PUCHAR Sector; + PUCHAR Sector = (PUCHAR)DISKREADBUFFER; BOOL Result; // Hard disks use drive numbers >= 0x80 @@ -51,7 +51,6 @@ BOOL DiskIsDriveCdRom(ULONG DriveNumber) // then return FALSE if ((DriveNumber >= 0x80) && (BiosInt13ExtensionsSupported(DriveNumber))) { - Sector = AllocateMemory(2048); if (!BiosInt13ReadExtended(DriveNumber, 16, 1, Sector)) { @@ -67,8 +66,6 @@ BOOL DiskIsDriveCdRom(ULONG DriveNumber) Sector[4] == '0' && Sector[5] == '1'); - FreeMemory(Sector); - return Result; } diff --git a/freeldr/freeldr/freeldr.c b/freeldr/freeldr/freeldr.c index f651897dbc0..c1d816fb777 100644 --- a/freeldr/freeldr/freeldr.c +++ b/freeldr/freeldr/freeldr.c @@ -131,7 +131,7 @@ VOID BootMain(VOID) } else if (stricmp(SettingValue, "Linux") == 0) { - MessageBox("Cannot boot this OS type yet!"); + LoadAndBootLinux(OperatingSystemSectionNames[SelectedOperatingSystem]); } else if (stricmp(SettingValue, "BootSector") == 0) { diff --git a/freeldr/freeldr/freeldr.h b/freeldr/freeldr/freeldr.h index d6b1759fd26..b8b9529bd4a 100644 --- a/freeldr/freeldr/freeldr.h +++ b/freeldr/freeldr/freeldr.h @@ -22,11 +22,11 @@ /* just some stuff */ -#define VERSION "FreeLoader v0.9" +#define VERSION "FreeLoader v1.0" #define COPYRIGHT "Copyright (C) 1998-2002 Brian Palmer " -#define ROSLDR_MAJOR_VERSION 0 -#define ROSLDR_MINOR_VERSION 8 +#define ROSLDR_MAJOR_VERSION 1 +#define ROSLDR_MINOR_VERSION 0 #define ROSLDR_PATCH_VERSION 0 #define size_t unsigned int diff --git a/freeldr/freeldr/fs/fat.c b/freeldr/freeldr/fs/fat.c index c11be24249f..88fc00b544a 100644 --- a/freeldr/freeldr/fs/fat.c +++ b/freeldr/freeldr/fs/fat.c @@ -576,9 +576,9 @@ BOOL FatLookupFile(PUCHAR FileName, PFAT_FILE_INFO FatFileInfoPointer) memset(FatFileInfoPointer, 0, sizeof(FAT_FILE_INFO)); // - // Check and see if the first character is '\' and remove it if so + // Check and see if the first character is '\' or '/' and remove it if so // - while (*FileName == '\\') + while ((*FileName == '\\') || (*FileName == '/')) { FileName++; } @@ -601,7 +601,7 @@ BOOL FatLookupFile(PUCHAR FileName, PFAT_FILE_INFO FatFileInfoPointer) // // Advance to the next part of the path // - for (; (*FileName != '\\') && (*FileName != '\0'); FileName++) + for (; (*FileName != '\\') && (*FileName != '/') && (*FileName != '\0'); FileName++) { } FileName++; @@ -654,7 +654,7 @@ ULONG FatGetNumPathParts(PUCHAR Path) for (i=0,num=0; i<(int)strlen(Path); i++) { - if (Path[i] == '\\') + if ((Path[i] == '\\') || (Path[i] == '/')) { num++; } @@ -681,7 +681,7 @@ VOID FatGetFirstNameFromPath(PUCHAR Buffer, PUCHAR Path) // and put them in Buffer for (i=0; i<(int)strlen(Path); i++) { - if (Path[i] == '\\') + if ((Path[i] == '\\') || (Path[i] == '/')) { break; } @@ -1217,8 +1217,8 @@ BOOL FatReadFile(FILE *FileHandle, ULONG BytesToRead, PULONG BytesRead, PVOID Bu { *BytesRead += BytesToRead; } - BytesToRead -= BytesToRead; FatFileInfo->FilePointer += BytesToRead; + BytesToRead -= BytesToRead; Buffer += BytesToRead; } diff --git a/freeldr/freeldr/fs/iso.c b/freeldr/freeldr/fs/iso.c index 2fdfef1ecad..dfcb33dc32e 100644 --- a/freeldr/freeldr/fs/iso.c +++ b/freeldr/freeldr/fs/iso.c @@ -186,7 +186,7 @@ static ULONG IsoGetNumPathParts(PUCHAR Path) for (i=0,num=0; i<(int)strlen(Path); i++) { - if (Path[i] == '\\') + if ((Path[i] == '\\') || (Path[i] == '/')) { num++; } @@ -215,7 +215,7 @@ static VOID IsoGetFirstNameFromPath(PUCHAR Buffer, PUCHAR Path) // and put them in Buffer for (i=0; i<(int)strlen(Path); i++) { - if (Path[i] == '\\') + if ((Path[i] == '\\') || (Path[i] == '/')) { break; } @@ -257,7 +257,7 @@ static BOOL IsoLookupFile(PUCHAR FileName, PISO_FILE_INFO IsoFileInfoPointer) // // Check and see if the first character is '\' and remove it if so // - while (*FileName == '\\') + while ((*FileName == '\\') || (*FileName == '/')) { FileName++; } @@ -283,7 +283,7 @@ static BOOL IsoLookupFile(PUCHAR FileName, PISO_FILE_INFO IsoFileInfoPointer) // // Advance to the next part of the path // - for (; (*FileName != '\\') && (*FileName != '\0'); FileName++) + for (; (*FileName != '\\') && (*FileName != '/') && (*FileName != '\0'); FileName++) { } FileName++; @@ -535,8 +535,8 @@ BOOL IsoReadFile(FILE *FileHandle, ULONG BytesToRead, PULONG BytesRead, PVOID Bu { *BytesRead += BytesToRead; } - BytesToRead -= BytesToRead; IsoFileInfo->FilePointer += BytesToRead; + BytesToRead -= BytesToRead; Buffer += BytesToRead; } diff --git a/freeldr/freeldr/linux.c b/freeldr/freeldr/linux.c index 9a99c9a6ff3..9d30594a764 100644 --- a/freeldr/freeldr/linux.c +++ b/freeldr/freeldr/linux.c @@ -25,77 +25,273 @@ #include "fs.h" #include "ui.h" #include "linux.h" +#include "debug.h" +#include "mm.h" +#include "inifile.h" -void LoadAndBootLinux(int DriveNum, int Partition, char *vmlinuz, char *cmd_line) +PLINUX_BOOTSECTOR LinuxBootSector = NULL; +PLINUX_SETUPSECTOR LinuxSetupSector = NULL; +ULONG SetupSectorSize = 0; +BOOL BigZImageKernel = TRUE; +ULONG LinuxKernelSize = 0; +UCHAR LinuxKernelName[260]; +UCHAR LinuxInitrdName[260]; +BOOL LinuxHasInitrd = FALSE; +UCHAR LinuxCommandLine[260] = ""; +ULONG LinuxCommandLineSize = 0; + +VOID LoadAndBootLinux(PUCHAR OperatingSystemName) { - /*FILE file; - char temp[260]; - char bootsector[512]; - char setup[2048]; - int len; + PFILE LinuxKernel = NULL; + UCHAR TempString[260]; + + DrawBackdrop(); - BootDrive = DriveNum; - BootPartition = Partition; + // Parse the .ini file section + if (!LinuxParseIniSection(OperatingSystemName)) + { + goto LinuxBootFailed; + } + // Open the boot volume if (!OpenDiskDrive(BootDrive, BootPartition)) { MessageBox("Failed to open boot drive."); - return; + goto LinuxBootFailed; } - if (!OpenFile(vmlinuz, &file)) + // Open the kernel + LinuxKernel = OpenFile(LinuxKernelName); + if (LinuxKernel == NULL) { - strcpy(temp, vmlinuz); - strcat(temp, " not found."); - MessageBox(temp); - return; + sprintf(TempString, "Linux kernel \'%s\' not found.", LinuxKernelName); + MessageBox(TempString); + goto LinuxBootFailed; } - // Read boot sector - if (ReadFile(&file, 512, bootsector) != 512) + // Read the boot sector + if (!LinuxReadBootSector(LinuxKernel)) { - MessageBox("Disk Read Error"); - return; + goto LinuxBootFailed; } - MessageBox("bootsector loaded"); - // Read setup code - if (ReadFile(&file, 2048, setup) != 2048) + // Read the setup sector + if (!LinuxReadSetupSector(LinuxKernel)) { - MessageBox("Disk Read Error"); - return; + goto LinuxBootFailed; } - MessageBox("setup loaded"); - // Read kernel code - len = GetFileSize(&file) - (2048 + 512); - //len = 0x200; - if (ReadFile(&file, len, (void*)0x100000) != len) + // Read the kernel + if (!LinuxReadKernel(LinuxKernel)) + { + goto LinuxBootFailed; + } + + LinuxBootSector->CommandLineMagic = LINUX_COMMAND_LINE_MAGIC; + LinuxBootSector->CommandLineOffset = 0x9000; + + LinuxSetupSector->TypeOfLoader = LINUX_LOADER_TYPE_FREELOADER; + + RtlCopyMemory((PVOID)0x90000, LinuxBootSector, 512); + RtlCopyMemory((PVOID)0x90200, LinuxSetupSector, SetupSectorSize); + RtlCopyMemory((PVOID)0x99000, LinuxCommandLine, LinuxCommandLineSize); + + showcursor(); + clrscr(); + + stop_floppy(); + JumpToLinuxBootCode(); + + +LinuxBootFailed: + + if (LinuxKernel != NULL) + { + CloseFile(LinuxKernel); + } + + if (LinuxBootSector != NULL) + { + FreeMemory(LinuxBootSector); + } + if (LinuxSetupSector != NULL) { - MessageBox("Disk Read Error"); - return; + FreeMemory(LinuxSetupSector); + } + + LinuxBootSector = NULL; + LinuxSetupSector = NULL; + SetupSectorSize = 0; + BigZImageKernel = TRUE; + LinuxKernelSize = 0; + LinuxHasInitrd = FALSE; + strcpy(LinuxCommandLine, ""); + LinuxCommandLineSize = 0; +} + +BOOL LinuxParseIniSection(PUCHAR OperatingSystemName) +{ + UCHAR SettingName[260]; + UCHAR SettingValue[260]; + ULONG SectionId; + + // Find all the message box settings and run them + ShowMessageBoxesInSection(OperatingSystemName); + + // Try to open the operating system section in the .ini file + if (!IniOpenSection(OperatingSystemName, &SectionId)) + { + sprintf(SettingName, "Section [%s] not found in freeldr.ini.\n", OperatingSystemName); + MessageBox(SettingName); + return FALSE; + } + + if (!IniReadSettingByName(SectionId, "BootDrive", SettingValue, 260)) + { + MessageBox("Boot drive not specified for selected OS!"); + return FALSE; + } + + BootDrive = atoi(SettingValue); + + BootPartition = 0; + if (IniReadSettingByName(SectionId, "BootPartition", SettingValue, 260)) + { + BootPartition = atoi(SettingValue); + } + + // Get the kernel name + if (!IniReadSettingByName(SectionId, "Kernel", LinuxKernelName, 260)) + { + MessageBox("Linux kernel filename not specified for selected OS!"); + return FALSE; + } + + // Get the initrd name + if (IniReadSettingByName(SectionId, "Initrd", LinuxInitrdName, 260)) + { + LinuxHasInitrd = TRUE; + } + + // Get the command line + if (IniReadSettingByName(SectionId, "CommandLine", LinuxCommandLine, 260)) + { + LinuxCommandLineSize = strlen(LinuxCommandLine) + 1; + } + + return TRUE; +} + +BOOL LinuxReadBootSector(PFILE LinuxKernelFile) +{ + // Allocate memory for boot sector + LinuxBootSector = (PLINUX_BOOTSECTOR)AllocateMemory(512); + if (LinuxBootSector == NULL) + { + return FALSE; + } + + // Read linux boot sector + SetFilePointer(LinuxKernelFile, 0); + if (!ReadFile(LinuxKernelFile, 512, NULL, LinuxBootSector)) + { + return FALSE; } - MessageBox("kernel loaded"); // Check for validity - if (*((WORD*)(bootsector + 0x1fe)) != 0xaa55) + if (LinuxBootSector->BootFlag != LINUX_BOOT_SECTOR_MAGIC) { MessageBox("Invalid boot sector magic (0xaa55)"); - return; + return FALSE; + } + + DbgDumpBuffer(DPRINT_LINUX, LinuxBootSector, 512); + + DbgPrint((DPRINT_LINUX, "SetupSectors: %d\n", LinuxBootSector->SetupSectors)); + DbgPrint((DPRINT_LINUX, "RootFlags: 0x%x\n", LinuxBootSector->RootFlags)); + DbgPrint((DPRINT_LINUX, "SystemSize: 0x%x\n", LinuxBootSector->SystemSize)); + DbgPrint((DPRINT_LINUX, "SwapDevice: 0x%x\n", LinuxBootSector->SwapDevice)); + DbgPrint((DPRINT_LINUX, "RamSize: 0x%x\n", LinuxBootSector->RamSize)); + DbgPrint((DPRINT_LINUX, "VideoMode: 0x%x\n", LinuxBootSector->VideoMode)); + DbgPrint((DPRINT_LINUX, "RootDevice: 0x%x\n", LinuxBootSector->RootDevice)); + DbgPrint((DPRINT_LINUX, "BootFlag: 0x%x\n", LinuxBootSector->BootFlag)); + + return TRUE; +} + +BOOL LinuxReadSetupSector(PFILE LinuxKernelFile) +{ + SetupSectorSize = 512 * LinuxBootSector->SetupSectors; + + // Allocate memory for setup sectors + LinuxSetupSector = (PLINUX_SETUPSECTOR)AllocateMemory(SetupSectorSize); + if (LinuxSetupSector == NULL) + { + return FALSE; + } + + // Read linux setup sectors + SetFilePointer(LinuxKernelFile, 512); + if (!ReadFile(LinuxKernelFile, SetupSectorSize, NULL, LinuxSetupSector)) + { + return FALSE; } - if (*((DWORD*)(setup + 2)) != 0x53726448) + + // Check for validity + if (LinuxSetupSector->SetupHeaderSignature != LINUX_SETUP_HEADER_ID) { - MessageBox("Invalid setup magic (\"HdrS\")"); - return; + MessageBox("Invalid setup magic (HdrS)"); + return FALSE; } - memcpy((void*)0x90000, bootsector, 512); - memcpy((void*)0x90200, setup, 2048); + DbgDumpBuffer(DPRINT_LINUX, LinuxSetupSector, SetupSectorSize); - RestoreScreen(ScreenBuffer); - showcursor(); - gotoxy(CursorXPos, CursorYPos); + DbgPrint((DPRINT_LINUX, "SetupHeaderSignature: 0x%x (HdrS)\n", LinuxSetupSector->SetupHeaderSignature)); + DbgPrint((DPRINT_LINUX, "Version: 0x%x\n", LinuxSetupSector->Version)); + DbgPrint((DPRINT_LINUX, "RealModeSwitch: 0x%x\n", LinuxSetupSector->RealModeSwitch)); + DbgPrint((DPRINT_LINUX, "SetupSeg: 0x%x\n", LinuxSetupSector->SetupSeg)); + DbgPrint((DPRINT_LINUX, "StartSystemSeg: 0x%x\n", LinuxSetupSector->StartSystemSeg)); + DbgPrint((DPRINT_LINUX, "KernelVersion: 0x%x\n", LinuxSetupSector->KernelVersion)); + DbgPrint((DPRINT_LINUX, "TypeOfLoader: 0x%x\n", LinuxSetupSector->TypeOfLoader)); + DbgPrint((DPRINT_LINUX, "LoadFlags: 0x%x\n", LinuxSetupSector->LoadFlags)); + DbgPrint((DPRINT_LINUX, "SetupMoveSize: 0x%x\n", LinuxSetupSector->SetupMoveSize)); + DbgPrint((DPRINT_LINUX, "Code32Start: 0x%x\n", LinuxSetupSector->Code32Start)); + DbgPrint((DPRINT_LINUX, "RamdiskAddress: 0x%x\n", LinuxSetupSector->RamdiskAddress)); + DbgPrint((DPRINT_LINUX, "RamdiskSize: 0x%x\n", LinuxSetupSector->RamdiskSize)); + DbgPrint((DPRINT_LINUX, "BootSectKludgeOffset: 0x%x\n", LinuxSetupSector->BootSectKludgeOffset)); + DbgPrint((DPRINT_LINUX, "BootSectKludgeSegment: 0x%x\n", LinuxSetupSector->BootSectKludgeSegment)); + DbgPrint((DPRINT_LINUX, "HeapEnd: 0x%x\n", LinuxSetupSector->HeapEnd)); - stop_floppy(); - JumpToLinuxBootCode();*/ + return TRUE; +} + +BOOL LinuxReadKernel(PFILE LinuxKernelFile) +{ + PVOID LoadAddress = (PVOID)LINUX_KERNEL_LOAD_ADDRESS; + ULONG BytesLoaded; + UCHAR StatusText[260]; + + sprintf(StatusText, " Loading %s", LinuxKernelName); + DrawStatusText(StatusText); + DrawProgressBar(0); + + // Calc kernel size + LinuxKernelSize = GetFileSize(LinuxKernelFile) - (512 + SetupSectorSize); + + // Read linux kernel to 0x100000 (1mb) + SetFilePointer(LinuxKernelFile, 512 + SetupSectorSize); + for (BytesLoaded=0; BytesLoaded