- Add stubs for video mach functions and update minor to 1.3.
[reactos.git] / reactos / boot / freeldr / freeldr / arch / arm / macharm.c
index d95ed54..1450595 100644 (file)
@@ -1,59 +1,41 @@
 /*
  * PROJECT:         ReactOS Boot Loader
- * LICENSE:         GPL - See COPYING in the top level directory
+ * LICENSE:         BSD - See COPYING.ARM in the top level directory
  * FILE:            boot/freeldr/arch/arm/marcharm.c
- * PURPOSE:         Implements ARM-specific machine initialization
- * PROGRAMMERS:     alex@winsiderss.com
+ * PURPOSE:         Provides abstraction between the ARM Boot Loader and FreeLDR
+ * PROGRAMMERS:     ReactOS Portable Systems Group
  */
 
 /* INCLUDES *******************************************************************/
 
 #include <freeldr.h>
+#define RGB565(r, g, b) (((r >> 3) << 11)| ((g >> 2) << 5)| ((b >> 3) << 0))
 
 /* GLOBALS ********************************************************************/
 
-//
-// The only things we support
-//
-typedef enum _ARM_BOARD_TYPE
-{
-    //
-    // Marvell Feroceon-based SoC:
-    // Buffalo Linkstation, KuroBox Pro, D-Link DS323 and others
-    //
-    ARM_FEROCEON = 1,
-} ARM_BOARD_TYPE;
-
-//
-// Compatible boot-loaders should return us this information
-//
-#define ARM_BOARD_CONFIGURATION_MAJOR_VERSION 1
-#define ARM_BOARD_CONFIGURATION_MINOR_VERSION 1
-typedef struct _ARM_BOARD_CONFIGURATION_BLOCK
-{
-    ULONG MajorVersion;
-    ULONG MinorVersion;
-    ARM_BOARD_TYPE BoardType;
-    ULONG TimerRegisterBase;
-    ULONG UartRegisterBase;
-    PBIOS_MEMORY_MAP MemoryMap;
-    CHAR CommandLine[256];
-} ARM_BOARD_CONFIGURATION_BLOCK, *PARM_BOARD_CONFIGURATION_BLOCK;
+UCHAR BootStack[0x4000];
+PUCHAR BootStackEnd = &BootStack[0x3FFF];
+PARM_BOARD_CONFIGURATION_BLOCK ArmBoardBlock;
+ULONG BootDrive, BootPartition;
+VOID ArmPrepareForReactOS(IN BOOLEAN Setup);
+ADDRESS_RANGE ArmBoardMemoryMap[16];
+ULONG ArmBoardMemoryMapRangeCount;
+ULONG gDiskReadBuffer, gFileSysBuffer;
 
 /* FUNCTIONS ******************************************************************/
 
-PARM_BOARD_CONFIGURATION_BLOCK ArmBoardBlock;
-
 VOID
 ArmInit(IN PARM_BOARD_CONFIGURATION_BLOCK BootContext)
 {
+    ULONG i;
+
     //
     // Remember the pointer
     //
     ArmBoardBlock = BootContext;
     
     //
-    // Let's make sure we understand the boot-loader
+    // Let's make sure we understand the LLB
     //
     ASSERT(ArmBoardBlock->MajorVersion == ARM_BOARD_CONFIGURATION_MAJOR_VERSION);
     ASSERT(ArmBoardBlock->MinorVersion == ARM_BOARD_CONFIGURATION_MINOR_VERSION);
@@ -61,7 +43,25 @@ ArmInit(IN PARM_BOARD_CONFIGURATION_BLOCK BootContext)
     //
     // This should probably go away once we support more boards
     //
-    ASSERT(ArmBoardBlock->BoardType == ARM_FEROCEON);
+    ASSERT((ArmBoardBlock->BoardType == MACH_TYPE_FEROCEON) ||
+           (ArmBoardBlock->BoardType == MACH_TYPE_VERSATILE_PB) ||
+           (ArmBoardBlock->BoardType == MACH_TYPE_OMAP3_BEAGLE));
+
+    //
+    // Save data required for memory initialization
+    //
+    ArmBoardMemoryMapRangeCount = ArmBoardBlock->MemoryMapEntryCount;
+    ASSERT(ArmBoardMemoryMapRangeCount != 0);
+    ASSERT(ArmBoardMemoryMapRangeCount < 16);
+    for (i = 0; i < ArmBoardMemoryMapRangeCount; i++)
+    {
+        //
+        // Copy each entry
+        //
+        RtlCopyMemory(&ArmBoardMemoryMap[i],
+                      &ArmBoardBlock->MemoryMap[i],
+                      sizeof(ADDRESS_RANGE));
+    }
 
     //
     // Call FreeLDR's portable entrypoint with our command-line
@@ -69,3 +69,143 @@ ArmInit(IN PARM_BOARD_CONFIGURATION_BLOCK BootContext)
     BootMain(ArmBoardBlock->CommandLine);
 }
 
+BOOLEAN
+ArmDiskNormalizeSystemPath(IN OUT PCHAR SystemPath,
+                           IN unsigned Size)
+{
+    TuiPrintf("Called: %s\n", SystemPath);
+    while (TRUE);
+    return TRUE;
+}
+
+BOOLEAN
+ArmDiskGetBootPath(OUT PCHAR BootPath,
+                   IN unsigned Size)
+{
+    PCCH Path = "ramdisk(0)";
+    
+    /* Make sure enough space exists */
+    if (Size < sizeof(Path)) return FALSE;
+    
+    /* On ARM platforms, the loader is always in RAM */
+    strcpy(BootPath, Path);
+    return TRUE;
+}
+
+PCONFIGURATION_COMPONENT_DATA
+ArmHwDetect(VOID)
+{
+    PCONFIGURATION_COMPONENT_DATA RootNode;
+    
+    //
+    // Create the root node
+    //
+    FldrCreateSystemKey(&RootNode);
+    
+    //
+    // TODO:
+    // There's no such thing as "PnP" on embedded hardware.
+    // The boot loader will send us a device tree, similar to ACPI
+    // or OpenFirmware device trees, and we will convert it to ARC.
+    //
+    
+    //
+    // Register RAMDISK Device
+    //
+    RamDiskInitialize();
+    
+    //
+    // Return the root node
+    //
+    return RootNode;
+}
+
+ULONG
+ArmMemGetMemoryMap(OUT PBIOS_MEMORY_MAP BiosMemoryMap,
+                   IN ULONG MaxMemoryMapSize)
+{
+    //
+    // Return whatever the board returned to us (CS0 Base + Size and FLASH0)
+    //
+    RtlCopyMemory(BiosMemoryMap,
+                  ArmBoardBlock->MemoryMap,
+                  ArmBoardBlock->MemoryMapEntryCount * sizeof(BIOS_MEMORY_MAP));
+    return ArmBoardBlock->MemoryMapEntryCount;
+}
+
+VOID
+MachInit(IN PCCH CommandLine)
+{
+    //
+    // Setup board-specific ARM routines
+    //
+    switch (ArmBoardBlock->BoardType)
+    {
+        //
+        // Check for Feroceon-base boards
+        //
+        case MACH_TYPE_FEROCEON:
+            TuiPrintf("Not implemented\n");
+            while (TRUE);
+            break;
+            
+        //
+        // Check for ARM Versatile PB boards
+        //
+        case MACH_TYPE_VERSATILE_PB:
+            
+            /* Copy Machine Routines from Firmware Table */
+            MachVtbl.ConsPutChar = ArmBoardBlock->ConsPutChar;
+            MachVtbl.ConsKbHit = ArmBoardBlock->ConsKbHit;
+            MachVtbl.ConsGetCh = ArmBoardBlock->ConsGetCh;
+            MachVtbl.VideoClearScreen = ArmBoardBlock->VideoClearScreen;
+            MachVtbl.VideoSetDisplayMode = ArmBoardBlock->VideoSetDisplayMode;
+            MachVtbl.VideoGetDisplaySize = ArmBoardBlock->VideoGetDisplaySize;
+            MachVtbl.VideoGetBufferSize = ArmBoardBlock->VideoGetBufferSize;
+            MachVtbl.VideoSetTextCursorPosition = ArmBoardBlock->VideoSetTextCursorPosition;
+            MachVtbl.VideoSetTextCursorPosition = ArmBoardBlock->VideoSetTextCursorPosition;
+            MachVtbl.VideoHideShowTextCursor = ArmBoardBlock->VideoHideShowTextCursor;
+            MachVtbl.VideoPutChar = ArmBoardBlock->VideoPutChar;
+            MachVtbl.VideoCopyOffScreenBufferToVRAM = ArmBoardBlock->VideoCopyOffScreenBufferToVRAM;
+            MachVtbl.VideoIsPaletteFixed = ArmBoardBlock->VideoIsPaletteFixed;
+            MachVtbl.VideoSetPaletteColor = ArmBoardBlock->VideoSetPaletteColor;
+            MachVtbl.VideoGetPaletteColor = ArmBoardBlock->VideoGetPaletteColor;
+            MachVtbl.VideoSync = ArmBoardBlock->VideoSync;
+                        
+            /* Setup the disk and file system buffers */
+            gDiskReadBuffer = 0x00090000;
+            gFileSysBuffer = 0x00090000;
+            break;
+            
+        //
+        // Check for TI OMAP3 boards
+        // For now that means only Beagle, but ZOOM and others should be ok too
+        //
+        case MACH_TYPE_OMAP3_BEAGLE:
+            TuiPrintf("Not implemented\n");
+            while (TRUE);
+            break;
+            
+        default:
+            ASSERT(FALSE);
+    }
+        
+    //
+    // Setup generic ARM routines for all boards
+    //
+    MachVtbl.PrepareForReactOS = ArmPrepareForReactOS;
+    MachVtbl.GetMemoryMap = ArmMemGetMemoryMap;
+    MachVtbl.HwDetect = ArmHwDetect;
+    
+    //
+    // Setup disk I/O routines
+    //
+    MachVtbl.DiskGetBootPath = ArmDiskGetBootPath;
+    MachVtbl.DiskNormalizeSystemPath = ArmDiskNormalizeSystemPath;
+    
+    //
+    // We can now print to the console
+    //
+    TuiPrintf("%s for ARM\n", GetFreeLoaderVersionString());
+    TuiPrintf("Bootargs: %s\n\n", CommandLine);
+}