ia64/xen-unstable

changeset 17972:433d1b26fd51

stubdom: use host's gcc

This makes stubdom use the host's gcc instead of downloading/compiling
binutils+gcc. That requires a bunch of changes and even uncovered a
few bugs, but saves a lot of time.

Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Jul 04 17:47:11 2008 +0100 (2008-07-04)
parents a49673cd23d2
children e42135b61dc6
files extras/mini-os/Config.mk extras/mini-os/arch/x86/mm.c extras/mini-os/blkfront.c extras/mini-os/events.c extras/mini-os/fbfront.c extras/mini-os/hypervisor.c extras/mini-os/include/ctype.h extras/mini-os/include/errno.h extras/mini-os/include/ia64/arch_spinlock.h extras/mini-os/include/sys/lock.h extras/mini-os/include/types.h extras/mini-os/include/wait.h extras/mini-os/include/waittypes.h extras/mini-os/include/x86/arch_spinlock.h extras/mini-os/include/xmalloc.h extras/mini-os/kernel.c extras/mini-os/lib/ctype.c extras/mini-os/lib/printf.c extras/mini-os/lib/xmalloc.c extras/mini-os/lock.c extras/mini-os/lwip-net.c extras/mini-os/main.c extras/mini-os/minios.mk extras/mini-os/mm.c extras/mini-os/netfront.c extras/mini-os/pcifront.c extras/mini-os/sched.c extras/mini-os/xenbus/xenbus.c stubdom/Makefile
line diff
     1.1 --- a/extras/mini-os/Config.mk	Fri Jul 04 16:27:44 2008 +0100
     1.2 +++ b/extras/mini-os/Config.mk	Fri Jul 04 17:47:11 2008 +0100
     1.3 @@ -38,15 +38,15 @@ EXTRA_INC = $(ARCH_INC)
     1.4  # This must be before include minios.mk!
     1.5  include $(MINI-OS_ROOT)/$(TARGET_ARCH_DIR)/arch.mk
     1.6  
     1.7 -extra_incl := $(foreach dir,$(EXTRA_INC),-I$(MINI-OS_ROOT)/include/$(dir))
     1.8 +extra_incl := $(foreach dir,$(EXTRA_INC),-I$(realpath $(MINI-OS_ROOT)/include/$(dir)))
     1.9  
    1.10 -DEF_CPPFLAGS += -I$(MINI-OS_ROOT)/include
    1.11 +DEF_CPPFLAGS += -I$(realpath $(MINI-OS_ROOT)/include)
    1.12  DEF_CPPFLAGS += -D__MINIOS__
    1.13  
    1.14  ifeq ($(libc),y)
    1.15  DEF_CPPFLAGS += -DHAVE_LIBC
    1.16 -DEF_CPPFLAGS += -I$(MINI-OS_ROOT)/include/posix
    1.17 -DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/xenstore
    1.18 +DEF_CPPFLAGS += -I$(realpath $(MINI-OS_ROOT)/include/posix)
    1.19 +DEF_CPPFLAGS += -I$(realpath $(XEN_ROOT)/tools/xenstore)
    1.20  endif
    1.21  
    1.22  ifneq ($(LWIPDIR),)
     2.1 --- a/extras/mini-os/arch/x86/mm.c	Fri Jul 04 16:27:44 2008 +0100
     2.2 +++ b/extras/mini-os/arch/x86/mm.c	Fri Jul 04 17:47:11 2008 +0100
     2.3 @@ -549,7 +549,7 @@ void arch_init_p2m(unsigned long max_pfn
     2.4  #define L2_P2M_MASK     (L2_P2M_ENTRIES - 1)    
     2.5  #define L3_P2M_MASK     (L3_P2M_ENTRIES - 1)    
     2.6      
     2.7 -    unsigned long *l1_list, *l2_list, *l3_list;
     2.8 +    unsigned long *l1_list = NULL, *l2_list = NULL, *l3_list;
     2.9      unsigned long pfn;
    2.10      
    2.11      l3_list = (unsigned long *)alloc_page(); 
     3.1 --- a/extras/mini-os/blkfront.c	Fri Jul 04 16:27:44 2008 +0100
     3.2 +++ b/extras/mini-os/blkfront.c	Fri Jul 04 17:47:11 2008 +0100
     3.3 @@ -84,7 +84,7 @@ static void free_blkfront(struct blkfron
     3.4      free(dev);
     3.5  }
     3.6  
     3.7 -struct blkfront_dev *init_blkfront(char *nodename, struct blkfront_info *info)
     3.8 +struct blkfront_dev *init_blkfront(char *_nodename, struct blkfront_info *info)
     3.9  {
    3.10      xenbus_transaction_t xbt;
    3.11      char* err;
    3.12 @@ -93,12 +93,10 @@ struct blkfront_dev *init_blkfront(char 
    3.13      int retry=0;
    3.14      char* msg;
    3.15      char* c;
    3.16 +    char* nodename = _nodename ? _nodename : "device/vbd/768";
    3.17  
    3.18      struct blkfront_dev *dev;
    3.19  
    3.20 -    if (!nodename)
    3.21 -        nodename = "device/vbd/768";
    3.22 -
    3.23      char path[strlen(nodename) + 1 + 10 + 1];
    3.24  
    3.25      printk("******************* BLKFRONT for %s **********\n\n\n", nodename);
    3.26 @@ -342,13 +340,14 @@ static void blkfront_aio_cb(struct blkfr
    3.27  void blkfront_io(struct blkfront_aiocb *aiocbp, int write)
    3.28  {
    3.29      unsigned long flags;
    3.30 +    DEFINE_WAIT(w);
    3.31 +
    3.32      ASSERT(!aiocbp->aio_cb);
    3.33      aiocbp->aio_cb = blkfront_aio_cb;
    3.34      blkfront_aio(aiocbp, write);
    3.35      aiocbp->data = NULL;
    3.36  
    3.37      local_irq_save(flags);
    3.38 -    DEFINE_WAIT(w);
    3.39      while (1) {
    3.40  	blkfront_aio_poll(aiocbp->aio_dev);
    3.41  	if (aiocbp->data)
    3.42 @@ -393,6 +392,7 @@ void blkfront_aio_push_operation(struct 
    3.43  void blkfront_sync(struct blkfront_dev *dev)
    3.44  {
    3.45      unsigned long flags;
    3.46 +    DEFINE_WAIT(w);
    3.47  
    3.48      if (dev->info.mode == O_RDWR) {
    3.49          if (dev->info.barrier == 1)
    3.50 @@ -404,7 +404,6 @@ void blkfront_sync(struct blkfront_dev *
    3.51  
    3.52      /* Note: This won't finish if another thread enqueues requests.  */
    3.53      local_irq_save(flags);
    3.54 -    DEFINE_WAIT(w);
    3.55      while (1) {
    3.56  	blkfront_aio_poll(dev);
    3.57  	if (RING_FREE_REQUESTS(&dev->ring) == RING_SIZE(&dev->ring))
    3.58 @@ -424,6 +423,7 @@ int blkfront_aio_poll(struct blkfront_de
    3.59      RING_IDX rp, cons;
    3.60      struct blkif_response *rsp;
    3.61      int more;
    3.62 +    int nr_consumed;
    3.63  
    3.64  moretodo:
    3.65  #ifdef HAVE_LIBC
    3.66 @@ -437,14 +437,17 @@ moretodo:
    3.67      rmb(); /* Ensure we see queued responses up to 'rp'. */
    3.68      cons = dev->ring.rsp_cons;
    3.69  
    3.70 -    int nr_consumed = 0;
    3.71 +    nr_consumed = 0;
    3.72      while ((cons != rp))
    3.73      {
    3.74 +        struct blkfront_aiocb *aiocbp;
    3.75 +        int status;
    3.76 +
    3.77  	rsp = RING_GET_RESPONSE(&dev->ring, cons);
    3.78  	nr_consumed++;
    3.79  
    3.80 -        struct blkfront_aiocb *aiocbp = (void*) (uintptr_t) rsp->id;
    3.81 -        int status = rsp->status;
    3.82 +        aiocbp = (void*) (uintptr_t) rsp->id;
    3.83 +        status = rsp->status;
    3.84  
    3.85          if (status != BLKIF_RSP_OKAY)
    3.86              printk("block error %d for op %d\n", status, rsp->operation);
     4.1 --- a/extras/mini-os/events.c	Fri Jul 04 16:27:44 2008 +0100
     4.2 +++ b/extras/mini-os/events.c	Fri Jul 04 17:47:11 2008 +0100
     4.3 @@ -207,10 +207,11 @@ void default_handler(evtchn_port_t port,
     4.4  int evtchn_alloc_unbound(domid_t pal, evtchn_handler_t handler,
     4.5  						 void *data, evtchn_port_t *port)
     4.6  {
     4.7 +    int err;
     4.8      evtchn_alloc_unbound_t op;
     4.9      op.dom = DOMID_SELF;
    4.10      op.remote_dom = pal;
    4.11 -    int err = HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound, &op);
    4.12 +    err = HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound, &op);
    4.13      if (err)
    4.14  		return err;
    4.15      *port = bind_evtchn(op.port, handler, data);
    4.16 @@ -224,13 +225,15 @@ int evtchn_bind_interdomain(domid_t pal,
    4.17  			    evtchn_handler_t handler, void *data,
    4.18  			    evtchn_port_t *local_port)
    4.19  {
    4.20 +    int err;
    4.21 +    evtchn_port_t port;
    4.22      evtchn_bind_interdomain_t op;
    4.23      op.remote_dom = pal;
    4.24      op.remote_port = remote_port;
    4.25 -    int err = HYPERVISOR_event_channel_op(EVTCHNOP_bind_interdomain, &op);
    4.26 +    err = HYPERVISOR_event_channel_op(EVTCHNOP_bind_interdomain, &op);
    4.27      if (err)
    4.28  		return err;
    4.29 -    evtchn_port_t port = op.local_port;
    4.30 +    port = op.local_port;
    4.31      *local_port = bind_evtchn(port, handler, data);
    4.32      return err;
    4.33  }
     5.1 --- a/extras/mini-os/fbfront.c	Fri Jul 04 16:27:44 2008 +0100
     5.2 +++ b/extras/mini-os/fbfront.c	Fri Jul 04 17:47:11 2008 +0100
     5.3 @@ -64,7 +64,7 @@ static void free_kbdfront(struct kbdfron
     5.4      free(dev);
     5.5  }
     5.6  
     5.7 -struct kbdfront_dev *init_kbdfront(char *nodename, int abs_pointer)
     5.8 +struct kbdfront_dev *init_kbdfront(char *_nodename, int abs_pointer)
     5.9  {
    5.10      xenbus_transaction_t xbt;
    5.11      char* err;
    5.12 @@ -72,12 +72,9 @@ struct kbdfront_dev *init_kbdfront(char 
    5.13      struct xenkbd_page *s;
    5.14      int retry=0;
    5.15      char* msg;
    5.16 -
    5.17 +    char* nodename = _nodename ? _nodename : "device/vkbd/0";
    5.18      struct kbdfront_dev *dev;
    5.19  
    5.20 -    if (!nodename)
    5.21 -        nodename = "device/vkbd/0";
    5.22 -
    5.23      char path[strlen(nodename) + 1 + 10 + 1];
    5.24  
    5.25      printk("******************* KBDFRONT for %s **********\n\n\n", nodename);
    5.26 @@ -351,7 +348,7 @@ int fbfront_receive(struct fbfront_dev *
    5.27      return i;
    5.28  }
    5.29  
    5.30 -struct fbfront_dev *init_fbfront(char *nodename, unsigned long *mfns, int width, int height, int depth, int stride, int n)
    5.31 +struct fbfront_dev *init_fbfront(char *_nodename, unsigned long *mfns, int width, int height, int depth, int stride, int n)
    5.32  {
    5.33      xenbus_transaction_t xbt;
    5.34      char* err;
    5.35 @@ -361,9 +358,9 @@ struct fbfront_dev *init_fbfront(char *n
    5.36      char* msg;
    5.37      int i, j;
    5.38      struct fbfront_dev *dev;
    5.39 -
    5.40 -    if (!nodename)
    5.41 -        nodename = "device/vfb/0";
    5.42 +    int max_pd;
    5.43 +    unsigned long mapped;
    5.44 +    char* nodename = _nodename ? _nodename : "device/vfb/0";
    5.45  
    5.46      char path[strlen(nodename) + 1 + 10 + 1];
    5.47  
    5.48 @@ -392,8 +389,8 @@ struct fbfront_dev *init_fbfront(char *n
    5.49      dev->offset = 0;
    5.50      dev->events = NULL;
    5.51  
    5.52 -    const int max_pd = sizeof(s->pd) / sizeof(s->pd[0]);
    5.53 -    unsigned long mapped = 0;
    5.54 +    max_pd = sizeof(s->pd) / sizeof(s->pd[0]);
    5.55 +    mapped = 0;
    5.56  
    5.57      for (i = 0; mapped < n && i < max_pd; i++) {
    5.58          unsigned long *pd = (unsigned long *) alloc_page();
     6.1 --- a/extras/mini-os/hypervisor.c	Fri Jul 04 16:27:44 2008 +0100
     6.2 +++ b/extras/mini-os/hypervisor.c	Fri Jul 04 17:47:11 2008 +0100
     6.3 @@ -72,9 +72,10 @@ void do_hypervisor_callback(struct pt_re
     6.4  
     6.5  void force_evtchn_callback(void)
     6.6  {
     6.7 +    int save;
     6.8      vcpu_info_t *vcpu;
     6.9      vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()];
    6.10 -    int save = vcpu->evtchn_upcall_mask;
    6.11 +    save = vcpu->evtchn_upcall_mask;
    6.12  
    6.13      while (vcpu->evtchn_upcall_pending) {
    6.14          vcpu->evtchn_upcall_mask = 1;
     7.1 --- a/extras/mini-os/include/ctype.h	Fri Jul 04 16:27:44 2008 +0100
     7.2 +++ b/extras/mini-os/include/ctype.h	Fri Jul 04 17:47:11 2008 +0100
     7.3 @@ -1,6 +1,9 @@
     7.4  #ifndef _CTYPE_H
     7.5  #define _CTYPE_H
     7.6  
     7.7 +#ifdef HAVE_LIBC
     7.8 +#include_next <ctype.h>
     7.9 +#else
    7.10  /*
    7.11   * NOTE! This ctype does not handle EOF like the standard C
    7.12   * library is required to.
    7.13 @@ -53,3 +56,5 @@ static inline unsigned char __toupper(un
    7.14  #define toupper(c) __toupper(c)
    7.15  
    7.16  #endif
    7.17 +
    7.18 +#endif
     8.1 --- a/extras/mini-os/include/errno.h	Fri Jul 04 16:27:44 2008 +0100
     8.2 +++ b/extras/mini-os/include/errno.h	Fri Jul 04 17:47:11 2008 +0100
     8.3 @@ -3,6 +3,8 @@
     8.4  
     8.5  #include <errno-base.h>
     8.6  
     8.7 +typedef int error_t;
     8.8 +
     8.9  #define	EDEADLK		35	/* Resource deadlock would occur */
    8.10  #define	ENAMETOOLONG	36	/* File name too long */
    8.11  #define	ENOLCK		37	/* No record locks available */
    8.12 @@ -107,6 +109,9 @@
    8.13  #define	EOWNERDEAD	130	/* Owner died */
    8.14  #define	ENOTRECOVERABLE	131	/* State not recoverable */
    8.15  
    8.16 +
    8.17 +#define EFTYPE          132     /* Inappropriate file type or format */
    8.18 +
    8.19  #ifdef HAVE_LIBC
    8.20  #include <sched.h>
    8.21  extern int errno;
     9.1 --- a/extras/mini-os/include/ia64/arch_spinlock.h	Fri Jul 04 16:27:44 2008 +0100
     9.2 +++ b/extras/mini-os/include/ia64/arch_spinlock.h	Fri Jul 04 17:47:11 2008 +0100
     9.3 @@ -27,7 +27,7 @@
     9.4  
     9.5  #include "atomic.h"
     9.6  
     9.7 -#define ARCH_SPIN_LOCK_UNLOCKED (spinlock_t) { 0 }
     9.8 +#define ARCH_SPIN_LOCK_UNLOCKED { 0 }
     9.9  
    9.10  #define SPIN_LOCK_UNUSED	0
    9.11  #define SPIN_LOCK_USED		1
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/extras/mini-os/include/sys/lock.h	Fri Jul 04 17:47:11 2008 +0100
    10.3 @@ -0,0 +1,52 @@
    10.4 +#ifndef _MINIOS_SYS_LOCK_H_
    10.5 +#define _MINIOS_SYS_LOCK_H_
    10.6 +
    10.7 +#ifdef HAVE_LIBC
    10.8 +
    10.9 +/* Due to inclusion loop, we can not include sched.h, so have to hide things */
   10.10 +
   10.11 +#include <waittypes.h>
   10.12 +
   10.13 +
   10.14 +typedef struct {
   10.15 +        int busy;
   10.16 +        struct wait_queue_head wait;
   10.17 +} _LOCK_T;
   10.18 +
   10.19 +#define __LOCK_INIT(class,lock) \
   10.20 +    class _LOCK_T lock = { .wait = __WAIT_QUEUE_HEAD_INITIALIZER(lock.wait) }
   10.21 +int ___lock_init(_LOCK_T *lock);
   10.22 +int ___lock_acquire(_LOCK_T *lock);
   10.23 +int ___lock_try_acquire(_LOCK_T *lock);
   10.24 +int ___lock_release(_LOCK_T *lock);
   10.25 +int ___lock_close(_LOCK_T *lock);
   10.26 +#define __lock_init(__lock) ___lock_init(&__lock)
   10.27 +#define __lock_acquire(__lock) ___lock_acquire(&__lock)
   10.28 +#define __lock_release(__lock) ___lock_release(&__lock)
   10.29 +#define __lock_try_acquire(__lock) ___lock_try_acquire(&__lock)
   10.30 +#define __lock_close(__lock) 0
   10.31 +
   10.32 +
   10.33 +typedef struct {
   10.34 +    struct thread *owner;
   10.35 +    int count;
   10.36 +    struct wait_queue_head wait;
   10.37 +} _LOCK_RECURSIVE_T;
   10.38 +
   10.39 +#define __LOCK_INIT_RECURSIVE(class, lock) \
   10.40 +    class _LOCK_RECURSIVE_T lock = { .wait = __WAIT_QUEUE_HEAD_INITIALIZER((lock).wait) }
   10.41 +
   10.42 +int ___lock_init_recursive(_LOCK_RECURSIVE_T *lock);
   10.43 +int ___lock_acquire_recursive(_LOCK_RECURSIVE_T *lock);
   10.44 +int ___lock_try_acquire_recursive(_LOCK_RECURSIVE_T *lock);
   10.45 +int ___lock_release_recursive(_LOCK_RECURSIVE_T *lock);
   10.46 +int ___lock_close_recursive(_LOCK_RECURSIVE_T *lock);
   10.47 +#define __lock_init_recursive(__lock) ___lock_init_recursive(&__lock)
   10.48 +#define __lock_acquire_recursive(__lock) ___lock_acquire_recursive(&__lock)
   10.49 +#define __lock_release_recursive(__lock) ___lock_release_recursive(&__lock)
   10.50 +#define __lock_try_acquire_recursive(__lock) ___lock_try_acquire_recursive(&__lock)
   10.51 +#define __lock_close_recursive(__lock) 0
   10.52 +
   10.53 +#endif
   10.54 +
   10.55 +#endif /* _MINIOS_SYS_LOCK_H_ */
    11.1 --- a/extras/mini-os/include/types.h	Fri Jul 04 16:27:44 2008 +0100
    11.2 +++ b/extras/mini-os/include/types.h	Fri Jul 04 17:47:11 2008 +0100
    11.3 @@ -36,9 +36,11 @@ typedef unsigned long       u64;
    11.4  #endif
    11.5  
    11.6  /* FreeBSD compat types */
    11.7 +#ifndef HAVE_LIBC
    11.8  typedef unsigned char       u_char;
    11.9  typedef unsigned int        u_int;
   11.10  typedef unsigned long       u_long;
   11.11 +#endif
   11.12  #ifdef __i386__
   11.13  typedef long long           quad_t;
   11.14  typedef unsigned long long  u_quad_t;
   11.15 @@ -79,11 +81,14 @@ typedef s32 int32_t;
   11.16  typedef u64 uint64_t, uintmax_t;
   11.17  typedef s64 int64_t, intmax_t;
   11.18  typedef u64 off_t;
   11.19 +#endif
   11.20 +
   11.21 +typedef intptr_t            ptrdiff_t;
   11.22  
   11.23  
   11.24 -#define INT_MAX         ((int)(~0U>>1))
   11.25 -#define UINT_MAX            (~0U)
   11.26 -
   11.27 +#ifndef HAVE_LIBC
   11.28  typedef long ssize_t;
   11.29  #endif
   11.30 +typedef unsigned long size_t;
   11.31 +
   11.32  #endif /* _TYPES_H_ */
    12.1 --- a/extras/mini-os/include/wait.h	Fri Jul 04 16:27:44 2008 +0100
    12.2 +++ b/extras/mini-os/include/wait.h	Fri Jul 04 17:47:11 2008 +0100
    12.3 @@ -2,29 +2,8 @@
    12.4  #define __WAIT_H__
    12.5  
    12.6  #include <sched.h>
    12.7 -#include <list.h>
    12.8 -#include <lib.h>
    12.9  #include <os.h>
   12.10 -
   12.11 -struct wait_queue
   12.12 -{
   12.13 -    struct thread *thread;
   12.14 -    struct list_head thread_list;
   12.15 -};
   12.16 -
   12.17 -struct wait_queue_head
   12.18 -{
   12.19 -    /* TODO - lock required? */
   12.20 -    struct list_head thread_list;
   12.21 -};
   12.22 -
   12.23 -#define DECLARE_WAIT_QUEUE_HEAD(name) \
   12.24 -   struct wait_queue_head name =     \
   12.25 -        { .thread_list = { &(name).thread_list, &(name).thread_list} }
   12.26 -
   12.27 -#define __WAIT_QUEUE_HEAD_INITIALIZER(name) {                           \
   12.28 -    .thread_list      = { &(name).thread_list, &(name).thread_list } }
   12.29 -
   12.30 +#include <waittypes.h>
   12.31  
   12.32  #define DEFINE_WAIT(name)                               \
   12.33  struct wait_queue name = {                              \
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/extras/mini-os/include/waittypes.h	Fri Jul 04 17:47:11 2008 +0100
    13.3 @@ -0,0 +1,26 @@
    13.4 +#ifndef __WAITTYPE_H__
    13.5 +#define __WAITTYPE_H__
    13.6 +
    13.7 +#include <list.h>
    13.8 +
    13.9 +struct thread;
   13.10 +struct wait_queue
   13.11 +{
   13.12 +    struct thread *thread;
   13.13 +    struct list_head thread_list;
   13.14 +};
   13.15 +
   13.16 +struct wait_queue_head
   13.17 +{
   13.18 +    /* TODO - lock required? */
   13.19 +    struct list_head thread_list;
   13.20 +};
   13.21 +
   13.22 +#define DECLARE_WAIT_QUEUE_HEAD(name) \
   13.23 +   struct wait_queue_head name =     \
   13.24 +        { .thread_list = { &(name).thread_list, &(name).thread_list} }
   13.25 +
   13.26 +#define __WAIT_QUEUE_HEAD_INITIALIZER(name) {                           \
   13.27 +    .thread_list      = { &(name).thread_list, &(name).thread_list } }
   13.28 +
   13.29 +#endif
    14.1 --- a/extras/mini-os/include/x86/arch_spinlock.h	Fri Jul 04 16:27:44 2008 +0100
    14.2 +++ b/extras/mini-os/include/x86/arch_spinlock.h	Fri Jul 04 17:47:11 2008 +0100
    14.3 @@ -7,7 +7,7 @@
    14.4  #include "os.h"
    14.5  
    14.6  
    14.7 -#define ARCH_SPIN_LOCK_UNLOCKED (spinlock_t) { 1 }
    14.8 +#define ARCH_SPIN_LOCK_UNLOCKED { 1 }
    14.9  
   14.10  /*
   14.11   * Simple spin lock operations.  There are two variants, one clears IRQ's
    15.1 --- a/extras/mini-os/include/xmalloc.h	Fri Jul 04 16:27:44 2008 +0100
    15.2 +++ b/extras/mini-os/include/xmalloc.h	Fri Jul 04 17:47:11 2008 +0100
    15.3 @@ -11,6 +11,8 @@
    15.4  
    15.5  #else
    15.6  
    15.7 +#include <limits.h>
    15.8 +
    15.9  #define DEFAULT_ALIGN (sizeof(unsigned long))
   15.10  #define malloc(size) _xmalloc(size, DEFAULT_ALIGN)
   15.11  #define free(ptr) xfree(ptr)
    16.1 --- a/extras/mini-os/kernel.c	Fri Jul 04 16:27:44 2008 +0100
    16.2 +++ b/extras/mini-os/kernel.c	Fri Jul 04 17:47:11 2008 +0100
    16.3 @@ -449,6 +449,8 @@ static void pcifront_thread(void *p)
    16.4      }
    16.5  
    16.6      pci_dev = init_pcifront(NULL);
    16.7 +    if (!pci_dev)
    16.8 +        return;
    16.9      printk("PCI devices:\n");
   16.10      pcifront_scan(pci_dev, print);
   16.11  }
    17.1 --- a/extras/mini-os/lib/ctype.c	Fri Jul 04 16:27:44 2008 +0100
    17.2 +++ b/extras/mini-os/lib/ctype.c	Fri Jul 04 17:47:11 2008 +0100
    17.3 @@ -1,3 +1,4 @@
    17.4 +#ifndef HAVE_LIBC
    17.5  #include <ctype.h>
    17.6  
    17.7  unsigned char _ctype[] = {
    17.8 @@ -25,3 +26,4 @@ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,        
    17.9  _U,_U,_U,_U,_U,_U,_U,_P,_U,_U,_U,_U,_U,_U,_U,_L,       /* 208-223 */
   17.10  _L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,       /* 224-239 */
   17.11  _L,_L,_L,_L,_L,_L,_L,_P,_L,_L,_L,_L,_L,_L,_L,_L};      /* 240-255 */
   17.12 +#endif
    18.1 --- a/extras/mini-os/lib/printf.c	Fri Jul 04 16:27:44 2008 +0100
    18.2 +++ b/extras/mini-os/lib/printf.c	Fri Jul 04 17:47:11 2008 +0100
    18.3 @@ -62,6 +62,7 @@
    18.4  #include <lib.h>
    18.5  #include <mm.h>
    18.6  #include <ctype.h>
    18.7 +#include <limits.h>
    18.8  
    18.9  /**
   18.10   * simple_strtoul - convert a string to an unsigned long
    19.1 --- a/extras/mini-os/lib/xmalloc.c	Fri Jul 04 16:27:44 2008 +0100
    19.2 +++ b/extras/mini-os/lib/xmalloc.c	Fri Jul 04 17:47:11 2008 +0100
    19.3 @@ -139,7 +139,7 @@ static void *xmalloc_whole_pages(size_t 
    19.4  
    19.5  void *_xmalloc(size_t size, size_t align)
    19.6  {
    19.7 -    struct xmalloc_hdr *i, *hdr = NULL;
    19.8 +    struct xmalloc_hdr *i, *tmp, *hdr = NULL;
    19.9      uintptr_t data_begin;
   19.10      size_t hdr_size;
   19.11      /* unsigned long flags; */
   19.12 @@ -155,7 +155,7 @@ void *_xmalloc(size_t size, size_t align
   19.13  
   19.14      /* Search free list. */
   19.15      /* spin_lock_irqsave(&freelist_lock, flags); */
   19.16 -    list_for_each_entry( i, &freelist, freelist )
   19.17 +    list_for_each_entry_safe( i, tmp, &freelist, freelist )
   19.18      {
   19.19          data_begin = align_up((uintptr_t)i + hdr_size, align);
   19.20  
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/extras/mini-os/lock.c	Fri Jul 04 17:47:11 2008 +0100
    20.3 @@ -0,0 +1,111 @@
    20.4 +/*
    20.5 + * locks for newlib
    20.6 + *
    20.7 + * Samuel Thibault <Samuel.Thibault@eu.citrix.net>, July 20008
    20.8 + */
    20.9 +
   20.10 +#ifdef HAVE_LIBC
   20.11 +
   20.12 +#include <sys/lock.h>
   20.13 +#include <sched.h>
   20.14 +#include <wait.h>
   20.15 +
   20.16 +int ___lock_init(_LOCK_T *lock)
   20.17 +{
   20.18 +    lock->busy = 0;
   20.19 +    init_waitqueue_head(&lock->wait);
   20.20 +    return 0;
   20.21 +}
   20.22 +
   20.23 +int ___lock_acquire(_LOCK_T *lock)
   20.24 +{
   20.25 +    unsigned long flags;
   20.26 +    while(1) {
   20.27 +        wait_event(lock->wait, !lock->busy);
   20.28 +        local_irq_save(flags);
   20.29 +        if (!lock->busy)
   20.30 +            break;
   20.31 +        local_irq_restore(flags);
   20.32 +    }
   20.33 +    lock->busy = 1;
   20.34 +    local_irq_restore(flags);
   20.35 +    return 0;
   20.36 +}
   20.37 +
   20.38 +int ___lock_try_acquire(_LOCK_T *lock)
   20.39 +{
   20.40 +    unsigned long flags;
   20.41 +    int ret = -1;
   20.42 +    local_irq_save(flags);
   20.43 +    if (!lock->busy) {
   20.44 +        lock->busy = 1;
   20.45 +        ret = 0;
   20.46 +    }
   20.47 +    local_irq_restore(flags);
   20.48 +    return ret;
   20.49 +}
   20.50 +
   20.51 +int ___lock_release(_LOCK_T *lock)
   20.52 +{
   20.53 +    unsigned long flags;
   20.54 +    local_irq_save(flags);
   20.55 +    lock->busy = 0;
   20.56 +    wake_up(&lock->wait);
   20.57 +    local_irq_restore(flags);
   20.58 +    return 0;
   20.59 +}
   20.60 +
   20.61 +
   20.62 +int ___lock_init_recursive(_LOCK_RECURSIVE_T *lock)
   20.63 +{
   20.64 +    lock->owner = NULL;
   20.65 +    init_waitqueue_head(&lock->wait);
   20.66 +    return 0;
   20.67 +}
   20.68 +
   20.69 +int ___lock_acquire_recursive(_LOCK_RECURSIVE_T *lock)
   20.70 +{
   20.71 +    unsigned long flags;
   20.72 +    if (lock->owner != get_current()) {
   20.73 +        while (1) {
   20.74 +            wait_event(lock->wait, lock->owner == NULL);
   20.75 +            local_irq_save(flags);
   20.76 +            if (lock->owner == NULL)
   20.77 +                break;
   20.78 +            local_irq_restore(flags);
   20.79 +        }
   20.80 +        lock->owner = get_current();
   20.81 +        local_irq_restore(flags);
   20.82 +    }
   20.83 +    lock->count++;
   20.84 +    return 0;
   20.85 +}
   20.86 +
   20.87 +int ___lock_try_acquire_recursive(_LOCK_RECURSIVE_T *lock)
   20.88 +{
   20.89 +    unsigned long flags;
   20.90 +    int ret = -1;
   20.91 +    local_irq_save(flags);
   20.92 +    if (!lock->owner) {
   20.93 +        ret = 0;
   20.94 +        lock->owner = get_current();
   20.95 +        lock->count++;
   20.96 +    }
   20.97 +    local_irq_restore(flags);
   20.98 +    return ret;
   20.99 +}
  20.100 +
  20.101 +int ___lock_release_recursive(_LOCK_RECURSIVE_T *lock)
  20.102 +{
  20.103 +    unsigned long flags;
  20.104 +    BUG_ON(lock->owner != get_current());
  20.105 +    if (--lock->count)
  20.106 +        return 0;
  20.107 +    local_irq_save(flags);
  20.108 +    lock->owner = NULL;
  20.109 +    wake_up(&lock->wait);
  20.110 +    local_irq_restore(flags);
  20.111 +    return 0;
  20.112 +}
  20.113 +
  20.114 +#endif
    21.1 --- a/extras/mini-os/lwip-net.c	Fri Jul 04 16:27:44 2008 +0100
    21.2 +++ b/extras/mini-os/lwip-net.c	Fri Jul 04 17:47:11 2008 +0100
    21.3 @@ -93,6 +93,9 @@ static err_t netfront_output(struct neti
    21.4  static err_t
    21.5  low_level_output(struct netif *netif, struct pbuf *p)
    21.6  {
    21.7 +  if (!dev)
    21.8 +    return ERR_OK;
    21.9 +
   21.10  #ifdef ETH_PAD_SIZE
   21.11    pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
   21.12  #endif
   21.13 @@ -342,7 +345,7 @@ void start_networking(void)
   21.14    struct ip_addr ipaddr = { htonl(IF_IPADDR) };
   21.15    struct ip_addr netmask = { htonl(IF_NETMASK) };
   21.16    struct ip_addr gw = { 0 };
   21.17 -  char *ip;
   21.18 +  char *ip = NULL;
   21.19  
   21.20    tprintk("Waiting for network.\n");
   21.21  
   21.22 @@ -380,5 +383,6 @@ void start_networking(void)
   21.23  /* Shut down the network */
   21.24  void stop_networking(void)
   21.25  {
   21.26 -  shutdown_netfront(dev);
   21.27 +  if (dev)
   21.28 +    shutdown_netfront(dev);
   21.29  }
    22.1 --- a/extras/mini-os/main.c	Fri Jul 04 16:27:44 2008 +0100
    22.2 +++ b/extras/mini-os/main.c	Fri Jul 04 17:47:11 2008 +0100
    22.3 @@ -52,6 +52,7 @@ static void call_main(void *p)
    22.4  #ifdef CONFIG_QEMU
    22.5      char *vm;
    22.6      char path[128];
    22.7 +    int domid;
    22.8  #endif
    22.9      int i;
   22.10  
   22.11 @@ -74,7 +75,6 @@ static void call_main(void *p)
   22.12      }
   22.13  
   22.14      /* Fetch argc, argv from XenStore */
   22.15 -    int domid;
   22.16      domid = xenbus_read_integer("target");
   22.17      if (domid == -1) {
   22.18          printk("Couldn't read target\n");
    23.1 --- a/extras/mini-os/minios.mk	Fri Jul 04 16:27:44 2008 +0100
    23.2 +++ b/extras/mini-os/minios.mk	Fri Jul 04 17:47:11 2008 +0100
    23.3 @@ -6,13 +6,14 @@ debug = y
    23.4  
    23.5  # Define some default flags.
    23.6  # NB. '-Wcast-qual' is nasty, so I omitted it.
    23.7 -DEF_CFLAGS += -fno-builtin -Wall -Werror -Wredundant-decls -Wno-format
    23.8 +DEF_CFLAGS += -fno-builtin -Wall -Werror -Wredundant-decls -Wno-format -Wno-redundant-decls
    23.9  DEF_CFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
   23.10 +DEF_CFLAGS += $(call cc-option,$(CC),-fgnu89-inline)
   23.11  DEF_CFLAGS += -Wstrict-prototypes -Wnested-externs -Wpointer-arith -Winline
   23.12  DEF_CPPFLAGS += -D__XEN_INTERFACE_VERSION__=$(XEN_INTERFACE_VERSION)
   23.13  
   23.14 -DEF_ASFLAGS = -D__ASSEMBLY__
   23.15 -DEF_LDFLAGS =
   23.16 +DEF_ASFLAGS += -D__ASSEMBLY__
   23.17 +DEF_LDFLAGS +=
   23.18  
   23.19  ifeq ($(debug),y)
   23.20  DEF_CFLAGS += -g
    24.1 --- a/extras/mini-os/mm.c	Fri Jul 04 16:27:44 2008 +0100
    24.2 +++ b/extras/mini-os/mm.c	Fri Jul 04 17:47:11 2008 +0100
    24.3 @@ -361,6 +361,7 @@ void free_pages(void *pointer, int order
    24.4     
    24.5  }
    24.6  
    24.7 +#ifndef __ia64__
    24.8  int free_physical_pages(xen_pfn_t *mfns, int n)
    24.9  {
   24.10      struct xen_memory_reservation reservation;
   24.11 @@ -371,6 +372,7 @@ int free_physical_pages(xen_pfn_t *mfns,
   24.12      reservation.domid = DOMID_SELF;
   24.13      return HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation);
   24.14  }
   24.15 +#endif
   24.16  
   24.17  #ifdef HAVE_LIBC
   24.18  void *sbrk(ptrdiff_t increment)
    25.1 --- a/extras/mini-os/netfront.c	Fri Jul 04 16:27:44 2008 +0100
    25.2 +++ b/extras/mini-os/netfront.c	Fri Jul 04 17:47:11 2008 +0100
    25.3 @@ -95,8 +95,9 @@ static inline int xennet_rxidx(RING_IDX 
    25.4  
    25.5  void network_rx(struct netfront_dev *dev)
    25.6  {
    25.7 -    RING_IDX rp,cons;
    25.8 +    RING_IDX rp,cons,req_prod;
    25.9      struct netif_rx_response *rx;
   25.10 +    int nr_consumed, some, more, i, notify;
   25.11  
   25.12  
   25.13  moretodo:
   25.14 @@ -104,12 +105,13 @@ moretodo:
   25.15      rmb(); /* Ensure we see queued responses up to 'rp'. */
   25.16      cons = dev->rx.rsp_cons;
   25.17  
   25.18 -    int nr_consumed=0;
   25.19 -    int some = 0;
   25.20 +    nr_consumed = 0;
   25.21 +    some = 0;
   25.22      while ((cons != rp) && !some)
   25.23      {
   25.24          struct net_buffer* buf;
   25.25          unsigned char* page;
   25.26 +        int id;
   25.27  
   25.28          rx = RING_GET_RESPONSE(&dev->rx, cons);
   25.29  
   25.30 @@ -122,7 +124,7 @@ moretodo:
   25.31  
   25.32          if (rx->status == NETIF_RSP_NULL) continue;
   25.33  
   25.34 -        int id = rx->id;
   25.35 +        id = rx->id;
   25.36          BUG_ON(id >= NET_TX_RING_SIZE);
   25.37  
   25.38          buf = &dev->rx_buffers[id];
   25.39 @@ -151,19 +153,15 @@ moretodo:
   25.40      }
   25.41      dev->rx.rsp_cons=cons;
   25.42  
   25.43 -    int more;
   25.44      RING_FINAL_CHECK_FOR_RESPONSES(&dev->rx,more);
   25.45      if(more && !some) goto moretodo;
   25.46  
   25.47 -    RING_IDX req_prod = dev->rx.req_prod_pvt;
   25.48 -
   25.49 -    int i;
   25.50 -    netif_rx_request_t *req;
   25.51 +    req_prod = dev->rx.req_prod_pvt;
   25.52  
   25.53      for(i=0; i<nr_consumed; i++)
   25.54      {
   25.55          int id = xennet_rxidx(req_prod + i);
   25.56 -        req = RING_GET_REQUEST(&dev->rx, req_prod + i);
   25.57 +        netif_rx_request_t *req = RING_GET_REQUEST(&dev->rx, req_prod + i);
   25.58          struct net_buffer* buf = &dev->rx_buffers[id];
   25.59          void* page = buf->page;
   25.60  
   25.61 @@ -178,7 +176,6 @@ moretodo:
   25.62  
   25.63      dev->rx.req_prod_pvt = req_prod + i;
   25.64      
   25.65 -    int notify;
   25.66      RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&dev->rx, notify);
   25.67      if (notify)
   25.68          notify_remote_via_evtchn(dev->evtchn);
   25.69 @@ -199,6 +196,7 @@ void network_tx_buf_gc(struct netfront_d
   25.70          for (cons = dev->tx.rsp_cons; cons != prod; cons++) 
   25.71          {
   25.72              struct netif_tx_response *txrsp;
   25.73 +            struct net_buffer *buf;
   25.74  
   25.75              txrsp = RING_GET_RESPONSE(&dev->tx, cons);
   25.76              if (txrsp->status == NETIF_RSP_NULL)
   25.77 @@ -209,7 +207,7 @@ void network_tx_buf_gc(struct netfront_d
   25.78  
   25.79              id  = txrsp->id;
   25.80              BUG_ON(id >= NET_TX_RING_SIZE);
   25.81 -            struct net_buffer* buf = &dev->tx_buffers[id];
   25.82 +            buf = &dev->tx_buffers[id];
   25.83              gnttab_end_access(buf->gref);
   25.84              buf->gref=GRANT_INVALID_REF;
   25.85  
   25.86 @@ -298,7 +296,7 @@ static void free_netfront(struct netfron
   25.87      free(dev);
   25.88  }
   25.89  
   25.90 -struct netfront_dev *init_netfront(char *nodename, void (*thenetif_rx)(unsigned char* data, int len), unsigned char rawmac[6], char **ip)
   25.91 +struct netfront_dev *init_netfront(char *_nodename, void (*thenetif_rx)(unsigned char* data, int len), unsigned char rawmac[6], char **ip)
   25.92  {
   25.93      xenbus_transaction_t xbt;
   25.94      char* err;
   25.95 @@ -308,12 +306,10 @@ struct netfront_dev *init_netfront(char 
   25.96      int retry=0;
   25.97      int i;
   25.98      char* msg;
   25.99 +    char* nodename = _nodename ? _nodename : "device/vif/0";
  25.100  
  25.101      struct netfront_dev *dev;
  25.102  
  25.103 -    if (!nodename)
  25.104 -	nodename = "device/vif/0";
  25.105 -
  25.106      char path[strlen(nodename) + 1 + 10 + 1];
  25.107  
  25.108      if (!thenetif_rx)
    26.1 --- a/extras/mini-os/pcifront.c	Fri Jul 04 16:27:44 2008 +0100
    26.2 +++ b/extras/mini-os/pcifront.c	Fri Jul 04 17:47:11 2008 +0100
    26.3 @@ -49,19 +49,17 @@ static void free_pcifront(struct pcifron
    26.4      free(dev);
    26.5  }
    26.6  
    26.7 -struct pcifront_dev *init_pcifront(char *nodename)
    26.8 +struct pcifront_dev *init_pcifront(char *_nodename)
    26.9  {
   26.10      xenbus_transaction_t xbt;
   26.11      char* err;
   26.12      char* message=NULL;
   26.13      int retry=0;
   26.14      char* msg;
   26.15 +    char* nodename = _nodename ? _nodename : "device/pci/0";
   26.16  
   26.17      struct pcifront_dev *dev;
   26.18  
   26.19 -    if (!nodename)
   26.20 -        nodename = "device/pci/0";
   26.21 -
   26.22      char path[strlen(nodename) + 1 + 10 + 1];
   26.23  
   26.24      printk("******************* PCIFRONT for %s **********\n\n\n", nodename);
    27.1 --- a/extras/mini-os/sched.c	Fri Jul 04 16:27:44 2008 +0100
    27.2 +++ b/extras/mini-os/sched.c	Fri Jul 04 17:47:11 2008 +0100
    27.3 @@ -75,7 +75,7 @@ void inline print_runqueue(void)
    27.4  void schedule(void)
    27.5  {
    27.6      struct thread *prev, *next, *thread;
    27.7 -    struct list_head *iterator;
    27.8 +    struct list_head *iterator, *next_iterator;
    27.9      unsigned long flags;
   27.10  
   27.11      prev = current;
   27.12 @@ -97,7 +97,7 @@ void schedule(void)
   27.13          s_time_t now = NOW();
   27.14          s_time_t min_wakeup_time = now + SECONDS(10);
   27.15          next = NULL;   
   27.16 -        list_for_each(iterator, &idle_thread->thread_list)
   27.17 +        list_for_each_safe(iterator, next_iterator, &idle_thread->thread_list)
   27.18          {
   27.19              thread = list_entry(iterator, struct thread, thread_list);
   27.20              if (!is_runnable(thread) && thread->wakeup_time != 0LL)
   27.21 @@ -128,7 +128,7 @@ void schedule(void)
   27.22         inturrupted at the return instruction. And therefore at safe point. */
   27.23      if(prev != next) switch_threads(prev, next);
   27.24  
   27.25 -    list_for_each(iterator, &exited_threads)
   27.26 +    list_for_each_safe(iterator, next_iterator, &exited_threads)
   27.27      {
   27.28          thread = list_entry(iterator, struct thread, thread_list);
   27.29          if(thread != prev)
    28.1 --- a/extras/mini-os/xenbus/xenbus.c	Fri Jul 04 16:27:44 2008 +0100
    28.2 +++ b/extras/mini-os/xenbus/xenbus.c	Fri Jul 04 17:47:11 2008 +0100
    28.3 @@ -78,9 +78,9 @@ static void memcpy_from_ring(const void 
    28.4  char **xenbus_wait_for_watch_return(xenbus_event_queue *queue)
    28.5  {
    28.6      struct xenbus_event *event;
    28.7 +    DEFINE_WAIT(w);
    28.8      if (!queue)
    28.9          queue = &xenbus_events;
   28.10 -    DEFINE_WAIT(w);
   28.11      while (!(event = *queue)) {
   28.12          add_waiter(w, xenbus_watch_queue);
   28.13          schedule();
   28.14 @@ -382,6 +382,7 @@ xenbus_msg_reply(int type,
   28.15  
   28.16  static char *errmsg(struct xsd_sockmsg *rep)
   28.17  {
   28.18 +    char *res;
   28.19      if (!rep) {
   28.20  	char msg[] = "No reply";
   28.21  	size_t len = strlen(msg) + 1;
   28.22 @@ -389,7 +390,7 @@ static char *errmsg(struct xsd_sockmsg *
   28.23      }
   28.24      if (rep->type != XS_ERROR)
   28.25  	return NULL;
   28.26 -    char *res = malloc(rep->len + 1);
   28.27 +    res = malloc(rep->len + 1);
   28.28      memcpy(res, rep + 1, rep->len);
   28.29      res[rep->len] = 0;
   28.30      free(rep);
   28.31 @@ -419,10 +420,10 @@ char *xenbus_ls(xenbus_transaction_t xbt
   28.32      struct xsd_sockmsg *reply, *repmsg;
   28.33      struct write_req req[] = { { pre, strlen(pre)+1 } };
   28.34      int nr_elems, x, i;
   28.35 -    char **res;
   28.36 +    char **res, *msg;
   28.37  
   28.38      repmsg = xenbus_msg_reply(XS_DIRECTORY, xbt, req, ARRAY_SIZE(req));
   28.39 -    char *msg = errmsg(repmsg);
   28.40 +    msg = errmsg(repmsg);
   28.41      if (msg) {
   28.42  	*contents = NULL;
   28.43  	return msg;
   28.44 @@ -447,9 +448,9 @@ char *xenbus_read(xenbus_transaction_t x
   28.45  {
   28.46      struct write_req req[] = { {path, strlen(path) + 1} };
   28.47      struct xsd_sockmsg *rep;
   28.48 -    char *res;
   28.49 +    char *res, *msg;
   28.50      rep = xenbus_msg_reply(XS_READ, xbt, req, ARRAY_SIZE(req));
   28.51 -    char *msg = errmsg(rep);
   28.52 +    msg = errmsg(rep);
   28.53      if (msg) {
   28.54  	*value = NULL;
   28.55  	return msg;
   28.56 @@ -469,8 +470,9 @@ char *xenbus_write(xenbus_transaction_t 
   28.57  	{value, strlen(value)},
   28.58      };
   28.59      struct xsd_sockmsg *rep;
   28.60 +    char *msg;
   28.61      rep = xenbus_msg_reply(XS_WRITE, xbt, req, ARRAY_SIZE(req));
   28.62 -    char *msg = errmsg(rep);
   28.63 +    msg = errmsg(rep);
   28.64      if (msg) return msg;
   28.65      free(rep);
   28.66      return NULL;
   28.67 @@ -487,6 +489,8 @@ char* xenbus_watch_path_token( xenbus_tr
   28.68  
   28.69      struct watch *watch = malloc(sizeof(*watch));
   28.70  
   28.71 +    char *msg;
   28.72 +
   28.73      if (!events)
   28.74          events = &xenbus_events;
   28.75  
   28.76 @@ -497,7 +501,7 @@ char* xenbus_watch_path_token( xenbus_tr
   28.77  
   28.78      rep = xenbus_msg_reply(XS_WATCH, xbt, req, ARRAY_SIZE(req));
   28.79  
   28.80 -    char *msg = errmsg(rep);
   28.81 +    msg = errmsg(rep);
   28.82      if (msg) return msg;
   28.83      free(rep);
   28.84  
   28.85 @@ -515,9 +519,11 @@ char* xenbus_unwatch_path_token( xenbus_
   28.86  
   28.87      struct watch *watch, **prev;
   28.88  
   28.89 +    char *msg;
   28.90 +
   28.91      rep = xenbus_msg_reply(XS_UNWATCH, xbt, req, ARRAY_SIZE(req));
   28.92  
   28.93 -    char *msg = errmsg(rep);
   28.94 +    msg = errmsg(rep);
   28.95      if (msg) return msg;
   28.96      free(rep);
   28.97  
   28.98 @@ -536,8 +542,9 @@ char *xenbus_rm(xenbus_transaction_t xbt
   28.99  {
  28.100      struct write_req req[] = { {path, strlen(path) + 1} };
  28.101      struct xsd_sockmsg *rep;
  28.102 +    char *msg;
  28.103      rep = xenbus_msg_reply(XS_RM, xbt, req, ARRAY_SIZE(req));
  28.104 -    char *msg = errmsg(rep);
  28.105 +    msg = errmsg(rep);
  28.106      if (msg)
  28.107  	return msg;
  28.108      free(rep);
  28.109 @@ -548,9 +555,9 @@ char *xenbus_get_perms(xenbus_transactio
  28.110  {
  28.111      struct write_req req[] = { {path, strlen(path) + 1} };
  28.112      struct xsd_sockmsg *rep;
  28.113 -    char *res;
  28.114 +    char *res, *msg;
  28.115      rep = xenbus_msg_reply(XS_GET_PERMS, xbt, req, ARRAY_SIZE(req));
  28.116 -    char *msg = errmsg(rep);
  28.117 +    msg = errmsg(rep);
  28.118      if (msg) {
  28.119  	*value = NULL;
  28.120  	return msg;
  28.121 @@ -567,14 +574,16 @@ char *xenbus_get_perms(xenbus_transactio
  28.122  char *xenbus_set_perms(xenbus_transaction_t xbt, const char *path, domid_t dom, char perm)
  28.123  {
  28.124      char value[PERM_MAX_SIZE];
  28.125 -    snprintf(value, PERM_MAX_SIZE, "%c%hu", perm, dom);
  28.126      struct write_req req[] = { 
  28.127  	{path, strlen(path) + 1},
  28.128 -	{value, strlen(value) + 1},
  28.129 +	{value, 0},
  28.130      };
  28.131      struct xsd_sockmsg *rep;
  28.132 +    char *msg;
  28.133 +    snprintf(value, PERM_MAX_SIZE, "%c%hu", perm, dom);
  28.134 +    req[1].len = strlen(value) + 1;
  28.135      rep = xenbus_msg_reply(XS_SET_PERMS, xbt, req, ARRAY_SIZE(req));
  28.136 -    char *msg = errmsg(rep);
  28.137 +    msg = errmsg(rep);
  28.138      if (msg)
  28.139  	return msg;
  28.140      free(rep);
  28.141 @@ -659,11 +668,11 @@ char* xenbus_printf(xenbus_transaction_t
  28.142  
  28.143  static void do_ls_test(const char *pre)
  28.144  {
  28.145 -    char **dirs;
  28.146 +    char **dirs, *msg;
  28.147      int x;
  28.148  
  28.149      DEBUG("ls %s...\n", pre);
  28.150 -    char *msg = xenbus_ls(XBT_NIL, pre, &dirs);
  28.151 +    msg = xenbus_ls(XBT_NIL, pre, &dirs);
  28.152      if (msg) {
  28.153  	DEBUG("Error in xenbus ls: %s\n", msg);
  28.154  	free(msg);
  28.155 @@ -679,9 +688,9 @@ static void do_ls_test(const char *pre)
  28.156  
  28.157  static void do_read_test(const char *path)
  28.158  {
  28.159 -    char *res;
  28.160 +    char *res, *msg;
  28.161      DEBUG("Read %s...\n", path);
  28.162 -    char *msg = xenbus_read(XBT_NIL, path, &res);
  28.163 +    msg = xenbus_read(XBT_NIL, path, &res);
  28.164      if (msg) {
  28.165  	DEBUG("Error in xenbus read: %s\n", msg);
  28.166  	free(msg);
  28.167 @@ -693,8 +702,9 @@ static void do_read_test(const char *pat
  28.168  
  28.169  static void do_write_test(const char *path, const char *val)
  28.170  {
  28.171 +    char *msg;
  28.172      DEBUG("Write %s to %s...\n", val, path);
  28.173 -    char *msg = xenbus_write(XBT_NIL, path, val);
  28.174 +    msg = xenbus_write(XBT_NIL, path, val);
  28.175      if (msg) {
  28.176  	DEBUG("Result %s\n", msg);
  28.177  	free(msg);
  28.178 @@ -705,8 +715,9 @@ static void do_write_test(const char *pa
  28.179  
  28.180  static void do_rm_test(const char *path)
  28.181  {
  28.182 +    char *msg;
  28.183      DEBUG("rm %s...\n", path);
  28.184 -    char *msg = xenbus_rm(XBT_NIL, path);
  28.185 +    msg = xenbus_rm(XBT_NIL, path);
  28.186      if (msg) {
  28.187  	DEBUG("Result %s\n", msg);
  28.188  	free(msg);
    29.1 --- a/stubdom/Makefile	Fri Jul 04 16:27:44 2008 +0100
    29.2 +++ b/stubdom/Makefile	Fri Jul 04 17:47:11 2008 +0100
    29.3 @@ -3,13 +3,11 @@ MINI_OS = $(XEN_ROOT)/extras/mini-os
    29.4  
    29.5  export XEN_OS=MiniOS
    29.6  
    29.7 -include $(XEN_ROOT)/Config.mk
    29.8  export stubdom=y
    29.9  export debug=y
   29.10 +include $(XEN_ROOT)/Config.mk
   29.11  
   29.12  IOEMU_OPTIONS=--disable-vnc-tls 
   29.13 -BINUTILS_VERSION=2.18
   29.14 -GCC_VERSION=4.2.2
   29.15  ZLIB_VERSION=1.2.3
   29.16  LIBPCI_VERSION=2.2.9
   29.17  NEWLIB_DATE=2008-01-01
   29.18 @@ -37,57 +35,29 @@ endif
   29.19  
   29.20  CROSS_ROOT=cross-root-$(GNU_TARGET_ARCH)
   29.21  CROSS_PREFIX=$(CURDIR)/$(CROSS_ROOT)
   29.22 -export CROSS_COMPILE=$(GNU_TARGET_ARCH)-xen-elf-
   29.23 -export PATH:=$(CROSS_PREFIX)/bin:$(PATH)
   29.24 +
   29.25 +# Disable PIE/SSP if GCC supports them. They can break us.
   29.26 +TARGET_CFLAGS += $(CFLAGS)
   29.27 +TARGET_CPPFLAGS += $(CPPFLAGS)
   29.28 +TARGET_CFLAGS += $(call cc-option,$(CC),-nopie,)
   29.29 +TARGET_CFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
   29.30 +TARGET_CFLAGS += $(call cc-option,$(CC),-fno-stack-protector-all,)
   29.31 +
   29.32 +# Do not use host headers and libs
   29.33 +GCC_INSTALL = $(shell gcc -print-search-dirs | sed -n -e 's/install: \(.*\)/\1/p')
   29.34 +TARGET_CPPFLAGS += -U __linux__ -U __FreeBSD__ -U __sun__
   29.35 +TARGET_CFLAGS += -nostdinc
   29.36 +TARGET_CPPFLAGS += -isystem $(realpath $(MINI_OS)/include/posix)
   29.37 +TARGET_CPPFLAGS += -isystem $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/include
   29.38 +TARGET_CPPFLAGS += -isystem $(GCC_INSTALL)include
   29.39 +
   29.40 +TARGET_LDFLAGS += -nostdlib -L$(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/lib
   29.41  
   29.42  TARGETS=ioemu c caml grub
   29.43  
   29.44  .PHONY: all
   29.45  all: ioemu-stubdom c-stubdom pv-grub
   29.46  
   29.47 -################
   29.48 -# Cross-binutils
   29.49 -################
   29.50 -
   29.51 -binutils-$(BINUTILS_VERSION).tar.bz2:
   29.52 -	$(WGET) http://ftp.gnu.org/gnu/binutils/$@
   29.53 -binutils-$(BINUTILS_VERSION): binutils-$(BINUTILS_VERSION).tar.bz2
   29.54 -	tar xjf $<
   29.55 -	patch -d $@ -p1 < binutils.patch
   29.56 -	touch $@
   29.57 -
   29.58 -BINUTILS_STAMPFILE=$(CROSS_ROOT)/bin/$(GNU_TARGET_ARCH)-xen-elf-ar
   29.59 -.PHONY: cross-binutils
   29.60 -cross-binutils: $(BINUTILS_STAMPFILE)
   29.61 -$(BINUTILS_STAMPFILE): binutils-$(BINUTILS_VERSION)
   29.62 -	mkdir -p binutils-build
   29.63 -	( cd binutils-build && \
   29.64 -	  ../binutils-$(BINUTILS_VERSION)/configure --prefix=$(CROSS_PREFIX) --verbose --target=$(GNU_TARGET_ARCH)-xen-elf && \
   29.65 -	  $(MAKE) && \
   29.66 -	  $(MAKE) check && \
   29.67 -	  $(MAKE) install )
   29.68 -
   29.69 -###########
   29.70 -# Cross-gcc
   29.71 -###########
   29.72 -
   29.73 -gcc-$(GCC_VERSION).tar.bz2:
   29.74 -	$(WGET) http://ftp.gnu.org/gnu/gcc/gcc-$(GCC_VERSION)/gcc-$(GCC_VERSION).tar.bz2
   29.75 -gcc-$(GCC_VERSION): gcc-$(GCC_VERSION).tar.bz2
   29.76 -	tar xjf $<
   29.77 -	patch -d $@ -p1 < gcc.patch
   29.78 -	touch $@
   29.79 -
   29.80 -GCC_STAMPFILE=$(CROSS_ROOT)/bin/$(GNU_TARGET_ARCH)-xen-elf-gcc-$(GCC_VERSION)
   29.81 -.PHONY: cross-gcc
   29.82 -cross-gcc: $(GCC_STAMPFILE)
   29.83 -$(GCC_STAMPFILE): gcc-$(GCC_VERSION) $(BINUTILS_STAMPFILE)
   29.84 -	mkdir -p gcc-build
   29.85 -	( cd gcc-build && \
   29.86 -	  ../gcc-$(GCC_VERSION)/configure --prefix=$(CROSS_PREFIX) --verbose --target=$(GNU_TARGET_ARCH)-xen-elf --enable-languages=c --disable-libssp --with-gnu-as --with-gnu-ld && \
   29.87 -	  $(MAKE) GCC_FOR_TARGET='$$$$r/gcc/xgcc -B$$$$r/gcc/ '"$(TARGET_CFLAGS)"' $$(FLAGS_FOR_TARGET)' && \
   29.88 -	  $(MAKE) install )
   29.89 -
   29.90  ##############
   29.91  # Cross-newlib
   29.92  ##############
   29.93 @@ -100,10 +70,10 @@ newlib-cvs:
   29.94  NEWLIB_STAMPFILE=$(CROSS_ROOT)/$(GNU_TARGET_ARCH)-xen-elf/lib/libc.a
   29.95  .PHONY: cross-newlib
   29.96  cross-newlib: $(NEWLIB_STAMPFILE)
   29.97 -$(NEWLIB_STAMPFILE): newlib-cvs $(GCC_STAMPFILE)
   29.98 +$(NEWLIB_STAMPFILE): newlib-cvs
   29.99  	mkdir -p newlib-build
  29.100  	( cd newlib-build && \
  29.101 -	  CC_FOR_TARGET="$(GNU_TARGET_ARCH)-xen-elf-gcc $(TARGET_CFLAGS) $(NEWLIB_CFLAGS)" ../newlib-cvs/configure --prefix=$(CROSS_PREFIX) --verbose --target=$(GNU_TARGET_ARCH)-xen-elf --enable-newlib-io-long-long && \
  29.102 +	  CC_FOR_TARGET="$(CC) $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) $(NEWLIB_CFLAGS)" AR_FOR_TARGET=$(AR) LD_FOR_TARGET=$(LD) RANLIB_FOR_TARGET=$(RANLIB) ../newlib-cvs/configure --prefix=$(CROSS_PREFIX) --verbose --target=$(GNU_TARGET_ARCH)-xen-elf --enable-newlib-io-long-long --disable-multilib && \
  29.103  	  $(MAKE) && \
  29.104  	  $(MAKE) install )
  29.105  
  29.106 @@ -120,7 +90,7 @@ cross-zlib: $(ZLIB_STAMPFILE)
  29.107  $(ZLIB_STAMPFILE): zlib-$(ZLIB_VERSION).tar.gz $(NEWLIB_STAMPFILE)
  29.108  	tar xzf $<
  29.109  	( cd zlib-$(ZLIB_VERSION) && \
  29.110 -	  CFLAGS="$(TARGET_CFLAGS)" CC=$(GNU_TARGET_ARCH)-xen-elf-gcc ./configure --prefix=$(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf && \
  29.111 +	  CFLAGS="$(TARGET_CPPFLAGS) $(TARGET_CFLAGS)" CC=$(CC) ./configure --prefix=$(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf && \
  29.112  	  $(MAKE) libz.a && \
  29.113  	  $(MAKE) install )
  29.114  
  29.115 @@ -144,7 +114,7 @@ cross-libpci: $(LIBPCI_STAMPFILE)
  29.116  	  cp ../libpci.config.h lib/config.h && \
  29.117  	  echo '#define PCILIB_VERSION "$(LIBPCI_VERSION)"' >> lib/config.h && \
  29.118  	  cp ../libpci.config.mak lib/config.mk && \
  29.119 -	  $(MAKE) CC="$(GNU_TARGET_ARCH)-xen-elf-gcc $(TARGET_CFLAGS) -I$(realpath $(MINI_OS)/include)" lib/libpci.a && \
  29.120 +	  $(MAKE) CC="$(CC) $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -I$(realpath $(MINI_OS)/include)" lib/libpci.a && \
  29.121  	  $(INSTALL_DATA) lib/libpci.a $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/lib/ && \
  29.122  	  $(INSTALL_DIR) $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/include/pci && \
  29.123  	  $(INSTALL_DATA) lib/{config,header,pci,types}.h $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/include/pci/ \
  29.124 @@ -198,7 +168,7 @@ TARGETS_MINIOS=$(addprefix mini-os-,$(TA
  29.125  .PHONY: libxc
  29.126  libxc: libxc/libxenctrl.a libxc/libxenguest.a
  29.127  libxc/libxenctrl.a libxc/libxenguest.a: cross-zlib mk-symlinks
  29.128 -	$(MAKE) -C libxc
  29.129 +	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) -C libxc
  29.130  
  29.131  #######
  29.132  # ioemu
  29.133 @@ -207,8 +177,9 @@ libxc/libxenctrl.a libxc/libxenguest.a: 
  29.134  .PHONY: ioemu
  29.135  ioemu: cross-zlib cross-libpci mk-symlinks libxc
  29.136  	[ -f ioemu/config-host.mak ] || \
  29.137 -	  ( cd ioemu ; XEN_TARGET_ARCH=$(XEN_TARGET_ARCH) sh configure --prefix=/usr --enable-stubdom $(IOEMU_OPTIONS))
  29.138 -	$(MAKE) -C ioemu LWIPDIR=$(CURDIR)/lwip-cvs
  29.139 +	  ( cd ioemu ; \
  29.140 +          XEN_TARGET_ARCH=$(XEN_TARGET_ARCH) CFLAGS="$(TARGET_CFLAGS)" sh configure --prefix=/usr --enable-stubdom $(IOEMU_OPTIONS))
  29.141 +	CPPFLAGS="$(TARGET_CPPFLAGS)" $(MAKE) -C ioemu LWIPDIR=$(CURDIR)/lwip-cvs
  29.142  
  29.143  ######
  29.144  # caml
  29.145 @@ -216,7 +187,7 @@ ioemu: cross-zlib cross-libpci mk-symlin
  29.146  
  29.147  .PHONY: caml
  29.148  caml: cross-newlib mk-symlinks
  29.149 -	$(MAKE) -C $@ LWIPDIR=$(CURDIR)/lwip-cvs 
  29.150 +	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) -C $@ LWIPDIR=$(CURDIR)/lwip-cvs 
  29.151  
  29.152  ###
  29.153  # C
  29.154 @@ -224,7 +195,7 @@ caml: cross-newlib mk-symlinks
  29.155  
  29.156  .PHONY: c
  29.157  c: cross-newlib mk-symlinks
  29.158 -	$(MAKE) -C $@ LWIPDIR=$(CURDIR)/lwip-cvs 
  29.159 +	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) -C $@ LWIPDIR=$(CURDIR)/lwip-cvs 
  29.160  
  29.161  ######
  29.162  # Grub
  29.163 @@ -238,7 +209,7 @@ grub-cvs:
  29.164  
  29.165  .PHONY: grub
  29.166  grub: grub-cvs cross-newlib mk-symlinks
  29.167 -	$(MAKE) -C $@
  29.168 +	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) -C $@
  29.169  
  29.170  ########
  29.171  # minios
  29.172 @@ -246,20 +217,20 @@ grub: grub-cvs cross-newlib mk-symlinks
  29.173  
  29.174  .PHONY: ioemu-stubdom
  29.175  ioemu-stubdom: mini-os-ioemu lwip-cvs libxc ioemu
  29.176 -	DEF_CFLAGS=-DCONFIG_QEMU $(MAKE) -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< LWIPDIR=$(CURDIR)/lwip-cvs APP_OBJS="$(CURDIR)/ioemu/i386-dm-stubdom/qemu.a $(CURDIR)/ioemu/i386-dm-stubdom/libqemu.a"
  29.177 +	DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="-DCONFIG_QEMU $(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" $(MAKE) -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< LWIPDIR=$(CURDIR)/lwip-cvs APP_OBJS="$(CURDIR)/ioemu/i386-dm-stubdom/qemu.a $(CURDIR)/ioemu/i386-dm-stubdom/libqemu.a"
  29.178  
  29.179  CAMLLIB = $(shell ocamlc -where)
  29.180  .PHONY: caml-stubdom
  29.181  caml-stubdom: mini-os-caml lwip-cvs libxc caml
  29.182 -	DEF_CFLAGS=-DCONFIG_CAML $(MAKE) -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< LWIPDIR=$(CURDIR)/lwip-cvs APP_OBJS="$(CURDIR)/caml/main-caml.o $(CURDIR)/caml/caml.o $(CAMLLIB)/libasmrun.a"
  29.183 +	DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="-DCONFIG_CAML $(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" $(MAKE) -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< LWIPDIR=$(CURDIR)/lwip-cvs APP_OBJS="$(CURDIR)/caml/main-caml.o $(CURDIR)/caml/caml.o $(CAMLLIB)/libasmrun.a"
  29.184  
  29.185  .PHONY: c-stubdom
  29.186  c-stubdom: mini-os-c lwip-cvs libxc c
  29.187 -	DEF_CFLAGS=-DCONFIG_C $(MAKE) -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< LWIPDIR=$(CURDIR)/lwip-cvs APP_OBJS=$(CURDIR)/c/main.a
  29.188 +	DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="-DCONFIG_C $(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" $(MAKE) -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< LWIPDIR=$(CURDIR)/lwip-cvs APP_OBJS=$(CURDIR)/c/main.a
  29.189  
  29.190  .PHONY: pv-grub
  29.191  pv-grub: mini-os-grub libxc grub
  29.192 -	DEF_CFLAGS=-DCONFIG_GRUB $(MAKE) -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< APP_OBJS=$(CURDIR)/grub/main.a
  29.193 +	DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="-DCONFIG_GRUB $(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" $(MAKE) -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< APP_OBJS=$(CURDIR)/grub/main.a
  29.194  
  29.195  #########
  29.196  # install
  29.197 @@ -294,14 +265,12 @@ clean:
  29.198  .PHONY: crossclean
  29.199  crossclean: clean
  29.200  	rm -fr $(CROSS_ROOT)
  29.201 -	rm -fr binutils-build gcc-build newlib-build
  29.202 +	rm -fr newlib-build
  29.203  	rm -fr zlib-$(ZLIB_VERSION) pciutils-$(LIBPCI_VERSION)
  29.204  
  29.205  # clean patched sources
  29.206  .PHONY: patchclean
  29.207  patchclean: crossclean
  29.208 -	rm -fr binutils-$(BINUTILS_VERSION)
  29.209 -	rm -fr gcc-$(GCC_VERSION)
  29.210  	rm -fr newlib-cvs
  29.211  	rm -fr lwip-cvs
  29.212  	rm -fr grub-cvs
  29.213 @@ -309,8 +278,6 @@ patchclean: crossclean
  29.214  # clean downloads
  29.215  .PHONY: downloadclean
  29.216  downloadclean: patchclean
  29.217 -	rm -f binutils-$(BINUTILS_VERSION).tar.bz2
  29.218 -	rm -f gcc-$(GCC_VERSION).tar.bz2
  29.219  	rm -f zlib-$(ZLIB_VERSION).tar.gz
  29.220  	rm -f pciutils-$(LIBPCI_VERSION).tar.bz2
  29.221