Commit graph

80 commits

Author SHA1 Message Date
Mark Harmstone dd6c1c8843 [FREELDR] Allow Freeloader to boot Vista revamp of PR #1905 (#6479)
[FREELDR] Add "WindowsVista" boot type
[FREELDR] Set GDT correctly for Vista
[FREELDR] Map first page of memory, this is an observed behavior, and
also increases stability boot Checked windows 2003 SP2 ntoskrnl with
freeloader.
[SDK] Don't assert on big keys in bootloader

Co-authored-by: Justin Miller <justin.miller@reactos.org>
2024-04-18 09:28:54 -07:00
Adam Słaboń fec827eeef
[FREELDR][NTOS:MM] Add security cookie generation to FreeLoader (#6270)
* [NTOS:MM] Misc improvements for cookie generation code

- Improve support for 64 bit images
- Improve LdrpFetchAddressOfSecurityCookie code

* [FREELDR] Add security cookie generation to FreeLoader

CORE-17808
2024-03-27 23:33:06 +02:00
Hermès Bélusca-Maïto dad056e06a
[FREELDR] Move the arch-specific intrin_i.h inclusions to where they are actually needed (NTLDR) 2024-03-11 22:37:37 +01:00
Justin Miller 516ccad340
[NTOS:KE][HALX86] Implement AP startup code (#5879)
Co-authored-by: Victor Perevertkin <victor.perevertkin@reactos.org>

Introduce the initial changes needed to get other processors up and into kernel mode. 
This only supports x86 as of now but is the first real step towards using other system processors.
2023-11-19 15:51:33 -08:00
George Bișoc fa80176a62
[FREELDR][HACK] Temporarily disable registry recovery code for AMD64
The newly implemented code for registry recovery makes the FreeLdr binary to grow
in size, to the point that it would BSOD because the PE image is too big.

For now we have to temporarily disable any of the newly added code, until
either FreeLdr is split into a basic PE bootloader image itself and a
"FreeLdrlib" that is used by the PE image to access various bootloader APIs
or another proper solution is found.
2023-11-19 20:44:28 +01:00
George Bișoc 7983b65e10
[FREELDR] Implement SYSTEM hive recovery at bootloader level & use CmCheckRegistry for registry validation
Validate the SYSTEM hive with CmCheckRegistry and purge volatile data with the same function when initializing a hive descriptor for SYSTEM.
Also implement SYSTEM recovery code that takes use of SYSTEM log in case something is fishy with the hive. If hive repair doesn't have fully recovered the SYSTEM hive, FreeLdr will load the alternate variant of the SYSTEM hive, aka SYSTEM.ALT.

If FreeLdr repairs the hive with a LOG, it will mark it with HBOOT_BOOT_RECOVERED_BY_HIVE_LOG on BootRecover field of the header. All the recovered data that is present as dirty in memory will have to be flushed by the kernel once it is in charge of the system.
Otherwise if the system boot occurred by loading SYSTEM.ALT instead, FreeLdr will mark HBOOT_BOOT_RECOVERED_BY_ALTERNATE_HIVE, the kernel will start recovering the main hive as soon as it does any I/O activity into it.
2023-11-19 20:44:28 +01:00
Hermès Bélusca-Maïto 10e7643c80
[FREELDR:NTLDR] Pass boot-time detection options to HwDetect routines.
Will be used for supporting /NOSERIALMICE, /FASTDETECT (NT 5+) switches
(see PR #5886), as well as the undocumented /PCIENUM option.
2023-11-13 19:19:40 +01:00
Serge Gautherie 57d7f6f6b3
[FREELDR:NTLDR] Add '\n' to debug logs (#4474) 2022-04-29 18:20:36 +03:00
Hermès Bélusca-Maïto 8ed7d4b341
[SDK:CMLIB][FREELDR:NTLDR] Revert commit 168fea0ee and provide a better fix. Addendum to 93d8a1b7b.
Correct fix was to fix the HCELL_INDEX <-> HKEY conversions, much like
is being done with UlongToHandle / HandleToUlong.

The on-disk/in-memory hive file structures are platform-independent:
their layout must not depend on whether code is compiled in 32 or 64
bits.
2022-04-17 16:46:47 +02:00
Hermès Bélusca-Maïto 736331973e
[FREELDR:NTLDR] Rewrite RegInitCurrentControlSet() using CmpFindControlSet().
Also remove useless "success" traces at the end of some registry functions.
(Only show when they enter and when they fail.)
2022-04-17 04:57:43 +02:00
Hermès Bélusca-Maïto 94874baf19
[FREELDR:NTLDR] Use NTOS kernel's CMBOOT functions to enumerate and build the boot-time driver list.
They are correct and are more performant.

- Rewrite WinLdrAddDriverToList() on the model of CmpAddDriverToList()
  with support for CmpIsDriverInList().

- Disable RegEnumKey() as it is now unused.
2022-04-17 04:57:42 +02:00
Hermès Bélusca-Maïto 93d8a1b7b1
[FREELDR:NTLDR] Adapt the registry code to access from outside the underlying HHIVE and HCELL_INDEX (needed for cmboot). 2022-04-17 04:57:40 +02:00
Hermès Bélusca-Maïto f10437b1e2
[FREELDR:NTLDR] Expose and use the CurrentControlSetKey handle.
This allows: (i) to shorten dramatically the lengths of the static
registry path strings being used (and thus, allow for reduced binary
file size), and (ii) to prepare future support for selecting different
control sets (and related Last-Known-Good configurations).
2022-04-07 03:19:11 +02:00
Hermès Bélusca-Maïto 57b9c6b2f2
[FREELDR:NTLDR] Improve NLS data loading.
- Use UNICODE_STRINGs wherever possible.
- Retrieve the OEMHAL font file name. TODO: Load it!

- In WinLdrLoadNLSData(), don't open/close each file twice (and showing
  we are loading them twice). Instead, open all files at once (and keep
  them that way), retrieve their sizes and do the calculations, then
  load their respective contents one by one -- giving loading feedback
  only at that point -- and finally close all of them at once.
2022-04-07 03:19:10 +02:00
Hermès Bélusca-Maïto eeb4cbcb6b
[FREELDR:INF] Change immutable input string pointers to PCSTR when it's possible. 2022-03-25 18:54:22 +01:00
Vadim Galyant d4a05ad7aa
[FREELDR:NTLDR] Stub out x86 PAE support in preparation for PR #4272.
- Move boot options parsing early on in LoadWindowsCore().

- Add WinLdrIsPaeSupported(), move in it the PAE options parsing.
  The aim is to perform other tests to determine whether or not to
  enable PAE, and select an adequate kernel image.

Co-authored-by: Vadim Galyant <vgal@rambler.ru>

- Fix parsing of the NOEXECUTE options, taking their precedence
  into account. Most of these are also x86-specific.
2022-03-20 04:12:58 +01:00
Hermès Bélusca-Maïto d535ecf1dc
[FREELDR] Use safe-string buffer printf to initialize the returned strings in WinLdrGetNLSNames().
This will also stop the GCC 9+ warnings, see PR #4385.
2022-03-19 16:56:13 +01:00
Hermès Bélusca-Maïto c322610f6e
[FREELDR] Improve progress bar support, adapted from Inbv.
- Improve accuracy/progression smoothness when loading drivers.
- Allow changing text and percentage independently.
2022-02-21 02:53:54 +01:00
Hermès Bélusca-Maïto 81943afb7b
[FREELDR:NTLDR] Slightly rework how KD transport DLLs are loaded.
A Kernel Debugger Transport DLL is always loaded for Windows XP+ :
either the standard KDCOM.DLL (by default), or an alternative
user-provided one via the /DEBUGPORT= option. If this alternative
does not exist or fails to be loaded, fall back to the standard
KDCOM.DLL.

If no KD dll is loaded, kernel loading would fail because of the
resulting unsatisfied KDCOM dll import (tested on Windows and ReactOS).

+ Normalize kernel, HAL and KD dll file names to lowercase (needed for
  case-sensitive installations).
2022-02-18 20:24:51 +01:00
Hermès Bélusca-Maïto 2221df213f
[FREELDR] Add cleanup in PE-image-handling-related failure code paths. 2022-02-18 20:24:49 +01:00
Hermès Bélusca-Maïto 15e1489c7f
[FREELDR:NTLDR] Add some error handling for LoadModule().
Based on PR #4294 by Serge Gautherie.

Co-authored-by: Serge Gautherie <reactos-git_serge_171003@gautherie.fr>
2022-02-18 20:24:48 +01:00
Hermès Bélusca-Maïto 1a920d9a7e
[FREELDR:NTLDR] Shorten KdTransportDllName --> KdDllName. 2022-02-18 20:24:47 +01:00
Hermès Bélusca-Maïto 914f14a8b9
[FREELDR:NTLDR] Adjust some debug traces. RegOpenKey(): demote an ERR to WARN.
CORE-18040
2022-02-07 00:26:30 +01:00
Hermès Bélusca-Maïto f6a13d452c
[FREELDR:NTLDR] Implement support for the SOS option.
CORE-9023, CORE-18033

- Reset the UI to a minimal one in SOS mode.

- In SOS mode, a trace of loaded files is displayed on the screen,
  instead of the usual progress bar.

- Add a callback to the PE loader to notify when imported DLLs are
  loaded for a main image. This allows getting an accurate SOS trace.
2022-02-06 23:53:41 +01:00
Hermès Bélusca-Maïto e2daca3f60
[FREELDR:UI] Improve drawing of progress bars, reducing flickering.
- Remove excessive UiDrawBackdrop() calls that caused too many
  unnecessary redraws.

- ProgressBar: Clear only the portions that need to be cleared up.
  This allows to not use DrawBackdrop anymore and the flickering.
2022-02-06 17:52:46 +01:00
Hermès Bélusca-Maïto 2b31977838
[FREELDR] Add RegCloseKey() and use it where registry keys need to be closed.
Actually, RegCloseKey() is here a dummy macro that just "returns"
success. Indeed, the internal implementation of RegOpenKey() doesn't
really allocate internal structures: it just returns a "pointer" to
already existing allocated data. Therefore nothing needs to be closed/freed
later on.
2021-11-19 03:55:21 +01:00
Serge Gautherie c5e5e3117c
[FREELDR] Diverse improvements and fixes for CORE-12802. (#3466)
- Move a few lines around.
- Switch to RtlZeroMemory() from memset().
- Make while() more explicit.

For CORE-12802:
- Add/Fix FrLdrHeapAlloc() failure handling and related.
  Especially, add/fix FrLdrHeapFree() calls.

- Add/Improve ERR() to some FrLdrHeapAlloc() failure cases.

Co-authored-by: Hermès BÉLUSCA - MAÏTO <hermes.belusca-maito@reactos.org>
2021-11-19 01:49:55 +01:00
Hermès Bélusca-Maïto 9b1edceae1
[REACTOS] Fix some instances of DPRINTs with trailing whitespace before newlines. 2021-09-13 03:52:19 +02:00
Serge Gautherie 25e1235fe7
[FREELDR] Remove a few useless code lines (#3503)
CORE-14516
2021-03-09 16:02:11 +01:00
Serge Gautherie abc84a742b [FREELDR] LoadAndBootWindowsCommon(): Use UNREACHABLE, on success
KiSystemStartup() is DECLSPEC_NORETURN.
2021-03-05 00:43:15 +03:00
Hermès Bélusca-Maïto 5dd0b32799
[FREELDR] EMS boot options: Parse NT kernel load options in a consistent manner. Addendum to d887308b.
In particular the parsing should not care about the letter case.
2020-12-27 00:51:57 +01:00
Hermès Bélusca-Maïto 4792c007aa
[FREELDR] Add the possibility to change the boot load options from TXTSETUP.SIF
at runtime from the boot selection menu or from FREELDR.INI.

CORE-17350, CORE-9023

For a proper override of the options by new user options, specify the
/SIFOPTIONSOVERRIDE switch in addition. Otherwise, user options are
merged with those retrieved from TXTSETUP.SIF, with priority given to
the former ones.

- Update the documentation for the 'ReactOSSetup' OS type in the
  FREELDR.INI file template.

- Use a different prompt in the custom boot options editor for the
  'ReactOSSetup' OS type, with adequate explanation.

- Get rid of the ReactOS-specific TXTSETUP.SIF 'DbgOsLoadOptions' value,
  and use instead the Windows-compatible 'SetupDebugOptions' value that
  is added to the other load options when debugging is to be enabled.
2020-11-04 19:59:28 +01:00
Hermès Bélusca-Maïto d45b268127
[FREELDR] Fix x64 compilation warning (addendum to commit d887308b). 2020-11-04 19:59:27 +01:00
Hermès Bélusca-Maïto d887308b2f
[FREELDR] Parse NT kernel load options in a consistent manner.
- Introduce a set of NtLdrGet(Next)Option(Ex) helpers that allow
  retrieving respectively, the "next" option in an options string,
  and retrieving a given named option in such an options string,
  by correctly parsing that string.

  Valid syntaxes:
      /OPTION1 /OPTION2/OPTION3 OPTION4 /OPTION5(=...) ...

  Options separators are slashes, or whitespace (space, tab), mandatory
  if no slash is used, and otherwise optional.

- Use these functions wherever NT load options are being parsed.

- Simplify the parsing of /DEBUGPORT=... using these functions.

- When parsing the /HAL=... or /KERNEL=... options, only the first
  encountered one is taken into account, any other ones are discarded.

- When parsing the other load options, only their first occurrences are
  taken into account, any other repetitions are discarded.
  * The NOPAE option overrides any previous PAE option.
  * Any NOEXECUTE(=) option should override any previous
    NOEXECUTE=ALWAYSOFF (or equivalently, EXECUTE) option.
2020-11-03 01:52:47 +01:00
Hermès Bélusca-Maïto d8547a8f20
[FREELDR] In LoadReactOSSetup(), verify that our BootType is really ReactOSSetup. 2020-11-03 01:52:47 +01:00
Hermès Bélusca-Maïto 3033580c1a
[FREELDR] Minor code formatting / renaming some variables. 2020-11-03 01:52:46 +01:00
Hermès Bélusca-Maïto 04b4e3b05d
[FREELDR] Fix the parameter type of WinLdrSetupEms()
It's a NULL-terminated string. And thus avoid an unelegant cast.
2020-11-03 01:52:36 +01:00
Hermès Bélusca-Maïto 58866a112a
[FREELDR] Remove the 'Setup' parameter of the LoadAndBootWindowsCommon() function.
This parameter is not needed since it's possible to determine, from
within this function, whether or not we are in Setup mode, by just
looking for the presence of a non NULL LoaderBlock->SetupLdrBlock.
2020-11-03 01:51:48 +01:00
Hermès Bélusca-Maïto 64ca7f6427
[FREELDR] Remove trailing whitespace. 2020-11-03 01:51:47 +01:00
Thomas Faber 794d00c303
[FREELDR][NETKVM][ATL_APITEST] Pick the GCC code path for clang in some cases. CORE-17202 2020-08-23 12:07:37 +02:00
Dmitry Borisov 4501bbac8f
[KDCOM][NTOS:INBV][FREELDR] Decrease default baud rate for PC-98 target (#2601)
According to PC-9801 Bible p. 50, divisor for PIT will become unsupported in some cases after having removed the fractional part. Replace 19200 value with 9600 which is supported by both 10 MHz and 8 MHz machines.
2020-04-21 23:22:42 +03:00
Vadim Galyant 305e856ef8
[FREELDR] Add parsing boot options from .ini files. (#2511)
Co-Authored-By: Stanislav Motylkov <x86corez@gmail.com>
2020-04-09 16:25:25 +02:00
Dmitry Borisov 222e79232c
[CPORTLIB][NTOS:INBV][KDCOM][FREELDR] Add ComPort library for NEC PC-98 series (#2407)
There are 2 known serial ports:
    COM1 - based on Intel 8251A
    COM2 - National Semiconductor 16550
2020-03-06 19:50:31 +01:00
Hervé Poussineau 46fdc89e4f [FREELDR] Comment out useless variable 2020-01-22 20:56:51 +01:00
Hermès Bélusca-Maïto 3c9e562bd3
[FREELDR] Fix build with the 'Grossly Crying Compiler' (aka. GCC). 2019-10-13 21:07:23 +02:00
Hermès Bélusca-Maïto c85ef31f6a
[FREELDR] Improvements for GDT descriptors initialization.
Triggered by a fix attempt by M.Harmstone in PR #1905.

- Introduce #defines and helper functions so as to initialize the
  descriptors in a human-readable and tractable way, without magic values.

- Rework some comments.

- Document what the changes are in (Longhorn and) Vista+.

Data has been obtained through using the WinDbg command: dg 0x00 0xFF
(for example), that lists all the selectors from 0x00 to 0xFF included.
See https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/dg--display-selector-
for more details.
2019-10-13 19:57:54 +02:00
Hermès Bélusca-Maïto db15c921e8
[FREELDR] Improvements for the RamDisk support.
- Implement support for the "RDIMAGELENGTH" and "RDIMAGEOFFSET" boot
  options. Fixes CORE-15432.

- Separate the initialization of the global gInitRamDiskBase /
  gInitRamDiskSize variables from the FreeLdr command-line, and the
  actual initialization of the internal variables of the RamDisk.
  The latter are initialized via calls to RamDiskInitialize().

- Implement 'SeekRelative' mode in RamDiskSeek().

- Make RamDiskLoadVirtualFile() internal function that gets called by
  RamDiskInitialize(), and we use the latter in the NT loader instead.
2019-10-09 03:26:41 +02:00
Hermès Bélusca-Maïto 2d1a6b2db9
[FREELDR] NT loader: Allocate the Loader Block Extension much earlier in the process. 2019-10-06 18:24:48 +02:00
Hermès Bélusca-Maïto eeeca29c6c
[FREELDR] INFFILE Parser: Fix while-loop conditions, this bug existed for 16+ years (commit 939d5316, revision 4758). 2019-10-06 18:18:34 +02:00
Mark Harmstone f551caa840
[FREELDR] Load the Firmware Errata file specified in the registry. (#1951)
On Windows <= 2003 (and current ReactOS), this is the "InfName" value
in the "HKEY_LOCAL_MACHINE\CurrentControlSet\Control\BiosInfo\" key.
(The default file name found there is 'biosinfo.inf'.)

On Vista+, this is the "InfName" value in the
"HKEY_LOCAL_MACHINE\CurrentControlSet\Control\Errata\" key.
(The default file name found there is 'errata.inf'.)

For 1st-stage setup, the file is specified in the "InfName" value of
the "BiosInfo" section in the TXTSETUP.SIF file.

Co-authored-by: Hermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
2019-10-05 23:20:53 +02:00