1 /* -*- linux-c -*- ------------------------------------------------------- *
3 * Copyright (C) 1991, 1992 Linus Torvalds
4 * Copyright 2007 rPath, Inc. - All Rights Reserved
6 * This file is part of the Linux kernel, and is made available under
7 * the terms of the GNU General Public License version 2.
9 * ----------------------------------------------------------------------- */
12 * Simple command-line parser for early boot.
17 static inline int myisspace(u8 c
)
19 return c
<= ' '; /* Close enough approximation */
23 * Find a non-boolean option, that is, "option=argument". In accordance
24 * with standard Linux practice, if this option is repeated, this returns
25 * the last instance on the command line.
27 * Returns the length of the argument (regardless of if it was
28 * truncated to fit in the buffer), or -1 on not found.
30 int __cmdline_find_option(u32 cmdline_ptr
, const char *option
, char *buffer
, int bufsize
)
35 const char *opptr
= NULL
;
36 char *bufptr
= buffer
;
38 st_wordstart
, /* Start of word/after whitespace */
39 st_wordcmp
, /* Comparing this word */
40 st_wordskip
, /* Miscompare, skip */
41 st_bufcpy
/* Copying this to buffer */
42 } state
= st_wordstart
;
44 if (!cmdline_ptr
|| cmdline_ptr
>= 0x100000)
45 return -1; /* No command line, or inaccessible */
47 cptr
= cmdline_ptr
& 0xf;
48 set_fs(cmdline_ptr
>> 4);
50 while (cptr
< 0x10000 && (c
= rdfs8(cptr
++))) {
62 if (c
== '=' && !*opptr
) {
66 } else if (myisspace(c
)) {
68 } else if (c
!= *opptr
++) {
97 * Find a boolean option (like quiet,noapic,nosmp....)
99 * Returns the position of that option (starts counting with 1)
102 int __cmdline_find_option_bool(u32 cmdline_ptr
, const char *option
)
106 int pos
= 0, wstart
= 0;
107 const char *opptr
= NULL
;
109 st_wordstart
, /* Start of word/after whitespace */
110 st_wordcmp
, /* Comparing this word */
111 st_wordskip
, /* Miscompare, skip */
112 } state
= st_wordstart
;
114 if (!cmdline_ptr
|| cmdline_ptr
>= 0x100000)
115 return -1; /* No command line, or inaccessible */
117 cptr
= cmdline_ptr
& 0xf;
118 set_fs(cmdline_ptr
>> 4);
120 while (cptr
< 0x10000) {
128 else if (myisspace(c
))
138 if (!c
|| myisspace(c
))
144 else if (c
!= *opptr
++)
151 else if (myisspace(c
))
152 state
= st_wordstart
;
157 return 0; /* Buffer overrun */