Next Generation WASM Microkernel Operating System
at trap_handler 51 lines 1.5 kB view raw
1// Copyright 2025 Jonas Kruckenberg 2// 3// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or 4// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or 5// http://opensource.org/licenses/MIT>, at your option. This file may not be 6// copied, modified, or distributed except according to those terms. 7 8use crate::backtrace::BacktraceStyle; 9use crate::device_tree::DeviceTree; 10use crate::tracing::Filter; 11use core::str::FromStr; 12 13pub fn parse(devtree: &DeviceTree) -> crate::Result<Bootargs> { 14 let chosen = devtree.find_by_path("/chosen").unwrap(); 15 let Some(prop) = chosen.property("bootargs") else { 16 return Ok(Bootargs::default()); 17 }; 18 19 Bootargs::from_str(prop.as_str()?) 20} 21 22#[derive(Default)] 23pub struct Bootargs { 24 pub log: Filter, 25 pub backtrace: BacktraceStyle, 26} 27 28impl FromStr for Bootargs { 29 type Err = anyhow::Error; 30 31 fn from_str(s: &str) -> Result<Self, Self::Err> { 32 let mut log = None; 33 let mut backtrace = None; 34 35 let parts = s.trim().split(';'); 36 for part in parts { 37 if let Some(current) = part.strip_prefix("log=") { 38 log = Some(Filter::from_str(current)?); 39 } 40 41 if let Some(current) = part.strip_prefix("backtrace=") { 42 backtrace = Some(BacktraceStyle::from_str(current)?); 43 } 44 } 45 46 Ok(Self { 47 log: log.unwrap_or_default(), 48 backtrace: backtrace.unwrap_or_default(), 49 }) 50 } 51}