Skip to content

Commit

Permalink
intermediate work
Browse files Browse the repository at this point in the history
  • Loading branch information
devsnek committed Aug 26, 2023
1 parent f73a3e7 commit d3a15ba
Show file tree
Hide file tree
Showing 19 changed files with 422 additions and 200 deletions.
40 changes: 20 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 9 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
BUILD ?= debug
PROFILE ?= $(BUILD)
TARGET ?= x86_64-unknown-none
CARGO_PROFILE ?= $(BUILD)

ifeq ($(BUILD), debug)
PROFILE = dev
CARGO_PROFILE = dev
endif

KERNEL = target/x86_64-unknown-none/$(BUILD)/snek_kernel
ISO = out/$(BUILD)/snek_os.iso
KERNEL = target/$(TARGET)/$(BUILD)/snek_kernel
ISO = out/$(TARGET)/$(BUILD)/snek_os.iso
LIMINE = out/limine/limine
OVMF = out/ovmf/OVMF.fd

Expand All @@ -23,12 +24,12 @@ $(LIMINE):
cd out/limine && $(MAKE)

$(KERNEL): FORCE
cargo build --profile $(PROFILE) --package snek_kernel --target x86_64-unknown-none
cargo build --profile $(CARGO_PROFILE) --package snek_kernel --target $(TARGET)

$(ISO): $(KERNEL) $(OVMF) $(LIMINE)
rm -rf out/iso_root
mkdir -p out/iso_root
mkdir -p out/$(BUILD)
mkdir -p out/$(TARGET)/$(BUILD)
cp $(KERNEL) out/iso_root/kernel.elf
cp kernel/limine.cfg out/iso_root/
cp -v out/limine/limine-bios.sys out/limine/limine-bios-cd.bin out/limine/limine-uefi-cd.bin out/iso_root/
Expand All @@ -52,7 +53,7 @@ fmt:
cargo fmt

clippy:
cargo clippy --package snek_kernel --target x86_64-unknown-none
cargo clippy --package snek_kernel --target $(TARGET)

run: $(ISO)
qemu-system-x86_64 \
Expand All @@ -63,5 +64,6 @@ run: $(ISO)
-smp 4 \
-m 2G \
-device qemu-xhci \
-device e1000 \
-bios $(OVMF) \
-drive file=$(ISO),format=raw
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# snek_os

Experimental OS. Aiming to have:

- [x] Lightweight cooperative scheduler
- [ ] WebAssembly userspace
- [ ] Reasonable collection of networking drivers to run on real systems

## Building

```shell
$ make
```

## Running in QEMU

```shell
$ make run
```

## Running elsewhere

Grab `out/x86_64-unknown-none/debug/snek_os.iso` and use as needed.

![Screenshot of the OS after booting, displaying a logo and debug logs](./screenshot.png)
27 changes: 14 additions & 13 deletions crates/e9/src/tracing.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
extern crate alloc;

use alloc::format;

use tracing::field::{Field, Visit};
use tracing::Subscriber;
use tracing::{Level, Subscriber};
use tracing_subscriber::layer::{self, Context};

pub struct Layer;
pub struct Layer {
level: Level,
}

impl Layer {
pub fn new(level: Level) -> Self {
Self { level }
}
}

impl<S: Subscriber> layer::Layer<S> for Layer {
fn enabled(&self, _metadata: &tracing::Metadata<'_>, _ctx: Context<'_, S>) -> bool {
true
fn enabled(&self, meta: &tracing::Metadata<'_>, _ctx: Context<'_, S>) -> bool {
meta.level() <= &self.level
}

fn on_new_span(
Expand All @@ -23,16 +27,13 @@ impl<S: Subscriber> layer::Layer<S> for Layer {

fn on_event(&self, event: &tracing::Event<'_>, _ctx: Context<'_, S>) {
let meta = event.metadata();
let target = meta.target();
let level = meta.level();
let origin = meta
.file()
.and_then(|file| meta.line().map(|ln| format!("{}:{}", file, ln)))
.unwrap_or_default();

static LOCK: spin::Mutex<()> = spin::Mutex::new(());
let _guard = LOCK.lock();

crate::print!("{level} {origin}");
crate::print!("{level} {target}");

struct Visitor;
impl Visit for Visitor {
Expand Down
13 changes: 6 additions & 7 deletions kernel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,27 @@ futures = { version = "0.3", default-features = false, features = ["alloc"] }
futures-util = { version = "0.3", default-features = false, features = ["alloc"] }
conquer-once = { version = "0.3", default-features = false }
noto-sans-mono-bitmap = { version = "0.2", default-features = false, features = ["size_16", "regular", "unicode-basic-latin", "unicode-specials"] }
mycelium-bitfield = { git = "https://github.com/hawkw/mycelium.git", rev = "f173c18b05543f3bf1abd7b5e3b2bfe32214e5d3" }
maitake = { git = "https://github.com/devsnek/mycelium.git", rev = "e23b02810a9586fe268868c01c36c1d4d6dfa37f" }
mycelium-bitfield = { git = "https://github.com/hawkw/mycelium.git", rev = "3f509037380c4ef5f1b9dd3e148d4e7450cd44e5" }
maitake = { git = "https://github.com/hawkw/mycelium.git", rev = "3f509037380c4ef5f1b9dd3e148d4e7450cd44e5" }
rand_xoshiro = "0.6"
rand = { version = "0.8", default-features = false }
i8042 = { path = "../crates/i8042" }
pci-ids = "0.2"
pci_types = "0.3"
pci_types = "0.5"
rustc-demangle = "0.1"
snalloc = { path = "../crates/snalloc" }
limine = "0.1"
e9 = { path = "../crates/e9", features = ["tracing"] }
e9 = { path = "../crates/e9" }
embedded-graphics = "0.8"
unwinding = { version = "0.2", default-features = false, features = ["unwinder", "fde-static", "personality", "panic", "dwarf-expr"] }
tracing = { version = "0.1", default-features = false }
tracing-subscriber = { version = "0.3", default-features = false }
pin-project = "1.1"
bitflags = "2.4"

[target.'cfg(target_arch = "x86_64")'.dependencies]
x86_64 = "0.14"
pic8259 = "0.10"
acpi = { git = "https://github.com/rust-osdev/acpi.git", rev = "e41036d3749a5a901e62cdf62011c735bf283e9c" }
aml = "0.16.4"
aml = "0.16"
os_units = "0.4"
x2apic = "0.4"
raw-cpuid = "10.6"
Expand Down
16 changes: 16 additions & 0 deletions kernel/src/arch/x86_64/acpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@ pub fn init(
)
}

pub fn pci_route_pin(device: u16, function: u16, pin: u8) {
let acpi_tables =
unsafe { AcpiTables::from_rsdp(AcpiHandlerImpl, RSDP_ADDRESS.as_u64() as _) }.unwrap();

let dsdt = acpi_tables.dsdt().unwrap();
let table =
unsafe { core::slice::from_raw_parts(dsdt.address as *mut u8, dsdt.length as usize) };

let mut aml = AmlContext::new(Box::new(AmlHandler), DebugVerbosity::None);
aml.parse_table(table).unwrap();
aml.initialize_objects().unwrap();

// find_bus(d);
}

pub fn shutdown() {
let acpi_tables =
unsafe { AcpiTables::from_rsdp(AcpiHandlerImpl, RSDP_ADDRESS.as_u64() as _) }.unwrap();
Expand All @@ -46,6 +61,7 @@ pub fn shutdown() {

let mut aml = AmlContext::new(Box::new(AmlHandler), DebugVerbosity::None);
aml.parse_table(table).unwrap();
aml.initialize_objects().unwrap();
let name = AmlName::from_str("\\_S5").unwrap();
if let Ok(AmlValue::Package(s5)) = aml.namespace.get_by_path(&name) {
if let AmlValue::Integer(value) = s5[0] {
Expand Down
Loading

0 comments on commit d3a15ba

Please sign in to comment.