4 * Copyright (C) 2009 Aleksey Bragin <aleksey@reactos.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include <ndk/ldrtypes.h>
24 #include <arc/setupblk.h>
28 DBG_DEFAULT_CHANNEL(WINDOWS
);
31 WinLdrSetupMachineDependent(PLOADER_PARAMETER_BLOCK LoaderBlock
);
34 WinLdrSetProcessorContext(void);
37 VOID
AllocateAndInitLPB(PLOADER_PARAMETER_BLOCK
*OutLoaderBlock
);
40 SetupLdrLoadNlsData(PLOADER_PARAMETER_BLOCK LoaderBlock
, HINF InfHandle
, LPCSTR SearchPath
)
42 INFCONTEXT InfContext
;
44 LPCSTR AnsiName
, OemName
, LangName
;
46 /* Get ANSI codepage file */
47 if (!InfFindFirstLine(InfHandle
, "NLS", "AnsiCodepage", &InfContext
))
49 ERR("Failed to find 'NLS/AnsiCodepage'\n");
52 if (!InfGetDataField(&InfContext
, 1, &AnsiName
))
54 ERR("Failed to get load options\n");
58 /* Get OEM codepage file */
59 if (!InfFindFirstLine(InfHandle
, "NLS", "OemCodepage", &InfContext
))
61 ERR("Failed to find 'NLS/AnsiCodepage'\n");
64 if (!InfGetDataField(&InfContext
, 1, &OemName
))
66 ERR("Failed to get load options\n");
70 if (!InfFindFirstLine(InfHandle
, "NLS", "UnicodeCasetable", &InfContext
))
72 ERR("Failed to find 'NLS/AnsiCodepage'\n");
75 if (!InfGetDataField(&InfContext
, 1, &LangName
))
77 ERR("Failed to get load options\n");
81 Status
= WinLdrLoadNLSData(LoaderBlock
, SearchPath
, AnsiName
, OemName
, LangName
);
82 TRACE("NLS data loaded with status %d\n", Status
);
86 SetupLdrScanBootDrivers(PLIST_ENTRY BootDriverListHead
, HINF InfHandle
, LPCSTR SearchPath
)
88 INFCONTEXT InfContext
, dirContext
;
90 LPCSTR Media
, DriverName
, dirIndex
, ImagePath
;
91 WCHAR ServiceName
[256];
92 WCHAR ImagePathW
[256];
94 /* Open inf section */
95 if (!InfFindFirstLine(InfHandle
, "SourceDisksFiles", NULL
, &InfContext
))
98 /* Load all listed boot drivers */
101 if (InfGetDataField(&InfContext
, 7, &Media
) &&
102 InfGetDataField(&InfContext
, 0, &DriverName
) &&
103 InfGetDataField(&InfContext
, 13, &dirIndex
))
105 if ((strcmp(Media
, "x") == 0) &&
106 InfFindFirstLine(InfHandle
, "Directories", dirIndex
, &dirContext
) &&
107 InfGetDataField(&dirContext
, 1, &ImagePath
))
109 /* Convert name to widechar */
110 swprintf(ServiceName
, L
"%S", DriverName
);
112 /* Prepare image path */
113 swprintf(ImagePathW
, L
"%S", ImagePath
);
114 wcscat(ImagePathW
, L
"\\");
115 wcscat(ImagePathW
, ServiceName
);
117 /* Remove .sys extension */
118 ServiceName
[wcslen(ServiceName
) - 4] = 0;
120 /* Add it to the list */
121 Status
= WinLdrAddDriverToList(BootDriverListHead
,
122 L
"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\",
128 ERR("could not add boot driver %s, %s\n", SearchPath
, DriverName
);
133 } while (InfFindNextLine(&InfContext
, &InfContext
));
136 VOID
LoadReactOSSetup(VOID
)
140 LPCSTR LoadOptions
, BootOptions
;
141 BOOLEAN BootFromFloppy
;
144 INFCONTEXT InfContext
;
145 PLOADER_PARAMETER_BLOCK LoaderBlock
;
146 PSETUP_LOADER_BLOCK SetupBlock
;
148 LPCSTR SourcePaths
[] =
150 "\\", /* Only for floppy boot */
153 #elif defined(_M_MPPC)
155 #elif defined(_M_MRX000)
163 MachDiskGetBootPath(BootPath
, sizeof(BootPath
));
165 /* And check if we booted from floppy */
166 BootFromFloppy
= strstr(BootPath
, "fdisk") != NULL
;
168 /* Open 'txtsetup.sif' from any of source paths */
169 for (i
= BootFromFloppy
? 0 : 1; ; i
++)
171 SystemPath
= SourcePaths
[i
];
174 ERR("Failed to open txtsetup.sif\n");
177 sprintf(FileName
, "%stxtsetup.sif", SystemPath
);
178 if (InfOpenFile (&InfHandle
, FileName
, &ErrorLine
))
180 strcat(BootPath
, SystemPath
);
185 TRACE("BootPath: '%s', SystemPath: '%s'\n", BootPath
, SystemPath
);
187 /* Get Load options - debug and non-debug */
188 if (!InfFindFirstLine(InfHandle
, "SetupData", "OsLoadOptions", &InfContext
))
190 ERR("Failed to find 'SetupData/OsLoadOptions'\n");
194 if (!InfGetDataField (&InfContext
, 1, &LoadOptions
))
196 ERR("Failed to get load options\n");
200 BootOptions
= LoadOptions
;
203 /* Get debug load options and use them */
204 if (InfFindFirstLine(InfHandle
, "SetupData", "DbgOsLoadOptions", &InfContext
))
206 if (InfGetDataField(&InfContext
, 1, &LoadOptions
))
207 BootOptions
= LoadOptions
;
211 TRACE("BootOptions: '%s'\n", BootOptions
);
214 UiDrawStatusText("Setup is loading...");
216 /* Allocate and minimalistic-initialize LPB */
217 AllocateAndInitLPB(&LoaderBlock
);
219 /* Allocate and initialize setup loader block */
220 SetupBlock
= &WinLdrSystemBlock
->SetupBlock
;
221 LoaderBlock
->SetupLdrBlock
= SetupBlock
;
223 /* Set textmode setup flag */
224 SetupBlock
->Flags
= SETUPLDR_TEXT_MODE
;
226 /* Load NLS data, they are in system32 */
227 strcpy(FileName
, BootPath
);
228 strcat(FileName
, "system32\\");
229 SetupLdrLoadNlsData(LoaderBlock
, InfHandle
, FileName
);
231 /* Get a list of boot drivers */
232 SetupLdrScanBootDrivers(&LoaderBlock
->BootDriverListHead
, InfHandle
, BootPath
);
235 LoadAndBootWindowsCommon(_WIN32_WINNT_WS03
,