ia64/xen-unstable

changeset 13461:8690e3448971

[MINIOS] New make structure to support different architectures.
Signed-off-by: Dietmar Hahn <dietmar.hahn@fujitsu-siemens.com>
author kfraser@localhost.localdomain
date Wed Jan 17 15:09:50 2007 +0000 (2007-01-17)
parents 120d882a4d8e
children 6d832b092857
files extras/mini-os/Makefile extras/mini-os/arch/x86/Makefile extras/mini-os/arch/x86/arch.mk extras/mini-os/arch/x86/minios-x86_32.lds extras/mini-os/arch/x86/minios-x86_64.lds extras/mini-os/arch/x86/x86_32.S extras/mini-os/arch/x86/x86_64.S extras/mini-os/minios-x86_32.lds extras/mini-os/minios-x86_64.lds extras/mini-os/minios.mk extras/mini-os/x86_32.S extras/mini-os/x86_64.S
line diff
     1.1 --- a/extras/mini-os/Makefile	Wed Jan 17 15:03:27 2007 +0000
     1.2 +++ b/extras/mini-os/Makefile	Wed Jan 17 15:09:50 2007 +0000
     1.3 @@ -1,112 +1,88 @@
     1.4 -debug ?= y
     1.5 +# Common Makefile for mini-os.
     1.6 +#
     1.7 +# Every architecture directory below mini-os/arch has to have a
     1.8 +# Makefile and a arch.mk.
     1.9 +#
    1.10 +
    1.11  pae ?= n
    1.12  
    1.13  XEN_ROOT = ../..
    1.14  include $(XEN_ROOT)/Config.mk
    1.15  
    1.16 -# Set TARGET_ARCH
    1.17 -override TARGET_ARCH     := $(XEN_TARGET_ARCH)
    1.18 -
    1.19  XEN_INTERFACE_VERSION := 0x00030204
    1.20 +export XEN_INTERFACE_VERSION
    1.21  
    1.22 -# NB. '-Wcast-qual' is nasty, so I omitted it.
    1.23 -CFLAGS := -fno-builtin -Wall -Werror -Wredundant-decls -Wno-format
    1.24 -CFLAGS += -Wstrict-prototypes -Wnested-externs -Wpointer-arith -Winline
    1.25 -CFLAGS += -D__XEN_INTERFACE_VERSION__=$(XEN_INTERFACE_VERSION)
    1.26 +# Set TARGET_ARCH
    1.27 +override TARGET_ARCH := $(XEN_TARGET_ARCH)
    1.28  
    1.29 -ASFLAGS = -D__ASSEMBLY__
    1.30 +# Set mini-os root path, used in mini-os.mk.
    1.31 +MINI-OS_ROOT=$(PWD)
    1.32 +export MINI-OS_ROOT
    1.33  
    1.34 -LDLIBS =  -L. -lminios
    1.35 -LDFLAGS_FINAL := -N -T minios-$(TARGET_ARCH).lds
    1.36 -LDFLAGS :=
    1.37 +# Try to find out the architecture family TARGET_ARCH_FAM.
    1.38 +# First check whether x86_... is contained (for x86_32, x86_32y, x86_64).
    1.39 +# If not x86 then use $(TARGET_ARCH) -> for ia64, ...
    1.40 +ifeq ($(findstring x86_,$(TARGET_ARCH)),x86_)
    1.41 +TARGET_ARCH_FAM = x86
    1.42 +else
    1.43 +TARGET_ARCH_FAM = $(TARGET_ARCH)
    1.44 +endif
    1.45 +
    1.46 +# The architecture family directory below mini-os.
    1.47 +TARGET_ARCH_DIR := arch/$(TARGET_ARCH_FAM)
    1.48 +
    1.49 +# Export these variables for possible use in architecture dependent makefiles.
    1.50 +export TARGET_ARCH
    1.51 +export TARGET_ARCH_DIR
    1.52 +export TARGET_ARCH_FAM
    1.53 +
    1.54 +# This is used for architecture specific links.
    1.55 +# This can be overwritten from arch specific rules.
    1.56 +ARCH_LINKS =
    1.57 +
    1.58 +# For possible special header directories.
    1.59 +# This can be overwritten from arch specific rules.
    1.60 +EXTRA_INC =
    1.61 +
    1.62 +# Special build dependencies.
    1.63 +# Build all after touching this/these file(s) (see minios.mk)
    1.64 +SPEC_DEPENDS = minios.mk
    1.65 +
    1.66 +# Include the architecture family's special makerules.
    1.67 +# This must be before include minios.mk!
    1.68 +include $(TARGET_ARCH_DIR)/arch.mk
    1.69 +
    1.70 +# Include common mini-os makerules.
    1.71 +include minios.mk
    1.72 +
    1.73 +# Define some default flags for linking.
    1.74 +LDLIBS := 
    1.75 +LDFLAGS := 
    1.76 +LDARCHLIB := -L$(TARGET_ARCH_DIR) -l$(ARCH_LIB_NAME)
    1.77 +LDFLAGS_FINAL := -N -T $(TARGET_ARCH_DIR)/minios-$(TARGET_ARCH).lds
    1.78  
    1.79  # Prefix for global API names. All other symbols are localised before
    1.80  # linking with EXTRA_OBJS.
    1.81  GLOBAL_PREFIX := xenos_
    1.82  EXTRA_OBJS =
    1.83  
    1.84 -# For possible special source directories.
    1.85 -EXTRA_SRC =
    1.86 -# For possible special header directories.
    1.87 -EXTRA_INC =
    1.88 -
    1.89 -# Standard name for architecture specific subdirectories.
    1.90 -TARGET_ARCH_DIR = $(TARGET_ARCH)
    1.91 -# This is used for architecture specific links.
    1.92 -ARCH_LINKS =
    1.93 -
    1.94 -ifeq ($(TARGET_ARCH),x86_32)
    1.95 -CFLAGS += -m32 -march=i686
    1.96 -LDFLAGS += -m elf_i386
    1.97 -TARGET_ARCH_DIR = x86
    1.98 -EXTRA_INC += $(TARGET_ARCH_DIR)/$(TARGET_ARCH)
    1.99 -EXTRA_SRC += arch/$(EXTRA_INC)
   1.100 -endif
   1.101 -
   1.102 -ifeq ($(TARGET_ARCH)$(pae),x86_32y)
   1.103 -CFLAGS  += -DCONFIG_X86_PAE=1
   1.104 -ASFLAGS += -DCONFIG_X86_PAE=1
   1.105 -TARGET_ARCH_DIR = x86
   1.106 -EXTRA_INC += $(TARGET_ARCH_DIR)/$(TARGET_ARCH)
   1.107 -EXTRA_SRC += arch/$(EXTRA_INC)
   1.108 -endif
   1.109 -
   1.110 -ifeq ($(TARGET_ARCH),x86_64)
   1.111 -CFLAGS += -m64 -mno-red-zone -fpic -fno-reorder-blocks
   1.112 -CFLAGS += -fno-asynchronous-unwind-tables
   1.113 -LDFLAGS += -m elf_x86_64
   1.114 -TARGET_ARCH_DIR = x86
   1.115 -EXTRA_INC += $(TARGET_ARCH_DIR)/$(TARGET_ARCH)
   1.116 -EXTRA_SRC += arch/$(EXTRA_INC)
   1.117 -endif
   1.118 -
   1.119 -ifeq ($(TARGET_ARCH),ia64)
   1.120 -CFLAGS += -mfixed-range=f2-f5,f12-f15,f32-f127 -mconstant-gp
   1.121 -ASFLAGS += -x assembler-with-cpp -Wall
   1.122 -ASFLAGS += -mfixed-range=f2-f5,f12-f15,f32-f127 -fomit-frame-pointer
   1.123 -ASFLAGS += -fno-builtin -fno-common -fno-strict-aliasing -mconstant-gp
   1.124 -ARCH_LINKS = IA64_LINKS		# Special link on ia64 needed
   1.125 -define arch_links
   1.126 -[ -e include/ia64/asm-xsi-offsets.h ] || ln -sf ../../../../xen/include/asm-ia64/asm-xsi-offsets.h include/ia64/asm-xsi-offsets.h
   1.127 -endef
   1.128 -endif
   1.129 -
   1.130 -ifeq ($(debug),y)
   1.131 -CFLAGS += -g
   1.132 -else
   1.133 -CFLAGS += -O3
   1.134 -endif
   1.135 -
   1.136 -# Add the special header directories to the include paths.
   1.137 -extra_incl := $(foreach dir,$(EXTRA_INC),-Iinclude/$(dir))
   1.138 -override CPPFLAGS := -Iinclude $(CPPFLAGS) -Iinclude/$(TARGET_ARCH_DIR)	$(extra_incl)
   1.139 -
   1.140  TARGET := mini-os
   1.141  
   1.142 -HEAD := $(TARGET_ARCH).o
   1.143 +# Subdirectories common to mini-os
   1.144 +SUBDIRS := lib xenbus console
   1.145 +
   1.146 +# The common mini-os objects to build.
   1.147  OBJS := $(patsubst %.c,%.o,$(wildcard *.c))
   1.148  OBJS += $(patsubst %.c,%.o,$(wildcard lib/*.c))
   1.149  OBJS += $(patsubst %.c,%.o,$(wildcard xenbus/*.c))
   1.150  OBJS += $(patsubst %.c,%.o,$(wildcard console/*.c))
   1.151 -OBJS += $(patsubst %.S,%.o,$(wildcard arch/$(TARGET_ARCH_DIR)/*.S))
   1.152 -OBJS += $(patsubst %.c,%.o,$(wildcard arch/$(TARGET_ARCH_DIR)/*.c))
   1.153 -# For special wanted source directories.
   1.154 -extra_objs := $(foreach dir,$(EXTRA_SRC),$(patsubst %.c,%.o,$(wildcard $(dir)/*.c)))
   1.155 -OBJS += $(extra_objs)
   1.156 -extra_objs := $(foreach dir,$(EXTRA_SRC),$(patsubst %.S,%.o,$(wildcard $(dir)/*.S)))
   1.157 -OBJS += $(extra_objs)
   1.158  
   1.159 -HDRS := $(wildcard include/*.h)
   1.160 -HDRS += $(wildcard include/xen/*.h)
   1.161 -HDRS += $(wildcard include/$(TARGET_ARCH_DIR)/*.h)
   1.162 -# For special wanted header directories.
   1.163 -extra_heads := $(foreach dir,$(EXTRA_INC),$(wildcard $(dir)/*.h))
   1.164 -HDRS += $(extra_heads)
   1.165  
   1.166  .PHONY: default
   1.167  default: $(TARGET)
   1.168  
   1.169 -# Create special architecture specific links.
   1.170 +# Create special architecture specific links. The function arch_links
   1.171 +# has to be defined in arch.mk (see include above).
   1.172  ifneq ($(ARCH_LINKS),)
   1.173  $(ARCH_LINKS):
   1.174  	$(arch_links)
   1.175 @@ -116,24 +92,29 @@ endif
   1.176  links:	$(ARCH_LINKS)
   1.177  	[ -e include/xen ] || ln -sf ../../../xen/include/public include/xen
   1.178  
   1.179 -$(TARGET): links $(OBJS) $(HEAD)
   1.180 -	$(LD) -r $(LDFLAGS) $(HEAD) $(OBJS) -o $@.o
   1.181 +.PHONY: arch_lib
   1.182 +arch_lib:
   1.183 +	$(MAKE) --directory=$(TARGET_ARCH_DIR) || exit 1;
   1.184 +
   1.185 +$(TARGET): links $(OBJS) arch_lib
   1.186 +	$(LD) -r $(LDFLAGS) $(HEAD_OBJ) $(OBJS) $(LDARCHLIB) -o $@.o
   1.187  	$(OBJCOPY) -w -G $(GLOBAL_PREFIX)* -G _start $@.o $@.o
   1.188  	$(LD) $(LDFLAGS) $(LDFLAGS_FINAL) $@.o $(EXTRA_OBJS) -o $@
   1.189  	gzip -f -9 -c $@ >$@.gz
   1.190  
   1.191 -.PHONY: clean
   1.192 -clean:
   1.193 -	find . -type f -name '*.o' | xargs rm -f
   1.194 -	rm -f *.o *~ core $(TARGET) $(TARGET).gz
   1.195 +.PHONY: clean arch_clean
   1.196 +
   1.197 +arch_clean:
   1.198 +	$(MAKE) --directory=$(TARGET_ARCH_DIR) clean || exit 1;
   1.199 +
   1.200 +clean:	arch_clean
   1.201 +	for dir in $(SUBDIRS); do \
   1.202 +		rm -f $$dir/*.o; \
   1.203 +	done
   1.204 +	rm -f *.o *~ core $(TARGET).elf $(TARGET).raw $(TARGET) $(TARGET).gz
   1.205  	find . -type l | xargs rm -f
   1.206  	rm -f tags TAGS
   1.207  
   1.208 -%.o: %.c $(HDRS) Makefile
   1.209 -	$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
   1.210 -
   1.211 -%.o: %.S $(HDRS) Makefile
   1.212 -	$(CC) $(ASFLAGS) $(CPPFLAGS) -c $< -o $@
   1.213  
   1.214  define all_sources
   1.215       ( find . -follow -name SCCS -prune -o -name '*.[chS]' -print )
   1.216 @@ -147,3 +128,4 @@ cscope:
   1.217  .PHONY: tags
   1.218  tags:
   1.219  	$(all_sources) | xargs ctags
   1.220 +
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/extras/mini-os/arch/x86/Makefile	Wed Jan 17 15:09:50 2007 +0000
     2.3 @@ -0,0 +1,29 @@
     2.4 +#
     2.5 +# x86 architecture specific makefiles.
     2.6 +# It's is used for x86_32, x86_32y and x86_64
     2.7 +#
     2.8 +
     2.9 +# Rebuild all after touching this/these extra file(s) (see mini-os.mk)
    2.10 +SPEC_DEP = arch.mk
    2.11 +
    2.12 +# include arch.mk has to be before mini-os.mk!
    2.13 +include arch.mk
    2.14 +include ../../minios.mk
    2.15 +
    2.16 +# Sources here are all *.c *.S without $(TARGET_ARCH).S
    2.17 +# This is handled in $(HEAD_ARCH_OBJ)
    2.18 +ARCH_SRCS := $(wildcard *.c)
    2.19 +
    2.20 +# The objects built from the sources.
    2.21 +ARCH_OBJS := $(patsubst %.c,%.o,$(ARCH_SRCS))
    2.22 +
    2.23 +all: $(ARCH_LIB)
    2.24 +
    2.25 +# $(HEAD_ARCH_OBJ) is only build here, needed on linking
    2.26 +# in ../../Makefile.
    2.27 +$(ARCH_LIB): $(ARCH_OBJS) $(HEAD_ARCH_OBJ)
    2.28 +	$(AR) rv $(ARCH_LIB) $(ARCH_OBJS)
    2.29 +
    2.30 +clean:
    2.31 +	rm -f $(ARCH_LIB) $(ARCH_OBJS)
    2.32 +
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/extras/mini-os/arch/x86/arch.mk	Wed Jan 17 15:09:50 2007 +0000
     3.3 @@ -0,0 +1,28 @@
     3.4 +#
     3.5 +# Architecture special makerules for x86 family
     3.6 +# (including x86_32, x86_32y and x86_64).
     3.7 +#
     3.8 +
     3.9 +ifeq ($(TARGET_ARCH),x86_32)
    3.10 +ARCH_CFLAGS  := -m32 -march=i686
    3.11 +ARCH_LDFLAGS := -m elf_i386
    3.12 +EXTRA_INC += $(TARGET_ARCH_FAM)/$(TARGET_ARCH)
    3.13 +EXTRA_SRC += arch/$(EXTRA_INC)
    3.14 +endif
    3.15 +
    3.16 +ifeq ($(TARGET_ARCH)$(pae),x86_32y)
    3.17 +ARCH_CFLAGS  := -DCONFIG_X86_PAE=1
    3.18 +ARCH_ASFLAGS := -DCONFIG_X86_PAE=1
    3.19 +EXTRA_INC += $(TARGET_ARCH_FAM)/$(TARGET_ARCH)
    3.20 +EXTRA_SRC += arch/$(EXTRA_INC)
    3.21 +endif
    3.22 +
    3.23 +ifeq ($(TARGET_ARCH),x86_64)
    3.24 +ARCH_CFLAGS := -m64 -mno-red-zone -fpic -fno-reorder-blocks
    3.25 +ARCH_CFLAGS := -fno-asynchronous-unwind-tables
    3.26 +ARCH_LDFLAGS := -m elf_x86_64
    3.27 +EXTRA_INC += $(TARGET_ARCH_FAM)/$(TARGET_ARCH)
    3.28 +EXTRA_SRC += arch/$(EXTRA_INC)
    3.29 +endif
    3.30 +
    3.31 +
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/extras/mini-os/arch/x86/minios-x86_32.lds	Wed Jan 17 15:09:50 2007 +0000
     4.3 @@ -0,0 +1,45 @@
     4.4 +OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
     4.5 +OUTPUT_ARCH(i386)
     4.6 +ENTRY(_start)
     4.7 +SECTIONS
     4.8 +{
     4.9 +  . = 0x0;
    4.10 +  _text = .;			/* Text and read-only data */
    4.11 +  .text : {
    4.12 +	*(.text)
    4.13 +	*(.gnu.warning)
    4.14 +	} = 0x9090
    4.15 +
    4.16 +  _etext = .;			/* End of text section */
    4.17 +
    4.18 +  .rodata : { *(.rodata) *(.rodata.*) }
    4.19 +
    4.20 +  .data : {			/* Data */
    4.21 +	*(.data)
    4.22 +	CONSTRUCTORS
    4.23 +	}
    4.24 +
    4.25 +  _edata = .;			/* End of data section */
    4.26 +
    4.27 +  __bss_start = .;		/* BSS */
    4.28 +  .bss : {
    4.29 +	*(.bss)
    4.30 +	}
    4.31 +  _end = . ;
    4.32 +
    4.33 +  /* Sections to be discarded */
    4.34 +  /DISCARD/ : {
    4.35 +	*(.text.exit)
    4.36 +	*(.data.exit)
    4.37 +	*(.exitcall.exit)
    4.38 +	}
    4.39 +
    4.40 +  /* Stabs debugging sections.  */
    4.41 +  .stab 0 : { *(.stab) }
    4.42 +  .stabstr 0 : { *(.stabstr) }
    4.43 +  .stab.excl 0 : { *(.stab.excl) }
    4.44 +  .stab.exclstr 0 : { *(.stab.exclstr) }
    4.45 +  .stab.index 0 : { *(.stab.index) }
    4.46 +  .stab.indexstr 0 : { *(.stab.indexstr) }
    4.47 +  .comment 0 : { *(.comment) }
    4.48 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/extras/mini-os/arch/x86/minios-x86_64.lds	Wed Jan 17 15:09:50 2007 +0000
     5.3 @@ -0,0 +1,54 @@
     5.4 +OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64", "elf64-x86-64")
     5.5 +OUTPUT_ARCH(i386:x86-64)
     5.6 +ENTRY(_start)
     5.7 +SECTIONS
     5.8 +{
     5.9 +  . = 0x0;
    5.10 +  _text = .;			/* Text and read-only data */
    5.11 +  .text : {
    5.12 +	*(.text)
    5.13 +	*(.gnu.warning)
    5.14 +	} = 0x9090
    5.15 +
    5.16 +  _etext = .;			/* End of text section */
    5.17 +
    5.18 +  .rodata : { *(.rodata) *(.rodata.*) }
    5.19 +
    5.20 +  .data : {			/* Data */
    5.21 +	*(.data)
    5.22 +	CONSTRUCTORS
    5.23 +	}
    5.24 +
    5.25 +  _edata = .;			/* End of data section */
    5.26 +
    5.27 +  . = ALIGN(8192);		/* init_task */
    5.28 +  .data.init_task : { *(.data.init_task) }
    5.29 +
    5.30 +  . = ALIGN(4096);
    5.31 +  .data.page_aligned : { *(.data.idt) }
    5.32 +
    5.33 +  . = ALIGN(32);
    5.34 +  .data.cacheline_aligned : { *(.data.cacheline_aligned) }
    5.35 +
    5.36 +  __bss_start = .;		/* BSS */
    5.37 +  .bss : {
    5.38 +	*(.bss)
    5.39 +	}
    5.40 +  _end = . ;
    5.41 +
    5.42 +  /* Sections to be discarded */
    5.43 +  /DISCARD/ : {
    5.44 +	*(.text.exit)
    5.45 +	*(.data.exit)
    5.46 +	*(.exitcall.exit)
    5.47 +	}
    5.48 +
    5.49 +  /* Stabs debugging sections.  */
    5.50 +  .stab 0 : { *(.stab) }
    5.51 +  .stabstr 0 : { *(.stabstr) }
    5.52 +  .stab.excl 0 : { *(.stab.excl) }
    5.53 +  .stab.exclstr 0 : { *(.stab.exclstr) }
    5.54 +  .stab.index 0 : { *(.stab.index) }
    5.55 +  .stab.indexstr 0 : { *(.stab.indexstr) }
    5.56 +  .comment 0 : { *(.comment) }
    5.57 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/extras/mini-os/arch/x86/x86_32.S	Wed Jan 17 15:09:50 2007 +0000
     6.3 @@ -0,0 +1,287 @@
     6.4 +#include <os.h>
     6.5 +#include <xen/arch-x86_32.h>
     6.6 +
     6.7 +.section __xen_guest
     6.8 +	.ascii	"GUEST_OS=Mini-OS"
     6.9 +	.ascii	",XEN_VER=xen-3.0"
    6.10 +	.ascii	",VIRT_BASE=0x0" /* &_text from minios_x86_32.lds */
    6.11 +	.ascii	",ELF_PADDR_OFFSET=0x0"
    6.12 +	.ascii	",HYPERCALL_PAGE=0x2"
    6.13 +#ifdef CONFIG_X86_PAE
    6.14 +	.ascii	",PAE=yes"
    6.15 +#else
    6.16 +	.ascii	",PAE=no"
    6.17 +#endif
    6.18 +	.ascii	",LOADER=generic"
    6.19 +	.byte	0
    6.20 +.text
    6.21 +
    6.22 +.globl _start, shared_info, hypercall_page
    6.23 +                        
    6.24 +_start:
    6.25 +        cld
    6.26 +        lss stack_start,%esp
    6.27 +        push %esi 
    6.28 +        call start_kernel
    6.29 +
    6.30 +stack_start:
    6.31 +	.long stack+8192, __KERNEL_SS
    6.32 +
    6.33 +        /* Unpleasant -- the PTE that maps this page is actually overwritten */
    6.34 +        /* to map the real shared-info page! :-)                             */
    6.35 +        .org 0x1000
    6.36 +shared_info:
    6.37 +        .org 0x2000
    6.38 +
    6.39 +hypercall_page:
    6.40 +        .org 0x3000
    6.41 +
    6.42 +ES		= 0x20
    6.43 +ORIG_EAX	= 0x24
    6.44 +EIP		= 0x28
    6.45 +CS		= 0x2C
    6.46 +
    6.47 +#define ENTRY(X) .globl X ; X :
    6.48 +
    6.49 +#define SAVE_ALL \
    6.50 +	cld; \
    6.51 +	pushl %es; \
    6.52 +	pushl %ds; \
    6.53 +	pushl %eax; \
    6.54 +	pushl %ebp; \
    6.55 +	pushl %edi; \
    6.56 +	pushl %esi; \
    6.57 +	pushl %edx; \
    6.58 +	pushl %ecx; \
    6.59 +	pushl %ebx; \
    6.60 +	movl $(__KERNEL_DS),%edx; \
    6.61 +	movl %edx,%ds; \
    6.62 +	movl %edx,%es;
    6.63 +
    6.64 +#define RESTORE_ALL	\
    6.65 +	popl %ebx;	\
    6.66 +	popl %ecx;	\
    6.67 +	popl %edx;	\
    6.68 +	popl %esi;	\
    6.69 +	popl %edi;	\
    6.70 +	popl %ebp;	\
    6.71 +	popl %eax;	\
    6.72 +	popl %ds;	\
    6.73 +	popl %es;	\
    6.74 +	addl $4,%esp;	\
    6.75 +	iret;		\
    6.76 +
    6.77 +ENTRY(divide_error)
    6.78 +	pushl $0		# no error code
    6.79 +	pushl $do_divide_error
    6.80 +do_exception:
    6.81 +    pushl %ds
    6.82 +	pushl %eax
    6.83 +	xorl %eax, %eax
    6.84 +	pushl %ebp
    6.85 +	pushl %edi
    6.86 +	pushl %esi
    6.87 +	pushl %edx
    6.88 +	decl %eax			# eax = -1
    6.89 +	pushl %ecx
    6.90 +	pushl %ebx
    6.91 +	cld
    6.92 +	movl %es, %ecx
    6.93 +	movl ES(%esp), %edi		# get the function address
    6.94 +	movl ORIG_EAX(%esp), %edx	# get the error code
    6.95 +	movl %eax, ORIG_EAX(%esp)
    6.96 +	movl %ecx, ES(%esp)
    6.97 +	movl $(__KERNEL_DS), %ecx
    6.98 +	movl %ecx, %ds
    6.99 +	movl %ecx, %es
   6.100 +	movl %esp,%eax			# pt_regs pointer
   6.101 +    pushl %edx
   6.102 +    pushl %eax
   6.103 +	call *%edi
   6.104 +    jmp ret_from_exception
   6.105 +    
   6.106 +ret_from_exception:
   6.107 +        movb CS(%esp),%cl
   6.108 +	test $2,%cl          # slow return to ring 2 or 3
   6.109 +	jne  safesti
   6.110 +        RESTORE_ALL
   6.111 +
   6.112 +# A note on the "critical region" in our callback handler.
   6.113 +# We want to avoid stacking callback handlers due to events occurring
   6.114 +# during handling of the last event. To do this, we keep events disabled
   6.115 +# until weve done all processing. HOWEVER, we must enable events before
   6.116 +# popping the stack frame (cant be done atomically) and so it would still
   6.117 +# be possible to get enough handler activations to overflow the stack.
   6.118 +# Although unlikely, bugs of that kind are hard to track down, so wed
   6.119 +# like to avoid the possibility.
   6.120 +# So, on entry to the handler we detect whether we interrupted an
   6.121 +# existing activation in its critical region -- if so, we pop the current
   6.122 +# activation and restart the handler using the previous one.
   6.123 +ENTRY(hypervisor_callback)
   6.124 +        pushl %eax
   6.125 +        SAVE_ALL
   6.126 +        movl EIP(%esp),%eax
   6.127 +        cmpl $scrit,%eax
   6.128 +        jb   11f
   6.129 +        cmpl $ecrit,%eax
   6.130 +        jb   critical_region_fixup
   6.131 +11:     push %esp
   6.132 +        call do_hypervisor_callback
   6.133 +        add  $4,%esp
   6.134 +        movl HYPERVISOR_shared_info,%esi
   6.135 +        xorl %eax,%eax
   6.136 +        movb CS(%esp),%cl
   6.137 +    	test $2,%cl          # slow return to ring 2 or 3
   6.138 +        jne  safesti
   6.139 +safesti:movb $0,1(%esi)     # reenable event callbacks
   6.140 +scrit:  /**** START OF CRITICAL REGION ****/
   6.141 +        testb $0xFF,(%esi)
   6.142 +        jnz  14f              # process more events if necessary...
   6.143 +        RESTORE_ALL
   6.144 +14:     movb $1,1(%esi)
   6.145 +        jmp  11b
   6.146 +ecrit:  /**** END OF CRITICAL REGION ****/
   6.147 +# [How we do the fixup]. We want to merge the current stack frame with the
   6.148 +# just-interrupted frame. How we do this depends on where in the critical
   6.149 +# region the interrupted handler was executing, and so how many saved
   6.150 +# registers are in each frame. We do this quickly using the lookup table
   6.151 +# 'critical_fixup_table'. For each byte offset in the critical region, it
   6.152 +# provides the number of bytes which have already been popped from the
   6.153 +# interrupted stack frame. 
   6.154 +critical_region_fixup:
   6.155 +        addl $critical_fixup_table-scrit,%eax
   6.156 +        movzbl (%eax),%eax    # %eax contains num bytes popped
   6.157 +        mov  %esp,%esi
   6.158 +        add  %eax,%esi        # %esi points at end of src region
   6.159 +        mov  %esp,%edi
   6.160 +        add  $0x34,%edi       # %edi points at end of dst region
   6.161 +        mov  %eax,%ecx
   6.162 +        shr  $2,%ecx          # convert words to bytes
   6.163 +        je   16f              # skip loop if nothing to copy
   6.164 +15:     subl $4,%esi          # pre-decrementing copy loop
   6.165 +        subl $4,%edi
   6.166 +        movl (%esi),%eax
   6.167 +        movl %eax,(%edi)
   6.168 +        loop 15b
   6.169 +16:     movl %edi,%esp        # final %edi is top of merged stack
   6.170 +        jmp  11b
   6.171 +         
   6.172 +critical_fixup_table:        
   6.173 +        .byte 0x00,0x00,0x00                  # testb $0xff,(%esi)
   6.174 +        .byte 0x00,0x00                       # jne  14f
   6.175 +        .byte 0x00                            # pop  %ebx
   6.176 +        .byte 0x04                            # pop  %ecx
   6.177 +        .byte 0x08                            # pop  %edx
   6.178 +        .byte 0x0c                            # pop  %esi
   6.179 +        .byte 0x10                            # pop  %edi
   6.180 +        .byte 0x14                            # pop  %ebp
   6.181 +        .byte 0x18                            # pop  %eax
   6.182 +        .byte 0x1c                            # pop  %ds
   6.183 +        .byte 0x20                            # pop  %es
   6.184 +        .byte 0x24,0x24,0x24                  # add  $4,%esp
   6.185 +        .byte 0x28                            # iret
   6.186 +        .byte 0x00,0x00,0x00,0x00             # movb $1,1(%esi)
   6.187 +        .byte 0x00,0x00                       # jmp  11b
   6.188 +       
   6.189 +# Hypervisor uses this for application faults while it executes.
   6.190 +ENTRY(failsafe_callback)
   6.191 +      pop  %ds
   6.192 +      pop  %es
   6.193 +      pop  %fs
   6.194 +      pop  %gs
   6.195 +      iret
   6.196 +                
   6.197 +ENTRY(coprocessor_error)
   6.198 +	pushl $0
   6.199 +	pushl $do_coprocessor_error
   6.200 +	jmp do_exception
   6.201 +
   6.202 +ENTRY(simd_coprocessor_error)
   6.203 +	pushl $0
   6.204 +	pushl $do_simd_coprocessor_error
   6.205 +	jmp do_exception
   6.206 +
   6.207 +ENTRY(device_not_available)
   6.208 +        iret
   6.209 +
   6.210 +ENTRY(debug)
   6.211 +	pushl $0
   6.212 +	pushl $do_debug
   6.213 +	jmp do_exception
   6.214 +
   6.215 +ENTRY(int3)
   6.216 +	pushl $0
   6.217 +	pushl $do_int3
   6.218 +	jmp do_exception
   6.219 +
   6.220 +ENTRY(overflow)
   6.221 +	pushl $0
   6.222 +	pushl $do_overflow
   6.223 +	jmp do_exception
   6.224 +
   6.225 +ENTRY(bounds)
   6.226 +	pushl $0
   6.227 +	pushl $do_bounds
   6.228 +	jmp do_exception
   6.229 +
   6.230 +ENTRY(invalid_op)
   6.231 +	pushl $0
   6.232 +	pushl $do_invalid_op
   6.233 +	jmp do_exception
   6.234 +
   6.235 +
   6.236 +ENTRY(coprocessor_segment_overrun)
   6.237 +	pushl $0
   6.238 +	pushl $do_coprocessor_segment_overrun
   6.239 +	jmp do_exception
   6.240 +
   6.241 +
   6.242 +ENTRY(invalid_TSS)
   6.243 +	pushl $do_invalid_TSS
   6.244 +	jmp do_exception
   6.245 +
   6.246 +
   6.247 +ENTRY(segment_not_present)
   6.248 +	pushl $do_segment_not_present
   6.249 +	jmp do_exception
   6.250 +
   6.251 +
   6.252 +ENTRY(stack_segment)
   6.253 +	pushl $do_stack_segment
   6.254 +	jmp do_exception
   6.255 +
   6.256 +
   6.257 +ENTRY(general_protection)
   6.258 +	pushl $do_general_protection
   6.259 +	jmp do_exception
   6.260 +
   6.261 +
   6.262 +ENTRY(alignment_check)
   6.263 +	pushl $do_alignment_check
   6.264 +	jmp do_exception
   6.265 +
   6.266 +
   6.267 +ENTRY(page_fault)
   6.268 +    pushl $do_page_fault
   6.269 +    jmp do_exception
   6.270 +    
   6.271 +ENTRY(machine_check)
   6.272 +	pushl $0
   6.273 +	pushl $do_machine_check
   6.274 +	jmp do_exception
   6.275 +
   6.276 +
   6.277 +ENTRY(spurious_interrupt_bug)
   6.278 +	pushl $0
   6.279 +	pushl $do_spurious_interrupt_bug
   6.280 +	jmp do_exception
   6.281 +
   6.282 +
   6.283 +
   6.284 +ENTRY(thread_starter)
   6.285 +    popl %eax
   6.286 +    popl %ebx
   6.287 +    pushl %eax
   6.288 +    call *%ebx
   6.289 +    call exit_thread 
   6.290 +    
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/extras/mini-os/arch/x86/x86_64.S	Wed Jan 17 15:09:50 2007 +0000
     7.3 @@ -0,0 +1,385 @@
     7.4 +#include <os.h>
     7.5 +#include <xen/features.h>
     7.6 +
     7.7 +.section __xen_guest
     7.8 +	.ascii	"GUEST_OS=Mini-OS"
     7.9 +	.ascii	",XEN_VER=xen-3.0"
    7.10 +	.ascii	",VIRT_BASE=0x0" /* &_text from minios_x86_64.lds */
    7.11 +	.ascii	",ELF_PADDR_OFFSET=0x0"
    7.12 +	.ascii	",HYPERCALL_PAGE=0x2"
    7.13 +	.ascii	",LOADER=generic"
    7.14 +	.byte	0
    7.15 +.text
    7.16 +
    7.17 +#define ENTRY(X) .globl X ; X :
    7.18 +.globl _start, shared_info, hypercall_page
    7.19 +
    7.20 +
    7.21 +_start:
    7.22 +        cld
    7.23 +        movq stack_start(%rip),%rsp
    7.24 +        movq %rsi,%rdi
    7.25 +        call start_kernel
    7.26 +
    7.27 +stack_start:
    7.28 +        .quad stack+8192
    7.29 +
    7.30 +        /* Unpleasant -- the PTE that maps this page is actually overwritten */
    7.31 +        /* to map the real shared-info page! :-)                             */
    7.32 +        .org 0x1000
    7.33 +shared_info:
    7.34 +        .org 0x2000
    7.35 +
    7.36 +hypercall_page:
    7.37 +        .org 0x3000
    7.38 +
    7.39 +
    7.40 +/* Offsets into shared_info_t. */                
    7.41 +#define evtchn_upcall_pending		/* 0 */
    7.42 +#define evtchn_upcall_mask		1
    7.43 +
    7.44 +NMI_MASK = 0x80000000
    7.45 +
    7.46 +#define RDI 112
    7.47 +#define ORIG_RAX 120       /* + error_code */ 
    7.48 +#define EFLAGS 144
    7.49 +
    7.50 +#define REST_SKIP 6*8			
    7.51 +.macro SAVE_REST
    7.52 +	subq $REST_SKIP,%rsp
    7.53 +#	CFI_ADJUST_CFA_OFFSET	REST_SKIP
    7.54 +	movq %rbx,5*8(%rsp) 
    7.55 +#	CFI_REL_OFFSET	rbx,5*8
    7.56 +	movq %rbp,4*8(%rsp) 
    7.57 +#	CFI_REL_OFFSET	rbp,4*8
    7.58 +	movq %r12,3*8(%rsp) 
    7.59 +#	CFI_REL_OFFSET	r12,3*8
    7.60 +	movq %r13,2*8(%rsp) 
    7.61 +#	CFI_REL_OFFSET	r13,2*8
    7.62 +	movq %r14,1*8(%rsp) 
    7.63 +#	CFI_REL_OFFSET	r14,1*8
    7.64 +	movq %r15,(%rsp) 
    7.65 +#	CFI_REL_OFFSET	r15,0*8
    7.66 +.endm		
    7.67 +
    7.68 +
    7.69 +.macro RESTORE_REST
    7.70 +	movq (%rsp),%r15
    7.71 +#	CFI_RESTORE r15
    7.72 +	movq 1*8(%rsp),%r14
    7.73 +#	CFI_RESTORE r14
    7.74 +	movq 2*8(%rsp),%r13
    7.75 +#	CFI_RESTORE r13
    7.76 +	movq 3*8(%rsp),%r12
    7.77 +#	CFI_RESTORE r12
    7.78 +	movq 4*8(%rsp),%rbp
    7.79 +#	CFI_RESTORE rbp
    7.80 +	movq 5*8(%rsp),%rbx
    7.81 +#	CFI_RESTORE rbx
    7.82 +	addq $REST_SKIP,%rsp
    7.83 +#	CFI_ADJUST_CFA_OFFSET	-(REST_SKIP)
    7.84 +.endm
    7.85 +
    7.86 +
    7.87 +#define ARG_SKIP 9*8
    7.88 +.macro RESTORE_ARGS skiprax=0,addskip=0,skiprcx=0,skipr11=0,skipr8910=0,skiprdx=0
    7.89 +	.if \skipr11
    7.90 +	.else
    7.91 +	movq (%rsp),%r11
    7.92 +#	CFI_RESTORE r11
    7.93 +	.endif
    7.94 +	.if \skipr8910
    7.95 +	.else
    7.96 +	movq 1*8(%rsp),%r10
    7.97 +#	CFI_RESTORE r10
    7.98 +	movq 2*8(%rsp),%r9
    7.99 +#	CFI_RESTORE r9
   7.100 +	movq 3*8(%rsp),%r8
   7.101 +#	CFI_RESTORE r8
   7.102 +	.endif
   7.103 +	.if \skiprax
   7.104 +	.else
   7.105 +	movq 4*8(%rsp),%rax
   7.106 +#	CFI_RESTORE rax
   7.107 +	.endif
   7.108 +	.if \skiprcx
   7.109 +	.else
   7.110 +	movq 5*8(%rsp),%rcx
   7.111 +#	CFI_RESTORE rcx
   7.112 +	.endif
   7.113 +	.if \skiprdx
   7.114 +	.else
   7.115 +	movq 6*8(%rsp),%rdx
   7.116 +#	CFI_RESTORE rdx
   7.117 +	.endif
   7.118 +	movq 7*8(%rsp),%rsi
   7.119 +#	CFI_RESTORE rsi
   7.120 +	movq 8*8(%rsp),%rdi
   7.121 +#	CFI_RESTORE rdi
   7.122 +	.if ARG_SKIP+\addskip > 0
   7.123 +	addq $ARG_SKIP+\addskip,%rsp
   7.124 +#	CFI_ADJUST_CFA_OFFSET	-(ARG_SKIP+\addskip)
   7.125 +	.endif
   7.126 +.endm	
   7.127 +
   7.128 +
   7.129 +.macro HYPERVISOR_IRET flag
   7.130 +#    testb $3,1*8(%rsp)    /* Don't need to do that in Mini-os, as */
   7.131 +#	jnz   2f               /* there is no userspace? */
   7.132 +	testl $NMI_MASK,2*8(%rsp)
   7.133 +	jnz   2f
   7.134 +
   7.135 +	testb $1,(xen_features+XENFEAT_supervisor_mode_kernel)
   7.136 +	jnz   1f
   7.137 +
   7.138 +	/* Direct iret to kernel space. Correct CS and SS. */
   7.139 +	orb   $3,1*8(%rsp)
   7.140 +	orb   $3,4*8(%rsp)
   7.141 +1:	iretq
   7.142 +
   7.143 +2:	/* Slow iret via hypervisor. */
   7.144 +	andl  $~NMI_MASK, 16(%rsp)
   7.145 +	pushq $\flag
   7.146 +	jmp  hypercall_page + (__HYPERVISOR_iret * 32)
   7.147 +.endm
   7.148 +
   7.149 +/*
   7.150 + * Exception entry point. This expects an error code/orig_rax on the stack
   7.151 + * and the exception handler in %rax.	
   7.152 + */ 		  				
   7.153 +ENTRY(error_entry)
   7.154 +#	_frame RDI
   7.155 +	/* rdi slot contains rax, oldrax contains error code */
   7.156 +	cld	
   7.157 +	subq  $14*8,%rsp
   7.158 +#	CFI_ADJUST_CFA_OFFSET	(14*8)
   7.159 +	movq %rsi,13*8(%rsp)
   7.160 +#	CFI_REL_OFFSET	rsi,RSI
   7.161 +	movq 14*8(%rsp),%rsi	/* load rax from rdi slot */
   7.162 +	movq %rdx,12*8(%rsp)
   7.163 +#	CFI_REL_OFFSET	rdx,RDX
   7.164 +	movq %rcx,11*8(%rsp)
   7.165 +#	CFI_REL_OFFSET	rcx,RCX
   7.166 +	movq %rsi,10*8(%rsp)	/* store rax */ 
   7.167 +#	CFI_REL_OFFSET	rax,RAX
   7.168 +	movq %r8, 9*8(%rsp)
   7.169 +#	CFI_REL_OFFSET	r8,R8
   7.170 +	movq %r9, 8*8(%rsp)
   7.171 +#	CFI_REL_OFFSET	r9,R9
   7.172 +	movq %r10,7*8(%rsp)
   7.173 +#	CFI_REL_OFFSET	r10,R10
   7.174 +	movq %r11,6*8(%rsp)
   7.175 +#	CFI_REL_OFFSET	r11,R11
   7.176 +	movq %rbx,5*8(%rsp) 
   7.177 +#	CFI_REL_OFFSET	rbx,RBX
   7.178 +	movq %rbp,4*8(%rsp) 
   7.179 +#	CFI_REL_OFFSET	rbp,RBP
   7.180 +	movq %r12,3*8(%rsp) 
   7.181 +#	CFI_REL_OFFSET	r12,R12
   7.182 +	movq %r13,2*8(%rsp) 
   7.183 +#	CFI_REL_OFFSET	r13,R13
   7.184 +	movq %r14,1*8(%rsp) 
   7.185 +#	CFI_REL_OFFSET	r14,R14
   7.186 +	movq %r15,(%rsp) 
   7.187 +#	CFI_REL_OFFSET	r15,R15
   7.188 +#if 0        
   7.189 +	cmpl $__KERNEL_CS,CS(%rsp)
   7.190 +	je  error_kernelspace
   7.191 +#endif        
   7.192 +error_call_handler:
   7.193 +	movq %rdi, RDI(%rsp)            
   7.194 +	movq %rsp,%rdi
   7.195 +	movq ORIG_RAX(%rsp),%rsi	# get error code 
   7.196 +	movq $-1,ORIG_RAX(%rsp)
   7.197 +	call *%rax
   7.198 +
   7.199 +.macro zeroentry sym
   7.200 +#	INTR_FRAME
   7.201 +    movq (%rsp),%rcx
   7.202 +    movq 8(%rsp),%r11
   7.203 +    addq $0x10,%rsp /* skip rcx and r11 */
   7.204 +	pushq $0	/* push error code/oldrax */ 
   7.205 +#	CFI_ADJUST_CFA_OFFSET 8
   7.206 +	pushq %rax	/* push real oldrax to the rdi slot */ 
   7.207 +#	CFI_ADJUST_CFA_OFFSET 8
   7.208 +	leaq  \sym(%rip),%rax
   7.209 +	jmp error_entry
   7.210 +#	CFI_ENDPROC
   7.211 +.endm	
   7.212 +
   7.213 +.macro errorentry sym
   7.214 +#	XCPT_FRAME
   7.215 +        movq (%rsp),%rcx
   7.216 +        movq 8(%rsp),%r11
   7.217 +        addq $0x10,%rsp /* rsp points to the error code */
   7.218 +	pushq %rax
   7.219 +#	CFI_ADJUST_CFA_OFFSET 8
   7.220 +	leaq  \sym(%rip),%rax
   7.221 +	jmp error_entry
   7.222 +#	CFI_ENDPROC
   7.223 +.endm
   7.224 +
   7.225 +#define XEN_GET_VCPU_INFO(reg)	movq HYPERVISOR_shared_info,reg
   7.226 +#define XEN_PUT_VCPU_INFO(reg)
   7.227 +#define XEN_PUT_VCPU_INFO_fixup
   7.228 +#define XEN_LOCKED_BLOCK_EVENTS(reg)	movb $1,evtchn_upcall_mask(reg)
   7.229 +#define XEN_LOCKED_UNBLOCK_EVENTS(reg)	movb $0,evtchn_upcall_mask(reg)
   7.230 +#define XEN_TEST_PENDING(reg)	testb $0xFF,evtchn_upcall_pending(reg)
   7.231 +
   7.232 +#define XEN_BLOCK_EVENTS(reg)	XEN_GET_VCPU_INFO(reg)			; \
   7.233 +                    			XEN_LOCKED_BLOCK_EVENTS(reg)	; \
   7.234 +    				            XEN_PUT_VCPU_INFO(reg)
   7.235 +
   7.236 +#define XEN_UNBLOCK_EVENTS(reg)	XEN_GET_VCPU_INFO(reg)			; \
   7.237 +                				XEN_LOCKED_UNBLOCK_EVENTS(reg)	; \
   7.238 +    			            	XEN_PUT_VCPU_INFO(reg)
   7.239 +
   7.240 +
   7.241 +
   7.242 +ENTRY(hypervisor_callback)
   7.243 +    zeroentry hypervisor_callback2
   7.244 +
   7.245 +ENTRY(hypervisor_callback2)
   7.246 +        movq %rdi, %rsp 
   7.247 +11:     movq %gs:8,%rax
   7.248 +        incl %gs:0
   7.249 +        cmovzq %rax,%rsp
   7.250 +        pushq %rdi
   7.251 +        call do_hypervisor_callback 
   7.252 +        popq %rsp
   7.253 +        decl %gs:0
   7.254 +        jmp error_exit
   7.255 +
   7.256 +#        ALIGN
   7.257 +restore_all_enable_events:  
   7.258 +	XEN_UNBLOCK_EVENTS(%rsi)        # %rsi is already set up...
   7.259 +
   7.260 +scrit:	/**** START OF CRITICAL REGION ****/
   7.261 +	XEN_TEST_PENDING(%rsi)
   7.262 +	jnz  14f			# process more events if necessary...
   7.263 +	XEN_PUT_VCPU_INFO(%rsi)
   7.264 +        RESTORE_ARGS 0,8,0
   7.265 +        HYPERVISOR_IRET 0
   7.266 +        
   7.267 +14:	XEN_LOCKED_BLOCK_EVENTS(%rsi)
   7.268 +	XEN_PUT_VCPU_INFO(%rsi)
   7.269 +	SAVE_REST
   7.270 +        movq %rsp,%rdi                  # set the argument again
   7.271 +	jmp  11b
   7.272 +ecrit:  /**** END OF CRITICAL REGION ****/
   7.273 +
   7.274 +
   7.275 +retint_kernel:
   7.276 +retint_restore_args:
   7.277 +	movl EFLAGS-REST_SKIP(%rsp), %eax
   7.278 +	shr $9, %eax			# EAX[0] == IRET_EFLAGS.IF
   7.279 +	XEN_GET_VCPU_INFO(%rsi)
   7.280 +	andb evtchn_upcall_mask(%rsi),%al
   7.281 +	andb $1,%al			# EAX[0] == IRET_EFLAGS.IF & event_mask
   7.282 +	jnz restore_all_enable_events	#        != 0 => enable event delivery
   7.283 +	XEN_PUT_VCPU_INFO(%rsi)
   7.284 +		
   7.285 +	RESTORE_ARGS 0,8,0
   7.286 +	HYPERVISOR_IRET 0
   7.287 +
   7.288 +
   7.289 +error_exit:		
   7.290 +	RESTORE_REST
   7.291 +/*	cli */
   7.292 +	XEN_BLOCK_EVENTS(%rsi)		
   7.293 +	jmp retint_kernel
   7.294 +
   7.295 +
   7.296 +
   7.297 +ENTRY(failsafe_callback)
   7.298 +        popq  %rcx
   7.299 +        popq  %r11
   7.300 +        iretq
   7.301 +
   7.302 +
   7.303 +ENTRY(coprocessor_error)
   7.304 +        zeroentry do_coprocessor_error
   7.305 +
   7.306 +
   7.307 +ENTRY(simd_coprocessor_error)
   7.308 +        zeroentry do_simd_coprocessor_error
   7.309 +
   7.310 +
   7.311 +ENTRY(device_not_available)
   7.312 +        zeroentry do_device_not_available
   7.313 +
   7.314 +
   7.315 +ENTRY(debug)
   7.316 +#       INTR_FRAME
   7.317 +#       CFI_ADJUST_CFA_OFFSET 8 */
   7.318 +        zeroentry do_debug
   7.319 +#       CFI_ENDPROC
   7.320 +
   7.321 +
   7.322 +ENTRY(int3)
   7.323 +#       INTR_FRAME
   7.324 +#       CFI_ADJUST_CFA_OFFSET 8 */
   7.325 +        zeroentry do_int3
   7.326 +#       CFI_ENDPROC
   7.327 +
   7.328 +ENTRY(overflow)
   7.329 +        zeroentry do_overflow
   7.330 +
   7.331 +
   7.332 +ENTRY(bounds)
   7.333 +        zeroentry do_bounds
   7.334 +    
   7.335 +    
   7.336 +ENTRY(invalid_op)
   7.337 +        zeroentry do_invalid_op
   7.338 +
   7.339 +
   7.340 +ENTRY(coprocessor_segment_overrun)
   7.341 +        zeroentry do_coprocessor_segment_overrun
   7.342 +
   7.343 +
   7.344 +ENTRY(invalid_TSS)
   7.345 +        errorentry do_invalid_TSS
   7.346 +
   7.347 +
   7.348 +ENTRY(segment_not_present)
   7.349 +        errorentry do_segment_not_present
   7.350 +
   7.351 +
   7.352 +/* runs on exception stack */
   7.353 +ENTRY(stack_segment)
   7.354 +#       XCPT_FRAME
   7.355 +        errorentry do_stack_segment
   7.356 +#       CFI_ENDPROC
   7.357 +                    
   7.358 +
   7.359 +ENTRY(general_protection)
   7.360 +        errorentry do_general_protection
   7.361 +
   7.362 +
   7.363 +ENTRY(alignment_check)
   7.364 +        errorentry do_alignment_check
   7.365 +
   7.366 +
   7.367 +ENTRY(divide_error)
   7.368 +        zeroentry do_divide_error
   7.369 +
   7.370 +
   7.371 +ENTRY(spurious_interrupt_bug)
   7.372 +        zeroentry do_spurious_interrupt_bug
   7.373 +            
   7.374 +
   7.375 +ENTRY(page_fault)
   7.376 +        errorentry do_page_fault
   7.377 +
   7.378 +
   7.379 +
   7.380 +
   7.381 +
   7.382 +ENTRY(thread_starter)
   7.383 +        popq %rdi
   7.384 +        popq %rbx
   7.385 +        call *%rbx
   7.386 +        call exit_thread 
   7.387 +        
   7.388 +
     8.1 --- a/extras/mini-os/minios-x86_32.lds	Wed Jan 17 15:03:27 2007 +0000
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,45 +0,0 @@
     8.4 -OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
     8.5 -OUTPUT_ARCH(i386)
     8.6 -ENTRY(_start)
     8.7 -SECTIONS
     8.8 -{
     8.9 -  . = 0x0;
    8.10 -  _text = .;			/* Text and read-only data */
    8.11 -  .text : {
    8.12 -	*(.text)
    8.13 -	*(.gnu.warning)
    8.14 -	} = 0x9090
    8.15 -
    8.16 -  _etext = .;			/* End of text section */
    8.17 -
    8.18 -  .rodata : { *(.rodata) *(.rodata.*) }
    8.19 -
    8.20 -  .data : {			/* Data */
    8.21 -	*(.data)
    8.22 -	CONSTRUCTORS
    8.23 -	}
    8.24 -
    8.25 -  _edata = .;			/* End of data section */
    8.26 -
    8.27 -  __bss_start = .;		/* BSS */
    8.28 -  .bss : {
    8.29 -	*(.bss)
    8.30 -	}
    8.31 -  _end = . ;
    8.32 -
    8.33 -  /* Sections to be discarded */
    8.34 -  /DISCARD/ : {
    8.35 -	*(.text.exit)
    8.36 -	*(.data.exit)
    8.37 -	*(.exitcall.exit)
    8.38 -	}
    8.39 -
    8.40 -  /* Stabs debugging sections.  */
    8.41 -  .stab 0 : { *(.stab) }
    8.42 -  .stabstr 0 : { *(.stabstr) }
    8.43 -  .stab.excl 0 : { *(.stab.excl) }
    8.44 -  .stab.exclstr 0 : { *(.stab.exclstr) }
    8.45 -  .stab.index 0 : { *(.stab.index) }
    8.46 -  .stab.indexstr 0 : { *(.stab.indexstr) }
    8.47 -  .comment 0 : { *(.comment) }
    8.48 -}
     9.1 --- a/extras/mini-os/minios-x86_64.lds	Wed Jan 17 15:03:27 2007 +0000
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,54 +0,0 @@
     9.4 -OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64", "elf64-x86-64")
     9.5 -OUTPUT_ARCH(i386:x86-64)
     9.6 -ENTRY(_start)
     9.7 -SECTIONS
     9.8 -{
     9.9 -  . = 0x0;
    9.10 -  _text = .;			/* Text and read-only data */
    9.11 -  .text : {
    9.12 -	*(.text)
    9.13 -	*(.gnu.warning)
    9.14 -	} = 0x9090
    9.15 -
    9.16 -  _etext = .;			/* End of text section */
    9.17 -
    9.18 -  .rodata : { *(.rodata) *(.rodata.*) }
    9.19 -
    9.20 -  .data : {			/* Data */
    9.21 -	*(.data)
    9.22 -	CONSTRUCTORS
    9.23 -	}
    9.24 -
    9.25 -  _edata = .;			/* End of data section */
    9.26 -
    9.27 -  . = ALIGN(8192);		/* init_task */
    9.28 -  .data.init_task : { *(.data.init_task) }
    9.29 -
    9.30 -  . = ALIGN(4096);
    9.31 -  .data.page_aligned : { *(.data.idt) }
    9.32 -
    9.33 -  . = ALIGN(32);
    9.34 -  .data.cacheline_aligned : { *(.data.cacheline_aligned) }
    9.35 -
    9.36 -  __bss_start = .;		/* BSS */
    9.37 -  .bss : {
    9.38 -	*(.bss)
    9.39 -	}
    9.40 -  _end = . ;
    9.41 -
    9.42 -  /* Sections to be discarded */
    9.43 -  /DISCARD/ : {
    9.44 -	*(.text.exit)
    9.45 -	*(.data.exit)
    9.46 -	*(.exitcall.exit)
    9.47 -	}
    9.48 -
    9.49 -  /* Stabs debugging sections.  */
    9.50 -  .stab 0 : { *(.stab) }
    9.51 -  .stabstr 0 : { *(.stabstr) }
    9.52 -  .stab.excl 0 : { *(.stab.excl) }
    9.53 -  .stab.exclstr 0 : { *(.stab.exclstr) }
    9.54 -  .stab.index 0 : { *(.stab.index) }
    9.55 -  .stab.indexstr 0 : { *(.stab.indexstr) }
    9.56 -  .comment 0 : { *(.comment) }
    9.57 -}
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/extras/mini-os/minios.mk	Wed Jan 17 15:09:50 2007 +0000
    10.3 @@ -0,0 +1,62 @@
    10.4 +#
    10.5 +# The file contains the common make rules for building mini-os.
    10.6 +#
    10.7 +
    10.8 +debug = y
    10.9 +
   10.10 +# Define some default flags.
   10.11 +# NB. '-Wcast-qual' is nasty, so I omitted it.
   10.12 +DEF_CFLAGS := -fno-builtin -Wall -Werror -Wredundant-decls -Wno-format
   10.13 +DEF_CFLAGS += -Wstrict-prototypes -Wnested-externs -Wpointer-arith -Winline
   10.14 +DEF_CFLAGS += -D__XEN_INTERFACE_VERSION__=$(XEN_INTERFACE_VERSION)
   10.15 +
   10.16 +DEF_ASFLAGS = -D__ASSEMBLY__
   10.17 +
   10.18 +ifeq ($(debug),y)
   10.19 +DEF_CFLAGS += -g
   10.20 +else
   10.21 +DEF_CFLAGS += -O3
   10.22 +endif
   10.23 +
   10.24 +# Build the CFLAGS and ASFLAGS for compiling and assembling.
   10.25 +# DEF_... flags are the common mini-os flags,
   10.26 +# ARCH_... flags may be defined in arch/$(TARGET_ARCH_FAM/rules.mk
   10.27 +CFLAGS := $(DEF_CFLAGS) $(ARCH_CFLAGS)
   10.28 +ASFLAGS := $(DEF_ASFLAGS) $(ARCH_ASFLAGS)
   10.29 +
   10.30 +# The path pointing to the architecture specific header files.
   10.31 +ARCH_SPEC_INC := $(MINI-OS_ROOT)/include/$(TARGET_ARCH_FAM)
   10.32 +
   10.33 +# Find all header files for checking dependencies.
   10.34 +HDRS := $(wildcard $(MINI-OS_ROOT)/include/*.h)
   10.35 +HDRS += $(wildcard $(MINI-OS_ROOT)/include/xen/*.h)
   10.36 +HDRS += $(wildcard $(ARCH_SPEC_INC)/*.h)
   10.37 +# For special wanted header directories.
   10.38 +extra_heads := $(foreach dir,$(EXTRA_INC),$(wildcard $(dir)/*.h))
   10.39 +HDRS += $(extra_heads)
   10.40 +
   10.41 +# Add the special header directories to the include paths.
   10.42 +extra_incl := $(foreach dir,$(EXTRA_INC),-I$(MINI-OS_ROOT)/include/$(dir))
   10.43 +override CPPFLAGS := -I$(MINI-OS_ROOT)/include $(CPPFLAGS) -I$(ARCH_SPEC_INC)	$(extra_incl)
   10.44 +
   10.45 +# The name of the architecture specific library.
   10.46 +# This is on x86_32: libx86_32.a
   10.47 +# $(ARCH_LIB) has to built in the architecture specific directory.
   10.48 +ARCH_LIB_NAME = $(TARGET_ARCH)
   10.49 +ARCH_LIB := lib$(ARCH_LIB_NAME).a
   10.50 +
   10.51 +# This object contains the entrypoint for startup from Xen.
   10.52 +# $(HEAD_ARCH_OBJ) has to be built in the architecture specific directory.
   10.53 +HEAD_ARCH_OBJ := $(TARGET_ARCH).o
   10.54 +HEAD_OBJ := $(TARGET_ARCH_DIR)/$(HEAD_ARCH_OBJ)
   10.55 +
   10.56 +
   10.57 +%.o: %.c $(HDRS) Makefile $(SPEC_DEPENDS)
   10.58 +	$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
   10.59 +
   10.60 +%.o: %.S $(HDRS) Makefile $(SPEC_DEPENDS)
   10.61 +	$(CC) $(ASFLAGS) $(CPPFLAGS) -c $< -o $@
   10.62 +
   10.63 +
   10.64 +
   10.65 +
    11.1 --- a/extras/mini-os/x86_32.S	Wed Jan 17 15:03:27 2007 +0000
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,287 +0,0 @@
    11.4 -#include <os.h>
    11.5 -#include <xen/arch-x86_32.h>
    11.6 -
    11.7 -.section __xen_guest
    11.8 -	.ascii	"GUEST_OS=Mini-OS"
    11.9 -	.ascii	",XEN_VER=xen-3.0"
   11.10 -	.ascii	",VIRT_BASE=0x0" /* &_text from minios_x86_32.lds */
   11.11 -	.ascii	",ELF_PADDR_OFFSET=0x0"
   11.12 -	.ascii	",HYPERCALL_PAGE=0x2"
   11.13 -#ifdef CONFIG_X86_PAE
   11.14 -	.ascii	",PAE=yes"
   11.15 -#else
   11.16 -	.ascii	",PAE=no"
   11.17 -#endif
   11.18 -	.ascii	",LOADER=generic"
   11.19 -	.byte	0
   11.20 -.text
   11.21 -
   11.22 -.globl _start, shared_info, hypercall_page
   11.23 -                        
   11.24 -_start:
   11.25 -        cld
   11.26 -        lss stack_start,%esp
   11.27 -        push %esi 
   11.28 -        call start_kernel
   11.29 -
   11.30 -stack_start:
   11.31 -	.long stack+8192, __KERNEL_SS
   11.32 -
   11.33 -        /* Unpleasant -- the PTE that maps this page is actually overwritten */
   11.34 -        /* to map the real shared-info page! :-)                             */
   11.35 -        .org 0x1000
   11.36 -shared_info:
   11.37 -        .org 0x2000
   11.38 -
   11.39 -hypercall_page:
   11.40 -        .org 0x3000
   11.41 -
   11.42 -ES		= 0x20
   11.43 -ORIG_EAX	= 0x24
   11.44 -EIP		= 0x28
   11.45 -CS		= 0x2C
   11.46 -
   11.47 -#define ENTRY(X) .globl X ; X :
   11.48 -
   11.49 -#define SAVE_ALL \
   11.50 -	cld; \
   11.51 -	pushl %es; \
   11.52 -	pushl %ds; \
   11.53 -	pushl %eax; \
   11.54 -	pushl %ebp; \
   11.55 -	pushl %edi; \
   11.56 -	pushl %esi; \
   11.57 -	pushl %edx; \
   11.58 -	pushl %ecx; \
   11.59 -	pushl %ebx; \
   11.60 -	movl $(__KERNEL_DS),%edx; \
   11.61 -	movl %edx,%ds; \
   11.62 -	movl %edx,%es;
   11.63 -
   11.64 -#define RESTORE_ALL	\
   11.65 -	popl %ebx;	\
   11.66 -	popl %ecx;	\
   11.67 -	popl %edx;	\
   11.68 -	popl %esi;	\
   11.69 -	popl %edi;	\
   11.70 -	popl %ebp;	\
   11.71 -	popl %eax;	\
   11.72 -	popl %ds;	\
   11.73 -	popl %es;	\
   11.74 -	addl $4,%esp;	\
   11.75 -	iret;		\
   11.76 -
   11.77 -ENTRY(divide_error)
   11.78 -	pushl $0		# no error code
   11.79 -	pushl $do_divide_error
   11.80 -do_exception:
   11.81 -    pushl %ds
   11.82 -	pushl %eax
   11.83 -	xorl %eax, %eax
   11.84 -	pushl %ebp
   11.85 -	pushl %edi
   11.86 -	pushl %esi
   11.87 -	pushl %edx
   11.88 -	decl %eax			# eax = -1
   11.89 -	pushl %ecx
   11.90 -	pushl %ebx
   11.91 -	cld
   11.92 -	movl %es, %ecx
   11.93 -	movl ES(%esp), %edi		# get the function address
   11.94 -	movl ORIG_EAX(%esp), %edx	# get the error code
   11.95 -	movl %eax, ORIG_EAX(%esp)
   11.96 -	movl %ecx, ES(%esp)
   11.97 -	movl $(__KERNEL_DS), %ecx
   11.98 -	movl %ecx, %ds
   11.99 -	movl %ecx, %es
  11.100 -	movl %esp,%eax			# pt_regs pointer
  11.101 -    pushl %edx
  11.102 -    pushl %eax
  11.103 -	call *%edi
  11.104 -    jmp ret_from_exception
  11.105 -    
  11.106 -ret_from_exception:
  11.107 -        movb CS(%esp),%cl
  11.108 -	test $2,%cl          # slow return to ring 2 or 3
  11.109 -	jne  safesti
  11.110 -        RESTORE_ALL
  11.111 -
  11.112 -# A note on the "critical region" in our callback handler.
  11.113 -# We want to avoid stacking callback handlers due to events occurring
  11.114 -# during handling of the last event. To do this, we keep events disabled
  11.115 -# until weve done all processing. HOWEVER, we must enable events before
  11.116 -# popping the stack frame (cant be done atomically) and so it would still
  11.117 -# be possible to get enough handler activations to overflow the stack.
  11.118 -# Although unlikely, bugs of that kind are hard to track down, so wed
  11.119 -# like to avoid the possibility.
  11.120 -# So, on entry to the handler we detect whether we interrupted an
  11.121 -# existing activation in its critical region -- if so, we pop the current
  11.122 -# activation and restart the handler using the previous one.
  11.123 -ENTRY(hypervisor_callback)
  11.124 -        pushl %eax
  11.125 -        SAVE_ALL
  11.126 -        movl EIP(%esp),%eax
  11.127 -        cmpl $scrit,%eax
  11.128 -        jb   11f
  11.129 -        cmpl $ecrit,%eax
  11.130 -        jb   critical_region_fixup
  11.131 -11:     push %esp
  11.132 -        call do_hypervisor_callback
  11.133 -        add  $4,%esp
  11.134 -        movl HYPERVISOR_shared_info,%esi
  11.135 -        xorl %eax,%eax
  11.136 -        movb CS(%esp),%cl
  11.137 -    	test $2,%cl          # slow return to ring 2 or 3
  11.138 -        jne  safesti
  11.139 -safesti:movb $0,1(%esi)     # reenable event callbacks
  11.140 -scrit:  /**** START OF CRITICAL REGION ****/
  11.141 -        testb $0xFF,(%esi)
  11.142 -        jnz  14f              # process more events if necessary...
  11.143 -        RESTORE_ALL
  11.144 -14:     movb $1,1(%esi)
  11.145 -        jmp  11b
  11.146 -ecrit:  /**** END OF CRITICAL REGION ****/
  11.147 -# [How we do the fixup]. We want to merge the current stack frame with the
  11.148 -# just-interrupted frame. How we do this depends on where in the critical
  11.149 -# region the interrupted handler was executing, and so how many saved
  11.150 -# registers are in each frame. We do this quickly using the lookup table
  11.151 -# 'critical_fixup_table'. For each byte offset in the critical region, it
  11.152 -# provides the number of bytes which have already been popped from the
  11.153 -# interrupted stack frame. 
  11.154 -critical_region_fixup:
  11.155 -        addl $critical_fixup_table-scrit,%eax
  11.156 -        movzbl (%eax),%eax    # %eax contains num bytes popped
  11.157 -        mov  %esp,%esi
  11.158 -        add  %eax,%esi        # %esi points at end of src region
  11.159 -        mov  %esp,%edi
  11.160 -        add  $0x34,%edi       # %edi points at end of dst region
  11.161 -        mov  %eax,%ecx
  11.162 -        shr  $2,%ecx          # convert words to bytes
  11.163 -        je   16f              # skip loop if nothing to copy
  11.164 -15:     subl $4,%esi          # pre-decrementing copy loop
  11.165 -        subl $4,%edi
  11.166 -        movl (%esi),%eax
  11.167 -        movl %eax,(%edi)
  11.168 -        loop 15b
  11.169 -16:     movl %edi,%esp        # final %edi is top of merged stack
  11.170 -        jmp  11b
  11.171 -         
  11.172 -critical_fixup_table:        
  11.173 -        .byte 0x00,0x00,0x00                  # testb $0xff,(%esi)
  11.174 -        .byte 0x00,0x00                       # jne  14f
  11.175 -        .byte 0x00                            # pop  %ebx
  11.176 -        .byte 0x04                            # pop  %ecx
  11.177 -        .byte 0x08                            # pop  %edx
  11.178 -        .byte 0x0c                            # pop  %esi
  11.179 -        .byte 0x10                            # pop  %edi
  11.180 -        .byte 0x14                            # pop  %ebp
  11.181 -        .byte 0x18                            # pop  %eax
  11.182 -        .byte 0x1c                            # pop  %ds
  11.183 -        .byte 0x20                            # pop  %es
  11.184 -        .byte 0x24,0x24,0x24                  # add  $4,%esp
  11.185 -        .byte 0x28                            # iret
  11.186 -        .byte 0x00,0x00,0x00,0x00             # movb $1,1(%esi)
  11.187 -        .byte 0x00,0x00                       # jmp  11b
  11.188 -       
  11.189 -# Hypervisor uses this for application faults while it executes.
  11.190 -ENTRY(failsafe_callback)
  11.191 -      pop  %ds
  11.192 -      pop  %es
  11.193 -      pop  %fs
  11.194 -      pop  %gs
  11.195 -      iret
  11.196 -                
  11.197 -ENTRY(coprocessor_error)
  11.198 -	pushl $0
  11.199 -	pushl $do_coprocessor_error
  11.200 -	jmp do_exception
  11.201 -
  11.202 -ENTRY(simd_coprocessor_error)
  11.203 -	pushl $0
  11.204 -	pushl $do_simd_coprocessor_error
  11.205 -	jmp do_exception
  11.206 -
  11.207 -ENTRY(device_not_available)
  11.208 -        iret
  11.209 -
  11.210 -ENTRY(debug)
  11.211 -	pushl $0
  11.212 -	pushl $do_debug
  11.213 -	jmp do_exception
  11.214 -
  11.215 -ENTRY(int3)
  11.216 -	pushl $0
  11.217 -	pushl $do_int3
  11.218 -	jmp do_exception
  11.219 -
  11.220 -ENTRY(overflow)
  11.221 -	pushl $0
  11.222 -	pushl $do_overflow
  11.223 -	jmp do_exception
  11.224 -
  11.225 -ENTRY(bounds)
  11.226 -	pushl $0
  11.227 -	pushl $do_bounds
  11.228 -	jmp do_exception
  11.229 -
  11.230 -ENTRY(invalid_op)
  11.231 -	pushl $0
  11.232 -	pushl $do_invalid_op
  11.233 -	jmp do_exception
  11.234 -
  11.235 -
  11.236 -ENTRY(coprocessor_segment_overrun)
  11.237 -	pushl $0
  11.238 -	pushl $do_coprocessor_segment_overrun
  11.239 -	jmp do_exception
  11.240 -
  11.241 -
  11.242 -ENTRY(invalid_TSS)
  11.243 -	pushl $do_invalid_TSS
  11.244 -	jmp do_exception
  11.245 -
  11.246 -
  11.247 -ENTRY(segment_not_present)
  11.248 -	pushl $do_segment_not_present
  11.249 -	jmp do_exception
  11.250 -
  11.251 -
  11.252 -ENTRY(stack_segment)
  11.253 -	pushl $do_stack_segment
  11.254 -	jmp do_exception
  11.255 -
  11.256 -
  11.257 -ENTRY(general_protection)
  11.258 -	pushl $do_general_protection
  11.259 -	jmp do_exception
  11.260 -
  11.261 -
  11.262 -ENTRY(alignment_check)
  11.263 -	pushl $do_alignment_check
  11.264 -	jmp do_exception
  11.265 -
  11.266 -
  11.267 -ENTRY(page_fault)
  11.268 -    pushl $do_page_fault
  11.269 -    jmp do_exception
  11.270 -    
  11.271 -ENTRY(machine_check)
  11.272 -	pushl $0
  11.273 -	pushl $do_machine_check
  11.274 -	jmp do_exception
  11.275 -
  11.276 -
  11.277 -ENTRY(spurious_interrupt_bug)
  11.278 -	pushl $0
  11.279 -	pushl $do_spurious_interrupt_bug
  11.280 -	jmp do_exception
  11.281 -
  11.282 -
  11.283 -
  11.284 -ENTRY(thread_starter)
  11.285 -    popl %eax
  11.286 -    popl %ebx
  11.287 -    pushl %eax
  11.288 -    call *%ebx
  11.289 -    call exit_thread 
  11.290 -    
    12.1 --- a/extras/mini-os/x86_64.S	Wed Jan 17 15:03:27 2007 +0000
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,385 +0,0 @@
    12.4 -#include <os.h>
    12.5 -#include <xen/features.h>
    12.6 -
    12.7 -.section __xen_guest
    12.8 -	.ascii	"GUEST_OS=Mini-OS"
    12.9 -	.ascii	",XEN_VER=xen-3.0"
   12.10 -	.ascii	",VIRT_BASE=0x0" /* &_text from minios_x86_64.lds */
   12.11 -	.ascii	",ELF_PADDR_OFFSET=0x0"
   12.12 -	.ascii	",HYPERCALL_PAGE=0x2"
   12.13 -	.ascii	",LOADER=generic"
   12.14 -	.byte	0
   12.15 -.text
   12.16 -
   12.17 -#define ENTRY(X) .globl X ; X :
   12.18 -.globl _start, shared_info, hypercall_page
   12.19 -
   12.20 -
   12.21 -_start:
   12.22 -        cld
   12.23 -        movq stack_start(%rip),%rsp
   12.24 -        movq %rsi,%rdi
   12.25 -        call start_kernel
   12.26 -
   12.27 -stack_start:
   12.28 -        .quad stack+8192
   12.29 -
   12.30 -        /* Unpleasant -- the PTE that maps this page is actually overwritten */
   12.31 -        /* to map the real shared-info page! :-)                             */
   12.32 -        .org 0x1000
   12.33 -shared_info:
   12.34 -        .org 0x2000
   12.35 -
   12.36 -hypercall_page:
   12.37 -        .org 0x3000
   12.38 -
   12.39 -
   12.40 -/* Offsets into shared_info_t. */                
   12.41 -#define evtchn_upcall_pending		/* 0 */
   12.42 -#define evtchn_upcall_mask		1
   12.43 -
   12.44 -NMI_MASK = 0x80000000
   12.45 -
   12.46 -#define RDI 112
   12.47 -#define ORIG_RAX 120       /* + error_code */ 
   12.48 -#define EFLAGS 144
   12.49 -
   12.50 -#define REST_SKIP 6*8			
   12.51 -.macro SAVE_REST
   12.52 -	subq $REST_SKIP,%rsp
   12.53 -#	CFI_ADJUST_CFA_OFFSET	REST_SKIP
   12.54 -	movq %rbx,5*8(%rsp) 
   12.55 -#	CFI_REL_OFFSET	rbx,5*8
   12.56 -	movq %rbp,4*8(%rsp) 
   12.57 -#	CFI_REL_OFFSET	rbp,4*8
   12.58 -	movq %r12,3*8(%rsp) 
   12.59 -#	CFI_REL_OFFSET	r12,3*8
   12.60 -	movq %r13,2*8(%rsp) 
   12.61 -#	CFI_REL_OFFSET	r13,2*8
   12.62 -	movq %r14,1*8(%rsp) 
   12.63 -#	CFI_REL_OFFSET	r14,1*8
   12.64 -	movq %r15,(%rsp) 
   12.65 -#	CFI_REL_OFFSET	r15,0*8
   12.66 -.endm		
   12.67 -
   12.68 -
   12.69 -.macro RESTORE_REST
   12.70 -	movq (%rsp),%r15
   12.71 -#	CFI_RESTORE r15
   12.72 -	movq 1*8(%rsp),%r14
   12.73 -#	CFI_RESTORE r14
   12.74 -	movq 2*8(%rsp),%r13
   12.75 -#	CFI_RESTORE r13
   12.76 -	movq 3*8(%rsp),%r12
   12.77 -#	CFI_RESTORE r12
   12.78 -	movq 4*8(%rsp),%rbp
   12.79 -#	CFI_RESTORE rbp
   12.80 -	movq 5*8(%rsp),%rbx
   12.81 -#	CFI_RESTORE rbx
   12.82 -	addq $REST_SKIP,%rsp
   12.83 -#	CFI_ADJUST_CFA_OFFSET	-(REST_SKIP)
   12.84 -.endm
   12.85 -
   12.86 -
   12.87 -#define ARG_SKIP 9*8
   12.88 -.macro RESTORE_ARGS skiprax=0,addskip=0,skiprcx=0,skipr11=0,skipr8910=0,skiprdx=0
   12.89 -	.if \skipr11
   12.90 -	.else
   12.91 -	movq (%rsp),%r11
   12.92 -#	CFI_RESTORE r11
   12.93 -	.endif
   12.94 -	.if \skipr8910
   12.95 -	.else
   12.96 -	movq 1*8(%rsp),%r10
   12.97 -#	CFI_RESTORE r10
   12.98 -	movq 2*8(%rsp),%r9
   12.99 -#	CFI_RESTORE r9
  12.100 -	movq 3*8(%rsp),%r8
  12.101 -#	CFI_RESTORE r8
  12.102 -	.endif
  12.103 -	.if \skiprax
  12.104 -	.else
  12.105 -	movq 4*8(%rsp),%rax
  12.106 -#	CFI_RESTORE rax
  12.107 -	.endif
  12.108 -	.if \skiprcx
  12.109 -	.else
  12.110 -	movq 5*8(%rsp),%rcx
  12.111 -#	CFI_RESTORE rcx
  12.112 -	.endif
  12.113 -	.if \skiprdx
  12.114 -	.else
  12.115 -	movq 6*8(%rsp),%rdx
  12.116 -#	CFI_RESTORE rdx
  12.117 -	.endif
  12.118 -	movq 7*8(%rsp),%rsi
  12.119 -#	CFI_RESTORE rsi
  12.120 -	movq 8*8(%rsp),%rdi
  12.121 -#	CFI_RESTORE rdi
  12.122 -	.if ARG_SKIP+\addskip > 0
  12.123 -	addq $ARG_SKIP+\addskip,%rsp
  12.124 -#	CFI_ADJUST_CFA_OFFSET	-(ARG_SKIP+\addskip)
  12.125 -	.endif
  12.126 -.endm	
  12.127 -
  12.128 -
  12.129 -.macro HYPERVISOR_IRET flag
  12.130 -#    testb $3,1*8(%rsp)    /* Don't need to do that in Mini-os, as */
  12.131 -#	jnz   2f               /* there is no userspace? */
  12.132 -	testl $NMI_MASK,2*8(%rsp)
  12.133 -	jnz   2f
  12.134 -
  12.135 -	testb $1,(xen_features+XENFEAT_supervisor_mode_kernel)
  12.136 -	jnz   1f
  12.137 -
  12.138 -	/* Direct iret to kernel space. Correct CS and SS. */
  12.139 -	orb   $3,1*8(%rsp)
  12.140 -	orb   $3,4*8(%rsp)
  12.141 -1:	iretq
  12.142 -
  12.143 -2:	/* Slow iret via hypervisor. */
  12.144 -	andl  $~NMI_MASK, 16(%rsp)
  12.145 -	pushq $\flag
  12.146 -	jmp  hypercall_page + (__HYPERVISOR_iret * 32)
  12.147 -.endm
  12.148 -
  12.149 -/*
  12.150 - * Exception entry point. This expects an error code/orig_rax on the stack
  12.151 - * and the exception handler in %rax.	
  12.152 - */ 		  				
  12.153 -ENTRY(error_entry)
  12.154 -#	_frame RDI
  12.155 -	/* rdi slot contains rax, oldrax contains error code */
  12.156 -	cld	
  12.157 -	subq  $14*8,%rsp
  12.158 -#	CFI_ADJUST_CFA_OFFSET	(14*8)
  12.159 -	movq %rsi,13*8(%rsp)
  12.160 -#	CFI_REL_OFFSET	rsi,RSI
  12.161 -	movq 14*8(%rsp),%rsi	/* load rax from rdi slot */
  12.162 -	movq %rdx,12*8(%rsp)
  12.163 -#	CFI_REL_OFFSET	rdx,RDX
  12.164 -	movq %rcx,11*8(%rsp)
  12.165 -#	CFI_REL_OFFSET	rcx,RCX
  12.166 -	movq %rsi,10*8(%rsp)	/* store rax */ 
  12.167 -#	CFI_REL_OFFSET	rax,RAX
  12.168 -	movq %r8, 9*8(%rsp)
  12.169 -#	CFI_REL_OFFSET	r8,R8
  12.170 -	movq %r9, 8*8(%rsp)
  12.171 -#	CFI_REL_OFFSET	r9,R9
  12.172 -	movq %r10,7*8(%rsp)
  12.173 -#	CFI_REL_OFFSET	r10,R10
  12.174 -	movq %r11,6*8(%rsp)
  12.175 -#	CFI_REL_OFFSET	r11,R11
  12.176 -	movq %rbx,5*8(%rsp) 
  12.177 -#	CFI_REL_OFFSET	rbx,RBX
  12.178 -	movq %rbp,4*8(%rsp) 
  12.179 -#	CFI_REL_OFFSET	rbp,RBP
  12.180 -	movq %r12,3*8(%rsp) 
  12.181 -#	CFI_REL_OFFSET	r12,R12
  12.182 -	movq %r13,2*8(%rsp) 
  12.183 -#	CFI_REL_OFFSET	r13,R13
  12.184 -	movq %r14,1*8(%rsp) 
  12.185 -#	CFI_REL_OFFSET	r14,R14
  12.186 -	movq %r15,(%rsp) 
  12.187 -#	CFI_REL_OFFSET	r15,R15
  12.188 -#if 0        
  12.189 -	cmpl $__KERNEL_CS,CS(%rsp)
  12.190 -	je  error_kernelspace
  12.191 -#endif        
  12.192 -error_call_handler:
  12.193 -	movq %rdi, RDI(%rsp)            
  12.194 -	movq %rsp,%rdi
  12.195 -	movq ORIG_RAX(%rsp),%rsi	# get error code 
  12.196 -	movq $-1,ORIG_RAX(%rsp)
  12.197 -	call *%rax
  12.198 -
  12.199 -.macro zeroentry sym
  12.200 -#	INTR_FRAME
  12.201 -    movq (%rsp),%rcx
  12.202 -    movq 8(%rsp),%r11
  12.203 -    addq $0x10,%rsp /* skip rcx and r11 */
  12.204 -	pushq $0	/* push error code/oldrax */ 
  12.205 -#	CFI_ADJUST_CFA_OFFSET 8
  12.206 -	pushq %rax	/* push real oldrax to the rdi slot */ 
  12.207 -#	CFI_ADJUST_CFA_OFFSET 8
  12.208 -	leaq  \sym(%rip),%rax
  12.209 -	jmp error_entry
  12.210 -#	CFI_ENDPROC
  12.211 -.endm	
  12.212 -
  12.213 -.macro errorentry sym
  12.214 -#	XCPT_FRAME
  12.215 -        movq (%rsp),%rcx
  12.216 -        movq 8(%rsp),%r11
  12.217 -        addq $0x10,%rsp /* rsp points to the error code */
  12.218 -	pushq %rax
  12.219 -#	CFI_ADJUST_CFA_OFFSET 8
  12.220 -	leaq  \sym(%rip),%rax
  12.221 -	jmp error_entry
  12.222 -#	CFI_ENDPROC
  12.223 -.endm
  12.224 -
  12.225 -#define XEN_GET_VCPU_INFO(reg)	movq HYPERVISOR_shared_info,reg
  12.226 -#define XEN_PUT_VCPU_INFO(reg)
  12.227 -#define XEN_PUT_VCPU_INFO_fixup
  12.228 -#define XEN_LOCKED_BLOCK_EVENTS(reg)	movb $1,evtchn_upcall_mask(reg)
  12.229 -#define XEN_LOCKED_UNBLOCK_EVENTS(reg)	movb $0,evtchn_upcall_mask(reg)
  12.230 -#define XEN_TEST_PENDING(reg)	testb $0xFF,evtchn_upcall_pending(reg)
  12.231 -
  12.232 -#define XEN_BLOCK_EVENTS(reg)	XEN_GET_VCPU_INFO(reg)			; \
  12.233 -                    			XEN_LOCKED_BLOCK_EVENTS(reg)	; \
  12.234 -    				            XEN_PUT_VCPU_INFO(reg)
  12.235 -
  12.236 -#define XEN_UNBLOCK_EVENTS(reg)	XEN_GET_VCPU_INFO(reg)			; \
  12.237 -                				XEN_LOCKED_UNBLOCK_EVENTS(reg)	; \
  12.238 -    			            	XEN_PUT_VCPU_INFO(reg)
  12.239 -
  12.240 -
  12.241 -
  12.242 -ENTRY(hypervisor_callback)
  12.243 -    zeroentry hypervisor_callback2
  12.244 -
  12.245 -ENTRY(hypervisor_callback2)
  12.246 -        movq %rdi, %rsp 
  12.247 -11:     movq %gs:8,%rax
  12.248 -        incl %gs:0
  12.249 -        cmovzq %rax,%rsp
  12.250 -        pushq %rdi
  12.251 -        call do_hypervisor_callback 
  12.252 -        popq %rsp
  12.253 -        decl %gs:0
  12.254 -        jmp error_exit
  12.255 -
  12.256 -#        ALIGN
  12.257 -restore_all_enable_events:  
  12.258 -	XEN_UNBLOCK_EVENTS(%rsi)        # %rsi is already set up...
  12.259 -
  12.260 -scrit:	/**** START OF CRITICAL REGION ****/
  12.261 -	XEN_TEST_PENDING(%rsi)
  12.262 -	jnz  14f			# process more events if necessary...
  12.263 -	XEN_PUT_VCPU_INFO(%rsi)
  12.264 -        RESTORE_ARGS 0,8,0
  12.265 -        HYPERVISOR_IRET 0
  12.266 -        
  12.267 -14:	XEN_LOCKED_BLOCK_EVENTS(%rsi)
  12.268 -	XEN_PUT_VCPU_INFO(%rsi)
  12.269 -	SAVE_REST
  12.270 -        movq %rsp,%rdi                  # set the argument again
  12.271 -	jmp  11b
  12.272 -ecrit:  /**** END OF CRITICAL REGION ****/
  12.273 -
  12.274 -
  12.275 -retint_kernel:
  12.276 -retint_restore_args:
  12.277 -	movl EFLAGS-REST_SKIP(%rsp), %eax
  12.278 -	shr $9, %eax			# EAX[0] == IRET_EFLAGS.IF
  12.279 -	XEN_GET_VCPU_INFO(%rsi)
  12.280 -	andb evtchn_upcall_mask(%rsi),%al
  12.281 -	andb $1,%al			# EAX[0] == IRET_EFLAGS.IF & event_mask
  12.282 -	jnz restore_all_enable_events	#        != 0 => enable event delivery
  12.283 -	XEN_PUT_VCPU_INFO(%rsi)
  12.284 -		
  12.285 -	RESTORE_ARGS 0,8,0
  12.286 -	HYPERVISOR_IRET 0
  12.287 -
  12.288 -
  12.289 -error_exit:		
  12.290 -	RESTORE_REST
  12.291 -/*	cli */
  12.292 -	XEN_BLOCK_EVENTS(%rsi)		
  12.293 -	jmp retint_kernel
  12.294 -
  12.295 -
  12.296 -
  12.297 -ENTRY(failsafe_callback)
  12.298 -        popq  %rcx
  12.299 -        popq  %r11
  12.300 -        iretq
  12.301 -
  12.302 -
  12.303 -ENTRY(coprocessor_error)
  12.304 -        zeroentry do_coprocessor_error
  12.305 -
  12.306 -
  12.307 -ENTRY(simd_coprocessor_error)
  12.308 -        zeroentry do_simd_coprocessor_error
  12.309 -
  12.310 -
  12.311 -ENTRY(device_not_available)
  12.312 -        zeroentry do_device_not_available
  12.313 -
  12.314 -
  12.315 -ENTRY(debug)
  12.316 -#       INTR_FRAME
  12.317 -#       CFI_ADJUST_CFA_OFFSET 8 */
  12.318 -        zeroentry do_debug
  12.319 -#       CFI_ENDPROC
  12.320 -
  12.321 -
  12.322 -ENTRY(int3)
  12.323 -#       INTR_FRAME
  12.324 -#       CFI_ADJUST_CFA_OFFSET 8 */
  12.325 -        zeroentry do_int3
  12.326 -#       CFI_ENDPROC
  12.327 -
  12.328 -ENTRY(overflow)
  12.329 -        zeroentry do_overflow
  12.330 -
  12.331 -
  12.332 -ENTRY(bounds)
  12.333 -        zeroentry do_bounds
  12.334 -    
  12.335 -    
  12.336 -ENTRY(invalid_op)
  12.337 -        zeroentry do_invalid_op
  12.338 -
  12.339 -
  12.340 -ENTRY(coprocessor_segment_overrun)
  12.341 -        zeroentry do_coprocessor_segment_overrun
  12.342 -
  12.343 -
  12.344 -ENTRY(invalid_TSS)
  12.345 -        errorentry do_invalid_TSS
  12.346 -
  12.347 -
  12.348 -ENTRY(segment_not_present)
  12.349 -        errorentry do_segment_not_present
  12.350 -
  12.351 -
  12.352 -/* runs on exception stack */
  12.353 -ENTRY(stack_segment)
  12.354 -#       XCPT_FRAME
  12.355 -        errorentry do_stack_segment
  12.356 -#       CFI_ENDPROC
  12.357 -                    
  12.358 -
  12.359 -ENTRY(general_protection)
  12.360 -        errorentry do_general_protection
  12.361 -
  12.362 -
  12.363 -ENTRY(alignment_check)
  12.364 -        errorentry do_alignment_check
  12.365 -
  12.366 -
  12.367 -ENTRY(divide_error)
  12.368 -        zeroentry do_divide_error
  12.369 -
  12.370 -
  12.371 -ENTRY(spurious_interrupt_bug)
  12.372 -        zeroentry do_spurious_interrupt_bug
  12.373 -            
  12.374 -
  12.375 -ENTRY(page_fault)
  12.376 -        errorentry do_page_fault
  12.377 -
  12.378 -
  12.379 -
  12.380 -
  12.381 -
  12.382 -ENTRY(thread_starter)
  12.383 -        popq %rdi
  12.384 -        popq %rbx
  12.385 -        call *%rbx
  12.386 -        call exit_thread 
  12.387 -        
  12.388 -