- Flesh out more code.
authorevb <evb@svn.reactos.org>
Wed, 3 Feb 2010 03:14:59 +0000 (03:14 +0000)
committerevb <evb@svn.reactos.org>
Wed, 3 Feb 2010 03:14:59 +0000 (03:14 +0000)
- Support ATAG Linux/ARMBoot architecture defined-structures. These are used by all ARMBoot-compatible loaders (QEmu, U-boot, etc).
- Read RAMDisk, RAM, Command Line from ATAGs (use -append boot-device=RAMDISK).
- Make environment-get function read command-line.
- Allocate RAM memory structure portably.
- Validate board info on boot.

svn path=/trunk/; revision=45386

reactos/boot/armllb/envir.c
reactos/boot/armllb/hw/versatile/hwinfo.c
reactos/boot/armllb/hw/versatile/hwinit.c
reactos/boot/armllb/inc/envir.h [new file with mode: 0755]
reactos/boot/armllb/inc/osloader.h
reactos/boot/armllb/inc/precomp.h
reactos/boot/armllb/main.c
reactos/boot/armllb/os/loader.c

index 0283947..47ff888 100644 (file)
 
 #include "precomp.h"
 
+ULONG LlbEnvHwPageSize;
+ULONG LlbEnvHwMemStart;
+ULONG LlbEnvHwMemSize;
+ULONG LlbEnvRamDiskStart;
+ULONG LlbEnvRamDiskSize;
+CHAR LlbEnvCmdLine[256];
+
+VOID
+NTAPI
+LlbEnvParseArguments(IN PATAG Arguments)
+{
+    PATAG Atag;
+    
+    /* Parse the ATAGs */
+    Atag = Arguments;
+    while (Atag->Hdr.Size)
+    {
+        /* Check tag type */
+        switch (Atag->Hdr.Tag)
+        {
+            case ATAG_CORE:
+            
+                /* Save page size */
+                LlbEnvHwPageSize = Atag->u.Core.PageSize;
+                break;
+                
+            case ATAG_MEM:
+            
+                /* Save RAM start and size */
+                LlbEnvHwMemStart = Atag->u.Mem.Start;
+                LlbEnvHwMemSize = Atag->u.Mem.Size;
+                break;
+                
+            case ATAG_INITRD2:
+            
+                /* Save RAMDISK start and size */
+                LlbEnvRamDiskStart = Atag->u.InitRd2.Start;
+                LlbEnvRamDiskSize = Atag->u.InitRd2.Size;
+                break;
+                
+            case ATAG_CMDLINE:
+            
+                /* Save command line */
+                strncpy(LlbEnvCmdLine,
+                        Atag->u.CmdLine.CmdLine,
+                        Atag->Hdr.Size * sizeof(ULONG));
+                break;
+                
+            /* Nothing left to handle */
+            case ATAG_NONE:
+            default:
+                return;
+        }
+        
+        /* Next tag */
+        Atag = (PATAG)((PULONG)Atag + Atag->Hdr.Size);
+    }
+    
+    /* For debugging */
+    DbgPrint("[BOOTROM] PageSize: %dKB RAM: %dMB CMDLINE: %s\n",
+             LlbEnvHwPageSize / 1024, LlbEnvHwMemSize / 1024 / 1024, LlbEnvCmdLine);
+}
+
+VOID
+NTAPI
+LlbEnvGetMemoryInformation(IN PULONG Base,
+                           IN PULONG Size)
+{
+    /* Return RAM information */
+    *Base = LlbEnvHwMemStart;
+    *Size = LlbEnvHwMemSize;
+}
+
+BOOLEAN
+NTAPI
+LlbEnvGetRamDiskInformation(IN PULONG Base,
+                            IN PULONG Size)
+{
+    /* Do we have a ramdisk? */
+    if (LlbEnvRamDiskSize == 0)
+    {
+        /* No */
+        *Base = 0;
+        *Size = 0;
+        return FALSE;
+    }
+    
+    /* Return ramdisk information */
+    *Base = LlbEnvRamDiskStart;
+    *Size = LlbEnvRamDiskSize;
+    return TRUE;
+}
+
 PCHAR
 NTAPI
 LlbEnvRead(IN PCHAR ValueName)
 {
-    /* FIXME: HACK */
-    return "RAMDISK";
+    PCHAR ValueData;
+    
+    /* Search for the value name */
+    ValueData = strstr(LlbEnvCmdLine, ValueName);
+    if (ValueData) ValueData += strlen(ValueName) + 1;
+
+    /* Return the data */
+    return ValueData;
 }
 
 /* EOF */
index edac411..5c2c0b8 100755 (executable)
@@ -40,9 +40,6 @@ VOID
 NTAPI
 LlbHwBuildMemoryMap(IN PBIOS_MEMORY_MAP MemoryMap)
 {
-    /* For now, hard-code 128MB of RAM starting at 0x00000000 */
-    LlbAllocateMemoryEntry(BiosMemoryUsable, 0x00000000, 128 * 1024 * 1024);
-    
     /* Mark MMIO space as reserved */
     LlbAllocateMemoryEntry(BiosMemoryReserved, 0x10000000, 128 * 1024 * 1024);
 }
index 6aa73e6..184caca 100755 (executable)
@@ -29,8 +29,11 @@ POSLOADER_INIT
 NTAPI
 LlbHwLoadOsLoaderFromRam(VOID)
 {
-    /* The OS Loader should have already been loaded by QEMU at the right place */
-    return (POSLOADER_INIT)0x800000;
+    ULONG Base, Dummy;
+    
+    /* On versatile, the loader is loaded with the RAMDISK. Just get the address */
+    LlbEnvGetRamDiskInformation(&Base, &Dummy);
+    return (POSLOADER_INIT)Base;
 }
 
 
diff --git a/reactos/boot/armllb/inc/envir.h b/reactos/boot/armllb/inc/envir.h
new file mode 100755 (executable)
index 0000000..590f32f
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * PROJECT:         ReactOS Boot Loader
+ * LICENSE:         BSD - See COPYING.ARM in the top level directory
+ * FILE:            boot/armllb/inc/envir.h
+ * PURPOSE:         LLB Environment Functions
+ * PROGRAMMERS:     ReactOS Portable Systems Group
+ */
+
+typedef struct _ATAG_HEADER
+{
+    ULONG Size;
+    ULONG Tag;
+} ATAG_HEADER, *PATAG_HEADER;
+
+typedef struct _ATAG_CORE
+{
+    ULONG Flags;
+    ULONG PageSize;
+    ULONG RootDev;
+} ATAG_CORE, *PATAG_CORE;
+
+typedef struct _ATAG_MEM
+{
+    ULONG Size;
+    ULONG Start;
+} ATAG_MEM, *PATAG_MEM;
+
+typedef struct _ATAG_INITRD2
+{
+    ULONG Start;
+    ULONG Size;
+} ATAG_INITRD2, *PATAG_INITRD2;
+
+typedef struct _ATAG_CMDLINE
+{
+    CHAR CmdLine[ANYSIZE_ARRAY];
+} ATAG_CMDLINE, *PATAG_CMDLINE;
+
+typedef struct _ATAG
+{
+    ATAG_HEADER Hdr;
+    union
+    {
+        ATAG_CORE Core;
+        ATAG_MEM Mem;
+        ATAG_INITRD2 InitRd2;
+        ATAG_CMDLINE CmdLine;
+    } u;
+} ATAG, *PATAG;
+
+#define ATAG_NONE       0x00000000
+#define ATAG_CORE       0x54410001
+#define ATAG_MEM        0x54410002
+#define ATAG_VIDEOTEXT  0x54410003
+#define ATAG_RAMDISK    0x54410004
+#define ATAG_INITRD2    0x54420005
+#define ATAG_SERIAL     0x54410006
+#define ATAG_REVISION   0x54410007
+#define ATAG_VIDEOLFB   0x54410008
+#define ATAG_CMDLINE    0x54410009
+
+PCHAR
+NTAPI
+LlbEnvRead(
+    IN PCHAR Option
+);
+
+BOOLEAN
+NTAPI
+LlbEnvGetRamDiskInformation(
+    IN PULONG Base,
+    IN PULONG Size
+);
+
+VOID
+NTAPI
+LlbEnvGetMemoryInformation(
+    IN PULONG Base,
+    IN PULONG Size
+);
+
+VOID
+NTAPI
+LlbEnvParseArguments(
+    IN PATAG Arguments
+);
+
+/* EOF */
index 41b9c8f..291625e 100644 (file)
@@ -97,10 +97,4 @@ LlbBoot(
     IN PCHAR CommandLine
 );
 
-PCHAR
-NTAPI
-LlbEnvRead(
-    IN PCHAR Option
-);
-
 /* EOF */
index ce2a637..bda644b 100755 (executable)
@@ -16,6 +16,7 @@
 #include "serial.h"
 #include "video.h"
 #include "keyboard.h"
+#include "envir.h"
 
 VOID
 DbgPrint(
index 7248cbc..2931deb 100755 (executable)
@@ -9,8 +9,16 @@
 #include "precomp.h"
 
 VOID
-LlbStartup(VOID)
+LlbStartup(IN ULONG Reserved,
+           IN ULONG BoardInfo,
+           IN PATAG Arguments)
 {
+    /* Make sure we are booting on the correct kind of machine */
+    if (BoardInfo != LlbHwGetBoardType()) while (TRUE);
+
+    /* Either QEMU or U-Boot itself should send this information */
+    LlbEnvParseArguments(Arguments);
+    
     /* Initialize hardware components */
     LlbHwInitialize();
 
index acb6984..0853ff0 100755 (executable)
@@ -38,7 +38,6 @@ NTAPI
 LlbSetCommandLine(IN PCHAR CommandLine)
 {
     /* Copy the command line in the ARM block */
-    printf("Command Line %s\n", CommandLine);
     strcpy(ArmBlock.CommandLine, CommandLine);
 }
 
@@ -61,11 +60,11 @@ LlbBuildArmBlock(VOID)
     ArmBlock.UartRegisterBase = LlbHwGetUartBase(LlbHwGetSerialUart());
     
     /* Debug */
-    printf("Machine Identifier: %lx\nPCLK: %d\nTIMER 0: %p\nSERIAL UART: %p\n",
-            ArmBlock.BoardType,
-            ArmBlock.ClockRate,
-            ArmBlock.TimerRegisterBase,
-            ArmBlock.UartRegisterBase);
+    DbgPrint("Machine Identifier: %lx\nPCLK: %d\nTIMER 0: %p\nSERIAL UART: %p\n",
+             ArmBlock.BoardType,
+             ArmBlock.ClockRate,
+             ArmBlock.TimerRegisterBase,
+             ArmBlock.UartRegisterBase);
     
     /* Now load the memory map */
     ArmBlock.MemoryMap = MemoryMap;
@@ -80,10 +79,16 @@ VOID
 NTAPI
 LlbBuildMemoryMap(VOID)
 {
+    ULONG Base, Size;
+    
     /* Zero out the memory map */
     memset(MemoryMap, 0, sizeof(MemoryMap));
+        
+    /* Query memory information */
+    LlbEnvGetMemoryInformation(&Base, &Size);
+    LlbAllocateMemoryEntry(BiosMemoryUsable, Base, Size);
 
-    /* Call the hardware-specific function */
+    /* Call the hardware-specific function for hardware-defined regions */
     LlbHwBuildMemoryMap(MemoryMap);
 }