2009-03-12 14:42:02 +00:00
|
|
|
/*
|
|
|
|
* FreeLoader
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Aleksey Bragin <aleksey@reactos.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
2009-10-27 10:34:16 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2009-03-12 14:42:02 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <freeldr.h>
|
|
|
|
|
|
|
|
#include <ndk/ldrtypes.h>
|
2009-03-21 11:11:44 +00:00
|
|
|
#include <arc/setupblk.h>
|
|
|
|
|
2009-03-12 14:42:02 +00:00
|
|
|
#include <debug.h>
|
|
|
|
|
2011-09-03 10:56:36 +00:00
|
|
|
DBG_DEFAULT_CHANNEL(WINDOWS);
|
|
|
|
|
2011-08-31 13:47:25 +00:00
|
|
|
void
|
|
|
|
WinLdrSetupMachineDependent(PLOADER_PARAMETER_BLOCK LoaderBlock);
|
|
|
|
|
2009-03-15 10:46:41 +00:00
|
|
|
VOID
|
2011-08-31 13:47:25 +00:00
|
|
|
WinLdrSetProcessorContext(void);
|
2009-03-15 10:46:41 +00:00
|
|
|
|
2011-08-31 13:47:25 +00:00
|
|
|
// TODO: Move to .h
|
|
|
|
VOID AllocateAndInitLPB(PLOADER_PARAMETER_BLOCK *OutLoaderBlock);
|
2009-03-15 10:46:41 +00:00
|
|
|
|
2011-10-03 08:32:07 +00:00
|
|
|
static VOID
|
2009-03-15 11:10:52 +00:00
|
|
|
SetupLdrLoadNlsData(PLOADER_PARAMETER_BLOCK LoaderBlock, HINF InfHandle, LPCSTR SearchPath)
|
|
|
|
{
|
|
|
|
INFCONTEXT InfContext;
|
|
|
|
BOOLEAN Status;
|
|
|
|
LPCSTR AnsiName, OemName, LangName;
|
|
|
|
|
|
|
|
/* Get ANSI codepage file */
|
|
|
|
if (!InfFindFirstLine(InfHandle, "NLS", "AnsiCodepage", &InfContext))
|
|
|
|
{
|
2011-09-03 10:56:36 +00:00
|
|
|
ERR("Failed to find 'NLS/AnsiCodepage'\n");
|
2009-03-15 11:10:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!InfGetDataField(&InfContext, 1, &AnsiName))
|
|
|
|
{
|
2011-09-03 10:56:36 +00:00
|
|
|
ERR("Failed to get load options\n");
|
2009-03-15 11:10:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get OEM codepage file */
|
|
|
|
if (!InfFindFirstLine(InfHandle, "NLS", "OemCodepage", &InfContext))
|
|
|
|
{
|
2011-09-03 10:56:36 +00:00
|
|
|
ERR("Failed to find 'NLS/AnsiCodepage'\n");
|
2009-03-15 11:10:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!InfGetDataField(&InfContext, 1, &OemName))
|
|
|
|
{
|
2011-09-03 10:56:36 +00:00
|
|
|
ERR("Failed to get load options\n");
|
2009-03-15 11:10:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!InfFindFirstLine(InfHandle, "NLS", "UnicodeCasetable", &InfContext))
|
|
|
|
{
|
2011-09-03 10:56:36 +00:00
|
|
|
ERR("Failed to find 'NLS/AnsiCodepage'\n");
|
2009-03-15 11:10:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!InfGetDataField(&InfContext, 1, &LangName))
|
|
|
|
{
|
2011-09-03 10:56:36 +00:00
|
|
|
ERR("Failed to get load options\n");
|
2009-03-15 11:10:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = WinLdrLoadNLSData(LoaderBlock, SearchPath, AnsiName, OemName, LangName);
|
2011-09-03 10:56:36 +00:00
|
|
|
TRACE("NLS data loaded with status %d\n", Status);
|
2009-03-15 11:10:52 +00:00
|
|
|
}
|
|
|
|
|
2011-10-03 08:32:07 +00:00
|
|
|
static VOID
|
|
|
|
SetupLdrScanBootDrivers(PLIST_ENTRY BootDriverListHead, HINF InfHandle, LPCSTR SearchPath)
|
2009-03-16 20:56:07 +00:00
|
|
|
{
|
2011-05-20 22:29:54 +00:00
|
|
|
INFCONTEXT InfContext, dirContext;
|
2009-03-16 20:56:07 +00:00
|
|
|
BOOLEAN Status;
|
2011-05-20 22:29:54 +00:00
|
|
|
LPCSTR Media, DriverName, dirIndex, ImagePath;
|
2009-03-16 20:56:07 +00:00
|
|
|
WCHAR ServiceName[256];
|
2011-05-20 22:29:54 +00:00
|
|
|
WCHAR ImagePathW[256];
|
2009-03-16 20:56:07 +00:00
|
|
|
|
|
|
|
/* Open inf section */
|
|
|
|
if (!InfFindFirstLine(InfHandle, "SourceDisksFiles", NULL, &InfContext))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Load all listed boot drivers */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (InfGetDataField(&InfContext, 7, &Media) &&
|
2011-06-25 13:52:47 +00:00
|
|
|
InfGetDataField(&InfContext, 0, &DriverName) &&
|
2011-05-20 22:29:54 +00:00
|
|
|
InfGetDataField(&InfContext, 13, &dirIndex))
|
2009-03-16 20:56:07 +00:00
|
|
|
{
|
2011-05-20 22:29:54 +00:00
|
|
|
if ((strcmp(Media, "x") == 0) &&
|
|
|
|
InfFindFirstLine(InfHandle, "Directories", dirIndex, &dirContext) &&
|
|
|
|
InfGetDataField(&dirContext, 1, &ImagePath))
|
2009-03-16 20:56:07 +00:00
|
|
|
{
|
|
|
|
/* Convert name to widechar */
|
|
|
|
swprintf(ServiceName, L"%S", DriverName);
|
|
|
|
|
2011-05-20 22:29:54 +00:00
|
|
|
/* Prepare image path */
|
|
|
|
swprintf(ImagePathW, L"%S", ImagePath);
|
|
|
|
wcscat(ImagePathW, L"\\");
|
|
|
|
wcscat(ImagePathW, ServiceName);
|
2011-06-25 13:52:47 +00:00
|
|
|
|
2009-03-16 20:56:07 +00:00
|
|
|
/* Remove .sys extension */
|
|
|
|
ServiceName[wcslen(ServiceName) - 4] = 0;
|
|
|
|
|
|
|
|
/* Add it to the list */
|
2011-10-03 08:32:07 +00:00
|
|
|
Status = WinLdrAddDriverToList(BootDriverListHead,
|
2009-03-16 20:56:07 +00:00
|
|
|
L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\",
|
2011-05-20 22:29:54 +00:00
|
|
|
ImagePathW,
|
2009-03-16 20:56:07 +00:00
|
|
|
ServiceName);
|
|
|
|
|
|
|
|
if (!Status)
|
|
|
|
{
|
2011-09-03 10:56:36 +00:00
|
|
|
ERR("could not add boot driver %s, %s\n", SearchPath, DriverName);
|
2009-03-16 20:56:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (InfFindNextLine(&InfContext, &InfContext));
|
|
|
|
}
|
|
|
|
|
2012-12-13 00:46:55 +00:00
|
|
|
VOID
|
|
|
|
LoadReactOSSetup(IN OperatingSystemItem* OperatingSystem,
|
|
|
|
IN USHORT OperatingSystemVersion)
|
2009-03-12 14:42:02 +00:00
|
|
|
{
|
2011-08-31 13:47:25 +00:00
|
|
|
CHAR FileName[512];
|
|
|
|
CHAR BootPath[512];
|
2009-09-25 13:03:42 +00:00
|
|
|
LPCSTR LoadOptions, BootOptions;
|
2009-10-03 12:49:14 +00:00
|
|
|
BOOLEAN BootFromFloppy;
|
2009-03-15 10:46:41 +00:00
|
|
|
ULONG i, ErrorLine;
|
|
|
|
HINF InfHandle;
|
|
|
|
INFCONTEXT InfContext;
|
2011-08-31 13:47:25 +00:00
|
|
|
PLOADER_PARAMETER_BLOCK LoaderBlock;
|
2009-03-21 11:11:44 +00:00
|
|
|
PSETUP_LOADER_BLOCK SetupBlock;
|
2011-08-31 13:47:25 +00:00
|
|
|
LPCSTR SystemPath;
|
2009-03-15 10:46:41 +00:00
|
|
|
LPCSTR SourcePaths[] =
|
|
|
|
{
|
2011-08-31 13:47:25 +00:00
|
|
|
"\\", /* Only for floppy boot */
|
2009-03-15 10:46:41 +00:00
|
|
|
#if defined(_M_IX86)
|
2011-08-31 13:47:25 +00:00
|
|
|
"\\I386\\",
|
2009-03-15 10:46:41 +00:00
|
|
|
#elif defined(_M_MPPC)
|
2011-08-31 13:47:25 +00:00
|
|
|
"\\PPC\\",
|
2009-03-15 10:46:41 +00:00
|
|
|
#elif defined(_M_MRX000)
|
2011-08-31 13:47:25 +00:00
|
|
|
"\\MIPS\\",
|
2009-03-15 10:46:41 +00:00
|
|
|
#endif
|
2011-08-31 13:47:25 +00:00
|
|
|
"\\reactos\\",
|
2009-03-15 10:46:41 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2009-10-03 12:49:14 +00:00
|
|
|
/* Get boot path */
|
2011-08-31 13:47:25 +00:00
|
|
|
MachDiskGetBootPath(BootPath, sizeof(BootPath));
|
2009-10-03 12:49:14 +00:00
|
|
|
|
|
|
|
/* And check if we booted from floppy */
|
2011-08-31 13:47:25 +00:00
|
|
|
BootFromFloppy = strstr(BootPath, "fdisk") != NULL;
|
2009-10-03 12:49:14 +00:00
|
|
|
|
|
|
|
/* Open 'txtsetup.sif' from any of source paths */
|
|
|
|
for (i = BootFromFloppy ? 0 : 1; ; i++)
|
2009-03-15 10:46:41 +00:00
|
|
|
{
|
2011-08-31 13:47:25 +00:00
|
|
|
SystemPath = SourcePaths[i];
|
|
|
|
if (!SystemPath)
|
2009-03-15 10:46:41 +00:00
|
|
|
{
|
2011-09-03 10:56:36 +00:00
|
|
|
ERR("Failed to open txtsetup.sif\n");
|
2009-03-15 10:46:41 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-08-31 13:47:25 +00:00
|
|
|
sprintf(FileName, "%stxtsetup.sif", SystemPath);
|
2009-03-15 10:46:41 +00:00
|
|
|
if (InfOpenFile (&InfHandle, FileName, &ErrorLine))
|
2009-04-20 20:04:23 +00:00
|
|
|
{
|
2011-08-31 13:47:25 +00:00
|
|
|
strcat(BootPath, SystemPath);
|
2009-03-15 10:46:41 +00:00
|
|
|
break;
|
2009-04-20 20:04:23 +00:00
|
|
|
}
|
2009-03-15 10:46:41 +00:00
|
|
|
}
|
|
|
|
|
2011-09-03 10:56:36 +00:00
|
|
|
TRACE("BootPath: '%s', SystemPath: '%s'\n", BootPath, SystemPath);
|
2011-08-31 13:47:25 +00:00
|
|
|
|
2009-09-25 09:28:37 +00:00
|
|
|
/* Get Load options - debug and non-debug */
|
2011-08-31 13:47:25 +00:00
|
|
|
if (!InfFindFirstLine(InfHandle, "SetupData", "OsLoadOptions", &InfContext))
|
2009-03-15 10:46:41 +00:00
|
|
|
{
|
2011-09-03 10:56:36 +00:00
|
|
|
ERR("Failed to find 'SetupData/OsLoadOptions'\n");
|
2009-03-15 10:46:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-09-25 09:28:37 +00:00
|
|
|
if (!InfGetDataField (&InfContext, 1, &LoadOptions))
|
2009-03-15 10:46:41 +00:00
|
|
|
{
|
2011-09-03 10:56:36 +00:00
|
|
|
ERR("Failed to get load options\n");
|
2009-03-15 10:46:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-09-25 09:28:37 +00:00
|
|
|
BootOptions = LoadOptions;
|
|
|
|
|
|
|
|
#if DBG
|
|
|
|
/* Get debug load options and use them */
|
2011-08-31 13:47:25 +00:00
|
|
|
if (InfFindFirstLine(InfHandle, "SetupData", "DbgOsLoadOptions", &InfContext))
|
2009-09-25 09:28:37 +00:00
|
|
|
{
|
2011-08-31 13:47:25 +00:00
|
|
|
if (InfGetDataField(&InfContext, 1, &LoadOptions))
|
|
|
|
BootOptions = LoadOptions;
|
2009-09-25 09:28:37 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-09-03 10:56:36 +00:00
|
|
|
TRACE("BootOptions: '%s'\n", BootOptions);
|
2009-09-25 09:28:37 +00:00
|
|
|
|
2012-12-09 15:01:51 +00:00
|
|
|
UiDrawStatusText("Setup is loading...");
|
2009-03-15 10:46:41 +00:00
|
|
|
|
|
|
|
/* Allocate and minimalistic-initialize LPB */
|
|
|
|
AllocateAndInitLPB(&LoaderBlock);
|
2009-03-12 14:42:02 +00:00
|
|
|
|
2009-03-21 11:11:44 +00:00
|
|
|
/* Allocate and initialize setup loader block */
|
2011-09-26 16:06:19 +00:00
|
|
|
SetupBlock = &WinLdrSystemBlock->SetupBlock;
|
2009-03-21 11:11:44 +00:00
|
|
|
LoaderBlock->SetupLdrBlock = SetupBlock;
|
|
|
|
|
|
|
|
/* Set textmode setup flag */
|
|
|
|
SetupBlock->Flags = SETUPLDR_TEXT_MODE;
|
|
|
|
|
2011-05-20 22:29:54 +00:00
|
|
|
/* Load NLS data, they are in system32 */
|
2011-08-31 13:47:25 +00:00
|
|
|
strcpy(FileName, BootPath);
|
|
|
|
strcat(FileName, "system32\\");
|
|
|
|
SetupLdrLoadNlsData(LoaderBlock, InfHandle, FileName);
|
2009-03-15 10:46:41 +00:00
|
|
|
|
2009-03-16 20:56:07 +00:00
|
|
|
/* Get a list of boot drivers */
|
2011-10-03 08:32:07 +00:00
|
|
|
SetupLdrScanBootDrivers(&LoaderBlock->BootDriverListHead, InfHandle, BootPath);
|
2009-03-16 20:56:07 +00:00
|
|
|
|
2012-12-09 15:01:51 +00:00
|
|
|
/* Load ReactOS */
|
2011-08-31 13:47:25 +00:00
|
|
|
LoadAndBootWindowsCommon(_WIN32_WINNT_WS03,
|
|
|
|
LoaderBlock,
|
|
|
|
BootOptions,
|
|
|
|
BootPath,
|
2012-12-13 00:15:19 +00:00
|
|
|
TRUE);
|
2009-03-15 10:46:41 +00:00
|
|
|
}
|