Added system hive support.
[reactos.git] / freeldr / freeldr / freeldr.c
1 /*
2 * FreeLoader
3 * Copyright (C) 1999, 2000, 2001 Brian Palmer <brianp@sginet.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include "freeldr.h"
21 #include "stdlib.h"
22 #include "fs.h"
23 #include "reactos/reactos.h"
24 #include "tui.h"
25 #include "asmcode.h"
26 #include "menu.h"
27 #include "miscboot.h"
28 #include "linux.h"
29 #include "memory.h"
30 #include "parseini.h"
31 #include "debug.h"
32 #include "oslist.h"
33
34 // Variable BootDrive moved to asmcode.S
35 //ULONG BootDrive = 0; // BIOS boot drive, 0-A:, 1-B:, 0x80-C:, 0x81-D:, etc.
36 ULONG BootPartition = 0; // Boot Partition, 1-4
37
38 PUCHAR ScreenBuffer = (PUCHAR)(SCREENBUFFER); // Save buffer for screen contents
39 ULONG CursorXPos = 0; // Cursor's X Position
40 ULONG CursorYPos = 0; // Cursor's Y Position
41
42 ULONG GetDefaultOperatingSystem(PUCHAR OperatingSystemList[], ULONG OperatingSystemCount);
43 LONG GetTimeOut(VOID);
44
45 VOID BootMain(VOID)
46 {
47 ULONG Idx;
48 UCHAR SettingName[80];
49 UCHAR SettingValue[80];
50 ULONG SectionId;
51 ULONG OperatingSystemCount;
52 PUCHAR *OperatingSystemSectionNames;
53 PUCHAR *OperatingSystemDisplayNames;
54 ULONG DefaultOperatingSystem;
55 LONG TimeOut;
56 ULONG SelectedOperatingSystem;
57
58 enable_a20();
59
60 CursorXPos = (ULONG) *((PUCHAR)(SCREENXCOORD));
61 CursorYPos = (ULONG) *((PUCHAR)(SCREENYCOORD));
62
63 #ifdef DEBUG
64 DebugInit();
65 #endif
66
67 InitMemoryManager( (PVOID) 0x20000 /* BaseAddress */, 0x70000 /* Length */);
68
69 if (!ParseIniFile())
70 {
71 printf("Press any key to reboot.\n");
72 getch();
73 return;
74 }
75
76 if (!OpenSection("FreeLoader", &SectionId))
77 {
78 printf("Section [FreeLoader] not found in freeldr.ini.\n");
79 getch();
80 return;
81 }
82
83 if (!InitUserInterface())
84 {
85 printf("Press any key to reboot.\n");
86 getch();
87 return;
88 }
89
90 if (!InitOperatingSystemList(&OperatingSystemSectionNames, &OperatingSystemDisplayNames, &OperatingSystemCount))
91 {
92 MessageBox("Press ENTER to reboot.\n");
93 goto reboot;
94 }
95
96 if (OperatingSystemCount == 0)
97 {
98 MessageBox("There were no operating systems listed in freeldr.ini.\nPress ENTER to reboot.");
99 goto reboot;
100 }
101
102 DefaultOperatingSystem = GetDefaultOperatingSystem(OperatingSystemSectionNames, OperatingSystemCount);
103 TimeOut = GetTimeOut();
104
105 //
106 // Find all the message box settings and run them
107 //
108 for (Idx=0; Idx<GetNumSectionItems(SectionId); Idx++)
109 {
110 ReadSectionSettingByNumber(SectionId, Idx, SettingName, 80, SettingValue, 80);
111
112 if (stricmp(SettingName, "MessageBox") == 0)
113 {
114 MessageBox(SettingValue);
115 }
116 else if (stricmp(SettingName, "MessageLine") == 0)
117 {
118 MessageLine(SettingValue);
119 }
120 }
121
122 for (;;)
123 {
124 if (!DisplayMenu(OperatingSystemDisplayNames, OperatingSystemCount, DefaultOperatingSystem, TimeOut, &SelectedOperatingSystem))
125 {
126 MessageBox("Press ENTER to reboot.\n");
127 return;
128 }
129
130 LoadAndBootReactOS(OperatingSystemSectionNames[SelectedOperatingSystem]);
131
132 /*switch (OSList[nOSToBoot].nOSType)
133 {
134 case OSTYPE_REACTOS:
135 LoadAndBootReactOS(OSList[nOSToBoot].name);
136 break;
137 case OSTYPE_LINUX:
138 MessageBox("Cannot boot this OS type yet!");
139 break;
140 case OSTYPE_BOOTSECTOR:
141 LoadAndBootBootSector(nOSToBoot);
142 break;
143 case OSTYPE_PARTITION:
144 LoadAndBootPartition(nOSToBoot);
145 break;
146 case OSTYPE_DRIVE:
147 LoadAndBootDrive(nOSToBoot);
148 break;
149 }*/
150 }
151
152
153 reboot:
154 RestoreScreen(ScreenBuffer);
155 showcursor();
156 gotoxy(CursorXPos, CursorYPos);
157 return;
158 }
159
160 ULONG GetDefaultOperatingSystem(PUCHAR OperatingSystemList[], ULONG OperatingSystemCount)
161 {
162 UCHAR DefaultOSText[80];
163 ULONG SectionId;
164 ULONG DefaultOS;
165 ULONG Idx;
166
167 if (!OpenSection("FreeLoader", &SectionId))
168 {
169 return 0;
170 }
171
172 if (ReadSectionSettingByName(SectionId, "DefaultOS", DefaultOSText, 80))
173 {
174 for (Idx=0; Idx<OperatingSystemCount; Idx++)
175 {
176 if (stricmp(DefaultOSText, OperatingSystemList[Idx]) == 0)
177 {
178 DefaultOS = Idx;
179 break;
180 }
181 }
182 }
183 else
184 {
185 DefaultOS = 0;
186 }
187
188 return DefaultOS;
189 }
190
191 LONG GetTimeOut(VOID)
192 {
193 UCHAR TimeOutText[20];
194 ULONG TimeOut;
195 ULONG SectionId;
196
197 if (!OpenSection("FreeLoader", &SectionId))
198 {
199 return -1;
200 }
201
202 if (ReadSectionSettingByName(SectionId, "TimeOut", TimeOutText, 20))
203 {
204 TimeOut = atoi(TimeOutText);
205 }
206 else
207 {
208 TimeOut = -1;
209 }
210
211 return TimeOut;
212 }