mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-24 01:43:22 +00:00
Do mapping in the wrapper
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
e922eaa428
commit
85d4cfdeb7
@ -1,61 +0,0 @@
|
||||
use std::{
|
||||
error::Error,
|
||||
io::Write,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
let source_dir = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap());
|
||||
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
|
||||
build_linux_setup_header(&source_dir, &out_dir)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn build_linux_setup_header(
|
||||
source_dir: &Path,
|
||||
out_dir: &Path,
|
||||
) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
// Build the setup header to ELF.
|
||||
let setup_crate_dir = source_dir
|
||||
.join("src")
|
||||
.join("arch")
|
||||
.join("x86")
|
||||
.join("boot")
|
||||
.join("linux_boot")
|
||||
.join("setup");
|
||||
let target_json = setup_crate_dir.join("x86_64-i386_protected_mode.json");
|
||||
|
||||
println!(
|
||||
"cargo:rerun-if-changed={}",
|
||||
setup_crate_dir.to_str().unwrap()
|
||||
);
|
||||
|
||||
let cargo = std::env::var("CARGO").unwrap();
|
||||
let mut cmd = std::process::Command::new(cargo);
|
||||
cmd.arg("install").arg("aster-frame-x86-boot-linux-setup");
|
||||
cmd.arg("--debug");
|
||||
cmd.arg("--locked");
|
||||
cmd.arg("--path").arg(setup_crate_dir.to_str().unwrap());
|
||||
cmd.arg("--target").arg(target_json.as_os_str());
|
||||
cmd.arg("-Zbuild-std=core,compiler_builtins");
|
||||
cmd.arg("-Zbuild-std-features=compiler-builtins-mem");
|
||||
// Specify the installation root.
|
||||
cmd.arg("--root").arg(out_dir.as_os_str());
|
||||
// Specify the build target directory to avoid cargo running
|
||||
// into a deadlock reading the workspace files.
|
||||
cmd.arg("--target-dir").arg(out_dir.as_os_str());
|
||||
cmd.env_remove("RUSTFLAGS");
|
||||
cmd.env_remove("CARGO_ENCODED_RUSTFLAGS");
|
||||
let output = cmd.output()?;
|
||||
if !output.status.success() {
|
||||
std::io::stdout().write_all(&output.stdout).unwrap();
|
||||
std::io::stderr().write_all(&output.stderr).unwrap();
|
||||
return Err(format!(
|
||||
"Failed to build linux x86 setup header:\n\tcommand `{:?}`\n\treturned {}",
|
||||
cmd, output.status
|
||||
)
|
||||
.into());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
@ -4,12 +4,13 @@
|
||||
.section ".boot", "awx"
|
||||
.code32
|
||||
|
||||
// With the 32-bit entry types we should go through a common paging and machine
|
||||
// state setup routine. Thus we make a mark of protocol used in each entrypoint
|
||||
// With every entry types we could go through common paging or machine
|
||||
// state setup routines. Thus we make a mark of protocol used in each entrypoint
|
||||
// on the stack.
|
||||
ENTRYTYPE_MULTIBOOT = 1
|
||||
ENTRYTYPE_MULTIBOOT2 = 2
|
||||
ENTRYTYPE_LINUX_32 = 3
|
||||
ENTRYTYPE_LINUX_64 = 4
|
||||
|
||||
MULTIBOOT_ENTRY_MAGIC = 0x2BADB002
|
||||
MULTIBOOT2_ENTRY_MAGIC = 0x36D76289
|
||||
@ -39,14 +40,13 @@ __linux32_boot:
|
||||
.org 0x200
|
||||
.global __linux64_boot_tag
|
||||
__linux64_boot_tag:
|
||||
// We switch back to 32-bit mode to call the 32-bit entry point.
|
||||
lgdt [boot_gdtr]
|
||||
mov eax, 0xb002b002 // magic for boot_params
|
||||
mov ebx, esi // struct boot_params *
|
||||
sub rsp, 8
|
||||
mov dword ptr [rsp], offset __linux32_boot
|
||||
mov dword ptr [rsp + 4], 24
|
||||
retf
|
||||
// Set the kernel call stack.
|
||||
lea rsp, [boot_stack_top]
|
||||
push rsi // boot_params ptr from the loader
|
||||
push ENTRYTYPE_LINUX_64
|
||||
|
||||
// Here RSP/RIP are still using low address.
|
||||
jmp long_mode_in_low_address
|
||||
|
||||
// The multiboot & multiboot2 entry point.
|
||||
.code32
|
||||
@ -274,6 +274,7 @@ gdt_end:
|
||||
// The page tables and the stack
|
||||
.align 4096
|
||||
|
||||
.global boot_page_table_start
|
||||
boot_page_table_start:
|
||||
boot_pml4:
|
||||
.skip 4096
|
||||
@ -296,6 +297,7 @@ boot_pt_32g:
|
||||
.skip 4096 * 512
|
||||
boot_page_table_end:
|
||||
|
||||
.global boot_stack_top
|
||||
boot_stack_bottom:
|
||||
.skip 0x40000
|
||||
boot_stack_top:
|
||||
@ -335,21 +337,22 @@ long_mode:
|
||||
cmp rax, ENTRYTYPE_MULTIBOOT2
|
||||
je entry_type_multiboot2
|
||||
cmp rax, ENTRYTYPE_LINUX_32
|
||||
je entry_type_linux_32
|
||||
je entry_type_linux
|
||||
cmp rax, ENTRYTYPE_LINUX_64
|
||||
je entry_type_linux
|
||||
// Unreachable!
|
||||
jmp halt
|
||||
|
||||
.extern __linux64_boot
|
||||
.extern __linux_boot
|
||||
.extern __multiboot_entry
|
||||
.extern __multiboot2_entry
|
||||
|
||||
entry_type_linux_32:
|
||||
entry_type_linux:
|
||||
pop rdi // boot_params ptr
|
||||
|
||||
// Clear the frame pointer to stop backtracing here.
|
||||
xor rbp, rbp
|
||||
|
||||
lea rax, [rip + __linux64_boot] // jump into Rust code
|
||||
lea rax, [rip + __linux_boot] // jump into Rust code
|
||||
call rax
|
||||
jmp halt
|
||||
|
||||
@ -357,7 +360,6 @@ entry_type_multiboot:
|
||||
pop rsi // the address of multiboot info
|
||||
pop rdi // multiboot magic
|
||||
|
||||
// Clear the frame pointer to stop backtracing here.
|
||||
xor rbp, rbp
|
||||
|
||||
lea rax, [rip + __multiboot_entry] // jump into Rust code
|
||||
@ -368,7 +370,6 @@ entry_type_multiboot2:
|
||||
pop rsi // the address of multiboot info
|
||||
pop rdi // multiboot magic
|
||||
|
||||
// Clear the frame pointer to stop backtracing here.
|
||||
xor rbp, rbp
|
||||
|
||||
lea rax, [rip + __multiboot2_entry] // jump into Rust code
|
||||
|
@ -138,9 +138,9 @@ fn init_memory_regions(memory_regions: &'static Once<Vec<MemoryRegion>>) {
|
||||
memory_regions.call_once(|| non_overlapping_regions_from(regions.as_ref()));
|
||||
}
|
||||
|
||||
/// The entry point of Rust code called by the Linux 64-bit boot compatible bootloader.
|
||||
/// The entry point of of the Rust code portion of Asterinas.
|
||||
#[no_mangle]
|
||||
unsafe extern "sysv64" fn __linux64_boot(params_ptr: *const BootParams) -> ! {
|
||||
unsafe extern "sysv64" fn __linux_boot(params_ptr: *const BootParams) -> ! {
|
||||
let params = *params_ptr;
|
||||
assert_eq!({ params.hdr.header }, LINUX_BOOT_HEADER_MAGIC);
|
||||
BOOT_PARAMS.call_once(|| params);
|
||||
|
@ -5,9 +5,7 @@ use spin::Once;
|
||||
use crate::{
|
||||
boot::{
|
||||
kcmdline::KCmdlineArg,
|
||||
memory_region::{
|
||||
non_overlapping_regions_from, MemoryRegion, MemoryRegionType,
|
||||
},
|
||||
memory_region::{non_overlapping_regions_from, MemoryRegion, MemoryRegionType},
|
||||
BootloaderAcpiArg, BootloaderFramebufferArg,
|
||||
},
|
||||
config::PHYS_OFFSET,
|
||||
|
@ -6,9 +6,7 @@ use multiboot2::{BootInformation, BootInformationHeader, MemoryAreaType};
|
||||
|
||||
use crate::boot::{
|
||||
kcmdline::KCmdlineArg,
|
||||
memory_region::{
|
||||
non_overlapping_regions_from, MemoryRegion, MemoryRegionType,
|
||||
},
|
||||
memory_region::{non_overlapping_regions_from, MemoryRegion, MemoryRegionType},
|
||||
BootloaderAcpiArg, BootloaderFramebufferArg,
|
||||
};
|
||||
use spin::Once;
|
||||
|
Reference in New Issue
Block a user