1 // SPDX-License-Identifier: GPL-2.0-only
2 /* -*- linux-c -*- ------------------------------------------------------- *
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 * Copyright 2007 rPath, Inc. - All Rights Reserved
7 * ----------------------------------------------------------------------- */
10 * Simple command-line parser for early boot.
15 static inline int myisspace(u8 c)
17 return c <= ' '; /* Close enough approximation */
21 * Find a non-boolean option, that is, "option=argument". In accordance
22 * with standard Linux practice, if this option is repeated, this returns
23 * the last instance on the command line.
25 * Returns the length of the argument (regardless of if it was
26 * truncated to fit in the buffer), or -1 on not found.
28 int __cmdline_find_option(unsigned long cmdline_ptr, const char *option, char *buffer, int bufsize)
33 const char *opptr = NULL;
34 char *bufptr = buffer;
36 st_wordstart, /* Start of word/after whitespace */
37 st_wordcmp, /* Comparing this word */
38 st_wordskip, /* Miscompare, skip */
39 st_bufcpy /* Copying this to buffer */
40 } state = st_wordstart;
43 return -1; /* No command line */
45 cptr = cmdline_ptr & 0xf;
46 set_fs(cmdline_ptr >> 4);
48 while (cptr < 0x10000 && (c = rdfs8(cptr++))) {
60 if (c == '=' && !*opptr) {
64 } else if (myisspace(c)) {
66 } else if (c != *opptr++) {
95 * Find a boolean option (like quiet,noapic,nosmp....)
97 * Returns the position of that option (starts counting with 1)
100 int __cmdline_find_option_bool(unsigned long cmdline_ptr, const char *option)
104 int pos = 0, wstart = 0;
105 const char *opptr = NULL;
107 st_wordstart, /* Start of word/after whitespace */
108 st_wordcmp, /* Comparing this word */
109 st_wordskip, /* Miscompare, skip */
110 } state = st_wordstart;
113 return -1; /* No command line */
115 cptr = cmdline_ptr & 0xf;
116 set_fs(cmdline_ptr >> 4);
118 while (cptr < 0x10000) {
126 else if (myisspace(c))
136 if (!c || myisspace(c))
142 else if (c != *opptr++)
149 else if (myisspace(c))
150 state = st_wordstart;
155 return 0; /* Buffer overrun */