Esempio n. 1
0
File: vcpu.c Progetto: HideSand/ksm
void vcpu_init(uintptr_t sp, uintptr_t ip, struct ksm *k)
{
	struct vcpu *vcpu = ExAllocatePool(NonPagedPoolNx, sizeof(*vcpu));
	if (!vcpu)
		return;

	RtlZeroMemory(vcpu, sizeof(*vcpu));
	if (!ept_init(&vcpu->ept))
		return ExFreePool(vcpu);

	PHYSICAL_ADDRESS highest;
	highest.QuadPart = -1;

	vcpu->stack = MmAllocateContiguousMemory(KERNEL_STACK_SIZE, highest);
	if (!vcpu->stack)
		goto out;
	RtlZeroMemory(vcpu->stack, KERNEL_STACK_SIZE);

	vcpu->vmcs = ExAllocatePool(NonPagedPoolNx, PAGE_SIZE);
	if (!vcpu->vmcs)
		goto out;
	RtlZeroMemory(vcpu->vmcs, PAGE_SIZE);

	vcpu->vmxon = ExAllocatePool(NonPagedPoolNx, PAGE_SIZE);
	if (!vcpu->vmxon)
		goto out;
	RtlZeroMemory(vcpu->vmxon, PAGE_SIZE);

	vcpu->ve = ExAllocatePool(NonPagedPoolNx, PAGE_SIZE);
	if (!vcpu->ve)
		goto out;
	RtlZeroMemory(vcpu->ve, PAGE_SIZE);

	vcpu->idt.limit = PAGE_SIZE - 1;
	vcpu->idt.base = (uintptr_t)ExAllocatePool(NonPagedPoolNx, PAGE_SIZE);
	if (!vcpu->idt.base)
		goto out;

	for (int i = 0; i < 0x100; ++i)
		vcpu->shadow_idt[i] = (struct kidt_entry64) { .e32 = (kidt_entry_t) { .p = 0 } };

	vcpu->nr = cpu_nr();
	k->vcpu_list[cpu_nr()] = vcpu;

	if (!enter_vmx(vcpu->vmxon))
		goto out;

	if (!init_vmcs(vcpu->vmcs))
		goto out_off;

	if (setup_vmcs(vcpu, sp, ip, (uintptr_t)vcpu->stack + KERNEL_STACK_SIZE))
		vcpu_launch();

out_off:
	__vmx_off();
out:
	vcpu_free(vcpu);
}
Esempio n. 2
0
STATIC_INLINE_EMUL_GENERIC void
emul_syscall_enter(emul_syscall *emul,
		   int call,
		   int arg0,
		   cpu *processor,
		   unsigned_word cia)
{
  printf_filtered("%d:0x%lx:%s(",
		  cpu_nr(processor) + 1,
		  (long)cia,
		  emul->syscall_descriptor[call].name);
}
Esempio n. 3
0
File: hw_pal.c Progetto: 5kg/gdb
static unsigned
hw_pal_io_read_buffer_callback(device *me,
			       void *dest,
			       int space,
			       unsigned_word addr,
			       unsigned nr_bytes,
			       cpu *processor,
			       unsigned_word cia)
{
  hw_pal_device *hw_pal = (hw_pal_device*)device_data(me);
  unsigned_1 val;
  switch (addr & hw_pal_address_mask) {
  case hw_pal_cpu_nr_register:
    val = cpu_nr(processor);
    DTRACE(pal, ("read - cpu-nr %d\n", val));
    break;
  case hw_pal_nr_cpu_register:
    val = tree_find_integer_property(me, "/openprom/options/smp");
    DTRACE(pal, ("read - nr-cpu %d\n", val));
    break;
  case hw_pal_read_fifo:
    val = hw_pal->input.buffer;
    DTRACE(pal, ("read - input-fifo %d\n", val));
    break;
  case hw_pal_read_status:
    scan_hw_pal(hw_pal);
    val = hw_pal->input.status;
    DTRACE(pal, ("read - input-status %d\n", val));
    break;
  case hw_pal_write_fifo:
    val = hw_pal->output.buffer;
    DTRACE(pal, ("read - output-fifo %d\n", val));
    break;
  case hw_pal_write_status:
    val = hw_pal->output.status;
    DTRACE(pal, ("read - output-status %d\n", val));
    break;
  default:
    val = 0;
    DTRACE(pal, ("read - ???\n"));
  }
  memset(dest, 0, nr_bytes);
  *(unsigned_1*)dest = val;
  return nr_bytes;
}