Orbital (#16)
* Port previous ethernet scheme * Add ipd * Fix initfs rebuilds, use QEMU user networking addresses in ipd * Add tcp/udp, netutils, dns, and network config * Add fsync to network driver * Add dns, router, subnet by default * Fix e1000 driver. Make ethernet and IP non-blocking to avoid deadlocks * Add orbital server, WIP * Add futex * Add orbutils and orbital * Update libstd, orbutils, and orbital Move ANSI key encoding to vesad * Add orbital assets * Update orbital * Update to add login manager * Add blocking primitives, block for most things except waitpid, update orbital * Wait in waitpid and IRQ, improvements for other waits * Fevent in root scheme * WIP: Switch to using fevent * Reorganize * Event based e1000d driver * Superuser-only access to some network schemes, display, and disk * Superuser root and irq schemes * Fix orbital
This commit is contained in:
parent
372d44f88c
commit
224c43f761
92 changed files with 3418 additions and 476 deletions
12
.gitmodules
vendored
12
.gitmodules
vendored
|
|
@ -28,3 +28,15 @@
|
||||||
[submodule "programs/userutils"]
|
[submodule "programs/userutils"]
|
||||||
path = programs/userutils
|
path = programs/userutils
|
||||||
url = https://github.com/redox-os/userutils.git
|
url = https://github.com/redox-os/userutils.git
|
||||||
|
[submodule "programs/netutils"]
|
||||||
|
path = programs/netutils
|
||||||
|
url = https://github.com/redox-os/netutils.git
|
||||||
|
[submodule "schemes/orbital"]
|
||||||
|
path = schemes/orbital
|
||||||
|
url = https://github.com/redox-os/orbital.git
|
||||||
|
[submodule "programs/orbutils"]
|
||||||
|
path = programs/orbutils
|
||||||
|
url = https://github.com/redox-os/orbutils.git
|
||||||
|
[submodule "filesystem/ui"]
|
||||||
|
path = filesystem/ui
|
||||||
|
url = https://github.com/redox-os/orbdata.git
|
||||||
|
|
|
||||||
82
Makefile
82
Makefile
|
|
@ -17,7 +17,7 @@ CARGO=RUSTC="$(RUSTC)" cargo
|
||||||
CARGOFLAGS=--target $(TARGET).json -- -C opt-level=s --cfg redox
|
CARGOFLAGS=--target $(TARGET).json -- -C opt-level=s --cfg redox
|
||||||
|
|
||||||
# Default targets
|
# Default targets
|
||||||
.PHONY: all clean qemu bochs FORCE
|
.PHONY: all clean qemu bochs drivers schemes coreutils extrautils netutils userutils wireshark FORCE
|
||||||
|
|
||||||
all: $(KBUILD)/harddrive.bin
|
all: $(KBUILD)/harddrive.bin
|
||||||
|
|
||||||
|
|
@ -25,6 +25,7 @@ clean:
|
||||||
cargo clean
|
cargo clean
|
||||||
cargo clean --manifest-path libstd/Cargo.toml
|
cargo clean --manifest-path libstd/Cargo.toml
|
||||||
cargo clean --manifest-path drivers/ahcid/Cargo.toml
|
cargo clean --manifest-path drivers/ahcid/Cargo.toml
|
||||||
|
cargo clean --manifest-path drivers/e1000d/Cargo.toml
|
||||||
cargo clean --manifest-path drivers/ps2d/Cargo.toml
|
cargo clean --manifest-path drivers/ps2d/Cargo.toml
|
||||||
cargo clean --manifest-path drivers/pcid/Cargo.toml
|
cargo clean --manifest-path drivers/pcid/Cargo.toml
|
||||||
cargo clean --manifest-path drivers/vesad/Cargo.toml
|
cargo clean --manifest-path drivers/vesad/Cargo.toml
|
||||||
|
|
@ -32,10 +33,17 @@ clean:
|
||||||
cargo clean --manifest-path programs/ion/Cargo.toml
|
cargo clean --manifest-path programs/ion/Cargo.toml
|
||||||
cargo clean --manifest-path programs/coreutils/Cargo.toml
|
cargo clean --manifest-path programs/coreutils/Cargo.toml
|
||||||
cargo clean --manifest-path programs/extrautils/Cargo.toml
|
cargo clean --manifest-path programs/extrautils/Cargo.toml
|
||||||
|
cargo clean --manifest-path programs/netutils/Cargo.toml
|
||||||
|
cargo clean --manifest-path programs/orbutils/Cargo.toml
|
||||||
cargo clean --manifest-path programs/userutils/Cargo.toml
|
cargo clean --manifest-path programs/userutils/Cargo.toml
|
||||||
cargo clean --manifest-path programs/smith/Cargo.toml
|
cargo clean --manifest-path programs/smith/Cargo.toml
|
||||||
|
cargo clean --manifest-path schemes/ethernetd/Cargo.toml
|
||||||
cargo clean --manifest-path schemes/example/Cargo.toml
|
cargo clean --manifest-path schemes/example/Cargo.toml
|
||||||
|
cargo clean --manifest-path schemes/ipd/Cargo.toml
|
||||||
|
cargo clean --manifest-path schemes/orbital/Cargo.toml
|
||||||
cargo clean --manifest-path schemes/redoxfs/Cargo.toml
|
cargo clean --manifest-path schemes/redoxfs/Cargo.toml
|
||||||
|
cargo clean --manifest-path schemes/tcpd/Cargo.toml
|
||||||
|
cargo clean --manifest-path schemes/udpd/Cargo.toml
|
||||||
rm -rf initfs/bin
|
rm -rf initfs/bin
|
||||||
rm -rf filesystem/bin
|
rm -rf filesystem/bin
|
||||||
rm -rf build
|
rm -rf build
|
||||||
|
|
@ -118,7 +126,7 @@ $(KBUILD)/librustc_unicode.rlib: rust/src/librustc_unicode/lib.rs $(KBUILD)/libc
|
||||||
$(KBUILD)/libcollections.rlib: rust/src/libcollections/lib.rs $(KBUILD)/libcore.rlib $(KBUILD)/liballoc.rlib $(KBUILD)/librustc_unicode.rlib
|
$(KBUILD)/libcollections.rlib: rust/src/libcollections/lib.rs $(KBUILD)/libcore.rlib $(KBUILD)/liballoc.rlib $(KBUILD)/librustc_unicode.rlib
|
||||||
$(KRUSTC) $(KRUSTCFLAGS) -o $@ $<
|
$(KRUSTC) $(KRUSTCFLAGS) -o $@ $<
|
||||||
|
|
||||||
$(KBUILD)/libkernel.a: kernel/** $(KBUILD)/libcore.rlib $(KBUILD)/liballoc.rlib $(KBUILD)/libcollections.rlib $(BUILD)/initfs.rs FORCE
|
$(KBUILD)/libkernel.a: kernel/** $(KBUILD)/libcore.rlib $(KBUILD)/liballoc.rlib $(KBUILD)/libcollections.rlib $(BUILD)/initfs.rs
|
||||||
$(KCARGO) rustc $(KCARGOFLAGS) -C opt-level=s -C lto -o $@
|
$(KCARGO) rustc $(KCARGOFLAGS) -C opt-level=s -C lto -o $@
|
||||||
|
|
||||||
$(KBUILD)/kernel: $(KBUILD)/libkernel.a
|
$(KBUILD)/kernel: $(KBUILD)/libkernel.a
|
||||||
|
|
@ -170,17 +178,12 @@ initfs/bin/%: schemes/%/Cargo.toml schemes/%/src/** $(BUILD)/libstd.rlib
|
||||||
strip $@
|
strip $@
|
||||||
rm $@.d
|
rm $@.d
|
||||||
|
|
||||||
initfs_drivers: \
|
|
||||||
initfs/bin/ahcid \
|
|
||||||
initfs/bin/pcid
|
|
||||||
|
|
||||||
initfs_schemes: \
|
|
||||||
initfs/bin/redoxfs
|
|
||||||
|
|
||||||
$(BUILD)/initfs.rs: \
|
$(BUILD)/initfs.rs: \
|
||||||
initfs/bin/init \
|
initfs/bin/init \
|
||||||
initfs_drivers \
|
initfs/bin/ahcid \
|
||||||
initfs_schemes
|
initfs/bin/pcid \
|
||||||
|
initfs/bin/redoxfs \
|
||||||
|
initfs/etc/**
|
||||||
echo 'use collections::BTreeMap;' > $@
|
echo 'use collections::BTreeMap;' > $@
|
||||||
echo 'pub fn gen() -> BTreeMap<&'"'"'static [u8], (&'"'"'static [u8], bool)> {' >> $@
|
echo 'pub fn gen() -> BTreeMap<&'"'"'static [u8], (&'"'"'static [u8], bool)> {' >> $@
|
||||||
echo ' let mut files: BTreeMap<&'"'"'static [u8], (&'"'"'static [u8], bool)> = BTreeMap::new();' >> $@
|
echo ' let mut files: BTreeMap<&'"'"'static [u8], (&'"'"'static [u8], bool)> = BTreeMap::new();' >> $@
|
||||||
|
|
@ -218,6 +221,18 @@ filesystem/bin/%: programs/extrautils/Cargo.toml programs/extrautils/src/bin/%.r
|
||||||
strip $@
|
strip $@
|
||||||
rm $@.d
|
rm $@.d
|
||||||
|
|
||||||
|
filesystem/bin/%: programs/netutils/Cargo.toml programs/netutils/src/%/**.rs $(BUILD)/libstd.rlib
|
||||||
|
mkdir -p filesystem/bin
|
||||||
|
$(CARGO) rustc --manifest-path $< --bin $* $(CARGOFLAGS) -o $@
|
||||||
|
strip $@
|
||||||
|
rm $@.d
|
||||||
|
|
||||||
|
filesystem/bin/%: programs/orbutils/Cargo.toml programs/orbutils/src/%/**.rs $(BUILD)/libstd.rlib
|
||||||
|
mkdir -p filesystem/bin
|
||||||
|
$(CARGO) rustc --manifest-path $< --bin $* $(CARGOFLAGS) -o $@
|
||||||
|
strip $@
|
||||||
|
rm $@.d
|
||||||
|
|
||||||
filesystem/bin/%: programs/userutils/Cargo.toml programs/userutils/src/bin/%.rs $(BUILD)/libstd.rlib
|
filesystem/bin/%: programs/userutils/Cargo.toml programs/userutils/src/bin/%.rs $(BUILD)/libstd.rlib
|
||||||
mkdir -p filesystem/bin
|
mkdir -p filesystem/bin
|
||||||
$(CARGO) rustc --manifest-path $< --bin $* $(CARGOFLAGS) -o $@
|
$(CARGO) rustc --manifest-path $< --bin $* $(CARGOFLAGS) -o $@
|
||||||
|
|
@ -278,6 +293,23 @@ extrautils: \
|
||||||
filesystem/bin/rem \
|
filesystem/bin/rem \
|
||||||
#filesystem/bin/dmesg filesystem/bin/info filesystem/bin/man filesystem/bin/watch
|
#filesystem/bin/dmesg filesystem/bin/info filesystem/bin/man filesystem/bin/watch
|
||||||
|
|
||||||
|
netutils: \
|
||||||
|
filesystem/bin/dhcpd \
|
||||||
|
filesystem/bin/dnsd \
|
||||||
|
filesystem/bin/irc \
|
||||||
|
filesystem/bin/nc \
|
||||||
|
filesystem/bin/wget
|
||||||
|
|
||||||
|
orbutils: \
|
||||||
|
filesystem/bin/calculator \
|
||||||
|
filesystem/bin/character_map \
|
||||||
|
filesystem/bin/editor \
|
||||||
|
filesystem/bin/file_manager \
|
||||||
|
filesystem/bin/launcher \
|
||||||
|
filesystem/bin/orblogin \
|
||||||
|
filesystem/bin/terminal \
|
||||||
|
filesystem/bin/viewer
|
||||||
|
|
||||||
userutils: \
|
userutils: \
|
||||||
filesystem/bin/getty \
|
filesystem/bin/getty \
|
||||||
filesystem/bin/id \
|
filesystem/bin/id \
|
||||||
|
|
@ -286,28 +318,35 @@ userutils: \
|
||||||
filesystem/bin/sudo
|
filesystem/bin/sudo
|
||||||
|
|
||||||
schemes: \
|
schemes: \
|
||||||
filesystem/bin/example
|
filesystem/bin/ethernetd \
|
||||||
|
filesystem/bin/example \
|
||||||
|
filesystem/bin/ipd \
|
||||||
|
filesystem/bin/orbital \
|
||||||
|
filesystem/bin/tcpd \
|
||||||
|
filesystem/bin/udpd
|
||||||
|
|
||||||
$(BUILD)/filesystem.bin: \
|
$(BUILD)/filesystem.bin: \
|
||||||
drivers \
|
drivers \
|
||||||
coreutils \
|
coreutils \
|
||||||
extrautils \
|
extrautils \
|
||||||
|
netutils \
|
||||||
|
orbutils \
|
||||||
userutils \
|
userutils \
|
||||||
schemes \
|
schemes \
|
||||||
filesystem/bin/ion \
|
filesystem/bin/ion \
|
||||||
filesystem/bin/smith
|
filesystem/bin/smith
|
||||||
rm -rf $@ $(BUILD)/filesystem/
|
rm -rf $@ $(BUILD)/filesystem/
|
||||||
echo exit | cargo run --manifest-path schemes/redoxfs/Cargo.toml --bin redoxfs-utility $@ 8
|
echo exit | cargo run --manifest-path schemes/redoxfs/Cargo.toml --bin redoxfs-utility $@ 64
|
||||||
mkdir -p $(BUILD)/filesystem/
|
mkdir -p $(BUILD)/filesystem/
|
||||||
cargo run --manifest-path schemes/redoxfs/Cargo.toml --bin redoxfs-fuse $@ $(BUILD)/filesystem/ &
|
cargo run --manifest-path schemes/redoxfs/Cargo.toml --bin redoxfs-fuse $@ $(BUILD)/filesystem/ &
|
||||||
sleep 2
|
sleep 2
|
||||||
-cp -RL filesystem/* $(BUILD)/filesystem/
|
cp -RL filesystem/* $(BUILD)/filesystem/
|
||||||
-chown -R 0:0 $(BUILD)/filesystem/
|
chown -R 0:0 $(BUILD)/filesystem/
|
||||||
-chown -R 1000:1000 $(BUILD)/filesystem/home/user/
|
chown -R 1000:1000 $(BUILD)/filesystem/home/user/
|
||||||
-chmod 700 $(BUILD)/filesystem/root/
|
chmod 700 $(BUILD)/filesystem/root/
|
||||||
-chmod 700 $(BUILD)/filesystem/home/user/
|
chmod 700 $(BUILD)/filesystem/home/user/
|
||||||
-chmod +s $(BUILD)/filesystem/bin/su
|
chmod +s $(BUILD)/filesystem/bin/su
|
||||||
-chmod +s $(BUILD)/filesystem/bin/sudo
|
chmod +s $(BUILD)/filesystem/bin/sudo
|
||||||
sync
|
sync
|
||||||
-fusermount -u $(BUILD)/filesystem/
|
-fusermount -u $(BUILD)/filesystem/
|
||||||
rm -rf $(BUILD)/filesystem/
|
rm -rf $(BUILD)/filesystem/
|
||||||
|
|
@ -321,3 +360,6 @@ unmount: FORCE
|
||||||
sync
|
sync
|
||||||
-fusermount -u $(KBUILD)/harddrive/
|
-fusermount -u $(KBUILD)/harddrive/
|
||||||
rm -rf $(KBUILD)/harddrive/
|
rm -rf $(KBUILD)/harddrive/
|
||||||
|
|
||||||
|
wireshark: FORCE
|
||||||
|
wireshark $(KBUILD)/network.pcap
|
||||||
|
|
|
||||||
|
|
@ -4,5 +4,5 @@ version = "0.1.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bitflags = "*"
|
bitflags = "*"
|
||||||
hole_list_allocator = { path = "../../alloc/hole_list_allocator"}
|
hole_list_allocator = { path = "../../crates/hole_list_allocator"}
|
||||||
spin = "*"
|
spin = "*"
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,10 @@ version = "0.1.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bitflags = "*"
|
bitflags = "*"
|
||||||
hole_list_allocator = { path = "../../alloc/hole_list_allocator" }
|
hole_list_allocator = { path = "../../crates/hole_list_allocator/" }
|
||||||
io = { path = "../../drivers/io" }
|
io = { path = "../../crates/io/" }
|
||||||
spin = "*"
|
spin = "*"
|
||||||
|
|
||||||
[dependencies.x86]
|
[dependencies.x86]
|
||||||
version = "*"
|
version = "0.7"
|
||||||
default-features = false
|
default-features = false
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
use spin::Mutex;
|
|
||||||
use x86::io;
|
use x86::io;
|
||||||
|
|
||||||
use device::serial::{COM1, COM2};
|
use device::serial::{COM1, COM2};
|
||||||
use time;
|
use time;
|
||||||
|
|
||||||
pub static ACKS: Mutex<[usize; 16]> = Mutex::new([0; 16]);
|
extern {
|
||||||
pub static COUNTS: Mutex<[usize; 16]> = Mutex::new([0; 16]);
|
fn irq_trigger(irq: u8);
|
||||||
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
unsafe fn master_ack() {
|
unsafe fn master_ack() {
|
||||||
|
|
@ -27,7 +27,7 @@ pub unsafe fn acknowledge(irq: usize) {
|
||||||
}
|
}
|
||||||
|
|
||||||
interrupt!(pit, {
|
interrupt!(pit, {
|
||||||
COUNTS.lock()[0] += 1;
|
irq_trigger(0);
|
||||||
|
|
||||||
{
|
{
|
||||||
const PIT_RATE: u64 = 46500044;
|
const PIT_RATE: u64 = 46500044;
|
||||||
|
|
@ -42,76 +42,74 @@ interrupt!(pit, {
|
||||||
});
|
});
|
||||||
|
|
||||||
interrupt!(keyboard, {
|
interrupt!(keyboard, {
|
||||||
COUNTS.lock()[1] += 1;
|
irq_trigger(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
interrupt!(cascade, {
|
interrupt!(cascade, {
|
||||||
COUNTS.lock()[2] += 1;
|
irq_trigger(2);
|
||||||
master_ack();
|
master_ack();
|
||||||
});
|
});
|
||||||
|
|
||||||
interrupt!(com2, {
|
interrupt!(com2, {
|
||||||
COUNTS.lock()[3] += 1;
|
irq_trigger(3);
|
||||||
COM2.lock().on_receive();
|
COM2.lock().on_receive();
|
||||||
master_ack();
|
master_ack();
|
||||||
});
|
});
|
||||||
|
|
||||||
interrupt!(com1, {
|
interrupt!(com1, {
|
||||||
COUNTS.lock()[4] += 1;
|
irq_trigger(4);
|
||||||
COM1.lock().on_receive();
|
COM1.lock().on_receive();
|
||||||
master_ack();
|
master_ack();
|
||||||
});
|
});
|
||||||
|
|
||||||
interrupt!(lpt2, {
|
interrupt!(lpt2, {
|
||||||
COUNTS.lock()[5] += 1;
|
irq_trigger(5);
|
||||||
master_ack();
|
master_ack();
|
||||||
});
|
});
|
||||||
|
|
||||||
interrupt!(floppy, {
|
interrupt!(floppy, {
|
||||||
COUNTS.lock()[6] += 1;
|
irq_trigger(6);
|
||||||
master_ack();
|
master_ack();
|
||||||
});
|
});
|
||||||
|
|
||||||
interrupt!(lpt1, {
|
interrupt!(lpt1, {
|
||||||
COUNTS.lock()[7] += 1;
|
irq_trigger(7);
|
||||||
master_ack();
|
master_ack();
|
||||||
});
|
});
|
||||||
|
|
||||||
interrupt!(rtc, {
|
interrupt!(rtc, {
|
||||||
COUNTS.lock()[8] += 1;
|
irq_trigger(8);
|
||||||
slave_ack();
|
slave_ack();
|
||||||
});
|
});
|
||||||
|
|
||||||
interrupt!(pci1, {
|
interrupt!(pci1, {
|
||||||
COUNTS.lock()[9] += 1;
|
irq_trigger(9);
|
||||||
slave_ack();
|
slave_ack();
|
||||||
});
|
});
|
||||||
|
|
||||||
interrupt!(pci2, {
|
interrupt!(pci2, {
|
||||||
COUNTS.lock()[10] += 1;
|
irq_trigger(10);
|
||||||
slave_ack();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
interrupt!(pci3, {
|
interrupt!(pci3, {
|
||||||
COUNTS.lock()[11] += 1;
|
irq_trigger(11);
|
||||||
slave_ack();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
interrupt!(mouse, {
|
interrupt!(mouse, {
|
||||||
COUNTS.lock()[12] += 1;
|
irq_trigger(12);
|
||||||
});
|
});
|
||||||
|
|
||||||
interrupt!(fpu, {
|
interrupt!(fpu, {
|
||||||
COUNTS.lock()[13] += 1;
|
irq_trigger(13);
|
||||||
slave_ack();
|
slave_ack();
|
||||||
});
|
});
|
||||||
|
|
||||||
interrupt!(ata1, {
|
interrupt!(ata1, {
|
||||||
COUNTS.lock()[14] += 1;
|
irq_trigger(14);
|
||||||
slave_ack();
|
slave_ack();
|
||||||
});
|
});
|
||||||
|
|
||||||
interrupt!(ata2, {
|
interrupt!(ata2, {
|
||||||
COUNTS.lock()[15] += 1;
|
irq_trigger(15);
|
||||||
slave_ack();
|
slave_ack();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -148,7 +148,7 @@ pub unsafe extern fn kstart_ap(cpu_id: usize, _page_table: usize, stack_start: u
|
||||||
let kernel_table = KERNEL_TABLE.load(Ordering::SeqCst);
|
let kernel_table = KERNEL_TABLE.load(Ordering::SeqCst);
|
||||||
|
|
||||||
// Initialize paging
|
// Initialize paging
|
||||||
let (active_table, tcb_offset) = paging::init_ap(cpu_id, stack_start, stack_end, kernel_table);
|
let (_active_table, tcb_offset) = paging::init_ap(cpu_id, stack_start, stack_end, kernel_table);
|
||||||
|
|
||||||
// Set up GDT for AP
|
// Set up GDT for AP
|
||||||
gdt::init(tcb_offset, stack_end);
|
gdt::init(tcb_offset, stack_end);
|
||||||
|
|
|
||||||
|
|
@ -115,8 +115,8 @@ vesa:
|
||||||
.minx dw 640
|
.minx dw 640
|
||||||
.miny dw 480
|
.miny dw 480
|
||||||
.required:
|
.required:
|
||||||
.requiredx dw 0 ; 1024 ;USE THESE WITH CAUTION
|
.requiredx dw 1024 ;USE THESE WITH CAUTION
|
||||||
.requiredy dw 0 ; 768
|
.requiredy dw 768
|
||||||
.requiredmode dw 0
|
.requiredmode dw 0
|
||||||
|
|
||||||
.modeok db ": Is this OK?(y/n)",10,13,0
|
.modeok db ": Is this OK?(y/n)",10,13,0
|
||||||
|
|
|
||||||
36
cakefile.rs
36
cakefile.rs
|
|
@ -1,36 +0,0 @@
|
||||||
#[macro_use]
|
|
||||||
extern crate cake;
|
|
||||||
|
|
||||||
const QEMU: &'static str = "qemu-system-x86_64";
|
|
||||||
|
|
||||||
const LS_FLAGS: &'static [&'static str] = &["-a", "/"];
|
|
||||||
|
|
||||||
build! {
|
|
||||||
// ---- COMMANDS ----
|
|
||||||
start(harddrive) => {},
|
|
||||||
list(kernel_list) => {},
|
|
||||||
run(bochs) => {},
|
|
||||||
clean() => cmd!("rm", "-rf", "build/*"),
|
|
||||||
|
|
||||||
// ---- RECIPES ----
|
|
||||||
bochs(harddrive) => cmd!("bochs", "-f", "bochs.x86_64"),
|
|
||||||
qemu(harddrive) => cmd!(QEMU,
|
|
||||||
"-serial", "mon:stdio",
|
|
||||||
"-drive", "file=build/harddrive.bin,format=raw,index=0,media=disk"),
|
|
||||||
libkernel() => cmd!("cargo", "rustc", "--", "-C", "lto"),
|
|
||||||
kernel(libkernel) => cmd!("ld",
|
|
||||||
"-m", "elf_x86_64",
|
|
||||||
"--gc-sections",
|
|
||||||
"-z", "max-page-size=0x1000",
|
|
||||||
"-T bootloader/x86/kernel.ld",
|
|
||||||
"-o", "build/kernel.in", "build/libkernel.a"),
|
|
||||||
kernel_list(kernel) => cmd!("objdump",
|
|
||||||
"-C", "-M", "intel",
|
|
||||||
"-D", "build/kernel.bin",
|
|
||||||
">", "build/kernel.list"),
|
|
||||||
harddrive(kernel) => cmd!("nasm",
|
|
||||||
"-f", "bin",
|
|
||||||
"-o", "build/harddrive.bin",
|
|
||||||
"-D", "ARCH_x86_64", "-ibootloader/x86/", "-ibuild/",
|
|
||||||
"bootloader/x86/harddrive.asm"),
|
|
||||||
}
|
|
||||||
6
crates/dma/Cargo.toml
Normal file
6
crates/dma/Cargo.toml
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
[package]
|
||||||
|
name = "dma"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
syscall = { path = "../../syscall/" }
|
||||||
80
crates/dma/src/lib.rs
Normal file
80
crates/dma/src/lib.rs
Normal file
|
|
@ -0,0 +1,80 @@
|
||||||
|
#![feature(question_mark)]
|
||||||
|
|
||||||
|
extern crate syscall;
|
||||||
|
|
||||||
|
use std::{mem, ptr};
|
||||||
|
use std::ops::{Deref, DerefMut};
|
||||||
|
|
||||||
|
use syscall::Result;
|
||||||
|
|
||||||
|
struct PhysBox {
|
||||||
|
address: usize,
|
||||||
|
size: usize
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PhysBox {
|
||||||
|
fn new(size: usize) -> Result<PhysBox> {
|
||||||
|
let address = unsafe { syscall::physalloc(size)? };
|
||||||
|
Ok(PhysBox {
|
||||||
|
address: address,
|
||||||
|
size: size
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for PhysBox {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
let _ = unsafe { syscall::physfree(self.address, self.size) };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Dma<T> {
|
||||||
|
phys: PhysBox,
|
||||||
|
virt: *mut T
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Dma<T> {
|
||||||
|
pub fn new(value: T) -> Result<Dma<T>> {
|
||||||
|
let phys = PhysBox::new(mem::size_of::<T>())?;
|
||||||
|
let virt = unsafe { syscall::physmap(phys.address, phys.size, syscall::MAP_WRITE)? } as *mut T;
|
||||||
|
unsafe { ptr::write(virt, value); }
|
||||||
|
Ok(Dma {
|
||||||
|
phys: phys,
|
||||||
|
virt: virt
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn zeroed() -> Result<Dma<T>> {
|
||||||
|
let phys = PhysBox::new(mem::size_of::<T>())?;
|
||||||
|
let virt = unsafe { syscall::physmap(phys.address, phys.size, syscall::MAP_WRITE)? } as *mut T;
|
||||||
|
unsafe { ptr::write_bytes(virt as *mut u8, 0, phys.size); }
|
||||||
|
Ok(Dma {
|
||||||
|
phys: phys,
|
||||||
|
virt: virt
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn physical(&self) -> usize {
|
||||||
|
self.phys.address
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Deref for Dma<T> {
|
||||||
|
type Target = T;
|
||||||
|
fn deref(&self) -> &T {
|
||||||
|
unsafe { &*self.virt }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> DerefMut for Dma<T> {
|
||||||
|
fn deref_mut(&mut self) -> &mut T {
|
||||||
|
unsafe { &mut *self.virt }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Drop for Dma<T> {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
unsafe { drop(ptr::read(self.virt)); }
|
||||||
|
let _ = unsafe { syscall::physunmap(self.virt as usize) };
|
||||||
|
}
|
||||||
|
}
|
||||||
6
crates/event/Cargo.toml
Normal file
6
crates/event/Cargo.toml
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
[package]
|
||||||
|
name = "event"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
|
[dependencies.syscall]
|
||||||
|
path = "../../syscall/"
|
||||||
55
crates/event/src/lib.rs
Normal file
55
crates/event/src/lib.rs
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
#![feature(question_mark)]
|
||||||
|
|
||||||
|
extern crate syscall;
|
||||||
|
|
||||||
|
use std::collections::BTreeMap;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{Read, Error, Result};
|
||||||
|
use std::os::unix::io::RawFd;
|
||||||
|
|
||||||
|
pub struct EventQueue<R> {
|
||||||
|
/// The file to read events from
|
||||||
|
file: File,
|
||||||
|
/// A map of registered file descriptors to their handler callbacks
|
||||||
|
callbacks: BTreeMap<RawFd, Box<FnMut(usize) -> Result<Option<R>>>>
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<R> EventQueue<R> {
|
||||||
|
/// Create a new event queue
|
||||||
|
pub fn new() -> Result<EventQueue<R>> {
|
||||||
|
Ok(EventQueue {
|
||||||
|
file: File::open("event:")?,
|
||||||
|
callbacks: BTreeMap::new()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Add a file to the event queue, calling a callback when an event occurs
|
||||||
|
///
|
||||||
|
/// The callback is given a mutable reference to the file and the event data
|
||||||
|
/// (typically the length of data available for read)
|
||||||
|
///
|
||||||
|
/// The callback returns Ok(None) if it wishes to continue the event loop,
|
||||||
|
/// or Ok(Some(R)) to break the event loop and return the value.
|
||||||
|
/// Err can be used to allow the callback to return an I/O error, and break the
|
||||||
|
/// event loop
|
||||||
|
pub fn add<F: FnMut(usize) -> Result<Option<R>> + 'static>(&mut self, fd: RawFd, callback: F) -> Result<()> {
|
||||||
|
syscall::fevent(fd, syscall::EVENT_READ).map_err(|x| Error::from_sys(x))?;
|
||||||
|
|
||||||
|
self.callbacks.insert(fd, Box::new(callback));
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Process the event queue until a callback returns Some(R)
|
||||||
|
pub fn run(&mut self) -> Result<R> {
|
||||||
|
loop {
|
||||||
|
let mut event = syscall::Event::default();
|
||||||
|
self.file.read(&mut event)?;
|
||||||
|
if let Some(callback) = self.callbacks.get_mut(&event.id) {
|
||||||
|
if let Some(ret) = callback(event.data)? {
|
||||||
|
return Ok(ret);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
8
crates/hole_list_allocator/Cargo.toml
Normal file
8
crates/hole_list_allocator/Cargo.toml
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
[package]
|
||||||
|
authors = ["Philipp Oppermann <dev@phil-opp.com>"]
|
||||||
|
name = "hole_list_allocator"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
linked_list_allocator = { git = "https://github.com/phil-opp/linked-list-allocator.git" }
|
||||||
|
spin = "*"
|
||||||
62
crates/hole_list_allocator/src/lib.rs
Normal file
62
crates/hole_list_allocator/src/lib.rs
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
#![feature(allocator)]
|
||||||
|
#![feature(const_fn)]
|
||||||
|
|
||||||
|
#![allocator]
|
||||||
|
#![no_std]
|
||||||
|
|
||||||
|
use spin::Mutex;
|
||||||
|
use linked_list_allocator::Heap;
|
||||||
|
|
||||||
|
extern crate spin;
|
||||||
|
extern crate linked_list_allocator;
|
||||||
|
|
||||||
|
static HEAP: Mutex<Option<Heap>> = Mutex::new(None);
|
||||||
|
|
||||||
|
pub unsafe fn init(offset: usize, size: usize) {
|
||||||
|
*HEAP.lock() = Some(Heap::new(offset, size));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern fn __rust_allocate(size: usize, align: usize) -> *mut u8 {
|
||||||
|
if let Some(ref mut heap) = *HEAP.lock() {
|
||||||
|
heap.allocate_first_fit(size, align).expect("out of memory")
|
||||||
|
} else {
|
||||||
|
panic!("__rust_allocate: heap not initialized");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern fn __rust_deallocate(ptr: *mut u8, size: usize, align: usize) {
|
||||||
|
if let Some(ref mut heap) = *HEAP.lock() {
|
||||||
|
unsafe { heap.deallocate(ptr, size, align) };
|
||||||
|
} else {
|
||||||
|
panic!("__rust_deallocate: heap not initialized");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern fn __rust_usable_size(size: usize, _align: usize) -> usize {
|
||||||
|
size
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern fn __rust_reallocate_inplace(_ptr: *mut u8, size: usize,
|
||||||
|
_new_size: usize, _align: usize) -> usize
|
||||||
|
{
|
||||||
|
size
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern fn __rust_reallocate(ptr: *mut u8, size: usize, new_size: usize,
|
||||||
|
align: usize) -> *mut u8 {
|
||||||
|
use core::{ptr, cmp};
|
||||||
|
|
||||||
|
// from: https://github.com/rust-lang/rust/blob/
|
||||||
|
// c66d2380a810c9a2b3dbb4f93a830b101ee49cc2/
|
||||||
|
// src/liballoc_system/lib.rs#L98-L101
|
||||||
|
|
||||||
|
let new_ptr = __rust_allocate(new_size, align);
|
||||||
|
unsafe { ptr::copy(ptr, new_ptr, cmp::min(size, new_size)) };
|
||||||
|
__rust_deallocate(ptr, size, align);
|
||||||
|
new_ptr
|
||||||
|
}
|
||||||
3
crates/io/Cargo.toml
Normal file
3
crates/io/Cargo.toml
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
[package]
|
||||||
|
name = "io"
|
||||||
|
version = "0.1.0"
|
||||||
67
crates/io/src/io.rs
Normal file
67
crates/io/src/io.rs
Normal file
|
|
@ -0,0 +1,67 @@
|
||||||
|
use core::cmp::PartialEq;
|
||||||
|
use core::ops::{BitAnd, BitOr, Not};
|
||||||
|
|
||||||
|
pub trait Io {
|
||||||
|
type Value: Copy + PartialEq + BitAnd<Output = Self::Value> + BitOr<Output = Self::Value> + Not<Output = Self::Value>;
|
||||||
|
|
||||||
|
fn read(&self) -> Self::Value;
|
||||||
|
fn write(&mut self, value: Self::Value);
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
fn readf(&self, flags: Self::Value) -> bool {
|
||||||
|
(self.read() & flags) as Self::Value == flags
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
fn writef(&mut self, flags: Self::Value, value: bool) {
|
||||||
|
let tmp: Self::Value = match value {
|
||||||
|
true => self.read() | flags,
|
||||||
|
false => self.read() & !flags,
|
||||||
|
};
|
||||||
|
self.write(tmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct ReadOnly<I: Io> {
|
||||||
|
inner: I
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<I: Io> ReadOnly<I> {
|
||||||
|
pub const fn new(inner: I) -> ReadOnly<I> {
|
||||||
|
ReadOnly {
|
||||||
|
inner: inner
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn read(&self) -> I::Value {
|
||||||
|
self.inner.read()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn readf(&self, flags: I::Value) -> bool {
|
||||||
|
self.inner.readf(flags)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct WriteOnly<I: Io> {
|
||||||
|
inner: I
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<I: Io> WriteOnly<I> {
|
||||||
|
pub const fn new(inner: I) -> WriteOnly<I> {
|
||||||
|
WriteOnly {
|
||||||
|
inner: inner
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn write(&mut self, value: I::Value) {
|
||||||
|
self.inner.write(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn writef(&mut self, flags: I::Value, value: bool) {
|
||||||
|
self.inner.writef(flags, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
14
crates/io/src/lib.rs
Normal file
14
crates/io/src/lib.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
//! I/O functions
|
||||||
|
|
||||||
|
#![feature(asm)]
|
||||||
|
#![feature(const_fn)]
|
||||||
|
#![feature(core_intrinsics)]
|
||||||
|
#![no_std]
|
||||||
|
|
||||||
|
pub use self::io::*;
|
||||||
|
pub use self::mmio::*;
|
||||||
|
pub use self::pio::*;
|
||||||
|
|
||||||
|
mod io;
|
||||||
|
mod mmio;
|
||||||
|
mod pio;
|
||||||
31
crates/io/src/mmio.rs
Normal file
31
crates/io/src/mmio.rs
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
use core::intrinsics::{volatile_load, volatile_store};
|
||||||
|
use core::mem::uninitialized;
|
||||||
|
use core::ops::{BitAnd, BitOr, Not};
|
||||||
|
|
||||||
|
use super::io::Io;
|
||||||
|
|
||||||
|
#[repr(packed)]
|
||||||
|
pub struct Mmio<T> {
|
||||||
|
value: T,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Mmio<T> {
|
||||||
|
/// Create a new Mmio without initializing
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Mmio {
|
||||||
|
value: unsafe { uninitialized() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Io for Mmio<T> where T: Copy + PartialEq + BitAnd<Output = T> + BitOr<Output = T> + Not<Output = T> {
|
||||||
|
type Value = T;
|
||||||
|
|
||||||
|
fn read(&self) -> T {
|
||||||
|
unsafe { volatile_load(&self.value) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write(&mut self, value: T) {
|
||||||
|
unsafe { volatile_store(&mut self.value, value) };
|
||||||
|
}
|
||||||
|
}
|
||||||
89
crates/io/src/pio.rs
Normal file
89
crates/io/src/pio.rs
Normal file
|
|
@ -0,0 +1,89 @@
|
||||||
|
use core::marker::PhantomData;
|
||||||
|
|
||||||
|
use super::io::Io;
|
||||||
|
|
||||||
|
/// Generic PIO
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
pub struct Pio<T> {
|
||||||
|
port: u16,
|
||||||
|
value: PhantomData<T>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Pio<T> {
|
||||||
|
/// Create a PIO from a given port
|
||||||
|
pub const fn new(port: u16) -> Self {
|
||||||
|
Pio::<T> {
|
||||||
|
port: port,
|
||||||
|
value: PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Read/Write for byte PIO
|
||||||
|
impl Io for Pio<u8> {
|
||||||
|
type Value = u8;
|
||||||
|
|
||||||
|
/// Read
|
||||||
|
#[inline(always)]
|
||||||
|
fn read(&self) -> u8 {
|
||||||
|
let value: u8;
|
||||||
|
unsafe {
|
||||||
|
asm!("in $0, $1" : "={al}"(value) : "{dx}"(self.port) : "memory" : "intel", "volatile");
|
||||||
|
}
|
||||||
|
value
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Write
|
||||||
|
#[inline(always)]
|
||||||
|
fn write(&mut self, value: u8) {
|
||||||
|
unsafe {
|
||||||
|
asm!("out $1, $0" : : "{al}"(value), "{dx}"(self.port) : "memory" : "intel", "volatile");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Read/Write for word PIO
|
||||||
|
impl Io for Pio<u16> {
|
||||||
|
type Value = u16;
|
||||||
|
|
||||||
|
/// Read
|
||||||
|
#[inline(always)]
|
||||||
|
fn read(&self) -> u16 {
|
||||||
|
let value: u16;
|
||||||
|
unsafe {
|
||||||
|
asm!("in $0, $1" : "={ax}"(value) : "{dx}"(self.port) : "memory" : "intel", "volatile");
|
||||||
|
}
|
||||||
|
value
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Write
|
||||||
|
#[inline(always)]
|
||||||
|
fn write(&mut self, value: u16) {
|
||||||
|
unsafe {
|
||||||
|
asm!("out $1, $0" : : "{ax}"(value), "{dx}"(self.port) : "memory" : "intel", "volatile");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Read/Write for doubleword PIO
|
||||||
|
impl Io for Pio<u32> {
|
||||||
|
type Value = u32;
|
||||||
|
|
||||||
|
/// Read
|
||||||
|
#[inline(always)]
|
||||||
|
fn read(&self) -> u32 {
|
||||||
|
let value: u32;
|
||||||
|
unsafe {
|
||||||
|
asm!("in $0, $1" : "={eax}"(value) : "{dx}"(self.port) : "memory" : "intel", "volatile");
|
||||||
|
}
|
||||||
|
value
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Write
|
||||||
|
#[inline(always)]
|
||||||
|
fn write(&mut self, value: u32) {
|
||||||
|
unsafe {
|
||||||
|
asm!("out $1, $0" : : "{eax}"(value), "{dx}"(self.port) : "memory" : "intel", "volatile");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
6
crates/resource_scheme/Cargo.toml
Normal file
6
crates/resource_scheme/Cargo.toml
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
[package]
|
||||||
|
name = "resource_scheme"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
|
[dependencies.syscall]
|
||||||
|
path = "../../syscall/"
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue