Skip to content

Commit

Permalink
Call one_time_init directly in hypervisor_entry, so remove INITED.
Browse files Browse the repository at this point in the history
  • Loading branch information
efenniht committed Sep 9, 2019
1 parent 5f7a90b commit 1f8d79a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 15 deletions.
5 changes: 5 additions & 0 deletions hfo2/src/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,11 @@ impl CpuManager {

None
}

/// Temporal impl (WIP)
pub fn boot_cpu(&self) -> *mut Cpu {
self.cpus.get(0).unwrap() as &Cpu as *const _ as usize as *mut _
}
}

pub fn cpu_module_init(cpu_ids: &[cpu_id_t]) -> CpuManager {
Expand Down
21 changes: 7 additions & 14 deletions hfo2/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ extern "C" {
static mut PTABLE_BUF: MaybeUninit<[RawPage; HEAP_PAGES]> = MaybeUninit::uninit();

/// Performs one-time initialisation of the hypervisor.
unsafe fn one_time_init() {
#[no_mangle]
unsafe extern "C" fn one_time_init() -> *mut Cpu {
// Make sure the console is initialised before calling dlog.
plat_console_init();

Expand All @@ -64,8 +65,8 @@ unsafe fn one_time_init() {
let params = boot_params_get(&mut hypervisor_ptable, &mut ppool)
.expect("unable to retrieve boot params");

let cpu_manager = cpu_module_init(&params.cpu_ids[..params.cpu_count]);
cpu_manager_init(cpu_manager);
let cpum = cpu_module_init(&params.cpu_ids[..params.cpu_count]);
cpu_manager_init(cpum);

for i in 0..params.mem_ranges_count {
dlog!(
Expand Down Expand Up @@ -134,22 +135,14 @@ unsafe fn one_time_init() {
mm_vm_enable_invalidation();

dlog!("Hafnium initialisation completed\n");
}

static mut INITED: bool = false;
cpu_manager().boot_cpu()
}

// The entry point of CPUs when they are turned on. It is supposed to initialise
// all state and return the first vCPU to run.
#[no_mangle]
pub unsafe extern "C" fn cpu_main(mut c: *const Cpu) -> *mut VCpu {
// Do global one-time initialisation just once. We avoid using atomics by
// only touching the variable from cpu 0.
if !INITED {
INITED = true;
one_time_init();
c = cpu_manager().lookup((*c).id).unwrap();
}

pub unsafe extern "C" fn cpu_main(c: *const Cpu) -> *mut VCpu {
if !mm_cpu_init() {
panic!("mm_cpu_init failed");
}
Expand Down
33 changes: 32 additions & 1 deletion src/arch/aarch64/hypervisor/hypervisor_entry.S
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,35 @@ image_entry:
orr x30, x29, x30
str x30, [x0, CPU_ID]

b cpu_entry
/**
* Basically do the same thing on cpu_entry, but call one_time_init
* before cpu_main.
*/

/* Disable interrupts. */
msr DAIFSet, #0xf

/* Use SPx (instead of SP0). */
msr spsel, #1

/* Prepare the stack. */
ldr x30, [x0, #CPU_STACK_BOTTOM]
mov sp, x30

/* Configure exception handlers. */
adrp x30, vector_table_el2
add x30, x30, :lo12:vector_table_el2
msr vbar_el2, x30

/* Initialize the hypervisor. It returns a correct pointer to boot cpu. */
bl one_time_init

/* Call into C code, x0 holds the cpu pointer. */
bl cpu_main

/* Run the vcpu returned by cpu_main. */
bl vcpu_restore_all_and_run

/* Loop forever waiting for interrupts. */
0: wfi
b 0b

0 comments on commit 1f8d79a

Please sign in to comment.