diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8a9a2fb30e..1fc87cdd35 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -54,7 +54,7 @@ jobs: components: rust-src, llvm-tools targets: x86_64-unknown-none, riscv64gc-unknown-none-elf, aarch64-unknown-none, aarch64-unknown-none-softfloat - uses: Swatinem/rust-cache@v2 - - run: cargo install cargo-binutils + - run: make prepare - name: Build helloworld continue-on-error: ${{ matrix.rust-toolchain == 'nightly' }} run: make ARCH=${{ matrix.arch }} A=examples/helloworld @@ -96,7 +96,7 @@ jobs: components: rust-src, llvm-tools targets: x86_64-unknown-none, riscv64gc-unknown-none-elf, aarch64-unknown-none, aarch64-unknown-none-softfloat - uses: Swatinem/rust-cache@v2 - - run: cargo install cargo-binutils + - run: make prepare - name: Build helloworld for x86_64-pc-oslab continue-on-error: ${{ matrix.rust-toolchain == 'nightly' }} run: make PLATFORM=x86_64-pc-oslab A=examples/helloworld @@ -127,7 +127,7 @@ jobs: run: make PLATFORM=aarch64-raspi4 A=examples/shell FEATURES=driver-bcm2835-sdhci - name: Build helloworld for aarch64-bsta1000b run: make PLATFORM=aarch64-bsta1000b A=examples/helloworld - + - uses: ./.github/workflows/actions/setup-musl with: arch: x86_64 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bb99dadbe6..37330a158f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,7 +33,7 @@ jobs: toolchain: ${{ env.rust-toolchain }} components: rust-src - uses: Swatinem/rust-cache@v2 - - run: cargo install cargo-binutils + - run: make prepare - uses: ./.github/workflows/actions/setup-qemu with: qemu-version: ${{ env.qemu-version }} diff --git a/.gitignore b/.gitignore index ca3fc1aefc..2a2c5a3dd2 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ qemu.log rusty-tags.vi /.project* +/.axconfig.* diff --git a/Cargo.lock b/Cargo.lock index 26658bb52e..f9e0027de5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -47,6 +47,55 @@ dependencies = [ "libc", ] +[[package]] +name = "anstream" +version = "0.6.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" + +[[package]] +name = "anstyle-parse" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" +dependencies = [ + "anstyle", + "windows-sys", +] + [[package]] name = "arceos-helloworld" version = "0.1.0" @@ -181,10 +230,29 @@ dependencies = [ name = "axconfig" version = "0.1.0" dependencies = [ - "serde", + "axconfig-gen-macros", +] + +[[package]] +name = "axconfig-gen" +version = "0.1.0" +source = "git+https://github.com/arceos-org/axconfig-gen.git#551dbf6cf7759464883e2288cfe66b6d78729808" +dependencies = [ + "clap", "toml_edit", ] +[[package]] +name = "axconfig-gen-macros" +version = "0.1.0" +source = "git+https://github.com/arceos-org/axconfig-gen.git#551dbf6cf7759464883e2288cfe66b6d78729808" +dependencies = [ + "axconfig-gen", + "proc-macro2", + "quote", + "syn 2.0.70", +] + [[package]] name = "axdisplay" version = "0.1.0" @@ -680,6 +748,52 @@ dependencies = [ "libloading", ] +[[package]] +name = "clap" +version = "4.5.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3135e7ec2ef7b10c6ed8950f0f792ed96ee093fa088608f1c76e569722700c84" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30582fc632330df2bd26877bde0c1f4470d57c582bbc070376afcd04d8cb4838" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.70", +] + +[[package]] +name = "clap_lex" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" + +[[package]] +name = "colorchoice" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" + [[package]] name = "const-default" version = "1.0.0" @@ -852,6 +966,12 @@ dependencies = [ "stable_deref_trait", ] +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "iana-time-zone" version = "0.1.60" @@ -891,6 +1011,12 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd361c344145620f0c02e56200ca3e3a45203121447376519a9070e546b2916f" +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + [[package]] name = "itertools" version = "0.10.5" @@ -1342,26 +1468,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" -[[package]] -name = "serde" -version = "1.0.204" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.204" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.70", -] - [[package]] name = "shlex" version = "1.1.0" @@ -1411,6 +1517,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + [[package]] name = "svgbobdoc" version = "0.3.0" @@ -1507,6 +1619,12 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + [[package]] name = "version_check" version = "0.9.4" @@ -1644,6 +1762,15 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-targets" version = "0.52.5" diff --git a/Dockerfile b/Dockerfile index 1f960240e9..8e395c4f51 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ RUN apt-get update \ && apt-get install -y --no-install-recommends libclang-dev qemu-system wget make \ && rm -rf /var/lib/apt/lists/* -RUN cargo install cargo-binutils +RUN cargo install cargo-binutils axconfig-gen RUN wget https://musl.cc/aarch64-linux-musl-cross.tgz \ && wget https://musl.cc/riscv64-linux-musl-cross.tgz \ @@ -14,4 +14,4 @@ RUN wget https://musl.cc/aarch64-linux-musl-cross.tgz \ && tar zxf x86_64-linux-musl-cross.tgz \ && rm -f *.tgz -ENV PATH="/x86_64-linux-musl-cross/bin:/aarch64-linux-musl-cross/bin:/riscv64-linux-musl-cross/bin:$PATH" \ No newline at end of file +ENV PATH="/x86_64-linux-musl-cross/bin:/aarch64-linux-musl-cross/bin:/riscv64-linux-musl-cross/bin:$PATH" diff --git a/Makefile b/Makefile index 3d0dd587b0..6974e77ba8 100644 --- a/Makefile +++ b/Makefile @@ -46,6 +46,7 @@ BLK ?= n NET ?= n GRAPHIC ?= n BUS ?= pci +ACCEL ?= DISK_IMG ?= disk.img QEMU_LOG ?= n @@ -69,63 +70,28 @@ else APP_TYPE := c endif -# Architecture and platform -ifneq ($(filter $(MAKECMDGOALS),unittest unittest_no_fail_fast),) - PLATFORM_NAME := -else ifneq ($(PLATFORM),) - # `PLATFORM` is specified, override the `ARCH` variables - builtin_platforms := $(patsubst platforms/%.toml,%,$(wildcard platforms/*)) - ifneq ($(filter $(PLATFORM),$(builtin_platforms)),) - # builtin platform - PLATFORM_NAME := $(PLATFORM) - _arch := $(word 1,$(subst -, ,$(PLATFORM))) - else ifneq ($(wildcard $(PLATFORM)),) - # custom platform, read the "platform" field from the toml file - PLATFORM_NAME := $(shell cat $(PLATFORM) | sed -n 's/^platform = "\([a-z0-9A-Z_\-]*\)"/\1/p') - _arch := $(shell cat $(PLATFORM) | sed -n 's/^arch = "\([a-z0-9A-Z_\-]*\)"/\1/p') - else - $(error "PLATFORM" must be one of "$(builtin_platforms)" or a valid path to a toml file) - endif - ifeq ($(origin ARCH),command line) - ifneq ($(ARCH),$(_arch)) - $(error "ARCH=$(ARCH)" is not compatible with "PLATFORM=$(PLATFORM)") - endif - endif - ARCH := $(_arch) -endif - -ifeq ($(ARCH), x86_64) - # Don't enable kvm for WSL/WSL2. - ACCEL ?= $(if $(findstring -microsoft, $(shell uname -r | tr '[:upper:]' '[:lower:]')),n,y) - PLATFORM_NAME ?= x86_64-qemu-q35 -else ifeq ($(ARCH), riscv64) - ACCEL ?= n - PLATFORM_NAME ?= riscv64-qemu-virt -else ifeq ($(ARCH), aarch64) - ACCEL ?= n - PLATFORM_NAME ?= aarch64-qemu-virt -else - $(error "ARCH" must be one of "x86_64", "riscv64", or "aarch64") -endif - # Feature parsing include scripts/make/features.mk +# Platform resolving +include scripts/make/platform.mk # Target ifeq ($(ARCH), x86_64) TARGET := x86_64-unknown-none -else ifeq ($(ARCH), riscv64) - TARGET := riscv64gc-unknown-none-elf else ifeq ($(ARCH), aarch64) ifeq ($(findstring fp_simd,$(FEATURES)),) TARGET := aarch64-unknown-none-softfloat else TARGET := aarch64-unknown-none endif +else ifeq ($(ARCH), riscv64) + TARGET := riscv64gc-unknown-none-elf +else + $(error "ARCH" must be one of "x86_64", "riscv64", or "aarch64") endif export AX_ARCH=$(ARCH) -export AX_PLATFORM=$(PLATFORM_NAME) +export AX_PLATFORM=$(PLAT_NAME) export AX_SMP=$(SMP) export AX_MODE=$(MODE) export AX_LOG=$(LOG) @@ -148,22 +114,33 @@ GDB ?= gdb-multiarch OUT_DIR ?= $(APP) APP_NAME := $(shell basename $(APP)) -LD_SCRIPT := $(TARGET_DIR)/$(TARGET)/$(MODE)/linker_$(PLATFORM_NAME).lds -OUT_ELF := $(OUT_DIR)/$(APP_NAME)_$(PLATFORM_NAME).elf -OUT_BIN := $(OUT_DIR)/$(APP_NAME)_$(PLATFORM_NAME).bin +LD_SCRIPT := $(TARGET_DIR)/$(TARGET)/$(MODE)/linker_$(PLAT_NAME).lds +OUT_ELF := $(OUT_DIR)/$(APP_NAME)_$(PLAT_NAME).elf +OUT_BIN := $(OUT_DIR)/$(APP_NAME)_$(PLAT_NAME).bin all: build +prepare: + cargo install cargo-binutils + cargo install --git https://github.com/arceos-org/axconfig-gen.git + include scripts/make/utils.mk +include scripts/make/config.mk include scripts/make/build.mk include scripts/make/qemu.mk include scripts/make/test.mk -ifeq ($(PLATFORM_NAME), aarch64-raspi4) +ifeq ($(PLAT_NAME), aarch64-raspi4) include scripts/make/raspi4.mk -else ifeq ($(PLATFORM_NAME), aarch64-bsta1000b) +else ifeq ($(PLAT_NAME), aarch64-bsta1000b) include scripts/make/bsta1000b-fada.mk endif +defconfig: + $(call defconfig) + +oldconfig: + $(call oldconfig) + build: $(OUT_DIR) $(OUT_BIN) disasm: diff --git a/README.md b/README.md index fe56224d87..1db8882f5d 100644 --- a/README.md +++ b/README.md @@ -45,17 +45,25 @@ docker run -it -v $(pwd):/arceos -w /arceos arceos bash make A=examples/helloworld ARCH=aarch64 run ``` - ### Manually Build and Run #### 1. Install Build Dependencies -Install [cargo-binutils](https://github.com/rust-embedded/cargo-binutils) to use `rust-objcopy` and `rust-objdump` tools: +Install [cargo-binutils](https://github.com/rust-embedded/cargo-binutils) to use `rust-objcopy` and `rust-objdump` tools, and [axconfig-gen](https://github.com/arceos-org/axconfig-gen) for kernel configuration: + +```bash +cargo install cargo-binutils axconfig-gen +``` + +##### Dependencies for running apps ```bash -cargo install cargo-binutils +# for Debian/Ubuntu +sudo apt-get install qemu-system +# for macos +brew install qemu ``` -##### Dependencies for C apps +##### Dependencies for building C apps (optional) Install `libclang-dev`: @@ -78,18 +86,6 @@ tar zxf x86_64-linux-musl-cross.tgz export PATH=`pwd`/x86_64-linux-musl-cross/bin:`pwd`/aarch64-linux-musl-cross/bin:`pwd`/riscv64-linux-musl-cross/bin:$PATH ``` -##### Dependencies for running apps - -```bash -# for Debian/Ubuntu -sudo apt-get install qemu-system -``` - -```bash -# for macos -brew install qemu -``` - Other systems and arch please refer to [Qemu Download](https://www.qemu.org/download/#linux) #### 2. Build & Run @@ -133,7 +129,7 @@ Examples are given below and in the [app-helloworld](https://github.com/arceos-o ``` 3. Call library functions from `axstd` in your code, just like the Rust [std](https://doc.rust-lang.org/std/) library. - + Remember to annotate the `main` function with `#[unsafe(no_mangle)]` (see this [example](examples/helloworld/src/main.rs)). 4. Build your application with ArceOS, by running the `make` command in the application directory: diff --git a/api/arceos_posix_api/src/imp/sys.rs b/api/arceos_posix_api/src/imp/sys.rs index 0e7a432927..931951b06d 100644 --- a/api/arceos_posix_api/src/imp/sys.rs +++ b/api/arceos_posix_api/src/imp/sys.rs @@ -9,17 +9,36 @@ const PAGE_SIZE_4K: usize = 4096; /// Notice: currently only support what unikraft covers pub fn sys_sysconf(name: c_int) -> c_long { debug!("sys_sysconf <= {}", name); + + #[cfg(feature = "alloc")] + let (phys_pages, avail_pages) = { + let alloc = axalloc::global_allocator(); + let avail_pages = alloc.available_pages(); + (alloc.used_pages() + avail_pages, avail_pages) + }; + + #[cfg(not(feature = "alloc"))] + let (phys_pages, avail_pages) = { + let mem_size = axconfig::platform::PHYS_MEMORY_SIZE; + unsafe extern "C" { + fn _ekernel(); + } + ( + mem_size / PAGE_SIZE_4K, + (mem_size - _ekernel as usize) / PAGE_SIZE_4K, + ) + }; + syscall_body!(sys_sysconf, { match name as u32 { // Page size ctypes::_SC_PAGE_SIZE => Ok(PAGE_SIZE_4K), - // Total physical pages - ctypes::_SC_PHYS_PAGES => Ok(axconfig::PHYS_MEMORY_SIZE / PAGE_SIZE_4K), // Number of processors in use ctypes::_SC_NPROCESSORS_ONLN => Ok(axconfig::SMP), + // Total physical pages + ctypes::_SC_PHYS_PAGES => Ok(phys_pages), // Avaliable physical pages - #[cfg(feature = "alloc")] - ctypes::_SC_AVPHYS_PAGES => Ok(axalloc::global_allocator().available_pages()), + ctypes::_SC_AVPHYS_PAGES => Ok(avail_pages), // Maximum number of files per process #[cfg(feature = "fd")] ctypes::_SC_OPEN_MAX => Ok(super::fd_ops::AX_FILE_LIMIT), diff --git a/configs/defconfig.toml b/configs/defconfig.toml new file mode 100644 index 0000000000..3770c6ac4a --- /dev/null +++ b/configs/defconfig.toml @@ -0,0 +1,15 @@ +# Architecture identifier. +arch = "" # str + +# Platform identifier. +plat-name = "" # str + +# Stack size of each task. +task-stack-size = 0x40000 # uint + +# Number of timer ticks per second (Hz). A timer tick may contain several timer +# interrupts. +ticks-per-sec = 100 # uint + +# Number of CPUs +smp = 1 # uint diff --git a/configs/platforms/aarch64-qemu-virt.toml b/configs/platforms/aarch64-qemu-virt.toml new file mode 100644 index 0000000000..6874c3d622 --- /dev/null +++ b/configs/platforms/aarch64-qemu-virt.toml @@ -0,0 +1,108 @@ +# +# Platform configs +# +[platform] +# Platform family. +plat-family = "aarch64-qemu-virt" # str + +# Base address of the whole physical memory. +phys-memory-base = 0x4000_0000 # uint +# Size of the whole physical memory. +phys-memory-size = 0x800_0000 # uint +# End address of the whole physical memory. +phys-memory-end = 0x4800_0000 # uint +# Base physical address of the kernel image. +kernel-base-paddr = 0x4008_0000 # uint +# Base virtual address of the kernel image. +kernel-base-vaddr = "0xffff_0000_4008_0000" # uint +# Linear mapping offset, for quick conversions between physical and virtual +# addresses. +phys-virt-offset = "0xffff_0000_0000_0000" # uint +# Offset of bus address and phys address. some boards, the bus address is +# different from the physical address. +phys-bus-offset = 0 # uint +# Kernel address space base. +kernel-aspace-base = "0xffff_0000_0000_0000" # uint +# Kernel address space size. +kernel-aspace-size = "0x0000_ffff_ffff_f000" # uint + +# +# Device specifications +# +[devices] +# MMIO regions with format (`base_paddr`, `size`). +mmio-regions = [ + [0x0900_0000, 0x1000], # PL011 UART + [0x0910_0000, 0x1000], # PL031 RTC + [0x0800_0000, 0x2_0000], # GICv2 + [0x0a00_0000, 0x4000], # VirtIO + [0x1000_0000, 0x2eff_0000], # PCI memory ranges (ranges 1: 32-bit MMIO space) + [0x40_1000_0000, 0x1000_0000], # PCI config space +] # [(uint, uint)] +# VirtIO MMIO regions with format (`base_paddr`, `size`). +virtio-mmio-regions = [ + [0x0a00_0000, 0x200], + [0x0a00_0200, 0x200], + [0x0a00_0400, 0x200], + [0x0a00_0600, 0x200], + [0x0a00_0800, 0x200], + [0x0a00_0a00, 0x200], + [0x0a00_0c00, 0x200], + [0x0a00_0e00, 0x200], + [0x0a00_1000, 0x200], + [0x0a00_1200, 0x200], + [0x0a00_1400, 0x200], + [0x0a00_1600, 0x200], + [0x0a00_1800, 0x200], + [0x0a00_1a00, 0x200], + [0x0a00_1c00, 0x200], + [0x0a00_1e00, 0x200], + [0x0a00_3000, 0x200], + [0x0a00_2200, 0x200], + [0x0a00_2400, 0x200], + [0x0a00_2600, 0x200], + [0x0a00_2800, 0x200], + [0x0a00_2a00, 0x200], + [0x0a00_2c00, 0x200], + [0x0a00_2e00, 0x200], + [0x0a00_3000, 0x200], + [0x0a00_3200, 0x200], + [0x0a00_3400, 0x200], + [0x0a00_3600, 0x200], + [0x0a00_3800, 0x200], + [0x0a00_3a00, 0x200], + [0x0a00_3c00, 0x200], + [0x0a00_3e00, 0x200], +] # [(uint, uint)] +# Base physical address of the PCIe ECAM space. +pci-ecam-base = 0x40_1000_0000 # uint +# End PCI bus number (`bus-range` property in device tree). +pci-bus-end = 0xff # uint +# PCI device memory ranges (`ranges` property in device tree). +pci-ranges = [ + [0x3ef_f0000, 0x1_0000], # PIO space + [0x1000_0000, 0x2eff_0000], # 32-bit MMIO space + [0x80_0000_0000, 0x80_0000_0000], # 64-bit MMIO space +] # [(uint, uint)] +# UART Address +uart-paddr = 0x0900_0000 # uint +# UART IRQ number +uart-irq = 1 # uint + +# GIC CPU Interface base address +gicc-paddr = 0x0801_0000 # uint +# GIC Distributor base address +gicd-paddr = 0x0800_0000 # uint + +# PSCI +psci-method = "hvc" # str + +# pl031@9010000 { +# clock-names = "apb_pclk"; +# clocks = <0x8000>; +# interrupts = <0x00 0x02 0x04>; +# reg = <0x00 0x9010000 0x00 0x1000>; +# compatible = "arm,pl031\0arm,primecell"; +# }; +# RTC (PL031) Address +rtc-paddr = 0x901_0000 # uint diff --git a/configs/platforms/riscv64-qemu-virt.toml b/configs/platforms/riscv64-qemu-virt.toml new file mode 100644 index 0000000000..7be0473e4a --- /dev/null +++ b/configs/platforms/riscv64-qemu-virt.toml @@ -0,0 +1,74 @@ +# +# Platform configs +# +[platform] +# Platform family. +plat-family = "riscv64-qemu-virt" # str + +# Base address of the whole physical memory. +phys-memory-base = 0x8000_0000 # uint +# Size of the whole physical memory. +phys-memory-size = 0x800_0000 # uint +# End address of the whole physical memory. +phys-memory-end = 0x8800_0000 # uint +# Base physical address of the kernel image. +kernel-base-paddr = 0x8020_0000 # uint +# Base virtual address of the kernel image. +kernel-base-vaddr = "0xffff_ffc0_8020_0000" # uint +# Linear mapping offset, for quick conversions between physical and virtual +# addresses. +phys-virt-offset = "0xffff_ffc0_0000_0000" # uint +# Offset of bus address and phys address. some boards, the bus address is +# different from the physical address. +phys-bus-offset = 0 # uint +# Kernel address space base. +kernel-aspace-base = "0xffff_ffc0_0000_0000" # uint +# Kernel address space size. +kernel-aspace-size = "0x0000_003f_ffff_f000" # uint + +# +# Device specifications +# +[devices] +# MMIO regions with format (`base_paddr`, `size`). +mmio-regions = [ + [0x0010_1000, 0x1000], # RTC + [0x0c00_0000, 0x21_0000], # PLIC + [0x1000_0000, 0x1000], # UART + [0x1000_1000, 0x8000], # VirtIO + [0x3000_0000, 0x1000_0000], # PCI config space + [0x4000_0000, 0x4000_0000], # PCI memory ranges (ranges 1: 32-bit MMIO space) +] # [(uint, uint)] +# VirtIO MMIO regions with format (`base_paddr`, `size`). +virtio-mmio-regions = [ + [0x1000_1000, 0x1000], + [0x1000_2000, 0x1000], + [0x1000_3000, 0x1000], + [0x1000_4000, 0x1000], + [0x1000_5000, 0x1000], + [0x1000_6000, 0x1000], + [0x1000_7000, 0x1000], + [0x1000_8000, 0x1000], +] # [(uint, uint)] +# Base physical address of the PCIe ECAM space. +pci-ecam-base = 0x3000_0000 # uint +# End PCI bus number (`bus-range` property in device tree). +pci-bus-end = 0xff # uint +# PCI device memory ranges (`ranges` property in device tree). +pci-ranges = [ + [0x0300_0000, 0x1_0000], # PIO space + [0x4000_0000, 0x4000_0000], # 32-bit MMIO space + [0x4_0000_0000, 0x4_0000_0000], # 64-but MMIO space +] # [(uint, uint)] + +# Timer interrupt frequency in Hz. +timer-frequency = 10_000_000 # uint + +# rtc@101000 { +# interrupts = <0x0b>; +# interrupt-parent = <0x03>; +# reg = <0x00 0x101000 0x00 0x1000>; +# compatible = "google,goldfish-rtc"; +# }; +# RTC (goldfish) Address +rtc-paddr = 0x10_1000 # uint diff --git a/configs/platforms/x86_64-qemu-q35.toml b/configs/platforms/x86_64-qemu-q35.toml new file mode 100644 index 0000000000..0013b0e1ba --- /dev/null +++ b/configs/platforms/x86_64-qemu-q35.toml @@ -0,0 +1,51 @@ +# +# Platform configs +# +[platform] +# Platform family. +plat-family = "x86-pc" # str + +# Base address of the whole physical memory. +phys-memory-base = 0 # uint +# Size of the whole physical memory. +phys-memory-size = 0x800_0000 # uint +# End address of the whole physical memory. +phys-memory-end = 0x800_0000 # uint +# Base physical address of the kernel image. +kernel-base-paddr = 0x20_0000 # uint +# Base virtual address of the kernel image. +kernel-base-vaddr = "0xffff_ff80_0020_0000" # uint +# Linear mapping offset, for quick conversions between physical and virtual +# addresses. +phys-virt-offset = "0xffff_ff80_0000_0000" # uint +# Offset of bus address and phys address. some boards, the bus address is +# different from the physical address. +phys-bus-offset = 0 # uint +# Kernel address space base. +kernel-aspace-base = "0xffff_ff80_0000_0000" # uint +# Kernel address space size. +kernel-aspace-size = "0x0000_007f_ffff_f000" # uint + +# +# Device specifications +# +[devices] +# MMIO regions with format (`base_paddr`, `size`). +mmio-regions = [ + [0xb000_0000, 0x1000_0000], # PCI config space + [0xfe00_0000, 0xc0_0000], # PCI devices + [0xfec0_0000, 0x1000], # IO APIC + [0xfed0_0000, 0x1000], # HPET + [0xfee0_0000, 0x1000], # Local APIC +] # [(uint, uint)] +# VirtIO MMIO regions with format (`base_paddr`, `size`). +virtio-mmio-regions = [] # [(uint, uint)] +# Base physical address of the PCIe ECAM space (should read from ACPI 'MCFG' table). +pci-ecam-base = 0xb000_0000 # uint +# End PCI bus number. +pci-bus-end = 0xff # uint +# PCI device memory ranges (not used on x86). +pci-ranges = [] # [(uint, uint)] + +# Timer interrupt frequencyin Hz. +timer-frequency = 4_000_000_000 # uint diff --git a/modules/axconfig/Cargo.toml b/modules/axconfig/Cargo.toml index 1e389fb490..75d0eca752 100644 --- a/modules/axconfig/Cargo.toml +++ b/modules/axconfig/Cargo.toml @@ -9,6 +9,5 @@ homepage.workspace = true repository = "https://github.com/arceos-org/arceos/tree/main/modules/axconfig" documentation = "https://arceos-org.github.io/arceos/axconfig/index.html" -[build-dependencies] -toml_edit = "0.22" -serde = "1.0" +[dependencies] +axconfig-gen-macros = { git = "https://github.com/arceos-org/axconfig-gen.git" } diff --git a/modules/axconfig/build.rs b/modules/axconfig/build.rs index 4737362331..33d332b733 100644 --- a/modules/axconfig/build.rs +++ b/modules/axconfig/build.rs @@ -1,182 +1,8 @@ -use std::io::{Result, Write}; -use std::path::{Path, PathBuf}; -use toml_edit::{Decor, DocumentMut, Item, Table, Value}; +use std::path::PathBuf; -fn resolve_config_path(platform: Option<&str>) -> Result { +fn main() { let mut root_dir = PathBuf::from(std::env!("CARGO_MANIFEST_DIR")); root_dir.extend(["..", ".."]); - let config_dir = root_dir.join("platforms"); - - let builtin_platforms = std::fs::read_dir(&config_dir)? - .filter_map(|e| { - e.unwrap() - .file_name() - .to_str()? - .strip_suffix(".toml") - .map(String::from) - }) - .collect::>(); - - let path = match platform { - None | Some("") => "defconfig.toml".into(), - Some(plat) if builtin_platforms.contains(&plat.to_string()) => { - config_dir.join(format!("{plat}.toml")) - } - Some(plat) => { - let path = PathBuf::from(&plat); - if path.is_absolute() { - path - } else { - root_dir.join(plat) - } - } - }; - - Ok(path) -} - -fn get_comments<'a>(config: &'a Table, key: &str) -> Option<&'a str> { - config - .key(key) - .and_then(|k| k.leaf_decor().prefix()) - .and_then(|s| s.as_str()) - .map(|s| s.trim()) -} - -fn add_config(config: &mut Table, key: &str, item: Item, comments: Option<&str>) { - config.insert(key, item); - if let Some(comm) = comments { - if let Some(mut dst) = config.key_mut(key) { - *dst.leaf_decor_mut() = Decor::new(comm, ""); - } - } -} - -fn load_config_toml(config_path: &Path) -> Result { - let config_content = std::fs::read_to_string(config_path)?; - let toml = config_content - .parse::() - .expect("failed to parse config file") - .as_table() - .clone(); - Ok(toml) -} - -fn gen_config_rs(config_path: &Path) -> Result> { - fn is_num(s: &str) -> bool { - let s = s.replace('_', ""); - if s.parse::().is_ok() { - true - } else if let Some(s) = s.strip_prefix("0x") { - usize::from_str_radix(s, 16).is_ok() - } else { - false - } - } - - // Load TOML config file - let mut config = if config_path == Path::new("defconfig.toml") { - load_config_toml(config_path)? - } else { - // Set default values for missing items - let defconfig = load_config_toml(Path::new("defconfig.toml"))?; - let mut config = load_config_toml(config_path)?; - - for (key, item) in defconfig.iter() { - if !config.contains_key(key) { - add_config( - &mut config, - key, - item.clone(), - get_comments(&defconfig, key), - ); - } - } - config - }; - - add_config( - &mut config, - "smp", - toml_edit::value(std::env::var("AX_SMP").unwrap_or("1".into())), - Some("# Number of CPUs"), - ); - - // Generate config.rs - let mut output = Vec::new(); - writeln!( - output, - "// Platform constants and parameters for {}.", - config["platform"].as_str().unwrap(), - )?; - writeln!(output, "// Generated by build.rs, DO NOT edit!\n")?; - - for (key, item) in config.iter() { - let var_name = key.to_uppercase().replace('-', "_"); - if let Item::Value(value) = item { - let comments = get_comments(&config, key) - .unwrap_or_default() - .replace('#', "///"); - match value { - Value::String(s) => { - writeln!(output, "{comments}")?; - let s = s.value(); - if is_num(s) { - writeln!(output, "pub const {var_name}: usize = {s};")?; - } else { - writeln!(output, "pub const {var_name}: &str = \"{s}\";")?; - } - } - Value::Array(regions) => match key { - "cpu-id-list" => { - writeln!(output, "{comments}")?; - writeln!(output, "pub const {var_name}: &[usize] = &[")?; - for r in regions.iter() { - let r = r.as_str().unwrap(); - writeln!(output, "{},", r)?; - } - writeln!(output, "];")?; - } - "mmio-regions" | "virtio-mmio-regions" | "pci-ranges" => { - writeln!(output, "{comments}")?; - writeln!(output, "pub const {var_name}: &[(usize, usize)] = &[")?; - for r in regions.iter() { - let r = r.as_array().unwrap(); - writeln!( - output, - " ({}, {}),", - r.get(0).unwrap().as_str().unwrap(), - r.get(1).unwrap().as_str().unwrap() - )?; - } - writeln!(output, "];")?; - } - _ => { - continue; - } - }, - _ => {} - } - } - } - - Ok(output) -} - -fn main() -> Result<()> { - let platform = option_env!("AX_PLATFORM"); - let config_path = resolve_config_path(platform)?; - - println!("Reading config file: {:?}", config_path); - let config_rs = gen_config_rs(&config_path)?; - - let out_dir = std::env::var("OUT_DIR").unwrap(); - let out_path = Path::new(&out_dir).join("config.rs"); - println!("Generating config file: {}", out_path.display()); - std::fs::write(out_path, config_rs)?; - + let config_path = root_dir.join(".axconfig.toml"); println!("cargo:rerun-if-changed={}", config_path.display()); - println!("cargo:rerun-if-env-changed=AX_PLATFORM"); - println!("cargo:rerun-if-env-changed=AX_SMP"); - Ok(()) } diff --git a/modules/axconfig/defconfig.toml b/modules/axconfig/defconfig.toml deleted file mode 100644 index 7d9babb6f0..0000000000 --- a/modules/axconfig/defconfig.toml +++ /dev/null @@ -1,51 +0,0 @@ -# Architecture identifier. -arch = "unknown" -# Platform identifier. -platform = "dummy" -# Platform family. -family = "dummy" - -# Base address of the whole physical memory. -phys-memory-base = "0" -# Size of the whole physical memory. -phys-memory-size = "0" -# Base physical address of the kernel image. -kernel-base-paddr = "0" -# Base virtual address of the kernel image. -kernel-base-vaddr = "0" -# Linear mapping offset, for quick conversions between physical and virtual -# addresses. -phys-virt-offset = "0" -# Offset of bus address and phys address. some boards, the bus address is -# different from the physical address. -phys-bus-offset = "0" -# Kernel address space base. -kernel-aspace-base = "0" -# Kernel address space size. -kernel-aspace-size = "0" -# MMIO regions with format (`base_paddr`, `size`). -mmio-regions = [] -# VirtIO MMIO regions with format (`base_paddr`, `size`). -virtio-mmio-regions = [] -# Base physical address of the PCIe ECAM space. -pci-ecam-base = "0" -# End PCI bus number. -pci-bus-end = "0" -# PCI device memory ranges. -pci-ranges = [] - -# Timer interrupt frequency in Hz. -timer-frequency = "0" - -# Stack size of each task. -task-stack-size = "0x40000" # 256 K - -# Number of timer ticks per second (Hz). A timer tick may contain several timer -# interrupts. -ticks-per-sec = "100" - -# Number of CPUs -smp = "1" - -# CPU Hardware ID list -cpu-id-list = [] \ No newline at end of file diff --git a/modules/axconfig/src/lib.rs b/modules/axconfig/src/lib.rs index 6488790b0b..e93dceea33 100644 --- a/modules/axconfig/src/lib.rs +++ b/modules/axconfig/src/lib.rs @@ -8,12 +8,8 @@ #![no_std] -#[rustfmt::skip] mod config { - include!(concat!(env!("OUT_DIR"), "/config.rs")); + axconfig_gen_macros::include_configs!("../../.axconfig.toml"); } pub use config::*; - -/// End address of the whole physical memory. -pub const PHYS_MEMORY_END: usize = PHYS_MEMORY_BASE + PHYS_MEMORY_SIZE; diff --git a/modules/axdma/src/lib.rs b/modules/axdma/src/lib.rs index bc896a710b..f02658f9f3 100644 --- a/modules/axdma/src/lib.rs +++ b/modules/axdma/src/lib.rs @@ -16,34 +16,50 @@ use self::dma::ALLOCATOR; /// Converts a physical address to a bus address. /// /// It assumes that there is a linear mapping with the offset -/// [`axconfig::PHYS_BUS_OFFSET`], that maps all the physical memory to the virtual -/// space at the address plus the offset. So we have +/// [`axconfig::platform::PHYS_BUS_OFFSET`], that maps all the physical memory +/// to the virtual space at the address plus the offset. So we have /// `baddr = paddr + PHYS_BUS_OFFSET`. #[inline] pub const fn phys_to_bus(paddr: PhysAddr) -> BusAddr { - BusAddr::new((paddr.as_usize() + axconfig::PHYS_BUS_OFFSET) as u64) + BusAddr::new((paddr.as_usize() + axconfig::platform::PHYS_BUS_OFFSET) as u64) } -/// Allocates **coherent** memory that meets Direct Memory Access (DMA) requirements. +/// Allocates **coherent** memory that meets Direct Memory Access (DMA) +/// requirements. /// -/// This function allocates a block of memory through the global allocator. The memory pages must be contiguous, undivided, and have consistent read and write access. +/// This function allocates a block of memory through the global allocator. The +/// memory pages must be contiguous, undivided, and have consistent read and +/// write access. /// -/// - `layout`: The memory layout, which describes the size and alignment requirements of the requested memory. +/// - `layout`: The memory layout, which describes the size and alignment +/// requirements of the requested memory. +/// +/// Returns an [`DMAInfo`] structure containing details about the allocated +/// memory, such as the starting address and size. If it's not possible to +/// allocate memory meeting the criteria, returns [`None`]. /// -/// Returns an [`DMAInfo`] structure containing details about the allocated memory, such as the starting address and size. If it's not possible to allocate memory meeting the criteria, returns [`None`]. /// # Safety -/// This function is unsafe because it directly interacts with the global allocator, which can potentially cause memory leaks or other issues if not used correctly. +/// +/// This function is unsafe because it directly interacts with the global +/// allocator, which can potentially cause memory leaks or other issues if not +/// used correctly. pub unsafe fn alloc_coherent(layout: Layout) -> AllocResult { ALLOCATOR.lock().alloc_coherent(layout) } /// Frees coherent memory previously allocated. /// -/// This function releases the memory block that was previously allocated and marked as coherent. It ensures proper deallocation and management of resources associated with the memory block. +/// This function releases the memory block that was previously allocated and +/// marked as coherent. It ensures proper deallocation and management of resources +/// associated with the memory block. +/// +/// - `dma_info`: An instance of [`DMAInfo`] containing the details of the memory +/// block to be freed, such as its starting address and size. /// -/// - `dma_info`: An instance of [`DMAInfo`] containing the details of the memory block to be freed, such as its starting address and size. /// # Safety -/// This function is unsafe because it directly interacts with the global allocator, which can potentially cause memory leaks or other issues if not used correctly. +/// +/// This function is unsafe because it directly interacts with the global allocator, +/// which can potentially cause memory leaks or other issues if not used correctly. pub unsafe fn dealloc_coherent(dma: DMAInfo, layout: Layout) { ALLOCATOR.lock().dealloc_coherent(dma, layout) } @@ -84,10 +100,10 @@ impl core::fmt::Debug for BusAddr { /// Represents information related to a DMA operation. #[derive(Debug, Clone, Copy)] pub struct DMAInfo { - /// The `cpu_addr` field represents the address at which the CPU accesses this memory region. - /// This address is a virtual memory address used by the CPU to access memory. + /// The address at which the CPU accesses this memory region. This address + /// is a virtual memory address used by the CPU to access memory. pub cpu_addr: NonNull, - /// The `bus_addr` field represents the physical address of this memory region on the bus. - /// The DMA controller uses this address to directly access memory. + /// Represents the physical address of this memory region on the bus. The DMA + /// controller uses this address to directly access memory. pub bus_addr: BusAddr, } diff --git a/modules/axdriver/src/bus/mmio.rs b/modules/axdriver/src/bus/mmio.rs index da6fa76cb6..5a4a45a157 100644 --- a/modules/axdriver/src/bus/mmio.rs +++ b/modules/axdriver/src/bus/mmio.rs @@ -5,7 +5,7 @@ impl AllDevices { pub(crate) fn probe_bus_devices(&mut self) { // TODO: parse device tree #[cfg(feature = "virtio")] - for reg in axconfig::VIRTIO_MMIO_REGIONS { + for reg in axconfig::devices::VIRTIO_MMIO_REGIONS { for_each_drivers!(type Driver, { if let Some(dev) = Driver::probe_mmio(reg.0, reg.1) { info!( diff --git a/modules/axdriver/src/bus/pci.rs b/modules/axdriver/src/bus/pci.rs index 1957f67e02..6689f1ece7 100644 --- a/modules/axdriver/src/bus/pci.rs +++ b/modules/axdriver/src/bus/pci.rs @@ -84,15 +84,15 @@ fn config_pci_device( impl AllDevices { pub(crate) fn probe_bus_devices(&mut self) { - let base_vaddr = phys_to_virt(axconfig::PCI_ECAM_BASE.into()); + let base_vaddr = phys_to_virt(axconfig::devices::PCI_ECAM_BASE.into()); let mut root = unsafe { PciRoot::new(base_vaddr.as_mut_ptr(), Cam::Ecam) }; // PCI 32-bit MMIO space - let mut allocator = axconfig::PCI_RANGES + let mut allocator = axconfig::devices::PCI_RANGES .get(1) .map(|range| PciRangeAllocator::new(range.0 as u64, range.1 as u64)); - for bus in 0..=axconfig::PCI_BUS_END as u8 { + for bus in 0..=axconfig::devices::PCI_BUS_END as u8 { for (bdf, dev_info) in root.enumerate_bus(bus) { debug!("PCI {}: {}", bdf, dev_info); if dev_info.header_type != HeaderType::Standard { diff --git a/modules/axhal/build.rs b/modules/axhal/build.rs index 19d92afe4d..ea71ddba4d 100644 --- a/modules/axhal/build.rs +++ b/modules/axhal/build.rs @@ -29,13 +29,16 @@ fn make_cfg_values(str_list: &[&str]) -> String { fn main() { let arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap(); - let platform = axconfig::PLATFORM; + let platform = axconfig::PLAT_NAME; if platform != "dummy" { gen_linker_script(&arch, platform).unwrap(); } println!("cargo:rustc-cfg=platform=\"{}\"", platform); - println!("cargo:rustc-cfg=platform_family=\"{}\"", axconfig::FAMILY); + println!( + "cargo:rustc-cfg=platform_family=\"{}\"", + axconfig::platform::PLAT_FAMILY + ); println!( "cargo::rustc-check-cfg=cfg(platform, values({}))", make_cfg_values(BUILTIN_PLATFORMS) @@ -59,7 +62,7 @@ fn gen_linker_script(arch: &str, platform: &str) -> Result<()> { let ld_content = ld_content.replace("%ARCH%", output_arch); let ld_content = ld_content.replace( "%KERNEL_BASE%", - &format!("{:#x}", axconfig::KERNEL_BASE_VADDR), + &format!("{:#x}", axconfig::platform::KERNEL_BASE_VADDR), ); let ld_content = ld_content.replace("%SMP%", &format!("{}", axconfig::SMP)); diff --git a/modules/axhal/src/mem.rs b/modules/axhal/src/mem.rs index 354a157b08..961b4de98a 100644 --- a/modules/axhal/src/mem.rs +++ b/modules/axhal/src/mem.rs @@ -51,10 +51,10 @@ pub struct MemRegion { /// space at the address plus the offset. So we have /// `paddr = vaddr - PHYS_VIRT_OFFSET`. /// -/// [`PHYS_VIRT_OFFSET`]: axconfig::PHYS_VIRT_OFFSET +/// [`PHYS_VIRT_OFFSET`]: axconfig::platform::PHYS_VIRT_OFFSET #[inline] pub const fn virt_to_phys(vaddr: VirtAddr) -> PhysAddr { - pa!(vaddr.as_usize() - axconfig::PHYS_VIRT_OFFSET) + pa!(vaddr.as_usize() - axconfig::platform::PHYS_VIRT_OFFSET) } /// Converts a physical address to a virtual address. @@ -64,10 +64,10 @@ pub const fn virt_to_phys(vaddr: VirtAddr) -> PhysAddr { /// space at the address plus the offset. So we have /// `vaddr = paddr + PHYS_VIRT_OFFSET`. /// -/// [`PHYS_VIRT_OFFSET`]: axconfig::PHYS_VIRT_OFFSET +/// [`PHYS_VIRT_OFFSET`]: axconfig::platform::PHYS_VIRT_OFFSET #[inline] pub const fn phys_to_virt(paddr: PhysAddr) -> VirtAddr { - va!(paddr.as_usize() + axconfig::PHYS_VIRT_OFFSET) + va!(paddr.as_usize() + axconfig::platform::PHYS_VIRT_OFFSET) } /// Returns an iterator over all physical memory regions. @@ -115,7 +115,7 @@ fn kernel_image_regions() -> impl Iterator { /// Returns the default MMIO memory regions (from [`axconfig::MMIO_REGIONS`]). #[allow(dead_code)] pub(crate) fn default_mmio_regions() -> impl Iterator { - axconfig::MMIO_REGIONS.iter().map(|reg| MemRegion { + axconfig::devices::MMIO_REGIONS.iter().map(|reg| MemRegion { paddr: reg.0.into(), size: reg.1, flags: MemRegionFlags::RESERVED @@ -130,7 +130,7 @@ pub(crate) fn default_mmio_regions() -> impl Iterator { #[allow(dead_code)] pub(crate) fn default_free_regions() -> impl Iterator { let start = virt_to_phys((_ekernel as usize).into()).align_up_4k(); - let end = pa!(axconfig::PHYS_MEMORY_END).align_down_4k(); + let end = pa!(axconfig::platform::PHYS_MEMORY_END).align_down_4k(); core::iter::once(MemRegion { paddr: start, size: end.as_usize() - start.as_usize(), diff --git a/modules/axhal/src/platform/aarch64_bsta1000b/dw_apb_uart.rs b/modules/axhal/src/platform/aarch64_bsta1000b/dw_apb_uart.rs index c6edb10f68..bbcc8e0d76 100644 --- a/modules/axhal/src/platform/aarch64_bsta1000b/dw_apb_uart.rs +++ b/modules/axhal/src/platform/aarch64_bsta1000b/dw_apb_uart.rs @@ -5,7 +5,7 @@ use dw_apb_uart::DW8250; use kspin::SpinNoIrq; use memory_addr::PhysAddr; -const UART_BASE: PhysAddr = pa!(axconfig::UART_PADDR); +const UART_BASE: PhysAddr = pa!(axconfig::devices::UART_PADDR); static UART: SpinNoIrq = SpinNoIrq::new(DW8250::new(phys_to_virt(UART_BASE).as_usize())); diff --git a/modules/axhal/src/platform/aarch64_bsta1000b/misc.rs b/modules/axhal/src/platform/aarch64_bsta1000b/misc.rs index 440aafab5c..34e9e83b0a 100644 --- a/modules/axhal/src/platform/aarch64_bsta1000b/misc.rs +++ b/modules/axhal/src/platform/aarch64_bsta1000b/misc.rs @@ -9,7 +9,8 @@ pub fn reset_qspi() { // qspi exit 4-byte mode // exit_4byte_qspi(); - let ptr = phys_to_virt((axconfig::A1000BASE_SAFETYCRM + 0x8).into()).as_mut_ptr() as *mut u32; + let ptr = phys_to_virt((axconfig::devices::A1000BASE_SAFETYCRM + 0x8).into()).as_mut_ptr() + as *mut u32; unsafe { let value = read_volatile(ptr); trace!("SAFETY CRM RESET CTRL = {:#x}", value); @@ -26,7 +27,8 @@ pub fn reset_cpu() { reset_qspi(); //Data Width = 32 - let ptr = phys_to_virt((axconfig::A1000BASE_SAFETYCRM + 0x8).into()).as_mut_ptr() as *mut u32; + let ptr = phys_to_virt((axconfig::devices::A1000BASE_SAFETYCRM + 0x8).into()).as_mut_ptr() + as *mut u32; unsafe { write_volatile(ptr, read_volatile(ptr) & !0b1); } @@ -54,7 +56,8 @@ pub fn do_reset() { #[allow(dead_code)] pub fn get_bootmode() -> u32 { unsafe { - let ptr = phys_to_virt((axconfig::A1000BASE_TOPCRM).into()).as_mut_ptr() as *mut u32; + let ptr = + phys_to_virt((axconfig::devices::A1000BASE_TOPCRM).into()).as_mut_ptr() as *mut u32; (ptr.read_volatile() >> 26) & 0x7 } } diff --git a/modules/axhal/src/platform/aarch64_common/boot.rs b/modules/axhal/src/platform/aarch64_common/boot.rs index e3f72c7da4..1d7851900b 100644 --- a/modules/axhal/src/platform/aarch64_common/boot.rs +++ b/modules/axhal/src/platform/aarch64_common/boot.rs @@ -3,7 +3,7 @@ use core::ptr::addr_of_mut; use page_table_entry::aarch64::{A64PTE, MemAttr}; use tock_registers::interfaces::{ReadWriteable, Readable, Writeable}; -use axconfig::TASK_STACK_SIZE; +use axconfig::{TASK_STACK_SIZE, platform::PHYS_VIRT_OFFSET}; #[unsafe(link_section = ".bss.stack")] static mut BOOT_STACK: [u8; TASK_STACK_SIZE] = [0; TASK_STACK_SIZE]; @@ -135,7 +135,7 @@ unsafe extern "C" fn _start() -> ! { enable_fp = sym enable_fp, boot_stack = sym BOOT_STACK, boot_stack_size = const TASK_STACK_SIZE, - phys_virt_offset = const axconfig::PHYS_VIRT_OFFSET, + phys_virt_offset = const PHYS_VIRT_OFFSET, entry = sym crate::platform::rust_entry, ) } @@ -165,7 +165,7 @@ unsafe extern "C" fn _start_secondary() -> ! { switch_to_el1 = sym switch_to_el1, init_mmu = sym init_mmu, enable_fp = sym enable_fp, - phys_virt_offset = const axconfig::PHYS_VIRT_OFFSET, + phys_virt_offset = const PHYS_VIRT_OFFSET, entry = sym crate::platform::rust_entry_secondary, ) } diff --git a/modules/axhal/src/platform/aarch64_common/generic_timer.rs b/modules/axhal/src/platform/aarch64_common/generic_timer.rs index 62bb4cdfb2..8b5bcb97b6 100644 --- a/modules/axhal/src/platform/aarch64_common/generic_timer.rs +++ b/modules/axhal/src/platform/aarch64_common/generic_timer.rs @@ -58,12 +58,12 @@ pub(crate) fn init_early() { // Make sure `RTC_PADDR` is valid in platform config file. #[cfg(feature = "rtc")] - if axconfig::RTC_PADDR != 0 { + if axconfig::devices::RTC_PADDR != 0 { use crate::mem::phys_to_virt; use arm_pl031::Rtc; use memory_addr::PhysAddr; - const PL031_BASE: PhysAddr = pa!(axconfig::RTC_PADDR); + const PL031_BASE: PhysAddr = pa!(axconfig::devices::RTC_PADDR); let rtc = unsafe { Rtc::new(phys_to_virt(PL031_BASE).as_usize() as _) }; // Get the current time in microseconds since the epoch (1970-01-01) from the aarch64 pl031 RTC. diff --git a/modules/axhal/src/platform/aarch64_common/gic.rs b/modules/axhal/src/platform/aarch64_common/gic.rs index b320255ac6..f8b21c9113 100644 --- a/modules/axhal/src/platform/aarch64_common/gic.rs +++ b/modules/axhal/src/platform/aarch64_common/gic.rs @@ -1,5 +1,6 @@ use crate::{irq::IrqHandler, mem::phys_to_virt}; use arm_gicv2::{GicCpuInterface, GicDistributor, InterruptType, translate_irq}; +use axconfig::devices::{GICC_PADDR, GICD_PADDR, UART_IRQ}; use kspin::SpinNoIrq; use memory_addr::PhysAddr; @@ -10,10 +11,10 @@ pub const MAX_IRQ_COUNT: usize = 1024; pub const TIMER_IRQ_NUM: usize = translate_irq(14, InterruptType::PPI).unwrap(); /// The UART IRQ number. -pub const UART_IRQ_NUM: usize = translate_irq(axconfig::UART_IRQ, InterruptType::SPI).unwrap(); +pub const UART_IRQ_NUM: usize = translate_irq(UART_IRQ, InterruptType::SPI).unwrap(); -const GICD_BASE: PhysAddr = pa!(axconfig::GICD_PADDR); -const GICC_BASE: PhysAddr = pa!(axconfig::GICC_PADDR); +const GICD_BASE: PhysAddr = pa!(GICD_PADDR); +const GICC_BASE: PhysAddr = pa!(GICC_PADDR); static GICD: SpinNoIrq = SpinNoIrq::new(GicDistributor::new(phys_to_virt(GICD_BASE).as_mut_ptr())); diff --git a/modules/axhal/src/platform/aarch64_common/pl011.rs b/modules/axhal/src/platform/aarch64_common/pl011.rs index 8b4325c04e..6b7f0ab4ce 100644 --- a/modules/axhal/src/platform/aarch64_common/pl011.rs +++ b/modules/axhal/src/platform/aarch64_common/pl011.rs @@ -6,7 +6,7 @@ use memory_addr::PhysAddr; use crate::mem::phys_to_virt; -const UART_BASE: PhysAddr = pa!(axconfig::UART_PADDR); +const UART_BASE: PhysAddr = pa!(axconfig::devices::UART_PADDR); static UART: SpinNoIrq = SpinNoIrq::new(Pl011Uart::new(phys_to_virt(UART_BASE).as_mut_ptr())); diff --git a/modules/axhal/src/platform/aarch64_common/psci.rs b/modules/axhal/src/platform/aarch64_common/psci.rs index feca7ba6db..8a13d59c9c 100644 --- a/modules/axhal/src/platform/aarch64_common/psci.rs +++ b/modules/axhal/src/platform/aarch64_common/psci.rs @@ -2,6 +2,8 @@ #![allow(dead_code)] +use axconfig::devices::PSCI_METHOD; + pub const PSCI_0_2_FN_BASE: u32 = 0x84000000; pub const PSCI_0_2_64BIT: u32 = 0x40000000; pub const PSCI_0_2_FN_CPU_SUSPEND: u32 = PSCI_0_2_FN_BASE + 1; @@ -79,10 +81,10 @@ fn psci_hvc_call(func: u32, arg0: usize, arg1: usize, arg2: usize) -> usize { } fn psci_call(func: u32, arg0: usize, arg1: usize, arg2: usize) -> Result<(), PsciError> { - let ret = match axconfig::PSCI_METHOD { + let ret = match PSCI_METHOD { "smc" => arm_smccc_smc(func, arg0, arg1, arg2), "hvc" => psci_hvc_call(func, arg0, arg1, arg2), - _ => panic!("Unknown PSCI method: {}", axconfig::PSCI_METHOD), + _ => panic!("Unknown PSCI method: {}", PSCI_METHOD), }; if ret == 0 { Ok(()) diff --git a/modules/axhal/src/platform/aarch64_phytium_pi/mod.rs b/modules/axhal/src/platform/aarch64_phytium_pi/mod.rs index c9068952c3..893d50063b 100644 --- a/modules/axhal/src/platform/aarch64_phytium_pi/mod.rs +++ b/modules/axhal/src/platform/aarch64_phytium_pi/mod.rs @@ -71,7 +71,7 @@ pub fn platform_init_secondary() { } fn cpu_hard_id_to_logic_id(hard_id: usize) -> usize { - axconfig::CPU_ID_LIST + axconfig::devices::CPU_ID_LIST .iter() .position(|&x| x == hard_id) .unwrap() diff --git a/modules/axhal/src/platform/aarch64_phytium_pi/mp.rs b/modules/axhal/src/platform/aarch64_phytium_pi/mp.rs index b6f63b5ef0..c5bcbf8ff6 100644 --- a/modules/axhal/src/platform/aarch64_phytium_pi/mp.rs +++ b/modules/axhal/src/platform/aarch64_phytium_pi/mp.rs @@ -1,4 +1,4 @@ -use axconfig::CPU_ID_LIST; +use axconfig::devices::CPU_ID_LIST; use crate::mem::{PhysAddr, virt_to_phys}; diff --git a/modules/axhal/src/platform/aarch64_raspi/mp.rs b/modules/axhal/src/platform/aarch64_raspi/mp.rs index e8194dfbe3..35341062ee 100644 --- a/modules/axhal/src/platform/aarch64_raspi/mp.rs +++ b/modules/axhal/src/platform/aarch64_raspi/mp.rs @@ -17,7 +17,8 @@ unsafe extern "C" fn modify_stack_and_start() { mov x0, x21 // x0 will be set to SP in the beginning of _start_secondary b _start_secondary", secondary_boot_stack = sym SECONDARY_STACK_TOP, - phys_virt_offset = const axconfig::PHYS_VIRT_OFFSET, + phys_virt_offset = const axconfig::platform::PHYS_VIRT_OFFSET, + options(noreturn) ); } diff --git a/modules/axhal/src/platform/riscv64_qemu_virt/boot.rs b/modules/axhal/src/platform/riscv64_qemu_virt/boot.rs index f27bfc08c9..4d34dabd04 100644 --- a/modules/axhal/src/platform/riscv64_qemu_virt/boot.rs +++ b/modules/axhal/src/platform/riscv64_qemu_virt/boot.rs @@ -1,6 +1,6 @@ use riscv::register::satp; -use axconfig::{PHYS_VIRT_OFFSET, TASK_STACK_SIZE}; +use axconfig::{TASK_STACK_SIZE, platform::PHYS_VIRT_OFFSET}; #[unsafe(link_section = ".bss.stack")] static mut BOOT_STACK: [u8; TASK_STACK_SIZE] = [0; TASK_STACK_SIZE]; diff --git a/modules/axhal/src/platform/riscv64_qemu_virt/time.rs b/modules/axhal/src/platform/riscv64_qemu_virt/time.rs index 538bddadd1..74a3b4ec9b 100644 --- a/modules/axhal/src/platform/riscv64_qemu_virt/time.rs +++ b/modules/axhal/src/platform/riscv64_qemu_virt/time.rs @@ -1,6 +1,6 @@ use riscv::register::time; -const NANOS_PER_TICK: u64 = crate::time::NANOS_PER_SEC / axconfig::TIMER_FREQUENCY as u64; +const NANOS_PER_TICK: u64 = crate::time::NANOS_PER_SEC / axconfig::devices::TIMER_FREQUENCY as u64; /// RTC wall time offset in nanoseconds at monotonic time base. static mut RTC_EPOCHOFFSET_NANOS: u64 = 0; @@ -37,12 +37,12 @@ pub fn set_oneshot_timer(deadline_ns: u64) { pub(super) fn init_early() { #[cfg(feature = "rtc")] - if axconfig::RTC_PADDR != 0 { + if axconfig::devices::RTC_PADDR != 0 { use crate::mem::phys_to_virt; use memory_addr::PhysAddr; use riscv_goldfish::Rtc; - const GOLDFISH_BASE: PhysAddr = pa!(axconfig::RTC_PADDR); + const GOLDFISH_BASE: PhysAddr = pa!(axconfig::devices::RTC_PADDR); // Get the current time in microseconds since the epoch (1970-01-01) from the riscv RTC. // Subtract the timer ticks to get the actual time when ArceOS was booted. let epoch_time_nanos = diff --git a/modules/axhal/src/platform/x86_pc/boot.rs b/modules/axhal/src/platform/x86_pc/boot.rs index 60ccf4c939..8cdba9f984 100644 --- a/modules/axhal/src/platform/x86_pc/boot.rs +++ b/modules/axhal/src/platform/x86_pc/boot.rs @@ -3,7 +3,7 @@ use core::arch::global_asm; use x86_64::registers::control::{Cr0Flags, Cr4Flags}; use x86_64::registers::model_specific::EferFlags; -use axconfig::{PHYS_VIRT_OFFSET, TASK_STACK_SIZE}; +use axconfig::{TASK_STACK_SIZE, platform::PHYS_VIRT_OFFSET}; /// Flags set in the ’flags’ member of the multiboot header. /// diff --git a/modules/axhal/src/platform/x86_pc/time.rs b/modules/axhal/src/platform/x86_pc/time.rs index 871ad9c3fb..8949da3491 100644 --- a/modules/axhal/src/platform/x86_pc/time.rs +++ b/modules/axhal/src/platform/x86_pc/time.rs @@ -10,7 +10,7 @@ const LAPIC_TICKS_PER_SEC: u64 = 1_000_000_000; // TODO: need to calibrate static mut NANOS_TO_LAPIC_TICKS_RATIO: Ratio = Ratio::zero(); static mut INIT_TICK: u64 = 0; -static mut CPU_FREQ_MHZ: u64 = axconfig::TIMER_FREQUENCY as u64 / 1_000_000; +static mut CPU_FREQ_MHZ: u64 = axconfig::devices::TIMER_FREQUENCY as u64 / 1_000_000; /// RTC wall time offset in nanoseconds at monotonic time base. static mut RTC_EPOCHOFFSET_NANOS: u64 = 0; diff --git a/modules/axmm/src/lib.rs b/modules/axmm/src/lib.rs index 09d27ff344..e3608432e5 100644 --- a/modules/axmm/src/lib.rs +++ b/modules/axmm/src/lib.rs @@ -33,8 +33,8 @@ fn paging_err_to_ax_err(err: PagingError) -> AxError { /// Creates a new address space for kernel itself. pub fn new_kernel_aspace() -> AxResult { let mut aspace = AddrSpace::new_empty( - va!(axconfig::KERNEL_ASPACE_BASE), - axconfig::KERNEL_ASPACE_SIZE, + va!(axconfig::platform::KERNEL_ASPACE_BASE), + axconfig::platform::KERNEL_ASPACE_SIZE, )?; for r in axhal::mem::memory_regions() { aspace.map_linear(phys_to_virt(r.paddr), r.paddr, r.size, r.flags.into())?; diff --git a/modules/axruntime/src/lib.rs b/modules/axruntime/src/lib.rs index 33f2fd933a..9ff17bdf52 100644 --- a/modules/axruntime/src/lib.rs +++ b/modules/axruntime/src/lib.rs @@ -107,15 +107,15 @@ pub extern "C" fn rust_main(cpu_id: usize, dtb: usize) -> ! { "\ arch = {}\n\ platform = {}\n\ - target = {}\n\ smp = {}\n\ + target = {}\n\ build_mode = {}\n\ log_level = {}\n\ ", - option_env!("AX_ARCH").unwrap_or(""), - option_env!("AX_PLATFORM").unwrap_or(""), + axconfig::ARCH, + axconfig::PLAT_NAME, + axconfig::SMP, option_env!("AX_TARGET").unwrap_or(""), - option_env!("AX_SMP").unwrap_or(""), option_env!("AX_MODE").unwrap_or(""), option_env!("AX_LOG").unwrap_or(""), ); diff --git a/platforms/aarch64-bsta1000b.toml b/platforms/aarch64-bsta1000b.toml deleted file mode 100644 index 48f66efa32..0000000000 --- a/platforms/aarch64-bsta1000b.toml +++ /dev/null @@ -1,64 +0,0 @@ -# Architecture identifier. -arch = "aarch64" -# Platform identifier. -platform = "aarch64-bsta1000b" -# Platform family. -family = "aarch64-bsta1000b" - -# Base address of the whole physical memory. -phys-memory-base = "0x80000000" -# Size of the whole physical memory. -phys-memory-size = "0x70000000" -# Offset of bus address and phys address. some boards, the bus address is -# different from the physical address. -phys-bus-offset = "0" -# Base physical address of the kernel image. -kernel-base-paddr = "0x81000000" -# Base virtual address of the kernel image. -kernel-base-vaddr = "0xffff_0000_8100_0000" -# Linear mapping offset, for quick conversions between physical and virtual -# addresses. -phys-virt-offset = "0xffff_0000_0000_0000" -# Kernel address space base. -kernel-aspace-base = "0xffff_0000_0000_0000" -# Kernel address space size. -kernel-aspace-size = "0x0000_ffff_ffff_f000" -# MMIO regions with format (`base_paddr`, `size`). -mmio-regions = [ - ["0x20008000", "0x1000"], # uart8250 UART0 - ["0x32000000", "0x8000"], # arm,gic-400 - ["0x32011000", "0x1000"], # CPU CSR - ["0x33002000", "0x1000"], # Top CRM - ["0x70035000", "0x1000"], # CRM reg - ["0x70038000", "0x1000"], # aon pinmux -] - -virtio-mmio-regions = [] - -# Base physical address of the PCIe ECAM space. -# pci-ecam-base = "0x40_1000_0000" -# End PCI bus number (`bus-range` property in device tree). -# pci-bus-end = "0xff" -# PCI device memory ranges (`ranges` property in device tree). -# pci-ranges = [] - -# UART Address -uart-paddr = "0x20008000" -# UART irq from device tree -uart-irq = "0xd5" -# GICD Address -gicd-paddr = "0x32001000" -# GICC Address -gicc-paddr = "0x32002000" - -# BST A1000B board registers -CPU_CSR_BASE = "0x32011000" -A1000BASE_TOPCRM = "0x33002000" -A1000BASE_SAFETYCRM = "0x70035000" -A1000BASE_AONCFG = "0x70038000" - -# PSCI -psci-method = "smc" - -# RTC (PL031) Address (Need to read from DTB). -rtc-paddr = "0x0" \ No newline at end of file diff --git a/platforms/aarch64-phytium-pi.toml b/platforms/aarch64-phytium-pi.toml deleted file mode 100644 index abc561cd2c..0000000000 --- a/platforms/aarch64-phytium-pi.toml +++ /dev/null @@ -1,80 +0,0 @@ -# Architecture identifier. -arch = "aarch64" -# Platform identifier. -platform = "aarch64-phytium-pi" -# Platform family. -family = "aarch64-phytium-pi" - -# Base address of the whole physical memory. -phys-memory-base = "0x8000_0000" -# Size of the whole physical memory. -phys-memory-size = "0x8000_0000" # 2G -# Base physical address of the kernel image. -kernel-base-paddr = "0x9000_0000" -# Base virtual address of the kernel image. -kernel-base-vaddr = "0xffff_0000_9000_0000" -# Linear mapping offset, for quick conversions between physical and virtual -# addresses. -phys-virt-offset = "0xffff_0000_0000_0000" -# Kernel address space base. -kernel-aspace-base = "0xffff_0000_0000_0000" -# Kernel address space size. -kernel-aspace-size = "0x0000_ffff_ffff_f000" -# MMIO regions with format (`base_paddr`, `size`). -mmio-regions = [ - ["0x2800_C000", "0x1000"], # UART 0 - ["0x2800_D000", "0x1000"], # UART 1 - ["0x2800_E000", "0x1000"], # UART 2 - ["0x2800_F000", "0x1000"], # UART 3 - - ["0x3000_0000", "0x800_0000"], # other devices - ["0x4000_0000", "0x1000_0000"], # Pcie ecam - - ["0x5800_0000", "0x2800_0000"], # 32-bit MMIO space - - ["0x2801_4000", "0x2000"], # MIO0 - I2C - ["0x2801_6000", "0x2000"], # MIO1 - I2C - ["0x2801_8000", "0x2000"], # MIO2 - I2C - ["0x2801_A000", "0x2000"], # MIO3 - I2C - ["0x2801_C000", "0x2000"], # MIO4 - I2C - - ["0x000_2803_4000", "0x1000"], # GPIO0 - ["0x000_2803_5000", "0x1000"], # GPIO1 - ["0x000_2803_6000", "0x1000"], # GPIO2 - ["0x000_2803_7000", "0x1000"], # GPIO3 - ["0x000_2803_8000", "0x1000"], # GPIO4 - ["0x000_2803_9000", "0x1000"], # GPIO5 -] - -# UART Address -uart-paddr = "0x2800_D000" -# UART Irq num -uart-irq = "24" - -# MIO0 I2C -MIO0 = "0x2801_4000" - -# PSCI -psci-method = "smc" - -# GICC Address -gicc-paddr = "0x3080_0000" -# TODO: gicv3 dosen't support yet, there is no gicd and need a gicr address. -gicd-paddr = "0x3088_0000" - -# Base physical address of the PCIe ECAM space. -pci-ecam-base = "0x4000_0000" -# End PCI bus number. -pci-bus-end = "0x2" -# PCI device memory ranges. -pci-ranges = [ - ["0x0", "0x5000_0000"], # PIO space - ["0x5800_0000", "0x2800_0000"], # 32-bit MMIO space - ["0x10_0000_0000", "0x10_0000_0000"], # 64-bit MMIO space -] - -# Number of CPUs -smp = "4" - -# CPU Hardware ID list -cpu-id-list = ["0x0", "0x100", "0x200", "0x201"] diff --git a/platforms/aarch64-qemu-virt.toml b/platforms/aarch64-qemu-virt.toml deleted file mode 100644 index 8f88673751..0000000000 --- a/platforms/aarch64-qemu-virt.toml +++ /dev/null @@ -1,99 +0,0 @@ -# Architecture identifier. -arch = "aarch64" -# Platform identifier. -platform = "aarch64-qemu-virt" -# Platform family. -family = "aarch64-qemu-virt" - -# Base address of the whole physical memory. -phys-memory-base = "0x4000_0000" -# Size of the whole physical memory. -phys-memory-size = "0x800_0000" # 128M -# Base physical address of the kernel image. -kernel-base-paddr = "0x4008_0000" -# Base virtual address of the kernel image. -kernel-base-vaddr = "0xffff_0000_4008_0000" -# Linear mapping offset, for quick conversions between physical and virtual -# addresses. -phys-virt-offset = "0xffff_0000_0000_0000" -# Offset of bus address and phys address. some boards, the bus address is -# different from the physical address. -phys-bus-offset = "0" -# Kernel address space base. -kernel-aspace-base = "0xffff_0000_0000_0000" -# Kernel address space size. -kernel-aspace-size = "0x0000_ffff_ffff_f000" -# MMIO regions with format (`base_paddr`, `size`). -mmio-regions = [ - ["0x0900_0000", "0x1000"], # PL011 UART - ["0x0910_0000", "0x1000"], # PL031 RTC - ["0x0800_0000", "0x2_0000"], # GICv2 - ["0x0a00_0000", "0x4000"], # VirtIO - ["0x1000_0000", "0x2eff_0000"], # PCI memory ranges (ranges 1: 32-bit MMIO space) - ["0x40_1000_0000", "0x1000_0000"], # PCI config space -] -# VirtIO MMIO regions with format (`base_paddr`, `size`). -virtio-mmio-regions = [ - ["0x0a00_0000", "0x200"], - ["0x0a00_0200", "0x200"], - ["0x0a00_0400", "0x200"], - ["0x0a00_0600", "0x200"], - ["0x0a00_0800", "0x200"], - ["0x0a00_0a00", "0x200"], - ["0x0a00_0c00", "0x200"], - ["0x0a00_0e00", "0x200"], - ["0x0a00_1000", "0x200"], - ["0x0a00_1200", "0x200"], - ["0x0a00_1400", "0x200"], - ["0x0a00_1600", "0x200"], - ["0x0a00_1800", "0x200"], - ["0x0a00_1a00", "0x200"], - ["0x0a00_1c00", "0x200"], - ["0x0a00_1e00", "0x200"], - ["0x0a00_3000", "0x200"], - ["0x0a00_2200", "0x200"], - ["0x0a00_2400", "0x200"], - ["0x0a00_2600", "0x200"], - ["0x0a00_2800", "0x200"], - ["0x0a00_2a00", "0x200"], - ["0x0a00_2c00", "0x200"], - ["0x0a00_2e00", "0x200"], - ["0x0a00_3000", "0x200"], - ["0x0a00_3200", "0x200"], - ["0x0a00_3400", "0x200"], - ["0x0a00_3600", "0x200"], - ["0x0a00_3800", "0x200"], - ["0x0a00_3a00", "0x200"], - ["0x0a00_3c00", "0x200"], - ["0x0a00_3e00", "0x200"], -] -# Base physical address of the PCIe ECAM space. -pci-ecam-base = "0x40_1000_0000" -# End PCI bus number (`bus-range` property in device tree). -pci-bus-end = "0xff" -# PCI device memory ranges (`ranges` property in device tree). -pci-ranges = [ - ["0x3ef_f0000", "0x1_0000"], # PIO space - ["0x1000_0000", "0x2eff_0000"], # 32-bit MMIO space - ["0x80_0000_0000", "0x80_0000_0000"], # 64-but MMIO space -] -# UART Address -uart-paddr = "0x0900_0000" -uart-irq = "1" - -# GICC Address -gicc-paddr = "0x0801_0000" -gicd-paddr = "0x0800_0000" - -# PSCI -psci-method = "hvc" - -# pl031@9010000 { -# clock-names = "apb_pclk"; -# clocks = <0x8000>; -# interrupts = <0x00 0x02 0x04>; -# reg = <0x00 0x9010000 0x00 0x1000>; -# compatible = "arm,pl031\0arm,primecell"; -# }; -# RTC (PL031) Address -rtc-paddr = "0x901_0000" \ No newline at end of file diff --git a/platforms/aarch64-raspi4.toml b/platforms/aarch64-raspi4.toml deleted file mode 100644 index 5edae28501..0000000000 --- a/platforms/aarch64-raspi4.toml +++ /dev/null @@ -1,40 +0,0 @@ -# Architecture identifier. -arch = "aarch64" -# Platform identifier. -platform = "aarch64-raspi4" -# Platform family. -family = "aarch64-raspi" - -# Base address of the whole physical memory. -phys-memory-base = "0x0" -# Size of the whole physical memory. -phys-memory-size = "0xFC00_0000" # 3G 960M -# Base physical address of the kernel image. -kernel-base-paddr = "0x8_0000" -# Base virtual address of the kernel image. -kernel-base-vaddr = "0xffff_0000_0008_0000" -# Linear mapping offset, for quick conversions between physical and virtual -# addresses. -phys-virt-offset = "0xffff_0000_0000_0000" -# Offset of bus address and phys address. -phys-bus-offset = "0xC0000000" -# Kernel address space base. -kernel-aspace-base = "0xffff_0000_0000_0000" -# Kernel address space size. -kernel-aspace-size = "0x0000_ffff_ffff_f000" -# MMIO regions with format (`base_paddr`, `size`). -mmio-regions = [ - ["0xFE20_1000", "0x1000"], # PL011 UART - ["0xFF84_1000", "0x8000"], # GICv2 -] -virtio-mmio-regions = [] -# UART Address -uart-paddr = "0xFE20_1000" -uart-irq = "0x79" - -# GIC Address -gicc-paddr = "0xFF84_2000" -gicd-paddr = "0xFF84_1000" - -# RTC (PL031) Address (Need to read from DTB). -rtc-paddr = "0x0" diff --git a/platforms/riscv64-qemu-virt.toml b/platforms/riscv64-qemu-virt.toml deleted file mode 100644 index 670582eada..0000000000 --- a/platforms/riscv64-qemu-virt.toml +++ /dev/null @@ -1,67 +0,0 @@ -# Architecture identifier. -arch = "riscv64" -# Platform identifier. -platform = "riscv64-qemu-virt" -# Platform family. -family = "riscv64-qemu-virt" - -# Base address of the whole physical memory. -phys-memory-base = "0x8000_0000" -# Size of the whole physical memory. -phys-memory-size = "0x800_0000" # 128M -# Base physical address of the kernel image. -kernel-base-paddr = "0x8020_0000" -# Base virtual address of the kernel image. -kernel-base-vaddr = "0xffff_ffc0_8020_0000" -# Linear mapping offset, for quick conversions between physical and virtual -# addresses. -phys-virt-offset = "0xffff_ffc0_0000_0000" -# Offset of bus address and phys address. some boards, the bus address is -# different from the physical address. -phys-bus-offset = "0" -# Kernel address space base. -kernel-aspace-base = "0xffff_ffc0_0000_0000" -# Kernel address space size. -kernel-aspace-size = "0x0000_003f_ffff_f000" -# MMIO regions with format (`base_paddr`, `size`). -mmio-regions = [ - ["0x0010_1000", "0x1000"], # RTC - ["0x0c00_0000", "0x21_0000"], # PLIC - ["0x1000_0000", "0x1000"], # UART - ["0x1000_1000", "0x8000"], # VirtIO - ["0x3000_0000", "0x1000_0000"], # PCI config space - ["0x4000_0000", "0x4000_0000"], # PCI memory ranges (ranges 1: 32-bit MMIO space) -] -# VirtIO MMIO regions with format (`base_paddr`, `size`). -virtio-mmio-regions = [ - ["0x1000_1000", "0x1000"], - ["0x1000_2000", "0x1000"], - ["0x1000_3000", "0x1000"], - ["0x1000_4000", "0x1000"], - ["0x1000_5000", "0x1000"], - ["0x1000_6000", "0x1000"], - ["0x1000_7000", "0x1000"], - ["0x1000_8000", "0x1000"], -] -# Base physical address of the PCIe ECAM space. -pci-ecam-base = "0x3000_0000" -# End PCI bus number (`bus-range` property in device tree). -pci-bus-end = "0xff" -# PCI device memory ranges (`ranges` property in device tree). -pci-ranges = [ - ["0x0300_0000", "0x1_0000"], # PIO space - ["0x4000_0000", "0x4000_0000"], # 32-bit MMIO space - ["0x4_0000_0000", "0x4_0000_0000"], # 64-but MMIO space -] - -# Timer interrupt frequency in Hz. -timer-frequency = "10_000_000" # 10MHz - -# rtc@101000 { -# interrupts = <0x0b>; -# interrupt-parent = <0x03>; -# reg = <0x00 0x101000 0x00 0x1000>; -# compatible = "google,goldfish-rtc"; -# }; -# RTC (goldfish) Address -rtc-paddr = "0x10_1000" \ No newline at end of file diff --git a/platforms/x86_64-pc-oslab.toml b/platforms/x86_64-pc-oslab.toml deleted file mode 100644 index 8c4d1238a5..0000000000 --- a/platforms/x86_64-pc-oslab.toml +++ /dev/null @@ -1,44 +0,0 @@ -# Architecture identifier. -arch = "x86_64" -# Platform identifier. -platform = "x86_64-pc-oslab" -# Platform family. -family = "x86-pc" - -# Base address of the whole physical memory. -phys-memory-base = "0" -# Size of the whole physical memory. -phys-memory-size = "0x8000_0000" # 2G -# Base physical address of the kernel image. -kernel-base-paddr = "0x20_0000" -# Base virtual address of the kernel image. -kernel-base-vaddr = "0xffff_ff80_0020_0000" -# Linear mapping offset, for quick conversions between physical and virtual -# addresses. -phys-virt-offset = "0xffff_ff80_0000_0000" -# Offset of bus address and phys address. some boards, the bus address is -# different from the physical address. -phys-bus-offset = "0" -# Kernel address space base. -kernel-aspace-base = "0xffff_ff80_0000_0000" -# Kernel address space size. -kernel-aspace-size = "0x0000_007f_ffff_f000" -# MMIO regions with format (`base_paddr`, `size`). -mmio-regions = [ - ["0xfec0_0000", "0x1000"], # IO APIC - ["0xfed0_0000", "0x1000"], # HPET - ["0xfee0_0000", "0x1000"], # Local APIC - ["0xf000_0000", "0x0800_0000"], # PCI config space - ["0xfcd8_0000", "0x0008_0000"], # Ixgbe BAR0 -] -# VirtIO MMIO regions with format (`base_paddr`, `size`). -virtio-mmio-regions = [] -# Base physical address of the PCIe ECAM space (should read from ACPI 'MCFG' table). -pci-ecam-base = "0xf000_0000" -# End PCI bus number. -pci-bus-end = "0x7f" -# PCI device memory ranges (not used on x86). -pci-ranges = [] - -# Timer interrupt frequencyin Hz. -timer-frequency = "4_000_000_000" # 4.0GHz diff --git a/platforms/x86_64-qemu-q35.toml b/platforms/x86_64-qemu-q35.toml deleted file mode 100644 index 9b9b9e0fb4..0000000000 --- a/platforms/x86_64-qemu-q35.toml +++ /dev/null @@ -1,44 +0,0 @@ -# Architecture identifier. -arch = "x86_64" -# Platform identifier. -platform = "x86_64-qemu-q35" -# Platform family. -family = "x86-pc" - -# Base address of the whole physical memory. -phys-memory-base = "0" -# Size of the whole physical memory. -phys-memory-size = "0x800_0000" # 128M -# Base physical address of the kernel image. -kernel-base-paddr = "0x20_0000" -# Base virtual address of the kernel image. -kernel-base-vaddr = "0xffff_ff80_0020_0000" -# Linear mapping offset, for quick conversions between physical and virtual -# addresses. -phys-virt-offset = "0xffff_ff80_0000_0000" -# Offset of bus address and phys address. some boards, the bus address is -# different from the physical address. -phys-bus-offset = "0" -# Kernel address space base. -kernel-aspace-base = "0xffff_ff80_0000_0000" -# Kernel address space size. -kernel-aspace-size = "0x0000_007f_ffff_f000" -# MMIO regions with format (`base_paddr`, `size`). -mmio-regions = [ - ["0xb000_0000", "0x1000_0000"], # PCI config space - ["0xfe00_0000", "0xc0_0000"], # PCI devices - ["0xfec0_0000", "0x1000"], # IO APIC - ["0xfed0_0000", "0x1000"], # HPET - ["0xfee0_0000", "0x1000"], # Local APIC -] -# VirtIO MMIO regions with format (`base_paddr`, `size`). -virtio-mmio-regions = [] -# Base physical address of the PCIe ECAM space (should read from ACPI 'MCFG' table). -pci-ecam-base = "0xb000_0000" -# End PCI bus number. -pci-bus-end = "0xff" -# PCI device memory ranges (not used on x86). -pci-ranges = [] - -# Timer interrupt frequencyin Hz. -timer-frequency = "4_000_000_000" # 4.0GHz diff --git a/scripts/make/build.mk b/scripts/make/build.mk index 96a6503e05..89252a04b0 100644 --- a/scripts/make/build.mk +++ b/scripts/make/build.mk @@ -9,11 +9,14 @@ else rust_elf := $(TARGET_DIR)/$(TARGET)/$(MODE)/$(rust_package) endif -ifneq ($(filter $(MAKECMDGOALS),doc doc_check_missing),) # run `cargo doc` +ifneq ($(filter $(MAKECMDGOALS),doc doc_check_missing),) + # run `make doc` RUSTFLAGS := $(RUSTFLAGS_WITHOUT_LINK_ARG) - $(if $(V), $(info RUSTDOCFLAGS: "$(RUSTDOCFLAGS)")) + $(if $(V), $(info RUSTFLAGS: "$(RUSTFLAGS)") $(info RUSTDOCFLAGS: "$(RUSTDOCFLAGS)")) + export RUSTFLAGS export RUSTDOCFLAGS -else ifeq ($(filter $(MAKECMDGOALS),clippy unittest unittest_no_fail_fast),) # not run `cargo test` or `cargo clippy` +else ifeq ($(filter $(MAKECMDGOALS),prepare defconfig oldconfig clippy unittest unittest_no_fail_fast),) + # not run make with the above goals ifneq ($(V),) $(info APP: "$(APP)") $(info APP_TYPE: "$(APP_TYPE)") @@ -28,13 +31,12 @@ else ifeq ($(filter $(MAKECMDGOALS),clippy unittest unittest_no_fail_fast),) # n else RUSTFLAGS := $(RUSTFLAGS_WITH_LINK_ARG) endif + $(if $(V), $(info RUSTFLAGS: "$(RUSTFLAGS)")) + export RUSTFLAGS endif -$(if $(V), $(info RUSTFLAGS: "$(RUSTFLAGS)")) -export RUSTFLAGS - -_cargo_build: - @printf " $(GREEN_C)Building$(END_C) App: $(APP_NAME), Arch: $(ARCH), Platform: $(PLATFORM_NAME), App type: $(APP_TYPE)\n" +_cargo_build: oldconfig + @printf " $(GREEN_C)Building$(END_C) App: $(APP_NAME), Arch: $(ARCH), Platform: $(PLAT_NAME), App type: $(APP_TYPE)\n" ifeq ($(APP_TYPE), rust) $(call cargo_build,$(APP),$(AX_FEAT) $(LIB_FEAT) $(APP_FEAT)) @cp $(rust_elf) $(OUT_ELF) diff --git a/scripts/make/config.mk b/scripts/make/config.mk new file mode 100644 index 0000000000..35f277667e --- /dev/null +++ b/scripts/make/config.mk @@ -0,0 +1,27 @@ +# Config generation + +config_file := .axconfig.toml + +config_args := \ + configs/defconfig.toml configs/platforms/$(PLAT_NAME).toml \ + -w 'smp=$(SMP)' \ + -w 'arch="$(ARCH)"' \ + -w 'plat-name="$(PLAT_NAME)"' \ + -o $(config_file) + +define defconfig + $(call run_cmd,axconfig-gen,$(config_args)) +endef + +ifneq ($(wildcard $(config_file)),) + define oldconfig + $(if $(filter "$(PLAT_NAME)",$(shell axconfig-gen $(config_file) -r plat-name)),\ + ,\ + $(error "ARCH" or "PLATFORM" has been changed, please run "make defconfig" again)) + $(call run_cmd,axconfig-gen,$(config_args) -c $(config_file)) + endef +else + define oldconfig + $(call defconfig) + endef +endif diff --git a/scripts/make/platform.mk b/scripts/make/platform.mk new file mode 100644 index 0000000000..7a33c293fe --- /dev/null +++ b/scripts/make/platform.mk @@ -0,0 +1,57 @@ +# Architecture and platform resolving + +ifneq ($(filter $(MAKECMDGOALS),unittest unittest_no_fail_fast),) + PLAT_NAME := +else ifeq ($(PLATFORM),) + # `PLATFORM` is not specified, use the default platform for each architecture + ifeq ($(ARCH), x86_64) + PLAT_NAME := x86_64-qemu-q35 + else ifeq ($(ARCH), aarch64) + PLAT_NAME := aarch64-qemu-virt + else ifeq ($(ARCH), riscv64) + PLAT_NAME := riscv64-qemu-virt + endif +else ifneq ($(PLATFORM),) + # `PLATFORM` is specified, override the `ARCH` variables + builtin_platforms := $(patsubst configs/platforms/%.toml,%,$(wildcard configs/platforms/*)) + ifneq ($(filter $(PLATFORM),$(builtin_platforms)),) + # builtin platform + PLAT_NAME := $(PLATFORM) + _arch := $(word 1,$(subst -, ,$(PLATFORM))) + else ifneq ($(wildcard $(PLATFORM)),) + # custom platform, read the "arch" and "plat-name" fields from the toml file + PLAT_NAME := $(patsubst "%",%,$(shell axconfig-gen $(PLATFORM) -r platform.plat-name)) + _arch := $(patsubst "%",%,$(shell axconfig-gen $(PLATFORM) -r platform.arch)) + else + $(error "PLATFORM" must be one of "$(builtin_platforms)" or a valid path to a toml file) + endif + ifeq ($(origin ARCH),command line) + ifneq ($(ARCH),$(_arch)) + $(error "ARCH=$(ARCH)" is not compatible with "PLATFORM=$(PLATFORM)") + endif + endif + ARCH := $(_arch) +endif + +# Target +ifeq ($(ARCH), x86_64) + TARGET := x86_64-unknown-none + ifeq ($(shell uname -r | tr '[:upper:]' '[:lower:]'), -microsoft) + # Don't enable kvm for WSL/WSL2. + ACCEL ?= n + else + ACCEL ?= $(if $(findstring x86_64, $(shell uname -m)),y,n) + endif +else ifeq ($(ARCH), aarch64) + ifeq ($(findstring fp_simd,$(FEATURES)),) + TARGET := aarch64-unknown-none-softfloat + else + TARGET := aarch64-unknown-none + endif + ACCEL ?= $(if $(findstring arm64, $(shell uname -m)),y,n) +else ifeq ($(ARCH), riscv64) + TARGET := riscv64gc-unknown-none-elf + ACCEL ?= n +else + $(error "ARCH" must be one of "x86_64", "riscv64", or "aarch64") +endif diff --git a/scripts/make/qemu.mk b/scripts/make/qemu.mk index fd2c78b9a6..9d1c3939af 100644 --- a/scripts/make/qemu.mk +++ b/scripts/make/qemu.mk @@ -68,6 +68,18 @@ endif qemu_args-debug := $(qemu_args-y) -s -S +ifeq ($(ACCEL),) + ifneq ($(findstring -microsoft, $(shell uname -r | tr '[:upper:]' '[:lower:]')),) + ACCEL := n # Don't enable kvm for WSL/WSL2 + else ifeq ($(ARCH), x86_64) + ACCEL := $(if $(findstring x86_64, $(shell uname -m)),y,n) + else ifeq ($(ARCH), aarch64) + ACCEL := $(if $(findstring arm64, $(shell uname -m)),y,n) + else + ACCEL := n + endif +endif + # Do not use KVM for debugging ifeq ($(shell uname), Darwin) qemu_args-$(ACCEL) += -cpu host -accel hvf