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 PCSTR DefaultOperatingSystem
;
20 } CMDLINEINFO
, *PCMDLINEINFO
;
22 CCHAR DebugString
[256];
24 CMDLINEINFO CmdLineInfo
;
26 /* FUNCTIONS ******************************************************************/
29 CmdLineParse(IN PCSTR 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
, " ");
51 Length
= (End
? (End
- Setting
) : strlen(Setting
));
53 /* Copy the debug string and upcase it */
54 RtlStringCbCopyNA(DebugString
, sizeof(DebugString
), Setting
, Length
);
57 /* Replace all separators ';' by spaces */
58 Setting
= DebugString
;
61 if (*Setting
== ';') *Setting
= ' ';
65 CmdLineInfo
.DebugString
= DebugString
;
69 Setting
= strstr(CmdLine
, "timeout=");
72 CmdLineInfo
.TimeOut
= atoi(Setting
+
73 sizeof("timeout=") - sizeof(ANSI_NULL
));
77 Setting
= strstr(CmdLine
, "defaultos=");
80 /* Check if there are more command-line parameters following */
81 Setting
+= sizeof("defaultos=") - sizeof(ANSI_NULL
);
82 End
= strstr(Setting
, " ");
83 Length
= (End
? (End
- Setting
) : strlen(Setting
));
85 /* Copy the default OS */
86 RtlStringCbCopyNA(DefaultOs
, sizeof(DefaultOs
), Setting
, Length
);
87 CmdLineInfo
.DefaultOperatingSystem
= DefaultOs
;
90 /* Get ramdisk base address */
91 Setting
= strstr(CmdLine
, "rdbase=");
95 (PVOID
)(ULONG_PTR
)strtoull(Setting
+
96 sizeof("rdbase=") - sizeof(ANSI_NULL
),
100 /* Get ramdisk size */
101 Setting
= strstr(CmdLine
, "rdsize=");
104 gRamDiskSize
= strtoul(Setting
+
105 sizeof("rdsize=") - sizeof(ANSI_NULL
),
109 /* Get ramdisk offset */
110 Setting
= strstr(CmdLine
, "rdoffset=");
113 Offset
= strtoul(Setting
+
114 sizeof("rdoffset=") - sizeof(ANSI_NULL
),
119 gRamDiskBase
= (PVOID
)((ULONG_PTR
)gRamDiskBase
+ Offset
);
123 CmdLineGetDebugString(VOID
)
125 return CmdLineInfo
.DebugString
;
129 CmdLineGetDefaultOS(VOID
)
131 return CmdLineInfo
.DefaultOperatingSystem
;
135 CmdLineGetTimeOut(VOID
)
137 return CmdLineInfo
.TimeOut
;