BlStartup 函数

ContractedBlock.gif ExpandedBlockStart.gif Code
VOID
BlStartup(
    IN PCHAR PartitionName
    )
/*++
Routine Description:
    Does x86-specific initialization, particularly presenting the boot.ini
    menu and running NTDETECT, then calls to the common osloader.
Arguments:
    PartitionName - Supplies the ARC name of the partition (or floppy) that
        setupldr was loaded from.
Return Value:
    Does not return
--
*/
{
    PUCHAR Argv[
10];
    ARC_STATUS Status;
    ULONG BootFileId;
    PCHAR BootFile;
    ULONG Read;
    PCHAR p;
    ULONG i;
    ULONG DriveId;
    ULONG FileSize;
    ULONG Count;
    LARGE_INTEGER SeekPosition;
    PCHAR LoadOptions 
= NULL;
    BOOLEAN UseTimeOut
=TRUE;
    BOOLEAN AlreadyInitialized 
= FALSE;
    
extern BOOLEAN FwDescriptorsValid;
    
//
    
// Open the boot partition so we can load boot drivers off it.
    
//
    Status = ArcOpen(PartitionName, ArcOpenReadOnly, &DriveId);
    
if (Status != ESUCCESS) {
        BlPrint(
"Couldn't open drive %s\n",PartitionName);
        BlPrint(BlFindMessage(BL_DRIVE_ERROR),PartitionName);
        
goto BootFailed;
    }
    
//
    
// Initialize dbcs font and display support.
    
//
    TextGrInitialize(DriveId);
    
do {
        Status 
= BlOpen( DriveId,
                         
"[url=file://\\boot.ini]\\boot.ini[/url]",
                         ArcOpenReadOnly,
                         
&BootFileId );
        BootFile 
= MyBuffer;
        RtlZeroMemory(MyBuffer, SECTOR_SIZE
+32);
        
if (Status != ESUCCESS) {
            BootFile[
0]='\0';
        } 
else {
            
//
            
// Determine the length of the boot.ini file by reading to the end of
            
// file.
            
//
            FileSize = 0;
            
do {
                Status 
= BlRead(BootFileId, BootFile, SECTOR_SIZE, &Count);
                
if (Status != ESUCCESS) {
                    BlClose(BootFileId);
                    BlPrint(BlFindMessage(BL_READ_ERROR),Status);
                    BootFile[
0= '\0';
                    FileSize 
= 0;
                    Count 
= 0;
                    
goto BootFailed;
                }
                FileSize 
+= Count;
            } 
while (Count != 0);
            
if (FileSize >= SECTOR_SIZE) {
                
//
                
// We need to allocate a bigger buffer, since the boot.ini file
                
// is bigger than one sector.
                
//
                BootFile=FwAllocateHeap(FileSize);
            }
            
if (BootFile == NULL) {
                BlPrint(BlFindMessage(BL_READ_ERROR),ENOMEM);
                BootFile 
= MyBuffer;
                BootFile[
0= '\0';
                
goto BootFailed;
            } 
else {
                SeekPosition.QuadPart 
= 0;
                Status 
= BlSeek(BootFileId,
                                
&SeekPosition,
                                SeekAbsolute);
                
if (Status != ESUCCESS) {
                    BlPrint(BlFindMessage(BL_READ_ERROR),Status);
                    BootFile 
= MyBuffer;
                    BootFile[
0= '\0';
                    
goto BootFailed;
                } 
else {
                    Status 
= BlRead( BootFileId,
                                     BootFile,
                                     FileSize,
                                     
&Read );
                    SeekPosition.QuadPart 
= 0;
                    Status 
= BlSeek(BootFileId,
                                    
&SeekPosition,
                                    SeekAbsolute);
                    
if (Status != ESUCCESS) {
                        BlPrint(BlFindMessage(BL_READ_ERROR),Status);
                        BootFile 
= MyBuffer;
                        BootFile[
0= '\0';
                        
goto BootFailed;
                    } 
else {
                        BootFile[Read]
='\0';
                    }
                }
            }
            
//
            
// Find Ctrl-Z, if it exists
            
//
            p=BootFile;
            
while ((*p!='\0'&& (*p!=26)) {
                
++p;
            }
            
if (*!= '\0') {
                
*p='\0';
            }
            BlClose(BootFileId);
        }
        
if (!AlreadyInitialized) {
            AbiosInitDataStructures();
        }
        MdShutoffFloppy();
        TextClearDisplay();
        p
=BlSelectKernel(DriveId,BootFile, &LoadOptions, UseTimeOut);
        
if (!AlreadyInitialized) {
            BlPrint(BlFindMessage(BL_NTDETECT_MSG));
            
if (!BlDetectHardware(DriveId, LoadOptions)) {
                BlPrint(BlFindMessage(BL_NTDETECT_FAILURE));
                
return;
            }
            TextClearDisplay();
            
//
            
// Initialize SCSI boot driver, if necessary.
            
//
            if(!_strnicmp(p,"scsi(",5)) {
                AEInitializeIo(DriveId);
            }
            ArcClose(DriveId);
            
//
            
// Indicate that fw memory descriptors cannot be changed from
            
// now on.
            
//
            FwDescriptorsValid = FALSE;
        } 
else {
            TextClearDisplay();
        }
        
//
        
// Set AlreadyInitialized Flag to TRUE to indicate that ntdetect
        
// and abios init routines have been run.
        
//
        AlreadyInitialized = TRUE;
        
//
        
// Only time out the boot menu the first time through the boot.
        
// For all subsequent reboots, the menu will stay up.
        
//
        UseTimeOut=FALSE;
        i
=0;
        
while (*!='\\') {
            KernelBootDevice 
= *p;
            i
++;
            p
++;
        }
        KernelBootDevice 
= '\0';
        strcpy(OsLoadFilename,
"osloadfilename=");
        strcat(OsLoadFilename,p);
        
//
        
// We are fooling the OS Loader here. It only uses the osloader= variable
        
// to determine where to load HAL.DLL from. Since x86 systems have no
        
// "system partition" we want to load HAL.DLL from \nt\system\HAL.DLL.
        
// So we pass that it as the osloader path.
        
//
        strcpy(OsLoaderFilename,"osloader=");
        strcat(OsLoaderFilename,p);
        strcat(OsLoaderFilename,
"[url=file://\\System32\\NTLDR]\\System32\\NTLDR[/url]");
        strcpy(SystemPartition,
"systempartition=");
        strcat(SystemPartition,KernelBootDevice);
        strcpy(OsLoadPartition,
"osloadpartition=");
        strcat(OsLoadPartition,KernelBootDevice);
        strcpy(OsLoadOptions,
"osloadoptions=");
        
if (LoadOptions) {
            strcat(OsLoadOptions,LoadOptions);
        }

        strcpy(ConsoleInputName,
"consolein=multi(0)key(0)keyboard(0)");
        strcpy(ConsoleOutputName,
"consoleout=multi(0)video(0)monitor(0)");
        strcpy(X86SystemPartition,
"x86systempartition=");
        strcat(X86SystemPartition,PartitionName);
        Argv[
0]="load";
        Argv[
1]=OsLoaderFilename;
        Argv[
2]=SystemPartition;
        Argv[
3]=OsLoadFilename;
        Argv[
4]=OsLoadPartition;
        Argv[
5]=OsLoadOptions;
        Argv[
6]=ConsoleInputName;
        Argv[
7]=ConsoleOutputName;
        Argv[
8]=X86SystemPartition;
        Status 
= BlOsLoader(9,Argv,NULL);
    BootFailed:
        
if (Status != ESUCCESS) {
            
//
            
// Boot failed, wait for reboot
            
//
            while (TRUE) {
                GET_KEY();
            }
        } 
else {
            
//
            
// Need to reopen the drive
            
//
            Status = ArcOpen(BootPartitionName, ArcOpenReadOnly, &DriveId);
            
if (Status != ESUCCESS) {
                BlPrint(BlFindMessage(BL_DRIVE_ERROR),BootPartitionName);
                
goto BootFailed;
            }
        }
    } 
while (TRUE);
}

转载于:https://www.cnblogs.com/binsys/articles/1303008.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值