diff --git a/.gitignore b/.gitignore index 021a507..b2b7748 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ build target /kernel/src/arch/x86_64/interrupt/vector.asm +/kernel/src/arch/mipsel/boot/linker.ld *.gen.s *.dtb diff --git a/kernel/Makefile b/kernel/Makefile index b0ccb2a..b6620a4 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -346,8 +346,9 @@ else ifeq ($(arch), aarch64) @cargo xbuild $(build_args) else ifeq ($(arch), mipsel) @for file in context entry trap ; do \ - $(hostcc) -E src/arch/$(arch)/boot/$${file}.S -o src/arch/$(arch)/boot/$${file}.gen.s ; \ + $(hostcc) -Dboard_$(board) -E src/arch/$(arch)/boot/$${file}.S -o src/arch/$(arch)/boot/$${file}.gen.s ; \ done + $(hostcc) -Dboard_$(board) -E src/arch/$(arch)/boot/linker.ld.S -o src/arch/$(arch)/boot/linker.ld @cargo xbuild $(build_args) endif diff --git a/kernel/src/arch/mipsel/board/malta/consts.rs b/kernel/src/arch/mipsel/board/malta/consts.rs index c16d545..8f6fbe7 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 -pub const MEMORY_END: usize = 0x8800_0000; -pub const KERNEL_HEAP_SIZE: usize = 0x0044_0000; +pub const MEMORY_END: usize = 0x8090_0000; +pub const KERNEL_HEAP_SIZE: usize = 0x003b_0000; diff --git a/kernel/src/arch/mipsel/board/malta/device.dts b/kernel/src/arch/mipsel/board/malta/device.dts index bbe1e66..bee60a4 100644 --- a/kernel/src/arch/mipsel/board/malta/device.dts +++ b/kernel/src/arch/mipsel/board/malta/device.dts @@ -9,7 +9,7 @@ chosen { stdio = &uart2; - bootargs = "rust/sh"; + bootargs = "sh"; }; aliases { }; diff --git a/kernel/src/arch/mipsel/board/thinpad/consts.rs b/kernel/src/arch/mipsel/board/thinpad/consts.rs index 98f0a5e..db1971f 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 pub const MEMORY_END: usize = 0x8080_0000; -pub const KERNEL_HEAP_SIZE: usize = 0x0044_0000; +pub const KERNEL_HEAP_SIZE: usize = 0x0038_0000; diff --git a/kernel/src/arch/mipsel/board/thinpad/device.dts b/kernel/src/arch/mipsel/board/thinpad/device.dts index 5a771c9..ef41be8 100644 --- a/kernel/src/arch/mipsel/board/thinpad/device.dts +++ b/kernel/src/arch/mipsel/board/thinpad/device.dts @@ -9,7 +9,7 @@ chosen { stdio = &uart; - bootargs = ""; + bootargs = "sh"; }; aliases { }; diff --git a/kernel/src/arch/mipsel/boot/linker.ld b/kernel/src/arch/mipsel/boot/linker.ld.S similarity index 93% rename from kernel/src/arch/mipsel/boot/linker.ld rename to kernel/src/arch/mipsel/boot/linker.ld.S index 13adcfc..e231659 100644 --- a/kernel/src/arch/mipsel/boot/linker.ld +++ b/kernel/src/arch/mipsel/boot/linker.ld.S @@ -4,7 +4,11 @@ OUTPUT_ARCH(riscv) ENTRY(_start) +#ifdef board_thinpad +BASE_ADDRESS = 0x80000000; +#else BASE_ADDRESS = 0x80100000; +#endif SECTIONS { diff --git a/kernel/src/arch/mipsel/boot/trap.S b/kernel/src/arch/mipsel/boot/trap.S index 07b7ffa..012d792 100644 --- a/kernel/src/arch/mipsel/boot/trap.S +++ b/kernel/src/arch/mipsel/boot/trap.S @@ -32,6 +32,12 @@ trap_from_kernel: * k1 = old stack pointer * sp = kernel stack */ +#ifdef board_thinpad +#define TRAPFRAME_SIZE 304 +#else +#define TRAPFRAME_SIZE 176 +#endif + # align stack pointer andi k0, sp, 0xf beqz k0, sp_aligned @@ -39,12 +45,13 @@ trap_from_kernel: la k0, 0xfffffff0 and k0, sp, k0 - sw sp, -176(k0) + sw sp, -TRAPFRAME_SIZE(k0) move sp, k0 sp_aligned: - # allocate 38 words for trapframe + 6 extra words - addiu sp, sp, -176 + # allocate 38 / 70 words for trapframe + 6 extra words + + addiu sp, sp, -TRAPFRAME_SIZE # save general registers sw ra, 160(sp) @@ -80,6 +87,42 @@ sp_aligned: sw AT, 40(sp) nop +#ifdef board_thinpad + # save floating point registers + swc1 $f0, 164(sp) + swc1 $f1, 168(sp) + swc1 $f2, 172(sp) + swc1 $f3, 176(sp) + swc1 $f4, 180(sp) + swc1 $f5, 184(sp) + swc1 $f6, 188(sp) + swc1 $f7, 192(sp) + swc1 $f8, 196(sp) + swc1 $f9, 200(sp) + swc1 $f10, 204(sp) + swc1 $f11, 208(sp) + swc1 $f12, 212(sp) + swc1 $f13, 216(sp) + swc1 $f14, 220(sp) + swc1 $f15, 224(sp) + swc1 $f16, 228(sp) + swc1 $f17, 232(sp) + swc1 $f18, 236(sp) + swc1 $f19, 240(sp) + swc1 $f20, 244(sp) + swc1 $f21, 248(sp) + swc1 $f22, 252(sp) + swc1 $f23, 256(sp) + swc1 $f24, 260(sp) + swc1 $f25, 264(sp) + swc1 $f26, 268(sp) + swc1 $f27, 272(sp) + swc1 $f28, 276(sp) + swc1 $f29, 280(sp) + swc1 $f30, 284(sp) + swc1 $f31, 288(sp) +#endif + # save hi/lo mflo t1 sw t1, 36(sp) @@ -158,9 +201,45 @@ trap_return: lw fp, 156(sp) lw ra, 160(sp) +#ifdef board_thinpad + # restore floating point registers + lwc1 $f0, 164(sp) + lwc1 $f1, 168(sp) + lwc1 $f2, 172(sp) + lwc1 $f3, 176(sp) + lwc1 $f4, 180(sp) + lwc1 $f5, 184(sp) + lwc1 $f6, 188(sp) + lwc1 $f7, 192(sp) + lwc1 $f8, 196(sp) + lwc1 $f9, 200(sp) + lwc1 $f10, 204(sp) + lwc1 $f11, 208(sp) + lwc1 $f12, 212(sp) + lwc1 $f13, 216(sp) + lwc1 $f14, 220(sp) + lwc1 $f15, 224(sp) + lwc1 $f16, 228(sp) + lwc1 $f17, 232(sp) + lwc1 $f18, 236(sp) + lwc1 $f19, 240(sp) + lwc1 $f20, 244(sp) + lwc1 $f21, 248(sp) + lwc1 $f22, 252(sp) + lwc1 $f23, 256(sp) + lwc1 $f24, 260(sp) + lwc1 $f25, 264(sp) + lwc1 $f26, 268(sp) + lwc1 $f27, 272(sp) + lwc1 $f28, 276(sp) + lwc1 $f29, 280(sp) + lwc1 $f30, 284(sp) + lwc1 $f31, 288(sp) +#endif + # save kernel stack lw k0, 0(sp) - addiu k1, sp, 176 + addiu k1, sp, TRAPFRAME_SIZE movn k1, k0, k0 la k0, _cur_kstack_ptr diff --git a/kernel/src/arch/mipsel/consts.rs b/kernel/src/arch/mipsel/consts.rs index 48a48d3..e1e5a28 100644 --- a/kernel/src/arch/mipsel/consts.rs +++ b/kernel/src/arch/mipsel/consts.rs @@ -2,11 +2,16 @@ /// pub use super::board::consts::*; -pub const MEMORY_OFFSET: usize = 0x80000000; -pub const KERNEL_OFFSET: usize = 0x80100000; -pub const PHYSICAL_MEMORY_OFFSET: usize = 0x80000000; +pub const MEMORY_OFFSET: usize = 0x8000_0000; -pub const USER_STACK_OFFSET: usize = 0x70000000 - USER_STACK_SIZE; +#[cfg(feature = "board_thinpad")] +pub const KERNEL_OFFSET: usize = 0x8000_0000; +#[cfg(feature = "board_malta")] +pub const KERNEL_OFFSET: usize = 0x8010_0000; + +pub const PHYSICAL_MEMORY_OFFSET: usize = 0x8000_0000; + +pub const USER_STACK_OFFSET: usize = 0x7000_0000 - USER_STACK_SIZE; pub const USER_STACK_SIZE: usize = 0x10000; pub const MAX_DTB_SIZE: usize = 0x2000; diff --git a/kernel/src/arch/mipsel/context.rs b/kernel/src/arch/mipsel/context.rs index 116e9f0..9441313 100644 --- a/kernel/src/arch/mipsel/context.rs +++ b/kernel/src/arch/mipsel/context.rs @@ -52,6 +52,39 @@ pub struct TrapFrame { pub sp: usize, pub fp: usize, pub ra: usize, + /// Floating-point registers (contains garbage if no FP support present) + pub f0: usize, + pub f1: usize, + pub f2: usize, + pub f3: usize, + pub f4: usize, + pub f5: usize, + pub f6: usize, + pub f7: usize, + pub f8: usize, + pub f9: usize, + pub f10: usize, + pub f11: usize, + pub f12: usize, + pub f13: usize, + pub f14: usize, + pub f15: usize, + pub f16: usize, + pub f17: usize, + pub f18: usize, + pub f19: usize, + pub f20: usize, + pub f21: usize, + pub f22: usize, + pub f23: usize, + pub f24: usize, + pub f25: usize, + pub f26: usize, + pub f27: usize, + pub f28: usize, + pub f29: usize, + pub f30: usize, + pub f31: usize, /// Reserved pub reserved: usize, pub __padding: [usize; 2], diff --git a/kernel/src/drivers/serial/16550_reg.rs b/kernel/src/drivers/serial/16550_reg.rs index 424b839..e4d7dc0 100644 --- a/kernel/src/drivers/serial/16550_reg.rs +++ b/kernel/src/drivers/serial/16550_reg.rs @@ -68,12 +68,19 @@ impl SerialPort { impl Write for SerialPort { fn write_str(&mut self, s: &str) -> Result { for c in s.bytes() { - if c == 127 { - self.putchar(8); - self.putchar(b' '); - self.putchar(8); - } else { - self.putchar(c); + match c { + 127 => { + self.putchar(8); + self.putchar(b' '); + self.putchar(8); + }, + b'\n' => { + self.putchar(b'\r'); + self.putchar(b'\n'); + }, + c => { + self.putchar(c); + } } } Ok(()) diff --git a/kernel/src/drivers/serial/simple_uart.rs b/kernel/src/drivers/serial/simple_uart.rs index ee5c569..584fc33 100644 --- a/kernel/src/drivers/serial/simple_uart.rs +++ b/kernel/src/drivers/serial/simple_uart.rs @@ -59,12 +59,19 @@ impl SerialPort { impl Write for SerialPort { fn write_str(&mut self, s: &str) -> Result { for c in s.bytes() { - if c == 127 { - self.putchar(8); - self.putchar(b' '); - self.putchar(8); - } else { - self.putchar(c); + match c { + 127 => { + self.putchar(8); + self.putchar(b' '); + self.putchar(8); + }, + b'\n' => { + self.putchar(b'\r'); + self.putchar(b'\n'); + }, + c => { + self.putchar(c); + } } } Ok(()) diff --git a/kernel/src/drivers/serial/ti_16c550c.rs b/kernel/src/drivers/serial/ti_16c550c.rs index 4f5b51a..e4b1973 100644 --- a/kernel/src/drivers/serial/ti_16c550c.rs +++ b/kernel/src/drivers/serial/ti_16c550c.rs @@ -68,12 +68,19 @@ impl SerialPort { impl Write for SerialPort { fn write_str(&mut self, s: &str) -> Result { for c in s.bytes() { - if c == 127 { - self.putchar(8); - self.putchar(b' '); - self.putchar(8); - } else { - self.putchar(c); + match c { + 127 => { + self.putchar(8); + self.putchar(b' '); + self.putchar(8); + }, + b'\n' => { + self.putchar(b'\r'); + self.putchar(b'\n'); + }, + c => { + self.putchar(c); + } } } Ok(()) diff --git a/kernel/src/syscall/mod.rs b/kernel/src/syscall/mod.rs index b50c80a..b20b092 100644 --- a/kernel/src/syscall/mod.rs +++ b/kernel/src/syscall/mod.rs @@ -289,7 +289,8 @@ impl Syscall<'_> { ), SYS_GETRANDOM => { self.sys_getrandom(args[0] as *mut u8, args[1] as usize, args[2] as u32) - } + }, + SYS_RT_SIGQUEUEINFO => self.unimplemented("rt_sigqueueinfo", Ok(0)), // custom SYS_MAP_PCI_DEVICE => self.sys_map_pci_device(args[0], args[1]), diff --git a/kernel/targets/mipsel.json b/kernel/targets/mipsel.json index 346e3e8..7cc6d7d 100644 --- a/kernel/targets/mipsel.json +++ b/kernel/targets/mipsel.json @@ -7,7 +7,7 @@ "target-pointer-width": "32", "target-c-int-width": "32", "os": "none", - "features": "+mips32r2,+soft-float", + "features": "+mips32r2,+single-float", "max-atomic-width": "32", "linker": "rust-lld", "linker-flavor": "ld.lld",