Skip to content
Draft
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/platform/*/*/image/kernel/*
/platform/*/*/image/virtdisk/*
/platform/*/*/image/bootloader/out
/platform/*/*/image/mb2_bootloader/out
/platform/*/*/image/iso/boot/kernel/*
/platform/*/*/image/iso/boot/hvisor
/tools/hvisor
Expand Down Expand Up @@ -41,4 +42,4 @@ jenkins/__pycache__
jenkins-cli.jar
tools/kconfig/.venv/
tools/kconfig/__pycache__/
kernel_build/
kernel_build/
8 changes: 4 additions & 4 deletions platform/x86_64/nuc14mnk/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ 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 = "video=vesafb console=tty0 nointremap no_timer_check efi=noruntime pci=pcie_scan_all root=/dev/nvme0n1p5 rw init=/init rootwait\0";
pub const ROOT_ZONE_CMDLINE: &str = "video=vesafb console=tty0 earlycon=efifb nointremap no_timer_check efi=noruntime pci=pcie_scan_all root=/dev/nvme0n1p5 rw init=/init rootwait\0";
// pub const ROOT_ZONE_CMDLINE: &str = "video=vesafb console=ttyS0 earlyprintk=serial nointremap no_timer_check pci=pcie_scan_all root=/dev/vda rw init=/init\0";
//"console=ttyS0 earlyprintk=serial rdinit=/init nokaslr nointremap\0"; // noapic
// video=vesafb
Expand Down Expand Up @@ -113,9 +113,9 @@ pub const ROOT_ZONE_MEMORY_REGIONS: [HvConfigMemoryRegion; 15] = [
}, // pnp 00:05
HvConfigMemoryRegion {
mem_type: MEM_TYPE_RESERVED,
physical_start: 0xfe01_1000,
virtual_start: 0xfe01_1000,
size: 0x40_0000,
physical_start: 0xfe00_0000,
virtual_start: 0xfe00_0000,
size: 0xd0_0000,
}, // reserved
HvConfigMemoryRegion {
mem_type: MEM_TYPE_RESERVED,
Expand Down
22 changes: 17 additions & 5 deletions platform/x86_64/qemu/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,18 @@ const ROOT_ZONE_UEFI_REGION_ID: usize = 0x3;

pub const ROOT_ZONE_NAME: &str = "root-linux";
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=/init\0";
// "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=tty0 console=ttyS0 earlycon=efifb earlyprintk=serial nointremap no_timer_check efi=noruntime pci=pcie_scan_all,lastbus=1 root=/dev/vda rw init=/init\0";
//"console=ttyS0 earlyprintk=serial rdinit=/init nokaslr nointremap\0"; // noapic
// video=vesafb
// /lib/systemd/systemd

/// Reserved HPA range for zone1 high memory (0x1_0000_0000 -> 0x2_E000_0000).
/// Reserved as a placeholder for future zone1 high-memory regions; the current
/// Asterinas config does not use this range under QEMU's default 4G RAM.
const ZONE1_HIGH_RESERVED_SIZE: u64 = 0x1_E000_0000;

pub const ROOT_ZONE_MEMORY_REGIONS: [HvConfigMemoryRegion; 10] = [
HvConfigMemoryRegion {
mem_type: MEM_TYPE_RAM,
Expand Down Expand Up @@ -104,11 +111,13 @@ 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,
size: ZONE1_HIGH_RESERVED_SIZE,
}, // zone 1
];

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 @@ -122,8 +131,9 @@ 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,
initrd_load_gpa: 0, // 0x1500_0000,
initrd_size: 0, //0x26_b000,
// TODO: Asterinas
initrd_load_gpa: 0, // 0x1530_0000,
initrd_size: 0, // 0x210_0000, //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,
Expand All @@ -149,11 +159,13 @@ pub const ROOT_PCI_CONFIG: [HvPciConfig; 1] = [HvPciConfig {
}];

pub const ROOT_PCI_MAX_BUS: usize = 1;
pub const ROOT_PCI_DEVS: [HvPciDevConfig; 7] = [
pub const ROOT_PCI_DEVS: [HvPciDevConfig; 8] = [
pci_dev!(0x0, 0x0, 0x0, 0x0 => 0x0, 0x0, 0x0, VpciDevType::Physical), // host bridge
pci_dev!(0x0, 0x0, 0x1, 0x0 => 0x0, 0x1, 0x0, VpciDevType::Physical), // VGA controller
pci_dev!(0x0, 0x0, 0x2, 0x0 => 0x0, 0x2, 0x0, VpciDevType::Physical), // Ethernet controller
pci_dev!(0x0, 0x0, 0x3, 0x0 => 0x0, 0x3, 0x0, VpciDevType::Physical), // PCI bridge
// Asterinas
pci_dev!(0x0, 0x0, 0x4, 0x0 => 0x0, 0x4, 0x0, VpciDevType::Physical), // PCI bridge
pci_dev!(0x0, 0x0, 0x1f, 0x0 => 0x0, 0x1f, 0x0, VpciDevType::Physical), // ISA bridge
pci_dev!(0x0, 0x0, 0x1f, 0x2 => 0x0, 0x1f, 0x2, VpciDevType::Physical), // SATA controller
// pci_dev!(0x0, 0x0, 0x1f, 0x3 => 0x0, 0x1f, 0x3, VpciDevType::Physical), // SMBus
Expand Down
40 changes: 40 additions & 0 deletions platform/x86_64/qemu/configs/virtio_cfg_asterinas.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"zones": [
{
"id": 1,
"memory_region": [
{
"zone0_ipa": "0x40300000",
"zonex_ipa": "0x0",
"size": "0x20000000"
}
],
"devices": [
{
"type": "console",
"status": "enable",
"addr": "0xFEB00000",
"len": "0x200",
"irq": "16"
},
{
"type": "net",
"status": "enable",
"addr": "0xFEB00200",
"len": "0x200",
"irq": "17",
"tap": "tap0",
"mac": ["0x00", "0x16", "0x3e", "0x10", "0x10", "0x10"]
},
{
"type": "blk",
"status": "enable",
"addr": "0xFEB00400",
"len": "0x200",
"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 ostd.log_level=error SHELL=/bin/sh LOGNAME=root HOME=/ USER=root PATH=/bin:/benchmark init=/init -- sh -l",
"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": "0x8001238",
"cmdline_load_gpa": "0x9020000",
"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": "0xe0000000",
"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": []
}
11 changes: 10 additions & 1 deletion platform/x86_64/qemu/image/iso/boot/grub/grub.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@ set default=0 # default menu entry index

insmod all_video


menuentry "Hvisor" {
multiboot2 /boot/hvisor # use multiboot spec to boot
module2 /boot/kernel/boot.bin 0
module2 /boot/kernel/boot.bin 5008000
module2 /boot/kernel/setup.bin 500a000
module2 /boot/kernel/vmlinux.bin 5100000
module2 /boot/kernel/initramfs.cpio.gz 1a000000
boot
}

menuentry "Asterinas" {
multiboot2 /boot/hvisor # use multiboot spec to boot
module2 /boot/kernel/boot.bin 0
module2 /boot/kernel/boot.bin 5008000
module2 /boot/kernel/aster-kernel-osdk-bin 50ff000
module2 /boot/kernel/initramfs.cpio.gz 1a300000
boot
}

Expand Down
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)
}
}
40 changes: 40 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,40 @@
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=0x1fffc000, limit=103, type=0x89 (32-bit available TSS)
# Encoded bytes: 67 00 00 c0 ff 89 00 1f
# Stack/TSS live near the top of zone1 low RAM, outside the kernel LOAD range.
# The stack at 0x1fffe000 must not grow more than 8KB into the TSS below.
MB2_TSS_DESC := 0x1F0089FFC0000067
MB2_STACK := 0x1fffe000

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
Loading
Loading