[FREELDR] Always change video mode back to text-mode before starting up ReactOS.
[reactos.git] / boot / freeldr / freeldr / arch / i386 / machxbox.c
1 /*
2 * FreeLoader
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19 #include <freeldr.h>
20
21 #include <debug.h>
22
23 DBG_DEFAULT_CHANNEL(HWDETECT);
24
25
26 // NOTE: Similar to machpc.c!PcGetHarddiskConfigurationData(),
27 // but without extended geometry support.
28 static
29 PCM_PARTIAL_RESOURCE_LIST
30 XboxGetHarddiskConfigurationData(UCHAR DriveNumber, ULONG* pSize)
31 {
32 PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
33 PCM_DISK_GEOMETRY_DEVICE_DATA DiskGeometry;
34 //EXTENDED_GEOMETRY ExtGeometry;
35 GEOMETRY Geometry;
36 ULONG Size;
37
38 //
39 // Initialize returned size
40 //
41 *pSize = 0;
42
43 /* Set 'Configuration Data' value */
44 Size = sizeof(CM_PARTIAL_RESOURCE_LIST) +
45 sizeof(CM_DISK_GEOMETRY_DEVICE_DATA);
46 PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
47 if (PartialResourceList == NULL)
48 {
49 ERR("Failed to allocate a full resource descriptor\n");
50 return NULL;
51 }
52
53 memset(PartialResourceList, 0, Size);
54 PartialResourceList->Version = 1;
55 PartialResourceList->Revision = 1;
56 PartialResourceList->Count = 1;
57 PartialResourceList->PartialDescriptors[0].Type =
58 CmResourceTypeDeviceSpecific;
59 // PartialResourceList->PartialDescriptors[0].ShareDisposition =
60 // PartialResourceList->PartialDescriptors[0].Flags =
61 PartialResourceList->PartialDescriptors[0].u.DeviceSpecificData.DataSize =
62 sizeof(CM_DISK_GEOMETRY_DEVICE_DATA);
63
64 /* Get pointer to geometry data */
65 DiskGeometry = (PVOID)(((ULONG_PTR)PartialResourceList) + sizeof(CM_PARTIAL_RESOURCE_LIST));
66
67 /* Get the disk geometry */
68 //ExtGeometry.Size = sizeof(EXTENDED_GEOMETRY);
69
70 if (MachDiskGetDriveGeometry(DriveNumber, &Geometry))
71 {
72 DiskGeometry->BytesPerSector = Geometry.BytesPerSector;
73 DiskGeometry->NumberOfCylinders = Geometry.Cylinders;
74 DiskGeometry->SectorsPerTrack = Geometry.Sectors;
75 DiskGeometry->NumberOfHeads = Geometry.Heads;
76 }
77 else
78 {
79 ERR("Reading disk geometry failed\n");
80 FrLdrHeapFree(PartialResourceList, TAG_HW_RESOURCE_LIST);
81 return NULL;
82 }
83 TRACE("Disk %x: %u Cylinders %u Heads %u Sectors %u Bytes\n",
84 DriveNumber,
85 DiskGeometry->NumberOfCylinders,
86 DiskGeometry->NumberOfHeads,
87 DiskGeometry->SectorsPerTrack,
88 DiskGeometry->BytesPerSector);
89
90 //
91 // Return configuration data
92 //
93 *pSize = Size;
94 return PartialResourceList;
95 }
96
97 static
98 VOID
99 DetectIsaBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
100 {
101 PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
102 PCONFIGURATION_COMPONENT_DATA BusKey;
103 ULONG Size;
104
105 /* Set 'Configuration Data' value */
106 Size = sizeof(CM_PARTIAL_RESOURCE_LIST) -
107 sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
108 PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
109 if (PartialResourceList == NULL)
110 {
111 TRACE("Failed to allocate resource descriptor\n");
112 return;
113 }
114
115 /* Initialize resource descriptor */
116 memset(PartialResourceList, 0, Size);
117 PartialResourceList->Version = 1;
118 PartialResourceList->Revision = 1;
119 PartialResourceList->Count = 0;
120
121 /* Create new bus key */
122 FldrCreateComponentKey(SystemKey,
123 AdapterClass,
124 MultiFunctionAdapter,
125 0x0,
126 0x0,
127 0xFFFFFFFF,
128 "ISA",
129 PartialResourceList,
130 Size,
131 &BusKey);
132
133 /* Increment bus number */
134 (*BusNumber)++;
135
136 /* Detect ISA/BIOS devices */
137 DetectBiosDisks(SystemKey, BusKey);
138
139 /* FIXME: Detect more ISA devices */
140 }
141
142 PCONFIGURATION_COMPONENT_DATA
143 XboxHwDetect(VOID)
144 {
145 PCONFIGURATION_COMPONENT_DATA SystemKey;
146 ULONG BusNumber = 0;
147
148 TRACE("DetectHardware()\n");
149
150 /* Create the 'System' key */
151 FldrCreateSystemKey(&SystemKey);
152
153 GetHarddiskConfigurationData = XboxGetHarddiskConfigurationData;
154
155 /* TODO: Build actual xbox's hardware configuration tree */
156 DetectIsaBios(SystemKey, &BusNumber);
157
158 TRACE("DetectHardware() Done\n");
159 return SystemKey;
160 }
161
162 VOID XboxHwIdle(VOID)
163 {
164 /* UNIMPLEMENTED */
165 }
166
167
168 /******************************************************************************/
169
170 VOID
171 XboxMachInit(const char *CmdLine)
172 {
173 /* Set LEDs to red before anything is initialized */
174 XboxSetLED("rrrr");
175
176 /* Initialize our stuff */
177 XboxMemInit();
178 XboxVideoInit();
179
180 /* Setup vtbl */
181 MachVtbl.ConsPutChar = XboxConsPutChar;
182 MachVtbl.ConsKbHit = XboxConsKbHit;
183 MachVtbl.ConsGetCh = XboxConsGetCh;
184 MachVtbl.VideoClearScreen = XboxVideoClearScreen;
185 MachVtbl.VideoSetDisplayMode = XboxVideoSetDisplayMode;
186 MachVtbl.VideoGetDisplaySize = XboxVideoGetDisplaySize;
187 MachVtbl.VideoGetBufferSize = XboxVideoGetBufferSize;
188 MachVtbl.VideoHideShowTextCursor = XboxVideoHideShowTextCursor;
189 MachVtbl.VideoPutChar = XboxVideoPutChar;
190 MachVtbl.VideoCopyOffScreenBufferToVRAM = XboxVideoCopyOffScreenBufferToVRAM;
191 MachVtbl.VideoIsPaletteFixed = XboxVideoIsPaletteFixed;
192 MachVtbl.VideoSetPaletteColor = XboxVideoSetPaletteColor;
193 MachVtbl.VideoGetPaletteColor = XboxVideoGetPaletteColor;
194 MachVtbl.VideoSync = XboxVideoSync;
195 MachVtbl.Beep = PcBeep;
196 MachVtbl.PrepareForReactOS = XboxPrepareForReactOS;
197 MachVtbl.GetMemoryMap = XboxMemGetMemoryMap;
198 MachVtbl.DiskGetBootPath = DiskGetBootPath;
199 MachVtbl.DiskReadLogicalSectors = XboxDiskReadLogicalSectors;
200 MachVtbl.DiskGetDriveGeometry = XboxDiskGetDriveGeometry;
201 MachVtbl.DiskGetCacheableBlockCount = XboxDiskGetCacheableBlockCount;
202 MachVtbl.GetTime = XboxGetTime;
203 MachVtbl.InitializeBootDevices = PcInitializeBootDevices;
204 MachVtbl.HwDetect = XboxHwDetect;
205 MachVtbl.HwIdle = XboxHwIdle;
206
207 DiskGetPartitionEntry = XboxDiskGetPartitionEntry;
208
209 /* Set LEDs to orange after init */
210 XboxSetLED("oooo");
211 }
212
213 VOID
214 XboxPrepareForReactOS(VOID)
215 {
216 /* On XBOX, prepare video and turn off the floppy motor */
217 XboxVideoPrepareForReactOS();
218 DiskStopFloppyMotor();
219 }
220
221 /* EOF */