c636a0a9fe056366ed9c75fa5622f20eeb61a9e6
[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
13 /* GLOBALS ********************************************************************/
14
15 UCHAR BootStack[0x4000];
16 PUCHAR BootStackEnd = &BootStack[0x3FFF];
17 PARM_BOARD_CONFIGURATION_BLOCK ArmBoardBlock;
18 ULONG BootDrive, BootPartition;
19 VOID ArmPrepareForReactOS(IN BOOLEAN Setup);
20 ADDRESS_RANGE ArmBoardMemoryMap[16];
21 ULONG ArmBoardMemoryMapRangeCount;
22
23 /* FUNCTIONS ******************************************************************/
24
25 VOID
26 ArmInit(IN PARM_BOARD_CONFIGURATION_BLOCK BootContext)
27 {
28 ULONG i;
29
30 //
31 // Remember the pointer
32 //
33 ArmBoardBlock = BootContext;
34
35 //
36 // Let's make sure we understand the boot-loader
37 //
38 ASSERT(ArmBoardBlock->MajorVersion == ARM_BOARD_CONFIGURATION_MAJOR_VERSION);
39 ASSERT(ArmBoardBlock->MinorVersion == ARM_BOARD_CONFIGURATION_MINOR_VERSION);
40
41 //
42 // This should probably go away once we support more boards
43 //
44 ASSERT((ArmBoardBlock->BoardType == MACH_TYPE_FEROCEON) ||
45 (ArmBoardBlock->BoardType == MACH_TYPE_VERSATILE_PB) ||
46 (ArmBoardBlock->BoardType == MACH_TYPE_OMAP3_BEAGLE));
47
48 //
49 // Save data required for memory initialization
50 //
51 ArmBoardMemoryMapRangeCount = ArmBoardBlock->MemoryMapEntryCount;
52 ASSERT(ArmBoardMemoryMapRangeCount != 0);
53 ASSERT(ArmBoardMemoryMapRangeCount < 16);
54 for (i = 0; i < ArmBoardMemoryMapRangeCount; i++)
55 {
56 //
57 // Copy each entry
58 //
59 RtlCopyMemory(&ArmBoardMemoryMap[i],
60 &ArmBoardBlock->MemoryMap[i],
61 sizeof(ADDRESS_RANGE));
62 }
63
64 //
65 // Call FreeLDR's portable entrypoint with our command-line
66 //
67 BootMain(ArmBoardBlock->CommandLine);
68 }
69
70 BOOLEAN
71 ArmDiskGetDriveGeometry(IN ULONG DriveNumber,
72 OUT PGEOMETRY Geometry)
73 {
74 return FALSE;
75 }
76
77 BOOLEAN
78 ArmDiskReadLogicalSectors(IN ULONG DriveNumber,
79 IN ULONGLONG SectorNumber,
80 IN ULONG SectorCount,
81 IN PVOID Buffer)
82 {
83 return FALSE;
84 }
85
86 ULONG
87 ArmDiskGetCacheableBlockCount(IN ULONG DriveNumber)
88 {
89 return 0;
90 }
91
92 PCONFIGURATION_COMPONENT_DATA
93 ArmHwDetect(VOID)
94 {
95 PCONFIGURATION_COMPONENT_DATA RootNode;
96
97 //
98 // Create the root node
99 //
100 FldrCreateSystemKey(&RootNode);
101
102 //
103 // TODO:
104 // There's no such thing as "PnP" on embedded hardware.
105 // The boot loader will send us a device tree, similar to ACPI
106 // or OpenFirmware device trees, and we will convert it to ARC.
107 //
108
109 //
110 // Return the root node
111 //
112 return RootNode;
113 }
114
115 ULONG
116 ArmMemGetMemoryMap(OUT PBIOS_MEMORY_MAP BiosMemoryMap,
117 IN ULONG MaxMemoryMapSize)
118 {
119 //
120 // Return whatever the board returned to us (CS0 Base + Size and FLASH0)
121 //
122 RtlCopyMemory(BiosMemoryMap,
123 ArmBoardBlock->MemoryMap,
124 ArmBoardBlock->MemoryMapEntryCount * sizeof(BIOS_MEMORY_MAP));
125 return ArmBoardBlock->MemoryMapEntryCount;
126 }
127
128 VOID
129 MachInit(IN PCCH CommandLine)
130 {
131 //
132 // Setup board-specific ARM routines
133 //
134 switch (ArmBoardBlock->BoardType)
135 {
136 //
137 // Check for Feroceon-base boards
138 //
139 case MACH_TYPE_FEROCEON:
140
141 //
142 // These boards use a UART16550. Set us up for 115200 bps
143 //
144 ArmFeroSerialInit(115200);
145 MachVtbl.ConsPutChar = ArmFeroPutChar;
146 MachVtbl.ConsKbHit = ArmFeroKbHit;
147 MachVtbl.ConsGetCh = ArmFeroGetCh;
148 break;
149
150 //
151 // Check for ARM Versatile PB boards
152 //
153 case MACH_TYPE_VERSATILE_PB:
154
155 //
156 // These boards use a PrimeCell UART (PL011)
157 //
158 ArmVersaSerialInit(115200);
159 MachVtbl.ConsPutChar = ArmVersaPutChar;
160 MachVtbl.ConsKbHit = ArmVersaKbHit;
161 MachVtbl.ConsGetCh = ArmVersaGetCh;
162 break;
163
164 //
165 // Check for TI OMAP3 boards
166 // For now that means only Beagle, but ZOOM and others should be ok too
167 //
168 case MACH_TYPE_OMAP3_BEAGLE:
169
170 //
171 // These boards use a UART16550
172 //
173 ArmOmap3SerialInit(115200);
174 MachVtbl.ConsPutChar = ArmOmap3PutChar;
175 MachVtbl.ConsKbHit = ArmOmap3KbHit;
176 MachVtbl.ConsGetCh = ArmOmap3GetCh;
177 break;
178
179 default:
180 ASSERT(FALSE);
181 }
182
183 //
184 // Setup generic ARM routines for all boards
185 //
186 MachVtbl.PrepareForReactOS = ArmPrepareForReactOS;
187 MachVtbl.GetMemoryMap = ArmMemGetMemoryMap;
188 MachVtbl.HwDetect = ArmHwDetect;
189
190 //
191 // Setup disk I/O routines
192 //
193 MachVtbl.DiskReadLogicalSectors = ArmDiskReadLogicalSectors;
194 MachVtbl.DiskGetDriveGeometry = ArmDiskGetDriveGeometry;
195 MachVtbl.DiskGetCacheableBlockCount = ArmDiskGetCacheableBlockCount;
196
197 //
198 // Now set default disk handling routines -- we don't need to override
199 //
200 MachVtbl.DiskGetBootPath = DiskGetBootPath;
201 MachVtbl.DiskNormalizeSystemPath = DiskNormalizeSystemPath;
202
203 //
204 // We can now print to the console
205 //
206 TuiPrintf("%s for ARM\n", GetFreeLoaderVersionString());
207 TuiPrintf("Bootargs: %s\n", CommandLine);
208 }