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