WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] merge with xen-unstable.hg

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] merge with xen-unstable.hg
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Mon, 11 Aug 2008 05:50:12 -0700
Delivery-date: Mon, 11 Aug 2008 05:51:10 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Isaku Yamahata <yamahata@xxxxxxxxxxxxx>
# Date 1216350761 -32400
# Node ID 400e5d4877caacf9a9da96b3fe47e76024e27b44
# Parent  eb0fc71cfc72ed15ed35fa17617b7cab32164029
# Parent  a8603b2fb786958f8e74e9b6d6356eb1beec5b68
merge with xen-unstable.hg
---
 stubdom/binutils.patch                                         |   12 
 stubdom/gcc.patch                                              |   28 
 tools/firmware/vgabios/vbetables.h                             | 1282 -----
 .hgignore                                                      |    7 
 Config.mk                                                      |    8 
 Makefile                                                       |   18 
 buildconfigs/mk.linux-2.6-tip-latest                           |   14 
 buildconfigs/src.git-clone                                     |   60 
 config/StdGNU.mk                                               |    3 
 docs/ChangeLog                                                 |    3 
 extras/mini-os/Config.mk                                       |   12 
 extras/mini-os/Makefile                                        |    4 
 extras/mini-os/arch/ia64/minios-ia64.lds                       |    6 
 extras/mini-os/arch/x86/minios-x86_32.lds                      |    6 
 extras/mini-os/arch/x86/minios-x86_64.lds                      |    6 
 extras/mini-os/arch/x86/mm.c                                   |    2 
 extras/mini-os/blkfront.c                                      |   21 
 extras/mini-os/events.c                                        |   26 
 extras/mini-os/fbfront.c                                       |   19 
 extras/mini-os/fs-front.c                                      |    2 
 extras/mini-os/hypervisor.c                                    |    3 
 extras/mini-os/include/arch/cc.h                               |    6 
 extras/mini-os/include/arch/sys_arch.h                         |    6 
 extras/mini-os/include/blkfront.h                              |    4 
 extras/mini-os/include/byteswap.h                              |    2 
 extras/mini-os/include/console.h                               |    4 
 extras/mini-os/include/ctype.h                                 |    5 
 extras/mini-os/include/err.h                                   |    2 
 extras/mini-os/include/errno.h                                 |    9 
 extras/mini-os/include/events.h                                |    3 
 extras/mini-os/include/fbfront.h                               |    2 
 extras/mini-os/include/fs.h                                    |    4 
 extras/mini-os/include/hypervisor.h                            |    4 
 extras/mini-os/include/ia64/arch_spinlock.h                    |    2 
 extras/mini-os/include/ia64/atomic.h                           |    2 
 extras/mini-os/include/ia64/efi.h                              |    2 
 extras/mini-os/include/ia64/endian.h                           |    2 
 extras/mini-os/include/ia64/hypercall-ia64.h                   |    4 
 extras/mini-os/include/ia64/os.h                               |    6 
 extras/mini-os/include/lib.h                                   |    4 
 extras/mini-os/include/linux/types.h                           |    2 
 extras/mini-os/include/mm.h                                    |    6 
 extras/mini-os/include/netfront.h                              |    2 
 extras/mini-os/include/pcifront.h                              |   28 
 extras/mini-os/include/posix/fcntl.h                           |   11 
 extras/mini-os/include/posix/limits.h                          |   41 
 extras/mini-os/include/posix/sys/mman.h                        |    3 
 extras/mini-os/include/posix/sys/select.h                      |    1 
 extras/mini-os/include/posix/unistd.h                          |    5 
 extras/mini-os/include/sched.h                                 |    9 
 extras/mini-os/include/semaphore.h                             |    4 
 extras/mini-os/include/spinlock.h                              |    4 
 extras/mini-os/include/sys/lock.h                              |   52 
 extras/mini-os/include/time.h                                  |    2 
 extras/mini-os/include/types.h                                 |    8 
 extras/mini-os/include/wait.h                                  |   27 
 extras/mini-os/include/waittypes.h                             |   26 
 extras/mini-os/include/x86/arch_sched.h                        |    2 
 extras/mini-os/include/x86/arch_spinlock.h                     |    4 
 extras/mini-os/include/x86/os.h                                |    6 
 extras/mini-os/include/x86/x86_32/hypercall-x86_32.h           |    2 
 extras/mini-os/include/x86/x86_64/hypercall-x86_64.h           |    2 
 extras/mini-os/include/xmalloc.h                               |    2 
 extras/mini-os/kernel.c                                        |   28 
 extras/mini-os/lib/ctype.c                                     |    2 
 extras/mini-os/lib/printf.c                                    |    1 
 extras/mini-os/lib/sys.c                                       |   20 
 extras/mini-os/lib/xmalloc.c                                   |    4 
 extras/mini-os/lock.c                                          |  111 
 extras/mini-os/lwip-net.c                                      |   10 
 extras/mini-os/main.c                                          |    2 
 extras/mini-os/minios.mk                                       |    7 
 extras/mini-os/mm.c                                            |    2 
 extras/mini-os/netfront.c                                      |   28 
 extras/mini-os/pcifront.c                                      |  364 +
 extras/mini-os/sched.c                                         |    6 
 extras/mini-os/xenbus/xenbus.c                                 |   53 
 stubdom/Makefile                                               |  261 -
 stubdom/grub.patches/00cvs                                     |  872 +++
 stubdom/grub.patches/99minios                                  |   24 
 stubdom/grub/Makefile                                          |   10 
 stubdom/grub/mini-os.c                                         |    4 
 stubdom/libpci.config.h                                        |    2 
 stubdom/libpci.config.mak                                      |    5 
 stubdom/lwip.patch-cvs                                         | 1512 ++++++
 stubdom/newlib.patch                                           |  234 
 stubdom/pciutils.patch                                         |   94 
 tools/Makefile                                                 |   35 
 tools/blktap/drivers/Makefile                                  |    7 
 tools/blktap/drivers/blktapctrl.c                              |  109 
 tools/blktap/drivers/blktapctrl.h                              |   23 
 tools/blktap/drivers/blktapctrl_linux.c                        |  109 
 tools/blktap/drivers/block-aio.c                               |   16 
 tools/blktap/drivers/block-qcow.c                              |   22 
 tools/blktap/drivers/block-ram.c                               |   16 
 tools/blktap/drivers/block-sync.c                              |   18 
 tools/blktap/drivers/img2qcow.c                                |    6 
 tools/blktap/drivers/qcow-create.c                             |    2 
 tools/blktap/drivers/qcow2raw.c                                |    6 
 tools/blktap/drivers/tapdisk.c                                 |   10 
 tools/blktap/lib/blktaplib.h                                   |    9 
 tools/blktap/lib/xenbus.c                                      |    6 
 tools/console/daemon/io.c                                      |    2 
 tools/examples/network-bridge                                  |   13 
 tools/examples/vscsi                                           |   22 
 tools/examples/vtpm-common.sh                                  |    4 
 tools/examples/xen-backend.agent                               |    3 
 tools/examples/xen-backend.rules                               |    1 
 tools/examples/xmexample.hvm                                   |   23 
 tools/examples/xmexample.vti                                   |   22 
 tools/examples/xmexample1                                      |   25 
 tools/examples/xmexample2                                      |   24 
 tools/firmware/hvmloader/acpi/build.c                          |    8 
 tools/firmware/hvmloader/config.h                              |   11 
 tools/firmware/hvmloader/hvmloader.c                           |   23 
 tools/firmware/hvmloader/mp_tables.c                           |   19 
 tools/firmware/hvmloader/smp.c                                 |    3 
 tools/firmware/hvmloader/util.h                                |    6 
 tools/firmware/rombios/32bit/tcgbios/tcgbios.c                 |    4 
 tools/firmware/rombios/32bit/tcgbios/tpm_drivers.c             |   12 
 tools/firmware/rombios/32bit/util.c                            |    6 
 tools/firmware/rombios/rombios.c                               |   24 
 tools/firmware/vgabios/ChangeLog                               |  204 
 tools/firmware/vgabios/Makefile                                |   16 
 tools/firmware/vgabios/README                                  |   28 
 tools/firmware/vgabios/TODO                                    |    4 
 tools/firmware/vgabios/biossums.c                              |  220 
 tools/firmware/vgabios/clext.c                                 |   24 
 tools/firmware/vgabios/vbe.c                                   |  516 +-
 tools/firmware/vgabios/vbe.h                                   |   25 
 tools/firmware/vgabios/vbe_display_api.txt                     |   78 
 tools/firmware/vgabios/vbetables-gen.c                         |  240 +
 tools/firmware/vgabios/vgabios.c                               |  389 +
 tools/firmware/vgabios/vgatables.h                             |  528 +-
 tools/fs-back/fs-backend.c                                     |    7 
 tools/fs-back/fs-backend.h                                     |    6 
 tools/fs-back/fs-ops.c                                         |   82 
 tools/include/xen-sys/MiniOS/privcmd.h                         |   18 
 tools/ioemu/Makefile.target                                    |    2 
 tools/ioemu/hw/e1000.c                                         |   53 
 tools/ioemu/hw/pass-through.c                                  | 2395 
+++++++++-
 tools/ioemu/hw/pass-through.h                                  |  175 
 tools/ioemu/hw/pci.c                                           |   35 
 tools/ioemu/hw/pt-msi.c                                        |  583 --
 tools/ioemu/hw/pt-msi.h                                        |   44 
 tools/ioemu/hw/vga.c                                           |  207 
 tools/ioemu/hw/xen_platform.c                                  |   98 
 tools/ioemu/sdl.c                                              |    3 
 tools/ioemu/target-i386-dm/exec-dm.c                           |    4 
 tools/ioemu/vl.c                                               |    5 
 tools/ioemu/vl.h                                               |    2 
 tools/ioemu/xenstore.c                                         |    4 
 tools/libfsimage/ext2fs/fsys_ext2fs.c                          |    6 
 tools/libfsimage/fat/fsys_fat.c                                |    6 
 tools/libfsimage/iso9660/fsys_iso9660.c                        |    6 
 tools/libfsimage/reiserfs/fsys_reiserfs.c                      |    6 
 tools/libfsimage/ufs/fsys_ufs.c                                |    6 
 tools/libfsimage/zfs/fsys_zfs.c                                |    6 
 tools/libxc/xc_domain.c                                        |   63 
 tools/libxc/xc_minios.c                                        |    1 
 tools/libxc/xc_misc.c                                          |   30 
 tools/libxc/xc_private.c                                       |    2 
 tools/libxc/xenctrl.h                                          |   26 
 tools/libxc/xg_private.h                                       |    3 
 tools/misc/xenperf.c                                           |    4 
 tools/python/xen/lowlevel/acm/acm.c                            |    2 
 tools/python/xen/lowlevel/xc/xc.c                              |   57 
 tools/python/xen/util/pci.py                                   |  667 ++
 tools/python/xen/util/vscsi_util.py                            |  133 
 tools/python/xen/xend/XendAPI.py                               |   20 
 tools/python/xen/xend/XendCheckpoint.py                        |    2 
 tools/python/xen/xend/XendConfig.py                            |  175 
 tools/python/xen/xend/XendDPCI.py                              |  154 
 tools/python/xen/xend/XendDevices.py                           |    3 
 tools/python/xen/xend/XendDomain.py                            |    3 
 tools/python/xen/xend/XendDomainInfo.py                        |  280 -
 tools/python/xen/xend/XendError.py                             |   11 
 tools/python/xen/xend/XendNode.py                              |   54 
 tools/python/xen/xend/XendPPCI.py                              |  158 
 tools/python/xen/xend/image.py                                 |    2 
 tools/python/xen/xend/osdep.py                                 |   10 
 tools/python/xen/xend/server/DevController.py                  |    8 
 tools/python/xen/xend/server/XMLRPCServer.py                   |    9 
 tools/python/xen/xend/server/pciif.py                          |   75 
 tools/python/xen/xend/server/vscsiif.py                        |  232 
 tools/python/xen/xm/create.py                                  |  103 
 tools/python/xen/xm/main.py                                    |  137 
 tools/xcutils/xc_save.c                                        |  123 
 tools/xenmon/xenbaked.c                                        |   89 
 tools/xenstat/xentop/xentop.c                                  |    2 
 tools/xenstore/talloc.c                                        |    2 
 tools/xenstore/tdb.c                                           |    4 
 tools/xenstore/xenstore_client.c                               |    2 
 tools/xenstore/xenstored_core.c                                |   17 
 tools/xentrace/xenctx.c                                        |   32 
 tools/xentrace/xentrace.c                                      |   28 
 tools/xm-test/tests/security-acm/10_security-acm_pol_update.py |    5 
 xen/arch/ia64/xen/fw_emul.c                                    |    5 
 xen/arch/x86/acpi/cpu_idle.c                                   |   23 
 xen/arch/x86/acpi/cpufreq/cpufreq_ondemand.c                   |    2 
 xen/arch/x86/cpu/intel.c                                       |   32 
 xen/arch/x86/cpu/mcheck/Makefile                               |    3 
 xen/arch/x86/cpu/mcheck/amd_f10.c                              |  131 
 xen/arch/x86/cpu/mcheck/amd_k8.c                               |  324 +
 xen/arch/x86/cpu/mcheck/amd_nonfatal.c                         |  303 +
 xen/arch/x86/cpu/mcheck/k7.c                                   |    7 
 xen/arch/x86/cpu/mcheck/mce.c                                  |  566 ++
 xen/arch/x86/cpu/mcheck/mce.h                                  |   26 
 xen/arch/x86/cpu/mcheck/non-fatal.c                            |   30 
 xen/arch/x86/cpu/mcheck/x86_mca.h                              |   72 
 xen/arch/x86/domain.c                                          |   17 
 xen/arch/x86/domctl.c                                          |   51 
 xen/arch/x86/hpet.c                                            |   15 
 xen/arch/x86/hvm/hvm.c                                         |  142 
 xen/arch/x86/hvm/mtrr.c                                        |   27 
 xen/arch/x86/hvm/rtc.c                                         |   65 
 xen/arch/x86/hvm/svm/svm.c                                     |    6 
 xen/arch/x86/hvm/svm/vmcb.c                                    |    4 
 xen/arch/x86/hvm/vlapic.c                                      |    5 
 xen/arch/x86/hvm/vmx/vmcs.c                                    |    6 
 xen/arch/x86/hvm/vmx/vmx.c                                     |   21 
 xen/arch/x86/i8259.c                                           |    7 
 xen/arch/x86/irq.c                                             |   42 
 xen/arch/x86/mm/hap/p2m-ept.c                                  |   95 
 xen/arch/x86/mm/p2m.c                                          |   22 
 xen/arch/x86/mm/shadow/common.c                                |  285 -
 xen/arch/x86/mm/shadow/multi.c                                 |   85 
 xen/arch/x86/mm/shadow/private.h                               |   11 
 xen/arch/x86/msi.c                                             |  228 
 xen/arch/x86/nmi.c                                             |    4 
 xen/arch/x86/physdev.c                                         |   30 
 xen/arch/x86/setup.c                                           |    2 
 xen/arch/x86/smpboot.c                                         |    4 
 xen/arch/x86/time.c                                            |  210 
 xen/arch/x86/traps.c                                           |  125 
 xen/arch/x86/x86_32/asm-offsets.c                              |    6 
 xen/arch/x86/x86_32/entry.S                                    |   36 
 xen/arch/x86/x86_32/traps.c                                    |    9 
 xen/arch/x86/x86_64/asm-offsets.c                              |    6 
 xen/arch/x86/x86_64/compat/entry.S                             |   35 
 xen/arch/x86/x86_64/compat/traps.c                             |    9 
 xen/arch/x86/x86_64/entry.S                                    |   35 
 xen/arch/x86/x86_64/mm.c                                       |    3 
 xen/arch/x86/x86_64/traps.c                                    |    9 
 xen/common/domain.c                                            |   10 
 xen/common/domctl.c                                            |   17 
 xen/common/event_channel.c                                     |   34 
 xen/common/hvm/save.c                                          |    6 
 xen/common/memory.c                                            |   36 
 xen/common/page_alloc.c                                        |    3 
 xen/common/sched_sedf.c                                        |   26 
 xen/common/stop_machine.c                                      |    1 
 xen/common/version.c                                           |    1 
 xen/drivers/acpi/reboot.c                                      |    1 
 xen/drivers/passthrough/Makefile                               |    1 
 xen/drivers/passthrough/amd/Makefile                           |    1 
 xen/drivers/passthrough/amd/iommu_intr.c                       |  205 
 xen/drivers/passthrough/amd/iommu_map.c                        |   49 
 xen/drivers/passthrough/amd/pci_amd_iommu.c                    |  133 
 xen/drivers/passthrough/io.c                                   |   36 
 xen/drivers/passthrough/iommu.c                                |   79 
 xen/drivers/passthrough/pci.c                                  |  203 
 xen/drivers/passthrough/vtd/dmar.c                             |  389 -
 xen/drivers/passthrough/vtd/dmar.h                             |   44 
 xen/drivers/passthrough/vtd/extern.h                           |    1 
 xen/drivers/passthrough/vtd/intremap.c                         |    4 
 xen/drivers/passthrough/vtd/iommu.c                            |  481 --
 xen/drivers/passthrough/vtd/qinval.c                           |    4 
 xen/drivers/passthrough/vtd/utils.c                            |   75 
 xen/include/Makefile                                           |    1 
 xen/include/acpi/cpufreq/processor_perf.h                      |    2 
 xen/include/asm-x86/domain.h                                   |   14 
 xen/include/asm-x86/event.h                                    |    7 
 xen/include/asm-x86/hvm/hvm.h                                  |    1 
 xen/include/asm-x86/hvm/support.h                              |    3 
 xen/include/asm-x86/hvm/svm/amd-iommu-defs.h                   |   66 
 xen/include/asm-x86/hvm/svm/amd-iommu-proto.h                  |   14 
 xen/include/asm-x86/hvm/vmx/vmx.h                              |    4 
 xen/include/asm-x86/hvm/vpt.h                                  |    4 
 xen/include/asm-x86/io_apic.h                                  |    4 
 xen/include/asm-x86/mm.h                                       |    9 
 xen/include/asm-x86/msi.h                                      |    4 
 xen/include/asm-x86/msr-index.h                                |    3 
 xen/include/asm-x86/mtrr.h                                     |    3 
 xen/include/asm-x86/perfc_defn.h                               |    9 
 xen/include/asm-x86/time.h                                     |    4 
 xen/include/asm-x86/traps.h                                    |   50 
 xen/include/public/arch-x86/xen-mca.h                          |  279 +
 xen/include/public/arch-x86/xen.h                              |    4 
 xen/include/public/domctl.h                                    |   16 
 xen/include/public/hvm/hvm_op.h                                |   21 
 xen/include/public/io/fsif.h                                   |    2 
 xen/include/public/io/pciif.h                                  |    6 
 xen/include/public/memory.h                                    |   26 
 xen/include/public/physdev.h                                   |   11 
 xen/include/public/xen-compat.h                                |    2 
 xen/include/xen/event.h                                        |   12 
 xen/include/xen/hvm/iommu.h                                    |    5 
 xen/include/xen/iommu.h                                        |   15 
 xen/include/xen/pci.h                                          |   42 
 xen/include/xen/sched.h                                        |   21 
 xen/include/xen/time.h                                         |    2 
 xen/include/xsm/xsm.h                                          |    6 
 xen/xsm/dummy.c                                                |    6 
 304 files changed, 15866 insertions(+), 4761 deletions(-)

diff -r eb0fc71cfc72 -r 400e5d4877ca .hgignore
--- a/.hgignore Tue Jul 08 11:41:43 2008 +0900
+++ b/.hgignore Fri Jul 18 12:12:41 2008 +0900
@@ -135,9 +135,8 @@
 ^tools/firmware/rombios/_rombios[^/]*_\.c$
 ^tools/firmware/rombios/rombios[^/]*\.s$
 ^tools/firmware/rombios/32bit/32bitbios_flat\.h$
-^tools/firmware/vmxassist/gen$
-^tools/firmware/vmxassist/offsets\.h$
-^tools/firmware/vmxassist/vmxassist$
+^tools/firmware/vgabios/vbetables-gen$
+^tools/firmware/vgabios/vbetables\.h$
 ^tools/flask/loadpolicy/flask-loadpolicy$
 ^tools/include/xen/.*$
 ^tools/include/xen-foreign/.*\.(c|h|size)$
@@ -248,6 +247,8 @@
 ^tools/xm-test/lib/XmTestLib/config.py$
 ^tools/xm-test/lib/XmTestReport/xmtest.py$
 ^tools/xm-test/tests/.*\.test$
+^tools/ioemu-remote
+^tools/ioemu-dir$
 ^xen/\.banner.*$
 ^xen/BLOG$
 ^xen/System.map$
diff -r eb0fc71cfc72 -r 400e5d4877ca Config.mk
--- a/Config.mk Tue Jul 08 11:41:43 2008 +0900
+++ b/Config.mk Fri Jul 18 12:12:41 2008 +0900
@@ -78,6 +78,14 @@ FLASK_ENABLE ?= n
 FLASK_ENABLE ?= n
 ACM_SECURITY ?= n
 
+QEMU_REMOTE=http://xenbits.xensource.com/git-http/qemu-xen-unstable.git
+
+# Specify which qemu-dm to use. This may be `ioemu' to use the old
+# Mercurial in-tree version, or a local directory, or a git URL.
+# CONFIG_QEMU   ?= ioemu
+# CONFIG_QEMU   ?= ../qemu-xen.git
+CONFIG_QEMU   ?= $(QEMU_REMOTE)
+
 # Optional components
 XENSTAT_XENTOP     ?= y
 VTPM_TOOLS         ?= n
diff -r eb0fc71cfc72 -r 400e5d4877ca Makefile
--- a/Makefile  Tue Jul 08 11:41:43 2008 +0900
+++ b/Makefile  Fri Jul 18 12:12:41 2008 +0900
@@ -15,12 +15,13 @@ include buildconfigs/Rules.mk
 
 # build and install everything into the standard system directories
 .PHONY: install
-install: install-xen install-kernels install-tools install-docs
+install: install-xen install-kernels install-tools install-stubdom install-docs
 
 .PHONY: build
 build: kernels
        $(MAKE) -C xen build
        $(MAKE) -C tools build
+       $(MAKE) -C stubdom build
        $(MAKE) -C docs build
 
 # The test target is for unit tests that can run without an installation.  Of
@@ -33,7 +34,7 @@ test:
 # build and install everything into local dist directory
 .PHONY: dist
 dist: DESTDIR=$(DISTDIR)/install
-dist: dist-xen dist-kernels dist-tools dist-docs
+dist: dist-xen dist-kernels dist-tools dist-stubdom dist-docs
        $(INSTALL_DIR) $(DISTDIR)/check
        $(INSTALL_DATA) ./COPYING $(DISTDIR)
        $(INSTALL_DATA) ./README $(DISTDIR)
@@ -44,10 +45,11 @@ dist-%: install-%
        @: # do nothing
 
 # Legacy dist targets
-.PHONY: xen tools kernels docs
+.PHONY: xen tools stubdom kernels docs
 xen: dist-xen
 tools: dist-tools
 kernels: dist-kernels
+stubdom: dist-stubdom
 docs: dist-docs
 
 .PHONY: prep-kernels
@@ -65,6 +67,10 @@ install-tools:
 .PHONY: install-kernels
 install-kernels:
        for i in $(XKERNELS) ; do $(MAKE) $$i-install || exit 1; done
+
+.PHONY: install-stubdom
+install-stubdom:
+       $(MAKE) -C stubdom install
 
 .PHONY: install-docs
 install-docs:
@@ -102,6 +108,7 @@ clean::
 clean::
        $(MAKE) -C xen clean
        $(MAKE) -C tools clean
+       $(MAKE) -C stubdom crossclean
        $(MAKE) -C docs clean
 
 # clean, but blow away kernel build tree plus tarballs
@@ -109,6 +116,7 @@ distclean:
 distclean:
        $(MAKE) -C xen distclean
        $(MAKE) -C tools distclean
+       $(MAKE) -C stubdom distclean
        $(MAKE) -C docs distclean
        rm -rf dist patches/tmp
        for i in $(ALLKERNELS) ; do $(MAKE) $$i-delete ; done
@@ -132,6 +140,7 @@ help:
        @echo '  install-xen      - build and install the Xen hypervisor'
        @echo '  install-tools    - build and install the control tools'
        @echo '  install-kernels  - build and install guest kernels'
+       @echo '  install-stubdom  - build and install the stubdomain images'
        @echo '  install-docs     - build and install user documentation'
        @echo ''
        @echo 'Building targets:'
@@ -140,6 +149,7 @@ help:
        @echo '                     trees then make dist'
        @echo '  xen              - build and install Xen hypervisor'
        @echo '  tools            - build and install tools'
+       @echo '  stubdomain       - build and install the stubdomain images'
        @echo '  kernels          - build and install guest kernels'
        @echo '  kbuild           - synonym for make kernels'
        @echo '  docs             - build and install user documentation'
@@ -214,7 +224,7 @@ linux26:
 # tboot targets
 #
 
-TBOOT_TARFILE = tboot-20071128.tar.gz
+TBOOT_TARFILE = tboot-20080613.tar.gz
 TBOOT_BASE_URL = http://downloads.sourceforge.net/tboot
 
 .PHONY: build-tboot
diff -r eb0fc71cfc72 -r 400e5d4877ca buildconfigs/mk.linux-2.6-tip-latest
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/buildconfigs/mk.linux-2.6-tip-latest      Fri Jul 18 12:12:41 2008 +0900
@@ -0,0 +1,14 @@
+XEN_LINUX_SOURCE ?= git-clone
+LINUX_VER ?= 2.6-x86-latest
+
+IMAGE_TARGET ?= bzImage vmlinux
+
+XEN_LINUX_CONFIG_UPDATE := buildconfigs/enable-xen-config
+
+XEN_LINUX_GIT_URL ?= 
git://git.kernel.org/pub/scm/linux/kernel/git/x86/linux-2.6-tip.git
+XEN_LINUX_GIT_REMOTENAME ?= x86
+XEN_LINUX_GIT_REMOTEBRANCH ?= auto-latest
+
+EXTRAVERSION ?=
+
+include buildconfigs/mk.linux-2.6-common
diff -r eb0fc71cfc72 -r 400e5d4877ca buildconfigs/src.git-clone
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/buildconfigs/src.git-clone        Fri Jul 18 12:12:41 2008 +0900
@@ -0,0 +1,60 @@
+# Mercurial
+GIT ?= git
+
+LINUX_SRCDIR ?= linux-$(LINUX_VER).git
+
+# The URL of the remote GIT repository
+ifeq ($(XEN_LINUX_GIT_URL),)
+.ERROR: XEN_LINUX_GIT_URL not specified
+endif
+
+# The name to use for the remote repository
+XEN_LINUX_GIT_REMOTENAME ?= origin
+
+# The branch in the remote repository
+ifeq ($(XEN_LINUX_GIT_REMOTEBRANCH),)
+.ERROR: XEN_LINUX_GIT_REMOTEBRANCH not specified
+endif
+
+XEN_LINUX_GIT_LOCALBRANCH ?= master
+
+# Set XEN_LINUX_GITREV to update to a particlar revision.
+XEN_LINUX_GITREV  ?= 
+
+$(LINUX_SRCDIR)/.valid-src: $(__XEN_LINUX_UPDATE)
+       @set -e ; if [ -d $(LINUX_SRCDIR) ] && [ ! -d $(GIT_DIR) ] ; then \
+           echo "$(LINUX_SRCDIR) exists but is not a git repository." 1>&2 ; \
+           false ; \
+       fi
+
+       @set -e ; if [ ! -e $(LINUX_SRCDIR)/.git ] ; then \
+           mkdir $(LINUX_SRCDIR) ; \
+           cd $(LINUX_SRCDIR) ; \
+           $(GIT) init-db ; \
+       fi
+
+       @set -e ; cd $(LINUX_SRCDIR) ; \
+       if ! $(GIT) remote | grep -q $(XEN_LINUX_GIT_REMOTENAME) ; then \
+           echo "Adding remote git repository \`$(XEN_LINUX_GIT_URL)' as 
\`$(XEN_LINUX_GIT_REMOTENAME)'" ; \
+           $(GIT) remote add $(XEN_LINUX_GIT_REMOTENAME) $(XEN_LINUX_GIT_URL) 
; \
+       fi
+
+       @echo "Updating remote \`$(XEN_LINUX_GIT_REMOTENAME)'"
+       @cd $(LINUX_SRCDIR) && $(GIT) fetch $(XEN_LINUX_GIT_REMOTENAME)
+
+       @set -e ; cd $(LINUX_SRCDIR) ; \
+       if ! $(GIT) branch -l | grep -q $(XEN_LINUX_GIT_LOCALBRANCH) ; then \
+           $(GIT) branch --track $(XEN_LINUX_GIT_LOCALBRANCH) \
+               $(XEN_LINUX_GIT_REMOTENAME)/$(XEN_LINUX_GIT_REMOTEBRANCH) ; \
+           $(GIT) checkout ; \
+       fi
+
+       @ set -e ; cd $(LINUX_SRCDIR) ; \
+       if [ -n "$(XEN_LINUX_GITREV)" ] ; then \
+           echo "Updating $(LINUX_SRCDIR) to revision \'$(XEN_LINUX_GITREV)'." 
; \
+           $(GIT) reset --hard $(XEN_LINUX_GITREV) ; \
+       else \
+           $(GIT) reset --hard 
$(XEN_LINUX_GIT_REMOTENAME)/$(XEN_LINUX_GIT_REMOTEBRANCH) ; \
+       fi
+
+       touch $@
diff -r eb0fc71cfc72 -r 400e5d4877ca config/StdGNU.mk
--- a/config/StdGNU.mk  Tue Jul 08 11:41:43 2008 +0900
+++ b/config/StdGNU.mk  Fri Jul 18 12:12:41 2008 +0900
@@ -12,6 +12,9 @@ SIZEUTIL   = $(CROSS_COMPILE)size
 
 MSGFMT     = msgfmt
 MSGMERGE   = msgmerge
+
+# Allow git to be wrappered in the environment
+GIT        ?= git
 
 INSTALL      = install
 INSTALL_DIR  = $(INSTALL) -d -m0755 -p
diff -r eb0fc71cfc72 -r 400e5d4877ca docs/ChangeLog
--- a/docs/ChangeLog    Tue Jul 08 11:41:43 2008 +0900
+++ b/docs/ChangeLog    Fri Jul 18 12:12:41 2008 +0900
@@ -15,6 +15,9 @@ http://lists.xensource.com/archives/html
 
 Xen 3.3 release
 ---------------
+
+17974: PHYSDEVOP_manage_pci_add/PHYSDEVOP_manage_pci_remove
+http://xenbits.xensource.com/xen-unstable.hg?rev/183ca809e1d7
 
 17903: Add greater than 16 xvd device availability
 http://xenbits.xensource.com/xen-unstable.hg?rev/0728459b3c8d
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/Config.mk
--- a/extras/mini-os/Config.mk  Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/Config.mk  Fri Jul 18 12:12:41 2008 +0900
@@ -38,20 +38,20 @@ EXTRA_INC = $(ARCH_INC)
 # This must be before include minios.mk!
 include $(MINI-OS_ROOT)/$(TARGET_ARCH_DIR)/arch.mk
 
-extra_incl := $(foreach dir,$(EXTRA_INC),-I$(MINI-OS_ROOT)/include/$(dir))
+extra_incl := $(foreach dir,$(EXTRA_INC),-isystem 
$(CURDIR)/$(MINI-OS_ROOT)/include/$(dir))
 
-DEF_CPPFLAGS += -I$(MINI-OS_ROOT)/include
+DEF_CPPFLAGS += -isystem $(CURDIR)/$(MINI-OS_ROOT)/include
 DEF_CPPFLAGS += -D__MINIOS__
 
 ifeq ($(libc),y)
 DEF_CPPFLAGS += -DHAVE_LIBC
-DEF_CPPFLAGS += -I$(MINI-OS_ROOT)/include/posix
-DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/xenstore
+DEF_CPPFLAGS += -isystem $(CURDIR)/$(MINI-OS_ROOT)/include/posix
+DEF_CPPFLAGS += -isystem $(CURDIR)/$(XEN_ROOT)/tools/xenstore
 endif
 
 ifneq ($(LWIPDIR),)
 lwip=y
 DEF_CPPFLAGS += -DHAVE_LWIP
-DEF_CPPFLAGS += -I$(LWIPDIR)/src/include
-DEF_CPPFLAGS += -I$(LWIPDIR)/src/include/ipv4
+DEF_CPPFLAGS += -isystem $(LWIPDIR)/src/include
+DEF_CPPFLAGS += -isystem $(LWIPDIR)/src/include/ipv4
 endif
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/Makefile
--- a/extras/mini-os/Makefile   Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/Makefile   Fri Jul 18 12:12:41 2008 +0900
@@ -55,6 +55,8 @@ endif
 .PHONY: links
 links: $(ARCH_LINKS)
        [ -e include/xen ] || ln -sf ../../../xen/include/public include/xen
+       [ -e include/mini-os ] || ln -sf . include/mini-os
+       [ -e include/$(TARGET_ARCH_FAM)/mini-os ] || ln -sf . 
include/$(TARGET_ARCH_FAM)/mini-os
 
 .PHONY: arch_lib
 arch_lib:
@@ -89,7 +91,7 @@ endif
 endif
 
 $(OBJ_DIR)/$(TARGET)_app.o: $(APP_OBJS) app.lds
-       $(LD) -r -d $(LDFLAGS) $^ $(APP_LDLIBS) --undefined main -o $@
+       $(LD) -r -d $(LDFLAGS) -\( $^ -\) $(APP_LDLIBS) --undefined main -o $@
 
 $(OBJ_DIR)/$(TARGET): links $(OBJS) $(OBJ_DIR)/$(TARGET)_app.o arch_lib
        $(LD) -r $(LDFLAGS) $(HEAD_OBJ) $(OBJ_DIR)/$(TARGET)_app.o $(OBJS) 
$(LDARCHLIB) $(LDLIBS) -o $@.o
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/arch/ia64/minios-ia64.lds
--- a/extras/mini-os/arch/ia64/minios-ia64.lds  Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/arch/ia64/minios-ia64.lds  Fri Jul 18 12:12:41 2008 +0900
@@ -55,8 +55,8 @@ SECTIONS
   .ctors : {
         __CTOR_LIST__ = .;
         QUAD((__CTOR_END__ - __CTOR_LIST__) / 8 - 2)
-        *(SORT_BY_NAME(.ctors))
-       SORT_BY_NAME(CONSTRUCTORS)
+        *(.ctors)
+       CONSTRUCTORS
         QUAD(0)
         __CTOR_END__ = .;
         }
@@ -64,7 +64,7 @@ SECTIONS
   .dtors : {
         __DTOR_LIST__ = .;
         QUAD((__DTOR_END__ - __DTOR_LIST__) / 8 - 2)
-        *(SORT_BY_NAME(.dtors))
+        *(.dtors)
         QUAD(0)
         __DTOR_END__ = .;
         }
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/arch/x86/minios-x86_32.lds
--- a/extras/mini-os/arch/x86/minios-x86_32.lds Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/arch/x86/minios-x86_32.lds Fri Jul 18 12:12:41 2008 +0900
@@ -31,8 +31,8 @@ SECTIONS
   .ctors : {
         __CTOR_LIST__ = .;
         LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
-        *(SORT_BY_NAME(.ctors))
-       SORT_BY_NAME(CONSTRUCTORS)
+        *(.ctors)
+       CONSTRUCTORS
         LONG(0)
         __CTOR_END__ = .;
         }
@@ -40,7 +40,7 @@ SECTIONS
   .dtors : {
         __DTOR_LIST__ = .;
         LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2)
-        *(SORT_BY_NAME(.dtors))
+        *(.dtors)
         LONG(0)
         __DTOR_END__ = .;
         }
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/arch/x86/minios-x86_64.lds
--- a/extras/mini-os/arch/x86/minios-x86_64.lds Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/arch/x86/minios-x86_64.lds Fri Jul 18 12:12:41 2008 +0900
@@ -31,8 +31,8 @@ SECTIONS
   .ctors : {
         __CTOR_LIST__ = .;
         QUAD((__CTOR_END__ - __CTOR_LIST__) / 8 - 2)
-        *(SORT_BY_NAME(.ctors))
-       SORT_BY_NAME(CONSTRUCTORS)
+        *(.ctors)
+       CONSTRUCTORS
         QUAD(0)
         __CTOR_END__ = .;
         }
@@ -40,7 +40,7 @@ SECTIONS
   .dtors : {
         __DTOR_LIST__ = .;
         QUAD((__DTOR_END__ - __DTOR_LIST__) / 8 - 2)
-        *(SORT_BY_NAME(.dtors))
+        *(.dtors)
         QUAD(0)
         __DTOR_END__ = .;
         }
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/arch/x86/mm.c
--- a/extras/mini-os/arch/x86/mm.c      Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/arch/x86/mm.c      Fri Jul 18 12:12:41 2008 +0900
@@ -549,7 +549,7 @@ void arch_init_p2m(unsigned long max_pfn
 #define L2_P2M_MASK     (L2_P2M_ENTRIES - 1)    
 #define L3_P2M_MASK     (L3_P2M_ENTRIES - 1)    
     
-    unsigned long *l1_list, *l2_list, *l3_list;
+    unsigned long *l1_list = NULL, *l2_list = NULL, *l3_list;
     unsigned long pfn;
     
     l3_list = (unsigned long *)alloc_page(); 
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/blkfront.c
--- a/extras/mini-os/blkfront.c Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/blkfront.c Fri Jul 18 12:12:41 2008 +0900
@@ -84,7 +84,7 @@ static void free_blkfront(struct blkfron
     free(dev);
 }
 
-struct blkfront_dev *init_blkfront(char *nodename, struct blkfront_info *info)
+struct blkfront_dev *init_blkfront(char *_nodename, struct blkfront_info *info)
 {
     xenbus_transaction_t xbt;
     char* err;
@@ -93,11 +93,9 @@ struct blkfront_dev *init_blkfront(char 
     int retry=0;
     char* msg;
     char* c;
+    char* nodename = _nodename ? _nodename : "device/vbd/768";
 
     struct blkfront_dev *dev;
-
-    if (!nodename)
-        nodename = "device/vbd/768";
 
     char path[strlen(nodename) + 1 + 10 + 1];
 
@@ -342,13 +340,14 @@ void blkfront_io(struct blkfront_aiocb *
 void blkfront_io(struct blkfront_aiocb *aiocbp, int write)
 {
     unsigned long flags;
+    DEFINE_WAIT(w);
+
     ASSERT(!aiocbp->aio_cb);
     aiocbp->aio_cb = blkfront_aio_cb;
     blkfront_aio(aiocbp, write);
     aiocbp->data = NULL;
 
     local_irq_save(flags);
-    DEFINE_WAIT(w);
     while (1) {
        blkfront_aio_poll(aiocbp->aio_dev);
        if (aiocbp->data)
@@ -393,6 +392,7 @@ void blkfront_sync(struct blkfront_dev *
 void blkfront_sync(struct blkfront_dev *dev)
 {
     unsigned long flags;
+    DEFINE_WAIT(w);
 
     if (dev->info.mode == O_RDWR) {
         if (dev->info.barrier == 1)
@@ -404,7 +404,6 @@ void blkfront_sync(struct blkfront_dev *
 
     /* Note: This won't finish if another thread enqueues requests.  */
     local_irq_save(flags);
-    DEFINE_WAIT(w);
     while (1) {
        blkfront_aio_poll(dev);
        if (RING_FREE_REQUESTS(&dev->ring) == RING_SIZE(&dev->ring))
@@ -424,6 +423,7 @@ int blkfront_aio_poll(struct blkfront_de
     RING_IDX rp, cons;
     struct blkif_response *rsp;
     int more;
+    int nr_consumed;
 
 moretodo:
 #ifdef HAVE_LIBC
@@ -437,14 +437,17 @@ moretodo:
     rmb(); /* Ensure we see queued responses up to 'rp'. */
     cons = dev->ring.rsp_cons;
 
-    int nr_consumed = 0;
+    nr_consumed = 0;
     while ((cons != rp))
     {
+        struct blkfront_aiocb *aiocbp;
+        int status;
+
        rsp = RING_GET_RESPONSE(&dev->ring, cons);
        nr_consumed++;
 
-        struct blkfront_aiocb *aiocbp = (void*) (uintptr_t) rsp->id;
-        int status = rsp->status;
+        aiocbp = (void*) (uintptr_t) rsp->id;
+        status = rsp->status;
 
         if (status != BLKIF_RSP_OKAY)
             printk("block error %d for op %d\n", status, rsp->operation);
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/events.c
--- a/extras/mini-os/events.c   Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/events.c   Fri Jul 18 12:12:41 2008 +0900
@@ -136,6 +136,23 @@ evtchn_port_t bind_virq(uint32_t virq, e
        return op.port;
 }
 
+evtchn_port_t bind_pirq(uint32_t pirq, int will_share, evtchn_handler_t 
handler, void *data)
+{
+       evtchn_bind_pirq_t op;
+
+       /* Try to bind the pirq to a port */
+       op.pirq = pirq;
+       op.flags = will_share ? BIND_PIRQ__WILL_SHARE : 0;
+
+       if ( HYPERVISOR_event_channel_op(EVTCHNOP_bind_pirq, &op) != 0 )
+       {
+               printk("Failed to bind physical IRQ %d\n", pirq);
+               return -1;
+       }
+       bind_evtchn(op.port, handler, data);
+       return op.port;
+}
+
 #if defined(__x86_64__)
 char irqstack[2 * STACK_SIZE];
 
@@ -190,10 +207,11 @@ int evtchn_alloc_unbound(domid_t pal, ev
 int evtchn_alloc_unbound(domid_t pal, evtchn_handler_t handler,
                                                 void *data, evtchn_port_t 
*port)
 {
+    int err;
     evtchn_alloc_unbound_t op;
     op.dom = DOMID_SELF;
     op.remote_dom = pal;
-    int err = HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound, &op);
+    err = HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound, &op);
     if (err)
                return err;
     *port = bind_evtchn(op.port, handler, data);
@@ -207,13 +225,15 @@ int evtchn_bind_interdomain(domid_t pal,
                            evtchn_handler_t handler, void *data,
                            evtchn_port_t *local_port)
 {
+    int err;
+    evtchn_port_t port;
     evtchn_bind_interdomain_t op;
     op.remote_dom = pal;
     op.remote_port = remote_port;
-    int err = HYPERVISOR_event_channel_op(EVTCHNOP_bind_interdomain, &op);
+    err = HYPERVISOR_event_channel_op(EVTCHNOP_bind_interdomain, &op);
     if (err)
                return err;
-    evtchn_port_t port = op.local_port;
+    port = op.local_port;
     *local_port = bind_evtchn(port, handler, data);
     return err;
 }
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/fbfront.c
--- a/extras/mini-os/fbfront.c  Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/fbfront.c  Fri Jul 18 12:12:41 2008 +0900
@@ -64,7 +64,7 @@ static void free_kbdfront(struct kbdfron
     free(dev);
 }
 
-struct kbdfront_dev *init_kbdfront(char *nodename, int abs_pointer)
+struct kbdfront_dev *init_kbdfront(char *_nodename, int abs_pointer)
 {
     xenbus_transaction_t xbt;
     char* err;
@@ -72,11 +72,8 @@ struct kbdfront_dev *init_kbdfront(char 
     struct xenkbd_page *s;
     int retry=0;
     char* msg;
-
+    char* nodename = _nodename ? _nodename : "device/vkbd/0";
     struct kbdfront_dev *dev;
-
-    if (!nodename)
-        nodename = "device/vkbd/0";
 
     char path[strlen(nodename) + 1 + 10 + 1];
 
@@ -351,7 +348,7 @@ int fbfront_receive(struct fbfront_dev *
     return i;
 }
 
-struct fbfront_dev *init_fbfront(char *nodename, unsigned long *mfns, int 
width, int height, int depth, int stride, int n)
+struct fbfront_dev *init_fbfront(char *_nodename, unsigned long *mfns, int 
width, int height, int depth, int stride, int n)
 {
     xenbus_transaction_t xbt;
     char* err;
@@ -361,9 +358,9 @@ struct fbfront_dev *init_fbfront(char *n
     char* msg;
     int i, j;
     struct fbfront_dev *dev;
-
-    if (!nodename)
-        nodename = "device/vfb/0";
+    int max_pd;
+    unsigned long mapped;
+    char* nodename = _nodename ? _nodename : "device/vfb/0";
 
     char path[strlen(nodename) + 1 + 10 + 1];
 
@@ -392,8 +389,8 @@ struct fbfront_dev *init_fbfront(char *n
     dev->offset = 0;
     dev->events = NULL;
 
-    const int max_pd = sizeof(s->pd) / sizeof(s->pd[0]);
-    unsigned long mapped = 0;
+    max_pd = sizeof(s->pd) / sizeof(s->pd[0]);
+    mapped = 0;
 
     for (i = 0; mapped < n && i < max_pd; i++) {
         unsigned long *pd = (unsigned long *) alloc_page();
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/fs-front.c
--- a/extras/mini-os/fs-front.c Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/fs-front.c Fri Jul 18 12:12:41 2008 +0900
@@ -3,7 +3,7 @@
  * 
  * Frontend driver for FS split device driver.
  *
- * Copyright (c) 2007, Grzegorz Milos, Sun Microsystems, Inc.
+ * Copyright (c) 2007, Grzegorz Milos, <gm281@xxxxxxxxx>.
  * 
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/hypervisor.c
--- a/extras/mini-os/hypervisor.c       Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/hypervisor.c       Fri Jul 18 12:12:41 2008 +0900
@@ -72,9 +72,10 @@ void do_hypervisor_callback(struct pt_re
 
 void force_evtchn_callback(void)
 {
+    int save;
     vcpu_info_t *vcpu;
     vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()];
-    int save = vcpu->evtchn_upcall_mask;
+    save = vcpu->evtchn_upcall_mask;
 
     while (vcpu->evtchn_upcall_pending) {
         vcpu->evtchn_upcall_mask = 1;
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/arch/cc.h
--- a/extras/mini-os/include/arch/cc.h  Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/include/arch/cc.h  Fri Jul 18 12:12:41 2008 +0900
@@ -10,8 +10,8 @@
 #define __LWIP_ARCH_CC_H__
 
 /*   Typedefs for the types used by lwip - */
-#include <os.h>
-#include <types.h>
+#include <mini-os/os.h>
+#include <mini-os/types.h>
 #include <time.h>
 typedef  u8  u8_t;
 typedef  s8  s8_t;
@@ -46,7 +46,7 @@ extern void lwip_die(char *fmt, ...);
 
 /*   If the compiler does not provide memset() this file must include a */
 /*   definition of it, or include a file which defines it. */
-#include <lib.h>
+#include <mini-os/lib.h>
 
 /*   This file must either include a system-local <errno.h> which defines */
 /*   the standard *nix error codes, or it should #define LWIP_PROVIDE_ERRNO */
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/arch/sys_arch.h
--- a/extras/mini-os/include/arch/sys_arch.h    Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/include/arch/sys_arch.h    Fri Jul 18 12:12:41 2008 +0900
@@ -9,9 +9,9 @@
 #ifndef __LWIP_ARCH_SYS_ARCH_H__
 #define __LWIP_ARCH_SYS_ARCH_H__
 
-#include <os.h>
-#include <xmalloc.h>
-#include <semaphore.h>
+#include <mini-os/os.h>
+#include <mini-os/xmalloc.h>
+#include <mini-os/semaphore.h>
 
 typedef struct semaphore *sys_sem_t;
 #define SYS_SEM_NULL ((sys_sem_t) NULL)
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/blkfront.h
--- a/extras/mini-os/include/blkfront.h Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/include/blkfront.h Fri Jul 18 12:12:41 2008 +0900
@@ -1,6 +1,6 @@
-#include <wait.h>
+#include <mini-os/wait.h>
 #include <xen/io/blkif.h>
-#include <types.h>
+#include <mini-os/types.h>
 struct blkfront_dev;
 struct blkfront_aiocb
 {
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/byteswap.h
--- a/extras/mini-os/include/byteswap.h Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/include/byteswap.h Fri Jul 18 12:12:41 2008 +0900
@@ -3,7 +3,7 @@
 
 /* Unfortunately not provided by newlib.  */
 
-#include <types.h>
+#include <mini-os/types.h>
 static inline uint16_t bswap_16(uint16_t x)
 {
     return
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/console.h
--- a/extras/mini-os/include/console.h  Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/include/console.h  Fri Jul 18 12:12:41 2008 +0900
@@ -36,8 +36,8 @@
 #ifndef _LIB_CONSOLE_H_
 #define _LIB_CONSOLE_H_
 
-#include<os.h>
-#include<traps.h>
+#include<mini-os/os.h>
+#include<mini-os/traps.h>
 #include<stdarg.h>
 
 void print(int direct, const char *fmt, va_list args);
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/ctype.h
--- a/extras/mini-os/include/ctype.h    Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/include/ctype.h    Fri Jul 18 12:12:41 2008 +0900
@@ -1,6 +1,9 @@
 #ifndef _CTYPE_H
 #define _CTYPE_H
 
+#ifdef HAVE_LIBC
+#include_next <ctype.h>
+#else
 /*
  * NOTE! This ctype does not handle EOF like the standard C
  * library is required to.
@@ -53,3 +56,5 @@ static inline unsigned char __toupper(un
 #define toupper(c) __toupper(c)
 
 #endif
+
+#endif
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/err.h
--- a/extras/mini-os/include/err.h      Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/include/err.h      Fri Jul 18 12:12:41 2008 +0900
@@ -1,7 +1,7 @@
 #ifndef _ERR_H
 #define _ERR_H
 
-#include <errno.h>
+#include <mini-os/errno.h>
 
 /*
  * Kernel pointers have redundant information, so we can use a
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/errno.h
--- a/extras/mini-os/include/errno.h    Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/include/errno.h    Fri Jul 18 12:12:41 2008 +0900
@@ -1,7 +1,9 @@
 #ifndef _ERRNO_H
 #define _ERRNO_H
 
-#include <errno-base.h>
+#include <mini-os/errno-base.h>
+
+typedef int error_t;
 
 #define        EDEADLK         35      /* Resource deadlock would occur */
 #define        ENAMETOOLONG    36      /* File name too long */
@@ -107,8 +109,11 @@
 #define        EOWNERDEAD      130     /* Owner died */
 #define        ENOTRECOVERABLE 131     /* State not recoverable */
 
+
+#define EFTYPE          132     /* Inappropriate file type or format */
+
 #ifdef HAVE_LIBC
-#include <sched.h>
+#include <mini-os/sched.h>
 extern int errno;
 #define ERRNO
 #define errno (get_current()->reent._errno)
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/events.h
--- a/extras/mini-os/include/events.h   Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/include/events.h   Fri Jul 18 12:12:41 2008 +0900
@@ -19,7 +19,7 @@
 #ifndef _EVENTS_H_
 #define _EVENTS_H_
 
-#include<traps.h>
+#include<mini-os/traps.h>
 #include<xen/event_channel.h>
 
 typedef void (*evtchn_handler_t)(evtchn_port_t, struct pt_regs *, void *);
@@ -27,6 +27,7 @@ typedef void (*evtchn_handler_t)(evtchn_
 /* prototypes */
 int do_event(evtchn_port_t port, struct pt_regs *regs);
 evtchn_port_t bind_virq(uint32_t virq, evtchn_handler_t handler, void *data);
+evtchn_port_t bind_pirq(uint32_t pirq, int will_share, evtchn_handler_t 
handler, void *data);
 evtchn_port_t bind_evtchn(evtchn_port_t port, evtchn_handler_t handler,
                                                  void *data);
 void unbind_evtchn(evtchn_port_t port);
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/fbfront.h
--- a/extras/mini-os/include/fbfront.h  Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/include/fbfront.h  Fri Jul 18 12:12:41 2008 +0900
@@ -1,6 +1,6 @@
 #include <xen/io/kbdif.h>
 #include <xen/io/fbif.h>
-#include <wait.h>
+#include <mini-os/wait.h>
 
 /* from <linux/input.h> */
 #ifndef BTN_LEFT
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/fs.h
--- a/extras/mini-os/include/fs.h       Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/include/fs.h       Fri Jul 18 12:12:41 2008 +0900
@@ -2,8 +2,8 @@
 #define __FS_H__
 
 #include <xen/io/fsif.h>
-#include <semaphore.h>
-#include <types.h>
+#include <mini-os/semaphore.h>
+#include <mini-os/types.h>
 
 struct fs_import 
 {
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/hypervisor.h
--- a/extras/mini-os/include/hypervisor.h       Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/include/hypervisor.h       Fri Jul 18 12:12:41 2008 +0900
@@ -13,7 +13,7 @@
 #ifndef _HYPERVISOR_H_
 #define _HYPERVISOR_H_
 
-#include <types.h>
+#include <mini-os/types.h>
 #include <xen/xen.h>
 #if defined(__i386__)
 #include <hypercall-x86_32.h>
@@ -24,7 +24,7 @@
 #else
 #error "Unsupported architecture"
 #endif
-#include <traps.h>
+#include <mini-os/traps.h>
 
 /*
  * a placeholder for the start of day information passed up from the hypervisor
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/ia64/arch_spinlock.h
--- a/extras/mini-os/include/ia64/arch_spinlock.h       Tue Jul 08 11:41:43 
2008 +0900
+++ b/extras/mini-os/include/ia64/arch_spinlock.h       Fri Jul 18 12:12:41 
2008 +0900
@@ -27,7 +27,7 @@
 
 #include "atomic.h"
 
-#define ARCH_SPIN_LOCK_UNLOCKED (spinlock_t) { 0 }
+#define ARCH_SPIN_LOCK_UNLOCKED { 0 }
 
 #define SPIN_LOCK_UNUSED       0
 #define SPIN_LOCK_USED         1
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/ia64/atomic.h
--- a/extras/mini-os/include/ia64/atomic.h      Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/include/ia64/atomic.h      Fri Jul 18 12:12:41 2008 +0900
@@ -38,7 +38,7 @@
 
 #if !defined(__ASSEMBLY__)
 
-#include <types.h>
+#include <mini-os/types.h>
 
 
 /*
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/ia64/efi.h
--- a/extras/mini-os/include/ia64/efi.h Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/include/ia64/efi.h Fri Jul 18 12:12:41 2008 +0900
@@ -32,7 +32,7 @@
 #ifndef _EFI_H_
 #define _EFI_H_
 
-#include "types.h"
+#include <mini-os/types.h>
 
 
 #define EFIWARN(a)                      (a)
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/ia64/endian.h
--- a/extras/mini-os/include/ia64/endian.h      Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/include/ia64/endian.h      Fri Jul 18 12:12:41 2008 +0900
@@ -26,7 +26,7 @@
 #if !defined(_ENDIAN_H_)
 #define _ENDIAN_H_
 
-#include "types.h"
+#include <mini-os/types.h>
 
 
 #if !defined(__ASSEMBLY__)
diff -r eb0fc71cfc72 -r 400e5d4877ca 
extras/mini-os/include/ia64/hypercall-ia64.h
--- a/extras/mini-os/include/ia64/hypercall-ia64.h      Tue Jul 08 11:41:43 
2008 +0900
+++ b/extras/mini-os/include/ia64/hypercall-ia64.h      Fri Jul 18 12:12:41 
2008 +0900
@@ -34,8 +34,8 @@
 #ifndef __HYPERCALL_H__
 #define __HYPERCALL_H__
 
-#include "lib.h"       /* memcpy() */
-#include "errno.h"     /* ENOSYS() */
+#include <mini-os/lib.h>       /* memcpy() */
+#include <mini-os/errno.h>     /* ENOSYS() */
 #include <xen/event_channel.h>
 #include <xen/sched.h>
 #include <xen/version.h>
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/ia64/os.h
--- a/extras/mini-os/include/ia64/os.h  Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/include/ia64/os.h  Fri Jul 18 12:12:41 2008 +0900
@@ -27,15 +27,15 @@
 
 #if !defined(__ASSEMBLY__)
 
-#include "types.h"
+#include <mini-os/types.h>
 #include "endian.h"
 #include "ia64_cpu.h"
 #include "atomic.h"
 #include "efi.h"
 #include "sal.h"
 #include "pal.h"
-#include "hypervisor.h"
-#include <kernel.h>
+#include <mini-os/hypervisor.h>
+#include <mini-os/kernel.h>
 
 
 typedef uint64_t paddr_t;              /* Physical address. */
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/lib.h
--- a/extras/mini-os/include/lib.h      Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/include/lib.h      Fri Jul 18 12:12:41 2008 +0900
@@ -99,13 +99,13 @@ char * strcat(char * dest, const char * 
 char * strcat(char * dest, const char * src);
 char  *strdup(const char *s);
 #endif
-#include <console.h>
+#include <mini-os/console.h>
 
 #define RAND_MIX 2654435769U
 
 int rand(void);
 
-#include <xenbus.h>
+#include <mini-os/xenbus.h>
 
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/linux/types.h
--- a/extras/mini-os/include/linux/types.h      Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/include/linux/types.h      Fri Jul 18 12:12:41 2008 +0900
@@ -1,5 +1,5 @@
 #ifndef _LINUX_TYPES_H_
 #define _LINUX_TYPES_H_
-#include <types.h>
+#include <mini-os/types.h>
 typedef u64 __u64;
 #endif /* _LINUX_TYPES_H_ */
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/mm.h
--- a/extras/mini-os/include/mm.h       Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/include/mm.h       Fri Jul 18 12:12:41 2008 +0900
@@ -35,10 +35,10 @@
 #error "Unsupported architecture"
 #endif
 
-#include <lib.h>
+#include <mini-os/lib.h>
 
-#include <arch_limits.h>
-#include <arch_mm.h>
+#include <mini-os/arch_limits.h>
+#include <mini-os/arch_mm.h>
 
 #define STACK_SIZE_PAGE_ORDER __STACK_SIZE_PAGE_ORDER
 #define STACK_SIZE __STACK_SIZE
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/netfront.h
--- a/extras/mini-os/include/netfront.h Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/include/netfront.h Fri Jul 18 12:12:41 2008 +0900
@@ -1,4 +1,4 @@
-#include <wait.h>
+#include <mini-os/wait.h>
 #ifdef HAVE_LWIP
 #include <lwip/netif.h>
 #endif
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/pcifront.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/extras/mini-os/include/pcifront.h Fri Jul 18 12:12:41 2008 +0900
@@ -0,0 +1,28 @@
+#include <mini-os/types.h>
+#include <xen/io/pciif.h>
+struct pcifront_dev;
+struct pcifront_dev *init_pcifront(char *nodename);
+void pcifront_op(struct pcifront_dev *dev, struct xen_pci_op *op);
+void pcifront_scan(struct pcifront_dev *dev, void (*fun)(unsigned int domain, 
unsigned int bus, unsigned slot, unsigned int fun));
+int pcifront_conf_read(struct pcifront_dev *dev,
+                       unsigned int dom,
+                       unsigned int bus, unsigned int slot, unsigned long fun,
+                       unsigned int off, unsigned int size, unsigned int *val);
+int pcifront_conf_write(struct pcifront_dev *dev,
+                        unsigned int dom,
+                        unsigned int bus, unsigned int slot, unsigned long fun,
+                        unsigned int off, unsigned int size, unsigned int val);
+int pcifront_enable_msi(struct pcifront_dev *dev,
+                        unsigned int dom,
+                        unsigned int bus, unsigned int slot, unsigned long 
fun);
+int pcifront_disable_msi(struct pcifront_dev *dev,
+                         unsigned int dom,
+                         unsigned int bus, unsigned int slot, unsigned long 
fun);
+int pcifront_enable_msix(struct pcifront_dev *dev,
+                         unsigned int dom,
+                         unsigned int bus, unsigned int slot, unsigned long 
fun,
+                         struct xen_msix_entry *entries, int n);
+int pcifront_disable_msix(struct pcifront_dev *dev,
+                          unsigned int dom,
+                          unsigned int bus, unsigned int slot, unsigned long 
fun);
+void shutdown_pcifront(struct pcifront_dev *dev);
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/posix/fcntl.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/extras/mini-os/include/posix/fcntl.h      Fri Jul 18 12:12:41 2008 +0900
@@ -0,0 +1,11 @@
+#ifndef _POSIX_FCNTL_H
+#define _POSIX_FCNTL_H
+
+#include_next <fcntl.h>
+
+#define F_ULOCK 0
+#define F_LOCK  1
+#define F_TLOCK 2
+#define F_TEST  3
+
+#endif /* _POSIX_FCNTL_H */
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/posix/limits.h
--- a/extras/mini-os/include/posix/limits.h     Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/include/posix/limits.h     Fri Jul 18 12:12:41 2008 +0900
@@ -1,9 +1,46 @@
 #ifndef _POSIX_LIMITS_H
 #define _POSIX_LIMITS_H
 
-#include_next <limits.h>
-#include <arch_limits.h>
+#include <mini-os/arch_limits.h>
+
+#define CHAR_BIT        8
+
+#define SCHAR_MAX       0x7f
+#define SCHAR_MIN       (-SCHAR_MAX-1)
+#define UCHAR_MAX       0xff
+
+#ifdef __CHAR_UNSIGNED__
+# define CHAR_MIN       0
+# define CHAR_MAX       UCHAR_MAX
+#else
+# define CHAR_MIN       SCHAR_MIN
+# define CHAR_MAX       SCHAR_MAX
+#endif
+
+#define INT_MAX         0x7fffffff
+#define INT_MIN         (-INT_MAX-1)
+#define UINT_MAX        0xffffffff
+
+#define SHRT_MAX        0x7fff
+
+#if defined(__x86_64__) || defined(__ia64__)
+# define LONG_MAX       0x7fffffffffffffffL
+# define ULONG_MAX      0xffffffffffffffffUL
+#else
+# define LONG_MAX       0x7fffffffL
+# define ULONG_MAX      0xffffffffUL
+#endif
+#define LONG_MIN        (-LONG_MAX-1L)
+
+#define LLONG_MAX       0x7fffffffffffffffLL
+#define LLONG_MIN       (-LLONG_MAX-1LL)
+#define ULLONG_MAX      0xffffffffffffffffULL
+
+#define LONG_LONG_MIN   LLONG_MIN
+#define LONG_LONG_MAX   LLONG_MAX
+#define ULONG_LONG_MAX  ULLONG_MAX
 
 #define PATH_MAX __PAGE_SIZE
+#define PAGE_SIZE __PAGE_SIZE
 
 #endif /* _POSIX_LIMITS_H */
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/posix/sys/mman.h
--- a/extras/mini-os/include/posix/sys/mman.h   Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/include/posix/sys/mman.h   Fri Jul 18 12:12:41 2008 +0900
@@ -9,6 +9,9 @@
 #define MAP_PRIVATE    0x02
 #define MAP_ANON       0x20
 
+/* Pages are always resident anyway */
+#define MAP_LOCKED     0x0
+
 #define MAP_FAILED     ((void*)0)
 
 void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t 
offset);
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/posix/sys/select.h
--- a/extras/mini-os/include/posix/sys/select.h Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/include/posix/sys/select.h Fri Jul 18 12:12:41 2008 +0900
@@ -2,6 +2,7 @@
 #define _POSIX_SELECT_H
 
 #include <sys/time.h>
+#include <lwip/sockets.h>
 int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, 
struct timeval *timeout);
 
 #endif /* _POSIX_SELECT_H */
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/posix/unistd.h
--- a/extras/mini-os/include/posix/unistd.h     Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/include/posix/unistd.h     Fri Jul 18 12:12:41 2008 +0900
@@ -2,11 +2,8 @@
 #define _POSIX_UNISTD_H
 
 #include_next <unistd.h>
-#include <sys/select.h>
-#include <arch_limits.h>
 
-#define getpagesize() __PAGE_SIZE
-
+size_t getpagesize(void);
 int ftruncate(int fd, off_t length);
 
 #endif /* _POSIX_UNISTD_H */
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/sched.h
--- a/extras/mini-os/include/sched.h    Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/include/sched.h    Fri Jul 18 12:12:41 2008 +0900
@@ -1,9 +1,12 @@
 #ifndef __SCHED_H__
 #define __SCHED_H__
 
-#include <list.h>
-#include <time.h>
-#include <arch_sched.h>
+#include <mini-os/list.h>
+#include <mini-os/time.h>
+#include <mini-os/arch_sched.h>
+#ifdef HAVE_LIBC
+#include <sys/reent.h>
+#endif
 
 struct thread
 {
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/semaphore.h
--- a/extras/mini-os/include/semaphore.h        Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/include/semaphore.h        Fri Jul 18 12:12:41 2008 +0900
@@ -1,8 +1,8 @@
 #ifndef _SEMAPHORE_H_
 #define _SEMAPHORE_H_
 
-#include <wait.h>
-#include <spinlock.h>
+#include <mini-os/wait.h>
+#include <mini-os/spinlock.h>
 
 /*
  * Implementation of semaphore in Mini-os is simple, because 
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/spinlock.h
--- a/extras/mini-os/include/spinlock.h Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/include/spinlock.h Fri Jul 18 12:12:41 2008 +0900
@@ -1,7 +1,7 @@
 #ifndef __ASM_SPINLOCK_H
 #define __ASM_SPINLOCK_H
 
-#include <lib.h>
+#include <mini-os/lib.h>
 
 /*
  * Your basic SMP spinlocks, allowing only a single CPU anywhere
@@ -12,7 +12,7 @@ typedef struct {
 } spinlock_t;
 
 
-#include "arch_spinlock.h"
+#include <mini-os/arch_spinlock.h>
 
 
 #define SPINLOCK_MAGIC 0xdead4ead
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/sys/lock.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/extras/mini-os/include/sys/lock.h Fri Jul 18 12:12:41 2008 +0900
@@ -0,0 +1,52 @@
+#ifndef _MINIOS_SYS_LOCK_H_
+#define _MINIOS_SYS_LOCK_H_
+
+#ifdef HAVE_LIBC
+
+/* Due to inclusion loop, we can not include sched.h, so have to hide things */
+
+#include <mini-os/waittypes.h>
+
+
+typedef struct {
+        int busy;
+        struct wait_queue_head wait;
+} _LOCK_T;
+
+#define __LOCK_INIT(class,lock) \
+    class _LOCK_T lock = { .wait = __WAIT_QUEUE_HEAD_INITIALIZER(lock.wait) }
+int ___lock_init(_LOCK_T *lock);
+int ___lock_acquire(_LOCK_T *lock);
+int ___lock_try_acquire(_LOCK_T *lock);
+int ___lock_release(_LOCK_T *lock);
+int ___lock_close(_LOCK_T *lock);
+#define __lock_init(__lock) ___lock_init(&__lock)
+#define __lock_acquire(__lock) ___lock_acquire(&__lock)
+#define __lock_release(__lock) ___lock_release(&__lock)
+#define __lock_try_acquire(__lock) ___lock_try_acquire(&__lock)
+#define __lock_close(__lock) 0
+
+
+typedef struct {
+    struct thread *owner;
+    int count;
+    struct wait_queue_head wait;
+} _LOCK_RECURSIVE_T;
+
+#define __LOCK_INIT_RECURSIVE(class, lock) \
+    class _LOCK_RECURSIVE_T lock = { .wait = 
__WAIT_QUEUE_HEAD_INITIALIZER((lock).wait) }
+
+int ___lock_init_recursive(_LOCK_RECURSIVE_T *lock);
+int ___lock_acquire_recursive(_LOCK_RECURSIVE_T *lock);
+int ___lock_try_acquire_recursive(_LOCK_RECURSIVE_T *lock);
+int ___lock_release_recursive(_LOCK_RECURSIVE_T *lock);
+int ___lock_close_recursive(_LOCK_RECURSIVE_T *lock);
+#define __lock_init_recursive(__lock) ___lock_init_recursive(&__lock)
+#define __lock_acquire_recursive(__lock) ___lock_acquire_recursive(&__lock)
+#define __lock_release_recursive(__lock) ___lock_release_recursive(&__lock)
+#define __lock_try_acquire_recursive(__lock) 
___lock_try_acquire_recursive(&__lock)
+#define __lock_close_recursive(__lock) 0
+
+#endif
+
+#endif /* _MINIOS_SYS_LOCK_H_ */
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/time.h
--- a/extras/mini-os/include/time.h     Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/include/time.h     Fri Jul 18 12:12:41 2008 +0900
@@ -19,7 +19,7 @@
 
 #ifndef _MINIOS_TIME_H_
 #define _MINIOS_TIME_H_
-#include <types.h>
+#include <mini-os/types.h>
 
 /*
  * System Time
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/types.h
--- a/extras/mini-os/include/types.h    Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/include/types.h    Fri Jul 18 12:12:41 2008 +0900
@@ -36,9 +36,11 @@ typedef unsigned long       u64;
 #endif
 
 /* FreeBSD compat types */
+#ifndef HAVE_LIBC
 typedef unsigned char       u_char;
 typedef unsigned int        u_int;
 typedef unsigned long       u_long;
+#endif
 #ifdef __i386__
 typedef long long           quad_t;
 typedef unsigned long long  u_quad_t;
@@ -79,11 +81,13 @@ typedef u64 uint64_t, uintmax_t;
 typedef u64 uint64_t, uintmax_t;
 typedef s64 int64_t, intmax_t;
 typedef u64 off_t;
+#endif
 
+typedef intptr_t            ptrdiff_t;
 
-#define INT_MAX         ((int)(~0U>>1))
-#define UINT_MAX            (~0U)
 
+#ifndef HAVE_LIBC
 typedef long ssize_t;
 #endif
+
 #endif /* _TYPES_H_ */
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/wait.h
--- a/extras/mini-os/include/wait.h     Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/include/wait.h     Fri Jul 18 12:12:41 2008 +0900
@@ -1,30 +1,9 @@
 #ifndef __WAIT_H__
 #define __WAIT_H__
 
-#include <sched.h>
-#include <list.h>
-#include <lib.h>
-#include <os.h>
-
-struct wait_queue
-{
-    struct thread *thread;
-    struct list_head thread_list;
-};
-
-struct wait_queue_head
-{
-    /* TODO - lock required? */
-    struct list_head thread_list;
-};
-
-#define DECLARE_WAIT_QUEUE_HEAD(name) \
-   struct wait_queue_head name =     \
-        { .thread_list = { &(name).thread_list, &(name).thread_list} }
-
-#define __WAIT_QUEUE_HEAD_INITIALIZER(name) {                           \
-    .thread_list      = { &(name).thread_list, &(name).thread_list } }
-
+#include <mini-os/sched.h>
+#include <mini-os/os.h>
+#include <mini-os/waittypes.h>
 
 #define DEFINE_WAIT(name)                               \
 struct wait_queue name = {                              \
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/waittypes.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/extras/mini-os/include/waittypes.h        Fri Jul 18 12:12:41 2008 +0900
@@ -0,0 +1,26 @@
+#ifndef __WAITTYPE_H__
+#define __WAITTYPE_H__
+
+#include <mini-os/list.h>
+
+struct thread;
+struct wait_queue
+{
+    struct thread *thread;
+    struct list_head thread_list;
+};
+
+struct wait_queue_head
+{
+    /* TODO - lock required? */
+    struct list_head thread_list;
+};
+
+#define DECLARE_WAIT_QUEUE_HEAD(name) \
+   struct wait_queue_head name =     \
+        { .thread_list = { &(name).thread_list, &(name).thread_list} }
+
+#define __WAIT_QUEUE_HEAD_INITIALIZER(name) {                           \
+    .thread_list      = { &(name).thread_list, &(name).thread_list } }
+
+#endif
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/x86/arch_sched.h
--- a/extras/mini-os/include/x86/arch_sched.h   Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/include/x86/arch_sched.h   Fri Jul 18 12:12:41 2008 +0900
@@ -2,7 +2,7 @@
 #ifndef __ARCH_SCHED_H__
 #define __ARCH_SCHED_H__
 
-#include <arch_limits.h>
+#include "arch_limits.h"
 
 static inline struct thread* get_current(void)
 {
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/x86/arch_spinlock.h
--- a/extras/mini-os/include/x86/arch_spinlock.h        Tue Jul 08 11:41:43 
2008 +0900
+++ b/extras/mini-os/include/x86/arch_spinlock.h        Fri Jul 18 12:12:41 
2008 +0900
@@ -3,11 +3,11 @@
 #ifndef __ARCH_ASM_SPINLOCK_H
 #define __ARCH_ASM_SPINLOCK_H
 
-#include <lib.h>
+#include <mini-os/lib.h>
 #include "os.h"
 
 
-#define ARCH_SPIN_LOCK_UNLOCKED (spinlock_t) { 1 }
+#define ARCH_SPIN_LOCK_UNLOCKED { 1 }
 
 /*
  * Simple spin lock operations.  There are two variants, one clears IRQ's
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/x86/os.h
--- a/extras/mini-os/include/x86/os.h   Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/include/x86/os.h   Fri Jul 18 12:12:41 2008 +0900
@@ -16,9 +16,9 @@
 
 
 #ifndef __ASSEMBLY__
-#include <types.h>
-#include <hypervisor.h>
-#include <kernel.h>
+#include <mini-os/types.h>
+#include <mini-os/hypervisor.h>
+#include <mini-os/kernel.h>
 
 #define USED    __attribute__ ((used))
 
diff -r eb0fc71cfc72 -r 400e5d4877ca 
extras/mini-os/include/x86/x86_32/hypercall-x86_32.h
--- a/extras/mini-os/include/x86/x86_32/hypercall-x86_32.h      Tue Jul 08 
11:41:43 2008 +0900
+++ b/extras/mini-os/include/x86/x86_32/hypercall-x86_32.h      Fri Jul 18 
12:12:41 2008 +0900
@@ -33,7 +33,7 @@
 #include <xen/xen.h>
 #include <xen/sched.h>
 #include <xen/nmi.h>
-#include <mm.h>
+#include <mini-os/mm.h>
 
 #define __STR(x) #x
 #define STR(x) __STR(x)
diff -r eb0fc71cfc72 -r 400e5d4877ca 
extras/mini-os/include/x86/x86_64/hypercall-x86_64.h
--- a/extras/mini-os/include/x86/x86_64/hypercall-x86_64.h      Tue Jul 08 
11:41:43 2008 +0900
+++ b/extras/mini-os/include/x86/x86_64/hypercall-x86_64.h      Fri Jul 18 
12:12:41 2008 +0900
@@ -36,7 +36,7 @@
 
 #include <xen/xen.h>
 #include <xen/sched.h>
-#include <mm.h>
+#include <mini-os/mm.h>
 
 #define __STR(x) #x
 #define STR(x) __STR(x)
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/include/xmalloc.h
--- a/extras/mini-os/include/xmalloc.h  Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/include/xmalloc.h  Fri Jul 18 12:12:41 2008 +0900
@@ -10,6 +10,8 @@
 #define xfree(ptr) free(ptr)
 
 #else
+
+#include <limits.h>
 
 #define DEFAULT_ALIGN (sizeof(unsigned long))
 #define malloc(size) _xmalloc(size, DEFAULT_ALIGN)
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/kernel.c
--- a/extras/mini-os/kernel.c   Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/kernel.c   Fri Jul 18 12:12:41 2008 +0900
@@ -40,6 +40,7 @@
 #include <netfront.h>
 #include <blkfront.h>
 #include <fbfront.h>
+#include <pcifront.h>
 #include <fs.h>
 #include <xmalloc.h>
 #include <fcntl.h>
@@ -431,6 +432,29 @@ static void kbdfront_thread(void *p)
     }
 }
 
+static struct pcifront_dev *pci_dev;
+
+static void pcifront_thread(void *p)
+{
+    void print(unsigned int domain, unsigned int bus, unsigned int slot, 
unsigned int fun)
+    {
+        unsigned int vendor, device, rev, class;
+
+        pcifront_conf_read(pci_dev, domain, bus, slot, fun, 0x00, 2, &vendor);
+        pcifront_conf_read(pci_dev, domain, bus, slot, fun, 0x02, 2, &device);
+        pcifront_conf_read(pci_dev, domain, bus, slot, fun, 0x08, 1, &rev);
+        pcifront_conf_read(pci_dev, domain, bus, slot, fun, 0x0a, 2, &class);
+
+        printk("%04x:%02x:%02x.%02x %04x: %04x:%04x (rev %02x)\n", domain, 
bus, slot, fun, class, vendor, device, rev);
+    }
+
+    pci_dev = init_pcifront(NULL);
+    if (!pci_dev)
+        return;
+    printk("PCI devices:\n");
+    pcifront_scan(pci_dev, print);
+}
+
 static void fs_thread(void *p)
 {
     init_fs_frontend();
@@ -446,6 +470,7 @@ __attribute__((weak)) int app_main(start
     create_thread("blkfront", blkfront_thread, si);
     create_thread("fbfront", fbfront_thread, si);
     create_thread("kbdfront", kbdfront_thread, si);
+    create_thread("pcifront", pcifront_thread, si);
     create_thread("fs-frontend", fs_thread, si);
     return 0;
 }
@@ -524,6 +549,9 @@ void stop_kernel(void)
     if (kbd_dev)
         shutdown_kbdfront(kbd_dev);
 
+    if (pci_dev)
+        shutdown_pcifront(pci_dev);
+
     /* TODO: fs import */
 
     local_irq_disable();
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/lib/ctype.c
--- a/extras/mini-os/lib/ctype.c        Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/lib/ctype.c        Fri Jul 18 12:12:41 2008 +0900
@@ -1,3 +1,4 @@
+#ifndef HAVE_LIBC
 #include <ctype.h>
 
 unsigned char _ctype[] = {
@@ -25,3 +26,4 @@ _U,_U,_U,_U,_U,_U,_U,_P,_U,_U,_U,_U,_U,_
 _U,_U,_U,_U,_U,_U,_U,_P,_U,_U,_U,_U,_U,_U,_U,_L,       /* 208-223 */
 _L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,       /* 224-239 */
 _L,_L,_L,_L,_L,_L,_L,_P,_L,_L,_L,_L,_L,_L,_L,_L};      /* 240-255 */
+#endif
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/lib/printf.c
--- a/extras/mini-os/lib/printf.c       Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/lib/printf.c       Fri Jul 18 12:12:41 2008 +0900
@@ -62,6 +62,7 @@
 #include <lib.h>
 #include <mm.h>
 #include <ctype.h>
+#include <limits.h>
 
 /**
  * simple_strtoul - convert a string to an unsigned long
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/lib/sys.c
--- a/extras/mini-os/lib/sys.c  Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/lib/sys.c  Fri Jul 18 12:12:41 2008 +0900
@@ -733,7 +733,7 @@ static int select_poll(int nfds, fd_set 
            FD_CLR(i, exceptfds);
            break;
        case FTYPE_CONSOLE:
-           if (FD_ISSET(i, writefds)) {
+           if (FD_ISSET(i, readfds)) {
                 if (xencons_ring_avail())
                    n++;
                else
@@ -1094,6 +1094,11 @@ int clock_gettime(clockid_t clk_id, stru
     return 0;
 }
 
+size_t getpagesize(void)
+{
+    return PAGE_SIZE;
+}
+
 void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t 
offset)
 {
     unsigned long n = (length + PAGE_SIZE - 1) / PAGE_SIZE;
@@ -1185,6 +1190,7 @@ void sparse(unsigned long data, size_t s
 /* Not supported by FS yet.  */
 unsupported_function_crash(link);
 unsupported_function(int, readlink, -1);
+unsupported_function_crash(umask);
 
 /* We could support that.  */
 unsupported_function_log(int, chdir, -1);
@@ -1207,6 +1213,18 @@ unsupported_function(int, sigaltstack, -
 unsupported_function(int, sigaltstack, -1);
 unsupported_function_crash(kill);
 
+/* Unsupported */
+unsupported_function_crash(pipe);
+unsupported_function_crash(fork);
+unsupported_function_crash(execv);
+unsupported_function_crash(execve);
+unsupported_function_crash(waitpid);
+unsupported_function_crash(wait);
+unsupported_function_crash(lockf);
+unsupported_function_crash(sysconf);
+unsupported_function(int, tcsetattr, -1);
+unsupported_function(int, tcgetattr, 0);
+
 /* Linuxish abi for the Caml runtime, don't support */
 unsupported_function_log(struct dirent *, readdir64, NULL);
 unsupported_function_log(int, getrusage, -1);
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/lib/xmalloc.c
--- a/extras/mini-os/lib/xmalloc.c      Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/lib/xmalloc.c      Fri Jul 18 12:12:41 2008 +0900
@@ -139,7 +139,7 @@ static void *xmalloc_whole_pages(size_t 
 
 void *_xmalloc(size_t size, size_t align)
 {
-    struct xmalloc_hdr *i, *hdr = NULL;
+    struct xmalloc_hdr *i, *tmp, *hdr = NULL;
     uintptr_t data_begin;
     size_t hdr_size;
     /* unsigned long flags; */
@@ -155,7 +155,7 @@ void *_xmalloc(size_t size, size_t align
 
     /* Search free list. */
     /* spin_lock_irqsave(&freelist_lock, flags); */
-    list_for_each_entry( i, &freelist, freelist )
+    list_for_each_entry_safe( i, tmp, &freelist, freelist )
     {
         data_begin = align_up((uintptr_t)i + hdr_size, align);
 
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/lock.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/extras/mini-os/lock.c     Fri Jul 18 12:12:41 2008 +0900
@@ -0,0 +1,111 @@
+/*
+ * locks for newlib
+ *
+ * Samuel Thibault <Samuel.Thibault@xxxxxxxxxxxxx>, July 20008
+ */
+
+#ifdef HAVE_LIBC
+
+#include <sys/lock.h>
+#include <sched.h>
+#include <wait.h>
+
+int ___lock_init(_LOCK_T *lock)
+{
+    lock->busy = 0;
+    init_waitqueue_head(&lock->wait);
+    return 0;
+}
+
+int ___lock_acquire(_LOCK_T *lock)
+{
+    unsigned long flags;
+    while(1) {
+        wait_event(lock->wait, !lock->busy);
+        local_irq_save(flags);
+        if (!lock->busy)
+            break;
+        local_irq_restore(flags);
+    }
+    lock->busy = 1;
+    local_irq_restore(flags);
+    return 0;
+}
+
+int ___lock_try_acquire(_LOCK_T *lock)
+{
+    unsigned long flags;
+    int ret = -1;
+    local_irq_save(flags);
+    if (!lock->busy) {
+        lock->busy = 1;
+        ret = 0;
+    }
+    local_irq_restore(flags);
+    return ret;
+}
+
+int ___lock_release(_LOCK_T *lock)
+{
+    unsigned long flags;
+    local_irq_save(flags);
+    lock->busy = 0;
+    wake_up(&lock->wait);
+    local_irq_restore(flags);
+    return 0;
+}
+
+
+int ___lock_init_recursive(_LOCK_RECURSIVE_T *lock)
+{
+    lock->owner = NULL;
+    init_waitqueue_head(&lock->wait);
+    return 0;
+}
+
+int ___lock_acquire_recursive(_LOCK_RECURSIVE_T *lock)
+{
+    unsigned long flags;
+    if (lock->owner != get_current()) {
+        while (1) {
+            wait_event(lock->wait, lock->owner == NULL);
+            local_irq_save(flags);
+            if (lock->owner == NULL)
+                break;
+            local_irq_restore(flags);
+        }
+        lock->owner = get_current();
+        local_irq_restore(flags);
+    }
+    lock->count++;
+    return 0;
+}
+
+int ___lock_try_acquire_recursive(_LOCK_RECURSIVE_T *lock)
+{
+    unsigned long flags;
+    int ret = -1;
+    local_irq_save(flags);
+    if (!lock->owner) {
+        ret = 0;
+        lock->owner = get_current();
+        lock->count++;
+    }
+    local_irq_restore(flags);
+    return ret;
+}
+
+int ___lock_release_recursive(_LOCK_RECURSIVE_T *lock)
+{
+    unsigned long flags;
+    BUG_ON(lock->owner != get_current());
+    if (--lock->count)
+        return 0;
+    local_irq_save(flags);
+    lock->owner = NULL;
+    wake_up(&lock->wait);
+    local_irq_restore(flags);
+    return 0;
+}
+
+#endif
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/lwip-net.c
--- a/extras/mini-os/lwip-net.c Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/lwip-net.c Fri Jul 18 12:12:41 2008 +0900
@@ -93,6 +93,9 @@ static err_t
 static err_t
 low_level_output(struct netif *netif, struct pbuf *p)
 {
+  if (!dev)
+    return ERR_OK;
+
 #ifdef ETH_PAD_SIZE
   pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
 #endif
@@ -342,7 +345,7 @@ void start_networking(void)
   struct ip_addr ipaddr = { htonl(IF_IPADDR) };
   struct ip_addr netmask = { htonl(IF_NETMASK) };
   struct ip_addr gw = { 0 };
-  char *ip;
+  char *ip = NULL;
 
   tprintk("Waiting for network.\n");
 
@@ -380,5 +383,6 @@ void start_networking(void)
 /* Shut down the network */
 void stop_networking(void)
 {
-  shutdown_netfront(dev);
-}
+  if (dev)
+    shutdown_netfront(dev);
+}
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/main.c
--- a/extras/mini-os/main.c     Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/main.c     Fri Jul 18 12:12:41 2008 +0900
@@ -52,6 +52,7 @@ static void call_main(void *p)
 #ifdef CONFIG_QEMU
     char *vm;
     char path[128];
+    int domid;
 #endif
     int i;
 
@@ -74,7 +75,6 @@ static void call_main(void *p)
     }
 
     /* Fetch argc, argv from XenStore */
-    int domid;
     domid = xenbus_read_integer("target");
     if (domid == -1) {
         printk("Couldn't read target\n");
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/minios.mk
--- a/extras/mini-os/minios.mk  Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/minios.mk  Fri Jul 18 12:12:41 2008 +0900
@@ -6,13 +6,14 @@ debug = y
 
 # Define some default flags.
 # NB. '-Wcast-qual' is nasty, so I omitted it.
-DEF_CFLAGS += -fno-builtin -Wall -Werror -Wredundant-decls -Wno-format
+DEF_CFLAGS += -fno-builtin -Wall -Werror -Wredundant-decls -Wno-format 
-Wno-redundant-decls
 DEF_CFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
+DEF_CFLAGS += $(call cc-option,$(CC),-fgnu89-inline)
 DEF_CFLAGS += -Wstrict-prototypes -Wnested-externs -Wpointer-arith -Winline
 DEF_CPPFLAGS += -D__XEN_INTERFACE_VERSION__=$(XEN_INTERFACE_VERSION)
 
-DEF_ASFLAGS = -D__ASSEMBLY__
-DEF_LDFLAGS =
+DEF_ASFLAGS += -D__ASSEMBLY__
+DEF_LDFLAGS +=
 
 ifeq ($(debug),y)
 DEF_CFLAGS += -g
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/mm.c
--- a/extras/mini-os/mm.c       Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/mm.c       Fri Jul 18 12:12:41 2008 +0900
@@ -361,6 +361,7 @@ void free_pages(void *pointer, int order
    
 }
 
+#ifndef __ia64__
 int free_physical_pages(xen_pfn_t *mfns, int n)
 {
     struct xen_memory_reservation reservation;
@@ -371,6 +372,7 @@ int free_physical_pages(xen_pfn_t *mfns,
     reservation.domid = DOMID_SELF;
     return HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation);
 }
+#endif
 
 #ifdef HAVE_LIBC
 void *sbrk(ptrdiff_t increment)
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/netfront.c
--- a/extras/mini-os/netfront.c Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/netfront.c Fri Jul 18 12:12:41 2008 +0900
@@ -95,8 +95,9 @@ static inline int xennet_rxidx(RING_IDX 
 
 void network_rx(struct netfront_dev *dev)
 {
-    RING_IDX rp,cons;
+    RING_IDX rp,cons,req_prod;
     struct netif_rx_response *rx;
+    int nr_consumed, some, more, i, notify;
 
 
 moretodo:
@@ -104,12 +105,13 @@ moretodo:
     rmb(); /* Ensure we see queued responses up to 'rp'. */
     cons = dev->rx.rsp_cons;
 
-    int nr_consumed=0;
-    int some = 0;
+    nr_consumed = 0;
+    some = 0;
     while ((cons != rp) && !some)
     {
         struct net_buffer* buf;
         unsigned char* page;
+        int id;
 
         rx = RING_GET_RESPONSE(&dev->rx, cons);
 
@@ -122,7 +124,7 @@ moretodo:
 
         if (rx->status == NETIF_RSP_NULL) continue;
 
-        int id = rx->id;
+        id = rx->id;
         BUG_ON(id >= NET_TX_RING_SIZE);
 
         buf = &dev->rx_buffers[id];
@@ -151,19 +153,15 @@ moretodo:
     }
     dev->rx.rsp_cons=cons;
 
-    int more;
     RING_FINAL_CHECK_FOR_RESPONSES(&dev->rx,more);
     if(more && !some) goto moretodo;
 
-    RING_IDX req_prod = dev->rx.req_prod_pvt;
-
-    int i;
-    netif_rx_request_t *req;
+    req_prod = dev->rx.req_prod_pvt;
 
     for(i=0; i<nr_consumed; i++)
     {
         int id = xennet_rxidx(req_prod + i);
-        req = RING_GET_REQUEST(&dev->rx, req_prod + i);
+        netif_rx_request_t *req = RING_GET_REQUEST(&dev->rx, req_prod + i);
         struct net_buffer* buf = &dev->rx_buffers[id];
         void* page = buf->page;
 
@@ -178,7 +176,6 @@ moretodo:
 
     dev->rx.req_prod_pvt = req_prod + i;
     
-    int notify;
     RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&dev->rx, notify);
     if (notify)
         notify_remote_via_evtchn(dev->evtchn);
@@ -199,6 +196,7 @@ void network_tx_buf_gc(struct netfront_d
         for (cons = dev->tx.rsp_cons; cons != prod; cons++) 
         {
             struct netif_tx_response *txrsp;
+            struct net_buffer *buf;
 
             txrsp = RING_GET_RESPONSE(&dev->tx, cons);
             if (txrsp->status == NETIF_RSP_NULL)
@@ -209,7 +207,7 @@ void network_tx_buf_gc(struct netfront_d
 
             id  = txrsp->id;
             BUG_ON(id >= NET_TX_RING_SIZE);
-            struct net_buffer* buf = &dev->tx_buffers[id];
+            buf = &dev->tx_buffers[id];
             gnttab_end_access(buf->gref);
             buf->gref=GRANT_INVALID_REF;
 
@@ -298,7 +296,7 @@ static void free_netfront(struct netfron
     free(dev);
 }
 
-struct netfront_dev *init_netfront(char *nodename, void 
(*thenetif_rx)(unsigned char* data, int len), unsigned char rawmac[6], char 
**ip)
+struct netfront_dev *init_netfront(char *_nodename, void 
(*thenetif_rx)(unsigned char* data, int len), unsigned char rawmac[6], char 
**ip)
 {
     xenbus_transaction_t xbt;
     char* err;
@@ -308,11 +306,9 @@ struct netfront_dev *init_netfront(char 
     int retry=0;
     int i;
     char* msg;
+    char* nodename = _nodename ? _nodename : "device/vif/0";
 
     struct netfront_dev *dev;
-
-    if (!nodename)
-       nodename = "device/vif/0";
 
     char path[strlen(nodename) + 1 + 10 + 1];
 
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/pcifront.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/extras/mini-os/pcifront.c Fri Jul 18 12:12:41 2008 +0900
@@ -0,0 +1,364 @@
+/* Minimal PCI driver for Mini-OS. 
+ * Copyright (c) 2007-2008 Samuel Thibault.
+ * Based on blkfront.c.
+ */
+
+#include <os.h>
+#include <xenbus.h>
+#include <events.h>
+#include <errno.h>
+#include <gnttab.h>
+#include <xmalloc.h>
+#include <wait.h>
+#include <pcifront.h>
+
+#define PCI_DEVFN(slot, func) ((((slot) & 0x1f) << 3) | ((func) & 0x07))
+
+DECLARE_WAIT_QUEUE_HEAD(pcifront_queue);
+
+struct pcifront_dev {
+    domid_t dom;
+
+    struct xen_pci_sharedinfo *info;
+    grant_ref_t info_ref;
+    evtchn_port_t evtchn;
+
+    char *nodename;
+    char *backend;
+
+    xenbus_event_queue events;
+};
+
+void pcifront_handler(evtchn_port_t port, struct pt_regs *regs, void *data)
+{
+    wake_up(&pcifront_queue);
+}
+
+static void free_pcifront(struct pcifront_dev *dev)
+{
+    mask_evtchn(dev->evtchn);
+
+    free(dev->backend);
+
+    gnttab_end_access(dev->info_ref);
+    free_page(dev->info);
+
+    unbind_evtchn(dev->evtchn);
+
+    free(dev->nodename);
+    free(dev);
+}
+
+struct pcifront_dev *init_pcifront(char *_nodename)
+{
+    xenbus_transaction_t xbt;
+    char* err;
+    char* message=NULL;
+    int retry=0;
+    char* msg;
+    char* nodename = _nodename ? _nodename : "device/pci/0";
+
+    struct pcifront_dev *dev;
+
+    char path[strlen(nodename) + 1 + 10 + 1];
+
+    printk("******************* PCIFRONT for %s **********\n\n\n", nodename);
+
+    dev = malloc(sizeof(*dev));
+    memset(dev, 0, sizeof(*dev));
+    dev->nodename = strdup(nodename);
+
+    snprintf(path, sizeof(path), "%s/backend-id", nodename);
+    dev->dom = xenbus_read_integer(path); 
+    evtchn_alloc_unbound(dev->dom, pcifront_handler, dev, &dev->evtchn);
+
+    dev->info = (struct xen_pci_sharedinfo*) alloc_page();
+    memset(dev->info,0,PAGE_SIZE);
+
+    dev->info_ref = gnttab_grant_access(dev->dom,virt_to_mfn(dev->info),0);
+
+    dev->events = NULL;
+
+again:
+    err = xenbus_transaction_start(&xbt);
+    if (err) {
+        printk("starting transaction\n");
+    }
+
+    err = xenbus_printf(xbt, nodename, "pci-op-ref","%u",
+                dev->info_ref);
+    if (err) {
+        message = "writing pci-op-ref";
+        goto abort_transaction;
+    }
+    err = xenbus_printf(xbt, nodename,
+                "event-channel", "%u", dev->evtchn);
+    if (err) {
+        message = "writing event-channel";
+        goto abort_transaction;
+    }
+    err = xenbus_printf(xbt, nodename,
+                "magic", XEN_PCI_MAGIC);
+    if (err) {
+        message = "writing magic";
+        goto abort_transaction;
+    }
+
+    err = xenbus_printf(xbt, nodename, "state", "%u",
+            3); /* initialised */
+
+
+    err = xenbus_transaction_end(xbt, 0, &retry);
+    if (retry) {
+            goto again;
+        printk("completing transaction\n");
+    }
+
+    goto done;
+
+abort_transaction:
+    xenbus_transaction_end(xbt, 1, &retry);
+    goto error;
+
+done:
+
+    snprintf(path, sizeof(path), "%s/backend", nodename);
+    msg = xenbus_read(XBT_NIL, path, &dev->backend);
+    if (msg) {
+        printk("Error %s when reading the backend path %s\n", msg, path);
+        goto error;
+    }
+
+    printk("backend at %s\n", dev->backend);
+
+    {
+        char path[strlen(dev->backend) + 1 + 5 + 1];
+        snprintf(path, sizeof(path), "%s/state", dev->backend);
+
+        xenbus_watch_path_token(XBT_NIL, path, path, &dev->events);
+
+        xenbus_wait_for_value(path, "4", &dev->events);
+
+        xenbus_printf(xbt, nodename, "state", "%u", 4); /* connected */
+    }
+    unmask_evtchn(dev->evtchn);
+
+    printk("**************************\n");
+
+    return dev;
+
+error:
+    free_pcifront(dev);
+    return NULL;
+}
+
+void pcifront_scan(struct pcifront_dev *dev, void (*func)(unsigned int domain, 
unsigned int bus, unsigned slot, unsigned int fun))
+{
+    char path[strlen(dev->backend) + 1 + 5 + 10 + 1];
+    int i, n;
+    char *s, *msg;
+    unsigned int domain, bus, slot, fun;
+
+    snprintf(path, sizeof(path), "%s/num_devs", dev->backend);
+    n = xenbus_read_integer(path);
+
+    for (i = 0; i < n; i++) {
+        snprintf(path, sizeof(path), "%s/vdev-%d", dev->backend, i);
+        msg = xenbus_read(XBT_NIL, path, &s);
+        if (msg) {
+            printk("Error %s when reading the PCI root name at %s\n", path);
+            continue;
+        }
+
+        if (sscanf(s, "%x:%x:%x.%x", &domain, &bus, &slot, &fun) != 4) {
+            printk("\"%s\" does not look like a PCI device address\n", s);
+            free(s);
+            continue;
+        }
+        free(s);
+
+        func(domain, bus, slot, fun);
+    }
+}
+
+void shutdown_pcifront(struct pcifront_dev *dev)
+{
+    char* err;
+    char *nodename = dev->nodename;
+
+    char path[strlen(dev->backend) + 1 + 5 + 1];
+
+    printk("close pci: backend at %s\n",dev->backend);
+
+    snprintf(path, sizeof(path), "%s/state", dev->backend);
+    err = xenbus_printf(XBT_NIL, nodename, "state", "%u", 5); /* closing */
+    xenbus_wait_for_value(path, "5", &dev->events);
+
+    err = xenbus_printf(XBT_NIL, nodename, "state", "%u", 6);
+    xenbus_wait_for_value(path, "6", &dev->events);
+
+    err = xenbus_printf(XBT_NIL, nodename, "state", "%u", 1);
+    xenbus_wait_for_value(path, "2", &dev->events);
+
+    xenbus_unwatch_path(XBT_NIL, path);
+
+    snprintf(path, sizeof(path), "%s/info-ref", nodename);
+    xenbus_rm(XBT_NIL, path);
+    snprintf(path, sizeof(path), "%s/event-channel", nodename);
+    xenbus_rm(XBT_NIL, path);
+
+    free_pcifront(dev);
+}
+
+
+void pcifront_op(struct pcifront_dev *dev, struct xen_pci_op *op)
+{
+    dev->info->op = *op;
+    /* Make sure info is written before the flag */
+    wmb();
+    set_bit(_XEN_PCIF_active, (void*) &dev->info->flags);
+    notify_remote_via_evtchn(dev->evtchn);
+
+    wait_event(pcifront_queue, !test_bit(_XEN_PCIF_active, (void*) 
&dev->info->flags));
+
+    /* Make sure flag is read before info */
+    rmb();
+    *op = dev->info->op;
+}
+
+int pcifront_conf_read(struct pcifront_dev *dev,
+                       unsigned int dom,
+                       unsigned int bus, unsigned int slot, unsigned long fun,
+                       unsigned int off, unsigned int size, unsigned int *val)
+{
+    struct xen_pci_op op;
+
+    memset(&op, 0, sizeof(op));
+
+    op.cmd = XEN_PCI_OP_conf_read;
+    op.domain = dom;
+    op.bus = bus;
+    op.devfn = PCI_DEVFN(slot, fun);
+    op.offset = off;
+    op.size = size;
+
+    pcifront_op(dev, &op);
+
+    if (op.err)
+        return op.err;
+
+    *val = op.value;
+
+    return 0;
+}
+
+int pcifront_conf_write(struct pcifront_dev *dev,
+                        unsigned int dom,
+                        unsigned int bus, unsigned int slot, unsigned long fun,
+                        unsigned int off, unsigned int size, unsigned int val)
+{
+    struct xen_pci_op op;
+
+    memset(&op, 0, sizeof(op));
+
+    op.cmd = XEN_PCI_OP_conf_write;
+    op.domain = dom;
+    op.bus = bus;
+    op.devfn = PCI_DEVFN(slot, fun);
+    op.offset = off;
+    op.size = size;
+
+    op.value = val;
+
+    pcifront_op(dev, &op);
+
+    return op.err;
+}
+
+int pcifront_enable_msi(struct pcifront_dev *dev,
+                        unsigned int dom,
+                        unsigned int bus, unsigned int slot, unsigned long fun)
+{
+    struct xen_pci_op op;
+
+    memset(&op, 0, sizeof(op));
+
+    op.cmd = XEN_PCI_OP_enable_msi;
+    op.domain = dom;
+    op.bus = bus;
+    op.devfn = PCI_DEVFN(slot, fun);
+
+    pcifront_op(dev, &op);
+    
+    if (op.err)
+        return op.err;
+    else
+        return op.value;
+}
+
+int pcifront_disable_msi(struct pcifront_dev *dev,
+                         unsigned int dom,
+                         unsigned int bus, unsigned int slot, unsigned long 
fun)
+{
+    struct xen_pci_op op;
+
+    memset(&op, 0, sizeof(op));
+
+    op.cmd = XEN_PCI_OP_disable_msi;
+    op.domain = dom;
+    op.bus = bus;
+    op.devfn = PCI_DEVFN(slot, fun);
+
+    pcifront_op(dev, &op);
+    
+    return op.err;
+}
+
+int pcifront_enable_msix(struct pcifront_dev *dev,
+                         unsigned int dom,
+                         unsigned int bus, unsigned int slot, unsigned long 
fun,
+                         struct xen_msix_entry *entries, int n)
+{
+    struct xen_pci_op op;
+
+    if (n > SH_INFO_MAX_VEC)
+        return XEN_PCI_ERR_op_failed;
+
+    memset(&op, 0, sizeof(op));
+
+    op.cmd = XEN_PCI_OP_enable_msix;
+    op.domain = dom;
+    op.bus = bus;
+    op.devfn = PCI_DEVFN(slot, fun);
+    op.value = n;
+
+    memcpy(op.msix_entries, entries, n * sizeof(*entries));
+
+    pcifront_op(dev, &op);
+    
+    if (op.err)
+        return op.err;
+
+    memcpy(entries, op.msix_entries, n * sizeof(*entries));
+
+    return 0;
+}
+
+
+int pcifront_disable_msix(struct pcifront_dev *dev,
+                          unsigned int dom,
+                          unsigned int bus, unsigned int slot, unsigned long 
fun)
+{
+    struct xen_pci_op op;
+
+    memset(&op, 0, sizeof(op));
+
+    op.cmd = XEN_PCI_OP_disable_msix;
+    op.domain = dom;
+    op.bus = bus;
+    op.devfn = PCI_DEVFN(slot, fun);
+
+    pcifront_op(dev, &op);
+    
+    return op.err;
+}
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/sched.c
--- a/extras/mini-os/sched.c    Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/sched.c    Fri Jul 18 12:12:41 2008 +0900
@@ -75,7 +75,7 @@ void schedule(void)
 void schedule(void)
 {
     struct thread *prev, *next, *thread;
-    struct list_head *iterator;
+    struct list_head *iterator, *next_iterator;
     unsigned long flags;
 
     prev = current;
@@ -97,7 +97,7 @@ void schedule(void)
         s_time_t now = NOW();
         s_time_t min_wakeup_time = now + SECONDS(10);
         next = NULL;   
-        list_for_each(iterator, &idle_thread->thread_list)
+        list_for_each_safe(iterator, next_iterator, &idle_thread->thread_list)
         {
             thread = list_entry(iterator, struct thread, thread_list);
             if (!is_runnable(thread) && thread->wakeup_time != 0LL)
@@ -128,7 +128,7 @@ void schedule(void)
        inturrupted at the return instruction. And therefore at safe point. */
     if(prev != next) switch_threads(prev, next);
 
-    list_for_each(iterator, &exited_threads)
+    list_for_each_safe(iterator, next_iterator, &exited_threads)
     {
         thread = list_entry(iterator, struct thread, thread_list);
         if(thread != prev)
diff -r eb0fc71cfc72 -r 400e5d4877ca extras/mini-os/xenbus/xenbus.c
--- a/extras/mini-os/xenbus/xenbus.c    Tue Jul 08 11:41:43 2008 +0900
+++ b/extras/mini-os/xenbus/xenbus.c    Fri Jul 18 12:12:41 2008 +0900
@@ -78,9 +78,9 @@ char **xenbus_wait_for_watch_return(xenb
 char **xenbus_wait_for_watch_return(xenbus_event_queue *queue)
 {
     struct xenbus_event *event;
+    DEFINE_WAIT(w);
     if (!queue)
         queue = &xenbus_events;
-    DEFINE_WAIT(w);
     while (!(event = *queue)) {
         add_waiter(w, xenbus_watch_queue);
         schedule();
@@ -382,6 +382,7 @@ xenbus_msg_reply(int type,
 
 static char *errmsg(struct xsd_sockmsg *rep)
 {
+    char *res;
     if (!rep) {
        char msg[] = "No reply";
        size_t len = strlen(msg) + 1;
@@ -389,7 +390,7 @@ static char *errmsg(struct xsd_sockmsg *
     }
     if (rep->type != XS_ERROR)
        return NULL;
-    char *res = malloc(rep->len + 1);
+    res = malloc(rep->len + 1);
     memcpy(res, rep + 1, rep->len);
     res[rep->len] = 0;
     free(rep);
@@ -419,10 +420,10 @@ char *xenbus_ls(xenbus_transaction_t xbt
     struct xsd_sockmsg *reply, *repmsg;
     struct write_req req[] = { { pre, strlen(pre)+1 } };
     int nr_elems, x, i;
-    char **res;
+    char **res, *msg;
 
     repmsg = xenbus_msg_reply(XS_DIRECTORY, xbt, req, ARRAY_SIZE(req));
-    char *msg = errmsg(repmsg);
+    msg = errmsg(repmsg);
     if (msg) {
        *contents = NULL;
        return msg;
@@ -447,9 +448,9 @@ char *xenbus_read(xenbus_transaction_t x
 {
     struct write_req req[] = { {path, strlen(path) + 1} };
     struct xsd_sockmsg *rep;
-    char *res;
+    char *res, *msg;
     rep = xenbus_msg_reply(XS_READ, xbt, req, ARRAY_SIZE(req));
-    char *msg = errmsg(rep);
+    msg = errmsg(rep);
     if (msg) {
        *value = NULL;
        return msg;
@@ -469,8 +470,9 @@ char *xenbus_write(xenbus_transaction_t 
        {value, strlen(value)},
     };
     struct xsd_sockmsg *rep;
+    char *msg;
     rep = xenbus_msg_reply(XS_WRITE, xbt, req, ARRAY_SIZE(req));
-    char *msg = errmsg(rep);
+    msg = errmsg(rep);
     if (msg) return msg;
     free(rep);
     return NULL;
@@ -487,6 +489,8 @@ char* xenbus_watch_path_token( xenbus_tr
 
     struct watch *watch = malloc(sizeof(*watch));
 
+    char *msg;
+
     if (!events)
         events = &xenbus_events;
 
@@ -497,7 +501,7 @@ char* xenbus_watch_path_token( xenbus_tr
 
     rep = xenbus_msg_reply(XS_WATCH, xbt, req, ARRAY_SIZE(req));
 
-    char *msg = errmsg(rep);
+    msg = errmsg(rep);
     if (msg) return msg;
     free(rep);
 
@@ -515,9 +519,11 @@ char* xenbus_unwatch_path_token( xenbus_
 
     struct watch *watch, **prev;
 
+    char *msg;
+
     rep = xenbus_msg_reply(XS_UNWATCH, xbt, req, ARRAY_SIZE(req));
 
-    char *msg = errmsg(rep);
+    msg = errmsg(rep);
     if (msg) return msg;
     free(rep);
 
@@ -536,8 +542,9 @@ char *xenbus_rm(xenbus_transaction_t xbt
 {
     struct write_req req[] = { {path, strlen(path) + 1} };
     struct xsd_sockmsg *rep;
+    char *msg;
     rep = xenbus_msg_reply(XS_RM, xbt, req, ARRAY_SIZE(req));
-    char *msg = errmsg(rep);
+    msg = errmsg(rep);
     if (msg)
        return msg;
     free(rep);
@@ -548,9 +555,9 @@ char *xenbus_get_perms(xenbus_transactio
 {
     struct write_req req[] = { {path, strlen(path) + 1} };
     struct xsd_sockmsg *rep;
-    char *res;
+    char *res, *msg;
     rep = xenbus_msg_reply(XS_GET_PERMS, xbt, req, ARRAY_SIZE(req));
-    char *msg = errmsg(rep);
+    msg = errmsg(rep);
     if (msg) {
        *value = NULL;
        return msg;
@@ -567,14 +574,16 @@ char *xenbus_set_perms(xenbus_transactio
 char *xenbus_set_perms(xenbus_transaction_t xbt, const char *path, domid_t 
dom, char perm)
 {
     char value[PERM_MAX_SIZE];
-    snprintf(value, PERM_MAX_SIZE, "%c%hu", perm, dom);
     struct write_req req[] = { 
        {path, strlen(path) + 1},
-       {value, strlen(value) + 1},
+       {value, 0},
     };
     struct xsd_sockmsg *rep;
+    char *msg;
+    snprintf(value, PERM_MAX_SIZE, "%c%hu", perm, dom);
+    req[1].len = strlen(value) + 1;
     rep = xenbus_msg_reply(XS_SET_PERMS, xbt, req, ARRAY_SIZE(req));
-    char *msg = errmsg(rep);
+    msg = errmsg(rep);
     if (msg)
        return msg;
     free(rep);
@@ -659,11 +668,11 @@ char* xenbus_printf(xenbus_transaction_t
 
 static void do_ls_test(const char *pre)
 {
-    char **dirs;
+    char **dirs, *msg;
     int x;
 
     DEBUG("ls %s...\n", pre);
-    char *msg = xenbus_ls(XBT_NIL, pre, &dirs);
+    msg = xenbus_ls(XBT_NIL, pre, &dirs);
     if (msg) {
        DEBUG("Error in xenbus ls: %s\n", msg);
        free(msg);
@@ -679,9 +688,9 @@ static void do_ls_test(const char *pre)
 
 static void do_read_test(const char *path)
 {
-    char *res;
+    char *res, *msg;
     DEBUG("Read %s...\n", path);
-    char *msg = xenbus_read(XBT_NIL, path, &res);
+    msg = xenbus_read(XBT_NIL, path, &res);
     if (msg) {
        DEBUG("Error in xenbus read: %s\n", msg);
        free(msg);
@@ -693,8 +702,9 @@ static void do_read_test(const char *pat
 
 static void do_write_test(const char *path, const char *val)
 {
+    char *msg;
     DEBUG("Write %s to %s...\n", val, path);
-    char *msg = xenbus_write(XBT_NIL, path, val);
+    msg = xenbus_write(XBT_NIL, path, val);
     if (msg) {
        DEBUG("Result %s\n", msg);
        free(msg);
@@ -705,8 +715,9 @@ static void do_write_test(const char *pa
 
 static void do_rm_test(const char *path)
 {
+    char *msg;
     DEBUG("rm %s...\n", path);
-    char *msg = xenbus_rm(XBT_NIL, path);
+    msg = xenbus_rm(XBT_NIL, path);
     if (msg) {
        DEBUG("Result %s\n", msg);
        free(msg);
diff -r eb0fc71cfc72 -r 400e5d4877ca stubdom/Makefile
--- a/stubdom/Makefile  Tue Jul 08 11:41:43 2008 +0900
+++ b/stubdom/Makefile  Fri Jul 18 12:12:41 2008 +0900
@@ -3,18 +3,18 @@ MINI_OS = $(XEN_ROOT)/extras/mini-os
 
 export XEN_OS=MiniOS
 
-include $(XEN_ROOT)/Config.mk
+CONFIG_QEMU=ioemu
+
 export stubdom=y
 export debug=y
-
-IOEMU_OPTIONS=--disable-vnc-tls 
-BINUTILS_VERSION=2.18
-GCC_VERSION=4.2.2
+include $(XEN_ROOT)/Config.mk
+
+IOEMU_OPTIONS=--disable-sdl --disable-opengl --disable-gfx-check 
--disable-vnc-tls --disable-brlapi --disable-kqemu
 ZLIB_VERSION=1.2.3
 LIBPCI_VERSION=2.2.9
-NEWLIB_DATE=2008-01-01
-LWIP_DATE=2008-06-01
-GRUB_DATE=2008-06-01
+NEWLIB_VERSION=1.16.0
+LWIP_VERSION=1.3.0
+GRUB_VERSION=0.97
 
 WGET=wget -c
 
@@ -26,10 +26,12 @@ ifeq ($(GNU_TARGET_ARCH), i686)
 ifeq ($(GNU_TARGET_ARCH), i686)
 TARGET_CFLAGS=
 NEWLIB_CFLAGS+=-D_I386MACH_ALLOW_HW_INTERRUPTS
+STUBDOM_SUPPORTED=1
 endif
 ifeq ($(GNU_TARGET_ARCH), x86_64)
 TARGET_CFLAGS=-mno-red-zone
 NEWLIB_CFLAGS+=-D_I386MACH_ALLOW_HW_INTERRUPTS
+STUBDOM_SUPPORTED=1
 endif
 ifeq ($(GNU_TARGET_ARCH), ia64)
 TARGET_CFLAGS=-mconstant-gp
@@ -37,82 +39,65 @@ endif
 
 CROSS_ROOT=cross-root-$(GNU_TARGET_ARCH)
 CROSS_PREFIX=$(CURDIR)/$(CROSS_ROOT)
-export CROSS_COMPILE=$(GNU_TARGET_ARCH)-xen-elf-
-export PATH:=$(CROSS_PREFIX)/bin:$(PATH)
+
+# Disable PIE/SSP if GCC supports them. They can break us.
+TARGET_CFLAGS += $(CFLAGS)
+TARGET_CPPFLAGS += $(CPPFLAGS)
+TARGET_CFLAGS += $(call cc-option,$(CC),-nopie,)
+TARGET_CFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
+TARGET_CFLAGS += $(call cc-option,$(CC),-fno-stack-protector-all,)
+
+# Do not use host headers and libs
+GCC_INSTALL = $(shell gcc -print-search-dirs | sed -n -e 's/install: 
\(.*\)/\1/p')
+TARGET_CPPFLAGS += -U __linux__ -U __FreeBSD__ -U __sun__
+TARGET_CPPFLAGS += -nostdinc
+TARGET_CPPFLAGS += -isystem $(CURDIR)/$(MINI_OS)/include/posix
+TARGET_CPPFLAGS += -isystem $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/include
+TARGET_CPPFLAGS += -isystem $(GCC_INSTALL)include
+TARGET_CPPFLAGS += -isystem $(CURDIR)/lwip/src/include
+TARGET_CPPFLAGS += -isystem $(CURDIR)/lwip/src/include/ipv4
+TARGET_CPPFLAGS += -I$(CURDIR)/include
+
+TARGET_LDFLAGS += -nostdlib -L$(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/lib
 
 TARGETS=ioemu c caml grub
 
 .PHONY: all
-all: ioemu-stubdom c-stubdom pv-grub
-
-################
-# Cross-binutils
-################
-
-binutils-$(BINUTILS_VERSION).tar.bz2:
-       $(WGET) http://ftp.gnu.org/gnu/binutils/$@
-binutils-$(BINUTILS_VERSION): binutils-$(BINUTILS_VERSION).tar.bz2
-       tar xjf $<
-       patch -d $@ -p1 < binutils.patch
+all: build
+ifeq ($(STUBDOM_SUPPORTED),1)
+build: ioemu-stubdom c-stubdom pv-grub
+else
+build:
+endif
+
+##############
+# Cross-newlib
+##############
+
+newlib-$(NEWLIB_VERSION).tar.gz:
+       $(WGET) ftp://sources.redhat.com/pub/newlib/$@
+
+newlib-$(NEWLIB_VERSION): newlib-$(NEWLIB_VERSION).tar.gz
+       tar xzf $<
+       patch -d $@ -p0 < newlib.patch
        touch $@
-
-BINUTILS_STAMPFILE=$(CROSS_ROOT)/bin/$(GNU_TARGET_ARCH)-xen-elf-ar
-.PHONY: cross-binutils
-cross-binutils: $(BINUTILS_STAMPFILE)
-$(BINUTILS_STAMPFILE): binutils-$(BINUTILS_VERSION)
-       mkdir -p binutils-build
-       ( cd binutils-build && \
-         ../binutils-$(BINUTILS_VERSION)/configure --prefix=$(CROSS_PREFIX) 
--verbose --target=$(GNU_TARGET_ARCH)-xen-elf && \
-         $(MAKE) && \
-         $(MAKE) check && \
-         $(MAKE) install )
-
-###########
-# Cross-gcc
-###########
-
-gcc-$(GCC_VERSION).tar.bz2:
-       $(WGET) 
http://ftp.gnu.org/gnu/gcc/gcc-$(GCC_VERSION)/gcc-$(GCC_VERSION).tar.bz2
-gcc-$(GCC_VERSION): gcc-$(GCC_VERSION).tar.bz2
-       tar xjf $<
-       patch -d $@ -p1 < gcc.patch
-       touch $@
-
-GCC_STAMPFILE=$(CROSS_ROOT)/bin/$(GNU_TARGET_ARCH)-xen-elf-gcc-$(GCC_VERSION)
-.PHONY: cross-gcc
-cross-gcc: $(GCC_STAMPFILE)
-$(GCC_STAMPFILE): gcc-$(GCC_VERSION) $(BINUTILS_STAMPFILE)
-       mkdir -p gcc-build
-       ( cd gcc-build && \
-         ../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 && \
-         $(MAKE) GCC_FOR_TARGET='$$$$r/gcc/xgcc -B$$$$r/gcc/ 
'"$(TARGET_CFLAGS)"' $$(FLAGS_FOR_TARGET)' && \
-         $(MAKE) install )
-
-##############
-# Cross-newlib
-##############
-
-newlib-cvs:
-       cvs -z 9 -d :pserver:anoncvs@xxxxxxxxxxxxxxxxxx:/cvs/src co -D 
$(NEWLIB_DATE) newlib
-       mv src newlib-cvs
-       patch -d $@ -p0 < newlib.patch
 
 NEWLIB_STAMPFILE=$(CROSS_ROOT)/$(GNU_TARGET_ARCH)-xen-elf/lib/libc.a
 .PHONY: cross-newlib
 cross-newlib: $(NEWLIB_STAMPFILE)
-$(NEWLIB_STAMPFILE): newlib-cvs $(GCC_STAMPFILE)
+$(NEWLIB_STAMPFILE): newlib-$(NEWLIB_VERSION)
        mkdir -p newlib-build
        ( cd newlib-build && \
-         CC_FOR_TARGET="$(GNU_TARGET_ARCH)-xen-elf-gcc $(TARGET_CFLAGS) 
$(NEWLIB_CFLAGS)" ../newlib-cvs/configure --prefix=$(CROSS_PREFIX) --verbose 
--target=$(GNU_TARGET_ARCH)-xen-elf --enable-newlib-io-long-long && \
+         CC_FOR_TARGET="$(CC) $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) 
$(NEWLIB_CFLAGS)" AR_FOR_TARGET=$(AR) LD_FOR_TARGET=$(LD) 
RANLIB_FOR_TARGET=$(RANLIB) ../newlib-$(NEWLIB_VERSION)/configure 
--prefix=$(CROSS_PREFIX) --verbose --target=$(GNU_TARGET_ARCH)-xen-elf 
--enable-newlib-io-long-long --disable-multilib && \
          $(MAKE) && \
-         $(MAKE) install )
+         DESTDIR= $(MAKE) install )
 
 ############
 # Cross-zlib
 ############
 
 zlib-$(ZLIB_VERSION).tar.gz:
-       $(WGET) http://www.zlib.net/zlib-$(ZLIB_VERSION).tar.gz
+       $(WGET) http://www.zlib.net/$@
 
 ZLIB_STAMPFILE=$(CROSS_ROOT)/$(GNU_TARGET_ARCH)-xen-elf/lib/libz.a
 .PHONY: cross-zlib
@@ -120,7 +105,7 @@ cross-zlib: $(ZLIB_STAMPFILE)
 $(ZLIB_STAMPFILE): zlib-$(ZLIB_VERSION).tar.gz $(NEWLIB_STAMPFILE)
        tar xzf $<
        ( cd zlib-$(ZLIB_VERSION) && \
-         CFLAGS="$(TARGET_CFLAGS)" CC=$(GNU_TARGET_ARCH)-xen-elf-gcc 
./configure --prefix=$(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf && \
+         CFLAGS="$(TARGET_CPPFLAGS) $(TARGET_CFLAGS)" CC=$(CC) ./configure 
--prefix=$(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf && \
          $(MAKE) libz.a && \
          $(MAKE) install )
 
@@ -129,18 +114,22 @@ cross-zlib: $(ZLIB_STAMPFILE)
 ##############
 
 pciutils-$(LIBPCI_VERSION).tar.bz2:
-       $(WGET) 
http://www.kernel.org/pub/software/utils/pciutils/pciutils-$(LIBPCI_VERSION).tar.bz2
+       $(WGET) http://www.kernel.org/pub/software/utils/pciutils/$@
+
+pciutils-$(LIBPCI_VERSION): pciutils-$(LIBPCI_VERSION).tar.bz2
+       tar xjf $<
+       patch -d $@ -p1 < pciutils.patch
+       touch $@
 
 LIBPCI_STAMPFILE=$(CROSS_ROOT)/$(GNU_TARGET_ARCH)-xen-elf/lib/libpci.a
 .PHONY: cross-libpci
 cross-libpci: $(LIBPCI_STAMPFILE)
-$(LIBPCI_STAMPFILE): pciutils-$(LIBPCI_VERSION).tar.bz2 $(NEWLIB_STAMPFILE) 
$(ZLIB_STAMPFILE)
-       tar xjf $<
+$(LIBPCI_STAMPFILE): pciutils-$(LIBPCI_VERSION) $(NEWLIB_STAMPFILE) 
$(ZLIB_STAMPFILE)
        ( cd pciutils-$(LIBPCI_VERSION) && \
          cp ../libpci.config.h lib/config.h && \
          echo '#define PCILIB_VERSION "$(LIBPCI_VERSION)"' >> lib/config.h && \
          cp ../libpci.config.mak lib/config.mk && \
-         $(MAKE) CC="$(GNU_TARGET_ARCH)-xen-elf-gcc $(TARGET_CFLAGS)" 
lib/libpci.a && \
+         $(MAKE) CC="$(CC) $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -I$(realpath 
$(MINI_OS)/include)" lib/libpci.a && \
          $(INSTALL_DATA) lib/libpci.a 
$(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/lib/ && \
          $(INSTALL_DIR) $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/include/pci 
&& \
          $(INSTALL_DATA) lib/{config,header,pci,types}.h 
$(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/include/pci/ \
@@ -150,8 +139,13 @@ cross-libpci: $(LIBPCI_STAMPFILE)
 # lwIP
 ######
 
-lwip-cvs:
-       cvs -z 9 -d :pserver:anonymous@xxxxxxxxxxxxxxxxxxxxxxx:/sources/lwip co 
-D $(LWIP_DATE) -d $@ lwip
+lwip-$(LWIP_VERSION).tar.gz:
+       $(WGET) http://download.savannah.gnu.org/releases/lwip/$@
+
+lwip: lwip-$(LWIP_VERSION).tar.gz
+       tar xzf $<
+       patch -d $@ -p0 < lwip.patch-cvs
+       touch $@
 
 #######
 # Links
@@ -160,9 +154,16 @@ lwip-cvs:
 .PHONY: $(CROSS_ROOT)
 $(CROSS_ROOT): cross-newlib cross-zlib cross-libpci
 
-.PHONY: mk-symlinks
-mk-symlinks:
-       [ -h include ] || ln -sf ../tools/include .
+.PHONY: mk-headers
+mk-headers:
+       mkdir -p include/xen && \
+          ln -sf $(addprefix ../../,$(wildcard 
$(XEN_ROOT)/xen/include/public/*.h)) include/xen && \
+          ln -sf $(addprefix ../../$(XEN_ROOT)/xen/include/public/,arch-ia64 
arch-x86 hvm io xsm) include/xen && \
+          ( [ -h include/xen/sys ] || ln -sf 
../../$(XEN_ROOT)/tools/include/xen-sys/MiniOS include/xen/sys ) && \
+         mkdir -p include/xen-foreign && \
+         ln -sf $(addprefix ../../,$(wildcard 
$(XEN_ROOT)/tools/include/xen-foreign/*)) include/xen-foreign/ && \
+         $(MAKE) -C include/xen-foreign/ && \
+         ( [ -h include/xen/foreign ] || ln -sf ../xen-foreign 
include/xen/foreign )
        mkdir -p libxc
        [ -h libxc/Makefile ] || ( cd libxc && \
          ln -sf ../$(XEN_ROOT)/tools/libxc/*.h . && \
@@ -174,10 +175,21 @@ mk-symlinks:
          ln -sf ../$(XEN_ROOT)/tools/libxc/$(XEN_TARGET_ARCH)/*.h . && \
          ln -sf ../$(XEN_ROOT)/tools/libxc/$(XEN_TARGET_ARCH)/Makefile . )
        mkdir -p ioemu
+ifeq ($(CONFIG_QEMU),ioemu)
        [ -h ioemu/Makefile ] || ( cd ioemu && \
-         ln -sf ../$(XEN_ROOT)/tools/ioemu/* . && \
-         ([ ! -h config-host.h ] || rm -f config-host.h) && \
-         ([ ! -h config-host.mak ] || rm -f config-host.mak) )
+         ln -sf ../$(XEN_ROOT)/tools/ioemu/* .)
+else
+       [ -h ioemu/Makefile ] || ( cd ioemu && \
+         ln -sf $(CONFIG_QEMU)/* . && \
+          rm -fr i386-dm && \
+          rm -fr i386-stubdom && \
+          mkdir i386-dm && \
+          mkdir i386-stubdom && \
+         ln -sf $(CONFIG_QEMU)/i386-dm/* i386-dm/ && \
+         ln -sf $(CONFIG_QEMU)/i386-stubdom/* i386-stubdom/ )
+endif
+       [ ! -h ioemu/config-host.h ] || rm -f ioemu/config-host.h
+       [ ! -h ioemu/config-host.mak ] || rm -f ioemu/config-host.mak
        $(MAKE) -C $(MINI_OS) links
 
 TARGETS_MINIOS=$(addprefix mini-os-,$(TARGETS))
@@ -193,82 +205,106 @@ TARGETS_MINIOS=$(addprefix mini-os-,$(TA
 
 .PHONY: libxc
 libxc: libxc/libxenctrl.a libxc/libxenguest.a
-libxc/libxenctrl.a libxc/libxenguest.a: cross-zlib mk-symlinks
-       $(MAKE) -C libxc
+libxc/libxenctrl.a libxc/libxenguest.a:: cross-zlib mk-headers
+       CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) -C libxc
 
 #######
 # ioemu
 #######
 
 .PHONY: ioemu
-ioemu: cross-zlib cross-libpci mk-symlinks libxc
+ioemu: cross-zlib cross-libpci mk-headers libxc
+ifeq ($(CONFIG_QEMU),ioemu)
        [ -f ioemu/config-host.mak ] || \
-         ( cd ioemu ; XEN_TARGET_ARCH=$(XEN_TARGET_ARCH) sh configure 
--prefix=/usr --enable-stubdom $(IOEMU_OPTIONS))
-       $(MAKE) -C ioemu LWIPDIR=$(CURDIR)/lwip-cvs
+         ( cd ioemu ; \
+          XEN_TARGET_ARCH=$(XEN_TARGET_ARCH) CFLAGS="$(TARGET_CFLAGS)" sh 
configure --prefix=/usr --enable-stubdom $(IOEMU_OPTIONS))
+       CPPFLAGS="$(TARGET_CPPFLAGS)" $(MAKE) -C ioemu LWIPDIR=$(CURDIR)/lwip 
TOOLS=
+else
+       [ -f ioemu/config-host.mak ] || \
+         ( cd ioemu ; \
+          CONFIG_STUBDOM=yes XEN_ROOT=$(abspath $(XEN_ROOT)) 
XEN_TARGET_ARCH=$(XEN_TARGET_ARCH) CFLAGS="$(TARGET_CFLAGS)" sh ./xen-setup 
--cc=$(CC) --disable-gcc-check $(IOEMU_OPTIONS))
+       CPPFLAGS= TARGET_CPPFLAGS="$(TARGET_CPPFLAGS)" $(MAKE) -C ioemu 
LWIPDIR=$(CURDIR)/lwip TOOLS= CONFIG_STUBDOM=yes
+endif
 
 ######
 # caml
 ######
 
 .PHONY: caml
-caml: cross-newlib mk-symlinks
-       $(MAKE) -C $@ LWIPDIR=$(CURDIR)/lwip-cvs 
+caml: cross-newlib mk-headers
+       CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) -C $@ 
LWIPDIR=$(CURDIR)/lwip 
 
 ###
 # C
 ###
 
 .PHONY: c
-c: cross-newlib mk-symlinks
-       $(MAKE) -C $@ LWIPDIR=$(CURDIR)/lwip-cvs 
+c: cross-newlib mk-headers
+       CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) -C $@ 
LWIPDIR=$(CURDIR)/lwip 
 
 ######
 # Grub
 ######
 
-grub-cvs:
-       cvs -z 9 -d :pserver:anonymous@xxxxxxxxxxxxxx:/sources/grub co -D 
$(GRUB_DATE) -d $@ grub
+grub-$(GRUB_VERSION).tar.gz:
+       $(WGET) ftp://alpha.gnu.org/gnu/grub/$@
+
+grub-upstream: grub-$(GRUB_VERSION).tar.gz
+       tar xzf $<
+       mv grub-$(GRUB_VERSION) $@
        for i in grub.patches/* ; do \
                patch -d $@ -p1 < $$i ; \
        done
 
 .PHONY: grub
-grub: grub-cvs cross-newlib mk-symlinks
-       $(MAKE) -C $@
+grub: grub-upstream cross-newlib mk-headers
+       CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) -C $@
 
 ########
 # minios
 ########
 
 .PHONY: ioemu-stubdom
-ioemu-stubdom: mini-os-ioemu lwip-cvs libxc ioemu
-       DEF_CFLAGS=-DCONFIG_QEMU $(MAKE) -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< 
LWIPDIR=$(CURDIR)/lwip-cvs APP_OBJS="$(CURDIR)/ioemu/i386-dm-stubdom/qemu.a 
$(CURDIR)/ioemu/i386-dm-stubdom/libqemu.a"
+ifeq ($(CONFIG_QEMU),ioemu)
+ioemu-stubdom: APP_OBJS=$(CURDIR)/ioemu/i386-dm-stubdom/qemu.a 
$(CURDIR)/ioemu/i386-dm-stubdom/libqemu.a
+else
+ioemu-stubdom: APP_OBJS=$(CURDIR)/ioemu/i386-stubdom/qemu.a 
$(CURDIR)/ioemu/i386-stubdom/libqemu.a $(CURDIR)/ioemu/libqemu_common.a
+endif
+ioemu-stubdom: mini-os-ioemu lwip libxc ioemu
+       DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="-DCONFIG_QEMU 
$(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" $(MAKE) -C $(MINI_OS) 
OBJ_DIR=$(CURDIR)/$< LWIPDIR=$(CURDIR)/lwip APP_OBJS="$(APP_OBJS)"
 
 CAMLLIB = $(shell ocamlc -where)
 .PHONY: caml-stubdom
-caml-stubdom: mini-os-caml lwip-cvs libxc caml
-       DEF_CFLAGS=-DCONFIG_CAML $(MAKE) -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< 
LWIPDIR=$(CURDIR)/lwip-cvs APP_OBJS="$(CURDIR)/caml/main-caml.o 
$(CURDIR)/caml/caml.o $(CAMLLIB)/libasmrun.a"
+caml-stubdom: mini-os-caml lwip libxc caml
+       DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="-DCONFIG_CAML 
$(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" $(MAKE) -C $(MINI_OS) 
OBJ_DIR=$(CURDIR)/$< LWIPDIR=$(CURDIR)/lwip 
APP_OBJS="$(CURDIR)/caml/main-caml.o $(CURDIR)/caml/caml.o 
$(CAMLLIB)/libasmrun.a"
 
 .PHONY: c-stubdom
-c-stubdom: mini-os-c lwip-cvs libxc c
-       DEF_CFLAGS=-DCONFIG_C $(MAKE) -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< 
LWIPDIR=$(CURDIR)/lwip-cvs APP_OBJS=$(CURDIR)/c/main.a
+c-stubdom: mini-os-c lwip libxc c
+       DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="-DCONFIG_C 
$(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" $(MAKE) -C $(MINI_OS) 
OBJ_DIR=$(CURDIR)/$< LWIPDIR=$(CURDIR)/lwip APP_OBJS=$(CURDIR)/c/main.a
 
 .PHONY: pv-grub
 pv-grub: mini-os-grub libxc grub
-       DEF_CFLAGS=-DCONFIG_GRUB $(MAKE) -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< 
APP_OBJS=$(CURDIR)/grub/main.a
+       DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="-DCONFIG_GRUB 
$(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" $(MAKE) -C $(MINI_OS) 
OBJ_DIR=$(CURDIR)/$< APP_OBJS=$(CURDIR)/grub/main.a
 
 #########
 # install
 #########
 
+ifeq ($(STUBDOM_SUPPORTED),1)
 install: install-ioemu install-grub
-
-install-ioemu: mini-os-ioemu/mini-os.gz
+else
+install:
+endif
+
+install-ioemu: ioemu-stubdom
+       $(INSTALL_DIR) "$(DESTDIR)/usr/lib/xen/bin"
        $(INSTALL_PROG) stubdom-dm "$(DESTDIR)/usr/lib/xen/bin"
-       $(INSTALL_PROG) $< "$(DESTDIR)/usr/lib/xen/boot/ioemu-stubdom.gz"
-
-install-grub: mini-os-grub/mini-os.gz
-       $(INSTALL_PROG) $< "$(DESTDIR)/usr/lib/xen/boot/pv-grub.gz"
+       $(INSTALL_DIR) "$(DESTDIR)/usr/lib/xen/boot"
+       $(INSTALL_PROG) mini-os-ioemu/mini-os.gz 
"$(DESTDIR)/usr/lib/xen/boot/ioemu-stubdom.gz"
+
+install-grub: pv-grub
+       $(INSTALL_DIR) "$(DESTDIR)/usr/lib/xen/boot"
+       $(INSTALL_PROG) mini-os-grub/mini-os.gz 
"$(DESTDIR)/usr/lib/xen/boot/pv-grub.gz"
 
 #######
 # clean
@@ -290,25 +326,24 @@ clean:
 .PHONY: crossclean
 crossclean: clean
        rm -fr $(CROSS_ROOT)
-       rm -fr binutils-build gcc-build newlib-build
+       rm -fr newlib-build
        rm -fr zlib-$(ZLIB_VERSION) pciutils-$(LIBPCI_VERSION)
 
 # clean patched sources
 .PHONY: patchclean
 patchclean: crossclean
-       rm -fr binutils-$(BINUTILS_VERSION)
-       rm -fr gcc-$(GCC_VERSION)
-       rm -fr newlib-cvs
-       rm -fr lwip-cvs
-       rm -fr grub-cvs
+       rm -fr newlib-$(NEWLIB_VERSION)
+       rm -fr lwip
+       rm -fr grub-upstream
 
 # clean downloads
 .PHONY: downloadclean
 downloadclean: patchclean
-       rm -f binutils-$(BINUTILS_VERSION).tar.bz2
-       rm -f gcc-$(GCC_VERSION).tar.bz2
+       rm -f newlib-$(NEWLIB_VERSION).tar.gz
        rm -f zlib-$(ZLIB_VERSION).tar.gz
        rm -f pciutils-$(LIBPCI_VERSION).tar.bz2
+       rm -f grub-$(GRUB_VERSION).tar.gz
+       rm -f lwip-$(LWIP_VERSION).tar.gz
 
 .PHONY: distclean
 distclean: downloadclean
diff -r eb0fc71cfc72 -r 400e5d4877ca stubdom/binutils.patch
--- a/stubdom/binutils.patch    Tue Jul 08 11:41:43 2008 +0900
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,14 +0,0 @@
-It looks like binutils has troubles with makeinfo and the doc generation.
-We don't need it anyway
-
---- binutils-2.18/bfd/Makefile.inorig  2008-01-16 16:17:43.004484000 +0000
-+++ binutils-2.18/bfd/Makefile.in      2008-01-16 16:17:50.505526000 +0000
-@@ -271,7 +271,7 @@
- INCDIR = $(srcdir)/../include
- CSEARCH = -I. -I$(srcdir) -I$(INCDIR)
- MKDEP = gcc -MM
--SUBDIRS = doc po
-+SUBDIRS = po
- bfddocdir = doc
- bfdlib_LTLIBRARIES = libbfd.la
- AM_CFLAGS = $(WARN_CFLAGS)
diff -r eb0fc71cfc72 -r 400e5d4877ca stubdom/gcc.patch
--- a/stubdom/gcc.patch Tue Jul 08 11:41:43 2008 +0900
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,31 +0,0 @@
-Backported from later versions
-
---- gcc-4.2.2/gcc/config.gcc       2007-11-22 16:27:45.000000000 +0000
-+++ gcc-4.2.2/gcc/config.gcc       2007-11-22 16:23:00.000000000 +0000
-@@ -1033,6 +1033,11 @@
-       tmake_file="i386/t-i386elf t-svr4"
-       use_fixproto=yes
-       ;;
-+x86_64-*-elf*)
-+      tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h 
i386/i386elf.h i386/x86-64.h"
-+      tmake_file="i386/t-i386elf t-svr4"
-+      use_fixproto=yes
-+      ;;
- i[34567]86-sequent-ptx4* | i[34567]86-sequent-sysv4*)
-       if test x$gas = xyes
-       then
-
-We don't have a libc yet at this stage. Unused anyway
-
---- gcc-4.2.2/gcc/unwind-generic.h.orig 2008-01-11 18:54:40.000000000 +0100
-+++ gcc-4.2.2/gcc/unwind-generic.h      2008-01-11 18:54:31.000000000 +0100
-@@ -203,7 +203,6 @@
-    compatible with the standard ABI for IA-64, we inline these.  */
- 
- #ifdef __ia64__
--#include <stdlib.h>
- 
- static inline _Unwind_Ptr
- _Unwind_GetDataRelBase (struct _Unwind_Context *_C)
-Backported from later versions
-
diff -r eb0fc71cfc72 -r 400e5d4877ca stubdom/grub.patches/00cvs
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/stubdom/grub.patches/00cvs        Fri Jul 18 12:12:41 2008 +0900
@@ -0,0 +1,1382 @@
+diff -uprN grub-0.97/acinclude.m4 grub/acinclude.m4
+--- grub-0.97/acinclude.m4     2004-04-27 21:48:06.000000000 +0100
++++ grub/acinclude.m4  2007-11-05 01:29:46.000000000 +0000
+@@ -57,7 +57,7 @@ else
+ fi
+ grub_cv_prog_objcopy_absolute=yes
+ for link_addr in 2000 8000 7C00; do
+-  if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -nostdlib -Wl,-N -Wl,-Ttext 
-Wl,$link_addr conftest.o -o conftest.exec]); then :
++  if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} ${LDFLAGS} -nostdlib -Wl,-N 
-Wl,-Ttext -Wl,$link_addr conftest.o -o conftest.exec]); then :
+   else
+     AC_MSG_ERROR([${CC-cc} cannot link at address $link_addr])
+   fi
+diff -uprN grub-0.97/ChangeLog grub/ChangeLog
+--- grub-0.97/ChangeLog        2005-05-08 03:47:02.000000000 +0100
++++ grub/ChangeLog     2008-05-20 12:04:18.000000000 +0100
+@@ -1,3 +1,127 @@
++2008-05-20  Robert Millan  <rmh@xxxxxxxxxxx>
++
++      * netboot/cs89x0.c: Fix license violation.
++      * netboot/cs89x0.h: Likewise.
++
++2008-04-10  Pavel Roskin  <proski@xxxxxxx>
++
++      * configure.ac: Always use "_cv_" in cache variables for
++      compatibility with Autoconf 2.62.
++
++2008-03-28  Robert Millan  <rmh@xxxxxxxxxxx>
++
++      Surpass 1 TiB disk addressing limit.  Note: there are no plans to handle
++      the 2 TiB disk limit in GRUB Legacy, since that would need considerable
++      rework.  If you have >2TiB disks, use GRUB 2 instead.
++
++      * grub/asmstub.c (biosdisk): Add unsigned qualifier to `sector'.
++      * stage2/bios.c (biosdisk): Likewise.
++      * stage2/disk_io.c (rawread, devread, rawwrite, devwrite): Likewise.
++      * stage2/shared.h (rawread, devread, rawwrite, devwrite): Likewise.
++      * lib/device.c (get_drive_geometry): Replace BLKGETSIZE with
++      BLKGETSIZE64.
++
++2007-10-29  Pavel Roskin  <proski@xxxxxxx>
++
++      * configure.ac: Test if '--build-id=none' is supported by the
++      linker and add it to LDFLAGS if possible.  Build ID causes
++      objcopy to generate huge binary files.
++      * aclocal.m4 (grub_PROG_OBJCOPY_ABSOLUTE): Use LDFLAGS when
++      linking, so that build ID doesn't break the test.
++      * stage1/Makefile.am: Preserve LDFLAGS, use stage1_exec_LDFLAGS.
++
++2007-02-22  Pavel Roskin  <proski@xxxxxxx>
++
++      * stage2/iso9660.h: Remove unnecessary packed attributes.
++
++2007-02-22  Robert Millan  <rmh@xxxxxxxxxxx>
++
++      * util/mkbimage: Update my email address, and remove my name from
++      some places where unnecessary credit is given.
++
++2006-09-10  Pavel Roskin  <proski@xxxxxxx>
++
++      * netboot/natsemi.c: Fix compile error with gcc 4.1.1.  Cast
++      cannot make a variable volatile - it should be declared as such.
++      * netboot/sis900.c: Likewise.
++
++2006-09-08  Pavel Roskin  <proski@xxxxxxx>
++
++      * netboot/etherboot.h: Remove incorrect extern declarations of
++      the variables later declared static.  Move BOOTP_DATA_ADDR ...
++      * netboot/main.c: ... here.  Eliminate end_of_rfc1533 - it's
++      write-only.
++
++2006-06-24  Yoshinori K. Okuji  <okuji@xxxxxxxxx>
++
++      * docs/grub.texi: Changed the license term to the GNU Free
++      Documentation License 1.2.
++
++      * docs/multiboot.texi: Reformatted to show the license term
++      and the version number explicitly.
++      
++      * docs/fdl.texi: New file.
++      
++      * docs/Makefile.am (grub_TEXINFOS): Added fdl.texi.
++
++2006-06-24  Robert Millan  <robertmh@xxxxxxx>
++
++      * lib/device.c (write_to_partition): /dev/ataraid/ and /dev/rd/
++      partitions have a "p" prefix.  Add it.
++
++2006-06-24  Robert Millan  <robertmh@xxxxxxx>
++
++      * lib/device.c (get_i2o_disk_name): New function.
++      (init_device_map) [__linux__]: Add support for I2O devices.
++
++2006-05-02  Pavel Roskin  <proski@xxxxxxx>
++
++      * stage2/stage2.c (run_menu): Fix "savedefault" to save only top
++      level menu positions.  Remember current position when calling a
++      submenu.  Don't recalculate it when booting from a submenu.
++
++      * grub/main.c (main): Make sure the boot drive number doesn't
++      exceed 255.
++
++2006-05-02  Vesa Jaaskelainen  <chaac@xxxxxx>
++
++      * stage2/shared.h (vbe_mode): Back ported aligment fix from GRUB 2
++      to GRUB Legacy.  Problem reported by Gerardo Richarte.
++
++2006-04-23  Robert Millan  <robertmh@xxxxxxx>
++
++      * grub/asmstub.c (get_diskinfo): Optimize sysctl routine.
++
++2006-04-20  Robert Millan  <robertmh@xxxxxxx>
++
++      Fixes for kernel of FreeBSD:
++      * grub/asmstub.c (get_diskinfo): Toggle "kern.geom.debugflags" sysctl
++      before opening a device for writing.
++      * util/grub-install.in: Devices don't have this "r" prefix anymore.
++
++2006-04-16  Yoshinori K. Okuji  <okuji@xxxxxxxxx>
++
++      * docs/multiboot.texi: Correct the offset of address
++      fields. Reported by Jeroen Dekkers.
++
++2006-03-21  Yoshinori K. Okuji  <okuji@xxxxxxxxx>
++
++      * stage2/builtins.c (setup_func): Specify the size of DEVICE to
++      grub_strncat instead of a strange number 256. Reported by Vitaly
++      Fertman <vitaly@xxxxxxxxxxx>.
++
++2005-09-29  Yoshinori K. Okuji  <okuji@xxxxxxxxx>
++
++      * docs/multiboot.texi: Fix a bug in the byte order of
++      boot_device. I hope this won't affect any OS image.
++      Increased the version number to 0.6.94.
++
++2005-09-28  Yoshinori K. Okuji  <okuji@xxxxxxxxx>
++
++      * stage2/boot.c (load_image): Even if an OS image is an ELF
++      object, use the a.out kludge if MULTIBOOT_AOUT_KLUDGE is
++      specified.
++
+ 2005-05-08  Yoshinori K. Okuji  <okuji@xxxxxxxxx>
+ 
+       * configure.ac (AC_INIT): Upgraded to 0.97.
+diff -uprN grub-0.97/configure grub/configure
+--- grub-0.97/configure        2005-05-08 03:48:12.000000000 +0100
++++ grub/configure     2007-11-05 01:29:46.000000000 +0000
+@@ -3694,6 +3694,64 @@ if test "x$undef_flag" = xyes; then
+   CPPFLAGS="$CPPFLAGS -Wundef"
+ fi
+ 
++# Check if build ID can be disabled in the linker
++echo "$as_me:$LINENO: checking whether linker accepts \`--build-id=none'" >&5
++echo $ECHO_N "checking whether linker accepts \`--build-id=none'... $ECHO_C" 
>&6
++save_LDFLAGS="$LDFLAGS"
++LDFLAGS="$LDFLAGS -Wl,--build-id=none"
++cat >conftest.$ac_ext <<_ACEOF
++/* confdefs.h.  */
++_ACEOF
++cat confdefs.h >>conftest.$ac_ext
++cat >>conftest.$ac_ext <<_ACEOF
++/* end confdefs.h.  */
++
++int
++main ()
++{
++
++  ;
++  return 0;
++}
++_ACEOF
++rm -f conftest.$ac_objext conftest$ac_exeext
++if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
++  (eval $ac_link) 2>conftest.er1
++  ac_status=$?
++  grep -v '^ *+' conftest.er1 >conftest.err
++  rm -f conftest.er1
++  cat conftest.err >&5
++  echo "$as_me:$LINENO: \$? = $ac_status" >&5
++  (exit $ac_status); } &&
++       { ac_try='test -z "$ac_c_werror_flag"
++                       || test ! -s conftest.err'
++  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
++  (eval $ac_try) 2>&5
++  ac_status=$?
++  echo "$as_me:$LINENO: \$? = $ac_status" >&5
++  (exit $ac_status); }; } &&
++       { ac_try='test -s conftest$ac_exeext'
++  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
++  (eval $ac_try) 2>&5
++  ac_status=$?
++  echo "$as_me:$LINENO: \$? = $ac_status" >&5
++  (exit $ac_status); }; }; then
++  build_id_flag=yes
++else
++  echo "$as_me: failed program was:" >&5
++sed 's/^/| /' conftest.$ac_ext >&5
++
++build_id_flag=no
++fi
++rm -f conftest.err conftest.$ac_objext \
++      conftest$ac_exeext conftest.$ac_ext
++echo "$as_me:$LINENO: result: $build_id_flag" >&5
++echo "${ECHO_T}$build_id_flag" >&6
++LDFLAGS="$save_LDFLAGS"
++if test "x$build_id_flag" = xyes; then
++  LDFLAGS="$LDFLAGS -Wl,--build-id=none"
++fi
++
+ if test "x$with_binutils" != x; then
+   # Extract the first word of "objcopy", so it can be a program name with 
args.
+ set dummy objcopy; ac_word=$2
+@@ -3892,7 +3950,7 @@ echo "$as_me: error: ${CC-cc} cannot com
+ fi
+ grub_cv_prog_objcopy_absolute=yes
+ for link_addr in 2000 8000 7C00; do
+-  if { ac_try='${CC-cc} ${CFLAGS} -nostdlib -Wl,-N -Wl,-Ttext -Wl,$link_addr 
conftest.o -o conftest.exec'
++  if { ac_try='${CC-cc} ${CFLAGS} ${LDFLAGS} -nostdlib -Wl,-N -Wl,-Ttext 
-Wl,$link_addr conftest.o -o conftest.exec'
+   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+   (eval $ac_try) 2>&5
+   ac_status=$?
+diff -uprN grub-0.97/configure.ac grub/configure.ac
+--- grub-0.97/configure.ac     2005-05-08 03:36:03.000000000 +0100
++++ grub/configure.ac  2008-04-10 23:26:50.000000000 +0100
+@@ -86,13 +86,13 @@ if test "x$ac_cv_prog_gcc" = xyes; then
+     fi
+     STAGE1_CFLAGS="-O2"
+     GRUB_CFLAGS="-O2"
+-    AC_CACHE_CHECK([whether optimization for size works], size_flag, [
++    AC_CACHE_CHECK([whether optimization for size works], grub_cv_cc_Os, [
+       saved_CFLAGS=$CFLAGS
+       CFLAGS="-Os -g"
+-      AC_TRY_COMPILE(, , size_flag=yes, size_flag=no)
++      AC_TRY_COMPILE(, , grub_cv_cc_Os=yes, grub_cv_cc_Os=no)
+       CFLAGS=$saved_CFLAGS
+     ])
+-    if test "x$size_flag" = xyes; then
++    if test "x$grub_cv_cc_Os" = xyes; then
+       STAGE2_CFLAGS="-Os"
+     else
+       STAGE2_CFLAGS="-O2 -fno-strength-reduce -fno-unroll-loops"
+@@ -100,16 +100,16 @@ if test "x$ac_cv_prog_gcc" = xyes; then
+     # OpenBSD has a GCC extension for protecting applications from
+     # stack smashing attacks, but GRUB doesn't want this feature.
+     AC_CACHE_CHECK([whether gcc has -fno-stack-protector],
+-                 no_stack_protector_flag, [
++                 grub_cv_cc_no_stack_protector, [
+       saved_CFLAGS=$CFLAGS
+       CFLAGS="-fno-stack-protector"
+       AC_TRY_COMPILE(,
+                    ,
+-                   no_stack_protector_flag=yes,
+-                   no_stack_protector_flag=no)
++                   grub_cv_cc_no_stack_protector=yes,
++                   grub_cv_cc_no_stack_protector=no)
+       CFLAGS=$saved_CFLAGS
+     ])
+-    if test "x$no_stack_protector_flag" = xyes; then
++    if test "x$grub_cv_cc_no_stack_protector" = xyes; then
+       STAGE2_CFLAGS="$STAGE2_CFLAGS -fno-stack-protector"
+     fi
+   fi
+@@ -123,33 +123,44 @@ AC_SUBST(GRUB_CFLAGS)
+ CPPFLAGS="$CPPFLAGS -Wall -Wmissing-prototypes -Wunused -Wshadow"
+ CPPFLAGS="$CPPFLAGS -Wpointer-arith"
+ 
+-AC_CACHE_CHECK([whether -Wundef works], undef_flag, [
++AC_CACHE_CHECK([whether -Wundef works], grub_cv_cc_Wundef, [
+   saved_CPPFLAGS="$CPPFLAGS"
+   CPPFLAGS="-Wundef"
+-  AC_TRY_COMPILE(, , undef_flag=yes, undef_flag=no)
++  AC_TRY_COMPILE(, , grub_cv_cc_Wundef=yes, grub_cv_cc_Wundef=no)
+   CPPFLAGS="$saved_CPPFLAGS"
+ ])
+ 
+ # The options `-falign-*' are supported by gcc 3.0 or later.
+ # Probably it is sufficient to only check for -falign-loops.
+-AC_CACHE_CHECK([whether -falign-loops works], [falign_loop_flag], [
++AC_CACHE_CHECK([whether -falign-loops works], [grub_cv_cc_falign_loop], [
+   saved_CPPFLAGS="$CPPFLAGS"
+   CPPFLAGS="-falign-loops=1"
+-  AC_TRY_COMPILE(, , [falign_loop_flag=yes], [falign_loop_flag=no])
++  AC_TRY_COMPILE(, , [grub_cv_cc_falign_loop=yes], 
[grub_cv_cc_falign_loop=no])
+   CPPFLAGS="$saved_CPPFLAGS"
+ ])
+ 
+ # Force no alignment to save space.
+-if test "x$falign_loop_flag" = xyes; then
++if test "x$grub_cv_cc_falign_loop" = xyes; then
+   CPPFLAGS="$CPPFLAGS -falign-jumps=1 -falign-loops=1 -falign-functions=1"
+ else
+   CPPFLAGS="$CPPFLAGS -malign-jumps=1 -malign-loops=1 -malign-functions=1"
+ fi
+ 
+-if test "x$undef_flag" = xyes; then
++if test "x$grub_cv_cc_Wundef" = xyes; then
+   CPPFLAGS="$CPPFLAGS -Wundef"
+ fi
+ 
++# Check if build ID can be disabled in the linker
++AC_MSG_CHECKING([whether linker accepts `--build-id=none'])
++save_LDFLAGS="$LDFLAGS"
++LDFLAGS="$LDFLAGS -Wl,--build-id=none"
++AC_TRY_LINK(, , build_id_flag=yes, build_id_flag=no)
++AC_MSG_RESULT([$build_id_flag])
++LDFLAGS="$save_LDFLAGS"
++if test "x$build_id_flag" = xyes; then
++  LDFLAGS="$LDFLAGS -Wl,--build-id=none"
++fi
++
+ if test "x$with_binutils" != x; then
+ dnl  AC_PATH_TOOL(OBJCOPY, objcopy, , "$with_binutils:$PATH")
+   AC_PATH_PROG(OBJCOPY, objcopy, , "$with_binutils:$PATH")
+diff -uprN grub-0.97/docs/grub.8 grub/docs/grub.8
+--- grub-0.97/docs/grub.8      2005-05-08 03:48:56.000000000 +0100
++++ grub/docs/grub.8   2006-06-24 15:40:02.000000000 +0100
+@@ -1,5 +1,5 @@
+ .\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.23.
+-.TH GRUB "8" "May 2005" "grub (GNU GRUB 0.97)" FSF
++.TH GRUB "8" "June 2006" "grub (GNU GRUB 0.97)" FSF
+ .SH NAME
+ grub \- the grub shell
+ .SH SYNOPSIS
+diff -uprN grub-0.97/docs/grub-install.8 grub/docs/grub-install.8
+--- grub-0.97/docs/grub-install.8      2005-05-08 03:48:56.000000000 +0100
++++ grub/docs/grub-install.8   2006-06-24 15:40:02.000000000 +0100
+@@ -1,5 +1,5 @@
+ .\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.23.
+-.TH GRUB-INSTALL "8" "May 2005" "grub-install (GNU GRUB 0.97)" FSF
++.TH GRUB-INSTALL "8" "June 2006" "grub-install (GNU GRUB 0.97)" FSF
+ .SH NAME
+ grub-install \- install GRUB on your drive
+ .SH SYNOPSIS
+diff -uprN grub-0.97/docs/grub-md5-crypt.8 grub/docs/grub-md5-crypt.8
+--- grub-0.97/docs/grub-md5-crypt.8    2005-05-08 03:48:56.000000000 +0100
++++ grub/docs/grub-md5-crypt.8 2006-06-24 15:40:02.000000000 +0100
+@@ -1,5 +1,5 @@
+ .\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.23.
+-.TH GRUB-MD5-CRYPT "8" "May 2005" "grub-md5-crypt (GNU GRUB )" FSF
++.TH GRUB-MD5-CRYPT "8" "June 2006" "grub-md5-crypt (GNU GRUB )" FSF
+ .SH NAME
+ grub-md5-crypt \- Encrypt a password in MD5 format
+ .SH SYNOPSIS
+diff -uprN grub-0.97/docs/grub-terminfo.8 grub/docs/grub-terminfo.8
+--- grub-0.97/docs/grub-terminfo.8     2005-05-08 03:48:56.000000000 +0100
++++ grub/docs/grub-terminfo.8  2006-06-24 15:40:02.000000000 +0100
+@@ -1,5 +1,5 @@
+ .\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.23.
+-.TH GRUB-TERMINFO "8" "May 2005" "grub-terminfo (GNU GRUB 0.97)" FSF
++.TH GRUB-TERMINFO "8" "June 2006" "grub-terminfo (GNU GRUB 0.97)" FSF
+ .SH NAME
+ grub-terminfo \- Generate a terminfo command from a terminfo name
+ .SH SYNOPSIS
+diff -uprN grub-0.97/docs/grub.texi grub/docs/grub.texi
+--- grub-0.97/docs/grub.texi   2005-05-08 03:59:59.000000000 +0100
++++ grub/docs/grub.texi        2006-06-24 15:40:02.000000000 +0100
+@@ -2,22 +2,41 @@
+ @c -*-texinfo-*-
+ @c %**start of header
+ @setfilename grub.info
+-@settitle GRUB Manual
+-@c %**end of header
+-
+ @include version.texi
+-
++@settitle GNU GRUB Manual @value{VERSION}
+ @c Unify all our little indices for now.
+ @syncodeindex fn cp
+ @syncodeindex vr cp
+ @syncodeindex ky cp
+ @syncodeindex pg cp
+ @syncodeindex tp cp
++@c %**end of header
+ 
+ @footnotestyle separate
+ @paragraphindent 3
+ @finalout
+ 
++@copying
++This manual is for GNU GRUB (version @value{VERSION},
++@value{UPDATED}).
++
++Copyright @copyright{} 1999,2000,2001,2002,2004,2006 Free Software 
Foundation, Inc.
++
++@quotation
++Permission is granted to copy, distribute and/or modify this document
++under the terms of the GNU Free Documentation License, Version 1.2 or
++any later version published by the Free Software Foundation; with no
++Invariant Sections, with the Front-Cover Texts being ``A GNU Manual,''
++and with the Back-Cover Texts as in (a) below.  A copy of the
++license is included in the section entitled ``GNU Free Documentation
++License.''
++
++(a) The FSF's Back-Cover Text is: ``You have freedom to copy and modify
++this GNU Manual, like GNU software.  Copies published by the Free
++Software Foundation raise funds for GNU development.''
++@end quotation
++@end copying
++
+ @dircategory Kernel
+ @direntry
+ * GRUB: (grub).                 The GRand Unified Bootloader
+@@ -34,53 +53,16 @@
+ 
+ @setchapternewpage odd
+ 
+-@ifinfo
+-Copyright @copyright{} 1999,2000,2001,2002,2004 Free Software Foundation, Inc.
+-
+-Permission is granted to make and distribute verbatim copies of
+-this manual provided the copyright notice and this permission notice
+-are preserved on all copies.
+-
+-@ignore
+-Permission is granted to process this file through TeX and print the
+-results, provided the printed document carries a copying permission
+-notice identical to this one except for the removal of this paragraph
+-(this paragraph not being relevant to the printed manual).
+-
+-@end ignore
+-
+-Permission is granted to copy and distribute modified versions of this
+-manual under the conditions for verbatim copying, provided also that
+-the entire resulting derived work is distributed under the terms of a
+-permission notice identical to this one.
+-
+-Permission is granted to copy and distribute translations of this manual
+-into another language, under the above conditions for modified versions.
+-@end ifinfo
+-
+ @titlepage
+ @sp 10
+-@title the GRUB manual
++@title the GNU GRUB manual
+ @subtitle The GRand Unified Bootloader, version @value{VERSION}, 
@value{UPDATED}.
+ @author Gordon Matzigkeit
+ @author Yoshinori K. Okuji
+ @c The following two commands start the copyright page.
+ @page
+ @vskip 0pt plus 1filll
+-Copyright @copyright{} 1999,2000,2001,2002,2004 Free Software Foundation, Inc.
+-
+-Permission is granted to make and distribute verbatim copies of
+-this manual provided the copyright notice and this permission notice
+-are preserved on all copies.
+-Permission is granted to copy and distribute modified versions of this
+-manual under the conditions for verbatim copying, provided that the entire
+-resulting derived work is distributed under the terms of a permission
+-notice identical to this one.
+-
+-Permission is granted to copy and distribute translations of this manual
+-into another language, under the above conditions for modified versions,
+-except that this permission notice may be stated in a translation approved
+-by Free Software Foundation.
++@insertcopying
+ @end titlepage
+ 
+ @c Output the table of contents at the beginning.
+@@ -91,12 +73,14 @@ by Free Software Foundation.
+ 
+ @ifnottex
+ @node Top
+-@top GRUB manual
++@top GNU GRUB manual
+ 
+ This is the documentation of GNU GRUB, the GRand Unified Bootloader,
+ a flexible and powerful boot loader program for @sc{pc}s.
+ 
+ This edition documents version @value{VERSION}.
++
++@insertcopying
+ @end ifnottex
+ 
+ @menu
+@@ -124,6 +108,7 @@ This edition documents version @value{VE
+ * Reporting bugs::              Where you should send a bug report
+ * Future::                      Some future plans on GRUB
+ * Internals::                   Hacking GRUB
++* Copying This Manual::         Copying This Manual
+ * Index::
+ @end menu
+ 
+@@ -3965,6 +3950,16 @@ homepage}.
+ @include internals.texi
+ 
+ 
++@node Copying This Manual
++@appendix Copying This Manual
++
++@menu
++* GNU Free Documentation License::  License for copying this manual.
++@end menu
++
++@include fdl.texi
++
++
+ @node Index
+ @unnumbered Index
+ 
+diff -uprN grub-0.97/docs/Makefile.am grub/docs/Makefile.am
+--- grub-0.97/docs/Makefile.am 2003-07-09 12:45:35.000000000 +0100
++++ grub/docs/Makefile.am      2006-06-24 15:40:02.000000000 +0100
+@@ -1,5 +1,5 @@
+ info_TEXINFOS = grub.texi multiboot.texi
+-grub_TEXINFOS = internals.texi
++grub_TEXINFOS = internals.texi fdl.texi
+ EXAMPLES = boot.S kernel.c multiboot.h
+ multiboot_TEXINFOS = boot.S.texi kernel.c.texi multiboot.h.texi
+ man_MANS = grub.8 mbchk.1 grub-install.8 grub-md5-crypt.8 grub-terminfo.8
+diff -uprN grub-0.97/docs/Makefile.in grub/docs/Makefile.in
+--- grub-0.97/docs/Makefile.in 2005-05-08 03:42:34.000000000 +0100
++++ grub/docs/Makefile.in      2006-06-24 15:40:02.000000000 +0100
+@@ -202,7 +202,7 @@ sharedstatedir = @sharedstatedir@
+ sysconfdir = @sysconfdir@
+ target_alias = @target_alias@
+ info_TEXINFOS = grub.texi multiboot.texi
+-grub_TEXINFOS = internals.texi
++grub_TEXINFOS = internals.texi fdl.texi
+ EXAMPLES = boot.S kernel.c multiboot.h
+ multiboot_TEXINFOS = boot.S.texi kernel.c.texi multiboot.h.texi
+ man_MANS = grub.8 mbchk.1 grub-install.8 grub-md5-crypt.8 grub-terminfo.8
+diff -uprN grub-0.97/docs/mbchk.1 grub/docs/mbchk.1
+--- grub-0.97/docs/mbchk.1     2005-05-08 03:48:56.000000000 +0100
++++ grub/docs/mbchk.1  2006-06-24 15:40:02.000000000 +0100
+@@ -1,5 +1,5 @@
+ .\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.23.
+-.TH MBCHK "1" "May 2005" "mbchk (GNU GRUB 0.97)" FSF
++.TH MBCHK "1" "June 2006" "mbchk (GNU GRUB 0.97)" FSF
+ .SH NAME
+ mbchk \- check the format of a Multiboot kernel
+ .SH SYNOPSIS
+diff -uprN grub-0.97/docs/multiboot.texi grub/docs/multiboot.texi
+--- grub-0.97/docs/multiboot.texi      2003-07-09 12:45:36.000000000 +0100
++++ grub/docs/multiboot.texi   2006-06-24 15:40:02.000000000 +0100
+@@ -1,32 +1,28 @@
+ \input texinfo @c -*-texinfo-*-
+-@c -*-texinfo-*-
+ @c %**start of header
+ @setfilename multiboot.info
+-@settitle Multiboot Specification
+-@c %**end of header
+-
++@set VERSION 0.6.95
++@settitle Multiboot Specification version @value{VERSION}
+ @c Unify all our little indices for now.
+ @syncodeindex fn cp
+ @syncodeindex vr cp
+ @syncodeindex ky cp
+ @syncodeindex pg cp
+ @syncodeindex tp cp
++@c %**end of header
+ 
+ @footnotestyle separate
+ @paragraphindent 3
+ @finalout
+ 
++@copying
++Copyright @copyright{} 1995,96 Bryan Ford <baford@@cs.utah.edu>
+ 
+-@dircategory Kernel
+-@direntry
+-* Multiboot Specification: (multiboot).               Multiboot Specification.
+-@end direntry
++Copyright @copyright{} 1995,96 Erich Stefan Boleyn <erich@@uruk.org>
+ 
+-@ifinfo
+-Copyright @copyright{} 1995, 96 Bryan Ford <baford@@cs.utah.edu>
+-Copyright @copyright{} 1995, 96 Erich Stefan Boleyn <erich@@uruk.org>
+-Copyright @copyright{} 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
++Copyright @copyright{} 1999,2000,2001,2002,2005,2006 Free Software 
Foundation, Inc.
+ 
++@quotation
+ Permission is granted to make and distribute verbatim copies of
+ this manual provided the copyright notice and this permission notice
+ are preserved on all copies.
+@@ -36,7 +32,6 @@ Permission is granted to process this fi
+ results, provided the printed document carries a copying permission
+ notice identical to this one except for the removal of this paragraph
+ (this paragraph not being relevant to the printed manual).
+-
+ @end ignore
+ 
+ Permission is granted to copy and distribute modified versions of this
+@@ -45,31 +40,23 @@ the entire resulting derived work is dis
+ permission notice identical to this one.
+ 
+ Permission is granted to copy and distribute translations of this manual
+-into another language, under the above conditions for modified versions.
+-@end ifinfo
++into another language, under the above conditions for modified
++versions.
++@end quotation
++@end copying
++
++@dircategory Kernel
++@direntry
++* Multiboot Specification: (multiboot).               Multiboot Specification.
++@end direntry
+ 
+ @titlepage
+ @sp 10
+-@title The Multiboot Specification
++@title The Multiboot Specification version @value{VERSION}
+ @author Yoshinori K. Okuji, Bryan Ford, Erich Stefan Boleyn, Kunihiro Ishiguro
+ @page
+-
+ @vskip 0pt plus 1filll
+-Copyright @copyright{} 1995, 96 Bryan Ford <baford@@cs.utah.edu>
+-Copyright @copyright{} 1995, 96 Erich Stefan Boleyn <erich@@uruk.org>
+-Copyright @copyright{} 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+-
+-Permission is granted to make and distribute verbatim copies of
+-this manual provided the copyright notice and this permission notice
+-are preserved on all copies.
+-
+-Permission is granted to copy and distribute modified versions of this
+-manual under the conditions for verbatim copying, provided also that
+-the entire resulting derived work is distributed under the terms of a
+-permission notice identical to this one.
+-
+-Permission is granted to copy and distribute translations of this manual
+-into another language, under the above conditions for modified versions.
++@insertcopying
+ @end titlepage
+ 
+ @finalout
+@@ -80,7 +67,9 @@ into another language, under the above c
+ @top Multiboot Specification
+ 
+ This file documents Multiboot Specification, the proposal for the boot
+-sequence standard. This edition documents version 0.6.93.
++sequence standard. This edition documents version @value{VERSION}.
++
++@insertcopying
+ @end ifnottex
+ 
+ @menu
+@@ -426,7 +415,7 @@ mode table (@pxref{Boot information form
+ kernel.
+ 
+ If bit 16 in the @samp{flags} word is set, then the fields at offsets
+-8-24 in the Multiboot header are valid, and the boot loader should use
++12-28 in the Multiboot header are valid, and the boot loader should use
+ them instead of the fields in the actual executable header to calculate
+ where to load the OS image. This information does not need to be
+ provided if the kernel image is in @sc{elf} format, but it @emph{must}
+@@ -677,7 +666,7 @@ follows:
+ @example
+ @group
+ +-------+-------+-------+-------+
+-| drive | part1 | part2 | part3 |
++| part3 | part2 | part1 | drive |
+ +-------+-------+-------+-------+
+ @end group
+ @end example
+@@ -1197,6 +1186,17 @@ Rewritten, using more strict words.
+ @item
+ The maintainer changes to the GNU GRUB maintainer team
+ @email{bug-grub@@gnu.org}, from Bryan Ford and Erich Stefan Boleyn.
++
++@item
++The byte order of the @samp{boot_device} in Multiboot information is
++reversed. This was a mistake.
++
++@item
++The offset of the address fields were wrong.
++
++@item
++The format is adapted to a newer Texinfo, and the version number is
++specified more explicitly in the title.
+ @end itemize
+ 
+ @item 0.6
+diff -uprN grub-0.97/grub/asmstub.c grub/grub/asmstub.c
+--- grub-0.97/grub/asmstub.c   2005-02-16 20:45:14.000000000 +0000
++++ grub/grub/asmstub.c        2008-03-28 13:22:28.000000000 +0000
+@@ -55,6 +55,10 @@ int grub_stage2 (void);
+ # endif /* ! BLKFLSBUF */
+ #endif /* __linux__ */
+ 
++#if defined(__FreeBSD_kernel__) || defined(__FreeBSD__)
++# include <sys/sysctl.h>
++#endif
++
+ /* We want to prevent any circularararity in our stubs, as well as
+    libc name clashes. */
+ #define WITHOUT_LIBC_STUBS 1
+@@ -777,7 +781,39 @@ get_diskinfo (int drive, struct geometry
+ 
+       /* Open read/write, or read-only if that failed. */
+       if (! read_only)
+-      disks[drive].flags = open (devname, O_RDWR);
++      {
++/* By default, kernel of FreeBSD does not allow overwriting MBR */
++#if defined(__FreeBSD_kernel__) || defined(__FreeBSD__)
++#define GEOM_SYSCTL   "kern.geom.debugflags"
++        int old_flags, flags;
++        size_t sizeof_int = sizeof (int);
++
++        if (sysctlbyname (GEOM_SYSCTL, &old_flags, &sizeof_int, NULL, 0) != 0)
++          grub_printf ("failed to get " GEOM_SYSCTL "sysctl: %s\n", strerror 
(errno));
++
++        if ((old_flags & 0x10) == 0)
++          {
++            /* "allow foot shooting", see geom(4) */
++            flags = old_flags | 0x10;
++
++            if (sysctlbyname (GEOM_SYSCTL, NULL, NULL, &flags, sizeof (int)) 
!= 0)
++              {
++                flags = old_flags;
++                grub_printf ("failed to set " GEOM_SYSCTL "sysctl: %s\n", 
strerror (errno));
++              }
++          }
++        else
++          flags = old_flags;
++#endif
++        disks[drive].flags = open (devname, O_RDWR);
++#if defined(__FreeBSD_kernel__) || defined(__FreeBSD__)
++        if (flags != old_flags)
++          {
++            if (sysctlbyname (GEOM_SYSCTL, NULL, NULL, &old_flags, sizeof 
(int)) != 0)
++              grub_printf ("failed to set " GEOM_SYSCTL "sysctl: %s\n", 
strerror (errno));
++          }
++#endif
++      }
+ 
+       if (disks[drive].flags == -1)
+       {
+@@ -926,7 +962,7 @@ hex_dump (void *buf, size_t size)
+ 
+ int
+ biosdisk (int subfunc, int drive, struct geometry *geometry,
+-        int sector, int nsec, int segment)
++        unsigned int sector, int nsec, int segment)
+ {
+   char *buf;
+   int fd = geometry->flags;
+diff -uprN grub-0.97/grub/main.c grub/grub/main.c
+--- grub-0.97/grub/main.c      2003-07-09 12:45:36.000000000 +0100
++++ grub/grub/main.c   2006-05-05 22:43:46.000000000 +0100
+@@ -32,6 +32,7 @@ int grub_stage2 (void);
+ #define WITHOUT_LIBC_STUBS 1
+ #include <shared.h>
+ #include <term.h>
++#include <device.h>
+ 
+ char *program_name = 0;
+ int use_config_file = 1;
+@@ -192,6 +193,12 @@ main (int argc, char **argv)
+             perror ("strtoul");
+             exit (1);
+           }
++        if (boot_drive >= NUM_DISKS)
++          {
++            fprintf (stderr, "boot_drive should be from 0 to %d\n",
++                     NUM_DISKS - 1);
++            exit (1);
++          }
+         break;
+ 
+       case OPT_NO_CONFIG_FILE:
+diff -uprN grub-0.97/lib/device.c grub/lib/device.c
+--- grub-0.97/lib/device.c     2005-03-28 00:14:25.000000000 +0100
++++ grub/lib/device.c  2008-03-28 13:22:28.000000000 +0000
+@@ -69,9 +69,9 @@ struct hd_geometry
+ # ifndef CDROM_GET_CAPABILITY
+ #  define CDROM_GET_CAPABILITY        0x5331  /* get capabilities */
+ # endif /* ! CDROM_GET_CAPABILITY */
+-# ifndef BLKGETSIZE
+-#  define BLKGETSIZE  _IO(0x12,96)    /* return device size */
+-# endif /* ! BLKGETSIZE */
++# ifndef BLKGETSIZE64
++#  define BLKGETSIZE64        _IOR(0x12,114,size_t)   /* return device size */
++# endif /* ! BLKGETSIZE64 */
+ #endif /* __linux__ */
+ 
+ /* Use __FreeBSD_kernel__ instead of __FreeBSD__ for compatibility with
+@@ -152,19 +152,19 @@ get_drive_geometry (struct geometry *geo
+   /* Linux */
+   {
+     struct hd_geometry hdg;
+-    unsigned long nr;
++    unsigned long long nr;
+     
+     if (ioctl (fd, HDIO_GETGEO, &hdg))
+       goto fail;
+ 
+-    if (ioctl (fd, BLKGETSIZE, &nr))
++    if (ioctl (fd, BLKGETSIZE64, &nr))
+       goto fail;
+     
+     /* Got the geometry, so save it. */
+     geom->cylinders = hdg.cylinders;
+     geom->heads = hdg.heads;
+     geom->sectors = hdg.sectors;
+-    geom->total_sectors = nr;
++    geom->total_sectors = nr / 512;
+     
+     goto success;
+   }
+@@ -407,6 +407,12 @@ get_ataraid_disk_name (char *name, int u
+ {
+   sprintf (name, "/dev/ataraid/d%c", unit + '0');
+ }
++
++static void
++get_i2o_disk_name (char *name, char unit)
++{
++  sprintf (name, "/dev/i2o/hd%c", unit);
++}
+ #endif
+ 
+ /* Check if DEVICE can be read. If an error occurs, return zero,
+@@ -801,6 +807,29 @@ init_device_map (char ***map, const char
+         }
+       }
+   }
++    
++  /* This is for I2O - we have /dev/i2o/hd<logical drive><partition> */
++  {
++    int unit;
++
++    for (unit = 'a'; unit < 'f'; unit++)
++      {
++        char name[24];
++    
++        get_i2o_disk_name (name, unit);
++        if (check_device (name))
++          {
++              (*map)[num_hd + 0x80] = strdup (name);
++                  assert ((*map)[num_hd + 0x80]);
++                  
++          /* If the device map file is opened, write the map.  */
++               if (fp)
++                     fprintf (fp, "(hd%d)\t%s\n", num_hd, name);
++                     
++          num_hd++;
++          }
++      }
++  }
+ #endif /* __linux__ */
+   
+   /* OK, close the device map file if opened.  */
+@@ -861,6 +890,12 @@ write_to_partition (char **map, int driv
+       if (strcmp (dev + strlen(dev) - 5, "/disc") == 0)
+       strcpy (dev + strlen(dev) - 5, "/part");
+     }
++  else
++    {
++      if ((strncmp (dev, "/dev/ataraid/", 13) == 0) ||
++         (strncmp (dev, "/dev/rd/", 8) == 0))
++        strcpy (dev + strlen(dev), "p");
++    }
+   sprintf (dev + strlen(dev), "%d", ((partition >> 16) & 0xFF) + 1);
+   
+   /* Open the partition.  */
+diff -uprN grub-0.97/netboot/3c509.c grub/netboot/3c509.c
+--- grub-0.97/netboot/3c509.c  2003-07-09 12:45:37.000000000 +0100
++++ grub/netboot/3c509.c       2002-01-02 21:56:40.000000000 +0000
+@@ -18,7 +18,7 @@ Author: Martin Renters.
+ 
+ 3c509 support added by Serge Babkin (babkin@xxxxxxxxxxxxxx)
+ 
+-$Id: 3c509.c,v 1.4 2002/01/02 21:56:40 okuji Exp $
++$Id: 3c509.c 609 2002-01-02 21:56:40Z okuji $
+ 
+ ***************************************************************************/
+ 
+diff -uprN grub-0.97/netboot/cs89x0.c grub/netboot/cs89x0.c
+--- grub-0.97/netboot/cs89x0.c 2003-07-09 12:45:37.000000000 +0100
++++ grub/netboot/cs89x0.c      2008-05-20 12:04:18.000000000 +0100
+@@ -1,3 +1,21 @@
++/**
++   Per an email message from Russ Nelson <nelson@xxxxxxxxxx> on
++   18 March 2008 this file is now licensed under GPL Version 2.
++
++   From: Russ Nelson <nelson@xxxxxxxxxx>
++   Date: Tue, 18 Mar 2008 12:42:00 -0400
++   Subject: Re: [Etherboot-developers] cs89x0 driver in etherboot
++   -- quote from email
++   As copyright holder, if I say it doesn't conflict with the GPL,
++   then it doesn't conflict with the GPL.
++
++   However, there's no point in causing people's brains to overheat,
++   so yes, I grant permission for the code to be relicensed under the
++   GPLv2.  Please make sure that this change in licensing makes its
++   way upstream.  -russ
++   -- quote from email
++**/
++
+ /* cs89x0.c: A Crystal Semiconductor CS89[02]0 driver for etherboot. */
+ /*
+   Permission is granted to distribute the enclosed cs89x0.[ch] driver
+diff -uprN grub-0.97/netboot/cs89x0.h grub/netboot/cs89x0.h
+--- grub-0.97/netboot/cs89x0.h 2003-07-09 12:45:37.000000000 +0100
++++ grub/netboot/cs89x0.h      2008-05-20 12:04:18.000000000 +0100
+@@ -1,3 +1,21 @@
++/**
++   Per an email message from Russ Nelson <nelson@xxxxxxxxxx> on
++   18 March 2008 this file is now licensed under GPL Version 2.
++
++   From: Russ Nelson <nelson@xxxxxxxxxx>
++   Date: Tue, 18 Mar 2008 12:42:00 -0400
++   Subject: Re: [Etherboot-developers] cs89x0 driver in etherboot
++   -- quote from email
++   As copyright holder, if I say it doesn't conflict with the GPL,
++   then it doesn't conflict with the GPL.
++
++   However, there's no point in causing people's brains to overheat,
++   so yes, I grant permission for the code to be relicensed under the
++   GPLv2.  Please make sure that this change in licensing makes its
++   way upstream.  -russ
++   -- quote from email
++**/
++
+ /*  Copyright, 1988-1992, Russell Nelson, Crynwr Software
+ 
+    This program is free software; you can redistribute it and/or modify
+diff -uprN grub-0.97/netboot/etherboot.h grub/netboot/etherboot.h
+--- grub-0.97/netboot/etherboot.h      2003-07-09 12:45:37.000000000 +0100
++++ grub/netboot/etherboot.h   2006-09-08 13:56:22.000000000 +0100
+@@ -531,9 +531,6 @@ extern int ip_abort;
+ extern int network_ready;
+ extern struct rom_info rom;
+ extern struct arptable_t arptable[MAX_ARP];
+-extern struct bootpd_t bootp_data;
+-#define       BOOTP_DATA_ADDR (&bootp_data)
+-extern unsigned char *end_of_rfc1533;
+ 
+ /* config.c */
+ extern struct nic nic;
+diff -uprN grub-0.97/netboot/main.c grub/netboot/main.c
+--- grub-0.97/netboot/main.c   2004-05-20 23:19:33.000000000 +0100
++++ grub/netboot/main.c        2006-09-08 13:56:22.000000000 +0100
+@@ -56,7 +56,8 @@ static int vendorext_isvalid;
+ static unsigned long netmask;
+ static struct bootpd_t bootp_data;
+ static unsigned long xid;
+-static unsigned char *end_of_rfc1533 = NULL;
++
++#define       BOOTP_DATA_ADDR (&bootp_data)
+ 
+ #ifndef       NO_DHCP_SUPPORT
+ #endif /* NO_DHCP_SUPPORT */
+@@ -967,7 +968,6 @@ decode_rfc1533 (unsigned char *p, int bl
+   
+   if (block == 0)
+     {
+-      end_of_rfc1533 = NULL;
+       vendorext_isvalid = 0;
+       
+       if (grub_memcmp (p, rfc1533_cookie, 4))
+@@ -1021,7 +1021,7 @@ decode_rfc1533 (unsigned char *p, int bl
+       }
+       else if (c == RFC1533_END)
+       {
+-        end_of_rfc1533 = endp = p;
++        endp = p;
+         continue;
+       }
+       else if (c == RFC1533_NETMASK)
+diff -uprN grub-0.97/netboot/natsemi.c grub/netboot/natsemi.c
+--- grub-0.97/netboot/natsemi.c        2003-07-09 12:45:38.000000000 +0100
++++ grub/netboot/natsemi.c     2006-09-10 08:26:10.000000000 +0100
+@@ -608,7 +608,7 @@ natsemi_transmit(struct nic  *nic,
+                const char  *p)     /* Packet */
+ {
+     u32 status, to, nstype;
+-    u32 tx_status;
++    volatile u32 tx_status;
+     
+     /* Stop the transmitter */
+     outl(TxOff, ioaddr + ChipCmd);
+@@ -647,7 +647,7 @@ natsemi_transmit(struct nic  *nic,
+ 
+     to = currticks() + TX_TIMEOUT;
+ 
+-    while ((((volatile u32) tx_status=txd.cmdsts) & OWN) && (currticks() < 
to))
++    while (((tx_status=txd.cmdsts) & OWN) && (currticks() < to))
+         /* wait */ ;
+ 
+     if (currticks() >= to) {
+diff -uprN grub-0.97/netboot/sis900.c grub/netboot/sis900.c
+--- grub-0.97/netboot/sis900.c 2003-07-09 12:45:38.000000000 +0100
++++ grub/netboot/sis900.c      2006-09-10 08:26:10.000000000 +0100
+@@ -901,7 +901,7 @@ sis900_transmit(struct nic  *nic,
+                 const char  *p)     /* Packet */
+ {
+     u32 status, to, nstype;
+-    u32 tx_status;
++    volatile u32 tx_status;
+     
+     /* Stop the transmitter */
+     outl(TxDIS, ioaddr + cr);
+@@ -940,7 +940,7 @@ sis900_transmit(struct nic  *nic,
+ 
+     to = currticks() + TX_TIMEOUT;
+ 
+-    while ((((volatile u32) tx_status=txd.cmdsts) & OWN) && (currticks() < 
to))
++    while (((tx_status=txd.cmdsts) & OWN) && (currticks() < to))
+         /* wait */ ;
+ 
+     if (currticks() >= to) {
+diff -uprN grub-0.97/netboot/sk_g16.c grub/netboot/sk_g16.c
+--- grub-0.97/netboot/sk_g16.c 2003-07-09 12:45:38.000000000 +0100
++++ grub/netboot/sk_g16.c      2002-01-02 21:56:40.000000000 +0000
+@@ -13,12 +13,12 @@ Changes to make it work with Etherboot b
+  *
+  * Module         : sk_g16.c
+  *
+- * Version        : $Revision: 1.4 $
++ * Version        : $Revision: 609 $
+  *
+  * Author         : Patrick J.D. Weichmann
+  *
+  * Date Created   : 94/05/26
+- * Last Updated   : $Date: 2002/01/02 21:56:40 $
++ * Last Updated   : $Date: 2002-01-02 21:56:40 +0000 (mer 02 jan 2002) $
+  *
+  * Description    : Schneider & Koch G16 Ethernet Device Driver for
+  *                  Linux Kernel >= 1.1.22
+diff -uprN grub-0.97/netboot/sk_g16.h grub/netboot/sk_g16.h
+--- grub-0.97/netboot/sk_g16.h 2003-07-09 12:45:38.000000000 +0100
++++ grub/netboot/sk_g16.h      2000-07-29 20:22:54.000000000 +0100
+@@ -4,7 +4,7 @@
+  * of the GNU Public License, incorporated herein by reference.
+  *
+  * Module         : sk_g16.h
+- * Version        : $Revision: 1.3 $
++ * Version        : $Revision: 388 $
+  *
+  * Author         : M.Hipp (mhipp@xxxxxxxxxxxxxxxxxxxxxxxx)
+  * changes by     : Patrick J.D. Weichmann
+@@ -15,8 +15,8 @@
+  *                  the am7990 (LANCE) chip used for writing a
+  *                  network device driver which uses this chip
+  *
+- * $Log: sk_g16.h,v $
+- * Revision 1.3  2000/07/29 19:22:54  okuji
++ * $Log$
++ * Revision 1.3  2000-07-29 19:22:54  okuji
+  * update the network support to etherboot-4.6.4.
+  *
+ -*/
+diff -uprN grub-0.97/stage1/Makefile.am grub/stage1/Makefile.am
+--- grub-0.97/stage1/Makefile.am       2004-07-16 12:44:56.000000000 +0100
++++ grub/stage1/Makefile.am    2007-11-05 01:29:46.000000000 +0000
+@@ -5,7 +5,7 @@ CLEANFILES = $(nodist_pkglib_DATA)
+ 
+ # We can't use builtins or standard includes.
+ AM_CCASFLAGS = $(STAGE1_CFLAGS) -fno-builtin -nostdinc
+-LDFLAGS = -nostdlib -Wl,-N,-Ttext,7C00
++stage1_exec_LDFLAGS = -nostdlib -Wl,-N,-Ttext,7C00
+ 
+ noinst_PROGRAMS = stage1.exec
+ stage1_exec_SOURCES = stage1.S stage1.h
+diff -uprN grub-0.97/stage1/Makefile.in grub/stage1/Makefile.in
+--- grub-0.97/stage1/Makefile.in       2005-05-08 03:42:36.000000000 +0100
++++ grub/stage1/Makefile.in    2007-11-05 01:29:46.000000000 +0000
+@@ -110,7 +110,7 @@ INSTALL_DATA = @INSTALL_DATA@
+ INSTALL_PROGRAM = @INSTALL_PROGRAM@
+ INSTALL_SCRIPT = @INSTALL_SCRIPT@
+ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+-LDFLAGS = -nostdlib -Wl,-N,-Ttext,7C00
++LDFLAGS = @LDFLAGS@
+ LIBOBJS = @LIBOBJS@
+ LIBS = @LIBS@
+ LTLIBOBJS = @LTLIBOBJS@
+@@ -188,6 +188,7 @@ CLEANFILES = $(nodist_pkglib_DATA)
+ 
+ # We can't use builtins or standard includes.
+ AM_CCASFLAGS = $(STAGE1_CFLAGS) -fno-builtin -nostdinc
++stage1_exec_LDFLAGS = -nostdlib -Wl,-N,-Ttext,7C00
+ stage1_exec_SOURCES = stage1.S stage1.h
+ SUFFIXES = .exec
+ all: all-am
+diff -uprN grub-0.97/stage2/bios.c grub/stage2/bios.c
+--- grub-0.97/stage2/bios.c    2004-03-27 16:34:04.000000000 +0000
++++ grub/stage2/bios.c 2008-03-28 13:22:28.000000000 +0000
+@@ -47,7 +47,7 @@ extern int get_diskinfo_floppy (int driv
+    return the error number. Otherwise, return 0.  */
+ int
+ biosdisk (int read, int drive, struct geometry *geometry,
+-        int sector, int nsec, int segment)
++        unsigned int sector, int nsec, int segment)
+ {
+   int err;
+   
+diff -uprN grub-0.97/stage2/boot.c grub/stage2/boot.c
+--- grub-0.97/stage2/boot.c    2004-03-30 12:44:08.000000000 +0100
++++ grub/stage2/boot.c 2005-09-28 22:47:55.000000000 +0100
+@@ -1,7 +1,7 @@
+ /* boot.c - load and bootstrap a kernel */
+ /*
+  *  GRUB  --  GRand Unified Bootloader
+- *  Copyright (C) 1999,2000,2001,2002,2003,2004  Free Software Foundation, 
Inc.
++ *  Copyright (C) 1999,2000,2001,2002,2003,2004,2005  Free Software 
Foundation, Inc.
+  *
+  *  This program is free software; you can redistribute it and/or modify
+  *  it under the terms of the GNU General Public License as published by
+@@ -96,7 +96,7 @@ load_image (char *kernel, char *arg, ker
+   lh = (struct linux_kernel_header *) buffer;
+   
+   /* ELF loading supported if multiboot, FreeBSD and NetBSD.  */
+-  if ((type == KERNEL_TYPE_MULTIBOOT
++  if (((type == KERNEL_TYPE_MULTIBOOT && ! (flags & MULTIBOOT_AOUT_KLUDGE))
+        || pu.elf->e_ident[EI_OSABI] == ELFOSABI_FREEBSD
+        || grub_strcmp (pu.elf->e_ident + EI_BRAND, "FreeBSD") == 0
+        || suggested_type == KERNEL_TYPE_NETBSD)
+diff -uprN grub-0.97/stage2/builtins.c grub/stage2/builtins.c
+--- grub-0.97/stage2/builtins.c        2005-02-15 21:58:23.000000000 +0000
++++ grub/stage2/builtins.c     2006-03-21 20:51:58.000000000 +0000
+@@ -3830,15 +3830,15 @@ setup_func (char *arg, int flags)
+       {
+         char tmp[16];
+         grub_sprintf (tmp, ",%d", (partition >> 16) & 0xFF);
+-        grub_strncat (device, tmp, 256);
++        grub_strncat (device, tmp, sizeof (device));
+       }
+       if ((partition & 0x00FF00) != 0x00FF00)
+       {
+         char tmp[16];
+         grub_sprintf (tmp, ",%c", 'a' + ((partition >> 8) & 0xFF));
+-        grub_strncat (device, tmp, 256);
++        grub_strncat (device, tmp, sizeof (device));
+       }
+-      grub_strncat (device, ")", 256);
++      grub_strncat (device, ")", sizeof (device));
+     }
+   
+   int embed_stage1_5 (char *stage1_5, int drive, int partition)
+diff -uprN grub-0.97/stage2/disk_io.c grub/stage2/disk_io.c
+--- grub-0.97/stage2/disk_io.c 2004-05-23 17:35:24.000000000 +0100
++++ grub/stage2/disk_io.c      2008-03-28 13:22:28.000000000 +0000
+@@ -137,7 +137,7 @@ log2 (unsigned long word)
+ }
+ 
+ int
+-rawread (int drive, int sector, int byte_offset, int byte_len, char *buf)
++rawread (int drive, unsigned int sector, int byte_offset, int byte_len, char 
*buf)
+ {
+   int slen, sectors_per_vtrack;
+   int sector_size_bits = log2 (buf_geom.sector_size);
+@@ -261,7 +261,7 @@ rawread (int drive, int sector, int byte
+        */
+       if (disk_read_func)
+       {
+-        int sector_num = sector;
++        unsigned int sector_num = sector;
+         int length = buf_geom.sector_size - byte_offset;
+         if (length > size)
+           length = size;
+@@ -291,7 +291,7 @@ rawread (int drive, int sector, int byte
+ 
+ 
+ int
+-devread (int sector, int byte_offset, int byte_len, char *buf)
++devread (unsigned int sector, int byte_offset, int byte_len, char *buf)
+ {
+   /*
+    *  Check partition boundaries
+@@ -330,7 +330,7 @@ devread (int sector, int byte_offset, in
+ 
+ #ifndef STAGE1_5
+ int
+-rawwrite (int drive, int sector, char *buf)
++rawwrite (int drive, unsigned int sector, char *buf)
+ {
+   if (sector == 0)
+     {
+@@ -363,7 +363,7 @@ rawwrite (int drive, int sector, char *b
+ }
+ 
+ int
+-devwrite (int sector, int sector_count, char *buf)
++devwrite (unsigned int sector, int sector_count, char *buf)
+ {
+ #if defined(GRUB_UTIL) && defined(__linux__)
+   if (current_partition != 0xFFFFFF
+diff -uprN grub-0.97/stage2/fsys_ffs.c grub/stage2/fsys_ffs.c
+--- grub-0.97/stage2/fsys_ffs.c        2003-07-09 12:45:52.000000000 +0100
++++ grub/stage2/fsys_ffs.c     2001-11-12 06:57:29.000000000 +0000
+@@ -50,7 +50,7 @@
+  * the rights to redistribute these changes.
+  *
+  *    from: Mach, Revision 2.2  92/04/04  11:35:49  rpd
+- *    $Id: fsys_ffs.c,v 1.10 2001/11/12 06:57:29 okuji Exp $
++ *    $Id: fsys_ffs.c 594 2001-11-12 06:57:29Z okuji $
+  */
+ 
+ #ifdef FSYS_FFS
+diff -uprN grub-0.97/stage2/fsys_ufs2.c grub/stage2/fsys_ufs2.c
+--- grub-0.97/stage2/fsys_ufs2.c       2004-06-19 13:17:52.000000000 +0100
++++ grub/stage2/fsys_ufs2.c    2004-06-19 13:17:52.000000000 +0100
+@@ -51,7 +51,7 @@
+  * the rights to redistribute these changes.
+  *
+  *    from: Mach, Revision 2.2  92/04/04  11:35:49  rpd
+- *    $Id: fsys_ufs2.c,v 1.2 2004/06/19 12:17:52 okuji Exp $
++ *    $Id: fsys_ufs2.c 841 2004-06-19 12:17:52Z okuji $
+  */
+ 
+ #ifdef FSYS_UFS2
+diff -uprN grub-0.97/stage2/imgact_aout.h grub/stage2/imgact_aout.h
+--- grub-0.97/stage2/imgact_aout.h     2003-07-09 12:45:53.000000000 +0100
++++ grub/stage2/imgact_aout.h  1999-06-24 01:03:29.000000000 +0100
+@@ -32,7 +32,7 @@
+  * SUCH DAMAGE.
+  *
+  *    from: @(#)exec.h        8.1 (Berkeley) 6/11/93
+- *    $Id: imgact_aout.h,v 1.1 1999/06/24 00:03:22 okuji Exp $
++ *    $Id: imgact_aout.h 98 1999-06-24 00:03:29Z okuji $
+  */
+ /*
+  *  11/23/95 - Kludge to get "ntohl" null macro added.  -- ESB
+diff -uprN grub-0.97/stage2/iso9660.h grub/stage2/iso9660.h
+--- grub-0.97/stage2/iso9660.h 2004-03-27 16:02:38.000000000 +0000
++++ grub/stage2/iso9660.h      2007-02-22 23:40:25.000000000 +0000
+@@ -73,11 +73,11 @@ typedef    union {
+ 
+ typedef       struct __iso_16bit {
+   u_int16_t l, b;
+-} iso_16bit_t __attribute__ ((packed));
++} iso_16bit_t;
+ 
+ typedef       struct __iso_32bit {
+   u_int32_t l, b;
+-} iso_32bit_t __attribute__ ((packed));
++} iso_32bit_t;
+ 
+ typedef u_int8_t              iso_date_t[7];
+ 
+diff -uprN grub-0.97/stage2/shared.h grub/stage2/shared.h
+--- grub-0.97/stage2/shared.h  2004-06-19 17:40:09.000000000 +0100
++++ grub/stage2/shared.h       2008-03-28 13:22:28.000000000 +0000
+@@ -499,7 +499,11 @@ struct vbe_mode
+   unsigned char linear_reserved_field_position;
+   unsigned long max_pixel_clock;
+ 
+-  unsigned char reserved3[189];
++  /* Reserved field to make structure to be 256 bytes long, VESA BIOS 
++     Extension 3.0 Specification says to reserve 189 bytes here but 
++     that doesn't make structure to be 256 bytes.  So additional one is 
++     added here.  */
++  unsigned char reserved3[189 + 1];
+ } __attribute__ ((packed));
+ 
+ 
+@@ -807,7 +811,7 @@ int checkkey (void);
+ /* Low-level disk I/O */
+ int get_diskinfo (int drive, struct geometry *geometry);
+ int biosdisk (int subfunc, int drive, struct geometry *geometry,
+-            int sector, int nsec, int segment);
++            unsigned int sector, int nsec, int segment);
+ void stop_floppy (void);
+ 
+ /* Command-line interface functions. */
+@@ -920,10 +924,10 @@ int gunzip_test_header (void);
+ int gunzip_read (char *buf, int len);
+ #endif /* NO_DECOMPRESSION */
+ 
+-int rawread (int drive, int sector, int byte_offset, int byte_len, char *buf);
+-int devread (int sector, int byte_offset, int byte_len, char *buf);
+-int rawwrite (int drive, int sector, char *buf);
+-int devwrite (int sector, int sector_len, char *buf);
++int rawread (int drive, unsigned int sector, int byte_offset, int byte_len, 
char *buf);
++int devread (unsigned int sector, int byte_offset, int byte_len, char *buf);
++int rawwrite (int drive, unsigned int sector, char *buf);
++int devwrite (unsigned int sector, int sector_len, char *buf);
+ 
+ /* Parse a device string and initialize the global parameters. */
+ char *set_device (char *device);
+diff -uprN grub-0.97/stage2/stage2.c grub/stage2/stage2.c
+--- grub-0.97/stage2/stage2.c  2005-03-19 17:51:57.000000000 +0000
++++ grub/stage2/stage2.c       2006-05-05 23:06:31.000000000 +0100
+@@ -651,7 +651,10 @@ restart:
+                 *(new_heap++) = 0;
+ 
+                 if (config_entries)
+-                  run_menu (heap, NULL, new_num_entries, new_heap, 0);
++                  {
++                    current_entryno = first_entry + entryno;
++                    run_menu (heap, NULL, new_num_entries, new_heap, 0);
++                  }
+                 else
+                   {
+                     cls ();
+@@ -727,7 +730,8 @@ restart:
+       cur_entry = get_entry (config_entries, first_entry + entryno, 1);
+ 
+       /* Set CURRENT_ENTRYNO for the command "savedefault".  */
+-      current_entryno = first_entry + entryno;
++      if (config_entries)
++      current_entryno = first_entry + entryno;
+       
+       if (run_script (cur_entry, heap))
+       {
+diff -uprN grub-0.97/stage2/tparm.c grub/stage2/tparm.c
+--- grub-0.97/stage2/tparm.c   2003-07-09 12:45:53.000000000 +0100
++++ grub/stage2/tparm.c        2002-11-29 20:39:24.000000000 +0000
+@@ -63,7 +63,7 @@ typedef char grub_bool;
+ #define MAX_FORMAT_LEN 256
+ #define max(a,b) ((a) > (b) ? (a) : (b))
+ 
+-//MODULE_ID("$Id: tparm.c,v 1.1 2002/11/29 20:39:24 okuji Exp $")
++//MODULE_ID("$Id: tparm.c 708 2002-11-29 20:39:24Z okuji $")
+ 
+ /*
+  *    char *
+diff -uprN grub-0.97/stamp-h.in grub/stamp-h.in
+--- grub-0.97/stamp-h.in       1970-01-01 01:00:00.000000000 +0100
++++ grub/stamp-h.in    1999-09-13 14:32:31.000000000 +0100
+@@ -0,0 +1 @@
++timestamp
+diff -uprN grub-0.97/THANKS grub/THANKS
+--- grub-0.97/THANKS   2005-05-08 03:17:43.000000000 +0100
++++ grub/THANKS        2006-03-21 20:51:58.000000000 +0000
+@@ -121,3 +121,4 @@ Vesa Jaaskelainen <jaaskela@tietomyrsky.
+ Yedidyah Bar-David <didi@xxxxxxxxxxxxxx>
+ Yury V. Umanets <umka@xxxxxxxxxxx>
+ Yuri Zaporogets <yuriz@xxxxxxx>
++Vitaly Fertman <vitaly@xxxxxxxxxxx>
+diff -uprN grub-0.97/util/grub-install.in grub/util/grub-install.in
+--- grub-0.97/util/grub-install.in     2004-07-24 19:57:31.000000000 +0100
++++ grub/util/grub-install.in  2006-04-20 14:46:46.000000000 +0100
+@@ -112,8 +112,8 @@ convert () {
+       tmp_disk=`echo "$1" | sed 's%\([sh]d[0-9]*\).*%\1%'`
+       tmp_part=`echo "$1" | sed "s%$tmp_disk%%"` ;;
+     freebsd* | kfreebsd*-gnu)
+-      tmp_disk=`echo "$1" | sed 's%r\{0,1\}\([saw]d[0-9]*\).*$%r\1%' \
+-                          | sed 's%r\{0,1\}\(da[0-9]*\).*$%r\1%'`
++      tmp_disk=`echo "$1" | sed 's%r\{0,1\}\([saw]d[0-9]*\).*$%\1%' \
++                          | sed 's%r\{0,1\}\(da[0-9]*\).*$%\1%'`
+       tmp_part=`echo "$1" \
+           | sed "s%.*/r\{0,1\}[saw]d[0-9]\(s[0-9]*[a-h]\)%\1%" \
+                   | sed "s%.*/r\{0,1\}da[0-9]\(s[0-9]*[a-h]\)%\1%"`
+diff -uprN grub-0.97/util/mkbimage grub/util/mkbimage
+--- grub-0.97/util/mkbimage    2004-07-24 19:57:31.000000000 +0100
++++ grub/util/mkbimage 2007-02-22 16:01:03.000000000 +0000
+@@ -1,7 +1,7 @@
+ #!/bin/sh
+ # MaKe a Bootable IMAGE --- 1.44, 2.88 and El Torito no-emulation mode
+ # C) 2001,2002,2003 Thierry Laronde <tlaronde@xxxxxxxxxxx>
+-# C) 2001,2002,2003 Robert Millan <robertmh@xxxxxxx>
++# C) 2001,2002,2003 Robert Millan <rmh@xxxxxxxxxxx>
+ 
+ 
+ # This program is free software; you can redistribute it and/or modify
+@@ -19,7 +19,7 @@
+ # program's maintainer or write to: The Free Software Foundation,
+ # Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.
+ 
+-# $Id: mkbimage,v 1.19 2004/07/21 14:43:04 robertmh Exp $
++# $Id: mkbimage 1233 2007-02-22 16:01:03Z robertmh $
+ 
+ # Global variables
+ tarfile=
+@@ -58,7 +58,7 @@ stage2_os_name=
+ 
+ # Name by which this script was invoked.
+ program=`echo "$0" | sed -e 's/[^\/]*\///g'`
+-version_number='$Revision: 1.19 $'
++version_number='$Revision: 1233 $'
+ 
+ usage="
+ Usage: $program [-hVF] [-t TYPE] [-d DIRECTORY] [-s FS_TYPE] -f TAR_FILE
+@@ -94,15 +94,13 @@ Options:
+           display Version information and exit
+ 
+ Copyright (c) 2001,2002,2003 Thierry Laronde <tlaronde@xxxxxxxxxxx>. 
+-Copyright (c) 2001,2002 Robert Millan <zeratul2@xxxxxxxxxx>.
+ GPLed."
+ 
+ version="mkbimage $version_number
+ 
+-Written by Thierry Laronde and Robert Millan.
++Written by Thierry Laronde.
+ 
+ Copyright (c) 2001,2002,2003 Thierry Laronde <tlaronde@xxxxxxxxxxx>.
+-Copyright (c) 2001,2002,2003 Robert Millan <zeratul2@xxxxxxxxxx>.
+ 
+ This is free software under the GPL version 2 or later; see the source for 
+ copying conditions.  There is NO warranty, not even for MERCHANTABILITY or 
diff -r eb0fc71cfc72 -r 400e5d4877ca stubdom/grub.patches/99minios
--- a/stubdom/grub.patches/99minios     Tue Jul 08 11:41:43 2008 +0900
+++ b/stubdom/grub.patches/99minios     Fri Jul 18 12:12:41 2008 +0900
@@ -1465,3 +1465,31 @@ Index: grub/stage2/stage2.c
  # endif /* SUPPORT_DISKLESS */
  
  static int preset_menu_offset;
+Index: grub/stage2/fsys_xfs.c
+===================================================================
+RCS file: /sources/grub/grub/stage2/fsys_xfs.c,v
+retrieving revision 1.5
+diff -u -p -r1.5 fsys_xfs.c
+--- grub/stage2/fsys_xfs.c     8 May 2005 02:18:14 -0000       1.5
++++ grub/stage2/fsys_xfs.c     10 Jul 2008 13:09:50 -0000
+@@ -101,7 +101,7 @@ static inline __const__ xfs_uint16_t
+ le16 (xfs_uint16_t x)
+ {
+       __asm__("xchgb %b0,%h0" \
+-              : "=q" (x) \
++              : "=Q" (x) \
+               :  "0" (x)); \
+               return x;
+ }
+@@ -109,9 +109,9 @@ le16 (xfs_uint16_t x)
+ static inline __const__ xfs_uint32_t
+ le32 (xfs_uint32_t x)
+ {
+-#if 0
++#if 1
+         /* 386 doesn't have bswap.  */
+-      __asm__("bswap %0" : "=r" (x) : "0" (x));
++      __asm__("bswapl %k0" : "=r" (x) : "0" (x));
+ #else
+       /* This is slower but this works on all x86 architectures.  */
+       __asm__("xchgb %b0, %h0" \
diff -r eb0fc71cfc72 -r 400e5d4877ca stubdom/grub/Makefile
--- a/stubdom/grub/Makefile     Tue Jul 08 11:41:43 2008 +0900
+++ b/stubdom/grub/Makefile     Fri Jul 18 12:12:41 2008 +0900
@@ -1,14 +1,14 @@ XEN_ROOT = ../..
 XEN_ROOT = ../..
 
 include $(XEN_ROOT)/Config.mk
-vpath %.c ../grub-cvs
+vpath %.c ../grub-upstream
 
 BOOT=boot-$(XEN_TARGET_ARCH).o
 
 DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/libxc -I$(XEN_ROOT)/tools/include -I.
-DEF_CPPFLAGS += -I../grub-cvs/stage1
-DEF_CPPFLAGS += -I../grub-cvs/stage2
-DEF_CPPFLAGS += -I../grub-cvs/netboot
+DEF_CPPFLAGS += -I../grub-upstream/stage1
+DEF_CPPFLAGS += -I../grub-upstream/stage2
+DEF_CPPFLAGS += -I../grub-upstream/netboot
 DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/firmware/vgabios
 DEF_CPPFLAGS += -DWITHOUT_LIBC_STUBS
 DEF_CPPFLAGS += -DSUPPORT_NETBOOT
@@ -51,10 +51,8 @@ STAGE2_SOURCES+=fsys_vstafs.c
 STAGE2_SOURCES+=fsys_vstafs.c
 CPPFLAGS += -DFSYS_VSTAFS=1
 
-ifeq (0,1)
 STAGE2_SOURCES+=fsys_xfs.c
 CPPFLAGS += -DFSYS_XFS=1
-endif
 
 STAGE2_SOURCES:=$(addprefix stage2/,$(STAGE2_SOURCES))
 NETBOOT_SOURCES:=$(addprefix netboot/,$(NETBOOT_SOURCES))
diff -r eb0fc71cfc72 -r 400e5d4877ca stubdom/grub/mini-os.c
--- a/stubdom/grub/mini-os.c    Tue Jul 08 11:41:43 2008 +0900
+++ b/stubdom/grub/mini-os.c    Fri Jul 18 12:12:41 2008 +0900
@@ -681,7 +681,9 @@ int main(int argc, char *argv[])
         config_file[sizeof(config_file) - 1] = 0;
         if (!strncmp(config_file, "(nd)", 4))
             preset_menu = "dhcp";
-    } else
+    } else if (start_info.mod_len)
+        preset_menu = (void*) start_info.mod_start;
+    else
         preset_menu = "dhcp --with-configfile";
 
     mbi.drives_addr = BOOTSEC_LOCATION + (60 * 1024);
diff -r eb0fc71cfc72 -r 400e5d4877ca stubdom/libpci.config.h
--- a/stubdom/libpci.config.h   Tue Jul 08 11:41:43 2008 +0900
+++ b/stubdom/libpci.config.h   Fri Jul 18 12:12:41 2008 +0900
@@ -1,4 +1,4 @@
-#define PCI_OS_STUBDOM
+#define PCI_OS_MINIOS
 #define PCI_HAVE_STDINT_H
 #define PCI_PATH_IDS_DIR "."
 #define PCI_COMPRESSED_IDS
diff -r eb0fc71cfc72 -r 400e5d4877ca stubdom/libpci.config.mak
--- a/stubdom/libpci.config.mak Tue Jul 08 11:41:43 2008 +0900
+++ b/stubdom/libpci.config.mak Fri Jul 18 12:12:41 2008 +0900
@@ -1,2 +1,7 @@ LIBZ=-lz
 LIBZ=-lz
 LDLIBS+=$(LIBZ)
+PCI_OS_MINIOS=1
+PCI_HAVE_STDINT_H=1
+PCI_PATH_IDS_DIR=.
+PCI_COMPRESSED_IDS=1
+PCI_IDS=pci.ids.gz
diff -r eb0fc71cfc72 -r 400e5d4877ca stubdom/lwip.patch-cvs
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/stubdom/lwip.patch-cvs    Fri Jul 18 12:12:41 2008 +0900
@@ -0,0 +1,2398 @@
+? .ChangeLog.swp
+? ChangeLog
+Index: CHANGELOG
+===================================================================
+RCS file: /sources/lwip/lwip/CHANGELOG,v
+retrieving revision 1.300
+retrieving revision 1.318
+diff -u -p -r1.300 -r1.318
+--- CHANGELOG  23 Mar 2008 13:49:39 -0000      1.300
++++ CHANGELOG  14 Jul 2008 20:12:36 -0000      1.318
+@@ -19,9 +19,77 @@ HISTORY
+ 
+   ++ New features:
+ 
++  2008-06-30 Simon Goldschmidt
++  * mem.c, opt.h, stats.h: fixed bug #21433: Calling mem_free/pbuf_free from
++    interrupt context isn't safe: LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 
allows
++    mem_free to run between mem_malloc iterations. Added illegal counter for
++    mem stats.
++
++  2008-06-27 Simon Goldschmidt
++  * stats.h/.c, some other files: patch #6483: stats module improvement:
++    Added defines to display each module's statistic individually, added stats
++    defines for MEM, MEMP and SYS modules, removed (unused) rexmit counter.
++
++  2008-06-17 Simon Goldschmidt
++  * err.h: patch #6459: Made err_t overridable to use a more efficient type
++    (define LWIP_ERR_T in cc.h)
++
++  2008-06-17 Simon Goldschmidt
++  * slipif.c: patch #6480: Added a configuration option for slipif for 
symmetry
++    to loopif
++
++  2008-06-17 Simon Goldschmidt (patch by Luca Ceresoli)
++  * netif.c, loopif.c, ip.c, netif.h, loopif.h, opt.h: Checked in slightly
++    modified version of patch # 6370: Moved loopif code to netif.c so that
++    loopback traffic is supported on all netifs (all local IPs).
++    Added option to limit loopback packets for each netifs.
++
+ 
+   ++ Bugfixes:
+ 
++  2008-08-14 Simon Goldschmidt
++  * api_msg.c: fixed bug #23847: do_close_internal references freed memory 
(when
++    tcp_close returns != ERR_OK)
++
++  2008-07-08 Frédéric Bernon
++  * stats.h: Fix some build bugs introduced with patch #6483 (missing some 
parameters
++    in macros, mainly if MEM_STATS=0 and MEMP_STATS=0).
++
++  2008-06-24 Jonathan Larmour
++  * tcp_in.c: Fix for bug #23693 as suggested by Art R. Ensure cseg is unused
++    if tcp_seg_copy fails.
++
++  2008-06-17 Simon Goldschmidt
++  * inet_chksum.c: Checked in some ideas of patch #6460 (loop optimizations)
++    and created defines for swapping bytes and folding u32 to u16.
++
++  2008-05-30 Kieran Mansley
++  * tcp_in.c Remove redundant "if" statement, and use real rcv_wnd
++    rather than rcv_ann_wnd when deciding if packets are in-window.
++    Contributed by <arasmussen@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
++
++  2008-05-30 Kieran Mansley
++  * mem.h: Fix BUG#23254.  Change macro definition of mem_* to allow
++    passing as function pointers when MEM_LIBC_MALLOC is defined.
++
++  2008-05-09 Jonathan Larmour
++  * err.h, err.c, sockets.c: Fix bug #23119: Reorder timeout error code to
++    stop it being treated as a fatal error.
++
++  2008-04-15 Simon Goldschmidt
++  * dhcp.c: fixed bug #22804: dhcp_stop doesn't clear NETIF_FLAG_DHCP
++    (flag now cleared)
++
++  2008-03-27 Simon Goldschmidt
++  * mem.c, tcpip.c, tcpip.h, opt.h: fixed bug #21433 (Calling 
mem_free/pbuf_free
++    from interrupt context isn't safe): set LWIP_USE_HEAP_FROM_INTERRUPT to 1
++    in lwipopts.h or use pbuf_free_callback(p)/mem_free_callback(m) to free 
pbufs
++    or heap memory from interrupt context
++
++  2008-03-26 Simon Goldschmidt
++  * tcp_in.c, tcp.c: fixed bug #22249: division by zero could occur if a 
remote
++    host sent a zero mss as TCP option.
++
+ 
+ (STABLE-1.3.0)
+ 
+Index: src/api/api_msg.c
+===================================================================
+RCS file: /sources/lwip/lwip/src/api/api_msg.c,v
+retrieving revision 1.102
+retrieving revision 1.104
+diff -u -p -r1.102 -r1.104
+--- src/api/api_msg.c  21 Mar 2008 16:23:14 -0000      1.102
++++ src/api/api_msg.c  15 Jul 2008 11:18:58 -0000      1.104
+@@ -598,11 +598,16 @@ do_close_internal(struct netconn *conn)
+   LWIP_ASSERT("pcb already closed", (conn->pcb.tcp != NULL));
+ 
+   /* Set back some callback pointers */
++  tcp_arg(conn->pcb.tcp, NULL);
+   if (conn->pcb.tcp->state == LISTEN) {
+-    tcp_arg(conn->pcb.tcp, NULL);
+     tcp_accept(conn->pcb.tcp, NULL);
+   } else {
+     tcp_recv(conn->pcb.tcp, NULL);
++    tcp_accept(conn->pcb.tcp, NULL);
++    /* some callbacks have to be reset if tcp_close is not successful */
++    tcp_sent(conn->pcb.tcp, NULL);
++    tcp_poll(conn->pcb.tcp, NULL, 4);
++    tcp_err(conn->pcb.tcp, NULL);
+   }
+   /* Try to close the connection */
+   err = tcp_close(conn->pcb.tcp);
+@@ -610,11 +615,6 @@ do_close_internal(struct netconn *conn)
+     /* Closing succeeded */
+     conn->state = NETCONN_NONE;
+     /* Set back some callback pointers as conn is going away */
+-    tcp_err(conn->pcb.tcp, NULL);
+-    tcp_poll(conn->pcb.tcp, NULL, 4);
+-    tcp_sent(conn->pcb.tcp, NULL);
+-    tcp_recv(conn->pcb.tcp, NULL);
+-    tcp_arg(conn->pcb.tcp, NULL);
+     conn->pcb.tcp = NULL;
+     conn->err = ERR_OK;
+     /* Trigger select() in socket layer. This send should something else so 
the
+@@ -623,6 +623,14 @@ do_close_internal(struct netconn *conn)
+     API_EVENT(conn, NETCONN_EVT_SENDPLUS, 0);
+     /* wake up the application task */
+     sys_sem_signal(conn->op_completed);
++  } else {
++    /* Closing failed, restore some of the callbacks */
++    /* Closing of listen pcb will never fail! */
++    LWIP_ASSERT("Closing a listen pcb may not fail!", (conn->pcb.tcp->state 
!= LISTEN));
++    tcp_sent(conn->pcb.tcp, sent_tcp);
++    tcp_poll(conn->pcb.tcp, poll_tcp, 4);
++    tcp_err(conn->pcb.tcp, err_tcp);
++    tcp_arg(conn->pcb.tcp, conn);
+   }
+   /* If closing didn't succeed, we get called again either
+      from poll_tcp or from sent_tcp */
+Index: src/api/err.c
+===================================================================
+RCS file: /sources/lwip/lwip/src/api/err.c,v
+retrieving revision 1.11
+retrieving revision 1.12
+diff -u -p -r1.11 -r1.12
+--- src/api/err.c      13 Dec 2007 23:06:50 -0000      1.11
++++ src/api/err.c      9 May 2008 12:14:23 -0000       1.12
+@@ -44,17 +44,17 @@ static const char *err_strerr[] = {
+            "Ok.",                    /* ERR_OK          0  */
+            "Out of memory error.",   /* ERR_MEM        -1  */
+            "Buffer error.",          /* ERR_BUF        -2  */
+-           "Routing problem.",       /* ERR_RTE        -3  */
+-           "Connection aborted.",    /* ERR_ABRT       -4  */
+-           "Connection reset.",      /* ERR_RST        -5  */
+-           "Connection closed.",     /* ERR_CLSD       -6  */
+-           "Not connected.",         /* ERR_CONN       -7  */
+-           "Illegal value.",         /* ERR_VAL        -8  */
+-           "Illegal argument.",      /* ERR_ARG        -9  */
+-           "Address in use.",        /* ERR_USE        -10 */
+-           "Low-level netif error.", /* ERR_IF         -11 */
+-           "Already connected.",     /* ERR_ISCONN     -12 */
+-           "Timeout.",               /* ERR_TIMEOUT    -13 */
++           "Timeout.",               /* ERR_TIMEOUT    -3 */
++           "Routing problem.",       /* ERR_RTE        -4  */
++           "Connection aborted.",    /* ERR_ABRT       -5  */
++           "Connection reset.",      /* ERR_RST        -6  */
++           "Connection closed.",     /* ERR_CLSD       -7  */
++           "Not connected.",         /* ERR_CONN       -8  */
++           "Illegal value.",         /* ERR_VAL        -9  */
++           "Illegal argument.",      /* ERR_ARG        -10 */
++           "Address in use.",        /* ERR_USE        -11 */
++           "Low-level netif error.", /* ERR_IF         -12 */
++           "Already connected.",     /* ERR_ISCONN     -13 */
+            "Operation in progress."  /* ERR_INPROGRESS -14 */
+ };
+ 
+Index: src/api/netdb.c
+===================================================================
+RCS file: /sources/lwip/lwip/src/api/netdb.c,v
+retrieving revision 1.4
+retrieving revision 1.5
+diff -u -p -r1.4 -r1.5
+--- src/api/netdb.c    26 Jan 2008 16:11:39 -0000      1.4
++++ src/api/netdb.c    16 Jul 2008 20:36:12 -0000      1.5
+@@ -326,7 +326,8 @@ lwip_getaddrinfo(const char *nodename, c
+   if (nodename != NULL) {
+     /* copy nodename to canonname if specified */
+     size_t namelen = strlen(nodename);
+-    ai->ai_canonname = mem_malloc(namelen + 1);
++    LWIP_ASSERT("namelen is too long", (namelen + 1) <= (mem_size_t)-1);
++    ai->ai_canonname = mem_malloc((mem_size_t)(namelen + 1));
+     if (ai->ai_canonname == NULL) {
+       goto memerr;
+     }
+Index: src/api/sockets.c
+===================================================================
+RCS file: /sources/lwip/lwip/src/api/sockets.c,v
+retrieving revision 1.116
+retrieving revision 1.117
+diff -u -p -r1.116 -r1.117
+--- src/api/sockets.c  13 Mar 2008 20:03:57 -0000      1.116
++++ src/api/sockets.c  9 May 2008 12:14:24 -0000       1.117
+@@ -128,17 +128,17 @@ static const int err_to_errno_table[] = 
+   0,             /* ERR_OK          0      No error, everything OK. */
+   ENOMEM,        /* ERR_MEM        -1      Out of memory error.     */
+   ENOBUFS,       /* ERR_BUF        -2      Buffer error.            */
+-  EHOSTUNREACH,  /* ERR_RTE        -3      Routing problem.         */
+-  ECONNABORTED,  /* ERR_ABRT       -4      Connection aborted.      */
+-  ECONNRESET,    /* ERR_RST        -5      Connection reset.        */
+-  ESHUTDOWN,     /* ERR_CLSD       -6      Connection closed.       */
+-  ENOTCONN,      /* ERR_CONN       -7      Not connected.           */
+-  EINVAL,        /* ERR_VAL        -8      Illegal value.           */
+-  EIO,           /* ERR_ARG        -9      Illegal argument.        */
+-  EADDRINUSE,    /* ERR_USE        -10     Address in use.          */
+-  -1,            /* ERR_IF         -11     Low-level netif error    */
+-  -1,            /* ERR_ISCONN     -12     Already connected.       */
+-  ETIMEDOUT,     /* ERR_TIMEOUT    -13     Timeout                  */
++  ETIMEDOUT,     /* ERR_TIMEOUT    -3      Timeout                  */
++  EHOSTUNREACH,  /* ERR_RTE        -4      Routing problem.         */
++  ECONNABORTED,  /* ERR_ABRT       -5      Connection aborted.      */
++  ECONNRESET,    /* ERR_RST        -6      Connection reset.        */
++  ESHUTDOWN,     /* ERR_CLSD       -7      Connection closed.       */
++  ENOTCONN,      /* ERR_CONN       -8      Not connected.           */
++  EINVAL,        /* ERR_VAL        -9      Illegal value.           */
++  EIO,           /* ERR_ARG        -10     Illegal argument.        */
++  EADDRINUSE,    /* ERR_USE        -11     Address in use.          */
++  -1,            /* ERR_IF         -12     Low-level netif error    */
++  -1,            /* ERR_ISCONN     -13     Already connected.       */
+   EINPROGRESS    /* ERR_INPROGRESS -14     Operation in progress    */
+ };
+ 
+Index: src/api/tcpip.c
+===================================================================
+RCS file: /sources/lwip/lwip/src/api/tcpip.c,v
+retrieving revision 1.70
+retrieving revision 1.73
+diff -u -p -r1.70 -r1.73
+--- src/api/tcpip.c    12 Jan 2008 11:52:22 -0000      1.70
++++ src/api/tcpip.c    27 Jun 2008 20:34:51 -0000      1.73
+@@ -518,4 +518,42 @@ tcpip_init(void (* initfunc)(void *), vo
+   sys_thread_new(TCPIP_THREAD_NAME, tcpip_thread, NULL, 
TCPIP_THREAD_STACKSIZE, TCPIP_THREAD_PRIO);
+ }
+ 
++/**
++ * Simple callback function used with tcpip_callback to free a pbuf
++ * (pbuf_free has a wrong signature for tcpip_callback)
++ *
++ * @param p The pbuf (chain) to be dereferenced.
++ */
++static void
++pbuf_free_int(void *p)
++{
++  struct pbuf *q = p;
++  pbuf_free(q);
++}
++
++/**
++ * A simple wrapper function that allows you to free a pbuf from interrupt 
context.
++ *
++ * @param p The pbuf (chain) to be dereferenced.
++ * @return ERR_OK if callback could be enqueued, an err_t if not
++ */
++err_t
++pbuf_free_callback(struct pbuf *p)
++{
++  return tcpip_callback_with_block(pbuf_free_int, p, 0);
++}
++
++/**
++ * A simple wrapper function that allows you to free heap memory from
++ * interrupt context.
++ *
++ * @param m the heap memory to free
++ * @return ERR_OK if callback could be enqueued, an err_t if not
++ */
++err_t
++mem_free_callback(void *m)
++{
++  return tcpip_callback_with_block(mem_free, m, 0);
++}
++
+ #endif /* !NO_SYS */
+Index: src/core/dhcp.c
+===================================================================
+RCS file: /sources/lwip/lwip/src/core/dhcp.c,v
+retrieving revision 1.86
+retrieving revision 1.87
+diff -u -p -r1.86 -r1.87
+--- src/core/dhcp.c    4 Mar 2008 14:25:58 -0000       1.86
++++ src/core/dhcp.c    15 Apr 2008 17:24:55 -0000      1.87
+@@ -568,6 +568,8 @@ dhcp_start(struct netif *netif)
+   LWIP_ERROR("netif != NULL", (netif != NULL), return ERR_ARG;);
+   dhcp = netif->dhcp;
+   LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, 
("dhcp_start(netif=%p) %c%c%"U16_F"\n", (void*)netif, netif->name[0], 
netif->name[1], (u16_t)netif->num));
++  /* Remove the flag that says this netif is handled by DHCP,
++     it is set when we succeeded starting. */
+   netif->flags &= ~NETIF_FLAG_DHCP;
+ 
+   /* no DHCP client attached yet? */
+@@ -609,6 +611,7 @@ dhcp_start(struct netif *netif)
+     dhcp_stop(netif);
+     return ERR_MEM;
+   }
++  /* Set the flag that says this netif is handled by DHCP. */
+   netif->flags |= NETIF_FLAG_DHCP;
+   return result;
+ }
+@@ -1063,6 +1066,8 @@ dhcp_stop(struct netif *netif)
+ {
+   struct dhcp *dhcp = netif->dhcp;
+   LWIP_ERROR("dhcp_stop: netif != NULL", (netif != NULL), return;);
++  /* Remove the flag that says this netif is handled by DHCP. */
++  netif->flags &= ~NETIF_FLAG_DHCP;
+ 
+   LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | 3, ("dhcp_stop()\n"));
+   /* netif is DHCP configured? */
+Index: src/core/mem.c
+===================================================================
+RCS file: /sources/lwip/lwip/src/core/mem.c,v
+retrieving revision 1.59
+retrieving revision 1.62
+diff -u -p -r1.59 -r1.62
+--- src/core/mem.c     4 Mar 2008 16:31:32 -0000       1.59
++++ src/core/mem.c     30 Jun 2008 18:16:51 -0000      1.62
+@@ -177,9 +177,36 @@ static u8_t *ram;
+ static struct mem *ram_end;
+ /** pointer to the lowest free block, this is used for faster search */
+ static struct mem *lfree;
++
+ /** concurrent access protection */
+ static sys_sem_t mem_sem;
+ 
++#if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
++
++static volatile u8_t mem_free_count;
++
++/* Allow mem_free from other (e.g. interrupt) context */
++#define LWIP_MEM_FREE_DECL_PROTECT()  SYS_ARCH_DECL_PROTECT(lev_free)
++#define LWIP_MEM_FREE_PROTECT()       SYS_ARCH_PROTECT(lev_free)
++#define LWIP_MEM_FREE_UNPROTECT()     SYS_ARCH_UNPROTECT(lev_free)
++#define LWIP_MEM_ALLOC_DECL_PROTECT() SYS_ARCH_DECL_PROTECT(lev_alloc)
++#define LWIP_MEM_ALLOC_PROTECT()      SYS_ARCH_PROTECT(lev_alloc)
++#define LWIP_MEM_ALLOC_UNPROTECT()    SYS_ARCH_UNPROTECT(lev_alloc)
++
++#else /* LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT */
++
++/* Protect the heap only by using a semaphore */
++#define LWIP_MEM_FREE_DECL_PROTECT()
++#define LWIP_MEM_FREE_PROTECT()    sys_arch_sem_wait(mem_sem, 0)
++#define LWIP_MEM_FREE_UNPROTECT()  sys_sem_signal(mem_sem)
++/* mem_malloc is protected using semaphore AND LWIP_MEM_ALLOC_PROTECT */
++#define LWIP_MEM_ALLOC_DECL_PROTECT()
++#define LWIP_MEM_ALLOC_PROTECT()
++#define LWIP_MEM_ALLOC_UNPROTECT()
++
++#endif /* LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT */
++
++
+ /**
+  * "Plug holes" by combining adjacent empty struct mems.
+  * After this function is through, there should not exist
+@@ -255,9 +282,7 @@ mem_init(void)
+   /* initialize the lowest-free pointer to the start of the heap */
+   lfree = (struct mem *)ram;
+ 
+-#if MEM_STATS
+-  lwip_stats.mem.avail = MEM_SIZE_ALIGNED;
+-#endif /* MEM_STATS */
++  MEM_STATS_AVAIL(avail, MEM_SIZE_ALIGNED);
+ }
+ 
+ /**
+@@ -270,6 +295,7 @@ void
+ mem_free(void *rmem)
+ {
+   struct mem *mem;
++  LWIP_MEM_FREE_DECL_PROTECT();
+ 
+   if (rmem == NULL) {
+     LWIP_DEBUGF(MEM_DEBUG | LWIP_DBG_TRACE | 2, ("mem_free(p == NULL) was 
called.\n"));
+@@ -277,20 +303,20 @@ mem_free(void *rmem)
+   }
+   LWIP_ASSERT("mem_free: sanity check alignment", (((mem_ptr_t)rmem) & 
(MEM_ALIGNMENT-1)) == 0);
+ 
+-  /* protect the heap from concurrent access */
+-  sys_arch_sem_wait(mem_sem, 0);
+-
+   LWIP_ASSERT("mem_free: legal memory", (u8_t *)rmem >= (u8_t *)ram &&
+     (u8_t *)rmem < (u8_t *)ram_end);
+ 
+   if ((u8_t *)rmem < (u8_t *)ram || (u8_t *)rmem >= (u8_t *)ram_end) {
++    SYS_ARCH_DECL_PROTECT(lev);
+     LWIP_DEBUGF(MEM_DEBUG | 3, ("mem_free: illegal memory\n"));
+-#if MEM_STATS
+-    ++lwip_stats.mem.err;
+-#endif /* MEM_STATS */
+-    sys_sem_signal(mem_sem);
++    /* protect mem stats from concurrent access */
++    SYS_ARCH_PROTECT(lev);
++    MEM_STATS_INC(illegal);
++    SYS_ARCH_UNPROTECT(lev);
+     return;
+   }
++  /* protect the heap from concurrent access */
++  LWIP_MEM_FREE_PROTECT();
+   /* Get the corresponding struct mem ... */
+   mem = (struct mem *)((u8_t *)rmem - SIZEOF_STRUCT_MEM);
+   /* ... which has to be in a used state ... */
+@@ -303,13 +329,14 @@ mem_free(void *rmem)
+     lfree = mem;
+   }
+ 
+-#if MEM_STATS
+-  lwip_stats.mem.used -= mem->next - ((u8_t *)mem - ram);
+-#endif /* MEM_STATS */
++  MEM_STATS_DEC_USED(used, mem->next - ((u8_t *)mem - ram));
+ 
+   /* finally, see if prev or next are free also */
+   plug_holes(mem);
+-  sys_sem_signal(mem_sem);
++#if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
++  mem_free_count = 1;
++#endif /* LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT */
++  LWIP_MEM_FREE_UNPROTECT();
+ }
+ 
+ /**
+@@ -321,6 +348,8 @@ mem_free(void *rmem)
+  * @param newsize required size after shrinking (needs to be smaller than or
+  *                equal to the previous size)
+  * @return for compatibility reasons: is always == rmem, at the moment
++ *         or NULL if newsize is > old size, in which case rmem is NOT touched
++ *         or freed!
+  */
+ void *
+ mem_realloc(void *rmem, mem_size_t newsize)
+@@ -328,6 +357,8 @@ mem_realloc(void *rmem, mem_size_t newsi
+   mem_size_t size;
+   mem_size_t ptr, ptr2;
+   struct mem *mem, *mem2;
++  /* use the FREE_PROTECT here: it protects with sem OR SYS_ARCH_PROTECT */
++  LWIP_MEM_FREE_DECL_PROTECT();
+ 
+   /* Expand the size of the allocated memory region so that we can
+      adjust for alignment. */
+@@ -346,7 +377,12 @@ mem_realloc(void *rmem, mem_size_t newsi
+    (u8_t *)rmem < (u8_t *)ram_end);
+ 
+   if ((u8_t *)rmem < (u8_t *)ram || (u8_t *)rmem >= (u8_t *)ram_end) {
++    SYS_ARCH_DECL_PROTECT(lev);
+     LWIP_DEBUGF(MEM_DEBUG | 3, ("mem_realloc: illegal memory\n"));
++    /* protect mem stats from concurrent access */
++    SYS_ARCH_PROTECT(lev);
++    MEM_STATS_INC(illegal);
++    SYS_ARCH_UNPROTECT(lev);
+     return rmem;
+   }
+   /* Get the corresponding struct mem ... */
+@@ -366,11 +402,9 @@ mem_realloc(void *rmem, mem_size_t newsi
+   }
+ 
+   /* protect the heap from concurrent access */
+-  sys_arch_sem_wait(mem_sem, 0);
++  LWIP_MEM_FREE_PROTECT();
+ 
+-#if MEM_STATS
+-  lwip_stats.mem.used -= (size - newsize);
+-#endif /* MEM_STATS */
++  MEM_STATS_DEC_USED(used, (size - newsize));
+ 
+   mem2 = (struct mem *)&ram[mem->next];
+   if(mem2->used == 0) {
+@@ -426,7 +460,10 @@ mem_realloc(void *rmem, mem_size_t newsi
+     -> don't do anyhting. 
+     -> the remaining space stays unused since it is too small
+   } */
+-  sys_sem_signal(mem_sem);
++#if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
++  mem_free_count = 1;
++#endif /* LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT */
++  LWIP_MEM_FREE_UNPROTECT();
+   return rmem;
+ }
+ 
+@@ -444,6 +481,10 @@ mem_malloc(mem_size_t size)
+ {
+   mem_size_t ptr, ptr2;
+   struct mem *mem, *mem2;
++#if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
++  u8_t local_mem_free_count = 0;
++#endif /* LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT */
++  LWIP_MEM_ALLOC_DECL_PROTECT();
+ 
+   if (size == 0) {
+     return NULL;
+@@ -464,88 +505,101 @@ mem_malloc(mem_size_t size)
+ 
+   /* protect the heap from concurrent access */
+   sys_arch_sem_wait(mem_sem, 0);
++  LWIP_MEM_ALLOC_PROTECT();
++#if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
++  /* run as long as a mem_free disturbed mem_malloc */
++  do {
++    local_mem_free_count = 0;
++#endif /* LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT */
++
++    /* Scan through the heap searching for a free block that is big enough,
++     * beginning with the lowest free block.
++     */
++    for (ptr = (u8_t *)lfree - ram; ptr < MEM_SIZE_ALIGNED - size;
++         ptr = ((struct mem *)&ram[ptr])->next) {
++      mem = (struct mem *)&ram[ptr];
++#if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
++      mem_free_count = 0;
++      LWIP_MEM_ALLOC_UNPROTECT();
++      /* allow mem_free to run */
++      LWIP_MEM_ALLOC_PROTECT();
++      if (mem_free_count != 0) {
++        local_mem_free_count = mem_free_count;
++      }
++      mem_free_count = 0;
++#endif /* LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT */
+ 
+-  /* Scan through the heap searching for a free block that is big enough,
+-   * beginning with the lowest free block.
+-   */
+-  for (ptr = (u8_t *)lfree - ram; ptr < MEM_SIZE_ALIGNED - size;
+-       ptr = ((struct mem *)&ram[ptr])->next) {
+-    mem = (struct mem *)&ram[ptr];
+-
+-    if ((!mem->used) &&
+-        (mem->next - (ptr + SIZEOF_STRUCT_MEM)) >= size) {
+-      /* mem is not used and at least perfect fit is possible:
+-       * mem->next - (ptr + SIZEOF_STRUCT_MEM) gives us the 'user data size' 
of mem */
+-
+-      if (mem->next - (ptr + SIZEOF_STRUCT_MEM) >= (size + SIZEOF_STRUCT_MEM 
+ MIN_SIZE_ALIGNED)) {
+-        /* (in addition to the above, we test if another struct mem 
(SIZEOF_STRUCT_MEM) containing
+-         * at least MIN_SIZE_ALIGNED of data also fits in the 'user data 
space' of 'mem')
+-         * -> split large block, create empty remainder,
+-         * remainder must be large enough to contain MIN_SIZE_ALIGNED data: if
+-         * mem->next - (ptr + (2*SIZEOF_STRUCT_MEM)) == size,
+-         * struct mem would fit in but no data between mem2 and mem2->next
+-         * @todo we could leave out MIN_SIZE_ALIGNED. We would create an empty
+-         *       region that couldn't hold data, but when mem->next gets 
freed,
+-         *       the 2 regions would be combined, resulting in more free 
memory
+-         */
+-        ptr2 = ptr + SIZEOF_STRUCT_MEM + size;
+-        /* create mem2 struct */
+-        mem2 = (struct mem *)&ram[ptr2];
+-        mem2->used = 0;
+-        mem2->next = mem->next;
+-        mem2->prev = ptr;
+-        /* and insert it between mem and mem->next */
+-        mem->next = ptr2;
+-        mem->used = 1;
+-
+-        if (mem2->next != MEM_SIZE_ALIGNED) {
+-          ((struct mem *)&ram[mem2->next])->prev = ptr2;
+-        }
+-#if MEM_STATS
+-        lwip_stats.mem.used += (size + SIZEOF_STRUCT_MEM);
+-        if (lwip_stats.mem.max < lwip_stats.mem.used) {
+-          lwip_stats.mem.max = lwip_stats.mem.used;
++      if ((!mem->used) &&
++          (mem->next - (ptr + SIZEOF_STRUCT_MEM)) >= size) {
++        /* mem is not used and at least perfect fit is possible:
++         * mem->next - (ptr + SIZEOF_STRUCT_MEM) gives us the 'user data 
size' of mem */
++
++        if (mem->next - (ptr + SIZEOF_STRUCT_MEM) >= (size + 
SIZEOF_STRUCT_MEM + MIN_SIZE_ALIGNED)) {
++          /* (in addition to the above, we test if another struct mem 
(SIZEOF_STRUCT_MEM) containing
++           * at least MIN_SIZE_ALIGNED of data also fits in the 'user data 
space' of 'mem')
++           * -> split large block, create empty remainder,
++           * remainder must be large enough to contain MIN_SIZE_ALIGNED data: 
if
++           * mem->next - (ptr + (2*SIZEOF_STRUCT_MEM)) == size,
++           * struct mem would fit in but no data between mem2 and mem2->next
++           * @todo we could leave out MIN_SIZE_ALIGNED. We would create an 
empty
++           *       region that couldn't hold data, but when mem->next gets 
freed,
++           *       the 2 regions would be combined, resulting in more free 
memory
++           */
++          ptr2 = ptr + SIZEOF_STRUCT_MEM + size;
++          /* create mem2 struct */
++          mem2 = (struct mem *)&ram[ptr2];
++          mem2->used = 0;
++          mem2->next = mem->next;
++          mem2->prev = ptr;
++          /* and insert it between mem and mem->next */
++          mem->next = ptr2;
++          mem->used = 1;
++
++          if (mem2->next != MEM_SIZE_ALIGNED) {
++            ((struct mem *)&ram[mem2->next])->prev = ptr2;
++          }
++          MEM_STATS_INC_USED(used, (size + SIZEOF_STRUCT_MEM));
++        } else {
++          /* (a mem2 struct does no fit into the user data space of mem and 
mem->next will always
++           * be used at this point: if not we have 2 unused structs in a row, 
plug_holes should have
++           * take care of this).
++           * -> near fit or excact fit: do not split, no mem2 creation
++           * also can't move mem->next directly behind mem, since mem->next
++           * will always be used at this point!
++           */
++          mem->used = 1;
++          MEM_STATS_INC_USED(used, mem->next - ((u8_t *)mem - ram));
+         }
+-#endif /* MEM_STATS */
+-      } else {
+-        /* (a mem2 struct does no fit into the user data space of mem and 
mem->next will always
+-         * be used at this point: if not we have 2 unused structs in a row, 
plug_holes should have
+-         * take care of this).
+-         * -> near fit or excact fit: do not split, no mem2 creation
+-         * also can't move mem->next directly behind mem, since mem->next
+-         * will always be used at this point!
+-         */
+-        mem->used = 1;
+-#if MEM_STATS
+-        lwip_stats.mem.used += mem->next - ((u8_t *)mem - ram);
+-        if (lwip_stats.mem.max < lwip_stats.mem.used) {
+-          lwip_stats.mem.max = lwip_stats.mem.used;
+-        }
+-#endif /* MEM_STATS */
+-      }
+ 
+-      if (mem == lfree) {
+-        /* Find next free block after mem and update lowest free pointer */
+-        while (lfree->used && lfree != ram_end) {
+-          lfree = (struct mem *)&ram[lfree->next];
++        if (mem == lfree) {
++          /* Find next free block after mem and update lowest free pointer */
++          while (lfree->used && lfree != ram_end) {
++            LWIP_MEM_ALLOC_UNPROTECT();
++            /* prevent high interrupt latency... */
++            LWIP_MEM_ALLOC_PROTECT();
++            lfree = (struct mem *)&ram[lfree->next];
++          }
++          LWIP_ASSERT("mem_malloc: !lfree->used", ((lfree == ram_end) || 
(!lfree->used)));
+         }
+-        LWIP_ASSERT("mem_malloc: !lfree->used", ((lfree == ram_end) || 
(!lfree->used)));
+-      }
+-      sys_sem_signal(mem_sem);
+-      LWIP_ASSERT("mem_malloc: allocated memory not above ram_end.",
+-       (mem_ptr_t)mem + SIZEOF_STRUCT_MEM + size <= (mem_ptr_t)ram_end);
+-      LWIP_ASSERT("mem_malloc: allocated memory properly aligned.",
+-       (unsigned long)((u8_t *)mem + SIZEOF_STRUCT_MEM) % MEM_ALIGNMENT == 0);
+-      LWIP_ASSERT("mem_malloc: sanity check alignment",
+-        (((mem_ptr_t)mem) & (MEM_ALIGNMENT-1)) == 0);
++        LWIP_MEM_ALLOC_UNPROTECT();
++        sys_sem_signal(mem_sem);
++        LWIP_ASSERT("mem_malloc: allocated memory not above ram_end.",
++         (mem_ptr_t)mem + SIZEOF_STRUCT_MEM + size <= (mem_ptr_t)ram_end);
++        LWIP_ASSERT("mem_malloc: allocated memory properly aligned.",
++         (unsigned long)((u8_t *)mem + SIZEOF_STRUCT_MEM) % MEM_ALIGNMENT == 
0);
++        LWIP_ASSERT("mem_malloc: sanity check alignment",
++          (((mem_ptr_t)mem) & (MEM_ALIGNMENT-1)) == 0);
+ 
+-      return (u8_t *)mem + SIZEOF_STRUCT_MEM;
++        return (u8_t *)mem + SIZEOF_STRUCT_MEM;
++      }
+     }
+-  }
++#if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
++    /* if we got interrupted by a mem_free, try again */
++  } while(local_mem_free_count != 0);
++#endif /* LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT */
+   LWIP_DEBUGF(MEM_DEBUG | 2, ("mem_malloc: could not allocate %"S16_F" 
bytes\n", (s16_t)size));
+-#if MEM_STATS
+-  ++lwip_stats.mem.err;
+-#endif /* MEM_STATS */
++  MEM_STATS_INC(err);
++  LWIP_MEM_ALLOC_UNPROTECT();
+   sys_sem_signal(mem_sem);
+   return NULL;
+ }
+Index: src/core/memp.c
+===================================================================
+RCS file: /sources/lwip/lwip/src/core/memp.c,v
+retrieving revision 1.55
+retrieving revision 1.56
+diff -u -p -r1.55 -r1.56
+--- src/core/memp.c    25 Nov 2007 10:43:28 -0000      1.55
++++ src/core/memp.c    27 Jun 2008 18:37:54 -0000      1.56
+@@ -252,13 +252,12 @@ memp_init(void)
+   struct memp *memp;
+   u16_t i, j;
+ 
+-#if MEMP_STATS
+   for (i = 0; i < MEMP_MAX; ++i) {
+-    lwip_stats.memp[i].used = lwip_stats.memp[i].max =
+-      lwip_stats.memp[i].err = 0;
+-    lwip_stats.memp[i].avail = memp_num[i];
++    MEMP_STATS_AVAIL(used, i, 0);
++    MEMP_STATS_AVAIL(max, i, 0);
++    MEMP_STATS_AVAIL(err, i, 0);
++    MEMP_STATS_AVAIL(avail, i, memp_num[i]);
+   }
+-#endif /* MEMP_STATS */
+ 
+   memp = LWIP_MEM_ALIGN(memp_memory);
+   /* for every pool: */
+@@ -315,20 +314,13 @@ memp_malloc_fn(memp_t type, const char* 
+     memp->file = file;
+     memp->line = line;
+ #endif /* MEMP_OVERFLOW_CHECK */
+-#if MEMP_STATS
+-    ++lwip_stats.memp[type].used;
+-    if (lwip_stats.memp[type].used > lwip_stats.memp[type].max) {
+-      lwip_stats.memp[type].max = lwip_stats.memp[type].used;
+-    }
+-#endif /* MEMP_STATS */
++    MEMP_STATS_INC_USED(used, type);
+     LWIP_ASSERT("memp_malloc: memp properly aligned",
+                 ((mem_ptr_t)memp % MEM_ALIGNMENT) == 0);
+     memp = (struct memp*)((u8_t*)memp + MEMP_SIZE);
+   } else {
+     LWIP_DEBUGF(MEMP_DEBUG | 2, ("memp_malloc: out of memory in pool %s\n", 
memp_desc[type]));
+-#if MEMP_STATS
+-    ++lwip_stats.memp[type].err;
+-#endif /* MEMP_STATS */
++    MEMP_STATS_INC(err, type);
+   }
+ 
+   SYS_ARCH_UNPROTECT(old_level);
+@@ -365,9 +357,7 @@ memp_free(memp_t type, void *mem)
+ #endif /* MEMP_OVERFLOW_CHECK >= 2 */
+ #endif /* MEMP_OVERFLOW_CHECK */
+ 
+-#if MEMP_STATS
+-  lwip_stats.memp[type].used--; 
+-#endif /* MEMP_STATS */
++  MEMP_STATS_DEC(used, type); 
+   
+   memp->next = memp_tab[type]; 
+   memp_tab[type] = memp;
+Index: src/core/netif.c
+===================================================================
+RCS file: /sources/lwip/lwip/src/core/netif.c,v
+retrieving revision 1.65
+retrieving revision 1.68
+diff -u -p -r1.65 -r1.68
+--- src/core/netif.c   9 Oct 2007 20:00:55 -0000       1.65
++++ src/core/netif.c   19 Jun 2008 16:27:18 -0000      1.68
+@@ -45,6 +45,12 @@
+ #include "lwip/snmp.h"
+ #include "lwip/igmp.h"
+ #include "netif/etharp.h"
++#if ENABLE_LOOPBACK
++#include "lwip/sys.h"
++#if LWIP_NETIF_LOOPBACK_MULTITHREADING
++#include "lwip/tcpip.h"
++#endif /* LWIP_NETIF_LOOPBACK_MULTITHREADING */
++#endif /* ENABLE_LOOPBACK */
+ 
+ #if LWIP_NETIF_STATUS_CALLBACK
+ #define NETIF_STATUS_CALLBACK(n) { if (n->status_callback) 
(n->status_callback)(n); }
+@@ -106,6 +112,10 @@ netif_add(struct netif *netif, struct ip
+ #if LWIP_IGMP
+   netif->igmp_mac_filter = NULL;
+ #endif /* LWIP_IGMP */
++#if ENABLE_LOOPBACK
++  netif->loop_first = NULL;
++  netif->loop_last = NULL;
++#endif /* ENABLE_LOOPBACK */
+ 
+   /* remember netif specific state information data */
+   netif->state = state;
+@@ -114,6 +124,9 @@ netif_add(struct netif *netif, struct ip
+ #if LWIP_NETIF_HWADDRHINT
+   netif->addr_hint = NULL;
+ #endif /* LWIP_NETIF_HWADDRHINT*/
++#if ENABLE_LOOPBACK && LWIP_LOOPBACK_MAX_PBUFS
++  netif->loop_cnt_current = 0;
++#endif /* ENABLE_LOOPBACK && LWIP_LOOPBACK_MAX_PBUFS */
+ 
+   netif_set_addr(netif, ipaddr, netmask, gw);
+ 
+@@ -493,7 +506,158 @@ u8_t netif_is_link_up(struct netif *neti
+  */
+ void netif_set_link_callback(struct netif *netif, void (* 
link_callback)(struct netif *netif ))
+ {
+-    if ( netif )
+-        netif->link_callback = link_callback;
++  if (netif) {
++    netif->link_callback = link_callback;
++  }
+ }
+ #endif /* LWIP_NETIF_LINK_CALLBACK */
++
++#if ENABLE_LOOPBACK
++/**
++ * Send an IP packet to be received on the same netif (loopif-like).
++ * The pbuf is simply copied and handed back to netif->input.
++ * In multithreaded mode, this is done directly since netif->input must put
++ * the packet on a queue.
++ * In callback mode, the packet is put on an internal queue and is fed to
++ * netif->input by netif_poll().
++ *
++ * @param netif the lwip network interface structure
++ * @param p the (IP) packet to 'send'
++ * @param ipaddr the ip address to send the packet to (not used)
++ * @return ERR_OK if the packet has been sent
++ *         ERR_MEM if the pbuf used to copy the packet couldn't be allocated
++ */
++err_t
++netif_loop_output(struct netif *netif, struct pbuf *p,
++       struct ip_addr *ipaddr)
++{
++  struct pbuf *r;
++  err_t err;
++  struct pbuf *last;
++#if LWIP_LOOPBACK_MAX_PBUFS
++  u8_t clen = 0;
++#endif /* LWIP_LOOPBACK_MAX_PBUFS */
++  SYS_ARCH_DECL_PROTECT(lev);
++  LWIP_UNUSED_ARG(ipaddr);
++
++  /* Allocate a new pbuf */
++  r = pbuf_alloc(PBUF_LINK, p->tot_len, PBUF_RAM);
++  if (r == NULL) {
++    return ERR_MEM;
++  }
++#if LWIP_LOOPBACK_MAX_PBUFS
++  clen = pbuf_clen(r);
++  /* check for overflow or too many pbuf on queue */
++  if(((netif->loop_cnt_current + clen) < netif->loop_cnt_current) ||
++    ((netif->loop_cnt_current + clen) > LWIP_LOOPBACK_MAX_PBUFS)) {
++      pbuf_free(r);
++      r = NULL;
++      return ERR_MEM;
++  }
++  netif->loop_cnt_current += clen;
++#endif /* LWIP_LOOPBACK_MAX_PBUFS */
++
++  /* Copy the whole pbuf queue p into the single pbuf r */
++  if ((err = pbuf_copy(r, p)) != ERR_OK) {
++    pbuf_free(r);
++    r = NULL;
++    return err;
++  }
++
++  /* Put the packet on a linked list which gets emptied through calling
++     netif_poll(). */
++
++  /* let last point to the last pbuf in chain r */
++  for (last = r; last->next != NULL; last = last->next);
++
++  SYS_ARCH_PROTECT(lev);
++  if(netif->loop_first != NULL) {
++    LWIP_ASSERT("if first != NULL, last must also be != NULL", 
netif->loop_last != NULL);
++    netif->loop_last->next = r;
++    netif->loop_last = last;
++  } else {
++    netif->loop_first = r;
++    netif->loop_last = last;
++  }
++  SYS_ARCH_UNPROTECT(lev);
++
++#if LWIP_NETIF_LOOPBACK_MULTITHREADING
++  /* For multithreading environment, schedule a call to netif_poll */
++  tcpip_callback(netif_poll, netif);
++#endif /* LWIP_NETIF_LOOPBACK_MULTITHREADING */
++
++  return ERR_OK;
++}
++
++/**
++ * Call netif_poll() in the main loop of your application. This is to prevent
++ * reentering non-reentrant functions like tcp_input(). Packets passed to
++ * netif_loop_output() are put on a list that is passed to netif->input() by
++ * netif_poll().
++ */
++void
++netif_poll(struct netif *netif)
++{
++  struct pbuf *in;
++  SYS_ARCH_DECL_PROTECT(lev);
++
++  do {
++    /* Get a packet from the list. With SYS_LIGHTWEIGHT_PROT=1, this is 
protected */
++    SYS_ARCH_PROTECT(lev);
++    in = netif->loop_first;
++    if(in != NULL) {
++      struct pbuf *in_end = in;
++#if LWIP_LOOPBACK_MAX_PBUFS
++      u8_t clen = pbuf_clen(in);
++      /* adjust the number of pbufs on queue */
++      LWIP_ASSERT("netif->loop_cnt_current underflow",
++        ((netif->loop_cnt_current - clen) < netif->loop_cnt_current));
++      netif->loop_cnt_current -= clen;
++#endif /* LWIP_LOOPBACK_MAX_PBUFS */
++      while(in_end->len != in_end->tot_len) {
++        LWIP_ASSERT("bogus pbuf: len != tot_len but next == NULL!", 
in_end->next != NULL);
++        in_end = in_end->next;
++      }
++      /* 'in_end' now points to the last pbuf from 'in' */
++      if(in_end == netif->loop_last) {
++        /* this was the last pbuf in the list */
++        netif->loop_first = netif->loop_last = NULL;
++      } else {
++        /* pop the pbuf off the list */
++        netif->loop_first = in_end->next;
++        LWIP_ASSERT("should not be null since first != last!", 
netif->loop_first != NULL);
++      }
++      /* De-queue the pbuf from its successors on the 'loop_' list. */
++      in_end->next = NULL;
++    }
++    SYS_ARCH_UNPROTECT(lev);
++
++    if(in != NULL) {
++      /* loopback packets are always IP packets! */
++      if(ip_input(in, netif) != ERR_OK) {
++        pbuf_free(in);
++      }
++      /* Don't reference the packet any more! */
++      in = NULL;
++    }
++  /* go on while there is a packet on the list */
++  } while(netif->loop_first != NULL);
++}
++
++#if !LWIP_NETIF_LOOPBACK_MULTITHREADING
++/**
++ * Calls netif_poll() for every netif on the netif_list.
++ */
++void
++netif_poll_all(void)
++{
++  struct netif *netif = netif_list;
++  /* loop through netifs */
++  while (netif != NULL) {
++    netif_poll(netif);
++    /* proceed to next network interface */
++    netif = netif->next;
++  }
++}
++#endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */
++#endif /* ENABLE_LOOPBACK */
+Index: src/core/pbuf.c
+===================================================================
+RCS file: /sources/lwip/lwip/src/core/pbuf.c,v
+retrieving revision 1.127
+retrieving revision 1.128
+diff -u -p -r1.127 -r1.128
+--- src/core/pbuf.c    4 Mar 2008 16:37:46 -0000       1.127
++++ src/core/pbuf.c    1 Apr 2008 19:05:40 -0000       1.128
+@@ -667,8 +667,8 @@ pbuf_dechain(struct pbuf *p)
+  *
+  * @note Only one packet is copied, no packet queue!
+  *
+- * @param p_to pbuf source of the copy
+- * @param p_from pbuf destination of the copy
++ * @param p_to pbuf destination of the copy
++ * @param p_from pbuf source of the copy
+  *
+  * @return ERR_OK if pbuf was copied
+  *         ERR_ARG if one of the pbufs is NULL or p_to is not big
+Index: src/core/stats.c
+===================================================================
+RCS file: /sources/lwip/lwip/src/core/stats.c,v
+retrieving revision 1.27
+retrieving revision 1.28
+diff -u -p -r1.27 -r1.28
+--- src/core/stats.c   4 Mar 2008 16:31:32 -0000       1.27
++++ src/core/stats.c   27 Jun 2008 18:37:54 -0000      1.28
+@@ -54,7 +54,6 @@ stats_display_proto(struct stats_proto *
+ {
+   LWIP_PLATFORM_DIAG(("\n%s\n\t", name));
+   LWIP_PLATFORM_DIAG(("xmit: %"STAT_COUNTER_F"\n\t", proto->xmit)); 
+-  LWIP_PLATFORM_DIAG(("rexmit: %"STAT_COUNTER_F"\n\t", proto->rexmit)); 
+   LWIP_PLATFORM_DIAG(("recv: %"STAT_COUNTER_F"\n\t", proto->recv)); 
+   LWIP_PLATFORM_DIAG(("fw: %"STAT_COUNTER_F"\n\t", proto->fw)); 
+   LWIP_PLATFORM_DIAG(("drop: %"STAT_COUNTER_F"\n\t", proto->drop)); 
+@@ -68,6 +67,7 @@ stats_display_proto(struct stats_proto *
+   LWIP_PLATFORM_DIAG(("cachehit: %"STAT_COUNTER_F"\n", proto->cachehit)); 
+ }
+ 
++#if IGMP_STATS
+ void
+ stats_display_igmp(struct stats_igmp *igmp)
+ {
+@@ -82,7 +82,9 @@ stats_display_igmp(struct stats_igmp *ig
+   LWIP_PLATFORM_DIAG(("report_rxed: %"STAT_COUNTER_F"\n\t", 
igmp->report_rxed)); 
+   LWIP_PLATFORM_DIAG(("group_query_rxed: %"STAT_COUNTER_F"\n", 
igmp->group_query_rxed));
+ }
++#endif /* IGMP_STATS */
+ 
++#if MEM_STATS || MEMP_STATS
+ void
+ stats_display_mem(struct stats_mem *mem, char *name)
+ {
+@@ -93,48 +95,53 @@ stats_display_mem(struct stats_mem *mem,
+   LWIP_PLATFORM_DIAG(("err: %"U32_F"\n", (u32_t)mem->err));
+ }
+ 
++#if MEMP_STATS
+ void
+-stats_display(void)
++stats_display_memp(struct stats_mem *mem, int index)
+ {
+-#if MEMP_STATS
+-  s16_t i;
+   char * memp_names[] = {
+ #define LWIP_MEMPOOL(name,num,size,desc) desc,
+ #include "lwip/memp_std.h"
+   };
+-#endif
+-#if LINK_STATS
+-  stats_display_proto(&lwip_stats.link, "LINK");
+-#endif
+-#if ETHARP_STATS
+-  stats_display_proto(&lwip_stats.etharp, "ETHARP");
+-#endif
+-#if IPFRAG_STATS
+-  stats_display_proto(&lwip_stats.ip_frag, "IP_FRAG");
+-#endif
+-#if IP_STATS
+-  stats_display_proto(&lwip_stats.ip, "IP");
+-#endif
+-#if ICMP_STATS
+-  stats_display_proto(&lwip_stats.icmp, "ICMP");
+-#endif
+-#if IGMP_STATS
+-  stats_display_igmp(&lwip_stats.igmp);
+-#endif
+-#if UDP_STATS
+-  stats_display_proto(&lwip_stats.udp, "UDP");
+-#endif
+-#if TCP_STATS
+-  stats_display_proto(&lwip_stats.tcp, "TCP");
+-#endif
+-#if MEM_STATS
+-  stats_display_mem(&lwip_stats.mem, "HEAP");
+-#endif
+-#if MEMP_STATS
++  if(index < MEMP_MAX) {
++    stats_display_mem(mem, memp_names[index]);
++  }
++}
++#endif /* MEMP_STATS */
++#endif /* MEM_STATS || MEMP_STATS */
++
++#if SYS_STATS
++void
++stats_display_sys(struct stats_sys *sys)
++{
++  LWIP_PLATFORM_DIAG(("\nSYS\n\t"));
++  LWIP_PLATFORM_DIAG(("sem.used: %"U32_F"\n\t", (u32_t)sys->sem.used)); 
++  LWIP_PLATFORM_DIAG(("sem.max:  %"U32_F"\n\t", (u32_t)sys->sem.max)); 
++  LWIP_PLATFORM_DIAG(("sem.err:  %"U32_F"\n\t", (u32_t)sys->sem.err)); 
++  LWIP_PLATFORM_DIAG(("mbox.used: %"U32_F"\n\t", (u32_t)sys->mbox.used)); 
++  LWIP_PLATFORM_DIAG(("mbox.max:  %"U32_F"\n\t", (u32_t)sys->mbox.max)); 
++  LWIP_PLATFORM_DIAG(("mbox.err:  %"U32_F"\n\t", (u32_t)sys->mbox.err)); 
++}
++#endif /* SYS_STATS */
++
++void
++stats_display(void)
++{
++  s16_t i;
++
++  LINK_STATS_DISPLAY();
++  ETHARP_STATS_DISPLAY();
++  IPFRAG_STATS_DISPLAY();
++  IP_STATS_DISPLAY();
++  IGMP_STATS_DISPLAY();
++  ICMP_STATS_DISPLAY();
++  UDP_STATS_DISPLAY();
++  TCP_STATS_DISPLAY();
++  MEM_STATS_DISPLAY();
+   for (i = 0; i < MEMP_MAX; i++) {
+-    stats_display_mem(&lwip_stats.memp[i], memp_names[i]);
++    MEMP_STATS_DISPLAY(i);
+   }
+-#endif
++  SYS_STATS_DISPLAY();
+ }
+ #endif /* LWIP_STATS_DISPLAY */
+ 
+Index: src/core/sys.c
+===================================================================
+RCS file: /sources/lwip/lwip/src/core/sys.c,v
+retrieving revision 1.32
+retrieving revision 1.33
+diff -u -p -r1.32 -r1.33
+--- src/core/sys.c     25 Nov 2007 13:57:05 -0000      1.32
++++ src/core/sys.c     16 Jul 2008 20:36:12 -0000      1.33
+@@ -65,7 +65,7 @@ struct sswt_cb
+ void
+ sys_mbox_fetch(sys_mbox_t mbox, void **msg)
+ {
+-  u32_t time;
++  u32_t time_needed;
+   struct sys_timeouts *timeouts;
+   struct sys_timeo *tmptimeout;
+   sys_timeout_handler h;
+@@ -76,18 +76,18 @@ sys_mbox_fetch(sys_mbox_t mbox, void **m
+ 
+   if (!timeouts || !timeouts->next) {
+     UNLOCK_TCPIP_CORE();
+-    time = sys_arch_mbox_fetch(mbox, msg, 0);
++    time_needed = sys_arch_mbox_fetch(mbox, msg, 0);
+     LOCK_TCPIP_CORE();
+   } else {
+     if (timeouts->next->time > 0) {
+       UNLOCK_TCPIP_CORE();
+-      time = sys_arch_mbox_fetch(mbox, msg, timeouts->next->time);
++      time_needed = sys_arch_mbox_fetch(mbox, msg, timeouts->next->time);
+       LOCK_TCPIP_CORE();
+     } else {
+-      time = SYS_ARCH_TIMEOUT;
++      time_needed = SYS_ARCH_TIMEOUT;
+     }
+ 
+-    if (time == SYS_ARCH_TIMEOUT) {
++    if (time_needed == SYS_ARCH_TIMEOUT) {
+       /* If time == SYS_ARCH_TIMEOUT, a timeout occured before a message
+          could be fetched. We should now call the timeout handler and
+          deallocate the memory allocated for the timeout. */
+@@ -107,8 +107,8 @@ sys_mbox_fetch(sys_mbox_t mbox, void **m
+       /* If time != SYS_ARCH_TIMEOUT, a message was received before the 
timeout
+          occured. The time variable is set to the number of
+          milliseconds we waited for the message. */
+-      if (time < timeouts->next->time) {
+-        timeouts->next->time -= time;
++      if (time_needed < timeouts->next->time) {
++        timeouts->next->time -= time_needed;
+       } else {
+         timeouts->next->time = 0;
+       }
+@@ -125,7 +125,7 @@ sys_mbox_fetch(sys_mbox_t mbox, void **m
+ void
+ sys_sem_wait(sys_sem_t sem)
+ {
+-  u32_t time;
++  u32_t time_needed;
+   struct sys_timeouts *timeouts;
+   struct sys_timeo *tmptimeout;
+   sys_timeout_handler h;
+@@ -139,12 +139,12 @@ sys_sem_wait(sys_sem_t sem)
+     sys_arch_sem_wait(sem, 0);
+   } else {
+     if (timeouts->next->time > 0) {
+-      time = sys_arch_sem_wait(sem, timeouts->next->time);
++      time_needed = sys_arch_sem_wait(sem, timeouts->next->time);
+     } else {
+-      time = SYS_ARCH_TIMEOUT;
++      time_needed = SYS_ARCH_TIMEOUT;
+     }
+ 
+-    if (time == SYS_ARCH_TIMEOUT) {
++    if (time_needed == SYS_ARCH_TIMEOUT) {
+       /* If time == SYS_ARCH_TIMEOUT, a timeout occured before a message
+         could be fetched. We should now call the timeout handler and
+         deallocate the memory allocated for the timeout. */
+@@ -164,8 +164,8 @@ sys_sem_wait(sys_sem_t sem)
+       /* If time != SYS_ARCH_TIMEOUT, a message was received before the 
timeout
+          occured. The time variable is set to the number of
+          milliseconds we waited for the message. */
+-      if (time < timeouts->next->time) {
+-        timeouts->next->time -= time;
++      if (time_needed < timeouts->next->time) {
++        timeouts->next->time -= time_needed;
+       } else {
+         timeouts->next->time = 0;
+       }
+Index: src/core/tcp.c
+===================================================================
+RCS file: /sources/lwip/lwip/src/core/tcp.c,v
+retrieving revision 1.85
+retrieving revision 1.86
+diff -u -p -r1.85 -r1.86
+--- src/core/tcp.c     22 Jan 2008 21:15:15 -0000      1.85
++++ src/core/tcp.c     26 Mar 2008 11:57:13 -0000      1.86
+@@ -509,7 +509,8 @@ tcp_connect(struct tcp_pcb *pcb, struct 
+   pcb->rcv_wnd = TCP_WND;
+   pcb->rcv_ann_wnd = TCP_WND;
+   pcb->snd_wnd = TCP_WND;
+-  /* The send MSS is updated when an MSS option is received. */
++  /* As initial send MSS, we use TCP_MSS but limit it to 536.
++     The send MSS is updated when an MSS option is received. */
+   pcb->mss = (TCP_MSS > 536) ? 536 : TCP_MSS;
+ #if TCP_CALCULATE_EFF_SEND_MSS
+   pcb->mss = tcp_eff_send_mss(pcb->mss, ipaddr);
+@@ -991,7 +992,8 @@ tcp_alloc(u8_t prio)
+     pcb->rcv_ann_wnd = TCP_WND;
+     pcb->tos = 0;
+     pcb->ttl = TCP_TTL;
+-    /* The send MSS is updated when an MSS option is received. */
++    /* As initial send MSS, we use TCP_MSS but limit it to 536.
++       The send MSS is updated when an MSS option is received. */
+     pcb->mss = (TCP_MSS > 536) ? 536 : TCP_MSS;
+     pcb->rto = 3000 / TCP_SLOW_INTERVAL;
+     pcb->sa = 0;
+Index: src/core/tcp_in.c
+===================================================================
+RCS file: /sources/lwip/lwip/src/core/tcp_in.c,v
+retrieving revision 1.97
+retrieving revision 1.100
+diff -u -p -r1.97 -r1.100
+--- src/core/tcp_in.c  22 Jan 2008 21:15:15 -0000      1.97
++++ src/core/tcp_in.c  24 Jun 2008 15:46:39 -0000      1.100
+@@ -511,7 +511,7 @@ tcp_process(struct tcp_pcb *pcb)
+       }
+     } else {
+       if (TCP_SEQ_BETWEEN(seqno, pcb->rcv_nxt, 
+-                          pcb->rcv_nxt+pcb->rcv_ann_wnd)) {
++                          pcb->rcv_nxt+pcb->rcv_wnd)) {
+         acceptable = 1;
+       }
+     }
+@@ -1038,7 +1038,7 @@ tcp_receive(struct tcp_pcb *pcb)
+        and below rcv_nxt + rcv_wnd) in order to be further
+        processed. */
+     if (TCP_SEQ_BETWEEN(seqno, pcb->rcv_nxt, 
+-                        pcb->rcv_nxt + pcb->rcv_ann_wnd - 1)){
++                        pcb->rcv_nxt + pcb->rcv_wnd - 1)){
+       if (pcb->rcv_nxt == seqno) {
+         accepted_inseq = 1; 
+         /* The incoming segment is the next in sequence. We check if
+@@ -1195,14 +1195,14 @@ tcp_receive(struct tcp_pcb *pcb)
+                   } else {
+                     pcb->ooseq = cseg;
+                   }
+-                }
+-                tcp_seg_free(next);
+-                if (cseg->next != NULL) {
+-                  next = cseg->next;
+-                  if (TCP_SEQ_GT(seqno + cseg->len, next->tcphdr->seqno)) {
+-                    /* We need to trim the incoming segment. */
+-                    cseg->len = (u16_t)(next->tcphdr->seqno - seqno);
+-                    pbuf_realloc(cseg->p, cseg->len);
++                  tcp_seg_free(next);
++                  if (cseg->next != NULL) {
++                    next = cseg->next;
++                    if (TCP_SEQ_GT(seqno + cseg->len, next->tcphdr->seqno)) {
++                      /* We need to trim the incoming segment. */
++                      cseg->len = (u16_t)(next->tcphdr->seqno - seqno);
++                      pbuf_realloc(cseg->p, cseg->len);
++                    }
+                   }
+                 }
+                 break;
+@@ -1282,10 +1282,7 @@ tcp_receive(struct tcp_pcb *pcb)
+ 
+       }
+     } else {
+-      if(!TCP_SEQ_BETWEEN(seqno, pcb->rcv_nxt, 
+-                          pcb->rcv_nxt + pcb->rcv_ann_wnd-1)){
+-        tcp_ack_now(pcb);
+-      }
++      tcp_ack_now(pcb);
+     }
+   } else {
+     /* Segments with length 0 is taken care of here. Segments that
+@@ -1331,7 +1328,8 @@ tcp_parseopt(struct tcp_pcb *pcb)
+         opts[c + 1] == 0x04) {
+         /* An MSS option with the right option length. */
+         mss = (opts[c + 2] << 8) | opts[c + 3];
+-        pcb->mss = mss > TCP_MSS? TCP_MSS: mss;
++        /* Limit the mss to the configured TCP_MSS and prevent division by 
zero */
++        pcb->mss = ((mss > TCP_MSS) || (mss == 0)) ? TCP_MSS : mss;
+ 
+         /* And we are done processing options. */
+         break;
+Index: src/core/ipv4/autoip.c
+===================================================================
+RCS file: /sources/lwip/lwip/src/core/ipv4/autoip.c,v
+retrieving revision 1.16
+retrieving revision 1.17
+diff -u -p -r1.16 -r1.17
+--- src/core/ipv4/autoip.c     26 Jan 2008 16:11:40 -0000      1.16
++++ src/core/ipv4/autoip.c     17 Jun 2008 20:16:23 -0000      1.17
+@@ -395,8 +395,8 @@ autoip_arp_reply(struct netif *netif, st
+     /* Copy struct ip_addr2 to aligned ip_addr, to support compilers without
+      * structure packing (not using structure copy which breaks 
strict-aliasing rules).
+      */
+-    MEMCPY(&sipaddr, &hdr->sipaddr, sizeof(sipaddr));
+-    MEMCPY(&dipaddr, &hdr->dipaddr, sizeof(dipaddr));
++    SMEMCPY(&sipaddr, &hdr->sipaddr, sizeof(sipaddr));
++    SMEMCPY(&dipaddr, &hdr->dipaddr, sizeof(dipaddr));
+       
+     if ((netif->autoip->state == AUTOIP_STATE_PROBING) ||
+         ((netif->autoip->state == AUTOIP_STATE_ANNOUNCING) &&
+Index: src/core/ipv4/inet_chksum.c
+===================================================================
+RCS file: /sources/lwip/lwip/src/core/ipv4/inet_chksum.c,v
+retrieving revision 1.4
+retrieving revision 1.5
+diff -u -p -r1.4 -r1.5
+--- src/core/ipv4/inet_chksum.c        10 Mar 2008 16:12:31 -0000      1.4
++++ src/core/ipv4/inet_chksum.c        17 Jun 2008 20:06:25 -0000      1.5
+@@ -41,8 +41,6 @@
+ #include "lwip/inet_chksum.h"
+ #include "lwip/inet.h"
+ 
+-#include <string.h>
+-
+ /* These are some reference implementations of the checksum algorithm, with 
the
+  * aim of being simple, correct and fully portable. Checksumming is the
+  * first thing you would want to optimize for your platform. If you create
+@@ -65,6 +63,11 @@
+ # define LWIP_CHKSUM_ALGORITHM 0
+ #endif
+ 
++/** Like the name says... */
++#define SWAP_BYTES_IN_WORD(w) ((w & 0xff) << 8) | ((w & 0xff00) >> 8)
++/** Split an u32_t in two u16_ts and add them up */
++#define FOLD_U32T(u)          ((u >> 16) + (u & 0x0000ffffUL))
++
+ #if (LWIP_CHKSUM_ALGORITHM == 1) /* Version #1 */
+ /**
+  * lwip checksum
+@@ -86,8 +89,7 @@ lwip_standard_chksum(void *dataptr, u16_
+   acc = 0;
+   /* dataptr may be at odd or even addresses */
+   octetptr = (u8_t*)dataptr;
+-  while (len > 1)
+-  {
++  while (len > 1) {
+     /* declare first octet as most significant
+        thus assume network order, ignoring host order */
+     src = (*octetptr) << 8;
+@@ -98,8 +100,7 @@ lwip_standard_chksum(void *dataptr, u16_
+     acc += src;
+     len -= 2;
+   }
+-  if (len > 0)
+-  {
++  if (len > 0) {
+     /* accumulate remaining octet */
+     src = (*octetptr) << 8;
+     acc += src;
+@@ -154,19 +155,22 @@ lwip_standard_chksum(void *dataptr, int 
+   }
+ 
+   /* Consume left-over byte, if any */
+-  if (len > 0)
++  if (len > 0) {
+     ((u8_t *)&t)[0] = *(u8_t *)ps;;
++  }
+ 
+   /* Add end bytes */
+   sum += t;
+ 
+-  /*  Fold 32-bit sum to 16 bits */
+-  while ((sum >> 16) != 0)
+-    sum = (sum & 0xffff) + (sum >> 16);
++  /* Fold 32-bit sum to 16 bits
++     calling this twice is propably faster than if statements... */
++  sum = FOLD_U32T(sum);
++  sum = FOLD_U32T(sum);
+ 
+   /* Swap if alignment was odd */
+-  if (odd)
+-    sum = ((sum & 0xff) << 8) | ((sum & 0xff00) >> 8);
++  if (odd) {
++    sum = SWAP_BYTES_IN_WORD(sum);
++  }
+ 
+   return sum;
+ }
+@@ -211,18 +215,20 @@ lwip_standard_chksum(void *dataptr, int 
+ 
+   while (len > 7)  {
+     tmp = sum + *pl++;          /* ping */
+-    if (tmp < sum)
++    if (tmp < sum) {
+       tmp++;                    /* add back carry */
++    }
+ 
+     sum = tmp + *pl++;          /* pong */
+-    if (sum < tmp)
++    if (sum < tmp) {
+       sum++;                    /* add back carry */
++    }
+ 
+     len -= 8;
+   }
+ 
+   /* make room in upper bits */
+-  sum = (sum >> 16) + (sum & 0xffff);
++  sum = FOLD_U32T(sum);
+ 
+   ps = (u16_t *)pl;
+ 
+@@ -233,16 +239,20 @@ lwip_standard_chksum(void *dataptr, int 
+   }
+ 
+   /* dangling tail byte remaining? */
+-  if (len > 0)                  /* include odd byte */
++  if (len > 0) {                /* include odd byte */
+     ((u8_t *)&t)[0] = *(u8_t *)ps;
++  }
+ 
+   sum += t;                     /* add end bytes */
+ 
+-  while ((sum >> 16) != 0)      /* combine halves */
+-    sum = (sum >> 16) + (sum & 0xffff);
++  /* Fold 32-bit sum to 16 bits
++     calling this twice is propably faster than if statements... */
++  sum = FOLD_U32T(sum);
++  sum = FOLD_U32T(sum);
+ 
+-  if (odd)
+-    sum = ((sum & 0xff) << 8) | ((sum & 0xff00) >> 8);
++  if (odd) {
++    sum = SWAP_BYTES_IN_WORD(sum);
++  }
+ 
+   return sum;
+ }
+@@ -277,18 +287,18 @@ inet_chksum_pseudo(struct pbuf *p,
+       (void *)q, (void *)q->next));
+     acc += LWIP_CHKSUM(q->payload, q->len);
+     /*LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): unwrapped 
lwip_chksum()=%"X32_F" \n", acc));*/
+-    while ((acc >> 16) != 0) {
+-      acc = (acc & 0xffffUL) + (acc >> 16);
+-    }
++    /* just executing this next line is probably faster that the if statement 
needed
++       to check whether we really need to execute it, and does no harm */
++    acc = FOLD_U32T(acc);
+     if (q->len % 2 != 0) {
+       swapped = 1 - swapped;
+-      acc = ((acc & 0xff) << 8) | ((acc & 0xff00UL) >> 8);
++      acc = SWAP_BYTES_IN_WORD(acc);
+     }
+     /*LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): wrapped 
lwip_chksum()=%"X32_F" \n", acc));*/
+   }
+ 
+   if (swapped) {
+-    acc = ((acc & 0xff) << 8) | ((acc & 0xff00UL) >> 8);
++    acc = SWAP_BYTES_IN_WORD(acc);
+   }
+   acc += (src->addr & 0xffffUL);
+   acc += ((src->addr >> 16) & 0xffffUL);
+@@ -297,9 +307,10 @@ inet_chksum_pseudo(struct pbuf *p,
+   acc += (u32_t)htons((u16_t)proto);
+   acc += (u32_t)htons(proto_len);
+ 
+-  while ((acc >> 16) != 0) {
+-    acc = (acc & 0xffffUL) + (acc >> 16);
+-  }
++  /* Fold 32-bit sum to 16 bits
++     calling this twice is propably faster than if statements... */
++  acc = FOLD_U32T(acc);
++  acc = FOLD_U32T(acc);
+   LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): pbuf chain 
lwip_chksum()=%"X32_F"\n", acc));
+   return (u16_t)~(acc & 0xffffUL);
+ }
+@@ -340,18 +351,17 @@ inet_chksum_pseudo_partial(struct pbuf *
+     chksum_len -= chklen;
+     LWIP_ASSERT("delete me", chksum_len < 0x7fff);
+     /*LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): unwrapped 
lwip_chksum()=%"X32_F" \n", acc));*/
+-    while ((acc >> 16) != 0) {
+-      acc = (acc & 0xffffUL) + (acc >> 16);
+-    }
++    /* fold the upper bit down */
++    acc = FOLD_U32T(acc);
+     if (q->len % 2 != 0) {
+       swapped = 1 - swapped;
+-      acc = ((acc & 0xff) << 8) | ((acc & 0xff00UL) >> 8);
++      acc = SWAP_BYTES_IN_WORD(acc);
+     }
+     /*LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): wrapped 
lwip_chksum()=%"X32_F" \n", acc));*/
+   }
+ 
+   if (swapped) {
+-    acc = ((acc & 0xff) << 8) | ((acc & 0xff00UL) >> 8);
++    acc = SWAP_BYTES_IN_WORD(acc);
+   }
+   acc += (src->addr & 0xffffUL);
+   acc += ((src->addr >> 16) & 0xffffUL);
+@@ -360,9 +370,10 @@ inet_chksum_pseudo_partial(struct pbuf *
+   acc += (u32_t)htons((u16_t)proto);
+   acc += (u32_t)htons(proto_len);
+ 
+-  while ((acc >> 16) != 0) {
+-    acc = (acc & 0xffffUL) + (acc >> 16);
+-  }
++  /* Fold 32-bit sum to 16 bits
++     calling this twice is propably faster than if statements... */
++  acc = FOLD_U32T(acc);
++  acc = FOLD_U32T(acc);
+   LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): pbuf chain 
lwip_chksum()=%"X32_F"\n", acc));
+   return (u16_t)~(acc & 0xffffUL);
+ }
+@@ -380,13 +391,7 @@ inet_chksum_pseudo_partial(struct pbuf *
+ u16_t
+ inet_chksum(void *dataptr, u16_t len)
+ {
+-  u32_t acc;
+-
+-  acc = LWIP_CHKSUM(dataptr, len);
+-  while ((acc >> 16) != 0) {
+-    acc = (acc & 0xffff) + (acc >> 16);
+-  }
+-  return (u16_t)~(acc & 0xffff);
++  return ~LWIP_CHKSUM(dataptr, len);
+ }
+ 
+ /**
+@@ -407,17 +412,15 @@ inet_chksum_pbuf(struct pbuf *p)
+   swapped = 0;
+   for(q = p; q != NULL; q = q->next) {
+     acc += LWIP_CHKSUM(q->payload, q->len);
+-    while ((acc >> 16) != 0) {
+-      acc = (acc & 0xffffUL) + (acc >> 16);
+-    }
++    acc = FOLD_U32T(acc);
+     if (q->len % 2 != 0) {
+       swapped = 1 - swapped;
+-      acc = (acc & 0x00ffUL << 8) | (acc & 0xff00UL >> 8);
++      acc = SWAP_BYTES_IN_WORD(acc);
+     }
+   }
+ 
+   if (swapped) {
+-    acc = ((acc & 0x00ffUL) << 8) | ((acc & 0xff00UL) >> 8);
++    acc = SWAP_BYTES_IN_WORD(acc);
+   }
+   return (u16_t)~(acc & 0xffffUL);
+ }
+Index: src/core/ipv4/ip.c
+===================================================================
+RCS file: /sources/lwip/lwip/src/core/ipv4/ip.c,v
+retrieving revision 1.66
+retrieving revision 1.68
+diff -u -p -r1.66 -r1.68
+--- src/core/ipv4/ip.c 14 Jan 2008 20:53:23 -0000      1.66
++++ src/core/ipv4/ip.c 17 Jun 2008 19:39:22 -0000      1.68
+@@ -531,9 +531,19 @@ ip_output_if(struct pbuf *p, struct ip_a
+   LWIP_DEBUGF(IP_DEBUG, ("ip_output_if: %c%c%"U16_F"\n", netif->name[0], 
netif->name[1], netif->num));
+   ip_debug_print(p);
+ 
+-  LWIP_DEBUGF(IP_DEBUG, ("netif->output()"));
++#if (LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF)
++  if (ip_addr_cmp(dest, &netif->ip_addr)) {
++    /* Packet to self, enqueue it for loopback */
++    LWIP_DEBUGF(IP_DEBUG, ("netif_loop_output()"));
++
++    return netif_loop_output(netif, p, dest);
++  } else
++#endif /* (LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF) */
++  {
++    LWIP_DEBUGF(IP_DEBUG, ("netif->output()"));
+ 
+-  return netif->output(netif, p, dest);
++    return netif->output(netif, p, dest);
++  }
+ }
+ 
+ /**
+Index: src/include/lwip/debug.h
+===================================================================
+RCS file: /sources/lwip/lwip/src/include/lwip/debug.h,v
+retrieving revision 1.37
+retrieving revision 1.39
+diff -u -p -r1.37 -r1.39
+--- src/include/lwip/debug.h   22 Sep 2007 11:16:07 -0000      1.37
++++ src/include/lwip/debug.h   16 Jul 2008 20:36:22 -0000      1.39
+@@ -61,26 +61,28 @@
+ #define LWIP_DBG_HALT          0x08U
+ 
+ #ifndef LWIP_NOASSERT
+-#define LWIP_ASSERT(x,y) do { if(!(y)) LWIP_PLATFORM_ASSERT(x); } while(0)
++#define LWIP_ASSERT(message, assertion) do { if(!(assertion)) \
++  LWIP_PLATFORM_ASSERT(message); } while(0)
+ #else  /* LWIP_NOASSERT */
+-#define LWIP_ASSERT(x,y) 
++#define LWIP_ASSERT(message, assertion) 
+ #endif /* LWIP_NOASSERT */
+ 
+-/** print "m" message only if "e" is true, and execute "h" expression */
++/** if "expression" isn't true, then print "message" and execute "handler" 
expression */
+ #ifndef LWIP_ERROR
+-#define LWIP_ERROR(m,e,h) do { if (!(e)) { LWIP_PLATFORM_ASSERT(m); h;}} 
while(0)
++#define LWIP_ERROR(message, expression, handler) do { if (!(expression)) { \
++  LWIP_PLATFORM_ASSERT(message); handler;}} while(0)
+ #endif /* LWIP_ERROR */
+ 
+ #ifdef LWIP_DEBUG
+ /** print debug message only if debug message type is enabled...
+  *  AND is of correct type AND is at least LWIP_DBG_LEVEL
+  */
+-#define LWIP_DEBUGF(debug,x) do { \
++#define LWIP_DEBUGF(debug, message) do { \
+                                if ( \
+                                    ((debug) & LWIP_DBG_ON) && \
+                                    ((debug) & LWIP_DBG_TYPES_ON) && \
+                                    ((s16_t)((debug) & LWIP_DBG_MASK_LEVEL) >= 
LWIP_DBG_MIN_LEVEL)) { \
+-                                 LWIP_PLATFORM_DIAG(x); \
++                                 LWIP_PLATFORM_DIAG(message); \
+                                  if ((debug) & LWIP_DBG_HALT) { \
+                                    while(1); \
+                                  } \
+@@ -88,7 +90,7 @@
+                              } while(0)
+ 
+ #else  /* LWIP_DEBUG */
+-#define LWIP_DEBUGF(debug,x) 
++#define LWIP_DEBUGF(debug, message) 
+ #endif /* LWIP_DEBUG */
+ 
+ #endif /* __LWIP_DEBUG_H__ */
+Index: src/include/lwip/err.h
+===================================================================
+RCS file: /sources/lwip/lwip/src/include/lwip/err.h,v
+retrieving revision 1.13
+retrieving revision 1.15
+diff -u -p -r1.13 -r1.15
+--- src/include/lwip/err.h     13 Dec 2007 23:06:50 -0000      1.13
++++ src/include/lwip/err.h     17 Jun 2008 20:27:32 -0000      1.15
+@@ -33,37 +33,43 @@
+ #define __LWIP_ERR_H__
+ 
+ #include "lwip/opt.h"
++#include "lwip/arch.h"
+ 
+ #ifdef __cplusplus
+ extern "C" {
+ #endif
+ 
+-typedef s8_t err_t;
++/** Define LWIP_ERR_T in cc.h if you want to use
++ *  a different type for your platform (must be signed). */
++#ifdef LWIP_ERR_T
++typedef LWIP_ERR_T err_t;
++#else /* LWIP_ERR_T */
++ typedef s8_t err_t;
++#endif /* LWIP_ERR_T*/
+ 
+ /* Definitions for error constants. */
+ 
+ #define ERR_OK          0    /* No error, everything OK. */
+ #define ERR_MEM        -1    /* Out of memory error.     */
+ #define ERR_BUF        -2    /* Buffer error.            */
+-#define ERR_RTE        -3    /* Routing problem.         */
++#define ERR_TIMEOUT    -3    /* Timeout.                 */
++#define ERR_RTE        -4    /* Routing problem.         */
+ 
+ #define ERR_IS_FATAL(e) ((e) < ERR_RTE)
+ 
+-#define ERR_ABRT       -4    /* Connection aborted.      */
+-#define ERR_RST        -5    /* Connection reset.        */
+-#define ERR_CLSD       -6    /* Connection closed.       */
+-#define ERR_CONN       -7    /* Not connected.           */
++#define ERR_ABRT       -5    /* Connection aborted.      */
++#define ERR_RST        -6    /* Connection reset.        */
++#define ERR_CLSD       -7    /* Connection closed.       */
++#define ERR_CONN       -8    /* Not connected.           */
+ 
+-#define ERR_VAL        -8    /* Illegal value.           */
++#define ERR_VAL        -9    /* Illegal value.           */
+ 
+-#define ERR_ARG        -9    /* Illegal argument.        */
++#define ERR_ARG        -10   /* Illegal argument.        */
+ 
+-#define ERR_USE        -10   /* Address in use.          */
++#define ERR_USE        -11   /* Address in use.          */
+ 
+-#define ERR_IF         -11   /* Low-level netif error    */
+-#define ERR_ISCONN     -12   /* Already connected.       */
+-
+-#define ERR_TIMEOUT    -13   /* Timeout.                 */
++#define ERR_IF         -12   /* Low-level netif error    */
++#define ERR_ISCONN     -13   /* Already connected.       */
+ 
+ #define ERR_INPROGRESS -14   /* Operation in progress    */
+ 
+Index: src/include/lwip/mem.h
+===================================================================
+RCS file: /sources/lwip/lwip/src/include/lwip/mem.h,v
+retrieving revision 1.21
+retrieving revision 1.22
+diff -u -p -r1.21 -r1.22
+--- src/include/lwip/mem.h     4 Mar 2008 16:31:32 -0000       1.21
++++ src/include/lwip/mem.h     30 May 2008 11:37:15 -0000      1.22
+@@ -50,16 +50,16 @@ typedef size_t mem_size_t;
+  * allow these defines to be overridden.
+  */
+ #ifndef mem_free
+-#define mem_free(x) free(x)
++#define mem_free free
+ #endif
+ #ifndef mem_malloc
+-#define mem_malloc(x) malloc(x)
++#define mem_malloc malloc
+ #endif
+ #ifndef mem_calloc
+-#define mem_calloc(x, y) calloc(x, y)
++#define mem_calloc calloc
+ #endif
+ #ifndef mem_realloc
+-#define mem_realloc(x, size) (x)
++#define mem_realloc realloc
+ #endif
+ #else /* MEM_LIBC_MALLOC */
+ 
+Index: src/include/lwip/netif.h
+===================================================================
+RCS file: /sources/lwip/lwip/src/include/lwip/netif.h,v
+retrieving revision 1.43
+retrieving revision 1.46
+diff -u -p -r1.43 -r1.46
+--- src/include/lwip/netif.h   9 Oct 2007 19:59:59 -0000       1.43
++++ src/include/lwip/netif.h   19 Jun 2008 16:27:23 -0000      1.46
+@@ -34,6 +34,8 @@
+ 
+ #include "lwip/opt.h"
+ 
++#define ENABLE_LOOPBACK (LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF)
++
+ #include "lwip/err.h"
+ 
+ #include "lwip/ip_addr.h"
+@@ -165,6 +167,14 @@ struct netif {
+ #if LWIP_NETIF_HWADDRHINT
+   u8_t *addr_hint;
+ #endif /* LWIP_NETIF_HWADDRHINT */
++#if ENABLE_LOOPBACK
++  /* List of packets to be queued for ourselves. */
++  struct pbuf *loop_first;
++  struct pbuf *loop_last;
++#if LWIP_LOOPBACK_MAX_PBUFS
++  u16_t loop_cnt_current;
++#endif /* LWIP_LOOPBACK_MAX_PBUFS */
++#endif /* ENABLE_LOOPBACK */
+ };
+ 
+ #if LWIP_SNMP
+@@ -242,4 +252,12 @@ void netif_set_link_callback(struct neti
+ }
+ #endif
+ 
++#if ENABLE_LOOPBACK
++err_t netif_loop_output(struct netif *netif, struct pbuf *p, struct ip_addr 
*dest_ip);
++void netif_poll(struct netif *netif);
++#if !LWIP_NETIF_LOOPBACK_MULTITHREADING
++void netif_poll_all(void);
++#endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */
++#endif /* ENABLE_LOOPBACK */
++
+ #endif /* __LWIP_NETIF_H__ */
+Index: src/include/lwip/opt.h
+===================================================================
+RCS file: /sources/lwip/lwip/src/include/lwip/opt.h,v
+retrieving revision 1.116
+retrieving revision 1.122
+diff -u -p -r1.116 -r1.122
+--- src/include/lwip/opt.h     31 Jan 2008 18:19:29 -0000      1.116
++++ src/include/lwip/opt.h     30 Jun 2008 18:16:52 -0000      1.122
+@@ -155,6 +155,27 @@
+ #define MEMP_USE_CUSTOM_POOLS           0
+ #endif
+ 
++/**
++ * Set this to 1 if you want to free PBUF_RAM pbufs (or call mem_free()) from
++ * interrupt context (or another context that doesn't allow waiting for a
++ * semaphore).
++ * If set to 1, mem_malloc will be protected by a semaphore and 
SYS_ARCH_PROTECT,
++ * while mem_free will only use SYS_ARCH_PROTECT. mem_malloc 
SYS_ARCH_UNPROTECTs
++ * with each loop so that mem_free can run.
++ *
++ * ATTENTION: As you can see from the above description, this leads to dis-/
++ * enabling interrupts often, which can be slow! Also, on low memory, 
mem_malloc
++ * can need longer.
++ *
++ * If you don't want that, at least for NO_SYS=0, you can still use the 
following
++ * functions to enqueue a deallocation call which then runs in the 
tcpip_thread
++ * context:
++ * - pbuf_free_callback(p);
++ * - mem_free_callback(m);
++ */
++#ifndef LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
++#define LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 0
++#endif
+ 
+ /*
+    ------------------------------------------------
+@@ -815,6 +836,39 @@
+ #define LWIP_NETIF_HWADDRHINT           0
+ #endif
+ 
++/**
++ * LWIP_NETIF_LOOPBACK==1: Support sending packets with a destination IP
++ * address equal to the netif IP address, looping them back up the stack.
++ */
++#ifndef LWIP_NETIF_LOOPBACK
++#define LWIP_NETIF_LOOPBACK             0
++#endif
++
++/**
++ * LWIP_LOOPBACK_MAX_PBUFS: Maximum number of pbufs on queue for loopback
++ * sending for each netif (0 = disabled)
++ */
++#ifndef LWIP_LOOPBACK_MAX_PBUFS
++#define LWIP_LOOPBACK_MAX_PBUFS         0
++#endif
++
++/**
++ * LWIP_NETIF_LOOPBACK_MULTITHREADING: Indicates whether threading is enabled 
in
++ * the system, as netifs must change how they behave depending on this setting
++ * for the LWIP_NETIF_LOOPBACK option to work.
++ * Setting this is needed to avoid reentering non-reentrant functions like
++ * tcp_input().
++ *    LWIP_NETIF_LOOPBACK_MULTITHREADING==1: Indicates that the user is using 
a
++ *       multithreaded environment like tcpip.c. In this case, netif->input()
++ *       is called directly.
++ *    LWIP_NETIF_LOOPBACK_MULTITHREADING==0: Indicates a polling (or NO_SYS) 
setup.
++ *       The packets are put on a list and netif_poll() must be called in
++ *       the main application loop.
++ */
++#ifndef LWIP_NETIF_LOOPBACK_MULTITHREADING
++#define LWIP_NETIF_LOOPBACK_MULTITHREADING    (!NO_SYS)
++#endif
++
+ /*
+    ------------------------------------
+    ---------- LOOPIF options ----------
+@@ -827,20 +881,16 @@
+ #define LWIP_HAVE_LOOPIF                0
+ #endif
+ 
++/*
++   ------------------------------------
++   ---------- SLIPIF options ----------
++   ------------------------------------
++*/
+ /**
+- * LWIP_LOOPIF_MULTITHREADING: Indicates whether threading is enabled in
+- * the system, as LOOPIF must change how it behaves depending on this setting.
+- * Setting this is needed to avoid reentering non-reentrant functions like
+- * tcp_input().
+- *    LWIP_LOOPIF_MULTITHREADING==1: Indicates that the user is using a
+- *       multithreaded environment like tcpip.c. In this case, netif->input()
+- *       is called directly.
+- *    LWIP_LOOPIF_MULTITHREADING==0: Indicates a polling (or NO_SYS) setup.
+- *       The packets are put on a list and loopif_poll() must be called in
+- *       the main application loop.
++ * LWIP_HAVE_SLIPIF==1: Support slip interface and slipif.c
+  */
+-#ifndef LWIP_LOOPIF_MULTITHREADING
+-#define LWIP_LOOPIF_MULTITHREADING      1
++#ifndef LWIP_HAVE_SLIPIF
++#define LWIP_HAVE_SLIPIF                0
+ #endif
+ 
+ /*
+Index: src/include/lwip/sio.h
+===================================================================
+RCS file: /sources/lwip/lwip/src/include/lwip/sio.h,v
+retrieving revision 1.7
+retrieving revision 1.8
+diff -u -p -r1.7 -r1.8
+--- src/include/lwip/sio.h     6 Sep 2007 16:43:44 -0000       1.7
++++ src/include/lwip/sio.h     27 Mar 2008 18:06:02 -0000      1.8
+@@ -32,16 +32,24 @@
+  * It needs to be implemented by those platforms which need SLIP or PPP
+  */
+ 
++#ifndef __SIO_H__
++#define __SIO_H__
++
+ #include "lwip/arch.h"
+ 
+ #ifdef __cplusplus
+ extern "C" {
+ #endif
+ 
++/* If you want to define sio_fd_t elsewhere or differently,
++   define this in your cc.h file. */
+ #ifndef __sio_fd_t_defined
+ typedef void * sio_fd_t;
+ #endif
+ 
++/* The following functions can be defined to something else in your cc.h file
++   or be implemented in your custom sio.c file. */
++
+ #ifndef sio_open
+ sio_fd_t sio_open(u8_t);
+ #endif
+@@ -69,3 +77,5 @@ void sio_read_abort(sio_fd_t);
+ #ifdef __cplusplus
+ }
+ #endif
++
++#endif /* __SIO_H__ */
+Index: src/include/lwip/sockets.h
+===================================================================
+RCS file: /sources/lwip/lwip/src/include/lwip/sockets.h,v
+retrieving revision 1.38
+retrieving revision 1.39
+diff -u -p -r1.38 -r1.39
+--- src/include/lwip/sockets.h 2 Dec 2007 15:24:02 -0000       1.38
++++ src/include/lwip/sockets.h 26 Apr 2008 10:46:23 -0000      1.39
+@@ -177,7 +177,22 @@ typedef struct ip_mreq {
+ } ip_mreq;
+ #endif /* LWIP_IGMP */
+ 
+-/* Unimplemented for now... */
++/*
++ * The Type of Service provides an indication of the abstract
++ * parameters of the quality of service desired.  These parameters are
++ * to be used to guide the selection of the actual service parameters
++ * when transmitting a datagram through a particular network.  Several
++ * networks offer service precedence, which somehow treats high
++ * precedence traffic as more important than other traffic (generally
++ * by accepting only traffic above a certain precedence at time of high
++ * load).  The major choice is a three way tradeoff between low-delay,
++ * high-reliability, and high-throughput.
++ * The use of the Delay, Throughput, and Reliability indications may
++ * increase the cost (in some sense) of the service.  In many networks
++ * better performance for one of these parameters is coupled with worse
++ * performance on another.  Except for very unusual cases at most two
++ * of these three indications should be set.
++ */
+ #define IPTOS_TOS_MASK          0x1E
+ #define IPTOS_TOS(tos)          ((tos) & IPTOS_TOS_MASK)
+ #define IPTOS_LOWDELAY          0x10
+@@ -187,7 +202,13 @@ typedef struct ip_mreq {
+ #define IPTOS_MINCOST           IPTOS_LOWCOST
+ 
+ /*
+- * Definitions for IP precedence (also in ip_tos) (Unimplemented)
++ * The Network Control precedence designation is intended to be used
++ * within a network only.  The actual use and control of that
++ * designation is up to each network. The Internetwork Control
++ * designation is intended for use by gateway control originators only.
++ * If the actual use of these precedence designations is of concern to
++ * a particular network, it is the responsibility of that network to
++ * control the access to, and use of, those precedence designations.
+  */
+ #define IPTOS_PREC_MASK                 0xe0
+ #define IPTOS_PREC(tos)                ((tos) & IPTOS_PREC_MASK)
+Index: src/include/lwip/stats.h
+===================================================================
+RCS file: /sources/lwip/lwip/src/include/lwip/stats.h,v
+retrieving revision 1.19
+retrieving revision 1.23
+diff -u -p -r1.19 -r1.23
+--- src/include/lwip/stats.h   28 Nov 2007 21:25:07 -0000      1.19
++++ src/include/lwip/stats.h   8 Jul 2008 09:15:57 -0000       1.23
+@@ -57,7 +57,6 @@ extern "C" {
+ 
+ struct stats_proto {
+   STAT_COUNTER xmit;             /* Transmitted packets. */
+-  STAT_COUNTER rexmit;           /* Retransmitted packets. */
+   STAT_COUNTER recv;             /* Received packets. */
+   STAT_COUNTER fw;               /* Forwarded packets. */
+   STAT_COUNTER drop;             /* Dropped packets. */
+@@ -87,7 +86,8 @@ struct stats_mem {
+   mem_size_t avail;
+   mem_size_t used;
+   mem_size_t max;
+-  mem_size_t err;
++  STAT_COUNTER err;
++  STAT_COUNTER illegal;
+ };
+ 
+ struct stats_syselem {
+@@ -142,64 +142,138 @@ extern struct stats_ lwip_stats;
+ #define stats_init() /* Compatibility define, not init needed. */
+ 
+ #define STATS_INC(x) ++lwip_stats.x
++#define STATS_DEC(x) --lwip_stats.x
+ #else
+ #define stats_init()
+ #define STATS_INC(x)
++#define STATS_DEC(x)
+ #endif /* LWIP_STATS */
+ 
+ #if TCP_STATS
+ #define TCP_STATS_INC(x) STATS_INC(x)
++#define TCP_STATS_DISPLAY() stats_display_proto(&lwip_stats.tcp, "TCP")
+ #else
+ #define TCP_STATS_INC(x)
++#define TCP_STATS_DISPLAY()
+ #endif
+ 
+ #if UDP_STATS
+ #define UDP_STATS_INC(x) STATS_INC(x)
++#define UDP_STATS_DISPLAY() stats_display_proto(&lwip_stats.udp, "UDP")
+ #else
+ #define UDP_STATS_INC(x)
++#define UDP_STATS_DISPLAY()
+ #endif
+ 
+ #if ICMP_STATS
+ #define ICMP_STATS_INC(x) STATS_INC(x)
++#define ICMP_STATS_DISPLAY() stats_display_proto(&lwip_stats.icmp, "ICMP")
+ #else
+ #define ICMP_STATS_INC(x)
++#define ICMP_STATS_DISPLAY()
+ #endif
+ 
+ #if IGMP_STATS
+ #define IGMP_STATS_INC(x) STATS_INC(x)
++#define IGMP_STATS_DISPLAY() stats_display_igmp(&lwip_stats.igmp)
+ #else
+ #define IGMP_STATS_INC(x)
++#define IGMP_STATS_DISPLAY()
+ #endif
+ 
+ #if IP_STATS
+ #define IP_STATS_INC(x) STATS_INC(x)
++#define IP_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip, "IP")
+ #else
+ #define IP_STATS_INC(x)
++#define IP_STATS_DISPLAY()
+ #endif
+ 
+ #if IPFRAG_STATS
+ #define IPFRAG_STATS_INC(x) STATS_INC(x)
++#define IPFRAG_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip_frag, 
"IP_FRAG")
+ #else
+ #define IPFRAG_STATS_INC(x)
++#define IPFRAG_STATS_DISPLAY()
+ #endif
+ 
+ #if ETHARP_STATS
+ #define ETHARP_STATS_INC(x) STATS_INC(x)
++#define ETHARP_STATS_DISPLAY() stats_display_proto(&lwip_stats.etharp, 
"ETHARP")
+ #else
+ #define ETHARP_STATS_INC(x)
++#define ETHARP_STATS_DISPLAY()
+ #endif
+ 
+ #if LINK_STATS
+ #define LINK_STATS_INC(x) STATS_INC(x)
++#define LINK_STATS_DISPLAY() stats_display_proto(&lwip_stats.link, "LINK")
+ #else
+ #define LINK_STATS_INC(x)
++#define LINK_STATS_DISPLAY()
++#endif
++
++#if MEM_STATS
++#define MEM_STATS_AVAIL(x, y) lwip_stats.mem.x = y
++#define MEM_STATS_INC(x) STATS_INC(mem.x)
++#define MEM_STATS_INC_USED(x, y) do { lwip_stats.mem.used += y; \
++                                    if (lwip_stats.mem.max < 
lwip_stats.mem.used) { \
++                                        lwip_stats.mem.max = 
lwip_stats.mem.used; \
++                                    } \
++                                 } while(0)
++#define MEM_STATS_DEC_USED(x, y) lwip_stats.mem.x -= y
++#define MEM_STATS_DISPLAY() stats_display_mem(&lwip_stats.mem, "HEAP")
++#else
++#define MEM_STATS_AVAIL(x, y)
++#define MEM_STATS_INC(x)
++#define MEM_STATS_INC_USED(x, y)
++#define MEM_STATS_DEC_USED(x, y)
++#define MEM_STATS_DISPLAY()
++#endif
++
++#if MEMP_STATS
++#define MEMP_STATS_AVAIL(x, i, y) lwip_stats.memp[i].x = y
++#define MEMP_STATS_INC(x, i) STATS_INC(memp[i].x)
++#define MEMP_STATS_DEC(x, i) STATS_DEC(memp[i].x)
++#define MEMP_STATS_INC_USED(x, i) do { ++lwip_stats.memp[i].used; \
++                                    if (lwip_stats.memp[i].max < 
lwip_stats.memp[i].used) { \
++                                        lwip_stats.memp[i].max = 
lwip_stats.memp[i].used; \
++                                    } \
++                                 } while(0)
++#define MEMP_STATS_DISPLAY(i) stats_display_memp(&lwip_stats.memp[i], i)
++#else
++#define MEMP_STATS_AVAIL(x, i, y)
++#define MEMP_STATS_INC(x, i)
++#define MEMP_STATS_DEC(x, i)
++#define MEMP_STATS_INC_USED(x, i)
++#define MEMP_STATS_DISPLAY(i)
++#endif
++
++#if SYS_STATS
++#define SYS_STATS_INC(x) STATS_INC(sys.x)
++#define SYS_STATS_DEC(x) STATS_DEC(sys.x)
++#define SYS_STATS_DISPLAY() stats_display_sys(&lwip_stats.sys)
++#else
++#define SYS_STATS_INC(x)
++#define SYS_STATS_DEC(x)
++#define SYS_STATS_DISPLAY()
+ #endif
+ 
+ /* Display of statistics */
+ #if LWIP_STATS_DISPLAY
+ void stats_display(void);
++void stats_display_proto(struct stats_proto *proto, char *name);
++void stats_display_igmp(struct stats_igmp *igmp);
++void stats_display_mem(struct stats_mem *mem, char *name);
++void stats_display_memp(struct stats_mem *mem, int index);
++void stats_display_sys(struct stats_sys *sys);
+ #else
+ #define stats_display()
++#define stats_display_proto(proto, name)
++#define stats_display_igmp(igmp)
++#define stats_display_mem(mem, name)
++#define stats_display_memp(mem, index)
++#define stats_display_sys(sys)
+ #endif /* LWIP_STATS_DISPLAY */
+ 
+ #ifdef __cplusplus
+Index: src/include/lwip/tcpip.h
+===================================================================
+RCS file: /sources/lwip/lwip/src/include/lwip/tcpip.h,v
+retrieving revision 1.24
+retrieving revision 1.27
+diff -u -p -r1.24 -r1.27
+--- src/include/lwip/tcpip.h   12 Jan 2008 11:52:22 -0000      1.24
++++ src/include/lwip/tcpip.h   27 Jun 2008 20:34:55 -0000      1.27
+@@ -83,7 +83,11 @@ err_t tcpip_netifapi_lock(struct netifap
+ #endif /* LWIP_NETIF_API */
+ 
+ err_t tcpip_callback_with_block(void (*f)(void *ctx), void *ctx, u8_t block);
+-#define tcpip_callback(f,ctx) tcpip_callback_with_block(f,ctx,1)
++#define tcpip_callback(f, ctx)              tcpip_callback_with_block(f, ctx, 
1)
++
++/* free pbufs or heap memory from another context without blocking */
++err_t pbuf_free_callback(struct pbuf *p);
++err_t mem_free_callback(void *m);
+ 
+ err_t tcpip_timeout(u32_t msecs, sys_timeout_handler h, void *arg);
+ #define tcpip_untimeout(h, arg) tcpip_timeout(0xffffffff, h, arg)
+Index: src/include/netif/loopif.h
+===================================================================
+RCS file: /sources/lwip/lwip/src/include/netif/loopif.h,v
+retrieving revision 1.7
+retrieving revision 1.9
+diff -u -p -r1.7 -r1.9
+--- src/include/netif/loopif.h 10 May 2007 10:59:20 -0000      1.7
++++ src/include/netif/loopif.h 17 Jun 2008 20:12:22 -0000      1.9
+@@ -32,6 +32,7 @@
+ #ifndef __NETIF_LOOPIF_H__
+ #define __NETIF_LOOPIF_H__
+ 
++#include "lwip/opt.h"
+ #include "lwip/netif.h"
+ #include "lwip/err.h"
+ 
+@@ -39,9 +40,9 @@
+ extern "C" {
+ #endif
+ 
+-#if !LWIP_LOOPIF_MULTITHREADING
+-void loopif_poll(struct netif *netif);
+-#endif
++#if !LWIP_NETIF_LOOPBACK_MULTITHREADING
++#define loopif_poll netif_poll
++#endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */
+ 
+ err_t loopif_init(struct netif *netif);
+ 
+Index: src/netif/etharp.c
+===================================================================
+RCS file: /sources/lwip/lwip/src/netif/etharp.c,v
+retrieving revision 1.145
+retrieving revision 1.148
+diff -u -p -r1.145 -r1.148
+--- src/netif/etharp.c 4 Mar 2008 13:41:24 -0000       1.145
++++ src/netif/etharp.c 19 Jun 2008 16:40:59 -0000      1.148
+@@ -353,7 +353,7 @@ find_entry(struct ip_addr *ipaddr, u8_t 
+    * 1) empty entry
+    * 2) oldest stable entry
+    * 3) oldest pending entry without queued packets
+-   * 4) oldest pending entry without queued packets
++   * 4) oldest pending entry with queued packets
+    * 
+    * { ETHARP_TRY_HARD is set at this point }
+    */ 
+@@ -1130,7 +1130,14 @@ ethernet_input(struct pbuf *p, struct ne
+ 
+   /* points to packet payload, which starts with an Ethernet header */
+   ethhdr = p->payload;
+-  
++  LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE,
++    ("ethernet_input: dest:%02x:%02x:%02x:%02x:%02x:%02x, 
src:%02x:%02x:%02x:%02x:%02x:%02x, type:%2hx\n",
++     (unsigned)ethhdr->dest.addr[0], (unsigned)ethhdr->dest.addr[1], 
(unsigned)ethhdr->dest.addr[2],
++     (unsigned)ethhdr->dest.addr[3], (unsigned)ethhdr->dest.addr[4], 
(unsigned)ethhdr->dest.addr[5],
++     (unsigned)ethhdr->src.addr[0], (unsigned)ethhdr->src.addr[1], 
(unsigned)ethhdr->src.addr[2],
++     (unsigned)ethhdr->src.addr[3], (unsigned)ethhdr->src.addr[4], 
(unsigned)ethhdr->src.addr[5],
++     (unsigned)htons(ethhdr->type)));
++
+   switch (htons(ethhdr->type)) {
+     /* IP packet? */
+     case ETHTYPE_IP:
+@@ -1165,6 +1172,8 @@ ethernet_input(struct pbuf *p, struct ne
+ #endif /* PPPOE_SUPPORT */
+ 
+     default:
++      ETHARP_STATS_INC(etharp.proterr);
++      ETHARP_STATS_INC(etharp.drop);
+       pbuf_free(p);
+       p = NULL;
+       break;
+Index: src/netif/loopif.c
+===================================================================
+RCS file: /sources/lwip/lwip/src/netif/loopif.c,v
+retrieving revision 1.26
+retrieving revision 1.27
+diff -u -p -r1.26 -r1.27
+--- src/netif/loopif.c 31 Aug 2007 10:14:09 -0000      1.26
++++ src/netif/loopif.c 12 Jun 2008 20:10:10 -0000      1.27
+@@ -40,149 +40,8 @@
+ #if LWIP_HAVE_LOOPIF
+ 
+ #include "netif/loopif.h"
+-#include "lwip/pbuf.h"
+ #include "lwip/snmp.h"
+ 
+-#include <string.h>
+-
+-#if !LWIP_LOOPIF_MULTITHREADING
+-
+-#include "lwip/sys.h"
+-#include "lwip/mem.h"
+-
+-/* helper struct for the linked list of pbufs */
+-struct loopif_private {
+-  struct pbuf *first;
+-  struct pbuf *last;
+-};
+-
+-/**
+- * Call loopif_poll() in the main loop of your application. This is to prevent
+- * reentering non-reentrant functions like tcp_input(). Packets passed to
+- * loopif_output() are put on a list that is passed to netif->input() by
+- * loopif_poll().
+- *
+- * @param netif the lwip network interface structure for this loopif
+- */
+-void
+-loopif_poll(struct netif *netif)
+-{
+-  SYS_ARCH_DECL_PROTECT(lev);
+-  struct pbuf *in, *in_end;
+-  struct loopif_private *priv = (struct loopif_private*)netif->state;
+-
+-  LWIP_ERROR("priv != NULL", (priv != NULL), return;);
+-
+-  do {
+-    /* Get a packet from the list. With SYS_LIGHTWEIGHT_PROT=1, this is 
protected */
+-    SYS_ARCH_PROTECT(lev);
+-    in = priv->first;
+-    if(in) {
+-      in_end = in;
+-      while(in_end->len != in_end->tot_len) {
+-        LWIP_ASSERT("bogus pbuf: len != tot_len but next == NULL!", 
in_end->next != NULL);
+-        in_end = in_end->next;
+-      }
+-      /* 'in_end' now points to the last pbuf from 'in' */
+-      if(in_end == priv->last) {
+-        /* this was the last pbuf in the list */
+-        priv->first = priv->last = NULL;
+-      } else {
+-        /* pop the pbuf off the list */
+-        priv->first = in_end->next;
+-        LWIP_ASSERT("should not be null since first != last!", priv->first != 
NULL);
+-      }
+-    }
+-    SYS_ARCH_UNPROTECT(lev);
+-  
+-    if(in != NULL) {
+-      if(in_end->next != NULL) {
+-        /* De-queue the pbuf from its successors on the 'priv' list. */
+-        in_end->next = NULL;
+-      }
+-      if(netif->input(in, netif) != ERR_OK) {
+-        pbuf_free(in);
+-      }
+-      /* Don't reference the packet any more! */
+-      in = NULL;
+-      in_end = NULL;
+-    }
+-  /* go on while there is a packet on the list */
+-  } while(priv->first != NULL);
+-}
+-#endif /* LWIP_LOOPIF_MULTITHREADING */
+-
+-/**
+- * Send an IP packet over the loopback interface.
+- * The pbuf is simply copied and handed back to netif->input.
+- * In multithreaded mode, this is done directly since netif->input must put
+- * the packet on a queue.
+- * In callback mode, the packet is put on an internal queue and is fed to
+- * netif->input by loopif_poll().
+- *
+- * @param netif the lwip network interface structure for this loopif
+- * @param p the (IP) packet to 'send'
+- * @param ipaddr the ip address to send the packet to (not used for loopif)
+- * @return ERR_OK if the packet has been sent
+- *         ERR_MEM if the pbuf used to copy the packet couldn't be allocated
+- */
+-static err_t
+-loopif_output(struct netif *netif, struct pbuf *p,
+-       struct ip_addr *ipaddr)
+-{
+-#if !LWIP_LOOPIF_MULTITHREADING
+-  SYS_ARCH_DECL_PROTECT(lev);
+-  struct loopif_private *priv;
+-  struct pbuf *last;
+-#endif /* LWIP_LOOPIF_MULTITHREADING */
+-  struct pbuf *r;
+-  err_t err;
+-
+-  LWIP_UNUSED_ARG(ipaddr);
+-
+-  /* Allocate a new pbuf */
+-  r = pbuf_alloc(PBUF_RAW, p->tot_len, PBUF_RAM);
+-  if (r == NULL) {
+-    return ERR_MEM;
+-  }
+-
+-  /* Copy the whole pbuf queue p into the single pbuf r */
+-  if ((err = pbuf_copy(r, p)) != ERR_OK) {
+-    pbuf_free(r);
+-    r = NULL;
+-    return err;
+-  }
+-
+-#if LWIP_LOOPIF_MULTITHREADING
+-  /* Multithreading environment, netif->input() is supposed to put the packet
+-     into a mailbox, so we can safely call it here without risking to re-enter
+-     functions that are not reentrant (TCP!!!) */
+-  if(netif->input(r, netif) != ERR_OK) {
+-    pbuf_free(r);
+-    r = NULL;
+-  }
+-#else /* LWIP_LOOPIF_MULTITHREADING */
+-  /* Raw API without threads: put the packet on a linked list which gets 
emptied
+-     through calling loopif_poll(). */
+-  priv = (struct loopif_private*)netif->state;
+-
+-  /* let last point to the last pbuf in chain r */
+-  for (last = r; last->next != NULL; last = last->next);
+-  SYS_ARCH_PROTECT(lev);
+-  if(priv->first != NULL) {
+-    LWIP_ASSERT("if first != NULL, last must also be != NULL", priv->last != 
NULL);
+-    priv->last->next = r;
+-    priv->last = last;
+-  } else {
+-    priv->first = r;
+-    priv->last = last;
+-  }
+-  SYS_ARCH_UNPROTECT(lev);
+-#endif /* LWIP_LOOPIF_MULTITHREADING */
+-
+-  return ERR_OK;    
+-}
+-
+ /**
+  * Initialize a lwip network interface structure for a loopback interface
+  *
+@@ -193,16 +52,6 @@ loopif_output(struct netif *netif, struc
+ err_t
+ loopif_init(struct netif *netif)
+ {
+-#if !LWIP_LOOPIF_MULTITHREADING
+-  struct loopif_private *priv;
+-
+-  priv = (struct loopif_private*)mem_malloc(sizeof(struct loopif_private));
+-  if(priv == NULL) 
+-    return ERR_MEM;
+-  priv->first = priv->last = NULL;
+-  netif->state = priv;
+-#endif /* LWIP_LOOPIF_MULTITHREADING */
+-
+   /* initialize the snmp variables and counters inside the struct netif
+    * ifSpeed: no assumption can be made!
+    */
+@@ -210,7 +59,7 @@ loopif_init(struct netif *netif)
+ 
+   netif->name[0] = 'l';
+   netif->name[1] = 'o';
+-  netif->output = loopif_output;
++  netif->output = netif_loop_output;
+   return ERR_OK;
+ }
+ 
+Index: src/netif/slipif.c
+===================================================================
+RCS file: /sources/lwip/lwip/src/netif/slipif.c,v
+retrieving revision 1.29
+retrieving revision 1.30
+diff -u -p -r1.29 -r1.30
+--- src/netif/slipif.c 30 Nov 2007 17:22:21 -0000      1.29
++++ src/netif/slipif.c 17 Jun 2008 20:14:05 -0000      1.30
+@@ -44,6 +44,9 @@
+ 
+ #include "netif/slipif.h"
+ #include "lwip/opt.h"
++
++#if LWIP_HAVE_SLIPIF
++
+ #include "lwip/def.h"
+ #include "lwip/pbuf.h"
+ #include "lwip/sys.h"
+@@ -273,3 +276,4 @@ slipif_init(struct netif *netif)
+   sys_thread_new(SLIPIF_THREAD_NAME, slipif_loop, netif, 
SLIPIF_THREAD_STACKSIZE, SLIPIF_THREAD_PRIO);
+   return ERR_OK;
+ }
++#endif /* LWIP_HAVE_SLIPIF */
diff -r eb0fc71cfc72 -r 400e5d4877ca stubdom/newlib.patch
--- a/stubdom/newlib.patch      Tue Jul 08 11:41:43 2008 +0900
+++ b/stubdom/newlib.patch      Fri Jul 18 12:12:41 2008 +0900
@@ -201,3 +201,429 @@ diff -u -p -r1.1 memcpy.S
    ret
  
  
+--- newlib/libc/machine/x86_64/x86_64mach.h.orig       2008-07-11 
14:57:23.062269000 +0100
++++ newlib/libc/machine/x86_64/x86_64mach.h    2008-07-11 14:58:01.262503000 
+0100
+@@ -22,81 +22,81 @@
+ 
+ #define REG(x) CONCAT1(__REG_PREFIX__, x)
+ 
+-#define rax REG(rax)
+-#define rbx REG(rbx)
+-#define rcx REG(rcx)
+-#define rdx REG(rdx)
+-#define rsi REG(rsi)
+-#define rdi REG(rdi)
+-#define rbp REG(rbp)
+-#define rsp REG(rsp)
+-
+-#define r8  REG(r8)
+-#define r9  REG(r9)
+-#define r10 REG(r10)
+-#define r11 REG(r11)
+-#define r12 REG(r12)
+-#define r13 REG(r13)
+-#define r14 REG(r14)
+-#define r15 REG(r15)
+-
+-#define eax REG(eax)
+-#define ebx REG(ebx)
+-#define ecx REG(ecx)
+-#define edx REG(edx)
+-#define esi REG(esi)
+-#define edi REG(edi)
+-#define ebp REG(ebp)
+-#define esp REG(esp)
+-
+-#define st0 REG(st)
+-#define st1 REG(st(1))
+-#define st2 REG(st(2))
+-#define st3 REG(st(3))
+-#define st4 REG(st(4))
+-#define st5 REG(st(5))
+-#define st6 REG(st(6))
+-#define st7 REG(st(7))
+-
+-#define ax REG(ax)
+-#define bx REG(bx)
+-#define cx REG(cx)
+-#define dx REG(dx)
+-
+-#define ah REG(ah)
+-#define bh REG(bh)
+-#define ch REG(ch)
+-#define dh REG(dh)
+-
+-#define al REG(al)
+-#define bl REG(bl)
+-#define cl REG(cl)
+-#define dl REG(dl)
+-
+-#define sil REG(sil)
+-
+-#define mm1 REG(mm1)
+-#define mm2 REG(mm2)
+-#define mm3 REG(mm3)
+-#define mm4 REG(mm4)
+-#define mm5 REG(mm5)
+-#define mm6 REG(mm6)
+-#define mm7 REG(mm7)
+-
+-#define xmm0 REG(xmm0)
+-#define xmm1 REG(xmm1)
+-#define xmm2 REG(xmm2)
+-#define xmm3 REG(xmm3)
+-#define xmm4 REG(xmm4)
+-#define xmm5 REG(xmm5)
+-#define xmm6 REG(xmm6)
+-#define xmm7 REG(xmm7)
+-
+-#define cr0 REG(cr0)
+-#define cr1 REG(cr1)
+-#define cr2 REG(cr2)
+-#define cr3 REG(cr3)
+-#define cr4 REG(cr4)
++#define rax %rax
++#define rbx %rbx
++#define rcx %rcx
++#define rdx %rdx
++#define rsi %rsi
++#define rdi %rdi
++#define rbp %rbp
++#define rsp %rsp
++
++#define r8  %r8
++#define r9  %r9
++#define r10 %r10
++#define r11 %r11
++#define r12 %r12
++#define r13 %r13
++#define r14 %r14
++#define r15 %r15
++
++#define eax %eax
++#define ebx %ebx
++#define ecx %ecx
++#define edx %edx
++#define esi %esi
++#define edi %edi
++#define ebp %ebp
++#define esp %esp
++
++#define st0 %st
++#define st1 %st(1)
++#define st2 %st(2)
++#define st3 %st(3)
++#define st4 %st(4)
++#define st5 %st(5)
++#define st6 %st(6)
++#define st7 %st(7)
++
++#define ax %ax
++#define bx %bx
++#define cx %cx
++#define dx %dx
++
++#define ah %ah
++#define bh %bh
++#define ch %ch
++#define dh %dh
++
++#define al %al
++#define bl %bl
++#define cl %cl
++#define dl %dl
++
++#define sil %sil
++
++#define mm1 %mm1
++#define mm2 %mm2
++#define mm3 %mm3
++#define mm4 %mm4
++#define mm5 %mm5
++#define mm6 %mm6
++#define mm7 %mm7
++
++#define xmm0 %xmm0
++#define xmm1 %xmm1
++#define xmm2 %xmm2
++#define xmm3 %xmm3
++#define xmm4 %xmm4
++#define xmm5 %xmm5
++#define xmm6 %xmm6
++#define xmm7 %xmm7
++
++#define cr0 %cr0
++#define cr1 %cr1
++#define cr2 %cr2
++#define cr3 %cr3
++#define cr4 %cr4
+ 
+ #ifdef _I386MACH_NEED_SOTYPE_FUNCTION
+ #define SOTYPE_FUNCTION(sym) .type SYM(sym),@function
+--- newlib/libc/machine/x86_64/memcpy.S.orig   2008-07-11 15:12:27.494693000 
+0100
++++ newlib/libc/machine/x86_64/memcpy.S        2008-07-11 15:12:29.448706000 
+0100
+@@ -60,14 +60,14 @@
+   movq    48 (rsi), r13
+   movq    56 (rsi), r14
+ 
+-  movntiq rax,    (rdi)
+-  movntiq r8 ,  8 (rdi)
+-  movntiq r9 , 16 (rdi)
+-  movntiq r10, 24 (rdi)
+-  movntiq r11, 32 (rdi)
+-  movntiq r12, 40 (rdi)
+-  movntiq r13, 48 (rdi)
+-  movntiq r14, 56 (rdi)
++  movnti rax,    (rdi)
++  movnti r8 ,  8 (rdi)
++  movnti r9 , 16 (rdi)
++  movnti r10, 24 (rdi)
++  movnti r11, 32 (rdi)
++  movnti r12, 40 (rdi)
++  movnti r13, 48 (rdi)
++  movnti r14, 56 (rdi)
+ 
+   movq     64 (rsi), rax
+   movq     72 (rsi), r8
+@@ -78,14 +78,14 @@
+   movq    112 (rsi), r13
+   movq    120 (rsi), r14
+ 
+-  movntiq rax,  64 (rdi)
+-  movntiq r8 ,  72 (rdi)
+-  movntiq r9 ,  80 (rdi)
+-  movntiq r10,  88 (rdi)
+-  movntiq r11,  96 (rdi)
+-  movntiq r12, 104 (rdi)
+-  movntiq r13, 112 (rdi)
+-  movntiq r14, 120 (rdi)
++  movnti rax,  64 (rdi)
++  movnti r8 ,  72 (rdi)
++  movnti r9 ,  80 (rdi)
++  movnti r10,  88 (rdi)
++  movnti r11,  96 (rdi)
++  movnti r12, 104 (rdi)
++  movnti r13, 112 (rdi)
++  movnti r14, 120 (rdi)
+ 
+   leaq    128 (rsi), rsi
+   leaq    128 (rdi), rdi
+--- newlib/libc/machine/i386/i386mach.h        2000-08-28 18:50:06.000000000 
+0100
++++ newlib/libc/machine/i386/i386mach.h        2008-07-11 15:17:13.874409000 
+0100
+@@ -27,46 +27,46 @@
+  
+ #define REG(x) CONCAT1(__REG_PREFIX__, x)
+  
+-#define eax REG(eax)
+-#define ebx REG(ebx)
+-#define ecx REG(ecx)
+-#define edx REG(edx)
+-#define esi REG(esi)
+-#define edi REG(edi)
+-#define ebp REG(ebp)
+-#define esp REG(esp)
+-
+-#define st0 REG(st)
+-#define st1 REG(st(1))
+-#define st2 REG(st(2))
+-#define st3 REG(st(3))
+-#define st4 REG(st(4))
+-#define st5 REG(st(5))
+-#define st6 REG(st(6))
+-#define st7 REG(st(7))
+-
+-#define ax REG(ax)
+-#define bx REG(bx)
+-#define cx REG(cx)
+-#define dx REG(dx)
+-
+-#define ah REG(ah)
+-#define bh REG(bh)
+-#define ch REG(ch)
+-#define dh REG(dh)
+-
+-#define al REG(al)
+-#define bl REG(bl)
+-#define cl REG(cl)
+-#define dl REG(dl)
+-
+-#define mm1 REG(mm1)
+-#define mm2 REG(mm2)
+-#define mm3 REG(mm3)
+-#define mm4 REG(mm4)
+-#define mm5 REG(mm5)
+-#define mm6 REG(mm6)
+-#define mm7 REG(mm7)
++#define eax %eax
++#define ebx %ebx
++#define ecx %ecx
++#define edx %edx
++#define esi %esi
++#define edi %edi
++#define ebp %ebp
++#define esp %esp
++
++#define st0 %st
++#define st1 %st(1)
++#define st2 %st(2)
++#define st3 %st(3)
++#define st4 %st(4)
++#define st5 %st(5)
++#define st6 %st(6)
++#define st7 %st(7)
++
++#define ax %ax
++#define bx %bx
++#define cx %cx
++#define dx %dx
++
++#define ah %ah
++#define bh %bh
++#define ch %ch
++#define dh %dh
++
++#define al %al
++#define bl %bl
++#define cl %cl
++#define dl %dl
++
++#define mm1 %mm1
++#define mm2 %mm2
++#define mm3 %mm3
++#define mm4 %mm4
++#define mm5 %mm5
++#define mm6 %mm6
++#define mm7 %mm7
+ 
+ #ifdef _I386MACH_NEED_SOTYPE_FUNCTION
+ #define SOTYPE_FUNCTION(sym) .type SYM(sym),@function
+--- newlib/libc/machine/x86_64/memset.S        2007-08-28 22:56:49.000000000 
+0100
++++ newlib/libc/machine/x86_64/memset.S        2008-07-11 15:16:59.098320000 
+0100
+@@ -40,22 +40,22 @@
+ 
+   .p2align 4
+ loop:
+-  movntiq rax,     (rdi)
+-  movntiq rax,   8 (rdi)
+-  movntiq rax,  16 (rdi)
+-  movntiq rax,  24 (rdi)
+-  movntiq rax,  32 (rdi)
+-  movntiq rax,  40 (rdi)
+-  movntiq rax,  48 (rdi)
+-  movntiq rax,  56 (rdi)
+-  movntiq rax,  64 (rdi)
+-  movntiq rax,  72 (rdi)
+-  movntiq rax,  80 (rdi)
+-  movntiq rax,  88 (rdi)
+-  movntiq rax,  96 (rdi)
+-  movntiq rax, 104 (rdi)
+-  movntiq rax, 112 (rdi)
+-  movntiq rax, 120 (rdi)
++  movnti rax,     (rdi)
++  movnti rax,   8 (rdi)
++  movnti rax,  16 (rdi)
++  movnti rax,  24 (rdi)
++  movnti rax,  32 (rdi)
++  movnti rax,  40 (rdi)
++  movnti rax,  48 (rdi)
++  movnti rax,  56 (rdi)
++  movnti rax,  64 (rdi)
++  movnti rax,  72 (rdi)
++  movnti rax,  80 (rdi)
++  movnti rax,  88 (rdi)
++  movnti rax,  96 (rdi)
++  movnti rax, 104 (rdi)
++  movnti rax, 112 (rdi)
++  movnti rax, 120 (rdi)
+ 
+   leaq    128 (rdi), rdi
+ 
+--- newlib/libm/machine/i386/i386mach.h.orig   2008-07-11 15:30:37.367227000 
+0100
++++ newlib/libm/machine/i386/i386mach.h        2008-07-11 15:30:55.232337000 
+0100
+@@ -27,46 +27,46 @@
+  
+ #define REG(x) CONCAT1(__REG_PREFIX__, x)
+  
+-#define eax REG(eax)
+-#define ebx REG(ebx)
+-#define ecx REG(ecx)
+-#define edx REG(edx)
+-#define esi REG(esi)
+-#define edi REG(edi)
+-#define ebp REG(ebp)
+-#define esp REG(esp)
+-
+-#define st0 REG(st)
+-#define st1 REG(st(1))
+-#define st2 REG(st(2))
+-#define st3 REG(st(3))
+-#define st4 REG(st(4))
+-#define st5 REG(st(5))
+-#define st6 REG(st(6))
+-#define st7 REG(st(7))
+-
+-#define ax REG(ax)
+-#define bx REG(bx)
+-#define cx REG(cx)
+-#define dx REG(dx)
+-
+-#define ah REG(ah)
+-#define bh REG(bh)
+-#define ch REG(ch)
+-#define dh REG(dh)
+-
+-#define al REG(al)
+-#define bl REG(bl)
+-#define cl REG(cl)
+-#define dl REG(dl)
+-
+-#define mm1 REG(mm1)
+-#define mm2 REG(mm2)
+-#define mm3 REG(mm3)
+-#define mm4 REG(mm4)
+-#define mm5 REG(mm5)
+-#define mm6 REG(mm6)
+-#define mm7 REG(mm7)
++#define eax %eax
++#define ebx %ebx
++#define ecx %ecx
++#define edx %edx
++#define esi %esi
++#define edi %edi
++#define ebp %ebp
++#define esp %esp
++
++#define st0 %st
++#define st1 %st(1)
++#define st2 %st(2)
++#define st3 %st(3)
++#define st4 %st(4)
++#define st5 %st(5)
++#define st6 %st(6)
++#define st7 %st(7)
++
++#define ax %ax
++#define bx %bx
++#define cx %cx
++#define dx %dx
++
++#define ah %ah
++#define bh %bh
++#define ch %ch
++#define dh %dh
++
++#define al %al
++#define bl %bl
++#define cl %cl
++#define dl %dl
++
++#define mm1 %mm1
++#define mm2 %mm2
++#define mm3 %mm3
++#define mm4 %mm4
++#define mm5 %mm5
++#define mm6 %mm6
++#define mm7 %mm7
+ 
+ #ifdef _I386MACH_NEED_SOTYPE_FUNCTION
+ #define SOTYPE_FUNCTION(sym) .type SYM(sym),@function
diff -r eb0fc71cfc72 -r 400e5d4877ca stubdom/pciutils.patch
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/stubdom/pciutils.patch    Fri Jul 18 12:12:41 2008 +0900
@@ -0,0 +1,299 @@
+diff -urN pciutils-2.2.9.orig/lib/access.c pciutils-2.2.9/lib/access.c
+--- pciutils-2.2.9.orig/lib/access.c   2007-02-06 11:59:43.000000000 +0000
++++ pciutils-2.2.9/lib/access.c        2008-06-30 19:07:09.713187000 +0100
+@@ -57,6 +57,11 @@
+ #else
+   NULL,
+ #endif
++#ifdef PCI_OS_MINIOS
++  &pm_minios,
++#else
++  NULL,
++#endif
+ };
+ 
+ struct pci_access *
+--- pciutils-2.2.9.orig/lib/pci.h      2006-09-09 13:46:06.000000000 +0100
++++ pciutils-2.2.9/lib/pci.h   2008-06-30 18:56:15.350111000 +0100
+@@ -33,6 +33,7 @@
+   PCI_ACCESS_NBSD_LIBPCI,             /* NetBSD libpci */
+   PCI_ACCESS_OBSD_DEVICE,             /* OpenBSD /dev/pci */
+   PCI_ACCESS_DUMP,                    /* Dump file (params: filename) */
++  PCI_ACCESS_MINIOS,                  /* MiniOS */
+   PCI_ACCESS_MAX
+ };
+ 
+@@ -63,6 +64,7 @@
+   int fd_rw;                          /* proc: fd opened read-write */
+   struct pci_dev *cached_dev;         /* proc: device the fd is for */
+   int fd_pos;                         /* proc: current position */
++  void *minios;
+ };
+ 
+ /* Initialize PCI access */
+--- pciutils-2.2.9.orig/lib/internal.h 2006-09-09 11:52:47.000000000 +0100
++++ pciutils-2.2.9/lib/internal.h      2008-07-01 10:46:24.968202000 +0100
+@@ -37,4 +37,4 @@
+ 
+ extern struct pci_methods pm_intel_conf1, pm_intel_conf2, pm_linux_proc,
+       pm_fbsd_device, pm_aix_device, pm_nbsd_libpci, pm_obsd_device,
+-      pm_dump, pm_linux_sysfs;
++      pm_dump, pm_linux_sysfs, pm_minios;
+--- pciutils-2.2.9.orig/lib/Makefile   2007-10-19 13:41:34.000000000 +0100
++++ pciutils-2.2.9/lib/Makefile        2008-07-01 12:13:14.400525000 +0100
+@@ -46,6 +46,12 @@
+ PCILIB=libpciutils.a
+ endif
+ 
++ifdef PCI_OS_MINIOS
++XEN_ROOT=../../..
++include $(XEN_ROOT)/Config.mk
++OBJS += minios.o
++endif
++
+ all: $(PCILIB) $(PCILIBPC)
+ 
+ $(PCILIB): $(OBJS)
+--- pciutils-2.2.9.orig/lib/types.h    2007-09-03 09:44:15.000000000 +0100
++++ pciutils-2.2.9/lib/types.h 2008-07-01 12:17:08.396156000 +0100
+@@ -17,9 +17,13 @@
+ typedef DWORD u32;
+ #elif defined(PCI_HAVE_STDINT_H)
+ #include <stdint.h>
++#ifdef PCI_OS_MINIOS
++#include <types.h>
++#else
+ typedef uint8_t u8;
+ typedef uint16_t u16;
+ typedef uint32_t u32;
++#endif
+ #else
+ typedef u_int8_t u8;
+ typedef u_int16_t u16;
+--- pciutils-2.2.9.orig/lib/minios.c   1970-01-01 01:00:00.000000000 +0100
++++ pciutils-2.2.9/lib/minios.c        2008-07-01 12:31:40.554260000 +0100
+@@ -0,0 +1,113 @@
++/*
++ *    The PCI Library -- MiniOS PCI frontend access
++ *
++ *    Samuel Thibault <samuel.thibault@xxxxxxxxxxxxx>, 2008
++ *
++ *    Can be freely distributed and used under the terms of the GNU GPL.
++ */
++
++#include <os.h>
++#include <pcifront.h>
++#include <xenbus.h>
++#include "internal.h"
++
++static int
++minios_detect(struct pci_access *a)
++{
++  return 1;
++}
++
++static void
++minios_init(struct pci_access *a)
++{
++  a->minios = init_pcifront(NULL);
++  if (!a->minios)
++    a->warning("minios_init open failed");
++}
++
++static void
++minios_cleanup(struct pci_access *a)
++{
++  if (a->minios)
++    shutdown_pcifront(a->minios);
++}
++
++static void
++minios_scan(struct pci_access *a)
++{
++  if (!a->minios)
++    return;
++
++  void func(unsigned int domain, unsigned int bus, unsigned int slot, 
unsigned int fun)
++  {
++    struct pci_dev *d = pci_alloc_dev(a);
++
++    d->domain = domain;
++    d->bus = bus;
++    d->dev = slot;
++    d->func = fun;
++
++    pci_link_dev(a, d);
++  }
++
++  pcifront_scan(a->minios, func);
++}
++
++static int
++minios_read(struct pci_dev *d, int pos, byte *buf, int len)
++{
++  unsigned int val;
++  switch (len) {
++    case 1:
++      if (pcifront_conf_read(d->access->minios, d->domain, d->bus, d->dev, 
d->func, pos, len, &val))
++        return 0;
++      * buf = val;
++      return 1;
++    case 2:
++      if (pcifront_conf_read(d->access->minios, d->domain, d->bus, d->dev, 
d->func, pos, len, &val))
++        return 0;
++      *(u16 *) buf = cpu_to_le16((u16) val);
++      return 1;
++    case 4:
++      if (pcifront_conf_read(d->access->minios, d->domain, d->bus, d->dev, 
d->func, pos, len, &val))
++        return 0;
++      *(u32 *) buf = cpu_to_le32((u32) val);
++      return 1;
++    default:
++      return pci_generic_block_read(d, pos, buf, len);
++  }
++}
++
++static int
++minios_write(struct pci_dev *d, int pos, byte *buf, int len)
++{
++  unsigned int val;
++  switch (len) {
++    case 1:
++      val = * buf;
++      break;
++    case 2:
++      val = le16_to_cpu(*(u16 *) buf);
++      break;
++    case 4:
++      val = le32_to_cpu(*(u32 *) buf);
++      break;
++    default:
++      return pci_generic_block_write(d, pos, buf, len);
++  }
++  return !pcifront_conf_write(d->access->minios, d->domain, d->bus, d->dev, 
d->func, pos, len, val);
++}
++
++struct pci_methods pm_minios = {
++  "MiniOS-device",
++  NULL,                                 /* config */
++  minios_detect,
++  minios_init,
++  minios_cleanup,
++  minios_scan,
++  pci_generic_fill_info,
++  minios_read,
++  minios_write,
++  NULL,                                 /* dev_init */
++  NULL                                  /* dev_cleanup */
++};
+--- pciutils-2.2.9/lib/generic.c       2007-02-06 12:00:05.000000000 +0000
++++ pciutils-2.2.9-mine/lib/generic.c  2008-07-01 19:13:52.289949000 +0100
+@@ -74,6 +74,19 @@
+   pci_generic_scan_bus(a, busmap, 0);
+ }
+ 
++static u32 pci_size(u32 base, u32 maxbase, u32 mask)
++{
++  u32 size = mask & maxbase;
++  if (!size)
++    return 0;
++  size = (size & ~(size-1)) - 1;
++
++  if (base == maxbase && ((base | size) & mask) != mask)
++    return 0;
++
++  return size + 1;
++}
++
+ int
+ pci_generic_fill_info(struct pci_dev *d, int flags)
+ {
+@@ -114,23 +127,61 @@
+             if (!x || x == (u32) ~0)
+               continue;
+             if ((x & PCI_BASE_ADDRESS_SPACE) == PCI_BASE_ADDRESS_SPACE_IO)
+-              d->base_addr[i] = x;
+-            else
++                {
++                  d->base_addr[i] = x & PCI_BASE_ADDRESS_IO_MASK;
++                  if (flags & PCI_FILL_SIZES)
++                    {
++                      u32 size;
++                      pci_write_long(d, PCI_BASE_ADDRESS_0 + i*4, ~0);
++                      d->size[i] = pci_size(x, pci_read_long(d, 
PCI_BASE_ADDRESS_0 + i*4), PCI_BASE_ADDRESS_IO_MASK);
++                      pci_write_long(d, PCI_BASE_ADDRESS_0 + i*4, x);
++                    }
++                }
++              else
+               {
+                 if ((x & PCI_BASE_ADDRESS_MEM_TYPE_MASK) != 
PCI_BASE_ADDRESS_MEM_TYPE_64)
+-                  d->base_addr[i] = x;
++                    {
++                      d->base_addr[i] = x & PCI_BASE_ADDRESS_MEM_MASK;
++                      if (flags & PCI_FILL_SIZES)
++                        {
++                          u32 size;
++                          pci_write_long(d, PCI_BASE_ADDRESS_0 + i*4, ~0);
++                          d->size[i] = pci_read_long(d, PCI_BASE_ADDRESS_0 + 
i*4);
++                          d->size[i] = pci_size(x, pci_read_long(d, 
PCI_BASE_ADDRESS_0 + i*4), PCI_BASE_ADDRESS_MEM_MASK);
++                          pci_write_long(d, PCI_BASE_ADDRESS_0 + i*4, x);
++                        }
++                    }
+                 else if (i >= cnt-1)
+                   a->warning("%04x:%02x:%02x.%d: Invalid 64-bit address seen 
for BAR %d.", d->domain, d->bus, d->dev, d->func, i);
+                 else
+                   {
+                     u32 y = pci_read_long(d, PCI_BASE_ADDRESS_0 + (++i)*4);
+ #ifdef PCI_HAVE_64BIT_ADDRESS
+-                    d->base_addr[i-1] = x | (((pciaddr_t) y) << 32);
++                    d->base_addr[i-1] = (x | (((pciaddr_t) y) << 32)) & 
PCI_BASE_ADDRESS_MEM_MASK;
++                      if (flags & PCI_FILL_SIZES)
++                        {
++                          u32 size;
++                          pci_write_long(d, PCI_BASE_ADDRESS_0 + (i-1)*4, ~0);
++                          pci_write_long(d, PCI_BASE_ADDRESS_0 + i*4, ~0);
++                          d->size[i-1] = pci_size(y, pci_read_long(d, 
PCI_BASE_ADDRESS_0 + (i-1)*4) | 
++                                         pci_read_long(d, PCI_BASE_ADDRESS_0 
+ i*4), 0xffffffff );
++                          pci_write_long(d, PCI_BASE_ADDRESS_0 + (i-1)*4, x);
++                          pci_write_long(d, PCI_BASE_ADDRESS_0 + i*4, y);
++                        }
+ #else
+                     if (y)
+                       a->warning("%04x:%02x:%02x.%d 64-bit device address 
ignored.", d->domain, d->bus, d->dev, d->func);
+                     else
+-                      d->base_addr[i-1] = x;
++                        {
++                          d->base_addr[i-1] = x & PCI_BASE_ADDRESS_MEM_MASK;
++                          if (flags & PCI_FILL_SIZES)
++                            {
++                              u32 size;
++                              pci_write_long(d, PCI_BASE_ADDRESS_0 + (i-1)*4, 
~0);
++                              d->size[i-1] = pci_size(x, pci_read_long(d, 
PCI_BASE_ADDRESS_0 + (i-1)*4), PCI_BASE_ADDRESS_MEM_MASK);
++                              pci_write_long(d, PCI_BASE_ADDRESS_0 + (i-1)*4, 
x);
++                            }
++                        }
+ #endif
+                   }
+               }
+@@ -154,10 +205,19 @@
+       {
+         u32 u = pci_read_long(d, reg);
+         if (u != 0xffffffff)
+-          d->rom_base_addr = u;
++            {
++              d->rom_base_addr = u;
++              if (flags & PCI_FILL_SIZES)
++                {
++                  u32 size;
++                  pci_write_long(d, reg, ~0);
++                  d->rom_size = pci_read_long(d, reg);
++                  pci_write_long(d, reg, u);
++                }
++            }
+       }
+     }
+-  return flags & ~PCI_FILL_SIZES;
++  return flags;
+ }
+ 
+ static int
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/Makefile
--- a/tools/Makefile    Tue Jul 08 11:41:43 2008 +0900
+++ b/tools/Makefile    Fri Jul 18 12:12:41 2008 +0900
@@ -22,7 +22,12 @@ SUBDIRS-y += blktap
 SUBDIRS-y += blktap
 SUBDIRS-y += libfsimage
 SUBDIRS-$(LIBXENAPI_BINDINGS) += libxen
+
+ifeq (ioemu,$(CONFIG_QEMU))
 SUBDIRS-$(CONFIG_IOEMU) += ioemu
+else
+SUBDIRS-$(CONFIG_IOEMU) += ioemu-dir
+endif
 
 # These don't cross-compile
 ifeq ($(XEN_COMPILE_ARCH),$(XEN_TARGET_ARCH))
@@ -62,3 +67,33 @@ subdir-clean-ioemu:
 subdir-clean-ioemu:
        $(MAKE) -C ioemu distclean
 
+ioemu-dir-find:
+       set -ex; \
+       if test -d $(CONFIG_QEMU); then \
+               rm -f ioemu-dir; \
+               ln -sf $(CONFIG_QEMU) ioemu-dir; \
+       else \
+               if [ ! -d ioemu-remote ]; then \
+                       rm -rf ioemu-remote ioemu-remote.tmp; \
+                       mkdir ioemu-remote.tmp; rmdir ioemu-remote.tmp; \
+                       $(GIT) clone $(CONFIG_QEMU) ioemu-remote.tmp; \
+                       mv ioemu-remote.tmp ioemu-remote; \
+               fi; \
+               rm -f ioemu-dir; \
+               ln -sf ioemu-remote ioemu-dir; \
+       fi
+       set -e; \
+               case "$(XEN_ROOT)" in \
+               /*)     XEN_ROOT=$(XEN_ROOT) ;; \
+               *)      XEN_ROOT=`pwd`/$(XEN_ROOT) ;; \
+               esac; \
+               export XEN_ROOT; \
+               cd ioemu-dir; \
+               ./xen-setup
+
+subdir-all-ioemu-dir subdir-install-ioemu-dir: ioemu-dir-find
+
+subdir-clean-ioemu-dir:
+       if test -d ioemu-dir/.; then \
+               $(MAKE) -C ioemu-dir clean; \
+       fi
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/blktap/drivers/Makefile
--- a/tools/blktap/drivers/Makefile     Tue Jul 08 11:41:43 2008 +0900
+++ b/tools/blktap/drivers/Makefile     Fri Jul 18 12:12:41 2008 +0900
@@ -36,11 +36,14 @@ BLK-OBJS-y  += block-qcow2.o
 BLK-OBJS-y  += block-qcow2.o
 BLK-OBJS-y  += aes.o
 BLK-OBJS-y  += tapaio.o
-BLK-OBJS-$(CONFIG_Linux) += blk_linux.c
+BLK-OBJS-$(CONFIG_Linux) += blk_linux.o
+
+BLKTAB-OBJS-y := blktapctrl.o
+BLKTAB-OBJS-$(CONFIG_Linux) += blktapctrl_linux.o
 
 all: $(IBIN) qcow-util
 
-blktapctrl: blktapctrl.o
+blktapctrl: $(BLKTAB-OBJS-y)
        $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LDFLAGS_blktapctrl)
 
 tapdisk: tapdisk.o $(BLK-OBJS-y)
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/blktap/drivers/blktapctrl.c
--- a/tools/blktap/drivers/blktapctrl.c Tue Jul 08 11:41:43 2008 +0900
+++ b/tools/blktap/drivers/blktapctrl.c Fri Jul 18 12:12:41 2008 +0900
@@ -37,7 +37,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/mman.h>
-#include <sys/stat.h>
 #include <err.h>
 #include <errno.h>
 #include <sys/types.h>
@@ -55,6 +54,8 @@
 #include "blktaplib.h"
 #include "blktapctrl.h"
 #include "tapdisk.h"
+#include "list.h"
+#include "xs_api.h" /* for xs_fire_next_watch() */
 
 #define PIDFILE "/var/run/blktapctrl.pid"
 
@@ -75,6 +76,32 @@ static int read_msg(int fd, int msgtype,
 static int read_msg(int fd, int msgtype, void *ptr);
 static driver_list_entry_t *active_disks[MAX_DISK_TYPES];
 
+
+static unsigned long long tapdisk_get_size(blkif_t *blkif)
+{
+       image_t *img = (image_t *)blkif->prv;
+       return img->size;
+}
+
+static unsigned long tapdisk_get_secsize(blkif_t *blkif)
+{
+       image_t *img = (image_t *)blkif->prv;
+       return img->secsize;
+}
+
+static unsigned int tapdisk_get_info(blkif_t *blkif)
+{
+       image_t *img = (image_t *)blkif->prv;
+       return img->info;
+}
+
+struct blkif_ops tapdisk_ops = {
+       .get_size = tapdisk_get_size,
+       .get_secsize = tapdisk_get_secsize,
+       .get_info = tapdisk_get_info,
+};
+
+
 static void init_driver_list(void)
 {
        int i;
@@ -93,62 +120,6 @@ static void init_rng(void)
        seed = tv.tv_usec;
        srand48(seed);
        return;
-}
-
-static void make_blktap_dev(char *devname, int major, int minor)
-{
-       struct stat st;
-       
-       if (lstat(devname, &st) != 0) {
-               /*Need to create device*/
-               if (mkdir(BLKTAP_DEV_DIR, 0755) == 0)
-                       DPRINTF("Created %s directory\n",BLKTAP_DEV_DIR);
-               if (mknod(devname, S_IFCHR|0600,
-                       makedev(major, minor)) == 0)
-                       DPRINTF("Created %s device\n",devname);
-       } else {
-               DPRINTF("%s device already exists\n",devname);
-               /* it already exists, but is it the same major number */
-               if (((st.st_rdev>>8) & 0xff) != major) {
-                       DPRINTF("%s has old major %d\n",
-                               devname,
-                               (unsigned int)((st.st_rdev >> 8) & 0xff));
-                       /* only try again if we succed in deleting it */
-                       if (!unlink(devname))
-                               make_blktap_dev(devname, major, minor);
-               }
-       }
-}
-
-static int get_new_dev(int *major, int *minor, blkif_t *blkif)
-{
-       domid_translate_t tr;
-       int ret;
-       char *devname;
-       
-       tr.domid = blkif->domid;
-        tr.busid = blkif->be_id;
-       ret = ioctl(ctlfd, BLKTAP_IOCTL_NEWINTF, tr );
-       
-       if ( (ret <= 0)||(ret > MAX_TAP_DEV) ) {
-               DPRINTF("Incorrect Dev ID [%d]\n",ret);
-               return -1;
-       }
-       
-       *minor = ret;
-       *major = ioctl(ctlfd, BLKTAP_IOCTL_MAJOR, ret );
-       if (*major < 0) {
-               DPRINTF("Incorrect Major ID [%d]\n",*major);
-               return -1;
-       }
-
-       if (asprintf(&devname,"%s/%s%d",BLKTAP_DEV_DIR, BLKTAP_DEV_NAME, 
*minor) == -1)
-               return -1;
-       make_blktap_dev(devname,*major,*minor); 
-       DPRINTF("Received device id %d and major %d, "
-               "sent domid %d and be_id %d\n",
-               *minor, *major, tr.domid, tr.busid);
-       return 0;
 }
 
 static int get_tapdisk_pid(blkif_t *blkif)
@@ -626,7 +597,7 @@ fail:
        return ret;
 }
 
-int blktapctrl_new_blkif(blkif_t *blkif)
+static int blktapctrl_new_blkif(blkif_t *blkif)
 {
        blkif_info_t *blk;
        int major, minor, fd_read, fd_write, type, new;
@@ -637,7 +608,7 @@ int blktapctrl_new_blkif(blkif_t *blkif)
 
        DPRINTF("Received a poll for a new vbd\n");
        if ( ((blk=blkif->info) != NULL) && (blk->params != NULL) ) {
-               if (get_new_dev(&major, &minor, blkif)<0)
+               if (blktap_interface_create(ctlfd, &major, &minor, blkif) < 0)
                        return -1;
 
                if (test_path(blk->params, &ptr, &type, &exist) != 0) {
@@ -698,7 +669,7 @@ fail:
        return -EINVAL;
 }
 
-int map_new_blktapctrl(blkif_t *blkif)
+static int map_new_blktapctrl(blkif_t *blkif)
 {
        DPRINTF("Received a poll for a new devmap\n");
        if (write_msg(blkif->fds[WRITE], CTLMSG_NEWDEV, blkif, NULL) <= 0) {
@@ -715,7 +686,7 @@ int map_new_blktapctrl(blkif_t *blkif)
        return blkif->minor - 1;
 }
 
-int unmap_blktapctrl(blkif_t *blkif)
+static int unmap_blktapctrl(blkif_t *blkif)
 {
        DPRINTF("Unmapping vbd\n");
 
@@ -829,21 +800,11 @@ int main(int argc, char *argv[])
        register_new_devmap_hook(map_new_blktapctrl);
        register_new_unmap_hook(unmap_blktapctrl);
 
-       /* Attach to blktap0 */
-       if (asprintf(&devname,"%s/%s0", BLKTAP_DEV_DIR, BLKTAP_DEV_NAME) == -1)
-                goto open_failed;
-       if ((ret = xc_find_device_number("blktap0")) < 0) {
-               DPRINTF("couldn't find device number for 'blktap0'\n");
+       ctlfd = blktap_interface_open();
+       if (ctlfd < 0) {
+               DPRINTF("couldn't open blktap interface\n");
                goto open_failed;
        }
-       blktap_major = major(ret);
-       make_blktap_dev(devname,blktap_major,0);
-       ctlfd = open(devname, O_RDWR);
-       if (ctlfd == -1) {
-               DPRINTF("blktap0 open failed\n");
-               goto open_failed;
-       }
-
 
  retry:
        /* Set up store connection and watch. */
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/blktap/drivers/blktapctrl.h
--- a/tools/blktap/drivers/blktapctrl.h Tue Jul 08 11:41:43 2008 +0900
+++ b/tools/blktap/drivers/blktapctrl.h Fri Jul 18 12:12:41 2008 +0900
@@ -30,26 +30,7 @@
  */
 
 
-static inline unsigned long long tapdisk_get_size(blkif_t *blkif)
-{
-       image_t *img = (image_t *)blkif->prv;
-       return img->size;
-}
+int blktap_interface_open(void);
 
-static inline unsigned long tapdisk_get_secsize(blkif_t *blkif)
-{
-       image_t *img = (image_t *)blkif->prv;
-       return img->secsize;
-}
+int blktap_interface_create(int ctlfd, int *major, int *minor, blkif_t *blkif);
 
-static inline unsigned int tapdisk_get_info(blkif_t *blkif)
-{
-       image_t *img = (image_t *)blkif->prv;
-       return img->info;
-}
-
-struct blkif_ops tapdisk_ops = {
-       .get_size = tapdisk_get_size,
-       .get_secsize = tapdisk_get_secsize,
-       .get_info = tapdisk_get_info,
-};
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/blktap/drivers/blktapctrl_linux.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/blktap/drivers/blktapctrl_linux.c   Fri Jul 18 12:12:41 2008 +0900
@@ -0,0 +1,109 @@
+
+#include <stdio.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+
+#include "tapdisk.h"
+#include "blktaplib.h"
+#include "blktapctrl.h"
+
+static void make_blktap_dev(char *devname, int major, int minor)
+{
+       struct stat st;
+ 
+       if (lstat(devname, &st) != 0) {
+               /*Need to create device*/
+               if (mkdir(BLKTAP_DEV_DIR, 0755) == 0)
+                       DPRINTF("Created %s directory\n",BLKTAP_DEV_DIR);
+               if (mknod(devname, S_IFCHR|0600,
+                       makedev(major, minor)) == 0)
+                       DPRINTF("Created %s device\n",devname);
+       } else {
+               DPRINTF("%s device already exists\n",devname); 
+               /* it already exists, but is it the same major number */
+               if (((st.st_rdev>>8) & 0xff) != major) {
+                       DPRINTF("%s has old major %d\n",
+                               devname,
+                               (unsigned int)((st.st_rdev >> 8) & 0xff));
+                       /* only try again if we succed in deleting it */
+                       if (!unlink(devname))
+                               make_blktap_dev(devname, major, minor);
+               }
+       }
+}
+
+int blktap_interface_create(int ctlfd, int *major, int *minor, blkif_t *blkif)
+{       
+        domid_translate_t tr;
+        domid_translate_ext_t tr_ext;
+        int ret; 
+        char *devname;
+
+        if (blkif->be_id >= (1<<28)) {
+                /* new-style backend-id, so use the extended structure */
+                tr_ext.domid = blkif->domid;
+                tr_ext.busid = blkif->be_id;
+                ret = ioctl(ctlfd, BLKTAP_IOCTL_NEWINTF_EXT, &tr_ext);
+                DPRINTF("Sent domid %d and be_id %d\n", tr_ext.domid,
+                        tr_ext.busid);
+        }
+        else {
+                /* old-style backend-id; use the old structure */
+                tr.domid = blkif->domid;
+                tr.busid = (unsigned short)blkif->be_id;
+                ret = ioctl(ctlfd, BLKTAP_IOCTL_NEWINTF, tr);
+                DPRINTF("Sent domid %d and be_id %d\n", tr.domid, tr.busid);
+        }
+
+        if ( (ret <= 0)||(ret > MAX_TAP_DEV) ) {
+                DPRINTF("Incorrect Dev ID [%d]\n",ret);
+                return -1;
+        }
+
+        *minor = ret;
+        *major = ioctl(ctlfd, BLKTAP_IOCTL_MAJOR, ret );
+        if (*major < 0) {
+                DPRINTF("Incorrect Major ID [%d]\n",*major);
+                return -1;
+        }
+
+        if (asprintf(&devname,"%s/%s%d",BLKTAP_DEV_DIR, BLKTAP_DEV_NAME, 
*minor) == -1)
+                return -1;
+        make_blktap_dev(devname,*major,*minor);
+        DPRINTF("Received device id %d and major %d\n",
+                *minor, *major);
+        return 0;
+}
+
+
+int blktap_interface_open(void)
+{
+       char *devname;
+       int ret;
+       int ctlfd;
+
+       /* Attach to blktap0 */
+       if (asprintf(&devname,"%s/%s0", BLKTAP_DEV_DIR, BLKTAP_DEV_NAME) == -1)
+               goto open_failed;
+
+       ret = xc_find_device_number("blktap0");
+       if (ret < 0) {
+               DPRINTF("couldn't find device number for 'blktap0'\n");
+               goto open_failed;
+       }
+
+       blktap_major = major(ret);
+       make_blktap_dev(devname,blktap_major, 0);
+
+       ctlfd = open(devname, O_RDWR);
+       if (ctlfd == -1) {
+               DPRINTF("blktap0 open failed\n");
+               goto open_failed;
+       }
+
+       return ctlfd;
+
+open_failed:
+       return -1;
+}
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/blktap/drivers/block-aio.c
--- a/tools/blktap/drivers/block-aio.c  Tue Jul 08 11:41:43 2008 +0900
+++ b/tools/blktap/drivers/block-aio.c  Fri Jul 18 12:12:41 2008 +0900
@@ -118,7 +118,7 @@ static inline void init_fds(struct disk_
 }
 
 /* Open the disk file and initialize aio state. */
-int tdaio_open (struct disk_driver *dd, const char *name, td_flag_t flags)
+static int tdaio_open (struct disk_driver *dd, const char *name, td_flag_t 
flags)
 {
        int i, fd, ret = 0, o_flags;
        struct td_state    *s   = dd->td_state;
@@ -161,7 +161,7 @@ done:
        return ret;     
 }
 
-int tdaio_queue_read(struct disk_driver *dd, uint64_t sector,
+static int tdaio_queue_read(struct disk_driver *dd, uint64_t sector,
                     int nb_sectors, char *buf, td_callback_t cb,
                     int id, void *private)
 {
@@ -174,7 +174,7 @@ int tdaio_queue_read(struct disk_driver 
                cb, id, sector, private);
 }
                        
-int tdaio_queue_write(struct disk_driver *dd, uint64_t sector,
+static int tdaio_queue_write(struct disk_driver *dd, uint64_t sector,
                      int nb_sectors, char *buf, td_callback_t cb,
                      int id, void *private)
 {
@@ -187,14 +187,14 @@ int tdaio_queue_write(struct disk_driver
                cb, id, sector, private);
 }
 
-int tdaio_submit(struct disk_driver *dd)
+static int tdaio_submit(struct disk_driver *dd)
 {
        struct tdaio_state *prv = (struct tdaio_state *)dd->private;
 
        return tap_aio_submit(&prv->aio);
 }
                        
-int tdaio_close(struct disk_driver *dd)
+static int tdaio_close(struct disk_driver *dd)
 {
        struct tdaio_state *prv = (struct tdaio_state *)dd->private;
        
@@ -204,7 +204,7 @@ int tdaio_close(struct disk_driver *dd)
        return 0;
 }
 
-int tdaio_do_callbacks(struct disk_driver *dd, int sid)
+static int tdaio_do_callbacks(struct disk_driver *dd, int sid)
 {
        int i, nr_events, rsp = 0;
        struct io_event *ep;
@@ -234,12 +234,12 @@ repeat:
        return rsp;
 }
 
-int tdaio_get_parent_id(struct disk_driver *dd, struct disk_id *id)
+static int tdaio_get_parent_id(struct disk_driver *dd, struct disk_id *id)
 {
        return TD_NO_PARENT;
 }
 
-int tdaio_validate_parent(struct disk_driver *dd, 
+static int tdaio_validate_parent(struct disk_driver *dd, 
                          struct disk_driver *parent, td_flag_t flags)
 {
        return -EINVAL;
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/blktap/drivers/block-qcow.c
--- a/tools/blktap/drivers/block-qcow.c Tue Jul 08 11:41:43 2008 +0900
+++ b/tools/blktap/drivers/block-qcow.c Fri Jul 18 12:12:41 2008 +0900
@@ -720,7 +720,7 @@ static inline void init_fds(struct disk_
 }
 
 /* Open the disk file and initialize qcow state. */
-int tdqcow_open (struct disk_driver *dd, const char *name, td_flag_t flags)
+static int tdqcow_open (struct disk_driver *dd, const char *name, td_flag_t 
flags)
 {
        int fd, len, i, shift, ret, size, l1_table_size, o_flags;
        int max_aio_reqs;
@@ -937,7 +937,7 @@ fail:
        return -1;
 }
 
-int tdqcow_queue_read(struct disk_driver *dd, uint64_t sector,
+static int tdqcow_queue_read(struct disk_driver *dd, uint64_t sector,
                      int nb_sectors, char *buf, td_callback_t cb,
                      int id, void *private)
 {
@@ -999,7 +999,7 @@ done:
        return rsp;
 }
 
-int tdqcow_queue_write(struct disk_driver *dd, uint64_t sector,
+static int tdqcow_queue_write(struct disk_driver *dd, uint64_t sector,
                       int nb_sectors, char *buf, td_callback_t cb,
                       int id, void *private)
 {
@@ -1057,14 +1057,14 @@ int tdqcow_queue_write(struct disk_drive
        return 0;
 }
                
-int tdqcow_submit(struct disk_driver *dd)
+static int tdqcow_submit(struct disk_driver *dd)
 {
         struct tdqcow_state *prv = (struct tdqcow_state *)dd->private;
 
        return tap_aio_submit(&prv->aio);
 }
 
-int tdqcow_close(struct disk_driver *dd)
+static int tdqcow_close(struct disk_driver *dd)
 {
        struct tdqcow_state *s = (struct tdqcow_state *)dd->private;
        uint32_t cksum, out;
@@ -1092,7 +1092,7 @@ int tdqcow_close(struct disk_driver *dd)
        return 0;
 }
 
-int tdqcow_do_callbacks(struct disk_driver *dd, int sid)
+static int tdqcow_do_callbacks(struct disk_driver *dd, int sid)
 {
         int ret, i, nr_events, rsp = 0,*ptr;
         struct io_event *ep;
@@ -1276,7 +1276,7 @@ int qcow_create(const char *filename, ui
        return 0;
 }
 
-int qcow_make_empty(struct tdqcow_state *s)
+static int qcow_make_empty(struct tdqcow_state *s)
 {
        uint32_t l1_length = s->l1_size * sizeof(uint64_t);
 
@@ -1296,14 +1296,14 @@ int qcow_make_empty(struct tdqcow_state 
        return 0;
 }
 
-int qcow_get_cluster_size(struct tdqcow_state *s)
+static int qcow_get_cluster_size(struct tdqcow_state *s)
 {
        return s->cluster_size;
 }
 
 /* XXX: put compressed sectors first, then all the cluster aligned
    tables to avoid losing bytes in alignment */
-int qcow_compress_cluster(struct tdqcow_state *s, int64_t sector_num, 
+static int qcow_compress_cluster(struct tdqcow_state *s, int64_t sector_num, 
                           const uint8_t *buf)
 {
        z_stream strm;
@@ -1358,7 +1358,7 @@ int qcow_compress_cluster(struct tdqcow_
        return 0;
 }
 
-int tdqcow_get_parent_id(struct disk_driver *dd, struct disk_id *id)
+static int tdqcow_get_parent_id(struct disk_driver *dd, struct disk_id *id)
 {
        off_t off;
        char *buf, *filename;
@@ -1392,7 +1392,7 @@ int tdqcow_get_parent_id(struct disk_dri
        return err;
 }
 
-int tdqcow_validate_parent(struct disk_driver *child,
+static int tdqcow_validate_parent(struct disk_driver *child,
                           struct disk_driver *parent, td_flag_t flags)
 {
        struct stat stats;
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/blktap/drivers/block-ram.c
--- a/tools/blktap/drivers/block-ram.c  Tue Jul 08 11:41:43 2008 +0900
+++ b/tools/blktap/drivers/block-ram.c  Fri Jul 18 12:12:41 2008 +0900
@@ -127,7 +127,7 @@ static inline void init_fds(struct disk_
 }
 
 /* Open the disk file and initialize ram state. */
-int tdram_open (struct disk_driver *dd, const char *name, td_flag_t flags)
+static int tdram_open (struct disk_driver *dd, const char *name, td_flag_t 
flags)
 {
        char *p;
        uint64_t size;
@@ -220,7 +220,7 @@ done:
        return ret;
 }
 
- int tdram_queue_read(struct disk_driver *dd, uint64_t sector,
+static int tdram_queue_read(struct disk_driver *dd, uint64_t sector,
                      int nb_sectors, char *buf, td_callback_t cb,
                      int id, void *private)
 {
@@ -234,7 +234,7 @@ done:
        return cb(dd, 0, sector, nb_sectors, id, private);
 }
 
-int tdram_queue_write(struct disk_driver *dd, uint64_t sector,
+static int tdram_queue_write(struct disk_driver *dd, uint64_t sector,
                      int nb_sectors, char *buf, td_callback_t cb,
                      int id, void *private)
 {
@@ -250,12 +250,12 @@ int tdram_queue_write(struct disk_driver
        return cb(dd, 0, sector, nb_sectors, id, private);
 }
                
-int tdram_submit(struct disk_driver *dd)
+static int tdram_submit(struct disk_driver *dd)
 {
        return 0;       
 }
 
-int tdram_close(struct disk_driver *dd)
+static int tdram_close(struct disk_driver *dd)
 {
        struct tdram_state *prv = (struct tdram_state *)dd->private;
        
@@ -264,18 +264,18 @@ int tdram_close(struct disk_driver *dd)
        return 0;
 }
 
-int tdram_do_callbacks(struct disk_driver *dd, int sid)
+static int tdram_do_callbacks(struct disk_driver *dd, int sid)
 {
        /* always ask for a kick */
        return 1;
 }
 
-int tdram_get_parent_id(struct disk_driver *dd, struct disk_id *id)
+static int tdram_get_parent_id(struct disk_driver *dd, struct disk_id *id)
 {
        return TD_NO_PARENT;
 }
 
-int tdram_validate_parent(struct disk_driver *dd, 
+static int tdram_validate_parent(struct disk_driver *dd, 
                          struct disk_driver *parent, td_flag_t flags)
 {
        return -EINVAL;
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/blktap/drivers/block-sync.c
--- a/tools/blktap/drivers/block-sync.c Tue Jul 08 11:41:43 2008 +0900
+++ b/tools/blktap/drivers/block-sync.c Fri Jul 18 12:12:41 2008 +0900
@@ -109,7 +109,7 @@ static inline void init_fds(struct disk_
 }
 
 /* Open the disk file and initialize aio state. */
-int tdsync_open (struct disk_driver *dd, const char *name, td_flag_t flags)
+static int tdsync_open (struct disk_driver *dd, const char *name, td_flag_t 
flags)
 {
        int i, fd, ret = 0, o_flags;
        struct td_state     *s   = dd->td_state;
@@ -129,7 +129,7 @@ int tdsync_open (struct disk_driver *dd,
 
                 /* Maybe O_DIRECT isn't supported. */
                o_flags &= ~O_DIRECT;
-                fd = open(name, O_RDWR | O_LARGEFILE);
+                fd = open(name, o_flags);
                 if (fd != -1) DPRINTF("WARNING: Accessing image without"
                                      "O_DIRECT! (%s)\n", name);
 
@@ -149,7 +149,7 @@ done:
        return ret;     
 }
 
- int tdsync_queue_read(struct disk_driver *dd, uint64_t sector,
+static int tdsync_queue_read(struct disk_driver *dd, uint64_t sector,
                               int nb_sectors, char *buf, td_callback_t cb,
                               int id, void *private)
 {
@@ -172,7 +172,7 @@ done:
        return cb(dd, (ret < 0) ? ret: 0, sector, nb_sectors, id, private);
 }
 
- int tdsync_queue_write(struct disk_driver *dd, uint64_t sector,
+static int tdsync_queue_write(struct disk_driver *dd, uint64_t sector,
                               int nb_sectors, char *buf, td_callback_t cb,
                               int id, void *private)
 {
@@ -195,12 +195,12 @@ done:
        return cb(dd, (ret < 0) ? ret : 0, sector, nb_sectors, id, private);
 }
                
-int tdsync_submit(struct disk_driver *dd)
+static int tdsync_submit(struct disk_driver *dd)
 {
        return 0;       
 }
 
-int tdsync_close(struct disk_driver *dd)
+static int tdsync_close(struct disk_driver *dd)
 {
        struct tdsync_state *prv = (struct tdsync_state *)dd->private;
        
@@ -211,18 +211,18 @@ int tdsync_close(struct disk_driver *dd)
        return 0;
 }
 
-int tdsync_do_callbacks(struct disk_driver *dd, int sid)
+static int tdsync_do_callbacks(struct disk_driver *dd, int sid)
 {
        /* always ask for a kick */
        return 1;
 }
 
-int tdsync_get_parent_id(struct disk_driver *dd, struct disk_id *id)
+static int tdsync_get_parent_id(struct disk_driver *dd, struct disk_id *id)
 {
        return TD_NO_PARENT;
 }
 
-int tdsync_validate_parent(struct disk_driver *dd, 
+static int tdsync_validate_parent(struct disk_driver *dd, 
                           struct disk_driver *parent, td_flag_t flags)
 {
        return -EINVAL;
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/blktap/drivers/img2qcow.c
--- a/tools/blktap/drivers/img2qcow.c   Tue Jul 08 11:41:43 2008 +0900
+++ b/tools/blktap/drivers/img2qcow.c   Fri Jul 18 12:12:41 2008 +0900
@@ -61,8 +61,8 @@ static uint64_t prev = 0;
 static uint64_t prev = 0;
 static char output[25];
 
-void print_bytes(void *ptr, int length) {
-
+static void print_bytes(void *ptr, int length)
+{
   int i,k;
   unsigned char *p = ptr;
 
@@ -77,7 +77,7 @@ void print_bytes(void *ptr, int length) 
     return;
 }
 
-void debug_output(uint64_t progress, uint64_t size)
+static void debug_output(uint64_t progress, uint64_t size)
 {
        uint64_t blocks = size/20;
 
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/blktap/drivers/qcow-create.c
--- a/tools/blktap/drivers/qcow-create.c        Tue Jul 08 11:41:43 2008 +0900
+++ b/tools/blktap/drivers/qcow-create.c        Fri Jul 18 12:12:41 2008 +0900
@@ -48,7 +48,7 @@
 
 #define MAX_NAME_LEN 1000
 
-void help(void)
+static void help(void)
 {
        fprintf(stderr, "Qcow-utils: v1.0.0\n");
        fprintf(stderr, 
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/blktap/drivers/qcow2raw.c
--- a/tools/blktap/drivers/qcow2raw.c   Tue Jul 08 11:41:43 2008 +0900
+++ b/tools/blktap/drivers/qcow2raw.c   Fri Jul 18 12:12:41 2008 +0900
@@ -65,8 +65,8 @@ static uint64_t prev = 0, written = 0;
 static uint64_t prev = 0, written = 0;
 static char output[25];
 
-void print_bytes(void *ptr, int length) {
-
+static void print_bytes(void *ptr, int length)
+{
   int i,k;
   unsigned char *p = ptr;
 
@@ -81,7 +81,7 @@ void print_bytes(void *ptr, int length) 
     return;
 }
 
-void debug_output(uint64_t progress, uint64_t size)
+static void debug_output(uint64_t progress, uint64_t size)
 {
        /*Output progress every 5% */   
        uint64_t blocks = size/20;
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/blktap/drivers/tapdisk.c
--- a/tools/blktap/drivers/tapdisk.c    Tue Jul 08 11:41:43 2008 +0900
+++ b/tools/blktap/drivers/tapdisk.c    Fri Jul 18 12:12:41 2008 +0900
@@ -53,14 +53,14 @@ int do_cow_read(struct disk_driver *dd, 
 #define td_for_each_disk(tds, drv) \
         for (drv = tds->disks; drv != NULL; drv = drv->next)
 
-void usage(void) 
+static void usage(void) 
 {
        fprintf(stderr, "blktap-utils: v1.0.0\n");
        fprintf(stderr, "usage: tapdisk <READ fifo> <WRITE fifo>\n");
         exit(-1);
 }
 
-void daemonize(void)
+static void daemonize(void)
 {
        int i;
 
@@ -121,7 +121,7 @@ static void unmap_disk(struct td_state *
        return;
 }
 
-void sig_handler(int sig)
+static void sig_handler(int sig)
 {
        /*Received signal to close. If no disks are active, we close app.*/
 
@@ -512,7 +512,7 @@ static inline void kick_responses(struct
        }
 }
 
-void io_done(struct disk_driver *dd, int sid)
+static void io_done(struct disk_driver *dd, int sid)
 {
        struct tap_disk *drv = dd->drv;
 
@@ -537,7 +537,7 @@ segment_start(blkif_request_t *req, int 
 }
 
 uint64_t sends, responds;
-int send_responses(struct disk_driver *dd, int res, 
+static int send_responses(struct disk_driver *dd, int res, 
                   uint64_t sector, int nr_secs, int idx, void *private)
 {
        pending_req_t   *preq;
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/blktap/lib/blktaplib.h
--- a/tools/blktap/lib/blktaplib.h      Tue Jul 08 11:41:43 2008 +0900
+++ b/tools/blktap/lib/blktaplib.h      Fri Jul 18 12:12:41 2008 +0900
@@ -57,6 +57,7 @@
 #define BLKTAP_IOCTL_MAJOR          7
 #define BLKTAP_QUERY_ALLOC_REQS      8
 #define BLKTAP_IOCTL_FREEINTF       9
+#define BLKTAP_IOCTL_NEWINTF_EXT     50
 #define BLKTAP_IOCTL_PRINT_IDXS      100   
 
 /* blktap switching modes: (Set with BLKTAP_IOCTL_SETMODE)             */
@@ -161,8 +162,13 @@ typedef struct tapdev_info {
 
 typedef struct domid_translate {
        unsigned short domid;
+       unsigned short busid;
+} domid_translate_t ;
+
+typedef struct domid_translate_ext {
+       unsigned short domid;
        uint32_t busid;
-} domid_translate_t ;
+} domid_translate_ext_t ;
 
 typedef struct image {
        unsigned long long size;
@@ -207,7 +213,6 @@ typedef struct msg_pid {
 /* xenstore/xenbus: */
 #define DOMNAME "Domain-0"
 int setup_probe_watch(struct xs_handle *h);
-int xs_fire_next_watch(struct xs_handle *h);
 
 
 /* Abitrary values, must match the underlying driver... */
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/blktap/lib/xenbus.c
--- a/tools/blktap/lib/xenbus.c Tue Jul 08 11:41:43 2008 +0900
+++ b/tools/blktap/lib/xenbus.c Fri Jul 18 12:12:41 2008 +0900
@@ -354,7 +354,7 @@ static void ueblktap_probe(struct xs_han
  *are created, we initalise the state and attach a disk.
  */
 
-int add_blockdevice_probe_watch(struct xs_handle *h, const char *domid)
+static int add_blockdevice_probe_watch(struct xs_handle *h, const char *domid)
 {
        char *path;
        struct xenbus_watch *vbd_watch;
@@ -377,7 +377,7 @@ int add_blockdevice_probe_watch(struct x
 }
 
 /* Asynch callback to check for /local/domain/<DOMID>/name */
-void check_dom(struct xs_handle *h, struct xenbus_watch *w, 
+static void check_dom(struct xs_handle *h, struct xenbus_watch *w, 
               const char *bepath_im)
 {
        char *domid;
@@ -392,7 +392,7 @@ void check_dom(struct xs_handle *h, stru
 }
 
 /* We must wait for xend to register /local/domain/<DOMID> */
-int watch_for_domid(struct xs_handle *h)
+static int watch_for_domid(struct xs_handle *h)
 {
        struct xenbus_watch *domid_watch;
        char *path = NULL;
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/console/daemon/io.c
--- a/tools/console/daemon/io.c Tue Jul 08 11:41:43 2008 +0900
+++ b/tools/console/daemon/io.c Fri Jul 18 12:12:41 2008 +0900
@@ -471,7 +471,7 @@ out:
 }
  
 /* Takes tuples of names, scanf-style args, and void **, NULL terminated. */
-int xs_gather(struct xs_handle *xs, const char *dir, ...)
+static int xs_gather(struct xs_handle *xs, const char *dir, ...)
 {
        va_list ap;
        const char *name;
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/examples/network-bridge
--- a/tools/examples/network-bridge     Tue Jul 08 11:41:43 2008 +0900
+++ b/tools/examples/network-bridge     Fri Jul 18 12:12:41 2008 +0900
@@ -60,7 +60,18 @@ is_network_root () {
     local rootfs=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $3; }}' 
/etc/mtab)
     local rootopts=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $4; }}' 
/etc/mtab)
 
-    [[ "$rootfs" =~ "^nfs" ]] || [[ "$rootopts" =~ "_netdev" ]] && return 0 || 
return 1
+    [[ "$rootfs" =~ "^nfs" ]] || [[ "$rootopts" =~ "_netdev" ]] && 
has_nfsroot=1 || has_nfsroot=0
+    if [ $has_nfsroot -eq 1 ]; then
+        local bparms=$(cat /proc/cmdline)
+        for p in $bparms; do
+            local ipaddr=$(echo $p | awk /nfsroot=/'{ print 
substr($1,9,index($1,":")-9) }')
+            if [ "$ipaddr" != "" ]; then
+                local nfsdev=$(ip route get $ipaddr | awk /$ipaddr/'{ print $3 
}')
+                [[ "$nfsdev" == "$netdev" ]] && return 0 || return 1
+            fi
+        done
+    fi
+    return 1
 }
 
 find_alt_device () {
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/examples/vscsi
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/examples/vscsi      Fri Jul 18 12:12:41 2008 +0900
@@ -0,0 +1,22 @@
+#!/bin/sh
+#
+# Copyright (c) 2007, FUJITSU Limited
+# Based on the block scripts code.
+#
+
+dir=$(dirname "$0")
+. "$dir/xen-hotplug-common.sh"
+
+findCommand "$@"
+
+case "$command" in
+       add)
+               success
+               ;;
+       remove)
+               # TODO
+               exit 0
+               ;;
+esac
+
+exit 0
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/examples/vtpm-common.sh
--- a/tools/examples/vtpm-common.sh     Tue Jul 08 11:41:43 2008 +0900
+++ b/tools/examples/vtpm-common.sh     Fri Jul 18 12:12:41 2008 +0900
@@ -310,11 +310,11 @@ function vtpm_remove_instance () {
 
        instance="0"
 
-       if [ "$uuid != "" ]; then
+       if [ "$uuid" != "" ]; then
                instance=$(vtpmdb_find_instance $uuid)
        fi
 
-       if [ "$instance == "0" ]; then
+       if [ "$instance" == "0" ]; then
                domname=$(xenstore_read "$XENBUS_PATH"/domain)
                instance=$(vtpmdb_find_instance $domname)
        fi
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/examples/xen-backend.agent
--- a/tools/examples/xen-backend.agent  Tue Jul 08 11:41:43 2008 +0900
+++ b/tools/examples/xen-backend.agent  Fri Jul 18 12:12:41 2008 +0900
@@ -19,6 +19,9 @@ case "$XENBUS_TYPE" in
   vif)
     [ -n "$script" ] && $script "$ACTION"
     ;;
+  vscsi)
+    /etc/xen/scripts/vscsi "$ACTION"
+    ;;
 esac
 
 case "$ACTION" in
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/examples/xen-backend.rules
--- a/tools/examples/xen-backend.rules  Tue Jul 08 11:41:43 2008 +0900
+++ b/tools/examples/xen-backend.rules  Fri Jul 18 12:12:41 2008 +0900
@@ -3,6 +3,7 @@ SUBSYSTEM=="xen-backend", KERNEL=="vtpm*
 SUBSYSTEM=="xen-backend", KERNEL=="vtpm*", RUN+="/etc/xen/scripts/vtpm 
$env{ACTION}"
 SUBSYSTEM=="xen-backend", KERNEL=="vif*", ACTION=="online", RUN+="$env{script} 
online"
 SUBSYSTEM=="xen-backend", KERNEL=="vif*", ACTION=="offline", 
RUN+="$env{script} offline"
+SUBSYSTEM=="xen-backend", KERNEL=="vscsi*", RUN+="/etc/xen/scripts/vscsi 
$env{ACTION}"
 SUBSYSTEM=="xen-backend", ACTION=="remove", 
RUN+="/etc/xen/scripts/xen-hotplug-cleanup"
 KERNEL=="evtchn", NAME="xen/%k"
 KERNEL=="blktap[0-9]*", NAME="xen/%k"
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/examples/xmexample.hvm
--- a/tools/examples/xmexample.hvm      Tue Jul 08 11:41:43 2008 +0900
+++ b/tools/examples/xmexample.hvm      Fri Jul 18 12:12:41 2008 +0900
@@ -282,3 +282,26 @@ serial='pty'
 #  '0' -> the bit must be '0'
 #  'x' -> we don't care (do not check)
 #  's' -> the bit must be the same as on the host that started this VM
+
+
+#-----------------------------------------------------------------------------
+#   Configure PVSCSI devices:
+#
+#vscsi=[ 'PDEV, VDEV' ]
+#
+#   PDEV   gives physical SCSI device to be attached to specified guest
+#          domain by one of the following identifier format.
+#          - XX:XX:XX:XX (4-tuples with decimal notation which shows
+#                          "host:channel:target:lun")
+#          - /dev/sdxx or sdx
+#          - /dev/stxx or stx
+#          - /dev/sgxx or sgx
+#          - result of 'scsi_id -gu -s'.
+#            ex. # scsi_id -gu -s /block/sdb
+#                  36000b5d0006a0000006a0257004c0000
+#
+#   VDEV   gives virtual SCSI device by 4-tuples (XX:XX:XX:XX) as 
+#          which the specified guest domain recognize.
+#
+
+#vscsi = [ '/dev/sdx, 0:0:0:0' ]
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/examples/xmexample.vti
--- a/tools/examples/xmexample.vti      Tue Jul 08 11:41:43 2008 +0900
+++ b/tools/examples/xmexample.vti      Fri Jul 18 12:12:41 2008 +0900
@@ -161,3 +161,25 @@ serial='pty'
 #    'windows' - All Windows variants (Windows Server 2003/2008)
 #
 #guest_os_type='default'
+
+#-----------------------------------------------------------------------------
+#   Configure PVSCSI devices:
+#
+#vscsi=[ 'PDEV, VDEV' ]
+#
+#   PDEV   gives physical SCSI device to be attached to specified guest
+#          domain by one of the following identifier format.
+#          - XX:XX:XX:XX (4-tuples with decimal notation which shows
+#                          "host:channel:target:lun")
+#          - /dev/sdxx or sdx
+#          - /dev/stxx or stx
+#          - /dev/sgxx or sgx
+#          - result of 'scsi_id -gu -s'.
+#            ex. # scsi_id -gu -s /block/sdb
+#                  36000b5d0006a0000006a0257004c0000
+#
+#   VDEV   gives virtual SCSI device by 4-tuples (XX:XX:XX:XX) as 
+#          which the specified guest domain recognize.
+#
+
+#vscsi = [ '/dev/sdx, 0:0:0:0' ]
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/examples/xmexample1
--- a/tools/examples/xmexample1 Tue Jul 08 11:41:43 2008 +0900
+++ b/tools/examples/xmexample1 Fri Jul 18 12:12:41 2008 +0900
@@ -185,4 +185,27 @@ extra = "4"
 #on_reboot   = 'restart'
 #on_crash    = 'restart'
 
-#============================================================================
+#-----------------------------------------------------------------------------
+#   Configure PVSCSI devices:
+#
+#vscsi=[ 'PDEV, VDEV' ]
+#
+#   PDEV   gives physical SCSI device to be attached to specified guest
+#          domain by one of the following identifier format.
+#          - XX:XX:XX:XX (4-tuples with decimal notation which shows
+#                          "host:channel:target:lun")
+#          - /dev/sdxx or sdx
+#          - /dev/stxx or stx
+#          - /dev/sgxx or sgx
+#          - result of 'scsi_id -gu -s'.
+#            ex. # scsi_id -gu -s /block/sdb
+#                  36000b5d0006a0000006a0257004c0000
+#
+#   VDEV   gives virtual SCSI device by 4-tuples (XX:XX:XX:XX) as 
+#          which the specified guest domain recognize.
+#
+
+#vscsi = [ '/dev/sdx, 0:0:0:0' ]
+
+#============================================================================
+
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/examples/xmexample2
--- a/tools/examples/xmexample2 Tue Jul 08 11:41:43 2008 +0900
+++ b/tools/examples/xmexample2 Fri Jul 18 12:12:41 2008 +0900
@@ -221,4 +221,26 @@ extra = "4 VMID=%d usr=/dev/sda6" % vmid
 #on_reboot   = 'restart'
 #on_crash    = 'restart'
 
-#============================================================================
+#-----------------------------------------------------------------------------
+#   Configure PVSCSI devices:
+#
+#vscsi=[ 'PDEV, VDEV' ]
+#
+#   PDEV   gives physical SCSI device to be attached to specified guest
+#          domain by one of the following identifier format.
+#          - XX:XX:XX:XX (4-tuples with decimal notation which shows
+#                          "host:channel:target:lun")
+#          - /dev/sdxx or sdx
+#          - /dev/stxx or stx
+#          - /dev/sgxx or sgx
+#          - result of 'scsi_id -gu -s'.
+#            ex. # scsi_id -gu -s /block/sdb
+#                  36000b5d0006a0000006a0257004c0000
+#
+#   VDEV   gives virtual SCSI device by 4-tuples (XX:XX:XX:XX) as 
+#          which the specified guest domain recognize.
+#
+
+#vscsi = [ '/dev/sdx, 0:0:0:0' ]
+
+#============================================================================
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/firmware/hvmloader/acpi/build.c
--- a/tools/firmware/hvmloader/acpi/build.c     Tue Jul 08 11:41:43 2008 +0900
+++ b/tools/firmware/hvmloader/acpi/build.c     Fri Jul 18 12:12:41 2008 +0900
@@ -70,12 +70,7 @@ static int hpet_exists(unsigned long hpe
 
 static int construct_bios_info_table(uint8_t *buf)
 {
-    struct bios_info {
-        uint8_t  com1_present:1;
-        uint8_t  com2_present:1;
-        uint8_t  hpet_present:1;
-        uint32_t pci_min, pci_len;
-    } *bios_info = (struct bios_info *)buf;
+    struct bios_info *bios_info = (struct bios_info *)buf;
 
     memset(bios_info, 0, sizeof(*bios_info));
 
@@ -86,6 +81,7 @@ static int construct_bios_info_table(uin
 
     bios_info->pci_min = PCI_MEMBASE;
     bios_info->pci_len = PCI_MEMSIZE;
+    bios_info->xen_pfiob = 0xdead;
 
     return align16(sizeof(*bios_info));
 }
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/firmware/hvmloader/config.h
--- a/tools/firmware/hvmloader/config.h Tue Jul 08 11:41:43 2008 +0900
+++ b/tools/firmware/hvmloader/config.h Fri Jul 18 12:12:41 2008 +0900
@@ -31,4 +31,15 @@
 #define ROMBIOS_PHYSICAL_ADDRESS      0x000F0000
 #define SCRATCH_PHYSICAL_ADDRESS      0x00010000
 
+/* Xen Platform Device */
+#define PFFLAG_ROM_LOCK 1 /* Sets whether ROM memory area is RW or RO */
+
+struct bios_info {
+    uint8_t  com1_present:1;
+    uint8_t  com2_present:1;
+    uint8_t  hpet_present:1;
+    uint32_t pci_min, pci_len;
+    uint16_t xen_pfiob;
+};
+
 #endif /* __HVMLOADER_CONFIG_H__ */
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/firmware/hvmloader/hvmloader.c
--- a/tools/firmware/hvmloader/hvmloader.c      Tue Jul 08 11:41:43 2008 +0900
+++ b/tools/firmware/hvmloader/hvmloader.c      Fri Jul 18 12:12:41 2008 +0900
@@ -99,10 +99,6 @@ asm (
     "    .text                       \n"
     );
 
-void smp_initialise(void);
-void create_mp_tables(void);
-int hvm_write_smbios_tables(void);
-
 static enum { VGA_none, VGA_std, VGA_cirrus } virtual_vga = VGA_none;
 
 static void
@@ -432,6 +428,23 @@ static void cmos_write_memory_size(void)
     /* Some BIOSes: alternative extended memory (64kB chunks above 16MB). */
     cmos_outb(0x34, (uint8_t)( alt_mem >> 0));
     cmos_outb(0x35, (uint8_t)( alt_mem >> 8));
+}
+
+static void init_xen_platform_io_base(void)
+{
+    struct bios_info *bios_info = (struct bios_info *)ACPI_PHYSICAL_ADDRESS;
+    uint32_t devfn, bar_data;
+    uint16_t vendor_id, device_id;
+
+    for ( devfn = 0; devfn < 128; devfn++ )
+    {
+        vendor_id = pci_readw(devfn, PCI_VENDOR_ID);
+        device_id = pci_readw(devfn, PCI_DEVICE_ID);
+        if ( (vendor_id != 0x5853) || (device_id != 0x0001) )
+            continue;
+        bar_data = pci_readl(devfn, PCI_BASE_ADDRESS_0);
+        bios_info->xen_pfiob = bar_data & PCI_BASE_ADDRESS_IO_MASK;
+    }
 }
 
 int main(void)
@@ -527,6 +540,8 @@ int main(void)
                ROMBIOS_PHYSICAL_ADDRESS,
                ROMBIOS_PHYSICAL_ADDRESS + rombios_sz - 1);
 
+    init_xen_platform_io_base();
+
     printf("Invoking ROMBIOS ...\n");
     return 0;
 }
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/firmware/hvmloader/mp_tables.c
--- a/tools/firmware/hvmloader/mp_tables.c      Tue Jul 08 11:41:43 2008 +0900
+++ b/tools/firmware/hvmloader/mp_tables.c      Fri Jul 18 12:12:41 2008 +0900
@@ -69,8 +69,6 @@
 
 #include "util.h"
 
-extern int get_vcpu_nr(void);  /* for the guest's VCPU count */
-
 /*
  * The following structures are defined in the MuliProcessor Specifiation v1.4
  */
@@ -152,7 +150,7 @@ struct mp_local_intr_entry {
 };
 
 
-void fill_mp_config_table(struct mp_config_table *mpct, int length)
+static void fill_mp_config_table(struct mp_config_table *mpct, int length)
 {
     int vcpu_nr, i;
     uint8_t checksum;
@@ -199,7 +197,7 @@ void fill_mp_config_table(struct mp_conf
 }
 
 /* fills in an MP processor entry for VCPU 'vcpu_id' */
-void fill_mp_proc_entry(struct mp_proc_entry *mppe, int vcpu_id)
+static void fill_mp_proc_entry(struct mp_proc_entry *mppe, int vcpu_id)
 {
     mppe->type = ENTRY_TYPE_PROCESSOR;
     mppe->lapic_id = LAPIC_ID(vcpu_id);
@@ -213,7 +211,7 @@ void fill_mp_proc_entry(struct mp_proc_e
 
 
 /* fills in an MP bus entry of type 'type' and bus ID 'bus_id' */
-void fill_mp_bus_entry(struct mp_bus_entry *mpbe, int bus_id, const char *type)
+static void fill_mp_bus_entry(struct mp_bus_entry *mpbe, int bus_id, const 
char *type)
 {
     int i;
 
@@ -225,7 +223,7 @@ void fill_mp_bus_entry(struct mp_bus_ent
 
 
 /* fills in an MP IOAPIC entry for IOAPIC 'ioapic_id' */
-void fill_mp_ioapic_entry(struct mp_ioapic_entry *mpie)
+static void fill_mp_ioapic_entry(struct mp_ioapic_entry *mpie)
 {
     mpie->type = ENTRY_TYPE_IOAPIC;
     mpie->ioapic_id = IOAPIC_ID;
@@ -236,7 +234,7 @@ void fill_mp_ioapic_entry(struct mp_ioap
 
 
 /* fills in an IO interrupt entry for IOAPIC 'ioapic_id' */
-void fill_mp_io_intr_entry(
+static void fill_mp_io_intr_entry(
     struct mp_io_intr_entry *mpiie,
     int src_bus_id, int src_bus_irq, int ioapic_id, int dst_ioapic_intin)
 {
@@ -251,7 +249,7 @@ void fill_mp_io_intr_entry(
 
 
 /* fill in the mp floating processor structure */
-void fill_mpfps(struct mp_floating_pointer_struct *mpfps, uint32_t mpct)
+static void fill_mpfps(struct mp_floating_pointer_struct *mpfps, uint32_t mpct)
 {
     int i;
     uint8_t checksum;
@@ -283,7 +281,7 @@ void fill_mpfps(struct mp_floating_point
  * The '___HVMMP' signature is created by the ROMBIOS and designates a chunk
  * of space inside the ROMBIOS that is safe for us to write our MP table info
  */
-void* get_mp_table_start(void)
+static void *get_mp_table_start(void)
 {
     char *bios_mem;
 
@@ -300,7 +298,7 @@ void* get_mp_table_start(void)
 
 
 /* recalculate the new ROMBIOS checksum after adding MP tables */
-void reset_bios_checksum(void)
+static void reset_bios_checksum(void)
 {
     uint32_t i;
     uint8_t checksum;
@@ -311,7 +309,6 @@ void reset_bios_checksum(void)
 
     *((uint8_t *)(ROMBIOS_BEGIN + ROMBIOS_MAXOFFSET)) = -checksum;
 }
-
 
 /* create_mp_tables - creates MP tables for the guest based upon config data */
 void create_mp_tables(void)
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/firmware/hvmloader/smp.c
--- a/tools/firmware/hvmloader/smp.c    Tue Jul 08 11:41:43 2008 +0900
+++ b/tools/firmware/hvmloader/smp.c    Fri Jul 18 12:12:41 2008 +0900
@@ -69,8 +69,7 @@ asm (
     "    .text                       \n"
     );
 
-extern void cacheattr_init(void);
-
+void ap_start(void); /* non-static avoids unused-function compiler warning */
 /*static*/ void ap_start(void)
 {
     printf(" - CPU%d ... ", ap_cpuid);
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/firmware/hvmloader/util.h
--- a/tools/firmware/hvmloader/util.h   Tue Jul 08 11:41:43 2008 +0900
+++ b/tools/firmware/hvmloader/util.h   Fri Jul 18 12:12:41 2008 +0900
@@ -137,6 +137,12 @@ uint32_t e820_malloc(uint32_t size);
 /* Prepare the 32bit BIOS */
 void highbios_setup(void);
 
+/* Miscellaneous. */
+void cacheattr_init(void);
+void create_mp_tables(void);
+int hvm_write_smbios_tables(void);
+void smp_initialise(void);
+
 #define isdigit(c) ((c) >= '0' && (c) <= '9')
 
 #endif /* __HVMLOADER_UTIL_H__ */
diff -r eb0fc71cfc72 -r 400e5d4877ca 
tools/firmware/rombios/32bit/tcgbios/tcgbios.c
--- a/tools/firmware/rombios/32bit/tcgbios/tcgbios.c    Tue Jul 08 11:41:43 
2008 +0900
+++ b/tools/firmware/rombios/32bit/tcgbios/tcgbios.c    Fri Jul 18 12:12:41 
2008 +0900
@@ -581,7 +581,7 @@ static char wake_event_1[]    = "Wake Ev
  * data       : additional parameter; used as parameter for 10.4.3
  *              'action index'
  */
-void tcpa_add_measurement(uint32_t pcrIndex,
+static void tcpa_add_measurement(uint32_t pcrIndex,
                           uint16_t event_type,
                           uint32_t data)
 {
@@ -863,7 +863,7 @@ uint32_t tcpa_initialize_tpm(uint32_t ph
 }
 
 
-uint16_t TCG_IsShutdownPreBootInterface(void)
+static uint16_t TCG_IsShutdownPreBootInterface(void)
 {
        return tcpa_acpi.flags & STATUS_FLAG_SHUTDOWN;
 }
diff -r eb0fc71cfc72 -r 400e5d4877ca 
tools/firmware/rombios/32bit/tcgbios/tpm_drivers.c
--- a/tools/firmware/rombios/32bit/tcgbios/tpm_drivers.c        Tue Jul 08 
11:41:43 2008 +0900
+++ b/tools/firmware/rombios/32bit/tcgbios/tpm_drivers.c        Fri Jul 18 
12:12:41 2008 +0900
@@ -75,7 +75,7 @@ static uint32_t tis_activate(uint32_t ba
        return rc;
 }
 
-uint32_t tis_ready(uint32_t baseaddr)
+static uint32_t tis_ready(uint32_t baseaddr)
 {
        uint32_t rc = 0;
        uint8_t *tis_addr = (uint8_t*)baseaddr;
@@ -86,7 +86,7 @@ uint32_t tis_ready(uint32_t baseaddr)
        return rc;
 }
 
-uint32_t tis_senddata(uint32_t baseaddr, unsigned char *data, uint32_t len)
+static uint32_t tis_senddata(uint32_t baseaddr, unsigned char *data, uint32_t 
len)
 {
        uint32_t rc = 0;
        uint8_t *tis_addr = (uint8_t*)baseaddr;
@@ -127,7 +127,7 @@ uint32_t tis_senddata(uint32_t baseaddr,
        return rc;
 }
 
-uint32_t tis_readresp(uint32_t baseaddr, unsigned char *buffer, uint32_t len)
+static uint32_t tis_readresp(uint32_t baseaddr, unsigned char *buffer, 
uint32_t len)
 {
        uint32_t rc = 0;
        uint32_t offset = 0;
@@ -147,7 +147,7 @@ uint32_t tis_readresp(uint32_t baseaddr,
 }
 
 
-uint32_t tis_waitdatavalid(uint32_t baseaddr)
+static uint32_t tis_waitdatavalid(uint32_t baseaddr)
 {
        uint8_t *tis_addr = (uint8_t*)baseaddr;
        uint32_t rc = 0;
@@ -157,7 +157,7 @@ uint32_t tis_waitdatavalid(uint32_t base
        return rc;
 }
 
-uint32_t tis_waitrespready(uint32_t baseaddr, uint32_t timeout)
+static uint32_t tis_waitrespready(uint32_t baseaddr, uint32_t timeout)
 {
        uint32_t rc = 0;
        uint8_t *tis_addr = (uint8_t*)baseaddr;
@@ -170,7 +170,7 @@ uint32_t tis_waitrespready(uint32_t base
 }
 
 /* if device is not there, return '0', '1' otherwise */
-uint32_t tis_probe(uint32_t baseaddr)
+static uint32_t tis_probe(uint32_t baseaddr)
 {
        uint32_t rc = 0;
        uint8_t *tis_addr = (uint8_t*)baseaddr;
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/firmware/rombios/32bit/util.c
--- a/tools/firmware/rombios/32bit/util.c       Tue Jul 08 11:41:43 2008 +0900
+++ b/tools/firmware/rombios/32bit/util.c       Fri Jul 18 12:12:41 2008 +0900
@@ -388,12 +388,6 @@ int printf(const char *fmt, ...)
     return 0;
 }
 
-int vprintf(const char *fmt, va_list ap)
-{
-    _doprint(putchar, fmt, ap);
-    return 0;
-}
-
 void mssleep(uint32_t waittime)
 {
     uint32_t i;
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/firmware/rombios/rombios.c
--- a/tools/firmware/rombios/rombios.c  Tue Jul 08 11:41:43 2008 +0900
+++ b/tools/firmware/rombios/rombios.c  Fri Jul 18 12:12:41 2008 +0900
@@ -26,6 +26,9 @@
 
 // ROM BIOS for use with Bochs/Plex x86 emulation environment
 
+#define uint8_t unsigned char
+#define uint16_t unsigned short
+#define uint32_t unsigned long
 #include "../hvmloader/config.h"
 
 #define HVMASSIST
@@ -1459,6 +1462,23 @@ copy_e820_table()
   base_mem = read_dword(0x9000, 0x2d0 + 8);
   write_word(0x40, 0x13, base_mem >> 10);
 }
+
+void
+disable_rom_write_access()
+{
+    Bit16u off = (Bit16u)&((struct bios_info *)0)->xen_pfiob;
+ASM_START
+    mov si,.disable_rom_write_access.off[bp]
+    push ds
+    mov ax,#(ACPI_PHYSICAL_ADDRESS >> 4)
+    mov ds,ax
+    mov dx,[si]
+    pop ds
+    mov ax,#PFFLAG_ROM_LOCK
+    out dx,al
+ASM_END
+}
+    
 #endif /* HVMASSIST */
 
 #if BX_DEBUG_SERIAL
@@ -10154,6 +10174,10 @@ post_default_ints:
 #if BX_TCGBIOS
   call tcpa_post_part2
 #endif
+
+#ifdef HVMASSIST
+  call _disable_rom_write_access
+#endif 
 
   ;; Start the boot sequence.   See the comments in int19_relocated 
   ;; for why we use INT 18h instead of INT 19h here.
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/firmware/vgabios/ChangeLog
--- a/tools/firmware/vgabios/ChangeLog  Tue Jul 08 11:41:43 2008 +0900
+++ b/tools/firmware/vgabios/ChangeLog  Fri Jul 18 12:12:41 2008 +0900
@@ -1,3 +1,207 @@ 2005-05-24 16:50  vruppert
+2008-05-11 08:40  vruppert
+
+       * biossums.c (1.6):
+
+       - fixed a warning
+
+2008-03-02 08:47  vruppert
+
+       * vbe.c (1.60):
+
+       - added debug message for unsupported VBE modes
+
+2008-02-24 09:18  vruppert
+
+       * vbe.c (1.59):
+
+       - in LFB modes the number of banks must be set to 1
+
+2008-01-27 10:44  vruppert
+
+       * Makefile (1.21), biossums.c (1.5), vgabios.c (1.67):
+
+       - added PCI data structure for the Cirrus VGABIOS images
+       - added support for the PCI data structure in biossums
+       - updated year in copyright
+
+2008-01-26 11:46  vruppert
+
+       * BUGS (1.4), Makefile (1.20), README (1.14), TODO (1.13), 
vbe_display_api.txt (1.14):
+
+       - whitespace cleanup
+
+2006-11-26 10:43  vruppert
+
+       * Makefile (1.19):
+
+       - disable the generation of linemarkers by the preprocessor, since the 
latest
+         versions of bcc don't like them
+
+2006-09-02 13:15  vruppert
+
+       * biossums.c (1.4):
+
+       - the biossums utility no longer modifies VGABIOS images with proper 
checksum
+         and size
+
+2006-08-19 14:28  vruppert
+
+       * Changelog (1.26), README (1.13), TODO (1.12):
+
+       - updates for 0.6a release
+
+2006-08-19 09:39  vruppert
+
+       * vbe.c (1.58):
+
+       - improved VGA compatible setup for VBE modes (disable CGA and Hercules
+         compatible memory layout)
+
+2006-08-18 20:39  vruppert
+
+       * vbe.c (1.57):
+
+       - improved VGA compatible setup for >=8bpp VBE modes (CRTC doubleword 
mode and
+         GRDC shift register setting added)
+       - now using symbolic name for CRTC address register
+
+2006-08-15 20:42  vruppert
+
+       * vbe.c (1.56), vbetables-gen.c (1.4):
+
+       - init 4bpp VBE modes by a temporary switch to VGA mode 0x6A
+       - all 4bpp VBE modes now enabled
+
+2006-08-14 20:24  vruppert
+
+       * vbe.c (1.55):
+
+       - VGA compatible setup for VBE modes improved (Bochs hack can be 
removed now)
+
+2006-08-12 07:51  vruppert
+
+       * .cvsignore (1.1):
+
+       - .cvsignore added for auto-generated file
+
+2006-08-12 07:47  vruppert
+
+       * vbe.c (1.54), vbe.h (1.27), vbe_display_api.txt (1.13), 
vbetables-gen.c (1.3):
+
+       - cleaned up VBE memory size definitions (removed duplicate defines, 
main
+         definition now in vbetables-gen.c)
+
+2006-08-09 21:28  vruppert
+
+       * vbetables.h (1.30):
+
+       - removed auto-generated file
+
+2006-08-09 21:26  vruppert
+
+       * vbe.c (1.53), vbe.h (1.26), vbe_display_api.txt (1.12), 
vbetables-gen.c (1.2),
+         vbetables.h (1.29):
+
+       - VBE video memory increased to 8 MB
+       - VBE dispi ID changed to B0C4
+       - documentation update
+
+2006-07-11 08:03  vruppert
+
+       * Makefile (1.18), vbetables-gen.c (1.1), vbetables.h (1.28):
+
+       - generate vbetables.h dynamicly
+         * initial patch from the qemu project by Fabrice Bellard
+         * only add modes that fit in video memory (still 4 MB)
+         * several other fixes (e.g. 4 bpp specific stuff, number of pages)
+
+2006-07-10 07:47  vruppert
+
+       * vgabios.c (1.66):
+
+       - biosfn_scroll(): check variable 'i' for underflowing when scrolling 
downwards
+         to avoid screen corruption
+
+2006-07-10 07:47  vruppert
+
+       * vbe.c (1.52):
+
+       - VBE set bank functions failure handling added
+       - VBE get/set logical scan line length fixes for the 4bpp mode
+
+2006-07-08 13:27  vruppert
+
+       * vbe.c (1.51), vbetables.h (1.27):
+
+       - added special case for the 4 bpp when setting VBE display start
+       - VBE mode table fixes
+
+2006-07-07 13:30  vruppert
+
+       * clext.c (1.12):
+
+       - bank pointer must be set to 0 after a mode set
+
+2006-06-21 16:58  vruppert
+
+       * vbe.c (1.50), vbetables.h (1.26):
+
+       - improved VBE display capabilities check (X resulution checked now)
+       - removed obsolete defines (LFB always available, always generate 
dynamic list)
+       - CR/LF to LF fixes
+
+2006-06-18 15:22  vruppert
+
+       * clext.c (1.11), vbe.c (1.49), vbe.h (1.25), vbetables.h (1.25), 
vgabios.c
+         (1.65):
+
+       - applied patch from the qemu project (Fabrice Bellard)
+         * Cirrus SVGA now supports the "no clear" bit when switching to 
Cirrus or
+           VESA mode
+         * Bochs VBE protected mode interface improved
+         * save/restore video state support for Bochs VBE and standard VGA 
added
+         * Bochs VBE prepared for more modi
+
+2006-03-25 10:19  vruppert
+
+       * clext.c (1.10), vgabios.c (1.64), vgatables.h (1.10):
+
+       - applied patch from Fabrice Bellard
+        * added minimal support for the video parameter table (VPT)
+        * added Cirrus SVGA mode 0x7b (1600x1200x8)
+
+2005-12-26 19:50  vruppert
+
+       * vbe.c (1.48), vgabios.c (1.63):
+
+       - Bochs VBE protected mode interface added (based on a patch by 
malc@xxxxxxxxxxxxx)
+
+2005-12-26 19:50  vruppert
+
+       * biossums.c (1.3):
+
+       - biossums utility now supports VGABIOS sizes up to 64 kBytes
+
+2005-09-21 18:45  vruppert
+
+       * vgatables.h (1.9):
+
+       - mode 0x11: all color planes must be enabled in this 2-color VGA mode
+
+2005-08-30 18:41  vruppert
+
+       * biossums.c (1.2):
+
+       - missing license text added in biossums.c
+
+2005-07-02 18:39  vruppert
+
+       * vgabios.c (1.62):
+
+       - BIOS configuration word usually reports initial mode 80x25 color text
+       - vgabios function 0x0e (write teletype): linefeed (0x0a) only 
increments the
+         cursor row value
+
 2005-05-24 16:50  vruppert
 
        * vbe.c (1.47), vgabios.c (1.61):
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/firmware/vgabios/Makefile
--- a/tools/firmware/vgabios/Makefile   Tue Jul 08 11:41:43 2008 +0900
+++ b/tools/firmware/vgabios/Makefile   Fri Jul 18 12:12:41 2008 +0900
@@ -21,7 +21,7 @@ cirrus-bios: vgabios-cirrus.bin vgabios-
 
 .PHONY: clean
 clean:
-       rm -f biossums *.o *.s *.ld86 \
+       rm -f  biossums vbetables-gen vbetables.h *.o *.s *.ld86 \
           temp.awk.* vgabios*.orig _vgabios_* _vgabios-debug_* core 
vgabios*.bin vgabios*.txt $(RELEASE).bin *.bak
        rm -f VGABIOS-lgpl-latest*.bin
 
@@ -37,7 +37,7 @@ release:
        tar czvf ../$(RELEASE).tgz --exclude CVS -C .. $(RELEASE)/
 
 vgabios.bin: biossums vgabios.c vgabios.h vgafonts.h vgatables.h vbe.h vbe.c 
vbetables.h
-       $(GCC) -E -P vgabios.c $(VGABIOS_VERS) $(VGABIOS_DATE) > _vgabios_.c
+       $(GCC) -E -P vgabios.c $(VGABIOS_VERS) -DVBE $(VGABIOS_DATE) > 
_vgabios_.c
        $(BCC) -o vgabios.s -C-c -D__i86__ -S -0 _vgabios_.c
        sed -e 's/^\.text//' -e 's/^\.data//' vgabios.s > _vgabios_.s
        $(AS86) _vgabios_.s -b vgabios.bin -u -w- -g -0 -j -O -l vgabios.txt
@@ -47,7 +47,7 @@ vgabios.bin: biossums vgabios.c vgabios.
        ls -l VGABIOS-lgpl-latest.bin
 
 vgabios.debug.bin: biossums vgabios.c vgabios.h vgafonts.h vgatables.h vbe.h 
vbe.c vbetables.h
-       $(GCC) -E -P vgabios.c $(VGABIOS_VERS) -DDEBUG $(VGABIOS_DATE) > 
_vgabios-debug_.c
+       $(GCC) -E -P vgabios.c $(VGABIOS_VERS) -DVBE -DDEBUG $(VGABIOS_DATE) > 
_vgabios-debug_.c
        $(BCC) -o vgabios-debug.s -C-c -D__i86__ -S -0 _vgabios-debug_.c
        sed -e 's/^\.text//' -e 's/^\.data//' vgabios-debug.s > 
_vgabios-debug_.s
        $(AS86) _vgabios-debug_.s -b vgabios.debug.bin -u -w- -g -0 -j -O -l 
vgabios.debug.txt
@@ -57,7 +57,7 @@ vgabios.debug.bin: biossums vgabios.c vg
        ls -l VGABIOS-lgpl-latest.debug.bin
 
 vgabios-cirrus.bin: biossums vgabios.c vgabios.h vgafonts.h vgatables.h clext.c
-       $(GCC) -E -P vgabios.c $(VGABIOS_VERS) -DCIRRUS $(VGABIOS_DATE) > 
_vgabios-cirrus_.c
+       $(GCC) -E -P vgabios.c $(VGABIOS_VERS) -DCIRRUS -DPCIBIOS 
$(VGABIOS_DATE) > _vgabios-cirrus_.c
        $(BCC) -o vgabios-cirrus.s -C-c -D__i86__ -S -0 _vgabios-cirrus_.c
        sed -e 's/^\.text//' -e 's/^\.data//' vgabios-cirrus.s > 
_vgabios-cirrus_.s
        $(AS86) _vgabios-cirrus_.s -b vgabios-cirrus.bin -u -w- -g -0 -j -O -l 
vgabios-cirrus.txt
@@ -67,7 +67,7 @@ vgabios-cirrus.bin: biossums vgabios.c v
        ls -l VGABIOS-lgpl-latest.cirrus.bin
 
 vgabios-cirrus.debug.bin: biossums vgabios.c vgabios.h vgafonts.h vgatables.h 
clext.c
-       $(GCC) -E -P vgabios.c $(VGABIOS_VERS) -DCIRRUS -DCIRRUS_DEBUG 
$(VGABIOS_DATE) > _vgabios-cirrus-debug_.c
+       $(GCC) -E -P vgabios.c $(VGABIOS_VERS) -DCIRRUS -DCIRRUS_DEBUG 
-DPCIBIOS $(VGABIOS_DATE) > _vgabios-cirrus-debug_.c
        $(BCC) -o vgabios-cirrus-debug.s -C-c -D__i86__ -S -0 
_vgabios-cirrus-debug_.c
        sed -e 's/^\.text//' -e 's/^\.data//' vgabios-cirrus-debug.s > 
_vgabios-cirrus-debug_.s
        $(AS86) _vgabios-cirrus-debug_.s -b vgabios-cirrus.debug.bin -u -w- -g 
-0 -j -O -l vgabios-cirrus.debug.txt
@@ -78,3 +78,9 @@ vgabios-cirrus.debug.bin: biossums vgabi
 
 biossums: biossums.c
        $(CC) -o biossums biossums.c
+
+vbetables-gen: vbetables-gen.c
+       $(CC) -o vbetables-gen vbetables-gen.c
+
+vbetables.h: vbetables-gen
+       ./vbetables-gen > $@
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/firmware/vgabios/README
--- a/tools/firmware/vgabios/README     Tue Jul 08 11:41:43 2008 +0900
+++ b/tools/firmware/vgabios/README     Fri Jul 18 12:12:41 2008 +0900
@@ -90,6 +90,34 @@ For any information on qemu, visit the w
 
 History
 -------
+vgabios-0.6b : May 30 2008
+  - Volker
+    . added PCI data structure for the Cirrus VGABIOS images
+    . minor bugfixes in biossums utility, VBE support and makefile
+
+vgabios-0.6a : Aug 19 2006
+  - Volker
+    . added minimal support for the video parameter table (VPT)
+    . Cirrus SVGA now supports the "no clear" bit in Cirrus and VESA mode
+    . Bochs VBE protected mode interface improved
+    . save/restore video state support for Bochs VBE and standard VGA added
+    . generate vbetables.h dynamicly
+    . VBE video memory increased to 8 MB (VBE dispi ID changed to B0C4)
+    . lots of 4bpp VBE fixes (all 4bpp VBE modes now enabled)
+    . VGA compatible setup for VBE modes added
+
+vgabios-0.5d : Dec 29 2005
+  - Volker
+    . Bochs VBE protected mode interface added (based on a patch by 
malc@xxxxxxxxxxxxx)
+    . biossums utility now supports VGABIOS sizes up to 64 kBytes
+    . VGA mode 0x11: all color planes must be enabled in this 2-color VGA mode
+
+vgabios-0.5c : Jul 07 2005
+  - Volker
+    . BIOS configuration word usually reports initial mode 80x25 color text
+    . vgabios function 0x0e (write teletype): linefeed (0x0a) only increments 
the
+      cursor row value
+
 vgabios-0.5b : May 24 2005
   - Volker
     . fixed return value for the default case in the VBE section (non-debug 
mode)
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/firmware/vgabios/TODO
--- a/tools/firmware/vgabios/TODO       Tue Jul 08 11:41:43 2008 +0900
+++ b/tools/firmware/vgabios/TODO       Fri Jul 18 12:12:41 2008 +0900
@@ -6,13 +6,11 @@ General
   - Add new functionalities and modify static functionality table 
   - Performance : 16 bits IO
 
-v0.6
-  - Reimplement the tables so it is compatible with the video save pointer 
table
+v0.7
   - Implement the remaining functions (don't know if all are needed):
        - chargen ax=1120, ax=1121, ax=1122, ax=1123, ax=1124
        - display switch interface ah=12 bl=35
        - video refresh control ah=12 bl=36
-        - save/restore state ah=1c
   - Graphic modes
 
 v1.0
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/firmware/vgabios/biossums.c
--- a/tools/firmware/vgabios/biossums.c Tue Jul 08 11:41:43 2008 +0900
+++ b/tools/firmware/vgabios/biossums.c Fri Jul 18 12:12:41 2008 +0900
@@ -1,25 +1,35 @@
 /* biossums.c  --- written by Eike W. for the Bochs BIOS */
 /* adapted for the LGPL'd VGABIOS by vruppert */
 
+/*  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 
USA
+ */
 #include <stdlib.h>
 #include <stdio.h>
+#include <string.h>
 
 typedef unsigned char byte;
 
 void check( int value, char* message );
 
-#define LEN_BIOS_DATA 0x8000
-#define MAX_OFFSET    (LEN_BIOS_DATA - 1)
-
-
-#define BIOS_OFFSET 0x7FFF
+#define MAX_BIOS_DATA 0x10000
 
 long chksum_bios_get_offset( byte* data, long offset );
 byte chksum_bios_calc_value( byte* data, long offset );
 byte chksum_bios_get_value(  byte* data, long offset );
 void chksum_bios_set_value(  byte* data, long offset, byte value );
 
-
 #define PMID_LEN        20
 #define PMID_CHKSUM     19
 
@@ -28,33 +38,55 @@ byte chksum_pmid_get_value(  byte* data,
 byte chksum_pmid_get_value(  byte* data, long offset );
 void chksum_pmid_set_value(  byte* data, long offset, byte value );
 
-
-byte bios_data[LEN_BIOS_DATA];
-
-
-int main( int argc, char* argv[] ) {
-
+#define PCIR_LEN        24
+
+long chksum_pcir_get_offset( byte* data, long offset );
+
+
+byte bios_data[MAX_BIOS_DATA];
+long bios_len;
+
+
+int main(int argc, char* argv[])
+{
   FILE* stream;
-  long  offset, tmp_offset;
-  byte  cur_val = 0, new_val = 0;
-  int   hits;
-
-
-  if( argc != 2 ) {
+  long  offset, tmp_offset, pcir_offset;
+  byte  bios_len_byte, cur_val = 0, new_val = 0;
+  int   hits, modified;
+
+  if (argc != 2) {
     printf( "Error. Need a file-name as an argument.\n" );
     exit( EXIT_FAILURE );
   }
 
-  if(( stream = fopen( argv[1], "rb" )) == NULL ) {
-    printf( "Error opening %s for reading.\n", argv[1] );
-    exit( EXIT_FAILURE );
-  }
-  if( fread( bios_data, 1, LEN_BIOS_DATA, stream ) >= LEN_BIOS_DATA ) {
-    printf( "Error reading max. 32767 Bytes from %s.\n", argv[1] );
-    fclose( stream );
-    exit( EXIT_FAILURE );
-  }
-  fclose( stream );
+  if ((stream = fopen(argv[1], "rb")) == NULL) {
+    printf("Error opening %s for reading.\n", argv[1]);
+    exit(EXIT_FAILURE);
+  }
+  memset(bios_data, 0, MAX_BIOS_DATA);
+  bios_len = fread(bios_data, 1, MAX_BIOS_DATA, stream);
+  if (bios_len > MAX_BIOS_DATA) {
+    printf("Error reading max. 65536 Bytes from %s.\n", argv[1]);
+    fclose(stream);
+    exit(EXIT_FAILURE);
+  }
+  fclose(stream);
+  modified = 0;
+  if (bios_len < 0x8000) {
+    bios_len = 0x8000;
+    modified = 1;
+  } else if ((bios_len & 0x1FF) != 0) {
+    bios_len = (bios_len + 0x200) & ~0x1FF;
+    modified = 1;
+  }
+  bios_len_byte = (byte)(bios_len / 512);
+  if (bios_len_byte != bios_data[2]) {
+    if (modified == 0) {
+      bios_len += 0x200;
+    }
+    bios_data[2] = (byte)(bios_len / 512);
+    modified = 1;
+  }
 
   hits   = 0;
   offset = 0L;
@@ -67,44 +99,76 @@ int main( int argc, char* argv[] ) {
     printf( "Calculated checksum:  0x%02X  ",   new_val );
     hits++;
   }
-  if( hits == 1 && cur_val != new_val ) {
-    printf( "Setting checksum." );
+  if ((hits == 1) && (cur_val != new_val)) {
+    printf("Setting checksum.");
     chksum_pmid_set_value( bios_data, offset, new_val );
-  }
-  if( hits >= 2 ) {
+    if (modified == 0) {
+      bios_len += 0x200;
+      bios_data[2]++;
+    }
+    modified = 1;
+  }
+  if (hits >= 2) {
     printf( "Multiple PMID entries! No checksum set." );
   }
-  if( hits ) {
-    printf( "\n" );
-  }
-
+  if (hits) {
+    printf("\n");
+  }
+
+  offset = 0L;
+  pcir_offset = chksum_pcir_get_offset( bios_data, offset );
+  if (pcir_offset != -1L) {
+    if (bios_data[pcir_offset + 16] != bios_data[2]) {
+      bios_data[pcir_offset + 16] = bios_data[2];
+      if (modified == 0) {
+        bios_len += 0x200;
+        bios_data[2]++;
+        bios_data[pcir_offset + 16]++;
+      }
+      modified = 1;
+    }
+  }
 
   offset  = 0L;
-  offset  = chksum_bios_get_offset( bios_data, offset );
-  cur_val = chksum_bios_get_value(  bios_data, offset );
-  new_val = chksum_bios_calc_value( bios_data, offset );
-  printf( "\nBios checksum at:   0x%4lX\n", offset  );
-  printf( "Current checksum:     0x%02X\n",   cur_val );
-  printf( "Calculated checksum:  0x%02X  ",   new_val );
-  if( cur_val != new_val ) {
-    printf( "Setting checksum." );
-    chksum_bios_set_value( bios_data, offset, new_val );
-  }
-  printf( "\n" );
-
-
-  if(( stream = fopen( argv[1], "wb" )) == NULL ) {
-    printf( "Error opening %s for writing.\n", argv[1] );
-    exit( EXIT_FAILURE );
-  }
-  if( fwrite( bios_data, 1, LEN_BIOS_DATA, stream ) < LEN_BIOS_DATA ) {
-    printf( "Error writing 32KBytes to %s.\n", argv[1] );
-    fclose( stream );
-    exit( EXIT_FAILURE );
-  }
-  fclose( stream );
-
-  return( EXIT_SUCCESS );
+  do {
+    offset  = chksum_bios_get_offset(bios_data, offset);
+    cur_val = chksum_bios_get_value(bios_data, offset);
+    new_val = chksum_bios_calc_value(bios_data, offset);
+    if ((cur_val != new_val) && (modified == 0)) {
+      bios_len += 0x200;
+      bios_data[2]++;
+      if (pcir_offset != -1L) {
+        bios_data[pcir_offset + 16]++;
+      }
+      modified = 1;
+    } else {
+      printf("\nBios checksum at:   0x%4lX\n", offset);
+      printf("Current checksum:     0x%02X\n", cur_val);
+      printf("Calculated checksum:  0x%02X  ", new_val);
+      if (cur_val != new_val) {
+        printf("Setting checksum.");
+        chksum_bios_set_value(bios_data, offset, new_val);
+        cur_val = new_val;
+        modified = 1;
+      }
+      printf( "\n" );
+    }
+  } while (cur_val != new_val);
+
+  if (modified == 1) {
+    if ((stream = fopen( argv[1], "wb")) == NULL) {
+      printf("Error opening %s for writing.\n", argv[1]);
+      exit(EXIT_FAILURE);
+    }
+    if (fwrite(bios_data, 1, bios_len, stream) < bios_len) {
+      printf("Error writing %d KBytes to %s.\n", bios_len / 1024, argv[1]);
+      fclose(stream);
+      exit(EXIT_FAILURE);
+    }
+    fclose(stream);
+  }
+
+  return (EXIT_SUCCESS);
 }
 
 
@@ -119,7 +183,7 @@ void check( int okay, char* message ) {
 
 long chksum_bios_get_offset( byte* data, long offset ) {
 
-  return( BIOS_OFFSET );
+  return (bios_len - 1);
 }
 
 
@@ -129,7 +193,7 @@ byte chksum_bios_calc_value( byte* data,
   byte  sum;
 
   sum = 0;
-  for( i = 0; i < MAX_OFFSET; i++ ) {
+  for( i = 0; i < offset; i++ ) {
     sum = sum + *( data + i );
   }
   sum = -sum;          /* iso ensures -s + s == 0 on unsigned types */
@@ -139,13 +203,13 @@ byte chksum_bios_calc_value( byte* data,
 
 byte chksum_bios_get_value( byte* data, long offset ) {
 
-  return( *( data + BIOS_OFFSET ) );
+  return( *( data + offset ) );
 }
 
 
 void chksum_bios_set_value( byte* data, long offset, byte value ) {
 
-  *( data + BIOS_OFFSET ) = value;
+  *( data + offset ) = value;
 }
 
 
@@ -156,7 +220,7 @@ byte chksum_pmid_calc_value( byte* data,
   byte sum;
 
   len = PMID_LEN;
-  check( offset + len <= MAX_OFFSET, "PMID entry length out of bounds" );
+  check((offset + len) <= (bios_len - 1), "PMID entry length out of bounds" );
   sum = 0;
   for( i = 0; i < len; i++ ) {
     if( i != PMID_CHKSUM ) {
@@ -172,7 +236,7 @@ long chksum_pmid_get_offset( byte* data,
 
   long result = -1L;
 
-  while( offset + PMID_LEN < MAX_OFFSET ) {
+  while ((offset + PMID_LEN) < (bios_len - 1)) {
     offset = offset + 1;
     if( *( data + offset + 0 ) == 'P' && \
         *( data + offset + 1 ) == 'M' && \
@@ -188,13 +252,31 @@ long chksum_pmid_get_offset( byte* data,
 
 byte chksum_pmid_get_value( byte* data, long offset ) {
 
-  check( offset + PMID_CHKSUM <= MAX_OFFSET, "PMID checksum out of bounds" );
+  check((offset + PMID_CHKSUM) <= (bios_len - 1), "PMID checksum out of 
bounds" );
   return(  *( data + offset + PMID_CHKSUM ) );
 }
 
 
 void chksum_pmid_set_value( byte* data, long offset, byte value ) {
 
-  check( offset + PMID_CHKSUM <= MAX_OFFSET, "PMID checksum out of bounds" );
+  check((offset + PMID_CHKSUM) <= (bios_len - 1), "PMID checksum out of 
bounds" );
   *( data + offset + PMID_CHKSUM ) = value;
 }
+
+
+long chksum_pcir_get_offset( byte* data, long offset ) {
+
+  long result = -1L;
+
+  while ((offset + PCIR_LEN) < (bios_len - 1)) {
+    offset = offset + 1;
+    if( *( data + offset + 0 ) == 'P' && \
+        *( data + offset + 1 ) == 'C' && \
+        *( data + offset + 2 ) == 'I' && \
+        *( data + offset + 3 ) == 'R' ) {
+      result = offset;
+      break;
+    }
+  }
+  return( result );
+}
diff -r eb0fc71cfc72 -r 400e5d4877ca tools/firmware/vgabios/clext.c
--- a/tools/firmware/vgabios/clext.c    Tue Jul 08 11:41:43 2008 +0900
+++ b/tools/firmware/vgabios/clext.c    Fri Jul 18 12:12:41 2008 +0900
@@ -239,6 +239,21 @@ 0xffff
 0xffff
 };
 
+/* 1600x1200x8 */
+unsigned short cseq_1600x1200x8[] = {
+0x0300,0x2101,0x0f02,0x0003,0x0e04,0x1107,
+0x760b,0x760c,0x760d,0x760e,
+0x0412,0x0013,0x2017,
+0x341b,0x341c,0x341d,0x341e,
+0xffff
+};
+unsigned short ccrtc_1600x1200x8[] = {
+0x2911,0xc300,0x9f01,0x9f02,0x8603,0x8304,0x9405,0x2406,0xf707,
+0x6009,0x000c,0x000d,
+0x0310,0xff12,0xa013,0x4014,0xff15,0x2416,0xc317,0xff18,
+0x001a,0x221b,0x001d,
+0xffff
+};
 
 cirrus_mode_t cirrus_modes[] =
 {
@@ -291,6 +306,10 @@ cirrus_mode_t cirrus_modes[] =
  {0x75,1280,1024,16,0xe1,
    cseq_1280x1024x16,cgraph_svgacolor,ccrtc_1280x1024x16,16,
    6,5,11,6,5,5,0,0,0},
+
+ {0x7b,1600,1200,8,0x00,
+   cseq_1600x1200x8,cgraph_svgacolor,ccrtc_1600x1200x8,8,
+   4,0,0,0,0,0,0,0,0},
 
  {0xfe,0,0,0,0,cseq_vga,cgraph_vga,ccrtc_vga,0,
    0xff,0,0,0,0,0,0,0,0},

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>