From 85afa2b4377db079494b7c8a829f9c8086965097 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Wed, 16 Jan 2019 22:30:06 +0100 Subject: [PATCH] pci first commit --- kernel-rs/mk/qemu.mk | 8 +++++--- kernel-rs/src/console.rs | 10 ++++++---- kernel-rs/src/lib.rs | 5 +++-- kernel-rs/src/pci/mod.rs | 22 ++++++++++++++++++++++ 4 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 kernel-rs/src/pci/mod.rs diff --git a/kernel-rs/mk/qemu.mk b/kernel-rs/mk/qemu.mk index e5f89e2d..99fbe143 100644 --- a/kernel-rs/mk/qemu.mk +++ b/kernel-rs/mk/qemu.mk @@ -12,7 +12,8 @@ qemu: -monitor unix:${QEMU_SOCKET},server,nowait qemu-gdb: - gdb -q\ + gdb\ + -q\ -symbols "$(KERNEL)" \ -ex "target remote :$(QEMU_GDB_PORT)"\ -ex "set arch i386" @@ -20,5 +21,6 @@ qemu-gdb: qemu-monitor: $(QEMU_MONITOR) qemu-reload: - echo "change ide1-cd0 $(ISO)" | $(QEMU_MONITOR) &>- - echo "system_reset" | $(QEMU_MONITOR) &>- + echo "stop" | $(QEMU_MONITOR) &>/dev/null + echo "change ide1-cd0 $(ISO)" | $(QEMU_MONITOR) &>/dev/null + echo "system_reset" | $(QEMU_MONITOR) &>/dev/null diff --git a/kernel-rs/src/console.rs b/kernel-rs/src/console.rs index 963d37ac..b0d7e09a 100644 --- a/kernel-rs/src/console.rs +++ b/kernel-rs/src/console.rs @@ -54,7 +54,11 @@ impl Console { } b'\n' => { unsafe { VGA.write_byte(b'\n'); } - self.exec(); + if let Err(msg) = self.exec() { + set_color!(Red); + println!("{}", msg); + set_color!(); + } self.command_len = 0; self.prompt(); } @@ -83,9 +87,7 @@ impl Console { pub fn exec(&self) -> core::result::Result<(), &'static str> { let command = self.get_command(); if let Err(msg) = command { - set_color!(Red); - println!("{}", msg); - set_color!(); + return Err(msg) } match command.unwrap() { "help" | "h" => self::help(), diff --git a/kernel-rs/src/lib.rs b/kernel-rs/src/lib.rs index c29bcad3..c58b1d51 100644 --- a/kernel-rs/src/lib.rs +++ b/kernel-rs/src/lib.rs @@ -24,6 +24,8 @@ extern crate rlibc; extern crate slab_allocator; extern crate spin; +extern crate bitflags; + // used by arch/x86, need conditional compilation here extern crate x86; @@ -44,7 +46,7 @@ pub mod pci; /// calling this once the core has loaded pub fn kmain() -> ! { // memory init after heap is available - memory::init_noncore(); + // memory::init_noncore(); // unsafe VGA unsafe { console::CONSOLE.init(); } @@ -68,5 +70,4 @@ pub extern "C" fn panic_fmt(info: &core::panic::PanicInfo) -> ! { } #[global_allocator] -// pub static ALLOCATOR: slab_allocator::LockedHeap = allocator::ALLOCATOR; pub static ALLOCATOR: slab_allocator::LockedHeap = slab_allocator::LockedHeap::empty(); diff --git a/kernel-rs/src/pci/mod.rs b/kernel-rs/src/pci/mod.rs new file mode 100644 index 00000000..2440fe82 --- /dev/null +++ b/kernel-rs/src/pci/mod.rs @@ -0,0 +1,22 @@ +// https://wiki.osdev.org/PCI + +use x86::devices::io::{Pio}; + +pub static mut PCI_CONFIG_ADDRESS: Pio = Pio::new(0xCF8); +pub static mut PCI_CONFIG_DATA: Pio = Pio::new(0xCFC); + +pub fn lspci() { + pci_config_read_word(1, 1, 1, 2); +} + +pub fn pci_config_read_word(bus: u32, slot: u32, func: u32, offset: u32) { + // let address: u64 = (bus as u32) << 16 + // | (slot as u32) << 11 + // | (func as u32) << 8 + // | (offset as u32) & 0xfc + // | 0x80000000; + let address: u64 = 0x80000000; + println!("{} {} {} {}", bus, slot, func, offset); + println!("{:#x}", address); + println!("{:#b}", address); +}