direct-io.hg

changeset 3793:2d4c4c4574f2

bitkeeper revision 1.1183 (420cc313TZKdpM4_m9WvFiEqZsQ13w)

Merge douglas.cl.cam.ac.uk:/auto/groups/xeno-xenod/BK/xen-unstable.bk
into douglas.cl.cam.ac.uk:/local/scratch/sos22/xendbng/xen-unstable.bk
author sos22@douglas.cl.cam.ac.uk
date Fri Feb 11 14:37:07 2005 +0000 (2005-02-11)
parents c31ea2f7dd9e 2686c08089bb
children 50e6fb796ba1
files .rootkeys BitKeeper/etc/ignore extras/mini-os/Makefile extras/mini-os/entry.S extras/mini-os/h/hypervisor.h extras/mini-os/h/mm.h extras/mini-os/h/os.h extras/mini-os/head.S extras/mini-os/kernel.c extras/mini-os/lib/math.c extras/mini-os/minios-x86_32.lds extras/mini-os/minios-x86_64.lds extras/mini-os/minios.lds extras/mini-os/traps.c extras/mini-os/x86_32.S extras/mini-os/x86_64.S xen/arch/x86/traps.c xen/arch/x86/x86_32/entry.S xen/arch/x86/x86_64/entry.S xen/include/asm-x86/x86_32/regs.h xen/include/asm-x86/x86_64/regs.h xen/include/public/arch-x86_64.h
line diff
     1.1 --- a/.rootkeys	Fri Feb 11 13:06:19 2005 +0000
     1.2 +++ b/.rootkeys	Fri Feb 11 14:37:07 2005 +0000
     1.3 @@ -25,7 +25,6 @@ 3f9e7d564bWFB-Czjv1qdmE6o0GqNg docs/src/
     1.4  410144afnSd2Yw68AHGO5gXu2m3y6A docs/src/user.tex
     1.5  3f815144d1vI2777JI-dO4wk49Iw7g extras/mini-os/Makefile
     1.6  3f815144zTnCV5591ulIJQrpe5b-5Q extras/mini-os/README
     1.7 -3f815144wiiDekmfMl9LIPIvhR83Uw extras/mini-os/entry.S
     1.8  3f815144r7AHj8GPvc3Nl1L9OSsWIg extras/mini-os/events.c
     1.9  3f815144h-Chna6E38yo40jqU95G1Q extras/mini-os/h/events.h
    1.10  3f8151445bYdgThGHQPeOW49PsrJ_A extras/mini-os/h/hypervisor.h
    1.11 @@ -34,17 +33,19 @@ 3f81514437EzzRWAnZl4_Ej1oznMjg extras/mi
    1.12  3f815144nbSjjT1h4m99-QPbeSWY0Q extras/mini-os/h/os.h
    1.13  3f815144L1t0AevJt2JDXPegv6JTrw extras/mini-os/h/time.h
    1.14  3f815144UxddtL0ICCKisN-NDHNFaA extras/mini-os/h/types.h
    1.15 -3f815145W2mamPMclRLOzm5B38vWUQ extras/mini-os/head.S
    1.16  3f815145LqcH11TCEZbAvcjarckkJw extras/mini-os/hypervisor.c
    1.17  3f815145vwnmxhCwN7dMRWv_XFtXbg extras/mini-os/kernel.c
    1.18  3f8151451k5emQAlRe80JdIvfSN4VA extras/mini-os/lib/malloc.c
    1.19  3f815145Mb9WSKjOPsYTLsPIvPyy4Q extras/mini-os/lib/math.c
    1.20  3f8151454rEuPjN74V2Bcu65RLnM-Q extras/mini-os/lib/printf.c
    1.21  3f815145MQZrUJV0iRmTK2KIhwB2wg extras/mini-os/lib/string.c
    1.22 -3f815145AYE58Kpmsj5U7oHDpVDZJA extras/mini-os/minios.lds
    1.23 +3f815145AYE58Kpmsj5U7oHDpVDZJA extras/mini-os/minios-x86_32.lds
    1.24 +420c983dKBm6a2-sM04QzaaTy55crw extras/mini-os/minios-x86_64.lds
    1.25  3f815145CB8XdPUqsmhAjSDFuwOoqA extras/mini-os/mm.c
    1.26  3f815145vGYx1WY79voKkZB9yKwJKQ extras/mini-os/time.c
    1.27  3f815145xlKBAQmal9oces3G_Mvxqw extras/mini-os/traps.c
    1.28 +3f815145W2mamPMclRLOzm5B38vWUQ extras/mini-os/x86_32.S
    1.29 +420c983dAE5qEtJMI6wHAQnHVJ1r2g extras/mini-os/x86_64.S
    1.30  4187ca95_eQN62ugV1zliQcfzXrHnw install.sh
    1.31  3e5a4e6589G-U42lFKs43plskXoFxQ linux-2.4.29-xen-sparse/Makefile
    1.32  3e5a4e65IEPjnWPZ5w3TxS5scV8Ewg linux-2.4.29-xen-sparse/arch/xen/Makefile
     2.1 --- a/BitKeeper/etc/ignore	Fri Feb 11 13:06:19 2005 +0000
     2.2 +++ b/BitKeeper/etc/ignore	Fri Feb 11 14:37:07 2005 +0000
     2.3 @@ -44,7 +44,8 @@ docs/user/internals.pl
     2.4  docs/user/labels.pl
     2.5  docs/user/user.css
     2.6  docs/user/user.html
     2.7 -extras/mini-os/h/hypervisor-ifs
     2.8 +extras/mini-os/h/xen-public
     2.9 +extras/mini-os/mini-os.*
    2.10  install/*
    2.11  linux-*-xen0/*
    2.12  linux-*-xenU/*
    2.13 @@ -91,7 +92,7 @@ xen/drivers/pci/gen-devlist
    2.14  xen/figlet/figlet
    2.15  xen/include/asm
    2.16  xen/include/asm-*/asm-offsets.h
    2.17 -xen/include/hypervisor-ifs/arch
    2.18 +xen/include/public/public
    2.19  xen/include/xen/*.new
    2.20  xen/include/xen/banner.h
    2.21  xen/include/xen/compile.h
     3.1 --- a/extras/mini-os/Makefile	Fri Feb 11 13:06:19 2005 +0000
     3.2 +++ b/extras/mini-os/Makefile	Fri Feb 11 14:37:07 2005 +0000
     3.3 @@ -2,31 +2,44 @@
     3.4  CC := gcc
     3.5  LD := ld
     3.6  
     3.7 -# Linker should relocate monitor to this address
     3.8 -MONITOR_BASE := 0xE0100000
     3.9 +TARGET_ARCH := $(shell uname -m | sed -e s/i.86/x86_32/)
    3.10  
    3.11  # NB. '-Wcast-qual' is nasty, so I omitted it.
    3.12 -CFLAGS := -fno-builtin -O3 -Wall -Ih/ -Wredundant-decls
    3.13 -CFLAGS += -Wstrict-prototypes -Wnested-externs -Wpointer-arith -Winline -ansi
    3.14 +CFLAGS := -fno-builtin -O3 -Wall -Ih/ -Wredundant-decls -Wno-format
    3.15 +CFLAGS += -Wstrict-prototypes -Wnested-externs -Wpointer-arith -Winline
    3.16 +
    3.17 +ifeq ($(TARGET_ARCH),x86_32)
    3.18 +CFLAGS += -m32 -march=i686
    3.19 +LDFLAGS := -m elf_i386
    3.20 +endif
    3.21 +
    3.22 +ifeq ($(TARGET_ARCH),x86_64)
    3.23 +CFLAGS += -m64 -mno-red-zone -fpic -fno-reorder-blocks
    3.24 +CFLAGS += -fno-asynchronous-unwind-tables
    3.25 +LDFLAGS := -m elf_x86_64
    3.26 +endif
    3.27  
    3.28  TARGET := mini-os
    3.29  
    3.30 -LOBJS := lib/malloc.o lib/math.o lib/printf.o lib/string.o 
    3.31 -OBJS  := entry.o kernel.o traps.o hypervisor.o mm.o events.o time.o ${LOBJS}
    3.32 +OBJS := $(TARGET_ARCH).o
    3.33 +OBJS += $(patsubst %.c,%.o,$(wildcard *.c))
    3.34 +OBJS += $(patsubst %.c,%.o,$(wildcard lib/*.c))
    3.35  
    3.36 -HINTF := h/xen-public/xen.h
    3.37 -HDRS  :=  h/os.h h/types.h h/hypervisor.h h/mm.h h/events.h h/time.h h/lib.h
    3.38 -HDRS  += $(HINTF)
    3.39 +OBJS := $(subst events.o,,$(OBJS))
    3.40 +OBJS := $(subst hypervisor.o,,$(OBJS))
    3.41 +OBJS := $(subst time.o,,$(OBJS))
    3.42 +
    3.43 +HDRS := $(wildcard h/*.h)
    3.44 +HDRS += $(wildcard h/xen-public/*.h)
    3.45  
    3.46  default: $(TARGET)
    3.47  
    3.48  xen-public:
    3.49 -	[ -e h/xen-public] || ln -sf ../../../xen/include/public h/xen-public
    3.50 +	[ -e h/xen-public ] || ln -sf ../../../xen/include/public h/xen-public
    3.51  
    3.52 -$(TARGET): xen-public head.o $(OBJS)
    3.53 -	$(LD) -N -T minios.lds head.o $(OBJS) -o $@.elf
    3.54 -	objcopy -R .note -R .comment $@.elf $@
    3.55 -	gzip -f -9 -c $@ >$@.gz
    3.56 +$(TARGET): xen-public $(OBJS)
    3.57 +	$(LD) -N -T minios-$(TARGET_ARCH).lds $(OBJS) -o $@.elf
    3.58 +	gzip -f -9 -c $@.elf >$@.gz
    3.59  
    3.60  clean:
    3.61  	find . -type f -name '*.o' | xargs rm -f
    3.62 @@ -38,4 +51,3 @@ clean:
    3.63  
    3.64  %.o: %.S $(HDRS) Makefile
    3.65  	$(CC) $(CFLAGS) -D__ASSEMBLY__ -c $< -o $@
    3.66 -
     4.1 --- a/extras/mini-os/entry.S	Fri Feb 11 13:06:19 2005 +0000
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,265 +0,0 @@
     4.4 -        
     4.5 -#include <os.h>
     4.6 -
     4.7 -ES		= 0x20
     4.8 -ORIG_EAX	= 0x24
     4.9 -EIP		= 0x28
    4.10 -CS		= 0x2C
    4.11 -
    4.12 -#define ENTRY(X) .globl X ; X :
    4.13 -
    4.14 -#define SAVE_ALL \
    4.15 -	cld; \
    4.16 -	pushl %es; \
    4.17 -	pushl %ds; \
    4.18 -	pushl %eax; \
    4.19 -	pushl %ebp; \
    4.20 -	pushl %edi; \
    4.21 -	pushl %esi; \
    4.22 -	pushl %edx; \
    4.23 -	pushl %ecx; \
    4.24 -	pushl %ebx; \
    4.25 -	movl $(__KERNEL_DS),%edx; \
    4.26 -	movl %edx,%ds; \
    4.27 -	movl %edx,%es;
    4.28 -
    4.29 -#define RESTORE_ALL	\
    4.30 -	popl %ebx;	\
    4.31 -	popl %ecx;	\
    4.32 -	popl %edx;	\
    4.33 -	popl %esi;	\
    4.34 -	popl %edi;	\
    4.35 -	popl %ebp;	\
    4.36 -	popl %eax;	\
    4.37 -	popl %ds;	\
    4.38 -	popl %es;	\
    4.39 -	addl $4,%esp;	\
    4.40 -	iret;		\
    4.41 -
    4.42 -ENTRY(divide_error)
    4.43 -	pushl $0		# no error code
    4.44 -	pushl $do_divide_error
    4.45 -do_exception:
    4.46 -	pushl %ds
    4.47 -	pushl %eax
    4.48 -	xorl %eax,%eax
    4.49 -	pushl %ebp
    4.50 -	pushl %edi
    4.51 -	pushl %esi
    4.52 -	pushl %edx
    4.53 -	decl %eax			# eax = -1
    4.54 -	pushl %ecx
    4.55 -	pushl %ebx
    4.56 -	cld
    4.57 -	movl %es,%ecx
    4.58 -	movl ORIG_EAX(%esp), %esi	# get the error code
    4.59 -	movl ES(%esp), %edi		# get the function address
    4.60 -	movl %eax, ORIG_EAX(%esp)
    4.61 -	movl %ecx, ES(%esp)
    4.62 -	movl %esp,%edx
    4.63 -	pushl %esi			# push the error code
    4.64 -	pushl %edx			# push the pt_regs pointer
    4.65 -	movl $(__KERNEL_DS),%edx
    4.66 -	movl %edx,%ds
    4.67 -	movl %edx,%es
    4.68 -	call *%edi
    4.69 -	addl $8,%esp
    4.70 -
    4.71 -        
    4.72 -ret_from_exception:
    4.73 -        movb CS(%esp),%cl
    4.74 -	test $2,%cl          # slow return to ring 2 or 3
    4.75 -	jne  safesti
    4.76 -        RESTORE_ALL
    4.77 -
    4.78 -# A note on the "critical region" in our callback handler.
    4.79 -# We want to avoid stacking callback handlers due to events occurring
    4.80 -# during handling of the last event. To do this, we keep events disabled
    4.81 -# until weve done all processing. HOWEVER, we must enable events before
    4.82 -# popping the stack frame (cant be done atomically) and so it would still
    4.83 -# be possible to get enough handler activations to overflow the stack.
    4.84 -# Although unlikely, bugs of that kind are hard to track down, so wed
    4.85 -# like to avoid the possibility.
    4.86 -# So, on entry to the handler we detect whether we interrupted an
    4.87 -# existing activation in its critical region -- if so, we pop the current
    4.88 -# activation and restart the handler using the previous one.
    4.89 -ENTRY(hypervisor_callback)
    4.90 -        pushl %eax
    4.91 -        SAVE_ALL
    4.92 -        movl EIP(%esp),%eax
    4.93 -        cmpl $scrit,%eax
    4.94 -        jb   11f
    4.95 -        cmpl $ecrit,%eax
    4.96 -        jb   critical_region_fixup
    4.97 -11:     push %esp
    4.98 -        call do_hypervisor_callback
    4.99 -        add  $4,%esp
   4.100 -        movl HYPERVISOR_shared_info,%esi
   4.101 -        xorl %eax,%eax
   4.102 -        movb CS(%esp),%cl
   4.103 -    	test $2,%cl          # slow return to ring 2 or 3
   4.104 -        jne  safesti
   4.105 -safesti:btsl $31,4(%esi)     # reenable event callbacks
   4.106 -scrit:  /**** START OF CRITICAL REGION ****/
   4.107 -        cmpl %eax,(%esi)
   4.108 -        jne  14f              # process more events if necessary...
   4.109 -        RESTORE_ALL
   4.110 -14:     btrl %eax,4(%esi)
   4.111 -        jmp  11b
   4.112 -ecrit:  /**** END OF CRITICAL REGION ****/
   4.113 -# [How we do the fixup]. We want to merge the current stack frame with the
   4.114 -# just-interrupted frame. How we do this depends on where in the critical
   4.115 -# region the interrupted handler was executing, and so how many saved
   4.116 -# registers are in each frame. We do this quickly using the lookup table
   4.117 -# 'critical_fixup_table'. For each byte offset in the critical region, it
   4.118 -# provides the number of bytes which have already been popped from the
   4.119 -# interrupted stack frame. 
   4.120 -critical_region_fixup:
   4.121 -        addl $critical_fixup_table-scrit,%eax
   4.122 -        movzbl (%eax),%eax    # %eax contains num bytes popped
   4.123 -        mov  %esp,%esi
   4.124 -        add  %eax,%esi        # %esi points at end of src region
   4.125 -        mov  %esp,%edi
   4.126 -        add  $0x34,%edi       # %edi points at end of dst region
   4.127 -        mov  %eax,%ecx
   4.128 -        shr  $2,%ecx          # convert words to bytes
   4.129 -        je   16f              # skip loop if nothing to copy
   4.130 -15:     subl $4,%esi          # pre-decrementing copy loop
   4.131 -        subl $4,%edi
   4.132 -        movl (%esi),%eax
   4.133 -        movl %eax,(%edi)
   4.134 -        loop 15b
   4.135 -16:     movl %edi,%esp        # final %edi is top of merged stack
   4.136 -        jmp  11b
   4.137 -         
   4.138 -critical_fixup_table:        
   4.139 -        .byte 0x00,0x00                       # cmpl %eax,(%esi)
   4.140 -        .byte 0x00,0x00                       # jne  14f
   4.141 -        .byte 0x00                            # pop  %ebx
   4.142 -        .byte 0x04                            # pop  %ecx
   4.143 -        .byte 0x08                            # pop  %edx
   4.144 -        .byte 0x0c                            # pop  %esi
   4.145 -        .byte 0x10                            # pop  %edi
   4.146 -        .byte 0x14                            # pop  %ebp
   4.147 -        .byte 0x18                            # pop  %eax
   4.148 -        .byte 0x1c                            # pop  %ds
   4.149 -        .byte 0x20                            # pop  %es
   4.150 -        .byte 0x24,0x24,0x24                  # add  $4,%esp
   4.151 -        .byte 0x28                            # iret
   4.152 -        .byte 0x00,0x00,0x00,0x00,0x00        # btrl $31,4(%esi)
   4.153 -        .byte 0x00,0x00                       # jmp  11b
   4.154 -       
   4.155 -# Hypervisor uses this for application faults while it executes.
   4.156 -ENTRY(failsafe_callback)
   4.157 -      pop  %ds
   4.158 -      pop  %es
   4.159 -      pop  %fs
   4.160 -      pop  %gs
   4.161 -      iret
   4.162 -                
   4.163 -ENTRY(coprocessor_error)
   4.164 -	pushl $0
   4.165 -	pushl $do_coprocessor_error
   4.166 -	jmp do_exception
   4.167 -
   4.168 -ENTRY(simd_coprocessor_error)
   4.169 -	pushl $0
   4.170 -	pushl $do_simd_coprocessor_error
   4.171 -	jmp do_exception
   4.172 -
   4.173 -ENTRY(device_not_available)
   4.174 -        iret
   4.175 -
   4.176 -ENTRY(debug)
   4.177 -	pushl $0
   4.178 -	pushl $do_debug
   4.179 -	jmp do_exception
   4.180 -
   4.181 -ENTRY(int3)
   4.182 -	pushl $0
   4.183 -	pushl $do_int3
   4.184 -	jmp do_exception
   4.185 -
   4.186 -ENTRY(overflow)
   4.187 -	pushl $0
   4.188 -	pushl $do_overflow
   4.189 -	jmp do_exception
   4.190 -
   4.191 -ENTRY(bounds)
   4.192 -	pushl $0
   4.193 -	pushl $do_bounds
   4.194 -	jmp do_exception
   4.195 -
   4.196 -ENTRY(invalid_op)
   4.197 -	pushl $0
   4.198 -	pushl $do_invalid_op
   4.199 -	jmp do_exception
   4.200 -
   4.201 -ENTRY(coprocessor_segment_overrun)
   4.202 -	pushl $0
   4.203 -	pushl $do_coprocessor_segment_overrun
   4.204 -	jmp do_exception
   4.205 -
   4.206 -ENTRY(double_fault)
   4.207 -	pushl $do_double_fault
   4.208 -	jmp do_exception
   4.209 -
   4.210 -ENTRY(invalid_TSS)
   4.211 -	pushl $do_invalid_TSS
   4.212 -	jmp do_exception
   4.213 -
   4.214 -ENTRY(segment_not_present)
   4.215 -	pushl $do_segment_not_present
   4.216 -	jmp do_exception
   4.217 -
   4.218 -ENTRY(stack_segment)
   4.219 -	pushl $do_stack_segment
   4.220 -	jmp do_exception
   4.221 -
   4.222 -ENTRY(general_protection)
   4.223 -	pushl $do_general_protection
   4.224 -	jmp do_exception
   4.225 -
   4.226 -ENTRY(alignment_check)
   4.227 -	pushl $do_alignment_check
   4.228 -	jmp do_exception
   4.229 -
   4.230 -# This handler is special, because it gets an extra value on its stack,
   4.231 -# which is the linear faulting address.
   4.232 -ENTRY(page_fault)
   4.233 -	pushl %ds
   4.234 -	pushl %eax
   4.235 -	xorl %eax,%eax
   4.236 -	pushl %ebp
   4.237 -	pushl %edi
   4.238 -	pushl %esi
   4.239 -	pushl %edx
   4.240 -	decl %eax			# eax = -1
   4.241 -	pushl %ecx
   4.242 -	pushl %ebx
   4.243 -	cld
   4.244 -	movl %es,%ecx
   4.245 -	movl ORIG_EAX(%esp), %esi	# get the error code
   4.246 -	movl ES(%esp), %edi		# get the faulting address
   4.247 -	movl %eax, ORIG_EAX(%esp)
   4.248 -	movl %ecx, ES(%esp)
   4.249 -	movl %esp,%edx
   4.250 -        pushl %edi                      # push the faulting address
   4.251 -	pushl %esi			# push the error code
   4.252 -	pushl %edx			# push the pt_regs pointer
   4.253 -	movl $(__KERNEL_DS),%edx
   4.254 -	movl %edx,%ds
   4.255 -	movl %edx,%es
   4.256 -	call do_page_fault
   4.257 -	addl $12,%esp
   4.258 -	jmp ret_from_exception
   4.259 -
   4.260 -ENTRY(machine_check)
   4.261 -	pushl $0
   4.262 -	pushl $do_machine_check
   4.263 -	jmp do_exception
   4.264 -
   4.265 -ENTRY(spurious_interrupt_bug)
   4.266 -	pushl $0
   4.267 -	pushl $do_spurious_interrupt_bug
   4.268 -	jmp do_exception
     5.1 --- a/extras/mini-os/h/hypervisor.h	Fri Feb 11 13:06:19 2005 +0000
     5.2 +++ b/extras/mini-os/h/hypervisor.h	Fri Feb 11 14:37:07 2005 +0000
     5.3 @@ -36,13 +36,25 @@ void ack_hypervisor_event(unsigned int e
     5.4   * Assembler stubs for hyper-calls.
     5.5   */
     5.6  
     5.7 +#ifdef __i386__
     5.8 +#define _a1 "b"
     5.9 +#define _a2 "c"
    5.10 +#define _a3 "d"
    5.11 +#define _a4 "S"
    5.12 +#else
    5.13 +#define _a1 "D"
    5.14 +#define _a2 "S"
    5.15 +#define _a3 "d"
    5.16 +#define _a4 "b"
    5.17 +#endif
    5.18 +
    5.19  static __inline__ int HYPERVISOR_set_trap_table(trap_info_t *table)
    5.20  {
    5.21      int ret;
    5.22      __asm__ __volatile__ (
    5.23          TRAP_INSTR
    5.24          : "=a" (ret) : "0" (__HYPERVISOR_set_trap_table),
    5.25 -        "b" (table) : "memory" );
    5.26 +        _a1 (table) : "memory" );
    5.27  
    5.28      return ret;
    5.29  }
    5.30 @@ -55,7 +67,7 @@ static __inline__ int HYPERVISOR_mmu_upd
    5.31      __asm__ __volatile__ (
    5.32          TRAP_INSTR
    5.33          : "=a" (ret) : "0" (__HYPERVISOR_mmu_update), 
    5.34 -        "b" (req), "c" (count), "d" (success_count)  : "memory" );
    5.35 +        _a1 (req), _a2 (count), _a3 (success_count)  : "memory" );
    5.36  
    5.37      return ret;
    5.38  }
    5.39 @@ -66,7 +78,7 @@ static __inline__ int HYPERVISOR_set_gdt
    5.40      __asm__ __volatile__ (
    5.41          TRAP_INSTR
    5.42          : "=a" (ret) : "0" (__HYPERVISOR_set_gdt), 
    5.43 -        "b" (frame_list), "c" (entries) : "memory" );
    5.44 +        _a1 (frame_list), _a2 (entries) : "memory" );
    5.45  
    5.46  
    5.47      return ret;
    5.48 @@ -78,11 +90,12 @@ static __inline__ int HYPERVISOR_stack_s
    5.49      __asm__ __volatile__ (
    5.50          TRAP_INSTR
    5.51          : "=a" (ret) : "0" (__HYPERVISOR_stack_switch),
    5.52 -        "b" (ss), "c" (esp) : "memory" );
    5.53 +        _a1 (ss), _a2 (esp) : "memory" );
    5.54  
    5.55      return ret;
    5.56  }
    5.57  
    5.58 +#ifdef __i386__
    5.59  static __inline__ int HYPERVISOR_set_callbacks(
    5.60      unsigned long event_selector, unsigned long event_address,
    5.61      unsigned long failsafe_selector, unsigned long failsafe_address)
    5.62 @@ -91,11 +104,27 @@ static __inline__ int HYPERVISOR_set_cal
    5.63      __asm__ __volatile__ (
    5.64          TRAP_INSTR
    5.65          : "=a" (ret) : "0" (__HYPERVISOR_set_callbacks),
    5.66 -        "b" (event_selector), "c" (event_address), 
    5.67 -        "d" (failsafe_selector), "S" (failsafe_address) : "memory" );
    5.68 +        _a1 (event_selector), _a2 (event_address), 
    5.69 +        _a3 (failsafe_selector), _a4 (failsafe_address) : "memory" );
    5.70  
    5.71      return ret;
    5.72  }
    5.73 +#else
    5.74 +static __inline__ int HYPERVISOR_set_callbacks(
    5.75 +    unsigned long event_address,
    5.76 +    unsigned long failsafe_address,
    5.77 +    unsigned long syscall_address)
    5.78 +{
    5.79 +    int ret;
    5.80 +    __asm__ __volatile__ (
    5.81 +        TRAP_INSTR
    5.82 +        : "=a" (ret) : "0" (__HYPERVISOR_set_callbacks),
    5.83 +        _a1 (event_address), _a2 (failsafe_address), 
    5.84 +        _a3 (syscall_address) : "memory" );
    5.85 +
    5.86 +    return ret;
    5.87 +}
    5.88 +#endif
    5.89  
    5.90  static __inline__ int HYPERVISOR_fpu_taskswitch(void)
    5.91  {
    5.92 @@ -113,7 +142,7 @@ static __inline__ int HYPERVISOR_yield(v
    5.93      __asm__ __volatile__ (
    5.94          TRAP_INSTR
    5.95          : "=a" (ret) : "0" (__HYPERVISOR_sched_op),
    5.96 -        "b" (SCHEDOP_yield) : "memory" );
    5.97 +        _a1 (SCHEDOP_yield) : "memory" );
    5.98  
    5.99      return ret;
   5.100  }
   5.101 @@ -124,7 +153,7 @@ static __inline__ int HYPERVISOR_block(v
   5.102      __asm__ __volatile__ (
   5.103          TRAP_INSTR
   5.104          : "=a" (ret) : "0" (__HYPERVISOR_sched_op),
   5.105 -        "b" (SCHEDOP_block) : "memory" );
   5.106 +        _a1 (SCHEDOP_block) : "memory" );
   5.107  
   5.108      return ret;
   5.109  }
   5.110 @@ -135,7 +164,7 @@ static __inline__ int HYPERVISOR_shutdow
   5.111      __asm__ __volatile__ (
   5.112          TRAP_INSTR
   5.113          : "=a" (ret) : "0" (__HYPERVISOR_sched_op),
   5.114 -        "b" (SCHEDOP_shutdown | (SHUTDOWN_poweroff << SCHEDOP_reasonshift))
   5.115 +        _a1 (SCHEDOP_shutdown | (SHUTDOWN_poweroff << SCHEDOP_reasonshift))
   5.116          : "memory" );
   5.117  
   5.118      return ret;
   5.119 @@ -147,7 +176,7 @@ static __inline__ int HYPERVISOR_reboot(
   5.120      __asm__ __volatile__ (
   5.121          TRAP_INSTR
   5.122          : "=a" (ret) : "0" (__HYPERVISOR_sched_op),
   5.123 -        "b" (SCHEDOP_shutdown | (SHUTDOWN_reboot << SCHEDOP_reasonshift))
   5.124 +        _a1 (SCHEDOP_shutdown | (SHUTDOWN_reboot << SCHEDOP_reasonshift))
   5.125          : "memory" );
   5.126  
   5.127      return ret;
   5.128 @@ -160,7 +189,7 @@ static __inline__ int HYPERVISOR_suspend
   5.129      __asm__ __volatile__ (
   5.130          TRAP_INSTR
   5.131          : "=a" (ret) : "0" (__HYPERVISOR_sched_op),
   5.132 -        "b" (SCHEDOP_shutdown | (SHUTDOWN_suspend << SCHEDOP_reasonshift)), 
   5.133 +        _a1 (SCHEDOP_shutdown | (SHUTDOWN_suspend << SCHEDOP_reasonshift)), 
   5.134          "S" (srec) : "memory" );
   5.135  
   5.136      return ret;
   5.137 @@ -172,7 +201,7 @@ static __inline__ long HYPERVISOR_set_ti
   5.138      __asm__ __volatile__ (
   5.139          TRAP_INSTR
   5.140          : "=a" (ret) : "0" (__HYPERVISOR_set_timer_op),
   5.141 -        "b" (timer_arg) : "memory" );
   5.142 +        _a1 (timer_arg) : "memory" );
   5.143  
   5.144      return ret;
   5.145  }
   5.146 @@ -183,7 +212,7 @@ static __inline__ int HYPERVISOR_dom0_op
   5.147      __asm__ __volatile__ (
   5.148          TRAP_INSTR
   5.149          : "=a" (ret) : "0" (__HYPERVISOR_dom0_op),
   5.150 -        "b" (dom0_op) : "memory" );
   5.151 +        _a1 (dom0_op) : "memory" );
   5.152  
   5.153      return ret;
   5.154  }
   5.155 @@ -194,7 +223,7 @@ static __inline__ int HYPERVISOR_set_deb
   5.156      __asm__ __volatile__ (
   5.157          TRAP_INSTR
   5.158          : "=a" (ret) : "0" (__HYPERVISOR_set_debugreg),
   5.159 -        "b" (reg), "c" (value) : "memory" );
   5.160 +        _a1 (reg), _a2 (value) : "memory" );
   5.161  
   5.162      return ret;
   5.163  }
   5.164 @@ -205,7 +234,7 @@ static __inline__ unsigned long HYPERVIS
   5.165      __asm__ __volatile__ (
   5.166          TRAP_INSTR
   5.167          : "=a" (ret) : "0" (__HYPERVISOR_get_debugreg),
   5.168 -        "b" (reg) : "memory" );
   5.169 +        _a1 (reg) : "memory" );
   5.170  
   5.171      return ret;
   5.172  }
   5.173 @@ -217,7 +246,7 @@ static __inline__ int HYPERVISOR_update_
   5.174      __asm__ __volatile__ (
   5.175          TRAP_INSTR
   5.176          : "=a" (ret) : "0" (__HYPERVISOR_update_descriptor), 
   5.177 -        "b" (pa), "c" (word1), "d" (word2) : "memory" );
   5.178 +        _a1 (pa), _a2 (word1), _a3 (word2) : "memory" );
   5.179  
   5.180      return ret;
   5.181  }
   5.182 @@ -228,7 +257,7 @@ static __inline__ int HYPERVISOR_set_fas
   5.183      __asm__ __volatile__ (
   5.184          TRAP_INSTR
   5.185          : "=a" (ret) : "0" (__HYPERVISOR_set_fast_trap), 
   5.186 -        "b" (idx) : "memory" );
   5.187 +        _a1 (idx) : "memory" );
   5.188  
   5.189      return ret;
   5.190  }
   5.191 @@ -239,7 +268,7 @@ static __inline__ int HYPERVISOR_dom_mem
   5.192      __asm__ __volatile__ (
   5.193          TRAP_INSTR
   5.194          : "=a" (ret) : "0" (__HYPERVISOR_dom_mem_op),
   5.195 -        "b" (dom_mem_op) : "memory" );
   5.196 +        _a1 (dom_mem_op) : "memory" );
   5.197  
   5.198      return ret;
   5.199  }
   5.200 @@ -250,7 +279,7 @@ static __inline__ int HYPERVISOR_multica
   5.201      __asm__ __volatile__ (
   5.202          TRAP_INSTR
   5.203          : "=a" (ret) : "0" (__HYPERVISOR_multicall),
   5.204 -        "b" (call_list), "c" (nr_calls) : "memory" );
   5.205 +        _a1 (call_list), _a2 (nr_calls) : "memory" );
   5.206  
   5.207      return ret;
   5.208  }
   5.209 @@ -262,7 +291,7 @@ static __inline__ int HYPERVISOR_update_
   5.210      __asm__ __volatile__ (
   5.211          TRAP_INSTR
   5.212          : "=a" (ret) : "0" (__HYPERVISOR_update_va_mapping), 
   5.213 -        "b" (page_nr), "c" (new_val), "d" (flags) : "memory" );
   5.214 +        _a1 (page_nr), _a2 (new_val), _a3 (flags) : "memory" );
   5.215  
   5.216      return ret;
   5.217  }
   5.218 @@ -273,7 +302,7 @@ static __inline__ int HYPERVISOR_xen_ver
   5.219      __asm__ __volatile__ (
   5.220          TRAP_INSTR
   5.221          : "=a" (ret) : "0" (__HYPERVISOR_xen_version), 
   5.222 -        "b" (cmd) : "memory" );
   5.223 +        _a1 (cmd) : "memory" );
   5.224  
   5.225      return ret;
   5.226  }
   5.227 @@ -284,7 +313,7 @@ static __inline__ int HYPERVISOR_console
   5.228      __asm__ __volatile__ (
   5.229          TRAP_INSTR
   5.230          : "=a" (ret) : "0" (__HYPERVISOR_console_io),
   5.231 -        "b" (cmd), "c" (count), "d" (str) : "memory" );
   5.232 +        _a1 (cmd), _a2 (count), _a3 (str) : "memory" );
   5.233  
   5.234      return ret;
   5.235  }
     6.1 --- a/extras/mini-os/h/mm.h	Fri Feb 11 13:06:19 2005 +0000
     6.2 +++ b/extras/mini-os/h/mm.h	Fri Feb 11 14:37:07 2005 +0000
     6.3 @@ -64,7 +64,11 @@ static __inline__ unsigned long machine_
     6.4      return phys;
     6.5  }
     6.6  
     6.7 +#ifdef __x86_64__
     6.8 +#define VIRT_START              0xFFFFFFFF00000000UL
     6.9 +#else
    6.10  #define VIRT_START              0xC0000000UL
    6.11 +#endif
    6.12  
    6.13  #define to_phys(x)                 ((unsigned long)(x)-VIRT_START)
    6.14  #define to_virt(x)                 ((void *)((unsigned long)(x)+VIRT_START))
     7.1 --- a/extras/mini-os/h/os.h	Fri Feb 11 13:06:19 2005 +0000
     7.2 +++ b/extras/mini-os/h/os.h	Fri Feb 11 14:37:07 2005 +0000
     7.3 @@ -9,116 +9,108 @@
     7.4  
     7.5  #define NULL 0
     7.6  
     7.7 -/* Somewhere in the middle of the GCC 2.96 development cycle, we implemented
     7.8 -   a mechanism by which the user can annotate likely branch directions and
     7.9 -   expect the blocks to be reordered appropriately.  Define __builtin_expect
    7.10 -   to nothing for earlier compilers.  */
    7.11 -
    7.12  #if __GNUC__ == 2 && __GNUC_MINOR__ < 96
    7.13  #define __builtin_expect(x, expected_value) (x)
    7.14  #endif
    7.15 +#define unlikely(x)  __builtin_expect((x),0)
    7.16  
    7.17 -/*
    7.18 - * These are the segment descriptors provided for us by the hypervisor.
    7.19 - * For now, these are hardwired -- guest OSes cannot update the GDT
    7.20 - * or LDT.
    7.21 - * 
    7.22 - * It shouldn't be hard to support descriptor-table frobbing -- let me 
    7.23 - * know if the BSD or XP ports require flexibility here.
    7.24 - */
    7.25 +#define smp_processor_id() 0
    7.26 +#define preempt_disable() ((void)0)
    7.27 +#define preempt_enable() ((void)0)
    7.28  
    7.29 +#define force_evtchn_callback() ((void)HYPERVISOR_xen_version(0))
    7.30  
    7.31 -/*
    7.32 - * these are also defined in xen-public/xen.h but can't be pulled in as
    7.33 - * they are used in start of day assembly. Need to clean up the .h files
    7.34 - * a bit more...
    7.35 - */
    7.36 +#ifndef __ASSEMBLY__
    7.37 +#include <types.h>
    7.38 +#endif
    7.39 +#include <xen-public/xen.h>
    7.40  
    7.41 -#ifndef FLAT_RING1_CS
    7.42 -#define FLAT_RING1_CS		0x0819
    7.43 -#define FLAT_RING1_DS		0x0821
    7.44 -#define FLAT_RING3_CS		0x082b
    7.45 -#define FLAT_RING3_DS		0x0833
    7.46 -#endif
    7.47 -
    7.48 -#define __KERNEL_CS        FLAT_RING1_CS
    7.49 -#define __KERNEL_DS        FLAT_RING1_DS
    7.50 +#define __KERNEL_CS  FLAT_KERNEL_CS
    7.51 +#define __KERNEL_DS  FLAT_KERNEL_DS
    7.52 +#define __KERNEL_SS  FLAT_KERNEL_SS
    7.53  
    7.54  /* Everything below this point is not included by assembler (.S) files. */
    7.55  #ifndef __ASSEMBLY__
    7.56  
    7.57 -#include <types.h>
    7.58 -#include <xen-public/xen.h>
    7.59 -
    7.60 +#define pt_regs xen_regs
    7.61  
    7.62 -/* this struct defines the way the registers are stored on the 
    7.63 -   stack during an exception or interrupt. */
    7.64 -struct pt_regs {
    7.65 -	long ebx;
    7.66 -	long ecx;
    7.67 -	long edx;
    7.68 -	long esi;
    7.69 -	long edi;
    7.70 -	long ebp;
    7.71 -	long eax;
    7.72 -	int  xds;
    7.73 -	int  xes;
    7.74 -	long orig_eax;
    7.75 -	long eip;
    7.76 -	int  xcs;
    7.77 -	long eflags;
    7.78 -	long esp;
    7.79 -	int  xss;
    7.80 -};
    7.81 -
    7.82 -/* some function prototypes */
    7.83  void trap_init(void);
    7.84  void dump_regs(struct pt_regs *regs);
    7.85  
    7.86 -
    7.87 -/*
    7.88 - * STI/CLI equivalents. These basically set and clear the virtual
    7.89 - * event_enable flag in teh shared_info structure. Note that when
    7.90 - * the enable bit is set, there may be pending events to be handled.
    7.91 - * We may therefore call into do_hypervisor_callback() directly.
    7.92 +/* 
    7.93 + * The use of 'barrier' in the following reflects their use as local-lock
    7.94 + * operations. Reentrancy must be prevented (e.g., __cli()) /before/ following
    7.95 + * critical operations are executed. All critical operations must complete
    7.96 + * /before/ reentrancy is permitted (e.g., __sti()). Alpha architecture also
    7.97 + * includes these barriers, for example.
    7.98   */
    7.99 -#define unlikely(x)  __builtin_expect((x),0)
   7.100 -#define __save_flags(x)                                                       \
   7.101 -do {                                                                          \
   7.102 -    (x) = test_bit(EVENTS_MASTER_ENABLE_BIT,                                  \
   7.103 -                   &HYPERVISOR_shared_info->events_mask);                     \
   7.104 -    barrier();                                                                \
   7.105 +
   7.106 +#define __cli()								\
   7.107 +do {									\
   7.108 +	vcpu_info_t *_vcpu;						\
   7.109 +	preempt_disable();						\
   7.110 +	_vcpu = &HYPERVISOR_shared_info->vcpu_data[smp_processor_id()];	\
   7.111 +	_vcpu->evtchn_upcall_mask = 1;					\
   7.112 +	preempt_enable_no_resched();					\
   7.113 +	barrier();							\
   7.114 +} while (0)
   7.115 +
   7.116 +#define __sti()								\
   7.117 +do {									\
   7.118 +	vcpu_info_t *_vcpu;						\
   7.119 +	barrier();							\
   7.120 +	preempt_disable();						\
   7.121 +	_vcpu = &HYPERVISOR_shared_info->vcpu_data[smp_processor_id()];	\
   7.122 +	_vcpu->evtchn_upcall_mask = 0;					\
   7.123 +	barrier(); /* unmask then check (avoid races) */		\
   7.124 +	if ( unlikely(_vcpu->evtchn_upcall_pending) )			\
   7.125 +		force_evtchn_callback();				\
   7.126 +	preempt_enable();						\
   7.127  } while (0)
   7.128  
   7.129 -#define __restore_flags(x)                                                    \
   7.130 -do {                                                                          \
   7.131 -    shared_info_t *_shared = HYPERVISOR_shared_info;                          \
   7.132 -    if (x) set_bit(EVENTS_MASTER_ENABLE_BIT, &_shared->events_mask);          \
   7.133 -    barrier();                                                                \
   7.134 -    if ( unlikely(_shared->events) && (x) ) do_hypervisor_callback(NULL);     \
   7.135 +#define __save_flags(x)							\
   7.136 +do {									\
   7.137 +	vcpu_info_t *_vcpu;						\
   7.138 +	_vcpu = &HYPERVISOR_shared_info->vcpu_data[smp_processor_id()];	\
   7.139 +	(x) = _vcpu->evtchn_upcall_mask;				\
   7.140  } while (0)
   7.141  
   7.142 -#define __cli()                                                               \
   7.143 -do {                                                                          \
   7.144 -    clear_bit(EVENTS_MASTER_ENABLE_BIT, &HYPERVISOR_shared_info->events_mask);\
   7.145 -    barrier();                                                                \
   7.146 +#define __restore_flags(x)						\
   7.147 +do {									\
   7.148 +	vcpu_info_t *_vcpu;						\
   7.149 +	barrier();							\
   7.150 +	preempt_disable();						\
   7.151 +	_vcpu = &HYPERVISOR_shared_info->vcpu_data[smp_processor_id()];	\
   7.152 +	if ((_vcpu->evtchn_upcall_mask = (x)) == 0) {			\
   7.153 +		barrier(); /* unmask then check (avoid races) */	\
   7.154 +		if ( unlikely(_vcpu->evtchn_upcall_pending) )		\
   7.155 +			force_evtchn_callback();			\
   7.156 +		preempt_enable();					\
   7.157 +	} else								\
   7.158 +		preempt_enable_no_resched();				\
   7.159  } while (0)
   7.160  
   7.161 -#define __sti()                                                               \
   7.162 -do {                                                                          \
   7.163 -    shared_info_t *_shared = HYPERVISOR_shared_info;                          \
   7.164 -    set_bit(EVENTS_MASTER_ENABLE_BIT, &_shared->events_mask);                 \
   7.165 -    barrier();                                                                \
   7.166 -    if ( unlikely(_shared->events) ) do_hypervisor_callback(NULL);            \
   7.167 +#define safe_halt()		((void)0)
   7.168 +
   7.169 +#define __save_and_cli(x)						\
   7.170 +do {									\
   7.171 +	vcpu_info_t *_vcpu;						\
   7.172 +	preempt_disable();						\
   7.173 +	_vcpu = &HYPERVISOR_shared_info->vcpu_data[smp_processor_id()];	\
   7.174 +	(x) = _vcpu->evtchn_upcall_mask;				\
   7.175 +	_vcpu->evtchn_upcall_mask = 1;					\
   7.176 +	preempt_enable_no_resched();					\
   7.177 +	barrier();							\
   7.178  } while (0)
   7.179 -#define cli() __cli()
   7.180 -#define sti() __sti()
   7.181 -#define save_flags(x) __save_flags(x)
   7.182 -#define restore_flags(x) __restore_flags(x)
   7.183 -#define save_and_cli(x) __save_and_cli(x)
   7.184 -#define save_and_sti(x) __save_and_sti(x)
   7.185  
   7.186 +#define local_irq_save(x)	__save_and_cli(x)
   7.187 +#define local_irq_restore(x)	__restore_flags(x)
   7.188 +#define local_save_flags(x)	__save_flags(x)
   7.189 +#define local_irq_disable()	__cli()
   7.190 +#define local_irq_enable()	__sti()
   7.191  
   7.192 +#define irqs_disabled()			\
   7.193 +    HYPERVISOR_shared_info->vcpu_data[smp_processor_id()].evtchn_upcall_mask
   7.194  
   7.195  /* This is a barrier for the compiler only, NOT the processor! */
   7.196  #define barrier() __asm__ __volatile__("": : :"memory")
     8.1 --- a/extras/mini-os/head.S	Fri Feb 11 13:06:19 2005 +0000
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,18 +0,0 @@
     8.4 -#include <os.h>
     8.5 -
     8.6 -.globl _start, shared_info
     8.7 -                        
     8.8 -_start:
     8.9 -        cld
    8.10 -        lss stack_start,%esp
    8.11 -        push %esi 
    8.12 -        call start_kernel
    8.13 -
    8.14 -stack_start:
    8.15 -	.long stack+8192, __KERNEL_DS
    8.16 -
    8.17 -        /* Unpleasant -- the PTE that maps this page is actually overwritten */
    8.18 -        /* to map the real shared-info page! :-)                             */
    8.19 -        .org 0x1000
    8.20 -shared_info:
    8.21 -        .org 0x2000
     9.1 --- a/extras/mini-os/kernel.c	Fri Feb 11 13:06:19 2005 +0000
     9.2 +++ b/extras/mini-os/kernel.c	Fri Feb 11 14:37:07 2005 +0000
     9.3 @@ -64,8 +64,8 @@ extern char shared_info[PAGE_SIZE];
     9.4  
     9.5  static shared_info_t *map_shared_info(unsigned long pa)
     9.6  {
     9.7 -    if ( HYPERVISOR_update_va_mapping((unsigned long)shared_info >> PAGE_SHIFT,
     9.8 -                                      pa | 3, UVMF_INVLPG) )
     9.9 +    if ( HYPERVISOR_update_va_mapping(
    9.10 +        (unsigned long)shared_info, pa | 3, UVMF_INVLPG) )
    9.11      {
    9.12          printk("Failed to map shared_info!!\n");
    9.13          *(int*)0=0;
    9.14 @@ -79,6 +79,9 @@ static shared_info_t *map_shared_info(un
    9.15   */
    9.16  void start_kernel(start_info_t *si)
    9.17  {
    9.18 +    static char hello[] = "Bootstrapping...\n";
    9.19 +    (void)HYPERVISOR_console_io(CONSOLEIO_write, strlen(hello), hello);
    9.20 +
    9.21      /* Copy the start_info struct to a globally-accessible area. */
    9.22      memcpy(&start_info, si, sizeof(*si));
    9.23  
    9.24 @@ -86,9 +89,15 @@ void start_kernel(start_info_t *si)
    9.25      HYPERVISOR_shared_info = map_shared_info(start_info.shared_info);
    9.26  
    9.27      /* Set up event and failsafe callback addresses. */
    9.28 +#ifdef __i386__
    9.29      HYPERVISOR_set_callbacks(
    9.30          __KERNEL_CS, (unsigned long)hypervisor_callback,
    9.31          __KERNEL_CS, (unsigned long)failsafe_callback);
    9.32 +#else
    9.33 +    HYPERVISOR_set_callbacks(
    9.34 +        (unsigned long)hypervisor_callback,
    9.35 +        (unsigned long)failsafe_callback, 0);
    9.36 +#endif
    9.37  
    9.38      trap_init();
    9.39  
    9.40 @@ -117,7 +126,7 @@ void start_kernel(start_info_t *si)
    9.41      init_mm();
    9.42  
    9.43      /* set up events */
    9.44 -    init_events();
    9.45 +//    init_events();
    9.46  
    9.47      /*
    9.48       * These need to be replaced with event-channel/control-interface
    9.49 @@ -135,7 +144,7 @@ void start_kernel(start_info_t *si)
    9.50  #endif
    9.51  
    9.52      /* init time and timers */
    9.53 -    init_time();
    9.54 +//    init_time();
    9.55  
    9.56      /* do nothing */
    9.57      for ( ; ; ) HYPERVISOR_yield();
    10.1 --- a/extras/mini-os/lib/math.c	Fri Feb 11 13:06:19 2005 +0000
    10.2 +++ b/extras/mini-os/lib/math.c	Fri Feb 11 14:37:07 2005 +0000
    10.3 @@ -96,14 +96,14 @@ union uu {
    10.4   * (sizeof(long)*CHAR_BIT/2).
    10.5   */
    10.6  #define HHALF(x)        ((x) >> HALF_BITS)
    10.7 -#define LHALF(x)        ((x) & ((1 << HALF_BITS) - 1))
    10.8 +#define LHALF(x)        ((x) & ((1UL << HALF_BITS) - 1))
    10.9  #define LHUP(x)         ((x) << HALF_BITS)
   10.10  
   10.11  /*
   10.12   * Multiprecision divide.  This algorithm is from Knuth vol. 2 (2nd ed),
   10.13   * section 4.3.1, pp. 257--259.
   10.14   */
   10.15 -#define	B	(1 << HALF_BITS)	/* digit base */
   10.16 +#define	B	(1UL << HALF_BITS)	/* digit base */
   10.17  
   10.18  /* Combine two `digits' to make a single two-digit number. */
   10.19  #define	COMBINE(a, b) (((u_long)(a) << HALF_BITS) | (b))
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/extras/mini-os/minios-x86_32.lds	Fri Feb 11 14:37:07 2005 +0000
    11.3 @@ -0,0 +1,54 @@
    11.4 +OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
    11.5 +OUTPUT_ARCH(i386)
    11.6 +ENTRY(_start)
    11.7 +SECTIONS
    11.8 +{
    11.9 +  . = 0xC0000000;
   11.10 +  _text = .;			/* Text and read-only data */
   11.11 +  .text : {
   11.12 +	*(.text)
   11.13 +	*(.gnu.warning)
   11.14 +	} = 0x9090
   11.15 +
   11.16 +  _etext = .;			/* End of text section */
   11.17 +
   11.18 +  .rodata : { *(.rodata) *(.rodata.*) }
   11.19 +
   11.20 +  .data : {			/* Data */
   11.21 +	*(.data)
   11.22 +	CONSTRUCTORS
   11.23 +	}
   11.24 +
   11.25 +  _edata = .;			/* End of data section */
   11.26 +
   11.27 +  . = ALIGN(8192);		/* init_task */
   11.28 +  .data.init_task : { *(.data.init_task) }
   11.29 +
   11.30 +  . = ALIGN(4096);
   11.31 +  .data.page_aligned : { *(.data.idt) }
   11.32 +
   11.33 +  . = ALIGN(32);
   11.34 +  .data.cacheline_aligned : { *(.data.cacheline_aligned) }
   11.35 +
   11.36 +  __bss_start = .;		/* BSS */
   11.37 +  .bss : {
   11.38 +	*(.bss)
   11.39 +	}
   11.40 +  _end = . ;
   11.41 +
   11.42 +  /* Sections to be discarded */
   11.43 +  /DISCARD/ : {
   11.44 +	*(.text.exit)
   11.45 +	*(.data.exit)
   11.46 +	*(.exitcall.exit)
   11.47 +	}
   11.48 +
   11.49 +  /* Stabs debugging sections.  */
   11.50 +  .stab 0 : { *(.stab) }
   11.51 +  .stabstr 0 : { *(.stabstr) }
   11.52 +  .stab.excl 0 : { *(.stab.excl) }
   11.53 +  .stab.exclstr 0 : { *(.stab.exclstr) }
   11.54 +  .stab.index 0 : { *(.stab.index) }
   11.55 +  .stab.indexstr 0 : { *(.stab.indexstr) }
   11.56 +  .comment 0 : { *(.comment) }
   11.57 +}
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/extras/mini-os/minios-x86_64.lds	Fri Feb 11 14:37:07 2005 +0000
    12.3 @@ -0,0 +1,54 @@
    12.4 +OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64", "elf64-x86-64")
    12.5 +OUTPUT_ARCH(i386:x86-64)
    12.6 +ENTRY(_start)
    12.7 +SECTIONS
    12.8 +{
    12.9 +  . = 0xFFFFFFFF00000000;
   12.10 +  _text = .;			/* Text and read-only data */
   12.11 +  .text : {
   12.12 +	*(.text)
   12.13 +	*(.gnu.warning)
   12.14 +	} = 0x9090
   12.15 +
   12.16 +  _etext = .;			/* End of text section */
   12.17 +
   12.18 +  .rodata : { *(.rodata) *(.rodata.*) }
   12.19 +
   12.20 +  .data : {			/* Data */
   12.21 +	*(.data)
   12.22 +	CONSTRUCTORS
   12.23 +	}
   12.24 +
   12.25 +  _edata = .;			/* End of data section */
   12.26 +
   12.27 +  . = ALIGN(8192);		/* init_task */
   12.28 +  .data.init_task : { *(.data.init_task) }
   12.29 +
   12.30 +  . = ALIGN(4096);
   12.31 +  .data.page_aligned : { *(.data.idt) }
   12.32 +
   12.33 +  . = ALIGN(32);
   12.34 +  .data.cacheline_aligned : { *(.data.cacheline_aligned) }
   12.35 +
   12.36 +  __bss_start = .;		/* BSS */
   12.37 +  .bss : {
   12.38 +	*(.bss)
   12.39 +	}
   12.40 +  _end = . ;
   12.41 +
   12.42 +  /* Sections to be discarded */
   12.43 +  /DISCARD/ : {
   12.44 +	*(.text.exit)
   12.45 +	*(.data.exit)
   12.46 +	*(.exitcall.exit)
   12.47 +	}
   12.48 +
   12.49 +  /* Stabs debugging sections.  */
   12.50 +  .stab 0 : { *(.stab) }
   12.51 +  .stabstr 0 : { *(.stabstr) }
   12.52 +  .stab.excl 0 : { *(.stab.excl) }
   12.53 +  .stab.exclstr 0 : { *(.stab.exclstr) }
   12.54 +  .stab.index 0 : { *(.stab.index) }
   12.55 +  .stab.indexstr 0 : { *(.stab.indexstr) }
   12.56 +  .comment 0 : { *(.comment) }
   12.57 +}
    13.1 --- a/extras/mini-os/minios.lds	Fri Feb 11 13:06:19 2005 +0000
    13.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.3 @@ -1,54 +0,0 @@
    13.4 -OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
    13.5 -OUTPUT_ARCH(i386)
    13.6 -ENTRY(_start)
    13.7 -SECTIONS
    13.8 -{
    13.9 -  . = 0xC0000000;
   13.10 -  _text = .;			/* Text and read-only data */
   13.11 -  .text : {
   13.12 -	*(.text)
   13.13 -	*(.gnu.warning)
   13.14 -	} = 0x9090
   13.15 -
   13.16 -  _etext = .;			/* End of text section */
   13.17 -
   13.18 -  .rodata : { *(.rodata) *(.rodata.*) }
   13.19 -
   13.20 -  .data : {			/* Data */
   13.21 -	*(.data)
   13.22 -	CONSTRUCTORS
   13.23 -	}
   13.24 -
   13.25 -  _edata = .;			/* End of data section */
   13.26 -
   13.27 -  . = ALIGN(8192);		/* init_task */
   13.28 -  .data.init_task : { *(.data.init_task) }
   13.29 -
   13.30 -  . = ALIGN(4096);
   13.31 -  .data.page_aligned : { *(.data.idt) }
   13.32 -
   13.33 -  . = ALIGN(32);
   13.34 -  .data.cacheline_aligned : { *(.data.cacheline_aligned) }
   13.35 -
   13.36 -  __bss_start = .;		/* BSS */
   13.37 -  .bss : {
   13.38 -	*(.bss)
   13.39 -	}
   13.40 -  _end = . ;
   13.41 -
   13.42 -  /* Sections to be discarded */
   13.43 -  /DISCARD/ : {
   13.44 -	*(.text.exit)
   13.45 -	*(.data.exit)
   13.46 -	*(.exitcall.exit)
   13.47 -	}
   13.48 -
   13.49 -  /* Stabs debugging sections.  */
   13.50 -  .stab 0 : { *(.stab) }
   13.51 -  .stabstr 0 : { *(.stabstr) }
   13.52 -  .stab.excl 0 : { *(.stab.excl) }
   13.53 -  .stab.exclstr 0 : { *(.stab.exclstr) }
   13.54 -  .stab.index 0 : { *(.stab.index) }
   13.55 -  .stab.indexstr 0 : { *(.stab.indexstr) }
   13.56 -  .comment 0 : { *(.comment) }
   13.57 -}
    14.1 --- a/extras/mini-os/traps.c	Fri Feb 11 13:06:19 2005 +0000
    14.2 +++ b/extras/mini-os/traps.c	Fri Feb 11 14:37:07 2005 +0000
    14.3 @@ -33,38 +33,38 @@ extern void do_exit(void);
    14.4  
    14.5  void dump_regs(struct pt_regs *regs)
    14.6  {
    14.7 -	int in_kernel = 1;
    14.8 -	unsigned long esp;
    14.9 -	unsigned short ss;
   14.10 +    int in_kernel = 1;
   14.11 +    unsigned long esp;
   14.12 +    unsigned short ss;
   14.13  
   14.14 -	esp = (unsigned long) (&regs->esp);
   14.15 -	ss = __KERNEL_DS;
   14.16 -	if (regs->xcs & 2) {
   14.17 -		in_kernel = 0;
   14.18 -		esp = regs->esp;
   14.19 -		ss = regs->xss & 0xffff;
   14.20 -	}
   14.21 -	printf("EIP:    %04x:[<%08lx>]\n",
   14.22 -	       0xffff & regs->xcs, regs->eip);
   14.23 -	printf("EFLAGS: %08lx\n",regs->eflags);
   14.24 -	printf("eax: %08lx   ebx: %08lx   ecx: %08lx   edx: %08lx\n",
   14.25 -		regs->eax, regs->ebx, regs->ecx, regs->edx);
   14.26 -	printf("esi: %08lx   edi: %08lx   ebp: %08lx   esp: %08lx\n",
   14.27 -		regs->esi, regs->edi, regs->ebp, esp);
   14.28 -	printf("ds: %04x   es: %04x   ss: %04x\n",
   14.29 -		regs->xds & 0xffff, regs->xes & 0xffff, ss);
   14.30 -	printf("\n");
   14.31 +    esp = (unsigned long) (&regs->esp);
   14.32 +    ss = __KERNEL_DS;
   14.33 +    if (regs->cs & 2) {
   14.34 +        in_kernel = 0;
   14.35 +        esp = regs->esp;
   14.36 +        ss = regs->ss & 0xffff;
   14.37 +    }
   14.38 +    printf("EIP:    %04x:[<%p>]\n",
   14.39 +           0xffff & regs->cs , regs->eip);
   14.40 +    printf("EFLAGS: %p\n",regs->eflags);
   14.41 +    printf("eax: %p   ebx: %p   ecx: %p   edx: %p\n",
   14.42 +           regs->eax, regs->ebx, regs->ecx, regs->edx);
   14.43 +    printf("esi: %p   edi: %p   ebp: %p   esp: %p\n",
   14.44 +           regs->esi, regs->edi, regs->ebp, esp);
   14.45 +    printf("ds: %04x   es: %04x   ss: %04x\n",
   14.46 +           regs->ds & 0xffff, regs->es & 0xffff, ss);
   14.47 +    printf("\n");
   14.48  }	
   14.49  
   14.50  
   14.51 -static __inline__ void dump_code(unsigned eip)
   14.52 +static __inline__ void dump_code(unsigned long eip)
   14.53  {
   14.54 -  unsigned *ptr = (unsigned *)eip;
   14.55 -  int x;
   14.56 -
   14.57 -  printk("Bytes at eip:\n");
   14.58 -  for (x = -4; x < 5; x++)
   14.59 -      printf("%x", ptr[x]);
   14.60 +    unsigned *ptr = (unsigned *)eip;
   14.61 +    int x;
   14.62 +    
   14.63 +    printk("Bytes at eip:\n");
   14.64 +    for (x = -4; x < 5; x++)
   14.65 +        printf("%p", ptr[x]);
   14.66  }
   14.67  
   14.68  
   14.69 @@ -81,14 +81,14 @@ static __inline__ void dump_code(unsigne
   14.70   */
   14.71  
   14.72  static void __inline__ do_trap(int trapnr, char *str,
   14.73 -			   struct pt_regs * regs, long error_code)
   14.74 +                               struct pt_regs * regs, long error_code)
   14.75  {
   14.76 -  printk("FATAL:  Unhandled Trap (see mini-os:traps.c)");
   14.77 -  printf("%d %s", trapnr, str);
   14.78 -  dump_regs(regs);
   14.79 -  dump_code(regs->eip);
   14.80 +    printk("FATAL:  Unhandled Trap (see mini-os:traps.c)");
   14.81 +    printf("%d %s", trapnr, str);
   14.82 +    dump_regs(regs);
   14.83 +    dump_code(regs->eip);
   14.84  
   14.85 -  do_exit();
   14.86 +    do_exit();
   14.87  }
   14.88  
   14.89  #define DO_ERROR(trapnr, str, name) \
   14.90 @@ -104,38 +104,36 @@ void do_##name(struct pt_regs * regs, lo
   14.91  }
   14.92  
   14.93  DO_ERROR_INFO( 0, "divide error", divide_error, FPE_INTDIV, regs->eip)
   14.94 -DO_ERROR( 3, "int3", int3)
   14.95 -DO_ERROR( 4, "overflow", overflow)
   14.96 -DO_ERROR( 5, "bounds", bounds)
   14.97 -DO_ERROR_INFO( 6, "invalid operand", invalid_op, ILL_ILLOPN, regs->eip)
   14.98 -DO_ERROR( 7, "device not available", device_not_available)
   14.99 -DO_ERROR( 8, "double fault", double_fault)
  14.100 -DO_ERROR( 9, "coprocessor segment overrun", coprocessor_segment_overrun)
  14.101 -DO_ERROR(10, "invalid TSS", invalid_TSS)
  14.102 -DO_ERROR(11, "segment not present", segment_not_present)
  14.103 -DO_ERROR(12, "stack segment", stack_segment)
  14.104 -DO_ERROR_INFO(17, "alignment check", alignment_check, BUS_ADRALN, 0)
  14.105 -DO_ERROR(18, "machine check", machine_check)
  14.106 +    DO_ERROR( 3, "int3", int3)
  14.107 +    DO_ERROR( 4, "overflow", overflow)
  14.108 +    DO_ERROR( 5, "bounds", bounds)
  14.109 +    DO_ERROR_INFO( 6, "invalid operand", invalid_op, ILL_ILLOPN, regs->eip)
  14.110 +    DO_ERROR( 7, "device not available", device_not_available)
  14.111 +    DO_ERROR( 8, "double fault", double_fault)
  14.112 +    DO_ERROR( 9, "coprocessor segment overrun", coprocessor_segment_overrun)
  14.113 +    DO_ERROR(10, "invalid TSS", invalid_TSS)
  14.114 +    DO_ERROR(11, "segment not present", segment_not_present)
  14.115 +    DO_ERROR(12, "stack segment", stack_segment)
  14.116 +    DO_ERROR_INFO(17, "alignment check", alignment_check, BUS_ADRALN, 0)
  14.117 +    DO_ERROR(18, "machine check", machine_check)
  14.118  
  14.119 -void do_page_fault(struct pt_regs *regs, long error_code,
  14.120 -                   unsigned long address)
  14.121 +    void do_page_fault(struct pt_regs *regs, long error_code,
  14.122 +                       unsigned long address)
  14.123  {
  14.124      printk("Page fault\n");
  14.125 -    printk("Address: 0x%lx", address);
  14.126 -    printk("Error Code: 0x%lx", error_code);
  14.127 -    printk("eip: \t 0x%lx", regs->eip);
  14.128 +    printk("Address: 0x%p", address);
  14.129 +    printk("Error Code: 0x%p", error_code);
  14.130 +    printk("eip: \t 0x%p", regs->eip);
  14.131      do_exit();
  14.132  }
  14.133  
  14.134  void do_general_protection(struct pt_regs * regs, long error_code)
  14.135  {
  14.136 -
  14.137 -  HYPERVISOR_shared_info->events_mask = 0;
  14.138 -  printk("GPF\n");
  14.139 -  printk("Error Code: 0x%lx", error_code);
  14.140 -  dump_regs(regs);
  14.141 -  dump_code(regs->eip);
  14.142 -  do_exit();
  14.143 +    printk("GPF\n");
  14.144 +    printk("Error Code: 0x%p", error_code);
  14.145 +    dump_regs(regs);
  14.146 +    dump_code(regs->eip);
  14.147 +    do_exit();
  14.148  }
  14.149  
  14.150  
  14.151 @@ -180,26 +178,29 @@ void do_spurious_interrupt_bug(struct pt
  14.152   * The 'privilege ring' field specifies the least-privileged ring that
  14.153   * can trap to that vector using a software-interrupt instruction (INT).
  14.154   */
  14.155 +#ifdef __x86_64__
  14.156 +#define _P 0,
  14.157 +#endif
  14.158  static trap_info_t trap_table[] = {
  14.159 -    {  0, 0, __KERNEL_CS, (unsigned long)divide_error                },
  14.160 -    {  1, 0, __KERNEL_CS, (unsigned long)debug                       },
  14.161 -    {  3, 3, __KERNEL_CS, (unsigned long)int3                        },
  14.162 -    {  4, 3, __KERNEL_CS, (unsigned long)overflow                    },
  14.163 -    {  5, 3, __KERNEL_CS, (unsigned long)bounds                      },
  14.164 -    {  6, 0, __KERNEL_CS, (unsigned long)invalid_op                  },
  14.165 -    {  7, 0, __KERNEL_CS, (unsigned long)device_not_available        },
  14.166 -    {  8, 0, __KERNEL_CS, (unsigned long)double_fault                },
  14.167 -    {  9, 0, __KERNEL_CS, (unsigned long)coprocessor_segment_overrun },
  14.168 -    { 10, 0, __KERNEL_CS, (unsigned long)invalid_TSS                 },
  14.169 -    { 11, 0, __KERNEL_CS, (unsigned long)segment_not_present         },
  14.170 -    { 12, 0, __KERNEL_CS, (unsigned long)stack_segment               },
  14.171 -    { 13, 0, __KERNEL_CS, (unsigned long)general_protection          },
  14.172 -    { 14, 0, __KERNEL_CS, (unsigned long)page_fault                  },
  14.173 -    { 15, 0, __KERNEL_CS, (unsigned long)spurious_interrupt_bug      },
  14.174 -    { 16, 0, __KERNEL_CS, (unsigned long)coprocessor_error           },
  14.175 -    { 17, 0, __KERNEL_CS, (unsigned long)alignment_check             },
  14.176 -    { 18, 0, __KERNEL_CS, (unsigned long)machine_check               },
  14.177 -    { 19, 0, __KERNEL_CS, (unsigned long)simd_coprocessor_error      },
  14.178 +    {  0, 0, __KERNEL_CS, _P (unsigned long)divide_error                },
  14.179 +    {  1, 0, __KERNEL_CS, _P (unsigned long)debug                       },
  14.180 +    {  3, 3, __KERNEL_CS, _P (unsigned long)int3                        },
  14.181 +    {  4, 3, __KERNEL_CS, _P (unsigned long)overflow                    },
  14.182 +    {  5, 3, __KERNEL_CS, _P (unsigned long)bounds                      },
  14.183 +    {  6, 0, __KERNEL_CS, _P (unsigned long)invalid_op                  },
  14.184 +    {  7, 0, __KERNEL_CS, _P (unsigned long)device_not_available        },
  14.185 +    {  8, 0, __KERNEL_CS, _P (unsigned long)double_fault                },
  14.186 +    {  9, 0, __KERNEL_CS, _P (unsigned long)coprocessor_segment_overrun },
  14.187 +    { 10, 0, __KERNEL_CS, _P (unsigned long)invalid_TSS                 },
  14.188 +    { 11, 0, __KERNEL_CS, _P (unsigned long)segment_not_present         },
  14.189 +    { 12, 0, __KERNEL_CS, _P (unsigned long)stack_segment               },
  14.190 +    { 13, 0, __KERNEL_CS, _P (unsigned long)general_protection          },
  14.191 +    { 14, 0, __KERNEL_CS, _P (unsigned long)page_fault                  },
  14.192 +    { 15, 0, __KERNEL_CS, _P (unsigned long)spurious_interrupt_bug      },
  14.193 +    { 16, 0, __KERNEL_CS, _P (unsigned long)coprocessor_error           },
  14.194 +    { 17, 0, __KERNEL_CS, _P (unsigned long)alignment_check             },
  14.195 +    { 18, 0, __KERNEL_CS, _P (unsigned long)machine_check               },
  14.196 +    { 19, 0, __KERNEL_CS, _P (unsigned long)simd_coprocessor_error      },
  14.197      {  0, 0,           0, 0                           }
  14.198  };
  14.199      
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/extras/mini-os/x86_32.S	Fri Feb 11 14:37:07 2005 +0000
    15.3 @@ -0,0 +1,285 @@
    15.4 +#include <os.h>
    15.5 +
    15.6 +.section __xen_guest
    15.7 +        .asciz  "XEN_VER=2.0,LOADER=generic,PT_MODE_WRITABLE"
    15.8 +.text
    15.9 +
   15.10 +.globl _start, shared_info
   15.11 +                        
   15.12 +_start:
   15.13 +        cld
   15.14 +        lss stack_start,%esp
   15.15 +        push %esi 
   15.16 +        call start_kernel
   15.17 +
   15.18 +stack_start:
   15.19 +	.long stack+8192, __KERNEL_SS
   15.20 +
   15.21 +        /* Unpleasant -- the PTE that maps this page is actually overwritten */
   15.22 +        /* to map the real shared-info page! :-)                             */
   15.23 +        .org 0x1000
   15.24 +shared_info:
   15.25 +        .org 0x2000
   15.26 +        
   15.27 +ES		= 0x20
   15.28 +ORIG_EAX	= 0x24
   15.29 +EIP		= 0x28
   15.30 +CS		= 0x2C
   15.31 +
   15.32 +#define ENTRY(X) .globl X ; X :
   15.33 +
   15.34 +#define SAVE_ALL \
   15.35 +	cld; \
   15.36 +	pushl %es; \
   15.37 +	pushl %ds; \
   15.38 +	pushl %eax; \
   15.39 +	pushl %ebp; \
   15.40 +	pushl %edi; \
   15.41 +	pushl %esi; \
   15.42 +	pushl %edx; \
   15.43 +	pushl %ecx; \
   15.44 +	pushl %ebx; \
   15.45 +	movl $(__KERNEL_DS),%edx; \
   15.46 +	movl %edx,%ds; \
   15.47 +	movl %edx,%es;
   15.48 +
   15.49 +#define RESTORE_ALL	\
   15.50 +	popl %ebx;	\
   15.51 +	popl %ecx;	\
   15.52 +	popl %edx;	\
   15.53 +	popl %esi;	\
   15.54 +	popl %edi;	\
   15.55 +	popl %ebp;	\
   15.56 +	popl %eax;	\
   15.57 +	popl %ds;	\
   15.58 +	popl %es;	\
   15.59 +	addl $4,%esp;	\
   15.60 +	iret;		\
   15.61 +
   15.62 +ENTRY(divide_error)
   15.63 +	pushl $0		# no error code
   15.64 +	pushl $do_divide_error
   15.65 +do_exception:
   15.66 +	pushl %ds
   15.67 +	pushl %eax
   15.68 +	xorl %eax,%eax
   15.69 +	pushl %ebp
   15.70 +	pushl %edi
   15.71 +	pushl %esi
   15.72 +	pushl %edx
   15.73 +	decl %eax			# eax = -1
   15.74 +	pushl %ecx
   15.75 +	pushl %ebx
   15.76 +	cld
   15.77 +	movl %es,%ecx
   15.78 +	movl ORIG_EAX(%esp), %esi	# get the error code
   15.79 +	movl ES(%esp), %edi		# get the function address
   15.80 +	movl %eax, ORIG_EAX(%esp)
   15.81 +	movl %ecx, ES(%esp)
   15.82 +	movl %esp,%edx
   15.83 +	pushl %esi			# push the error code
   15.84 +	pushl %edx			# push the pt_regs pointer
   15.85 +	movl $(__KERNEL_DS),%edx
   15.86 +	movl %edx,%ds
   15.87 +	movl %edx,%es
   15.88 +	call *%edi
   15.89 +	addl $8,%esp
   15.90 +
   15.91 +        
   15.92 +ret_from_exception:
   15.93 +        movb CS(%esp),%cl
   15.94 +	test $2,%cl          # slow return to ring 2 or 3
   15.95 +	jne  safesti
   15.96 +        RESTORE_ALL
   15.97 +
   15.98 +# A note on the "critical region" in our callback handler.
   15.99 +# We want to avoid stacking callback handlers due to events occurring
  15.100 +# during handling of the last event. To do this, we keep events disabled
  15.101 +# until weve done all processing. HOWEVER, we must enable events before
  15.102 +# popping the stack frame (cant be done atomically) and so it would still
  15.103 +# be possible to get enough handler activations to overflow the stack.
  15.104 +# Although unlikely, bugs of that kind are hard to track down, so wed
  15.105 +# like to avoid the possibility.
  15.106 +# So, on entry to the handler we detect whether we interrupted an
  15.107 +# existing activation in its critical region -- if so, we pop the current
  15.108 +# activation and restart the handler using the previous one.
  15.109 +ENTRY(hypervisor_callback)
  15.110 +        pushl %eax
  15.111 +        SAVE_ALL
  15.112 +        movl EIP(%esp),%eax
  15.113 +        cmpl $scrit,%eax
  15.114 +        jb   11f
  15.115 +        cmpl $ecrit,%eax
  15.116 +        jb   critical_region_fixup
  15.117 +11:     push %esp
  15.118 +#        call do_hypervisor_callback
  15.119 +        add  $4,%esp
  15.120 +        movl HYPERVISOR_shared_info,%esi
  15.121 +        xorl %eax,%eax
  15.122 +        movb CS(%esp),%cl
  15.123 +    	test $2,%cl          # slow return to ring 2 or 3
  15.124 +        jne  safesti
  15.125 +safesti:btsl $31,4(%esi)     # reenable event callbacks
  15.126 +scrit:  /**** START OF CRITICAL REGION ****/
  15.127 +        cmpl %eax,(%esi)
  15.128 +        jne  14f              # process more events if necessary...
  15.129 +        RESTORE_ALL
  15.130 +14:     btrl %eax,4(%esi)
  15.131 +        jmp  11b
  15.132 +ecrit:  /**** END OF CRITICAL REGION ****/
  15.133 +# [How we do the fixup]. We want to merge the current stack frame with the
  15.134 +# just-interrupted frame. How we do this depends on where in the critical
  15.135 +# region the interrupted handler was executing, and so how many saved
  15.136 +# registers are in each frame. We do this quickly using the lookup table
  15.137 +# 'critical_fixup_table'. For each byte offset in the critical region, it
  15.138 +# provides the number of bytes which have already been popped from the
  15.139 +# interrupted stack frame. 
  15.140 +critical_region_fixup:
  15.141 +        addl $critical_fixup_table-scrit,%eax
  15.142 +        movzbl (%eax),%eax    # %eax contains num bytes popped
  15.143 +        mov  %esp,%esi
  15.144 +        add  %eax,%esi        # %esi points at end of src region
  15.145 +        mov  %esp,%edi
  15.146 +        add  $0x34,%edi       # %edi points at end of dst region
  15.147 +        mov  %eax,%ecx
  15.148 +        shr  $2,%ecx          # convert words to bytes
  15.149 +        je   16f              # skip loop if nothing to copy
  15.150 +15:     subl $4,%esi          # pre-decrementing copy loop
  15.151 +        subl $4,%edi
  15.152 +        movl (%esi),%eax
  15.153 +        movl %eax,(%edi)
  15.154 +        loop 15b
  15.155 +16:     movl %edi,%esp        # final %edi is top of merged stack
  15.156 +        jmp  11b
  15.157 +         
  15.158 +critical_fixup_table:        
  15.159 +        .byte 0x00,0x00                       # cmpl %eax,(%esi)
  15.160 +        .byte 0x00,0x00                       # jne  14f
  15.161 +        .byte 0x00                            # pop  %ebx
  15.162 +        .byte 0x04                            # pop  %ecx
  15.163 +        .byte 0x08                            # pop  %edx
  15.164 +        .byte 0x0c                            # pop  %esi
  15.165 +        .byte 0x10                            # pop  %edi
  15.166 +        .byte 0x14                            # pop  %ebp
  15.167 +        .byte 0x18                            # pop  %eax
  15.168 +        .byte 0x1c                            # pop  %ds
  15.169 +        .byte 0x20                            # pop  %es
  15.170 +        .byte 0x24,0x24,0x24                  # add  $4,%esp
  15.171 +        .byte 0x28                            # iret
  15.172 +        .byte 0x00,0x00,0x00,0x00,0x00        # btrl $31,4(%esi)
  15.173 +        .byte 0x00,0x00                       # jmp  11b
  15.174 +       
  15.175 +# Hypervisor uses this for application faults while it executes.
  15.176 +ENTRY(failsafe_callback)
  15.177 +      pop  %ds
  15.178 +      pop  %es
  15.179 +      pop  %fs
  15.180 +      pop  %gs
  15.181 +      iret
  15.182 +                
  15.183 +ENTRY(coprocessor_error)
  15.184 +	pushl $0
  15.185 +	pushl $do_coprocessor_error
  15.186 +	jmp do_exception
  15.187 +
  15.188 +ENTRY(simd_coprocessor_error)
  15.189 +	pushl $0
  15.190 +	pushl $do_simd_coprocessor_error
  15.191 +	jmp do_exception
  15.192 +
  15.193 +ENTRY(device_not_available)
  15.194 +        iret
  15.195 +
  15.196 +ENTRY(debug)
  15.197 +	pushl $0
  15.198 +	pushl $do_debug
  15.199 +	jmp do_exception
  15.200 +
  15.201 +ENTRY(int3)
  15.202 +	pushl $0
  15.203 +	pushl $do_int3
  15.204 +	jmp do_exception
  15.205 +
  15.206 +ENTRY(overflow)
  15.207 +	pushl $0
  15.208 +	pushl $do_overflow
  15.209 +	jmp do_exception
  15.210 +
  15.211 +ENTRY(bounds)
  15.212 +	pushl $0
  15.213 +	pushl $do_bounds
  15.214 +	jmp do_exception
  15.215 +
  15.216 +ENTRY(invalid_op)
  15.217 +	pushl $0
  15.218 +	pushl $do_invalid_op
  15.219 +	jmp do_exception
  15.220 +
  15.221 +ENTRY(coprocessor_segment_overrun)
  15.222 +	pushl $0
  15.223 +	pushl $do_coprocessor_segment_overrun
  15.224 +	jmp do_exception
  15.225 +
  15.226 +ENTRY(double_fault)
  15.227 +	pushl $do_double_fault
  15.228 +	jmp do_exception
  15.229 +
  15.230 +ENTRY(invalid_TSS)
  15.231 +	pushl $do_invalid_TSS
  15.232 +	jmp do_exception
  15.233 +
  15.234 +ENTRY(segment_not_present)
  15.235 +	pushl $do_segment_not_present
  15.236 +	jmp do_exception
  15.237 +
  15.238 +ENTRY(stack_segment)
  15.239 +	pushl $do_stack_segment
  15.240 +	jmp do_exception
  15.241 +
  15.242 +ENTRY(general_protection)
  15.243 +	pushl $do_general_protection
  15.244 +	jmp do_exception
  15.245 +
  15.246 +ENTRY(alignment_check)
  15.247 +	pushl $do_alignment_check
  15.248 +	jmp do_exception
  15.249 +
  15.250 +# This handler is special, because it gets an extra value on its stack,
  15.251 +# which is the linear faulting address.
  15.252 +ENTRY(page_fault)
  15.253 +	pushl %ds
  15.254 +	pushl %eax
  15.255 +	xorl %eax,%eax
  15.256 +	pushl %ebp
  15.257 +	pushl %edi
  15.258 +	pushl %esi
  15.259 +	pushl %edx
  15.260 +	decl %eax			# eax = -1
  15.261 +	pushl %ecx
  15.262 +	pushl %ebx
  15.263 +	cld
  15.264 +	movl %es,%ecx
  15.265 +	movl ORIG_EAX(%esp), %esi	# get the error code
  15.266 +	movl ES(%esp), %edi		# get the faulting address
  15.267 +	movl %eax, ORIG_EAX(%esp)
  15.268 +	movl %ecx, ES(%esp)
  15.269 +	movl %esp,%edx
  15.270 +        pushl %edi                      # push the faulting address
  15.271 +	pushl %esi			# push the error code
  15.272 +	pushl %edx			# push the pt_regs pointer
  15.273 +	movl $(__KERNEL_DS),%edx
  15.274 +	movl %edx,%ds
  15.275 +	movl %edx,%es
  15.276 +	call do_page_fault
  15.277 +	addl $12,%esp
  15.278 +	jmp ret_from_exception
  15.279 +
  15.280 +ENTRY(machine_check)
  15.281 +	pushl $0
  15.282 +	pushl $do_machine_check
  15.283 +	jmp do_exception
  15.284 +
  15.285 +ENTRY(spurious_interrupt_bug)
  15.286 +	pushl $0
  15.287 +	pushl $do_spurious_interrupt_bug
  15.288 +	jmp do_exception
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/extras/mini-os/x86_64.S	Fri Feb 11 14:37:07 2005 +0000
    16.3 @@ -0,0 +1,78 @@
    16.4 +#include <os.h>
    16.5 +
    16.6 +.section __xen_guest
    16.7 +        .asciz  "XEN_VER=2.0,LOADER=generic,PT_MODE_WRITABLE"
    16.8 +.text
    16.9 +
   16.10 +#define ENTRY(X) .globl X ; X :
   16.11 +.globl _start, shared_info
   16.12 +                        
   16.13 +_start:
   16.14 +        cld
   16.15 +        movq stack_start(%rip),%rsp
   16.16 +        movq %rsi,%rdi
   16.17 +        call start_kernel
   16.18 +
   16.19 +stack_start:
   16.20 +        .quad stack+8192
   16.21 +
   16.22 +        /* Unpleasant -- the PTE that maps this page is actually overwritten */
   16.23 +        /* to map the real shared-info page! :-)                             */
   16.24 +        .org 0x1000
   16.25 +shared_info:
   16.26 +        .org 0x2000
   16.27 +
   16.28 +ENTRY(hypervisor_callback)
   16.29 +
   16.30 +ENTRY(failsafe_callback)
   16.31 +      iret
   16.32 +                
   16.33 +ENTRY(divide_error)
   16.34 +	pushq $0
   16.35 +
   16.36 +ENTRY(coprocessor_error)
   16.37 +	pushq $0
   16.38 +
   16.39 +ENTRY(simd_coprocessor_error)
   16.40 +	pushq $0
   16.41 +
   16.42 +ENTRY(device_not_available)
   16.43 +        iret
   16.44 +
   16.45 +ENTRY(debug)
   16.46 +	pushq $0
   16.47 +
   16.48 +ENTRY(int3)
   16.49 +	pushq $0
   16.50 +
   16.51 +ENTRY(overflow)
   16.52 +	pushq $0
   16.53 +
   16.54 +ENTRY(bounds)
   16.55 +	pushq $0
   16.56 +
   16.57 +ENTRY(invalid_op)
   16.58 +	pushq $0
   16.59 +
   16.60 +ENTRY(coprocessor_segment_overrun)
   16.61 +	pushq $0
   16.62 +
   16.63 +ENTRY(double_fault)
   16.64 +
   16.65 +ENTRY(invalid_TSS)
   16.66 +
   16.67 +ENTRY(segment_not_present)
   16.68 +
   16.69 +ENTRY(stack_segment)
   16.70 +
   16.71 +ENTRY(general_protection)
   16.72 +
   16.73 +ENTRY(alignment_check)
   16.74 +
   16.75 +ENTRY(page_fault)
   16.76 +
   16.77 +ENTRY(machine_check)
   16.78 +	pushq $0
   16.79 +
   16.80 +ENTRY(spurious_interrupt_bug)
   16.81 +	pushq $0
    17.1 --- a/xen/arch/x86/traps.c	Fri Feb 11 13:06:19 2005 +0000
    17.2 +++ b/xen/arch/x86/traps.c	Fri Feb 11 14:37:07 2005 +0000
    17.3 @@ -510,7 +510,7 @@ asmlinkage int do_general_protection(str
    17.4      {
    17.5          /* This fault must be due to <INT n> instruction. */
    17.6          ti = current->arch.traps + (regs->error_code>>3);
    17.7 -        if ( TI_GET_DPL(ti) >= (VM86_MODE(regs) ? 3 : (regs->cs & 3)) )
    17.8 +        if ( PERMIT_SOFTINT(TI_GET_DPL(ti), ed, regs) )
    17.9          {
   17.10              tb->flags = TBF_EXCEPTION;
   17.11              regs->eip += 2;
    18.1 --- a/xen/arch/x86/x86_32/entry.S	Fri Feb 11 13:06:19 2005 +0000
    18.2 +++ b/xen/arch/x86/x86_32/entry.S	Fri Feb 11 14:37:07 2005 +0000
    18.3 @@ -256,6 +256,7 @@ FIX6:   pushl %ebx
    18.4          orb   $TF_failsafe_return,EDOMAIN_thread_flags(%ebx)
    18.5          pop   %ebx
    18.6          jmp   FIX5
    18.7 +.previous
    18.8  .section __pre_ex_table,"a"
    18.9  	.long FLT6,FIX6
   18.10  .previous
    19.1 --- a/xen/arch/x86/x86_64/entry.S	Fri Feb 11 13:06:19 2005 +0000
    19.2 +++ b/xen/arch/x86/x86_64/entry.S	Fri Feb 11 14:37:07 2005 +0000
    19.3 @@ -85,6 +85,7 @@ FIX2:   pushq %rbx
    19.4          orb   $TF_failsafe_return,EDOMAIN_thread_flags(%rbx)
    19.5          popq  %rbx
    19.6          jmp   FIX1
    19.7 +.previous
    19.8  .section __pre_ex_table,"a"
    19.9  	.quad FLT2,FIX2
   19.10  .previous
   19.11 @@ -287,8 +288,11 @@ 1:      sti
   19.12          movq  %rsp,%rdi
   19.13          movl  XREGS_entry_vector(%rsp),%eax
   19.14          leaq  SYMBOL_NAME(exception_table)(%rip),%rdx
   19.15 +        GET_CURRENT(%rbx)
   19.16          callq *(%rdx,%rax,8)
   19.17 -        jmp   restore_all_xen
   19.18 +        testb $3,XREGS_cs(%rsp)
   19.19 +        jz    restore_all_xen
   19.20 +        jmp   process_guest_exception_and_events
   19.21  
   19.22  exception_with_ints_disabled:
   19.23          testb $3,XREGS_cs(%rsp)         # interrupts disabled outside Xen?
   19.24 @@ -299,12 +303,15 @@ exception_with_ints_disabled:
   19.25          testq %rax,%rax                 # no fixup code for faulting EIP?
   19.26          jz    FATAL_exception_with_ints_disabled
   19.27          movq  %rax,XREGS_rip(%rsp)
   19.28 +        subq  $8,XREGS_rsp(%rsp)        # add ec/ev to previous stack frame
   19.29 +        testb $15,XREGS_rsp(%rsp)       # return %rsp is now aligned?
   19.30 +        jz    1f                        # then there is a pad quadword already
   19.31          movq  %rsp,%rsi
   19.32          subq  $8,%rsp
   19.33          movq  %rsp,%rdi
   19.34          movq  $XREGS_kernel_sizeof/8,%rcx
   19.35 -        rep;  movsq                     # make room for error_code/entry_vector
   19.36 -        movq  XREGS_error_code(%rsp),%rax # error_code/entry_vector
   19.37 +        rep;  movsq                     # make room for ec/ev
   19.38 +1:      movq  XREGS_error_code(%rsp),%rax # ec/ev
   19.39          movq  %rax,XREGS_kernel_sizeof(%rsp)
   19.40          jmp   restore_all_xen           # return to fixup code
   19.41  
    20.1 --- a/xen/include/asm-x86/x86_32/regs.h	Fri Feb 11 13:06:19 2005 +0000
    20.2 +++ b/xen/include/asm-x86/x86_32/regs.h	Fri Feb 11 14:37:07 2005 +0000
    20.3 @@ -12,4 +12,7 @@
    20.4  
    20.5  #define KERNEL_MODE(_e, _r) (!VM86_MODE(_r) && RING_1(_r))
    20.6  
    20.7 +#define PERMIT_SOFTINT(_dpl, _e, _r) \
    20.8 +    ((_dpl) >= (VM86_MODE(_r) ? 3 : ((_r)->cs & 3)))
    20.9 +
   20.10  #endif
    21.1 --- a/xen/include/asm-x86/x86_64/regs.h	Fri Feb 11 13:06:19 2005 +0000
    21.2 +++ b/xen/include/asm-x86/x86_64/regs.h	Fri Feb 11 14:37:07 2005 +0000
    21.3 @@ -12,4 +12,7 @@
    21.4  
    21.5  #define KERNEL_MODE(_e, _r) ((_e)->arch.flags & TF_kernel_mode)
    21.6  
    21.7 +#define PERMIT_SOFTINT(_dpl, _e, _r) \
    21.8 +    ((_dpl) >= (KERNEL_MODE(_e, _r) ? 1 : 3))
    21.9 +
   21.10  #endif
    22.1 --- a/xen/include/public/arch-x86_64.h	Fri Feb 11 13:06:19 2005 +0000
    22.2 +++ b/xen/include/public/arch-x86_64.h	Fri Feb 11 14:37:07 2005 +0000
    22.3 @@ -115,7 +115,14 @@ typedef unsigned long memory_t;   /* Ful
    22.4  typedef unsigned long cpureg_t;   /* Full-sized register.                    */
    22.5  
    22.6  /*
    22.7 - * Send an array of these to HYPERVISOR_set_trap_table()
    22.8 + * Send an array of these to HYPERVISOR_set_trap_table().
    22.9 + * N.B. As in x86/32 mode, the privilege level specifies which modes may enter
   22.10 + * a trap via a software interrupt. Since rings 1 and 2 are unavailable, we
   22.11 + * allocate privilege levels as follows:
   22.12 + *  Level == 0: Noone may enter
   22.13 + *  Level == 1: Kernel may enter
   22.14 + *  Level == 2: Kernel may enter
   22.15 + *  Level == 3: Everyone may enter
   22.16   */
   22.17  #define TI_GET_DPL(_ti)      ((_ti)->flags & 3)
   22.18  #define TI_GET_IF(_ti)       ((_ti)->flags & 4)