Commit graph

419 commits

Author SHA1 Message Date
Hermès Bélusca-Maïto
a3899d8151
[FREELDR:PC98] Don't do the HighRes check everytime a character is written with writechr (#4359)
And bring similar simplifications to the PC98 FAT12 bootsector.

Co-authored-by: Dmitry Borisov <di.sean@protonmail.com>
2025-04-08 15:50:43 +02:00
Adam Słaboń
d66ad21ee0
[FREELDR][INSTALL] Update the FreeLoader installation message (#7853)
Update the installfreeldr message in accordance with the changes in 3d516e71d3.
2025-04-02 00:06:12 +03:00
Justin Miller
177cbd81af Revert "[FREELDR] Pass the correct ACPI table for Windows (#7486)"
Sorry this is something I had to do, I should have investigated deeper
before approving it and that's on me so ill take this over and get this
done. and credit you once again. Thank you @ILauncherDev
This reverts commit 185225a5fc.
2025-03-28 07:20:45 +01:00
Daniel Victor
185225a5fc
[FREELDR] Pass the correct ACPI table for Windows (#7486)
JIRA issue: CORE-11954 and CORE-18969

This PR passes the real ACPI table instead of a hardcoded (PVOID)1.
2025-03-24 21:49:39 +01:00
Serge Gautherie
9ecd5fb6fe
[FREELDR] DisplayBootTimeOptions(): Simplify concatenation checks (#4058) 2025-03-24 20:14:04 +01:00
Dmitry Borisov
5fb6fad175
[FREELDR] iso.c: Remember the last directory that was accessed (#7734)
This patch reduces the number of sectors read by 709 (from 8788 to 8079)
2025-03-21 22:17:29 +01:00
Dmitry Borisov
564be44f45
[FREELDR] iso.c: Remove a redundant zero initialization of the FileName buffer (#7734)
The FileName buffer is NUL-terminated later on.
2025-03-21 22:17:11 +01:00
Dmitry Borisov
b931c51937
[FREELDR] iso.c: Avoid unnecessary zero-init and copy of the file info structure (#7734)
FileHandle gets initialized completely in IsoSearchDirectoryBufferForFile()

- Also mark some functions as static.
2025-03-21 22:15:54 +01:00
Dmitry Borisov
61ee431169
[FREELDR] iso.c: Cache the PVD information for ISO volumes (#7734)
This patch reduces the number of sectors read by 41 (from 8829 to 8788)
2025-03-21 22:15:43 +01:00
Daniel Victor
19c1f5661f
[BOOTSECT][FREELDR] Fix wrong comment of conditional jump on ext.S and extldr.S (#7798) 2025-03-18 23:52:56 +01:00
Dmitry Borisov
787f81f3f5
[FREELDR] Refactor and optimize the IDE driver (#7728)
[DDK] Update IDENTIFY data and other ATA definitions.
Based on the MinGW header.

[FREELDR] Refactor and optimize the IDE driver.
Fix long-standing bugs, which have a negative impact on the boot stability.

- Make the driver more ATA specification compliant.
- Improve the speed of device detection.
- Remove inconsistent delays.
- Support modern hard drives with sector size greater than 512 bytes.
- Add basic error recovery.
- Move private definitions to a separate private header.
- Remove the useless AtaFree API method.
2025-03-18 21:56:25 +01:00
Daniel Victor
ddf55b3772
[BOOTSECT][FREELDR] Rewrite the Ext bootsector (#7544)
Rewrite the Ext bootsector because the older one was broken and had no compatibility with Ext4 extents.
Introduce a 3rd-stage bootsector for complex code.

CORE-14235

- Why was the previous bootsector broken?
  Because of hardcoded inode size, hardcoded freeldr base address, etc.

- Why is there a extldr.sys?
  The extldr.sys was introduced because the limited code space in the bootsector
  prevents adding new features, such as Ext4 full extents support.

- What is extldr.sys and What does it do?
  It is the helper file for the Ext bootsector and that is necessary for adding
  Ext4 support. It locates the freeldr.sys file, loads it into memory and runs it.
2025-03-18 21:53:47 +01:00
Timo Kreuzer
9a093ecbe9 [FREELDR] Fix menu display on VMware
When drawing the menu, the boot options should not be overwritten, but when clearing the screen, everything needs to be drawn, otherwise there will be uninitialized characters at the bottom. See CORE-20014.
2025-03-18 00:36:40 +02:00
Dmitry Borisov
029e53ddb5
[MINIHAL] Minor improvements (#7398)
* [FREELDR] Mark noreturn functions

* [FREELDR] Compile hw debugging support code only in debug builds

- Make BREAKPOINT() portable

* [FREELDR] Consolidate identical names into a single string

* [FREELDR] Use intrinsics for string I/O operations on x86 and x64

Stop them being pulled in from a static minihal library

* [MINIHAL] Exclude unnecessary portio dependency
2025-03-11 10:30:14 +03:00
Daniel Victor
afb96acfdd [FREELDR] Use the OFF(x) macro on realmode assembly files 2025-03-02 19:09:46 +01:00
Daniel Victor
56c8c8ab4f [FREELDR] Add Extents support 2025-02-20 19:28:41 +02:00
Daniel Victor
a980ad08b4 [FREELDR] Rewrite the header and reformat/adapt current code 2025-02-20 19:28:41 +02:00
Daniel Victor
1f3083be75 [FREELDR] Rename almost everything to Ext 2025-02-20 19:28:41 +02:00
Daniel Victor
d0dfb6cf6f [FREELDR] Rename the ext2.* to ext.* 2025-02-20 19:28:41 +02:00
Timo Kreuzer
a1a169fbe8 [FREELDR] Fix pc98 build 2025-02-04 16:45:48 +02:00
Timo Kreuzer
2b71c738b8 [ROSLOAD] Enable registry healing code for x64 2025-02-04 16:45:48 +02:00
Timo Kreuzer
e56911f66b [FREELDR] Implement loading of rosload as 2nd stage loader 2025-02-04 16:45:48 +02:00
Timo Kreuzer
adacd51a30 [FREELDR] Use StallExecutionProcessor instead of KeStallExecutionProcessor
The latter will only be available in rosload.exe.
2025-02-04 16:45:48 +02:00
Timo Kreuzer
17cf47df44 [ROSLOAD] Add rosload.exe target as 2nd stage loader 2025-02-04 16:45:48 +02:00
Timo Kreuzer
ebcf3f23aa [FREELDR] Remove ShowBootOptions from Menu code
This removes a dependency of UI code to boot options code by getting rid of a call to DisplayBootTimeOptions() from within the menu code.
Instead this is now handled by MainBootMenuKeyPressFilter.
2025-02-04 16:45:48 +02:00
Timo Kreuzer
9daef292e9 [FREELDR] Move MachInitializeBootDevices to BootMain 2025-02-04 16:45:48 +02:00
Timo Kreuzer
f81c1910ee [FREELDR] Export functions for a 2nd stage loader 2025-02-04 16:45:48 +02:00
Timo Kreuzer
2f9dde09e1 [FREELDR] Replace some macros/inline functions and global variables with functions
This allows to easily import them from a 2nd stage loader without having to bother about _declspec(dllimport)
2025-02-04 16:45:48 +02:00
Katayama Hirofumi MZ
fe11f7a2e5
[REACTOS] Refresh old URLs (#7632)
URLs are getting old. We have to
update URLs for documentation
purpose.
JIRA issue: CORE-19963
- Refresh old URLs.
- Add " (DEAD_LINK)" labels
  to dead links.
- Use MS Learn links rather
  than MSDN ones.
- Some dead links revived by
  Web Archive.
- Don't change Wine Tests
  and Wine Sync.
- Don't change 3rd party libraries.
- Don't append "redirected" labels.
2025-01-28 13:36:45 +09:00
Daniel Victor
d72864de95 [FREELDR] Fix wrong segment register at lgdt instruction in amd64.S 2025-01-20 08:34:44 +02:00
Hermès Bélusca-Maïto
ba342e1d14
[FREELDR] peloader.c: Minor code enhancements.
PeLdrCheckForLoadedDll():
- Use a for-loop to iterate over the linked list.
- Adjust few comments.
- Use SAL2 annotations.

PeLdrpCompareDllName():
- Make its input paramters const.
- Use SAL2 annotations.
2024-12-14 23:31:41 +01:00
Daniel Victor
34e76ade03 [FREELDR] Make it more compatible with w2k3 ini file 2024-12-11 07:18:34 +02:00
Andrei Miloiu
6ec5f8841b
[FDEBUG] Update Romanian (ro-RO) translation (#7340) 2024-12-06 20:48:33 +01:00
Hermès Bélusca-Maïto
dfb43905bb
[FREELDR] peloader.c: Fix PE import binding (#7537)
Use the PE import table's OriginalFirstThunk array when scanning and
resolving imports during DLL binding.

It points to an array of pointer-sized IMAGE_THUNK_DATA structures
which describe the functions being imported. On the other hand, the
FirstThunk points to an array of pointers, whose initial values are
a copy of those pointed to by OriginalFirstThunk, but are replaced
by the actual function pointers determined at runtime, when a DLL
is loaded (see PeLdrpBindImportName() function).
If we were to use the FirstThunk array to find again later the imports
by name or ordinal, we would fail because these are replaced by the
addresses of the corresponding functions.

This fixes loading kdcom.dll from Windows XP x64 with FreeLDR when
testing on ReactOS x64.

```diff
 (freeldr\freeldr\lib\peloader.c:498) trace: PeLdrpScanImportAddressTable() ---- Calling PeLdrpBindImportName() in a loop
 (freeldr\freeldr\lib\peloader.c:501) trace: *** ThunkName->u1.AddressOfData = 00000000000070F0
 (freeldr\freeldr\lib\peloader.c:502) trace: *** ThunkData->u1.AddressOfData = 0000000000573780
 (freeldr\freeldr\lib\peloader.c:209) trace:   !!! ExportDirectory->NumberOfNames 1504
-(freeldr\freeldr\lib\peloader.c:210) trace:   !!! ImportHint 0 - ExportName 'CcCanIWrite' - ImportDataName ''
+(freeldr\freeldr\lib\peloader.c:210) trace:   !!! ImportHint 282 - ExportName 'HalPrivateDispatchTable' - ImportDataName 'HalPrivateDispatchTable'
 ....
-(freeldr\freeldr\lib\peloader.c:268) err: Did not find export ''!
-(freeldr\freeldr\lib\peloader.c:709) err: PeLdrpScanImportAddressTable() failed: ImportName = 'ntoskrnl.exe', DirectoryPath = 'multi(0)disk(0)rdisk(0)partition(2)\ReactOS\system32\'
```
('-': lines before the fix; '+': lines after the fix)

Code has been adapted based from the following functions:
ntdll/ldr/ldrpe.c!LdrpSnapThunk() and LdrpSnapIAT()
ntoskrnl/mm/ARM3/sysldr.c!MiSnapThunk() and MiResolveImageReferences()

References:
https://devblogs.microsoft.com/oldnewthing/20231129-00/?p=109077
https://devblogs.microsoft.com/oldnewthing/20231130-00/?p=109084
https://stackoverflow.com/questions/42413937/why-pe-need-original-first-thunkoft
2024-12-03 13:13:38 +01:00
Hermès Bélusca-Maïto
576fafbaf8
[FREELDR] peloader.c: Add SAL2 annotations for two import-resolving helpers (#7537)
Add annotations for PeLdrpBindImportName()
and PeLdrpScanImportAddressTable().
2024-12-03 13:13:26 +01:00
Hermès Bélusca-Maïto
ddd59f19ae
[FREELDR] peloader.c: Fix some traces 2024-12-03 12:32:08 +01:00
Timo Kreuzer
9b8c59d6b7 [FREELDR] Refactor LoadBootDeviceDriver 2024-11-02 17:31:57 +02:00
Timo Kreuzer
393b1f8998 [FREELDR] Implement PeLdrLoadBootImage 2024-11-02 17:31:57 +02:00
Timo Kreuzer
f9849f7cc4 [FREELDR] Initialize a global module list head for freeldr 2024-11-02 17:31:57 +02:00
Timo Kreuzer
6eac9b5891 [FREELDR] Pass VA instead of PA to PeLdrAllocateDataTableEntry
This allows to create DTEs for loader modules.
2024-11-02 17:31:57 +02:00
Timo Kreuzer
8a5ef4c1cc [FREELDR] Implement PeLdrLoadImageEx
This allows to load an image as freeldr extension code.
TODO:
- Add global bootloader DTE list
- Add wrapper function that also processes imports
- Use this for scsiport
2024-11-02 17:31:57 +02:00
Timo Kreuzer
bee8e81d5a [FREELDR] Move IoReadPartitionTable to ntoskrnl.c 2024-11-02 17:31:57 +02:00
Timo Kreuzer
77ba2d496b [FREELDR] Fix some trace prints 2024-11-02 17:31:57 +02:00
Daniel Victor
3fd6e34ab8
[FREELDR/x64] Fix the Multiboot pointer size (#7469)
Addendum to b524c18a3e. CORE-18374
2024-10-19 18:50:41 +03:00
Daniel Victor
b524c18a3e [FREELDR/x64] Add Multiboot header 2024-10-19 17:54:39 +03:00
Timo Kreuzer
bed8b2a0a6 [FREELDR][NDK][X64] Remove KIP0PCRADDRESS definition and mapping
It is not used by either ReactOS or Windows.
2024-10-17 18:31:32 +03:00
Hermès Bélusca-Maïto
5d361b602d
[FREELDR] fs.c: Fix handling of file handles, (de)referencing, and direct-device access (#7414)
- The original code was just incrementing the reference counts (RefCounts)
  of the device objects or the device/file handles, without decrementing
  them when closing the handles. This is now fixed.

  Notice the following:

  * When opening a file on a device (disk), the device's (and its
    handle's) RefCount is incremented, and the file handle's RefCount
    is incremented as well.

  * When closing a file, the file handle's RefCount is decremented
    (and the file closed if the RefCount reaches zero), and the file's
    parent device handle is also closed, recursively.
    This has the effect of decrementing the parent device handle's
    RefCount, and the device's own RefCount is decremented as well.

  IMPORTANT NOTE: The usefulness of handle-level RefCount is still
  under question, and might be (consistently) removed in the future.

- Fix opening a device (disk) in direct access, when this device is
  already opened. Indeed, we previously allowed direct access only if
  the device was opened as such for the very first time (its RefCount
  = 0 originally); no filesystem mounting was attempted as well.
  Then for any later open-operations on this device (while keeping an
  already-opened handle to it), filesystem access was assumed.

  Thus, this problem would show up in two ways:

  * Either the device is first opened for direct access, this succeeded
    and no filesystem was mounted. Then, for any other open-operations,
    the filesystem was NOT mounted, and opening files on it would fail.
    Direct accesses would succeed but would create an unnecessary second
    file handle.

  * Or, the device is first opened for file-access: a filesystem was
    mounted and file opening would succeed. Any other file opening
    operation would succeed as well (if the file exists). But, a direct
    access open-operation would fail, because now any open-operations on
    the device would be assumed to be a file opening.

  This is now correctly fixed. If direct-open is requested, just do it.
  If this is a file opening, we open the device, then try to mount a
  filesystem on it (if not already done), then we try to open the file.

  If file opening fails, derereference the device.

- Pass the file path to the filesystem-specific Open() functions without
  truncating the leading path separator, if any. This has to be handled
  by the filesystem routines themselves.
2024-10-16 22:20:52 +02:00
Joachim Henze
798ea90784
[FREELDR] Less outdated version-hardcodes (#7384)
Those haven't been groomed anymore for more than 10 years. We had many thousands of
different freeldr builds with different behavior and bugs each, but nobody ever
did have the slightest motivation to update those hardcoded
FREELOADER_MAJOR_VERSION, FREELOADER_MINOR_VERSION, FREELOADER_PATCH_VERSION
from ver.h. And that is logical, because touching other modules will change the behavior
of freeldr as well, so it is absolutely impossible to groom anything like that correctly.
Instead we should simply do what we started to do in PR7383, which will at least give
some information (the actual sources it was built from) instead of some misleading voodoo-version.

This might slightly shrink the size of freeldr as well, but I was too lazy to measure by how much.
2024-10-13 19:23:38 +02:00
Timo Kreuzer
0c2cdcae83 [REACTOS] Add missing line breaks at end of file 2024-10-06 10:47:11 +03:00
Hermès Bélusca-Maïto
764881a94b
[FREELDR] Remove the "setupldr" build target (#7419)
The setupldr and freeldr binaries are the same since commit 948e82af1
(r65832), because both their functionality have been shared.
2024-10-03 12:32:45 +02:00