Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
georglauterbach committed Oct 18, 2023
1 parent 521d5fc commit 9ce2efd
Show file tree
Hide file tree
Showing 18 changed files with 180 additions and 620 deletions.
20 changes: 10 additions & 10 deletions code/src/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ mod subcommands {
}

impl Command {
/// TODO
/// Actually dispatches the given subcommand by matching on `Self`.
pub(super) fn execute(self, architecture: super::Architecture) -> anyhow::Result<()> {
check_dependencies(architecture)?;
match self {
Expand All @@ -67,15 +67,15 @@ mod subcommands {
}
}

/// TODO
/// Holds information about all architecture-specific files and commands.
struct ArchitectureSpecification {
/// TODO
/// The target triple
pub target: &'static str,
/// TODO
/// The QEMU command to execute
pub qemu_command: &'static str,
/// TODO
/// Path to the linker script
pub linker_script_path: String,
/// TODO
/// The parameters of the QEMU command to execute
pub qemu_arguments: Vec<String>,
}

Expand Down Expand Up @@ -120,11 +120,11 @@ mod subcommands {
}
}

/// TODO
/// Check all dependencies (libraries and binaries) given a specific architecture.
fn check_dependencies(architecture: super::Architecture) -> anyhow::Result<()> {
use anyhow::Context;

/// TODO
/// Short-hand for calling [`which`].
macro_rules! check_bin {
($command:tt) => {
which::which($command).context(format!("Package {} seems to be missing", $command))?;
Expand All @@ -144,7 +144,7 @@ mod subcommands {
Ok(())
}

/// TODO
/// Builds the kernel given an [`ArchitectureSpecification`].
fn build(arch_specification: &ArchitectureSpecification) -> anyhow::Result<()> {
std::process::Command::new(env!("CARGO"))
.args([
Expand All @@ -163,7 +163,7 @@ mod subcommands {
Ok(())
}

/// TODO
/// Runs the kernel given an [`ArchitectureSpecification`].
fn run(arch_specification: &ArchitectureSpecification) -> anyhow::Result<()> {
std::process::Command::new(arch_specification.qemu_command)
.args(&arch_specification.qemu_arguments)
Expand Down
2 changes: 1 addition & 1 deletion code/src/logger.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-or-later

//! TODO
//! This module provides logging functionality.

/// ## The Global Test Runner Logger
///
Expand Down
2 changes: 2 additions & 0 deletions code/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: GPL-3.0-or-later

// Preventing `unsafe` code in `main.rs` completely.
#![forbid(unsafe_code)]
// Clippy lint target one. Enables all lints that are on by
Expand Down
171 changes: 84 additions & 87 deletions code/uncore/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,26 @@ extern "C" fn eh_personality() {}

#[panic_handler]
fn panic(info: &core::panic::PanicInfo) -> ! {
print!("Aborting: ");
if let Some(p) = info.location() {
println!(
"line {}, file {}: {}",
p.line(),
p.file(),
info.message().unwrap()
);
}
else {
println!("no information available.");
}
abort();
print!("Aborting: ");
if let Some(p) = info.location() {
println!(
"line {}, file {}: {}",
p.line(),
p.file(),
info.message().unwrap()
);
} else {
println!("no information available.");
}
abort();
}
#[no_mangle]
extern "C"
fn abort() -> ! {
loop {
unsafe {
core::arch::asm!("wfi");
}
}
extern "C" fn abort() -> ! {
loop {
unsafe {
core::arch::asm!("wfi");
}
}
}

// ///////////////////////////////////
Expand All @@ -72,77 +70,76 @@ fn abort() -> ! {
// / ENTRY POINT
// ///////////////////////////////////
#[no_mangle]
extern "C"
fn kmain() {
// Main should initialize all sub-systems and get
// ready to start scheduling. The last thing this
// should do is start the timer.
extern "C" fn kmain() {
// Main should initialize all sub-systems and get
// ready to start scheduling. The last thing this
// should do is start the timer.

// Let's try using our newly minted UART by initializing it first.
// The UART is sitting at MMIO address 0x1000_0000, so for testing
// now, lets connect to it and see if we can initialize it and write
// to it.
let mut my_uart = uart::Uart::new(0x1000_0000);
// Let's try using our newly minted UART by initializing it first.
// The UART is sitting at MMIO address 0x1000_0000, so for testing
// now, lets connect to it and see if we can initialize it and write
// to it.
let mut my_uart = uart::Uart::new(0x1000_0000);

my_uart.init();
my_uart.init();

// Now test println! macro!
println!("This is my operating system! Juhu!");
println!("I'm so awesome. If you start typing something, I'll show you what you typed!");
// Now test println! macro!
println!("This is my operating system! Juhu!");
println!("I'm so awesome. If you start typing something, I'll show you what you typed!");

// Now see if we can read stuff:
// Usually we can use #[test] modules in Rust, but it would convolute the
// task at hand. So, we'll just add testing snippets.
loop {
if let Some(c) = my_uart.get() {
match c {
8 => {
// This is a backspace, so we essentially have
// to write a space and backup again:
print!("{}{}{}", 8 as char, ' ', 8 as char);
},
10 | 13 => {
// Newline or carriage-return
println!();
},
0x1b => {
// Those familiar with ANSI escape sequences
// knows that this is one of them. The next
// thing we should get is the left bracket [
// These are multi-byte sequences, so we can take
// a chance and get from UART ourselves.
// Later, we'll button this up.
if let Some(next_byte) = my_uart.get() {
if next_byte == 91 {
// This is a right bracket! We're on our way!
if let Some(b) = my_uart.get() {
match b as char {
'A' => {
println!("That's the up arrow!");
},
'B' => {
println!("That's the down arrow!");
},
'C' => {
println!("That's the right arrow!");
},
'D' => {
println!("That's the left arrow!");
},
_ => {
println!("That's something else.....");
}
}
}
}
}
},
_ => {
print!("{}", c as char);
}
}
}
}
// Now see if we can read stuff:
// Usually we can use #[test] modules in Rust, but it would convolute the
// task at hand. So, we'll just add testing snippets.
loop {
if let Some(c) = my_uart.get() {
match c {
8 => {
// This is a backspace, so we essentially have
// to write a space and backup again:
print!("{}{}{}", 8 as char, ' ', 8 as char);
},
10 | 13 => {
// Newline or carriage-return
println!();
},
0x1B => {
// Those familiar with ANSI escape sequences
// knows that this is one of them. The next
// thing we should get is the left bracket [
// These are multi-byte sequences, so we can take
// a chance and get from UART ourselves.
// Later, we'll button this up.
if let Some(next_byte) = my_uart.get() {
if next_byte == 91 {
// This is a right bracket! We're on our way!
if let Some(b) = my_uart.get() {
match b as char {
'A' => {
println!("That's the up arrow!");
},
'B' => {
println!("That's the down arrow!");
},
'C' => {
println!("That's the right arrow!");
},
'D' => {
println!("That's the left arrow!");
},
_ => {
println!("That's something else.....");
},
}
}
}
}
},
_ => {
print!("{}", c as char);
},
}
}
}
}

// ///////////////////////////////////
Expand Down
Loading

0 comments on commit 9ce2efd

Please sign in to comment.