From: Gé van Geldorp Date: Thu, 21 Apr 2005 09:29:02 +0000 (+0000) Subject: - Protect multiboot info from being overwritten X-Git-Tag: backups/powerpc@14753~17 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=5568b1261a0bccee5118f58f81f96c5deea53e18 - Protect multiboot info from being overwritten - Pass command line to MachInit() funcs svn path=/trunk/; revision=14725 --- diff --git a/reactos/boot/freeldr/freeldr/arch/i386/arch.S b/reactos/boot/freeldr/freeldr/arch/i386/arch.S index ee6ee682a49..5780ceaf87b 100644 --- a/reactos/boot/freeldr/freeldr/arch/i386/arch.S +++ b/reactos/boot/freeldr/freeldr/arch/i386/arch.S @@ -275,9 +275,11 @@ EXTERN(_DisableA20) * other boot loaders like Grub */ +#define MB_INFO_SIZE 90 #define MB_INFO_FLAGS_OFFSET 0 #define MB_INFO_BOOT_DEVICE_OFFSET 12 #define MB_INFO_COMMAND_LINE_OFFSET 16 +#define CMDLINE_SIZE 256 /* * We want to execute at 0x8000 (to be compatible with bootsector @@ -285,7 +287,6 @@ EXTERN(_DisableA20) * above 1MB. So we let Grub load us there and then relocate * ourself to 0x8000 */ -#define CMDLINE_BASE 0x7000 #define FREELDR_BASE 0x8000 #define INITIAL_BASE 0x200000 @@ -328,6 +329,31 @@ mb1: movw %dx,%ds movw %dx,%es + /* Check for valid multiboot signature */ + cmpl $MULTIBOOT_BOOTLOADER_MAGIC,%eax + jne mbfail + + /* Store multiboot info in a safe place */ + movl %ebx,%esi + movl $(mb_info + INITIAL_BASE - FREELDR_BASE),%edi + movl $MB_INFO_SIZE,%ecx + rep movsb + + /* Save commandline */ + movl MB_INFO_FLAGS_OFFSET(%ebx),%edx + testl $MB_INFO_FLAG_COMMAND_LINE,MB_INFO_FLAGS_OFFSET(%ebx) + jz mb3 + movl MB_INFO_COMMAND_LINE_OFFSET(%ebx),%esi + movl $(cmdline + INITIAL_BASE - FREELDR_BASE),%edi + movl $CMDLINE_SIZE,%ecx +mb2: lodsb + stosb + testb %al,%al + jz mb3 + dec %ecx + jnz mb2 +mb3: + /* Copy to low mem */ movl $INITIAL_BASE,%esi movl $FREELDR_BASE,%edi @@ -342,8 +368,8 @@ mb1: /* Clear prefetch queue & correct CS, * jump to low mem */ - ljmp $PMODE_CS, $mb2 -mb2: + ljmp $PMODE_CS, $mb4 +mb4: /* Reload segment selectors */ movw $PMODE_DS,%dx movw %dx,%ds @@ -353,39 +379,28 @@ mb2: movw %dx,%ss movl $STACK32ADDR,%esp - /* Check for valid multiboot signature */ - cmpl $MULTIBOOT_BOOTLOADER_MAGIC,%eax - jne mbfail - + movl $mb_info,%ebx /* See if the boot device was passed in */ movl MB_INFO_FLAGS_OFFSET(%ebx),%edx testl $MB_INFO_FLAG_BOOT_DEVICE,%edx - jz mb3 + jz mb5 /* Retrieve boot device info */ movl MB_INFO_BOOT_DEVICE_OFFSET(%ebx),%eax shrl $16,%eax incb %al movb %al,_i386BootPartition movb %ah,_i386BootDrive - jmp mb4 -mb3: /* No boot device known, assume first partition of first harddisk */ + jmp mb6 +mb5: /* No boot device known, assume first partition of first harddisk */ movb $0x80,_i386BootDrive movb $1,_i386BootPartition -mb4: - - /* Check for a command line */ - xorl %eax,%eax - testl $MB_INFO_FLAG_COMMAND_LINE,%edx - jz mb6 - /* Copy command line to low mem*/ - movl MB_INFO_COMMAND_LINE_OFFSET(%ebx),%esi - movl $CMDLINE_BASE,%edi -mb5: lodsb - stosb - testb %al,%al - jnz mb5 - movl $CMDLINE_BASE,%eax mb6: + /* Check for command line */ + mov $cmdline,%eax + testl $MB_INFO_FLAG_COMMAND_LINE,MB_INFO_FLAGS_OFFSET(%ebx) + jnz mb7 + xorl %eax,%eax +mb7: /* GO! */ pushl %eax @@ -467,3 +482,10 @@ EXTERN(_i386BootDrive) EXTERN(_i386BootPartition) .long 0 + +.bss +mb_info: + .fill MB_INFO_SIZE, 1, 0 + +cmdline: + .fill CMDLINE_SIZE, 1, 0 diff --git a/reactos/boot/freeldr/freeldr/arch/i386/archmach.c b/reactos/boot/freeldr/freeldr/arch/i386/archmach.c index 347d8f56e22..c8171b0208c 100644 --- a/reactos/boot/freeldr/freeldr/arch/i386/archmach.c +++ b/reactos/boot/freeldr/freeldr/arch/i386/archmach.c @@ -27,7 +27,7 @@ #include "rtl.h" VOID -MachInit(VOID) +MachInit(char *CmdLine) { ULONG PciId; @@ -39,11 +39,11 @@ MachInit(VOID) PciId = READ_PORT_ULONG((ULONG*) 0xcfc); if (0x02a510de == PciId) { - XboxMachInit(); + XboxMachInit(CmdLine); } else { - PcMachInit(); + PcMachInit(CmdLine); } HalpCalibrateStallExecution(); diff --git a/reactos/boot/freeldr/freeldr/arch/i386/machpc.c b/reactos/boot/freeldr/freeldr/arch/i386/machpc.c index e35583dec5d..8bbe0cadbc8 100644 --- a/reactos/boot/freeldr/freeldr/arch/i386/machpc.c +++ b/reactos/boot/freeldr/freeldr/arch/i386/machpc.c @@ -26,7 +26,7 @@ #include "i386.h" VOID -PcMachInit(VOID) +PcMachInit(char *CmdLine) { EnableA20(); diff --git a/reactos/boot/freeldr/freeldr/arch/i386/machpc.h b/reactos/boot/freeldr/freeldr/arch/i386/machpc.h index 5462a10effa..7a2a6eb58b8 100644 --- a/reactos/boot/freeldr/freeldr/arch/i386/machpc.h +++ b/reactos/boot/freeldr/freeldr/arch/i386/machpc.h @@ -26,7 +26,7 @@ #include "mm.h" #endif -VOID PcMachInit(VOID); +VOID PcMachInit(char *CmdLine); VOID PcConsPutChar(int Ch); BOOL PcConsKbHit(); diff --git a/reactos/boot/freeldr/freeldr/arch/i386/machxbox.c b/reactos/boot/freeldr/freeldr/arch/i386/machxbox.c index 37819da67c1..bbb3ca86f44 100644 --- a/reactos/boot/freeldr/freeldr/arch/i386/machxbox.c +++ b/reactos/boot/freeldr/freeldr/arch/i386/machxbox.c @@ -24,7 +24,7 @@ #include "i386.h" VOID -XboxMachInit(VOID) +XboxMachInit(char *CmdLine) { /* Initialize our stuff */ XboxMemInit(); diff --git a/reactos/boot/freeldr/freeldr/arch/i386/machxbox.h b/reactos/boot/freeldr/freeldr/arch/i386/machxbox.h index 845f242e8b0..d82cdc8f246 100644 --- a/reactos/boot/freeldr/freeldr/arch/i386/machxbox.h +++ b/reactos/boot/freeldr/freeldr/arch/i386/machxbox.h @@ -26,7 +26,7 @@ UCHAR XboxFont8x16[256 * 16]; -VOID XboxMachInit(VOID); +VOID XboxMachInit(char *CmdLine); VOID XboxConsPutChar(int Ch); BOOL XboxConsKbHit(); diff --git a/reactos/boot/freeldr/freeldr/arch/powerpc/mach.c b/reactos/boot/freeldr/freeldr/arch/powerpc/mach.c index b5405cc2864..071ec9ebe17 100644 --- a/reactos/boot/freeldr/freeldr/arch/powerpc/mach.c +++ b/reactos/boot/freeldr/freeldr/arch/powerpc/mach.c @@ -279,7 +279,7 @@ void PpcInit( of_proxy the_ofproxy ) { BootMain("freeldr-ppc"); } -void MachInit() { +void MachInit(char *CmdLine) { int len; printf( "Determining boot device:\n" ); len = ofw_getprop(chosen_package, "bootpath", diff --git a/reactos/boot/freeldr/freeldr/freeldr.c b/reactos/boot/freeldr/freeldr/freeldr.c index d1a6b5675de..0a2259a67c9 100644 --- a/reactos/boot/freeldr/freeldr/freeldr.c +++ b/reactos/boot/freeldr/freeldr/freeldr.c @@ -31,7 +31,7 @@ VOID BootMain(char *CmdLine) { CmdLineParse(CmdLine); - MachInit(); + MachInit(CmdLine); DebugInit(); diff --git a/reactos/boot/freeldr/freeldr/include/machine.h b/reactos/boot/freeldr/freeldr/include/machine.h index 3f917ae6375..5879d2ef466 100644 --- a/reactos/boot/freeldr/freeldr/include/machine.h +++ b/reactos/boot/freeldr/freeldr/include/machine.h @@ -71,7 +71,7 @@ typedef struct tagMACHVTBL VOID (*HwDetect)(VOID); } MACHVTBL, *PMACHVTBL; -VOID MachInit(VOID); +VOID MachInit(char *CmdLine); extern MACHVTBL MachVtbl;