ReactOS  0.4.13-dev-39-g8b6696f
freeldr.h File Reference
#include <ntsup.h>
#include <arcname.h>
#include <bytesex.h>
#include <cache.h>
#include <cmdline.h>
#include <comm.h>
#include <disk.h>
#include <fs.h>
#include <inffile.h>
#include <inifile.h>
#include <keycodes.h>
#include <linux.h>
#include <custom.h>
#include <miscboot.h>
#include <machine.h>
#include <mm.h>
#include <multiboot.h>
#include <options.h>
#include <oslist.h>
#include <ramdisk.h>
#include <ui.h>
#include <ver.h>
#include <video.h>
#include <winldr.h>
#include <conversion.h>
#include <fs/ext2.h>
#include <fs/fat.h>
#include <fs/ntfs.h>
#include <fs/iso.h>
#include <fs/pxe.h>
#include <fs/btrfs.h>
#include <ui/gui.h>
#include <ui/minitui.h>
#include <ui/noui.h>
#include <ui/tui.h>
#include <arch/archwsup.h>
Include dependency graph for freeldr.h:

Go to the source code of this file.

Macros

#define UINT64_C(val)   val##ULL
 
#define RVA(m, b)   ((PVOID)((ULONG_PTR)(b) + (ULONG_PTR)(m)))
 
#define ROUND_DOWN(n, align)   (((ULONG)n) & ~((align) - 1l))
 
#define ROUND_UP(n, align)   ROUND_DOWN(((ULONG)n) + (align) - 1, (align))
 

Functions

VOID __cdecl BootMain (IN PCCH CmdLine)
 
VOID LoadOperatingSystem (IN OperatingSystemItem *OperatingSystem)
 
VOID RunLoader (VOID)
 
VOID FrLdrCheckCpuCompatibility (VOID)
 

Macro Definition Documentation

◆ ROUND_DOWN

#define ROUND_DOWN (   n,
  align 
)    (((ULONG)n) & ~((align) - 1l))

Definition at line 26 of file freeldr.h.

◆ ROUND_UP

#define ROUND_UP (   n,
  align 
)    ROUND_DOWN(((ULONG)n) + (align) - 1, (align))

Definition at line 29 of file freeldr.h.

◆ RVA

#define RVA (   m,
  b 
)    ((PVOID)((ULONG_PTR)(b) + (ULONG_PTR)(m)))

Definition at line 24 of file freeldr.h.

◆ UINT64_C

#define UINT64_C (   val)    val##ULL

Definition at line 23 of file freeldr.h.

Function Documentation

◆ BootMain()

VOID __cdecl BootMain ( IN PCCH  CmdLine)

Definition at line 29 of file freeldr.c.

30 {
32 
33  /* Debugger pre-initialization */
35 
36  TRACE("BootMain() called.\n");
37 
39 
40  /* Check if the CPU is new enough */
41  FrLdrCheckCpuCompatibility(); // FIXME: Should be done inside MachInit!
42 
43  /* UI pre-initialization */
44  if (!UiInitialize(FALSE))
45  {
46  UiMessageBoxCritical("Unable to initialize UI.");
47  goto Quit;
48  }
49 
50  /* Initialize memory manager */
52  {
53  UiMessageBoxCritical("Unable to initialize memory manager.");
54  goto Quit;
55  }
56 
57  /* Initialize I/O subsystem */
58  FsInit();
59 
60  RunLoader();
61 
62 Quit:
63  /* If we reach this point, something went wrong before, therefore reboot */
64 #if defined(__i386__) || defined(_M_AMD64)
66 #endif
67  Reboot();
68 }
#define DebugInit(init)
Definition: debug.h:116
VOID FsInit(VOID)
Definition: fs.c:488
char CmdLine[0x100]
Definition: mach.c:35
VOID RunLoader(VOID)
Definition: bootmgr.c:176
BOOLEAN MmInitializeMemoryManager(VOID)
Definition: meminit.c:313
BOOLEAN UiInitialize(BOOLEAN ShowGui)
Definition: ui.c:84
Definition: bl.h:892
#define TRACE(s)
Definition: solgame.cpp:4
VOID FrLdrCheckCpuCompatibility(VOID)
Definition: macharm.c:67
VOID CmdLineParse(IN PCCH CmdLine)
Definition: cmdline.c:29
VOID UiMessageBoxCritical(PCSTR MessageText)
Definition: ui.c:358
#define MachInit
Definition: amd64.h:42
VOID DiskStopFloppyMotor(VOID)
Definition: macharm.c:62

◆ FrLdrCheckCpuCompatibility()

VOID FrLdrCheckCpuCompatibility ( VOID  )

Definition at line 67 of file macharm.c.

68 {
69  /* Nothing for now */
70 }

Referenced by BootMain().

◆ LoadOperatingSystem()

VOID LoadOperatingSystem ( IN OperatingSystemItem OperatingSystem)

Definition at line 56 of file bootmgr.c.

57 {
58  ULONG_PTR SectionId;
59  PCSTR SectionName = OperatingSystem->SystemPartition;
60  CHAR BootType[80];
61  ULONG i;
62 
63  /* Try to open the operating system section in the .ini file */
64  if (IniOpenSection(SectionName, &SectionId))
65  {
66  /* Try to read the boot type */
67  IniReadSettingByName(SectionId, "BootType", BootType, sizeof(BootType));
68  }
69  else
70  {
71  BootType[0] = ANSI_NULL;
72  }
73 
74  if (BootType[0] == ANSI_NULL && SectionName[0] != ANSI_NULL)
75  {
76  /* Try to infer the boot type value */
77 #ifdef _M_IX86
78  ULONG FileId;
79  if (ArcOpen((PSTR)SectionName, OpenReadOnly, &FileId) == ESUCCESS)
80  {
81  ArcClose(FileId);
82  strcpy(BootType, "BootSector");
83  }
84  else
85 #endif
86  {
87  strcpy(BootType, "Windows");
88  }
89  }
90 
91 #if defined(_M_IX86)
92  /* Install the drive mapper according to this section drive mappings */
93  DriveMapMapDrivesInSection(SectionName);
94 #endif
95 
96  /* Loop through the OS loading method table and find a suitable OS to boot */
97  for (i = 0; i < sizeof(OSLoadingMethods) / sizeof(OSLoadingMethods[0]); ++i)
98  {
100  {
101  OSLoadingMethods[i].Load(OperatingSystem,
103  return;
104  }
105  }
106 }
Definition: arc.h:32
char CHAR
Definition: xmlstorage.h:175
PCHAR BootType
Definition: bootmgr.c:34
#define _stricmp
Definition: cat.c:22
uint32_t ULONG_PTR
Definition: typedefs.h:63
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define ANSI_NULL
VOID DriveMapMapDrivesInSection(PCSTR SectionName)
Definition: drivemap.c:30
USHORT OperatingSystemVersion
Definition: bootmgr.c:35
BOOLEAN IniReadSettingByName(ULONG_PTR SectionId, PCSTR SettingName, PCHAR Buffer, ULONG BufferSize)
Definition: inifile.c:147
BOOLEAN IniOpenSection(PCSTR SectionName, ULONG_PTR *SectionId)
Definition: inifile.c:25
static const struct @151 OSLoadingMethods[]
signed char * PSTR
Definition: retypes.h:7
ARC_STATUS ArcClose(ULONG FileId)
Definition: fs.c:219
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
ARC_STATUS ArcOpen(CHAR *Path, OPENMODE OpenMode, ULONG *FileId)
Definition: fs.c:57
unsigned int ULONG
Definition: retypes.h:1
const char * PCSTR
Definition: typedefs.h:51

Referenced by OptionMenuCustomBootReactOS(), and RunLoader().

◆ RunLoader()

VOID RunLoader ( VOID  )

Definition at line 176 of file bootmgr.c.

177 {
178  ULONG_PTR SectionId;
179  ULONG OperatingSystemCount;
180  OperatingSystemItem* OperatingSystemList;
181  PCSTR* OperatingSystemDisplayNames;
182  ULONG DefaultOperatingSystem;
183  LONG TimeOut;
184  ULONG SelectedOperatingSystem;
185  ULONG i;
186 
188  {
189  UiMessageBoxCritical("Error when detecting hardware.");
190  return;
191  }
192 
193 #ifdef _M_IX86
194  /* Load additional SCSI driver (if any) */
196  {
197  UiMessageBoxCritical("Unable to load additional boot device drivers.");
198  }
199 #endif
200 
201  if (!IniFileInitialize())
202  {
203  UiMessageBoxCritical("Error initializing .ini file.");
204  return;
205  }
206 
207  /* Debugger main initialization */
208  DebugInit(TRUE);
209 
210  if (!IniOpenSection("FreeLoader", &SectionId))
211  {
212  UiMessageBoxCritical("Section [FreeLoader] not found in freeldr.ini.");
213  return;
214  }
215 
216  TimeOut = GetTimeOut();
217 
218  /* UI main initialization */
219  if (!UiInitialize(TRUE))
220  {
221  UiMessageBoxCritical("Unable to initialize UI.");
222  return;
223  }
224 
225  OperatingSystemList = InitOperatingSystemList(&OperatingSystemCount);
226  if (!OperatingSystemList)
227  {
228  UiMessageBox("Unable to read operating systems section in freeldr.ini.\nPress ENTER to reboot.");
229  goto Reboot;
230  }
231 
232  if (OperatingSystemCount == 0)
233  {
234  UiMessageBox("There were no operating systems listed in freeldr.ini.\nPress ENTER to reboot.");
235  goto Reboot;
236  }
237 
238  DefaultOperatingSystem = GetDefaultOperatingSystem(OperatingSystemList, OperatingSystemCount);
239 
240  /* Create list of display names */
241  OperatingSystemDisplayNames = FrLdrTempAlloc(sizeof(PCSTR) * OperatingSystemCount, 'mNSO');
242  if (!OperatingSystemDisplayNames)
243  goto Reboot;
244 
245  for (i = 0; i < OperatingSystemCount; i++)
246  {
247  OperatingSystemDisplayNames[i] = OperatingSystemList[i].LoadIdentifier;
248  }
249 
250  /* Find all the message box settings and run them */
251  UiShowMessageBoxesInSection("FreeLoader");
252 
253  for (;;)
254  {
255  /* Redraw the backdrop */
256  UiDrawBackdrop();
257 
258  /* Show the operating system list menu */
259  if (!UiDisplayMenu("Please select the operating system to start:",
260  "For troubleshooting and advanced startup options for "
261  "ReactOS, press F8.",
262  TRUE,
263  OperatingSystemDisplayNames,
264  OperatingSystemCount,
265  DefaultOperatingSystem,
266  TimeOut,
267  &SelectedOperatingSystem,
268  FALSE,
270  {
271  UiMessageBox("Press ENTER to reboot.");
272  goto Reboot;
273  }
274 
275  TimeOut = -1;
276 
277  /* Load the chosen operating system */
278  LoadOperatingSystem(&OperatingSystemList[SelectedOperatingSystem]);
279  }
280 
281 Reboot:
282  UiUnInitialize("Rebooting...");
283  return;
284 }
#define DebugInit(init)
Definition: debug.h:116
#define TRUE
Definition: types.h:120
OperatingSystemItem * InitOperatingSystemList(ULONG *OperatingSystemCountPointer)
Definition: oslist.c:43
Definition: arc.h:32
BOOLEAN UiInitialize(BOOLEAN ShowGui)
Definition: ui.c:84
BOOLEAN MainBootMenuKeyPressFilter(ULONG KeyPress)
Definition: bootmgr.c:164
ULONG LoadBootDeviceDriver(VOID)
Definition: scsiport.c:1591
VOID UiShowMessageBoxesInSection(PCSTR SectionName)
Definition: ui.c:383
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define MachInitializeBootDevices()
Definition: machine.h:127
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
long LONG
Definition: pedump.c:60
VOID UiMessageBox(PCSTR Format,...)
Definition: ui.c:347
FORCEINLINE PVOID FrLdrTempAlloc(_In_ SIZE_T Size, _In_ ULONG Tag)
Definition: mm.h:177
Definition: bl.h:892
ULONG GetDefaultOperatingSystem(OperatingSystemItem *OperatingSystemList, ULONG OperatingSystemCount)
Definition: bootmgr.c:108
BOOLEAN UiDisplayMenu(PCSTR MenuHeader, PCSTR MenuFooter, BOOLEAN ShowBootOptions, PCSTR MenuItemList[], ULONG MenuItemCount, ULONG DefaultMenuItem, LONG MenuTimeOut, ULONG *SelectedMenuItem, BOOLEAN CanEscape, UiMenuKeyPressFilterCallback KeyPressFilter)
Definition: ui.c:459
BOOLEAN IniOpenSection(PCSTR SectionName, ULONG_PTR *SectionId)
Definition: inifile.c:25
VOID UiUnInitialize(PCSTR BootText)
Definition: ui.c:232
VOID UiDrawBackdrop(VOID)
Definition: ui.c:241
LONG GetTimeOut(VOID)
Definition: bootmgr.c:143
BOOLEAN IniFileInitialize(VOID)
Definition: ini_init.c:38
unsigned int ULONG
Definition: retypes.h:1
VOID LoadOperatingSystem(IN OperatingSystemItem *OperatingSystem)
Definition: bootmgr.c:56
const char * PCSTR
Definition: typedefs.h:51
VOID UiMessageBoxCritical(PCSTR MessageText)
Definition: ui.c:358

Referenced by BootMain().