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