14505959b73940f81a866a7bf30ef48f523167bb
[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 ULONG gDiskReadBuffer, gFileSysBuffer;
24
25 /* FUNCTIONS ******************************************************************/
26
27 VOID
28 ArmInit(IN PARM_BOARD_CONFIGURATION_BLOCK BootContext)
29 {
30 ULONG i;
31
32 //
33 // Remember the pointer
34 //
35 ArmBoardBlock = BootContext;
36
37 //
38 // Let's make sure we understand the LLB
39 //
40 ASSERT(ArmBoardBlock->MajorVersion == ARM_BOARD_CONFIGURATION_MAJOR_VERSION);
41 ASSERT(ArmBoardBlock->MinorVersion == ARM_BOARD_CONFIGURATION_MINOR_VERSION);
42
43 //
44 // This should probably go away once we support more boards
45 //
46 ASSERT((ArmBoardBlock->BoardType == MACH_TYPE_FEROCEON) ||
47 (ArmBoardBlock->BoardType == MACH_TYPE_VERSATILE_PB) ||
48 (ArmBoardBlock->BoardType == MACH_TYPE_OMAP3_BEAGLE));
49
50 //
51 // Save data required for memory initialization
52 //
53 ArmBoardMemoryMapRangeCount = ArmBoardBlock->MemoryMapEntryCount;
54 ASSERT(ArmBoardMemoryMapRangeCount != 0);
55 ASSERT(ArmBoardMemoryMapRangeCount < 16);
56 for (i = 0; i < ArmBoardMemoryMapRangeCount; i++)
57 {
58 //
59 // Copy each entry
60 //
61 RtlCopyMemory(&ArmBoardMemoryMap[i],
62 &ArmBoardBlock->MemoryMap[i],
63 sizeof(ADDRESS_RANGE));
64 }
65
66 //
67 // Call FreeLDR's portable entrypoint with our command-line
68 //
69 BootMain(ArmBoardBlock->CommandLine);
70 }
71
72 BOOLEAN
73 ArmDiskNormalizeSystemPath(IN OUT PCHAR SystemPath,
74 IN unsigned Size)
75 {
76 TuiPrintf("Called: %s\n", SystemPath);
77 while (TRUE);
78 return TRUE;
79 }
80
81 BOOLEAN
82 ArmDiskGetBootPath(OUT PCHAR BootPath,
83 IN unsigned Size)
84 {
85 PCCH Path = "ramdisk(0)";
86
87 /* Make sure enough space exists */
88 if (Size < sizeof(Path)) return FALSE;
89
90 /* On ARM platforms, the loader is always in RAM */
91 strcpy(BootPath, Path);
92 return TRUE;
93 }
94
95 PCONFIGURATION_COMPONENT_DATA
96 ArmHwDetect(VOID)
97 {
98 PCONFIGURATION_COMPONENT_DATA RootNode;
99
100 //
101 // Create the root node
102 //
103 FldrCreateSystemKey(&RootNode);
104
105 //
106 // TODO:
107 // There's no such thing as "PnP" on embedded hardware.
108 // The boot loader will send us a device tree, similar to ACPI
109 // or OpenFirmware device trees, and we will convert it to ARC.
110 //
111
112 //
113 // Register RAMDISK Device
114 //
115 RamDiskInitialize();
116
117 //
118 // Return the root node
119 //
120 return RootNode;
121 }
122
123 ULONG
124 ArmMemGetMemoryMap(OUT PBIOS_MEMORY_MAP BiosMemoryMap,
125 IN ULONG MaxMemoryMapSize)
126 {
127 //
128 // Return whatever the board returned to us (CS0 Base + Size and FLASH0)
129 //
130 RtlCopyMemory(BiosMemoryMap,
131 ArmBoardBlock->MemoryMap,
132 ArmBoardBlock->MemoryMapEntryCount * sizeof(BIOS_MEMORY_MAP));
133 return ArmBoardBlock->MemoryMapEntryCount;
134 }
135
136 VOID
137 MachInit(IN PCCH CommandLine)
138 {
139 //
140 // Setup board-specific ARM routines
141 //
142 switch (ArmBoardBlock->BoardType)
143 {
144 //
145 // Check for Feroceon-base boards
146 //
147 case MACH_TYPE_FEROCEON:
148 TuiPrintf("Not implemented\n");
149 while (TRUE);
150 break;
151
152 //
153 // Check for ARM Versatile PB boards
154 //
155 case MACH_TYPE_VERSATILE_PB:
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.VideoGetBufferSize = ArmBoardBlock->VideoGetBufferSize;
165 MachVtbl.VideoSetTextCursorPosition = ArmBoardBlock->VideoSetTextCursorPosition;
166 MachVtbl.VideoSetTextCursorPosition = ArmBoardBlock->VideoSetTextCursorPosition;
167 MachVtbl.VideoHideShowTextCursor = ArmBoardBlock->VideoHideShowTextCursor;
168 MachVtbl.VideoPutChar = ArmBoardBlock->VideoPutChar;
169 MachVtbl.VideoCopyOffScreenBufferToVRAM = ArmBoardBlock->VideoCopyOffScreenBufferToVRAM;
170 MachVtbl.VideoIsPaletteFixed = ArmBoardBlock->VideoIsPaletteFixed;
171 MachVtbl.VideoSetPaletteColor = ArmBoardBlock->VideoSetPaletteColor;
172 MachVtbl.VideoGetPaletteColor = ArmBoardBlock->VideoGetPaletteColor;
173 MachVtbl.VideoSync = ArmBoardBlock->VideoSync;
174
175 /* Setup the disk and file system buffers */
176 gDiskReadBuffer = 0x00090000;
177 gFileSysBuffer = 0x00090000;
178 break;
179
180 //
181 // Check for TI OMAP3 boards
182 // For now that means only Beagle, but ZOOM and others should be ok too
183 //
184 case MACH_TYPE_OMAP3_BEAGLE:
185 TuiPrintf("Not implemented\n");
186 while (TRUE);
187 break;
188
189 default:
190 ASSERT(FALSE);
191 }
192
193 //
194 // Setup generic ARM routines for all boards
195 //
196 MachVtbl.PrepareForReactOS = ArmPrepareForReactOS;
197 MachVtbl.GetMemoryMap = ArmMemGetMemoryMap;
198 MachVtbl.HwDetect = ArmHwDetect;
199
200 //
201 // Setup disk I/O routines
202 //
203 MachVtbl.DiskGetBootPath = ArmDiskGetBootPath;
204 MachVtbl.DiskNormalizeSystemPath = ArmDiskNormalizeSystemPath;
205
206 //
207 // We can now print to the console
208 //
209 TuiPrintf("%s for ARM\n", GetFreeLoaderVersionString());
210 TuiPrintf("Bootargs: %s\n\n", CommandLine);
211 }