/// Parse command line argument and initialize the logging infrastructure.
///
/// Example: If args is './kernel log=trace' -> sets level to Level::Trace
Parse command line argument and initialize the logging infrastructure.
Example: If args is './kernel log=trace' -> sets level to Level::Trace
Parse command line argument and initialize the logging infrastructure . Example : If args is ' . / kernel log = trace ' - > sets level to Level :: Trace
pub fn from_str(args: &'static str) -> BootloaderArguments {
        // The args argument will be a physical address slice that
        // goes away once we switch to a process address space
        // make sure we translate it into a kernel virtual address:
        let args_paddr = args.as_ptr();
        let args_kaddr = paddr_to_kernel_vaddr(PAddr::from(args_paddr as u64));
        // Safe: Depends on bootloader setting up identity mapping abobe `KERNEL_BASE`.
        let args_kslice = unsafe { from_raw_parts(args_kaddr.as_ptr(), args.len()) };
        let args = core::str::from_utf8(args_kslice).expect("Can't read args in kernel space?");
        let mut parsed_args: BootloaderArguments = Default::default();
        let mut lexer = CmdToken::lexer(args);
        let mut prev = CmdToken::Error;
        while let Some(token) = lexer.next() {
            let slice = lexer.slice();
            match token {
                CmdToken::KernelBinary => {
                    //assert_eq!(slice, "./kernel");
                }
                CmdToken::BspOnly => {
                    parsed_args.bsp_only = true;
                }
                CmdToken::Log
                | CmdToken::Test
                | CmdToken::InitBinary
                | CmdToken::InitArgs
                | CmdToken::AppArgs => {
                    prev = token;
                }
                CmdToken::Ident => match prev {
                    CmdToken::Log => {
                        parsed_args.log_filter = slice;
                        prev = CmdToken::Error;
                    }
                    CmdToken::InitBinary => {
                        parsed_args.init_binary = slice;
                        prev = CmdToken::Error;
                    }
                    CmdToken::InitArgs => {
                        parsed_args.init_args = slice;
                        prev = CmdToken::Error;
                    }
                    CmdToken::AppArgs => {
                        parsed_args.app_args = slice;
                        prev = CmdToken::Error;
                    }
                    CmdToken::Test => {
                        parsed_args.test = Some(slice);
                        prev = CmdToken::Error;
                    }
                    _ => {
                        error!("Invalid cmd arguments: {} (skipped {})", args, slice);
                        continue;
                    }
                },
                CmdToken::KVSeparator => {
                    if prev != CmdToken::Log
                        && prev != CmdToken::InitBinary
                        && prev != CmdToken::InitArgs
                        && prev != CmdToken::AppArgs
                        && prev != CmdToken::Test
                    {
                        error!("Malformed args (unexpected equal sign) in {}", args);
                        continue;
                    }
                }
                CmdToken::LiteralString => {
                    // We strip the quotes with 1..slice.len()-1
                    let slice_no_quote = &slice[1..slice.len() - 1];
                    match prev {
                        CmdToken::Log => {
                            parsed_args.log_filter = slice_no_quote;
                            prev = CmdToken::Error;
                        }
                        CmdToken::InitBinary => {
                            parsed_args.init_binary = slice_no_quote;
                            prev = CmdToken::Error;
                        }
                        CmdToken::InitArgs => {
                            parsed_args.init_args = slice_no_quote;
                            prev = CmdToken::Error;
                        }
                        CmdToken::AppArgs => {
                            parsed_args.app_args = slice_no_quote;
                            prev = CmdToken::Error;
                        }
                        CmdToken::Test => {
                            parsed_args.test = Some(slice_no_quote);
                            prev = CmdToken::Error;
                        }
                        _ => {
                            error!("Invalid cmd arguments: {} (skipped {})", args, slice);
                            continue;
                        }
                    }
                }
                CmdToken::Error => {
                    error!("Ignored '{}' while parsing cmd args: {}", slice, args);
                    continue;
                }
            }
        }
        parsed_args
    }
pub fn from_str ( args : & ' static str ) -> BootloaderArguments { // The args argument will be a physical address slice that // goes away once we switch to a process address space // make sure we translate it into a kernel virtual address: let args_paddr = args . as_ptr ( ) ; let args_kaddr = paddr_to_kernel_vaddr ( PAddr :: from ( args_paddr as u64 ) ) ; // Safe: Depends on bootloader setting up identity mapping abobe `KERNEL_BASE`. let args_kslice = unsafe { from_raw_parts ( args_kaddr . as_ptr ( ) , args . len ( ) ) } ; let args = core :: str :: from_utf8 ( args_kslice ) . expect ( " " ) ; let mut parsed_args : BootloaderArguments = Default :: default ( ) ; let mut lexer = CmdToken :: lexer ( args ) ; let mut prev = CmdToken :: Error ; while let Some ( token ) = lexer . next ( ) { let slice = lexer . slice ( ) ; match token { CmdToken :: KernelBinary => { //assert_eq!(slice, "./kernel"); } CmdToken :: BspOnly => { parsed_args . bsp_only = true ; } CmdToken :: Log | CmdToken :: Test | CmdToken :: InitBinary | CmdToken :: InitArgs | CmdToken :: AppArgs => { prev = token ; } CmdToken :: Ident => match prev { CmdToken :: Log => { parsed_args . log_filter = slice ; prev = CmdToken :: Error ; } CmdToken :: InitBinary => { parsed_args . init_binary = slice ; prev = CmdToken :: Error ; } CmdToken :: InitArgs => { parsed_args . init_args = slice ; prev = CmdToken :: Error ; } CmdToken :: AppArgs => { parsed_args . app_args = slice ; prev = CmdToken :: Error ; } CmdToken :: Test => { parsed_args . test = Some ( slice ) ; prev = CmdToken :: Error ; } _ => { error ! ( " " args slice ) ; continue ; } } , CmdToken :: KVSeparator => { if prev != CmdToken :: Log && prev != CmdToken :: InitBinary && prev != CmdToken :: InitArgs && prev != CmdToken :: AppArgs && prev != CmdToken :: Test { error ! ( " " args ) ; continue ; } } CmdToken :: LiteralString => { // We strip the quotes with 1..slice.len()-1 let slice_no_quote = & slice [ 1 .. slice . len ( ) - 1 ] ; match prev { CmdToken :: Log => { parsed_args . log_filter = slice_no_quote ; prev = CmdToken :: Error ; } CmdToken :: InitBinary => { parsed_args . init_binary = slice_no_quote ; prev = CmdToken :: Error ; } CmdToken :: InitArgs => { parsed_args . init_args = slice_no_quote ; prev = CmdToken :: Error ; } CmdToken :: AppArgs => { parsed_args . app_args = slice_no_quote ; prev = CmdToken :: Error ; } CmdToken :: Test => { parsed_args . test = Some ( slice_no_quote ) ; prev = CmdToken :: Error ; } _ => { error ! ( " " args slice ) ; continue ; } } } CmdToken :: Error => { error ! ( " " slice args ) ; continue ; } } } parsed_args }
Parse command line argument and initialize the logging infrastructure.
Parse command line argument and initialize the logging infrastructure .
args
&'static str