| Crates.io | somehal |
| lib.rs | somehal |
| version | 0.4.4 |
| created_at | 2025-07-22 09:07:18.224868+00 |
| updated_at | 2025-09-22 08:23:15.595129+00 |
| description | Boot kernel code with mmu. |
| homepage | |
| repository | https://github.com/rcore-os/somehal |
| max_upload_size | |
| id | 1763247 |
| size | 145,917 |
SomeHAL is a hardware abstraction layer library designed specifically for AArch64 chips with MMU functionality. It provides bootloader capabilities to complete MMU initialization and run code at specified virtual addresses.
Add to your Cargo.toml:
[dependencies]
somehal = "0.3"
#![no_std]
#![no_main]
use somehal::{entry, BootInfo};
#[entry]
fn main(boot_info: &BootInfo) -> ! {
// Your kernel main function
println!("Hello from virtual address!");
// Access boot information
println!("FDT address: {:p}", boot_info.fdt);
println!("Memory regions: {}", boot_info.memory_regions.len());
// Your kernel logic
loop {}
}
use somehal::{entry, secondary_entry, BootInfo};
#[entry]
fn main(boot_info: &BootInfo) -> ! {
// Primary CPU startup logic
println!("Primary CPU started");
// Start other cores
let secondary_addr = somehal::secondary_entry_addr();
// Start other cores through your method...
loop {}
}
#[secondary_entry]
fn secondary_main(cpu_id: usize) -> ! {
// Secondary CPU startup logic
println!("Secondary CPU {} started", cpu_id);
loop {}
}
_start) - Save boot parametersVirtual Address Space:
0xffff_0000_0000_0000 +----------------+
| Kernel Space |
| |
0xffff_8000_0000_0000 +----------------+
| Linear Mapping|
| (Physical Mem) |
0xffff_0000_0000_0000 +----------------+
BootInfo provides important boot-time information:
pub struct BootInfo {
pub fdt: Option<NonNull<u8>>, // Device tree pointer
pub memory_regions: MemoryRegions, // Memory region list
pub kimage_start_lma: u64, // Kernel load address
pub kimage_start_vma: u64, // Kernel virtual address
pub free_memory_start: *mut u8, // Free memory start address
pub pg_start: u64, // Page table start address
pub cpu_id: usize, // CPU ID
}
hv: Enable hypervisor mode (EL2) support[dependencies]
somehal = { version = "0.3", features = ["hv"] }
use somehal::{BootInfo, MemoryRegionKind};
#[entry]
fn main(boot_info: &BootInfo) -> ! {
for region in boot_info.memory_regions.iter() {
match region.kind {
MemoryRegionKind::Ram => {
println!("RAM: {:#x} - {:#x}", region.start, region.end);
}
MemoryRegionKind::Reserved => {
println!("Reserved: {:#x} - {:#x}", region.start, region.end);
}
}
}
loop {}
}
use somehal::mem::iomap;
// Map I/O device memory
let device_base = 0x1000_0000;
let device_size = 0x1000;
match iomap(device_base, device_size) {
Ok(virt_addr) => {
println!("Device mapped at {:p}", virt_addr);
// Use virtual address to access device
}
Err(e) => {
println!("Failed to map device: {:?}", e);
}
}
use somehal::*;
println!("Early boot message");
SomeHAL requires specific linker script configuration. Create link.ld in your project:
STACK_SIZE = 0x40000;
INCLUDE "somehal.x"
SECTIONS
{
# other sections...
}
In build.rs:
fn main() {
// SomeHAL will automatically configure necessary linking parameters
println!("cargo:rustc-link-arg=-Tlink.ld");
}
The project provides test configurations for multiple platforms:
# Test runtime
cargo test --target aarch64-unknown-none-softfloat -p test-some-rt
# Test configuration with VM functionality
cargo test --target aarch64-unknown-none-softfloat -p test-some-rt --features hv
Check the tests/test-some-rt directory for complete usage examples.
aarch64-unknown-none-softfloat targetThis project is licensed under the MIT License. See the LICENSE file for details.
Issues and pull requests are welcome!