direct-io.hg

changeset 3647:bbe8541361dd

bitkeeper revision 1.1159.1.542 (42038a42_52IAalMZRKdTn0UbVN5fw)

Merge tempest.cl.cam.ac.uk:/auto/groups/xeno-xenod/BK/xeno.bk
into tempest.cl.cam.ac.uk:/local/scratch/smh22/xen-unstable.bk
author smh22@tempest.cl.cam.ac.uk
date Fri Feb 04 14:44:18 2005 +0000 (2005-02-04)
parents e8d6036117fd 33d462bea5cd
children 393483ae9f62
files .hgtags .rootkeys BitKeeper/etc/logging_ok buildconfigs/mk.linux-2.6-xen0 buildconfigs/mk.linux-2.6-xenU linux-2.6.10-xen-sparse/arch/xen/configs/xen0_defconfig linux-2.6.10-xen-sparse/arch/xen/i386/Makefile linux-2.6.10-xen-sparse/arch/xen/i386/kernel/Makefile linux-2.6.10-xen-sparse/arch/xen/i386/kernel/setup.c linux-2.6.10-xen-sparse/arch/xen/i386/mm/ioremap.c linux-2.6.10-xen-sparse/drivers/xen/blkfront/blkfront.c linux-2.6.10-xen-sparse/drivers/xen/blkfront/vbd.c linux-2.6.10-xen-sparse/drivers/xen/netback/common.h linux-2.6.10-xen-sparse/drivers/xen/netback/interface.c linux-2.6.10-xen-sparse/drivers/xen/privcmd/privcmd.c linux-2.6.10-xen-sparse/drivers/xen/usbback/usbback.c linux-2.6.10-xen-sparse/include/asm-xen/asm-i386/pgtable.h tools/examples/network-nat tools/examples/vif-nat tools/examples/xmexample3 tools/ioemu/include/config.h tools/ioemu/iodev/cpu.cc tools/ioemu/iodev/dma.cc tools/ioemu/iodev/dma.h tools/ioemu/memory/misc_mem.cc tools/ioemu/mk/helix.mk tools/libxc/Makefile tools/libxc/linux_boot_params.h tools/libxc/xc.h tools/libxc/xc_vmx_build.c tools/libxutil/Makefile tools/python/xen/lowlevel/xc/xc.c tools/python/xen/lowlevel/xu/xu.c tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/server/blkif.py tools/python/xen/xend/server/messages.py tools/python/xen/xend/server/netif.py tools/python/xen/xm/create.py tools/xcs/xcs.c xen/Makefile xen/Rules.mk xen/arch/x86/Rules.mk xen/arch/x86/boot/mkelf32.c xen/arch/x86/boot/x86_64.S xen/arch/x86/dom0_ops.c xen/arch/x86/domain.c xen/arch/x86/irq.c xen/arch/x86/memory.c xen/arch/x86/microcode.c xen/arch/x86/mpparse.c xen/arch/x86/mtrr/generic.c xen/arch/x86/mtrr/main.c xen/arch/x86/pci-pc.c xen/arch/x86/setup.c xen/arch/x86/shadow.c xen/arch/x86/smpboot.c xen/arch/x86/traps.c xen/arch/x86/vmx.c xen/arch/x86/vmx_platform.c xen/arch/x86/x86_32/asm-offsets.c xen/arch/x86/x86_32/domain_build.c xen/arch/x86/x86_32/entry.S xen/arch/x86/x86_32/mm.c xen/arch/x86/x86_32/seg_fixup.c xen/arch/x86/x86_32/traps.c xen/arch/x86/x86_32/xen.lds xen/arch/x86/x86_64/asm-offsets.c xen/arch/x86/x86_64/domain_build.c xen/arch/x86/x86_64/entry.S xen/arch/x86/x86_64/mm.c xen/arch/x86/x86_64/traps.c xen/arch/x86/x86_64/xen.lds xen/common/Makefile xen/common/ac_timer.c xen/common/dom0_ops.c xen/common/domain.c xen/common/elf.c xen/common/event_channel.c xen/common/grant_table.c xen/common/malloc.c xen/common/page_alloc.c xen/common/physdev.c xen/common/resource.c xen/common/sched_atropos.c xen/common/sched_bvt.c xen/common/sched_rrobin.c xen/common/slab.c xen/drivers/char/console.c xen/drivers/char/serial.c xen/drivers/pci/pci.c xen/drivers/pci/setup-res.c xen/include/asm-x86/apicdef.h xen/include/asm-x86/config.h xen/include/asm-x86/desc.h xen/include/asm-x86/domain_page.h xen/include/asm-x86/fixmap.h xen/include/asm-x86/irq.h xen/include/asm-x86/mm.h xen/include/asm-x86/page.h xen/include/asm-x86/pda.h xen/include/asm-x86/processor.h xen/include/asm-x86/regs.h xen/include/asm-x86/shadow.h xen/include/asm-x86/smp.h xen/include/asm-x86/time.h xen/include/asm-x86/vmx_platform.h xen/include/asm-x86/x86_32/asm_defns.h xen/include/asm-x86/x86_32/domain_page.h xen/include/asm-x86/x86_32/regs.h xen/include/asm-x86/x86_64/asm_defns.h xen/include/asm-x86/x86_64/current.h xen/include/asm-x86/x86_64/desc.h xen/include/asm-x86/x86_64/domain_page.h xen/include/asm-x86/x86_64/regs.h xen/include/public/arch-x86_32.h xen/include/public/arch-x86_64.h xen/include/public/io/domain_controller.h xen/include/public/xen.h xen/include/xen/domain.h xen/include/xen/elf.h xen/include/xen/keyhandler.h xen/include/xen/lib.h xen/include/xen/list.h xen/include/xen/sched.h xen/include/xen/slab.h xen/include/xen/time.h
line diff
     1.1 --- a/.hgtags	Fri Jan 28 14:53:32 2005 +0000
     1.2 +++ b/.hgtags	Fri Feb 04 14:44:18 2005 +0000
     1.3 @@ -2,6 +2,7 @@ 42882b3e0dda89f3a8ec00da568f86e9b3c230f1
     1.4  475a162b66e2c19b1e9468b234a4ba705334905e RELEASE-2.0.1
     1.5  dc2f08429f17e6614fd2f1ab88cc09ca0a850f32 RELEASE-2.0.2
     1.6  6e1bbc13911751efa0b1c018425c1b085820fa02 RELEASE-2.0.3
     1.7 +fb875591fd72e15c31879c0e9034d99b80225595 RELEASE-2.0.4
     1.8  487b2ee37d1cecb5f3e7a546b05ad097a0226f2f beta1
     1.9  3d330e41f41ce1bc118c02346e18949ad5d67f6b latest-semistable
    1.10  30c521db4c71960b0cf1d9c9e1b658e77b535a3e latest-stable
     2.1 --- a/.rootkeys	Fri Jan 28 14:53:32 2005 +0000
     2.2 +++ b/.rootkeys	Fri Feb 04 14:44:18 2005 +0000
     2.3 @@ -335,13 +335,16 @@ 405ff55dawQyCHFEnJ067ChPRoXBBA tools/exa
     2.4  40278d94cIUWl2eRgnwZtr4hTyWT1Q tools/examples/init.d/xendomains
     2.5  41dde8afTUuvdtFUlOx0ZRusKxyd8w tools/examples/mem-map.sxp
     2.6  40ee75a9xFz6S05sDKu-JCLqyVTkDA tools/examples/network
     2.7 +41fc0c18hVgK5rKJyZUsqybux9D9Dg tools/examples/network-nat
     2.8  41e661e1giIEKbJ25qfiP-ke8u8hFA tools/examples/network-route
     2.9  40ee75a967sxgcRY4Q7zXoVUaJ4flA tools/examples/vif-bridge
    2.10 +41fc0c18AFAVXA1uGm1JFWHMeeznVw tools/examples/vif-nat
    2.11  41e661e1ooiRKlOfwumG6wwzc0PdhQ tools/examples/vif-route
    2.12  40ee75a93cqxHp6MiYXxxwR5j2_8QQ tools/examples/xend-config.sxp
    2.13  41dde8af6M2Pm1Rrv_f5jEFC_BIOIA tools/examples/xmexample.vmx
    2.14  41090ec8Pj_bkgCBpg2W7WfmNkumEA tools/examples/xmexample1
    2.15  40cf2937oKlROYOJTN8GWwWM5AmjBg tools/examples/xmexample2
    2.16 +41fc0c18_k4iL81hu4pMIWQu9dKpKA tools/examples/xmexample3
    2.17  41e2ff6dNPgvIrdIF6dC1azdex1U3A tools/ioemu/Makefile
    2.18  41e2ff6aoF5fgddZi0QpEWqFr89E5g tools/ioemu/font/vga.bitmap.h
    2.19  41e2ff6avgnBNvZRiL4ynyGGq2UKlw tools/ioemu/gui/Makefile
    2.20 @@ -894,15 +897,19 @@ 41c0c411ODt8uEmV-yUxpQLpqimE5Q xen/arch/
    2.21  41f97ef5139vN42cOYHfX_Ac8WOOjA xen/arch/x86/vmx_platform.c
    2.22  41c0c4128URE0dxcO15JME_MuKBPfg xen/arch/x86/vmx_vmcs.c
    2.23  419cbedeQDg8IrO3izo3o5rQNlo0kQ xen/arch/x86/x86_32/asm-offsets.c
    2.24 +4202391dkvdTZ8GhWXe3Gqf9EOgWXg xen/arch/x86/x86_32/domain_build.c
    2.25  3e32af9aRnYGl4GMOaDKp7JdfhOGhg xen/arch/x86/x86_32/domain_page.c
    2.26  3ddb79bcecupHj56ZbTa3B0FxDowMg xen/arch/x86/x86_32/entry.S
    2.27  3ddb79bcHwuCQDjBICDTSis52hWguw xen/arch/x86/x86_32/mm.c
    2.28  40f92331jfOlE7MfKwpdkEb1CEf23g xen/arch/x86/x86_32/seg_fixup.c
    2.29 +42000d3ckiFc1qxa4AWqsd0t3lxuyw xen/arch/x86/x86_32/traps.c
    2.30  3ddb79bc4nTpGQOe6_-MbyZzkhlhFQ xen/arch/x86/x86_32/usercopy.c
    2.31  3ddb79bcOMCu9-5mKpjIh5d0qqBDPg xen/arch/x86/x86_32/xen.lds
    2.32  41bf1717Ty3hwN3E9swdu8QfnvGqww xen/arch/x86/x86_64/asm-offsets.c
    2.33 +4202391dA91ZovYX9d_5zJi9yGvLoQ xen/arch/x86/x86_64/domain_build.c
    2.34  40e96d3aLDI-nViMuYneD7VKYlZrVg xen/arch/x86/x86_64/entry.S
    2.35  41bf1717XhPz_dNT5OKSjgmbFuWBuA xen/arch/x86/x86_64/mm.c
    2.36 +42000d3cMb8o1WuFBXC07c8i3lPZBw xen/arch/x86/x86_64/traps.c
    2.37  40e96d3ahBTZqbTViInnq0lM03vs7A xen/arch/x86/x86_64/usercopy.c
    2.38  40e96d3akN3Hu_J5Bk-WXD8OGscrYQ xen/arch/x86/x86_64/xen.lds
    2.39  3ddb79bdff-gj-jFGKjOejeHLqL8Lg xen/common/Makefile
    2.40 @@ -918,6 +925,7 @@ 41262590gGIOn-1pvF5KpUu8Wb6_JA xen/commo
    2.41  3ddb79bd9drcFPVxd4w2GPOIjLlXpA xen/common/kernel.c
    2.42  3e4cd9d8LAAghUY0hNIK72uc2ch_Nw xen/common/keyhandler.c
    2.43  3ddb79bduhSEZI8xa7IbGQCpap5y2A xen/common/lib.c
    2.44 +4200cf14XGr26_PCC8NxREDhr7Hk5Q xen/common/malloc.c
    2.45  41a61536SZbR6cj1ukWTb0DYU-vz9w xen/common/multicall.c
    2.46  3ddb79bdD4SLmmdMD7yLW5HcUWucXw xen/common/page_alloc.c
    2.47  3e54c38dkHAev597bPr71-hGzTdocg xen/common/perfc.c
    2.48 @@ -996,7 +1004,7 @@ 3ddb79c2jFkPAZTDmU35L6IUssYMgQ xen/inclu
    2.49  3ddb79c3r9-31dIsewPV3P3i8HALsQ xen/include/asm-x86/delay.h
    2.50  3ddb79c34BFiXjBJ_cCKB0aCsV1IDw xen/include/asm-x86/desc.h
    2.51  40715b2dTokMLYGSuD58BnxOqyWVew xen/include/asm-x86/div64.h
    2.52 -3e20b82fl1jmQiKdLy7fxMcutfpjWA xen/include/asm-x86/domain_page.h
    2.53 +41febc4bBKTKHhnAu_KPYwgNkHjFlg xen/include/asm-x86/domain_page.h
    2.54  41d3eaaeIBzW621S1oa0c2yk7X43qQ xen/include/asm-x86/e820.h
    2.55  3ddb79c3NU8Zy40OTrq3D-i30Y3t4A xen/include/asm-x86/fixmap.h
    2.56  3e2d29944GI24gf7vOP_7x8EyuqxeA xen/include/asm-x86/flushtlb.h
    2.57 @@ -1014,7 +1022,6 @@ 41aaf567Mi3OishhvrCtET1y-mxQBg xen/inclu
    2.58  41a61536MFhNalgbVmYGXAhQsPTZNw xen/include/asm-x86/multicall.h
    2.59  3ddb79c3xjYnrv5t3VqYlR4tNEOl4Q xen/include/asm-x86/page.h
    2.60  3ddb79c3ysKUbxZuwKBRK3WXU2TlEg xen/include/asm-x86/pci.h
    2.61 -404f1bb41Yl-5ZjIWnG66HDCj6OIWA xen/include/asm-x86/pda.h
    2.62  4022a73diKn2Ax4-R4gzk59lm1YdDg xen/include/asm-x86/pdb.h
    2.63  3ddb79c2QF5-pZGzuX4QukPCDAl59A xen/include/asm-x86/processor.h
    2.64  40cf1596bim9F9DNdV75klgRSZ6Y2A xen/include/asm-x86/regs.h
    2.65 @@ -1025,6 +1032,7 @@ 3ddb79c3jn8ALV_S9W5aeTYUQRKBpg xen/inclu
    2.66  3ddb79c3NiyQE2vQnyGiaBnNjBO1rA xen/include/asm-x86/spinlock.h
    2.67  40e1966akOHWvvunCED7x3HPv35QvQ xen/include/asm-x86/string.h
    2.68  3ddb79c3ezddh34MdelJpa5tNR00Dw xen/include/asm-x86/system.h
    2.69 +42033fc1Bb8ffTshBYFGouGkiAMoUQ xen/include/asm-x86/time.h
    2.70  3ddb79c4HugMq7IYGxcQKFBpKwKhzA xen/include/asm-x86/types.h
    2.71  40cf1596saFaHD5DC5zvrSn7CDCWGQ xen/include/asm-x86/uaccess.h
    2.72  41c0c412k6GHYF3cJtDdw37ee3TVaw xen/include/asm-x86/vmx.h
    2.73 @@ -1033,12 +1041,13 @@ 41c0c41243jC1mcArZx_t3YkBL4lTA xen/inclu
    2.74  41c0c412lQ0NVVN9PsOSznQ-qhOiPA xen/include/asm-x86/vmx_vmcs.h
    2.75  418fbcfe_WliJPToeVM-9VStvym-hw xen/include/asm-x86/x86_32/asm_defns.h
    2.76  3ddb79c2ADvRmdexd9y3AYK9_NTx-Q xen/include/asm-x86/x86_32/current.h
    2.77 +3e20b82fl1jmQiKdLy7fxMcutfpjWA xen/include/asm-x86/x86_32/domain_page.h
    2.78  3ddb79c3mbqEM7QQr3zVq7NiBNhouA xen/include/asm-x86/x86_32/regs.h
    2.79  3e7f358aG11EvMI9VJ4_9hD4LUO7rQ xen/include/asm-x86/x86_32/string.h
    2.80  3ddb79c3M2n1ROZH6xk3HbyN4CPDqg xen/include/asm-x86/x86_32/uaccess.h
    2.81  41bf1717bML6GxpclTWJabiaO5W5vg xen/include/asm-x86/x86_64/asm_defns.h
    2.82  404f1b9ceJeGVaPNIENm2FkK0AgEOQ xen/include/asm-x86/x86_64/current.h
    2.83 -404f1b9fl6AQ_a-T1TDK3fuwTPXmHw xen/include/asm-x86/x86_64/desc.h
    2.84 +41febc4b1aCGLsm0Y0b_82h7lFtrEA xen/include/asm-x86/x86_64/domain_page.h
    2.85  404f1badfXZJZ2sU8sh9PS2EZvd19Q xen/include/asm-x86/x86_64/ldt.h
    2.86  404f1bb86rAXB3aLS1vYdcqpJiEcyg xen/include/asm-x86/x86_64/regs.h
    2.87  40e1966azOJZfNI6Ilthe6Q-T3Hewg xen/include/asm-x86/x86_64/string.h
     3.1 --- a/BitKeeper/etc/logging_ok	Fri Jan 28 14:53:32 2005 +0000
     3.2 +++ b/BitKeeper/etc/logging_ok	Fri Feb 04 14:44:18 2005 +0000
     3.3 @@ -21,6 +21,7 @@ harry@dory.(none)
     3.4  iap10@freefall.cl.cam.ac.uk
     3.5  iap10@labyrinth.cl.cam.ac.uk
     3.6  iap10@nidd.cl.cam.ac.uk
     3.7 +iap10@pb001.cl.cam.ac.uk
     3.8  iap10@pb007.cl.cam.ac.uk
     3.9  iap10@striker.cl.cam.ac.uk
    3.10  iap10@tetris.cl.cam.ac.uk
    3.11 @@ -32,9 +33,11 @@ kaf24@freefall.cl.cam.ac.uk
    3.12  kaf24@labyrinth.cl.cam.ac.uk
    3.13  kaf24@pb001.cl.cam.ac.uk
    3.14  kaf24@penguin.local
    3.15 +kaf24@planb.cl.cam.ac.uk
    3.16  kaf24@plym.cl.cam.ac.uk
    3.17  kaf24@scramble.cl.cam.ac.uk
    3.18  kaf24@striker.cl.cam.ac.uk
    3.19 +kaf24@viper.(none)
    3.20  laudney@eclipse.(none)
    3.21  lynx@idefix.cl.cam.ac.uk
    3.22  mafetter@fleming.research
     4.1 --- a/buildconfigs/mk.linux-2.6-xen0	Fri Jan 28 14:53:32 2005 +0000
     4.2 +++ b/buildconfigs/mk.linux-2.6-xen0	Fri Feb 04 14:44:18 2005 +0000
     4.3 @@ -34,7 +34,7 @@ build: $(LINUX_DIR)/include/linux/autoco
     4.4  	  cp $(DESTDIR)/boot/config-$(FULLVERSION) $(LINUX_DIR)/.config \
     4.5  	  || cp $(LINUX_DIR)/arch/xen/configs/$(EXTRAVERSION)_defconfig \
     4.6  		$(LINUX_DIR)/.config
     4.7 -	make -C $(LINUX_DIR) ARCH=xen oldconfig
     4.8 +	$(MAKE) -C $(LINUX_DIR) ARCH=xen oldconfig
     4.9  
    4.10  clean:
    4.11  	$(MAKE) -C $(LINUX_DIR) ARCH=xen clean
     5.1 --- a/buildconfigs/mk.linux-2.6-xenU	Fri Jan 28 14:53:32 2005 +0000
     5.2 +++ b/buildconfigs/mk.linux-2.6-xenU	Fri Feb 04 14:44:18 2005 +0000
     5.3 @@ -34,7 +34,7 @@ build: $(LINUX_DIR)/include/linux/autoco
     5.4  	  cp $(DESTDIR)/boot/config-$(FULLVERSION) $(LINUX_DIR)/.config \
     5.5  	  || cp $(LINUX_DIR)/arch/xen/configs/$(EXTRAVERSION)_defconfig \
     5.6  		$(LINUX_DIR)/.config
     5.7 -	make -C $(LINUX_DIR) ARCH=xen oldconfig
     5.8 +	$(MAKE) -C $(LINUX_DIR) ARCH=xen oldconfig
     5.9  
    5.10  clean:
    5.11  	$(MAKE) -C $(LINUX_DIR) ARCH=xen clean
     6.1 --- a/linux-2.6.10-xen-sparse/arch/xen/configs/xen0_defconfig	Fri Jan 28 14:53:32 2005 +0000
     6.2 +++ b/linux-2.6.10-xen-sparse/arch/xen/configs/xen0_defconfig	Fri Feb 04 14:44:18 2005 +0000
     6.3 @@ -501,7 +501,7 @@ CONFIG_IP_NF_FTP=m
     6.4  # CONFIG_IP_NF_QUEUE is not set
     6.5  CONFIG_IP_NF_IPTABLES=m
     6.6  # CONFIG_IP_NF_MATCH_LIMIT is not set
     6.7 -# CONFIG_IP_NF_MATCH_IPRANGE is not set
     6.8 +CONFIG_IP_NF_MATCH_IPRANGE=m
     6.9  # CONFIG_IP_NF_MATCH_MAC is not set
    6.10  # CONFIG_IP_NF_MATCH_PKTTYPE is not set
    6.11  # CONFIG_IP_NF_MATCH_MARK is not set
    6.12 @@ -524,11 +524,20 @@ CONFIG_IP_NF_IPTABLES=m
    6.13  # CONFIG_IP_NF_MATCH_SCTP is not set
    6.14  # CONFIG_IP_NF_MATCH_COMMENT is not set
    6.15  # CONFIG_IP_NF_MATCH_HASHLIMIT is not set
    6.16 -# CONFIG_IP_NF_FILTER is not set
    6.17 +CONFIG_IP_NF_FILTER=m
    6.18 +CONFIG_IP_NF_TARGET_REJECT=m
    6.19  # CONFIG_IP_NF_TARGET_LOG is not set
    6.20  # CONFIG_IP_NF_TARGET_ULOG is not set
    6.21  # CONFIG_IP_NF_TARGET_TCPMSS is not set
    6.22 -# CONFIG_IP_NF_NAT is not set
    6.23 +CONFIG_IP_NF_NAT=m
    6.24 +CONFIG_IP_NF_NAT_NEEDED=y
    6.25 +CONFIG_IP_NF_TARGET_MASQUERADE=m
    6.26 +# CONFIG_IP_NF_TARGET_REDIRECT is not set
    6.27 +# CONFIG_IP_NF_TARGET_NETMAP is not set
    6.28 +# CONFIG_IP_NF_TARGET_SAME is not set
    6.29 +# CONFIG_IP_NF_NAT_LOCAL is not set
    6.30 +# CONFIG_IP_NF_NAT_SNMP_BASIC is not set
    6.31 +CONFIG_IP_NF_NAT_FTP=m
    6.32  # CONFIG_IP_NF_MANGLE is not set
    6.33  # CONFIG_IP_NF_RAW is not set
    6.34  # CONFIG_IP_NF_ARPTABLES is not set
     7.1 --- a/linux-2.6.10-xen-sparse/arch/xen/i386/Makefile	Fri Jan 28 14:53:32 2005 +0000
     7.2 +++ b/linux-2.6.10-xen-sparse/arch/xen/i386/Makefile	Fri Feb 04 14:44:18 2005 +0000
     7.3 @@ -21,6 +21,9 @@ LDFLAGS		:= -m elf_i386
     7.4  LDFLAGS_vmlinux :=
     7.5  CHECK		:= $(CHECK) -D__i386__=1
     7.6  
     7.7 +CFLAGS += -m32
     7.8 +AFLAGS += -m32
     7.9 +
    7.10  CFLAGS += -pipe -msoft-float
    7.11  
    7.12  # prevent gcc from keeping the stack 16 byte aligned
     8.1 --- a/linux-2.6.10-xen-sparse/arch/xen/i386/kernel/Makefile	Fri Jan 28 14:53:32 2005 +0000
     8.2 +++ b/linux-2.6.10-xen-sparse/arch/xen/i386/kernel/Makefile	Fri Feb 04 14:44:18 2005 +0000
     8.3 @@ -55,7 +55,7 @@ targets += $(foreach F,int80 sysenter,vs
     8.4  
     8.5  # The DSO images are built using a special linker script.
     8.6  quiet_cmd_syscall = SYSCALL $@
     8.7 -      cmd_syscall = $(CC) -nostdlib $(SYSCFLAGS_$(@F)) \
     8.8 +      cmd_syscall = $(CC) -nostdlib -m32 $(SYSCFLAGS_$(@F)) \
     8.9  		          -Wl,-T,$(filter-out FORCE,$^) -o $@
    8.10  
    8.11  vsyscall-flags = -shared -s -Wl,-soname=linux-gate.so.1
     9.1 --- a/linux-2.6.10-xen-sparse/arch/xen/i386/kernel/setup.c	Fri Jan 28 14:53:32 2005 +0000
     9.2 +++ b/linux-2.6.10-xen-sparse/arch/xen/i386/kernel/setup.c	Fri Feb 04 14:44:18 2005 +0000
     9.3 @@ -1492,6 +1492,10 @@ void __init setup_arch(char **cmdline_p)
     9.4  		get_smp_config();
     9.5  #endif
     9.6  
     9.7 +	/* XXX Disable irqdebug until we have a way to avoid interrupt
     9.8 +	 * conflicts. */
     9.9 +	noirqdebug_setup("");
    9.10 +
    9.11  	register_memory(max_low_pfn);
    9.12  
    9.13  	/* If we are a privileged guest OS then we should request IO privs. */
    10.1 --- a/linux-2.6.10-xen-sparse/arch/xen/i386/mm/ioremap.c	Fri Jan 28 14:53:32 2005 +0000
    10.2 +++ b/linux-2.6.10-xen-sparse/arch/xen/i386/mm/ioremap.c	Fri Feb 04 14:44:18 2005 +0000
    10.3 @@ -79,6 +79,7 @@ void __iomem * __ioremap(unsigned long p
    10.4  	void __iomem * addr;
    10.5  	struct vm_struct * area;
    10.6  	unsigned long offset, last_addr;
    10.7 +	domid_t domid = DOMID_IO;
    10.8  
    10.9  	/* Don't allow wraparound or zero size */
   10.10  	last_addr = phys_addr + size - 1;
   10.11 @@ -106,6 +107,8 @@ void __iomem * __ioremap(unsigned long p
   10.12  		for(page = virt_to_page(t_addr); page <= virt_to_page(t_end); page++)
   10.13  			if(!PageReserved(page))
   10.14  				return NULL;
   10.15 +
   10.16 +		domid = DOMID_LOCAL;
   10.17  	}
   10.18  
   10.19  	/*
   10.20 @@ -382,10 +385,13 @@ int direct_remap_area_pages(struct mm_st
   10.21  #define MAX_DIRECTMAP_MMU_QUEUE 130
   10.22  	mmu_update_t u[MAX_DIRECTMAP_MMU_QUEUE], *w, *v;
   10.23  
   10.24 -	u[0].ptr  = MMU_EXTENDED_COMMAND;
   10.25 -	u[0].val  = MMUEXT_SET_FOREIGNDOM;
   10.26 -	u[0].val |= (unsigned long)domid << 16;
   10.27 -	v = w = &u[1];
   10.28 +	v = w = &u[0];
   10.29 +	if (domid != DOMID_LOCAL) {
   10.30 +		u[0].ptr  = MMU_EXTENDED_COMMAND;
   10.31 +		u[0].val  = MMUEXT_SET_FOREIGNDOM;
   10.32 +		u[0].val |= (unsigned long)domid << 16;
   10.33 +		v = w = &u[1];
   10.34 +	}
   10.35  
   10.36  	start_address = address;
   10.37  
    11.1 --- a/linux-2.6.10-xen-sparse/drivers/xen/blkfront/blkfront.c	Fri Jan 28 14:53:32 2005 +0000
    11.2 +++ b/linux-2.6.10-xen-sparse/drivers/xen/blkfront/blkfront.c	Fri Feb 04 14:44:18 2005 +0000
    11.3 @@ -218,6 +218,7 @@ int blkif_release(struct inode *inode, s
    11.4  int blkif_ioctl(struct inode *inode, struct file *filep,
    11.5                  unsigned command, unsigned long argument)
    11.6  {
    11.7 +	int i;
    11.8      /*  struct gendisk *gd = inode->i_bdev->bd_disk; */
    11.9  
   11.10      DPRINTK_IOCTL("command: 0x%x, argument: 0x%lx, dev: 0x%04x\n",
   11.11 @@ -229,6 +230,12 @@ int blkif_ioctl(struct inode *inode, str
   11.12          /* return ENOSYS to use defaults */
   11.13          return -ENOSYS;
   11.14  
   11.15 +    case CDROMMULTISESSION:
   11.16 +        DPRINTK("FIXME: support multisession CDs later\n");
   11.17 +        for ( i = 0; i < sizeof(struct cdrom_multisession); i++ )
   11.18 +            if ( put_user(0, (byte *)(argument + i)) ) return -EFAULT;
   11.19 +        return 0;
   11.20 +
   11.21      default:
   11.22          printk(KERN_ALERT "ioctl %08x not supported by Xen blkdev\n",
   11.23                 command);
    12.1 --- a/linux-2.6.10-xen-sparse/drivers/xen/blkfront/vbd.c	Fri Jan 28 14:53:32 2005 +0000
    12.2 +++ b/linux-2.6.10-xen-sparse/drivers/xen/blkfront/vbd.c	Fri Feb 04 14:44:18 2005 +0000
    12.3 @@ -317,7 +317,7 @@ static int xlvbd_init_device(vdisk_t *xd
    12.4      down(&bd->bd_sem);
    12.5  
    12.6      gd = xlvbd_get_gendisk(mi, minor, xd);
    12.7 -    if (mi == NULL) {
    12.8 +    if (gd == NULL) {
    12.9          err = -EPERM;
   12.10          goto out;
   12.11      }
    13.1 --- a/linux-2.6.10-xen-sparse/drivers/xen/netback/common.h	Fri Jan 28 14:53:32 2005 +0000
    13.2 +++ b/linux-2.6.10-xen-sparse/drivers/xen/netback/common.h	Fri Feb 04 14:44:18 2005 +0000
    13.3 @@ -35,6 +35,8 @@ typedef struct netif_st {
    13.4      domid_t          domid;
    13.5      unsigned int     handle;
    13.6  
    13.7 +    u8               fe_dev_addr[6];
    13.8 +
    13.9      /* Physical parameters of the comms window. */
   13.10      unsigned long    tx_shmem_frame;
   13.11      unsigned long    rx_shmem_frame;
    14.1 --- a/linux-2.6.10-xen-sparse/drivers/xen/netback/interface.c	Fri Jan 28 14:53:32 2005 +0000
    14.2 +++ b/linux-2.6.10-xen-sparse/drivers/xen/netback/interface.c	Fri Feb 04 14:44:18 2005 +0000
    14.3 @@ -163,13 +163,24 @@ void netif_create(netif_be_create_t *cre
    14.4      /* Disable queuing. */
    14.5      dev->tx_queue_len = 0;
    14.6  
    14.7 -    /*
    14.8 -     * Initialise a dummy MAC address. We choose the numerically largest
    14.9 -     * non-broadcast address to prevent the address getting stolen by an 
   14.10 -     * Ethernet bridge for STP purposes. (FE:FF:FF:FF:FF:FF)
   14.11 -     */
   14.12 -    memset(dev->dev_addr, 0xFF, ETH_ALEN);
   14.13 -    dev->dev_addr[0] &= ~0x01;
   14.14 +    if ( (create->be_mac[0] == 0) && (create->be_mac[1] == 0) &&
   14.15 +         (create->be_mac[2] == 0) && (create->be_mac[3] == 0) &&
   14.16 +         (create->be_mac[4] == 0) && (create->be_mac[5] == 0) )
   14.17 +    {
   14.18 +        /*
   14.19 +         * Initialise a dummy MAC address. We choose the numerically largest
   14.20 +         * non-broadcast address to prevent the address getting stolen by an
   14.21 +         * Ethernet bridge for STP purposes. (FE:FF:FF:FF:FF:FF)
   14.22 +         */ 
   14.23 +        memset(dev->dev_addr, 0xFF, ETH_ALEN);
   14.24 +        dev->dev_addr[0] &= ~0x01;
   14.25 +    }
   14.26 +    else
   14.27 +    {
   14.28 +        memcpy(dev->dev_addr, create->be_mac, ETH_ALEN);
   14.29 +    }
   14.30 +
   14.31 +    memcpy(netif->fe_dev_addr, create->mac, ETH_ALEN);
   14.32  
   14.33      rtnl_lock();
   14.34      err = register_netdevice(dev);
    15.1 --- a/linux-2.6.10-xen-sparse/drivers/xen/privcmd/privcmd.c	Fri Jan 28 14:53:32 2005 +0000
    15.2 +++ b/linux-2.6.10-xen-sparse/drivers/xen/privcmd/privcmd.c	Fri Feb 04 14:44:18 2005 +0000
    15.3 @@ -174,13 +174,11 @@ static int privcmd_ioctl(struct inode *i
    15.4  
    15.5      case IOCTL_PRIVCMD_GET_MACH2PHYS_START_MFN:
    15.6      {
    15.7 -	unsigned long m2p_start_mfn = 
    15.8 -	    HYPERVISOR_shared_info->arch.mfn_to_pfn_start;
    15.9 -
   15.10 -	if( put_user( m2p_start_mfn, (unsigned long *) data ) )
   15.11 -	    ret = -EFAULT;
   15.12 -	else
   15.13 -	    ret = 0;
   15.14 +        unsigned long m2pv = (unsigned long)machine_to_phys_mapping;
   15.15 +        pgd_t *pgd = pgd_offset_k(m2pv);
   15.16 +        pmd_t *pmd = pmd_offset(pgd, m2pv);
   15.17 +        unsigned long m2p_start_mfn = pmd_val(*pmd) >> PAGE_SHIFT;
   15.18 +        ret = put_user(m2p_start_mfn, (unsigned long *)data) ? -EFAULT: 0;
   15.19      }
   15.20      break;
   15.21  
    16.1 --- a/linux-2.6.10-xen-sparse/drivers/xen/usbback/usbback.c	Fri Jan 28 14:53:32 2005 +0000
    16.2 +++ b/linux-2.6.10-xen-sparse/drivers/xen/usbback/usbback.c	Fri Feb 04 14:44:18 2005 +0000
    16.3 @@ -4,7 +4,9 @@
    16.4   * Backend for the Xen virtual USB driver - provides an abstraction of a
    16.5   * USB host controller to the corresponding frontend driver.
    16.6   *
    16.7 - * by Mark Williamson, Copyright (c) 2004 Intel Research Cambridge
    16.8 + * by Mark Williamson
    16.9 + * Copyright (c) 2004 Intel Research Cambridge
   16.10 + * Copyright (c) 2004, 2005 Mark Williamson
   16.11   *
   16.12   * Based on arch/xen/drivers/blkif/backend/main.c
   16.13   * Copyright (c) 2003-2004, Keir Fraser & Steve Hand
   16.14 @@ -39,7 +41,6 @@ static unsigned long mmap_vstart;
   16.15       ((_req) * MMAP_PAGES_PER_REQUEST * PAGE_SIZE) + \
   16.16       ((_seg) * PAGE_SIZE))
   16.17  
   16.18 -#define MIN(x,y) ( ( x < y ) ? x : y )
   16.19  
   16.20  static spinlock_t owned_ports_lock;
   16.21  LIST_HEAD(owned_ports);
   16.22 @@ -83,7 +84,7 @@ typedef struct {
   16.23   */
   16.24  static pending_req_t pending_reqs[MAX_PENDING_REQS];
   16.25  static unsigned char pending_ring[MAX_PENDING_REQS];
   16.26 -static spinlock_t pend_prod_lock = SPIN_LOCK_UNLOCKED;
   16.27 +static spinlock_t pend_prod_lock;
   16.28  
   16.29  /* NB. We use a different index type to differentiate from shared blk rings. */
   16.30  typedef unsigned int PEND_RING_IDX;
   16.31 @@ -100,20 +101,87 @@ static void dispatch_usb_io(usbif_priv_t
   16.32  static void dispatch_usb_reset(usbif_priv_t *up, unsigned long portid);
   16.33  static owned_port_t *usbif_find_port(char *);
   16.34  
   16.35 +/******************************************************************
   16.36 + * PRIVATE DEBUG FUNCTIONS
   16.37 + */
   16.38  
   16.39 -void dump_port(owned_port_t *p)
   16.40 +#undef DEBUG
   16.41 +#ifdef DEBUG
   16.42 +
   16.43 +static void dump_port(owned_port_t *p)
   16.44  {
   16.45 -    printk("owned_port_t @ %p\n", p);
   16.46 -    printk("  usbif_priv @ %p\n", p->usbif_priv);
   16.47 -    printk("  path: %s\n", p->path);
   16.48 -    printk("  guest_port: %d\n", p->guest_port);
   16.49 -    printk("  guest_address: %ld\n", p->guest_address);
   16.50 -    printk("  dev_present: %d\n", p->dev_present);
   16.51 -    printk("  dev @ %p\n", p->dev);
   16.52 -    printk("  ifaces: 0x%lx\n", p->ifaces);
   16.53 +    printk(KERN_DEBUG "owned_port_t @ %p\n"
   16.54 +	   "  usbif_priv @ %p\n"
   16.55 +	   "  path: %s\n"
   16.56 +	   "  guest_port: %d\n"
   16.57 +	   "  guest_address: %ld\n"
   16.58 +	   "  dev_present: %d\n"
   16.59 +	   "  dev @ %p\n"
   16.60 +	   "  ifaces: 0x%lx\n",
   16.61 +	   p, p->usbif_priv, p->path, p->guest_port, p->guest_address,
   16.62 +	   p->dev_present, p->dev, p->ifaces);
   16.63  }
   16.64  
   16.65  
   16.66 +static void dump_request(usbif_request_t *req)
   16.67 +{    
   16.68 +    printk(KERN_DEBUG "id = 0x%lx\n"
   16.69 +	   "devnum %d\n"
   16.70 +	   "endpoint 0x%x\n"
   16.71 +	   "direction %d\n"
   16.72 +	   "speed %d\n"
   16.73 +	   "pipe_type 0x%x\n"
   16.74 +	   "transfer_buffer 0x%lx\n"
   16.75 +	   "length 0x%lx\n"
   16.76 +	   "transfer_flags 0x%lx\n"
   16.77 +	   "setup = { 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x }\n"
   16.78 +	   "iso_schedule = 0x%lx\n"
   16.79 +	   "num_iso %ld\n",
   16.80 +	   req->id, req->devnum, req->endpoint, req->direction, req->speed,
   16.81 +	   req->pipe_type, req->transfer_buffer, req->length,
   16.82 +	   req->transfer_flags, req->setup[0], req->setup[1], req->setup[2],
   16.83 +	   req->setup[3], req->setup[4], req->setup[5], req->setup[6],
   16.84 +	   req->setup[7], req->iso_schedule, req->num_iso);
   16.85 +}
   16.86 +
   16.87 +static void dump_urb(struct urb *urb)
   16.88 +{
   16.89 +    printk(KERN_DEBUG "dumping urb @ %p\n", urb);
   16.90 +
   16.91 +#define DUMP_URB_FIELD(name, format) \
   16.92 +    printk(KERN_DEBUG "  " # name " " format "\n", urb-> name)
   16.93 +    
   16.94 +    DUMP_URB_FIELD(pipe, "0x%x");
   16.95 +    DUMP_URB_FIELD(status, "%d");
   16.96 +    DUMP_URB_FIELD(transfer_flags, "0x%x");    
   16.97 +    DUMP_URB_FIELD(transfer_buffer, "%p");
   16.98 +    DUMP_URB_FIELD(transfer_buffer_length, "%d");
   16.99 +    DUMP_URB_FIELD(actual_length, "%d");
  16.100 +}
  16.101 +
  16.102 +static void dump_response(usbif_response_t *resp)
  16.103 +{
  16.104 +    printk(KERN_DEBUG "usbback: Sending response:\n"
  16.105 +	   "         id = 0x%x\n"
  16.106 +	   "         op = %d\n"
  16.107 +	   "         status = %d\n"
  16.108 +	   "         data = %d\n"
  16.109 +	   "         length = %d\n",
  16.110 +	   resp->id, resp->op, resp->status, resp->data, resp->length);
  16.111 +}
  16.112 +
  16.113 +#else /* DEBUG */
  16.114 +
  16.115 +#define dump_port(blah)     ((void)0)
  16.116 +#define dump_request(blah)   ((void)0)
  16.117 +#define dump_urb(blah)      ((void)0)
  16.118 +#define dump_response(blah) ((void)0)
  16.119 +
  16.120 +#endif /* DEBUG */
  16.121 +
  16.122 +/******************************************************************
  16.123 + * MEMORY MANAGEMENT
  16.124 + */
  16.125  
  16.126  static void fast_flush_area(int idx, int nr_pages)
  16.127  {
  16.128 @@ -173,6 +241,15 @@ static void add_to_usbif_list_tail(usbif
  16.129      spin_unlock_irqrestore(&usbio_schedule_list_lock, flags);
  16.130  }
  16.131  
  16.132 +void free_pending(int pending_idx)
  16.133 +{
  16.134 +    unsigned long flags;
  16.135 +
  16.136 +    /* Free the pending request. */
  16.137 +    spin_lock_irqsave(&pend_prod_lock, flags);
  16.138 +    pending_ring[MASK_PEND_IDX(pending_prod++)] = pending_idx;
  16.139 +    spin_unlock_irqrestore(&pend_prod_lock, flags);
  16.140 +}
  16.141  
  16.142  /******************************************************************
  16.143   * COMPLETION CALLBACK -- Called as urb->complete()
  16.144 @@ -182,17 +259,11 @@ static void maybe_trigger_usbio_schedule
  16.145  
  16.146  static void __end_usb_io_op(struct urb *purb)
  16.147  {
  16.148 -    unsigned long flags;
  16.149      pending_req_t *pending_req;
  16.150      int pending_idx;
  16.151  
  16.152      pending_req = purb->context;
  16.153  
  16.154 -/*     printk("Completed for id = %p to 0x%lx - 0x%lx\n", pending_req->id, */
  16.155 -/*            virt_to_machine(purb->transfer_buffer), */
  16.156 -/*            virt_to_machine(purb->transfer_buffer) */
  16.157 -/*            + pending_req->nr_pages * PAGE_SIZE); */
  16.158 -
  16.159      pending_idx = pending_req - pending_reqs;
  16.160  
  16.161      ASSERT(purb->actual_length <= purb->transfer_buffer_length);
  16.162 @@ -201,7 +272,7 @@ static void __end_usb_io_op(struct urb *
  16.163      /* An error fails the entire request. */
  16.164      if ( purb->status )
  16.165      {
  16.166 -        printk("URB @ %p failed. Status %d\n", purb, purb->status);
  16.167 +        printk(KERN_WARNING "URB @ %p failed. Status %d\n", purb, purb->status);
  16.168      }
  16.169  
  16.170      if ( usb_pipetype(purb->pipe) == 0 )
  16.171 @@ -211,8 +282,6 @@ static void __end_usb_io_op(struct urb *
  16.172  
  16.173          ASSERT(sched == pending_req->sched);
  16.174  
  16.175 -	//	printk("writing back schedule at %p\n", sched);
  16.176 -
  16.177          /* If we're dealing with an iso pipe, we need to copy back the schedule. */
  16.178          for ( i = 0; i < purb->number_of_packets; i++ )
  16.179          {
  16.180 @@ -223,24 +292,18 @@ static void __end_usb_io_op(struct urb *
  16.181          }
  16.182      }
  16.183      
  16.184 -    //    printk("Flushing %d pages\n", pending_req->nr_pages);
  16.185      fast_flush_area(pending_req - pending_reqs, pending_req->nr_pages);
  16.186  
  16.187      kfree(purb->setup_packet);
  16.188  
  16.189 -    spin_lock_irqsave(&pending_req->usbif_priv->usb_ring_lock, flags);
  16.190      make_response(pending_req->usbif_priv, pending_req->id,
  16.191  		  pending_req->operation, pending_req->status, 0, purb->actual_length);
  16.192 -    spin_unlock_irqrestore(&pending_req->usbif_priv->usb_ring_lock, flags);
  16.193      usbif_put(pending_req->usbif_priv);
  16.194  
  16.195      usb_free_urb(purb);
  16.196  
  16.197 -    /* Free the pending request. */
  16.198 -    spin_lock_irqsave(&pend_prod_lock, flags);
  16.199 -    pending_ring[MASK_PEND_IDX(pending_prod++)] = pending_idx;
  16.200 -    spin_unlock_irqrestore(&pend_prod_lock, flags);
  16.201 -
  16.202 +    free_pending(pending_idx);
  16.203 +    
  16.204      rmb();
  16.205  
  16.206      /* Check for anything still waiting in the rings, having freed a request... */
  16.207 @@ -332,9 +395,6 @@ static int do_usb_io_op(usbif_priv_t *up
  16.208      usbif_request_t *req;
  16.209      USBIF_RING_IDX i, rp;
  16.210      int more_to_do = 0;
  16.211 -    unsigned long flags;
  16.212 -
  16.213 -    spin_lock_irqsave(&up->usb_ring_lock, flags);
  16.214  
  16.215      rp = usb_ring->req_prod;
  16.216      rmb(); /* Ensure we see queued requests up to 'rp'. */
  16.217 @@ -377,8 +437,6 @@ static int do_usb_io_op(usbif_priv_t *up
  16.218  
  16.219      up->usb_req_cons = i;
  16.220  
  16.221 -    spin_unlock_irqrestore(&up->usb_ring_lock, flags);
  16.222 -
  16.223      return more_to_do;
  16.224  }
  16.225  
  16.226 @@ -412,11 +470,7 @@ static void dispatch_usb_reset(usbif_pri
  16.227       * than it's worth.  We just fake it out in software but we will do a real
  16.228       * reset when the interface is destroyed. */
  16.229  
  16.230 -#if 0
  16.231 -    printk("Reset port %d\n", portid);
  16.232 -
  16.233      dump_port(port);
  16.234 -#endif
  16.235  
  16.236      port->guest_address = 0;
  16.237      /* If there's an attached device then the port is now enabled. */
  16.238 @@ -438,8 +492,8 @@ static void dispatch_usb_probe(usbif_pri
  16.239      else
  16.240      {
  16.241          ret = -EINVAL;
  16.242 -        printk("dispatch_usb_probe(): invalid port probe request (port %ld)\n",
  16.243 -	       portid);
  16.244 +        printk(KERN_INFO "dispatch_usb_probe(): invalid port probe request "
  16.245 +	       "(port %ld)\n", portid);
  16.246      }
  16.247  
  16.248      /* Probe result is sent back in-band.  Probes don't have an associated id
  16.249 @@ -449,40 +503,6 @@ static void dispatch_usb_probe(usbif_pri
  16.250  
  16.251  owned_port_t *find_port_for_request(usbif_priv_t *up, usbif_request_t *req);
  16.252  
  16.253 -static void dump_request(usbif_request_t *req)
  16.254 -{    
  16.255 -    printk("id = 0x%lx\n", req->id);
  16.256 -    
  16.257 -	printk("devnum %d\n", req->devnum);
  16.258 -	printk("endpoint 0x%x\n", req->endpoint);
  16.259 -	printk("direction %d\n", req->direction);
  16.260 -	printk("speed %d\n", req->speed);
  16.261 -        printk("pipe_type 0x%x\n", req->pipe_type);
  16.262 -        printk("transfer_buffer 0x%lx\n", req->transfer_buffer);
  16.263 -        printk("length 0x%lx\n", req->length);
  16.264 -        printk("transfer_flags 0x%lx\n", req->transfer_flags);
  16.265 -        printk("setup = { 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n",
  16.266 -               req->setup[0], req->setup[1], req->setup[2], req->setup[3],
  16.267 -               req->setup[4], req->setup[5], req->setup[6], req->setup[7]);
  16.268 -        printk("iso_schedule = 0x%lx\n", req->iso_schedule);
  16.269 -        printk("num_iso %ld\n", req->num_iso);
  16.270 -}
  16.271 -
  16.272 -void dump_urb(struct urb *urb)
  16.273 -{
  16.274 -    printk("dumping urb @ %p\n", urb);
  16.275 -
  16.276 -#define DUMP_URB_FIELD(name, format) printk("  " # name " " format "\n", urb-> name)
  16.277 -    
  16.278 -    DUMP_URB_FIELD(pipe, "0x%x");
  16.279 -    DUMP_URB_FIELD(status, "%d");
  16.280 -    DUMP_URB_FIELD(transfer_flags, "0x%x");    
  16.281 -    DUMP_URB_FIELD(transfer_buffer, "%p");
  16.282 -    DUMP_URB_FIELD(transfer_buffer_length, "%d");
  16.283 -    DUMP_URB_FIELD(actual_length, "%d");
  16.284 -}
  16.285 -
  16.286 -
  16.287  static void dispatch_usb_io(usbif_priv_t *up, usbif_request_t *req)
  16.288  {
  16.289      unsigned long buffer_mach;
  16.290 @@ -495,27 +515,36 @@ static void dispatch_usb_io(usbif_priv_t
  16.291      owned_port_t *port;
  16.292      unsigned char *setup;    
  16.293  
  16.294 -//    dump_request(req);
  16.295 +    dump_request(req);
  16.296  
  16.297      if ( NR_PENDING_REQS == MAX_PENDING_REQS )
  16.298      {
  16.299 -        printk("usbback: Max requests already queued.  Now giving up!\n");
  16.300 +        printk(KERN_WARNING "usbback: Max requests already queued. "
  16.301 +	       "Giving up!\n");
  16.302          
  16.303          return;
  16.304      }
  16.305  
  16.306      port = find_port_for_request(up, req);
  16.307  
  16.308 -    if(port == NULL)
  16.309 +    if ( port == NULL )
  16.310      {
  16.311 -	printk("No such device! (%d)\n", req->devnum);
  16.312 +	printk(KERN_WARNING "No such device! (%d)\n", req->devnum);
  16.313  	dump_request(req);
  16.314  
  16.315          make_response(up, req->id, req->operation, -ENODEV, 0, 0);
  16.316  	return;
  16.317      }
  16.318 +    else if ( !port->dev_present )
  16.319 +    {
  16.320 +        /* In normal operation, we'll only get here if a device is unplugged
  16.321 +         * and the frontend hasn't noticed yet. */
  16.322 +        make_response(up, req->id, req->operation, -ENODEV, 0, 0);
  16.323 +	return;
  16.324 +    }
  16.325 +        
  16.326  
  16.327 -    setup = kmalloc(8, GFP_ATOMIC | GFP_NOIO);
  16.328 +    setup = kmalloc(8, GFP_KERNEL);
  16.329  
  16.330      if ( setup == NULL )
  16.331          goto no_mem;
  16.332 @@ -549,7 +578,10 @@ static void dispatch_usb_io(usbif_priv_t
  16.333           * because various error checks get confused otherwise.  We just do
  16.334           * configuration settings here, under controlled conditions.
  16.335           */
  16.336 -        usb_set_configuration(port->dev, setup[2]);
  16.337 +
  16.338 +      /* Ignore configuration setting and hope that the host kernel
  16.339 +	 did it right. */
  16.340 +        /* usb_set_configuration(port->dev, setup[2]); */
  16.341  
  16.342          make_response(up, req->id, req->operation, 0, 0, 0);
  16.343  
  16.344 @@ -576,7 +608,8 @@ static void dispatch_usb_io(usbif_priv_t
  16.345  	   + req->length )
  16.346  	 > MMAP_PAGES_PER_REQUEST * PAGE_SIZE )
  16.347      {
  16.348 -        printk("usbback: request of %d bytes too large, failing it\n", req->length);
  16.349 +        printk(KERN_WARNING "usbback: request of %lu bytes too large\n",
  16.350 +	       req->length);
  16.351          make_response(up, req->id, req->operation, -EINVAL, 0, 0);
  16.352          kfree(setup);
  16.353          return;
  16.354 @@ -596,8 +629,6 @@ static void dispatch_usb_io(usbif_priv_t
  16.355      for ( i = 0, offset = 0; offset < req->length;
  16.356            i++, offset += PAGE_SIZE )
  16.357      {
  16.358 -      //        printk("length = %d, offset = %d, looping!\n", req->length, offset);
  16.359 -        
  16.360  	mcl[i].op = __HYPERVISOR_update_va_mapping_otherdomain;
  16.361  	mcl[i].args[0] = MMAP_VADDR(pending_idx, i) >> PAGE_SHIFT;
  16.362          mcl[i].args[1] = ((buffer_mach & PAGE_MASK) + offset) | remap_prot;
  16.363 @@ -606,7 +637,6 @@ static void dispatch_usb_io(usbif_priv_t
  16.364          
  16.365          phys_to_machine_mapping[__pa(MMAP_VADDR(pending_idx, i))>>PAGE_SHIFT] =
  16.366              FOREIGN_FRAME((buffer_mach + offset) >> PAGE_SHIFT);
  16.367 -	//	printk("i = %d\n", i);
  16.368  
  16.369          ASSERT(virt_to_machine(MMAP_VADDR(pending_idx, i))
  16.370                 == buffer_mach + i << PAGE_SHIFT);
  16.371 @@ -614,7 +644,6 @@ static void dispatch_usb_io(usbif_priv_t
  16.372  
  16.373      if ( req->pipe_type == 0 && req->num_iso > 0 ) /* Maybe schedule ISO... */
  16.374      {
  16.375 -      //      printk("for iso, i = %d\n", i);
  16.376          /* Map in ISO schedule, if necessary. */
  16.377          mcl[i].op = __HYPERVISOR_update_va_mapping_otherdomain;
  16.378          mcl[i].args[0] = MMAP_VADDR(pending_idx, i) >> PAGE_SHIFT;
  16.379 @@ -625,12 +654,9 @@ static void dispatch_usb_io(usbif_priv_t
  16.380          phys_to_machine_mapping[__pa(MMAP_VADDR(pending_idx, i))>>PAGE_SHIFT] =
  16.381              FOREIGN_FRAME(req->iso_schedule >> PAGE_SHIFT);
  16.382      
  16.383 -        //    printk("Mapped iso at %p\n", MMAP_VADDR(pending_idx, i));
  16.384          i++;
  16.385      }
  16.386  
  16.387 -    //    printk("Well we got this far!\n");
  16.388 -
  16.389      if ( unlikely(HYPERVISOR_multicall(mcl, i) != 0) )
  16.390          BUG();
  16.391      
  16.392 @@ -640,9 +666,9 @@ static void dispatch_usb_io(usbif_priv_t
  16.393          {
  16.394              if ( unlikely(mcl[j].args[5] != 0) )
  16.395              {
  16.396 -                printk("invalid buffer %d -- could not remap it\n", j);
  16.397 +                printk(KERN_WARNING
  16.398 +		       "invalid buffer %d -- could not remap it\n", j);
  16.399                  fast_flush_area(pending_idx, i);
  16.400 -		printk("sending invalid descriptor\n");
  16.401                  goto bad_descriptor;
  16.402              }
  16.403  	}
  16.404 @@ -660,8 +686,6 @@ static void dispatch_usb_io(usbif_priv_t
  16.405      pending_req->operation = req->operation;
  16.406      pending_req->nr_pages  = i;
  16.407  
  16.408 -
  16.409 -
  16.410      pending_cons++;
  16.411  
  16.412      usbif_get(up);
  16.413 @@ -670,20 +694,22 @@ static void dispatch_usb_io(usbif_priv_t
  16.414      purb = usb_alloc_urb(req->num_iso);
  16.415  
  16.416      if ( purb == NULL )
  16.417 +    {
  16.418 +        usbif_put(up);
  16.419 +        free_pending(pending_idx);
  16.420          goto no_mem;
  16.421 +    }
  16.422  
  16.423      purb->dev = port->dev;
  16.424      purb->context = pending_req;
  16.425 -    purb->transfer_buffer = (void *)MMAP_VADDR(pending_idx, 0) + (buffer_mach & ~PAGE_MASK);
  16.426 +    purb->transfer_buffer =
  16.427 +        (void *)MMAP_VADDR(pending_idx, 0) + (buffer_mach & ~PAGE_MASK);
  16.428      if(buffer_mach == 0)
  16.429        purb->transfer_buffer = NULL;
  16.430      purb->complete = __end_usb_io_op;
  16.431      purb->transfer_buffer_length = req->length;
  16.432      purb->transfer_flags = req->transfer_flags;
  16.433  
  16.434 -/*     if ( req->transfer_flags != 0 ) */
  16.435 -/*       dump_request(req); */
  16.436 -
  16.437      purb->pipe = 0;
  16.438      purb->pipe |= req->direction << 7;
  16.439      purb->pipe |= port->dev->devnum << 8;
  16.440 @@ -704,8 +730,6 @@ static void dispatch_usb_io(usbif_priv_t
  16.441          int j;
  16.442          usbif_iso_t *iso_sched = (usbif_iso_t *)MMAP_VADDR(pending_idx, i - 1);
  16.443  
  16.444 -	//	printk("Reading iso sched at %p\n", iso_sched);
  16.445 -
  16.446          /* If we're dealing with an iso pipe, we need to copy in a schedule. */
  16.447          for ( j = 0; j < req->num_iso; j++ )
  16.448          {
  16.449 @@ -717,13 +741,17 @@ static void dispatch_usb_io(usbif_priv_t
  16.450      }
  16.451  
  16.452      {
  16.453 -      int ret;
  16.454 -      ret = usb_submit_urb(purb);
  16.455 -
  16.456 -      //      dump_urb(purb);
  16.457 -
  16.458 -      if ( ret != 0 )
  16.459 -          goto bad_descriptor; /* XXX free pending here! */
  16.460 +        int ret;
  16.461 +        ret = usb_submit_urb(purb);
  16.462 +        
  16.463 +        dump_urb(purb);
  16.464 +        
  16.465 +        if ( ret != 0 )
  16.466 +        {
  16.467 +            usbif_put(up);
  16.468 +            free_pending(pending_idx);
  16.469 +            goto bad_descriptor;
  16.470 +        }
  16.471      }
  16.472      
  16.473      return;
  16.474 @@ -756,15 +784,6 @@ static void make_response(usbif_priv_t *
  16.475      usbif_response_t *resp;
  16.476      unsigned long     flags;
  16.477  
  16.478 -#if 0
  16.479 -    printk("usbback: Sending response:\n");
  16.480 -    printk("         id = 0x%x\n", id);
  16.481 -    printk("         op = %d\n", op);
  16.482 -    printk("         status = %d\n", st);
  16.483 -    printk("         data = %d\n", inband);
  16.484 -    printk("         length = %d\n", length);
  16.485 -#endif
  16.486 -
  16.487      /* Place on the response ring for the relevant domain. */ 
  16.488      spin_lock_irqsave(&up->usb_ring_lock, flags);
  16.489      resp = &up->usb_ring_base->
  16.490 @@ -775,6 +794,9 @@ static void make_response(usbif_priv_t *
  16.491      resp->data      = inband;
  16.492      resp->length = length;
  16.493      wmb(); /* Ensure other side can see the response fields. */
  16.494 +
  16.495 +    dump_response(resp);
  16.496 +
  16.497      up->usb_ring_base->resp_prod = ++up->usb_resp_prod;
  16.498      spin_unlock_irqrestore(&up->usb_ring_lock, flags);
  16.499  
  16.500 @@ -795,16 +817,17 @@ int usbif_claim_port(usbif_be_claim_port
  16.501      /* Sanity... */
  16.502      if ( usbif_find_port(msg->path) != NULL )
  16.503      {
  16.504 -        printk("usbback: Attempted to claim USB port "
  16.505 +        printk(KERN_WARNING "usbback: Attempted to claim USB port "
  16.506                 "we already own!\n");
  16.507          return -EINVAL;
  16.508      }
  16.509  
  16.510 -    spin_lock_irq(&owned_ports_lock);
  16.511 -    
  16.512      /* No need for a slab cache - this should be infrequent. */
  16.513      o_p = kmalloc(sizeof(owned_port_t), GFP_KERNEL);
  16.514  
  16.515 +    if ( o_p == NULL )
  16.516 +        return -ENOMEM;
  16.517 +
  16.518      o_p->enabled = 0;
  16.519      o_p->usbif_priv = usbif_find(msg->domid);
  16.520      o_p->guest_port = msg->usbif_port;
  16.521 @@ -813,13 +836,15 @@ int usbif_claim_port(usbif_be_claim_port
  16.522  
  16.523      strcpy(o_p->path, msg->path);
  16.524  
  16.525 +    spin_lock_irq(&owned_ports_lock);
  16.526 +    
  16.527      list_add(&o_p->list, &owned_ports);
  16.528  
  16.529 -    printk("usbback: Claimed USB port (%s) for %d.%d\n", o_p->path,
  16.530 +    spin_unlock_irq(&owned_ports_lock);
  16.531 +
  16.532 +    printk(KERN_INFO "usbback: Claimed USB port (%s) for %d.%d\n", o_p->path,
  16.533  	   msg->domid, msg->usbif_port);
  16.534  
  16.535 -    spin_unlock_irq(&owned_ports_lock);
  16.536 -
  16.537      /* Force a reprobe for unclaimed devices. */
  16.538      usb_scan_devices();
  16.539  
  16.540 @@ -840,11 +865,9 @@ owned_port_t *find_port_for_request(usbi
  16.541          owned_port_t *p = list_entry(port, owned_port_t, list);
  16.542          if(p->usbif_priv == up && p->guest_address == req->devnum && p->enabled )
  16.543  	  {
  16.544 -#if 0
  16.545 -              printk("Found port for devnum %d\n", req->devnum);
  16.546 +              dump_port(p);
  16.547  
  16.548 -              dump_port(p);
  16.549 -#endif
  16.550 +	      spin_unlock_irqrestore(&owned_ports_lock, flags);
  16.551                return p;
  16.552  	  }
  16.553      }
  16.554 @@ -853,29 +876,37 @@ owned_port_t *find_port_for_request(usbi
  16.555      return NULL;    
  16.556  }
  16.557  
  16.558 -owned_port_t *usbif_find_port(char *path)
  16.559 +owned_port_t *__usbif_find_port(char *path)
  16.560  {
  16.561      struct list_head *port;
  16.562 -    unsigned long flags;
  16.563  
  16.564 -    spin_lock_irqsave(&owned_ports_lock, flags);
  16.565      list_for_each(port, &owned_ports)
  16.566      {
  16.567          owned_port_t *p = list_entry(port, owned_port_t, list);
  16.568          if(!strcmp(path, p->path))
  16.569          {
  16.570 -            spin_unlock_irqrestore(&owned_ports_lock, flags);
  16.571              return p;
  16.572          }
  16.573      }
  16.574 -    spin_unlock_irqrestore(&owned_ports_lock, flags);
  16.575  
  16.576      return NULL;
  16.577  }
  16.578  
  16.579 +owned_port_t *usbif_find_port(char *path)
  16.580 +{
  16.581 +    owned_port_t *ret;
  16.582 +    unsigned long flags;
  16.583 +
  16.584 +    spin_lock_irqsave(&owned_ports_lock, flags);
  16.585 +    ret = __usbif_find_port(path);    
  16.586 +    spin_unlock_irqrestore(&owned_ports_lock, flags);
  16.587 +
  16.588 +    return ret;
  16.589 +}
  16.590 +
  16.591  
  16.592  static void *probe(struct usb_device *dev, unsigned iface,
  16.593 -	    const struct usb_device_id *id)
  16.594 +                   const struct usb_device_id *id)
  16.595  {
  16.596      owned_port_t *p;
  16.597  
  16.598 @@ -884,7 +915,7 @@ static void *probe(struct usb_device *de
  16.599       * the device actually is ;-) */
  16.600      if ( ( p = usbif_find_port(dev->devpath) ) != NULL )
  16.601      {
  16.602 -        printk("usbback: claimed device attached to owned port\n");
  16.603 +        printk(KERN_INFO "usbback: claimed device attached to owned port\n");
  16.604  
  16.605          p->dev_present = 1;
  16.606          p->dev = dev;
  16.607 @@ -893,7 +924,8 @@ static void *probe(struct usb_device *de
  16.608          return p->usbif_priv;
  16.609      }
  16.610      else
  16.611 -        printk("usbback: hotplug for non-owned port (%s), ignoring\n", dev->devpath);
  16.612 +        printk(KERN_INFO "usbback: hotplug for non-owned port (%s), ignoring\n",
  16.613 +	       dev->devpath);
  16.614     
  16.615  
  16.616      return NULL;
  16.617 @@ -935,6 +967,10 @@ void __usbif_release_port(owned_port_t *
  16.618       * drivers in this kernel because we assume the device is completely under
  16.619       * the control of ourselves (i.e. the guest!).  This should ensure that the
  16.620       * device is in a sane state for the next customer ;-) */
  16.621 +
  16.622 +    /* MAW NB: we're not resetting the real device here.  This looks perfectly
  16.623 +     * valid to me but it causes memory corruption.  We seem to get away with not
  16.624 +     * resetting for now, although it'd be nice to have this tracked down. */
  16.625  /*     if ( p->dev != NULL) */
  16.626  /*         usb_reset_device(p->dev); */
  16.627  
  16.628 @@ -950,7 +986,7 @@ void usbif_release_port(usbif_be_release
  16.629      owned_port_t *p;
  16.630  
  16.631      spin_lock_irq(&owned_ports_lock);
  16.632 -    p = usbif_find_port(msg->path);
  16.633 +    p = __usbif_find_port(msg->path);
  16.634      __usbif_release_port(p);
  16.635      spin_unlock_irq(&owned_ports_lock);
  16.636  }
  16.637 @@ -978,12 +1014,6 @@ static int __init usbif_init(void)
  16.638           !(xen_start_info.flags & SIF_USB_BE_DOMAIN) )
  16.639          return 0;
  16.640      
  16.641 -    INIT_LIST_HEAD(&owned_ports);
  16.642 -
  16.643 -    usb_register(&driver);
  16.644 -
  16.645 -    usbif_interface_init();
  16.646 -
  16.647      if ( (mmap_vstart = allocate_empty_lowmem_region(MMAP_PAGES)) == 0 )
  16.648          BUG();
  16.649  
  16.650 @@ -993,17 +1023,24 @@ static int __init usbif_init(void)
  16.651      for ( i = 0; i < MAX_PENDING_REQS; i++ )
  16.652          pending_ring[i] = i;
  16.653  
  16.654 +    spin_lock_init(&pend_prod_lock);
  16.655 +
  16.656 +    spin_lock_init(&owned_ports_lock);
  16.657 +    INIT_LIST_HEAD(&owned_ports);
  16.658 +
  16.659      spin_lock_init(&usbio_schedule_list_lock);
  16.660      INIT_LIST_HEAD(&usbio_schedule_list);
  16.661  
  16.662      if ( kernel_thread(usbio_schedule, 0, CLONE_FS | CLONE_FILES) < 0 )
  16.663          BUG();
  16.664      
  16.665 +    usbif_interface_init();
  16.666 +
  16.667      usbif_ctrlif_init();
  16.668  
  16.669 -    spin_lock_init(&owned_ports_lock);
  16.670 +    usb_register(&driver);
  16.671  
  16.672 -    printk("Xen USB Backend Initialised");
  16.673 +    printk(KERN_INFO "Xen USB Backend Initialised");
  16.674  
  16.675      return 0;
  16.676  }
    17.1 --- a/linux-2.6.10-xen-sparse/include/asm-xen/asm-i386/pgtable.h	Fri Jan 28 14:53:32 2005 +0000
    17.2 +++ b/linux-2.6.10-xen-sparse/include/asm-xen/asm-i386/pgtable.h	Fri Feb 04 14:44:18 2005 +0000
    17.3 @@ -475,6 +475,7 @@ void make_pages_writable(void *va, unsig
    17.4  #define kern_addr_valid(addr)	(1)
    17.5  #endif /* !CONFIG_DISCONTIGMEM */
    17.6  
    17.7 +#define DOMID_LOCAL (0xFFFFU)
    17.8  int direct_remap_area_pages(struct mm_struct *mm,
    17.9                              unsigned long address, 
   17.10                              unsigned long machine_addr,
   17.11 @@ -489,17 +490,6 @@ int __direct_remap_area_pages(struct mm_
   17.12  #define io_remap_page_range(vma,from,phys,size,prot) \
   17.13  	direct_remap_area_pages(vma->vm_mm,from,phys,size,prot,DOMID_IO)
   17.14  
   17.15 -int direct_remap_area_pages(struct mm_struct *mm,
   17.16 -			    unsigned long address, 
   17.17 -			    unsigned long machine_addr,
   17.18 -			    unsigned long size, 
   17.19 -			    pgprot_t prot,
   17.20 -			    domid_t  domid);
   17.21 -int __direct_remap_area_pages(struct mm_struct *mm,
   17.22 -			      unsigned long address, 
   17.23 -			      unsigned long size, 
   17.24 -			      mmu_update_t *v);
   17.25 -
   17.26  #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
   17.27  #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_DIRTY
   17.28  #define __HAVE_ARCH_PTEP_GET_AND_CLEAR
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/tools/examples/network-nat	Fri Feb 04 14:44:18 2005 +0000
    18.3 @@ -0,0 +1,77 @@
    18.4 +#!/bin/sh
    18.5 +#============================================================================
    18.6 +# Default Xen network start/stop script.
    18.7 +# Xend calls a network script when it starts.
    18.8 +# The script name to use is defined in /etc/xen/xend-config.sxp
    18.9 +# in the network-script field.
   18.10 +#
   18.11 +# Usage:
   18.12 +#
   18.13 +# network-route (start|stop|status) {VAR=VAL}*
   18.14 +#
   18.15 +# Vars:
   18.16 +#
   18.17 +# netdev     The gateway interface (default eth0).
   18.18 +# antispoof  Whether to use iptables to prevent spoofing (default yes).
   18.19 +#
   18.20 +#============================================================================
   18.21 +
   18.22 +
   18.23 +
   18.24 +# Exit if anything goes wrong.
   18.25 +set -e 
   18.26 +
   18.27 +# First arg is the operation.
   18.28 +OP=$1
   18.29 +shift
   18.30 +
   18.31 +# Pull variables in args in to environment.
   18.32 +for arg ; do export "${arg}" ; done
   18.33 +
   18.34 +netdev=${netdev:-eth0}
   18.35 +# antispoofing not yet implemented
   18.36 +antispoof=${antispoof:-yes}
   18.37 +
   18.38 +echo "network-nat $OP netdev=$netdev antispoof=$antispoof"
   18.39 +
   18.40 +
   18.41 +op_start() {
   18.42 +	echo 1 >/proc/sys/net/ipv4/ip_forward
   18.43 +	iptables -t nat -A POSTROUTING -o ${netdev} -j MASQUERADE
   18.44 +}
   18.45 +
   18.46 +
   18.47 +op_stop() {
   18.48 +	iptables -t nat -D POSTROUTING -o ${netdev} -j MASQUERADE
   18.49 +}
   18.50 +
   18.51 +
   18.52 +show_status() {
   18.53 +    echo '============================================================'
   18.54 +    ifconfig
   18.55 +    echo ' '
   18.56 +    ip route list
   18.57 +    echo ' '
   18.58 +    route -n
   18.59 +    echo '============================================================'
   18.60 +
   18.61 +}
   18.62 +
   18.63 +case ${OP} in
   18.64 +    start)
   18.65 +        op_start
   18.66 +        ;;
   18.67 +    
   18.68 +    stop)
   18.69 +        op_stop
   18.70 +        ;;
   18.71 +
   18.72 +    status)
   18.73 +        show_status
   18.74 +       ;;
   18.75 +
   18.76 +    *)
   18.77 +       echo 'Unknown command: ' ${OP}
   18.78 +       echo 'Valid commands are: start, stop, status'
   18.79 +       exit 1
   18.80 +esac
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/tools/examples/vif-nat	Fri Feb 04 14:44:18 2005 +0000
    19.3 @@ -0,0 +1,66 @@
    19.4 +#!/bin/sh
    19.5 +#============================================================================
    19.6 +# /etc/xen/vif-nat
    19.7 +#
    19.8 +# Script for configuring a vif in routed-nat mode.
    19.9 +# Xend calls a vif script when bringing a vif up or down.
   19.10 +# This script is the default - but it can be configured for each vif.
   19.11 +#
   19.12 +# Example invocation:
   19.13 +#
   19.14 +# vif-nat up domain=VM1 vif=vif1.0 ip="192.168.0.10/31"
   19.15 +#
   19.16 +# Usage:
   19.17 +# vif-nat (up|down) {VAR=VAL}*
   19.18 +#
   19.19 +# Vars:
   19.20 +#
   19.21 +# domain  name of the domain the interface is on (required).
   19.22 +# vif     vif interface name (required).
   19.23 +# ip      list of IP networks for the vif, space-separated (required).
   19.24 +#============================================================================
   19.25 +
   19.26 +# Exit if anything goes wrong
   19.27 +set -e 
   19.28 +
   19.29 +echo "vif-nat $*"
   19.30 +
   19.31 +# Operation name.
   19.32 +OP=$1
   19.33 +shift
   19.34 +
   19.35 +# Pull variables in args into environment
   19.36 +for arg ; do export "${arg}" ; done
   19.37 +
   19.38 +# Required parameters. Fail if not set.
   19.39 +domain=${domain:?}
   19.40 +vif=${vif:?}
   19.41 +ip=${ip:?} 
   19.42 +
   19.43 +# better way to strip /netmask from the ip?
   19.44 +vif_ip=`echo ${ip} | awk -F. '{print $1"."$2"."$3"."$4}'`
   19.45 +
   19.46 +main_ip=`ifconfig eth0 | grep "inet addr:" | sed -e 's/.*inet addr:\(\w\w*\.\w\w*\.\w\w*\.\w\w*\).*/\1/'`
   19.47 +
   19.48 +# Are we going up or down?
   19.49 +case $OP in
   19.50 +    up)
   19.51 +        ifconfig ${vif} ${vif_ip} netmask 255.255.255.0 up
   19.52 +        echo 1 >/proc/sys/net/ipv4/conf/${vif}/proxy_arp
   19.53 +        iptcmd='-A'
   19.54 +        ipcmd='a'
   19.55 +        ;;
   19.56 +    down)
   19.57 +        ifconfig ${vif} down
   19.58 +        iptcmd='-D'
   19.59 +        ipcmd='d'
   19.60 +        ;;
   19.61 +    *)
   19.62 +        echo 'Invalid command: ' $OP
   19.63 +        echo 'Valid commands are: up, down'
   19.64 +        exit 1
   19.65 +        ;;
   19.66 +esac
   19.67 +
   19.68 +ip r ${ipcmd} ${ip} dev ${vif} src ${main_ip}
   19.69 +#    iptables ${iptcmd} FORWARD -m physdev --physdev-in ${vif} -p udp --sport 68 --dport 67 -j ACCEPT
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/tools/examples/xmexample3	Fri Feb 04 14:44:18 2005 +0000
    20.3 @@ -0,0 +1,120 @@
    20.4 +#  -*- mode: python; -*-
    20.5 +#============================================================================
    20.6 +# Example Python setup script for 'xm create'.
    20.7 +# This script sets the parameters used when a domain is created using 'xm create'.
    20.8 +#
    20.9 +# This is a relatively advanced script that uses a parameter, vmid, to control
   20.10 +# the settings. So this script can be used to start a set of domains by
   20.11 +# setting the vmid parameter on the 'xm create' command line. For example:
   20.12 +#
   20.13 +# xm create vmid=1
   20.14 +# xm create vmid=2
   20.15 +# xm create vmid=3
   20.16 +#
   20.17 +# The vmid is purely a script variable, and has no effect on the the domain
   20.18 +# id assigned to the new domain.
   20.19 +#============================================================================
   20.20 +
   20.21 +# Define script variables here.
   20.22 +# xm_vars is defined automatically, use xm_vars.var() to define a variable.
   20.23 +
   20.24 +# This function checks that 'vmid' has been given a valid value.
   20.25 +# It is called automatically by 'xm create'.
   20.26 +def vmid_check(var, val):
   20.27 +    val = int(val)
   20.28 +    if val <= 0:
   20.29 +        raise ValueError
   20.30 +    return val
   20.31 +
   20.32 +# Define the 'vmid' variable so that 'xm create' knows about it.
   20.33 +xm_vars.var('vmid',
   20.34 +            use="Virtual machine id. Integer greater than 0.",
   20.35 +            check=vmid_check)
   20.36 +
   20.37 +# Check the defined variables have valid values..
   20.38 +xm_vars.check()
   20.39 +
   20.40 +#----------------------------------------------------------------------------
   20.41 +# Kernel image file.
   20.42 +kernel = "/path/to/domU/kernel"
   20.43 +
   20.44 +# Optional ramdisk.
   20.45 +#ramdisk = "/boot/initrd.gz"
   20.46 +
   20.47 +# The domain build function. Default is 'linux'.
   20.48 +#builder='linux'
   20.49 +
   20.50 +# Initial memory allocation (in megabytes) for the new domain.
   20.51 +memory = 64
   20.52 +
   20.53 +# A name for the new domain. All domains have to have different names,
   20.54 +# so we use the vmid to create a name.
   20.55 +name = "VM%d" % vmid
   20.56 +
   20.57 +# Which CPU to start domain on? 
   20.58 +#cpu = -1   # leave to Xen to pick
   20.59 +cpu = vmid  # set based on vmid (mod number of CPUs)
   20.60 +
   20.61 +#----------------------------------------------------------------------------
   20.62 +# Define network interfaces.
   20.63 +
   20.64 +# Number of network interfaces. Default is 1.
   20.65 +#nics=1
   20.66 +
   20.67 +# Optionally define mac and/or bridge for the network interfaces.
   20.68 +# Random MACs are assigned if not given.
   20.69 +
   20.70 +vif = [ 'ip=192.168.%d.1/24' % (vmid)]
   20.71 +
   20.72 +#----------------------------------------------------------------------------
   20.73 +# Define the disk devices you want the domain to have access to, and
   20.74 +# what you want them accessible as.
   20.75 +# Each disk entry is of the form phy:UNAME,DEV,MODE
   20.76 +# where UNAME is the device, DEV is the device name the domain will see,
   20.77 +# and MODE is r for read-only, w for read-write.
   20.78 +
   20.79 +# This makes the disk device depend on the vmid - assuming
   20.80 +# tHat devices sda7, sda8 etc. exist. The device is exported
   20.81 +# to all domains as sda1.
   20.82 +# All domains get sda6 read-only (to use for /usr, see below).
   20.83 +disk = [ 'phy:hda%d,hda1,w' % (vmid)]
   20.84 +
   20.85 +#----------------------------------------------------------------------------
   20.86 +# Set the kernel command line for the new domain.
   20.87 +# You only need to define the IP parameters and hostname if the domain's
   20.88 +# IP config doesn't, e.g. in ifcfg-eth0 or via DHCP.
   20.89 +# You can use 'extra' to set the runlevel and custom environment
   20.90 +# variables used by custom rc scripts (e.g. VMID=, usr= ).
   20.91 +
   20.92 +# Set if you want dhcp to allocate the IP address.
   20.93 +dhcp="off"
   20.94 +ip="192.168.%d.2" % (vmid)
   20.95 +# Set netmask.
   20.96 +netmask="255.255.255.0"
   20.97 +# Set default gateway.
   20.98 +gateway="192.168.%d.1" % (vmid)
   20.99 +# Set the hostname.
  20.100 +hostname= "domain-%d.xeno" % vmid
  20.101 +
  20.102 +# Set root device.
  20.103 +root = "/dev/hda1 ro"
  20.104 +
  20.105 +# Root device for nfs.
  20.106 +#root = "/dev/nfs"
  20.107 +# The nfs server.
  20.108 +#nfs_server = "10.212.4.103"
  20.109 +# Root directory on the nfs server.
  20.110 +#nfs_root   = "/path/to/root/filesystem"
  20.111 +
  20.112 +# Sets runlevel 4 and the device for /usr.
  20.113 +extra = "4 VMID=%d" % vmid
  20.114 +
  20.115 +#----------------------------------------------------------------------------
  20.116 +# Set according to whether you want the domain restarted when it exits.
  20.117 +# The default is 'onreboot', which restarts the domain when it shuts down
  20.118 +# with exit code reboot.
  20.119 +# Other values are 'always', and 'never'.
  20.120 +
  20.121 +#restart = 'onreboot'
  20.122 +
  20.123 +#============================================================================
    21.1 --- a/tools/ioemu/include/config.h	Fri Jan 28 14:53:32 2005 +0000
    21.2 +++ b/tools/ioemu/include/config.h	Fri Feb 04 14:44:18 2005 +0000
    21.3 @@ -867,7 +867,7 @@ typedef
    21.4  #endif
    21.5  
    21.6  // NE2K network emulation
    21.7 -#define BX_NE2K_SUPPORT 0
    21.8 +#define BX_NE2K_SUPPORT 1
    21.9  #define BX_ETH_NULL_LOGGING 1
   21.10  #define BX_ETH_FBSD_LOGGING 1
   21.11  
   21.12 @@ -891,7 +891,7 @@ typedef
   21.13  #define HAVE_ETHERTAP 0
   21.14  
   21.15  // this enables TUN/TAP packet mover; determined by configure script
   21.16 -#define HAVE_TUNTAP 0
   21.17 +#define HAVE_TUNTAP 1
   21.18  
   21.19  
   21.20  // I/O Interface to debug
    22.1 --- a/tools/ioemu/iodev/cpu.cc	Fri Jan 28 14:53:32 2005 +0000
    22.2 +++ b/tools/ioemu/iodev/cpu.cc	Fri Feb 04 14:44:18 2005 +0000
    22.3 @@ -83,6 +83,9 @@ ioreq_t* bx_cpu_c::get_ioreq(void)
    22.4  void bx_cpu_c::dispatch_ioreq(ioreq_t *req)
    22.5  {
    22.6  	int ret, i;
    22.7 +    int sign;
    22.8 +
    22.9 +    sign = (req->df) ? -1 : 1;
   22.10  
   22.11  	if ((!req->pdata_valid) && (req->dir == IOREQ_WRITE)) {
   22.12  		if (req->size != 4) {
   22.13 @@ -99,7 +102,7 @@ void bx_cpu_c::dispatch_ioreq(ioreq_t *r
   22.14  
   22.15  				for (i = 0; i < req->count; i++) {
   22.16  					tmp = BX_INP(req->addr, req->size);
   22.17 -					BX_MEM_WRITE_PHYSICAL((Bit32u) req->u.pdata + (i * req->size), 
   22.18 +					BX_MEM_WRITE_PHYSICAL((Bit32u) req->u.pdata + (sign * i * req->size), 
   22.19  							       req->size, &tmp);
   22.20  				}
   22.21  			}
   22.22 @@ -110,7 +113,7 @@ void bx_cpu_c::dispatch_ioreq(ioreq_t *r
   22.23  				for (i = 0; i < req->count; i++) {
   22.24  					unsigned long tmp;
   22.25  
   22.26 -					BX_MEM_READ_PHYSICAL((Bit32u) req->u.pdata + (i * req->size), req->size, 
   22.27 +					BX_MEM_READ_PHYSICAL((Bit32u) req->u.pdata + (sign * i * req->size), req->size, 
   22.28  							 &tmp);
   22.29  					BX_OUTP(req->addr, (Bit32u) tmp, req->size);
   22.30  				}
   22.31 @@ -129,14 +132,14 @@ void bx_cpu_c::dispatch_ioreq(ioreq_t *r
   22.32  			if (req->dir == IOREQ_READ) {
   22.33  				//BX_INFO(("<READ>addr:%llx, pdata:%llx, size: %x, count: %x\n", req->addr, req->u.pdata, req->size, req->count));
   22.34  				for (i = 0; i < req->count; i++) {
   22.35 -					BX_MEM_READ_PHYSICAL(req->addr + (i * req->size), req->size, &tmp);
   22.36 -					BX_MEM_WRITE_PHYSICAL((Bit32u) req->u.pdata + (i * req->size), req->size, &tmp);
   22.37 +					BX_MEM_READ_PHYSICAL(req->addr + (sign * i * req->size), req->size, &tmp);
   22.38 +					BX_MEM_WRITE_PHYSICAL((Bit32u) req->u.pdata + (sign * i * req->size), req->size, &tmp);
   22.39  				}
   22.40  			} else if (req->dir == IOREQ_WRITE) {
   22.41  				//BX_INFO(("<WRITE>addr:%llx, pdata:%llx, size: %x, count: %x\n", req->addr, req->u.pdata, req->size, req->count));
   22.42  				for (i = 0; i < req->count; i++) {
   22.43 -					BX_MEM_READ_PHYSICAL((Bit32u)req->u.pdata + (i * req->size), req->size, &tmp);
   22.44 -					BX_MEM_WRITE_PHYSICAL(req->addr + (i * req->size), req->size, &tmp);
   22.45 +					BX_MEM_READ_PHYSICAL((Bit32u)req->u.pdata + (sign * i * req->size), req->size, &tmp);
   22.46 +					BX_MEM_WRITE_PHYSICAL(req->addr + (sign * i * req->size), req->size, &tmp);
   22.47  				}
   22.48  			}
   22.49  		}
   22.50 @@ -210,6 +213,10 @@ bx_cpu_c::cpu_loop(int max_instr_count)
   22.51  #endif
   22.52  			interrupt(vector);
   22.53  		}
   22.54 +		/* we check DMA after interrupt check*/
   22.55 +		while(BX_HRQ){
   22.56 +			DEV_dma_raise_hlda();
   22.57 +		}
   22.58  
   22.59  		if (send_event) {
   22.60  			int ret;
    23.1 --- a/tools/ioemu/iodev/dma.cc	Fri Jan 28 14:53:32 2005 +0000
    23.2 +++ b/tools/ioemu/iodev/dma.cc	Fri Feb 04 14:44:18 2005 +0000
    23.3 @@ -182,6 +182,14 @@ bx_dma_c::init(void)
    23.4      }
    23.5    BX_DMA_THIS s[1].chan[0].used = 1; // cascade channel in use
    23.6    BX_INFO(("channel 4 used by cascade"));
    23.7 +  bios_init();
    23.8 +}
    23.9 +
   23.10 +/* Remove it when guest fw ready*/
   23.11 +  void
   23.12 +bx_dma_c::bios_init(void){
   23.13 +  BX_DMA_THIS s[1].mask[0] = 0; // unmask cascade channel  
   23.14 +  BX_DMA_THIS s[1].chan[0].mode.mode_type = 3; // cascade mode for channel 4
   23.15  }
   23.16  
   23.17    void
   23.18 @@ -189,6 +197,7 @@ bx_dma_c::reset(unsigned type)
   23.19  {
   23.20    reset_controller(0);
   23.21    reset_controller(1);
   23.22 +  bios_init();
   23.23  }
   23.24  
   23.25    void
    24.1 --- a/tools/ioemu/iodev/dma.h	Fri Jan 28 14:53:32 2005 +0000
    24.2 +++ b/tools/ioemu/iodev/dma.h	Fri Feb 04 14:44:18 2005 +0000
    24.3 @@ -46,6 +46,7 @@ public:
    24.4    ~bx_dma_c(void);
    24.5  
    24.6    virtual void     init(void);
    24.7 +  virtual void     bios_init(void);
    24.8    virtual void     reset(unsigned type);
    24.9    virtual void     raise_HLDA(void);
   24.10    virtual void     set_DRQ(unsigned channel, bx_bool val);
    25.1 --- a/tools/ioemu/memory/misc_mem.cc	Fri Jan 28 14:53:32 2005 +0000
    25.2 +++ b/tools/ioemu/memory/misc_mem.cc	Fri Feb 04 14:44:18 2005 +0000
    25.3 @@ -174,20 +174,16 @@ BX_MEM_C::init_memory(int memsize)
    25.4  
    25.5  #define PAGE_SHIFT 12
    25.6  #define PAGE_SIZE  (1 << PAGE_SHIFT)
    25.7 -#define round_pgup(x)	(((x) + PAGE_SIZE-1) & ~ (PAGE_SIZE-1))
    25.8  
    25.9 -    int npte_pages = 1 + (round_pgup(nr_pages * 4) / PAGE_SIZE); 
   25.10 -
   25.11 -    /* We don't map pte pages and the top 64k -- XXX: this could be a problem */
   25.12      if ((vector = (Bit8u *) xc_map_foreign_batch(xc_handle, domid,
   25.13                                                   PROT_READ|PROT_WRITE,
   25.14                                                   page_array,
   25.15 -                                                 nr_pages - npte_pages - 16)) == 0) {
   25.16 +                                                 nr_pages - 1)) == 0) {
   25.17          BX_ERROR(("Could not map guest physical"));
   25.18          return;
   25.19      }
   25.20  
   25.21 -    BX_MEM_THIS dma_limit = (nr_pages - npte_pages - 16) << PAGE_SHIFT;
   25.22 +    BX_MEM_THIS dma_limit = (nr_pages - 1) << PAGE_SHIFT;
   25.23      BX_INFO(("DMA limit: %lx", BX_MEM_THIS dma_limit));
   25.24  
   25.25      shared_page = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE, 
    26.1 --- a/tools/ioemu/mk/helix.mk	Fri Jan 28 14:53:32 2005 +0000
    26.2 +++ b/tools/ioemu/mk/helix.mk	Fri Feb 04 14:44:18 2005 +0000
    26.3 @@ -1,5 +1,4 @@
    26.4 -LDFLAGS  += -g
    26.5 -CXXFLAGS += -g  -I../../../tools/libxc -I../../../xen/include/public
    26.6 +CXXFLAGS += -O2  -I../../../tools/libxc -I../../../xen/include/public
    26.7  clean:
    26.8  	$(RM) -f *.o *~ lib*.a device-model
    26.9  
    27.1 --- a/tools/libxc/Makefile	Fri Jan 28 14:53:32 2005 +0000
    27.2 +++ b/tools/libxc/Makefile	Fri Feb 04 14:44:18 2005 +0000
    27.3 @@ -69,7 +69,7 @@ mk-symlinks:
    27.4  install: all
    27.5  	[ -d $(DESTDIR)/usr/lib ] || $(INSTALL_DIR) $(DESTDIR)/usr/lib
    27.6  	[ -d $(DESTDIR)/usr/include ] || $(INSTALL_DIR) $(DESTDIR)/usr/include
    27.7 -	$(INSTALL_PROG) $(LIB) $(DESTDIR)/usr/lib
    27.8 +	$(INSTALL_PROG) libxc.so.$(MAJOR).$(MINOR) $(DESTDIR)/usr/lib
    27.9  	ln -sf libxc.so.$(MAJOR).$(MINOR) $(DESTDIR)/usr/lib/libxc.so.$(MAJOR)
   27.10  	ln -sf libxc.so.$(MAJOR) $(DESTDIR)/usr/lib/libxc.so
   27.11  	$(INSTALL_DATA) xc.h $(DESTDIR)/usr/include
    28.1 --- a/tools/libxc/linux_boot_params.h	Fri Jan 28 14:53:32 2005 +0000
    28.2 +++ b/tools/libxc/linux_boot_params.h	Fri Feb 04 14:44:18 2005 +0000
    28.3 @@ -15,6 +15,8 @@ struct mem_map {
    28.4  #define E820_RESERVED   2
    28.5  #define E820_ACPI       3 /* usable as RAM once ACPI tables have been read */
    28.6  #define E820_NVS        4
    28.7 +#define E820_IO         16
    28.8 +#define E820_SHARED     17
    28.9  
   28.10          unsigned long caching_attr;    /* used by hypervisor */
   28.11  #define MEMMAP_UC	0
    29.1 --- a/tools/libxc/xc.h	Fri Jan 28 14:53:32 2005 +0000
    29.2 +++ b/tools/libxc/xc.h	Fri Feb 04 14:44:18 2005 +0000
    29.3 @@ -211,6 +211,7 @@ xc_plan9_build (int xc_handle,
    29.4  struct mem_map;
    29.5  int xc_vmx_build(int xc_handle,
    29.6                   u32 domid,
    29.7 +                 int memsize,
    29.8                   const char *image_name,
    29.9                   struct mem_map *memmap,
   29.10                   const char *ramdisk_name,
    30.1 --- a/tools/libxc/xc_vmx_build.c	Fri Jan 28 14:53:32 2005 +0000
    30.2 +++ b/tools/libxc/xc_vmx_build.c	Fri Feb 04 14:44:18 2005 +0000
    30.3 @@ -46,8 +46,70 @@ loadelfsymtab(
    30.4      char *elfbase, int xch, u32 dom, unsigned long *parray,
    30.5      struct domain_setup_info *dsi);
    30.6  
    30.7 +static void build_e820map(struct mem_map *mem_mapp, unsigned long mem_size)
    30.8 +{
    30.9 +    int nr_map = 0;
   30.10 +
   30.11 +    /* XXX: Doesn't work for > 4GB yet */
   30.12 +    mem_mapp->map[0].addr = 0x0;
   30.13 +    mem_mapp->map[0].size = 0x9F800;
   30.14 +    mem_mapp->map[0].type = E820_RAM;
   30.15 +    mem_mapp->map[0].caching_attr = MEMMAP_WB;
   30.16 +    nr_map++;
   30.17 +
   30.18 +    mem_mapp->map[1].addr = 0x9F800;
   30.19 +    mem_mapp->map[1].size = 0x800;
   30.20 +    mem_mapp->map[1].type = E820_RESERVED;
   30.21 +    mem_mapp->map[1].caching_attr = MEMMAP_UC;
   30.22 +    nr_map++;
   30.23 +
   30.24 +    mem_mapp->map[2].addr = 0xA0000;
   30.25 +    mem_mapp->map[2].size = 0x20000;
   30.26 +    mem_mapp->map[2].type = E820_IO;
   30.27 +    mem_mapp->map[2].caching_attr = MEMMAP_UC;
   30.28 +    nr_map++;
   30.29 +
   30.30 +    mem_mapp->map[3].addr = 0xF0000;
   30.31 +    mem_mapp->map[3].size = 0x10000;
   30.32 +    mem_mapp->map[3].type = E820_RESERVED;
   30.33 +    mem_mapp->map[3].caching_attr = MEMMAP_UC;
   30.34 +    nr_map++;
   30.35 +
   30.36 +    mem_mapp->map[4].addr = 0x100000;
   30.37 +    mem_mapp->map[4].size = mem_size - 0x100000 - PAGE_SIZE;
   30.38 +    mem_mapp->map[4].type = E820_RAM;
   30.39 +    mem_mapp->map[4].caching_attr = MEMMAP_WB;
   30.40 +    nr_map++;
   30.41 +
   30.42 +    mem_mapp->map[5].addr = mem_size - PAGE_SIZE;
   30.43 +    mem_mapp->map[5].size = PAGE_SIZE;
   30.44 +    mem_mapp->map[5].type = E820_SHARED;
   30.45 +    mem_mapp->map[5].caching_attr = MEMMAP_WB;
   30.46 +    nr_map++;
   30.47 +
   30.48 +    mem_mapp->map[6].addr = mem_size;
   30.49 +    mem_mapp->map[6].size = 0x3 * PAGE_SIZE;
   30.50 +    mem_mapp->map[6].type = E820_NVS;
   30.51 +    mem_mapp->map[6].caching_attr = MEMMAP_UC;
   30.52 +    nr_map++;
   30.53 +
   30.54 +    mem_mapp->map[7].addr = mem_size + 0x3 * PAGE_SIZE;
   30.55 +    mem_mapp->map[7].size = 0xA * PAGE_SIZE;
   30.56 +    mem_mapp->map[7].type = E820_ACPI;
   30.57 +    mem_mapp->map[7].caching_attr = MEMMAP_WB;
   30.58 +    nr_map++;
   30.59 +
   30.60 +    mem_mapp->map[8].addr = 0xFEC00000;
   30.61 +    mem_mapp->map[8].size = 0x1400000;
   30.62 +    mem_mapp->map[8].type = E820_IO;
   30.63 +    mem_mapp->map[8].caching_attr = MEMMAP_UC;
   30.64 +    nr_map++;
   30.65 +
   30.66 +    mem_mapp->nr_map = nr_map;
   30.67 +}
   30.68 +
   30.69  static int setup_guestos(int xc_handle,
   30.70 -                         u32 dom,
   30.71 +                         u32 dom, int memsize,
   30.72                           char *image, unsigned long image_size,
   30.73                           gzFile initrd_gfd, unsigned long initrd_len,
   30.74                           unsigned long nr_pages,
   30.75 @@ -110,21 +172,24 @@ static int setup_guestos(int xc_handle,
   30.76       * read-only). We have a pair of simultaneous equations in two unknowns, 
   30.77       * which we solve by exhaustive search.
   30.78       */
   30.79 -    nr_pt_pages = 1 + (nr_pages >> (PAGE_SHIFT - 2));
   30.80      vboot_params_start = LINUX_BOOT_PARAMS_ADDR;
   30.81      vboot_params_end   = vboot_params_start + PAGE_SIZE;
   30.82      vboot_gdt_start    = vboot_params_end;
   30.83      vboot_gdt_end      = vboot_gdt_start + PAGE_SIZE;
   30.84 -    v_end              = nr_pages << PAGE_SHIFT;
   30.85 -    vpt_end            = v_end - (16 << PAGE_SHIFT); /* leaving the top 64k untouched */
   30.86 -    vpt_start          = vpt_end - (nr_pt_pages << PAGE_SHIFT);
   30.87 -    vinitrd_end        = vpt_start;
   30.88 +
   30.89 +    /* memsize is in megabytes */
   30.90 +    v_end              = memsize << 20;
   30.91 +    vinitrd_end        = v_end - PAGE_SIZE; /* leaving the top 4k untouched for IO requests page use */
   30.92      vinitrd_start      = vinitrd_end - initrd_len;
   30.93      vinitrd_start      = vinitrd_start & (~(PAGE_SIZE - 1));
   30.94  
   30.95      if(initrd_len == 0)
   30.96          vinitrd_start = vinitrd_end = 0;
   30.97  
   30.98 +    nr_pt_pages = 1 + ((memsize + 3) >> 2);
   30.99 +    vpt_start   = v_end;
  30.100 +    vpt_end     = vpt_start + (nr_pt_pages * PAGE_SIZE);
  30.101 +
  30.102      printf("VIRTUAL MEMORY ARRANGEMENT:\n"
  30.103             " Boot_params:   %08lx->%08lx\n"
  30.104             " boot_gdt:      %08lx->%08lx\n"
  30.105 @@ -218,9 +283,6 @@ static int setup_guestos(int xc_handle,
  30.106          }
  30.107  
  30.108          *vl1e = (page_array[count] << PAGE_SHIFT) | L1_PROT;
  30.109 -        if ( (count >= ((vpt_start-dsi.v_start)>>PAGE_SHIFT)) && 
  30.110 -             (count <  ((vpt_end  -dsi.v_start)>>PAGE_SHIFT)) )
  30.111 -            *vl1e &= ~_PAGE_RW;
  30.112          vl1e++;
  30.113      }
  30.114      munmap(vl1tab, PAGE_SIZE);
  30.115 @@ -267,7 +329,7 @@ static int setup_guestos(int xc_handle,
  30.116      boot_paramsp->initrd_start = vinitrd_start;
  30.117      boot_paramsp->initrd_size = initrd_len;
  30.118  
  30.119 -    i = (nr_pages >> (PAGE_SHIFT - 10)) - (1 << 10) - 4;
  30.120 +    i = ((memsize - 1) << 10) - 4;
  30.121      boot_paramsp->alt_mem_k = i; /* alt_mem_k */
  30.122      boot_paramsp->screen.overlap.ext_mem_k = i & 0xFFFF; /* ext_mem_k */
  30.123  
  30.124 @@ -291,6 +353,8 @@ static int setup_guestos(int xc_handle,
  30.125      boot_paramsp->drive_info.dummy[2] = 4;
  30.126      boot_paramsp->drive_info.dummy[14] = 32;
  30.127  
  30.128 +    /* memsize is in megabytes */
  30.129 +    build_e820map(mem_mapp, memsize << 20);
  30.130      boot_paramsp->e820_map_nr = mem_mapp->nr_map;
  30.131      for (i=0; i<mem_mapp->nr_map; i++) {
  30.132          boot_paramsp->e820_map[i].addr = mem_mapp->map[i].addr; 
  30.133 @@ -374,6 +438,7 @@ int vmx_identify(void)
  30.134  
  30.135  int xc_vmx_build(int xc_handle,
  30.136                     u32 domid,
  30.137 +                   int memsize,
  30.138                     const char *image_name,
  30.139                     struct mem_map *mem_mapp,
  30.140                     const char *ramdisk_name,
  30.141 @@ -445,7 +510,7 @@ int xc_vmx_build(int xc_handle,
  30.142          goto error_out;
  30.143      }
  30.144  
  30.145 -    if ( setup_guestos(xc_handle, domid, image, image_size, 
  30.146 +    if ( setup_guestos(xc_handle, domid, memsize, image, image_size, 
  30.147                         initrd_gfd, initrd_size, nr_pages, 
  30.148                         ctxt, cmdline,
  30.149                         op.u.getdomaininfo.shared_info_frame,
    31.1 --- a/tools/libxutil/Makefile	Fri Jan 28 14:53:32 2005 +0000
    31.2 +++ b/tools/libxutil/Makefile	Fri Feb 04 14:44:18 2005 +0000
    31.3 @@ -64,7 +64,7 @@ check-for-zlib:
    31.4  
    31.5  install: all
    31.6  	[ -d $(DESTDIR)/usr/lib ] || $(INSTALL_DIR) -p $(DESTDIR)/usr/lib
    31.7 -	$(INSTALL_PROG) $(LIB) $(DESTDIR)/usr/lib
    31.8 +	$(INSTALL_PROG) $(LIB_NAME).so.$(MAJOR).$(MINOR) $(DESTDIR)/usr/lib
    31.9  	ln -sf $(LIB_NAME).so.$(MAJOR).$(MINOR) $(DESTDIR)/usr/lib/$(LIB_NAME).so.$(MAJOR)
   31.10  	ln -sf $(LIB_NAME).so.$(MAJOR) $(DESTDIR)/usr/lib/$(LIB_NAME).so
   31.11  
    32.1 --- a/tools/python/xen/lowlevel/xc/xc.c	Fri Jan 28 14:53:32 2005 +0000
    32.2 +++ b/tools/python/xen/lowlevel/xc/xc.c	Fri Feb 04 14:44:18 2005 +0000
    32.3 @@ -405,15 +405,18 @@ static PyObject *pyxc_vmx_build(PyObject
    32.4      PyObject *memmap;
    32.5      int   control_evtchn, flags = 0;
    32.6      int numItems, i;
    32.7 +    int memsize;
    32.8      struct mem_map mem_map;
    32.9  
   32.10 -    static char *kwd_list[] = { "dom", "control_evtchn", 
   32.11 +    static char *kwd_list[] = { "dom", "control_evtchn",
   32.12 +                                "memsize",
   32.13                                  "image", "memmap",
   32.14  				"ramdisk", "cmdline", "flags",
   32.15                                  NULL };
   32.16  
   32.17 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iisO!|ssi", kwd_list, 
   32.18 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiisO!|ssi", kwd_list, 
   32.19                                        &dom, &control_evtchn, 
   32.20 +                                      &memsize,
   32.21                                        &image, &PyList_Type, &memmap,
   32.22  				      &ramdisk, &cmdline, &flags) )
   32.23          return NULL;
   32.24 @@ -467,7 +470,7 @@ static PyObject *pyxc_vmx_build(PyObject
   32.25              mem_map.map[i-1].caching_attr = lf4;
   32.26      }
   32.27  
   32.28 -    if ( xc_vmx_build(xc->xc_handle, dom, image, &mem_map,
   32.29 +    if ( xc_vmx_build(xc->xc_handle, dom, memsize, image, &mem_map,
   32.30                          ramdisk, cmdline, control_evtchn, flags) != 0 )
   32.31          return PyErr_SetFromErrno(xc_error);
   32.32      
    33.1 --- a/tools/python/xen/lowlevel/xu/xu.c	Fri Jan 28 14:53:32 2005 +0000
    33.2 +++ b/tools/python/xen/lowlevel/xu/xu.c	Fri Feb 04 14:44:18 2005 +0000
    33.3 @@ -917,6 +917,12 @@ static PyObject *xu_message_new(PyObject
    33.4          P2C(netif_be_create_t, mac[3],       u8);
    33.5          P2C(netif_be_create_t, mac[4],       u8);
    33.6          P2C(netif_be_create_t, mac[5],       u8);
    33.7 +        P2C(netif_be_create_t, be_mac[0],    u8);
    33.8 +        P2C(netif_be_create_t, be_mac[1],    u8);
    33.9 +        P2C(netif_be_create_t, be_mac[2],    u8);
   33.10 +        P2C(netif_be_create_t, be_mac[3],    u8);
   33.11 +        P2C(netif_be_create_t, be_mac[4],    u8);
   33.12 +        P2C(netif_be_create_t, be_mac[5],    u8);
   33.13          break;
   33.14      case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_DESTROY):
   33.15          P2C(netif_be_destroy_t, domid,        u32);
    34.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Fri Jan 28 14:53:32 2005 +0000
    34.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Fri Feb 04 14:44:18 2005 +0000
    34.3 @@ -320,6 +320,7 @@ class XendDomainInfo:
    34.4          self.restart_time = None
    34.5          self.console_port = None
    34.6          self.savedinfo = None
    34.7 +        self.image_handler = None
    34.8          self.is_vmx = 0
    34.9          self.vcpus = 1
   34.10  
   34.11 @@ -455,6 +456,7 @@ class XendDomainInfo:
   34.12              except:
   34.13                  raise VmError('invalid vcpus value')
   34.14  
   34.15 +            self.find_image_handler()
   34.16              self.init_domain()
   34.17              self.configure_console()
   34.18              self.configure_backends()
   34.19 @@ -471,7 +473,7 @@ class XendDomainInfo:
   34.20              raise
   34.21          return deferred
   34.22  
   34.23 -    def construct_image(self):
   34.24 +    def find_image_handler(self):
   34.25          """Construct the boot image for the domain.
   34.26  
   34.27          @return vm
   34.28 @@ -482,10 +484,17 @@ class XendDomainInfo:
   34.29          image_name = sxp.name(image)
   34.30          if image_name is None:
   34.31              raise VmError('missing image name')
   34.32 +        if image_name == "vmx":
   34.33 +            self.is_vmx = 1
   34.34          image_handler = get_image_handler(image_name)
   34.35          if image_handler is None:
   34.36              raise VmError('unknown image type: ' + image_name)
   34.37 -        image_handler(self, image)
   34.38 +        self.image_handler = image_handler
   34.39 +        return self
   34.40 +
   34.41 +    def construct_image(self):
   34.42 +        image = sxp.child_value(self.config, 'image')
   34.43 +        self.image_handler(self, image)
   34.44          return self
   34.45  
   34.46      def config_devices(self, name):
   34.47 @@ -730,7 +739,8 @@ class XendDomainInfo:
   34.48          except:
   34.49              raise VmError('invalid cpu')
   34.50          cpu_weight = self.cpu_weight
   34.51 -        dom = xc.domain_create(dom= dom, mem_kb= memory * 1024,
   34.52 +        memory = memory * 1024 + self.pgtable_size(memory)
   34.53 +        dom = xc.domain_create(dom= dom, mem_kb= memory,
   34.54                                 cpu= cpu, cpu_weight= cpu_weight)
   34.55          if dom <= 0:
   34.56              raise VmError('Creating domain failed: name=%s memory=%d'
   34.57 @@ -757,6 +767,7 @@ class XendDomainInfo:
   34.58          	err = buildfn(dom      = dom,
   34.59                 	      	image          = kernel,
   34.60                        	control_evtchn = 0,
   34.61 +                        memsize        = self.memory,
   34.62  			memmap	       = memmap,
   34.63                        	cmdline        = cmdline,
   34.64                        	ramdisk        = ramdisk,
   34.65 @@ -1084,6 +1095,18 @@ class XendDomainInfo:
   34.66          d.addErrback(dlist_err)
   34.67          return d
   34.68  
   34.69 +    def pgtable_size(self, memory):
   34.70 +        """Return the size of memory needed for 1:1 page tables for physical
   34.71 +           mode.
   34.72 +
   34.73 +        @param memory: size in MB
   34.74 +        @return size in KB
   34.75 +        """
   34.76 +        if self.is_vmx:
   34.77 +            # Logic x86-32 specific. 
   34.78 +            # 1 page for the PGD + 1 pte page for 4MB of memory (rounded)
   34.79 +            return (1 + ((memory + 3) >> 2)) * 4
   34.80 +        return 0
   34.81  
   34.82  def vm_image_linux(vm, image):
   34.83      """Create a VM for a linux image.
   34.84 @@ -1159,7 +1182,6 @@ def vm_image_vmx(vm, image):
   34.85      from xen.util.memmap import memmap_parse
   34.86      memmap = memmap_parse(memmap)
   34.87      vm.create_domain("vmx", kernel, ramdisk, cmdline, memmap)
   34.88 -    vm.is_vmx = 1
   34.89      return vm
   34.90  
   34.91  def vm_dev_vif(vm, val, index, change=0):
    35.1 --- a/tools/python/xen/xend/server/blkif.py	Fri Jan 28 14:53:32 2005 +0000
    35.2 +++ b/tools/python/xen/xend/server/blkif.py	Fri Feb 04 14:44:18 2005 +0000
    35.3 @@ -66,8 +66,11 @@ def blkdev_name_to_number(name):
    35.4      if re.match( '/dev/sd[a-p]([0-9]|1[0-5])', n):
    35.5          return 8 * 256 + 16 * (ord(n[7:8]) - ord('a')) + int(n[8:])
    35.6  
    35.7 -    if re.match( '/dev/hd[a-p]([0-9]|[1-5][0-9]|6[0-3])', n):
    35.8 -        return 3 * 256 + 16 * (ord(n[7:8]) - ord('a')) + int(n[8:])        
    35.9 +    if re.match( '/dev/hd[a-t]([1-9]|[1-5][0-9]|6[0-3])?', n):
   35.10 +        ide_majors = [ 3, 22, 33, 34, 56, 57, 88, 89, 90, 91 ]
   35.11 +        major = ide_majors[(ord(n[7:8]) - ord('a')) / 2]
   35.12 +        minor = ((ord(n[7:8]) - ord('a')) % 2) * 64 + int(n[8:] or 0)
   35.13 +        return major * 256 + minor
   35.14  
   35.15      # see if this is a hex device number
   35.16      if re.match( '^(0x)?[0-9a-fA-F]+$', name ):
    36.1 --- a/tools/python/xen/xend/server/messages.py	Fri Jan 28 14:53:32 2005 +0000
    36.2 +++ b/tools/python/xen/xend/server/messages.py	Fri Feb 04 14:44:18 2005 +0000
    36.3 @@ -330,9 +330,9 @@ def packMsg(ty, params):
    36.4      (major, minor) = msg_formats[ty]
    36.5      args = {}
    36.6      for (k, v) in params.items():
    36.7 -        if k == 'mac':
    36.8 +        if k in ['mac', 'be_mac']:
    36.9              for i in range(0, 6):
   36.10 -                args['mac[%d]' % i] = v[i]
   36.11 +                args['%s[%d]' % (k, i)] = v[i]
   36.12          else:
   36.13              args[k] = v
   36.14      msg = xu.message(major, minor, msgid, args)
    37.1 --- a/tools/python/xen/xend/server/netif.py	Fri Jan 28 14:53:32 2005 +0000
    37.2 +++ b/tools/python/xen/xend/server/netif.py	Fri Feb 04 14:44:18 2005 +0000
    37.3 @@ -109,7 +109,14 @@ class NetDev(controller.SplitDev):
    37.4          vmac = sxp.child_value(config, 'mac')
    37.5          if not vmac: return None
    37.6          mac = [ int(x, 16) for x in vmac.split(':') ]
    37.7 -        if len(mac) != 6: raise XendError("invalid mac")
    37.8 +        if len(mac) != 6: raise XendError("invalid mac: %s" % vmac)
    37.9 +        return mac
   37.10 +
   37.11 +    def _get_config_be_mac(self, config):
   37.12 +        vmac = sxp.child_value(config, 'be_mac')
   37.13 +        if not vmac: return None
   37.14 +        mac = [ int(x, 16) for x in vmac.split(':') ]
   37.15 +        if len(mac) != 6: raise XendError("invalid backend mac: %s" % vmac)
   37.16          return mac
   37.17  
   37.18      def _get_config_ipaddr(self, config):
   37.19 @@ -127,6 +134,7 @@ class NetDev(controller.SplitDev):
   37.20              return self.reconfigure(config)
   37.21          self.config = config
   37.22          self.mac = None
   37.23 +        self.be_mac = None
   37.24          self.bridge = None
   37.25          self.script = None
   37.26          self.ipaddr = []
   37.27 @@ -135,6 +143,7 @@ class NetDev(controller.SplitDev):
   37.28          if mac is None:
   37.29              raise XendError("invalid mac")
   37.30          self.mac = mac
   37.31 +        self.be_mac = self._get_config_be_mac(config)
   37.32          self.bridge = sxp.child_value(config, 'bridge')
   37.33          self.script = sxp.child_value(config, 'script')
   37.34          self.ipaddr = self._get_config_ipaddr(config) or []
   37.35 @@ -159,6 +168,7 @@ class NetDev(controller.SplitDev):
   37.36          """
   37.37          changes = {}
   37.38          mac = self._get_config_mac(config)
   37.39 +        be_mac = self._get_config_be_mac(config)
   37.40          bridge = sxp.child_value(config, 'bridge')
   37.41          script = sxp.child_value(config, 'script')
   37.42          ipaddr = self._get_config_ipaddr(config)
   37.43 @@ -166,6 +176,8 @@ class NetDev(controller.SplitDev):
   37.44          backendDomain = str(xd.domain_lookup(sxp.child_value(config, 'backend', '0')).id)
   37.45          if (mac is not None) and (mac != self.mac):
   37.46              raise XendError("cannot change mac")
   37.47 +        if (be_mac is not None) and (be_mac != self.be_mac):
   37.48 +            raise XendError("cannot change backend mac")
   37.49          if (backendDomain is not None) and (backendDomain != str(self.backendDomain)):
   37.50              raise XendError("cannot change backend")
   37.51          if (bridge is not None) and (bridge != self.bridge):
   37.52 @@ -190,6 +202,8 @@ class NetDev(controller.SplitDev):
   37.53                 ['idx', self.idx],
   37.54                 ['vif', vif],
   37.55                 ['mac', mac]]
   37.56 +        if self.be_mac:
   37.57 +            val.append(['be_mac', self.get_be_mac()])
   37.58          if self.bridge:
   37.59              val.append(['bridge', self.bridge])
   37.60          if self.script:
   37.61 @@ -214,6 +228,11 @@ class NetDev(controller.SplitDev):
   37.62          """
   37.63          return ':'.join(map(lambda x: "%02x" % x, self.mac))
   37.64  
   37.65 +    def get_be_mac(self):
   37.66 +        """Get the backend MAC address as a string.
   37.67 +        """
   37.68 +        return ':'.join(map(lambda x: "%02x" % x, self.be_mac))
   37.69 +
   37.70      def vifctl_params(self, vmname=None):
   37.71          """Get the parameters to pass to vifctl.
   37.72          """
   37.73 @@ -267,6 +286,7 @@ class NetDev(controller.SplitDev):
   37.74          msg = packMsg('netif_be_create_t',
   37.75                        { 'domid'        : self.controller.dom,
   37.76                          'netif_handle' : self.vif,
   37.77 +                        'be_mac'       : self.be_mac or [0, 0, 0, 0, 0, 0],
   37.78                          'mac'          : self.mac })
   37.79          self.getBackendInterface().writeRequest(msg, response=d)
   37.80          return d
    38.1 --- a/tools/python/xen/xm/create.py	Fri Jan 28 14:53:32 2005 +0000
    38.2 +++ b/tools/python/xen/xm/create.py	Fri Feb 04 14:44:18 2005 +0000
    38.3 @@ -160,11 +160,13 @@ gopts.var('ipaddr', val="IPADDR",
    38.4            fn=append_value, default=[],
    38.5            use="Add an IP address to the domain.")
    38.6  
    38.7 -gopts.var('vif', val="mac=MAC,bridge=BRIDGE,script=SCRIPT,backend=DOM",
    38.8 +gopts.var('vif', val="mac=MAC,be_mac=MAC,bridge=BRIDGE,script=SCRIPT,backend=DOM",
    38.9            fn=append_value, default=[],
   38.10            use="""Add a network interface with the given MAC address and bridge.
   38.11            The vif is configured by calling the given configuration script.
   38.12            If mac is not specified a random MAC address is used.
   38.13 +          The MAC address of the backend interface can be selected with be_mac.
   38.14 +          If not specified then the network backend chooses it's own MAC address.
   38.15            If bridge is not specified the default bridge is used.
   38.16            If script is not specified the default script is used.
   38.17            If backend is not specified the default backend driver domain is used.
   38.18 @@ -314,18 +316,22 @@ def configure_vifs(config_devs, vals):
   38.19              mac = d.get('mac')
   38.20              if not mac:
   38.21                  mac = randomMAC()
   38.22 +            be_mac = d.get('be_mac')
   38.23              bridge = d.get('bridge')
   38.24              script = d.get('script')
   38.25              backend = d.get('backend')
   38.26              ip = d.get('ip')
   38.27          else:
   38.28              mac = randomMAC()
   38.29 +            be_mac = None
   38.30              bridge = None
   38.31              script = None
   38.32              backend = None
   38.33              ip = None
   38.34          config_vif = ['vif']
   38.35          config_vif.append(['mac', mac])
   38.36 +        if be_mac:
   38.37 +            config_vif.append(['be_mac', be_mac])
   38.38          if bridge:
   38.39              config_vif.append(['bridge', bridge])
   38.40          if script:
   38.41 @@ -423,7 +429,7 @@ def preprocess_vifs(opts, vals):
   38.42              (k, v) = b.strip().split('=', 1)
   38.43              k = k.strip()
   38.44              v = v.strip()
   38.45 -            if k not in ['mac', 'bridge', 'script', 'backend', 'ip']:
   38.46 +            if k not in ['mac', 'be_mac', 'bridge', 'script', 'backend', 'ip']:
   38.47                  opts.err('Invalid vif specifier: ' + vif)
   38.48              d[k] = v
   38.49          vifs.append(d)
    39.1 --- a/tools/xcs/xcs.c	Fri Jan 28 14:53:32 2005 +0000
    39.2 +++ b/tools/xcs/xcs.c	Fri Feb 04 14:44:18 2005 +0000
    39.3 @@ -74,6 +74,8 @@
    39.4  #include <netinet/in.h>
    39.5  #include <arpa/inet.h>
    39.6  #include <errno.h>
    39.7 +#include <malloc.h>
    39.8 +#include <fcntl.h>
    39.9  #include "xcs.h"
   39.10  
   39.11  #undef fd_max
   39.12 @@ -82,14 +84,36 @@
   39.13  /* ------[ Control channel interfaces ]------------------------------------*/
   39.14  
   39.15  static control_channel_t *cc_list[NR_EVENT_CHANNELS];
   39.16 -static int dom_to_port[MAX_DOMS]; /* This should not be a fixed-size array.*/
   39.17 +static int *dom_port_map = 0;
   39.18 +static int dom_port_map_size = 0;
   39.19 +
   39.20 +static void map_dom_to_port(u32 dom, int port)
   39.21 +{
   39.22 +	if (dom >= dom_port_map_size) {
   39.23 +		dom_port_map = (int *)realloc(dom_port_map,
   39.24 +					      (dom + 10) * sizeof(dom_port_map[0]));
   39.25 +
   39.26 +		if (dom_port_map == NULL) {
   39.27 +			perror("realloc(dom_port_map)");
   39.28 +			exit(1);
   39.29 +		}
   39.30 +
   39.31 +		for (; dom_port_map_size < dom + 10; dom_port_map_size++) {
   39.32 +			dom_port_map[dom_port_map_size] = -1;
   39.33 +		}
   39.34 +	}
   39.35 +
   39.36 +	dom_port_map[dom] = port;
   39.37 +}
   39.38 +
   39.39 +static int dom_to_port(u32 dom) {
   39.40 +	if (dom >= dom_port_map_size) return -1;
   39.41 +
   39.42 +	return dom_port_map[dom];
   39.43 +}
   39.44  
   39.45  static void init_interfaces(void)
   39.46  {
   39.47 -    int i;
   39.48 -    
   39.49 -    for (i = 0; i < MAX_DOMS; i++)
   39.50 -        dom_to_port[i] = -1;
   39.51      memset(cc_list, 0, sizeof cc_list);
   39.52  }
   39.53  
   39.54 @@ -99,9 +123,9 @@ static control_channel_t *add_interface(
   39.55      control_channel_t *cc=NULL, *oldcc;
   39.56      int ret;
   39.57      
   39.58 -    if (cc_list[dom_to_port[dom]] != NULL)
   39.59 +    if (cc_list[dom_to_port(dom)] != NULL)
   39.60      {
   39.61 -        return(cc_list[dom_to_port[dom]]);
   39.62 +        return(cc_list[dom_to_port(dom)]);
   39.63      }
   39.64      
   39.65      if (cc_list[local_port] == NULL) 
   39.66 @@ -133,13 +157,13 @@ static control_channel_t *add_interface(
   39.67          {
   39.68              DPRINTF("CC conflict! (port: %d, old dom: %u, new dom: %u)\n",
   39.69                      cc->local_port, oldcc->remote_dom, cc->remote_dom);
   39.70 -            dom_to_port[oldcc->remote_dom] = -1;
   39.71 +            map_dom_to_port(oldcc->remote_dom, -1);
   39.72              ctrl_chan_free(cc_list[cc->local_port]);
   39.73          }
   39.74      }
   39.75       
   39.76      cc_list[cc->local_port] = cc;
   39.77 -    dom_to_port[cc->remote_dom] = cc->local_port;
   39.78 +    map_dom_to_port(cc->remote_dom, cc->local_port);
   39.79      cc->type = CC_TYPE_INTERDOMAIN;
   39.80      cc->ref_count = 0;
   39.81      return cc;
   39.82 @@ -436,7 +460,7 @@ void handle_data_message( connection_t *
   39.83          if ( cmsg->remote_dom > MAX_DOMS )
   39.84              break;
   39.85          
   39.86 -        port = dom_to_port[cmsg->remote_dom];
   39.87 +        port = dom_to_port(cmsg->remote_dom);
   39.88          if (port == -1) break;
   39.89          cc = cc_list[port];
   39.90          if ((cc != NULL) && ( cc->type == CC_TYPE_INTERDOMAIN ))
   39.91 @@ -455,7 +479,7 @@ void handle_data_message( connection_t *
   39.92          if ( cmsg->remote_dom > MAX_DOMS )
   39.93              break;
   39.94          
   39.95 -        port = dom_to_port[cmsg->remote_dom];
   39.96 +        port = dom_to_port(cmsg->remote_dom);
   39.97          if (port == -1) break;
   39.98          cc = cc_list[port];
   39.99          if ((cc != NULL) && ( cc->type == CC_TYPE_INTERDOMAIN ))
  39.100 @@ -627,7 +651,30 @@ int main (int argc, char*argv[])
  39.101      init_bindings();
  39.102      
  39.103      listen_fd = listen_socket(XCS_TCP_PORT);
  39.104 -    
  39.105 +   
  39.106 +    /* detach from our controlling tty so that a shell does hang waiting for
  39.107 +       stopped jobs. */
  39.108 +    /* we should use getopt() here */
  39.109 +
  39.110 +    if (!(argc == 2 && !strcmp(argv[1], "-i"))) {
  39.111 +	pid_t pid = fork();
  39.112 +	int fd;
  39.113 +
  39.114 +	if (pid == -1) {
  39.115 +		perror("fork()");
  39.116 +	} else if (pid) {
  39.117 +		exit(0);
  39.118 +	}
  39.119 +
  39.120 +    	setsid();
  39.121 +	close(2);
  39.122 +	close(1);
  39.123 +	close(0);
  39.124 +	fd = open("/dev/null", O_RDWR);
  39.125 +	dup(fd);
  39.126 +	dup(fd);
  39.127 +    }
  39.128 + 
  39.129      for (;;)
  39.130      {
  39.131          int n, ret;
    40.1 --- a/xen/Makefile	Fri Jan 28 14:53:32 2005 +0000
    40.2 +++ b/xen/Makefile	Fri Feb 04 14:44:18 2005 +0000
    40.3 @@ -1,3 +1,7 @@
    40.4 +# Default is to install to local 'dist' directory.
    40.5 +DISTDIR ?= ../dist
    40.6 +DESTDIR ?= $(DISTDIR)/install
    40.7 +
    40.8  INSTALL			= install
    40.9  INSTALL_DATA		= $(INSTALL) -m0644
   40.10  INSTALL_DIR		= $(INSTALL) -d -m0755
   40.11 @@ -20,6 +24,9 @@ default: $(TARGET).gz
   40.12  debug:	
   40.13  	objdump -D -S $(TARGET)-syms > $(TARGET).s
   40.14  
   40.15 +dist:
   40.16 +	$(MAKE) install
   40.17 +
   40.18  install: $(TARGET).gz
   40.19  	[ -d $(DESTDIR)/boot ] || $(INSTALL_DIR) $(DESTDIR)/boot
   40.20  	$(INSTALL_DATA) $(TARGET).gz $(DESTDIR)/boot
   40.21 @@ -77,7 +84,7 @@ include/xen/banner.h: tools/figlet/figle
   40.22  	tools/figlet/figlet -d tools/figlet Xen $(XEN_VERSION).$(XEN_SUBVERSION)$(XEN_EXTRAVERSION) > $@.new
   40.23  	@mv -f $@.new $@
   40.24  
   40.25 -include/asm-$(TARGET_ARCH)/asm-offsets.h: arch/$(TARGET_ARCH)/asm-offsets.s
   40.26 +include/asm-$(TARGET_ARCH)/asm-offsets.h: arch/$(TARGET_ARCH)/asm-offsets.s $(HDRS)
   40.27  	@(set -e; \
   40.28  	  echo "/*"; \
   40.29  	  echo " * DO NOT MODIFY."; \
    41.1 --- a/xen/Rules.mk	Fri Jan 28 14:53:32 2005 +0000
    41.2 +++ b/xen/Rules.mk	Fri Feb 04 14:44:18 2005 +0000
    41.3 @@ -11,10 +11,10 @@ COMPILE_ARCH    ?= $(shell uname -m | se
    41.4  TARGET_ARCH     ?= $(COMPILE_ARCH)
    41.5  
    41.6  # Set ARCH/SUBARCH appropriately.
    41.7 -COMPILE_SUBARCH := $(COMPILE_ARCH)
    41.8 -TARGET_SUBARCH  := $(COMPILE_ARCH)
    41.9 -COMPILE_ARCH    := $(patsubst x86%,x86,$(COMPILE_ARCH))
   41.10 -TARGET_ARCH     := $(patsubst x86%,x86,$(TARGET_ARCH))
   41.11 +override COMPILE_SUBARCH := $(COMPILE_ARCH)
   41.12 +override TARGET_SUBARCH  := $(TARGET_ARCH)
   41.13 +override COMPILE_ARCH    := $(patsubst x86%,x86,$(COMPILE_ARCH))
   41.14 +override TARGET_ARCH     := $(patsubst x86%,x86,$(TARGET_ARCH))
   41.15  
   41.16  TARGET  := $(BASEDIR)/xen
   41.17  HDRS    := $(wildcard $(BASEDIR)/include/xen/*.h)
    42.1 --- a/xen/arch/x86/Rules.mk	Fri Jan 28 14:53:32 2005 +0000
    42.2 +++ b/xen/arch/x86/Rules.mk	Fri Feb 04 14:44:18 2005 +0000
    42.3 @@ -5,7 +5,7 @@ CC := gcc
    42.4  LD := ld
    42.5  
    42.6  CFLAGS  := -nostdinc -fno-builtin -fno-common -fno-strict-aliasing
    42.7 -CFLAGS  += -iwithprefix include -Wall -Werror -pipe
    42.8 +CFLAGS  += -iwithprefix include -Wall -Werror -Wno-format -pipe
    42.9  CFLAGS  += -I$(BASEDIR)/include -Wno-pointer-arith -Wredundant-decls
   42.10  
   42.11  ifeq ($(optimize),y)
    43.1 --- a/xen/arch/x86/boot/mkelf32.c	Fri Jan 28 14:53:32 2005 +0000
    43.2 +++ b/xen/arch/x86/boot/mkelf32.c	Fri Feb 04 14:44:18 2005 +0000
    43.3 @@ -201,7 +201,7 @@ int main(int argc, char **argv)
    43.4  
    43.5          if ( in32_ehdr.e_phnum != 1 )
    43.6          {
    43.7 -            fprintf(stderr, "Expect precisly 1 program header; found %d.\n",
    43.8 +            fprintf(stderr, "Expect precisely 1 program header; found %d.\n",
    43.9                      (int)in32_ehdr.e_phnum);
   43.10              return 1;
   43.11          }
    44.1 --- a/xen/arch/x86/boot/x86_64.S	Fri Jan 28 14:53:32 2005 +0000
    44.2 +++ b/xen/arch/x86/boot/x86_64.S	Fri Feb 04 14:44:18 2005 +0000
    44.3 @@ -52,16 +52,16 @@ 3:      in      %dx,%al
    44.4  
    44.5          /* Set up a few descriptors: on entry only CS is guaranteed good. */
    44.6          lgdt    %cs:0x1001f0
    44.7 -        mov     $(__HYPERVISOR_DS),%ecx
    44.8 +        mov     $(__HYPERVISOR_DS32),%ecx
    44.9          mov     %ecx,%ds
   44.10          mov     %ecx,%es
   44.11  
   44.12 +        cmp     $(SECONDARY_CPU_FLAG),%ebx
   44.13 +        je      skip_boot_checks
   44.14 +
   44.15          /* Check for Multiboot bootloader */
   44.16 -        cmp     $(SECONDARY_CPU_FLAG),%ebx
   44.17 -        je      skip_multiboot_check
   44.18          cmp     $0x2BADB002,%eax
   44.19          jne     not_multiboot
   44.20 -skip_multiboot_check:
   44.21          
   44.22          /* Save the Multiboot info structure for later use. */
   44.23          mov     %ebx,0x1001e0
   44.24 @@ -75,7 +75,8 @@ skip_multiboot_check:
   44.25          cpuid
   44.26          bt      $29,%edx            # Long mode feature?
   44.27          jnc     bad_cpu
   44.28 -        
   44.29 +skip_boot_checks:
   44.30 +
   44.31          /* Set up FPU. */
   44.32          fninit
   44.33          
   44.34 @@ -106,10 +107,6 @@ 1:      /* Now in compatibility mode. Lo
   44.35  
   44.36          /* Install relocated selectors (FS/GS unused). */
   44.37          lgdt    gdt_descr(%rip)
   44.38 -        mov     $(__HYPERVISOR_DS),%ecx
   44.39 -        mov     %ecx,%ds
   44.40 -        mov     %ecx,%es
   44.41 -        mov     %ecx,%ss
   44.42  
   44.43          /* Enable full CR4 features. */
   44.44          mov     mmu_cr4_features(%rip),%rcx
   44.45 @@ -127,6 +124,13 @@ 1:      /* Now in compatibility mode. Lo
   44.46          ret
   44.47  __high_start:
   44.48          
   44.49 +        mov     $(__HYPERVISOR_DS64),%ecx
   44.50 +        mov     %ecx,%ds
   44.51 +        mov     %ecx,%es
   44.52 +        mov     %ecx,%fs
   44.53 +        mov     %ecx,%gs
   44.54 +        mov     %ecx,%ss
   44.55 +
   44.56          lidt    idt_descr(%rip)
   44.57                  
   44.58          cmp     $(SECONDARY_CPU_FLAG),%ebx
   44.59 @@ -164,9 +168,6 @@ int_msg:
   44.60          .asciz "Unknown interrupt\n"
   44.61  ignore_int:
   44.62          cld
   44.63 -        mov     $(__HYPERVISOR_DS),%eax
   44.64 -        mov     %eax,%ds
   44.65 -        mov     %eax,%es
   44.66          lea     int_msg(%rip),%rdi
   44.67          call    SYMBOL_NAME(printf)
   44.68  1:      jmp     1b
   44.69 @@ -195,7 +196,7 @@ ENTRY(gdt_table)
   44.70          .quad 0x00affa000000ffff     /* 0x082b ring 3 code, 64-bit mode   */
   44.71          .quad 0x00cff2000000ffff     /* 0x0833 ring 3 data                */
   44.72          .quad 0x0000000000000000     /* unused                            */
   44.73 -        .fill 2*NR_CPUS,8,0          /* space for TSS and LDT per CPU     */
   44.74 +        .fill 4*NR_CPUS,8,0          /* space for TSS and LDT per CPU     */
   44.75  
   44.76          .word   0
   44.77  gdt_descr:
   44.78 @@ -205,12 +206,12 @@ SYMBOL_NAME(gdt):
   44.79  
   44.80          .word   0    
   44.81  idt_descr:
   44.82 -        .word   256*8-1
   44.83 +        .word   256*16-1
   44.84  SYMBOL_NAME(idt):
   44.85          .quad   SYMBOL_NAME(idt_table)
   44.86  
   44.87  ENTRY(stack_start)
   44.88 -        .quad   SYMBOL_NAME(cpu0_stack) + 8100
   44.89 +        .quad   SYMBOL_NAME(cpu0_stack) + 8000
   44.90  
   44.91  high_start:
   44.92          .quad   __high_start
   44.93 @@ -248,34 +249,11 @@ ENTRY(cpu0_stack)    # Initial stack is 
   44.94  ENTRY(stext)
   44.95  ENTRY(_stext)
   44.96  
   44.97 -.globl map_domain_mem, unmap_domain_mem, ret_from_intr
   44.98 -map_domain_mem:
   44.99 -unmap_domain_mem:
  44.100 -ret_from_intr:
  44.101 -#undef machine_to_phys_mapping
  44.102 -#undef phys_to_machine_mapping
  44.103 -.globl copy_to_user, set_intr_gate, die, machine_to_phys_mapping
  44.104 -.globl phys_to_machine_mapping
  44.105 +.globl copy_from_user, copy_to_user, copy_user_generic
  44.106 +copy_from_user: 
  44.107  copy_to_user:
  44.108 -set_intr_gate:
  44.109 -die:
  44.110 -machine_to_phys_mapping:
  44.111 -phys_to_machine_mapping:
  44.112 -.globl copy_from_user, show_registers, do_iopl
  44.113 -copy_from_user: 
  44.114 -show_registers: 
  44.115 -do_iopl: 
  44.116 -.globl idt_table, copy_user_generic, idt_tables, new_thread
  44.117 -idt_table:
  44.118  copy_user_generic:
  44.119 -idt_tables:
  44.120 -new_thread:
  44.121 -.globl switch_to, __get_user_1, __get_user_4, __get_user_8, trap_init
  44.122 -switch_to:
  44.123 +.globl __get_user_1, __get_user_4, __get_user_8
  44.124  __get_user_1:
  44.125  __get_user_4:
  44.126  __get_user_8:
  44.127 -trap_init: 
  44.128 -.globl set_debugreg
  44.129 -set_debugreg:
  44.130 -        
    45.1 --- a/xen/arch/x86/dom0_ops.c	Fri Jan 28 14:53:32 2005 +0000
    45.2 +++ b/xen/arch/x86/dom0_ops.c	Fri Feb 04 14:44:18 2005 +0000
    45.3 @@ -295,6 +295,44 @@ long arch_do_dom0_op(dom0_op_t *op, dom0
    45.4      }
    45.5      break;
    45.6  
    45.7 +    case DOM0_GETMEMLIST:
    45.8 +    {
    45.9 +        int i;
   45.10 +        struct domain *d = find_domain_by_id(op->u.getmemlist.domain);
   45.11 +        unsigned long max_pfns = op->u.getmemlist.max_pfns;
   45.12 +        unsigned long pfn;
   45.13 +        unsigned long *buffer = op->u.getmemlist.buffer;
   45.14 +        struct list_head *list_ent;
   45.15 +
   45.16 +        ret = -EINVAL;
   45.17 +        if ( d != NULL )
   45.18 +        {
   45.19 +            ret = 0;
   45.20 +
   45.21 +            spin_lock(&d->page_alloc_lock);
   45.22 +            list_ent = d->page_list.next;
   45.23 +            for ( i = 0; (i < max_pfns) && (list_ent != &d->page_list); i++ )
   45.24 +            {
   45.25 +                pfn = list_entry(list_ent, struct pfn_info, list) - 
   45.26 +                    frame_table;
   45.27 +                if ( put_user(pfn, buffer) )
   45.28 +                {
   45.29 +                    ret = -EFAULT;
   45.30 +                    break;
   45.31 +                }
   45.32 +                buffer++;
   45.33 +                list_ent = frame_table[pfn].list.next;
   45.34 +            }
   45.35 +            spin_unlock(&d->page_alloc_lock);
   45.36 +
   45.37 +            op->u.getmemlist.num_pfns = i;
   45.38 +            copy_to_user(u_dom0_op, op, sizeof(*op));
   45.39 +            
   45.40 +            put_domain(d);
   45.41 +        }
   45.42 +    }
   45.43 +    break;
   45.44 +
   45.45      default:
   45.46          ret = -ENOSYS;
   45.47  
    46.1 --- a/xen/arch/x86/domain.c	Fri Jan 28 14:53:32 2005 +0000
    46.2 +++ b/xen/arch/x86/domain.c	Fri Feb 04 14:44:18 2005 +0000
    46.3 @@ -43,20 +43,6 @@
    46.4  static int opt_noreboot = 0;
    46.5  boolean_param("noreboot", opt_noreboot);
    46.6  
    46.7 -#if !defined(CONFIG_X86_64BITMODE)
    46.8 -/* No ring-3 access in initial page tables. */
    46.9 -#define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED)
   46.10 -#else
   46.11 -/* Allow ring-3 access in long mode as guest cannot use ring 1. */
   46.12 -#define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_USER)
   46.13 -#endif
   46.14 -#define L2_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER)
   46.15 -#define L3_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER)
   46.16 -#define L4_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER)
   46.17 -
   46.18 -#define round_pgup(_p)    (((_p)+(PAGE_SIZE-1))&PAGE_MASK)
   46.19 -#define round_pgdown(_p)  ((_p)&PAGE_MASK)
   46.20 -
   46.21  static void default_idle(void)
   46.22  {
   46.23      __cli();
   46.24 @@ -223,42 +209,24 @@ void dump_pageframe_info(struct domain *
   46.25             page->u.inuse.type_info);
   46.26  }
   46.27  
   46.28 -xmem_cache_t *domain_struct_cachep;
   46.29 -xmem_cache_t *exec_domain_struct_cachep;
   46.30 -
   46.31 -void __init domain_startofday(void)
   46.32 -{
   46.33 -    domain_struct_cachep = xmem_cache_create(
   46.34 -        "domain_cache", sizeof(struct domain),
   46.35 -        0, SLAB_HWCACHE_ALIGN, NULL, NULL);
   46.36 -    if ( domain_struct_cachep == NULL )
   46.37 -        panic("No slab cache for domain structs.");
   46.38 -
   46.39 -    exec_domain_struct_cachep = xmem_cache_create(
   46.40 -        "exec_dom_cache", sizeof(struct exec_domain),
   46.41 -        0, SLAB_HWCACHE_ALIGN, NULL, NULL);
   46.42 -    if ( exec_domain_struct_cachep == NULL )
   46.43 -        BUG();
   46.44 -}
   46.45 -
   46.46  struct domain *arch_alloc_domain_struct(void)
   46.47  {
   46.48 -    return xmem_cache_alloc(domain_struct_cachep);
   46.49 +    return xmalloc(struct domain);
   46.50  }
   46.51  
   46.52  void arch_free_domain_struct(struct domain *d)
   46.53  {
   46.54 -    xmem_cache_free(domain_struct_cachep, d);
   46.55 +    xfree(d);
   46.56  }
   46.57  
   46.58  struct exec_domain *arch_alloc_exec_domain_struct(void)
   46.59  {
   46.60 -    return xmem_cache_alloc(exec_domain_struct_cachep);
   46.61 +    return xmalloc(struct exec_domain);
   46.62  }
   46.63  
   46.64  void arch_free_exec_domain_struct(struct exec_domain *ed)
   46.65  {
   46.66 -    xmem_cache_free(exec_domain_struct_cachep, ed);
   46.67 +    xfree(ed);
   46.68  }
   46.69  
   46.70  void free_perdomain_pt(struct domain *d)
   46.71 @@ -279,9 +247,8 @@ static void continue_nonidle_task(struct
   46.72  void arch_do_createdomain(struct exec_domain *ed)
   46.73  {
   46.74      struct domain *d = ed->domain;
   46.75 -#ifdef ARCH_HAS_FAST_TRAP
   46.76 +
   46.77      SET_DEFAULT_FAST_TRAP(&ed->thread);
   46.78 -#endif
   46.79  
   46.80      if ( d->id == IDLE_DOMAIN_ID )
   46.81      {
   46.82 @@ -294,7 +261,6 @@ void arch_do_createdomain(struct exec_do
   46.83          d->shared_info = (void *)alloc_xenheap_page();
   46.84          memset(d->shared_info, 0, PAGE_SIZE);
   46.85          ed->vcpu_info = &d->shared_info->vcpu_data[ed->eid];
   46.86 -        d->shared_info->arch.mfn_to_pfn_start = m2p_start_mfn;
   46.87          SHARE_PFN_WITH_DOMAIN(virt_to_page(d->shared_info), d);
   46.88          machine_to_phys_mapping[virt_to_phys(d->shared_info) >> 
   46.89                                 PAGE_SHIFT] = INVALID_P2M_ENTRY;
   46.90 @@ -364,6 +330,8 @@ static void monitor_rm_pagetable(struct 
   46.91      l2_pgentry_t *mpl2e;
   46.92      unsigned long mpfn;
   46.93  
   46.94 +    ASSERT( pagetable_val(m->monitor_table) );
   46.95 +    
   46.96      mpl2e = (l2_pgentry_t *) map_domain_mem(pagetable_val(m->monitor_table));
   46.97      /*
   46.98       * First get the pfn for guest_pl2e_cache by looking at monitor_table
   46.99 @@ -471,10 +439,8 @@ int arch_final_setup_guestos(struct exec
  46.100             &c->trap_ctxt,
  46.101             sizeof(d->thread.traps));
  46.102  
  46.103 -#ifdef ARCH_HAS_FAST_TRAP
  46.104      if ( (rc = (int)set_fast_trap(d, c->fast_trap_idx)) != 0 )
  46.105          return rc;
  46.106 -#endif
  46.107  
  46.108      d->mm.ldt_base = c->ldt_base;
  46.109      d->mm.ldt_ents = c->ldt_ents;
  46.110 @@ -516,8 +482,6 @@ int arch_final_setup_guestos(struct exec
  46.111      return 0;
  46.112  }
  46.113  
  46.114 -#if defined(__i386__)
  46.115 -
  46.116  void new_thread(struct exec_domain *d,
  46.117                  unsigned long start_pc,
  46.118                  unsigned long start_stack,
  46.119 @@ -533,8 +497,8 @@ void new_thread(struct exec_domain *d,
  46.120       *          ESI = start_info
  46.121       *  [EAX,EBX,ECX,EDX,EDI,EBP are zero]
  46.122       */
  46.123 -    ec->ds = ec->es = ec->fs = ec->gs = ec->ss = FLAT_RING1_DS;
  46.124 -    ec->cs = FLAT_RING1_CS;
  46.125 +    ec->ds = ec->es = ec->fs = ec->gs = ec->ss = FLAT_GUESTOS_DS;
  46.126 +    ec->cs = FLAT_GUESTOS_CS;
  46.127      ec->eip = start_pc;
  46.128      ec->esp = start_stack;
  46.129      ec->esi = start_info;
  46.130 @@ -548,18 +512,19 @@ void new_thread(struct exec_domain *d,
  46.131   * This special macro can be used to load a debugging register
  46.132   */
  46.133  #define loaddebug(thread,register) \
  46.134 -		__asm__("movl %0,%%db" #register  \
  46.135 +		__asm__("mov %0,%%db" #register  \
  46.136  			: /* no output */ \
  46.137  			:"r" (thread->debugreg[register]))
  46.138  
  46.139 -
  46.140  void switch_to(struct exec_domain *prev_p, struct exec_domain *next_p)
  46.141  {
  46.142      struct thread_struct *next = &next_p->thread;
  46.143      struct tss_struct *tss = init_tss + smp_processor_id();
  46.144      execution_context_t *stack_ec = get_execution_context();
  46.145      int i;
  46.146 +#ifdef CONFIG_VMX
  46.147      unsigned long vmx_domain = next_p->thread.arch_vmx.flags; 
  46.148 +#endif
  46.149  
  46.150      __cli();
  46.151  
  46.152 @@ -591,7 +556,9 @@ void switch_to(struct exec_domain *prev_
  46.153              loaddebug(next, 7);
  46.154          }
  46.155  
  46.156 -         if (vmx_domain) {
  46.157 +#ifdef CONFIG_VMX
  46.158 +        if ( vmx_domain )
  46.159 +        {
  46.160              /* Switch page tables. */
  46.161              write_ptbase(&next_p->mm);
  46.162   
  46.163 @@ -601,13 +568,16 @@ void switch_to(struct exec_domain *prev_
  46.164  
  46.165              __sti();
  46.166              return;
  46.167 -         }
  46.168 +        }
  46.169 +#endif
  46.170   
  46.171          SET_FAST_TRAP(&next_p->thread);
  46.172  
  46.173 +#ifdef __i386__
  46.174          /* Switch the guest OS ring-1 stack. */
  46.175          tss->esp1 = next->guestos_sp;
  46.176          tss->ss1  = next->guestos_ss;
  46.177 +#endif
  46.178  
  46.179          /* Switch page tables. */
  46.180          write_ptbase(&next_p->mm);
  46.181 @@ -650,8 +620,6 @@ long do_iopl(domid_t domain, unsigned in
  46.182      return 0;
  46.183  }
  46.184  
  46.185 -#endif
  46.186 -
  46.187  unsigned long hypercall_create_continuation(
  46.188      unsigned int op, unsigned int nr_args, ...)
  46.189  {
  46.190 @@ -815,364 +783,3 @@ void domain_relinquish_memory(struct dom
  46.191      relinquish_list(d, &d->page_list);
  46.192  }
  46.193  
  46.194 -
  46.195 -int construct_dom0(struct domain *p, 
  46.196 -                   unsigned long alloc_start,
  46.197 -                   unsigned long alloc_end,
  46.198 -                   char *image_start, unsigned long image_len, 
  46.199 -                   char *initrd_start, unsigned long initrd_len,
  46.200 -                   char *cmdline)
  46.201 -{
  46.202 -    char *dst;
  46.203 -    int i, rc;
  46.204 -    unsigned long pfn, mfn;
  46.205 -    unsigned long nr_pages = (alloc_end - alloc_start) >> PAGE_SHIFT;
  46.206 -    unsigned long nr_pt_pages;
  46.207 -    unsigned long count;
  46.208 -    l2_pgentry_t *l2tab, *l2start;
  46.209 -    l1_pgentry_t *l1tab = NULL, *l1start = NULL;
  46.210 -    struct pfn_info *page = NULL;
  46.211 -    start_info_t *si;
  46.212 -    struct exec_domain *ed = p->exec_domain[0];
  46.213 -
  46.214 -    /*
  46.215 -     * This fully describes the memory layout of the initial domain. All 
  46.216 -     * *_start address are page-aligned, except v_start (and v_end) which are 
  46.217 -     * superpage-aligned.
  46.218 -     */
  46.219 -    struct domain_setup_info dsi;
  46.220 -    unsigned long vinitrd_start;
  46.221 -    unsigned long vinitrd_end;
  46.222 -    unsigned long vphysmap_start;
  46.223 -    unsigned long vphysmap_end;
  46.224 -    unsigned long vstartinfo_start;
  46.225 -    unsigned long vstartinfo_end;
  46.226 -    unsigned long vstack_start;
  46.227 -    unsigned long vstack_end;
  46.228 -    unsigned long vpt_start;
  46.229 -    unsigned long vpt_end;
  46.230 -    unsigned long v_end;
  46.231 -
  46.232 -    /* Machine address of next candidate page-table page. */
  46.233 -    unsigned long mpt_alloc;
  46.234 -
  46.235 -    extern void physdev_init_dom0(struct domain *);
  46.236 -
  46.237 -    /* Sanity! */
  46.238 -    if ( p->id != 0 ) 
  46.239 -        BUG();
  46.240 -    if ( test_bit(DF_CONSTRUCTED, &p->d_flags) ) 
  46.241 -        BUG();
  46.242 -
  46.243 -    memset(&dsi, 0, sizeof(struct domain_setup_info));
  46.244 -
  46.245 -    printk("*** LOADING DOMAIN 0 ***\n");
  46.246 -
  46.247 -    /*
  46.248 -     * This is all a bit grim. We've moved the modules to the "safe" physical 
  46.249 -     * memory region above MAP_DIRECTMAP_ADDRESS (48MB). Later in this 
  46.250 -     * routine we're going to copy it down into the region that's actually 
  46.251 -     * been allocated to domain 0. This is highly likely to be overlapping, so 
  46.252 -     * we use a forward copy.
  46.253 -     * 
  46.254 -     * MAP_DIRECTMAP_ADDRESS should be safe. The worst case is a machine with 
  46.255 -     * 4GB and lots of network/disk cards that allocate loads of buffers. 
  46.256 -     * We'll have to revisit this if we ever support PAE (64GB).
  46.257 -     */
  46.258 -
  46.259 -    rc = parseelfimage(image_start, image_len, &dsi);
  46.260 -    if ( rc != 0 )
  46.261 -        return rc;
  46.262 -
  46.263 -    /* Set up domain options */
  46.264 -    if ( dsi.use_writable_pagetables )
  46.265 -        vm_assist(p, VMASST_CMD_enable, VMASST_TYPE_writable_pagetables);
  46.266 -
  46.267 -    if ( (dsi.v_start & (PAGE_SIZE-1)) != 0 )
  46.268 -    {
  46.269 -        printk("Initial guest OS must load to a page boundary.\n");
  46.270 -        return -EINVAL;
  46.271 -    }
  46.272 -
  46.273 -    /*
  46.274 -     * Why do we need this? The number of page-table frames depends on the 
  46.275 -     * size of the bootstrap address space. But the size of the address space 
  46.276 -     * depends on the number of page-table frames (since each one is mapped 
  46.277 -     * read-only). We have a pair of simultaneous equations in two unknowns, 
  46.278 -     * which we solve by exhaustive search.
  46.279 -     */
  46.280 -    vinitrd_start    = round_pgup(dsi.v_kernend);
  46.281 -    vinitrd_end      = vinitrd_start + initrd_len;
  46.282 -    vphysmap_start   = round_pgup(vinitrd_end);
  46.283 -    vphysmap_end     = vphysmap_start + (nr_pages * sizeof(unsigned long));
  46.284 -    vpt_start        = round_pgup(vphysmap_end);
  46.285 -    for ( nr_pt_pages = 2; ; nr_pt_pages++ )
  46.286 -    {
  46.287 -        vpt_end          = vpt_start + (nr_pt_pages * PAGE_SIZE);
  46.288 -        vstartinfo_start = vpt_end;
  46.289 -        vstartinfo_end   = vstartinfo_start + PAGE_SIZE;
  46.290 -        vstack_start     = vstartinfo_end;
  46.291 -        vstack_end       = vstack_start + PAGE_SIZE;
  46.292 -        v_end            = (vstack_end + (1<<22)-1) & ~((1<<22)-1);
  46.293 -        if ( (v_end - vstack_end) < (512 << 10) )
  46.294 -            v_end += 1 << 22; /* Add extra 4MB to get >= 512kB padding. */
  46.295 -        if ( (((v_end - dsi.v_start + ((1<<L2_PAGETABLE_SHIFT)-1)) >> 
  46.296 -               L2_PAGETABLE_SHIFT) + 1) <= nr_pt_pages )
  46.297 -            break;
  46.298 -    }
  46.299 -
  46.300 -    printk("PHYSICAL MEMORY ARRANGEMENT:\n"
  46.301 -           " Kernel image:  %p->%p\n"
  46.302 -           " Initrd image:  %p->%p\n"
  46.303 -           " Dom0 alloc.:   %08lx->%08lx\n",
  46.304 -           image_start, image_start + image_len,
  46.305 -           initrd_start, initrd_start + initrd_len,
  46.306 -           alloc_start, alloc_end);
  46.307 -    printk("VIRTUAL MEMORY ARRANGEMENT:\n"
  46.308 -           " Loaded kernel: %08lx->%08lx\n"
  46.309 -           " Init. ramdisk: %08lx->%08lx\n"
  46.310 -           " Phys-Mach map: %08lx->%08lx\n"
  46.311 -           " Page tables:   %08lx->%08lx\n"
  46.312 -           " Start info:    %08lx->%08lx\n"
  46.313 -           " Boot stack:    %08lx->%08lx\n"
  46.314 -           " TOTAL:         %08lx->%08lx\n",
  46.315 -           dsi.v_kernstart, dsi.v_kernend, 
  46.316 -           vinitrd_start, vinitrd_end,
  46.317 -           vphysmap_start, vphysmap_end,
  46.318 -           vpt_start, vpt_end,
  46.319 -           vstartinfo_start, vstartinfo_end,
  46.320 -           vstack_start, vstack_end,
  46.321 -           dsi.v_start, v_end);
  46.322 -    printk(" ENTRY ADDRESS: %08lx\n", dsi.v_kernentry);
  46.323 -
  46.324 -    if ( (v_end - dsi.v_start) > (nr_pages * PAGE_SIZE) )
  46.325 -    {
  46.326 -        printk("Initial guest OS requires too much space\n"
  46.327 -               "(%luMB is greater than %luMB limit)\n",
  46.328 -               (v_end-dsi.v_start)>>20, (nr_pages<<PAGE_SHIFT)>>20);
  46.329 -        return -ENOMEM;
  46.330 -    }
  46.331 -
  46.332 -    /*
  46.333 -     * Protect the lowest 1GB of memory. We use a temporary mapping there
  46.334 -     * from which we copy the kernel and ramdisk images.
  46.335 -     */
  46.336 -    if ( dsi.v_start < (1<<30) )
  46.337 -    {
  46.338 -        printk("Initial loading isn't allowed to lowest 1GB of memory.\n");
  46.339 -        return -EINVAL;
  46.340 -    }
  46.341 -
  46.342 -    /* Paranoia: scrub DOM0's memory allocation. */
  46.343 -    printk("Scrubbing DOM0 RAM: ");
  46.344 -    dst = (char *)alloc_start;
  46.345 -    while ( dst < (char *)alloc_end )
  46.346 -    {
  46.347 -#define SCRUB_BYTES (100 * 1024 * 1024) /* 100MB */
  46.348 -        printk(".");
  46.349 -        touch_nmi_watchdog();
  46.350 -        if ( ((char *)alloc_end - dst) > SCRUB_BYTES )
  46.351 -        {
  46.352 -            memset(dst, 0, SCRUB_BYTES);
  46.353 -            dst += SCRUB_BYTES;
  46.354 -        }
  46.355 -        else
  46.356 -        {
  46.357 -            memset(dst, 0, (char *)alloc_end - dst);
  46.358 -            break;
  46.359 -        }
  46.360 -    }
  46.361 -    printk("done.\n");
  46.362 -
  46.363 -    /* Construct a frame-allocation list for the initial domain. */
  46.364 -    for ( mfn = (alloc_start>>PAGE_SHIFT); 
  46.365 -          mfn < (alloc_end>>PAGE_SHIFT); 
  46.366 -          mfn++ )
  46.367 -    {
  46.368 -        page = &frame_table[mfn];
  46.369 -        page->u.inuse.domain    = p;
  46.370 -        page->u.inuse.type_info = 0;
  46.371 -        page->count_info        = PGC_allocated | 1;
  46.372 -        list_add_tail(&page->list, &p->page_list);
  46.373 -        p->tot_pages++; p->max_pages++;
  46.374 -    }
  46.375 -
  46.376 -    mpt_alloc = (vpt_start - dsi.v_start) + alloc_start;
  46.377 -
  46.378 -    SET_GDT_ENTRIES(ed, DEFAULT_GDT_ENTRIES);
  46.379 -    SET_GDT_ADDRESS(ed, DEFAULT_GDT_ADDRESS);
  46.380 -
  46.381 -    /*
  46.382 -     * We're basically forcing default RPLs to 1, so that our "what privilege
  46.383 -     * level are we returning to?" logic works.
  46.384 -     */
  46.385 -    ed->thread.failsafe_selector = FLAT_GUESTOS_CS;
  46.386 -    ed->thread.event_selector    = FLAT_GUESTOS_CS;
  46.387 -    ed->thread.guestos_ss = FLAT_GUESTOS_DS;
  46.388 -    for ( i = 0; i < 256; i++ ) 
  46.389 -        ed->thread.traps[i].cs = FLAT_GUESTOS_CS;
  46.390 -
  46.391 -    /* WARNING: The new domain must have its 'processor' field filled in! */
  46.392 -    l2start = l2tab = (l2_pgentry_t *)mpt_alloc; mpt_alloc += PAGE_SIZE;
  46.393 -    memcpy(l2tab, &idle_pg_table[0], PAGE_SIZE);
  46.394 -    l2tab[LINEAR_PT_VIRT_START >> L2_PAGETABLE_SHIFT] =
  46.395 -        mk_l2_pgentry((unsigned long)l2start | __PAGE_HYPERVISOR);
  46.396 -    l2tab[PERDOMAIN_VIRT_START >> L2_PAGETABLE_SHIFT] =
  46.397 -        mk_l2_pgentry(__pa(p->mm_perdomain_pt) | __PAGE_HYPERVISOR);
  46.398 -    ed->mm.pagetable = mk_pagetable((unsigned long)l2start);
  46.399 -
  46.400 -    l2tab += l2_table_offset(dsi.v_start);
  46.401 -    mfn = alloc_start >> PAGE_SHIFT;
  46.402 -    for ( count = 0; count < ((v_end-dsi.v_start)>>PAGE_SHIFT); count++ )
  46.403 -    {
  46.404 -        if ( !((unsigned long)l1tab & (PAGE_SIZE-1)) )
  46.405 -        {
  46.406 -            l1start = l1tab = (l1_pgentry_t *)mpt_alloc; 
  46.407 -            mpt_alloc += PAGE_SIZE;
  46.408 -            *l2tab++ = mk_l2_pgentry((unsigned long)l1start | L2_PROT);
  46.409 -            clear_page(l1tab);
  46.410 -            if ( count == 0 )
  46.411 -                l1tab += l1_table_offset(dsi.v_start);
  46.412 -        }
  46.413 -        *l1tab++ = mk_l1_pgentry((mfn << PAGE_SHIFT) | L1_PROT);
  46.414 -        
  46.415 -        page = &frame_table[mfn];
  46.416 -        if ( !get_page_and_type(page, p, PGT_writable_page) )
  46.417 -            BUG();
  46.418 -
  46.419 -        mfn++;
  46.420 -    }
  46.421 -
  46.422 -    /* Pages that are part of page tables must be read only. */
  46.423 -    l2tab = l2start + l2_table_offset(vpt_start);
  46.424 -    l1start = l1tab = (l1_pgentry_t *)l2_pgentry_to_phys(*l2tab);
  46.425 -    l1tab += l1_table_offset(vpt_start);
  46.426 -    l2tab++;
  46.427 -    for ( count = 0; count < nr_pt_pages; count++ ) 
  46.428 -    {
  46.429 -        *l1tab = mk_l1_pgentry(l1_pgentry_val(*l1tab) & ~_PAGE_RW);
  46.430 -        page = &frame_table[l1_pgentry_to_pagenr(*l1tab)];
  46.431 -        if ( count == 0 )
  46.432 -        {
  46.433 -            page->u.inuse.type_info &= ~PGT_type_mask;
  46.434 -            page->u.inuse.type_info |= PGT_l2_page_table;
  46.435 -
  46.436 -            /*
  46.437 -             * No longer writable: decrement the type_count.
  46.438 -             * Installed as CR3: increment both the ref_count and type_count.
  46.439 -             * Net: just increment the ref_count.
  46.440 -             */
  46.441 -            get_page(page, p); /* an extra ref because of readable mapping */
  46.442 -
  46.443 -            /* Get another ref to L2 page so that it can be pinned. */
  46.444 -            if ( !get_page_and_type(page, p, PGT_l2_page_table) )
  46.445 -                BUG();
  46.446 -            set_bit(_PGT_pinned, &page->u.inuse.type_info);
  46.447 -        }
  46.448 -        else
  46.449 -        {
  46.450 -            page->u.inuse.type_info &= ~PGT_type_mask;
  46.451 -            page->u.inuse.type_info |= PGT_l1_page_table;
  46.452 -	    page->u.inuse.type_info |= 
  46.453 -		((dsi.v_start>>L2_PAGETABLE_SHIFT)+(count-1))<<PGT_va_shift;
  46.454 -
  46.455 -            /*
  46.456 -             * No longer writable: decrement the type_count.
  46.457 -             * This is an L1 page, installed in a validated L2 page:
  46.458 -             * increment both the ref_count and type_count.
  46.459 -             * Net: just increment the ref_count.
  46.460 -             */
  46.461 -            get_page(page, p); /* an extra ref because of readable mapping */
  46.462 -        }
  46.463 -        l1tab++;
  46.464 -        if( !((unsigned long)l1tab & (PAGE_SIZE - 1)) )
  46.465 -            l1start = l1tab = (l1_pgentry_t *)l2_pgentry_to_phys(*l2tab);
  46.466 -    }
  46.467 -
  46.468 -    /* Set up shared-info area. */
  46.469 -    update_dom_time(p);
  46.470 -    p->shared_info->domain_time = 0;
  46.471 -    /* Mask all upcalls... */
  46.472 -    for ( i = 0; i < MAX_VIRT_CPUS; i++ )
  46.473 -        p->shared_info->vcpu_data[i].evtchn_upcall_mask = 1;
  46.474 -    p->shared_info->n_vcpu = smp_num_cpus;
  46.475 -
  46.476 -    /* Install the new page tables. */
  46.477 -    __cli();
  46.478 -    write_ptbase(&ed->mm);
  46.479 -
  46.480 -    /* Copy the OS image. */
  46.481 -    (void)loadelfimage(image_start);
  46.482 -
  46.483 -    /* Copy the initial ramdisk. */
  46.484 -    if ( initrd_len != 0 )
  46.485 -        memcpy((void *)vinitrd_start, initrd_start, initrd_len);
  46.486 -    
  46.487 -    /* Set up start info area. */
  46.488 -    si = (start_info_t *)vstartinfo_start;
  46.489 -    memset(si, 0, PAGE_SIZE);
  46.490 -    si->nr_pages     = p->tot_pages;
  46.491 -    si->shared_info  = virt_to_phys(p->shared_info);
  46.492 -    si->flags        = SIF_PRIVILEGED | SIF_INITDOMAIN;
  46.493 -    si->pt_base      = vpt_start;
  46.494 -    si->nr_pt_frames = nr_pt_pages;
  46.495 -    si->mfn_list     = vphysmap_start;
  46.496 -
  46.497 -    /* Write the phys->machine and machine->phys table entries. */
  46.498 -    for ( pfn = 0; pfn < p->tot_pages; pfn++ )
  46.499 -    {
  46.500 -        mfn = pfn + (alloc_start>>PAGE_SHIFT);
  46.501 -#ifndef NDEBUG
  46.502 -#define REVERSE_START ((v_end - dsi.v_start) >> PAGE_SHIFT)
  46.503 -        if ( pfn > REVERSE_START )
  46.504 -            mfn = (alloc_end>>PAGE_SHIFT) - (pfn - REVERSE_START);
  46.505 -#endif
  46.506 -        ((unsigned long *)vphysmap_start)[pfn] = mfn;
  46.507 -        machine_to_phys_mapping[mfn] = pfn;
  46.508 -    }
  46.509 -
  46.510 -    if ( initrd_len != 0 )
  46.511 -    {
  46.512 -        si->mod_start = vinitrd_start;
  46.513 -        si->mod_len   = initrd_len;
  46.514 -        printk("Initrd len 0x%lx, start at 0x%08lx\n",
  46.515 -               si->mod_len, si->mod_start);
  46.516 -    }
  46.517 -
  46.518 -    dst = si->cmd_line;
  46.519 -    if ( cmdline != NULL )
  46.520 -    {
  46.521 -        for ( i = 0; i < 255; i++ )
  46.522 -        {
  46.523 -            if ( cmdline[i] == '\0' )
  46.524 -                break;
  46.525 -            *dst++ = cmdline[i];
  46.526 -        }
  46.527 -    }
  46.528 -    *dst = '\0';
  46.529 -
  46.530 -    /* Reinstate the caller's page tables. */
  46.531 -    write_ptbase(&current->mm);
  46.532 -    __sti();
  46.533 -
  46.534 -    /* Destroy low mappings - they were only for our convenience. */
  46.535 -    for ( i = 0; i < DOMAIN_ENTRIES_PER_L2_PAGETABLE; i++ )
  46.536 -        if ( l2_pgentry_val(l2start[i]) & _PAGE_PSE )
  46.537 -            l2start[i] = mk_l2_pgentry(0);
  46.538 -    zap_low_mappings(); /* Do the same for the idle page tables. */
  46.539 -    
  46.540 -    /* DOM0 gets access to everything. */
  46.541 -    physdev_init_dom0(p);
  46.542 -
  46.543 -    set_bit(DF_CONSTRUCTED, &p->d_flags);
  46.544 -
  46.545 -    new_thread(ed, dsi.v_kernentry, vstack_end, vstartinfo_start);
  46.546 -
  46.547 -#if 0 /* XXXXX DO NOT CHECK IN ENABLED !!! (but useful for testing so leave) */
  46.548 -    shadow_lock(&p->mm);
  46.549 -    shadow_mode_enable(p, SHM_test); 
  46.550 -    shadow_unlock(&p->mm);
  46.551 -#endif
  46.552 -
  46.553 -    return 0;
  46.554 -}
    47.1 --- a/xen/arch/x86/irq.c	Fri Jan 28 14:53:32 2005 +0000
    47.2 +++ b/xen/arch/x86/irq.c	Fri Feb 04 14:44:18 2005 +0000
    47.3 @@ -87,13 +87,9 @@ void enable_irq(unsigned int irq)
    47.4      spin_unlock_irqrestore(&desc->lock, flags);
    47.5  }
    47.6  
    47.7 -asmlinkage void do_IRQ(struct xen_regs regs)
    47.8 +asmlinkage void do_IRQ(struct xen_regs *regs)
    47.9  {       
   47.10 -#if defined(__i386__)
   47.11 -    unsigned int      irq = regs.entry_vector;
   47.12 -#else
   47.13 -    unsigned int      irq = 0; /* XXX */
   47.14 -#endif
   47.15 +    unsigned int      irq = regs->entry_vector;
   47.16      irq_desc_t       *desc = &irq_desc[irq];
   47.17      struct irqaction *action;
   47.18  
   47.19 @@ -127,7 +123,7 @@ asmlinkage void do_IRQ(struct xen_regs r
   47.20          desc->status &= ~IRQ_PENDING;
   47.21          irq_enter(smp_processor_id(), irq);
   47.22          spin_unlock_irq(&desc->lock);
   47.23 -        action->handler(irq, action->dev_id, &regs);
   47.24 +        action->handler(irq, action->dev_id, regs);
   47.25          spin_lock_irq(&desc->lock);
   47.26          irq_exit(smp_processor_id(), irq);
   47.27      }
   47.28 @@ -260,7 +256,7 @@ int pirq_guest_bind(struct exec_domain *
   47.29              goto out;
   47.30          }
   47.31  
   47.32 -        action = xmalloc(sizeof(irq_guest_action_t));
   47.33 +        action = xmalloc(irq_guest_action_t);
   47.34          if ( (desc->action = (struct irqaction *)action) == NULL )
   47.35          {
   47.36              DPRINTK("Cannot bind IRQ %d to guest. Out of memory.\n", irq);
    48.1 --- a/xen/arch/x86/memory.c	Fri Jan 28 14:53:32 2005 +0000
    48.2 +++ b/xen/arch/x86/memory.c	Fri Feb 04 14:44:18 2005 +0000
    48.3 @@ -148,7 +148,6 @@ unsigned long max_page;
    48.4  
    48.5  void __init init_frametable(void)
    48.6  {
    48.7 -#ifdef __i386__
    48.8      unsigned long i, p;
    48.9  
   48.10      frame_table      = (struct pfn_info *)FRAMETABLE_VIRT_START;
   48.11 @@ -160,40 +159,19 @@ void __init init_frametable(void)
   48.12          p = alloc_boot_pages(min(frame_table_size - i, 4UL << 20), 4UL << 20);
   48.13          if ( p == 0 )
   48.14              panic("Not enough memory for frame table\n");
   48.15 -        idle_pg_table[(FRAMETABLE_VIRT_START + i) >> L2_PAGETABLE_SHIFT] =
   48.16 -            mk_l2_pgentry(p | __PAGE_HYPERVISOR | _PAGE_PSE);
   48.17 +        map_pages(idle_pg_table, FRAMETABLE_VIRT_START + i, p, 
   48.18 +                  4UL << 20, PAGE_HYPERVISOR);
   48.19      }
   48.20  
   48.21      memset(frame_table, 0, frame_table_size);
   48.22 -#endif
   48.23  }
   48.24  
   48.25  void arch_init_memory(void)
   48.26  {
   48.27 -    unsigned long i;
   48.28 -
   48.29 -    /*
   48.30 -     * We are rather picky about the layout of 'struct pfn_info'. The
   48.31 -     * count_info and domain fields must be adjacent, as we perform atomic
   48.32 -     * 64-bit operations on them. Also, just for sanity, we assert the size
   48.33 -     * of the structure here.
   48.34 -     */
   48.35 -    if ( (offsetof(struct pfn_info, u.inuse.domain) != 
   48.36 -          (offsetof(struct pfn_info, count_info) + sizeof(u32))) ||
   48.37 -         (sizeof(struct pfn_info) != 24) )
   48.38 -    {
   48.39 -        printk("Weird pfn_info layout (%ld,%ld,%d)\n",
   48.40 -               offsetof(struct pfn_info, count_info),
   48.41 -               offsetof(struct pfn_info, u.inuse.domain),
   48.42 -               sizeof(struct pfn_info));
   48.43 -        for ( ; ; ) ;
   48.44 -    }
   48.45 +    extern void subarch_init_memory(struct domain *);
   48.46  
   48.47      memset(percpu_info, 0, sizeof(percpu_info));
   48.48  
   48.49 -    /* Initialise to a magic of 0x55555555 so easier to spot bugs later. */
   48.50 -    memset(machine_to_phys_mapping, 0x55, 4<<20);
   48.51 -
   48.52      /*
   48.53       * Initialise our DOMID_XEN domain.
   48.54       * Any Xen-heap pages that we will allow to be mapped will have
   48.55 @@ -212,15 +190,7 @@ void arch_init_memory(void)
   48.56      atomic_set(&dom_io->refcnt, 1);
   48.57      dom_io->id = DOMID_IO;
   48.58  
   48.59 -    /* M2P table is mappable read-only by privileged domains. */
   48.60 -    for ( i = 0; i < 1024; i++ )
   48.61 -    {
   48.62 -        frame_table[m2p_start_mfn+i].count_info        = PGC_allocated | 1;
   48.63 -	/* gdt to make sure it's only mapped read-only by non-privileged
   48.64 -	   domains. */
   48.65 -        frame_table[m2p_start_mfn+i].u.inuse.type_info = PGT_gdt_page | 1;
   48.66 -        frame_table[m2p_start_mfn+i].u.inuse.domain    = dom_xen;
   48.67 -    }
   48.68 +    subarch_init_memory(dom_xen);
   48.69  }
   48.70  
   48.71  static void __invalidate_shadow_ldt(struct exec_domain *d)
   48.72 @@ -474,7 +444,7 @@ static void put_page_from_l1e(l1_pgentry
   48.73      if ( !(l1v & _PAGE_PRESENT) || !pfn_is_ram(pfn) )
   48.74          return;
   48.75  
   48.76 -    e = page->u.inuse.domain;
   48.77 +    e = page_get_owner(page);
   48.78      if ( unlikely(e != d) )
   48.79      {
   48.80          /*
   48.81 @@ -523,7 +493,7 @@ static void put_page_from_l2e(l2_pgentry
   48.82  
   48.83  static int alloc_l2_table(struct pfn_info *page)
   48.84  {
   48.85 -    struct domain *d = page->u.inuse.domain;
   48.86 +    struct domain *d = page_get_owner(page);
   48.87      unsigned long  page_nr = page_to_pfn(page);
   48.88      l2_pgentry_t  *pl2e;
   48.89      int            i;
   48.90 @@ -542,7 +512,7 @@ static int alloc_l2_table(struct pfn_inf
   48.91      pl2e[LINEAR_PT_VIRT_START >> L2_PAGETABLE_SHIFT] =
   48.92          mk_l2_pgentry((page_nr << PAGE_SHIFT) | __PAGE_HYPERVISOR);
   48.93      pl2e[PERDOMAIN_VIRT_START >> L2_PAGETABLE_SHIFT] =
   48.94 -        mk_l2_pgentry(__pa(page->u.inuse.domain->mm_perdomain_pt) | 
   48.95 +        mk_l2_pgentry(__pa(page_get_owner(page)->mm_perdomain_pt) | 
   48.96                        __PAGE_HYPERVISOR);
   48.97  #endif
   48.98  
   48.99 @@ -560,7 +530,7 @@ static int alloc_l2_table(struct pfn_inf
  48.100  
  48.101  static int alloc_l1_table(struct pfn_info *page)
  48.102  {
  48.103 -    struct domain *d = page->u.inuse.domain;
  48.104 +    struct domain *d = page_get_owner(page);
  48.105      unsigned long  page_nr = page_to_pfn(page);
  48.106      l1_pgentry_t  *pl1e;
  48.107      int            i;
  48.108 @@ -600,7 +570,7 @@ static void free_l2_table(struct pfn_inf
  48.109  
  48.110  static void free_l1_table(struct pfn_info *page)
  48.111  {
  48.112 -    struct domain *d = page->u.inuse.domain;
  48.113 +    struct domain *d = page_get_owner(page);
  48.114      unsigned long page_nr = page - frame_table;
  48.115      l1_pgentry_t *pl1e;
  48.116      int i;
  48.117 @@ -761,7 +731,7 @@ int alloc_page_type(struct pfn_info *pag
  48.118  
  48.119  void free_page_type(struct pfn_info *page, unsigned int type)
  48.120  {
  48.121 -    struct domain *d = page->u.inuse.domain;
  48.122 +    struct domain *d = page_get_owner(page);
  48.123  
  48.124      switch ( type )
  48.125      {
  48.126 @@ -804,7 +774,7 @@ void put_page_type(struct pfn_info *page
  48.127           * See domain.c:relinquish_list().
  48.128           */
  48.129          ASSERT((x & PGT_validated) || 
  48.130 -               test_bit(DF_DYING, &page->u.inuse.domain->d_flags));
  48.131 +               test_bit(DF_DYING, &page_get_owner(page)->d_flags));
  48.132  
  48.133          if ( unlikely((nx & PGT_count_mask) == 0) )
  48.134          {
  48.135 @@ -862,7 +832,7 @@ int get_page_type(struct pfn_info *page,
  48.136                   * may be unnecessary (e.g., page was GDT/LDT) but those
  48.137                   * circumstances should be very rare.
  48.138                   */
  48.139 -                struct domain *d = page->u.inuse.domain;
  48.140 +                struct domain *d = page_get_owner(page);
  48.141                  if ( unlikely(NEED_FLUSH(tlbflush_time[d->exec_domain[0]->processor],
  48.142                                           page->tlbflush_timestamp)) )
  48.143                  {
  48.144 @@ -1017,7 +987,7 @@ static int do_extended_command(unsigned 
  48.145          if ( unlikely(!(okay = get_page_from_pagenr(pfn, FOREIGNDOM))) )
  48.146          {
  48.147              MEM_LOG("Page %08lx bad domain (dom=%p)",
  48.148 -                    ptr, page->u.inuse.domain);
  48.149 +                    ptr, page_get_owner(page));
  48.150          }
  48.151          else if ( likely(test_and_clear_bit(_PGT_pinned, 
  48.152                                              &page->u.inuse.type_info)) )
  48.153 @@ -1147,7 +1117,7 @@ static int do_extended_command(unsigned 
  48.154           * benign reference to the page (PGC_allocated). If that reference
  48.155           * disappears then the deallocation routine will safely spin.
  48.156           */
  48.157 -        nd = page->u.inuse.domain;
  48.158 +        nd = page_get_owner(page);
  48.159          y  = page->count_info;
  48.160          do {
  48.161              x = y;
  48.162 @@ -1203,7 +1173,7 @@ static int do_extended_command(unsigned 
  48.163          if ( unlikely(e->tot_pages++ == 0) )
  48.164              get_knownalive_domain(e);
  48.165          list_add_tail(&page->list, &e->page_list);
  48.166 -        page->u.inuse.domain = e;
  48.167 +        page_set_owner(page, e);
  48.168  
  48.169          spin_unlock(&e->page_alloc_lock);
  48.170  
  48.171 @@ -1259,7 +1229,7 @@ static int do_extended_command(unsigned 
  48.172           * benign reference to the page (PGC_allocated). If that reference
  48.173           * disappears then the deallocation routine will safely spin.
  48.174           */
  48.175 -        nd = page->u.inuse.domain;
  48.176 +        nd = page_get_owner(page);
  48.177          y  = page->count_info;
  48.178          do {
  48.179              x = y;
  48.180 @@ -2102,7 +2072,7 @@ void audit_domain(struct domain *d)
  48.181          pfn = list_entry(list_ent, struct pfn_info, list) - frame_table;       
  48.182          page = &frame_table[pfn];
  48.183  
  48.184 -        if ( page->u.inuse.domain != d )
  48.185 +        if ( page_get_owner(page) != d )
  48.186              BUG();
  48.187  
  48.188          if ( (page->u.inuse.type_info & PGT_count_mask) >
  48.189 @@ -2148,7 +2118,7 @@ void audit_domain(struct domain *d)
  48.190          pfn = list_entry(list_ent, struct pfn_info, list) - frame_table;       
  48.191          page = &frame_table[pfn];
  48.192  
  48.193 -        if ( page->u.inuse.domain != d )
  48.194 +        if ( page_get_owner(page) != d )
  48.195              BUG();
  48.196  
  48.197          switch ( page->u.inuse.type_info & PGT_type_mask )
  48.198 @@ -2174,10 +2144,10 @@ void audit_domain(struct domain *d)
  48.199                      unsigned long l1pfn = pt[i]>>PAGE_SHIFT;
  48.200                      struct pfn_info *l1page = &frame_table[l1pfn];
  48.201  
  48.202 -                    if ( l1page->u.inuse.domain != d )
  48.203 +                    if ( page_get_owner(l1page) != d )
  48.204                      {
  48.205                          printk("L2: Skip bizarre page belonging to other "
  48.206 -                               "dom %p\n", l1page->u.inuse.domain);    
  48.207 +                               "dom %p\n", page_get_owner(l1page));
  48.208                          continue;
  48.209                      }
  48.210                      
  48.211 @@ -2252,12 +2222,12 @@ void audit_domain(struct domain *d)
  48.212  
  48.213                      }
  48.214  
  48.215 -                    if ( l1page->u.inuse.domain != d )
  48.216 +                    if ( page_get_owner(l1page) != d )
  48.217                      {
  48.218 -                        printk("Audit %d: [%lx,%x] Skip foreign page dom=%lx "
  48.219 +                        printk("Audit %d: [%lx,%x] Skip foreign page dom=%p "
  48.220                                 "pfn=%lx c=%08x t=%08x m2p=%lx\n",
  48.221                                 d->id, pfn, i,
  48.222 -                               (unsigned long)l1page->u.inuse.domain,
  48.223 +                               page_get_owner(l1page),
  48.224                                 l1pfn,
  48.225                                 l1page->count_info,
  48.226                                 l1page->u.inuse.type_info,
  48.227 @@ -2342,7 +2312,7 @@ void audit_domain(struct domain *d)
  48.228                      unsigned long l1pfn = pt[i]>>PAGE_SHIFT;
  48.229                      struct pfn_info *l1page = &frame_table[l1pfn];
  48.230  
  48.231 -                    if ( l1page->u.inuse.domain == d)
  48.232 +                    if ( page_get_owner(l1page) == d )
  48.233                          adjust(l1page, 1, 1);
  48.234                  }
  48.235              }
  48.236 @@ -2363,7 +2333,7 @@ void audit_domain(struct domain *d)
  48.237                      unsigned long l1pfn = pt[i]>>PAGE_SHIFT;
  48.238                      struct pfn_info *l1page = &frame_table[l1pfn];
  48.239  
  48.240 -                    if ( (l1page->u.inuse.domain != d) ||
  48.241 +                    if ( (page_get_owner(l1page) != d) ||
  48.242                           (l1pfn < 0x100) || (l1pfn > max_page) )
  48.243                          continue;
  48.244  
    49.1 --- a/xen/arch/x86/microcode.c	Fri Jan 28 14:53:32 2005 +0000
    49.2 +++ b/xen/arch/x86/microcode.c	Fri Feb 04 14:44:18 2005 +0000
    49.3 @@ -84,7 +84,7 @@
    49.4  #define DECLARE_MUTEX(_m) spinlock_t _m = SPIN_LOCK_UNLOCKED
    49.5  #define down(_m) spin_lock(_m)
    49.6  #define up(_m) spin_unlock(_m)
    49.7 -#define vmalloc(_s) xmalloc(_s)
    49.8 +#define vmalloc(_s) xmalloc_bytes(_s)
    49.9  #define vfree(_p) xfree(_p)
   49.10  #define num_online_cpus() smp_num_cpus
   49.11  static inline int on_each_cpu(
    50.1 --- a/xen/arch/x86/mpparse.c	Fri Jan 28 14:53:32 2005 +0000
    50.2 +++ b/xen/arch/x86/mpparse.c	Fri Feb 04 14:44:18 2005 +0000
    50.3 @@ -859,7 +859,7 @@ void __init get_smp_config (void)
    50.4  
    50.5  static int __init smp_scan_config (unsigned long base, unsigned long length)
    50.6  {
    50.7 -	unsigned long *bp = phys_to_virt(base);
    50.8 +	unsigned int *bp = phys_to_virt(base);
    50.9  	struct intel_mp_floating *mpf;
   50.10  
   50.11  	Dprintk("Scan SMP from %p for %ld bytes.\n", bp,length);
    51.1 --- a/xen/arch/x86/mtrr/generic.c	Fri Jan 28 14:53:32 2005 +0000
    51.2 +++ b/xen/arch/x86/mtrr/generic.c	Fri Feb 04 14:44:18 2005 +0000
    51.3 @@ -52,7 +52,8 @@ void __init get_mtrr_state(void)
    51.4  	unsigned lo, dummy;
    51.5  
    51.6  	if (!mtrr_state.var_ranges) {
    51.7 -		mtrr_state.var_ranges = xmalloc(num_var_ranges * sizeof (struct mtrr_var_range));
    51.8 +		mtrr_state.var_ranges = xmalloc_array(struct mtrr_var_range,
    51.9 +						  num_var_ranges);
   51.10  		if (!mtrr_state.var_ranges)
   51.11  			return;
   51.12  	} 
    52.1 --- a/xen/arch/x86/mtrr/main.c	Fri Jan 28 14:53:32 2005 +0000
    52.2 +++ b/xen/arch/x86/mtrr/main.c	Fri Feb 04 14:44:18 2005 +0000
    52.3 @@ -136,8 +136,7 @@ static void __init init_table(void)
    52.4  	int i, max;
    52.5  
    52.6  	max = num_var_ranges;
    52.7 -	if ((usage_table = xmalloc(max * sizeof *usage_table))
    52.8 -	    == NULL) {
    52.9 +	if ((usage_table = xmalloc_array(unsigned int, max)) == NULL) {
   52.10  		printk(KERN_ERR "mtrr: could not allocate\n");
   52.11  		return;
   52.12  	}
    53.1 --- a/xen/arch/x86/pci-pc.c	Fri Jan 28 14:53:32 2005 +0000
    53.2 +++ b/xen/arch/x86/pci-pc.c	Fri Feb 04 14:44:18 2005 +0000
    53.3 @@ -1036,7 +1036,7 @@ struct irq_routing_table * __devinit pci
    53.4  	if (ret & 0xff00)
    53.5  		printk(KERN_ERR "PCI: Error %02x when fetching IRQ routing table.\n", (ret >> 8) & 0xff);
    53.6  	else if (opt.size) {
    53.7 -		rt = xmalloc(sizeof(struct irq_routing_table) + opt.size);
    53.8 +		rt = xmalloc_bytes(sizeof(struct irq_routing_table) + opt.size);
    53.9  		if (rt) {
   53.10  			memset(rt, 0, sizeof(struct irq_routing_table));
   53.11  			rt->size = opt.size + sizeof(struct irq_routing_table);
    54.1 --- a/xen/arch/x86/setup.c	Fri Jan 28 14:53:32 2005 +0000
    54.2 +++ b/xen/arch/x86/setup.c	Fri Feb 04 14:44:18 2005 +0000
    54.3 @@ -55,6 +55,8 @@ boolean_param("ignorebiostables", opt_ig
    54.4  static int opt_watchdog = 0;
    54.5  boolean_param("watchdog", opt_watchdog);
    54.6  
    54.7 +int early_boot = 1;
    54.8 +
    54.9  unsigned long xenheap_phys_end;
   54.10  
   54.11  extern void arch_init_memory(void);
   54.12 @@ -89,23 +91,21 @@ EXPORT_SYMBOL(acpi_disabled);
   54.13  int phys_proc_id[NR_CPUS];
   54.14  int logical_proc_id[NR_CPUS];
   54.15  
   54.16 -#if defined(__i386__)
   54.17 -
   54.18 -/* Standard macro to see if a specific flag is changeable */
   54.19 -static inline int flag_is_changeable_p(u32 flag)
   54.20 +/* Standard macro to see if a specific flag is changeable. */
   54.21 +static inline int flag_is_changeable_p(unsigned long flag)
   54.22  {
   54.23 -    u32 f1, f2;
   54.24 +    unsigned long f1, f2;
   54.25  
   54.26 -    asm("pushfl\n\t"
   54.27 -        "pushfl\n\t"
   54.28 -        "popl %0\n\t"
   54.29 -        "movl %0,%1\n\t"
   54.30 -        "xorl %2,%0\n\t"
   54.31 -        "pushl %0\n\t"
   54.32 -        "popfl\n\t"
   54.33 -        "pushfl\n\t"
   54.34 -        "popl %0\n\t"
   54.35 -        "popfl\n\t"
   54.36 +    asm("pushf\n\t"
   54.37 +        "pushf\n\t"
   54.38 +        "pop %0\n\t"
   54.39 +        "mov %0,%1\n\t"
   54.40 +        "xor %2,%0\n\t"
   54.41 +        "push %0\n\t"
   54.42 +        "popf\n\t"
   54.43 +        "pushf\n\t"
   54.44 +        "pop %0\n\t"
   54.45 +        "popf\n\t"
   54.46          : "=&r" (f1), "=&r" (f2)
   54.47          : "ir" (flag));
   54.48  
   54.49 @@ -118,12 +118,6 @@ static int __init have_cpuid_p(void)
   54.50      return flag_is_changeable_p(X86_EFLAGS_ID);
   54.51  }
   54.52  
   54.53 -#elif defined(__x86_64__)
   54.54 -
   54.55 -#define have_cpuid_p() (1)
   54.56 -
   54.57 -#endif
   54.58 -
   54.59  void __init get_cpu_vendor(struct cpuinfo_x86 *c)
   54.60  {
   54.61      char *v = c->x86_vendor_id;
   54.62 @@ -304,38 +298,40 @@ void __init identify_cpu(struct cpuinfo_
   54.63  unsigned long cpu_initialized;
   54.64  void __init cpu_init(void)
   54.65  {
   54.66 -#if defined(__i386__) /* XXX */
   54.67      int nr = smp_processor_id();
   54.68 -    struct tss_struct * t = &init_tss[nr];
   54.69 +    struct tss_struct *t = &init_tss[nr];
   54.70  
   54.71      if ( test_and_set_bit(nr, &cpu_initialized) )
   54.72          panic("CPU#%d already initialized!!!\n", nr);
   54.73      printk("Initializing CPU#%d\n", nr);
   54.74  
   54.75 -    t->bitmap = IOBMP_INVALID_OFFSET;
   54.76 -    memset(t->io_bitmap, ~0, sizeof(t->io_bitmap));
   54.77 -
   54.78      /* Set up GDT and IDT. */
   54.79      SET_GDT_ENTRIES(current, DEFAULT_GDT_ENTRIES);
   54.80      SET_GDT_ADDRESS(current, DEFAULT_GDT_ADDRESS);
   54.81 -    __asm__ __volatile__("lgdt %0": "=m" (*current->mm.gdt));
   54.82 -    __asm__ __volatile__("lidt %0": "=m" (idt_descr));
   54.83 +    __asm__ __volatile__ ( "lgdt %0" : "=m" (*current->mm.gdt) );
   54.84 +    __asm__ __volatile__ ( "lidt %0" : "=m" (idt_descr) );
   54.85  
   54.86      /* No nested task. */
   54.87 -    __asm__("pushfl ; andl $0xffffbfff,(%esp) ; popfl");
   54.88 +    __asm__ __volatile__ ( "pushf ; andw $0xbfff,(%"__OP"sp) ; popf" );
   54.89  
   54.90      /* Ensure FPU gets initialised for each domain. */
   54.91      stts();
   54.92  
   54.93      /* Set up and load the per-CPU TSS and LDT. */
   54.94 +    t->bitmap = IOBMP_INVALID_OFFSET;
   54.95 +    memset(t->io_bitmap, ~0, sizeof(t->io_bitmap));
   54.96 +#if defined(__i386__)
   54.97      t->ss0  = __HYPERVISOR_DS;
   54.98      t->esp0 = get_stack_top();
   54.99 +#elif defined(__x86_64__)
  54.100 +    t->rsp0 = get_stack_top();
  54.101 +#endif
  54.102      set_tss_desc(nr,t);
  54.103      load_TR(nr);
  54.104 -    __asm__ __volatile__("lldt %%ax"::"a" (0));
  54.105 +    __asm__ __volatile__ ( "lldt %%ax" : : "a" (0) );
  54.106  
  54.107      /* Clear all 6 debug registers. */
  54.108 -#define CD(register) __asm__("movl %0,%%db" #register ::"r"(0) );
  54.109 +#define CD(register) __asm__ ( "mov %0,%%db" #register : : "r" (0UL) );
  54.110      CD(0); CD(1); CD(2); CD(3); /* no db4 and db5 */; CD(6); CD(7);
  54.111  #undef CD
  54.112  
  54.113 @@ -343,7 +339,6 @@ void __init cpu_init(void)
  54.114      write_ptbase(&current->mm);
  54.115  
  54.116      init_idle_task();
  54.117 -#endif
  54.118  }
  54.119  
  54.120  static void __init do_initcalls(void)
  54.121 @@ -464,6 +459,9 @@ static void __init start_of_day(void)
  54.122  #endif
  54.123  
  54.124      watchdog_on = 1;
  54.125 +#ifdef __x86_64__ /* x86_32 uses low mappings when building DOM0. */
  54.126 +    zap_low_mappings();
  54.127 +#endif
  54.128  }
  54.129  
  54.130  void __init __start_xen(multiboot_info_t *mbi)
  54.131 @@ -594,12 +592,12 @@ void __init __start_xen(multiboot_info_t
  54.132  	   (xenheap_phys_end-__pa(heap_start)) >> 20,
  54.133  	   (xenheap_phys_end-__pa(heap_start)) >> 10);
  54.134  
  54.135 +    early_boot = 0;
  54.136 +
  54.137      /* Initialise the slab allocator. */
  54.138      xmem_cache_init();
  54.139      xmem_cache_sizes_init(max_page);
  54.140  
  54.141 -    domain_startofday();
  54.142 -
  54.143      start_of_day();
  54.144  
  54.145      grant_table_init();
  54.146 @@ -627,10 +625,10 @@ void __init __start_xen(multiboot_info_t
  54.147       * above our heap. The second module, if present, is an initrd ramdisk.
  54.148       */
  54.149      if ( construct_dom0(dom0, dom0_memory_start, dom0_memory_end,
  54.150 -                        (char *)initial_images_start, 
  54.151 +                        initial_images_start, 
  54.152                          mod[0].mod_end-mod[0].mod_start,
  54.153                          (mbi->mods_count == 1) ? 0 :
  54.154 -                        (char *)initial_images_start + 
  54.155 +                        initial_images_start + 
  54.156                          (mod[1].mod_start-mod[0].mod_start),
  54.157                          (mbi->mods_count == 1) ? 0 :
  54.158                          mod[mbi->mods_count-1].mod_end - mod[1].mod_start,
    55.1 --- a/xen/arch/x86/shadow.c	Fri Jan 28 14:53:32 2005 +0000
    55.2 +++ b/xen/arch/x86/shadow.c	Fri Feb 04 14:44:18 2005 +0000
    55.3 @@ -176,8 +176,7 @@ int shadow_mode_enable(struct domain *p,
    55.4  {
    55.5      struct mm_struct *m = &p->exec_domain[0]->mm;
    55.6  
    55.7 -    m->shadow_ht = xmalloc(
    55.8 -        shadow_ht_buckets * sizeof(struct shadow_status));
    55.9 +    m->shadow_ht = xmalloc_array(struct shadow_status, shadow_ht_buckets);
   55.10      if ( m->shadow_ht == NULL )
   55.11          goto nomem;
   55.12      memset(m->shadow_ht, 0, shadow_ht_buckets * sizeof(struct shadow_status));
   55.13 @@ -186,7 +185,8 @@ int shadow_mode_enable(struct domain *p,
   55.14      {
   55.15          m->shadow_dirty_bitmap_size = (p->max_pages + 63) & ~63;
   55.16          m->shadow_dirty_bitmap = 
   55.17 -            xmalloc(m->shadow_dirty_bitmap_size/8);
   55.18 +            xmalloc_array(unsigned long, m->shadow_dirty_bitmap_size /
   55.19 +                                         (8 * sizeof(unsigned long)));
   55.20          if ( m->shadow_dirty_bitmap == NULL )
   55.21          {
   55.22              m->shadow_dirty_bitmap_size = 0;
   55.23 @@ -420,7 +420,7 @@ static inline struct pfn_info *alloc_sha
   55.24  void unshadow_table(unsigned long gpfn, unsigned int type)
   55.25  {
   55.26      unsigned long  spfn;
   55.27 -    struct domain *d = frame_table[gpfn].u.inuse.domain;
   55.28 +    struct domain *d = page_get_owner(&frame_table[gpfn]);
   55.29  
   55.30      SH_VLOG("unshadow_table type=%08x gpfn=%08lx", type, gpfn);
   55.31  
   55.32 @@ -494,7 +494,7 @@ unsigned long shadow_l2_table(
   55.33          spl2e[SH_LINEAR_PT_VIRT_START >> L2_PAGETABLE_SHIFT] =
   55.34              mk_l2_pgentry((spfn << PAGE_SHIFT) | __PAGE_HYPERVISOR);
   55.35          spl2e[PERDOMAIN_VIRT_START >> L2_PAGETABLE_SHIFT] =
   55.36 -            mk_l2_pgentry(__pa(frame_table[gpfn].u.inuse.domain->mm_perdomain_pt) |
   55.37 +            mk_l2_pgentry(__pa(page_get_owner(&frame_table[gpfn])->mm_perdomain_pt) |
   55.38  			  __PAGE_HYPERVISOR);
   55.39      }
   55.40  #endif
   55.41 @@ -924,7 +924,7 @@ int check_pagetable(struct mm_struct *m,
   55.42  
   55.43      if (m->shadow_mode != SHM_full_32) {
   55.44          if ( (l2_pgentry_val(spl2e[PERDOMAIN_VIRT_START >> L2_PAGETABLE_SHIFT]) !=
   55.45 -              ((__pa(frame_table[gpfn].u.inuse.domain->mm.perdomain_pt) | 
   55.46 +              ((__pa(page_get_owner(&frame_table[gpfn])->mm.perdomain_pt) | 
   55.47              __PAGE_HYPERVISOR))) )
   55.48              FAILPT("hypervisor per-domain map inconsistent");
   55.49      }
    56.1 --- a/xen/arch/x86/smpboot.c	Fri Jan 28 14:53:32 2005 +0000
    56.2 +++ b/xen/arch/x86/smpboot.c	Fri Feb 04 14:44:18 2005 +0000
    56.3 @@ -409,9 +409,9 @@ void __init start_secondary(void)
    56.4       * At this point, boot CPU has fully initialised the IDT. It is
    56.5       * now safe to make ourselves a private copy.
    56.6       */
    56.7 -    idt_tables[cpu] = xmalloc(IDT_ENTRIES*8);
    56.8 -    memcpy(idt_tables[cpu], idt_table, IDT_ENTRIES*8);
    56.9 -    *(unsigned short *)(&idt_load[0]) = (IDT_ENTRIES*8)-1;
   56.10 +    idt_tables[cpu] = xmalloc_array(idt_entry_t, IDT_ENTRIES);
   56.11 +    memcpy(idt_tables[cpu], idt_table, IDT_ENTRIES*sizeof(idt_entry_t));
   56.12 +    *(unsigned short *)(&idt_load[0]) = (IDT_ENTRIES*sizeof(idt_entry_t))-1;
   56.13      *(unsigned long  *)(&idt_load[2]) = (unsigned long)idt_tables[cpu];
   56.14      __asm__ __volatile__ ( "lidt %0" : "=m" (idt_load) );
   56.15  
   56.16 @@ -650,7 +650,8 @@ static void __init do_boot_cpu (int apic
   56.17      struct exec_domain *ed;
   56.18      unsigned long boot_error = 0;
   56.19      int timeout, cpu;
   56.20 -    unsigned long start_eip, stack;
   56.21 +    unsigned long start_eip;
   56.22 +    void *stack;
   56.23  
   56.24      cpu = ++cpucount;
   56.25  
   56.26 @@ -673,11 +674,15 @@ static void __init do_boot_cpu (int apic
   56.27      /* So we see what's up. */
   56.28      printk("Booting processor %d/%d eip %lx\n", cpu, apicid, start_eip);
   56.29  
   56.30 -    stack = __pa(alloc_xenheap_pages(1));
   56.31 -    stack_start.esp = stack + STACK_SIZE - STACK_RESERVED;
   56.32 +    stack = (void *)alloc_xenheap_pages(1);
   56.33 +#if defined(__i386__)
   56.34 +    stack_start.esp = __pa(stack) + STACK_SIZE - STACK_RESERVED;
   56.35 +#elif defined(__x86_64__)
   56.36 +    stack_start.esp = (unsigned long)stack + STACK_SIZE - STACK_RESERVED;
   56.37 +#endif
   56.38  
   56.39      /* Debug build: detect stack overflow by setting up a guard page. */
   56.40 -    memguard_guard_range(__va(stack), PAGE_SIZE);
   56.41 +    memguard_guard_range(stack, PAGE_SIZE);
   56.42  
   56.43      /*
   56.44       * This grunge runs the startup process for
   56.45 @@ -739,7 +744,7 @@ static void __init do_boot_cpu (int apic
   56.46              printk("CPU%d has booted.\n", cpu);
   56.47          } else {
   56.48              boot_error= 1;
   56.49 -            if (*((volatile unsigned long *)phys_to_virt(start_eip))
   56.50 +            if (*((volatile unsigned int *)phys_to_virt(start_eip))
   56.51                  == 0xA5A5A5A5)
   56.52  				/* trampoline started but...? */
   56.53                  printk("Stuck ??\n");
    57.1 --- a/xen/arch/x86/traps.c	Fri Jan 28 14:53:32 2005 +0000
    57.2 +++ b/xen/arch/x86/traps.c	Fri Feb 04 14:44:18 2005 +0000
    57.3 @@ -1,5 +1,5 @@
    57.4  /******************************************************************************
    57.5 - * arch/i386/traps.c
    57.6 + * arch/x86/traps.c
    57.7   * 
    57.8   * Modifications to Linux original are copyright (c) 2002-2004, K A Fraser
    57.9   * 
   57.10 @@ -66,20 +66,12 @@ char opt_nmi[10] = "fatal";
   57.11  #endif
   57.12  string_param("nmi", opt_nmi);
   57.13  
   57.14 -#if defined(__i386__)
   57.15 -
   57.16 -#define GUEST_FAULT(_r) (likely(VM86_MODE(_r) || !RING_0(_r)))
   57.17 -
   57.18 -#define DOUBLEFAULT_STACK_SIZE 1024
   57.19 -static struct tss_struct doublefault_tss;
   57.20 -static unsigned char doublefault_stack[DOUBLEFAULT_STACK_SIZE];
   57.21 -
   57.22  asmlinkage int hypercall(void);
   57.23  
   57.24  /* Master table, and the one used by CPU0. */
   57.25 -struct desc_struct idt_table[256] = { {0, 0}, };
   57.26 +idt_entry_t idt_table[IDT_ENTRIES] = { {0, 0}, };
   57.27  /* All other CPUs have their own copy. */
   57.28 -struct desc_struct *idt_tables[NR_CPUS] = { 0 };
   57.29 +idt_entry_t *idt_tables[NR_CPUS] = { 0 };
   57.30  
   57.31  asmlinkage void divide_error(void);
   57.32  asmlinkage void debug(void);
   57.33 @@ -101,116 +93,6 @@ asmlinkage void alignment_check(void);
   57.34  asmlinkage void spurious_interrupt_bug(void);
   57.35  asmlinkage void machine_check(void);
   57.36  
   57.37 -int kstack_depth_to_print = 8*20;
   57.38 -
   57.39 -static inline int kernel_text_address(unsigned long addr)
   57.40 -{
   57.41 -    if (addr >= (unsigned long) &_stext &&
   57.42 -        addr <= (unsigned long) &_etext)
   57.43 -        return 1;
   57.44 -    return 0;
   57.45 -
   57.46 -}
   57.47 -
   57.48 -void show_guest_stack()
   57.49 -{
   57.50 -    int i;
   57.51 -    execution_context_t *ec = get_execution_context();
   57.52 -    unsigned long *stack = (unsigned long *)ec->esp;
   57.53 -    printk("Guest EIP is %lx\n",ec->eip);
   57.54 -
   57.55 -    for ( i = 0; i < kstack_depth_to_print; i++ )
   57.56 -    {
   57.57 -        if ( ((long)stack & (STACK_SIZE-1)) == 0 )
   57.58 -            break;
   57.59 -        if ( i && ((i % 8) == 0) )
   57.60 -            printk("\n       ");
   57.61 -            printk("%08lx ", *stack++);            
   57.62 -    }
   57.63 -    printk("\n");
   57.64 -    
   57.65 -}
   57.66 -
   57.67 -void show_trace(unsigned long *esp)
   57.68 -{
   57.69 -    unsigned long *stack, addr;
   57.70 -    int i;
   57.71 -
   57.72 -    printk("Call Trace from ESP=%p: ", esp);
   57.73 -    stack = esp;
   57.74 -    i = 0;
   57.75 -    while (((long) stack & (STACK_SIZE-1)) != 0) {
   57.76 -        addr = *stack++;
   57.77 -        if (kernel_text_address(addr)) {
   57.78 -            if (i && ((i % 6) == 0))
   57.79 -                printk("\n   ");
   57.80 -            printk("[<%08lx>] ", addr);
   57.81 -            i++;
   57.82 -        }
   57.83 -    }
   57.84 -    printk("\n");
   57.85 -}
   57.86 -
   57.87 -void show_stack(unsigned long *esp)
   57.88 -{
   57.89 -    unsigned long *stack;
   57.90 -    int i;
   57.91 -
   57.92 -    printk("Stack trace from ESP=%p:\n", esp);
   57.93 -
   57.94 -    stack = esp;
   57.95 -    for ( i = 0; i < kstack_depth_to_print; i++ )
   57.96 -    {
   57.97 -        if ( ((long)stack & (STACK_SIZE-1)) == 0 )
   57.98 -            break;
   57.99 -        if ( i && ((i % 8) == 0) )
  57.100 -            printk("\n       ");
  57.101 -        if ( kernel_text_address(*stack) )
  57.102 -            printk("[%08lx] ", *stack++);
  57.103 -        else
  57.104 -            printk("%08lx ", *stack++);            
  57.105 -    }
  57.106 -    printk("\n");
  57.107 -
  57.108 -    show_trace( esp );
  57.109 -}
  57.110 -
  57.111 -void show_registers(struct xen_regs *regs)
  57.112 -{
  57.113 -    unsigned long esp;
  57.114 -    unsigned short ss, ds, es, fs, gs;
  57.115 -
  57.116 -    if ( GUEST_FAULT(regs) )
  57.117 -    {
  57.118 -        esp = regs->esp;
  57.119 -        ss  = regs->ss & 0xffff;
  57.120 -        ds  = regs->ds & 0xffff;
  57.121 -        es  = regs->es & 0xffff;
  57.122 -        fs  = regs->fs & 0xffff;
  57.123 -        gs  = regs->gs & 0xffff;
  57.124 -    }
  57.125 -    else
  57.126 -    {
  57.127 -        esp = (unsigned long)(&regs->esp);
  57.128 -        ss  = __HYPERVISOR_DS;
  57.129 -        ds  = __HYPERVISOR_DS;
  57.130 -        es  = __HYPERVISOR_DS;
  57.131 -        fs  = __HYPERVISOR_DS;
  57.132 -        gs  = __HYPERVISOR_DS;
  57.133 -    }
  57.134 -
  57.135 -    printk("CPU:    %d\nEIP:    %04x:[<%08x>]      \nEFLAGS: %08x\n",
  57.136 -           smp_processor_id(), 0xffff & regs->cs, regs->eip, regs->eflags);
  57.137 -    printk("eax: %08x   ebx: %08x   ecx: %08x   edx: %08x\n",
  57.138 -           regs->eax, regs->ebx, regs->ecx, regs->edx);
  57.139 -    printk("esi: %08x   edi: %08x   ebp: %08x   esp: %08lx\n",
  57.140 -           regs->esi, regs->edi, regs->ebp, esp);
  57.141 -    printk("ds: %04x   es: %04x   fs: %04x   gs: %04x   ss: %04x\n",
  57.142 -           ds, es, fs, gs, ss);
  57.143 -
  57.144 -    show_stack((unsigned long *)&regs->esp);
  57.145 -} 
  57.146 -
  57.147  /*
  57.148   * This is called for faults at very unexpected times (e.g., when interrupts
  57.149   * are disabled). In such situations we can't do much that is safe. We try to
  57.150 @@ -233,8 +115,8 @@ asmlinkage void fatal_trap(int trapnr, s
  57.151  
  57.152      if ( trapnr == TRAP_page_fault )
  57.153      {
  57.154 -        __asm__ __volatile__ ("movl %%cr2,%0" : "=r" (cr2) : );
  57.155 -        printk("Faulting linear address might be %08lx\n", cr2);
  57.156 +        __asm__ __volatile__ ("mov %%cr2,%0" : "=r" (cr2) : );
  57.157 +        printk("Faulting linear address might be %0lx %lx\n", cr2, cr2);
  57.158      }
  57.159  
  57.160      printk("************************************\n");
  57.161 @@ -283,7 +165,7 @@ static inline int do_trap(int trapnr, ch
  57.162  
  57.163      if ( likely((fixup = search_exception_table(regs->eip)) != 0) )
  57.164      {
  57.165 -        DPRINTK("Trap %d: %08x -> %08lx\n", trapnr, regs->eip, fixup);
  57.166 +        DPRINTK("Trap %d: %p -> %p\n", trapnr, regs->eip, fixup);
  57.167          regs->eip = fixup;
  57.168          return 0;
  57.169      }
  57.170 @@ -346,38 +228,6 @@ asmlinkage int do_int3(struct xen_regs *
  57.171      return 0;
  57.172  }
  57.173  
  57.174 -asmlinkage void do_double_fault(void)
  57.175 -{
  57.176 -    struct tss_struct *tss = &doublefault_tss;
  57.177 -    unsigned int cpu = ((tss->back_link>>3)-__FIRST_TSS_ENTRY)>>1;
  57.178 -
  57.179 -    /* Disable the NMI watchdog. It's useless now. */
  57.180 -    watchdog_on = 0;
  57.181 -
  57.182 -    /* Find information saved during fault and dump it to the console. */
  57.183 -    tss = &init_tss[cpu];
  57.184 -    printk("CPU:    %d\nEIP:    %04x:[<%08x>]      \nEFLAGS: %08x\n",
  57.185 -           cpu, tss->cs, tss->eip, tss->eflags);
  57.186 -    printk("CR3:    %08x\n", tss->__cr3);
  57.187 -    printk("eax: %08x   ebx: %08x   ecx: %08x   edx: %08x\n",
  57.188 -           tss->eax, tss->ebx, tss->ecx, tss->edx);
  57.189 -    printk("esi: %08x   edi: %08x   ebp: %08x   esp: %08x\n",
  57.190 -           tss->esi, tss->edi, tss->ebp, tss->esp);
  57.191 -    printk("ds: %04x   es: %04x   fs: %04x   gs: %04x   ss: %04x\n",
  57.192 -           tss->ds, tss->es, tss->fs, tss->gs, tss->ss);
  57.193 -    printk("************************************\n");
  57.194 -    printk("CPU%d DOUBLE FAULT -- system shutdown\n", cpu);
  57.195 -    printk("System needs manual reset.\n");
  57.196 -    printk("************************************\n");
  57.197 -
  57.198 -    /* Lock up the console to prevent spurious output from other CPUs. */
  57.199 -    console_force_lock();
  57.200 -
  57.201 -    /* Wait for manual reset. */
  57.202 -    for ( ; ; )
  57.203 -        __asm__ __volatile__ ( "hlt" );
  57.204 -}
  57.205 -
  57.206  asmlinkage void do_machine_check(struct xen_regs *regs)
  57.207  {
  57.208      fatal_trap(TRAP_machine_check, regs);
  57.209 @@ -410,7 +260,7 @@ asmlinkage int do_page_fault(struct xen_
  57.210      int cpu = ed->processor;
  57.211      int ret;
  57.212  
  57.213 -    __asm__ __volatile__ ("movl %%cr2,%0" : "=r" (addr) : );
  57.214 +    __asm__ __volatile__ ("mov %%cr2,%0" : "=r" (addr) : );
  57.215  
  57.216      DEBUGGER_trap_entry(TRAP_page_fault, regs);
  57.217  
  57.218 @@ -472,34 +322,18 @@ asmlinkage int do_page_fault(struct xen_
  57.219      {
  57.220          perfc_incrc(copy_user_faults);
  57.221          if ( !ed->mm.shadow_mode )
  57.222 -            DPRINTK("Page fault: %08x -> %08lx\n", regs->eip, fixup);
  57.223 +            DPRINTK("Page fault: %p -> %p\n", regs->eip, fixup);
  57.224          regs->eip = fixup;
  57.225          return 0;
  57.226      }
  57.227  
  57.228      DEBUGGER_trap_fatal(TRAP_page_fault, regs);
  57.229  
  57.230 -    if ( addr >= PAGE_OFFSET )
  57.231 -    {
  57.232 -        unsigned long page;
  57.233 -        page = l2_pgentry_val(idle_pg_table[addr >> L2_PAGETABLE_SHIFT]);
  57.234 -        printk("*pde = %08lx\n", page);
  57.235 -        if ( page & _PAGE_PRESENT )
  57.236 -        {
  57.237 -            page &= PAGE_MASK;
  57.238 -            page = ((unsigned long *) __va(page))[(addr&0x3ff000)>>PAGE_SHIFT];
  57.239 -            printk(" *pte = %08lx\n", page);
  57.240 -        }
  57.241 -#ifdef MEMORY_GUARD
  57.242 -        if ( !(regs->error_code & 1) )
  57.243 -            printk(" -- POSSIBLY AN ACCESS TO FREED MEMORY? --\n");
  57.244 -#endif
  57.245 -    }
  57.246 -
  57.247      show_registers(regs);
  57.248 +    show_page_walk(addr);
  57.249      panic("CPU%d FATAL PAGE FAULT\n"
  57.250            "[error_code=%04x]\n"
  57.251 -          "Faulting linear address might be %08lx\n",
  57.252 +          "Faulting linear address might be %p\n",
  57.253            smp_processor_id(), regs->error_code, addr);
  57.254      return 0;
  57.255  }
  57.256 @@ -544,7 +378,7 @@ static int emulate_privileged_op(struct 
  57.257          eip += 1;
  57.258          if ( (opcode & 0xc0) != 0xc0 )
  57.259              goto fail;
  57.260 -        reg = decode_reg(regs, opcode);
  57.261 +        reg = decode_reg(regs, opcode & 7);
  57.262          switch ( (opcode >> 3) & 7 )
  57.263          {
  57.264          case 0: /* Read CR0 */
  57.265 @@ -572,7 +406,7 @@ static int emulate_privileged_op(struct 
  57.266          eip += 1;
  57.267          if ( (opcode & 0xc0) != 0xc0 )
  57.268              goto fail;
  57.269 -        reg = decode_reg(regs, opcode);
  57.270 +        reg = decode_reg(regs, opcode & 7);
  57.271          switch ( (opcode >> 3) & 7 )
  57.272          {
  57.273          case 0: /* Write CR0 */
  57.274 @@ -631,7 +465,6 @@ static int emulate_privileged_op(struct 
  57.275  asmlinkage int do_general_protection(struct xen_regs *regs)
  57.276  {
  57.277      struct exec_domain *ed = current;
  57.278 -    struct domain *d = ed->domain;
  57.279      struct trap_bounce *tb = &ed->thread.trap_bounce;
  57.280      trap_info_t *ti;
  57.281      unsigned long fixup;
  57.282 @@ -683,7 +516,7 @@ asmlinkage int do_general_protection(str
  57.283          return 0;
  57.284  
  57.285  #if defined(__i386__)
  57.286 -    if ( VM_ASSIST(d, VMASST_TYPE_4gb_segments) && 
  57.287 +    if ( VM_ASSIST(ed->domain, VMASST_TYPE_4gb_segments) && 
  57.288           (regs->error_code == 0) && 
  57.289           gpf_emulate_4gb(regs) )
  57.290          return 0;
  57.291 @@ -704,7 +537,7 @@ asmlinkage int do_general_protection(str
  57.292  
  57.293      if ( likely((fixup = search_exception_table(regs->eip)) != 0) )
  57.294      {
  57.295 -        DPRINTK("GPF (%04x): %08x -> %08lx\n",
  57.296 +        DPRINTK("GPF (%04x): %p -> %p\n",
  57.297                  regs->error_code, regs->eip, fixup);
  57.298          regs->eip = fixup;
  57.299          return 0;
  57.300 @@ -793,19 +626,19 @@ asmlinkage int math_state_restore(struct
  57.301  
  57.302  asmlinkage int do_debug(struct xen_regs *regs)
  57.303  {
  57.304 -    unsigned int condition;
  57.305 +    unsigned long condition;
  57.306      struct exec_domain *d = current;
  57.307      struct trap_bounce *tb = &d->thread.trap_bounce;
  57.308  
  57.309      DEBUGGER_trap_entry(TRAP_debug, regs);
  57.310  
  57.311 -    __asm__ __volatile__("movl %%db6,%0" : "=r" (condition));
  57.312 +    __asm__ __volatile__("mov %%db6,%0" : "=r" (condition));
  57.313  
  57.314      /* Mask out spurious debug traps due to lazy DR7 setting */
  57.315      if ( (condition & (DR_TRAP0|DR_TRAP1|DR_TRAP2|DR_TRAP3)) &&
  57.316           (d->thread.debugreg[7] == 0) )
  57.317      {
  57.318 -        __asm__("movl %0,%%db7" : : "r" (0));
  57.319 +        __asm__("mov %0,%%db7" : : "r" (0UL));
  57.320          goto out;
  57.321      }
  57.322  
  57.323 @@ -838,85 +671,35 @@ asmlinkage int do_spurious_interrupt_bug
  57.324      return EXCRET_not_a_fault;
  57.325  }
  57.326  
  57.327 -#define _set_gate(gate_addr,type,dpl,addr) \
  57.328 -do { \
  57.329 -  int __d0, __d1; \
  57.330 -  __asm__ __volatile__ ("movw %%dx,%%ax\n\t" \
  57.331 - "movw %4,%%dx\n\t" \
  57.332 - "movl %%eax,%0\n\t" \
  57.333 - "movl %%edx,%1" \
  57.334 - :"=m" (*((long *) (gate_addr))), \
  57.335 -  "=m" (*(1+(long *) (gate_addr))), "=&a" (__d0), "=&d" (__d1) \
  57.336 - :"i" ((short) (0x8000+(dpl<<13)+(type<<8))), \
  57.337 -  "3" ((char *) (addr)),"2" (__HYPERVISOR_CS << 16)); \
  57.338 -} while (0)
  57.339 -
  57.340  void set_intr_gate(unsigned int n, void *addr)
  57.341  {
  57.342      _set_gate(idt_table+n,14,0,addr);
  57.343  }
  57.344  
  57.345 -static void __init set_system_gate(unsigned int n, void *addr)
  57.346 +void set_system_gate(unsigned int n, void *addr)
  57.347  {
  57.348      _set_gate(idt_table+n,14,3,addr);
  57.349  }
  57.350  
  57.351 -static void set_task_gate(unsigned int n, unsigned int sel)
  57.352 +void set_task_gate(unsigned int n, unsigned int sel)
  57.353  {
  57.354      idt_table[n].a = sel << 16;
  57.355      idt_table[n].b = 0x8500;
  57.356  }
  57.357  
  57.358 -#define _set_seg_desc(gate_addr,type,dpl,base,limit) {\
  57.359 - *((gate_addr)+1) = ((base) & 0xff000000) | \
  57.360 -  (((base) & 0x00ff0000)>>16) | \
  57.361 -  ((limit) & 0xf0000) | \
  57.362 -  ((dpl)<<13) | \
  57.363 -  (0x00408000) | \
  57.364 -  ((type)<<8); \
  57.365 - *(gate_addr) = (((base) & 0x0000ffff)<<16) | \
  57.366 -  ((limit) & 0x0ffff); }
  57.367 -
  57.368 -#define _set_tssldt_desc(n,addr,limit,type) \
  57.369 -__asm__ __volatile__ ("movw %w3,0(%2)\n\t" \
  57.370 - "movw %%ax,2(%2)\n\t" \
  57.371 - "rorl $16,%%eax\n\t" \
  57.372 - "movb %%al,4(%2)\n\t" \
  57.373 - "movb %4,5(%2)\n\t" \
  57.374 - "movb $0,6(%2)\n\t" \
  57.375 - "movb %%ah,7(%2)\n\t" \
  57.376 - "rorl $16,%%eax" \
  57.377 - : "=m"(*(n)) : "a" (addr), "r"(n), "ir"(limit), "i"(type))
  57.378 -
  57.379  void set_tss_desc(unsigned int n, void *addr)
  57.380  {
  57.381      _set_tssldt_desc(
  57.382          gdt_table + __TSS(n),
  57.383 -        (int)addr,
  57.384 +        (unsigned long)addr,
  57.385          offsetof(struct tss_struct, __cacheline_filler) - 1,
  57.386 -        0x89);
  57.387 +        9);
  57.388  }
  57.389  
  57.390  void __init trap_init(void)
  57.391  {
  57.392 -    /*
  57.393 -     * Make a separate task for double faults. This will get us debug output if
  57.394 -     * we blow the kernel stack.
  57.395 -     */
  57.396 -    struct tss_struct *tss = &doublefault_tss;
  57.397 -    memset(tss, 0, sizeof(*tss));
  57.398 -    tss->ds     = __HYPERVISOR_DS;
  57.399 -    tss->es     = __HYPERVISOR_DS;
  57.400 -    tss->ss     = __HYPERVISOR_DS;
  57.401 -    tss->esp    = (unsigned long)
  57.402 -        &doublefault_stack[DOUBLEFAULT_STACK_SIZE];
  57.403 -    tss->__cr3  = __pa(idle_pg_table);
  57.404 -    tss->cs     = __HYPERVISOR_CS;
  57.405 -    tss->eip    = (unsigned long)do_double_fault;
  57.406 -    tss->eflags = 2;
  57.407 -    tss->bitmap = IOBMP_INVALID_OFFSET;
  57.408 -    _set_tssldt_desc(gdt_table+__DOUBLEFAULT_TSS_ENTRY,
  57.409 -                     (int)tss, 235, 0x89);
  57.410 +    extern void doublefault_init(void);
  57.411 +    doublefault_init();
  57.412  
  57.413      /*
  57.414       * Note that interrupt gates are always used, rather than trap gates. We 
  57.415 @@ -934,7 +717,6 @@ void __init trap_init(void)
  57.416      set_intr_gate(TRAP_bounds,&bounds);
  57.417      set_intr_gate(TRAP_invalid_op,&invalid_op);
  57.418      set_intr_gate(TRAP_no_device,&device_not_available);
  57.419 -    set_task_gate(TRAP_double_fault,__DOUBLEFAULT_TSS_ENTRY<<3);
  57.420      set_intr_gate(TRAP_copro_seg,&coprocessor_segment_overrun);
  57.421      set_intr_gate(TRAP_invalid_tss,&invalid_TSS);
  57.422      set_intr_gate(TRAP_no_segment,&segment_not_present);
  57.423 @@ -946,9 +728,13 @@ void __init trap_init(void)
  57.424      set_intr_gate(TRAP_alignment_check,&alignment_check);
  57.425      set_intr_gate(TRAP_machine_check,&machine_check);
  57.426      set_intr_gate(TRAP_simd_error,&simd_coprocessor_error);
  57.427 +    set_intr_gate(TRAP_deferred_nmi,&nmi);
  57.428  
  57.429 -    /* Only ring 1 can access Xen services. */
  57.430 -    _set_gate(idt_table+HYPERCALL_VECTOR,14,1,&hypercall);
  57.431 +#if defined(__i386__)
  57.432 +    _set_gate(idt_table+HYPERCALL_VECTOR, 14, 1, &hypercall);
  57.433 +#elif defined(__x86_64__)
  57.434 +    _set_gate(idt_table+HYPERCALL_VECTOR, 14, 3, &hypercall);
  57.435 +#endif
  57.436  
  57.437      /* CPU0 uses the master IDT. */
  57.438      idt_tables[0] = idt_table;
  57.439 @@ -1016,57 +802,6 @@ long do_set_callbacks(unsigned long even
  57.440  }
  57.441  
  57.442  
  57.443 -long set_fast_trap(struct exec_domain *p, int idx)
  57.444 -{
  57.445 -    trap_info_t *ti;
  57.446 -
  57.447 -    /* Index 0 is special: it disables fast traps. */
  57.448 -    if ( idx == 0 )
  57.449 -    {
  57.450 -        if ( p == current )
  57.451 -            CLEAR_FAST_TRAP(&p->thread);
  57.452 -        SET_DEFAULT_FAST_TRAP(&p->thread);
  57.453 -        return 0;
  57.454 -    }
  57.455 -
  57.456 -    /*
  57.457 -     * We only fast-trap vectors 0x20-0x2f, and vector 0x80.
  57.458 -     * The former range is used by Windows and MS-DOS.
  57.459 -     * Vector 0x80 is used by Linux and the BSD variants.
  57.460 -     */
  57.461 -    if ( (idx != 0x80) && ((idx < 0x20) || (idx > 0x2f)) ) 
  57.462 -        return -1;
  57.463 -
  57.464 -    ti = p->thread.traps + idx;
  57.465 -
  57.466 -    /*
  57.467 -     * We can't virtualise interrupt gates, as there's no way to get
  57.468 -     * the CPU to automatically clear the events_mask variable.
  57.469 -     */
  57.470 -    if ( TI_GET_IF(ti) )
  57.471 -        return -1;
  57.472 -
  57.473 -    if ( p == current )
  57.474 -        CLEAR_FAST_TRAP(&p->thread);
  57.475 -
  57.476 -    p->thread.fast_trap_idx    = idx;
  57.477 -    p->thread.fast_trap_desc.a = (ti->cs << 16) | (ti->address & 0xffff);
  57.478 -    p->thread.fast_trap_desc.b = 
  57.479 -        (ti->address & 0xffff0000) | 0x8f00 | (TI_GET_DPL(ti)&3)<<13;
  57.480 -
  57.481 -    if ( p == current )
  57.482 -        SET_FAST_TRAP(&p->thread);
  57.483 -
  57.484 -    return 0;
  57.485 -}
  57.486 -
  57.487 -
  57.488 -long do_set_fast_trap(int idx)
  57.489 -{
  57.490 -    return set_fast_trap(current, idx);
  57.491 -}
  57.492 -
  57.493 -
  57.494  long do_fpu_taskswitch(void)
  57.495  {
  57.496      set_bit(EDF_GUEST_STTS, &current->ed_flags);
  57.497 @@ -1084,22 +819,22 @@ long set_debugreg(struct exec_domain *p,
  57.498      case 0: 
  57.499          if ( value > (PAGE_OFFSET-4) ) return -EPERM;
  57.500          if ( p == current ) 
  57.501 -            __asm__ ( "movl %0, %%db0" : : "r" (value) );
  57.502 +            __asm__ ( "mov %0, %%db0" : : "r" (value) );
  57.503          break;
  57.504      case 1: 
  57.505          if ( value > (PAGE_OFFSET-4) ) return -EPERM;
  57.506          if ( p == current ) 
  57.507 -            __asm__ ( "movl %0, %%db1" : : "r" (value) );
  57.508 +            __asm__ ( "mov %0, %%db1" : : "r" (value) );
  57.509          break;
  57.510      case 2: 
  57.511          if ( value > (PAGE_OFFSET-4) ) return -EPERM;
  57.512          if ( p == current ) 
  57.513 -            __asm__ ( "movl %0, %%db2" : : "r" (value) );
  57.514 +            __asm__ ( "mov %0, %%db2" : : "r" (value) );
  57.515          break;
  57.516      case 3:
  57.517          if ( value > (PAGE_OFFSET-4) ) return -EPERM;
  57.518          if ( p == current ) 
  57.519 -            __asm__ ( "movl %0, %%db3" : : "r" (value) );
  57.520 +            __asm__ ( "mov %0, %%db3" : : "r" (value) );
  57.521          break;
  57.522      case 6:
  57.523          /*
  57.524 @@ -1109,7 +844,7 @@ long set_debugreg(struct exec_domain *p,
  57.525          value &= 0xffffefff; /* reserved bits => 0 */
  57.526          value |= 0xffff0ff0; /* reserved bits => 1 */
  57.527          if ( p == current ) 
  57.528 -            __asm__ ( "movl %0, %%db6" : : "r" (value) );
  57.529 +            __asm__ ( "mov %0, %%db6" : : "r" (value) );
  57.530          break;
  57.531      case 7:
  57.532          /*
  57.533 @@ -1130,7 +865,7 @@ long set_debugreg(struct exec_domain *p,
  57.534                  if ( ((value >> (i+16)) & 3) == 2 ) return -EPERM;
  57.535          }
  57.536          if ( p == current ) 
  57.537 -            __asm__ ( "movl %0, %%db7" : : "r" (value) );
  57.538 +            __asm__ ( "mov %0, %%db7" : : "r" (value) );
  57.539          break;
  57.540      default:
  57.541          return -EINVAL;
  57.542 @@ -1150,11 +885,3 @@ unsigned long do_get_debugreg(int reg)
  57.543      if ( (reg < 0) || (reg > 7) ) return -EINVAL;
  57.544      return current->thread.debugreg[reg];
  57.545  }
  57.546 -
  57.547 -#else
  57.548 -
  57.549 -asmlinkage void fatal_trap(int trapnr, struct xen_regs *regs)
  57.550 -{
  57.551 -}
  57.552 -
  57.553 -#endif /* __i386__ */
    58.1 --- a/xen/arch/x86/vmx.c	Fri Jan 28 14:53:32 2005 +0000
    58.2 +++ b/xen/arch/x86/vmx.c	Fri Feb 04 14:44:18 2005 +0000
    58.3 @@ -166,7 +166,7 @@ static void vmx_do_general_protection_fa
    58.4              eip, error_code);
    58.5  
    58.6      VMX_DBG_LOG(DBG_LEVEL_1,
    58.7 -            "eax=%x, ebx=%x, ecx=%x, edx=%x, esi=%x, edi=%x\n",
    58.8 +            "eax=%lx, ebx=%lx, ecx=%lx, edx=%lx, esi=%lx, edi=%lx\n",
    58.9              regs->eax, regs->ebx, regs->ecx, regs->edx, regs->esi, regs->edi);
   58.10  
   58.11      /* Reflect it back into the guest */
   58.12 @@ -186,7 +186,10 @@ static void vmx_vmexit_do_cpuid(unsigned
   58.13      __vmread(GUEST_EIP, &eip);
   58.14  
   58.15      VMX_DBG_LOG(DBG_LEVEL_1, 
   58.16 -            "do_cpuid: (eax) %x, (ebx) %x, (ecx) %x, (edx) %x, (esi) %x, (edi) %x\n", regs->eax, regs->ebx, regs->ecx, regs->edx, regs->esi, regs->edi);
   58.17 +                "do_cpuid: (eax) %lx, (ebx) %lx, (ecx) %lx, (edx) %lx,"
   58.18 +                " (esi) %lx, (edi) %lx\n",
   58.19 +                regs->eax, regs->ebx, regs->ecx, regs->edx,
   58.20 +                regs->esi, regs->edi);
   58.21  
   58.22      cpuid(input, &eax, &ebx, &ecx, &edx);
   58.23  
   58.24 @@ -213,16 +216,16 @@ static void vmx_vmexit_do_cpuid(unsigned
   58.25  static void vmx_dr_access (unsigned long exit_qualification, struct xen_regs *regs)
   58.26  {
   58.27      unsigned int reg;
   58.28 -    u32 *reg_p = 0;
   58.29 +    unsigned long *reg_p = 0;
   58.30      struct exec_domain *ed = current;
   58.31 -    u32 eip;
   58.32 +    unsigned long eip;
   58.33  
   58.34      __vmread(GUEST_EIP, &eip);
   58.35  
   58.36      reg = exit_qualification & DEBUG_REG_ACCESS_NUM;
   58.37  
   58.38      VMX_DBG_LOG(DBG_LEVEL_1, 
   58.39 -                "vmx_dr_access : eip=%08x, reg=%d, exit_qualification = %lx\n",
   58.40 +                "vmx_dr_access : eip=%lx, reg=%d, exit_qualification = %lx\n",
   58.41                  eip, reg, exit_qualification);
   58.42  
   58.43      switch(exit_qualification & DEBUG_REG_ACCESS_REG) {
   58.44 @@ -629,13 +632,14 @@ static void vmx_cr_access (unsigned long
   58.45  
   58.46  static inline void vmx_do_msr_read(struct xen_regs *regs)
   58.47  {
   58.48 -    VMX_DBG_LOG(DBG_LEVEL_1, "vmx_do_msr_read: ecx=%x, eax=%x, edx=%x",
   58.49 +    VMX_DBG_LOG(DBG_LEVEL_1, "vmx_do_msr_read: ecx=%lx, eax=%lx, edx=%lx",
   58.50              regs->ecx, regs->eax, regs->edx);
   58.51  
   58.52      rdmsr(regs->ecx, regs->eax, regs->edx);
   58.53  
   58.54 -    VMX_DBG_LOG(DBG_LEVEL_1, "vmx_do_msr_read returns: ecx=%x, eax=%x, edx=%x",
   58.55 -            regs->ecx, regs->eax, regs->edx);
   58.56 +    VMX_DBG_LOG(DBG_LEVEL_1, "vmx_do_msr_read returns: "
   58.57 +                "ecx=%lx, eax=%lx, edx=%lx",
   58.58 +                regs->ecx, regs->eax, regs->edx);
   58.59  }
   58.60  
   58.61  /*
   58.62 @@ -792,7 +796,9 @@ asmlinkage void vmx_vmexit_handler(struc
   58.63              __vmread(EXIT_QUALIFICATION, &va);
   58.64              __vmread(VM_EXIT_INTR_ERROR_CODE, &error_code);
   58.65              VMX_DBG_LOG(DBG_LEVEL_VMMU, 
   58.66 -                    "eax=%x, ebx=%x, ecx=%x, edx=%x, esi=%x, edi=%x\n", regs.eax, regs.ebx, regs.ecx, regs.edx, regs.esi, regs.edi);
   58.67 +                    "eax=%lx, ebx=%lx, ecx=%lx, edx=%lx, esi=%lx, edi=%lx\n",
   58.68 +                        regs.eax, regs.ebx, regs.ecx, regs.edx, regs.esi,
   58.69 +                        regs.edi);
   58.70              d->thread.arch_vmx.vmx_platform.mpci.inst_decoder_regs = &regs;
   58.71  
   58.72              if (!(error = vmx_do_page_fault(va, error_code))) {
   58.73 @@ -907,7 +913,7 @@ asmlinkage void vmx_vmexit_handler(struc
   58.74          break;
   58.75      case EXIT_REASON_MSR_WRITE:
   58.76          __vmread(GUEST_EIP, &eip);
   58.77 -        VMX_DBG_LOG(DBG_LEVEL_1, "MSR_WRITE: eip=%08lx, eax=%08x, edx=%08x",
   58.78 +        VMX_DBG_LOG(DBG_LEVEL_1, "MSR_WRITE: eip=%08lx, eax=%08lx, edx=%08lx",
   58.79                  eip, regs.eax, regs.edx);
   58.80          /* just ignore this point */
   58.81          __get_instruction_length(inst_len);
    59.1 --- a/xen/arch/x86/vmx_platform.c	Fri Jan 28 14:53:32 2005 +0000
    59.2 +++ b/xen/arch/x86/vmx_platform.c	Fri Feb 04 14:44:18 2005 +0000
    59.3 @@ -372,7 +372,7 @@ static int inst_copy_from_guest(char *bu
    59.4          ma = (mfn << PAGE_SHIFT) | (guest_eip & (PAGE_SIZE - 1));
    59.5          inst_start = (unsigned char *)map_domain_mem(ma);
    59.6                  
    59.7 -        strncpy(buf, inst_start, inst_len);
    59.8 +        memcpy(buf, inst_start, inst_len);
    59.9          unmap_domain_mem(inst_start);
   59.10      } else {
   59.11          // Todo: In two page frames
    60.1 --- a/xen/arch/x86/x86_32/asm-offsets.c	Fri Jan 28 14:53:32 2005 +0000
    60.2 +++ b/xen/arch/x86/x86_32/asm-offsets.c	Fri Feb 04 14:44:18 2005 +0000
    60.3 @@ -65,4 +65,7 @@ void __dummy__(void)
    60.4      OFFSET(MULTICALL_arg3, multicall_entry_t, args[3]);
    60.5      OFFSET(MULTICALL_arg4, multicall_entry_t, args[4]);
    60.6      OFFSET(MULTICALL_result, multicall_entry_t, args[5]);
    60.7 +    BLANK();
    60.8 +
    60.9 +    DEFINE(FIXMAP_apic_base, fix_to_virt(FIX_APIC_BASE));
   60.10  }
    61.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    61.2 +++ b/xen/arch/x86/x86_32/domain_build.c	Fri Feb 04 14:44:18 2005 +0000
    61.3 @@ -0,0 +1,403 @@
    61.4 +/******************************************************************************
    61.5 + * domain_build.c
    61.6 + * 
    61.7 + * Copyright (c) 2002-2005, K A Fraser
    61.8 + */
    61.9 +
   61.10 +#include <xen/config.h>
   61.11 +#include <xen/init.h>
   61.12 +#include <xen/lib.h>
   61.13 +#include <xen/sched.h>
   61.14 +#include <xen/smp.h>
   61.15 +#include <xen/delay.h>
   61.16 +#include <asm/regs.h>
   61.17 +#include <asm/system.h>
   61.18 +#include <asm/io.h>
   61.19 +#include <asm/processor.h>
   61.20 +#include <asm/desc.h>
   61.21 +#include <asm/i387.h>
   61.22 +#include <xen/event.h>
   61.23 +#include <xen/elf.h>
   61.24 +#include <xen/kernel.h>
   61.25 +
   61.26 +/* No ring-3 access in initial page tables. */
   61.27 +#define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED)
   61.28 +#define L2_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER)
   61.29 +
   61.30 +#define round_pgup(_p)    (((_p)+(PAGE_SIZE-1))&PAGE_MASK)
   61.31 +#define round_pgdown(_p)  ((_p)&PAGE_MASK)
   61.32 +
   61.33 +int construct_dom0(struct domain *d,
   61.34 +                   unsigned long alloc_start,
   61.35 +                   unsigned long alloc_end,
   61.36 +                   unsigned long _image_start, unsigned long image_len, 
   61.37 +                   unsigned long _initrd_start, unsigned long initrd_len,
   61.38 +                   char *cmdline)
   61.39 +{
   61.40 +    char *dst;
   61.41 +    int i, rc;
   61.42 +    unsigned long pfn, mfn;
   61.43 +    unsigned long nr_pages = (alloc_end - alloc_start) >> PAGE_SHIFT;
   61.44 +    unsigned long nr_pt_pages;
   61.45 +    unsigned long count;
   61.46 +    l2_pgentry_t *l2tab, *l2start;
   61.47 +    l1_pgentry_t *l1tab = NULL, *l1start = NULL;
   61.48 +    struct pfn_info *page = NULL;
   61.49 +    start_info_t *si;
   61.50 +    struct exec_domain *ed = d->exec_domain[0];
   61.51 +    char *image_start  = (char *)_image_start;  /* use lowmem mappings */
   61.52 +    char *initrd_start = (char *)_initrd_start; /* use lowmem mappings */
   61.53 +
   61.54 +    /*
   61.55 +     * This fully describes the memory layout of the initial domain. All 
   61.56 +     * *_start address are page-aligned, except v_start (and v_end) which are 
   61.57 +     * superpage-aligned.
   61.58 +     */
   61.59 +    struct domain_setup_info dsi;
   61.60 +    unsigned long vinitrd_start;
   61.61 +    unsigned long vinitrd_end;
   61.62 +    unsigned long vphysmap_start;
   61.63 +    unsigned long vphysmap_end;
   61.64 +    unsigned long vstartinfo_start;
   61.65 +    unsigned long vstartinfo_end;
   61.66 +    unsigned long vstack_start;
   61.67 +    unsigned long vstack_end;
   61.68 +    unsigned long vpt_start;
   61.69 +    unsigned long vpt_end;
   61.70 +    unsigned long v_end;
   61.71 +
   61.72 +    /* Machine address of next candidate page-table page. */
   61.73 +    unsigned long mpt_alloc;
   61.74 +
   61.75 +    extern void physdev_init_dom0(struct domain *);
   61.76 +
   61.77 +    /* Sanity! */
   61.78 +    if ( d->id != 0 ) 
   61.79 +        BUG();
   61.80 +    if ( test_bit(DF_CONSTRUCTED, &d->d_flags) ) 
   61.81 +        BUG();
   61.82 +
   61.83 +    memset(&dsi, 0, sizeof(struct domain_setup_info));
   61.84 +
   61.85 +    printk("*** LOADING DOMAIN 0 ***\n");
   61.86 +
   61.87 +    /*
   61.88 +     * This is all a bit grim. We've moved the modules to the "safe" physical 
   61.89 +     * memory region above MAP_DIRECTMAP_ADDRESS (48MB). Later in this 
   61.90 +     * routine we're going to copy it down into the region that's actually 
   61.91 +     * been allocated to domain 0. This is highly likely to be overlapping, so 
   61.92 +     * we use a forward copy.
   61.93 +     * 
   61.94 +     * MAP_DIRECTMAP_ADDRESS should be safe. The worst case is a machine with 
   61.95 +     * 4GB and lots of network/disk cards that allocate loads of buffers. 
   61.96 +     * We'll have to revisit this if we ever support PAE (64GB).
   61.97 +     */
   61.98 +
   61.99 +    rc = parseelfimage(image_start, image_len, &dsi);
  61.100 +    if ( rc != 0 )
  61.101 +        return rc;
  61.102 +
  61.103 +    /* Set up domain options */
  61.104 +    if ( dsi.use_writable_pagetables )
  61.105 +        vm_assist(d, VMASST_CMD_enable, VMASST_TYPE_writable_pagetables);
  61.106 +
  61.107 +    /* Align load address to 4MB boundary. */
  61.108 +    dsi.v_start &= ~((1UL<<22)-1);
  61.109 +
  61.110 +    /*
  61.111 +     * Why do we need this? The number of page-table frames depends on the 
  61.112 +     * size of the bootstrap address space. But the size of the address space 
  61.113 +     * depends on the number of page-table frames (since each one is mapped 
  61.114 +     * read-only). We have a pair of simultaneous equations in two unknowns, 
  61.115 +     * which we solve by exhaustive search.
  61.116 +     */
  61.117 +    vinitrd_start    = round_pgup(dsi.v_kernend);
  61.118 +    vinitrd_end      = vinitrd_start + initrd_len;
  61.119 +    vphysmap_start   = round_pgup(vinitrd_end);
  61.120 +    vphysmap_end     = vphysmap_start + (nr_pages * sizeof(unsigned long));
  61.121 +    vpt_start        = round_pgup(vphysmap_end);
  61.122 +    for ( nr_pt_pages = 2; ; nr_pt_pages++ )
  61.123 +    {
  61.124 +        vpt_end          = vpt_start + (nr_pt_pages * PAGE_SIZE);
  61.125 +        vstartinfo_start = vpt_end;
  61.126 +        vstartinfo_end   = vstartinfo_start + PAGE_SIZE;
  61.127 +        vstack_start     = vstartinfo_end;
  61.128 +        vstack_end       = vstack_start + PAGE_SIZE;
  61.129 +        v_end            = (vstack_end + (1UL<<22)-1) & ~((1UL<<22)-1);
  61.130 +        if ( (v_end - vstack_end) < (512UL << 10) )
  61.131 +            v_end += 1UL << 22; /* Add extra 4MB to get >= 512kB padding. */
  61.132 +        if ( (((v_end - dsi.v_start + ((1UL<<L2_PAGETABLE_SHIFT)-1)) >> 
  61.133 +               L2_PAGETABLE_SHIFT) + 1) <= nr_pt_pages )
  61.134 +            break;
  61.135 +    }
  61.136 +
  61.137 +    printk("PHYSICAL MEMORY ARRANGEMENT:\n"
  61.138 +           " Kernel image:  %p->%p\n"
  61.139 +           " Initrd image:  %p->%p\n"
  61.140 +           " Dom0 alloc.:   %p->%p\n",
  61.141 +           _image_start, _image_start + image_len,
  61.142 +           _initrd_start, _initrd_start + initrd_len,
  61.143 +           alloc_start, alloc_end);
  61.144 +    printk("VIRTUAL MEMORY ARRANGEMENT:\n"
  61.145 +           " Loaded kernel: %p->%p\n"
  61.146 +           " Init. ramdisk: %p->%p\n"
  61.147 +           " Phys-Mach map: %p->%p\n"
  61.148 +           " Page tables:   %p->%p\n"
  61.149 +           " Start info:    %p->%p\n"
  61.150 +           " Boot stack:    %p->%p\n"
  61.151 +           " TOTAL:         %p->%p\n",
  61.152 +           dsi.v_kernstart, dsi.v_kernend, 
  61.153 +           vinitrd_start, vinitrd_end,
  61.154 +           vphysmap_start, vphysmap_end,
  61.155 +           vpt_start, vpt_end,
  61.156 +           vstartinfo_start, vstartinfo_end,
  61.157 +           vstack_start, vstack_end,
  61.158 +           dsi.v_start, v_end);
  61.159 +    printk(" ENTRY ADDRESS: %p\n", dsi.v_kernentry);
  61.160 +
  61.161 +    if ( (v_end - dsi.v_start) > (nr_pages * PAGE_SIZE) )
  61.162 +    {
  61.163 +        printk("Initial guest OS requires too much space\n"
  61.164 +               "(%luMB is greater than %luMB limit)\n",
  61.165 +               (v_end-dsi.v_start)>>20, (nr_pages<<PAGE_SHIFT)>>20);
  61.166 +        return -ENOMEM;
  61.167 +    }
  61.168 +
  61.169 +    /*
  61.170 +     * Protect the lowest 1GB of memory. We use a temporary mapping there
  61.171 +     * from which we copy the kernel and ramdisk images.
  61.172 +     */
  61.173 +    if ( dsi.v_start < (1UL<<30) )
  61.174 +    {
  61.175 +        printk("Initial loading isn't allowed to lowest 1GB of memory.\n");
  61.176 +        return -EINVAL;
  61.177 +    }
  61.178 +
  61.179 +    /* Paranoia: scrub DOM0's memory allocation. */
  61.180 +    printk("Scrubbing DOM0 RAM: ");
  61.181 +    dst = (char *)alloc_start;
  61.182 +    while ( dst < (char *)alloc_end )
  61.183 +    {
  61.184 +#define SCRUB_BYTES (100 * 1024 * 1024) /* 100MB */
  61.185 +        printk(".");
  61.186 +        touch_nmi_watchdog();
  61.187 +        if ( ((char *)alloc_end - dst) > SCRUB_BYTES )
  61.188 +        {
  61.189 +            memset(dst, 0, SCRUB_BYTES);
  61.190 +            dst += SCRUB_BYTES;
  61.191 +        }
  61.192 +        else
  61.193 +        {
  61.194 +            memset(dst, 0, (char *)alloc_end - dst);
  61.195 +            break;
  61.196 +        }
  61.197 +    }
  61.198 +    printk("done.\n");
  61.199 +
  61.200 +    /* Construct a frame-allocation list for the initial domain. */
  61.201 +    for ( mfn = (alloc_start>>PAGE_SHIFT); 
  61.202 +          mfn < (alloc_end>>PAGE_SHIFT); 
  61.203 +          mfn++ )
  61.204 +    {
  61.205 +        page = &frame_table[mfn];
  61.206 +        page_set_owner(page, d);
  61.207 +        page->u.inuse.type_info = 0;
  61.208 +        page->count_info        = PGC_allocated | 1;
  61.209 +        list_add_tail(&page->list, &d->page_list);
  61.210 +        d->tot_pages++; d->max_pages++;
  61.211 +    }
  61.212 +
  61.213 +    mpt_alloc = (vpt_start - dsi.v_start) + alloc_start;
  61.214 +
  61.215 +    SET_GDT_ENTRIES(ed, DEFAULT_GDT_ENTRIES);
  61.216 +    SET_GDT_ADDRESS(ed, DEFAULT_GDT_ADDRESS);
  61.217 +
  61.218 +    /*
  61.219 +     * We're basically forcing default RPLs to 1, so that our "what privilege
  61.220 +     * level are we returning to?" logic works.
  61.221 +     */
  61.222 +    ed->thread.failsafe_selector = FLAT_GUESTOS_CS;
  61.223 +    ed->thread.event_selector    = FLAT_GUESTOS_CS;
  61.224 +    ed->thread.guestos_ss = FLAT_GUESTOS_DS;
  61.225 +    for ( i = 0; i < 256; i++ ) 
  61.226 +        ed->thread.traps[i].cs = FLAT_GUESTOS_CS;
  61.227 +
  61.228 +    /* WARNING: The new domain must have its 'processor' field filled in! */
  61.229 +    l2start = l2tab = (l2_pgentry_t *)mpt_alloc; mpt_alloc += PAGE_SIZE;
  61.230 +    memcpy(l2tab, &idle_pg_table[0], PAGE_SIZE);
  61.231 +    l2tab[LINEAR_PT_VIRT_START >> L2_PAGETABLE_SHIFT] =
  61.232 +        mk_l2_pgentry((unsigned long)l2start | __PAGE_HYPERVISOR);
  61.233 +    l2tab[PERDOMAIN_VIRT_START >> L2_PAGETABLE_SHIFT] =
  61.234 +        mk_l2_pgentry(__pa(d->mm_perdomain_pt) | __PAGE_HYPERVISOR);
  61.235 +    ed->mm.pagetable = mk_pagetable((unsigned long)l2start);
  61.236 +
  61.237 +    l2tab += l2_table_offset(dsi.v_start);
  61.238 +    mfn = alloc_start >> PAGE_SHIFT;
  61.239 +    for ( count = 0; count < ((v_end-dsi.v_start)>>PAGE_SHIFT); count++ )
  61.240 +    {
  61.241 +        if ( !((unsigned long)l1tab & (PAGE_SIZE-1)) )
  61.242 +        {
  61.243 +            l1start = l1tab = (l1_pgentry_t *)mpt_alloc; 
  61.244 +            mpt_alloc += PAGE_SIZE;
  61.245 +            *l2tab++ = mk_l2_pgentry((unsigned long)l1start | L2_PROT);
  61.246 +            clear_page(l1tab);
  61.247 +            if ( count == 0 )
  61.248 +                l1tab += l1_table_offset(dsi.v_start);
  61.249 +        }
  61.250 +        *l1tab++ = mk_l1_pgentry((mfn << PAGE_SHIFT) | L1_PROT);
  61.251 +        
  61.252 +        page = &frame_table[mfn];
  61.253 +        if ( !get_page_and_type(page, d, PGT_writable_page) )
  61.254 +            BUG();
  61.255 +
  61.256 +        mfn++;
  61.257 +    }
  61.258 +
  61.259 +    /* Pages that are part of page tables must be read only. */
  61.260 +    l2tab = l2start + l2_table_offset(vpt_start);
  61.261 +    l1start = l1tab = (l1_pgentry_t *)l2_pgentry_to_phys(*l2tab);
  61.262 +    l1tab += l1_table_offset(vpt_start);
  61.263 +    l2tab++;
  61.264 +    for ( count = 0; count < nr_pt_pages; count++ ) 
  61.265 +    {
  61.266 +        *l1tab = mk_l1_pgentry(l1_pgentry_val(*l1tab) & ~_PAGE_RW);
  61.267 +        page = &frame_table[l1_pgentry_to_pagenr(*l1tab)];
  61.268 +        if ( count == 0 )
  61.269 +        {
  61.270 +            page->u.inuse.type_info &= ~PGT_type_mask;
  61.271 +            page->u.inuse.type_info |= PGT_l2_page_table;
  61.272 +
  61.273 +            /*
  61.274 +             * No longer writable: decrement the type_count.
  61.275 +             * Installed as CR3: increment both the ref_count and type_count.
  61.276 +             * Net: just increment the ref_count.
  61.277 +             */
  61.278 +            get_page(page, d); /* an extra ref because of readable mapping */
  61.279 +
  61.280 +            /* Get another ref to L2 page so that it can be pinned. */
  61.281 +            if ( !get_page_and_type(page, d, PGT_l2_page_table) )
  61.282 +                BUG();
  61.283 +            set_bit(_PGT_pinned, &page->u.inuse.type_info);
  61.284 +        }
  61.285 +        else
  61.286 +        {
  61.287 +            page->u.inuse.type_info &= ~PGT_type_mask;
  61.288 +            page->u.inuse.type_info |= PGT_l1_page_table;
  61.289 +	    page->u.inuse.type_info |= 
  61.290 +		((dsi.v_start>>L2_PAGETABLE_SHIFT)+(count-1))<<PGT_va_shift;
  61.291 +
  61.292 +            /*
  61.293 +             * No longer writable: decrement the type_count.
  61.294 +             * This is an L1 page, installed in a validated L2 page:
  61.295 +             * increment both the ref_count and type_count.
  61.296 +             * Net: just increment the ref_count.
  61.297 +             */
  61.298 +            get_page(page, d); /* an extra ref because of readable mapping */
  61.299 +        }
  61.300 +        l1tab++;
  61.301 +        if( !((unsigned long)l1tab & (PAGE_SIZE - 1)) )
  61.302 +            l1start = l1tab = (l1_pgentry_t *)l2_pgentry_to_phys(*l2tab);
  61.303 +    }
  61.304 +
  61.305 +    /* Set up shared-info area. */
  61.306 +    update_dom_time(d);
  61.307 +    d->shared_info->domain_time = 0;
  61.308 +    /* Mask all upcalls... */
  61.309 +    for ( i = 0; i < MAX_VIRT_CPUS; i++ )
  61.310 +        d->shared_info->vcpu_data[i].evtchn_upcall_mask = 1;
  61.311 +    d->shared_info->n_vcpu = smp_num_cpus;
  61.312 +
  61.313 +    /* Install the new page tables. */
  61.314 +    __cli();
  61.315 +    write_ptbase(&ed->mm);
  61.316 +
  61.317 +    /* Copy the OS image. */
  61.318 +    (void)loadelfimage(image_start);
  61.319 +
  61.320 +    /* Copy the initial ramdisk. */
  61.321 +    if ( initrd_len != 0 )
  61.322 +        memcpy((void *)vinitrd_start, initrd_start, initrd_len);
  61.323 +    
  61.324 +    /* Set up start info area. */
  61.325 +    si = (start_info_t *)vstartinfo_start;
  61.326 +    memset(si, 0, PAGE_SIZE);
  61.327 +    si->nr_pages     = d->tot_pages;
  61.328 +    si->shared_info  = virt_to_phys(d->shared_info);
  61.329 +    si->flags        = SIF_PRIVILEGED | SIF_INITDOMAIN;
  61.330 +    si->pt_base      = vpt_start;
  61.331 +    si->nr_pt_frames = nr_pt_pages;
  61.332 +    si->mfn_list     = vphysmap_start;
  61.333 +
  61.334 +    /* Write the phys->machine and machine->phys table entries. */
  61.335 +    for ( pfn = 0; pfn < d->tot_pages; pfn++ )
  61.336 +    {
  61.337 +        mfn = pfn + (alloc_start>>PAGE_SHIFT);
  61.338 +#ifndef NDEBUG
  61.339 +#define REVERSE_START ((v_end - dsi.v_start) >> PAGE_SHIFT)
  61.340 +        if ( pfn > REVERSE_START )
  61.341 +            mfn = (alloc_end>>PAGE_SHIFT) - (pfn - REVERSE_START);
  61.342 +#endif
  61.343 +        ((unsigned long *)vphysmap_start)[pfn] = mfn;
  61.344 +        machine_to_phys_mapping[mfn] = pfn;
  61.345 +    }
  61.346 +
  61.347 +    if ( initrd_len != 0 )
  61.348 +    {
  61.349 +        si->mod_start = vinitrd_start;
  61.350 +        si->mod_len   = initrd_len;
  61.351 +        printk("Initrd len 0x%lx, start at 0x%p\n",
  61.352 +               si->mod_len, si->mod_start);
  61.353 +    }
  61.354 +
  61.355 +    dst = si->cmd_line;
  61.356 +    if ( cmdline != NULL )
  61.357 +    {
  61.358 +        for ( i = 0; i < 255; i++ )
  61.359 +        {
  61.360 +            if ( cmdline[i] == '\0' )
  61.361 +                break;
  61.362 +            *dst++ = cmdline[i];
  61.363 +        }
  61.364 +    }
  61.365 +    *dst = '\0';
  61.366 +
  61.367 +    /* Reinstate the caller's page tables. */
  61.368 +    write_ptbase(&current->mm);
  61.369 +    __sti();
  61.370 +
  61.371 +    /* Destroy low mappings - they were only for our convenience. */
  61.372 +    for ( i = 0; i < DOMAIN_ENTRIES_PER_L2_PAGETABLE; i++ )
  61.373 +        if ( l2_pgentry_val(l2start[i]) & _PAGE_PSE )
  61.374 +            l2start[i] = mk_l2_pgentry(0);
  61.375 +    zap_low_mappings(); /* Do the same for the idle page tables. */
  61.376 +    
  61.377 +    /* DOM0 gets access to everything. */
  61.378 +    physdev_init_dom0(d);
  61.379 +
  61.380 +    set_bit(DF_CONSTRUCTED, &d->d_flags);
  61.381 +
  61.382 +    new_thread(ed, dsi.v_kernentry, vstack_end, vstartinfo_start);
  61.383 +
  61.384 +#if 0 /* XXXXX DO NOT CHECK IN ENABLED !!! (but useful for testing so leave) */
  61.385 +    shadow_lock(&d->mm);
  61.386 +    shadow_mode_enable(d, SHM_test); 
  61.387 +    shadow_unlock(&d->mm);
  61.388 +#endif
  61.389 +
  61.390 +    return 0;
  61.391 +}
  61.392 +
  61.393 +int elf_sanity_check(Elf_Ehdr *ehdr)
  61.394 +{
  61.395 +    if ( !IS_ELF(*ehdr) ||
  61.396 +         (ehdr->e_ident[EI_CLASS] != ELFCLASS32) ||
  61.397 +         (ehdr->e_ident[EI_DATA] != ELFDATA2LSB) ||
  61.398 +         (ehdr->e_type != ET_EXEC) ||
  61.399 +         (ehdr->e_machine != EM_386) )
  61.400 +    {
  61.401 +        printk("DOM0 image is not i386-compatible executable Elf image.\n");
  61.402 +        return 0;
  61.403 +    }
  61.404 +
  61.405 +    return 1;
  61.406 +}
    62.1 --- a/xen/arch/x86/x86_32/entry.S	Fri Jan 28 14:53:32 2005 +0000
    62.2 +++ b/xen/arch/x86/x86_32/entry.S	Fri Feb 04 14:44:18 2005 +0000
    62.3 @@ -57,6 +57,7 @@
    62.4  #include <xen/errno.h>
    62.5  #include <xen/softirq.h>
    62.6  #include <asm/asm_defns.h>
    62.7 +#include <asm/apicdef.h>
    62.8  #include <public/xen.h>
    62.9  
   62.10  #define GET_CURRENT(reg)   \
   62.11 @@ -605,10 +606,10 @@ ENTRY(nmi)
   62.12          jnz   do_watchdog_tick
   62.13          movl  %ds,%eax
   62.14          cmpw  $(__HYPERVISOR_DS),%ax
   62.15 -        jne   restore_all_xen
   62.16 +        jne   defer_nmi
   62.17          movl  %es,%eax
   62.18          cmpw  $(__HYPERVISOR_DS),%ax
   62.19 -        jne   restore_all_xen
   62.20 +        jne   defer_nmi
   62.21  
   62.22  do_watchdog_tick:
   62.23          movl  $(__HYPERVISOR_DS),%edx
   62.24 @@ -626,6 +627,17 @@ do_watchdog_tick:
   62.25          GET_CURRENT(%ebx)
   62.26          jmp   restore_all_guest
   62.27  
   62.28 +defer_nmi:
   62.29 +        movl  $FIXMAP_apic_base,%eax
   62.30 +        # apic_wait_icr_idle()
   62.31 +1:      movl  %ss:APIC_ICR(%eax),%ebx
   62.32 +        testl $APIC_ICR_BUSY,%ebx
   62.33 +        jnz   1b
   62.34 +        # __send_IPI_shortcut(APIC_DEST_SELF, TRAP_deferred_nmi)
   62.35 +        movl  $(APIC_DM_FIXED | APIC_DEST_SELF | APIC_DEST_LOGICAL | \
   62.36 +                TRAP_deferred_nmi),%ss:APIC_ICR(%eax)
   62.37 +        jmp   restore_all_xen
   62.38 +
   62.39  nmi_parity_err:
   62.40          # Clear and disable the parity-error line
   62.41          andb $0xf,%al
    63.1 --- a/xen/arch/x86/x86_32/mm.c	Fri Jan 28 14:53:32 2005 +0000
    63.2 +++ b/xen/arch/x86/x86_32/mm.c	Fri Feb 04 14:44:18 2005 +0000
    63.3 @@ -27,32 +27,62 @@
    63.4  #include <asm/fixmap.h>
    63.5  #include <asm/domain_page.h>
    63.6  
    63.7 -unsigned long m2p_start_mfn;
    63.8 -
    63.9 -static inline void set_pte_phys(unsigned long vaddr,
   63.10 -                                l1_pgentry_t entry)
   63.11 +/* Map physical byte range (@p, @p+@s) at virt address @v in pagetable @pt. */
   63.12 +int map_pages(
   63.13 +    pagetable_t *pt,
   63.14 +    unsigned long v,
   63.15 +    unsigned long p,
   63.16 +    unsigned long s,
   63.17 +    unsigned long flags)
   63.18  {
   63.19 -    l2_pgentry_t *l2ent;
   63.20 -    l1_pgentry_t *l1ent;
   63.21 +    l2_pgentry_t *pl2e;
   63.22 +    l1_pgentry_t *pl1e;
   63.23 +    void         *newpg;
   63.24  
   63.25 -    l2ent = &idle_pg_table[l2_table_offset(vaddr)];
   63.26 -    l1ent = l2_pgentry_to_l1(*l2ent) + l1_table_offset(vaddr);
   63.27 -    *l1ent = entry;
   63.28 +    while ( s != 0 )
   63.29 +    {
   63.30 +        pl2e = &pt[l2_table_offset(v)];
   63.31  
   63.32 -    /* It's enough to flush this one mapping. */
   63.33 -    __flush_tlb_one(vaddr);
   63.34 +        if ( ((s|v|p) & ((1<<L2_PAGETABLE_SHIFT)-1)) == 0 )
   63.35 +        {
   63.36 +            /* Super-page mapping. */
   63.37 +            if ( (l2_pgentry_val(*pl2e) & _PAGE_PRESENT) )
   63.38 +                __flush_tlb_pge();
   63.39 +            *pl2e = mk_l2_pgentry(p|flags|_PAGE_PSE);
   63.40 +
   63.41 +            v += 1 << L2_PAGETABLE_SHIFT;
   63.42 +            p += 1 << L2_PAGETABLE_SHIFT;
   63.43 +            s -= 1 << L2_PAGETABLE_SHIFT;
   63.44 +        }
   63.45 +        else
   63.46 +        {
   63.47 +            /* Normal page mapping. */
   63.48 +            if ( !(l2_pgentry_val(*pl2e) & _PAGE_PRESENT) )
   63.49 +            {
   63.50 +                newpg = (void *)alloc_xenheap_page();
   63.51 +                clear_page(newpg);
   63.52 +                *pl2e = mk_l2_pgentry(__pa(newpg) | __PAGE_HYPERVISOR);
   63.53 +            }
   63.54 +            pl1e = l2_pgentry_to_l1(*pl2e) + l1_table_offset(v);
   63.55 +            if ( (l1_pgentry_val(*pl1e) & _PAGE_PRESENT) )
   63.56 +                __flush_tlb_one(v);
   63.57 +            *pl1e = mk_l1_pgentry(p|flags);
   63.58 +
   63.59 +            v += 1 << L1_PAGETABLE_SHIFT;
   63.60 +            p += 1 << L1_PAGETABLE_SHIFT;
   63.61 +            s -= 1 << L1_PAGETABLE_SHIFT;            
   63.62 +        }
   63.63 +    }
   63.64 +
   63.65 +    return 0;
   63.66  }
   63.67  
   63.68 -
   63.69 -void __set_fixmap(enum fixed_addresses idx, 
   63.70 -                  l1_pgentry_t entry)
   63.71 +void __set_fixmap(
   63.72 +    enum fixed_addresses idx, unsigned long p, unsigned long flags)
   63.73  {
   63.74 -    unsigned long address = fix_to_virt(idx);
   63.75 -
   63.76 -    if ( likely(idx < __end_of_fixed_addresses) )
   63.77 -        set_pte_phys(address, entry);
   63.78 -    else
   63.79 -        printk("Invalid __set_fixmap\n");
   63.80 +    if ( unlikely(idx >= __end_of_fixed_addresses) )
   63.81 +        BUG();
   63.82 +    map_pages(idle_pg_table, fix_to_virt(idx), p, PAGE_SIZE, flags);
   63.83  }
   63.84  
   63.85  
   63.86 @@ -65,16 +95,16 @@ void __init paging_init(void)
   63.87      /* Allocate and map the machine-to-phys table. */
   63.88      if ( (pg = alloc_domheap_pages(NULL, 10)) == NULL )
   63.89          panic("Not enough memory to bootstrap Xen.\n");
   63.90 -    m2p_start_mfn = page_to_pfn(pg);
   63.91 -    idle_pg_table[RDWR_MPT_VIRT_START >> L2_PAGETABLE_SHIFT] =
   63.92 +    idle_pg_table[l2_table_offset(RDWR_MPT_VIRT_START)] =
   63.93          mk_l2_pgentry(page_to_phys(pg) | __PAGE_HYPERVISOR | _PAGE_PSE);
   63.94 +    memset((void *)RDWR_MPT_VIRT_START, 0x55, 4UL << 20);
   63.95  
   63.96      /* Xen 4MB mappings can all be GLOBAL. */
   63.97      if ( cpu_has_pge )
   63.98      {
   63.99          for ( v = HYPERVISOR_VIRT_START; v; v += (1 << L2_PAGETABLE_SHIFT) )
  63.100          {
  63.101 -             l2e = l2_pgentry_val(idle_pg_table[v >> L2_PAGETABLE_SHIFT]);
  63.102 +             l2e = l2_pgentry_val(idle_pg_table[l2_table_offset(v)]);
  63.103               if ( l2e & _PAGE_PSE )
  63.104                   l2e |= _PAGE_GLOBAL;
  63.105               idle_pg_table[v >> L2_PAGETABLE_SHIFT] = mk_l2_pgentry(l2e);
  63.106 @@ -84,23 +114,22 @@ void __init paging_init(void)
  63.107      /* Create page table for ioremap(). */
  63.108      ioremap_pt = (void *)alloc_xenheap_page();
  63.109      clear_page(ioremap_pt);
  63.110 -    idle_pg_table[IOREMAP_VIRT_START >> L2_PAGETABLE_SHIFT] = 
  63.111 +    idle_pg_table[l2_table_offset(IOREMAP_VIRT_START)] =
  63.112          mk_l2_pgentry(__pa(ioremap_pt) | __PAGE_HYPERVISOR);
  63.113  
  63.114      /* Create read-only mapping of MPT for guest-OS use. */
  63.115 -    idle_pg_table[RO_MPT_VIRT_START >> L2_PAGETABLE_SHIFT] =
  63.116 +    idle_pg_table[l2_table_offset(RO_MPT_VIRT_START)] =
  63.117          mk_l2_pgentry(l2_pgentry_val(
  63.118 -            idle_pg_table[RDWR_MPT_VIRT_START >> L2_PAGETABLE_SHIFT]) & 
  63.119 -                      ~_PAGE_RW);
  63.120 +            idle_pg_table[l2_table_offset(RDWR_MPT_VIRT_START)]) & ~_PAGE_RW);
  63.121  
  63.122      /* Set up mapping cache for domain pages. */
  63.123      mapcache = (unsigned long *)alloc_xenheap_page();
  63.124      clear_page(mapcache);
  63.125 -    idle_pg_table[MAPCACHE_VIRT_START >> L2_PAGETABLE_SHIFT] =
  63.126 +    idle_pg_table[l2_table_offset(MAPCACHE_VIRT_START)] =
  63.127          mk_l2_pgentry(__pa(mapcache) | __PAGE_HYPERVISOR);
  63.128  
  63.129      /* Set up linear page table mapping. */
  63.130 -    idle_pg_table[LINEAR_PT_VIRT_START >> L2_PAGETABLE_SHIFT] =
  63.131 +    idle_pg_table[l2_table_offset(LINEAR_PT_VIRT_START)] =
  63.132          mk_l2_pgentry(__pa(idle_pg_table) | __PAGE_HYPERVISOR);
  63.133  }
  63.134  
  63.135 @@ -112,6 +141,39 @@ void __init zap_low_mappings(void)
  63.136      flush_tlb_all_pge();
  63.137  }
  63.138  
  63.139 +void subarch_init_memory(struct domain *dom_xen)
  63.140 +{
  63.141 +    unsigned long i, m2p_start_mfn;
  63.142 +
  63.143 +    /*
  63.144 +     * We are rather picky about the layout of 'struct pfn_info'. The
  63.145 +     * count_info and domain fields must be adjacent, as we perform atomic
  63.146 +     * 64-bit operations on them. Also, just for sanity, we assert the size
  63.147 +     * of the structure here.
  63.148 +     */
  63.149 +    if ( (offsetof(struct pfn_info, u.inuse._domain) != 
  63.150 +          (offsetof(struct pfn_info, count_info) + sizeof(u32))) ||
  63.151 +         (sizeof(struct pfn_info) != 24) )
  63.152 +    {
  63.153 +        printk("Weird pfn_info layout (%ld,%ld,%d)\n",
  63.154 +               offsetof(struct pfn_info, count_info),
  63.155 +               offsetof(struct pfn_info, u.inuse._domain),
  63.156 +               sizeof(struct pfn_info));
  63.157 +        for ( ; ; ) ;
  63.158 +    }
  63.159 +
  63.160 +    /* M2P table is mappable read-only by privileged domains. */
  63.161 +    m2p_start_mfn = l2_pgentry_to_pagenr(
  63.162 +        idle_pg_table[l2_table_offset(RDWR_MPT_VIRT_START)]);
  63.163 +    for ( i = 0; i < 1024; i++ )
  63.164 +    {
  63.165 +        frame_table[m2p_start_mfn+i].count_info = PGC_allocated | 1;
  63.166 +	/* gdt to make sure it's only mapped read-only by non-privileged
  63.167 +	   domains. */
  63.168 +        frame_table[m2p_start_mfn+i].u.inuse.type_info = PGT_gdt_page | 1;
  63.169 +        page_set_owner(&frame_table[m2p_start_mfn+i], dom_xen);
  63.170 +    }
  63.171 +}
  63.172  
  63.173  /*
  63.174   * Allows shooting down of borrowed page-table use on specific CPUs.
    64.1 --- a/xen/arch/x86/x86_32/seg_fixup.c	Fri Jan 28 14:53:32 2005 +0000
    64.2 +++ b/xen/arch/x86/x86_32/seg_fixup.c	Fri Feb 04 14:44:18 2005 +0000
    64.3 @@ -292,7 +292,7 @@ int gpf_emulate_4gb(struct xen_regs *reg
    64.4      u32           disp32 = 0;
    64.5      u8            *eip;         /* ptr to instruction start */
    64.6      u8            *pb, b;       /* ptr into instr. / current instr. byte */
    64.7 -    unsigned int  *pseg = NULL; /* segment for memory operand (NULL=default) */
    64.8 +    unsigned long *pseg = NULL; /* segment for memory operand (NULL=default) */
    64.9  
   64.10      /* WARNING: We only work for ring-3 segments. */
   64.11      if ( unlikely(VM86_MODE(regs)) || unlikely(!RING_3(regs)) )
    65.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    65.2 +++ b/xen/arch/x86/x86_32/traps.c	Fri Feb 04 14:44:18 2005 +0000
    65.3 @@ -0,0 +1,247 @@
    65.4 +
    65.5 +#include <xen/config.h>
    65.6 +#include <xen/init.h>
    65.7 +#include <xen/sched.h>
    65.8 +#include <xen/lib.h>
    65.9 +#include <xen/console.h>
   65.10 +#include <xen/mm.h>
   65.11 +#include <xen/irq.h>
   65.12 +
   65.13 +static int kstack_depth_to_print = 8*20;
   65.14 +
   65.15 +static inline int kernel_text_address(unsigned long addr)
   65.16 +{
   65.17 +    if (addr >= (unsigned long) &_stext &&
   65.18 +        addr <= (unsigned long) &_etext)
   65.19 +        return 1;
   65.20 +    return 0;
   65.21 +
   65.22 +}
   65.23 +
   65.24 +void show_guest_stack(void)
   65.25 +{
   65.26 +    int i;
   65.27 +    execution_context_t *ec = get_execution_context();
   65.28 +    unsigned long *stack = (unsigned long *)ec->esp;
   65.29 +    printk("Guest EIP is %lx\n   ",ec->eip);
   65.30 +
   65.31 +    for ( i = 0; i < kstack_depth_to_print; i++ )
   65.32 +    {
   65.33 +        if ( ((long)stack & (STACK_SIZE-1)) == 0 )
   65.34 +            break;
   65.35 +        if ( i && ((i % 8) == 0) )
   65.36 +            printk("\n   ");
   65.37 +            printk("%p ", *stack++);            
   65.38 +    }
   65.39 +    printk("\n");
   65.40 +    
   65.41 +}
   65.42 +
   65.43 +void show_trace(unsigned long *esp)
   65.44 +{
   65.45 +    unsigned long *stack, addr;
   65.46 +    int i;
   65.47 +
   65.48 +    printk("Call Trace from ESP=%p:\n   ", esp);
   65.49 +    stack = esp;
   65.50 +    i = 0;
   65.51 +    while (((long) stack & (STACK_SIZE-1)) != 0) {
   65.52 +        addr = *stack++;
   65.53 +        if (kernel_text_address(addr)) {
   65.54 +            if (i && ((i % 6) == 0))
   65.55 +                printk("\n   ");
   65.56 +            printk("[<%p>] ", addr);
   65.57 +            i++;
   65.58 +        }
   65.59 +    }
   65.60 +    printk("\n");
   65.61 +}
   65.62 +
   65.63 +void show_stack(unsigned long *esp)
   65.64 +{
   65.65 +    unsigned long *stack;
   65.66 +    int i;
   65.67 +
   65.68 +    printk("Stack trace from ESP=%p:\n   ", esp);
   65.69 +
   65.70 +    stack = esp;
   65.71 +    for ( i = 0; i < kstack_depth_to_print; i++ )
   65.72 +    {
   65.73 +        if ( ((long)stack & (STACK_SIZE-1)) == 0 )
   65.74 +            break;
   65.75 +        if ( i && ((i % 8) == 0) )
   65.76 +            printk("\n   ");
   65.77 +        if ( kernel_text_address(*stack) )
   65.78 +            printk("[%p] ", *stack++);
   65.79 +        else
   65.80 +            printk("%p ", *stack++);            
   65.81 +    }
   65.82 +    printk("\n");
   65.83 +
   65.84 +    show_trace( esp );
   65.85 +}
   65.86 +
   65.87 +void show_registers(struct xen_regs *regs)
   65.88 +{
   65.89 +    unsigned long esp;
   65.90 +    unsigned short ss, ds, es, fs, gs;
   65.91 +
   65.92 +    if ( GUEST_FAULT(regs) )
   65.93 +    {
   65.94 +        esp = regs->esp;
   65.95 +        ss  = regs->ss & 0xffff;
   65.96 +        ds  = regs->ds & 0xffff;
   65.97 +        es  = regs->es & 0xffff;
   65.98 +        fs  = regs->fs & 0xffff;
   65.99 +        gs  = regs->gs & 0xffff;
  65.100 +    }
  65.101 +    else
  65.102 +    {
  65.103 +        esp = (unsigned long)(&regs->esp);
  65.104 +        ss  = __HYPERVISOR_DS;
  65.105 +        ds  = __HYPERVISOR_DS;
  65.106 +        es  = __HYPERVISOR_DS;
  65.107 +        fs  = __HYPERVISOR_DS;
  65.108 +        gs  = __HYPERVISOR_DS;
  65.109 +    }
  65.110 +
  65.111 +    printk("CPU:    %d\nEIP:    %04lx:[<%p>]      \nEFLAGS: %p\n",
  65.112 +           smp_processor_id(), 0xffff & regs->cs, regs->eip, regs->eflags);
  65.113 +    printk("eax: %p   ebx: %p   ecx: %p   edx: %p\n",
  65.114 +           regs->eax, regs->ebx, regs->ecx, regs->edx);
  65.115 +    printk("esi: %p   edi: %p   ebp: %p   esp: %p\n",
  65.116 +           regs->esi, regs->edi, regs->ebp, esp);
  65.117 +    printk("ds: %04x   es: %04x   fs: %04x   gs: %04x   ss: %04x\n",
  65.118 +           ds, es, fs, gs, ss);
  65.119 +
  65.120 +    show_stack((unsigned long *)&regs->esp);
  65.121 +} 
  65.122 +
  65.123 +void show_page_walk(unsigned long addr)
  65.124 +{
  65.125 +    unsigned long page;
  65.126 +
  65.127 +    if ( addr < PAGE_OFFSET )
  65.128 +        return;
  65.129 +
  65.130 +    printk("Pagetable walk from %p:\n", addr);
  65.131 +    
  65.132 +    page = l2_pgentry_val(idle_pg_table[l2_table_offset(addr)]);
  65.133 +    printk(" L2 = %p %s\n", page, (page & _PAGE_PSE) ? "(4MB)" : "");
  65.134 +    if ( !(page & _PAGE_PRESENT) || (page & _PAGE_PSE) )
  65.135 +        return;
  65.136 +
  65.137 +    page &= PAGE_MASK;
  65.138 +    page = ((unsigned long *) __va(page))[l1_table_offset(addr)];
  65.139 +    printk("  L1 = %p\n", page);
  65.140 +}
  65.141 +
  65.142 +#define DOUBLEFAULT_STACK_SIZE 1024
  65.143 +static struct tss_struct doublefault_tss;
  65.144 +static unsigned char doublefault_stack[DOUBLEFAULT_STACK_SIZE];
  65.145 +
  65.146 +asmlinkage void do_double_fault(void)
  65.147 +{
  65.148 +    struct tss_struct *tss = &doublefault_tss;
  65.149 +    unsigned int cpu = ((tss->back_link>>3)-__FIRST_TSS_ENTRY)>>1;
  65.150 +
  65.151 +    /* Disable the NMI watchdog. It's useless now. */
  65.152 +    watchdog_on = 0;
  65.153 +
  65.154 +    /* Find information saved during fault and dump it to the console. */
  65.155 +    tss = &init_tss[cpu];
  65.156 +    printk("CPU:    %d\nEIP:    %04x:[<%08x>]      \nEFLAGS: %08x\n",
  65.157 +           cpu, tss->cs, tss->eip, tss->eflags);
  65.158 +    printk("CR3:    %08x\n", tss->__cr3);
  65.159 +    printk("eax: %08x   ebx: %08x   ecx: %08x   edx: %08x\n",
  65.160 +           tss->eax, tss->ebx, tss->ecx, tss->edx);
  65.161 +    printk("esi: %08x   edi: %08x   ebp: %08x   esp: %08x\n",
  65.162 +           tss->esi, tss->edi, tss->ebp, tss->esp);
  65.163 +    printk("ds: %04x   es: %04x   fs: %04x   gs: %04x   ss: %04x\n",
  65.164 +           tss->ds, tss->es, tss->fs, tss->gs, tss->ss);
  65.165 +    printk("************************************\n");
  65.166 +    printk("CPU%d DOUBLE FAULT -- system shutdown\n", cpu);
  65.167 +    printk("System needs manual reset.\n");
  65.168 +    printk("************************************\n");
  65.169 +
  65.170 +    /* Lock up the console to prevent spurious output from other CPUs. */
  65.171 +    console_force_lock();
  65.172 +
  65.173 +    /* Wait for manual reset. */
  65.174 +    for ( ; ; )
  65.175 +        __asm__ __volatile__ ( "hlt" );
  65.176 +}
  65.177 +
  65.178 +void __init doublefault_init(void)
  65.179 +{
  65.180 +    /*
  65.181 +     * Make a separate task for double faults. This will get us debug output if
  65.182 +     * we blow the kernel stack.
  65.183 +     */
  65.184 +    struct tss_struct *tss = &doublefault_tss;
  65.185 +    memset(tss, 0, sizeof(*tss));
  65.186 +    tss->ds     = __HYPERVISOR_DS;
  65.187 +    tss->es     = __HYPERVISOR_DS;
  65.188 +    tss->ss     = __HYPERVISOR_DS;
  65.189 +    tss->esp    = (unsigned long)
  65.190 +        &doublefault_stack[DOUBLEFAULT_STACK_SIZE];
  65.191 +    tss->__cr3  = __pa(idle_pg_table);
  65.192 +    tss->cs     = __HYPERVISOR_CS;
  65.193 +    tss->eip    = (unsigned long)do_double_fault;
  65.194 +    tss->eflags = 2;
  65.195 +    tss->bitmap = IOBMP_INVALID_OFFSET;
  65.196 +    _set_tssldt_desc(gdt_table+__DOUBLEFAULT_TSS_ENTRY,
  65.197 +                     (unsigned long)tss, 235, 9);
  65.198 +
  65.199 +    set_task_gate(TRAP_double_fault, __DOUBLEFAULT_TSS_ENTRY<<3);
  65.200 +}
  65.201 +
  65.202 +long set_fast_trap(struct exec_domain *p, int idx)
  65.203 +{
  65.204 +    trap_info_t *ti;
  65.205 +
  65.206 +    /* Index 0 is special: it disables fast traps. */
  65.207 +    if ( idx == 0 )
  65.208 +    {
  65.209 +        if ( p == current )
  65.210 +            CLEAR_FAST_TRAP(&p->thread);
  65.211 +        SET_DEFAULT_FAST_TRAP(&p->thread);
  65.212 +        return 0;
  65.213 +    }
  65.214 +
  65.215 +    /*
  65.216 +     * We only fast-trap vectors 0x20-0x2f, and vector 0x80.
  65.217 +     * The former range is used by Windows and MS-DOS.
  65.218 +     * Vector 0x80 is used by Linux and the BSD variants.
  65.219 +     */
  65.220 +    if ( (idx != 0x80) && ((idx < 0x20) || (idx > 0x2f)) ) 
  65.221 +        return -1;
  65.222 +
  65.223 +    ti = p->thread.traps + idx;
  65.224 +
  65.225 +    /*
  65.226 +     * We can't virtualise interrupt gates, as there's no way to get
  65.227 +     * the CPU to automatically clear the events_mask variable.
  65.228 +     */
  65.229 +    if ( TI_GET_IF(ti) )
  65.230 +        return -1;
  65.231 +
  65.232 +    if ( p == current )
  65.233 +        CLEAR_FAST_TRAP(&p->thread);
  65.234 +
  65.235 +    p->thread.fast_trap_idx    = idx;
  65.236 +    p->thread.fast_trap_desc.a = (ti->cs << 16) | (ti->address & 0xffff);
  65.237 +    p->thread.fast_trap_desc.b = 
  65.238 +        (ti->address & 0xffff0000) | 0x8f00 | (TI_GET_DPL(ti)&3)<<13;
  65.239 +
  65.240 +    if ( p == current )
  65.241 +        SET_FAST_TRAP(&p->thread);
  65.242 +
  65.243 +    return 0;
  65.244 +}
  65.245 +
  65.246 +
  65.247 +long do_set_fast_trap(int idx)
  65.248 +{
  65.249 +    return set_fast_trap(current, idx);
  65.250 +}
    66.1 --- a/xen/arch/x86/x86_32/xen.lds	Fri Jan 28 14:53:32 2005 +0000
    66.2 +++ b/xen/arch/x86/x86_32/xen.lds	Fri Feb 04 14:44:18 2005 +0000
    66.3 @@ -64,12 +64,8 @@ SECTIONS
    66.4    __initcall_start = .;
    66.5    .initcall.init : { *(.initcall.init) } :text
    66.6    __initcall_end = .;
    66.7 -  . = ALIGN(4096);
    66.8    __init_end = .;
    66.9  
   66.10 -  . = ALIGN(4096);
   66.11 -  .data.page_aligned : { *(.data.idt) } :text
   66.12 -
   66.13    __bss_start = .;		/* BSS */
   66.14    .bss : {
   66.15  	*(.bss)
    67.1 --- a/xen/arch/x86/x86_64/asm-offsets.c	Fri Jan 28 14:53:32 2005 +0000
    67.2 +++ b/xen/arch/x86/x86_64/asm-offsets.c	Fri Feb 04 14:44:18 2005 +0000
    67.3 @@ -30,7 +30,8 @@ void __dummy__(void)
    67.4      OFFSET(XREGS_rdx, struct xen_regs, rdx);
    67.5      OFFSET(XREGS_rsi, struct xen_regs, rsi);
    67.6      OFFSET(XREGS_rdi, struct xen_regs, rdi);
    67.7 -    OFFSET(XREGS_orig_rax, struct xen_regs, orig_rax);
    67.8 +    OFFSET(XREGS_error_code, struct xen_regs, error_code);
    67.9 +    OFFSET(XREGS_entry_vector, struct xen_regs, entry_vector);
   67.10      OFFSET(XREGS_rip, struct xen_regs, rip);
   67.11      OFFSET(XREGS_cs, struct xen_regs, cs);
   67.12      OFFSET(XREGS_eflags, struct xen_regs, eflags);
    68.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    68.2 +++ b/xen/arch/x86/x86_64/domain_build.c	Fri Feb 04 14:44:18 2005 +0000
    68.3 @@ -0,0 +1,403 @@
    68.4 +/******************************************************************************
    68.5 + * domain_build.c
    68.6 + * 
    68.7 + * Copyright (c) 2002-2005, K A Fraser
    68.8 + */
    68.9 +
   68.10 +#include <xen/config.h>
   68.11 +#include <xen/init.h>
   68.12 +#include <xen/lib.h>
   68.13 +#include <xen/sched.h>
   68.14 +#include <xen/smp.h>
   68.15 +#include <xen/delay.h>
   68.16 +#include <asm/regs.h>
   68.17 +#include <asm/system.h>
   68.18 +#include <asm/io.h>
   68.19 +#include <asm/processor.h>
   68.20 +#include <asm/desc.h>
   68.21 +#include <asm/i387.h>
   68.22 +#include <xen/event.h>
   68.23 +#include <xen/elf.h>
   68.24 +#include <xen/kernel.h>
   68.25 +
   68.26 +/* Allow ring-3 access in long mode as guest cannot use ring 1. */
   68.27 +#define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_USER)
   68.28 +#define L2_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER)
   68.29 +#define L3_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER)
   68.30 +#define L4_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER)
   68.31 +
   68.32 +#define round_pgup(_p)    (((_p)+(PAGE_SIZE-1))&PAGE_MASK)
   68.33 +#define round_pgdown(_p)  ((_p)&PAGE_MASK)
   68.34 +
   68.35 +int construct_dom0(struct domain *d,
   68.36 +                   unsigned long alloc_start,
   68.37 +                   unsigned long alloc_end,
   68.38 +                   unsigned long _image_start, unsigned long image_len, 
   68.39 +                   unsigned long _initrd_start, unsigned long initrd_len,
   68.40 +                   char *cmdline)
   68.41 +{
   68.42 +    char *dst;
   68.43 +    int i, rc;
   68.44 +    unsigned long pfn, mfn;
   68.45 +    unsigned long nr_pages = (alloc_end - alloc_start) >> PAGE_SHIFT;
   68.46 +    unsigned long nr_pt_pages;
   68.47 +    unsigned long count;
   68.48 +    l2_pgentry_t *l2tab, *l2start;
   68.49 +    l1_pgentry_t *l1tab = NULL, *l1start = NULL;
   68.50 +    struct pfn_info *page = NULL;
   68.51 +    start_info_t *si;
   68.52 +    struct exec_domain *ed = d->exec_domain[0];
   68.53 +    char *image_start  = __va(_image_start);
   68.54 +    char *initrd_start = __va(_initrd_start);
   68.55 +
   68.56 +    /*
   68.57 +     * This fully describes the memory layout of the initial domain. All 
   68.58 +     * *_start address are page-aligned, except v_start (and v_end) which are 
   68.59 +     * superpage-aligned.
   68.60 +     */
   68.61 +    struct domain_setup_info dsi;
   68.62 +    unsigned long vinitrd_start;
   68.63 +    unsigned long vinitrd_end;
   68.64 +    unsigned long vphysmap_start;
   68.65 +    unsigned long vphysmap_end;
   68.66 +    unsigned long vstartinfo_start;
   68.67 +    unsigned long vstartinfo_end;
   68.68 +    unsigned long vstack_start;
   68.69 +    unsigned long vstack_end;
   68.70 +    unsigned long vpt_start;
   68.71 +    unsigned long vpt_end;
   68.72 +    unsigned long v_end;
   68.73 +
   68.74 +    /* Machine address of next candidate page-table page. */
   68.75 +    unsigned long mpt_alloc;
   68.76 +
   68.77 +    extern void physdev_init_dom0(struct domain *);
   68.78 +
   68.79 +    /* Sanity! */
   68.80 +    if ( d->id != 0 ) 
   68.81 +        BUG();
   68.82 +    if ( test_bit(DF_CONSTRUCTED, &d->d_flags) ) 
   68.83 +        BUG();
   68.84 +
   68.85 +    memset(&dsi, 0, sizeof(struct domain_setup_info));
   68.86 +
   68.87 +    printk("*** LOADING DOMAIN 0 ***\n");
   68.88 +
   68.89 +    /*
   68.90 +     * This is all a bit grim. We've moved the modules to the "safe" physical 
   68.91 +     * memory region above MAP_DIRECTMAP_ADDRESS (48MB). Later in this 
   68.92 +     * routine we're going to copy it down into the region that's actually 
   68.93 +     * been allocated to domain 0. This is highly likely to be overlapping, so 
   68.94 +     * we use a forward copy.
   68.95 +     * 
   68.96 +     * MAP_DIRECTMAP_ADDRESS should be safe. The worst case is a machine with 
   68.97 +     * 4GB and lots of network/disk cards that allocate loads of buffers. 
   68.98 +     * We'll have to revisit this if we ever support PAE (64GB).
   68.99 +     */
  68.100 +
  68.101 +    rc = parseelfimage(image_start, image_len, &dsi);
  68.102 +    if ( rc != 0 )
  68.103 +        return rc;
  68.104 +
  68.105 +    /* Set up domain options */
  68.106 +    if ( dsi.use_writable_pagetables )
  68.107 +        vm_assist(d, VMASST_CMD_enable, VMASST_TYPE_writable_pagetables);
  68.108 +
  68.109 +    /* Align load address to 4MB boundary. */
  68.110 +    dsi.v_start &= ~((1UL<<22)-1);
  68.111 +
  68.112 +    /*
  68.113 +     * Why do we need this? The number of page-table frames depends on the 
  68.114 +     * size of the bootstrap address space. But the size of the address space 
  68.115 +     * depends on the number of page-table frames (since each one is mapped 
  68.116 +     * read-only). We have a pair of simultaneous equations in two unknowns, 
  68.117 +     * which we solve by exhaustive search.
  68.118 +     */
  68.119 +    vinitrd_start    = round_pgup(dsi.v_kernend);
  68.120 +    vinitrd_end      = vinitrd_start + initrd_len;
  68.121 +    vphysmap_start   = round_pgup(vinitrd_end);
  68.122 +    vphysmap_end     = vphysmap_start + (nr_pages * sizeof(unsigned long));
  68.123 +    vpt_start        = round_pgup(vphysmap_end);
  68.124 +    for ( nr_pt_pages = 2; ; nr_pt_pages++ )
  68.125 +    {
  68.126 +        vpt_end          = vpt_start + (nr_pt_pages * PAGE_SIZE);
  68.127 +        vstartinfo_start = vpt_end;
  68.128 +        vstartinfo_end   = vstartinfo_start + PAGE_SIZE;
  68.129 +        vstack_start     = vstartinfo_end;
  68.130 +        vstack_end       = vstack_start + PAGE_SIZE;
  68.131 +        v_end            = (vstack_end + (1UL<<22)-1) & ~((1UL<<22)-1);
  68.132 +        if ( (v_end - vstack_end) < (512UL << 10) )
  68.133 +            v_end += 1UL << 22; /* Add extra 4MB to get >= 512kB padding. */
  68.134 +        if ( (((v_end - dsi.v_start + ((1UL<<L2_PAGETABLE_SHIFT)-1)) >> 
  68.135 +               L2_PAGETABLE_SHIFT) + 1) <= nr_pt_pages )
  68.136 +            break;
  68.137 +    }
  68.138 +
  68.139 +    printk("PHYSICAL MEMORY ARRANGEMENT:\n"
  68.140 +           " Kernel image:  %p->%p\n"
  68.141 +           " Initrd image:  %p->%p\n"
  68.142 +           " Dom0 alloc.:   %p->%p\n",
  68.143 +           _image_start, _image_start + image_len,
  68.144 +           _initrd_start, _initrd_start + initrd_len,
  68.145 +           alloc_start, alloc_end);
  68.146 +    printk("VIRTUAL MEMORY ARRANGEMENT:\n"
  68.147 +           " Loaded kernel: %p->%p\n"
  68.148 +           " Init. ramdisk: %p->%p\n"
  68.149 +           " Phys-Mach map: %p->%p\n"
  68.150 +           " Page tables:   %p->%p\n"
  68.151 +           " Start info:    %p->%p\n"
  68.152 +           " Boot stack:    %p->%p\n"
  68.153 +           " TOTAL:         %p->%p\n",
  68.154 +           dsi.v_kernstart, dsi.v_kernend, 
  68.155 +           vinitrd_start, vinitrd_end,
  68.156 +           vphysmap_start, vphysmap_end,
  68.157 +           vpt_start, vpt_end,
  68.158 +           vstartinfo_start, vstartinfo_end,
  68.159 +           vstack_start, vstack_end,
  68.160 +           dsi.v_start, v_end);
  68.161 +    printk(" ENTRY ADDRESS: %p\n", dsi.v_kernentry);
  68.162 +
  68.163 +    if ( (v_end - dsi.v_start) > (nr_pages * PAGE_SIZE) )
  68.164 +    {
  68.165 +        printk("Initial guest OS requires too much space\n"
  68.166 +               "(%luMB is greater than %luMB limit)\n",
  68.167 +               (v_end-dsi.v_start)>>20, (nr_pages<<PAGE_SHIFT)>>20);
  68.168 +        return -ENOMEM;
  68.169 +    }
  68.170 +
  68.171 +    /* Overlap with Xen protected area? */
  68.172 +    if ( (dsi.v_start < HYPERVISOR_VIRT_END) &&
  68.173 +         (v_end > HYPERVISOR_VIRT_START) )
  68.174 +    {
  68.175 +        printk("DOM0 image overlaps with Xen private area.\n");
  68.176 +        return -EINVAL;
  68.177 +    }
  68.178 +
  68.179 +    /* Paranoia: scrub DOM0's memory allocation. */
  68.180 +    printk("Scrubbing DOM0 RAM: ");
  68.181 +    dst = __va(alloc_start);
  68.182 +    while ( __pa(dst) < alloc_end )
  68.183 +    {
  68.184 +#define SCRUB_BYTES (100 * 1024 * 1024) /* 100MB */
  68.185 +        printk(".");
  68.186 +        touch_nmi_watchdog();
  68.187 +        if ( (alloc_end - __pa(dst)) > SCRUB_BYTES )
  68.188 +        {
  68.189 +            memset(dst, 0, SCRUB_BYTES);
  68.190 +            dst += SCRUB_BYTES;
  68.191 +        }
  68.192 +        else
  68.193 +        {
  68.194 +            memset(dst, 0, alloc_end - __pa(dst));
  68.195 +            break;
  68.196 +        }
  68.197 +    }
  68.198 +    printk("done.\n");
  68.199 +
  68.200 +    /* Construct a frame-allocation list for the initial domain. */
  68.201 +    for ( mfn = (alloc_start>>PAGE_SHIFT); 
  68.202 +          mfn < (alloc_end>>PAGE_SHIFT); 
  68.203 +          mfn++ )
  68.204 +    {
  68.205 +        page = &frame_table[mfn];
  68.206 +        page_set_owner(page, d);
  68.207 +        page->u.inuse.type_info = 0;
  68.208 +        page->count_info        = PGC_allocated | 1;
  68.209 +        list_add_tail(&page->list, &d->page_list);
  68.210 +        d->tot_pages++; d->max_pages++;
  68.211 +    }
  68.212 +
  68.213 +    mpt_alloc = (vpt_start - dsi.v_start) + alloc_start;
  68.214 +
  68.215 +    SET_GDT_ENTRIES(ed, DEFAULT_GDT_ENTRIES);
  68.216 +    SET_GDT_ADDRESS(ed, DEFAULT_GDT_ADDRESS);
  68.217 +
  68.218 +    /*
  68.219 +     * We're basically forcing default RPLs to 1, so that our "what privilege
  68.220 +     * level are we returning to?" logic works.
  68.221 +     */
  68.222 +    ed->thread.failsafe_selector = FLAT_GUESTOS_CS;
  68.223 +    ed->thread.event_selector    = FLAT_GUESTOS_CS;
  68.224 +    ed->thread.guestos_ss = FLAT_GUESTOS_DS;
  68.225 +    for ( i = 0; i < 256; i++ ) 
  68.226 +        ed->thread.traps[i].cs = FLAT_GUESTOS_CS;
  68.227 +
  68.228 +    /* WARNING: The new domain must have its 'processor' field filled in! */
  68.229 +    l2start = l2tab = (l2_pgentry_t *)mpt_alloc; mpt_alloc += PAGE_SIZE;
  68.230 +    memcpy(l2tab, &idle_pg_table[0], PAGE_SIZE);
  68.231 +    l2tab[LINEAR_PT_VIRT_START >> L2_PAGETABLE_SHIFT] =
  68.232 +        mk_l2_pgentry((unsigned long)l2start | __PAGE_HYPERVISOR);
  68.233 +    l2tab[PERDOMAIN_VIRT_START >> L2_PAGETABLE_SHIFT] =
  68.234 +        mk_l2_pgentry(__pa(d->mm_perdomain_pt) | __PAGE_HYPERVISOR);
  68.235 +    ed->mm.pagetable = mk_pagetable((unsigned long)l2start);
  68.236 +
  68.237 +    l2tab += l2_table_offset(dsi.v_start);
  68.238 +    mfn = alloc_start >> PAGE_SHIFT;
  68.239 +    for ( count = 0; count < ((v_end-dsi.v_start)>>PAGE_SHIFT); count++ )
  68.240 +    {
  68.241 +        if ( !((unsigned long)l1tab & (PAGE_SIZE-1)) )
  68.242 +        {
  68.243 +            l1start = l1tab = (l1_pgentry_t *)mpt_alloc; 
  68.244 +            mpt_alloc += PAGE_SIZE;
  68.245 +            *l2tab++ = mk_l2_pgentry((unsigned long)l1start | L2_PROT);
  68.246 +            clear_page(l1tab);
  68.247 +            if ( count == 0 )
  68.248 +                l1tab += l1_table_offset(dsi.v_start);
  68.249 +        }
  68.250 +        *l1tab++ = mk_l1_pgentry((mfn << PAGE_SHIFT) | L1_PROT);
  68.251 +        
  68.252 +        page = &frame_table[mfn];
  68.253 +        if ( !get_page_and_type(page, d, PGT_writable_page) )
  68.254 +            BUG();
  68.255 +
  68.256 +        mfn++;
  68.257 +    }
  68.258 +
  68.259 +    /* Pages that are part of page tables must be read only. */
  68.260 +    l2tab = l2start + l2_table_offset(vpt_start);
  68.261 +    l1start = l1tab = (l1_pgentry_t *)l2_pgentry_to_phys(*l2tab);
  68.262 +    l1tab += l1_table_offset(vpt_start);
  68.263 +    l2tab++;
  68.264 +    for ( count = 0; count < nr_pt_pages; count++ ) 
  68.265 +    {
  68.266 +        *l1tab = mk_l1_pgentry(l1_pgentry_val(*l1tab) & ~_PAGE_RW);
  68.267 +        page = &frame_table[l1_pgentry_to_pagenr(*l1tab)];
  68.268 +        if ( count == 0 )
  68.269 +        {
  68.270 +            page->u.inuse.type_info &= ~PGT_type_mask;
  68.271 +            page->u.inuse.type_info |= PGT_l2_page_table;
  68.272 +
  68.273 +            /*
  68.274 +             * No longer writable: decrement the type_count.
  68.275 +             * Installed as CR3: increment both the ref_count and type_count.
  68.276 +             * Net: just increment the ref_count.
  68.277 +             */
  68.278 +            get_page(page, d); /* an extra ref because of readable mapping */
  68.279 +
  68.280 +            /* Get another ref to L2 page so that it can be pinned. */
  68.281 +            if ( !get_page_and_type(page, d, PGT_l2_page_table) )
  68.282 +                BUG();
  68.283 +            set_bit(_PGT_pinned, &page->u.inuse.type_info);
  68.284 +        }
  68.285 +        else
  68.286 +        {
  68.287 +            page->u.inuse.type_info &= ~PGT_type_mask;
  68.288 +            page->u.inuse.type_info |= PGT_l1_page_table;
  68.289 +	    page->u.inuse.type_info |= 
  68.290 +		((dsi.v_start>>L2_PAGETABLE_SHIFT)+(count-1))<<PGT_va_shift;
  68.291 +
  68.292 +            /*
  68.293 +             * No longer writable: decrement the type_count.
  68.294 +             * This is an L1 page, installed in a validated L2 page:
  68.295 +             * increment both the ref_count and type_count.
  68.296 +             * Net: just increment the ref_count.
  68.297 +             */
  68.298 +            get_page(page, d); /* an extra ref because of readable mapping */
  68.299 +        }
  68.300 +        l1tab++;
  68.301 +        if( !((unsigned long)l1tab & (PAGE_SIZE - 1)) )
  68.302 +            l1start = l1tab = (l1_pgentry_t *)l2_pgentry_to_phys(*l2tab);
  68.303 +    }
  68.304 +
  68.305 +    /* Set up shared-info area. */
  68.306 +    update_dom_time(d);
  68.307 +    d->shared_info->domain_time = 0;
  68.308 +    /* Mask all upcalls... */
  68.309 +    for ( i = 0; i < MAX_VIRT_CPUS; i++ )
  68.310 +        d->shared_info->vcpu_data[i].evtchn_upcall_mask = 1;
  68.311 +    d->shared_info->n_vcpu = smp_num_cpus;
  68.312 +
  68.313 +    /* Install the new page tables. */
  68.314 +    __cli();
  68.315 +    write_ptbase(&ed->mm);
  68.316 +
  68.317 +    /* Copy the OS image. */
  68.318 +    (void)loadelfimage(image_start);
  68.319 +
  68.320 +    /* Copy the initial ramdisk. */
  68.321 +    if ( initrd_len != 0 )
  68.322 +        memcpy((void *)vinitrd_start, initrd_start, initrd_len);
  68.323 +    
  68.324 +    /* Set up start info area. */
  68.325 +    si = (start_info_t *)vstartinfo_start;
  68.326 +    memset(si, 0, PAGE_SIZE);
  68.327 +    si->nr_pages     = d->tot_pages;
  68.328 +    si->shared_info  = virt_to_phys(d->shared_info);
  68.329 +    si->flags        = SIF_PRIVILEGED | SIF_INITDOMAIN;
  68.330 +    si->pt_base      = vpt_start;
  68.331 +    si->nr_pt_frames = nr_pt_pages;
  68.332 +    si->mfn_list     = vphysmap_start;
  68.333 +
  68.334 +    /* Write the phys->machine and machine->phys table entries. */
  68.335 +    for ( pfn = 0; pfn < d->tot_pages; pfn++ )
  68.336 +    {
  68.337 +        mfn = pfn + (alloc_start>>PAGE_SHIFT);
  68.338 +#ifndef NDEBUG
  68.339 +#define REVERSE_START ((v_end - dsi.v_start) >> PAGE_SHIFT)
  68.340 +        if ( pfn > REVERSE_START )
  68.341 +            mfn = (alloc_end>>PAGE_SHIFT) - (pfn - REVERSE_START);
  68.342 +#endif
  68.343 +        ((unsigned long *)vphysmap_start)[pfn] = mfn;
  68.344 +        machine_to_phys_mapping[mfn] = pfn;
  68.345 +    }
  68.346 +
  68.347 +    if ( initrd_len != 0 )
  68.348 +    {
  68.349 +        si->mod_start = vinitrd_start;
  68.350 +        si->mod_len   = initrd_len;
  68.351 +        printk("Initrd len 0x%lx, start at 0x%p\n",
  68.352 +               si->mod_len, si->mod_start);
  68.353 +    }
  68.354 +
  68.355 +    dst = si->cmd_line;
  68.356 +    if ( cmdline != NULL )
  68.357 +    {
  68.358 +        for ( i = 0; i < 255; i++ )
  68.359 +        {
  68.360 +            if ( cmdline[i] == '\0' )
  68.361 +                break;
  68.362 +            *dst++ = cmdline[i];
  68.363 +        }
  68.364 +    }
  68.365 +    *dst = '\0';
  68.366 +
  68.367 +    /* Reinstate the caller's page tables. */
  68.368 +    write_ptbase(&current->mm);
  68.369 +    __sti();
  68.370 +
  68.371 +    /* Destroy low mappings - they were only for our convenience. */
  68.372 +    for ( i = 0; i < DOMAIN_ENTRIES_PER_L2_PAGETABLE; i++ )
  68.373 +        if ( l2_pgentry_val(l2start[i]) & _PAGE_PSE )
  68.374 +            l2start[i] = mk_l2_pgentry(0);
  68.375 +    zap_low_mappings(); /* Do the same for the idle page tables. */
  68.376 +    
  68.377 +    /* DOM0 gets access to everything. */
  68.378 +    physdev_init_dom0(d);
  68.379 +
  68.380 +    set_bit(DF_CONSTRUCTED, &d->d_flags);
  68.381 +
  68.382 +    new_thread(ed, dsi.v_kernentry, vstack_end, vstartinfo_start);
  68.383 +
  68.384 +#if 0 /* XXXXX DO NOT CHECK IN ENABLED !!! (but useful for testing so leave) */
  68.385 +    shadow_lock(&d->mm);
  68.386 +    shadow_mode_enable(p, SHM_test); 
  68.387 +    shadow_unlock(&d->mm);
  68.388 +#endif
  68.389 +
  68.390 +    return 0;
  68.391 +}
  68.392 +
  68.393 +int elf_sanity_check(Elf_Ehdr *ehdr)
  68.394 +{
  68.395 +    if ( !IS_ELF(*ehdr) ||
  68.396 +         (ehdr->e_ident[EI_CLASS] != ELFCLASS64) ||
  68.397 +         (ehdr->e_ident[EI_DATA] != ELFDATA2LSB) ||
  68.398 +         (ehdr->e_type != ET_EXEC) ||
  68.399 +         (ehdr->e_machine != EM_X86_64) )
  68.400 +    {
  68.401 +        printk("DOM0 image is not x86/64-compatible executable Elf image.\n");
  68.402 +        return 0;
  68.403 +    }
  68.404 +
  68.405 +    return 1;
  68.406 +}
    69.1 --- a/xen/arch/x86/x86_64/entry.S	Fri Jan 28 14:53:32 2005 +0000
    69.2 +++ b/xen/arch/x86/x86_64/entry.S	Fri Feb 04 14:44:18 2005 +0000
    69.3 @@ -0,0 +1,158 @@
    69.4 +/*
    69.5 + * Hypercall and fault low-level handling routines.
    69.6 + *
    69.7 + * Copyright (c) 2005, K A Fraser
    69.8 + */
    69.9 +
   69.10 +#include <xen/config.h>
   69.11 +#include <xen/errno.h>
   69.12 +#include <xen/softirq.h>
   69.13 +#include <asm/asm_defns.h>
   69.14 +#include <asm/apicdef.h>
   69.15 +#include <public/xen.h>
   69.16 +
   69.17 +ENTRY(hypercall)
   69.18 +        iret
   69.19 +
   69.20 +ENTRY(ret_from_intr)
   69.21 +restore_all_xen:
   69.22 +        popq  %r15
   69.23 +        popq  %r14
   69.24 +        popq  %r13
   69.25 +        popq  %r12
   69.26 +        popq  %rbp
   69.27 +        popq  %rbx
   69.28 +        popq  %r11
   69.29 +        popq  %r10
   69.30 +        popq  %r9
   69.31 +        popq  %r8
   69.32 +        popq  %rax
   69.33 +        popq  %rcx
   69.34 +        popq  %rdx
   69.35 +        popq  %rsi
   69.36 +        popq  %rdi
   69.37 +        addq  $8,%rsp
   69.38 +        iretq
   69.39 +
   69.40 +error_code:
   69.41 +        SAVE_ALL
   69.42 +        movq  %rsp,%rdi
   69.43 +        movl  XREGS_entry_vector(%rsp),%eax
   69.44 +        leaq  SYMBOL_NAME(exception_table)(%rip),%rdx
   69.45 +        callq *(%rdx,%rax,8)
   69.46 +	jmp   restore_all_xen
   69.47 +
   69.48 +ENTRY(divide_error)
   69.49 +        pushq $0
   69.50 +        movl  $TRAP_divide_error,4(%rsp)
   69.51 +        jmp   error_code
   69.52 +
   69.53 +ENTRY(coprocessor_error)
   69.54 +        pushq $0
   69.55 +        movl  $TRAP_copro_error,4(%rsp)
   69.56 +	jmp   error_code
   69.57 +
   69.58 +ENTRY(simd_coprocessor_error)
   69.59 +        pushq $0
   69.60 +        movl  $TRAP_simd_error,4(%rsp)
   69.61 +	jmp error_code
   69.62 +
   69.63 +ENTRY(device_not_available)
   69.64 +        pushq $0
   69.65 +        movl  $TRAP_no_device,4(%rsp)
   69.66 +        jmp   error_code
   69.67 +
   69.68 +ENTRY(debug)
   69.69 +        pushq $0
   69.70 +        movl  $TRAP_debug,4(%rsp)
   69.71 +	jmp   error_code
   69.72 +
   69.73 +ENTRY(int3)
   69.74 +        pushq $0
   69.75 +	movl  $TRAP_int3,4(%rsp)
   69.76 +	jmp   error_code
   69.77 +
   69.78 +ENTRY(overflow)
   69.79 +        pushq $0
   69.80 +	movl  $TRAP_overflow,4(%rsp)
   69.81 +	jmp   error_code
   69.82 +
   69.83 +ENTRY(bounds)
   69.84 +        pushq $0
   69.85 +	movl  $TRAP_bounds,4(%rsp)
   69.86 +	jmp   error_code
   69.87 +
   69.88 +ENTRY(invalid_op)
   69.89 +        pushq $0
   69.90 +	movl  $TRAP_invalid_op,4(%rsp)
   69.91 +	jmp   error_code
   69.92 +
   69.93 +ENTRY(coprocessor_segment_overrun)
   69.94 +        pushq $0
   69.95 +	movl  $TRAP_copro_seg,4(%rsp)
   69.96 +	jmp   error_code
   69.97 +
   69.98 +ENTRY(invalid_TSS)
   69.99 +        movl  $TRAP_invalid_tss,4(%rsp)
  69.100 +	jmp   error_code
  69.101 +
  69.102 +ENTRY(segment_not_present)
  69.103 +        movl  $TRAP_no_segment,4(%rsp)
  69.104 +	jmp   error_code
  69.105 +
  69.106 +ENTRY(stack_segment)
  69.107 +        movl  $TRAP_stack_error,4(%rsp)
  69.108 +	jmp   error_code
  69.109 +
  69.110 +ENTRY(general_protection)
  69.111 +        movl  $TRAP_gp_fault,4(%rsp)
  69.112 +	jmp   error_code
  69.113 +
  69.114 +ENTRY(alignment_check)
  69.115 +        movl  $TRAP_alignment_check,4(%rsp)
  69.116 +	jmp   error_code
  69.117 +
  69.118 +ENTRY(page_fault)
  69.119 +        movl  $TRAP_page_fault,4(%rsp)
  69.120 +	jmp   error_code
  69.121 +
  69.122 +ENTRY(machine_check)
  69.123 +        pushq $0
  69.124 +        movl  $TRAP_machine_check,4(%rsp)
  69.125 +	jmp   error_code
  69.126 +
  69.127 +ENTRY(spurious_interrupt_bug)
  69.128 +        pushq $0
  69.129 +        movl  $TRAP_spurious_int,4(%rsp)
  69.130 +	jmp   error_code
  69.131 +
  69.132 +ENTRY(double_fault)
  69.133 +        movl  $TRAP_double_fault,4(%rsp)
  69.134 +        jmp   error_code
  69.135 +
  69.136 +ENTRY(nmi)
  69.137 +        iret
  69.138 +
  69.139 +.data
  69.140 +
  69.141 +ENTRY(exception_table)
  69.142 +        .quad SYMBOL_NAME(do_divide_error)
  69.143 +        .quad SYMBOL_NAME(do_debug)
  69.144 +        .quad 0 # nmi
  69.145 +        .quad SYMBOL_NAME(do_int3)
  69.146 +        .quad SYMBOL_NAME(do_overflow)
  69.147 +        .quad SYMBOL_NAME(do_bounds)
  69.148 +        .quad SYMBOL_NAME(do_invalid_op)
  69.149 +        .quad SYMBOL_NAME(math_state_restore)
  69.150 +        .quad SYMBOL_NAME(do_double_fault)
  69.151 +        .quad SYMBOL_NAME(do_coprocessor_segment_overrun)
  69.152 +        .quad SYMBOL_NAME(do_invalid_TSS)
  69.153 +        .quad SYMBOL_NAME(do_segment_not_present)
  69.154 +        .quad SYMBOL_NAME(do_stack_segment)
  69.155 +        .quad SYMBOL_NAME(do_general_protection)
  69.156 +        .quad SYMBOL_NAME(do_page_fault)
  69.157 +        .quad SYMBOL_NAME(do_spurious_interrupt_bug)
  69.158 +        .quad SYMBOL_NAME(do_coprocessor_error)
  69.159 +        .quad SYMBOL_NAME(do_alignment_check)
  69.160 +        .quad SYMBOL_NAME(do_machine_check)
  69.161 +        .quad SYMBOL_NAME(do_simd_coprocessor_error)
    70.1 --- a/xen/arch/x86/x86_64/mm.c	Fri Jan 28 14:53:32 2005 +0000
    70.2 +++ b/xen/arch/x86/x86_64/mm.c	Fri Feb 04 14:44:18 2005 +0000
    70.3 @@ -27,49 +27,189 @@
    70.4  #include <asm/fixmap.h>
    70.5  #include <asm/domain_page.h>
    70.6  
    70.7 -static inline void set_pte_phys(unsigned long vaddr,
    70.8 -                                l1_pgentry_t entry)
    70.9 +void *safe_page_alloc(void)
   70.10  {
   70.11 -    l4_pgentry_t *l4ent;
   70.12 -    l3_pgentry_t *l3ent;
   70.13 -    l2_pgentry_t *l2ent;
   70.14 -    l1_pgentry_t *l1ent;
   70.15 -
   70.16 -    l4ent = &idle_pg_table[l4_table_offset(vaddr)];
   70.17 -    l3ent = l4_pgentry_to_l3(*l4ent) + l3_table_offset(vaddr);
   70.18 -    l2ent = l3_pgentry_to_l2(*l3ent) + l2_table_offset(vaddr);
   70.19 -    l1ent = l2_pgentry_to_l1(*l2ent) + l1_table_offset(vaddr);
   70.20 -    *l1ent = entry;
   70.21 -
   70.22 -    /* It's enough to flush this one mapping. */
   70.23 -    __flush_tlb_one(vaddr);
   70.24 +    extern int early_boot;
   70.25 +    if ( early_boot )
   70.26 +        return __va(alloc_boot_pages(PAGE_SIZE, PAGE_SIZE));
   70.27 +    return (void *)alloc_xenheap_page();
   70.28  }
   70.29  
   70.30 -
   70.31 -void __set_fixmap(enum fixed_addresses idx, 
   70.32 -                  l1_pgentry_t entry)
   70.33 +/* Map physical byte range (@p, @p+@s) at virt address @v in pagetable @pt. */
   70.34 +int map_pages(
   70.35 +    pagetable_t *pt,
   70.36 +    unsigned long v,
   70.37 +    unsigned long p,
   70.38 +    unsigned long s,
   70.39 +    unsigned long flags)
   70.40  {
   70.41 -    unsigned long address = fix_to_virt(idx);
   70.42 +    l4_pgentry_t *pl4e;
   70.43 +    l3_pgentry_t *pl3e;
   70.44 +    l2_pgentry_t *pl2e;
   70.45 +    l1_pgentry_t *pl1e;
   70.46 +    void         *newpg;
   70.47  
   70.48 -    if ( likely(idx < __end_of_fixed_addresses) )
   70.49 -        set_pte_phys(address, entry);
   70.50 -    else
   70.51 -        printk("Invalid __set_fixmap\n");
   70.52 +    while ( s != 0 )
   70.53 +    {
   70.54 +        pl4e = &pt[l4_table_offset(v)];
   70.55 +        if ( !(l4_pgentry_val(*pl4e) & _PAGE_PRESENT) )
   70.56 +        {
   70.57 +            newpg = safe_page_alloc();
   70.58 +            clear_page(newpg);
   70.59 +            *pl4e = mk_l4_pgentry(__pa(newpg) | __PAGE_HYPERVISOR);
   70.60 +        }
   70.61 +
   70.62 +        pl3e = l4_pgentry_to_l3(*pl4e) + l3_table_offset(v);
   70.63 +        if ( !(l3_pgentry_val(*pl3e) & _PAGE_PRESENT) )
   70.64 +        {
   70.65 +            newpg = safe_page_alloc();
   70.66 +            clear_page(newpg);
   70.67 +            *pl3e = mk_l3_pgentry(__pa(newpg) | __PAGE_HYPERVISOR);
   70.68 +        }
   70.69 +
   70.70 +        pl2e = l3_pgentry_to_l2(*pl3e) + l2_table_offset(v);
   70.71 +
   70.72 +        if ( ((s|v|p) & ((1<<L2_PAGETABLE_SHIFT)-1)) == 0 )
   70.73 +        {
   70.74 +            /* Super-page mapping. */
   70.75 +            if ( (l2_pgentry_val(*pl2e) & _PAGE_PRESENT) )
   70.76 +                __flush_tlb_pge();
   70.77 +            *pl2e = mk_l2_pgentry(p|flags|_PAGE_PSE);
   70.78 +
   70.79 +            v += 1 << L2_PAGETABLE_SHIFT;
   70.80 +            p += 1 << L2_PAGETABLE_SHIFT;
   70.81 +            s -= 1 << L2_PAGETABLE_SHIFT;
   70.82 +        }
   70.83 +        else
   70.84 +        {
   70.85 +            /* Normal page mapping. */
   70.86 +            if ( !(l2_pgentry_val(*pl2e) & _PAGE_PRESENT) )
   70.87 +            {
   70.88 +                newpg = safe_page_alloc();
   70.89 +                clear_page(newpg);
   70.90 +                *pl2e = mk_l2_pgentry(__pa(newpg) | __PAGE_HYPERVISOR);
   70.91 +            }
   70.92 +            pl1e = l2_pgentry_to_l1(*pl2e) + l1_table_offset(v);
   70.93 +            if ( (l1_pgentry_val(*pl1e) & _PAGE_PRESENT) )
   70.94 +                __flush_tlb_one(v);
   70.95 +            *pl1e = mk_l1_pgentry(p|flags);
   70.96 +
   70.97 +            v += 1 << L1_PAGETABLE_SHIFT;
   70.98 +            p += 1 << L1_PAGETABLE_SHIFT;
   70.99 +            s -= 1 << L1_PAGETABLE_SHIFT;
  70.100 +        }
  70.101 +    }
  70.102 +
  70.103 +    return 0;
  70.104 +}
  70.105 +
  70.106 +void __set_fixmap(
  70.107 +    enum fixed_addresses idx, unsigned long p, unsigned long flags)
  70.108 +{
  70.109 +    if ( unlikely(idx >= __end_of_fixed_addresses) )
  70.110 +        BUG();
  70.111 +    map_pages(idle_pg_table, fix_to_virt(idx), p, PAGE_SIZE, flags);
  70.112  }
  70.113  
  70.114  
  70.115  void __init paging_init(void)
  70.116  {
  70.117 +    void *newpt;
  70.118 +    unsigned long i, p, max;
  70.119 +
  70.120 +    /* Map all of physical memory. */
  70.121 +    max = (max_page + (1UL << L2_PAGETABLE_SHIFT) - 1UL) &
  70.122 +        ~((1UL << L2_PAGETABLE_SHIFT) - 1UL);
  70.123 +    map_pages(idle_pg_table, PAGE_OFFSET, 0, max, PAGE_HYPERVISOR);
  70.124 +
  70.125 +    /*
  70.126 +     * Allocate and map the machine-to-phys table.
  70.127 +     * This also ensures L3 is present for ioremap().
  70.128 +     */
  70.129 +    for ( i = 0; i < max_page; i += ((1UL << L2_PAGETABLE_SHIFT) / 8) )
  70.130 +    {
  70.131 +        p = alloc_boot_pages(1UL << L2_PAGETABLE_SHIFT,
  70.132 +                             1UL << L2_PAGETABLE_SHIFT);
  70.133 +        if ( p == 0 )
  70.134 +            panic("Not enough memory for m2p table\n");
  70.135 +        map_pages(idle_pg_table, RDWR_MPT_VIRT_START + i*8, p, 
  70.136 +                  1UL << L2_PAGETABLE_SHIFT, PAGE_HYPERVISOR);
  70.137 +        memset((void *)(RDWR_MPT_VIRT_START + i*8), 0x55,
  70.138 +               1UL << L2_PAGETABLE_SHIFT);
  70.139 +    }
  70.140 +
  70.141 +    /* Create read-only mapping of MPT for guest-OS use. */
  70.142 +    newpt = (void *)alloc_xenheap_page();
  70.143 +    clear_page(newpt);
  70.144 +    idle_pg_table[l4_table_offset(RO_MPT_VIRT_START)] =
  70.145 +        mk_l4_pgentry((__pa(newpt) | __PAGE_HYPERVISOR | _PAGE_USER) &
  70.146 +                      ~_PAGE_RW);
  70.147 +    /* Copy the L3 mappings from the RDWR_MPT area. */
  70.148 +    p  = l4_pgentry_val(idle_pg_table[l4_table_offset(RDWR_MPT_VIRT_START)]);
  70.149 +    p &= PAGE_MASK;
  70.150 +    p += l3_table_offset(RDWR_MPT_VIRT_START) * sizeof(l3_pgentry_t);
  70.151 +    newpt = (void *)((unsigned long)newpt +
  70.152 +                     (l3_table_offset(RO_MPT_VIRT_START) *
  70.153 +                      sizeof(l3_pgentry_t)));
  70.154 +    memcpy(newpt, __va(p),
  70.155 +           (RDWR_MPT_VIRT_END - RDWR_MPT_VIRT_START) >> L3_PAGETABLE_SHIFT);
  70.156 +
  70.157      /* Set up linear page table mapping. */
  70.158 -    idle_pg_table[LINEAR_PT_VIRT_START >> L4_PAGETABLE_SHIFT] =
  70.159 +    idle_pg_table[l4_table_offset(LINEAR_PT_VIRT_START)] =
  70.160          mk_l4_pgentry(__pa(idle_pg_table) | __PAGE_HYPERVISOR);
  70.161  }
  70.162  
  70.163  void __init zap_low_mappings(void)
  70.164  {
  70.165      idle_pg_table[0] = mk_l4_pgentry(0);
  70.166 +    flush_tlb_all_pge();
  70.167  }
  70.168  
  70.169 +void subarch_init_memory(struct domain *dom_xen)
  70.170 +{
  70.171 +    unsigned long i, v, m2p_start_mfn;
  70.172 +    l3_pgentry_t l3e;
  70.173 +    l2_pgentry_t l2e;
  70.174 +
  70.175 +    /*
  70.176 +     * We are rather picky about the layout of 'struct pfn_info'. The
  70.177 +     * count_info and domain fields must be adjacent, as we perform atomic
  70.178 +     * 64-bit operations on them.
  70.179 +     */
  70.180 +    if ( (offsetof(struct pfn_info, u.inuse._domain) != 
  70.181 +          (offsetof(struct pfn_info, count_info) + sizeof(u32))) )
  70.182 +    {
  70.183 +        printk("Weird pfn_info layout (%ld,%ld,%d)\n",
  70.184 +               offsetof(struct pfn_info, count_info),
  70.185 +               offsetof(struct pfn_info, u.inuse._domain),
  70.186 +               sizeof(struct pfn_info));
  70.187 +        for ( ; ; ) ;
  70.188 +    }
  70.189 +
  70.190 +    /* M2P table is mappable read-only by privileged domains. */
  70.191 +    for ( v  = RDWR_MPT_VIRT_START; 
  70.192 +          v != RDWR_MPT_VIRT_END;
  70.193 +          v += 1 << L2_PAGETABLE_SHIFT )
  70.194 +    {
  70.195 +        l3e = l4_pgentry_to_l3(idle_pg_table[l4_table_offset(v)])[
  70.196 +            l3_table_offset(v)];
  70.197 +        if ( !(l3_pgentry_val(l3e) & _PAGE_PRESENT) )
  70.198 +            continue;
  70.199 +        l2e = l3_pgentry_to_l2(l3e)[l2_table_offset(v)];
  70.200 +        if ( !(l2_pgentry_val(l2e) & _PAGE_PRESENT) )
  70.201 +            continue;
  70.202 +        m2p_start_mfn = l2_pgentry_to_pagenr(l2e);
  70.203 +
  70.204 +        for ( i = 0; i < ENTRIES_PER_L1_PAGETABLE; i++ )
  70.205 +        {
  70.206 +            frame_table[m2p_start_mfn+i].count_info = PGC_allocated | 1;
  70.207 +            /* gdt to make sure it's only mapped read-only by non-privileged
  70.208 +               domains. */
  70.209 +            frame_table[m2p_start_mfn+i].u.inuse.type_info = PGT_gdt_page | 1;
  70.210 +            page_set_owner(&frame_table[m2p_start_mfn+i], dom_xen);
  70.211 +        }
  70.212 +    }
  70.213 +}
  70.214  
  70.215  /*
  70.216   * Allows shooting down of borrowed page-table use on specific CPUs.
  70.217 @@ -90,19 +230,10 @@ void synchronise_pagetables(unsigned lon
  70.218  
  70.219  long do_stack_switch(unsigned long ss, unsigned long esp)
  70.220  {
  70.221 -#if 0
  70.222 -    int nr = smp_processor_id();
  70.223 -    struct tss_struct *t = &init_tss[nr];
  70.224 -
  70.225 -    /* We need to do this check as we load and use SS on guest's behalf. */
  70.226 -    if ( (ss & 3) == 0 )
  70.227 +    if ( (ss & 3) != 3 )
  70.228          return -EPERM;
  70.229 -
  70.230      current->thread.guestos_ss = ss;
  70.231      current->thread.guestos_sp = esp;
  70.232 -    t->ss1  = ss;
  70.233 -    t->esp1 = esp;
  70.234 -#endif
  70.235      return 0;
  70.236  }
  70.237  
    71.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    71.2 +++ b/xen/arch/x86/x86_64/traps.c	Fri Feb 04 14:44:18 2005 +0000
    71.3 @@ -0,0 +1,202 @@
    71.4 +
    71.5 +#include <xen/config.h>
    71.6 +#include <xen/init.h>
    71.7 +#include <xen/sched.h>
    71.8 +#include <xen/lib.h>
    71.9 +#include <xen/errno.h>
   71.10 +#include <xen/mm.h>
   71.11 +#include <xen/irq.h>
   71.12 +#include <xen/console.h>
   71.13 +
   71.14 +static int kstack_depth_to_print = 8*20;
   71.15 +
   71.16 +static inline int kernel_text_address(unsigned long addr)
   71.17 +{
   71.18 +    if (addr >= (unsigned long) &_stext &&
   71.19 +        addr <= (unsigned long) &_etext)
   71.20 +        return 1;
   71.21 +    return 0;
   71.22 +
   71.23 +}
   71.24 +
   71.25 +void show_guest_stack(void)
   71.26 +{
   71.27 +    int i;
   71.28 +    execution_context_t *ec = get_execution_context();
   71.29 +    unsigned long *stack = (unsigned long *)ec->rsp;
   71.30 +    printk("Guest RIP is %lx\n   ", ec->rip);
   71.31 +
   71.32 +    for ( i = 0; i < kstack_depth_to_print; i++ )
   71.33 +    {
   71.34 +        if ( ((long)stack & (STACK_SIZE-1)) == 0 )
   71.35 +            break;
   71.36 +        if ( i && ((i % 8) == 0) )
   71.37 +            printk("\n    ");
   71.38 +            printk("%p ", *stack++);
   71.39 +    }
   71.40 +    printk("\n");
   71.41 +    
   71.42 +}
   71.43 +
   71.44 +void show_trace(unsigned long *rsp)
   71.45 +{
   71.46 +    unsigned long *stack, addr;
   71.47 +    int i;
   71.48 +
   71.49 +    printk("Call Trace from RSP=%p:\n   ", rsp);
   71.50 +    stack = rsp;
   71.51 +    i = 0;
   71.52 +    while (((long) stack & (STACK_SIZE-1)) != 0) {
   71.53 +        addr = *stack++;
   71.54 +        if (kernel_text_address(addr)) {
   71.55 +            if (i && ((i % 6) == 0))
   71.56 +                printk("\n   ");
   71.57 +            printk("[<%p>] ", addr);
   71.58 +            i++;
   71.59 +        }
   71.60 +    }
   71.61 +    printk("\n");
   71.62 +}
   71.63 +
   71.64 +void show_stack(unsigned long *rsp)
   71.65 +{
   71.66 +    unsigned long *stack;
   71.67 +    int i;
   71.68 +
   71.69 +    printk("Stack trace from RSP=%p:\n    ", rsp);
   71.70 +
   71.71 +    stack = rsp;
   71.72 +    for ( i = 0; i < kstack_depth_to_print; i++ )
   71.73 +    {
   71.74 +        if ( ((long)stack & (STACK_SIZE-1)) == 0 )
   71.75 +            break;
   71.76 +        if ( i && ((i % 8) == 0) )
   71.77 +            printk("\n    ");
   71.78 +        if ( kernel_text_address(*stack) )
   71.79 +            printk("[%p] ", *stack++);
   71.80 +        else
   71.81 +            printk("%p ", *stack++);            
   71.82 +    }
   71.83 +    printk("\n");
   71.84 +
   71.85 +    show_trace(rsp);
   71.86 +}
   71.87 +
   71.88 +void show_registers(struct xen_regs *regs)
   71.89 +{
   71.90 +    printk("CPU:    %d\nEIP:    %04lx:[<%p>]      \nEFLAGS: %p\n",
   71.91 +           smp_processor_id(), 0xffff & regs->cs, regs->rip, regs->eflags);
   71.92 +    printk("rax: %p   rbx: %p   rcx: %p   rdx: %p\n",
   71.93 +           regs->rax, regs->rbx, regs->rcx, regs->rdx);
   71.94 +    printk("rsi: %p   rdi: %p   rbp: %p   rsp: %p\n",
   71.95 +           regs->rsi, regs->rdi, regs->rbp, regs->rsp);
   71.96 +    printk("r8:  %p   r9:  %p   r10: %p   r11: %p\n",
   71.97 +           regs->r8,  regs->r9,  regs->r10, regs->r11);
   71.98 +    printk("r12: %p   r13: %p   r14: %p   r15: %p\n",
   71.99 +           regs->r12, regs->r13, regs->r14, regs->r15);
  71.100 +
  71.101 +    show_stack((unsigned long *)regs->rsp);
  71.102 +} 
  71.103 +
  71.104 +void show_page_walk(unsigned long addr)
  71.105 +{
  71.106 +    unsigned long page = read_cr3();
  71.107 +    
  71.108 +    printk("Pagetable walk from %p:\n", addr);
  71.109 +
  71.110 +    page &= PAGE_MASK;
  71.111 +    page = ((unsigned long *) __va(page))[l4_table_offset(addr)];
  71.112 +    printk(" L4 = %p\n", page);
  71.113 +    if ( !(page & _PAGE_PRESENT) )
  71.114 +        return;
  71.115 +
  71.116 +    page &= PAGE_MASK;
  71.117 +    page = ((unsigned long *) __va(page))[l3_table_offset(addr)];
  71.118 +    printk("  L3 = %p\n", page);
  71.119 +    if ( !(page & _PAGE_PRESENT) )
  71.120 +        return;
  71.121 +
  71.122 +    page &= PAGE_MASK;
  71.123 +    page = ((unsigned long *) __va(page))[l2_table_offset(addr)];
  71.124 +    printk("   L2 = %p %s\n", page, (page & _PAGE_PSE) ? "(2MB)" : "");
  71.125 +    if ( !(page & _PAGE_PRESENT) || (page & _PAGE_PSE) )
  71.126 +        return;
  71.127 +
  71.128 +    page &= PAGE_MASK;
  71.129 +    page = ((unsigned long *) __va(page))[l1_table_offset(addr)];
  71.130 +    printk("    L1 = %p\n", page);
  71.131 +}
  71.132 +
  71.133 +#define DOUBLEFAULT_STACK_SIZE 1024
  71.134 +static unsigned char doublefault_stack[DOUBLEFAULT_STACK_SIZE];
  71.135 +asmlinkage void double_fault(void);
  71.136 +
  71.137 +asmlinkage void do_double_fault(struct xen_regs *regs)
  71.138 +{
  71.139 +    /* Disable the NMI watchdog. It's useless now. */
  71.140 +    watchdog_on = 0;
  71.141 +
  71.142 +    /* Find information saved during fault and dump it to the console. */
  71.143 +    printk("************************************\n");
  71.144 +    printk("EIP:    %04lx:[<%p>]      \nEFLAGS: %p\n",
  71.145 +           0xffff & regs->cs, regs->rip, regs->eflags);
  71.146 +    printk("rax: %p   rbx: %p   rcx: %p   rdx: %p\n",
  71.147 +           regs->rax, regs->rbx, regs->rcx, regs->rdx);
  71.148 +    printk("rsi: %p   rdi: %p   rbp: %p   rsp: %p\n",
  71.149 +           regs->rsi, regs->rdi, regs->rbp, regs->rsp);
  71.150 +    printk("r8:  %p   r9:  %p   r10: %p   r11: %p\n",
  71.151 +           regs->r8,  regs->r9,  regs->r10, regs->r11);
  71.152 +    printk("r12: %p   r13: %p   r14: %p   r15: %p\n",
  71.153 +           regs->r12, regs->r13, regs->r14, regs->r15);
  71.154 +    printk("************************************\n");
  71.155 +    printk("CPU%d DOUBLE FAULT -- system shutdown\n",
  71.156 +           logical_smp_processor_id());
  71.157 +    printk("System needs manual reset.\n");
  71.158 +    printk("************************************\n");
  71.159 +
  71.160 +    /* Lock up the console to prevent spurious output from other CPUs. */
  71.161 +    console_force_lock();
  71.162 +
  71.163 +    /* Wait for manual reset. */
  71.164 +    for ( ; ; )
  71.165 +        __asm__ __volatile__ ( "hlt" );
  71.166 +}
  71.167 +
  71.168 +void __init doublefault_init(void)
  71.169 +{
  71.170 +    int i;
  71.171 +
  71.172 +    /* Initialise IST1 for each CPU. Note the handler is non-reentrant. */
  71.173 +    for ( i = 0; i < NR_CPUS; i++ )
  71.174 +        init_tss[i].ist[0] = (unsigned long)
  71.175 +            &doublefault_stack[DOUBLEFAULT_STACK_SIZE];
  71.176 +
  71.177 +    /* Set interrupt gate for double faults, specifying IST1. */
  71.178 +    set_intr_gate(TRAP_double_fault, &double_fault);
  71.179 +    idt_table[TRAP_double_fault].a |= 1UL << 32; /* IST1 */
  71.180 +}
  71.181 +
  71.182 +void *decode_reg(struct xen_regs *regs, u8 b)
  71.183 +{
  71.184 +    switch ( b )
  71.185 +    {
  71.186 +    case  0: return &regs->rax;
  71.187 +    case  1: return &regs->rcx;
  71.188 +    case  2: return &regs->rdx;
  71.189 +    case  3: return &regs->rbx;
  71.190 +    case  4: return &regs->rsp;
  71.191 +    case  5: return &regs->rbp;
  71.192 +    case  6: return &regs->rsi;
  71.193 +    case  7: return &regs->rdi;
  71.194 +    case  8: return &regs->r8;
  71.195 +    case  9: return &regs->r9;
  71.196 +    case 10: return &regs->r10;
  71.197 +    case 11: return &regs->r11;
  71.198 +    case 12: return &regs->r12;
  71.199 +    case 13: return &regs->r13;
  71.200 +    case 14: return &regs->r14;
  71.201 +    case 15: return &regs->r15;
  71.202 +    }
  71.203 +
  71.204 +    return NULL;
  71.205 +}
    72.1 --- a/xen/arch/x86/x86_64/xen.lds	Fri Jan 28 14:53:32 2005 +0000
    72.2 +++ b/xen/arch/x86/x86_64/xen.lds	Fri Feb 04 14:44:18 2005 +0000
    72.3 @@ -62,12 +62,8 @@ SECTIONS
    72.4    __initcall_start = .;
    72.5    .initcall.init : { *(.initcall.init) } :text
    72.6    __initcall_end = .;
    72.7 -  . = ALIGN(4096);
    72.8    __init_end = .;
    72.9  
   72.10 -  . = ALIGN(4096);
   72.11 -  .data.page_aligned : { *(.data.idt) } :text
   72.12 -
   72.13    __bss_start = .;		/* BSS */
   72.14    .bss : {
   72.15  	*(.bss)
    73.1 --- a/xen/common/Makefile	Fri Jan 28 14:53:32 2005 +0000
    73.2 +++ b/xen/common/Makefile	Fri Feb 04 14:44:18 2005 +0000
    73.3 @@ -5,6 +5,7 @@ ifeq ($(TARGET_ARCH),ia64)
    73.4  OBJS := $(subst dom_mem_ops.o,,$(OBJS))
    73.5  OBJS := $(subst grant_table.o,,$(OBJS))
    73.6  OBJS := $(subst page_alloc.o,,$(OBJS))
    73.7 +OBJS := $(subst physdev.o,,$(OBJS))
    73.8  OBJS := $(subst slab.o,,$(OBJS))
    73.9  endif
   73.10  
    74.1 --- a/xen/common/ac_timer.c	Fri Jan 28 14:53:32 2005 +0000
    74.2 +++ b/xen/common/ac_timer.c	Fri Feb 04 14:44:18 2005 +0000
    74.3 @@ -130,7 +130,7 @@ static int add_entry(struct ac_timer **h
    74.4      if ( unlikely(sz == GET_HEAP_LIMIT(heap)) )
    74.5      {
    74.6          int i, limit = (GET_HEAP_LIMIT(heap)+1) << 1;
    74.7 -        struct ac_timer **new_heap = xmalloc(limit*sizeof(struct ac_timer *));
    74.8 +        struct ac_timer **new_heap = xmalloc_array(struct ac_timer *, limit);
    74.9          if ( new_heap == NULL ) BUG();
   74.10          memcpy(new_heap, heap, (limit>>1)*sizeof(struct ac_timer *));
   74.11          for ( i = 0; i < smp_num_cpus; i++ )
   74.12 @@ -278,8 +278,7 @@ void __init ac_timer_init(void)
   74.13  
   74.14      for ( i = 0; i < smp_num_cpus; i++ )
   74.15      {
   74.16 -        ac_timers[i].heap = xmalloc(
   74.17 -            (DEFAULT_HEAP_LIMIT+1) * sizeof(struct ac_timer *));
   74.18 +        ac_timers[i].heap = xmalloc_array(struct ac_timer *, DEFAULT_HEAP_LIMIT+1);
   74.19          if ( ac_timers[i].heap == NULL ) BUG();
   74.20          SET_HEAP_SIZE(ac_timers[i].heap, 0);
   74.21          SET_HEAP_LIMIT(ac_timers[i].heap, DEFAULT_HEAP_LIMIT);
    75.1 --- a/xen/common/dom0_ops.c	Fri Jan 28 14:53:32 2005 +0000
    75.2 +++ b/xen/common/dom0_ops.c	Fri Feb 04 14:44:18 2005 +0000
    75.3 @@ -291,44 +291,6 @@ long do_dom0_op(dom0_op_t *u_dom0_op)
    75.4      }
    75.5      break;
    75.6  
    75.7 -    case DOM0_GETMEMLIST:
    75.8 -    {
    75.9 -        int i;
   75.10 -        struct domain *d = find_domain_by_id(op->u.getmemlist.domain);
   75.11 -        unsigned long max_pfns = op->u.getmemlist.max_pfns;
   75.12 -        unsigned long pfn;
   75.13 -        unsigned long *buffer = op->u.getmemlist.buffer;
   75.14 -        struct list_head *list_ent;
   75.15 -
   75.16 -        ret = -EINVAL;
   75.17 -        if ( d != NULL )
   75.18 -        {
   75.19 -            ret = 0;
   75.20 -
   75.21 -            spin_lock(&d->page_alloc_lock);
   75.22 -            list_ent = d->page_list.next;
   75.23 -            for ( i = 0; (i < max_pfns) && (list_ent != &d->page_list); i++ )
   75.24 -            {
   75.25 -                pfn = list_entry(list_ent, struct pfn_info, list) - 
   75.26 -                    frame_table;
   75.27 -                if ( put_user(pfn, buffer) )
   75.28 -                {
   75.29 -                    ret = -EFAULT;
   75.30 -                    break;
   75.31 -                }
   75.32 -                buffer++;
   75.33 -                list_ent = frame_table[pfn].list.next;
   75.34 -            }
   75.35 -            spin_unlock(&d->page_alloc_lock);
   75.36 -
   75.37 -            op->u.getmemlist.num_pfns = i;
   75.38 -            copy_to_user(u_dom0_op, op, sizeof(*op));
   75.39 -            
   75.40 -            put_domain(d);
   75.41 -        }
   75.42 -    }
   75.43 -    break;
   75.44 -
   75.45      case DOM0_GETDOMAININFO:
   75.46      { 
   75.47          full_execution_context_t *c;
   75.48 @@ -383,7 +345,7 @@ long do_dom0_op(dom0_op_t *u_dom0_op)
   75.49  
   75.50          if ( op->u.getdomaininfo.ctxt != NULL )
   75.51          {
   75.52 -            if ( (c = xmalloc(sizeof(*c))) == NULL )
   75.53 +            if ( (c = xmalloc(full_execution_context_t)) == NULL )
   75.54              {
   75.55                  ret = -ENOMEM;
   75.56                  put_domain(d);
    76.1 --- a/xen/common/domain.c	Fri Jan 28 14:53:32 2005 +0000
    76.2 +++ b/xen/common/domain.c	Fri Feb 04 14:44:18 2005 +0000
    76.3 @@ -264,7 +264,7 @@ int final_setup_guestos(struct domain *p
    76.4      int rc = 0;
    76.5      full_execution_context_t *c;
    76.6  
    76.7 -    if ( (c = xmalloc(sizeof(*c))) == NULL )
    76.8 +    if ( (c = xmalloc(full_execution_context_t)) == NULL )
    76.9          return -ENOMEM;
   76.10  
   76.11      if ( test_bit(DF_CONSTRUCTED, &p->d_flags) )
   76.12 @@ -311,7 +311,7 @@ long do_boot_vcpu(unsigned long vcpu, fu
   76.13      if ( alloc_exec_domain_struct(d, vcpu) == NULL )
   76.14          return -ENOMEM;
   76.15  
   76.16 -    if ( (c = xmalloc(sizeof(*c))) == NULL )
   76.17 +    if ( (c = xmalloc(full_execution_context_t)) == NULL )
   76.18      {
   76.19          rc = -ENOMEM;
   76.20          goto out;
    77.1 --- a/xen/common/elf.c	Fri Jan 28 14:53:32 2005 +0000
    77.2 +++ b/xen/common/elf.c	Fri Feb 04 14:44:18 2005 +0000
    77.3 @@ -35,11 +35,8 @@ int parseelfimage(char *elfbase,
    77.4      char *shstrtab, *guestinfo=NULL, *p;
    77.5      int h;
    77.6  
    77.7 -    if ( !IS_ELF(*ehdr) )
    77.8 -    {
    77.9 -        printk("Kernel image does not have an ELF header.\n");
   77.10 +    if ( !elf_sanity_check(ehdr) )
   77.11          return -EINVAL;
   77.12 -    }
   77.13  
   77.14      if ( (ehdr->e_phoff + (ehdr->e_phnum * ehdr->e_phentsize)) > elfsize )
   77.15      {
   77.16 @@ -92,7 +89,7 @@ int parseelfimage(char *elfbase,
   77.17      if ( guestinfo == NULL )
   77.18      {
   77.19          printk("Not a Xen-ELF image: '__xen_guest' section not found.\n");
   77.20 -#ifndef FORCE_XENELF_IMAGE
   77.21 +#if FORCE_XENELF_IMAGE
   77.22          return -EINVAL;
   77.23  #endif
   77.24      }
    78.1 --- a/xen/common/event_channel.c	Fri Jan 28 14:53:32 2005 +0000
    78.2 +++ b/xen/common/event_channel.c	Fri Feb 04 14:44:18 2005 +0000
    78.3 @@ -54,7 +54,7 @@ static int get_free_port(struct exec_dom
    78.4          else
    78.5              max = port + EVENT_CHANNELS_SPREAD;
    78.6          
    78.7 -        chn = xmalloc(max * sizeof(event_channel_t));
    78.8 +        chn = xmalloc_array(event_channel_t, max);
    78.9          if ( unlikely(chn == NULL) )
   78.10              return -ENOMEM;
   78.11  
    79.1 --- a/xen/common/grant_table.c	Fri Jan 28 14:53:32 2005 +0000
    79.2 +++ b/xen/common/grant_table.c	Fri Feb 04 14:44:18 2005 +0000
    79.3 @@ -565,7 +565,7 @@ grant_table_create(
    79.4      grant_table_t *t;
    79.5      int            i;
    79.6  
    79.7 -    if ( (t = xmalloc(sizeof(*t))) == NULL )
    79.8 +    if ( (t = xmalloc(grant_table_t)) == NULL )
    79.9          goto no_mem;
   79.10  
   79.11      /* Simple stuff. */
   79.12 @@ -573,8 +573,8 @@ grant_table_create(
   79.13      spin_lock_init(&t->lock);
   79.14  
   79.15      /* Active grant table. */
   79.16 -    if ( (t->active = xmalloc(sizeof(active_grant_entry_t) * 
   79.17 -                              NR_GRANT_ENTRIES)) == NULL )
   79.18 +    if ( (t->active = xmalloc_array(active_grant_entry_t, NR_GRANT_ENTRIES))
   79.19 +	 == NULL )
   79.20          goto no_mem;
   79.21      memset(t->active, 0, sizeof(active_grant_entry_t) * NR_GRANT_ENTRIES);
   79.22  
    80.1 --- a/xen/common/page_alloc.c	Fri Jan 28 14:53:32 2005 +0000
    80.2 +++ b/xen/common/page_alloc.c	Fri Feb 04 14:44:18 2005 +0000
    80.3 @@ -49,8 +49,9 @@ static unsigned long  bitmap_size; /* in
    80.4  static unsigned long *alloc_bitmap;
    80.5  #define PAGES_PER_MAPWORD (sizeof(unsigned long) * 8)
    80.6  
    80.7 -#define allocated_in_map(_pn) \
    80.8 -(alloc_bitmap[(_pn)/PAGES_PER_MAPWORD] & (1<<((_pn)&(PAGES_PER_MAPWORD-1))))
    80.9 +#define allocated_in_map(_pn)                 \
   80.10 +( !! (alloc_bitmap[(_pn)/PAGES_PER_MAPWORD] & \
   80.11 +     (1UL<<((_pn)&(PAGES_PER_MAPWORD-1)))) )
   80.12  
   80.13  /*
   80.14   * Hint regarding bitwise arithmetic in map_{alloc,free}:
   80.15 @@ -79,13 +80,13 @@ static void map_alloc(unsigned long firs
   80.16  
   80.17      if ( curr_idx == end_idx )
   80.18      {
   80.19 -        alloc_bitmap[curr_idx] |= ((1<<end_off)-1) & -(1<<start_off);
   80.20 +        alloc_bitmap[curr_idx] |= ((1UL<<end_off)-1) & -(1UL<<start_off);
   80.21      }
   80.22      else 
   80.23      {
   80.24 -        alloc_bitmap[curr_idx] |= -(1<<start_off);
   80.25 -        while ( ++curr_idx < end_idx ) alloc_bitmap[curr_idx] = ~0L;
   80.26 -        alloc_bitmap[curr_idx] |= (1<<end_off)-1;
   80.27 +        alloc_bitmap[curr_idx] |= -(1UL<<start_off);
   80.28 +        while ( ++curr_idx < end_idx ) alloc_bitmap[curr_idx] = ~0UL;
   80.29 +        alloc_bitmap[curr_idx] |= (1UL<<end_off)-1;
   80.30      }
   80.31  }
   80.32  
   80.33 @@ -108,13 +109,13 @@ static void map_free(unsigned long first
   80.34  
   80.35      if ( curr_idx == end_idx )
   80.36      {
   80.37 -        alloc_bitmap[curr_idx] &= -(1<<end_off) | ((1<<start_off)-1);
   80.38 +        alloc_bitmap[curr_idx] &= -(1UL<<end_off) | ((1UL<<start_off)-1);
   80.39      }
   80.40      else 
   80.41      {
   80.42 -        alloc_bitmap[curr_idx] &= (1<<start_off)-1;
   80.43 +        alloc_bitmap[curr_idx] &= (1UL<<start_off)-1;
   80.44          while ( ++curr_idx != end_idx ) alloc_bitmap[curr_idx] = 0;
   80.45 -        alloc_bitmap[curr_idx] &= -(1<<end_off);
   80.46 +        alloc_bitmap[curr_idx] &= -(1UL<<end_off);
   80.47      }
   80.48  }
   80.49  
   80.50 @@ -176,7 +177,7 @@ unsigned long alloc_boot_pages(unsigned 
   80.51      size  = round_pgup(size) >> PAGE_SHIFT;
   80.52      align = round_pgup(align) >> PAGE_SHIFT;
   80.53  
   80.54 -    for ( pg = 0; (pg + size) < (bitmap_size*PAGES_PER_MAPWORD); pg += align )
   80.55 +    for ( pg = 0; (pg + size) < (bitmap_size*8); pg += align )
   80.56      {
   80.57          for ( i = 0; i < size; i++ )
   80.58              if ( allocated_in_map(pg + i) )
   80.59 @@ -417,7 +418,7 @@ unsigned long alloc_xenheap_pages(unsign
   80.60      for ( i = 0; i < (1 << order); i++ )
   80.61      {
   80.62          pg[i].count_info        = 0;
   80.63 -        pg[i].u.inuse.domain    = NULL;
   80.64 +        pg[i].u.inuse._domain   = 0;
   80.65          pg[i].u.inuse.type_info = 0;
   80.66      }
   80.67  
   80.68 @@ -483,11 +484,11 @@ struct pfn_info *alloc_domheap_pages(str
   80.69              pfn_stamp = pg[i].tlbflush_timestamp;
   80.70              for ( j = 0; (mask != 0) && (j < smp_num_cpus); j++ )
   80.71              {
   80.72 -                if ( mask & (1<<j) )
   80.73 +                if ( mask & (1UL<<j) )
   80.74                  {
   80.75                      cpu_stamp = tlbflush_time[j];
   80.76                      if ( !NEED_FLUSH(cpu_stamp, pfn_stamp) )
   80.77 -                        mask &= ~(1<<j);
   80.78 +                        mask &= ~(1UL<<j);
   80.79                  }
   80.80              }
   80.81              
   80.82 @@ -500,7 +501,7 @@ struct pfn_info *alloc_domheap_pages(str
   80.83          }
   80.84  
   80.85          pg[i].count_info        = 0;
   80.86 -        pg[i].u.inuse.domain    = NULL;
   80.87 +        pg[i].u.inuse._domain   = 0;
   80.88          pg[i].u.inuse.type_info = 0;
   80.89      }
   80.90  
   80.91 @@ -528,7 +529,7 @@ struct pfn_info *alloc_domheap_pages(str
   80.92  
   80.93      for ( i = 0; i < (1 << order); i++ )
   80.94      {
   80.95 -        pg[i].u.inuse.domain = d;
   80.96 +        page_set_owner(&pg[i], d);
   80.97          wmb(); /* Domain pointer must be visible before updating refcnt. */
   80.98          pg[i].count_info |= PGC_allocated | 1;
   80.99          list_add_tail(&pg[i].list, &d->page_list);
  80.100 @@ -543,7 +544,7 @@ struct pfn_info *alloc_domheap_pages(str
  80.101  void free_domheap_pages(struct pfn_info *pg, unsigned int order)
  80.102  {
  80.103      int            i, drop_dom_ref;
  80.104 -    struct domain *d = pg->u.inuse.domain;
  80.105 +    struct domain *d = page_get_owner(pg);
  80.106      struct exec_domain *ed;
  80.107      void          *p;
  80.108      int cpu_mask = 0;
    81.1 --- a/xen/common/physdev.c	Fri Jan 28 14:53:32 2005 +0000
    81.2 +++ b/xen/common/physdev.c	Fri Feb 04 14:44:18 2005 +0000
    81.3 @@ -98,7 +98,7 @@ static void add_dev_to_task(struct domai
    81.4          return;
    81.5      }
    81.6  
    81.7 -    if ( (pdev = xmalloc(sizeof(phys_dev_t))) == NULL )
    81.8 +    if ( (pdev = xmalloc(phys_dev_t)) == NULL )
    81.9      {
   81.10          INFO("Error allocating pdev structure.\n");
   81.11          return;
   81.12 @@ -174,7 +174,7 @@ int physdev_pci_access_modify(
   81.13  
   81.14      if ( ed->thread.io_bitmap == NULL )
   81.15      {
   81.16 -        if ( (ed->thread.io_bitmap = xmalloc(IOBMP_BYTES)) == NULL )
   81.17 +        if ( (ed->thread.io_bitmap = xmalloc_array(u8, IOBMP_BYTES)) == NULL )
   81.18          {
   81.19              rc = -ENOMEM;
   81.20              goto out;
   81.21 @@ -765,7 +765,7 @@ void physdev_init_dom0(struct domain *p)
   81.22          if ( (dev->hdr_type != PCI_HEADER_TYPE_NORMAL) &&
   81.23               (dev->hdr_type != PCI_HEADER_TYPE_CARDBUS) )
   81.24              continue;
   81.25 -        pdev = xmalloc(sizeof(phys_dev_t));
   81.26 +        pdev = xmalloc(phys_dev_t);
   81.27          pdev->dev = dev;
   81.28          pdev->flags = ACC_WRITE;
   81.29          pdev->state = 0;
    82.1 --- a/xen/common/resource.c	Fri Jan 28 14:53:32 2005 +0000
    82.2 +++ b/xen/common/resource.c	Fri Feb 04 14:44:18 2005 +0000
    82.3 @@ -220,7 +220,7 @@ int allocate_resource(struct resource *r
    82.4   */
    82.5  struct resource * __request_region(struct resource *parent, unsigned long start, unsigned long n, const char *name)
    82.6  {
    82.7 -	struct resource *res = xmalloc(sizeof(*res));
    82.8 +	struct resource *res = xmalloc(struct resource);
    82.9  
   82.10  	if (res) {
   82.11  		memset(res, 0, sizeof(*res));
    83.1 --- a/xen/common/sched_atropos.c	Fri Jan 28 14:53:32 2005 +0000
    83.2 +++ b/xen/common/sched_atropos.c	Fri Feb 04 14:44:18 2005 +0000
    83.3 @@ -69,8 +69,6 @@ struct at_cpu_info
    83.4  
    83.5  static void at_dump_cpu_state(int cpu);
    83.6  
    83.7 -static xmem_cache_t *dom_info_cache;
    83.8 -
    83.9  static inline void __add_to_runqueue_head(struct domain *d)
   83.10  {
   83.11      list_add(RUNLIST(d), RUNQ(d->processor));
   83.12 @@ -173,7 +171,7 @@ static int at_alloc_task(struct domain *
   83.13  {
   83.14      ASSERT(p != NULL);
   83.15      
   83.16 -    p->sched_priv = xmem_cache_alloc(dom_info_cache);
   83.17 +    p->sched_priv = xmalloc(struct at_dom_info);
   83.18      if ( p->sched_priv == NULL )
   83.19          return -1;
   83.20      
   83.21 @@ -558,10 +556,6 @@ static int at_init_scheduler()
   83.22          INIT_LIST_HEAD(RUNQ(i));
   83.23      }
   83.24  
   83.25 -    dom_info_cache = xmem_cache_create("Atropos dom info",
   83.26 -                                       sizeof(struct at_dom_info),
   83.27 -                                       0, 0, NULL, NULL);
   83.28 -
   83.29      return 0;
   83.30  }
   83.31  
   83.32 @@ -649,7 +643,7 @@ static int at_adjdom(struct domain *p, s
   83.33  /* free memory associated with a task */
   83.34  static void at_free_task(struct domain *p)
   83.35  {
   83.36 -    xmem_cache_free( dom_info_cache, DOM_INFO(p) );
   83.37 +    xfree( DOM_INFO(p) );
   83.38  }
   83.39  
   83.40  
    84.1 --- a/xen/common/sched_bvt.c	Fri Jan 28 14:53:32 2005 +0000
    84.2 +++ b/xen/common/sched_bvt.c	Fri Feb 04 14:44:18 2005 +0000
    84.3 @@ -71,8 +71,6 @@ struct bvt_cpu_info
    84.4  #define TIME_SLOP      (s32)MICROSECS(50)     /* allow time to slip a bit */
    84.5  static s32 ctx_allow = (s32)MILLISECS(5);     /* context switch allowance */
    84.6  
    84.7 -static xmem_cache_t *dom_info_cache;
    84.8 -
    84.9  static inline void __add_to_runqueue_head(struct exec_domain *d)
   84.10  {
   84.11      list_add(RUNLIST(d), RUNQUEUE(d->processor));
   84.12 @@ -173,7 +171,7 @@ int bvt_alloc_task(struct exec_domain *e
   84.13  {
   84.14      struct domain *d = ed->domain;
   84.15      if ( (d->sched_priv == NULL) ) {
   84.16 -        if ( (d->sched_priv = xmem_cache_alloc(dom_info_cache)) == NULL )
   84.17 +        if ( (d->sched_priv = xmalloc(struct bvt_dom_info)) == NULL )
   84.18              return -1;
   84.19          memset(d->sched_priv, 0, sizeof(struct bvt_dom_info));
   84.20      }
   84.21 @@ -295,7 +293,7 @@ static void bvt_sleep(struct exec_domain
   84.22  void bvt_free_task(struct domain *d)
   84.23  {
   84.24      ASSERT(d->sched_priv != NULL);
   84.25 -    xmem_cache_free(dom_info_cache, d->sched_priv);
   84.26 +    xfree(d->sched_priv);
   84.27  }
   84.28  
   84.29  /* Control the scheduler. */
   84.30 @@ -557,7 +555,7 @@ int bvt_init_scheduler()
   84.31  
   84.32      for ( i = 0; i < NR_CPUS; i++ )
   84.33      {
   84.34 -        schedule_data[i].sched_priv = xmalloc(sizeof(struct bvt_cpu_info));
   84.35 +        schedule_data[i].sched_priv = xmalloc(struct bvt_cpu_info);
   84.36         
   84.37          if ( schedule_data[i].sched_priv == NULL )
   84.38          {
   84.39 @@ -570,14 +568,6 @@ int bvt_init_scheduler()
   84.40          CPU_SVT(i) = 0; /* XXX do I really need to do this? */
   84.41      }
   84.42  
   84.43 -    dom_info_cache = xmem_cache_create(
   84.44 -        "BVT dom info", sizeof(struct bvt_dom_info), 0, 0, NULL, NULL);
   84.45 -    if ( dom_info_cache == NULL )
   84.46 -    {
   84.47 -        printk("BVT: Failed to allocate domain info SLAB cache");
   84.48 -        return -1;
   84.49 -    }
   84.50 -
   84.51      return 0;
   84.52  }
   84.53  
    85.1 --- a/xen/common/sched_rrobin.c	Fri Jan 28 14:53:32 2005 +0000
    85.2 +++ b/xen/common/sched_rrobin.c	Fri Feb 04 14:44:18 2005 +0000
    85.3 @@ -27,8 +27,6 @@ struct rrobin_dom_info
    85.4  #define RUNLIST(d)      ((struct list_head *)&(RR_INFO(d)->run_list))
    85.5  #define RUNQUEUE(cpu)   RUNLIST(schedule_data[cpu].idle)
    85.6  
    85.7 -static xmem_cache_t *dom_info_cache;
    85.8 -
    85.9  static inline void __add_to_runqueue_head(struct domain *d)
   85.10  {
   85.11      list_add(RUNLIST(d), RUNQUEUE(d->processor));
   85.12 @@ -59,21 +57,12 @@ static int rr_init_scheduler()
   85.13      for ( i = 0; i < NR_CPUS; i++ )
   85.14          INIT_LIST_HEAD(RUNQUEUE(i));
   85.15     
   85.16 -    dom_info_cache = xmem_cache_create(
   85.17 -        "RR dom info", sizeof(struct rrobin_dom_info), 0, 0, 0, NULL);
   85.18 -    if ( dom_info_cache == NULL )
   85.19 -    {
   85.20 -        printk("Could not allocate SLAB cache.\n");
   85.21 -        return -1;
   85.22 -    }
   85.23 -
   85.24      return 0;                                                                
   85.25  }
   85.26 -
   85.27  /* Allocates memory for per domain private scheduling data*/
   85.28  static int rr_alloc_task(struct domain *d)
   85.29  {
   85.30 -    if ( (d->sched_priv = xmem_cache_alloc(dom_info_cache)) == NULL )
   85.31 +    if ( (d->sched_priv = new(struct rrobin_dom_info) == NULL )
   85.32          return -1;
   85.33      memset(d->sched_priv, 0, sizeof(struct rrobin_dom_info));
   85.34      return 0;
   85.35 @@ -91,7 +80,7 @@ static void rr_add_task(struct domain *d
   85.36  static void rr_free_task(struct domain *d)
   85.37  {
   85.38      ASSERT(d->sched_priv != NULL);
   85.39 -    xmem_cache_free(dom_info_cache, d->sched_priv);
   85.40 +    xfree(d->sched_priv);
   85.41  }
   85.42  
   85.43  /* Initialises idle task */
    86.1 --- a/xen/common/slab.c	Fri Jan 28 14:53:32 2005 +0000
    86.2 +++ b/xen/common/slab.c	Fri Feb 04 14:44:18 2005 +0000
    86.3 @@ -1449,10 +1449,10 @@ void *xmem_cache_alloc(xmem_cache_t *cac
    86.4  }
    86.5  
    86.6  /**
    86.7 - * xmalloc - allocate memory
    86.8 + * _xmalloc - allocate memory
    86.9   * @size: how many bytes of memory are required.
   86.10   */
   86.11 -void *xmalloc(size_t size)
   86.12 +void *_xmalloc(size_t size)
   86.13  {
   86.14      cache_sizes_t *csizep = cache_sizes;
   86.15  
   86.16 @@ -1548,7 +1548,7 @@ static int xmem_tune_cpucache (xmem_cach
   86.17          for (i = 0; i< smp_num_cpus; i++) {
   86.18              cpucache_t* ccnew;
   86.19  
   86.20 -            ccnew = xmalloc(sizeof(void*)*limit+sizeof(cpucache_t));
   86.21 +            ccnew = _xmalloc(sizeof(void*)*limit+sizeof(cpucache_t));
   86.22              if (!ccnew)
   86.23                  goto oom;
   86.24              ccnew->limit = limit;
    87.1 --- a/xen/drivers/char/console.c	Fri Jan 28 14:53:32 2005 +0000
    87.2 +++ b/xen/drivers/char/console.c	Fri Feb 04 14:44:18 2005 +0000
    87.3 @@ -21,7 +21,7 @@
    87.4  #include <asm/mm.h>
    87.5  
    87.6  /* opt_console: comma-separated list of console outputs. */
    87.7 -static unsigned char opt_console[30] = "com1,vga";
    87.8 +static unsigned char opt_console[30] = OPT_CONSOLE_STR;
    87.9  string_param("console", opt_console);
   87.10  
   87.11  /* opt_conswitch: a character pair controlling console switching. */
   87.12 @@ -506,6 +506,7 @@ void panic(const char *fmt, ...)
   87.13      __putstr("Reboot in five seconds...\n");
   87.14      spin_unlock_irqrestore(&console_lock, flags);
   87.15  
   87.16 +    watchdog_on = 0;
   87.17      mdelay(5000);
   87.18      machine_restart(0);
   87.19  }
    88.1 --- a/xen/drivers/char/serial.c	Fri Jan 28 14:53:32 2005 +0000
    88.2 +++ b/xen/drivers/char/serial.c	Fri Feb 04 14:44:18 2005 +0000
    88.3 @@ -331,11 +331,13 @@ int parse_serial_handle(char *conf)
    88.4          goto fail;
    88.5      }
    88.6  
    88.7 +#ifndef NO_UART_CONFIG_OK
    88.8      if ( !UART_ENABLED(&com[handle]) )
    88.9      {
   88.10          printk("ERROR: cannot use unconfigured serial port COM%d\n", handle+1);
   88.11          return -1;
   88.12      }
   88.13 +#endif
   88.14  
   88.15      if ( conf[4] == 'H' )
   88.16          handle |= SERHND_HI;
    89.1 --- a/xen/drivers/pci/pci.c	Fri Jan 28 14:53:32 2005 +0000
    89.2 +++ b/xen/drivers/pci/pci.c	Fri Feb 04 14:44:18 2005 +0000
    89.3 @@ -1126,7 +1126,7 @@ static struct pci_bus * __devinit pci_al
    89.4  {
    89.5  	struct pci_bus *b;
    89.6  
    89.7 -	b = xmalloc(sizeof(*b));
    89.8 +	b = xmalloc(struct pci_bus);
    89.9  	if (b) {
   89.10  		memset(b, 0, sizeof(*b));
   89.11  		INIT_LIST_HEAD(&b->children);
   89.12 @@ -1351,7 +1351,7 @@ struct pci_dev * __devinit pci_scan_devi
   89.13  	if (l == 0xffffffff || l == 0x00000000 || l == 0x0000ffff || l == 0xffff0000)
   89.14  		return NULL;
   89.15  
   89.16 -	dev = xmalloc(sizeof(*dev));
   89.17 +	dev = xmalloc(struct pci_dev);
   89.18  	if (!dev)
   89.19  		return NULL;
   89.20  
   89.21 @@ -1431,7 +1431,7 @@ unsigned int __devinit pci_do_scan_bus(s
   89.22  	max = bus->secondary;
   89.23  
   89.24  	/* Create a device template */
   89.25 -	dev0 = xmalloc(sizeof(struct pci_dev));
   89.26 +	dev0 = xmalloc(struct pci_dev);
   89.27  	if(!dev0) {
   89.28  	  panic("Out of memory scanning PCI bus!\n");
   89.29  	}
    90.1 --- a/xen/drivers/pci/setup-res.c	Fri Jan 28 14:53:32 2005 +0000
    90.2 +++ b/xen/drivers/pci/setup-res.c	Fri Feb 04 14:44:18 2005 +0000
    90.3 @@ -171,10 +171,10 @@ pdev_sort_resources(struct pci_dev *dev,
    90.4  					ln->res->start;
    90.5  			}
    90.6  			if (r_align > align) {
    90.7 -				tmp = xmalloc(sizeof(*tmp));
    90.8 +				tmp = xmalloc(struct resource_list);
    90.9  				if (!tmp)
   90.10  					panic("pdev_sort_resources(): "
   90.11 -					      "xmalloc() failed!\n");
   90.12 +					      "malloc() failed!\n");
   90.13  				tmp->next = ln;
   90.14  				tmp->res = r;
   90.15  				tmp->dev = dev;
    91.1 --- a/xen/include/asm-x86/apicdef.h	Fri Jan 28 14:53:32 2005 +0000
    91.2 +++ b/xen/include/asm-x86/apicdef.h	Fri Feb 04 14:44:18 2005 +0000
    91.3 @@ -125,255 +125,4 @@
    91.4  #define APIC_BROADCAST_ID_XAPIC (0xFF)
    91.5  #define APIC_BROADCAST_ID_APIC  (0x0F)
    91.6  
    91.7 -/*
    91.8 - * the local APIC register structure, memory mapped. Not terribly well
    91.9 - * tested, but we might eventually use this one in the future - the
   91.10 - * problem why we cannot use it right now is the P5 APIC, it has an
   91.11 - * errata which cannot take 8-bit reads and writes, only 32-bit ones ...
   91.12 - */
   91.13 -#define u32 unsigned int
   91.14 -
   91.15 -#define lapic ((volatile struct local_apic *)APIC_BASE)
   91.16 -
   91.17 -struct local_apic {
   91.18 -
   91.19 -/*000*/	struct { u32 __reserved[4]; } __reserved_01;
   91.20 -
   91.21 -/*010*/	struct { u32 __reserved[4]; } __reserved_02;
   91.22 -
   91.23 -/*020*/	struct { /* APIC ID Register */
   91.24 -		u32   __reserved_1	: 24,
   91.25 -			phys_apic_id	:  4,
   91.26 -			__reserved_2	:  4;
   91.27 -		u32 __reserved[3];
   91.28 -	} id;
   91.29 -
   91.30 -/*030*/	const
   91.31 -	struct { /* APIC Version Register */
   91.32 -		u32   version		:  8,
   91.33 -			__reserved_1	:  8,
   91.34 -			max_lvt		:  8,
   91.35 -			__reserved_2	:  8;
   91.36 -		u32 __reserved[3];
   91.37 -	} version;
   91.38 -
   91.39 -/*040*/	struct { u32 __reserved[4]; } __reserved_03;
   91.40 -
   91.41 -/*050*/	struct { u32 __reserved[4]; } __reserved_04;
   91.42 -
   91.43 -/*060*/	struct { u32 __reserved[4]; } __reserved_05;
   91.44 -
   91.45 -/*070*/	struct { u32 __reserved[4]; } __reserved_06;
   91.46 -
   91.47 -/*080*/	struct { /* Task Priority Register */
   91.48 -		u32   priority	:  8,
   91.49 -			__reserved_1	: 24;
   91.50 -		u32 __reserved_2[3];
   91.51 -	} tpr;
   91.52 -
   91.53 -/*090*/	const
   91.54 -	struct { /* Arbitration Priority Register */
   91.55 -		u32   priority	:  8,
   91.56 -			__reserved_1	: 24;
   91.57 -		u32 __reserved_2[3];
   91.58 -	} apr;
   91.59 -
   91.60 -/*0A0*/	const
   91.61 -	struct { /* Processor Priority Register */
   91.62 -		u32   priority	:  8,
   91.63 -			__reserved_1	: 24;
   91.64 -		u32 __reserved_2[3];
   91.65 -	} ppr;
   91.66 -
   91.67 -/*0B0*/	struct { /* End Of Interrupt Register */
   91.68 -		u32   eoi;
   91.69 -		u32 __reserved[3];
   91.70 -	} eoi;
   91.71 -
   91.72 -/*0C0*/	struct { u32 __reserved[4]; } __reserved_07;
   91.73 -
   91.74 -/*0D0*/	struct { /* Logical Destination Register */
   91.75 -		u32   __reserved_1	: 24,
   91.76 -			logical_dest	:  8;
   91.77 -		u32 __reserved_2[3];
   91.78 -	} ldr;
   91.79 -
   91.80 -/*0E0*/	struct { /* Destination Format Register */
   91.81 -		u32   __reserved_1	: 28,
   91.82 -			model		:  4;
   91.83 -		u32 __reserved_2[3];
   91.84 -	} dfr;
   91.85 -
   91.86 -/*0F0*/	struct { /* Spurious Interrupt Vector Register */
   91.87 -		u32	spurious_vector	:  8,
   91.88 -			apic_enabled	:  1,
   91.89 -			focus_cpu	:  1,
   91.90 -			__reserved_2	: 22;
   91.91 -		u32 __reserved_3[3];
   91.92 -	} svr;
   91.93 -
   91.94 -/*100*/	struct { /* In Service Register */
   91.95 -/*170*/		u32 bitfield;
   91.96 -		u32 __reserved[3];
   91.97 -	} isr [8];
   91.98 -
   91.99 -/*180*/	struct { /* Trigger Mode Register */
  91.100 -/*1F0*/		u32 bitfield;
  91.101 -		u32 __reserved[3];
  91.102 -	} tmr [8];
  91.103 -
  91.104 -/*200*/	struct { /* Interrupt Request Register */
  91.105 -/*270*/		u32 bitfield;
  91.106 -		u32 __reserved[3];
  91.107 -	} irr [8];
  91.108 -
  91.109 -/*280*/	union { /* Error Status Register */
  91.110 -		struct {
  91.111 -			u32   send_cs_error			:  1,
  91.112 -				receive_cs_error		:  1,
  91.113 -				send_accept_error		:  1,
  91.114 -				receive_accept_error		:  1,
  91.115 -				__reserved_1			:  1,
  91.116 -				send_illegal_vector		:  1,
  91.117 -				receive_illegal_vector		:  1,
  91.118 -				illegal_register_address	:  1,
  91.119 -				__reserved_2			: 24;
  91.120 -			u32 __reserved_3[3];
  91.121 -		} error_bits;
  91.122 -		struct {
  91.123 -			u32 errors;
  91.124 -			u32 __reserved_3[3];
  91.125 -		} all_errors;
  91.126 -	} esr;
  91.127 -
  91.128 -/*290*/	struct { u32 __reserved[4]; } __reserved_08;
  91.129 -
  91.130 -/*2A0*/	struct { u32 __reserved[4]; } __reserved_09;
  91.131 -
  91.132 -/*2B0*/	struct { u32 __reserved[4]; } __reserved_10;
  91.133 -
  91.134 -/*2C0*/	struct { u32 __reserved[4]; } __reserved_11;
  91.135 -
  91.136 -/*2D0*/	struct { u32 __reserved[4]; } __reserved_12;
  91.137 -
  91.138 -/*2E0*/	struct { u32 __reserved[4]; } __reserved_13;
  91.139 -
  91.140 -/*2F0*/	struct { u32 __reserved[4]; } __reserved_14;
  91.141 -
  91.142 -/*300*/	struct { /* Interrupt Command Register 1 */
  91.143 -		u32   vector			:  8,
  91.144 -			delivery_mode		:  3,
  91.145 -			destination_mode	:  1,
  91.146 -			delivery_status		:  1,
  91.147 -			__reserved_1		:  1,
  91.148 -			level			:  1,
  91.149 -			trigger			:  1,
  91.150 -			__reserved_2		:  2,
  91.151 -			shorthand		:  2,
  91.152 -			__reserved_3		:  12;
  91.153 -		u32 __reserved_4[3];
  91.154 -	} icr1;
  91.155 -
  91.156 -/*310*/	struct { /* Interrupt Command Register 2 */
  91.157 -		union {
  91.158 -			u32   __reserved_1	: 24,
  91.159 -				phys_dest	:  4,
  91.160 -				__reserved_2	:  4;
  91.161 -			u32   __reserved_3	: 24,
  91.162 -				logical_dest	:  8;
  91.163 -		} dest;
  91.164 -		u32 __reserved_4[3];
  91.165 -	} icr2;
  91.166 -
  91.167 -/*320*/	struct { /* LVT - Timer */
  91.168 -		u32   vector		:  8,
  91.169 -			__reserved_1	:  4,
  91.170 -			delivery_status	:  1,
  91.171 -			__reserved_2	:  3,
  91.172 -			mask		:  1,
  91.173 -			timer_mode	:  1,
  91.174 -			__reserved_3	: 14;
  91.175 -		u32 __reserved_4[3];
  91.176 -	} lvt_timer;
  91.177 -
  91.178 -/*330*/	struct { u32 __reserved[4]; } __reserved_15;
  91.179 -
  91.180 -/*340*/	struct { /* LVT - Performance Counter */
  91.181 -		u32   vector		:  8,
  91.182 -			delivery_mode	:  3,
  91.183 -			__reserved_1	:  1,
  91.184 -			delivery_status	:  1,
  91.185 -			__reserved_2	:  3,
  91.186 -			mask		:  1,
  91.187 -			__reserved_3	: 15;
  91.188 -		u32 __reserved_4[3];
  91.189 -	} lvt_pc;
  91.190 -
  91.191 -/*350*/	struct { /* LVT - LINT0 */
  91.192 -		u32   vector		:  8,
  91.193 -			delivery_mode	:  3,
  91.194 -			__reserved_1	:  1,
  91.195 -			delivery_status	:  1,
  91.196 -			polarity	:  1,
  91.197 -			remote_irr	:  1,
  91.198 -			trigger		:  1,
  91.199 -			mask		:  1,
  91.200 -			__reserved_2	: 15;
  91.201 -		u32 __reserved_3[3];
  91.202 -	} lvt_lint0;
  91.203 -
  91.204 -/*360*/	struct { /* LVT - LINT1 */
  91.205 -		u32   vector		:  8,
  91.206 -			delivery_mode	:  3,
  91.207 -			__reserved_1	:  1,
  91.208 -			delivery_status	:  1,
  91.209 -			polarity	:  1,
  91.210 -			remote_irr	:  1,
  91.211 -			trigger		:  1,
  91.212 -			mask		:  1,
  91.213 -			__reserved_2	: 15;
  91.214 -		u32 __reserved_3[3];
  91.215 -	} lvt_lint1;
  91.216 -
  91.217 -/*370*/	struct { /* LVT - Error */
  91.218 -		u32   vector		:  8,
  91.219 -			__reserved_1	:  4,
  91.220 -			delivery_status	:  1,
  91.221 -			__reserved_2	:  3,
  91.222 -			mask		:  1,
  91.223 -			__reserved_3	: 15;
  91.224 -		u32 __reserved_4[3];
  91.225 -	} lvt_error;
  91.226 -
  91.227 -/*380*/	struct { /* Timer Initial Count Register */
  91.228 -		u32   initial_count;
  91.229 -		u32 __reserved_2[3];
  91.230 -	} timer_icr;
  91.231 -
  91.232 -/*390*/	const
  91.233 -	struct { /* Timer Current Count Register */
  91.234 -		u32   curr_count;
  91.235 -		u32 __reserved_2[3];
  91.236 -	} timer_ccr;
  91.237 -
  91.238 -/*3A0*/	struct { u32 __reserved[4]; } __reserved_16;
  91.239 -
  91.240 -/*3B0*/	struct { u32 __reserved[4]; } __reserved_17;
  91.241 -
  91.242 -/*3C0*/	struct { u32 __reserved[4]; } __reserved_18;
  91.243 -
  91.244 -/*3D0*/	struct { u32 __reserved[4]; } __reserved_19;
  91.245 -
  91.246 -/*3E0*/	struct { /* Timer Divide Configuration Register */
  91.247 -		u32   divisor		:  4,
  91.248 -			__reserved_1	: 28;
  91.249 -		u32 __reserved_2[3];
  91.250 -	} timer_dcr;
  91.251 -
  91.252 -/*3F0*/	struct { u32 __reserved[4]; } __reserved_20;
  91.253 -
  91.254 -} __attribute__ ((packed));
  91.255 -
  91.256 -#undef u32
  91.257 -
  91.258  #endif
    92.1 --- a/xen/include/asm-x86/config.h	Fri Jan 28 14:53:32 2005 +0000
    92.2 +++ b/xen/include/asm-x86/config.h	Fri Feb 04 14:44:18 2005 +0000
    92.3 @@ -52,6 +52,8 @@
    92.4  
    92.5  #define HZ 100
    92.6  
    92.7 +#define OPT_CONSOLE_STR "com1,vga"
    92.8 +
    92.9  /*
   92.10   * Just to keep compiler happy.
   92.11   * NB. DO NOT CHANGE SMP_CACHE_BYTES WITHOUT FIXING arch/i386/entry.S!!!
   92.12 @@ -61,7 +63,6 @@
   92.13  #define NR_CPUS 16
   92.14  
   92.15  /* Linkage for x86 */
   92.16 -#define asmlinkage        __attribute__((regparm(0)))
   92.17  #define __ALIGN .align 16,0x90
   92.18  #define __ALIGN_STR ".align 16,0x90"
   92.19  #define SYMBOL_NAME_STR(X) #X
   92.20 @@ -97,10 +98,15 @@ extern void __out_of_line_bug(int line) 
   92.21  
   92.22  #if defined(__x86_64__)
   92.23  
   92.24 +#define asmlinkage
   92.25 +
   92.26  #define XENHEAP_DEFAULT_MB (16)
   92.27  
   92.28  #define PML4_ENTRY_BITS  39
   92.29 -#define PML4_ENTRY_BYTES (1UL<<PML4_ENTRY_BITS)
   92.30 +#define PML4_ENTRY_BYTES (1UL << PML4_ENTRY_BITS)
   92.31 +#define PML4_ADDR(_slot)                             \
   92.32 +    ((((_slot ## UL) >> 8) * 0xffff000000000000UL) | \
   92.33 +     (_slot ## UL << PML4_ENTRY_BITS))
   92.34  
   92.35  /*
   92.36   * Memory layout:
   92.37 @@ -120,7 +126,13 @@ extern void __out_of_line_bug(int line) 
   92.38   *    Shadow linear page table.
   92.39   *  0xffff820000000000 - 0xffff827fffffffff [512GB, 2^39 bytes, PML4:260]
   92.40   *    Per-domain mappings (e.g., GDT, LDT).
   92.41 - *  0xffff828000000000 - 0xffff8287ffffffff [512GB, 2^39 bytes, PML4:261]
   92.42 + *  0xffff828000000000 - 0xffff8283ffffffff [16GB,  2^34 bytes, PML4:261]
   92.43 + *    Machine-to-phys translation table.
   92.44 + *  0xffff828400000000 - 0xffff8287ffffffff [16GB,  2^34 bytes, PML4:261]
   92.45 + *    Page-frame information array.
   92.46 + *  0xffff828800000000 - 0xffff828bffffffff [16GB,  2^34 bytes, PML4:261]
   92.47 + *    ioremap()/fixmap area.
   92.48 + *  0xffff828c00000000 - 0xffff82ffffffffff [464GB,             PML4:261]
   92.49   *    Reserved for future use.
   92.50   *  0xffff830000000000 - 0xffff83ffffffffff [1TB,   2^40 bytes, PML4:262-263]
   92.51   *    1:1 direct mapping of all physical memory. Xen and its heap live here.
   92.52 @@ -130,33 +142,46 @@ extern void __out_of_line_bug(int line) 
   92.53   *    Guest-defined use.
   92.54   */
   92.55  
   92.56 +
   92.57  /* Hypervisor reserves PML4 slots 256 to 271 inclusive. */
   92.58 -#define HYPERVISOR_VIRT_START   (0xFFFF800000000000UL)
   92.59 -#define HYPERVISOR_VIRT_END     (0xFFFF880000000000UL)
   92.60 +#define HYPERVISOR_VIRT_START   (PML4_ADDR(256))
   92.61 +#define HYPERVISOR_VIRT_END     (HYPERVISOR_VIRT_START + PML4_ENTRY_BYTES*16)
   92.62  /* Slot 256: read-only guest-accessible machine-to-phys translation table. */
   92.63 -#define RO_MPT_VIRT_START       (HYPERVISOR_VIRT_START)
   92.64 +#define RO_MPT_VIRT_START       (PML4_ADDR(256))
   92.65  #define RO_MPT_VIRT_END         (RO_MPT_VIRT_START + PML4_ENTRY_BYTES/2)
   92.66  /* Slot 257: read-only guest-accessible linear page table. */
   92.67 -#define RO_LINEAR_PT_VIRT_START (RO_MPT_VIRT_END + PML4_ENTRY_BYTES/2)
   92.68 +#define RO_LINEAR_PT_VIRT_START (PML4_ADDR(257))
   92.69  #define RO_LINEAR_PT_VIRT_END   (RO_LINEAR_PT_VIRT_START + PML4_ENTRY_BYTES)
   92.70  /* Slot 258: linear page table (guest table). */
   92.71 -#define LINEAR_PT_VIRT_START    (RO_LINEAR_PT_VIRT_END)
   92.72 +#define LINEAR_PT_VIRT_START    (PML4_ADDR(258))
   92.73  #define LINEAR_PT_VIRT_END      (LINEAR_PT_VIRT_START + PML4_ENTRY_BYTES)
   92.74  /* Slot 259: linear page table (shadow table). */
   92.75 -#define SH_LINEAR_PT_VIRT_START (LINEAR_PT_VIRT_END)
   92.76 +#define SH_LINEAR_PT_VIRT_START (PML4_ADDR(259))
   92.77  #define SH_LINEAR_PT_VIRT_END   (SH_LINEAR_PT_VIRT_START + PML4_ENTRY_BYTES)
   92.78  /* Slot 260: per-domain mappings. */
   92.79 -#define PERDOMAIN_VIRT_START    (SH_LINEAR_PT_VIRT_END)
   92.80 +#define PERDOMAIN_VIRT_START    (PML4_ADDR(260))
   92.81  #define PERDOMAIN_VIRT_END      (PERDOMAIN_VIRT_START + PML4_ENTRY_BYTES)
   92.82 +/* Slot 261: machine-to-phys conversion table (16GB). */
   92.83 +#define RDWR_MPT_VIRT_START     (PML4_ADDR(261))
   92.84 +#define RDWR_MPT_VIRT_END       (RDWR_MPT_VIRT_START + (16UL<<30))
   92.85 +/* Slot 261: page-frame information array (16GB). */
   92.86 +#define FRAMETABLE_VIRT_START   (RDWR_MPT_VIRT_END)
   92.87 +#define FRAMETABLE_VIRT_END     (FRAMETABLE_VIRT_START + (16UL<<30))
   92.88 +/* Slot 261: ioremap()/fixmap area (16GB). */
   92.89 +#define IOREMAP_VIRT_START      (FRAMETABLE_VIRT_END)
   92.90 +#define IOREMAP_VIRT_END        (IOREMAP_VIRT_START + (16UL<<30))
   92.91  /* Slot 262-263: A direct 1:1 mapping of all of physical memory. */
   92.92 -#define DIRECTMAP_VIRT_START    (PERDOMAIN_VIRT_END + PML4_ENTRY_BYTES)
   92.93 +#define DIRECTMAP_VIRT_START    (PML4_ADDR(262))
   92.94  #define DIRECTMAP_VIRT_END      (DIRECTMAP_VIRT_START + PML4_ENTRY_BYTES*2)
   92.95  
   92.96  #define PGT_base_page_table PGT_l4_page_table
   92.97  
   92.98  #define __HYPERVISOR_CS64 0x0810
   92.99  #define __HYPERVISOR_CS32 0x0808
  92.100 -#define __HYPERVISOR_DS 0x0818
  92.101 +#define __HYPERVISOR_CS   __HYPERVISOR_CS64
  92.102 +#define __HYPERVISOR_DS64 0x0000
  92.103 +#define __HYPERVISOR_DS32 0x0818
  92.104 +#define __HYPERVISOR_DS   __HYPERVISOR_DS64
  92.105  
  92.106  /* For generic assembly code: use macros to define operation/operand sizes. */
  92.107  #define __OS "q"  /* Operation Suffix */
  92.108 @@ -164,6 +189,8 @@ extern void __out_of_line_bug(int line) 
  92.109  
  92.110  #elif defined(__i386__)
  92.111  
  92.112 +#define asmlinkage __attribute__((regparm(0)))
  92.113 +
  92.114  #define XENHEAP_DEFAULT_MB (12)
  92.115  #define DIRECTMAP_PHYS_END (12*1024*1024)
  92.116  
  92.117 @@ -180,10 +207,8 @@ extern void __out_of_line_bug(int line) 
  92.118  /* Xen heap extends to end of 1:1 direct-mapped memory region. */
  92.119  #define DIRECTMAP_VIRT_START  (RO_MPT_VIRT_END)
  92.120  #define DIRECTMAP_VIRT_END    (DIRECTMAP_VIRT_START + DIRECTMAP_PHYS_END)
  92.121 -#define XENHEAP_VIRT_START    (DIRECTMAP_VIRT_START)
  92.122 -#define XENHEAP_VIRT_END      (DIRECTMAP_VIRT_END)
  92.123  /* Machine-to-phys conversion table. */
  92.124 -#define RDWR_MPT_VIRT_START   (XENHEAP_VIRT_END)
  92.125 +#define RDWR_MPT_VIRT_START   (DIRECTMAP_VIRT_END)
  92.126  #define RDWR_MPT_VIRT_END     (RDWR_MPT_VIRT_START + (4*1024*1024))
  92.127  /* Variable-length page-frame information array. */
  92.128  #define FRAMETABLE_VIRT_START (RDWR_MPT_VIRT_END)
    93.1 --- a/xen/include/asm-x86/desc.h	Fri Jan 28 14:53:32 2005 +0000
    93.2 +++ b/xen/include/asm-x86/desc.h	Fri Feb 04 14:44:18 2005 +0000
    93.3 @@ -1,16 +1,9 @@
    93.4  #ifndef __ARCH_DESC_H
    93.5  #define __ARCH_DESC_H
    93.6 +#ifndef __ASSEMBLY__
    93.7  
    93.8  #define LDT_ENTRY_SIZE 8
    93.9  
   93.10 -#define __DOUBLEFAULT_TSS_ENTRY FIRST_RESERVED_GDT_ENTRY
   93.11 -
   93.12 -#define __FIRST_TSS_ENTRY (FIRST_RESERVED_GDT_ENTRY + 8)
   93.13 -#define __FIRST_LDT_ENTRY (__FIRST_TSS_ENTRY + 1)
   93.14 -
   93.15 -#define __TSS(n) (((n)<<1) + __FIRST_TSS_ENTRY)
   93.16 -#define __LDT(n) (((n)<<1) + __FIRST_LDT_ENTRY)
   93.17 -
   93.18  #define load_TR(n)  __asm__ __volatile__ ("ltr  %%ax" : : "a" (__TSS(n)<<3) )
   93.19  
   93.20  /*
   93.21 @@ -25,7 +18,7 @@
   93.22        (((_s)>>3) >  LAST_RESERVED_GDT_ENTRY) ||                            \
   93.23        ((_s)&4)) &&                                                         \
   93.24       (((_s)&3) == 1))
   93.25 -#define VALID_CODESEL(_s) ((_s) == FLAT_RING1_CS || VALID_SEL(_s))
   93.26 +#define VALID_CODESEL(_s) ((_s) == FLAT_GUESTOS_CS || VALID_SEL(_s))
   93.27  
   93.28  /* These are bitmasks for the high 32 bits of a descriptor table entry. */
   93.29  #define _SEGMENT_TYPE    (15<< 8)
   93.30 @@ -38,25 +31,101 @@
   93.31  #define _SEGMENT_DB      ( 1<<22) /* 16- or 32-bit segment */
   93.32  #define _SEGMENT_G       ( 1<<23) /* Granularity */
   93.33  
   93.34 -#ifndef __ASSEMBLY__
   93.35  struct desc_struct {
   93.36 -	unsigned long a,b;
   93.37 +    u32 a, b;
   93.38  };
   93.39  
   93.40 +#if defined(__x86_64__)
   93.41 +
   93.42 +#define __FIRST_TSS_ENTRY (FIRST_RESERVED_GDT_ENTRY + 8)
   93.43 +#define __FIRST_LDT_ENTRY (__FIRST_TSS_ENTRY + 2)
   93.44 +
   93.45 +#define __TSS(n) (((n)<<2) + __FIRST_TSS_ENTRY)
   93.46 +#define __LDT(n) (((n)<<2) + __FIRST_LDT_ENTRY)
   93.47 +
   93.48 +typedef struct {
   93.49 +    u64 a, b;
   93.50 +} idt_entry_t;
   93.51 +
   93.52 +#define _set_gate(gate_addr,type,dpl,addr)               \
   93.53 +do {                                                     \
   93.54 +    (gate_addr)->a =                                     \
   93.55 +        (((unsigned long)(addr) & 0xFFFF0000UL) << 32) | \
   93.56 +        ((unsigned long)(dpl) << 45) |                   \
   93.57 +        ((unsigned long)(type) << 40) |                  \
   93.58 +        ((unsigned long)(addr) & 0xFFFFUL) |             \
   93.59 +        ((unsigned long)__HYPERVISOR_CS64 << 16) |       \
   93.60 +        (1UL << 47);                                     \
   93.61 +    (gate_addr)->b =                                     \
   93.62 +        ((unsigned long)(addr) >> 32);                   \
   93.63 +} while (0)
   93.64 +
   93.65 +#define _set_tssldt_desc(desc,addr,limit,type)           \
   93.66 +do {                                                     \
   93.67 +    (desc)[0].a =                                        \
   93.68 +        ((u32)(addr) << 16) | ((u32)(limit) & 0xFFFF);   \
   93.69 +    (desc)[0].b =                                        \
   93.70 +        ((u32)(addr) & 0xFF000000U) |                    \
   93.71 +        ((u32)(type) << 8) | 0x8000U |                   \
   93.72 +        (((u32)(addr) & 0x00FF0000U) >> 16);             \
   93.73 +    (desc)[1].a = (u32)(((unsigned long)(addr)) >> 32);  \
   93.74 +    (desc)[1].b = 0;                                     \
   93.75 +} while (0)
   93.76 +
   93.77 +#elif defined(__i386__)
   93.78 +
   93.79 +#define __DOUBLEFAULT_TSS_ENTRY FIRST_RESERVED_GDT_ENTRY
   93.80 +
   93.81 +#define __FIRST_TSS_ENTRY (FIRST_RESERVED_GDT_ENTRY + 8)
   93.82 +#define __FIRST_LDT_ENTRY (__FIRST_TSS_ENTRY + 1)
   93.83 +
   93.84 +#define __TSS(n) (((n)<<1) + __FIRST_TSS_ENTRY)
   93.85 +#define __LDT(n) (((n)<<1) + __FIRST_LDT_ENTRY)
   93.86 +
   93.87 +typedef struct desc_struct idt_entry_t;
   93.88 +
   93.89 +#define _set_gate(gate_addr,type,dpl,addr) \
   93.90 +do { \
   93.91 +  int __d0, __d1; \
   93.92 +  __asm__ __volatile__ ("movw %%dx,%%ax\n\t" \
   93.93 + "movw %4,%%dx\n\t" \
   93.94 + "movl %%eax,%0\n\t" \
   93.95 + "movl %%edx,%1" \
   93.96 + :"=m" (*((long *) (gate_addr))), \
   93.97 +  "=m" (*(1+(long *) (gate_addr))), "=&a" (__d0), "=&d" (__d1) \
   93.98 + :"i" ((short) (0x8000+(dpl<<13)+(type<<8))), \
   93.99 +  "3" ((char *) (addr)),"2" (__HYPERVISOR_CS << 16)); \
  93.100 +} while (0)
  93.101 +
  93.102 +#define _set_tssldt_desc(n,addr,limit,type) \
  93.103 +__asm__ __volatile__ ("movw %w3,0(%2)\n\t" \
  93.104 + "movw %%ax,2(%2)\n\t" \
  93.105 + "rorl $16,%%eax\n\t" \
  93.106 + "movb %%al,4(%2)\n\t" \
  93.107 + "movb %4,5(%2)\n\t" \
  93.108 + "movb $0,6(%2)\n\t" \
  93.109 + "movb %%ah,7(%2)\n\t" \
  93.110 + "rorl $16,%%eax" \
  93.111 + : "=m"(*(n)) : "a" (addr), "r"(n), "ir"(limit), "i"(type|0x80))
  93.112 +
  93.113 +#endif
  93.114 +
  93.115  extern struct desc_struct gdt_table[];
  93.116 -extern struct desc_struct *idt, *gdt;
  93.117 +extern struct desc_struct *gdt;
  93.118 +extern idt_entry_t        *idt;
  93.119  
  93.120  struct Xgt_desc_struct {
  93.121 -	unsigned short size;
  93.122 -	unsigned long address __attribute__((packed));
  93.123 +    unsigned short size;
  93.124 +    unsigned long address __attribute__((packed));
  93.125  };
  93.126  
  93.127  #define idt_descr (*(struct Xgt_desc_struct *)((char *)&idt - 2))
  93.128  #define gdt_descr (*(struct Xgt_desc_struct *)((char *)&gdt - 2))
  93.129  
  93.130  extern void set_intr_gate(unsigned int irq, void * addr);
  93.131 +extern void set_system_gate(unsigned int n, void *addr);
  93.132 +extern void set_task_gate(unsigned int n, unsigned int sel);
  93.133  extern void set_tss_desc(unsigned int n, void *addr);
  93.134  
  93.135  #endif /* !__ASSEMBLY__ */
  93.136 -
  93.137 -#endif
  93.138 +#endif /* __ARCH_DESC_H */
    94.1 --- a/xen/include/asm-x86/domain_page.h	Fri Jan 28 14:53:32 2005 +0000
    94.2 +++ b/xen/include/asm-x86/domain_page.h	Fri Feb 04 14:44:18 2005 +0000
    94.3 @@ -1,29 +1,5 @@
    94.4 -/******************************************************************************
    94.5 - * domain_page.h
    94.6 - * 
    94.7 - * Allow temporary mapping of domain page frames into Xen space.
    94.8 - */
    94.9 -
   94.10 -#ifndef __ASM_DOMAIN_PAGE_H__
   94.11 -#define __ASM_DOMAIN_PAGE_H__
   94.12 -
   94.13 -#include <xen/config.h>
   94.14 -#include <xen/sched.h>
   94.15 -
   94.16 -extern unsigned long *mapcache;
   94.17 -#define MAPCACHE_ENTRIES        1024
   94.18 -
   94.19 -/*
   94.20 - * Maps a given physical address, returning corresponding virtual address.
   94.21 - * The entire page containing that VA is now accessible until a 
   94.22 - * corresponding call to unmap_domain_mem().
   94.23 - */
   94.24 -extern void *map_domain_mem(unsigned long pa);
   94.25 -
   94.26 -/*
   94.27 - * Pass a VA within a page previously mapped with map_domain_mem().
   94.28 - * That page will then be removed from the mapping lists.
   94.29 - */
   94.30 -extern void unmap_domain_mem(void *va);
   94.31 -
   94.32 -#endif /* __ASM_DOMAIN_PAGE_H__ */
   94.33 +#ifdef __x86_64__
   94.34 +#include <asm/x86_64/domain_page.h>
   94.35 +#else
   94.36 +#include <asm/x86_32/domain_page.h>
   94.37 +#endif
    95.1 --- a/xen/include/asm-x86/fixmap.h	Fri Jan 28 14:53:32 2005 +0000
    95.2 +++ b/xen/include/asm-x86/fixmap.h	Fri Feb 04 14:44:18 2005 +0000
    95.3 @@ -39,18 +39,18 @@ enum fixed_addresses {
    95.4      __end_of_fixed_addresses
    95.5  };
    95.6  
    95.7 -#define FIXADDR_TOP   (0xffffe000UL)
    95.8 +#define FIXADDR_TOP   (IOREMAP_VIRT_END - PAGE_SIZE)
    95.9  #define FIXADDR_SIZE  (__end_of_fixed_addresses << PAGE_SHIFT)
   95.10  #define FIXADDR_START (FIXADDR_TOP - FIXADDR_SIZE)
   95.11  
   95.12 -extern void __set_fixmap(enum fixed_addresses idx,
   95.13 -                         l1_pgentry_t entry);
   95.14 +extern void __set_fixmap(
   95.15 +    enum fixed_addresses idx, unsigned long p, unsigned long flags);
   95.16  
   95.17  #define set_fixmap(idx, phys) \
   95.18 -    __set_fixmap(idx, mk_l1_pgentry(phys|PAGE_HYPERVISOR))
   95.19 +    __set_fixmap(idx, phys, PAGE_HYPERVISOR)
   95.20  
   95.21  #define set_fixmap_nocache(idx, phys) \
   95.22 -    __set_fixmap(idx, mk_l1_pgentry(phys|PAGE_HYPERVISOR_NOCACHE))
   95.23 +    __set_fixmap(idx, phys, PAGE_HYPERVISOR_NOCACHE)
   95.24  
   95.25  #define fix_to_virt(x) (FIXADDR_TOP - ((x) << PAGE_SHIFT))
   95.26  
    96.1 --- a/xen/include/asm-x86/irq.h	Fri Jan 28 14:53:32 2005 +0000
    96.2 +++ b/xen/include/asm-x86/irq.h	Fri Feb 04 14:44:18 2005 +0000
    96.3 @@ -15,11 +15,11 @@ extern void enable_irq(unsigned int);
    96.4   * IDT vectors usable for external interrupt sources start
    96.5   * at 0x20:
    96.6   */
    96.7 -#define FIRST_EXTERNAL_VECTOR	0x30
    96.8 +#define FIRST_EXTERNAL_VECTOR   0x30
    96.9  
   96.10  #define NR_IRQS (256 - FIRST_EXTERNAL_VECTOR)
   96.11  
   96.12 -#define HYPERCALL_VECTOR	0x82
   96.13 +#define HYPERCALL_VECTOR        0x82
   96.14  
   96.15  /*
   96.16   * Vectors 0x30-0x3f are used for ISA interrupts.
   96.17 @@ -28,30 +28,30 @@ extern void enable_irq(unsigned int);
   96.18  /*
   96.19   * Special IRQ vectors used by the SMP architecture, 0xf0-0xff
   96.20   */
   96.21 -#define SPURIOUS_APIC_VECTOR	0xff
   96.22 -#define ERROR_APIC_VECTOR	0xfe
   96.23 -#define INVALIDATE_TLB_VECTOR	0xfd
   96.24 -#define EVENT_CHECK_VECTOR	0xfc
   96.25 -#define CALL_FUNCTION_VECTOR	0xfb
   96.26 -#define KDB_VECTOR		0xfa
   96.27 +#define SPURIOUS_APIC_VECTOR    0xff
   96.28 +#define ERROR_APIC_VECTOR       0xfe
   96.29 +#define INVALIDATE_TLB_VECTOR   0xfd
   96.30 +#define EVENT_CHECK_VECTOR      0xfc
   96.31 +#define CALL_FUNCTION_VECTOR    0xfb
   96.32 +#define KDB_VECTOR              0xfa
   96.33  
   96.34  /*
   96.35   * Local APIC timer IRQ vector is on a different priority level,
   96.36   * to work around the 'lost local interrupt if more than 2 IRQ
   96.37   * sources per level' errata.
   96.38   */
   96.39 -#define LOCAL_TIMER_VECTOR	0xef
   96.40 +#define LOCAL_TIMER_VECTOR      0xef
   96.41  
   96.42  /*
   96.43   * First APIC vector available to drivers: (vectors 0x40-0xee)
   96.44   * we start at 0x41 to spread out vectors evenly between priority
   96.45   * levels. (0x82 is the hypercall vector)
   96.46   */
   96.47 -#define FIRST_DEVICE_VECTOR	0x41
   96.48 -#define FIRST_SYSTEM_VECTOR	0xef
   96.49 +#define FIRST_DEVICE_VECTOR     0x41
   96.50 +#define FIRST_SYSTEM_VECTOR     0xef
   96.51  
   96.52  extern int irq_vector[NR_IRQS];
   96.53 -#define IO_APIC_VECTOR(irq)	irq_vector[irq]
   96.54 +#define IO_APIC_VECTOR(irq)     irq_vector[irq]
   96.55  
   96.56  /*
   96.57   * Various low-level irq details needed by irq.c, process.c,
   96.58 @@ -84,63 +84,13 @@ extern char _stext, _etext;
   96.59  
   96.60  #define IO_APIC_IRQ(x) (((x) >= 16) || ((1<<(x)) & io_apic_irqs))
   96.61  
   96.62 -#define BUILD_SMP_INTERRUPT(x,v) XBUILD_SMP_INTERRUPT(x,v)
   96.63 -#define XBUILD_SMP_INTERRUPT(x,v)\
   96.64 -asmlinkage void x(void); \
   96.65 -asmlinkage void call_##x(void); \
   96.66 -__asm__( \
   96.67 -"\n"__ALIGN_STR"\n" \
   96.68 -SYMBOL_NAME_STR(x) ":\n\t" \
   96.69 -	"push"__OS" $"#v"<<16\n\t" \
   96.70 -	SAVE_ALL(a) \
   96.71 -	SYMBOL_NAME_STR(call_##x)":\n\t" \
   96.72 -	"call "SYMBOL_NAME_STR(smp_##x)"\n\t" \
   96.73 -	"jmp ret_from_intr\n");
   96.74 -
   96.75 -#define BUILD_SMP_TIMER_INTERRUPT(x,v) XBUILD_SMP_TIMER_INTERRUPT(x,v)
   96.76 -#define XBUILD_SMP_TIMER_INTERRUPT(x,v) \
   96.77 -asmlinkage void x(struct xen_regs * regs); \
   96.78 -asmlinkage void call_##x(void); \
   96.79 -__asm__( \
   96.80 -"\n"__ALIGN_STR"\n" \
   96.81 -SYMBOL_NAME_STR(x) ":\n\t" \
   96.82 -	"push"__OS" $"#v"<<16\n\t" \
   96.83 -	SAVE_ALL(a) \
   96.84 -	"mov %"__OP"sp,%"__OP"ax\n\t" \
   96.85 -	"push %"__OP"ax\n\t" \
   96.86 -	SYMBOL_NAME_STR(call_##x)":\n\t" \
   96.87 -	"call "SYMBOL_NAME_STR(smp_##x)"\n\t" \
   96.88 -	"add $4,%"__OP"sp\n\t" \
   96.89 -	"jmp ret_from_intr\n");
   96.90 -
   96.91 -#define BUILD_COMMON_IRQ() \
   96.92 -asmlinkage void call_do_IRQ(void); \
   96.93 -__asm__( \
   96.94 -	"\n" __ALIGN_STR"\n" \
   96.95 -	"common_interrupt:\n\t" \
   96.96 -	SAVE_ALL(a) \
   96.97 -	SYMBOL_NAME_STR(call_do_IRQ)":\n\t" \
   96.98 -	"call " SYMBOL_NAME_STR(do_IRQ) "\n\t" \
   96.99 -	"jmp ret_from_intr\n");
  96.100 -
  96.101 -#define IRQ_NAME2(nr) nr##_interrupt(void)
  96.102 -#define IRQ_NAME(nr) IRQ_NAME2(IRQ##nr)
  96.103 -
  96.104 -#define BUILD_IRQ(nr) \
  96.105 -asmlinkage void IRQ_NAME(nr); \
  96.106 -__asm__( \
  96.107 -"\n"__ALIGN_STR"\n" \
  96.108 -SYMBOL_NAME_STR(IRQ) #nr "_interrupt:\n\t" \
  96.109 -	"push"__OS" $"#nr"<<16\n\t" \
  96.110 -	"jmp common_interrupt");
  96.111 -
  96.112  #include <xen/irq.h>
  96.113  
  96.114  static inline void hw_resend_irq(struct hw_interrupt_type *h, unsigned int i)
  96.115  {
  96.116  #if defined(CONFIG_X86_IO_APIC)
  96.117 -        if (IO_APIC_IRQ(i))
  96.118 -                send_IPI_self(IO_APIC_VECTOR(i));
  96.119 +    if (IO_APIC_IRQ(i))
  96.120 +        send_IPI_self(IO_APIC_VECTOR(i));
  96.121  #endif
  96.122  }
  96.123  
    97.1 --- a/xen/include/asm-x86/mm.h	Fri Jan 28 14:53:32 2005 +0000
    97.2 +++ b/xen/include/asm-x86/mm.h	Fri Feb 04 14:44:18 2005 +0000
    97.3 @@ -30,6 +30,9 @@ struct pfn_info
    97.4      /* Each frame can be threaded onto a doubly-linked list. */
    97.5      struct list_head list;
    97.6  
    97.7 +    /* Timestamp from 'TLB clock', used to reduce need for safety flushes. */
    97.8 +    u32 tlbflush_timestamp;
    97.9 +
   97.10      /* Reference count and various PGC_xxx flags and fields. */
   97.11      u32 count_info;
   97.12  
   97.13 @@ -39,24 +42,22 @@ struct pfn_info
   97.14          /* Page is in use: ((count_info & PGC_count_mask) != 0). */
   97.15          struct {
   97.16              /* Owner of this page (NULL if page is anonymous). */
   97.17 -            struct domain *domain;
   97.18 +            u32 _domain; /* pickled format */
   97.19              /* Type reference count and various PGT_xxx flags and fields. */
   97.20              u32 type_info;
   97.21 -        } inuse;
   97.22 +        } PACKED inuse;
   97.23  
   97.24          /* Page is on a free list: ((count_info & PGC_count_mask) == 0). */
   97.25          struct {
   97.26              /* Mask of possibly-tainted TLBs. */
   97.27 -            unsigned long cpu_mask;
   97.28 +            u32 cpu_mask;
   97.29              /* Order-size of the free chunk this page is the head of. */
   97.30              u8 order;
   97.31 -        } free;
   97.32 +        } PACKED free;
   97.33  
   97.34 -    } u;
   97.35 +    } PACKED u;
   97.36  
   97.37 -    /* Timestamp from 'TLB clock', used to reduce need for safety flushes. */
   97.38 -    u32 tlbflush_timestamp;
   97.39 -};
   97.40 +} PACKED;
   97.41  
   97.42   /* The following page types are MUTUALLY EXCLUSIVE. */
   97.43  #define PGT_none            (0<<29) /* no special uses of this page */
   97.44 @@ -97,9 +98,25 @@ struct pfn_info
   97.45  
   97.46  #define IS_XEN_HEAP_FRAME(_pfn) (page_to_phys(_pfn) < xenheap_phys_end)
   97.47  
   97.48 +#if defined(__i386__)
   97.49 +
   97.50 +#define pickle_domptr(_d)   ((u32)(unsigned long)(_d))
   97.51 +#define unpickle_domptr(_d) ((struct domain *)(unsigned long)(_d))
   97.52 +
   97.53 +#elif defined(__x86_64__)
   97.54 +static inline struct domain *unpickle_domptr(u32 _domain)
   97.55 +{ return (_domain == 0) ? NULL : __va(_domain); }
   97.56 +static inline u32 pickle_domptr(struct domain *domain)
   97.57 +{ return (domain == NULL) ? 0 : (u32)__pa(domain); }
   97.58 +
   97.59 +#endif
   97.60 +
   97.61 +#define page_get_owner(_p)    (unpickle_domptr((_p)->u.inuse._domain))
   97.62 +#define page_set_owner(_p,_d) ((_p)->u.inuse._domain = pickle_domptr(_d))
   97.63 +
   97.64  #define SHARE_PFN_WITH_DOMAIN(_pfn, _dom)                                   \
   97.65      do {                                                                    \
   97.66 -        (_pfn)->u.inuse.domain = (_dom);                                    \
   97.67 +        page_set_owner((_pfn), (_dom));                                     \
   97.68          /* The incremented type count is intended to pin to 'writable'. */  \
   97.69          (_pfn)->u.inuse.type_info = PGT_writable_page | PGT_validated | 1;  \
   97.70          wmb(); /* install valid domain ptr before updating refcnt. */       \
   97.71 @@ -142,7 +159,8 @@ static inline int get_page(struct pfn_in
   97.72                             struct domain *domain)
   97.73  {
   97.74      u32 x, nx, y = page->count_info;
   97.75 -    struct domain *d, *nd = page->u.inuse.domain;
   97.76 +    u32 d, nd = page->u.inuse._domain;
   97.77 +    u32 _domain = pickle_domptr(domain);
   97.78  
   97.79      do {
   97.80          x  = y;
   97.81 @@ -150,10 +168,10 @@ static inline int get_page(struct pfn_in
   97.82          d  = nd;
   97.83          if ( unlikely((x & PGC_count_mask) == 0) ||  /* Not allocated? */
   97.84               unlikely((nx & PGC_count_mask) == 0) || /* Count overflow? */
   97.85 -             unlikely(d != domain) )                 /* Wrong owner? */
   97.86 +             unlikely(d != _domain) )                /* Wrong owner? */
   97.87          {
   97.88              DPRINTK("Error pfn %08lx: ed=%p, sd=%p, caf=%08x, taf=%08x\n",
   97.89 -                    page_to_pfn(page), domain, d,
   97.90 +                    page_to_pfn(page), domain, unpickle_domptr(d),
   97.91                      x, page->u.inuse.type_info);
   97.92              return 0;
   97.93          }
   97.94 @@ -198,7 +216,7 @@ static inline int get_page_and_type(stru
   97.95      ASSERT(((_p)->u.inuse.type_info & PGT_count_mask) != 0)
   97.96  #define ASSERT_PAGE_IS_DOMAIN(_p, _d)                          \
   97.97      ASSERT(((_p)->count_info & PGC_count_mask) != 0);          \
   97.98 -    ASSERT((_p)->u.inuse.domain == (_d))
   97.99 +    ASSERT(page_get_owner(_p) == (_d))
  97.100  
  97.101  int check_descriptor(unsigned long *d);
  97.102  
  97.103 @@ -222,17 +240,8 @@ void synchronise_pagetables(unsigned lon
  97.104   */
  97.105  #undef  phys_to_machine_mapping
  97.106  
  97.107 -#ifdef __x86_64__
  97.108 -extern unsigned long *machine_to_phys_mapping;
  97.109 -extern unsigned long *phys_to_machine_mapping;
  97.110 -#define m2p_start_mfn virt_to_phys(machine_to_phys_mapping)
  97.111 -#else
  97.112 -/* Don't call virt_to_phys on this: it isn't direct mapped.  Using
  97.113 -   m2p_start_mfn instead. */
  97.114  #define machine_to_phys_mapping ((unsigned long *)RDWR_MPT_VIRT_START)
  97.115 -extern unsigned long m2p_start_mfn;
  97.116  #define phys_to_machine_mapping ((unsigned long *)PERDOMAIN_VIRT_START)
  97.117 -#endif
  97.118  
  97.119  #define set_machinetophys(_mfn, _pfn) machine_to_phys_mapping[(_mfn)] = (_pfn)
  97.120  
    98.1 --- a/xen/include/asm-x86/page.h	Fri Jan 28 14:53:32 2005 +0000
    98.2 +++ b/xen/include/asm-x86/page.h	Fri Feb 04 14:44:18 2005 +0000
    98.3 @@ -46,7 +46,6 @@ typedef struct { unsigned long l1_lo; } 
    98.4  typedef struct { unsigned long l2_lo; } l2_pgentry_t;
    98.5  typedef struct { unsigned long l3_lo; } l3_pgentry_t;
    98.6  typedef struct { unsigned long l4_lo; } l4_pgentry_t;
    98.7 -typedef struct { unsigned long pt_lo; } pagetable_t;
    98.8  #endif /* !__ASSEMBLY__ */
    98.9  
   98.10  /* Strip type from a table entry. */
   98.11 @@ -54,14 +53,12 @@ typedef struct { unsigned long pt_lo; } 
   98.12  #define l2_pgentry_val(_x) ((_x).l2_lo)
   98.13  #define l3_pgentry_val(_x) ((_x).l3_lo)
   98.14  #define l4_pgentry_val(_x) ((_x).l4_lo)
   98.15 -#define pagetable_val(_x)  ((_x).pt_lo)
   98.16  
   98.17  /* Add type to a table entry. */
   98.18  #define mk_l1_pgentry(_x)  ( (l1_pgentry_t) { (_x) } )
   98.19  #define mk_l2_pgentry(_x)  ( (l2_pgentry_t) { (_x) } )
   98.20  #define mk_l3_pgentry(_x)  ( (l3_pgentry_t) { (_x) } )
   98.21  #define mk_l4_pgentry(_x)  ( (l4_pgentry_t) { (_x) } )
   98.22 -#define mk_pagetable(_x)   ( (pagetable_t) { (_x) } )
   98.23  
   98.24  /* Turn a typed table entry into a page index. */
   98.25  #define l1_pgentry_to_pagenr(_x) (l1_pgentry_val(_x) >> PAGE_SHIFT) 
   98.26 @@ -91,11 +88,23 @@ typedef struct { unsigned long pt_lo; } 
   98.27    ((_a) >> L2_PAGETABLE_SHIFT)
   98.28  #elif defined(__x86_64__)
   98.29  #define l2_table_offset(_a) \
   98.30 -  (((_a) >> L2_PAGETABLE_SHIFT) & (ENTRIES_PER_L2_PAGETABLE -1))
   98.31 +  (((_a) >> L2_PAGETABLE_SHIFT) & (ENTRIES_PER_L2_PAGETABLE - 1))
   98.32  #define l3_table_offset(_a) \
   98.33 -  (((_a) >> L3_PAGETABLE_SHIFT) & (ENTRIES_PER_L3_PAGETABLE -1))
   98.34 +  (((_a) >> L3_PAGETABLE_SHIFT) & (ENTRIES_PER_L3_PAGETABLE - 1))
   98.35  #define l4_table_offset(_a) \
   98.36 -  ((_a) >> L4_PAGETABLE_SHIFT)
   98.37 +  (((_a) >> L4_PAGETABLE_SHIFT) & (ENTRIES_PER_L4_PAGETABLE - 1))
   98.38 +#endif
   98.39 +
   98.40 +#if defined(__i386__)
   98.41 +#define pagetable_t l2_pgentry_t
   98.42 +#define pagetable_val(_x)  ((_x).l2_lo)
   98.43 +#define mk_pagetable(_x)   ( (l2_pgentry_t) { (_x) } )
   98.44 +#define ENTRIES_PER_PAGETABLE ENTRIES_PER_L2_PAGETABLE
   98.45 +#elif defined(__x86_64__)
   98.46 +#define pagetable_t l4_pgentry_t
   98.47 +#define pagetable_val(_x)  ((_x).l4_lo)
   98.48 +#define mk_pagetable(_x)   ( (l4_pgentry_t) { (_x) } )
   98.49 +#define ENTRIES_PER_PAGETABLE ENTRIES_PER_L4_PAGETABLE
   98.50  #endif
   98.51  
   98.52  #define PAGE_OFFSET		((unsigned long)__PAGE_OFFSET)
   98.53 @@ -131,11 +140,7 @@ typedef struct { unsigned long pt_lo; } 
   98.54  
   98.55  #define va_to_l1mfn(_va) (l2_pgentry_val(linear_l2_table[_va>>L2_PAGETABLE_SHIFT]) >> PAGE_SHIFT)
   98.56  
   98.57 -#ifdef __i386__
   98.58 -extern l2_pgentry_t idle_pg_table[ENTRIES_PER_L2_PAGETABLE];
   98.59 -#else
   98.60 -extern l4_pgentry_t idle_pg_table[ENTRIES_PER_L4_PAGETABLE];
   98.61 -#endif
   98.62 +extern pagetable_t idle_pg_table[ENTRIES_PER_PAGETABLE];
   98.63  
   98.64  extern void paging_init(void);
   98.65  
   98.66 @@ -191,6 +196,7 @@ extern void paging_init(void);
   98.67  #define PAGE_HYPERVISOR_NOCACHE MAKE_GLOBAL(__PAGE_HYPERVISOR_NOCACHE)
   98.68  
   98.69  #ifndef __ASSEMBLY__
   98.70 +
   98.71  static __inline__ int get_order(unsigned long size)
   98.72  {
   98.73      int order;
   98.74 @@ -205,6 +211,16 @@ static __inline__ int get_order(unsigned
   98.75  }
   98.76  
   98.77  extern void zap_low_mappings(void);
   98.78 -#endif
   98.79 +
   98.80 +/* Map physical byte range (@p, @p+@s) at virt address @v in pagetable @pt. */
   98.81 +extern int
   98.82 +map_pages(
   98.83 +    pagetable_t *pt,
   98.84 +    unsigned long v,
   98.85 +    unsigned long p,
   98.86 +    unsigned long s,
   98.87 +    unsigned long flags);
   98.88 +
   98.89 +#endif /* !__ASSEMBLY__ */
   98.90  
   98.91  #endif /* __I386_PAGE_H__ */
    99.1 --- a/xen/include/asm-x86/pda.h	Fri Jan 28 14:53:32 2005 +0000
    99.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    99.3 @@ -1,63 +0,0 @@
    99.4 -#ifndef X86_64_PDA_H
    99.5 -#define X86_64_PDA_H
    99.6 -
    99.7 -#include <xen/cache.h>
    99.8 -
    99.9 -/* Per processor datastructure. %gs points to it while the kernel runs */ 
   99.10 -/* To use a new field with the *_pda macros it needs to be added to tools/offset.c */
   99.11 -struct x8664_pda {
   99.12 -	unsigned long kernelstack;  /* TOS for current process */ 
   99.13 -	unsigned long oldrsp; 	    /* user rsp for system call */
   99.14 -	unsigned long irqrsp;	    /* Old rsp for interrupts. */ 
   99.15 -	struct exec_domain *pcurrent;	/* Current process */
   99.16 -        int irqcount;		    /* Irq nesting counter. Starts with -1 */  	
   99.17 -	int cpunumber;		    /* Logical CPU number */
   99.18 -	char *irqstackptr;	/* top of irqstack */
   99.19 -	unsigned long volatile *level4_pgt; 
   99.20 -} __cacheline_aligned;
   99.21 -
   99.22 -#define PDA_STACKOFFSET (5*8)
   99.23 -
   99.24 -#define IRQSTACK_ORDER 2
   99.25 -#define IRQSTACKSIZE (PAGE_SIZE << IRQSTACK_ORDER) 
   99.26 -
   99.27 -extern struct x8664_pda cpu_pda[];
   99.28 -
   99.29 -/* 
   99.30 - * There is no fast way to get the base address of the PDA, all the accesses
   99.31 - * have to mention %fs/%gs.  So it needs to be done this Torvaldian way.
   99.32 - */ 
   99.33 -#define sizeof_field(type,field)  (sizeof(((type *)0)->field))
   99.34 -#define typeof_field(type,field)  typeof(((type *)0)->field)
   99.35 -
   99.36 -extern void __bad_pda_field(void);
   99.37 -/* Don't use offsetof because it requires too much infrastructure */
   99.38 -#define pda_offset(field) ((unsigned long)&((struct x8664_pda *)0)->field)
   99.39 -
   99.40 -#define pda_to_op(op,field,val) do { \
   99.41 -       switch (sizeof_field(struct x8664_pda, field)) { 		\
   99.42 -       case 2: asm volatile(op "w %0,%%gs:%P1" :: "r" (val), "i"(pda_offset(field)):"memory"); break;	\
   99.43 -       case 4: asm volatile(op "l %0,%%gs:%P1" :: "r" (val), "i"(pda_offset(field)):"memory"); break;	\
   99.44 -       case 8: asm volatile(op "q %0,%%gs:%P1" :: "r" (val), "i"(pda_offset(field)):"memory"); break;	\
   99.45 -       default: __bad_pda_field(); 					\
   99.46 -       } \
   99.47 -       } while (0)
   99.48 -
   99.49 -
   99.50 -#define pda_from_op(op,field) ({ \
   99.51 -       typedef typeof_field(struct x8664_pda, field) T__; T__ ret__; \
   99.52 -       switch (sizeof_field(struct x8664_pda, field)) { 		\
   99.53 -       case 2: asm volatile(op "w %%gs:%P1,%0":"=r" (ret__): "i" (pda_offset(field)):"memory"); break;	\
   99.54 -       case 4: asm volatile(op "l %%gs:%P1,%0":"=r" (ret__): "i" (pda_offset(field)):"memory"); break;	\
   99.55 -       case 8: asm volatile(op "q %%gs:%P1,%0":"=r" (ret__): "i" (pda_offset(field)):"memory"); break;	\
   99.56 -       default: __bad_pda_field(); 					\
   99.57 -       } \
   99.58 -       ret__; })
   99.59 -
   99.60 -
   99.61 -#define read_pda(field) pda_from_op("mov",field)
   99.62 -#define write_pda(field,val) pda_to_op("mov",field,val)
   99.63 -#define add_pda(field,val) pda_to_op("add",field,val)
   99.64 -#define sub_pda(field,val) pda_to_op("sub",field,val)
   99.65 -
   99.66 -#endif
   100.1 --- a/xen/include/asm-x86/processor.h	Fri Jan 28 14:53:32 2005 +0000
   100.2 +++ b/xen/include/asm-x86/processor.h	Fri Feb 04 14:44:18 2005 +0000
   100.3 @@ -16,6 +16,7 @@
   100.4  #include <asm/pdb.h>
   100.5  #include <xen/config.h>
   100.6  #include <xen/spinlock.h>
   100.7 +#include <xen/cache.h>
   100.8  #include <asm/vmx_vmcs.h>
   100.9  #include <public/xen.h>
  100.10  #endif
  100.11 @@ -110,6 +111,7 @@
  100.12  #define TRAP_alignment_check 17
  100.13  #define TRAP_machine_check   18
  100.14  #define TRAP_simd_error      19
  100.15 +#define TRAP_deferred_nmi    31
  100.16  
  100.17  /*
  100.18   * Non-fatal fault/trap handlers return an error code to the caller. If the
  100.19 @@ -377,7 +379,7 @@ struct tss_struct {
  100.20      u8  io_bitmap[IOBMP_BYTES+1];
  100.21      /* Pads the TSS to be cacheline-aligned (total size is 0x2080). */
  100.22      u8 __cacheline_filler[23];
  100.23 -};
  100.24 +} __cacheline_aligned PACKED;
  100.25  
  100.26  struct trap_bounce {
  100.27      unsigned long  error_code;
  100.28 @@ -411,11 +413,11 @@ struct thread_struct {
  100.29       * for segment registers %ds, %es, %fs and %gs:
  100.30       * 	%ds, %es, %fs, %gs, %eip, %cs, %eflags [, %oldesp, %oldss]
  100.31       */
  100.32 -    unsigned long event_selector;    /* 08: entry CS  */
  100.33 -    unsigned long event_address;     /* 12: entry EIP */
  100.34 +    unsigned long event_selector;    /* entry CS  */
  100.35 +    unsigned long event_address;     /* entry EIP */
  100.36  
  100.37 -    unsigned long failsafe_selector; /* 16: entry CS  */
  100.38 -    unsigned long failsafe_address;  /* 20: entry EIP */
  100.39 +    unsigned long failsafe_selector; /* entry CS  */
  100.40 +    unsigned long failsafe_address;  /* entry EIP */
  100.41  
  100.42      /* Bounce information for propagating an exception to guest OS. */
  100.43      struct trap_bounce trap_bounce;
  100.44 @@ -426,7 +428,7 @@ struct thread_struct {
  100.45      u8 *io_bitmap; /* Pointer to task's IO bitmap or NULL */
  100.46  
  100.47      /* Trap info. */
  100.48 -#ifdef __i386__
  100.49 +#ifdef ARCH_HAS_FAST_TRAP
  100.50      int                fast_trap_idx;
  100.51      struct desc_struct fast_trap_desc;
  100.52  #endif
  100.53 @@ -434,13 +436,13 @@ struct thread_struct {
  100.54  #ifdef CONFIG_VMX
  100.55      struct arch_vmx_struct arch_vmx; /* Virtual Machine Extensions */
  100.56  #endif
  100.57 -};
  100.58 +} __cacheline_aligned;
  100.59  
  100.60  #define IDT_ENTRIES 256
  100.61 -extern struct desc_struct idt_table[];
  100.62 -extern struct desc_struct *idt_tables[];
  100.63 +extern idt_entry_t idt_table[];
  100.64 +extern idt_entry_t *idt_tables[];
  100.65  
  100.66 -#if defined(__i386__)
  100.67 +#ifdef ARCH_HAS_FAST_TRAP
  100.68  
  100.69  #define SET_DEFAULT_FAST_TRAP(_p) \
  100.70      (_p)->fast_trap_idx = 0x20;   \
  100.71 @@ -464,6 +466,13 @@ extern struct desc_struct *idt_tables[];
  100.72  
  100.73  long set_fast_trap(struct exec_domain *p, int idx);
  100.74  
  100.75 +#else
  100.76 +
  100.77 +#define SET_DEFAULT_FAST_TRAP(_p) ((void)0)
  100.78 +#define CLEAR_FAST_TRAP(_p)       ((void)0)
  100.79 +#define SET_FAST_TRAP(_p)         ((void)0)
  100.80 +#define set_fast_trap(_p, _i)     (0)
  100.81 +
  100.82  #endif
  100.83  
  100.84  #define INIT_THREAD { 0 }
  100.85 @@ -634,6 +643,7 @@ void show_guest_stack();
  100.86  void show_trace(unsigned long *esp);
  100.87  void show_stack(unsigned long *esp);
  100.88  void show_registers(struct xen_regs *regs);
  100.89 +void show_page_walk(unsigned long addr);
  100.90  asmlinkage void fatal_trap(int trapnr, struct xen_regs *regs);
  100.91  
  100.92  #endif /* !__ASSEMBLY__ */
   101.1 --- a/xen/include/asm-x86/regs.h	Fri Jan 28 14:53:32 2005 +0000
   101.2 +++ b/xen/include/asm-x86/regs.h	Fri Feb 04 14:44:18 2005 +0000
   101.3 @@ -1,6 +1,36 @@
   101.4 +
   101.5 +#ifndef __X86_REGS_H__
   101.6 +#define __X86_REGS_H__
   101.7  
   101.8  #ifdef __x86_64__
   101.9  #include <asm/x86_64/regs.h>
  101.10  #else
  101.11  #include <asm/x86_32/regs.h>
  101.12  #endif
  101.13 +
  101.14 +enum EFLAGS {
  101.15 +    EF_CF   = 0x00000001,
  101.16 +    EF_PF   = 0x00000004,
  101.17 +    EF_AF   = 0x00000010,
  101.18 +    EF_ZF   = 0x00000040,
  101.19 +    EF_SF   = 0x00000080,
  101.20 +    EF_TF   = 0x00000100,
  101.21 +    EF_IE   = 0x00000200,
  101.22 +    EF_DF   = 0x00000400,
  101.23 +    EF_OF   = 0x00000800,
  101.24 +    EF_IOPL = 0x00003000,
  101.25 +    EF_IOPL_RING0 = 0x00000000,
  101.26 +    EF_IOPL_RING1 = 0x00001000,
  101.27 +    EF_IOPL_RING2 = 0x00002000,
  101.28 +    EF_NT   = 0x00004000,   /* nested task */
  101.29 +    EF_RF   = 0x00010000,   /* resume */
  101.30 +    EF_VM   = 0x00020000,   /* virtual mode */
  101.31 +    EF_AC   = 0x00040000,   /* alignment */
  101.32 +    EF_VIF  = 0x00080000,   /* virtual interrupt */
  101.33 +    EF_VIP  = 0x00100000,   /* virtual interrupt pending */
  101.34 +    EF_ID   = 0x00200000,   /* id */
  101.35 +};
  101.36 +
  101.37 +#define GUEST_FAULT(_r) (likely(VM86_MODE(_r) || !RING_0(_r)))
  101.38 +
  101.39 +#endif /* __X86_REGS_H__ */
   102.1 --- a/xen/include/asm-x86/shadow.h	Fri Jan 28 14:53:32 2005 +0000
   102.2 +++ b/xen/include/asm-x86/shadow.h	Fri Feb 04 14:44:18 2005 +0000
   102.3 @@ -189,7 +189,7 @@ static inline int __mark_dirty( struct m
   102.4          SH_LOG("mark_dirty OOR! mfn=%x pfn=%lx max=%x (mm %p)",
   102.5                 mfn, pfn, m->shadow_dirty_bitmap_size, m );
   102.6          SH_LOG("dom=%p caf=%08x taf=%08x\n", 
   102.7 -               frame_table[mfn].u.inuse.domain,
   102.8 +               page_get_owner(&frame_table[mfn]),
   102.9                 frame_table[mfn].count_info, 
  102.10                 frame_table[mfn].u.inuse.type_info );
  102.11      }
  102.12 @@ -616,7 +616,7 @@ static inline void set_shadow_status(
  102.13      {
  102.14          SH_LOG("Allocate more shadow hashtable blocks.");
  102.15  
  102.16 -        extra = xmalloc(
  102.17 +        extra = xmalloc_bytes(
  102.18              sizeof(void *) + (shadow_ht_extra_size * sizeof(*x)));
  102.19  
  102.20          /* XXX Should be more graceful here. */
   103.1 --- a/xen/include/asm-x86/smp.h	Fri Jan 28 14:53:32 2005 +0000
   103.2 +++ b/xen/include/asm-x86/smp.h	Fri Feb 04 14:44:18 2005 +0000
   103.3 @@ -61,12 +61,7 @@ extern void smp_store_cpu_info(int id);	
   103.4   * so this is correct in the x86 case.
   103.5   */
   103.6  
   103.7 -#if defined(__i386__)
   103.8  #define smp_processor_id() (current->processor)
   103.9 -#elif defined(__x86_64__)
  103.10 -#include <asm/pda.h>
  103.11 -#define smp_processor_id() read_pda(cpunumber)
  103.12 -#endif
  103.13  
  103.14  static __inline int hard_smp_processor_id(void)
  103.15  {
   104.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   104.2 +++ b/xen/include/asm-x86/time.h	Fri Feb 04 14:44:18 2005 +0000
   104.3 @@ -0,0 +1,7 @@
   104.4 +
   104.5 +#ifndef __X86_TIME_H__
   104.6 +#define __X86_TIME_H__
   104.7 +
   104.8 +/* nothing */
   104.9 +
  104.10 +#endif /* __X86_TIME_H__ */
   105.1 --- a/xen/include/asm-x86/vmx_platform.h	Fri Jan 28 14:53:32 2005 +0000
   105.2 +++ b/xen/include/asm-x86/vmx_platform.h	Fri Feb 04 14:44:18 2005 +0000
   105.3 @@ -81,11 +81,10 @@ struct virutal_platform_def {
   105.4      struct mi_per_cpu_info mpci;            /* MMIO */
   105.5  };
   105.6  
   105.7 -extern int mmio_space(unsigned long);
   105.8  extern void handle_mmio(unsigned long, unsigned long, unsigned long);
   105.9  extern int vmx_setup_platform(struct exec_domain *, execution_context_t *);
  105.10  
  105.11 -extern inline int mmio_space(unsigned long gpa)
  105.12 +static inline int mmio_space(unsigned long gpa)
  105.13  {
  105.14      if (gpa >= VGA_SPACE_START && gpa < VGA_SPACE_END) {
  105.15          return 1;
   106.1 --- a/xen/include/asm-x86/x86_32/asm_defns.h	Fri Jan 28 14:53:32 2005 +0000
   106.2 +++ b/xen/include/asm-x86/x86_32/asm_defns.h	Fri Feb 04 14:44:18 2005 +0000
   106.3 @@ -78,4 +78,51 @@
   106.4  
   106.5  #endif
   106.6  
   106.7 +#define BUILD_SMP_INTERRUPT(x,v) XBUILD_SMP_INTERRUPT(x,v)
   106.8 +#define XBUILD_SMP_INTERRUPT(x,v)\
   106.9 +asmlinkage void x(void); \
  106.10 +__asm__( \
  106.11 +    "\n"__ALIGN_STR"\n" \
  106.12 +    SYMBOL_NAME_STR(x) ":\n\t" \
  106.13 +    "pushl $"#v"<<16\n\t" \
  106.14 +    SAVE_ALL(a) \
  106.15 +    "call "SYMBOL_NAME_STR(smp_##x)"\n\t" \
  106.16 +    "jmp ret_from_intr\n");
  106.17 +
  106.18 +#define BUILD_SMP_TIMER_INTERRUPT(x,v) XBUILD_SMP_TIMER_INTERRUPT(x,v)
  106.19 +#define XBUILD_SMP_TIMER_INTERRUPT(x,v) \
  106.20 +asmlinkage void x(struct xen_regs * regs); \
  106.21 +__asm__( \
  106.22 +"\n"__ALIGN_STR"\n" \
  106.23 +SYMBOL_NAME_STR(x) ":\n\t" \
  106.24 +    "pushl $"#v"<<16\n\t" \
  106.25 +    SAVE_ALL(a) \
  106.26 +    "movl %esp,%eax\n\t" \
  106.27 +    "pushl %eax\n\t" \
  106.28 +    "call "SYMBOL_NAME_STR(smp_##x)"\n\t" \
  106.29 +    "addl $4,%esp\n\t" \
  106.30 +    "jmp ret_from_intr\n");
  106.31 +
  106.32 +#define BUILD_COMMON_IRQ() \
  106.33 +__asm__( \
  106.34 +    "\n" __ALIGN_STR"\n" \
  106.35 +    "common_interrupt:\n\t" \
  106.36 +    SAVE_ALL(a) \
  106.37 +    "movl %esp,%eax\n\t" \
  106.38 +    "pushl %eax\n\t" \
  106.39 +    "call " SYMBOL_NAME_STR(do_IRQ) "\n\t" \
  106.40 +    "addl $4,%esp\n\t" \
  106.41 +    "jmp ret_from_intr\n");
  106.42 +
  106.43 +#define IRQ_NAME2(nr) nr##_interrupt(void)
  106.44 +#define IRQ_NAME(nr) IRQ_NAME2(IRQ##nr)
  106.45 +
  106.46 +#define BUILD_IRQ(nr) \
  106.47 +asmlinkage void IRQ_NAME(nr); \
  106.48 +__asm__( \
  106.49 +"\n"__ALIGN_STR"\n" \
  106.50 +SYMBOL_NAME_STR(IRQ) #nr "_interrupt:\n\t" \
  106.51 +    "pushl $"#nr"<<16\n\t" \
  106.52 +    "jmp common_interrupt");
  106.53 +
  106.54  #endif /* __X86_32_ASM_DEFNS_H__ */
   107.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   107.2 +++ b/xen/include/asm-x86/x86_32/domain_page.h	Fri Feb 04 14:44:18 2005 +0000
   107.3 @@ -0,0 +1,29 @@
   107.4 +/******************************************************************************
   107.5 + * domain_page.h
   107.6 + * 
   107.7 + * Allow temporary mapping of domain page frames into Xen space.
   107.8 + */
   107.9 +
  107.10 +#ifndef __ASM_DOMAIN_PAGE_H__
  107.11 +#define __ASM_DOMAIN_PAGE_H__
  107.12 +
  107.13 +#include <xen/config.h>
  107.14 +#include <xen/sched.h>
  107.15 +
  107.16 +extern unsigned long *mapcache;
  107.17 +#define MAPCACHE_ENTRIES        1024
  107.18 +
  107.19 +/*
  107.20 + * Maps a given physical address, returning corresponding virtual address.
  107.21 + * The entire page containing that VA is now accessible until a 
  107.22 + * corresponding call to unmap_domain_mem().
  107.23 + */
  107.24 +extern void *map_domain_mem(unsigned long pa);
  107.25 +
  107.26 +/*
  107.27 + * Pass a VA within a page previously mapped with map_domain_mem().
  107.28 + * That page will then be removed from the mapping lists.
  107.29 + */
  107.30 +extern void unmap_domain_mem(void *va);
  107.31 +
  107.32 +#endif /* __ASM_DOMAIN_PAGE_H__ */
   108.1 --- a/xen/include/asm-x86/x86_32/regs.h	Fri Jan 28 14:53:32 2005 +0000
   108.2 +++ b/xen/include/asm-x86/x86_32/regs.h	Fri Feb 04 14:44:18 2005 +0000
   108.3 @@ -3,6 +3,9 @@
   108.4  
   108.5  #include <asm/types.h>
   108.6  
   108.7 +/* So that we can use 'l' modifier in printf-style format strings. */
   108.8 +#define u32 unsigned long
   108.9 +
  108.10  struct xen_regs
  108.11  {
  108.12      /* All saved activations contain the following fields. */
  108.13 @@ -28,28 +31,7 @@ struct xen_regs
  108.14      u32 gs;
  108.15  } __attribute__ ((packed));
  108.16  
  108.17 -enum EFLAGS {
  108.18 -    EF_CF   = 0x00000001,
  108.19 -    EF_PF   = 0x00000004,
  108.20 -    EF_AF   = 0x00000010,
  108.21 -    EF_ZF   = 0x00000040,
  108.22 -    EF_SF   = 0x00000080,
  108.23 -    EF_TF   = 0x00000100,
  108.24 -    EF_IE   = 0x00000200,
  108.25 -    EF_DF   = 0x00000400,
  108.26 -    EF_OF   = 0x00000800,
  108.27 -    EF_IOPL = 0x00003000,
  108.28 -    EF_IOPL_RING0 = 0x00000000,
  108.29 -    EF_IOPL_RING1 = 0x00001000,
  108.30 -    EF_IOPL_RING2 = 0x00002000,
  108.31 -    EF_NT   = 0x00004000,   /* nested task */
  108.32 -    EF_RF   = 0x00010000,   /* resume */
  108.33 -    EF_VM   = 0x00020000,   /* virtual mode */
  108.34 -    EF_AC   = 0x00040000,   /* alignment */
  108.35 -    EF_VIF  = 0x00080000,   /* virtual interrupt */
  108.36 -    EF_VIP  = 0x00100000,   /* virtual interrupt pending */
  108.37 -    EF_ID   = 0x00200000,   /* id */
  108.38 -};
  108.39 +#undef u32
  108.40  
  108.41  #define VM86_MODE(_r) ((_r)->eflags & EF_VM)
  108.42  #define RING_0(_r)    (((_r)->cs & 3) == 0)
   109.1 --- a/xen/include/asm-x86/x86_64/asm_defns.h	Fri Jan 28 14:53:32 2005 +0000
   109.2 +++ b/xen/include/asm-x86/x86_64/asm_defns.h	Fri Feb 04 14:44:18 2005 +0000
   109.3 @@ -1,6 +1,93 @@
   109.4  #ifndef __X86_64_ASM_DEFNS_H__
   109.5  #define __X86_64_ASM_DEFNS_H__
   109.6  
   109.7 -#define SAVE_ALL(_r) ""
   109.8 +/* Maybe auto-generate the following two cases (quoted vs. unquoted). */
   109.9 +#ifndef __ASSEMBLY__
  109.10 +
  109.11 +#define SAVE_ALL \
  109.12 +        "cld;" \
  109.13 +        "pushq %rdi;" \
  109.14 +        "pushq %rsi;" \
  109.15 +        "pushq %rdx;" \
  109.16 +        "pushq %rcx;" \
  109.17 +        "pushq %rax;" \
  109.18 +        "pushq %r8;" \
  109.19 +        "pushq %r9;" \
  109.20 +        "pushq %r10;" \
  109.21 +        "pushq %r11;" \
  109.22 +        "pushq %rbx;" \
  109.23 +        "pushq %rbp;" \
  109.24 +        "pushq %r12;" \
  109.25 +        "pushq %r13;" \
  109.26 +        "pushq %r14;" \
  109.27 +        "pushq %r15;"
  109.28 +
  109.29 +#else
  109.30 +
  109.31 +#define SAVE_ALL \
  109.32 +        cld; \
  109.33 +        pushq %rdi; \
  109.34 +        pushq %rsi; \
  109.35 +        pushq %rdx; \
  109.36 +        pushq %rcx; \
  109.37 +        pushq %rax; \
  109.38 +        pushq %r8; \
  109.39 +        pushq %r9; \
  109.40 +        pushq %r10; \
  109.41 +        pushq %r11; \
  109.42 +        pushq %rbx; \
  109.43 +        pushq %rbp; \
  109.44 +        pushq %r12; \
  109.45 +        pushq %r13; \
  109.46 +        pushq %r14; \
  109.47 +        pushq %r15;
  109.48 +
  109.49 +#endif
  109.50 +
  109.51 +#define BUILD_SMP_INTERRUPT(x,v) XBUILD_SMP_INTERRUPT(x,v)
  109.52 +#define XBUILD_SMP_INTERRUPT(x,v)\
  109.53 +asmlinkage void x(void); \
  109.54 +__asm__( \
  109.55 +    "\n"__ALIGN_STR"\n" \
  109.56 +    SYMBOL_NAME_STR(x) ":\n\t" \
  109.57 +    "pushq $0\n\t" \
  109.58 +    "movl $"#v",4(%rsp)\n\t" \
  109.59 +    SAVE_ALL \
  109.60 +    "callq "SYMBOL_NAME_STR(smp_##x)"\n\t" \
  109.61 +    "jmp ret_from_intr\n");
  109.62 +
  109.63 +#define BUILD_SMP_TIMER_INTERRUPT(x,v) XBUILD_SMP_TIMER_INTERRUPT(x,v)
  109.64 +#define XBUILD_SMP_TIMER_INTERRUPT(x,v) \
  109.65 +asmlinkage void x(struct xen_regs * regs); \
  109.66 +__asm__( \
  109.67 +"\n"__ALIGN_STR"\n" \
  109.68 +SYMBOL_NAME_STR(x) ":\n\t" \
  109.69 +    "pushq $0\n\t" \
  109.70 +    "movl $"#v",4(%rsp)\n\t" \
  109.71 +    SAVE_ALL \
  109.72 +    "movq %rsp,%rdi\n\t" \
  109.73 +    "callq "SYMBOL_NAME_STR(smp_##x)"\n\t" \
  109.74 +    "jmp ret_from_intr\n");
  109.75 +
  109.76 +#define BUILD_COMMON_IRQ() \
  109.77 +__asm__( \
  109.78 +    "\n" __ALIGN_STR"\n" \
  109.79 +    "common_interrupt:\n\t" \
  109.80 +    SAVE_ALL \
  109.81 +    "movq %rsp,%rdi\n\t" \
  109.82 +    "callq " SYMBOL_NAME_STR(do_IRQ) "\n\t" \
  109.83 +    "jmp ret_from_intr\n");
  109.84 +
  109.85 +#define IRQ_NAME2(nr) nr##_interrupt(void)
  109.86 +#define IRQ_NAME(nr) IRQ_NAME2(IRQ##nr)
  109.87 +
  109.88 +#define BUILD_IRQ(nr) \
  109.89 +asmlinkage void IRQ_NAME(nr); \
  109.90 +__asm__( \
  109.91 +"\n"__ALIGN_STR"\n" \
  109.92 +SYMBOL_NAME_STR(IRQ) #nr "_interrupt:\n\t" \
  109.93 +    "pushq $0\n\t" \
  109.94 +    "movl $"#nr",4(%rsp)\n\t" \
  109.95 +    "jmp common_interrupt");
  109.96  
  109.97  #endif /* __X86_64_ASM_DEFNS_H__ */
   110.1 --- a/xen/include/asm-x86/x86_64/current.h	Fri Jan 28 14:53:32 2005 +0000
   110.2 +++ b/xen/include/asm-x86/x86_64/current.h	Fri Feb 04 14:44:18 2005 +0000
   110.3 @@ -1,18 +1,16 @@
   110.4  #ifndef _X86_64_CURRENT_H
   110.5  #define _X86_64_CURRENT_H
   110.6  
   110.7 -#if !defined(__ASSEMBLY__)
   110.8  struct domain;
   110.9  
  110.10 -#include <asm/pda.h>
  110.11 -
  110.12  #define STACK_RESERVED \
  110.13 -    (sizeof(execution_context_t))
  110.14 +    (sizeof(execution_context_t) + sizeof(struct domain *))
  110.15  
  110.16  static inline struct exec_domain *get_current(void)
  110.17  {
  110.18      struct exec_domain *ed;
  110.19 -    ed = read_pda(pcurrent);
  110.20 +    __asm__ ( "orq %%rsp,%0; andq $~7,%0; movq (%0),%0" 
  110.21 +              : "=r" (ed) : "0" (STACK_SIZE-8) );
  110.22      return ed;
  110.23  }
  110.24   
  110.25 @@ -20,7 +18,8 @@ static inline struct exec_domain *get_cu
  110.26  
  110.27  static inline void set_current(struct exec_domain *ed)
  110.28  {
  110.29 -    write_pda(pcurrent, ed);
  110.30 +    __asm__ ( "orq %%rsp,%0; andq $~7,%0; movq %1,(%0)" 
  110.31 +              : : "r" (STACK_SIZE-8), "r" (ed) );    
  110.32  }
  110.33  
  110.34  static inline execution_context_t *get_execution_context(void)
  110.35 @@ -47,14 +46,4 @@ static inline unsigned long get_stack_to
  110.36  
  110.37  #define schedule_tail(_d) ((_d)->thread.schedule_tail)(_d)
  110.38  
  110.39 -#else
  110.40 -
  110.41 -#ifndef ASM_OFFSET_H
  110.42 -#include <asm/offset.h> 
  110.43 -#endif
  110.44 -
  110.45 -#define GET_CURRENT(reg) movq %gs:(pda_pcurrent),reg
  110.46 -
  110.47 -#endif
  110.48 -
  110.49  #endif /* !(_X86_64_CURRENT_H) */
   111.1 --- a/xen/include/asm-x86/x86_64/desc.h	Fri Jan 28 14:53:32 2005 +0000
   111.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   111.3 @@ -1,118 +0,0 @@
   111.4 -#ifndef __ARCH_DESC_H
   111.5 -#define __ARCH_DESC_H
   111.6 -
   111.7 -#define LDT_ENTRY_SIZE 16
   111.8 -
   111.9 -#define __DOUBLEFAULT_TSS_ENTRY FIRST_RESERVED_GDT_ENTRY
  111.10 -
  111.11 -#define __FIRST_PER_CPU_ENTRY (FIRST_RESERVED_GDT_ENTRY + 8)
  111.12 -
  111.13 -#define __CPU_DESC_INDEX(x,field) \
  111.14 -	((x) * sizeof(struct per_cpu_gdt) + offsetof(struct per_cpu_gdt, field) + (__FIRST_PER_CPU_ENTRY*8))
  111.15 -#define __LDT(n) (((n)<<1) + __FIRST_LDT_ENTRY)
  111.16 -
  111.17 -#define load_TR(cpu) asm volatile("ltr %w0"::"r" (__CPU_DESC_INDEX(cpu, tss)));
  111.18 -#define __load_LDT(cpu) asm volatile("lldt %w0"::"r" (__CPU_DESC_INDEX(cpu, ldt)));
  111.19 -#define clear_LDT(n)  asm volatile("lldt %w0"::"r" (0))
  111.20 -
  111.21 -/*
  111.22 - * Guest OS must provide its own code selectors, or use the one we provide. The
  111.23 - * RPL must be 1, as we only create bounce frames to ring 1. Any LDT selector
  111.24 - * value is okay. Note that checking only the RPL is insufficient: if the
  111.25 - * selector is poked into an interrupt, trap or call gate then the RPL is
  111.26 - * ignored when the gate is accessed.
  111.27 - */
  111.28 -#define VALID_SEL(_s)                                                      \
  111.29 -    (((((_s)>>3) < FIRST_RESERVED_GDT_ENTRY) ||                            \
  111.30 -      (((_s)>>3) >  LAST_RESERVED_GDT_ENTRY) ||                            \
  111.31 -      ((_s)&4)) &&                                                         \
  111.32 -     (((_s)&3) == 0))
  111.33 -#define VALID_CODESEL(_s) ((_s) == FLAT_RING3_CS || VALID_SEL(_s))
  111.34 -
  111.35 -/* These are bitmasks for the first 32 bits of a descriptor table entry. */
  111.36 -#define _SEGMENT_TYPE    (15<< 8)
  111.37 -#define _SEGMENT_S       ( 1<<12) /* System descriptor (yes iff S==0) */
  111.38 -#define _SEGMENT_DPL     ( 3<<13) /* Descriptor Privilege Level */
  111.39 -#define _SEGMENT_P       ( 1<<15) /* Segment Present */
  111.40 -#define _SEGMENT_G       ( 1<<23) /* Granularity */
  111.41 -
  111.42 -#ifndef __ASSEMBLY__
  111.43 -
  111.44 -enum { 
  111.45 -	GATE_INTERRUPT = 0xE, 
  111.46 -	GATE_TRAP = 0xF, 	
  111.47 -	GATE_CALL = 0xC,
  111.48 -}; 	
  111.49 -
  111.50 -// 16byte gate
  111.51 -struct gate_struct {          
  111.52 -	u16 offset_low;
  111.53 -	u16 segment; 
  111.54 -	unsigned ist : 3, zero0 : 5, type : 5, dpl : 2, p : 1;
  111.55 -	u16 offset_middle;
  111.56 -	u32 offset_high;
  111.57 -	u32 zero1; 
  111.58 -} __attribute__((packed));
  111.59 -
  111.60 -// 8 byte segment descriptor
  111.61 -struct desc_struct { 
  111.62 -	u16 limit0;
  111.63 -	u16 base0;
  111.64 -	unsigned base1 : 8, type : 4, s : 1, dpl : 2, p : 1;
  111.65 -	unsigned limit : 4, avl : 1, l : 1, d : 1, g : 1, base2 : 8;
  111.66 -} __attribute__((packed)); 
  111.67 -
  111.68 -// LDT or TSS descriptor in the GDT. 16 bytes.
  111.69 -struct ldttss_desc { 
  111.70 -	u16 limit0;
  111.71 -	u16 base0;
  111.72 -	unsigned base1 : 8, type : 5, dpl : 2, p : 1;
  111.73 -	unsigned limit1 : 4, zero0 : 3, g : 1, base2 : 8;
  111.74 -	u32 base3;
  111.75 -	u32 zero1; 
  111.76 -} __attribute__((packed)); 
  111.77 -
  111.78 -// Union of above structures
  111.79 -union desc_union {
  111.80 -	struct desc_struct seg;
  111.81 -	struct ldttss_desc ldttss;
  111.82 -	struct gate_struct gate;
  111.83 -};
  111.84 -
  111.85 -struct per_cpu_gdt {
  111.86 -	struct ldttss_desc tss;
  111.87 -	struct ldttss_desc ldt; 
  111.88 -} __cacheline_aligned; 
  111.89 -
  111.90 -
  111.91 -struct Xgt_desc_struct {
  111.92 -	unsigned short size;
  111.93 -	unsigned long address;
  111.94 -} __attribute__((packed));
  111.95 -
  111.96 -extern __u8 gdt_table[];
  111.97 -extern __u8 gdt_end[];
  111.98 -extern union desc_union *gdt; 
  111.99 -
 111.100 -extern struct per_cpu_gdt gdt_cpu_table[]; 
 111.101 -
 111.102 -#define PTR_LOW(x) ((unsigned long)(x) & 0xFFFF) 
 111.103 -#define PTR_MIDDLE(x) (((unsigned long)(x) >> 16) & 0xFFFF)
 111.104 -#define PTR_HIGH(x) ((unsigned long)(x) >> 32)
 111.105 -
 111.106 -enum { 
 111.107 -	DESC_TSS = 0x9,
 111.108 -	DESC_LDT = 0x2,
 111.109 -}; 
 111.110 -
 111.111 -extern struct gate_struct *idt;
 111.112 -
 111.113 -#define idt_descr (*(struct Xgt_desc_struct *)((char *)&idt - 2))
 111.114 -#define gdt_descr (*(struct Xgt_desc_struct *)((char *)&gdt - 2))
 111.115 -
 111.116 -extern void set_intr_gate(unsigned int irq, void * addr);
 111.117 -extern void set_tss_desc(unsigned int n, void *addr);
 111.118 -
 111.119 -#endif /* !__ASSEMBLY__ */
 111.120 -
 111.121 -#endif
   112.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   112.2 +++ b/xen/include/asm-x86/x86_64/domain_page.h	Fri Feb 04 14:44:18 2005 +0000
   112.3 @@ -0,0 +1,13 @@
   112.4 +/******************************************************************************
   112.5 + * domain_page.h
   112.6 + * 
   112.7 + * This is a trivial no-op on x86/64, where we can 1:1 map all RAM.
   112.8 + */
   112.9 +
  112.10 +#ifndef __ASM_DOMAIN_PAGE_H__
  112.11 +#define __ASM_DOMAIN_PAGE_H__
  112.12 +
  112.13 +#define map_domain_mem(_pa)   phys_to_virt(_pa)
  112.14 +#define unmap_domain_mem(_va) ((void)(_va))
  112.15 +
  112.16 +#endif /* __ASM_DOMAIN_PAGE_H__ */
   113.1 --- a/xen/include/asm-x86/x86_64/regs.h	Fri Jan 28 14:53:32 2005 +0000
   113.2 +++ b/xen/include/asm-x86/x86_64/regs.h	Fri Feb 04 14:44:18 2005 +0000
   113.3 @@ -1,114 +1,39 @@
   113.4  #ifndef _X86_64_REGS_H
   113.5  #define _X86_64_REGS_H
   113.6  
   113.7 -#if defined(__ASSEMBLY__) || defined(__FRAME_OFFSETS) 
   113.8 -#define R15 0
   113.9 -#define R14 8
  113.10 -#define R13 16
  113.11 -#define R12 24
  113.12 -#define RBP 36
  113.13 -#define RBX 40
  113.14 -/* arguments: interrupts/hypercalls only save upto here*/
  113.15 -#define R11 48
  113.16 -#define R10 56	
  113.17 -#define R9 64
  113.18 -#define R8 72
  113.19 -#define RAX 80
  113.20 -#define RCX 88
  113.21 -#define RDX 96
  113.22 -#define RSI 104
  113.23 -#define RDI 112
  113.24 -#define ORIG_RAX 120       /* = ERROR */ 
  113.25 -/* end of arguments */ 	
  113.26 -/* cpu exception frame or undefined in case of fast hypercall. */
  113.27 -#define RIP 128
  113.28 -#define CS 136
  113.29 -#define EFLAGS 144
  113.30 -#define RSP 152
  113.31 -#define SS 160
  113.32 -#define ARGOFFSET R11
  113.33 -#endif /* __ASSEMBLY__ */
  113.34 -
  113.35 -/* top of stack page */ 
  113.36 -#define FRAME_SIZE 168
  113.37 -
  113.38 -#define PTRACE_SETOPTIONS         21
  113.39 +#include <asm/types.h>
  113.40  
  113.41 -/* options set using PTRACE_SETOPTIONS */
  113.42 -#define PTRACE_O_TRACESYSGOOD     0x00000001
  113.43 -
  113.44 -/* Dummy values for ptrace */ 
  113.45 -#define FS 1000 
  113.46 -#define GS 1008
  113.47 -
  113.48 -#ifndef __ASSEMBLY__ 
  113.49 +struct xen_regs
  113.50 +{
  113.51 +    u64 r15;
  113.52 +    u64 r14;
  113.53 +    u64 r13;
  113.54 +    u64 r12;
  113.55 +    union { u64 rbp; u32 ebp; } __attribute__ ((packed));
  113.56 +    union { u64 rbx; u32 ebx; } __attribute__ ((packed));
  113.57 +    /* NB. Above here is C callee-saves. */
  113.58 +    u64 r11;
  113.59 +    u64 r10;	
  113.60 +    u64 r9;
  113.61 +    u64 r8;
  113.62 +    union { u64 rax; u32 eax; } __attribute__ ((packed));
  113.63 +    union { u64 rcx; u32 ecx; } __attribute__ ((packed));
  113.64 +    union { u64 rdx; u32 edx; } __attribute__ ((packed));
  113.65 +    union { u64 rsi; u32 esi; } __attribute__ ((packed));
  113.66 +    union { u64 rdi; u32 edi; } __attribute__ ((packed));
  113.67 +    u32 error_code;
  113.68 +    u32 entry_vector;
  113.69 +    union { u64 rip; u64 eip; } __attribute__ ((packed));
  113.70 +    u64 cs;
  113.71 +    union { u64 rflags; u64 eflags; } __attribute__ ((packed));
  113.72 +    union { u64 rsp; u64 esp; } __attribute__ ((packed));
  113.73 +    u64 ss;
  113.74 +} __attribute__ ((packed));
  113.75  
  113.76 -struct xen_regs {
  113.77 -	unsigned long r15;
  113.78 -	unsigned long r14;
  113.79 -	unsigned long r13;
  113.80 -	unsigned long r12;
  113.81 -	unsigned long rbp;
  113.82 -	unsigned long rbx;
  113.83 -/* arguments: non interrupts/hypercalls only save upto here*/
  113.84 - 	unsigned long r11;
  113.85 -	unsigned long r10;	
  113.86 -	unsigned long r9;
  113.87 -	unsigned long r8;
  113.88 -	unsigned long rax;
  113.89 -	unsigned long rcx;
  113.90 -	unsigned long rdx;
  113.91 -	unsigned long rsi;
  113.92 -	unsigned long rdi;
  113.93 -	unsigned long orig_rax;
  113.94 -/* end of arguments */ 	
  113.95 -/* cpu exception frame or undefined */
  113.96 -	unsigned long rip;
  113.97 -	unsigned long cs;
  113.98 -	unsigned long eflags; 
  113.99 -	unsigned long rsp; 
 113.100 -	unsigned long ss;
 113.101 -/* top of stack page */ 
 113.102 -};
 113.103 +#define VM86_MODE(_r) ((_r)->eflags & EF_VM)
 113.104 +#define RING_0(_r)    (((_r)->cs & 3) == 0)
 113.105 +#define RING_1(_r)    (((_r)->cs & 3) == 1)
 113.106 +#define RING_2(_r)    (((_r)->cs & 3) == 2)
 113.107 +#define RING_3(_r)    (((_r)->cs & 3) == 3)
 113.108  
 113.109  #endif
 113.110 -
 113.111 -/* Arbitrarily choose the same ptrace numbers as used by the Sparc code. */
 113.112 -#define PTRACE_GETREGS            12
 113.113 -#define PTRACE_SETREGS            13
 113.114 -#define PTRACE_GETFPREGS          14
 113.115 -#define PTRACE_SETFPREGS          15
 113.116 -#define PTRACE_GETFPXREGS         18
 113.117 -#define PTRACE_SETFPXREGS         19
 113.118 -
 113.119 -#if !defined(__ASSEMBLY__) 
 113.120 -
 113.121 -#define instruction_pointer(regs) ((regs)->rip)
 113.122 -extern void show_regs(struct xen_regs *);
 113.123 -
 113.124 -enum {
 113.125 -        EF_CF   = 0x00000001,
 113.126 -        EF_PF   = 0x00000004,
 113.127 -        EF_AF   = 0x00000010,
 113.128 -        EF_ZF   = 0x00000040,
 113.129 -        EF_SF   = 0x00000080,
 113.130 -        EF_TF   = 0x00000100,
 113.131 -        EF_IE   = 0x00000200,
 113.132 -        EF_DF   = 0x00000400,
 113.133 -        EF_OF   = 0x00000800,
 113.134 -        EF_IOPL = 0x00003000,
 113.135 -        EF_IOPL_RING0 = 0x00000000,
 113.136 -        EF_IOPL_RING1 = 0x00001000,
 113.137 -        EF_IOPL_RING2 = 0x00002000,
 113.138 -        EF_NT   = 0x00004000,   /* nested task */
 113.139 -        EF_RF   = 0x00010000,   /* resume */
 113.140 -        EF_VM   = 0x00020000,   /* virtual mode */
 113.141 -        EF_AC   = 0x00040000,   /* alignment */
 113.142 -        EF_VIF  = 0x00080000,   /* virtual interrupt */
 113.143 -        EF_VIP  = 0x00100000,   /* virtual interrupt pending */
 113.144 -        EF_ID   = 0x00200000,   /* id */
 113.145 -};
 113.146 -
 113.147 -#endif
 113.148 -
 113.149 -#endif
   114.1 --- a/xen/include/public/arch-x86_32.h	Fri Jan 28 14:53:32 2005 +0000
   114.2 +++ b/xen/include/public/arch-x86_32.h	Fri Feb 04 14:44:18 2005 +0000
   114.3 @@ -137,11 +137,13 @@ typedef struct {
   114.4  } PACKED full_execution_context_t;
   114.5  
   114.6  typedef struct {
   114.7 -    u64 mfn_to_pfn_start;      /* MFN of start of m2p table */
   114.8 -    u64 pfn_to_mfn_frame_list; /* MFN of a table of MFNs that 
   114.9 -				  make up p2m table */
  114.10 +    /* MFN of a table of MFNs that make up p2m table */
  114.11 +    u64 pfn_to_mfn_frame_list;
  114.12  } PACKED arch_shared_info_t;
  114.13  
  114.14 +typedef struct {
  114.15 +} PACKED arch_vcpu_info_t;
  114.16 +
  114.17  #define ARCH_HAS_FAST_TRAP
  114.18  
  114.19  #endif
   115.1 --- a/xen/include/public/arch-x86_64.h	Fri Jan 28 14:53:32 2005 +0000
   115.2 +++ b/xen/include/public/arch-x86_64.h	Fri Feb 04 14:44:18 2005 +0000
   115.3 @@ -30,7 +30,7 @@
   115.4   * NB. The reserved range is inclusive (that is, both FIRST_RESERVED_GDT_ENTRY
   115.5   * and LAST_RESERVED_GDT_ENTRY are reserved).
   115.6   */
   115.7 -#define NR_RESERVED_GDT_ENTRIES    40 
   115.8 +#define NR_RESERVED_GDT_ENTRIES    72
   115.9  #define FIRST_RESERVED_GDT_ENTRY   256
  115.10  #define LAST_RESERVED_GDT_ENTRY    \
  115.11    (FIRST_RESERVED_GDT_ENTRY + NR_RESERVED_GDT_ENTRIES - 1)
  115.12 @@ -44,15 +44,22 @@
  115.13  
  115.14  #define FLAT_RING3_CS32 0x0823  /* GDT index 260 */
  115.15  #define FLAT_RING3_CS64 0x082b  /* GDT index 261 */
  115.16 -#define FLAT_RING3_DS   0x0833  /* GDT index 262 */
  115.17 +#define FLAT_RING3_DS32 0x0833  /* GDT index 262 */
  115.18 +#define FLAT_RING3_DS64 0x0000
  115.19  
  115.20 -#define FLAT_GUESTOS_DS   FLAT_RING3_DS
  115.21 -#define FLAT_GUESTOS_CS   FLAT_RING3_CS64
  115.22 +#define FLAT_GUESTOS_DS64 FLAT_RING3_DS64
  115.23 +#define FLAT_GUESTOS_DS32 FLAT_RING3_DS32
  115.24 +#define FLAT_GUESTOS_DS   FLAT_GUESTOS_DS64
  115.25 +#define FLAT_GUESTOS_CS64 FLAT_RING3_CS64
  115.26  #define FLAT_GUESTOS_CS32 FLAT_RING3_CS32
  115.27 +#define FLAT_GUESTOS_CS   FLAT_GUESTOS_CS64
  115.28  
  115.29 -#define FLAT_USER_DS      FLAT_RING3_DS
  115.30 -#define FLAT_USER_CS      FLAT_RING3_CS64
  115.31 -#define FLAT_USER_CS32    FLAT_RING3_CS32
  115.32 +#define FLAT_USER_DS64 FLAT_RING3_DS64
  115.33 +#define FLAT_USER_DS32 FLAT_RING3_DS32
  115.34 +#define FLAT_USER_DS   FLAT_USER_DS64
  115.35 +#define FLAT_USER_CS64 FLAT_RING3_CS64
  115.36 +#define FLAT_USER_CS32 FLAT_RING3_CS32
  115.37 +#define FLAT_USER_CS   FLAT_USER_CS64
  115.38  
  115.39  /* And the trap vector is... */
  115.40  #define TRAP_INSTR "syscall"
  115.41 @@ -89,22 +96,27 @@ typedef struct
  115.42      unsigned long r14;
  115.43      unsigned long r13;
  115.44      unsigned long r12;
  115.45 -    unsigned long rbp;
  115.46 -    unsigned long rbx;
  115.47 +    union { unsigned long rbp, ebp; } PACKED;
  115.48 +    union { unsigned long rbx, ebx; } PACKED;
  115.49      unsigned long r11;
  115.50      unsigned long r10;
  115.51      unsigned long r9;
  115.52      unsigned long r8;
  115.53 -    unsigned long rax;
  115.54 -    unsigned long rcx;
  115.55 -    unsigned long rdx;
  115.56 -    unsigned long rsi;
  115.57 -    unsigned long rdi;
  115.58 -    unsigned long rip;
  115.59 +    union { unsigned long rax, eax; } PACKED;
  115.60 +    union { unsigned long rcx, ecx; } PACKED;
  115.61 +    union { unsigned long rdx, edx; } PACKED;
  115.62 +    union { unsigned long rsi, esi; } PACKED;
  115.63 +    union { unsigned long rdi, edi; } PACKED;
  115.64 +    unsigned long _unused;
  115.65 +    union { unsigned long rip, eip; } PACKED;
  115.66      unsigned long cs;
  115.67 -    unsigned long eflags;
  115.68 -    unsigned long rsp;
  115.69 +    union { unsigned long rflags, eflags; } PACKED;
  115.70 +    union { unsigned long rsp, esp; } PACKED;
  115.71      unsigned long ss;
  115.72 +    unsigned long es;
  115.73 +    unsigned long ds;
  115.74 +    unsigned long fs;
  115.75 +    unsigned long gs;
  115.76  } PACKED execution_context_t;
  115.77  
  115.78  typedef u64 tsc_timestamp_t; /* RDTSC timestamp */
  115.79 @@ -132,11 +144,13 @@ typedef struct {
  115.80  } PACKED full_execution_context_t;
  115.81  
  115.82  typedef struct {
  115.83 -    u64 mfn_to_pfn_start;      /* MFN of start of m2p table */
  115.84 -    u64 pfn_to_mfn_frame_list; /* MFN of a table of MFNs that 
  115.85 -				  make up p2m table */
  115.86 +    /* MFN of a table of MFNs that make up p2m table */
  115.87 +    u64 pfn_to_mfn_frame_list;
  115.88  } PACKED arch_shared_info_t;
  115.89  
  115.90 +typedef struct {
  115.91 +} PACKED arch_vcpu_info_t;
  115.92 +
  115.93  #endif /* !__ASSEMBLY__ */
  115.94  
  115.95  #endif
   116.1 --- a/xen/include/public/io/domain_controller.h	Fri Jan 28 14:53:32 2005 +0000
   116.2 +++ b/xen/include/public/io/domain_controller.h	Fri Feb 04 14:44:18 2005 +0000
   116.3 @@ -489,9 +489,11 @@ typedef struct {
   116.4      u32        netif_handle;  /*  4: Domain-specific interface handle.   */
   116.5      u8         mac[6];        /*  8 */
   116.6      u16        __pad1;        /* 14 */
   116.7 +    u8         be_mac[6];     /* 16 */
   116.8 +    u16        __pad2;        /* 22 */
   116.9      /* OUT */
  116.10 -    u32        status;        /* 16 */
  116.11 -} PACKED netif_be_create_t; /* 20 bytes */
  116.12 +    u32        status;        /* 24 */
  116.13 +} PACKED netif_be_create_t; /* 28 bytes */
  116.14  
  116.15  /*
  116.16   * CMSG_NETIF_BE_DESTROY:
   117.1 --- a/xen/include/public/xen.h	Fri Jan 28 14:53:32 2005 +0000
   117.2 +++ b/xen/include/public/xen.h	Fri Feb 04 14:44:18 2005 +0000
   117.3 @@ -257,7 +257,7 @@ typedef struct
   117.4   * Per-VCPU information goes here. This will be cleaned up more when Xen 
   117.5   * actually supports multi-VCPU guests.
   117.6   */
   117.7 -typedef struct vcpu_info_st
   117.8 +typedef struct
   117.9  {
  117.10      /*
  117.11       * 'evtchn_upcall_pending' is written non-zero by Xen to indicate
  117.12 @@ -284,11 +284,12 @@ typedef struct vcpu_info_st
  117.13       * an upcall activation. The mask is cleared when the VCPU requests
  117.14       * to block: this avoids wakeup-waiting races.
  117.15       */
  117.16 -    u8 evtchn_upcall_pending;
  117.17 -    u8 evtchn_upcall_mask;
  117.18 +    u8 evtchn_upcall_pending;           /* 0 */
  117.19 +    u8 evtchn_upcall_mask;              /* 1 */
  117.20      u8 pad0, pad1;
  117.21      u32 evtchn_pending_sel;             /* 4 */
  117.22 -} PACKED vcpu_info_t;                   /* 8 */
  117.23 +    arch_vcpu_info_t arch;              /* 8 */
  117.24 +} PACKED vcpu_info_t;                   /* 8 + arch */
  117.25  
  117.26  /*
  117.27   * Xen/guestos shared data -- pointer provided in start_info.
   118.1 --- a/xen/include/xen/elf.h	Fri Jan 28 14:53:32 2005 +0000
   118.2 +++ b/xen/include/xen/elf.h	Fri Feb 04 14:44:18 2005 +0000
   118.3 @@ -528,4 +528,8 @@ struct domain_setup_info;
   118.4  extern int loadelfimage(char *);
   118.5  extern int parseelfimage(char *, unsigned long, struct domain_setup_info *);
   118.6  
   118.7 +#ifdef Elf_Ehdr
   118.8 +extern int elf_sanity_check(Elf_Ehdr *ehdr);
   118.9 +#endif
  118.10 +
  118.11  #endif /* __XEN_ELF_H__ */
   119.1 --- a/xen/include/xen/keyhandler.h	Fri Jan 28 14:53:32 2005 +0000
   119.2 +++ b/xen/include/xen/keyhandler.h	Fri Feb 04 14:44:18 2005 +0000
   119.3 @@ -10,7 +10,7 @@
   119.4  #ifndef __XEN_KEYHANDLER_H__
   119.5  #define __XEN_KEYHANDLER_H__
   119.6  
   119.7 -struct xen_regs;
   119.8 +#include <asm/regs.h>
   119.9  
  119.10  /*
  119.11   * Register a callback function for key @key. The callback occurs in
   120.1 --- a/xen/include/xen/sched.h	Fri Jan 28 14:53:32 2005 +0000
   120.2 +++ b/xen/include/xen/sched.h	Fri Feb 04 14:44:18 2005 +0000
   120.3 @@ -216,8 +216,8 @@ extern struct domain *do_createdomain(
   120.4  extern int construct_dom0(struct domain *d, 
   120.5                            unsigned long alloc_start,
   120.6                            unsigned long alloc_end,
   120.7 -                          char *image_start, unsigned long image_len, 
   120.8 -                          char *initrd_start, unsigned long initrd_len,
   120.9 +                          unsigned long image_start, unsigned long image_len, 
  120.10 +                          unsigned long initrd_start, unsigned long initrd_len,
  120.11                            char *cmdline);
  120.12  extern int final_setup_guestos(struct domain *d, dom0_builddomain_t *);
  120.13  
   121.1 --- a/xen/include/xen/slab.h	Fri Jan 28 14:53:32 2005 +0000
   121.2 +++ b/xen/include/xen/slab.h	Fri Feb 04 14:44:18 2005 +0000
   121.3 @@ -18,6 +18,7 @@ typedef struct xmem_cache_s xmem_cache_t
   121.4  
   121.5  #include <xen/mm.h>
   121.6  #include <xen/cache.h>
   121.7 +#include <xen/types.h>
   121.8  
   121.9  /* Flags to pass to xmem_cache_create(). */
  121.10  /* NB. The first 3 are only valid when built with SLAB_DEBUG_SUPPORT. */
  121.11 @@ -45,13 +46,24 @@ extern int xmem_cache_shrink(xmem_cache_
  121.12  extern void *xmem_cache_alloc(xmem_cache_t *);
  121.13  extern void xmem_cache_free(xmem_cache_t *, void *);
  121.14  
  121.15 -extern void *xmalloc(size_t);
  121.16 +extern void *_xmalloc(size_t);
  121.17  extern void xfree(const void *);
  121.18  
  121.19  extern int xmem_cache_reap(void);
  121.20  
  121.21  extern void dump_slabinfo();
  121.22  
  121.23 +/* Allocate space for typed object. */
  121.24 +#define xmalloc(_type) ((_type *)_xmalloc(sizeof(_type)))
  121.25 +
  121.26 +/* Allocate space for array of typed objects. */
  121.27 +#define xmalloc_array(_type, _num)                 \
  121.28 +((_type *)(((_num) > (UINT_MAX / sizeof(_type))) ? \
  121.29 +           NULL : _xmalloc((_num) * sizeof(_type))))
  121.30 +
  121.31 +/* Allocate untyped storage. */
  121.32 +#define xmalloc_bytes(_bytes) (_xmalloc(_bytes))
  121.33 +
  121.34  #endif /* __ARCH_HAS_SLAB_ALLOCATOR */
  121.35  
  121.36  #endif /* __SLAB_H__ */
   122.1 --- a/xen/include/xen/time.h	Fri Jan 28 14:53:32 2005 +0000
   122.2 +++ b/xen/include/xen/time.h	Fri Feb 04 14:44:18 2005 +0000
   122.3 @@ -29,6 +29,7 @@
   122.4  
   122.5  #include <xen/types.h>
   122.6  #include <public/xen.h>
   122.7 +#include <asm/time.h>
   122.8  
   122.9  extern int init_xen_time();
  122.10