ia64/xen-unstable

changeset 3788:9877b62b4f26

bitkeeper revision 1.1177.1.1 (420c983eSjbjDYGF-fYWrXw_L7qkLA)

Mini-OS cleanups. Bug fixes in x86_64 assembly code.
Signed-off-by: keir.fraser@cl.cam.ac.uk
author kaf24@scramble.cl.cam.ac.uk
date Fri Feb 11 11:34:22 2005 +0000 (2005-02-11)
parents 2c95c08ed850
children 2686c08089bb
files .rootkeys 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 01:51:41 2005 +0000
     1.2 +++ b/.rootkeys	Fri Feb 11 11:34:22 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/extras/mini-os/Makefile	Fri Feb 11 01:51:41 2005 +0000
     2.2 +++ b/extras/mini-os/Makefile	Fri Feb 11 11:34:22 2005 +0000
     2.3 @@ -2,31 +2,44 @@
     2.4  CC := gcc
     2.5  LD := ld
     2.6  
     2.7 -# Linker should relocate monitor to this address
     2.8 -MONITOR_BASE := 0xE0100000
     2.9 +TARGET_ARCH := $(shell uname -m | sed -e s/i.86/x86_32/)
    2.10  
    2.11  # NB. '-Wcast-qual' is nasty, so I omitted it.
    2.12 -CFLAGS := -fno-builtin -O3 -Wall -Ih/ -Wredundant-decls
    2.13 -CFLAGS += -Wstrict-prototypes -Wnested-externs -Wpointer-arith -Winline -ansi
    2.14 +CFLAGS := -fno-builtin -O3 -Wall -Ih/ -Wredundant-decls -Wno-format
    2.15 +CFLAGS += -Wstrict-prototypes -Wnested-externs -Wpointer-arith -Winline
    2.16 +
    2.17 +ifeq ($(TARGET_ARCH),x86_32)
    2.18 +CFLAGS += -m32 -march=i686
    2.19 +LDFLAGS := -m elf_i386
    2.20 +endif
    2.21 +
    2.22 +ifeq ($(TARGET_ARCH),x86_64)
    2.23 +CFLAGS += -m64 -mno-red-zone -fpic -fno-reorder-blocks
    2.24 +CFLAGS += -fno-asynchronous-unwind-tables
    2.25 +LDFLAGS := -m elf_x86_64
    2.26 +endif
    2.27  
    2.28  TARGET := mini-os
    2.29  
    2.30 -LOBJS := lib/malloc.o lib/math.o lib/printf.o lib/string.o 
    2.31 -OBJS  := entry.o kernel.o traps.o hypervisor.o mm.o events.o time.o ${LOBJS}
    2.32 +OBJS := $(TARGET_ARCH).o
    2.33 +OBJS += $(patsubst %.c,%.o,$(wildcard *.c))
    2.34 +OBJS += $(patsubst %.c,%.o,$(wildcard lib/*.c))
    2.35  
    2.36 -HINTF := h/xen-public/xen.h
    2.37 -HDRS  :=  h/os.h h/types.h h/hypervisor.h h/mm.h h/events.h h/time.h h/lib.h
    2.38 -HDRS  += $(HINTF)
    2.39 +OBJS := $(subst events.o,,$(OBJS))
    2.40 +OBJS := $(subst hypervisor.o,,$(OBJS))
    2.41 +OBJS := $(subst time.o,,$(OBJS))
    2.42 +
    2.43 +HDRS := $(wildcard h/*.h)
    2.44 +HDRS += $(wildcard h/xen-public/*.h)
    2.45  
    2.46  default: $(TARGET)
    2.47  
    2.48  xen-public:
    2.49 -	[ -e h/xen-public] || ln -sf ../../../xen/include/public h/xen-public
    2.50 +	[ -e h/xen-public ] || ln -sf ../../../xen/include/public h/xen-public
    2.51  
    2.52 -$(TARGET): xen-public head.o $(OBJS)
    2.53 -	$(LD) -N -T minios.lds head.o $(OBJS) -o $@.elf
    2.54 -	objcopy -R .note -R .comment $@.elf $@
    2.55 -	gzip -f -9 -c $@ >$@.gz
    2.56 +$(TARGET): xen-public $(OBJS)
    2.57 +	$(LD) -N -T minios-$(TARGET_ARCH).lds $(OBJS) -o $@.elf
    2.58 +	gzip -f -9 -c $@.elf >$@.gz
    2.59  
    2.60  clean:
    2.61  	find . -type f -name '*.o' | xargs rm -f
    2.62 @@ -38,4 +51,3 @@ clean:
    2.63  
    2.64  %.o: %.S $(HDRS) Makefile
    2.65  	$(CC) $(CFLAGS) -D__ASSEMBLY__ -c $< -o $@
    2.66 -
     3.1 --- a/extras/mini-os/entry.S	Fri Feb 11 01:51:41 2005 +0000
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,265 +0,0 @@
     3.4 -        
     3.5 -#include <os.h>
     3.6 -
     3.7 -ES		= 0x20
     3.8 -ORIG_EAX	= 0x24
     3.9 -EIP		= 0x28
    3.10 -CS		= 0x2C
    3.11 -
    3.12 -#define ENTRY(X) .globl X ; X :
    3.13 -
    3.14 -#define SAVE_ALL \
    3.15 -	cld; \
    3.16 -	pushl %es; \
    3.17 -	pushl %ds; \
    3.18 -	pushl %eax; \
    3.19 -	pushl %ebp; \
    3.20 -	pushl %edi; \
    3.21 -	pushl %esi; \
    3.22 -	pushl %edx; \
    3.23 -	pushl %ecx; \
    3.24 -	pushl %ebx; \
    3.25 -	movl $(__KERNEL_DS),%edx; \
    3.26 -	movl %edx,%ds; \
    3.27 -	movl %edx,%es;
    3.28 -
    3.29 -#define RESTORE_ALL	\
    3.30 -	popl %ebx;	\
    3.31 -	popl %ecx;	\
    3.32 -	popl %edx;	\
    3.33 -	popl %esi;	\
    3.34 -	popl %edi;	\
    3.35 -	popl %ebp;	\
    3.36 -	popl %eax;	\
    3.37 -	popl %ds;	\
    3.38 -	popl %es;	\
    3.39 -	addl $4,%esp;	\
    3.40 -	iret;		\
    3.41 -
    3.42 -ENTRY(divide_error)
    3.43 -	pushl $0		# no error code
    3.44 -	pushl $do_divide_error
    3.45 -do_exception:
    3.46 -	pushl %ds
    3.47 -	pushl %eax
    3.48 -	xorl %eax,%eax
    3.49 -	pushl %ebp
    3.50 -	pushl %edi
    3.51 -	pushl %esi
    3.52 -	pushl %edx
    3.53 -	decl %eax			# eax = -1
    3.54 -	pushl %ecx
    3.55 -	pushl %ebx
    3.56 -	cld
    3.57 -	movl %es,%ecx
    3.58 -	movl ORIG_EAX(%esp), %esi	# get the error code
    3.59 -	movl ES(%esp), %edi		# get the function address
    3.60 -	movl %eax, ORIG_EAX(%esp)
    3.61 -	movl %ecx, ES(%esp)
    3.62 -	movl %esp,%edx
    3.63 -	pushl %esi			# push the error code
    3.64 -	pushl %edx			# push the pt_regs pointer
    3.65 -	movl $(__KERNEL_DS),%edx
    3.66 -	movl %edx,%ds
    3.67 -	movl %edx,%es
    3.68 -	call *%edi
    3.69 -	addl $8,%esp
    3.70 -
    3.71 -        
    3.72 -ret_from_exception:
    3.73 -        movb CS(%esp),%cl
    3.74 -	test $2,%cl          # slow return to ring 2 or 3
    3.75 -	jne  safesti
    3.76 -        RESTORE_ALL
    3.77 -
    3.78 -# A note on the "critical region" in our callback handler.
    3.79 -# We want to avoid stacking callback handlers due to events occurring
    3.80 -# during handling of the last event. To do this, we keep events disabled
    3.81 -# until weve done all processing. HOWEVER, we must enable events before
    3.82 -# popping the stack frame (cant be done atomically) and so it would still
    3.83 -# be possible to get enough handler activations to overflow the stack.
    3.84 -# Although unlikely, bugs of that kind are hard to track down, so wed
    3.85 -# like to avoid the possibility.
    3.86 -# So, on entry to the handler we detect whether we interrupted an
    3.87 -# existing activation in its critical region -- if so, we pop the current
    3.88 -# activation and restart the handler using the previous one.
    3.89 -ENTRY(hypervisor_callback)
    3.90 -        pushl %eax
    3.91 -        SAVE_ALL
    3.92 -        movl EIP(%esp),%eax
    3.93 -        cmpl $scrit,%eax
    3.94 -        jb   11f
    3.95 -        cmpl $ecrit,%eax
    3.96 -        jb   critical_region_fixup
    3.97 -11:     push %esp
    3.98 -        call do_hypervisor_callback
    3.99 -        add  $4,%esp
   3.100 -        movl HYPERVISOR_shared_info,%esi
   3.101 -        xorl %eax,%eax
   3.102 -        movb CS(%esp),%cl
   3.103 -    	test $2,%cl          # slow return to ring 2 or 3
   3.104 -        jne  safesti
   3.105 -safesti:btsl $31,4(%esi)     # reenable event callbacks
   3.106 -scrit:  /**** START OF CRITICAL REGION ****/
   3.107 -        cmpl %eax,(%esi)
   3.108 -        jne  14f              # process more events if necessary...
   3.109 -        RESTORE_ALL
   3.110 -14:     btrl %eax,4(%esi)
   3.111 -        jmp  11b
   3.112 -ecrit:  /**** END OF CRITICAL REGION ****/
   3.113 -# [How we do the fixup]. We want to merge the current stack frame with the
   3.114 -# just-interrupted frame. How we do this depends on where in the critical
   3.115 -# region the interrupted handler was executing, and so how many saved
   3.116 -# registers are in each frame. We do this quickly using the lookup table
   3.117 -# 'critical_fixup_table'. For each byte offset in the critical region, it
   3.118 -# provides the number of bytes which have already been popped from the
   3.119 -# interrupted stack frame. 
   3.120 -critical_region_fixup:
   3.121 -        addl $critical_fixup_table-scrit,%eax
   3.122 -        movzbl (%eax),%eax    # %eax contains num bytes popped
   3.123 -        mov  %esp,%esi
   3.124 -        add  %eax,%esi        # %esi points at end of src region
   3.125 -        mov  %esp,%edi
   3.126 -        add  $0x34,%edi       # %edi points at end of dst region
   3.127 -        mov  %eax,%ecx
   3.128 -        shr  $2,%ecx          # convert words to bytes
   3.129 -        je   16f              # skip loop if nothing to copy
   3.130 -15:     subl $4,%esi          # pre-decrementing copy loop
   3.131 -        subl $4,%edi
   3.132 -        movl (%esi),%eax
   3.133 -        movl %eax,(%edi)
   3.134 -        loop 15b
   3.135 -16:     movl %edi,%esp        # final %edi is top of merged stack
   3.136 -        jmp  11b
   3.137 -         
   3.138 -critical_fixup_table:        
   3.139 -        .byte 0x00,0x00                       # cmpl %eax,(%esi)
   3.140 -        .byte 0x00,0x00                       # jne  14f
   3.141 -        .byte 0x00                            # pop  %ebx
   3.142 -        .byte 0x04                            # pop  %ecx
   3.143 -        .byte 0x08                            # pop  %edx
   3.144 -        .byte 0x0c                            # pop  %esi
   3.145 -        .byte 0x10                            # pop  %edi
   3.146 -        .byte 0x14                            # pop  %ebp
   3.147 -        .byte 0x18                            # pop  %eax
   3.148 -        .byte 0x1c                            # pop  %ds
   3.149 -        .byte 0x20                            # pop  %es
   3.150 -        .byte 0x24,0x24,0x24                  # add  $4,%esp
   3.151 -        .byte 0x28                            # iret
   3.152 -        .byte 0x00,0x00,0x00,0x00,0x00        # btrl $31,4(%esi)
   3.153 -        .byte 0x00,0x00                       # jmp  11b
   3.154 -       
   3.155 -# Hypervisor uses this for application faults while it executes.
   3.156 -ENTRY(failsafe_callback)
   3.157 -      pop  %ds
   3.158 -      pop  %es
   3.159 -      pop  %fs
   3.160 -      pop  %gs
   3.161 -      iret
   3.162 -                
   3.163 -ENTRY(coprocessor_error)
   3.164 -	pushl $0
   3.165 -	pushl $do_coprocessor_error
   3.166 -	jmp do_exception
   3.167 -
   3.168 -ENTRY(simd_coprocessor_error)
   3.169 -	pushl $0
   3.170 -	pushl $do_simd_coprocessor_error
   3.171 -	jmp do_exception
   3.172 -
   3.173 -ENTRY(device_not_available)
   3.174 -        iret
   3.175 -
   3.176 -ENTRY(debug)
   3.177 -	pushl $0
   3.178 -	pushl $do_debug
   3.179 -	jmp do_exception
   3.180 -
   3.181 -ENTRY(int3)
   3.182 -	pushl $0
   3.183 -	pushl $do_int3
   3.184 -	jmp do_exception
   3.185 -
   3.186 -ENTRY(overflow)
   3.187 -	pushl $0
   3.188 -	pushl $do_overflow
   3.189 -	jmp do_exception
   3.190 -
   3.191 -ENTRY(bounds)
   3.192 -	pushl $0
   3.193 -	pushl $do_bounds
   3.194 -	jmp do_exception
   3.195 -
   3.196 -ENTRY(invalid_op)
   3.197 -	pushl $0
   3.198 -	pushl $do_invalid_op
   3.199 -	jmp do_exception
   3.200 -
   3.201 -ENTRY(coprocessor_segment_overrun)
   3.202 -	pushl $0
   3.203 -	pushl $do_coprocessor_segment_overrun
   3.204 -	jmp do_exception
   3.205 -
   3.206 -ENTRY(double_fault)
   3.207 -	pushl $do_double_fault
   3.208 -	jmp do_exception
   3.209 -
   3.210 -ENTRY(invalid_TSS)
   3.211 -	pushl $do_invalid_TSS
   3.212 -	jmp do_exception
   3.213 -
   3.214 -ENTRY(segment_not_present)
   3.215 -	pushl $do_segment_not_present
   3.216 -	jmp do_exception
   3.217 -
   3.218 -ENTRY(stack_segment)
   3.219 -	pushl $do_stack_segment
   3.220 -	jmp do_exception
   3.221 -
   3.222 -ENTRY(general_protection)
   3.223 -	pushl $do_general_protection
   3.224 -	jmp do_exception
   3.225 -
   3.226 -ENTRY(alignment_check)
   3.227 -	pushl $do_alignment_check
   3.228 -	jmp do_exception
   3.229 -
   3.230 -# This handler is special, because it gets an extra value on its stack,
   3.231 -# which is the linear faulting address.
   3.232 -ENTRY(page_fault)
   3.233 -	pushl %ds
   3.234 -	pushl %eax
   3.235 -	xorl %eax,%eax
   3.236 -	pushl %ebp
   3.237 -	pushl %edi
   3.238 -	pushl %esi
   3.239 -	pushl %edx
   3.240 -	decl %eax			# eax = -1
   3.241 -	pushl %ecx
   3.242 -	pushl %ebx
   3.243 -	cld
   3.244 -	movl %es,%ecx
   3.245 -	movl ORIG_EAX(%esp), %esi	# get the error code
   3.246 -	movl ES(%esp), %edi		# get the faulting address
   3.247 -	movl %eax, ORIG_EAX(%esp)
   3.248 -	movl %ecx, ES(%esp)
   3.249 -	movl %esp,%edx
   3.250 -        pushl %edi                      # push the faulting address
   3.251 -	pushl %esi			# push the error code
   3.252 -	pushl %edx			# push the pt_regs pointer
   3.253 -	movl $(__KERNEL_DS),%edx
   3.254 -	movl %edx,%ds
   3.255 -	movl %edx,%es
   3.256 -	call do_page_fault
   3.257 -	addl $12,%esp
   3.258 -	jmp ret_from_exception
   3.259 -
   3.260 -ENTRY(machine_check)
   3.261 -	pushl $0
   3.262 -	pushl $do_machine_check
   3.263 -	jmp do_exception
   3.264 -
   3.265 -ENTRY(spurious_interrupt_bug)
   3.266 -	pushl $0
   3.267 -	pushl $do_spurious_interrupt_bug
   3.268 -	jmp do_exception
     4.1 --- a/extras/mini-os/h/hypervisor.h	Fri Feb 11 01:51:41 2005 +0000
     4.2 +++ b/extras/mini-os/h/hypervisor.h	Fri Feb 11 11:34:22 2005 +0000
     4.3 @@ -36,13 +36,25 @@ void ack_hypervisor_event(unsigned int e
     4.4   * Assembler stubs for hyper-calls.
     4.5   */
     4.6  
     4.7 +#ifdef __i386__
     4.8 +#define _a1 "b"
     4.9 +#define _a2 "c"
    4.10 +#define _a3 "d"
    4.11 +#define _a4 "S"
    4.12 +#else
    4.13 +#define _a1 "D"
    4.14 +#define _a2 "S"
    4.15 +#define _a3 "d"
    4.16 +#define _a4 "b"
    4.17 +#endif
    4.18 +
    4.19  static __inline__ int HYPERVISOR_set_trap_table(trap_info_t *table)
    4.20  {
    4.21      int ret;
    4.22      __asm__ __volatile__ (
    4.23          TRAP_INSTR
    4.24          : "=a" (ret) : "0" (__HYPERVISOR_set_trap_table),
    4.25 -        "b" (table) : "memory" );
    4.26 +        _a1 (table) : "memory" );
    4.27  
    4.28      return ret;
    4.29  }
    4.30 @@ -55,7 +67,7 @@ static __inline__ int HYPERVISOR_mmu_upd
    4.31      __asm__ __volatile__ (
    4.32          TRAP_INSTR
    4.33          : "=a" (ret) : "0" (__HYPERVISOR_mmu_update), 
    4.34 -        "b" (req), "c" (count), "d" (success_count)  : "memory" );
    4.35 +        _a1 (req), _a2 (count), _a3 (success_count)  : "memory" );
    4.36  
    4.37      return ret;
    4.38  }
    4.39 @@ -66,7 +78,7 @@ static __inline__ int HYPERVISOR_set_gdt
    4.40      __asm__ __volatile__ (
    4.41          TRAP_INSTR
    4.42          : "=a" (ret) : "0" (__HYPERVISOR_set_gdt), 
    4.43 -        "b" (frame_list), "c" (entries) : "memory" );
    4.44 +        _a1 (frame_list), _a2 (entries) : "memory" );
    4.45  
    4.46  
    4.47      return ret;
    4.48 @@ -78,11 +90,12 @@ static __inline__ int HYPERVISOR_stack_s
    4.49      __asm__ __volatile__ (
    4.50          TRAP_INSTR
    4.51          : "=a" (ret) : "0" (__HYPERVISOR_stack_switch),
    4.52 -        "b" (ss), "c" (esp) : "memory" );
    4.53 +        _a1 (ss), _a2 (esp) : "memory" );
    4.54  
    4.55      return ret;
    4.56  }
    4.57  
    4.58 +#ifdef __i386__
    4.59  static __inline__ int HYPERVISOR_set_callbacks(
    4.60      unsigned long event_selector, unsigned long event_address,
    4.61      unsigned long failsafe_selector, unsigned long failsafe_address)
    4.62 @@ -91,11 +104,27 @@ static __inline__ int HYPERVISOR_set_cal
    4.63      __asm__ __volatile__ (
    4.64          TRAP_INSTR
    4.65          : "=a" (ret) : "0" (__HYPERVISOR_set_callbacks),
    4.66 -        "b" (event_selector), "c" (event_address), 
    4.67 -        "d" (failsafe_selector), "S" (failsafe_address) : "memory" );
    4.68 +        _a1 (event_selector), _a2 (event_address), 
    4.69 +        _a3 (failsafe_selector), _a4 (failsafe_address) : "memory" );
    4.70  
    4.71      return ret;
    4.72  }
    4.73 +#else
    4.74 +static __inline__ int HYPERVISOR_set_callbacks(
    4.75 +    unsigned long event_address,
    4.76 +    unsigned long failsafe_address,
    4.77 +    unsigned long syscall_address)
    4.78 +{
    4.79 +    int ret;
    4.80 +    __asm__ __volatile__ (
    4.81 +        TRAP_INSTR
    4.82 +        : "=a" (ret) : "0" (__HYPERVISOR_set_callbacks),
    4.83 +        _a1 (event_address), _a2 (failsafe_address), 
    4.84 +        _a3 (syscall_address) : "memory" );
    4.85 +
    4.86 +    return ret;
    4.87 +}
    4.88 +#endif
    4.89  
    4.90  static __inline__ int HYPERVISOR_fpu_taskswitch(void)
    4.91  {
    4.92 @@ -113,7 +142,7 @@ static __inline__ int HYPERVISOR_yield(v
    4.93      __asm__ __volatile__ (
    4.94          TRAP_INSTR
    4.95          : "=a" (ret) : "0" (__HYPERVISOR_sched_op),
    4.96 -        "b" (SCHEDOP_yield) : "memory" );
    4.97 +        _a1 (SCHEDOP_yield) : "memory" );
    4.98  
    4.99      return ret;
   4.100  }
   4.101 @@ -124,7 +153,7 @@ static __inline__ int HYPERVISOR_block(v
   4.102      __asm__ __volatile__ (
   4.103          TRAP_INSTR
   4.104          : "=a" (ret) : "0" (__HYPERVISOR_sched_op),
   4.105 -        "b" (SCHEDOP_block) : "memory" );
   4.106 +        _a1 (SCHEDOP_block) : "memory" );
   4.107  
   4.108      return ret;
   4.109  }
   4.110 @@ -135,7 +164,7 @@ static __inline__ int HYPERVISOR_shutdow
   4.111      __asm__ __volatile__ (
   4.112          TRAP_INSTR
   4.113          : "=a" (ret) : "0" (__HYPERVISOR_sched_op),
   4.114 -        "b" (SCHEDOP_shutdown | (SHUTDOWN_poweroff << SCHEDOP_reasonshift))
   4.115 +        _a1 (SCHEDOP_shutdown | (SHUTDOWN_poweroff << SCHEDOP_reasonshift))
   4.116          : "memory" );
   4.117  
   4.118      return ret;
   4.119 @@ -147,7 +176,7 @@ static __inline__ int HYPERVISOR_reboot(
   4.120      __asm__ __volatile__ (
   4.121          TRAP_INSTR
   4.122          : "=a" (ret) : "0" (__HYPERVISOR_sched_op),
   4.123 -        "b" (SCHEDOP_shutdown | (SHUTDOWN_reboot << SCHEDOP_reasonshift))
   4.124 +        _a1 (SCHEDOP_shutdown | (SHUTDOWN_reboot << SCHEDOP_reasonshift))
   4.125          : "memory" );
   4.126  
   4.127      return ret;
   4.128 @@ -160,7 +189,7 @@ static __inline__ int HYPERVISOR_suspend
   4.129      __asm__ __volatile__ (
   4.130          TRAP_INSTR
   4.131          : "=a" (ret) : "0" (__HYPERVISOR_sched_op),
   4.132 -        "b" (SCHEDOP_shutdown | (SHUTDOWN_suspend << SCHEDOP_reasonshift)), 
   4.133 +        _a1 (SCHEDOP_shutdown | (SHUTDOWN_suspend << SCHEDOP_reasonshift)), 
   4.134          "S" (srec) : "memory" );
   4.135  
   4.136      return ret;
   4.137 @@ -172,7 +201,7 @@ static __inline__ long HYPERVISOR_set_ti
   4.138      __asm__ __volatile__ (
   4.139          TRAP_INSTR
   4.140          : "=a" (ret) : "0" (__HYPERVISOR_set_timer_op),
   4.141 -        "b" (timer_arg) : "memory" );
   4.142 +        _a1 (timer_arg) : "memory" );
   4.143  
   4.144      return ret;
   4.145  }
   4.146 @@ -183,7 +212,7 @@ static __inline__ int HYPERVISOR_dom0_op
   4.147      __asm__ __volatile__ (
   4.148          TRAP_INSTR
   4.149          : "=a" (ret) : "0" (__HYPERVISOR_dom0_op),
   4.150 -        "b" (dom0_op) : "memory" );
   4.151 +        _a1 (dom0_op) : "memory" );
   4.152  
   4.153      return ret;
   4.154  }
   4.155 @@ -194,7 +223,7 @@ static __inline__ int HYPERVISOR_set_deb
   4.156      __asm__ __volatile__ (
   4.157          TRAP_INSTR
   4.158          : "=a" (ret) : "0" (__HYPERVISOR_set_debugreg),
   4.159 -        "b" (reg), "c" (value) : "memory" );
   4.160 +        _a1 (reg), _a2 (value) : "memory" );
   4.161  
   4.162      return ret;
   4.163  }
   4.164 @@ -205,7 +234,7 @@ static __inline__ unsigned long HYPERVIS
   4.165      __asm__ __volatile__ (
   4.166          TRAP_INSTR
   4.167          : "=a" (ret) : "0" (__HYPERVISOR_get_debugreg),
   4.168 -        "b" (reg) : "memory" );
   4.169 +        _a1 (reg) : "memory" );
   4.170  
   4.171      return ret;
   4.172  }
   4.173 @@ -217,7 +246,7 @@ static __inline__ int HYPERVISOR_update_
   4.174      __asm__ __volatile__ (
   4.175          TRAP_INSTR
   4.176          : "=a" (ret) : "0" (__HYPERVISOR_update_descriptor), 
   4.177 -        "b" (pa), "c" (word1), "d" (word2) : "memory" );
   4.178 +        _a1 (pa), _a2 (word1), _a3 (word2) : "memory" );
   4.179  
   4.180      return ret;
   4.181  }
   4.182 @@ -228,7 +257,7 @@ static __inline__ int HYPERVISOR_set_fas
   4.183      __asm__ __volatile__ (
   4.184          TRAP_INSTR
   4.185          : "=a" (ret) : "0" (__HYPERVISOR_set_fast_trap), 
   4.186 -        "b" (idx) : "memory" );
   4.187 +        _a1 (idx) : "memory" );
   4.188  
   4.189      return ret;
   4.190  }
   4.191 @@ -239,7 +268,7 @@ static __inline__ int HYPERVISOR_dom_mem
   4.192      __asm__ __volatile__ (
   4.193          TRAP_INSTR
   4.194          : "=a" (ret) : "0" (__HYPERVISOR_dom_mem_op),
   4.195 -        "b" (dom_mem_op) : "memory" );
   4.196 +        _a1 (dom_mem_op) : "memory" );
   4.197  
   4.198      return ret;
   4.199  }
   4.200 @@ -250,7 +279,7 @@ static __inline__ int HYPERVISOR_multica
   4.201      __asm__ __volatile__ (
   4.202          TRAP_INSTR
   4.203          : "=a" (ret) : "0" (__HYPERVISOR_multicall),
   4.204 -        "b" (call_list), "c" (nr_calls) : "memory" );
   4.205 +        _a1 (call_list), _a2 (nr_calls) : "memory" );
   4.206  
   4.207      return ret;
   4.208  }
   4.209 @@ -262,7 +291,7 @@ static __inline__ int HYPERVISOR_update_
   4.210      __asm__ __volatile__ (
   4.211          TRAP_INSTR
   4.212          : "=a" (ret) : "0" (__HYPERVISOR_update_va_mapping), 
   4.213 -        "b" (page_nr), "c" (new_val), "d" (flags) : "memory" );
   4.214 +        _a1 (page_nr), _a2 (new_val), _a3 (flags) : "memory" );
   4.215  
   4.216      return ret;
   4.217  }
   4.218 @@ -273,7 +302,7 @@ static __inline__ int HYPERVISOR_xen_ver
   4.219      __asm__ __volatile__ (
   4.220          TRAP_INSTR
   4.221          : "=a" (ret) : "0" (__HYPERVISOR_xen_version), 
   4.222 -        "b" (cmd) : "memory" );
   4.223 +        _a1 (cmd) : "memory" );
   4.224  
   4.225      return ret;
   4.226  }
   4.227 @@ -284,7 +313,7 @@ static __inline__ int HYPERVISOR_console
   4.228      __asm__ __volatile__ (
   4.229          TRAP_INSTR
   4.230          : "=a" (ret) : "0" (__HYPERVISOR_console_io),
   4.231 -        "b" (cmd), "c" (count), "d" (str) : "memory" );
   4.232 +        _a1 (cmd), _a2 (count), _a3 (str) : "memory" );
   4.233  
   4.234      return ret;
   4.235  }
     5.1 --- a/extras/mini-os/h/mm.h	Fri Feb 11 01:51:41 2005 +0000
     5.2 +++ b/extras/mini-os/h/mm.h	Fri Feb 11 11:34:22 2005 +0000
     5.3 @@ -64,7 +64,11 @@ static __inline__ unsigned long machine_
     5.4      return phys;
     5.5  }
     5.6  
     5.7 +#ifdef __x86_64__
     5.8 +#define VIRT_START              0xFFFFFFFF00000000UL
     5.9 +#else
    5.10  #define VIRT_START              0xC0000000UL
    5.11 +#endif
    5.12  
    5.13  #define to_phys(x)                 ((unsigned long)(x)-VIRT_START)
    5.14  #define to_virt(x)                 ((void *)((unsigned long)(x)+VIRT_START))
     6.1 --- a/extras/mini-os/h/os.h	Fri Feb 11 01:51:41 2005 +0000
     6.2 +++ b/extras/mini-os/h/os.h	Fri Feb 11 11:34:22 2005 +0000
     6.3 @@ -9,116 +9,108 @@
     6.4  
     6.5  #define NULL 0
     6.6  
     6.7 -/* Somewhere in the middle of the GCC 2.96 development cycle, we implemented
     6.8 -   a mechanism by which the user can annotate likely branch directions and
     6.9 -   expect the blocks to be reordered appropriately.  Define __builtin_expect
    6.10 -   to nothing for earlier compilers.  */
    6.11 -
    6.12  #if __GNUC__ == 2 && __GNUC_MINOR__ < 96
    6.13  #define __builtin_expect(x, expected_value) (x)
    6.14  #endif
    6.15 +#define unlikely(x)  __builtin_expect((x),0)
    6.16  
    6.17 -/*
    6.18 - * These are the segment descriptors provided for us by the hypervisor.
    6.19 - * For now, these are hardwired -- guest OSes cannot update the GDT
    6.20 - * or LDT.
    6.21 - * 
    6.22 - * It shouldn't be hard to support descriptor-table frobbing -- let me 
    6.23 - * know if the BSD or XP ports require flexibility here.
    6.24 - */
    6.25 +#define smp_processor_id() 0
    6.26 +#define preempt_disable() ((void)0)
    6.27 +#define preempt_enable() ((void)0)
    6.28  
    6.29 +#define force_evtchn_callback() ((void)HYPERVISOR_xen_version(0))
    6.30  
    6.31 -/*
    6.32 - * these are also defined in xen-public/xen.h but can't be pulled in as
    6.33 - * they are used in start of day assembly. Need to clean up the .h files
    6.34 - * a bit more...
    6.35 - */
    6.36 +#ifndef __ASSEMBLY__
    6.37 +#include <types.h>
    6.38 +#endif
    6.39 +#include <xen-public/xen.h>
    6.40  
    6.41 -#ifndef FLAT_RING1_CS
    6.42 -#define FLAT_RING1_CS		0x0819
    6.43 -#define FLAT_RING1_DS		0x0821
    6.44 -#define FLAT_RING3_CS		0x082b
    6.45 -#define FLAT_RING3_DS		0x0833
    6.46 -#endif
    6.47 -
    6.48 -#define __KERNEL_CS        FLAT_RING1_CS
    6.49 -#define __KERNEL_DS        FLAT_RING1_DS
    6.50 +#define __KERNEL_CS  FLAT_KERNEL_CS
    6.51 +#define __KERNEL_DS  FLAT_KERNEL_DS
    6.52 +#define __KERNEL_SS  FLAT_KERNEL_SS
    6.53  
    6.54  /* Everything below this point is not included by assembler (.S) files. */
    6.55  #ifndef __ASSEMBLY__
    6.56  
    6.57 -#include <types.h>
    6.58 -#include <xen-public/xen.h>
    6.59 -
    6.60 +#define pt_regs xen_regs
    6.61  
    6.62 -/* this struct defines the way the registers are stored on the 
    6.63 -   stack during an exception or interrupt. */
    6.64 -struct pt_regs {
    6.65 -	long ebx;
    6.66 -	long ecx;
    6.67 -	long edx;
    6.68 -	long esi;
    6.69 -	long edi;
    6.70 -	long ebp;
    6.71 -	long eax;
    6.72 -	int  xds;
    6.73 -	int  xes;
    6.74 -	long orig_eax;
    6.75 -	long eip;
    6.76 -	int  xcs;
    6.77 -	long eflags;
    6.78 -	long esp;
    6.79 -	int  xss;
    6.80 -};
    6.81 -
    6.82 -/* some function prototypes */
    6.83  void trap_init(void);
    6.84  void dump_regs(struct pt_regs *regs);
    6.85  
    6.86 -
    6.87 -/*
    6.88 - * STI/CLI equivalents. These basically set and clear the virtual
    6.89 - * event_enable flag in teh shared_info structure. Note that when
    6.90 - * the enable bit is set, there may be pending events to be handled.
    6.91 - * We may therefore call into do_hypervisor_callback() directly.
    6.92 +/* 
    6.93 + * The use of 'barrier' in the following reflects their use as local-lock
    6.94 + * operations. Reentrancy must be prevented (e.g., __cli()) /before/ following
    6.95 + * critical operations are executed. All critical operations must complete
    6.96 + * /before/ reentrancy is permitted (e.g., __sti()). Alpha architecture also
    6.97 + * includes these barriers, for example.
    6.98   */
    6.99 -#define unlikely(x)  __builtin_expect((x),0)
   6.100 -#define __save_flags(x)                                                       \
   6.101 -do {                                                                          \
   6.102 -    (x) = test_bit(EVENTS_MASTER_ENABLE_BIT,                                  \
   6.103 -                   &HYPERVISOR_shared_info->events_mask);                     \
   6.104 -    barrier();                                                                \
   6.105 +
   6.106 +#define __cli()								\
   6.107 +do {									\
   6.108 +	vcpu_info_t *_vcpu;						\
   6.109 +	preempt_disable();						\
   6.110 +	_vcpu = &HYPERVISOR_shared_info->vcpu_data[smp_processor_id()];	\
   6.111 +	_vcpu->evtchn_upcall_mask = 1;					\
   6.112 +	preempt_enable_no_resched();					\
   6.113 +	barrier();							\
   6.114 +} while (0)
   6.115 +
   6.116 +#define __sti()								\
   6.117 +do {									\
   6.118 +	vcpu_info_t *_vcpu;						\
   6.119 +	barrier();							\
   6.120 +	preempt_disable();						\
   6.121 +	_vcpu = &HYPERVISOR_shared_info->vcpu_data[smp_processor_id()];	\
   6.122 +	_vcpu->evtchn_upcall_mask = 0;					\
   6.123 +	barrier(); /* unmask then check (avoid races) */		\
   6.124 +	if ( unlikely(_vcpu->evtchn_upcall_pending) )			\
   6.125 +		force_evtchn_callback();				\
   6.126 +	preempt_enable();						\
   6.127  } while (0)
   6.128  
   6.129 -#define __restore_flags(x)                                                    \
   6.130 -do {                                                                          \
   6.131 -    shared_info_t *_shared = HYPERVISOR_shared_info;                          \
   6.132 -    if (x) set_bit(EVENTS_MASTER_ENABLE_BIT, &_shared->events_mask);          \
   6.133 -    barrier();                                                                \
   6.134 -    if ( unlikely(_shared->events) && (x) ) do_hypervisor_callback(NULL);     \
   6.135 +#define __save_flags(x)							\
   6.136 +do {									\
   6.137 +	vcpu_info_t *_vcpu;						\
   6.138 +	_vcpu = &HYPERVISOR_shared_info->vcpu_data[smp_processor_id()];	\
   6.139 +	(x) = _vcpu->evtchn_upcall_mask;				\
   6.140  } while (0)
   6.141  
   6.142 -#define __cli()                                                               \
   6.143 -do {                                                                          \
   6.144 -    clear_bit(EVENTS_MASTER_ENABLE_BIT, &HYPERVISOR_shared_info->events_mask);\
   6.145 -    barrier();                                                                \
   6.146 +#define __restore_flags(x)						\
   6.147 +do {									\
   6.148 +	vcpu_info_t *_vcpu;						\
   6.149 +	barrier();							\
   6.150 +	preempt_disable();						\
   6.151 +	_vcpu = &HYPERVISOR_shared_info->vcpu_data[smp_processor_id()];	\
   6.152 +	if ((_vcpu->evtchn_upcall_mask = (x)) == 0) {			\
   6.153 +		barrier(); /* unmask then check (avoid races) */	\
   6.154 +		if ( unlikely(_vcpu->evtchn_upcall_pending) )		\
   6.155 +			force_evtchn_callback();			\
   6.156 +		preempt_enable();					\
   6.157 +	} else								\
   6.158 +		preempt_enable_no_resched();				\
   6.159  } while (0)
   6.160  
   6.161 -#define __sti()                                                               \
   6.162 -do {                                                                          \
   6.163 -    shared_info_t *_shared = HYPERVISOR_shared_info;                          \
   6.164 -    set_bit(EVENTS_MASTER_ENABLE_BIT, &_shared->events_mask);                 \
   6.165 -    barrier();                                                                \
   6.166 -    if ( unlikely(_shared->events) ) do_hypervisor_callback(NULL);            \
   6.167 +#define safe_halt()		((void)0)
   6.168 +
   6.169 +#define __save_and_cli(x)						\
   6.170 +do {									\
   6.171 +	vcpu_info_t *_vcpu;						\
   6.172 +	preempt_disable();						\
   6.173 +	_vcpu = &HYPERVISOR_shared_info->vcpu_data[smp_processor_id()];	\
   6.174 +	(x) = _vcpu->evtchn_upcall_mask;				\
   6.175 +	_vcpu->evtchn_upcall_mask = 1;					\
   6.176 +	preempt_enable_no_resched();					\
   6.177 +	barrier();							\
   6.178  } while (0)
   6.179 -#define cli() __cli()
   6.180 -#define sti() __sti()
   6.181 -#define save_flags(x) __save_flags(x)
   6.182 -#define restore_flags(x) __restore_flags(x)
   6.183 -#define save_and_cli(x) __save_and_cli(x)
   6.184 -#define save_and_sti(x) __save_and_sti(x)
   6.185  
   6.186 +#define local_irq_save(x)	__save_and_cli(x)
   6.187 +#define local_irq_restore(x)	__restore_flags(x)
   6.188 +#define local_save_flags(x)	__save_flags(x)
   6.189 +#define local_irq_disable()	__cli()
   6.190 +#define local_irq_enable()	__sti()
   6.191  
   6.192 +#define irqs_disabled()			\
   6.193 +    HYPERVISOR_shared_info->vcpu_data[smp_processor_id()].evtchn_upcall_mask
   6.194  
   6.195  /* This is a barrier for the compiler only, NOT the processor! */
   6.196  #define barrier() __asm__ __volatile__("": : :"memory")
     7.1 --- a/extras/mini-os/head.S	Fri Feb 11 01:51:41 2005 +0000
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,18 +0,0 @@
     7.4 -#include <os.h>
     7.5 -
     7.6 -.globl _start, shared_info
     7.7 -                        
     7.8 -_start:
     7.9 -        cld
    7.10 -        lss stack_start,%esp
    7.11 -        push %esi 
    7.12 -        call start_kernel
    7.13 -
    7.14 -stack_start:
    7.15 -	.long stack+8192, __KERNEL_DS
    7.16 -
    7.17 -        /* Unpleasant -- the PTE that maps this page is actually overwritten */
    7.18 -        /* to map the real shared-info page! :-)                             */
    7.19 -        .org 0x1000
    7.20 -shared_info:
    7.21 -        .org 0x2000
     8.1 --- a/extras/mini-os/kernel.c	Fri Feb 11 01:51:41 2005 +0000
     8.2 +++ b/extras/mini-os/kernel.c	Fri Feb 11 11:34:22 2005 +0000
     8.3 @@ -64,8 +64,8 @@ extern char shared_info[PAGE_SIZE];
     8.4  
     8.5  static shared_info_t *map_shared_info(unsigned long pa)
     8.6  {
     8.7 -    if ( HYPERVISOR_update_va_mapping((unsigned long)shared_info >> PAGE_SHIFT,
     8.8 -                                      pa | 3, UVMF_INVLPG) )
     8.9 +    if ( HYPERVISOR_update_va_mapping(
    8.10 +        (unsigned long)shared_info, pa | 3, UVMF_INVLPG) )
    8.11      {
    8.12          printk("Failed to map shared_info!!\n");
    8.13          *(int*)0=0;
    8.14 @@ -79,6 +79,9 @@ static shared_info_t *map_shared_info(un
    8.15   */
    8.16  void start_kernel(start_info_t *si)
    8.17  {
    8.18 +    static char hello[] = "Bootstrapping...\n";
    8.19 +    (void)HYPERVISOR_console_io(CONSOLEIO_write, strlen(hello), hello);
    8.20 +
    8.21      /* Copy the start_info struct to a globally-accessible area. */
    8.22      memcpy(&start_info, si, sizeof(*si));
    8.23  
    8.24 @@ -86,9 +89,15 @@ void start_kernel(start_info_t *si)
    8.25      HYPERVISOR_shared_info = map_shared_info(start_info.shared_info);
    8.26  
    8.27      /* Set up event and failsafe callback addresses. */
    8.28 +#ifdef __i386__
    8.29      HYPERVISOR_set_callbacks(
    8.30          __KERNEL_CS, (unsigned long)hypervisor_callback,
    8.31          __KERNEL_CS, (unsigned long)failsafe_callback);
    8.32 +#else
    8.33 +    HYPERVISOR_set_callbacks(
    8.34 +        (unsigned long)hypervisor_callback,
    8.35 +        (unsigned long)failsafe_callback, 0);
    8.36 +#endif
    8.37  
    8.38      trap_init();
    8.39  
    8.40 @@ -117,7 +126,7 @@ void start_kernel(start_info_t *si)
    8.41      init_mm();
    8.42  
    8.43      /* set up events */
    8.44 -    init_events();
    8.45 +//    init_events();
    8.46  
    8.47      /*
    8.48       * These need to be replaced with event-channel/control-interface
    8.49 @@ -135,7 +144,7 @@ void start_kernel(start_info_t *si)
    8.50  #endif
    8.51  
    8.52      /* init time and timers */
    8.53 -    init_time();
    8.54 +//    init_time();
    8.55  
    8.56      /* do nothing */
    8.57      for ( ; ; ) HYPERVISOR_yield();
     9.1 --- a/extras/mini-os/lib/math.c	Fri Feb 11 01:51:41 2005 +0000
     9.2 +++ b/extras/mini-os/lib/math.c	Fri Feb 11 11:34:22 2005 +0000
     9.3 @@ -96,14 +96,14 @@ union uu {
     9.4   * (sizeof(long)*CHAR_BIT/2).
     9.5   */
     9.6  #define HHALF(x)        ((x) >> HALF_BITS)
     9.7 -#define LHALF(x)        ((x) & ((1 << HALF_BITS) - 1))
     9.8 +#define LHALF(x)        ((x) & ((1UL << HALF_BITS) - 1))
     9.9  #define LHUP(x)         ((x) << HALF_BITS)
    9.10  
    9.11  /*
    9.12   * Multiprecision divide.  This algorithm is from Knuth vol. 2 (2nd ed),
    9.13   * section 4.3.1, pp. 257--259.
    9.14   */
    9.15 -#define	B	(1 << HALF_BITS)	/* digit base */
    9.16 +#define	B	(1UL << HALF_BITS)	/* digit base */
    9.17  
    9.18  /* Combine two `digits' to make a single two-digit number. */
    9.19  #define	COMBINE(a, b) (((u_long)(a) << HALF_BITS) | (b))
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/extras/mini-os/minios-x86_32.lds	Fri Feb 11 11:34:22 2005 +0000
    10.3 @@ -0,0 +1,54 @@
    10.4 +OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
    10.5 +OUTPUT_ARCH(i386)
    10.6 +ENTRY(_start)
    10.7 +SECTIONS
    10.8 +{
    10.9 +  . = 0xC0000000;
   10.10 +  _text = .;			/* Text and read-only data */
   10.11 +  .text : {
   10.12 +	*(.text)
   10.13 +	*(.gnu.warning)
   10.14 +	} = 0x9090
   10.15 +
   10.16 +  _etext = .;			/* End of text section */
   10.17 +
   10.18 +  .rodata : { *(.rodata) *(.rodata.*) }
   10.19 +
   10.20 +  .data : {			/* Data */
   10.21 +	*(.data)
   10.22 +	CONSTRUCTORS
   10.23 +	}
   10.24 +
   10.25 +  _edata = .;			/* End of data section */
   10.26 +
   10.27 +  . = ALIGN(8192);		/* init_task */
   10.28 +  .data.init_task : { *(.data.init_task) }
   10.29 +
   10.30 +  . = ALIGN(4096);
   10.31 +  .data.page_aligned : { *(.data.idt) }
   10.32 +
   10.33 +  . = ALIGN(32);
   10.34 +  .data.cacheline_aligned : { *(.data.cacheline_aligned) }
   10.35 +
   10.36 +  __bss_start = .;		/* BSS */
   10.37 +  .bss : {
   10.38 +	*(.bss)
   10.39 +	}
   10.40 +  _end = . ;
   10.41 +
   10.42 +  /* Sections to be discarded */
   10.43 +  /DISCARD/ : {
   10.44 +	*(.text.exit)
   10.45 +	*(.data.exit)
   10.46 +	*(.exitcall.exit)
   10.47 +	}
   10.48 +
   10.49 +  /* Stabs debugging sections.  */
   10.50 +  .stab 0 : { *(.stab) }
   10.51 +  .stabstr 0 : { *(.stabstr) }
   10.52 +  .stab.excl 0 : { *(.stab.excl) }
   10.53 +  .stab.exclstr 0 : { *(.stab.exclstr) }
   10.54 +  .stab.index 0 : { *(.stab.index) }
   10.55 +  .stab.indexstr 0 : { *(.stab.indexstr) }
   10.56 +  .comment 0 : { *(.comment) }
   10.57 +}
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/extras/mini-os/minios-x86_64.lds	Fri Feb 11 11:34:22 2005 +0000
    11.3 @@ -0,0 +1,54 @@
    11.4 +OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64", "elf64-x86-64")
    11.5 +OUTPUT_ARCH(i386:x86-64)
    11.6 +ENTRY(_start)
    11.7 +SECTIONS
    11.8 +{
    11.9 +  . = 0xFFFFFFFF00000000;
   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 --- a/extras/mini-os/minios.lds	Fri Feb 11 01:51:41 2005 +0000
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,54 +0,0 @@
    12.4 -OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
    12.5 -OUTPUT_ARCH(i386)
    12.6 -ENTRY(_start)
    12.7 -SECTIONS
    12.8 -{
    12.9 -  . = 0xC0000000;
   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/traps.c	Fri Feb 11 01:51:41 2005 +0000
    13.2 +++ b/extras/mini-os/traps.c	Fri Feb 11 11:34:22 2005 +0000
    13.3 @@ -33,38 +33,38 @@ extern void do_exit(void);
    13.4  
    13.5  void dump_regs(struct pt_regs *regs)
    13.6  {
    13.7 -	int in_kernel = 1;
    13.8 -	unsigned long esp;
    13.9 -	unsigned short ss;
   13.10 +    int in_kernel = 1;
   13.11 +    unsigned long esp;
   13.12 +    unsigned short ss;
   13.13  
   13.14 -	esp = (unsigned long) (&regs->esp);
   13.15 -	ss = __KERNEL_DS;
   13.16 -	if (regs->xcs & 2) {
   13.17 -		in_kernel = 0;
   13.18 -		esp = regs->esp;
   13.19 -		ss = regs->xss & 0xffff;
   13.20 -	}
   13.21 -	printf("EIP:    %04x:[<%08lx>]\n",
   13.22 -	       0xffff & regs->xcs, regs->eip);
   13.23 -	printf("EFLAGS: %08lx\n",regs->eflags);
   13.24 -	printf("eax: %08lx   ebx: %08lx   ecx: %08lx   edx: %08lx\n",
   13.25 -		regs->eax, regs->ebx, regs->ecx, regs->edx);
   13.26 -	printf("esi: %08lx   edi: %08lx   ebp: %08lx   esp: %08lx\n",
   13.27 -		regs->esi, regs->edi, regs->ebp, esp);
   13.28 -	printf("ds: %04x   es: %04x   ss: %04x\n",
   13.29 -		regs->xds & 0xffff, regs->xes & 0xffff, ss);
   13.30 -	printf("\n");
   13.31 +    esp = (unsigned long) (&regs->esp);
   13.32 +    ss = __KERNEL_DS;
   13.33 +    if (regs->cs & 2) {
   13.34 +        in_kernel = 0;
   13.35 +        esp = regs->esp;
   13.36 +        ss = regs->ss & 0xffff;
   13.37 +    }
   13.38 +    printf("EIP:    %04x:[<%p>]\n",
   13.39 +           0xffff & regs->cs , regs->eip);
   13.40 +    printf("EFLAGS: %p\n",regs->eflags);
   13.41 +    printf("eax: %p   ebx: %p   ecx: %p   edx: %p\n",
   13.42 +           regs->eax, regs->ebx, regs->ecx, regs->edx);
   13.43 +    printf("esi: %p   edi: %p   ebp: %p   esp: %p\n",
   13.44 +           regs->esi, regs->edi, regs->ebp, esp);
   13.45 +    printf("ds: %04x   es: %04x   ss: %04x\n",
   13.46 +           regs->ds & 0xffff, regs->es & 0xffff, ss);
   13.47 +    printf("\n");
   13.48  }	
   13.49  
   13.50  
   13.51 -static __inline__ void dump_code(unsigned eip)
   13.52 +static __inline__ void dump_code(unsigned long eip)
   13.53  {
   13.54 -  unsigned *ptr = (unsigned *)eip;
   13.55 -  int x;
   13.56 -
   13.57 -  printk("Bytes at eip:\n");
   13.58 -  for (x = -4; x < 5; x++)
   13.59 -      printf("%x", ptr[x]);
   13.60 +    unsigned *ptr = (unsigned *)eip;
   13.61 +    int x;
   13.62 +    
   13.63 +    printk("Bytes at eip:\n");
   13.64 +    for (x = -4; x < 5; x++)
   13.65 +        printf("%p", ptr[x]);
   13.66  }
   13.67  
   13.68  
   13.69 @@ -81,14 +81,14 @@ static __inline__ void dump_code(unsigne
   13.70   */
   13.71  
   13.72  static void __inline__ do_trap(int trapnr, char *str,
   13.73 -			   struct pt_regs * regs, long error_code)
   13.74 +                               struct pt_regs * regs, long error_code)
   13.75  {
   13.76 -  printk("FATAL:  Unhandled Trap (see mini-os:traps.c)");
   13.77 -  printf("%d %s", trapnr, str);
   13.78 -  dump_regs(regs);
   13.79 -  dump_code(regs->eip);
   13.80 +    printk("FATAL:  Unhandled Trap (see mini-os:traps.c)");
   13.81 +    printf("%d %s", trapnr, str);
   13.82 +    dump_regs(regs);
   13.83 +    dump_code(regs->eip);
   13.84  
   13.85 -  do_exit();
   13.86 +    do_exit();
   13.87  }
   13.88  
   13.89  #define DO_ERROR(trapnr, str, name) \
   13.90 @@ -104,38 +104,36 @@ void do_##name(struct pt_regs * regs, lo
   13.91  }
   13.92  
   13.93  DO_ERROR_INFO( 0, "divide error", divide_error, FPE_INTDIV, regs->eip)
   13.94 -DO_ERROR( 3, "int3", int3)
   13.95 -DO_ERROR( 4, "overflow", overflow)
   13.96 -DO_ERROR( 5, "bounds", bounds)
   13.97 -DO_ERROR_INFO( 6, "invalid operand", invalid_op, ILL_ILLOPN, regs->eip)
   13.98 -DO_ERROR( 7, "device not available", device_not_available)
   13.99 -DO_ERROR( 8, "double fault", double_fault)
  13.100 -DO_ERROR( 9, "coprocessor segment overrun", coprocessor_segment_overrun)
  13.101 -DO_ERROR(10, "invalid TSS", invalid_TSS)
  13.102 -DO_ERROR(11, "segment not present", segment_not_present)
  13.103 -DO_ERROR(12, "stack segment", stack_segment)
  13.104 -DO_ERROR_INFO(17, "alignment check", alignment_check, BUS_ADRALN, 0)
  13.105 -DO_ERROR(18, "machine check", machine_check)
  13.106 +    DO_ERROR( 3, "int3", int3)
  13.107 +    DO_ERROR( 4, "overflow", overflow)
  13.108 +    DO_ERROR( 5, "bounds", bounds)
  13.109 +    DO_ERROR_INFO( 6, "invalid operand", invalid_op, ILL_ILLOPN, regs->eip)
  13.110 +    DO_ERROR( 7, "device not available", device_not_available)
  13.111 +    DO_ERROR( 8, "double fault", double_fault)
  13.112 +    DO_ERROR( 9, "coprocessor segment overrun", coprocessor_segment_overrun)
  13.113 +    DO_ERROR(10, "invalid TSS", invalid_TSS)
  13.114 +    DO_ERROR(11, "segment not present", segment_not_present)
  13.115 +    DO_ERROR(12, "stack segment", stack_segment)
  13.116 +    DO_ERROR_INFO(17, "alignment check", alignment_check, BUS_ADRALN, 0)
  13.117 +    DO_ERROR(18, "machine check", machine_check)
  13.118  
  13.119 -void do_page_fault(struct pt_regs *regs, long error_code,
  13.120 -                   unsigned long address)
  13.121 +    void do_page_fault(struct pt_regs *regs, long error_code,
  13.122 +                       unsigned long address)
  13.123  {
  13.124      printk("Page fault\n");
  13.125 -    printk("Address: 0x%lx", address);
  13.126 -    printk("Error Code: 0x%lx", error_code);
  13.127 -    printk("eip: \t 0x%lx", regs->eip);
  13.128 +    printk("Address: 0x%p", address);
  13.129 +    printk("Error Code: 0x%p", error_code);
  13.130 +    printk("eip: \t 0x%p", regs->eip);
  13.131      do_exit();
  13.132  }
  13.133  
  13.134  void do_general_protection(struct pt_regs * regs, long error_code)
  13.135  {
  13.136 -
  13.137 -  HYPERVISOR_shared_info->events_mask = 0;
  13.138 -  printk("GPF\n");
  13.139 -  printk("Error Code: 0x%lx", error_code);
  13.140 -  dump_regs(regs);
  13.141 -  dump_code(regs->eip);
  13.142 -  do_exit();
  13.143 +    printk("GPF\n");
  13.144 +    printk("Error Code: 0x%p", error_code);
  13.145 +    dump_regs(regs);
  13.146 +    dump_code(regs->eip);
  13.147 +    do_exit();
  13.148  }
  13.149  
  13.150  
  13.151 @@ -180,26 +178,29 @@ void do_spurious_interrupt_bug(struct pt
  13.152   * The 'privilege ring' field specifies the least-privileged ring that
  13.153   * can trap to that vector using a software-interrupt instruction (INT).
  13.154   */
  13.155 +#ifdef __x86_64__
  13.156 +#define _P 0,
  13.157 +#endif
  13.158  static trap_info_t trap_table[] = {
  13.159 -    {  0, 0, __KERNEL_CS, (unsigned long)divide_error                },
  13.160 -    {  1, 0, __KERNEL_CS, (unsigned long)debug                       },
  13.161 -    {  3, 3, __KERNEL_CS, (unsigned long)int3                        },
  13.162 -    {  4, 3, __KERNEL_CS, (unsigned long)overflow                    },
  13.163 -    {  5, 3, __KERNEL_CS, (unsigned long)bounds                      },
  13.164 -    {  6, 0, __KERNEL_CS, (unsigned long)invalid_op                  },
  13.165 -    {  7, 0, __KERNEL_CS, (unsigned long)device_not_available        },
  13.166 -    {  8, 0, __KERNEL_CS, (unsigned long)double_fault                },
  13.167 -    {  9, 0, __KERNEL_CS, (unsigned long)coprocessor_segment_overrun },
  13.168 -    { 10, 0, __KERNEL_CS, (unsigned long)invalid_TSS                 },
  13.169 -    { 11, 0, __KERNEL_CS, (unsigned long)segment_not_present         },
  13.170 -    { 12, 0, __KERNEL_CS, (unsigned long)stack_segment               },
  13.171 -    { 13, 0, __KERNEL_CS, (unsigned long)general_protection          },
  13.172 -    { 14, 0, __KERNEL_CS, (unsigned long)page_fault                  },
  13.173 -    { 15, 0, __KERNEL_CS, (unsigned long)spurious_interrupt_bug      },
  13.174 -    { 16, 0, __KERNEL_CS, (unsigned long)coprocessor_error           },
  13.175 -    { 17, 0, __KERNEL_CS, (unsigned long)alignment_check             },
  13.176 -    { 18, 0, __KERNEL_CS, (unsigned long)machine_check               },
  13.177 -    { 19, 0, __KERNEL_CS, (unsigned long)simd_coprocessor_error      },
  13.178 +    {  0, 0, __KERNEL_CS, _P (unsigned long)divide_error                },
  13.179 +    {  1, 0, __KERNEL_CS, _P (unsigned long)debug                       },
  13.180 +    {  3, 3, __KERNEL_CS, _P (unsigned long)int3                        },
  13.181 +    {  4, 3, __KERNEL_CS, _P (unsigned long)overflow                    },
  13.182 +    {  5, 3, __KERNEL_CS, _P (unsigned long)bounds                      },
  13.183 +    {  6, 0, __KERNEL_CS, _P (unsigned long)invalid_op                  },
  13.184 +    {  7, 0, __KERNEL_CS, _P (unsigned long)device_not_available        },
  13.185 +    {  8, 0, __KERNEL_CS, _P (unsigned long)double_fault                },
  13.186 +    {  9, 0, __KERNEL_CS, _P (unsigned long)coprocessor_segment_overrun },
  13.187 +    { 10, 0, __KERNEL_CS, _P (unsigned long)invalid_TSS                 },
  13.188 +    { 11, 0, __KERNEL_CS, _P (unsigned long)segment_not_present         },
  13.189 +    { 12, 0, __KERNEL_CS, _P (unsigned long)stack_segment               },
  13.190 +    { 13, 0, __KERNEL_CS, _P (unsigned long)general_protection          },
  13.191 +    { 14, 0, __KERNEL_CS, _P (unsigned long)page_fault                  },
  13.192 +    { 15, 0, __KERNEL_CS, _P (unsigned long)spurious_interrupt_bug      },
  13.193 +    { 16, 0, __KERNEL_CS, _P (unsigned long)coprocessor_error           },
  13.194 +    { 17, 0, __KERNEL_CS, _P (unsigned long)alignment_check             },
  13.195 +    { 18, 0, __KERNEL_CS, _P (unsigned long)machine_check               },
  13.196 +    { 19, 0, __KERNEL_CS, _P (unsigned long)simd_coprocessor_error      },
  13.197      {  0, 0,           0, 0                           }
  13.198  };
  13.199      
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/extras/mini-os/x86_32.S	Fri Feb 11 11:34:22 2005 +0000
    14.3 @@ -0,0 +1,285 @@
    14.4 +#include <os.h>
    14.5 +
    14.6 +.section __xen_guest
    14.7 +        .asciz  "XEN_VER=2.0,LOADER=generic,PT_MODE_WRITABLE"
    14.8 +.text
    14.9 +
   14.10 +.globl _start, shared_info
   14.11 +                        
   14.12 +_start:
   14.13 +        cld
   14.14 +        lss stack_start,%esp
   14.15 +        push %esi 
   14.16 +        call start_kernel
   14.17 +
   14.18 +stack_start:
   14.19 +	.long stack+8192, __KERNEL_SS
   14.20 +
   14.21 +        /* Unpleasant -- the PTE that maps this page is actually overwritten */
   14.22 +        /* to map the real shared-info page! :-)                             */
   14.23 +        .org 0x1000
   14.24 +shared_info:
   14.25 +        .org 0x2000
   14.26 +        
   14.27 +ES		= 0x20
   14.28 +ORIG_EAX	= 0x24
   14.29 +EIP		= 0x28
   14.30 +CS		= 0x2C
   14.31 +
   14.32 +#define ENTRY(X) .globl X ; X :
   14.33 +
   14.34 +#define SAVE_ALL \
   14.35 +	cld; \
   14.36 +	pushl %es; \
   14.37 +	pushl %ds; \
   14.38 +	pushl %eax; \
   14.39 +	pushl %ebp; \
   14.40 +	pushl %edi; \
   14.41 +	pushl %esi; \
   14.42 +	pushl %edx; \
   14.43 +	pushl %ecx; \
   14.44 +	pushl %ebx; \
   14.45 +	movl $(__KERNEL_DS),%edx; \
   14.46 +	movl %edx,%ds; \
   14.47 +	movl %edx,%es;
   14.48 +
   14.49 +#define RESTORE_ALL	\
   14.50 +	popl %ebx;	\
   14.51 +	popl %ecx;	\
   14.52 +	popl %edx;	\
   14.53 +	popl %esi;	\
   14.54 +	popl %edi;	\
   14.55 +	popl %ebp;	\
   14.56 +	popl %eax;	\
   14.57 +	popl %ds;	\
   14.58 +	popl %es;	\
   14.59 +	addl $4,%esp;	\
   14.60 +	iret;		\
   14.61 +
   14.62 +ENTRY(divide_error)
   14.63 +	pushl $0		# no error code
   14.64 +	pushl $do_divide_error
   14.65 +do_exception:
   14.66 +	pushl %ds
   14.67 +	pushl %eax
   14.68 +	xorl %eax,%eax
   14.69 +	pushl %ebp
   14.70 +	pushl %edi
   14.71 +	pushl %esi
   14.72 +	pushl %edx
   14.73 +	decl %eax			# eax = -1
   14.74 +	pushl %ecx
   14.75 +	pushl %ebx
   14.76 +	cld
   14.77 +	movl %es,%ecx
   14.78 +	movl ORIG_EAX(%esp), %esi	# get the error code
   14.79 +	movl ES(%esp), %edi		# get the function address
   14.80 +	movl %eax, ORIG_EAX(%esp)
   14.81 +	movl %ecx, ES(%esp)
   14.82 +	movl %esp,%edx
   14.83 +	pushl %esi			# push the error code
   14.84 +	pushl %edx			# push the pt_regs pointer
   14.85 +	movl $(__KERNEL_DS),%edx
   14.86 +	movl %edx,%ds
   14.87 +	movl %edx,%es
   14.88 +	call *%edi
   14.89 +	addl $8,%esp
   14.90 +
   14.91 +        
   14.92 +ret_from_exception:
   14.93 +        movb CS(%esp),%cl
   14.94 +	test $2,%cl          # slow return to ring 2 or 3
   14.95 +	jne  safesti
   14.96 +        RESTORE_ALL
   14.97 +
   14.98 +# A note on the "critical region" in our callback handler.
   14.99 +# We want to avoid stacking callback handlers due to events occurring
  14.100 +# during handling of the last event. To do this, we keep events disabled
  14.101 +# until weve done all processing. HOWEVER, we must enable events before
  14.102 +# popping the stack frame (cant be done atomically) and so it would still
  14.103 +# be possible to get enough handler activations to overflow the stack.
  14.104 +# Although unlikely, bugs of that kind are hard to track down, so wed
  14.105 +# like to avoid the possibility.
  14.106 +# So, on entry to the handler we detect whether we interrupted an
  14.107 +# existing activation in its critical region -- if so, we pop the current
  14.108 +# activation and restart the handler using the previous one.
  14.109 +ENTRY(hypervisor_callback)
  14.110 +        pushl %eax
  14.111 +        SAVE_ALL
  14.112 +        movl EIP(%esp),%eax
  14.113 +        cmpl $scrit,%eax
  14.114 +        jb   11f
  14.115 +        cmpl $ecrit,%eax
  14.116 +        jb   critical_region_fixup
  14.117 +11:     push %esp
  14.118 +#        call do_hypervisor_callback
  14.119 +        add  $4,%esp
  14.120 +        movl HYPERVISOR_shared_info,%esi
  14.121 +        xorl %eax,%eax
  14.122 +        movb CS(%esp),%cl
  14.123 +    	test $2,%cl          # slow return to ring 2 or 3
  14.124 +        jne  safesti
  14.125 +safesti:btsl $31,4(%esi)     # reenable event callbacks
  14.126 +scrit:  /**** START OF CRITICAL REGION ****/
  14.127 +        cmpl %eax,(%esi)
  14.128 +        jne  14f              # process more events if necessary...
  14.129 +        RESTORE_ALL
  14.130 +14:     btrl %eax,4(%esi)
  14.131 +        jmp  11b
  14.132 +ecrit:  /**** END OF CRITICAL REGION ****/
  14.133 +# [How we do the fixup]. We want to merge the current stack frame with the
  14.134 +# just-interrupted frame. How we do this depends on where in the critical
  14.135 +# region the interrupted handler was executing, and so how many saved
  14.136 +# registers are in each frame. We do this quickly using the lookup table
  14.137 +# 'critical_fixup_table'. For each byte offset in the critical region, it
  14.138 +# provides the number of bytes which have already been popped from the
  14.139 +# interrupted stack frame. 
  14.140 +critical_region_fixup:
  14.141 +        addl $critical_fixup_table-scrit,%eax
  14.142 +        movzbl (%eax),%eax    # %eax contains num bytes popped
  14.143 +        mov  %esp,%esi
  14.144 +        add  %eax,%esi        # %esi points at end of src region
  14.145 +        mov  %esp,%edi
  14.146 +        add  $0x34,%edi       # %edi points at end of dst region
  14.147 +        mov  %eax,%ecx
  14.148 +        shr  $2,%ecx          # convert words to bytes
  14.149 +        je   16f              # skip loop if nothing to copy
  14.150 +15:     subl $4,%esi          # pre-decrementing copy loop
  14.151 +        subl $4,%edi
  14.152 +        movl (%esi),%eax
  14.153 +        movl %eax,(%edi)
  14.154 +        loop 15b
  14.155 +16:     movl %edi,%esp        # final %edi is top of merged stack
  14.156 +        jmp  11b
  14.157 +         
  14.158 +critical_fixup_table:        
  14.159 +        .byte 0x00,0x00                       # cmpl %eax,(%esi)
  14.160 +        .byte 0x00,0x00                       # jne  14f
  14.161 +        .byte 0x00                            # pop  %ebx
  14.162 +        .byte 0x04                            # pop  %ecx
  14.163 +        .byte 0x08                            # pop  %edx
  14.164 +        .byte 0x0c                            # pop  %esi
  14.165 +        .byte 0x10                            # pop  %edi
  14.166 +        .byte 0x14                            # pop  %ebp
  14.167 +        .byte 0x18                            # pop  %eax
  14.168 +        .byte 0x1c                            # pop  %ds
  14.169 +        .byte 0x20                            # pop  %es
  14.170 +        .byte 0x24,0x24,0x24                  # add  $4,%esp
  14.171 +        .byte 0x28                            # iret
  14.172 +        .byte 0x00,0x00,0x00,0x00,0x00        # btrl $31,4(%esi)
  14.173 +        .byte 0x00,0x00                       # jmp  11b
  14.174 +       
  14.175 +# Hypervisor uses this for application faults while it executes.
  14.176 +ENTRY(failsafe_callback)
  14.177 +      pop  %ds
  14.178 +      pop  %es
  14.179 +      pop  %fs
  14.180 +      pop  %gs
  14.181 +      iret
  14.182 +                
  14.183 +ENTRY(coprocessor_error)
  14.184 +	pushl $0
  14.185 +	pushl $do_coprocessor_error
  14.186 +	jmp do_exception
  14.187 +
  14.188 +ENTRY(simd_coprocessor_error)
  14.189 +	pushl $0
  14.190 +	pushl $do_simd_coprocessor_error
  14.191 +	jmp do_exception
  14.192 +
  14.193 +ENTRY(device_not_available)
  14.194 +        iret
  14.195 +
  14.196 +ENTRY(debug)
  14.197 +	pushl $0
  14.198 +	pushl $do_debug
  14.199 +	jmp do_exception
  14.200 +
  14.201 +ENTRY(int3)
  14.202 +	pushl $0
  14.203 +	pushl $do_int3
  14.204 +	jmp do_exception
  14.205 +
  14.206 +ENTRY(overflow)
  14.207 +	pushl $0
  14.208 +	pushl $do_overflow
  14.209 +	jmp do_exception
  14.210 +
  14.211 +ENTRY(bounds)
  14.212 +	pushl $0
  14.213 +	pushl $do_bounds
  14.214 +	jmp do_exception
  14.215 +
  14.216 +ENTRY(invalid_op)
  14.217 +	pushl $0
  14.218 +	pushl $do_invalid_op
  14.219 +	jmp do_exception
  14.220 +
  14.221 +ENTRY(coprocessor_segment_overrun)
  14.222 +	pushl $0
  14.223 +	pushl $do_coprocessor_segment_overrun
  14.224 +	jmp do_exception
  14.225 +
  14.226 +ENTRY(double_fault)
  14.227 +	pushl $do_double_fault
  14.228 +	jmp do_exception
  14.229 +
  14.230 +ENTRY(invalid_TSS)
  14.231 +	pushl $do_invalid_TSS
  14.232 +	jmp do_exception
  14.233 +
  14.234 +ENTRY(segment_not_present)
  14.235 +	pushl $do_segment_not_present
  14.236 +	jmp do_exception
  14.237 +
  14.238 +ENTRY(stack_segment)
  14.239 +	pushl $do_stack_segment
  14.240 +	jmp do_exception
  14.241 +
  14.242 +ENTRY(general_protection)
  14.243 +	pushl $do_general_protection
  14.244 +	jmp do_exception
  14.245 +
  14.246 +ENTRY(alignment_check)
  14.247 +	pushl $do_alignment_check
  14.248 +	jmp do_exception
  14.249 +
  14.250 +# This handler is special, because it gets an extra value on its stack,
  14.251 +# which is the linear faulting address.
  14.252 +ENTRY(page_fault)
  14.253 +	pushl %ds
  14.254 +	pushl %eax
  14.255 +	xorl %eax,%eax
  14.256 +	pushl %ebp
  14.257 +	pushl %edi
  14.258 +	pushl %esi
  14.259 +	pushl %edx
  14.260 +	decl %eax			# eax = -1
  14.261 +	pushl %ecx
  14.262 +	pushl %ebx
  14.263 +	cld
  14.264 +	movl %es,%ecx
  14.265 +	movl ORIG_EAX(%esp), %esi	# get the error code
  14.266 +	movl ES(%esp), %edi		# get the faulting address
  14.267 +	movl %eax, ORIG_EAX(%esp)
  14.268 +	movl %ecx, ES(%esp)
  14.269 +	movl %esp,%edx
  14.270 +        pushl %edi                      # push the faulting address
  14.271 +	pushl %esi			# push the error code
  14.272 +	pushl %edx			# push the pt_regs pointer
  14.273 +	movl $(__KERNEL_DS),%edx
  14.274 +	movl %edx,%ds
  14.275 +	movl %edx,%es
  14.276 +	call do_page_fault
  14.277 +	addl $12,%esp
  14.278 +	jmp ret_from_exception
  14.279 +
  14.280 +ENTRY(machine_check)
  14.281 +	pushl $0
  14.282 +	pushl $do_machine_check
  14.283 +	jmp do_exception
  14.284 +
  14.285 +ENTRY(spurious_interrupt_bug)
  14.286 +	pushl $0
  14.287 +	pushl $do_spurious_interrupt_bug
  14.288 +	jmp do_exception
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/extras/mini-os/x86_64.S	Fri Feb 11 11:34:22 2005 +0000
    15.3 @@ -0,0 +1,78 @@
    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 +#define ENTRY(X) .globl X ; X :
   15.11 +.globl _start, shared_info
   15.12 +                        
   15.13 +_start:
   15.14 +        cld
   15.15 +        movq stack_start(%rip),%rsp
   15.16 +        movq %rsi,%rdi
   15.17 +        call start_kernel
   15.18 +
   15.19 +stack_start:
   15.20 +        .quad stack+8192
   15.21 +
   15.22 +        /* Unpleasant -- the PTE that maps this page is actually overwritten */
   15.23 +        /* to map the real shared-info page! :-)                             */
   15.24 +        .org 0x1000
   15.25 +shared_info:
   15.26 +        .org 0x2000
   15.27 +
   15.28 +ENTRY(hypervisor_callback)
   15.29 +
   15.30 +ENTRY(failsafe_callback)
   15.31 +      iret
   15.32 +                
   15.33 +ENTRY(divide_error)
   15.34 +	pushq $0
   15.35 +
   15.36 +ENTRY(coprocessor_error)
   15.37 +	pushq $0
   15.38 +
   15.39 +ENTRY(simd_coprocessor_error)
   15.40 +	pushq $0
   15.41 +
   15.42 +ENTRY(device_not_available)
   15.43 +        iret
   15.44 +
   15.45 +ENTRY(debug)
   15.46 +	pushq $0
   15.47 +
   15.48 +ENTRY(int3)
   15.49 +	pushq $0
   15.50 +
   15.51 +ENTRY(overflow)
   15.52 +	pushq $0
   15.53 +
   15.54 +ENTRY(bounds)
   15.55 +	pushq $0
   15.56 +
   15.57 +ENTRY(invalid_op)
   15.58 +	pushq $0
   15.59 +
   15.60 +ENTRY(coprocessor_segment_overrun)
   15.61 +	pushq $0
   15.62 +
   15.63 +ENTRY(double_fault)
   15.64 +
   15.65 +ENTRY(invalid_TSS)
   15.66 +
   15.67 +ENTRY(segment_not_present)
   15.68 +
   15.69 +ENTRY(stack_segment)
   15.70 +
   15.71 +ENTRY(general_protection)
   15.72 +
   15.73 +ENTRY(alignment_check)
   15.74 +
   15.75 +ENTRY(page_fault)
   15.76 +
   15.77 +ENTRY(machine_check)
   15.78 +	pushq $0
   15.79 +
   15.80 +ENTRY(spurious_interrupt_bug)
   15.81 +	pushq $0
    16.1 --- a/xen/arch/x86/traps.c	Fri Feb 11 01:51:41 2005 +0000
    16.2 +++ b/xen/arch/x86/traps.c	Fri Feb 11 11:34:22 2005 +0000
    16.3 @@ -510,7 +510,7 @@ asmlinkage int do_general_protection(str
    16.4      {
    16.5          /* This fault must be due to <INT n> instruction. */
    16.6          ti = current->arch.traps + (regs->error_code>>3);
    16.7 -        if ( TI_GET_DPL(ti) >= (VM86_MODE(regs) ? 3 : (regs->cs & 3)) )
    16.8 +        if ( PERMIT_SOFTINT(TI_GET_DPL(ti), ed, regs) )
    16.9          {
   16.10              tb->flags = TBF_EXCEPTION;
   16.11              regs->eip += 2;
    17.1 --- a/xen/arch/x86/x86_32/entry.S	Fri Feb 11 01:51:41 2005 +0000
    17.2 +++ b/xen/arch/x86/x86_32/entry.S	Fri Feb 11 11:34:22 2005 +0000
    17.3 @@ -256,6 +256,7 @@ FIX6:   pushl %ebx
    17.4          orb   $TF_failsafe_return,EDOMAIN_thread_flags(%ebx)
    17.5          pop   %ebx
    17.6          jmp   FIX5
    17.7 +.previous
    17.8  .section __pre_ex_table,"a"
    17.9  	.long FLT6,FIX6
   17.10  .previous
    18.1 --- a/xen/arch/x86/x86_64/entry.S	Fri Feb 11 01:51:41 2005 +0000
    18.2 +++ b/xen/arch/x86/x86_64/entry.S	Fri Feb 11 11:34:22 2005 +0000
    18.3 @@ -85,6 +85,7 @@ FIX2:   pushq %rbx
    18.4          orb   $TF_failsafe_return,EDOMAIN_thread_flags(%rbx)
    18.5          popq  %rbx
    18.6          jmp   FIX1
    18.7 +.previous
    18.8  .section __pre_ex_table,"a"
    18.9  	.quad FLT2,FIX2
   18.10  .previous
   18.11 @@ -287,8 +288,11 @@ 1:      sti
   18.12          movq  %rsp,%rdi
   18.13          movl  XREGS_entry_vector(%rsp),%eax
   18.14          leaq  SYMBOL_NAME(exception_table)(%rip),%rdx
   18.15 +        GET_CURRENT(%rbx)
   18.16          callq *(%rdx,%rax,8)
   18.17 -        jmp   restore_all_xen
   18.18 +        testb $3,XREGS_cs(%rsp)
   18.19 +        jz    restore_all_xen
   18.20 +        jmp   process_guest_exception_and_events
   18.21  
   18.22  exception_with_ints_disabled:
   18.23          testb $3,XREGS_cs(%rsp)         # interrupts disabled outside Xen?
   18.24 @@ -299,12 +303,15 @@ exception_with_ints_disabled:
   18.25          testq %rax,%rax                 # no fixup code for faulting EIP?
   18.26          jz    FATAL_exception_with_ints_disabled
   18.27          movq  %rax,XREGS_rip(%rsp)
   18.28 +        subq  $8,XREGS_rsp(%rsp)        # add ec/ev to previous stack frame
   18.29 +        testb $15,XREGS_rsp(%rsp)       # return %rsp is now aligned?
   18.30 +        jz    1f                        # then there is a pad quadword already
   18.31          movq  %rsp,%rsi
   18.32          subq  $8,%rsp
   18.33          movq  %rsp,%rdi
   18.34          movq  $XREGS_kernel_sizeof/8,%rcx
   18.35 -        rep;  movsq                     # make room for error_code/entry_vector
   18.36 -        movq  XREGS_error_code(%rsp),%rax # error_code/entry_vector
   18.37 +        rep;  movsq                     # make room for ec/ev
   18.38 +1:      movq  XREGS_error_code(%rsp),%rax # ec/ev
   18.39          movq  %rax,XREGS_kernel_sizeof(%rsp)
   18.40          jmp   restore_all_xen           # return to fixup code
   18.41  
    19.1 --- a/xen/include/asm-x86/x86_32/regs.h	Fri Feb 11 01:51:41 2005 +0000
    19.2 +++ b/xen/include/asm-x86/x86_32/regs.h	Fri Feb 11 11:34:22 2005 +0000
    19.3 @@ -12,4 +12,7 @@
    19.4  
    19.5  #define KERNEL_MODE(_e, _r) (!VM86_MODE(_r) && RING_1(_r))
    19.6  
    19.7 +#define PERMIT_SOFTINT(_dpl, _e, _r) \
    19.8 +    ((_dpl) >= (VM86_MODE(_r) ? 3 : ((_r)->cs & 3)))
    19.9 +
   19.10  #endif
    20.1 --- a/xen/include/asm-x86/x86_64/regs.h	Fri Feb 11 01:51:41 2005 +0000
    20.2 +++ b/xen/include/asm-x86/x86_64/regs.h	Fri Feb 11 11:34:22 2005 +0000
    20.3 @@ -12,4 +12,7 @@
    20.4  
    20.5  #define KERNEL_MODE(_e, _r) ((_e)->arch.flags & TF_kernel_mode)
    20.6  
    20.7 +#define PERMIT_SOFTINT(_dpl, _e, _r) \
    20.8 +    ((_dpl) >= (KERNEL_MODE(_e, _r) ? 1 : 3))
    20.9 +
   20.10  #endif
    21.1 --- a/xen/include/public/arch-x86_64.h	Fri Feb 11 01:51:41 2005 +0000
    21.2 +++ b/xen/include/public/arch-x86_64.h	Fri Feb 11 11:34:22 2005 +0000
    21.3 @@ -115,7 +115,14 @@ typedef unsigned long memory_t;   /* Ful
    21.4  typedef unsigned long cpureg_t;   /* Full-sized register.                    */
    21.5  
    21.6  /*
    21.7 - * Send an array of these to HYPERVISOR_set_trap_table()
    21.8 + * Send an array of these to HYPERVISOR_set_trap_table().
    21.9 + * N.B. As in x86/32 mode, the privilege level specifies which modes may enter
   21.10 + * a trap via a software interrupt. Since rings 1 and 2 are unavailable, we
   21.11 + * allocate privilege levels as follows:
   21.12 + *  Level == 0: Noone may enter
   21.13 + *  Level == 1: Kernel may enter
   21.14 + *  Level == 2: Kernel may enter
   21.15 + *  Level == 3: Everyone may enter
   21.16   */
   21.17  #define TI_GET_DPL(_ti)      ((_ti)->flags & 3)
   21.18  #define TI_GET_IF(_ti)       ((_ti)->flags & 4)