blob: b1d26c9bac084de2e73013f7ce49ef2387c5101e [file] [log] [blame]
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +01001#include "vm.h"
2
3#include "cpu.h"
4
Wedson Almeida Filho84a30a02018-07-23 20:05:05 +01005bool vm_init(struct vm *vm, uint32_t id, uint32_t vcpu_count)
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +01006{
Wedson Almeida Filho87009642018-07-02 10:20:07 +01007 uint32_t i;
8
9 vm->vcpu_count = vcpu_count;
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010010
11 /* Do basic initialization of vcpus. */
Andrew Scull7364a8e2018-07-19 15:39:29 +010012 for (i = 0; i < vcpu_count; i++) {
Wedson Almeida Filho87009642018-07-02 10:20:07 +010013 vcpu_init(vm->vcpus + i, vm);
Andrew Scull7364a8e2018-07-19 15:39:29 +010014 }
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010015
Wedson Almeida Filho84a30a02018-07-23 20:05:05 +010016 return mm_ptable_init(&vm->ptable, id, 0);
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010017}
18
19/* TODO: Shall we use index or id here? */
Wedson Almeida Filho87009642018-07-02 10:20:07 +010020void vm_start_vcpu(struct vm *vm, size_t index, size_t entry, size_t arg,
21 bool is_primary)
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010022{
23 struct vcpu *vcpu = vm->vcpus + index;
Wedson Almeida Filho87009642018-07-02 10:20:07 +010024 if (index < vm->vcpu_count) {
25 arch_regs_init(&vcpu->regs, entry, arg, is_primary);
26 vcpu_on(vcpu);
27 }
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010028}
Wedson Almeida Filho84a30a02018-07-23 20:05:05 +010029
30void vm_set_current(struct vm *vm)
31{
32 arch_mm_set_vm(vm->ptable.id, (paddr_t)vm->ptable.table);
33}