Skip to content

Commit 6a55c53

Browse files
committed
init
1 parent ae33d2f commit 6a55c53

File tree

14 files changed

+1842
-19
lines changed

14 files changed

+1842
-19
lines changed

Cargo.lock

Lines changed: 1404 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ members = [
1515
"platforms/axplat-riscv64-qemu-virt",
1616
"platforms/axplat-loongarch64-qemu-virt",
1717

18-
"examples/hello-kernel",
18+
"examples/hello-kernel", "platforms/axplat-aarch64-dyn",
1919
]
2020

2121
[workspace.package]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
authors.workspace = true
3+
documentation.workspace = true
4+
edition.workspace = true
5+
homepage.workspace = true
6+
license.workspace = true
7+
name = "axplat-aarch64-dyn"
8+
repository.workspace = true
9+
version = "0.1.0"
10+
11+
[dependencies]
12+
axconfig-macros = "0.2"
13+
axplat = {git = "https://github.com/arceos-org/axplat_crates"}
14+
pie-boot = {version = "0.1.11"}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Architecture identifier.
2+
arch = "aarch64" # str
3+
# Platform identifier.
4+
platform = "aarch64-dyn" # str
5+
# Platform package.
6+
package = "axplat-aarch64-dyn" # str
7+
8+
#
9+
# Platform configs
10+
#
11+
[plat]
12+
# Platform family (deprecated).
13+
family = "" # str
14+
# Number of CPUs.
15+
cpu-num = 256 # uint
16+
# No need.
17+
phys-memory-base = 0 # uint
18+
# No need.
19+
phys-memory-size = 0x0 # uint
20+
# No need.
21+
kernel-base-paddr = 0x0 # uint
22+
# Base virtual address of the kernel image.
23+
kernel-base-vaddr = "0xffff_8000_0000_0000" # uint
24+
# No need.
25+
phys-virt-offset = "0" # uint
26+
# Offset of bus address and phys address. some boards, the bus address is
27+
# different from the physical address.
28+
phys-bus-offset = 0 # uint
29+
# Kernel address space base.
30+
kernel-aspace-base = "0xffff_8000_0000_0000" # uint
31+
# Kernel address space size.
32+
kernel-aspace-size = "0x0000_7fff_ffff_f000" # uint
33+
34+
#
35+
# Device specifications
36+
#
37+
[devices]
38+
# MMIO regions with format (`base_paddr`, `size`).
39+
mmio-regions = [] # [(uint, uint)]
40+
# VirtIO MMIO regions with format (`base_paddr`, `size`).
41+
virtio-mmio-regions = [] # [(uint, uint)]
42+
# Base physical address of the PCIe ECAM space.
43+
pci-ecam-base = 0 # uint
44+
# End PCI bus number.
45+
pci-bus-end = 0 # uint
46+
# PCI device memory ranges.
47+
pci-ranges = [] # [(uint, uint)]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
fn main() {
2+
println!("cargo:rerun-if-env-changed=AX_CONFIG_PATH");
3+
if let Ok(config_path) = std::env::var("AX_CONFIG_PATH") {
4+
println!("cargo:rerun-if-changed={config_path}");
5+
}
6+
7+
println!("cargo:rustc-link-search={}", out_dir().display());
8+
println!("cargo::rustc-link-arg=-Tlink.x");
9+
println!("cargo::rustc-link-arg=-no-pie");
10+
println!("cargo::rustc-link-arg=-znostart-stop-gc");
11+
12+
let script = "link.ld";
13+
14+
println!("cargo:rerun-if-changed={script}");
15+
let ld_content = std::fs::read_to_string(script).unwrap();
16+
17+
std::fs::write(out_dir().join("link.x"), ld_content).expect("link.x write failed");
18+
}
19+
20+
fn out_dir() -> PathBuf {
21+
PathBuf::from(std::env::var("OUT_DIR").unwrap())
22+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
OUTPUT_ARCH(aarch64)
2+
3+
__SMP = 4;
4+
5+
INCLUDE "pie_boot.x"
6+
7+
ENTRY(_start)
8+
SECTIONS
9+
{
10+
_skernel = .;
11+
12+
.text : ALIGN(4K) {
13+
_stext = .;
14+
*(.text.boot)
15+
*(.text .text.*)
16+
. = ALIGN(4K);
17+
_etext = .;
18+
}
19+
20+
_srodata = .;
21+
.rodata : ALIGN(4K) {
22+
*(.rodata .rodata.*)
23+
*(.srodata .srodata.*)
24+
*(.sdata2 .sdata2.*)
25+
}
26+
27+
.init_array : ALIGN(0x10) {
28+
__init_array_start = .;
29+
*(.init_array .init_array.*)
30+
__init_array_end = .;
31+
}
32+
33+
. = ALIGN(4K);
34+
_erodata = .;
35+
36+
.data : ALIGN(4K) {
37+
_sdata = .;
38+
*(.data.boot_page_table)
39+
. = ALIGN(4K);
40+
*(.data .data.*)
41+
*(.sdata .sdata.*)
42+
*(.got .got.*)
43+
}
44+
45+
.tdata : ALIGN(0x10) {
46+
_stdata = .;
47+
*(.tdata .tdata.*)
48+
_etdata = .;
49+
}
50+
51+
.tbss : ALIGN(0x10) {
52+
_stbss = .;
53+
*(.tbss .tbss.*)
54+
*(.tcommon)
55+
_etbss = .;
56+
}
57+
58+
. = ALIGN(4K);
59+
_percpu_start = .;
60+
_percpu_end = _percpu_start + SIZEOF(.percpu);
61+
.percpu 0x0 : AT(_percpu_start) {
62+
_percpu_load_start = .;
63+
*(.percpu .percpu.*)
64+
_percpu_load_end = .;
65+
. = _percpu_load_start + ALIGN(64) * __SMP;
66+
}
67+
. = _percpu_end;
68+
69+
. = ALIGN(4K);
70+
_edata = .;
71+
72+
.bss : AT(.) ALIGN(4K) {
73+
boot_stack = .;
74+
*(.bss.stack)
75+
. = ALIGN(4K);
76+
boot_stack_top = .;
77+
78+
_sbss = .;
79+
*(.bss .bss.*)
80+
*(.sbss .sbss.*)
81+
*(COMMON)
82+
. = ALIGN(4K);
83+
_ebss = .;
84+
}
85+
86+
_ekernel = .;
87+
88+
/DISCARD/ : {
89+
*(.comment) *(.gnu*) *(.note*) *(.eh_frame*)
90+
}
91+
}
92+
93+
SECTIONS {
94+
linkme_IRQ : { *(linkme_IRQ) }
95+
linkm2_IRQ : { *(linkm2_IRQ) }
96+
linkme_PAGE_FAULT : { *(linkme_PAGE_FAULT) }
97+
linkm2_PAGE_FAULT : { *(linkm2_PAGE_FAULT) }
98+
linkme_SYSCALL : { *(linkme_SYSCALL) }
99+
linkm2_SYSCALL : { *(linkm2_SYSCALL) }
100+
axns_resource : { *(axns_resource) }
101+
}
102+
INSERT AFTER .tbss;
103+
104+
__kernel_load_end = _etdata;
105+
__kernel_code_end = _ekernel;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use axplat::console::ConsoleIf;
2+
3+
struct ConsoleIfImpl;
4+
5+
#[impl_plat_interface]
6+
impl ConsoleIf for ConsoleIfImpl {
7+
/// Writes given bytes to the console.
8+
fn write_bytes(bytes: &[u8]) {
9+
todo!()
10+
}
11+
12+
/// Reads bytes from the console into the given mutable slice.
13+
///
14+
/// Returns the number of bytes read.
15+
fn read_bytes(bytes: &mut [u8]) -> usize {
16+
todo!()
17+
}
18+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
use axplat::init::InitIf;
2+
3+
struct InitIfImpl;
4+
5+
#[impl_plat_interface]
6+
impl InitIf for InitIfImpl {
7+
/// Initializes the platform at the early stage for the primary core.
8+
///
9+
/// This function should be called immediately after the kernel has booted,
10+
/// and performed earliest platform configuration and initialization (e.g.,
11+
/// early console, clocking).
12+
///
13+
/// # Arguments
14+
///
15+
/// * `cpu_id` is the logical CPU ID (0, 1, ..., N-1, N is the number of CPU
16+
/// cores on the platform).
17+
/// * `arg` is passed from the bootloader (typically the device tree blob
18+
/// address).
19+
///
20+
/// # Before calling this function
21+
///
22+
/// * CPU is booted in the kernel mode.
23+
/// * Early page table is set up, virtual memory is enabled.
24+
/// * CPU-local data is initialized.
25+
///
26+
/// # After calling this function
27+
///
28+
/// * Exception & interrupt handlers are set up.
29+
/// * Early console is initialized.
30+
/// * Current monotonic time and wall time can be obtained.
31+
fn init_early(cpu_id: usize, arg: usize) {
32+
todo!()
33+
}
34+
35+
/// Initializes the platform at the early stage for secondary cores.
36+
///
37+
/// See [`init_early`] for details.
38+
fn init_early_secondary(cpu_id: usize) {
39+
todo!()
40+
}
41+
42+
/// Initializes the platform at the later stage for the primary core.
43+
///
44+
/// This function should be called after the kernel has done part of its
45+
/// initialization (e.g, logging, memory management), and finalized the rest of
46+
/// platform configuration and initialization.
47+
///
48+
/// # Arguments
49+
///
50+
/// * `cpu_id` is the logical CPU ID (0, 1, ..., N-1, N is the number of CPU
51+
/// cores on the platform).
52+
/// * `arg` is passed from the bootloader (typically the device tree blob
53+
/// address).
54+
///
55+
/// # Before calling this function
56+
///
57+
/// * Kernel logging is initialized.
58+
/// * Fine-grained kernel page table is set up (if applicable).
59+
/// * Physical memory allocation is initialized (if applicable).
60+
///
61+
/// # After calling this function
62+
///
63+
/// * Interrupt controller is initialized (if applicable).
64+
/// * Timer interrupts are enabled (if applicable).
65+
/// * Other platform devices are initialized.
66+
fn init_later(cpu_id: usize, arg: usize) {
67+
todo!()
68+
}
69+
70+
/// Initializes the platform at the later stage for secondary cores.
71+
///
72+
/// See [`init_later`] for details.
73+
fn init_later_secondary(cpu_id: usize) {
74+
todo!()
75+
}
76+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use axplat::irq::{IrqHandler, IrqIf};
2+
3+
struct IrqIfImpl;
4+
5+
#[impl_plat_interface]
6+
impl IrqIf for IrqIfImpl {
7+
/// Enables or disables the given IRQ.
8+
fn set_enable(irq: usize, enabled: bool) {
9+
todo!()
10+
}
11+
12+
/// Registers an IRQ handler for the given IRQ.
13+
///
14+
/// It also enables the IRQ if the registration succeeds. It returns `false`
15+
/// if the registration failed.
16+
fn register(irq: usize, handler: IrqHandler) -> bool {
17+
todo!()
18+
}
19+
20+
/// Unregisters the IRQ handler for the given IRQ.
21+
///
22+
/// It also disables the IRQ if the unregistration succeeds. It returns the
23+
/// existing handler if it is registered, `None` otherwise.
24+
fn unregister(irq: usize) -> Option<IrqHandler> {
25+
todo!()
26+
}
27+
28+
/// Handles the IRQ.
29+
///
30+
/// It is called by the common interrupt handler. It should look up in the
31+
/// IRQ handler table and calls the corresponding handler. If necessary, it
32+
/// also acknowledges the interrupt controller after handling.
33+
fn handle(irq: usize) {
34+
todo!()
35+
}
36+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#![cfg(all(target_arch = "aarch64", target_os = "none"))]
2+
#![no_std]
3+
4+
#[macro_use]
5+
extern crate axplat;
6+
7+
use pie_boot::BootArgs;
8+
9+
mod console;
10+
mod init;
11+
mod irq;
12+
mod mem;
13+
mod power;
14+
mod time;
15+
16+
mod config {
17+
axconfig_macros::include_configs!(path_env = "AX_CONFIG_PATH", fallback = "axconfig.toml");
18+
}
19+
20+
#[pie_boot::entry]
21+
fn main(_args: &BootArgs) -> ! {
22+
// TODO: Implement actual bootstrap logic
23+
axplat::call_main(0, 0);
24+
}

0 commit comments

Comments
 (0)