Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions platform/x86_64/qemu/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ const ROOT_ZONE_UEFI_REGION: HvConfigMemoryRegion = HvConfigMemoryRegion {
const ROOT_ZONE_UEFI_REGION_ID: usize = 0x3;

pub const ROOT_ZONE_NAME: &str = "root-linux";
pub const ROOT_ZONE_CMDLINE: &str =
// "BOOT_IMAGE=/boot/aster-kernel-osdk-bin SHELL=/bin/sh LOGNAME=root HOME=/ USER=root PATH=/bin:/benchmark ostd.log_level=info console=ttyS0 console=tty0 -- sh -l";
// TODO: Asterinas
"console=ttyS0 earlyprintk=serial nointremap no_timer_check efi=noruntime pci=pcie_scan_all,lastbus=1 root=/dev/vda rw init=/init\0";

/// Reserved HPA range for zone1 high memory (0x1_0000_0000 -> 0x2_E000_0000).
/// Adjust if zone1 high-memory layout changes.
const ZONE1_HIGH_RESERVED_SIZE: u64 = 0x1_E000_0000;
pub const ROOT_ZONE_CMDLINE: &str =
"console=tty0 console=ttyS0 earlycon=efifb earlyprintk=serial nointremap no_timer_check efi=noruntime pci=pcie_scan_all,lastbus=1 root=/dev/vda rw init=/sbin/init\0";
//"console=ttyS0 earlyprintk=serial rdinit=/init nokaslr nointremap\0"; // noapic
// video=vesafb
// /lib/systemd/systemd
Expand Down Expand Up @@ -106,13 +108,11 @@ pub const ROOT_ZONE_MEMORY_REGIONS: [HvConfigMemoryRegion; 10] = [
mem_type: MEM_TYPE_RESERVED,
physical_start: 0x1_0000_0000,
virtual_start: 0x1_0000_0000,
size: 0x7000_0000,
}, // zone 1
size: ZONE1_HIGH_RESERVED_SIZE,
}, // zone 1 (0x100000000 → 0x2E0000000)
];

const ROOT_ZONE_CMDLINE_ADDR: GuestPhysAddr = 0x9000;
// TODO: Asterinas
// const ROOT_ZONE_SETUP_ADDR: GuestPhysAddr = 0xf_f000;
const ROOT_ZONE_SETUP_ADDR: GuestPhysAddr = 0xa000;
const ROOT_ZONE_VMLINUX_ENTRY_ADDR: GuestPhysAddr = 0x10_0000;
const ROOT_ZONE_SCREEN_BASE_ADDR: GuestPhysAddr = 0x7000_0000;
Expand All @@ -126,14 +126,15 @@ pub const ROOT_ARCH_ZONE_CONFIG: HvArchZoneConfig = HvArchZoneConfig {
kernel_entry_gpa: ROOT_ZONE_VMLINUX_ENTRY_ADDR,
cmdline_load_gpa: ROOT_ZONE_CMDLINE_ADDR,
setup_load_gpa: ROOT_ZONE_SETUP_ADDR,
// TODO: Asterinas
initrd_load_gpa:0,// 0x1530_0000,
initrd_size:0,// 0x210_0000, //0x26_b000,
initrd_load_gpa: 0, // 0x1500_0000,
initrd_size: 0, //0x26_b000,
rsdp_memory_region_id: ROOT_ZONE_RSDP_REGION_ID,
acpi_memory_region_id: ROOT_ZONE_ACPI_REGION_ID,
uefi_memory_region_id: ROOT_ZONE_UEFI_REGION_ID,
// not longer than 32 bits
screen_base: ROOT_ZONE_SCREEN_BASE_ADDR,
multiboot_info_paddr: 0,
multiboot_enabled: 0,
};

pub const ROOT_PCI_CONFIG: [HvPciConfig; 1] = [HvPciConfig {
Expand All @@ -159,12 +160,9 @@ pub const ROOT_PCI_DEVS: [HvPciDevConfig; 8] = [
pci_dev!(0x0, 0x0, 0x1, 0x0, VpciDevType::Physical), // VGA controller
pci_dev!(0x0, 0x0, 0x2, 0x0, VpciDevType::Physical), // Ethernet controller
pci_dev!(0x0, 0x0, 0x3, 0x0, VpciDevType::Physical), // PCI bridge
// Asterinas
pci_dev!(0x0, 0x0, 0x4, 0x0, VpciDevType::Physical), // PCI bridge

pci_dev!(0x0, 0x0, 0x1f, 0x0, VpciDevType::Physical), // ISA bridge
pci_dev!(0x0, 0x0, 0x1f, 0x2, VpciDevType::Physical), // SATA controller
// pci_dev!(0x0, 0x0, 0x1f, 0x3, VpciDevType::Physical), // SMBus
pci_dev!(0x0, 0x0, 0x1f, 0x3, VpciDevType::Physical), // SMBus
pci_dev!(0x0, 0x1, 0x0, 0x0, VpciDevType::Physical), // SCSI controller
];

Expand Down
36 changes: 12 additions & 24 deletions platform/x86_64/qemu/configs/virtio_cfg.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,34 @@
"zone0_ipa": "0x40300000",
"zonex_ipa": "0x0",
"size": "0x20000000"
},
{
"zone0_ipa": "0x100000000",
"zonex_ipa": "0x100000000",
"size": "0x70000000"
}
],
"devices": [
{
"type": "console",
"addr": "0x5950f000",
"status": "enable",
"addr": "0xFEB00000",
"len": "0x200",
"irq": 10,
"status": "enable"
"irq": "16"
},
{
"type": "net",
"addr": "0x5950f200",
"status": "enable",
"addr": "0xFEB00200",
"len": "0x200",
"irq": 14,
"irq": "17",
"tap": "tap0",
"mac": [
"0x00",
"0x16",
"0x3e",
"0x10",
"0x10",
"0x10"
],
"status": "enable"
"mac": ["0x00", "0x16", "0x3e", "0x10", "0x10", "0x10"]
},
{
"type": "blk",
"addr": "0x5950f400",
"status": "enable",
"addr": "0xFEB00400",
"len": "0x200",
"irq": 11,
"img": "rootfs2.img",
"status": "enable"
"irq": "18",
"img": "/zone1_disk.img"
}
]
}
]
}
}
84 changes: 84 additions & 0 deletions platform/x86_64/qemu/configs/zone1-asterinas.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"name": "asterinas",
"zone_id": 1,
"cpus": [2, 3],
"memory_regions": [
{
"type": "ram",
"physical_start": "0x40300000",
"virtual_start": "0x0",
"size": "0xe0000"
},
{
"type": "ram",
"physical_start": "0x403e0000",
"virtual_start": "0xe0000",
"size": "0x20000"
},
{
"type": "ram",
"physical_start": "0x40400000",
"virtual_start": "0x100000",
"size": "0x1fe00000"
},
{
"type": "ram",
"physical_start": "0x60200000",
"virtual_start": "0x1ff00000",
"size": "0x100000"
},
{
"type": "virtio",
"physical_start": "0xFEB00000",
"virtual_start": "0xFEB00000",
"size": "0x2000"
}
],
"interrupts": [],
"ivc_configs": [],
"kernel_filepath": "./aster-kernel-osdk-bin",
"dtb_filepath": "null",
"kernel_load_paddr": "0x8000000",
"dtb_load_paddr": "0x00000000",
"entry_point": "0x8000",
"multiboot_enabled": true,
"multiboot_info_paddr": "0x9000000",
"kernel_cmdline": "console=hvc0 root=/dev/vda rw ostd.log_level=error",
"initramfs_filepath": "./initramfs.cpio.gz",
"initramfs_load_gpa": "0x10000000",
"arch_config": {
"ioapic_base": "0xfec00000",
"ioapic_size": "0x1000",
"boot_filepath": "mb2_boot.bin",
"boot_load_paddr": "0x8000",
"kernel_entry_gpa": "0x8000000",
"cmdline_load_gpa": "0x9000000",
"setup_load_gpa": "0x80000",
"initrd_load_gpa": "0x0",
"initrd_size": "0x0",
"rsdp_memory_region_id": 1,
"acpi_memory_region_id": 3,
"uefi_memory_region_id": 0,
"screen_base": "0x0"
},
"pci_config": [
{
"ecam_base": "0xb0000000",
"ecam_size": "0x200000",
"io_base": "0x0",
"io_size": "0x0",
"pci_io_base": "0x0",
"mem32_base": "0x0",
"mem32_size": "0x0",
"pci_mem32_base": "0x0",
"mem64_base": "0x0",
"mem64_size": "0x0",
"pci_mem64_base": "0x0",
"bus_range_begin": "0x0",
"bus_range_end": "0x1f",
"domain": "0x0"
}
],
"num_pci_devs": 0,
"alloc_pci_devs": []
}
68 changes: 68 additions & 0 deletions platform/x86_64/qemu/image/mb2_bootloader/mb2_boot.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Multiboot2 bootloader for Asterinas zone1
# Transitions from 16-bit real mode to 32-bit protected mode,
# sets up GDT with TSS, then jumps to the kernel entry point.
#
# Entry state (from VMCS guest_regs via unrestricted guest):
# EAX = Multiboot2 magic (0x36D76289)
# EBX = Multiboot2 info pointer (GPA)
# ESI = Kernel entry point (GPA)

.section .text
.code16
.global mb2_entry16
mb2_entry16:
cli
cld

mov ebp, eax # save multiboot magic
mov edi, ebx # save multiboot info pointer
mov ecx, esi # save kernel entry point

xor ax, ax
mov ds, ax
mov es, ax
mov ss, ax

lgdt [mb2_gdt_desc]
mov eax, cr0
or eax, 0x1
mov cr0, eax

ljmp 0x08, mb2_entry32

.code32
.global mb2_entry32
mb2_entry32:
mov ax, 0x10
mov ds, ax
mov es, ax
mov ss, ax
mov fs, ax
mov gs, ax

# Load TSS (entry 4 at selector 0x20)
mov ax, 0x20
ltr ax

# Restore Multiboot2 parameters
mov eax, ebp
mov ebx, edi

# Set up stack
mov esp, MB2_STACK

# Jump to kernel entry
jmp ecx

.align 16
mb2_gdt:
.quad 0x0000000000000000 # 0x00: null
.quad 0x00cf9b000000ffff # 0x08: 32-bit code
.quad 0x00cf93000000ffff # 0x10: 32-bit data
.quad 0x0000000000000000 # 0x18: unused
.quad MB2_TSS_DESCRIPTOR # 0x20: 32-bit available TSS
mb2_gdt_end:

mb2_gdt_desc:
.short mb2_gdt_end - mb2_gdt - 1
.long mb2_gdt
15 changes: 15 additions & 0 deletions platform/x86_64/qemu/image/mb2_bootloader/mb2_boot.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
OUTPUT_ARCH(i386)
BASE_ADDRESS = 0x8000;

ENTRY(mb2_entry16)
SECTIONS
{
. = BASE_ADDRESS;
.text : {
*(.text .text.*)
}

/DISCARD/ : {
*(.eh_frame) *(.eh_frame_hdr)
}
}
37 changes: 37 additions & 0 deletions platform/x86_64/qemu/image/mb2_bootloader/mb2_boot.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
mb2_boot_dir := $(image_dir)/mb2_bootloader
mb2_boot_out_dir := $(image_dir)/mb2_bootloader/out

mb2_boot_src := $(mb2_boot_dir)/mb2_boot.S
mb2_boot_lds := $(mb2_boot_dir)/mb2_boot.ld

mb2_boot_o := $(mb2_boot_out_dir)/mb2_boot.o
mb2_boot_elf := $(mb2_boot_out_dir)/mb2_boot.elf
mb2_boot_bin := $(mb2_boot_out_dir)/mb2_boot.bin

AS ?= as
LD ?= ld
OBJCOPY ?= objcopy

# TSS descriptor: base=0x8048000, limit=103, type=0x89 (32-bit available TSS)
MB2_TSS_DESC := 0x8000890480000067
MB2_STACK := 0x804a000

mb2_boot_flags := --32 -msyntax=intel -mnaked-reg
mb2_boot_flags += --defsym MB2_STACK=$(MB2_STACK)
mb2_boot_flags += --defsym MB2_TSS_DESCRIPTOR=$(MB2_TSS_DESC)

mb2_boot: | $(mb2_boot_out_dir) $(mb2_boot_bin)

$(mb2_boot_out_dir):
mkdir -p $@

$(mb2_boot_o): $(mb2_boot_src)
$(AS) $(mb2_boot_flags) $< -o $@

$(mb2_boot_elf): $(mb2_boot_o) $(mb2_boot_lds)
$(LD) -T$(mb2_boot_lds) $< -o $@

$(mb2_boot_bin): $(mb2_boot_elf)
$(OBJCOPY) $< --strip-all -O binary $@

.PHONY: mb2_boot
9 changes: 7 additions & 2 deletions platform/x86_64/qemu/platform.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
QEMU := qemu-system-x86_64

zone0_boot := $(image_dir)/bootloader/out/boot.bin
zone1_mb2_boot := $(image_dir)/mb2_bootloader/out/mb2_boot.bin
zone0_setup := $(image_dir)/kernel/setup.bin
zone0_vmlinux := $(image_dir)/kernel/vmlinux.bin
zone0_asterinas := $(image_dir)/kernel/aster-kernel-osdk-bin
Expand Down Expand Up @@ -53,7 +54,7 @@ QEMU_ARGS += -drive file=$(image_dir)/virtdisk/hvisor.iso,format=raw,index=0,med
# QEMU_ARGS += -device loader,file="$(zone0_initrd)",addr=0x1a000000,force-raw=on
# QEMU_ARGS += -append "initrd_size=$(shell stat -c%s $(zone0_initrd))"

$(hvisor_bin): elf boot
$(hvisor_bin): elf boot mb2_boot
$(OBJCOPY) $(hvisor_elf) --strip-all -O binary $@
cp $(hvisor_elf) $(image_dir)/iso/boot
mkdir -p $(image_dir)/iso/boot/kernel
Expand Down Expand Up @@ -89,11 +90,15 @@ $(hvisor_bin): elf boot
else \
echo "Warning: $(zone0_initrd) not found, skipping"; \
fi
if [ -f $(zone1_mb2_boot) ]; then \
cp $(zone1_mb2_boot) $(image_dir)/iso/boot/kernel; \
fi

if command -v xorriso >/dev/null 2>&1; then \
grub-mkrescue /usr/lib/grub/x86_64-efi -o $(image_dir)/virtdisk/hvisor.iso $(image_dir)/iso; \
else \
echo "Warning: xorriso not installed, skipping ISO creation"; \
fi

include $(image_dir)/bootloader/boot.mk
include $(image_dir)/bootloader/boot.mk
include $(image_dir)/mb2_bootloader/mb2_boot.mk
Loading
Loading