#hal #x86-64 #arceos

no-std axplat-x86-pc

Implementation of axplat hardware abstraction layer for x86 Standard PC machine

3 unstable releases

Uses new Rust 2024

0.2.0 Aug 21, 2025
0.1.1 Jul 8, 2025
0.1.0 Jul 2, 2025

#1181 in Hardware support

Download history 325/week @ 2025-07-09 297/week @ 2025-07-16 364/week @ 2025-07-23 416/week @ 2025-07-30 402/week @ 2025-08-06 625/week @ 2025-08-13 1167/week @ 2025-08-20 697/week @ 2025-08-27 854/week @ 2025-09-03 566/week @ 2025-09-10 465/week @ 2025-09-17 980/week @ 2025-09-24 92/week @ 2025-10-01 453/week @ 2025-10-08 218/week @ 2025-10-15 519/week @ 2025-10-22

1,329 downloads per month

GPL-3.0-or-later OR Apache-2…

60KB
990 lines

axplat-x86-pc

Crates.io CI

Implementation of axplat hardware abstraction layer for x86 Standard PC machine.

Install

cargo +nightly add axcpu axplat axplat-x86-pc

Usage

1. Write your kernel code

#[axplat::main]
fn kernel_main(cpu_id: usize, arg: usize) -> ! {
    // x86_64 requires the `percpu` crate to be initialized first.
    axcpu::init::init_percpu(cpu_id);
    // Initialize trap, console, time.
    axplat::init::init_early(cpu_id, arg);
    // Initialize platform peripherals (not used in this example).
    axplat::init::init_later(cpu_id, arg);

    // Write your kernel code here.
    axplat::console_println!("Hello, ArceOS!");

    // Power off the system.
    axplat::power::system_off();
}
// Can be located at any dependency crate.
extern crate axplat_x86_pc;

3. Use a linker script like the following

ENTRY(_start)
SECTIONS
{
    . = 0xffff000040200000;
    _skernel = .;                   /* Symbol `_skernel` is required */

    .text : ALIGN(4K) {
        *(.text.boot)               /* This section is required */
        *(.text .text.*)
    }

    .rodata : ALIGN(4K) {
        *(.rodata .rodata.*)
    }

    .data : ALIGN(4K) {
        *(.data .data.*)
    }

    /* .percpu section and related symbols are required */
    . = ALIGN(4K);
    _percpu_start = .;
    _percpu_end = _percpu_start + SIZEOF(.percpu);
    .percpu 0x0 : AT(_percpu_start) {
        _percpu_load_start = .;
        *(.percpu .percpu.*)
        _percpu_load_end = .;
        . = _percpu_load_start + ALIGN(64) * 1;
    }
    . = _percpu_end;
    _edata = .;                     /* Symbol `_edata` is required */

    .bss : ALIGN(4K) {
        *(.bss.stack)               /* This section is required */
        . = ALIGN(4K);
        *(.bss .bss.*)
        *(COMMON)
        _ebss = .;                  /* Symbol `_ebss` is required */
    }

    /DISCARD/ : {
        *(.comment)
    }
}

Some symbols and sections are required to be defined in the linker script, listed as below:

  • _skernel: Start of kernel image.
  • _edata: End of data section.
  • _ebss: End of BSS section.
  • .text.boot: Kernel boot code.
  • .bss.stack: Stack for kernel booting.
  • .percpu section and related symbols: CPU-local data managed by the percpu crate.

hello-kernel is a complete example of a minimal kernel implemented using axplat and related platform packages.

Dependencies

~7.5MB
~114K SLoC