Skip to content

Commit

Permalink
Call axhal::platform_init in axruntime
Browse files Browse the repository at this point in the history
it's allow to use `info!()` in `axhal::platform_init()`
  • Loading branch information
equation314 committed Apr 27, 2023
1 parent b008feb commit 3bb1cc4
Show file tree
Hide file tree
Showing 43 changed files with 253 additions and 182 deletions.
1 change: 1 addition & 0 deletions apps/c/helloworld/expect_info.out
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Found physcial memory regions:
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
free memory (READ | WRITE | FREE)
Initialize platform devices...
Primary CPU 0 init OK.
Hello, C app!
Shutting down...
1 change: 1 addition & 0 deletions apps/c/helloworld/expect_info_smp4.out
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Found physcial memory regions:
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
free memory (READ | WRITE | FREE)
Initialize platform devices...
CPU 0 init OK
CPU 1 started
CPU 2 started
Expand Down
1 change: 1 addition & 0 deletions apps/c/memtest/expect_trace.out
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Found physcial memory regions:
Initialize global memory allocator...
initialize global allocator at: \[0x[0-9a-f]\+, 0x[0-9a-f]\+)
Initialize kernel page table...
Initialize platform devices...
map_region(PA:0x[0-9a-f]\+): \[VA:0x[0-9a-f]\+, VA:0x[0-9a-f]\+) -> \[PA:0x[0-9a-f]\+, PA:0x[0-9a-f]\+) MappingFlags(READ | EXECUTE)
map_region(PA:0x[0-9a-f]\+): \[VA:0x[0-9a-f]\+, VA:0x[0-9a-f]\+) -> \[PA:0x[0-9a-f]\+, PA:0x[0-9a-f]\+) MappingFlags(READ)
map_region(PA:0x[0-9a-f]\+): \[VA:0x[0-9a-f]\+, VA:0x[0-9a-f]\+) -> \[PA:0x[0-9a-f]\+, PA:0x[0-9a-f]\+) MappingFlags(READ | WRITE)
Expand Down
1 change: 1 addition & 0 deletions apps/c/sqlite3/expect_info.out
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Found physcial memory regions:
free memory (READ | WRITE | FREE)
Initialize global memory allocator...
Initialize kernel page table...
Initialize platform devices...
Initialize device drivers...
created a new Block device: "virtio-blk"
Initialize filesystems...
Expand Down
1 change: 1 addition & 0 deletions apps/c/sqlite3/expect_info_again.out
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Found physcial memory regions:
free memory (READ | WRITE | FREE)
Initialize global memory allocator...
Initialize kernel page table...
Initialize platform devices...
Initialize device drivers...
created a new Block device: "virtio-blk"
Initialize filesystems...
Expand Down
1 change: 1 addition & 0 deletions apps/exception/expect_debug_aarch64.out
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Found physcial memory regions:
free memory (READ | WRITE | FREE)
Initialize global memory allocator...
Initialize kernel page table...
Initialize platform devices...
Primary CPU 0 init OK.
Running exception tests...
BRK #0x0 @
Expand Down
1 change: 1 addition & 0 deletions apps/exception/expect_debug_riscv64.out
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Found physcial memory regions:
free memory (READ | WRITE | FREE)
Initialize global memory allocator...
Initialize kernel page table...
Initialize platform devices...
Primary CPU 0 init OK.
Running exception tests...
Exception(Breakpoint) @
Expand Down
1 change: 1 addition & 0 deletions apps/helloworld/expect_info.out
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Found physcial memory regions:
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
free memory (READ | WRITE | FREE)
Initialize platform devices...
Primary CPU 0 init OK.
Hello, world!
Shutting down...
1 change: 1 addition & 0 deletions apps/helloworld/expect_info_smp4.out
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Found physcial memory regions:
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
free memory (READ | WRITE | FREE)
Initialize platform devices...
CPU 0 init OK
CPU 1 started
CPU 2 started
Expand Down
1 change: 1 addition & 0 deletions apps/memtest/expect_trace.out
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Found physcial memory regions:
Initialize global memory allocator...
initialize global allocator at: \[0x[0-9a-f]\+, 0x[0-9a-f]\+)
Initialize kernel page table...
Initialize platform devices...
map_region(PA:0x[0-9a-f]\+): \[VA:0x[0-9a-f]\+, VA:0x[0-9a-f]\+) -> \[PA:0x[0-9a-f]\+, PA:0x[0-9a-f]\+) MappingFlags(READ | EXECUTE)
map_region(PA:0x[0-9a-f]\+): \[VA:0x[0-9a-f]\+, VA:0x[0-9a-f]\+) -> \[PA:0x[0-9a-f]\+, PA:0x[0-9a-f]\+) MappingFlags(READ)
map_region(PA:0x[0-9a-f]\+): \[VA:0x[0-9a-f]\+, VA:0x[0-9a-f]\+) -> \[PA:0x[0-9a-f]\+, PA:0x[0-9a-f]\+) MappingFlags(READ | WRITE)
Expand Down
1 change: 1 addition & 0 deletions apps/net/httpclient/expect_info.out
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Found physcial memory regions:
free memory (READ | WRITE | FREE)
Initialize global memory allocator...
Initialize kernel page table...
Initialize platform devices...
Initialize device drivers...
created a new Net device: "virtio-net"
Initialize network subsystem...
Expand Down
1 change: 1 addition & 0 deletions apps/net/httpclient/expect_info_dns.out
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Found physcial memory regions:
free memory (READ | WRITE | FREE)
Initialize global memory allocator...
Initialize kernel page table...
Initialize platform devices...
Initialize device drivers...
created a new Net device: "virtio-net"
Initialize network subsystem...
Expand Down
1 change: 1 addition & 0 deletions apps/task/parallel/expect_info_smp1_fifo.out
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Found physcial memory regions:
free memory (READ | WRITE | FREE)
Initialize global memory allocator...
Initialize kernel page table...
Initialize platform devices...
Initialize scheduling...
use FIFO scheduler.
Initialize interrupt handlers...
Expand Down
1 change: 1 addition & 0 deletions apps/task/parallel/expect_info_smp4_rr.out
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Found physcial memory regions:
free memory (READ | WRITE | FREE)
Initialize global memory allocator...
Initialize kernel page table...
Initialize platform devices...
Initialize scheduling...
use Round-robin scheduler.
Initialize interrupt handlers...
Expand Down
1 change: 1 addition & 0 deletions apps/task/sleep/expect_info_smp4_fifo.out
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Found physcial memory regions:
free memory (READ | WRITE | FREE)
Initialize global memory allocator...
Initialize kernel page table...
Initialize platform devices...
Initialize scheduling...
use FIFO scheduler.
Initialize interrupt handlers...
Expand Down
1 change: 1 addition & 0 deletions apps/task/sleep/expect_info_smp4_rr.out
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Found physcial memory regions:
free memory (READ | WRITE | FREE)
Initialize global memory allocator...
Initialize kernel page table...
Initialize platform devices...
Initialize scheduling...
use Round-robin scheduler.
Initialize interrupt handlers...
Expand Down
1 change: 1 addition & 0 deletions apps/task/yield/expect_info_smp4_fifo.out
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Found physcial memory regions:
free memory (READ | WRITE | FREE)
Initialize global memory allocator...
Initialize kernel page table...
Initialize platform devices...
Initialize scheduling...
use FIFO scheduler.
CPU 1 init OK
Expand Down
1 change: 1 addition & 0 deletions apps/task/yield/expect_info_smp4_rr.out
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Found physcial memory regions:
free memory (READ | WRITE | FREE)
Initialize global memory allocator...
Initialize kernel page table...
Initialize platform devices...
Initialize scheduling...
use Round-robin scheduler.
Initialize interrupt handlers...
Expand Down
4 changes: 2 additions & 2 deletions doc/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

We will provide an example to illustrate the process of building and running ArceOS:

**Examples:**
**Examples:**

What happens when "make A=apps/net/httpserver ARCH=aarch64 LOG=info NET=y SMP=1 run" is executed?

Expand Down Expand Up @@ -44,7 +44,7 @@ What happens when "make A=apps/net/httpserver ARCH=aarch64 LOG=info NET=y SMP=1
#[no_mangle]
#[link_section = ".text.boot"]
unsafe extern "C" fn _start() -> ! {
extern "Rust" {
extern "C" {
fn rust_main();
}
// PC = 0x8020_0000
Expand Down
9 changes: 9 additions & 0 deletions modules/axhal/src/arch/aarch64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,20 @@ pub fn irqs_enabled() -> bool {
}

/// Relaxes the current CPU and waits for interrupts.
///
/// It must be called with interrupts enabled, otherwise it will never return.
#[inline]
pub fn wait_for_irqs() {
aarch64_cpu::asm::wfi();
}

/// Halt the current CPU.
#[inline]
pub fn halt() {
disable_irqs();
aarch64_cpu::asm::wfi(); // should never return
}

/// Reads the register that stores the current page table root.
///
/// Returns the physical address of the page table root.
Expand Down
9 changes: 9 additions & 0 deletions modules/axhal/src/arch/riscv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,20 @@ pub fn irqs_enabled() -> bool {
}

/// Relaxes the current CPU and waits for interrupts.
///
/// It must be called with interrupts enabled, otherwise it will never return.
#[inline]
pub fn wait_for_irqs() {
unsafe { riscv::asm::wfi() }
}

/// Halt the current CPU.
#[inline]
pub fn halt() {
disable_irqs();
unsafe { riscv::asm::wfi() } // should never return
}

/// Reads the register that stores the current page table root.
///
/// Returns the physical address of the page table root.
Expand Down
12 changes: 10 additions & 2 deletions modules/axhal/src/arch/x86_64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,24 @@ pub fn irqs_enabled() -> bool {
}

/// Relaxes the current CPU and waits for interrupts.
///
/// It must be called with interrupts enabled, otherwise it will never return.
#[inline]
pub fn wait_for_irqs() {
if cfg!(target_os = "none") && irqs_enabled() {
// don't halt if local interrupts are disabled
if cfg!(target_os = "none") {
unsafe { asm!("hlt") }
} else {
core::hint::spin_loop()
}
}

/// Halt the current CPU.
#[inline]
pub fn halt() {
disable_irqs();
wait_for_irqs(); // should never return
}

/// Reads the register that stores the current page table root.
///
/// Returns the physical address of the page table root.
Expand Down
16 changes: 11 additions & 5 deletions modules/axhal/src/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,20 @@ pub unsafe fn set_current_task_ptr<T>(ptr: *const T) {
}

#[allow(dead_code)]
pub(crate) fn init_percpu(cpu_id: usize, is_bsp: bool) {
if is_bsp {
percpu::init(axconfig::SMP);
pub(crate) fn init_primary(cpu_id: usize) {
percpu::init(axconfig::SMP);
percpu::set_local_thread_pointer(cpu_id);
unsafe {
CPU_ID.write_current_raw(cpu_id);
IS_BSP.write_current_raw(true);
}
}

#[allow(dead_code)]
pub(crate) fn init_secondary(cpu_id: usize) {
percpu::set_local_thread_pointer(cpu_id);
unsafe {
// preemption is disabled on initialization.
CPU_ID.write_current_raw(cpu_id);
IS_BSP.write_current_raw(is_bsp);
IS_BSP.write_current_raw(false);
}
}
3 changes: 3 additions & 0 deletions modules/axhal/src/irq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ pub(crate) fn dispatch_irq_common(irq_num: usize) {
}

/// Platform-independent IRQ handler registration.
///
/// It also enables the IRQ if the registration succeeds. It returns `false` if
/// the registration failed.
#[allow(dead_code)]
pub(crate) fn register_handler_common(irq_num: usize, handler: IrqHandler) -> bool {
if irq_num < MAX_IRQ_COUNT && IRQ_HANDLER_TABLE.register_handler(irq_num, handler) {
Expand Down
5 changes: 5 additions & 0 deletions modules/axhal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,8 @@ pub mod misc {
pub mod mp {
pub use super::platform::mp::*;
}

pub use self::platform::platform_init;

#[cfg(feature = "smp")]
pub use self::platform::platform_init_secondary;
25 changes: 12 additions & 13 deletions modules/axhal/src/platform/dummy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,8 @@ pub mod misc {

#[cfg(feature = "smp")]
pub mod mp {
/// Starts a secondary CPU with the given ID.
///
/// When the CPU is started, it will jump to the given entry and set the
/// corresponding register to the given argument.
pub fn start_secondary_cpu(
hardid: usize,
entry: crate::mem::PhysAddr,
stack_top: crate::mem::PhysAddr,
) {
}
/// Starts the given secondary CPU with its boot stack.
pub fn start_secondary_cpu(cpu_id: usize, stack_top: crate::mem::PhysAddr) {}
}

pub mod mem {
Expand All @@ -48,9 +40,6 @@ pub mod mem {
}

pub mod time {
/// The timer IRQ number.
pub const TIMER_IRQ_NUM: usize = 0;

/// Returns the current clock time in hardware ticks.
pub fn current_ticks() -> u64 {
0
Expand All @@ -77,6 +66,9 @@ pub mod irq {
/// The maximum number of IRQs.
pub const MAX_IRQ_COUNT: usize = 256;

/// The timer IRQ number.
pub const TIMER_IRQ_NUM: usize = 0;

/// Enables or disables the given IRQ.
pub fn set_enable(irq_num: usize, enabled: bool) {}

Expand All @@ -92,3 +84,10 @@ pub mod irq {
/// necessary, it also acknowledges the interrupt controller after handling.
pub fn dispatch_irq(irq_num: usize) {}
}

/// Initializes the platform devices for the primary CPU.
pub fn platform_init() {}

/// Initializes the platform devices for secondary CPUs.
#[cfg(feature = "smp")]
pub fn platform_init_secondary() {}
Loading

0 comments on commit 3bb1cc4

Please sign in to comment.