diff --git a/Makefile b/Makefile index a11cafb..3ea7054 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,17 @@ +# Examples: +# make run Run in debug +# make run int=1 Run with interrupt info by QEMU +# make run mode=release Run in release +# make doc Generate docs +# make asm Open the deassemble file of the last build +# make clean Clean + arch ?= x86_64 kernel := build/kernel-$(arch).bin iso := build/os-$(arch).iso target ?= $(arch)-blog_os -rust_os := target/$(target)/debug/librust_ucore.a +mode ?= debug +rust_os := target/$(target)/$(mode)/librust_ucore.a boot_src := src/arch/$(arch)/boot linker_script := $(boot_src)/linker.ld @@ -37,6 +46,12 @@ ifdef int qemu_opts := $(qemu_opts) -d int endif +build_args := --target $(target) --features "$(features)" + +ifeq ($(mode), release) +build_args := $(build_args) --release +endif + ifeq ($(OS),Windows_NT) uname := Win32 @@ -54,7 +69,7 @@ ld := $(prefix)ld objdump := $(prefix)objdump cc := $(prefix)gcc -.PHONY: all clean run iso kernel build debug_asm doc +.PHONY: all clean run iso kernel build asm doc all: $(kernel) @@ -74,7 +89,7 @@ iso: $(iso) build: iso -debug_asm: +asm: @$(objdump) -dS $(kernel) | less $(iso): $(kernel) $(grub_cfg) @@ -89,7 +104,7 @@ $(kernel): kernel $(rust_os) $(assembly_object_files) $(linker_script) $(assembly_object_files) $(rust_os) kernel: - @RUST_TARGET_PATH=$(shell pwd) CC=$(cc) xargo build --target $(target) --features "$(features)" + @RUSTFLAGS=-g RUST_TARGET_PATH=$(shell pwd) CC=$(cc) xargo build $(build_args) # compile assembly files build/arch/$(arch)/boot/%.o: $(boot_src)/%.asm diff --git a/src/arch/x86_64/driver/apic/lapic.rs b/src/arch/x86_64/driver/apic/lapic.rs index 80e2b54..2332e5f 100644 --- a/src/arch/x86_64/driver/apic/lapic.rs +++ b/src/arch/x86_64/driver/apic/lapic.rs @@ -36,8 +36,10 @@ pub fn start_ap(apicid: u8, addr: u32) { pub fn lapic_id() -> u8 { unsafe{ if lapic.is_null() { + warn!("lapic is null. return lapic id = 0"); return 0; } - (*(lapic as *const u32).offset(0x0020/4) >> 24) as u8 + let ptr = (lapic as *const u32).offset(0x0020 / 4); + (ptr.read_volatile() >> 24) as u8 } } \ No newline at end of file diff --git a/src/arch/x86_64/smp.rs b/src/arch/x86_64/smp.rs index 9ab9f6d..f30818f 100644 --- a/src/arch/x86_64/smp.rs +++ b/src/arch/x86_64/smp.rs @@ -1,5 +1,6 @@ use arch::driver::{acpi::AcpiResult, apic::start_ap}; use memory::{MemoryController, PhysAddr}; +use core::ptr::{read_volatile, write_volatile}; extern { fn entryother_start(); // physical addr of entryother @@ -29,7 +30,7 @@ pub fn start_other_cores(acpi: &AcpiResult, mc: &mut MemoryController) { stack: 0x8000, // just enough stack to get us to entry64mp }; start_ap(apic_id, ENTRYOTHER_ADDR); - while unsafe{ !STARTED[i as usize] } {} + while unsafe { !read_volatile(&STARTED[i as usize]) } {} } } @@ -54,5 +55,5 @@ use consts::MAX_CPU_NUM; static mut STARTED: [bool; MAX_CPU_NUM] = [false; MAX_CPU_NUM]; pub unsafe fn notify_started(cpu_id: u8) { - STARTED[cpu_id as usize] = true; + write_volatile(&mut STARTED[cpu_id as usize], true); } \ No newline at end of file