Commit graph

99 commits

Author SHA1 Message Date
Hermès Bélusca-Maïto ff85aa0c38
[FREELDR] Other enhancements.
- Modify DiskReportError() to use an internal "display counter", so that
  imbricated DiskReportError(FALSE) ... DiskReportError(TRUE) can behave
  as expected.
- Merge LoadAndBootDrive(), LoadAndBootPartition(),
  LoadAndBootBootSector() into one LoadAndBootDevice() function + its
  helpers (in progress...).
2019-09-18 00:27:53 +02:00
Hermès Bélusca-Maïto fc29a6c41c
[FREELDR] Minor code improvements + 1 bug-fix.
- "FrldrBootPath" -> "FrLdrBootPath";
- Get rid of GetFreeLoaderVersionString() and use FrLdrVersionString
  directly instead;
- Rephrase some comments;
- Use RTL_NUMBER_OF();
- Reduce indent level in LoadOperatingSystem() and EditOperatingSystemEntry().

Bug fix:
- Fix DissectArcPath() for "ramdisk(0)" case.
2019-09-17 23:24:51 +02:00
Hermès Bélusca-Maïto a9411fb658
[FREELDR] Minor code style - use RtlZeroMemory(); shorter member name; use different debug channel. 2019-09-13 15:18:28 +02:00
Hermès Bélusca-Maïto eeff926ede
[FREELDR] Limit the usage of DiskStopFloppyMotor() in hardware/platform-specific code.
- Move DiskStopFloppyMotor() calls into the implementations of
  Boot(New)LinuxKernel() and Reboot() HW functions, and the explanation
  comments in ChainLoadBiosBootSectorCode().

- Remove unneeded DiskStopFloppyMotor() dummies in ARM and PPC code.

- Use more adequate bitmask value to be sent to floppy's Digital Output
  Register for shutting down its motor (based on OSDev & our floppy
  controller driver).
2019-09-13 15:18:27 +02:00
Hermès Bélusca-Maïto 4843c1a954
[FREELDR] Other enhancements.
- Add optional arguments BootDrive and BootPartition to
  ChainLoadBiosBootSectorCode() so as not to modify explicitly the
  FrldrBootDrive and FrldrBootPartition variables, that should remain
  purely internal.

- Implement ChainLoadBiosBootSectorCode() for x64.

- Get rid of the machine-specific DiskGetBootPath(), and instead do its
  job only once in the machine-specific InitializeBootDevices() (or in
  MachInit() for PPC).
  Cache the result of this operation into the globally-accessible
  FrldrBootPath buffer. This avoids the unneeded calls to (Mach)DiskGetBootPath()
  we used to do before.
  Also remove the separate distinction between the PC and XBOX versions
  of this functionality.

- Move the PC-specific DiskIsDriveRemovable() and DiskGetBootPath()
  as well as the disk-IO-error functionality, back into the
  corresponding PC-arch files.

- Simplify IniFileInitialize(), getting rid of IniOpenIniFile().
2019-09-13 15:18:07 +02:00
Hermès Bélusca-Maïto bd451f240f
[FREELDR] Code fixes and enhancements.
CORE-9023

FIXES:
======

- Fix parsing of the multiboot options string.
  NOTE: They are not yet treated in a case-insensitive manner!

- Fix a bug in ArcOpen() so that it correctly skips the first path
  separator (after the adapter-controller-peripheral ARC descriptors).
  The path separator can be either a backslash or a slash (both are
  allowed according to the specs); they were also already handled
  correctly in other parts of the code.

- Fix DissectArcPath() so as to:
  * **OPTIONALLY** (and not mandatorily!) return the path part that follows
    the ARC adapter-controller-peripheral elements in the ARC path;

  * make it correctly handle the (yes, optional!!) partition() part in the
    ARC path, for the multi(x)disk(y)rdisk(z) cases.

ENHANCEMENTS:
=============

- Directly retrieve the default OS entry as we enumerate them and
  build their list (i.e. merge the GetDefaultOperatingSystem() helper
  within InitOperatingSystemList()).

- Directly use the opened 'FreeLoader' INI section via its ID in the
  different functions that need it.

- Make the custom-boot and linux loaders honour the boot options they are
  supposed to support (see FREELDR.INI documentation / template).
  This includes the 'BootDrive' and 'BootPartition' (alternatively the ARC
  'BootPath').
  This also allows them to take into account the user-specified choices in the
  FreeLdr custom-boot editors.

- Modify the FreeLdr custom-boot editors so as to correctly honour
  the  priorities of the boot options as specified in the FREELDR.INI
  documentation / template.

- Use stack trick (union of structs) to reduce stack usage in the
  FreeLdr custom-boot editors, because there are strings buffers that are
  used in an alternate manner.

- Extract out from the editors the LoadOperatingSystem() calls, and
  move it back into OptionMenuCustomBoot(), so that when this latter
  function is called there is no risk of having a stack almost full.

- When building the ARC-compatible argument vector for the loaders, add
  the mandatory "SystemPartition" path. This allows the loaders to NOT
  call the machine-specific MachDiskGetBootPath() later on (this data is
  indeed passed to them by the boot manager part of FreeLdr).

- Improve the FsOpenFile() helper so as to make it:
  * return an adequate ARC_STATUS instead of a mere uninformative BOOLEAN;
  * take open options, as well as a default path (optional) that would be
    prepended to the file name in case the latter is a relative one.

- Make RamDiskLoadVirtualFile() return an actual descriptive ARC_STATUS
  value, and make it take an optional default path (same usage as the one
  in FsOpenFile() ).
  + Remove useless NTAPI .

- UiInitialize() and TuiTextToColor(), TuiTextToFillStyle(): load or
  convert named settings into corresponding values using setting table and
  a tight for-loop, instead of duplicating 10x the same parameter reading
  logic.

- UiInitialize(): Open the "Display" INI section just once. Remove usage
  of DisplayModeText[] buffer.

- UiShowMessageBoxesInSection() and UiShowMessageBoxesInArgv(): reduce
  code indentation level.

ENHANCEMENTS for NT OS loader:
==============================

- Don't use MachDiskGetBootPath() but use instead the "SystemPartition"
  value passed via the ARC argument vector by the boot manager
  (+ validation checks). Use it as the "default path" when calling
  FsOpenFile() or loading the ramdisk.

- Honour the FreeLdr-specific "Hal=" and "Kernel=" options by converting
  them into NT standard "/HAL=" and "/KERNEL=" options in the boot
  command line.

  Note that if the latter ones are already present on the standard "Options="
  option line, they would take precedence over those passed via the separate
  "Hal=" and "Kernel=" FreeLdr-specific options.

  Also add some documentation links to Geoff Chappell's website about
  how the default HAL and KERNEL names are chosen depending on the
  detected underlying platform on which the NT OS loader is running.
2019-08-31 01:42:46 +02:00
Hermès Bélusca-Maïto 602fc29ad4
[FREELDR] Formatting only. 2019-08-31 01:42:40 +02:00
Hermès Bélusca-Maïto 41ad62ea69
[FREELDR] Move around & static-ify some disk/partition functions. 2019-08-31 00:25:06 +02:00
Mark Jansen 93b2d5597e
[FREELDR][ARM] Suppress error about unused var 2019-08-20 22:28:11 +02:00
Hermès Bélusca-Maïto dca43193c8
[FREELDR] Demote the ArcOpen() trace in WinLdrLoadImage() to a warning only. 2019-08-18 15:26:25 +02:00
Stanislav Motylkov 87845a1cc2 [FREELDR] Add missing VideoSetTextCursorPosition handler for Xbox
This fixes null pointer call bug, which was revealed in 85d44fc. Spotted by Mark Jansen. CORE-16216

Co-authored-by: Mark Jansen <mark.jansen@reactos.org>
2019-08-17 01:47:34 +02:00
Stanislav Motylkov 7497b81e5b [FREELDR] Add Serial ports detection in DetectIsaBios() (#1829)
CORE-16216
2019-08-16 20:00:25 +02:00
Stanislav Motylkov c08beef1cf [FREELDR] Add PCI BIOS emulation and PCI bus enumeration for Xbox (#1830)
CORE-16216 CORE-16308
2019-08-16 19:14:10 +02:00
Timo Kreuzer cbb7ad6f5b [FREELDR] Improve debug output 2019-08-15 18:04:57 +02:00
Hermès Bélusca-Maïto 423d1e2e09
[FREELDR] Minor fixes.
- Add some forgotten, or move some misplaced ArcClose() calls so as
  to avoid leakages in failure paths. (Thanks to Serge Gautherie for
  having caught some of them.)

- Simplify some code; remove unneeded casts; use string-safe functions.
2019-08-14 16:36:50 +02:00
Hermès Bélusca-Maïto 85d44fca59
[FREELDR] Minor enhancements for disk/partition boot and UI.
- Factor out disk & partition opening in LoadAndBootPartition() and
  LoadAndBootDrive() into a LoadAndBootPartitionOrDrive() helper.

- Use ARC paths and ArcOpen()/ArcRead() instead of calling the
  machine-specific BIOS-oriented DiskGetPartitionEntry() and
  MachDiskReadLogicalSectors() functions to open the disk/partition
  and read their boot sectors.

- Don't forget to close the opened boot sector file in LoadAndBootBootSector().

- Add assertions for DiskReadBufferSize in PcMemFinalizeMemoryMap()
  and EnumerateHarddisks().

- x86/amd64 only:
  * Add a DisableA20 helper for disabling the A20 line, before rebooting
    back, or chain-load a boot sector, into 16-bit world.
    Also pulse the output port of the keyboard controller to clear out
    its state after having set the state of the A20 line.

  * In addition to disabling the A20 line when rebooting or chain-loading
    a boot sector, reset the video back to 80x25 text mode.

- Reset the cursor position back to the origin when initializing or
  terminating the TUI.
2019-08-13 23:07:01 +02:00
Hermès Bélusca-Maïto 7b5fab40c1
Addendum to fba4ad4c. 2019-08-11 22:06:27 +02:00
Hermès Bélusca-Maïto fba4ad4ceb
[FREELDR] Move files where they are only used.
- Merge fade.c/palette.c/video.c into video.c and move it into UI.
- Move inffile.c into NTLDR.
2019-08-11 22:01:36 +02:00
Hermès Bélusca-Maïto 8823a0c51e
[FREELDR] Addendum to 31a3f317. 2019-08-10 19:47:49 +02:00
Hermès Bélusca-Maïto 31a3f3177c
[FREELDR] Some changes that accumulated since years in my local copy. Also initialize SetupBlock->ArcSetupDeviceName to some valid value. 2019-08-10 19:15:37 +02:00
Hermès Bélusca-Maïto c9a20ced91
[FREELDR] Rework EXT2 filesystem to interface with ARC and not be tied to the boot volume.
See 28bf1f3b (r42537) and c599bd7d (r43267) for additional information.
2019-08-10 16:41:29 +02:00
Hermès Bélusca-Maïto 8d94b2a68d
[FREELDR] Diverse enhancements.
- Get rid of the FsCloseFile(), FsReadFile(), FsGetFileInformation(),
  FsGetFileSize() and FsSetFilePointer() wrappers and use the ARC
  functions directly instead. Make FsOpenFile() return an ARC file
  descriptor ID of the correct type. Get rid of unused FS_* defines.

- Use TRACEs in the ***Mount() filesystem functions for diagnostics
  purposes.

- Remove a leak in FatGetFatEntry(). Assign stuff via QuadPart where
  possible in FatMount(). Remove an unused member in FAT_FILE_INFO.

- Reduce code indentation in BtrFsMount() and remove a leak there.

- Disable reading the "BootPath" parameter in the linux loader since
  we don't use this parameter (yet??)
2019-08-10 16:41:29 +02:00
Hermès Bélusca-Maïto 75623bb1fa
[FREELDR] Fix erroneous change from d05be0da regarding RAMDISK loading in SETUPLDR.
Restore the correct position of (optional) RAMDISK loading code, before
attempting to open txtsetup.sif since the bootcd ISO might be the RAMDISK.
2019-08-08 23:09:43 +02:00
Victor Perevertkin 304e281099 [FREELDR] Verbose error output for FS errors 2019-08-08 02:33:10 +03:00
Hermès Bélusca-Maïto bc3314d4aa
[FREELDR] Better fix for x64. Addendum to 268cdf57. 2019-08-07 19:30:55 +02:00
Hermès Bélusca-Maïto 15bf4d18d6
[FREELDR] Fix EditBox initial string display length: do not count the NULL-terminator. 2019-08-07 19:18:04 +02:00
Yaroslav Kibysh bc7c689448
[FREELDR] Add ReactOS Setup as a custom boot type. (#1763)
CORE-9023 CORE-16260

Co-authored-by: Hermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
2019-08-07 18:50:26 +02:00
Yaroslav Kibysh b34d516e81
[FREELDR] Add "Edit Boot Command Line" feature. (#1763)
CORE-9023 CORE-16260

Co-authored-by: Hermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
2019-08-07 18:50:23 +02:00
Hermès Bélusca-Maïto 5d5b6a5600
[FREELDR] Some enhancements for the UI code. (#1763)
- EditBox: Display the initial contents of the text buffer.
  This allows modifying already existing text in the passed buffer.

- Menu:
  * Make both MenuHeader and MenuFooter optional (but the latter is
    more "optional" than the former...).

  * Allow passing a user-provided "Context" structure to the key-press
    filter callback, and pass also the index of the menu item that has
    been selected.

- Minor formatting fixes.
2019-08-07 18:50:20 +02:00
Hermès Bélusca-Maïto 268cdf5702
[FREELDR] Fix x64 build. 2019-08-07 18:49:19 +02:00
Hermès Bélusca-Maïto 5b326e74cd
[FREELDR] Don't call twice strlen() implicitly (in the min() macro). 2019-08-07 18:49:18 +02:00
Stanislav Motylkov 2811d2f990 [FREELDR] xboxmem: Fix array out-of-bounds access (#1775)
Memory map array should be large enough to fit additional descriptors.

CORE-16216 CORE-16267
2019-08-07 12:06:37 +02:00
Hermès Bélusca-Maïto d05be0da3f
[FREELDR] Some ARC-spec compatibility refactoring + simplifications & fixes.
CORE-9023

- During loading and initialization of the list of operating systems
  available in freeldr.ini, convert any legacy operating system entry
  encountered -- they are like those in NTLDR's boot.ini file, i.e.:

    ArcOsLoadPartition="LoadIdentifier" /List /of /Options

  into a new operating system INI entry, like those used by default in
  FreeLoader. This allows us to avoid treating this corner-case later in
  different parts of the code. Also, the "BootType" value is now
  determined there, only once.

- Convert the OS loaders entry-points to ARC-compatible ones, following
  the "Advanced RISC Computing Specification, Version 1.2" specification
  https://www.netbsd.org/docs/Hardware/Machines/ARC/riscspec.pdf

- Introduce helpers for retrieving options values from the argument vector
  in a simple way.

- Simplify LoadOperatingSystem(), since now the "BootType" value has
  been determined once while loading the list of OSes (see above) and
  is well-defined there. Use the BuildArgvForOsLoader() helper to build
  the ARC-compatible argument vector from the corresponding INI settings
  for the selected operating system entry, and use it when calling the
  corresponding OS loader.

- In the OS loaders, since we can now directly read the settings from
  the argument vector (instead of using INI settings), we can avoid
  using a bunch of fixed-size string buffers, and avoid potentially
  failing IniOpenSection() calls as well.

- Simplify code in the Linux loader (and the RemoveQuotes() function).

- Add UiShowMessageBoxesInArgv() that acts on the "MessageBox=" settings
  passed through the argument vector (equivalent to
  UiShowMessageBoxesInSection() ).

- Use string-safe functions where needed (copy/concatenation/printf on
  fixed-size buffers).
2019-08-06 23:40:05 +02:00
Hermès Bélusca-Maïto d21ffe6336
[FREELDR] Add an INI helper that allows modifying an existing setting's value in memory. 2019-08-06 23:39:53 +02:00
Hermès Bélusca-Maïto 909bfff460
[FREELDR] Some initialization fixes.
- Initialize BootPath and BootOptions buffers when fallback behaviour is not taken.
- Correctly skip all the understood whitespace (space & tabs) and the
  quotes before reading the boot options when using the alternative syntax:

  [Operating Systems]
  section_name = "ReactOS" /bootoptions

  Fixes the minor regression introduced in 370e8564 (r43875).
2019-08-04 17:47:04 +02:00
Hermès Bélusca-Maïto b978d42bd9
[FREELDR] Whitespace, minor code styles and comments fixes only. 2019-08-04 17:47:04 +02:00
Hermès Bélusca-Maïto e79e7bf53c
[FREELDR] Unload freeldr.ini file before booting. 2019-08-04 17:47:03 +02:00
Hermès Bélusca-Maïto 5cdb76094c
[FREELDR] Use NOGUIBOOT when booting in Safe-Mode. 2019-08-04 17:47:03 +02:00
Hermès Bélusca-Maïto b382145539
[FREELDR] Improve some *GetFileInformation() traces. 2019-07-30 00:57:22 +02:00
Stanislav Motylkov ef76709b3d [FREELDR] Fix remaining hwdisk and FATX bugs (#1766)
- DiskGetFileInformation() should return relative addresses -- relative to the beginning of the "device" (partition, or disk) in question.
- FatXSearchDirectoryBufferForFile() should assign file attributes.
- Minor code style improvements in FatOpenVolume().

CORE-16216 CORE-16248

Co-authored-by: Victor Perevertkin <victor@perevertkin.ru>
2019-07-30 00:27:36 +02:00
Stanislav Motylkov 06b77b8572 [FREELDR] Implement proper partition type detection and handling (#1762)
- This allows to detect and dynamically handle different partitioning schemes.
- Implemented detection of MBR, GPT, Xbox-BRFR, and partitionless disks.
- Currently only MBR and Xbox-BRFR partitions are handled and tested.

CORE-9841 CORE-15768 CORE-16216 CORE-16248
2019-07-29 14:25:54 +02:00
Stanislav Motylkov 8f25e464c2 [FREELDR] Trivial improvements (#1757)
* [FREELDR] Fix uninitialized string in DiskGetBootPath()

CORE-16216 CORE-16248

* [FREELDR] xboxdisk: Add comment and fix code style
2019-07-28 18:20:53 +02:00
Timo Kreuzer 8f050e66fd [FREELDR] Use RtlStringCbPrintfA instead of sprintf
Fixes GCC 8 warnings like:
boot/freeldr/freeldr/disk/scsiport.c:806:31: error: 'partition(0)' directive writing 12 bytes into a region of size between 1 and 64 [-Werror=format-overflow=]
     sprintf(PartitionName, "%spartition(0)", ArcName);
                               ^~~~~~~~~~~~
boot/freeldr/freeldr/disk/scsiport.c:806:5: note: 'sprintf' output between 13 and 76 bytes into a destination of size 64
     sprintf(PartitionName, "%spartition(0)", ArcName);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2019-07-20 13:56:18 +02:00
Stanislav Motylkov 74bcf3083d [FREELDR] Abstract VGA BIOS specific code (#1736)
* [FREELDR] Abstract VGA BIOS specific code

WinLdrSetupSpecialDataPointers() uses INT 10h video interrupts, but they are not available on Xbox, so make them machine-specific.

CORE-16204 CORE-16210

* [FREELDR] Abstract getting extended BIOS data area

WinLdrSetupSpecialDataPointers() uses INT 15h AH=C1h to get extended BIOS data area, but it's not available on Xbox, so make it machine-specific.

CORE-16204 CORE-16210
2019-07-18 23:09:59 +02:00
Stanislav Motylkov 7547f85b7e [FREELDR] Abstract floppy drive detection code (#1735)
Make floppy detection code machine-specific, because Xbox CMOS cannot be used to detect floppies. Based on a patch by Matt Borgerson.

CORE-16204 CORE-16207

Co-authored-by: Matt Borgerson <contact@mborgerson.com>
2019-07-18 22:50:48 +02:00
Stanislav Motylkov bca8093b89 [FREELDR] Fix memory initialization on Xbox
- Refactor and use PC memory map init functions
- This fixes filesystem detection and probably some other problems

Based on a patch by Matt Borgerson.

CORE-16204 CORE-16206

Co-authored-by: Matt Borgerson <contact@mborgerson.com>
2019-07-18 22:49:51 +02:00
Stanislav Motylkov 8c55fdd17c [FREELDR] Whitespace improvements - no code changes 2019-07-18 22:49:51 +02:00
Stanislav Motylkov 31aca248a1 [FREELDR] hwdisk: Add sanity checks to avoid infinite loop (#1731)
CORE-16204 CORE-16205
2019-07-18 22:49:11 +02:00
Victor Perevertkin 12542f271d
[FREELDR] Fix Release build 2019-06-26 00:56:21 +03:00
Yaroslav Kibysh f37fb1f7f8
[FREELDR] Always change video mode back to text-mode before starting up ReactOS.
CORE-16116

- This allows getting the /NOGUIBOOT mode working correctly, as the latter
  expects text-mode. Then, usetup (via BLUE driver) will change to a
  different text-mode, or, GUI boot will change (via BOOTVID) to VGA
  640*480 16-color.

- Always hide the VGA cursor.

- Remove also the deprecated boolean "Setup" in the *PrepareForReactOS()
  functions.

Co-authored-by: Hermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
2019-06-25 02:32:09 +02:00