5d388581358e4214a7e40d14cdbcbdb1875159a4
[reactos.git] / freeldr / freeldr / freeldr.c
1 /*
2 * FreeLoader
3 * Copyright (C) 1998-2002 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 "rtl.h"
22 #include "fs.h"
23 #include "reactos.h"
24 #include "ui.h"
25 #include "arch.h"
26 #include "miscboot.h"
27 #include "linux.h"
28 #include "mm.h"
29 #include "parseini.h"
30 #include "debug.h"
31 #include "oslist.h"
32 #include "cache.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 ULONG GetDefaultOperatingSystem(PUCHAR OperatingSystemList[], ULONG OperatingSystemCount);
39 LONG GetTimeOut(VOID);
40
41 VOID BootMain(VOID)
42 {
43 ULONG Idx;
44 UCHAR SettingName[80];
45 UCHAR SettingValue[80];
46 ULONG SectionId;
47 ULONG OperatingSystemCount;
48 PUCHAR *OperatingSystemSectionNames;
49 PUCHAR *OperatingSystemDisplayNames;
50 ULONG DefaultOperatingSystem;
51 LONG TimeOut;
52 ULONG SelectedOperatingSystem;
53
54 enable_a20();
55
56 #ifdef DEBUG
57 DebugInit();
58 #endif
59
60 InitMemoryManager( (PVOID) 0x20000 /* BaseAddress */, 0x70000 /* Length */);
61
62 if (!ParseIniFile())
63 {
64 printf("Press any key to reboot.\n");
65 getch();
66 return;
67 }
68
69 if (!OpenSection("FreeLoader", &SectionId))
70 {
71 printf("Section [FreeLoader] not found in freeldr.ini.\n");
72 getch();
73 return;
74 }
75
76 if (!InitUserInterface())
77 {
78 printf("Press any key to reboot.\n");
79 getch();
80 return;
81 }
82
83 if (!InitOperatingSystemList(&OperatingSystemSectionNames, &OperatingSystemDisplayNames, &OperatingSystemCount))
84 {
85 MessageBox("Press ENTER to reboot.\n");
86 goto reboot;
87 }
88
89 if (OperatingSystemCount == 0)
90 {
91 MessageBox("There were no operating systems listed in freeldr.ini.\nPress ENTER to reboot.");
92 goto reboot;
93 }
94
95 DefaultOperatingSystem = GetDefaultOperatingSystem(OperatingSystemSectionNames, OperatingSystemCount);
96 TimeOut = GetTimeOut();
97
98 //
99 // Find all the message box settings and run them
100 //
101 ShowMessageBoxesInSection("FreeLoader");
102
103 for (;;)
104 {
105 if (!DisplayMenu(OperatingSystemDisplayNames, OperatingSystemCount, DefaultOperatingSystem, TimeOut, &SelectedOperatingSystem))
106 {
107 MessageBox("Press ENTER to reboot.\n");
108 return;
109 }
110
111 LoadAndBootReactOS(OperatingSystemSectionNames[SelectedOperatingSystem]);
112
113 /*switch (OSList[nOSToBoot].nOSType)
114 {
115 case OSTYPE_REACTOS:
116 LoadAndBootReactOS(OSList[nOSToBoot].name);
117 break;
118 case OSTYPE_LINUX:
119 MessageBox("Cannot boot this OS type yet!");
120 break;
121 case OSTYPE_BOOTSECTOR:
122 LoadAndBootBootSector(nOSToBoot);
123 break;
124 case OSTYPE_PARTITION:
125 LoadAndBootPartition(nOSToBoot);
126 break;
127 case OSTYPE_DRIVE:
128 LoadAndBootDrive(nOSToBoot);
129 break;
130 }*/
131 }
132
133
134 reboot:
135 clrscr();
136 showcursor();
137 return;
138 }
139
140 ULONG GetDefaultOperatingSystem(PUCHAR OperatingSystemList[], ULONG OperatingSystemCount)
141 {
142 UCHAR DefaultOSText[80];
143 ULONG SectionId;
144 ULONG DefaultOS = 0;
145 ULONG Idx;
146
147 if (!OpenSection("FreeLoader", &SectionId))
148 {
149 return 0;
150 }
151
152 if (ReadSectionSettingByName(SectionId, "DefaultOS", DefaultOSText, 80))
153 {
154 for (Idx=0; Idx<OperatingSystemCount; Idx++)
155 {
156 if (stricmp(DefaultOSText, OperatingSystemList[Idx]) == 0)
157 {
158 DefaultOS = Idx;
159 break;
160 }
161 }
162 }
163
164 return DefaultOS;
165 }
166
167 LONG GetTimeOut(VOID)
168 {
169 UCHAR TimeOutText[20];
170 ULONG TimeOut;
171 ULONG SectionId;
172
173 if (!OpenSection("FreeLoader", &SectionId))
174 {
175 return -1;
176 }
177
178 if (ReadSectionSettingByName(SectionId, "TimeOut", TimeOutText, 20))
179 {
180 TimeOut = atoi(TimeOutText);
181 }
182 else
183 {
184 TimeOut = -1;
185 }
186
187 return TimeOut;
188 }