From 75b67fa5753f33ae9ec4e0b8e65bb29834d7b412 Mon Sep 17 00:00:00 2001 From: Harry Chen Date: Fri, 10 May 2019 17:25:49 +0800 Subject: [PATCH 01/11] Replace \n to \r\n in serial driver Signed-off-by: Harry Chen --- kernel/src/drivers/serial/16550_reg.rs | 19 +++++++++++++------ kernel/src/drivers/serial/simple_uart.rs | 19 +++++++++++++------ kernel/src/drivers/serial/ti_16c550c.rs | 19 +++++++++++++------ 3 files changed, 39 insertions(+), 18 deletions(-) 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(()) From 6add7002fd7b365f9b6cfe6ceda2855152b5b020 Mon Sep 17 00:00:00 2001 From: Yuhao Zhou Date: Sun, 12 May 2019 22:56:34 +0800 Subject: [PATCH 02/11] Update consts for MIPS.malta --- kernel/src/arch/mipsel/board/malta/consts.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/src/arch/mipsel/board/malta/consts.rs b/kernel/src/arch/mipsel/board/malta/consts.rs index 98f0a5e..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 = 0x8080_0000; -pub const KERNEL_HEAP_SIZE: usize = 0x0044_0000; +pub const MEMORY_END: usize = 0x8090_0000; +pub const KERNEL_HEAP_SIZE: usize = 0x003b_0000; From 6b7aa5ae59a76387e0f89766d94ef4113ed440fa Mon Sep 17 00:00:00 2001 From: Harry Chen Date: Mon, 13 May 2019 20:18:28 +0800 Subject: [PATCH 03/11] Bump user to latest version Signed-off-by: Harry Chen --- user | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user b/user index ad822e6..822cd03 160000 --- a/user +++ b/user @@ -1 +1 @@ -Subproject commit ad822e6d3b626b598874bb52a407e90f549c5ab9 +Subproject commit 822cd0336855b8648424b10cebcaa0b7c944dbca From d261b4e0b35b448dbbf4a1a9038dc414d0e9a743 Mon Sep 17 00:00:00 2001 From: Harry Chen Date: Mon, 13 May 2019 21:18:25 +0800 Subject: [PATCH 04/11] Save/restore FP registers when context switching (broken mipsel arch) Signed-off-by: Harry Chen --- kernel/Makefile | 2 +- kernel/src/arch/mipsel/boot/trap.S | 85 +++++++++++++++++++++++++++- kernel/src/arch/mipsel/context.rs | 33 +++++++++++ kernel/src/arch/mipsel/driver/mod.rs | 2 +- kernel/targets/mipsel.json | 2 +- 5 files changed, 118 insertions(+), 6 deletions(-) diff --git a/kernel/Makefile b/kernel/Makefile index b0ccb2a..275d0b7 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -346,7 +346,7 @@ 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 @cargo xbuild $(build_args) endif diff --git a/kernel/src/arch/mipsel/boot/trap.S b/kernel/src/arch/mipsel/boot/trap.S index 07b7ffa..4ec8650 100644 --- a/kernel/src/arch/mipsel/boot/trap.S +++ b/kernel/src/arch/mipsel/boot/trap.S @@ -43,8 +43,15 @@ trap_from_kernel: 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 + +#ifdef board_thinpad +#define TRAPFRAME_SIZE 304 +#else +#define TRAPFRAME_SIZE 176 +#endif + + 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/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/arch/mipsel/driver/mod.rs b/kernel/src/arch/mipsel/driver/mod.rs index 071142b..206d601 100644 --- a/kernel/src/arch/mipsel/driver/mod.rs +++ b/kernel/src/arch/mipsel/driver/mod.rs @@ -10,7 +10,7 @@ pub mod console; /// Initialize common drivers pub fn init() { board::init_driver(); - console::init(); + // console::init(); if let Some(con) = console::CONSOLE.lock().as_mut() { con.clear(); } 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", From 297c9d453df5ad5a51cf57d87faeee18b4d50bb1 Mon Sep 17 00:00:00 2001 From: Yuhao Zhou Date: Mon, 13 May 2019 22:20:52 +0800 Subject: [PATCH 05/11] Fix trapframe. --- kernel/src/arch/mipsel/boot/trap.S | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/kernel/src/arch/mipsel/boot/trap.S b/kernel/src/arch/mipsel/boot/trap.S index 4ec8650..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,18 +45,12 @@ 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 / 70 words for trapframe + 6 extra words -#ifdef board_thinpad -#define TRAPFRAME_SIZE 304 -#else -#define TRAPFRAME_SIZE 176 -#endif - addiu sp, sp, -TRAPFRAME_SIZE # save general registers From 6a83de78465d5a17dddb90ef57d9046f0c658bee Mon Sep 17 00:00:00 2001 From: Harry Chen Date: Mon, 13 May 2019 23:53:47 +0800 Subject: [PATCH 06/11] Revert "Fix trapframe." This reverts commit 297c9d453df5ad5a51cf57d87faeee18b4d50bb1. --- kernel/src/arch/mipsel/boot/trap.S | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/kernel/src/arch/mipsel/boot/trap.S b/kernel/src/arch/mipsel/boot/trap.S index 012d792..4ec8650 100644 --- a/kernel/src/arch/mipsel/boot/trap.S +++ b/kernel/src/arch/mipsel/boot/trap.S @@ -32,12 +32,6 @@ 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 @@ -45,12 +39,18 @@ trap_from_kernel: la k0, 0xfffffff0 and k0, sp, k0 - sw sp, -TRAPFRAME_SIZE(k0) + sw sp, -176(k0) move sp, k0 sp_aligned: # allocate 38 / 70 words for trapframe + 6 extra words +#ifdef board_thinpad +#define TRAPFRAME_SIZE 304 +#else +#define TRAPFRAME_SIZE 176 +#endif + addiu sp, sp, -TRAPFRAME_SIZE # save general registers From b8f4ee2ce80bfa6e6401e76fc0766c7c9829467d Mon Sep 17 00:00:00 2001 From: Harry Chen Date: Mon, 13 May 2019 23:53:52 +0800 Subject: [PATCH 07/11] Revert "Save/restore FP registers when context switching (broken mipsel arch)" This reverts commit d261b4e0b35b448dbbf4a1a9038dc414d0e9a743. --- kernel/Makefile | 2 +- kernel/src/arch/mipsel/boot/trap.S | 85 +--------------------------- kernel/src/arch/mipsel/context.rs | 33 ----------- kernel/src/arch/mipsel/driver/mod.rs | 2 +- kernel/targets/mipsel.json | 2 +- 5 files changed, 6 insertions(+), 118 deletions(-) diff --git a/kernel/Makefile b/kernel/Makefile index 275d0b7..b0ccb2a 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -346,7 +346,7 @@ else ifeq ($(arch), aarch64) @cargo xbuild $(build_args) else ifeq ($(arch), mipsel) @for file in context entry trap ; do \ - $(hostcc) -Dboard_$(board) -E src/arch/$(arch)/boot/$${file}.S -o src/arch/$(arch)/boot/$${file}.gen.s ; \ + $(hostcc) -E src/arch/$(arch)/boot/$${file}.S -o src/arch/$(arch)/boot/$${file}.gen.s ; \ done @cargo xbuild $(build_args) endif diff --git a/kernel/src/arch/mipsel/boot/trap.S b/kernel/src/arch/mipsel/boot/trap.S index 4ec8650..07b7ffa 100644 --- a/kernel/src/arch/mipsel/boot/trap.S +++ b/kernel/src/arch/mipsel/boot/trap.S @@ -43,15 +43,8 @@ trap_from_kernel: move sp, k0 sp_aligned: - # allocate 38 / 70 words for trapframe + 6 extra words - -#ifdef board_thinpad -#define TRAPFRAME_SIZE 304 -#else -#define TRAPFRAME_SIZE 176 -#endif - - addiu sp, sp, -TRAPFRAME_SIZE + # allocate 38 words for trapframe + 6 extra words + addiu sp, sp, -176 # save general registers sw ra, 160(sp) @@ -87,42 +80,6 @@ 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) @@ -201,45 +158,9 @@ 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, TRAPFRAME_SIZE + addiu k1, sp, 176 movn k1, k0, k0 la k0, _cur_kstack_ptr diff --git a/kernel/src/arch/mipsel/context.rs b/kernel/src/arch/mipsel/context.rs index 9441313..116e9f0 100644 --- a/kernel/src/arch/mipsel/context.rs +++ b/kernel/src/arch/mipsel/context.rs @@ -52,39 +52,6 @@ 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/arch/mipsel/driver/mod.rs b/kernel/src/arch/mipsel/driver/mod.rs index 206d601..071142b 100644 --- a/kernel/src/arch/mipsel/driver/mod.rs +++ b/kernel/src/arch/mipsel/driver/mod.rs @@ -10,7 +10,7 @@ pub mod console; /// Initialize common drivers pub fn init() { board::init_driver(); - // console::init(); + console::init(); if let Some(con) = console::CONSOLE.lock().as_mut() { con.clear(); } diff --git a/kernel/targets/mipsel.json b/kernel/targets/mipsel.json index 7cc6d7d..346e3e8 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,+single-float", + "features": "+mips32r2,+soft-float", "max-atomic-width": "32", "linker": "rust-lld", "linker-flavor": "ld.lld", From 6544093dc6e04ea3b8dbb91fc324053ac2087dc5 Mon Sep 17 00:00:00 2001 From: Harry Chen Date: Tue, 14 May 2019 00:11:22 +0800 Subject: [PATCH 08/11] Revert "Revert "Save/restore FP registers when context switching (broken mipsel arch)"" This reverts commit b8f4ee2ce80bfa6e6401e76fc0766c7c9829467d. --- kernel/Makefile | 2 +- kernel/src/arch/mipsel/boot/trap.S | 85 +++++++++++++++++++++++++++- kernel/src/arch/mipsel/context.rs | 33 +++++++++++ kernel/src/arch/mipsel/driver/mod.rs | 2 +- kernel/targets/mipsel.json | 2 +- 5 files changed, 118 insertions(+), 6 deletions(-) diff --git a/kernel/Makefile b/kernel/Makefile index b0ccb2a..275d0b7 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -346,7 +346,7 @@ 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 @cargo xbuild $(build_args) endif diff --git a/kernel/src/arch/mipsel/boot/trap.S b/kernel/src/arch/mipsel/boot/trap.S index 07b7ffa..4ec8650 100644 --- a/kernel/src/arch/mipsel/boot/trap.S +++ b/kernel/src/arch/mipsel/boot/trap.S @@ -43,8 +43,15 @@ trap_from_kernel: 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 + +#ifdef board_thinpad +#define TRAPFRAME_SIZE 304 +#else +#define TRAPFRAME_SIZE 176 +#endif + + 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/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/arch/mipsel/driver/mod.rs b/kernel/src/arch/mipsel/driver/mod.rs index 071142b..206d601 100644 --- a/kernel/src/arch/mipsel/driver/mod.rs +++ b/kernel/src/arch/mipsel/driver/mod.rs @@ -10,7 +10,7 @@ pub mod console; /// Initialize common drivers pub fn init() { board::init_driver(); - console::init(); + // console::init(); if let Some(con) = console::CONSOLE.lock().as_mut() { con.clear(); } 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", From 22d29a6257f7c46ab36575a1083e7daedd0934f5 Mon Sep 17 00:00:00 2001 From: Harry Chen Date: Tue, 14 May 2019 00:11:25 +0800 Subject: [PATCH 09/11] Revert "Revert "Fix trapframe."" This reverts commit 6a83de78465d5a17dddb90ef57d9046f0c658bee. --- kernel/src/arch/mipsel/boot/trap.S | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/kernel/src/arch/mipsel/boot/trap.S b/kernel/src/arch/mipsel/boot/trap.S index 4ec8650..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,18 +45,12 @@ 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 / 70 words for trapframe + 6 extra words -#ifdef board_thinpad -#define TRAPFRAME_SIZE 304 -#else -#define TRAPFRAME_SIZE 176 -#endif - addiu sp, sp, -TRAPFRAME_SIZE # save general registers From fbca9a6e3a57e13dc62d10824db9278ea403dcd5 Mon Sep 17 00:00:00 2001 From: Harry Chen Date: Tue, 14 May 2019 00:21:04 +0800 Subject: [PATCH 10/11] Add conditional compilation for mipsel, fix heap size for thinpad Signed-off-by: Harry Chen --- .gitignore | 1 + kernel/Makefile | 1 + kernel/src/arch/mipsel/board/thinpad/consts.rs | 2 +- .../src/arch/mipsel/boot/{linker.ld => linker.ld.S} | 4 ++++ kernel/src/arch/mipsel/consts.rs | 13 +++++++++---- kernel/src/arch/mipsel/driver/mod.rs | 2 +- 6 files changed, 17 insertions(+), 6 deletions(-) rename kernel/src/arch/mipsel/boot/{linker.ld => linker.ld.S} (92%) 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 275d0b7..b6620a4 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -348,6 +348,7 @@ else ifeq ($(arch), mipsel) @for file in context entry trap ; do \ $(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/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/boot/linker.ld b/kernel/src/arch/mipsel/boot/linker.ld.S similarity index 92% rename from kernel/src/arch/mipsel/boot/linker.ld rename to kernel/src/arch/mipsel/boot/linker.ld.S index 420430d..331b595 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/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/driver/mod.rs b/kernel/src/arch/mipsel/driver/mod.rs index 206d601..071142b 100644 --- a/kernel/src/arch/mipsel/driver/mod.rs +++ b/kernel/src/arch/mipsel/driver/mod.rs @@ -10,7 +10,7 @@ pub mod console; /// Initialize common drivers pub fn init() { board::init_driver(); - // console::init(); + console::init(); if let Some(con) = console::CONSOLE.lock().as_mut() { con.clear(); } From 3658e265a835fa7cace1f91fc96e8045d321d46e Mon Sep 17 00:00:00 2001 From: Harry Chen Date: Thu, 23 May 2019 02:19:42 +0800 Subject: [PATCH 11/11] Update device tree file and add stub for SYS_RT_SIGQUEUE Signed-off-by: Harry Chen --- kernel/src/arch/mipsel/board/malta/device.dts | 2 +- kernel/src/arch/mipsel/board/thinpad/device.dts | 2 +- kernel/src/syscall/mod.rs | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) 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/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/syscall/mod.rs b/kernel/src/syscall/mod.rs index 1e5fe1e..0f4c2d6 100644 --- a/kernel/src/syscall/mod.rs +++ b/kernel/src/syscall/mod.rs @@ -287,7 +287,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]),