- Merge from trunk up to r45543
[reactos.git] / boot / armllb / envir.c
1 /*
2 * PROJECT: ReactOS Boot Loader
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: boot/armllb/envir.c
5 * PURPOSE: LLB Environment Variable Routines
6 * PROGRAMMERS: ReactOS Portable Systems Group
7 */
8
9 #include "precomp.h"
10
11 ULONG LlbEnvHwPageSize;
12 ULONG LlbEnvHwMemStart;
13 ULONG LlbEnvHwMemSize;
14 ULONG LlbEnvRamDiskStart;
15 ULONG LlbEnvRamDiskSize;
16 CHAR LlbEnvCmdLine[256];
17 CHAR LlbValueData[32];
18
19 VOID
20 NTAPI
21 LlbEnvParseArguments(IN PATAG Arguments)
22 {
23 PATAG Atag;
24
25 /* Parse the ATAGs */
26 Atag = Arguments;
27 while (Atag->Hdr.Size)
28 {
29 /* Check tag type */
30 switch (Atag->Hdr.Tag)
31 {
32 case ATAG_CORE:
33
34 /* Save page size */
35 LlbEnvHwPageSize = Atag->u.Core.PageSize;
36 break;
37
38 case ATAG_MEM:
39
40 /* Save RAM start and size */
41 LlbEnvHwMemStart = Atag->u.Mem.Start;
42 LlbEnvHwMemSize = Atag->u.Mem.Size;
43 break;
44
45 case ATAG_INITRD2:
46
47 /* Save RAMDISK start and size */
48 LlbEnvRamDiskStart = Atag->u.InitRd2.Start;
49 LlbEnvRamDiskSize = Atag->u.InitRd2.Size;
50
51 /* Make sure it's 16MB-aligned */
52 LlbEnvRamDiskSize = (LlbEnvRamDiskSize + (16 * 1024 * 1024) - 1)
53 &~ ((16 * 1024 * 1024) - 1);
54
55 /* The RAMDISK actually starts 16MB later */
56 LlbEnvRamDiskStart += 16 * 1024 * 1024;
57 LlbEnvRamDiskSize -= 16 * 1024 * 1024;
58 break;
59
60 case ATAG_CMDLINE:
61
62 /* Save command line */
63 strncpy(LlbEnvCmdLine,
64 Atag->u.CmdLine.CmdLine,
65 Atag->Hdr.Size * sizeof(ULONG));
66 break;
67
68 /* Nothing left to handle */
69 case ATAG_NONE:
70 default:
71 return;
72 }
73
74 /* Next tag */
75 Atag = (PATAG)((PULONG)Atag + Atag->Hdr.Size);
76 }
77
78 /* For debugging */
79 DbgPrint("[BOOTROM] PageSize: %dKB RAM: %dMB CMDLINE: %s\n",
80 LlbEnvHwPageSize / 1024, LlbEnvHwMemSize / 1024 / 1024, LlbEnvCmdLine);
81 }
82
83 VOID
84 NTAPI
85 LlbEnvGetMemoryInformation(IN PULONG Base,
86 IN PULONG Size)
87 {
88 /* Return RAM information */
89 *Base = LlbEnvHwMemStart;
90 *Size = LlbEnvHwMemSize;
91 }
92
93 BOOLEAN
94 NTAPI
95 LlbEnvGetRamDiskInformation(IN PULONG Base,
96 IN PULONG Size)
97 {
98 /* Do we have a ramdisk? */
99 if (LlbEnvRamDiskSize == 0)
100 {
101 /* No */
102 *Base = 0;
103 *Size = 0;
104 return FALSE;
105 }
106
107 /* Return ramdisk information */
108 *Base = LlbEnvRamDiskStart;
109 *Size = LlbEnvRamDiskSize;
110 return TRUE;
111 }
112
113 PCHAR
114 NTAPI
115 LlbEnvRead(IN PCHAR ValueName)
116 {
117 PCHAR ValuePointer;
118 ULONG Length = 0;
119
120 /* Search for the value name */
121 ValuePointer = strstr(LlbEnvCmdLine, ValueName);
122 if (ValuePointer)
123 {
124 /* Get the value data and its length */
125 ValuePointer += strlen(ValueName) + 1;
126 if (strchr(ValuePointer, ','))
127 {
128 /* Stop before next parameter */
129 Length = strchr(ValuePointer, ',') - ValuePointer;
130 }
131 else
132 {
133 /* Stop before the string ends */
134 Length = strlen(ValuePointer);
135 }
136
137 /* Copy it */
138 strncpy(LlbValueData, ValuePointer, Length);
139 }
140
141 /* Terminate the data */
142 LlbValueData[Length] = ANSI_NULL;
143
144 /* Return the data */
145 return LlbValueData;
146 }
147
148 /* EOF */
149