mirror of
https://github.com/AmbiML/sparrow-kata-full.git
synced 2025-07-04 18:06:22 +00:00
Misc cleanups.
- change early logging (pre kata-shell prompt) to trace level so by default nothing shows up unless kata-debug-console::pre_init sets log::set_max_level to Trace (default is Debug) - log allocator init's in caller so log msgs identify per-component heap setups (all the same for now but at some point may diverge) - shorten kata-shell prompt to "KATA> " - remove unused camkes control's and consolidate other early work in pre_init and <component>__init hooks - cargo fmt components Change-Id: I010eb5cc5af2e379691cb2e62d82dbab32a06bc3 GitOrigin-RevId: badddf46f5ba50fa60e9cbead9f6d99d5ff3808b
This commit is contained in:
parent
a3bd1a6026
commit
d97a78316e
@ -6,5 +6,4 @@ edition = "2018"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
linked_list_allocator = { version = "0.9", default-features = false, features = ["const_mut_refs"] }
|
linked_list_allocator = { version = "0.9", default-features = false, features = ["const_mut_refs"] }
|
||||||
log = "0.4"
|
|
||||||
spin = "0.9"
|
spin = "0.9"
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
use core::alloc::{GlobalAlloc, Layout};
|
use core::alloc::{GlobalAlloc, Layout};
|
||||||
use core::panic;
|
use core::panic;
|
||||||
use core::ptr::{self, NonNull};
|
use core::ptr::{self, NonNull};
|
||||||
use log::info;
|
|
||||||
|
|
||||||
use linked_list_allocator::Heap;
|
use linked_list_allocator::Heap;
|
||||||
use spin::Mutex;
|
use spin::Mutex;
|
||||||
@ -53,10 +52,9 @@ impl KataHeap {
|
|||||||
///
|
///
|
||||||
/// Obey these or Bad Stuff will happen.
|
/// Obey these or Bad Stuff will happen.
|
||||||
///
|
///
|
||||||
/// - This function must be called exactly ONCE.
|
/// - This function must be called exactly ONCE (per thread).
|
||||||
/// - `size > 0`
|
/// - `size > 0`
|
||||||
pub unsafe fn init(&self, start_addr: usize, size: usize) {
|
pub unsafe fn init(&self, start_addr: usize, size: usize) {
|
||||||
info!("init: start_addr {:#x} size {}", start_addr, size);
|
|
||||||
(*self.heap.lock()).init(start_addr, size);
|
(*self.heap.lock()).init(start_addr, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,30 +17,31 @@ use kata_allocator;
|
|||||||
use kata_logger::KataLogger;
|
use kata_logger::KataLogger;
|
||||||
use kata_shell;
|
use kata_shell;
|
||||||
use kata_uart_client;
|
use kata_uart_client;
|
||||||
use log::debug;
|
use log::trace;
|
||||||
|
|
||||||
static KATA_LOGGER: KataLogger = KataLogger;
|
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn pre_init() {
|
pub extern "C" fn pre_init() {
|
||||||
|
static KATA_LOGGER: KataLogger = KataLogger;
|
||||||
log::set_logger(&KATA_LOGGER).unwrap();
|
log::set_logger(&KATA_LOGGER).unwrap();
|
||||||
|
// NB: set to Trace for early-boot msgs
|
||||||
log::set_max_level(log::LevelFilter::Debug);
|
log::set_max_level(log::LevelFilter::Debug);
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
// NB: use post_init insted of pre_init so syslog interface is setup
|
|
||||||
pub extern "C" fn post_init() {
|
|
||||||
// TODO(sleffler): temp until we integrate with seL4
|
// TODO(sleffler): temp until we integrate with seL4
|
||||||
static mut HEAP_MEMORY: [u8; 16 * 1024] = [0; 16 * 1024];
|
static mut HEAP_MEMORY: [u8; 16 * 1024] = [0; 16 * 1024];
|
||||||
unsafe {
|
unsafe {
|
||||||
kata_allocator::ALLOCATOR.init(HEAP_MEMORY.as_mut_ptr() as usize, HEAP_MEMORY.len());
|
kata_allocator::ALLOCATOR.init(HEAP_MEMORY.as_mut_ptr() as usize, HEAP_MEMORY.len());
|
||||||
|
trace!(
|
||||||
|
"setup heap: start_addr {:p} size {}",
|
||||||
|
HEAP_MEMORY.as_ptr(),
|
||||||
|
HEAP_MEMORY.len()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Entry point for DebugConsole. Runs the shell with UART IO.
|
/// Entry point for DebugConsole. Runs the shell with UART IO.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn run() -> ! {
|
pub extern "C" fn run() -> ! {
|
||||||
debug!("run");
|
trace!("run");
|
||||||
let mut tx = kata_uart_client::Tx {};
|
let mut tx = kata_uart_client::Tx {};
|
||||||
let mut rx = kata_uart_client::Rx {};
|
let mut rx = kata_uart_client::Rx {};
|
||||||
kata_shell::repl(&mut tx, &mut rx);
|
kata_shell::repl(&mut tx, &mut rx);
|
||||||
|
@ -23,8 +23,7 @@ impl log::Log for KataLogger {
|
|||||||
let mut buf = [0 as u8; MAX_MSG_LEN];
|
let mut buf = [0 as u8; MAX_MSG_LEN];
|
||||||
let mut cur = Cursor::new(&mut buf[..]);
|
let mut cur = Cursor::new(&mut buf[..]);
|
||||||
// Log msgs are of the form: '<target>::<fmt'd-msg>
|
// Log msgs are of the form: '<target>::<fmt'd-msg>
|
||||||
write!(&mut cur, "{}::{}\0", record.target(), record.args())
|
write!(&mut cur, "{}::{}\0", record.target(), record.args()).unwrap_or_else(|_| {
|
||||||
.unwrap_or_else(|_| {
|
|
||||||
// Too big, indicate overflow with a trailing "...".
|
// Too big, indicate overflow with a trailing "...".
|
||||||
cur.set_position((MAX_MSG_LEN - 4) as u64);
|
cur.set_position((MAX_MSG_LEN - 4) as u64);
|
||||||
cur.write(b"...\0").expect("write!");
|
cur.write(b"...\0").expect("write!");
|
||||||
@ -38,8 +37,7 @@ impl log::Log for KataLogger {
|
|||||||
record: &Record,
|
record: &Record,
|
||||||
) -> &'a cstr_core::CStr {
|
) -> &'a cstr_core::CStr {
|
||||||
let mut cur = Cursor::new(&mut buf[..]);
|
let mut cur = Cursor::new(&mut buf[..]);
|
||||||
write!(&mut cur, "{}::<embedded nul>\0", record.target())
|
write!(&mut cur, "{}::<embedded nul>\0", record.target()).expect("nul!");
|
||||||
.expect("nul!");
|
|
||||||
let pos = cur.position() as usize;
|
let pos = cur.position() as usize;
|
||||||
CStr::from_bytes_with_nul(&buf[..pos]).unwrap()
|
CStr::from_bytes_with_nul(&buf[..pos]).unwrap()
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
use core::fmt;
|
use core::fmt;
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
use cstr_core::CString;
|
use cstr_core::CString;
|
||||||
use log::info;
|
|
||||||
|
|
||||||
use kata_io as io;
|
use kata_io as io;
|
||||||
use kata_line_reader::LineReader;
|
use kata_line_reader::LineReader;
|
||||||
@ -46,10 +45,9 @@ impl From<fmt::Error> for CommandError {
|
|||||||
|
|
||||||
/// Read-eval-print loop for the DebugConsole command line interface.
|
/// Read-eval-print loop for the DebugConsole command line interface.
|
||||||
pub fn repl(output: &mut dyn io::Write, input: &mut dyn io::Read) -> ! {
|
pub fn repl(output: &mut dyn io::Write, input: &mut dyn io::Read) -> ! {
|
||||||
info!("DebugConsole::repl()");
|
|
||||||
let mut line_reader = LineReader::new();
|
let mut line_reader = LineReader::new();
|
||||||
loop {
|
loop {
|
||||||
const PROMPT: &str = "KATA_PROMPT> ";
|
const PROMPT: &str = "KATA> ";
|
||||||
let _ = output.write_str(PROMPT);
|
let _ = output.write_str(PROMPT);
|
||||||
match line_reader.read_line(output, input) {
|
match line_reader.read_line(output, input) {
|
||||||
Ok(cmdline) => dispatch_command(cmdline, output),
|
Ok(cmdline) => dispatch_command(cmdline, output),
|
||||||
|
@ -21,14 +21,12 @@ extern "C" {
|
|||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn logger_log(level: u8, msg: *const cstr_core::c_char) {
|
pub extern "C" fn logger_log(level: u8, msg: *const cstr_core::c_char) {
|
||||||
use log::Level;
|
use log::Level;
|
||||||
// TODO(sleffler): seems like this should be try_from?
|
|
||||||
let l = match level {
|
let l = match level {
|
||||||
x if x == Level::Error as u8 => Level::Error,
|
x if x == Level::Error as u8 => Level::Error,
|
||||||
x if x == Level::Warn as u8 => Level::Warn,
|
x if x == Level::Warn as u8 => Level::Warn,
|
||||||
x if x == Level::Info as u8 => Level::Info,
|
x if x == Level::Info as u8 => Level::Info,
|
||||||
x if x == Level::Debug as u8 => Level::Debug,
|
x if x == Level::Debug as u8 => Level::Debug,
|
||||||
x if x == Level::Trace as u8 => Level::Trace,
|
_ => Level::Trace,
|
||||||
_ => { return }, // TODO(sleffler): accept or not?
|
|
||||||
};
|
};
|
||||||
if l <= log::max_level() {
|
if l <= log::max_level() {
|
||||||
// TODO(sleffler): is the uart driver ok w/ multiple writers?
|
// TODO(sleffler): is the uart driver ok w/ multiple writers?
|
||||||
|
@ -2,7 +2,6 @@ import <LoggerInterface.camkes>;
|
|||||||
import <MlCoordinatorInterface.camkes>;
|
import <MlCoordinatorInterface.camkes>;
|
||||||
|
|
||||||
component MlCoordinator {
|
component MlCoordinator {
|
||||||
control;
|
|
||||||
provides MlCoordinatorInterface mlcoord;
|
provides MlCoordinatorInterface mlcoord;
|
||||||
|
|
||||||
uses LoggerInterface logger;
|
uses LoggerInterface logger;
|
||||||
|
@ -5,24 +5,24 @@
|
|||||||
extern crate kata_panic;
|
extern crate kata_panic;
|
||||||
|
|
||||||
use kata_logger::KataLogger;
|
use kata_logger::KataLogger;
|
||||||
use log::debug;
|
use log::trace;
|
||||||
|
|
||||||
static KATA_LOGGER: KataLogger = KataLogger;
|
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn pre_init() {
|
pub extern "C" fn pre_init() {
|
||||||
|
static KATA_LOGGER: KataLogger = KataLogger;
|
||||||
log::set_logger(&KATA_LOGGER).unwrap();
|
log::set_logger(&KATA_LOGGER).unwrap();
|
||||||
log::set_max_level(log::LevelFilter::Debug);
|
log::set_max_level(log::LevelFilter::Trace);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn run() {
|
pub extern "C" fn mlcoord__init() {
|
||||||
debug!("run");
|
// TODO(sleffler): maybe not needed?
|
||||||
|
trace!("init");
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Move out of this file into separate (auto-generated?) file.
|
// TODO: Move out of this file into separate (auto-generated?) file.
|
||||||
// TODO: Consider the modular_bitfield crate to represent bitfields.
|
// TODO: Consider the modular_bitfield crate to represent bitfields.
|
||||||
fn vctop_ctrl(freeze: u32, vc_reset: u32, pc_start: u32) -> u32 {
|
fn vctop_ctrl(freeze: u32, vc_reset: u32, pc_start: u32) -> u32 {
|
||||||
(pc_start << 2) + ((vc_reset & 1) << 1) + (freeze & 1)
|
(pc_start << 2) + ((vc_reset & 1) << 1) + (freeze & 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,4 +38,4 @@ pub extern "C" fn mlcoord_execute() {
|
|||||||
// Unhalt, start at default PC.
|
// Unhalt, start at default PC.
|
||||||
vctop_set_ctrl(vctop_ctrl(0, 0, 0));
|
vctop_set_ctrl(vctop_ctrl(0, 0, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
// Kata OS ProcessManager services.
|
// Kata OS ProcessManager services.
|
||||||
|
|
||||||
import <LoggerInterface.camkes>;
|
import <LoggerInterface.camkes>;
|
||||||
import <ProcessControlInterface.camkes>;
|
|
||||||
import <PackageManagementInterface.camkes>;
|
import <PackageManagementInterface.camkes>;
|
||||||
|
import <ProcessControlInterface.camkes>;
|
||||||
import <SeL4DebugInterface.camkes>;
|
import <SeL4DebugInterface.camkes>;
|
||||||
|
|
||||||
component ProcessManager {
|
component ProcessManager {
|
||||||
control;
|
|
||||||
provides ProcessControlInterface proc_ctrl;
|
|
||||||
provides PackageManagementInterface pkg_mgmt;
|
provides PackageManagementInterface pkg_mgmt;
|
||||||
|
provides ProcessControlInterface proc_ctrl;
|
||||||
|
|
||||||
uses LoggerInterface logger;
|
uses LoggerInterface logger;
|
||||||
uses SeL4DebugInterface sel4debug;
|
uses SeL4DebugInterface sel4debug;
|
||||||
|
@ -126,7 +126,8 @@ impl RawBundleIdData {
|
|||||||
// TODO(sleffler): handle truncation better
|
// TODO(sleffler): handle truncation better
|
||||||
pub fn pack_bundles(&mut self, bundles: &BundleIdArray) -> bare_io::Result<()> {
|
pub fn pack_bundles(&mut self, bundles: &BundleIdArray) -> bare_io::Result<()> {
|
||||||
let mut result = Cursor::new(&mut self.data[..]);
|
let mut result = Cursor::new(&mut self.data[..]);
|
||||||
let bundle_count = [u8::try_from(bundles.len()).map_err(|_| bare_io::ErrorKind::InvalidData)?];
|
let bundle_count =
|
||||||
|
[u8::try_from(bundles.len()).map_err(|_| bare_io::ErrorKind::InvalidData)?];
|
||||||
result.write(&bundle_count[..])?; // # bundles
|
result.write(&bundle_count[..])?; // # bundles
|
||||||
for bid in bundles.ids.as_slice().iter() {
|
for bid in bundles.ids.as_slice().iter() {
|
||||||
let bid_len = [u8::try_from(bid.len()).map_err(|_| bare_io::ErrorKind::InvalidData)?];
|
let bid_len = [u8::try_from(bid.len()).map_err(|_| bare_io::ErrorKind::InvalidData)?];
|
||||||
|
@ -9,7 +9,7 @@ use kata_allocator;
|
|||||||
use kata_logger::KataLogger;
|
use kata_logger::KataLogger;
|
||||||
use kata_proc_common::*;
|
use kata_proc_common::*;
|
||||||
use kata_proc_manager::KATA_PROC;
|
use kata_proc_manager::KATA_PROC;
|
||||||
use log::{info, trace};
|
use log::trace;
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn pre_init() {
|
pub extern "C" fn pre_init() {
|
||||||
@ -22,25 +22,29 @@ pub extern "C" fn pre_init() {
|
|||||||
static mut HEAP_MEMORY: [u8; 16 * 1024] = [0; 16 * 1024];
|
static mut HEAP_MEMORY: [u8; 16 * 1024] = [0; 16 * 1024];
|
||||||
unsafe {
|
unsafe {
|
||||||
kata_allocator::ALLOCATOR.init(HEAP_MEMORY.as_mut_ptr() as usize, HEAP_MEMORY.len());
|
kata_allocator::ALLOCATOR.init(HEAP_MEMORY.as_mut_ptr() as usize, HEAP_MEMORY.len());
|
||||||
|
trace!(
|
||||||
|
"setup heap: start_addr {:p} size {}",
|
||||||
|
HEAP_MEMORY.as_ptr(),
|
||||||
|
HEAP_MEMORY.len()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Complete KATA_PROC setup. This is as early as we can do it given that
|
// Complete KATA_PROC setup. This is as early as we can do it given that
|
||||||
// it needs the GlobalAllocator.
|
// it needs the GlobalAllocator.
|
||||||
unsafe {
|
unsafe {
|
||||||
KATA_PROC.init();
|
KATA_PROC.init();
|
||||||
info!(
|
trace!(
|
||||||
"ProcessManager has capacity for {} bundles",
|
"ProcessManager has capacity for {} bundles",
|
||||||
KATA_PROC.capacity()
|
KATA_PROC.capacity()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(sleffler): move to init or similar if a thread isn't needed
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn run() {
|
pub extern "C" fn pkg_mgmt__init() {
|
||||||
// Setup the userland address spaces, lifecycles, and system introspection
|
// Setup the userland address spaces, lifecycles, and system introspection
|
||||||
// for third-party applications.
|
// for third-party applications.
|
||||||
trace!("run");
|
trace!("init");
|
||||||
}
|
}
|
||||||
|
|
||||||
// PackageManagerInterface glue stubs.
|
// PackageManagerInterface glue stubs.
|
||||||
|
Loading…
Reference in New Issue
Block a user