ia64/xen-unstable

changeset 4119:ef90e028e868

bitkeeper revision 1.1236.25.13 (423386505SwGplSmaVcNHcvNqtQ2QA)

Automerge
author cl349@firebug.cl.cam.ac.uk
date Sun Mar 13 00:16:16 2005 +0000 (2005-03-13)
parents c0c50017de07 5a68bda6018b
children 3236c27b9832
files .rootkeys BitKeeper/etc/logging_ok tools/libxc/Makefile tools/libxc/xc_linux_build.c tools/libxc/xc_linux_restore.c tools/libxc/xc_plan9_build.c tools/libxc/xc_ptrace.c tools/libxc/xc_vmx_build.c xen/Rules.mk xen/arch/ia64/domain.c xen/arch/x86/domain.c xen/arch/x86/traps.c xen/common/dom0_ops.c xen/common/domain.c xen/include/public/dom0_ops.h xen/include/xen/domain.h xen/include/xen/sched.h
line diff
     1.1 --- a/.rootkeys	Sat Mar 12 21:38:47 2005 +0000
     1.2 +++ b/.rootkeys	Sun Mar 13 00:16:16 2005 +0000
     1.3 @@ -572,6 +572,7 @@ 4051bce6CHAsYh8P5t2OHDtRWOP9og tools/lib
     1.4  41cc934aO1m6NxEh_8eDr9bJIMoLFA tools/libxc/xc_plan9_build.c
     1.5  3fbba6dctWRWlFJkYb6hdix2X4WMuw tools/libxc/xc_private.c
     1.6  3fbba6dcbVrG2hPzEzwdeV_UC8kydQ tools/libxc/xc_private.h
     1.7 +42337174PxyzzPk62raDiYCIsfStDg tools/libxc/xc_ptrace.c
     1.8  40589968UQFnJeOMn8UIFLbXBuwXjw tools/libxc/xc_rrobin.c
     1.9  41dde8b0pLfAKMs_L9Uri2hnzHiCRQ tools/libxc/xc_vmx_build.c
    1.10  40e1b09dMYB4ItGCqcMIzirdMd9I-w tools/libxutil/Makefile
     2.1 --- a/BitKeeper/etc/logging_ok	Sat Mar 12 21:38:47 2005 +0000
     2.2 +++ b/BitKeeper/etc/logging_ok	Sun Mar 13 00:16:16 2005 +0000
     2.3 @@ -46,6 +46,7 @@ kaf24@plym.cl.cam.ac.uk
     2.4  kaf24@scramble.cl.cam.ac.uk
     2.5  kaf24@striker.cl.cam.ac.uk
     2.6  kaf24@viper.(none)
     2.7 +kmacy@shemp.lab.netapp.com
     2.8  laudney@eclipse.(none)
     2.9  lynx@idefix.cl.cam.ac.uk
    2.10  maf46@burn.cl.cam.ac.uk
     3.1 --- a/tools/libxc/Makefile	Sat Mar 12 21:38:47 2005 +0000
     3.2 +++ b/tools/libxc/Makefile	Sun Mar 13 00:16:16 2005 +0000
     3.3 @@ -29,6 +29,7 @@ SRCS     += xc_linux_save.c
     3.4  SRCS     += xc_misc.c
     3.5  SRCS     += xc_physdev.c
     3.6  SRCS     += xc_private.c
     3.7 +SRCS     += xc_ptrace.c
     3.8  SRCS     += xc_rrobin.c
     3.9  SRCS     += xc_vmx_build.c
    3.10  
     4.1 --- a/tools/libxc/xc_linux_build.c	Sat Mar 12 21:38:47 2005 +0000
     4.2 +++ b/tools/libxc/xc_linux_build.c	Sun Mar 13 00:16:16 2005 +0000
     4.3 @@ -459,10 +459,11 @@ int xc_linux_build(int xc_handle,
     4.4  
     4.5      memset( &launch_op, 0, sizeof(launch_op) );
     4.6  
     4.7 -    launch_op.u.builddomain.domain   = (domid_t)domid;
     4.8 -    launch_op.u.builddomain.ctxt = ctxt;
     4.9 +    launch_op.u.setdomaininfo.domain   = (domid_t)domid;
    4.10 +    launch_op.u.setdomaininfo.exec_domain = 0;
    4.11 +    launch_op.u.setdomaininfo.ctxt = ctxt;
    4.12  
    4.13 -    launch_op.cmd = DOM0_BUILDDOMAIN;
    4.14 +    launch_op.cmd = DOM0_SETDOMAININFO;
    4.15      rc = do_dom0_op(xc_handle, &launch_op);
    4.16      
    4.17      return rc;
     5.1 --- a/tools/libxc/xc_linux_restore.c	Sat Mar 12 21:38:47 2005 +0000
     5.2 +++ b/tools/libxc/xc_linux_restore.c	Sun Mar 13 00:16:16 2005 +0000
     5.3 @@ -638,9 +638,10 @@ int xc_linux_restore(int xc_handle, XcIO
     5.4  
     5.5      xcio_info(ioctxt, "Domain ready to be built.\n");
     5.6  
     5.7 -    op.cmd = DOM0_BUILDDOMAIN;
     5.8 -    op.u.builddomain.domain   = (domid_t)dom;
     5.9 -    op.u.builddomain.ctxt = &ctxt;
    5.10 +    op.cmd = DOM0_SETDOMAININFO;
    5.11 +    op.u.setdomaininfo.domain   = (domid_t)dom;
    5.12 +    op.u.setdomaininfo.exec_domain   = 0;
    5.13 +    op.u.setdomaininfo.ctxt = &ctxt;
    5.14      rc = do_dom0_op(xc_handle, &op);
    5.15  
    5.16      if ( rc != 0 )
     6.1 --- a/tools/libxc/xc_plan9_build.c	Sat Mar 12 21:38:47 2005 +0000
     6.2 +++ b/tools/libxc/xc_plan9_build.c	Sun Mar 13 00:16:16 2005 +0000
     6.3 @@ -533,10 +533,11 @@ xc_plan9_build(int xc_handle,
     6.4  
     6.5  	memset(&launch_op, 0, sizeof (launch_op));
     6.6  
     6.7 -	launch_op.u.builddomain.domain = (domid_t) domid;
     6.8 -	//  launch_op.u.builddomain.num_vifs = 1;
     6.9 -	launch_op.u.builddomain.ctxt = ctxt;
    6.10 -	launch_op.cmd = DOM0_BUILDDOMAIN;
    6.11 +	launch_op.u.setdomaininfo.domain = (domid_t) domid;
    6.12 +	launch_op.u.setdomaininfo.exec_domain = 0;
    6.13 +	//  launch_op.u.setdomaininfo.num_vifs = 1;
    6.14 +	launch_op.u.setdomaininfo.ctxt = ctxt;
    6.15 +	launch_op.cmd = DOM0_SETDOMAININFO;
    6.16  	rc = do_dom0_op(xc_handle, &launch_op);
    6.17  
    6.18  	fprintf(stderr, "RC is %d\n", rc);
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/tools/libxc/xc_ptrace.c	Sun Mar 13 00:16:16 2005 +0000
     7.3 @@ -0,0 +1,341 @@
     7.4 +#include <sys/ptrace.h>
     7.5 +#include <sys/wait.h>
     7.6 +#include "xc_private.h"
     7.7 +#include <asm/elf.h>
     7.8 +#include <time.h>
     7.9 +
    7.10 +
    7.11 +#define BSD_PAGE_MASK	(PAGE_SIZE-1)
    7.12 +#define	PG_FRAME	(~((unsigned long)BSD_PAGE_MASK)
    7.13 +#define PDRSHIFT        22
    7.14 +#define	PSL_T		0x00000100	/* trace enable bit */
    7.15 +
    7.16 +
    7.17 +/*
    7.18 + * long  
    7.19 + * ptrace(enum __ptrace_request request, pid_t pid, void *addr, void *data);
    7.20 + */
    7.21 +
    7.22 +long xc_ptrace(enum __ptrace_request request, 
    7.23 +	       pid_t pid, void *addr, void *data);
    7.24 +int waitdomain(int domain, int *status, int options);
    7.25 +
    7.26 +char * ptrace_names[] = {
    7.27 +    "PTRACE_TRACEME",
    7.28 +    "PTRACE_PEEKTEXT",
    7.29 +    "PTRACE_PEEKDATA",
    7.30 +    "PTRACE_PEEKUSER",
    7.31 +    "PTRACE_POKETEXT",
    7.32 +    "PTRACE_POKEDATA",
    7.33 +    "PTRACE_POKEUSER",
    7.34 +    "PTRACE_CONT",
    7.35 +    "PTRACE_KILL",
    7.36 +    "PTRACE_SINGLESTEP",
    7.37 +    "PTRACE_INVALID",
    7.38 +    "PTRACE_INVALID",
    7.39 +    "PTRACE_GETREGS",
    7.40 +    "PTRACE_SETREGS",
    7.41 +    "PTRACE_GETFPREGS",
    7.42 +    "PTRACE_SETFPREGS",
    7.43 +    "PTRACE_ATTACH",
    7.44 +    "PTRACE_DETACH",
    7.45 +    "PTRACE_GETFPXREGS",
    7.46 +    "PTRACE_SETFPXREGS",
    7.47 +    "PTRACE_INVALID",
    7.48 +    "PTRACE_INVALID",
    7.49 +    "PTRACE_INVALID",
    7.50 +    "PTRACE_INVALID",
    7.51 +    "PTRACE_SYSCALL",
    7.52 +};
    7.53 +
    7.54 +struct gdb_regs {
    7.55 +        long ebx; /* 0 */
    7.56 +        long ecx; /* 4 */
    7.57 +        long edx; /* 8 */
    7.58 +        long esi; /* 12 */
    7.59 +        long edi; /* 16 */
    7.60 +        long ebp; /* 20 */
    7.61 +        long eax; /* 24 */ 
    7.62 +        int  xds; /* 28 */
    7.63 +        int  xes; /* 32 */
    7.64 +	int  xfs; /* 36 */
    7.65 +	int  xgs; /* 40 */
    7.66 +	long orig_eax; /* 44 */
    7.67 +        long eip;    /* 48 */
    7.68 +        int  xcs;    /* 52 */
    7.69 +        long eflags; /* 56 */
    7.70 +        long esp;    /* 60 */     
    7.71 +	int  xss;    /* 64 */
    7.72 +};
    7.73 +#define printval(x) printf("%s = %lx\n", #x, (long)x);
    7.74 +#define SET_PT_REGS(pt, xc) \
    7.75 +{ \
    7.76 +pt.ebx = xc.ebx; \
    7.77 +pt.ecx = xc.ecx; \
    7.78 +pt.edx = xc.edx; \
    7.79 +pt.esi = xc.esi; \
    7.80 +pt.edi = xc.edi; \
    7.81 +pt.ebp = xc.ebp; \
    7.82 +pt.eax = xc.eax; \
    7.83 +pt.eip = xc.eip; \
    7.84 +pt.xcs = xc.cs; \
    7.85 +pt.eflags = xc.eflags; \
    7.86 +pt.esp = xc.esp; \
    7.87 +pt.xss = xc.ss; \
    7.88 +pt.xes = xc.es; \
    7.89 +pt.xds = xc.ds; \
    7.90 +pt.xfs = xc.fs; \
    7.91 +pt.xgs = xc.gs; \
    7.92 +}
    7.93 +
    7.94 +#define SET_XC_REGS(pt, xc) \
    7.95 +{ \
    7.96 +xc.ebx = pt->ebx; \
    7.97 +xc.ecx = pt->ecx; \
    7.98 +xc.edx = pt->edx; \
    7.99 +xc.esi = pt->esi; \
   7.100 +xc.edi = pt->edi; \
   7.101 +xc.ebp = pt->ebp; \
   7.102 +xc.eax = pt->eax; \
   7.103 +xc.eip = pt->eip; \
   7.104 +xc.cs = pt->xcs; \
   7.105 +xc.eflags = pt->eflags; \
   7.106 +xc.esp = pt->esp; \
   7.107 +xc.ss = pt->xss; \
   7.108 +xc.es = pt->xes; \
   7.109 +xc.ds = pt->xds; \
   7.110 +xc.fs = pt->xfs; \
   7.111 +xc.gs = pt->xgs; \
   7.112 +}
   7.113 +
   7.114 +
   7.115 +#define vtopdi(va) ((va) >> PDRSHIFT)
   7.116 +#define vtopti(va) (((va) >> PAGE_SHIFT) & BSD_PAGE_MASK)
   7.117 +
   7.118 +/* XXX application state */
   7.119 +
   7.120 +
   7.121 +static int xc_handle;
   7.122 +static int regs_valid;
   7.123 +static unsigned long cr3;
   7.124 +static full_execution_context_t ctxt;
   7.125 +
   7.126 +/* --------------------- */
   7.127 +
   7.128 +static void *
   7.129 +map_domain_va(unsigned long domid, void * guest_va)
   7.130 +{
   7.131 +    unsigned long pde, page;
   7.132 +    unsigned long va = (unsigned long)guest_va;
   7.133 +
   7.134 +    static unsigned long cr3_phys;
   7.135 +    static unsigned long *cr3_virt;
   7.136 +    static unsigned long pde_phys;
   7.137 +    static unsigned long *pde_virt;
   7.138 +    static unsigned long page_phys;
   7.139 +    static unsigned long *page_virt;
   7.140 +
   7.141 +    if (cr3 != cr3_phys) 
   7.142 +    {
   7.143 +	cr3_phys = cr3;
   7.144 +	if (cr3_virt)
   7.145 +	    munmap(cr3_virt, PAGE_SIZE);
   7.146 +	if ((cr3_virt = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
   7.147 +					     PROT_READ,
   7.148 +					     cr3_phys >> PAGE_SHIFT)) == NULL)
   7.149 +	    goto error_out;
   7.150 +    } 
   7.151 +    pde = cr3_virt[vtopdi(va)];
   7.152 +    if (pde != pde_phys) 
   7.153 +    {
   7.154 +	pde_phys = pde;
   7.155 +	if (pde_virt)
   7.156 +	    munmap(pde_virt, PAGE_SIZE);
   7.157 +	if ((pde_virt = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
   7.158 +					     PROT_READ,
   7.159 +					     pde_phys >> PAGE_SHIFT)) == NULL)
   7.160 +	    goto error_out;
   7.161 +    }
   7.162 +    page = pde_virt[vtopti(va)];
   7.163 +    if (page != page_phys) 
   7.164 +    {
   7.165 +	page_phys = page;
   7.166 +	if (page_virt)
   7.167 +	    munmap(page_virt, PAGE_SIZE);
   7.168 +	if ((page_virt = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
   7.169 +					     PROT_READ|PROT_WRITE,
   7.170 +					     page_phys >> PAGE_SHIFT)) == NULL)
   7.171 +	    goto error_out;
   7.172 +    }	
   7.173 +    return (void *)(((unsigned long)page_virt) | (va & BSD_PAGE_MASK));
   7.174 +
   7.175 + error_out:
   7.176 +    return 0;
   7.177 +}
   7.178 +
   7.179 +int 
   7.180 +waitdomain(int domain, int *status, int options)
   7.181 +{
   7.182 +    dom0_op_t op;
   7.183 +    int retval;
   7.184 +    full_execution_context_t ctxt;
   7.185 +    struct timespec ts;
   7.186 +    ts.tv_sec = 0;
   7.187 +    ts.tv_nsec = 10*1000*1000;
   7.188 +
   7.189 +    if (!xc_handle)
   7.190 +	if ((xc_handle = xc_interface_open()) < 0) 
   7.191 +	{
   7.192 +	    printf("xc_interface_open failed\n");
   7.193 +	    return -1;
   7.194 +	}
   7.195 +    op.cmd = DOM0_GETDOMAININFO;
   7.196 +    op.u.getdomaininfo.domain = domain;
   7.197 +    op.u.getdomaininfo.exec_domain = 0;
   7.198 +    op.u.getdomaininfo.ctxt = &ctxt;
   7.199 + retry:
   7.200 +
   7.201 +    retval = do_dom0_op(xc_handle, &op);
   7.202 +    if (retval) {
   7.203 +	printf("getdomaininfo failed\n");
   7.204 +	goto done;
   7.205 +    }
   7.206 +    *status = op.u.getdomaininfo.flags;
   7.207 +    
   7.208 +    if (options & WNOHANG)
   7.209 +	goto done;
   7.210 +	
   7.211 +
   7.212 +    if (!(op.u.getdomaininfo.flags & DOMFLAGS_PAUSED)) {	
   7.213 +	nanosleep(&ts,NULL);
   7.214 +	goto retry;
   7.215 +    }
   7.216 + done:
   7.217 +    return retval;
   7.218 +
   7.219 +}
   7.220 +
   7.221 +long
   7.222 +xc_ptrace(enum __ptrace_request request, pid_t pid, void *addr, void *data)
   7.223 +{
   7.224 +    dom0_op_t op;
   7.225 +    int status = 0;
   7.226 +    xc_domaininfo_t info;
   7.227 +    struct gdb_regs pt;
   7.228 +    long retval = 0;
   7.229 +    long *guest_va;
   7.230 +
   7.231 +    op.interface_version = DOM0_INTERFACE_VERSION;
   7.232 +    
   7.233 +    if (!xc_handle)
   7.234 +	if ((xc_handle = xc_interface_open()) < 0)
   7.235 +	    return -1;
   7.236 +#if 0
   7.237 +    printf("%20s %d, %p, %p \n", ptrace_names[request], pid, addr, data);
   7.238 +#endif
   7.239 +    switch (request) {	
   7.240 +    case PTRACE_PEEKTEXT:
   7.241 +    case PTRACE_PEEKDATA:
   7.242 +    case PTRACE_POKETEXT:
   7.243 +    case PTRACE_POKEDATA:
   7.244 +	if ((guest_va = (unsigned long *)map_domain_va(pid, addr)) == NULL)
   7.245 +	    goto done;
   7.246 +
   7.247 +	if (request == PTRACE_PEEKTEXT || request == PTRACE_PEEKDATA)
   7.248 +	    retval = *guest_va;
   7.249 +	else
   7.250 +	    *guest_va = (unsigned long)data;
   7.251 +	break;
   7.252 +    case PTRACE_GETREGS:
   7.253 +    case PTRACE_GETFPREGS:
   7.254 +    case PTRACE_GETFPXREGS:
   7.255 +	/* XXX hard-coding UP */
   7.256 +	retval = xc_domain_getfullinfo(xc_handle, pid, 0, &info, &ctxt);
   7.257 +
   7.258 +	if (retval) {
   7.259 +	    printf("getfullinfo failed\n");
   7.260 +	    goto done;
   7.261 +	}
   7.262 +	if (request == PTRACE_GETREGS) {
   7.263 +		SET_PT_REGS(pt, ctxt.cpu_ctxt); 
   7.264 +		memcpy(data, &pt, sizeof(elf_gregset_t));
   7.265 +	} else if (request == PTRACE_GETFPREGS)
   7.266 +	    memcpy(data, &ctxt.fpu_ctxt, sizeof(elf_fpregset_t));
   7.267 +	else /*if (request == PTRACE_GETFPXREGS)*/
   7.268 +	    memcpy(data, &ctxt.fpu_ctxt, sizeof(elf_fpxregset_t));
   7.269 +	cr3 = ctxt.pt_base;
   7.270 +	regs_valid = 1;
   7.271 +	break;
   7.272 +    case PTRACE_SETREGS:
   7.273 +	op.cmd = DOM0_SETDOMAININFO;
   7.274 +	SET_XC_REGS(((struct gdb_regs *)data), ctxt.cpu_ctxt);
   7.275 +	op.u.setdomaininfo.domain = pid;
   7.276 +	/* XXX need to understand multiple exec_domains */
   7.277 +	op.u.setdomaininfo.exec_domain = 0;
   7.278 +	op.u.setdomaininfo.ctxt = &ctxt;
   7.279 +	retval = do_dom0_op(xc_handle, &op);
   7.280 +	if (retval)
   7.281 +	    goto done;
   7.282 +
   7.283 +	break;
   7.284 +    case PTRACE_ATTACH:
   7.285 +	op.cmd = DOM0_GETDOMAININFO;
   7.286 +	op.u.getdomaininfo.domain = pid;
   7.287 +	op.u.getdomaininfo.exec_domain = 0;
   7.288 +	op.u.getdomaininfo.ctxt = &ctxt;
   7.289 +	retval = do_dom0_op(xc_handle, &op);
   7.290 +	if (retval) {
   7.291 +	    perror("dom0 op failed");
   7.292 +	    goto done;
   7.293 +	}
   7.294 +	if (op.u.getdomaininfo.flags & DOMFLAGS_PAUSED) {
   7.295 +	    printf("domain currently paused\n");
   7.296 +	    goto done;
   7.297 +	}
   7.298 +	printf("domain not currently paused\n");
   7.299 +	op.cmd = DOM0_PAUSEDOMAIN;
   7.300 +	op.u.pausedomain.domain = pid;
   7.301 +	retval = do_dom0_op(xc_handle, &op);
   7.302 +	break;
   7.303 +    case PTRACE_SINGLESTEP:
   7.304 +	ctxt.cpu_ctxt.eflags |= PSL_T;
   7.305 +	op.cmd = DOM0_SETDOMAININFO;
   7.306 +	op.u.setdomaininfo.domain = pid;
   7.307 +	op.u.setdomaininfo.exec_domain = 0;
   7.308 +	op.u.setdomaininfo.ctxt = &ctxt;
   7.309 +	retval = do_dom0_op(xc_handle, &op);	
   7.310 +	if (retval) {
   7.311 +	    perror("dom0 op failed");
   7.312 +	    goto done;
   7.313 +	}
   7.314 +    case PTRACE_CONT:
   7.315 +    case PTRACE_DETACH:
   7.316 +	regs_valid = 0;
   7.317 +	op.cmd = DOM0_UNPAUSEDOMAIN;
   7.318 +	op.u.unpausedomain.domain = pid > 0 ? pid : -pid;
   7.319 +	retval = do_dom0_op(xc_handle, &op);
   7.320 +	break;
   7.321 +    case PTRACE_SETFPREGS:
   7.322 +    case PTRACE_SETFPXREGS:
   7.323 +    case PTRACE_PEEKUSER:
   7.324 +    case PTRACE_POKEUSER:
   7.325 +    case PTRACE_SYSCALL:
   7.326 +    case PTRACE_KILL:
   7.327 +#ifdef DEBUG
   7.328 +	printf("unsupported xc_ptrace request %s\n", ptrace_names[request]);
   7.329 +#endif
   7.330 +	/* XXX not yet supported */
   7.331 +	status = ENOSYS;
   7.332 +	break;
   7.333 +    case PTRACE_TRACEME:
   7.334 +	printf("PTRACE_TRACEME is an invalid request under Xen\n");
   7.335 +	status = EINVAL;
   7.336 +    }
   7.337 +    
   7.338 +    if (status) {
   7.339 +	errno = status;
   7.340 +	retval = -1;
   7.341 +    }
   7.342 + done:
   7.343 +    return retval;
   7.344 +}
     8.1 --- a/tools/libxc/xc_vmx_build.c	Sat Mar 12 21:38:47 2005 +0000
     8.2 +++ b/tools/libxc/xc_vmx_build.c	Sun Mar 13 00:16:16 2005 +0000
     8.3 @@ -603,10 +603,11 @@ int xc_vmx_build(int xc_handle,
     8.4  
     8.5      memset( &launch_op, 0, sizeof(launch_op) );
     8.6  
     8.7 -    launch_op.u.builddomain.domain   = (domid_t)domid;
     8.8 -    launch_op.u.builddomain.ctxt = ctxt;
     8.9 +    launch_op.u.setdomaininfo.domain   = (domid_t)domid;
    8.10 +    launch_op.u.setdomaininfo.exec_domain = 0;
    8.11 +    launch_op.u.setdomaininfo.ctxt = ctxt;
    8.12  
    8.13 -    launch_op.cmd = DOM0_BUILDDOMAIN;
    8.14 +    launch_op.cmd = DOM0_SETDOMAININFO;
    8.15      rc = do_dom0_op(xc_handle, &launch_op);
    8.16      return rc;
    8.17  
     9.1 --- a/xen/Rules.mk	Sat Mar 12 21:38:47 2005 +0000
     9.2 +++ b/xen/Rules.mk	Sun Mar 13 00:16:16 2005 +0000
     9.3 @@ -1,6 +1,7 @@
     9.4  
     9.5  verbose     ?= n
     9.6  debug       ?= n
     9.7 +debugger    ?= n
     9.8  perfc       ?= n
     9.9  trace       ?= n
    9.10  optimize    ?= y
    9.11 @@ -54,6 +55,10 @@ else
    9.12  CFLAGS += -DVERBOSE
    9.13  endif
    9.14  
    9.15 +ifeq ($(debugger),y)
    9.16 +CFLAGS += -DXEN_UDB
    9.17 +endif
    9.18 +
    9.19  ifeq ($(crash_debug),y)
    9.20  CFLAGS += -g -DCRASH_DEBUG
    9.21  endif
    10.1 --- a/xen/arch/ia64/domain.c	Sat Mar 12 21:38:47 2005 +0000
    10.2 +++ b/xen/arch/ia64/domain.c	Sun Mar 13 00:16:16 2005 +0000
    10.3 @@ -200,7 +200,7 @@ void arch_do_boot_vcpu(struct exec_domai
    10.4  	return;
    10.5  }
    10.6  
    10.7 -int arch_final_setup_guest(struct exec_domain *p, full_execution_context_t *c)
    10.8 +int arch_set_info_guest(struct exec_domain *p, full_execution_context_t *c)
    10.9  {
   10.10  	dummy();
   10.11  	return 1;
    11.1 --- a/xen/arch/x86/domain.c	Sat Mar 12 21:38:47 2005 +0000
    11.2 +++ b/xen/arch/x86/domain.c	Sun Mar 13 00:16:16 2005 +0000
    11.3 @@ -423,13 +423,23 @@ out:
    11.4  
    11.5  
    11.6  /* This is called by arch_final_setup_guest and do_boot_vcpu */
    11.7 -int arch_final_setup_guest(
    11.8 +int arch_set_info_guest(
    11.9      struct exec_domain *ed, full_execution_context_t *c)
   11.10  {
   11.11      struct domain *d = ed->domain;
   11.12      unsigned long phys_basetab;
   11.13      int i, rc;
   11.14  
   11.15 +    /*
   11.16 +     * This is sufficient! If the descriptor DPL differs from CS RPL then we'll
   11.17 +     * #GP. If DS, ES, FS, GS are DPL 0 then they'll be cleared automatically.
   11.18 +     * If SS RPL or DPL differs from CS RPL then we'll #GP.
   11.19 +     */
   11.20 +    if (!(c->flags & ECF_VMX_GUEST)) 
   11.21 +        if ( ((c->cpu_ctxt.cs & 3) == 0) ||
   11.22 +             ((c->cpu_ctxt.ss & 3) == 0) )
   11.23 +                return -EINVAL;
   11.24 +
   11.25      clear_bit(EDF_DONEFPUINIT, &ed->ed_flags);
   11.26      if ( c->flags & ECF_I387_VALID )
   11.27          set_bit(EDF_DONEFPUINIT, &ed->ed_flags);
   11.28 @@ -441,6 +451,11 @@ int arch_final_setup_guest(
   11.29      memcpy(&ed->arch.user_ctxt,
   11.30             &c->cpu_ctxt,
   11.31             sizeof(ed->arch.user_ctxt));
   11.32 +
   11.33 +    memcpy(&ed->arch.i387,
   11.34 +           &c->fpu_ctxt,
   11.35 +           sizeof(ed->arch.i387));
   11.36 +
   11.37      /* IOPL privileges are virtualised. */
   11.38      ed->arch.iopl = (ed->arch.user_ctxt.eflags >> 12) & 3;
   11.39      ed->arch.user_ctxt.eflags &= ~EF_IOPL;
   11.40 @@ -449,19 +464,8 @@ int arch_final_setup_guest(
   11.41      if (!IS_PRIV(d))
   11.42          ed->arch.user_ctxt.eflags &= 0xffffcfff;
   11.43  
   11.44 -    /*
   11.45 -     * This is sufficient! If the descriptor DPL differs from CS RPL then we'll
   11.46 -     * #GP. If DS, ES, FS, GS are DPL 0 then they'll be cleared automatically.
   11.47 -     * If SS RPL or DPL differs from CS RPL then we'll #GP.
   11.48 -     */
   11.49 -    if (!(c->flags & ECF_VMX_GUEST)) 
   11.50 -        if ( ((ed->arch.user_ctxt.cs & 3) == 0) ||
   11.51 -             ((ed->arch.user_ctxt.ss & 3) == 0) )
   11.52 -                return -EINVAL;
   11.53 -
   11.54 -    memcpy(&ed->arch.i387,
   11.55 -           &c->fpu_ctxt,
   11.56 -           sizeof(ed->arch.i387));
   11.57 +    if (test_bit(EDF_DONEINIT, &ed->ed_flags))
   11.58 +        return 0;
   11.59  
   11.60      memcpy(ed->arch.traps,
   11.61             &c->trap_ctxt,
   11.62 @@ -509,10 +513,14 @@ int arch_final_setup_guest(
   11.63  #endif
   11.64  
   11.65      update_pagetables(ed);
   11.66 +    
   11.67 +    /* Don't redo final setup */
   11.68 +    set_bit(EDF_DONEINIT, &ed->ed_flags);
   11.69  
   11.70      return 0;
   11.71  }
   11.72  
   11.73 +
   11.74  void new_thread(struct exec_domain *d,
   11.75                  unsigned long start_pc,
   11.76                  unsigned long start_stack,
    12.1 --- a/xen/arch/x86/traps.c	Sat Mar 12 21:38:47 2005 +0000
    12.2 +++ b/xen/arch/x86/traps.c	Sun Mar 13 00:16:16 2005 +0000
    12.3 @@ -222,8 +222,19 @@ asmlinkage int do_int3(struct xen_regs *
    12.4          DEBUGGER_trap_fatal(TRAP_int3, regs);
    12.5          show_registers(regs);
    12.6          panic("CPU%d FATAL TRAP: vector = 3 (Int3)\n", smp_processor_id());
    12.7 +    } 
    12.8 +#ifdef XEN_UDB
    12.9 +    else if ( KERNEL_MODE(ed, regs) && ed->domain->id != 0 ) 
   12.10 +    {
   12.11 +        if ( !test_and_set_bit(EDF_CTRLPAUSE, &ed->ed_flags) ) {
   12.12 +            while (ed == current)
   12.13 +                __enter_scheduler();
   12.14 +            domain_pause_by_systemcontroller(ed->domain);
   12.15 +        }
   12.16 +        
   12.17 +        return 0;
   12.18      }
   12.19 -
   12.20 +#endif /* XEN_UDB */
   12.21      ti = current->arch.traps + 3;
   12.22      tb->flags = TBF_EXCEPTION;
   12.23      tb->cs    = ti->cs;
   12.24 @@ -886,8 +897,8 @@ asmlinkage int math_state_restore(struct
   12.25  asmlinkage int do_debug(struct xen_regs *regs)
   12.26  {
   12.27      unsigned long condition;
   12.28 -    struct exec_domain *d = current;
   12.29 -    struct trap_bounce *tb = &d->arch.trap_bounce;
   12.30 +    struct exec_domain *ed = current;
   12.31 +    struct trap_bounce *tb = &ed->arch.trap_bounce;
   12.32  
   12.33      DEBUGGER_trap_entry(TRAP_debug, regs);
   12.34  
   12.35 @@ -895,7 +906,7 @@ asmlinkage int do_debug(struct xen_regs 
   12.36  
   12.37      /* Mask out spurious debug traps due to lazy DR7 setting */
   12.38      if ( (condition & (DR_TRAP0|DR_TRAP1|DR_TRAP2|DR_TRAP3)) &&
   12.39 -         (d->arch.debugreg[7] == 0) )
   12.40 +         (ed->arch.debugreg[7] == 0) )
   12.41      {
   12.42          __asm__("mov %0,%%db7" : : "r" (0UL));
   12.43          goto out;
   12.44 @@ -912,14 +923,26 @@ asmlinkage int do_debug(struct xen_regs 
   12.45           * breakpoint, which can't happen to us.
   12.46           */
   12.47          goto out;
   12.48 -    }
   12.49 +    } 
   12.50 +#ifdef XEN_UDB
   12.51 +    else if ( KERNEL_MODE(ed, regs) && ed->domain->id != 0 ) 
   12.52 +    {
   12.53 +        regs->eflags &= ~EF_TF;
   12.54 +        if ( !test_and_set_bit(EDF_CTRLPAUSE, &ed->ed_flags) ) {
   12.55 +            while (ed == current)
   12.56 +                __enter_scheduler();
   12.57 +            domain_pause_by_systemcontroller(ed->domain);
   12.58 +        }
   12.59  
   12.60 +        goto out;
   12.61 +    }    
   12.62 +#endif /* XEN_UDB */
   12.63      /* Save debug status register where guest OS can peek at it */
   12.64 -    d->arch.debugreg[6] = condition;
   12.65 +    ed->arch.debugreg[6] = condition;
   12.66  
   12.67      tb->flags = TBF_EXCEPTION;
   12.68 -    tb->cs    = d->arch.traps[1].cs;
   12.69 -    tb->eip   = d->arch.traps[1].address;
   12.70 +    tb->cs    = ed->arch.traps[1].cs;
   12.71 +    tb->eip   = ed->arch.traps[1].address;
   12.72  
   12.73   out:
   12.74      return EXCRET_not_a_fault;
    13.1 --- a/xen/common/dom0_ops.c	Sat Mar 12 21:38:47 2005 +0000
    13.2 +++ b/xen/common/dom0_ops.c	Sun Mar 13 00:16:16 2005 +0000
    13.3 @@ -111,13 +111,13 @@ long do_dom0_op(dom0_op_t *u_dom0_op)
    13.4      switch ( op->cmd )
    13.5      {
    13.6  
    13.7 -    case DOM0_BUILDDOMAIN:
    13.8 +    case DOM0_SETDOMAININFO:
    13.9      {
   13.10 -        struct domain *d = find_domain_by_id(op->u.builddomain.domain);
   13.11 +        struct domain *d = find_domain_by_id(op->u.setdomaininfo.domain);
   13.12          ret = -ESRCH;
   13.13          if ( d != NULL )
   13.14          {
   13.15 -            ret = final_setup_guest(d, &op->u.builddomain);
   13.16 +            ret = set_info_guest(d, &op->u.setdomaininfo);
   13.17              put_domain(d);
   13.18          }
   13.19      }
    14.1 --- a/xen/common/domain.c	Sat Mar 12 21:38:47 2005 +0000
    14.2 +++ b/xen/common/domain.c	Sun Mar 13 00:16:16 2005 +0000
    14.3 @@ -256,31 +256,34 @@ void domain_destruct(struct domain *d)
    14.4  
    14.5  
    14.6  /*
    14.7 - * final_setup_guest is used for final setup and launching of domains other
    14.8 - * than domain 0. ie. the domains that are being built by the userspace dom0
    14.9 - * domain builder.
   14.10 + * set_info_guest is used for final setup, launching, and state modification 
   14.11 + * of domains other than domain 0. ie. the domains that are being built by 
   14.12 + * the userspace dom0 domain builder.
   14.13   */
   14.14 -int final_setup_guest(struct domain *p, dom0_builddomain_t *builddomain)
   14.15 +int set_info_guest(struct domain *p, dom0_setdomaininfo_t *setdomaininfo)
   14.16  {
   14.17      int rc = 0;
   14.18 -    full_execution_context_t *c;
   14.19 +    full_execution_context_t *c = NULL;
   14.20 +    unsigned long vcpu = setdomaininfo->exec_domain;
   14.21 +    struct exec_domain *ed; 
   14.22 +
   14.23 +    if ( (vcpu >= MAX_VIRT_CPUS) || ((ed = p->exec_domain[vcpu]) != NULL) )
   14.24 +        return -EINVAL;
   14.25 +    
   14.26 +    if (test_bit(DF_CONSTRUCTED, &p->d_flags) && 
   14.27 +        !test_bit(EDF_CTRLPAUSE, &ed->ed_flags))
   14.28 +        return -EINVAL;
   14.29  
   14.30      if ( (c = xmalloc(full_execution_context_t)) == NULL )
   14.31          return -ENOMEM;
   14.32  
   14.33 -    if ( test_bit(DF_CONSTRUCTED, &p->d_flags) )
   14.34 -    {
   14.35 -        rc = -EINVAL;
   14.36 -        goto out;
   14.37 -    }
   14.38 -
   14.39 -    if ( copy_from_user(c, builddomain->ctxt, sizeof(*c)) )
   14.40 +    if ( copy_from_user(c, setdomaininfo->ctxt, sizeof(*c)) )
   14.41      {
   14.42          rc = -EFAULT;
   14.43          goto out;
   14.44      }
   14.45      
   14.46 -    if ( (rc = arch_final_setup_guest(p->exec_domain[0],c)) != 0 )
   14.47 +    if ( (rc = arch_set_info_guest(ed, c)) != 0 )
   14.48          goto out;
   14.49  
   14.50      set_bit(DF_CONSTRUCTED, &p->d_flags);
   14.51 @@ -331,7 +334,7 @@ long do_boot_vcpu(unsigned long vcpu, fu
   14.52  
   14.53      sched_add_domain(ed);
   14.54  
   14.55 -    if ( (rc = arch_final_setup_guest(ed, c)) != 0 ) {
   14.56 +    if ( (rc = arch_set_info_guest(ed, c)) != 0 ) {
   14.57          sched_rem_domain(ed);
   14.58          goto out;
   14.59      }
    15.1 --- a/xen/include/public/dom0_ops.h	Sat Mar 12 21:38:47 2005 +0000
    15.2 +++ b/xen/include/public/dom0_ops.h	Sun Mar 13 00:16:16 2005 +0000
    15.3 @@ -109,16 +109,16 @@ typedef struct {
    15.4      u64      cpu_time;                /* 40 */
    15.5  } PACKED dom0_getdomaininfo_t; /* 48 bytes */
    15.6  
    15.7 -#define DOM0_BUILDDOMAIN      13
    15.8 +#define DOM0_SETDOMAININFO      13
    15.9  typedef struct {
   15.10      /* IN variables. */
   15.11 -    domid_t                 domain;   /*  0 */
   15.12 -    u16                     __pad0;   /*  2 */
   15.13 -    u32                     __pad1;   /*  4 */
   15.14 +    domid_t                   domain;       /*  0 */
   15.15 +    u16                       exec_domain;  /*  2 */
   15.16 +    u32                       __pad0;       /*  4 */
   15.17      /* IN/OUT parameters */
   15.18 -    full_execution_context_t *ctxt;   /*  8 */
   15.19 +    full_execution_context_t *ctxt;         /*  8 */
   15.20      MEMORY_PADDING;
   15.21 -} PACKED dom0_builddomain_t; /* 16 bytes */
   15.22 +} PACKED dom0_setdomaininfo_t;              /* 16 bytes */
   15.23  
   15.24  #define DOM0_IOPL             14
   15.25  typedef struct {
   15.26 @@ -426,7 +426,7 @@ typedef struct {
   15.27          dom0_getmemlist_t        getmemlist;
   15.28          dom0_schedctl_t          schedctl;
   15.29          dom0_adjustdom_t         adjustdom;
   15.30 -        dom0_builddomain_t       builddomain;
   15.31 +        dom0_setdomaininfo_t     setdomaininfo;
   15.32          dom0_getdomaininfo_t     getdomaininfo;
   15.33          dom0_getpageframeinfo_t  getpageframeinfo;
   15.34          dom0_iopl_t              iopl;
    16.1 --- a/xen/include/xen/domain.h	Sat Mar 12 21:38:47 2005 +0000
    16.2 +++ b/xen/include/xen/domain.h	Sun Mar 13 00:16:16 2005 +0000
    16.3 @@ -18,7 +18,7 @@ extern void arch_do_createdomain(struct 
    16.4  
    16.5  extern void arch_do_boot_vcpu(struct exec_domain *ed);
    16.6  
    16.7 -extern int  arch_final_setup_guest(
    16.8 +extern int  arch_set_info_guest(
    16.9      struct exec_domain *d, full_execution_context_t *c);
   16.10  
   16.11  extern void free_perdomain_pt(struct domain *d);
    17.1 --- a/xen/include/xen/sched.h	Sat Mar 12 21:38:47 2005 +0000
    17.2 +++ b/xen/include/xen/sched.h	Sun Mar 13 00:16:16 2005 +0000
    17.3 @@ -220,7 +220,7 @@ extern int construct_dom0(
    17.4      unsigned long image_start, unsigned long image_len, 
    17.5      unsigned long initrd_start, unsigned long initrd_len,
    17.6      char *cmdline);
    17.7 -extern int final_setup_guest(struct domain *d, dom0_builddomain_t *);
    17.8 +extern int set_info_guest(struct domain *d, dom0_setdomaininfo_t *);
    17.9  
   17.10  struct domain *find_domain_by_id(domid_t dom);
   17.11  struct domain *find_last_domain(void);
   17.12 @@ -317,6 +317,7 @@ extern struct domain *domain_list;
   17.13  #define EDF_RUNNING     12 /* Currently running on a CPU.                    */
   17.14  #define EDF_CPUPINNED   13 /* Disables auto-migration.                       */
   17.15  #define EDF_MIGRATED    14 /* Domain migrated between CPUs.                  */
   17.16 +#define EDF_DONEINIT    15 /* Initialization completed    .                  */
   17.17  
   17.18  static inline int domain_runnable(struct exec_domain *d)
   17.19  {