diff --git a/kernel/Makefile b/kernel/Makefile index 0053184..acca445 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -12,11 +12,13 @@ # d = int | in_asm | ... QEMU debug info # mode = debug | release # LOG = off | error | warn | info | debug | trace +# smp SMP core number # board Only available on riscv32, build without bbl, run on board arch ?= riscv32 mode ?= debug LOG ?= debug +smp ?= 1 target := $(arch)-blog_os kernel := target/$(target)/$(mode)/ucore @@ -31,12 +33,12 @@ ifeq ($(arch), x86_64) qemu_opts := \ -drive format=raw,file=$(bootimage) \ -drive format=raw,file=$(SFSIMG),media=disk,cache=writeback \ - -smp 4 \ + -smp $(smp) \ -serial mon:stdio \ -device isa-debug-exit endif ifeq ($(arch), riscv32) -qemu_opts := -machine virt -kernel $(bin) -nographic +qemu_opts := -machine virt -kernel $(bin) -nographic -smp cpus=$(smp) endif ifdef board @@ -69,7 +71,7 @@ ifeq ($(uname), Darwin) prefix := x86_64-elf- endif ifeq ($(arch), riscv32) -prefix := riscv64-unknown-elf- +prefix := riscv32-unknown-elf- endif ld := $(prefix)ld @@ -118,7 +120,7 @@ else --enable-32bit \ --enable-logo \ --disable-fp-emulation \ - --host=riscv64-unknown-elf \ + --host=riscv32-unknown-elf \ --with-payload=$(abspath $(kernel)) && \ make && \ cp bbl ../../kernel/$@ diff --git a/kernel/src/arch/riscv32/boot/entry.asm b/kernel/src/arch/riscv32/boot/entry.asm index 8bb9268..0485f0e 100644 --- a/kernel/src/arch/riscv32/boot/entry.asm +++ b/kernel/src/arch/riscv32/boot/entry.asm @@ -1,14 +1,19 @@ .section .text.entry .globl _start _start: - lui sp, %hi(bootstacktop) - addi sp, sp, %lo(bootstacktop) + add t0, a0, 1 + slli t0, t0, 16 + + lui sp, %hi(bootstack) + addi sp, sp, %lo(bootstack) + add sp, sp, t0 + call rust_main .section .bss .align 12 #PGSHIFT .global bootstack bootstack: - .space 4096 * 16 #KSTACKSIZE + .space 4096 * 16 * 8 .global bootstacktop bootstacktop: diff --git a/kernel/src/arch/riscv32/mod.rs b/kernel/src/arch/riscv32/mod.rs index 13d9ad3..298c814 100644 --- a/kernel/src/arch/riscv32/mod.rs +++ b/kernel/src/arch/riscv32/mod.rs @@ -7,10 +7,11 @@ pub mod timer; pub mod paging; pub mod memory; pub mod compiler_rt; +pub mod smp; #[no_mangle] -pub extern fn rust_main() -> ! { - println!("Hello RISCV! {}", 123); +pub extern fn rust_main(hartid: usize) -> ! { + println!("Hello RISCV! {}", hartid); ::logging::init(); interrupt::init(); memory::init(); diff --git a/riscv-pk/configure b/riscv-pk/configure index 49dddf3..6b316db 100755 --- a/riscv-pk/configure +++ b/riscv-pk/configure @@ -4084,8 +4084,8 @@ fi case "${BUILD_32BIT}" in yes|default) echo "Building 32-bit pk" - CFLAGS="$default_CFLAGS -march=rv32i -mabi=ilp32" - LDFLAGS="-march=rv32i -mabi=ilp32" + CFLAGS="$default_CFLAGS -march=rv32ia -mabi=ilp32" + LDFLAGS="-march=rv32ia -mabi=ilp32" install_subdir="riscv32-unknown-elf" ;; *) diff --git a/riscv-pk/configure.ac b/riscv-pk/configure.ac index 107a3f2..5a06896 100644 --- a/riscv-pk/configure.ac +++ b/riscv-pk/configure.ac @@ -88,8 +88,8 @@ AC_ARG_ENABLE([32bit], case "${BUILD_32BIT}" in yes|default) echo "Building 32-bit pk" - CFLAGS="$default_CFLAGS -march=rv32i -mabi=ilp32" - LDFLAGS="-march=rv32i -mabi=ilp32" + CFLAGS="$default_CFLAGS -march=rv32ia -mabi=ilp32" + LDFLAGS="-march=rv32ia -mabi=ilp32" install_subdir="riscv32-unknown-elf" ;; *)