2 * PROJECT: ReactOS Boot Loader
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: boot/freeldr/freeldr/cmdline.c
5 * PURPOSE: FreeLDR Command Line Parsing
6 * PROGRAMMERS: ReactOS Portable Systems Group
9 /* INCLUDES *******************************************************************/
13 /* GLOBALS ********************************************************************/
15 typedef struct tagCMDLINEINFO
18 PCCH DefaultOperatingSystem
;
20 } CMDLINEINFO
, *PCMDLINEINFO
;
22 CCHAR DebugString
[256];
24 CMDLINEINFO CmdLineInfo
;
26 /* FUNCTIONS ******************************************************************/
29 CmdLineParse(IN PCCH CmdLine
)
32 ULONG_PTR Length
, Offset
= 0;
35 CmdLineInfo
.DebugString
= NULL
;
36 CmdLineInfo
.DefaultOperatingSystem
= NULL
;
37 CmdLineInfo
.TimeOut
= -1;
40 * Get debug string, in the following format:
41 * "debug=option1=XXX;option2=YYY;..."
42 * and translate it into the format:
43 * "OPTION1=XXX OPTION2=YYY ..."
45 Setting
= strstr(CmdLine
, "debug=");
48 /* Check if there are more command-line parameters following */
49 Setting
+= sizeof("debug=") + sizeof(ANSI_NULL
);
50 End
= strstr(Setting
, " ");
52 Length
= End
- Setting
;
54 Length
= sizeof(DebugString
);
56 /* Copy the debug string and upcase it */
57 strncpy(DebugString
, Setting
, Length
);
58 DebugString
[Length
- 1] = ANSI_NULL
;
61 /* Replace all separators ';' by spaces */
62 Setting
= DebugString
;
65 if (*Setting
== ';') *Setting
= ' ';
69 CmdLineInfo
.DebugString
= DebugString
;
73 Setting
= strstr(CmdLine
, "timeout=");
74 if (Setting
) CmdLineInfo
.TimeOut
= atoi(Setting
+
79 Setting
= strstr(CmdLine
, "defaultos=");
82 /* Check if there are more command-line parameters following */
83 Setting
+= sizeof("defaultos=") + sizeof(ANSI_NULL
);
84 End
= strstr(Setting
, " ");
86 Length
= End
- Setting
;
88 Length
= sizeof(DefaultOs
);
90 /* Copy the default OS */
91 strncpy(DefaultOs
, Setting
, Length
);
92 DefaultOs
[Length
- 1] = ANSI_NULL
;
93 CmdLineInfo
.DefaultOperatingSystem
= DefaultOs
;
96 /* Get ramdisk base address */
97 Setting
= strstr(CmdLine
, "rdbase=");
98 if (Setting
) gRamDiskBase
= (PVOID
)(ULONG_PTR
)strtoull(Setting
+
104 /* Get ramdisk size */
105 Setting
= strstr(CmdLine
, "rdsize=");
106 if (Setting
) gRamDiskSize
= strtoul(Setting
+
112 /* Get ramdisk offset */
113 Setting
= strstr(CmdLine
, "rdoffset=");
114 if (Setting
) Offset
= strtoul(Setting
+
115 sizeof("rdoffset=") -
121 gRamDiskBase
= (PVOID
)((ULONG_PTR
)gRamDiskBase
+ Offset
);
125 CmdLineGetDebugString(VOID
)
127 return CmdLineInfo
.DebugString
;
131 CmdLineGetDefaultOS(VOID
)
133 return CmdLineInfo
.DefaultOperatingSystem
;
137 CmdLineGetTimeOut(VOID
)
139 return CmdLineInfo
.TimeOut
;