8bf927d1b91d4579f117c07f9a2890fbc10f2ca6
[reactos.git] / boot / freeldr / freeldr / arch / arm / macharm.c
1 /*
2 * PROJECT: ReactOS Boot Loader
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: boot/freeldr/freeldr/arch/arm/macharm.c
5 * PURPOSE: Provides abstraction between the ARM Boot Loader and FreeLDR
6 * PROGRAMMERS: ReactOS Portable Systems Group
7 */
8
9 /* INCLUDES *******************************************************************/
10
11 #include <freeldr.h>
12 #include <internal/arm/intrin_i.h>
13
14 /* GLOBALS ********************************************************************/
15
16 PARM_BOARD_CONFIGURATION_BLOCK ArmBoardBlock;
17 ULONG gDiskReadBuffer, gFileSysBuffer;
18 BOOLEAN ArmHwDetectRan;
19 PCONFIGURATION_COMPONENT_DATA RootNode;
20
21 BOOLEAN AcpiPresent = FALSE;
22
23 ULONG FirstLevelDcacheSize;
24 ULONG FirstLevelDcacheFillSize;
25 ULONG FirstLevelIcacheSize;
26 ULONG FirstLevelIcacheFillSize;
27 ULONG SecondLevelDcacheSize;
28 ULONG SecondLevelDcacheFillSize;
29 ULONG SecondLevelIcacheSize;
30 ULONG SecondLevelIcacheFillSize;
31
32 extern ULONG reactos_disk_count;
33 extern ARC_DISK_SIGNATURE_EX reactos_arc_disk_info[];
34
35 ULONG SizeBits[] =
36 {
37 -1, // INVALID
38 -1, // INVALID
39 1 << 12, // 4KB
40 1 << 13, // 8KB
41 1 << 14, // 16KB
42 1 << 15, // 32KB
43 1 << 16, // 64KB
44 1 << 17 // 128KB
45 };
46
47 ULONG AssocBits[] =
48 {
49 -1, // INVALID
50 -1, // INVALID
51 4 // 4-way associative
52 };
53
54 ULONG LenBits[] =
55 {
56 -1, // INVALID
57 -1, // INVALID
58 8 // 8 words per line (32 bytes)
59 };
60
61 /* FUNCTIONS ******************************************************************/
62
63 VOID DiskStopFloppyMotor(VOID)
64 {
65 }
66
67 VOID
68 FrLdrCheckCpuCompatibility(VOID)
69 {
70 /* Nothing for now */
71 }
72
73 VOID
74 ArmInit(IN PARM_BOARD_CONFIGURATION_BLOCK BootContext)
75 {
76 /* Remember the pointer */
77 ArmBoardBlock = BootContext;
78
79 /* Let's make sure we understand the LLB */
80 ASSERT(ArmBoardBlock->MajorVersion == ARM_BOARD_CONFIGURATION_MAJOR_VERSION);
81 ASSERT(ArmBoardBlock->MinorVersion == ARM_BOARD_CONFIGURATION_MINOR_VERSION);
82
83 /* This should probably go away once we support more boards */
84 ASSERT((ArmBoardBlock->BoardType == MACH_TYPE_FEROCEON) ||
85 (ArmBoardBlock->BoardType == MACH_TYPE_VERSATILE_PB) ||
86 (ArmBoardBlock->BoardType == MACH_TYPE_OMAP3_BEAGLE) ||
87 (ArmBoardBlock->BoardType == MACH_TYPE_OMAP_ZOOM2));
88
89 /* Call FreeLDR's portable entrypoint with our command-line */
90 BootMain(ArmBoardBlock->CommandLine);
91 }
92
93 VOID
94 ArmPrepareForReactOS(IN BOOLEAN Setup)
95 {
96 return;
97 }
98
99 BOOLEAN
100 ArmDiskGetBootPath(OUT PCHAR BootPath, IN ULONG Size)
101 {
102 PCCH Path = "ramdisk(0)";
103
104 /* Make sure enough space exists */
105 if (Size < sizeof(Path)) return FALSE;
106
107 /* On ARM platforms, the loader is always in RAM */
108 strcpy(BootPath, Path);
109 return TRUE;
110 }
111
112 PCONFIGURATION_COMPONENT_DATA
113 ArmHwDetect(VOID)
114 {
115 ARM_CACHE_REGISTER CacheReg;
116
117 /* Create the root node */
118 if (ArmHwDetectRan++) return RootNode;
119 FldrCreateSystemKey(&RootNode);
120
121 /*
122 * TODO:
123 * There's no such thing as "PnP" on embedded hardware.
124 * The boot loader will send us a device tree, similar to ACPI
125 * or OpenFirmware device trees, and we will convert it to ARC.
126 */
127
128 /* Get cache information */
129 CacheReg = KeArmCacheRegisterGet();
130 FirstLevelDcacheSize = SizeBits[CacheReg.DSize];
131 FirstLevelDcacheFillSize = LenBits[CacheReg.DLength];
132 FirstLevelDcacheFillSize <<= 2;
133 FirstLevelIcacheSize = SizeBits[CacheReg.ISize];
134 FirstLevelIcacheFillSize = LenBits[CacheReg.ILength];
135 FirstLevelIcacheFillSize <<= 2;
136 SecondLevelDcacheSize =
137 SecondLevelDcacheFillSize =
138 SecondLevelIcacheSize =
139 SecondLevelIcacheFillSize = 0;
140
141 /* Register RAMDISK Device */
142 RamDiskInitialize();
143
144 /* Fill out the ARC disk block */
145 reactos_arc_disk_info[reactos_disk_count].DiskSignature.Signature = 0xBADAB00F;
146 reactos_arc_disk_info[reactos_disk_count].DiskSignature.CheckSum = 0xDEADBABE;
147 strcpy(reactos_arc_disk_info[reactos_disk_count].ArcName, "ramdisk(0)");
148 reactos_arc_disk_info[reactos_disk_count].DiskSignature.ArcName =
149 reactos_arc_disk_info[reactos_disk_count].ArcName;
150 reactos_disk_count++;
151 ASSERT(reactos_disk_count == 1);
152
153 /* Return the root node */
154 return RootNode;
155 }
156
157 BOOLEAN
158 ArmInitializeBootDevices(VOID)
159 {
160 /* Emulate old behavior */
161 return (ArmHwDetect() != NULL);
162 }
163
164 FREELDR_MEMORY_DESCRIPTOR ArmMemoryMap[32];
165
166 PFREELDR_MEMORY_DESCRIPTOR
167 ArmMemGetMemoryMap(OUT ULONG *MemoryMapSize)
168 {
169 ULONG i;
170 ASSERT(ArmBoardBlock->MemoryMapEntryCount <= 32);
171
172 /* Return whatever the board returned to us (CS0 Base + Size and FLASH0) */
173 for (i = 0; i < ArmBoardBlock->MemoryMapEntryCount; i++)
174 {
175 ArmMemoryMap[i].BasePage = ArmBoardBlock->MemoryMap[i].BaseAddress / PAGE_SIZE;
176 ArmMemoryMap[i].PageCount = ArmBoardBlock->MemoryMap[i].Length / PAGE_SIZE;
177 if (ArmBoardBlock->MemoryMap[i].Type == BiosMemoryUsable)
178 ArmMemoryMap[i].MemoryType = MemoryFree;
179 else
180 ArmMemoryMap[i].MemoryType = MemoryFirmwarePermanent;
181 }
182
183 *MemoryMapSize = ArmBoardBlock->MemoryMapEntryCount;
184
185 // FIXME
186 return NULL;
187 }
188
189 VOID
190 ArmHwIdle(VOID)
191 {
192 /* UNIMPLEMENTED */
193 }
194
195 VOID
196 MachInit(IN PCCH CommandLine)
197 {
198 /* Copy Machine Routines from Firmware Table */
199 MachVtbl.ConsPutChar = ArmBoardBlock->ConsPutChar;
200 MachVtbl.ConsKbHit = ArmBoardBlock->ConsKbHit;
201 MachVtbl.ConsGetCh = ArmBoardBlock->ConsGetCh;
202 MachVtbl.VideoClearScreen = ArmBoardBlock->VideoClearScreen;
203 MachVtbl.VideoSetDisplayMode = ArmBoardBlock->VideoSetDisplayMode;
204 MachVtbl.VideoGetDisplaySize = ArmBoardBlock->VideoGetDisplaySize;
205 MachVtbl.VideoPutChar = ArmBoardBlock->VideoPutChar;
206 MachVtbl.GetTime = ArmBoardBlock->GetTime;
207
208 /* Setup board-specific ARM routines */
209 switch (ArmBoardBlock->BoardType)
210 {
211 /* Check for Feroceon-base boards */
212 case MACH_TYPE_FEROCEON:
213 TuiPrintf("Not implemented\n");
214 while (TRUE);
215 break;
216
217 /* Check for TI OMAP3 ZOOM-II MDK */
218 case MACH_TYPE_OMAP_ZOOM2:
219
220 /* Setup the disk and file system buffers */
221 gDiskReadBuffer = 0x81094000;
222 gFileSysBuffer = 0x81094000;
223 break;
224
225 /* Check for ARM Versatile PB boards */
226 case MACH_TYPE_VERSATILE_PB:
227
228 /* Setup the disk and file system buffers */
229 gDiskReadBuffer = 0x00090000;
230 gFileSysBuffer = 0x00090000;
231 break;
232
233 /* Check for TI OMAP3 Beagleboard */
234 case MACH_TYPE_OMAP3_BEAGLE:
235 TuiPrintf("Not implemented\n");
236 while (TRUE);
237 break;
238
239 default:
240 ASSERT(FALSE);
241 }
242
243 /* Setup generic ARM routines for all boards */
244 MachVtbl.PrepareForReactOS = ArmPrepareForReactOS;
245 MachVtbl.GetMemoryMap = ArmMemGetMemoryMap;
246 MachVtbl.InitializeBootDevices = ArmInitializeBootDevices;
247 MachVtbl.HwDetect = ArmHwDetect;
248 MachVtbl.DiskGetBootPath = ArmDiskGetBootPath;
249 MachVtbl.HwIdle = ArmHwIdle;
250 }