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