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(const char *option, char *buffer, int bufsize)
32 u32 cmdline_ptr = boot_params.hdr.cmd_line_ptr;
36 const char *opptr = NULL;
37 char *bufptr = buffer;
39 st_wordstart, /* Start of word/after whitespace */
40 st_wordcmp, /* Comparing this word */
41 st_wordskip, /* Miscompare, skip */
42 st_bufcpy /* Copying this to buffer */
43 } state = st_wordstart;
45 if (!cmdline_ptr || cmdline_ptr >= 0x100000)
46 return -1; /* No command line, or inaccessible */
48 cptr = cmdline_ptr & 0xf;
49 set_fs(cmdline_ptr >> 4);
51 while (cptr < 0x10000 && (c = rdfs8(cptr++))) {
63 if (c == '=' && !*opptr) {
67 } else if (myisspace(c)) {
69 } else if (c != *opptr++) {
98 * Find a boolean option (like quiet,noapic,nosmp....)
100 * Returns the position of that option (starts counting with 1)
103 int cmdline_find_option_bool(const char *option)
105 u32 cmdline_ptr = boot_params.hdr.cmd_line_ptr;
108 int pos = 0, wstart = 0;
109 const char *opptr = NULL;
111 st_wordstart, /* Start of word/after whitespace */
112 st_wordcmp, /* Comparing this word */
113 st_wordskip, /* Miscompare, skip */
114 } state = st_wordstart;
116 if (!cmdline_ptr || cmdline_ptr >= 0x100000)
117 return -1; /* No command line, or inaccessible */
119 cptr = cmdline_ptr & 0xf;
120 set_fs(cmdline_ptr >> 4);
122 while (cptr < 0x10000) {
130 else if (myisspace(c))
140 if (!c || myisspace(c))
146 else if (c != *opptr++)
153 else if (myisspace(c))
154 state = st_wordstart;
159 return 0; /* Buffer overrun */