ia64/xen-unstable

changeset 17066:9e9ba5185ef1

merge with xen-unstable.hg
author Alex Williamson <alex.williamson@hp.com>
date Thu Feb 14 09:34:27 2008 -0700 (2008-02-14)
parents 0a2ee4279326 55ae3b66b1b6
children 8e89261a8308
files unmodified_drivers/linux-2.6/platform-pci/Kbuild
line diff
     1.1 --- a/.hgignore	Wed Feb 13 10:37:18 2008 -0700
     1.2 +++ b/.hgignore	Thu Feb 14 09:34:27 2008 -0700
     1.3 @@ -80,6 +80,17 @@
     1.4  ^pristine-.*$
     1.5  ^ref-.*$
     1.6  ^tmp-.*$
     1.7 +^stubdom/binutils-.*$
     1.8 +^stubdom/cross-root-.*$
     1.9 +^stubdom/gcc-.*$
    1.10 +^stubdom/include$
    1.11 +^stubdom/ioemu$
    1.12 +^stubdom/libxc$
    1.13 +^stubdom/lwip-.*$
    1.14 +^stubdom/mini-os$
    1.15 +^stubdom/newlib-.*$
    1.16 +^stubdom/pciutils-.*$
    1.17 +^stubdom/zlib-.*$
    1.18  ^tools/.*/TAGS$
    1.19  ^tools/.*/build/lib.*/.*\.py$
    1.20  ^tools/blktap/Makefile\.smh$
     2.1 --- a/buildconfigs/enable-xen-config	Wed Feb 13 10:37:18 2008 -0700
     2.2 +++ b/buildconfigs/enable-xen-config	Thu Feb 14 09:34:27 2008 -0700
     2.3 @@ -1,6 +1,6 @@
     2.4  #!/bin/sh
     2.5  
     2.6 -set -ex
     2.7 +set -e
     2.8  
     2.9  if [ $# -ne 1 ] ; then
    2.10  	echo "Usage $(basename $0) <config-file>" 1>&2
    2.11 @@ -26,6 +26,7 @@ setopt()
    2.12  }
    2.13  
    2.14  setopt CONFIG_PARAVIRT y
    2.15 +setopt CONFIG_PARAVIRT_GUEST y
    2.16  setopt CONFIG_XEN y
    2.17  setopt CONFIG_VMI y
    2.18  setopt CONFIG_KVM y
    2.19 @@ -36,5 +37,12 @@ setopt CONFIG_XEN_BLKDEV_FRONTEND y
    2.20  setopt CONFIG_XEN_NETDEV_FRONTEND y
    2.21  setopt CONFIG_HVC_XEN y
    2.22  setopt CONFIG_NUMA n
    2.23 +setopt CONFIG_LOCALVERSION_AUTO n
    2.24 +
    2.25 +case ${XEN_TARGET_ARCH} in
    2.26 +    x86_32) setopt CONFIG_64BIT n ;;
    2.27 +    x86_64) setopt CONFIG_64BIT y ;;
    2.28 +    *) ;;
    2.29 +esac
    2.30  
    2.31  exit 0
     3.1 --- a/buildconfigs/mk.linux-2.6-common	Wed Feb 13 10:37:18 2008 -0700
     3.2 +++ b/buildconfigs/mk.linux-2.6-common	Thu Feb 14 09:34:27 2008 -0700
     3.3 @@ -14,22 +14,15 @@ else
     3.4  __XEN_LINUX_UPDATE =
     3.5  endif
     3.6  
     3.7 -# Let XEN_TARGET_ARCH override ARCH.
     3.8 -ifeq ($(XEN_TARGET_ARCH),x86_32)
     3.9 -LINUX_ARCH	?= i386
    3.10 +ifeq ($(XEN_LINUX_NONINTERACTIVE_CONFIG),y)
    3.11 +__NONINT_CONFIG = yes $$'\n' |
    3.12  else
    3.13 -LINUX_ARCH	?= $(XEN_TARGET_ARCH)
    3.14 +__NONINT_CONFIG =
    3.15  endif
    3.16  
    3.17  LINUX_DIR     = build-linux-$(LINUX_VER)$(EXTRAVERSION)_$(XEN_TARGET_ARCH)
    3.18  
    3.19  IMAGE_TARGET ?= vmlinuz
    3.20 -ifneq ($(XEN_TARGET_ARCH),ia64)
    3.21 -IMAGE_PATH ?= arch/$(LINUX_ARCH)/boot/$(firstword $(IMAGE_TARGET))
    3.22 -else
    3.23 -IMAGE_PATH ?= arch/ia64/hp/sim/boot/vmlinux.gz
    3.24 -endif
    3.25 -INSTALL_BOOT_PATH := $(DESTDIR)/boot
    3.26  
    3.27  LINUX_VER3  := $(LINUX_SERIES).$(word 3, $(subst ., ,$(LINUX_VER)))
    3.28  
    3.29 @@ -38,6 +31,11 @@ LINUX_VER3  := $(LINUX_SERIES).$(word 3,
    3.30  
    3.31  include buildconfigs/src.$(XEN_LINUX_SOURCE)
    3.32  
    3.33 +LINUX_ARCH = $$(sh buildconfigs/select-linux-arch $(LINUX_SRCDIR))
    3.34 +IMAGE_PATH = $$(sh buildconfigs/select-linux-image $(LINUX_DIR) $(LINUX_ARCH) $(IMAGE_TARGET))
    3.35 +
    3.36 +INSTALL_BOOT_PATH := $(DESTDIR)/boot
    3.37 +
    3.38  # Default to allowing interface mismatch
    3.39  ifndef XEN_LINUX_ALLOW_INTERFACE_MISMATCH
    3.40  XEN_LINUX_ALLOW_INTERFACE_MISMATCH := y
    3.41 @@ -64,9 +62,9 @@ endif
    3.42  	fi
    3.43  	$(MAKE) -C $(LINUX_DIR) ARCH=$(LINUX_ARCH) INSTALL_PATH=$(DESTDIR) $(IMAGE_TARGET)
    3.44  	mkdir -p $(INSTALL_BOOT_PATH)
    3.45 -	cp $(LINUX_DIR)/$(IMAGE_PATH) $(INSTALL_BOOT_PATH)/vmlinuz-$(KERNELRELEASE)
    3.46 -	cp $(LINUX_DIR)/.config $(INSTALL_BOOT_PATH)/config-$(KERNELRELEASE)
    3.47 -	cp $(LINUX_DIR)/System.map $(INSTALL_BOOT_PATH)/System.map-$(KERNELRELEASE)
    3.48 +	@cp -v $(IMAGE_PATH) $(INSTALL_BOOT_PATH)/vmlinuz-$(KERNELRELEASE)
    3.49 +	@cp -v $(LINUX_DIR)/.config $(INSTALL_BOOT_PATH)/config-$(KERNELRELEASE)
    3.50 +	@cp -v $(LINUX_DIR)/System.map $(INSTALL_BOOT_PATH)/System.map-$(KERNELRELEASE)
    3.51  
    3.52  $(LINUX_DIR)/include/linux/autoconf.h: CONFIG_FILE=$(CURDIR)/$(LINUX_DIR)/.config
    3.53  $(LINUX_DIR)/include/linux/autoconf.h: $(LINUX_SRCDIR)/.valid-src
    3.54 @@ -102,7 +100,7 @@ endif
    3.55  ifneq ($(EXTRAVERSION),)
    3.56  	echo "$(EXTRAVERSION)" >$(LINUX_DIR)/localversion-xen
    3.57  endif
    3.58 -	$(MAKE) -C $(LINUX_SRCDIR) ARCH=$(LINUX_ARCH) oldconfig O=$$(/bin/pwd)/$(LINUX_DIR)
    3.59 +	$(__NONINT_CONFIG) $(MAKE) -C $(LINUX_SRCDIR) ARCH=$(LINUX_ARCH) oldconfig O=$$(/bin/pwd)/$(LINUX_DIR)
    3.60  	@set -e ; if [ ! -f $(LINUX_DIR)/Makefile ] ; then \
    3.61  	    echo "***********************************"; \
    3.62  	    echo "oldconfig did not create a Makefile"; \
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/buildconfigs/select-linux-arch	Thu Feb 14 09:34:27 2008 -0700
     4.3 @@ -0,0 +1,30 @@
     4.4 +#!/bin/sh
     4.5 +
     4.6 +ME=$(basename $0)
     4.7 +
     4.8 +if [ $# -lt 1 ] || [ $# -gt 2 ] ; then
     4.9 +    echo "usage: $ME <linux-build-directory>" 1>&2
    4.10 +    exit 1;
    4.11 +fi
    4.12 +
    4.13 +LINUX_DIR=$1
    4.14 +
    4.15 +case ${XEN_TARGET_ARCH} in
    4.16 +    x86_32|x86_64)
    4.17 +	if [ -d ${LINUX_DIR}/arch/x86 ] ; then
    4.18 +	    ARCH=x86
    4.19 +	elif [ "${XEN_TARGET_ARCH}" = "x86_32" ] ; then
    4.20 +	    ARCH=i386
    4.21 +	else
    4.22 +	    ARCH=x86_64
    4.23 +	fi
    4.24 +	;;
    4.25 +    *)
    4.26 +	ARCH=${XEN_TARGET_ARCH}
    4.27 +	;;
    4.28 +esac
    4.29 +
    4.30 +echo "$ME: ${ARCH}" 1>&2
    4.31 +echo ${ARCH}
    4.32 +
    4.33 +exit 0
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/buildconfigs/select-linux-image	Thu Feb 14 09:34:27 2008 -0700
     5.3 @@ -0,0 +1,33 @@
     5.4 +#!/bin/sh
     5.5 +
     5.6 +ME=$(basename $0)
     5.7 +
     5.8 +if [ $# -lt 3 ] ; then
     5.9 +    echo "usage: $ME <linux-build-directory> <linux-arch> <linux-targets...>" 1>&2
    5.10 +    exit 1;
    5.11 +fi
    5.12 +
    5.13 +LINUX_DIR=$1
    5.14 +LINUX_ARCH=$2
    5.15 +LINUX_TARGET=$3 # We don't care about second and subsequent targets
    5.16 +
    5.17 +case ${XEN_TARGET_ARCH} in
    5.18 +    ia64)
    5.19 +	IMAGE=${LINUX_DIR}/arch/ia64/hp/sim/boot/vmlinux.gz
    5.20 +	;;
    5.21 +    *)
    5.22 +	if [ -f ${LINUX_DIR}/arch/${LINUX_ARCH}/boot/${LINUX_TARGET} ] ; then
    5.23 +	    IMAGE=${LINUX_DIR}/arch/${LINUX_ARCH}/boot/${LINUX_TARGET}
    5.24 +	elif [ -f ${LINUX_DIR}/${LINUX_TARGET} ] ; then
    5.25 +	    IMAGE=${LINUX_DIR}/${LINUX_TARGET}
    5.26 +	else
    5.27 +	    echo "$ME: cannot determine Linux image to use for ${LINUX_ARCH} in ${LINUX_DIR}" 1>&2
    5.28 +	    exit 1
    5.29 +	fi
    5.30 +	;;
    5.31 +esac
    5.32 +
    5.33 +echo "$ME: ${IMAGE}" 1>&2
    5.34 +echo ${IMAGE}
    5.35 +
    5.36 +exit 0
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/config/MiniOS.mk	Thu Feb 14 09:34:27 2008 -0700
     6.3 @@ -0,0 +1,9 @@
     6.4 +include $(XEN_ROOT)/config/StdGNU.mk
     6.5 +include $(XEN_ROOT)/extras/mini-os/Config.mk
     6.6 +CFLAGS += $(DEF_CFLAGS) $(ARCH_CFLAGS)
     6.7 +CPPFLAGS += $(DEF_CPPFLAGS) $(ARCH_CPPFLAGS) $(extra_incl)
     6.8 +ASFLAGS += $(DEF_ASFLAGS) $(ARCH_ASFLAGS)
     6.9 +LDFLAGS += $(DEF_LDFLAGS) $(ARCH_LDFLAGS)
    6.10 +
    6.11 +# Override settings for this OS
    6.12 +PTHREAD_LIBS =
     7.1 --- a/config/StdGNU.mk	Wed Feb 13 10:37:18 2008 -0700
     7.2 +++ b/config/StdGNU.mk	Thu Feb 14 09:34:27 2008 -0700
     7.3 @@ -35,6 +35,7 @@ PRIVATE_BINDIR = $(PRIVATE_PREFIX)/bin
     7.4  
     7.5  SOCKET_LIBS =
     7.6  CURSES_LIBS = -lncurses
     7.7 +PTHREAD_LIBS = -lpthread
     7.8  UTIL_LIBS = -lutil
     7.9  SONAME_LDFLAG = -soname
    7.10  SHLIB_CFLAGS = -shared
     8.1 --- a/config/SunOS.mk	Wed Feb 13 10:37:18 2008 -0700
     8.2 +++ b/config/SunOS.mk	Thu Feb 14 09:34:27 2008 -0700
     8.3 @@ -39,6 +39,7 @@ SunOS_LIBDIR_x86_64 = /usr/sfw/lib/amd64
     8.4  
     8.5  SOCKET_LIBS = -lsocket
     8.6  CURSES_LIBS = -lcurses
     8.7 +PTHREAD_LIBS = -lpthread
     8.8  UTIL_LIBS =
     8.9  SONAME_LDFLAG = -h
    8.10  SHLIB_CFLAGS = -R $(SunOS_LIBDIR) -shared
     9.1 --- a/docs/misc/xenstore.txt	Wed Feb 13 10:37:18 2008 -0700
     9.2 +++ b/docs/misc/xenstore.txt	Thu Feb 14 09:34:27 2008 -0700
     9.3 @@ -296,6 +296,16 @@ RESUME			<domid>|
     9.4  
     9.5  	xenstored prevents the use of RESUME other than by dom0.
     9.6  
     9.7 +SET_TARGET		<domid>|<tdomid>|
     9.8 +	Notifies xenstored that domain <domid> is targeting domain
     9.9 +	<tdomid>. This grants domain <domid> full access to paths
    9.10 +	owned by <tdomid>. Domain <domid> also inherits all
    9.11 +	permissions granted to <tdomid> on all other paths. This
    9.12 +	allows <domid> to behave as if it were dom0 when modifying
    9.13 +	paths related to <tdomid>.
    9.14 +
    9.15 +	xenstored prevents the use of SET_TARGET other than by dom0.
    9.16 +
    9.17  ---------- Miscellaneous ----------
    9.18  
    9.19  DEBUG			print|<string>|??	    sends <string> to debug log
    10.1 --- a/docs/xen-api/revision-history.tex	Wed Feb 13 10:37:18 2008 -0700
    10.2 +++ b/docs/xen-api/revision-history.tex	Thu Feb 14 09:34:27 2008 -0700
    10.3 @@ -23,5 +23,12 @@
    10.4      \end{flushleft}
    10.5     \end{minipage}\\
    10.6    \hline
    10.7 +  1.0.2 & 11th Feb. 08 & S. Berger &
    10.8 +   \begin{minipage}[t]{7cm}
    10.9 +    \begin{flushleft}
   10.10 +     Added table of contents and hyperlink cross reference.
   10.11 +    \end{flushleft}
   10.12 +   \end{minipage}\\
   10.13 +  \hline
   10.14   \end{tabular}
   10.15  \end{center}
   10.16 \ No newline at end of file
    11.1 --- a/docs/xen-api/xenapi-coversheet.tex	Wed Feb 13 10:37:18 2008 -0700
    11.2 +++ b/docs/xen-api/xenapi-coversheet.tex	Thu Feb 14 09:34:27 2008 -0700
    11.3 @@ -17,7 +17,7 @@
    11.4  \newcommand{\coversheetlogo}{xen.eps}
    11.5  
    11.6  %% Document date
    11.7 -\newcommand{\datestring}{25th January 2008}
    11.8 +\newcommand{\datestring}{11th February 2008}
    11.9  
   11.10  \newcommand{\releasestatement}{Stable Release}
   11.11  
    12.1 --- a/docs/xen-api/xenapi.tex	Wed Feb 13 10:37:18 2008 -0700
    12.2 +++ b/docs/xen-api/xenapi.tex	Thu Feb 14 09:34:27 2008 -0700
    12.3 @@ -17,6 +17,7 @@
    12.4  \usepackage{graphics}
    12.5  \usepackage{longtable}
    12.6  \usepackage{fancyhdr}
    12.7 +\usepackage{hyperref}
    12.8  
    12.9  \setlength\topskip{0cm}
   12.10  \setlength\topmargin{0cm}
   12.11 @@ -35,6 +36,10 @@
   12.12  % The revision history
   12.13  \include{revision-history}
   12.14  
   12.15 +% Table of contents
   12.16 +\tableofcontents
   12.17 +
   12.18 +
   12.19  % ... and off we go!
   12.20  
   12.21  \chapter{Introduction}
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/extras/mini-os/Config.mk	Thu Feb 14 09:34:27 2008 -0700
    13.3 @@ -0,0 +1,76 @@
    13.4 +# Set mini-os root path, used in mini-os.mk.
    13.5 +MINI-OS_ROOT=$(XEN_ROOT)/extras/mini-os
    13.6 +export MINI-OS_ROOT
    13.7 +
    13.8 +ifeq ($(XEN_TARGET_ARCH),x86_32)
    13.9 +export pae ?= y
   13.10 +endif
   13.11 +libc = $(stubdom)
   13.12 +
   13.13 +XEN_INTERFACE_VERSION := 0x00030205
   13.14 +export XEN_INTERFACE_VERSION
   13.15 +
   13.16 +# Try to find out the architecture family TARGET_ARCH_FAM.
   13.17 +# First check whether x86_... is contained (for x86_32, x86_32y, x86_64).
   13.18 +# If not x86 then use $(XEN_TARGET_ARCH) -> for ia64, ...
   13.19 +ifeq ($(findstring x86_,$(XEN_TARGET_ARCH)),x86_)
   13.20 +TARGET_ARCH_FAM = x86
   13.21 +else
   13.22 +TARGET_ARCH_FAM = $(XEN_TARGET_ARCH)
   13.23 +endif
   13.24 +
   13.25 +# The architecture family directory below mini-os.
   13.26 +TARGET_ARCH_DIR := arch/$(TARGET_ARCH_FAM)
   13.27 +
   13.28 +# Export these variables for possible use in architecture dependent makefiles.
   13.29 +export TARGET_ARCH_DIR
   13.30 +export TARGET_ARCH_FAM
   13.31 +export XEN_TARGET_X86_PAE 
   13.32 +
   13.33 +# This is used for architecture specific links.
   13.34 +# This can be overwritten from arch specific rules.
   13.35 +ARCH_LINKS =
   13.36 +
   13.37 +# The path pointing to the architecture specific header files.
   13.38 +ARCH_INC := $(TARGET_ARCH_FAM)
   13.39 +
   13.40 +# For possible special header directories.
   13.41 +# This can be overwritten from arch specific rules.
   13.42 +EXTRA_INC = $(ARCH_INC)	
   13.43 +
   13.44 +# Include the architecture family's special makerules.
   13.45 +# This must be before include minios.mk!
   13.46 +include $(MINI-OS_ROOT)/$(TARGET_ARCH_DIR)/arch.mk
   13.47 +
   13.48 +extra_incl := $(foreach dir,$(EXTRA_INC),-I$(MINI-OS_ROOT)/include/$(dir))
   13.49 +
   13.50 +DEF_CPPFLAGS += -I$(MINI-OS_ROOT)/include
   13.51 +
   13.52 +ifeq ($(stubdom),y)
   13.53 +DEF_CPPFLAGS += -DCONFIG_STUBDOM
   13.54 +endif
   13.55 +
   13.56 +ifeq ($(libc),y)
   13.57 +DEF_CPPFLAGS += -DHAVE_LIBC
   13.58 +DEF_CPPFLAGS += -I$(MINI-OS_ROOT)/include/posix
   13.59 +DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/xenstore
   13.60 +endif
   13.61 +
   13.62 +ifneq ($(LWIPDIR),)
   13.63 +lwip=y
   13.64 +DEF_CPPFLAGS += -DHAVE_LWIP
   13.65 +DEF_CPPFLAGS += -I$(LWIPDIR)/src/include
   13.66 +DEF_CPPFLAGS += -I$(LWIPDIR)/src/include/ipv4
   13.67 +endif
   13.68 +
   13.69 +ifneq ($(QEMUDIR),)
   13.70 +qemu=y
   13.71 +endif
   13.72 +
   13.73 +ifneq ($(CAMLDIR),)
   13.74 +caml=y
   13.75 +endif
   13.76 +
   13.77 +ifeq ($(pae),y)
   13.78 +DEF_CPPFLAGS += -DCONFIG_X86_PAE
   13.79 +endif
    14.1 --- a/extras/mini-os/Makefile	Wed Feb 13 10:37:18 2008 -0700
    14.2 +++ b/extras/mini-os/Makefile	Thu Feb 14 09:34:27 2008 -0700
    14.3 @@ -4,54 +4,11 @@
    14.4  # Makefile and a arch.mk.
    14.5  #
    14.6  
    14.7 -XEN_ROOT = ../..
    14.8 +export XEN_ROOT = ../..
    14.9  include $(XEN_ROOT)/Config.mk
   14.10  
   14.11 -XEN_INTERFACE_VERSION := 0x00030205
   14.12 -export XEN_INTERFACE_VERSION
   14.13 -
   14.14 -# Set TARGET_ARCH
   14.15 -override TARGET_ARCH := $(XEN_TARGET_ARCH)
   14.16 -
   14.17 -# Set mini-os root path, used in mini-os.mk.
   14.18 -MINI-OS_ROOT=$(PWD)
   14.19 -export MINI-OS_ROOT
   14.20 -
   14.21 -# Try to find out the architecture family TARGET_ARCH_FAM.
   14.22 -# First check whether x86_... is contained (for x86_32, x86_32y, x86_64).
   14.23 -# If not x86 then use $(TARGET_ARCH) -> for ia64, ...
   14.24 -ifeq ($(findstring x86_,$(TARGET_ARCH)),x86_)
   14.25 -TARGET_ARCH_FAM = x86
   14.26 -else
   14.27 -TARGET_ARCH_FAM = $(TARGET_ARCH)
   14.28 -endif
   14.29 -
   14.30 -# The architecture family directory below mini-os.
   14.31 -TARGET_ARCH_DIR := arch/$(TARGET_ARCH_FAM)
   14.32 -
   14.33 -# Export these variables for possible use in architecture dependent makefiles.
   14.34 -export TARGET_ARCH
   14.35 -export TARGET_ARCH_DIR
   14.36 -export TARGET_ARCH_FAM
   14.37 -export XEN_TARGET_X86_PAE 
   14.38 -
   14.39 -# This is used for architecture specific links.
   14.40 -# This can be overwritten from arch specific rules.
   14.41 -ARCH_LINKS =
   14.42 -
   14.43 -# For possible special header directories.
   14.44 -# This can be overwritten from arch specific rules.
   14.45 -EXTRA_INC =
   14.46 -
   14.47 -# Include the architecture family's special makerules.
   14.48 -# This must be before include minios.mk!
   14.49 -include $(TARGET_ARCH_DIR)/arch.mk
   14.50 -
   14.51 -ifneq ($(LWIPDIR),)
   14.52 -lwip=y
   14.53 -DEF_CFLAGS += -DHAVE_LWIP
   14.54 -DEF_CFLAGS += -I$(LWIPDIR)/src/include
   14.55 -DEF_CFLAGS += -I$(LWIPDIR)/src/include/ipv4
   14.56 +ifneq ($(stubdom),y)
   14.57 +include Config.mk
   14.58  endif
   14.59  
   14.60  # Include common mini-os makerules.
   14.61 @@ -63,7 +20,7 @@ include minios.mk
   14.62  # Define some default flags for linking.
   14.63  LDLIBS := 
   14.64  LDARCHLIB := -L$(TARGET_ARCH_DIR) -l$(ARCH_LIB_NAME)
   14.65 -LDFLAGS_FINAL := -T $(TARGET_ARCH_DIR)/minios-$(TARGET_ARCH).lds
   14.66 +LDFLAGS_FINAL := -T $(TARGET_ARCH_DIR)/minios-$(XEN_TARGET_ARCH).lds
   14.67  
   14.68  # Prefix for global API names. All other symbols are localised before
   14.69  # linking with EXTRA_OBJS.
   14.70 @@ -112,14 +69,38 @@ lwip.a: $(LWO)
   14.71  	$(AR) cqs $@ $^
   14.72  
   14.73  OBJS += lwip.a
   14.74 +endif
   14.75  
   14.76 -OBJS := $(filter-out $(LWO), $(OBJS))
   14.77 +OBJS := $(filter-out lwip%.o $(LWO), $(OBJS))
   14.78 +
   14.79 +ifeq ($(caml),y)
   14.80 +CAMLLIB = $(shell ocamlc -where)
   14.81 +OBJS += $(CAMLDIR)/caml.o
   14.82 +OBJS += $(CAMLLIB)/libasmrun.a
   14.83 +CFLAGS += -I$(CAMLLIB)
   14.84 +LDLIBS += -lm
   14.85  else
   14.86 -OBJS := $(filter-out daytime.o lwip%.o, $(OBJS))
   14.87 +OBJS := $(filter-out main-caml.o, $(OBJS))
   14.88 +endif
   14.89 +
   14.90 +ifeq ($(qemu),y)
   14.91 +OBJS += $(QEMUDIR)/i386-dm-stubdom/qemu.a $(QEMUDIR)/i386-dm-stubdom/libqemu.a
   14.92 +CFLAGS += -DCONFIG_QEMU
   14.93 +endif
   14.94 +
   14.95 +ifeq ($(libc),y)
   14.96 +LDLIBS += -L$(XEN_ROOT)/stubdom/libxc -lxenctrl -lxenguest
   14.97 +LDLIBS += -lpci
   14.98 +LDLIBS += -lz
   14.99 +LDLIBS += -lc
  14.100 +endif
  14.101 +
  14.102 +ifneq ($(caml)-$(qemu)-$(lwip),--y)
  14.103 +OBJS := $(filter-out daytime.o, $(OBJS))
  14.104  endif
  14.105  
  14.106  $(TARGET): links $(OBJS) arch_lib
  14.107 -	$(LD) -r $(LDFLAGS) $(HEAD_OBJ) $(OBJS) $(LDARCHLIB) -o $@.o
  14.108 +	$(LD) -r $(LDFLAGS) $(HEAD_OBJ) $(OBJS) $(LDARCHLIB) $(LDLIBS) -o $@.o
  14.109  	$(OBJCOPY) -w -G $(GLOBAL_PREFIX)* -G _start $@.o $@.o
  14.110  	$(LD) $(LDFLAGS) $(LDFLAGS_FINAL) $@.o $(EXTRA_OBJS) -o $@
  14.111  	gzip -f -9 -c $@ >$@.gz
    15.1 --- a/extras/mini-os/arch/ia64/Makefile	Wed Feb 13 10:37:18 2008 -0700
    15.2 +++ b/extras/mini-os/arch/ia64/Makefile	Thu Feb 14 09:34:27 2008 -0700
    15.3 @@ -5,6 +5,8 @@
    15.4  XEN_ROOT = ../../../..
    15.5  include $(XEN_ROOT)/Config.mk
    15.6  
    15.7 +include ../../Config.mk
    15.8 +
    15.9  include arch.mk
   15.10  include ../../minios.mk
   15.11  
   15.12 @@ -41,7 +43,7 @@ ARCH_OBJS += __divdi3.o
   15.13  
   15.14  GEN_OFF_SRC := gen_off.c
   15.15  GEN_OFF_ASM := gen_off.s
   15.16 -GEN_OFF_H   := $(ARCH_INC)/offsets.h
   15.17 +GEN_OFF_H   := $(MINI-OS_ROOT)/include/$(ARCH_INC)/offsets.h
   15.18  
   15.19  all: $(ARCH_LIB)
   15.20  
    16.1 --- a/extras/mini-os/arch/ia64/minios-ia64.lds	Wed Feb 13 10:37:18 2008 -0700
    16.2 +++ b/extras/mini-os/arch/ia64/minios-ia64.lds	Thu Feb 14 09:34:27 2008 -0700
    16.3 @@ -40,6 +40,18 @@ SECTIONS
    16.4    .rodata.str1.8 : AT(ADDR(.rodata.str1.8) - (((5<<(61))+0x100000000) - (1 << 20)))
    16.5    { *(.rodata.str1.8) }
    16.6  
    16.7 +  /* newlib initialization functions */
    16.8 +  . = ALIGN(64 / 8);
    16.9 +  PROVIDE (__preinit_array_start = .);
   16.10 +  .preinit_array     : { *(.preinit_array) }
   16.11 +  PROVIDE (__preinit_array_end = .);
   16.12 +  PROVIDE (__init_array_start = .);
   16.13 +  .init_array     : { *(.init_array) }
   16.14 +  PROVIDE (__init_array_end = .);
   16.15 +  PROVIDE (__fini_array_start = .);
   16.16 +  .fini_array     : { *(.fini_array) }
   16.17 +  PROVIDE (__fini_array_end = .);
   16.18 +
   16.19    .IA_64.unwind_info : AT(ADDR(.IA_64.unwind_info) - (((5<<(61))+0x100000000) - (1 << 20)))
   16.20    { *(.IA_64.unwind_info) }
   16.21  
    17.1 --- a/extras/mini-os/arch/ia64/mm.c	Wed Feb 13 10:37:18 2008 -0700
    17.2 +++ b/extras/mini-os/arch/ia64/mm.c	Thu Feb 14 09:34:27 2008 -0700
    17.3 @@ -43,6 +43,14 @@ extern uint64_t _text[], _etext[], _end[
    17.4  
    17.5  uint64_t kernstart, kernend, kernsize, kernpstart, kernpend;
    17.6  
    17.7 +#ifdef HAVE_LIBC
    17.8 +uint8_t _heap[512 * 1024];
    17.9 +unsigned long heap = (unsigned long)_heap,
   17.10 +              brk = (unsigned long)_heap,
   17.11 +              heap_mapped = (unsigned long)_heap + sizeof(_heap),
   17.12 +              heap_end = (unsigned long)_heap + sizeof(_heap);
   17.13 +#endif
   17.14 +
   17.15  /* Print the available memory chunks. */
   17.16  static void
   17.17  print_phys_avail(void)
    18.1 --- a/extras/mini-os/arch/x86/Makefile	Wed Feb 13 10:37:18 2008 -0700
    18.2 +++ b/extras/mini-os/arch/x86/Makefile	Thu Feb 14 09:34:27 2008 -0700
    18.3 @@ -5,13 +5,14 @@
    18.4  
    18.5  XEN_ROOT = ../../../..
    18.6  include $(XEN_ROOT)/Config.mk
    18.7 +include ../../Config.mk
    18.8  
    18.9  # include arch.mk has to be before mini-os.mk!
   18.10  
   18.11  include arch.mk
   18.12  include ../../minios.mk
   18.13  
   18.14 -# Sources here are all *.c *.S without $(TARGET_ARCH).S
   18.15 +# Sources here are all *.c *.S without $(XEN_TARGET_ARCH).S
   18.16  # This is handled in $(HEAD_ARCH_OBJ)
   18.17  ARCH_SRCS := $(wildcard *.c)
   18.18  
    19.1 --- a/extras/mini-os/arch/x86/arch.mk	Wed Feb 13 10:37:18 2008 -0700
    19.2 +++ b/extras/mini-os/arch/x86/arch.mk	Thu Feb 14 09:34:27 2008 -0700
    19.3 @@ -3,11 +3,11 @@
    19.4  # (including x86_32, x86_32y and x86_64).
    19.5  #
    19.6  
    19.7 -ifeq ($(TARGET_ARCH),x86_32)
    19.8 +ifeq ($(XEN_TARGET_ARCH),x86_32)
    19.9  ARCH_CFLAGS  := -m32 -march=i686
   19.10  ARCH_LDFLAGS := -m elf_i386
   19.11  ARCH_ASFLAGS := -m32
   19.12 -EXTRA_INC += $(TARGET_ARCH_FAM)/$(TARGET_ARCH)
   19.13 +EXTRA_INC += $(TARGET_ARCH_FAM)/$(XEN_TARGET_ARCH)
   19.14  EXTRA_SRC += arch/$(EXTRA_INC)
   19.15  
   19.16  ifeq ($(XEN_TARGET_X86_PAE),y)
   19.17 @@ -16,12 +16,12 @@ ARCH_ASFLAGS += -DCONFIG_X86_PAE=1
   19.18  endif
   19.19  endif
   19.20  
   19.21 -ifeq ($(TARGET_ARCH),x86_64)
   19.22 +ifeq ($(XEN_TARGET_ARCH),x86_64)
   19.23  ARCH_CFLAGS := -m64 -mno-red-zone -fno-reorder-blocks
   19.24  ARCH_CFLAGS += -fno-asynchronous-unwind-tables
   19.25  ARCH_ASFLAGS := -m64
   19.26  ARCH_LDFLAGS := -m elf_x86_64
   19.27 -EXTRA_INC += $(TARGET_ARCH_FAM)/$(TARGET_ARCH)
   19.28 +EXTRA_INC += $(TARGET_ARCH_FAM)/$(XEN_TARGET_ARCH)
   19.29  EXTRA_SRC += arch/$(EXTRA_INC)
   19.30  endif
   19.31  
    20.1 --- a/extras/mini-os/arch/x86/minios-x86_32.lds	Wed Feb 13 10:37:18 2008 -0700
    20.2 +++ b/extras/mini-os/arch/x86/minios-x86_32.lds	Thu Feb 14 09:34:27 2008 -0700
    20.3 @@ -16,6 +16,18 @@ SECTIONS
    20.4    . = ALIGN(4096);
    20.5    _erodata = .;
    20.6  
    20.7 +  /* newlib initialization functions */
    20.8 +  . = ALIGN(32 / 8);
    20.9 +  PROVIDE (__preinit_array_start = .);
   20.10 +  .preinit_array     : { *(.preinit_array) }
   20.11 +  PROVIDE (__preinit_array_end = .);
   20.12 +  PROVIDE (__init_array_start = .);
   20.13 +  .init_array     : { *(.init_array) }
   20.14 +  PROVIDE (__init_array_end = .);
   20.15 +  PROVIDE (__fini_array_start = .);
   20.16 +  .fini_array     : { *(.fini_array) }
   20.17 +  PROVIDE (__fini_array_end = .);
   20.18 +
   20.19    .data : {			/* Data */
   20.20  	*(.data)
   20.21  	CONSTRUCTORS
    21.1 --- a/extras/mini-os/arch/x86/minios-x86_64.lds	Wed Feb 13 10:37:18 2008 -0700
    21.2 +++ b/extras/mini-os/arch/x86/minios-x86_64.lds	Thu Feb 14 09:34:27 2008 -0700
    21.3 @@ -16,6 +16,18 @@ SECTIONS
    21.4    . = ALIGN(4096);
    21.5    _erodata = .;
    21.6  
    21.7 +  /* newlib initialization functions */
    21.8 +  . = ALIGN(64 / 8);
    21.9 +  PROVIDE (__preinit_array_start = .);
   21.10 +  .preinit_array     : { *(.preinit_array) }
   21.11 +  PROVIDE (__preinit_array_end = .);
   21.12 +  PROVIDE (__init_array_start = .);
   21.13 +  .init_array     : { *(.init_array) }
   21.14 +  PROVIDE (__init_array_end = .);
   21.15 +  PROVIDE (__fini_array_start = .);
   21.16 +  .fini_array     : { *(.fini_array) }
   21.17 +  PROVIDE (__fini_array_end = .);
   21.18 +
   21.19    .data : {			/* Data */
   21.20  	*(.data)
   21.21  	CONSTRUCTORS
    22.1 --- a/extras/mini-os/arch/x86/mm.c	Wed Feb 13 10:37:18 2008 -0700
    22.2 +++ b/extras/mini-os/arch/x86/mm.c	Thu Feb 14 09:34:27 2008 -0700
    22.3 @@ -448,6 +448,15 @@ static unsigned long demand_map_area_sta
    22.4  #define DEMAND_MAP_PAGES ((2ULL << 30) / PAGE_SIZE)
    22.5  #endif
    22.6  
    22.7 +#ifdef HAVE_LIBC
    22.8 +unsigned long heap, brk, heap_mapped, heap_end;
    22.9 +#ifdef __x86_64__
   22.10 +#define HEAP_PAGES ((128ULL << 30) / PAGE_SIZE)
   22.11 +#else
   22.12 +#define HEAP_PAGES ((1ULL << 30) / PAGE_SIZE)
   22.13 +#endif
   22.14 +#endif
   22.15 +
   22.16  void arch_init_demand_mapping_area(unsigned long cur_pfn)
   22.17  {
   22.18      cur_pfn++;
   22.19 @@ -455,6 +464,14 @@ void arch_init_demand_mapping_area(unsig
   22.20      demand_map_area_start = (unsigned long) pfn_to_virt(cur_pfn);
   22.21      cur_pfn += DEMAND_MAP_PAGES;
   22.22      printk("Demand map pfns at %lx-%lx.\n", demand_map_area_start, pfn_to_virt(cur_pfn));
   22.23 +
   22.24 +#ifdef HAVE_LIBC
   22.25 +    cur_pfn++;
   22.26 +    heap_mapped = brk = heap = (unsigned long) pfn_to_virt(cur_pfn);
   22.27 +    cur_pfn += HEAP_PAGES;
   22.28 +    heap_end = (unsigned long) pfn_to_virt(cur_pfn);
   22.29 +    printk("Heap resides at %lx-%lx.\n", brk, heap_end);
   22.30 +#endif
   22.31  }
   22.32  
   22.33  #define MAP_BATCH ((STACK_SIZE / 2) / sizeof(mmu_update_t))
    23.1 --- a/extras/mini-os/arch/x86/x86_32.S	Wed Feb 13 10:37:18 2008 -0700
    23.2 +++ b/extras/mini-os/arch/x86/x86_32.S	Thu Feb 14 09:34:27 2008 -0700
    23.3 @@ -1,5 +1,5 @@
    23.4  #include <os.h>
    23.5 -#include <arch_mm.h>
    23.6 +#include <arch_limits.h>
    23.7  #include <xen/arch-x86_32.h>
    23.8  
    23.9  .section __xen_guest
   23.10 @@ -22,12 +22,12 @@
   23.11  _start:
   23.12          cld
   23.13          lss stack_start,%esp
   23.14 -        andl $(~(STACK_SIZE-1)), %esp
   23.15 +        andl $(~(__STACK_SIZE-1)), %esp
   23.16          push %esi 
   23.17          call start_kernel
   23.18  
   23.19  stack_start:
   23.20 -	.long stack+(2*STACK_SIZE), __KERNEL_SS
   23.21 +	.long stack+(2*__STACK_SIZE), __KERNEL_SS
   23.22  
   23.23          /* Unpleasant -- the PTE that maps this page is actually overwritten */
   23.24          /* to map the real shared-info page! :-)                             */
    24.1 --- a/extras/mini-os/arch/x86/x86_64.S	Wed Feb 13 10:37:18 2008 -0700
    24.2 +++ b/extras/mini-os/arch/x86/x86_64.S	Thu Feb 14 09:34:27 2008 -0700
    24.3 @@ -1,5 +1,5 @@
    24.4  #include <os.h>
    24.5 -#include <arch_mm.h>
    24.6 +#include <arch_limits.h>
    24.7  #include <xen/features.h>
    24.8  
    24.9  .section __xen_guest
   24.10 @@ -19,12 +19,12 @@
   24.11  _start:
   24.12          cld
   24.13          movq stack_start(%rip),%rsp
   24.14 -        andq $(~(STACK_SIZE-1)), %rsp
   24.15 +        andq $(~(__STACK_SIZE-1)), %rsp
   24.16          movq %rsi,%rdi
   24.17          call start_kernel
   24.18  
   24.19  stack_start:
   24.20 -        .quad stack+(2*STACK_SIZE)
   24.21 +        .quad stack+(2*__STACK_SIZE)
   24.22  
   24.23          /* Unpleasant -- the PTE that maps this page is actually overwritten */
   24.24          /* to map the real shared-info page! :-)                             */
    25.1 --- a/extras/mini-os/blkfront.c	Wed Feb 13 10:37:18 2008 -0700
    25.2 +++ b/extras/mini-os/blkfront.c	Thu Feb 14 09:34:27 2008 -0700
    25.3 @@ -15,6 +15,10 @@
    25.4  #include <lib.h>
    25.5  #include <fcntl.h>
    25.6  
    25.7 +#ifndef HAVE_LIBC
    25.8 +#define strtoul simple_strtoul
    25.9 +#endif
   25.10 +
   25.11  /* Note: we generally don't need to disable IRQs since we hardly do anything in
   25.12   * the interrupt handler.  */
   25.13  
   25.14 @@ -49,15 +53,20 @@ struct blkfront_dev {
   25.15      int mode;
   25.16      int barrier;
   25.17      int flush;
   25.18 -};
   25.19  
   25.20 -static inline int xenblk_rxidx(RING_IDX idx)
   25.21 -{
   25.22 -    return idx & (BLK_RING_SIZE - 1);
   25.23 -}
   25.24 +#ifdef HAVE_LIBC
   25.25 +    int fd;
   25.26 +#endif
   25.27 +};
   25.28  
   25.29  void blkfront_handler(evtchn_port_t port, struct pt_regs *regs, void *data)
   25.30  {
   25.31 +#ifdef HAVE_LIBC
   25.32 +    struct blkfront_dev *dev = data;
   25.33 +    int fd = dev->fd;
   25.34 +
   25.35 +    files[fd].read = 1;
   25.36 +#endif
   25.37      wake_up(&blkfront_queue);
   25.38  }
   25.39  
   25.40 @@ -148,7 +157,7 @@ done:
   25.41  
   25.42      printk("backend at %s\n", dev->backend);
   25.43  
   25.44 -    dev->handle = simple_strtoul(strrchr(nodename, '/')+1, NULL, 0);
   25.45 +    dev->handle = strtoul(strrchr(nodename, '/')+1, NULL, 0);
   25.46  
   25.47      {
   25.48          char path[strlen(dev->backend) + 1 + 19 + 1];
   25.49 @@ -313,6 +322,11 @@ int blkfront_aio_poll(struct blkfront_de
   25.50      struct blkif_response *rsp;
   25.51  
   25.52  moretodo:
   25.53 +#ifdef HAVE_LIBC
   25.54 +    files[dev->fd].read = 0;
   25.55 +    mb(); /* Make sure to let the handler set read to 1 before we start looking at the ring */
   25.56 +#endif
   25.57 +
   25.58      rp = dev->ring.sring->rsp_prod;
   25.59      rmb(); /* Ensure we see queued responses up to 'rp'. */
   25.60      cons = dev->ring.rsp_cons;
   25.61 @@ -322,12 +336,16 @@ moretodo:
   25.62      {
   25.63  	rsp = RING_GET_RESPONSE(&dev->ring, cons);
   25.64  
   25.65 +        if (rsp->status != BLKIF_RSP_OKAY)
   25.66 +            printk("block error %d for op %d\n", rsp->status, rsp->operation);
   25.67 +
   25.68          switch (rsp->operation) {
   25.69          case BLKIF_OP_READ:
   25.70          case BLKIF_OP_WRITE:
   25.71          {
   25.72              struct blkfront_aiocb *aiocbp = (void*) (uintptr_t) rsp->id;
   25.73              int j;
   25.74 +
   25.75              for (j = 0; j < aiocbp->n; j++)
   25.76                  gnttab_end_access(aiocbp->gref[j]);
   25.77  
   25.78 @@ -365,6 +383,12 @@ static void blkfront_push_operation(stru
   25.79      i = dev->ring.req_prod_pvt;
   25.80      req = RING_GET_REQUEST(&dev->ring, i);
   25.81      req->operation = op;
   25.82 +    req->nr_segments = 0;
   25.83 +    req->handle = dev->handle;
   25.84 +    /* Not used */
   25.85 +    req->id = 0;
   25.86 +    /* Not needed anyway, but the backend will check it */
   25.87 +    req->sector_number = 0;
   25.88      dev->ring.req_prod_pvt = i + 1;
   25.89      wmb();
   25.90      RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&dev->ring, notify);
   25.91 @@ -375,11 +399,13 @@ void blkfront_sync(struct blkfront_dev *
   25.92  {
   25.93      unsigned long flags;
   25.94  
   25.95 -    if (dev->barrier == 1)
   25.96 -        blkfront_push_operation(dev, BLKIF_OP_WRITE_BARRIER);
   25.97 +    if (dev->mode == O_RDWR) {
   25.98 +        if (dev->barrier == 1)
   25.99 +            blkfront_push_operation(dev, BLKIF_OP_WRITE_BARRIER);
  25.100  
  25.101 -    if (dev->flush == 1)
  25.102 -        blkfront_push_operation(dev, BLKIF_OP_FLUSH_DISKCACHE);
  25.103 +        if (dev->flush == 1)
  25.104 +            blkfront_push_operation(dev, BLKIF_OP_FLUSH_DISKCACHE);
  25.105 +    }
  25.106  
  25.107      /* Note: This won't finish if another thread enqueues requests.  */
  25.108      local_irq_save(flags);
  25.109 @@ -397,3 +423,13 @@ void blkfront_sync(struct blkfront_dev *
  25.110      remove_waiter(w);
  25.111      local_irq_restore(flags);
  25.112  }
  25.113 +
  25.114 +#ifdef HAVE_LIBC
  25.115 +int blkfront_open(struct blkfront_dev *dev)
  25.116 +{
  25.117 +    dev->fd = alloc_fd(FTYPE_BLK);
  25.118 +    printk("blk_open(%s) -> %d\n", dev->nodename, dev->fd);
  25.119 +    files[dev->fd].blk.dev = dev;
  25.120 +    return dev->fd;
  25.121 +}
  25.122 +#endif
    26.1 --- a/extras/mini-os/include/arch/cc.h	Wed Feb 13 10:37:18 2008 -0700
    26.2 +++ b/extras/mini-os/include/arch/cc.h	Thu Feb 14 09:34:27 2008 -0700
    26.3 @@ -54,7 +54,14 @@ extern void lwip_die(char *fmt, ...);
    26.4  #include <errno.h>
    26.5  
    26.6  /*   Not required by the docs, but needed for network-order calculations */
    26.7 +#ifdef HAVE_LIBC
    26.8 +#include <machine/endian.h>
    26.9 +#ifndef BIG_ENDIAN
   26.10 +#error endian.h does not define byte order
   26.11 +#endif
   26.12 +#else
   26.13  #include <endian.h>
   26.14 +#endif
   26.15  
   26.16  #include <inttypes.h>
   26.17  #define S16_F PRIi16
    27.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.2 +++ b/extras/mini-os/include/byteswap.h	Thu Feb 14 09:34:27 2008 -0700
    27.3 @@ -0,0 +1,22 @@
    27.4 +#ifndef _BYTESWAP_H_
    27.5 +#define _BYTESWAP_H_
    27.6 +
    27.7 +/* Unfortunately not provided by newlib.  */
    27.8 +#define bswap_16(x) \
    27.9 +    ((((x) & 0xff00) >> 8) | (((x) & 0xff) << 8))
   27.10 +
   27.11 +#define bswap_32(x) \
   27.12 +    ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >>  8) | \
   27.13 +     (((x) & 0x0000ff00) <<  8) | (((x) & 0x000000ff) << 24))
   27.14 +
   27.15 +#define bswap_64(x) \
   27.16 +    ((((x) & 0xff00000000000000ULL) >> 56) | \
   27.17 +     (((x) & 0x00ff000000000000ULL) >> 40) | \
   27.18 +     (((x) & 0x0000ff0000000000ULL) >> 24) | \
   27.19 +     (((x) & 0x000000ff00000000ULL) >>  8) | \
   27.20 +     (((x) & 0x00000000ff000000ULL) <<  8) | \
   27.21 +     (((x) & 0x0000000000ff0000ULL) << 24) | \
   27.22 +     (((x) & 0x000000000000ff00ULL) << 40) | \
   27.23 +     (((x) & 0x00000000000000ffULL) << 56))
   27.24 +
   27.25 +#endif /* _BYTESWAP_H */
    28.1 --- a/extras/mini-os/include/console.h	Wed Feb 13 10:37:18 2008 -0700
    28.2 +++ b/extras/mini-os/include/console.h	Thu Feb 14 09:34:27 2008 -0700
    28.3 @@ -36,7 +36,9 @@
    28.4  #ifndef _LIB_CONSOLE_H_
    28.5  #define _LIB_CONSOLE_H_
    28.6  
    28.7 +#include<os.h>
    28.8  #include<traps.h>
    28.9 +#include<stdarg.h>
   28.10  
   28.11  void print(int direct, const char *fmt, va_list args);
   28.12  void printk(const char *fmt, ...);
   28.13 @@ -48,5 +50,6 @@ void xencons_rx(char *buf, unsigned len,
   28.14  void xencons_tx(void);
   28.15  
   28.16  void init_console(void);
   28.17 +void console_print(char *data, int length);
   28.18  
   28.19  #endif /* _LIB_CONSOLE_H_ */
    29.1 --- a/extras/mini-os/include/errno.h	Wed Feb 13 10:37:18 2008 -0700
    29.2 +++ b/extras/mini-os/include/errno.h	Thu Feb 14 09:34:27 2008 -0700
    29.3 @@ -107,4 +107,11 @@
    29.4  #define	EOWNERDEAD	130	/* Owner died */
    29.5  #define	ENOTRECOVERABLE	131	/* State not recoverable */
    29.6  
    29.7 +#ifdef HAVE_LIBC
    29.8 +#include <sched.h>
    29.9 +extern int errno;
   29.10 +#define ERRNO
   29.11 +#define errno (get_current()->reent._errno)
   29.12  #endif
   29.13 +
   29.14 +#endif
    30.1 --- a/extras/mini-os/include/fcntl.h	Wed Feb 13 10:37:18 2008 -0700
    30.2 +++ b/extras/mini-os/include/fcntl.h	Thu Feb 14 09:34:27 2008 -0700
    30.3 @@ -86,4 +86,7 @@ struct flock64 {
    30.4  
    30.5  #define F_LINUX_SPECIFIC_BASE	1024
    30.6  */
    30.7 +
    30.8 +int open(const char *path, int flags, ...);
    30.9 +int fcntl(int fd, int cmd, ...);
   30.10  #endif
    31.1 --- a/extras/mini-os/include/fs.h	Wed Feb 13 10:37:18 2008 -0700
    31.2 +++ b/extras/mini-os/include/fs.h	Thu Feb 14 09:34:27 2008 -0700
    31.3 @@ -22,6 +22,7 @@ struct fs_import
    31.4      struct semaphore reqs_sem;      /* Accounts requests resource           */
    31.5  };
    31.6  
    31.7 +extern struct fs_import *fs_import;
    31.8  
    31.9  void init_fs_frontend(void);
   31.10  
    32.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    32.2 +++ b/extras/mini-os/include/ia64/arch_limits.h	Thu Feb 14 09:34:27 2008 -0700
    32.3 @@ -0,0 +1,12 @@
    32.4 +
    32.5 +#ifndef __ARCH_LIMITS_H__
    32.6 +#define __ARCH_LIMITS_H__
    32.7 +
    32.8 +/* Commonly 16K pages are used. */
    32.9 +#define __PAGE_SHIFT	14	/* 16K pages */
   32.10 +#define __PAGE_SIZE	(1<<(__PAGE_SHIFT))
   32.11 +
   32.12 +#define __STACK_SIZE_PAGE_ORDER   2
   32.13 +#define __STACK_SIZE              (__PAGE_SIZE * (1 << __STACK_SIZE_PAGE_ORDER))
   32.14 +          
   32.15 +#endif /* __ARCH_LIMITS_H__ */
    33.1 --- a/extras/mini-os/include/ia64/arch_mm.h	Wed Feb 13 10:37:18 2008 -0700
    33.2 +++ b/extras/mini-os/include/ia64/arch_mm.h	Thu Feb 14 09:34:27 2008 -0700
    33.3 @@ -35,11 +35,9 @@
    33.4  #define virt_to_mfn(x)	virt_to_pfn(x)
    33.5  #define virtual_to_mfn(x)      (ia64_tpa((uint64_t)(x)) >> PAGE_SHIFT)
    33.6  
    33.7 -#define STACK_SIZE_PAGE_ORDER   1
    33.8 -#define STACK_SIZE              (PAGE_SIZE * (1 << STACK_SIZE_PAGE_ORDER))
    33.9 -
   33.10  #define map_frames(f, n) map_frames_ex(f, n, 1, 0, 1, DOMID_SELF, 0, 0)
   33.11  /* TODO */
   33.12  #define map_zero(n, a) map_frames_ex(NULL, n, 0, 0, a, DOMID_SELF, 0, 0)
   33.13 +#define do_map_zero(start, n) ((void)0)
   33.14  
   33.15  #endif /* __ARCH_MM_H__ */
    34.1 --- a/extras/mini-os/include/ia64/page.h	Wed Feb 13 10:37:18 2008 -0700
    34.2 +++ b/extras/mini-os/include/ia64/page.h	Thu Feb 14 09:34:27 2008 -0700
    34.3 @@ -43,9 +43,9 @@
    34.4  /* The efi-pal page size for text and data. */
    34.5  #define PAL_TR_PAGE_SIZE	PTE_PS_1M
    34.6  
    34.7 -/* Commonly 16K pages are used. */
    34.8 -#define PAGE_SHIFT	14	/* 16K pages */
    34.9 -#define PAGE_SIZE	(1<<(PAGE_SHIFT))
   34.10 +#include "arch_limits.h"
   34.11 +#define PAGE_SHIFT	__PAGE_SHIFT
   34.12 +#define PAGE_SIZE	__PAGE_SIZE
   34.13  #define PAGE_MASK	(~(PAGE_SIZE-1))
   34.14  
   34.15  #define KSTACK_PAGES	4	/* 4 pages for the kernel stack + bsp */
    35.1 --- a/extras/mini-os/include/lib.h	Wed Feb 13 10:37:18 2008 -0700
    35.2 +++ b/extras/mini-os/include/lib.h	Thu Feb 14 09:34:27 2008 -0700
    35.3 @@ -57,6 +57,8 @@
    35.4  
    35.5  #include <stdarg.h>
    35.6  #include <stddef.h>
    35.7 +#include <xen/xen.h>
    35.8 +#include <xen/event_channel.h>
    35.9  
   35.10  #ifdef HAVE_LIBC
   35.11  #include <stdio.h>
   35.12 @@ -103,6 +105,8 @@ char  *strdup(const char *s);
   35.13  
   35.14  int rand(void);
   35.15  
   35.16 +#include <xenbus.h>
   35.17 +
   35.18  #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
   35.19  
   35.20  struct kvec {
   35.21 @@ -126,4 +130,59 @@ do {                                    
   35.22  /* Consistency check as much as possible. */
   35.23  void sanity_check(void);
   35.24  
   35.25 +#ifdef HAVE_LIBC
   35.26 +enum fd_type {
   35.27 +    FTYPE_NONE = 0,
   35.28 +    FTYPE_CONSOLE,
   35.29 +    FTYPE_FILE,
   35.30 +    FTYPE_XENBUS,
   35.31 +    FTYPE_EVTCHN,
   35.32 +    FTYPE_SOCKET,
   35.33 +    FTYPE_TAP,
   35.34 +    FTYPE_BLK,
   35.35 +};
   35.36 +
   35.37 +#define MAX_EVTCHN_PORTS 16
   35.38 +
   35.39 +extern struct file {
   35.40 +    enum fd_type type;
   35.41 +    union {
   35.42 +	struct {
   35.43 +            /* lwIP fd */
   35.44 +	    int fd;
   35.45 +	} socket;
   35.46 +	struct {
   35.47 +            /* FS import fd */
   35.48 +	    int fd;
   35.49 +	    off_t offset;
   35.50 +	} file;
   35.51 +	struct {
   35.52 +            /* To each event channel FD is associated a series of ports which
   35.53 +             * wakes select for this FD. */
   35.54 +            struct {
   35.55 +                evtchn_port_t port;
   35.56 +                volatile unsigned long pending;
   35.57 +                int bound;
   35.58 +            } ports[MAX_EVTCHN_PORTS];
   35.59 +	} evtchn;
   35.60 +	struct {
   35.61 +	    struct netfront_dev *dev;
   35.62 +	} tap;
   35.63 +	struct {
   35.64 +	    struct blkfront_dev *dev;
   35.65 +	} blk;
   35.66 +        struct {
   35.67 +            /* To each xenbus FD is associated a queue of watch events for this
   35.68 +             * FD.  */
   35.69 +            struct xenbus_event *volatile events;
   35.70 +        } xenbus;
   35.71 +    };
   35.72 +    volatile int read;	/* maybe available for read */
   35.73 +} files[];
   35.74 +
   35.75 +int alloc_fd(enum fd_type type);
   35.76 +void close_all_files(void);
   35.77 +extern struct thread *main_thread;
   35.78 +#endif
   35.79 +
   35.80  #endif /* _LIB_H_ */
    36.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    36.2 +++ b/extras/mini-os/include/linux/types.h	Thu Feb 14 09:34:27 2008 -0700
    36.3 @@ -0,0 +1,5 @@
    36.4 +#ifndef _LINUX_TYPES_H_
    36.5 +#define _LINUX_TYPES_H_
    36.6 +#include <types.h>
    36.7 +typedef u64 __u64;
    36.8 +#endif /* _LINUX_TYPES_H_ */
    37.1 --- a/extras/mini-os/include/mm.h	Wed Feb 13 10:37:18 2008 -0700
    37.2 +++ b/extras/mini-os/include/mm.h	Thu Feb 14 09:34:27 2008 -0700
    37.3 @@ -36,8 +36,13 @@
    37.4  #endif
    37.5  
    37.6  #include <lib.h>
    37.7 +
    37.8 +#include <arch_limits.h>
    37.9  #include <arch_mm.h>
   37.10  
   37.11 +#define STACK_SIZE_PAGE_ORDER __STACK_SIZE_PAGE_ORDER
   37.12 +#define STACK_SIZE __STACK_SIZE
   37.13 +
   37.14  
   37.15  void init_mm(void);
   37.16  unsigned long alloc_pages(int order);
   37.17 @@ -61,5 +66,8 @@ void arch_init_p2m(unsigned long max_pfn
   37.18  void *map_frames_ex(unsigned long *f, unsigned long n, unsigned long stride,
   37.19  	unsigned long increment, unsigned long alignment, domid_t id,
   37.20  	int may_fail, unsigned long prot);
   37.21 +#ifdef HAVE_LIBC
   37.22 +extern unsigned long heap, brk, heap_mapped, heap_end;
   37.23 +#endif
   37.24  
   37.25  #endif /* _MM_H_ */
    38.1 --- a/extras/mini-os/include/netfront.h	Wed Feb 13 10:37:18 2008 -0700
    38.2 +++ b/extras/mini-os/include/netfront.h	Thu Feb 14 09:34:27 2008 -0700
    38.3 @@ -6,6 +6,10 @@ struct netfront_dev;
    38.4  struct netfront_dev *init_netfront(char *nodename, void (*netif_rx)(unsigned char *data, int len), unsigned char rawmac[6]);
    38.5  void netfront_xmit(struct netfront_dev *dev, unsigned char* data,int len);
    38.6  void shutdown_netfront(struct netfront_dev *dev);
    38.7 +#ifdef HAVE_LIBC
    38.8 +int netfront_tap_open(char *nodename);
    38.9 +ssize_t netfront_receive(struct netfront_dev *dev, unsigned char *data, size_t len);
   38.10 +#endif
   38.11  
   38.12  extern struct wait_queue_head netfront_queue;
   38.13  
    39.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    39.2 +++ b/extras/mini-os/include/posix/dirent.h	Thu Feb 14 09:34:27 2008 -0700
    39.3 @@ -0,0 +1,24 @@
    39.4 +#ifndef _POSIX_DIRENT_H
    39.5 +#define _POSIX_DIRENT_H
    39.6 +
    39.7 +#include <sys/types.h>
    39.8 +
    39.9 +struct dirent {
   39.10 +        char *d_name;
   39.11 +};
   39.12 +
   39.13 +typedef struct {
   39.14 +        struct dirent dirent;
   39.15 +        char *name;
   39.16 +        int32_t offset;
   39.17 +        char **entries;
   39.18 +        int32_t curentry;
   39.19 +        int32_t nbentries;
   39.20 +        int has_more;
   39.21 +} DIR;
   39.22 +
   39.23 +DIR *opendir(const char *name);
   39.24 +struct dirent *readdir(DIR *dir);
   39.25 +int closedir(DIR *dir);
   39.26 +
   39.27 +#endif /* _POSIX_DIRENT_H */
    40.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    40.2 +++ b/extras/mini-os/include/posix/limits.h	Thu Feb 14 09:34:27 2008 -0700
    40.3 @@ -0,0 +1,9 @@
    40.4 +#ifndef _POSIX_LIMITS_H
    40.5 +#define _POSIX_LIMITS_H
    40.6 +
    40.7 +#include_next <limits.h>
    40.8 +#include <arch_limits.h>
    40.9 +
   40.10 +#define PATH_MAX __PAGE_SIZE
   40.11 +
   40.12 +#endif /* _POSIX_LIMITS_H */
    41.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    41.2 +++ b/extras/mini-os/include/posix/netdb.h	Thu Feb 14 09:34:27 2008 -0700
    41.3 @@ -0,0 +1,9 @@
    41.4 +#ifndef _POSIX_NETDB_H_
    41.5 +#define _POSIX_NETDB_H_
    41.6 +
    41.7 +struct hostent {
    41.8 +    char *h_addr;
    41.9 +};
   41.10 +#define gethostbyname(buf) NULL
   41.11 +
   41.12 +#endif /* _POSIX_NETDB_H_ */
    42.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    42.2 +++ b/extras/mini-os/include/posix/netinet/in.h	Thu Feb 14 09:34:27 2008 -0700
    42.3 @@ -0,0 +1,7 @@
    42.4 +#ifndef _POSIX_SYS_IN_H_
    42.5 +#define _POSIX_SYS_IN_H_
    42.6 +
    42.7 +#include <fcntl.h>
    42.8 +#include <lwip/sockets.h>
    42.9 +
   42.10 +#endif /* _POSIX_SYS_IN_H_ */
    43.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    43.2 +++ b/extras/mini-os/include/posix/netinet/tcp.h	Thu Feb 14 09:34:27 2008 -0700
    43.3 @@ -0,0 +1,6 @@
    43.4 +#ifndef _POSIX_SYS_TCP_H_
    43.5 +#define _POSIX_SYS_TCP_H_
    43.6 +
    43.7 +#include <lwip/tcp.h>
    43.8 +
    43.9 +#endif /* _POSIX_SYS_TCP_H_ */
    44.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    44.2 +++ b/extras/mini-os/include/posix/pthread.h	Thu Feb 14 09:34:27 2008 -0700
    44.3 @@ -0,0 +1,19 @@
    44.4 +#ifndef _POSIX_PTHREAD_H
    44.5 +#define _POSIX_PTHREAD_H
    44.6 +
    44.7 +/* Let's be single-threaded for now.  */
    44.8 +
    44.9 +typedef void *pthread_key_t;
   44.10 +typedef struct {} pthread_mutex_t, pthread_once_t;
   44.11 +#define PTHREAD_MUTEX_INITIALIZER {}
   44.12 +#define PTHREAD_ONCE_INIT {}
   44.13 +static inline int pthread_mutex_lock(pthread_mutex_t *mutex) { return 0; }
   44.14 +static inline int pthread_mutex_unlock(pthread_mutex_t *mutex) { return 0; }
   44.15 +static inline int pthread_key_create(pthread_key_t *key, void (*destr_function)(void*)) { *key = NULL; return 0; }
   44.16 +static inline int pthread_setspecific(pthread_key_t *key, const void *pointer) { *key = (void*) pointer; return 0; }
   44.17 +static inline void *pthread_getspecific(pthread_key_t *key) { return *key; }
   44.18 +static inline int pthread_once(pthread_once_t *once_control, void (*init_routine)(void)) { init_routine(); return 0; }
   44.19 +
   44.20 +#define __thread
   44.21 +
   44.22 +#endif /* _POSIX_PTHREAD_H */
    45.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    45.2 +++ b/extras/mini-os/include/posix/stdlib.h	Thu Feb 14 09:34:27 2008 -0700
    45.3 @@ -0,0 +1,8 @@
    45.4 +#ifndef _POSIX_STDLIB_H
    45.5 +#define _POSIX_STDLIB_H
    45.6 +
    45.7 +#include_next <stdlib.h>
    45.8 +
    45.9 +#define realpath(p,r) strcpy(r,p)
   45.10 +
   45.11 +#endif /* _POSIX_STDLIB_H */
    46.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    46.2 +++ b/extras/mini-os/include/posix/strings.h	Thu Feb 14 09:34:27 2008 -0700
    46.3 @@ -0,0 +1,8 @@
    46.4 +#ifndef _POSIX_STRINGS_H
    46.5 +#define _POSIX_STRINGS_H
    46.6 +
    46.7 +#include <string.h>
    46.8 +
    46.9 +#define bzero(ptr, size) (memset((ptr), '\0', (size)), (void) 0)
   46.10 +
   46.11 +#endif /* _POSIX_STRINGS_H */
    47.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    47.2 +++ b/extras/mini-os/include/posix/sys/ioctl.h	Thu Feb 14 09:34:27 2008 -0700
    47.3 @@ -0,0 +1,16 @@
    47.4 +#ifndef _POSIX_SYS_IOCTL_H
    47.5 +#define _POSIX_SYS_IOCTL_H
    47.6 +
    47.7 +int ioctl(int fd, int request, ...);
    47.8 +
    47.9 +#define _IOC_NONE 0
   47.10 +#define _IOC_WRITE 1
   47.11 +#define _IOC_READ 2
   47.12 +
   47.13 +#define _IOC(rw, class, n, size) \
   47.14 +    	(((rw   ) << 30) | \
   47.15 +	 ((class) << 22) | \
   47.16 +	 ((n    ) << 14) | \
   47.17 +	 ((size ) << 0))
   47.18 +
   47.19 +#endif /* _POSIX_SYS_IOCTL_H */
    48.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    48.2 +++ b/extras/mini-os/include/posix/sys/mman.h	Thu Feb 14 09:34:27 2008 -0700
    48.3 @@ -0,0 +1,19 @@
    48.4 +#ifndef _POSIX_SYS_MMAN_H
    48.5 +#define _POSIX_SYS_MMAN_H
    48.6 +
    48.7 +#define PROT_READ	0x1
    48.8 +#define PROT_WRITE	0x2
    48.9 +#define PROT_EXEC	0x4
   48.10 +
   48.11 +#define MAP_SHARED	0x01
   48.12 +#define MAP_PRIVATE	0x02
   48.13 +#define MAP_ANON	0x20
   48.14 +
   48.15 +#define MAP_FAILED	((void*)0)
   48.16 +
   48.17 +void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset);
   48.18 +int munmap(void *start, size_t length);
   48.19 +#define munlock(addr, len) ((void)addr, (void)len, 0)
   48.20 +#define mlock(addr, len) ((void)addr, (void)len, 0)
   48.21 +
   48.22 +#endif /* _POSIX_SYS_MMAN_H */
    49.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    49.2 +++ b/extras/mini-os/include/posix/sys/select.h	Thu Feb 14 09:34:27 2008 -0700
    49.3 @@ -0,0 +1,7 @@
    49.4 +#ifndef _POSIX_SELECT_H
    49.5 +#define _POSIX_SELECT_H
    49.6 +
    49.7 +#include <sys/time.h>
    49.8 +int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
    49.9 +
   49.10 +#endif /* _POSIX_SELECT_H */
    50.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    50.2 +++ b/extras/mini-os/include/posix/sys/socket.h	Thu Feb 14 09:34:27 2008 -0700
    50.3 @@ -0,0 +1,31 @@
    50.4 +#ifndef _POSIX_SYS_SOCKET_H_
    50.5 +#define _POSIX_SYS_SOCKET_H_
    50.6 +
    50.7 +#include <fcntl.h>
    50.8 +#include <lwip/sockets.h>
    50.9 +
   50.10 +int accept(int s, struct sockaddr *addr, socklen_t *addrlen);
   50.11 +int bind(int s, struct sockaddr *name, socklen_t namelen);
   50.12 +int shutdown(int s, int how);
   50.13 +int getpeername (int s, struct sockaddr *name, socklen_t *namelen);
   50.14 +int getsockname (int s, struct sockaddr *name, socklen_t *namelen);
   50.15 +int getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen);
   50.16 +int setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen);
   50.17 +int close(int s);
   50.18 +int connect(int s, struct sockaddr *name, socklen_t namelen);
   50.19 +int listen(int s, int backlog);
   50.20 +int recv(int s, void *mem, int len, unsigned int flags);
   50.21 +//int read(int s, void *mem, int len);
   50.22 +int recvfrom(int s, void *mem, int len, unsigned int flags,
   50.23 +      struct sockaddr *from, socklen_t *fromlen);
   50.24 +int send(int s, void *dataptr, int size, unsigned int flags);
   50.25 +int sendto(int s, void *dataptr, int size, unsigned int flags,
   50.26 +    struct sockaddr *to, socklen_t tolen);
   50.27 +int socket(int domain, int type, int protocol);
   50.28 +//int write(int s, void *dataptr, int size);
   50.29 +int select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
   50.30 +                struct timeval *timeout);
   50.31 +//int ioctl(int s, long cmd, void *argp);
   50.32 +int getsockname(int s, struct sockaddr *name, socklen_t *namelen);
   50.33 +
   50.34 +#endif /* _POSIX_SYS_SOCKET_H_ */
    51.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    51.2 +++ b/extras/mini-os/include/posix/termios.h	Thu Feb 14 09:34:27 2008 -0700
    51.3 @@ -0,0 +1,87 @@
    51.4 +#ifndef _POSIX_TERMIOS_H
    51.5 +#define _POSIX_TERMIOS_H
    51.6 +
    51.7 +#define NCC 32
    51.8 +
    51.9 +struct termios {
   51.10 +    unsigned long c_iflag;
   51.11 +    unsigned long c_oflag;
   51.12 +    unsigned long c_lflag;
   51.13 +    unsigned long c_cflag;
   51.14 +    unsigned char c_cc[NCC];
   51.15 +};
   51.16 +
   51.17 +/* modem lines */
   51.18 +#define TIOCM_DTR	0x002
   51.19 +#define TIOCM_RTS	0x004
   51.20 +#define TIOCM_CTS	0x020
   51.21 +#define TIOCM_CAR	0x040
   51.22 +#define TIOCM_RI	0x080
   51.23 +#define TIOCM_DSR	0x100
   51.24 +
   51.25 +/* c_iflag */
   51.26 +#define IGNBRK	0x00000001
   51.27 +#define BRKINT	0x00000002
   51.28 +#define IGNPAR	0x00000004
   51.29 +#define PARMRK	0x00000008
   51.30 +#define INPCK	0x00000010
   51.31 +#define ISTRIP	0x00000020
   51.32 +#define INLCR	0x00000040
   51.33 +#define IGNCR	0x00000080
   51.34 +#define ICRNL	0x00000100
   51.35 +#define IUCLC	0x00000200
   51.36 +#define IXON	0x00000400
   51.37 +#define IXANY	0x00000800
   51.38 +#define IXOFF	0x00001000
   51.39 +#define IMAXBEL	0x00002000
   51.40 +#define IUTF8	0x00004000
   51.41 +
   51.42 +/* c_oflag */
   51.43 +#define OPOST	0x00000001
   51.44 +#define OLCUC	0x00000002
   51.45 +#define ONLCR	0x00000004
   51.46 +#define OCRNL	0x00000008
   51.47 +#define ONOCR	0x00000010
   51.48 +#define ONLRET	0x00000020
   51.49 +#define OFILL	0x00000040
   51.50 +#define OFDEL	0x00000080
   51.51 +
   51.52 +/* c_lflag */
   51.53 +#define ISIG	0x00000001
   51.54 +#define ICANON	0x00000002
   51.55 +#define XCASE	0x00000004
   51.56 +#define ECHO	0x00000008
   51.57 +#define ECHOE	0x00000010
   51.58 +#define ECHOK	0x00000020
   51.59 +#define ECHONL	0x00000040
   51.60 +#define NOFLSH	0x00000080
   51.61 +#define TOSTOP	0x00000100
   51.62 +#define ECHOCTL	0x00000200
   51.63 +#define ECHOPRT	0x00000400
   51.64 +#define ECHOKE	0x00000800
   51.65 +#define FLUSHO	0x00002000
   51.66 +#define PENDIN	0x00004000
   51.67 +#define IEXTEN	0x00008000
   51.68 +
   51.69 +/* c_cflag */
   51.70 +#define CSIZE	0x00000030
   51.71 +#define CS8	0x00000030
   51.72 +#define CSTOPB	0x00000040
   51.73 +#define CREAD	0x00000080
   51.74 +#define PARENB	0x00000100
   51.75 +#define PARODD	0x00000200
   51.76 +#define HUPCL	0x00000400
   51.77 +#define CLOCAL	0x00000800
   51.78 +
   51.79 +/* c_cc */
   51.80 +#define VTIME	5
   51.81 +#define VMIN	6
   51.82 +
   51.83 +#define TCSANOW		0
   51.84 +#define TCSADRAIN	1
   51.85 +#define TCSAFLUSH	2
   51.86 +
   51.87 +int tcsetattr(int fildes, int action, const struct termios *tios);
   51.88 +int tcgetattr(int fildes, struct termios *tios);
   51.89 +
   51.90 +#endif /* _POSIX_TERMIOS_H */
    52.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    52.2 +++ b/extras/mini-os/include/posix/time.h	Thu Feb 14 09:34:27 2008 -0700
    52.3 @@ -0,0 +1,10 @@
    52.4 +#ifndef _POSIX_TIME_H
    52.5 +#define _POSIX_TIME_H
    52.6 +
    52.7 +#include <sys/time.h>
    52.8 +#define CLOCK_MONOTONIC	2
    52.9 +#include_next <time.h>
   52.10 +
   52.11 +int nanosleep(const struct timespec *req, struct timespec *rem);
   52.12 +
   52.13 +#endif /* _POSIX_TIME_H */
    53.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    53.2 +++ b/extras/mini-os/include/posix/unistd.h	Thu Feb 14 09:34:27 2008 -0700
    53.3 @@ -0,0 +1,12 @@
    53.4 +#ifndef _POSIX_UNISTD_H
    53.5 +#define _POSIX_UNISTD_H
    53.6 +
    53.7 +#include_next <unistd.h>
    53.8 +#include <sys/select.h>
    53.9 +#include <arch_limits.h>
   53.10 +
   53.11 +#define getpagesize() __PAGE_SIZE
   53.12 +
   53.13 +int ftruncate(int fd, off_t length);
   53.14 +
   53.15 +#endif /* _POSIX_UNISTD_H */
    54.1 --- a/extras/mini-os/include/sched.h	Wed Feb 13 10:37:18 2008 -0700
    54.2 +++ b/extras/mini-os/include/sched.h	Thu Feb 14 09:34:27 2008 -0700
    54.3 @@ -19,6 +19,9 @@ struct thread
    54.4      struct list_head thread_list;
    54.5      u32 flags;
    54.6      s_time_t wakeup_time;
    54.7 +#ifdef HAVE_LIBC
    54.8 +    struct _reent reent;
    54.9 +#endif
   54.10  };
   54.11  
   54.12  extern struct thread *idle_thread;
    55.1 --- a/extras/mini-os/include/sys/time.h	Wed Feb 13 10:37:18 2008 -0700
    55.2 +++ b/extras/mini-os/include/sys/time.h	Thu Feb 14 09:34:27 2008 -0700
    55.3 @@ -20,6 +20,9 @@
    55.4  #ifndef _MINIOS_SYS_TIME_H_
    55.5  #define _MINIOS_SYS_TIME_H_
    55.6  
    55.7 +#ifdef HAVE_LIBC
    55.8 +#include_next <sys/time.h>
    55.9 +#else
   55.10  struct timespec {
   55.11      time_t      tv_sec;
   55.12      long        tv_nsec;
   55.13 @@ -34,5 +37,6 @@ struct timeval {
   55.14  };
   55.15  
   55.16  int      gettimeofday(struct timeval *tv, void *tz);
   55.17 +#endif
   55.18  
   55.19  #endif /* _MINIOS_SYS_TIME_H_ */
    56.1 --- a/extras/mini-os/include/time.h	Wed Feb 13 10:37:18 2008 -0700
    56.2 +++ b/extras/mini-os/include/time.h	Thu Feb 14 09:34:27 2008 -0700
    56.3 @@ -17,8 +17,9 @@
    56.4   ****************************************************************************
    56.5   */
    56.6  
    56.7 -#ifndef _TIME_H_
    56.8 -#define _TIME_H_
    56.9 +#ifndef _MINIOS_TIME_H_
   56.10 +#define _MINIOS_TIME_H_
   56.11 +#include <types.h>
   56.12  
   56.13  /*
   56.14   * System Time
   56.15 @@ -44,8 +45,12 @@ typedef s64 s_time_t;
   56.16  /* wall clock time  */
   56.17  typedef long time_t;
   56.18  typedef long suseconds_t;
   56.19 +
   56.20  #include <sys/time.h>
   56.21  
   56.22 +#ifdef HAVE_LIBC
   56.23 +#include_next <time.h>
   56.24 +#endif
   56.25  
   56.26  /* prototypes */
   56.27  void     init_time(void);
   56.28 @@ -54,4 +59,4 @@ s_time_t get_v_time(void);
   56.29  u64      monotonic_clock(void);
   56.30  void     block_domain(s_time_t until);
   56.31  
   56.32 -#endif /* _TIME_H_ */
   56.33 +#endif /* _MINIOS_TIME_H_ */
    57.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    57.2 +++ b/extras/mini-os/include/x86/arch_limits.h	Thu Feb 14 09:34:27 2008 -0700
    57.3 @@ -0,0 +1,20 @@
    57.4 +
    57.5 +#ifndef __ARCH_LIMITS_H__
    57.6 +#define __ARCH_LIMITS_H__
    57.7 +
    57.8 +#define __PAGE_SHIFT      12
    57.9 +
   57.10 +#ifdef __ASSEMBLY__
   57.11 +#define __PAGE_SIZE       (1 << __PAGE_SHIFT)
   57.12 +#else
   57.13 +#ifndef CONFIG_X86_PAE
   57.14 +#define __PAGE_SIZE       (1UL << __PAGE_SHIFT)
   57.15 +#else
   57.16 +#define __PAGE_SIZE       (1ULL << __PAGE_SHIFT)
   57.17 +#endif
   57.18 +#endif
   57.19 +
   57.20 +#define __STACK_SIZE_PAGE_ORDER  4
   57.21 +#define __STACK_SIZE             (__PAGE_SIZE * (1 << __STACK_SIZE_PAGE_ORDER))
   57.22 +          
   57.23 +#endif /* __ARCH_LIMITS_H__ */
    58.1 --- a/extras/mini-os/include/x86/arch_mm.h	Wed Feb 13 10:37:18 2008 -0700
    58.2 +++ b/extras/mini-os/include/x86/arch_mm.h	Thu Feb 14 09:34:27 2008 -0700
    58.3 @@ -157,16 +157,9 @@ typedef unsigned long pgentry_t;
    58.4  #define L4_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER)
    58.5  #endif /* __i386__ || __x86_64__ */
    58.6  
    58.7 -#ifdef __ASSEMBLY__
    58.8 -#define PAGE_SIZE       (1 << L1_PAGETABLE_SHIFT)
    58.9 -#else
   58.10 -#ifndef CONFIG_X86_PAE
   58.11 -#define PAGE_SIZE       (1UL << L1_PAGETABLE_SHIFT)
   58.12 -#else
   58.13 -#define PAGE_SIZE       (1ULL << L1_PAGETABLE_SHIFT)
   58.14 -#endif
   58.15 -#endif
   58.16 -#define PAGE_SHIFT      L1_PAGETABLE_SHIFT
   58.17 +#include "arch_limits.h"
   58.18 +#define PAGE_SIZE       __PAGE_SIZE
   58.19 +#define PAGE_SHIFT      __PAGE_SHIFT
   58.20  #define PAGE_MASK       (~(PAGE_SIZE-1))
   58.21  
   58.22  #define PFN_UP(x)	(((x) + PAGE_SIZE-1) >> L1_PAGETABLE_SHIFT)
   58.23 @@ -177,9 +170,6 @@ typedef unsigned long pgentry_t;
   58.24  /* to align the pointer to the (next) page boundary */
   58.25  #define PAGE_ALIGN(addr)        (((addr)+PAGE_SIZE-1)&PAGE_MASK)
   58.26  
   58.27 -#define STACK_SIZE_PAGE_ORDER  1
   58.28 -#define STACK_SIZE             (PAGE_SIZE * (1 << STACK_SIZE_PAGE_ORDER))
   58.29 -
   58.30  #ifndef __ASSEMBLY__
   58.31  /* Definitions for machine and pseudophysical addresses. */
   58.32  #ifdef CONFIG_X86_PAE
   58.33 @@ -257,5 +247,11 @@ static __inline__ paddr_t machine_to_phy
   58.34  
   58.35  #define map_frames(f, n) map_frames_ex(f, n, 1, 0, 1, DOMID_SELF, 0, L1_PROT)
   58.36  #define map_zero(n, a) map_frames_ex(&mfn_zero, n, 0, 0, a, DOMID_SELF, 0, L1_PROT_RO)
   58.37 +#ifndef __ASSEMBLY__
   58.38 +void do_map_frames(unsigned long addr,
   58.39 +        unsigned long *f, unsigned long n, unsigned long stride,
   58.40 +	unsigned long increment, domid_t id, int may_fail, unsigned long prot);
   58.41 +#endif
   58.42 +#define do_map_zero(start, n) do_map_frames(start, &mfn_zero, n, 0, 0, DOMID_SELF, 0, L1_PROT_RO)
   58.43  
   58.44  #endif /* _ARCH_MM_H_ */
    59.1 --- a/extras/mini-os/include/x86/arch_sched.h	Wed Feb 13 10:37:18 2008 -0700
    59.2 +++ b/extras/mini-os/include/x86/arch_sched.h	Thu Feb 14 09:34:27 2008 -0700
    59.3 @@ -2,7 +2,7 @@
    59.4  #ifndef __ARCH_SCHED_H__
    59.5  #define __ARCH_SCHED_H__
    59.6  
    59.7 -#include <arch_mm.h>
    59.8 +#include <arch_limits.h>
    59.9  
   59.10  static inline struct thread* get_current(void)
   59.11  {
   59.12 @@ -12,7 +12,7 @@ static inline struct thread* get_current
   59.13  #else
   59.14      register unsigned long sp asm("rsp");
   59.15  #endif 
   59.16 -    current = (void *)(unsigned long)(sp & ~(STACK_SIZE-1));
   59.17 +    current = (void *)(unsigned long)(sp & ~(__STACK_SIZE-1));
   59.18      return *current;
   59.19  }
   59.20  
    60.1 --- a/extras/mini-os/include/x86/arch_spinlock.h	Wed Feb 13 10:37:18 2008 -0700
    60.2 +++ b/extras/mini-os/include/x86/arch_spinlock.h	Thu Feb 14 09:34:27 2008 -0700
    60.3 @@ -4,6 +4,7 @@
    60.4  #define __ARCH_ASM_SPINLOCK_H
    60.5  
    60.6  #include <lib.h>
    60.7 +#include "os.h"
    60.8  
    60.9  
   60.10  #define ARCH_SPIN_LOCK_UNLOCKED (spinlock_t) { 1 }
    61.1 --- a/extras/mini-os/include/x86/os.h	Wed Feb 13 10:37:18 2008 -0700
    61.2 +++ b/extras/mini-os/include/x86/os.h	Thu Feb 14 09:34:27 2008 -0700
    61.3 @@ -563,6 +563,7 @@ static __inline__ int synch_var_test_bit
    61.4   synch_var_test_bit((nr),(addr)))
    61.5  
    61.6  
    61.7 +#undef ADDR
    61.8  
    61.9  #endif /* not assembly */
   61.10  #endif /* _OS_H_ */
    62.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    62.2 +++ b/extras/mini-os/lib/sys.c	Thu Feb 14 09:34:27 2008 -0700
    62.3 @@ -0,0 +1,1083 @@
    62.4 +/*
    62.5 + * POSIX-compatible libc layer
    62.6 + *
    62.7 + * Samuel Thibault <Samuel.Thibault@eu.citrix.net>, October 2007
    62.8 + *
    62.9 + * Provides the UNIXish part of the standard libc function.
   62.10 + *
   62.11 + * Relatively straight-forward: just multiplex the file descriptor operations
   62.12 + * among the various file types (console, FS, network, ...)
   62.13 + */
   62.14 +
   62.15 +//#define LIBC_VERBOSE
   62.16 +//#define LIBC_DEBUG
   62.17 +
   62.18 +#ifdef LIBC_DEBUG
   62.19 +#define DEBUG(fmt,...) printk(fmt, ##__VA_ARGS__)
   62.20 +#else
   62.21 +#define DEBUG(fmt,...)
   62.22 +#endif
   62.23 +
   62.24 +#ifdef HAVE_LIBC
   62.25 +#include <os.h>
   62.26 +#include <console.h>
   62.27 +#include <sched.h>
   62.28 +#include <events.h>
   62.29 +#include <wait.h>
   62.30 +#include <netfront.h>
   62.31 +#include <blkfront.h>
   62.32 +#include <xenbus.h>
   62.33 +#include <xs.h>
   62.34 +
   62.35 +#include <sys/types.h>
   62.36 +#include <sys/unistd.h>
   62.37 +#include <sys/stat.h>
   62.38 +#include <sys/mman.h>
   62.39 +#include <time.h>
   62.40 +#include <errno.h>
   62.41 +#include <fcntl.h>
   62.42 +#include <pthread.h>
   62.43 +#include <assert.h>
   62.44 +#include <dirent.h>
   62.45 +#include <stdlib.h>
   62.46 +#include <math.h>
   62.47 +
   62.48 +#include <lwip/sockets.h>
   62.49 +#include <fs.h>
   62.50 +
   62.51 +#define debug(fmt, ...) \
   62.52 +
   62.53 +#define print_unsupported(fmt, ...) \
   62.54 +    printk("Unsupported function "fmt" called in Mini-OS kernel\n", ## __VA_ARGS__);
   62.55 +
   62.56 +/* Crash on function call */
   62.57 +#define unsupported_function_crash(function) \
   62.58 +    int __unsup_##function(void) asm(#function); \
   62.59 +    int __unsup_##function(void) \
   62.60 +    { \
   62.61 +	print_unsupported(#function); \
   62.62 +	do_exit(); \
   62.63 +    }
   62.64 +
   62.65 +/* Log and err out on function call */
   62.66 +#define unsupported_function_log(type, function, ret) \
   62.67 +    type __unsup_##function(void) asm(#function); \
   62.68 +    type __unsup_##function(void) \
   62.69 +    { \
   62.70 +	print_unsupported(#function); \
   62.71 +	errno = ENOSYS; \
   62.72 +	return ret; \
   62.73 +    }
   62.74 +
   62.75 +/* Err out on function call */
   62.76 +#define unsupported_function(type, function, ret) \
   62.77 +    type __unsup_##function(void) asm(#function); \
   62.78 +    type __unsup_##function(void) \
   62.79 +    { \
   62.80 +	errno = ENOSYS; \
   62.81 +	return ret; \
   62.82 +    }
   62.83 +
   62.84 +#define NOFILE 32
   62.85 +extern int xc_evtchn_close(int fd);
   62.86 +
   62.87 +pthread_mutex_t fd_lock = PTHREAD_MUTEX_INITIALIZER;
   62.88 +struct file files[NOFILE] = {
   62.89 +    { .type = FTYPE_CONSOLE }, /* stdin */
   62.90 +    { .type = FTYPE_CONSOLE }, /* stdout */
   62.91 +    { .type = FTYPE_CONSOLE }, /* stderr */
   62.92 +};
   62.93 +
   62.94 +DECLARE_WAIT_QUEUE_HEAD(event_queue);
   62.95 +
   62.96 +int alloc_fd(enum fd_type type)
   62.97 +{
   62.98 +    int i;
   62.99 +    pthread_mutex_lock(&fd_lock);
  62.100 +    for (i=0; i<NOFILE; i++) {
  62.101 +	if (files[i].type == FTYPE_NONE) {
  62.102 +	    files[i].type = type;
  62.103 +	    pthread_mutex_unlock(&fd_lock);
  62.104 +	    return i;
  62.105 +	}
  62.106 +    }
  62.107 +    pthread_mutex_unlock(&fd_lock);
  62.108 +    printk("Too many opened files\n");
  62.109 +    do_exit();
  62.110 +}
  62.111 +
  62.112 +void close_all_files(void)
  62.113 +{
  62.114 +    int i;
  62.115 +    pthread_mutex_lock(&fd_lock);
  62.116 +    for (i=NOFILE - 1; i > 0; i--)
  62.117 +	if (files[i].type != FTYPE_NONE)
  62.118 +            close(i);
  62.119 +    pthread_mutex_unlock(&fd_lock);
  62.120 +}
  62.121 +
  62.122 +int dup2(int oldfd, int newfd)
  62.123 +{
  62.124 +    pthread_mutex_lock(&fd_lock);
  62.125 +    if (files[newfd].type != FTYPE_NONE)
  62.126 +	close(newfd);
  62.127 +    // XXX: this is a bit bogus, as we are supposed to share the offset etc
  62.128 +    files[newfd] = files[oldfd];
  62.129 +    pthread_mutex_unlock(&fd_lock);
  62.130 +    return 0;
  62.131 +}
  62.132 +
  62.133 +pid_t getpid(void)
  62.134 +{
  62.135 +    return 1;
  62.136 +}
  62.137 +
  62.138 +pid_t getppid(void)
  62.139 +{
  62.140 +    return 1;
  62.141 +}
  62.142 +
  62.143 +pid_t setsid(void)
  62.144 +{
  62.145 +    return 1;
  62.146 +}
  62.147 +
  62.148 +char *getcwd(char *buf, size_t size)
  62.149 +{
  62.150 +    snprintf(buf, size, "/");
  62.151 +    return buf;
  62.152 +}
  62.153 +
  62.154 +#define LOG_PATH "/var/log/"
  62.155 +
  62.156 +int mkdir(const char *pathname, mode_t mode)
  62.157 +{
  62.158 +    int ret;
  62.159 +    ret = fs_create(fs_import, (char *) pathname, 1, mode);
  62.160 +    if (ret < 0) {
  62.161 +        errno = EIO;
  62.162 +        return -1;
  62.163 +    }
  62.164 +    return 0;
  62.165 +}
  62.166 +
  62.167 +int open(const char *pathname, int flags, ...)
  62.168 +{
  62.169 +    int fs_fd, fd;
  62.170 +    /* Ugly, but fine.  */
  62.171 +    if (!strncmp(pathname,LOG_PATH,strlen(LOG_PATH))) {
  62.172 +	fd = alloc_fd(FTYPE_CONSOLE);
  62.173 +        printk("open(%s) -> %d\n", pathname, fd);
  62.174 +        return fd;
  62.175 +    }
  62.176 +    printk("open(%s)", pathname);
  62.177 +    fs_fd = fs_open(fs_import, (void *) pathname);
  62.178 +    if (fs_fd < 0) {
  62.179 +	errno = EIO;
  62.180 +	return -1;
  62.181 +    }
  62.182 +    fd = alloc_fd(FTYPE_FILE);
  62.183 +    printk("-> %d\n", fd);
  62.184 +    files[fd].file.fd = fs_fd;
  62.185 +    files[fd].file.offset = 0;
  62.186 +    return fd;
  62.187 +}
  62.188 +#if defined(__x86_64__) || defined(__ia64__)
  62.189 +__typeof__(open) open64 __attribute__((__alias__("open")));
  62.190 +#endif
  62.191 +
  62.192 +int isatty(int fd)
  62.193 +{
  62.194 +    return files[fd].type == FTYPE_CONSOLE;
  62.195 +}
  62.196 +
  62.197 +int read(int fd, void *buf, size_t nbytes)
  62.198 +{
  62.199 +    switch (files[fd].type) {
  62.200 +	case FTYPE_CONSOLE:
  62.201 +	    return 0;
  62.202 +	case FTYPE_FILE: {
  62.203 +	    ssize_t ret;
  62.204 +	    if (nbytes > PAGE_SIZE)
  62.205 +		nbytes = PAGE_SIZE;
  62.206 +	    ret = fs_read(fs_import, files[fd].file.fd, buf, nbytes, files[fd].file.offset);
  62.207 +	    if (ret > 0) {
  62.208 +		files[fd].file.offset += ret;
  62.209 +		return ret;
  62.210 +	    } else if (ret < 0) {
  62.211 +		errno = EIO;
  62.212 +		return -1;
  62.213 +	    }
  62.214 +	    return 0;
  62.215 +	}
  62.216 +	case FTYPE_SOCKET:
  62.217 +	    return lwip_read(files[fd].socket.fd, buf, nbytes);
  62.218 +	case FTYPE_TAP: {
  62.219 +	    ssize_t ret;
  62.220 +	    ret = netfront_receive(files[fd].tap.dev, buf, nbytes);
  62.221 +	    if (ret <= 0) {
  62.222 +		errno = EAGAIN;
  62.223 +		return -1;
  62.224 +	    }
  62.225 +	    return ret;
  62.226 +	}
  62.227 +	case FTYPE_NONE:
  62.228 +	case FTYPE_XENBUS:
  62.229 +	case FTYPE_EVTCHN:
  62.230 +	case FTYPE_BLK:
  62.231 +	    break;
  62.232 +    }
  62.233 +    printk("read(%d): Bad descriptor\n", fd);
  62.234 +    errno = EBADF;
  62.235 +    return -1;
  62.236 +}
  62.237 +
  62.238 +int write(int fd, const void *buf, size_t nbytes)
  62.239 +{
  62.240 +    switch (files[fd].type) {
  62.241 +	case FTYPE_CONSOLE:
  62.242 +	    console_print((char *)buf, nbytes);
  62.243 +	    return nbytes;
  62.244 +	case FTYPE_FILE: {
  62.245 +	    ssize_t ret;
  62.246 +	    if (nbytes > PAGE_SIZE)
  62.247 +		nbytes = PAGE_SIZE;
  62.248 +	    ret = fs_write(fs_import, files[fd].file.fd, (void *) buf, nbytes, files[fd].file.offset);
  62.249 +	    if (ret > 0) {
  62.250 +		files[fd].file.offset += ret;
  62.251 +		return ret;
  62.252 +	    } else if (ret < 0) {
  62.253 +		errno = EIO;
  62.254 +		return -1;
  62.255 +	    }
  62.256 +	    return 0;
  62.257 +	}
  62.258 +	case FTYPE_SOCKET:
  62.259 +	    return lwip_write(files[fd].socket.fd, (void*) buf, nbytes);
  62.260 +	case FTYPE_TAP:
  62.261 +	    netfront_xmit(files[fd].tap.dev, (void*) buf, nbytes);
  62.262 +	    return nbytes;
  62.263 +	case FTYPE_NONE:
  62.264 +	case FTYPE_XENBUS:
  62.265 +	case FTYPE_EVTCHN:
  62.266 +	case FTYPE_BLK:
  62.267 +	    break;
  62.268 +    }
  62.269 +    printk("write(%d): Bad descriptor\n", fd);
  62.270 +    errno = EBADF;
  62.271 +    return -1;
  62.272 +}
  62.273 +
  62.274 +off_t lseek(int fd, off_t offset, int whence)
  62.275 +{
  62.276 +    if (files[fd].type != FTYPE_FILE) {
  62.277 +	errno = ESPIPE;
  62.278 +	return (off_t) -1;
  62.279 +    }
  62.280 +    switch (whence) {
  62.281 +	case SEEK_SET:
  62.282 +	    files[fd].file.offset = offset;
  62.283 +	    break;
  62.284 +	case SEEK_CUR:
  62.285 +	    files[fd].file.offset += offset;
  62.286 +	    break;
  62.287 +	case SEEK_END: {
  62.288 +	    struct stat st;
  62.289 +	    int ret;
  62.290 +	    ret = fstat(fd, &st);
  62.291 +	    if (ret)
  62.292 +		return -1;
  62.293 +	    files[fd].file.offset = st.st_size + offset;
  62.294 +	    break;
  62.295 +	}
  62.296 +	default:
  62.297 +	    errno = EINVAL;
  62.298 +	    return -1;
  62.299 +    }
  62.300 +    return files[fd].file.offset;
  62.301 +}
  62.302 +#if defined(__x86_64__) || defined(__ia64__)
  62.303 +__typeof__(lseek) lseek64 __attribute__((__alias__("lseek")));
  62.304 +#endif
  62.305 +
  62.306 +int fsync(int fd) {
  62.307 +    switch (files[fd].type) {
  62.308 +	case FTYPE_FILE: {
  62.309 +	    int ret;
  62.310 +	    ret = fs_sync(fs_import, files[fd].file.fd);
  62.311 +	    if (ret < 0) {
  62.312 +		errno = EIO;
  62.313 +		return -1;
  62.314 +	    }
  62.315 +	    return 0;
  62.316 +	}
  62.317 +	case FTYPE_NONE:
  62.318 +	case FTYPE_CONSOLE:
  62.319 +	case FTYPE_SOCKET:
  62.320 +	case FTYPE_XENBUS:
  62.321 +	case FTYPE_EVTCHN:
  62.322 +	case FTYPE_TAP:
  62.323 +	case FTYPE_BLK:
  62.324 +	    break;
  62.325 +    }
  62.326 +    printk("fsync(%d): Bad descriptor\n", fd);
  62.327 +    errno = EBADF;
  62.328 +    return -1;
  62.329 +}
  62.330 +
  62.331 +int close(int fd)
  62.332 +{
  62.333 +    printk("close(%d)\n", fd);
  62.334 +    switch (files[fd].type) {
  62.335 +	case FTYPE_CONSOLE:
  62.336 +	    files[fd].type = FTYPE_NONE;
  62.337 +	    return 0;
  62.338 +	case FTYPE_FILE: {
  62.339 +	    int ret = fs_close(fs_import, files[fd].file.fd);
  62.340 +	    files[fd].type = FTYPE_NONE;
  62.341 +	    if (ret < 0) {
  62.342 +		errno = EIO;
  62.343 +		return -1;
  62.344 +	    }
  62.345 +	    return 0;
  62.346 +	}
  62.347 +	case FTYPE_XENBUS:
  62.348 +            xs_daemon_close((void*)(intptr_t) fd);
  62.349 +            return 0;
  62.350 +	case FTYPE_SOCKET: {
  62.351 +	    int res = lwip_close(files[fd].socket.fd);
  62.352 +	    files[fd].type = FTYPE_NONE;
  62.353 +	    return res;
  62.354 +	}
  62.355 +	case FTYPE_EVTCHN:
  62.356 +            xc_evtchn_close(fd);
  62.357 +            return 0;
  62.358 +	case FTYPE_TAP:
  62.359 +	    shutdown_netfront(files[fd].tap.dev);
  62.360 +	    files[fd].type = FTYPE_NONE;
  62.361 +	    return 0;
  62.362 +	case FTYPE_BLK:
  62.363 +            shutdown_blkfront(files[fd].blk.dev);
  62.364 +	    files[fd].type = FTYPE_NONE;
  62.365 +	    return 0;
  62.366 +	case FTYPE_NONE:
  62.367 +	    break;
  62.368 +    }
  62.369 +    printk("close(%d): Bad descriptor\n", fd);
  62.370 +    errno = EBADF;
  62.371 +    return -1;
  62.372 +}
  62.373 +
  62.374 +static void init_stat(struct stat *buf)
  62.375 +{
  62.376 +    memset(buf, 0, sizeof(*buf));
  62.377 +    buf->st_dev = 0;
  62.378 +    buf->st_ino = 0;
  62.379 +    buf->st_nlink = 1;
  62.380 +    buf->st_rdev = 0;
  62.381 +    buf->st_blksize = 4096;
  62.382 +    buf->st_blocks = 0;
  62.383 +}
  62.384 +
  62.385 +static void stat_from_fs(struct stat *buf, struct fsif_stat_response *stat)
  62.386 +{
  62.387 +    buf->st_mode = stat->stat_mode;
  62.388 +    buf->st_uid = stat->stat_uid;
  62.389 +    buf->st_gid = stat->stat_gid;
  62.390 +    buf->st_size = stat->stat_size;
  62.391 +    buf->st_atime = stat->stat_atime;
  62.392 +    buf->st_mtime = stat->stat_mtime;
  62.393 +    buf->st_ctime = stat->stat_ctime;
  62.394 +}
  62.395 +
  62.396 +int stat(const char *path, struct stat *buf)
  62.397 +{
  62.398 +    struct fsif_stat_response stat;
  62.399 +    int ret;
  62.400 +    int fs_fd;
  62.401 +    printk("stat(%s)\n", path);
  62.402 +    fs_fd = fs_open(fs_import, (char*) path);
  62.403 +    if (fs_fd < 0) {
  62.404 +	errno = EIO;
  62.405 +	ret = -1;
  62.406 +	goto out;
  62.407 +    }
  62.408 +    ret = fs_stat(fs_import, fs_fd, &stat);
  62.409 +    if (ret < 0) {
  62.410 +	errno = EIO;
  62.411 +	ret = -1;
  62.412 +	goto outfd;
  62.413 +    }
  62.414 +    init_stat(buf);
  62.415 +    stat_from_fs(buf, &stat);
  62.416 +    ret = 0;
  62.417 +
  62.418 +outfd:
  62.419 +    fs_close(fs_import, fs_fd);
  62.420 +out:
  62.421 +    return ret;
  62.422 +}
  62.423 +
  62.424 +int fstat(int fd, struct stat *buf)
  62.425 +{
  62.426 +    init_stat(buf);
  62.427 +    switch (files[fd].type) {
  62.428 +	case FTYPE_CONSOLE:
  62.429 +	case FTYPE_SOCKET: {
  62.430 +	    buf->st_mode = (files[fd].type == FTYPE_CONSOLE?S_IFCHR:S_IFSOCK) | S_IRUSR|S_IWUSR;
  62.431 +	    buf->st_uid = 0;
  62.432 +	    buf->st_gid = 0;
  62.433 +	    buf->st_size = 0;
  62.434 +	    buf->st_atime = 
  62.435 +	    buf->st_mtime = 
  62.436 +	    buf->st_ctime = time(NULL);
  62.437 +	    return 0;
  62.438 +	}
  62.439 +	case FTYPE_FILE: {
  62.440 +	    struct fsif_stat_response stat;
  62.441 +	    int ret;
  62.442 +	    ret = fs_stat(fs_import, files[fd].file.fd, &stat);
  62.443 +	    if (ret < 0) {
  62.444 +		errno = EIO;
  62.445 +		return -1;
  62.446 +	    }
  62.447 +	    /* The protocol is a bit evasive about this value */
  62.448 +	    stat_from_fs(buf, &stat);
  62.449 +	    return 0;
  62.450 +	}
  62.451 +	case FTYPE_NONE:
  62.452 +	case FTYPE_XENBUS:
  62.453 +	case FTYPE_EVTCHN:
  62.454 +	case FTYPE_TAP:
  62.455 +	case FTYPE_BLK:
  62.456 +	    break;
  62.457 +    }
  62.458 +
  62.459 +    printk("statf(%d): Bad descriptor\n", fd);
  62.460 +    errno = EBADF;
  62.461 +    return -1;
  62.462 +}
  62.463 +
  62.464 +int ftruncate(int fd, off_t length)
  62.465 +{
  62.466 +    switch (files[fd].type) {
  62.467 +	case FTYPE_FILE: {
  62.468 +            int ret;
  62.469 +            ret = fs_truncate(fs_import, files[fd].file.fd, length);
  62.470 +	    if (ret < 0) {
  62.471 +		errno = EIO;
  62.472 +		return -1;
  62.473 +	    }
  62.474 +	    return 0;
  62.475 +	}
  62.476 +	case FTYPE_NONE:
  62.477 +	case FTYPE_CONSOLE:
  62.478 +	case FTYPE_SOCKET:
  62.479 +	case FTYPE_XENBUS:
  62.480 +	case FTYPE_EVTCHN:
  62.481 +	case FTYPE_TAP:
  62.482 +	case FTYPE_BLK:
  62.483 +	    break;
  62.484 +    }
  62.485 +
  62.486 +    printk("ftruncate(%d): Bad descriptor\n", fd);
  62.487 +    errno = EBADF;
  62.488 +    return -1;
  62.489 +}
  62.490 +
  62.491 +int remove(const char *pathname)
  62.492 +{
  62.493 +    int ret;
  62.494 +    printk("remove(%s)", pathname);
  62.495 +    ret = fs_remove(fs_import, (char*) pathname);
  62.496 +    if (ret < 0) {
  62.497 +        errno = EIO;
  62.498 +        return -1;
  62.499 +    }
  62.500 +    return 0;
  62.501 +}
  62.502 +
  62.503 +int unlink(const char *pathname)
  62.504 +{
  62.505 +    return remove(pathname);
  62.506 +}
  62.507 +
  62.508 +int rmdir(const char *pathname)
  62.509 +{
  62.510 +    return remove(pathname);
  62.511 +}
  62.512 +
  62.513 +int fcntl(int fd, int cmd, ...)
  62.514 +{
  62.515 +    long arg;
  62.516 +    va_list ap;
  62.517 +    va_start(ap, cmd);
  62.518 +    arg = va_arg(ap, long);
  62.519 +    va_end(ap);
  62.520 +
  62.521 +    switch (cmd) {
  62.522 +	case F_SETFL:
  62.523 +	    if (files[fd].type == FTYPE_SOCKET && !(arg & ~O_NONBLOCK)) {
  62.524 +		/* Only flag supported: non-blocking mode */
  62.525 +		uint32_t nblock = !!(arg & O_NONBLOCK);
  62.526 +		return lwip_ioctl(files[fd].socket.fd, FIONBIO, &nblock);
  62.527 +	    }
  62.528 +	    /* Fallthrough */
  62.529 +	default:
  62.530 +	    printk("fcntl(%d, %d, %lx/%lo)\n", fd, cmd, arg, arg);
  62.531 +	    errno = ENOSYS;
  62.532 +	    return -1;
  62.533 +    }
  62.534 +}
  62.535 +
  62.536 +DIR *opendir(const char *name)
  62.537 +{
  62.538 +    DIR *ret;
  62.539 +    ret = malloc(sizeof(*ret));
  62.540 +    ret->name = strdup(name);
  62.541 +    ret->offset = 0;
  62.542 +    ret->entries = NULL;
  62.543 +    ret->curentry = -1;
  62.544 +    ret->nbentries = 0;
  62.545 +    ret->has_more = 1;
  62.546 +    return ret;
  62.547 +}
  62.548 +
  62.549 +struct dirent *readdir(DIR *dir)
  62.550 +{
  62.551 +    if (dir->curentry >= 0) {
  62.552 +        free(dir->entries[dir->curentry]);
  62.553 +        dir->entries[dir->curentry] = NULL;
  62.554 +    }
  62.555 +    dir->curentry++;
  62.556 +    if (dir->curentry >= dir->nbentries) {
  62.557 +        dir->offset += dir->nbentries;
  62.558 +        free(dir->entries);
  62.559 +        dir->curentry = -1;
  62.560 +        dir->nbentries = 0;
  62.561 +        if (!dir->has_more)
  62.562 +            return NULL;
  62.563 +        dir->entries = fs_list(fs_import, dir->name, dir->offset, &dir->nbentries, &dir->has_more);
  62.564 +        if (!dir->entries || !dir->nbentries)
  62.565 +            return NULL;
  62.566 +        dir->curentry = 0;
  62.567 +    }
  62.568 +    dir->dirent.d_name = dir->entries[dir->curentry];
  62.569 +    return &dir->dirent;
  62.570 +} 
  62.571 +int closedir(DIR *dir)
  62.572 +{
  62.573 +    int i;
  62.574 +    for (i=0; i<dir->nbentries; i++)
  62.575 +        free(dir->entries[i]);
  62.576 +    free(dir->entries);
  62.577 +    free(dir->name);
  62.578 +    free(dir);
  62.579 +    return 0;
  62.580 +}
  62.581 +
  62.582 +/* We assume that only the main thread calls select(). */
  62.583 +
  62.584 +static const char file_types[] = {
  62.585 +    [FTYPE_NONE]	= 'N',
  62.586 +    [FTYPE_CONSOLE]	= 'C',
  62.587 +    [FTYPE_FILE]	= 'F',
  62.588 +    [FTYPE_XENBUS]	= 'X',
  62.589 +    [FTYPE_EVTCHN]	= 'E',
  62.590 +    [FTYPE_SOCKET]	= 'S',
  62.591 +    [FTYPE_TAP]		= 'T',
  62.592 +    [FTYPE_BLK]		= 'B',
  62.593 +};
  62.594 +#ifdef LIBC_DEBUG
  62.595 +static void dump_set(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
  62.596 +{
  62.597 +    int i, comma;
  62.598 +#define printfds(set) do {\
  62.599 +    comma = 0; \
  62.600 +    for (i = 0; i < nfds; i++) { \
  62.601 +	if (FD_ISSET(i, set)) { \
  62.602 +	    if (comma) \
  62.603 +		printk(", "); \
  62.604 +	    printk("%d(%c)", i, file_types[files[i].type]); \
  62.605 +	    comma = 1; \
  62.606 +	} \
  62.607 +    } \
  62.608 +} while (0)
  62.609 +
  62.610 +    printk("[");
  62.611 +    if (readfds)
  62.612 +	printfds(readfds);
  62.613 +    printk("], [");
  62.614 +    if (writefds)
  62.615 +	printfds(writefds);
  62.616 +    printk("], [");
  62.617 +    if (exceptfds)
  62.618 +	printfds(exceptfds);
  62.619 +    printk("], ");
  62.620 +    if (timeout)
  62.621 +	printk("{ %ld, %ld }", timeout->tv_sec, timeout->tv_usec);
  62.622 +}
  62.623 +#else
  62.624 +#define dump_set(nfds, readfds, writefds, exceptfds, timeout)
  62.625 +#endif
  62.626 +
  62.627 +/* Just poll without blocking */
  62.628 +static int select_poll(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds)
  62.629 +{
  62.630 +    int i, n = 0, sock_n, sock_nfds = 0;
  62.631 +    fd_set sock_readfds, sock_writefds, sock_exceptfds;
  62.632 +    struct timeval timeout = { .tv_sec = 0, .tv_usec = 0};
  62.633 +
  62.634 +#ifdef LIBC_VERBOSE
  62.635 +    static int nb;
  62.636 +    static int nbread[NOFILE], nbwrite[NOFILE], nbexcept[NOFILE];
  62.637 +    static s64_t lastshown;
  62.638 +
  62.639 +    nb++;
  62.640 +#endif
  62.641 +
  62.642 +    /* first poll network */
  62.643 +    FD_ZERO(&sock_readfds);
  62.644 +    FD_ZERO(&sock_writefds);
  62.645 +    FD_ZERO(&sock_exceptfds);
  62.646 +    for (i = 0; i < nfds; i++) {
  62.647 +	if (files[i].type == FTYPE_SOCKET) {
  62.648 +	    if (FD_ISSET(i, readfds)) {
  62.649 +		FD_SET(files[i].socket.fd, &sock_readfds);
  62.650 +		sock_nfds = i+1;
  62.651 +	    }
  62.652 +	    if (FD_ISSET(i, writefds)) {
  62.653 +		FD_SET(files[i].socket.fd, &sock_writefds);
  62.654 +		sock_nfds = i+1;
  62.655 +	    }
  62.656 +	    if (FD_ISSET(i, exceptfds)) {
  62.657 +		FD_SET(files[i].socket.fd, &sock_exceptfds);
  62.658 +		sock_nfds = i+1;
  62.659 +	    }
  62.660 +	}
  62.661 +    }
  62.662 +    DEBUG("lwip_select(");
  62.663 +    dump_set(nfds, &sock_readfds, &sock_writefds, &sock_exceptfds, &timeout);
  62.664 +    DEBUG("); -> ");
  62.665 +    sock_n = lwip_select(sock_nfds, &sock_readfds, &sock_writefds, &sock_exceptfds, &timeout);
  62.666 +    dump_set(nfds, &sock_readfds, &sock_writefds, &sock_exceptfds, &timeout);
  62.667 +    DEBUG("\n");
  62.668 +
  62.669 +    /* Then see others as well. */
  62.670 +    for (i = 0; i < nfds; i++) {
  62.671 +	switch(files[i].type) {
  62.672 +	case FTYPE_NONE:
  62.673 +	    if (FD_ISSET(i, readfds) || FD_ISSET(i, writefds) || FD_ISSET(i, exceptfds))
  62.674 +		printk("bogus fd %d in select\n", i);
  62.675 +	    /* Fallthrough.  */
  62.676 +	case FTYPE_FILE:
  62.677 +	    FD_CLR(i, readfds);
  62.678 +	    FD_CLR(i, writefds);
  62.679 +	    FD_CLR(i, exceptfds);
  62.680 +	    break;
  62.681 +	case FTYPE_CONSOLE:
  62.682 +	    FD_CLR(i, readfds);
  62.683 +	    if (FD_ISSET(i, writefds))
  62.684 +                n++;
  62.685 +	    FD_CLR(i, exceptfds);
  62.686 +	    break;
  62.687 +	case FTYPE_XENBUS:
  62.688 +	    if (FD_ISSET(i, readfds)) {
  62.689 +                if (files[i].xenbus.events)
  62.690 +		    n++;
  62.691 +		else
  62.692 +		    FD_CLR(i, readfds);
  62.693 +	    }
  62.694 +	    FD_CLR(i, writefds);
  62.695 +	    FD_CLR(i, exceptfds);
  62.696 +	    break;
  62.697 +	case FTYPE_EVTCHN:
  62.698 +	case FTYPE_TAP:
  62.699 +	case FTYPE_BLK:
  62.700 +	    if (FD_ISSET(i, readfds)) {
  62.701 +		if (files[i].read)
  62.702 +		    n++;
  62.703 +		else
  62.704 +		    FD_CLR(i, readfds);
  62.705 +	    }
  62.706 +	    FD_CLR(i, writefds);
  62.707 +	    FD_CLR(i, exceptfds);
  62.708 +	    break;
  62.709 +	case FTYPE_SOCKET:
  62.710 +	    if (FD_ISSET(i, readfds)) {
  62.711 +	        /* Optimize no-network-packet case.  */
  62.712 +		if (sock_n && FD_ISSET(files[i].socket.fd, &sock_readfds))
  62.713 +		    n++;
  62.714 +		else
  62.715 +		    FD_CLR(i, readfds);
  62.716 +	    }
  62.717 +            if (FD_ISSET(i, writefds)) {
  62.718 +		if (sock_n && FD_ISSET(files[i].socket.fd, &sock_writefds))
  62.719 +		    n++;
  62.720 +		else
  62.721 +		    FD_CLR(i, writefds);
  62.722 +            }
  62.723 +            if (FD_ISSET(i, exceptfds)) {
  62.724 +		if (sock_n && FD_ISSET(files[i].socket.fd, &sock_exceptfds))
  62.725 +		    n++;
  62.726 +		else
  62.727 +		    FD_CLR(i, exceptfds);
  62.728 +            }
  62.729 +	    break;
  62.730 +	}
  62.731 +#ifdef LIBC_VERBOSE
  62.732 +	if (FD_ISSET(i, readfds))
  62.733 +	    nbread[i]++;
  62.734 +	if (FD_ISSET(i, writefds))
  62.735 +	    nbwrite[i]++;
  62.736 +	if (FD_ISSET(i, exceptfds))
  62.737 +	    nbexcept[i]++;
  62.738 +#endif
  62.739 +    }
  62.740 +#ifdef LIBC_VERBOSE
  62.741 +    if (NOW() > lastshown + 1000000000ull) {
  62.742 +	lastshown = NOW();
  62.743 +	printk("%lu MB free, ", num_free_pages() / ((1 << 20) / PAGE_SIZE));
  62.744 +	printk("%d(%d): ", nb, sock_n);
  62.745 +	for (i = 0; i < nfds; i++) {
  62.746 +	    if (nbread[i] || nbwrite[i] || nbexcept[i])
  62.747 +		printk(" %d(%c):", i, file_types[files[i].type]);
  62.748 +	    if (nbread[i])
  62.749 +	    	printk(" %dR", nbread[i]);
  62.750 +	    if (nbwrite[i])
  62.751 +		printk(" %dW", nbwrite[i]);
  62.752 +	    if (nbexcept[i])
  62.753 +		printk(" %dE", nbexcept[i]);
  62.754 +	}
  62.755 +	printk("\n");
  62.756 +	memset(nbread, 0, sizeof(nbread));
  62.757 +	memset(nbwrite, 0, sizeof(nbwrite));
  62.758 +	memset(nbexcept, 0, sizeof(nbexcept));
  62.759 +	nb = 0;
  62.760 +    }
  62.761 +#endif
  62.762 +    return n;
  62.763 +}
  62.764 +
  62.765 +/* The strategy is to
  62.766 + * - announce that we will maybe sleep
  62.767 + * - poll a bit ; if successful, return
  62.768 + * - if timeout, return
  62.769 + * - really sleep (except if somebody woke us in the meanwhile) */
  62.770 +int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
  62.771 +	struct timeval *timeout)
  62.772 +{
  62.773 +    int n, ret;
  62.774 +    fd_set myread, mywrite, myexcept;
  62.775 +    struct thread *thread = get_current();
  62.776 +    s_time_t start = NOW(), stop;
  62.777 +    DEFINE_WAIT(w1);
  62.778 +    DEFINE_WAIT(w2);
  62.779 +    DEFINE_WAIT(w3);
  62.780 +    DEFINE_WAIT(w4);
  62.781 +
  62.782 +    assert(thread == main_thread);
  62.783 +
  62.784 +    DEBUG("select(%d, ", nfds);
  62.785 +    dump_set(nfds, readfds, writefds, exceptfds, timeout);
  62.786 +    DEBUG(");\n");
  62.787 +
  62.788 +    if (timeout)
  62.789 +	stop = start + SECONDS(timeout->tv_sec) + timeout->tv_usec * 1000;
  62.790 +    else
  62.791 +	/* just make gcc happy */
  62.792 +	stop = start;
  62.793 +
  62.794 +    /* Tell people we're going to sleep before looking at what they are
  62.795 +     * saying, hence letting them wake us if events happen between here and
  62.796 +     * schedule() */
  62.797 +    add_waiter(w1, netfront_queue);
  62.798 +    add_waiter(w2, event_queue);
  62.799 +    add_waiter(w3, blkfront_queue);
  62.800 +    add_waiter(w4, xenbus_watch_queue);
  62.801 +
  62.802 +    myread = *readfds;
  62.803 +    mywrite = *writefds;
  62.804 +    myexcept = *exceptfds;
  62.805 +    DEBUG("polling ");
  62.806 +    dump_set(nfds, &myread, &mywrite, &myexcept, timeout);
  62.807 +    DEBUG("\n");
  62.808 +    n = select_poll(nfds, &myread, &mywrite, &myexcept);
  62.809 +
  62.810 +    if (n) {
  62.811 +	dump_set(nfds, readfds, writefds, exceptfds, timeout);
  62.812 +	if (readfds)
  62.813 +	    *readfds = myread;
  62.814 +	if (writefds)
  62.815 +	    *writefds = mywrite;
  62.816 +	if (exceptfds)
  62.817 +	    *exceptfds = myexcept;
  62.818 +	DEBUG(" -> ");
  62.819 +	dump_set(nfds, readfds, writefds, exceptfds, timeout);
  62.820 +	DEBUG("\n");
  62.821 +	wake(thread);
  62.822 +	ret = n;
  62.823 +	goto out;
  62.824 +    }
  62.825 +    if (timeout && NOW() >= stop) {
  62.826 +	if (readfds)
  62.827 +	    FD_ZERO(readfds);
  62.828 +	if (writefds)
  62.829 +	    FD_ZERO(writefds);
  62.830 +	if (exceptfds)
  62.831 +	    FD_ZERO(exceptfds);
  62.832 +	timeout->tv_sec = 0;
  62.833 +	timeout->tv_usec = 0;
  62.834 +	wake(thread);
  62.835 +	ret = 0;
  62.836 +	goto out;
  62.837 +    }
  62.838 +
  62.839 +    if (timeout)
  62.840 +	thread->wakeup_time = stop;
  62.841 +    schedule();
  62.842 +
  62.843 +    myread = *readfds;
  62.844 +    mywrite = *writefds;
  62.845 +    myexcept = *exceptfds;
  62.846 +    n = select_poll(nfds, &myread, &mywrite, &myexcept);
  62.847 +
  62.848 +    if (n) {
  62.849 +	if (readfds)
  62.850 +	    *readfds = myread;
  62.851 +	if (writefds)
  62.852 +	    *writefds = mywrite;
  62.853 +	if (exceptfds)
  62.854 +	    *exceptfds = myexcept;
  62.855 +	ret = n;
  62.856 +	goto out;
  62.857 +    }
  62.858 +    errno = EINTR;
  62.859 +    ret = -1;
  62.860 +
  62.861 +out:
  62.862 +    remove_waiter(w1);
  62.863 +    remove_waiter(w2);
  62.864 +    remove_waiter(w3);
  62.865 +    remove_waiter(w4);
  62.866 +    return ret;
  62.867 +}
  62.868 +
  62.869 +int socket(int domain, int type, int protocol)
  62.870 +{
  62.871 +    int fd, res;
  62.872 +    fd = lwip_socket(domain, type, protocol);
  62.873 +    if (fd < 0)
  62.874 +	return -1;
  62.875 +    res = alloc_fd(FTYPE_SOCKET);
  62.876 +    printk("socket -> %d\n", res);
  62.877 +    files[res].socket.fd = fd;
  62.878 +    return res;
  62.879 +}
  62.880 +
  62.881 +int accept(int s, struct sockaddr *addr, socklen_t *addrlen)
  62.882 +{
  62.883 +    int fd, res;
  62.884 +    if (files[s].type != FTYPE_SOCKET) {
  62.885 +	printk("accept(%d): Bad descriptor\n", s);
  62.886 +	errno = EBADF;
  62.887 +	return -1;
  62.888 +    }
  62.889 +    fd = lwip_accept(files[s].socket.fd, addr, addrlen);
  62.890 +    if (fd < 0)
  62.891 +	return -1;
  62.892 +    res = alloc_fd(FTYPE_SOCKET);
  62.893 +    files[res].socket.fd = fd;
  62.894 +    printk("accepted on %d -> %d\n", s, res);
  62.895 +    return res;
  62.896 +}
  62.897 +
  62.898 +#define LWIP_STUB(ret, name, proto, args) \
  62.899 +ret name proto \
  62.900 +{ \
  62.901 +    if (files[s].type != FTYPE_SOCKET) { \
  62.902 +	printk(#name "(%d): Bad descriptor\n", s); \
  62.903 +	errno = EBADF; \
  62.904 +	return -1; \
  62.905 +    } \
  62.906 +    s = files[s].socket.fd; \
  62.907 +    return lwip_##name args; \
  62.908 +}
  62.909 +
  62.910 +LWIP_STUB(int, bind, (int s, struct sockaddr *my_addr, socklen_t addrlen), (s, my_addr, addrlen))
  62.911 +LWIP_STUB(int, getsockopt, (int s, int level, int optname, void *optval, socklen_t *optlen), (s, level, optname, optval, optlen))
  62.912 +LWIP_STUB(int, setsockopt, (int s, int level, int optname, void *optval, socklen_t optlen), (s, level, optname, optval, optlen))
  62.913 +LWIP_STUB(int, connect, (int s, struct sockaddr *serv_addr, socklen_t addrlen), (s, serv_addr, addrlen))
  62.914 +LWIP_STUB(int, listen, (int s, int backlog), (s, backlog));
  62.915 +LWIP_STUB(ssize_t, recv, (int s, void *buf, size_t len, int flags), (s, buf, len, flags))
  62.916 +LWIP_STUB(ssize_t, recvfrom, (int s, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen), (s, buf, len, flags, from, fromlen))
  62.917 +LWIP_STUB(ssize_t, send, (int s, void *buf, size_t len, int flags), (s, buf, len, flags))
  62.918 +LWIP_STUB(ssize_t, sendto, (int s, void *buf, size_t len, int flags, struct sockaddr *to, socklen_t tolen), (s, buf, len, flags, to, tolen))
  62.919 +LWIP_STUB(int, getsockname, (int s, struct sockaddr *name, socklen_t *namelen), (s, name, namelen))
  62.920 +
  62.921 +int nanosleep(const struct timespec *req, struct timespec *rem)
  62.922 +{
  62.923 +    s_time_t start = NOW();
  62.924 +    s_time_t stop = start + SECONDS(req->tv_sec) + req->tv_nsec;
  62.925 +    s_time_t stopped;
  62.926 +    struct thread *thread = get_current();
  62.927 +
  62.928 +    thread->wakeup_time = stop;
  62.929 +    clear_runnable(thread);
  62.930 +    schedule();
  62.931 +    stopped = NOW();
  62.932 +
  62.933 +    if (rem)
  62.934 +    {
  62.935 +	s_time_t remaining = stop - stopped;
  62.936 +	if (remaining > 0)
  62.937 +	{
  62.938 +	    rem->tv_nsec = remaining % 1000000000ULL;
  62.939 +	    rem->tv_sec  = remaining / 1000000000ULL;
  62.940 +	} else memset(rem, 0, sizeof(*rem));
  62.941 +    }
  62.942 +
  62.943 +    return 0;
  62.944 +}
  62.945 +
  62.946 +int usleep(useconds_t usec)
  62.947 +{
  62.948 +    /* "usec shall be less than one million."  */
  62.949 +    struct timespec req;
  62.950 +    req.tv_nsec = usec * 1000;
  62.951 +    req.tv_sec = 0;
  62.952 +
  62.953 +    if (nanosleep(&req, NULL))
  62.954 +	return -1;
  62.955 +
  62.956 +    return 0;
  62.957 +}
  62.958 +
  62.959 +unsigned int sleep(unsigned int seconds)
  62.960 +{
  62.961 +    struct timespec req, rem;
  62.962 +    req.tv_sec = seconds;
  62.963 +    req.tv_nsec = 0;
  62.964 +
  62.965 +    if (nanosleep(&req, &rem))
  62.966 +	return -1;
  62.967 +
  62.968 +    if (rem.tv_nsec > 0)
  62.969 +	rem.tv_sec++;
  62.970 +
  62.971 +    return rem.tv_sec;
  62.972 +}
  62.973 +
  62.974 +int clock_gettime(clockid_t clk_id, struct timespec *tp)
  62.975 +{
  62.976 +    switch (clk_id) {
  62.977 +	case CLOCK_MONOTONIC:
  62.978 +	{
  62.979 +	    struct timeval tv;
  62.980 +
  62.981 +	    gettimeofday(&tv, NULL);
  62.982 +
  62.983 +	    tp->tv_sec = tv.tv_sec;
  62.984 +	    tp->tv_nsec = tv.tv_usec * 1000;
  62.985 +
  62.986 +	    break;
  62.987 +	}
  62.988 +	case CLOCK_REALTIME:
  62.989 +	{
  62.990 +	    u64 nsec = monotonic_clock();
  62.991 +
  62.992 +	    tp->tv_sec = nsec / 1000000000ULL;
  62.993 +	    tp->tv_nsec = nsec % 1000000000ULL;
  62.994 +
  62.995 +	    break;
  62.996 +	}
  62.997 +	default:
  62.998 +	    print_unsupported("clock_gettime(%d)", clk_id);
  62.999 +	    errno = EINVAL;
 62.1000 +	    return -1;
 62.1001 +    }
 62.1002 +
 62.1003 +    return 0;
 62.1004 +}
 62.1005 +
 62.1006 +void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset)
 62.1007 +{
 62.1008 +    ASSERT(!start);
 62.1009 +    length = (length + PAGE_SIZE - 1) & PAGE_MASK;
 62.1010 +    ASSERT(prot == (PROT_READ|PROT_WRITE));
 62.1011 +    ASSERT(flags == (MAP_SHARED|MAP_ANON) || flags == (MAP_PRIVATE|MAP_ANON));
 62.1012 +    ASSERT(fd == -1);
 62.1013 +    ASSERT(offset == 0);
 62.1014 +
 62.1015 +    return map_zero(length / PAGE_SIZE, 1);
 62.1016 +}
 62.1017 +#if defined(__x86_64__) || defined(__ia64__)
 62.1018 +__typeof__(mmap) mmap64 __attribute__((__alias__("mmap")));
 62.1019 +#endif
 62.1020 +
 62.1021 +int munmap(void *start, size_t length)
 62.1022 +{
 62.1023 +    int i, n = length / PAGE_SIZE;
 62.1024 +    multicall_entry_t call[n];
 62.1025 +    unsigned char (*data)[PAGE_SIZE] = start;
 62.1026 +    int ret;
 62.1027 +    ASSERT(!((unsigned long)start & ~PAGE_MASK));
 62.1028 +    ASSERT(!(length & ~PAGE_MASK));
 62.1029 +
 62.1030 +    for (i = 0; i < n; i++) {
 62.1031 +	call[i].op = __HYPERVISOR_update_va_mapping;
 62.1032 +	call[i].args[0] = (unsigned long) &data[i];
 62.1033 +	call[i].args[1] = 0;
 62.1034 +	call[i].args[2] = 0;
 62.1035 +	call[i].args[3] = UVMF_INVLPG | UVMF_ALL;
 62.1036 +    }
 62.1037 +
 62.1038 +    ret = HYPERVISOR_multicall(call, n);
 62.1039 +    if (ret) {
 62.1040 +	errno = -ret;
 62.1041 +	return -1;
 62.1042 +    }
 62.1043 +
 62.1044 +    for (i = 0; i < n; i++) {
 62.1045 +	if (call[i].result) {
 62.1046 +	    errno = call[i].result;
 62.1047 +	    return -1;
 62.1048 +	}
 62.1049 +    }
 62.1050 +    return 0;
 62.1051 +}
 62.1052 +
 62.1053 +/* Not supported by FS yet.  */
 62.1054 +unsupported_function_crash(link);
 62.1055 +unsupported_function(int, readlink, -1);
 62.1056 +
 62.1057 +/* We could support that.  */
 62.1058 +unsupported_function_log(int, chdir, -1);
 62.1059 +
 62.1060 +/* No dynamic library support.  */ 
 62.1061 +unsupported_function_log(void *, dlopen, NULL);
 62.1062 +unsupported_function_log(void *, dlsym, NULL);
 62.1063 +unsupported_function_log(char *, dlerror, NULL);
 62.1064 +unsupported_function_log(int, dlclose, -1);
 62.1065 +
 62.1066 +/* We don't raise signals anyway.  */
 62.1067 +unsupported_function(int, sigemptyset, -1);
 62.1068 +unsupported_function(int, sigfillset, -1);
 62.1069 +unsupported_function(int, sigaddset, -1);
 62.1070 +unsupported_function(int, sigdelset, -1);
 62.1071 +unsupported_function(int, sigismember, -1);
 62.1072 +unsupported_function(int, sigprocmask, -1);
 62.1073 +unsupported_function(int, sigaction, -1);
 62.1074 +unsupported_function(int, __sigsetjmp, 0);
 62.1075 +unsupported_function(int, sigaltstack, -1);
 62.1076 +unsupported_function_crash(kill);
 62.1077 +
 62.1078 +/* Linuxish abi for the Caml runtime, don't support */
 62.1079 +unsupported_function_log(struct dirent *, readdir64, NULL);
 62.1080 +unsupported_function_log(int, getrusage, -1);
 62.1081 +unsupported_function_log(int, getrlimit, -1);
 62.1082 +unsupported_function_log(int, getrlimit64, -1);
 62.1083 +unsupported_function_log(int, __xstat64, -1);
 62.1084 +unsupported_function_log(long, __strtol_internal, LONG_MIN);
 62.1085 +unsupported_function_log(double, __strtod_internal, HUGE_VAL);
 62.1086 +#endif
    63.1 --- a/extras/mini-os/lib/xmalloc.c	Wed Feb 13 10:37:18 2008 -0700
    63.2 +++ b/extras/mini-os/lib/xmalloc.c	Thu Feb 14 09:34:27 2008 -0700
    63.3 @@ -62,10 +62,19 @@ struct xmalloc_pad
    63.4      size_t hdr_size;
    63.5  };
    63.6  
    63.7 +/* Return size, increased to alignment with align. */
    63.8 +static inline size_t align_up(size_t size, size_t align)
    63.9 +{
   63.10 +    return (size + align - 1) & ~(align - 1);
   63.11 +}
   63.12 +
   63.13  static void maybe_split(struct xmalloc_hdr *hdr, size_t size, size_t block)
   63.14  {
   63.15      struct xmalloc_hdr *extra;
   63.16 -    size_t leftover = block - size;
   63.17 +    size_t leftover;
   63.18 +    size = align_up(size, __alignof__(struct xmalloc_hdr));
   63.19 +    size = align_up(size, __alignof__(struct xmalloc_pad));
   63.20 +    leftover = block - size;
   63.21  
   63.22      /* If enough is left to make a block, put it on free list. */
   63.23      if ( leftover >= (2 * (sizeof(struct xmalloc_hdr) + sizeof(struct xmalloc_pad))) )
   63.24 @@ -100,12 +109,6 @@ static struct xmalloc_hdr *xmalloc_new_p
   63.25      return hdr;
   63.26  }
   63.27  
   63.28 -/* Return size, increased to alignment with align. */
   63.29 -static inline size_t align_up(size_t size, size_t align)
   63.30 -{
   63.31 -    return (size + align - 1) & ~(align - 1);
   63.32 -}
   63.33 -
   63.34  /* Big object?  Just use the page allocator. */
   63.35  static void *xmalloc_whole_pages(size_t size, size_t align)
   63.36  {
    64.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    64.2 +++ b/extras/mini-os/lib/xs.c	Thu Feb 14 09:34:27 2008 -0700
    64.3 @@ -0,0 +1,187 @@
    64.4 +/*
    64.5 + * libxs-compatible layer
    64.6 + *
    64.7 + * Samuel Thibault <Samuel.Thibault@eu.citrix.net>, 2007-2008
    64.8 + *
    64.9 + * Mere wrapper around xenbus_*
   64.10 + */
   64.11 +
   64.12 +#ifdef HAVE_LIBC
   64.13 +#include <os.h>
   64.14 +#include <lib.h>
   64.15 +#include <xs.h>
   64.16 +#include <xenbus.h>
   64.17 +#include <stdlib.h>
   64.18 +#include <unistd.h>
   64.19 +
   64.20 +static inline int _xs_fileno(struct xs_handle *h) {
   64.21 +    return (intptr_t) h;
   64.22 +}
   64.23 +
   64.24 +struct xs_handle *xs_daemon_open()
   64.25 +{
   64.26 +    int fd = alloc_fd(FTYPE_XENBUS);
   64.27 +    files[fd].xenbus.events = NULL;
   64.28 +    printk("xs_daemon_open -> %d, %p\n", fd, &files[fd].xenbus.events);
   64.29 +    return (void*)(intptr_t) fd;
   64.30 +}
   64.31 +
   64.32 +void xs_daemon_close(struct xs_handle *h)
   64.33 +{
   64.34 +    int fd = _xs_fileno(h);
   64.35 +    struct xenbus_event *event;
   64.36 +    for (event = files[fd].xenbus.events; event; event = event->next)
   64.37 +        free(event);
   64.38 +    files[fd].type = FTYPE_NONE;
   64.39 +}
   64.40 +
   64.41 +int xs_fileno(struct xs_handle *h)
   64.42 +{
   64.43 +    return _xs_fileno(h);
   64.44 +}
   64.45 +
   64.46 +void *xs_read(struct xs_handle *h, xs_transaction_t t,
   64.47 +	     const char *path, unsigned int *len)
   64.48 +{
   64.49 +    char *value;
   64.50 +    char *msg;
   64.51 +
   64.52 +    msg = xenbus_read(t, path, &value);
   64.53 +    if (msg) {
   64.54 +	printk("xs_read(%s): %s\n", path, msg);
   64.55 +	return NULL;
   64.56 +    }
   64.57 +
   64.58 +    if (len)
   64.59 +	*len = strlen(value);
   64.60 +    return value;
   64.61 +}
   64.62 +
   64.63 +bool xs_write(struct xs_handle *h, xs_transaction_t t,
   64.64 +	      const char *path, const void *data, unsigned int len)
   64.65 +{
   64.66 +    char value[len + 1];
   64.67 +    char *msg;
   64.68 +
   64.69 +    memcpy(value, data, len);
   64.70 +    value[len] = 0;
   64.71 +
   64.72 +    msg = xenbus_write(t, path, value);
   64.73 +    if (msg) {
   64.74 +	printk("xs_write(%s): %s\n", path, msg);
   64.75 +	return false;
   64.76 +    }
   64.77 +    return true;
   64.78 +}
   64.79 +
   64.80 +static bool xs_bool(char *reply)
   64.81 +{
   64.82 +    if (!reply)
   64.83 +	return true;
   64.84 +    free(reply);
   64.85 +    return false;
   64.86 +}
   64.87 +
   64.88 +bool xs_rm(struct xs_handle *h, xs_transaction_t t, const char *path)
   64.89 +{
   64.90 +    return xs_bool(xenbus_rm(t, path));
   64.91 +}
   64.92 +
   64.93 +static void *xs_talkv(struct xs_handle *h, xs_transaction_t t,
   64.94 +		enum xsd_sockmsg_type type,
   64.95 +		struct write_req *iovec,
   64.96 +		unsigned int num_vecs,
   64.97 +		unsigned int *len)
   64.98 +{
   64.99 +    struct xsd_sockmsg *msg;
  64.100 +    void *ret;
  64.101 +
  64.102 +    msg = xenbus_msg_reply(type, t, iovec, num_vecs);
  64.103 +    ret = malloc(msg->len);
  64.104 +    memcpy(ret, (char*) msg + sizeof(*msg), msg->len);
  64.105 +    if (len)
  64.106 +	*len = msg->len - 1;
  64.107 +    free(msg);
  64.108 +    return ret;
  64.109 +}
  64.110 +
  64.111 +static void *xs_single(struct xs_handle *h, xs_transaction_t t,
  64.112 +		enum xsd_sockmsg_type type,
  64.113 +		const char *string,
  64.114 +		unsigned int *len)
  64.115 +{
  64.116 +    struct write_req iovec;
  64.117 +
  64.118 +    iovec.data = (void *)string;
  64.119 +    iovec.len = strlen(string) + 1;
  64.120 +
  64.121 +    return xs_talkv(h, t, type, &iovec, 1, len);
  64.122 +}
  64.123 +
  64.124 +char *xs_get_domain_path(struct xs_handle *h, unsigned int domid)
  64.125 +{
  64.126 +    char domid_str[MAX_STRLEN(domid)];
  64.127 +
  64.128 +    sprintf(domid_str, "%u", domid);
  64.129 +
  64.130 +    return xs_single(h, XBT_NULL, XS_GET_DOMAIN_PATH, domid_str, NULL);
  64.131 +}
  64.132 +
  64.133 +char **xs_directory(struct xs_handle *h, xs_transaction_t t,
  64.134 +		    const char *path, unsigned int *num)
  64.135 +{
  64.136 +    char *msg;
  64.137 +    char **entries, **res;
  64.138 +    char *entry;
  64.139 +    int i, n;
  64.140 +    int size;
  64.141 +
  64.142 +    msg = xenbus_ls(t, path, &res);
  64.143 +    if (msg) {
  64.144 +	printk("xs_directory(%s): %s\n", path, msg);
  64.145 +	return NULL;
  64.146 +    }
  64.147 +
  64.148 +    size = 0;
  64.149 +    for (n = 0; res[n]; n++)
  64.150 +	size += strlen(res[n]) + 1;
  64.151 +
  64.152 +    entries = malloc(n * sizeof(char *) + size);
  64.153 +    entry = (char *) (&entries[n]);
  64.154 +
  64.155 +    for (i = 0; i < n; i++) {
  64.156 +	int l = strlen(res[i]) + 1;
  64.157 +	memcpy(entry, res[i], l);
  64.158 +	free(res[i]);
  64.159 +	entries[i] = entry;
  64.160 +	entry += l;
  64.161 +    }
  64.162 +
  64.163 +    *num = n;
  64.164 +    return entries;
  64.165 +}
  64.166 +
  64.167 +bool xs_watch(struct xs_handle *h, const char *path, const char *token)
  64.168 +{
  64.169 +    int fd = _xs_fileno(h);
  64.170 +    printk("xs_watch(%s, %s)\n", path, token);
  64.171 +    return xs_bool(xenbus_watch_path_token(XBT_NULL, path, token, &files[fd].xenbus.events));
  64.172 +}
  64.173 +
  64.174 +char **xs_read_watch(struct xs_handle *h, unsigned int *num)
  64.175 +{
  64.176 +    int fd = _xs_fileno(h);
  64.177 +    struct xenbus_event *event;
  64.178 +    event = files[fd].xenbus.events;
  64.179 +    files[fd].xenbus.events = event->next;
  64.180 +    printk("xs_read_watch() -> %s %s\n", event->path, event->token);
  64.181 +    *num = 2;
  64.182 +    return (char **) &event->path;
  64.183 +}
  64.184 +
  64.185 +bool xs_unwatch(struct xs_handle *h, const char *path, const char *token)
  64.186 +{
  64.187 +    printk("xs_unwatch(%s, %s)\n", path, token);
  64.188 +    return xs_bool(xenbus_unwatch_path_token(XBT_NULL, path, token));
  64.189 +}
  64.190 +#endif
    65.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    65.2 +++ b/extras/mini-os/main-caml.c	Thu Feb 14 09:34:27 2008 -0700
    65.3 @@ -0,0 +1,42 @@
    65.4 +/*
    65.5 + * Caml bootstrap
    65.6 + *
    65.7 + * Samuel Thibault <Samuel.Thibault@eu.citrix.net>, January 2008
    65.8 + */
    65.9 +
   65.10 +#include <stdio.h>
   65.11 +#include <errno.h>
   65.12 +
   65.13 +#include <caml/mlvalues.h>
   65.14 +#include <caml/callback.h>
   65.15 +#include <unistd.h>
   65.16 +
   65.17 +/* Ugly binary compatibility with Linux */
   65.18 +FILE *_stderr asm("stderr");
   65.19 +int *__errno_location;
   65.20 +/* Will probably break everything, probably need to fetch from glibc */
   65.21 +void *__ctype_b_loc;
   65.22 +
   65.23 +int main(int argc, char *argv[], char *envp[])
   65.24 +{
   65.25 +    value *val;
   65.26 +
   65.27 +    /* Get current thread's value */
   65.28 +    _stderr = stderr;
   65.29 +    __errno_location = &errno;
   65.30 +
   65.31 +    printf("starting caml\n");
   65.32 +
   65.33 +    /* Wait before things might hang up */
   65.34 +    sleep(1);
   65.35 +
   65.36 +    caml_startup(argv);
   65.37 +    val = caml_named_value("main");
   65.38 +    if (!val) {
   65.39 +        printf("Couldn't find Caml main");
   65.40 +        return 1;
   65.41 +    }
   65.42 +    caml_callback(*val, Val_int(0));
   65.43 +    printf("callback returned\n");
   65.44 +    return 0;
   65.45 +}
    66.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    66.2 +++ b/extras/mini-os/main.c	Thu Feb 14 09:34:27 2008 -0700
    66.3 @@ -0,0 +1,167 @@
    66.4 +/*
    66.5 + * POSIX-compatible main layer
    66.6 + *
    66.7 + * Samuel Thibault <Samuel.Thibault@eu.citrix.net>, October 2007
    66.8 + */
    66.9 +
   66.10 +#ifdef HAVE_LIBC
   66.11 +#include <os.h>
   66.12 +#include <sched.h>
   66.13 +#include <console.h>
   66.14 +#include <netfront.h>
   66.15 +#include <time.h>
   66.16 +#include <stdlib.h>
   66.17 +#include <unistd.h>
   66.18 +#include <fs.h>
   66.19 +#include <xenbus.h>
   66.20 +#include <events.h>
   66.21 +
   66.22 +extern int main(int argc, char *argv[], char *envp[]);
   66.23 +extern void __libc_init_array(void);
   66.24 +extern void __libc_fini_array(void);
   66.25 +
   66.26 +struct thread *main_thread;
   66.27 +
   66.28 +#if 0
   66.29 +#include <stdio.h>
   66.30 +int main(int argc, char *argv[], char *envp[])
   66.31 +{
   66.32 +    printf("Hello, World!\n");
   66.33 +    return 1;
   66.34 +}
   66.35 +#endif
   66.36 +
   66.37 +void _init(void)
   66.38 +{
   66.39 +}
   66.40 +
   66.41 +void _fini(void)
   66.42 +{
   66.43 +}
   66.44 +
   66.45 +static void call_main(void *p)
   66.46 +{
   66.47 +    char *args, /**path,*/ *msg, *c;
   66.48 +    int argc;
   66.49 +    char **argv;
   66.50 +    char *envp[] = { NULL };
   66.51 +    char *vm;
   66.52 +    int i;
   66.53 +    char path[128];
   66.54 +
   66.55 +    /* Let other parts initialize (including console output) before maybe
   66.56 +     * crashing. */
   66.57 +    //sleep(1);
   66.58 +
   66.59 +    start_networking();
   66.60 +    init_fs_frontend();
   66.61 +
   66.62 +#ifdef CONFIG_QEMU
   66.63 +    if (!fs_import) {
   66.64 +        printk("No FS backend found, is it running?\n");
   66.65 +        do_exit();
   66.66 +    }
   66.67 +
   66.68 +    /* Fetch argc, argv from XenStore */
   66.69 +    char domid_s[10];
   66.70 +    int domid;
   66.71 +    domid = xenbus_read_integer("target");
   66.72 +    if (domid == -1) {
   66.73 +        printk("Couldn't read target\n");
   66.74 +        do_exit();
   66.75 +    }
   66.76 +    snprintf(domid_s, sizeof(domid_s), "%d", domid);
   66.77 +
   66.78 +    snprintf(path, sizeof(path), "/local/domain/%d/vm", domid);
   66.79 +    msg = xenbus_read(XBT_NIL, path, &vm);
   66.80 +    if (msg) {
   66.81 +        printk("Couldn't read vm path\n");
   66.82 +        do_exit();
   66.83 +    }
   66.84 +    printk("vm is at %s\n", vm);
   66.85 +#else
   66.86 +    msg = xenbus_read(XBT_NIL, "vm", &vm);
   66.87 +    if (msg) {
   66.88 +        printk("Couldn't read vm path\n");
   66.89 +        do_exit();
   66.90 +    }
   66.91 +#endif
   66.92 +
   66.93 +    snprintf(path, sizeof(path), "%s/image/dmargs", vm);
   66.94 +    free(vm);
   66.95 +    msg = xenbus_read(XBT_NIL, path, &args);
   66.96 +
   66.97 +    if (msg) {
   66.98 +        printk("Couldn't get stubdom args: %s\n", msg);
   66.99 +        args = strdup("");
  66.100 +    }
  66.101 +
  66.102 +    argc = 1;
  66.103 +#ifdef CONFIG_QEMU
  66.104 +    argc += 2;
  66.105 +#endif
  66.106 +    c = args;
  66.107 +    while (*c) {
  66.108 +	if (*c != ' ') {
  66.109 +	    argc++;
  66.110 +	    while (*c && *c != ' ')
  66.111 +		c++;
  66.112 +	} else {
  66.113 +	    while (*c == ' ')
  66.114 +		c++;
  66.115 +	}
  66.116 +    }
  66.117 +    argv = alloca((argc + 1) * sizeof(char *));
  66.118 +    argv[0] = "main";
  66.119 +    argc = 1;
  66.120 +#ifdef CONFIG_QEMU
  66.121 +    argv[1] = "-d";
  66.122 +    argv[2] = domid_s;
  66.123 +    argc += 2;
  66.124 +#endif
  66.125 +    c = args;
  66.126 +    while (*c) {
  66.127 +	if (*c != ' ') {
  66.128 +	    argv[argc++] = c;
  66.129 +	    while (*c && *c != ' ')
  66.130 +		c++;
  66.131 +	} else {
  66.132 +	    *c++ = 0;
  66.133 +	    while (*c == ' ')
  66.134 +		c++;
  66.135 +	}
  66.136 +    }
  66.137 +    argv[argc] = NULL;
  66.138 +
  66.139 +    for (i = 0; i < argc; i++)
  66.140 +	printf("\"%s\" ", argv[i]);
  66.141 +    printf("\n");
  66.142 +
  66.143 +    __libc_init_array();
  66.144 +    environ = envp;
  66.145 +    tzset();
  66.146 +
  66.147 +    exit(main(argc, argv, envp));
  66.148 +}
  66.149 +
  66.150 +void _exit(int ret)
  66.151 +{
  66.152 +    close_all_files();
  66.153 +    __libc_fini_array();
  66.154 +    printk("main returned %d\n", ret);
  66.155 +    unbind_all_ports();
  66.156 +    if (!ret) {
  66.157 +	/* No problem, just shutdown.  */
  66.158 +        struct sched_shutdown sched_shutdown = { .reason = SHUTDOWN_poweroff };
  66.159 +        HYPERVISOR_sched_op(SCHEDOP_shutdown, &sched_shutdown);
  66.160 +    }
  66.161 +    do_exit();
  66.162 +}
  66.163 +
  66.164 +int app_main(start_info_t *si)
  66.165 +{
  66.166 +    printk("Dummy main: start_info=%p\n", si);
  66.167 +    main_thread = create_thread("main", call_main, si);
  66.168 +    return 0;
  66.169 +}
  66.170 +#endif
    67.1 --- a/extras/mini-os/minios.mk	Wed Feb 13 10:37:18 2008 -0700
    67.2 +++ b/extras/mini-os/minios.mk	Thu Feb 14 09:34:27 2008 -0700
    67.3 @@ -9,7 +9,7 @@ debug = y
    67.4  DEF_CFLAGS += -fno-builtin -Wall -Werror -Wredundant-decls -Wno-format
    67.5  DEF_CFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
    67.6  DEF_CFLAGS += -Wstrict-prototypes -Wnested-externs -Wpointer-arith -Winline
    67.7 -DEF_CFLAGS += -D__XEN_INTERFACE_VERSION__=$(XEN_INTERFACE_VERSION)
    67.8 +DEF_CPPFLAGS += -D__XEN_INTERFACE_VERSION__=$(XEN_INTERFACE_VERSION)
    67.9  
   67.10  DEF_ASFLAGS = -D__ASSEMBLY__
   67.11  DEF_LDFLAGS =
   67.12 @@ -24,12 +24,10 @@ endif
   67.13  # DEF_... flags are the common mini-os flags,
   67.14  # ARCH_... flags may be defined in arch/$(TARGET_ARCH_FAM/rules.mk
   67.15  CFLAGS := $(DEF_CFLAGS) $(ARCH_CFLAGS)
   67.16 +CPPFLAGS := $(DEF_CPPFLAGS) $(ARCH_CPPFLAGS)
   67.17  ASFLAGS := $(DEF_ASFLAGS) $(ARCH_ASFLAGS)
   67.18  LDFLAGS := $(DEF_LDFLAGS) $(ARCH_LDFLAGS)
   67.19  
   67.20 -# The path pointing to the architecture specific header files.
   67.21 -ARCH_INC := $(MINI-OS_ROOT)/include/$(TARGET_ARCH_FAM)
   67.22 -
   67.23  # Special build dependencies.
   67.24  # Rebuild all after touching this/these file(s)
   67.25  EXTRA_DEPS = $(MINI-OS_ROOT)/minios.mk \
   67.26 @@ -44,18 +42,17 @@ extra_heads := $(foreach dir,$(EXTRA_INC
   67.27  HDRS += $(extra_heads)
   67.28  
   67.29  # Add the special header directories to the include paths.
   67.30 -extra_incl := $(foreach dir,$(EXTRA_INC),-I$(MINI-OS_ROOT)/include/$(dir))
   67.31 -override CPPFLAGS := -I$(MINI-OS_ROOT)/include $(CPPFLAGS) -I$(ARCH_INC)	$(extra_incl)
   67.32 +override CPPFLAGS := $(CPPFLAGS) $(extra_incl)
   67.33  
   67.34  # The name of the architecture specific library.
   67.35  # This is on x86_32: libx86_32.a
   67.36  # $(ARCH_LIB) has to built in the architecture specific directory.
   67.37 -ARCH_LIB_NAME = $(TARGET_ARCH)
   67.38 +ARCH_LIB_NAME = $(XEN_TARGET_ARCH)
   67.39  ARCH_LIB := lib$(ARCH_LIB_NAME).a
   67.40  
   67.41  # This object contains the entrypoint for startup from Xen.
   67.42  # $(HEAD_ARCH_OBJ) has to be built in the architecture specific directory.
   67.43 -HEAD_ARCH_OBJ := $(TARGET_ARCH).o
   67.44 +HEAD_ARCH_OBJ := $(XEN_TARGET_ARCH).o
   67.45  HEAD_OBJ := $(TARGET_ARCH_DIR)/$(HEAD_ARCH_OBJ)
   67.46  
   67.47  
    68.1 --- a/extras/mini-os/mm.c	Wed Feb 13 10:37:18 2008 -0700
    68.2 +++ b/extras/mini-os/mm.c	Thu Feb 14 09:34:27 2008 -0700
    68.3 @@ -360,6 +360,29 @@ void free_pages(void *pointer, int order
    68.4     
    68.5  }
    68.6  
    68.7 +#ifdef HAVE_LIBC
    68.8 +void *sbrk(ptrdiff_t increment)
    68.9 +{
   68.10 +    unsigned long old_brk = brk;
   68.11 +    unsigned long new_brk = old_brk + increment;
   68.12 +
   68.13 +    if (new_brk > heap_end) {
   68.14 +	printk("Heap exhausted: %p + %lx = %p > %p\n", old_brk, increment, new_brk, heap_end);
   68.15 +	return NULL;
   68.16 +    }
   68.17 +    
   68.18 +    if (new_brk > heap_mapped) {
   68.19 +        unsigned long n = (new_brk - heap_mapped + PAGE_SIZE - 1) / PAGE_SIZE;
   68.20 +        do_map_zero(heap_mapped, n);
   68.21 +        heap_mapped += n * PAGE_SIZE;
   68.22 +    }
   68.23 +
   68.24 +    brk = new_brk;
   68.25 +
   68.26 +    return (void *) old_brk;
   68.27 +}
   68.28 +#endif
   68.29 +
   68.30  
   68.31  
   68.32  void init_mm(void)
    69.1 --- a/extras/mini-os/netfront.c	Wed Feb 13 10:37:18 2008 -0700
    69.2 +++ b/extras/mini-os/netfront.c	Thu Feb 14 09:34:27 2008 -0700
    69.3 @@ -19,7 +19,10 @@
    69.4  
    69.5  DECLARE_WAIT_QUEUE_HEAD(netfront_queue);
    69.6  
    69.7 +#ifdef HAVE_LIBC
    69.8  #define NETIF_SELECT_RX ((void*)-1)
    69.9 +#endif
   69.10 +
   69.11  
   69.12  
   69.13  #define NET_TX_RING_SIZE __RING_SIZE((struct netif_tx_sring *)0, PAGE_SIZE)
   69.14 @@ -50,6 +53,13 @@ struct netfront_dev {
   69.15      char *nodename;
   69.16      char *backend;
   69.17  
   69.18 +#ifdef HAVE_LIBC
   69.19 +    int fd;
   69.20 +    unsigned char *data;
   69.21 +    size_t len;
   69.22 +    size_t rlen;
   69.23 +#endif
   69.24 +
   69.25      void (*netif_rx)(unsigned char* data, int len);
   69.26  };
   69.27  
   69.28 @@ -92,7 +102,8 @@ moretodo:
   69.29      cons = dev->rx.rsp_cons;
   69.30  
   69.31      int nr_consumed=0;
   69.32 -    while ((cons != rp))
   69.33 +    int some = 0;
   69.34 +    while ((cons != rp) && !some)
   69.35      {
   69.36          struct net_buffer* buf;
   69.37          unsigned char* page;
   69.38 @@ -116,7 +127,18 @@ moretodo:
   69.39  
   69.40          if(rx->status>0)
   69.41          {
   69.42 -            dev->netif_rx(page+rx->offset,rx->status);
   69.43 +#ifdef HAVE_LIBC
   69.44 +	    if (dev->netif_rx == NETIF_SELECT_RX) {
   69.45 +		int len = rx->status;
   69.46 +		ASSERT(current == main_thread);
   69.47 +		if (len > dev->len)
   69.48 +		    len = dev->len;
   69.49 +		memcpy(dev->data, page+rx->offset, len);
   69.50 +		dev->rlen = len;
   69.51 +		some = 1;
   69.52 +	    } else
   69.53 +#endif
   69.54 +		dev->netif_rx(page+rx->offset,rx->status);
   69.55          }
   69.56  
   69.57          nr_consumed++;
   69.58 @@ -127,7 +149,7 @@ moretodo:
   69.59  
   69.60      int more;
   69.61      RING_FINAL_CHECK_FOR_RESPONSES(&dev->rx,more);
   69.62 -    if(more) goto moretodo;
   69.63 +    if(more && !some) goto moretodo;
   69.64  
   69.65      RING_IDX req_prod = dev->rx.req_prod_pvt;
   69.66  
   69.67 @@ -178,6 +200,9 @@ void network_tx_buf_gc(struct netfront_d
   69.68              if (txrsp->status == NETIF_RSP_NULL)
   69.69                  continue;
   69.70  
   69.71 +            if (txrsp->status == NETIF_RSP_ERROR)
   69.72 +                printk("packet error\n");
   69.73 +
   69.74              id  = txrsp->id;
   69.75              struct net_buffer* buf = &dev->tx_buffers[id];
   69.76              gnttab_end_access(buf->gref);
   69.77 @@ -218,6 +243,22 @@ void netfront_handler(evtchn_port_t port
   69.78      local_irq_restore(flags);
   69.79  }
   69.80  
   69.81 +#ifdef HAVE_LIBC
   69.82 +void netfront_select_handler(evtchn_port_t port, struct pt_regs *regs, void *data)
   69.83 +{
   69.84 +    int flags;
   69.85 +    struct netfront_dev *dev = data;
   69.86 +    int fd = dev->fd;
   69.87 +
   69.88 +    local_irq_save(flags);
   69.89 +    network_tx_buf_gc(dev);
   69.90 +    local_irq_restore(flags);
   69.91 +
   69.92 +    files[fd].read = 1;
   69.93 +    wake_up(&netfront_queue);
   69.94 +}
   69.95 +#endif
   69.96 +
   69.97  struct netfront_dev *init_netfront(char *nodename, void (*thenetif_rx)(unsigned char* data, int len), unsigned char rawmac[6])
   69.98  {
   69.99      xenbus_transaction_t xbt;
  69.100 @@ -266,7 +307,12 @@ struct netfront_dev *init_netfront(char 
  69.101      dev->dom = op.remote_dom = xenbus_read_integer(path);
  69.102      HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound, &op);
  69.103      clear_evtchn(op.port);        /* Without, handler gets invoked now! */
  69.104 -    dev->local_port = bind_evtchn(op.port, netfront_handler, dev);
  69.105 +#ifdef HAVE_LIBC
  69.106 +    if (thenetif_rx == NETIF_SELECT_RX)
  69.107 +	dev->local_port = bind_evtchn(op.port, netfront_select_handler, dev);
  69.108 +    else
  69.109 +#endif
  69.110 +	dev->local_port = bind_evtchn(op.port, netfront_handler, dev);
  69.111      dev->evtchn=op.port;
  69.112  
  69.113      txs = (struct netif_tx_sring*) alloc_page();
  69.114 @@ -381,6 +427,23 @@ done:
  69.115      return dev;
  69.116  }
  69.117  
  69.118 +#ifdef HAVE_LIBC
  69.119 +int netfront_tap_open(char *nodename) {
  69.120 +    struct netfront_dev *dev;
  69.121 +
  69.122 +    dev = init_netfront(nodename, NETIF_SELECT_RX, NULL);
  69.123 +    if (!dev) {
  69.124 +	printk("TAP open failed\n");
  69.125 +	errno = EIO;
  69.126 +	return -1;
  69.127 +    }
  69.128 +    dev->fd = alloc_fd(FTYPE_TAP);
  69.129 +    printk("tap_open(%s) -> %d\n", nodename, dev->fd);
  69.130 +    files[dev->fd].tap.dev = dev;
  69.131 +    return dev->fd;
  69.132 +}
  69.133 +#endif
  69.134 +
  69.135  void shutdown_netfront(struct netfront_dev *dev)
  69.136  {
  69.137      char* err;
  69.138 @@ -481,3 +544,30 @@ void netfront_xmit(struct netfront_dev *
  69.139      network_tx_buf_gc(dev);
  69.140      local_irq_restore(flags);
  69.141  }
  69.142 +
  69.143 +#ifdef HAVE_LIBC
  69.144 +ssize_t netfront_receive(struct netfront_dev *dev, unsigned char *data, size_t len)
  69.145 +{
  69.146 +    unsigned long flags;
  69.147 +    int fd = dev->fd;
  69.148 +    ASSERT(current == main_thread);
  69.149 +
  69.150 +    dev->rlen = 0;
  69.151 +    dev->data = data;
  69.152 +    dev->len = len;
  69.153 +
  69.154 +    local_irq_save(flags);
  69.155 +    network_rx(dev);
  69.156 +    if (!dev->rlen)
  69.157 +	/* No data for us, make select stop returning */
  69.158 +	files[fd].read = 0;
  69.159 +    /* Before re-enabling the interrupts, in case a packet just arrived in the
  69.160 +     * meanwhile. */
  69.161 +    local_irq_restore(flags);
  69.162 +
  69.163 +    dev->data = NULL;
  69.164 +    dev->len = 0;
  69.165 +
  69.166 +    return dev->rlen;
  69.167 +}
  69.168 +#endif
    70.1 --- a/extras/mini-os/sched.c	Wed Feb 13 10:37:18 2008 -0700
    70.2 +++ b/extras/mini-os/sched.c	Thu Feb 14 09:34:27 2008 -0700
    70.3 @@ -56,6 +56,7 @@
    70.4  
    70.5  struct thread *idle_thread = NULL;
    70.6  LIST_HEAD(exited_threads);
    70.7 +static int threads_started;
    70.8  
    70.9  void inline print_runqueue(void)
   70.10  {
   70.11 @@ -172,6 +173,9 @@ struct thread* create_thread(char *name,
   70.12      /* Not runable, not exited, not sleeping */
   70.13      thread->flags = 0;
   70.14      thread->wakeup_time = 0LL;
   70.15 +#ifdef HAVE_LIBC
   70.16 +    _REENT_INIT_PTR((&thread->reent))
   70.17 +#endif
   70.18      set_runnable(thread);
   70.19      local_irq_save(flags);
   70.20      if(idle_thread != NULL) {
   70.21 @@ -185,6 +189,42 @@ struct thread* create_thread(char *name,
   70.22      return thread;
   70.23  }
   70.24  
   70.25 +#ifdef HAVE_LIBC
   70.26 +static struct _reent callback_reent;
   70.27 +struct _reent *__getreent(void)
   70.28 +{
   70.29 +    struct _reent *_reent;
   70.30 +
   70.31 +    if (!threads_started)
   70.32 +	_reent = _impure_ptr;
   70.33 +    else if (in_callback)
   70.34 +	_reent = &callback_reent;
   70.35 +    else
   70.36 +	_reent = &get_current()->reent;
   70.37 +
   70.38 +#ifndef NDEBUG
   70.39 +#if defined(__x86_64__) || defined(__x86__)
   70.40 +    {
   70.41 +#ifdef __x86_64__
   70.42 +	register unsigned long sp asm ("rsp");
   70.43 +#else
   70.44 +	register unsigned long sp asm ("esp");
   70.45 +#endif
   70.46 +	if ((sp & (STACK_SIZE-1)) < STACK_SIZE / 16) {
   70.47 +	    static int overflowing;
   70.48 +	    if (!overflowing) {
   70.49 +		overflowing = 1;
   70.50 +		printk("stack overflow\n");
   70.51 +		BUG();
   70.52 +	    }
   70.53 +	}
   70.54 +    }
   70.55 +#endif
   70.56 +#endif
   70.57 +    return _reent;
   70.58 +}
   70.59 +#endif
   70.60 +
   70.61  void exit_thread(void)
   70.62  {
   70.63      unsigned long flags;
   70.64 @@ -228,6 +268,7 @@ void wake(struct thread *thread)
   70.65  void idle_thread_fn(void *unused)
   70.66  {
   70.67      s_time_t until;
   70.68 +    threads_started = 1;
   70.69      unsigned long flags;
   70.70      struct list_head *iterator;
   70.71      struct thread *next, *thread;
   70.72 @@ -297,6 +338,9 @@ void init_sched(void)
   70.73  {
   70.74      printk("Initialising scheduler\n");
   70.75  
   70.76 +#ifdef HAVE_LIBC
   70.77 +    _REENT_INIT_PTR((&callback_reent))
   70.78 +#endif
   70.79      idle_thread = create_thread("Idle", idle_thread_fn, NULL);
   70.80      INIT_LIST_HEAD(&idle_thread->thread_list);
   70.81  }
    71.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    71.2 +++ b/stubdom/Makefile	Thu Feb 14 09:34:27 2008 -0700
    71.3 @@ -0,0 +1,259 @@
    71.4 +XEN_ROOT = ..
    71.5 +
    71.6 +export XEN_OS=MiniOS
    71.7 +
    71.8 +include $(XEN_ROOT)/Config.mk
    71.9 +export stubdom=y
   71.10 +export debug=y
   71.11 +
   71.12 +IOEMU_OPTIONS=--disable-vnc-tls 
   71.13 +BINUTILS_VERSION=2.18
   71.14 +GCC_VERSION=4.2.2
   71.15 +ZLIB_VERSION=1.2.3
   71.16 +LIBPCI_VERSION=2.2.9
   71.17 +NEWLIB_DATE=2008-01-01
   71.18 +LWIP_DATE=2008-02-08
   71.19 +
   71.20 +WGET=wget -c
   71.21 +
   71.22 +GNU_TARGET_ARCH:=$(XEN_TARGET_ARCH)
   71.23 +ifeq ($(XEN_TARGET_ARCH),x86_32)
   71.24 +GNU_TARGET_ARCH:=i686
   71.25 +endif
   71.26 +
   71.27 +ifeq ($(GNU_TARGET_ARCH), i686)
   71.28 +TARGET_CFLAGS=
   71.29 +endif
   71.30 +ifeq ($(GNU_TARGET_ARCH), x86_64)
   71.31 +TARGET_CFLAGS=-mno-red-zone
   71.32 +endif
   71.33 +ifeq ($(GNU_TARGET_ARCH), ia64)
   71.34 +TARGET_CFLAGS=-mconstant-gp
   71.35 +endif
   71.36 +
   71.37 +CROSS_ROOT=cross-root-$(GNU_TARGET_ARCH)
   71.38 +CROSS_PREFIX=$(CURDIR)/$(CROSS_ROOT)
   71.39 +export CROSS_COMPILE=$(GNU_TARGET_ARCH)-xen-elf-
   71.40 +export PATH:=$(CROSS_PREFIX)/bin:$(PATH)
   71.41 +
   71.42 +.PHONY: all
   71.43 +all: qemu-stubdom
   71.44 +
   71.45 +################
   71.46 +# Cross-binutils
   71.47 +################
   71.48 +
   71.49 +binutils-$(BINUTILS_VERSION).tar.bz2:
   71.50 +	$(WGET) http://ftp.gnu.org/gnu/binutils/$@
   71.51 +binutils-$(BINUTILS_VERSION): binutils-$(BINUTILS_VERSION).tar.bz2
   71.52 +	tar xjf $@.tar.bz2
   71.53 +	( cd binutils-$(BINUTILS_VERSION) && patch -p1 < ../binutils.patch )
   71.54 +	touch $@
   71.55 +
   71.56 +BINUTILS_STAMPFILE=$(CROSS_ROOT)/bin/$(GNU_TARGET_ARCH)-xen-elf-ar
   71.57 +.PHONY: cross-binutils
   71.58 +cross-binutils: $(BINUTILS_STAMPFILE)
   71.59 +$(BINUTILS_STAMPFILE): binutils-$(BINUTILS_VERSION)
   71.60 +	mkdir -p binutils-build
   71.61 +	( cd binutils-build && \
   71.62 +	  ../binutils-$(BINUTILS_VERSION)/configure --prefix=$(CROSS_PREFIX) --verbose --target=$(GNU_TARGET_ARCH)-xen-elf && \
   71.63 +	  $(MAKE) && \
   71.64 +	  $(MAKE) check && \
   71.65 +	  $(MAKE) install )
   71.66 +
   71.67 +###########
   71.68 +# Cross-gcc
   71.69 +###########
   71.70 +
   71.71 +gcc-$(GCC_VERSION).tar.bz2:
   71.72 +	$(WGET) http://ftp.gnu.org/gnu/gcc/gcc-$(GCC_VERSION)/gcc-$(GCC_VERSION).tar.bz2
   71.73 +gcc-$(GCC_VERSION): gcc-$(GCC_VERSION).tar.bz2
   71.74 +	tar xjf gcc-$(GCC_VERSION).tar.bz2
   71.75 +	( cd gcc-$(GCC_VERSION) && patch -p1 < ../gcc.patch )
   71.76 +	touch $@
   71.77 +	
   71.78 +GCC_STAMPFILE=$(CROSS_ROOT)/bin/$(GNU_TARGET_ARCH)-xen-elf-gcc-$(GCC_VERSION)
   71.79 +.PHONY: cross-gcc
   71.80 +cross-gcc: $(GCC_STAMPFILE)
   71.81 +$(GCC_STAMPFILE): gcc-$(GCC_VERSION) $(BINUTILS_STAMPFILE)
   71.82 +	mkdir -p gcc-build
   71.83 +	( cd gcc-build && \
   71.84 +	  ../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 && \
   71.85 +	  $(MAKE) GCC_FOR_TARGET='$$$$r/gcc/xgcc -B$$$$r/gcc/ '"$(TARGET_CFLAGS)"' $$(FLAGS_FOR_TARGET)' && \
   71.86 +	  $(MAKE) install )
   71.87 +
   71.88 +##############
   71.89 +# Cross-newlib
   71.90 +##############
   71.91 +
   71.92 +newlib-cvs:
   71.93 +	cvs -z 9 -d :pserver:anoncvs@sources.redhat.com:/cvs/src co -D $(NEWLIB_DATE) newlib
   71.94 +	mv src newlib-cvs
   71.95 +	( cd newlib-cvs && patch -p0 < ../newlib.patch)
   71.96 +
   71.97 +NEWLIB_STAMPFILE=$(CROSS_ROOT)/$(GNU_TARGET_ARCH)-xen-elf/lib/libc.a
   71.98 +.PHONY: cross-newlib
   71.99 +cross-newlib: $(NEWLIB_STAMPFILE)
  71.100 +$(NEWLIB_STAMPFILE): newlib-cvs $(GCC_STAMPFILE)
  71.101 +	mkdir -p newlib-build
  71.102 +	( cd newlib-build && \
  71.103 +	  CC_FOR_TARGET="$(GNU_TARGET_ARCH)-xen-elf-gcc $(TARGET_CFLAGS)" ../newlib-cvs/configure --prefix=$(CROSS_PREFIX) --verbose --target=$(GNU_TARGET_ARCH)-xen-elf --enable-newlib-io-long-long && \
  71.104 +	  $(MAKE) && \
  71.105 +	  $(MAKE) install )
  71.106 +
  71.107 +############
  71.108 +# Cross-zlib
  71.109 +############
  71.110 +
  71.111 +zlib-$(ZLIB_VERSION).tar.gz:
  71.112 +	$(WGET) http://www.zlib.net/zlib-$(ZLIB_VERSION).tar.gz
  71.113 +
  71.114 +ZLIB_STAMPFILE=$(CROSS_ROOT)/$(GNU_TARGET_ARCH)-xen-elf/lib/libz.a
  71.115 +.PHONY: cross-zlib
  71.116 +cross-zlib: $(ZLIB_STAMPFILE)
  71.117 +$(ZLIB_STAMPFILE): zlib-$(ZLIB_VERSION).tar.gz $(NEWLIB_STAMPFILE)
  71.118 +	tar xzf $<
  71.119 +	( cd zlib-$(ZLIB_VERSION) && \
  71.120 +	  CFLAGS="$(TARGET_CFLAGS)" CC=$(GNU_TARGET_ARCH)-xen-elf-gcc ./configure --prefix=$(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf && \
  71.121 +	  $(MAKE) libz.a && \
  71.122 +	  $(MAKE) install )
  71.123 +
  71.124 +##############
  71.125 +# Cross-libpci
  71.126 +##############
  71.127 +
  71.128 +pciutils-$(LIBPCI_VERSION).tar.bz2:
  71.129 +	$(WGET) http://www.kernel.org/pub/software/utils/pciutils/pciutils-$(LIBPCI_VERSION).tar.bz2
  71.130 +
  71.131 +LIBPCI_STAMPFILE=$(CROSS_ROOT)/$(GNU_TARGET_ARCH)-xen-elf/lib/libpci.a
  71.132 +.PHONY: cross-libpci
  71.133 +cross-libpci: $(LIBPCI_STAMPFILE)
  71.134 +$(LIBPCI_STAMPFILE): pciutils-$(LIBPCI_VERSION).tar.bz2 $(NEWLIB_STAMPFILE) $(ZLIB_STAMPFILE)
  71.135 +	tar xjf $<
  71.136 +	( cd pciutils-$(LIBPCI_VERSION) && \
  71.137 +	  cp ../libpci.config.h lib/config.h && \
  71.138 +	  echo '#define PCILIB_VERSION "$(LIBPCI_VERSION)"' >> lib/config.h && \
  71.139 +	  cp ../libpci.config.mak lib/config.mk && \
  71.140 +	  $(MAKE) CC="$(GNU_TARGET_ARCH)-xen-elf-gcc $(TARGET_CFLAGS)" lib/libpci.a && \
  71.141 +	  $(INSTALL_DATA) lib/libpci.a $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/lib/ && \
  71.142 +	  $(INSTALL_DIR) $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/include/pci && \
  71.143 +	  $(INSTALL_DATA) lib/{config,header,pci,types}.h $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/include/pci/ \
  71.144 +	)
  71.145 +
  71.146 +######
  71.147 +# lwIP
  71.148 +######
  71.149 +
  71.150 +lwip-cvs:
  71.151 +	cvs -z 9 -d :pserver:anonymous@cvs.savannah.nongnu.org:/sources/lwip co -D $(LWIP_DATE) lwip
  71.152 +	mv lwip lwip-cvs
  71.153 +
  71.154 +#######
  71.155 +# Links
  71.156 +#######
  71.157 +
  71.158 +.PHONY: $(CROSS_ROOT)
  71.159 +$(CROSS_ROOT): cross-newlib cross-zlib cross-libpci
  71.160 +
  71.161 +.PHONY: mk-symlinks
  71.162 +mk-symlinks:
  71.163 +	[ -h include ] || ln -sf ../tools/include .
  71.164 +	mkdir -p libxc
  71.165 +	[ -h libxc/Makefile ] || ( cd libxc && \
  71.166 +	  ln -sf ../../tools/libxc/*.h . && \
  71.167 +	  ln -sf ../../tools/libxc/*.c . && \
  71.168 +	  ln -sf ../../tools/libxc/Makefile . )
  71.169 +	mkdir -p libxc/$(XEN_TARGET_ARCH)
  71.170 +	[ -h libxc/$(XEN_TARGET_ARCH) ] || ( cd libxc/$(XEN_TARGET_ARCH) && \
  71.171 +	  ln -sf ../../tools/libxc/$(XEN_TARGET_ARCH)/*.c . && \
  71.172 +	  ln -sf ../../tools/libxc/$(XEN_TARGET_ARCH)/*.h . && \
  71.173 +	  ln -sf ../../tools/libxc/$(XEN_TARGET_ARCH)/Makefile . )
  71.174 +	mkdir -p ioemu
  71.175 +	[ -h ioemu/Makefile ] || ( cd ioemu && \
  71.176 +	  ln -sf ../../tools/ioemu/* . && \
  71.177 +	  ([ ! -h config-host.h ] || rm -f config-host.h) && \
  71.178 +	  ([ ! -h config-host.mak ] || rm -f config-host.mak) )
  71.179 +	[ -h mini-os ] || ln -sf ../extras/mini-os .
  71.180 +
  71.181 +#######
  71.182 +# libxc
  71.183 +#######
  71.184 +
  71.185 +.PHONY: libxc
  71.186 +libxc: cross-zlib mk-symlinks
  71.187 +	$(MAKE) -C $@
  71.188 +
  71.189 +#######
  71.190 +# ioemu
  71.191 +#######
  71.192 +
  71.193 +.PHONY: ioemu
  71.194 +ioemu: cross-zlib cross-libpci mk-symlinks libxc
  71.195 +	[ -f ioemu/config-host.mak ] || \
  71.196 +	  ( cd ioemu ; XEN_TARGET_ARCH=$(XEN_TARGET_ARCH) sh configure --prefix=/usr --enable-stubdom $(IOEMU_OPTIONS))
  71.197 +	$(MAKE) -C ioemu LWIPDIR=$(CURDIR)/lwip-cvs
  71.198 +
  71.199 +######
  71.200 +# caml
  71.201 +######
  71.202 +
  71.203 +.PHONY: caml
  71.204 +caml:
  71.205 +	$(MAKE) -C $@
  71.206 +
  71.207 +########
  71.208 +# minios
  71.209 +########
  71.210 +
  71.211 +.PHONY: qemu-stubdom
  71.212 +qemu-stubdom: mk-symlinks lwip-cvs libxc ioemu
  71.213 +	$(MAKE) -C mini-os LWIPDIR=$(CURDIR)/lwip-cvs QEMUDIR=$(CURDIR)/ioemu
  71.214 +
  71.215 +.PHONY: caml-stubdom
  71.216 +caml-stubdom: mk-symlinks lwip-cvs libxc cross-libpci caml
  71.217 +	$(MAKE) -C mini-os LWIPDIR=$(CURDIR)/lwia-cvs CAMLDIR=$(CURDIR)/caml
  71.218 +
  71.219 +#########
  71.220 +# install
  71.221 +#########
  71.222 +
  71.223 +install: mini-os/mini-os.gz
  71.224 +	$(INSTALL_PROG) stubdom-dm "$(DESTDIR)/usr/lib/xen/bin"
  71.225 +	$(INSTALL_PROG) mini-os/mini-os.gz "$(DESTDIR)/usr/lib/xen/boot/stubdom.gz"
  71.226 +
  71.227 +#######
  71.228 +# clean
  71.229 +#######
  71.230 +
  71.231 +# Only clean the libxc/ioemu/mini-os part
  71.232 +.PHONY: clean
  71.233 +clean:
  71.234 +	-$(MAKE) -C mini-os LWIPDIR=$(CURDIR)/lwip-cvs clean
  71.235 +	$(MAKE) -C caml clean
  71.236 +	rm -fr libxc ioemu mini-os include
  71.237 +
  71.238 +# clean the cross-compilation result
  71.239 +.PHONY: crossclean
  71.240 +crossclean: clean
  71.241 +	rm -fr $(CROSS_ROOT)
  71.242 +	rm -fr binutils-build gcc-build newlib-build
  71.243 +	rm -fr zlib-$(ZLIB_VERSION) pciutils-$(LIBPCI_VERSION)
  71.244 +
  71.245 +# clean patched sources
  71.246 +.PHONY: patchclean
  71.247 +patchclean: crossclean
  71.248 +	rm -fr binutils-$(BINUTILS_VERSION)
  71.249 +	rm -fr gcc-$(GCC_VERSION)
  71.250 +	rm -fr newlib-cvs
  71.251 +	rm -fr lwip-cvs
  71.252 +
  71.253 +# clean downloads
  71.254 +.PHONY: downloadclean
  71.255 +downloadclean: patchclean
  71.256 +	rm -f binutils-$(BINUTILS_VERSION).tar.bz2
  71.257 +	rm -f gcc-$(GCC_VERSION).tar.bz2
  71.258 +	rm -f zlib-$(ZLIB_VERSION).tar.gz
  71.259 +	rm -f pciutils-$(LIBPCI_VERSION).tar.bz2
  71.260 +
  71.261 +.PHONY: distclean
  71.262 +distclean: downloadclean
    72.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    72.2 +++ b/stubdom/README	Thu Feb 14 09:34:27 2008 -0700
    72.3 @@ -0,0 +1,41 @@
    72.4 +To compile
    72.5 +==========
    72.6 +
    72.7 +Just run make -j 4, that will download / patch / compile
    72.8 +Then make install to install the result.
    72.9 +
   72.10 +Also, run make and make install in $XEN_ROOT/tools/fs-back
   72.11 +
   72.12 +To run
   72.13 +======
   72.14 +
   72.15 +mkdir -p /exports/usr/share/qemu
   72.16 +ln -s /usr/share/qemu/keymaps /exports/usr/share/qemu
   72.17 +/usr/sbin/fs-backend &
   72.18 +
   72.19 +
   72.20 +In your HVM config "hvmconfig",
   72.21 +
   72.22 +- use VNC, set vnclisten to "172.30.206.1" for instance:
   72.23 +
   72.24 +vnc=1 
   72.25 +vnclisten="172.30.206.1" 
   72.26 +
   72.27 +- use /usr/lib/xen/bin/stubdom-dm as dm script
   72.28 +
   72.29 +device_model = '/usr/lib/xen/bin/stubdom-dm'
   72.30 +
   72.31 +- comment the disk statement:
   72.32 +#disk = [  'file:/tmp/install.iso,hdc:cdrom,r', 'phy:/dev/sda6,hda,w', 'file:/tmp/test,hdb,r' ]
   72.33 +
   72.34 +Create /etc/xen/stubdom-hvmconfig ("hvmconfig" must match your main config file)
   72.35 +with
   72.36 +
   72.37 +kernel="/usr/lib/xen/boot/stubdom.gz"
   72.38 +vif=[ 'ip=172.30.206.1', 'ip=10.0.1.1,mac=aa:00:00:12:23:34']
   72.39 +disk = [  'file:/tmp/install.iso,hdc:cdrom,r', 'phy:/dev/sda6,hda,w', 'file:/tmp/test,hdb,r' ]
   72.40 +
   72.41 +where
   72.42 +- 172.30.206.1 is the IP for vnc,
   72.43 +- 'ip=10.0.1.1,mac=' is the same net configuration as in the hvmconfig script,
   72.44 +- and disk = is the same block configuration as in the hvmconfig script.
    73.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    73.2 +++ b/stubdom/binutils.patch	Thu Feb 14 09:34:27 2008 -0700
    73.3 @@ -0,0 +1,14 @@
    73.4 +It looks like binutils has troubles with makeinfo and the doc generation.
    73.5 +We don't need it anyway
    73.6 +
    73.7 +--- binutils-2.18/bfd/Makefile.inorig	2008-01-16 16:17:43.004484000 +0000
    73.8 ++++ binutils-2.18/bfd/Makefile.in	2008-01-16 16:17:50.505526000 +0000
    73.9 +@@ -271,7 +271,7 @@
   73.10 + INCDIR = $(srcdir)/../include
   73.11 + CSEARCH = -I. -I$(srcdir) -I$(INCDIR)
   73.12 + MKDEP = gcc -MM
   73.13 +-SUBDIRS = doc po
   73.14 ++SUBDIRS = po
   73.15 + bfddocdir = doc
   73.16 + bfdlib_LTLIBRARIES = libbfd.la
   73.17 + AM_CFLAGS = $(WARN_CFLAGS)
    74.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    74.2 +++ b/stubdom/caml/Makefile	Thu Feb 14 09:34:27 2008 -0700
    74.3 @@ -0,0 +1,18 @@
    74.4 +XEN_ROOT = ../..
    74.5 +
    74.6 +include $(XEN_ROOT)/Config.mk
    74.7 +
    74.8 +OCAMLFIND=ocamlfind
    74.9 +OCAMLOPT=ocamlopt
   74.10 +
   74.11 +OBJS := hello.cmx
   74.12 +LIBS := 
   74.13 +
   74.14 +%.cmx: %.ml
   74.15 +	$(OCAMLFIND) $(OCAMLOPT) -c $< -o $@
   74.16 +
   74.17 +caml.o: $(OBJS)
   74.18 +	$(OCAMLFIND) $(OCAMLOPT) $(LIBS) $^ -output-obj -o $@
   74.19 +
   74.20 +clean:
   74.21 +	rm -f *.o *.cmx *.cmi
    75.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    75.2 +++ b/stubdom/caml/hello.ml	Thu Feb 14 09:34:27 2008 -0700
    75.3 @@ -0,0 +1,4 @@
    75.4 +let main arg =
    75.5 +  Printf.printf "Hello, world!\n%!."
    75.6 +
    75.7 +let _ = Callback.register "main" main
    76.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    76.2 +++ b/stubdom/gcc.patch	Thu Feb 14 09:34:27 2008 -0700
    76.3 @@ -0,0 +1,31 @@
    76.4 +Backported from later versions
    76.5 +
    76.6 +--- gcc-4.2.2/gcc/config.gcc       2007-11-22 16:27:45.000000000 +0000
    76.7 ++++ gcc-4.2.2/gcc/config.gcc       2007-11-22 16:23:00.000000000 +0000
    76.8 +@@ -1033,6 +1033,11 @@
    76.9 + 	tmake_file="i386/t-i386elf t-svr4"
   76.10 + 	use_fixproto=yes
   76.11 + 	;;
   76.12 ++x86_64-*-elf*)
   76.13 ++	tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h i386/i386elf.h i386/x86-64.h"
   76.14 ++	tmake_file="i386/t-i386elf t-svr4"
   76.15 ++	use_fixproto=yes
   76.16 ++	;;
   76.17 + i[34567]86-sequent-ptx4* | i[34567]86-sequent-sysv4*)
   76.18 + 	if test x$gas = xyes
   76.19 + 	then
   76.20 +
   76.21 +We don't have a libc yet at this stage. Unused anyway
   76.22 +
   76.23 +--- gcc-4.2.2/gcc/unwind-generic.h.orig 2008-01-11 18:54:40.000000000 +0100
   76.24 ++++ gcc-4.2.2/gcc/unwind-generic.h      2008-01-11 18:54:31.000000000 +0100
   76.25 +@@ -203,7 +203,6 @@
   76.26 +    compatible with the standard ABI for IA-64, we inline these.  */
   76.27 + 
   76.28 + #ifdef __ia64__
   76.29 +-#include <stdlib.h>
   76.30 + 
   76.31 + static inline _Unwind_Ptr
   76.32 + _Unwind_GetDataRelBase (struct _Unwind_Context *_C)
   76.33 +Backported from later versions
   76.34 +
    77.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    77.2 +++ b/stubdom/libpci.config.h	Thu Feb 14 09:34:27 2008 -0700
    77.3 @@ -0,0 +1,5 @@
    77.4 +#define PCI_OS_STUBDOM
    77.5 +#define PCI_HAVE_STDINT_H
    77.6 +#define PCI_PATH_IDS_DIR "."
    77.7 +#define PCI_COMPRESSED_IDS
    77.8 +#define PCI_IDS "pci.ids.gz"
    78.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    78.2 +++ b/stubdom/libpci.config.mak	Thu Feb 14 09:34:27 2008 -0700
    78.3 @@ -0,0 +1,2 @@
    78.4 +LIBZ=-lz
    78.5 +LDLIBS+=$(LIBZ)
    79.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    79.2 +++ b/stubdom/newlib.patch	Thu Feb 14 09:34:27 2008 -0700
    79.3 @@ -0,0 +1,203 @@
    79.4 +There is a mix between longs and long longs.
    79.5 +
    79.6 +Index: newlib/libc/include/inttypes.h
    79.7 +===================================================================
    79.8 +RCS file: /cvs/src/src/newlib/libc/include/inttypes.h,v
    79.9 +retrieving revision 1.3
   79.10 +diff -u -p -r1.3 inttypes.h
   79.11 +--- newlib/libc/include/inttypes.h	16 Dec 2005 19:03:12 -0000	1.3
   79.12 ++++ newlib/libc/include/inttypes.h	8 Nov 2007 16:32:44 -0000
   79.13 +@@ -163,12 +163,12 @@
   79.14 + 
   79.15 + 
   79.16 + /* 64-bit types */
   79.17 +-#if __have_longlong64
   79.18 +-#define __PRI64(x) __STRINGIFY(ll##x)
   79.19 +-#define __SCN64(x) __STRINGIFY(ll##x)
   79.20 +-#elif __have_long64
   79.21 ++#if __have_long64
   79.22 + #define __PRI64(x) __STRINGIFY(l##x)
   79.23 + #define __SCN64(x) __STRINGIFY(l##x)
   79.24 ++#elif __have_longlong64
   79.25 ++#define __PRI64(x) __STRINGIFY(ll##x)
   79.26 ++#define __SCN64(x) __STRINGIFY(ll##x)
   79.27 + #else
   79.28 + #define __PRI64(x) __STRINGIFY(x)
   79.29 + #define __SCN64(x) __STRINGIFY(x)
   79.30 +@@ -217,12 +217,12 @@
   79.31 + #endif
   79.32 + 
   79.33 + /* max-bit types */
   79.34 +-#if __have_longlong64
   79.35 +-#define __PRIMAX(x) __STRINGIFY(ll##x)
   79.36 +-#define __SCNMAX(x) __STRINGIFY(ll##x)
   79.37 +-#elif __have_long64
   79.38 ++#if __have_long64
   79.39 + #define __PRIMAX(x) __STRINGIFY(l##x)
   79.40 + #define __SCNMAX(x) __STRINGIFY(l##x)
   79.41 ++#elif __have_longlong64
   79.42 ++#define __PRIMAX(x) __STRINGIFY(ll##x)
   79.43 ++#define __SCNMAX(x) __STRINGIFY(ll##x)
   79.44 + #else
   79.45 + #define __PRIMAX(x) __STRINGIFY(x)
   79.46 + #define __SCNMAX(x) __STRINGIFY(x)
   79.47 +@@ -242,12 +242,12 @@
   79.48 + #define SCNxMAX		__SCNMAX(x)
   79.49 + 
   79.50 + /* ptr types */
   79.51 +-#if __have_longlong64
   79.52 +-#define __PRIPTR(x) __STRINGIFY(ll##x)
   79.53 +-#define __SCNPTR(x) __STRINGIFY(ll##x)
   79.54 +-#elif __have_long64
   79.55 ++#if __have_long64
   79.56 + #define __PRIPTR(x) __STRINGIFY(l##x)
   79.57 + #define __SCNPTR(x) __STRINGIFY(l##x)
   79.58 ++#elif __have_longlong64
   79.59 ++#define __PRIPTR(x) __STRINGIFY(ll##x)
   79.60 ++#define __SCNPTR(x) __STRINGIFY(ll##x)
   79.61 + #else
   79.62 + #define __PRIPTR(x) __STRINGIFY(x)
   79.63 + #define __SCNPTR(x) __STRINGIFY(x)
   79.64 +
   79.65 +We don't want u?int32_t to be long as our code assume in a lot of places to be
   79.66 +int.
   79.67 +
   79.68 +Index: newlib/libc/include/stdint.h
   79.69 +===================================================================
   79.70 +RCS file: /cvs/src/src/newlib/libc/include/stdint.h,v
   79.71 +retrieving revision 1.10
   79.72 +diff -u -p -r1.10 stdint.h
   79.73 +--- newlib/libc/include/stdint.h	16 Aug 2006 21:39:43 -0000	1.10
   79.74 ++++ newlib/libc/include/stdint.h	12 Feb 2008 13:07:52 -0000
   79.75 +@@ -38,7 +38,7 @@ extern "C" {
   79.76 + #if __STDINT_EXP(LONG_MAX) > 0x7fffffff
   79.77 + #define __have_long64 1
   79.78 + #elif __STDINT_EXP(LONG_MAX) == 0x7fffffff && !defined(__SPU__)
   79.79 +-#define __have_long32 1
   79.80 ++/* #define __have_long32 1 */
   79.81 + #endif
   79.82 + 
   79.83 + #if __STDINT_EXP(SCHAR_MAX) == 0x7f
   79.84 +
   79.85 +Define the basic ia64 jump buffer
   79.86 +
   79.87 +Index: newlib/libc/include/machine/setjmp.h
   79.88 +===================================================================
   79.89 +RCS file: /cvs/src/src/newlib/libc/include/machine/setjmp.h,v
   79.90 +retrieving revision 1.34
   79.91 +diff -u -p -r1.34 setjmp.h
   79.92 +--- newlib/libc/include/machine/setjmp.h	7 Nov 2007 21:42:24 -0000	1.34
   79.93 ++++ newlib/libc/include/machine/setjmp.h	11 Jan 2008 18:10:43 -0000
   79.94 +@@ -72,6 +72,11 @@ _BEGIN_STD_C
   79.95 + #define _JBLEN  8
   79.96 + #endif
   79.97 + 
   79.98 ++#ifdef __ia64__
   79.99 ++#define _JBTYPE long
  79.100 ++#define _JBLEN 70
  79.101 ++#endif
  79.102 ++
  79.103 + #ifdef __i960__
  79.104 + #define _JBLEN 35
  79.105 + #endif
  79.106 +
  79.107 +In mini-os we use a dynamic reentrency buffer.
  79.108 +
  79.109 +Index: newlib/libc/include/sys/config.h
  79.110 +===================================================================
  79.111 +RCS file: /cvs/src/src/newlib/libc/include/sys/config.h,v
  79.112 +retrieving revision 1.47
  79.113 +diff -u -p -r1.47 config.h
  79.114 +--- newlib/libc/include/sys/config.h	15 Mar 2007 21:32:12 -0000	1.47
  79.115 ++++ newlib/libc/include/sys/config.h	8 Nov 2007 16:32:44 -0000
  79.116 +@@ -71,6 +71,10 @@
  79.117 + #endif
  79.118 + #endif
  79.119 + 
  79.120 ++#ifndef __DYNAMIC_REENT__
  79.121 ++#define __DYNAMIC_REENT__
  79.122 ++#endif
  79.123 ++
  79.124 + #ifdef __mn10200__
  79.125 + #define __SMALL_BITFIELDS
  79.126 + #endif
  79.127 +
  79.128 +Dynamic pointer to our reentrancy zone
  79.129 +
  79.130 +Index: newlib/libc/reent/getreent.c
  79.131 +===================================================================
  79.132 +RCS file: /cvs/src/src/newlib/libc/reent/getreent.c,v
  79.133 +retrieving revision 1.2
  79.134 +diff -u -p -r1.2 getreent.c
  79.135 +--- newlib/libc/reent/getreent.c	7 Sep 2007 00:45:55 -0000	1.2
  79.136 ++++ newlib/libc/reent/getreent.c	8 Nov 2007 16:32:44 -0000
  79.137 +@@ -3,12 +3,20 @@
  79.138 + #include <_ansi.h>
  79.139 + #include <reent.h>
  79.140 + 
  79.141 ++#define weak_alias(name, aliasname) \
  79.142 ++  extern __typeof (name) aliasname __attribute__ ((weak, alias (#name)));
  79.143 ++
  79.144 + #ifdef __getreent
  79.145 + #undef __getreent
  79.146 + #endif
  79.147 ++#ifdef __libc_getreent
  79.148 ++#undef __libc_getreent
  79.149 ++#endif
  79.150 + 
  79.151 + struct _reent *
  79.152 +-_DEFUN_VOID(__getreent)
  79.153 ++__libc_getreent (void)
  79.154 + {
  79.155 +   return _impure_ptr;
  79.156 + }
  79.157 ++weak_alias(__libc_getreent,__getreent)
  79.158 ++
  79.159 +
  79.160 +We can't provide a red zone in mini-os.
  79.161 +
  79.162 +Index: newlib/libc/machine/x86_64/memcpy.S
  79.163 +===================================================================
  79.164 +RCS file: /cvs/src/src/newlib/libc/machine/x86_64/memcpy.S,v
  79.165 +retrieving revision 1.1
  79.166 +diff -u -p -r1.1 memcpy.S
  79.167 +--- newlib/libc/machine/x86_64/memcpy.S	28 Aug 2007 21:56:49 -0000	1.1
  79.168 ++++ newlib/libc/machine/x86_64/memcpy.S	8 Nov 2007 16:32:44 -0000
  79.169 +@@ -30,10 +30,18 @@ quadword_aligned:
  79.170 +   cmpq    $256, rdx
  79.171 +   jb      quadword_copy
  79.172 + 
  79.173 ++#if 1
  79.174 ++  subq    $32, rsp
  79.175 ++  movq    rax, 24 (rsp)
  79.176 ++  movq    r12, 16 (rsp)
  79.177 ++  movq    r13, 8  (rsp)
  79.178 ++  movq    r14, 0  (rsp)
  79.179 ++#else
  79.180 +   movq    rax, -8  (rsp)
  79.181 +   movq    r12, -16 (rsp)
  79.182 +   movq    r13, -24 (rsp)
  79.183 +   movq    r14, -32 (rsp)
  79.184 ++#endif
  79.185 + 
  79.186 +   movq    rdx, rcx                /* Copy 128 bytes at a time with minimum cache polution */
  79.187 +   shrq    $7, rcx
  79.188 +@@ -89,10 +97,18 @@ loop:
  79.189 +   movq    rdx, rcx
  79.190 +   andq    $127, rcx
  79.191 +   rep     movsb
  79.192 ++#if 1
  79.193 ++  movq    24 (rsp), rax
  79.194 ++  movq    16 (rsp), r12
  79.195 ++  movq    8  (rsp), r13
  79.196 ++  movq    0  (rsp), r14
  79.197 ++  addq    $32, rsp
  79.198 ++#else
  79.199 +   movq    -8  (rsp), rax
  79.200 +   movq    -16 (rsp), r12
  79.201 +   movq    -24 (rsp), r13
  79.202 +   movq    -32 (rsp), r14
  79.203 ++#endif
  79.204 +   ret
  79.205 + 
  79.206 + 
    80.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    80.2 +++ b/stubdom/stubdom-dm	Thu Feb 14 09:34:27 2008 -0700
    80.3 @@ -0,0 +1,97 @@
    80.4 +#!/bin/bash
    80.5 +#
    80.6 +# Copyright 2007-2008 Samuel Thibault <samuel.thibault@eu.citrix.net>
    80.7 +#
    80.8 +# dm script around stubdomains.
    80.9 +#
   80.10 +
   80.11 +# To fit xterms nicely
   80.12 +height=339
   80.13 +
   80.14 +# Parse arguments
   80.15 +
   80.16 +domid=
   80.17 +domname=
   80.18 +vncviewer=0
   80.19 +vncpid=
   80.20 +while [ "$#" -gt 0 ];
   80.21 +do
   80.22 +    if [ "$#" -ge 2 ];
   80.23 +    then
   80.24 +	case "$1" in
   80.25 +	    -d) domid=$2; shift ;;
   80.26 +	    -domain-name) domname=$2; shift ;;
   80.27 +	    -vnc)
   80.28 +		ip=${2%:*};
   80.29 +		vnc_port=${2#*:};
   80.30 +		shift
   80.31 +		;;
   80.32 +	esac
   80.33 +    fi
   80.34 +    case "$1" in
   80.35 +	-vncviewer) vncviewer=1 ;;
   80.36 +    esac
   80.37 +    shift
   80.38 +done
   80.39 +
   80.40 +[ -z "$domid"   ] && ( echo "couldn't find domain ID" ; exit 1 )
   80.41 +[ -z "$domname" ] && ( echo "couldn't find domain name" ; exit 1 )
   80.42 +
   80.43 +# Termination handler
   80.44 +
   80.45 +term() {
   80.46 +    kill %1
   80.47 +    (
   80.48 +	[ -n "$vncpid" ] && kill -9 $vncpid
   80.49 +	xm destroy stubdom-$domname
   80.50 +	#xm destroy $domname
   80.51 +    ) &
   80.52 +    # We need to exit immediately so as to let xend do the commands above
   80.53 +    exit 0
   80.54 +}
   80.55 +
   80.56 +trap term SIGHUP
   80.57 +
   80.58 +############
   80.59 +# stubdomain
   80.60 +# Wait for any previous stubdom to terminate
   80.61 +while xm list | grep stubdom-$domname
   80.62 +do
   80.63 +	sleep 1
   80.64 +done
   80.65 +
   80.66 +creation="xm create -c stubdom-$domname target=$domid memory=32"
   80.67 +
   80.68 +(while true ; do sleep 60 ; done) | $creation &
   80.69 +#xterm -geometry +0+0 -e /bin/sh -c "$creation ; echo ; echo press ENTER to shut down ; read" &
   80.70 +consolepid=$!
   80.71 +
   80.72 +
   80.73 +while ! vnc_port=`xenstore-read /local/domain/$domid/console/vnc-port`
   80.74 +do
   80.75 +        # Check that the stubdom job is still alive
   80.76 +        kill -0 $consolepid || term
   80.77 +	sleep 1
   80.78 +done
   80.79 +
   80.80 +################
   80.81 +# DEBUG: tcpdump
   80.82 +#while ! stubdomid=`xm domid stubdom-$domname`
   80.83 +#do
   80.84 +#        sleep 1
   80.85 +#done
   80.86 +#xterm -geometry 160x25+0+$height -e /bin/sh -c "tcpdump -n -i vif$stubdomid.0" &
   80.87 +#xterm -geometry 160x25+0+$((2 * $height)) -e /bin/sh -c "tcpdump -n -i vif$stubdomid.1" &
   80.88 +
   80.89 +###########
   80.90 +# vncviewer
   80.91 +if [ "$vncviewer" = 1 ]
   80.92 +then
   80.93 +    vncviewer $ip:$vnc_port &
   80.94 +    vncpid=$!
   80.95 +fi
   80.96 +
   80.97 +# wait for SIGHUP or stubdom termination
   80.98 +wait $consolepid
   80.99 +
  80.100 +term
    81.1 --- a/tools/blktap/drivers/tapdisk.c	Wed Feb 13 10:37:18 2008 -0700
    81.2 +++ b/tools/blktap/drivers/tapdisk.c	Thu Feb 14 09:34:27 2008 -0700
    81.3 @@ -641,7 +641,7 @@ static void get_io_request(struct td_sta
    81.4  	if (!run) return; /*We have received signal to close*/
    81.5  
    81.6  	rp = info->fe_ring.sring->req_prod; 
    81.7 -	rmb();
    81.8 +	xen_rmb();
    81.9  	for (j = info->fe_ring.req_cons; j != rp; j++)
   81.10  	{
   81.11  		int done = 0, start_seg = 0; 
    82.1 --- a/tools/console/daemon/io.c	Wed Feb 13 10:37:18 2008 -0700
    82.2 +++ b/tools/console/daemon/io.c	Thu Feb 14 09:34:27 2008 -0700
    82.3 @@ -60,6 +60,8 @@
    82.4  extern int log_reload;
    82.5  extern int log_guest;
    82.6  extern int log_hv;
    82.7 +extern int log_time_hv;
    82.8 +extern int log_time_guest;
    82.9  extern char *log_dir;
   82.10  
   82.11  static int log_hv_fd = -1;
   82.12 @@ -99,6 +101,50 @@ struct domain
   82.13  
   82.14  static struct domain *dom_head;
   82.15  
   82.16 +static int write_all(int fd, const char* buf, size_t len)
   82.17 +{
   82.18 +	while (len) {
   82.19 +		ssize_t ret = write(fd, buf, len);
   82.20 +		if (ret == -1 && errno == EINTR)
   82.21 +			continue;
   82.22 +		if (ret <= 0)
   82.23 +			return -1;
   82.24 +		len -= ret;
   82.25 +		buf += ret;
   82.26 +	}
   82.27 +
   82.28 +	return 0;
   82.29 +}
   82.30 +
   82.31 +static int write_with_timestamp(int fd, const char *data, size_t sz)
   82.32 +{
   82.33 +	char buf[sz+1];
   82.34 +	char ts[32];
   82.35 +	time_t now = time(NULL);
   82.36 +	const struct tm *tmnow = localtime(&now);
   82.37 +	size_t tslen = strftime(ts, sizeof(ts), "[%d-%m-%Y %H:%M:%S] ", tmnow);
   82.38 +
   82.39 +	memcpy(buf, data, sz);
   82.40 +	while (sz > 0 && buf[sz-1] == '\r')
   82.41 +		sz--;		    // Don't print trailing \r's
   82.42 +	if (sz > 0 && buf[sz-1] != '\n')
   82.43 +		buf[sz++] = '\n';   // Force ending newline
   82.44 +	data = buf;
   82.45 +
   82.46 +	while (sz > 0) {
   82.47 +		const char *nl = strchr(data, '\n') + 1;
   82.48 +		size_t towrite = nl - data;
   82.49 +		if (write_all(fd, ts, tslen) < 0)
   82.50 +			return -1;
   82.51 +		if (write_all(fd, data, towrite))
   82.52 +			return -1;
   82.53 +		sz -= towrite;
   82.54 +		data = nl;
   82.55 +	}
   82.56 +
   82.57 +	return 0;
   82.58 +}
   82.59 +
   82.60  static void buffer_append(struct domain *dom)
   82.61  {
   82.62  	struct buffer *buffer = &dom->buffer;
   82.63 @@ -107,7 +153,7 @@ static void buffer_append(struct domain 
   82.64  
   82.65  	cons = intf->out_cons;
   82.66  	prod = intf->out_prod;
   82.67 -	mb();
   82.68 +	xen_mb();
   82.69  
   82.70  	size = prod - cons;
   82.71  	if ((size == 0) || (size > sizeof(intf->out)))
   82.72 @@ -126,7 +172,7 @@ static void buffer_append(struct domain 
   82.73  		buffer->data[buffer->size++] = intf->out[
   82.74  			MASK_XENCONS_IDX(cons++, intf->out)];
   82.75  
   82.76 -	mb();
   82.77 +	xen_mb();
   82.78  	intf->out_cons = cons;
   82.79  	xc_evtchn_notify(dom->xce_handle, dom->local_port);
   82.80  
   82.81 @@ -135,10 +181,13 @@ static void buffer_append(struct domain 
   82.82  	 * and handle_tty_write will stop being called.
   82.83  	 */
   82.84  	if (dom->log_fd != -1) {
   82.85 -		int len = write(dom->log_fd,
   82.86 -				buffer->data + buffer->size - size,
   82.87 -				size);
   82.88 -		if (len < 0)
   82.89 +		int logret;
   82.90 +		if (log_time_guest) {
   82.91 +			logret = write_with_timestamp(dom->log_fd, buffer->data + buffer->size - size, size);
   82.92 +		} else {
   82.93 +			logret = write_all(dom->log_fd, buffer->data + buffer->size - size, size);
   82.94 +        }
   82.95 +		if (logret < 0)
   82.96  			dolog(LOG_ERR, "Write to log failed on domain %d: %d (%s)\n",
   82.97  			      dom->domid, errno, strerror(errno));
   82.98  	}
   82.99 @@ -195,6 +244,15 @@ static int create_hv_log(void)
  82.100  	if (fd == -1)
  82.101  		dolog(LOG_ERR, "Failed to open log %s: %d (%s)",
  82.102  		      logfile, errno, strerror(errno));
  82.103 +	if (fd != -1 && log_time_hv) {
  82.104 +		if (write_with_timestamp(fd, "Logfile Opened",
  82.105 +					 strlen("Logfile Opened")) < 0) {
  82.106 +			dolog(LOG_ERR, "Failed to log opening timestamp "
  82.107 +				       "in %s: %d (%s)", logfile, errno,
  82.108 +				       strerror(errno));
  82.109 +			return -1;
  82.110 +		}
  82.111 +	}
  82.112  	return fd;
  82.113  }
  82.114  
  82.115 @@ -229,6 +287,15 @@ static int create_domain_log(struct doma
  82.116  	if (fd == -1)
  82.117  		dolog(LOG_ERR, "Failed to open log %s: %d (%s)",
  82.118  		      logfile, errno, strerror(errno));
  82.119 +	if (fd != -1 && log_time_guest) {
  82.120 +		if (write_with_timestamp(fd, "Logfile Opened",
  82.121 +					 strlen("Logfile Opened")) < 0) {
  82.122 +			dolog(LOG_ERR, "Failed to log opening timestamp "
  82.123 +				       "in %s: %d (%s)", logfile, errno,
  82.124 +				       strerror(errno));
  82.125 +			return -1;
  82.126 +		}
  82.127 +	}
  82.128  	return fd;
  82.129  }
  82.130  
  82.131 @@ -683,7 +750,7 @@ static int ring_free_bytes(struct domain
  82.132  
  82.133  	cons = intf->in_cons;
  82.134  	prod = intf->in_prod;
  82.135 -	mb();
  82.136 +	xen_mb();
  82.137  
  82.138  	space = prod - cons;
  82.139  	if (space > sizeof(intf->in))
  82.140 @@ -730,7 +797,7 @@ static void handle_tty_read(struct domai
  82.141  			intf->in[MASK_XENCONS_IDX(prod++, intf->in)] =
  82.142  				msg[i];
  82.143  		}
  82.144 -		wmb();
  82.145 +		xen_wmb();
  82.146  		intf->in_prod = prod;
  82.147  		xc_evtchn_notify(dom->xce_handle, dom->local_port);
  82.148  	} else {
  82.149 @@ -817,11 +884,16 @@ static void handle_hv_logs(void)
  82.150  	if ((port = xc_evtchn_pending(xce_handle)) == -1)
  82.151  		return;
  82.152  
  82.153 -	if (xc_readconsolering(xc_handle, &bufptr, &size, 0, 1, &index) == 0) {
  82.154 -		int len = write(log_hv_fd, buffer, size);
  82.155 -		if (len < 0)
  82.156 -			dolog(LOG_ERR, "Failed to write hypervisor log: %d (%s)",
  82.157 -			      errno, strerror(errno));
  82.158 +	if (xc_readconsolering(xc_handle, &bufptr, &size, 0, 1, &index) == 0 && size > 0) {
  82.159 +		int logret;
  82.160 +		if (log_time_guest)
  82.161 +			logret = write_with_timestamp(log_hv_fd, buffer, size);
  82.162 +		else
  82.163 +			logret = write_all(log_hv_fd, buffer, size);
  82.164 +
  82.165 +		if (logret < 0)
  82.166 +			dolog(LOG_ERR, "Failed to write hypervisor log: "
  82.167 +				       "%d (%s)", errno, strerror(errno));
  82.168  	}
  82.169  
  82.170  	(void)xc_evtchn_unmask(xce_handle, port);
    83.1 --- a/tools/console/daemon/main.c	Wed Feb 13 10:37:18 2008 -0700
    83.2 +++ b/tools/console/daemon/main.c	Thu Feb 14 09:34:27 2008 -0700
    83.3 @@ -35,6 +35,8 @@
    83.4  int log_reload = 0;
    83.5  int log_guest = 0;
    83.6  int log_hv = 0;
    83.7 +int log_time_hv = 0;
    83.8 +int log_time_guest = 0;
    83.9  char *log_dir = NULL;
   83.10  
   83.11  static void handle_hup(int sig)
   83.12 @@ -44,7 +46,7 @@ static void handle_hup(int sig)
   83.13  
   83.14  static void usage(char *name)
   83.15  {
   83.16 -	printf("Usage: %s [-h] [-V] [-v] [-i] [--log=none|guest|hv|all] [--log-dir=DIR] [--pid-file=PATH]\n", name);
   83.17 +	printf("Usage: %s [-h] [-V] [-v] [-i] [--log=none|guest|hv|all] [--log-dir=DIR] [--pid-file=PATH] [-t, --timestamp=none|guest|hv|all]\n", name);
   83.18  }
   83.19  
   83.20  static void version(char *name)
   83.21 @@ -54,7 +56,7 @@ static void version(char *name)
   83.22  
   83.23  int main(int argc, char **argv)
   83.24  {
   83.25 -	const char *sopts = "hVvi";
   83.26 +	const char *sopts = "hVvit:";
   83.27  	struct option lopts[] = {
   83.28  		{ "help", 0, 0, 'h' },
   83.29  		{ "version", 0, 0, 'V' },
   83.30 @@ -63,6 +65,7 @@ int main(int argc, char **argv)
   83.31  		{ "log", 1, 0, 'l' },
   83.32  		{ "log-dir", 1, 0, 'r' },
   83.33  		{ "pid-file", 1, 0, 'p' },
   83.34 +		{ "timestamp", 1, 0, 't' },
   83.35  		{ 0 },
   83.36  	};
   83.37  	bool is_interactive = false;
   83.38 @@ -103,6 +106,19 @@ int main(int argc, char **argv)
   83.39  		case 'p':
   83.40  		        pidfile = strdup(optarg);
   83.41  			break;
   83.42 +		case 't':
   83.43 +			if (!strcmp(optarg, "all")) {
   83.44 +				log_time_hv = 1;
   83.45 +				log_time_guest = 1;
   83.46 +			} else if (!strcmp(optarg, "hv")) {
   83.47 +				log_time_hv = 1;
   83.48 +			} else if (!strcmp(optarg, "guest")) {
   83.49 +				log_time_guest = 1;
   83.50 +			} else if (!strcmp(optarg, "none")) {
   83.51 +				log_time_guest = 0;
   83.52 +				log_time_hv = 0;
   83.53 +			}
   83.54 +			break;
   83.55  		case '?':
   83.56  			fprintf(stderr,
   83.57  				"Try `%s --help' for more information\n",
    84.1 --- a/tools/firmware/hvmloader/acpi/build.c	Wed Feb 13 10:37:18 2008 -0700
    84.2 +++ b/tools/firmware/hvmloader/acpi/build.c	Thu Feb 14 09:34:27 2008 -0700
    84.3 @@ -62,11 +62,18 @@ static int uart_exists(uint16_t uart_bas
    84.4      return ((b == 0) && (c == 0xf));
    84.5  }
    84.6  
    84.7 +static int hpet_exists(unsigned long hpet_base)
    84.8 +{
    84.9 +    uint32_t hpet_id = *(uint32_t *)hpet_base;
   84.10 +    return ((hpet_id >> 16) == 0x8086);
   84.11 +}
   84.12 +
   84.13  static int construct_bios_info_table(uint8_t *buf)
   84.14  {
   84.15      struct bios_info {
   84.16          uint8_t  com1_present:1;
   84.17          uint8_t  com2_present:1;
   84.18 +        uint8_t  hpet_present:1;
   84.19          uint32_t pci_min, pci_len;
   84.20      } *bios_info = (struct bios_info *)buf;
   84.21  
   84.22 @@ -75,6 +82,8 @@ static int construct_bios_info_table(uin
   84.23      bios_info->com1_present = uart_exists(0x3f8);
   84.24      bios_info->com2_present = uart_exists(0x2f8);
   84.25  
   84.26 +    bios_info->hpet_present = hpet_exists(ACPI_HPET_ADDRESS);
   84.27 +
   84.28      bios_info->pci_min = 0xf0000000;
   84.29      bios_info->pci_len = 0x0c000000;
   84.30  
   84.31 @@ -272,9 +281,12 @@ static int construct_secondary_tables(ui
   84.32      }
   84.33  
   84.34      /* HPET. */
   84.35 -    hpet = (struct acpi_20_hpet *)&buf[offset];
   84.36 -    offset += construct_hpet(hpet);
   84.37 -    table_ptrs[nr_tables++] = (unsigned long)hpet;
   84.38 +    if ( hpet_exists(ACPI_HPET_ADDRESS) )
   84.39 +    {
   84.40 +        hpet = (struct acpi_20_hpet *)&buf[offset];
   84.41 +        offset += construct_hpet(hpet);
   84.42 +        table_ptrs[nr_tables++] = (unsigned long)hpet;
   84.43 +    }
   84.44  
   84.45      /* Processor Object SSDT. */
   84.46      table_ptrs[nr_tables++] = (unsigned long)&buf[offset];
    85.1 --- a/tools/firmware/hvmloader/acpi/dsdt.asl	Wed Feb 13 10:37:18 2008 -0700
    85.2 +++ b/tools/firmware/hvmloader/acpi/dsdt.asl	Thu Feb 14 09:34:27 2008 -0700
    85.3 @@ -49,6 +49,7 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
    85.4         Field(BIOS, ByteAcc, NoLock, Preserve) {
    85.5             UAR1, 1,
    85.6             UAR2, 1,
    85.7 +           HPET, 1,
    85.8             Offset(4),
    85.9             PMIN, 32,
   85.10             PLEN, 32
   85.11 @@ -296,6 +297,13 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
   85.12              Device(HPET) {
   85.13                  Name(_HID,  EISAID("PNP0103"))
   85.14                  Name(_UID, 0)
   85.15 +                Method (_STA, 0, NotSerialized) {
   85.16 +                    If(LEqual(\_SB.HPET, 0)) {
   85.17 +                        Return(0x00)
   85.18 +                    } Else {
   85.19 +                        Return(0x0F)
   85.20 +                    }
   85.21 +                }
   85.22                  Name(_CRS, ResourceTemplate() {
   85.23                      DWordMemory(
   85.24                          ResourceConsumer, PosDecode, MinFixed, MaxFixed,
    86.1 --- a/tools/firmware/hvmloader/acpi/dsdt.c	Wed Feb 13 10:37:18 2008 -0700
    86.2 +++ b/tools/firmware/hvmloader/acpi/dsdt.c	Thu Feb 14 09:34:27 2008 -0700
    86.3 @@ -5,15 +5,15 @@
    86.4   * Copyright (C) 2000 - 2006 Intel Corporation
    86.5   * Supports ACPI Specification Revision 3.0a
    86.6   * 
    86.7 - * Compilation of "dsdt.asl" - Mon Jan 21 14:11:31 2008
    86.8 + * Compilation of "dsdt.asl" - Mon Feb 11 13:31:53 2008
    86.9   * 
   86.10   * C source code output
   86.11   *
   86.12   */
   86.13  unsigned char AmlCode[] =
   86.14  {
   86.15 -    0x44,0x53,0x44,0x54,0x6F,0x0E,0x00,0x00,  /* 00000000    "DSDTo..." */
   86.16 -    0x02,0xE1,0x58,0x65,0x6E,0x00,0x00,0x00,  /* 00000008    "..Xen..." */
   86.17 +    0x44,0x53,0x44,0x54,0x8E,0x0E,0x00,0x00,  /* 00000000    "DSDT...." */
   86.18 +    0x02,0x6E,0x58,0x65,0x6E,0x00,0x00,0x00,  /* 00000008    ".nXen..." */
   86.19      0x48,0x56,0x4D,0x00,0x00,0x00,0x00,0x00,  /* 00000010    "HVM....." */
   86.20      0x00,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C,  /* 00000018    "....INTL" */
   86.21      0x07,0x07,0x06,0x20,0x08,0x50,0x4D,0x42,  /* 00000020    "... .PMB" */
   86.22 @@ -27,452 +27,456 @@ unsigned char AmlCode[] =
   86.23      0x04,0x0A,0x07,0x0A,0x07,0x00,0x00,0x08,  /* 00000060    "........" */
   86.24      0x50,0x49,0x43,0x44,0x00,0x14,0x0C,0x5F,  /* 00000068    "PICD..._" */
   86.25      0x50,0x49,0x43,0x01,0x70,0x68,0x50,0x49,  /* 00000070    "PIC.phPI" */
   86.26 -    0x43,0x44,0x10,0x44,0xDF,0x5F,0x53,0x42,  /* 00000078    "CD.D._SB" */
   86.27 +    0x43,0x44,0x10,0x43,0xE1,0x5F,0x53,0x42,  /* 00000078    "CD.C._SB" */
   86.28      0x5F,0x5B,0x80,0x42,0x49,0x4F,0x53,0x00,  /* 00000080    "_[.BIOS." */
   86.29      0x0C,0x00,0xA0,0x0E,0x00,0x0A,0x10,0x5B,  /* 00000088    ".......[" */
   86.30 -    0x81,0x1C,0x42,0x49,0x4F,0x53,0x01,0x55,  /* 00000090    "..BIOS.U" */
   86.31 +    0x81,0x21,0x42,0x49,0x4F,0x53,0x01,0x55,  /* 00000090    ".!BIOS.U" */
   86.32      0x41,0x52,0x31,0x01,0x55,0x41,0x52,0x32,  /* 00000098    "AR1.UAR2" */
   86.33 -    0x01,0x00,0x1E,0x50,0x4D,0x49,0x4E,0x20,  /* 000000A0    "...PMIN " */
   86.34 -    0x50,0x4C,0x45,0x4E,0x20,0x5B,0x82,0x49,  /* 000000A8    "PLEN [.I" */
   86.35 -    0x04,0x4D,0x45,0x4D,0x30,0x08,0x5F,0x48,  /* 000000B0    ".MEM0._H" */
   86.36 -    0x49,0x44,0x0C,0x41,0xD0,0x0C,0x02,0x08,  /* 000000B8    "ID.A...." */
   86.37 -    0x5F,0x43,0x52,0x53,0x11,0x33,0x0A,0x30,  /* 000000C0    "_CRS.3.0" */
   86.38 -    0x8A,0x2B,0x00,0x00,0x0D,0x03,0x00,0x00,  /* 000000C8    ".+......" */
   86.39 -    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  /* 000000D0    "........" */
   86.40 -    0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,  /* 000000D8    "........" */
   86.41 -    0x09,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  /* 000000E0    "........" */
   86.42 +    0x01,0x48,0x50,0x45,0x54,0x01,0x00,0x1D,  /* 000000A0    ".HPET..." */
   86.43 +    0x50,0x4D,0x49,0x4E,0x20,0x50,0x4C,0x45,  /* 000000A8    "PMIN PLE" */
   86.44 +    0x4E,0x20,0x5B,0x82,0x49,0x04,0x4D,0x45,  /* 000000B0    "N [.I.ME" */
   86.45 +    0x4D,0x30,0x08,0x5F,0x48,0x49,0x44,0x0C,  /* 000000B8    "M0._HID." */
   86.46 +    0x41,0xD0,0x0C,0x02,0x08,0x5F,0x43,0x52,  /* 000000C0    "A...._CR" */
   86.47 +    0x53,0x11,0x33,0x0A,0x30,0x8A,0x2B,0x00,  /* 000000C8    "S.3.0.+." */
   86.48 +    0x00,0x0D,0x03,0x00,0x00,0x00,0x00,0x00,  /* 000000D0    "........" */
   86.49 +    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  /* 000000D8    "........" */
   86.50 +    0x00,0x00,0x00,0xFF,0xFF,0x09,0x00,0x00,  /* 000000E0    "........" */
   86.51      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  /* 000000E8    "........" */
   86.52 -    0x0A,0x00,0x00,0x00,0x00,0x00,0x79,0x00,  /* 000000F0    "......y." */
   86.53 -    0x5B,0x82,0x45,0xD7,0x50,0x43,0x49,0x30,  /* 000000F8    "[.E.PCI0" */
   86.54 -    0x08,0x5F,0x48,0x49,0x44,0x0C,0x41,0xD0,  /* 00000100    "._HID.A." */
   86.55 -    0x0A,0x03,0x08,0x5F,0x55,0x49,0x44,0x00,  /* 00000108    "..._UID." */
   86.56 -    0x08,0x5F,0x41,0x44,0x52,0x00,0x08,0x5F,  /* 00000110    "._ADR.._" */
   86.57 -    0x42,0x42,0x4E,0x00,0x14,0x4E,0x0C,0x5F,  /* 00000118    "BBN..N._" */
   86.58 -    0x43,0x52,0x53,0x00,0x08,0x50,0x52,0x54,  /* 00000120    "CRS..PRT" */
   86.59 -    0x30,0x11,0x42,0x07,0x0A,0x6E,0x88,0x0D,  /* 00000128    "0.B..n.." */
   86.60 -    0x00,0x02,0x0E,0x00,0x00,0x00,0x00,0x00,  /* 00000130    "........" */
   86.61 -    0xFF,0x00,0x00,0x00,0x00,0x01,0x47,0x01,  /* 00000138    "......G." */
   86.62 -    0xF8,0x0C,0xF8,0x0C,0x01,0x08,0x88,0x0D,  /* 00000140    "........" */
   86.63 -    0x00,0x01,0x0C,0x03,0x00,0x00,0x00,0x00,  /* 00000148    "........" */
   86.64 -    0xF7,0x0C,0x00,0x00,0xF8,0x0C,0x88,0x0D,  /* 00000150    "........" */
   86.65 -    0x00,0x01,0x0C,0x03,0x00,0x00,0x00,0x0D,  /* 00000158    "........" */
   86.66 -    0xFF,0xFF,0x00,0x00,0x00,0xF3,0x87,0x17,  /* 00000160    "........" */
   86.67 -    0x00,0x00,0x0C,0x03,0x00,0x00,0x00,0x00,  /* 00000168    "........" */
   86.68 -    0x00,0x00,0x0A,0x00,0xFF,0xFF,0x0B,0x00,  /* 00000170    "........" */
   86.69 -    0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,  /* 00000178    "........" */
   86.70 -    0x87,0x17,0x00,0x00,0x0C,0x03,0x00,0x00,  /* 00000180    "........" */
   86.71 -    0x00,0x00,0x00,0x00,0x00,0xF0,0xFF,0xFF,  /* 00000188    "........" */
   86.72 -    0xFF,0xF4,0x00,0x00,0x00,0x00,0x00,0x00,  /* 00000190    "........" */
   86.73 -    0x00,0x05,0x79,0x00,0x8A,0x50,0x52,0x54,  /* 00000198    "..y..PRT" */
   86.74 -    0x30,0x0A,0x5C,0x4D,0x4D,0x49,0x4E,0x8A,  /* 000001A0    "0.\MMIN." */
   86.75 -    0x50,0x52,0x54,0x30,0x0A,0x60,0x4D,0x4D,  /* 000001A8    "PRT0.`MM" */
   86.76 -    0x41,0x58,0x8A,0x50,0x52,0x54,0x30,0x0A,  /* 000001B0    "AX.PRT0." */
   86.77 -    0x68,0x4D,0x4C,0x45,0x4E,0x70,0x50,0x4D,  /* 000001B8    "hMLENpPM" */
   86.78 -    0x49,0x4E,0x4D,0x4D,0x49,0x4E,0x70,0x50,  /* 000001C0    "INMMINpP" */
   86.79 -    0x4C,0x45,0x4E,0x4D,0x4C,0x45,0x4E,0x72,  /* 000001C8    "LENMLENr" */
   86.80 -    0x4D,0x4D,0x49,0x4E,0x4D,0x4C,0x45,0x4E,  /* 000001D0    "MMINMLEN" */
   86.81 -    0x4D,0x4D,0x41,0x58,0x74,0x4D,0x4D,0x41,  /* 000001D8    "MMAXtMMA" */
   86.82 -    0x58,0x01,0x4D,0x4D,0x41,0x58,0xA4,0x50,  /* 000001E0    "X.MMAX.P" */
   86.83 -    0x52,0x54,0x30,0x08,0x42,0x55,0x46,0x41,  /* 000001E8    "RT0.BUFA" */
   86.84 -    0x11,0x09,0x0A,0x06,0x23,0x20,0x0C,0x18,  /* 000001F0    "....# .." */
   86.85 -    0x79,0x00,0x08,0x42,0x55,0x46,0x42,0x11,  /* 000001F8    "y..BUFB." */
   86.86 -    0x09,0x0A,0x06,0x23,0x00,0x00,0x18,0x79,  /* 00000200    "...#...y" */
   86.87 -    0x00,0x8B,0x42,0x55,0x46,0x42,0x01,0x49,  /* 00000208    "..BUFB.I" */
   86.88 -    0x52,0x51,0x56,0x5B,0x82,0x48,0x08,0x4C,  /* 00000210    "RQV[.H.L" */
   86.89 -    0x4E,0x4B,0x41,0x08,0x5F,0x48,0x49,0x44,  /* 00000218    "NKA._HID" */
   86.90 -    0x0C,0x41,0xD0,0x0C,0x0F,0x08,0x5F,0x55,  /* 00000220    ".A...._U" */
   86.91 -    0x49,0x44,0x01,0x14,0x1C,0x5F,0x53,0x54,  /* 00000228    "ID..._ST" */
   86.92 -    0x41,0x00,0x7B,0x50,0x49,0x52,0x41,0x0A,  /* 00000230    "A.{PIRA." */
   86.93 -    0x80,0x60,0xA0,0x08,0x93,0x60,0x0A,0x80,  /* 00000238    ".`...`.." */
   86.94 -    0xA4,0x0A,0x09,0xA1,0x04,0xA4,0x0A,0x0B,  /* 00000240    "........" */
   86.95 -    0x14,0x0B,0x5F,0x50,0x52,0x53,0x00,0xA4,  /* 00000248    ".._PRS.." */
   86.96 -    0x42,0x55,0x46,0x41,0x14,0x11,0x5F,0x44,  /* 00000250    "BUFA.._D" */
   86.97 -    0x49,0x53,0x00,0x7D,0x50,0x49,0x52,0x41,  /* 00000258    "IS.}PIRA" */
   86.98 -    0x0A,0x80,0x50,0x49,0x52,0x41,0x14,0x1A,  /* 00000260    "..PIRA.." */
   86.99 -    0x5F,0x43,0x52,0x53,0x00,0x7B,0x50,0x49,  /* 00000268    "_CRS.{PI" */
  86.100 -    0x52,0x41,0x0A,0x0F,0x60,0x79,0x01,0x60,  /* 00000270    "RA..`y.`" */
  86.101 -    0x49,0x52,0x51,0x56,0xA4,0x42,0x55,0x46,  /* 00000278    "IRQV.BUF" */
  86.102 -    0x42,0x14,0x1B,0x5F,0x53,0x52,0x53,0x01,  /* 00000280    "B.._SRS." */
  86.103 -    0x8B,0x68,0x01,0x49,0x52,0x51,0x31,0x82,  /* 00000288    ".h.IRQ1." */
  86.104 -    0x49,0x52,0x51,0x31,0x60,0x76,0x60,0x70,  /* 00000290    "IRQ1`v`p" */
  86.105 -    0x60,0x50,0x49,0x52,0x41,0x5B,0x82,0x49,  /* 00000298    "`PIRA[.I" */
  86.106 -    0x08,0x4C,0x4E,0x4B,0x42,0x08,0x5F,0x48,  /* 000002A0    ".LNKB._H" */
  86.107 -    0x49,0x44,0x0C,0x41,0xD0,0x0C,0x0F,0x08,  /* 000002A8    "ID.A...." */
  86.108 -    0x5F,0x55,0x49,0x44,0x0A,0x02,0x14,0x1C,  /* 000002B0    "_UID...." */
  86.109 -    0x5F,0x53,0x54,0x41,0x00,0x7B,0x50,0x49,  /* 000002B8    "_STA.{PI" */
  86.110 -    0x52,0x42,0x0A,0x80,0x60,0xA0,0x08,0x93,  /* 000002C0    "RB..`..." */
  86.111 -    0x60,0x0A,0x80,0xA4,0x0A,0x09,0xA1,0x04,  /* 000002C8    "`......." */
  86.112 -    0xA4,0x0A,0x0B,0x14,0x0B,0x5F,0x50,0x52,  /* 000002D0    "....._PR" */
  86.113 -    0x53,0x00,0xA4,0x42,0x55,0x46,0x41,0x14,  /* 000002D8    "S..BUFA." */
  86.114 -    0x11,0x5F,0x44,0x49,0x53,0x00,0x7D,0x50,  /* 000002E0    "._DIS.}P" */
  86.115 -    0x49,0x52,0x42,0x0A,0x80,0x50,0x49,0x52,  /* 000002E8    "IRB..PIR" */
  86.116 -    0x42,0x14,0x1A,0x5F,0x43,0x52,0x53,0x00,  /* 000002F0    "B.._CRS." */
  86.117 -    0x7B,0x50,0x49,0x52,0x42,0x0A,0x0F,0x60,  /* 000002F8    "{PIRB..`" */
  86.118 -    0x79,0x01,0x60,0x49,0x52,0x51,0x56,0xA4,  /* 00000300    "y.`IRQV." */
  86.119 -    0x42,0x55,0x46,0x42,0x14,0x1B,0x5F,0x53,  /* 00000308    "BUFB.._S" */
  86.120 -    0x52,0x53,0x01,0x8B,0x68,0x01,0x49,0x52,  /* 00000310    "RS..h.IR" */
  86.121 -    0x51,0x31,0x82,0x49,0x52,0x51,0x31,0x60,  /* 00000318    "Q1.IRQ1`" */
  86.122 -    0x76,0x60,0x70,0x60,0x50,0x49,0x52,0x42,  /* 00000320    "v`p`PIRB" */
  86.123 -    0x5B,0x82,0x49,0x08,0x4C,0x4E,0x4B,0x43,  /* 00000328    "[.I.LNKC" */
  86.124 -    0x08,0x5F,0x48,0x49,0x44,0x0C,0x41,0xD0,  /* 00000330    "._HID.A." */
  86.125 -    0x0C,0x0F,0x08,0x5F,0x55,0x49,0x44,0x0A,  /* 00000338    "..._UID." */
  86.126 -    0x03,0x14,0x1C,0x5F,0x53,0x54,0x41,0x00,  /* 00000340    "..._STA." */
  86.127 -    0x7B,0x50,0x49,0x52,0x43,0x0A,0x80,0x60,  /* 00000348    "{PIRC..`" */
  86.128 -    0xA0,0x08,0x93,0x60,0x0A,0x80,0xA4,0x0A,  /* 00000350    "...`...." */
  86.129 -    0x09,0xA1,0x04,0xA4,0x0A,0x0B,0x14,0x0B,  /* 00000358    "........" */
  86.130 -    0x5F,0x50,0x52,0x53,0x00,0xA4,0x42,0x55,  /* 00000360    "_PRS..BU" */
  86.131 -    0x46,0x41,0x14,0x11,0x5F,0x44,0x49,0x53,  /* 00000368    "FA.._DIS" */
  86.132 -    0x00,0x7D,0x50,0x49,0x52,0x43,0x0A,0x80,  /* 00000370    ".}PIRC.." */
  86.133 -    0x50,0x49,0x52,0x43,0x14,0x1A,0x5F,0x43,  /* 00000378    "PIRC.._C" */
  86.134 -    0x52,0x53,0x00,0x7B,0x50,0x49,0x52,0x43,  /* 00000380    "RS.{PIRC" */
  86.135 -    0x0A,0x0F,0x60,0x79,0x01,0x60,0x49,0x52,  /* 00000388    "..`y.`IR" */
  86.136 -    0x51,0x56,0xA4,0x42,0x55,0x46,0x42,0x14,  /* 00000390    "QV.BUFB." */
  86.137 -    0x1B,0x5F,0x53,0x52,0x53,0x01,0x8B,0x68,  /* 00000398    "._SRS..h" */
  86.138 -    0x01,0x49,0x52,0x51,0x31,0x82,0x49,0x52,  /* 000003A0    ".IRQ1.IR" */
  86.139 -    0x51,0x31,0x60,0x76,0x60,0x70,0x60,0x50,  /* 000003A8    "Q1`v`p`P" */
  86.140 -    0x49,0x52,0x43,0x5B,0x82,0x49,0x08,0x4C,  /* 000003B0    "IRC[.I.L" */
  86.141 -    0x4E,0x4B,0x44,0x08,0x5F,0x48,0x49,0x44,  /* 000003B8    "NKD._HID" */
  86.142 -    0x0C,0x41,0xD0,0x0C,0x0F,0x08,0x5F,0x55,  /* 000003C0    ".A...._U" */
  86.143 -    0x49,0x44,0x0A,0x04,0x14,0x1C,0x5F,0x53,  /* 000003C8    "ID...._S" */
  86.144 -    0x54,0x41,0x00,0x7B,0x50,0x49,0x52,0x44,  /* 000003D0    "TA.{PIRD" */
  86.145 -    0x0A,0x80,0x60,0xA0,0x08,0x93,0x60,0x0A,  /* 000003D8    "..`...`." */
  86.146 -    0x80,0xA4,0x0A,0x09,0xA1,0x04,0xA4,0x0A,  /* 000003E0    "........" */
  86.147 -    0x0B,0x14,0x0B,0x5F,0x50,0x52,0x53,0x00,  /* 000003E8    "..._PRS." */
  86.148 -    0xA4,0x42,0x55,0x46,0x41,0x14,0x11,0x5F,  /* 000003F0    ".BUFA.._" */
  86.149 -    0x44,0x49,0x53,0x00,0x7D,0x50,0x49,0x52,  /* 000003F8    "DIS.}PIR" */
  86.150 -    0x44,0x0A,0x80,0x50,0x49,0x52,0x44,0x14,  /* 00000400    "D..PIRD." */
  86.151 -    0x1A,0x5F,0x43,0x52,0x53,0x00,0x7B,0x50,  /* 00000408    "._CRS.{P" */
  86.152 -    0x49,0x52,0x44,0x0A,0x0F,0x60,0x79,0x01,  /* 00000410    "IRD..`y." */
  86.153 -    0x60,0x49,0x52,0x51,0x56,0xA4,0x42,0x55,  /* 00000418    "`IRQV.BU" */
  86.154 -    0x46,0x42,0x14,0x1B,0x5F,0x53,0x52,0x53,  /* 00000420    "FB.._SRS" */
  86.155 -    0x01,0x8B,0x68,0x01,0x49,0x52,0x51,0x31,  /* 00000428    "..h.IRQ1" */
  86.156 -    0x82,0x49,0x52,0x51,0x31,0x60,0x76,0x60,  /* 00000430    ".IRQ1`v`" */
  86.157 -    0x70,0x60,0x50,0x49,0x52,0x44,0x5B,0x82,  /* 00000438    "p`PIRD[." */
  86.158 -    0x3A,0x48,0x50,0x45,0x54,0x08,0x5F,0x48,  /* 00000440    ":HPET._H" */
  86.159 -    0x49,0x44,0x0C,0x41,0xD0,0x01,0x03,0x08,  /* 00000448    "ID.A...." */
  86.160 -    0x5F,0x55,0x49,0x44,0x00,0x08,0x5F,0x43,  /* 00000450    "_UID.._C" */
  86.161 -    0x52,0x53,0x11,0x1F,0x0A,0x1C,0x87,0x17,  /* 00000458    "RS......" */
  86.162 -    0x00,0x00,0x0D,0x01,0x00,0x00,0x00,0x00,  /* 00000460    "........" */
  86.163 -    0x00,0x00,0xD0,0xFE,0xFF,0x03,0xD0,0xFE,  /* 00000468    "........" */
  86.164 -    0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,  /* 00000470    "........" */
  86.165 -    0x79,0x00,0x14,0x16,0x5F,0x50,0x52,0x54,  /* 00000478    "y..._PRT" */
  86.166 -    0x00,0xA0,0x0A,0x50,0x49,0x43,0x44,0xA4,  /* 00000480    "...PICD." */
  86.167 -    0x50,0x52,0x54,0x41,0xA4,0x50,0x52,0x54,  /* 00000488    "PRTA.PRT" */
  86.168 -    0x50,0x08,0x50,0x52,0x54,0x50,0x12,0x49,  /* 00000490    "P.PRTP.I" */
  86.169 -    0x36,0x3C,0x12,0x0D,0x04,0x0C,0xFF,0xFF,  /* 00000498    "6<......" */
  86.170 -    0x01,0x00,0x00,0x4C,0x4E,0x4B,0x42,0x00,  /* 000004A0    "...LNKB." */
  86.171 -    0x12,0x0D,0x04,0x0C,0xFF,0xFF,0x01,0x00,  /* 000004A8    "........" */
  86.172 -    0x01,0x4C,0x4E,0x4B,0x43,0x00,0x12,0x0E,  /* 000004B0    ".LNKC..." */
  86.173 -    0x04,0x0C,0xFF,0xFF,0x01,0x00,0x0A,0x02,  /* 000004B8    "........" */
  86.174 -    0x4C,0x4E,0x4B,0x44,0x00,0x12,0x0E,0x04,  /* 000004C0    "LNKD...." */
  86.175 -    0x0C,0xFF,0xFF,0x01,0x00,0x0A,0x03,0x4C,  /* 000004C8    ".......L" */
  86.176 -    0x4E,0x4B,0x41,0x00,0x12,0x0D,0x04,0x0C,  /* 000004D0    "NKA....." */
  86.177 -    0xFF,0xFF,0x02,0x00,0x00,0x4C,0x4E,0x4B,  /* 000004D8    ".....LNK" */
  86.178 -    0x43,0x00,0x12,0x0D,0x04,0x0C,0xFF,0xFF,  /* 000004E0    "C......." */
  86.179 -    0x02,0x00,0x01,0x4C,0x4E,0x4B,0x44,0x00,  /* 000004E8    "...LNKD." */
  86.180 -    0x12,0x0E,0x04,0x0C,0xFF,0xFF,0x02,0x00,  /* 000004F0    "........" */
  86.181 -    0x0A,0x02,0x4C,0x4E,0x4B,0x41,0x00,0x12,  /* 000004F8    "..LNKA.." */
  86.182 -    0x0E,0x04,0x0C,0xFF,0xFF,0x02,0x00,0x0A,  /* 00000500    "........" */
  86.183 -    0x03,0x4C,0x4E,0x4B,0x42,0x00,0x12,0x0D,  /* 00000508    ".LNKB..." */
  86.184 -    0x04,0x0C,0xFF,0xFF,0x03,0x00,0x00,0x4C,  /* 00000510    ".......L" */
  86.185 -    0x4E,0x4B,0x44,0x00,0x12,0x0D,0x04,0x0C,  /* 00000518    "NKD....." */
  86.186 -    0xFF,0xFF,0x03,0x00,0x01,0x4C,0x4E,0x4B,  /* 00000520    ".....LNK" */
  86.187 -    0x41,0x00,0x12,0x0E,0x04,0x0C,0xFF,0xFF,  /* 00000528    "A......." */
  86.188 -    0x03,0x00,0x0A,0x02,0x4C,0x4E,0x4B,0x42,  /* 00000530    "....LNKB" */
  86.189 -    0x00,0x12,0x0E,0x04,0x0C,0xFF,0xFF,0x03,  /* 00000538    "........" */
  86.190 -    0x00,0x0A,0x03,0x4C,0x4E,0x4B,0x43,0x00,  /* 00000540    "...LNKC." */
  86.191 -    0x12,0x0D,0x04,0x0C,0xFF,0xFF,0x04,0x00,  /* 00000548    "........" */
  86.192 -    0x00,0x4C,0x4E,0x4B,0x41,0x00,0x12,0x0D,  /* 00000550    ".LNKA..." */
  86.193 -    0x04,0x0C,0xFF,0xFF,0x04,0x00,0x01,0x4C,  /* 00000558    ".......L" */
  86.194 -    0x4E,0x4B,0x42,0x00,0x12,0x0E,0x04,0x0C,  /* 00000560    "NKB....." */
  86.195 -    0xFF,0xFF,0x04,0x00,0x0A,0x02,0x4C,0x4E,  /* 00000568    "......LN" */
  86.196 -    0x4B,0x43,0x00,0x12,0x0E,0x04,0x0C,0xFF,  /* 00000570    "KC......" */
  86.197 -    0xFF,0x04,0x00,0x0A,0x03,0x4C,0x4E,0x4B,  /* 00000578    ".....LNK" */
  86.198 -    0x44,0x00,0x12,0x0D,0x04,0x0C,0xFF,0xFF,  /* 00000580    "D......." */
  86.199 -    0x05,0x00,0x00,0x4C,0x4E,0x4B,0x42,0x00,  /* 00000588    "...LNKB." */
  86.200 -    0x12,0x0D,0x04,0x0C,0xFF,0xFF,0x05,0x00,  /* 00000590    "........" */
  86.201 -    0x01,0x4C,0x4E,0x4B,0x43,0x00,0x12,0x0E,  /* 00000598    ".LNKC..." */
  86.202 -    0x04,0x0C,0xFF,0xFF,0x05,0x00,0x0A,0x02,  /* 000005A0    "........" */
  86.203 -    0x4C,0x4E,0x4B,0x44,0x00,0x12,0x0E,0x04,  /* 000005A8    "LNKD...." */
  86.204 -    0x0C,0xFF,0xFF,0x05,0x00,0x0A,0x03,0x4C,  /* 000005B0    ".......L" */
  86.205 -    0x4E,0x4B,0x41,0x00,0x12,0x0D,0x04,0x0C,  /* 000005B8    "NKA....." */
  86.206 -    0xFF,0xFF,0x06,0x00,0x00,0x4C,0x4E,0x4B,  /* 000005C0    ".....LNK" */
  86.207 -    0x43,0x00,0x12,0x0D,0x04,0x0C,0xFF,0xFF,  /* 000005C8    "C......." */
  86.208 -    0x06,0x00,0x01,0x4C,0x4E,0x4B,0x44,0x00,  /* 000005D0    "...LNKD." */
  86.209 -    0x12,0x0E,0x04,0x0C,0xFF,0xFF,0x06,0x00,  /* 000005D8    "........" */
  86.210 -    0x0A,0x02,0x4C,0x4E,0x4B,0x41,0x00,0x12,  /* 000005E0    "..LNKA.." */
  86.211 -    0x0E,0x04,0x0C,0xFF,0xFF,0x06,0x00,0x0A,  /* 000005E8    "........" */
  86.212 -    0x03,0x4C,0x4E,0x4B,0x42,0x00,0x12,0x0D,  /* 000005F0    ".LNKB..." */
  86.213 -    0x04,0x0C,0xFF,0xFF,0x07,0x00,0x00,0x4C,  /* 000005F8    ".......L" */
  86.214 -    0x4E,0x4B,0x44,0x00,0x12,0x0D,0x04,0x0C,  /* 00000600    "NKD....." */
  86.215 -    0xFF,0xFF,0x07,0x00,0x01,0x4C,0x4E,0x4B,  /* 00000608    ".....LNK" */
  86.216 -    0x41,0x00,0x12,0x0E,0x04,0x0C,0xFF,0xFF,  /* 00000610    "A......." */
  86.217 -    0x07,0x00,0x0A,0x02,0x4C,0x4E,0x4B,0x42,  /* 00000618    "....LNKB" */
  86.218 -    0x00,0x12,0x0E,0x04,0x0C,0xFF,0xFF,0x07,  /* 00000620    "........" */
  86.219 -    0x00,0x0A,0x03,0x4C,0x4E,0x4B,0x43,0x00,  /* 00000628    "...LNKC." */
  86.220 -    0x12,0x0D,0x04,0x0C,0xFF,0xFF,0x08,0x00,  /* 00000630    "........" */
  86.221 -    0x00,0x4C,0x4E,0x4B,0x41,0x00,0x12,0x0D,  /* 00000638    ".LNKA..." */
  86.222 -    0x04,0x0C,0xFF,0xFF,0x08,0x00,0x01,0x4C,  /* 00000640    ".......L" */
  86.223 -    0x4E,0x4B,0x42,0x00,0x12,0x0E,0x04,0x0C,  /* 00000648    "NKB....." */
  86.224 -    0xFF,0xFF,0x08,0x00,0x0A,0x02,0x4C,0x4E,  /* 00000650    "......LN" */
  86.225 -    0x4B,0x43,0x00,0x12,0x0E,0x04,0x0C,0xFF,  /* 00000658    "KC......" */
  86.226 -    0xFF,0x08,0x00,0x0A,0x03,0x4C,0x4E,0x4B,  /* 00000660    ".....LNK" */
  86.227 -    0x44,0x00,0x12,0x0D,0x04,0x0C,0xFF,0xFF,  /* 00000668    "D......." */
  86.228 -    0x09,0x00,0x00,0x4C,0x4E,0x4B,0x42,0x00,  /* 00000670    "...LNKB." */
  86.229 -    0x12,0x0D,0x04,0x0C,0xFF,0xFF,0x09,0x00,  /* 00000678    "........" */
  86.230 -    0x01,0x4C,0x4E,0x4B,0x43,0x00,0x12,0x0E,  /* 00000680    ".LNKC..." */
  86.231 -    0x04,0x0C,0xFF,0xFF,0x09,0x00,0x0A,0x02,  /* 00000688    "........" */
  86.232 -    0x4C,0x4E,0x4B,0x44,0x00,0x12,0x0E,0x04,  /* 00000690    "LNKD...." */
  86.233 -    0x0C,0xFF,0xFF,0x09,0x00,0x0A,0x03,0x4C,  /* 00000698    ".......L" */
  86.234 -    0x4E,0x4B,0x41,0x00,0x12,0x0D,0x04,0x0C,  /* 000006A0    "NKA....." */
  86.235 -    0xFF,0xFF,0x0A,0x00,0x00,0x4C,0x4E,0x4B,  /* 000006A8    ".....LNK" */
  86.236 -    0x43,0x00,0x12,0x0D,0x04,0x0C,0xFF,0xFF,  /* 000006B0    "C......." */
  86.237 -    0x0A,0x00,0x01,0x4C,0x4E,0x4B,0x44,0x00,  /* 000006B8    "...LNKD." */
  86.238 -    0x12,0x0E,0x04,0x0C,0xFF,0xFF,0x0A,0x00,  /* 000006C0    "........" */
  86.239 -    0x0A,0x02,0x4C,0x4E,0x4B,0x41,0x00,0x12,  /* 000006C8    "..LNKA.." */
  86.240 -    0x0E,0x04,0x0C,0xFF,0xFF,0x0A,0x00,0x0A,  /* 000006D0    "........" */
  86.241 -    0x03,0x4C,0x4E,0x4B,0x42,0x00,0x12,0x0D,  /* 000006D8    ".LNKB..." */
  86.242 -    0x04,0x0C,0xFF,0xFF,0x0B,0x00,0x00,0x4C,  /* 000006E0    ".......L" */
  86.243 -    0x4E,0x4B,0x44,0x00,0x12,0x0D,0x04,0x0C,  /* 000006E8    "NKD....." */
  86.244 -    0xFF,0xFF,0x0B,0x00,0x01,0x4C,0x4E,0x4B,  /* 000006F0    ".....LNK" */
  86.245 -    0x41,0x00,0x12,0x0E,0x04,0x0C,0xFF,0xFF,  /* 000006F8    "A......." */
  86.246 -    0x0B,0x00,0x0A,0x02,0x4C,0x4E,0x4B,0x42,  /* 00000700    "....LNKB" */
  86.247 -    0x00,0x12,0x0E,0x04,0x0C,0xFF,0xFF,0x0B,  /* 00000708    "........" */
  86.248 -    0x00,0x0A,0x03,0x4C,0x4E,0x4B,0x43,0x00,  /* 00000710    "...LNKC." */
  86.249 -    0x12,0x0D,0x04,0x0C,0xFF,0xFF,0x0C,0x00,  /* 00000718    "........" */
  86.250 -    0x00,0x4C,0x4E,0x4B,0x41,0x00,0x12,0x0D,  /* 00000720    ".LNKA..." */
  86.251 -    0x04,0x0C,0xFF,0xFF,0x0C,0x00,0x01,0x4C,  /* 00000728    ".......L" */
  86.252 -    0x4E,0x4B,0x42,0x00,0x12,0x0E,0x04,0x0C,  /* 00000730    "NKB....." */
  86.253 -    0xFF,0xFF,0x0C,0x00,0x0A,0x02,0x4C,0x4E,  /* 00000738    "......LN" */
  86.254 -    0x4B,0x43,0x00,0x12,0x0E,0x04,0x0C,0xFF,  /* 00000740    "KC......" */
  86.255 -    0xFF,0x0C,0x00,0x0A,0x03,0x4C,0x4E,0x4B,  /* 00000748    ".....LNK" */
  86.256 -    0x44,0x00,0x12,0x0D,0x04,0x0C,0xFF,0xFF,  /* 00000750    "D......." */
  86.257 -    0x0D,0x00,0x00,0x4C,0x4E,0x4B,0x42,0x00,  /* 00000758    "...LNKB." */
  86.258 -    0x12,0x0D,0x04,0x0C,0xFF,0xFF,0x0D,0x00,  /* 00000760    "........" */
  86.259 -    0x01,0x4C,0x4E,0x4B,0x43,0x00,0x12,0x0E,  /* 00000768    ".LNKC..." */
  86.260 -    0x04,0x0C,0xFF,0xFF,0x0D,0x00,0x0A,0x02,  /* 00000770    "........" */
  86.261 -    0x4C,0x4E,0x4B,0x44,0x00,0x12,0x0E,0x04,  /* 00000778    "LNKD...." */
  86.262 -    0x0C,0xFF,0xFF,0x0D,0x00,0x0A,0x03,0x4C,  /* 00000780    ".......L" */
  86.263 -    0x4E,0x4B,0x41,0x00,0x12,0x0D,0x04,0x0C,  /* 00000788    "NKA....." */
  86.264 -    0xFF,0xFF,0x0E,0x00,0x00,0x4C,0x4E,0x4B,  /* 00000790    ".....LNK" */
  86.265 -    0x43,0x00,0x12,0x0D,0x04,0x0C,0xFF,0xFF,  /* 00000798    "C......." */
  86.266 -    0x0E,0x00,0x01,0x4C,0x4E,0x4B,0x44,0x00,  /* 000007A0    "...LNKD." */
  86.267 -    0x12,0x0E,0x04,0x0C,0xFF,0xFF,0x0E,0x00,  /* 000007A8    "........" */
  86.268 -    0x0A,0x02,0x4C,0x4E,0x4B,0x41,0x00,0x12,  /* 000007B0    "..LNKA.." */
  86.269 -    0x0E,0x04,0x0C,0xFF,0xFF,0x0E,0x00,0x0A,  /* 000007B8    "........" */
  86.270 -    0x03,0x4C,0x4E,0x4B,0x42,0x00,0x12,0x0D,  /* 000007C0    ".LNKB..." */
  86.271 -    0x04,0x0C,0xFF,0xFF,0x0F,0x00,0x00,0x4C,  /* 000007C8    ".......L" */
  86.272 -    0x4E,0x4B,0x44,0x00,0x12,0x0D,0x04,0x0C,  /* 000007D0    "NKD....." */
  86.273 -    0xFF,0xFF,0x0F,0x00,0x01,0x4C,0x4E,0x4B,  /* 000007D8    ".....LNK" */
  86.274 -    0x41,0x00,0x12,0x0E,0x04,0x0C,0xFF,0xFF,  /* 000007E0    "A......." */
  86.275 -    0x0F,0x00,0x0A,0x02,0x4C,0x4E,0x4B,0x42,  /* 000007E8    "....LNKB" */
  86.276 -    0x00,0x12,0x0E,0x04,0x0C,0xFF,0xFF,0x0F,  /* 000007F0    "........" */
  86.277 -    0x00,0x0A,0x03,0x4C,0x4E,0x4B,0x43,0x00,  /* 000007F8    "...LNKC." */
  86.278 -    0x08,0x50,0x52,0x54,0x41,0x12,0x41,0x2F,  /* 00000800    ".PRTA.A/" */
  86.279 -    0x3C,0x12,0x0B,0x04,0x0C,0xFF,0xFF,0x01,  /* 00000808    "<......." */
  86.280 -    0x00,0x00,0x00,0x0A,0x14,0x12,0x0B,0x04,  /* 00000810    "........" */
  86.281 -    0x0C,0xFF,0xFF,0x01,0x00,0x01,0x00,0x0A,  /* 00000818    "........" */
  86.282 -    0x15,0x12,0x0C,0x04,0x0C,0xFF,0xFF,0x01,  /* 00000820    "........" */
  86.283 -    0x00,0x0A,0x02,0x00,0x0A,0x16,0x12,0x0C,  /* 00000828    "........" */
  86.284 -    0x04,0x0C,0xFF,0xFF,0x01,0x00,0x0A,0x03,  /* 00000830    "........" */
  86.285 -    0x00,0x0A,0x17,0x12,0x0B,0x04,0x0C,0xFF,  /* 00000838    "........" */
  86.286 -    0xFF,0x02,0x00,0x00,0x00,0x0A,0x18,0x12,  /* 00000840    "........" */
  86.287 -    0x0B,0x04,0x0C,0xFF,0xFF,0x02,0x00,0x01,  /* 00000848    "........" */
  86.288 -    0x00,0x0A,0x19,0x12,0x0C,0x04,0x0C,0xFF,  /* 00000850    "........" */
  86.289 -    0xFF,0x02,0x00,0x0A,0x02,0x00,0x0A,0x1A,  /* 00000858    "........" */
  86.290 -    0x12,0x0C,0x04,0x0C,0xFF,0xFF,0x02,0x00,  /* 00000860    "........" */
  86.291 -    0x0A,0x03,0x00,0x0A,0x1B,0x12,0x0B,0x04,  /* 00000868    "........" */
  86.292 -    0x0C,0xFF,0xFF,0x03,0x00,0x00,0x00,0x0A,  /* 00000870    "........" */
  86.293 -    0x1C,0x12,0x0B,0x04,0x0C,0xFF,0xFF,0x03,  /* 00000878    "........" */
  86.294 -    0x00,0x01,0x00,0x0A,0x1D,0x12,0x0C,0x04,  /* 00000880    "........" */
  86.295 -    0x0C,0xFF,0xFF,0x03,0x00,0x0A,0x02,0x00,  /* 00000888    "........" */
  86.296 -    0x0A,0x1E,0x12,0x0C,0x04,0x0C,0xFF,0xFF,  /* 00000890    "........" */
  86.297 -    0x03,0x00,0x0A,0x03,0x00,0x0A,0x1F,0x12,  /* 00000898    "........" */
  86.298 -    0x0B,0x04,0x0C,0xFF,0xFF,0x04,0x00,0x00,  /* 000008A0    "........" */
  86.299 -    0x00,0x0A,0x20,0x12,0x0B,0x04,0x0C,0xFF,  /* 000008A8    ".. ....." */
  86.300 -    0xFF,0x04,0x00,0x01,0x00,0x0A,0x21,0x12,  /* 000008B0    "......!." */
  86.301 -    0x0C,0x04,0x0C,0xFF,0xFF,0x04,0x00,0x0A,  /* 000008B8    "........" */
  86.302 -    0x02,0x00,0x0A,0x22,0x12,0x0C,0x04,0x0C,  /* 000008C0    "..."...." */
  86.303 -    0xFF,0xFF,0x04,0x00,0x0A,0x03,0x00,0x0A,  /* 000008C8    "........" */
  86.304 -    0x23,0x12,0x0B,0x04,0x0C,0xFF,0xFF,0x05,  /* 000008D0    "#......." */
  86.305 -    0x00,0x00,0x00,0x0A,0x24,0x12,0x0B,0x04,  /* 000008D8    "....$..." */
  86.306 -    0x0C,0xFF,0xFF,0x05,0x00,0x01,0x00,0x0A,  /* 000008E0    "........" */
  86.307 -    0x25,0x12,0x0C,0x04,0x0C,0xFF,0xFF,0x05,  /* 000008E8    "%......." */
  86.308 -    0x00,0x0A,0x02,0x00,0x0A,0x26,0x12,0x0C,  /* 000008F0    ".....&.." */
  86.309 -    0x04,0x0C,0xFF,0xFF,0x05,0x00,0x0A,0x03,  /* 000008F8    "........" */
  86.310 -    0x00,0x0A,0x27,0x12,0x0B,0x04,0x0C,0xFF,  /* 00000900    "..'....." */
  86.311 -    0xFF,0x06,0x00,0x00,0x00,0x0A,0x28,0x12,  /* 00000908    "......(." */
  86.312 -    0x0B,0x04,0x0C,0xFF,0xFF,0x06,0x00,0x01,  /* 00000910    "........" */
  86.313 -    0x00,0x0A,0x29,0x12,0x0C,0x04,0x0C,0xFF,  /* 00000918    "..)....." */
  86.314 -    0xFF,0x06,0x00,0x0A,0x02,0x00,0x0A,0x2A,  /* 00000920    ".......*" */
  86.315 -    0x12,0x0C,0x04,0x0C,0xFF,0xFF,0x06,0x00,  /* 00000928    "........" */
  86.316 -    0x0A,0x03,0x00,0x0A,0x2B,0x12,0x0B,0x04,  /* 00000930    "....+..." */
  86.317 -    0x0C,0xFF,0xFF,0x07,0x00,0x00,0x00,0x0A,  /* 00000938    "........" */
  86.318 -    0x2C,0x12,0x0B,0x04,0x0C,0xFF,0xFF,0x07,  /* 00000940    ",......." */
  86.319 -    0x00,0x01,0x00,0x0A,0x2D,0x12,0x0C,0x04,  /* 00000948    "....-..." */
  86.320 -    0x0C,0xFF,0xFF,0x07,0x00,0x0A,0x02,0x00,  /* 00000950    "........" */
  86.321 -    0x0A,0x2E,0x12,0x0C,0x04,0x0C,0xFF,0xFF,  /* 00000958    "........" */
  86.322 -    0x07,0x00,0x0A,0x03,0x00,0x0A,0x2F,0x12,  /* 00000960    "....../." */
  86.323 -    0x0B,0x04,0x0C,0xFF,0xFF,0x08,0x00,0x00,  /* 00000968    "........" */
  86.324 -    0x00,0x0A,0x11,0x12,0x0B,0x04,0x0C,0xFF,  /* 00000970    "........" */
  86.325 -    0xFF,0x08,0x00,0x01,0x00,0x0A,0x12,0x12,  /* 00000978    "........" */
  86.326 -    0x0C,0x04,0x0C,0xFF,0xFF,0x08,0x00,0x0A,  /* 00000980    "........" */
  86.327 -    0x02,0x00,0x0A,0x13,0x12,0x0C,0x04,0x0C,  /* 00000988    "........" */
  86.328 -    0xFF,0xFF,0x08,0x00,0x0A,0x03,0x00,0x0A,  /* 00000990    "........" */
  86.329 -    0x14,0x12,0x0B,0x04,0x0C,0xFF,0xFF,0x09,  /* 00000998    "........" */
  86.330 -    0x00,0x00,0x00,0x0A,0x15,0x12,0x0B,0x04,  /* 000009A0    "........" */
  86.331 -    0x0C,0xFF,0xFF,0x09,0x00,0x01,0x00,0x0A,  /* 000009A8    "........" */
  86.332 -    0x16,0x12,0x0C,0x04,0x0C,0xFF,0xFF,0x09,  /* 000009B0    "........" */
  86.333 -    0x00,0x0A,0x02,0x00,0x0A,0x17,0x12,0x0C,  /* 000009B8    "........" */
  86.334 -    0x04,0x0C,0xFF,0xFF,0x09,0x00,0x0A,0x03,  /* 000009C0    "........" */
  86.335 -    0x00,0x0A,0x18,0x12,0x0B,0x04,0x0C,0xFF,  /* 000009C8    "........" */
  86.336 -    0xFF,0x0A,0x00,0x00,0x00,0x0A,0x19,0x12,  /* 000009D0    "........" */
  86.337 -    0x0B,0x04,0x0C,0xFF,0xFF,0x0A,0x00,0x01,  /* 000009D8    "........" */
  86.338 -    0x00,0x0A,0x1A,0x12,0x0C,0x04,0x0C,0xFF,  /* 000009E0    "........" */
  86.339 -    0xFF,0x0A,0x00,0x0A,0x02,0x00,0x0A,0x1B,  /* 000009E8    "........" */
  86.340 -    0x12,0x0C,0x04,0x0C,0xFF,0xFF,0x0A,0x00,  /* 000009F0    "........" */
  86.341 -    0x0A,0x03,0x00,0x0A,0x1C,0x12,0x0B,0x04,  /* 000009F8    "........" */
  86.342 -    0x0C,0xFF,0xFF,0x0B,0x00,0x00,0x00,0x0A,  /* 00000A00    "........" */
  86.343 -    0x1D,0x12,0x0B,0x04,0x0C,0xFF,0xFF,0x0B,  /* 00000A08    "........" */
  86.344 -    0x00,0x01,0x00,0x0A,0x1E,0x12,0x0C,0x04,  /* 00000A10    "........" */
  86.345 -    0x0C,0xFF,0xFF,0x0B,0x00,0x0A,0x02,0x00,  /* 00000A18    "........" */
  86.346 -    0x0A,0x1F,0x12,0x0C,0x04,0x0C,0xFF,0xFF,  /* 00000A20    "........" */
  86.347 -    0x0B,0x00,0x0A,0x03,0x00,0x0A,0x20,0x12,  /* 00000A28    "...... ." */
  86.348 -    0x0B,0x04,0x0C,0xFF,0xFF,0x0C,0x00,0x00,  /* 00000A30    "........" */
  86.349 -    0x00,0x0A,0x21,0x12,0x0B,0x04,0x0C,0xFF,  /* 00000A38    "..!....." */
  86.350 -    0xFF,0x0C,0x00,0x01,0x00,0x0A,0x22,0x12,  /* 00000A40    "......"." */
  86.351 -    0x0C,0x04,0x0C,0xFF,0xFF,0x0C,0x00,0x0A,  /* 00000A48    "........" */
  86.352 -    0x02,0x00,0x0A,0x23,0x12,0x0C,0x04,0x0C,  /* 00000A50    "...#...." */
  86.353 -    0xFF,0xFF,0x0C,0x00,0x0A,0x03,0x00,0x0A,  /* 00000A58    "........" */
  86.354 -    0x24,0x12,0x0B,0x04,0x0C,0xFF,0xFF,0x0D,  /* 00000A60    "$......." */
  86.355 -    0x00,0x00,0x00,0x0A,0x25,0x12,0x0B,0x04,  /* 00000A68    "....%..." */
  86.356 -    0x0C,0xFF,0xFF,0x0D,0x00,0x01,0x00,0x0A,  /* 00000A70    "........" */
  86.357 -    0x26,0x12,0x0C,0x04,0x0C,0xFF,0xFF,0x0D,  /* 00000A78    "&......." */
  86.358 -    0x00,0x0A,0x02,0x00,0x0A,0x27,0x12,0x0C,  /* 00000A80    ".....'.." */
  86.359 -    0x04,0x0C,0xFF,0xFF,0x0D,0x00,0x0A,0x03,  /* 00000A88    "........" */
  86.360 -    0x00,0x0A,0x28,0x12,0x0B,0x04,0x0C,0xFF,  /* 00000A90    "..(....." */
  86.361 -    0xFF,0x0E,0x00,0x00,0x00,0x0A,0x29,0x12,  /* 00000A98    "......)." */
  86.362 -    0x0B,0x04,0x0C,0xFF,0xFF,0x0E,0x00,0x01,  /* 00000AA0    "........" */
  86.363 -    0x00,0x0A,0x2A,0x12,0x0C,0x04,0x0C,0xFF,  /* 00000AA8    "..*....." */
  86.364 -    0xFF,0x0E,0x00,0x0A,0x02,0x00,0x0A,0x2B,  /* 00000AB0    ".......+" */
  86.365 -    0x12,0x0C,0x04,0x0C,0xFF,0xFF,0x0E,0x00,  /* 00000AB8    "........" */
  86.366 -    0x0A,0x03,0x00,0x0A,0x2C,0x12,0x0B,0x04,  /* 00000AC0    "....,..." */
  86.367 -    0x0C,0xFF,0xFF,0x0F,0x00,0x00,0x00,0x0A,  /* 00000AC8    "........" */
  86.368 -    0x2D,0x12,0x0B,0x04,0x0C,0xFF,0xFF,0x0F,  /* 00000AD0    "-......." */
  86.369 -    0x00,0x01,0x00,0x0A,0x2E,0x12,0x0C,0x04,  /* 00000AD8    "........" */
  86.370 -    0x0C,0xFF,0xFF,0x0F,0x00,0x0A,0x02,0x00,  /* 00000AE0    "........" */
  86.371 -    0x0A,0x2F,0x12,0x0C,0x04,0x0C,0xFF,0xFF,  /* 00000AE8    "./......" */
  86.372 -    0x0F,0x00,0x0A,0x03,0x00,0x0A,0x10,0x5B,  /* 00000AF0    ".......[" */
  86.373 -    0x82,0x46,0x37,0x49,0x53,0x41,0x5F,0x08,  /* 00000AF8    ".F7ISA_." */
  86.374 -    0x5F,0x41,0x44,0x52,0x0C,0x00,0x00,0x01,  /* 00000B00    "_ADR...." */
  86.375 -    0x00,0x5B,0x80,0x50,0x49,0x52,0x51,0x02,  /* 00000B08    ".[.PIRQ." */
  86.376 -    0x0A,0x60,0x0A,0x04,0x10,0x2E,0x5C,0x00,  /* 00000B10    ".`....\." */
  86.377 -    0x5B,0x81,0x29,0x5C,0x2F,0x04,0x5F,0x53,  /* 00000B18    "[.)\/._S" */
  86.378 -    0x42,0x5F,0x50,0x43,0x49,0x30,0x49,0x53,  /* 00000B20    "B_PCI0IS" */
  86.379 -    0x41,0x5F,0x50,0x49,0x52,0x51,0x01,0x50,  /* 00000B28    "A_PIRQ.P" */
  86.380 -    0x49,0x52,0x41,0x08,0x50,0x49,0x52,0x42,  /* 00000B30    "IRA.PIRB" */
  86.381 -    0x08,0x50,0x49,0x52,0x43,0x08,0x50,0x49,  /* 00000B38    ".PIRC.PI" */
  86.382 -    0x52,0x44,0x08,0x5B,0x82,0x46,0x0B,0x53,  /* 00000B40    "RD.[.F.S" */
  86.383 -    0x59,0x53,0x52,0x08,0x5F,0x48,0x49,0x44,  /* 00000B48    "YSR._HID" */
  86.384 -    0x0C,0x41,0xD0,0x0C,0x02,0x08,0x5F,0x55,  /* 00000B50    ".A...._U" */
  86.385 -    0x49,0x44,0x01,0x08,0x43,0x52,0x53,0x5F,  /* 00000B58    "ID..CRS_" */
  86.386 -    0x11,0x4E,0x08,0x0A,0x8A,0x47,0x01,0x10,  /* 00000B60    ".N...G.." */
  86.387 -    0x00,0x10,0x00,0x00,0x10,0x47,0x01,0x22,  /* 00000B68    ".....G."" */
  86.388 -    0x00,0x22,0x00,0x00,0x0C,0x47,0x01,0x30,  /* 00000B70    "."...G.0" */
  86.389 -    0x00,0x30,0x00,0x00,0x10,0x47,0x01,0x44,  /* 00000B78    ".0...G.D" */
  86.390 -    0x00,0x44,0x00,0x00,0x1C,0x47,0x01,0x62,  /* 00000B80    ".D...G.b" */
  86.391 -    0x00,0x62,0x00,0x00,0x02,0x47,0x01,0x65,  /* 00000B88    ".b...G.e" */
  86.392 -    0x00,0x65,0x00,0x00,0x0B,0x47,0x01,0x72,  /* 00000B90    ".e...G.r" */
  86.393 -    0x00,0x72,0x00,0x00,0x0E,0x47,0x01,0x80,  /* 00000B98    ".r...G.." */
  86.394 -    0x00,0x80,0x00,0x00,0x01,0x47,0x01,0x84,  /* 00000BA0    ".....G.." */
  86.395 -    0x00,0x84,0x00,0x00,0x03,0x47,0x01,0x88,  /* 00000BA8    ".....G.." */
  86.396 -    0x00,0x88,0x00,0x00,0x01,0x47,0x01,0x8C,  /* 00000BB0    ".....G.." */
  86.397 -    0x00,0x8C,0x00,0x00,0x03,0x47,0x01,0x90,  /* 00000BB8    ".....G.." */
  86.398 -    0x00,0x90,0x00,0x00,0x10,0x47,0x01,0xA2,  /* 00000BC0    ".....G.." */
  86.399 -    0x00,0xA2,0x00,0x00,0x1C,0x47,0x01,0xE0,  /* 00000BC8    ".....G.." */
  86.400 -    0x00,0xE0,0x00,0x00,0x10,0x47,0x01,0xA0,  /* 00000BD0    ".....G.." */
  86.401 -    0x08,0xA0,0x08,0x00,0x04,0x47,0x01,0xC0,  /* 00000BD8    ".....G.." */
  86.402 -    0x0C,0xC0,0x0C,0x00,0x10,0x47,0x01,0xD0,  /* 00000BE0    ".....G.." */
  86.403 -    0x04,0xD0,0x04,0x00,0x02,0x79,0x00,0x14,  /* 00000BE8    ".....y.." */
  86.404 -    0x0B,0x5F,0x43,0x52,0x53,0x00,0xA4,0x43,  /* 00000BF0    "._CRS..C" */
  86.405 -    0x52,0x53,0x5F,0x5B,0x82,0x2B,0x50,0x49,  /* 00000BF8    "RS_[.+PI" */
  86.406 -    0x43,0x5F,0x08,0x5F,0x48,0x49,0x44,0x0B,  /* 00000C00    "C_._HID." */
  86.407 -    0x41,0xD0,0x08,0x5F,0x43,0x52,0x53,0x11,  /* 00000C08    "A.._CRS." */
  86.408 -    0x18,0x0A,0x15,0x47,0x01,0x20,0x00,0x20,  /* 00000C10    "...G. . " */
  86.409 -    0x00,0x01,0x02,0x47,0x01,0xA0,0x00,0xA0,  /* 00000C18    "...G...." */
  86.410 -    0x00,0x01,0x02,0x22,0x04,0x00,0x79,0x00,  /* 00000C20    "..."..y." */
  86.411 -    0x5B,0x82,0x47,0x05,0x44,0x4D,0x41,0x30,  /* 00000C28    "[.G.DMA0" */
  86.412 -    0x08,0x5F,0x48,0x49,0x44,0x0C,0x41,0xD0,  /* 00000C30    "._HID.A." */
  86.413 -    0x02,0x00,0x08,0x5F,0x43,0x52,0x53,0x11,  /* 00000C38    "..._CRS." */
  86.414 -    0x41,0x04,0x0A,0x3D,0x2A,0x10,0x04,0x47,  /* 00000C40    "A..=*..G" */
  86.415 -    0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x47,  /* 00000C48    ".......G" */
  86.416 -    0x01,0x81,0x00,0x81,0x00,0x00,0x03,0x47,  /* 00000C50    ".......G" */
  86.417 -    0x01,0x87,0x00,0x87,0x00,0x00,0x01,0x47,  /* 00000C58    ".......G" */
  86.418 -    0x01,0x89,0x00,0x89,0x00,0x00,0x03,0x47,  /* 00000C60    ".......G" */
  86.419 -    0x01,0x8F,0x00,0x8F,0x00,0x00,0x01,0x47,  /* 00000C68    ".......G" */
  86.420 -    0x01,0xC0,0x00,0xC0,0x00,0x00,0x20,0x47,  /* 00000C70    "...... G" */
  86.421 -    0x01,0x80,0x04,0x80,0x04,0x00,0x10,0x79,  /* 00000C78    ".......y" */
  86.422 -    0x00,0x5B,0x82,0x25,0x54,0x4D,0x52,0x5F,  /* 00000C80    ".[.%TMR_" */
  86.423 -    0x08,0x5F,0x48,0x49,0x44,0x0C,0x41,0xD0,  /* 00000C88    "._HID.A." */
  86.424 -    0x01,0x00,0x08,0x5F,0x43,0x52,0x53,0x11,  /* 00000C90    "..._CRS." */
  86.425 -    0x10,0x0A,0x0D,0x47,0x01,0x40,0x00,0x40,  /* 00000C98    "...G.@.@" */
  86.426 -    0x00,0x00,0x04,0x22,0x01,0x00,0x79,0x00,  /* 00000CA0    "..."..y." */
  86.427 -    0x5B,0x82,0x25,0x52,0x54,0x43,0x5F,0x08,  /* 00000CA8    "[.%RTC_." */
  86.428 -    0x5F,0x48,0x49,0x44,0x0C,0x41,0xD0,0x0B,  /* 00000CB0    "_HID.A.." */
  86.429 -    0x00,0x08,0x5F,0x43,0x52,0x53,0x11,0x10,  /* 00000CB8    ".._CRS.." */
  86.430 -    0x0A,0x0D,0x47,0x01,0x70,0x00,0x70,0x00,  /* 00000CC0    "..G.p.p." */
  86.431 -    0x00,0x02,0x22,0x00,0x01,0x79,0x00,0x5B,  /* 00000CC8    ".."..y.[" */
  86.432 -    0x82,0x22,0x53,0x50,0x4B,0x52,0x08,0x5F,  /* 00000CD0    "."SPKR._" */
  86.433 -    0x48,0x49,0x44,0x0C,0x41,0xD0,0x08,0x00,  /* 00000CD8    "HID.A..." */
  86.434 -    0x08,0x5F,0x43,0x52,0x53,0x11,0x0D,0x0A,  /* 00000CE0    "._CRS..." */
  86.435 -    0x0A,0x47,0x01,0x61,0x00,0x61,0x00,0x00,  /* 00000CE8    ".G.a.a.." */
  86.436 -    0x01,0x79,0x00,0x5B,0x82,0x31,0x50,0x53,  /* 00000CF0    ".y.[.1PS" */
  86.437 -    0x32,0x4D,0x08,0x5F,0x48,0x49,0x44,0x0C,  /* 00000CF8    "2M._HID." */
  86.438 -    0x41,0xD0,0x0F,0x13,0x08,0x5F,0x43,0x49,  /* 00000D00    "A...._CI" */
  86.439 -    0x44,0x0C,0x41,0xD0,0x0F,0x13,0x14,0x09,  /* 00000D08    "D.A....." */
  86.440 -    0x5F,0x53,0x54,0x41,0x00,0xA4,0x0A,0x0F,  /* 00000D10    "_STA...." */
  86.441 -    0x08,0x5F,0x43,0x52,0x53,0x11,0x08,0x0A,  /* 00000D18    "._CRS..." */
  86.442 -    0x05,0x22,0x00,0x10,0x79,0x00,0x5B,0x82,  /* 00000D20    "."..y.[." */
  86.443 -    0x42,0x04,0x50,0x53,0x32,0x4B,0x08,0x5F,  /* 00000D28    "B.PS2K._" */
  86.444 -    0x48,0x49,0x44,0x0C,0x41,0xD0,0x03,0x03,  /* 00000D30    "HID.A..." */
  86.445 -    0x08,0x5F,0x43,0x49,0x44,0x0C,0x41,0xD0,  /* 00000D38    "._CID.A." */
  86.446 -    0x03,0x0B,0x14,0x09,0x5F,0x53,0x54,0x41,  /* 00000D40    "...._STA" */
  86.447 -    0x00,0xA4,0x0A,0x0F,0x08,0x5F,0x43,0x52,  /* 00000D48    "....._CR" */
  86.448 -    0x53,0x11,0x18,0x0A,0x15,0x47,0x01,0x60,  /* 00000D50    "S....G.`" */
  86.449 -    0x00,0x60,0x00,0x00,0x01,0x47,0x01,0x64,  /* 00000D58    ".`...G.d" */
  86.450 -    0x00,0x64,0x00,0x00,0x01,0x22,0x02,0x00,  /* 00000D60    ".d...".." */
  86.451 -    0x79,0x00,0x5B,0x82,0x3A,0x46,0x44,0x43,  /* 00000D68    "y.[.:FDC" */
  86.452 -    0x30,0x08,0x5F,0x48,0x49,0x44,0x0C,0x41,  /* 00000D70    "0._HID.A" */
  86.453 -    0xD0,0x07,0x00,0x14,0x09,0x5F,0x53,0x54,  /* 00000D78    "....._ST" */
  86.454 -    0x41,0x00,0xA4,0x0A,0x0F,0x08,0x5F,0x43,  /* 00000D80    "A....._C" */
  86.455 -    0x52,0x53,0x11,0x1B,0x0A,0x18,0x47,0x01,  /* 00000D88    "RS....G." */
  86.456 -    0xF0,0x03,0xF0,0x03,0x01,0x06,0x47,0x01,  /* 00000D90    "......G." */
  86.457 -    0xF7,0x03,0xF7,0x03,0x01,0x01,0x22,0x40,  /* 00000D98    "......"@" */
  86.458 -    0x00,0x2A,0x04,0x00,0x79,0x00,0x5B,0x82,  /* 00000DA0    ".*..y.[." */
  86.459 -    0x46,0x04,0x55,0x41,0x52,0x31,0x08,0x5F,  /* 00000DA8    "F.UAR1._" */
  86.460 -    0x48,0x49,0x44,0x0C,0x41,0xD0,0x05,0x01,  /* 00000DB0    "HID.A..." */
  86.461 -    0x08,0x5F,0x55,0x49,0x44,0x01,0x14,0x19,  /* 00000DB8    "._UID..." */
  86.462 -    0x5F,0x53,0x54,0x41,0x00,0xA0,0x0D,0x93,  /* 00000DC0    "_STA...." */
  86.463 -    0x5E,0x5E,0x5E,0x5E,0x55,0x41,0x52,0x31,  /* 00000DC8    "^^^^UAR1" */
  86.464 -    0x00,0xA4,0x00,0xA1,0x04,0xA4,0x0A,0x0F,  /* 00000DD0    "........" */
  86.465 -    0x08,0x5F,0x43,0x52,0x53,0x11,0x10,0x0A,  /* 00000DD8    "._CRS..." */
  86.466 -    0x0D,0x47,0x01,0xF8,0x03,0xF8,0x03,0x08,  /* 00000DE0    ".G......" */
  86.467 -    0x08,0x22,0x10,0x00,0x79,0x00,0x5B,0x82,  /* 00000DE8    "."..y.[." */
  86.468 -    0x47,0x04,0x55,0x41,0x52,0x32,0x08,0x5F,  /* 00000DF0    "G.UAR2._" */
  86.469 -    0x48,0x49,0x44,0x0C,0x41,0xD0,0x05,0x01,  /* 00000DF8    "HID.A..." */
  86.470 -    0x08,0x5F,0x55,0x49,0x44,0x0A,0x02,0x14,  /* 00000E00    "._UID..." */
  86.471 -    0x19,0x5F,0x53,0x54,0x41,0x00,0xA0,0x0D,  /* 00000E08    "._STA..." */
  86.472 -    0x93,0x5E,0x5E,0x5E,0x5E,0x55,0x41,0x52,  /* 00000E10    ".^^^^UAR" */
  86.473 -    0x32,0x00,0xA4,0x00,0xA1,0x04,0xA4,0x0A,  /* 00000E18    "2......." */
  86.474 -    0x0F,0x08,0x5F,0x43,0x52,0x53,0x11,0x10,  /* 00000E20    ".._CRS.." */
  86.475 -    0x0A,0x0D,0x47,0x01,0xF8,0x02,0xF8,0x02,  /* 00000E28    "..G....." */
  86.476 -    0x08,0x08,0x22,0x08,0x00,0x79,0x00,0x5B,  /* 00000E30    ".."..y.[" */
  86.477 -    0x82,0x36,0x4C,0x54,0x50,0x31,0x08,0x5F,  /* 00000E38    ".6LTP1._" */
  86.478 -    0x48,0x49,0x44,0x0C,0x41,0xD0,0x04,0x00,  /* 00000E40    "HID.A..." */
  86.479 -    0x08,0x5F,0x55,0x49,0x44,0x0A,0x02,0x14,  /* 00000E48    "._UID..." */
  86.480 -    0x09,0x5F,0x53,0x54,0x41,0x00,0xA4,0x0A,  /* 00000E50    "._STA..." */
  86.481 -    0x0F,0x08,0x5F,0x43,0x52,0x53,0x11,0x10,  /* 00000E58    ".._CRS.." */
  86.482 -    0x0A,0x0D,0x47,0x01,0x78,0x03,0x78,0x03,  /* 00000E60    "..G.x.x." */
  86.483 -    0x08,0x08,0x22,0x80,0x00,0x79,0x00,
  86.484 +    0x00,0x00,0x00,0x00,0x00,0x0A,0x00,0x00,  /* 000000F0    "........" */
  86.485 +    0x00,0x00,0x00,0x79,0x00,0x5B,0x82,0x4F,  /* 000000F8    "...y.[.O" */
  86.486 +    0xD8,0x50,0x43,0x49,0x30,0x08,0x5F,0x48,  /* 00000100    ".PCI0._H" */
  86.487 +    0x49,0x44,0x0C,0x41,0xD0,0x0A,0x03,0x08,  /* 00000108    "ID.A...." */
  86.488 +    0x5F,0x55,0x49,0x44,0x00,0x08,0x5F,0x41,  /* 00000110    "_UID.._A" */
  86.489 +    0x44,0x52,0x00,0x08,0x5F,0x42,0x42,0x4E,  /* 00000118    "DR.._BBN" */
  86.490 +    0x00,0x14,0x4E,0x0C,0x5F,0x43,0x52,0x53,  /* 00000120    "..N._CRS" */
  86.491 +    0x00,0x08,0x50,0x52,0x54,0x30,0x11,0x42,  /* 00000128    "..PRT0.B" */
  86.492 +    0x07,0x0A,0x6E,0x88,0x0D,0x00,0x02,0x0E,  /* 00000130    "..n....." */
  86.493 +    0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,  /* 00000138    "........" */
  86.494 +    0x00,0x00,0x01,0x47,0x01,0xF8,0x0C,0xF8,  /* 00000140    "...G...." */
  86.495 +    0x0C,0x01,0x08,0x88,0x0D,0x00,0x01,0x0C,  /* 00000148    "........" */
  86.496 +    0x03,0x00,0x00,0x00,0x00,0xF7,0x0C,0x00,  /* 00000150    "........" */
  86.497 +    0x00,0xF8,0x0C,0x88,0x0D,0x00,0x01,0x0C,  /* 00000158    "........" */
  86.498 +    0x03,0x00,0x00,0x00,0x0D,0xFF,0xFF,0x00,  /* 00000160    "........" */
  86.499 +    0x00,0x00,0xF3,0x87,0x17,0x00,0x00,0x0C,  /* 00000168    "........" */
  86.500 +    0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x0A,  /* 00000170    "........" */
  86.501 +    0x00,0xFF,0xFF,0x0B,0x00,0x00,0x00,0x00,  /* 00000178    "........" */
  86.502 +    0x00,0x00,0x00,0x02,0x00,0x87,0x17,0x00,  /* 00000180    "........" */
  86.503 +    0x00,0x0C,0x03,0x00,0x00,0x00,0x00,0x00,  /* 00000188    "........" */
  86.504 +    0x00,0x00,0xF0,0xFF,0xFF,0xFF,0xF4,0x00,  /* 00000190    "........" */
  86.505 +    0x00,0x00,0x00,0x00,0x00,0x00,0x05,0x79,  /* 00000198    ".......y" */
  86.506 +    0x00,0x8A,0x50,0x52,0x54,0x30,0x0A,0x5C,  /* 000001A0    "..PRT0.\" */
  86.507 +    0x4D,0x4D,0x49,0x4E,0x8A,0x50,0x52,0x54,  /* 000001A8    "MMIN.PRT" */
  86.508 +    0x30,0x0A,0x60,0x4D,0x4D,0x41,0x58,0x8A,  /* 000001B0    "0.`MMAX." */
  86.509 +    0x50,0x52,0x54,0x30,0x0A,0x68,0x4D,0x4C,  /* 000001B8    "PRT0.hML" */
  86.510 +    0x45,0x4E,0x70,0x50,0x4D,0x49,0x4E,0x4D,  /* 000001C0    "ENpPMINM" */
  86.511 +    0x4D,0x49,0x4E,0x70,0x50,0x4C,0x45,0x4E,  /* 000001C8    "MINpPLEN" */
  86.512 +    0x4D,0x4C,0x45,0x4E,0x72,0x4D,0x4D,0x49,  /* 000001D0    "MLENrMMI" */
  86.513 +    0x4E,0x4D,0x4C,0x45,0x4E,0x4D,0x4D,0x41,  /* 000001D8    "NMLENMMA" */
  86.514 +    0x58,0x74,0x4D,0x4D,0x41,0x58,0x01,0x4D,  /* 000001E0    "XtMMAX.M" */
  86.515 +    0x4D,0x41,0x58,0xA4,0x50,0x52,0x54,0x30,  /* 000001E8    "MAX.PRT0" */
  86.516 +    0x08,0x42,0x55,0x46,0x41,0x11,0x09,0x0A,  /* 000001F0    ".BUFA..." */
  86.517 +    0x06,0x23,0x20,0x0C,0x18,0x79,0x00,0x08,  /* 000001F8    ".# ..y.." */
  86.518 +    0x42,0x55,0x46,0x42,0x11,0x09,0x0A,0x06,  /* 00000200    "BUFB...." */
  86.519 +    0x23,0x00,0x00,0x18,0x79,0x00,0x8B,0x42,  /* 00000208    "#...y..B" */
  86.520 +    0x55,0x46,0x42,0x01,0x49,0x52,0x51,0x56,  /* 00000210    "UFB.IRQV" */
  86.521 +    0x5B,0x82,0x48,0x08,0x4C,0x4E,0x4B,0x41,  /* 00000218    "[.H.LNKA" */
  86.522 +    0x08,0x5F,0x48,0x49,0x44,0x0C,0x41,0xD0,  /* 00000220    "._HID.A." */
  86.523 +    0x0C,0x0F,0x08,0x5F,0x55,0x49,0x44,0x01,  /* 00000228    "..._UID." */
  86.524 +    0x14,0x1C,0x5F,0x53,0x54,0x41,0x00,0x7B,  /* 00000230    ".._STA.{" */
  86.525 +    0x50,0x49,0x52,0x41,0x0A,0x80,0x60,0xA0,  /* 00000238    "PIRA..`." */
  86.526 +    0x08,0x93,0x60,0x0A,0x80,0xA4,0x0A,0x09,  /* 00000240    "..`....." */
  86.527 +    0xA1,0x04,0xA4,0x0A,0x0B,0x14,0x0B,0x5F,  /* 00000248    "......._" */
  86.528 +    0x50,0x52,0x53,0x00,0xA4,0x42,0x55,0x46,  /* 00000250    "PRS..BUF" */
  86.529 +    0x41,0x14,0x11,0x5F,0x44,0x49,0x53,0x00,  /* 00000258    "A.._DIS." */
  86.530 +    0x7D,0x50,0x49,0x52,0x41,0x0A,0x80,0x50,  /* 00000260    "}PIRA..P" */
  86.531 +    0x49,0x52,0x41,0x14,0x1A,0x5F,0x43,0x52,  /* 00000268    "IRA.._CR" */
  86.532 +    0x53,0x00,0x7B,0x50,0x49,0x52,0x41,0x0A,  /* 00000270    "S.{PIRA." */
  86.533 +    0x0F,0x60,0x79,0x01,0x60,0x49,0x52,0x51,  /* 00000278    ".`y.`IRQ" */
  86.534 +    0x56,0xA4,0x42,0x55,0x46,0x42,0x14,0x1B,  /* 00000280    "V.BUFB.." */
  86.535 +    0x5F,0x53,0x52,0x53,0x01,0x8B,0x68,0x01,  /* 00000288    "_SRS..h." */
  86.536 +    0x49,0x52,0x51,0x31,0x82,0x49,0x52,0x51,  /* 00000290    "IRQ1.IRQ" */
  86.537 +    0x31,0x60,0x76,0x60,0x70,0x60,0x50,0x49,  /* 00000298    "1`v`p`PI" */
  86.538 +    0x52,0x41,0x5B,0x82,0x49,0x08,0x4C,0x4E,  /* 000002A0    "RA[.I.LN" */
  86.539 +    0x4B,0x42,0x08,0x5F,0x48,0x49,0x44,0x0C,  /* 000002A8    "KB._HID." */
  86.540 +    0x41,0xD0,0x0C,0x0F,0x08,0x5F,0x55,0x49,  /* 000002B0    "A...._UI" */
  86.541 +    0x44,0x0A,0x02,0x14,0x1C,0x5F,0x53,0x54,  /* 000002B8    "D...._ST" */
  86.542 +    0x41,0x00,0x7B,0x50,0x49,0x52,0x42,0x0A,  /* 000002C0    "A.{PIRB." */
  86.543 +    0x80,0x60,0xA0,0x08,0x93,0x60,0x0A,0x80,  /* 000002C8    ".`...`.." */
  86.544 +    0xA4,0x0A,0x09,0xA1,0x04,0xA4,0x0A,0x0B,  /* 000002D0    "........" */
  86.545 +    0x14,0x0B,0x5F,0x50,0x52,0x53,0x00,0xA4,  /* 000002D8    ".._PRS.." */
  86.546 +    0x42,0x55,0x46,0x41,0x14,0x11,0x5F,0x44,  /* 000002E0    "BUFA.._D" */
  86.547 +    0x49,0x53,0x00,0x7D,0x50,0x49,0x52,0x42,  /* 000002E8    "IS.}PIRB" */
  86.548 +    0x0A,0x80,0x50,0x49,0x52,0x42,0x14,0x1A,  /* 000002F0    "..PIRB.." */
  86.549 +    0x5F,0x43,0x52,0x53,0x00,0x7B,0x50,0x49,  /* 000002F8    "_CRS.{PI" */
  86.550 +    0x52,0x42,0x0A,0x0F,0x60,0x79,0x01,0x60,  /* 00000300    "RB..`y.`" */
  86.551 +    0x49,0x52,0x51,0x56,0xA4,0x42,0x55,0x46,  /* 00000308    "IRQV.BUF" */
  86.552 +    0x42,0x14,0x1B,0x5F,0x53,0x52,0x53,0x01,  /* 00000310    "B.._SRS." */
  86.553 +    0x8B,0x68,0x01,0x49,0x52,0x51,0x31,0x82,  /* 00000318    ".h.IRQ1." */
  86.554 +    0x49,0x52,0x51,0x31,0x60,0x76,0x60,0x70,  /* 00000320    "IRQ1`v`p" */
  86.555 +    0x60,0x50,0x49,0x52,0x42,0x5B,0x82,0x49,  /* 00000328    "`PIRB[.I" */
  86.556 +    0x08,0x4C,0x4E,0x4B,0x43,0x08,0x5F,0x48,  /* 00000330    ".LNKC._H" */
  86.557 +    0x49,0x44,0x0C,0x41,0xD0,0x0C,0x0F,0x08,  /* 00000338    "ID.A...." */
  86.558 +    0x5F,0x55,0x49,0x44,0x0A,0x03,0x14,0x1C,  /* 00000340    "_UID...." */
  86.559 +    0x5F,0x53,0x54,0x41,0x00,0x7B,0x50,0x49,  /* 00000348    "_STA.{PI" */
  86.560 +    0x52,0x43,0x0A,0x80,0x60,0xA0,0x08,0x93,  /* 00000350    "RC..`..." */
  86.561 +    0x60,0x0A,0x80,0xA4,0x0A,0x09,0xA1,0x04,  /* 00000358    "`......." */
  86.562 +    0xA4,0x0A,0x0B,0x14,0x0B,0x5F,0x50,0x52,  /* 00000360    "....._PR" */
  86.563 +    0x53,0x00,0xA4,0x42,0x55,0x46,0x41,0x14,  /* 00000368    "S..BUFA." */
  86.564 +    0x11,0x5F,0x44,0x49,0x53,0x00,0x7D,0x50,  /* 00000370    "._DIS.}P" */
  86.565 +    0x49,0x52,0x43,0x0A,0x80,0x50,0x49,0x52,  /* 00000378    "IRC..PIR" */
  86.566 +    0x43,0x14,0x1A,0x5F,0x43,0x52,0x53,0x00,  /* 00000380    "C.._CRS." */
  86.567 +    0x7B,0x50,0x49,0x52,0x43,0x0A,0x0F,0x60,  /* 00000388    "{PIRC..`" */
  86.568 +    0x79,0x01,0x60,0x49,0x52,0x51,0x56,0xA4,  /* 00000390    "y.`IRQV." */
  86.569 +    0x42,0x55,0x46,0x42,0x14,0x1B,0x5F,0x53,  /* 00000398    "BUFB.._S" */
  86.570 +    0x52,0x53,0x01,0x8B,0x68,0x01,0x49,0x52,  /* 000003A0    "RS..h.IR" */
  86.571 +    0x51,0x31,0x82,0x49,0x52,0x51,0x31,0x60,  /* 000003A8    "Q1.IRQ1`" */
  86.572 +    0x76,0x60,0x70,0x60,0x50,0x49,0x52,0x43,  /* 000003B0    "v`p`PIRC" */
  86.573 +    0x5B,0x82,0x49,0x08,0x4C,0x4E,0x4B,0x44,  /* 000003B8    "[.I.LNKD" */
  86.574 +    0x08,0x5F,0x48,0x49,0x44,0x0C,0x41,0xD0,  /* 000003C0    "._HID.A." */
  86.575 +    0x0C,0x0F,0x08,0x5F,0x55,0x49,0x44,0x0A,  /* 000003C8    "..._UID." */
  86.576 +    0x04,0x14,0x1C,0x5F,0x53,0x54,0x41,0x00,  /* 000003D0    "..._STA." */
  86.577 +    0x7B,0x50,0x49,0x52,0x44,0x0A,0x80,0x60,  /* 000003D8    "{PIRD..`" */
  86.578 +    0xA0,0x08,0x93,0x60,0x0A,0x80,0xA4,0x0A,  /* 000003E0    "...`...." */
  86.579 +    0x09,0xA1,0x04,0xA4,0x0A,0x0B,0x14,0x0B,  /* 000003E8    "........" */
  86.580 +    0x5F,0x50,0x52,0x53,0x00,0xA4,0x42,0x55,  /* 000003F0    "_PRS..BU" */
  86.581 +    0x46,0x41,0x14,0x11,0x5F,0x44,0x49,0x53,  /* 000003F8    "FA.._DIS" */
  86.582 +    0x00,0x7D,0x50,0x49,0x52,0x44,0x0A,0x80,  /* 00000400    ".}PIRD.." */
  86.583 +    0x50,0x49,0x52,0x44,0x14,0x1A,0x5F,0x43,  /* 00000408    "PIRD.._C" */
  86.584 +    0x52,0x53,0x00,0x7B,0x50,0x49,0x52,0x44,  /* 00000410    "RS.{PIRD" */
  86.585 +    0x0A,0x0F,0x60,0x79,0x01,0x60,0x49,0x52,  /* 00000418    "..`y.`IR" */
  86.586 +    0x51,0x56,0xA4,0x42,0x55,0x46,0x42,0x14,  /* 00000420    "QV.BUFB." */
  86.587 +    0x1B,0x5F,0x53,0x52,0x53,0x01,0x8B,0x68,  /* 00000428    "._SRS..h" */
  86.588 +    0x01,0x49,0x52,0x51,0x31,0x82,0x49,0x52,  /* 00000430    ".IRQ1.IR" */
  86.589 +    0x51,0x31,0x60,0x76,0x60,0x70,0x60,0x50,  /* 00000438    "Q1`v`p`P" */
  86.590 +    0x49,0x52,0x44,0x5B,0x82,0x44,0x05,0x48,  /* 00000440    "IRD[.D.H" */
  86.591 +    0x50,0x45,0x54,0x08,0x5F,0x48,0x49,0x44,  /* 00000448    "PET._HID" */
  86.592 +    0x0C,0x41,0xD0,0x01,0x03,0x08,0x5F,0x55,  /* 00000450    ".A...._U" */
  86.593 +    0x49,0x44,0x00,0x14,0x18,0x5F,0x53,0x54,  /* 00000458    "ID..._ST" */
  86.594 +    0x41,0x00,0xA0,0x0C,0x93,0x5E,0x5E,0x5E,  /* 00000460    "A....^^^" */
  86.595 +    0x48,0x50,0x45,0x54,0x00,0xA4,0x00,0xA1,  /* 00000468    "HPET...." */
  86.596 +    0x04,0xA4,0x0A,0x0F,0x08,0x5F,0x43,0x52,  /* 00000470    "....._CR" */
  86.597 +    0x53,0x11,0x1F,0x0A,0x1C,0x87,0x17,0x00,  /* 00000478    "S......." */
  86.598 +    0x00,0x0D,0x01,0x00,0x00,0x00,0x00,0x00,  /* 00000480    "........" */
  86.599 +    0x00,0xD0,0xFE,0xFF,0x03,0xD0,0xFE,0x00,  /* 00000488    "........" */
  86.600 +    0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x79,  /* 00000490    ".......y" */
  86.601 +    0x00,0x14,0x16,0x5F,0x50,0x52,0x54,0x00,  /* 00000498    "..._PRT." */
  86.602 +    0xA0,0x0A,0x50,0x49,0x43,0x44,0xA4,0x50,  /* 000004A0    "..PICD.P" */
  86.603 +    0x52,0x54,0x41,0xA4,0x50,0x52,0x54,0x50,  /* 000004A8    "RTA.PRTP" */
  86.604 +    0x08,0x50,0x52,0x54,0x50,0x12,0x49,0x36,  /* 000004B0    ".PRTP.I6" */
  86.605 +    0x3C,0x12,0x0D,0x04,0x0C,0xFF,0xFF,0x01,  /* 000004B8    "<......." */
  86.606 +    0x00,0x00,0x4C,0x4E,0x4B,0x42,0x00,0x12,  /* 000004C0    "..LNKB.." */
  86.607 +    0x0D,0x04,0x0C,0xFF,0xFF,0x01,0x00,0x01,  /* 000004C8    "........" */
  86.608 +    0x4C,0x4E,0x4B,0x43,0x00,0x12,0x0E,0x04,  /* 000004D0    "LNKC...." */
  86.609 +    0x0C,0xFF,0xFF,0x01,0x00,0x0A,0x02,0x4C,  /* 000004D8    ".......L" */
  86.610 +    0x4E,0x4B,0x44,0x00,0x12,0x0E,0x04,0x0C,  /* 000004E0    "NKD....." */
  86.611 +    0xFF,0xFF,0x01,0x00,0x0A,0x03,0x4C,0x4E,  /* 000004E8    "......LN" */
  86.612 +    0x4B,0x41,0x00,0x12,0x0D,0x04,0x0C,0xFF,  /* 000004F0    "KA......" */
  86.613 +    0xFF,0x02,0x00,0x00,0x4C,0x4E,0x4B,0x43,  /* 000004F8    "....LNKC" */
  86.614 +    0x00,0x12,0x0D,0x04,0x0C,0xFF,0xFF,0x02,  /* 00000500    "........" */
  86.615 +    0x00,0x01,0x4C,0x4E,0x4B,0x44,0x00,0x12,  /* 00000508    "..LNKD.." */
  86.616 +    0x0E,0x04,0x0C,0xFF,0xFF,0x02,0x00,0x0A,  /* 00000510    "........" */
  86.617 +    0x02,0x4C,0x4E,0x4B,0x41,0x00,0x12,0x0E,  /* 00000518    ".LNKA..." */
  86.618 +    0x04,0x0C,0xFF,0xFF,0x02,0x00,0x0A,0x03,  /* 00000520    "........" */
  86.619 +    0x4C,0x4E,0x4B,0x42,0x00,0x12,0x0D,0x04,  /* 00000528    "LNKB...." */
  86.620 +    0x0C,0xFF,0xFF,0x03,0x00,0x00,0x4C,0x4E,  /* 00000530    "......LN" */
  86.621 +    0x4B,0x44,0x00,0x12,0x0D,0x04,0x0C,0xFF,  /* 00000538    "KD......" */
  86.622 +    0xFF,0x03,0x00,0x01,0x4C,0x4E,0x4B,0x41,  /* 00000540    "....LNKA" */
  86.623 +    0x00,0x12,0x0E,0x04,0x0C,0xFF,0xFF,0x03,  /* 00000548    "........" */
  86.624 +    0x00,0x0A,0x02,0x4C,0x4E,0x4B,0x42,0x00,  /* 00000550    "...LNKB." */
  86.625 +    0x12,0x0E,0x04,0x0C,0xFF,0xFF,0x03,0x00,  /* 00000558    "........" */
  86.626 +    0x0A,0x03,0x4C,0x4E,0x4B,0x43,0x00,0x12,  /* 00000560    "..LNKC.." */
  86.627 +    0x0D,0x04,0x0C,0xFF,0xFF,0x04,0x00,0x00,  /* 00000568    "........" */
  86.628 +    0x4C,0x4E,0x4B,0x41,0x00,0x12,0x0D,0x04,  /* 00000570    "LNKA...." */
  86.629 +    0x0C,0xFF,0xFF,0x04,0x00,0x01,0x4C,0x4E,  /* 00000578    "......LN" */
  86.630 +    0x4B,0x42,0x00,0x12,0x0E,0x04,0x0C,0xFF,  /* 00000580    "KB......" */
  86.631 +    0xFF,0x04,0x00,0x0A,0x02,0x4C,0x4E,0x4B,  /* 00000588    ".....LNK" */
  86.632 +    0x43,0x00,0x12,0x0E,0x04,0x0C,0xFF,0xFF,  /* 00000590    "C......." */
  86.633 +    0x04,0x00,0x0A,0x03,0x4C,0x4E,0x4B,0x44,  /* 00000598    "....LNKD" */
  86.634 +    0x00,0x12,0x0D,0x04,0x0C,0xFF,0xFF,0x05,  /* 000005A0    "........" */
  86.635 +    0x00,0x00,0x4C,0x4E,0x4B,0x42,0x00,0x12,  /* 000005A8    "..LNKB.." */
  86.636 +    0x0D,0x04,0x0C,0xFF,0xFF,0x05,0x00,0x01,  /* 000005B0    "........" */
  86.637 +    0x4C,0x4E,0x4B,0x43,0x00,0x12,0x0E,0x04,  /* 000005B8    "LNKC...." */
  86.638 +    0x0C,0xFF,0xFF,0x05,0x00,0x0A,0x02,0x4C,  /* 000005C0    ".......L" */
  86.639 +    0x4E,0x4B,0x44,0x00,0x12,0x0E,0x04,0x0C,  /* 000005C8    "NKD....." */
  86.640 +    0xFF,0xFF,0x05,0x00,0x0A,0x03,0x4C,0x4E,  /* 000005D0    "......LN" */
  86.641 +    0x4B,0x41,0x00,0x12,0x0D,0x04,0x0C,0xFF,  /* 000005D8    "KA......" */
  86.642 +    0xFF,0x06,0x00,0x00,0x4C,0x4E,0x4B,0x43,  /* 000005E0    "....LNKC" */
  86.643 +    0x00,0x12,0x0D,0x04,0x0C,0xFF,0xFF,0x06,  /* 000005E8    "........" */
  86.644 +    0x00,0x01,0x4C,0x4E,0x4B,0x44,0x00,0x12,  /* 000005F0    "..LNKD.." */
  86.645 +    0x0E,0x04,0x0C,0xFF,0xFF,0x06,0x00,0x0A,  /* 000005F8    "........" */
  86.646 +    0x02,0x4C,0x4E,0x4B,0x41,0x00,0x12,0x0E,  /* 00000600    ".LNKA..." */
  86.647 +    0x04,0x0C,0xFF,0xFF,0x06,0x00,0x0A,0x03,  /* 00000608    "........" */
  86.648 +    0x4C,0x4E,0x4B,0x42,0x00,0x12,0x0D,0x04,  /* 00000610    "LNKB...." */
  86.649 +    0x0C,0xFF,0xFF,0x07,0x00,0x00,0x4C,0x4E,  /* 00000618    "......LN" */
  86.650 +    0x4B,0x44,0x00,0x12,0x0D,0x04,0x0C,0xFF,  /* 00000620    "KD......" */
  86.651 +    0xFF,0x07,0x00,0x01,0x4C,0x4E,0x4B,0x41,  /* 00000628    "....LNKA" */
  86.652 +    0x00,0x12,0x0E,0x04,0x0C,0xFF,0xFF,0x07,  /* 00000630    "........" */
  86.653 +    0x00,0x0A,0x02,0x4C,0x4E,0x4B,0x42,0x00,  /* 00000638    "...LNKB." */
  86.654 +    0x12,0x0E,0x04,0x0C,0xFF,0xFF,0x07,0x00,  /* 00000640    "........" */
  86.655 +    0x0A,0x03,0x4C,0x4E,0x4B,0x43,0x00,0x12,  /* 00000648    "..LNKC.." */
  86.656 +    0x0D,0x04,0x0C,0xFF,0xFF,0x08,0x00,0x00,  /* 00000650    "........" */
  86.657 +    0x4C,0x4E,0x4B,0x41,0x00,0x12,0x0D,0x04,  /* 00000658    "LNKA...." */
  86.658 +    0x0C,0xFF,0xFF,0x08,0x00,0x01,0x4C,0x4E,  /* 00000660    "......LN" */
  86.659 +    0x4B,0x42,0x00,0x12,0x0E,0x04,0x0C,0xFF,  /* 00000668    "KB......" */
  86.660 +    0xFF,0x08,0x00,0x0A,0x02,0x4C,0x4E,0x4B,  /* 00000670    ".....LNK" */
  86.661 +    0x43,0x00,0x12,0x0E,0x04,0x0C,0xFF,0xFF,  /* 00000678    "C......." */
  86.662 +    0x08,0x00,0x0A,0x03,0x4C,0x4E,0x4B,0x44,  /* 00000680    "....LNKD" */
  86.663 +    0x00,0x12,0x0D,0x04,0x0C,0xFF,0xFF,0x09,  /* 00000688    "........" */
  86.664 +    0x00,0x00,0x4C,0x4E,0x4B,0x42,0x00,0x12,  /* 00000690    "..LNKB.." */
  86.665 +    0x0D,0x04,0x0C,0xFF,0xFF,0x09,0x00,0x01,  /* 00000698    "........" */
  86.666 +    0x4C,0x4E,0x4B,0x43,0x00,0x12,0x0E,0x04,  /* 000006A0    "LNKC...." */
  86.667 +    0x0C,0xFF,0xFF,0x09,0x00,0x0A,0x02,0x4C,  /* 000006A8    ".......L" */
  86.668 +    0x4E,0x4B,0x44,0x00,0x12,0x0E,0x04,0x0C,  /* 000006B0    "NKD....." */
  86.669 +    0xFF,0xFF,0x09,0x00,0x0A,0x03,0x4C,0x4E,  /* 000006B8    "......LN" */
  86.670 +    0x4B,0x41,0x00,0x12,0x0D,0x04,0x0C,0xFF,  /* 000006C0    "KA......" */
  86.671 +    0xFF,0x0A,0x00,0x00,0x4C,0x4E,0x4B,0x43,  /* 000006C8    "....LNKC" */
  86.672 +    0x00,0x12,0x0D,0x04,0x0C,0xFF,0xFF,0x0A,  /* 000006D0    "........" */
  86.673 +    0x00,0x01,0x4C,0x4E,0x4B,0x44,0x00,0x12,  /* 000006D8    "..LNKD.." */
  86.674 +    0x0E,0x04,0x0C,0xFF,0xFF,0x0A,0x00,0x0A,  /* 000006E0    "........" */
  86.675 +    0x02,0x4C,0x4E,0x4B,0x41,0x00,0x12,0x0E,  /* 000006E8    ".LNKA..." */
  86.676 +    0x04,0x0C,0xFF,0xFF,0x0A,0x00,0x0A,0x03,  /* 000006F0    "........" */
  86.677 +    0x4C,0x4E,0x4B,0x42,0x00,0x12,0x0D,0x04,  /* 000006F8    "LNKB...." */
  86.678 +    0x0C,0xFF,0xFF,0x0B,0x00,0x00,0x4C,0x4E,  /* 00000700    "......LN" */
  86.679 +    0x4B,0x44,0x00,0x12,0x0D,0x04,0x0C,0xFF,  /* 00000708    "KD......" */
  86.680 +    0xFF,0x0B,0x00,0x01,0x4C,0x4E,0x4B,0x41,  /* 00000710    "....LNKA" */
  86.681 +    0x00,0x12,0x0E,0x04,0x0C,0xFF,0xFF,0x0B,  /* 00000718    "........" */
  86.682 +    0x00,0x0A,0x02,0x4C,0x4E,0x4B,0x42,0x00,  /* 00000720    "...LNKB." */
  86.683 +    0x12,0x0E,0x04,0x0C,0xFF,0xFF,0x0B,0x00,  /* 00000728    "........" */
  86.684 +    0x0A,0x03,0x4C,0x4E,0x4B,0x43,0x00,0x12,  /* 00000730    "..LNKC.." */
  86.685 +    0x0D,0x04,0x0C,0xFF,0xFF,0x0C,0x00,0x00,  /* 00000738    "........" */
  86.686 +    0x4C,0x4E,0x4B,0x41,0x00,0x12,0x0D,0x04,  /* 00000740    "LNKA...." */
  86.687 +    0x0C,0xFF,0xFF,0x0C,0x00,0x01,0x4C,0x4E,  /* 00000748    "......LN" */
  86.688 +    0x4B,0x42,0x00,0x12,0x0E,0x04,0x0C,0xFF,  /* 00000750    "KB......" */
  86.689 +    0xFF,0x0C,0x00,0x0A,0x02,0x4C,0x4E,0x4B,  /* 00000758    ".....LNK" */
  86.690 +    0x43,0x00,0x12,0x0E,0x04,0x0C,0xFF,0xFF,  /* 00000760    "C......." */
  86.691 +    0x0C,0x00,0x0A,0x03,0x4C,0x4E,0x4B,0x44,  /* 00000768    "....LNKD" */
  86.692 +    0x00,0x12,0x0D,0x04,0x0C,0xFF,0xFF,0x0D,  /* 00000770    "........" */
  86.693 +    0x00,0x00,0x4C,0x4E,0x4B,0x42,0x00,0x12,  /* 00000778    "..LNKB.." */
  86.694 +    0x0D,0x04,0x0C,0xFF,0xFF,0x0D,0x00,0x01,  /* 00000780    "........" */
  86.695 +    0x4C,0x4E,0x4B,0x43,0x00,0x12,0x0E,0x04,  /* 00000788    "LNKC...." */
  86.696 +    0x0C,0xFF,0xFF,0x0D,0x00,0x0A,0x02,0x4C,  /* 00000790    ".......L" */
  86.697 +    0x4E,0x4B,0x44,0x00,0x12,0x0E,0x04,0x0C,  /* 00000798    "NKD....." */
  86.698 +    0xFF,0xFF,0x0D,0x00,0x0A,0x03,0x4C,0x4E,  /* 000007A0    "......LN" */
  86.699 +    0x4B,0x41,0x00,0x12,0x0D,0x04,0x0C,0xFF,  /* 000007A8    "KA......" */
  86.700 +    0xFF,0x0E,0x00,0x00,0x4C,0x4E,0x4B,0x43,  /* 000007B0    "....LNKC" */
  86.701 +    0x00,0x12,0x0D,0x04,0x0C,0xFF,0xFF,0x0E,  /* 000007B8    "........" */
  86.702 +    0x00,0x01,0x4C,0x4E,0x4B,0x44,0x00,0x12,  /* 000007C0    "..LNKD.." */
  86.703 +    0x0E,0x04,0x0C,0xFF,0xFF,0x0E,0x00,0x0A,  /* 000007C8    "........" */
  86.704 +    0x02,0x4C,0x4E,0x4B,0x41,0x00,0x12,0x0E,  /* 000007D0    ".LNKA..." */
  86.705 +    0x04,0x0C,0xFF,0xFF,0x0E,0x00,0x0A,0x03,  /* 000007D8    "........" */
  86.706 +    0x4C,0x4E,0x4B,0x42,0x00,0x12,0x0D,0x04,  /* 000007E0    "LNKB...." */
  86.707 +    0x0C,0xFF,0xFF,0x0F,0x00,0x00,0x4C,0x4E,  /* 000007E8    "......LN" */
  86.708 +    0x4B,0x44,0x00,0x12,0x0D,0x04,0x0C,0xFF,  /* 000007F0    "KD......" */
  86.709 +    0xFF,0x0F,0x00,0x01,0x4C,0x4E,0x4B,0x41,  /* 000007F8    "....LNKA" */
  86.710 +    0x00,0x12,0x0E,0x04,0x0C,0xFF,0xFF,0x0F,  /* 00000800    "........" */
  86.711 +    0x00,0x0A,0x02,0x4C,0x4E,0x4B,0x42,0x00,  /* 00000808    "...LNKB." */
  86.712 +    0x12,0x0E,0x04,0x0C,0xFF,0xFF,0x0F,0x00,  /* 00000810    "........" */
  86.713 +    0x0A,0x03,0x4C,0x4E,0x4B,0x43,0x00,0x08,  /* 00000818    "..LNKC.." */
  86.714 +    0x50,0x52,0x54,0x41,0x12,0x41,0x2F,0x3C,  /* 00000820    "PRTA.A/<" */
  86.715 +    0x12,0x0B,0x04,0x0C,0xFF,0xFF,0x01,0x00,  /* 00000828    "........" */
  86.716 +    0x00,0x00,0x0A,0x14,0x12,0x0B,0x04,0x0C,  /* 00000830    "........" */
  86.717 +    0xFF,0xFF,0x01,0x00,0x01,0x00,0x0A,0x15,  /* 00000838    "........" */
  86.718 +    0x12,0x0C,0x04,0x0C,0xFF,0xFF,0x01,0x00,  /* 00000840    "........" */
  86.719 +    0x0A,0x02,0x00,0x0A,0x16,0x12,0x0C,0x04,  /* 00000848    "........" */
  86.720 +    0x0C,0xFF,0xFF,0x01,0x00,0x0A,0x03,0x00,  /* 00000850    "........" */
  86.721 +    0x0A,0x17,0x12,0x0B,0x04,0x0C,0xFF,0xFF,  /* 00000858    "........" */
  86.722 +    0x02,0x00,0x00,0x00,0x0A,0x18,0x12,0x0B,  /* 00000860    "........" */
  86.723 +    0x04,0x0C,0xFF,0xFF,0x02,0x00,0x01,0x00,  /* 00000868    "........" */
  86.724 +    0x0A,0x19,0x12,0x0C,0x04,0x0C,0xFF,0xFF,  /* 00000870    "........" */
  86.725 +    0x02,0x00,0x0A,0x02,0x00,0x0A,0x1A,0x12,  /* 00000878    "........" */
  86.726 +    0x0C,0x04,0x0C,0xFF,0xFF,0x02,0x00,0x0A,  /* 00000880    "........" */
  86.727 +    0x03,0x00,0x0A,0x1B,0x12,0x0B,0x04,0x0C,  /* 00000888    "........" */
  86.728 +    0xFF,0xFF,0x03,0x00,0x00,0x00,0x0A,0x1C,  /* 00000890    "........" */
  86.729 +    0x12,0x0B,0x04,0x0C,0xFF,0xFF,0x03,0x00,  /* 00000898    "........" */
  86.730 +    0x01,0x00,0x0A,0x1D,0x12,0x0C,0x04,0x0C,  /* 000008A0    "........" */
  86.731 +    0xFF,0xFF,0x03,0x00,0x0A,0x02,0x00,0x0A,  /* 000008A8    "........" */
  86.732 +    0x1E,0x12,0x0C,0x04,0x0C,0xFF,0xFF,0x03,  /* 000008B0    "........" */
  86.733 +    0x00,0x0A,0x03,0x00,0x0A,0x1F,0x12,0x0B,  /* 000008B8    "........" */
  86.734 +    0x04,0x0C,0xFF,0xFF,0x04,0x00,0x00,0x00,  /* 000008C0    "........" */
  86.735 +    0x0A,0x20,0x12,0x0B,0x04,0x0C,0xFF,0xFF,  /* 000008C8    ". ......" */
  86.736 +    0x04,0x00,0x01,0x00,0x0A,0x21,0x12,0x0C,  /* 000008D0    ".....!.." */
  86.737 +    0x04,0x0C,0xFF,0xFF,0x04,0x00,0x0A,0x02,  /* 000008D8    "........" */
  86.738 +    0x00,0x0A,0x22,0x12,0x0C,0x04,0x0C,0xFF,  /* 000008E0    ".."....." */
  86.739 +    0xFF,0x04,0x00,0x0A,0x03,0x00,0x0A,0x23,  /* 000008E8    ".......#" */
  86.740 +    0x12,0x0B,0x04,0x0C,0xFF,0xFF,0x05,0x00,  /* 000008F0    "........" */
  86.741 +    0x00,0x00,0x0A,0x24,0x12,0x0B,0x04,0x0C,  /* 000008F8    "...$...." */
  86.742 +    0xFF,0xFF,0x05,0x00,0x01,0x00,0x0A,0x25,  /* 00000900    ".......%" */
  86.743 +    0x12,0x0C,0x04,0x0C,0xFF,0xFF,0x05,0x00,  /* 00000908    "........" */
  86.744 +    0x0A,0x02,0x00,0x0A,0x26,0x12,0x0C,0x04,  /* 00000910    "....&..." */
  86.745 +    0x0C,0xFF,0xFF,0x05,0x00,0x0A,0x03,0x00,  /* 00000918    "........" */
  86.746 +    0x0A,0x27,0x12,0x0B,0x04,0x0C,0xFF,0xFF,  /* 00000920    ".'......" */
  86.747 +    0x06,0x00,0x00,0x00,0x0A,0x28,0x12,0x0B,  /* 00000928    ".....(.." */
  86.748 +    0x04,0x0C,0xFF,0xFF,0x06,0x00,0x01,0x00,  /* 00000930    "........" */
  86.749 +    0x0A,0x29,0x12,0x0C,0x04,0x0C,0xFF,0xFF,  /* 00000938    ".)......" */
  86.750 +    0x06,0x00,0x0A,0x02,0x00,0x0A,0x2A,0x12,  /* 00000940    "......*." */
  86.751 +    0x0C,0x04,0x0C,0xFF,0xFF,0x06,0x00,0x0A,  /* 00000948    "........" */
  86.752 +    0x03,0x00,0x0A,0x2B,0x12,0x0B,0x04,0x0C,  /* 00000950    "...+...." */
  86.753 +    0xFF,0xFF,0x07,0x00,0x00,0x00,0x0A,0x2C,  /* 00000958    ".......," */
  86.754 +    0x12,0x0B,0x04,0x0C,0xFF,0xFF,0x07,0x00,  /* 00000960    "........" */
  86.755 +    0x01,0x00,0x0A,0x2D,0x12,0x0C,0x04,0x0C,  /* 00000968    "...-...." */
  86.756 +    0xFF,0xFF,0x07,0x00,0x0A,0x02,0x00,0x0A,  /* 00000970    "........" */
  86.757 +    0x2E,0x12,0x0C,0x04,0x0C,0xFF,0xFF,0x07,  /* 00000978    "........" */
  86.758 +    0x00,0x0A,0x03,0x00,0x0A,0x2F,0x12,0x0B,  /* 00000980    "...../.." */
  86.759 +    0x04,0x0C,0xFF,0xFF,0x08,0x00,0x00,0x00,  /* 00000988    "........" */
  86.760 +    0x0A,0x11,0x12,0x0B,0x04,0x0C,0xFF,0xFF,  /* 00000990    "........" */
  86.761 +    0x08,0x00,0x01,0x00,0x0A,0x12,0x12,0x0C,  /* 00000998    "........" */
  86.762 +    0x04,0x0C,0xFF,0xFF,0x08,0x00,0x0A,0x02,  /* 000009A0    "........" */
  86.763 +    0x00,0x0A,0x13,0x12,0x0C,0x04,0x0C,0xFF,  /* 000009A8    "........" */
  86.764 +    0xFF,0x08,0x00,0x0A,0x03,0x00,0x0A,0x14,  /* 000009B0    "........" */
  86.765 +    0x12,0x0B,0x04,0x0C,0xFF,0xFF,0x09,0x00,  /* 000009B8    "........" */
  86.766 +    0x00,0x00,0x0A,0x15,0x12,0x0B,0x04,0x0C,  /* 000009C0    "........" */
  86.767 +    0xFF,0xFF,0x09,0x00,0x01,0x00,0x0A,0x16,  /* 000009C8    "........" */
  86.768 +    0x12,0x0C,0x04,0x0C,0xFF,0xFF,0x09,0x00,  /* 000009D0    "........" */
  86.769 +    0x0A,0x02,0x00,0x0A,0x17,0x12,0x0C,0x04,  /* 000009D8    "........" */
  86.770 +    0x0C,0xFF,0xFF,0x09,0x00,0x0A,0x03,0x00,  /* 000009E0    "........" */
  86.771 +    0x0A,0x18,0x12,0x0B,0x04,0x0C,0xFF,0xFF,  /* 000009E8    "........" */
  86.772 +    0x0A,0x00,0x00,0x00,0x0A,0x19,0x12,0x0B,  /* 000009F0    "........" */
  86.773 +    0x04,0x0C,0xFF,0xFF,0x0A,0x00,0x01,0x00,  /* 000009F8    "........" */
  86.774 +    0x0A,0x1A,0x12,0x0C,0x04,0x0C,0xFF,0xFF,  /* 00000A00    "........" */
  86.775 +    0x0A,0x00,0x0A,0x02,0x00,0x0A,0x1B,0x12,  /* 00000A08    "........" */
  86.776 +    0x0C,0x04,0x0C,0xFF,0xFF,0x0A,0x00,0x0A,  /* 00000A10    "........" */
  86.777 +    0x03,0x00,0x0A,0x1C,0x12,0x0B,0x04,0x0C,  /* 00000A18    "........" */
  86.778 +    0xFF,0xFF,0x0B,0x00,0x00,0x00,0x0A,0x1D,  /* 00000A20    "........" */
  86.779 +    0x12,0x0B,0x04,0x0C,0xFF,0xFF,0x0B,0x00,  /* 00000A28    "........" */
  86.780 +    0x01,0x00,0x0A,0x1E,0x12,0x0C,0x04,0x0C,  /* 00000A30    "........" */
  86.781 +    0xFF,0xFF,0x0B,0x00,0x0A,0x02,0x00,0x0A,  /* 00000A38    "........" */
  86.782 +    0x1F,0x12,0x0C,0x04,0x0C,0xFF,0xFF,0x0B,  /* 00000A40    "........" */
  86.783 +    0x00,0x0A,0x03,0x00,0x0A,0x20,0x12,0x0B,  /* 00000A48    "..... .." */
  86.784 +    0x04,0x0C,0xFF,0xFF,0x0C,0x00,0x00,0x00,  /* 00000A50    "........" */
  86.785 +    0x0A,0x21,0x12,0x0B,0x04,0x0C,0xFF,0xFF,  /* 00000A58    ".!......" */
  86.786 +    0x0C,0x00,0x01,0x00,0x0A,0x22,0x12,0x0C,  /* 00000A60    ".....".." */
  86.787 +    0x04,0x0C,0xFF,0xFF,0x0C,0x00,0x0A,0x02,  /* 00000A68    "........" */
  86.788 +    0x00,0x0A,0x23,0x12,0x0C,0x04,0x0C,0xFF,  /* 00000A70    "..#....." */
  86.789 +    0xFF,0x0C,0x00,0x0A,0x03,0x00,0x0A,0x24,  /* 00000A78    ".......$" */
  86.790 +    0x12,0x0B,0x04,0x0C,0xFF,0xFF,0x0D,0x00,  /* 00000A80    "........" */
  86.791 +    0x00,0x00,0x0A,0x25,0x12,0x0B,0x04,0x0C,  /* 00000A88    "...%...." */
  86.792 +    0xFF,0xFF,0x0D,0x00,0x01,0x00,0x0A,0x26,  /* 00000A90    ".......&" */
  86.793 +    0x12,0x0C,0x04,0x0C,0xFF,0xFF,0x0D,0x00,  /* 00000A98    "........" */
  86.794 +    0x0A,0x02,0x00,0x0A,0x27,0x12,0x0C,0x04,  /* 00000AA0    "....'..." */
  86.795 +    0x0C,0xFF,0xFF,0x0D,0x00,0x0A,0x03,0x00,  /* 00000AA8    "........" */
  86.796 +    0x0A,0x28,0x12,0x0B,0x04,0x0C,0xFF,0xFF,  /* 00000AB0    ".(......" */
  86.797 +    0x0E,0x00,0x00,0x00,0x0A,0x29,0x12,0x0B,  /* 00000AB8    ".....).." */
  86.798 +    0x04,0x0C,0xFF,0xFF,0x0E,0x00,0x01,0x00,  /* 00000AC0    "........" */
  86.799 +    0x0A,0x2A,0x12,0x0C,0x04,0x0C,0xFF,0xFF,  /* 00000AC8    ".*......" */
  86.800 +    0x0E,0x00,0x0A,0x02,0x00,0x0A,0x2B,0x12,  /* 00000AD0    "......+." */
  86.801 +    0x0C,0x04,0x0C,0xFF,0xFF,0x0E,0x00,0x0A,  /* 00000AD8    "........" */
  86.802 +    0x03,0x00,0x0A,0x2C,0x12,0x0B,0x04,0x0C,  /* 00000AE0    "...,...." */
  86.803 +    0xFF,0xFF,0x0F,0x00,0x00,0x00,0x0A,0x2D,  /* 00000AE8    ".......-" */
  86.804 +    0x12,0x0B,0x04,0x0C,0xFF,0xFF,0x0F,0x00,  /* 00000AF0    "........" */
  86.805 +    0x01,0x00,0x0A,0x2E,0x12,0x0C,0x04,0x0C,  /* 00000AF8    "........" */
  86.806 +    0xFF,0xFF,0x0F,0x00,0x0A,0x02,0x00,0x0A,  /* 00000B00    "........" */
  86.807 +    0x2F,0x12,0x0C,0x04,0x0C,0xFF,0xFF,0x0F,  /* 00000B08    "/......." */
  86.808 +    0x00,0x0A,0x03,0x00,0x0A,0x10,0x5B,0x82,  /* 00000B10    "......[." */
  86.809 +    0x46,0x37,0x49,0x53,0x41,0x5F,0x08,0x5F,  /* 00000B18    "F7ISA_._" */
  86.810 +    0x41,0x44,0x52,0x0C,0x00,0x00,0x01,0x00,  /* 00000B20    "ADR....." */
  86.811 +    0x5B,0x80,0x50,0x49,0x52,0x51,0x02,0x0A,  /* 00000B28    "[.PIRQ.." */
  86.812 +    0x60,0x0A,0x04,0x10,0x2E,0x5C,0x00,0x5B,  /* 00000B30    "`....\.[" */
  86.813 +    0x81,0x29,0x5C,0x2F,0x04,0x5F,0x53,0x42,  /* 00000B38    ".)\/._SB" */
  86.814 +    0x5F,0x50,0x43,0x49,0x30,0x49,0x53,0x41,  /* 00000B40    "_PCI0ISA" */
  86.815 +    0x5F,0x50,0x49,0x52,0x51,0x01,0x50,0x49,  /* 00000B48    "_PIRQ.PI" */
  86.816 +    0x52,0x41,0x08,0x50,0x49,0x52,0x42,0x08,  /* 00000B50    "RA.PIRB." */
  86.817 +    0x50,0x49,0x52,0x43,0x08,0x50,0x49,0x52,  /* 00000B58    "PIRC.PIR" */
  86.818 +    0x44,0x08,0x5B,0x82,0x46,0x0B,0x53,0x59,  /* 00000B60    "D.[.F.SY" */
  86.819 +    0x53,0x52,0x08,0x5F,0x48,0x49,0x44,0x0C,  /* 00000B68    "SR._HID." */
  86.820 +    0x41,0xD0,0x0C,0x02,0x08,0x5F,0x55,0x49,  /* 00000B70    "A...._UI" */
  86.821 +    0x44,0x01,0x08,0x43,0x52,0x53,0x5F,0x11,  /* 00000B78    "D..CRS_." */
  86.822 +    0x4E,0x08,0x0A,0x8A,0x47,0x01,0x10,0x00,  /* 00000B80    "N...G..." */
  86.823 +    0x10,0x00,0x00,0x10,0x47,0x01,0x22,0x00,  /* 00000B88    "....G."." */
  86.824 +    0x22,0x00,0x00,0x0C,0x47,0x01,0x30,0x00,  /* 00000B90    ""...G.0." */
  86.825 +    0x30,0x00,0x00,0x10,0x47,0x01,0x44,0x00,  /* 00000B98    "0...G.D." */
  86.826 +    0x44,0x00,0x00,0x1C,0x47,0x01,0x62,0x00,  /* 00000BA0    "D...G.b." */
  86.827 +    0x62,0x00,0x00,0x02,0x47,0x01,0x65,0x00,  /* 00000BA8    "b...G.e." */
  86.828 +    0x65,0x00,0x00,0x0B,0x47,0x01,0x72,0x00,  /* 00000BB0    "e...G.r." */
  86.829 +    0x72,0x00,0x00,0x0E,0x47,0x01,0x80,0x00,  /* 00000BB8    "r...G..." */
  86.830 +    0x80,0x00,0x00,0x01,0x47,0x01,0x84,0x00,  /* 00000BC0    "....G..." */
  86.831 +    0x84,0x00,0x00,0x03,0x47,0x01,0x88,0x00,  /* 00000BC8    "....G..." */
  86.832 +    0x88,0x00,0x00,0x01,0x47,0x01,0x8C,0x00,  /* 00000BD0    "....G..." */
  86.833 +    0x8C,0x00,0x00,0x03,0x47,0x01,0x90,0x00,  /* 00000BD8    "....G..." */
  86.834 +    0x90,0x00,0x00,0x10,0x47,0x01,0xA2,0x00,  /* 00000BE0    "....G..." */
  86.835 +    0xA2,0x00,0x00,0x1C,0x47,0x01,0xE0,0x00,  /* 00000BE8    "....G..." */
  86.836 +    0xE0,0x00,0x00,0x10,0x47,0x01,0xA0,0x08,  /* 00000BF0    "....G..." */
  86.837 +    0xA0,0x08,0x00,0x04,0x47,0x01,0xC0,0x0C,  /* 00000BF8    "....G..." */
  86.838 +    0xC0,0x0C,0x00,0x10,0x47,0x01,0xD0,0x04,  /* 00000C00    "....G..." */
  86.839 +    0xD0,0x04,0x00,0x02,0x79,0x00,0x14,0x0B,  /* 00000C08    "....y..." */
  86.840 +    0x5F,0x43,0x52,0x53,0x00,0xA4,0x43,0x52,  /* 00000C10    "_CRS..CR" */
  86.841 +    0x53,0x5F,0x5B,0x82,0x2B,0x50,0x49,0x43,  /* 00000C18    "S_[.+PIC" */
  86.842 +    0x5F,0x08,0x5F,0x48,0x49,0x44,0x0B,0x41,  /* 00000C20    "_._HID.A" */
  86.843 +    0xD0,0x08,0x5F,0x43,0x52,0x53,0x11,0x18,  /* 00000C28    ".._CRS.." */
  86.844 +    0x0A,0x15,0x47,0x01,0x20,0x00,0x20,0x00,  /* 00000C30    "..G. . ." */
  86.845 +    0x01,0x02,0x47,0x01,0xA0,0x00,0xA0,0x00,  /* 00000C38    "..G....." */
  86.846 +    0x01,0x02,0x22,0x04,0x00,0x79,0x00,0x5B,  /* 00000C40    ".."..y.[" */
  86.847 +    0x82,0x47,0x05,0x44,0x4D,0x41,0x30,0x08,  /* 00000C48    ".G.DMA0." */
  86.848 +    0x5F,0x48,0x49,0x44,0x0C,0x41,0xD0,0x02,  /* 00000C50    "_HID.A.." */
  86.849 +    0x00,0x08,0x5F,0x43,0x52,0x53,0x11,0x41,  /* 00000C58    ".._CRS.A" */
  86.850 +    0x04,0x0A,0x3D,0x2A,0x10,0x04,0x47,0x01,  /* 00000C60    "..=*..G." */
  86.851 +    0x00,0x00,0x00,0x00,0x00,0x10,0x47,0x01,  /* 00000C68    "......G." */
  86.852 +    0x81,0x00,0x81,0x00,0x00,0x03,0x47,0x01,  /* 00000C70    "......G." */
  86.853 +    0x87,0x00,0x87,0x00,0x00,0x01,0x47,0x01,  /* 00000C78    "......G." */
  86.854 +    0x89,0x00,0x89,0x00,0x00,0x03,0x47,0x01,  /* 00000C80    "......G." */
  86.855 +    0x8F,0x00,0x8F,0x00,0x00,0x01,0x47,0x01,  /* 00000C88    "......G." */
  86.856 +    0xC0,0x00,0xC0,0x00,0x00,0x20,0x47,0x01,  /* 00000C90    "..... G." */
  86.857 +    0x80,0x04,0x80,0x04,0x00,0x10,0x79,0x00,  /* 00000C98    "......y." */
  86.858 +    0x5B,0x82,0x25,0x54,0x4D,0x52,0x5F,0x08,  /* 00000CA0    "[.%TMR_." */
  86.859 +    0x5F,0x48,0x49,0x44,0x0C,0x41,0xD0,0x01,  /* 00000CA8    "_HID.A.." */
  86.860 +    0x00,0x08,0x5F,0x43,0x52,0x53,0x11,0x10,  /* 00000CB0    ".._CRS.." */
  86.861 +    0x0A,0x0D,0x47,0x01,0x40,0x00,0x40,0x00,  /* 00000CB8    "..G.@.@." */
  86.862 +    0x00,0x04,0x22,0x01,0x00,0x79,0x00,0x5B,  /* 00000CC0    ".."..y.[" */
  86.863 +    0x82,0x25,0x52,0x54,0x43,0x5F,0x08,0x5F,  /* 00000CC8    ".%RTC_._" */
  86.864 +    0x48,0x49,0x44,0x0C,0x41,0xD0,0x0B,0x00,  /* 00000CD0    "HID.A..." */
  86.865 +    0x08,0x5F,0x43,0x52,0x53,0x11,0x10,0x0A,  /* 00000CD8    "._CRS..." */
  86.866 +    0x0D,0x47,0x01,0x70,0x00,0x70,0x00,0x00,  /* 00000CE0    ".G.p.p.." */
  86.867 +    0x02,0x22,0x00,0x01,0x79,0x00,0x5B,0x82,  /* 00000CE8    "."..y.[." */
  86.868 +    0x22,0x53,0x50,0x4B,0x52,0x08,0x5F,0x48,  /* 00000CF0    ""SPKR._H" */
  86.869 +    0x49,0x44,0x0C,0x41,0xD0,0x08,0x00,0x08,  /* 00000CF8    "ID.A...." */
  86.870 +    0x5F,0x43,0x52,0x53,0x11,0x0D,0x0A,0x0A,  /* 00000D00    "_CRS...." */
  86.871 +    0x47,0x01,0x61,0x00,0x61,0x00,0x00,0x01,  /* 00000D08    "G.a.a..." */
  86.872 +    0x79,0x00,0x5B,0x82,0x31,0x50,0x53,0x32,  /* 00000D10    "y.[.1PS2" */
  86.873 +    0x4D,0x08,0x5F,0x48,0x49,0x44,0x0C,0x41,  /* 00000D18    "M._HID.A" */
  86.874 +    0xD0,0x0F,0x13,0x08,0x5F,0x43,0x49,0x44,  /* 00000D20    "...._CID" */
  86.875 +    0x0C,0x41,0xD0,0x0F,0x13,0x14,0x09,0x5F,  /* 00000D28    ".A....._" */
  86.876 +    0x53,0x54,0x41,0x00,0xA4,0x0A,0x0F,0x08,  /* 00000D30    "STA....." */
  86.877 +    0x5F,0x43,0x52,0x53,0x11,0x08,0x0A,0x05,  /* 00000D38    "_CRS...." */
  86.878 +    0x22,0x00,0x10,0x79,0x00,0x5B,0x82,0x42,  /* 00000D40    ""..y.[.B" */
  86.879 +    0x04,0x50,0x53,0x32,0x4B,0x08,0x5F,0x48,  /* 00000D48    ".PS2K._H" */
  86.880 +    0x49,0x44,0x0C,0x41,0xD0,0x03,0x03,0x08,  /* 00000D50    "ID.A...." */
  86.881 +    0x5F,0x43,0x49,0x44,0x0C,0x41,0xD0,0x03,  /* 00000D58    "_CID.A.." */
  86.882 +    0x0B,0x14,0x09,0x5F,0x53,0x54,0x41,0x00,  /* 00000D60    "..._STA." */
  86.883 +    0xA4,0x0A,0x0F,0x08,0x5F,0x43,0x52,0x53,  /* 00000D68    "...._CRS" */
  86.884 +    0x11,0x18,0x0A,0x15,0x47,0x01,0x60,0x00,  /* 00000D70    "....G.`." */
  86.885 +    0x60,0x00,0x00,0x01,0x47,0x01,0x64,0x00,  /* 00000D78    "`...G.d." */
  86.886 +    0x64,0x00,0x00,0x01,0x22,0x02,0x00,0x79,  /* 00000D80    "d..."..y" */
  86.887 +    0x00,0x5B,0x82,0x3A,0x46,0x44,0x43,0x30,  /* 00000D88    ".[.:FDC0" */
  86.888 +    0x08,0x5F,0x48,0x49,0x44,0x0C,0x41,0xD0,  /* 00000D90    "._HID.A." */
  86.889 +    0x07,0x00,0x14,0x09,0x5F,0x53,0x54,0x41,  /* 00000D98    "...._STA" */
  86.890 +    0x00,0xA4,0x0A,0x0F,0x08,0x5F,0x43,0x52,  /* 00000DA0    "....._CR" */
  86.891 +    0x53,0x11,0x1B,0x0A,0x18,0x47,0x01,0xF0,  /* 00000DA8    "S....G.." */
  86.892 +    0x03,0xF0,0x03,0x01,0x06,0x47,0x01,0xF7,  /* 00000DB0    ".....G.." */
  86.893 +    0x03,0xF7,0x03,0x01,0x01,0x22,0x40,0x00,  /* 00000DB8    "....."@." */
  86.894 +    0x2A,0x04,0x00,0x79,0x00,0x5B,0x82,0x46,  /* 00000DC0    "*..y.[.F" */
  86.895 +    0x04,0x55,0x41,0x52,0x31,0x08,0x5F,0x48,  /* 00000DC8    ".UAR1._H" */
  86.896 +    0x49,0x44,0x0C,0x41,0xD0,0x05,0x01,0x08,  /* 00000DD0    "ID.A...." */
  86.897 +    0x5F,0x55,0x49,0x44,0x01,0x14,0x19,0x5F,  /* 00000DD8    "_UID..._" */
  86.898 +    0x53,0x54,0x41,0x00,0xA0,0x0D,0x93,0x5E,  /* 00000DE0    "STA....^" */
  86.899 +    0x5E,0x5E,0x5E,0x55,0x41,0x52,0x31,0x00,  /* 00000DE8    "^^^UAR1." */
  86.900 +    0xA4,0x00,0xA1,0x04,0xA4,0x0A,0x0F,0x08,  /* 00000DF0    "........" */
  86.901 +    0x5F,0x43,0x52,0x53,0x11,0x10,0x0A,0x0D,  /* 00000DF8    "_CRS...." */
  86.902 +    0x47,0x01,0xF8,0x03,0xF8,0x03,0x08,0x08,  /* 00000E00    "G......." */
  86.903 +    0x22,0x10,0x00,0x79,0x00,0x5B,0x82,0x47,  /* 00000E08    ""..y.[.G" */
  86.904 +    0x04,0x55,0x41,0x52,0x32,0x08,0x5F,0x48,  /* 00000E10    ".UAR2._H" */
  86.905 +    0x49,0x44,0x0C,0x41,0xD0,0x05,0x01,0x08,  /* 00000E18    "ID.A...." */
  86.906 +    0x5F,0x55,0x49,0x44,0x0A,0x02,0x14,0x19,  /* 00000E20    "_UID...." */
  86.907 +    0x5F,0x53,0x54,0x41,0x00,0xA0,0x0D,0x93,  /* 00000E28    "_STA...." */
  86.908 +    0x5E,0x5E,0x5E,0x5E,0x55,0x41,0x52,0x32,  /* 00000E30    "^^^^UAR2" */
  86.909 +    0x00,0xA4,0x00,0xA1,0x04,0xA4,0x0A,0x0F,  /* 00000E38    "........" */
  86.910 +    0x08,0x5F,0x43,0x52,0x53,0x11,0x10,0x0A,  /* 00000E40    "._CRS..." */
  86.911 +    0x0D,0x47,0x01,0xF8,0x02,0xF8,0x02,0x08,  /* 00000E48    ".G......" */
  86.912 +    0x08,0x22,0x08,0x00,0x79,0x00,0x5B,0x82,  /* 00000E50    "."..y.[." */
  86.913 +    0x36,0x4C,0x54,0x50,0x31,0x08,0x5F,0x48,  /* 00000E58    "6LTP1._H" */
  86.914 +    0x49,0x44,0x0C,0x41,0xD0,0x04,0x00,0x08,  /* 00000E60    "ID.A...." */
  86.915 +    0x5F,0x55,0x49,0x44,0x0A,0x02,0x14,0x09,  /* 00000E68    "_UID...." */
  86.916 +    0x5F,0x53,0x54,0x41,0x00,0xA4,0x0A,0x0F,  /* 00000E70    "_STA...." */
  86.917 +    0x08,0x5F,0x43,0x52,0x53,0x11,0x10,0x0A,  /* 00000E78    "._CRS..." */
  86.918 +    0x0D,0x47,0x01,0x78,0x03,0x78,0x03,0x08,  /* 00000E80    ".G.x.x.." */
  86.919 +    0x08,0x22,0x80,0x00,0x79,0x00,
  86.920  };
  86.921  int DsdtLen=sizeof(AmlCode);
    87.1 --- a/tools/fs-back/fs-backend.c	Wed Feb 13 10:37:18 2008 -0700
    87.2 +++ b/tools/fs-back/fs-backend.c	Thu Feb 14 09:34:27 2008 -0700
    87.3 @@ -140,8 +140,8 @@ void* handle_mount(void *data)
    87.4          handle_aio_events(mount);
    87.5  moretodo:
    87.6          rp = mount->ring.sring->req_prod;
    87.7 -        rmb(); /* Ensure we see queued requests up to 'rp'. */
    87.8 -                
    87.9 +        xen_rmb(); /* Ensure we see queued requests up to 'rp'. */
   87.10 +
   87.11          while ((cons = mount->ring.req_cons) != rp)
   87.12          {
   87.13              int i;
    88.1 --- a/tools/ioemu/Makefile.target	Wed Feb 13 10:37:18 2008 -0700
    88.2 +++ b/tools/ioemu/Makefile.target	Thu Feb 14 09:34:27 2008 -0700
    88.3 @@ -15,7 +15,7 @@ TARGET_BASE_ARCH:=sparc
    88.4  endif
    88.5  TARGET_PATH=$(SRC_PATH)/target-$(TARGET_BASE_ARCH)$(TARGET_SUB)
    88.6  VPATH=$(SRC_PATH):$(TARGET_PATH):$(SRC_PATH)/hw:$(SRC_PATH)/audio
    88.7 -CPPFLAGS=-I. -I.. -I$(TARGET_PATH) -I$(SRC_PATH)
    88.8 +CPPFLAGS+=-I. -I.. -I$(TARGET_PATH) -I$(SRC_PATH)
    88.9  CPPFLAGS+= -I$(XEN_ROOT)/tools/libxc
   88.10  CPPFLAGS+= -I$(XEN_ROOT)/tools/xenstore
   88.11  CPPFLAGS+= -I$(XEN_ROOT)/tools/include
   88.12 @@ -66,7 +66,11 @@ else
   88.13  QEMU_SYSTEM=qemu-fast
   88.14  endif
   88.15  
   88.16 +ifdef CONFIG_STUBDOM
   88.17 +QEMU_SYSTEM=qemu.a
   88.18 +else
   88.19  QEMU_SYSTEM=qemu-dm
   88.20 +endif
   88.21  
   88.22  ifdef CONFIG_USER_ONLY
   88.23  PROGS=$(QEMU_USER)
   88.24 @@ -345,14 +349,25 @@ VL_OBJS=vl.o osdep.o readline.o monitor.
   88.25  VL_OBJS+=cutils.o
   88.26  VL_OBJS+=block.o block-raw.o
   88.27  VL_OBJS+=block-cow.o block-qcow.o aes.o block-vmdk.o block-cloop.o block-dmg.o block-bochs.o block-vpc.o block-vvfat.o block-qcow2.o
   88.28 +ifdef CONFIG_STUBDOM
   88.29 +VL_OBJS+=block-vbd.o
   88.30 +endif
   88.31  ifdef CONFIG_WIN32
   88.32  VL_OBJS+=tap-win32.o
   88.33  endif
   88.34  
   88.35 -ifeq (,$(wildcard /usr/include/pci))
   88.36 +ifdef CONFIG_STUBDOM
   88.37 +CONFIG_PASSTHROUGH=1
   88.38 +else
   88.39 +  ifeq (,$(wildcard /usr/include/pci))
   88.40  $(warning *** pciutils-devl package not found - missing /usr/include/pci)
   88.41  $(warning *** PCI passthrough capability has been disabled)
   88.42 -else
   88.43 +  else
   88.44 +CONFIG_PASSTHROUGH=1
   88.45 +  endif
   88.46 +endif
   88.47 +
   88.48 +ifdef CONFIG_PASSTHROUGH
   88.49  LIBS+=-lpci
   88.50  VL_OBJS+= pass-through.o
   88.51  CFLAGS += -DCONFIG_PASSTHROUGH
   88.52 @@ -404,13 +419,13 @@ VL_OBJS+= ne2000.o rtl8139.o pcnet.o e10
   88.53  
   88.54  ifeq ($(TARGET_BASE_ARCH), i386)
   88.55  # Hardware support
   88.56 -VL_OBJS+= ide.o pckbd.o ps2.o vga.o $(SOUND_HW) dma.o $(AUDIODRV) extboot.o
   88.57 +VL_OBJS+= ide.o pckbd.o ps2.o vga.o dma.o extboot.o
   88.58  ifeq ($(ARCH),ia64)
   88.59  VL_OBJS+= fdc.o mc146818rtc.o serial.o pc.o
   88.60  else
   88.61  VL_OBJS+= fdc.o serial.o pc.o
   88.62  endif
   88.63 -VL_OBJS+= cirrus_vga.o mixeng.o parallel.o acpi.o
   88.64 +VL_OBJS+= cirrus_vga.o parallel.o acpi.o
   88.65  VL_OBJS+= usb-uhci.o smbus_eeprom.o
   88.66  VL_OBJS+= piix4acpi.o
   88.67  VL_OBJS+= xenstore.o
   88.68 @@ -419,22 +434,32 @@ VL_OBJS+= xen_machine_fv.o
   88.69  VL_OBJS+= xen_machine_pv.o
   88.70  VL_OBJS+= xenfb.o
   88.71  VL_OBJS+= xen_console.o
   88.72 +ifndef CONFIG_STUBDOM
   88.73  VL_OBJS+= tpm_tis.o
   88.74 +VL_OBJS+= $(SOUND_HW) $(AUDIODRV) mixeng.o 
   88.75 +CPPFLAGS += -DHAS_TPM
   88.76  CPPFLAGS += -DHAS_AUDIO
   88.77  endif
   88.78 +endif
   88.79  ifeq ($(TARGET_BASE_ARCH), ppc)
   88.80 -VL_OBJS+= ppc.o ide.o pckbd.o ps2.o vga.o $(SOUND_HW) dma.o $(AUDIODRV)
   88.81 +VL_OBJS+= ppc.o ide.o pckbd.o ps2.o vga.o dma.o
   88.82  VL_OBJS+= mc146818rtc.o serial.o i8259.o i8254.o fdc.o m48t59.o
   88.83  VL_OBJS+= ppc_prep.o ppc_chrp.o cuda.o adb.o openpic.o heathrow_pic.o mixeng.o
   88.84  VL_OBJS+= grackle_pci.o prep_pci.o unin_pci.o
   88.85 +ifndef CONFIG_STUBDOM
   88.86 +VL_OBJS+= $(SOUND_HW) $(AUDIODRV) 
   88.87  CPPFLAGS += -DHAS_AUDIO
   88.88  endif
   88.89 +endif
   88.90  ifeq ($(TARGET_ARCH), mips)
   88.91  VL_OBJS+= mips_r4k.o mips_malta.o mips_timer.o mips_int.o dma.o vga.o serial.o i8254.o i8259.o
   88.92  VL_OBJS+= ide.o gt64xxx.o pckbd.o ps2.o fdc.o mc146818rtc.o usb-uhci.o acpi.o
   88.93 -VL_OBJS+= piix_pci.o parallel.o mixeng.o cirrus_vga.o $(SOUND_HW) $(AUDIODRV)
   88.94 +VL_OBJS+= piix_pci.o parallel.o mixeng.o cirrus_vga.o
   88.95 +ifndef CONFIG_STUBDOM
   88.96 +VL_OBJS+= $(SOUND_HW) $(AUDIODRV) 
   88.97  DEFINES += -DHAS_AUDIO
   88.98  endif
   88.99 +endif
  88.100  ifeq ($(TARGET_BASE_ARCH), sparc)
  88.101  ifeq ($(TARGET_ARCH), sparc64)
  88.102  VL_OBJS+= sun4u.o ide.o pckbd.o ps2.o vga.o apb_pci.o
  88.103 @@ -512,7 +537,11 @@ SDL_LIBS := $(filter-out -mwindows, $(SD
  88.104  endif
  88.105  
  88.106  $(QEMU_SYSTEM): $(VL_OBJS) libqemu.a
  88.107 +ifdef CONFIG_STUBDOM
  88.108 +	$(AR) rcs $@ $(VL_OBJS)
  88.109 +else
  88.110  	$(CC) $(VL_LDFLAGS) -o $@ $^ $(LIBS) $(SDL_LIBS) $(COCOA_LIBS) $(VL_LIBS)
  88.111 +endif
  88.112  
  88.113  cocoa.o: cocoa.m
  88.114  	$(CC) $(CFLAGS) $(CPPFLAGS) $(BASE_CFLAGS) -c -o $@ $<
    89.1 --- a/tools/ioemu/aes.c	Wed Feb 13 10:37:18 2008 -0700
    89.2 +++ b/tools/ioemu/aes.c	Thu Feb 14 09:34:27 2008 -0700
    89.3 @@ -33,9 +33,11 @@
    89.4  #define NDEBUG
    89.5  #include <assert.h>
    89.6  
    89.7 +#ifndef CONFIG_STUBDOM
    89.8  typedef uint32_t u32;
    89.9  typedef uint16_t u16;
   89.10  typedef uint8_t u8;
   89.11 +#endif
   89.12  
   89.13  #define MAXKC   (256/32)
   89.14  #define MAXKB   (256/8)
    90.1 --- a/tools/ioemu/block-raw.c	Wed Feb 13 10:37:18 2008 -0700
    90.2 +++ b/tools/ioemu/block-raw.c	Thu Feb 14 09:34:27 2008 -0700
    90.3 @@ -25,7 +25,9 @@
    90.4  #include "block_int.h"
    90.5  #include <assert.h>
    90.6  #ifndef _WIN32
    90.7 +#ifndef NO_AIO
    90.8  #include <aio.h>
    90.9 +#endif
   90.10  
   90.11  #ifndef QEMU_TOOL
   90.12  #include "exec-all.h"
   90.13 @@ -167,10 +169,16 @@ static int raw_pread(BlockDriverState *b
   90.14      }
   90.15      s->lseek_err_cnt=0;
   90.16  
   90.17 -    ret = read(s->fd, buf, count);
   90.18 -    if (ret == count) 
   90.19 -        goto label__raw_read__success;
   90.20 +    uint64_t done;
   90.21 +    for (done = 0; done < count; done += ret) {
   90.22 +	ret = read(s->fd, buf + done, count - done);
   90.23 +	if (ret == -1) 
   90.24 +	    goto label__raw_read__error;
   90.25 +    }
   90.26 +    ret = count;
   90.27 +    goto label__raw_read__success;
   90.28      
   90.29 +label__raw_read__error:
   90.30      DEBUG_BLOCK_PRINT("raw_read(%d:%s, %" PRId64 ", %p, %d) [%" PRId64 "] read failed %d : %d = %s\n", 
   90.31          s->fd, 
   90.32          bs->filename, 
   90.33 @@ -232,9 +240,16 @@ static int raw_pwrite(BlockDriverState *
   90.34      }
   90.35      s->lseek_err_cnt = 0;
   90.36  
   90.37 -    ret = write(s->fd, buf, count);
   90.38 -    if (ret == count) 
   90.39 -        goto label__raw_write__success;
   90.40 +    uint64_t done;
   90.41 +    for (done = 0; done < count; done += ret) {
   90.42 +	ret = write(s->fd, buf + done, count - done);
   90.43 +	if (ret == -1) 
   90.44 +	    goto label__raw_write__error;
   90.45 +    }
   90.46 +    ret = count;
   90.47 +    goto label__raw_write__success;
   90.48 +
   90.49 +label__raw_write__error:
   90.50      
   90.51      DEBUG_BLOCK_PRINT("raw_write(%d:%s, %" PRId64 ", %p, %d) [%" PRId64 "] write failed %d : %d = %s\n", 
   90.52          s->fd, 
   90.53 @@ -255,6 +270,7 @@ label__raw_write__success:
   90.54  /***********************************************************/
   90.55  /* Unix AIO using POSIX AIO */
   90.56  
   90.57 +#ifndef NO_AIO
   90.58  typedef struct RawAIOCB {
   90.59      BlockDriverAIOCB common;
   90.60      struct aiocb aiocb;
   90.61 @@ -480,6 +496,7 @@ static void raw_aio_cancel(BlockDriverAI
   90.62          pacb = &acb->next;
   90.63      }
   90.64  }
   90.65 +#endif
   90.66  
   90.67  static void raw_close(BlockDriverState *bs)
   90.68  {
   90.69 @@ -600,10 +617,12 @@ BlockDriver bdrv_raw = {
   90.70      raw_create,
   90.71      raw_flush,
   90.72      
   90.73 +#ifndef NO_AIO
   90.74      .bdrv_aio_read = raw_aio_read,
   90.75      .bdrv_aio_write = raw_aio_write,
   90.76      .bdrv_aio_cancel = raw_aio_cancel,
   90.77      .aiocb_size = sizeof(RawAIOCB),
   90.78 +#endif
   90.79      .protocol_name = "file",
   90.80      .bdrv_pread = raw_pread,
   90.81      .bdrv_pwrite = raw_pwrite,
   90.82 @@ -936,10 +955,12 @@ BlockDriver bdrv_host_device = {
   90.83      NULL,
   90.84      raw_flush,
   90.85      
   90.86 +#ifndef NO_AIO
   90.87      .bdrv_aio_read = raw_aio_read,
   90.88      .bdrv_aio_write = raw_aio_write,
   90.89      .bdrv_aio_cancel = raw_aio_cancel,
   90.90      .aiocb_size = sizeof(RawAIOCB),
   90.91 +#endif
   90.92      .bdrv_pread = raw_pread,
   90.93      .bdrv_pwrite = raw_pwrite,
   90.94      .bdrv_getlength = raw_getlength,
    91.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    91.2 +++ b/tools/ioemu/block-vbd.c	Thu Feb 14 09:34:27 2008 -0700
    91.3 @@ -0,0 +1,345 @@
    91.4 +/*
    91.5 + * Block driver for Mini-os PV devices
    91.6 + * Based on block-raw.c
    91.7 + * 
    91.8 + * Copyright (c) 2006 Fabrice Bellard, 2007 Samuel Thibault
    91.9 + * 
   91.10 + * Permission is hereby granted, free of charge, to any person obtaining a copy
   91.11 + * of this software and associated documentation files (the "Software"), to deal
   91.12 + * in the Software without restriction, including without limitation the rights
   91.13 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   91.14 + * copies of the Software, and to permit persons to whom the Software is
   91.15 + * furnished to do so, subject to the following conditions:
   91.16 + *
   91.17 + * The above copyright notice and this permission notice shall be included in
   91.18 + * all copies or substantial portions of the Software.
   91.19 + *
   91.20 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   91.21 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   91.22 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
   91.23 + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   91.24 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   91.25 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   91.26 + * THE SOFTWARE.
   91.27 + */
   91.28 +#include "vl.h"
   91.29 +#include "block_int.h"
   91.30 +#include <assert.h>
   91.31 +#include <xenbus.h>
   91.32 +#include <blkfront.h>
   91.33 +#include <malloc.h>
   91.34 +
   91.35 +#define SECTOR_SIZE 512
   91.36 +
   91.37 +#ifndef QEMU_TOOL
   91.38 +#include "exec-all.h"
   91.39 +#endif
   91.40 +
   91.41 +#define DEBUG_BLOCK
   91.42 +#ifdef  DEBUG_BLOCK
   91.43 +#define DEBUG_BLOCK_PRINT( formatCstr, args... ) fprintf( logfile, formatCstr, ##args ); fflush( logfile )
   91.44 +#else
   91.45 +#define DEBUG_BLOCK_PRINT( formatCstr, args... )
   91.46 +#endif
   91.47 +
   91.48 +#define FTYPE_FILE   0
   91.49 +#define FTYPE_CD     1
   91.50 +#define FTYPE_FD     2
   91.51 +
   91.52 +typedef struct BDRVVbdState {
   91.53 +    struct blkfront_dev *dev;
   91.54 +    int fd;
   91.55 +    int type;
   91.56 +    int mode;
   91.57 +    uint64_t sectors;
   91.58 +    unsigned sector_size;
   91.59 +    QEMU_LIST_ENTRY(BDRVVbdState) list;
   91.60 +} BDRVVbdState;
   91.61 +
   91.62 +QEMU_LIST_HEAD(, BDRVVbdState) vbds;
   91.63 +
   91.64 +static int vbd_probe(const uint8_t *buf, int buf_size, const char *filename)
   91.65 +{
   91.66 +    char *value;
   91.67 +    if (xenbus_read(XBT_NIL, filename, &value))
   91.68 +	return 0;
   91.69 +    free(value);
   91.70 +    return 100;
   91.71 +}
   91.72 +
   91.73 +static void vbd_io_completed(void *opaque)
   91.74 +{
   91.75 +    BDRVVbdState *s = opaque;
   91.76 +    blkfront_aio_poll(s->dev);
   91.77 +}
   91.78 +
   91.79 +static int vbd_open(BlockDriverState *bs, const char *filename, int flags)
   91.80 +{
   91.81 +    BDRVVbdState *s = bs->opaque;
   91.82 +
   91.83 +    //handy to test posix access
   91.84 +    //return -EIO;
   91.85 +
   91.86 +    s->dev = init_blkfront((char *) filename, &s->sectors, &s->sector_size, &s->mode);
   91.87 +
   91.88 +    if (!s->dev)
   91.89 +	return -EIO;
   91.90 +
   91.91 +    if (SECTOR_SIZE % s->sector_size) {
   91.92 +	printf("sector size is %d, we only support sector sizes that divide %d\n", s->sector_size, SECTOR_SIZE);
   91.93 +	return -EIO;
   91.94 +    }
   91.95 +
   91.96 +    s->fd = blkfront_open(s->dev);
   91.97 +    qemu_set_fd_handler(s->fd, vbd_io_completed, NULL, s);
   91.98 +
   91.99 +    QEMU_LIST_INSERT_HEAD(&vbds, s, list);
  91.100 +
  91.101 +    return 0;
  91.102 +}
  91.103 +
  91.104 +typedef struct VbdAIOCB {
  91.105 +    BlockDriverAIOCB common;
  91.106 +    struct blkfront_aiocb aiocb;
  91.107 +} VbdAIOCB;
  91.108 +
  91.109 +void qemu_aio_init(void)
  91.110 +{
  91.111 +}
  91.112 +
  91.113 +void qemu_aio_poll(void)
  91.114 +{
  91.115 +}
  91.116 +
  91.117 +/* Wait for all IO requests to complete.  */
  91.118 +void qemu_aio_flush(void)
  91.119 +{
  91.120 +    BDRVVbdState *s;
  91.121 +    for (s = vbds.lh_first; s; s = s->list.le_next)
  91.122 +	blkfront_sync(s->dev);
  91.123 +}
  91.124 +
  91.125 +void qemu_aio_wait_start(void)
  91.126 +{
  91.127 +}
  91.128 +
  91.129 +void qemu_aio_wait(void)
  91.130 +{
  91.131 +    int some = 0;
  91.132 +    DEFINE_WAIT(w);
  91.133 +    while (1) {
  91.134 +	BDRVVbdState *s;
  91.135 +	add_waiter(w, blkfront_queue);
  91.136 +        for (s = vbds.lh_first; s; s = s->list.le_next)
  91.137 +	    if (blkfront_aio_poll(s->dev))
  91.138 +		some = 1;
  91.139 +	if (some)
  91.140 +	    break;
  91.141 +	schedule();
  91.142 +    }
  91.143 +    remove_waiter(w);
  91.144 +}
  91.145 +
  91.146 +void qemu_aio_wait_end(void)
  91.147 +{
  91.148 +}
  91.149 +
  91.150 +static void vbd_aio_callback(struct blkfront_aiocb *aiocbp, int ret) {
  91.151 +    VbdAIOCB *acb = aiocbp->data;
  91.152 +
  91.153 +    acb->common.cb(acb->common.opaque, ret);
  91.154 +    qemu_aio_release(acb);
  91.155 +}
  91.156 +
  91.157 +static VbdAIOCB *vbd_aio_setup(BlockDriverState *bs,
  91.158 +        int64_t sector_num, uint8_t *buf, int nb_sectors,
  91.159 +        BlockDriverCompletionFunc *cb, void *opaque)
  91.160 +{
  91.161 +    BDRVVbdState *s = bs->opaque;
  91.162 +    VbdAIOCB *acb;
  91.163 +
  91.164 +    acb = qemu_aio_get(bs, cb, opaque);
  91.165 +    if (!acb)
  91.166 +	return NULL;
  91.167 +    acb->aiocb.aio_dev = s->dev;
  91.168 +    acb->aiocb.aio_buf = buf;
  91.169 +    acb->aiocb.aio_nbytes = nb_sectors * SECTOR_SIZE;
  91.170 +    acb->aiocb.aio_offset = sector_num * SECTOR_SIZE;
  91.171 +    acb->aiocb.aio_cb = vbd_aio_callback;
  91.172 +    acb->aiocb.data = acb;
  91.173 +
  91.174 +    return acb;
  91.175 +}
  91.176 +
  91.177 +static BlockDriverAIOCB *vbd_aio_read(BlockDriverState *bs,
  91.178 +        int64_t sector_num, uint8_t *buf, int nb_sectors,
  91.179 +        BlockDriverCompletionFunc *cb, void *opaque)
  91.180 +{
  91.181 +    VbdAIOCB *acb;
  91.182 +
  91.183 +    acb = vbd_aio_setup(bs, sector_num, buf, nb_sectors, cb, opaque);
  91.184 +    if (!acb)
  91.185 +	return NULL;
  91.186 +    blkfront_aio(&acb->aiocb, 0);
  91.187 +    return &acb->common;
  91.188 +}
  91.189 +
  91.190 +static BlockDriverAIOCB *vbd_aio_write(BlockDriverState *bs,
  91.191 +        int64_t sector_num, const uint8_t *buf, int nb_sectors,
  91.192 +        BlockDriverCompletionFunc *cb, void *opaque)
  91.193 +{
  91.194 +    VbdAIOCB *acb;
  91.195 +
  91.196 +    acb = vbd_aio_setup(bs, sector_num, (uint8_t*) buf, nb_sectors, cb, opaque);
  91.197 +    if (!acb)
  91.198 +	return NULL;
  91.199 +    blkfront_aio(&acb->aiocb, 1);
  91.200 +    return &acb->common;
  91.201 +}
  91.202 +
  91.203 +static void vbd_cb(void *data, int ret) {
  91.204 +    int *result = data;
  91.205 +    result[0] = 1;
  91.206 +    result[1] = ret;
  91.207 +}
  91.208 +
  91.209 +static int vbd_aligned_io(BlockDriverState *bs,
  91.210 +	int64_t sector_num, uint8_t *buf, int nb_sectors, int write)
  91.211 +{
  91.212 +    VbdAIOCB *acb;
  91.213 +    int result[2];
  91.214 +    result[0] = 0;
  91.215 +    qemu_aio_wait_start();
  91.216 +    acb = vbd_aio_setup(bs, sector_num, (uint8_t*) buf, nb_sectors, vbd_cb, &result);
  91.217 +    blkfront_aio(&acb->aiocb, write);
  91.218 +    while (!result[0])
  91.219 +	qemu_aio_wait();
  91.220 +    qemu_aio_wait_end();
  91.221 +    return result[1];
  91.222 +}
  91.223 +
  91.224 +static int vbd_read(BlockDriverState *bs,
  91.225 +	int64_t sector_num, uint8_t *buf, int nb_sectors)
  91.226 +{
  91.227 +    uint8_t *iobuf;
  91.228 +    int ret;
  91.229 +    /* page alignment would be a bit better, but that's still fine compared to
  91.230 +     * copying */
  91.231 +    if (!((uintptr_t)buf & (SECTOR_SIZE-1)))
  91.232 +	return vbd_aligned_io(bs, sector_num, buf, nb_sectors, 0);
  91.233 +    iobuf = qemu_memalign(PAGE_SIZE, nb_sectors * SECTOR_SIZE);
  91.234 +    ret = vbd_aligned_io(bs, sector_num, iobuf, nb_sectors, 0);
  91.235 +    memcpy(buf, iobuf, nb_sectors * SECTOR_SIZE);
  91.236 +    free(iobuf);
  91.237 +    if (ret < 0)
  91.238 +	return ret;
  91.239 +    else if (ret != nb_sectors * SECTOR_SIZE)
  91.240 +	return -EINVAL;
  91.241 +    else
  91.242 +	return 0;
  91.243 +}
  91.244 +
  91.245 +static int vbd_write(BlockDriverState *bs,
  91.246 +	int64_t sector_num, const uint8_t *buf, int nb_sectors)
  91.247 +{
  91.248 +    uint8_t *iobuf;
  91.249 +    int ret;
  91.250 +    if (!((uintptr_t)buf & (SECTOR_SIZE-1)))
  91.251 +	return vbd_aligned_io(bs, sector_num, (uint8_t*) buf, nb_sectors, 1);
  91.252 +    iobuf = qemu_memalign(PAGE_SIZE, nb_sectors * SECTOR_SIZE);
  91.253 +    memcpy(iobuf, buf, nb_sectors * SECTOR_SIZE);
  91.254 +    ret = vbd_aligned_io(bs, sector_num, iobuf, nb_sectors, 1);
  91.255 +    free(iobuf);
  91.256 +    if (ret < 0)
  91.257 +	return ret;
  91.258 +    else if (ret != nb_sectors * SECTOR_SIZE)
  91.259 +	return -EINVAL;
  91.260 +    else
  91.261 +	return 0;
  91.262 +}
  91.263 +
  91.264 +static void vbd_aio_cancel(BlockDriverAIOCB *blockacb)
  91.265 +{
  91.266 +    /* TODO */
  91.267 +    //VbdAIOCB *acb = (VbdAIOCB *)blockacb;
  91.268 +
  91.269 +    // Try to cancel. If can't, wait for it, drop the callback and call qemu_aio_release(acb)
  91.270 +}
  91.271 +
  91.272 +static void vbd_close(BlockDriverState *bs)
  91.273 +{
  91.274 +    BDRVVbdState *s = bs->opaque;
  91.275 +    bs->total_sectors = 0;
  91.276 +    if (s->fd >= 0) {
  91.277 +        close(s->fd);
  91.278 +        s->fd = -1;
  91.279 +    }
  91.280 +    QEMU_LIST_REMOVE(s, list);
  91.281 +}
  91.282 +
  91.283 +static int64_t  vbd_getlength(BlockDriverState *bs)
  91.284 +{
  91.285 +    BDRVVbdState *s = bs->opaque;
  91.286 +    return s->sectors * s->sector_size;
  91.287 +}
  91.288 +
  91.289 +static void vbd_flush(BlockDriverState *bs)
  91.290 +{
  91.291 +    BDRVVbdState *s = bs->opaque;
  91.292 +    blkfront_sync(s->dev);
  91.293 +}
  91.294 +
  91.295 +/***********************************************/
  91.296 +/* host device */
  91.297 +
  91.298 +static int vbd_is_inserted(BlockDriverState *bs)
  91.299 +{
  91.300 +    /* TODO: monitor the backend */
  91.301 +    return 1;
  91.302 +}
  91.303 +
  91.304 +/* currently only used by fdc.c, but a CD version would be good too */
  91.305 +static int vbd_media_changed(BlockDriverState *bs)
  91.306 +{
  91.307 +    /* TODO: monitor the backend */
  91.308 +    return -ENOTSUP;
  91.309 +}
  91.310 +
  91.311 +static int vbd_eject(BlockDriverState *bs, int eject_flag)
  91.312 +{
  91.313 +    /* TODO: Xen support needed */
  91.314 +    return -ENOTSUP;
  91.315 +}
  91.316 +
  91.317 +static int vbd_set_locked(BlockDriverState *bs, int locked)
  91.318 +{
  91.319 +    /* TODO: Xen support needed */
  91.320 +    return -ENOTSUP;
  91.321 +}
  91.322 +
  91.323 +BlockDriver bdrv_vbd = {
  91.324 +    "vbd",
  91.325 +    sizeof(BDRVVbdState),
  91.326 +    vbd_probe,
  91.327 +    vbd_open,
  91.328 +    NULL,
  91.329 +    NULL,
  91.330 +    vbd_close,
  91.331 +    NULL,
  91.332 +    vbd_flush,
  91.333 +    
  91.334 +    .bdrv_aio_read = vbd_aio_read,
  91.335 +    .bdrv_aio_write = vbd_aio_write,
  91.336 +    .bdrv_aio_cancel = vbd_aio_cancel,
  91.337 +    .aiocb_size = sizeof(VbdAIOCB),
  91.338 +    .bdrv_read = vbd_read,
  91.339 +    .bdrv_write = vbd_write,
  91.340 +    .bdrv_getlength = vbd_getlength,
  91.341 +
  91.342 +    /* removable device support */
  91.343 +    .bdrv_is_inserted = vbd_is_inserted,
  91.344 +    .bdrv_media_changed = vbd_media_changed,
  91.345 +    .bdrv_eject = vbd_eject,
  91.346 +    .bdrv_set_locked = vbd_set_locked,
  91.347 +};
  91.348 +
    92.1 --- a/tools/ioemu/block.c	Wed Feb 13 10:37:18 2008 -0700
    92.2 +++ b/tools/ioemu/block.c	Thu Feb 14 09:34:27 2008 -0700
    92.3 @@ -1235,6 +1235,9 @@ void bdrv_init(void)
    92.4  {
    92.5      bdrv_register(&bdrv_raw);
    92.6      bdrv_register(&bdrv_host_device);
    92.7 +#ifdef CONFIG_STUBDOM
    92.8 +    bdrv_register(&bdrv_vbd);
    92.9 +#endif
   92.10  #ifndef _WIN32
   92.11      bdrv_register(&bdrv_cow);
   92.12  #endif
    93.1 --- a/tools/ioemu/configure	Wed Feb 13 10:37:18 2008 -0700
    93.2 +++ b/tools/ioemu/configure	Thu Feb 14 09:34:27 2008 -0700
    93.3 @@ -74,6 +74,7 @@ softmmu="yes"
    93.4  linux_user="no"
    93.5  darwin_user="no"
    93.6  build_docs="no"
    93.7 +stubdom="no"
    93.8  uname_release=""
    93.9  
   93.10  # OS specific
   93.11 @@ -231,6 +232,8 @@ for opt do
   93.12    ;;
   93.13    --enable-uname-release=*) uname_release="$optarg"
   93.14    ;;
   93.15 +  --enable-stubdom) stubdom="yes"
   93.16 +  ;;
   93.17    esac
   93.18  done
   93.19  
   93.20 @@ -416,7 +419,11 @@ if test -z "$target_list" ; then
   93.21          target_list="i386-darwin-user ppc-darwin-user $target_list"
   93.22      fi
   93.23  # the i386-dm target
   93.24 -    target_list="i386-dm"
   93.25 +    if test "$stubdom" = "yes"; then
   93.26 +        target_list="i386-dm-stubdom"
   93.27 +    else
   93.28 +        target_list="i386-dm"
   93.29 +    fi
   93.30  else
   93.31      target_list=`echo "$target_list" | sed -e 's/,/ /g'`
   93.32  fi
   93.33 @@ -575,6 +582,11 @@ bindir="$prefix/$libdir/xen/bin"
   93.34  configdir="/etc/xen"
   93.35  fi
   93.36  
   93.37 +if test "$stubdom" = "yes"; then
   93.38 +    oss="no"
   93.39 +    sdl="no"
   93.40 +fi
   93.41 +
   93.42  echo "Install prefix    $prefix"
   93.43  echo "BIOS directory    $datadir"
   93.44  echo "binary directory  $bindir"
   93.45 @@ -943,6 +955,14 @@ if expr $target : '.*-dm' > /dev/null ; 
   93.46    echo "#define CONFIG_DM 1" >> $config_h
   93.47  fi
   93.48  
   93.49 +if test "$stubdom" = "yes" ; then
   93.50 +  echo "CONFIG_STUBDOM=yes" >> $config_mak
   93.51 +  echo "#define CONFIG_STUBDOM 1" >> $config_h
   93.52 +  echo "#define NO_UNIX_SOCKETS 1" >> $config_h
   93.53 +  echo "#define NO_DAEMONIZE 1" >> $config_h
   93.54 +  echo "#define NO_AIO 1" >> $config_h
   93.55 +fi
   93.56 +
   93.57  if test "$target_cpu" = "arm" -o "$target_cpu" = "armeb" -o "$target_cpu" = "sparc" -o "$target_cpu" = "sparc64" -o "$target_cpu" = "m68k"; then
   93.58    echo "CONFIG_SOFTFLOAT=yes" >> $config_mak
   93.59    echo "#define CONFIG_SOFTFLOAT 1" >> $config_h
    94.1 --- a/tools/ioemu/console.c	Wed Feb 13 10:37:18 2008 -0700
    94.2 +++ b/tools/ioemu/console.c	Thu Feb 14 09:34:27 2008 -0700
    94.3 @@ -169,16 +169,12 @@ static unsigned int vga_get_color(Displa
    94.4      unsigned int r, g, b, color;
    94.5  
    94.6      switch(ds->depth) {
    94.7 -#if 0
    94.8      case 8:
    94.9          r = (rgba >> 16) & 0xff;
   94.10          g = (rgba >> 8) & 0xff;
   94.11          b = (rgba) & 0xff;
   94.12 -        color = (rgb_to_index[r] * 6 * 6) + 
   94.13 -            (rgb_to_index[g] * 6) + 
   94.14 -            (rgb_to_index[b]);
   94.15 +        color = ((r >> 5) << 5 | (g >> 5) << 2 | (b >> 6));
   94.16          break;
   94.17 -#endif
   94.18      case 15:
   94.19          r = (rgba >> 16) & 0xff;
   94.20          g = (rgba >> 8) & 0xff;
    95.1 --- a/tools/ioemu/cpu-all.h	Wed Feb 13 10:37:18 2008 -0700
    95.2 +++ b/tools/ioemu/cpu-all.h	Thu Feb 14 09:34:27 2008 -0700
    95.3 @@ -116,6 +116,7 @@ static inline void tswap64s(uint64_t *s)
    95.4  #define bswaptls(s) bswap64s(s)
    95.5  #endif
    95.6  
    95.7 +#ifdef CONFIG_SOFTFLOAT
    95.8  /* NOTE: arm FPA is horrible as double 32 bit words are stored in big
    95.9     endian ! */
   95.10  typedef union {
   95.11 @@ -134,6 +135,7 @@ typedef union {
   95.12  #endif
   95.13      uint64_t ll;
   95.14  } CPU_DoubleU;
   95.15 +#endif
   95.16  
   95.17  /* CPU memory access without any memory or io remapping */
   95.18  
   95.19 @@ -267,6 +269,7 @@ static inline void stq_le_p(void *ptr, u
   95.20      stl_le_p(p + 4, v >> 32);
   95.21  }
   95.22  
   95.23 +#ifdef CONFIG_SOFTFLOAT
   95.24  /* float access */
   95.25  
   95.26  static inline float32 ldfl_le_p(void *ptr)
   95.27 @@ -304,6 +307,7 @@ static inline void stfq_le_p(void *ptr, 
   95.28      stl_le_p(ptr, u.l.lower);
   95.29      stl_le_p(ptr + 4, u.l.upper);
   95.30  }
   95.31 +#endif
   95.32  
   95.33  #else
   95.34  
   95.35 @@ -342,6 +346,7 @@ static inline void stq_le_p(void *ptr, u
   95.36      *(uint64_t *)ptr = v;
   95.37  }
   95.38  
   95.39 +#ifdef CONFIG_SOFTFLOAT
   95.40  /* float access */
   95.41  
   95.42  static inline float32 ldfl_le_p(void *ptr)
   95.43 @@ -364,6 +369,7 @@ static inline void stfq_le_p(void *ptr, 
   95.44      *(float64 *)ptr = v;
   95.45  }
   95.46  #endif
   95.47 +#endif
   95.48  
   95.49  #if !defined(WORDS_BIGENDIAN) || defined(WORDS_ALIGNED)
   95.50  
   95.51 @@ -456,6 +462,7 @@ static inline void stq_be_p(void *ptr, u
   95.52      stl_be_p(ptr + 4, v);
   95.53  }
   95.54  
   95.55 +#ifdef CONFIG_SOFTFLOAT
   95.56  /* float access */
   95.57  
   95.58  static inline float32 ldfl_be_p(void *ptr)
   95.59 @@ -493,6 +500,7 @@ static inline void stfq_be_p(void *ptr, 
   95.60      stl_be_p(ptr, u.l.upper);
   95.61      stl_be_p(ptr + 4, u.l.lower);
   95.62  }
   95.63 +#endif
   95.64  
   95.65  #else
   95.66  
   95.67 @@ -531,6 +539,7 @@ static inline void stq_be_p(void *ptr, u
   95.68      *(uint64_t *)ptr = v;
   95.69  }
   95.70  
   95.71 +#ifdef CONFIG_SOFTFLOAT
   95.72  /* float access */
   95.73  
   95.74  static inline float32 ldfl_be_p(void *ptr)
   95.75 @@ -552,6 +561,7 @@ static inline void stfq_be_p(void *ptr, 
   95.76  {
   95.77      *(float64 *)ptr = v;
   95.78  }
   95.79 +#endif
   95.80  
   95.81  #endif
   95.82  
    96.1 --- a/tools/ioemu/exec-all.h	Wed Feb 13 10:37:18 2008 -0700
    96.2 +++ b/tools/ioemu/exec-all.h	Thu Feb 14 09:34:27 2008 -0700
    96.3 @@ -481,6 +481,9 @@ static inline int testandset (int *p)
    96.4  }
    96.5  #endif
    96.6  
    96.7 +#ifdef CONFIG_STUBDOM
    96.8 +#include <spinlock.h>
    96.9 +#else
   96.10  typedef int spinlock_t;
   96.11  
   96.12  #define SPIN_LOCK_UNLOCKED 0
   96.13 @@ -514,6 +517,7 @@ static inline int spin_trylock(spinlock_
   96.14      return 1;
   96.15  }
   96.16  #endif
   96.17 +#endif
   96.18  
   96.19  extern spinlock_t tb_lock;
   96.20  
    97.1 --- a/tools/ioemu/hw/fdc.c	Wed Feb 13 10:37:18 2008 -0700
    97.2 +++ b/tools/ioemu/hw/fdc.c	Thu Feb 14 09:34:27 2008 -0700
    97.3 @@ -378,7 +378,7 @@ struct fdctrl_t {
    97.4      uint8_t cur_drv;
    97.5      uint8_t bootsel;
    97.6      /* Command FIFO */
    97.7 -    uint8_t fifo[FD_SECTOR_LEN];
    97.8 +    uint8_t *fifo;
    97.9      uint32_t data_pos;
   97.10      uint32_t data_len;
   97.11      uint8_t data_state;
   97.12 @@ -497,6 +497,11 @@ fdctrl_t *fdctrl_init (int irq_lvl, int 
   97.13      fdctrl = qemu_mallocz(sizeof(fdctrl_t));
   97.14      if (!fdctrl)
   97.15          return NULL;
   97.16 +    fdctrl->fifo = qemu_memalign(512, FD_SECTOR_LEN);
   97.17 +    if (fdctrl->fifo == NULL) {
   97.18 +        qemu_free(fdctrl);
   97.19 +        return NULL;
   97.20 +    }
   97.21      fdctrl->result_timer = qemu_new_timer(vm_clock, 
   97.22                                            fdctrl_result_timer, fdctrl);
   97.23  
    98.1 --- a/tools/ioemu/hw/ide.c	Wed Feb 13 10:37:18 2008 -0700
    98.2 +++ b/tools/ioemu/hw/ide.c	Thu Feb 14 09:34:27 2008 -0700
    98.3 @@ -22,6 +22,7 @@
    98.4   * THE SOFTWARE.
    98.5   */
    98.6  #include "vl.h"
    98.7 +#include <malloc.h>
    98.8  
    98.9  /* debug IDE devices */
   98.10  //#define DEBUG_IDE
   98.11 @@ -347,7 +348,7 @@ typedef struct IDEState {
   98.12      EndTransferFunc *end_transfer_func;
   98.13      uint8_t *data_ptr;
   98.14      uint8_t *data_end;
   98.15 -    uint8_t io_buffer[MAX_MULT_SECTORS*512 + 4];
   98.16 +    uint8_t *io_buffer;
   98.17      QEMUTimer *sector_write_timer; /* only used for win2k instal hack */
   98.18      uint32_t irq_count; /* counts IRQs when using win2k install hack */
   98.19  } IDEState;
   98.20 @@ -2305,6 +2306,7 @@ static void ide_init2(IDEState *ide_stat
   98.21  
   98.22      for(i = 0; i < 2; i++) {
   98.23          s = ide_state + i;
   98.24 +        s->io_buffer = qemu_memalign(getpagesize(), MAX_MULT_SECTORS*512 + 4);
   98.25          if (i == 0)
   98.26              s->bs = hd0;
   98.27          else
    99.1 --- a/tools/ioemu/hw/pc.c	Wed Feb 13 10:37:18 2008 -0700
    99.2 +++ b/tools/ioemu/hw/pc.c	Thu Feb 14 09:34:27 2008 -0700
    99.3 @@ -361,6 +361,7 @@ void bochs_bios_init(void)
    99.4      register_ioport_write(0x503, 1, 1, bochs_bios_write, NULL);
    99.5  }
    99.6  
    99.7 +#if defined(__i386__) || defined(__x86_64__)
    99.8  /* Generate an initial boot sector which sets state and jump to
    99.9     a specified vector */
   99.10  static void generate_bootsect(uint32_t gpr[8], uint16_t segs[6], uint16_t ip)
   99.11 @@ -718,6 +719,14 @@ static void load_linux(const char *kerne
   99.12  
   99.13      generate_bootsect(gpr, seg, 0);
   99.14  }
   99.15 +#else /* __ia64__ */
   99.16 +static void load_linux(const char *kernel_filename,
   99.17 +                       const char *initrd_filename,
   99.18 +                       const char *kernel_cmdline)
   99.19 +{
   99.20 +    /* Direct Linux boot is unsupported. */
   99.21 +}
   99.22 +#endif
   99.23  
   99.24  static void main_cpu_reset(void *opaque)
   99.25  {
   99.26 @@ -1013,8 +1022,10 @@ static void pc_init1(uint64_t ram_size, 
   99.27          }
   99.28      }
   99.29  
   99.30 +#ifdef HAS_TPM
   99.31      if (has_tpm_device())
   99.32          tpm_tis_init(&pic_set_irq_new, isa_pic, 11);
   99.33 +#endif
   99.34  
   99.35      kbd_init();
   99.36      DMA_init(0);
   100.1 --- a/tools/ioemu/hw/scsi-disk.c	Wed Feb 13 10:37:18 2008 -0700
   100.2 +++ b/tools/ioemu/hw/scsi-disk.c	Thu Feb 14 09:34:27 2008 -0700
   100.3 @@ -26,13 +26,18 @@ do { printf("scsi-disk: " fmt , ##args);
   100.4  do { fprintf(stderr, "scsi-disk: " fmt , ##args); } while (0)
   100.5  
   100.6  #include "vl.h"
   100.7 +#include <malloc.h>
   100.8  
   100.9  #define SENSE_NO_SENSE        0
  100.10  #define SENSE_NOT_READY       2
  100.11  #define SENSE_HARDWARE_ERROR  4
  100.12  #define SENSE_ILLEGAL_REQUEST 5
  100.13  
  100.14 +#ifdef CONFIG_STUBDOM
  100.15 +#define SCSI_DMA_BUF_SIZE    32768
  100.16 +#else
  100.17  #define SCSI_DMA_BUF_SIZE    65536
  100.18 +#endif
  100.19  
  100.20  typedef struct SCSIRequest {
  100.21      SCSIDevice *dev;
  100.22 @@ -44,7 +49,7 @@ typedef struct SCSIRequest {
  100.23      int sector_count;
  100.24      /* The amounnt of data in the buffer.  */
  100.25      int buf_len;
  100.26 -    uint8_t dma_buf[SCSI_DMA_BUF_SIZE];
  100.27 +    uint8_t *dma_buf;
  100.28      BlockDriverAIOCB *aiocb;
  100.29      struct SCSIRequest *next;
  100.30  } SCSIRequest;
  100.31 @@ -76,6 +81,7 @@ static SCSIRequest *scsi_new_request(SCS
  100.32          free_requests = r->next;
  100.33      } else {
  100.34          r = qemu_malloc(sizeof(SCSIRequest));
  100.35 +	r->dma_buf = qemu_memalign(getpagesize(), SCSI_DMA_BUF_SIZE);
  100.36      }
  100.37      r->dev = s;
  100.38      r->tag = tag;
   101.1 --- a/tools/ioemu/hw/usb-hid.c	Wed Feb 13 10:37:18 2008 -0700
   101.2 +++ b/tools/ioemu/hw/usb-hid.c	Thu Feb 14 09:34:27 2008 -0700
   101.3 @@ -224,15 +224,37 @@ static const uint8_t qemu_tablet_hid_rep
   101.4          0xC0,       /* End Collection */
   101.5  };
   101.6  
   101.7 +static int currentbutton = 0;
   101.8 +typedef struct _mouseclick {
   101.9 +    int button_state;
  101.10 +    struct _mouseclick *next;
  101.11 +} mouseclick; 
  101.12 +static mouseclick mousequeue[20];
  101.13 +static mouseclick *head = mousequeue;
  101.14 +static mouseclick *tail = mousequeue;
  101.15 +
  101.16  static void usb_mouse_event(void *opaque,
  101.17                              int dx1, int dy1, int dz1, int buttons_state)
  101.18  {
  101.19      USBMouseState *s = opaque;
  101.20  
  101.21 +    if (s->status_changed == 1){
  101.22 +        //A mouse event is lost
  101.23 +        if (buttons_state != currentbutton && tail->next != head) {
  101.24 +            //A left click event is lost: let's add it to the queue
  101.25 +            //counter++;
  101.26 +            tail->button_state = buttons_state;
  101.27 +            tail = tail->next;
  101.28 +        }
  101.29 +    }
  101.30 +    else {
  101.31 +        s->buttons_state = buttons_state;
  101.32 +    }
  101.33 +
  101.34      s->dx += dx1;
  101.35      s->dy += dy1;
  101.36      s->dz += dz1;
  101.37 -    s->buttons_state = buttons_state;
  101.38 +    currentbutton = buttons_state;
  101.39      s->status_changed = 1;
  101.40  }
  101.41  
  101.42 @@ -240,11 +262,24 @@ static void usb_tablet_event(void *opaqu
  101.43  			     int x, int y, int dz, int buttons_state)
  101.44  {
  101.45      USBMouseState *s = opaque;
  101.46 +    
  101.47 +    if (s->status_changed == 1){
  101.48 +        //A mouse event is lost
  101.49 +        if (buttons_state != currentbutton && tail->next != head) {
  101.50 +            //A left click event is lost: let's add it to the queue
  101.51 +            //counter++;
  101.52 +            tail->button_state = buttons_state;
  101.53 +            tail = tail->next;
  101.54 +        }
  101.55 +    }
  101.56 +    else {
  101.57 +        s->buttons_state = buttons_state;
  101.58 +    }
  101.59  
  101.60      s->x = x;
  101.61      s->y = y;
  101.62      s->dz += dz;
  101.63 -    s->buttons_state = buttons_state;
  101.64 +    currentbutton = buttons_state;
  101.65      s->status_changed = 1;
  101.66  }
  101.67  
  101.68 @@ -493,10 +528,17 @@ static int usb_mouse_handle_data(USBDevi
  101.69              else if (s->kind == USB_TABLET)
  101.70                  ret = usb_tablet_poll(s, p->data, p->len);
  101.71  
  101.72 -            if (!s->status_changed)
  101.73 +            if (!s->status_changed) {
  101.74                  ret = USB_RET_NAK;
  101.75 -            else
  101.76 -                s->status_changed = 0;
  101.77 +            } else {
  101.78 +                if (head != tail) {
  101.79 +                    s->buttons_state = head->button_state;
  101.80 +                    head = head->next;
  101.81 +                }
  101.82 +                else {
  101.83 +                    s->status_changed = 0;
  101.84 +                }
  101.85 +            }
  101.86  
  101.87          } else {
  101.88              goto fail;
  101.89 @@ -567,6 +609,14 @@ int usb_mouse_load(QEMUFile *f, void *op
  101.90  USBDevice *usb_tablet_init(void)
  101.91  {
  101.92      USBMouseState *s;
  101.93 +    int i;
  101.94 +    
  101.95 +    for (i = 0; i < 19; i++) {
  101.96 +        mousequeue[i].button_state = 0;
  101.97 +        mousequeue[i].next = &(mousequeue[i + 1]);
  101.98 +    }
  101.99 +    mousequeue[i].button_state = 0;
 101.100 +    mousequeue[i].next = mousequeue;
 101.101  
 101.102      s = qemu_mallocz(sizeof(USBMouseState));
 101.103      if (!s)
 101.104 @@ -591,6 +641,14 @@ USBDevice *usb_tablet_init(void)
 101.105  USBDevice *usb_mouse_init(void)
 101.106  {
 101.107      USBMouseState *s;
 101.108 +    int i;
 101.109 +    
 101.110 +    for (i = 0; i < 19; i++) {
 101.111 +        mousequeue[i].button_state = 0;
 101.112 +        mousequeue[i].next = &(mousequeue[i + 1]);
 101.113 +    }
 101.114 +    mousequeue[i].button_state = 0;
 101.115 +    mousequeue[i].next = mousequeue;
 101.116  
 101.117      s = qemu_mallocz(sizeof(USBMouseState));
 101.118      if (!s)
   102.1 --- a/tools/ioemu/hw/vga.c	Wed Feb 13 10:37:18 2008 -0700
   102.2 +++ b/tools/ioemu/hw/vga.c	Thu Feb 14 09:34:27 2008 -0700
   102.3 @@ -1071,7 +1071,7 @@ static const uint8_t cursor_glyph[32 * 4
   102.4   */
   102.5  static void vga_draw_text(VGAState *s, int full_update)
   102.6  {
   102.7 -    int cx, cy, cheight, cw, ch, cattr, height, width, ch_attr;
   102.8 +    int cx, cy, cheight, cw, ch, cattr, height, width, ch_attr, depth;
   102.9      int cx_min, cx_max, linesize, x_incr;
  102.10      uint32_t offset, fgcol, bgcol, v, cursor_offset;
  102.11      uint8_t *d1, *d, *src, *s1, *dest, *cursor_ptr;
  102.12 @@ -1134,6 +1134,11 @@ static void vga_draw_text(VGAState *s, i
  102.13          return;
  102.14      }
  102.15  
  102.16 +    depth = s->get_bpp(s);
  102.17 +    if (depth == 24)
  102.18 +        depth = 32;
  102.19 +    if (s->ds->dpy_colourdepth != NULL && s->ds->depth != depth)
  102.20 +        s->ds->dpy_colourdepth(s->ds, depth);
  102.21      if (width != s->last_width || height != s->last_height ||
  102.22          cw != s->last_cw || cheight != s->last_ch) {
  102.23          s->last_scr_width = width * cw;
  102.24 @@ -1477,7 +1482,7 @@ void check_sse2(void)
  102.25   */
  102.26  static void vga_draw_graphic(VGAState *s, int full_update)
  102.27  {
  102.28 -    int y1, y, update, linesize, y_start, double_scan, mask;
  102.29 +    int y1, y, update, linesize, y_start, double_scan, mask, depth;
  102.30      int width, height, shift_control, line_offset, bwidth;
  102.31      ram_addr_t page0, page1;
  102.32      int disp_width, multi_scan, multi_run;
  102.33 @@ -1551,6 +1556,11 @@ static void vga_draw_graphic(VGAState *s
  102.34      }
  102.35      vga_draw_line = vga_draw_line_table[v * NB_DEPTHS + get_depth_index(s->ds)];
  102.36  
  102.37 +    depth = s->get_bpp(s);
  102.38 +    if (depth == 24)
  102.39 +        depth = 32;
  102.40 +    if (s->ds->dpy_colourdepth != NULL && s->ds->depth != depth)
  102.41 +        s->ds->dpy_colourdepth(s->ds, depth);
  102.42      if (disp_width != s->last_width ||
  102.43          height != s->last_height) {
  102.44          dpy_resize(s->ds, disp_width, height);
   103.1 --- a/tools/ioemu/hw/xen_console.c	Wed Feb 13 10:37:18 2008 -0700
   103.2 +++ b/tools/ioemu/hw/xen_console.c	Thu Feb 14 09:34:27 2008 -0700
   103.3 @@ -75,7 +75,7 @@ static void buffer_append(struct domain 
   103.4  
   103.5  	cons = intf->out_cons;
   103.6  	prod = intf->out_prod;
   103.7 -	mb();
   103.8 +	xen_mb();
   103.9  
  103.10  	size = prod - cons;
  103.11  	if ((size == 0) || (size > sizeof(intf->out)))
  103.12 @@ -94,7 +94,7 @@ static void buffer_append(struct domain 
  103.13  		buffer->data[buffer->size++] = intf->out[
  103.14  			MASK_XENCONS_IDX(cons++, intf->out)];
  103.15  
  103.16 -	mb();
  103.17 +	xen_mb();
  103.18  	intf->out_cons = cons;
  103.19  	xc_evtchn_notify(dom->xce_handle, dom->local_port);
  103.20  
  103.21 @@ -289,7 +289,7 @@ static int ring_free_bytes(struct domain
  103.22  
  103.23  	cons = intf->in_cons;
  103.24  	prod = intf->in_prod;
  103.25 -	mb();
  103.26 +	xen_mb();
  103.27  
  103.28  	space = prod - cons;
  103.29  	if (space > sizeof(intf->in))
  103.30 @@ -322,7 +322,7 @@ static void xencons_receive(void *opaque
  103.31  		intf->in[MASK_XENCONS_IDX(prod++, intf->in)] =
  103.32  			buf[i];
  103.33  	}
  103.34 -	wmb();
  103.35 +	xen_wmb();
  103.36  	intf->in_prod = prod;
  103.37  	xc_evtchn_notify(dom->xce_handle, dom->local_port);
  103.38  }
   104.1 --- a/tools/ioemu/hw/xen_machine_fv.c	Wed Feb 13 10:37:18 2008 -0700
   104.2 +++ b/tools/ioemu/hw/xen_machine_fv.c	Thu Feb 14 09:34:27 2008 -0700
   104.3 @@ -24,6 +24,9 @@
   104.4   */
   104.5  
   104.6  #include "vl.h"
   104.7 +#ifdef CONFIG_STUBDOM
   104.8 +#include <xenbus.h>
   104.9 +#endif
  104.10  #include <xen/hvm/params.h>
  104.11  #include <sys/mman.h>
  104.12  
   105.1 --- a/tools/ioemu/hw/xenfb.c	Wed Feb 13 10:37:18 2008 -0700
   105.2 +++ b/tools/ioemu/hw/xenfb.c	Thu Feb 14 09:34:27 2008 -0700
   105.3 @@ -485,7 +485,7 @@ static void xenfb_on_fb_event(struct xen
   105.4  	prod = page->out_prod;
   105.5  	if (prod == page->out_cons)
   105.6  		return;
   105.7 -	rmb();			/* ensure we see ring contents up to prod */
   105.8 +	xen_rmb();		/* ensure we see ring contents up to prod */
   105.9  	for (cons = page->out_cons; cons != prod; cons++) {
  105.10  		union xenfb_out_event *event = &XENFB_OUT_RING_REF(page, cons);
  105.11  		int x, y, w, h;
  105.12 @@ -512,7 +512,7 @@ static void xenfb_on_fb_event(struct xen
  105.13  			break;
  105.14  		}
  105.15  	}
  105.16 -	mb();			/* ensure we're done with ring contents */
  105.17 +	xen_mb();		/* ensure we're done with ring contents */
  105.18  	page->out_cons = cons;
  105.19  	xc_evtchn_notify(xenfb->evt_xch, xenfb->fb.port);
  105.20  }
  105.21 @@ -571,9 +571,9 @@ static int xenfb_kbd_event(struct xenfb 
  105.22  		return -1;
  105.23  	}
  105.24  
  105.25 -	mb();			/* ensure ring space available */
  105.26 +	xen_mb();		/* ensure ring space available */
  105.27  	XENKBD_IN_RING_REF(page, prod) = *event;
  105.28 -	wmb();			/* ensure ring contents visible */
  105.29 +	xen_wmb();		/* ensure ring contents visible */
  105.30  	page->in_prod = prod + 1;
  105.31  	return xc_evtchn_notify(xenfb->evt_xch, xenfb->kbd.port);
  105.32  }
   106.1 --- a/tools/ioemu/osdep.c	Wed Feb 13 10:37:18 2008 -0700
   106.2 +++ b/tools/ioemu/osdep.c	Thu Feb 14 09:34:27 2008 -0700
   106.3 @@ -61,6 +61,10 @@ void *qemu_malloc(size_t size)
   106.4  }
   106.5  
   106.6  #if defined(_WIN32)
   106.7 +void *qemu_memalign(size_t alignment, size_t size)
   106.8 +{
   106.9 +    return VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE);
  106.10 +}
  106.11  
  106.12  void *qemu_vmalloc(size_t size)
  106.13  {
  106.14 @@ -172,6 +176,22 @@ void kqemu_vfree(void *ptr)
  106.15  
  106.16  #endif
  106.17  
  106.18 +void *qemu_memalign(size_t alignment, size_t size)
  106.19 +{
  106.20 +#if defined(_POSIX_C_SOURCE)
  106.21 +    int ret;
  106.22 +    void *ptr;
  106.23 +    ret = posix_memalign(&ptr, alignment, size);
  106.24 +    if (ret != 0)
  106.25 +        return NULL;
  106.26 +    return ptr;
  106.27 +#elif defined(_BSD)
  106.28 +    return valloc(size);
  106.29 +#else
  106.30 +    return memalign(alignment, size);
  106.31 +#endif
  106.32 +}
  106.33 +
  106.34  /* alloc shared memory pages */
  106.35  void *qemu_vmalloc(size_t size)
  106.36  {
   107.1 --- a/tools/ioemu/osdep.h	Wed Feb 13 10:37:18 2008 -0700
   107.2 +++ b/tools/ioemu/osdep.h	Thu Feb 14 09:34:27 2008 -0700
   107.3 @@ -14,6 +14,7 @@ void *qemu_mallocz(size_t size);
   107.4  void qemu_free(void *ptr);
   107.5  char *qemu_strdup(const char *str);
   107.6  
   107.7 +void *qemu_memalign(size_t alignment, size_t size);
   107.8  void *qemu_vmalloc(size_t size);
   107.9  void qemu_vfree(void *ptr);
  107.10  
   108.1 --- a/tools/ioemu/sdl.c	Wed Feb 13 10:37:18 2008 -0700
   108.2 +++ b/tools/ioemu/sdl.c	Thu Feb 14 09:34:27 2008 -0700
   108.3 @@ -259,11 +259,9 @@ static void sdl_grab_end(void)
   108.4      sdl_update_caption();
   108.5  }
   108.6  
   108.7 -static void sdl_send_mouse_event(int dz)
   108.8 +static void sdl_send_mouse_event(int dx, int dy, int dz, int state)
   108.9  {
  108.10 -    int dx, dy, state, buttons;
  108.11 -    state = SDL_GetRelativeMouseState(&dx, &dy);
  108.12 -    buttons = 0;
  108.13 +    int buttons = 0;
  108.14      if (state & SDL_BUTTON(SDL_BUTTON_LEFT))
  108.15          buttons |= MOUSE_EVENT_LBUTTON;
  108.16      if (state & SDL_BUTTON(SDL_BUTTON_RIGHT))
  108.17 @@ -425,11 +423,19 @@ static void sdl_refresh(DisplayState *ds
  108.18          case SDL_MOUSEMOTION:
  108.19              if (gui_grab || kbd_mouse_is_absolute() ||
  108.20                  absolute_enabled) {
  108.21 -                sdl_send_mouse_event(0);
  108.22 +                int dx, dy, state;
  108.23 +                state = SDL_GetRelativeMouseState(&dx, &dy);
  108.24 +                sdl_send_mouse_event(dx, dy, 0, state);
  108.25 +            }
  108.26 +            break;
  108.27 +        case SDL_MOUSEBUTTONUP:
  108.28 +            if (gui_grab || kbd_mouse_is_absolute()) {
  108.29 +                int dx, dy, state;
  108.30 +                state = SDL_GetRelativeMouseState(&dx, &dy);
  108.31 +                sdl_send_mouse_event(dx, dy, 0, state);
  108.32              }
  108.33              break;
  108.34          case SDL_MOUSEBUTTONDOWN:
  108.35 -        case SDL_MOUSEBUTTONUP:
  108.36              {
  108.37                  SDL_MouseButtonEvent *bev = &ev->button;
  108.38                  if (!gui_grab && !kbd_mouse_is_absolute()) {
  108.39 @@ -439,16 +445,19 @@ static void sdl_refresh(DisplayState *ds
  108.40                          sdl_grab_start();
  108.41                      }
  108.42                  } else {
  108.43 -                    int dz;
  108.44 +                    int dx, dy, dz, state;
  108.45                      dz = 0;
  108.46 +                    state = SDL_GetRelativeMouseState(&dx, &dy);
  108.47  #ifdef SDL_BUTTON_WHEELUP
  108.48 -                    if (bev->button == SDL_BUTTON_WHEELUP && ev->type == SDL_MOUSEBUTTONDOWN) {
  108.49 +                    if (bev->button == SDL_BUTTON_WHEELUP) {
  108.50                          dz = -1;
  108.51 -                    } else if (bev->button == SDL_BUTTON_WHEELDOWN && ev->type == SDL_MOUSEBUTTONDOWN) {
  108.52 +                    } else if (bev->button == SDL_BUTTON_WHEELDOWN) {
  108.53                          dz = 1;
  108.54 +                    } else {
  108.55 +                        state = bev->button | state;
  108.56                      }
  108.57  #endif               
  108.58 -                    sdl_send_mouse_event(dz);
  108.59 +                    sdl_send_mouse_event(dx, dy, dz, state);
  108.60                  }
  108.61              }
  108.62              break;
  108.63 @@ -499,6 +508,7 @@ void sdl_display_init(DisplayState *ds, 
  108.64      ds->dpy_update = sdl_update;
  108.65      ds->dpy_resize = sdl_resize;
  108.66      ds->dpy_refresh = sdl_refresh;
  108.67 +    ds->dpy_colourdepth = NULL;
  108.68  
  108.69      sdl_resize(ds, 640, 400);
  108.70      sdl_update_caption();
   109.1 --- a/tools/ioemu/target-i386-dm/cpu.h	Wed Feb 13 10:37:18 2008 -0700
   109.2 +++ b/tools/ioemu/target-i386-dm/cpu.h	Thu Feb 14 09:34:27 2008 -0700
   109.3 @@ -37,17 +37,21 @@
   109.4  
   109.5  #include "cpu-defs.h"
   109.6  
   109.7 +#ifdef CONFIG_SOFTFLOAT
   109.8  #include "softfloat.h"
   109.9 +#endif
  109.10  
  109.11  #if defined(__i386__) && !defined(CONFIG_SOFTMMU)
  109.12  #define USE_CODE_COPY
  109.13  #endif
  109.14  
  109.15 +#ifdef CONFIG_SOFTFLOAT
  109.16  #ifdef USE_X86LDOUBLE
  109.17  typedef floatx80 CPU86_LDouble;
  109.18  #else
  109.19  typedef float64 CPU86_LDouble;
  109.20  #endif
  109.21 +#endif
  109.22  
  109.23  /* Empty for now */
  109.24  typedef struct CPUX86State {
   110.1 --- a/tools/ioemu/target-i386-dm/helper2.c	Wed Feb 13 10:37:18 2008 -0700
   110.2 +++ b/tools/ioemu/target-i386-dm/helper2.c	Thu Feb 14 09:34:27 2008 -0700
   110.3 @@ -218,7 +218,7 @@ static ioreq_t *__cpu_get_ioreq(int vcpu
   110.4          return NULL;
   110.5      }
   110.6  
   110.7 -    rmb(); /* see IOREQ_READY /then/ read contents of ioreq */
   110.8 +    xen_rmb(); /* see IOREQ_READY /then/ read contents of ioreq */
   110.9  
  110.10      req->state = STATE_IOREQ_INPROCESS;
  110.11      return req;
  110.12 @@ -568,7 +568,7 @@ void __handle_buffered_iopage(CPUState *
  110.13  
  110.14          __handle_ioreq(env, &req);
  110.15  
  110.16 -        mb();
  110.17 +        xen_mb();
  110.18          buffered_io_page->read_pointer += qw ? 2 : 1;
  110.19      }
  110.20  }
  110.21 @@ -603,7 +603,7 @@ void cpu_handle_ioreq(void *opaque)
  110.22              return;
  110.23          }
  110.24  
  110.25 -        wmb(); /* Update ioreq contents /then/ update state. */
  110.26 +        xen_wmb(); /* Update ioreq contents /then/ update state. */
  110.27  
  110.28  	/*
  110.29           * We do this before we send the response so that the tools
   111.1 --- a/tools/ioemu/vl.c	Wed Feb 13 10:37:18 2008 -0700
   111.2 +++ b/tools/ioemu/vl.c	Thu Feb 14 09:34:27 2008 -0700
   111.3 @@ -36,22 +36,29 @@
   111.4  #include <sys/times.h>
   111.5  #include <sys/wait.h>
   111.6  #include <termios.h>
   111.7 +#ifndef CONFIG_STUBDOM
   111.8  #include <sys/poll.h>
   111.9 +#endif
  111.10  #include <sys/mman.h>
  111.11  #include <sys/ioctl.h>
  111.12  #include <sys/resource.h>
  111.13  #include <sys/socket.h>
  111.14  #include <netinet/in.h>
  111.15 +#ifndef CONFIG_STUBDOM
  111.16  #include <net/if.h>
  111.17 +#endif
  111.18  #if defined(__NetBSD__)
  111.19  #include <net/if_tap.h>
  111.20  #endif
  111.21  #if defined(__linux__) || defined(__Linux__)
  111.22  #include <linux/if_tun.h>
  111.23  #endif
  111.24 +#ifndef CONFIG_STUBDOM
  111.25  #include <arpa/inet.h>
  111.26  #include <dirent.h>
  111.27 +#endif
  111.28  #include <netdb.h>
  111.29 +#ifndef CONFIG_STUBDOM
  111.30  #ifdef _BSD
  111.31  #include <sys/stat.h>
  111.32  #ifndef _BSD
  111.33 @@ -70,6 +77,7 @@
  111.34  #include <stropts.h>
  111.35  #endif
  111.36  #endif
  111.37 +#endif
  111.38  
  111.39  #if defined(CONFIG_SLIRP)
  111.40  #include "libslirp.h"
  111.41 @@ -80,6 +88,7 @@
  111.42  #include <windows.h>
  111.43  #define getopt_long_only getopt_long
  111.44  #define memalign(align, size) malloc(size)
  111.45 +#define NO_DAEMONIZE 1
  111.46  #endif
  111.47  
  111.48  #include "qemu_socket.h"
  111.49 @@ -131,10 +140,9 @@
  111.50  #define MAX_IOPORTS 65536
  111.51  
  111.52  const char *bios_dir = CONFIG_QEMU_SHAREDIR;
  111.53 -char phys_ram_file[1024];
  111.54 -void *ioport_opaque[MAX_IOPORTS];
  111.55 -IOPortReadFunc *ioport_read_table[3][MAX_IOPORTS];
  111.56 -IOPortWriteFunc *ioport_write_table[3][MAX_IOPORTS];
  111.57 +void **ioport_opaque;
  111.58 +IOPortReadFunc *(*ioport_read_table)[MAX_IOPORTS];
  111.59 +IOPortWriteFunc *(*ioport_write_table)[MAX_IOPORTS];
  111.60  /* Note: bs_table[MAX_DISKS] is a dummy block driver if none available
  111.61     to store the VM snapshots */
  111.62  BlockDriverState *bs_table[MAX_DISKS + MAX_SCSI_DISKS + 1], *fd_table[MAX_FD];
  111.63 @@ -186,7 +194,9 @@ const char *vnc_display;
  111.64  int acpi_enabled = 0;
  111.65  int fd_bootchk = 1;
  111.66  int no_reboot = 0;
  111.67 +#ifndef NO_DAEMONIZE
  111.68  int daemonize = 0;
  111.69 +#endif
  111.70  const char *option_rom[MAX_OPTION_ROMS];
  111.71  int nb_option_roms;
  111.72  int semihosting_enabled = 0;
  111.73 @@ -224,17 +234,29 @@ void default_ioport_writeb(void *opaque,
  111.74  uint32_t default_ioport_readw(void *opaque, uint32_t address)
  111.75  {
  111.76      uint32_t data;
  111.77 -    data = ioport_read_table[0][address](ioport_opaque[address], address);
  111.78 +    IOPortReadFunc *func = ioport_read_table[0][address];
  111.79 +    if (!func)
  111.80 +	    func = default_ioport_readb;
  111.81 +    data = func(ioport_opaque[address], address);
  111.82      address = (address + 1) & (MAX_IOPORTS - 1);
  111.83 -    data |= ioport_read_table[0][address](ioport_opaque[address], address) << 8;
  111.84 +    func = ioport_read_table[0][address];
  111.85 +    if (!func)
  111.86 +	    func = default_ioport_readb;
  111.87 +    data |= func(ioport_opaque[address], address) << 8;
  111.88      return data;
  111.89  }
  111.90  
  111.91  void default_ioport_writew(void *opaque, uint32_t address, uint32_t data)
  111.92  {
  111.93 -    ioport_write_table[0][address](ioport_opaque[address], address, data & 0xff);
  111.94 +    IOPortWriteFunc *func = ioport_write_table[0][address];
  111.95 +    if (!func)
  111.96 +	    func = default_ioport_writeb;
  111.97 +    func(ioport_opaque[address], address, data & 0xff);
  111.98      address = (address + 1) & (MAX_IOPORTS - 1);
  111.99 -    ioport_write_table[0][address](ioport_opaque[address], address, (data >> 8) & 0xff);
 111.100 +    func = ioport_write_table[0][address];
 111.101 +    if (!func)
 111.102 +	    func = default_ioport_writeb;
 111.103 +    func(ioport_opaque[address], address, (data >> 8) & 0xff);
 111.104  }
 111.105  
 111.106  uint32_t default_ioport_readl(void *opaque, uint32_t address)
 111.107 @@ -254,16 +276,9 @@ void default_ioport_writel(void *opaque,
 111.108  
 111.109  void init_ioports(void)
 111.110  {
 111.111 -    int i;
 111.112 -
 111.113 -    for(i = 0; i < MAX_IOPORTS; i++) {
 111.114 -        ioport_read_table[0][i] = default_ioport_readb;
 111.115 -        ioport_write_table[0][i] = default_ioport_writeb;
 111.116 -        ioport_read_table[1][i] = default_ioport_readw;
 111.117 -        ioport_write_table[1][i] = default_ioport_writew;
 111.118 -        ioport_read_table[2][i] = default_ioport_readl;
 111.119 -        ioport_write_table[2][i] = default_ioport_writel;
 111.120 -    }
 111.121 +    ioport_opaque = malloc(MAX_IOPORTS * sizeof(*ioport_opaque));
 111.122 +    ioport_read_table = malloc(3 * MAX_IOPORTS * sizeof(**ioport_read_table));
 111.123 +    ioport_write_table = malloc(3 * MAX_IOPORTS * sizeof(**ioport_write_table));
 111.124  }
 111.125  
 111.126  /* size is the word size in byte */
 111.127 @@ -335,11 +350,14 @@ void isa_unassign_ioport(int start, int 
 111.128  
 111.129  void cpu_outb(CPUState *env, int addr, int val)
 111.130  {
 111.131 +    IOPortWriteFunc *func = ioport_write_table[0][addr];
 111.132 +    if (!func)
 111.133 +	    func = default_ioport_writeb;
 111.134  #ifdef DEBUG_IOPORT
 111.135      if (loglevel & CPU_LOG_IOPORT)
 111.136          fprintf(logfile, "outb: %04x %02x\n", addr, val);
 111.137  #endif    
 111.138 -    ioport_write_table[0][addr](ioport_opaque[addr], addr, val);
 111.139 +    func(ioport_opaque[addr], addr, val);
 111.140  #ifdef USE_KQEMU
 111.141      if (env)
 111.142          env->last_io_time = cpu_get_time_fast();
 111.143 @@ -348,11 +366,14 @@ void cpu_outb(CPUState *env, int addr, i
 111.144  
 111.145  void cpu_outw(CPUState *env, int addr, int val)
 111.146  {
 111.147 +    IOPortWriteFunc *func = ioport_write_table[1][addr];
 111.148 +    if (!func)
 111.149 +	    func = default_ioport_writew;
 111.150  #ifdef DEBUG_IOPORT
 111.151      if (loglevel & CPU_LOG_IOPORT)
 111.152          fprintf(logfile, "outw: %04x %04x\n", addr, val);
 111.153  #endif    
 111.154 -    ioport_write_table[1][addr](ioport_opaque[addr], addr, val);
 111.155 +    func(ioport_opaque[addr], addr, val);
 111.156  #ifdef USE_KQEMU
 111.157      if (env)
 111.158          env->last_io_time = cpu_get_time_fast();
 111.159 @@ -361,11 +382,14 @@ void cpu_outw(CPUState *env, int addr, i
 111.160  
 111.161  void cpu_outl(CPUState *env, int addr, int val)
 111.162  {
 111.163 +    IOPortWriteFunc *func = ioport_write_table[2][addr];
 111.164 +    if (!func)
 111.165 +	    func = default_ioport_writel;
 111.166  #ifdef DEBUG_IOPORT
 111.167      if (loglevel & CPU_LOG_IOPORT)
 111.168          fprintf(logfile, "outl: %04x %08x\n", addr, val);
 111.169  #endif
 111.170 -    ioport_write_table[2][addr](ioport_opaque[addr], addr, val);
 111.171 +    func(ioport_opaque[addr], addr, val);
 111.172  #ifdef USE_KQEMU
 111.173      if (env)
 111.174          env->last_io_time = cpu_get_time_fast();
 111.175 @@ -375,7 +399,10 @@ void cpu_outl(CPUState *env, int addr, i
 111.176  int cpu_inb(CPUState *env, int addr)
 111.177  {
 111.178      int val;
 111.179 -    val = ioport_read_table[0][addr](ioport_opaque[addr], addr);
 111.180 +    IOPortReadFunc *func = ioport_read_table[0][addr];
 111.181 +    if (!func)
 111.182 +	    func = default_ioport_readb;
 111.183 +    val = func(ioport_opaque[addr], addr);
 111.184  #ifdef DEBUG_IOPORT
 111.185      if (loglevel & CPU_LOG_IOPORT)
 111.186          fprintf(logfile, "inb : %04x %02x\n", addr, val);
 111.187 @@ -390,7 +417,10 @@ int cpu_inb(CPUState *env, int addr)
 111.188  int cpu_inw(CPUState *env, int addr)
 111.189  {
 111.190      int val;
 111.191 -    val = ioport_read_table[1][addr](ioport_opaque[addr], addr);
 111.192 +    IOPortReadFunc *func = ioport_read_table[1][addr];
 111.193 +    if (!func)
 111.194 +	    func = default_ioport_readw;
 111.195 +    val = func(ioport_opaque[addr], addr);
 111.196  #ifdef DEBUG_IOPORT
 111.197      if (loglevel & CPU_LOG_IOPORT)
 111.198          fprintf(logfile, "inw : %04x %04x\n", addr, val);
 111.199 @@ -405,7 +435,10 @@ int cpu_inw(CPUState *env, int addr)
 111.200  int cpu_inl(CPUState *env, int addr)
 111.201  {
 111.202      int val;
 111.203 -    val = ioport_read_table[2][addr](ioport_opaque[addr], addr);
 111.204 +    IOPortReadFunc *func = ioport_read_table[2][addr];
 111.205 +    if (!func)
 111.206 +	    func = default_ioport_readl;
 111.207 +    val = func(ioport_opaque[addr], addr);
 111.208  #ifdef DEBUG_IOPORT
 111.209      if (loglevel & CPU_LOG_IOPORT)
 111.210          fprintf(logfile, "inl : %04x %08x\n", addr, val);
 111.211 @@ -773,9 +806,6 @@ static QEMUTimer *active_timers[2];
 111.212  static MMRESULT timerID;
 111.213  static HANDLE host_alarm = NULL;
 111.214  static unsigned int period = 1;
 111.215 -#else
 111.216 -/* frequency of the times() clock tick */
 111.217 -static int timer_freq;
 111.218  #endif
 111.219  
 111.220  QEMUClock *qemu_new_clock(int type)
 111.221 @@ -1113,9 +1143,6 @@ static void init_timer_alarm(void)
 111.222          struct itimerval itv;
 111.223  #endif
 111.224          
 111.225 -        /* get times() syscall frequency */
 111.226 -        timer_freq = sysconf(_SC_CLK_TCK);
 111.227 -        
 111.228  #ifndef CONFIG_DM
 111.229          /* timer signal */
 111.230          sigfillset(&act.sa_mask);
 111.231 @@ -1473,6 +1500,7 @@ static CharDriverState *qemu_chr_open_fi
 111.232      return qemu_chr_open_fd(-1, fd_out);
 111.233  }
 111.234  
 111.235 +#ifndef CONFIG_STUBDOM
 111.236  static CharDriverState *qemu_chr_open_pipe(const char *filename)
 111.237  {
 111.238      int fd_in, fd_out;
 111.239 @@ -1718,6 +1746,7 @@ static CharDriverState *qemu_chr_open_st
 111.240      }
 111.241      return chr;
 111.242  }
 111.243 +#endif
 111.244  
 111.245  /*
 111.246   * Create a store entry for a device (e.g., monitor, serial/parallel lines).
 111.247 @@ -1727,6 +1756,9 @@ static CharDriverState *qemu_chr_open_st
 111.248  static int store_dev_info(char *devName, int domid,
 111.249                            CharDriverState *cState, char *storeString)
 111.250  {
 111.251 +#ifdef CONFIG_STUBDOM
 111.252 +    return 0;
 111.253 +#else
 111.254      int xc_handle;
 111.255      struct xs_handle *xs;
 111.256      char *path;
 111.257 @@ -1802,8 +1834,10 @@ static int store_dev_info(char *devName,
 111.258      close(xc_handle);
 111.259  
 111.260      return 0;
 111.261 -}
 111.262 -
 111.263 +#endif
 111.264 +}
 111.265 +
 111.266 +#ifndef CONFIG_STUBDOM
 111.267  #ifdef __sun__
 111.268  /* Once Solaris has openpty(), this is going to be removed. */
 111.269  int openpty(int *amaster, int *aslave, char *name,
 111.270 @@ -2462,6 +2496,7 @@ static CharDriverState *qemu_chr_open_wi
 111.271      return qemu_chr_open_win_file(fd_out);
 111.272  }
 111.273  #endif
 111.274 +#endif
 111.275  
 111.276  /***********************************************************/
 111.277  /* UDP Net console */
 111.278 @@ -2532,7 +2567,7 @@ static void udp_chr_update_read_handler(
 111.279  }
 111.280  
 111.281  int parse_host_port(struct sockaddr_in *saddr, const char *str);
 111.282 -#ifndef _WIN32
 111.283 +#ifndef NO_UNIX_SOCKETS
 111.284  static int parse_unix_path(struct sockaddr_un *uaddr, const char *str);
 111.285  #endif
 111.286  int parse_host_src_port(struct sockaddr_in *haddr,
 111.287 @@ -2740,7 +2775,7 @@ static void tcp_chr_accept(void *opaque)
 111.288      CharDriverState *chr = opaque;
 111.289      TCPCharDriver *s = chr->opaque;
 111.290      struct sockaddr_in saddr;
 111.291 -#ifndef _WIN32
 111.292 +#ifndef NO_UNIX_SOCKETS
 111.293      struct sockaddr_un uaddr;
 111.294  #endif
 111.295      struct sockaddr *addr;
 111.296 @@ -2748,7 +2783,7 @@ static void tcp_chr_accept(void *opaque)
 111.297      int fd;
 111.298  
 111.299      for(;;) {
 111.300 -#ifndef _WIN32
 111.301 +#ifndef NO_UNIX_SOCKETS
 111.302  	if (s->is_unix) {
 111.303  	    len = sizeof(uaddr);
 111.304  	    addr = (struct sockaddr *)&uaddr;
 111.305 @@ -2797,13 +2832,13 @@ static CharDriverState *qemu_chr_open_tc
 111.306      int do_nodelay = 0;
 111.307      const char *ptr;
 111.308      struct sockaddr_in saddr;
 111.309 -#ifndef _WIN32
 111.310 +#ifndef NO_UNIX_SOCKETS
 111.311      struct sockaddr_un uaddr;
 111.312  #endif
 111.313      struct sockaddr *addr;
 111.314      socklen_t addrlen;
 111.315  
 111.316 -#ifndef _WIN32
 111.317 +#ifndef NO_UNIX_SOCKETS
 111.318      if (is_unix) {
 111.319  	addr = (struct sockaddr *)&uaddr;
 111.320  	addrlen = sizeof(uaddr);
 111.321 @@ -2842,7 +2877,7 @@ static CharDriverState *qemu_chr_open_tc
 111.322      if (!s)
 111.323          goto fail;
 111.324  
 111.325 -#ifndef _WIN32
 111.326 +#ifndef NO_UNIX_SOCKETS
 111.327      if (is_unix)
 111.328  	fd = socket(PF_UNIX, SOCK_STREAM, 0);
 111.329      else
 111.330 @@ -2867,7 +2902,7 @@ static CharDriverState *qemu_chr_open_tc
 111.331  
 111.332      if (is_listen) {
 111.333          /* allow fast reuse */
 111.334 -#ifndef _WIN32
 111.335 +#ifndef NO_UNIX_SOCKETS
 111.336  	if (is_unix) {
 111.337  	    char path[109];
 111.338  	    strncpy(path, uaddr.sun_path, 108);
 111.339 @@ -2954,12 +2989,14 @@ CharDriverState *qemu_chr_open(const cha
 111.340  	return qemu_chr_open_tcp(p, 0, 1);
 111.341      } else if (strstart(filename, "file:", &p)) {
 111.342          return qemu_chr_open_file_out(p);
 111.343 +#ifndef CONFIG_STUBDOM
 111.344      } else if (strstart(filename, "pipe:", &p)) {
 111.345          return qemu_chr_open_pipe(p);
 111.346      } else if (!strcmp(filename, "pty")) {
 111.347          return qemu_chr_open_pty();
 111.348      } else if (!strcmp(filename, "stdio")) {
 111.349          return qemu_chr_open_stdio();
 111.350 +#endif
 111.351      } else 
 111.352  #endif
 111.353  #if defined(__linux__)
 111.354 @@ -3449,7 +3486,16 @@ static TAPState *net_tap_fd_init(VLANSta
 111.355      return s;
 111.356  }
 111.357  
 111.358 -#ifdef _BSD
 111.359 +#ifdef CONFIG_STUBDOM
 111.360 +#include <netfront.h>
 111.361 +static int tap_open(char *ifname, int ifname_size)
 111.362 +{
 111.363 +    char nodename[64];
 111.364 +    static int num = 1; // 0 is for our own TCP/IP networking
 111.365 +    snprintf(nodename, sizeof(nodename), "device/vif/%d", num++);
 111.366 +    return netfront_tap_open(nodename);
 111.367 +}
 111.368 +#elif defined(_BSD)
 111.369  static int tap_open(char *ifname, int ifname_size)
 111.370  {
 111.371      int fd;
 111.372 @@ -3537,6 +3583,7 @@ static int net_tap_init(VLANState *vlan,
 111.373      if (fd < 0)
 111.374          return -1;
 111.375  
 111.376 +#ifndef CONFIG_STUBDOM
 111.377      if (!setup_script || !strcmp(setup_script, "no"))
 111.378          setup_script = "";
 111.379      if (setup_script[0] != '\0') {
 111.380 @@ -3569,6 +3616,7 @@ static int net_tap_init(VLANState *vlan,
 111.381              }
 111.382          }
 111.383      }
 111.384 +#endif
 111.385      s = net_tap_fd_init(vlan, fd);
 111.386      if (!s)
 111.387          return -1;
 111.388 @@ -4397,6 +4445,7 @@ void dumb_display_init(DisplayState *ds)
 111.389      ds->depth = 0;
 111.390      ds->dpy_update = dumb_update;
 111.391      ds->dpy_resize = dumb_resize;
 111.392 +    ds->dpy_colourdepth = NULL;
 111.393      ds->dpy_refresh = dumb_refresh;
 111.394  }
 111.395  
 111.396 @@ -6510,7 +6559,7 @@ void help(void)
 111.397  	   "-vnc display    start a VNC server on display\n"
 111.398             "-vncviewer      start a vncviewer process for this domain\n"
 111.399             "-vncunused      bind the VNC server to an unused port\n"
 111.400 -#ifndef _WIN32
 111.401 +#ifndef NO_DAEMONIZE
 111.402  	   "-daemonize      daemonize QEMU after initializing\n"
 111.403  #endif
 111.404  	   "-option-rom rom load a file, rom, into the option ROM space\n"
 111.405 @@ -6600,7 +6649,9 @@ enum {
 111.406      QEMU_OPTION_vnc,
 111.407      QEMU_OPTION_no_acpi,
 111.408      QEMU_OPTION_no_reboot,
 111.409 +#ifndef NO_DAEMONIZE
 111.410      QEMU_OPTION_daemonize,
 111.411 +#endif
 111.412      QEMU_OPTION_option_rom,
 111.413      QEMU_OPTION_semihosting
 111.414      ,
 111.415 @@ -6698,7 +6749,9 @@ const QEMUOption qemu_options[] = {
 111.416      { "cirrusvga", 0, QEMU_OPTION_cirrusvga },
 111.417      { "no-acpi", 0, QEMU_OPTION_no_acpi },
 111.418      { "no-reboot", 0, QEMU_OPTION_no_reboot },
 111.419 +#ifndef NO_DAEMONIZE
 111.420      { "daemonize", 0, QEMU_OPTION_daemonize },
 111.421 +#endif
 111.422      { "option-rom", HAS_ARG, QEMU_OPTION_option_rom },
 111.423  #if defined(TARGET_ARM)
 111.424      { "semihosting", 0, QEMU_OPTION_semihosting },
 111.425 @@ -7009,12 +7062,14 @@ int main(int argc, char **argv)
 111.426      char usb_devices[MAX_USB_CMDLINE][128];
 111.427      int usb_devices_index;
 111.428      int fds[2];
 111.429 +#ifndef CONFIG_STUBDOM
 111.430      struct rlimit rl;
 111.431 +#endif
 111.432      sigset_t set;
 111.433      char qemu_dm_logfilename[128];
 111.434      const char *direct_pci = NULL;
 111.435  
 111.436 -#ifndef __sun__
 111.437 +#if !defined(__sun__) && !defined(CONFIG_STUBDOM)
 111.438      /* Maximise rlimits. Needed where default constraints are tight (*BSD). */
 111.439      if (getrlimit(RLIMIT_STACK, &rl) != 0) {
 111.440         perror("getrlimit(RLIMIT_STACK)");
 111.441 @@ -7040,6 +7095,7 @@ int main(int argc, char **argv)
 111.442         perror("setrlimit(RLIMIT_MEMLOCK)");
 111.443  #endif
 111.444  
 111.445 +#ifndef CONFIG_STUBDOM
 111.446      /* Ensure that SIGUSR2 is blocked by default when a new thread is created,
 111.447         then only the threads that use the signal unblock it -- this fixes a
 111.448         race condition in Qcow support where the AIO signal is misdelivered.  */
 111.449 @@ -7082,6 +7138,7 @@ int main(int argc, char **argv)
 111.450          }
 111.451      }
 111.452  #endif
 111.453 +#endif
 111.454  
 111.455      register_machines();
 111.456      machine = first_machine;
 111.457 @@ -7496,9 +7553,11 @@ int main(int argc, char **argv)
 111.458              case QEMU_OPTION_no_reboot:
 111.459                  no_reboot = 1;
 111.460                  break;
 111.461 +#ifndef NO_DAEMONIZE
 111.462  	    case QEMU_OPTION_daemonize:
 111.463  		daemonize = 1;
 111.464  		break;
 111.465 +#endif
 111.466  	    case QEMU_OPTION_option_rom:
 111.467  		if (nb_option_roms >= MAX_OPTION_ROMS) {
 111.468  		    fprintf(stderr, "Too many option ROMs\n");
 111.469 @@ -7542,7 +7601,7 @@ int main(int argc, char **argv)
 111.470      sprintf(qemu_dm_logfilename, "/var/log/xen/qemu-dm-%d.log", domid);
 111.471      cpu_set_log_filename(qemu_dm_logfilename);
 111.472  
 111.473 -#ifndef _WIN32
 111.474 +#ifndef NO_DAEMONIZE
 111.475      if (daemonize && !nographic && vnc_display == NULL && vncunused == 0) {
 111.476  	fprintf(stderr, "Can only daemonize if using -nographic or -vnc\n");
 111.477  	daemonize = 0;
 111.478 @@ -7593,7 +7652,15 @@ int main(int argc, char **argv)
 111.479  #ifdef CONFIG_DM
 111.480      bdrv_init();
 111.481      xc_handle = xc_interface_open();
 111.482 +#ifdef CONFIG_STUBDOM
 111.483 +    char *domid_s, *msg;
 111.484 +    if ((msg = xenbus_read(XBT_NIL, "domid", &domid_s)))
 111.485 +        fprintf(stderr,"Can not read our own domid\n", msg);
 111.486 +    else
 111.487 +        xenstore_parse_domain_config(atoi(domid_s));
 111.488 +#else /* CONFIG_STUBDOM */
 111.489      xenstore_parse_domain_config(domid);
 111.490 +#endif /* CONFIG_STUBDOM */
 111.491  #endif /* CONFIG_DM */
 111.492  
 111.493  #ifdef USE_KQEMU
 111.494 @@ -7760,8 +7827,10 @@ int main(int argc, char **argv)
 111.495  	vnc_display_password(ds, password);
 111.496  	if ((vnc_display_port = vnc_display_open(ds, vnc_display, vncunused)) < 0) 
 111.497  	    exit (0);
 111.498 +#ifndef CONFIG_STUBDOM	    
 111.499   	if (vncviewer)
 111.500  	    vnc_start_viewer(vnc_display_port);
 111.501 +#endif
 111.502  	xenstore_write_vncport(vnc_display_port);
 111.503      } else {
 111.504  #if defined(CONFIG_SDL)
 111.505 @@ -7863,6 +7932,7 @@ int main(int argc, char **argv)
 111.506          }
 111.507      }
 111.508  
 111.509 +#ifndef NO_DAEMONIZE
 111.510      if (daemonize) {
 111.511  	uint8_t status = 0;
 111.512  	ssize_t len;
 111.513 @@ -7886,12 +7956,17 @@ int main(int argc, char **argv)
 111.514  
 111.515  	close(fd);
 111.516      }
 111.517 -
 111.518 -    /* Unblock SIGTERM, which may have been blocked by the caller */
 111.519 +#endif
 111.520 +
 111.521 +#ifndef CONFIG_STUBDOM
 111.522 +    /* Unblock SIGTERM and SIGHUP, which may have been blocked by the caller */
 111.523 +    signal(SIGHUP, SIG_DFL);
 111.524      sigemptyset(&set);
 111.525      sigaddset(&set, SIGTERM);
 111.526 +    sigaddset(&set, SIGHUP);
 111.527      if (sigprocmask(SIG_UNBLOCK, &set, NULL) == -1)
 111.528 -        fprintf(stderr, "Failed to unblock SIGTERM\n");
 111.529 +        fprintf(stderr, "Failed to unblock SIGTERM and SIGHUP\n");
 111.530 +#endif
 111.531  
 111.532      main_loop();
 111.533      quit_timers();
   112.1 --- a/tools/ioemu/vl.h	Wed Feb 13 10:37:18 2008 -0700
   112.2 +++ b/tools/ioemu/vl.h	Thu Feb 14 09:34:27 2008 -0700
   112.3 @@ -574,6 +574,9 @@ typedef struct BlockDriver BlockDriver;
   112.4  
   112.5  extern BlockDriver bdrv_raw;
   112.6  extern BlockDriver bdrv_host_device;
   112.7 +#ifdef CONFIG_STUBDOM
   112.8 +extern BlockDriver bdrv_vbd;
   112.9 +#endif
  112.10  extern BlockDriver bdrv_cow;
  112.11  extern BlockDriver bdrv_qcow;
  112.12  extern BlockDriver bdrv_vmdk;
  112.13 @@ -912,8 +915,11 @@ struct DisplayState {
  112.14      int height;
  112.15      void *opaque;
  112.16  
  112.17 +    int switchbpp;
  112.18 +    
  112.19      void (*dpy_update)(struct DisplayState *s, int x, int y, int w, int h);
  112.20      void (*dpy_resize)(struct DisplayState *s, int w, int h);
  112.21 +    void (*dpy_colourdepth)(struct DisplayState *s, int depth);
  112.22      void (*dpy_refresh)(struct DisplayState *s);
  112.23      void (*dpy_copy)(struct DisplayState *s, int src_x, int src_y, int dst_x, int dst_y, int w, int h);
  112.24  };
   113.1 --- a/tools/ioemu/vnc.c	Wed Feb 13 10:37:18 2008 -0700
   113.2 +++ b/tools/ioemu/vnc.c	Thu Feb 14 09:34:27 2008 -0700
   113.3 @@ -30,6 +30,9 @@
   113.4  #include "vl.h"
   113.5  #include "qemu_socket.h"
   113.6  #include <assert.h>
   113.7 +#ifdef CONFIG_STUBDOM
   113.8 +#include <netfront.h>
   113.9 +#endif
  113.10  
  113.11  /* The refresh interval starts at BASE.  If we scan the buffer and
  113.12     find no change, we increase by INC, up to MAX.  If the mouse moves
  113.13 @@ -85,8 +88,8 @@ typedef void VncWritePixels(VncState *vs
  113.14  
  113.15  typedef void VncSendHextileTile(VncState *vs,
  113.16                                  int x, int y, int w, int h,
  113.17 -                                uint32_t *last_bg, 
  113.18 -                                uint32_t *last_fg,
  113.19 +                                void *last_bg, 
  113.20 +                                void *last_fg,
  113.21                                  int *has_bg, int *has_fg);
  113.22  
  113.23  #if 0
  113.24 @@ -154,6 +157,7 @@ struct VncState
  113.25      int has_resize;
  113.26      int has_hextile;
  113.27      int has_pointer_type_change;
  113.28 +    int has_WMVi;
  113.29      int absolute;
  113.30      int last_x;
  113.31      int last_y;
  113.32 @@ -187,9 +191,9 @@ struct VncState
  113.33      VncWritePixels *write_pixels;
  113.34      VncSendHextileTile *send_hextile_tile;
  113.35      int pix_bpp, pix_big_endian;
  113.36 -    int red_shift, red_max, red_shift1;
  113.37 -    int green_shift, green_max, green_shift1;
  113.38 -    int blue_shift, blue_max, blue_shift1;
  113.39 +    int red_shift, red_max, red_shift1, red_max1;
  113.40 +    int green_shift, green_max, green_shift1, green_max1;
  113.41 +    int blue_shift, blue_max, blue_shift1, blue_max1;
  113.42  
  113.43      VncReadEvent *read_handler;
  113.44      size_t read_handler_expect;
  113.45 @@ -379,54 +383,67 @@ static void vnc_write_pixels_copy(VncSta
  113.46  /* slowest but generic code. */
  113.47  static void vnc_convert_pixel(VncState *vs, uint8_t *buf, uint32_t v)
  113.48  {
  113.49 -    unsigned int r, g, b;
  113.50 +    uint8_t r, g, b;
  113.51  
  113.52 -    r = (v >> vs->red_shift1) & vs->red_max;
  113.53 -    g = (v >> vs->green_shift1) & vs->green_max;
  113.54 -    b = (v >> vs->blue_shift1) & vs->blue_max;
  113.55 -    v = (r << vs->red_shift) | 
  113.56 -        (g << vs->green_shift) | 
  113.57 -        (b << vs->blue_shift);
  113.58 +    r = ((v >> vs->red_shift1) & vs->red_max1) * (vs->red_max + 1) / (vs->red_max1 + 1);
  113.59 +    g = ((v >> vs->green_shift1) & vs->green_max1) * (vs->green_max + 1) / (vs->green_max1 + 1);
  113.60 +    b = ((v >> vs->blue_shift1) & vs->blue_max1) * (vs->blue_max + 1) / (vs->blue_max1 + 1);
  113.61      switch(vs->pix_bpp) {
  113.62      case 1:
  113.63 -        buf[0] = v;
  113.64 +        buf[0] = (r << vs->red_shift) | (g << vs->green_shift) | (b << vs->blue_shift);
  113.65          break;
  113.66      case 2:
  113.67 +    {
  113.68 +        uint16_t *p = (uint16_t *) buf;
  113.69 +        *p = (r << vs->red_shift) | (g << vs->green_shift) | (b << vs->blue_shift);
  113.70          if (vs->pix_big_endian) {
  113.71 -            buf[0] = v >> 8;
  113.72 -            buf[1] = v;
  113.73 -        } else {
  113.74 -            buf[1] = v >> 8;
  113.75 -            buf[0] = v;
  113.76 +            *p = htons(*p);
  113.77          }
  113.78 +    }
  113.79          break;
  113.80      default:
  113.81      case 4:
  113.82 +    {
  113.83 +        uint32_t *p = (uint32_t *) buf;
  113.84 +        *p = (r << vs->red_shift) | (g << vs->green_shift) | (b << vs->blue_shift);
  113.85          if (vs->pix_big_endian) {
  113.86 -            buf[0] = v >> 24;
  113.87 -            buf[1] = v >> 16;
  113.88 -            buf[2] = v >> 8;
  113.89 -            buf[3] = v;
  113.90 -        } else {
  113.91 -            buf[3] = v >> 24;
  113.92 -            buf[2] = v >> 16;
  113.93 -            buf[1] = v >> 8;
  113.94 -            buf[0] = v;
  113.95 +            *p = htonl(*p);
  113.96          }
  113.97          break;
  113.98      }
  113.99 +    }
 113.100  }
 113.101  
 113.102  static void vnc_write_pixels_generic(VncState *vs, void *pixels1, int size)
 113.103  {
 113.104 -    uint32_t *pixels = pixels1;
 113.105      uint8_t buf[4];
 113.106 -    int n, i;
 113.107  
 113.108 -    n = size >> 2;
 113.109 -    for(i = 0; i < n; i++) {
 113.110 -        vnc_convert_pixel(vs, buf, pixels[i]);
 113.111 -        vnc_write(vs, buf, vs->pix_bpp);
 113.112 +    if (vs->depth == 4) {
 113.113 +        uint32_t *pixels = pixels1;
 113.114 +        int n, i;
 113.115 +        n = size >> 2;
 113.116 +        for(i = 0; i < n; i++) {
 113.117 +            vnc_convert_pixel(vs, buf, pixels[i]);
 113.118 +            vnc_write(vs, buf, vs->pix_bpp);
 113.119 +        }
 113.120 +    } else if (vs->depth == 2) {
 113.121 +        uint16_t *pixels = pixels1;
 113.122 +        int n, i;
 113.123 +        n = size >> 1;
 113.124 +        for(i = 0; i < n; i++) {
 113.125 +            vnc_convert_pixel(vs, buf, pixels[i]);
 113.126 +            vnc_write(vs, buf, vs->pix_bpp);
 113.127 +        }
 113.128 +    } else if (vs->depth == 1) {
 113.129 +        uint8_t *pixels = pixels1;
 113.130 +        int n, i;
 113.131 +        n = size;
 113.132 +        for(i = 0; i < n; i++) {
 113.133 +            vnc_convert_pixel(vs, buf, pixels[i]);
 113.134 +            vnc_write(vs, buf, vs->pix_bpp);
 113.135 +        }
 113.136 +    } else {
 113.137 +        fprintf(stderr, "vnc_write_pixels_generic: VncState color depth not supported\n");
 113.138      }
 113.139  }
 113.140  
 113.141 @@ -463,6 +480,18 @@ static void hextile_enc_cord(uint8_t *pt
 113.142  #undef BPP
 113.143  
 113.144  #define GENERIC
 113.145 +#define BPP 8
 113.146 +#include "vnchextile.h"
 113.147 +#undef BPP
 113.148 +#undef GENERIC
 113.149 +
 113.150 +#define GENERIC
 113.151 +#define BPP 16
 113.152 +#include "vnchextile.h"
 113.153 +#undef BPP
 113.154 +#undef GENERIC
 113.155 +
 113.156 +#define GENERIC
 113.157  #define BPP 32
 113.158  #include "vnchextile.h"
 113.159  #undef BPP
 113.160 @@ -472,18 +501,22 @@ static void send_framebuffer_update_hext
 113.161  {
 113.162      int i, j;
 113.163      int has_fg, has_bg;
 113.164 -    uint32_t last_fg32, last_bg32;
 113.165 +    void *last_fg, *last_bg;
 113.166  
 113.167      vnc_framebuffer_update(vs, x, y, w, h, 5);
 113.168  
 113.169 +    last_fg = (void *) malloc(vs->depth);
 113.170 +    last_bg = (void *) malloc(vs->depth);
 113.171      has_fg = has_bg = 0;
 113.172      for (j = y; j < (y + h); j += 16) {
 113.173  	for (i = x; i < (x + w); i += 16) {
 113.174              vs->send_hextile_tile(vs, i, j, 
 113.175                                    MIN(16, x + w - i), MIN(16, y + h - j),
 113.176 -                                  &last_bg32, &last_fg32, &has_bg, &has_fg);
 113.177 +                                  last_bg, last_fg, &has_bg, &has_fg);
 113.178  	}
 113.179      }
 113.180 +    free(last_fg);
 113.181 +    free(last_bg);    
 113.182  }
 113.183  
 113.184  static void send_framebuffer_update(VncState *vs, int x, int y, int w, int h)
 113.185 @@ -1278,6 +1311,7 @@ static void set_encodings(VncState *vs, 
 113.186      vs->has_hextile = 0;
 113.187      vs->has_resize = 0;
 113.188      vs->has_pointer_type_change = 0;
 113.189 +    vs->has_WMVi = 0;
 113.190      vs->absolute = -1;
 113.191      vs->ds->dpy_copy = NULL;
 113.192  
 113.193 @@ -1298,6 +1332,8 @@ static void set_encodings(VncState *vs, 
 113.194  	case -257:
 113.195  	    vs->has_pointer_type_change = 1;
 113.196  	    break;
 113.197 +        case 0x574D5669:
 113.198 +            vs->has_WMVi = 1;
 113.199  	default:
 113.200  	    break;
 113.201  	}
 113.202 @@ -1306,17 +1342,6 @@ static void set_encodings(VncState *vs, 
 113.203      check_pointer_type_change(vs, kbd_mouse_is_absolute());
 113.204  }
 113.205  
 113.206 -static int compute_nbits(unsigned int val)
 113.207 -{
 113.208 -    int n;
 113.209 -    n = 0;
 113.210 -    while (val != 0) {
 113.211 -        n++;
 113.212 -        val >>= 1;
 113.213 -    }
 113.214 -    return n;
 113.215 -}
 113.216 -
 113.217  static void set_pixel_format(VncState *vs,
 113.218  			     int bits_per_pixel, int depth,
 113.219  			     int big_endian_flag, int true_color_flag,
 113.220 @@ -1335,23 +1360,24 @@ static void set_pixel_format(VncState *v
 113.221  	vnc_client_error(vs);
 113.222          return;
 113.223      }
 113.224 -    if (bits_per_pixel == 32 && 
 113.225 +    if (bits_per_pixel == 32 &&
 113.226 +        bits_per_pixel == vs->depth * 8 && 
 113.227          host_big_endian_flag == big_endian_flag &&
 113.228          red_max == 0xff && green_max == 0xff && blue_max == 0xff &&
 113.229          red_shift == 16 && green_shift == 8 && blue_shift == 0) {
 113.230 -        vs->depth = 4;
 113.231          vs->write_pixels = vnc_write_pixels_copy;
 113.232          vs->send_hextile_tile = send_hextile_tile_32;
 113.233      } else 
 113.234 -    if (bits_per_pixel == 16 && 
 113.235 +    if (bits_per_pixel == 16 &&
 113.236 +        bits_per_pixel == vs->depth * 8 && 
 113.237          host_big_endian_flag == big_endian_flag &&
 113.238          red_max == 31 && green_max == 63 && blue_max == 31 &&
 113.239          red_shift == 11 && green_shift == 5 && blue_shift == 0) {
 113.240 -        vs->depth = 2;
 113.241          vs->write_pixels = vnc_write_pixels_copy;
 113.242          vs->send_hextile_tile = send_hextile_tile_16;
 113.243      } else 
 113.244      if (bits_per_pixel == 8 && 
 113.245 +        bits_per_pixel == vs->depth * 8 &&
 113.246          red_max == 7 && green_max == 7 && blue_max == 3 &&
 113.247          red_shift == 5 && green_shift == 2 && blue_shift == 0) {
 113.248          vs->depth = 1;
 113.249 @@ -1364,28 +1390,170 @@ static void set_pixel_format(VncState *v
 113.250              bits_per_pixel != 16 &&
 113.251              bits_per_pixel != 32)
 113.252              goto fail;
 113.253 -        vs->depth = 4;
 113.254 -        vs->red_shift = red_shift;
 113.255 -        vs->red_max = red_max;
 113.256 -        vs->red_shift1 = 24 - compute_nbits(red_max);
 113.257 -        vs->green_shift = green_shift;
 113.258 -        vs->green_max = green_max;
 113.259 -        vs->green_shift1 = 16 - compute_nbits(green_max);
 113.260 -        vs->blue_shift = blue_shift;
 113.261 -        vs->blue_max = blue_max;
 113.262 -        vs->blue_shift1 = 8 - compute_nbits(blue_max);
 113.263 -        vs->pix_bpp = bits_per_pixel / 8;
 113.264 +        if (vs->depth == 4) {
 113.265 +            vs->send_hextile_tile = send_hextile_tile_generic_32;
 113.266 +        } else if (vs->depth == 2) {
 113.267 +            vs->send_hextile_tile = send_hextile_tile_generic_16;
 113.268 +        } else {
 113.269 +            vs->send_hextile_tile = send_hextile_tile_generic_8;
 113.270 +        }
 113.271 +            
 113.272          vs->pix_big_endian = big_endian_flag;
 113.273          vs->write_pixels = vnc_write_pixels_generic;
 113.274 -        vs->send_hextile_tile = send_hextile_tile_generic;
 113.275      }
 113.276 -
 113.277 -    vnc_dpy_resize(vs->ds, vs->ds->width, vs->ds->height);
 113.278 + 
 113.279 +    vs->red_shift = red_shift;
 113.280 +    vs->red_max = red_max;
 113.281 +    vs->green_shift = green_shift;
 113.282 +    vs->green_max = green_max;
 113.283 +    vs->blue_shift = blue_shift;
 113.284 +    vs->blue_max = blue_max;
 113.285 +    vs->pix_bpp = bits_per_pixel / 8;
 113.286  
 113.287      vga_hw_invalidate();
 113.288      vga_hw_update();
 113.289  }
 113.290  
 113.291 +static void pixel_format_message (VncState *vs) {
 113.292 +    char pad[3] = { 0, 0, 0 };
 113.293 +
 113.294 +    vnc_write_u8(vs, vs->depth * 8); /* bits-per-pixel */
 113.295 +    if (vs->depth == 4) vnc_write_u8(vs, 24); /* depth */
 113.296 +    else vnc_write_u8(vs, vs->depth * 8); /* depth */
 113.297 +
 113.298 +#ifdef WORDS_BIGENDIAN
 113.299 +    vnc_write_u8(vs, 1);             /* big-endian-flag */
 113.300 +#else
 113.301 +    vnc_write_u8(vs, 0);             /* big-endian-flag */
 113.302 +#endif
 113.303 +    vnc_write_u8(vs, 1);             /* true-color-flag */
 113.304 +    if (vs->depth == 4) {
 113.305 +        vnc_write_u16(vs, 0xFF);     /* red-max */
 113.306 +        vnc_write_u16(vs, 0xFF);     /* green-max */
 113.307 +        vnc_write_u16(vs, 0xFF);     /* blue-max */
 113.308 +        vnc_write_u8(vs, 16);        /* red-shift */
 113.309 +        vnc_write_u8(vs, 8);         /* green-shift */
 113.310 +        vnc_write_u8(vs, 0);         /* blue-shift */
 113.311 +        vs->send_hextile_tile = send_hextile_tile_32;
 113.312 +    } else if (vs->depth == 2) {
 113.313 +        vnc_write_u16(vs, 31);       /* red-max */
 113.314 +        vnc_write_u16(vs, 63);       /* green-max */
 113.315 +        vnc_write_u16(vs, 31);       /* blue-max */
 113.316 +        vnc_write_u8(vs, 11);        /* red-shift */
 113.317 +        vnc_write_u8(vs, 5);         /* green-shift */
 113.318 +        vnc_write_u8(vs, 0);         /* blue-shift */
 113.319 +        vs->send_hextile_tile = send_hextile_tile_16;
 113.320 +    } else if (vs->depth == 1) {
 113.321 +        /* XXX: change QEMU pixel 8 bit pixel format to match the VNC one ? */
 113.322 +        vnc_write_u16(vs, 7);        /* red-max */
 113.323 +        vnc_write_u16(vs, 7);        /* green-max */
 113.324 +        vnc_write_u16(vs, 3);        /* blue-max */
 113.325 +        vnc_write_u8(vs, 5);         /* red-shift */
 113.326 +        vnc_write_u8(vs, 2);         /* green-shift */
 113.327 +        vnc_write_u8(vs, 0);         /* blue-shift */
 113.328 +        vs->send_hextile_tile = send_hextile_tile_8;
 113.329 +    }
 113.330 +    vs->red_max = vs->red_max1;
 113.331 +    vs->green_max = vs->green_max1;
 113.332 +    vs->blue_max = vs->blue_max1;
 113.333 +    vs->red_shift = vs->red_shift1;
 113.334 +    vs->green_shift = vs->green_shift1;
 113.335 +    vs->blue_shift = vs->blue_shift1;
 113.336 +    vs->pix_bpp = vs->depth * 8;
 113.337 +    vs->write_pixels = vnc_write_pixels_copy;
 113.338 +        
 113.339 +    vnc_write(vs, pad, 3);           /* padding */
 113.340 +}
 113.341 +
 113.342 +static void vnc_dpy_colourdepth(DisplayState *ds, int depth)
 113.343 +{
 113.344 +    int host_big_endian_flag;
 113.345 +    struct VncState *vs;
 113.346 +    
 113.347 +    if (!depth) return;
 113.348 +    
 113.349 +#ifdef WORDS_BIGENDIAN
 113.350 +    host_big_endian_flag = 1;
 113.351 +#else
 113.352 +    host_big_endian_flag = 0;
 113.353 +#endif
 113.354 +    vs = ds->opaque;   
 113.355 +    
 113.356 +    switch (depth) {
 113.357 +        case 8:
 113.358 +            vs->depth = depth / 8;
 113.359 +            vs->red_max1 = 7;
 113.360 +            vs->green_max1 = 7;
 113.361 +            vs->blue_max1 = 3;
 113.362 +            vs->red_shift1 = 5;
 113.363 +            vs->green_shift1 = 2;
 113.364 +            vs->blue_shift1 = 0;
 113.365 +            break;
 113.366 +        case 16:
 113.367 +            vs->depth = depth / 8;
 113.368 +            vs->red_max1 = 31;
 113.369 +            vs->green_max1 = 63;
 113.370 +            vs->blue_max1 = 31;
 113.371 +            vs->red_shift1 = 11;
 113.372 +            vs->green_shift1 = 5;
 113.373 +            vs->blue_shift1 = 0;
 113.374 +            break;
 113.375 +        case 32:
 113.376 +            vs->depth = 4;
 113.377 +            vs->red_max1 = 255;
 113.378 +            vs->green_max1 = 255;
 113.379 +            vs->blue_max1 = 255;
 113.380 +            vs->red_shift1 = 16;
 113.381 +            vs->green_shift1 = 8;
 113.382 +            vs->blue_shift1 = 0;
 113.383 +            break;
 113.384 +        default:
 113.385 +            return;
 113.386 +    }
 113.387 +    if (ds->switchbpp) {
 113.388 +        vnc_client_error(vs);
 113.389 +    } else if (vs->csock != -1 && vs->has_WMVi) {
 113.390 +        /* Sending a WMVi message to notify the client*/
 113.391 +        vnc_write_u8(vs, 0);  /* msg id */
 113.392 +        vnc_write_u8(vs, 0);
 113.393 +        vnc_write_u16(vs, 1); /* number of rects */
 113.394 +        vnc_framebuffer_update(vs, 0, 0, ds->width, ds->height, 0x574D5669);
 113.395 +        pixel_format_message(vs);
 113.396 +        vnc_flush(vs);
 113.397 +    } else {
 113.398 +        if (vs->pix_bpp == 4 && vs->depth == 4 &&
 113.399 +            host_big_endian_flag == vs->pix_big_endian &&
 113.400 +            vs->red_max == 0xff && vs->green_max == 0xff && vs->blue_max == 0xff &&
 113.401 +            vs->red_shift == 16 && vs->green_shift == 8 && vs->blue_shift == 0) {
 113.402 +            vs->write_pixels = vnc_write_pixels_copy;
 113.403 +            vs->send_hextile_tile = send_hextile_tile_32;
 113.404 +        } else if (vs->pix_bpp == 2 && vs->depth == 2 &&
 113.405 +            host_big_endian_flag == vs->pix_big_endian &&
 113.406 +            vs->red_max == 31 && vs->green_max == 63 && vs->blue_max == 31 &&
 113.407 +            vs->red_shift == 11 && vs->green_shift == 5 && vs->blue_shift == 0) {
 113.408 +            vs->write_pixels = vnc_write_pixels_copy;
 113.409 +            vs->send_hextile_tile = send_hextile_tile_16;
 113.410 +        } else if (vs->pix_bpp == 1 && vs->depth == 1 &&
 113.411 +            host_big_endian_flag == vs->pix_big_endian &&
 113.412 +            vs->red_max == 7 && vs->green_max == 7 && vs->blue_max == 3 &&
 113.413 +            vs->red_shift == 5 && vs->green_shift == 2 && vs->blue_shift == 0) {
 113.414 +            vs->write_pixels = vnc_write_pixels_copy;
 113.415 +            vs->send_hextile_tile = send_hextile_tile_8;
 113.416 +        } else {
 113.417 +            if (vs->depth == 4) {
 113.418 +                vs->send_hextile_tile = send_hextile_tile_generic_32;
 113.419 +            } else if (vs->depth == 2) {
 113.420 +                vs->send_hextile_tile = send_hextile_tile_generic_16;
 113.421 +            } else {
 113.422 +                vs->send_hextile_tile = send_hextile_tile_generic_8;
 113.423 +            }
 113.424 +            vs->write_pixels = vnc_write_pixels_generic;
 113.425 +        }
 113.426 +    }
 113.427 +
 113.428 +    vnc_dpy_resize(ds, ds->width, ds->height);
 113.429 +}
 113.430 +
 113.431  static int protocol_client_msg(VncState *vs, uint8_t *data, size_t len)
 113.432  {
 113.433      int i;
 113.434 @@ -1473,7 +1641,6 @@ static int protocol_client_msg(VncState 
 113.435  static int protocol_client_init(VncState *vs, uint8_t *data, size_t len)
 113.436  {
 113.437      size_t l;
 113.438 -    char pad[3] = { 0, 0, 0 };
 113.439  
 113.440      vga_hw_update();
 113.441  
 113.442 @@ -1482,43 +1649,7 @@ static int protocol_client_init(VncState
 113.443      vnc_write_u16(vs, vs->ds->width);
 113.444      vnc_write_u16(vs, vs->ds->height);
 113.445  
 113.446 -    vnc_write_u8(vs, vs->depth * 8); /* bits-per-pixel */
 113.447 -    vnc_write_u8(vs, vs->depth * 8); /* depth */
 113.448 -#ifdef WORDS_BIGENDIAN
 113.449 -    vnc_write_u8(vs, 1);             /* big-endian-flag */
 113.450 -#else
 113.451 -    vnc_write_u8(vs, 0);             /* big-endian-flag */
 113.452 -#endif
 113.453 -    vnc_write_u8(vs, 1);             /* true-color-flag */
 113.454 -    if (vs->depth == 4) {
 113.455 -	vnc_write_u16(vs, 0xFF);     /* red-max */
 113.456 -	vnc_write_u16(vs, 0xFF);     /* green-max */
 113.457 -	vnc_write_u16(vs, 0xFF);     /* blue-max */
 113.458 -	vnc_write_u8(vs, 16);        /* red-shift */
 113.459 -	vnc_write_u8(vs, 8);         /* green-shift */
 113.460 -	vnc_write_u8(vs, 0);         /* blue-shift */
 113.461 -        vs->send_hextile_tile = send_hextile_tile_32;
 113.462 -    } else if (vs->depth == 2) {
 113.463 -	vnc_write_u16(vs, 31);       /* red-max */
 113.464 -	vnc_write_u16(vs, 63);       /* green-max */
 113.465 -	vnc_write_u16(vs, 31);       /* blue-max */
 113.466 -	vnc_write_u8(vs, 11);        /* red-shift */
 113.467 -	vnc_write_u8(vs, 5);         /* green-shift */
 113.468 -	vnc_write_u8(vs, 0);         /* blue-shift */
 113.469 -        vs->send_hextile_tile = send_hextile_tile_16;
 113.470 -    } else if (vs->depth == 1) {
 113.471 -        /* XXX: change QEMU pixel 8 bit pixel format to match the VNC one ? */
 113.472 -	vnc_write_u16(vs, 7);        /* red-max */
 113.473 -	vnc_write_u16(vs, 7);        /* green-max */
 113.474 -	vnc_write_u16(vs, 3);        /* blue-max */
 113.475 -	vnc_write_u8(vs, 5);         /* red-shift */
 113.476 -	vnc_write_u8(vs, 2);         /* green-shift */
 113.477 -	vnc_write_u8(vs, 0);         /* blue-shift */
 113.478 -        vs->send_hextile_tile = send_hextile_tile_8;
 113.479 -    }
 113.480 -    vs->write_pixels = vnc_write_pixels_copy;
 113.481 -	
 113.482 -    vnc_write(vs, pad, 3);           /* padding */
 113.483 +    pixel_format_message(vs);
 113.484  
 113.485      l = strlen(domain_name); 
 113.486      vnc_write_u32(vs, l);        
 113.487 @@ -2160,7 +2291,6 @@ void vnc_display_init(DisplayState *ds)
 113.488  
 113.489      vs->lsock = -1;
 113.490      vs->csock = -1;
 113.491 -    vs->depth = 4;
 113.492      vs->last_x = -1;
 113.493      vs->last_y = -1;
 113.494  
 113.495 @@ -2177,9 +2307,12 @@ void vnc_display_init(DisplayState *ds)
 113.496      vs->ds->data = NULL;
 113.497      vs->ds->dpy_update = vnc_dpy_update;
 113.498      vs->ds->dpy_resize = vnc_dpy_resize;
 113.499 +    vs->ds->dpy_colourdepth = vnc_dpy_colourdepth;
 113.500      vs->ds->dpy_refresh = vnc_dpy_refresh;
 113.501  
 113.502 -    vnc_dpy_resize(vs->ds, 640, 400);
 113.503 +    vs->ds->width = 640;
 113.504 +    vs->ds->height = 400;
 113.505 +    vnc_dpy_colourdepth(vs->ds, 32);
 113.506  }
 113.507  
 113.508  #if CONFIG_VNC_TLS
 113.509 @@ -2297,10 +2430,12 @@ int vnc_display_open(DisplayState *ds, c
 113.510  {
 113.511      struct sockaddr *addr;
 113.512      struct sockaddr_in iaddr;
 113.513 -#ifndef _WIN32
 113.514 +#ifndef NO_UNIX_SOCKETS
 113.515      struct sockaddr_un uaddr;
 113.516  #endif
 113.517 +#ifndef CONFIG_STUBDOM
 113.518      int reuse_addr, ret;
 113.519 +#endif
 113.520      socklen_t addrlen;
 113.521      const char *p;
 113.522      VncState *vs = ds ? (VncState *)ds->opaque : vnc_state;
 113.523 @@ -2325,6 +2460,8 @@ int vnc_display_open(DisplayState *ds, c
 113.524  	options++;
 113.525  	if (strncmp(options, "password", 8) == 0) {
 113.526  	    password = 1; /* Require password auth */
 113.527 +        } else if (strncmp(options, "switchbpp", 9) == 0) {
 113.528 +            ds->switchbpp = 1;
 113.529  #if CONFIG_VNC_TLS
 113.530  	} else if (strncmp(options, "tls", 3) == 0) {
 113.531  	    tls = 1; /* Require TLS */
 113.532 @@ -2432,6 +2569,15 @@ int vnc_display_open(DisplayState *ds, c
 113.533  	    return -1;
 113.534  	}
 113.535  
 113.536 +#ifdef CONFIG_STUBDOM
 113.537 +        {
 113.538 +            struct ip_addr ipaddr = { iaddr.sin_addr.s_addr };
 113.539 +            struct ip_addr netmask = { 0 };
 113.540 +            struct ip_addr gw = { 0 };
 113.541 +            networking_set_addr(&ipaddr, &netmask, &gw);
 113.542 +        }
 113.543 +#endif
 113.544 +
 113.545  	iaddr.sin_port = htons(ntohs(iaddr.sin_port) + 5900);
 113.546  
 113.547  	vs->lsock = socket(PF_INET, SOCK_STREAM, 0);
 113.548 @@ -2442,6 +2588,7 @@ int vnc_display_open(DisplayState *ds, c
 113.549  	    return -1;
 113.550  	}
 113.551  
 113.552 +#ifndef CONFIG_STUBDOM
 113.553  	reuse_addr = 1;
 113.554  	ret = setsockopt(vs->lsock, SOL_SOCKET, SO_REUSEADDR,
 113.555  			 (const char *)&reuse_addr, sizeof(reuse_addr));
 113.556 @@ -2453,6 +2600,7 @@ int vnc_display_open(DisplayState *ds, c
 113.557  	    vs->display = NULL;
 113.558  	    return -1;
 113.559  	}
 113.560 +#endif
 113.561      }
 113.562  
 113.563      while (bind(vs->lsock, addr, addrlen) == -1) {
 113.564 @@ -2483,6 +2631,7 @@ int vnc_display_open(DisplayState *ds, c
 113.565      return ntohs(iaddr.sin_port);
 113.566  }
 113.567  
 113.568 +#ifndef CONFIG_STUBDOM
 113.569  int vnc_start_viewer(int port)
 113.570  {
 113.571      int pid, i, open_max;
 113.572 @@ -2510,4 +2659,5 @@ int vnc_start_viewer(int port)
 113.573  	return pid;
 113.574      }
 113.575  }
 113.576 +#endif
 113.577  
   114.1 --- a/tools/ioemu/vnchextile.h	Wed Feb 13 10:37:18 2008 -0700
   114.2 +++ b/tools/ioemu/vnchextile.h	Thu Feb 14 09:34:27 2008 -0700
   114.3 @@ -2,29 +2,29 @@
   114.4  #define CONCAT(a, b) CONCAT_I(a, b)
   114.5  #define pixel_t CONCAT(uint, CONCAT(BPP, _t))
   114.6  #ifdef GENERIC
   114.7 -#define NAME generic
   114.8 +#define NAME CONCAT(generic_, BPP)
   114.9  #else
  114.10  #define NAME BPP
  114.11  #endif
  114.12  
  114.13  static void CONCAT(send_hextile_tile_, NAME)(VncState *vs,
  114.14                                               int x, int y, int w, int h,
  114.15 -                                             uint32_t *last_bg32, 
  114.16 -                                             uint32_t *last_fg32,
  114.17 +                                             void *last_bg_, 
  114.18 +                                             void *last_fg_,
  114.19                                               int *has_bg, int *has_fg)
  114.20  {
  114.21      uint8_t *row = (vs->ds->data + y * vs->ds->linesize + x * vs->depth);
  114.22      pixel_t *irow = (pixel_t *)row;
  114.23      int j, i;
  114.24 -    pixel_t *last_bg = (pixel_t *)last_bg32;
  114.25 -    pixel_t *last_fg = (pixel_t *)last_fg32;
  114.26 +    pixel_t *last_bg = (pixel_t *)last_bg_;
  114.27 +    pixel_t *last_fg = (pixel_t *)last_fg_;
  114.28      pixel_t bg = 0;
  114.29      pixel_t fg = 0;
  114.30      int n_colors = 0;
  114.31      int bg_count = 0;
  114.32      int fg_count = 0;
  114.33      int flags = 0;
  114.34 -    uint8_t data[(sizeof(pixel_t) + 2) * 16 * 16];
  114.35 +    uint8_t data[(vs->pix_bpp + 2) * 16 * 16];
  114.36      int n_data = 0;
  114.37      int n_subtiles = 0;
  114.38  
   115.1 --- a/tools/ioemu/xenstore.c	Wed Feb 13 10:37:18 2008 -0700
   115.2 +++ b/tools/ioemu/xenstore.c	Thu Feb 14 09:34:27 2008 -0700
   115.3 @@ -11,8 +11,10 @@
   115.4  #include "vl.h"
   115.5  #include "block_int.h"
   115.6  #include <unistd.h>
   115.7 +#ifndef CONFIG_STUBDOM
   115.8  #include <sys/ipc.h>
   115.9  #include <sys/shm.h>
  115.10 +#endif
  115.11  #include <sys/types.h>
  115.12  #include <sys/stat.h>
  115.13  #include <fcntl.h>
  115.14 @@ -219,10 +221,18 @@ void xenstore_parse_domain_config(int do
  115.15          }
  115.16  
  115.17          /* open device now if media present */
  115.18 +#ifdef CONFIG_STUBDOM
  115.19 +        if (pasprintf(&buf, "%s/device/vbd/%s", path, e[i]) == -1)
  115.20 +            continue;
  115.21 +	if (bdrv_open2(bs, buf, 0 /* snapshot */, &bdrv_vbd) == 0) {
  115.22 +	    pstrcpy(bs->filename, sizeof(bs->filename), params);
  115.23 +	    continue;
  115.24 +	}
  115.25 +#endif
  115.26 +
  115.27          if (params[0]) {
  115.28              if (bdrv_open(bs, params, 0 /* snapshot */) < 0)
  115.29 -                fprintf(stderr, "qemu: could not open hard disk image '%s'\n",
  115.30 -                        params);
  115.31 +                fprintf(stderr, "qemu: could not open vbd '%s' or hard disk image '%s'\n", buf, params);
  115.32          }
  115.33      }
  115.34  
  115.35 @@ -265,6 +275,10 @@ extern int vga_ram_size, bios_size;
  115.36  
  115.37  void xenstore_process_logdirty_event(void)
  115.38  {
  115.39 +#ifdef CONFIG_STUBDOM
  115.40 +    /* XXX we just can't use shm. */
  115.41 +    return;
  115.42 +#else
  115.43      char *act;
  115.44      static char *active_path = NULL;
  115.45      static char *next_active_path = NULL;
  115.46 @@ -367,6 +381,7 @@ void xenstore_process_logdirty_event(voi
  115.47      /* Ack that we've switched */
  115.48      xs_write(xsh, XBT_NULL, active_path, act, len);
  115.49      free(act);
  115.50 +#endif
  115.51  }
  115.52  
  115.53  
   116.1 --- a/tools/libxc/Makefile	Wed Feb 13 10:37:18 2008 -0700
   116.2 +++ b/tools/libxc/Makefile	Thu Feb 14 09:34:27 2008 -0700
   116.3 @@ -5,10 +5,12 @@ MAJOR    = 3.2
   116.4  MINOR    = 0
   116.5  
   116.6  CTRL_SRCS-y       :=
   116.7 +ifneq ($(stubdom),y)
   116.8  CTRL_SRCS-y       += xc_core.c
   116.9  CTRL_SRCS-$(CONFIG_X86) += xc_core_x86.c
  116.10  CTRL_SRCS-$(CONFIG_IA64) += xc_core_ia64.c
  116.11  CTRL_SRCS-$(CONFIG_POWERPC) += xc_core_powerpc.c
  116.12 +endif
  116.13  CTRL_SRCS-y       += xc_domain.c
  116.14  CTRL_SRCS-y       += xc_evtchn.c
  116.15  CTRL_SRCS-y       += xc_misc.c
  116.16 @@ -19,21 +21,27 @@ CTRL_SRCS-y       += xc_private.c
  116.17  CTRL_SRCS-y       += xc_sedf.c
  116.18  CTRL_SRCS-y       += xc_csched.c
  116.19  CTRL_SRCS-y       += xc_tbuf.c
  116.20 +ifneq ($(stubdom),y)
  116.21  CTRL_SRCS-y       += xc_resume.c
  116.22 +endif
  116.23  CTRL_SRCS-$(CONFIG_X86) += xc_pagetab.c
  116.24  CTRL_SRCS-$(CONFIG_Linux) += xc_linux.c
  116.25  CTRL_SRCS-$(CONFIG_SunOS) += xc_solaris.c
  116.26  CTRL_SRCS-$(CONFIG_X86_Linux) += xc_ptrace.c xc_ptrace_core.c
  116.27  CTRL_SRCS-$(CONFIG_NetBSD) += xc_netbsd.c
  116.28 +CTRL_SRCS-$(CONFIG_MiniOS) += xc_minios.c
  116.29  
  116.30  GUEST_SRCS-y :=
  116.31  GUEST_SRCS-y += xg_private.c
  116.32 +ifneq ($(stubdom),y)
  116.33  GUEST_SRCS-$(CONFIG_MIGRATE) += xc_domain_restore.c xc_domain_save.c
  116.34  GUEST_SRCS-$(CONFIG_HVM) += xc_hvm_build.c
  116.35 +endif
  116.36  
  116.37  VPATH = ../../xen/common/libelf
  116.38  CFLAGS += -I../../xen/common/libelf
  116.39  
  116.40 +ifneq ($(stubdom),y)
  116.41  GUEST_SRCS-y += libelf-tools.c libelf-loader.c
  116.42  GUEST_SRCS-y += libelf-dominfo.c libelf-relocate.c
  116.43  
  116.44 @@ -46,6 +54,7 @@ GUEST_SRCS-y += xc_dom_compat_linux.c
  116.45  GUEST_SRCS-$(CONFIG_X86)     += xc_dom_x86.c
  116.46  GUEST_SRCS-$(CONFIG_IA64)    += xc_dom_ia64.c
  116.47  GUEST_SRCS-$(CONFIG_POWERPC) += xc_dom_powerpc.c
  116.48 +endif
  116.49  
  116.50  -include $(XEN_TARGET_ARCH)/Makefile
  116.51  
  116.52 @@ -71,10 +80,14 @@ GUEST_LIB_OBJS := $(patsubst %.c,%.o,$(G
  116.53  GUEST_PIC_OBJS := $(patsubst %.c,%.opic,$(GUEST_SRCS-y))
  116.54  
  116.55  LIB := libxenctrl.a
  116.56 +ifneq ($(stubdom),y)
  116.57  LIB += libxenctrl.so libxenctrl.so.$(MAJOR) libxenctrl.so.$(MAJOR).$(MINOR)
  116.58 +endif
  116.59  
  116.60  LIB += libxenguest.a
  116.61 +ifneq ($(stubdom),y)
  116.62  LIB += libxenguest.so libxenguest.so.$(MAJOR) libxenguest.so.$(MAJOR).$(MINOR)
  116.63 +endif
  116.64  
  116.65  .PHONY: all
  116.66  all: build
  116.67 @@ -133,7 +146,7 @@ libxenctrl.so.$(MAJOR): libxenctrl.so.$(
  116.68  	ln -sf $< $@
  116.69  
  116.70  libxenctrl.so.$(MAJOR).$(MINOR): $(CTRL_PIC_OBJS)
  116.71 -	$(CC) $(CFLAGS) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenctrl.so.$(MAJOR) $(SHLIB_CFLAGS) -o $@ $^ -lpthread
  116.72 +	$(CC) $(CFLAGS) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenctrl.so.$(MAJOR) $(SHLIB_CFLAGS) -o $@ $^ $(PTHREAD_LIBS)
  116.73  
  116.74  # libxenguest
  116.75  
  116.76 @@ -146,7 +159,7 @@ libxenguest.so.$(MAJOR): libxenguest.so.
  116.77  	ln -sf $< $@
  116.78  
  116.79  libxenguest.so.$(MAJOR).$(MINOR): $(GUEST_PIC_OBJS) libxenctrl.so
  116.80 -	$(CC) $(CFLAGS) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenguest.so.$(MAJOR) $(SHLIB_CFLAGS) -o $@ $(GUEST_PIC_OBJS) -lz -lxenctrl -lpthread
  116.81 +	$(CC) $(CFLAGS) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenguest.so.$(MAJOR) $(SHLIB_CFLAGS) -o $@ $(GUEST_PIC_OBJS) -lz -lxenctrl $(PTHREAD_LIBS)
  116.82  
  116.83  -include $(DEPS)
  116.84  
   117.1 --- a/tools/libxc/ia64/Makefile	Wed Feb 13 10:37:18 2008 -0700
   117.2 +++ b/tools/libxc/ia64/Makefile	Thu Feb 14 09:34:27 2008 -0700
   117.3 @@ -1,3 +1,4 @@
   117.4 +ifneq ($(stubdom),y)
   117.5  CTRL_SRCS-y += ia64/xc_ia64_stubs.c
   117.6  
   117.7  GUEST_SRCS-y += ia64/xc_ia64_hvm_build.c
   117.8 @@ -8,6 +9,7 @@ GUEST_SRCS-y += ia64/xc_dom_ia64_util.c
   117.9  GUEST_SRCS-y += ia64/dom_fw_acpi.c
  117.10  
  117.11  DOMFW_SRCS_BASE := dom_fw_common.c dom_fw_domu.c dom_fw_asm.S
  117.12 +endif
  117.13  DOMFW_SRCS := $(addprefix ia64/, $(DOMFW_SRCS_BASE))
  117.14  $(DOMFW_SRCS):
  117.15  	ln -sf ../$(XEN_ROOT)/xen/arch/ia64/xen/$(@F) $@
   118.1 --- a/tools/libxc/xc_domain.c	Wed Feb 13 10:37:18 2008 -0700
   118.2 +++ b/tools/libxc/xc_domain.c	Thu Feb 14 09:34:27 2008 -0700
   118.3 @@ -350,21 +350,6 @@ int xc_shadow_control(int xc_handle,
   118.4      return (rc == 0) ? domctl.u.shadow_op.pages : rc;
   118.5  }
   118.6  
   118.7 -int xc_domain_setcpuweight(int xc_handle,
   118.8 -                           uint32_t domid,
   118.9 -                           float weight)
  118.10 -{
  118.11 -    int sched_id;
  118.12 -    int ret;
  118.13 -
  118.14 -    /* Figure out which scheduler is currently used: */
  118.15 -    if ( (ret = xc_sched_id(xc_handle, &sched_id)) != 0 )
  118.16 -        return ret;
  118.17 -
  118.18 -    /* No-op. */
  118.19 -    return 0;
  118.20 -}
  118.21 -
  118.22  int xc_domain_setmaxmem(int xc_handle,
  118.23                          uint32_t domid,
  118.24                          unsigned int max_memkb)
   119.1 --- a/tools/libxc/xc_domain_restore.c	Wed Feb 13 10:37:18 2008 -0700
   119.2 +++ b/tools/libxc/xc_domain_restore.c	Thu Feb 14 09:34:27 2008 -0700
   119.3 @@ -251,7 +251,7 @@ static xen_pfn_t *load_p2m_frame_list(
   119.4  
   119.5      /* Now that we know the guest's word-size, can safely allocate 
   119.6       * the p2m frame list */
   119.7 -    if ( (p2m_frame_list = malloc(P2M_FL_SIZE)) == NULL )
   119.8 +    if ( (p2m_frame_list = malloc(P2M_TOOLS_FL_SIZE)) == NULL )
   119.9      {
  119.10          ERROR("Couldn't allocate p2m_frame_list array");
  119.11          return NULL;
  119.12 @@ -1040,7 +1040,7 @@ int xc_domain_restore(int xc_handle, int
  119.13              SET_FIELD(&ctxt, gdt_frames[j], p2m[pfn]);
  119.14          }
  119.15          /* Uncanonicalise the page table base pointer. */
  119.16 -        pfn = xen_cr3_to_pfn(GET_FIELD(&ctxt, ctrlreg[3]));
  119.17 +        pfn = UNFOLD_CR3(GET_FIELD(&ctxt, ctrlreg[3]));
  119.18  
  119.19          if ( pfn >= p2m_size )
  119.20          {
  119.21 @@ -1057,12 +1057,12 @@ int xc_domain_restore(int xc_handle, int
  119.22                    (unsigned long)pt_levels<<XEN_DOMCTL_PFINFO_LTAB_SHIFT);
  119.23              goto out;
  119.24          }
  119.25 -        SET_FIELD(&ctxt, ctrlreg[3], xen_pfn_to_cr3(p2m[pfn]));
  119.26 +        SET_FIELD(&ctxt, ctrlreg[3], FOLD_CR3(p2m[pfn]));
  119.27  
  119.28          /* Guest pagetable (x86/64) stored in otherwise-unused CR1. */
  119.29          if ( (pt_levels == 4) && (ctxt.x64.ctrlreg[1] & 1) )
  119.30          {
  119.31 -            pfn = xen_cr3_to_pfn(ctxt.x64.ctrlreg[1] & ~1);
  119.32 +            pfn = UNFOLD_CR3(ctxt.x64.ctrlreg[1] & ~1);
  119.33              if ( pfn >= p2m_size )
  119.34              {
  119.35                  ERROR("User PT base is bad: pfn=%lu p2m_size=%lu",
  119.36 @@ -1077,7 +1077,7 @@ int xc_domain_restore(int xc_handle, int
  119.37                        (unsigned long)pt_levels<<XEN_DOMCTL_PFINFO_LTAB_SHIFT);
  119.38                  goto out;
  119.39              }
  119.40 -            ctxt.x64.ctrlreg[1] = xen_pfn_to_cr3(p2m[pfn]);
  119.41 +            ctxt.x64.ctrlreg[1] = FOLD_CR3(p2m[pfn]);
  119.42          }
  119.43          domctl.cmd = XEN_DOMCTL_setvcpucontext;
  119.44          domctl.domain = (domid_t)dom;
  119.45 @@ -1158,7 +1158,7 @@ int xc_domain_restore(int xc_handle, int
  119.46      if ( guest_width > sizeof (xen_pfn_t) )
  119.47          for ( i = p2m_size - 1; i >= 0; i-- )
  119.48              ((uint64_t *)p2m)[i] = p2m[i];
  119.49 -    else if ( guest_width > sizeof (xen_pfn_t) )
  119.50 +    else if ( guest_width < sizeof (xen_pfn_t) )
  119.51          for ( i = 0; i < p2m_size; i++ )   
  119.52              ((uint32_t *)p2m)[i] = p2m[i];
  119.53  
   120.1 --- a/tools/libxc/xc_domain_save.c	Wed Feb 13 10:37:18 2008 -0700
   120.2 +++ b/tools/libxc/xc_domain_save.c	Thu Feb 14 09:34:27 2008 -0700
   120.3 @@ -61,10 +61,11 @@ unsigned int guest_width;
   120.4  
   120.5  #define mfn_to_pfn(_mfn)  (live_m2p[(_mfn)])
   120.6  
   120.7 -#define pfn_to_mfn(_pfn)                                \
   120.8 -  ((xen_pfn_t) ((guest_width==8)                       \
   120.9 -                ? (((uint64_t *)live_p2m)[(_pfn)])      \
  120.10 -                : (((uint32_t *)live_p2m)[(_pfn)])))
  120.11 +#define pfn_to_mfn(_pfn)                                            \
  120.12 +  ((xen_pfn_t) ((guest_width==8)                                    \
  120.13 +                ? (((uint64_t *)live_p2m)[(_pfn)])                  \
  120.14 +                : ((((uint32_t *)live_p2m)[(_pfn)]) == 0xffffffffU  \
  120.15 +                   ? (-1UL) : (((uint32_t *)live_p2m)[(_pfn)]))))
  120.16  
  120.17  /*
  120.18   * Returns TRUE if the given machine frame number has a unique mapping
  120.19 @@ -496,10 +497,9 @@ static int canonicalize_pagetable(unsign
  120.20          xen_start = L3_PAGETABLE_ENTRIES_PAE;
  120.21  
  120.22      /*
  120.23 -    ** in PAE only the L2 mapping the top 1GB contains Xen mappings.
  120.24 -    ** We can spot this by looking for the guest linear mapping which
  120.25 -    ** Xen always ensures is present in that L2. Guests must ensure
  120.26 -    ** that this check will fail for other L2s.
  120.27 +    ** In PAE only the L2 mapping the top 1GB contains Xen mappings.
  120.28 +    ** We can spot this by looking for the guest's mappingof the m2p.
  120.29 +    ** Guests must ensure that this check will fail for other L2s.
  120.30      */
  120.31      if ( (pt_levels == 3) && (type == XEN_DOMCTL_PFINFO_L2TAB) )
  120.32      {
  120.33 @@ -555,7 +555,13 @@ static int canonicalize_pagetable(unsign
  120.34                  /* This will happen if the type info is stale which
  120.35                     is quite feasible under live migration */
  120.36                  pfn  = 0;  /* zap it - we'll retransmit this page later */
  120.37 -                race = 1;  /* inform the caller of race; fatal if !live */ 
  120.38 +                /* XXX: We can't spot Xen mappings in compat-mode L2es 
  120.39 +                 * from 64-bit tools, but the only thing in them is the
  120.40 +                 * compat m2p, so we quietly zap them.  This doesn't
  120.41 +                 * count as a race, so don't report it. */
  120.42 +                if ( !(type == XEN_DOMCTL_PFINFO_L2TAB 
  120.43 +                       && sizeof (unsigned long) > guest_width) )
  120.44 +                     race = 1;  /* inform the caller; fatal if !live */ 
  120.45              }
  120.46              else
  120.47                  pfn = mfn_to_pfn(mfn);
  120.48 @@ -690,7 +696,7 @@ static xen_pfn_t *map_and_save_p2m_table
  120.49              else
  120.50                  p2m_frame_list_list[i] = 0;
  120.51      else if ( guest_width < sizeof(unsigned long) )
  120.52 -        for ( i = PAGE_SIZE/sizeof(unsigned long) - 1; i >= 0; i++ )
  120.53 +        for ( i = PAGE_SIZE/sizeof(unsigned long) - 1; i >= 0; i-- )
  120.54              p2m_frame_list_list[i] = ((uint32_t *)p2m_frame_list_list)[i];
  120.55  
  120.56      live_p2m_frame_list =
  120.57 @@ -704,19 +710,20 @@ static xen_pfn_t *map_and_save_p2m_table
  120.58      }
  120.59  
  120.60      /* Get a local copy of the live_P2M_frame_list */
  120.61 -    if ( !(p2m_frame_list = malloc(P2M_FL_SIZE)) )
  120.62 +    if ( !(p2m_frame_list = malloc(P2M_TOOLS_FL_SIZE)) )
  120.63      {
  120.64          ERROR("Couldn't allocate p2m_frame_list array");
  120.65          goto out;
  120.66      }
  120.67 -    memcpy(p2m_frame_list, live_p2m_frame_list, P2M_FL_SIZE);
  120.68 +    memset(p2m_frame_list, 0, P2M_TOOLS_FL_SIZE);
  120.69 +    memcpy(p2m_frame_list, live_p2m_frame_list, P2M_GUEST_FL_SIZE);
  120.70  
  120.71      /* Canonicalize guest's unsigned long vs ours */
  120.72      if ( guest_width > sizeof(unsigned long) )
  120.73          for ( i = 0; i < P2M_FL_ENTRIES; i++ )
  120.74              p2m_frame_list[i] = ((uint64_t *)p2m_frame_list)[i];
  120.75      else if ( guest_width < sizeof(unsigned long) )
  120.76 -        for ( i = P2M_FL_ENTRIES - 1; i >= 0; i++ )
  120.77 +        for ( i = P2M_FL_ENTRIES - 1; i >= 0; i-- )
  120.78              p2m_frame_list[i] = ((uint32_t *)p2m_frame_list)[i];
  120.79  
  120.80  
  120.81 @@ -1559,31 +1566,26 @@ int xc_domain_save(int xc_handle, int io
  120.82          }
  120.83  
  120.84          /* Canonicalise the page table base pointer. */
  120.85 -        if ( !MFN_IS_IN_PSEUDOPHYS_MAP(xen_cr3_to_pfn(
  120.86 -                                          GET_FIELD(&ctxt, ctrlreg[3]))) )
  120.87 +        if ( !MFN_IS_IN_PSEUDOPHYS_MAP(UNFOLD_CR3(
  120.88 +                                           GET_FIELD(&ctxt, ctrlreg[3]))) )
  120.89          {
  120.90              ERROR("PT base is not in range of pseudophys map");
  120.91              goto out;
  120.92          }
  120.93          SET_FIELD(&ctxt, ctrlreg[3], 
  120.94 -            xen_pfn_to_cr3(
  120.95 -                mfn_to_pfn(
  120.96 -                    xen_cr3_to_pfn(
  120.97 -                        GET_FIELD(&ctxt, ctrlreg[3])))));
  120.98 +            FOLD_CR3(mfn_to_pfn(UNFOLD_CR3(GET_FIELD(&ctxt, ctrlreg[3])))));
  120.99  
 120.100          /* Guest pagetable (x86/64) stored in otherwise-unused CR1. */
 120.101          if ( (pt_levels == 4) && ctxt.x64.ctrlreg[1] )
 120.102          {
 120.103 -            if ( !MFN_IS_IN_PSEUDOPHYS_MAP(
 120.104 -                     xen_cr3_to_pfn(ctxt.x64.ctrlreg[1])) )
 120.105 +            if ( !MFN_IS_IN_PSEUDOPHYS_MAP(UNFOLD_CR3(ctxt.x64.ctrlreg[1])) )
 120.106              {
 120.107                  ERROR("PT base is not in range of pseudophys map");
 120.108                  goto out;
 120.109              }
 120.110              /* Least-significant bit means 'valid PFN'. */
 120.111              ctxt.x64.ctrlreg[1] = 1 |
 120.112 -                xen_pfn_to_cr3(
 120.113 -                    mfn_to_pfn(xen_cr3_to_pfn(ctxt.x64.ctrlreg[1])));
 120.114 +                FOLD_CR3(mfn_to_pfn(UNFOLD_CR3(ctxt.x64.ctrlreg[1])));
 120.115          }
 120.116  
 120.117          if ( write_exact(io_fd, &ctxt, ((guest_width==8) 
   121.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   121.2 +++ b/tools/libxc/xc_minios.c	Thu Feb 14 09:34:27 2008 -0700
   121.3 @@ -0,0 +1,313 @@
   121.4 +/******************************************************************************
   121.5 + *
   121.6 + * Copyright 2007-2008 Samuel Thibault <samuel.thibault@eu.citrix.com>.
   121.7 + * All rights reserved.
   121.8 + * Use is subject to license terms.
   121.9 + *
  121.10 + * This program is free software; you can redistribute it and/or
  121.11 + * modify it under the terms of the GNU General Public License as
  121.12 + * published by the Free Software Foundation, version 2 of the
  121.13 + * License.
  121.14 + */
  121.15 +
  121.16 +#undef NDEBUG
  121.17 +#include <types.h>
  121.18 +#include <os.h>
  121.19 +#include <mm.h>
  121.20 +#include <lib.h>
  121.21 +#include <events.h>
  121.22 +#include <wait.h>
  121.23 +#include <sys/mman.h>
  121.24 +#include <errno.h>
  121.25 +
  121.26 +#include <xen/memory.h>
  121.27 +#include <xen/sys/evtchn.h>
  121.28 +#include <unistd.h>
  121.29 +#include <fcntl.h>
  121.30 +#include <stdio.h>
  121.31 +#include <assert.h>
  121.32 +#include <stdint.h>
  121.33 +#include <inttypes.h>
  121.34 +
  121.35 +#include "xc_private.h"
  121.36 +
  121.37 +extern struct wait_queue_head event_queue;
  121.38 +
  121.39 +int xc_interface_open(void)
  121.40 +{
  121.41 +    return 0;
  121.42 +}
  121.43 +
  121.44 +int xc_interface_close(int xc_handle)
  121.45 +{
  121.46 +    return 0;
  121.47 +}
  121.48 +
  121.49 +void *xc_map_foreign_batch(int xc_handle, uint32_t dom, int prot,
  121.50 +                           xen_pfn_t *arr, int num)
  121.51 +{
  121.52 +    unsigned long pt_prot = 0;
  121.53 +#ifdef __ia64__
  121.54 +    /* TODO */
  121.55 +#else
  121.56 +    if (prot & PROT_READ)
  121.57 +	pt_prot = L1_PROT_RO;
  121.58 +    if (prot & PROT_WRITE)
  121.59 +	pt_prot = L1_PROT;
  121.60 +#endif
  121.61 +    return map_frames_ex(arr, num, 1, 0, 1, dom, 1, pt_prot);
  121.62 +}
  121.63 +
  121.64 +void *xc_map_foreign_range(int xc_handle, uint32_t dom,
  121.65 +                           int size, int prot,
  121.66 +                           unsigned long mfn)
  121.67 +{
  121.68 +    unsigned long pt_prot = 0;
  121.69 +    printf("xc_map_foreign_range(%lx, %d)\n", mfn, size);
  121.70 +#ifdef __ia64__
  121.71 +    /* TODO */
  121.72 +#else
  121.73 +    if (prot & PROT_READ)
  121.74 +	pt_prot = L1_PROT_RO;
  121.75 +    if (prot & PROT_WRITE)
  121.76 +	pt_prot = L1_PROT;
  121.77 +#endif
  121.78 +    assert(!(size % getpagesize()));
  121.79 +    return map_frames_ex(&mfn, size / getpagesize(), 0, 1, 1, dom, 0, pt_prot);
  121.80 +}
  121.81 +
  121.82 +int xc_map_foreign_ranges(int xc_handle, uint32_t dom,
  121.83 +                          privcmd_mmap_entry_t *entries, int nr)
  121.84 +{
  121.85 +    printf("xc_map_foreign_ranges, TODO\n");
  121.86 +    do_exit();
  121.87 +}
  121.88 +
  121.89 +int do_xen_hypercall(int xc_handle, privcmd_hypercall_t *hypercall)
  121.90 +{
  121.91 +    multicall_entry_t call;
  121.92 +    int i, ret;
  121.93 +
  121.94 +    call.op = hypercall->op;
  121.95 +    for (i = 0; i < sizeof(hypercall->arg) / sizeof(*hypercall->arg); i++)
  121.96 +	call.args[i] = hypercall->arg[i];
  121.97 +
  121.98 +    ret = HYPERVISOR_multicall(&call, 1);
  121.99 +
 121.100 +    if (ret < 0) {
 121.101 +	errno = -ret;
 121.102 +	return -1;
 121.103 +    }
 121.104 +    if (call.result < 0) {
 121.105 +        errno = -call.result;
 121.106 +        return -1;
 121.107 +    }
 121.108 +    return call.result;
 121.109 +}
 121.110 +
 121.111 +int xc_find_device_number(const char *name)
 121.112 +{
 121.113 +    printf("xc_find_device_number(%s)\n", name);
 121.114 +    do_exit();
 121.115 +}
 121.116 +
 121.117 +int xc_evtchn_open(void)
 121.118 +{
 121.119 +    int fd = alloc_fd(FTYPE_EVTCHN), i;
 121.120 +    for (i = 0; i < MAX_EVTCHN_PORTS; i++) {
 121.121 +	files[fd].evtchn.ports[i].port = -1;
 121.122 +        files[fd].evtchn.ports[i].bound = 0;
 121.123 +    }
 121.124 +    printf("evtchn_open() -> %d\n", fd);
 121.125 +    return fd;
 121.126 +}
 121.127 +
 121.128 +int xc_evtchn_close(int xce_handle)
 121.129 +{
 121.130 +    int i;
 121.131 +    for (i = 0; i < MAX_EVTCHN_PORTS; i++)
 121.132 +        if (files[xce_handle].evtchn.ports[i].bound)
 121.133 +            unbind_evtchn(files[xce_handle].evtchn.ports[i].port);
 121.134 +    files[xce_handle].type = FTYPE_NONE;
 121.135 +    return 0;
 121.136 +}
 121.137 +
 121.138 +int xc_evtchn_fd(int xce_handle)
 121.139 +{
 121.140 +    return xce_handle;
 121.141 +}
 121.142 +
 121.143 +int xc_evtchn_notify(int xce_handle, evtchn_port_t port)
 121.144 +{
 121.145 +    int ret;
 121.146 +
 121.147 +    ret = notify_remote_via_evtchn(port);
 121.148 +
 121.149 +    if (ret < 0) {
 121.150 +	errno = -ret;
 121.151 +	ret = -1;
 121.152 +    }
 121.153 +    return ret;
 121.154 +}
 121.155 +
 121.156 +/* XXX Note: This is not threadsafe */
 121.157 +static int port_alloc(int xce_handle) {
 121.158 +    int i;
 121.159 +    for (i= 0; i < MAX_EVTCHN_PORTS; i++)
 121.160 +	if (files[xce_handle].evtchn.ports[i].port == -1)
 121.161 +	    break;
 121.162 +    if (i == MAX_EVTCHN_PORTS) {
 121.163 +	printf("Too many ports in xc handle\n");
 121.164 +	errno = EMFILE;
 121.165 +	return -1;
 121.166 +    }
 121.167 +    files[xce_handle].evtchn.ports[i].pending = 0;
 121.168 +    return i;
 121.169 +}
 121.170 +
 121.171 +static void poke_port(int xce_handle, evtchn_port_t port)
 121.172 +{
 121.173 +    shared_info_t *s = HYPERVISOR_shared_info;
 121.174 +    printk("poking port %d\n", port);
 121.175 +    synch_set_bit(port, &s->evtchn_pending[0]);
 121.176 +    xc_evtchn_unmask(xce_handle, port);
 121.177 +}
 121.178 +
 121.179 +static void evtchn_handler(evtchn_port_t port, struct pt_regs *regs, void *data)
 121.180 +{
 121.181 +    int xce_handle = (intptr_t) data;
 121.182 +    int i;
 121.183 +    assert(files[xce_handle].type == FTYPE_EVTCHN);
 121.184 +    mask_evtchn(port);
 121.185 +    for (i= 0; i < MAX_EVTCHN_PORTS; i++)
 121.186 +	if (files[xce_handle].evtchn.ports[i].port == port)
 121.187 +	    break;
 121.188 +    if (i == MAX_EVTCHN_PORTS) {
 121.189 +	printk("Unknown port for handle %d\n", xce_handle);
 121.190 +	return;
 121.191 +    }
 121.192 +    files[xce_handle].evtchn.ports[i].pending++;
 121.193 +    files[xce_handle].read = 1;
 121.194 +    wake_up(&event_queue);
 121.195 +}
 121.196 +
 121.197 +evtchn_port_or_error_t xc_evtchn_bind_unbound_port(int xce_handle, int domid)
 121.198 +{
 121.199 +    int ret, i;
 121.200 +    evtchn_port_t port;
 121.201 +
 121.202 +    assert(get_current() == main_thread);
 121.203 +    i = port_alloc(xce_handle);
 121.204 +    if (i == -1)
 121.205 +	return -1;
 121.206 +
 121.207 +    printf("xc_evtchn_bind_unbound_port(%d)", domid);
 121.208 +    ret = evtchn_alloc_unbound(domid, evtchn_handler, (void*)(intptr_t)xce_handle, &port);
 121.209 +    printf(" = %d\n", ret);
 121.210 +
 121.211 +    if (ret < 0) {
 121.212 +	errno = -ret;
 121.213 +	return -1;
 121.214 +    }
 121.215 +    files[xce_handle].evtchn.ports[i].bound = 1;
 121.216 +    files[xce_handle].evtchn.ports[i].port = port;
 121.217 +    return port;
 121.218 +}
 121.219 +
 121.220 +evtchn_port_or_error_t xc_evtchn_bind_interdomain(int xce_handle, int domid,
 121.221 +    evtchn_port_t remote_port)
 121.222 +{
 121.223 +    evtchn_port_t local_port;
 121.224 +    int ret, i;
 121.225 +
 121.226 +    assert(get_current() == main_thread);
 121.227 +    i = port_alloc(xce_handle);
 121.228 +    if (i == -1)
 121.229 +	return -1;
 121.230 +
 121.231 +    printf("xc_evtchn_bind_interdomain(%d, %"PRId32")", domid, remote_port);
 121.232 +    ret = evtchn_bind_interdomain(domid, remote_port, evtchn_handler, (void*)(intptr_t)xce_handle, &local_port);
 121.233 +    printf(" = %d\n", ret);
 121.234 +
 121.235 +    if (ret < 0) {
 121.236 +	errno = -ret;
 121.237 +	return -1;
 121.238 +    }
 121.239 +    files[xce_handle].evtchn.ports[i].bound = 1;
 121.240 +    files[xce_handle].evtchn.ports[i].port = local_port;
 121.241 +/* Poke port on start: HVM won't send an event for the very first request since
 121.242 + * we were not ready yet */
 121.243 +    poke_port(xce_handle, local_port);
 121.244 +    return local_port;
 121.245 +}
 121.246 +
 121.247 +int xc_evtchn_unbind(int xce_handle, evtchn_port_t port)
 121.248 +{
 121.249 +    int i;
 121.250 +    for (i = 0; i < MAX_EVTCHN_PORTS; i++)
 121.251 +	if (files[xce_handle].evtchn.ports[i].port == port) {
 121.252 +	    files[xce_handle].evtchn.ports[i].port = -1;
 121.253 +	    break;
 121.254 +	}
 121.255 +    if (i == MAX_EVTCHN_PORTS)
 121.256 +	printf("Warning: couldn't find port %"PRId32" for xc handle %x\n", port, xce_handle);
 121.257 +    files[xce_handle].evtchn.ports[i].bound = 0;
 121.258 +    unbind_evtchn(port);
 121.259 +    return 0;
 121.260 +}
 121.261 +
 121.262 +evtchn_port_or_error_t xc_evtchn_bind_virq(int xce_handle, unsigned int virq)
 121.263 +{
 121.264 +    evtchn_port_t port;
 121.265 +    int i;
 121.266 +
 121.267 +    assert(get_current() == main_thread);
 121.268 +    i = port_alloc(xce_handle);
 121.269 +    if (i == -1)
 121.270 +	return -1;
 121.271 +
 121.272 +    printf("xc_evtchn_bind_virq(%d)", virq);
 121.273 +    port = bind_virq(virq, evtchn_handler, (void*)(intptr_t)xce_handle);
 121.274 +
 121.275 +    if (port < 0) {
 121.276 +	errno = -port;
 121.277 +	return -1;
 121.278 +    }
 121.279 +    files[xce_handle].evtchn.ports[i].bound = 1;
 121.280 +    files[xce_handle].evtchn.ports[i].port = port;
 121.281 +    return port;
 121.282 +}
 121.283 +
 121.284 +evtchn_port_or_error_t xc_evtchn_pending(int xce_handle)
 121.285 +{
 121.286 +    int i;
 121.287 +    unsigned long flags;
 121.288 +    local_irq_save(flags);
 121.289 +    for (i = 0; i < MAX_EVTCHN_PORTS; i++) {
 121.290 +	evtchn_port_t port = files[xce_handle].evtchn.ports[i].port;
 121.291 +	if (port != -1 && files[xce_handle].evtchn.ports[i].pending) {
 121.292 +	    files[xce_handle].evtchn.ports[i].pending--;
 121.293 +	    local_irq_restore(flags);
 121.294 +	    return port;
 121.295 +	}
 121.296 +    }
 121.297 +    files[xce_handle].read = 0;
 121.298 +    local_irq_restore(flags);
 121.299 +    return -1;
 121.300 +}
 121.301 +
 121.302 +int xc_evtchn_unmask(int xce_handle, evtchn_port_t port)
 121.303 +{
 121.304 +    unmask_evtchn(port);
 121.305 +    return 0;
 121.306 +}
 121.307 +
 121.308 +/*
 121.309 + * Local variables:
 121.310 + * mode: C
 121.311 + * c-set-style: "BSD"
 121.312 + * c-basic-offset: 4
 121.313 + * tab-width: 4
 121.314 + * indent-tabs-mode: nil
 121.315 + * End:
 121.316 + */
   122.1 --- a/tools/libxc/xenctrl.h	Wed Feb 13 10:37:18 2008 -0700
   122.2 +++ b/tools/libxc/xenctrl.h	Thu Feb 14 09:34:27 2008 -0700
   122.3 @@ -43,22 +43,21 @@
   122.4   */
   122.5  
   122.6  #if defined(__i386__)
   122.7 -#define mb()  __asm__ __volatile__ ( "lock; addl $0,0(%%esp)" : : : "memory" )
   122.8 -#define rmb() __asm__ __volatile__ ( "lock; addl $0,0(%%esp)" : : : "memory" )
   122.9 -#define wmb() __asm__ __volatile__ ( "" : : : "memory")
  122.10 +#define xen_mb()  asm volatile ( "lock; addl $0,0(%%esp)" : : : "memory" )
  122.11 +#define xen_rmb() asm volatile ( "lock; addl $0,0(%%esp)" : : : "memory" )
  122.12 +#define xen_wmb() asm volatile ( "" : : : "memory")
  122.13  #elif defined(__x86_64__)
  122.14 -#define mb()  __asm__ __volatile__ ( "mfence" : : : "memory")
  122.15 -#define rmb() __asm__ __volatile__ ( "lfence" : : : "memory")
  122.16 -#define wmb() __asm__ __volatile__ ( "" : : : "memory")
  122.17 +#define xen_mb()  asm volatile ( "mfence" : : : "memory")
  122.18 +#define xen_rmb() asm volatile ( "lfence" : : : "memory")
  122.19 +#define xen_wmb() asm volatile ( "" : : : "memory")
  122.20  #elif defined(__ia64__)
  122.21 -#define mb()   __asm__ __volatile__ ("mf" ::: "memory")
  122.22 -#define rmb()  __asm__ __volatile__ ("mf" ::: "memory")
  122.23 -#define wmb()  __asm__ __volatile__ ("mf" ::: "memory")
  122.24 +#define xen_mb()   asm volatile ("mf" ::: "memory")
  122.25 +#define xen_rmb()  asm volatile ("mf" ::: "memory")
  122.26 +#define xen_wmb()  asm volatile ("mf" ::: "memory")
  122.27  #elif defined(__powerpc__)
  122.28 -/* XXX loosen these up later */
  122.29 -#define mb()   __asm__ __volatile__ ("sync" : : : "memory")
  122.30 -#define rmb()  __asm__ __volatile__ ("sync" : : : "memory") /* lwsync? */
  122.31 -#define wmb()  __asm__ __volatile__ ("sync" : : : "memory") /* eieio? */
  122.32 +#define xen_mb()   asm volatile ("sync" : : : "memory")
  122.33 +#define xen_rmb()  asm volatile ("sync" : : : "memory") /* lwsync? */
  122.34 +#define xen_wmb()  asm volatile ("sync" : : : "memory") /* eieio? */
  122.35  #else
  122.36  #error "Define barriers"
  122.37  #endif
  122.38 @@ -380,9 +379,6 @@ int xc_vcpu_getinfo(int xc_handle,
  122.39                      uint32_t vcpu,
  122.40                      xc_vcpuinfo_t *info);
  122.41  
  122.42 -int xc_domain_setcpuweight(int xc_handle,
  122.43 -                           uint32_t domid,
  122.44 -                           float weight);
  122.45  long long xc_domain_get_cpu_usage(int xc_handle,
  122.46                                    domid_t domid,
  122.47                                    int vcpu);
   123.1 --- a/tools/libxc/xg_private.h	Wed Feb 13 10:37:18 2008 -0700
   123.2 +++ b/tools/libxc/xg_private.h	Thu Feb 14 09:34:27 2008 -0700
   123.3 @@ -155,7 +155,9 @@ typedef l4_pgentry_64_t l4_pgentry_t;
   123.4  #define P2M_FL_ENTRIES  (((p2m_size)+FPP-1)/FPP)
   123.5  
   123.6  /* Size in bytes of the pfn_to_mfn_frame_list     */
   123.7 -#define P2M_FL_SIZE     ((P2M_FL_ENTRIES)*(guest_width))
   123.8 +#define P2M_GUEST_FL_SIZE ((P2M_FL_ENTRIES) * (guest_width))
   123.9 +#define P2M_TOOLS_FL_SIZE ((P2M_FL_ENTRIES) *                           \
  123.10 +                           MAX((sizeof (xen_pfn_t)), guest_width))
  123.11  
  123.12  /* Masks for PTE<->PFN conversions */
  123.13  #define MADDR_BITS_X86  ((guest_width == 8) ? 52 : 44)
   124.1 --- a/tools/libxc/xg_save_restore.h	Wed Feb 13 10:37:18 2008 -0700
   124.2 +++ b/tools/libxc/xg_save_restore.h	Thu Feb 14 09:34:27 2008 -0700
   124.3 @@ -68,6 +68,13 @@ static inline int get_platform_info(int 
   124.4  
   124.5      *guest_width = domctl.u.address_size.size / 8;
   124.6  
   124.7 +    /* 64-bit tools will see the 64-bit hvirt_start, but 32-bit guests 
   124.8 +     * will be using the compat one. */
   124.9 +    if ( *guest_width < sizeof (unsigned long) )
  124.10 +        /* XXX need to fix up a way of extracting this value from Xen if
  124.11 +         * XXX it becomes variable for domU */
  124.12 +        *hvirt_start = 0xf5800000;
  124.13 +
  124.14      if (strstr(xen_caps, "xen-3.0-x86_64"))
  124.15          /* Depends on whether it's a compat 32-on-64 guest */
  124.16          *pt_levels = ( (*guest_width == 8) ? 4 : 3 );
  124.17 @@ -136,6 +143,16 @@ typedef union
  124.18          (_p)->x32._f = (_v);                    \
  124.19  } while (0)
  124.20  
  124.21 +#define UNFOLD_CR3(_c)                                                  \
  124.22 +  ((uint64_t)((guest_width == 8)                                        \
  124.23 +              ? ((_c) >> 12)                                            \
  124.24 +              : (((uint32_t)(_c) >> 12) | ((uint32_t)(_c) << 20))))
  124.25 +
  124.26 +#define FOLD_CR3(_c)                                                    \
  124.27 +  ((uint64_t)((guest_width == 8)                                        \
  124.28 +              ? ((uint64_t)(_c)) << 12                                  \
  124.29 +              : (((uint32_t)(_c) << 12) | ((uint32_t)(_c) >> 20))))
  124.30 +
  124.31  #define MEMCPY_FIELD(_d, _s, _f) do {                              \
  124.32      if (guest_width == 8)                                          \
  124.33          memcpy(&(_d)->x64._f, &(_s)->x64._f,sizeof((_d)->x64._f)); \
   125.1 --- a/tools/python/xen/lowlevel/xc/xc.c	Wed Feb 13 10:37:18 2008 -0700
   125.2 +++ b/tools/python/xen/lowlevel/xc/xc.c	Thu Feb 14 09:34:27 2008 -0700
   125.3 @@ -237,26 +237,6 @@ static PyObject *pyxc_vcpu_setaffinity(X
   125.4      return zero;
   125.5  }
   125.6  
   125.7 -static PyObject *pyxc_domain_setcpuweight(XcObject *self,
   125.8 -                                          PyObject *args,
   125.9 -                                          PyObject *kwds)
  125.10 -{
  125.11 -    uint32_t dom;
  125.12 -    float cpuweight = 1;
  125.13 -
  125.14 -    static char *kwd_list[] = { "domid", "cpuweight", NULL };
  125.15 -
  125.16 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|f", kwd_list, 
  125.17 -                                      &dom, &cpuweight) )
  125.18 -        return NULL;
  125.19 -
  125.20 -    if ( xc_domain_setcpuweight(self->xc_handle, dom, cpuweight) != 0 )
  125.21 -        return pyxc_error_to_exception();
  125.22 -    
  125.23 -    Py_INCREF(zero);
  125.24 -    return zero;
  125.25 -}
  125.26 -
  125.27  static PyObject *pyxc_domain_sethandle(XcObject *self, PyObject *args)
  125.28  {
  125.29      int i;
  125.30 @@ -1325,14 +1305,6 @@ static PyMethodDef pyxc_methods[] = {
  125.31        " cpumap [list, []]: list of usable CPUs.\n\n"
  125.32        "Returns: [int] 0 on success; -1 on error.\n" },
  125.33  
  125.34 -    { "domain_setcpuweight", 
  125.35 -      (PyCFunction)pyxc_domain_setcpuweight, 
  125.36 -      METH_VARARGS | METH_KEYWORDS, "\n"
  125.37 -      "Set cpuweight scheduler parameter for domain.\n"
  125.38 -      " dom [int]:            Identifier of domain to be changed.\n"
  125.39 -      " cpuweight [float, 1]: VCPU being pinned.\n"
  125.40 -      "Returns: [int] 0 on success; -1 on error.\n" },
  125.41 -
  125.42      { "domain_sethandle", 
  125.43        (PyCFunction)pyxc_domain_sethandle,
  125.44        METH_VARARGS, "\n"
   126.1 --- a/tools/python/xen/xend/XendConfig.py	Wed Feb 13 10:37:18 2008 -0700
   126.2 +++ b/tools/python/xen/xend/XendConfig.py	Thu Feb 14 09:34:27 2008 -0700
   126.3 @@ -127,7 +127,7 @@ LEGACY_CFG_TO_XENAPI_CFG = reverse_dict(
   126.4  XENAPI_PLATFORM_CFG = [ 'acpi', 'apic', 'boot', 'device_model', 'loader', 'display', 
   126.5                          'fda', 'fdb', 'keymap', 'isa', 'localtime', 'monitor', 
   126.6                          'nographic', 'pae', 'rtc_timeoffset', 'serial', 'sdl',
   126.7 -                        'soundhw','stdvga', 'usb', 'usbdevice', 'vnc',
   126.8 +                        'soundhw','stdvga', 'usb', 'usbdevice', 'hpet', 'vnc',
   126.9                          'vncconsole', 'vncdisplay', 'vnclisten', 'timer_mode',
  126.10                          'vncpasswd', 'vncunused', 'xauthority', 'pci', 'vhpt',
  126.11                          'guest_os_type', 'hap']
  126.12 @@ -406,15 +406,13 @@ class XendConfig(dict):
  126.13  
  126.14          if self.is_hvm():
  126.15              if 'loader' not in self['platform']:
  126.16 -                log.debug("No loader present")
  126.17 -                # Old configs may have hvmloder set as PV_kernel param,
  126.18 -                # so lets migrate them....
  126.19 -                if self['PV_kernel'] == "/usr/lib/xen/boot/hvmloader":
  126.20 +                # Old configs may have hvmloader set as PV_kernel param
  126.21 +                if self.has_key('PV_kernel') and re.search('hvmloader', self['PV_kernel']):
  126.22                      self['platform']['loader'] = self['PV_kernel']
  126.23 -                    log.debug("Loader copied from kernel %s" % str(self['platform']['loader']))
  126.24 +                    self['PV_kernel'] = ''
  126.25                  else:
  126.26                      self['platform']['loader'] = "/usr/lib/xen/boot/hvmloader"
  126.27 -                    log.debug("Loader %s" % str(self['platform']['loader']))
  126.28 +                log.debug("Loader is %s" % str(self['platform']['loader']))
  126.29  
  126.30              # Compatibility hack, can go away soon.
  126.31              if 'soundhw' not in self['platform'] and \
   127.1 --- a/tools/python/xen/xend/XendConstants.py	Wed Feb 13 10:37:18 2008 -0700
   127.2 +++ b/tools/python/xen/xend/XendConstants.py	Thu Feb 14 09:34:27 2008 -0700
   127.3 @@ -47,6 +47,7 @@ HVM_PARAM_NVRAM_FD     = 7
   127.4  HVM_PARAM_VHPT_SIZE    = 8
   127.5  HVM_PARAM_BUFPIOREQ_PFN = 9
   127.6  HVM_PARAM_TIMER_MODE   = 10
   127.7 +HVM_PARAM_HPET_ENABLED = 11
   127.8  
   127.9  restart_modes = [
  127.10      "restart",
   128.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Wed Feb 13 10:37:18 2008 -0700
   128.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Thu Feb 14 09:34:27 2008 -0700
   128.3 @@ -707,9 +707,6 @@ class XendDomainInfo:
   128.4          log.debug("Setting memory maximum of domain %s (%s) to %d MiB.",
   128.5                    self.info['name_label'], str(self.domid), limit)
   128.6  
   128.7 -        if limit <= 0:
   128.8 -            raise XendError('Invalid memory size')
   128.9 -
  128.10          MiB = 1024 * 1024
  128.11          self._safe_set_memory('memory_static_max', limit * MiB)
  128.12  
  128.13 @@ -1692,6 +1689,12 @@ class XendDomainInfo:
  128.14              xc.hvm_set_param(self.domid, HVM_PARAM_TIMER_MODE,
  128.15                               long(timer_mode))
  128.16  
  128.17 +        # Optionally enable virtual HPET
  128.18 +        hpet = self.info["platform"].get("hpet")
  128.19 +        if hvm and hpet is not None:
  128.20 +            xc.hvm_set_param(self.domid, HVM_PARAM_HPET_ENABLED,
  128.21 +                             long(hpet))
  128.22 +
  128.23          # Set maximum number of vcpus in domain
  128.24          xc.domain_max_vcpus(self.domid, int(self.info['VCPUs_max']))
  128.25  
  128.26 @@ -1750,9 +1753,6 @@ class XendDomainInfo:
  128.27  
  128.28              self.image = image.create(self, self.info)
  128.29  
  128.30 -            xc.domain_setcpuweight(self.domid, \
  128.31 -                                   self.info['vcpus_params']['weight'])
  128.32 -
  128.33              # repin domain vcpus if a restricted cpus list is provided
  128.34              # this is done prior to memory allocation to aide in memory
  128.35              # distribution for NUMA systems.
   129.1 --- a/tools/python/xen/xend/XendPBD.py	Wed Feb 13 10:37:18 2008 -0700
   129.2 +++ b/tools/python/xen/xend/XendPBD.py	Thu Feb 14 09:34:27 2008 -0700
   129.3 @@ -20,6 +20,7 @@ import uuid
   129.4  from XendLogging import log
   129.5  from xen.xend.XendBase import XendBase
   129.6  from xen.xend import XendAPIStore
   129.7 +from xen.xend import uuid as genuuid
   129.8  
   129.9  class XendPBD(XendBase):
  129.10      """Physical block devices."""
  129.11 @@ -39,8 +40,7 @@ class XendPBD(XendBase):
  129.12          return XendBase.getAttrRW() + attrRW
  129.13  
  129.14      def getAttrInst(self):
  129.15 -        return ['uuid',
  129.16 -                'host',
  129.17 +        return ['host',
  129.18                  'SR',
  129.19                  'device_config']
  129.20  
  129.21 @@ -61,31 +61,31 @@ class XendPBD(XendBase):
  129.22      getFuncs    = classmethod(getFuncs)
  129.23  
  129.24      def recreate(uuid, record):
  129.25 -        pbd = XendPBD(uuid, record)
  129.26 +        pbd = XendPBD(record, uuid)
  129.27          return uuid
  129.28      
  129.29      def create(cls, record):
  129.30          uuid = genuuid.createString()
  129.31 -        pbd = XendPBD(uuid, record)
  129.32 -        return uuid       
  129.33 +        pbd = XendPBD(record, uuid)
  129.34 +        return uuid
  129.35  
  129.36      create = classmethod(create)
  129.37      
  129.38 -    def __init__(self, uuid, record):
  129.39 +    def __init__(self, record,  uuid):
  129.40          XendBase.__init__(self, uuid, record)
  129.41 -        this.currently_attached = True
  129.42 +        self.currently_attached = True
  129.43  
  129.44      def get_host(self):
  129.45 -        return this.host
  129.46 +        return self.host
  129.47      
  129.48      def get_SR(self):
  129.49 -        return this.SR
  129.50 +        return self.SR
  129.51  
  129.52      def get_device_config(self):
  129.53 -        return this.device_config
  129.54 +        return self.device_config
  129.55  
  129.56      def get_currently_attached(self):
  129.57 -        return this.currently_attached
  129.58 +        return self.currently_attached
  129.59  
  129.60      def destroy(self):
  129.61          pass
   130.1 --- a/tools/python/xen/xend/image.py	Wed Feb 13 10:37:18 2008 -0700
   130.2 +++ b/tools/python/xen/xend/image.py	Thu Feb 14 09:34:27 2008 -0700
   130.3 @@ -91,12 +91,12 @@ class ImageHandler:
   130.4                          ("image/cmdline", self.cmdline),
   130.5                          ("image/ramdisk", self.ramdisk))
   130.6  
   130.7 -        self.dmargs = self.parseDeviceModelArgs(vmConfig)
   130.8          self.device_model = vmConfig['platform'].get('device_model')
   130.9  
  130.10          self.display = vmConfig['platform'].get('display')
  130.11          self.xauthority = vmConfig['platform'].get('xauthority')
  130.12          self.vncconsole = vmConfig['platform'].get('vncconsole')
  130.13 +        self.dmargs = self.parseDeviceModelArgs(vmConfig)
  130.14          self.pid = None
  130.15  
  130.16  
  130.17 @@ -204,8 +204,14 @@ class ImageHandler:
  130.18          for dev_uuid in vmConfig['console_refs']:
  130.19              dev_type, dev_info = vmConfig['devices'][dev_uuid]
  130.20              if dev_type == 'vfb':
  130.21 -                vnc_config = dev_info.get('other_config', {})
  130.22 -                has_vnc = True
  130.23 +                vfb_type = dev_info.get('type', {})
  130.24 +                if vfb_type == 'sdl':
  130.25 +                    self.display = dev_info.get('display', {})
  130.26 +                    self.xauthority = dev_info.get('xauthority', {})
  130.27 +                    has_sdl = True
  130.28 +                else:
  130.29 +                    vnc_config = dev_info.get('other_config', {})
  130.30 +                    has_vnc = True
  130.31                  break
  130.32  
  130.33          keymap = vmConfig['platform'].get("keymap")
  130.34 @@ -329,16 +335,27 @@ class ImageHandler:
  130.35              return
  130.36          if self.pid:
  130.37              try:
  130.38 -                os.kill(self.pid, signal.SIGKILL)
  130.39 +                os.kill(self.pid, signal.SIGHUP)
  130.40              except OSError, exn:
  130.41                  log.exception(exn)
  130.42              try:
  130.43 -                os.waitpid(self.pid, 0)
  130.44 +                # Try to reap the child every 100ms for 10s. Then SIGKILL it.
  130.45 +                for i in xrange(100):
  130.46 +                    (p, rv) = os.waitpid(self.pid, os.WNOHANG)
  130.47 +                    if p == self.pid:
  130.48 +                        break
  130.49 +                    time.sleep(0.1)
  130.50 +                else:
  130.51 +                    log.warning("DeviceModel %d took more than 10s "
  130.52 +                                "to terminate: sending SIGKILL" % self.pid)
  130.53 +                    os.kill(self.pid, signal.SIGKILL)
  130.54 +                    os.waitpid(self.pid, 0)
  130.55              except OSError, exn:
  130.56                  # This is expected if Xend has been restarted within the
  130.57                  # life of this domain.  In this case, we can kill the process,
  130.58                  # but we can't wait for it because it's not our child.
  130.59 -                pass
  130.60 +                # We just make really sure it's going away (SIGKILL) first.
  130.61 +                os.kill(self.pid, signal.SIGKILL)
  130.62              self.pid = None
  130.63              state = xstransact.Remove("/local/domain/0/device-model/%i"
  130.64                                        % self.vm.getDomid())
  130.65 @@ -449,7 +466,7 @@ class HVMImageHandler(ImageHandler):
  130.66          ret = ImageHandler.parseDeviceModelArgs(self, vmConfig)
  130.67          ret = ret + ['-vcpus', str(self.vm.getVCpuCount())]
  130.68  
  130.69 -        if self.kernel and self.kernel != "/usr/lib/xen/boot/hvmloader":
  130.70 +        if self.kernel:
  130.71              log.debug("kernel         = %s", self.kernel)
  130.72              ret = ret + ['-kernel', self.kernel]
  130.73          if self.ramdisk:
   131.1 --- a/tools/python/xen/xm/create.py	Wed Feb 13 10:37:18 2008 -0700
   131.2 +++ b/tools/python/xen/xm/create.py	Thu Feb 14 09:34:27 2008 -0700
   131.3 @@ -198,6 +198,10 @@ gopts.var('pae', val='PAE',
   131.4            fn=set_int, default=1,
   131.5            use="Disable or enable PAE of HVM domain.")
   131.6  
   131.7 +gopts.var('hpet', val='HPET',
   131.8 +          fn=set_int, default=0,
   131.9 +          use="Enable virtual high-precision event timer.")
  131.10 +
  131.11  gopts.var('timer_mode', val='TIMER_MODE',
  131.12            fn=set_int, default=0,
  131.13            use="""Timer mode (0=delay virtual time when ticks are missed;
  131.14 @@ -740,7 +744,7 @@ def configure_hvm(config_image, vals):
  131.15               'localtime', 'serial', 'stdvga', 'isa', 'nographic', 'soundhw',
  131.16               'vnc', 'vncdisplay', 'vncunused', 'vncconsole', 'vnclisten',
  131.17               'sdl', 'display', 'xauthority', 'rtc_timeoffset', 'monitor',
  131.18 -             'acpi', 'apic', 'usb', 'usbdevice', 'keymap', 'pci',
  131.19 +             'acpi', 'apic', 'usb', 'usbdevice', 'keymap', 'pci', 'hpet',
  131.20               'guest_os_type', 'hap']
  131.21  
  131.22      for a in args:
   132.1 --- a/tools/python/xen/xm/xenapi_create.py	Wed Feb 13 10:37:18 2008 -0700
   132.2 +++ b/tools/python/xen/xm/xenapi_create.py	Thu Feb 14 09:34:27 2008 -0700
   132.3 @@ -818,7 +818,8 @@ class sxp2xml:
   132.4  
   132.5  
   132.6      def extract_platform(self, image, document):
   132.7 -        platform_keys = ['acpi', 'apic', 'pae', 'vhpt', 'timer_mode', 'hap']
   132.8 +        platform_keys = ['acpi', 'apic', 'pae', 'vhpt', 'timer_mode',
   132.9 +                         'hap', 'hpet']
  132.10  
  132.11          def extract_platform_key(key):
  132.12              platform = document.createElement("platform")
   133.1 --- a/tools/xenmon/xenbaked.c	Wed Feb 13 10:37:18 2008 -0700
   133.2 +++ b/tools/xenmon/xenbaked.c	Thu Feb 14 09:34:27 2008 -0700
   133.3 @@ -511,10 +511,10 @@ int monitor_tbufs(void)
   133.4          {
   133.5              while ( meta[i]->cons != meta[i]->prod )
   133.6              {
   133.7 -                rmb(); /* read prod, then read item. */
   133.8 +                xen_rmb(); /* read prod, then read item. */
   133.9                  rec_size = process_record(
  133.10                      i, (struct t_rec *)(data[i] + meta[i]->cons % data_size));
  133.11 -                mb(); /* read item, then update cons. */
  133.12 +                xen_mb(); /* read item, then update cons. */
  133.13                  meta[i]->cons += rec_size;
  133.14              }
  133.15          }
   134.1 --- a/tools/xenstore/xenstored_domain.c	Wed Feb 13 10:37:18 2008 -0700
   134.2 +++ b/tools/xenstore/xenstored_domain.c	Thu Feb 14 09:34:27 2008 -0700
   134.3 @@ -112,7 +112,7 @@ static int writechn(struct connection *c
   134.4  	/* Must read indexes once, and before anything else, and verified. */
   134.5  	cons = intf->rsp_cons;
   134.6  	prod = intf->rsp_prod;
   134.7 -	mb();
   134.8 +	xen_mb();
   134.9  
  134.10  	if (!check_indexes(cons, prod)) {
  134.11  		errno = EIO;
  134.12 @@ -124,7 +124,7 @@ static int writechn(struct connection *c
  134.13  		len = avail;
  134.14  
  134.15  	memcpy(dest, data, len);
  134.16 -	mb();
  134.17 +	xen_mb();
  134.18  	intf->rsp_prod += len;
  134.19  
  134.20  	xc_evtchn_notify(xce_handle, conn->domain->port);
  134.21 @@ -142,7 +142,7 @@ static int readchn(struct connection *co
  134.22  	/* Must read indexes once, and before anything else, and verified. */
  134.23  	cons = intf->req_cons;
  134.24  	prod = intf->req_prod;
  134.25 -	mb();
  134.26 +	xen_mb();
  134.27  
  134.28  	if (!check_indexes(cons, prod)) {
  134.29  		errno = EIO;
  134.30 @@ -154,7 +154,7 @@ static int readchn(struct connection *co
  134.31  		len = avail;
  134.32  
  134.33  	memcpy(data, src, len);
  134.34 -	mb();
  134.35 +	xen_mb();
  134.36  	intf->req_cons += len;
  134.37  
  134.38  	xc_evtchn_notify(xce_handle, conn->domain->port);
   135.1 --- a/tools/xentrace/xentrace.c	Wed Feb 13 10:37:18 2008 -0700
   135.2 +++ b/tools/xentrace/xentrace.c	Thu Feb 14 09:34:27 2008 -0700
   135.3 @@ -23,6 +23,7 @@
   135.4  #include <string.h>
   135.5  #include <getopt.h>
   135.6  #include <assert.h>
   135.7 +#include <sys/poll.h>
   135.8  
   135.9  #include <xen/xen.h>
  135.10  #include <xen/trace.h>
  135.11 @@ -40,9 +41,6 @@ do {                                    
  135.12  
  135.13  /***** Compile time configuration of defaults ********************************/
  135.14  
  135.15 -/* when we've got more records than this waiting, we log it to the output */
  135.16 -#define NEW_DATA_THRESH 1
  135.17 -
  135.18  /* sleep for this long (milliseconds) between checking the trace buffers */
  135.19  #define POLL_SLEEP_MILLIS 100
  135.20  
  135.21 @@ -51,8 +49,7 @@ do {                                    
  135.22  
  135.23  typedef struct settings_st {
  135.24      char *outfile;
  135.25 -    struct timespec poll_sleep;
  135.26 -    unsigned long new_data_thresh;
  135.27 +    unsigned long poll_sleep; /* milliseconds to sleep between polls */
  135.28      uint32_t evt_mask;
  135.29      uint32_t cpu_mask;
  135.30      unsigned long tbuf_size;
  135.31 @@ -63,26 +60,16 @@ settings_t opts;
  135.32  
  135.33  int interrupted = 0; /* gets set if we get a SIGHUP */
  135.34  
  135.35 +static int xc_handle = -1;
  135.36 +static int event_fd = -1;
  135.37 +static int virq_port = -1;
  135.38 +
  135.39  void close_handler(int signal)
  135.40  {
  135.41      interrupted = 1;
  135.42  }
  135.43  
  135.44  /**
  135.45 - * millis_to_timespec - convert a time in milliseconds to a struct timespec
  135.46 - * @millis:             time interval in milliseconds
  135.47 - */
  135.48 -struct timespec millis_to_timespec(unsigned long millis)
  135.49 -{
  135.50 -    struct timespec spec;
  135.51 -    
  135.52 -    spec.tv_sec = millis / 1000;
  135.53 -    spec.tv_nsec = (millis % 1000) * 1000;
  135.54 -
  135.55 -    return spec;
  135.56 -}
  135.57 -
  135.58 -/**
  135.59   * write_buffer - write a section of the trace buffer
  135.60   * @cpu      - source buffer CPU ID
  135.61   * @start
  135.62 @@ -143,14 +130,8 @@ void write_buffer(unsigned int cpu, unsi
  135.63  
  135.64  static void get_tbufs(unsigned long *mfn, unsigned long *size)
  135.65  {
  135.66 -    int xc_handle = xc_interface_open();
  135.67      int ret;
  135.68  
  135.69 -    if ( xc_handle < 0 ) 
  135.70 -    {
  135.71 -        exit(EXIT_FAILURE);
  135.72 -    }
  135.73 -
  135.74      if(!opts.tbuf_size)
  135.75        opts.tbuf_size = DEFAULT_TBUF_SIZE;
  135.76  
  135.77 @@ -161,8 +142,6 @@ static void get_tbufs(unsigned long *mfn
  135.78          perror("Couldn't enable trace buffers");
  135.79          exit(1);
  135.80      }
  135.81 -
  135.82 -    xc_interface_close(xc_handle);
  135.83  }
  135.84  
  135.85  /**
  135.86 @@ -176,22 +155,12 @@ static void get_tbufs(unsigned long *mfn
  135.87  struct t_buf *map_tbufs(unsigned long tbufs_mfn, unsigned int num,
  135.88                          unsigned long size)
  135.89  {
  135.90 -    int xc_handle;
  135.91      struct t_buf *tbufs_mapped;
  135.92  
  135.93 -    xc_handle = xc_interface_open();
  135.94 -
  135.95 -    if ( xc_handle < 0 ) 
  135.96 -    {
  135.97 -        exit(EXIT_FAILURE);
  135.98 -    }
  135.99 -
 135.100      tbufs_mapped = xc_map_foreign_range(xc_handle, DOMID_XEN,
 135.101                                          size * num, PROT_READ | PROT_WRITE,
 135.102                                          tbufs_mfn);
 135.103  
 135.104 -    xc_interface_close(xc_handle);
 135.105 -
 135.106      if ( tbufs_mapped == 0 ) 
 135.107      {
 135.108          PERROR("Failed to mmap trace buffers");
 135.109 @@ -210,7 +179,6 @@ struct t_buf *map_tbufs(unsigned long tb
 135.110  void set_mask(uint32_t mask, int type)
 135.111  {
 135.112      int ret = 0;
 135.113 -    int xc_handle = xc_interface_open(); /* for accessing control interface */
 135.114  
 135.115      if (type == 1) {
 135.116          ret = xc_tbuf_set_cpu_mask(xc_handle, mask);
 135.117 @@ -220,8 +188,6 @@ void set_mask(uint32_t mask, int type)
 135.118          fprintf(stderr, "change evtmask to 0x%x\n", mask);
 135.119      }
 135.120  
 135.121 -    xc_interface_close(xc_handle);
 135.122 -
 135.123      if ( ret != 0 )
 135.124      {
 135.125          PERROR("Failure to get trace buffer pointer from Xen and set the new mask");
 135.126 @@ -295,7 +261,6 @@ unsigned char **init_rec_ptrs(struct t_b
 135.127  unsigned int get_num_cpus(void)
 135.128  {
 135.129      xc_physinfo_t physinfo = { 0 };
 135.130 -    int xc_handle = xc_interface_open();
 135.131      int ret;
 135.132      
 135.133      ret = xc_physinfo(xc_handle, &physinfo);
 135.134 @@ -306,9 +271,68 @@ unsigned int get_num_cpus(void)
 135.135          exit(EXIT_FAILURE);
 135.136      }
 135.137  
 135.138 -    xc_interface_close(xc_handle);
 135.139 +    return physinfo.nr_cpus;
 135.140 +}
 135.141  
 135.142 -    return physinfo.nr_cpus;
 135.143 +/**
 135.144 + * event_init - setup to receive the VIRQ_TBUF event
 135.145 + */
 135.146 +void event_init(void)
 135.147 +{
 135.148 +    int rc;
 135.149 +
 135.150 +    rc = xc_evtchn_open();
 135.151 +    if (rc < 0) {
 135.152 +        perror(xc_get_last_error()->message);
 135.153 +        exit(EXIT_FAILURE);
 135.154 +    }
 135.155 +    event_fd = rc;
 135.156 +
 135.157 +    rc = xc_evtchn_bind_virq(event_fd, VIRQ_TBUF);
 135.158 +    if (rc == -1) {
 135.159 +        PERROR("failed to bind to VIRQ port");
 135.160 +        exit(EXIT_FAILURE);
 135.161 +    }
 135.162 +    virq_port = rc;
 135.163 +}
 135.164 +
 135.165 +/**
 135.166 + * wait_for_event_or_timeout - sleep for the specified number of milliseconds,
 135.167 + *                             or until an VIRQ_TBUF event occurs
 135.168 + */
 135.169 +void wait_for_event_or_timeout(unsigned long milliseconds)
 135.170 +{
 135.171 +    int rc;
 135.172 +    struct pollfd fd = { .fd = event_fd,
 135.173 +                         .events = POLLIN | POLLERR };
 135.174 +    int port;
 135.175 +
 135.176 +    rc = poll(&fd, 1, milliseconds);
 135.177 +    if (rc == -1) {
 135.178 +        if (errno == EINTR)
 135.179 +            return;
 135.180 +        PERROR("poll exitted with an error");
 135.181 +        exit(EXIT_FAILURE);
 135.182 +    }
 135.183 +
 135.184 +    if (rc == 1) {
 135.185 +        port = xc_evtchn_pending(event_fd);
 135.186 +        if (port == -1) {
 135.187 +            PERROR("failed to read port from evtchn");
 135.188 +            exit(EXIT_FAILURE);
 135.189 +        }
 135.190 +        if (port != virq_port) {
 135.191 +            fprintf(stderr,
 135.192 +                    "unexpected port returned from evtchn (got %d vs expected %d)\n",
 135.193 +                    port, virq_port);
 135.194 +            exit(EXIT_FAILURE);
 135.195 +        }
 135.196 +        rc = xc_evtchn_unmask(event_fd, port);
 135.197 +        if (rc == -1) {
 135.198 +            PERROR("failed to write port to evtchn");
 135.199 +            exit(EXIT_FAILURE);
 135.200 +        }
 135.201 +    }
 135.202  }
 135.203  
 135.204  
 135.205 @@ -330,6 +354,9 @@ int monitor_tbufs(int outfd)
 135.206  
 135.207      unsigned long data_size;
 135.208  
 135.209 +    /* prepare to listen for VIRQ_TBUF */
 135.210 +    event_init();
 135.211 +
 135.212      /* get number of logical CPUs (and therefore number of trace buffers) */
 135.213      num = get_num_cpus();
 135.214  
 135.215 @@ -357,14 +384,23 @@ int monitor_tbufs(int outfd)
 135.216              /* Read window information only once. */
 135.217              cons = meta[i]->cons;
 135.218              prod = meta[i]->prod;
 135.219 -            rmb(); /* read prod, then read item. */
 135.220 -            
 135.221 +            xen_rmb(); /* read prod, then read item. */
 135.222 +
 135.223              if ( cons == prod )
 135.224                  continue;
 135.225             
 135.226 -            assert(prod > cons);
 135.227 +            assert(cons < 2*data_size);
 135.228 +            assert(prod < 2*data_size);
 135.229  
 135.230 -            window_size = prod - cons;
 135.231 +            // NB: if (prod<cons), then (prod-cons)%data_size will not yield
 135.232 +            // the correct answer because data_size is not a power of 2.
 135.233 +            if ( prod < cons )
 135.234 +                window_size = (prod + 2*data_size) - cons;
 135.235 +            else
 135.236 +                window_size = prod - cons;
 135.237 +            assert(window_size > 0);
 135.238 +            assert(window_size <= data_size);
 135.239 +
 135.240              start_offset = cons % data_size;
 135.241              end_offset = prod % data_size;
 135.242  
 135.243 @@ -392,11 +428,11 @@ int monitor_tbufs(int outfd)
 135.244                               outfd);
 135.245              }
 135.246  
 135.247 -            mb(); /* read buffer, then update cons. */
 135.248 +            xen_mb(); /* read buffer, then update cons. */
 135.249              meta[i]->cons = prod;
 135.250          }
 135.251  
 135.252 -        nanosleep(&opts.poll_sleep, NULL);
 135.253 +        wait_for_event_or_timeout(opts.poll_sleep);
 135.254      }
 135.255  
 135.256      /* cleanup */
 135.257 @@ -416,7 +452,7 @@ int monitor_tbufs(int outfd)
 135.258  #define xstr(x) str(x)
 135.259  #define str(x) #x
 135.260  
 135.261 -const char *program_version     = "xentrace v1.1";
 135.262 +const char *program_version     = "xentrace v1.2";
 135.263  const char *program_bug_address = "<mark.a.williamson@intel.com>";
 135.264  
 135.265  void usage(void)
 135.266 @@ -435,9 +471,6 @@ void usage(void)
 135.267  "                          N.B. that the trace buffer cannot be resized.\n" \
 135.268  "                          if it has already been set this boot cycle,\n" \
 135.269  "                          this argument will be ignored.\n" \
 135.270 -"  -t, --log-thresh=l      Set number, l, of new records required to\n" \
 135.271 -"                          trigger a write to output (default " \
 135.272 -                           xstr(NEW_DATA_THRESH) ").\n" \
 135.273  "  -?, --help              Show this message\n" \
 135.274  "  -V, --version           Print program version\n" \
 135.275  "\n" \
 135.276 @@ -516,12 +549,8 @@ void parse_args(int argc, char **argv)
 135.277      {
 135.278          switch ( option )
 135.279          {
 135.280 -        case 't': /* set new records threshold for logging */
 135.281 -            opts.new_data_thresh = argtol(optarg, 0);
 135.282 -            break;
 135.283 -
 135.284          case 's': /* set sleep time (given in milliseconds) */
 135.285 -            opts.poll_sleep = millis_to_timespec(argtol(optarg, 0));
 135.286 +            opts.poll_sleep = argtol(optarg, 0);
 135.287              break;
 135.288  
 135.289          case 'c': /* set new cpu mask for filtering*/
 135.290 @@ -565,13 +594,19 @@ int main(int argc, char **argv)
 135.291      struct sigaction act;
 135.292  
 135.293      opts.outfile = 0;
 135.294 -    opts.poll_sleep = millis_to_timespec(POLL_SLEEP_MILLIS);
 135.295 -    opts.new_data_thresh = NEW_DATA_THRESH;
 135.296 +    opts.poll_sleep = POLL_SLEEP_MILLIS;
 135.297      opts.evt_mask = 0;
 135.298      opts.cpu_mask = 0;
 135.299  
 135.300      parse_args(argc, argv);
 135.301 -    
 135.302 +
 135.303 +    xc_handle = xc_interface_open();
 135.304 +    if ( xc_handle < 0 ) 
 135.305 +    {
 135.306 +        perror(xc_get_last_error()->message);
 135.307 +        exit(EXIT_FAILURE);
 135.308 +    }
 135.309 +
 135.310      if ( opts.evt_mask != 0 )
 135.311          set_mask(opts.evt_mask, 0);
 135.312  
   136.1 --- a/unmodified_drivers/linux-2.6/platform-pci/Kbuild	Wed Feb 13 10:37:18 2008 -0700
   136.2 +++ b/unmodified_drivers/linux-2.6/platform-pci/Kbuild	Thu Feb 14 09:34:27 2008 -0700
   136.3 @@ -7,6 +7,7 @@ EXTRA_CFLAGS += -I$(M)/platform-pci
   136.4  xen-platform-pci-objs := evtchn.o platform-pci.o gnttab.o xen_support.o
   136.5  xen-platform-pci-objs += features.o platform-compat.o
   136.6  xen-platform-pci-objs += reboot.o machine_reboot.o
   136.7 +xen-platform-pci-objs += panic-handler.o
   136.8  
   136.9  xen-platform-pci-objs += ../xenbus/xenbus_comms.o
  136.10  xen-platform-pci-objs += ../xenbus/xenbus_xs.o
   137.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   137.2 +++ b/unmodified_drivers/linux-2.6/platform-pci/panic-handler.c	Thu Feb 14 09:34:27 2008 -0700
   137.3 @@ -0,0 +1,54 @@
   137.4 +#include <linux/module.h>
   137.5 +#include <linux/init.h>
   137.6 +#include <linux/notifier.h>
   137.7 +#include <asm/hypervisor.h>
   137.8 +
   137.9 +MODULE_LICENSE("GPL");
  137.10 +
  137.11 +#ifdef __ia64__
  137.12 +static void
  137.13 +xen_panic_hypercall(struct unw_frame_info *info, void *arg)
  137.14 +{
  137.15 +	current->thread.ksp = (__u64)info->sw - 16;
  137.16 +	HYPERVISOR_shutdown(SHUTDOWN_crash);
  137.17 +	/* we're never actually going to get here... */
  137.18 +}
  137.19 +#endif
  137.20 +
  137.21 +static int
  137.22 +xen_panic_event(struct notifier_block *this, unsigned long event, void *ptr)
  137.23 +{
  137.24 +#ifdef __ia64__
  137.25 +	unw_init_running(xen_panic_hypercall, NULL);
  137.26 +#else /* !__ia64__ */
  137.27 +	HYPERVISOR_shutdown(SHUTDOWN_crash);
  137.28 +#endif
  137.29 +	/* we're never actually going to get here... */
  137.30 +	return NOTIFY_DONE;
  137.31 +}
  137.32 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
  137.33 +static struct notifier_block xen_panic_block = {
  137.34 +	xen_panic_event, NULL, 0 /* try to go last */
  137.35 +};
  137.36 +#else
  137.37 +static struct notifier_block xen_panic_block = {
  137.38 +	.notifier_call= xen_panic_event,
  137.39 +	.next= NULL,
  137.40 +	.priority= 0/* try to go last */
  137.41 +};
  137.42 +#endif /*LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)*/
  137.43 +
  137.44 +static int __init setup_panic_event(void)
  137.45 +{
  137.46 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
  137.47 +	notifier_chain_register(&panic_notifier_list, &xen_panic_block);
  137.48 +#else
  137.49 +	atomic_notifier_chain_register(&panic_notifier_list, &xen_panic_block);
  137.50 +#endif /*LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)*/
  137.51 +	return 0;
  137.52 +}
  137.53 +
  137.54 +int xen_panic_handler_init(void)
  137.55 +{
  137.56 +	return setup_panic_event();
  137.57 +}
   138.1 --- a/unmodified_drivers/linux-2.6/platform-pci/platform-pci.c	Wed Feb 13 10:37:18 2008 -0700
   138.2 +++ b/unmodified_drivers/linux-2.6/platform-pci/platform-pci.c	Thu Feb 14 09:34:27 2008 -0700
   138.3 @@ -249,6 +249,7 @@ static int set_callback_via(uint64_t via
   138.4  int xen_irq_init(struct pci_dev *pdev);
   138.5  int xenbus_init(void);
   138.6  int xen_reboot_init(void);
   138.7 +int xen_panic_handler_init(void);
   138.8  int gnttab_init(void);
   138.9  
  138.10  static int __devinit platform_pci_init(struct pci_dev *pdev,
  138.11 @@ -317,6 +318,9 @@ static int __devinit platform_pci_init(s
  138.12  	if ((ret = xen_reboot_init()))
  138.13  		goto out;
  138.14  
  138.15 +	if ((ret = xen_panic_handler_init()))
  138.16 +		goto out;
  138.17 +
  138.18   out:
  138.19  	if (ret) {
  138.20  		release_mem_region(mmio_addr, mmio_len);
   139.1 --- a/xen/arch/x86/boot/trampoline.S	Wed Feb 13 10:37:18 2008 -0700
   139.2 +++ b/xen/arch/x86/boot/trampoline.S	Thu Feb 14 09:34:27 2008 -0700
   139.3 @@ -155,6 +155,13 @@ 1:      mov     $(BOOT_TRAMPOLINE>>4),%a
   139.4          lidt    bootsym(rm_idt)
   139.5          sti
   139.6  
   139.7 +#if defined(__x86_64__)
   139.8 +        /* Declare that our target operating mode is long mode. */
   139.9 +        movw    $0xec00,%ax      # declare target operating mode
  139.10 +        movw    $0x0002,%bx      # long mode
  139.11 +        int     $0x15
  139.12 +#endif
  139.13 +
  139.14          /*
  139.15           * Do real-mode work:
  139.16           *  1. Get memory map.
   140.1 --- a/xen/arch/x86/cpu/mtrr/main.c	Wed Feb 13 10:37:18 2008 -0700
   140.2 +++ b/xen/arch/x86/cpu/mtrr/main.c	Thu Feb 14 09:34:27 2008 -0700
   140.3 @@ -46,8 +46,6 @@
   140.4  #define DEFINE_MUTEX(_m) DEFINE_SPINLOCK(_m)
   140.5  #define mutex_lock(_m) spin_lock(_m)
   140.6  #define mutex_unlock(_m) spin_unlock(_m)
   140.7 -#define lock_cpu_hotplug() ((void)0)
   140.8 -#define unlock_cpu_hotplug() ((void)0)
   140.9  #define dump_stack() ((void)0)
  140.10  #define	get_cpu()	smp_processor_id()
  140.11  #define put_cpu()	do {} while(0)
   141.1 --- a/xen/arch/x86/domain.c	Wed Feb 13 10:37:18 2008 -0700
   141.2 +++ b/xen/arch/x86/domain.c	Thu Feb 14 09:34:27 2008 -0700
   141.3 @@ -82,7 +82,6 @@ static void default_idle(void)
   141.4  
   141.5  static void play_dead(void)
   141.6  {
   141.7 -    __cpu_disable();
   141.8      /* This must be done before dead CPU ack */
   141.9      cpu_exit_clear();
  141.10      hvm_cpu_down();
  141.11 @@ -101,7 +100,7 @@ void idle_loop(void)
  141.12  {
  141.13      for ( ; ; )
  141.14      {
  141.15 -        if (cpu_is_offline(smp_processor_id()))
  141.16 +        if ( cpu_is_offline(smp_processor_id()) )
  141.17              play_dead();
  141.18          page_scrub_schedule_work();
  141.19          default_idle();
   142.1 --- a/xen/arch/x86/domctl.c	Wed Feb 13 10:37:18 2008 -0700
   142.2 +++ b/xen/arch/x86/domctl.c	Thu Feb 14 09:34:27 2008 -0700
   142.3 @@ -530,7 +530,7 @@ long arch_do_domctl(
   142.4          u8 bus, devfn;
   142.5  
   142.6          ret = -EINVAL;
   142.7 -        if ( !vtd_enabled )
   142.8 +        if ( !iommu_enabled )
   142.9              break;
  142.10  
  142.11          bus = (domctl->u.assign_device.machine_bdf >> 16) & 0xff;
  142.12 @@ -553,7 +553,7 @@ long arch_do_domctl(
  142.13          u8 bus, devfn;
  142.14  
  142.15          ret = -EINVAL;
  142.16 -        if ( !vtd_enabled )
  142.17 +        if ( !iommu_enabled )
  142.18              break;
  142.19  
  142.20          if ( unlikely((d = get_domain_by_id(domctl->domain)) == NULL) )
  142.21 @@ -589,9 +589,9 @@ long arch_do_domctl(
  142.22          if ( (d = rcu_lock_domain_by_id(domctl->domain)) == NULL )
  142.23              break;
  142.24          bind = &(domctl->u.bind_pt_irq);
  142.25 -        if (vtd_enabled)
  142.26 +        if ( iommu_enabled )
  142.27              ret = pt_irq_create_bind_vtd(d, bind);
  142.28 -        if (ret < 0)
  142.29 +        if ( ret < 0 )
  142.30              gdprintk(XENLOG_ERR, "pt_irq_create_bind failed!\n");
  142.31          rcu_unlock_domain(d);
  142.32      }
   143.1 --- a/xen/arch/x86/hvm/Makefile	Wed Feb 13 10:37:18 2008 -0700
   143.2 +++ b/xen/arch/x86/hvm/Makefile	Thu Feb 14 09:34:27 2008 -0700
   143.3 @@ -6,6 +6,7 @@ obj-y += i8254.o
   143.4  obj-y += instrlen.o
   143.5  obj-y += intercept.o
   143.6  obj-y += io.o
   143.7 +obj-y += iommu.o
   143.8  obj-y += irq.o
   143.9  obj-y += mtrr.o
  143.10  obj-y += platform.o
   144.1 --- a/xen/arch/x86/hvm/hpet.c	Wed Feb 13 10:37:18 2008 -0700
   144.2 +++ b/xen/arch/x86/hvm/hpet.c	Thu Feb 14 09:34:27 2008 -0700
   144.3 @@ -353,7 +353,8 @@ static void hpet_write(
   144.4  
   144.5  static int hpet_range(struct vcpu *v, unsigned long addr)
   144.6  {
   144.7 -    return ((addr >= HPET_BASE_ADDRESS) &&
   144.8 +    return (v->domain->arch.hvm_domain.params[HVM_PARAM_HPET_ENABLED] &&
   144.9 +            (addr >= HPET_BASE_ADDRESS) &&
  144.10              (addr < (HPET_BASE_ADDRESS + HPET_MMAP_SIZE)));
  144.11  }
  144.12  
   145.1 --- a/xen/arch/x86/hvm/hvm.c	Wed Feb 13 10:37:18 2008 -0700
   145.2 +++ b/xen/arch/x86/hvm/hvm.c	Thu Feb 14 09:34:27 2008 -0700
   145.3 @@ -232,6 +232,8 @@ int hvm_domain_initialise(struct domain 
   145.4      spin_lock_init(&d->arch.hvm_domain.irq_lock);
   145.5      spin_lock_init(&d->arch.hvm_domain.uc_lock);
   145.6  
   145.7 +    d->arch.hvm_domain.params[HVM_PARAM_HPET_ENABLED] = 1;
   145.8 +
   145.9      hvm_init_cacheattr_region_list(d);
  145.10  
  145.11      rc = paging_enable(d, PG_refcounts|PG_translate|PG_external);
  145.12 @@ -285,9 +287,10 @@ static int hvm_save_cpu_ctxt(struct doma
  145.13  {
  145.14      struct vcpu *v;
  145.15      struct hvm_hw_cpu ctxt;
  145.16 +    struct segment_register seg;
  145.17      struct vcpu_guest_context *vc;
  145.18  
  145.19 -    for_each_vcpu(d, v)
  145.20 +    for_each_vcpu ( d, v )
  145.21      {
  145.22          /* We don't need to save state for a vcpu that is down; the restore 
  145.23           * code will leave it down if there is nothing saved. */
  145.24 @@ -297,12 +300,69 @@ static int hvm_save_cpu_ctxt(struct doma
  145.25          /* Architecture-specific vmcs/vmcb bits */
  145.26          hvm_funcs.save_cpu_ctxt(v, &ctxt);
  145.27  
  145.28 -        /* Other vcpu register state */
  145.29 +        hvm_get_segment_register(v, x86_seg_idtr, &seg);
  145.30 +        ctxt.idtr_limit = seg.limit;
  145.31 +        ctxt.idtr_base = seg.base;
  145.32 +
  145.33 +        hvm_get_segment_register(v, x86_seg_gdtr, &seg);
  145.34 +        ctxt.gdtr_limit = seg.limit;
  145.35 +        ctxt.gdtr_base = seg.base;
  145.36 +
  145.37 +        hvm_get_segment_register(v, x86_seg_cs, &seg);
  145.38 +        ctxt.cs_sel = seg.sel;
  145.39 +        ctxt.cs_limit = seg.limit;
  145.40 +        ctxt.cs_base = seg.base;
  145.41 +        ctxt.cs_arbytes = seg.attr.bytes;
  145.42 +
  145.43 +        hvm_get_segment_register(v, x86_seg_ds, &seg);
  145.44 +        ctxt.ds_sel = seg.sel;
  145.45 +        ctxt.ds_limit = seg.limit;
  145.46 +        ctxt.ds_base = seg.base;
  145.47 +        ctxt.ds_arbytes = seg.attr.bytes;
  145.48 +
  145.49 +        hvm_get_segment_register(v, x86_seg_es, &seg);
  145.50 +        ctxt.es_sel = seg.sel;
  145.51 +        ctxt.es_limit = seg.limit;
  145.52 +        ctxt.es_base = seg.base;
  145.53 +        ctxt.es_arbytes = seg.attr.bytes;
  145.54 +
  145.55 +        hvm_get_segment_register(v, x86_seg_ss, &seg);
  145.56 +        ctxt.ss_sel = seg.sel;
  145.57 +        ctxt.ss_limit = seg.limit;
  145.58 +        ctxt.ss_base = seg.base;
  145.59 +        ctxt.ss_arbytes = seg.attr.bytes;
  145.60 +
  145.61 +        hvm_get_segment_register(v, x86_seg_fs, &seg);
  145.62 +        ctxt.fs_sel = seg.sel;
  145.63 +        ctxt.fs_limit = seg.limit;
  145.64 +        ctxt.fs_base = seg.base;
  145.65 +        ctxt.fs_arbytes = seg.attr.bytes;
  145.66 +
  145.67 +        hvm_get_segment_register(v, x86_seg_gs, &seg);
  145.68 +        ctxt.gs_sel = seg.sel;
  145.69 +        ctxt.gs_limit = seg.limit;
  145.70 +        ctxt.gs_base = seg.base;
  145.71 +        ctxt.gs_arbytes = seg.attr.bytes;
  145.72 +
  145.73 +        hvm_get_segment_register(v, x86_seg_tr, &seg);
  145.74 +        ctxt.tr_sel = seg.sel;
  145.75 +        ctxt.tr_limit = seg.limit;
  145.76 +        ctxt.tr_base = seg.base;
  145.77 +        ctxt.tr_arbytes = seg.attr.bytes;
  145.78 +
  145.79 +        hvm_get_segment_register(v, x86_seg_ldtr, &seg);
  145.80 +        ctxt.ldtr_sel = seg.sel;
  145.81 +        ctxt.ldtr_limit = seg.limit;
  145.82 +        ctxt.ldtr_base = seg.base;
  145.83 +        ctxt.ldtr_arbytes = seg.attr.bytes;
  145.84 +
  145.85          vc = &v->arch.guest_context;
  145.86 +
  145.87          if ( v->fpu_initialised )
  145.88              memcpy(ctxt.fpu_regs, &vc->fpu_ctxt, sizeof(ctxt.fpu_regs));
  145.89          else 
  145.90              memset(ctxt.fpu_regs, 0, sizeof(ctxt.fpu_regs));
  145.91 +
  145.92          ctxt.rax = vc->user_regs.eax;
  145.93          ctxt.rbx = vc->user_regs.ebx;
  145.94          ctxt.rcx = vc->user_regs.ecx;
  145.95 @@ -341,6 +401,7 @@ static int hvm_load_cpu_ctxt(struct doma
  145.96      int vcpuid, rc;
  145.97      struct vcpu *v;
  145.98      struct hvm_hw_cpu ctxt;
  145.99 +    struct segment_register seg;
 145.100      struct vcpu_guest_context *vc;
 145.101  
 145.102      /* Which vcpu is this? */
 145.103 @@ -396,8 +457,64 @@ static int hvm_load_cpu_ctxt(struct doma
 145.104      if ( hvm_funcs.load_cpu_ctxt(v, &ctxt) < 0 )
 145.105          return -EINVAL;
 145.106  
 145.107 -    /* Other vcpu register state */
 145.108 +    seg.limit = ctxt.idtr_limit;
 145.109 +    seg.base = ctxt.idtr_base;
 145.110 +    hvm_set_segment_register(v, x86_seg_idtr, &seg);
 145.111 +
 145.112 +    seg.limit = ctxt.gdtr_limit;
 145.113 +    seg.base = ctxt.gdtr_base;
 145.114 +    hvm_set_segment_register(v, x86_seg_gdtr, &seg);
 145.115 +
 145.116 +    seg.sel = ctxt.cs_sel;
 145.117 +    seg.limit = ctxt.cs_limit;
 145.118 +    seg.base = ctxt.cs_base;
 145.119 +    seg.attr.bytes = ctxt.cs_arbytes;
 145.120 +    hvm_set_segment_register(v, x86_seg_cs, &seg);
 145.121 +
 145.122 +    seg.sel = ctxt.ds_sel;
 145.123 +    seg.limit = ctxt.ds_limit;
 145.124 +    seg.base = ctxt.ds_base;
 145.125 +    seg.attr.bytes = ctxt.ds_arbytes;
 145.126 +    hvm_set_segment_register(v, x86_seg_ds, &seg);
 145.127 +
 145.128 +    seg.sel = ctxt.es_sel;
 145.129 +    seg.limit = ctxt.es_limit;
 145.130 +    seg.base = ctxt.es_base;
 145.131 +    seg.attr.bytes = ctxt.es_arbytes;
 145.132 +    hvm_set_segment_register(v, x86_seg_es, &seg);
 145.133 +
 145.134 +    seg.sel = ctxt.ss_sel;
 145.135 +    seg.limit = ctxt.ss_limit;
 145.136 +    seg.base = ctxt.ss_base;
 145.137 +    seg.attr.bytes = ctxt.ss_arbytes;
 145.138 +    hvm_set_segment_register(v, x86_seg_ss, &seg);
 145.139 +
 145.140 +    seg.sel = ctxt.fs_sel;
 145.141 +    seg.limit = ctxt.fs_limit;
 145.142 +    seg.base = ctxt.fs_base;
 145.143 +    seg.attr.bytes = ctxt.fs_arbytes;
 145.144 +    hvm_set_segment_register(v, x86_seg_fs, &seg);
 145.145 +
 145.146 +    seg.sel = ctxt.gs_sel;
 145.147 +    seg.limit = ctxt.gs_limit;
 145.148 +    seg.base = ctxt.gs_base;
 145.149 +    seg.attr.bytes = ctxt.gs_arbytes;
 145.150 +    hvm_set_segment_register(v, x86_seg_gs, &seg);
 145.151 +
 145.152 +    seg.sel = ctxt.tr_sel;
 145.153 +    seg.limit = ctxt.tr_limit;
 145.154 +    seg.base = ctxt.tr_base;
 145.155 +    seg.attr.bytes = ctxt.tr_arbytes;
 145.156 +    hvm_set_segment_register(v, x86_seg_tr, &seg);
 145.157 +
 145.158 +    seg.sel = ctxt.ldtr_sel;
 145.159 +    seg.limit = ctxt.ldtr_limit;
 145.160 +    seg.base = ctxt.ldtr_base;
 145.161 +    seg.attr.bytes = ctxt.ldtr_arbytes;
 145.162 +    hvm_set_segment_register(v, x86_seg_ldtr, &seg);
 145.163 +
 145.164      memcpy(&vc->fpu_ctxt, ctxt.fpu_regs, sizeof(ctxt.fpu_regs));
 145.165 +
 145.166      vc->user_regs.eax = ctxt.rax;
 145.167      vc->user_regs.ebx = ctxt.rbx;
 145.168      vc->user_regs.ecx = ctxt.rcx;
 145.169 @@ -1269,6 +1386,7 @@ void hvm_task_switch(
 145.170  static enum hvm_copy_result __hvm_copy(
 145.171      void *buf, paddr_t addr, int size, int dir, int virt, int fetch)
 145.172  {
 145.173 +    struct vcpu *curr = current;
 145.174      unsigned long gfn, mfn;
 145.175      p2m_type_t p2mt;
 145.176      char *p;
 145.177 @@ -1277,12 +1395,22 @@ static enum hvm_copy_result __hvm_copy(
 145.178  
 145.179      if ( virt )
 145.180      {
 145.181 -        struct segment_register sreg;
 145.182 -        hvm_get_segment_register(current, x86_seg_ss, &sreg);
 145.183 -        if ( sreg.attr.fields.dpl == 3 )
 145.184 -            pfec |= PFEC_user_mode;
 145.185 +        /*
 145.186 +         * We cannot use hvm_get_segment_register() while executing in
 145.187 +         * vmx_realmode() as segment register state is cached. Furthermore,
 145.188 +         * VMREADs on every data access hurts emulation performance.
 145.189 +         */
 145.190 +        if ( !curr->arch.hvm_vmx.vmxemul )
 145.191 +        {
 145.192 +            struct segment_register sreg;
 145.193 +            hvm_get_segment_register(curr, x86_seg_ss, &sreg);
 145.194 +            if ( sreg.attr.fields.dpl == 3 )
 145.195 +                pfec |= PFEC_user_mode;
 145.196 +        }
 145.197 +
 145.198          if ( dir ) 
 145.199              pfec |= PFEC_write_access;
 145.200 +
 145.201          if ( fetch ) 
 145.202              pfec |= PFEC_insn_fetch;
 145.203      }
 145.204 @@ -1294,7 +1422,7 @@ static enum hvm_copy_result __hvm_copy(
 145.205  
 145.206          if ( virt )
 145.207          {
 145.208 -            gfn = paging_gva_to_gfn(current, addr, &pfec);
 145.209 +            gfn = paging_gva_to_gfn(curr, addr, &pfec);
 145.210              if ( gfn == INVALID_GFN )
 145.211              {
 145.212                  if ( virt == 2 ) /* 2 means generate a fault */
 145.213 @@ -1318,7 +1446,7 @@ static enum hvm_copy_result __hvm_copy(
 145.214          if ( dir )
 145.215          {
 145.216              memcpy(p, buf, count); /* dir == TRUE:  *to* guest */
 145.217 -            paging_mark_dirty(current->domain, mfn);
 145.218 +            paging_mark_dirty(curr->domain, mfn);
 145.219          }
 145.220          else
 145.221              memcpy(buf, p, count); /* dir == FALSE: *from guest */
   146.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   146.2 +++ b/xen/arch/x86/hvm/iommu.c	Thu Feb 14 09:34:27 2008 -0700
   146.3 @@ -0,0 +1,135 @@
   146.4 +/*
   146.5 + * This program is free software; you can redistribute it and/or modify it
   146.6 + * under the terms and conditions of the GNU General Public License,
   146.7 + * version 2, as published by the Free Software Foundation.
   146.8 + *
   146.9 + * This program is distributed in the hope it will be useful, but WITHOUT
  146.10 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  146.11 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  146.12 + * more details.
  146.13 + *
  146.14 + * You should have received a copy of the GNU General Public License along with
  146.15 + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  146.16 + * Place - Suite 330, Boston, MA 02111-1307 USA.
  146.17 + */
  146.18 +
  146.19 +#include <xen/init.h>
  146.20 +#include <xen/irq.h>
  146.21 +#include <xen/spinlock.h>
  146.22 +#include <xen/sched.h>
  146.23 +#include <xen/xmalloc.h>
  146.24 +#include <xen/domain_page.h>
  146.25 +#include <asm/delay.h>
  146.26 +#include <asm/string.h>
  146.27 +#include <asm/mm.h>
  146.28 +#include <asm/iommu.h>
  146.29 +#include <asm/hvm/vmx/intel-iommu.h>
  146.30 +
  146.31 +extern struct iommu_ops intel_iommu_ops;
  146.32 +extern struct iommu_ops amd_iommu_ops;
  146.33 +
  146.34 +int iommu_domain_init(struct domain *domain)
  146.35 +{
  146.36 +    struct hvm_iommu *hd = domain_hvm_iommu(domain);
  146.37 +
  146.38 +    spin_lock_init(&hd->mapping_lock);
  146.39 +    spin_lock_init(&hd->iommu_list_lock);
  146.40 +    INIT_LIST_HEAD(&hd->pdev_list);
  146.41 +    INIT_LIST_HEAD(&hd->g2m_ioport_list);
  146.42 +
  146.43 +    if ( !iommu_enabled )
  146.44 +        return 0;
  146.45 +
  146.46 +    switch ( boot_cpu_data.x86_vendor )
  146.47 +    {
  146.48 +    case X86_VENDOR_INTEL:
  146.49 +        hd->platform_ops = &intel_iommu_ops;
  146.50 +        break;
  146.51 +    case X86_VENDOR_AMD:
  146.52 +        hd->platform_ops = &amd_iommu_ops;
  146.53 +        break;
  146.54 +    default:
  146.55 +        BUG();
  146.56 +    }
  146.57 +
  146.58 +    return hd->platform_ops->init(domain);
  146.59 +}
  146.60 +
  146.61 +int assign_device(struct domain *d, u8 bus, u8 devfn)
  146.62 +{
  146.63 +    struct hvm_iommu *hd = domain_hvm_iommu(d);
  146.64 +
  146.65 +    if ( !iommu_enabled || !hd->platform_ops)
  146.66 +        return 0;
  146.67 +
  146.68 +    return hd->platform_ops->assign_device(d, bus, devfn);
  146.69 +}
  146.70 +
  146.71 +void iommu_domain_destroy(struct domain *d)
  146.72 +{
  146.73 +    struct hvm_irq_dpci *hvm_irq_dpci = d->arch.hvm_domain.irq.dpci;
  146.74 +    uint32_t i;
  146.75 +    struct hvm_iommu *hd  = domain_hvm_iommu(d);
  146.76 +    struct list_head *ioport_list, *digl_list, *tmp;
  146.77 +    struct g2m_ioport *ioport;
  146.78 +    struct dev_intx_gsi_link *digl;
  146.79 +
  146.80 +    if ( !iommu_enabled || !hd->platform_ops)
  146.81 +        return;
  146.82 +
  146.83 +    if ( hvm_irq_dpci != NULL )
  146.84 +    {
  146.85 +        for ( i = 0; i < NR_IRQS; i++ )
  146.86 +        {
  146.87 +            if ( !hvm_irq_dpci->mirq[i].valid )
  146.88 +                continue;
  146.89 +
  146.90 +            pirq_guest_unbind(d, i);
  146.91 +            kill_timer(&hvm_irq_dpci->hvm_timer[irq_to_vector(i)]);
  146.92 +
  146.93 +            list_for_each_safe ( digl_list, tmp,
  146.94 +                                 &hvm_irq_dpci->mirq[i].digl_list )
  146.95 +            {
  146.96 +                digl = list_entry(digl_list,
  146.97 +                                  struct dev_intx_gsi_link, list);
  146.98 +                list_del(&digl->list);
  146.99 +                xfree(digl);
 146.100 +            }
 146.101 +        }
 146.102 +
 146.103 +        d->arch.hvm_domain.irq.dpci = NULL;
 146.104 +        xfree(hvm_irq_dpci);
 146.105 +    }
 146.106 +
 146.107 +    if ( hd )
 146.108 +    {
 146.109 +        list_for_each_safe ( ioport_list, tmp, &hd->g2m_ioport_list )
 146.110 +        {
 146.111 +            ioport = list_entry(ioport_list, struct g2m_ioport, list);
 146.112 +            list_del(&ioport->list);
 146.113 +            xfree(ioport);
 146.114 +        }
 146.115 +    }
 146.116 +
 146.117 +    return hd->platform_ops->teardown(d);
 146.118 +}
 146.119 +
 146.120 +int iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn)
 146.121 +{
 146.122 +    struct hvm_iommu *hd = domain_hvm_iommu(d);
 146.123 +
 146.124 +    if ( !iommu_enabled || !hd->platform_ops)
 146.125 +        return 0;
 146.126 +
 146.127 +    return hd->platform_ops->map_page(d, gfn, mfn);
 146.128 +}
 146.129 +
 146.130 +int iommu_unmap_page(struct domain *d, unsigned long gfn)
 146.131 +{
 146.132 +    struct hvm_iommu *hd = domain_hvm_iommu(d);
 146.133 +
 146.134 +    if ( !iommu_enabled || !hd->platform_ops)
 146.135 +        return 0;
 146.136 +
 146.137 +    return hd->platform_ops->unmap_page(d, gfn);
 146.138 +}
   147.1 --- a/xen/arch/x86/hvm/svm/amd_iommu/amd-iommu-detect.c	Wed Feb 13 10:37:18 2008 -0700
   147.2 +++ b/xen/arch/x86/hvm/svm/amd_iommu/amd-iommu-detect.c	Thu Feb 14 09:34:27 2008 -0700
   147.3 @@ -89,12 +89,14 @@ int __init get_iommu_capabilities(u8 bus
   147.4      u32 cap_header, cap_range;
   147.5      u64 mmio_bar;
   147.6  
   147.7 +#if HACK_BIOS_SETTINGS
   147.8      /* remove it when BIOS available */
   147.9      write_pci_config(bus, dev, func,
  147.10          cap_ptr + PCI_CAP_MMIO_BAR_HIGH_OFFSET, 0x00000000);
  147.11      write_pci_config(bus, dev, func,
  147.12          cap_ptr + PCI_CAP_MMIO_BAR_LOW_OFFSET, 0x40000001);
  147.13      /* remove it when BIOS available */
  147.14 +#endif
  147.15  
  147.16      mmio_bar = (u64)read_pci_config(bus, dev, func,
  147.17               cap_ptr + PCI_CAP_MMIO_BAR_HIGH_OFFSET) << 32;
   148.1 --- a/xen/arch/x86/hvm/svm/amd_iommu/amd-iommu-map.c	Wed Feb 13 10:37:18 2008 -0700
   148.2 +++ b/xen/arch/x86/hvm/svm/amd_iommu/amd-iommu-map.c	Thu Feb 14 09:34:27 2008 -0700
   148.3 @@ -30,22 +30,20 @@ static int queue_iommu_command(struct am
   148.4      u32 tail, head, *cmd_buffer;
   148.5      int i;
   148.6  
   148.7 -    BUG_ON( !iommu || !cmd );
   148.8 -
   148.9      tail = iommu->cmd_buffer_tail;
  148.10 -    if ( ++tail == iommu->cmd_buffer.entries ) {
  148.11 +    if ( ++tail == iommu->cmd_buffer.entries )
  148.12          tail = 0;
  148.13 -    }
  148.14      head = get_field_from_reg_u32(
  148.15 -            readl(iommu->mmio_base+IOMMU_CMD_BUFFER_HEAD_OFFSET),
  148.16 -            IOMMU_CMD_BUFFER_HEAD_MASK,
  148.17 -            IOMMU_CMD_BUFFER_HEAD_SHIFT);
  148.18 -    if ( head != tail ) {
  148.19 +        readl(iommu->mmio_base+IOMMU_CMD_BUFFER_HEAD_OFFSET),
  148.20 +        IOMMU_CMD_BUFFER_HEAD_MASK,
  148.21 +        IOMMU_CMD_BUFFER_HEAD_SHIFT);
  148.22 +    if ( head != tail )
  148.23 +    {
  148.24          cmd_buffer = (u32 *)(iommu->cmd_buffer.buffer +
  148.25 -            (iommu->cmd_buffer_tail * IOMMU_CMD_BUFFER_ENTRY_SIZE));
  148.26 -        for ( i = 0; i < IOMMU_CMD_BUFFER_U32_PER_ENTRY; ++i ) {
  148.27 +                             (iommu->cmd_buffer_tail *
  148.28 +                              IOMMU_CMD_BUFFER_ENTRY_SIZE));
  148.29 +        for ( i = 0; i < IOMMU_CMD_BUFFER_U32_PER_ENTRY; i++ )
  148.30              cmd_buffer[i] = cmd[i];
  148.31 -        }
  148.32  
  148.33          iommu->cmd_buffer_tail = tail;
  148.34          return 1;
  148.35 @@ -58,27 +56,25 @@ static void commit_iommu_command_buffer(
  148.36  {
  148.37      u32 tail;
  148.38  
  148.39 -    BUG_ON( !iommu );
  148.40 -
  148.41      set_field_in_reg_u32(iommu->cmd_buffer_tail, 0,
  148.42 -        IOMMU_CMD_BUFFER_TAIL_MASK,
  148.43 -        IOMMU_CMD_BUFFER_TAIL_SHIFT, &tail);
  148.44 +                         IOMMU_CMD_BUFFER_TAIL_MASK,
  148.45 +                         IOMMU_CMD_BUFFER_TAIL_SHIFT, &tail);
  148.46      writel(tail, iommu->mmio_base+IOMMU_CMD_BUFFER_TAIL_OFFSET);
  148.47  }
  148.48  
  148.49  int send_iommu_command(struct amd_iommu *iommu, u32 cmd[])
  148.50  {
  148.51 -    BUG_ON( !iommu || !cmd );
  148.52 -
  148.53 -    if ( queue_iommu_command(iommu, cmd) ) {
  148.54 +    if ( queue_iommu_command(iommu, cmd) )
  148.55 +    {
  148.56          commit_iommu_command_buffer(iommu);
  148.57          return 1;
  148.58      }
  148.59 +
  148.60      return 0;
  148.61  }
  148.62  
  148.63  static void invalidate_iommu_page(struct amd_iommu *iommu,
  148.64 -            u64 io_addr, u16 domain_id)
  148.65 +                                  u64 io_addr, u16 domain_id)
  148.66  {
  148.67      u64 addr_lo, addr_hi;
  148.68      u32 cmd[4], entry;
  148.69 @@ -87,51 +83,52 @@ static void invalidate_iommu_page(struct
  148.70      addr_hi = io_addr >> 32;
  148.71  
  148.72      set_field_in_reg_u32(domain_id, 0,
  148.73 -        IOMMU_INV_IOMMU_PAGES_DOMAIN_ID_MASK,
  148.74 -        IOMMU_INV_IOMMU_PAGES_DOMAIN_ID_SHIFT, &entry);
  148.75 +                         IOMMU_INV_IOMMU_PAGES_DOMAIN_ID_MASK,
  148.76 +                         IOMMU_INV_IOMMU_PAGES_DOMAIN_ID_SHIFT, &entry);
  148.77      set_field_in_reg_u32(IOMMU_CMD_INVALIDATE_IOMMU_PAGES, entry,
  148.78 -        IOMMU_CMD_OPCODE_MASK, IOMMU_CMD_OPCODE_SHIFT, &entry);
  148.79 +                         IOMMU_CMD_OPCODE_MASK, IOMMU_CMD_OPCODE_SHIFT,
  148.80 +                         &entry);
  148.81      cmd[1] = entry;
  148.82  
  148.83      set_field_in_reg_u32(IOMMU_CONTROL_DISABLED, 0,
  148.84 -        IOMMU_INV_IOMMU_PAGES_S_FLAG_MASK,
  148.85 -        IOMMU_INV_IOMMU_PAGES_S_FLAG_SHIFT, &entry);
  148.86 +                         IOMMU_INV_IOMMU_PAGES_S_FLAG_MASK,
  148.87 +                         IOMMU_INV_IOMMU_PAGES_S_FLAG_SHIFT, &entry);
  148.88      set_field_in_reg_u32(IOMMU_CONTROL_DISABLED, entry,
  148.89 -        IOMMU_INV_IOMMU_PAGES_PDE_FLAG_MASK,
  148.90 -        IOMMU_INV_IOMMU_PAGES_PDE_FLAG_SHIFT, &entry);
  148.91 +                         IOMMU_INV_IOMMU_PAGES_PDE_FLAG_MASK,
  148.92 +                         IOMMU_INV_IOMMU_PAGES_PDE_FLAG_SHIFT, &entry);
  148.93      set_field_in_reg_u32((u32)addr_lo >> PAGE_SHIFT, entry,
  148.94 -        IOMMU_INV_IOMMU_PAGES_ADDR_LOW_MASK,
  148.95 -        IOMMU_INV_IOMMU_PAGES_ADDR_LOW_SHIFT, &entry);
  148.96 +                         IOMMU_INV_IOMMU_PAGES_ADDR_LOW_MASK,
  148.97 +                         IOMMU_INV_IOMMU_PAGES_ADDR_LOW_SHIFT, &entry);
  148.98      cmd[2] = entry;
  148.99  
 148.100      set_field_in_reg_u32((u32)addr_hi, 0,
 148.101 -        IOMMU_INV_IOMMU_PAGES_ADDR_HIGH_MASK,
 148.102 -        IOMMU_INV_IOMMU_PAGES_ADDR_HIGH_SHIFT, &entry);
 148.103 +                         IOMMU_INV_IOMMU_PAGES_ADDR_HIGH_MASK,
 148.104 +                         IOMMU_INV_IOMMU_PAGES_ADDR_HIGH_SHIFT, &entry);
 148.105      cmd[3] = entry;
 148.106  
 148.107      cmd[0] = 0;
 148.108      send_iommu_command(iommu, cmd);
 148.109  }
 148.110  
 148.111 -static void flush_command_buffer(struct amd_iommu *iommu)
 148.112 +void flush_command_buffer(struct amd_iommu *iommu)
 148.113  {
 148.114      u32 cmd[4], status;
 148.115      int loop_count, comp_wait;
 148.116  
 148.117      /* clear 'ComWaitInt' in status register (WIC) */
 148.118      set_field_in_reg_u32(IOMMU_CONTROL_ENABLED, 0,
 148.119 -        IOMMU_STATUS_COMP_WAIT_INT_MASK,
 148.120 -        IOMMU_STATUS_COMP_WAIT_INT_SHIFT, &status);
 148.121 +                         IOMMU_STATUS_COMP_WAIT_INT_MASK,
 148.122 +                         IOMMU_STATUS_COMP_WAIT_INT_SHIFT, &status);
 148.123      writel(status, iommu->mmio_base + IOMMU_STATUS_MMIO_OFFSET);
 148.124  
 148.125      /* send an empty COMPLETION_WAIT command to flush command buffer */
 148.126      cmd[3] = cmd[2] = 0;
 148.127      set_field_in_reg_u32(IOMMU_CMD_COMPLETION_WAIT, 0,
 148.128 -        IOMMU_CMD_OPCODE_MASK,
 148.129 -        IOMMU_CMD_OPCODE_SHIFT, &cmd[1]);
 148.130 +                         IOMMU_CMD_OPCODE_MASK,
 148.131 +                         IOMMU_CMD_OPCODE_SHIFT, &cmd[1]);
 148.132      set_field_in_reg_u32(IOMMU_CONTROL_ENABLED, 0,
 148.133 -        IOMMU_COMP_WAIT_I_FLAG_MASK,
 148.134 -        IOMMU_COMP_WAIT_I_FLAG_SHIFT, &cmd[0]);
 148.135 +                         IOMMU_COMP_WAIT_I_FLAG_MASK,
 148.136 +                         IOMMU_COMP_WAIT_I_FLAG_SHIFT, &cmd[0]);
 148.137      send_iommu_command(iommu, cmd);
 148.138  
 148.139      /* wait for 'ComWaitInt' to signal comp#endifletion? */
 148.140 @@ -139,34 +136,36 @@ static void flush_command_buffer(struct 
 148.141          loop_count = amd_iommu_poll_comp_wait;
 148.142          do {
 148.143              status = readl(iommu->mmio_base +
 148.144 -                    IOMMU_STATUS_MMIO_OFFSET);
 148.145 -            comp_wait = get_field_from_reg_u32(status,
 148.146 -                    IOMMU_STATUS_COMP_WAIT_INT_MASK,
 148.147 -                    IOMMU_STATUS_COMP_WAIT_INT_SHIFT);
 148.148 +                           IOMMU_STATUS_MMIO_OFFSET);
 148.149 +            comp_wait = get_field_from_reg_u32(
 148.150 +                status,
 148.151 +                IOMMU_STATUS_COMP_WAIT_INT_MASK,
 148.152 +                IOMMU_STATUS_COMP_WAIT_INT_SHIFT);
 148.153              --loop_count;
 148.154          } while ( loop_count && !comp_wait );
 148.155  
 148.156 -        if ( comp_wait ) {
 148.157 +        if ( comp_wait )
 148.158 +        {
 148.159              /* clear 'ComWaitInt' in status register (WIC) */
 148.160              status &= IOMMU_STATUS_COMP_WAIT_INT_MASK;
 148.161              writel(status, iommu->mmio_base +
 148.162 -                IOMMU_STATUS_MMIO_OFFSET);
 148.163 -        } else
 148.164 -            dprintk(XENLOG_WARNING, "AMD IOMMU: %s(): Warning:"
 148.165 -                " ComWaitInt bit did not assert!\n",
 148.166 -                 __FUNCTION__);
 148.167 +                   IOMMU_STATUS_MMIO_OFFSET);
 148.168 +        }
 148.169 +        else
 148.170 +            dprintk(XENLOG_WARNING, "AMD IOMMU: Warning:"
 148.171 +                    " ComWaitInt bit did not assert!\n");
 148.172      }
 148.173  }
 148.174  
 148.175  static void clear_page_table_entry_present(u32 *pte)
 148.176  {
 148.177      set_field_in_reg_u32(IOMMU_CONTROL_DISABLED, pte[0],
 148.178 -        IOMMU_PTE_PRESENT_MASK,
 148.179 -        IOMMU_PTE_PRESENT_SHIFT, &pte[0]);
 148.180 +                         IOMMU_PTE_PRESENT_MASK,
 148.181 +                         IOMMU_PTE_PRESENT_SHIFT, &pte[0]);
 148.182  }
 148.183  
 148.184  static void set_page_table_entry_present(u32 *pte, u64 page_addr,
 148.185 -                int iw, int ir)
 148.186 +                                         int iw, int ir)
 148.187  {
 148.188      u64 addr_lo, addr_hi;
 148.189      u32 entry;
 148.190 @@ -175,33 +174,33 @@ static void set_page_table_entry_present
 148.191      addr_hi = page_addr >> 32;
 148.192  
 148.193      set_field_in_reg_u32((u32)addr_hi, 0,
 148.194 -        IOMMU_PTE_ADDR_HIGH_MASK,
 148.195 -        IOMMU_PTE_ADDR_HIGH_SHIFT, &entry);
 148.196 +                         IOMMU_PTE_ADDR_HIGH_MASK,
 148.197 +                         IOMMU_PTE_ADDR_HIGH_SHIFT, &entry);
 148.198      set_field_in_reg_u32(iw ? IOMMU_CONTROL_ENABLED :
 148.199 -        IOMMU_CONTROL_DISABLED, entry,
 148.200 -        IOMMU_PTE_IO_WRITE_PERMISSION_MASK,
 148.201 -        IOMMU_PTE_IO_WRITE_PERMISSION_SHIFT, &entry);
 148.202 +                         IOMMU_CONTROL_DISABLED, entry,
 148.203 +                         IOMMU_PTE_IO_WRITE_PERMISSION_MASK,
 148.204 +                         IOMMU_PTE_IO_WRITE_PERMISSION_SHIFT, &entry);
 148.205      set_field_in_reg_u32(ir ? IOMMU_CONTROL_ENABLED :
 148.206 -        IOMMU_CONTROL_DISABLED, entry,
 148.207 -        IOMMU_PTE_IO_READ_PERMISSION_MASK,
 148.208 -        IOMMU_PTE_IO_READ_PERMISSION_SHIFT, &entry);
 148.209 +                         IOMMU_CONTROL_DISABLED, entry,
 148.210 +                         IOMMU_PTE_IO_READ_PERMISSION_MASK,
 148.211 +                         IOMMU_PTE_IO_READ_PERMISSION_SHIFT, &entry);
 148.212      pte[1] = entry;
 148.213  
 148.214      set_field_in_reg_u32((u32)addr_lo >> PAGE_SHIFT, 0,
 148.215 -        IOMMU_PTE_ADDR_LOW_MASK,
 148.216 -        IOMMU_PTE_ADDR_LOW_SHIFT, &entry);
 148.217 +                         IOMMU_PTE_ADDR_LOW_MASK,
 148.218 +                         IOMMU_PTE_ADDR_LOW_SHIFT, &entry);
 148.219      set_field_in_reg_u32(IOMMU_PAGING_MODE_LEVEL_0, entry,
 148.220 -        IOMMU_PTE_NEXT_LEVEL_MASK,
 148.221 -        IOMMU_PTE_NEXT_LEVEL_SHIFT, &entry);
 148.222 +                         IOMMU_PTE_NEXT_LEVEL_MASK,
 148.223 +                         IOMMU_PTE_NEXT_LEVEL_SHIFT, &entry);
 148.224      set_field_in_reg_u32(IOMMU_CONTROL_ENABLED, entry,
 148.225 -        IOMMU_PTE_PRESENT_MASK,
 148.226 -        IOMMU_PTE_PRESENT_SHIFT, &entry);
 148.227 +                         IOMMU_PTE_PRESENT_MASK,
 148.228 +                         IOMMU_PTE_PRESENT_SHIFT, &entry);
 148.229      pte[0] = entry;
 148.230  }
 148.231  
 148.232  
 148.233  static void amd_iommu_set_page_directory_entry(u32 *pde, 
 148.234 -            u64 next_ptr, u8 next_level)
 148.235 +                                               u64 next_ptr, u8 next_level)
 148.236  {
 148.237      u64 addr_lo, addr_hi;
 148.238      u32 entry;
 148.239 @@ -211,29 +210,31 @@ static void amd_iommu_set_page_directory
 148.240  
 148.241      /* enable read/write permissions,which will be enforced at the PTE */
 148.242      set_field_in_reg_u32((u32)addr_hi, 0,
 148.243 -        IOMMU_PDE_ADDR_HIGH_MASK, IOMMU_PDE_ADDR_HIGH_SHIFT, &entry);
 148.244 +                         IOMMU_PDE_ADDR_HIGH_MASK,
 148.245 +                         IOMMU_PDE_ADDR_HIGH_SHIFT, &entry);
 148.246      set_field_in_reg_u32(IOMMU_CONTROL_ENABLED, entry,
 148.247 -        IOMMU_PDE_IO_WRITE_PERMISSION_MASK,
 148.248 -        IOMMU_PDE_IO_WRITE_PERMISSION_SHIFT, &entry);
 148.249 +                         IOMMU_PDE_IO_WRITE_PERMISSION_MASK,
 148.250 +                         IOMMU_PDE_IO_WRITE_PERMISSION_SHIFT, &entry);
 148.251      set_field_in_reg_u32(IOMMU_CONTROL_ENABLED, entry,
 148.252 -        IOMMU_PDE_IO_READ_PERMISSION_MASK,
 148.253 -        IOMMU_PDE_IO_READ_PERMISSION_SHIFT, &entry);
 148.254 +                         IOMMU_PDE_IO_READ_PERMISSION_MASK,
 148.255 +                         IOMMU_PDE_IO_READ_PERMISSION_SHIFT, &entry);
 148.256      pde[1] = entry;
 148.257  
 148.258      /* mark next level as 'present' */
 148.259      set_field_in_reg_u32((u32)addr_lo >> PAGE_SHIFT, 0,
 148.260 -        IOMMU_PDE_ADDR_LOW_MASK, IOMMU_PDE_ADDR_LOW_SHIFT, &entry);
 148.261 +                         IOMMU_PDE_ADDR_LOW_MASK,
 148.262 +                         IOMMU_PDE_ADDR_LOW_SHIFT, &entry);
 148.263      set_field_in_reg_u32(next_level, entry,
 148.264 -        IOMMU_PDE_NEXT_LEVEL_MASK,
 148.265 -        IOMMU_PDE_NEXT_LEVEL_SHIFT, &entry);
 148.266 +                         IOMMU_PDE_NEXT_LEVEL_MASK,
 148.267 +                         IOMMU_PDE_NEXT_LEVEL_SHIFT, &entry);
 148.268      set_field_in_reg_u32(IOMMU_CONTROL_ENABLED, entry,
 148.269 -        IOMMU_PDE_PRESENT_MASK,
 148.270 -        IOMMU_PDE_PRESENT_SHIFT, &entry);
 148.271 +                         IOMMU_PDE_PRESENT_MASK,
 148.272 +                         IOMMU_PDE_PRESENT_SHIFT, &entry);
 148.273      pde[0] = entry;
 148.274  }
 148.275  
 148.276  void amd_iommu_set_dev_table_entry(u32 *dte, u64 root_ptr, u16 domain_id,
 148.277 -                u8 paging_mode)
 148.27