2 * Copyright (c) 2012 NetApp, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
33 #include <sys/types.h>
35 #include <machine/vmm.h>
43 #include "spinup_ap.h"
46 spinup_ap_realmode(struct vmctx *ctx, int newcpu, uint64_t *rip)
51 uint32_t desc_limit, desc_access;
53 vector = *rip >> PAGE_SHIFT;
57 * Update the %cs and %rip of the guest so that it starts
58 * executing real mode code at at 'vector << 12'.
60 error = vm_set_register(ctx, newcpu, VM_REG_GUEST_RIP, *rip);
63 error = vm_get_desc(ctx, newcpu, VM_REG_GUEST_CS, &desc_base,
64 &desc_limit, &desc_access);
67 desc_base = vector << PAGE_SHIFT;
68 error = vm_set_desc(ctx, newcpu, VM_REG_GUEST_CS,
69 desc_base, desc_limit, desc_access);
72 cs = (vector << PAGE_SHIFT) >> 4;
73 error = vm_set_register(ctx, newcpu, VM_REG_GUEST_CS, cs);
78 spinup_ap(struct vmctx *ctx, int vcpu, int newcpu, uint64_t rip)
83 assert(newcpu < guest_ncpus);
85 error = vcpu_reset(ctx, newcpu);
88 fbsdrun_set_capabilities(ctx, newcpu);
91 * Enable the 'unrestricted guest' mode for 'newcpu'.
93 * Set up the processor state in power-on 16-bit mode, with the CS:IP
94 * init'd to the specified low-mem 4K page.
96 error = vm_set_capability(ctx, newcpu, VM_CAP_UNRESTRICTED_GUEST, 1);
99 spinup_ap_realmode(ctx, newcpu, &rip);
101 fbsdrun_addcpu(ctx, newcpu, rip);