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