- Protect multiboot info from being overwritten

- Pass command line to MachInit() funcs

svn path=/trunk/; revision=14725
This commit is contained in:
Gé van Geldorp 2005-04-21 09:29:02 +00:00
parent ee219b0e23
commit 5568b1261a
9 changed files with 56 additions and 34 deletions

View file

@ -275,9 +275,11 @@ EXTERN(_DisableA20)
* other boot loaders like Grub * other boot loaders like Grub
*/ */
#define MB_INFO_SIZE 90
#define MB_INFO_FLAGS_OFFSET 0 #define MB_INFO_FLAGS_OFFSET 0
#define MB_INFO_BOOT_DEVICE_OFFSET 12 #define MB_INFO_BOOT_DEVICE_OFFSET 12
#define MB_INFO_COMMAND_LINE_OFFSET 16 #define MB_INFO_COMMAND_LINE_OFFSET 16
#define CMDLINE_SIZE 256
/* /*
* We want to execute at 0x8000 (to be compatible with bootsector * 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 * above 1MB. So we let Grub load us there and then relocate
* ourself to 0x8000 * ourself to 0x8000
*/ */
#define CMDLINE_BASE 0x7000
#define FREELDR_BASE 0x8000 #define FREELDR_BASE 0x8000
#define INITIAL_BASE 0x200000 #define INITIAL_BASE 0x200000
@ -328,6 +329,31 @@ mb1:
movw %dx,%ds movw %dx,%ds
movw %dx,%es 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 */ /* Copy to low mem */
movl $INITIAL_BASE,%esi movl $INITIAL_BASE,%esi
movl $FREELDR_BASE,%edi movl $FREELDR_BASE,%edi
@ -342,8 +368,8 @@ mb1:
/* Clear prefetch queue & correct CS, /* Clear prefetch queue & correct CS,
* jump to low mem */ * jump to low mem */
ljmp $PMODE_CS, $mb2 ljmp $PMODE_CS, $mb4
mb2: mb4:
/* Reload segment selectors */ /* Reload segment selectors */
movw $PMODE_DS,%dx movw $PMODE_DS,%dx
movw %dx,%ds movw %dx,%ds
@ -353,39 +379,28 @@ mb2:
movw %dx,%ss movw %dx,%ss
movl $STACK32ADDR,%esp movl $STACK32ADDR,%esp
/* Check for valid multiboot signature */ movl $mb_info,%ebx
cmpl $MULTIBOOT_BOOTLOADER_MAGIC,%eax
jne mbfail
/* See if the boot device was passed in */ /* See if the boot device was passed in */
movl MB_INFO_FLAGS_OFFSET(%ebx),%edx movl MB_INFO_FLAGS_OFFSET(%ebx),%edx
testl $MB_INFO_FLAG_BOOT_DEVICE,%edx testl $MB_INFO_FLAG_BOOT_DEVICE,%edx
jz mb3 jz mb5
/* Retrieve boot device info */ /* Retrieve boot device info */
movl MB_INFO_BOOT_DEVICE_OFFSET(%ebx),%eax movl MB_INFO_BOOT_DEVICE_OFFSET(%ebx),%eax
shrl $16,%eax shrl $16,%eax
incb %al incb %al
movb %al,_i386BootPartition movb %al,_i386BootPartition
movb %ah,_i386BootDrive movb %ah,_i386BootDrive
jmp mb4 jmp mb6
mb3: /* No boot device known, assume first partition of first harddisk */ mb5: /* No boot device known, assume first partition of first harddisk */
movb $0x80,_i386BootDrive movb $0x80,_i386BootDrive
movb $1,_i386BootPartition 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: 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! */ /* GO! */
pushl %eax pushl %eax
@ -467,3 +482,10 @@ EXTERN(_i386BootDrive)
EXTERN(_i386BootPartition) EXTERN(_i386BootPartition)
.long 0 .long 0
.bss
mb_info:
.fill MB_INFO_SIZE, 1, 0
cmdline:
.fill CMDLINE_SIZE, 1, 0

View file

@ -27,7 +27,7 @@
#include "rtl.h" #include "rtl.h"
VOID VOID
MachInit(VOID) MachInit(char *CmdLine)
{ {
ULONG PciId; ULONG PciId;
@ -39,11 +39,11 @@ MachInit(VOID)
PciId = READ_PORT_ULONG((ULONG*) 0xcfc); PciId = READ_PORT_ULONG((ULONG*) 0xcfc);
if (0x02a510de == PciId) if (0x02a510de == PciId)
{ {
XboxMachInit(); XboxMachInit(CmdLine);
} }
else else
{ {
PcMachInit(); PcMachInit(CmdLine);
} }
HalpCalibrateStallExecution(); HalpCalibrateStallExecution();

View file

@ -26,7 +26,7 @@
#include "i386.h" #include "i386.h"
VOID VOID
PcMachInit(VOID) PcMachInit(char *CmdLine)
{ {
EnableA20(); EnableA20();

View file

@ -26,7 +26,7 @@
#include "mm.h" #include "mm.h"
#endif #endif
VOID PcMachInit(VOID); VOID PcMachInit(char *CmdLine);
VOID PcConsPutChar(int Ch); VOID PcConsPutChar(int Ch);
BOOL PcConsKbHit(); BOOL PcConsKbHit();

View file

@ -24,7 +24,7 @@
#include "i386.h" #include "i386.h"
VOID VOID
XboxMachInit(VOID) XboxMachInit(char *CmdLine)
{ {
/* Initialize our stuff */ /* Initialize our stuff */
XboxMemInit(); XboxMemInit();

View file

@ -26,7 +26,7 @@
UCHAR XboxFont8x16[256 * 16]; UCHAR XboxFont8x16[256 * 16];
VOID XboxMachInit(VOID); VOID XboxMachInit(char *CmdLine);
VOID XboxConsPutChar(int Ch); VOID XboxConsPutChar(int Ch);
BOOL XboxConsKbHit(); BOOL XboxConsKbHit();

View file

@ -279,7 +279,7 @@ void PpcInit( of_proxy the_ofproxy ) {
BootMain("freeldr-ppc"); BootMain("freeldr-ppc");
} }
void MachInit() { void MachInit(char *CmdLine) {
int len; int len;
printf( "Determining boot device:\n" ); printf( "Determining boot device:\n" );
len = ofw_getprop(chosen_package, "bootpath", len = ofw_getprop(chosen_package, "bootpath",

View file

@ -31,7 +31,7 @@ VOID BootMain(char *CmdLine)
{ {
CmdLineParse(CmdLine); CmdLineParse(CmdLine);
MachInit(); MachInit(CmdLine);
DebugInit(); DebugInit();

View file

@ -71,7 +71,7 @@ typedef struct tagMACHVTBL
VOID (*HwDetect)(VOID); VOID (*HwDetect)(VOID);
} MACHVTBL, *PMACHVTBL; } MACHVTBL, *PMACHVTBL;
VOID MachInit(VOID); VOID MachInit(char *CmdLine);
extern MACHVTBL MachVtbl; extern MACHVTBL MachVtbl;