diff --git a/kernel/Cargo.lock b/kernel/Cargo.lock index 1ea185d..702c095 100644 --- a/kernel/Cargo.lock +++ b/kernel/Cargo.lock @@ -230,7 +230,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "mips" version = "0.1.0" -source = "git+https://github.com/Harry-Chen/rust-mips#e2cea12fc88f1f5a788a155972cd4047e7ad2b4f" +source = "git+https://github.com/Harry-Chen/rust-mips#bee9865920bceef12dbb527c1c237de905129c0b" dependencies = [ "bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index 2ce9880..74ab119 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -26,8 +26,9 @@ board_u540 = ["sv39", "link_user"] nographic = [] board_raspi3 = ["bcm2837", "link_user"] raspi3_use_generic_timer = ["bcm2837/use_generic_timer"] -# for mipsel qemu malta machine +# for qemu machine board_malta = ["link_user"] +board_mipssim = ["link_user"] # for thinpad board_thinpad = ["link_user"] # Hard link user program diff --git a/kernel/Makefile b/kernel/Makefile index 31ff5eb..8d7fc9e 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -68,6 +68,11 @@ ifeq ($(arch), mipsel) dtb := src/arch/$(arch)/board/$(board)/device.dtb endif +# mipssim does not support SMP +ifeq ($(board), mipssim) +smp := 1 +endif + export ARCH = $(arch) export BOARD = $(board) export SMP = $(smp) @@ -129,7 +134,7 @@ qemu_opts += \ -kernel $(kernel_img) else ifeq ($(arch), mipsel) -ifeq ($(board), malta) +ifeq ($(board), $(filter $(board), malta mipssim)) qemu_opts += \ -machine $(board) \ -serial mon:stdio \ diff --git a/kernel/src/arch/mipsel/board/malta/consts.rs b/kernel/src/arch/mipsel/board/malta/consts.rs index 5f1f8f5..73ff966 100644 --- a/kernel/src/arch/mipsel/board/malta/consts.rs +++ b/kernel/src/arch/mipsel/board/malta/consts.rs @@ -1,3 +1,3 @@ -/// board specific constants for malta +/// board specific constants pub const MEMORY_END: usize = 0x8800_0000; pub const KERNEL_HEAP_SIZE: usize = 0x00a0_0000; diff --git a/kernel/src/arch/mipsel/board/malta/mod.rs b/kernel/src/arch/mipsel/board/malta/mod.rs index 05b27b7..0c594ef 100644 --- a/kernel/src/arch/mipsel/board/malta/mod.rs +++ b/kernel/src/arch/mipsel/board/malta/mod.rs @@ -1,6 +1,7 @@ use once::*; use alloc::string::String; +#[path = "../../../../drivers/serial/16550_reg.rs"] pub mod serial; #[path = "../../../../drivers/gpu/fb.rs"] pub mod fb; @@ -21,6 +22,6 @@ pub fn init_driver() { // timer::init(); } -pub fn probe_fb_info(width: u32, height: u32, depth: u32) -> Result<(fb::FramebufferInfo, usize), String> { +pub fn probe_fb_info(_width: u32, _height: u32, _depth: u32) -> Result<(fb::FramebufferInfo, usize), String> { Err(String::from("Framebuffer not usable on malta board")) } \ No newline at end of file diff --git a/kernel/src/arch/mipsel/board/mipssim/consts.rs b/kernel/src/arch/mipsel/board/mipssim/consts.rs new file mode 100644 index 0000000..73ff966 --- /dev/null +++ b/kernel/src/arch/mipsel/board/mipssim/consts.rs @@ -0,0 +1,3 @@ +/// board specific constants +pub const MEMORY_END: usize = 0x8800_0000; +pub const KERNEL_HEAP_SIZE: usize = 0x00a0_0000; diff --git a/kernel/src/arch/mipsel/board/mipssim/device.dts b/kernel/src/arch/mipsel/board/mipssim/device.dts new file mode 100644 index 0000000..2e99f7b --- /dev/null +++ b/kernel/src/arch/mipsel/board/mipssim/device.dts @@ -0,0 +1,36 @@ +/dts-v1/; + + +/ { + model = "qemu mipssim"; + compatible = "qemu,mipssim"; + #address-cells = <1>; + #size-cells = <1>; + + chosen { + stdio = &uart0; + }; + + aliases { }; + + cpu_intc: interrupt-controller { + compatible = "mti,cpu-interrupt-controller"; + interrupt-controller; + #interrupt-cells = <1>; + }; + + main_memory: memory@0 { + device_type = "memory"; + reg = <0x00000000 0x10000000>; + }; + + uart0: serial@bfd003f8 { + compatible = "ns16550a"; + reg = <0xbfd003f8 0x8>; + clock-frequency = <1843200>; + /* attached to the MIPS CPU INT2 pin, ie interrupt 4 */ + interrupt-parent = <&cpu_intc>; + interrupts = <4>; + }; + +}; diff --git a/kernel/src/arch/mipsel/board/mipssim/mod.rs b/kernel/src/arch/mipsel/board/mipssim/mod.rs new file mode 100644 index 0000000..6633d7d --- /dev/null +++ b/kernel/src/arch/mipsel/board/mipssim/mod.rs @@ -0,0 +1,27 @@ +use once::*; +use alloc::string::String; + +#[path = "../../../../drivers/serial/16550_reg.rs"] +pub mod serial; +#[path = "../../../../drivers/gpu/fb.rs"] +pub mod fb; +#[path = "../../../../drivers/console/mod.rs"] +pub mod console; +pub mod consts; + +/// Initialize serial port first +pub fn init_serial_early() { + assert_has_not_been_called!("board::init must be called only once"); + serial::init(0xbfd003f8); + println!("Hello QEMU MIPSSIM!"); +} + +/// Initialize other board drivers +pub fn init_driver() { + // TODO: add possibly more drivers + // timer::init(); +} + +pub fn probe_fb_info(_width: u32, _height: u32, _depth: u32) -> Result<(fb::FramebufferInfo, usize), String> { + Err(String::from("Framebuffer not usable on mipssim board")) +} \ No newline at end of file diff --git a/kernel/src/arch/mipsel/board/thinpad/consts.rs b/kernel/src/arch/mipsel/board/thinpad/consts.rs index 9a10cde..b59309a 100644 --- a/kernel/src/arch/mipsel/board/thinpad/consts.rs +++ b/kernel/src/arch/mipsel/board/thinpad/consts.rs @@ -1,3 +1,3 @@ -/// board specific constants for thinpad +/// board specific constants pub const MEMORY_END: usize = 0x8080_0000; pub const KERNEL_HEAP_SIZE: usize = 0x0020_0000; diff --git a/kernel/src/arch/mipsel/board/thinpad/mod.rs b/kernel/src/arch/mipsel/board/thinpad/mod.rs index 358197f..1ebf3d1 100644 --- a/kernel/src/arch/mipsel/board/thinpad/mod.rs +++ b/kernel/src/arch/mipsel/board/thinpad/mod.rs @@ -1,6 +1,7 @@ use once::*; use alloc::string::String; +#[path = "../../../../drivers/serial/simple_uart.rs"] pub mod serial; #[path = "../../../../drivers/gpu/fb.rs"] pub mod fb; diff --git a/kernel/src/arch/mipsel/mod.rs b/kernel/src/arch/mipsel/mod.rs index e4d78b0..6347d3c 100644 --- a/kernel/src/arch/mipsel/mod.rs +++ b/kernel/src/arch/mipsel/mod.rs @@ -22,6 +22,11 @@ pub mod board; #[path = "board/thinpad/mod.rs"] pub mod board; +#[cfg(feature = "board_mipssim")] +#[path = "board/mipssim/mod.rs"] +pub mod board; + + extern "C" { fn _dtb_start(); fn _dtb_end(); diff --git a/kernel/src/arch/mipsel/board/malta/serial.rs b/kernel/src/drivers/serial/16550_reg.rs similarity index 100% rename from kernel/src/arch/mipsel/board/malta/serial.rs rename to kernel/src/drivers/serial/16550_reg.rs diff --git a/kernel/src/arch/mipsel/board/thinpad/serial.rs b/kernel/src/drivers/serial/simple_uart.rs similarity index 100% rename from kernel/src/arch/mipsel/board/thinpad/serial.rs rename to kernel/src/drivers/serial/simple_uart.rs