aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/lguest/lg.h1
-rw-r--r--drivers/lguest/lguest_user.c37
-rw-r--r--drivers/lguest/x86/core.c36
3 files changed, 38 insertions, 36 deletions
diff --git a/drivers/lguest/lg.h b/drivers/lguest/lg.h
index 00c869bd9f79..c2557cfd86c7 100644
--- a/drivers/lguest/lg.h
+++ b/drivers/lguest/lg.h
@@ -199,6 +199,7 @@ void lguest_arch_run_guest(struct lguest *lg);
199void lguest_arch_handle_trap(struct lguest *lg); 199void lguest_arch_handle_trap(struct lguest *lg);
200int lguest_arch_init_hypercalls(struct lguest *lg); 200int lguest_arch_init_hypercalls(struct lguest *lg);
201int lguest_arch_do_hcall(struct lguest *lg, struct hcall_args *args); 201int lguest_arch_do_hcall(struct lguest *lg, struct hcall_args *args);
202void lguest_arch_setup_regs(struct lguest *lg, unsigned long start);
202 203
203/* <arch>/switcher.S: */ 204/* <arch>/switcher.S: */
204extern char start_switcher_text[], end_switcher_text[], switch_to_guest[]; 205extern char start_switcher_text[], end_switcher_text[], switch_to_guest[];
diff --git a/drivers/lguest/lguest_user.c b/drivers/lguest/lguest_user.c
index d4ac5f846427..b184652e45d7 100644
--- a/drivers/lguest/lguest_user.c
+++ b/drivers/lguest/lguest_user.c
@@ -9,37 +9,6 @@
9#include <linux/fs.h> 9#include <linux/fs.h>
10#include "lg.h" 10#include "lg.h"
11 11
12/*L:030 setup_regs() doesn't really belong in this file, but it gives us an
13 * early glimpse deeper into the Host so it's worth having here.
14 *
15 * Most of the Guest's registers are left alone: we used get_zeroed_page() to
16 * allocate the structure, so they will be 0. */
17static void setup_regs(struct lguest_regs *regs, unsigned long start)
18{
19 /* There are four "segment" registers which the Guest needs to boot:
20 * The "code segment" register (cs) refers to the kernel code segment
21 * __KERNEL_CS, and the "data", "extra" and "stack" segment registers
22 * refer to the kernel data segment __KERNEL_DS.
23 *
24 * The privilege level is packed into the lower bits. The Guest runs
25 * at privilege level 1 (GUEST_PL).*/
26 regs->ds = regs->es = regs->ss = __KERNEL_DS|GUEST_PL;
27 regs->cs = __KERNEL_CS|GUEST_PL;
28
29 /* The "eflags" register contains miscellaneous flags. Bit 1 (0x002)
30 * is supposed to always be "1". Bit 9 (0x200) controls whether
31 * interrupts are enabled. We always leave interrupts enabled while
32 * running the Guest. */
33 regs->eflags = 0x202;
34
35 /* The "Extended Instruction Pointer" register says where the Guest is
36 * running. */
37 regs->eip = start;
38
39 /* %esi points to our boot information, at physical address 0, so don't
40 * touch it. */
41}
42
43/*L:310 To send DMA into the Guest, the Launcher needs to be able to ask for a 12/*L:310 To send DMA into the Guest, the Launcher needs to be able to ask for a
44 * DMA buffer. This is done by writing LHREQ_GETDMA and the key to 13 * DMA buffer. This is done by writing LHREQ_GETDMA and the key to
45 * /dev/lguest. */ 14 * /dev/lguest. */
@@ -214,11 +183,7 @@ static int initialize(struct file *file, const unsigned long __user *input)
214 183
215 /* Now we initialize the Guest's registers, handing it the start 184 /* Now we initialize the Guest's registers, handing it the start
216 * address. */ 185 * address. */
217 setup_regs(lg->regs, args[3]); 186 lguest_arch_setup_regs(lg, args[3]);
218
219 /* There are a couple of GDT entries the Guest expects when first
220 * booting. */
221 setup_guest_gdt(lg);
222 187
223 /* The timer for lguest's clock needs initialization. */ 188 /* The timer for lguest's clock needs initialization. */
224 init_clockdev(lg); 189 init_clockdev(lg);
diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
index 2ef64a2734d3..84c09082f27f 100644
--- a/drivers/lguest/x86/core.c
+++ b/drivers/lguest/x86/core.c
@@ -535,3 +535,39 @@ int lguest_arch_init_hypercalls(struct lguest *lg)
535/* Now we've examined the hypercall code; our Guest can make requests. There 535/* Now we've examined the hypercall code; our Guest can make requests. There
536 * is one other way we can do things for the Guest, as we see in 536 * is one other way we can do things for the Guest, as we see in
537 * emulate_insn(). :*/ 537 * emulate_insn(). :*/
538
539/*L:030 lguest_arch_setup_regs()
540 *
541 * Most of the Guest's registers are left alone: we used get_zeroed_page() to
542 * allocate the structure, so they will be 0. */
543void lguest_arch_setup_regs(struct lguest *lg, unsigned long start)
544{
545 struct lguest_regs *regs = lg->regs;
546
547 /* There are four "segment" registers which the Guest needs to boot:
548 * The "code segment" register (cs) refers to the kernel code segment
549 * __KERNEL_CS, and the "data", "extra" and "stack" segment registers
550 * refer to the kernel data segment __KERNEL_DS.
551 *
552 * The privilege level is packed into the lower bits. The Guest runs
553 * at privilege level 1 (GUEST_PL).*/
554 regs->ds = regs->es = regs->ss = __KERNEL_DS|GUEST_PL;
555 regs->cs = __KERNEL_CS|GUEST_PL;
556
557 /* The "eflags" register contains miscellaneous flags. Bit 1 (0x002)
558 * is supposed to always be "1". Bit 9 (0x200) controls whether
559 * interrupts are enabled. We always leave interrupts enabled while
560 * running the Guest. */
561 regs->eflags = 0x202;
562
563 /* The "Extended Instruction Pointer" register says where the Guest is
564 * running. */
565 regs->eip = start;
566
567 /* %esi points to our boot information, at physical address 0, so don't
568 * touch it. */
569 /* There are a couple of GDT entries the Guest expects when first
570 * booting. */
571
572 setup_guest_gdt(lg);
573}