ia64/xen-unstable

changeset 11701:2bfd19fc1b79

merge with xen-unstable.hg
author awilliam@xenbuild.aw
date Sun Oct 01 19:10:18 2006 -0600 (2006-10-01)
parents 914c44d10c8d 02311d8aba86
children 5c97ef4c7147
files tools/debugger/pdb/Domain.ml tools/debugger/pdb/Domain.mli tools/debugger/pdb/Intel.ml tools/debugger/pdb/Makefile tools/debugger/pdb/OCamlMakefile tools/debugger/pdb/PDB.ml tools/debugger/pdb/Process.ml tools/debugger/pdb/Process.mli tools/debugger/pdb/Util.ml tools/debugger/pdb/Xen_domain.ml tools/debugger/pdb/Xen_domain.mli tools/debugger/pdb/debugger.ml tools/debugger/pdb/evtchn.ml tools/debugger/pdb/evtchn.mli tools/debugger/pdb/linux-2.6-module/Makefile tools/debugger/pdb/linux-2.6-module/debug.c tools/debugger/pdb/linux-2.6-module/module.c tools/debugger/pdb/linux-2.6-module/pdb_debug.h tools/debugger/pdb/linux-2.6-module/pdb_module.h tools/debugger/pdb/linux-2.6-patches/Makefile tools/debugger/pdb/linux-2.6-patches/i386_ksyms.patch tools/debugger/pdb/linux-2.6-patches/kdebug.patch tools/debugger/pdb/linux-2.6-patches/makefile.patch tools/debugger/pdb/linux-2.6-patches/ptrace.patch tools/debugger/pdb/linux-2.6-patches/traps.patch tools/debugger/pdb/pdb_caml_domain.c tools/debugger/pdb/pdb_caml_evtchn.c tools/debugger/pdb/pdb_caml_process.c tools/debugger/pdb/pdb_caml_xc.c tools/debugger/pdb/pdb_caml_xcs.c tools/debugger/pdb/pdb_caml_xen.h tools/debugger/pdb/pdb_xen.c tools/debugger/pdb/readme tools/debugger/pdb/server.ml tools/debugger/pdb/xcs.ml tools/debugger/pdb/xcs.mli
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c	Sun Oct 01 11:39:41 2006 -0600
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c	Sun Oct 01 19:10:18 2006 -0600
     1.3 @@ -273,7 +273,7 @@ static void backend_changed(struct xenbu
     1.4  			xenbus_dev_fatal(dev, -ENODEV, "bdget failed");
     1.5  
     1.6  		down(&bd->bd_sem);
     1.7 -		if (info->users > 0 && system_state == SYSTEM_RUNNING)
     1.8 +		if (info->users > 0)
     1.9  			xenbus_dev_error(dev, -EBUSY,
    1.10  					 "Device in use; refusing to close");
    1.11  		else
    1.12 @@ -355,8 +355,10 @@ static void blkfront_closing(struct xenb
    1.13  	blk_stop_queue(info->rq);
    1.14  	/* No more gnttab callback work. */
    1.15  	gnttab_cancel_free_callback(&info->callback);
    1.16 +	spin_unlock_irqrestore(&blkif_io_lock, flags);
    1.17 +
    1.18 +	/* Flush gnttab callback work. Must be done with no locks held. */
    1.19  	flush_scheduled_work();
    1.20 -	spin_unlock_irqrestore(&blkif_io_lock, flags);
    1.21  
    1.22  	xlvbd_del(info);
    1.23  
    1.24 @@ -714,8 +716,10 @@ static void blkif_free(struct blkfront_i
    1.25  		blk_stop_queue(info->rq);
    1.26  	/* No more gnttab callback work. */
    1.27  	gnttab_cancel_free_callback(&info->callback);
    1.28 +	spin_unlock_irq(&blkif_io_lock);
    1.29 +
    1.30 +	/* Flush gnttab callback work. Must be done with no locks held. */
    1.31  	flush_scheduled_work();
    1.32 -	spin_unlock_irq(&blkif_io_lock);
    1.33  
    1.34  	/* Free resources associated with old device channel. */
    1.35  	if (info->ring_ref != GRANT_INVALID_REF) {
     2.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c	Sun Oct 01 11:39:41 2006 -0600
     2.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c	Sun Oct 01 19:10:18 2006 -0600
     2.3 @@ -44,7 +44,6 @@
     2.4  #include <linux/kernel.h>
     2.5  #include <linux/fs.h>
     2.6  #include <linux/mm.h>
     2.7 -#include <linux/miscdevice.h>
     2.8  #include <linux/errno.h>
     2.9  #include <linux/major.h>
    2.10  #include <linux/gfp.h>
    2.11 @@ -55,6 +54,30 @@
    2.12  #define MAX_TAP_DEV 100     /*the maximum number of tapdisk ring devices    */
    2.13  #define MAX_DEV_NAME 100    /*the max tapdisk ring device name e.g. blktap0 */
    2.14  
    2.15 +
    2.16 +struct class *xen_class;
    2.17 +EXPORT_SYMBOL_GPL(xen_class);
    2.18 +
    2.19 +/*
    2.20 + * Setup the xen class.  This should probably go in another file, but
    2.21 + * since blktap is the only user of it so far, it gets to keep it.
    2.22 + */
    2.23 +int setup_xen_class(void)
    2.24 +{
    2.25 +	int ret;
    2.26 +
    2.27 +	if (xen_class)
    2.28 +		return 0;
    2.29 +
    2.30 +	xen_class = class_create(THIS_MODULE, "xen");
    2.31 +	if ((ret = IS_ERR(xen_class))) {
    2.32 +		xen_class = NULL;
    2.33 +		return ret;
    2.34 +	}
    2.35 +
    2.36 +	return 0;
    2.37 +}
    2.38 +
    2.39  /*
    2.40   * The maximum number of requests that can be outstanding at any time
    2.41   * is determined by 
    2.42 @@ -100,20 +123,15 @@ typedef struct tap_blkif {
    2.43  	unsigned long *idx_map;       /*Record the user ring id to kern 
    2.44  					[req id, idx] tuple                  */
    2.45  	blkif_t *blkif;               /*Associate blkif with tapdev          */
    2.46 +	int sysfs_set;                /*Set if it has a class device.        */
    2.47  } tap_blkif_t;
    2.48  
    2.49 -/*Private data struct associated with the inode*/
    2.50 -typedef struct private_info {
    2.51 -	int idx;
    2.52 -} private_info_t;
    2.53 -
    2.54  /*Data struct handed back to userspace for tapdisk device to VBD mapping*/
    2.55  typedef struct domid_translate {
    2.56  	unsigned short domid;
    2.57  	unsigned short busid;
    2.58  } domid_translate_t ;
    2.59  
    2.60 -
    2.61  static domid_translate_t  translate_domid[MAX_TAP_DEV];
    2.62  static tap_blkif_t *tapfds[MAX_TAP_DEV];
    2.63  
    2.64 @@ -200,15 +218,13 @@ static struct grant_handle_pair
    2.65      + (_i)])
    2.66  
    2.67  
    2.68 -static int blktap_read_ufe_ring(int idx); /*local prototypes*/
    2.69 +static int blktap_read_ufe_ring(tap_blkif_t *info); /*local prototypes*/
    2.70  
    2.71 -#define BLKTAP_MINOR 0  /*/dev/xen/blktap resides at device number
    2.72 -			  major=254, minor numbers begin at 0            */ 
    2.73 -#define BLKTAP_DEV_MAJOR 254         /* TODO: Make major number dynamic  *
    2.74 -                                      * and create devices in the kernel *
    2.75 -				      */
    2.76 +#define BLKTAP_MINOR 0  /*/dev/xen/blktap has a dynamic major */
    2.77  #define BLKTAP_DEV_DIR  "/dev/xen"
    2.78  
    2.79 +static int blktap_major;
    2.80 +
    2.81  /* blktap IOCTLs: */
    2.82  #define BLKTAP_IOCTL_KICK_FE         1
    2.83  #define BLKTAP_IOCTL_KICK_BE         2 /* currently unused */
    2.84 @@ -264,7 +280,8 @@ static inline int GET_NEXT_REQ(unsigned 
    2.85  {
    2.86  	int i;
    2.87  	for (i = 0; i < MAX_PENDING_REQS; i++)
    2.88 -		if (idx_map[i] == INVALID_REQ) return i;
    2.89 +		if (idx_map[i] == INVALID_REQ)
    2.90 +			return i;
    2.91  
    2.92  	return INVALID_REQ;
    2.93  }
    2.94 @@ -311,8 +328,6 @@ static int blktap_ioctl(struct inode *in
    2.95                          unsigned int cmd, unsigned long arg);
    2.96  static unsigned int blktap_poll(struct file *file, poll_table *wait);
    2.97  
    2.98 -struct miscdevice *set_misc(int minor, char *name, int dev);
    2.99 -
   2.100  static struct file_operations blktap_fops = {
   2.101  	.owner   = THIS_MODULE,
   2.102  	.poll    = blktap_poll,
   2.103 @@ -344,6 +359,16 @@ static int get_next_free_dev(void)
   2.104  	
   2.105  done:
   2.106  	spin_unlock_irqrestore(&pending_free_lock, flags);
   2.107 +
   2.108 +	/*
   2.109 +	 * We are protected by having the dev_pending set.
   2.110 +	 */
   2.111 +	if (!tapfds[i]->sysfs_set && xen_class) {
   2.112 +		class_device_create(xen_class, NULL,
   2.113 +				    MKDEV(blktap_major, ret), NULL,
   2.114 +				    "blktap%d", ret);
   2.115 +		tapfds[i]->sysfs_set = 1;
   2.116 +	}
   2.117  	return ret;
   2.118  }
   2.119  
   2.120 @@ -369,9 +394,8 @@ void signal_tapdisk(int idx)
   2.121  	info = tapfds[idx];
   2.122  	if ( (idx > 0) && (idx < MAX_TAP_DEV) && (info->pid > 0) ) {
   2.123  		ptask = find_task_by_pid(info->pid);
   2.124 -		if (ptask) { 
   2.125 +		if (ptask)
   2.126  			info->status = CLEANSHUTDOWN;
   2.127 - 		}
   2.128  	}
   2.129  	info->blkif = NULL;
   2.130  	return;
   2.131 @@ -382,7 +406,6 @@ static int blktap_open(struct inode *ino
   2.132  	blkif_sring_t *sring;
   2.133  	int idx = iminor(inode) - BLKTAP_MINOR;
   2.134  	tap_blkif_t *info;
   2.135 -	private_info_t *prv;
   2.136  	int i;
   2.137  	
   2.138  	if (tapfds[idx] == NULL) {
   2.139 @@ -410,9 +433,7 @@ static int blktap_open(struct inode *ino
   2.140  	SHARED_RING_INIT(sring);
   2.141  	FRONT_RING_INIT(&info->ufe_ring, sring, PAGE_SIZE);
   2.142  	
   2.143 -	prv = kzalloc(sizeof(private_info_t),GFP_KERNEL);
   2.144 -	prv->idx = idx;
   2.145 -	filp->private_data = prv;
   2.146 +	filp->private_data = info;
   2.147  	info->vma = NULL;
   2.148  
   2.149  	info->idx_map = kmalloc(sizeof(unsigned long) * MAX_PENDING_REQS, 
   2.150 @@ -433,17 +454,16 @@ static int blktap_open(struct inode *ino
   2.151  
   2.152  static int blktap_release(struct inode *inode, struct file *filp)
   2.153  {
   2.154 -	int idx = iminor(inode) - BLKTAP_MINOR;
   2.155 -	tap_blkif_t *info;
   2.156 +	tap_blkif_t *info = filp->private_data;
   2.157  	
   2.158 -	if (tapfds[idx] == NULL) {
   2.159 +	/* can this ever happen? - sdr */
   2.160 +	if (!info) {
   2.161  		WPRINTK("Trying to free device that doesn't exist "
   2.162 -		       "[/dev/xen/blktap%d]\n",idx);
   2.163 -		return -1;
   2.164 +		       "[/dev/xen/blktap%d]\n",iminor(inode) - BLKTAP_MINOR);
   2.165 +		return -EBADF;
   2.166  	}
   2.167 -	info = tapfds[idx];
   2.168  	info->dev_inuse = 0;
   2.169 -	DPRINTK("Freeing device [/dev/xen/blktap%d]\n",idx);
   2.170 +	DPRINTK("Freeing device [/dev/xen/blktap%d]\n",info->minor);
   2.171  
   2.172  	/* Free the ring page. */
   2.173  	ClearPageReserved(virt_to_page(info->ufe_ring.sring));
   2.174 @@ -457,8 +477,6 @@ static int blktap_release(struct inode *
   2.175  		info->vma = NULL;
   2.176  	}
   2.177  	
   2.178 -	if (filp->private_data) kfree(filp->private_data);
   2.179 -
   2.180  	if ( (info->status != CLEANSHUTDOWN) && (info->blkif != NULL) ) {
   2.181  		kthread_stop(info->blkif->xenblkd);
   2.182  		info->blkif->xenblkd = NULL;
   2.183 @@ -491,16 +509,12 @@ static int blktap_mmap(struct file *filp
   2.184  	int size;
   2.185  	struct page **map;
   2.186  	int i;
   2.187 -	private_info_t *prv;
   2.188 -	tap_blkif_t *info;
   2.189 +	tap_blkif_t *info = filp->private_data;
   2.190  
   2.191 -	/*Retrieve the dev info*/
   2.192 -	prv = (private_info_t *)filp->private_data;
   2.193 -	if (prv == NULL) {
   2.194 +	if (info == NULL) {
   2.195  		WPRINTK("blktap: mmap, retrieving idx failed\n");
   2.196  		return -ENOMEM;
   2.197  	}
   2.198 -	info = tapfds[prv->idx];
   2.199  	
   2.200  	vma->vm_flags |= VM_RESERVED;
   2.201  	vma->vm_ops = &blktap_vm_ops;
   2.202 @@ -556,20 +570,17 @@ static int blktap_mmap(struct file *filp
   2.203  static int blktap_ioctl(struct inode *inode, struct file *filp,
   2.204                          unsigned int cmd, unsigned long arg)
   2.205  {
   2.206 -	int idx = iminor(inode) - BLKTAP_MINOR;
   2.207 +	tap_blkif_t *info = filp->private_data;
   2.208 +
   2.209  	switch(cmd) {
   2.210  	case BLKTAP_IOCTL_KICK_FE: 
   2.211  	{
   2.212  		/* There are fe messages to process. */
   2.213 -		return blktap_read_ufe_ring(idx);
   2.214 +		return blktap_read_ufe_ring(info);
   2.215  	}
   2.216  	case BLKTAP_IOCTL_SETMODE:
   2.217  	{
   2.218 -		tap_blkif_t *info = tapfds[idx];
   2.219 -		
   2.220 -		if ( (idx > 0) && (idx < MAX_TAP_DEV) 
   2.221 -		     && (tapfds[idx] != NULL) ) 
   2.222 -		{
   2.223 +		if (info) {
   2.224  			if (BLKTAP_MODE_VALID(arg)) {
   2.225  				info->mode = arg;
   2.226  				/* XXX: may need to flush rings here. */
   2.227 @@ -582,11 +593,7 @@ static int blktap_ioctl(struct inode *in
   2.228  	}
   2.229  	case BLKTAP_IOCTL_PRINT_IDXS:
   2.230          {
   2.231 -		tap_blkif_t *info = tapfds[idx];
   2.232 -		
   2.233 -		if ( (idx > 0) && (idx < MAX_TAP_DEV) 
   2.234 -		     && (tapfds[idx] != NULL) ) 
   2.235 -		{
   2.236 +		if (info) {
   2.237  			printk("User Rings: \n-----------\n");
   2.238  			printk("UF: rsp_cons: %2d, req_prod_prv: %2d "
   2.239  				"| req_prod: %2d, rsp_prod: %2d\n",
   2.240 @@ -599,11 +606,7 @@ static int blktap_ioctl(struct inode *in
   2.241          }
   2.242  	case BLKTAP_IOCTL_SENDPID:
   2.243  	{
   2.244 -		tap_blkif_t *info = tapfds[idx];
   2.245 -		
   2.246 -		if ( (idx > 0) && (idx < MAX_TAP_DEV) 
   2.247 -		     && (tapfds[idx] != NULL) ) 
   2.248 -		{
   2.249 +		if (info) {
   2.250  			info->pid = (pid_t)arg;
   2.251  			DPRINTK("blktap: pid received %d\n", 
   2.252  			       info->pid);
   2.253 @@ -631,26 +634,38 @@ static int blktap_ioctl(struct inode *in
   2.254  	case BLKTAP_IOCTL_FREEINTF:
   2.255  	{
   2.256  		unsigned long dev = arg;
   2.257 -		tap_blkif_t *info = NULL;
   2.258 +		unsigned long flags;
   2.259 +
   2.260 +		/* Looking at another device */
   2.261 +		info = NULL;
   2.262  
   2.263 -		if ( (dev > 0) && (dev < MAX_TAP_DEV) ) info = tapfds[dev];
   2.264 +		if ( (dev > 0) && (dev < MAX_TAP_DEV) )
   2.265 +			info = tapfds[dev];
   2.266  
   2.267 +		spin_lock_irqsave(&pending_free_lock, flags);
   2.268  		if ( (info != NULL) && (info->dev_pending) )
   2.269  			info->dev_pending = 0;
   2.270 +		spin_unlock_irqrestore(&pending_free_lock, flags);
   2.271 +
   2.272  		return 0;
   2.273  	}
   2.274  	case BLKTAP_IOCTL_MINOR:
   2.275  	{
   2.276  		unsigned long dev = arg;
   2.277 -		tap_blkif_t *info = NULL;
   2.278 +
   2.279 +		/* Looking at another device */
   2.280 +		info = NULL;
   2.281  		
   2.282 -		if ( (dev > 0) && (dev < MAX_TAP_DEV) ) info = tapfds[dev];
   2.283 +		if ( (dev > 0) && (dev < MAX_TAP_DEV) )
   2.284 +			info = tapfds[dev];
   2.285  		
   2.286 -		if (info != NULL) return info->minor;
   2.287 -		else return -1;
   2.288 +		if (info != NULL)
   2.289 +			return info->minor;
   2.290 +		else
   2.291 +			return -1;
   2.292  	}
   2.293  	case BLKTAP_IOCTL_MAJOR:
   2.294 -		return BLKTAP_DEV_MAJOR;
   2.295 +		return blktap_major;
   2.296  
   2.297  	case BLKTAP_QUERY_ALLOC_REQS:
   2.298  	{
   2.299 @@ -662,25 +677,21 @@ static int blktap_ioctl(struct inode *in
   2.300  	return -ENOIOCTLCMD;
   2.301  }
   2.302  
   2.303 -static unsigned int blktap_poll(struct file *file, poll_table *wait)
   2.304 +static unsigned int blktap_poll(struct file *filp, poll_table *wait)
   2.305  {
   2.306 -	private_info_t *prv;
   2.307 -	tap_blkif_t *info;
   2.308 +	tap_blkif_t *info = filp->private_data;
   2.309  	
   2.310 -	/*Retrieve the dev info*/
   2.311 -	prv = (private_info_t *)file->private_data;
   2.312 -	if (prv == NULL) {
   2.313 +	if (!info) {
   2.314  		WPRINTK(" poll, retrieving idx failed\n");
   2.315  		return 0;
   2.316  	}
   2.317 -	
   2.318 -	if (prv->idx == 0) return 0;
   2.319 -	
   2.320 -	info = tapfds[prv->idx];
   2.321 -	
   2.322 -	poll_wait(file, &info->wait, wait);
   2.323 +
   2.324 +	/* do not work on the control device */
   2.325 +	if (!info->minor)
   2.326 +		return 0;
   2.327 +
   2.328 +	poll_wait(filp, &info->wait, wait);
   2.329  	if (info->ufe_ring.req_prod_pvt != info->ufe_ring.sring->req_prod) {
   2.330 -		flush_tlb_all();
   2.331  		RING_PUSH_REQUESTS(&info->ufe_ring);
   2.332  		return POLLIN | POLLRDNORM;
   2.333  	}
   2.334 @@ -691,11 +702,14 @@ void blktap_kick_user(int idx)
   2.335  {
   2.336  	tap_blkif_t *info;
   2.337  
   2.338 -	if (idx == 0) return;
   2.339 +	if (idx == 0)
   2.340 +		return;
   2.341  	
   2.342  	info = tapfds[idx];
   2.343  	
   2.344 -	if (info != NULL) wake_up_interruptible(&info->wait);
   2.345 +	if (info != NULL)
   2.346 +		wake_up_interruptible(&info->wait);
   2.347 +
   2.348  	return;
   2.349  }
   2.350  
   2.351 @@ -713,11 +727,8 @@ static int req_increase(void)
   2.352  {
   2.353  	int i, j;
   2.354  	struct page *page;
   2.355 -	unsigned long flags;
   2.356  	int ret;
   2.357  
   2.358 -	spin_lock_irqsave(&pending_free_lock, flags);
   2.359 -
   2.360  	ret = -EINVAL;
   2.361  	if (mmap_alloc >= MAX_PENDING_REQS || mmap_lock) 
   2.362  		goto done;
   2.363 @@ -782,8 +793,7 @@ static int req_increase(void)
   2.364  
   2.365  	mmap_alloc++;
   2.366  	DPRINTK("# MMAPs increased to %d\n",mmap_alloc);
   2.367 - done:
   2.368 -	spin_unlock_irqrestore(&pending_free_lock, flags);
   2.369 +done:
   2.370  	return ret;
   2.371  }
   2.372  
   2.373 @@ -813,36 +823,6 @@ static void mmap_req_del(int mmap)
   2.374  	mmap_alloc--;
   2.375  }
   2.376  
   2.377 -/*N.B. Currently unused - will be accessed via sysfs*/
   2.378 -static void req_decrease(void)
   2.379 -{
   2.380 -	pending_req_t *req;
   2.381 -	int i;
   2.382 -	unsigned long flags;
   2.383 -
   2.384 -	spin_lock_irqsave(&pending_free_lock, flags);
   2.385 -
   2.386 -	DPRINTK("Req decrease called.\n");
   2.387 -	if (mmap_lock || mmap_alloc == 1) 
   2.388 -		goto done;
   2.389 -
   2.390 -	mmap_lock = 1;
   2.391 -	mmap_inuse = MAX_PENDING_REQS;
   2.392 -	
   2.393 -        /*Go through reqs and remove any that aren't in use*/
   2.394 -	for (i = 0; i < MAX_PENDING_REQS ; i++) {
   2.395 -		req = &pending_reqs[mmap_alloc-1][i];
   2.396 -		if (req->inuse == 0) {
   2.397 -			list_del(&req->free_list);
   2.398 -			mmap_inuse--;
   2.399 -		}
   2.400 -	}
   2.401 -	if (mmap_inuse == 0) mmap_req_del(mmap_alloc-1);
   2.402 - done:
   2.403 -	spin_unlock_irqrestore(&pending_free_lock, flags);
   2.404 -	return;
   2.405 -}
   2.406 -
   2.407  static pending_req_t* alloc_req(void)
   2.408  {
   2.409  	pending_req_t *req = NULL;
   2.410 @@ -1002,7 +982,7 @@ int tap_blkif_schedule(void *arg)
   2.411   * COMPLETION CALLBACK -- Called by user level ioctl()
   2.412   */
   2.413  
   2.414 -static int blktap_read_ufe_ring(int idx)
   2.415 +static int blktap_read_ufe_ring(tap_blkif_t *info)
   2.416  {
   2.417  	/* This is called to read responses from the UFE ring. */
   2.418  	RING_IDX i, j, rp;
   2.419 @@ -1010,12 +990,9 @@ static int blktap_read_ufe_ring(int idx)
   2.420  	blkif_t *blkif=NULL;
   2.421  	int pending_idx, usr_idx, mmap_idx;
   2.422  	pending_req_t *pending_req;
   2.423 -	tap_blkif_t *info;
   2.424  	
   2.425 -	info = tapfds[idx];
   2.426 -	if (info == NULL) {
   2.427 +	if (!info)
   2.428  		return 0;
   2.429 -	}
   2.430  
   2.431  	/* We currently only forward packets in INTERCEPT_FE mode. */
   2.432  	if (!(info->mode & BLKTAP_MODE_INTERCEPT_FE))
   2.433 @@ -1063,7 +1040,7 @@ static int blktap_read_ufe_ring(int idx)
   2.434  				>> PAGE_SHIFT;
   2.435  			map[offset] = NULL;
   2.436  		}
   2.437 -		fast_flush_area(pending_req, pending_idx, usr_idx, idx);
   2.438 +		fast_flush_area(pending_req, pending_idx, usr_idx, info->minor);
   2.439  		make_response(blkif, pending_req->id, resp->operation,
   2.440  			      resp->status);
   2.441  		info->idx_map[usr_idx] = INVALID_REQ;
   2.442 @@ -1416,7 +1393,8 @@ static int __init blkif_init(void)
   2.443  	/*Create the blktap devices, but do not map memory or waitqueue*/
   2.444  	for(i = 0; i < MAX_TAP_DEV; i++) translate_domid[i].domid = 0xFFFF;
   2.445  
   2.446 -	ret = register_chrdev(BLKTAP_DEV_MAJOR,"blktap",&blktap_fops);
   2.447 +	/* Dynamically allocate a major for this device */
   2.448 +	ret = register_chrdev(0, "blktap", &blktap_fops);
   2.449  	blktap_dir = devfs_mk_dir(NULL, "xen", 0, NULL);
   2.450  
   2.451  	if ( (ret < 0)||(blktap_dir < 0) ) {
   2.452 @@ -1424,22 +1402,44 @@ static int __init blkif_init(void)
   2.453  		return -ENOMEM;
   2.454  	}	
   2.455  	
   2.456 +	blktap_major = ret;
   2.457 +
   2.458  	for(i = 0; i < MAX_TAP_DEV; i++ ) {
   2.459  		info = tapfds[i] = kzalloc(sizeof(tap_blkif_t),GFP_KERNEL);
   2.460 -		if(tapfds[i] == NULL) return -ENOMEM;
   2.461 +		if(tapfds[i] == NULL)
   2.462 +			return -ENOMEM;
   2.463  		info->minor = i;
   2.464  		info->pid = 0;
   2.465  		info->blkif = NULL;
   2.466  
   2.467 -		ret = devfs_mk_cdev(MKDEV(BLKTAP_DEV_MAJOR, i),
   2.468 +		ret = devfs_mk_cdev(MKDEV(blktap_major, i),
   2.469  			S_IFCHR|S_IRUGO|S_IWUSR, "xen/blktap%d", i);
   2.470  
   2.471 -		if(ret != 0) return -ENOMEM;
   2.472 +		if(ret != 0)
   2.473 +			return -ENOMEM;
   2.474  		info->dev_pending = info->dev_inuse = 0;
   2.475  
   2.476  		DPRINTK("Created misc_dev [/dev/xen/blktap%d]\n",i);
   2.477  	}
   2.478  	
   2.479 +	/* Make sure the xen class exists */
   2.480 +	if (!setup_xen_class()) {
   2.481 +		/*
   2.482 +		 * This will allow udev to create the blktap ctrl device.
   2.483 +		 * We only want to create blktap0 first.  We don't want
   2.484 +		 * to flood the sysfs system with needless blktap devices.
   2.485 +		 * We only create the device when a request of a new device is
   2.486 +		 * made.
   2.487 +		 */
   2.488 +		class_device_create(xen_class, NULL,
   2.489 +				    MKDEV(blktap_major, 0), NULL,
   2.490 +				    "blktap0");
   2.491 +		tapfds[0]->sysfs_set = 1;
   2.492 +	} else {
   2.493 +		/* this is bad, but not fatal */
   2.494 +		WPRINTK("blktap: sysfs xen_class not created\n");
   2.495 +	}
   2.496 +
   2.497  	DPRINTK("Blktap device successfully created\n");
   2.498  
   2.499  	return 0;
     3.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/xenbus.c	Sun Oct 01 11:39:41 2006 -0600
     3.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/xenbus.c	Sun Oct 01 19:10:18 2006 -0600
     3.3 @@ -273,7 +273,6 @@ static void tap_frontend_changed(struct 
     3.4  			kthread_stop(be->blkif->xenblkd);
     3.5  			be->blkif->xenblkd = NULL;
     3.6  		}
     3.7 -		tap_blkif_unmap(be->blkif);
     3.8  		xenbus_switch_state(dev, XenbusStateClosing);
     3.9  		break;
    3.10  
     4.1 --- a/linux-2.6-xen-sparse/drivers/xen/evtchn/evtchn.c	Sun Oct 01 11:39:41 2006 -0600
     4.2 +++ b/linux-2.6-xen-sparse/drivers/xen/evtchn/evtchn.c	Sun Oct 01 19:10:18 2006 -0600
     4.3 @@ -419,10 +419,9 @@ static struct file_operations evtchn_fop
     4.4  };
     4.5  
     4.6  static struct miscdevice evtchn_miscdev = {
     4.7 -	.minor        = EVTCHN_MINOR,
     4.8 +	.minor        = MISC_DYNAMIC_MINOR,
     4.9  	.name         = "evtchn",
    4.10  	.fops         = &evtchn_fops,
    4.11 -	.devfs_name   = "misc/evtchn",
    4.12  };
    4.13  
    4.14  static int __init evtchn_init(void)
     5.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/loopback.c	Sun Oct 01 11:39:41 2006 -0600
     5.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/loopback.c	Sun Oct 01 19:10:18 2006 -0600
     5.3 @@ -53,8 +53,10 @@
     5.4  #include <linux/skbuff.h>
     5.5  #include <linux/ethtool.h>
     5.6  #include <net/dst.h>
     5.7 +#include <net/xfrm.h>		/* secpath_reset() */
     5.8 +#include <asm/hypervisor.h>	/* is_initial_xendomain() */
     5.9  
    5.10 -static int nloopbacks = 8;
    5.11 +static int nloopbacks = -1;
    5.12  module_param(nloopbacks, int, 0);
    5.13  MODULE_PARM_DESC(nloopbacks, "Number of netback-loopback devices to create");
    5.14  
    5.15 @@ -77,10 +79,60 @@ static int loopback_close(struct net_dev
    5.16  	return 0;
    5.17  }
    5.18  
    5.19 +#ifdef CONFIG_X86
    5.20 +static int is_foreign(unsigned long pfn)
    5.21 +{
    5.22 +	/* NB. Play it safe for auto-translation mode. */
    5.23 +	return (xen_feature(XENFEAT_auto_translated_physmap) ||
    5.24 +		(phys_to_machine_mapping[pfn] & FOREIGN_FRAME_BIT));
    5.25 +}
    5.26 +#else
    5.27 +/* How to detect a foreign mapping? Play it safe. */
    5.28 +#define is_foreign(pfn)	(1)
    5.29 +#endif
    5.30 +
    5.31 +static int skb_remove_foreign_references(struct sk_buff *skb)
    5.32 +{
    5.33 +	struct page *page;
    5.34 +	unsigned long pfn;
    5.35 +	int i, off;
    5.36 +	char *vaddr;
    5.37 +
    5.38 +	BUG_ON(skb_shinfo(skb)->frag_list);
    5.39 +
    5.40 +	for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
    5.41 +		pfn = page_to_pfn(skb_shinfo(skb)->frags[i].page);
    5.42 +		if (!is_foreign(pfn))
    5.43 +			continue;
    5.44 +		
    5.45 +		page = alloc_page(GFP_ATOMIC | __GFP_NOWARN);
    5.46 +		if (unlikely(!page))
    5.47 +			return 0;
    5.48 +
    5.49 +		vaddr = kmap_skb_frag(&skb_shinfo(skb)->frags[i]);
    5.50 +		off = skb_shinfo(skb)->frags[i].page_offset;
    5.51 +		memcpy(page_address(page) + off,
    5.52 +		       vaddr + off,
    5.53 +		       skb_shinfo(skb)->frags[i].size);
    5.54 +		kunmap_skb_frag(vaddr);
    5.55 +
    5.56 +		put_page(skb_shinfo(skb)->frags[i].page);
    5.57 +		skb_shinfo(skb)->frags[i].page = page;
    5.58 +	}
    5.59 +
    5.60 +	return 1;
    5.61 +}
    5.62 +
    5.63  static int loopback_start_xmit(struct sk_buff *skb, struct net_device *dev)
    5.64  {
    5.65  	struct net_private *np = netdev_priv(dev);
    5.66  
    5.67 +	if (!skb_remove_foreign_references(skb)) {
    5.68 +		np->stats.tx_dropped++;
    5.69 +		dev_kfree_skb(skb);
    5.70 +		return 0;
    5.71 +	}
    5.72 +
    5.73  	dst_release(skb->dst);
    5.74  	skb->dst = NULL;
    5.75  
    5.76 @@ -110,6 +162,11 @@ static int loopback_start_xmit(struct sk
    5.77  	skb->protocol = eth_type_trans(skb, dev);
    5.78  	skb->dev      = dev;
    5.79  	dev->last_rx  = jiffies;
    5.80 +
    5.81 +	/* Flush netfilter context: rx'ed skbuffs not expected to have any. */
    5.82 +	nf_reset(skb);
    5.83 +	secpath_reset(skb);
    5.84 +
    5.85  	netif_rx(skb);
    5.86  
    5.87  	return 0;
    5.88 @@ -239,6 +296,9 @@ static int __init loopback_init(void)
    5.89  {
    5.90  	int i, err = 0;
    5.91  
    5.92 +	if (nloopbacks == -1)
    5.93 +		nloopbacks = is_initial_xendomain() ? 4 : 0;
    5.94 +
    5.95  	for (i = 0; i < nloopbacks; i++)
    5.96  		if ((err = make_loopback(i)) != 0)
    5.97  			break;
     6.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c	Sun Oct 01 11:39:41 2006 -0600
     6.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c	Sun Oct 01 19:10:18 2006 -0600
     6.3 @@ -217,7 +217,7 @@ static struct sk_buff *netbk_copy_skb(st
     6.4  		copy = len >= PAGE_SIZE ? PAGE_SIZE : len;
     6.5  		zero = len >= PAGE_SIZE ? 0 : __GFP_ZERO;
     6.6  
     6.7 -		page = alloc_page(GFP_ATOMIC | zero);
     6.8 +		page = alloc_page(GFP_ATOMIC | __GFP_NOWARN | zero);
     6.9  		if (unlikely(!page))
    6.10  			goto err_free;
    6.11  
     7.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c	Sun Oct 01 11:39:41 2006 -0600
     7.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c	Sun Oct 01 19:10:18 2006 -0600
     7.3 @@ -322,6 +322,20 @@ static void otherend_changed(struct xenb
     7.4  	DPRINTK("state is %d (%s), %s, %s", state, xenbus_strstate(state),
     7.5  		dev->otherend_watch.node, vec[XS_WATCH_PATH]);
     7.6  
     7.7 +	/*
     7.8 +	 * Ignore xenbus transitions during shutdown. This prevents us doing
     7.9 +	 * work that can fail e.g., when the rootfs is gone.
    7.10 +	 */
    7.11 +	if (system_state > SYSTEM_RUNNING) {
    7.12 +		struct xen_bus_type *bus = bus;
    7.13 +		bus = container_of(dev->dev.bus, struct xen_bus_type, bus);
    7.14 +		/* If we're frontend, drive the state machine to Closed. */
    7.15 +		/* This should cause the backend to release our resources. */
    7.16 +		if ((bus == &xenbus_frontend) && (state == XenbusStateClosing))
    7.17 +			xenbus_frontend_closed(dev);
    7.18 +		return;
    7.19 +	}
    7.20 +
    7.21  	if (drv->otherend_changed)
    7.22  		drv->otherend_changed(dev, state);
    7.23  }
     8.1 --- a/linux-2.6-xen-sparse/include/xen/public/evtchn.h	Sun Oct 01 11:39:41 2006 -0600
     8.2 +++ b/linux-2.6-xen-sparse/include/xen/public/evtchn.h	Sun Oct 01 19:10:18 2006 -0600
     8.3 @@ -33,9 +33,6 @@
     8.4  #ifndef __LINUX_PUBLIC_EVTCHN_H__
     8.5  #define __LINUX_PUBLIC_EVTCHN_H__
     8.6  
     8.7 -/* /dev/xen/evtchn resides at device number major=10, minor=201 */
     8.8 -#define EVTCHN_MINOR 201
     8.9 -
    8.10  /*
    8.11   * Bind a fresh port to VIRQ @virq.
    8.12   * Return allocated port.
     9.1 --- a/tools/blktap/drivers/Makefile	Sun Oct 01 11:39:41 2006 -0600
     9.2 +++ b/tools/blktap/drivers/Makefile	Sun Oct 01 19:10:18 2006 -0600
     9.3 @@ -28,7 +28,7 @@ DEPS     = .*.d
     9.4  THREADLIB := -lpthread -lz
     9.5  LIBS      := -L. -L.. -L../lib
     9.6  LIBS      += -L$(XEN_LIBXC)
     9.7 -LIBS      += -lblktap
     9.8 +LIBS      += -lblktap -lxenctrl
     9.9  LIBS      += -lcrypto
    9.10  LIBS      += -lz
    9.11  LIBS      += -L$(XEN_XENSTORE) -lxenstore
    10.1 --- a/tools/blktap/drivers/blktapctrl.c	Sun Oct 01 11:39:41 2006 -0600
    10.2 +++ b/tools/blktap/drivers/blktapctrl.c	Sun Oct 01 19:10:18 2006 -0600
    10.3 @@ -67,6 +67,8 @@ int run = 1;
    10.4  int max_timeout = MAX_TIMEOUT;
    10.5  int ctlfd = 0;
    10.6  
    10.7 +int blktap_major;
    10.8 +
    10.9  static int open_ctrl_socket(char *devname);
   10.10  static int write_msg(int fd, int msgtype, void *ptr, void *ptr2);
   10.11  static int read_msg(int fd, int msgtype, void *ptr);
   10.12 @@ -108,7 +110,18 @@ static void make_blktap_dev(char *devnam
   10.13  		if (mknod(devname, S_IFCHR|0600,
   10.14                  	makedev(major, minor)) == 0)
   10.15  			DPRINTF("Created %s device\n",devname);
   10.16 -	} else DPRINTF("%s device already exists\n",devname);
   10.17 +	} else {
   10.18 +		DPRINTF("%s device already exists\n",devname);
   10.19 +		/* it already exists, but is it the same major number */
   10.20 +		if (((st.st_rdev>>8) & 0xff) != major) {
   10.21 +			DPRINTF("%s has old major %d\n",
   10.22 +				devname,
   10.23 +				(unsigned int)((st.st_rdev >> 8) & 0xff));
   10.24 +			/* only try again if we succed in deleting it */
   10.25 +			if (!unlink(devname))
   10.26 +				make_blktap_dev(devname, major, minor);
   10.27 +		}
   10.28 +	}
   10.29  }
   10.30  
   10.31  static int get_new_dev(int *major, int *minor, blkif_t *blkif)
   10.32 @@ -644,9 +657,12 @@ int main(int argc, char *argv[])
   10.33  	register_new_devmap_hook(map_new_blktapctrl);
   10.34  	register_new_unmap_hook(unmap_blktapctrl);
   10.35  
   10.36 -	/*Attach to blktap0 */	
   10.37 +	/* Attach to blktap0 */
   10.38  	asprintf(&devname,"%s/%s0", BLKTAP_DEV_DIR, BLKTAP_DEV_NAME);
   10.39 -	make_blktap_dev(devname,254,0);
   10.40 +	if ((ret = xc_find_device_number("blktap0")) < 0)
   10.41 +		goto open_failed;
   10.42 +	blktap_major = major(ret);
   10.43 +	make_blktap_dev(devname,blktap_major,0);
   10.44  	ctlfd = open(devname, O_RDWR);
   10.45  	if (ctlfd == -1) {
   10.46  		DPRINTF("blktap0 open failed\n");
    11.1 --- a/tools/blktap/drivers/tapdisk.c	Sun Oct 01 11:39:41 2006 -0600
    11.2 +++ b/tools/blktap/drivers/tapdisk.c	Sun Oct 01 19:10:18 2006 -0600
    11.3 @@ -271,7 +271,6 @@ static int read_msg(char *buf)
    11.4  	int length, len, msglen, tap_fd, *io_fd;
    11.5  	char *ptr, *path;
    11.6  	image_t *img;
    11.7 -	struct timeval timeout;
    11.8  	msg_hdr_t *msg;
    11.9  	msg_newdev_t *msg_dev;
   11.10  	msg_pid_t *msg_pid;
   11.11 @@ -579,8 +578,7 @@ int main(int argc, char *argv[])
   11.12  {
   11.13  	int len, msglen, ret;
   11.14  	char *p, *buf;
   11.15 -	fd_set readfds, writefds;
   11.16 -	struct timeval timeout;
   11.17 +	fd_set readfds, writefds;	
   11.18  	fd_list_entry_t *ptr;
   11.19  	struct tap_disk *drv;
   11.20  	struct td_state *s;
   11.21 @@ -622,12 +620,9 @@ int main(int argc, char *argv[])
   11.22  		/*Set all tap fds*/
   11.23  		LOCAL_FD_SET(&readfds);
   11.24  
   11.25 -		timeout.tv_sec = 0; 
   11.26 -		timeout.tv_usec = 1000; 
   11.27 -
   11.28  		/*Wait for incoming messages*/
   11.29  		ret = select(maxfds + 1, &readfds, (fd_set *) 0, 
   11.30 -			     (fd_set *) 0, &timeout);
   11.31 +			     (fd_set *) 0, NULL);
   11.32  
   11.33  		if (ret > 0) 
   11.34  		{
    12.1 --- a/tools/blktap/lib/blktaplib.h	Sun Oct 01 11:39:41 2006 -0600
    12.2 +++ b/tools/blktap/lib/blktaplib.h	Sun Oct 01 19:10:18 2006 -0600
    12.3 @@ -80,9 +80,10 @@ static inline int BLKTAP_MODE_VALID(unsi
    12.4  #define MAX_PENDING_REQS 64
    12.5  #define BLKTAP_DEV_DIR   "/dev/xen"
    12.6  #define BLKTAP_DEV_NAME  "blktap"
    12.7 -#define BLKTAP_DEV_MAJOR 254
    12.8  #define BLKTAP_DEV_MINOR 0
    12.9  
   12.10 +extern int blktap_major;
   12.11 +
   12.12  #define BLKTAP_RING_PAGES       1 /* Front */
   12.13  #define BLKTAP_MMAP_REGION_SIZE (BLKTAP_RING_PAGES + MMAP_PAGES)
   12.14  
    13.1 --- a/tools/debugger/pdb/Domain.ml	Sun Oct 01 11:39:41 2006 -0600
    13.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.3 @@ -1,61 +0,0 @@
    13.4 -(** Domain.ml
    13.5 - *
    13.6 - *  domain context implementation
    13.7 - *
    13.8 - *  @author copyright (c) 2005 alex ho
    13.9 - *  @see <www.cl.cam.ac.uk/netos/pdb> pervasive debugger
   13.10 - *  @version 1
   13.11 - *)
   13.12 -
   13.13 -open Int32
   13.14 -open Intel
   13.15 -
   13.16 -type context_t =
   13.17 -{
   13.18 -  mutable domain : int;
   13.19 -  mutable vcpu : int
   13.20 -}
   13.21 -
   13.22 -let default_context = { domain = 0; vcpu = 0 }
   13.23 -
   13.24 -let new_context new_dom new_vcpu = {domain = new_dom; vcpu = new_vcpu}
   13.25 -
   13.26 -let set_domain ctx value =
   13.27 -  ctx.domain <- value
   13.28 -
   13.29 -let set_vcpu ctx value =
   13.30 -  ctx.vcpu <- value
   13.31 -
   13.32 -let get_domain ctx =
   13.33 -  ctx.domain
   13.34 -
   13.35 -let get_vcpu ctx =
   13.36 -  ctx.vcpu
   13.37 -
   13.38 -let string_of_context ctx =
   13.39 -      Printf.sprintf "{domain} domain: %d, vcpu: %d"
   13.40 -                      ctx.domain  ctx.vcpu
   13.41 -
   13.42 -external read_register : context_t -> int -> int32 = "dom_read_register"
   13.43 -external read_registers : context_t -> registers = "dom_read_registers"
   13.44 -external write_register : context_t -> register -> int32 -> unit =
   13.45 -  "dom_write_register"
   13.46 -external read_memory : context_t -> int32 -> int -> int list = 
   13.47 -  "dom_read_memory"
   13.48 -external write_memory : context_t -> int32 -> int list -> unit = 
   13.49 -  "dom_write_memory"
   13.50 -	
   13.51 -external continue : context_t -> unit = "dom_continue_target"
   13.52 -external step : context_t -> unit = "dom_step_target"
   13.53 -
   13.54 -external insert_memory_breakpoint : context_t -> int32 -> int -> unit = 
   13.55 -  "dom_insert_memory_breakpoint"
   13.56 -external remove_memory_breakpoint : context_t -> int32 -> int -> unit = 
   13.57 -  "dom_remove_memory_breakpoint"
   13.58 -
   13.59 -external attach_debugger : int -> int -> unit = "dom_attach_debugger"
   13.60 -external detach_debugger : int -> int -> unit = "dom_detach_debugger"
   13.61 -external pause_target : int -> unit = "dom_pause_target"
   13.62 -
   13.63 -let pause ctx =
   13.64 -  pause_target ctx.domain
    14.1 --- a/tools/debugger/pdb/Domain.mli	Sun Oct 01 11:39:41 2006 -0600
    14.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.3 @@ -1,39 +0,0 @@
    14.4 -(** Domain.mli
    14.5 - *
    14.6 - *  domain context interface
    14.7 - *
    14.8 - *  @author copyright (c) 2005 alex ho
    14.9 - *  @see <www.cl.cam.ac.uk/netos/pdb> pervasive debugger
   14.10 - *  @version 1
   14.11 - *)
   14.12 -
   14.13 -open Int32
   14.14 -open Intel
   14.15 -
   14.16 -type context_t
   14.17 -
   14.18 -val default_context : context_t
   14.19 -val new_context : int -> int -> context_t 
   14.20 -
   14.21 -val set_domain : context_t -> int -> unit
   14.22 -val get_domain : context_t -> int
   14.23 -val set_vcpu : context_t -> int -> unit
   14.24 -val get_vcpu : context_t -> int
   14.25 -
   14.26 -val string_of_context : context_t -> string
   14.27 -
   14.28 -val read_register : context_t -> int -> int32
   14.29 -val read_registers : context_t -> registers
   14.30 -val write_register : context_t -> register -> int32 -> unit
   14.31 -val read_memory : context_t -> int32 -> int -> int list
   14.32 -val write_memory : context_t -> int32 -> int list -> unit
   14.33 -	
   14.34 -val continue : context_t -> unit
   14.35 -val step : context_t -> unit
   14.36 -
   14.37 -val insert_memory_breakpoint : context_t -> int32 -> int -> unit
   14.38 -val remove_memory_breakpoint : context_t -> int32 -> int -> unit
   14.39 -
   14.40 -val attach_debugger : int -> int -> unit
   14.41 -val detach_debugger : int -> int -> unit
   14.42 -val pause : context_t -> unit
    15.1 --- a/tools/debugger/pdb/Intel.ml	Sun Oct 01 11:39:41 2006 -0600
    15.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.3 @@ -1,66 +0,0 @@
    15.4 -(** Intel.ml
    15.5 - *
    15.6 - *  various sundry Intel x86 definitions
    15.7 - *
    15.8 - *  @author copyright (c) 2005 alex ho
    15.9 - *  @see <www.cl.cam.ac.uk/netos/pdb> pervasive debugger
   15.10 - *  @version 1
   15.11 - *)
   15.12 -
   15.13 -
   15.14 -type register =
   15.15 -  | EAX
   15.16 -  | ECX
   15.17 -  | EDX
   15.18 -  | EBX
   15.19 -  | ESP
   15.20 -  | EBP
   15.21 -  | ESI
   15.22 -  | EDI
   15.23 -  | EIP
   15.24 -  | EFL
   15.25 -  | CS
   15.26 -  | SS
   15.27 -  | DS
   15.28 -  | ES
   15.29 -  | FS
   15.30 -  | GS
   15.31 -
   15.32 -type registers =
   15.33 -    { eax : int32;
   15.34 -      ecx : int32;
   15.35 -      edx : int32;
   15.36 -      ebx : int32;
   15.37 -      esp : int32;
   15.38 -      ebp : int32;
   15.39 -      esi : int32;
   15.40 -      edi : int32;
   15.41 -      eip : int32;
   15.42 -      efl : int32;
   15.43 -      cs  : int32;
   15.44 -      ss  : int32;
   15.45 -      ds  : int32;
   15.46 -      es  : int32;
   15.47 -      fs  : int32;
   15.48 -      gs  : int32
   15.49 -    }
   15.50 -
   15.51 -let null_registers =
   15.52 -    { eax = 0l;
   15.53 -      ecx = 0l;
   15.54 -      edx = 0l;
   15.55 -      ebx = 0l;
   15.56 -      esp = 0l;
   15.57 -      ebp = 0l;
   15.58 -      esi = 0l;
   15.59 -      edi = 0l;
   15.60 -      eip = 0l;
   15.61 -      efl = 0l;
   15.62 -      cs  = 0l;
   15.63 -      ss  = 0l;
   15.64 -      ds  = 0l;
   15.65 -      es  = 0l;
   15.66 -      fs  = 0l;
   15.67 -      gs  = 0l
   15.68 -    }
   15.69 -
    16.1 --- a/tools/debugger/pdb/Makefile	Sun Oct 01 11:39:41 2006 -0600
    16.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.3 @@ -1,57 +0,0 @@
    16.4 -OCAMLMAKEFILE = OCamlMakefile
    16.5 -
    16.6 -XEN_ROOT    = ../../..
    16.7 -include $(XEN_ROOT)/tools/Rules.mk
    16.8 -
    16.9 -# overwrite LDFLAGS from xen/tool/Rules.mk
   16.10 -# otherwise, ocamlmktop gets confused.
   16.11 -LDFLAGS     =
   16.12 -
   16.13 -# force ocaml 3.08
   16.14 -OCAML_ROOT  = /usr/local
   16.15 -OCAMLC      = $(OCAML_ROOT)/bin/ocamlc
   16.16 -OCAMLMKTOP  = $(OCAML_ROOT)/bin/ocamlmktop
   16.17 -OCAMLLIBPATH= $(OCAML_ROOT)/lib/ocaml
   16.18 -
   16.19 -INCLUDES   += -I $(XEN_XC)
   16.20 -INCLUDES   += -I $(XEN_LIBXC)
   16.21 -INCLUDES   += -I ../libxendebug
   16.22 -INCLUDES   += -I ./linux-2.6-module
   16.23 -INCLUDES   += -I $(OCAML_ROOT)/lib/ocaml
   16.24 -
   16.25 -CFLAGS     += $(INCLUDES)
   16.26 -CFLAGS     += -Werror
   16.27 -CFLAGS     += -g
   16.28 -
   16.29 -CLIBS      += xc
   16.30 -CLIBS      += xendebug
   16.31 -
   16.32 -LIBDIRS    += $(XEN_LIBXC)
   16.33 -LIBDIRS    += ../libxendebug
   16.34 -
   16.35 -LIBS       += unix str
   16.36 -
   16.37 -# bc = byte-code, dc = debug byte-code
   16.38 -# patches = patch linux domU source code
   16.39 -.PHONY: all 
   16.40 -all : dc
   16.41 -
   16.42 -SOURCES    += pdb_caml_xc.c 
   16.43 -SOURCES    += pdb_caml_domain.c pdb_caml_process.c
   16.44 -SOURCES    += pdb_caml_evtchn.c pdb_caml_xcs.c pdb_xen.c
   16.45 -SOURCES    += Util.ml Intel.ml 
   16.46 -SOURCES    += evtchn.ml evtchn.mli
   16.47 -SOURCES    += xcs.ml xcs.mli
   16.48 -SOURCES    += Xen_domain.ml Xen_domain.mli
   16.49 -SOURCES    += Domain.ml  Process.ml
   16.50 -SOURCES    += Domain.mli Process.mli
   16.51 -SOURCES    += PDB.ml debugger.ml server.ml
   16.52 -
   16.53 -RESULT      = pdb
   16.54 -
   16.55 -include $(OCAMLMAKEFILE)
   16.56 -
   16.57 -PATCHDIR    = ./linux-2.6-patches
   16.58 -.PHONY: patches 
   16.59 -patches :
   16.60 -	make -C $(PATCHDIR) patches
    17.1 --- a/tools/debugger/pdb/OCamlMakefile	Sun Oct 01 11:39:41 2006 -0600
    17.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.3 @@ -1,1149 +0,0 @@
    17.4 -###########################################################################
    17.5 -#                              OCamlMakefile
    17.6 -#                  Copyright (C) 1999-2004  Markus Mottl
    17.7 -#
    17.8 -#                             For updates see:
    17.9 -#                http://www.oefai.at/~markus/ocaml_sources
   17.10 -#
   17.11 -#        $Id: OCamlMakefile,v 1.1 2005/05/19 09:30:48 root Exp $
   17.12 -#
   17.13 -###########################################################################
   17.14 -
   17.15 -# Modified by damien for .glade.ml compilation
   17.16 -
   17.17 -# Set these variables to the names of the sources to be processed and
   17.18 -# the result variable. Order matters during linkage!
   17.19 -
   17.20 -ifndef SOURCES
   17.21 -  SOURCES := foo.ml
   17.22 -endif
   17.23 -export SOURCES
   17.24 -
   17.25 -ifndef RES_CLIB_SUF
   17.26 -  RES_CLIB_SUF := _stubs
   17.27 -endif
   17.28 -export RES_CLIB_SUF
   17.29 -
   17.30 -ifndef RESULT
   17.31 -  RESULT := foo
   17.32 -endif
   17.33 -export RESULT
   17.34 -
   17.35 -export LIB_PACK_NAME
   17.36 -
   17.37 -ifndef DOC_FILES
   17.38 -  DOC_FILES := $(filter %.mli, $(SOURCES))
   17.39 -endif
   17.40 -export DOC_FILES
   17.41 -
   17.42 -export BCSUFFIX
   17.43 -export NCSUFFIX
   17.44 -
   17.45 -ifndef TOPSUFFIX
   17.46 -  TOPSUFFIX := .top
   17.47 -endif
   17.48 -export TOPSUFFIX
   17.49 -
   17.50 -# Eventually set include- and library-paths, libraries to link,
   17.51 -# additional compilation-, link- and ocamlyacc-flags
   17.52 -# Path- and library information needs not be written with "-I" and such...
   17.53 -# Define THREADS if you need it, otherwise leave it unset (same for
   17.54 -# USE_CAMLP4)!
   17.55 -
   17.56 -export THREADS
   17.57 -export VMTHREADS
   17.58 -export ANNOTATE
   17.59 -export USE_CAMLP4
   17.60 -
   17.61 -export INCDIRS
   17.62 -export LIBDIRS
   17.63 -export EXTLIBDIRS
   17.64 -export RESULTDEPS
   17.65 -export OCAML_DEFAULT_DIRS
   17.66 -
   17.67 -export LIBS
   17.68 -export CLIBS
   17.69 -
   17.70 -export OCAMLFLAGS
   17.71 -export OCAMLNCFLAGS
   17.72 -export OCAMLBCFLAGS
   17.73 -
   17.74 -export OCAMLLDFLAGS
   17.75 -export OCAMLNLDFLAGS
   17.76 -export OCAMLBLDFLAGS
   17.77 -
   17.78 -ifndef OCAMLCPFLAGS
   17.79 -  OCAMLCPFLAGS := a
   17.80 -endif
   17.81 -
   17.82 -export OCAMLCPFLAGS
   17.83 -
   17.84 -export PPFLAGS
   17.85 -
   17.86 -export YFLAGS
   17.87 -export IDLFLAGS
   17.88 -
   17.89 -export OCAMLDOCFLAGS
   17.90 -
   17.91 -export OCAMLFIND_INSTFLAGS
   17.92 -
   17.93 -export DVIPSFLAGS
   17.94 -
   17.95 -export STATIC
   17.96 -
   17.97 -# Add a list of optional trash files that should be deleted by "make clean"
   17.98 -export TRASH
   17.99 -
  17.100 -####################  variables depending on your OCaml-installation
  17.101 -
  17.102 -ifdef MINGW
  17.103 -  export MINGW
  17.104 -  WIN32   := 1
  17.105 -  CFLAGS_WIN32 := -mno-cygwin
  17.106 -endif
  17.107 -ifdef MSVC
  17.108 -  export MSVC
  17.109 -  WIN32   := 1
  17.110 -  ifndef STATIC
  17.111 -    CPPFLAGS_WIN32 := -DCAML_DLL
  17.112 -  endif
  17.113 -  CFLAGS_WIN32 += -nologo
  17.114 -  EXT_OBJ := obj
  17.115 -  EXT_LIB := lib
  17.116 -  ifeq ($(CC),gcc)
  17.117 -    # work around GNU Make default value
  17.118 -    ifdef THREADS
  17.119 -      CC := cl -MT
  17.120 -    else
  17.121 -      CC := cl
  17.122 -    endif
  17.123 -  endif
  17.124 -  ifeq ($(CXX),g++)
  17.125 -    # work around GNU Make default value
  17.126 -    CXX := $(CC)
  17.127 -  endif
  17.128 -  CFLAG_O := -Fo
  17.129 -endif
  17.130 -ifdef WIN32
  17.131 -  EXT_CXX := cpp
  17.132 -  EXE     := .exe
  17.133 -endif
  17.134 -
  17.135 -ifndef EXT_OBJ
  17.136 -  EXT_OBJ := o
  17.137 -endif
  17.138 -ifndef EXT_LIB
  17.139 -  EXT_LIB := a
  17.140 -endif
  17.141 -ifndef EXT_CXX
  17.142 -  EXT_CXX := cc
  17.143 -endif
  17.144 -ifndef EXE
  17.145 -  EXE := # empty
  17.146 -endif
  17.147 -ifndef CFLAG_O
  17.148 -  CFLAG_O := -o # do not delete this comment (preserves trailing whitespace)!
  17.149 -endif
  17.150 -
  17.151 -export CC
  17.152 -export CXX
  17.153 -export CFLAGS
  17.154 -export CXXFLAGS
  17.155 -export LDFLAGS
  17.156 -export CPPFLAGS
  17.157 -
  17.158 -ifndef RPATH_FLAG
  17.159 -  RPATH_FLAG := -R
  17.160 -endif
  17.161 -export RPATH_FLAG
  17.162 -
  17.163 -ifndef MSVC
  17.164 -ifndef PIC_CFLAGS
  17.165 -  PIC_CFLAGS := -fPIC
  17.166 -endif
  17.167 -ifndef PIC_CPPFLAGS
  17.168 -  PIC_CPPFLAGS := -DPIC
  17.169 -endif
  17.170 -endif
  17.171 -
  17.172 -export PIC_CFLAGS
  17.173 -export PIC_CPPFLAGS
  17.174 -
  17.175 -BCRESULT  := $(addsuffix $(BCSUFFIX), $(RESULT))
  17.176 -NCRESULT  := $(addsuffix $(NCSUFFIX), $(RESULT))
  17.177 -TOPRESULT := $(addsuffix $(TOPSUFFIX), $(RESULT))
  17.178 -
  17.179 -ifndef OCAMLFIND
  17.180 -  OCAMLFIND := ocamlfind
  17.181 -endif
  17.182 -export OCAMLFIND
  17.183 -
  17.184 -ifndef OCAMLC
  17.185 -  OCAMLC := ocamlc
  17.186 -endif
  17.187 -export OCAMLC
  17.188 -
  17.189 -ifndef OCAMLOPT
  17.190 -  OCAMLOPT := ocamlopt
  17.191 -endif
  17.192 -export OCAMLOPT
  17.193 -
  17.194 -ifndef OCAMLMKTOP
  17.195 -  OCAMLMKTOP := ocamlmktop
  17.196 -endif
  17.197 -export OCAMLMKTOP
  17.198 -
  17.199 -ifndef OCAMLCP
  17.200 -  OCAMLCP := ocamlcp
  17.201 -endif
  17.202 -export OCAMLCP
  17.203 -
  17.204 -ifndef OCAMLDEP
  17.205 -  OCAMLDEP := ocamldep
  17.206 -endif
  17.207 -export OCAMLDEP
  17.208 -
  17.209 -ifndef OCAMLLEX
  17.210 -  OCAMLLEX := ocamllex
  17.211 -endif
  17.212 -export OCAMLLEX
  17.213 -
  17.214 -ifndef OCAMLYACC
  17.215 -  OCAMLYACC := ocamlyacc
  17.216 -endif
  17.217 -export OCAMLYACC
  17.218 -
  17.219 -ifndef OCAMLMKLIB
  17.220 -  OCAMLMKLIB := ocamlmklib
  17.221 -endif
  17.222 -export OCAMLMKLIB
  17.223 -
  17.224 -ifndef OCAML_GLADECC
  17.225 -  OCAML_GLADECC := lablgladecc2
  17.226 -endif
  17.227 -export OCAML_GLADECC
  17.228 -
  17.229 -ifndef OCAML_GLADECC_FLAGS
  17.230 -  OCAML_GLADECC_FLAGS :=
  17.231 -endif
  17.232 -export OCAML_GLADECC_FLAGS
  17.233 -
  17.234 -ifndef CAMELEON_REPORT
  17.235 -  CAMELEON_REPORT := report
  17.236 -endif
  17.237 -export CAMELEON_REPORT
  17.238 -
  17.239 -ifndef CAMELEON_REPORT_FLAGS
  17.240 -  CAMELEON_REPORT_FLAGS :=
  17.241 -endif
  17.242 -export CAMELEON_REPORT_FLAGS
  17.243 -
  17.244 -ifndef CAMELEON_ZOGGY
  17.245 -  CAMELEON_ZOGGY := camlp4o pa_zog.cma pr_o.cmo
  17.246 -endif
  17.247 -export CAMELEON_ZOGGY
  17.248 -
  17.249 -ifndef CAMELEON_ZOGGY_FLAGS
  17.250 -  CAMELEON_ZOGGY_FLAGS :=
  17.251 -endif
  17.252 -export CAMELEON_ZOGGY_FLAGS
  17.253 -
  17.254 -ifndef OXRIDL
  17.255 -  OXRIDL := oxridl
  17.256 -endif
  17.257 -export OXRIDL
  17.258 -
  17.259 -ifndef CAMLIDL
  17.260 -  CAMLIDL := camlidl
  17.261 -endif
  17.262 -export CAMLIDL
  17.263 -
  17.264 -ifndef CAMLIDLDLL
  17.265 -  CAMLIDLDLL := camlidldll
  17.266 -endif
  17.267 -export CAMLIDLDLL
  17.268 -
  17.269 -ifndef NOIDLHEADER
  17.270 -  MAYBE_IDL_HEADER := -header
  17.271 -endif
  17.272 -export NOIDLHEADER
  17.273 -
  17.274 -export NO_CUSTOM
  17.275 -
  17.276 -ifndef CAMLP4
  17.277 -  CAMLP4 := camlp4
  17.278 -endif
  17.279 -export CAMLP4
  17.280 -
  17.281 -ifndef REAL_OCAMLFIND
  17.282 -  ifdef PACKS
  17.283 -    ifndef CREATE_LIB
  17.284 -      ifdef THREADS
  17.285 -	PACKS += threads
  17.286 -      endif
  17.287 -    endif
  17.288 -    empty :=
  17.289 -    space := $(empty) $(empty)
  17.290 -    comma := ,
  17.291 -    ifdef PREDS
  17.292 -      PRE_OCAML_FIND_PREDICATES := $(subst $(space),$(comma),$(PREDS))
  17.293 -      PRE_OCAML_FIND_PACKAGES := $(subst $(space),$(comma),$(PACKS))
  17.294 -      OCAML_FIND_PREDICATES := -predicates $(PRE_OCAML_FIND_PREDICATES)
  17.295 -  #    OCAML_DEP_PREDICATES := -syntax $(PRE_OCAML_FIND_PREDICATES)
  17.296 -      OCAML_FIND_PACKAGES := $(OCAML_FIND_PREDICATES) -package $(PRE_OCAML_FIND_PACKAGES)
  17.297 -      OCAML_DEP_PACKAGES := $(OCAML_DEP_PREDICATES) -package $(PRE_OCAML_FIND_PACKAGES)
  17.298 -    else
  17.299 -      OCAML_FIND_PACKAGES := -package $(subst $(space),$(comma),$(PACKS))
  17.300 -      OCAML_DEP_PACKAGES :=
  17.301 -    endif
  17.302 -    OCAML_FIND_LINKPKG := -linkpkg
  17.303 -    REAL_OCAMLFIND := $(OCAMLFIND)
  17.304 -  endif
  17.305 -endif
  17.306 -
  17.307 -export OCAML_FIND_PACKAGES
  17.308 -export OCAML_DEP_PACKAGES
  17.309 -export OCAML_FIND_LINKPKG
  17.310 -export REAL_OCAMLFIND
  17.311 -
  17.312 -ifndef OCAMLDOC
  17.313 -  OCAMLDOC := ocamldoc
  17.314 -endif
  17.315 -export OCAMLDOC
  17.316 -
  17.317 -ifndef LATEX
  17.318 -  LATEX := latex
  17.319 -endif
  17.320 -export LATEX
  17.321 -
  17.322 -ifndef DVIPS
  17.323 -  DVIPS := dvips
  17.324 -endif
  17.325 -export DVIPS
  17.326 -
  17.327 -ifndef PS2PDF
  17.328 -  PS2PDF := ps2pdf
  17.329 -endif
  17.330 -export PS2PDF
  17.331 -
  17.332 -ifndef OCAMLMAKEFILE
  17.333 -  OCAMLMAKEFILE := OCamlMakefile
  17.334 -endif
  17.335 -export OCAMLMAKEFILE
  17.336 -
  17.337 -ifndef OCAMLLIBPATH
  17.338 -  OCAMLLIBPATH := \
  17.339 -    $(shell $(OCAMLC) 2>/dev/null -where || echo /usr/local/lib/ocaml)
  17.340 -endif
  17.341 -export OCAMLLIBPATH
  17.342 -
  17.343 -ifndef OCAML_LIB_INSTALL
  17.344 -  OCAML_LIB_INSTALL := $(OCAMLLIBPATH)/contrib
  17.345 -endif
  17.346 -export OCAML_LIB_INSTALL
  17.347 -
  17.348 -###########################################################################
  17.349 -
  17.350 -####################  change following sections only if
  17.351 -####################    you know what you are doing!
  17.352 -
  17.353 -# delete target files when a build command fails
  17.354 -.PHONY: .DELETE_ON_ERROR
  17.355 -.DELETE_ON_ERROR:
  17.356 -
  17.357 -# for pedants using "--warn-undefined-variables"
  17.358 -export MAYBE_IDL
  17.359 -export REAL_RESULT
  17.360 -export CAMLIDLFLAGS
  17.361 -export THREAD_FLAG
  17.362 -export RES_CLIB
  17.363 -export MAKEDLL
  17.364 -export ANNOT_FLAG
  17.365 -export C_OXRIDL
  17.366 -export SUBPROJS
  17.367 -export CFLAGS_WIN32
  17.368 -export CPPFLAGS_WIN32
  17.369 -
  17.370 -INCFLAGS :=
  17.371 -
  17.372 -SHELL := /bin/sh
  17.373 -
  17.374 -MLDEPDIR := ._d
  17.375 -BCDIDIR  := ._bcdi
  17.376 -NCDIDIR  := ._ncdi
  17.377 -
  17.378 -FILTER_EXTNS := %.mli %.ml %.mll %.mly %.idl %.oxridl %.c %.$(EXT_CXX) %.rep %.zog %.glade
  17.379 -
  17.380 -FILTERED     := $(filter $(FILTER_EXTNS), $(SOURCES))
  17.381 -SOURCE_DIRS  := $(filter-out ./, $(sort $(dir $(FILTERED))))
  17.382 -
  17.383 -FILTERED_REP := $(filter %.rep, $(FILTERED))
  17.384 -DEP_REP      := $(FILTERED_REP:%.rep=$(MLDEPDIR)/%.d)
  17.385 -AUTO_REP     := $(FILTERED_REP:.rep=.ml)
  17.386 -
  17.387 -FILTERED_ZOG := $(filter %.zog, $(FILTERED))
  17.388 -DEP_ZOG      := $(FILTERED_ZOG:%.zog=$(MLDEPDIR)/%.d)
  17.389 -AUTO_ZOG     := $(FILTERED_ZOG:.zog=.ml)
  17.390 -
  17.391 -FILTERED_GLADE := $(filter %.glade, $(FILTERED))
  17.392 -DEP_GLADE      := $(FILTERED_GLADE:%.glade=$(MLDEPDIR)/%.d)
  17.393 -AUTO_GLADE     := $(FILTERED_GLADE:.glade=.ml)
  17.394 -
  17.395 -FILTERED_ML  := $(filter %.ml, $(FILTERED))
  17.396 -DEP_ML       := $(FILTERED_ML:%.ml=$(MLDEPDIR)/%.d)
  17.397 -
  17.398 -FILTERED_MLI := $(filter %.mli, $(FILTERED))
  17.399 -DEP_MLI      := $(FILTERED_MLI:.mli=.di)
  17.400 -
  17.401 -FILTERED_MLL := $(filter %.mll, $(FILTERED))
  17.402 -DEP_MLL      := $(FILTERED_MLL:%.mll=$(MLDEPDIR)/%.d)
  17.403 -AUTO_MLL     := $(FILTERED_MLL:.mll=.ml)
  17.404 -
  17.405 -FILTERED_MLY := $(filter %.mly, $(FILTERED))
  17.406 -DEP_MLY      := $(FILTERED_MLY:%.mly=$(MLDEPDIR)/%.d) $(FILTERED_MLY:.mly=.di)
  17.407 -AUTO_MLY     := $(FILTERED_MLY:.mly=.mli) $(FILTERED_MLY:.mly=.ml)
  17.408 -
  17.409 -FILTERED_IDL := $(filter %.idl, $(FILTERED))
  17.410 -DEP_IDL      := $(FILTERED_IDL:%.idl=$(MLDEPDIR)/%.d) $(FILTERED_IDL:.idl=.di)
  17.411 -C_IDL        := $(FILTERED_IDL:%.idl=%_stubs.c)
  17.412 -ifndef NOIDLHEADER
  17.413 - C_IDL += $(FILTERED_IDL:.idl=.h)
  17.414 -endif
  17.415 -OBJ_C_IDL    := $(FILTERED_IDL:%.idl=%_stubs.$(EXT_OBJ))
  17.416 -AUTO_IDL     := $(FILTERED_IDL:.idl=.mli) $(FILTERED_IDL:.idl=.ml) $(C_IDL)
  17.417 -
  17.418 -FILTERED_OXRIDL := $(filter %.oxridl, $(FILTERED))
  17.419 -DEP_OXRIDL      := $(FILTERED_OXRIDL:%.oxridl=$(MLDEPDIR)/%.d) $(FILTERED_OXRIDL:.oxridl=.di)
  17.420 -AUTO_OXRIDL     := $(FILTERED_OXRIDL:.oxridl=.mli) $(FILTERED_OXRIDL:.oxridl=.ml) $(C_OXRIDL)
  17.421 -
  17.422 -FILTERED_C_CXX := $(filter %.c %.$(EXT_CXX), $(FILTERED))
  17.423 -OBJ_C_CXX      := $(FILTERED_C_CXX:.c=.$(EXT_OBJ))
  17.424 -OBJ_C_CXX      := $(OBJ_C_CXX:.$(EXT_CXX)=.$(EXT_OBJ))
  17.425 -
  17.426 -PRE_TARGETS  += $(AUTO_MLL) $(AUTO_MLY) $(AUTO_IDL) $(AUTO_OXRIDL) $(AUTO_ZOG) $(AUTO_REP) $(AUTO_GLADE)
  17.427 -
  17.428 -ALL_DEPS     := $(DEP_ML) $(DEP_MLI) $(DEP_MLL) $(DEP_MLY) $(DEP_IDL) $(DEP_OXRIDL) $(DEP_ZOG) $(DEP_REP) $(DEP_GLADE)
  17.429 -
  17.430 -MLDEPS       := $(filter %.d, $(ALL_DEPS))
  17.431 -MLIDEPS      := $(filter %.di, $(ALL_DEPS))
  17.432 -BCDEPIS      := $(MLIDEPS:%.di=$(BCDIDIR)/%.di)
  17.433 -NCDEPIS      := $(MLIDEPS:%.di=$(NCDIDIR)/%.di)
  17.434 -
  17.435 -ALLML        := $(filter %.mli %.ml %.mll %.mly %.idl %.oxridl %.rep %.zog %.glade, $(FILTERED))
  17.436 -
  17.437 -IMPLO_INTF   := $(ALLML:%.mli=%.mli.__)
  17.438 -IMPLO_INTF   := $(foreach file, $(IMPLO_INTF), \
  17.439 -                  $(basename $(file)).cmi $(basename $(file)).cmo)
  17.440 -IMPLO_INTF   := $(filter-out %.mli.cmo, $(IMPLO_INTF))
  17.441 -IMPLO_INTF   := $(IMPLO_INTF:%.mli.cmi=%.cmi)
  17.442 -
  17.443 -IMPLX_INTF   := $(IMPLO_INTF:.cmo=.cmx)
  17.444 -
  17.445 -INTF         := $(filter %.cmi, $(IMPLO_INTF))
  17.446 -IMPL_CMO     := $(filter %.cmo, $(IMPLO_INTF))
  17.447 -IMPL_CMX     := $(IMPL_CMO:.cmo=.cmx)
  17.448 -IMPL_ASM     := $(IMPL_CMO:.cmo=.asm)
  17.449 -IMPL_S       := $(IMPL_CMO:.cmo=.s)
  17.450 -
  17.451 -OBJ_LINK     := $(OBJ_C_IDL) $(OBJ_C_CXX)
  17.452 -OBJ_FILES    := $(IMPL_CMO:.cmo=.$(EXT_OBJ)) $(OBJ_LINK)
  17.453 -
  17.454 -EXECS        := $(addsuffix $(EXE), \
  17.455 -                            $(sort $(TOPRESULT) $(BCRESULT) $(NCRESULT)))
  17.456 -ifdef WIN32
  17.457 -  EXECS      += $(BCRESULT).dll $(NCRESULT).dll
  17.458 -endif
  17.459 -
  17.460 -CLIB_BASE    := $(RESULT)$(RES_CLIB_SUF)
  17.461 -ifneq ($(strip $(OBJ_LINK)),)
  17.462 -  RES_CLIB     := lib$(CLIB_BASE).$(EXT_LIB)
  17.463 -endif
  17.464 -
  17.465 -ifdef WIN32
  17.466 -DLLSONAME := $(CLIB_BASE).dll
  17.467 -else
  17.468 -DLLSONAME := dll$(CLIB_BASE).so
  17.469 -endif
  17.470 -
  17.471 -NONEXECS     := $(INTF) $(IMPL_CMO) $(IMPL_CMX) $(IMPL_ASM) $(IMPL_S) \
  17.472 -		$(OBJ_FILES) $(PRE_TARGETS) $(BCRESULT).cma $(NCRESULT).cmxa \
  17.473 -		$(NCRESULT).$(EXT_LIB) $(BCRESULT).cmi $(BCRESULT).cmo \
  17.474 -		$(NCRESULT).cmi $(NCRESULT).cmx $(NCRESULT).o \
  17.475 -		$(RES_CLIB) $(IMPL_CMO:.cmo=.annot) \
  17.476 -		$(LIB_PACK_NAME).cmi $(LIB_PACK_NAME).cmo $(LIB_PACK_NAME).cmx $(LIB_PACK_NAME).o
  17.477 -
  17.478 -ifndef STATIC
  17.479 -  NONEXECS += $(DLLSONAME)
  17.480 -endif
  17.481 -
  17.482 -ifndef LIBINSTALL_FILES
  17.483 -  LIBINSTALL_FILES := $(RESULT).mli $(RESULT).cmi $(RESULT).cma \
  17.484 -		      $(RESULT).cmxa $(RESULT).$(EXT_LIB) $(RES_CLIB)
  17.485 -  ifndef STATIC
  17.486 -    ifneq ($(strip $(OBJ_LINK)),)
  17.487 -      LIBINSTALL_FILES += $(DLLSONAME)
  17.488 -    endif
  17.489 -  endif
  17.490 -endif
  17.491 -
  17.492 -export LIBINSTALL_FILES
  17.493 -
  17.494 -ifdef WIN32
  17.495 -  # some extra stuff is created while linking DLLs
  17.496 -  NONEXECS   += $(BCRESULT).$(EXT_LIB) $(BCRESULT).exp $(NCRESULT).exp $(CLIB_BASE).exp $(CLIB_BASE).lib
  17.497 -endif
  17.498 -
  17.499 -TARGETS      := $(EXECS) $(NONEXECS)
  17.500 -
  17.501 -# If there are IDL-files
  17.502 -ifneq ($(strip $(FILTERED_IDL)),)
  17.503 -  MAYBE_IDL := -cclib -lcamlidl
  17.504 -endif
  17.505 -
  17.506 -ifdef USE_CAMLP4
  17.507 -  CAMLP4PATH := \
  17.508 -    $(shell $(CAMLP4) -where 2>/dev/null || echo /usr/local/lib/camlp4)
  17.509 -  INCFLAGS := -I $(CAMLP4PATH)
  17.510 -  CINCFLAGS := -I$(CAMLP4PATH)
  17.511 -endif
  17.512 -
  17.513 -DINCFLAGS := $(INCFLAGS) $(SOURCE_DIRS:%=-I %) $(OCAML_DEFAULT_DIRS:%=-I %)
  17.514 -INCFLAGS := $(DINCFLAGS) $(INCDIRS:%=-I %)
  17.515 -CINCFLAGS += $(SOURCE_DIRS:%=-I%) $(INCDIRS:%=-I%) $(OCAML_DEFAULT_DIRS:%=-I%)
  17.516 -
  17.517 -ifndef MSVC
  17.518 -CLIBFLAGS += $(SOURCE_DIRS:%=-L%) $(LIBDIRS:%=-L%) \
  17.519 -             $(EXTLIBDIRS:%=-L%) $(EXTLIBDIRS:%=-Wl,$(RPATH_FLAG)%) \
  17.520 -             $(OCAML_DEFAULT_DIRS:%=-L%)
  17.521 -endif
  17.522 -
  17.523 -ifndef PROFILING
  17.524 -  INTF_OCAMLC := $(OCAMLC)
  17.525 -else
  17.526 -  ifndef THREADS
  17.527 -    INTF_OCAMLC := $(OCAMLCP) -p $(OCAMLCPFLAGS)
  17.528 -  else
  17.529 -    # OCaml does not support profiling byte code
  17.530 -    # with threads (yet), therefore we force an error.
  17.531 -    ifndef REAL_OCAMLC
  17.532 -      $(error Profiling of multithreaded byte code not yet supported by OCaml)
  17.533 -    endif
  17.534 -    INTF_OCAMLC := $(OCAMLC)
  17.535 -  endif
  17.536 -endif
  17.537 -
  17.538 -ifndef MSVC
  17.539 -COMMON_LDFLAGS := $(LDFLAGS:%=-ccopt %) $(SOURCE_DIRS:%=-ccopt -L%) \
  17.540 -		  $(LIBDIRS:%=-ccopt -L%) $(EXTLIBDIRS:%=-ccopt -L%) \
  17.541 -		  $(EXTLIBDIRS:%=-ccopt -Wl,$(RPATH_FLAG)%) \
  17.542 -		  $(OCAML_DEFAULT_DIRS:%=-ccopt -L%)
  17.543 -else
  17.544 -COMMON_LDFLAGS := -ccopt "/link -NODEFAULTLIB:LIBC $(LDFLAGS:%=%) $(SOURCE_DIRS:%=-LIBPATH:%) \
  17.545 -		  $(LIBDIRS:%=-LIBPATH:%) $(EXTLIBDIRS:%=-LIBPATH:%) \
  17.546 -		  $(OCAML_DEFAULT_DIRS:%=-LIBPATH:%) "
  17.547 -endif
  17.548 -
  17.549 -CLIBS_OPTS := $(CLIBS:%=-cclib -l%)
  17.550 -ifdef MSVC
  17.551 -  ifndef STATIC
  17.552 -  # MSVC libraries do not have 'lib' prefix
  17.553 -  CLIBS_OPTS := $(CLIBS:%=-cclib %.lib)
  17.554 -  endif
  17.555 -endif
  17.556 -
  17.557 -ifneq ($(strip $(OBJ_LINK)),)
  17.558 -  ifdef CREATE_LIB
  17.559 -    OBJS_LIBS := -cclib -l$(CLIB_BASE) $(CLIBS_OPTS) $(MAYBE_IDL)
  17.560 -  else
  17.561 -    OBJS_LIBS := $(OBJ_LINK) $(CLIBS_OPTS) $(MAYBE_IDL)
  17.562 -  endif
  17.563 -else
  17.564 -  OBJS_LIBS := $(CLIBS_OPTS) $(MAYBE_IDL)
  17.565 -endif
  17.566 -
  17.567 -# If we have to make byte-code
  17.568 -ifndef REAL_OCAMLC
  17.569 -  BYTE_OCAML := y
  17.570 -
  17.571 -  # EXTRADEPS is added dependencies we have to insert for all
  17.572 -  # executable files we generate.  Ideally it should be all of the
  17.573 -  # libraries we use, but it's hard to find the ones that get searched on
  17.574 -  # the path since I don't know the paths built into the compiler, so
  17.575 -  # just include the ones with slashes in their names.
  17.576 -  EXTRADEPS := $(addsuffix .cma,$(foreach i,$(LIBS),$(if $(findstring /,$(i)),$(i))))
  17.577 -  SPECIAL_OCAMLFLAGS := $(OCAMLBCFLAGS)
  17.578 -
  17.579 -  REAL_OCAMLC := $(INTF_OCAMLC)
  17.580 -
  17.581 -  REAL_IMPL := $(IMPL_CMO)
  17.582 -  REAL_IMPL_INTF := $(IMPLO_INTF)
  17.583 -  IMPL_SUF := .cmo
  17.584 -
  17.585 -  DEPFLAGS  :=
  17.586 -  MAKE_DEPS := $(MLDEPS) $(BCDEPIS)
  17.587 -
  17.588 -  ifdef CREATE_LIB
  17.589 -    CFLAGS := $(PIC_CFLAGS) $(CFLAGS)
  17.590 -    CPPFLAGS := $(PIC_CPPFLAGS) $(CPPFLAGS)
  17.591 -    ifndef STATIC
  17.592 -      ifneq ($(strip $(OBJ_LINK)),)
  17.593 -	MAKEDLL := $(DLLSONAME)
  17.594 -	ALL_LDFLAGS := -dllib $(DLLSONAME)
  17.595 -      endif
  17.596 -    endif
  17.597 -  endif
  17.598 -
  17.599 -  ifndef NO_CUSTOM
  17.600 -    ifneq "$(strip $(OBJ_LINK) $(THREADS) $(MAYBE_IDL) $(CLIBS))" ""
  17.601 -      ALL_LDFLAGS += -custom
  17.602 -    endif
  17.603 -  endif
  17.604 -
  17.605 -  ALL_LDFLAGS += $(INCFLAGS) $(OCAMLLDFLAGS) $(OCAMLBLDFLAGS) \
  17.606 -                 $(COMMON_LDFLAGS) $(LIBS:%=%.cma)
  17.607 -  CAMLIDLDLLFLAGS :=
  17.608 -
  17.609 -  ifdef THREADS
  17.610 -    ifdef VMTHREADS
  17.611 -      THREAD_FLAG := -vmthread
  17.612 -    else
  17.613 -      THREAD_FLAG := -thread
  17.614 -    endif
  17.615 -    ALL_LDFLAGS := $(THREAD_FLAG) $(ALL_LDFLAGS)
  17.616 -    ifndef CREATE_LIB
  17.617 -      ifndef REAL_OCAMLFIND
  17.618 -        ALL_LDFLAGS := unix.cma threads.cma $(ALL_LDFLAGS)
  17.619 -      endif
  17.620 -    endif
  17.621 -  endif
  17.622 -
  17.623 -# we have to make native-code
  17.624 -else
  17.625 -  EXTRADEPS := $(addsuffix .cmxa,$(foreach i,$(LIBS),$(if $(findstring /,$(i)),$(i))))
  17.626 -  ifndef PROFILING
  17.627 -    SPECIAL_OCAMLFLAGS := $(OCAMLNCFLAGS)
  17.628 -    PLDFLAGS :=
  17.629 -  else
  17.630 -    SPECIAL_OCAMLFLAGS := -p $(OCAMLNCFLAGS)
  17.631 -    PLDFLAGS := -p
  17.632 -  endif
  17.633 -
  17.634 -  REAL_IMPL := $(IMPL_CMX)
  17.635 -  REAL_IMPL_INTF := $(IMPLX_INTF)
  17.636 -  IMPL_SUF := .cmx
  17.637 -
  17.638 -  CPPFLAGS := -DNATIVE_CODE $(CPPFLAGS)
  17.639 -
  17.640 -  DEPFLAGS  := -native
  17.641 -  MAKE_DEPS := $(MLDEPS) $(NCDEPIS)
  17.642 -
  17.643 -  ALL_LDFLAGS := $(PLDFLAGS) $(INCFLAGS) $(OCAMLLDFLAGS) \
  17.644 -                 $(OCAMLNLDFLAGS) $(COMMON_LDFLAGS)
  17.645 -  CAMLIDLDLLFLAGS := -opt
  17.646 -
  17.647 -  ifndef CREATE_LIB
  17.648 -    ALL_LDFLAGS += $(LIBS:%=%.cmxa)
  17.649 -  else
  17.650 -    CFLAGS := $(PIC_CFLAGS) $(CFLAGS)
  17.651 -    CPPFLAGS := $(PIC_CPPFLAGS) $(CPPFLAGS)
  17.652 -  endif
  17.653 -
  17.654 -  ifdef THREADS
  17.655 -    THREAD_FLAG := -thread
  17.656 -    ALL_LDFLAGS := $(THREAD_FLAG) $(ALL_LDFLAGS)
  17.657 -    ifndef CREATE_LIB
  17.658 -      ifndef REAL_OCAMLFIND
  17.659 -        ALL_LDFLAGS := unix.cmxa threads.cmxa $(ALL_LDFLAGS)
  17.660 -      endif
  17.661 -    endif
  17.662 -  endif
  17.663 -endif
  17.664 -
  17.665 -export MAKE_DEPS
  17.666 -
  17.667 -ifdef ANNOTATE
  17.668 -  ANNOT_FLAG := -dtypes
  17.669 -else
  17.670 -endif
  17.671 -
  17.672 -ALL_OCAMLCFLAGS := $(THREAD_FLAG) $(ANNOT_FLAG) $(OCAMLFLAGS) \
  17.673 -                   $(INCFLAGS) $(SPECIAL_OCAMLFLAGS)
  17.674 -
  17.675 -ifdef make_deps
  17.676 -  -include $(MAKE_DEPS)
  17.677 -  PRE_TARGETS :=
  17.678 -endif
  17.679 -
  17.680 -###########################################################################
  17.681 -# USER RULES
  17.682 -
  17.683 -# Call "OCamlMakefile QUIET=" to get rid of all of the @'s.
  17.684 -QUIET=@
  17.685 -
  17.686 -# generates byte-code (default)
  17.687 -byte-code:		$(PRE_TARGETS)
  17.688 -			$(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) $(BCRESULT) \
  17.689 -				REAL_RESULT="$(BCRESULT)" make_deps=yes
  17.690 -bc:	byte-code
  17.691 -
  17.692 -byte-code-nolink:	$(PRE_TARGETS)
  17.693 -			$(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) nolink \
  17.694 -				REAL_RESULT="$(BCRESULT)" make_deps=yes
  17.695 -bcnl:	byte-code-nolink
  17.696 -
  17.697 -top:			$(PRE_TARGETS)
  17.698 -			$(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) $(TOPRESULT) \
  17.699 -				REAL_RESULT="$(BCRESULT)" make_deps=yes
  17.700 -
  17.701 -# generates native-code
  17.702 -
  17.703 -native-code:		$(PRE_TARGETS)
  17.704 -			$(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) $(NCRESULT) \
  17.705 -				REAL_RESULT="$(NCRESULT)" \
  17.706 -				REAL_OCAMLC="$(OCAMLOPT)" \
  17.707 -				make_deps=yes
  17.708 -nc:	native-code
  17.709 -
  17.710 -native-code-nolink:	$(PRE_TARGETS)
  17.711 -			$(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) nolink \
  17.712 -				REAL_RESULT="$(NCRESULT)" \
  17.713 -				REAL_OCAMLC="$(OCAMLOPT)" \
  17.714 -				make_deps=yes
  17.715 -ncnl:	native-code-nolink
  17.716 -
  17.717 -# generates byte-code libraries
  17.718 -byte-code-library:	$(PRE_TARGETS)
  17.719 -			$(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \
  17.720 -				$(RES_CLIB) $(BCRESULT).cma \
  17.721 -				REAL_RESULT="$(BCRESULT)" \
  17.722 -				CREATE_LIB=yes \
  17.723 -				make_deps=yes
  17.724 -bcl:	byte-code-library
  17.725 -
  17.726 -# generates native-code libraries
  17.727 -native-code-library:	$(PRE_TARGETS)
  17.728 -			$(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \
  17.729 -				$(RES_CLIB) $(NCRESULT).cmxa \
  17.730 -				REAL_RESULT="$(NCRESULT)" \
  17.731 -				REAL_OCAMLC="$(OCAMLOPT)" \
  17.732 -				CREATE_LIB=yes \
  17.733 -				make_deps=yes
  17.734 -ncl:	native-code-library
  17.735 -
  17.736 -ifdef WIN32
  17.737 -# generates byte-code dll
  17.738 -byte-code-dll:		$(PRE_TARGETS)
  17.739 -			$(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \
  17.740 -				$(RES_CLIB) $(BCRESULT).dll \
  17.741 -				REAL_RESULT="$(BCRESULT)" \
  17.742 -				make_deps=yes
  17.743 -bcd:	byte-code-dll
  17.744 -
  17.745 -# generates native-code dll
  17.746 -native-code-dll:	$(PRE_TARGETS)
  17.747 -			$(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \
  17.748 -				$(RES_CLIB) $(NCRESULT).dll \
  17.749 -				REAL_RESULT="$(NCRESULT)" \
  17.750 -				REAL_OCAMLC="$(OCAMLOPT)" \
  17.751 -				make_deps=yes
  17.752 -ncd:	native-code-dll
  17.753 -endif
  17.754 -
  17.755 -# generates byte-code with debugging information
  17.756 -debug-code:		$(PRE_TARGETS)
  17.757 -			$(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) $(BCRESULT) \
  17.758 -				REAL_RESULT="$(BCRESULT)" make_deps=yes \
  17.759 -				OCAMLFLAGS="-g $(OCAMLFLAGS)" \
  17.760 -				OCAMLLDFLAGS="-g $(OCAMLLDFLAGS)"
  17.761 -dc:	debug-code
  17.762 -
  17.763 -debug-code-nolink:	$(PRE_TARGETS)
  17.764 -			$(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) nolink \
  17.765 -				REAL_RESULT="$(BCRESULT)" make_deps=yes \
  17.766 -				OCAMLFLAGS="-g $(OCAMLFLAGS)" \
  17.767 -				OCAMLLDFLAGS="-g $(OCAMLLDFLAGS)"
  17.768 -dcnl:	debug-code-nolink
  17.769 -
  17.770 -# generates byte-code libraries with debugging information
  17.771 -debug-code-library:	$(PRE_TARGETS)
  17.772 -			$(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \
  17.773 -				$(RES_CLIB) $(BCRESULT).cma \
  17.774 -				REAL_RESULT="$(BCRESULT)" make_deps=yes \
  17.775 -				CREATE_LIB=yes \
  17.776 -				OCAMLFLAGS="-g $(OCAMLFLAGS)" \
  17.777 -				OCAMLLDFLAGS="-g $(OCAMLLDFLAGS)"
  17.778 -dcl:	debug-code-library
  17.779 -
  17.780 -# generates byte-code for profiling
  17.781 -profiling-byte-code:		$(PRE_TARGETS)
  17.782 -			$(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) $(BCRESULT) \
  17.783 -				REAL_RESULT="$(BCRESULT)" PROFILING="y" \
  17.784 -				make_deps=yes
  17.785 -pbc:	profiling-byte-code
  17.786 -
  17.787 -# generates native-code
  17.788 -
  17.789 -profiling-native-code:		$(PRE_TARGETS)
  17.790 -			$(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) $(NCRESULT) \
  17.791 -				REAL_RESULT="$(NCRESULT)" \
  17.792 -				REAL_OCAMLC="$(OCAMLOPT)" \
  17.793 -				PROFILING="y" \
  17.794 -				make_deps=yes
  17.795 -pnc:	profiling-native-code
  17.796 -
  17.797 -# generates byte-code libraries
  17.798 -profiling-byte-code-library:	$(PRE_TARGETS)
  17.799 -			$(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \
  17.800 -				$(RES_CLIB) $(BCRESULT).cma \
  17.801 -				REAL_RESULT="$(BCRESULT)" PROFILING="y" \
  17.802 -				CREATE_LIB=yes \
  17.803 -				make_deps=yes
  17.804 -pbcl:	profiling-byte-code-library
  17.805 -
  17.806 -# generates native-code libraries
  17.807 -profiling-native-code-library:	$(PRE_TARGETS)
  17.808 -			$(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \
  17.809 -				$(RES_CLIB) $(NCRESULT).cmxa \
  17.810 -				REAL_RESULT="$(NCRESULT)" PROFILING="y" \
  17.811 -				REAL_OCAMLC="$(OCAMLOPT)" \
  17.812 -				CREATE_LIB=yes \
  17.813 -				make_deps=yes
  17.814 -pncl:	profiling-native-code-library
  17.815 -
  17.816 -# packs byte-code objects
  17.817 -pack-byte-code:			$(PRE_TARGETS)
  17.818 -			$(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) $(BCRESULT).cmo \
  17.819 -				REAL_RESULT="$(BCRESULT)" \
  17.820 -				PACK_LIB=yes make_deps=yes
  17.821 -pabc:	pack-byte-code
  17.822 -
  17.823 -# packs native-code objects
  17.824 -pack-native-code:		$(PRE_TARGETS)
  17.825 -			$(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \
  17.826 -				$(NCRESULT).cmx $(NCRESULT).o \
  17.827 -				REAL_RESULT="$(NCRESULT)" \
  17.828 -				REAL_OCAMLC="$(OCAMLOPT)" \
  17.829 -				PACK_LIB=yes make_deps=yes
  17.830 -panc:	pack-native-code
  17.831 -
  17.832 -# generates HTML-documentation
  17.833 -htdoc:	doc/$(RESULT)/html
  17.834 -
  17.835 -# generates Latex-documentation
  17.836 -ladoc:	doc/$(RESULT)/latex
  17.837 -
  17.838 -# generates PostScript-documentation
  17.839 -psdoc:	doc/$(RESULT)/latex/doc.ps
  17.840 -
  17.841 -# generates PDF-documentation
  17.842 -pdfdoc:	doc/$(RESULT)/latex/doc.pdf
  17.843 -
  17.844 -# generates all supported forms of documentation
  17.845 -doc: htdoc ladoc psdoc pdfdoc
  17.846 -
  17.847 -###########################################################################
  17.848 -# LOW LEVEL RULES
  17.849 -
  17.850 -$(REAL_RESULT):		$(REAL_IMPL_INTF) $(OBJ_LINK) $(EXTRADEPS) $(RESULTDEPS)
  17.851 -			$(REAL_OCAMLFIND) $(REAL_OCAMLC) \
  17.852 -				$(OCAML_FIND_PACKAGES) $(OCAML_FIND_LINKPKG) \
  17.853 -				$(ALL_LDFLAGS) $(OBJS_LIBS) -o $@$(EXE) \
  17.854 -				$(REAL_IMPL)
  17.855 -
  17.856 -nolink:			$(REAL_IMPL_INTF) $(OBJ_LINK)
  17.857 -
  17.858 -ifdef WIN32
  17.859 -$(REAL_RESULT).dll:	$(REAL_IMPL_INTF) $(OBJ_LINK)
  17.860 -			$(CAMLIDLDLL) $(CAMLIDLDLLFLAGS) $(OBJ_LINK) $(CLIBS) \
  17.861 -				-o $@ $(REAL_IMPL)
  17.862 -endif
  17.863 -
  17.864 -%$(TOPSUFFIX):		$(REAL_IMPL_INTF) $(OBJ_LINK) $(EXTRADEPS)
  17.865 -			$(REAL_OCAMLFIND) $(OCAMLMKTOP) \
  17.866 -				$(OCAML_FIND_PACKAGES) $(OCAML_FIND_LINKPKG) \
  17.867 -				$(ALL_LDFLAGS) $(OBJS_LIBS) -o $@$(EXE) \
  17.868 -				$(REAL_IMPL)
  17.869 -
  17.870 -.SUFFIXES:		.mli .ml .cmi .cmo .cmx .cma .cmxa .$(EXT_OBJ) \
  17.871 -                        .mly .di .d .$(EXT_LIB) .idl %.oxridl .c .$(EXT_CXX) .h .so \
  17.872 -                        .rep .zog .glade
  17.873 -
  17.874 -ifndef STATIC
  17.875 -ifdef MINGW
  17.876 -$(DLLSONAME):		$(OBJ_LINK)
  17.877 -			$(CC) $(CFLAGS) $(CFLAGS_WIN32) $(OBJ_LINK) -shared -o $@ \
  17.878 -			-Wl,--whole-archive $(wildcard $(foreach dir,$(LIBDIRS),$(CLIBS:%=$(dir)/lib%.a))) \
  17.879 -			 $(OCAMLLIBPATH)/ocamlrun.a \
  17.880 -			-Wl,--export-all-symbols \
  17.881 -			-Wl,--no-whole-archive
  17.882 -else
  17.883 -ifdef MSVC
  17.884 -$(DLLSONAME):		$(OBJ_LINK)
  17.885 -			link /NOLOGO /DLL /OUT:$@ $(OBJ_LINK) \
  17.886 -			 $(wildcard $(foreach dir,$(LIBDIRS),$(CLIBS:%=$(dir)/%.lib))) \
  17.887 -			 $(OCAMLLIBPATH)/ocamlrun.lib
  17.888 -
  17.889 -else
  17.890 -$(DLLSONAME):		$(OBJ_LINK)
  17.891 -			$(OCAMLMKLIB) $(INCFLAGS) $(CLIBFLAGS) \
  17.892 -				-o $(CLIB_BASE) $(OBJ_LINK) $(CLIBS:%=-l%) \
  17.893 -				$(OCAMLMKLIB_FLAGS)
  17.894 -endif
  17.895 -endif
  17.896 -endif
  17.897 -
  17.898 -ifndef LIB_PACK_NAME
  17.899 -$(RESULT).cma:		$(REAL_IMPL_INTF) $(MAKEDLL) $(EXTRADEPS) $(RESULTDEPS)
  17.900 -			$(REAL_OCAMLFIND) $(REAL_OCAMLC) -a $(ALL_LDFLAGS) \
  17.901 -				$(OBJS_LIBS) -o $@ $(OCAMLBLDFLAGS) $(REAL_IMPL)
  17.902 -
  17.903 -$(RESULT).cmxa $(RESULT).$(EXT_LIB):	$(REAL_IMPL_INTF) $(EXTRADEPS) $(RESULTDEPS)
  17.904 -			$(REAL_OCAMLFIND) $(OCAMLOPT) -a $(ALL_LDFLAGS) $(OBJS_LIBS) \
  17.905 -				$(OCAMLNLDFLAGS) -o $@ $(REAL_IMPL)
  17.906 -else
  17.907 -ifdef BYTE_OCAML
  17.908 -$(LIB_PACK_NAME).cmi $(LIB_PACK_NAME).cmo: $(REAL_IMPL_INTF)
  17.909 -			$(REAL_OCAMLFIND) $(REAL_OCAMLC) -pack -o $(LIB_PACK_NAME).cmo $(REAL_IMPL)
  17.910 -else
  17.911 -$(LIB_PACK_NAME).cmi $(LIB_PACK_NAME).cmx: $(REAL_IMPL_INTF)
  17.912 -			$(REAL_OCAMLFIND) $(REAL_OCAMLC) -pack -o $(LIB_PACK_NAME).cmx $(REAL_IMPL)
  17.913 -endif
  17.914 -
  17.915 -$(RESULT).cma:		$(LIB_PACK_NAME).cmi $(LIB_PACK_NAME).cmo $(MAKEDLL) $(EXTRADEPS) $(RESULTDEPS)
  17.916 -			$(REAL_OCAMLFIND) $(REAL_OCAMLC) -a $(ALL_LDFLAGS) \
  17.917 -				$(OBJS_LIBS) -o $@ $(OCAMLBLDFLAGS) $(LIB_PACK_NAME).cmo
  17.918 -
  17.919 -$(RESULT).cmxa $(RESULT).$(EXT_LIB):	$(LIB_PACK_NAME).cmi $(LIB_PACK_NAME).cmx $(EXTRADEPS) $(RESULTDEPS)
  17.920 -			$(REAL_OCAMLFIND) $(OCAMLOPT) -a $(ALL_LDFLAGS) $(OBJS_LIBS) \
  17.921 -				$(OCAMLNLDFLAGS) -o $@ $(LIB_PACK_NAME).cmx
  17.922 -endif
  17.923 -
  17.924 -$(RES_CLIB): 		$(OBJ_LINK)
  17.925 -ifndef MSVC
  17.926 -  ifneq ($(strip $(OBJ_LINK)),)
  17.927 -		      $(AR) rcs $@ $(OBJ_LINK)
  17.928 -  endif
  17.929 -else
  17.930 -  ifneq ($(strip $(OBJ_LINK)),)
  17.931 -			lib -nologo -debugtype:cv -out:$(RES_CLIB) $(OBJ_LINK)
  17.932 -  endif
  17.933 -endif
  17.934 -
  17.935 -.mli.cmi: $(EXTRADEPS)
  17.936 -			$(QUIET)pp=`sed -n -e '/^#/d' -e 's/(\*pp \([^*]*\) \*)/\1/p;q' $<`; \
  17.937 -			if [ -z "$$pp" ]; then \
  17.938 -			  echo $(REAL_OCAMLFIND) $(INTF_OCAMLC) $(OCAML_FIND_PACKAGES) \
  17.939 -				-c $(THREAD_FLAG) $(ANNOT_FLAG) \
  17.940 -				$(OCAMLFLAGS) $(INCFLAGS) $<; \
  17.941 -			  $(REAL_OCAMLFIND) $(INTF_OCAMLC) $(OCAML_FIND_PACKAGES) \
  17.942 -				-c $(THREAD_FLAG) $(ANNOT_FLAG) \
  17.943 -				$(OCAMLFLAGS) $(INCFLAGS) $<; \
  17.944 -			else \
  17.945 -			    echo $(REAL_OCAMLFIND) $(INTF_OCAMLC) $(OCAML_FIND_PACKAGES) \
  17.946 -				-c -pp \"$$pp $(PPFLAGS)\" $(THREAD_FLAG) $(ANNOT_FLAG) \
  17.947 -				$(OCAMLFLAGS) $(INCFLAGS) $<; \
  17.948 -			    $(REAL_OCAMLFIND) $(INTF_OCAMLC) $(OCAML_FIND_PACKAGES) \
  17.949 -				-c -pp "$$pp $(PPFLAGS)" $(THREAD_FLAG) $(ANNOT_FLAG) \
  17.950 -				$(OCAMLFLAGS) $(INCFLAGS) $<; \
  17.951 -			fi
  17.952 -
  17.953 -.ml.cmi .ml.$(EXT_OBJ) .ml.cmx .ml.cmo: $(EXTRADEPS)
  17.954 -			$(QUIET)pp=`sed -n -e '/^#/d' -e 's/(\*pp \([^*]*\) \*)/\1/p;q' $<`; \
  17.955 -			if [ -z "$$pp" ]; then \
  17.956 -			  echo $(REAL_OCAMLFIND) $(REAL_OCAMLC) $(OCAML_FIND_PACKAGES) \
  17.957 -				-c $(ALL_OCAMLCFLAGS) $<; \
  17.958 -			  $(REAL_OCAMLFIND) $(REAL_OCAMLC) $(OCAML_FIND_PACKAGES) \
  17.959 -				-c $(ALL_OCAMLCFLAGS) $<; \
  17.960 -			else \
  17.961 -			  echo $(REAL_OCAMLFIND) $(REAL_OCAMLC) $(OCAML_FIND_PACKAGES) \
  17.962 -				-c -pp \"$$pp $(PPFLAGS)\" $(ALL_OCAMLCFLAGS) $<; \
  17.963 -			  $(REAL_OCAMLFIND) $(REAL_OCAMLC) $(OCAML_FIND_PACKAGES) \
  17.964 -				-c -pp "$$pp $(PPFLAGS)" $(ALL_OCAMLCFLAGS) $<; \
  17.965 -			fi
  17.966 -
  17.967 -ifdef PACK_LIB
  17.968 -$(REAL_RESULT).cmo $(REAL_RESULT).cmx $(REAL_RESULT).o: $(REAL_IMPL_INTF) $(OBJ_LINK) $(EXTRADEPS)
  17.969 -			$(REAL_OCAMLFIND) $(REAL_OCAMLC) -pack $(ALL_LDFLAGS) \
  17.970 -				$(OBJS_LIBS) -o $@ $(REAL_IMPL)
  17.971 -endif
  17.972 -
  17.973 -.PRECIOUS:		%.ml
  17.974 -%.ml:			%.mll
  17.975 -			$(OCAMLLEX) $<
  17.976 -
  17.977 -.PRECIOUS:              %.ml %.mli
  17.978 -%.ml %.mli:             %.mly
  17.979 -			$(OCAMLYACC) $(YFLAGS) $<
  17.980 -			$(QUIET)pp=`sed -n -e 's/.*(\*pp \([^*]*\) \*).*/\1/p;q' $<`; \
  17.981 -			if [ ! -z "$$pp" ]; then \
  17.982 -			  mv $*.ml $*.ml.temporary; \
  17.983 -			  echo "(*pp $$pp $(PPFLAGS)*)" > $*.ml; \
  17.984 -			  cat $*.ml.temporary >> $*.ml; \
  17.985 -			  rm $*.ml.temporary; \
  17.986 -			  mv $*.mli $*.mli.temporary; \
  17.987 -			  echo "(*pp $$pp $(PPFLAGS)*)" > $*.mli; \
  17.988 -			  cat $*.mli.temporary >> $*.mli; \
  17.989 -			  rm $*.mli.temporary; \
  17.990 -			fi
  17.991 -
  17.992 -
  17.993 -.PRECIOUS:		%.ml
  17.994 -%.ml:			%.rep
  17.995 -			$(CAMELEON_REPORT) $(CAMELEON_REPORT_FLAGS) -gen $<
  17.996 -
  17.997 -.PRECIOUS:		%.ml
  17.998 -%.ml:			%.zog
  17.999 -			$(CAMELEON_ZOGGY)  $(CAMELEON_ZOGGY_FLAGS) -impl $< > $@
 17.1000 -
 17.1001 -.PRECIOUS:		%.ml
 17.1002 -%.ml:			%.glade
 17.1003 -			$(OCAML_GLADECC)  $(OCAML_GLADECC_FLAGS) $< > $@
 17.1004 -
 17.1005 -.PRECIOUS:		%.ml %.mli
 17.1006 -%.ml %.mli:		%.oxridl
 17.1007 -			$(OXRIDL) $<
 17.1008 -
 17.1009 -.PRECIOUS:		%.ml %.mli %_stubs.c %.h
 17.1010 -%.ml %.mli %_stubs.c %.h:		%.idl
 17.1011 -			$(CAMLIDL) $(MAYBE_IDL_HEADER) $(IDLFLAGS) \
 17.1012 -				$(CAMLIDLFLAGS) $<
 17.1013 -			$(QUIET)if [ $(NOIDLHEADER) ]; then touch $*.h; fi
 17.1014 -
 17.1015 -.c.$(EXT_OBJ):
 17.1016 -			$(OCAMLC) -c -cc "$(CC)" -ccopt "$(CFLAGS) \
 17.1017 -				$(CPPFLAGS) $(CPPFLAGS_WIN32) \
 17.1018 -				$(CFLAGS_WIN32) $(CINCFLAGS) $(CFLAG_O)$@ " $< 
 17.1019 -
 17.1020 -.$(EXT_CXX).$(EXT_OBJ):
 17.1021 -			$(CXX) -c $(CXXFLAGS) $(CINCFLAGS) $(CPPFLAGS) \
 17.1022 -				-I'$(OCAMLLIBPATH)' \
 17.1023 -				$< $(CFLAG_O)$@
 17.1024 -
 17.1025 -$(MLDEPDIR)/%.d:	%.ml
 17.1026 -			$(QUIET)echo making $@ from $<
 17.1027 -			$(QUIET)if [ ! -d $(@D) ]; then mkdir -p $(@D); fi
 17.1028 -			$(QUIET)pp=`sed -n -e '/^#/d' -e 's/(\*pp \([^*]*\) \*)/\1/p;q' $<`; \
 17.1029 -			if [ -z "$$pp" ]; then \
 17.1030 -			  $(REAL_OCAMLFIND) $(OCAMLDEP) $(OCAML_DEP_PACKAGES) \
 17.1031 -				$(DINCFLAGS) $< > $@; \
 17.1032 -			else \
 17.1033 -			  $(REAL_OCAMLFIND) $(OCAMLDEP) $(OCAML_DEP_PACKAGES) \
 17.1034 -				-pp "$$pp $(PPFLAGS)" $(DINCFLAGS) $< > $@; \
 17.1035 -			fi
 17.1036 -
 17.1037 -$(BCDIDIR)/%.di $(NCDIDIR)/%.di:	%.mli
 17.1038 -			$(QUIET)echo making $@ from $<
 17.1039 -			$(QUIET)if [ ! -d $(@D) ]; then mkdir -p $(@D); fi
 17.1040 -			$(QUIET)pp=`sed -n -e '/^#/d' -e 's/(\*pp \([^*]*\) \*)/\1/p;q' $<`; \
 17.1041 -			if [ -z "$$pp" ]; then \
 17.1042 -			  $(REAL_OCAMLFIND) $(OCAMLDEP) $(DEPFLAGS) $(DINCFLAGS) $< > $@; \
 17.1043 -			else \
 17.1044 -			  $(REAL_OCAMLFIND) $(OCAMLDEP) $(DEPFLAGS) \
 17.1045 -			    -pp "$$pp $(PPFLAGS)" $(DINCFLAGS) $< > $@; \
 17.1046 -			fi
 17.1047 -
 17.1048 -doc/$(RESULT)/html: $(DOC_FILES)
 17.1049 -	rm -rf $@
 17.1050 -	mkdir -p $@
 17.1051 -	$(QUIET)pp=`sed -n -e '/^#/d' -e 's/(\*pp \([^*]*\) \*)/\1/p;q' $<`; \
 17.1052 -	if [ -z "$$pp" ]; then \
 17.1053 -	  echo $(OCAMLDOC) -html -d $@ $(OCAMLDOCFLAGS) $(INCFLAGS) $(DOC_FILES); \
 17.1054 -	  $(OCAMLDOC) -html -d $@ $(OCAMLDOCFLAGS) $(INCFLAGS) $(DOC_FILES); \
 17.1055 -	else \
 17.1056 -	  echo $(OCAMLDOC) -pp \"$$pp $(PPFLAGS)\" -html -d $@ $(OCAMLDOCFLAGS) \
 17.1057 -	  	$(INCFLAGS) $(DOC_FILES); \
 17.1058 -	  $(OCAMLDOC) -pp "$$pp $(PPFLAGS)" -html -d $@ $(OCAMLDOCFLAGS) \
 17.1059 -	  	$(INCFLAGS) $(DOC_FILES); \
 17.1060 -	fi
 17.1061 -
 17.1062 -doc/$(RESULT)/latex: $(DOC_FILES)
 17.1063 -	rm -rf $@
 17.1064 -	mkdir -p $@
 17.1065 -	$(QUIET)pp=`sed -n -e '/^#/d' -e 's/(\*pp \([^*]*\) \*)/\1/p;q' $<`; \
 17.1066 -	if [ -z "$$pp" ]; then \
 17.1067 -	  echo $(OCAMLDOC) -latex $(OCAMLDOCFLAGS) $(INCFLAGS) \
 17.1068 -	  	$(DOC_FILES) -o $@/doc.tex; \
 17.1069 -	  $(OCAMLDOC) -latex $(OCAMLDOCFLAGS) $(INCFLAGS) $(DOC_FILES) \
 17.1070 -	  	-o $@/doc.tex; \
 17.1071 -	else \
 17.1072 -	  echo $(OCAMLDOC) -pp \"$$pp $(PPFLAGS)\" -latex $(OCAMLDOCFLAGS) \
 17.1073 -	  	$(INCFLAGS) $(DOC_FILES) -o $@/doc.tex; \
 17.1074 -	  $(OCAMLDOC) -pp "$$pp $(PPFLAGS)" -latex $(OCAMLDOCFLAGS) \
 17.1075 -	  	$(INCFLAGS) $(DOC_FILES) -o $@/doc.tex; \
 17.1076 -	fi
 17.1077 -
 17.1078 -doc/$(RESULT)/latex/doc.ps: doc/$(RESULT)/latex
 17.1079 -	cd doc/$(RESULT)/latex && \
 17.1080 -	  $(LATEX) doc.tex && \
 17.1081 -	  $(LATEX) doc.tex && \
 17.1082 -	  $(DVIPS) $(DVIPSFLAGS) doc.dvi -o $(@F)
 17.1083 -
 17.1084 -doc/$(RESULT)/latex/doc.pdf: doc/$(RESULT)/latex/doc.ps
 17.1085 -	cd doc/$(RESULT)/latex && $(PS2PDF) $(<F)
 17.1086 -
 17.1087 -define make_subproj
 17.1088 -.PHONY:
 17.1089 -subproj_$(1):
 17.1090 -	$$(eval $$(call PROJ_$(1)))
 17.1091 -	$(QUIET)if [ "$(SUBTARGET)" != "all" ]; then \
 17.1092 -	  $(MAKE) -f $(OCAMLMAKEFILE) $(SUBTARGET); \
 17.1093 -	fi
 17.1094 -endef
 17.1095 -
 17.1096 -$(foreach subproj,$(SUBPROJS),$(eval $(call make_subproj,$(subproj))))
 17.1097 -
 17.1098 -.PHONY:
 17.1099 -subprojs: $(SUBPROJS:%=subproj_%)
 17.1100 -
 17.1101 -###########################################################################
 17.1102 -# (UN)INSTALL RULES FOR LIBRARIES
 17.1103 -
 17.1104 -.PHONY: libinstall
 17.1105 -libinstall:	all
 17.1106 -	$(QUIET)printf "\nInstalling library with ocamlfind\n"
 17.1107 -	$(OCAMLFIND) install $(OCAMLFIND_INSTFLAGS) $(RESULT) META $(LIBINSTALL_FILES)
 17.1108 -	$(QUIET)printf "\nInstallation successful.\n"
 17.1109 -
 17.1110 -.PHONY: libuninstall
 17.1111 -libuninstall:
 17.1112 -	$(QUIET)printf "\nUninstalling library with ocamlfind\n"
 17.1113 -	$(OCAMLFIND) remove $(OCAMLFIND_INSTFLAGS) $(RESULT)
 17.1114 -	$(QUIET)printf "\nUninstallation successful.\n"
 17.1115 -
 17.1116 -.PHONY: rawinstall
 17.1117 -rawinstall:	all
 17.1118 -	$(QUIET)printf "\nInstalling library to: $(OCAML_LIB_INSTALL)\n"
 17.1119 -	-install -d $(OCAML_LIB_INSTALL)
 17.1120 -	for i in $(LIBINSTALL_FILES); do \
 17.1121 -	  if [ -f $$i ]; then \
 17.1122 -	    install -c -m 0644 $$i $(OCAML_LIB_INSTALL); \
 17.1123 -	  fi; \
 17.1124 -	done
 17.1125 -	$(QUIET)printf "\nInstallation successful.\n"
 17.1126 -
 17.1127 -.PHONY: rawuninstall
 17.1128 -rawuninstall:
 17.1129 -	$(QUIET)printf "\nUninstalling library from: $(OCAML_LIB_INSTALL)\n"
 17.1130 -	cd $(OCAML_LIB_INSTALL) && rm $(notdir $(LIBINSTALL_FILES))
 17.1131 -	$(QUIET)printf "\nUninstallation successful.\n"
 17.1132 -
 17.1133 -###########################################################################
 17.1134 -# MAINTAINANCE RULES
 17.1135 -
 17.1136 -.PHONY:	clean
 17.1137 -clean::
 17.1138 -	rm -f $(TARGETS) $(TRASH)
 17.1139 -	rm -rf $(BCDIDIR) $(NCDIDIR) $(MLDEPDIR)
 17.1140 -
 17.1141 -.PHONY:	cleanup
 17.1142 -cleanup::
 17.1143 -	rm -f $(NONEXECS) $(TRASH)
 17.1144 -	rm -rf $(BCDIDIR) $(NCDIDIR) $(MLDEPDIR)
 17.1145 -
 17.1146 -.PHONY: clean-doc
 17.1147 -clean-doc::
 17.1148 -	rm -rf doc
 17.1149 -
 17.1150 -.PHONY: nobackup
 17.1151 -nobackup:
 17.1152 -	rm -f *.bak *~ *.dup
    18.1 --- a/tools/debugger/pdb/PDB.ml	Sun Oct 01 11:39:41 2006 -0600
    18.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.3 @@ -1,342 +0,0 @@
    18.4 -(** PDB.ml
    18.5 - *
    18.6 - *  Dispatch debugger commands to the appropriate context
    18.7 - *
    18.8 - *  @author copyright (c) 2005 alex ho
    18.9 - *  @see <www.cl.cam.ac.uk/netos/pdb> pervasive debugger
   18.10 - *  @version 1
   18.11 - *)
   18.12 -
   18.13 -open Util
   18.14 -
   18.15 -exception Unimplemented of string
   18.16 -exception Unknown_context of string
   18.17 -exception Unknown_domain
   18.18 -exception Unknown_process
   18.19 -
   18.20 -type context_t =
   18.21 -  | Void
   18.22 -  | Xen_virq
   18.23 -  | Xen_xcs
   18.24 -  | Xen_domain of Xen_domain.context_t
   18.25 -  | Domain of Domain.context_t
   18.26 -  | Process of Process.context_t
   18.27 -
   18.28 -let string_of_context ctx =
   18.29 -  match ctx with
   18.30 -  | Void -> "{void}"
   18.31 -  | Xen_virq  -> "{Xen virq evtchn}"
   18.32 -  | Xen_xcs   -> "{Xen xcs socket}"
   18.33 -  | Xen_domain d -> Xen_domain.string_of_context d
   18.34 -  | Domain d  -> Domain.string_of_context d
   18.35 -  | Process p -> Process.string_of_context p
   18.36 -
   18.37 -
   18.38 -let hash = Hashtbl.create 10
   18.39 -
   18.40 -
   18.41 -(***************************************************************************)
   18.42 -
   18.43 -let find_context key =
   18.44 -  try
   18.45 -    Hashtbl.find hash key
   18.46 -  with
   18.47 -    Not_found ->
   18.48 -      print_endline "error: (find_context) PDB context not found";
   18.49 -      raise Not_found
   18.50 -
   18.51 -let delete_context key =
   18.52 -  Hashtbl.remove hash key
   18.53 -
   18.54 -
   18.55 -(**
   18.56 -   find_process : Locate the socket associated with the context(s)
   18.57 -   matching a particular (domain, process id) pair.  if there are multiple
   18.58 -   contexts (there shouldn't be), then return the first one.
   18.59 - *)
   18.60 -
   18.61 -let find_process dom pid =
   18.62 -    let find key ctx list =
   18.63 -      match ctx with
   18.64 -      |	Process p ->
   18.65 -	  if (((Process.get_domain p) = dom) &&
   18.66 -	      ((Process.get_process p) = pid))
   18.67 -	  then
   18.68 -	    key :: list
   18.69 -	  else
   18.70 -	    list
   18.71 -      | _ -> list
   18.72 -    in
   18.73 -    let sock_list = Hashtbl.fold find hash [] in
   18.74 -    match sock_list with
   18.75 -    | hd::tl -> hd
   18.76 -    | [] -> raise Unknown_process
   18.77 -
   18.78 -
   18.79 -(**
   18.80 -   find_domain : Locate the socket associated with the context(s)
   18.81 -   matching a particular (domain, vcpu) pair.  if there are multiple
   18.82 -   contexts (there shouldn't be), then return the first one.
   18.83 - *)
   18.84 -
   18.85 -let find_domain dom vcpu =
   18.86 -    let find key ctx list =
   18.87 -      match ctx with
   18.88 -      |	Domain d ->
   18.89 -	  if (((Domain.get_domain d) = dom) &&
   18.90 -	      ((Domain.get_vcpu d) = vcpu))
   18.91 -	  then
   18.92 -	    key :: list
   18.93 -	  else
   18.94 -	    list
   18.95 -      | _ -> list
   18.96 -    in
   18.97 -    let sock_list = Hashtbl.fold find hash [] in
   18.98 -    match sock_list with
   18.99 -    | hd::tl -> hd
  18.100 -    | [] -> raise Unknown_domain
  18.101 -
  18.102 -(**
  18.103 -   find_xen_domain_context : fetch the socket associated with the
  18.104 -   xen_domain context for a domain.  if there are multiple contexts
  18.105 -   (there shouldn't be), then return the first one.
  18.106 - *)
  18.107 -
  18.108 -let find_xen_domain_context domain =
  18.109 -  let find key ctx list =
  18.110 -    match ctx with
  18.111 -      | Xen_domain d ->
  18.112 -	  if ((Xen_domain.get_domain d) = domain)
  18.113 -	  then
  18.114 -	    key :: list
  18.115 -	  else
  18.116 -	    list
  18.117 -      | _ -> list
  18.118 -  in
  18.119 -  let sock_list = Hashtbl.fold find hash [] in
  18.120 -  match sock_list with
  18.121 -    | hd::tl -> hd
  18.122 -    | [] -> raise Unknown_domain
  18.123 -
  18.124 -let attach_debugger ctx =
  18.125 -  match ctx with
  18.126 -  | Domain d  -> Domain.attach_debugger (Domain.get_domain d) 
  18.127 -	                                (Domain.get_vcpu d)
  18.128 -  | Process p ->
  18.129 -      begin
  18.130 -	let xdom_sock = find_xen_domain_context (Process.get_domain p) in
  18.131 -	let xdom_ctx = find_context xdom_sock in
  18.132 -	begin
  18.133 -	  match xdom_ctx with
  18.134 -	    | Xen_domain d ->
  18.135 -		Process.attach_debugger p d
  18.136 -	    | _ -> failwith ("context has wrong xen domain type")
  18.137 -	end;
  18.138 -	raise No_reply
  18.139 -      end
  18.140 -  | _ -> raise (Unimplemented "attach debugger")
  18.141 -
  18.142 -let detach_debugger ctx =
  18.143 -  match ctx with
  18.144 -  | Domain d  -> 
  18.145 -      Domain.detach_debugger (Domain.get_domain d) 
  18.146 -	                     (Domain.get_vcpu d);
  18.147 -      "OK"
  18.148 -  | Process p  ->
  18.149 -      Process.detach_debugger p;
  18.150 -      raise No_reply
  18.151 -  | _ -> raise (Unimplemented "detach debugger")
  18.152 -
  18.153 -
  18.154 -let debug_contexts () =
  18.155 -  print_endline "context list:";
  18.156 -  let print_context key ctx = 
  18.157 -    match ctx with
  18.158 -    | Void -> print_endline (Printf.sprintf "  [%s] {void}" 
  18.159 -			       (Util.get_connection_info key))
  18.160 -    | Xen_virq  -> print_endline (Printf.sprintf "  [%s] {xen virq evtchn}" 
  18.161 -	                          (Util.get_connection_info key))
  18.162 -    | Xen_xcs   -> print_endline (Printf.sprintf "  [%s] {xen xcs socket}" 
  18.163 -			          (Util.get_connection_info key))
  18.164 -    | Xen_domain d -> print_endline (Printf.sprintf "  [%s] %s" 
  18.165 -			          (Util.get_connection_info key) 
  18.166 -                                  (Xen_domain.string_of_context d))
  18.167 -    | Domain d  -> print_endline (Printf.sprintf "  [%s] %s" 
  18.168 -				  (Util.get_connection_info key)
  18.169 -				  (Domain.string_of_context d))
  18.170 -    | Process p -> print_endline (Printf.sprintf "  [%s] %s" 
  18.171 -				  (Util.get_connection_info key)
  18.172 -				  (Process.string_of_context p))
  18.173 -  in
  18.174 -  Hashtbl.iter print_context hash
  18.175 -
  18.176 -(** add_context : add a new context to the hash table.
  18.177 - *  if there is an existing context for the same key then it 
  18.178 - *  is first removed implictly by the hash table replace function.
  18.179 - *)
  18.180 -let add_context (key:Unix.file_descr) context params =
  18.181 -  match context with
  18.182 -  | "void"     -> Hashtbl.replace hash key Void
  18.183 -  | "xen virq" -> Hashtbl.replace hash key Xen_virq
  18.184 -  | "xen xcs"  -> Hashtbl.replace hash key Xen_xcs
  18.185 -  | "domain" -> 
  18.186 -      begin
  18.187 -	match params with
  18.188 -	| dom::vcpu::_ ->
  18.189 -            let d = Domain(Domain.new_context dom vcpu) in
  18.190 -	    attach_debugger d;
  18.191 -            Hashtbl.replace hash key d
  18.192 -	| _ -> failwith "bogus parameters to domain context"
  18.193 -      end
  18.194 -  | "process" -> 
  18.195 -      begin
  18.196 -	match params with
  18.197 -	| dom::pid::_ ->
  18.198 -	    let p = Process(Process.new_context dom pid) in
  18.199 -	    Hashtbl.replace hash key p;
  18.200 -	    attach_debugger p
  18.201 -	| _ -> failwith "bogus parameters to process context"
  18.202 -      end
  18.203 -  | "xen domain"
  18.204 -  | _ -> raise (Unknown_context context)
  18.205 -
  18.206 -(* 
  18.207 - * this is really bogus.  add_xen_domain_context should really
  18.208 - * be a case within add_context.  however, we need to pass in
  18.209 - * a pointer that can only be represented as an int32.
  18.210 - * this would require a different type for params... :(
  18.211 - * 31 bit integers suck.
  18.212 - *)
  18.213 -let add_xen_domain_context (key:Unix.file_descr) dom evtchn sring =
  18.214 -  let d = Xen_domain.new_context dom evtchn sring in
  18.215 -  Hashtbl.replace hash key (Xen_domain(d))
  18.216 -
  18.217 -
  18.218 -let add_default_context sock =
  18.219 -  add_context sock "void" []
  18.220 -
  18.221 -(***************************************************************************)
  18.222 -
  18.223 -(***************************************************************************)
  18.224 -
  18.225 -let read_register ctx register =    (* register is int32 because of sscanf *)
  18.226 -  match ctx with
  18.227 -  | Void -> 0l                                      (* default for startup *)
  18.228 -  | Domain d  -> Domain.read_register d register
  18.229 -  | Process p ->
  18.230 -      begin
  18.231 -	Process.read_register p register;
  18.232 -	raise No_reply
  18.233 -      end
  18.234 -  | _ -> raise (Unimplemented "read registers")
  18.235 -
  18.236 -let read_registers ctx =
  18.237 -  match ctx with
  18.238 -  | Void -> Intel.null_registers                    (* default for startup *)
  18.239 -  | Domain d  -> Domain.read_registers d 
  18.240 -  | Process p ->
  18.241 -      begin
  18.242 -	Process.read_registers p;
  18.243 -	raise No_reply
  18.244 -      end
  18.245 -  | _ -> raise (Unimplemented "read registers")
  18.246 -
  18.247 -let write_register ctx register value =
  18.248 -  match ctx with
  18.249 -  | Domain d  -> Domain.write_register d register value
  18.250 -  | Process p ->
  18.251 -      begin
  18.252 -	Process.write_register p register value;
  18.253 -	raise No_reply
  18.254 -      end
  18.255 -  | _ -> raise (Unimplemented "write register")
  18.256 -
  18.257 -
  18.258 -let read_memory ctx addr len =
  18.259 -  match ctx with
  18.260 -  | Domain d  -> Domain.read_memory d addr len
  18.261 -  | Process p ->
  18.262 -      begin
  18.263 -	Process.read_memory p addr len;
  18.264 -	raise No_reply
  18.265 -      end
  18.266 -  | _ -> raise (Unimplemented "read memory")
  18.267 -
  18.268 -let write_memory ctx addr values =
  18.269 -  match ctx with
  18.270 -  | Domain d  -> Domain.write_memory d addr values
  18.271 -  | Process p ->
  18.272 -      begin
  18.273 -	Process.write_memory p addr values;
  18.274 -	raise No_reply
  18.275 -      end
  18.276 -  | _ -> raise (Unimplemented "write memory")
  18.277 -
  18.278 -
  18.279 -let continue ctx =
  18.280 -  match ctx with
  18.281 -  | Domain d  -> Domain.continue d
  18.282 -  | Process p  -> Process.continue p
  18.283 -  | _ -> raise (Unimplemented "continue")
  18.284 -
  18.285 -let step ctx =
  18.286 -  match ctx with
  18.287 -  | Domain d  -> Domain.step d
  18.288 -  | Process p  -> Process.step p
  18.289 -  | _ -> raise (Unimplemented "step")
  18.290 -
  18.291 -
  18.292 -let insert_memory_breakpoint ctx addr len =
  18.293 -  match ctx with
  18.294 -  | Domain d  -> Domain.insert_memory_breakpoint d addr len
  18.295 -  | Process p  ->
  18.296 -      begin
  18.297 -	Process.insert_memory_breakpoint p addr len;
  18.298 -	raise No_reply
  18.299 -      end
  18.300 -  | _ -> raise (Unimplemented "insert memory breakpoint")
  18.301 -
  18.302 -let remove_memory_breakpoint ctx addr len =
  18.303 -  match ctx with
  18.304 -  | Domain d  -> Domain.remove_memory_breakpoint d addr len
  18.305 -  | Process p  ->
  18.306 -      begin
  18.307 -	Process.remove_memory_breakpoint p addr len;
  18.308 -	raise No_reply
  18.309 -      end
  18.310 -  | _ -> raise (Unimplemented "remove memory breakpoint")
  18.311 -
  18.312 -let insert_watchpoint ctx kind addr len =
  18.313 -  match ctx with
  18.314 -(*  | Domain d  -> Domain.insert_watchpoint d kind addr len  TODO *)
  18.315 -  | Process p  ->
  18.316 -      begin
  18.317 -	Process.insert_watchpoint p kind addr len;
  18.318 -	raise No_reply
  18.319 -      end
  18.320 -  | _ -> raise (Unimplemented "insert watchpoint")
  18.321 -
  18.322 -let remove_watchpoint ctx kind addr len =
  18.323 -  match ctx with
  18.324 -(*  | Domain d  -> Domain.remove_watchpoint d kind addr len  TODO *)
  18.325 -  | Process p  ->
  18.326 -      begin
  18.327 -	Process.remove_watchpoint p kind addr len;
  18.328 -	raise No_reply
  18.329 -      end
  18.330 -  | _ -> raise (Unimplemented "remove watchpoint")
  18.331 -
  18.332 -
  18.333 -let pause ctx =
  18.334 -  match ctx with
  18.335 -  | Domain d  -> Domain.pause d
  18.336 -  | Process p  -> Process.pause p
  18.337 -  | _ -> raise (Unimplemented "pause target")
  18.338 -
  18.339 -
  18.340 -external open_debugger : unit -> unit = "open_context"
  18.341 -external close_debugger : unit -> unit = "close_context"
  18.342 -
  18.343 -(* this is just the domains right now... expand to other contexts later *)
  18.344 -external debugger_status : unit -> unit = "debugger_status"
  18.345 -
    19.1 --- a/tools/debugger/pdb/Process.ml	Sun Oct 01 11:39:41 2006 -0600
    19.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.3 @@ -1,79 +0,0 @@
    19.4 -(** Process.ml
    19.5 - *
    19.6 - *  process context implementation
    19.7 - *
    19.8 - *  @author copyright (c) 2005 alex ho
    19.9 - *  @see <www.cl.cam.ac.uk/netos/pdb> pervasive debugger
   19.10 - *  @version 1
   19.11 - *)
   19.12 -
   19.13 -open Int32
   19.14 -open Intel
   19.15 -
   19.16 -type context_t =
   19.17 -{
   19.18 -  mutable domain  : int;
   19.19 -  mutable process : int;
   19.20 -  mutable evtchn  : int;
   19.21 -  mutable ring    : int32;
   19.22 -}
   19.23 -
   19.24 -let default_context = { domain = 0; process = 0; evtchn = 0; ring = 0l }
   19.25 -
   19.26 -let new_context dom proc = { domain = dom; process = proc; 
   19.27 -                             evtchn = 0; ring = 0l }
   19.28 -
   19.29 -let string_of_context ctx =
   19.30 -  Printf.sprintf "{process} domain: %d, process: %d"
   19.31 -                 ctx.domain  ctx.process
   19.32 -
   19.33 -let set_domain ctx value =
   19.34 -  ctx.domain <- value;
   19.35 -  print_endline (Printf.sprintf "ctx.domain <- %d" ctx.domain)
   19.36 -
   19.37 -let set_process ctx value =
   19.38 -  ctx.process <- value;
   19.39 -  print_endline (Printf.sprintf "ctx.process <- %d" ctx.process)
   19.40 -
   19.41 -let get_domain ctx =
   19.42 -  ctx.domain
   19.43 -
   19.44 -let get_process ctx =
   19.45 -  ctx.process
   19.46 -
   19.47 -external _attach_debugger : context_t -> unit = "proc_attach_debugger"
   19.48 -external detach_debugger : context_t -> unit = "proc_detach_debugger"
   19.49 -external pause_target : context_t -> unit = "proc_pause_target"
   19.50 -
   19.51 -(* save the event channel and ring for the domain for future use *)
   19.52 -let attach_debugger proc_ctx dom_ctx =
   19.53 -  print_endline (Printf.sprintf "%d %lx"
   19.54 -    (Xen_domain.get_evtchn dom_ctx)
   19.55 -    (Xen_domain.get_ring dom_ctx));
   19.56 -  proc_ctx.evtchn <- Xen_domain.get_evtchn dom_ctx;
   19.57 -  proc_ctx.ring   <- Xen_domain.get_ring   dom_ctx;
   19.58 -  _attach_debugger proc_ctx
   19.59 -
   19.60 -external read_register : context_t -> int -> unit = "proc_read_register"
   19.61 -external read_registers : context_t -> unit = "proc_read_registers"
   19.62 -external write_register : context_t -> register -> int32 -> unit =
   19.63 -  "proc_write_register"
   19.64 -external read_memory : context_t -> int32 -> int -> unit = 
   19.65 -  "proc_read_memory"
   19.66 -external write_memory : context_t -> int32 -> int list -> unit = 
   19.67 -  "proc_write_memory"
   19.68 -
   19.69 -external continue : context_t -> unit = "proc_continue_target"
   19.70 -external step : context_t -> unit = "proc_step_target"
   19.71 -
   19.72 -external insert_memory_breakpoint : context_t -> int32 -> int -> unit = 
   19.73 -  "proc_insert_memory_breakpoint"
   19.74 -external remove_memory_breakpoint : context_t -> int32 -> int -> unit = 
   19.75 -  "proc_remove_memory_breakpoint"
   19.76 -external insert_watchpoint : context_t -> int -> int32 -> int -> unit =
   19.77 -  "proc_insert_watchpoint"
   19.78 -external remove_watchpoint : context_t -> int -> int32 -> int -> unit =
   19.79 -  "proc_remove_watchpoint"
   19.80 -
   19.81 -let pause ctx =
   19.82 -  pause_target ctx
    20.1 --- a/tools/debugger/pdb/Process.mli	Sun Oct 01 11:39:41 2006 -0600
    20.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.3 @@ -1,41 +0,0 @@
    20.4 -(** Process.mli
    20.5 - *
    20.6 - *  process context interface
    20.7 - *
    20.8 - *  @author copyright (c) 2005 alex ho
    20.9 - *  @see <www.cl.cam.ac.uk/netos/pdb> pervasive debugger
   20.10 - *  @version 1
   20.11 - *)
   20.12 -
   20.13 -open Int32
   20.14 -open Intel
   20.15 -
   20.16 -type context_t
   20.17 -
   20.18 -val default_context : context_t
   20.19 -val new_context : int -> int -> context_t
   20.20 -
   20.21 -val set_domain : context_t -> int -> unit
   20.22 -val get_domain : context_t -> int
   20.23 -val set_process : context_t -> int -> unit
   20.24 -val get_process : context_t -> int
   20.25 -
   20.26 -val string_of_context : context_t -> string
   20.27 -
   20.28 -val attach_debugger : context_t -> Xen_domain.context_t -> unit
   20.29 -val detach_debugger : context_t -> unit
   20.30 -val pause : context_t -> unit
   20.31 -
   20.32 -val read_register : context_t -> int -> unit
   20.33 -val read_registers : context_t -> unit
   20.34 -val write_register : context_t -> register -> int32 -> unit
   20.35 -val read_memory : context_t -> int32 -> int -> unit
   20.36 -val write_memory : context_t -> int32 -> int list -> unit
   20.37 -	
   20.38 -val continue : context_t -> unit
   20.39 -val step : context_t -> unit
   20.40 -
   20.41 -val insert_memory_breakpoint : context_t -> int32 -> int -> unit
   20.42 -val remove_memory_breakpoint : context_t -> int32 -> int -> unit
   20.43 -val insert_watchpoint : context_t -> int -> int32 -> int -> unit
   20.44 -val remove_watchpoint : context_t -> int -> int32 -> int -> unit
    21.1 --- a/tools/debugger/pdb/Util.ml	Sun Oct 01 11:39:41 2006 -0600
    21.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.3 @@ -1,165 +0,0 @@
    21.4 -(** Util.ml
    21.5 - *
    21.6 - *  various utility functions
    21.7 - *
    21.8 - *  @author copyright (c) 2005 alex ho
    21.9 - *  @see <www.cl.cam.ac.uk/netos/pdb> pervasive debugger
   21.10 - *  @version 1
   21.11 - *)
   21.12 -
   21.13 -let int_of_hexchar h = 
   21.14 -  let i = int_of_char h in
   21.15 -  match h with
   21.16 -  | '0' .. '9' -> i - (int_of_char '0')
   21.17 -  | 'a' .. 'f' -> i - (int_of_char 'a') + 10
   21.18 -  | 'A' .. 'F' -> i - (int_of_char 'A') + 10
   21.19 -  | _ -> raise (Invalid_argument "unknown hex character")
   21.20 -
   21.21 -let hexchar_of_int i = 
   21.22 -  let hexchars = [| '0'; '1'; '2'; '3'; '4'; '5'; '6'; '7';
   21.23 -		    '8'; '9'; 'a'; 'b'; 'c'; 'd'; 'e'; 'f' |]
   21.24 -  in
   21.25 -  hexchars.(i)
   21.26 -
   21.27 -
   21.28 -(** flip the bytes of a four byte int 
   21.29 - *)
   21.30 -
   21.31 -let flip_int num =
   21.32 -  let a = num mod 256
   21.33 -  and b = (num / 256) mod 256
   21.34 -  and c = (num / (256 * 256)) mod 256
   21.35 -  and d = (num / (256 * 256 * 256)) in
   21.36 -  (a * 256 * 256 * 256) + (b * 256 * 256) + (c * 256) + d
   21.37 -
   21.38 -    
   21.39 -let flip_int32 num =
   21.40 -  let a = Int32.logand num 0xffl
   21.41 -  and b = Int32.logand (Int32.shift_right_logical num 8)  0xffl
   21.42 -  and c = Int32.logand (Int32.shift_right_logical num 16) 0xffl
   21.43 -  and d =              (Int32.shift_right_logical num 24)       in
   21.44 -  (Int32.logor
   21.45 -     (Int32.logor (Int32.shift_left a 24) (Int32.shift_left b 16))
   21.46 -     (Int32.logor (Int32.shift_left c 8)  d))
   21.47 -
   21.48 -
   21.49 -let int_list_of_string_list list =
   21.50 -  List.map (fun x -> int_of_string x) list
   21.51 -    
   21.52 -let int_list_of_string str len =
   21.53 -  let array_of_string s =
   21.54 -    let int_array = Array.make len 0 in
   21.55 -    for loop = 0 to len - 1 do
   21.56 -      int_array.(loop) <- (Char.code s.[loop]);
   21.57 -    done;
   21.58 -    int_array
   21.59 -  in
   21.60 -  Array.to_list (array_of_string str)
   21.61 -
   21.62 -
   21.63 -(* remove leading and trailing whitespace from a string *)
   21.64 -
   21.65 -let chomp str =
   21.66 -  let head = Str.regexp "^[ \t\r\n]+" in
   21.67 -  let tail = Str.regexp "[ \t\r\n]+$" in
   21.68 -  let str = Str.global_replace head "" str in
   21.69 -  Str.global_replace tail "" str
   21.70 -
   21.71 -(* Stupid little parser for    "<key>=<value>[,<key>=<value>]*"
   21.72 -   It first chops the entire command at each ',', so no ',' in key or value!
   21.73 -   Mucked to return a list of words for "value"
   21.74 - *)
   21.75 -
   21.76 -let list_of_string str =
   21.77 -  let delim c = Str.regexp ("[ \t]*" ^ c ^ "[ \t]*") in
   21.78 -  let str_list = Str.split (delim " ") str in
   21.79 -  List.map (fun x -> chomp(x)) str_list
   21.80 -
   21.81 -let little_parser fn str =
   21.82 -  let delim c = Str.regexp ("[ \t]*" ^ c ^ "[ \t]*") in
   21.83 -  let str_list = Str.split (delim ",") str in
   21.84 -  let pair s =
   21.85 -    match Str.split (delim "=") s with
   21.86 -    | [key;value] -> fn (chomp key) (list_of_string value)
   21.87 -    | [key] -> fn (chomp key) []
   21.88 -    | _ -> failwith (Printf.sprintf "error: (little_parser) parse error [%s]" str)
   21.89 -  in
   21.90 -  List.iter pair str_list
   21.91 -
   21.92 -(* boolean list membership test *)
   21.93 -let not_list_member the_list element =
   21.94 -  try 
   21.95 -    List.find (fun x -> x = element) the_list;
   21.96 -    false
   21.97 -  with
   21.98 -    Not_found -> true
   21.99 -
  21.100 -(* a very inefficient way to remove the elements of one list from another *)
  21.101 -let list_remove the_list remove_list =
  21.102 -  List.filter (not_list_member remove_list) the_list
  21.103 -
  21.104 -(* get a description of a file descriptor *)
  21.105 -let get_connection_info fd =
  21.106 -  let get_local_info fd =
  21.107 -    let sockname = Unix.getsockname fd in
  21.108 -    match sockname with
  21.109 -    | Unix.ADDR_UNIX(s) -> "unix"
  21.110 -    | Unix.ADDR_INET(a,p) -> ((Unix.string_of_inet_addr a) ^ ":" ^
  21.111 -			      (string_of_int p))
  21.112 -  and get_remote_info fd =
  21.113 -    let sockname = Unix.getpeername fd in 
  21.114 -    match sockname with
  21.115 -    | Unix.ADDR_UNIX(s) -> s
  21.116 -    | Unix.ADDR_INET(a,p) -> ((Unix.string_of_inet_addr a) ^ ":" ^
  21.117 -			      (string_of_int p))
  21.118 -  in
  21.119 -  try
  21.120 -    get_remote_info fd
  21.121 -  with
  21.122 -  | Unix.Unix_error (Unix.ENOTSOCK, s1, s2) -> 
  21.123 -      let s = Unix.fstat fd in
  21.124 -      Printf.sprintf "dev: %d, inode: %d" s.Unix.st_dev s.Unix.st_ino
  21.125 -  | Unix.Unix_error (Unix.EBADF, s1, s2) -> 
  21.126 -      let s = Unix.fstat fd in
  21.127 -      Printf.sprintf "dev: %d, inode: %d" s.Unix.st_dev s.Unix.st_ino
  21.128 -  | _ -> get_local_info fd
  21.129 -
  21.130 -
  21.131 -(* really write a string *)
  21.132 -let really_write fd str =
  21.133 -  let strlen = String.length str in
  21.134 -  let sent = ref 0 in
  21.135 -  while (!sent < strlen) do
  21.136 -    sent := !sent + (Unix.write fd str !sent (strlen - !sent))
  21.137 -  done
  21.138 -
  21.139 -let write_character fd ch =
  21.140 -  let str = String.create 1 in
  21.141 -  str.[0] <- ch;
  21.142 -  really_write fd str
  21.143 -
  21.144 -
  21.145 -
  21.146 -let send_reply fd reply =
  21.147 -  let checksum = ref 0 in
  21.148 -  write_character fd '$';
  21.149 -  for loop = 0 to (String.length reply) - 1 do
  21.150 -    write_character fd reply.[loop];
  21.151 -    checksum := !checksum + int_of_char reply.[loop]
  21.152 -  done;
  21.153 -  write_character fd '#';
  21.154 -  write_character fd (hexchar_of_int ((!checksum mod 256) / 16));
  21.155 -  write_character fd (hexchar_of_int ((!checksum mod 256) mod 16))
  21.156 -  (*
  21.157 -   * BUG NEED TO LISTEN FOR REPLY +/- AND POSSIBLY RE-TRANSMIT
  21.158 -   *)
  21.159 -
  21.160 -
  21.161 -(** A few debugger commands such as step 's' and continue 'c' do 
  21.162 - *  not immediately return a response to the debugger.  In these 
  21.163 - *  cases we raise No_reply instead. 
  21.164 - *  This is also used by some contexts (such as Linux processes)
  21.165 - *  which utilize an asynchronous request / response protocol when
  21.166 - *  communicating with their respective backends.
  21.167 - *)
  21.168 -exception No_reply
    22.1 --- a/tools/debugger/pdb/Xen_domain.ml	Sun Oct 01 11:39:41 2006 -0600
    22.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.3 @@ -1,43 +0,0 @@
    22.4 -(** Xen_domain.ml
    22.5 - *
    22.6 - *  domain assist for debugging processes
    22.7 - *
    22.8 - *  @author copyright (c) 2005 alex ho
    22.9 - *  @see <www.cl.cam.ac.uk/netos/pdb> pervasive debugger
   22.10 - *  @version 1
   22.11 - *)
   22.12 -
   22.13 -type context_t =
   22.14 -{
   22.15 -  mutable domain : int;
   22.16 -  mutable evtchn : int;
   22.17 -  mutable pdb_front_ring : int32
   22.18 -}
   22.19 -
   22.20 -let default_context = { domain = 0; evtchn = 0; pdb_front_ring = 0l }
   22.21 -
   22.22 -let new_context dom evtchn ring = 
   22.23 -  {domain = dom; evtchn = evtchn; pdb_front_ring = ring}
   22.24 -
   22.25 -let set_domain ctx value =
   22.26 -  ctx.domain <- value
   22.27 -
   22.28 -let set_evtchn ctx value =
   22.29 -  ctx.evtchn <- value
   22.30 -
   22.31 -let set_ring ctx value =
   22.32 -  ctx.pdb_front_ring <- value
   22.33 -
   22.34 -let get_domain ctx =
   22.35 -  ctx.domain
   22.36 -
   22.37 -let get_evtchn ctx =
   22.38 -  ctx.evtchn
   22.39 -
   22.40 -let get_ring ctx =
   22.41 -  ctx.pdb_front_ring
   22.42 -
   22.43 -let string_of_context ctx =
   22.44 -      Printf.sprintf "{xen domain assist} domain: %d" ctx.domain 
   22.45 -
   22.46 -external process_response : int32 -> int * int * string = "process_handle_response"
    23.1 --- a/tools/debugger/pdb/Xen_domain.mli	Sun Oct 01 11:39:41 2006 -0600
    23.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.3 @@ -1,25 +0,0 @@
    23.4 -(** Xen_domain.ml
    23.5 - *
    23.6 - *  domain assist for debugging processes
    23.7 - *
    23.8 - *  @author copyright (c) 2005 alex ho
    23.9 - *  @see <www.cl.cam.ac.uk/netos/pdb> pervasive debugger
   23.10 - *  @version 1
   23.11 - *)
   23.12 -
   23.13 -type context_t
   23.14 -
   23.15 -val default_context : context_t
   23.16 -val new_context : int -> int -> int32 -> context_t 
   23.17 -
   23.18 -val set_domain : context_t -> int -> unit
   23.19 -val get_domain : context_t -> int
   23.20 -val set_evtchn : context_t -> int -> unit
   23.21 -val get_evtchn : context_t -> int
   23.22 -val set_ring   : context_t -> int32 -> unit
   23.23 -val get_ring   : context_t -> int32
   23.24 -
   23.25 -val string_of_context : context_t -> string
   23.26 -
   23.27 -val process_response : int32 -> int * int * string
   23.28 -
    24.1 --- a/tools/debugger/pdb/debugger.ml	Sun Oct 01 11:39:41 2006 -0600
    24.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.3 @@ -1,372 +0,0 @@
    24.4 -(** debugger.ml
    24.5 - *
    24.6 - *  main debug functionality
    24.7 - *
    24.8 - *  @author copyright (c) 2005 alex ho
    24.9 - *  @see <www.cl.cam.ac.uk/netos/pdb> pervasive debugger
   24.10 - *  @version 1
   24.11 - *)
   24.12 -
   24.13 -open Intel
   24.14 -open PDB
   24.15 -open Util
   24.16 -open Str
   24.17 -
   24.18 -let initialize_debugger () =
   24.19 -  ()
   24.20 -
   24.21 -let exit_debugger () =
   24.22 -  ()
   24.23 -
   24.24 -
   24.25 -(**
   24.26 -   Detach Command
   24.27 -   Note: response is ignored by gdb.  We leave the context in the
   24.28 -   hash.  It will be cleaned up with the socket is closed.
   24.29 - *)
   24.30 -let gdb_detach ctx =
   24.31 -  PDB.detach_debugger ctx
   24.32 -
   24.33 -(**
   24.34 -   Kill Command
   24.35 -   Note: response is ignored by gdb.  We leave the context in the
   24.36 -   hash.  It will be cleaned up with the socket is closed.
   24.37 - *)
   24.38 -let gdb_kill () =
   24.39 -  ""
   24.40 -
   24.41 -
   24.42 -
   24.43 -(**
   24.44 -   Continue Command.
   24.45 -   resume the target
   24.46 - *)
   24.47 -let gdb_continue ctx =
   24.48 -  PDB.continue ctx;
   24.49 -  raise No_reply
   24.50 -
   24.51 -(**
   24.52 -   Step Command.
   24.53 -   single step the target
   24.54 - *)
   24.55 -let gdb_step ctx =
   24.56 -  PDB.step ctx;
   24.57 -  raise No_reply
   24.58 -
   24.59 -(**
   24.60 -   Read Register Command.
   24.61 -   return register as a 4-byte value.
   24.62 - *)
   24.63 -let gdb_read_register ctx command =
   24.64 -  let read_reg register =
   24.65 -    (Printf.sprintf "%08lx" (Util.flip_int32 (PDB.read_register ctx register)))
   24.66 -  in
   24.67 -  Scanf.sscanf command "p%x" read_reg
   24.68 -    
   24.69 -
   24.70 -(**
   24.71 -   Read Registers Command.
   24.72 -   returns 16 4-byte registers in a particular format defined by gdb.
   24.73 - *)
   24.74 -let gdb_read_registers ctx =
   24.75 -  let regs = PDB.read_registers ctx in
   24.76 -  let str = 
   24.77 -    (Printf.sprintf "%08lx" (Util.flip_int32 regs.eax)) ^
   24.78 -    (Printf.sprintf "%08lx" (Util.flip_int32 regs.ecx)) ^
   24.79 -    (Printf.sprintf "%08lx" (Util.flip_int32 regs.edx)) ^
   24.80 -    (Printf.sprintf "%08lx" (Util.flip_int32 regs.ebx)) ^
   24.81 -    (Printf.sprintf "%08lx" (Util.flip_int32 regs.esp)) ^
   24.82 -    (Printf.sprintf "%08lx" (Util.flip_int32 regs.ebp)) ^
   24.83 -    (Printf.sprintf "%08lx" (Util.flip_int32 regs.esi)) ^
   24.84 -    (Printf.sprintf "%08lx" (Util.flip_int32 regs.edi)) ^
   24.85 -    (Printf.sprintf "%08lx" (Util.flip_int32 regs.eip)) ^
   24.86 -    (Printf.sprintf "%08lx" (Util.flip_int32 regs.efl)) ^
   24.87 -    (Printf.sprintf "%08lx" (Util.flip_int32 regs.cs)) ^
   24.88 -    (Printf.sprintf "%08lx" (Util.flip_int32 regs.ss)) ^
   24.89 -    (Printf.sprintf "%08lx" (Util.flip_int32 regs.ds)) ^
   24.90 -    (Printf.sprintf "%08lx" (Util.flip_int32 regs.es)) ^
   24.91 -    (Printf.sprintf "%08lx" (Util.flip_int32 regs.fs)) ^
   24.92 -    (Printf.sprintf "%08lx" (Util.flip_int32 regs.gs)) in
   24.93 -  str
   24.94 -      
   24.95 -(**
   24.96 -   Set Thread Command
   24.97 - *)
   24.98 -let gdb_set_thread command =
   24.99 -  "OK"
  24.100 -
  24.101 -
  24.102 -(**
  24.103 -   Read Memory Packets
  24.104 - *)
  24.105 -let gdb_read_memory ctx command =
  24.106 -  let int_list_to_string i str =
  24.107 -    (Printf.sprintf "%02x" i) ^ str
  24.108 -  in
  24.109 -  let read_mem addr len =
  24.110 -    try
  24.111 -      let mem = PDB.read_memory ctx addr len  in
  24.112 -      List.fold_right int_list_to_string mem ""
  24.113 -    with
  24.114 -      Failure s -> "E02"
  24.115 -  in
  24.116 -  Scanf.sscanf command "m%lx,%x" read_mem
  24.117 -
  24.118 -
  24.119 -
  24.120 -(**
  24.121 -   Write Memory Packets
  24.122 - *)
  24.123 -let gdb_write_memory ctx command =
  24.124 -  let write_mem addr len =
  24.125 -    print_endline (Printf.sprintf "  gdb_write_memory %lx %x\n" addr len);
  24.126 -    print_endline (Printf.sprintf "  [[ unimplemented ]]\n")
  24.127 -  in
  24.128 -  Scanf.sscanf command "M%lx,%d" write_mem;
  24.129 -  "OK"
  24.130 -
  24.131 -
  24.132 -
  24.133 -(**
  24.134 -   Write Register Packets
  24.135 - *)
  24.136 -let gdb_write_register ctx command =
  24.137 -  let write_reg reg goofy_val =
  24.138 -    let new_val = Util.flip_int32 goofy_val in
  24.139 -    match reg with
  24.140 -    |  0 -> PDB.write_register ctx EAX new_val
  24.141 -    |  1 -> PDB.write_register ctx ECX new_val
  24.142 -    |  2 -> PDB.write_register ctx EDX new_val
  24.143 -    |  3 -> PDB.write_register ctx EBX new_val
  24.144 -    |  4 -> PDB.write_register ctx ESP new_val
  24.145 -    |  5 -> PDB.write_register ctx EBP new_val
  24.146 -    |  6 -> PDB.write_register ctx ESI new_val
  24.147 -    |  7 -> PDB.write_register ctx EDI new_val
  24.148 -    |  8 -> PDB.write_register ctx EIP new_val
  24.149 -    |  9 -> PDB.write_register ctx EFL new_val
  24.150 -    | 10 -> PDB.write_register ctx CS new_val
  24.151 -    | 11 -> PDB.write_register ctx SS new_val
  24.152 -    | 12 -> PDB.write_register ctx DS new_val
  24.153 -    | 13 -> PDB.write_register ctx ES new_val
  24.154 -    | 14 -> PDB.write_register ctx FS new_val
  24.155 -    | 15 -> PDB.write_register ctx GS new_val
  24.156 -    | _  -> print_endline (Printf.sprintf "write unknown register [%d]" reg)
  24.157 -  in
  24.158 -  Scanf.sscanf command "P%x=%lx" write_reg;
  24.159 -  "OK"
  24.160 -
  24.161 -
  24.162 -(**
  24.163 -   General Query Packets
  24.164 - *)
  24.165 -let gdb_query command =
  24.166 -  match command with
  24.167 -  | "qC" -> ""
  24.168 -  | "qOffsets" -> ""
  24.169 -  | "qSymbol::" -> ""
  24.170 -  | _ -> 
  24.171 -      print_endline (Printf.sprintf "unknown gdb query packet [%s]" command);
  24.172 -      "E01"
  24.173 -
  24.174 -
  24.175 -(**
  24.176 -   Write Memory Binary Packets
  24.177 - *)
  24.178 -let gdb_write_memory_binary ctx command =
  24.179 -  let write_mem addr len =
  24.180 -    let pos = Str.search_forward (Str.regexp ":") command 0 in
  24.181 -    let txt = Str.string_after command (pos + 1) in
  24.182 -    PDB.write_memory ctx addr (int_list_of_string txt len)
  24.183 -  in
  24.184 -  Scanf.sscanf command "X%lx,%d" write_mem;
  24.185 -  "OK"
  24.186 -
  24.187 -
  24.188 -
  24.189 -(**
  24.190 -   Last Signal Command
  24.191 - *)
  24.192 -let gdb_last_signal =
  24.193 -  "S00"
  24.194 -
  24.195 -
  24.196 -
  24.197 -
  24.198 -(**
  24.199 -   Process PDB extensions to the GDB serial protocol.
  24.200 -   Changes the mutable context state.
  24.201 - *)
  24.202 -let pdb_extensions command sock =
  24.203 -  let process_extension key value =
  24.204 -    (* since this command can change the context, 
  24.205 -       we need to grab it again each time *)
  24.206 -    let ctx = PDB.find_context sock in
  24.207 -    match key with
  24.208 -    | "status" ->
  24.209 -	PDB.debug_contexts ();
  24.210 -	(* print_endline ("debugger status");
  24.211 -	   debugger_status () 
  24.212 -	*)
  24.213 -    | "context" ->
  24.214 -        PDB.add_context sock (List.hd value) 
  24.215 -                             (int_list_of_string_list (List.tl value))
  24.216 -    | _ -> failwith (Printf.sprintf "unknown pdb extension command [%s:%s]" 
  24.217 -		                    key (List.hd value))
  24.218 -  in
  24.219 -  try
  24.220 -    Util.little_parser process_extension 
  24.221 -                       (String.sub command 1 ((String.length command) - 1));
  24.222 -    "OK"
  24.223 -  with
  24.224 -  | Unknown_context s -> 
  24.225 -      print_endline (Printf.sprintf "unknown context [%s]" s);
  24.226 -      "E01"
  24.227 -  | Unknown_domain -> "E01"
  24.228 -  | Failure s -> "E01"
  24.229 -
  24.230 -
  24.231 -(**
  24.232 -   Insert Breakpoint or Watchpoint Packet
  24.233 - *)
  24.234 -
  24.235 -let bwc_watch_write  = 102                              (* from pdb_module.h *)
  24.236 -let bwc_watch_read   = 103
  24.237 -let bwc_watch_access = 104
  24.238 -
  24.239 -let gdb_insert_bwcpoint ctx command =
  24.240 -  let insert cmd addr length =
  24.241 -    try
  24.242 -      match cmd with
  24.243 -      | 0 -> PDB.insert_memory_breakpoint ctx addr length; "OK"
  24.244 -      | 2 -> PDB.insert_watchpoint ctx bwc_watch_write  addr length; "OK"
  24.245 -      | 3 -> PDB.insert_watchpoint ctx bwc_watch_read   addr length; "OK"
  24.246 -      | 4 -> PDB.insert_watchpoint ctx bwc_watch_access addr length; "OK"
  24.247 -      | _ -> ""
  24.248 -    with
  24.249 -      Failure s -> "E03"
  24.250 -  in
  24.251 -  Scanf.sscanf command "Z%d,%lx,%x" insert
  24.252 -
  24.253 -(**
  24.254 -   Remove Breakpoint or Watchpoint Packet
  24.255 - *)
  24.256 -let gdb_remove_bwcpoint ctx command =
  24.257 -  let insert cmd addr length =
  24.258 -    try
  24.259 -      match cmd with
  24.260 -      | 0 -> PDB.remove_memory_breakpoint ctx addr length; "OK"
  24.261 -      | 2 -> PDB.remove_watchpoint ctx bwc_watch_write  addr length; "OK"
  24.262 -      | 3 -> PDB.remove_watchpoint ctx bwc_watch_read   addr length; "OK"
  24.263 -      | 4 -> PDB.remove_watchpoint ctx bwc_watch_access addr length; "OK"
  24.264 -      | _ -> ""
  24.265 -    with
  24.266 -      Failure s -> "E04"
  24.267 -  in
  24.268 -  Scanf.sscanf command "z%d,%lx,%d" insert
  24.269 -
  24.270 -(**
  24.271 -   Do Work!
  24.272 -
  24.273 -   @param command  char list
  24.274 - *)
  24.275 -
  24.276 -let process_command command sock =
  24.277 -  let ctx = PDB.find_context sock in
  24.278 -  try
  24.279 -    match command.[0] with
  24.280 -    | 'c' -> gdb_continue ctx
  24.281 -    | 'D' -> gdb_detach ctx
  24.282 -    | 'g' -> gdb_read_registers ctx
  24.283 -    | 'H' -> gdb_set_thread command
  24.284 -    | 'k' -> gdb_kill ()
  24.285 -    | 'm' -> gdb_read_memory ctx command
  24.286 -    | 'M' -> gdb_write_memory ctx command
  24.287 -    | 'p' -> gdb_read_register ctx command
  24.288 -    | 'P' -> gdb_write_register ctx command
  24.289 -    | 'q' -> gdb_query command
  24.290 -    | 's' -> gdb_step ctx
  24.291 -    | 'x' -> pdb_extensions command sock
  24.292 -    | 'X' -> gdb_write_memory_binary ctx command
  24.293 -    | '?' -> gdb_last_signal
  24.294 -    | 'z' -> gdb_remove_bwcpoint ctx command
  24.295 -    | 'Z' -> gdb_insert_bwcpoint ctx command
  24.296 -    | _ -> 
  24.297 -	print_endline (Printf.sprintf "unknown gdb command [%s]" command);
  24.298 -	""
  24.299 -  with
  24.300 -    Unimplemented s ->
  24.301 -      print_endline (Printf.sprintf "loser. unimplemented command [%s][%s]" 
  24.302 -		                    command s);
  24.303 -      "E03"
  24.304 -
  24.305 -(**
  24.306 -   process_xen_domain
  24.307 -
  24.308 -   This is called whenever a domain debug assist responds to a
  24.309 -   pdb packet.
  24.310 -*)
  24.311 -
  24.312 -let process_xen_domain fd =
  24.313 -  let channel = Evtchn.read fd in
  24.314 -  let ctx = find_context fd in
  24.315 -  
  24.316 -  let (dom, pid, str) =
  24.317 -  begin
  24.318 -    match ctx with
  24.319 -      | Xen_domain d -> Xen_domain.process_response (Xen_domain.get_ring d)
  24.320 -      | _ -> failwith ("process_xen_domain called without Xen_domain context")
  24.321 -  end 
  24.322 -  in
  24.323 -  let sock = PDB.find_process dom pid in
  24.324 -  print_endline (Printf.sprintf "(linux) dom:%d pid:%d  %s  %s" 
  24.325 -		   dom pid str (Util.get_connection_info sock));
  24.326 -  Util.send_reply sock str;
  24.327 -  Evtchn.unmask fd channel                                (* allow next virq *)
  24.328 -  
  24.329 -
  24.330 -(**
  24.331 -   process_xen_virq
  24.332 -
  24.333 -   This is called each time a virq_pdb is sent from xen to dom 0.
  24.334 -   It is sent by Xen when a domain hits a breakpoint. 
  24.335 -
  24.336 -   Think of this as the continuation function for a "c" or "s" command
  24.337 -   issued to a domain.
  24.338 -*)
  24.339 -
  24.340 -external query_domain_stop : unit -> (int * int) list = "query_domain_stop"
  24.341 -(* returns a list of paused domains : () -> (domain, vcpu) list *)
  24.342 -
  24.343 -let process_xen_virq fd =
  24.344 -  let channel = Evtchn.read fd in
  24.345 -  let find_pair (dom, vcpu) =
  24.346 -    print_endline (Printf.sprintf "checking %d.%d" dom vcpu);
  24.347 -    try
  24.348 -      let sock = PDB.find_domain dom vcpu in
  24.349 -      true
  24.350 -    with
  24.351 -      Unknown_domain -> false
  24.352 -  in
  24.353 -  let dom_list = query_domain_stop () in
  24.354 -  let (dom, vcpu) = List.find find_pair dom_list in
  24.355 -  let vec = 3 in
  24.356 -  let sock = PDB.find_domain dom vcpu in
  24.357 -  print_endline (Printf.sprintf "handle bkpt dom:%d vcpu:%d vec:%d  %s" 
  24.358 -		   dom vcpu vec (Util.get_connection_info sock));
  24.359 -  Util.send_reply sock "S05";
  24.360 -  Evtchn.unmask fd channel                                (* allow next virq *)
  24.361 -  
  24.362 -
  24.363 -(**
  24.364 -   process_xen_xcs
  24.365 -
  24.366 -   This is called each time the software assist residing in a backend 
  24.367 -   domain starts up.  The control message includes the address of a 
  24.368 -   shared ring page and our end of an event channel (which indicates
  24.369 -   when data is available on the ring).
  24.370 -*)
  24.371 -
  24.372 -let process_xen_xcs xcs_fd =
  24.373 -  let (local_evtchn_fd, evtchn, dom, ring) = Xcs.read xcs_fd in
  24.374 -  add_xen_domain_context local_evtchn_fd dom evtchn ring;
  24.375 -  local_evtchn_fd
    25.1 --- a/tools/debugger/pdb/evtchn.ml	Sun Oct 01 11:39:41 2006 -0600
    25.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.3 @@ -1,40 +0,0 @@
    25.4 -(** evtchn.ml
    25.5 - *
    25.6 - *  event channel interface
    25.7 - *
    25.8 - *  @author copyright (c) 2005 alex ho
    25.9 - *  @see <www.cl.cam.ac.uk/netos/pdb> pervasive debugger
   25.10 - *  @version 1
   25.11 - *)
   25.12 -
   25.13 -let dev_name = "/dev/xen/evtchn"                          (* EVTCHN_DEV_NAME *)
   25.14 -let dev_major = 10                                       (* EVTCHN_DEV_MAJOR *)
   25.15 -let dev_minor = 201                                      (* EVTCHN_DEV_MINOR *)
   25.16 -
   25.17 -let virq_pdb = 6                                      (* as defined VIRQ_PDB *)
   25.18 -
   25.19 -external bind_virq : int -> int = "evtchn_bind_virq"
   25.20 -external bind_interdomain : int -> int * int = "evtchn_bind_interdomain"
   25.21 -external bind : Unix.file_descr -> int -> unit = "evtchn_bind"
   25.22 -external unbind : Unix.file_descr -> int -> unit = "evtchn_unbind"
   25.23 -external ec_open : string -> int -> int -> Unix.file_descr = "evtchn_open"
   25.24 -external read : Unix.file_descr -> int = "evtchn_read"
   25.25 -external ec_close : Unix.file_descr -> unit = "evtchn_close"
   25.26 -external unmask : Unix.file_descr -> int -> unit = "evtchn_unmask"
   25.27 -
   25.28 -let _setup () =
   25.29 -  let fd = ec_open dev_name dev_major dev_minor in
   25.30 -  fd
   25.31 -
   25.32 -let _bind fd port =
   25.33 -  bind fd port
   25.34 -
   25.35 -let setup () =
   25.36 -  let port = bind_virq virq_pdb in
   25.37 -  let fd = _setup() in
   25.38 -  _bind fd port;
   25.39 -  fd
   25.40 -
   25.41 -let teardown fd =
   25.42 -  unbind fd virq_pdb;
   25.43 -  ec_close fd
    26.1 --- a/tools/debugger/pdb/evtchn.mli	Sun Oct 01 11:39:41 2006 -0600
    26.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.3 @@ -1,19 +0,0 @@
    26.4 -(** evtchn.mli
    26.5 - *
    26.6 - *  event channel interface
    26.7 - *
    26.8 - *  @author copyright (c) 2005 alex ho
    26.9 - *  @see <www.cl.cam.ac.uk/netos/pdb> pervasive debugger
   26.10 - *  @version 1
   26.11 - *)
   26.12 -
   26.13 -val _setup : unit -> Unix.file_descr
   26.14 -val _bind : Unix.file_descr -> int -> unit
   26.15 -
   26.16 -val bind_interdomain : int -> int * int
   26.17 -
   26.18 -
   26.19 -val setup : unit -> Unix.file_descr
   26.20 -val read : Unix.file_descr -> int
   26.21 -val teardown : Unix.file_descr -> unit
   26.22 -val unmask : Unix.file_descr -> int -> unit
    27.1 --- a/tools/debugger/pdb/linux-2.6-module/Makefile	Sun Oct 01 11:39:41 2006 -0600
    27.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.3 @@ -1,21 +0,0 @@
    27.4 -XEN_ROOT   = ../../../..
    27.5 -LINUX_DIR  = linux-2.6.12-xenU
    27.6 -KDIR       = $(XEN_ROOT)/$(LINUX_DIR)
    27.7 -
    27.8 -obj-m    += pdb.o
    27.9 -pdb-objs += module.o
   27.10 -pdb-objs += debug.o
   27.11 -
   27.12 -CFLAGS += -g
   27.13 -CFLAGS += -Wall
   27.14 -CFLAGS += -Werror
   27.15 -
   27.16 -.PHONY: module 
   27.17 -module : 
   27.18 -#	make KBUILD_VERBOSE=1 ARCH=xen -C $(KDIR) M=$(PWD) modules
   27.19 -	make                  ARCH=xen -C $(KDIR) M=$(PWD) modules
   27.20 -
   27.21 -.PHONY: clean 
   27.22 -clean :
   27.23 -	make -C $(KDIR) M=$(PWD) clean
   27.24 -
    28.1 --- a/tools/debugger/pdb/linux-2.6-module/debug.c	Sun Oct 01 11:39:41 2006 -0600
    28.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.3 @@ -1,851 +0,0 @@
    28.4 -/*
    28.5 - * debug.c
    28.6 - * pdb debug functionality for processes.
    28.7 - */
    28.8 -
    28.9 -#include <linux/module.h>
   28.10 -#include <linux/mm.h>
   28.11 -#include <linux/sched.h>
   28.12 -#include <asm-i386/kdebug.h>
   28.13 -#include <asm-i386/mach-xen/asm/processor.h>
   28.14 -#include <asm-i386/mach-xen/asm/ptrace.h>
   28.15 -#include <asm-i386/mach-xen/asm/tlbflush.h>
   28.16 -#include <xen/interface/xen.h>
   28.17 -#include "pdb_module.h"
   28.18 -#include "pdb_debug.h"
   28.19 -
   28.20 -
   28.21 -static int pdb_debug_fn (struct pt_regs *regs, long error_code,
   28.22 -                         unsigned int condition);
   28.23 -static int pdb_int3_fn (struct pt_regs *regs, long error_code);
   28.24 -static int pdb_page_fault_fn (struct pt_regs *regs, long error_code,
   28.25 -                              unsigned int condition);
   28.26 -
   28.27 -/***********************************************************************/
   28.28 -
   28.29 -typedef struct bwcpoint                           /* break/watch/catch point */
   28.30 -{
   28.31 -    struct list_head list;
   28.32 -    unsigned long address;
   28.33 -    int length;
   28.34 -
   28.35 -    uint8_t  type;                                                     /* BWC_??? */
   28.36 -    uint8_t  mode;                   /* for BWC_PAGE, the current protection mode */
   28.37 -    uint32_t process;
   28.38 -    uint8_t  error;                /* error occured when enabling: don't disable. */
   28.39 -
   28.40 -    /* original values */
   28.41 -    uint8_t    orig_bkpt;                               /* single byte breakpoint */
   28.42 -    pte_t orig_pte;
   28.43 -
   28.44 -    struct list_head watchpt_read_list;     /* read watchpoints on this page */
   28.45 -    struct list_head watchpt_write_list;                            /* write */
   28.46 -    struct list_head watchpt_access_list;                          /* access */
   28.47 -    struct list_head watchpt_disabled_list;                      /* disabled */
   28.48 -
   28.49 -    struct bwcpoint *parent;             /* watchpoint: bwc_watch (the page) */
   28.50 -    struct bwcpoint *watchpoint;      /* bwc_watch_step: original watchpoint */
   28.51 -} bwcpoint_t, *bwcpoint_p;
   28.52 -
   28.53 -static struct list_head bwcpoint_list = LIST_HEAD_INIT(bwcpoint_list);
   28.54 -
   28.55 -#define _pdb_bwcpoint_alloc(_var) \
   28.56 -{ \
   28.57 -    if ( (_var = kmalloc(sizeof(bwcpoint_t), GFP_KERNEL)) == NULL ) \
   28.58 -        printk("error: unable to allocate memory %d\n", __LINE__); \
   28.59 -    else { \
   28.60 -        memset(_var, 0, sizeof(bwcpoint_t)); \
   28.61 -        INIT_LIST_HEAD(&_var->watchpt_read_list); \
   28.62 -        INIT_LIST_HEAD(&_var->watchpt_write_list); \
   28.63 -        INIT_LIST_HEAD(&_var->watchpt_access_list); \
   28.64 -        INIT_LIST_HEAD(&_var->watchpt_disabled_list); \
   28.65 -    } \
   28.66 -}
   28.67 -
   28.68 -/***********************************************************************/
   28.69 -
   28.70 -static void _pdb_bwc_print_list (struct list_head *, char *, int);
   28.71 -
   28.72 -static void
   28.73 -_pdb_bwc_print (bwcpoint_p bwc, char *label, int level)
   28.74 -{
   28.75 -    printk("%s%03d 0x%08lx:0x%02x %c\n", label, bwc->type,
   28.76 -           bwc->address, bwc->length, bwc->error ? 'e' : '-');
   28.77 -
   28.78 -    if ( !list_empty(&bwc->watchpt_read_list) )
   28.79 -        _pdb_bwc_print_list(&bwc->watchpt_read_list, "r", level);
   28.80 -    if ( !list_empty(&bwc->watchpt_write_list) )
   28.81 -        _pdb_bwc_print_list(&bwc->watchpt_write_list, "w", level);
   28.82 -    if ( !list_empty(&bwc->watchpt_access_list) )
   28.83 -        _pdb_bwc_print_list(&bwc->watchpt_access_list, "a", level);
   28.84 -    if ( !list_empty(&bwc->watchpt_disabled_list) )
   28.85 -        _pdb_bwc_print_list(&bwc->watchpt_disabled_list, "d", level);
   28.86 -}
   28.87 -
   28.88 -static void
   28.89 -_pdb_bwc_print_list (struct list_head *bwc_list, char *label, int level)
   28.90 -{
   28.91 -    struct list_head *ptr;
   28.92 -    int counter = 0;
   28.93 -
   28.94 -    list_for_each(ptr, bwc_list)
   28.95 -    {
   28.96 -        bwcpoint_p bwc = list_entry(ptr, bwcpoint_t, list);
   28.97 -        printk("  %s[%02d]%s ", level > 0 ? "  " : "", counter++,
   28.98 -                                level > 0 ? "" : "  ");
   28.99 -        _pdb_bwc_print(bwc, label, level+1);
  28.100 -    }
  28.101 -
  28.102 -    if (counter == 0)
  28.103 -    {
  28.104 -        printk("  empty list\n");
  28.105 -    }
  28.106 -}
  28.107 -
  28.108 -void
  28.109 -pdb_bwc_print_list (void)
  28.110 -{
  28.111 -    _pdb_bwc_print_list(&bwcpoint_list, " ", 0);
  28.112 -}
  28.113 -
  28.114 -bwcpoint_p
  28.115 -pdb_search_watchpoint (uint32_t process, unsigned long address)
  28.116 -{
  28.117 -    bwcpoint_p bwc_watch = (bwcpoint_p) 0;
  28.118 -    bwcpoint_p bwc_entry = (bwcpoint_p) 0;
  28.119 -    struct list_head *ptr;
  28.120 -
  28.121 -    list_for_each(ptr, &bwcpoint_list)                /* find bwc page entry */
  28.122 -    {
  28.123 -        bwc_watch = list_entry(ptr, bwcpoint_t, list);
  28.124 -        if (bwc_watch->address == (address & PAGE_MASK)) break;
  28.125 -    }
  28.126 -
  28.127 -    if ( !bwc_watch )
  28.128 -    {
  28.129 -        return (bwcpoint_p) 0;
  28.130 -    }
  28.131 -
  28.132 -#define __pdb_search_watchpoint_list(__list) \
  28.133 -    list_for_each(ptr, (__list))  \
  28.134 -    { \
  28.135 -        bwc_entry = list_entry(ptr, bwcpoint_t, list); \
  28.136 -        if ( bwc_entry->process == process &&          \
  28.137 -             bwc_entry->address <= address &&          \
  28.138 -             bwc_entry->address + bwc_entry->length > address ) \
  28.139 -            return bwc_entry; \
  28.140 -    }
  28.141 -
  28.142 -    __pdb_search_watchpoint_list(&bwc_watch->watchpt_read_list);
  28.143 -    __pdb_search_watchpoint_list(&bwc_watch->watchpt_write_list);
  28.144 -    __pdb_search_watchpoint_list(&bwc_watch->watchpt_access_list);
  28.145 -
  28.146 -#undef __pdb_search_watchpoint_list
  28.147 -
  28.148 -    return (bwcpoint_p) 0;
  28.149 -}
  28.150 -
  28.151 -/*************************************************************/
  28.152 -
  28.153 -int
  28.154 -pdb_suspend (struct task_struct *target)
  28.155 -{
  28.156 -    uint32_t rc = 0;
  28.157 -
  28.158 -    force_sig(SIGSTOP, target);                    /* force_sig_specific ??? */
  28.159 -
  28.160 -    return rc;
  28.161 -}
  28.162 -
  28.163 -int
  28.164 -pdb_resume (struct task_struct *target)
  28.165 -{
  28.166 -    int rc = 0;
  28.167 -
  28.168 -    wake_up_process(target);
  28.169 -
  28.170 -    return rc;
  28.171 -}
  28.172 -
  28.173 -/*
  28.174 - * from linux-2.6.11/arch/i386/kernel/ptrace.c::getreg()
  28.175 - */
  28.176 -static unsigned long
  28.177 -_pdb_get_register (struct task_struct *target, int reg)
  28.178 -{
  28.179 -    unsigned long result = ~0UL;
  28.180 -    unsigned long offset;
  28.181 -    unsigned char *stack = 0L;
  28.182 -
  28.183 -    switch (reg)
  28.184 -    {
  28.185 -    case LINUX_FS:
  28.186 -        result = target->thread.fs;
  28.187 -        break;
  28.188 -    case LINUX_GS:
  28.189 -        result = target->thread.gs;
  28.190 -        break;
  28.191 -    case LINUX_DS:
  28.192 -    case LINUX_ES:
  28.193 -    case LINUX_SS:
  28.194 -    case LINUX_CS:
  28.195 -        result = 0xffff;
  28.196 -        /* fall through */
  28.197 -    default:
  28.198 -        if (reg > LINUX_GS)
  28.199 -            reg -= 2;
  28.200 -
  28.201 -        offset = reg * sizeof(long);
  28.202 -        offset -= sizeof(struct pt_regs);
  28.203 -        stack = (unsigned char *)target->thread.esp0;
  28.204 -        stack += offset;
  28.205 -        result &= *((int *)stack);
  28.206 -    }
  28.207 -
  28.208 -    return result;
  28.209 -}
  28.210 -
  28.211 -/*
  28.212 - * from linux-2.6.11/arch/i386/kernel/ptrace.c::putreg()
  28.213 - */
  28.214 -static void
  28.215 -_pdb_set_register (struct task_struct *target, int reg, unsigned long val)
  28.216 -{
  28.217 -    unsigned long offset;
  28.218 -    unsigned char *stack;
  28.219 -    unsigned long value = val;
  28.220 -
  28.221 -    switch (reg)
  28.222 -    {
  28.223 -    case LINUX_FS:
  28.224 -        target->thread.fs = value;
  28.225 -        return;
  28.226 -    case LINUX_GS:
  28.227 -        target->thread.gs = value;
  28.228 -        return;
  28.229 -    case LINUX_DS:
  28.230 -    case LINUX_ES:
  28.231 -        value &= 0xffff;
  28.232 -        break;
  28.233 -    case LINUX_SS:
  28.234 -    case LINUX_CS:
  28.235 -        value &= 0xffff;
  28.236 -        break;
  28.237 -    case LINUX_EFL:
  28.238 -        break;
  28.239 -    }
  28.240 -
  28.241 -    if (reg > LINUX_GS)
  28.242 -        reg -= 2;
  28.243 -    offset = reg * sizeof(long);
  28.244 -    offset -= sizeof(struct pt_regs);
  28.245 -    stack = (unsigned char *)target->thread.esp0;
  28.246 -    stack += offset;
  28.247 -    *(unsigned long *) stack = value;
  28.248 -
  28.249 -    return;
  28.250 -}
  28.251 -
  28.252 -int
  28.253 -pdb_read_register (struct task_struct *target, pdb_op_rd_reg_p op)
  28.254 -{
  28.255 -    int rc = 0;
  28.256 -
  28.257 -    switch (op->reg)
  28.258 -    {
  28.259 -    case  0: op->value = _pdb_get_register(target, LINUX_EAX); break;
  28.260 -    case  1: op->value = _pdb_get_register(target, LINUX_ECX); break;
  28.261 -    case  2: op->value = _pdb_get_register(target, LINUX_EDX); break;
  28.262 -    case  3: op->value = _pdb_get_register(target, LINUX_EBX); break;
  28.263 -    case  4: op->value = _pdb_get_register(target, LINUX_ESP); break;
  28.264 -    case  5: op->value = _pdb_get_register(target, LINUX_EBP); break;
  28.265 -    case  6: op->value = _pdb_get_register(target, LINUX_ESI); break;
  28.266 -    case  7: op->value = _pdb_get_register(target, LINUX_EDI); break;
  28.267 -    case  8: op->value = _pdb_get_register(target, LINUX_EIP); break;
  28.268 -    case  9: op->value = _pdb_get_register(target, LINUX_EFL); break;
  28.269 -
  28.270 -    case 10: op->value = _pdb_get_register(target, LINUX_CS); break;
  28.271 -    case 11: op->value = _pdb_get_register(target, LINUX_SS); break;
  28.272 -    case 12: op->value = _pdb_get_register(target, LINUX_DS); break;
  28.273 -    case 13: op->value = _pdb_get_register(target, LINUX_ES); break;
  28.274 -    case 14: op->value = _pdb_get_register(target, LINUX_FS); break;
  28.275 -    case 15: op->value = _pdb_get_register(target, LINUX_GS); break;
  28.276 -    }
  28.277 -
  28.278 -    return rc;
  28.279 -}
  28.280 -
  28.281 -int
  28.282 -pdb_read_registers (struct task_struct *target, pdb_op_rd_regs_p op)
  28.283 -{
  28.284 -    int rc = 0;
  28.285 -
  28.286 -    op->reg[ 0] = _pdb_get_register(target, LINUX_EAX);
  28.287 -    op->reg[ 1] = _pdb_get_register(target, LINUX_ECX);
  28.288 -    op->reg[ 2] = _pdb_get_register(target, LINUX_EDX);
  28.289 -    op->reg[ 3] = _pdb_get_register(target, LINUX_EBX);
  28.290 -    op->reg[ 4] = _pdb_get_register(target, LINUX_ESP);
  28.291 -    op->reg[ 5] = _pdb_get_register(target, LINUX_EBP);
  28.292 -    op->reg[ 6] = _pdb_get_register(target, LINUX_ESI);
  28.293 -    op->reg[ 7] = _pdb_get_register(target, LINUX_EDI);
  28.294 -    op->reg[ 8] = _pdb_get_register(target, LINUX_EIP);
  28.295 -    op->reg[ 9] = _pdb_get_register(target, LINUX_EFL);
  28.296 -
  28.297 -    op->reg[10] = _pdb_get_register(target, LINUX_CS);
  28.298 -    op->reg[11] = _pdb_get_register(target, LINUX_SS);
  28.299 -    op->reg[12] = _pdb_get_register(target, LINUX_DS);
  28.300 -    op->reg[13] = _pdb_get_register(target, LINUX_ES);
  28.301 -    op->reg[14] = _pdb_get_register(target, LINUX_FS);
  28.302 -    op->reg[15] = _pdb_get_register(target, LINUX_GS);
  28.303 -
  28.304 -    return rc;
  28.305 -}
  28.306 -
  28.307 -int
  28.308 -pdb_write_register (struct task_struct *target, pdb_op_wr_reg_p op)
  28.309 -{
  28.310 -    int rc = 0;
  28.311 -
  28.312 -    _pdb_set_register(target, op->reg, op->value);
  28.313 -
  28.314 -    return rc;
  28.315 -}
  28.316 -
  28.317 -int
  28.318 -pdb_access_memory (struct task_struct *target, unsigned long address, 
  28.319 -                   void *buffer, int length, int write)
  28.320 -{
  28.321 -    int rc = 0;
  28.322 -
  28.323 -    access_process_vm(target, address, buffer, length, write);
  28.324 -
  28.325 -    return rc;
  28.326 -}
  28.327 -
  28.328 -int
  28.329 -pdb_continue (struct task_struct *target)
  28.330 -{
  28.331 -    int rc = 0;
  28.332 -    unsigned long eflags;
  28.333 -
  28.334 -    eflags = _pdb_get_register(target, LINUX_EFL);
  28.335 -    eflags &= ~X86_EFLAGS_TF;
  28.336 -    _pdb_set_register(target, LINUX_EFL, eflags);
  28.337 -
  28.338 -    wake_up_process(target);
  28.339 -
  28.340 -    return rc;
  28.341 -}
  28.342 -
  28.343 -int
  28.344 -pdb_step (struct task_struct *target)
  28.345 -{
  28.346 -    int rc = 0;
  28.347 -    unsigned long eflags;
  28.348 -    bwcpoint_p bkpt;
  28.349 -    
  28.350 -    eflags = _pdb_get_register(target, LINUX_EFL);
  28.351 -    eflags |= X86_EFLAGS_TF;
  28.352 -    _pdb_set_register(target, LINUX_EFL, eflags);
  28.353 -
  28.354 -    _pdb_bwcpoint_alloc(bkpt);
  28.355 -    if ( bkpt == NULL )  return -1;
  28.356 -
  28.357 -    bkpt->process = target->pid;
  28.358 -    bkpt->address = 0;
  28.359 -    bkpt->type    = BWC_DEBUG;
  28.360 -    
  28.361 -    list_add_tail(&bkpt->list, &bwcpoint_list);
  28.362 -
  28.363 -    wake_up_process(target);
  28.364 -
  28.365 -    return rc;
  28.366 -}
  28.367 -
  28.368 -int
  28.369 -pdb_insert_memory_breakpoint (struct task_struct *target, 
  28.370 -                              unsigned long address, uint32_t length)
  28.371 -{
  28.372 -    int rc = 0;
  28.373 -    bwcpoint_p bkpt;
  28.374 -    uint8_t breakpoint_opcode = 0xcc;
  28.375 -
  28.376 -    printk("insert breakpoint %d:%lx len: %d\n", target->pid, address, length);
  28.377 -
  28.378 -    if ( length != 1 )
  28.379 -    {
  28.380 -        printk("error: breakpoint length should be 1\n");
  28.381 -        return -1;
  28.382 -    }
  28.383 -
  28.384 -    _pdb_bwcpoint_alloc(bkpt);
  28.385 -    if ( bkpt == NULL ) return -1;
  28.386 -
  28.387 -    bkpt->process = target->pid;
  28.388 -    bkpt->address = address;
  28.389 -    bkpt->type    = BWC_INT3;
  28.390 -
  28.391 -    pdb_access_memory(target, address, &bkpt->orig_bkpt, 1, PDB_MEM_READ);
  28.392 -    pdb_access_memory(target, address, &breakpoint_opcode, 1, PDB_MEM_WRITE);
  28.393 -    
  28.394 -    list_add_tail(&bkpt->list, &bwcpoint_list);
  28.395 -
  28.396 -    printk("breakpoint_set %d:%lx  OLD: 0x%x\n",
  28.397 -           target->pid, address, bkpt->orig_bkpt);
  28.398 -    pdb_bwc_print_list();
  28.399 -
  28.400 -    return rc;
  28.401 -}
  28.402 -
  28.403 -int
  28.404 -pdb_remove_memory_breakpoint (struct task_struct *target,
  28.405 -                              unsigned long address, uint32_t length)
  28.406 -{
  28.407 -    int rc = 0;
  28.408 -    bwcpoint_p bkpt = NULL;
  28.409 -
  28.410 -    printk ("remove breakpoint %d:%lx\n", target->pid, address);
  28.411 -
  28.412 -    struct list_head *entry;
  28.413 -    list_for_each(entry, &bwcpoint_list)
  28.414 -    {
  28.415 -        bkpt = list_entry(entry, bwcpoint_t, list);
  28.416 -        if ( target->pid == bkpt->process && 
  28.417 -             address == bkpt->address     &&
  28.418 -             bkpt->type == BWC_INT3 )
  28.419 -            break;
  28.420 -    }
  28.421 -    
  28.422 -    if (entry == &bwcpoint_list)
  28.423 -    {
  28.424 -        printk ("error: no breakpoint found\n");
  28.425 -        return -1;
  28.426 -    }
  28.427 -
  28.428 -    pdb_access_memory(target, address, &bkpt->orig_bkpt, 1, PDB_MEM_WRITE);
  28.429 -
  28.430 -    list_del(&bkpt->list);
  28.431 -    kfree(bkpt);
  28.432 -
  28.433 -    pdb_bwc_print_list();
  28.434 -
  28.435 -    return rc;
  28.436 -}
  28.437 -
  28.438 -#define PDB_PTE_UPDATE   1
  28.439 -#define PDB_PTE_RESTORE  2
  28.440 -
  28.441 -int
  28.442 -pdb_change_pte (struct task_struct *target, bwcpoint_p bwc, int mode)
  28.443 -{
  28.444 -    int rc = 0;
  28.445 -    pgd_t *pgd;
  28.446 -    pud_t *pud;
  28.447 -    pmd_t *pmd;
  28.448 -    pte_t *ptep;
  28.449 -
  28.450 -    pgd = pgd_offset(target->mm, bwc->address);
  28.451 -    if (pgd_none(*pgd) || unlikely(pgd_bad(*pgd)))  return -1;
  28.452 -
  28.453 -    pud = pud_offset(pgd, bwc->address);
  28.454 -    if (pud_none(*pud) || unlikely(pud_bad(*pud))) return -2;
  28.455 -
  28.456 -    pmd = pmd_offset(pud, bwc->address);
  28.457 -    if (pmd_none(*pmd) || unlikely(pmd_bad(*pmd))) return -3;
  28.458 -
  28.459 -    ptep = pte_offset_map(pmd, bwc->address);
  28.460 -    if (!ptep)  return -4;
  28.461 -
  28.462 -    switch ( mode )
  28.463 -    {
  28.464 -    case PDB_PTE_UPDATE:      /* added or removed a watchpoint.  update pte. */
  28.465 -    {
  28.466 -        pte_t new_pte;
  28.467 -
  28.468 -        if ( pte_val(bwc->parent->orig_pte) == 0 )    /* new watchpoint page */
  28.469 -        {
  28.470 -            bwc->parent->orig_pte = *ptep;
  28.471 -        }
  28.472 -
  28.473 -        new_pte = bwc->parent->orig_pte;
  28.474 -
  28.475 -        if ( !list_empty(&bwc->parent->watchpt_read_list)  || 
  28.476 -             !list_empty(&bwc->parent->watchpt_access_list) )
  28.477 -        {
  28.478 -            new_pte = pte_rdprotect(new_pte);
  28.479 -        }
  28.480 -
  28.481 -        if ( !list_empty(&bwc->parent->watchpt_write_list) ||
  28.482 -             !list_empty(&bwc->parent->watchpt_access_list) )
  28.483 -        {
  28.484 -            new_pte = pte_wrprotect(new_pte);
  28.485 -        }
  28.486 -        
  28.487 -        if ( pte_val(new_pte) != pte_val(*ptep) )
  28.488 -        {
  28.489 -            *ptep = new_pte;
  28.490 -            flush_tlb_mm(target->mm);
  28.491 -        }
  28.492 -        break;
  28.493 -    }
  28.494 -    case PDB_PTE_RESTORE :   /* suspend watchpoint by restoring original pte */
  28.495 -    {
  28.496 -        *ptep = bwc->parent->orig_pte;
  28.497 -        flush_tlb_mm(target->mm);
  28.498 -        break;
  28.499 -    }
  28.500 -    default :
  28.501 -    {
  28.502 -        printk("(linux) unknown mode %d %d\n", mode, __LINE__);
  28.503 -        break;
  28.504 -    }
  28.505 -    }
  28.506 -
  28.507 -    pte_unmap(ptep);                /* can i flush the tlb before pte_unmap? */
  28.508 -
  28.509 -    return rc;
  28.510 -}
  28.511 -
  28.512 -int
  28.513 -pdb_insert_watchpoint (struct task_struct *target, pdb_op_watchpt_p watchpt)
  28.514 -{
  28.515 -    int rc = 0;
  28.516 -
  28.517 -    bwcpoint_p bwc_watch;
  28.518 -    bwcpoint_p bwc_entry;
  28.519 -    struct list_head *ptr;
  28.520 -    unsigned long page = watchpt->address & PAGE_MASK;
  28.521 -    struct list_head *watchpoint_list;
  28.522 -    
  28.523 -    printk("insert watchpoint: %d %x %x\n", 
  28.524 -           watchpt->type, watchpt->address, watchpt->length);
  28.525 -
  28.526 -    list_for_each(ptr, &bwcpoint_list) /* find existing bwc page entry */
  28.527 -    {
  28.528 -        bwc_watch = list_entry(ptr, bwcpoint_t, list);
  28.529 -
  28.530 -        if (bwc_watch->address == page)  goto got_bwc_watch;
  28.531 -    }
  28.532 -
  28.533 -    _pdb_bwcpoint_alloc(bwc_watch);                  /* create new bwc:watch */
  28.534 -    if ( bwc_watch == NULL ) return -1;
  28.535 -
  28.536 -    bwc_watch->type    = BWC_WATCH;
  28.537 -    bwc_watch->process = target->pid;
  28.538 -    bwc_watch->address = page;
  28.539 -
  28.540 -    list_add_tail(&bwc_watch->list, &bwcpoint_list);
  28.541 -
  28.542 - got_bwc_watch:
  28.543 -
  28.544 -    switch (watchpt->type)
  28.545 -    {
  28.546 -    case BWC_WATCH_READ:
  28.547 -        watchpoint_list = &bwc_watch->watchpt_read_list; break;
  28.548 -    case BWC_WATCH_WRITE: 
  28.549 -        watchpoint_list = &bwc_watch->watchpt_write_list; break;
  28.550 -    case BWC_WATCH_ACCESS:
  28.551 -        watchpoint_list = &bwc_watch->watchpt_access_list; break;
  28.552 -    default:
  28.553 -        printk("unknown type %d\n", watchpt->type); return -2;
  28.554 -    }
  28.555 -
  28.556 -    _pdb_bwcpoint_alloc(bwc_entry);                  /* create new bwc:entry */
  28.557 -    if ( bwc_entry == NULL ) return -1;
  28.558 -
  28.559 -    bwc_entry->process = target->pid;
  28.560 -    bwc_entry->address = watchpt->address;
  28.561 -    bwc_entry->length  = watchpt->length;
  28.562 -    bwc_entry->type    = watchpt->type;
  28.563 -    bwc_entry->parent  = bwc_watch;
  28.564 -
  28.565 -    list_add_tail(&bwc_entry->list, watchpoint_list);
  28.566 -    pdb_change_pte(target, bwc_entry, PDB_PTE_UPDATE);
  28.567 -
  28.568 -    pdb_bwc_print_list();
  28.569 -
  28.570 -    return rc;
  28.571 -}
  28.572 -
  28.573 -int 
  28.574 -pdb_remove_watchpoint (struct task_struct *target, pdb_op_watchpt_p watchpt)
  28.575 -{
  28.576 -    int rc = 0;
  28.577 -    bwcpoint_p bwc_watch = (bwcpoint_p) NULL;
  28.578 -    bwcpoint_p bwc_entry = (bwcpoint_p) NULL;
  28.579 -    unsigned long page = watchpt->address & PAGE_MASK;
  28.580 -    struct list_head *ptr;
  28.581 -    struct list_head *watchpoint_list;
  28.582 -
  28.583 -    printk("remove watchpoint: %d %x %x\n", 
  28.584 -           watchpt->type, watchpt->address, watchpt->length);
  28.585 -
  28.586 -    list_for_each(ptr, &bwcpoint_list)                /* find bwc page entry */
  28.587 -    {
  28.588 -        bwc_watch = list_entry(ptr, bwcpoint_t, list);
  28.589 -        if (bwc_watch->address == page) break;
  28.590 -    }
  28.591 -
  28.592 -    if ( !bwc_watch )
  28.593 -    {
  28.594 -        printk("(linux) delete watchpoint: can't find bwc page 0x%08x\n",
  28.595 -               watchpt->address);
  28.596 -        return -1;
  28.597 -    }
  28.598 -
  28.599 -    switch (watchpt->type)
  28.600 -    {
  28.601 -    case BWC_WATCH_READ:
  28.602 -        watchpoint_list = &bwc_watch->watchpt_read_list; break;
  28.603 -    case BWC_WATCH_WRITE:
  28.604 -        watchpoint_list = &bwc_watch->watchpt_write_list; break;
  28.605 -    case BWC_WATCH_ACCESS:
  28.606 -        watchpoint_list = &bwc_watch->watchpt_access_list; break;
  28.607 -    default:
  28.608 -        printk("unknown type %d\n", watchpt->type); return -2;
  28.609 -    }
  28.610 -
  28.611 -    list_for_each(ptr, watchpoint_list)                   /* find watchpoint */
  28.612 -    {
  28.613 -        bwc_entry = list_entry(ptr, bwcpoint_t, list);
  28.614 -        if ( bwc_entry->address == watchpt->address &&
  28.615 -             bwc_entry->length  == watchpt->length ) break;
  28.616 -    }
  28.617 -
  28.618 -    if ( !bwc_entry )                           /* or ptr == watchpoint_list */
  28.619 -    {
  28.620 -        printk("(linux) delete watchpoint: can't find watchpoint 0x%08x\n",
  28.621 -               watchpt->address);
  28.622 -        return -1;
  28.623 -    }
  28.624 -    
  28.625 -    list_del(&bwc_entry->list);
  28.626 -    pdb_change_pte(target, bwc_entry, PDB_PTE_UPDATE);
  28.627 -    kfree(bwc_entry);
  28.628 -
  28.629 -
  28.630 -    if ( list_empty(&bwc_watch->watchpt_read_list)  &&
  28.631 -         list_empty(&bwc_watch->watchpt_write_list) &&
  28.632 -         list_empty(&bwc_watch->watchpt_access_list) )
  28.633 -    {
  28.634 -        list_del(&bwc_watch->list);
  28.635 -        kfree(bwc_watch);
  28.636 -    }
  28.637 -
  28.638 -    pdb_bwc_print_list();
  28.639 -
  28.640 -    return rc;
  28.641 -}
  28.642 -
  28.643 -
  28.644 -/***************************************************************/
  28.645 -
  28.646 -int
  28.647 -pdb_exceptions_notify (struct notifier_block *self, unsigned long val,
  28.648 -                       void *data)
  28.649 -{
  28.650 -    struct die_args *args = (struct die_args *)data;
  28.651 -
  28.652 -	switch (val) 
  28.653 -    {
  28.654 -	case DIE_DEBUG:
  28.655 -		if ( pdb_debug_fn(args->regs, args->trapnr, args->err) )
  28.656 -			return NOTIFY_STOP;
  28.657 -		break;
  28.658 -    case DIE_TRAP:
  28.659 -		if ( args->trapnr == 3 && pdb_int3_fn(args->regs, args->err) )
  28.660 -			return NOTIFY_STOP;
  28.661 -        break;
  28.662 -	case DIE_INT3:          /* without kprobes, we should never see DIE_INT3 */
  28.663 -		if ( pdb_int3_fn(args->regs, args->err) )
  28.664 -			return NOTIFY_STOP;
  28.665 -		break;
  28.666 -	case DIE_PAGE_FAULT:
  28.667 -		if ( pdb_page_fault_fn(args->regs, args->trapnr, args->err) )
  28.668 -			return NOTIFY_STOP;
  28.669 -		break;
  28.670 -	case DIE_GPF:
  28.671 -        printk("---------------GPF\n");
  28.672 -        break;
  28.673 -	default:
  28.674 -		break;
  28.675 -	}
  28.676 -
  28.677 -	return NOTIFY_DONE;
  28.678 -}
  28.679 -
  28.680 -
  28.681 -static int
  28.682 -pdb_debug_fn (struct pt_regs *regs, long error_code, 
  28.683 -                   unsigned int condition)
  28.684 -{
  28.685 -    pdb_response_t resp;
  28.686 -    bwcpoint_p bkpt = NULL;
  28.687 -    struct list_head *entry;
  28.688 -
  28.689 -    printk("pdb_debug_fn\n");
  28.690 -
  28.691 -    list_for_each(entry, &bwcpoint_list)
  28.692 -    {
  28.693 -        bkpt = list_entry(entry, bwcpoint_t, list);
  28.694 -        if ( current->pid == bkpt->process && 
  28.695 -             (bkpt->type == BWC_DEBUG ||                      /* single step */
  28.696 -              bkpt->type == BWC_WATCH_STEP))  /* single step over watchpoint */
  28.697 -            break;
  28.698 -    }
  28.699 -    
  28.700 -    if (entry == &bwcpoint_list)
  28.701 -    {
  28.702 -        printk("not my debug  0x%x 0x%lx\n", current->pid, regs->eip);
  28.703 -        return 0;
  28.704 -    }
  28.705 -
  28.706 -    pdb_suspend(current);
  28.707 -
  28.708 -    printk("(pdb) %s  pid: %d, eip: 0x%08lx\n", 
  28.709 -           bkpt->type == BWC_DEBUG ? "debug" : "watch-step",
  28.710 -           current->pid, regs->eip);
  28.711 -
  28.712 -    regs->eflags &= ~X86_EFLAGS_TF;
  28.713 -	set_tsk_thread_flag(current, TIF_SINGLESTEP);
  28.714 -
  28.715 -    switch (bkpt->type)
  28.716 -    {
  28.717 -    case BWC_DEBUG:
  28.718 -        resp.operation = PDB_OPCODE_STEP;
  28.719 -        break;
  28.720 -    case BWC_WATCH_STEP:
  28.721 -    {
  28.722 -        struct list_head *watchpoint_list;
  28.723 -        bwcpoint_p watch_page = bkpt->watchpoint->parent;
  28.724 -
  28.725 -        switch (bkpt->watchpoint->type)
  28.726 -        {
  28.727 -        case BWC_WATCH_READ:
  28.728 -            watchpoint_list = &watch_page->watchpt_read_list; break;
  28.729 -        case BWC_WATCH_WRITE: 
  28.730 -            watchpoint_list = &watch_page->watchpt_write_list; break;
  28.731 -        case BWC_WATCH_ACCESS:
  28.732 -            watchpoint_list = &watch_page->watchpt_access_list; break;
  28.733 -        default:
  28.734 -            printk("unknown type %d\n", bkpt->watchpoint->type); return 0;
  28.735 -        }
  28.736 -
  28.737 -        resp.operation = PDB_OPCODE_WATCHPOINT;
  28.738 -        list_del_init(&bkpt->watchpoint->list);
  28.739 -        list_add_tail(&bkpt->watchpoint->list, watchpoint_list);
  28.740 -        pdb_change_pte(current, bkpt->watchpoint, PDB_PTE_UPDATE);
  28.741 -        pdb_bwc_print_list();
  28.742 -        break;
  28.743 -    }
  28.744 -    default:
  28.745 -        printk("unknown breakpoint type %d %d\n", __LINE__, bkpt->type);
  28.746 -        return 0;
  28.747 -    }
  28.748 -
  28.749 -    resp.process   = current->pid;
  28.750 -    resp.status    = PDB_RESPONSE_OKAY;
  28.751 -
  28.752 -    pdb_send_response(&resp);
  28.753 -
  28.754 -    list_del(&bkpt->list);
  28.755 -    kfree(bkpt);
  28.756 -
  28.757 -    return 1;
  28.758 -}
  28.759 -
  28.760 -
  28.761 -static int
  28.762 -pdb_int3_fn (struct pt_regs *regs, long error_code)
  28.763 -{
  28.764 -    pdb_response_t resp;
  28.765 -    bwcpoint_p bkpt = NULL;
  28.766 -    unsigned long address = regs->eip - 1;
  28.767 -
  28.768 -    struct list_head *entry;
  28.769 -    list_for_each(entry, &bwcpoint_list)
  28.770 -    {
  28.771 -        bkpt = list_entry(entry, bwcpoint_t, list);
  28.772 -        if ( current->pid == bkpt->process && 
  28.773 -             address == bkpt->address      &&
  28.774 -             bkpt->type == BWC_INT3 )
  28.775 -            break;
  28.776 -    }
  28.777 -    
  28.778 -    if (entry == &bwcpoint_list)
  28.779 -    {
  28.780 -        printk("not my int3 bkpt  0x%x 0x%lx\n", current->pid, address);
  28.781 -        return 0;
  28.782 -    }
  28.783 -
  28.784 -    printk("(pdb) int3  pid: %d, eip: 0x%08lx\n", current->pid, address);
  28.785 -
  28.786 -    pdb_suspend(current);
  28.787 -
  28.788 -    resp.operation = PDB_OPCODE_CONTINUE;
  28.789 -    resp.process   = current->pid;
  28.790 -    resp.status    = PDB_RESPONSE_OKAY;
  28.791 -
  28.792 -    pdb_send_response(&resp);
  28.793 -
  28.794 -    return 1;
  28.795 -}
  28.796 -
  28.797 -static int
  28.798 -pdb_page_fault_fn (struct pt_regs *regs, long error_code, 
  28.799 -                   unsigned int condition)
  28.800 -{
  28.801 -    unsigned long cr2;
  28.802 -    unsigned long cr3;
  28.803 -    bwcpoint_p bwc;
  28.804 -    bwcpoint_p watchpt;
  28.805 -    bwcpoint_p bkpt;
  28.806 -
  28.807 -    __asm__ __volatile__ ("movl %%cr3,%0" : "=r" (cr3) : );
  28.808 -    __asm__ __volatile__ ("movl %%cr2,%0" : "=r" (cr2) : );
  28.809 -
  28.810 -    bwc = pdb_search_watchpoint(current->pid, cr2);
  28.811 -    if ( !bwc )
  28.812 -    {
  28.813 -        return 0;                                                /* not mine */
  28.814 -    }
  28.815 -
  28.816 -    printk("page_fault cr2:%08lx err:%lx eip:%08lx\n", 
  28.817 -           cr2, error_code, regs->eip);
  28.818 -
  28.819 -    /* disable the watchpoint */
  28.820 -    watchpt = bwc->watchpoint;
  28.821 -    list_del_init(&bwc->list);
  28.822 -    list_add_tail(&bwc->list, &bwc->parent->watchpt_disabled_list);
  28.823 -    pdb_change_pte(current, bwc, PDB_PTE_RESTORE);
  28.824 -
  28.825 -    /* single step the faulting instruction */
  28.826 -    regs->eflags |= X86_EFLAGS_TF;
  28.827 -
  28.828 -    /* create a bwcpoint entry so we know what to do once we regain control */
  28.829 -    _pdb_bwcpoint_alloc(bkpt);
  28.830 -    if ( bkpt == NULL )  return -1;
  28.831 -
  28.832 -    bkpt->process    = current->pid;
  28.833 -    bkpt->address    = 0;
  28.834 -    bkpt->type       = BWC_WATCH_STEP;
  28.835 -    bkpt->watchpoint = bwc;
  28.836 -
  28.837 -    /* add to head so we see it first the next time we break */
  28.838 -    list_add(&bkpt->list, &bwcpoint_list);                
  28.839 -
  28.840 -    pdb_bwc_print_list();
  28.841 -    return 1;
  28.842 -}
  28.843 -
  28.844 -
  28.845 -/*
  28.846 - * Local variables:
  28.847 - * mode: C
  28.848 - * c-set-style: "BSD"
  28.849 - * c-basic-offset: 4
  28.850 - * tab-width: 4
  28.851 - * indent-tabs-mode: nil
  28.852 - * End:
  28.853 - */
  28.854 -
    29.1 --- a/tools/debugger/pdb/linux-2.6-module/module.c	Sun Oct 01 11:39:41 2006 -0600
    29.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    29.3 @@ -1,337 +0,0 @@
    29.4 -
    29.5 -/*
    29.6 - * module.c
    29.7 - *
    29.8 - * Handles initial registration with pdb when the pdb module starts up
    29.9 - * and cleanup when the module goes away (sortof :)
   29.10 - * Also receives each request from pdb in domain 0 and dispatches to the
   29.11 - * appropriate debugger function.
   29.12 - */
   29.13 -
   29.14 -#include <linux/module.h>
   29.15 -#include <linux/interrupt.h>
   29.16 -
   29.17 -#include <asm-i386/kdebug.h>
   29.18 -
   29.19 -#include <xen/evtchn.h>
   29.20 -#include <xen/ctrl_if.h>
   29.21 -#include <xen/hypervisor.h>
   29.22 -#include <xen/interface/io/domain_controller.h>
   29.23 -#include <xen/interface/xen.h>
   29.24 -
   29.25 -#include <xen/interface/io/ring.h>
   29.26 -
   29.27 -#include "pdb_module.h"
   29.28 -#include "pdb_debug.h"
   29.29 -
   29.30 -#define PDB_RING_SIZE __RING_SIZE((pdb_sring_t *)0, PAGE_SIZE)
   29.31 -
   29.32 -static pdb_back_ring_t pdb_ring;
   29.33 -static unsigned int    pdb_evtchn;
   29.34 -static unsigned int    pdb_irq;
   29.35 -static unsigned int    pdb_domain;
   29.36 -
   29.37 -/* work queue */
   29.38 -static void pdb_work_handler(void *unused);
   29.39 -static DECLARE_WORK(pdb_deferred_work, pdb_work_handler, NULL);
   29.40 -
   29.41 -/*
   29.42 - * send response to a pdb request
   29.43 - */
   29.44 -void
   29.45 -pdb_send_response (pdb_response_t *response)
   29.46 -{
   29.47 -    pdb_response_t *resp;
   29.48 -
   29.49 -    resp = RING_GET_RESPONSE(&pdb_ring, pdb_ring.rsp_prod_pvt);
   29.50 -
   29.51 -    memcpy(resp, response, sizeof(pdb_response_t));
   29.52 -    resp->domain = pdb_domain;
   29.53 -    
   29.54 -    wmb();                 /* Ensure other side can see the response fields. */
   29.55 -    pdb_ring.rsp_prod_pvt++;
   29.56 -    RING_PUSH_RESPONSES(&pdb_ring);
   29.57 -    notify_via_evtchn(pdb_evtchn);
   29.58 -    return;
   29.59 -}
   29.60 -
   29.61 -/*
   29.62 - * handle a debug command from the front end
   29.63 - */
   29.64 -static void
   29.65 -pdb_process_request (pdb_request_t *request)
   29.66 -{
   29.67 -    pdb_response_t resp;
   29.68 -    struct task_struct *target;
   29.69 -
   29.70 -    read_lock(&tasklist_lock);
   29.71 -    target = find_task_by_pid(request->process);
   29.72 -    if (target)
   29.73 -        get_task_struct(target);
   29.74 -    read_unlock(&tasklist_lock);
   29.75 -
   29.76 -    resp.operation = request->operation;
   29.77 -    resp.process   = request->process;
   29.78 -
   29.79 -    if (!target)
   29.80 -    {
   29.81 -        printk ("(linux) target not found 0x%x\n", request->process);
   29.82 -        resp.status = PDB_RESPONSE_ERROR;
   29.83 -        goto response;
   29.84 -    }
   29.85 -
   29.86 -    switch (request->operation)
   29.87 -    {
   29.88 -    case PDB_OPCODE_PAUSE :
   29.89 -        pdb_suspend(target);
   29.90 -        resp.status = PDB_RESPONSE_OKAY;
   29.91 -        break;
   29.92 -    case PDB_OPCODE_ATTACH :
   29.93 -        pdb_suspend(target);
   29.94 -        pdb_domain = request->u.attach.domain;
   29.95 -        printk("(linux) attach  dom:0x%x pid:0x%x\n",
   29.96 -               pdb_domain, request->process);
   29.97 -        resp.status = PDB_RESPONSE_OKAY;
   29.98 -        break;
   29.99 -    case PDB_OPCODE_DETACH :
  29.100 -        pdb_resume(target);
  29.101 -        printk("(linux) detach 0x%x\n", request->process);
  29.102 -        resp.status = PDB_RESPONSE_OKAY;
  29.103 -        break;
  29.104 -    case PDB_OPCODE_RD_REG :
  29.105 -        resp.u.rd_reg.reg = request->u.rd_reg.reg;
  29.106 -        pdb_read_register(target, &resp.u.rd_reg);
  29.107 -        resp.status = PDB_RESPONSE_OKAY;
  29.108 -        break;
  29.109 -    case PDB_OPCODE_RD_REGS :
  29.110 -        pdb_read_registers(target, &resp.u.rd_regs);
  29.111 -        resp.status = PDB_RESPONSE_OKAY;
  29.112 -        break;
  29.113 -    case PDB_OPCODE_WR_REG :
  29.114 -        pdb_write_register(target, &request->u.wr_reg);
  29.115 -        resp.status = PDB_RESPONSE_OKAY;
  29.116 -        break;
  29.117 -    case PDB_OPCODE_RD_MEM :
  29.118 -        pdb_access_memory(target, request->u.rd_mem.address,
  29.119 -                          &resp.u.rd_mem.data, request->u.rd_mem.length, 
  29.120 -                          PDB_MEM_READ);
  29.121 -        resp.u.rd_mem.address = request->u.rd_mem.address;
  29.122 -        resp.u.rd_mem.length  = request->u.rd_mem.length;
  29.123 -        resp.status = PDB_RESPONSE_OKAY;
  29.124 -        break;
  29.125 -    case PDB_OPCODE_WR_MEM :
  29.126 -        pdb_access_memory(target, request->u.wr_mem.address,
  29.127 -                         &request->u.wr_mem.data, request->u.wr_mem.length, 
  29.128 -                          PDB_MEM_WRITE);
  29.129 -        resp.status = PDB_RESPONSE_OKAY;
  29.130 -        break;
  29.131 -    case PDB_OPCODE_CONTINUE :
  29.132 -        pdb_continue(target);
  29.133 -        goto no_response;
  29.134 -        break;
  29.135 -    case PDB_OPCODE_STEP :
  29.136 -        pdb_step(target);
  29.137 -        resp.status = PDB_RESPONSE_OKAY;
  29.138 -        goto no_response;
  29.139 -        break;
  29.140 -    case PDB_OPCODE_SET_BKPT :
  29.141 -        pdb_insert_memory_breakpoint(target, request->u.bkpt.address,
  29.142 -                                     request->u.bkpt.length);
  29.143 -        resp.status = PDB_RESPONSE_OKAY;
  29.144 -        break;
  29.145 -    case PDB_OPCODE_CLR_BKPT :
  29.146 -        pdb_remove_memory_breakpoint(target, request->u.bkpt.address,
  29.147 -                                     request->u.bkpt.length);
  29.148 -        resp.status = PDB_RESPONSE_OKAY;
  29.149 -        break;
  29.150 -    case PDB_OPCODE_SET_WATCHPT :
  29.151 -        pdb_insert_watchpoint(target, &request->u.watchpt);
  29.152 -        resp.status = PDB_RESPONSE_OKAY;
  29.153 -        break;
  29.154 -    case PDB_OPCODE_CLR_WATCHPT :
  29.155 -        pdb_remove_watchpoint(target, &request->u.watchpt);
  29.156 -        resp.status = PDB_RESPONSE_OKAY;
  29.157 -        break;
  29.158 -    default:
  29.159 -        printk("(pdb) unknown request operation %d\n", request->operation);
  29.160 -        resp.status = PDB_RESPONSE_ERROR;
  29.161 -    }
  29.162 -
  29.163 - response:        
  29.164 -    pdb_send_response (&resp);
  29.165 -
  29.166 - no_response:
  29.167 -    return;
  29.168 -}
  29.169 -
  29.170 -/*
  29.171 - * work queue
  29.172 - */
  29.173 -static void
  29.174 -pdb_work_handler (void *unused)
  29.175 -{
  29.176 -    pdb_request_t *req;
  29.177 -    RING_IDX i, rp;
  29.178 -
  29.179 -    rp = pdb_ring.sring->req_prod;
  29.180 -    rmb();
  29.181 -
  29.182 -    for ( i = pdb_ring.req_cons; 
  29.183 -          (i != rp) && !RING_REQUEST_CONS_OVERFLOW(&pdb_ring, i);
  29.184 -          i++ )
  29.185 -    {
  29.186 -        req = RING_GET_REQUEST(&pdb_ring, i);
  29.187 -        pdb_process_request(req);
  29.188 -
  29.189 -    }
  29.190 -    pdb_ring.req_cons = i;
  29.191 -}
  29.192 -
  29.193 -/*
  29.194 - * receive a pdb request
  29.195 - */
  29.196 -static irqreturn_t
  29.197 -pdb_interrupt (int irq, void *dev_id, struct pt_regs *ptregs)
  29.198 -{
  29.199 -    schedule_work(&pdb_deferred_work);
  29.200 -
  29.201 -    return IRQ_HANDLED;
  29.202 -}
  29.203 -
  29.204 -static void
  29.205 -pdb_send_connection_status(int status, unsigned long ring)
  29.206 -{
  29.207 -    ctrl_msg_t cmsg = 
  29.208 -    {
  29.209 -        .type = CMSG_DEBUG,
  29.210 -        .subtype = CMSG_DEBUG_CONNECTION_STATUS,
  29.211 -        .length  = sizeof(pdb_connection_t),
  29.212 -    };
  29.213 -    pdb_connection_t *conn = (pdb_connection_t *)cmsg.msg;
  29.214 -
  29.215 -    conn->status = status;
  29.216 -    conn->ring = ring;
  29.217 -    conn->evtchn = 0;
  29.218 -
  29.219 -    ctrl_if_send_message_block(&cmsg, NULL, 0, TASK_UNINTERRUPTIBLE);
  29.220 -}
  29.221 -
  29.222 -
  29.223 -/*
  29.224 - * this is called each time a message is received on the control channel
  29.225 - */
  29.226 -static void
  29.227 -pdb_ctrlif_rx(ctrl_msg_t *msg, unsigned long id)
  29.228 -{
  29.229 -    switch (msg->subtype)
  29.230 -    {
  29.231 -    case CMSG_DEBUG_CONNECTION_STATUS:
  29.232 -        /* initialize event channel created by the pdb server */
  29.233 -
  29.234 -        pdb_evtchn = ((pdb_connection_p) msg->msg)->evtchn;
  29.235 -        pdb_irq = bind_evtchn_to_irq(pdb_evtchn);
  29.236 -
  29.237 -        if ( request_irq(pdb_irq, pdb_interrupt, 
  29.238 -                         SA_SAMPLE_RANDOM, "pdb", NULL) )
  29.239 -        {
  29.240 -            printk("(pdb) request irq failed: %d %d\n", pdb_evtchn, pdb_irq);
  29.241 -        }
  29.242 -        break;
  29.243 -
  29.244 -    default:
  29.245 -        printk ("(pdb) unknown xcs control message: %d\n", msg->subtype);
  29.246 -        break;
  29.247 -    }
  29.248 -
  29.249 -    return;
  29.250 -}
  29.251 -
  29.252 -
  29.253 -/********************************************************************/
  29.254 -
  29.255 -static struct notifier_block pdb_exceptions_nb =
  29.256 -{
  29.257 -    .notifier_call = pdb_exceptions_notify,
  29.258 -    .priority = 0x1                                          /* low priority */
  29.259 -};
  29.260 -
  29.261 -
  29.262 -static int __init 
  29.263 -pdb_initialize (void)
  29.264 -{
  29.265 -    int err;
  29.266 -    pdb_sring_t *sring;
  29.267 -
  29.268 -    printk("----\npdb initialize   %s %s\n", __DATE__, __TIME__);
  29.269 -
  29.270 -    /*
  29.271 -    if ( xen_start_info.flags & SIF_INITDOMAIN )
  29.272 -        return 1;
  29.273 -    */
  29.274 -
  29.275 -    pdb_evtchn = 0;
  29.276 -    pdb_irq    = 0;
  29.277 -    pdb_domain = 0;
  29.278 -
  29.279 -    (void)ctrl_if_register_receiver(CMSG_DEBUG, pdb_ctrlif_rx,
  29.280 -                                    CALLBACK_IN_BLOCKING_CONTEXT);
  29.281 -
  29.282 -    /* rings */
  29.283 -    sring = (pdb_sring_t *)__get_free_page(GFP_KERNEL);
  29.284 -    SHARED_RING_INIT(sring);
  29.285 -    BACK_RING_INIT(&pdb_ring, sring, PAGE_SIZE);
  29.286 - 
  29.287 -    /* notify pdb in dom 0 */
  29.288 -    pdb_send_connection_status(PDB_CONNECTION_STATUS_UP, 
  29.289 -                               virt_to_machine(pdb_ring.sring) >> PAGE_SHIFT);
  29.290 -
  29.291 -    /* handler for int1 & int3 */
  29.292 -    err = register_die_notifier(&pdb_exceptions_nb);
  29.293 -
  29.294 -    return err;
  29.295 -}
  29.296 -
  29.297 -static void __exit
  29.298 -pdb_terminate(void)
  29.299 -{
  29.300 -    int err = 0;
  29.301 -
  29.302 -    printk("pdb cleanup\n");
  29.303 -
  29.304 -    (void)ctrl_if_unregister_receiver(CMSG_DEBUG, pdb_ctrlif_rx);
  29.305 -
  29.306 -    if (pdb_irq)
  29.307 -    {
  29.308 -        free_irq(pdb_irq, NULL);
  29.309 -        pdb_irq = 0;
  29.310 -    }
  29.311 -
  29.312 -    if (pdb_evtchn)
  29.313 -    {
  29.314 -        unbind_evtchn_from_irq(pdb_evtchn); 
  29.315 -        pdb_evtchn = 0;
  29.316 -    }
  29.317 -
  29.318 -    pdb_send_connection_status(PDB_CONNECTION_STATUS_DOWN, 0);
  29.319 -
  29.320 -    /* handler for int1 & int3 */
  29.321 -    err = unregister_die_notifier(&pdb_exceptions_nb);
  29.322 -
  29.323 -	return;
  29.324 -}
  29.325 -
  29.326 -
  29.327 -module_init(pdb_initialize);
  29.328 -module_exit(pdb_terminate);
  29.329 -
  29.330 -
  29.331 -/*
  29.332 - * Local variables:
  29.333 - * mode: C
  29.334 - * c-set-style: "BSD"
  29.335 - * c-basic-offset: 4
  29.336 - * tab-width: 4
  29.337 - * indent-tabs-mode: nil
  29.338 - * End:
  29.339 - */
  29.340 -
    30.1 --- a/tools/debugger/pdb/linux-2.6-module/pdb_debug.h	Sun Oct 01 11:39:41 2006 -0600
    30.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    30.3 @@ -1,47 +0,0 @@
    30.4 -
    30.5 -#ifndef __PDB_DEBUG_H_
    30.6 -#define __PDB_DEBUG_H_
    30.7 -
    30.8 -/* debugger.c */
    30.9 -void pdb_initialize_bwcpoint (void);
   30.10 -int pdb_suspend (struct task_struct *target);
   30.11 -int pdb_resume (struct task_struct *target);
   30.12 -int pdb_read_register (struct task_struct *target, pdb_op_rd_reg_p op);
   30.13 -int pdb_read_registers (struct task_struct *target, pdb_op_rd_regs_p op);
   30.14 -int pdb_write_register (struct task_struct *target, pdb_op_wr_reg_p op);
   30.15 -int pdb_read_memory (struct task_struct *target, pdb_op_rd_mem_req_p req, 
   30.16 -                     pdb_op_rd_mem_resp_p resp);
   30.17 -int pdb_write_memory (struct task_struct *target, pdb_op_wr_mem_p op);
   30.18 -int pdb_access_memory (struct task_struct *target, unsigned long address, 
   30.19 -                       void *buffer, int length, int write);
   30.20 -int pdb_continue (struct task_struct *target);
   30.21 -int pdb_step (struct task_struct *target);
   30.22 -
   30.23 -int pdb_insert_memory_breakpoint (struct task_struct *target, 
   30.24 -                                  unsigned long address, uint32_t length);
   30.25 -int pdb_remove_memory_breakpoint (struct task_struct *target,
   30.26 -                                  unsigned long address, uint32_t length);
   30.27 -int pdb_insert_watchpoint (struct task_struct *target,
   30.28 -                           pdb_op_watchpt_p watchpt);
   30.29 -int pdb_remove_watchpoint (struct task_struct *target,
   30.30 -                           pdb_op_watchpt_p watchpt);
   30.31 -
   30.32 -int pdb_exceptions_notify (struct notifier_block *self, unsigned long val,
   30.33 -                           void *data);
   30.34 -
   30.35 -/* module.c */
   30.36 -void pdb_send_response (pdb_response_t *response);
   30.37 -
   30.38 -#endif
   30.39 -
   30.40 -
   30.41 -/*
   30.42 - * Local variables:
   30.43 - * mode: C
   30.44 - * c-set-style: "BSD"
   30.45 - * c-basic-offset: 4
   30.46 - * tab-width: 4
   30.47 - * indent-tabs-mode: nil
   30.48 - * End:
   30.49 - */
   30.50 -
    31.1 --- a/tools/debugger/pdb/linux-2.6-module/pdb_module.h	Sun Oct 01 11:39:41 2006 -0600
    31.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    31.3 @@ -1,142 +0,0 @@
    31.4 -
    31.5 -#ifndef __PDB_MODULE_H_
    31.6 -#define __PDB_MODULE_H_
    31.7 -
    31.8 -#include "../pdb_caml_xen.h"
    31.9 -
   31.10 -#define PDB_OPCODE_PAUSE  1
   31.11 -
   31.12 -#define PDB_OPCODE_ATTACH 2
   31.13 -typedef struct pdb_op_attach
   31.14 -{
   31.15 -    uint32_t  domain;
   31.16 -} pdb_op_attach_t, *pdb_op_attach_p;
   31.17 -
   31.18 -#define PDB_OPCODE_DETACH 3
   31.19 -
   31.20 -#define PDB_OPCODE_RD_REG 4
   31.21 -typedef struct pdb_op_rd_reg
   31.22 -{
   31.23 -    uint32_t reg;
   31.24 -    uint32_t value;
   31.25 -} pdb_op_rd_reg_t, *pdb_op_rd_reg_p;
   31.26 -
   31.27 -#define PDB_OPCODE_RD_REGS 5
   31.28 -typedef struct pdb_op_rd_regs
   31.29 -{
   31.30 -    uint32_t reg[GDB_REGISTER_FRAME_SIZE];
   31.31 -} pdb_op_rd_regs_t, *pdb_op_rd_regs_p;
   31.32 -
   31.33 -#define PDB_OPCODE_WR_REG 6
   31.34 -typedef struct pdb_op_wr_reg
   31.35 -{
   31.36 -    uint32_t reg;
   31.37 -    uint32_t value;
   31.38 -} pdb_op_wr_reg_t, *pdb_op_wr_reg_p;
   31.39 -
   31.40 -#define PDB_OPCODE_RD_MEM 7
   31.41 -typedef struct pdb_op_rd_mem_req
   31.42 -{
   31.43 -    uint32_t address;
   31.44 -    uint32_t length;
   31.45 -} pdb_op_rd_mem_req_t, *pdb_op_rd_mem_req_p;
   31.46 -
   31.47 -typedef struct pdb_op_rd_mem_resp
   31.48 -{
   31.49 -    uint32_t address;
   31.50 -    uint32_t length;
   31.51 -    uint8_t  data[1024];
   31.52 -} pdb_op_rd_mem_resp_t, *pdb_op_rd_mem_resp_p;
   31.53 -
   31.54 -#define PDB_OPCODE_WR_MEM 8
   31.55 -typedef struct pdb_op_wr_mem
   31.56 -{
   31.57 -    uint32_t address;
   31.58 -    uint32_t length;
   31.59 -    uint8_t  data[1024];                                             /* arbitrary */
   31.60 -} pdb_op_wr_mem_t, *pdb_op_wr_mem_p;
   31.61 -
   31.62 -#define PDB_OPCODE_CONTINUE 9
   31.63 -#define PDB_OPCODE_STEP     10
   31.64 -
   31.65 -#define PDB_OPCODE_SET_BKPT 11
   31.66 -#define PDB_OPCODE_CLR_BKPT 12
   31.67 -typedef struct pdb_op_bkpt
   31.68 -{
   31.69 -    uint32_t address;
   31.70 -    uint32_t length;
   31.71 -} pdb_op_bkpt_t, *pdb_op_bkpt_p;
   31.72 -
   31.73 -#define PDB_OPCODE_SET_WATCHPT 13
   31.74 -#define PDB_OPCODE_CLR_WATCHPT 14
   31.75 -#define PDB_OPCODE_WATCHPOINT  15
   31.76 -typedef struct pdb_op_watchpt
   31.77 -{
   31.78 -#define BWC_DEBUG 1
   31.79 -#define BWC_INT3  3
   31.80 -#define BWC_WATCH        100                         /* pdb: watchpoint page */
   31.81 -#define BWC_WATCH_STEP   101                  /* pdb: watchpoint single step */
   31.82 -#define BWC_WATCH_WRITE  102
   31.83 -#define BWC_WATCH_READ   103
   31.84 -#define BWC_WATCH_ACCESS 104
   31.85 -    uint32_t type;
   31.86 -    uint32_t address;
   31.87 -    uint32_t length;
   31.88 -} pdb_op_watchpt_t, *pdb_op_watchpt_p;
   31.89 -
   31.90 -
   31.91 -typedef struct 
   31.92 -{
   31.93 -    uint8_t   operation;       /* PDB_OPCODE_???      */
   31.94 -    uint32_t  process;
   31.95 -    union
   31.96 -    {
   31.97 -        pdb_op_attach_t     attach;
   31.98 -        pdb_op_rd_reg_t     rd_reg;
   31.99 -        pdb_op_wr_reg_t     wr_reg;
  31.100 -        pdb_op_rd_mem_req_t rd_mem;
  31.101 -        pdb_op_wr_mem_t     wr_mem;
  31.102 -        pdb_op_bkpt_t       bkpt;
  31.103 -        pdb_op_watchpt_t    watchpt;
  31.104 -    } u;
  31.105 -} pdb_request_t, *pdb_request_p;
  31.106 -
  31.107 - 
  31.108 -
  31.109 -#define PDB_RESPONSE_OKAY   0
  31.110 -#define PDB_RESPONSE_ERROR -1
  31.111 -
  31.112 -typedef struct {
  31.113 -    uint8_t  operation;       /* copied from request */
  31.114 -    uint32_t domain;          
  31.115 -    uint32_t process;
  31.116 -    int16_t  status;          /* PDB_RESPONSE_???    */
  31.117 -    union
  31.118 -    {
  31.119 -        pdb_op_rd_reg_t      rd_reg;
  31.120 -        pdb_op_rd_regs_t     rd_regs;
  31.121 -        pdb_op_rd_mem_resp_t rd_mem;
  31.122 -    } u;
  31.123 -} pdb_response_t, *pdb_response_p;
  31.124 -
  31.125 -
  31.126 -DEFINE_RING_TYPES(pdb, pdb_request_t, pdb_response_t);
  31.127 -
  31.128 -
  31.129 -/* from access_process_vm */
  31.130 -#define PDB_MEM_READ  0
  31.131 -#define PDB_MEM_WRITE 1
  31.132 -
  31.133 -#endif
  31.134 -
  31.135 -
  31.136 -/*
  31.137 - * Local variables:
  31.138 - * mode: C
  31.139 - * c-set-style: "BSD"
  31.140 - * c-basic-offset: 4
  31.141 - * tab-width: 4
  31.142 - * indent-tabs-mode: nil
  31.143 - * End:
  31.144 - */
  31.145 -
    32.1 --- a/tools/debugger/pdb/linux-2.6-patches/Makefile	Sun Oct 01 11:39:41 2006 -0600
    32.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    32.3 @@ -1,11 +0,0 @@
    32.4 -XEN_ROOT   = ../../../..
    32.5 -LINUX_DIR  = linux-2.6.12-xenU
    32.6 -KDIR       = $(XEN_ROOT)/$(LINUX_DIR)
    32.7 -PATCH_DIR  = $(CURDIR)
    32.8 -
    32.9 -.PHONY: patches 
   32.10 -patches : patches-done
   32.11 -
   32.12 -patches-done :
   32.13 -	( for i in *.patch ; do ( cd $(KDIR) ; patch -p1 < $(PATCH_DIR)/$$i || exit 1 ) ; done )
   32.14 -	touch $@
    33.1 --- a/tools/debugger/pdb/linux-2.6-patches/i386_ksyms.patch	Sun Oct 01 11:39:41 2006 -0600
    33.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    33.3 @@ -1,19 +0,0 @@
    33.4 -diff -u linux-2.6.12/arch/xen/i386/kernel/i386_ksyms.c linux-2.6.12-pdb/arch/xen/i386/kernel/i386_ksyms.c
    33.5 ---- linux-2.6.12/arch/xen/i386/kernel/i386_ksyms.c	2005-07-31 22:36:50.000000000 +0100
    33.6 -+++ linux-2.6.12-pdb/arch/xen/i386/kernel/i386_ksyms.c	2005-08-01 10:57:31.000000000 +0100
    33.7 -@@ -151,6 +151,7 @@
    33.8 - /* TLB flushing */
    33.9 - EXPORT_SYMBOL(flush_tlb_page);
   33.10 - #endif
   33.11 -+EXPORT_SYMBOL(flush_tlb_mm);
   33.12 - 
   33.13 - #ifdef CONFIG_X86_IO_APIC
   33.14 - EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
   33.15 -@@ -172,6 +173,7 @@
   33.16 - EXPORT_SYMBOL_GPL(unset_nmi_callback);
   33.17 - 
   33.18 - EXPORT_SYMBOL(register_die_notifier);
   33.19 -+EXPORT_SYMBOL(unregister_die_notifier);
   33.20 - #ifdef CONFIG_HAVE_DEC_LOCK
   33.21 - EXPORT_SYMBOL(_atomic_dec_and_lock);
   33.22 - #endif
    34.1 --- a/tools/debugger/pdb/linux-2.6-patches/kdebug.patch	Sun Oct 01 11:39:41 2006 -0600
    34.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    34.3 @@ -1,11 +0,0 @@
    34.4 -diff -u linux-2.6.12/include/asm-i386/kdebug.h linux-2.6.12-pdb/include/asm-i386/kdebug.h
    34.5 ---- linux-2.6.12/include/asm-i386/kdebug.h	2005-06-17 20:48:29.000000000 +0100
    34.6 -+++ linux-2.6.12-pdb/include/asm-i386/kdebug.h	2005-08-01 11:11:53.000000000 +0100
    34.7 -@@ -21,6 +21,7 @@
    34.8 -    If you really want to do it first unregister - then synchronize_kernel - then free.
    34.9 -   */
   34.10 - int register_die_notifier(struct notifier_block *nb);
   34.11 -+int unregister_die_notifier(struct notifier_block *nb);
   34.12 - extern struct notifier_block *i386die_chain;
   34.13 - 
   34.14 - 
    35.1 --- a/tools/debugger/pdb/linux-2.6-patches/makefile.patch	Sun Oct 01 11:39:41 2006 -0600
    35.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    35.3 @@ -1,12 +0,0 @@
    35.4 -diff -Naur linux-2.6.12/Makefile linux-2.6.12-pdb/Makefile
    35.5 ---- linux-2.6.12/Makefile	2005-08-01 01:21:21.000000000 +0100
    35.6 -+++ linux-2.6.12-pdb/Makefile	2005-08-01 10:28:10.000000000 +0100
    35.7 -@@ -508,7 +508,7 @@
    35.8 - ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
    35.9 - CFLAGS		+= -Os
   35.10 - else
   35.11 --CFLAGS		+= -O2
   35.12 -+CFLAGS		+= -O
   35.13 - endif
   35.14 - 
   35.15 - #Add align options if CONFIG_CC_* is not equal to 0
    36.1 --- a/tools/debugger/pdb/linux-2.6-patches/ptrace.patch	Sun Oct 01 11:39:41 2006 -0600
    36.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    36.3 @@ -1,11 +0,0 @@
    36.4 -diff -u linux-2.6.12/kernel/ptrace.c linux-2.6.12-pdb/kernel/ptrace.c
    36.5 ---- linux-2.6.12/kernel/ptrace.c       2005-06-17 20:48:29.000000000 +0100
    36.6 -+++ linux-2.6.12-pdb/kernel/ptrace.c   2005-07-22 13:23:16.000000000 +0100
    36.7 -@@ -239,6 +239,7 @@
    36.8 - 
    36.9 -        return buf - old_buf;
   36.10 - }
   36.11 -+EXPORT_SYMBOL(access_process_vm);
   36.12 - 
   36.13 - int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst, int len)
   36.14 - {
    37.1 --- a/tools/debugger/pdb/linux-2.6-patches/traps.patch	Sun Oct 01 11:39:41 2006 -0600
    37.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    37.3 @@ -1,20 +0,0 @@
    37.4 -diff -u linux-2.6.12/arch/xen/i386/kernel/traps.c linux-2.6.12-pdb/arch/xen/i386/kernel/traps.c
    37.5 ---- linux-2.6.12/arch/xen/i386/kernel/traps.c	2005-07-31 22:47:00.000000000 +0100
    37.6 -+++ linux-2.6.12-pdb/arch/xen/i386/kernel/traps.c	2005-07-31 22:47:32.000000000 +0100
    37.7 -@@ -102,6 +102,16 @@
    37.8 - 	return err;
    37.9 - }
   37.10 - 
   37.11 -+int unregister_die_notifier(struct notifier_block *nb)
   37.12 -+{
   37.13 -+	int err = 0;
   37.14 -+	unsigned long flags;
   37.15 -+	spin_lock_irqsave(&die_notifier_lock, flags);
   37.16 -+	err = notifier_chain_unregister(&i386die_chain, nb);
   37.17 -+	spin_unlock_irqrestore(&die_notifier_lock, flags);
   37.18 -+	return err;
   37.19 -+}
   37.20 -+
   37.21 - static inline int valid_stack_ptr(struct thread_info *tinfo, void *p)
   37.22 - {
   37.23 - 	return	p > (void *)tinfo &&
    38.1 --- a/tools/debugger/pdb/pdb_caml_domain.c	Sun Oct 01 11:39:41 2006 -0600
    38.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    38.3 @@ -1,527 +0,0 @@
    38.4 -/*
    38.5 - * pdb_caml_xc.c
    38.6 - *
    38.7 - * http://www.cl.cam.ac.uk/netos/pdb
    38.8 - *
    38.9 - * PDB's OCaml interface library for debugging domains
   38.10 - */
   38.11 -
   38.12 -#include <xenctrl.h>
   38.13 -#include <xendebug.h>
   38.14 -#include <errno.h>
   38.15 -#include <stdio.h>
   38.16 -#include <stdlib.h>
   38.17 -#include <string.h>
   38.18 -#include <sys/mman.h>
   38.19 -#include <caml/alloc.h>
   38.20 -#include <caml/fail.h>
   38.21 -#include <caml/memory.h>
   38.22 -#include <caml/mlvalues.h>
   38.23 -
   38.24 -#include "pdb_caml_xen.h"
   38.25 -
   38.26 -typedef struct
   38.27 -{
   38.28 -    int domain;
   38.29 -    int vcpu;
   38.30 -} context_t;
   38.31 -
   38.32 -#define decode_context(_ctx, _ocaml)   \
   38.33 -{  \
   38.34 -    (_ctx)->domain = Int_val(Field((_ocaml),0));  \
   38.35 -    (_ctx)->vcpu = Int_val(Field((_ocaml),1));  \
   38.36 -}
   38.37 -
   38.38 -#define encode_context(_ctx, _ocaml)  \
   38.39 -{  \
   38.40 -    (_ocaml) = caml_alloc_tuple(2);  \
   38.41 -    Store_field((_ocaml), 0, Val_int((_ctx)->domain));  \
   38.42 -    Store_field((_ocaml), 1, Val_int((_ctx)->vcpu));  \
   38.43 -}
   38.44 -
   38.45 -
   38.46 -/****************************************************************************/
   38.47 -
   38.48 -/*
   38.49 - * dom_read_register : context_t -> int -> int32
   38.50 - */
   38.51 -value
   38.52 -dom_read_register (value context, value reg)
   38.53 -{
   38.54 -    CAMLparam2(context, reg);
   38.55 -    CAMLlocal1(result);
   38.56 -
   38.57 -    int my_reg = Int_val(reg);
   38.58 -    cpu_user_regs_t *regs;
   38.59 -    context_t ctx;
   38.60 -
   38.61 -    decode_context(&ctx, context);
   38.62 -
   38.63 -    if ( xendebug_read_registers(xc_handle, ctx.domain, ctx.vcpu, &regs) )
   38.64 -    {
   38.65 -        printf("(pdb) read registers error!\n");  fflush(stdout);
   38.66 -        failwith("read registers error");
   38.67 -    }
   38.68 -
   38.69 -    dump_regs(regs);
   38.70 -
   38.71 -    result = caml_alloc_tuple(16);
   38.72 -
   38.73 -    switch (my_reg)
   38.74 -    {
   38.75 -    case GDB_EAX: result = caml_copy_int32(regs->eax); break;
   38.76 -    case GDB_ECX: result = caml_copy_int32(regs->ecx); break;
   38.77 -    case GDB_EDX: result = caml_copy_int32(regs->edx); break;
   38.78 -    case GDB_EBX: result = caml_copy_int32(regs->ebx); break;
   38.79 -    case GDB_ESP: result = caml_copy_int32(regs->esp); break;
   38.80 -    case GDB_EBP: result = caml_copy_int32(regs->ebp); break;
   38.81 -    case GDB_ESI: result = caml_copy_int32(regs->esi); break;
   38.82 -    case GDB_EDI: result = caml_copy_int32(regs->edi); break;
   38.83 -    case GDB_EIP: result = caml_copy_int32(regs->eip); break;
   38.84 -    case GDB_EFL: result = caml_copy_int32(regs->eflags); break;
   38.85 -    case GDB_CS:  result = caml_copy_int32(regs->cs);  break;
   38.86 -    case GDB_SS: result = caml_copy_int32(regs->ss); break;
   38.87 -    case GDB_DS: result = caml_copy_int32(regs->ds); break;
   38.88 -    case GDB_ES: result = caml_copy_int32(regs->es); break;
   38.89 -    case GDB_FS: result = caml_copy_int32(regs->fs); break;
   38.90 -    case GDB_GS: result = caml_copy_int32(regs->gs); break;
   38.91 -    }
   38.92 -
   38.93 -    CAMLreturn(result);
   38.94 -}
   38.95 -
   38.96 -/*
   38.97 - * dom_read_registers : context_t -> int32
   38.98 - */
   38.99 -value
  38.100 -dom_read_registers (value context)
  38.101 -{
  38.102 -    CAMLparam1(context);
  38.103 -    CAMLlocal1(result);
  38.104 -
  38.105 -    cpu_user_regs_t *regs;
  38.106 -    context_t ctx;
  38.107 -
  38.108 -    decode_context(&ctx, context);
  38.109 -
  38.110 -    if ( xendebug_read_registers(xc_handle, ctx.domain, ctx.vcpu, &regs) )
  38.111 -    {
  38.112 -        printf("(pdb) read registers error!\n");  fflush(stdout);
  38.113 -        failwith("read registers error");
  38.114 -    }
  38.115 -
  38.116 -    dump_regs(regs);
  38.117 -
  38.118 -    result = caml_alloc_tuple(16);
  38.119 -
  38.120 -    Store_field(result,  0, caml_copy_int32(regs->eax));
  38.121 -    Store_field(result,  1, caml_copy_int32(regs->ecx));
  38.122 -    Store_field(result,  2, caml_copy_int32(regs->edx));
  38.123 -    Store_field(result,  3, caml_copy_int32(regs->ebx));
  38.124 -    Store_field(result,  4, caml_copy_int32(regs->esp));
  38.125 -    Store_field(result,  5, caml_copy_int32(regs->ebp));
  38.126 -    Store_field(result,  6, caml_copy_int32(regs->esi));
  38.127 -    Store_field(result,  7, caml_copy_int32(regs->edi));
  38.128 -    Store_field(result,  8, caml_copy_int32(regs->eip));
  38.129 -    Store_field(result,  9, caml_copy_int32(regs->eflags));
  38.130 -    Store_field(result, 10, caml_copy_int32(regs->cs));                /* 16 */
  38.131 -    Store_field(result, 11, caml_copy_int32(regs->ss));                /* 16 */
  38.132 -    Store_field(result, 12, caml_copy_int32(regs->ds));                /* 16 */
  38.133 -    Store_field(result, 13, caml_copy_int32(regs->es));                /* 16 */
  38.134 -    Store_field(result, 14, caml_copy_int32(regs->fs));                /* 16 */
  38.135 -    Store_field(result, 15, caml_copy_int32(regs->gs));                /* 16 */
  38.136 -
  38.137 -    CAMLreturn(result);
  38.138 -}
  38.139 -
  38.140 -
  38.141 -/*
  38.142 - * dom_write_register : context_t -> register -> int32 -> unit
  38.143 - */
  38.144 -value
  38.145 -dom_write_register (value context, value reg, value newval)
  38.146 -{
  38.147 -    CAMLparam3(context, reg, newval);
  38.148 -
  38.149 -    int my_reg = Int_val(reg);
  38.150 -    int val = Int32_val(newval);
  38.151 -
  38.152 -    context_t ctx;
  38.153 -    cpu_user_regs_t *regs;
  38.154 -
  38.155 -    printf("(pdb) write register\n");
  38.156 -
  38.157 -    decode_context(&ctx, context);
  38.158 -
  38.159 -    if ( xendebug_read_registers(xc_handle, ctx.domain, ctx.vcpu, &regs) )
  38.160 -    {
  38.161 -        printf("(pdb) write register (get) error!\n");  fflush(stdout);
  38.162 -        failwith("write register error");
  38.163 -    }
  38.164 -
  38.165 -    switch (my_reg)
  38.166 -    {
  38.167 -    case GDB_EAX: regs->eax = val; break;
  38.168 -    case GDB_ECX: regs->ecx = val; break;
  38.169 -    case GDB_EDX: regs->edx = val; break;
  38.170 -    case GDB_EBX: regs->ebx = val; break;
  38.171 -
  38.172 -    case GDB_ESP: regs->esp = val; break;
  38.173 -    case GDB_EBP: regs->ebp = val; break;
  38.174 -    case GDB_ESI: regs->esi = val; break;
  38.175 -    case GDB_EDI: regs->edi = val; break;
  38.176 - 
  38.177 -    case GDB_EIP: regs->eip = val; break;
  38.178 -    case GDB_EFL: regs->eflags = val; break;
  38.179 -
  38.180 -    case GDB_CS:  regs->cs  = val; break;
  38.181 -    case GDB_SS:  regs->ss  = val; break;
  38.182 -    case GDB_DS:  regs->ds  = val; break;
  38.183 -    case GDB_ES:  regs->es  = val; break;
  38.184 -    case GDB_FS:  regs->fs  = val; break;
  38.185 -    case GDB_GS:  regs->gs  = val; break;
  38.186 -    }
  38.187 -
  38.188 -    if ( xendebug_write_registers(xc_handle, ctx.domain, ctx.vcpu, regs) )
  38.189 -    {
  38.190 -        printf("(pdb) write register (set) error!\n");  fflush(stdout);
  38.191 -        failwith("write register error");
  38.192 -    }
  38.193 -
  38.194 -    CAMLreturn(Val_unit);
  38.195 -}
  38.196 -
  38.197 -/*
  38.198 - * dom_read_memory : context_t -> int32 -> int -> int
  38.199 - */
  38.200 -value
  38.201 -dom_read_memory (value context, value address, value length)
  38.202 -{
  38.203 -    CAMLparam3(context, address, length);
  38.204 -    CAMLlocal2(result, temp);
  38.205 -
  38.206 -    context_t ctx;
  38.207 -    int loop;
  38.208 -    char *buffer;
  38.209 -    unsigned long my_address = Int32_val(address);
  38.210 -    uint32_t my_length = Int_val(length);
  38.211 -
  38.212 -    printf ("(pdb) read memory\n");
  38.213 -
  38.214 -    decode_context(&ctx, context);
  38.215 -
  38.216 -    buffer = malloc(my_length);
  38.217 -    if ( buffer == NULL )
  38.218 -    {
  38.219 -        printf("(pdb) read memory: malloc failed.\n");  fflush(stdout);
  38.220 -        failwith("read memory error");
  38.221 -    }
  38.222 -
  38.223 -    if ( xendebug_read_memory(xc_handle, ctx.domain, ctx.vcpu, 
  38.224 -                              my_address, my_length, buffer) )
  38.225 -    {
  38.226 -        printf("(pdb) read memory error!\n");  fflush(stdout);
  38.227 -        failwith("read memory error");
  38.228 -    }
  38.229 -
  38.230 -    result = caml_alloc(2,0);
  38.231 -    if ( my_length > 0 )                                              /* car */
  38.232 -    {
  38.233 -        Store_field(result, 0, Val_int(buffer[my_length - 1] & 0xff));
  38.234 -    }
  38.235 -    else
  38.236 -
  38.237 -    {
  38.238 -        Store_field(result, 0, Val_int(0));                    
  38.239 -    }
  38.240 -    Store_field(result, 1, Val_int(0));                               /* cdr */
  38.241 -
  38.242 -    for (loop = 1; loop < my_length; loop++)
  38.243 -    {
  38.244 -        temp = result;
  38.245 -        result = caml_alloc(2,0);
  38.246 -        Store_field(result, 0, Val_int(buffer[my_length - loop - 1] & 0xff));
  38.247 -        Store_field(result, 1, temp);
  38.248 -    }
  38.249 -
  38.250 -    CAMLreturn(result);
  38.251 -}
  38.252 -
  38.253 -/*
  38.254 - * dom_write_memory : context_t -> int32 -> int list -> unit
  38.255 - */
  38.256 -value
  38.257 -dom_write_memory (value context, value address, value val_list)
  38.258 -{
  38.259 -    CAMLparam3(context, address, val_list);
  38.260 -    CAMLlocal1(node);
  38.261 -
  38.262 -    context_t ctx;
  38.263 -
  38.264 -    char buffer[4096];  /* a big buffer */
  38.265 -    unsigned long  my_address;
  38.266 -    uint32_t length = 0;
  38.267 -
  38.268 -    printf ("(pdb) write memory\n");
  38.269 -
  38.270 -    decode_context(&ctx, context);
  38.271 -
  38.272 -    node = val_list;
  38.273 -    if ( Int_val(node) == 0 )       /* gdb functionalty test uses empty list */
  38.274 -    {
  38.275 -        CAMLreturn(Val_unit);
  38.276 -    }
  38.277 -
  38.278 -    while ( Int_val(Field(node,1)) != 0 )
  38.279 -    {
  38.280 -        buffer[length++] = Int_val(Field(node, 0));
  38.281 -        node = Field(node,1);
  38.282 -    }
  38.283 -    buffer[length++] = Int_val(Field(node, 0));
  38.284 -
  38.285 -    my_address = (unsigned long) Int32_val(address);
  38.286 -
  38.287 -    if ( xendebug_write_memory(xc_handle, ctx.domain, ctx.vcpu,
  38.288 -                               my_address, length, buffer) )
  38.289 -    {
  38.290 -        printf("(pdb) write memory error!\n");  fflush(stdout);
  38.291 -        failwith("write memory error");
  38.292 -    }
  38.293 -
  38.294 -    CAMLreturn(Val_unit);
  38.295 -}
  38.296 -
  38.297 -/*
  38.298 - * dom_continue_target : context_t -> unit
  38.299 - */
  38.300 -value
  38.301 -dom_continue_target (value context)
  38.302 -{
  38.303 -    CAMLparam1(context);
  38.304 -
  38.305 -    context_t ctx;
  38.306 -
  38.307 -    decode_context(&ctx, context);
  38.308 -
  38.309 -    if ( xendebug_continue(xc_handle, ctx.domain, ctx.vcpu) )
  38.310 -    {
  38.311 -        printf("(pdb) continue\n");  fflush(stdout);
  38.312 -        failwith("continue");
  38.313 -    }
  38.314 -
  38.315 -    CAMLreturn(Val_unit);
  38.316 -}
  38.317 -
  38.318 -/*
  38.319 - * dom_step_target : context_t -> unit
  38.320 - */
  38.321 -value
  38.322 -dom_step_target (value context)
  38.323 -{
  38.324 -    CAMLparam1(context);
  38.325 -
  38.326 -    context_t ctx;
  38.327 -
  38.328 -    decode_context(&ctx, context);
  38.329 -
  38.330 -    if ( xendebug_step(xc_handle, ctx.domain, ctx.vcpu) )
  38.331 -    {
  38.332 -        printf("(pdb) step\n");  fflush(stdout);
  38.333 -        failwith("step");
  38.334 -    }
  38.335 -
  38.336 -    CAMLreturn(Val_unit);
  38.337 -}
  38.338 -
  38.339 -
  38.340 -
  38.341 -/*
  38.342 - * dom_insert_memory_breakpoint : context_t -> int32 -> int list -> unit
  38.343 - */
  38.344 -value
  38.345 -dom_insert_memory_breakpoint (value context, value address, value length)
  38.346 -{
  38.347 -    CAMLparam3(context, address, length);
  38.348 -
  38.349 -    context_t ctx;
  38.350 -    unsigned long my_address = (unsigned long) Int32_val(address);
  38.351 -    int my_length = Int_val(length);
  38.352 -
  38.353 -    decode_context(&ctx, context);
  38.354 -
  38.355 -    printf ("(pdb) insert memory breakpoint 0x%lx %d\n",
  38.356 -            my_address, my_length);
  38.357 -
  38.358 -    if ( xendebug_insert_memory_breakpoint(xc_handle, ctx.domain, ctx.vcpu,
  38.359 -                                           my_address, my_length) )
  38.360 -    {
  38.361 -        printf("(pdb) error: insert memory breakpoint\n");  fflush(stdout);
  38.362 -        failwith("insert memory breakpoint");
  38.363 -    }
  38.364 -
  38.365 -
  38.366 -    CAMLreturn(Val_unit);
  38.367 -}
  38.368 -
  38.369 -/*
  38.370 - * dom_remove_memory_breakpoint : context_t -> int32 -> int list -> unit
  38.371 - */
  38.372 -value
  38.373 -dom_remove_memory_breakpoint (value context, value address, value length)
  38.374 -{
  38.375 -    CAMLparam3(context, address, length);
  38.376 -
  38.377 -    context_t ctx;
  38.378 -
  38.379 -    unsigned long my_address = (unsigned long) Int32_val(address);
  38.380 -    int my_length = Int_val(length);
  38.381 -
  38.382 -    printf ("(pdb) remove memory breakpoint 0x%lx %d\n",
  38.383 -            my_address, my_length);
  38.384 -
  38.385 -    decode_context(&ctx, context);
  38.386 -
  38.387 -    if ( xendebug_remove_memory_breakpoint(xc_handle, 
  38.388 -                                           ctx.domain, ctx.vcpu,
  38.389 -                                           my_address, my_length) )
  38.390 -    {
  38.391 -        printf("(pdb) error: remove memory breakpoint\n");  fflush(stdout);
  38.392 -        failwith("remove memory breakpoint");
  38.393 -    }
  38.394 -
  38.395 -    CAMLreturn(Val_unit);
  38.396 -}
  38.397 -
  38.398 -/*
  38.399 - * dom_attach_debugger : int -> int -> unit
  38.400 - */
  38.401 -value
  38.402 -dom_attach_debugger (value domain, value vcpu)
  38.403 -{
  38.404 -    CAMLparam2(domain, vcpu);
  38.405 -
  38.406 -    int my_domain = Int_val(domain);
  38.407 -    int my_vcpu = Int_val(vcpu);
  38.408 -
  38.409 -    printf ("(pdb) attach domain [%d.%d]\n", my_domain, my_vcpu);
  38.410 -
  38.411 -    if ( xendebug_attach(xc_handle, my_domain, my_vcpu) )
  38.412 -    {
  38.413 -        printf("(pdb) attach error!\n");  fflush(stdout);
  38.414 -        failwith("attach error");
  38.415 -    }
  38.416 -
  38.417 -    CAMLreturn(Val_unit);
  38.418 -}
  38.419 -
  38.420 -
  38.421 -/*
  38.422 - * dom_detach_debugger : int -> int -> unit
  38.423 - */
  38.424 -value
  38.425 -dom_detach_debugger (value domain, value vcpu)
  38.426 -{
  38.427 -    CAMLparam2(domain, vcpu);
  38.428 -
  38.429 -    int my_domain = Int_val(domain);
  38.430 -    int my_vcpu = Int_val(vcpu);
  38.431 -
  38.432 -    printf ("(pdb) detach domain [%d.%d]\n", my_domain, my_vcpu);
  38.433 -
  38.434 -    if ( xendebug_detach(xc_handle, my_domain, my_vcpu) )
  38.435 -    {
  38.436 -        printf("(pdb) detach error!\n");  fflush(stdout);
  38.437 -        failwith("detach error");
  38.438 -    }
  38.439 -
  38.440 -    CAMLreturn(Val_unit);
  38.441 -}
  38.442 -
  38.443 -
  38.444 -/*
  38.445 - * dom_pause_target : int -> unit
  38.446 - */
  38.447 -value
  38.448 -dom_pause_target (value domid)
  38.449 -{
  38.450 -    CAMLparam1(domid);
  38.451 -
  38.452 -    int my_domid = Int_val(domid);
  38.453 -
  38.454 -    printf ("(pdb) pause target %d\n", my_domid);
  38.455 -
  38.456 -    xc_domain_pause(xc_handle, my_domid);
  38.457 -
  38.458 -    CAMLreturn(Val_unit);
  38.459 -}
  38.460 -
  38.461 -/****************************************************************************/
  38.462 -/****************************************************************************/
  38.463 -
  38.464 -/*
  38.465 - * query_domain_stop : unit -> (int * int) list
  38.466 - */
  38.467 -value
  38.468 -query_domain_stop (value unit)
  38.469 -{
  38.470 -    CAMLparam1(unit);
  38.471 -    CAMLlocal3(result, temp, node);
  38.472 -
  38.473 -    int max_domains = 20;
  38.474 -    int dom_list[max_domains];
  38.475 -    int loop, count;
  38.476 -
  38.477 -    count = xendebug_query_domain_stop(xc_handle, dom_list, max_domains);
  38.478 -    if ( count < 0 )
  38.479 -    {
  38.480 -        printf("(pdb) query domain stop!\n");  fflush(stdout);
  38.481 -        failwith("query domain stop");
  38.482 -    }
  38.483 -
  38.484 -    printf ("QDS [%d]: \n", count);
  38.485 -    for (loop = 0; loop < count; loop ++)
  38.486 -        printf (" %d", dom_list[loop]);
  38.487 -    printf ("\n");
  38.488 -
  38.489 -    result = caml_alloc(2,0);
  38.490 -    if ( count > 0 )                                                  /* car */
  38.491 -    {
  38.492 -        node = caml_alloc(2,0);
  38.493 -        Store_field(node, 0, Val_int(dom_list[0]));             /* domain id */
  38.494 -        Store_field(node, 1, Val_int(0));                            /* vcpu */
  38.495 -        Store_field(result, 0, node);
  38.496 -    }
  38.497 -    else
  38.498 -    {
  38.499 -        Store_field(result, 0, Val_int(0));                    
  38.500 -    }
  38.501 -    Store_field(result, 1, Val_int(0));                               /* cdr */
  38.502 -
  38.503 -    for ( loop = 1; loop < count; loop++ )
  38.504 -    {
  38.505 -        temp = result;
  38.506 -        result = caml_alloc(2,0);
  38.507 -        node = caml_alloc(2,0);
  38.508 -        Store_field(node, 0, Val_int(dom_list[loop]));          /* domain id */
  38.509 -        Store_field(node, 1, Val_int(0));                            /* vcpu */
  38.510 -        Store_field(result, 0, node);
  38.511 -        Store_field(result, 1, temp);
  38.512 -    }
  38.513 -
  38.514 -    CAMLreturn(result);
  38.515 -}
  38.516 -
  38.517 -/****************************************************************************/
  38.518 -
  38.519 -
  38.520 -
  38.521 -/*
  38.522 - * Local variables:
  38.523 - * mode: C
  38.524 - * c-set-style: "BSD"
  38.525 - * c-basic-offset: 4
  38.526 - * tab-width: 4
  38.527 - * indent-tabs-mode: nil
  38.528 - * End:
  38.529 - */
  38.530 -
    39.1 --- a/tools/debugger/pdb/pdb_caml_evtchn.c	Sun Oct 01 11:39:41 2006 -0600
    39.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    39.3 @@ -1,186 +0,0 @@
    39.4 -/*
    39.5 - * pdb_caml_evtchn.c
    39.6 - *
    39.7 - * http://www.cl.cam.ac.uk/netos/pdb
    39.8 - *
    39.9 - * PDB's OCaml interface library for event channels
   39.10 - */
   39.11 -
   39.12 -#include <xenctrl.h>
   39.13 -#include <stdio.h>
   39.14 -#include <stdlib.h>
   39.15 -#include <string.h>
   39.16 -
   39.17 -#include <caml/alloc.h>
   39.18 -#include <caml/fail.h>
   39.19 -#include <caml/memory.h>
   39.20 -#include <caml/mlvalues.h>
   39.21 -
   39.22 -
   39.23 -#include <errno.h>
   39.24 -#include <sys/ioctl.h>
   39.25 -#include <sys/stat.h>
   39.26 -#include <fcntl.h>
   39.27 -#include <unistd.h>
   39.28 -
   39.29 -int xen_evtchn_bind (int evtchn_fd, int idx);
   39.30 -int xen_evtchn_unbind (int evtchn_fd, int idx);
   39.31 -
   39.32 -int
   39.33 -__evtchn_open (char *filename, int major, int minor)
   39.34 -{
   39.35 -    int   evtchn_fd;
   39.36 -    struct stat st;
   39.37 -    
   39.38 -    /* Make sure any existing device file links to correct device. */
   39.39 -    if ( (lstat(filename, &st) != 0) ||
   39.40 -         !S_ISCHR(st.st_mode) ||
   39.41 -         (st.st_rdev != makedev(major, minor)) )
   39.42 -    {
   39.43 -        (void)unlink(filename);
   39.44 -    }
   39.45 -
   39.46 - reopen:
   39.47 -    evtchn_fd = open(filename, O_RDWR); 
   39.48 -    if ( evtchn_fd == -1 )
   39.49 -    {
   39.50 -        if ( (errno == ENOENT) &&
   39.51 -             ((mkdir("/dev/xen", 0755) == 0) || (errno == EEXIST)) &&
   39.52 -             (mknod(filename, S_IFCHR|0600, makedev(major,minor)) == 0) )
   39.53 -        {
   39.54 -            goto reopen;
   39.55 -        }
   39.56 -        return -errno;
   39.57 -    }
   39.58 -
   39.59 -    return evtchn_fd;
   39.60 -}
   39.61 -
   39.62 -/*
   39.63 - * evtchn_open : string -> int -> int -> Unix.file_descr
   39.64 - *
   39.65 - * OCaml's Unix library doesn't have mknod, so it makes more sense just write
   39.66 - * this in C.  This code is from Keir/Andy.
   39.67 - */
   39.68 -value
   39.69 -evtchn_open (value filename, value major, value minor)
   39.70 -{
   39.71 -    CAMLparam3(filename, major, minor);
   39.72 -
   39.73 -    char *myfilename = String_val(filename);
   39.74 -    int   mymajor = Int_val(major);
   39.75 -    int   myminor = Int_val(minor);
   39.76 -    int   evtchn_fd;
   39.77 -
   39.78 -    evtchn_fd = __evtchn_open(myfilename, mymajor, myminor);
   39.79 -
   39.80 -    CAMLreturn(Val_int(evtchn_fd));
   39.81 -}
   39.82 -
   39.83 -/*
   39.84 - * evtchn_bind : Unix.file_descr -> int -> unit
   39.85 - */
   39.86 -value
   39.87 -evtchn_bind (value fd, value idx)
   39.88 -{
   39.89 -    CAMLparam2(fd, idx);
   39.90 -
   39.91 -    int myfd = Int_val(fd);
   39.92 -    int myidx = Int_val(idx);
   39.93 -
   39.94 -    if ( xen_evtchn_bind(myfd, myidx) < 0 )
   39.95 -    {
   39.96 -        printf("(pdb) evtchn_bind error!\n");  fflush(stdout);
   39.97 -        failwith("evtchn_bind error");
   39.98 -    }
   39.99 -
  39.100 -    CAMLreturn(Val_unit);
  39.101 -}
  39.102 -
  39.103 -/*
  39.104 - * evtchn_unbind : Unix.file_descr -> int -> unit
  39.105 - */
  39.106 -value
  39.107 -evtchn_unbind (value fd, value idx)
  39.108 -{
  39.109 -    CAMLparam2(fd, idx);
  39.110 -
  39.111 -    int myfd = Int_val(fd);
  39.112 -    int myidx = Int_val(idx);
  39.113 -
  39.114 -    if ( xen_evtchn_unbind(myfd, myidx) < 0 )
  39.115 -    {
  39.116 -        printf("(pdb) evtchn_unbind error!\n");  fflush(stdout);
  39.117 -        failwith("evtchn_unbind error");
  39.118 -    }
  39.119 -
  39.120 -    CAMLreturn(Val_unit);
  39.121 -}
  39.122 -
  39.123 -/*
  39.124 - * evtchn_read : Unix.file_descr -> int
  39.125 - */
  39.126 -value
  39.127 -evtchn_read (value fd)
  39.128 -{
  39.129 -    CAMLparam1(fd);
  39.130 -
  39.131 -    uint16_t v;
  39.132 -    int bytes;
  39.133 -    int rc = -1;
  39.134 -    int myfd = Int_val(fd);
  39.135 -
  39.136 -    while ( (bytes = read(myfd, &v, sizeof(v))) == -1 )
  39.137 -    {
  39.138 -        if ( errno == EINTR )  continue;
  39.139 -        rc = -errno;
  39.140 -        goto exit;
  39.141 -    }
  39.142 -    
  39.143 -    if ( bytes == sizeof(v) )
  39.144 -        rc = v;
  39.145 -    
  39.146 - exit:
  39.147 -    CAMLreturn(Val_int(rc));
  39.148 -}
  39.149 -
  39.150 -
  39.151 -/*
  39.152 - * evtchn_close : Unix.file_descr -> unit
  39.153 - */
  39.154 -value
  39.155 -evtchn_close (value fd)
  39.156 -{
  39.157 -    CAMLparam1(fd);
  39.158 -    int myfd = Int_val(fd);
  39.159 -
  39.160 -    (void)close(myfd);
  39.161 -
  39.162 -    CAMLreturn(Val_unit);
  39.163 -}
  39.164 -
  39.165 -/*
  39.166 - * evtchn_unmask : Unix.file_descr -> int -> unit
  39.167 - */
  39.168 -value
  39.169 -evtchn_unmask (value fd, value idx)
  39.170 -{
  39.171 -    CAMLparam1(fd);
  39.172 -
  39.173 -    int myfd = Int_val(fd);
  39.174 -    uint16_t myidx = Int_val(idx);
  39.175 -
  39.176 -    (void)write(myfd, &myidx, sizeof(myidx));
  39.177 -
  39.178 -    CAMLreturn(Val_unit);
  39.179 -}
  39.180 -
  39.181 -/*
  39.182 - * Local variables:
  39.183 - * mode: C
  39.184 - * c-set-style: "BSD"
  39.185 - * c-basic-offset: 4
  39.186 - * tab-width: 4
  39.187 - * indent-tabs-mode: nil
  39.188 - * End:
  39.189 - */
    40.1 --- a/tools/debugger/pdb/pdb_caml_process.c	Sun Oct 01 11:39:41 2006 -0600
    40.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    40.3 @@ -1,587 +0,0 @@
    40.4 -/*
    40.5 - * pdb_caml_process.c
    40.6 - *
    40.7 - * http://www.cl.cam.ac.uk/netos/pdb
    40.8 - *
    40.9 - * PDB's OCaml interface library for debugging processes
   40.10 - */
   40.11 -
   40.12 -#include <errno.h>
   40.13 -#include <stdio.h>
   40.14 -#include <stdlib.h>
   40.15 -#include <string.h>
   40.16 -#include <caml/alloc.h>
   40.17 -#include <caml/fail.h>
   40.18 -#include <caml/memory.h>
   40.19 -#include <caml/mlvalues.h>
   40.20 -
   40.21 -#include <xenctrl.h>
   40.22 -#include <xen/xen.h>
   40.23 -#include <xen/io/domain_controller.h>
   40.24 -#include "pdb_module.h"
   40.25 -#include "pdb_caml_xen.h"
   40.26 -
   40.27 -typedef struct
   40.28 -{
   40.29 -    int domain;
   40.30 -    int process;
   40.31 -    int evtchn;
   40.32 -    pdb_front_ring_t *ring;
   40.33 -} context_t;
   40.34 -
   40.35 -#define decode_context(_ctx, _ocaml)   \
   40.36 -{  \
   40.37 -    (_ctx)->domain  = Int_val(Field((_ocaml),0));  \
   40.38 -    (_ctx)->process = Int_val(Field((_ocaml),1));  \
   40.39 -    (_ctx)->evtchn  = Int_val(Field((_ocaml),2));  \
   40.40 -    (_ctx)->ring    =  (pdb_front_ring_t *)Int32_val(Field((_ocaml),3));  \
   40.41 -}
   40.42 -
   40.43 -#define encode_context(_ctx, _ocaml)  \
   40.44 -{  \
   40.45 -    (_ocaml) = caml_alloc_tuple(2);  \
   40.46 -    Store_field((_ocaml), 0, Val_int((_ctx)->domain));  \
   40.47 -    Store_field((_ocaml), 1, Val_int((_ctx)->process));  \
   40.48 -}
   40.49 -
   40.50 -/*
   40.51 - * send a request to a pdb domain backend.
   40.52 - *
   40.53 - * puts the request on a ring and kicks the backend using an event channel.
   40.54 - */
   40.55 -static void
   40.56 -send_request (pdb_front_ring_t *pdb_ring, int evtchn, pdb_request_t *request)
   40.57 -{
   40.58 -    pdb_request_t    *req;
   40.59 -
   40.60 -    req = RING_GET_REQUEST(pdb_ring, pdb_ring->req_prod_pvt);
   40.61 -
   40.62 -    memcpy(req, request, sizeof(pdb_request_t));
   40.63 -
   40.64 -    pdb_ring->req_prod_pvt++;
   40.65 -
   40.66 -    RING_PUSH_REQUESTS(pdb_ring);
   40.67 -    xc_evtchn_send(xc_handle, evtchn);
   40.68 -}
   40.69 -
   40.70 -/*
   40.71 - * process_handle_response : int32 -> int * int * string
   40.72 - *
   40.73 - * A backend domain has notified pdb (via an event channel)
   40.74 - * that a command has finished.
   40.75 - * We read the result from the channel and formulate a response
   40.76 - * as a single string.  Also return the domain and process.
   40.77 - */
   40.78 -
   40.79 -static inline unsigned int
   40.80 -_flip (unsigned int orig)
   40.81 -{
   40.82 -    return (((orig << 24) & 0xff000000) | ((orig <<  8) & 0x00ff0000) |
   40.83 -            ((orig >>  8) & 0x0000ff00) | ((orig >> 24) & 0x000000ff));
   40.84 -}
   40.85 -
   40.86 -value
   40.87 -process_handle_response (value ring)
   40.88 -{
   40.89 -    CAMLparam1(ring);
   40.90 -    CAMLlocal2(result, str);
   40.91 -
   40.92 -    RING_IDX rp;
   40.93 -    pdb_response_p resp;
   40.94 -    pdb_front_ring_t *my_ring = (pdb_front_ring_t *)Int32_val(ring);
   40.95 -    char msg[2048];
   40.96 -    int msglen;
   40.97 -
   40.98 -    memset(msg, 0, sizeof(msg));
   40.99 -
  40.100 -    rp = my_ring->sring->rsp_prod;
  40.101 -    rmb();                     /* Ensure we see queued responses up to 'rp'. */
  40.102 -
  40.103 -    /* default response is OK unless the command has something 
  40.104 -       more interesting to say */
  40.105 -    sprintf(msg, "OK");
  40.106 -
  40.107 -    if (my_ring->rsp_cons != rp)
  40.108 -    {
  40.109 -        resp = RING_GET_RESPONSE(my_ring, my_ring->rsp_cons);
  40.110 -
  40.111 -        switch (resp->operation)
  40.112 -        {
  40.113 -        case PDB_OPCODE_PAUSE :
  40.114 -        case PDB_OPCODE_ATTACH :
  40.115 -        case PDB_OPCODE_DETACH :
  40.116 -            break;
  40.117 -            
  40.118 -        case PDB_OPCODE_RD_REG :
  40.119 -        {
  40.120 -            sprintf(&msg[0], "%08x", _flip(resp->u.rd_reg.value));
  40.121 -            break;
  40.122 -        }
  40.123 -
  40.124 -        case PDB_OPCODE_RD_REGS :
  40.125 -        {
  40.126 -            int loop;
  40.127 -            pdb_op_rd_regs_p regs = &resp->u.rd_regs;
  40.128 -            
  40.129 -            for (loop = 0; loop < GDB_REGISTER_FRAME_SIZE * 8; loop += 8)
  40.130 -            {
  40.131 -                sprintf(&msg[loop], "%08x", _flip(regs->reg[loop >> 3]));
  40.132 -            }
  40.133 -                
  40.134 -            break;
  40.135 -        }
  40.136 -        case PDB_OPCODE_WR_REG :
  40.137 -        {
  40.138 -            /* should check the return status */
  40.139 -            break;
  40.140 -        }
  40.141 -
  40.142 -        case PDB_OPCODE_RD_MEM :
  40.143 -        {
  40.144 -            int loop;
  40.145 -            pdb_op_rd_mem_resp_p mem = &resp->u.rd_mem;
  40.146 -
  40.147 -            for (loop = 0; loop < mem->length; loop ++)
  40.148 -            {
  40.149 -                sprintf(&msg[loop * 2], "%02x", mem->data[loop]);
  40.150 -            }
  40.151 -            break;
  40.152 -        }
  40.153 -        case PDB_OPCODE_WR_MEM :
  40.154 -        {
  40.155 -            /* should check the return status */
  40.156 -            break;
  40.157 -        }
  40.158 -
  40.159 -        /* this is equivalent to process_xen_virq */
  40.160 -        case PDB_OPCODE_CONTINUE :
  40.161 -        {
  40.162 -            sprintf(msg, "S05");
  40.163 -            break;
  40.164 -        }
  40.165 -        case PDB_OPCODE_STEP :
  40.166 -        {
  40.167 -            sprintf(msg, "S05");
  40.168 -            break;
  40.169 -        }
  40.170 -
  40.171 -        case PDB_OPCODE_SET_BKPT :
  40.172 -        case PDB_OPCODE_CLR_BKPT :
  40.173 -        case PDB_OPCODE_SET_WATCHPT :
  40.174 -        case PDB_OPCODE_CLR_WATCHPT :
  40.175 -        {
  40.176 -            break;
  40.177 -        }
  40.178 -
  40.179 -        case PDB_OPCODE_WATCHPOINT :
  40.180 -        {
  40.181 -            sprintf(msg, "S05");
  40.182 -            break;
  40.183 -        }
  40.184 -
  40.185 -        default :
  40.186 -            printf("(linux) UNKNOWN MESSAGE TYPE IN RESPONSE %d\n",
  40.187 -                   resp->operation);
  40.188 -            break;
  40.189 -        }
  40.190 -
  40.191 -        my_ring->rsp_cons++;
  40.192 -    }
  40.193 -
  40.194 -    msglen = strlen(msg);
  40.195 -    result = caml_alloc(3,0);
  40.196 -    str = alloc_string(msglen);
  40.197 -    memmove(&Byte(str,0), msg, msglen);
  40.198 -
  40.199 -    Store_field(result, 0, Val_int(resp->domain));
  40.200 -    Store_field(result, 1, Val_int(resp->process));
  40.201 -    Store_field(result, 2, str);
  40.202 -
  40.203 -    CAMLreturn(result);
  40.204 -}
  40.205 -
  40.206 -/*
  40.207 - * proc_attach_debugger : context_t -> unit
  40.208 - */
  40.209 -value
  40.210 -proc_attach_debugger (value context)
  40.211 -{
  40.212 -    CAMLparam1(context);
  40.213 -    context_t ctx;
  40.214 -    pdb_request_t req;
  40.215 -
  40.216 -    decode_context(&ctx, context);
  40.217 -
  40.218 -    req.operation = PDB_OPCODE_ATTACH;
  40.219 -    req.u.attach.domain  = ctx.domain;
  40.220 -    req.process = ctx.process;
  40.221 -
  40.222 -    send_request (ctx.ring, ctx.evtchn, &req);
  40.223 -
  40.224 -    CAMLreturn(Val_unit);
  40.225 -}
  40.226 -
  40.227 -
  40.228 -/*
  40.229 - * proc_detach_debugger : context_t -> unit
  40.230 - */
  40.231 -value
  40.232 -proc_detach_debugger (value context)
  40.233 -{
  40.234 -    CAMLparam1(context);
  40.235 -    context_t ctx;
  40.236 -    pdb_request_t req;
  40.237 -
  40.238 -    decode_context(&ctx, context);
  40.239 -
  40.240 -    printf("(pdb) detach process [%d.%d] %d %p\n", ctx.domain, ctx.process,
  40.241 -           ctx.evtchn, ctx.ring);
  40.242 -    fflush(stdout);
  40.243 -
  40.244 -    req.operation = PDB_OPCODE_DETACH;
  40.245 -    req.process = ctx.process;
  40.246 -
  40.247 -    send_request (ctx.ring, ctx.evtchn, &req);
  40.248 -
  40.249 -    CAMLreturn(Val_unit);
  40.250 -}
  40.251 -
  40.252 -
  40.253 -/*
  40.254 - * proc_pause_target : int -> unit
  40.255 - */
  40.256 -value
  40.257 -proc_pause_target (value context)
  40.258 -{
  40.259 -    CAMLparam1(context);
  40.260 -    context_t ctx;
  40.261 -    pdb_request_t req;
  40.262 -
  40.263 -    decode_context(&ctx, context);
  40.264 -
  40.265 -    printf("(pdb) pause target %d %d\n", ctx.domain, ctx.process);
  40.266 -    fflush(stdout);
  40.267 -
  40.268 -    req.operation = PDB_OPCODE_PAUSE;
  40.269 -    req.process = ctx.process;
  40.270 -
  40.271 -    send_request (ctx.ring, ctx.evtchn, &req);
  40.272 -
  40.273 -    CAMLreturn(Val_unit);
  40.274 -}
  40.275 -
  40.276 -
  40.277 -/*
  40.278 - * proc_read_register : context_t -> int -> unit
  40.279 - */
  40.280 -value
  40.281 -proc_read_register (value context, value reg)
  40.282 -{
  40.283 -    CAMLparam1(context);
  40.284 -
  40.285 -    pdb_request_t req;
  40.286 -    context_t ctx;
  40.287 -    int my_reg = Int_val(reg);
  40.288 -
  40.289 -    decode_context(&ctx, context);
  40.290 -
  40.291 -    req.operation = PDB_OPCODE_RD_REG;
  40.292 -    req.process = ctx.process;
  40.293 -    req.u.rd_reg.reg = my_reg;
  40.294 -    req.u.rd_reg.value = 0;
  40.295 -
  40.296 -    send_request (ctx.ring, ctx.evtchn, &req);
  40.297 -
  40.298 -    CAMLreturn(Val_unit);
  40.299 -}
  40.300 -
  40.301 -
  40.302 -
  40.303 -/*
  40.304 - * proc_read_registers : context_t -> unit
  40.305 - */
  40.306 -value
  40.307 -proc_read_registers (value context)
  40.308 -{
  40.309 -    CAMLparam1(context);
  40.310 -
  40.311 -    pdb_request_t req;
  40.312 -    context_t ctx;
  40.313 -
  40.314 -    decode_context(&ctx, context);
  40.315 -
  40.316 -    req.operation = PDB_OPCODE_RD_REGS;
  40.317 -    req.process = ctx.process;
  40.318 -
  40.319 -    send_request (ctx.ring, ctx.evtchn, &req);
  40.320 -
  40.321 -    CAMLreturn(Val_unit);
  40.322 -}
  40.323 -
  40.324 -
  40.325 -/*
  40.326 - * proc_write_register : context_t -> register -> int32 -> unit
  40.327 - */
  40.328 -value
  40.329 -proc_write_register (value context, value reg, value newval)
  40.330 -{
  40.331 -    CAMLparam3(context, reg, newval);
  40.332 -
  40.333 -    int my_reg = Int_val(reg);
  40.334 -    unsigned long my_newval = Int32_val(newval);
  40.335 -
  40.336 -    context_t ctx;
  40.337 -    pdb_request_t req;
  40.338 -
  40.339 -    decode_context(&ctx, context);
  40.340 -
  40.341 -    req.operation = PDB_OPCODE_WR_REG;
  40.342 -    req.process = ctx.process;
  40.343 -    req.u.wr_reg.value = my_newval;
  40.344 -
  40.345 -    switch (my_reg)
  40.346 -    {
  40.347 -    case GDB_EAX: req.u.wr_reg.reg = LINUX_EAX; break;
  40.348 -    case GDB_ECX: req.u.wr_reg.reg = LINUX_ECX; break;
  40.349 -    case GDB_EDX: req.u.wr_reg.reg = LINUX_EDX; break;
  40.350 -    case GDB_EBX: req.u.wr_reg.reg = LINUX_EBX; break;
  40.351 -
  40.352 -    case GDB_ESP: req.u.wr_reg.reg = LINUX_ESP; break;
  40.353 -    case GDB_EBP: req.u.wr_reg.reg = LINUX_EBP; break;
  40.354 -    case GDB_ESI: req.u.wr_reg.reg = LINUX_ESI; break;
  40.355 -    case GDB_EDI: req.u.wr_reg.reg = LINUX_EDI; break;
  40.356 -
  40.357 -    case GDB_EIP: req.u.wr_reg.reg = LINUX_EIP; break;
  40.358 -    case GDB_EFL: req.u.wr_reg.reg = LINUX_EFL; break;
  40.359 - 
  40.360 -    case GDB_CS:  req.u.wr_reg.reg = LINUX_CS; break;
  40.361 -    case GDB_SS:  req.u.wr_reg.reg = LINUX_SS; break;
  40.362 -    case GDB_DS:  req.u.wr_reg.reg = LINUX_DS; break;
  40.363 -    case GDB_ES:  req.u.wr_reg.reg = LINUX_ES; break;
  40.364 -    case GDB_FS:  req.u.wr_reg.reg = LINUX_FS; break;
  40.365 -    case GDB_GS:  req.u.wr_reg.reg = LINUX_GS; break;
  40.366 -    }
  40.367 -
  40.368 -    send_request(ctx.ring, ctx.evtchn, &req);
  40.369 -
  40.370 -    CAMLreturn(Val_unit);
  40.371 -}
  40.372 -
  40.373 -
  40.374 -/*
  40.375 - * proc_read_memory : context_t -> int32 -> int -> unit
  40.376 - */
  40.377 -value
  40.378 -proc_read_memory (value context, value address, value length)
  40.379 -{
  40.380 -    CAMLparam3(context, address, length);
  40.381 -
  40.382 -    context_t ctx;
  40.383 -    pdb_request_t req;
  40.384 -
  40.385 -    decode_context(&ctx, context);
  40.386 -
  40.387 -    req.operation = PDB_OPCODE_RD_MEM;
  40.388 -    req.process = ctx.process;
  40.389 -    req.u.rd_mem.address = Int32_val(address);
  40.390 -    req.u.rd_mem.length  = Int_val(length);
  40.391 -
  40.392 -    send_request(ctx.ring, ctx.evtchn, &req);
  40.393 -    
  40.394 -    CAMLreturn(Val_unit);
  40.395 -}
  40.396 -
  40.397 -
  40.398 -/*
  40.399 - * proc_write_memory : context_t -> int32 -> int list -> unit
  40.400 - */
  40.401 -value
  40.402 -proc_write_memory (value context, value address, value val_list)
  40.403 -{
  40.404 -    CAMLparam3(context, address, val_list);
  40.405 -    CAMLlocal1(node);
  40.406 -
  40.407 -    context_t ctx;
  40.408 -    pdb_request_t req;
  40.409 -    uint32_t length = 0;
  40.410 -
  40.411 -    decode_context(&ctx, context);
  40.412 -
  40.413 -    req.operation = PDB_OPCODE_WR_MEM;
  40.414 -    req.process = ctx.process;
  40.415 -
  40.416 -    node = val_list;
  40.417 -    if ( Int_val(node) == 0 )       /* gdb functionalty test uses empty list */
  40.418 -    {
  40.419 -        req.u.wr_mem.address = Int32_val(address);
  40.420 -        req.u.wr_mem.length  = 0;
  40.421 -    }
  40.422 -    else
  40.423 -    {
  40.424 -        while ( Int_val(Field(node,1)) != 0 )
  40.425 -        {
  40.426 -            req.u.wr_mem.data[length++] = Int_val(Field(node, 0));
  40.427 -            node = Field(node,1);
  40.428 -        }
  40.429 -        req.u.wr_mem.data[length++] = Int_val(Field(node, 0));
  40.430 -        
  40.431 -        req.u.wr_mem.address = Int32_val(address);
  40.432 -        req.u.wr_mem.length  = length;
  40.433 -    }
  40.434 - 
  40.435 -    send_request(ctx.ring, ctx.evtchn, &req);
  40.436 -   
  40.437 -    CAMLreturn(Val_unit);
  40.438 -}
  40.439 -
  40.440 -
  40.441 -/*
  40.442 - * proc_continue_target : context_t -> unit
  40.443 - */
  40.444 -value
  40.445 -proc_continue_target (value context)
  40.446 -{
  40.447 -    CAMLparam1(context);
  40.448 -
  40.449 -    context_t ctx;
  40.450 -    pdb_request_t req;
  40.451 -
  40.452 -    decode_context(&ctx, context);
  40.453 -
  40.454 -    req.operation = PDB_OPCODE_CONTINUE;
  40.455 -    req.process = ctx.process;
  40.456 - 
  40.457 -    send_request(ctx.ring, ctx.evtchn, &req);
  40.458 -
  40.459 -    CAMLreturn(Val_unit);
  40.460 -}
  40.461 -
  40.462 -/*
  40.463 - * proc_step_target : context_t -> unit
  40.464 - */
  40.465 -value
  40.466 -proc_step_target (value context)
  40.467 -{
  40.468 -    CAMLparam1(context);
  40.469 -
  40.470 -    context_t ctx;
  40.471 -    pdb_request_t req;
  40.472 -
  40.473 -    decode_context(&ctx, context);
  40.474 -
  40.475 -    req.operation = PDB_OPCODE_STEP;
  40.476 -    req.process = ctx.process;
  40.477 - 
  40.478 -    send_request(ctx.ring, ctx.evtchn, &req);
  40.479 -
  40.480 -    CAMLreturn(Val_unit);
  40.481 -}
  40.482 -
  40.483 -
  40.484 -
  40.485 -/*
  40.486 - * proc_insert_memory_breakpoint : context_t -> int32 -> int -> unit
  40.487 - */
  40.488 -value
  40.489 -proc_insert_memory_breakpoint (value context, value address, value length)
  40.490 -{
  40.491 -    CAMLparam3(context, address, length);
  40.492 -
  40.493 -    context_t ctx;
  40.494 -    pdb_request_t req;
  40.495 -
  40.496 -    decode_context(&ctx, context);
  40.497 -
  40.498 -    req.operation = PDB_OPCODE_SET_BKPT;
  40.499 -    req.process = ctx.process;
  40.500 -    req.u.bkpt.address = (unsigned long) Int32_val(address);
  40.501 -    req.u.bkpt.length  =  Int_val(length);
  40.502 -
  40.503 -    send_request(ctx.ring, ctx.evtchn, &req);
  40.504 -
  40.505 -    CAMLreturn(Val_unit);
  40.506 -}
  40.507 -
  40.508 -/*
  40.509 - * proc_remove_memory_breakpoint : context_t -> int32 -> int -> unit
  40.510 - */
  40.511 -value
  40.512 -proc_remove_memory_breakpoint (value context, value address, value length)
  40.513 -{
  40.514 -    CAMLparam3(context, address, length);
  40.515 -
  40.516 -    context_t ctx;
  40.517 -    pdb_request_t req;
  40.518 -
  40.519 -    decode_context(&ctx, context);
  40.520 -
  40.521 -    req.operation = PDB_OPCODE_CLR_BKPT;
  40.522 -    req.process = ctx.process;
  40.523 -    req.u.bkpt.address = (unsigned long) Int32_val(address);
  40.524 -    req.u.bkpt.length  =  Int_val(length);
  40.525 -
  40.526 -    send_request(ctx.ring, ctx.evtchn, &req);
  40.527 -
  40.528 -    CAMLreturn(Val_unit);
  40.529 -}
  40.530 -
  40.531 -/*
  40.532 - * proc_insert_watchpoint : context_t -> bwcpoint_t -> int32 -> int -> unit
  40.533 - */
  40.534 -value
  40.535 -proc_insert_watchpoint (value context, value kind, value address, value length)
  40.536 -{
  40.537 -    CAMLparam3(context, address, length);
  40.538 -
  40.539 -    context_t ctx;
  40.540 -    pdb_request_t req;
  40.541 -
  40.542 -    decode_context(&ctx, context);
  40.543 -
  40.544 -    req.operation = PDB_OPCODE_SET_WATCHPT;
  40.545 -    req.process = ctx.process;
  40.546 -    req.u.watchpt.type    =  Int_val(kind);
  40.547 -    req.u.watchpt.address = (unsigned long) Int32_val(address);
  40.548 -    req.u.watchpt.length  =  Int_val(length);
  40.549 -
  40.550 -    send_request(ctx.ring, ctx.evtchn, &req);
  40.551 -
  40.552 -    CAMLreturn(Val_unit);
  40.553 -}
  40.554 -
  40.555 -/*
  40.556 - * proc_remove_watchpoint : context_t -> bwcpoint_t -> int32 -> int -> unit
  40.557 - */
  40.558 -value
  40.559 -proc_remove_watchpoint (value context, value kind, value address, value length)
  40.560 -{
  40.561 -    CAMLparam3(context, address, length);
  40.562 -
  40.563 -    context_t ctx;
  40.564 -    pdb_request_t req;
  40.565 -
  40.566 -    decode_context(&ctx, context);
  40.567 -
  40.568 -    req.operation = PDB_OPCODE_CLR_WATCHPT;
  40.569 -    req.process = ctx.process;
  40.570 -    req.u.watchpt.type    =  Int_val(kind);
  40.571 -    req.u.watchpt.address = (unsigned long) Int32_val(address);
  40.572 -    req.u.watchpt.length  =  Int_val(length);
  40.573 -
  40.574 -    send_request(ctx.ring, ctx.evtchn, &req);
  40.575 -
  40.576 -    CAMLreturn(Val_unit);
  40.577 -}
  40.578 -
  40.579 -
  40.580 -/*
  40.581 - * Local variables:
  40.582 - * mode: C
  40.583 - * c-set-style: "BSD"
  40.584 - * c-basic-offset: 4
  40.585 - * tab-width: 4
  40.586 - * indent-tabs-mode: nil
  40.587 - * End:
  40.588 - */
  40.589 -
  40.590 -
    41.1 --- a/tools/debugger/pdb/pdb_caml_xc.c	Sun Oct 01 11:39:41 2006 -0600
    41.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    41.3 @@ -1,170 +0,0 @@
    41.4 -/*
    41.5 - * pdb_caml_xc.c
    41.6 - *
    41.7 - * http://www.cl.cam.ac.uk/netos/pdb
    41.8 - *
    41.9 - * PDB's OCaml interface library for debugging domains
   41.10 - */
   41.11 -
   41.12 -#include <xenctrl.h>
   41.13 -#include <xendebug.h>
   41.14 -#include <errno.h>
   41.15 -#include <stdio.h>
   41.16 -#include <stdlib.h>
   41.17 -#include <string.h>
   41.18 -#include <sys/mman.h>
   41.19 -#include <caml/alloc.h>
   41.20 -#include <caml/fail.h>
   41.21 -#include <caml/memory.h>
   41.22 -#include <caml/mlvalues.h>
   41.23 -
   41.24 -#include "pdb_caml_xen.h"
   41.25 -
   41.26 -int xc_handle = -1;
   41.27 -
   41.28 -
   41.29 -/****************************************************************************/
   41.30 -
   41.31 -/*
   41.32 - * open_context : unit -> unit
   41.33 - */
   41.34 -value
   41.35 -open_context (value unit)
   41.36 -{
   41.37 -    CAMLparam1(unit);
   41.38 -
   41.39 -    xc_handle = xc_interface_open();
   41.40 -
   41.41 -    if ( xc_handle < 0 )
   41.42 -    {
   41.43 -        fprintf(stderr, "(pdb) error opening xc interface: %d (%s)\n",
   41.44 -                errno, strerror(errno));
   41.45 -    }
   41.46 -
   41.47 -    CAMLreturn(Val_unit);
   41.48 -}
   41.49 -
   41.50 -/*
   41.51 - * close_context : unit -> unit
   41.52 - */
   41.53 -value
   41.54 -close_context (value unit)
   41.55 -{
   41.56 -    CAMLparam1(unit);
   41.57 -    int rc;
   41.58 -    
   41.59 -    if ( (rc = xc_interface_close(xc_handle)) < 0 )
   41.60 -    {
   41.61 -        fprintf(stderr, "(pdb) error closing xc interface: %d (%s)\n",
   41.62 -                errno, strerror(errno));
   41.63 -    }
   41.64 -
   41.65 -    CAMLreturn(Val_unit);
   41.66 -}
   41.67 -
   41.68 -
   41.69 -/*********************************************************************/
   41.70 -
   41.71 -void
   41.72 -dump_regs (cpu_user_regs_t *regs)
   41.73 -{
   41.74 -    printf ("   eax: %x\n", regs->eax);
   41.75 -    printf ("   ecx: %x\n", regs->ecx);
   41.76 -    printf ("   edx: %x\n", regs->edx);
   41.77 -    printf ("   ebx: %x\n", regs->ebx);
   41.78 -    printf ("   esp: %x\n", regs->esp);
   41.79 -    printf ("   ebp: %x\n", regs->ebp);
   41.80 -    printf ("   esi: %x\n", regs->esi);
   41.81 -    printf ("   edi: %x\n", regs->edi);
   41.82 -    printf ("   eip: %x\n", regs->eip);
   41.83 -    printf (" flags: %x\n", regs->eflags);
   41.84 -    printf ("    cs: %x\n", regs->cs);
   41.85 -    printf ("    ss: %x\n", regs->ss);
   41.86 -    printf ("    es: %x\n", regs->es);
   41.87 -    printf ("    ds: %x\n", regs->ds);
   41.88 -    printf ("    fs: %x\n", regs->fs);
   41.89 -    printf ("    gs: %x\n", regs->gs);
   41.90 -
   41.91 -    return;
   41.92 -}
   41.93 -
   41.94 -/*
   41.95 - * debugger_status : unit -> unit
   41.96 - */
   41.97 -value
   41.98 -debugger_status (value unit)
   41.99 -{
  41.100 -    CAMLparam1(unit);
  41.101 -
  41.102 -    CAMLreturn(Val_unit);
  41.103 -}
  41.104 -
  41.105 -/****************************************************************************/
  41.106 -/****************************************************************************/
  41.107 -
  41.108 -/*
  41.109 - * evtchn_bind_virq : int -> int
  41.110 - */
  41.111 -value
  41.112 -evtchn_bind_virq (value virq)
  41.113 -{
  41.114 -    CAMLparam1(virq);
  41.115 -
  41.116 -    int port;
  41.117 -    int my_virq = Int_val(virq);
  41.118 -
  41.119 -    if ( xc_evtchn_bind_virq(xc_handle, my_virq, &port) < 0 )
  41.120 -    {
  41.121 -        printf("(pdb) evtchn_bind_virq error!\n");  fflush(stdout);
  41.122 -        failwith("evtchn_bind_virq error");
  41.123 -    }
  41.124 -
  41.125 -    CAMLreturn(Val_int(port));
  41.126 -}
  41.127 -
  41.128 -/*
  41.129 - * evtchn_bind_interdomain : int -> int * int
  41.130 - */
  41.131 -value
  41.132 -evtchn_bind_interdomain (value remote_domain)
  41.133 -{
  41.134 -    CAMLparam1(remote_domain);
  41.135 -    CAMLlocal1(result);
  41.136 -
  41.137 -    int my_remote_domain = Int_val(remote_domain);
  41.138 -    int local_domain = 0;
  41.139 -    int local_port = 0;
  41.140 -    int remote_port = 0;
  41.141 -
  41.142 -    if ( xc_evtchn_bind_interdomain(xc_handle, local_domain, my_remote_domain,
  41.143 -                                    &local_port, &remote_port) < 0 )
  41.144 -    {
  41.145 -        printf("(pdb) evtchn_bind_interdomain error!\n");  fflush(stdout);
  41.146 -        failwith("evtchn_bind_interdomain error");
  41.147 -    }
  41.148 -
  41.149 -    result = caml_alloc_tuple(2);                                   /* FIXME */
  41.150 -    Store_field(result, 0, Val_int(local_port));
  41.151 -    Store_field(result, 1, Val_int(remote_port));
  41.152 -
  41.153 -    CAMLreturn(result);
  41.154 -}
  41.155 -
  41.156 -void *
  41.157 -map_ring(uint32_t dom, unsigned long mfn )
  41.158 -{
  41.159 -    return xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
  41.160 -                                PROT_READ | PROT_WRITE, mfn);
  41.161 -}
  41.162 -
  41.163 -
  41.164 -/*
  41.165 - * Local variables:
  41.166 - * mode: C
  41.167 - * c-set-style: "BSD"
  41.168 - * c-basic-offset: 4
  41.169 - * tab-width: 4
  41.170 - * indent-tabs-mode: nil
  41.171 - * End:
  41.172 - */
  41.173 -
    42.1 --- a/tools/debugger/pdb/pdb_caml_xcs.c	Sun Oct 01 11:39:41 2006 -0600
    42.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    42.3 @@ -1,307 +0,0 @@
    42.4 -/*
    42.5 - * xcs stuff
    42.6 - *
    42.7 - * http://www.cl.cam.ac.uk/netos/pdb
    42.8 - *
    42.9 - * this is responsible for establishing the initial connection
   42.10 - * between a backend domain and the pdb server.
   42.11 - *
   42.12 - * liberated from xu.c
   42.13 - *
   42.14 - */
   42.15 -
   42.16 -#include <stdio.h>
   42.17 -#include <stdlib.h>
   42.18 -#include <unistd.h>
   42.19 -#include <sys/un.h>
   42.20 -#include <sys/types.h>
   42.21 -#include <sys/socket.h>
   42.22 -#include <errno.h>
   42.23 -#include <xenctrl.h>
   42.24 -
   42.25 -#include <xen/xen.h>
   42.26 -#include <xen/io/domain_controller.h>
   42.27 -
   42.28 -#include <arpa/inet.h>
   42.29 -#include <xcs_proto.h>
   42.30 -
   42.31 -#include <caml/alloc.h>
   42.32 -#include <caml/fail.h>
   42.33 -#include <caml/memory.h>
   42.34 -#include <caml/mlvalues.h>
   42.35 -
   42.36 -static int control_fd = -1;
   42.37 -
   42.38 -#include "pdb_module.h"
   42.39 -#include "pdb_caml_xen.h"
   42.40 -
   42.41 -void *map_ring(uint32_t dom, unsigned long mfn );
   42.42 -
   42.43 -/*
   42.44 - * xcs_initialize_ring : int -> int32 -> int32
   42.45 - *
   42.46 - * initialize a communications ring
   42.47 - * (probably belongs in a different file :)
   42.48 - */
   42.49 -
   42.50 -value
   42.51 -xcs_initialize_ring (value domain, value ring)
   42.52 -{
   42.53 -    CAMLparam2(domain, ring);
   42.54 -    int my_domain = Int_val(domain);
   42.55 -    unsigned long my_ring = Int32_val(ring);
   42.56 -
   42.57 -    pdb_front_ring_t *front_ring;
   42.58 -    pdb_sring_t *sring;
   42.59 -
   42.60 -    front_ring = (pdb_front_ring_t *)malloc(sizeof(pdb_front_ring_t));
   42.61 -    if ( front_ring == NULL )
   42.62 -    {
   42.63 -        printf("(pdb) xcs initialize ring: malloc failed.\n");  fflush(stdout);
   42.64 -        failwith("xcs initialize ring: malloc");
   42.65 -    }
   42.66 -
   42.67 -    sring = map_ring(my_domain, my_ring);
   42.68 -    if ( sring == NULL )
   42.69 -    {
   42.70 -        printf("(pdb) xcs initialize ring: map ring failed.\n");fflush(stdout);
   42.71 -        failwith("xcs initialize ring: map ring");
   42.72 -    }
   42.73 -    FRONT_RING_INIT(front_ring, sring, PAGE_SIZE);
   42.74 -
   42.75 -    CAMLreturn(caml_copy_int32((unsigned long)front_ring));
   42.76 -}
   42.77 -
   42.78 -
   42.79 -/*
   42.80 - * xcs_write_message : Unix.file_descr -> xcs_message -> unit
   42.81 - *
   42.82 - * ack a packet
   42.83 - */
   42.84 -value
   42.85 -xcs_write_message (value data_fd, value msg)
   42.86 -{
   42.87 -    CAMLparam2(data_fd, msg);
   42.88 -    int my_data_fd = Int_val(data_fd);
   42.89 -    xcs_msg_t my_msg;
   42.90 -    pdb_connection_p conn;
   42.91 -
   42.92 -    my_msg.type = XCS_REQUEST;
   42.93 -    my_msg.u.control.remote_dom = Int_val(Field(msg,0));
   42.94 -    my_msg.u.control.msg.type = CMSG_DEBUG;
   42.95 -    my_msg.u.control.msg.subtype = CMSG_DEBUG_CONNECTION_STATUS;
   42.96 -    my_msg.u.control.msg.id = 0;
   42.97 -    my_msg.u.control.msg.length = sizeof(pdb_connection_t);
   42.98 -
   42.99 -    conn = (pdb_connection_p)my_msg.u.control.msg.msg;
  42.100 -
  42.101 -    conn->status = Int_val(Field(msg,1));
  42.102 -    conn->ring = Int32_val(Field(msg,2));
  42.103 -    conn->evtchn = Int_val(Field(msg,3));
  42.104 -        
  42.105 -    send(my_data_fd, &my_msg, sizeof(xcs_msg_t), 0);                  /* ack */
  42.106 -
  42.107 -    CAMLreturn(Val_unit);
  42.108 -}
  42.109 -
  42.110 -/*
  42.111 - * xcs_read_message : Unix.file_descr -> xcs_message
  42.112 - *
  42.113 - * read pending data on xcs socket.
  42.114 - */
  42.115 -
  42.116 -value
  42.117 -xcs_read_message (value data_fd)
  42.118 -{
  42.119 -    CAMLparam1(data_fd);
  42.120 -    CAMLlocal1(result);
  42.121 -    int my_data_fd = Int_val(data_fd);
  42.122 -    xcs_msg_t msg;
  42.123 -
  42.124 -    if ( read(my_data_fd, &msg, sizeof(xcs_msg_t)) < 0 )
  42.125 -    {
  42.126 -        perror("read");
  42.127 -        failwith("xcs message: read");
  42.128 -    }
  42.129 -
  42.130 -    switch (msg.type)
  42.131 -    {
  42.132 -    case XCS_REQUEST :
  42.133 -    {
  42.134 -        pdb_connection_p conn;
  42.135 -
  42.136 -        if ( msg.u.control.msg.type != CMSG_DEBUG ||
  42.137 -             msg.u.control.msg.subtype != CMSG_DEBUG_CONNECTION_STATUS )
  42.138 -        {
  42.139 -            printf("bogus message type: %d %d\n", 
  42.140 -                   msg.u.control.msg.type, msg.u.control.msg.subtype);
  42.141 -            failwith("xcs message: invalid message type");
  42.142 -        }
  42.143 -
  42.144 -        conn = (pdb_connection_p) msg.u.control.msg.msg;
  42.145 -        
  42.146 -        result = caml_alloc_tuple(4);                               /* FIXME */
  42.147 -        Store_field(result, 0, Val_int(msg.u.control.remote_dom)); /* domain */
  42.148 -        Store_field(result, 1, Val_int(conn->status));             /* status */
  42.149 -        Store_field(result, 2, caml_copy_int32(conn->ring));         /* ring */
  42.150 -        Store_field(result, 3, Val_int(0));                   /* OUT: evtchn */
  42.151 -
  42.152 -        break;
  42.153 -    }
  42.154 -    case XCS_RESPONSE :
  42.155 -    {
  42.156 -        printf("[XCS RESPONSE]  type: %d, remote_dom: %d\n", 
  42.157 -               msg.type, msg.u.control.remote_dom);
  42.158 -        printf("strange.  we never initiate messages, so what is the ");
  42.159 -        printf("domain responding to?\n");
  42.160 -        failwith ("xcs message: resonse");
  42.161 -        break;
  42.162 -    }
  42.163 -    default:
  42.164 -    {
  42.165 -        printf("[XCS IGNORE] type: %d\n", msg.type);
  42.166 -        failwith ("xcs message: unknown");
  42.167 -        break;
  42.168 -    }
  42.169 -    }
  42.170 -
  42.171 -    CAMLreturn(result);
  42.172 -}
  42.173 -
  42.174 -/*
  42.175 - * xcs_connect : string -> int -> Unix.file_descr
  42.176 - */
  42.177 -
  42.178 -value
  42.179 -xcs_connect (value path, value msg_type)
  42.180 -{
  42.181 -    CAMLparam2(path, msg_type);
  42.182 -    char *my_path = String_val(path);
  42.183 -    int my_msg_type = Int_val(msg_type);
  42.184 -    struct sockaddr_un addr;
  42.185 -    uint32_t session_id = 0;
  42.186 -    int data_fd;
  42.187 -    int ret, len;
  42.188 -    xcs_msg_t msg;
  42.189 -
  42.190 -    /* setup control channel connection to xcs */
  42.191 -
  42.192 -    control_fd = socket(AF_UNIX, SOCK_STREAM, 0);
  42.193 -    if ( control_fd < 0 )
  42.194 -    {
  42.195 -        printf("error creating xcs socket!\n");
  42.196 -        goto fail;
  42.197 -    }
  42.198 -
  42.199 -    addr.sun_family = AF_UNIX;
  42.200 -    strcpy(addr.sun_path, my_path);
  42.201 -    len = sizeof(addr.sun_family) + strlen(addr.sun_path) + 1;
  42.202 -
  42.203 -    ret = connect(control_fd, (struct sockaddr *)&addr, len);
  42.204 -    if (ret < 0) 
  42.205 -    {
  42.206 -        printf("error connecting to xcs (ctrl)! (%d)\n", errno);
  42.207 -        goto ctrl_fd_fail;
  42.208 -    }
  42.209 -            
  42.210 -    msg.type = XCS_CONNECT_CTRL;
  42.211 -    msg.u.connect.session_id = session_id;
  42.212 -    send(control_fd, &msg, sizeof(xcs_msg_t), 0);
  42.213 -    /* bug: this should have a timeout & error! */
  42.214 -    read(control_fd, &msg, sizeof(xcs_msg_t));
  42.215 -    
  42.216 -    if (msg.result != XCS_RSLT_OK)
  42.217 -    {
  42.218 -        printf("error connecting xcs control channel!\n");
  42.219 -        goto ctrl_fd_fail;
  42.220 -    }
  42.221 -    session_id = msg.u.connect.session_id;
  42.222 -
  42.223 -
  42.224 -    /* setup data channel connection to xcs */
  42.225 -    
  42.226 -    data_fd = socket(AF_UNIX, SOCK_STREAM, 0);
  42.227 -    if ( data_fd < 0 )
  42.228 -    {
  42.229 -        printf("error creating xcs data socket!\n");
  42.230 -        goto ctrl_fd_fail;
  42.231 -    }
  42.232 -    
  42.233 -    addr.sun_family = AF_UNIX;
  42.234 -    strcpy(addr.sun_path, my_path);
  42.235 -    len = sizeof(addr.sun_family) + strlen(addr.sun_path) + 1;
  42.236 -    
  42.237 -    ret = connect(data_fd, (struct sockaddr *)&addr, len);
  42.238 -    if (ret < 0) 
  42.239 -    {
  42.240 -        printf("error connecting to xcs (data)! (%d)\n", errno);
  42.241 -        goto data_fd_fail;
  42.242 -    }
  42.243 -
  42.244 -    msg.type = XCS_CONNECT_DATA;
  42.245 -    msg.u.connect.session_id = session_id;
  42.246 -    send(data_fd, &msg, sizeof(xcs_msg_t), 0);
  42.247 -    read(data_fd, &msg, sizeof(xcs_msg_t));                      /* same bug */
  42.248 -    
  42.249 -    if ( msg.result != XCS_RSLT_OK )
  42.250 -    {
  42.251 -        printf("error connecting xcs control channel!\n");
  42.252 -        goto ctrl_fd_fail;
  42.253 -    }
  42.254 -
  42.255 -
  42.256 -
  42.257 -    /* now request all messages of a particular type */
  42.258 -
  42.259 -    msg.type = XCS_MSG_BIND;
  42.260 -    msg.u.bind.port = PORT_WILDCARD;
  42.261 -    msg.u.bind.type = my_msg_type;
  42.262 -    send(control_fd, &msg, sizeof(xcs_msg_t), 0);
  42.263 -    read(control_fd, &msg, sizeof(xcs_msg_t));                /* still buggy */
  42.264 -
  42.265 -    if (msg.result != XCS_RSLT_OK) {
  42.266 -        printf ("error: MSG BIND\n");
  42.267 -	goto bind_fail;
  42.268 -    }
  42.269 -
  42.270 -    CAMLreturn(Val_int(data_fd));
  42.271 -
  42.272 -bind_fail:
  42.273 -data_fd_fail: 
  42.274 -    close(data_fd);  
  42.275 -    
  42.276 -ctrl_fd_fail:
  42.277 -    close(control_fd);
  42.278 -     
  42.279 -fail:
  42.280 -    failwith("xcs connection error");             /* should be more explicit */
  42.281 -}
  42.282 -
  42.283 -
  42.284 -/* xcs_disconnect: Unix.file_descr -> unit */
  42.285 -
  42.286 -value
  42.287 -xcs_disconnect (value data_fd)
  42.288 -{
  42.289 -    CAMLparam1(data_fd);
  42.290 -
  42.291 -    int my_data_fd = Int_val(data_fd);
  42.292 -
  42.293 -    close(my_data_fd);
  42.294 -    close(control_fd);
  42.295 -    control_fd = -1;
  42.296 -
  42.297 -    CAMLreturn(Val_unit);
  42.298 -}
  42.299 -
  42.300 -
  42.301 -/*
  42.302 - * Local variables:
  42.303 - * mode: C
  42.304 - * c-set-style: "BSD"
  42.305 - * c-basic-offset: 4
  42.306 - * tab-width: 4
  42.307 - * indent-tabs-mode: nil
  42.308 - * End:
  42.309 - */
  42.310 -
    43.1 --- a/tools/debugger/pdb/pdb_caml_xen.h	Sun Oct 01 11:39:41 2006 -0600
    43.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    43.3 @@ -1,39 +0,0 @@
    43.4 -/*
    43.5 - * pdb_caml_xen.h
    43.6 - *
    43.7 - * http://www.cl.cam.ac.uk/netos/pdb
    43.8 - *
    43.9 - * generic xen definitions
   43.10 - *
   43.11 - */
   43.12 -
   43.13 -#ifndef _PDB_CAML_XEN_DEFINED_
   43.14 -#define _PDB_CAML_XEN_DEFINED_
   43.15 -
   43.16 -enum gdb_registers { /* 32 */ GDB_EAX, GDB_ECX, GDB_EDX, GDB_EBX,
   43.17 -                              GDB_ESP, GDB_EBP, GDB_ESI, GDB_EDI,
   43.18 -                              GDB_EIP, GDB_EFL, 
   43.19 -                     /* 16 */ GDB_CS,  GDB_SS,  GDB_DS,  GDB_ES,
   43.20 -                              GDB_FS,  GDB_GS };
   43.21 -#define GDB_REGISTER_FRAME_SIZE 16
   43.22 -
   43.23 -/* this order comes from linux-2.6.11/include/asm-i386/ptrace.h */
   43.24 -enum x86_registers { LINUX_EBX, LINUX_ECX, LINUX_EDX, LINUX_ESI, LINUX_EDI,
   43.25 -                     LINUX_EBP, LINUX_EAX, LINUX_DS,  LINUX_ES,  LINUX_FS,
   43.26 -                     LINUX_GS,  LINUX_ORIG_EAX, LINUX_EIP, LINUX_CS, LINUX_EFL,
   43.27 -                     LINUX_ESP, LINUX_SS };
   43.28 -#define REGISTER_FRAME_SIZE 17
   43.29 -
   43.30 -
   43.31 -/* hack: this is also included from the pdb linux module which
   43.32 -   has PAGE_SIZE defined */
   43.33 -#ifndef PAGE_SIZE
   43.34 -#define PAGE_SIZE 4096
   43.35 -#endif
   43.36 -
   43.37 -extern int xc_handle;
   43.38 -
   43.39 -void dump_regs (cpu_user_regs_t *ctx);
   43.40 -
   43.41 -#endif
   43.42 -
    44.1 --- a/tools/debugger/pdb/pdb_xen.c	Sun Oct 01 11:39:41 2006 -0600
    44.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    44.3 @@ -1,75 +0,0 @@
    44.4 -/*
    44.5 - * pdb_xen.c
    44.6 - *
    44.7 - * alex ho
    44.8 - * http://www.cl.cam.ac.uk/netos/pdb
    44.9 - *
   44.10 - * PDB interface library for accessing Xen
   44.11 - */
   44.12 -
   44.13 -#include <xenctrl.h>
   44.14 -#include <stdio.h>
   44.15 -#include <stdlib.h>
   44.16 -#include <errno.h>
   44.17 -#include <string.h>
   44.18 -#include <sys/mman.h>
   44.19 -
   44.20 -int
   44.21 -pdb_open ()
   44.22 -{
   44.23 -    int xc_handle = xc_interface_open();
   44.24 -
   44.25 -    if ( xc_handle < 0 )
   44.26 -    {
   44.27 -        fprintf(stderr, "(pdb) error opening xc interface: %d (%s)\n",
   44.28 -                errno, strerror(errno));
   44.29 -    }
   44.30 -    return xc_handle;
   44.31 -}
   44.32 -
   44.33 -int 
   44.34 -pdb_close (int xc_handle)
   44.35 -{
   44.36 -    int rc;
   44.37 -
   44.38 -    
   44.39 -    if ( (rc = xc_interface_close(xc_handle)) < 0 )
   44.40 -    {
   44.41 -        fprintf(stderr, "(pdb) error closing xc interface: %d (%s)\n",
   44.42 -                errno, strerror(errno));
   44.43 -    }
   44.44 -    return rc;
   44.45 -}
   44.46 -
   44.47 -
   44.48 -#include <sys/ioctl.h>
   44.49 -#include <xen/linux/evtchn.h>
   44.50 -
   44.51 -int
   44.52 -xen_evtchn_bind (int evtchn_fd, int idx)
   44.53 -{
   44.54 -    if ( ioctl(evtchn_fd, EVTCHN_BIND, idx) != 0 )
   44.55 -        return -errno;
   44.56 -    
   44.57 -    return 0;
   44.58 -}
   44.59 -
   44.60 -int 
   44.61 -xen_evtchn_unbind (int evtchn_fd, int idx)
   44.62 -{
   44.63 -    if ( ioctl(evtchn_fd, EVTCHN_UNBIND, idx) != 0 )
   44.64 -        return -errno;
   44.65 -
   44.66 -    return 0;
   44.67 -}
   44.68 -
   44.69 -
   44.70 -/*
   44.71 - * Local variables:
   44.72 - * mode: C
   44.73 - * c-set-style: "BSD"
   44.74 - * c-basic-offset: 4
   44.75 - * tab-width: 4
   44.76 - * indent-tabs-mode: nil
   44.77 - * End:
   44.78 - */
    45.1 --- a/tools/debugger/pdb/readme	Sun Oct 01 11:39:41 2006 -0600
    45.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    45.3 @@ -1,105 +0,0 @@
    45.4 -
    45.5 -PDB 0.3.3
    45.6 -http://www.cl.cam.ac.uk/netos/pdb
    45.7 -
    45.8 -Alex Ho  
    45.9 -August 2005
   45.10 -
   45.11 -
   45.12 -This is the latest incarnation of the pervasive debugger.
   45.13 -PDB is a remote stub for GDB.  Running as a user-space
   45.14 -application in domain 0, it can debug any other domain.
   45.15 -
   45.16 -
   45.17 -+------+    tcp/ip    +-------+  
   45.18 -| GDB  |--------------|  PDB  |
   45.19 -+------+              +-------+   +-------+
   45.20 -                      | Dom 0 |   | Dom U |
   45.21 -                      +-------+---+-------+
   45.22 -                      |  Xen              |
   45.23 -                      +-------------------+
   45.24 -
   45.25 -Installation
   45.26 -
   45.27 -- Install OCaml 3.08 in domain 0.
   45.28 -  http://caml.inria.fr/download.en.html  is a good place to start.
   45.29 -
   45.30 -- Build Xen with debugger support
   45.31 -  make domu_debug=y xen
   45.32 -
   45.33 -- (optional)
   45.34 -  Build the target domains with debugging symbols.
   45.35 -  make CONFIG_DEBUG_INFO=true CONFIG_FRAME_POINTER=false linux-2.6-xenU-build
   45.36 -
   45.37 -  You can also change linux-2.6.12-xenU/Makefile
   45.38 -  CONFIG_CC_OPTIMIZE_FOR_SIZE from -O2 to -O
   45.39 -
   45.40 -- Build PDB
   45.41 -  (cd tools/debugger/libxendebug; make install)
   45.42 -  (cd tools/debugger/pdb; make)
   45.43 -
   45.44 -Usage
   45.45 -
   45.46 -- PDB does not currently support SMP.  Please boot xen with "maxcpus=1"
   45.47 -
   45.48 -- Run PDB
   45.49 -  domain-0.xeno# ./pdb <port>
   45.50 -
   45.51 -- Run GDB
   45.52 -  hostname% gdb <xeno.bk>/dist/install/boot/vmlinux-syms-2.6.12-xenU
   45.53 -
   45.54 -  (gdb) target remote domain-0.xeno:<port>
   45.55 -
   45.56 -  At this point, you'll get an error message such as:
   45.57 -  Remote debugging using domain-0.xeno:5000
   45.58 -  0x00000000 in ?? ()
   45.59 -  warning: shared library handler failed to enable breakpoint
   45.60 -  Although GDB is connected to PDB, PDB doesn't know which domain
   45.61 -  you'd like to debug, so it's just feeding GDB a bunch of zeros.
   45.62 -
   45.63 -  (gdb) maint packet x context = domain <domid> <vcpu>
   45.64 -
   45.65 -  This tells PDB that we'd like to debug a particular domain & vcpu.
   45.66 -  However, since we're sending the command directly to PDB, GDB doesn't 
   45.67 -  know that we now have a proper target.  We can force GDB to invalidate
   45.68 -  its register cache.  This is optional; the next time the program
   45.69 -  stops GDB will query for the registers automatically.
   45.70 -
   45.71 -  (gdb) flushreg
   45.72 -
   45.73 -  
   45.74 -  the following gdb commands should work :)
   45.75 -
   45.76 -  break
   45.77 -  step,   stepi
   45.78 -  next,   nexti
   45.79 -  continue
   45.80 -  print
   45.81 -
   45.82 -Process
   45.83 -
   45.84 -  PDB can also debug a process running in a Linux 2.6 domain. 
   45.85 -  You will need to patch the Linux 2.6 domain U tree to export some
   45.86 -  additional symbols for the pdb module
   45.87 -
   45.88 -  % make -C linux-2.6-patches
   45.89 -
   45.90 -  After running PDB in domain 0, insert the pdb module in dom u:
   45.91 -  
   45.92 -  % insmod linux-2.6-module/pdb.ko
   45.93 -
   45.94 -  Load GDB with the appropriate symbols, and attach with
   45.95 -
   45.96 -  (gdb) maint packet x context = process <domid> <pid>
   45.97 -
   45.98 -  Read, write, and access watchpoint should also work for processes, 
   45.99 -  use the "rwatch", "watch" and "awatch" gdb commands respectively.
  45.100 -
  45.101 -  If you are having trouble with GDB 5.3 (i386-redhat-linux-gnu),
  45.102 -  try GDB 6.3 (configured with --target=i386-linux-gnu).
  45.103 -
  45.104 -  
  45.105 -To Do
  45.106 -
  45.107 -- watchpoints for domains
  45.108 -- support for SMP
    46.1 --- a/tools/debugger/pdb/server.ml	Sun Oct 01 11:39:41 2006 -0600
    46.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    46.3 @@ -1,241 +0,0 @@
    46.4 -(** server.ml
    46.5 - *
    46.6 - *  PDB server main loop
    46.7 - *
    46.8 - *  @author copyright (c) 2005 alex ho
    46.9 - *  @see <www.cl.cam.ac.uk/netos/pdb> pervasive debugger
   46.10 - *  @version 1
   46.11 - *)
   46.12 -
   46.13 -open Unix
   46.14 -open Buffer
   46.15 -open Util
   46.16 -
   46.17 -(**
   46.18 - * connection_t: The state for each connection.
   46.19 - * buffer & length contains bytes that have been read from the sock
   46.20 - * but not yet parsed / processed.
   46.21 - *)
   46.22 -type connection_t =
   46.23 -{ 
   46.24 -          fd : file_descr;
   46.25 -  mutable buffer : string;
   46.26 -  mutable length : int;
   46.27 -}
   46.28 -
   46.29 -
   46.30 -(**
   46.31 - * validate_checksum:  Compute and compare the checksum of a string
   46.32 - * against the provided checksum using the gdb serial protocol algorithm.
   46.33 - *
   46.34 - *)
   46.35 -let validate_checksum command checksum =
   46.36 -  let c0 = ref 0 in
   46.37 -  for loop = 0 to (String.length command - 1) do
   46.38 -    c0 := !c0 + int_of_char(command.[loop]);
   46.39 -  done;
   46.40 -  if (String.length checksum) = 2 
   46.41 -  then
   46.42 -    let c1 = Util.int_of_hexchar(checksum.[1]) +
   46.43 -	     Util.int_of_hexchar(checksum.[0]) * 16 in
   46.44 -    (!c0 mod 256) = (c1 mod 256)
   46.45 -  else
   46.46 -    false
   46.47 -  
   46.48 -
   46.49 -(**
   46.50 - * process_input: Oh, joy!  Someone sent us a message.  Let's open the
   46.51 - * envelope and see what they have to say.
   46.52 - *
   46.53 - * This function is a paradigm of inefficiency; it performs as many 
   46.54 - * string copies as possible.
   46.55 - *)
   46.56 -let process_input conn sock = 
   46.57 -  let max_buffer_size = 1024 in
   46.58 -  let in_string = String.create max_buffer_size in
   46.59 -
   46.60 -  let length = read sock in_string 0 max_buffer_size in
   46.61 -  conn.buffer <- conn.buffer ^ (String.sub in_string 0 length);
   46.62 -  conn.length <- conn.length + length;
   46.63 -  let re = Str.regexp "[^\\$]*\\$\\([^#]*\\)#\\(..\\)" in
   46.64 -
   46.65 -  (* interrupt the target if there was a ctrl-c *)
   46.66 -  begin
   46.67 -    try
   46.68 -      let break = String.index conn.buffer '\003' + 1 in
   46.69 -      print_endline (Printf.sprintf "{{%s}}" (String.escaped conn.buffer));
   46.70 -
   46.71 -      (* discard everything seen before the ctrl-c *)
   46.72 -      conn.buffer <- String.sub conn.buffer break (conn.length - break);
   46.73 -      conn.length <- conn.length - break;
   46.74 -
   46.75 -      (* pause the target *)
   46.76 -      PDB.pause (PDB.find_context sock);
   46.77 -
   46.78 -      (* send a code back to the debugger *)
   46.79 -      Util.send_reply sock "S05"
   46.80 -
   46.81 -    with
   46.82 -      Not_found -> ()
   46.83 -  end;
   46.84 -
   46.85 -  (* with gdb this is unlikely to loop since you ack each packet *)
   46.86 -  while ( Str.string_match re conn.buffer 0 ) do
   46.87 -    let command = Str.matched_group 1 conn.buffer in
   46.88 -    let checksum = Str.matched_group 2 conn.buffer in
   46.89 -    let match_end = Str.group_end 2 in
   46.90 -
   46.91 -    begin
   46.92 -      match validate_checksum command checksum with
   46.93 -      | true -> 
   46.94 -	  begin
   46.95 -	    Util.write_character sock '+';
   46.96 -	    try
   46.97 -	      let reply = Debugger.process_command command sock in
   46.98 -	      print_endline (Printf.sprintf "[%s] %s -> \"%s\"" 
   46.99 -			       (Util.get_connection_info sock)
  46.100 -			       (String.escaped command) 
  46.101 -			       (String.escaped reply));
  46.102 -	      Util.send_reply sock reply
  46.103 -	    with
  46.104 -	      Util.No_reply ->
  46.105 -		print_endline (Printf.sprintf "[%s] %s -> null" 
  46.106 -				 (Util.get_connection_info sock)
  46.107 -				 (String.escaped command))
  46.108 -	  end
  46.109 -      | false ->
  46.110 -	  Util.write_character sock '-';
  46.111 -    end;
  46.112 -
  46.113 -    conn.buffer <- String.sub conn.buffer match_end (conn.length - match_end);
  46.114 -    conn.length <- conn.length - match_end;
  46.115 -  done;
  46.116 -  if length = 0 then raise End_of_file
  46.117 -
  46.118 -
  46.119 -
  46.120 -(** main_server_loop.
  46.121 - *
  46.122 - *  connection_hash is a hash (duh!) with one connection_t for each
  46.123 - *  open connection.
  46.124 - * 
  46.125 - *  in_list is a list of active sockets.  it also contains a number
  46.126 - *  of magic entries: 
  46.127 - *  - server_sock   for accepting new client connections (e.g. gdb)
  46.128 - *  - xen_virq_sock for Xen virq asynchronous notifications (via evtchn).
  46.129 - *                  This is used by context = domain
  46.130 - *  - xcs_sock      for xcs messages when a new backend domain registers
  46.131 - *                  This is used by context = process
  46.132 - *)
  46.133 -let main_server_loop sockaddr =
  46.134 -  let connection_hash = Hashtbl.create 10
  46.135 -  in
  46.136 -  let process_socket svr_sock sockets sock =
  46.137 -    let (new_list, closed_list) = sockets in
  46.138 -    if sock == svr_sock
  46.139 -    then
  46.140 -      begin
  46.141 -	let (new_sock, caller) = accept sock in
  46.142 -	print_endline (Printf.sprintf "[%s] new connection from %s"
  46.143 -			              (Util.get_connection_info sock)
  46.144 -			              (Util.get_connection_info new_sock));
  46.145 -	Hashtbl.add connection_hash new_sock 
  46.146 -	            {fd=new_sock; buffer=""; length = 0};
  46.147 -	PDB.add_default_context new_sock;
  46.148 -	(new_sock :: new_list, closed_list)
  46.149 -      end
  46.150 -    else
  46.151 -      begin
  46.152 -	try
  46.153 -	  match PDB.find_context sock with
  46.154 -	  | PDB.Xen_virq ->
  46.155 -	      print_endline (Printf.sprintf "[%s] Xen virq"
  46.156 -			                    (Util.get_connection_info sock));
  46.157 -	      Debugger.process_xen_virq sock;
  46.158 -	      (new_list, closed_list)
  46.159 -	  | PDB.Xen_xcs ->
  46.160 -	      print_endline (Printf.sprintf "[%s] Xen xcs"
  46.161 -			                    (Util.get_connection_info sock));
  46.162 -	      let new_xen_domain = Debugger.process_xen_xcs sock in
  46.163 -	      (new_xen_domain :: new_list, closed_list)
  46.164 -	  | PDB.Xen_domain d ->
  46.165 -	      print_endline (Printf.sprintf "[%s] Xen domain"
  46.166 -			                    (Util.get_connection_info sock));
  46.167 -	      Debugger.process_xen_domain sock;
  46.168 -	      (new_list, closed_list)
  46.169 -	  | _ ->
  46.170 -	      let conn = Hashtbl.find connection_hash sock in
  46.171 -	      process_input conn sock;
  46.172 -	      (new_list, closed_list)
  46.173 -	with
  46.174 -	| Not_found -> 
  46.175 -	    print_endline "error: (main_svr_loop) context not found";
  46.176 -	    PDB.debug_contexts ();
  46.177 -	    raise Not_found
  46.178 -	| End_of_file -> 
  46.179 -	    print_endline (Printf.sprintf "[%s] close connection from %s"
  46.180 -  			                   (Util.get_connection_info sock)
  46.181 -			                   (Util.get_connection_info sock));
  46.182 -	    PDB.delete_context sock;
  46.183 -	    Hashtbl.remove connection_hash sock;
  46.184 -	    close sock;
  46.185 -	    (new_list, sock :: closed_list)
  46.186 -      end
  46.187 -  in
  46.188 -
  46.189 -  let rec helper in_list server_sock =
  46.190 -
  46.191 -    (*    
  46.192 -     List.iter (fun x->Printf.printf " {%s}\n" 
  46.193 -                                    (Util.get_connection_info x)) in_list;   
  46.194 -     Printf.printf "\n";
  46.195 -    *)
  46.196 -
  46.197 -    let (rd_list, _, _) = select in_list [] [] (-1.0) in 
  46.198 -    let (new_list, closed_list) = List.fold_left (process_socket server_sock)
  46.199 -	                                         ([],[]) rd_list  in
  46.200 -    let merge_list = Util.list_remove (new_list @ in_list) closed_list  in
  46.201 -    helper merge_list server_sock
  46.202 -  in
  46.203 -
  46.204 -  try
  46.205 -    let server_sock = socket (domain_of_sockaddr sockaddr) SOCK_STREAM 0 in
  46.206 -    setsockopt server_sock SO_REUSEADDR true;
  46.207 -    bind server_sock sockaddr;
  46.208 -    listen server_sock 2;
  46.209 -
  46.210 -    PDB.open_debugger ();
  46.211 -    let xen_virq_sock = Evtchn.setup () in
  46.212 -    PDB.add_context xen_virq_sock "xen virq" [];
  46.213 -
  46.214 -    let xcs_sock = Xcs.setup () in
  46.215 -    PDB.add_context xcs_sock "xen xcs" [];
  46.216 -    helper [server_sock; xen_virq_sock; xcs_sock] server_sock
  46.217 -  with
  46.218 -  | Sys.Break ->
  46.219 -      print_endline "break: cleaning up";
  46.220 -      PDB.close_debugger ();
  46.221 -      Hashtbl.iter (fun sock conn -> close sock) connection_hash
  46.222 -(*  | Unix_error(e,err,param) -> 
  46.223 -      Printf.printf "unix error: [%s][%s][%s]\n" (error_message e) err param*)
  46.224 -  | Sys_error s -> Printf.printf "sys error: [%s]\n" s
  46.225 -  | Failure s -> Printf.printf "failure: [%s]\n" s
  46.226 -  | End_of_file -> Printf.printf "end of file\n"
  46.227 -
  46.228 -
  46.229 -let get_port () =
  46.230 -  if (Array.length Sys.argv) = 2 
  46.231 -  then
  46.232 -    int_of_string Sys.argv.(1)
  46.233 -  else
  46.234 -    begin
  46.235 -      print_endline (Printf.sprintf "error: %s <port>" Sys.argv.(0));
  46.236 -      exit 1
  46.237 -    end
  46.238 -
  46.239 -
  46.240 -let main =
  46.241 -  let address = inet_addr_any in
  46.242 -  let port = get_port () in
  46.243 -  main_server_loop (ADDR_INET(address, port))
  46.244 -
    47.1 --- a/tools/debugger/pdb/xcs.ml	Sun Oct 01 11:39:41 2006 -0600
    47.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    47.3 @@ -1,85 +0,0 @@
    47.4 -(** xcs.ml
    47.5 - *
    47.6 - *  xen control switch interface
    47.7 - *
    47.8 - *  @author copyright (c) 2005 alex ho
    47.9 - *  @see <www.cl.cam.ac.uk/netos/pdb> pervasive debugger
   47.10 - *  @version 1
   47.11 - *)
   47.12 -
   47.13 -open Int32
   47.14 -
   47.15 -let xcs_path = "/var/lib/xen/xcs_socket"                    (* XCS_SUN_PATH *)
   47.16 -let xcs_type = 11                                             (* CMSG_DEBUG *)
   47.17 -
   47.18 -
   47.19 -type xcs_message =
   47.20 -    {
   47.21 -              domain  : int;
   47.22 -              status  : int;
   47.23 -              ring    : int32;
   47.24 -      mutable evtchn  : int;
   47.25 -    }
   47.26 -
   47.27 -external connect : string -> int -> Unix.file_descr = "xcs_connect"
   47.28 -external disconnect : Unix.file_descr -> unit = "xcs_disconnect"
   47.29 -external read_message : Unix.file_descr -> xcs_message = "xcs_read_message"
   47.30 -external write_message : Unix.file_descr -> xcs_message -> unit = 
   47.31 -                                                            "xcs_write_message"
   47.32 -external initialize_ring : int -> int32 -> int32 = "xcs_initialize_ring"
   47.33 -
   47.34 -(*
   47.35 - * initialize xcs stuff
   47.36 - *)
   47.37 -let setup () =
   47.38 -  connect xcs_path xcs_type
   47.39 -
   47.40 -
   47.41 -(*
   47.42 - * adios
   47.43 - *)
   47.44 -let teardown fd =
   47.45 -  disconnect fd
   47.46 -
   47.47 -
   47.48 -(*
   47.49 - * message from a domain backend
   47.50 - *)
   47.51 -let read socket =
   47.52 -  let xcs = read_message socket in
   47.53 -  begin
   47.54 -    match xcs.status with
   47.55 -      | 1 ->                                    (* PDB_CONNECTION_STATUS_UP *)
   47.56 -	  begin
   47.57 -	    print_endline (Printf.sprintf "  new backend domain available (%d)"
   47.58 -	                   xcs.domain);
   47.59 -	    let ring = initialize_ring xcs.domain xcs.ring in
   47.60 -
   47.61 -	    let (local_evtchn, remote_evtchn) = 
   47.62 -	      Evtchn.bind_interdomain xcs.domain in
   47.63 -
   47.64 -	    xcs.evtchn <- remote_evtchn;
   47.65 -	    write_message socket xcs;
   47.66 -
   47.67 -	    let evtchn_fd = Evtchn._setup () in
   47.68 -	    Evtchn._bind evtchn_fd local_evtchn;
   47.69 -
   47.70 -	    (evtchn_fd, local_evtchn, xcs.domain, ring)
   47.71 -	  end
   47.72 -      | 2 ->                                  (* PDB_CONNECTION_STATUS_DOWN *)
   47.73 -	  begin
   47.74 -	    (* TODO:
   47.75 -	       unmap the ring
   47.76 -	       unbind event channel  xen_evtchn_unbind
   47.77 -	       find the evtchn_fd for this domain and close it
   47.78 -	       finally, need to failwith something
   47.79 -	    *)
   47.80 -	    print_endline (Printf.sprintf "  close connection from domain %d"
   47.81 -	                   xcs.domain);
   47.82 -	    (socket, 0, 0, 0l)
   47.83 -	  end
   47.84 -      | _ ->
   47.85 -	  failwith "xcs read: unknown xcs status"
   47.86 -  end
   47.87 -    
   47.88 -
    48.1 --- a/tools/debugger/pdb/xcs.mli	Sun Oct 01 11:39:41 2006 -0600
    48.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    48.3 @@ -1,13 +0,0 @@
    48.4 -(** xcs.mli
    48.5 - *
    48.6 - *  xen control switch interface
    48.7 - *
    48.8 - *  @author copyright (c) 2005 alex ho
    48.9 - *  @see <www.cl.cam.ac.uk/netos/pdb> pervasive debugger
   48.10 - *  @version 1
   48.11 - *)
   48.12 -
   48.13 -
   48.14 -val setup : unit -> Unix.file_descr
   48.15 -val read : Unix.file_descr -> Unix.file_descr * int * int * int32
   48.16 -val teardown : Unix.file_descr -> unit
    49.1 --- a/tools/examples/init.d/xendomains	Sun Oct 01 11:39:41 2006 -0600
    49.2 +++ b/tools/examples/init.d/xendomains	Sun Oct 01 19:10:18 2006 -0600
    49.3 @@ -352,9 +352,9 @@ stop()
    49.4  	    if test $? -ne 0; then
    49.5  		rc_failed $?
    49.6  		echo -n '!'
    49.7 -		kill $WDOG_PIG >/dev/null 2>&1
    49.8 +		kill $WDOG_PID >/dev/null 2>&1
    49.9  	    else
   49.10 -		kill $WDOG_PIG >/dev/null 2>&1
   49.11 +		kill $WDOG_PID >/dev/null 2>&1
   49.12  		continue
   49.13  	    fi
   49.14  	fi
   49.15 @@ -368,7 +368,7 @@ stop()
   49.16  		rc_failed $?
   49.17  		echo -n '!'
   49.18  	    fi
   49.19 -	    kill $WDOG_PIG >/dev/null 2>&1
   49.20 +	    kill $WDOG_PID >/dev/null 2>&1
   49.21  	fi
   49.22      done < <(xm list | grep -v '^Name')
   49.23  
    50.1 --- a/tools/examples/xen-backend.rules	Sun Oct 01 11:39:41 2006 -0600
    50.2 +++ b/tools/examples/xen-backend.rules	Sun Oct 01 19:10:18 2006 -0600
    50.3 @@ -5,3 +5,4 @@ SUBSYSTEM=="xen-backend", KERNEL=="vif*"
    50.4  SUBSYSTEM=="xen-backend", KERNEL=="vif*", ACTION=="offline", RUN+="$env{script} offline"
    50.5  SUBSYSTEM=="xen-backend", ACTION=="remove", RUN+="/etc/xen/scripts/xen-hotplug-cleanup"
    50.6  KERNEL=="evtchn", NAME="xen/%k"
    50.7 +KERNEL=="blktap[0-9]*", NAME="xen/%k"
    51.1 --- a/tools/firmware/vmxassist/vm86.c	Sun Oct 01 11:39:41 2006 -0600
    51.2 +++ b/tools/firmware/vmxassist/vm86.c	Sun Oct 01 19:10:18 2006 -0600
    51.3 @@ -68,7 +68,7 @@ guest_linear_to_real(uint32_t base)
    51.4  		return base;
    51.5  
    51.6  	if (!(oldctx.cr4 & CR4_PAE)) {
    51.7 -		l1_mfn = ((uint32_t *)gcr3)[(base >> 22) & 0x3ff];
    51.8 +		l1_mfn = ((uint32_t *)(long)gcr3)[(base >> 22) & 0x3ff];
    51.9  		if (!(l1_mfn & PT_ENTRY_PRESENT))
   51.10  			panic("l2 entry not present\n");
   51.11  
   51.12 @@ -79,19 +79,19 @@ guest_linear_to_real(uint32_t base)
   51.13  
   51.14  		l1_mfn &= 0xfffff000;
   51.15  
   51.16 -		l0_mfn = ((uint32_t *)l1_mfn)[(base >> 12) & 0x3ff];
   51.17 +		l0_mfn = ((uint32_t *)(long)l1_mfn)[(base >> 12) & 0x3ff];
   51.18  		if (!(l0_mfn & PT_ENTRY_PRESENT))
   51.19  			panic("l1 entry not present\n");
   51.20  		l0_mfn &= 0xfffff000;
   51.21  
   51.22  		return l0_mfn + (base & 0xfff);
   51.23  	} else {
   51.24 -		l2_mfn = ((uint64_t *)gcr3)[(base >> 30) & 0x3];
   51.25 +		l2_mfn = ((uint64_t *)(long)gcr3)[(base >> 30) & 0x3];
   51.26  		if (!(l2_mfn & PT_ENTRY_PRESENT))
   51.27  			panic("l3 entry not present\n");
   51.28  		l2_mfn &= 0x3fffff000ULL;
   51.29  
   51.30 -		l1_mfn = ((uint64_t *)l2_mfn)[(base >> 21) & 0x1ff];
   51.31 +		l1_mfn = ((uint64_t *)(long)l2_mfn)[(base >> 21) & 0x1ff];
   51.32  		if (!(l1_mfn & PT_ENTRY_PRESENT))
   51.33  			panic("l2 entry not present\n");
   51.34  
   51.35 @@ -102,7 +102,7 @@ guest_linear_to_real(uint32_t base)
   51.36  
   51.37  		l1_mfn &= 0x3fffff000ULL;
   51.38  
   51.39 -		l0_mfn = ((uint64_t *)l1_mfn)[(base >> 12) & 0x1ff];
   51.40 +		l0_mfn = ((uint64_t *)(long)l1_mfn)[(base >> 12) & 0x1ff];
   51.41  		if (!(l0_mfn & PT_ENTRY_PRESENT))
   51.42  			panic("l1 entry not present\n");
   51.43  		l0_mfn &= 0x3fffff000ULL;
   51.44 @@ -1230,6 +1230,18 @@ pushrm(struct regs *regs, int prefix, un
   51.45  
   51.46  enum { OPC_INVALID, OPC_EMULATED };
   51.47  
   51.48 +#define rdmsr(msr,val1,val2)				\
   51.49 +	__asm__ __volatile__(				\
   51.50 +		"rdmsr"					\
   51.51 +		: "=a" (val1), "=d" (val2)		\
   51.52 +		: "c" (msr))
   51.53 +
   51.54 +#define wrmsr(msr,val1,val2)				\
   51.55 +	__asm__ __volatile__(				\
   51.56 +		"wrmsr"					\
   51.57 +		: /* no outputs */			\
   51.58 +		: "c" (msr), "a" (val1), "d" (val2))
   51.59 +
   51.60  /*
   51.61   * Emulate a single instruction, including all its prefixes. We only implement
   51.62   * a small subset of the opcodes, and not all opcodes are implemented for each
   51.63 @@ -1288,6 +1300,12 @@ opcode(struct regs *regs)
   51.64  				if (!movcr(regs, prefix, opc))
   51.65  					goto invalid;
   51.66  				return OPC_EMULATED;
   51.67 +			case 0x30: /* WRMSR */
   51.68 +				wrmsr(regs->ecx, regs->eax, regs->edx);
   51.69 +				return OPC_EMULATED;
   51.70 +			case 0x32: /* RDMSR */
   51.71 +				rdmsr(regs->ecx, regs->eax, regs->edx);
   51.72 +				return OPC_EMULATED;
   51.73  			default:
   51.74  				goto invalid;
   51.75  			}
   51.76 @@ -1412,12 +1430,14 @@ opcode(struct regs *regs)
   51.77  			{
   51.78  				int addr, data;
   51.79  				int seg = segment(prefix, regs, regs->vds);
   51.80 +				int offset = prefix & ADDR32? fetch32(regs) : fetch16(regs);
   51.81 +
   51.82  				if (prefix & DATA32) {
   51.83 -					addr = address(regs, seg, fetch32(regs));
   51.84 +					addr = address(regs, seg, offset);
   51.85  					data = read32(addr);
   51.86  					setreg32(regs, 0, data);
   51.87  				} else {
   51.88 -					addr = address(regs, seg, fetch16(regs));
   51.89 +					addr = address(regs, seg, offset);
   51.90  					data = read16(addr);
   51.91  					setreg16(regs, 0, data);
   51.92  				}
    52.1 --- a/tools/ioemu/target-i386-dm/helper2.c	Sun Oct 01 11:39:41 2006 -0600
    52.2 +++ b/tools/ioemu/target-i386-dm/helper2.c	Sun Oct 01 19:10:18 2006 -0600
    52.3 @@ -520,8 +520,8 @@ int main_loop(void)
    52.4              }
    52.5          }
    52.6  
    52.7 -        /* Wait up to 100 msec. */
    52.8 -        main_loop_wait(100);
    52.9 +        /* Wait up to 10 msec. */
   52.10 +        main_loop_wait(10);
   52.11  
   52.12          if (env->send_event) {
   52.13              env->send_event = 0;
    53.1 --- a/tools/libxc/xc_linux.c	Sun Oct 01 11:39:41 2006 -0600
    53.2 +++ b/tools/libxc/xc_linux.c	Sun Oct 01 19:10:18 2006 -0600
    53.3 @@ -133,27 +133,95 @@ int do_xen_hypercall(int xc_handle, priv
    53.4                        (unsigned long)hypercall);
    53.5  }
    53.6  
    53.7 +#define MTAB "/proc/mounts"
    53.8 +#define MAX_PATH 255
    53.9 +#define _STR(x) #x
   53.10 +#define STR(x) _STR(x)
   53.11 +
   53.12 +static int find_sysfsdir(char *sysfsdir)
   53.13 +{
   53.14 +    FILE *fp;
   53.15 +    char type[MAX_PATH + 1];
   53.16 +
   53.17 +    if ( (fp = fopen(MTAB, "r")) == NULL )
   53.18 +        return -1;
   53.19 +
   53.20 +    while ( fscanf(fp, "%*s %"
   53.21 +                   STR(MAX_PATH)
   53.22 +                   "s %"
   53.23 +                   STR(MAX_PATH)
   53.24 +                   "s %*s %*d %*d\n",
   53.25 +                   sysfsdir, type) == 2 )
   53.26 +    {
   53.27 +        if ( strncmp(type, "sysfs", 5) == 0 )
   53.28 +            break;
   53.29 +    }
   53.30 +
   53.31 +    fclose(fp);
   53.32 +
   53.33 +    return ((strncmp(type, "sysfs", 5) == 0) ? 0 : -1);
   53.34 +}
   53.35 +
   53.36 +int xc_find_device_number(const char *name)
   53.37 +{
   53.38 +    FILE *fp;
   53.39 +    int i, major, minor;
   53.40 +    char sysfsdir[MAX_PATH + 1];
   53.41 +    static char *classlist[] = { "xen", "misc" };
   53.42 +
   53.43 +    for ( i = 0; i < (sizeof(classlist) / sizeof(classlist[0])); i++ )
   53.44 +    {
   53.45 +        if ( find_sysfsdir(sysfsdir) < 0 )
   53.46 +            goto not_found;
   53.47 +
   53.48 +        /* <base>/class/<classname>/<devname>/dev */
   53.49 +        strncat(sysfsdir, "/class/", MAX_PATH);
   53.50 +        strncat(sysfsdir, classlist[i], MAX_PATH);
   53.51 +        strncat(sysfsdir, "/", MAX_PATH);
   53.52 +        strncat(sysfsdir, name, MAX_PATH);
   53.53 +        strncat(sysfsdir, "/dev", MAX_PATH);
   53.54 +
   53.55 +        if ( (fp = fopen(sysfsdir, "r")) != NULL )
   53.56 +            goto found;
   53.57 +    }
   53.58 +
   53.59 + not_found:
   53.60 +    errno = -ENOENT;
   53.61 +    return -1;
   53.62 +
   53.63 + found:
   53.64 +    if ( fscanf(fp, "%d:%d", &major, &minor) != 2 )
   53.65 +    {
   53.66 +        fclose(fp);
   53.67 +        goto not_found;
   53.68 +    }
   53.69 +
   53.70 +    fclose(fp);
   53.71 +
   53.72 +    return makedev(major, minor);
   53.73 +}
   53.74 +
   53.75  #define EVTCHN_DEV_NAME  "/dev/xen/evtchn"
   53.76 -#define EVTCHN_DEV_MAJOR 10
   53.77 -#define EVTCHN_DEV_MINOR 201
   53.78  
   53.79  int xc_evtchn_open(void)
   53.80  {
   53.81      struct stat st;
   53.82      int fd;
   53.83 +    int devnum;
   53.84 +
   53.85 +    devnum = xc_find_device_number("evtchn");
   53.86  
   53.87      /* Make sure any existing device file links to correct device. */
   53.88 -    if ((lstat(EVTCHN_DEV_NAME, &st) != 0) || !S_ISCHR(st.st_mode) ||
   53.89 -        (st.st_rdev != makedev(EVTCHN_DEV_MAJOR, EVTCHN_DEV_MINOR)))
   53.90 +    if ( (lstat(EVTCHN_DEV_NAME, &st) != 0) || !S_ISCHR(st.st_mode) ||
   53.91 +         (st.st_rdev != devnum) )
   53.92          (void)unlink(EVTCHN_DEV_NAME);
   53.93  
   53.94 -reopen:
   53.95 + reopen:
   53.96      if ( (fd = open(EVTCHN_DEV_NAME, O_RDWR)) == -1 )
   53.97      {
   53.98          if ( (errno == ENOENT) &&
   53.99              ((mkdir("/dev/xen", 0755) == 0) || (errno == EEXIST)) &&
  53.100 -            (mknod(EVTCHN_DEV_NAME, S_IFCHR|0600,
  53.101 -            makedev(EVTCHN_DEV_MAJOR, EVTCHN_DEV_MINOR)) == 0) )
  53.102 +             (mknod(EVTCHN_DEV_NAME, S_IFCHR|0600, devnum) == 0) )
  53.103              goto reopen;
  53.104  
  53.105          PERROR("Could not open event channel interface");
    54.1 --- a/tools/libxc/xenctrl.h	Sun Oct 01 11:39:41 2006 -0600
    54.2 +++ b/tools/libxc/xenctrl.h	Sun Oct 01 19:10:18 2006 -0600
    54.3 @@ -92,6 +92,16 @@ int xc_interface_open(void);
    54.4  int xc_interface_close(int xc_handle);
    54.5  
    54.6  /*
    54.7 + * KERNEL INTERFACES
    54.8 + */
    54.9 +
   54.10 +/*
   54.11 + * Resolve a kernel device name (e.g., "evtchn", "blktap0") into a kernel
   54.12 + * device number. Returns -1 on error (and sets errno).
   54.13 + */
   54.14 +int xc_find_device_number(const char *name);
   54.15 +
   54.16 +/*
   54.17   * DOMAIN DEBUGGING FUNCTIONS
   54.18   */
   54.19  
    55.1 --- a/tools/pygrub/src/pygrub	Sun Oct 01 11:39:41 2006 -0600
    55.2 +++ b/tools/pygrub/src/pygrub	Sun Oct 01 19:10:18 2006 -0600
    55.3 @@ -25,7 +25,18 @@ sys.path = [ '/usr/lib/python' ] + sys.p
    55.4  import grub.GrubConf
    55.5  import grub.fsys
    55.6  
    55.7 -PYGRUB_VER = 0.4
    55.8 +PYGRUB_VER = 0.5
    55.9 +
   55.10 +def enable_cursor(ison):
   55.11 +    if ison:
   55.12 +        val = 2
   55.13 +    else:
   55.14 +        val = 0
   55.15 +        
   55.16 +    try:
   55.17 +        curses.curs_set(val)
   55.18 +    except _curses.error:
   55.19 +        pass
   55.20  
   55.21  def is_disk_image(file):
   55.22      fd = os.open(file, os.O_RDONLY)
   55.23 @@ -141,10 +152,7 @@ class Grub:
   55.24              self.screen.timeout(1000)
   55.25              if hasattr(curses, 'use_default_colors'):
   55.26                  curses.use_default_colors()
   55.27 -            try:
   55.28 -                curses.curs_set(0)
   55.29 -            except _curses.error:
   55.30 -                pass
   55.31 +            enable_cursor(False)
   55.32              self.entry_win = curses.newwin(10, 74, 2, 1)
   55.33              self.text_win = curses.newwin(10, 70, 12, 5)
   55.34              
   55.35 @@ -247,6 +255,7 @@ class Grub:
   55.36          self.screen.refresh()
   55.37  
   55.38          t = GrubLineEditor(self.screen, 5, 2, line)
   55.39 +        enable_cursor(True)
   55.40          ret = t.edit()
   55.41          if ret:
   55.42              return ret
   55.43 @@ -262,6 +271,7 @@ class Grub:
   55.44          lines = []
   55.45          while 1:
   55.46              t = GrubLineEditor(self.screen, y, 2)
   55.47 +            enable_cursor(True)            
   55.48              ret = t.edit()
   55.49              if ret:
   55.50                  if ret in ("quit", "return"):
    56.1 --- a/tools/python/xen/util/blkif.py	Sun Oct 01 11:39:41 2006 -0600
    56.2 +++ b/tools/python/xen/util/blkif.py	Sun Oct 01 19:10:18 2006 -0600
    56.3 @@ -67,6 +67,8 @@ def blkdev_uname_to_file(uname):
    56.4          (typ, fn) = uname.split(":")
    56.5          if typ == "phy" and not fn.startswith("/"):
    56.6              fn = "/dev/%s" %(fn,)
    56.7 +        if typ == "tap":
    56.8 +            (typ, fn) = fn.split(":", 1)
    56.9      return fn
   56.10  
   56.11  def mount_mode(name):
    57.1 --- a/tools/python/xen/xend/image.py	Sun Oct 01 11:39:41 2006 -0600
    57.2 +++ b/tools/python/xen/xend/image.py	Sun Oct 01 19:10:18 2006 -0600
    57.3 @@ -244,7 +244,8 @@ class HVMImageHandler(ImageHandler):
    57.4  
    57.5          info = xc.xeninfo()
    57.6          if not 'hvm' in info['xen_caps']:
    57.7 -            raise VmError("Not an HVM capable platform, we stop creating!")
    57.8 +            raise VmError("HVM guest support is unavailable: is VT/AMD-V "
    57.9 +                          "supported by your CPU and enabled in your BIOS?")
   57.10  
   57.11          self.dmargs = self.parseDeviceModelArgs(imageConfig, deviceConfig)
   57.12          self.device_model = sxp.child_value(imageConfig, 'device_model')
    58.1 --- a/tools/python/xen/xm/addlabel.py	Sun Oct 01 11:39:41 2006 -0600
    58.2 +++ b/tools/python/xen/xm/addlabel.py	Sun Oct 01 19:10:18 2006 -0600
    58.3 @@ -115,43 +115,45 @@ def add_domain_label(label, configfile, 
    58.4      config_fd.close()
    58.5  
    58.6  
    58.7 -def main (argv):
    58.8 -    try:
    58.9 -        policyref = None
   58.10 -        if len(argv) not in (4, 5):
   58.11 -            raise OptionError('Needs either 2 or 3 arguments')
   58.12 -
   58.13 -        label = argv[1]
   58.14 -
   58.15 -        if len(argv) == 5:
   58.16 -            policyref = argv[4]
   58.17 -        elif security.on():
   58.18 -            policyref = security.active_policy
   58.19 -        else:
   58.20 -            security.err("No active policy. Policy must be specified in command line.")
   58.21 +def main(argv):
   58.22 +    policyref = None
   58.23 +    if len(argv) not in (4, 5):
   58.24 +        raise OptionError('Needs either 2 or 3 arguments')
   58.25 +    
   58.26 +    label = argv[1]
   58.27 +    
   58.28 +    if len(argv) == 5:
   58.29 +        policyref = argv[4]
   58.30 +    elif security.on():
   58.31 +        policyref = security.active_policy
   58.32 +    else:
   58.33 +        raise OptionError("No active policy. Must specify policy on the "
   58.34 +                          "command line.")
   58.35  
   58.36 -        if argv[2].lower() == "dom":
   58.37 -            configfile = argv[3]
   58.38 -            if configfile[0] != '/':
   58.39 -                for prefix in [".", "/etc/xen"]:
   58.40 -                    configfile = prefix + "/" + configfile
   58.41 -                    if os.path.isfile(configfile):
   58.42 -                        break
   58.43 -            if not validate_config_file(configfile):
   58.44 -                raise OptionError('Invalid config file')
   58.45 -            else:
   58.46 -                add_domain_label(label, configfile, policyref)
   58.47 -        elif argv[2].lower() == "res":
   58.48 -            resource = argv[3]
   58.49 -            add_resource_label(label, resource, policyref)
   58.50 +    if argv[2].lower() == "dom":
   58.51 +        configfile = argv[3]
   58.52 +        if configfile[0] != '/':
   58.53 +            for prefix in [".", "/etc/xen"]:
   58.54 +                configfile = prefix + "/" + configfile
   58.55 +                if os.path.isfile(configfile):
   58.56 +                    break
   58.57 +        if not validate_config_file(configfile):
   58.58 +            raise OptionError('Invalid config file')
   58.59          else:
   58.60 -            raise OptionError('Need to specify either "dom" or "res" as object to add label to.')
   58.61 +            add_domain_label(label, configfile, policyref)
   58.62 +    elif argv[2].lower() == "res":
   58.63 +        resource = argv[3]
   58.64 +        add_resource_label(label, resource, policyref)
   58.65 +    else:
   58.66 +        raise OptionError('Need to specify either "dom" or "res" as '
   58.67 +                          'object to add label to.')
   58.68              
   58.69 -    except security.ACMError:
   58.70 +if __name__ == '__main__':
   58.71 +    try:
   58.72 +        main(sys.argv)
   58.73 +    except Exception, e:
   58.74 +        sys.stderr.write('Error: %s\n' % str(e))
   58.75          sys.exit(-1)
   58.76 -
   58.77 -if __name__ == '__main__':
   58.78 -    main(sys.argv)
   58.79      
   58.80  
   58.81  
    59.1 --- a/tools/python/xen/xm/cfgbootpolicy.py	Sun Oct 01 11:39:41 2006 -0600
    59.2 +++ b/tools/python/xen/xm/cfgbootpolicy.py	Sun Oct 01 19:10:18 2006 -0600
    59.3 @@ -140,44 +140,41 @@ def insert_policy(boot_file, kernel_vers
    59.4  
    59.5  
    59.6  def main(argv):
    59.7 -    try:
    59.8 -        user_kver = None
    59.9 -        policy = None
   59.10 -        if len(argv) == 2:
   59.11 -            policy = argv[1]
   59.12 -        elif len(argv) == 3:
   59.13 -            policy = argv[1]
   59.14 -            user_kver = argv[2]
   59.15 -        else:
   59.16 -            raise OptionError('Invalid number of arguments')
   59.17 -
   59.18 -        if not policy_name_re.match(policy):
   59.19 -            err("Illegal policy name \'" + policy + "\'")
   59.20 +    user_kver = None
   59.21 +    policy = None
   59.22 +    if len(argv) == 2:
   59.23 +        policy = argv[1]
   59.24 +    elif len(argv) == 3:
   59.25 +        policy = argv[1]
   59.26 +        user_kver = argv[2]
   59.27 +    else:
   59.28 +        raise OptionError('Invalid number of arguments')
   59.29 +    
   59.30 +    if not policy_name_re.match(policy):
   59.31 +        raise OptionError("Illegal policy name: '%s'" % policy)
   59.32  
   59.33 -        policy_file = policy_dir_prefix + "/" + string.join(string.split(policy, "."), "/")
   59.34 -        src_binary_policy_file = policy_file + ".bin"
   59.35 -        #check if .bin exists or if policy file exists
   59.36 -        if not os.path.isfile(src_binary_policy_file):
   59.37 -            if not os.path.isfile(policy_file + "-security_policy.xml"):
   59.38 -                err("Unknown policy \'" + policy +"\'")
   59.39 -            else:
   59.40 -                err("Cannot find binary file for policy \'" + policy +
   59.41 -                    "\'. Please use makepolicy to create binary file.")
   59.42 -        dst_binary_policy_file = "/boot/" + policy + ".bin"
   59.43 -        shutil.copyfile(src_binary_policy_file, dst_binary_policy_file)
   59.44 -
   59.45 -        kernel_version = determine_kernelversion(user_kver)
   59.46 -        insert_policy(boot_filename, kernel_version, policy)
   59.47 -        print "Boot entry created and \'%s\' copied to /boot" % (policy + ".bin")
   59.48 -
   59.49 -    except ACMError:
   59.50 -        sys.exit(-1)
   59.51 -    except:
   59.52 -        traceback.print_exc(limit=1)
   59.53 -        sys.exit(-1)
   59.54 -
   59.55 -
   59.56 +    policy_file = '/'.join([policy_dir_prefix] + policy.split('.'))
   59.57 +    src_binary_policy_file = policy_file + ".bin"
   59.58 +    #check if .bin exists or if policy file exists
   59.59 +    if not os.path.isfile(src_binary_policy_file):
   59.60 +        if not os.path.isfile(policy_file + "-security_policy.xml"):
   59.61 +            raise OptionError("Unknown policy '%s'" % policy)
   59.62 +        else:
   59.63 +            err_msg = "Cannot find binary file for policy '%s'." % policy
   59.64 +            err_msg += " Please use makepolicy to create binary file."
   59.65 +            raise OptionError(err_msg)
   59.66 +    
   59.67 +    dst_binary_policy_file = "/boot/" + policy + ".bin"
   59.68 +    shutil.copyfile(src_binary_policy_file, dst_binary_policy_file)
   59.69 +    
   59.70 +    kernel_version = determine_kernelversion(user_kver)
   59.71 +    insert_policy(boot_filename, kernel_version, policy)
   59.72 +    print "Boot entry created and \'%s\' copied to /boot" % (policy + ".bin")
   59.73  
   59.74  if __name__ == '__main__':
   59.75 -    main(sys.argv)
   59.76 -
   59.77 +    try:
   59.78 +        main(sys.argv)
   59.79 +    except Exception, e:
   59.80 +        sys.stderr.write('Error: ' + str(e) + '\n')    
   59.81 +        sys.exit(-1)
   59.82 +        
    60.1 --- a/tools/python/xen/xm/create.py	Sun Oct 01 11:39:41 2006 -0600
    60.2 +++ b/tools/python/xen/xm/create.py	Sun Oct 01 19:10:18 2006 -0600
    60.3 @@ -693,7 +693,7 @@ def make_config(vals):
    60.4          config_image = run_bootloader(vals, config_image)
    60.5          config.append(['bootloader', vals.bootloader])
    60.6          if vals.bootargs:
    60.7 -            config.append(['bootloader_args'], vals.bootargs)
    60.8 +            config.append(['bootloader_args', vals.bootargs])
    60.9      config.append(['image', config_image])
   60.10  
   60.11      config_devs = []
    61.1 --- a/tools/python/xen/xm/dry-run.py	Sun Oct 01 11:39:41 2006 -0600
    61.2 +++ b/tools/python/xen/xm/dry-run.py	Sun Oct 01 19:10:18 2006 -0600
    61.3 @@ -32,27 +32,26 @@ def help():
    61.4      individually along with the final security decision."""
    61.5  
    61.6  def main (argv):
    61.7 -    try:
    61.8 -        if len(argv) != 2:
    61.9 -            raise OptionError('Invalid number of arguments')
   61.10 -
   61.11 -        passed = 0
   61.12 -        (opts, config) = create.parseCommandLine(argv)
   61.13 -        if create.check_domain_label(config, verbose=1):
   61.14 -            if create.config_security_check(config, verbose=1):
   61.15 -                passed = 1
   61.16 -        else:
   61.17 -            print "Checking resources: (skipped)"
   61.18 -                
   61.19 -        if passed:
   61.20 -            print "Dry Run: PASSED"
   61.21 -        else:
   61.22 -            print "Dry Run: FAILED"
   61.23 -            sys.exit(-1)
   61.24 -
   61.25 -    except security.ACMError:
   61.26 +    if len(argv) != 2:
   61.27 +        raise OptionError('Invalid number of arguments')
   61.28 +    
   61.29 +    passed = 0
   61.30 +    (opts, config) = create.parseCommandLine(argv)
   61.31 +    if create.check_domain_label(config, verbose=1):
   61.32 +        if create.config_security_check(config, verbose=1):
   61.33 +            passed = 1
   61.34 +    else:
   61.35 +        print "Checking resources: (skipped)"
   61.36 +        
   61.37 +    if passed:
   61.38 +        print "Dry Run: PASSED"
   61.39 +    else:
   61.40 +        print "Dry Run: FAILED"
   61.41          sys.exit(-1)
   61.42  
   61.43 -
   61.44  if __name__ == '__main__':
   61.45 -    main(sys.argv)
   61.46 +    try:
   61.47 +        main(sys.argv)
   61.48 +    except Exception, e:
   61.49 +        sys.stderr.write('Error: %s\n' % str(e))
   61.50 +        sys.exit(-1)
    62.1 --- a/tools/python/xen/xm/dumppolicy.py	Sun Oct 01 11:39:41 2006 -0600
    62.2 +++ b/tools/python/xen/xm/dumppolicy.py	Sun Oct 01 19:10:18 2006 -0600
    62.3 @@ -19,7 +19,7 @@
    62.4  """
    62.5  import sys
    62.6  from xen.util.security import ACMError, err, dump_policy
    62.7 -
    62.8 +from xen.xm.opts import OptionError
    62.9  
   62.10  def help():
   62.11      return """
   62.12 @@ -27,16 +27,16 @@ def help():
   62.13      (low-level)."""
   62.14  
   62.15  def main(argv):
   62.16 +    if len(argv) != 1:
   62.17 +        raise OptionError("No arguments expected.")
   62.18 +
   62.19 +    dump_policy()
   62.20 +
   62.21 +if __name__ == '__main__':
   62.22      try:
   62.23 -        if len(argv) != 1:
   62.24 -            usage()
   62.25 -
   62.26 -        dump_policy()
   62.27 -    except ACMError:
   62.28 +        main(sys.argv)
   62.29 +    except Exception, e:
   62.30 +        sys.stderr.write('Error: %s\n' % str(e))    
   62.31          sys.exit(-1)
   62.32  
   62.33  
   62.34 -if __name__ == '__main__':
   62.35 -    main(sys.argv)
   62.36 -
   62.37 -
    63.1 --- a/tools/python/xen/xm/getlabel.py	Sun Oct 01 11:39:41 2006 -0600
    63.2 +++ b/tools/python/xen/xm/getlabel.py	Sun Oct 01 19:10:18 2006 -0600
    63.3 @@ -25,8 +25,9 @@ from xen.xm.opts import OptionError
    63.4  
    63.5  def help():
    63.6      return """
    63.7 -    Usage: xm getlabel dom <configfile>"
    63.8 -           xm getlabel res <resource>\n"
    63.9 +    Usage: xm getlabel dom <configfile>
   63.10 +           xm getlabel res <resource>
   63.11 +           
   63.12      This program shows the label for a domain or resource."""
   63.13  
   63.14  def get_resource_label(resource):
   63.15 @@ -37,7 +38,7 @@ def get_resource_label(resource):
   63.16      try:
   63.17          access_control = dictio.dict_read("resources", file)
   63.18      except:
   63.19 -        security.err("Resource label file not found")
   63.20 +        raise OptionError("Resource label file not found")
   63.21  
   63.22      # get the entry and print label
   63.23      if access_control.has_key(resource):
   63.24 @@ -45,23 +46,22 @@ def get_resource_label(resource):
   63.25          label = access_control[resource][1]
   63.26          print "policy="+policy+",label="+label
   63.27      else:
   63.28 -        security.err("Resource not labeled")
   63.29 +        raise security.ACMError("Resource not labeled")
   63.30  
   63.31  
   63.32  def get_domain_label(configfile):
   63.33      # open the domain config file
   63.34      fd = None
   63.35 -    file = None
   63.36      if configfile[0] == '/':
   63.37          fd = open(configfile, "rb")
   63.38      else:
   63.39          for prefix in [".", "/etc/xen"]:
   63.40 -            file = prefix + "/" + configfile
   63.41 -            if os.path.isfile(file):
   63.42 -                fd = open(file, "rb")
   63.43 +            abs_file = prefix + "/" + configfile
   63.44 +            if os.path.isfile(abs_file):
   63.45 +                fd = open(abs_file, "rb")
   63.46                  break
   63.47      if not fd:
   63.48 -        security.err("Configuration file '"+configfile+"' not found.")
   63.49 +        raise OptionError("Configuration file '%s' not found." % configfile)
   63.50  
   63.51      # read in the domain config file, finding the label line
   63.52      ac_entry_re = re.compile("^access_control\s*=.*", re.IGNORECASE)
   63.53 @@ -79,7 +79,7 @@ def get_domain_label(configfile):
   63.54  
   63.55      # send error message if we didn't find anything
   63.56      if acline == "":
   63.57 -        security.err("Domain not labeled")
   63.58 +        raise security.ACMError("Domain not labeled")
   63.59  
   63.60      # print out the label
   63.61      (title, data) = acline.split("=", 1)
   63.62 @@ -89,7 +89,7 @@ def get_domain_label(configfile):
   63.63      print data
   63.64  
   63.65  
   63.66 -def main (argv):
   63.67 +def main(argv):
   63.68      if len(argv) != 3:
   63.69          raise OptionError('Requires 2 arguments')
   63.70  
   63.71 @@ -103,6 +103,11 @@ def main (argv):
   63.72          raise OptionError('First subcommand argument must be "dom" or "res"')
   63.73  
   63.74  if __name__ == '__main__':
   63.75 -    main(sys.argv)
   63.76 +    try:
   63.77 +        main(sys.argv)
   63.78 +    except Exception, e:
   63.79 +        sys.stderr.write('Error: %s\n' % str(e))
   63.80 +        sys.exit(-1)
   63.81 +        
   63.82  
   63.83  
    64.1 --- a/tools/python/xen/xm/loadpolicy.py	Sun Oct 01 11:39:41 2006 -0600
    64.2 +++ b/tools/python/xen/xm/loadpolicy.py	Sun Oct 01 19:10:18 2006 -0600
    64.3 @@ -31,15 +31,12 @@ def main(argv):
    64.4      if len(argv) != 2:
    64.5          raise OptionError('No policy defined')
    64.6      
    64.7 -    try:
    64.8 -        load_policy(argv[1])
    64.9 -
   64.10 -    except ACMError:
   64.11 -        sys.exit(-1)
   64.12 -    except:
   64.13 -        traceback.print_exc(limit = 1)
   64.14 +    load_policy(argv[1])
   64.15  
   64.16  if __name__ == '__main__':
   64.17 -    main(sys.argv)
   64.18 -
   64.19 -
   64.20 +    try:
   64.21 +        main(sys.argv)
   64.22 +    except Exception, e:
   64.23 +        sys.stderr.write('Error: %s\n' % str(e))
   64.24 +        sys.exit(-1)
   64.25 +        
    65.1 --- a/tools/python/xen/xm/main.py	Sun Oct 01 11:39:41 2006 -0600
    65.2 +++ b/tools/python/xen/xm/main.py	Sun Oct 01 19:10:18 2006 -0600
    65.3 @@ -526,7 +526,7 @@ def parse_sedf_info(info):
    65.4          return t(sxp.child_value(info, n, d))
    65.5  
    65.6      return {
    65.7 -        'domid'    : get_info('domid',         int,   -1),
    65.8 +        'domid'    : get_info('domain',        int,   -1),
    65.9          'period'   : get_info('period',        int,   -1),
   65.10          'slice'    : get_info('slice',         int,   -1),
   65.11          'latency'  : get_info('latency',       int,   -1),
   65.12 @@ -979,7 +979,7 @@ def xm_uptime(args):
   65.13  
   65.14      for dom in doms:
   65.15          d = parse_doms_info(dom)
   65.16 -        if d['dom'] > 0:
   65.17 +        if d['domid'] > 0:
   65.18              uptime = int(round(d['up_time']))
   65.19          else:
   65.20              f=open('/proc/uptime', 'r')
   65.21 @@ -1006,10 +1006,10 @@ def xm_uptime(args):
   65.22          if short_mode:
   65.23              now = datetime.datetime.now()
   65.24              upstring = now.strftime(" %H:%M:%S") + " up " + upstring
   65.25 -            upstring += ", " + d['name'] + " (" + str(d['dom']) + ")"
   65.26 +            upstring += ", " + d['name'] + " (" + str(d['domid']) + ")"
   65.27          else:
   65.28              upstring += ':%(seconds)02d' % vars()
   65.29 -            upstring = ("%(name)-32s %(dom)3d " % d) + upstring
   65.30 +            upstring = ("%(name)-32s %(domid)3d " % d) + upstring
   65.31  
   65.32          print upstring
   65.33  
   65.34 @@ -1374,7 +1374,7 @@ IMPORTED_COMMANDS = [
   65.35      'cfgbootpolicy',
   65.36      'makepolicy',
   65.37      'loadpolicy',
   65.38 -    'dumppolicy'
   65.39 +    'dumppolicy',
   65.40      'rmlabel',
   65.41      'getlabel',
   65.42      'dry-run',
   65.43 @@ -1423,13 +1423,14 @@ def main(argv=sys.argv):
   65.44      if len(argv) < 2:
   65.45          usage()
   65.46  
   65.47 -    # intercept --help and output our own help
   65.48 -    if '--help' in argv[1:]:
   65.49 -        if '--help' == argv[1]:
   65.50 -            longHelp()
   65.51 -        else:
   65.52 -            usage(argv[1])
   65.53 -        sys.exit(0)
   65.54 +    # intercept --help(-h) and output our own help
   65.55 +    for help in ['--help', '-h']:
   65.56 +        if help in argv[1:]:
   65.57 +            if help == argv[1]:
   65.58 +                longHelp()
   65.59 +            else:
   65.60 +                usage(argv[1])
   65.61 +            sys.exit(0)
   65.62  
   65.63      cmd = xm_lookup_cmd(argv[1])
   65.64  
   65.65 @@ -1477,10 +1478,15 @@ def main(argv=sys.argv):
   65.66          except (ValueError, OverflowError):
   65.67              err("Invalid argument.")
   65.68              usage(argv[1])
   65.69 +            sys.exit(1)
   65.70          except OptionError, e:
   65.71              err(str(e))
   65.72              usage(argv[1])
   65.73              print e.usage()
   65.74 +            sys.exit(1)
   65.75 +        except security.ACMError, e:
   65.76 +            err(str(e))
   65.77 +            sys.exit(1)
   65.78          except:
   65.79              print "Unexpected error:", sys.exc_info()[0]
   65.80              print
    66.1 --- a/tools/python/xen/xm/makepolicy.py	Sun Oct 01 11:39:41 2006 -0600
    66.2 +++ b/tools/python/xen/xm/makepolicy.py	Sun Oct 01 19:10:18 2006 -0600
    66.3 @@ -33,16 +33,13 @@ def main(argv):
    66.4      if len(argv) != 2:
    66.5          raise OptionError('No XML policy file specified')
    66.6  
    66.7 +    make_policy(argv[1])
    66.8 +
    66.9 +if __name__ == '__main__':
   66.10      try:
   66.11 -        make_policy(argv[1])
   66.12 -    except ACMError:
   66.13 -        sys.exit(-1)
   66.14 -    except:
   66.15 -        traceback.print_exc(limit=1)
   66.16 +        main(sys.argv)
   66.17 +    except Exception, e:
   66.18 +        sys.stderr.write('Error: %s\n' % str(e))
   66.19          sys.exit(-1)
   66.20  
   66.21  
   66.22 -if __name__ == '__main__':
   66.23 -    main(sys.argv)
   66.24 -
   66.25 -
    67.1 --- a/tools/python/xen/xm/resources.py	Sun Oct 01 11:39:41 2006 -0600
    67.2 +++ b/tools/python/xen/xm/resources.py	Sun Oct 01 19:10:18 2006 -0600
    67.3 @@ -24,7 +24,7 @@ from xen.util import security
    67.4  from xen.xm.opts import OptionError
    67.5  
    67.6  def help():
    67.7 -    return """Usage: xm resource
    67.8 +    return """
    67.9      This program lists information for each resource in the
   67.10      global resource label file."""
   67.11  
   67.12 @@ -45,18 +45,13 @@ def main (argv):
   67.13          filename = security.res_label_filename
   67.14          access_control = dictio.dict_read("resources", filename)
   67.15      except:
   67.16 -        print "Resource file not found."
   67.17 -        return
   67.18 +        raise OptionError("Resource file not found")
   67.19  
   67.20 -        try:
   67.21 -            file = security.res_label_filename
   67.22 -            access_control = dictio.dict_read("resources", file)
   67.23 -        except:
   67.24 -            security.err("Error reading resource file.")
   67.25 -
   67.26 -        print_resource_data(access_control)
   67.27 +    print_resource_data(access_control)
   67.28  
   67.29  if __name__ == '__main__':
   67.30 -    main(sys.argv)
   67.31 -
   67.32 -
   67.33 +    try:
   67.34 +        main(sys.argv)
   67.35 +    except Exception, e:
   67.36 +        sys.stderr.write('Error: %s\n' % str(e))
   67.37 +        sys.exit(-1)    
    68.1 --- a/tools/python/xen/xm/rmlabel.py	Sun Oct 01 11:39:41 2006 -0600
    68.2 +++ b/tools/python/xen/xm/rmlabel.py	Sun Oct 01 19:10:18 2006 -0600
    68.3 @@ -42,14 +42,14 @@ def rm_resource_label(resource):
    68.4      try:
    68.5          access_control = dictio.dict_read("resources", file)
    68.6      except:
    68.7 -        security.err("Resource file not found, cannot remove label!")
    68.8 +        raise security.ACMError("Resource file not found, cannot remove label!")
    68.9  
   68.10      # remove the entry and update file
   68.11      if access_control.has_key(resource):
   68.12          del access_control[resource]
   68.13          dictio.dict_write(access_control, "resources", file)
   68.14      else:
   68.15 -        security.err("Resource not labeled.")
   68.16 +        raise security.ACMError("Resource not labeled")
   68.17  
   68.18  
   68.19  def rm_domain_label(configfile):
   68.20 @@ -65,8 +65,8 @@ def rm_domain_label(configfile):
   68.21                  fd = open(file, "rb")
   68.22                  break
   68.23      if not fd:
   68.24 -        security.err("Configuration file '"+configfile+"' not found.")
   68.25 -
   68.26 +        raise OptionError("Configuration file '%s' not found." % configfile)
   68.27 +        
   68.28      # read in the domain config file, removing label
   68.29      ac_entry_re = re.compile("^access_control\s*=.*", re.IGNORECASE)
   68.30      ac_exit_re = re.compile(".*'\].*")
   68.31 @@ -86,7 +86,7 @@ def rm_domain_label(configfile):
   68.32  
   68.33      # send error message if we didn't find anything to remove
   68.34      if not removed:
   68.35 -        security.err("Domain not labeled.")
   68.36 +        raise security.ACMError('Domain not labeled')
   68.37  
   68.38      # write the data back out to the file
   68.39      fd = open(file, "wb")
   68.40 @@ -102,17 +102,18 @@ def main (argv):
   68.41      if argv[1].lower() not in ('dom', 'res'):
   68.42          raise OptionError('Unrecognised type argument: %s' % argv[1])
   68.43  
   68.44 -    try:
   68.45 -        if argv[1].lower() == "dom":
   68.46 -            configfile = argv[2]
   68.47 -            rm_domain_label(configfile)
   68.48 -        elif argv[1].lower() == "res":
   68.49 -            resource = argv[2]
   68.50 -            rm_resource_label(resource)
   68.51 -    except security.ACMError:
   68.52 -        sys.exit(-1)
   68.53 +    if argv[1].lower() == "dom":
   68.54 +        configfile = argv[2]
   68.55 +        rm_domain_label(configfile)
   68.56 +    elif argv[1].lower() == "res":
   68.57 +        resource = argv[2]
   68.58 +        rm_resource_label(resource)
   68.59  
   68.60  if __name__ == '__main__':
   68.61 -    main(sys.argv)
   68.62 +    try:
   68.63 +        main(sys.argv)
   68.64 +    except Exception, e:
   68.65 +        sys.stderr.write('Error: %s\n' % str(e))
   68.66 +        sys.exit(-1)    
   68.67  
   68.68  
    69.1 --- a/tools/xm-test/tests/vtpm/vtpm_utils.py	Sun Oct 01 11:39:41 2006 -0600
    69.2 +++ b/tools/xm-test/tests/vtpm/vtpm_utils.py	Sun Oct 01 19:10:18 2006 -0600
    69.3 @@ -8,12 +8,10 @@ from XmTestLib import *
    69.4  if ENABLE_HVM_SUPPORT:
    69.5      SKIP("vtpm tests not supported for HVM domains")
    69.6  
    69.7 -if not os.path.exists("/dev/tpm0"):
    69.8 -    SKIP("This machine has no hardware TPM; cannot run this test")
    69.9 -
   69.10  status, output = traceCommand("ps aux | grep vtpm_manager | grep -v grep")
   69.11  if output == "":
   69.12 -    FAIL("virtual TPM manager must be started to run this test")
   69.13 +    SKIP("virtual TPM manager must be started to run this test; might "
   69.14 +         "need /dev/tpm0")
   69.15  
   69.16  def vtpm_cleanup(domName):
   69.17      traceCommand("/etc/xen/scripts/vtpm-delete %s" % domName)
    70.1 --- a/xen/arch/ia64/Makefile	Sun Oct 01 11:39:41 2006 -0600
    70.2 +++ b/xen/arch/ia64/Makefile	Sun Oct 01 19:10:18 2006 -0600
    70.3 @@ -4,22 +4,27 @@ subdir-y += linux
    70.4  subdir-y += linux-xen
    70.5  
    70.6  $(TARGET)-syms: linux-xen/head.o $(ALL_OBJS) xen.lds.s
    70.7 +	$(MAKE) -f $(BASEDIR)/Rules.mk $(BASEDIR)/common/symbols-dummy.o
    70.8  	$(LD) $(LDFLAGS) -T xen.lds.s -N \
    70.9 -		-Map map.out linux-xen/head.o $(ALL_OBJS) -o $@
   70.10 +		-Map map.out linux-xen/head.o $(ALL_OBJS) \
   70.11 +		$(BASEDIR)/common/symbols-dummy.o -o $@
   70.12  	$(NM) -n $@ | $(BASEDIR)/tools/symbols > $(BASEDIR)/xen-syms.S
   70.13  	$(MAKE) -f $(BASEDIR)/Rules.mk $(BASEDIR)/xen-syms.o
   70.14  	$(LD) $(LDFLAGS) -T xen.lds.s -N \
   70.15 -		-Map map.out linux-xen/head.o $(ALL_OBJS) $(BASEDIR)/xen-syms.o -o $@
   70.16 +		-Map map.out linux-xen/head.o $(ALL_OBJS) \
   70.17 +		$(BASEDIR)/xen-syms.o -o $@
   70.18  	$(NM) -n $@ | $(BASEDIR)/tools/symbols >$(BASEDIR)/xen-syms.S
   70.19  	$(MAKE) -f $(BASEDIR)/Rules.mk $(BASEDIR)/xen-syms.o
   70.20  	$(LD) $(LDFLAGS) -T xen.lds.s -N \
   70.21 -		-Map map.out linux-xen/head.o $(ALL_OBJS) $(BASEDIR)/xen-syms.o -o $@
   70.22 +		-Map map.out linux-xen/head.o $(ALL_OBJS) \
   70.23 +		$(BASEDIR)/xen-syms.o -o $@
   70.24  	rm -f $(BASEDIR)/xen-syms.S $(BASEDIR)/xen-syms.o
   70.25  
   70.26  $(TARGET): $(TARGET)-syms
   70.27  	$(OBJCOPY) -R .note -R .comment -S $(TARGET)-syms $@
   70.28 -	$(NM) -n $(TARGET)-syms | grep -v '\( [aUw] \)\|\(__crc_\)\|\( \$[adt]\)'\
   70.29 -		 > $(BASEDIR)/System.map
   70.30 +	$(NM) -n $(TARGET)-syms | \
   70.31 +		grep -v '\( [aUw] \)\|\(__crc_\)\|\( \$[adt]\)' \
   70.32 +		> $(BASEDIR)/System.map
   70.33  
   70.34  # Headers do not depend on auto-generated header, but object files do.
   70.35  HDRS    := $(subst $(BASEDIR)/include/asm-ia64/asm-xsi-offsets.h,,$(HDRS))
    71.1 --- a/xen/arch/powerpc/Makefile	Sun Oct 01 11:39:41 2006 -0600
    71.2 +++ b/xen/arch/powerpc/Makefile	Sun Oct 01 19:10:18 2006 -0600
    71.3 @@ -101,7 +101,8 @@ TARGET_OPTS = $(OMAGIC) -Wl,-Ttext,$(xen
    71.4  TARGET_OPTS += start.o $(ALL_OBJS)
    71.5  
    71.6  .xen-syms: start.o $(ALL_OBJS) xen.lds
    71.7 -	$(CC) $(CFLAGS) $(TARGET_OPTS) -o $@
    71.8 +	$(MAKE) -f $(BASEDIR)/Rules.mk $(BASEDIR)/common/symbols-dummy.o
    71.9 +	$(CC) $(CFLAGS) $(TARGET_OPTS) $(BASEDIR)/common/symbols-dummy.o -o $@
   71.10  
   71.11  NM=$(CROSS_COMPILE)nm
   71.12  new_nm := $(shell if $(NM) --help 2>&1 | grep -- '--synthetic' > /dev/null; then echo y; else echo n; fi)
    72.1 --- a/xen/arch/x86/Makefile	Sun Oct 01 11:39:41 2006 -0600
    72.2 +++ b/xen/arch/x86/Makefile	Sun Oct 01 19:10:18 2006 -0600
    72.3 @@ -46,19 +46,24 @@ obj-$(crash_debug) += gdbstub.o
    72.4  
    72.5  $(TARGET): $(TARGET)-syms boot/mkelf32
    72.6  	./boot/mkelf32 $(TARGET)-syms $(TARGET) 0x100000 \
    72.7 -	`$(NM) $(TARGET)-syms | sort | tail -n 1 | sed -e 's/^\([^ ]*\).*/0x\1/'`
    72.8 +	`$(NM) $(TARGET)-syms | sort | tail -n 1 | \
    72.9 +	 sed -e 's/^\([^ ]*\).*/0x\1/'`
   72.10  
   72.11  $(TARGET)-syms: boot/$(TARGET_SUBARCH).o $(ALL_OBJS) xen.lds
   72.12 +	$(MAKE) -f $(BASEDIR)/Rules.mk $(BASEDIR)/common/symbols-dummy.o
   72.13  	$(LD) $(LDFLAGS) -T xen.lds -N \
   72.14 -	    boot/$(TARGET_SUBARCH).o $(ALL_OBJS) -o $@
   72.15 +	    boot/$(TARGET_SUBARCH).o $(ALL_OBJS) \
   72.16 +	    $(BASEDIR)/common/symbols-dummy.o -o $@
   72.17  	$(NM) -n $@ | $(BASEDIR)/tools/symbols >$(BASEDIR)/xen-syms.S
   72.18  	$(MAKE) -f $(BASEDIR)/Rules.mk $(BASEDIR)/xen-syms.o
   72.19  	$(LD) $(LDFLAGS) -T xen.lds -N \
   72.20 -	    boot/$(TARGET_SUBARCH).o $(ALL_OBJS) $(BASEDIR)/xen-syms.o -o $@
   72.21 +	    boot/$(TARGET_SUBARCH).o $(ALL_OBJS) \
   72.22 +	    $(BASEDIR)/xen-syms.o -o $@
   72.23  	$(NM) -n $@ | $(BASEDIR)/tools/symbols >$(BASEDIR)/xen-syms.S
   72.24  	$(MAKE) -f $(BASEDIR)/Rules.mk $(BASEDIR)/xen-syms.o
   72.25  	$(LD) $(LDFLAGS) -T xen.lds -N \
   72.26 -	    boot/$(TARGET_SUBARCH).o $(ALL_OBJS) $(BASEDIR)/xen-syms.o -o $@
   72.27 +	    boot/$(TARGET_SUBARCH).o $(ALL_OBJS) \
   72.28 +	    $(BASEDIR)/xen-syms.o -o $@
   72.29  	rm -f $(BASEDIR)/xen-syms.S $(BASEDIR)/xen-syms.o
   72.30  
   72.31  asm-offsets.s: $(TARGET_SUBARCH)/asm-offsets.c $(HDRS)
    73.1 --- a/xen/arch/x86/domain.c	Sun Oct 01 11:39:41 2006 -0600
    73.2 +++ b/xen/arch/x86/domain.c	Sun Oct 01 19:10:18 2006 -0600
    73.3 @@ -334,8 +334,10 @@ int arch_set_info_guest(
    73.4      }
    73.5      else
    73.6      {
    73.7 -        if ( !get_page_and_type(mfn_to_page(cr3_pfn), d,
    73.8 -                                PGT_base_page_table) )
    73.9 +        if ( shadow_mode_refcounts(d)
   73.10 +             ? !get_page(mfn_to_page(cr3_pfn), d)
   73.11 +             : !get_page_and_type(mfn_to_page(cr3_pfn), d,
   73.12 +                                  PGT_base_page_table) )
   73.13          {
   73.14              destroy_gdt(v);
   73.15              return -EINVAL;
   73.16 @@ -952,7 +954,10 @@ void domain_relinquish_resources(struct 
   73.17          pfn = pagetable_get_pfn(v->arch.guest_table_user);
   73.18          if ( pfn != 0 )
   73.19          {
   73.20 -            put_page_and_type(mfn_to_page(pfn));
   73.21 +            if ( shadow_mode_refcounts(d) )
   73.22 +                put_page(mfn_to_page(pfn));
   73.23 +            else
   73.24 +                put_page_and_type(mfn_to_page(pfn));
   73.25              v->arch.guest_table_user = pagetable_null();
   73.26          }
   73.27  #endif
    74.1 --- a/xen/arch/x86/hvm/hvm.c	Sun Oct 01 11:39:41 2006 -0600
    74.2 +++ b/xen/arch/x86/hvm/hvm.c	Sun Oct 01 19:10:18 2006 -0600
    74.3 @@ -389,42 +389,68 @@ void hvm_hlt(unsigned long rflags)
    74.4  }
    74.5  
    74.6  /*
    74.7 - * Copy from/to guest virtual.
    74.8 + * __hvm_copy():
    74.9 + *  @buf  = hypervisor buffer
   74.10 + *  @addr = guest virtual or physical address to copy to/from
   74.11 + *  @size = number of bytes to copy
   74.12 + *  @dir  = copy *to* guest (TRUE) or *from* guest (FALSE)?
   74.13 + *  @phy  = interpret addr as physical (TRUE) or virtual (FALSE) address?
   74.14 + * Returns number of bytes failed to copy (0 == complete success).
   74.15   */
   74.16 -int hvm_copy(void *buf, unsigned long vaddr, int size, int dir)
   74.17 +static int __hvm_copy(
   74.18 +    void *buf, unsigned long addr, int size, int dir, int phy)
   74.19  {
   74.20      struct vcpu *v = current;
   74.21 -    unsigned long gfn;
   74.22      unsigned long mfn;
   74.23 -    char *addr;
   74.24 -    int count;
   74.25 +    char *p;
   74.26 +    int count, todo;
   74.27  
   74.28 -    while (size > 0) {
   74.29 -        count = PAGE_SIZE - (vaddr & ~PAGE_MASK);
   74.30 -        if (count > size)
   74.31 -            count = size;
   74.32 -
   74.33 -        gfn = shadow_gva_to_gfn(v, vaddr);
   74.34 -        mfn = mfn_x(sh_vcpu_gfn_to_mfn(v, gfn));
   74.35 +    todo = size;
   74.36 +    while ( todo > 0 )
   74.37 +    {
   74.38 +        count = min_t(int, PAGE_SIZE - (addr & ~PAGE_MASK), todo);
   74.39  
   74.40 -        if (mfn == INVALID_MFN)
   74.41 -            return 0;
   74.42 +        mfn = phy ? 
   74.43 +            get_mfn_from_gpfn(addr >> PAGE_SHIFT) :
   74.44 +            mfn_x(sh_vcpu_gfn_to_mfn(v, shadow_gva_to_gfn(v, addr)));
   74.45 +        if ( mfn == INVALID_MFN )
   74.46 +            return todo;
   74.47  
   74.48 -        addr = (char *)map_domain_page(mfn) + (vaddr & ~PAGE_MASK);
   74.49 +        p = (char *)map_domain_page(mfn) + (addr & ~PAGE_MASK);
   74.50  
   74.51 -        if (dir == HVM_COPY_IN)
   74.52 -            memcpy(buf, addr, count);
   74.53 +        if ( dir )
   74.54 +            memcpy(p, buf, count); /* dir == TRUE:  *to* guest */
   74.55          else
   74.56 -            memcpy(addr, buf, count);
   74.57 +            memcpy(buf, p, count); /* dir == FALSE: *from guest */
   74.58  
   74.59 -        unmap_domain_page(addr);
   74.60 +        unmap_domain_page(p);
   74.61  
   74.62 -        vaddr += count;
   74.63 -        buf += count;
   74.64 -        size -= count;
   74.65 +        addr += count;
   74.66 +        buf  += count;
   74.67 +        todo -= count;
   74.68      }
   74.69  
   74.70 -    return 1;
   74.71 +    return 0;
   74.72 +}
   74.73 +
   74.74 +int hvm_copy_to_guest_phys(unsigned long paddr, void *buf, int size)
   74.75 +{
   74.76 +    return __hvm_copy(buf, paddr, size, 1, 1);
   74.77 +}
   74.78 +
   74.79 +int hvm_copy_from_guest_phys(void *buf, unsigned long paddr, int size)
   74.80 +{
   74.81 +    return __hvm_copy(buf, paddr, size, 0, 1);
   74.82 +}
   74.83 +
   74.84 +int hvm_copy_to_guest_virt(unsigned long vaddr, void *buf, int size)
   74.85 +{
   74.86 +    return __hvm_copy(buf, vaddr, size, 1, 0);
   74.87 +}
   74.88 +
   74.89 +int hvm_copy_from_guest_virt(void *buf, unsigned long vaddr, int size)
   74.90 +{
   74.91 +    return __hvm_copy(buf, vaddr, size, 0, 0);
   74.92  }
   74.93  
   74.94  /*
    75.1 --- a/xen/arch/x86/hvm/i8259.c	Sun Oct 01 11:39:41 2006 -0600
    75.2 +++ b/xen/arch/x86/hvm/i8259.c	Sun Oct 01 19:10:18 2006 -0600
    75.3 @@ -86,7 +86,7 @@ static int pic_get_irq(PicState *s)
    75.4  
    75.5      ASSERT(spin_is_locked(&s->pics_state->lock));
    75.6  
    75.7 -    mask = s->irr & ~s->imr;
    75.8 +    mask = (s->irr|s->irr_xen) & ~s->imr;
    75.9      priority = get_priority(s, mask);
   75.10      if (priority == 8)
   75.11          return -1;
   75.12 @@ -128,6 +128,32 @@ void pic_update_irq(struct hvm_virpic *s
   75.13      }
   75.14  }
   75.15  
   75.16 +void pic_set_xen_irq(void *opaque, int irq, int level)
   75.17 +{
   75.18 +    struct hvm_virpic *s = opaque;
   75.19 +    unsigned long flags;
   75.20 +    PicState *ps;
   75.21 +
   75.22 +    spin_lock_irqsave(&s->lock, flags);
   75.23 +
   75.24 +    hvm_vioapic_set_xen_irq(current->domain, irq, level);
   75.25 +
   75.26 +    /* Set it on the 8259s */
   75.27 +    ps = &s->pics[irq >> 3];
   75.28 +    if (!(ps->elcr & (1 << (irq & 7)))) {
   75.29 +	DPRINTK("edge-triggered override IRQ?\n");
   75.30 +	domain_crash(current->domain);
   75.31 +    }
   75.32 +    if (level) {
   75.33 +	ps->irr_xen |= 1 << (irq & 7);
   75.34 +    } else {
   75.35 +	ps->irr_xen &= ~(1 << (irq & 7));
   75.36 +    }
   75.37 +
   75.38 +    pic_update_irq(s);
   75.39 +    spin_unlock_irqrestore(&s->lock, flags);
   75.40 +}
   75.41 +
   75.42  void pic_set_irq_new(void *opaque, int irq, int level)
   75.43  {
   75.44      struct hvm_virpic *s = opaque;
   75.45 @@ -136,9 +162,6 @@ void pic_set_irq_new(void *opaque, int i
   75.46      spin_lock_irqsave(&s->lock, flags);
   75.47      hvm_vioapic_set_irq(current->domain, irq, level);
   75.48      pic_set_irq1(&s->pics[irq >> 3], irq & 7, level);
   75.49 -    /* used for IOAPIC irqs */
   75.50 -    if (s->alt_irq_func)
   75.51 -        s->alt_irq_func(s->alt_irq_opaque, irq, level);
   75.52      pic_update_irq(s);
   75.53      spin_unlock_irqrestore(&s->lock, flags);
   75.54  }
   75.55 @@ -371,6 +394,7 @@ static uint32_t pic_poll_read (PicState 
   75.56              s->pics_state->pics[0].irr &= ~(1 << 2);
   75.57          }
   75.58          s->irr &= ~(1 << ret);
   75.59 +        s->irr_xen &= ~(1 << ret);
   75.60          s->isr &= ~(1 << ret);
   75.61          if (addr1 >> 7 || ret != 2)
   75.62              pic_update_irq(s->pics_state);
   75.63 @@ -400,7 +424,7 @@ static uint32_t pic_ioport_read(void *op
   75.64              if (s->read_reg_select)
   75.65                  ret = s->isr;
   75.66              else
   75.67 -                ret = s->irr;
   75.68 +                ret = s->irr | s->irr_xen;
   75.69          } else {
   75.70              ret = s->imr;
   75.71          }
   75.72 @@ -472,18 +496,6 @@ void pic_init(struct hvm_virpic *s, void
   75.73      s->irq_request_opaque = irq_request_opaque;
   75.74  }
   75.75  
   75.76 -void pic_set_alt_irq_func(struct hvm_virpic *s,
   75.77 -                          void (*alt_irq_func)(void *, int, int),
   75.78 -                          void *alt_irq_opaque)
   75.79 -{
   75.80 -    unsigned long flags;
   75.81 -
   75.82 -    spin_lock_irqsave(&s->lock, flags);
   75.83 -    s->alt_irq_func = alt_irq_func;
   75.84 -    s->alt_irq_opaque = alt_irq_opaque;
   75.85 -    spin_unlock_irqrestore(&s->lock, flags);
   75.86 -}
   75.87 -
   75.88  static int intercept_pic_io(ioreq_t *p)
   75.89  {
   75.90      struct hvm_virpic  *pic;
   75.91 @@ -497,8 +509,9 @@ static int intercept_pic_io(ioreq_t *p)
   75.92      }
   75.93      pic = &v->domain->arch.hvm_domain.vpic;
   75.94      if ( p->dir == 0 ) {
   75.95 -        if(p->pdata_valid) 
   75.96 -            hvm_copy(&data, (unsigned long)p->u.pdata, p->size, HVM_COPY_IN);
   75.97 +        if (p->pdata_valid) 
   75.98 +            (void)hvm_copy_from_guest_virt(
   75.99 +                &data, (unsigned long)p->u.pdata, p->size);
  75.100          else
  75.101              data = p->u.data;
  75.102          spin_lock_irqsave(&pic->lock, flags);
  75.103 @@ -511,8 +524,9 @@ static int intercept_pic_io(ioreq_t *p)
  75.104          data = pic_ioport_read(
  75.105              (void*)&pic->pics[p->addr>>7], (uint32_t) p->addr);
  75.106          spin_unlock_irqrestore(&pic->lock, flags);
  75.107 -        if(p->pdata_valid) 
  75.108 -            hvm_copy(&data, (unsigned long)p->u.pdata, p->size, HVM_COPY_OUT);
  75.109 +        if (p->pdata_valid) 
  75.110 +            (void)hvm_copy_to_guest_virt(
  75.111 +                (unsigned long)p->u.pdata, &data, p->size);
  75.112          else 
  75.113              p->u.data = (u64)data;
  75.114      }
  75.115 @@ -533,8 +547,9 @@ static int intercept_elcr_io(ioreq_t *p)
  75.116  
  75.117      s = &v->domain->arch.hvm_domain.vpic;
  75.118      if ( p->dir == 0 ) {
  75.119 -        if(p->pdata_valid) 
  75.120 -            hvm_copy(&data, (unsigned long)p->u.pdata, p->size, HVM_COPY_IN);
  75.121 +        if (p->pdata_valid) 
  75.122 +            (void)hvm_copy_from_guest_virt(
  75.123 +                &data, (unsigned long)p->u.pdata, p->size);
  75.124          else
  75.125              data = p->u.data;
  75.126          spin_lock_irqsave(&s->lock, flags);
  75.127 @@ -547,8 +562,9 @@ static int intercept_elcr_io(ioreq_t *p)
  75.128      else {
  75.129          data = (u64) elcr_ioport_read(
  75.130                  (void*)&s->pics[p->addr&1], (uint32_t) p->addr);
  75.131 -        if(p->pdata_valid) 
  75.132 -            hvm_copy(&data, (unsigned long)p->u.pdata, p->size, HVM_COPY_OUT);
  75.133 +        if (p->pdata_valid) 
  75.134 +            (void)hvm_copy_to_guest_virt(
  75.135 +                (unsigned long)p->u.pdata, &data, p->size);
  75.136          else 
  75.137              p->u.data = (u64)data;
  75.138  
    76.1 --- a/xen/arch/x86/hvm/instrlen.c	Sun Oct 01 11:39:41 2006 -0600
    76.2 +++ b/xen/arch/x86/hvm/instrlen.c	Sun Oct 01 19:10:18 2006 -0600
    76.3 @@ -196,26 +196,17 @@ static uint8_t twobyte_table[256] = {
    76.4  
    76.5  /* 
    76.6   * insn_fetch - fetch the next 1 to 4 bytes from instruction stream 
    76.7 - * 
    76.8   * @_type:   u8, u16, u32, s8, s16, or s32
    76.9   * @_size:   1, 2, or 4 bytes
   76.10 - * @_eip:    address to fetch from guest memory
   76.11 - * @_length: increments the current instruction length counter by _size
   76.12 - *
   76.13 - * This is used internally by hvm_instruction_length to fetch the next byte,
   76.14 - * word, or dword from guest memory at location _eip.  we currently use a local
   76.15 - * unsigned long as the storage buffer since the most bytes we're gonna get
   76.16 - * is limited to 4.
   76.17   */
   76.18 -#define insn_fetch(_type, _size, _eip, _length)                         \
   76.19 -({  unsigned long _x;                                                   \
   76.20 -        if ((rc = inst_copy_from_guest((unsigned char *)(&(_x)),        \
   76.21 -                (unsigned long)(_eip), _size))                          \
   76.22 -                    != _size)                                           \
   76.23 -        goto done;                                                      \
   76.24 -    (_eip) += (_size);                                                  \
   76.25 -    (_length) += (_size);                                               \
   76.26 -    (_type)_x;                                                          \
   76.27 +#define insn_fetch(_type, _size)                                        \
   76.28 +({ unsigned long _x, _ptr = _regs.eip;                                  \
   76.29 +   if ( mode == X86EMUL_MODE_REAL ) _ptr += _regs.cs << 4;              \
   76.30 +   rc = inst_copy_from_guest((unsigned char *)(&(_x)), _ptr, _size);    \
   76.31 +   if ( rc != _size ) goto done;                                        \
   76.32 +   _regs.eip += (_size);                                                \
   76.33 +   length += (_size);                                                   \
   76.34 +   (_type)_x;                                                           \
   76.35  })
   76.36  
   76.37  /**
   76.38 @@ -231,7 +222,7 @@ int hvm_instruction_length(struct cpu_us
   76.39  {
   76.40      uint8_t b, d, twobyte = 0, rex_prefix = 0;
   76.41      uint8_t modrm, modrm_mod = 0, modrm_reg = 0, modrm_rm = 0;
   76.42 -    unsigned int op_bytes, ad_bytes, lock_prefix = 0, rep_prefix = 0, i;
   76.43 +    unsigned int op_bytes, ad_bytes, i;
   76.44      int rc = 0;
   76.45      int length = 0;
   76.46      unsigned int tmp;
   76.47 @@ -239,10 +230,6 @@ int hvm_instruction_length(struct cpu_us
   76.48      /* Shadow copy of register state. Committed on successful emulation. */
   76.49      struct cpu_user_regs _regs = *regs;
   76.50  
   76.51 -    /* include CS for 16-bit modes */
   76.52 -    if (mode == X86EMUL_MODE_REAL || mode == X86EMUL_MODE_PROT16)
   76.53 -        _regs.eip += (_regs.cs << 4);
   76.54 -
   76.55      switch ( mode )
   76.56      {
   76.57      case X86EMUL_MODE_REAL:
   76.58 @@ -265,7 +252,7 @@ int hvm_instruction_length(struct cpu_us
   76.59      /* Legacy prefixes. */
   76.60      for ( i = 0; i < 8; i++ )
   76.61      {
   76.62 -        switch ( b = insn_fetch(uint8_t, 1, _regs.eip, length) )
   76.63 +        switch ( b = insn_fetch(uint8_t, 1) )
   76.64          {
   76.65          case 0x66: /* operand-size override */
   76.66              op_bytes ^= 6;      /* switch between 2/4 bytes */
   76.67 @@ -282,13 +269,8 @@ int hvm_instruction_length(struct cpu_us
   76.68          case 0x64: /* FS override */
   76.69          case 0x65: /* GS override */
   76.70          case 0x36: /* SS override */
   76.71 -            break;
   76.72          case 0xf0: /* LOCK */
   76.73 -            lock_prefix = 1;
   76.74 -            break;
   76.75          case 0xf3: /* REP/REPE/REPZ */
   76.76 -            rep_prefix = 1;
   76.77 -            break;
   76.78          case 0xf2: /* REPNE/REPNZ */
   76.79              break;
   76.80          default:
   76.81 @@ -297,12 +279,6 @@ int hvm_instruction_length(struct cpu_us
   76.82      }
   76.83  done_prefixes:
   76.84  
   76.85 -    /* Note quite the same as 80386 real mode, but hopefully good enough. */
   76.86 -    if ( (mode == X86EMUL_MODE_REAL) && (ad_bytes != 2) ) {
   76.87 -        printf("sonofabitch!! we don't support 32-bit addresses in realmode\n");
   76.88 -        goto cannot_emulate;
   76.89 -    }
   76.90 -
   76.91      /* REX prefix. */
   76.92      if ( (mode == X86EMUL_MODE_PROT64) && ((b & 0xf0) == 0x40) )
   76.93      {
   76.94 @@ -311,7 +287,7 @@ done_prefixes:
   76.95              op_bytes = 8;          /* REX.W */
   76.96          modrm_reg = (b & 4) << 1;  /* REX.R */
   76.97          /* REX.B and REX.X do not need to be decoded. */
   76.98 -        b = insn_fetch(uint8_t, 1, _regs.eip, length);
   76.99 +        b = insn_fetch(uint8_t, 1);
  76.100      }
  76.101  
  76.102      /* Opcode byte(s). */
  76.103 @@ -322,7 +298,7 @@ done_prefixes:
  76.104          if ( b == 0x0f )
  76.105          {
  76.106              twobyte = 1;
  76.107 -            b = insn_fetch(uint8_t, 1, _regs.eip, length);
  76.108 +            b = insn_fetch(uint8_t, 1);
  76.109              d = twobyte_table[b];
  76.110          }
  76.111  
  76.112 @@ -334,7 +310,7 @@ done_prefixes:
  76.113      /* ModRM and SIB bytes. */
  76.114      if ( d & ModRM )
  76.115      {
  76.116 -        modrm = insn_fetch(uint8_t, 1, _regs.eip, length);
  76.117 +        modrm = insn_fetch(uint8_t, 1);
  76.118          modrm_mod |= (modrm & 0xc0) >> 6;
  76.119          modrm_reg |= (modrm & 0x38) >> 3;
  76.120          modrm_rm  |= (modrm & 0x07);
  76.121 @@ -374,7 +350,7 @@ done_prefixes:
  76.122              {
  76.123              case 0:
  76.124                  if ( (modrm_rm == 4) && 
  76.125 -                     (((insn_fetch(uint8_t, 1, _regs.eip, length)) & 7) 
  76.126 +                     (((insn_fetch(uint8_t, 1)) & 7) 
  76.127                          == 5) )
  76.128                  {
  76.129                      length += 4;
  76.130 @@ -389,7 +365,7 @@ done_prefixes:
  76.131              case 1:
  76.132                  if ( modrm_rm == 4 )
  76.133                  {
  76.134 -                    insn_fetch(uint8_t, 1, _regs.eip, length);
  76.135 +                    insn_fetch(uint8_t, 1);
  76.136                  }
  76.137                  length += 1;
  76.138                  _regs.eip += 1; /* skip disp8 */
  76.139 @@ -397,7 +373,7 @@ done_prefixes:
  76.140              case 2:
  76.141                  if ( modrm_rm == 4 )
  76.142                  {
  76.143 -                    insn_fetch(uint8_t, 1, _regs.eip, length);
  76.144 +                    insn_fetch(uint8_t, 1);
  76.145                  }
  76.146                  length += 4;
  76.147                  _regs.eip += 4; /* skip disp32 */
  76.148 @@ -423,13 +399,13 @@ done_prefixes:
  76.149          /* NB. Immediates are sign-extended as necessary. */
  76.150          switch ( tmp )
  76.151          {
  76.152 -        case 1: insn_fetch(int8_t,  1, _regs.eip, length); break;
  76.153 -        case 2: insn_fetch(int16_t, 2, _regs.eip, length); break;
  76.154 -        case 4: insn_fetch(int32_t, 4, _regs.eip, length); break;
  76.155 +        case 1: insn_fetch(int8_t,  1); break;
  76.156 +        case 2: insn_fetch(int16_t, 2); break;
  76.157 +        case 4: insn_fetch(int32_t, 4); break;
  76.158          }
  76.159          break;
  76.160      case SrcImmByte:
  76.161 -        insn_fetch(int8_t,  1, _regs.eip, length);
  76.162 +        insn_fetch(int8_t,  1);
  76.163          break;
  76.164      }
  76.165  
  76.166 @@ -455,9 +431,9 @@ done_prefixes:
  76.167              if ( tmp == 8 ) tmp = 4;
  76.168              switch ( tmp )
  76.169              {
  76.170 -            case 1: insn_fetch(int8_t,  1, _regs.eip, length); break;
  76.171 -            case 2: insn_fetch(int16_t, 2, _regs.eip, length); break;
  76.172 -            case 4: insn_fetch(int32_t, 4, _regs.eip, length); break;
  76.173 +            case 1: insn_fetch(int8_t,  1); break;
  76.174 +            case 2: insn_fetch(int16_t, 2); break;
  76.175 +            case 4: insn_fetch(int32_t, 4); break;
  76.176              }
  76.177              goto done;
  76.178          }
    77.1 --- a/xen/arch/x86/hvm/intercept.c	Sun Oct 01 11:39:41 2006 -0600
    77.2 +++ b/xen/arch/x86/hvm/intercept.c	Sun Oct 01 19:10:18 2006 -0600
    77.3 @@ -90,17 +90,17 @@ static inline void hvm_mmio_access(struc
    77.4                      data = read_handler(v,
    77.5                        req->addr + (sign * i * req->size),
    77.6                        req->size);
    77.7 -                    hvm_copy(&data,
    77.8 -                      (unsigned long)p->u.pdata + (sign * i * req->size),
    77.9 -                      p->size,
   77.10 -                      HVM_COPY_OUT);
   77.11 +                    (void)hvm_copy_to_guest_virt(
   77.12 +                        (unsigned long)p->u.pdata + (sign * i * req->size),
   77.13 +                        &data,
   77.14 +                        p->size);
   77.15                  }
   77.16              } else {                  /* !req->dir == IOREQ_READ */
   77.17                  for (i = 0; i < req->count; i++) {
   77.18 -                    hvm_copy(&data,
   77.19 -                      (unsigned long)p->u.pdata + (sign * i * req->size),
   77.20 -                      p->size,
   77.21 -                      HVM_COPY_IN);
   77.22 +                    (void)hvm_copy_from_guest_virt(
   77.23 +                        &data,
   77.24 +                        (unsigned long)p->u.pdata + (sign * i * req->size),
   77.25 +                        p->size);
   77.26                      write_handler(v,
   77.27                        req->addr + (sign * i * req->size),
   77.28                        req->size, data);
    78.1 --- a/xen/arch/x86/hvm/io.c	Sun Oct 01 11:39:41 2006 -0600
    78.2 +++ b/xen/arch/x86/hvm/io.c	Sun Oct 01 19:10:18 2006 -0600
    78.3 @@ -379,7 +379,7 @@ static void hvm_pio_assist(struct cpu_us
    78.4                      addr += regs->es << 4;
    78.5                  if (sign > 0)
    78.6                      addr -= p->size;
    78.7 -                hvm_copy(&p->u.data, addr, p->size, HVM_COPY_OUT);
    78.8 +                (void)hvm_copy_to_guest_virt(addr, &p->u.data, p->size);
    78.9              }
   78.10          }
   78.11          else /* p->dir == IOREQ_WRITE */
   78.12 @@ -493,7 +493,7 @@ static void hvm_mmio_assist(struct cpu_u
   78.13  
   78.14              if (sign > 0)
   78.15                  addr -= p->size;
   78.16 -            hvm_copy(&p->u.data, addr, p->size, HVM_COPY_OUT);
   78.17 +            (void)hvm_copy_to_guest_virt(addr, &p->u.data, p->size);
   78.18          }
   78.19  
   78.20          if (mmio_opp->flags & REPZ)
   78.21 @@ -596,6 +596,7 @@ static void hvm_mmio_assist(struct cpu_u
   78.22          break;
   78.23  
   78.24      case INSTR_CMP:
   78.25 +    case INSTR_SUB:
   78.26          if (src & REGISTER) {
   78.27              index = operand_index(src);
   78.28              value = get_reg_value(size, index, 0, regs);
   78.29 @@ -607,6 +608,8 @@ static void hvm_mmio_assist(struct cpu_u
   78.30              index = operand_index(dst);
   78.31              value = get_reg_value(size, index, 0, regs);
   78.32              diff = value - (unsigned long) p->u.data;
   78.33 +            if ( mmio_opp->instr == INSTR_SUB )
   78.34 +                set_reg_value(size, index, 0, regs, diff);
   78.35          }
   78.36  
   78.37          /*
    79.1 --- a/xen/arch/x86/hvm/platform.c	Sun Oct 01 11:39:41 2006 -0600
    79.2 +++ b/xen/arch/x86/hvm/platform.c	Sun Oct 01 19:10:18 2006 -0600
    79.3 @@ -394,6 +394,11 @@ static int hvm_decode(int realmode, unsi
    79.4          GET_OP_SIZE_FOR_NONEBYTE(instr->op_size);
    79.5          return mem_reg(instr->op_size, opcode, instr, rex);
    79.6  
    79.7 +    case 0x2B: /* sub m32/16, r32/16 */
    79.8 +        instr->instr = INSTR_SUB;
    79.9 +        GET_OP_SIZE_FOR_NONEBYTE(instr->op_size);
   79.10 +        return mem_reg(instr->op_size, opcode, instr, rex);
   79.11 +
   79.12      case 0x30: /* xor r8, m8 */
   79.13          instr->instr = INSTR_XOR;
   79.14          instr->op_size = BYTE;
   79.15 @@ -689,7 +694,7 @@ int inst_copy_from_guest(unsigned char *
   79.16  {
   79.17      if (inst_len > MAX_INST_LEN || inst_len <= 0)
   79.18          return 0;
   79.19 -    if (!hvm_copy(buf, guest_eip, inst_len, HVM_COPY_IN))
   79.20 +    if (hvm_copy_from_guest_virt(buf, guest_eip, inst_len))
   79.21          return 0;
   79.22      return inst_len;
   79.23  }
   79.24 @@ -953,7 +958,7 @@ void handle_mmio(unsigned long va, unsig
   79.25              regs->eip -= inst_len; /* do not advance %eip */
   79.26  
   79.27              if (dir == IOREQ_WRITE)
   79.28 -                hvm_copy(&value, addr, size, HVM_COPY_IN);
   79.29 +                (void)hvm_copy_from_guest_virt(&value, addr, size);
   79.30              send_mmio_req(IOREQ_TYPE_COPY, gpa, 1, size, value, dir, 0);
   79.31          } else {
   79.32              if ((addr & PAGE_MASK) != ((addr + sign * (count * size - 1)) & PAGE_MASK)) {
   79.33 @@ -1011,6 +1016,7 @@ void handle_mmio(unsigned long va, unsig
   79.34  
   79.35      case INSTR_CMP:        /* Pass through */
   79.36      case INSTR_TEST:
   79.37 +    case INSTR_SUB:
   79.38          mmio_opp->flags = mmio_inst.flags;
   79.39          mmio_opp->instr = mmio_inst.instr;
   79.40          mmio_opp->operand[0] = mmio_inst.operand[0]; /* source */
   79.41 @@ -1094,7 +1100,7 @@ unsigned long copy_to_user_hvm(void *to,
   79.42          return 0;
   79.43      }
   79.44  
   79.45 -    return !hvm_copy((void *)from, (unsigned long)to, len, HVM_COPY_OUT);
   79.46 +    return hvm_copy_to_guest_virt((unsigned long)to, (void *)from, len);
   79.47  }
   79.48  
   79.49  unsigned long copy_from_user_hvm(void *to, const void *from, unsigned len)
   79.50 @@ -1105,7 +1111,7 @@ unsigned long copy_from_user_hvm(void *t
   79.51          return 0;
   79.52      }
   79.53  
   79.54 -    return !hvm_copy(to, (unsigned long)from, len, HVM_COPY_IN);
   79.55 +    return hvm_copy_from_guest_virt(to, (unsigned long)from, len);
   79.56  }
   79.57  
   79.58  /*
    80.1 --- a/xen/arch/x86/hvm/svm/emulate.c	Sun Oct 01 11:39:41 2006 -0600
    80.2 +++ b/xen/arch/x86/hvm/svm/emulate.c	Sun Oct 01 19:10:18 2006 -0600
    80.3 @@ -341,7 +341,11 @@ unsigned long svm_rip2pointer(struct vmc
    80.4       * %cs is update, but fortunately, base contain the valid base address
    80.5       * no matter what kind of addressing is used.
    80.6       */
    80.7 -    return vmcb->cs.base + vmcb->rip;
    80.8 +    unsigned long p = vmcb->cs.base + vmcb->rip;
    80.9 +    if (!(vmcb->cs.attributes.fields.l && vmcb->efer & EFER_LMA))
   80.10 +        return (u32)p; /* mask to 32 bits */
   80.11 +    /* NB. Should mask to 16 bits if in real mode or 16-bit protected mode. */
   80.12 +    return p;
   80.13  }
   80.14  
   80.15  
    81.1 --- a/xen/arch/x86/hvm/svm/intr.c	Sun Oct 01 11:39:41 2006 -0600
    81.2 +++ b/xen/arch/x86/hvm/svm/intr.c	Sun Oct 01 19:10:18 2006 -0600
    81.3 @@ -74,7 +74,6 @@ asmlinkage void svm_intr_assist(void)
    81.4      int intr_type = APIC_DM_EXTINT;
    81.5      int intr_vector = -1;
    81.6      int re_injecting = 0;
    81.7 -    unsigned long rflags;
    81.8  
    81.9      ASSERT(vmcb);
   81.10  
   81.11 @@ -87,14 +86,6 @@ asmlinkage void svm_intr_assist(void)
   81.12          re_injecting = 1;
   81.13      }
   81.14  
   81.15 -    /* Guest's interrputs masked? */
   81.16 -    rflags = vmcb->rflags;
   81.17 -    if (irq_masked(rflags)) {
   81.18 -        HVM_DBG_LOG(DBG_LEVEL_1, "Guest IRQs masked: rflags: %lx", rflags);
   81.19 -        /* bail out, we won't be injecting an interrupt this time */
   81.20 -        return;
   81.21 -    }
   81.22 -    
   81.23      /* Previous interrupt still pending? */
   81.24      if (vmcb->vintr.fields.irq) {
   81.25  //        printk("Re-injecting IRQ from Vintr\n");
   81.26 @@ -121,13 +112,11 @@ asmlinkage void svm_intr_assist(void)
   81.27            pic_set_irq(pic, pt->irq, 1);
   81.28        }
   81.29  
   81.30 -      callback_irq = v->domain->arch.hvm_domain.params[HVM_PARAM_CALLBACK_IRQ];
   81.31 -      if ( callback_irq != 0 &&
   81.32 -           local_events_need_delivery() ) {
   81.33 -          /*inject para-device call back irq*/
   81.34 -          v->vcpu_info->evtchn_upcall_mask = 1;
   81.35 -          pic_set_irq(pic, callback_irq, 0);
   81.36 -          pic_set_irq(pic, callback_irq, 1);
   81.37 +      if (v->vcpu_id == 0) {
   81.38 +          callback_irq =
   81.39 +              v->domain->arch.hvm_domain.params[HVM_PARAM_CALLBACK_IRQ];
   81.40 +          if ( callback_irq != 0)
   81.41 +              pic_set_xen_irq(pic, callback_irq, local_events_need_delivery());
   81.42        }
   81.43  
   81.44        if ( cpu_has_pending_irq(v) )
    82.1 --- a/xen/arch/x86/hvm/svm/svm.c	Sun Oct 01 11:39:41 2006 -0600
    82.2 +++ b/xen/arch/x86/hvm/svm/svm.c	Sun Oct 01 19:10:18 2006 -0600
    82.3 @@ -57,7 +57,7 @@
    82.4  extern void do_nmi(struct cpu_user_regs *, unsigned long);
    82.5  extern int inst_copy_from_guest(unsigned char *buf, unsigned long guest_eip,
    82.6                                  int inst_len);
    82.7 - extern uint32_t vlapic_update_ppr(struct vlapic *vlapic);
    82.8 +extern uint32_t vlapic_update_ppr(struct vlapic *vlapic);
    82.9  extern asmlinkage void do_IRQ(struct cpu_user_regs *);
   82.10  extern void send_pio_req(struct cpu_user_regs *regs, unsigned long port,
   82.11                           unsigned long count, int size, long value, int dir, int pvalid);
   82.12 @@ -282,7 +282,7 @@ static inline int long_mode_do_msr_read(
   82.13      switch (regs->ecx)
   82.14      {
   82.15      case MSR_EFER:
   82.16 -        msr_content = vmcb->efer;      
   82.17 +        msr_content = vmcb->efer;
   82.18          msr_content &= ~EFER_SVME;
   82.19          break;
   82.20  
   82.21 @@ -320,14 +320,14 @@ static inline int long_mode_do_msr_read(
   82.22      HVM_DBG_LOG(DBG_LEVEL_2, "mode_do_msr_read: msr_content: %"PRIx64"\n", 
   82.23                  msr_content);
   82.24  
   82.25 -    regs->eax = msr_content & 0xffffffff;
   82.26 -    regs->edx = msr_content >> 32;
   82.27 +    regs->eax = (u32)(msr_content >>  0);
   82.28 +    regs->edx = (u32)(msr_content >> 32);
   82.29      return 1;
   82.30  }
   82.31  
   82.32  static inline int long_mode_do_msr_write(struct cpu_user_regs *regs)
   82.33  {
   82.34 -    u64 msr_content = regs->eax | ((u64)regs->edx << 32);
   82.35 +    u64 msr_content = (u32)regs->eax | ((u64)regs->edx << 32);
   82.36      struct vcpu *vc = current;
   82.37      struct vmcb_struct *vmcb = vc->arch.hvm_svm.vmcb;
   82.38  
   82.39 @@ -342,7 +342,8 @@ static inline int long_mode_do_msr_write
   82.40          /* offending reserved bit will cause #GP */
   82.41          if ( msr_content & ~(EFER_LME | EFER_LMA | EFER_NX | EFER_SCE) )
   82.42          {
   82.43 -            printk("trying to set reserved bit in EFER\n");
   82.44 +            printk("Trying to set reserved bit in EFER: %"PRIx64"\n",
   82.45 +                   msr_content);
   82.46              svm_inject_exception(vc, TRAP_gp_fault, 1, 0);
   82.47              return 0;
   82.48          }
   82.49 @@ -355,7 +356,7 @@ static inline int long_mode_do_msr_write
   82.50                   !test_bit(SVM_CPU_STATE_PAE_ENABLED,
   82.51                             &vc->arch.hvm_svm.cpu_state) )
   82.52              {
   82.53 -                printk("trying to set LME bit when "
   82.54 +                printk("Trying to set LME bit when "
   82.55                         "in paging mode or PAE bit is not set\n");
   82.56                  svm_inject_exception(vc, TRAP_gp_fault, 1, 0);
   82.57                  return 0;
   82.58 @@ -903,9 +904,9 @@ static void svm_relinquish_guest_resourc
   82.59  
   82.60          destroy_vmcb(&v->arch.hvm_svm);
   82.61          kill_timer(&v->arch.hvm_vcpu.hlt_timer);
   82.62 -        if ( hvm_apic_support(v->domain) && (VLAPIC(v) != NULL) ) 
   82.63 +        if ( VLAPIC(v) != NULL )
   82.64          {
   82.65 -            kill_timer( &(VLAPIC(v)->vlapic_timer) );
   82.66 +            kill_timer(&VLAPIC(v)->vlapic_timer);
   82.67              unmap_domain_page_global(VLAPIC(v)->regs);
   82.68              free_domheap_page(VLAPIC(v)->regs_page);
   82.69              xfree(VLAPIC(v));
   82.70 @@ -929,12 +930,13 @@ static void svm_migrate_timers(struct vc
   82.71      struct periodic_time *pt = 
   82.72          &(v->domain->arch.hvm_domain.pl_time.periodic_tm);
   82.73  
   82.74 -    if ( pt->enabled ) {
   82.75 -        migrate_timer( &pt->timer, v->processor );
   82.76 -        migrate_timer( &v->arch.hvm_vcpu.hlt_timer, v->processor );
   82.77 +    if ( pt->enabled )
   82.78 +    {
   82.79 +        migrate_timer(&pt->timer, v->processor);
   82.80 +        migrate_timer(&v->arch.hvm_vcpu.hlt_timer, v->processor);
   82.81      }
   82.82 -    if ( hvm_apic_support(v->domain) && VLAPIC( v ))
   82.83 -        migrate_timer( &(VLAPIC(v)->vlapic_timer ), v->processor );
   82.84 +    if ( VLAPIC(v) != NULL )
   82.85 +        migrate_timer(&VLAPIC(v)->vlapic_timer, v->processor);
   82.86  }
   82.87  
   82.88  
   82.89 @@ -1075,9 +1077,6 @@ static void svm_vmexit_do_cpuid(struct v
   82.90                     clear_bit(X86_FEATURE_NX & 31, &edx);
   82.91              }
   82.92              clear_bit(X86_FEATURE_PSE36, &edx);
   82.93 -            /* Disable machine check architecture */
   82.94 -            clear_bit(X86_FEATURE_MCA, &edx);
   82.95 -            clear_bit(X86_FEATURE_MCE, &edx);
   82.96              if (input == 0x00000001 )
   82.97              {
   82.98                  /* Clear out reserved bits. */
   82.99 @@ -1470,7 +1469,7 @@ static void svm_io_instruction(struct vc
  82.100              pio_opp->flags |= OVERLAP;
  82.101  
  82.102              if (dir == IOREQ_WRITE)
  82.103 -                hvm_copy(&value, addr, size, HVM_COPY_IN);
  82.104 +                (void)hvm_copy_from_guest_virt(&value, addr, size);
  82.105  
  82.106              send_pio_req(regs, port, 1, size, value, dir, 0);
  82.107          } 
  82.108 @@ -1636,9 +1635,11 @@ static void mov_from_cr(int cr, int gp, 
  82.109      case 4:
  82.110          value = (unsigned long) v->arch.hvm_svm.cpu_shadow_cr4;
  82.111          if (svm_dbg_on)
  82.112 -            printk( "CR4 read=%lx\n", value );
  82.113 +            printk("CR4 read=%lx\n", value);
  82.114          break;
  82.115      case 8:
  82.116 +        if ( vlapic == NULL )
  82.117 +            break;
  82.118          value = (unsigned long)vlapic_get_reg(vlapic, APIC_TASKPRI);
  82.119          value = (value & 0xF0) >> 4;
  82.120          break;
  82.121 @@ -1816,6 +1817,8 @@ static int mov_to_cr(int gpreg, int cr, 
  82.122  
  82.123      case 8:
  82.124      {
  82.125 +        if ( vlapic == NULL )
  82.126 +            break;
  82.127          vlapic_set_reg(vlapic, APIC_TASKPRI, ((value & 0x0F) << 4));
  82.128          vlapic_update_ppr(vlapic);
  82.129          break;
  82.130 @@ -1997,7 +2000,7 @@ static inline void svm_do_msr_access(
  82.131      else
  82.132      {
  82.133          inst_len = __get_instruction_length(vmcb, INSTR_WRMSR, NULL);
  82.134 -        msr_content = (regs->eax & 0xFFFFFFFF) | ((u64)regs->edx << 32);
  82.135 +        msr_content = (u32)regs->eax | ((u64)regs->edx << 32);
  82.136  
  82.137          switch (regs->ecx)
  82.138          {
  82.139 @@ -2324,7 +2327,7 @@ void svm_dump_inst(unsigned long eip)
  82.140      ptr = eip & ~0xff;
  82.141      len = 0;
  82.142  
  82.143 -    if (hvm_copy(opcode, ptr, sizeof(opcode), HVM_COPY_IN))
  82.144 +    if (hvm_copy_from_guest_virt(opcode, ptr, sizeof(opcode)) == 0)
  82.145          len = sizeof(opcode);
  82.146  
  82.147      printf("Code bytes around(len=%d) %lx:", len, eip);
  82.148 @@ -2563,9 +2566,7 @@ void walk_shadow_and_guest_pt(unsigned l
  82.149  #endif /* SVM_WALK_GUEST_PAGES */
  82.150  
  82.151  
  82.152 -
  82.153 -
  82.154 -asmlinkage void svm_vmexit_handler(struct cpu_user_regs regs)
  82.155 +asmlinkage void svm_vmexit_handler(struct cpu_user_regs *regs)
  82.156  {
  82.157      unsigned int exit_reason;
  82.158      unsigned long eip;
  82.159 @@ -2577,7 +2578,7 @@ asmlinkage void svm_vmexit_handler(struc
  82.160      ASSERT(vmcb);
  82.161  
  82.162      exit_reason = vmcb->exitcode;
  82.163 -    save_svm_cpu_user_regs(v, &regs);
  82.164 +    save_svm_cpu_user_regs(v, regs);
  82.165  
  82.166      vmcb->tlb_control = 1;
  82.167  
  82.168 @@ -2601,26 +2602,26 @@ asmlinkage void svm_vmexit_handler(struc
  82.169              if (svm_paging_enabled(v) && 
  82.170                  !mmio_space(shadow_gva_to_gpa(current, vmcb->exitinfo2)))
  82.171              {
  82.172 -                printk("I%08ld,ExC=%s(%d),IP=%x:%llx,"
  82.173 -                       "I1=%llx,I2=%llx,INT=%llx, "
  82.174 -                       "gpa=%llx\n", intercepts_counter,
  82.175 -                       exit_reasons[exit_reason], exit_reason, regs.cs,
  82.176 -                       (unsigned long long) regs.rip,
  82.177 -                       (unsigned long long) vmcb->exitinfo1,
  82.178 -                       (unsigned long long) vmcb->exitinfo2,
  82.179 -                       (unsigned long long) vmcb->exitintinfo.bytes,
  82.180 -                       (unsigned long long) shadow_gva_to_gpa(current, vmcb->exitinfo2));
  82.181 +                printk("I%08ld,ExC=%s(%d),IP=%x:%"PRIx64","
  82.182 +                       "I1=%"PRIx64",I2=%"PRIx64",INT=%"PRIx64", "
  82.183 +                       "gpa=%"PRIx64"\n", intercepts_counter,
  82.184 +                       exit_reasons[exit_reason], exit_reason, regs->cs,
  82.185 +                       (u64)regs->rip,
  82.186 +                       (u64)vmcb->exitinfo1,
  82.187 +                       (u64)vmcb->exitinfo2,
  82.188 +                       (u64)vmcb->exitintinfo.bytes,
  82.189 +                       (u64)shadow_gva_to_gpa(current, vmcb->exitinfo2));
  82.190              }
  82.191              else 
  82.192              {
  82.193 -                printk("I%08ld,ExC=%s(%d),IP=%x:%llx,"
  82.194 -                       "I1=%llx,I2=%llx,INT=%llx\n", 
  82.195 +                printk("I%08ld,ExC=%s(%d),IP=%x:%"PRIx64","
  82.196 +                       "I1=%"PRIx64",I2=%"PRIx64",INT=%"PRIx64"\n", 
  82.197                         intercepts_counter,
  82.198 -                       exit_reasons[exit_reason], exit_reason, regs.cs,
  82.199 -                       (unsigned long long) regs.rip,
  82.200 -                       (unsigned long long) vmcb->exitinfo1,
  82.201 -                       (unsigned long long) vmcb->exitinfo2,
  82.202 -                       (unsigned long long) vmcb->exitintinfo.bytes );
  82.203 +                       exit_reasons[exit_reason], exit_reason, regs->cs,
  82.204 +                       (u64)regs->rip,
  82.205 +                       (u64)vmcb->exitinfo1,
  82.206 +                       (u64)vmcb->exitinfo2,
  82.207 +                       (u64)vmcb->exitintinfo.bytes );
  82.208              }
  82.209          } 
  82.210          else if ( svm_dbg_on 
  82.211 @@ -2630,24 +2631,24 @@ asmlinkage void svm_vmexit_handler(struc
  82.212  
  82.213              if (exit_reasons[exit_reason])
  82.214              {
  82.215 -                printk("I%08ld,ExC=%s(%d),IP=%x:%llx,"
  82.216 -                       "I1=%llx,I2=%llx,INT=%llx\n", 
  82.217 +                printk("I%08ld,ExC=%s(%d),IP=%x:%"PRIx64","
  82.218 +                       "I1=%"PRIx64",I2=%"PRIx64",INT=%"PRIx64"\n", 
  82.219                         intercepts_counter,
  82.220 -                       exit_reasons[exit_reason], exit_reason, regs.cs,
  82.221 -                       (unsigned long long) regs.rip,
  82.222 -                       (unsigned long long) vmcb->exitinfo1,
  82.223 -                       (unsigned long long) vmcb->exitinfo2,
  82.224 -                       (unsigned long long) vmcb->exitintinfo.bytes);
  82.225 +                       exit_reasons[exit_reason], exit_reason, regs->cs,
  82.226 +                       (u64)regs->rip,
  82.227 +                       (u64)vmcb->exitinfo1,
  82.228 +                       (u64)vmcb->exitinfo2,
  82.229 +                       (u64)vmcb->exitintinfo.bytes);
  82.230              } 
  82.231              else 
  82.232              {
  82.233 -                printk("I%08ld,ExC=%d(0x%x),IP=%x:%llx,"
  82.234 -                       "I1=%llx,I2=%llx,INT=%llx\n", 
  82.235 -                       intercepts_counter, exit_reason, exit_reason, regs.cs, 
  82.236 -                       (unsigned long long) regs.rip,
  82.237 -                       (unsigned long long) vmcb->exitinfo1,
  82.238 -                       (unsigned long long) vmcb->exitinfo2,
  82.239 -                       (unsigned long long) vmcb->exitintinfo.bytes);
  82.240 +                printk("I%08ld,ExC=%d(0x%x),IP=%x:%"PRIx64","
  82.241 +                       "I1=%"PRIx64",I2=%"PRIx64",INT=%"PRIx64"\n", 
  82.242 +                       intercepts_counter, exit_reason, exit_reason, regs->cs, 
  82.243 +                       (u64)regs->rip,
  82.244 +                       (u64)vmcb->exitinfo1,
  82.245 +                       (u64)vmcb->exitinfo2,
  82.246 +                       (u64)vmcb->exitintinfo.bytes);
  82.247              }
  82.248          }
  82.249  
  82.250 @@ -2679,7 +2680,7 @@ asmlinkage void svm_vmexit_handler(struc
  82.251                     (int) v->arch.shadow_table.pfn);
  82.252  
  82.253              svm_dump_vmcb(__func__, vmcb);
  82.254 -            svm_dump_regs(__func__, &regs);
  82.255 +            svm_dump_regs(__func__, regs);
  82.256              svm_dump_inst(svm_rip2pointer(vmcb));
  82.257          }
  82.258  
  82.259 @@ -2709,18 +2710,18 @@ asmlinkage void svm_vmexit_handler(struc
  82.260      case VMEXIT_EXCEPTION_DB:
  82.261      {
  82.262  #ifdef XEN_DEBUGGER
  82.263 -        svm_debug_save_cpu_user_regs(&regs);
  82.264 -        pdb_handle_exception(1, &regs, 1);
  82.265 -        svm_debug_restore_cpu_user_regs(&regs);
  82.266 +        svm_debug_save_cpu_user_regs(regs);
  82.267 +        pdb_handle_exception(1, regs, 1);
  82.268 +        svm_debug_restore_cpu_user_regs(regs);
  82.269  #else
  82.270 -        svm_store_cpu_user_regs(&regs, v);
  82.271 +        svm_store_cpu_user_regs(regs, v);
  82.272          domain_pause_for_debugger();  
  82.273  #endif
  82.274      }
  82.275      break;
  82.276  
  82.277      case VMEXIT_NMI:
  82.278 -        do_nmi(&regs, 0);
  82.279 +        do_nmi(regs, 0);
  82.280          break;
  82.281  
  82.282      case VMEXIT_SMI:
  82.283 @@ -2740,9 +2741,9 @@ asmlinkage void svm_vmexit_handler(struc
  82.284  
  82.285      case VMEXIT_EXCEPTION_BP:
  82.286  #ifdef XEN_DEBUGGER
  82.287 -        svm_debug_save_cpu_user_regs(&regs);
  82.288 -        pdb_handle_exception(3, &regs, 1);
  82.289 -        svm_debug_restore_cpu_user_regs(&regs);
  82.290 +        svm_debug_save_cpu_user_regs(regs);
  82.291 +        pdb_handle_exception(3, regs, 1);
  82.292 +        svm_debug_restore_cpu_user_regs(regs);
  82.293  #else
  82.294          if ( test_bit(_DOMF_debugging, &v->domain->domain_flags) )
  82.295              domain_pause_for_debugger();
  82.296 @@ -2757,25 +2758,25 @@ asmlinkage void svm_vmexit_handler(struc
  82.297  
  82.298      case VMEXIT_EXCEPTION_GP:
  82.299          /* This should probably not be trapped in the future */
  82.300 -        regs.error_code = vmcb->exitinfo1;
  82.301 -        svm_do_general_protection_fault(v, &regs);
  82.302 +        regs->error_code = vmcb->exitinfo1;
  82.303 +        svm_do_general_protection_fault(v, regs);
  82.304          break;  
  82.305  
  82.306      case VMEXIT_EXCEPTION_PF:
  82.307      {
  82.308          unsigned long va;
  82.309          va = vmcb->exitinfo2;
  82.310 -        regs.error_code = vmcb->exitinfo1;
  82.311 +        regs->error_code = vmcb->exitinfo1;
  82.312          HVM_DBG_LOG(DBG_LEVEL_VMMU, 
  82.313                      "eax=%lx, ebx=%lx, ecx=%lx, edx=%lx, esi=%lx, edi=%lx",
  82.314 -                    (unsigned long)regs.eax, (unsigned long)regs.ebx,
  82.315 -                    (unsigned long)regs.ecx, (unsigned long)regs.edx,
  82.316 -                    (unsigned long)regs.esi, (unsigned long)regs.edi);
  82.317 -
  82.318 -        if (!(error = svm_do_page_fault(va, &regs))) 
  82.319 +                    (unsigned long)regs->eax, (unsigned long)regs->ebx,
  82.320 +                    (unsigned long)regs->ecx, (unsigned long)regs->edx,
  82.321 +                    (unsigned long)regs->esi, (unsigned long)regs->edi);
  82.322 +
  82.323 +        if (!(error = svm_do_page_fault(va, regs))) 
  82.324          {
  82.325              /* Inject #PG using Interruption-Information Fields */
  82.326 -            svm_inject_exception(v, TRAP_page_fault, 1, regs.error_code);
  82.327 +            svm_inject_exception(v, TRAP_page_fault, 1, regs->error_code);
  82.328  
  82.329              v->arch.hvm_svm.cpu_cr2 = va;
  82.330              vmcb->cr2 = va;
  82.331 @@ -2788,7 +2789,7 @@ asmlinkage void svm_vmexit_handler(struc
  82.332      case VMEXIT_EXCEPTION_DF:
  82.333          /* Debug info to hopefully help debug WHY the guest double-faulted. */
  82.334          svm_dump_vmcb(__func__, vmcb);
  82.335 -        svm_dump_regs(__func__, &regs);
  82.336 +        svm_dump_regs(__func__, regs);
  82.337          svm_dump_inst(svm_rip2pointer(vmcb));
  82.338          svm_inject_exception(v, TRAP_double_fault, 1, 0);
  82.339          break;
  82.340 @@ -2805,11 +2806,11 @@ asmlinkage void svm_vmexit_handler(struc
  82.341          break;
  82.342  
  82.343      case VMEXIT_TASK_SWITCH:
  82.344 -        __hvm_bug(&regs);
  82.345 +        __hvm_bug(regs);
  82.346          break;
  82.347  
  82.348      case VMEXIT_CPUID:
  82.349 -        svm_vmexit_do_cpuid(vmcb, regs.eax, &regs);
  82.350 +        svm_vmexit_do_cpuid(vmcb, regs->eax, regs);
  82.351          break;
  82.352  
  82.353      case VMEXIT_HLT:
  82.354 @@ -2817,60 +2818,60 @@ asmlinkage void svm_vmexit_handler(struc
  82.355          break;
  82.356  
  82.357      case VMEXIT_INVLPG:
  82.358 -        svm_handle_invlpg(0, &regs);
  82.359 +        svm_handle_invlpg(0, regs);
  82.360          break;
  82.361  
  82.362      case VMEXIT_INVLPGA:
  82.363 -        svm_handle_invlpg(1, &regs);
  82.364 +        svm_handle_invlpg(1, regs);
  82.365          break;
  82.366  
  82.367      case VMEXIT_VMMCALL:
  82.368 -        svm_do_vmmcall(v, &regs);
  82.369 +        svm_do_vmmcall(v, regs);
  82.370          break;
  82.371  
  82.372      case VMEXIT_CR0_READ:
  82.373 -        svm_cr_access(v, 0, TYPE_MOV_FROM_CR, &regs);
  82.374 +        svm_cr_access(v, 0, TYPE_MOV_FROM_CR, regs);
  82.375          break;
  82.376  
  82.377      case VMEXIT_CR2_READ:
  82.378 -        svm_cr_access(v, 2, TYPE_MOV_FROM_CR, &regs);
  82.379 +        svm_cr_access(v, 2, TYPE_MOV_FROM_CR, regs);
  82.380          break;
  82.381  
  82.382      case VMEXIT_CR3_READ:
  82.383 -        svm_cr_access(v, 3, TYPE_MOV_FROM_CR, &regs);
  82.384 +        svm_cr_access(v, 3, TYPE_MOV_FROM_CR, regs);
  82.385          break;
  82.386  
  82.387      case VMEXIT_CR4_READ:
  82.388 -        svm_cr_access(v, 4, TYPE_MOV_FROM_CR, &regs);
  82.389 +        svm_cr_access(v, 4, TYPE_MOV_FROM_CR, regs);
  82.390          break;
  82.391  
  82.392      case VMEXIT_CR8_READ:
  82.393 -        svm_cr_access(v, 8, TYPE_MOV_FROM_CR, &regs);
  82.394 +        svm_cr_access(v, 8, TYPE_MOV_FROM_CR, regs);
  82.395          break;
  82.396  
  82.397      case VMEXIT_CR0_WRITE:
  82.398 -        svm_cr_access(v, 0, TYPE_MOV_TO_CR, &regs);
  82.399 +        svm_cr_access(v, 0, TYPE_MOV_TO_CR, regs);
  82.400          break;
  82.401  
  82.402      case VMEXIT_CR2_WRITE:
  82.403 -        svm_cr_access(v, 2, TYPE_MOV_TO_CR, &regs);
  82.404 +        svm_cr_access(v, 2, TYPE_MOV_TO_CR, regs);
  82.405          break;
  82.406  
  82.407      case VMEXIT_CR3_WRITE:
  82.408 -        svm_cr_access(v, 3, TYPE_MOV_TO_CR, &regs);
  82.409 +        svm_cr_access(v, 3, TYPE_MOV_TO_CR, regs);
  82.410          local_flush_tlb();
  82.411          break;
  82.412  
  82.413      case VMEXIT_CR4_WRITE:
  82.414 -        svm_cr_access(v, 4, TYPE_MOV_TO_CR, &regs);
  82.415 +        svm_cr_access(v, 4, TYPE_MOV_TO_CR, regs);
  82.416          break;
  82.417  
  82.418      case VMEXIT_CR8_WRITE:
  82.419 -        svm_cr_access(v, 8, TYPE_MOV_TO_CR, &regs);
  82.420 +        svm_cr_access(v, 8, TYPE_MOV_TO_CR, regs);
  82.421          break;
  82.422  	
  82.423      case VMEXIT_DR0_WRITE ... VMEXIT_DR7_WRITE:
  82.424 -        svm_dr_access(v, &regs);
  82.425 +        svm_dr_access(v, regs);
  82.426          break;
  82.427  
  82.428      case VMEXIT_IOIO:
  82.429 @@ -2878,7 +2879,7 @@ asmlinkage void svm_vmexit_handler(struc
  82.430          break;
  82.431  
  82.432      case VMEXIT_MSR:
  82.433 -        svm_do_msr_access(v, &regs);
  82.434 +        svm_do_msr_access(v, regs);
  82.435          break;
  82.436  
  82.437      case VMEXIT_SHUTDOWN:
  82.438 @@ -2887,11 +2888,10 @@ asmlinkage void svm_vmexit_handler(struc
  82.439          break;
  82.440  
  82.441      default:
  82.442 -        printk("unexpected VMEXIT: exit reason = 0x%x, exitinfo1 = %llx, "
  82.443 -               "exitinfo2 = %llx\n", exit_reason, 
  82.444 -               (unsigned long long)vmcb->exitinfo1, 
  82.445 -               (unsigned long long)vmcb->exitinfo2);
  82.446 -        __hvm_bug(&regs);       /* should not happen */
  82.447 +        printk("unexpected VMEXIT: exit reason = 0x%x, exitinfo1 = %"PRIx64", "
  82.448 +               "exitinfo2 = %"PRIx64"\n", exit_reason, 
  82.449 +               (u64)vmcb->exitinfo1, (u64)vmcb->exitinfo2);
  82.450 +        __hvm_bug(regs);       /* should not happen */
  82.451          break;
  82.452      }
  82.453  
  82.454 @@ -2899,7 +2899,7 @@ asmlinkage void svm_vmexit_handler(struc
  82.455      if (do_debug) 
  82.456      {
  82.457          printk("%s: Done switch on vmexit_code\n", __func__);
  82.458 -        svm_dump_regs(__func__, &regs);
  82.459 +        svm_dump_regs(__func__, regs);
  82.460      }
  82.461  
  82.462      if (do_debug) 
    83.1 --- a/xen/arch/x86/hvm/svm/x86_32/exits.S	Sun Oct 01 11:39:41 2006 -0600
    83.2 +++ b/xen/arch/x86/hvm/svm/x86_32/exits.S	Sun Oct 01 19:10:18 2006 -0600
    83.3 @@ -126,7 +126,10 @@ ENTRY(svm_asm_do_launch)
    83.4  
    83.5          HVM_SAVE_ALL_NOSEGREGS
    83.6          STGI
    83.7 +        movl %esp,%eax
    83.8 +        push %eax
    83.9          call svm_vmexit_handler
   83.10 +        addl $4,%esp
   83.11          jmp  svm_asm_do_resume
   83.12  
   83.13          ALIGN
    84.1 --- a/xen/arch/x86/hvm/svm/x86_64/exits.S	Sun Oct 01 11:39:41 2006 -0600
    84.2 +++ b/xen/arch/x86/hvm/svm/x86_64/exits.S	Sun Oct 01 19:10:18 2006 -0600
    84.3 @@ -144,6 +144,7 @@ ENTRY(svm_asm_do_launch)
    84.4          VMLOAD
    84.5  
    84.6          STGI
    84.7 +        movq %rsp,%rdi
    84.8          call svm_vmexit_handler
    84.9          jmp  svm_asm_do_resume
   84.10  
    85.1 --- a/xen/arch/x86/hvm/vioapic.c	Sun Oct 01 11:39:41 2006 -0600
    85.2 +++ b/xen/arch/x86/hvm/vioapic.c	Sun Oct 01 19:10:18 2006 -0600
    85.3 @@ -479,7 +479,7 @@ static void ioapic_deliver(hvm_vioapic_t
    85.4  
    85.5  static int ioapic_get_highest_irq(hvm_vioapic_t *s)
    85.6  {
    85.7 -    uint32_t irqs = s->irr & ~s->isr & ~s->imr;
    85.8 +    uint32_t irqs = (s->irr | s->irr_xen) & ~s->isr & ~s->imr;
    85.9      return fls(irqs) - 1;
   85.10  }
   85.11  
   85.12 @@ -501,6 +501,7 @@ static void service_ioapic(hvm_vioapic_t
   85.13          }
   85.14  
   85.15          s->irr &= ~(1 << irqno);
   85.16 +	s->irr_xen &= ~(1 << irqno);
   85.17      }
   85.18  }
   85.19  
   85.20 @@ -526,6 +527,25 @@ void hvm_vioapic_do_irqs_clear(struct do
   85.21      service_ioapic(s);
   85.22  }
   85.23  
   85.24 +void hvm_vioapic_set_xen_irq(struct domain *d, int irq, int level)
   85.25 +{
   85.26 +    hvm_vioapic_t *s = &d->arch.hvm_domain.vioapic;
   85.27 +
   85.28 +    if (!hvm_apic_support(d) || !IOAPICEnabled(s) ||
   85.29 +	s->redirtbl[irq].RedirForm.mask)
   85.30 +        return;
   85.31 +
   85.32 +    if (s->redirtbl[irq].RedirForm.trigmod != IOAPIC_LEVEL_TRIGGER) {
   85.33 +	DPRINTK("Forcing edge triggered APIC irq %d?\n", irq);
   85.34 +	domain_crash(d);
   85.35 +    }
   85.36 +
   85.37 +    if (level)
   85.38 +	s->irr_xen |= 1 << irq;
   85.39 +    else
   85.40 +	s->irr_xen &= ~(1 << irq);
   85.41 +}
   85.42 +
   85.43  void hvm_vioapic_set_irq(struct domain *d, int irq, int level)
   85.44  {
   85.45      hvm_vioapic_t *s = &(d->arch.hvm_domain.vioapic);
    86.1 --- a/xen/arch/x86/hvm/vmx/io.c	Sun Oct 01 11:39:41 2006 -0600
    86.2 +++ b/xen/arch/x86/hvm/vmx/io.c	Sun Oct 01 19:10:18 2006 -0600
    86.3 @@ -78,7 +78,6 @@ asmlinkage void vmx_intr_assist(void)
    86.4      struct hvm_domain *plat=&v->domain->arch.hvm_domain;
    86.5      struct periodic_time *pt = &plat->pl_time.periodic_tm;
    86.6      struct hvm_virpic *pic= &plat->vpic;
    86.7 -    int callback_irq;
    86.8      unsigned int idtv_info_field;
    86.9      unsigned long inst_len;
   86.10      int    has_ext_irq;
   86.11 @@ -91,13 +90,12 @@ asmlinkage void vmx_intr_assist(void)
   86.12          pic_set_irq(pic, pt->irq, 1);
   86.13      }
   86.14  
   86.15 -    callback_irq = v->domain->arch.hvm_domain.params[HVM_PARAM_CALLBACK_IRQ];
   86.16 -    if ( callback_irq != 0 &&
   86.17 -         local_events_need_delivery() ) {
   86.18 -        /*inject para-device call back irq*/
   86.19 -        v->vcpu_info->evtchn_upcall_mask = 1;
   86.20 -        pic_set_irq(pic, callback_irq, 0);
   86.21 -        pic_set_irq(pic, callback_irq, 1);
   86.22 +    if (v->vcpu_id == 0) {
   86.23 +        int callback_irq;
   86.24 +        callback_irq =
   86.25 +            v->domain->arch.hvm_domain.params[HVM_PARAM_CALLBACK_IRQ];
   86.26 +        if ( callback_irq != 0 )
   86.27 +            pic_set_xen_irq(pic, callback_irq, local_events_need_delivery());
   86.28      }
   86.29  
   86.30      has_ext_irq = cpu_has_pending_irq(v);
    87.1 --- a/xen/arch/x86/hvm/vmx/vmx.c	Sun Oct 01 11:39:41 2006 -0600
    87.2 +++ b/xen/arch/x86/hvm/vmx/vmx.c	Sun Oct 01 19:10:18 2006 -0600
    87.3 @@ -135,7 +135,7 @@ static void vmx_relinquish_guest_resourc
    87.4          if ( !test_bit(_VCPUF_initialised, &v->vcpu_flags) )
    87.5              continue;
    87.6          kill_timer(&v->arch.hvm_vcpu.hlt_timer);
    87.7 -        if ( hvm_apic_support(v->domain) && (VLAPIC(v) != NULL) )
    87.8 +        if ( VLAPIC(v) != NULL )
    87.9          {
   87.10              kill_timer(&VLAPIC(v)->vlapic_timer);
   87.11              unmap_domain_page_global(VLAPIC(v)->regs);
   87.12 @@ -269,15 +269,15 @@ static inline int long_mode_do_msr_read(
   87.13  
   87.14      HVM_DBG_LOG(DBG_LEVEL_2, "msr_content: 0x%"PRIx64, msr_content);
   87.15  
   87.16 -    regs->eax = msr_content & 0xffffffff;
   87.17 -    regs->edx = msr_content >> 32;
   87.18 +    regs->eax = (u32)(msr_content >>  0);
   87.19 +    regs->edx = (u32)(msr_content >> 32);
   87.20  
   87.21      return 1;
   87.22  }
   87.23  
   87.24  static inline int long_mode_do_msr_write(struct cpu_user_regs *regs)
   87.25  {
   87.26 -    u64 msr_content = regs->eax | ((u64)regs->edx << 32);
   87.27 +    u64 msr_content = (u32)regs->eax | ((u64)regs->edx << 32);
   87.28      struct vcpu *v = current;
   87.29      struct vmx_msr_state *msr = &v->arch.hvm_vmx.msr_content;
   87.30      struct vmx_msr_state *host_state = &this_cpu(percpu_msr);
   87.31 @@ -290,7 +290,8 @@ static inline int long_mode_do_msr_write
   87.32          /* offending reserved bit will cause #GP */
   87.33          if ( msr_content & ~(EFER_LME | EFER_LMA | EFER_NX | EFER_SCE) )
   87.34          {
   87.35 -            printk("trying to set reserved bit in EFER\n");
   87.36 +            printk("Trying to set reserved bit in EFER: %"PRIx64"\n",
   87.37 +                   msr_content);
   87.38              vmx_inject_hw_exception(v, TRAP_gp_fault, 0);
   87.39              return 0;
   87.40          }
   87.41 @@ -303,7 +304,7 @@ static inline int long_mode_do_msr_write
   87.42                   !test_bit(VMX_CPU_STATE_PAE_ENABLED,
   87.43                             &v->arch.hvm_vmx.cpu_state) )
   87.44              {
   87.45 -                printk("trying to set LME bit when "
   87.46 +                printk("Trying to set LME bit when "
   87.47                         "in paging mode or PAE bit is not set\n");
   87.48                  vmx_inject_hw_exception(v, TRAP_gp_fault, 0);
   87.49                  return 0;
   87.50 @@ -484,20 +485,23 @@ static void vmx_ctxt_switch_to(struct vc
   87.51  
   87.52  static void stop_vmx(void)
   87.53  {
   87.54 -    if (read_cr4() & X86_CR4_VMXE)
   87.55 -        __vmxoff();
   87.56 +    if ( !(read_cr4() & X86_CR4_VMXE) )
   87.57 +        return;
   87.58 +    __vmxoff();
   87.59 +    clear_in_cr4(X86_CR4_VMXE);
   87.60  }
   87.61  
   87.62  void vmx_migrate_timers(struct vcpu *v)
   87.63  {
   87.64      struct periodic_time *pt = &(v->domain->arch.hvm_domain.pl_time.periodic_tm);
   87.65  
   87.66 -    if ( pt->enabled ) {
   87.67 +    if ( pt->enabled )
   87.68 +    {
   87.69          migrate_timer(&pt->timer, v->processor);
   87.70          migrate_timer(&v->arch.hvm_vcpu.hlt_timer, v->processor);
   87.71      }
   87.72 -    if ( hvm_apic_support(v->domain) && VLAPIC(v))
   87.73 -        migrate_timer(&(VLAPIC(v)->vlapic_timer), v->processor);
   87.74 +    if ( VLAPIC(v) != NULL )
   87.75 +        migrate_timer(&VLAPIC(v)->vlapic_timer, v->processor);
   87.76  }
   87.77  
   87.78  static void vmx_store_cpu_guest_regs(
   87.79 @@ -805,12 +809,14 @@ int start_vmx(void)
   87.80  
   87.81      if ( (vmcs = vmx_alloc_host_vmcs()) == NULL )
   87.82      {
   87.83 +        clear_in_cr4(X86_CR4_VMXE);
   87.84          printk("Failed to allocate host VMCS\n");
   87.85          return 0;
   87.86      }
   87.87  
   87.88      if ( __vmxon(virt_to_maddr(vmcs)) )
   87.89      {
   87.90 +        clear_in_cr4(X86_CR4_VMXE);
   87.91          printk("VMXON failed\n");
   87.92          vmx_free_host_vmcs(vmcs);
   87.93          return 0;
   87.94 @@ -1163,7 +1169,7 @@ static void vmx_io_instruction(unsigned 
   87.95  
   87.96              pio_opp->flags |= OVERLAP;
   87.97              if (dir == IOREQ_WRITE)
   87.98 -                hvm_copy(&value, addr, size, HVM_COPY_IN);
   87.99 +                (void)hvm_copy_from_guest_virt(&value, addr, size);
  87.100              send_pio_req(regs, port, 1, size, value, dir, 0);
  87.101          } else {
  87.102              if ((addr & PAGE_MASK) != ((addr + count * size - 1) & PAGE_MASK)) {
  87.103 @@ -1370,7 +1376,8 @@ static int vmx_assist(struct vcpu *v, in
  87.104      u32 cp;
  87.105  
  87.106      /* make sure vmxassist exists (this is not an error) */
  87.107 -    if (!hvm_copy(&magic, VMXASSIST_MAGIC_OFFSET, sizeof(magic), HVM_COPY_IN))
  87.108 +    if (hvm_copy_from_guest_phys(&magic, VMXASSIST_MAGIC_OFFSET,
  87.109 +                                 sizeof(magic)))
  87.110          return 0;
  87.111      if (magic != VMXASSIST_MAGIC)
  87.112          return 0;
  87.113 @@ -1384,20 +1391,20 @@ static int vmx_assist(struct vcpu *v, in
  87.114           */
  87.115      case VMX_ASSIST_INVOKE:
  87.116          /* save the old context */
  87.117 -        if (!hvm_copy(&cp, VMXASSIST_OLD_CONTEXT, sizeof(cp), HVM_COPY_IN))
  87.118 +        if (hvm_copy_from_guest_phys(&cp, VMXASSIST_OLD_CONTEXT, sizeof(cp)))
  87.119              goto error;
  87.120          if (cp != 0) {
  87.121              if (!vmx_world_save(v, &c))
  87.122                  goto error;
  87.123 -            if (!hvm_copy(&c, cp, sizeof(c), HVM_COPY_OUT))
  87.124 +            if (hvm_copy_to_guest_phys(cp, &c, sizeof(c)))
  87.125                  goto error;
  87.126          }
  87.127  
  87.128          /* restore the new context, this should activate vmxassist */
  87.129 -        if (!hvm_copy(&cp, VMXASSIST_NEW_CONTEXT, sizeof(cp), HVM_COPY_IN))
  87.130 +        if (hvm_copy_from_guest_phys(&cp, VMXASSIST_NEW_CONTEXT, sizeof(cp)))
  87.131              goto error;
  87.132          if (cp != 0) {
  87.133 -            if (!hvm_copy(&c, cp, sizeof(c), HVM_COPY_IN))
  87.134 +            if (hvm_copy_from_guest_phys(&c, cp, sizeof(c)))
  87.135                  goto error;
  87.136              if (!vmx_world_restore(v, &c))
  87.137                  goto error;
  87.138 @@ -1411,10 +1418,10 @@ static int vmx_assist(struct vcpu *v, in
  87.139           */
  87.140      case VMX_ASSIST_RESTORE:
  87.141          /* save the old context */
  87.142 -        if (!hvm_copy(&cp, VMXASSIST_OLD_CONTEXT, sizeof(cp), HVM_COPY_IN))
  87.143 +        if (hvm_copy_from_guest_phys(&cp, VMXASSIST_OLD_CONTEXT, sizeof(cp)))
  87.144              goto error;
  87.145          if (cp != 0) {
  87.146 -            if (!hvm_copy(&c, cp, sizeof(c), HVM_COPY_IN))
  87.147 +            if (hvm_copy_from_guest_phys(&c, cp, sizeof(c)))
  87.148                  goto error;
  87.149              if (!vmx_world_restore(v, &c))
  87.150                  goto error;
  87.151 @@ -1761,6 +1768,8 @@ static int mov_to_cr(int gp, int cr, str
  87.152      }
  87.153      case 8:
  87.154      {
  87.155 +        if ( vlapic == NULL )
  87.156 +            break;
  87.157          vlapic_set_reg(vlapic, APIC_TASKPRI, ((value & 0x0F) << 4));
  87.158          vlapic_update_ppr(vlapic);
  87.159          break;
  87.160 @@ -1782,15 +1791,19 @@ static void mov_from_cr(int cr, int gp, 
  87.161      struct vcpu *v = current;
  87.162      struct vlapic *vlapic = VLAPIC(v);
  87.163  
  87.164 -    if ( cr != 3 && cr != 8)
  87.165 -        __hvm_bug(regs);
  87.166 -
  87.167 -    if ( cr == 3 )
  87.168 -        value = (unsigned long) v->arch.hvm_vmx.cpu_cr3;
  87.169 -    else if ( cr == 8 )
  87.170 +    switch ( cr )
  87.171      {
  87.172 +    case 3:
  87.173 +        value = (unsigned long)v->arch.hvm_vmx.cpu_cr3;
  87.174 +        break;
  87.175 +    case 8:
  87.176 +        if ( vlapic == NULL )
  87.177 +            break;
  87.178          value = (unsigned long)vlapic_get_reg(vlapic, APIC_TASKPRI);
  87.179          value = (value & 0xF0) >> 4;
  87.180 +        break;
  87.181 +    default:
  87.182 +        __hvm_bug(regs);
  87.183      }
  87.184  
  87.185      switch ( gp ) {
  87.186 @@ -1924,7 +1937,7 @@ static inline void vmx_do_msr_write(stru
  87.187                  (unsigned long)regs->ecx, (unsigned long)regs->eax,
  87.188                  (unsigned long)regs->edx);
  87.189  
  87.190 -    msr_content = (regs->eax & 0xFFFFFFFF) | ((u64)regs->edx << 32);
  87.191 +    msr_content = (u32)regs->eax | ((u64)regs->edx << 32);
  87.192  
  87.193      switch (regs->ecx) {
  87.194      case MSR_IA32_TIME_STAMP_COUNTER:
  87.195 @@ -2110,7 +2123,7 @@ static void vmx_reflect_exception(struct
  87.196      }
  87.197  }
  87.198  
  87.199 -asmlinkage void vmx_vmexit_handler(struct cpu_user_regs regs)
  87.200 +asmlinkage void vmx_vmexit_handler(struct cpu_user_regs *regs)
  87.201  {
  87.202      unsigned int exit_reason;
  87.203      unsigned long exit_qualification, rip, inst_len = 0;
  87.204 @@ -2181,16 +2194,16 @@ asmlinkage void vmx_vmexit_handler(struc
  87.205  #ifdef XEN_DEBUGGER
  87.206          case TRAP_debug:
  87.207          {
  87.208 -            save_cpu_user_regs(&regs);
  87.209 -            pdb_handle_exception(1, &regs, 1);
  87.210 -            restore_cpu_user_regs(&regs);
  87.211 +            save_cpu_user_regs(regs);
  87.212 +            pdb_handle_exception(1, regs, 1);
  87.213 +            restore_cpu_user_regs(regs);
  87.214              break;
  87.215          }
  87.216          case TRAP_int3:
  87.217          {
  87.218 -            save_cpu_user_regs(&regs);
  87.219 -            pdb_handle_exception(3, &regs, 1);
  87.220 -            restore_cpu_user_regs(&regs);
  87.221 +            save_cpu_user_regs(regs);
  87.222 +            pdb_handle_exception(3, regs, 1);
  87.223 +            restore_cpu_user_regs(regs);
  87.224              break;
  87.225          }
  87.226  #else
  87.227 @@ -2200,7 +2213,7 @@ asmlinkage void vmx_vmexit_handler(struc
  87.228  
  87.229              if ( test_bit(_DOMF_debugging, &v->domain->domain_flags) )
  87.230              {
  87.231 -                store_cpu_user_regs(&regs);
  87.232 +                store_cpu_user_regs(regs);
  87.233                  domain_pause_for_debugger();
  87.234                  __vm_clear_bit(GUEST_PENDING_DBG_EXCEPTIONS,
  87.235                                 PENDING_DEBUG_EXC_BS);
  87.236 @@ -2231,29 +2244,29 @@ asmlinkage void vmx_vmexit_handler(struc
  87.237          case TRAP_page_fault:
  87.238          {
  87.239              __vmread(EXIT_QUALIFICATION, &va);
  87.240 -            __vmread(VM_EXIT_INTR_ERROR_CODE, &regs.error_code);
  87.241 +            __vmread(VM_EXIT_INTR_ERROR_CODE, &regs->error_code);
  87.242  
  87.243 -            TRACE_VMEXIT(3,regs.error_code);
  87.244 -            TRACE_VMEXIT(4,va);
  87.245 +            TRACE_VMEXIT(3, regs->error_code);
  87.246 +            TRACE_VMEXIT(4, va);
  87.247  
  87.248              HVM_DBG_LOG(DBG_LEVEL_VMMU,
  87.249                          "eax=%lx, ebx=%lx, ecx=%lx, edx=%lx, esi=%lx, edi=%lx",
  87.250 -                        (unsigned long)regs.eax, (unsigned long)regs.ebx,
  87.251 -                        (unsigned long)regs.ecx, (unsigned long)regs.edx,
  87.252 -                        (unsigned long)regs.esi, (unsigned long)regs.edi);
  87.253 +                        (unsigned long)regs->eax, (unsigned long)regs->ebx,
  87.254 +                        (unsigned long)regs->ecx, (unsigned long)regs->edx,
  87.255 +                        (unsigned long)regs->esi, (unsigned long)regs->edi);
  87.256  
  87.257 -            if ( !vmx_do_page_fault(va, &regs) ) {
  87.258 -                /*
  87.259 -                 * Inject #PG using Interruption-Information Fields
  87.260 -                 */
  87.261 -                vmx_inject_hw_exception(v, TRAP_page_fault, regs.error_code);
  87.262 +            if ( !vmx_do_page_fault(va, regs) )
  87.263 +            {
  87.264 +                /* Inject #PG using Interruption-Information Fields. */
  87.265 +                vmx_inject_hw_exception(v, TRAP_page_fault, regs->error_code);
  87.266                  v->arch.hvm_vmx.cpu_cr2 = va;
  87.267 -                TRACE_3D(TRC_VMX_INT, v->domain->domain_id, TRAP_page_fault, va);
  87.268 +                TRACE_3D(TRC_VMX_INT, v->domain->domain_id,
  87.269 +                         TRAP_page_fault, va);
  87.270              }
  87.271              break;
  87.272          }
  87.273          case TRAP_nmi:
  87.274 -            do_nmi(&regs);
  87.275 +            do_nmi(regs);
  87.276              break;
  87.277          default:
  87.278              vmx_reflect_exception(v);
  87.279 @@ -2262,7 +2275,7 @@ asmlinkage void vmx_vmexit_handler(struc
  87.280          break;
  87.281      }
  87.282      case EXIT_REASON_EXTERNAL_INTERRUPT:
  87.283 -        vmx_vmexit_do_extint(&regs);
  87.284 +        vmx_vmexit_do_extint(regs);
  87.285          break;
  87.286      case EXIT_REASON_TRIPLE_FAULT:
  87.287          domain_crash_synchronous();
  87.288 @@ -2279,7 +2292,7 @@ asmlinkage void vmx_vmexit_handler(struc
  87.289      case EXIT_REASON_CPUID:
  87.290          inst_len = __get_instruction_length(); /* Safe: CPUID */
  87.291          __update_guest_eip(inst_len);
  87.292 -        vmx_vmexit_do_cpuid(&regs);
  87.293 +        vmx_vmexit_do_cpuid(regs);
  87.294          break;
  87.295      case EXIT_REASON_HLT:
  87.296          inst_len = __get_instruction_length(); /* Safe: HLT */
  87.297 @@ -2301,7 +2314,7 @@ asmlinkage void vmx_vmexit_handler(struc
  87.298          __update_guest_eip(inst_len);
  87.299          __vmread(GUEST_RIP, &rip);
  87.300          __vmread(EXIT_QUALIFICATION, &exit_qualification);
  87.301 -        hvm_do_hypercall(&regs);
  87.302 +        hvm_do_hypercall(regs);
  87.303          break;
  87.304      }
  87.305      case EXIT_REASON_CR_ACCESS:
  87.306 @@ -2309,15 +2322,15 @@ asmlinkage void vmx_vmexit_handler(struc
  87.307          __vmread(GUEST_RIP, &rip);
  87.308          __vmread(EXIT_QUALIFICATION, &exit_qualification);
  87.309          inst_len = __get_instruction_length(); /* Safe: MOV Cn, LMSW, CLTS */
  87.310 -        if ( vmx_cr_access(exit_qualification, &regs) )
  87.311 +        if ( vmx_cr_access(exit_qualification, regs) )
  87.312              __update_guest_eip(inst_len);
  87.313 -        TRACE_VMEXIT(3,regs.error_code);
  87.314 -        TRACE_VMEXIT(4,exit_qualification);
  87.315 +        TRACE_VMEXIT(3, regs->error_code);
  87.316 +        TRACE_VMEXIT(4, exit_qualification);
  87.317          break;
  87.318      }
  87.319      case EXIT_REASON_DR_ACCESS:
  87.320          __vmread(EXIT_QUALIFICATION, &exit_qualification);
  87.321 -        vmx_dr_access(exit_qualification, &regs);
  87.322 +        vmx_dr_access(exit_qualification, regs);
  87.323          break;
  87.324      case EXIT_REASON_IO_INSTRUCTION:
  87.325          __vmread(EXIT_QUALIFICATION, &exit_qualification);
  87.326 @@ -2328,12 +2341,12 @@ asmlinkage void vmx_vmexit_handler(struc
  87.327      case EXIT_REASON_MSR_READ:
  87.328          inst_len = __get_instruction_length(); /* Safe: RDMSR */
  87.329          __update_guest_eip(inst_len);
  87.330 -        vmx_do_msr_read(&regs);
  87.331 +        vmx_do_msr_read(regs);
  87.332          break;
  87.333      case EXIT_REASON_MSR_WRITE:
  87.334          inst_len = __get_instruction_length(); /* Safe: WRMSR */
  87.335          __update_guest_eip(inst_len);
  87.336 -        vmx_do_msr_write(&regs);
  87.337 +        vmx_do_msr_write(regs);
  87.338          break;
  87.339      case EXIT_REASON_MWAIT_INSTRUCTION:
  87.340      case EXIT_REASON_MONITOR_INSTRUCTION:
    88.1 --- a/xen/arch/x86/hvm/vmx/x86_32/exits.S	Sun Oct 01 11:39:41 2006 -0600
    88.2 +++ b/xen/arch/x86/hvm/vmx/x86_32/exits.S	Sun Oct 01 19:10:18 2006 -0600
    88.3 @@ -82,7 +82,10 @@ ENTRY(vmx_asm_vmexit_handler)
    88.4          /* selectors are restored/saved by VMX */
    88.5          HVM_SAVE_ALL_NOSEGREGS
    88.6          call vmx_trace_vmexit
    88.7 +        movl %esp,%eax
    88.8 +        push %eax
    88.9          call vmx_vmexit_handler
   88.10 +        addl $4,%esp
   88.11          jmp vmx_asm_do_vmentry
   88.12  
   88.13          ALIGN
    89.1 --- a/xen/arch/x86/hvm/vmx/x86_64/exits.S	Sun Oct 01 11:39:41 2006 -0600
    89.2 +++ b/xen/arch/x86/hvm/vmx/x86_64/exits.S	Sun Oct 01 19:10:18 2006 -0600
    89.3 @@ -93,6 +93,7 @@ ENTRY(vmx_asm_vmexit_handler)
    89.4          /* selectors are restored/saved by VMX */
    89.5          HVM_SAVE_ALL_NOSEGREGS
    89.6          call vmx_trace_vmexit
    89.7 +        movq %rsp,%rdi
    89.8          call vmx_vmexit_handler
    89.9          jmp vmx_asm_do_vmentry
   89.10  
    90.1 --- a/xen/arch/x86/mm.c	Sun Oct 01 11:39:41 2006 -0600
    90.2 +++ b/xen/arch/x86/mm.c	Sun Oct 01 19:10:18 2006 -0600
    90.3 @@ -427,23 +427,11 @@ int map_ldt_shadow_page(unsigned int off
    90.4      unsigned long gmfn, mfn;
    90.5      l1_pgentry_t l1e, nl1e;
    90.6      unsigned long gva = v->arch.guest_context.ldt_base + (off << PAGE_SHIFT);
    90.7 -    int res;
    90.8 -
    90.9 -#if defined(__x86_64__)
   90.10 -    /* If in user mode, switch to kernel mode just to read LDT mapping. */
   90.11 -    int user_mode = !(v->arch.flags & TF_kernel_mode);
   90.12 -#define TOGGLE_MODE() if ( user_mode ) toggle_guest_mode(v)
   90.13 -#elif defined(__i386__)
   90.14 -#define TOGGLE_MODE() ((void)0)
   90.15 -#endif
   90.16 +    int okay;
   90.17  
   90.18      BUG_ON(unlikely(in_irq()));
   90.19  
   90.20 -    TOGGLE_MODE();
   90.21 -    __copy_from_user(&l1e, &linear_pg_table[l1_linear_offset(gva)],
   90.22 -                     sizeof(l1e));
   90.23 -    TOGGLE_MODE();
   90.24 -
   90.25 +    guest_get_eff_kern_l1e(v, gva, &l1e);
   90.26      if ( unlikely(!(l1e_get_flags(l1e) & _PAGE_PRESENT)) )
   90.27          return 0;
   90.28  
   90.29 @@ -452,17 +440,17 @@ int map_ldt_shadow_page(unsigned int off
   90.30      if ( unlikely(!VALID_MFN(mfn)) )
   90.31          return 0;
   90.32  
   90.33 -    res = get_page_and_type(mfn_to_page(mfn), d, PGT_ldt_page);
   90.34 -
   90.35 -    if ( !res && unlikely(shadow_mode_refcounts(d)) )
   90.36 +    okay = get_page_and_type(mfn_to_page(mfn), d, PGT_ldt_page);
   90.37 +
   90.38 +    if ( !okay && unlikely(shadow_mode_refcounts(d)) )
   90.39      {
   90.40          shadow_lock(d);
   90.41          shadow_remove_write_access(d->vcpu[0], _mfn(mfn), 0, 0);
   90.42 -        res = get_page_and_type(mfn_to_page(mfn), d, PGT_ldt_page);
   90.43 +        okay = get_page_and_type(mfn_to_page(mfn), d, PGT_ldt_page);
   90.44          shadow_unlock(d);
   90.45      }
   90.46  
   90.47 -    if ( unlikely(!res) )
   90.48 +    if ( unlikely(!okay) )
   90.49          return 0;
   90.50  
   90.51      nl1e = l1e_from_pfn(mfn, l1e_get_flags(l1e) | _PAGE_RW);
   90.52 @@ -1233,7 +1221,7 @@ static inline int update_l1e(l1_pgentry_
   90.53          }
   90.54      }
   90.55  #endif
   90.56 -    if ( unlikely(shadow_mode_enabled(v->domain)) )
   90.57 +    if ( unlikely(shadow_mode_enabled(v->domain)) && rv )
   90.58      {
   90.59          shadow_validate_guest_entry(v, _mfn(gl1mfn), pl1e);
   90.60          shadow_unlock(v->domain);    
   90.61 @@ -1252,6 +1240,9 @@ static int mod_l1_entry(l1_pgentry_t *pl
   90.62      if ( unlikely(__copy_from_user(&ol1e, pl1e, sizeof(ol1e)) != 0) )
   90.63          return 0;
   90.64  
   90.65 +    if ( unlikely(shadow_mode_refcounts(d)) )
   90.66 +        return update_l1e(pl1e, ol1e, nl1e, gl1mfn, current);
   90.67 +
   90.68      if ( l1e_get_flags(nl1e) & _PAGE_PRESENT )
   90.69      {
   90.70          if ( unlikely(l1e_get_flags(nl1e) & L1_DISALLOW_MASK) )
   90.71 @@ -1544,9 +1535,7 @@ void free_page_type(struct page_info *pa
   90.72  
   90.73              gmfn = mfn_to_gmfn(owner, page_to_mfn(page));
   90.74              ASSERT(VALID_M2P(gmfn));
   90.75 -            shadow_lock(owner);
   90.76              shadow_remove_all_shadows(owner->vcpu[0], _mfn(gmfn));
   90.77 -            shadow_unlock(owner);
   90.78          }
   90.79      }
   90.80  
   90.81 @@ -1618,8 +1607,8 @@ void put_page_type(struct page_info *pag
   90.82               *  2. Shadow mode reuses this field for shadowed page tables to
   90.83               *     store flags info -- we don't want to conflict with that.
   90.84               */
   90.85 -            if ( !shadow_mode_enabled(page_get_owner(page)) ||
   90.86 -                 ((nx & PGT_type_mask) == PGT_writable_page) )
   90.87 +            if ( !(shadow_mode_enabled(page_get_owner(page)) &&
   90.88 +                   (page->count_info & PGC_page_table)) )
   90.89                  page->tlbflush_timestamp = tlbflush_current_time();
   90.90          }
   90.91      }
   90.92 @@ -1644,6 +1633,12 @@ int get_page_type(struct page_info *page
   90.93          }
   90.94          else if ( unlikely((x & PGT_count_mask) == 0) )
   90.95          {
   90.96 +            struct domain *d = page_get_owner(page);
   90.97 +
   90.98 +            /* Never allow a shadowed frame to go from type count 0 to 1 */
   90.99 +            if ( d && shadow_mode_enabled(d) )
  90.100 +                shadow_remove_all_shadows(d->vcpu[0], _mfn(page_to_mfn(page)));
  90.101 +
  90.102              ASSERT(!(x & PGT_pae_xen_l2));
  90.103              if ( (x & PGT_type_mask) != type )
  90.104              {
  90.105 @@ -1652,8 +1647,9 @@ int get_page_type(struct page_info *page
  90.106                   * may be unnecessary (e.g., page was GDT/LDT) but those 
  90.107                   * circumstances should be very rare.
  90.108                   */
  90.109 -                cpumask_t mask =
  90.110 -                    page_get_owner(page)->domain_dirty_cpumask;
  90.111 +                cpumask_t mask = d->domain_dirty_cpumask;
  90.112 +
  90.113 +                /* Don't flush if the timestamp is old enough */
  90.114                  tlbflush_filter(mask, page->tlbflush_timestamp);
  90.115  
  90.116                  if ( unlikely(!cpus_empty(mask)) &&
  90.117 @@ -1866,6 +1862,14 @@ static int set_foreigndom(domid_t domid)
  90.118          }
  90.119      }
  90.120  
  90.121 +    if ( unlikely(shadow_mode_translate(d)) )
  90.122 +    {
  90.123 +        MEM_LOG("%s: can not mix foreign mappings with translated domains",
  90.124 +                __func__);
  90.125 +        info->foreign = NULL;
  90.126 +        okay = 0; 
  90.127 +    }
  90.128 +
  90.129   out:
  90.130      return okay;
  90.131  }
  90.132 @@ -1897,7 +1901,7 @@ int do_mmuext_op(
  90.133  {
  90.134      struct mmuext_op op;
  90.135      int rc = 0, i = 0, okay;
  90.136 -    unsigned long mfn, type;
  90.137 +    unsigned long mfn = 0, gmfn = 0, type;
  90.138      unsigned int done = 0;
  90.139      struct page_info *page;
  90.140      struct vcpu *v = current;
  90.141 @@ -1942,7 +1946,8 @@ int do_mmuext_op(
  90.142          }
  90.143  
  90.144          okay = 1;
  90.145 -        mfn  = op.arg1.mfn;
  90.146 +        gmfn  = op.arg1.mfn;
  90.147 +        mfn = gmfn_to_mfn(FOREIGNDOM, gmfn);
  90.148          page = mfn_to_page(mfn);
  90.149  
  90.150          switch ( op.cmd )
  90.151 @@ -2017,7 +2022,6 @@ int do_mmuext_op(
  90.152              break;
  90.153  
  90.154          case MMUEXT_NEW_BASEPTR:
  90.155 -            mfn = gmfn_to_mfn(current->domain, mfn);
  90.156              okay = new_guest_cr3(mfn);
  90.157              this_cpu(percpu_mm_info).deferred_ops &= ~DOP_FLUSH_TLB;
  90.158              break;
  90.159 @@ -2026,8 +2030,13 @@ int do_mmuext_op(
  90.160          case MMUEXT_NEW_USER_BASEPTR:
  90.161              okay = 1;
  90.162              if (likely(mfn != 0))
  90.163 -                okay = get_page_and_type_from_pagenr(
  90.164 -                    mfn, PGT_root_page_table, d);
  90.165 +            {
  90.166 +                if ( shadow_mode_refcounts(d) )
  90.167 +                    okay = get_page_from_pagenr(mfn, d);
  90.168 +                else
  90.169 +                    okay = get_page_and_type_from_pagenr(
  90.170 +                        mfn, PGT_root_page_table, d);
  90.171 +            }
  90.172              if ( unlikely(!okay) )
  90.173              {
  90.174                  MEM_LOG("Error while installing new mfn %lx", mfn);
  90.175 @@ -2038,7 +2047,12 @@ int do_mmuext_op(
  90.176                      pagetable_get_pfn(v->arch.guest_table_user);
  90.177                  v->arch.guest_table_user = pagetable_from_pfn(mfn);
  90.178                  if ( old_mfn != 0 )
  90.179 -                    put_page_and_type(mfn_to_page(old_mfn));
  90.180 +                {
  90.181 +                    if ( shadow_mode_refcounts(d) )
  90.182 +                        put_page(mfn_to_page(old_mfn));
  90.183 +                    else
  90.184 +                        put_page_and_type(mfn_to_page(old_mfn));
  90.185 +                }
  90.186              }
  90.187              break;
  90.188  #endif
  90.189 @@ -2499,17 +2513,26 @@ static int create_grant_va_mapping(
  90.190  {
  90.191      l1_pgentry_t *pl1e, ol1e;
  90.192      struct domain *d = v->domain;
  90.193 +    unsigned long gl1mfn;
  90.194 +    int okay;
  90.195      
  90.196      ASSERT(spin_is_locked(&d->big_lock));
  90.197  
  90.198      adjust_guest_l1e(nl1e);
  90.199  
  90.200 -    pl1e = &linear_pg_table[l1_linear_offset(va)];
  90.201 -
  90.202 -    if ( unlikely(__copy_from_user(&ol1e, pl1e, sizeof(ol1e)) != 0) ||
  90.203 -         !update_l1e(pl1e, ol1e, nl1e, 
  90.204 -                    l2e_get_pfn(__linear_l2_table[l2_linear_offset(va)]), v) )
  90.205 +    pl1e = guest_map_l1e(v, va, &gl1mfn);
  90.206 +    if ( !pl1e )
  90.207 +    {
  90.208 +        MEM_LOG("Could not find L1 PTE for address %lx", va);
  90.209          return GNTST_general_error;
  90.210 +    }
  90.211 +    ol1e = *pl1e;
  90.212 +    okay = update_l1e(pl1e, ol1e, nl1e, gl1mfn, v);
  90.213 +    guest_unmap_l1e(v, pl1e);
  90.214 +    pl1e = NULL;
  90.215 +
  90.216 +    if ( !okay )
  90.217 +            return GNTST_general_error;
  90.218  
  90.219      if ( !shadow_mode_refcounts(d) )
  90.220          put_page_from_l1e(ol1e, d);
  90.221 @@ -2518,17 +2541,19 @@ static int create_grant_va_mapping(
  90.222  }
  90.223  
  90.224  static int destroy_grant_va_mapping(
  90.225 -    unsigned long addr, unsigned long frame, struct domain *d)
  90.226 +    unsigned long addr, unsigned long frame, struct vcpu *v)
  90.227  {
  90.228      l1_pgentry_t *pl1e, ol1e;
  90.229 +    unsigned long gl1mfn;
  90.230 +    int rc = 0;
  90.231      
  90.232 -    pl1e = &linear_pg_table[l1_linear_offset(addr)];
  90.233 -
  90.234 -    if ( unlikely(__get_user(ol1e.l1, &pl1e->l1) != 0) )
  90.235 +    pl1e = guest_map_l1e(v, addr, &gl1mfn);
  90.236 +    if ( !pl1e )
  90.237      {
  90.238 -        MEM_LOG("Could not find PTE entry for address %lx", addr);
  90.239 +        MEM_LOG("Could not find L1 PTE for address %lx", addr);
  90.240          return GNTST_general_error;
  90.241      }
  90.242 +    ol1e = *pl1e;
  90.243  
  90.244      /*
  90.245       * Check that the virtual address supplied is actually mapped to
  90.246 @@ -2538,19 +2563,21 @@ static int destroy_grant_va_mapping(
  90.247      {
  90.248          MEM_LOG("PTE entry %lx for address %lx doesn't match frame %lx",
  90.249                  l1e_get_pfn(ol1e), addr, frame);
  90.250 -        return GNTST_general_error;
  90.251 +        rc = GNTST_general_error;
  90.252 +        goto out;
  90.253      }
  90.254  
  90.255      /* Delete pagetable entry. */
  90.256 -    if ( unlikely(!update_l1e(pl1e, ol1e, l1e_empty(), 
  90.257 -                      l2e_get_pfn(__linear_l2_table[l2_linear_offset(addr)]),
  90.258 -                      d->vcpu[0] /* Change for per-vcpu shadows */)) )
  90.259 +    if ( unlikely(!update_l1e(pl1e, ol1e, l1e_empty(), gl1mfn, v)) )
  90.260      {
  90.261          MEM_LOG("Cannot delete PTE entry at %p", (unsigned long *)pl1e);
  90.262 -        return GNTST_general_error;
  90.263 +        rc = GNTST_general_error;
  90.264 +        goto out; // this is redundant & unnecessary, but informative
  90.265      }
  90.266  
  90.267 -    return 0;
  90.268 + out:
  90.269 +    guest_unmap_l1e(v, pl1e);
  90.270 +    return rc;
  90.271  }
  90.272  
  90.273  int create_grant_host_mapping(
  90.274 @@ -2573,7 +2600,7 @@ int destroy_grant_host_mapping(
  90.275  {
  90.276      if ( flags & GNTMAP_contains_pte )
  90.277          return destroy_grant_pte_mapping(addr, frame, current->domain);
  90.278 -    return destroy_grant_va_mapping(addr, frame, current->domain);
  90.279 +    return destroy_grant_va_mapping(addr, frame, current);
  90.280  }
  90.281  
  90.282  int steal_page(
  90.283 @@ -2629,7 +2656,8 @@ int do_update_va_mapping(unsigned long v
  90.284      l1_pgentry_t   val = l1e_from_intpte(val64);
  90.285      struct vcpu   *v   = current;
  90.286      struct domain *d   = v->domain;
  90.287 -    unsigned long  vmask, bmap_ptr;
  90.288 +    l1_pgentry_t  *pl1e;
  90.289 +    unsigned long  vmask, bmap_ptr, gl1mfn;
  90.290      cpumask_t      pmask;
  90.291      int            rc  = 0;
  90.292  
  90.293 @@ -2638,35 +2666,17 @@ int do_update_va_mapping(unsigned long v
  90.294      if ( unlikely(!__addr_ok(va) && !shadow_mode_external(d)) )
  90.295          return -EINVAL;
  90.296  
  90.297 -    if ( unlikely(shadow_mode_refcounts(d)) )
  90.298 -    {
  90.299 -        DPRINTK("Grant op on a shadow-refcounted domain\n");
  90.300 -        return -EINVAL; 
  90.301 -    }
  90.302 -
  90.303      LOCK_BIGLOCK(d);
  90.304  
  90.305 -    if ( likely(rc == 0) && unlikely(shadow_mode_enabled(d)) )
  90.306 -    {
  90.307 -        if ( unlikely(this_cpu(percpu_mm_info).foreign &&
  90.308 -                      (shadow_mode_translate(d) ||
  90.309 -                       shadow_mode_translate(
  90.310 -                           this_cpu(percpu_mm_info).foreign))) )
  90.311 -        {
  90.312 -            /*
  90.313 -             * The foreign domain's pfn's are in a different namespace. There's
  90.314 -             * not enough information in just a gpte to figure out how to   
  90.315 -             * (re-)shadow this entry.
  90.316 -             */
  90.317 -            domain_crash(d);
  90.318 -        }
  90.319 -    }
  90.320 -
  90.321 -    if ( unlikely(!mod_l1_entry(
  90.322 -                      &linear_pg_table[l1_linear_offset(va)], val,
  90.323 -                      l2e_get_pfn(__linear_l2_table[l2_linear_offset(va)]))) )
  90.324 +    pl1e = guest_map_l1e(v, va, &gl1mfn);
  90.325 +
  90.326 +    if ( unlikely(!pl1e || !mod_l1_entry(pl1e, val, gl1mfn)) )
  90.327          rc = -EINVAL;
  90.328 -    
  90.329 +
  90.330 +    if ( pl1e )
  90.331 +        guest_unmap_l1e(v, pl1e);
  90.332 +    pl1e = NULL;
  90.333 +
  90.334      switch ( flags & UVMF_FLUSHTYPE_MASK )
  90.335      {
  90.336      case UVMF_TLB_FLUSH:
  90.337 @@ -3028,7 +3038,7 @@ static int ptwr_emulated_update(
  90.338      unsigned int bytes,
  90.339      unsigned int do_cmpxchg)
  90.340  {
  90.341 -    unsigned long pfn;
  90.342 +    unsigned long gmfn, mfn;
  90.343      struct page_info *page;
  90.344      l1_pgentry_t pte, ol1e, nl1e, *pl1e;
  90.345      struct vcpu *v = current;
  90.346 @@ -3068,15 +3078,17 @@ static int ptwr_emulated_update(
  90.347      }
  90.348  
  90.349      /* Read the PTE that maps the page being updated. */
  90.350 -    if ( __copy_from_user(&pte, &linear_pg_table[l1_linear_offset(addr)],
  90.351 -                          sizeof(pte)) )
  90.352 +    guest_get_eff_l1e(v, addr, &pte);
  90.353 +    if ( unlikely(!(l1e_get_flags(pte) & _PAGE_PRESENT)) )
  90.354      {
  90.355 -        MEM_LOG("ptwr_emulate: Cannot read thru linear_pg_table");
  90.356 +        MEM_LOG("%s: Cannot get L1 PTE for guest address %lx",
  90.357 +                __func__, addr);
  90.358          return X86EMUL_UNHANDLEABLE;
  90.359      }
  90.360  
  90.361 -    pfn  = l1e_get_pfn(pte);
  90.362 -    page = mfn_to_page(pfn);
  90.363 +    gmfn  = l1e_get_pfn(pte);
  90.364 +    mfn = gmfn_to_mfn(d, gmfn);
  90.365 +    page = mfn_to_page(mfn);
  90.366  
  90.367      /* We are looking only for read-only mappings of p.t. pages. */
  90.368      ASSERT((l1e_get_flags(pte) & (_PAGE_RW|_PAGE_PRESENT)) == _PAGE_PRESENT);
  90.369 @@ -3086,7 +3098,7 @@ static int ptwr_emulated_update(
  90.370  
  90.371      /* Check the new PTE. */
  90.372      nl1e = l1e_from_intpte(val);
  90.373 -    if ( unlikely(!get_page_from_l1e(nl1e, d)) )
  90.374 +    if ( unlikely(!get_page_from_l1e(gl1e_to_ml1e(d, nl1e), d)) )
  90.375      {
  90.376          if ( (CONFIG_PAGING_LEVELS == 3) &&
  90.377               (bytes == 4) &&
  90.378 @@ -3125,13 +3137,13 @@ static int ptwr_emulated_update(
  90.379              if ( shadow_mode_enabled(d) )
  90.380                  shadow_unlock(d);
  90.381              unmap_domain_page(pl1e);
  90.382 -            put_page_from_l1e(nl1e, d);
  90.383 +            put_page_from_l1e(gl1e_to_ml1e(d, nl1e), d);
  90.384              return X86EMUL_CMPXCHG_FAILED;
  90.385          }
  90.386 -        if ( unlikely(shadow_mode_enabled(v->domain)) )
  90.387 +        if ( unlikely(shadow_mode_enabled(d)) )
  90.388          {
  90.389              shadow_validate_guest_entry(v, _mfn(page_to_mfn(page)), pl1e);
  90.390 -            shadow_unlock(v->domain);    
  90.391 +            shadow_unlock(d);    
  90.392          }
  90.393      }
  90.394      else
  90.395 @@ -3144,7 +3156,7 @@ static int ptwr_emulated_update(
  90.396      unmap_domain_page(pl1e);
  90.397  
  90.398      /* Finally, drop the old PTE. */
  90.399 -    put_page_from_l1e(ol1e, d);
  90.400 +    put_page_from_l1e(gl1e_to_ml1e(d, ol1e), d);
  90.401  
  90.402      return X86EMUL_CONTINUE;
  90.403  }
  90.404 @@ -3193,13 +3205,13 @@ static struct x86_emulate_ops ptwr_emula
  90.405  };
  90.406  
  90.407  /* Write page fault handler: check if guest is trying to modify a PTE. */
  90.408 -int ptwr_do_page_fault(struct domain *d, unsigned long addr, 
  90.409 +int ptwr_do_page_fault(struct vcpu *v, unsigned long addr, 
  90.410                         struct cpu_user_regs *regs)
  90.411  {
  90.412 +    struct domain *d = v->domain;
  90.413      unsigned long     pfn;
  90.414      struct page_info *page;
  90.415      l1_pgentry_t      pte;
  90.416 -    l2_pgentry_t     *pl2e, l2e;
  90.417      struct x86_emulate_ctxt emul_ctxt;
  90.418  
  90.419      LOCK_BIGLOCK(d);
  90.420 @@ -3208,13 +3220,9 @@ int ptwr_do_page_fault(struct domain *d,
  90.421       * Attempt to read the PTE that maps the VA being accessed. By checking for
  90.422       * PDE validity in the L2 we avoid many expensive fixups in __get_user().
  90.423       */
  90.424 -    pl2e = &__linear_l2_table[l2_linear_offset(addr)];
  90.425 -    if ( __copy_from_user(&l2e, pl2e, sizeof(l2e)) ||
  90.426 -        !(l2e_get_flags(l2e) & _PAGE_PRESENT) ||
  90.427 -         __copy_from_user(&pte, &linear_pg_table[l1_linear_offset(addr)],
  90.428 -                          sizeof(pte)) )
  90.429 +    guest_get_eff_l1e(v, addr, &pte);
  90.430 +    if ( !(l1e_get_flags(pte) & _PAGE_PRESENT) )
  90.431          goto bail;
  90.432 -
  90.433      pfn  = l1e_get_pfn(pte);
  90.434      page = mfn_to_page(pfn);
  90.435  
    91.1 --- a/xen/arch/x86/mm/shadow/common.c	Sun Oct 01 11:39:41 2006 -0600
    91.2 +++ b/xen/arch/x86/mm/shadow/common.c	Sun Oct 01 19:10:18 2006 -0600
    91.3 @@ -75,35 +75,27 @@ sh_x86_emulate_read_std(unsigned long ad
    91.4                           unsigned int bytes,
    91.5                           struct x86_emulate_ctxt *ctxt)
    91.6  {
    91.7 -    struct vcpu *v = current;
    91.8 -    if ( hvm_guest(v) )
    91.9 +    *val = 0;
   91.10 +    // XXX -- this is WRONG.
   91.11 +    //        It entirely ignores the permissions in the page tables.
   91.12 +    //        In this case, that is only a user vs supervisor access check.
   91.13 +    //
   91.14 +    if ( hvm_copy_from_guest_virt(val, addr, bytes) == 0 )
   91.15      {
   91.16 -        *val = 0;
   91.17 -        // XXX -- this is WRONG.
   91.18 -        //        It entirely ignores the permissions in the page tables.
   91.19 -        //        In this case, that is only a user vs supervisor access check.
   91.20 -        //
   91.21 -        if ( hvm_copy(val, addr, bytes, HVM_COPY_IN) )
   91.22 -        {
   91.23  #if 0
   91.24 -            SHADOW_PRINTK("d=%u v=%u a=%#lx v=%#lx bytes=%u\n",
   91.25 -                           v->domain->domain_id, v->vcpu_id, 
   91.26 -                           addr, *val, bytes);
   91.27 +        struct vcpu *v = current;
   91.28 +        SHADOW_PRINTK("d=%u v=%u a=%#lx v=%#lx bytes=%u\n",
   91.29 +                       v->domain->domain_id, v->vcpu_id, 
   91.30 +                       addr, *val, bytes);
   91.31  #endif
   91.32 -            return X86EMUL_CONTINUE;
   91.33 -        }
   91.34 -
   91.35 -        /* If we got here, there was nothing mapped here, or a bad GFN 
   91.36 -         * was mapped here.  This should never happen: we're here because
   91.37 -         * of a write fault at the end of the instruction we're emulating. */ 
   91.38 -        SHADOW_PRINTK("read failed to va %#lx\n", addr);
   91.39 -        return X86EMUL_PROPAGATE_FAULT;
   91.40 +        return X86EMUL_CONTINUE;
   91.41      }
   91.42 -    else 
   91.43 -    {
   91.44 -        SHADOW_PRINTK("this operation is not emulated yet\n");
   91.45 -        return X86EMUL_UNHANDLEABLE;
   91.46 -    }
   91.47 +
   91.48 +    /* If we got here, there was nothing mapped here, or a bad GFN 
   91.49 +     * was mapped here.  This should never happen: we're here because
   91.50 +     * of a write fault at the end of the instruction we're emulating. */ 
   91.51 +    SHADOW_PRINTK("read failed to va %#lx\n", addr);
   91.52 +    return X86EMUL_PROPAGATE_FAULT;
   91.53  }
   91.54  
   91.55  static int
   91.56 @@ -112,33 +104,26 @@ sh_x86_emulate_write_std(unsigned long a
   91.57                            unsigned int bytes,
   91.58                            struct x86_emulate_ctxt *ctxt)
   91.59  {
   91.60 +#if 0
   91.61      struct vcpu *v = current;
   91.62 -#if 0
   91.63      SHADOW_PRINTK("d=%u v=%u a=%#lx v=%#lx bytes=%u\n",
   91.64                    v->domain->domain_id, v->vcpu_id, addr, val, bytes);
   91.65  #endif
   91.66 -    if ( hvm_guest(v) )
   91.67 -    {
   91.68 -        // XXX -- this is WRONG.
   91.69 -        //        It entirely ignores the permissions in the page tables.
   91.70 -        //        In this case, that includes user vs supervisor, and
   91.71 -        //        write access.
   91.72 -        //
   91.73 -        if ( hvm_copy(&val, addr, bytes, HVM_COPY_OUT) )
   91.74 -            return X86EMUL_CONTINUE;
   91.75 -
   91.76 -        /* If we got here, there was nothing mapped here, or a bad GFN 
   91.77 -         * was mapped here.  This should never happen: we're here because
   91.78 -         * of a write fault at the end of the instruction we're emulating,
   91.79 -         * which should be handled by sh_x86_emulate_write_emulated. */ 
   91.80 -        SHADOW_PRINTK("write failed to va %#lx\n", addr);
   91.81 -        return X86EMUL_PROPAGATE_FAULT;
   91.82 -    }
   91.83 -    else 
   91.84 -    {
   91.85 -        SHADOW_PRINTK("this operation is not emulated yet\n");
   91.86 -        return X86EMUL_UNHANDLEABLE;
   91.87 -    }
   91.88 +
   91.89 +    // XXX -- this is WRONG.
   91.90 +    //        It entirely ignores the permissions in the page tables.
   91.91 +    //        In this case, that includes user vs supervisor, and
   91.92 +    //        write access.
   91.93 +    //
   91.94 +    if ( hvm_copy_to_guest_virt(addr, &val, bytes) == 0 )
   91.95 +        return X86EMUL_CONTINUE;
   91.96 +
   91.97 +    /* If we got here, there was nothing mapped here, or a bad GFN 
   91.98 +     * was mapped here.  This should never happen: we're here because
   91.99 +     * of a write fault at the end of the instruction we're emulating,
  91.100 +     * which should be handled by sh_x86_emulate_write_emulated. */ 
  91.101 +    SHADOW_PRINTK("write failed to va %#lx\n", addr);
  91.102 +    return X86EMUL_PROPAGATE_FAULT;
  91.103  }
  91.104  
  91.105  static int
  91.106 @@ -152,15 +137,7 @@ sh_x86_emulate_write_emulated(unsigned l
  91.107      SHADOW_PRINTK("d=%u v=%u a=%#lx v=%#lx bytes=%u\n",
  91.108                    v->domain->domain_id, v->vcpu_id, addr, val, bytes);
  91.109  #endif
  91.110 -    if ( hvm_guest(v) )
  91.111 -    {
  91.112 -        return v->arch.shadow.mode->x86_emulate_write(v, addr, &val, bytes, ctxt);
  91.113 -    }
  91.114 -    else 
  91.115 -    {
  9