- Change ARM loading architecture to match EFI/Firmware model. LLB provides "firmware...
[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 #define RGB565(r, g, b) (((r >> 3) << 11)| ((g >> 2) << 5)| ((b >> 3) << 0))
13
14 /* GLOBALS ********************************************************************/
15
16 UCHAR BootStack[0x4000];
17 PUCHAR BootStackEnd = &BootStack[0x3FFF];
18 PARM_BOARD_CONFIGURATION_BLOCK ArmBoardBlock;
19 ULONG BootDrive, BootPartition;
20 VOID ArmPrepareForReactOS(IN BOOLEAN Setup);
21 ADDRESS_RANGE ArmBoardMemoryMap[16];
22 ULONG ArmBoardMemoryMapRangeCount;
23
24 /* FUNCTIONS ******************************************************************/
25
26 VOID
27 ArmInit(IN PARM_BOARD_CONFIGURATION_BLOCK BootContext)
28 {
29 ULONG i;
30
31 //
32 // Remember the pointer
33 //
34 ArmBoardBlock = BootContext;
35
36 //
37 // Let's make sure we understand the LLB
38 //
39 ASSERT(ArmBoardBlock->MajorVersion == ARM_BOARD_CONFIGURATION_MAJOR_VERSION);
40 ASSERT(ArmBoardBlock->MinorVersion == ARM_BOARD_CONFIGURATION_MINOR_VERSION);
41
42 //
43 // This should probably go away once we support more boards
44 //
45 ASSERT((ArmBoardBlock->BoardType == MACH_TYPE_FEROCEON) ||
46 (ArmBoardBlock->BoardType == MACH_TYPE_VERSATILE_PB) ||
47 (ArmBoardBlock->BoardType == MACH_TYPE_OMAP3_BEAGLE));
48
49 //
50 // Save data required for memory initialization
51 //
52 ArmBoardMemoryMapRangeCount = ArmBoardBlock->MemoryMapEntryCount;
53 ASSERT(ArmBoardMemoryMapRangeCount != 0);
54 ASSERT(ArmBoardMemoryMapRangeCount < 16);
55 for (i = 0; i < ArmBoardMemoryMapRangeCount; i++)
56 {
57 //
58 // Copy each entry
59 //
60 RtlCopyMemory(&ArmBoardMemoryMap[i],
61 &ArmBoardBlock->MemoryMap[i],
62 sizeof(ADDRESS_RANGE));
63 }
64
65 //
66 // Call FreeLDR's portable entrypoint with our command-line
67 //
68 BootMain(ArmBoardBlock->CommandLine);
69 }
70
71 BOOLEAN
72 ArmDiskGetDriveGeometry(IN ULONG DriveNumber,
73 OUT PGEOMETRY Geometry)
74 {
75 return FALSE;
76 }
77
78 BOOLEAN
79 ArmDiskReadLogicalSectors(IN ULONG DriveNumber,
80 IN ULONGLONG SectorNumber,
81 IN ULONG SectorCount,
82 IN PVOID Buffer)
83 {
84 return FALSE;
85 }
86
87 ULONG
88 ArmDiskGetCacheableBlockCount(IN ULONG DriveNumber)
89 {
90 return 0;
91 }
92
93 PCONFIGURATION_COMPONENT_DATA
94 ArmHwDetect(VOID)
95 {
96 PCONFIGURATION_COMPONENT_DATA RootNode;
97
98 //
99 // Create the root node
100 //
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 //
111 // Return the root node
112 //
113 return RootNode;
114 }
115
116 ULONG
117 ArmMemGetMemoryMap(OUT PBIOS_MEMORY_MAP BiosMemoryMap,
118 IN ULONG MaxMemoryMapSize)
119 {
120 //
121 // Return whatever the board returned to us (CS0 Base + Size and FLASH0)
122 //
123 RtlCopyMemory(BiosMemoryMap,
124 ArmBoardBlock->MemoryMap,
125 ArmBoardBlock->MemoryMapEntryCount * sizeof(BIOS_MEMORY_MAP));
126 return ArmBoardBlock->MemoryMapEntryCount;
127 }
128
129 VOID
130 MachInit(IN PCCH CommandLine)
131 {
132 //
133 // Setup board-specific ARM routines
134 //
135 switch (ArmBoardBlock->BoardType)
136 {
137 //
138 // Check for Feroceon-base boards
139 //
140 case MACH_TYPE_FEROCEON:
141 break;
142
143 //
144 // Check for ARM Versatile PB boards
145 //
146 case MACH_TYPE_VERSATILE_PB:
147
148 /* Copy Machine Routines from Firmware Table */
149 MachVtbl.ConsPutChar = ArmBoardBlock->ConsPutChar;
150 MachVtbl.ConsKbHit = ArmBoardBlock->ConsKbHit;
151 MachVtbl.ConsGetCh = ArmBoardBlock->ConsGetCh;
152 break;
153
154 //
155 // Check for TI OMAP3 boards
156 // For now that means only Beagle, but ZOOM and others should be ok too
157 //
158 case MACH_TYPE_OMAP3_BEAGLE:
159 break;
160
161 default:
162 ASSERT(FALSE);
163 }
164
165 //
166 // Setup generic ARM routines for all boards
167 //
168 MachVtbl.PrepareForReactOS = ArmPrepareForReactOS;
169 MachVtbl.GetMemoryMap = ArmMemGetMemoryMap;
170 MachVtbl.HwDetect = ArmHwDetect;
171
172 //
173 // Setup disk I/O routines
174 //
175 MachVtbl.DiskReadLogicalSectors = ArmDiskReadLogicalSectors;
176 MachVtbl.DiskGetDriveGeometry = ArmDiskGetDriveGeometry;
177 MachVtbl.DiskGetCacheableBlockCount = ArmDiskGetCacheableBlockCount;
178
179 //
180 // Now set default disk handling routines -- we don't need to override
181 //
182 MachVtbl.DiskGetBootPath = DiskGetBootPath;
183 MachVtbl.DiskNormalizeSystemPath = DiskNormalizeSystemPath;
184
185 //
186 // We can now print to the console
187 //
188 TuiPrintf("%s for ARM\n", GetFreeLoaderVersionString());
189 TuiPrintf("Bootargs: %s\n\n", CommandLine);
190 }