ia64/xen-unstable

changeset 5675:189c87adf876

Mini-os updates from Grzegorz Milos.
author kaf24@firebug.cl.cam.ac.uk
date Wed Jul 06 10:46:29 2005 +0000 (2005-07-06)
parents 287583627544
children 9a7d86b8147d 5ead5ffa04c2
files extras/mini-os/Makefile extras/mini-os/events.c extras/mini-os/hypervisor.c extras/mini-os/include/events.h extras/mini-os/include/hypervisor.h extras/mini-os/include/lib.h extras/mini-os/include/mm.h extras/mini-os/include/os.h extras/mini-os/include/time.h extras/mini-os/include/traps.h extras/mini-os/include/types.h extras/mini-os/kernel.c extras/mini-os/time.c extras/mini-os/traps.c extras/mini-os/x86_32.S
line diff
     1.1 --- a/extras/mini-os/Makefile	Wed Jul 06 08:50:11 2005 +0000
     1.2 +++ b/extras/mini-os/Makefile	Wed Jul 06 10:46:29 2005 +0000
     1.3 @@ -1,11 +1,12 @@
     1.4 +debug ?= y
     1.5  
     1.6 -CC := gcc
     1.7 -LD := ld
     1.8 +include $(CURDIR)/../../Config.mk
     1.9  
    1.10 -TARGET_ARCH := $(shell uname -m | sed -e s/i.86/x86_32/)
    1.11 +# Set TARGET_ARCH
    1.12 +override TARGET_ARCH     := $(XEN_TARGET_ARCH)
    1.13  
    1.14  # NB. '-Wcast-qual' is nasty, so I omitted it.
    1.15 -CFLAGS := -fno-builtin -O3 -Wall -Ih/ -Wredundant-decls -Wno-format
    1.16 +CFLAGS := -fno-builtin -Wall -Werror -Iinclude/ -Wredundant-decls -Wno-format
    1.17  CFLAGS += -Wstrict-prototypes -Wnested-externs -Wpointer-arith -Winline
    1.18  
    1.19  ifeq ($(TARGET_ARCH),x86_32)
    1.20 @@ -19,23 +20,25 @@ CFLAGS += -fno-asynchronous-unwind-table
    1.21  LDFLAGS := -m elf_x86_64
    1.22  endif
    1.23  
    1.24 +ifeq ($(debug),y)
    1.25 +CFLAGS += -g
    1.26 +else
    1.27 +CFLAGS += -O3
    1.28 +endif
    1.29 +
    1.30  TARGET := mini-os
    1.31  
    1.32  OBJS := $(TARGET_ARCH).o
    1.33  OBJS += $(patsubst %.c,%.o,$(wildcard *.c))
    1.34  OBJS += $(patsubst %.c,%.o,$(wildcard lib/*.c))
    1.35  
    1.36 -OBJS := $(subst events.o,,$(OBJS))
    1.37 -OBJS := $(subst hypervisor.o,,$(OBJS))
    1.38 -OBJS := $(subst time.o,,$(OBJS))
    1.39 -
    1.40 -HDRS := $(wildcard h/*.h)
    1.41 -HDRS += $(wildcard h/xen-public/*.h)
    1.42 +HDRS := $(wildcard include/*.h)
    1.43 +HDRS += $(wildcard include/xen/*.h)
    1.44  
    1.45  default: $(TARGET)
    1.46  
    1.47  xen-public:
    1.48 -	[ -e h/xen-public ] || ln -sf ../../../xen/include/public h/xen-public
    1.49 +	[ -e include/xen ] || ln -sf ../../../xen/include/public include/xen
    1.50  
    1.51  $(TARGET): xen-public $(OBJS)
    1.52  	$(LD) -N -T minios-$(TARGET_ARCH).lds $(OBJS) -o $@.elf
    1.53 @@ -51,3 +54,4 @@ clean:
    1.54  
    1.55  %.o: %.S $(HDRS) Makefile
    1.56  	$(CC) $(CFLAGS) -D__ASSEMBLY__ -c $< -o $@
    1.57 +
     2.1 --- a/extras/mini-os/events.c	Wed Jul 06 08:50:11 2005 +0000
     2.2 +++ b/extras/mini-os/events.c	Wed Jul 06 10:46:29 2005 +0000
     2.3 @@ -1,20 +1,19 @@
     2.4  /* -*-  Mode:C; c-basic-offset:4; tab-width:4 -*-
     2.5   ****************************************************************************
     2.6   * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge
     2.7 + * (C) 2005 - Grzegorz Milos - Intel Research Cambridge
     2.8   ****************************************************************************
     2.9   *
    2.10   *        File: events.c
    2.11   *      Author: Rolf Neugebauer (neugebar@dcs.gla.ac.uk)
    2.12 - *     Changes: 
    2.13 + *     Changes: Grzegorz Milos (gm281@cam.ac.uk)
    2.14   *              
    2.15 - *        Date: Jul 2003
    2.16 + *        Date: Jul 2003, changes Jun 2005
    2.17   * 
    2.18   * Environment: Xen Minimal OS
    2.19 - * Description: Deal with events
    2.20 + * Description: Deals with events recieved on event channels
    2.21   *
    2.22   ****************************************************************************
    2.23 - * $Id: c-insert.c,v 1.7 2002/11/08 16:04:34 rn Exp $
    2.24 - ****************************************************************************
    2.25   */
    2.26  
    2.27  #include <os.h>
    2.28 @@ -22,25 +21,25 @@
    2.29  #include <events.h>
    2.30  #include <lib.h>
    2.31  
    2.32 +#include <xen/event_channel.h>
    2.33  static ev_action_t ev_actions[NR_EVS];
    2.34 -void default_handler(int ev, struct pt_regs *regs);
    2.35 +void default_handler(u32 port, struct pt_regs *regs);
    2.36  
    2.37  
    2.38  /*
    2.39 - * demux events to different handlers
    2.40 + * Demux events to different handlers.
    2.41   */
    2.42 -unsigned int do_event(int ev, struct pt_regs *regs)
    2.43 +int do_event(u32 port, struct pt_regs *regs)
    2.44  {
    2.45      ev_action_t  *action;
    2.46  
    2.47 -    if (ev >= NR_EVS) {
    2.48 -        printk("Large event number %d\n", ev);
    2.49 +    if (port >= NR_EVS) {
    2.50 +        printk("Port number too large: %d\n", port);
    2.51          return 0;
    2.52      }
    2.53  
    2.54 -    action = &ev_actions[ev];
    2.55 +    action = &ev_actions[port];
    2.56      action->count++;
    2.57 -    ack_hypervisor_event(ev);
    2.58  
    2.59      if (!action->handler)
    2.60          goto out;
    2.61 @@ -49,45 +48,49 @@ unsigned int do_event(int ev, struct pt_
    2.62          goto out;
    2.63      
    2.64      /* call the handler */
    2.65 -    action->handler(ev, regs);
    2.66 +    action->handler(port, regs);
    2.67 +
    2.68 +	clear_evtchn(port);
    2.69      
    2.70   out:
    2.71      return 1;
    2.72  
    2.73  }
    2.74  
    2.75 -/*
    2.76 - * add a handler
    2.77 - */
    2.78 -unsigned int add_ev_action( int ev, void (*handler)(int, struct pt_regs *) )
    2.79 +int bind_virq( u32 virq, void (*handler)(int, struct pt_regs *) )
    2.80  {
    2.81 -    if (ev_actions[ev].handler) {
    2.82 -        printk ("event[%d] already handled by %p", ev, ev_actions[ev].handler);
    2.83 -        return 0;
    2.84 +	evtchn_op_t op;
    2.85 +	int ret = 0;
    2.86 +	u32 port;
    2.87 +
    2.88 +	/* Try to bind the virq to a port */
    2.89 +	op.cmd = EVTCHNOP_bind_virq;
    2.90 +	op.u.bind_virq.virq = virq;
    2.91 +
    2.92 +	if ( HYPERVISOR_event_channel_op(&op) != 0 )
    2.93 +	{
    2.94 +		ret = 1;
    2.95 +		printk("Failed to bind virtual IRQ %d\n", virq);
    2.96 +		goto out;
    2.97      }
    2.98  
    2.99 -    ev_actions[ev].handler = handler;
   2.100 -    return 1;
   2.101 -}
   2.102 +    port = op.u.bind_virq.port;
   2.103 +	
   2.104 +	if(ev_actions[port].handler)
   2.105 +        printk("WARN: Handler for port %d already registered, replacing\n",
   2.106 +				port);
   2.107  
   2.108 -unsigned int enable_ev_action( int ev )
   2.109 -{
   2.110 -    if (!ev_actions[ev].handler) {
   2.111 -        printk ("enable event[%d], no handler installed", ev);
   2.112 -        return 0;
   2.113 -    }
   2.114 -    ev_actions[ev].status &= ~EVS_DISABLED;
   2.115 -    return 1;
   2.116 -}
   2.117 -
   2.118 -unsigned int disable_ev_action( int ev )
   2.119 -{
   2.120 -    ev_actions[ev].status |= EVS_DISABLED;
   2.121 -    return 1;
   2.122 +	ev_actions[port].handler = handler;
   2.123 +	ev_actions[port].status &= ~EVS_DISABLED;
   2.124 +	
   2.125 +	/* Finally unmask the port */
   2.126 +	unmask_evtchn(port);
   2.127 +out:
   2.128 +	return ret;
   2.129  }
   2.130  
   2.131  /*
   2.132 - * initially all events are without a handler and disabled
   2.133 + * Initially all events are without a handler and disabled
   2.134   */
   2.135  void init_events(void)
   2.136  {
   2.137 @@ -101,6 +104,6 @@ void init_events(void)
   2.138      }
   2.139  }
   2.140  
   2.141 -void default_handler(int ev, struct pt_regs *regs) {
   2.142 -    printk("X[%d] ", ev);
   2.143 +void default_handler(u32 port, struct pt_regs *regs) {
   2.144 +    printk("[Port %d] - event received\n", port);
   2.145  }
     3.1 --- a/extras/mini-os/h/events.h	Wed Jul 06 08:50:11 2005 +0000
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,53 +0,0 @@
     3.4 -/* -*-  Mode:C; c-basic-offset:4; tab-width:4 -*-
     3.5 - ****************************************************************************
     3.6 - * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge
     3.7 - ****************************************************************************
     3.8 - *
     3.9 - *        File: events.h
    3.10 - *      Author: Rolf Neugebauer (neugebar@dcs.gla.ac.uk)
    3.11 - *     Changes: 
    3.12 - *              
    3.13 - *        Date: Jul 2003
    3.14 - * 
    3.15 - * Environment: Xen Minimal OS
    3.16 - * Description: deal with events
    3.17 - *
    3.18 - ****************************************************************************
    3.19 - * $Id: h-insert.h,v 1.4 2002/11/08 16:03:55 rn Exp $
    3.20 - ****************************************************************************
    3.21 - */
    3.22 -
    3.23 -#ifndef _EVENTS_H_
    3.24 -#define _EVENTS_H_
    3.25 -
    3.26 -/* _EVENT_* are defined in xen-public/xen.h  */
    3.27 -#define EV_BLKDEV _EVENT_BLKDEV
    3.28 -#define EV_TIMER  _EVENT_TIMER
    3.29 -#define EV_DIE    _EVENT_DIE
    3.30 -#define EV_DEBUG  _EVENT_DEBUG
    3.31 -#define EV_NET    _EVENT_NET
    3.32 -#define EV_PS2    _EVENT_PS2
    3.33 -
    3.34 -#define NR_EVS (sizeof(HYPERVISOR_shared_info->events) * 8)
    3.35 -
    3.36 -/* ev handler status */
    3.37 -#define EVS_INPROGRESS	1	/* Event handler active - do not enter! */
    3.38 -#define EVS_DISABLED	2	/* Event disabled - do not enter! */
    3.39 -#define EVS_PENDING	    4	/* Event pending - replay on enable */
    3.40 -#define EVS_REPLAY	    8	/* Event has been replayed but not acked yet */
    3.41 -
    3.42 -/* this represents a event handler. Chaining or sharing is not allowed */
    3.43 -typedef struct _ev_action_t {
    3.44 -	void (*handler)(int, struct pt_regs *);
    3.45 -    unsigned int status;		/* IRQ status */
    3.46 -    u32 count;
    3.47 -} ev_action_t;
    3.48 -
    3.49 -/* prototypes */
    3.50 -unsigned int do_event(int ev, struct pt_regs *regs);
    3.51 -unsigned int add_ev_action( int ev, void (*handler)(int, struct pt_regs *) );
    3.52 -unsigned int enable_ev_action( int ev );
    3.53 -unsigned int disable_ev_action( int ev );
    3.54 -void init_events(void);
    3.55 -
    3.56 -#endif /* _EVENTS_H_ */
     4.1 --- a/extras/mini-os/h/hypervisor.h	Wed Jul 06 08:50:11 2005 +0000
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,316 +0,0 @@
     4.4 -/******************************************************************************
     4.5 - * hypervisor.h
     4.6 - * 
     4.7 - * Linux-specific hypervisor handling.
     4.8 - * 
     4.9 - * Copyright (c) 2002, K A Fraser
    4.10 - */
    4.11 -
    4.12 -#ifndef _HYPERVISOR_H_
    4.13 -#define _HYPERVISOR_H_
    4.14 -
    4.15 -#include <types.h>
    4.16 -
    4.17 -#include <xen-public/xen.h>
    4.18 -#include <xen-public/io/domain_controller.h>
    4.19 -
    4.20 -/*
    4.21 - * a placeholder for the start of day information passed up from the hypervisor
    4.22 - */
    4.23 -union start_info_union
    4.24 -{
    4.25 -    start_info_t start_info;
    4.26 -    char padding[512];
    4.27 -};
    4.28 -extern union start_info_union start_info_union;
    4.29 -#define start_info (start_info_union.start_info)
    4.30 -
    4.31 -
    4.32 -/* hypervisor.c */
    4.33 -void do_hypervisor_callback(struct pt_regs *regs);
    4.34 -void enable_hypervisor_event(unsigned int ev);
    4.35 -void disable_hypervisor_event(unsigned int ev);
    4.36 -void ack_hypervisor_event(unsigned int ev);
    4.37 -
    4.38 -/*
    4.39 - * Assembler stubs for hyper-calls.
    4.40 - */
    4.41 -
    4.42 -#ifdef __i386__
    4.43 -#define _a1 "b"
    4.44 -#define _a2 "c"
    4.45 -#define _a3 "d"
    4.46 -#define _a4 "S"
    4.47 -#else
    4.48 -#define _a1 "D"
    4.49 -#define _a2 "S"
    4.50 -#define _a3 "d"
    4.51 -#define _a4 "b"
    4.52 -#endif
    4.53 -
    4.54 -static __inline__ int HYPERVISOR_set_trap_table(trap_info_t *table)
    4.55 -{
    4.56 -    int ret;
    4.57 -    __asm__ __volatile__ (
    4.58 -        TRAP_INSTR
    4.59 -        : "=a" (ret) : "0" (__HYPERVISOR_set_trap_table),
    4.60 -        _a1 (table) : "memory" );
    4.61 -
    4.62 -    return ret;
    4.63 -}
    4.64 -
    4.65 -static __inline__ int HYPERVISOR_mmu_update(mmu_update_t *req, 
    4.66 -                                            int count, 
    4.67 -                                            int *success_count)
    4.68 -{
    4.69 -    int ret;
    4.70 -    __asm__ __volatile__ (
    4.71 -        TRAP_INSTR
    4.72 -        : "=a" (ret) : "0" (__HYPERVISOR_mmu_update), 
    4.73 -        _a1 (req), _a2 (count), _a3 (success_count)  : "memory" );
    4.74 -
    4.75 -    return ret;
    4.76 -}
    4.77 -
    4.78 -static __inline__ int HYPERVISOR_set_gdt(unsigned long *frame_list, int entries)
    4.79 -{
    4.80 -    int ret;
    4.81 -    __asm__ __volatile__ (
    4.82 -        TRAP_INSTR
    4.83 -        : "=a" (ret) : "0" (__HYPERVISOR_set_gdt), 
    4.84 -        _a1 (frame_list), _a2 (entries) : "memory" );
    4.85 -
    4.86 -
    4.87 -    return ret;
    4.88 -}
    4.89 -
    4.90 -static __inline__ int HYPERVISOR_stack_switch(unsigned long ss, unsigned long esp)
    4.91 -{
    4.92 -    int ret;
    4.93 -    __asm__ __volatile__ (
    4.94 -        TRAP_INSTR
    4.95 -        : "=a" (ret) : "0" (__HYPERVISOR_stack_switch),
    4.96 -        _a1 (ss), _a2 (esp) : "memory" );
    4.97 -
    4.98 -    return ret;
    4.99 -}
   4.100 -
   4.101 -#ifdef __i386__
   4.102 -static __inline__ int HYPERVISOR_set_callbacks(
   4.103 -    unsigned long event_selector, unsigned long event_address,
   4.104 -    unsigned long failsafe_selector, unsigned long failsafe_address)
   4.105 -{
   4.106 -    int ret;
   4.107 -    __asm__ __volatile__ (
   4.108 -        TRAP_INSTR
   4.109 -        : "=a" (ret) : "0" (__HYPERVISOR_set_callbacks),
   4.110 -        _a1 (event_selector), _a2 (event_address), 
   4.111 -        _a3 (failsafe_selector), _a4 (failsafe_address) : "memory" );
   4.112 -
   4.113 -    return ret;
   4.114 -}
   4.115 -#else
   4.116 -static __inline__ int HYPERVISOR_set_callbacks(
   4.117 -    unsigned long event_address,
   4.118 -    unsigned long failsafe_address,
   4.119 -    unsigned long syscall_address)
   4.120 -{
   4.121 -    int ret;
   4.122 -    __asm__ __volatile__ (
   4.123 -        TRAP_INSTR
   4.124 -        : "=a" (ret) : "0" (__HYPERVISOR_set_callbacks),
   4.125 -        _a1 (event_address), _a2 (failsafe_address), 
   4.126 -        _a3 (syscall_address) : "memory" );
   4.127 -
   4.128 -    return ret;
   4.129 -}
   4.130 -#endif
   4.131 -
   4.132 -static __inline__ int
   4.133 -HYPERVISOR_fpu_taskswitch(
   4.134 -    int set)
   4.135 -{
   4.136 -    int ret;
   4.137 -    unsigned long ign;
   4.138 -
   4.139 -    __asm__ __volatile__ (
   4.140 -        TRAP_INSTR
   4.141 -        : "=a" (ret), "=b" (ign)
   4.142 -        : "0" (__HYPERVISOR_fpu_taskswitch), "1" (set)
   4.143 -        : "memory" );
   4.144 -
   4.145 -    return ret;
   4.146 -}
   4.147 -
   4.148 -static __inline__ int HYPERVISOR_yield(void)
   4.149 -{
   4.150 -    int ret;
   4.151 -    __asm__ __volatile__ (
   4.152 -        TRAP_INSTR
   4.153 -        : "=a" (ret) : "0" (__HYPERVISOR_sched_op),
   4.154 -        _a1 (SCHEDOP_yield) : "memory" );
   4.155 -
   4.156 -    return ret;
   4.157 -}
   4.158 -
   4.159 -static __inline__ int HYPERVISOR_block(void)
   4.160 -{
   4.161 -    int ret;
   4.162 -    __asm__ __volatile__ (
   4.163 -        TRAP_INSTR
   4.164 -        : "=a" (ret) : "0" (__HYPERVISOR_sched_op),
   4.165 -        _a1 (SCHEDOP_block) : "memory" );
   4.166 -
   4.167 -    return ret;
   4.168 -}
   4.169 -
   4.170 -static __inline__ int HYPERVISOR_shutdown(void)
   4.171 -{
   4.172 -    int ret;
   4.173 -    __asm__ __volatile__ (
   4.174 -        TRAP_INSTR
   4.175 -        : "=a" (ret) : "0" (__HYPERVISOR_sched_op),
   4.176 -        _a1 (SCHEDOP_shutdown | (SHUTDOWN_poweroff << SCHEDOP_reasonshift))
   4.177 -        : "memory" );
   4.178 -
   4.179 -    return ret;
   4.180 -}
   4.181 -
   4.182 -static __inline__ int HYPERVISOR_reboot(void)
   4.183 -{
   4.184 -    int ret;
   4.185 -    __asm__ __volatile__ (
   4.186 -        TRAP_INSTR
   4.187 -        : "=a" (ret) : "0" (__HYPERVISOR_sched_op),
   4.188 -        _a1 (SCHEDOP_shutdown | (SHUTDOWN_reboot << SCHEDOP_reasonshift))
   4.189 -        : "memory" );
   4.190 -
   4.191 -    return ret;
   4.192 -}
   4.193 -
   4.194 -static __inline__ int HYPERVISOR_suspend(unsigned long srec)
   4.195 -{
   4.196 -    int ret;
   4.197 -    /* NB. On suspend, control software expects a suspend record in %esi. */
   4.198 -    __asm__ __volatile__ (
   4.199 -        TRAP_INSTR
   4.200 -        : "=a" (ret) : "0" (__HYPERVISOR_sched_op),
   4.201 -        _a1 (SCHEDOP_shutdown | (SHUTDOWN_suspend << SCHEDOP_reasonshift)), 
   4.202 -        "S" (srec) : "memory" );
   4.203 -
   4.204 -    return ret;
   4.205 -}
   4.206 -
   4.207 -static __inline__ long HYPERVISOR_set_timer_op(void *timer_arg)
   4.208 -{
   4.209 -    int ret;
   4.210 -    __asm__ __volatile__ (
   4.211 -        TRAP_INSTR
   4.212 -        : "=a" (ret) : "0" (__HYPERVISOR_set_timer_op),
   4.213 -        _a1 (timer_arg) : "memory" );
   4.214 -
   4.215 -    return ret;
   4.216 -}
   4.217 -
   4.218 -static __inline__ int HYPERVISOR_dom0_op(void *dom0_op)
   4.219 -{
   4.220 -    int ret;
   4.221 -    __asm__ __volatile__ (
   4.222 -        TRAP_INSTR
   4.223 -        : "=a" (ret) : "0" (__HYPERVISOR_dom0_op),
   4.224 -        _a1 (dom0_op) : "memory" );
   4.225 -
   4.226 -    return ret;
   4.227 -}
   4.228 -
   4.229 -static __inline__ int HYPERVISOR_set_debugreg(int reg, unsigned long value)
   4.230 -{
   4.231 -    int ret;
   4.232 -    __asm__ __volatile__ (
   4.233 -        TRAP_INSTR
   4.234 -        : "=a" (ret) : "0" (__HYPERVISOR_set_debugreg),
   4.235 -        _a1 (reg), _a2 (value) : "memory" );
   4.236 -
   4.237 -    return ret;
   4.238 -}
   4.239 -
   4.240 -static __inline__ unsigned long HYPERVISOR_get_debugreg(int reg)
   4.241 -{
   4.242 -    unsigned long ret;
   4.243 -    __asm__ __volatile__ (
   4.244 -        TRAP_INSTR
   4.245 -        : "=a" (ret) : "0" (__HYPERVISOR_get_debugreg),
   4.246 -        _a1 (reg) : "memory" );
   4.247 -
   4.248 -    return ret;
   4.249 -}
   4.250 -
   4.251 -static __inline__ int HYPERVISOR_update_descriptor(
   4.252 -    unsigned long pa, unsigned long word1, unsigned long word2)
   4.253 -{
   4.254 -    int ret;
   4.255 -    __asm__ __volatile__ (
   4.256 -        TRAP_INSTR
   4.257 -        : "=a" (ret) : "0" (__HYPERVISOR_update_descriptor), 
   4.258 -        _a1 (pa), _a2 (word1), _a3 (word2) : "memory" );
   4.259 -
   4.260 -    return ret;
   4.261 -}
   4.262 -
   4.263 -static __inline__ int HYPERVISOR_dom_mem_op(void *dom_mem_op)
   4.264 -{
   4.265 -    int ret;
   4.266 -    __asm__ __volatile__ (
   4.267 -        TRAP_INSTR
   4.268 -        : "=a" (ret) : "0" (__HYPERVISOR_dom_mem_op),
   4.269 -        _a1 (dom_mem_op) : "memory" );
   4.270 -
   4.271 -    return ret;
   4.272 -}
   4.273 -
   4.274 -static __inline__ int HYPERVISOR_multicall(void *call_list, int nr_calls)
   4.275 -{
   4.276 -    int ret;
   4.277 -    __asm__ __volatile__ (
   4.278 -        TRAP_INSTR
   4.279 -        : "=a" (ret) : "0" (__HYPERVISOR_multicall),
   4.280 -        _a1 (call_list), _a2 (nr_calls) : "memory" );
   4.281 -
   4.282 -    return ret;
   4.283 -}
   4.284 -
   4.285 -static __inline__ int HYPERVISOR_update_va_mapping(
   4.286 -    unsigned long page_nr, unsigned long new_val, unsigned long flags)
   4.287 -{
   4.288 -    int ret;
   4.289 -    __asm__ __volatile__ (
   4.290 -        TRAP_INSTR
   4.291 -        : "=a" (ret) : "0" (__HYPERVISOR_update_va_mapping), 
   4.292 -        _a1 (page_nr), _a2 (new_val), _a3 (flags) : "memory" );
   4.293 -
   4.294 -    return ret;
   4.295 -}
   4.296 -
   4.297 -static __inline__ int HYPERVISOR_xen_version(int cmd)
   4.298 -{
   4.299 -    int ret;
   4.300 -    __asm__ __volatile__ (
   4.301 -        TRAP_INSTR
   4.302 -        : "=a" (ret) : "0" (__HYPERVISOR_xen_version), 
   4.303 -        _a1 (cmd) : "memory" );
   4.304 -
   4.305 -    return ret;
   4.306 -}
   4.307 -
   4.308 -static __inline__ int HYPERVISOR_console_io(int cmd, int count, char *str)
   4.309 -{
   4.310 -    int ret;
   4.311 -    __asm__ __volatile__ (
   4.312 -        TRAP_INSTR
   4.313 -        : "=a" (ret) : "0" (__HYPERVISOR_console_io),
   4.314 -        _a1 (cmd), _a2 (count), _a3 (str) : "memory" );
   4.315 -
   4.316 -    return ret;
   4.317 -}
   4.318 -
   4.319 -#endif /* __HYPERVISOR_H__ */
     5.1 --- a/extras/mini-os/h/lib.h	Wed Jul 06 08:50:11 2005 +0000
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,114 +0,0 @@
     5.4 -/* -*-  Mode:C; c-basic-offset:4; tab-width:4 -*-
     5.5 - ****************************************************************************
     5.6 - * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge
     5.7 - ****************************************************************************
     5.8 - *
     5.9 - *        File: lib.h
    5.10 - *      Author: Rolf Neugebauer (neugebar@dcs.gla.ac.uk)
    5.11 - *     Changes: 
    5.12 - *              
    5.13 - *        Date: Aug 2003
    5.14 - * 
    5.15 - * Environment: Xen Minimal OS
    5.16 - * Description: Random useful library functions, contains some freebsd stuff
    5.17 - *
    5.18 - ****************************************************************************
    5.19 - * $Id: h-insert.h,v 1.4 2002/11/08 16:03:55 rn Exp $
    5.20 - ****************************************************************************
    5.21 - *
    5.22 - *-
    5.23 - * Copyright (c) 1991, 1993
    5.24 - *      The Regents of the University of California.  All rights reserved.
    5.25 - *
    5.26 - * Redistribution and use in source and binary forms, with or without
    5.27 - * modification, are permitted provided that the following conditions
    5.28 - * are met:
    5.29 - * 1. Redistributions of source code must retain the above copyright
    5.30 - *    notice, this list of conditions and the following disclaimer.
    5.31 - * 2. Redistributions in binary form must reproduce the above copyright
    5.32 - *    notice, this list of conditions and the following disclaimer in the
    5.33 - *    documentation and/or other materials provided with the distribution.
    5.34 - * 3. All advertising materials mentioning features or use of this software
    5.35 - *    must display the following acknowledgement:
    5.36 - *      This product includes software developed by the University of
    5.37 - *      California, Berkeley and its contributors.
    5.38 - * 4. Neither the name of the University nor the names of its contributors
    5.39 - *    may be used to endorse or promote products derived from this software
    5.40 - *    without specific prior written permission.
    5.41 - *
    5.42 - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
    5.43 - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    5.44 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    5.45 - * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
    5.46 - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    5.47 - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    5.48 - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    5.49 - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    5.50 - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    5.51 - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    5.52 - * SUCH DAMAGE.
    5.53 - *
    5.54 - *      @(#)stdarg.h    8.1 (Berkeley) 6/10/93
    5.55 - * $FreeBSD: src/sys/i386/include/stdarg.h,v 1.10 1999/08/28 00:44:26 peter Exp $
    5.56 - */
    5.57 -
    5.58 -#ifndef _LIB_H_
    5.59 -#define _LIB_H_
    5.60 -
    5.61 -#include <stdarg.h>
    5.62 -
    5.63 -/* printing */
    5.64 -#define printk  printf
    5.65 -#define kprintf printf
    5.66 -int printf(const char *fmt, ...);
    5.67 -int vprintf(const char *fmt, va_list ap);
    5.68 -int sprintf(char *buf, const char *cfmt, ...);
    5.69 -int vsprintf(char *buf, const char *cfmt, va_list ap);
    5.70 -
    5.71 -/* string and memory manipulation */
    5.72 -int    memcmp(const void *cs, const void *ct, size_t count);
    5.73 -void  *memcpy(void *dest, const void *src, size_t count);
    5.74 -int    strncmp(const char *cs, const char *ct, size_t count);
    5.75 -int    strcmp(const char *cs, const char *ct);
    5.76 -char  *strcpy(char *dest, const char *src);
    5.77 -char  *strncpy(char *dest, const char *src, size_t count);
    5.78 -void  *memset(void *s,int c, size_t count);
    5.79 -size_t strnlen(const char *s, size_t count);
    5.80 -size_t strlen(const char *s);
    5.81 -char  *strchr(const char *s, int c);
    5.82 -char  *strstr(const char *s1, const char *s2);
    5.83 -
    5.84 -
    5.85 -/* dlmalloc functions */
    5.86 -struct mallinfo {
    5.87 -  int arena;    /* non-mmapped space allocated from system */
    5.88 -  int ordblks;  /* number of free chunks */
    5.89 -  int smblks;   /* number of fastbin blocks */
    5.90 -  int hblks;    /* number of mmapped regions */
    5.91 -  int hblkhd;   /* space in mmapped regions */
    5.92 -  int usmblks;  /* maximum total allocated space */
    5.93 -  int fsmblks;  /* space available in freed fastbin blocks */
    5.94 -  int uordblks; /* total allocated space */
    5.95 -  int fordblks; /* total free space */
    5.96 -  int keepcost; /* top-most, releasable (via malloc_trim) space */
    5.97 -};
    5.98 -
    5.99 -void *malloc(size_t n);
   5.100 -void *calloc(size_t n_elements, size_t element_size);
   5.101 -void  free(void* p);
   5.102 -void *realloc(void* p, size_t n);
   5.103 -void *memalign(size_t alignment, size_t n);
   5.104 -void *valloc(size_t n);
   5.105 -struct mallinfo mallinfo(void);
   5.106 -int  mallopt(int parameter_number, int parameter_value);
   5.107 -
   5.108 -void **independent_calloc(size_t n_elements, size_t size, void* chunks[]);
   5.109 -void **independent_comalloc(size_t n_elements, size_t sizes[], void* chunks[]);
   5.110 -void *pvalloc(size_t n);
   5.111 -void cfree(void* p);
   5.112 -int malloc_trim(size_t pad);
   5.113 -size_t malloc_usable_size(void* p);
   5.114 -void malloc_stats(void);
   5.115 -
   5.116 -
   5.117 -#endif /* _LIB_H_ */
     6.1 --- a/extras/mini-os/h/mm.h	Wed Jul 06 08:50:11 2005 +0000
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,111 +0,0 @@
     6.4 -/* -*-  Mode:C; c-basic-offset:4; tab-width:4 -*-
     6.5 - *
     6.6 - * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge
     6.7 - * Copyright (c) 2005, Keir A Fraser
     6.8 - *
     6.9 - * Permission is hereby granted, free of charge, to any person obtaining a copy
    6.10 - * of this software and associated documentation files (the "Software"), to
    6.11 - * deal in the Software without restriction, including without limitation the
    6.12 - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
    6.13 - * sell copies of the Software, and to permit persons to whom the Software is
    6.14 - * furnished to do so, subject to the following conditions:
    6.15 - * 
    6.16 - * The above copyright notice and this permission notice shall be included in
    6.17 - * all copies or substantial portions of the Software.
    6.18 - * 
    6.19 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
    6.20 - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
    6.21 - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
    6.22 - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
    6.23 - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
    6.24 - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
    6.25 - * DEALINGS IN THE SOFTWARE.
    6.26 - */
    6.27 -
    6.28 -#ifndef _MM_H_
    6.29 -#define _MM_H_
    6.30 -
    6.31 -#ifdef __x86_64__
    6.32 -
    6.33 -#define L1_PAGETABLE_SHIFT      12
    6.34 -#define L2_PAGETABLE_SHIFT      21
    6.35 -#define L3_PAGETABLE_SHIFT      30
    6.36 -#define L4_PAGETABLE_SHIFT      39
    6.37 -
    6.38 -#define L1_PAGETABLE_ENTRIES    512
    6.39 -#define L2_PAGETABLE_ENTRIES    512
    6.40 -#define L3_PAGETABLE_ENTRIES    512
    6.41 -#define L4_PAGETABLE_ENTRIES    512
    6.42 -
    6.43 -/* These are page-table limitations. Current CPUs support only 40-bit phys. */
    6.44 -#define PADDR_BITS              52
    6.45 -#define VADDR_BITS              48
    6.46 -#define PADDR_MASK              ((1UL << PADDR_BITS)-1)
    6.47 -#define VADDR_MASK              ((1UL << VADDR_BITS)-1)
    6.48 -
    6.49 -#define pte_to_mfn(_pte) (((_pte) & (PADDR_MASK&PAGE_MASK)) >> PAGE_SHIFT)
    6.50 -
    6.51 -/* Given a virtual address, get an entry offset into a page table. */
    6.52 -#define l1_table_offset(_a) \
    6.53 -  (((_a) >> L1_PAGETABLE_SHIFT) & (L1_PAGETABLE_ENTRIES - 1))
    6.54 -#define l2_table_offset(_a) \
    6.55 -  (((_a) >> L2_PAGETABLE_SHIFT) & (L2_PAGETABLE_ENTRIES - 1))
    6.56 -#define l3_table_offset(_a) \
    6.57 -  (((_a) >> L3_PAGETABLE_SHIFT) & (L3_PAGETABLE_ENTRIES - 1))
    6.58 -#define l4_table_offset(_a) \
    6.59 -  (((_a) >> L4_PAGETABLE_SHIFT) & (L4_PAGETABLE_ENTRIES - 1))
    6.60 -#endif
    6.61 -
    6.62 -#define _PAGE_PRESENT  0x001UL
    6.63 -#define _PAGE_RW       0x002UL
    6.64 -#define _PAGE_USER     0x004UL
    6.65 -#define _PAGE_PWT      0x008UL
    6.66 -#define _PAGE_PCD      0x010UL
    6.67 -#define _PAGE_ACCESSED 0x020UL
    6.68 -#define _PAGE_DIRTY    0x040UL
    6.69 -#define _PAGE_PAT      0x080UL
    6.70 -#define _PAGE_PSE      0x080UL
    6.71 -#define _PAGE_GLOBAL   0x100UL
    6.72 -
    6.73 -#define PAGE_SHIFT      12
    6.74 -#define PAGE_SIZE       (1UL << PAGE_SHIFT)
    6.75 -#define PAGE_MASK       (~(PAGE_SIZE-1))
    6.76 -
    6.77 -#define PFN_UP(x)	(((x) + PAGE_SIZE-1) >> PAGE_SHIFT)
    6.78 -#define PFN_DOWN(x)	((x) >> PAGE_SHIFT)
    6.79 -#define PFN_PHYS(x)	((x) << PAGE_SHIFT)
    6.80 -
    6.81 -/* to align the pointer to the (next) page boundary */
    6.82 -#define PAGE_ALIGN(addr)        (((addr)+PAGE_SIZE-1)&PAGE_MASK)
    6.83 -
    6.84 -extern unsigned long *phys_to_machine_mapping;
    6.85 -#define pfn_to_mfn(_pfn) (phys_to_machine_mapping[(_pfn)])
    6.86 -#define mfn_to_pfn(_mfn) (machine_to_phys_mapping[(_mfn)])
    6.87 -static __inline__ unsigned long phys_to_machine(unsigned long phys)
    6.88 -{
    6.89 -    unsigned long machine = pfn_to_mfn(phys >> PAGE_SHIFT);
    6.90 -    machine = (machine << PAGE_SHIFT) | (phys & ~PAGE_MASK);
    6.91 -    return machine;
    6.92 -}
    6.93 -static __inline__ unsigned long machine_to_phys(unsigned long machine)
    6.94 -{
    6.95 -    unsigned long phys = mfn_to_pfn(machine >> PAGE_SHIFT);
    6.96 -    phys = (phys << PAGE_SHIFT) | (machine & ~PAGE_MASK);
    6.97 -    return phys;
    6.98 -}
    6.99 -
   6.100 -#ifdef __x86_64__
   6.101 -#define VIRT_START              0xFFFFFFFF00000000UL
   6.102 -#else
   6.103 -#define VIRT_START              0xC0000000UL
   6.104 -#endif
   6.105 -
   6.106 -#define to_phys(x)                 ((unsigned long)(x)-VIRT_START)
   6.107 -#define to_virt(x)                 ((void *)((unsigned long)(x)+VIRT_START))
   6.108 -#define __va to_virt
   6.109 -#define __pa to_phys
   6.110 -
   6.111 -void init_mm(void);
   6.112 -unsigned long alloc_pages(int order);
   6.113 -
   6.114 -#endif /* _MM_H_ */
     7.1 --- a/extras/mini-os/h/os.h	Wed Jul 06 08:50:11 2005 +0000
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,280 +0,0 @@
     7.4 -/******************************************************************************
     7.5 - * os.h
     7.6 - * 
     7.7 - * random collection of macros and definition
     7.8 - */
     7.9 -
    7.10 -#ifndef _OS_H_
    7.11 -#define _OS_H_
    7.12 -
    7.13 -#define NULL 0
    7.14 -
    7.15 -#if __GNUC__ == 2 && __GNUC_MINOR__ < 96
    7.16 -#define __builtin_expect(x, expected_value) (x)
    7.17 -#endif
    7.18 -#define unlikely(x)  __builtin_expect((x),0)
    7.19 -
    7.20 -#define smp_processor_id() 0
    7.21 -#define preempt_disable() ((void)0)
    7.22 -#define preempt_enable() ((void)0)
    7.23 -
    7.24 -#define force_evtchn_callback() ((void)HYPERVISOR_xen_version(0))
    7.25 -
    7.26 -#ifndef __ASSEMBLY__
    7.27 -#include <types.h>
    7.28 -#endif
    7.29 -#include <xen-public/xen.h>
    7.30 -
    7.31 -#define __KERNEL_CS  FLAT_KERNEL_CS
    7.32 -#define __KERNEL_DS  FLAT_KERNEL_DS
    7.33 -#define __KERNEL_SS  FLAT_KERNEL_SS
    7.34 -
    7.35 -#define TRAP_divide_error      0
    7.36 -#define TRAP_debug             1
    7.37 -#define TRAP_nmi               2
    7.38 -#define TRAP_int3              3
    7.39 -#define TRAP_overflow          4
    7.40 -#define TRAP_bounds            5
    7.41 -#define TRAP_invalid_op        6
    7.42 -#define TRAP_no_device         7
    7.43 -#define TRAP_double_fault      8
    7.44 -#define TRAP_copro_seg         9
    7.45 -#define TRAP_invalid_tss      10
    7.46 -#define TRAP_no_segment       11
    7.47 -#define TRAP_stack_error      12
    7.48 -#define TRAP_gp_fault         13
    7.49 -#define TRAP_page_fault       14
    7.50 -#define TRAP_spurious_int     15
    7.51 -#define TRAP_copro_error      16
    7.52 -#define TRAP_alignment_check  17
    7.53 -#define TRAP_machine_check    18
    7.54 -#define TRAP_simd_error       19
    7.55 -#define TRAP_deferred_nmi     31
    7.56 -
    7.57 -/* Everything below this point is not included by assembler (.S) files. */
    7.58 -#ifndef __ASSEMBLY__
    7.59 -
    7.60 -#define pt_regs xen_regs
    7.61 -
    7.62 -void trap_init(void);
    7.63 -void dump_regs(struct pt_regs *regs);
    7.64 -
    7.65 -/* 
    7.66 - * The use of 'barrier' in the following reflects their use as local-lock
    7.67 - * operations. Reentrancy must be prevented (e.g., __cli()) /before/ following
    7.68 - * critical operations are executed. All critical operations must complete
    7.69 - * /before/ reentrancy is permitted (e.g., __sti()). Alpha architecture also
    7.70 - * includes these barriers, for example.
    7.71 - */
    7.72 -
    7.73 -#define __cli()								\
    7.74 -do {									\
    7.75 -	vcpu_info_t *_vcpu;						\
    7.76 -	preempt_disable();						\
    7.77 -	_vcpu = &HYPERVISOR_shared_info->vcpu_data[smp_processor_id()];	\
    7.78 -	_vcpu->evtchn_upcall_mask = 1;					\
    7.79 -	preempt_enable_no_resched();					\
    7.80 -	barrier();							\
    7.81 -} while (0)
    7.82 -
    7.83 -#define __sti()								\
    7.84 -do {									\
    7.85 -	vcpu_info_t *_vcpu;						\
    7.86 -	barrier();							\
    7.87 -	preempt_disable();						\
    7.88 -	_vcpu = &HYPERVISOR_shared_info->vcpu_data[smp_processor_id()];	\
    7.89 -	_vcpu->evtchn_upcall_mask = 0;					\
    7.90 -	barrier(); /* unmask then check (avoid races) */		\
    7.91 -	if ( unlikely(_vcpu->evtchn_upcall_pending) )			\
    7.92 -		force_evtchn_callback();				\
    7.93 -	preempt_enable();						\
    7.94 -} while (0)
    7.95 -
    7.96 -#define __save_flags(x)							\
    7.97 -do {									\
    7.98 -	vcpu_info_t *_vcpu;						\
    7.99 -	_vcpu = &HYPERVISOR_shared_info->vcpu_data[smp_processor_id()];	\
   7.100 -	(x) = _vcpu->evtchn_upcall_mask;				\
   7.101 -} while (0)
   7.102 -
   7.103 -#define __restore_flags(x)						\
   7.104 -do {									\
   7.105 -	vcpu_info_t *_vcpu;						\
   7.106 -	barrier();							\
   7.107 -	preempt_disable();						\
   7.108 -	_vcpu = &HYPERVISOR_shared_info->vcpu_data[smp_processor_id()];	\
   7.109 -	if ((_vcpu->evtchn_upcall_mask = (x)) == 0) {			\
   7.110 -		barrier(); /* unmask then check (avoid races) */	\
   7.111 -		if ( unlikely(_vcpu->evtchn_upcall_pending) )		\
   7.112 -			force_evtchn_callback();			\
   7.113 -		preempt_enable();					\
   7.114 -	} else								\
   7.115 -		preempt_enable_no_resched();				\
   7.116 -} while (0)
   7.117 -
   7.118 -#define safe_halt()		((void)0)
   7.119 -
   7.120 -#define __save_and_cli(x)						\
   7.121 -do {									\
   7.122 -	vcpu_info_t *_vcpu;						\
   7.123 -	preempt_disable();						\
   7.124 -	_vcpu = &HYPERVISOR_shared_info->vcpu_data[smp_processor_id()];	\
   7.125 -	(x) = _vcpu->evtchn_upcall_mask;				\
   7.126 -	_vcpu->evtchn_upcall_mask = 1;					\
   7.127 -	preempt_enable_no_resched();					\
   7.128 -	barrier();							\
   7.129 -} while (0)
   7.130 -
   7.131 -#define local_irq_save(x)	__save_and_cli(x)
   7.132 -#define local_irq_restore(x)	__restore_flags(x)
   7.133 -#define local_save_flags(x)	__save_flags(x)
   7.134 -#define local_irq_disable()	__cli()
   7.135 -#define local_irq_enable()	__sti()
   7.136 -
   7.137 -#define irqs_disabled()			\
   7.138 -    HYPERVISOR_shared_info->vcpu_data[smp_processor_id()].evtchn_upcall_mask
   7.139 -
   7.140 -/* This is a barrier for the compiler only, NOT the processor! */
   7.141 -#define barrier() __asm__ __volatile__("": : :"memory")
   7.142 -
   7.143 -#define LOCK_PREFIX ""
   7.144 -#define LOCK ""
   7.145 -#define ADDR (*(volatile long *) addr)
   7.146 -/*
   7.147 - * Make sure gcc doesn't try to be clever and move things around
   7.148 - * on us. We need to use _exactly_ the address the user gave us,
   7.149 - * not some alias that contains the same information.
   7.150 - */
   7.151 -typedef struct { volatile int counter; } atomic_t;
   7.152 -
   7.153 -
   7.154 -#define xchg(ptr,v) \
   7.155 -        ((__typeof__(*(ptr)))__xchg((unsigned long)(v),(ptr),sizeof(*(ptr))))
   7.156 -struct __xchg_dummy { unsigned long a[100]; };
   7.157 -#define __xg(x) ((volatile struct __xchg_dummy *)(x))
   7.158 -static __inline__ unsigned long __xchg(unsigned long x, volatile void * ptr,
   7.159 -                                   int size)
   7.160 -{
   7.161 -    switch (size) {
   7.162 -    case 1:
   7.163 -        __asm__ __volatile__("xchgb %b0,%1"
   7.164 -                             :"=q" (x)
   7.165 -                             :"m" (*__xg(ptr)), "0" (x)
   7.166 -                             :"memory");
   7.167 -        break;
   7.168 -    case 2:
   7.169 -        __asm__ __volatile__("xchgw %w0,%1"
   7.170 -                             :"=r" (x)
   7.171 -                             :"m" (*__xg(ptr)), "0" (x)
   7.172 -                             :"memory");
   7.173 -        break;
   7.174 -    case 4:
   7.175 -        __asm__ __volatile__("xchgl %0,%1"
   7.176 -                             :"=r" (x)
   7.177 -                             :"m" (*__xg(ptr)), "0" (x)
   7.178 -                             :"memory");
   7.179 -        break;
   7.180 -    }
   7.181 -    return x;
   7.182 -}
   7.183 -
   7.184 -/**
   7.185 - * test_and_clear_bit - Clear a bit and return its old value
   7.186 - * @nr: Bit to set
   7.187 - * @addr: Address to count from
   7.188 - *
   7.189 - * This operation is atomic and cannot be reordered.  
   7.190 - * It also implies a memory barrier.
   7.191 - */
   7.192 -static __inline__ int test_and_clear_bit(int nr, volatile void * addr)
   7.193 -{
   7.194 -        int oldbit;
   7.195 -
   7.196 -        __asm__ __volatile__( LOCK_PREFIX
   7.197 -                "btrl %2,%1\n\tsbbl %0,%0"
   7.198 -                :"=r" (oldbit),"=m" (ADDR)
   7.199 -                :"Ir" (nr) : "memory");
   7.200 -        return oldbit;
   7.201 -}
   7.202 -
   7.203 -static __inline__ int constant_test_bit(int nr, const volatile void * addr)
   7.204 -{
   7.205 -    return ((1UL << (nr & 31)) & (((const volatile unsigned int *) addr)[nr >> 5])) != 0;
   7.206 -}
   7.207 -
   7.208 -static __inline__ int variable_test_bit(int nr, volatile void * addr)
   7.209 -{
   7.210 -    int oldbit;
   7.211 -    
   7.212 -    __asm__ __volatile__(
   7.213 -        "btl %2,%1\n\tsbbl %0,%0"
   7.214 -        :"=r" (oldbit)
   7.215 -        :"m" (ADDR),"Ir" (nr));
   7.216 -    return oldbit;
   7.217 -}
   7.218 -
   7.219 -#define test_bit(nr,addr) \
   7.220 -(__builtin_constant_p(nr) ? \
   7.221 - constant_test_bit((nr),(addr)) : \
   7.222 - variable_test_bit((nr),(addr)))
   7.223 -
   7.224 -
   7.225 -/**
   7.226 - * set_bit - Atomically set a bit in memory
   7.227 - * @nr: the bit to set
   7.228 - * @addr: the address to start counting from
   7.229 - *
   7.230 - * This function is atomic and may not be reordered.  See __set_bit()
   7.231 - * if you do not require the atomic guarantees.
   7.232 - * Note that @nr may be almost arbitrarily large; this function is not
   7.233 - * restricted to acting on a single-word quantity.
   7.234 - */
   7.235 -static __inline__ void set_bit(int nr, volatile void * addr)
   7.236 -{
   7.237 -        __asm__ __volatile__( LOCK_PREFIX
   7.238 -                "btsl %1,%0"
   7.239 -                :"=m" (ADDR)
   7.240 -                :"Ir" (nr));
   7.241 -}
   7.242 -
   7.243 -/**
   7.244 - * clear_bit - Clears a bit in memory
   7.245 - * @nr: Bit to clear
   7.246 - * @addr: Address to start counting from
   7.247 - *
   7.248 - * clear_bit() is atomic and may not be reordered.  However, it does
   7.249 - * not contain a memory barrier, so if it is used for locking purposes,
   7.250 - * you should call smp_mb__before_clear_bit() and/or smp_mb__after_clear_bit()
   7.251 - * in order to ensure changes are visible on other processors.
   7.252 - */
   7.253 -static __inline__ void clear_bit(int nr, volatile void * addr)
   7.254 -{
   7.255 -        __asm__ __volatile__( LOCK_PREFIX
   7.256 -                "btrl %1,%0"
   7.257 -                :"=m" (ADDR)
   7.258 -                :"Ir" (nr));
   7.259 -}
   7.260 -
   7.261 -/**
   7.262 - * atomic_inc - increment atomic variable
   7.263 - * @v: pointer of type atomic_t
   7.264 - * 
   7.265 - * Atomically increments @v by 1.  Note that the guaranteed
   7.266 - * useful range of an atomic_t is only 24 bits.
   7.267 - */ 
   7.268 -static __inline__ void atomic_inc(atomic_t *v)
   7.269 -{
   7.270 -        __asm__ __volatile__(
   7.271 -                LOCK "incl %0"
   7.272 -                :"=m" (v->counter)
   7.273 -                :"m" (v->counter));
   7.274 -}
   7.275 -
   7.276 -
   7.277 -#define rdtscll(val) \
   7.278 -     __asm__ __volatile__("rdtsc" : "=A" (val))
   7.279 -
   7.280 -
   7.281 -#endif /* !__ASSEMBLY__ */
   7.282 -
   7.283 -#endif /* _OS_H_ */
     8.1 --- a/extras/mini-os/h/time.h	Wed Jul 06 08:50:11 2005 +0000
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,57 +0,0 @@
     8.4 -/* -*-  Mode:C; c-basic-offset:4; tab-width:4 -*-
     8.5 - ****************************************************************************
     8.6 - * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge
     8.7 - ****************************************************************************
     8.8 - *
     8.9 - *        File: time.h
    8.10 - *      Author: Rolf Neugebauer (neugebar@dcs.gla.ac.uk)
    8.11 - *     Changes: 
    8.12 - *              
    8.13 - *        Date: Jul 2003
    8.14 - * 
    8.15 - * Environment: Xen Minimal OS
    8.16 - * Description: Time and timer functions
    8.17 - *
    8.18 - ****************************************************************************
    8.19 - * $Id: h-insert.h,v 1.4 2002/11/08 16:03:55 rn Exp $
    8.20 - ****************************************************************************
    8.21 - */
    8.22 -
    8.23 -#ifndef _TIME_H_
    8.24 -#define _TIME_H_
    8.25 -
    8.26 -/*
    8.27 - * System Time
    8.28 - * 64 bit value containing the nanoseconds elapsed since boot time.
    8.29 - * This value is adjusted by frequency drift.
    8.30 - * NOW() returns the current time.
    8.31 - * The other macros are for convenience to approximate short intervals
    8.32 - * of real time into system time 
    8.33 - */
    8.34 -typedef s64 s_time_t;
    8.35 -#define NOW()                   ((s_time_t)get_s_time())
    8.36 -#define SECONDS(_s)             (((s_time_t)(_s))  * 1000000000UL )
    8.37 -#define TENTHS(_ts)             (((s_time_t)(_ts)) * 100000000UL )
    8.38 -#define HUNDREDTHS(_hs)         (((s_time_t)(_hs)) * 10000000UL )
    8.39 -#define MILLISECS(_ms)          (((s_time_t)(_ms)) * 1000000UL )
    8.40 -#define MICROSECS(_us)          (((s_time_t)(_us)) * 1000UL )
    8.41 -#define Time_Max                ((s_time_t) 0x7fffffffffffffffLL)
    8.42 -#define FOREVER                 Time_Max
    8.43 -
    8.44 -
    8.45 -/* wall clock time  */
    8.46 -typedef long time_t;
    8.47 -typedef long suseconds_t;
    8.48 -struct timeval {
    8.49 -	time_t		tv_sec;		/* seconds */
    8.50 -	suseconds_t	tv_usec;	/* microseconds */
    8.51 -};
    8.52 -
    8.53 -
    8.54 -/* prototypes */
    8.55 -void     init_time(void);
    8.56 -s_time_t get_s_time(void);
    8.57 -s_time_t get_v_time(void);
    8.58 -void     gettimeofday(struct timeval *tv);
    8.59 -
    8.60 -#endif /* _TIME_H_ */
     9.1 --- a/extras/mini-os/h/types.h	Wed Jul 06 08:50:11 2005 +0000
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,52 +0,0 @@
     9.4 -/* -*-  Mode:C; c-basic-offset:4; tab-width:4 -*-
     9.5 - ****************************************************************************
     9.6 - * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge
     9.7 - ****************************************************************************
     9.8 - *
     9.9 - *        File: types.h
    9.10 - *      Author: Rolf Neugebauer (neugebar@dcs.gla.ac.uk)
    9.11 - *     Changes: 
    9.12 - *              
    9.13 - *        Date: May 2003
    9.14 - * 
    9.15 - * Environment: Xen Minimal OS
    9.16 - * Description: a random collection of type definitions
    9.17 - *
    9.18 - ****************************************************************************
    9.19 - * $Id: h-insert.h,v 1.4 2002/11/08 16:03:55 rn Exp $
    9.20 - ****************************************************************************
    9.21 - */
    9.22 -
    9.23 -#ifndef _TYPES_H_
    9.24 -#define _TYPES_H_
    9.25 -
    9.26 -typedef signed char         s8;
    9.27 -typedef unsigned char       u8;
    9.28 -typedef signed short        s16;
    9.29 -typedef unsigned short      u16;
    9.30 -typedef signed int          s32;
    9.31 -typedef unsigned int        u32;
    9.32 -#ifdef __i386__
    9.33 -typedef signed long long    s64;
    9.34 -typedef unsigned long long  u64;
    9.35 -#elif defined(__x86_64__)
    9.36 -typedef signed long         s64;
    9.37 -typedef unsigned long       u64;
    9.38 -#endif
    9.39 -
    9.40 -typedef unsigned int        size_t;
    9.41 -
    9.42 -/* FreeBSD compat types */
    9.43 -typedef unsigned char       u_char;
    9.44 -typedef unsigned int        u_int;
    9.45 -typedef unsigned long       u_long;
    9.46 -#ifdef __i386__
    9.47 -typedef long long           quad_t;
    9.48 -typedef unsigned long long  u_quad_t;
    9.49 -typedef unsigned int        uintptr_t;
    9.50 -#elif defined(__x86_64__)
    9.51 -typedef long                quad_t;
    9.52 -typedef unsigned long       u_quad_t;
    9.53 -typedef unsigned long       uintptr_t;
    9.54 -#endif
    9.55 -#endif /* _TYPES_H_ */
    10.1 --- a/extras/mini-os/hypervisor.c	Wed Jul 06 08:50:11 2005 +0000
    10.2 +++ b/extras/mini-os/hypervisor.c	Wed Jul 06 10:46:29 2005 +0000
    10.3 @@ -4,6 +4,7 @@
    10.4   * Communication to/from hypervisor.
    10.5   * 
    10.6   * Copyright (c) 2002-2003, K A Fraser
    10.7 + * Copyright (c) 2005, Grzegorz Milos, gm281@cam.ac.uk,Intel Research Cambridge
    10.8   * 
    10.9   * Permission is hereby granted, free of charge, to any person obtaining a copy
   10.10   * of this software and associated documentation files (the "Software"), to
   10.11 @@ -26,65 +27,69 @@
   10.12  
   10.13  #include <os.h>
   10.14  #include <hypervisor.h>
   10.15 +#include <events.h>
   10.16  
   10.17 -static unsigned long event_mask = 0;
   10.18 -static unsigned long ev_err_count;
   10.19 +#define active_evtchns(cpu,sh,idx)              \
   10.20 +    ((sh)->evtchn_pending[idx] &                \
   10.21 +     ~(sh)->evtchn_mask[idx])
   10.22  
   10.23  void do_hypervisor_callback(struct pt_regs *regs)
   10.24  {
   10.25 -    unsigned long events, flags;
   10.26 -    shared_info_t *shared = HYPERVISOR_shared_info;
   10.27 -
   10.28 -    do {
   10.29 -        /* Specialised local_irq_save(). */
   10.30 -        flags = test_and_clear_bit(EVENTS_MASTER_ENABLE_BIT, 
   10.31 -                                   &shared->events_mask);
   10.32 -        barrier();
   10.33 -
   10.34 -        events  = xchg(&shared->events, 0);
   10.35 -        events &= event_mask;
   10.36 +    u32 	       l1, l2;
   10.37 +    unsigned int   l1i, l2i, port;
   10.38 +    int            cpu = 0;
   10.39 +    shared_info_t *s = HYPERVISOR_shared_info;
   10.40 +    vcpu_info_t   *vcpu_info = &s->vcpu_data[cpu];
   10.41  
   10.42 -        /* 'events' now contains some pending events to handle. */
   10.43 -        __asm__ __volatile__ (
   10.44 -            "   push %1                            ;"
   10.45 -            "   sub  $4,%%esp                      ;"
   10.46 -            "   jmp  2f                            ;"
   10.47 -            "1: btrl %%eax,%0                      ;" /* clear bit     */
   10.48 -            "   mov  %%eax,(%%esp)                 ;"
   10.49 -            "   call do_event                      ;" /* do_event(event) */
   10.50 -            "2: bsfl %0,%%eax                      ;" /* %eax == bit # */
   10.51 -            "   jnz  1b                            ;"
   10.52 -            "   add  $8,%%esp                      ;"
   10.53 -            /* we use %ebx because it is callee-saved */
   10.54 -            : : "b" (events), "r" (regs)
   10.55 -            /* clobbered by callback function calls */
   10.56 -            : "eax", "ecx", "edx", "memory" ); 
   10.57 +    vcpu_info->evtchn_upcall_pending = 0;
   10.58 +    
   10.59 +    /* NB. No need for a barrier here -- XCHG is a barrier on x86. */
   10.60 +    l1 = xchg(&vcpu_info->evtchn_pending_sel, 0);
   10.61 +    while ( l1 != 0 )
   10.62 +    {
   10.63 +        l1i = __ffs(l1);
   10.64 +        l1 &= ~(1 << l1i);
   10.65 +        
   10.66 +        while ( (l2 = active_evtchns(cpu, s, l1i)) != 0 )
   10.67 +        {
   10.68 +            l2i = __ffs(l2);
   10.69 +            l2 &= ~(1 << l2i);
   10.70  
   10.71 -        /* Specialised local_irq_restore(). */
   10.72 -        if ( flags ) set_bit(EVENTS_MASTER_ENABLE_BIT, &shared->events_mask);
   10.73 -        barrier();
   10.74 +            port = (l1i << 5) + l2i;
   10.75 +			do_event(port, regs);
   10.76 +        }
   10.77      }
   10.78 -    while ( shared->events );
   10.79  }
   10.80  
   10.81 -void enable_hypervisor_event(unsigned int ev)
   10.82 +
   10.83 +inline void mask_evtchn(u32 port)
   10.84  {
   10.85 -    set_bit(ev, &event_mask);
   10.86 -    set_bit(ev, &HYPERVISOR_shared_info->events_mask);
   10.87 -    if ( test_bit(EVENTS_MASTER_ENABLE_BIT, 
   10.88 -                  &HYPERVISOR_shared_info->events_mask) )
   10.89 -        do_hypervisor_callback(NULL);
   10.90 +    shared_info_t *s = HYPERVISOR_shared_info;
   10.91 +    synch_set_bit(port, &s->evtchn_mask[0]);
   10.92  }
   10.93  
   10.94 -void disable_hypervisor_event(unsigned int ev)
   10.95 +inline void unmask_evtchn(u32 port)
   10.96  {
   10.97 -    clear_bit(ev, &event_mask);
   10.98 -    clear_bit(ev, &HYPERVISOR_shared_info->events_mask);
   10.99 +    shared_info_t *s = HYPERVISOR_shared_info;
  10.100 +    vcpu_info_t *vcpu_info = &s->vcpu_data[smp_processor_id()];
  10.101 +
  10.102 +    synch_clear_bit(port, &s->evtchn_mask[0]);
  10.103 +
  10.104 +    /*
  10.105 +     * The following is basically the equivalent of 'hw_resend_irq'. Just like
  10.106 +     * a real IO-APIC we 'lose the interrupt edge' if the channel is masked.
  10.107 +     */
  10.108 +    if (  synch_test_bit        (port,    &s->evtchn_pending[0]) && 
  10.109 +         !synch_test_and_set_bit(port>>5, &vcpu_info->evtchn_pending_sel) )
  10.110 +    {
  10.111 +        vcpu_info->evtchn_upcall_pending = 1;
  10.112 +        if ( !vcpu_info->evtchn_upcall_mask )
  10.113 +            force_evtchn_callback();
  10.114 +    }
  10.115  }
  10.116  
  10.117 -void ack_hypervisor_event(unsigned int ev)
  10.118 +inline void clear_evtchn(u32 port)
  10.119  {
  10.120 -    if ( !(event_mask & (1<<ev)) )
  10.121 -        atomic_inc((atomic_t *)&ev_err_count);
  10.122 -    set_bit(ev, &HYPERVISOR_shared_info->events_mask);
  10.123 +    shared_info_t *s = HYPERVISOR_shared_info;
  10.124 +    synch_clear_bit(port, &s->evtchn_pending[0]);
  10.125  }
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/extras/mini-os/include/events.h	Wed Jul 06 10:46:29 2005 +0000
    11.3 @@ -0,0 +1,44 @@
    11.4 +/* -*-  Mode:C; c-basic-offset:4; tab-width:4 -*-
    11.5 + ****************************************************************************
    11.6 + * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge
    11.7 + * (C) 2005 - Grzegorz Milos - Intel Reseach Cambridge
    11.8 + ****************************************************************************
    11.9 + *
   11.10 + *        File: events.h
   11.11 + *      Author: Rolf Neugebauer (neugebar@dcs.gla.ac.uk)
   11.12 + *     Changes: Grzegorz Milos (gm281@cam.ac.uk)
   11.13 + *              
   11.14 + *        Date: Jul 2003, changes Jun 2005
   11.15 + * 
   11.16 + * Environment: Xen Minimal OS
   11.17 + * Description: Deals with events on the event channels
   11.18 + *
   11.19 + ****************************************************************************
   11.20 + */
   11.21 +
   11.22 +#ifndef _EVENTS_H_
   11.23 +#define _EVENTS_H_
   11.24 +
   11.25 +#include<traps.h>
   11.26 +
   11.27 +#define NR_EVS 1024
   11.28 +
   11.29 +/* ev handler status */
   11.30 +#define EVS_INPROGRESS	1	/* Event handler active - do not enter! */
   11.31 +#define EVS_DISABLED	2	/* Event disabled - do not enter! */
   11.32 +#define EVS_PENDING	    4	/* Event pending - replay on enable */
   11.33 +#define EVS_REPLAY	    8	/* Event has been replayed but not acked yet */
   11.34 +
   11.35 +/* this represents a event handler. Chaining or sharing is not allowed */
   11.36 +typedef struct _ev_action_t {
   11.37 +	void (*handler)(int, struct pt_regs *);
   11.38 +    unsigned int status;		/* IRQ status */
   11.39 +    u32 count;
   11.40 +} ev_action_t;
   11.41 +
   11.42 +/* prototypes */
   11.43 +int do_event(u32 port, struct pt_regs *regs);
   11.44 +int bind_virq( u32 virq, void (*handler)(int, struct pt_regs *) );
   11.45 +void init_events(void);
   11.46 +
   11.47 +#endif /* _EVENTS_H_ */
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/extras/mini-os/include/hypervisor.h	Wed Jul 06 10:46:29 2005 +0000
    12.3 @@ -0,0 +1,357 @@
    12.4 +/******************************************************************************
    12.5 + * hypervisor.h
    12.6 + * 
    12.7 + * Hypervisor handling.
    12.8 + * 
    12.9 + * TODO - x86_64 broken!
   12.10 + *
   12.11 + * Copyright (c) 2002, K A Fraser
   12.12 + * Copyright (c) 2005, Grzegorz Milos
   12.13 + */
   12.14 +
   12.15 +#ifndef _HYPERVISOR_H_
   12.16 +#define _HYPERVISOR_H_
   12.17 +
   12.18 +#include <types.h>
   12.19 +
   12.20 +#include <xen/xen.h>
   12.21 +#include <xen/io/domain_controller.h>
   12.22 +
   12.23 +
   12.24 +
   12.25 +/*
   12.26 + * a placeholder for the start of day information passed up from the hypervisor
   12.27 + */
   12.28 +union start_info_union
   12.29 +{
   12.30 +    start_info_t start_info;
   12.31 +    char padding[512];
   12.32 +};
   12.33 +extern union start_info_union start_info_union;
   12.34 +#define start_info (start_info_union.start_info)
   12.35 +
   12.36 +
   12.37 +/* hypervisor.c */
   12.38 +//void do_hypervisor_callback(struct pt_regs *regs);
   12.39 +void mask_evtchn(u32 port);
   12.40 +void unmask_evtchn(u32 port);
   12.41 +void clear_evtchn(u32 port);
   12.42 +
   12.43 +/*
   12.44 + * Assembler stubs for hyper-calls.
   12.45 + */
   12.46 +
   12.47 +#ifdef __i386__
   12.48 +#define _a1 "b"
   12.49 +#define _a2 "c"
   12.50 +#define _a3 "d"
   12.51 +#define _a4 "S"
   12.52 +#else
   12.53 +#define _a1 "D"
   12.54 +#define _a2 "S"
   12.55 +#define _a3 "d"
   12.56 +#define _a4 "b"
   12.57 +#endif
   12.58 +
   12.59 +static __inline__ int HYPERVISOR_event_channel_op(
   12.60 +    void *op)
   12.61 +{
   12.62 +    int ret;
   12.63 +    unsigned long ignore;
   12.64 +    __asm__ __volatile__ (
   12.65 +        TRAP_INSTR
   12.66 +        : "=a" (ret), "=b" (ignore)
   12.67 +	: "0" (__HYPERVISOR_event_channel_op), "1" (op)
   12.68 +	: "memory" );
   12.69 +
   12.70 +    return ret;
   12.71 +}
   12.72 +
   12.73 +static __inline__ int HYPERVISOR_set_trap_table(trap_info_t *table)
   12.74 +{
   12.75 +    int ret;
   12.76 +    __asm__ __volatile__ (
   12.77 +        TRAP_INSTR
   12.78 +        : "=a" (ret) : "0" (__HYPERVISOR_set_trap_table),
   12.79 +        _a1 (table) : "memory" );
   12.80 +
   12.81 +    return ret;
   12.82 +}
   12.83 +
   12.84 +static __inline__ int HYPERVISOR_mmu_update(mmu_update_t *req, 
   12.85 +                                            int count, 
   12.86 +                                            int *success_count)
   12.87 +{
   12.88 +    int ret;
   12.89 +    __asm__ __volatile__ (
   12.90 +        TRAP_INSTR
   12.91 +        : "=a" (ret) : "0" (__HYPERVISOR_mmu_update), 
   12.92 +        _a1 (req), _a2 (count), _a3 (success_count)  : "memory" );
   12.93 +
   12.94 +    return ret;
   12.95 +}
   12.96 +
   12.97 +static __inline__ int HYPERVISOR_set_gdt(unsigned long *frame_list, int entries)
   12.98 +{
   12.99 +    int ret;
  12.100 +    __asm__ __volatile__ (
  12.101 +        TRAP_INSTR
  12.102 +        : "=a" (ret) : "0" (__HYPERVISOR_set_gdt), 
  12.103 +        _a1 (frame_list), _a2 (entries) : "memory" );
  12.104 +
  12.105 +
  12.106 +    return ret;
  12.107 +}
  12.108 +
  12.109 +static __inline__ int HYPERVISOR_stack_switch(unsigned long ss, unsigned long esp)
  12.110 +{
  12.111 +    int ret;
  12.112 +    __asm__ __volatile__ (
  12.113 +        TRAP_INSTR
  12.114 +        : "=a" (ret) : "0" (__HYPERVISOR_stack_switch),
  12.115 +        _a1 (ss), _a2 (esp) : "memory" );
  12.116 +
  12.117 +    return ret;
  12.118 +}
  12.119 +
  12.120 +#ifdef __i386__
  12.121 +static __inline__ int HYPERVISOR_set_callbacks(
  12.122 +    unsigned long event_selector, unsigned long event_address,
  12.123 +    unsigned long failsafe_selector, unsigned long failsafe_address)
  12.124 +{
  12.125 +    int ret;
  12.126 +    __asm__ __volatile__ (
  12.127 +        TRAP_INSTR
  12.128 +        : "=a" (ret) : "0" (__HYPERVISOR_set_callbacks),
  12.129 +        _a1 (event_selector), _a2 (event_address), 
  12.130 +        _a3 (failsafe_selector), _a4 (failsafe_address) : "memory" );
  12.131 +
  12.132 +    return ret;
  12.133 +}
  12.134 +#else
  12.135 +static __inline__ int HYPERVISOR_set_callbacks(
  12.136 +    unsigned long event_address,
  12.137 +    unsigned long failsafe_address,
  12.138 +    unsigned long syscall_address)
  12.139 +{
  12.140 +    int ret;
  12.141 +    __asm__ __volatile__ (
  12.142 +        TRAP_INSTR
  12.143 +        : "=a" (ret) : "0" (__HYPERVISOR_set_callbacks),
  12.144 +        _a1 (event_address), _a2 (failsafe_address), 
  12.145 +        _a3 (syscall_address) : "memory" );
  12.146 +
  12.147 +    return ret;
  12.148 +}
  12.149 +#endif
  12.150 +
  12.151 +static __inline__ int
  12.152 +HYPERVISOR_fpu_taskswitch(
  12.153 +    int set)
  12.154 +{
  12.155 +    int ret;
  12.156 +    unsigned long ign;
  12.157 +
  12.158 +    __asm__ __volatile__ (
  12.159 +        TRAP_INSTR
  12.160 +        : "=a" (ret), "=b" (ign)
  12.161 +        : "0" (__HYPERVISOR_fpu_taskswitch), "1" (set)
  12.162 +        : "memory" );
  12.163 +
  12.164 +    return ret;
  12.165 +}
  12.166 +
  12.167 +static __inline__ int HYPERVISOR_yield(void)
  12.168 +{
  12.169 +    int ret;
  12.170 +    __asm__ __volatile__ (
  12.171 +        TRAP_INSTR
  12.172 +        : "=a" (ret) : "0" (__HYPERVISOR_sched_op),
  12.173 +        _a1 (SCHEDOP_yield) : "memory" );
  12.174 +
  12.175 +    return ret;
  12.176 +}
  12.177 +
  12.178 +static __inline__ int HYPERVISOR_block(void)
  12.179 +{
  12.180 +    int ret;
  12.181 +    __asm__ __volatile__ (
  12.182 +        TRAP_INSTR
  12.183 +        : "=a" (ret) : "0" (__HYPERVISOR_sched_op),
  12.184 +        _a1 (SCHEDOP_block) : "memory" );
  12.185 +
  12.186 +    return ret;
  12.187 +}
  12.188 +
  12.189 +static __inline__ int HYPERVISOR_shutdown(void)
  12.190 +{
  12.191 +    int ret;
  12.192 +    __asm__ __volatile__ (
  12.193 +        TRAP_INSTR
  12.194 +        : "=a" (ret) : "0" (__HYPERVISOR_sched_op),
  12.195 +        _a1 (SCHEDOP_shutdown | (SHUTDOWN_poweroff << SCHEDOP_reasonshift))
  12.196 +        : "memory" );
  12.197 +
  12.198 +    return ret;
  12.199 +}
  12.200 +
  12.201 +static __inline__ int HYPERVISOR_reboot(void)
  12.202 +{
  12.203 +    int ret;
  12.204 +    __asm__ __volatile__ (
  12.205 +        TRAP_INSTR
  12.206 +        : "=a" (ret) : "0" (__HYPERVISOR_sched_op),
  12.207 +        _a1 (SCHEDOP_shutdown | (SHUTDOWN_reboot << SCHEDOP_reasonshift))
  12.208 +        : "memory" );
  12.209 +
  12.210 +    return ret;
  12.211 +}
  12.212 +
  12.213 +static __inline__ int HYPERVISOR_suspend(unsigned long srec)
  12.214 +{
  12.215 +    int ret;
  12.216 +    /* NB. On suspend, control software expects a suspend record in %esi. */
  12.217 +    __asm__ __volatile__ (
  12.218 +        TRAP_INSTR
  12.219 +        : "=a" (ret) : "0" (__HYPERVISOR_sched_op),
  12.220 +        _a1 (SCHEDOP_shutdown | (SHUTDOWN_suspend << SCHEDOP_reasonshift)), 
  12.221 +        "S" (srec) : "memory" );
  12.222 +
  12.223 +    return ret;
  12.224 +}
  12.225 +
  12.226 +#ifdef __i386__
  12.227 +static __inline__ long HYPERVISOR_set_timer_op( u64 timeout )
  12.228 +{
  12.229 +    int ret;
  12.230 +    unsigned long timeout_hi = (unsigned long)(timeout>>32);
  12.231 +    unsigned long timeout_lo = (unsigned long)timeout;
  12.232 +    unsigned long ign1, ign2;
  12.233 +
  12.234 +    __asm__ __volatile__ (
  12.235 +        TRAP_INSTR
  12.236 +        : "=a" (ret), "=b" (ign1), "=c" (ign2)
  12.237 +	: "0" (__HYPERVISOR_set_timer_op), "b" (timeout_lo), "c" (timeout_hi)
  12.238 +	: "memory");
  12.239 +
  12.240 +    return ret;
  12.241 +}
  12.242 +#else
  12.243 +static __inline__ long HYPERVISOR_set_timer_op( u64 timeout )
  12.244 +{
  12.245 +    int ret;
  12.246 +
  12.247 +    __asm__ __volatile__ (
  12.248 +        TRAP_INSTR
  12.249 +        : "=a" (ret)
  12.250 +	: "0" ((unsigned long)__HYPERVISOR_set_timer_op),
  12.251 +	  "D" (timeout)
  12.252 +	: __syscall_clobber );
  12.253 +
  12.254 +    return ret;
  12.255 +}
  12.256 +#endif
  12.257 +
  12.258 +
  12.259 +static __inline__ int HYPERVISOR_dom0_op(void *dom0_op)
  12.260 +{
  12.261 +    int ret;
  12.262 +    __asm__ __volatile__ (
  12.263 +        TRAP_INSTR
  12.264 +        : "=a" (ret) : "0" (__HYPERVISOR_dom0_op),
  12.265 +        _a1 (dom0_op) : "memory" );
  12.266 +
  12.267 +    return ret;
  12.268 +}
  12.269 +
  12.270 +static __inline__ int HYPERVISOR_set_debugreg(int reg, unsigned long value)
  12.271 +{
  12.272 +    int ret;
  12.273 +    __asm__ __volatile__ (
  12.274 +        TRAP_INSTR
  12.275 +        : "=a" (ret) : "0" (__HYPERVISOR_set_debugreg),
  12.276 +        _a1 (reg), _a2 (value) : "memory" );
  12.277 +
  12.278 +    return ret;
  12.279 +}
  12.280 +
  12.281 +static __inline__ unsigned long HYPERVISOR_get_debugreg(int reg)
  12.282 +{
  12.283 +    unsigned long ret;
  12.284 +    __asm__ __volatile__ (
  12.285 +        TRAP_INSTR
  12.286 +        : "=a" (ret) : "0" (__HYPERVISOR_get_debugreg),
  12.287 +        _a1 (reg) : "memory" );
  12.288 +
  12.289 +    return ret;
  12.290 +}
  12.291 +
  12.292 +static __inline__ int HYPERVISOR_update_descriptor(
  12.293 +    unsigned long pa, unsigned long word1, unsigned long word2)
  12.294 +{
  12.295 +    int ret;
  12.296 +    __asm__ __volatile__ (
  12.297 +        TRAP_INSTR
  12.298 +        : "=a" (ret) : "0" (__HYPERVISOR_update_descriptor), 
  12.299 +        _a1 (pa), _a2 (word1), _a3 (word2) : "memory" );
  12.300 +
  12.301 +    return ret;
  12.302 +}
  12.303 +
  12.304 +static __inline__ int HYPERVISOR_dom_mem_op(void *dom_mem_op)
  12.305 +{
  12.306 +    int ret;
  12.307 +    __asm__ __volatile__ (
  12.308 +        TRAP_INSTR
  12.309 +        : "=a" (ret) : "0" (__HYPERVISOR_dom_mem_op),
  12.310 +        _a1 (dom_mem_op) : "memory" );
  12.311 +
  12.312 +    return ret;
  12.313 +}
  12.314 +
  12.315 +static __inline__ int HYPERVISOR_multicall(void *call_list, int nr_calls)
  12.316 +{
  12.317 +    int ret;
  12.318 +    __asm__ __volatile__ (
  12.319 +        TRAP_INSTR
  12.320 +        : "=a" (ret) : "0" (__HYPERVISOR_multicall),
  12.321 +        _a1 (call_list), _a2 (nr_calls) : "memory" );
  12.322 +
  12.323 +    return ret;
  12.324 +}
  12.325 +
  12.326 +static __inline__ int HYPERVISOR_update_va_mapping(
  12.327 +    unsigned long page_nr, unsigned long new_val, unsigned long flags)
  12.328 +{
  12.329 +    int ret;
  12.330 +    __asm__ __volatile__ (
  12.331 +        TRAP_INSTR
  12.332 +        : "=a" (ret) : "0" (__HYPERVISOR_update_va_mapping), 
  12.333 +        _a1 (page_nr), _a2 (new_val), _a3 (flags) : "memory" );
  12.334 +
  12.335 +    return ret;
  12.336 +}
  12.337 +
  12.338 +static __inline__ int HYPERVISOR_xen_version(int cmd)
  12.339 +{
  12.340 +    int ret;
  12.341 +    __asm__ __volatile__ (
  12.342 +        TRAP_INSTR
  12.343 +        : "=a" (ret) : "0" (__HYPERVISOR_xen_version), 
  12.344 +        _a1 (cmd) : "memory" );
  12.345 +
  12.346 +    return ret;
  12.347 +}
  12.348 +
  12.349 +static __inline__ int HYPERVISOR_console_io(int cmd, int count, char *str)
  12.350 +{
  12.351 +    int ret;
  12.352 +    __asm__ __volatile__ (
  12.353 +        TRAP_INSTR
  12.354 +        : "=a" (ret) : "0" (__HYPERVISOR_console_io),
  12.355 +        _a1 (cmd), _a2 (count), _a3 (str) : "memory" );
  12.356 +
  12.357 +    return ret;
  12.358 +}
  12.359 +
  12.360 +#endif /* __HYPERVISOR_H__ */
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/extras/mini-os/include/lib.h	Wed Jul 06 10:46:29 2005 +0000
    13.3 @@ -0,0 +1,114 @@
    13.4 +/* -*-  Mode:C; c-basic-offset:4; tab-width:4 -*-
    13.5 + ****************************************************************************
    13.6 + * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge
    13.7 + ****************************************************************************
    13.8 + *
    13.9 + *        File: lib.h
   13.10 + *      Author: Rolf Neugebauer (neugebar@dcs.gla.ac.uk)
   13.11 + *     Changes: 
   13.12 + *              
   13.13 + *        Date: Aug 2003
   13.14 + * 
   13.15 + * Environment: Xen Minimal OS
   13.16 + * Description: Random useful library functions, contains some freebsd stuff
   13.17 + *
   13.18 + ****************************************************************************
   13.19 + * $Id: h-insert.h,v 1.4 2002/11/08 16:03:55 rn Exp $
   13.20 + ****************************************************************************
   13.21 + *
   13.22 + *-
   13.23 + * Copyright (c) 1991, 1993
   13.24 + *      The Regents of the University of California.  All rights reserved.
   13.25 + *
   13.26 + * Redistribution and use in source and binary forms, with or without
   13.27 + * modification, are permitted provided that the following conditions
   13.28 + * are met:
   13.29 + * 1. Redistributions of source code must retain the above copyright
   13.30 + *    notice, this list of conditions and the following disclaimer.
   13.31 + * 2. Redistributions in binary form must reproduce the above copyright
   13.32 + *    notice, this list of conditions and the following disclaimer in the
   13.33 + *    documentation and/or other materials provided with the distribution.
   13.34 + * 3. All advertising materials mentioning features or use of this software
   13.35 + *    must display the following acknowledgement:
   13.36 + *      This product includes software developed by the University of
   13.37 + *      California, Berkeley and its contributors.
   13.38 + * 4. Neither the name of the University nor the names of its contributors
   13.39 + *    may be used to endorse or promote products derived from this software
   13.40 + *    without specific prior written permission.
   13.41 + *
   13.42 + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   13.43 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   13.44 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   13.45 + * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   13.46 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   13.47 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   13.48 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   13.49 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   13.50 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   13.51 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   13.52 + * SUCH DAMAGE.
   13.53 + *
   13.54 + *      @(#)stdarg.h    8.1 (Berkeley) 6/10/93
   13.55 + * $FreeBSD: src/sys/i386/include/stdarg.h,v 1.10 1999/08/28 00:44:26 peter Exp $
   13.56 + */
   13.57 +
   13.58 +#ifndef _LIB_H_
   13.59 +#define _LIB_H_
   13.60 +
   13.61 +#include <stdarg.h>
   13.62 +
   13.63 +/* printing */
   13.64 +#define printk  printf
   13.65 +#define kprintf printf
   13.66 +int printf(const char *fmt, ...);
   13.67 +int vprintf(const char *fmt, va_list ap);
   13.68 +int sprintf(char *buf, const char *cfmt, ...);
   13.69 +int vsprintf(char *buf, const char *cfmt, va_list ap);
   13.70 +
   13.71 +/* string and memory manipulation */
   13.72 +int    memcmp(const void *cs, const void *ct, size_t count);
   13.73 +void  *memcpy(void *dest, const void *src, size_t count);
   13.74 +int    strncmp(const char *cs, const char *ct, size_t count);
   13.75 +int    strcmp(const char *cs, const char *ct);
   13.76 +char  *strcpy(char *dest, const char *src);
   13.77 +char  *strncpy(char *dest, const char *src, size_t count);
   13.78 +void  *memset(void *s,int c, size_t count);
   13.79 +size_t strnlen(const char *s, size_t count);
   13.80 +size_t strlen(const char *s);
   13.81 +char  *strchr(const char *s, int c);
   13.82 +char  *strstr(const char *s1, const char *s2);
   13.83 +
   13.84 +
   13.85 +/* dlmalloc functions */
   13.86 +struct mallinfo {
   13.87 +  int arena;    /* non-mmapped space allocated from system */
   13.88 +  int ordblks;  /* number of free chunks */
   13.89 +  int smblks;   /* number of fastbin blocks */
   13.90 +  int hblks;    /* number of mmapped regions */
   13.91 +  int hblkhd;   /* space in mmapped regions */
   13.92 +  int usmblks;  /* maximum total allocated space */
   13.93 +  int fsmblks;  /* space available in freed fastbin blocks */
   13.94 +  int uordblks; /* total allocated space */
   13.95 +  int fordblks; /* total free space */
   13.96 +  int keepcost; /* top-most, releasable (via malloc_trim) space */
   13.97 +};
   13.98 +
   13.99 +void *malloc(size_t n);
  13.100 +void *calloc(size_t n_elements, size_t element_size);
  13.101 +void  free(void* p);
  13.102 +void *realloc(void* p, size_t n);
  13.103 +void *memalign(size_t alignment, size_t n);
  13.104 +void *valloc(size_t n);
  13.105 +struct mallinfo mallinfo(void);
  13.106 +int  mallopt(int parameter_number, int parameter_value);
  13.107 +
  13.108 +void **independent_calloc(size_t n_elements, size_t size, void* chunks[]);
  13.109 +void **independent_comalloc(size_t n_elements, size_t sizes[], void* chunks[]);
  13.110 +void *pvalloc(size_t n);
  13.111 +void cfree(void* p);
  13.112 +int malloc_trim(size_t pad);
  13.113 +size_t malloc_usable_size(void* p);
  13.114 +void malloc_stats(void);
  13.115 +
  13.116 +
  13.117 +#endif /* _LIB_H_ */
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/extras/mini-os/include/mm.h	Wed Jul 06 10:46:29 2005 +0000
    14.3 @@ -0,0 +1,111 @@
    14.4 +/* -*-  Mode:C; c-basic-offset:4; tab-width:4 -*-
    14.5 + *
    14.6 + * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge
    14.7 + * Copyright (c) 2005, Keir A Fraser
    14.8 + *
    14.9 + * Permission is hereby granted, free of charge, to any person obtaining a copy
   14.10 + * of this software and associated documentation files (the "Software"), to
   14.11 + * deal in the Software without restriction, including without limitation the
   14.12 + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
   14.13 + * sell copies of the Software, and to permit persons to whom the Software is
   14.14 + * furnished to do so, subject to the following conditions:
   14.15 + * 
   14.16 + * The above copyright notice and this permission notice shall be included in
   14.17 + * all copies or substantial portions of the Software.
   14.18 + * 
   14.19 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
   14.20 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
   14.21 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
   14.22 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
   14.23 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
   14.24 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
   14.25 + * DEALINGS IN THE SOFTWARE.
   14.26 + */
   14.27 +
   14.28 +#ifndef _MM_H_
   14.29 +#define _MM_H_
   14.30 +
   14.31 +#ifdef __x86_64__
   14.32 +
   14.33 +#define L1_PAGETABLE_SHIFT      12
   14.34 +#define L2_PAGETABLE_SHIFT      21
   14.35 +#define L3_PAGETABLE_SHIFT      30
   14.36 +#define L4_PAGETABLE_SHIFT      39
   14.37 +
   14.38 +#define L1_PAGETABLE_ENTRIES    512
   14.39 +#define L2_PAGETABLE_ENTRIES    512
   14.40 +#define L3_PAGETABLE_ENTRIES    512
   14.41 +#define L4_PAGETABLE_ENTRIES    512
   14.42 +
   14.43 +/* These are page-table limitations. Current CPUs support only 40-bit phys. */
   14.44 +#define PADDR_BITS              52
   14.45 +#define VADDR_BITS              48
   14.46 +#define PADDR_MASK              ((1UL << PADDR_BITS)-1)
   14.47 +#define VADDR_MASK              ((1UL << VADDR_BITS)-1)
   14.48 +
   14.49 +#define pte_to_mfn(_pte) (((_pte) & (PADDR_MASK&PAGE_MASK)) >> PAGE_SHIFT)
   14.50 +
   14.51 +/* Given a virtual address, get an entry offset into a page table. */
   14.52 +#define l1_table_offset(_a) \
   14.53 +  (((_a) >> L1_PAGETABLE_SHIFT) & (L1_PAGETABLE_ENTRIES - 1))
   14.54 +#define l2_table_offset(_a) \
   14.55 +  (((_a) >> L2_PAGETABLE_SHIFT) & (L2_PAGETABLE_ENTRIES - 1))
   14.56 +#define l3_table_offset(_a) \
   14.57 +  (((_a) >> L3_PAGETABLE_SHIFT) & (L3_PAGETABLE_ENTRIES - 1))
   14.58 +#define l4_table_offset(_a) \
   14.59 +  (((_a) >> L4_PAGETABLE_SHIFT) & (L4_PAGETABLE_ENTRIES - 1))
   14.60 +#endif
   14.61 +
   14.62 +#define _PAGE_PRESENT  0x001UL
   14.63 +#define _PAGE_RW       0x002UL
   14.64 +#define _PAGE_USER     0x004UL
   14.65 +#define _PAGE_PWT      0x008UL
   14.66 +#define _PAGE_PCD      0x010UL
   14.67 +#define _PAGE_ACCESSED 0x020UL
   14.68 +#define _PAGE_DIRTY    0x040UL
   14.69 +#define _PAGE_PAT      0x080UL
   14.70 +#define _PAGE_PSE      0x080UL
   14.71 +#define _PAGE_GLOBAL   0x100UL
   14.72 +
   14.73 +#define PAGE_SHIFT      12
   14.74 +#define PAGE_SIZE       (1UL << PAGE_SHIFT)
   14.75 +#define PAGE_MASK       (~(PAGE_SIZE-1))
   14.76 +
   14.77 +#define PFN_UP(x)	(((x) + PAGE_SIZE-1) >> PAGE_SHIFT)
   14.78 +#define PFN_DOWN(x)	((x) >> PAGE_SHIFT)
   14.79 +#define PFN_PHYS(x)	((x) << PAGE_SHIFT)
   14.80 +
   14.81 +/* to align the pointer to the (next) page boundary */
   14.82 +#define PAGE_ALIGN(addr)        (((addr)+PAGE_SIZE-1)&PAGE_MASK)
   14.83 +
   14.84 +extern unsigned long *phys_to_machine_mapping;
   14.85 +#define pfn_to_mfn(_pfn) (phys_to_machine_mapping[(_pfn)])
   14.86 +#define mfn_to_pfn(_mfn) (machine_to_phys_mapping[(_mfn)])
   14.87 +static __inline__ unsigned long phys_to_machine(unsigned long phys)
   14.88 +{
   14.89 +    unsigned long machine = pfn_to_mfn(phys >> PAGE_SHIFT);
   14.90 +    machine = (machine << PAGE_SHIFT) | (phys & ~PAGE_MASK);
   14.91 +    return machine;
   14.92 +}
   14.93 +static __inline__ unsigned long machine_to_phys(unsigned long machine)
   14.94 +{
   14.95 +    unsigned long phys = mfn_to_pfn(machine >> PAGE_SHIFT);
   14.96 +    phys = (phys << PAGE_SHIFT) | (machine & ~PAGE_MASK);
   14.97 +    return phys;
   14.98 +}
   14.99 +
  14.100 +#ifdef __x86_64__
  14.101 +#define VIRT_START              0xFFFFFFFF00000000UL
  14.102 +#else
  14.103 +#define VIRT_START              0xC0000000UL
  14.104 +#endif
  14.105 +
  14.106 +#define to_phys(x)                 ((unsigned long)(x)-VIRT_START)
  14.107 +#define to_virt(x)                 ((void *)((unsigned long)(x)+VIRT_START))
  14.108 +#define __va to_virt
  14.109 +#define __pa to_phys
  14.110 +
  14.111 +void init_mm(void);
  14.112 +unsigned long alloc_pages(int order);
  14.113 +
  14.114 +#endif /* _MM_H_ */
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/extras/mini-os/include/os.h	Wed Jul 06 10:46:29 2005 +0000
    15.3 @@ -0,0 +1,334 @@
    15.4 +/******************************************************************************
    15.5 + * os.h
    15.6 + * 
    15.7 + * random collection of macros and definition
    15.8 + */
    15.9 +
   15.10 +#ifndef _OS_H_
   15.11 +#define _OS_H_
   15.12 +
   15.13 +#define NULL 0
   15.14 +
   15.15 +#if __GNUC__ == 2 && __GNUC_MINOR__ < 96
   15.16 +#define __builtin_expect(x, expected_value) (x)
   15.17 +#endif
   15.18 +#define unlikely(x)  __builtin_expect((x),0)
   15.19 +
   15.20 +#define smp_processor_id() 0
   15.21 +#define preempt_disable() ((void)0)
   15.22 +#define preempt_enable() ((void)0)
   15.23 +
   15.24 +#define force_evtchn_callback() ((void)HYPERVISOR_xen_version(0))
   15.25 +
   15.26 +#ifndef __ASSEMBLY__
   15.27 +#include <types.h>
   15.28 +#endif
   15.29 +#include <xen/xen.h>
   15.30 +
   15.31 +#define __KERNEL_CS  FLAT_KERNEL_CS
   15.32 +#define __KERNEL_DS  FLAT_KERNEL_DS
   15.33 +#define __KERNEL_SS  FLAT_KERNEL_SS
   15.34 +
   15.35 +#define TRAP_divide_error      0
   15.36 +#define TRAP_debug             1
   15.37 +#define TRAP_nmi               2
   15.38 +#define TRAP_int3              3
   15.39 +#define TRAP_overflow          4
   15.40 +#define TRAP_bounds            5
   15.41 +#define TRAP_invalid_op        6
   15.42 +#define TRAP_no_device         7
   15.43 +#define TRAP_double_fault      8
   15.44 +#define TRAP_copro_seg         9
   15.45 +#define TRAP_invalid_tss      10
   15.46 +#define TRAP_no_segment       11
   15.47 +#define TRAP_stack_error      12
   15.48 +#define TRAP_gp_fault         13
   15.49 +#define TRAP_page_fault       14
   15.50 +#define TRAP_spurious_int     15
   15.51 +#define TRAP_copro_error      16
   15.52 +#define TRAP_alignment_check  17
   15.53 +#define TRAP_machine_check    18
   15.54 +#define TRAP_simd_error       19
   15.55 +#define TRAP_deferred_nmi     31
   15.56 +
   15.57 +/* Everything below this point is not included by assembler (.S) files. */
   15.58 +#ifndef __ASSEMBLY__
   15.59 +
   15.60 +#define pt_regs xen_regs
   15.61 +
   15.62 +void trap_init(void);
   15.63 +
   15.64 +/* 
   15.65 + * The use of 'barrier' in the following reflects their use as local-lock
   15.66 + * operations. Reentrancy must be prevented (e.g., __cli()) /before/ following
   15.67 + * critical operations are executed. All critical operations must complete
   15.68 + * /before/ reentrancy is permitted (e.g., __sti()). Alpha architecture also
   15.69 + * includes these barriers, for example.
   15.70 + */
   15.71 +
   15.72 +#define __cli()								\
   15.73 +do {									\
   15.74 +	vcpu_info_t *_vcpu;						\
   15.75 +	preempt_disable();						\
   15.76 +	_vcpu = &HYPERVISOR_shared_info->vcpu_data[smp_processor_id()];	\
   15.77 +	_vcpu->evtchn_upcall_mask = 1;					\
   15.78 +	preempt_enable_no_resched();					\
   15.79 +	barrier();							\
   15.80 +} while (0)
   15.81 +
   15.82 +#define __sti()								\
   15.83 +do {									\
   15.84 +	vcpu_info_t *_vcpu;						\
   15.85 +	barrier();							\
   15.86 +	preempt_disable();						\
   15.87 +	_vcpu = &HYPERVISOR_shared_info->vcpu_data[smp_processor_id()];	\
   15.88 +	_vcpu->evtchn_upcall_mask = 0;					\
   15.89 +	barrier(); /* unmask then check (avoid races) */		\
   15.90 +	if ( unlikely(_vcpu->evtchn_upcall_pending) )			\
   15.91 +		force_evtchn_callback();				\
   15.92 +	preempt_enable();						\
   15.93 +} while (0)
   15.94 +
   15.95 +#define __save_flags(x)							\
   15.96 +do {									\
   15.97 +	vcpu_info_t *_vcpu;						\
   15.98 +	_vcpu = &HYPERVISOR_shared_info->vcpu_data[smp_processor_id()];	\
   15.99 +	(x) = _vcpu->evtchn_upcall_mask;				\
  15.100 +} while (0)
  15.101 +
  15.102 +#define __restore_flags(x)						\
  15.103 +do {									\
  15.104 +	vcpu_info_t *_vcpu;						\
  15.105 +	barrier();							\
  15.106 +	preempt_disable();						\
  15.107 +	_vcpu = &HYPERVISOR_shared_info->vcpu_data[smp_processor_id()];	\
  15.108 +	if ((_vcpu->evtchn_upcall_mask = (x)) == 0) {			\
  15.109 +		barrier(); /* unmask then check (avoid races) */	\
  15.110 +		if ( unlikely(_vcpu->evtchn_upcall_pending) )		\
  15.111 +			force_evtchn_callback();			\
  15.112 +		preempt_enable();					\
  15.113 +	} else								\
  15.114 +		preempt_enable_no_resched();				\
  15.115 +} while (0)
  15.116 +
  15.117 +#define safe_halt()		((void)0)
  15.118 +
  15.119 +#define __save_and_cli(x)						\
  15.120 +do {									\
  15.121 +	vcpu_info_t *_vcpu;						\
  15.122 +	preempt_disable();						\
  15.123 +	_vcpu = &HYPERVISOR_shared_info->vcpu_data[smp_processor_id()];	\
  15.124 +	(x) = _vcpu->evtchn_upcall_mask;				\
  15.125 +	_vcpu->evtchn_upcall_mask = 1;					\
  15.126 +	preempt_enable_no_resched();					\
  15.127 +	barrier();							\
  15.128 +} while (0)
  15.129 +
  15.130 +#define local_irq_save(x)	__save_and_cli(x)
  15.131 +#define local_irq_restore(x)	__restore_flags(x)
  15.132 +#define local_save_flags(x)	__save_flags(x)
  15.133 +#define local_irq_disable()	__cli()
  15.134 +#define local_irq_enable()	__sti()
  15.135 +
  15.136 +#define irqs_disabled()			\
  15.137 +    HYPERVISOR_shared_info->vcpu_data[smp_processor_id()].evtchn_upcall_mask
  15.138 +
  15.139 +/* This is a barrier for the compiler only, NOT the processor! */
  15.140 +#define barrier() __asm__ __volatile__("": : :"memory")
  15.141 +
  15.142 +#define LOCK_PREFIX ""
  15.143 +#define LOCK ""
  15.144 +#define ADDR (*(volatile long *) addr)
  15.145 +/*
  15.146 + * Make sure gcc doesn't try to be clever and move things around
  15.147 + * on us. We need to use _exactly_ the address the user gave us,
  15.148 + * not some alias that contains the same information.
  15.149 + */
  15.150 +typedef struct { volatile int counter; } atomic_t;
  15.151 +
  15.152 +
  15.153 +#define xchg(ptr,v) \
  15.154 +        ((__typeof__(*(ptr)))__xchg((unsigned long)(v),(ptr),sizeof(*(ptr))))
  15.155 +struct __xchg_dummy { unsigned long a[100]; };
  15.156 +#define __xg(x) ((volatile struct __xchg_dummy *)(x))
  15.157 +static __inline__ unsigned long __xchg(unsigned long x, volatile void * ptr,
  15.158 +                                   int size)
  15.159 +{
  15.160 +    switch (size) {
  15.161 +    case 1:
  15.162 +        __asm__ __volatile__("xchgb %b0,%1"
  15.163 +                             :"=q" (x)
  15.164 +                             :"m" (*__xg(ptr)), "0" (x)
  15.165 +                             :"memory");
  15.166 +        break;
  15.167 +    case 2:
  15.168 +        __asm__ __volatile__("xchgw %w0,%1"
  15.169 +                             :"=r" (x)
  15.170 +                             :"m" (*__xg(ptr)), "0" (x)
  15.171 +                             :"memory");
  15.172 +        break;
  15.173 +    case 4:
  15.174 +        __asm__ __volatile__("xchgl %0,%1"
  15.175 +                             :"=r" (x)
  15.176 +                             :"m" (*__xg(ptr)), "0" (x)
  15.177 +                             :"memory");
  15.178 +        break;
  15.179 +    }
  15.180 +    return x;
  15.181 +}
  15.182 +
  15.183 +/**
  15.184 + * test_and_clear_bit - Clear a bit and return its old value
  15.185 + * @nr: Bit to set
  15.186 + * @addr: Address to count from
  15.187 + *
  15.188 + * This operation is atomic and cannot be reordered.  
  15.189 + * It also implies a memory barrier.
  15.190 + */
  15.191 +static __inline__ int test_and_clear_bit(int nr, volatile void * addr)
  15.192 +{
  15.193 +        int oldbit;
  15.194 +
  15.195 +        __asm__ __volatile__( LOCK_PREFIX
  15.196 +                "btrl %2,%1\n\tsbbl %0,%0"
  15.197 +                :"=r" (oldbit),"=m" (ADDR)
  15.198 +                :"Ir" (nr) : "memory");
  15.199 +        return oldbit;
  15.200 +}
  15.201 +
  15.202 +static __inline__ int constant_test_bit(int nr, const volatile void * addr)
  15.203 +{
  15.204 +    return ((1UL << (nr & 31)) & (((const volatile unsigned int *) addr)[nr >> 5])) != 0;
  15.205 +}
  15.206 +
  15.207 +static __inline__ int variable_test_bit(int nr, volatile void * addr)
  15.208 +{
  15.209 +    int oldbit;
  15.210 +    
  15.211 +    __asm__ __volatile__(
  15.212 +        "btl %2,%1\n\tsbbl %0,%0"
  15.213 +        :"=r" (oldbit)
  15.214 +        :"m" (ADDR),"Ir" (nr));
  15.215 +    return oldbit;
  15.216 +}
  15.217 +
  15.218 +#define test_bit(nr,addr) \
  15.219 +(__builtin_constant_p(nr) ? \
  15.220 + constant_test_bit((nr),(addr)) : \
  15.221 + variable_test_bit((nr),(addr)))
  15.222 +
  15.223 +
  15.224 +/**
  15.225 + * set_bit - Atomically set a bit in memory
  15.226 + * @nr: the bit to set
  15.227 + * @addr: the address to start counting from
  15.228 + *
  15.229 + * This function is atomic and may not be reordered.  See __set_bit()
  15.230 + * if you do not require the atomic guarantees.
  15.231 + * Note that @nr may be almost arbitrarily large; this function is not
  15.232 + * restricted to acting on a single-word quantity.
  15.233 + */
  15.234 +static __inline__ void set_bit(int nr, volatile void * addr)
  15.235 +{
  15.236 +        __asm__ __volatile__( LOCK_PREFIX
  15.237 +                "btsl %1,%0"
  15.238 +                :"=m" (ADDR)
  15.239 +                :"Ir" (nr));
  15.240 +}
  15.241 +
  15.242 +/**
  15.243 + * clear_bit - Clears a bit in memory
  15.244 + * @nr: Bit to clear
  15.245 + * @addr: Address to start counting from
  15.246 + *
  15.247 + * clear_bit() is atomic and may not be reordered.  However, it does
  15.248 + * not contain a memory barrier, so if it is used for locking purposes,
  15.249 + * you should call smp_mb__before_clear_bit() and/or smp_mb__after_clear_bit()
  15.250 + * in order to ensure changes are visible on other processors.
  15.251 + */
  15.252 +static __inline__ void clear_bit(int nr, volatile void * addr)
  15.253 +{
  15.254 +        __asm__ __volatile__( LOCK_PREFIX
  15.255 +                "btrl %1,%0"
  15.256 +                :"=m" (ADDR)
  15.257 +                :"Ir" (nr));
  15.258 +}
  15.259 +
  15.260 +/**
  15.261 + * atomic_inc - increment atomic variable
  15.262 + * @v: pointer of type atomic_t
  15.263 + * 
  15.264 + * Atomically increments @v by 1.  Note that the guaranteed
  15.265 + * useful range of an atomic_t is only 24 bits.
  15.266 + */ 
  15.267 +static __inline__ void atomic_inc(atomic_t *v)
  15.268 +{
  15.269 +        __asm__ __volatile__(
  15.270 +                LOCK "incl %0"
  15.271 +                :"=m" (v->counter)
  15.272 +                :"m" (v->counter));
  15.273 +}
  15.274 +
  15.275 +
  15.276 +#define rdtscll(val) \
  15.277 +     __asm__ __volatile__("rdtsc" : "=A" (val))
  15.278 +
  15.279 +static __inline__ unsigned long __ffs(unsigned long word)
  15.280 +{
  15.281 +        __asm__("bsfl %1,%0"
  15.282 +                :"=r" (word)
  15.283 +                :"rm" (word));
  15.284 +        return word;
  15.285 +}
  15.286 +
  15.287 +#define ADDR (*(volatile long *) addr)
  15.288 +
  15.289 +static __inline__ void synch_set_bit(int nr, volatile void * addr)
  15.290 +{
  15.291 +    __asm__ __volatile__ ( 
  15.292 +        "lock btsl %1,%0"
  15.293 +        : "=m" (ADDR) : "Ir" (nr) : "memory" );
  15.294 +}
  15.295 +
  15.296 +static __inline__ void synch_clear_bit(int nr, volatile void * addr)
  15.297 +{
  15.298 +    __asm__ __volatile__ (
  15.299 +        "lock btrl %1,%0"
  15.300 +        : "=m" (ADDR) : "Ir" (nr) : "memory" );
  15.301 +}
  15.302 +
  15.303 +static __inline__ int synch_test_and_set_bit(int nr, volatile void * addr)
  15.304 +{
  15.305 +    int oldbit;
  15.306 +    __asm__ __volatile__ (
  15.307 +        "lock btsl %2,%1\n\tsbbl %0,%0"
  15.308 +        : "=r" (oldbit), "=m" (ADDR) : "Ir" (nr) : "memory");
  15.309 +    return oldbit;
  15.310 +}
  15.311 +
  15.312 +
  15.313 +static __inline__ int synch_const_test_bit(int nr, const volatile void * addr)
  15.314 +{
  15.315 +    return ((1UL << (nr & 31)) & 
  15.316 +            (((const volatile unsigned int *) addr)[nr >> 5])) != 0;
  15.317 +}
  15.318 +
  15.319 +static __inline__ int synch_var_test_bit(int nr, volatile void * addr)
  15.320 +{
  15.321 +    int oldbit;
  15.322 +    __asm__ __volatile__ (
  15.323 +        "btl %2,%1\n\tsbbl %0,%0"
  15.324 +        : "=r" (oldbit) : "m" (ADDR), "Ir" (nr) );
  15.325 +    return oldbit;
  15.326 +}
  15.327 +
  15.328 +#define synch_test_bit(nr,addr) \
  15.329 +(__builtin_constant_p(nr) ? \
  15.330 + synch_const_test_bit((nr),(addr)) : \
  15.331 + synch_var_test_bit((nr),(addr)))
  15.332 +#endif /* !__ASSEMBLY__ */
  15.333 +
  15.334 +#define rdtsc(low,high) \
  15.335 +     __asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high))
  15.336 +
  15.337 +#endif /* _OS_H_ */
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/extras/mini-os/include/time.h	Wed Jul 06 10:46:29 2005 +0000
    16.3 @@ -0,0 +1,57 @@
    16.4 +/* -*-  Mode:C; c-basic-offset:4; tab-width:4 -*-
    16.5 + ****************************************************************************
    16.6 + * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge
    16.7 + * (C) 2005 - Grzegorz Milos - Intel Research Cambridge
    16.8 + ****************************************************************************
    16.9 + *
   16.10 + *        File: time.h
   16.11 + *      Author: Rolf Neugebauer (neugebar@dcs.gla.ac.uk)
   16.12 + *     Changes: Grzegorz Milos (gm281@cam.ac.uk)
   16.13 + *              
   16.14 + *        Date: Jul 2003, changesJun 2005
   16.15 + * 
   16.16 + * Environment: Xen Minimal OS
   16.17 + * Description: Time and timer functions
   16.18 + *
   16.19 + ****************************************************************************
   16.20 + */
   16.21 +
   16.22 +#ifndef _TIME_H_
   16.23 +#define _TIME_H_
   16.24 +
   16.25 +/*
   16.26 + * System Time
   16.27 + * 64 bit value containing the nanoseconds elapsed since boot time.
   16.28 + * This value is adjusted by frequency drift.
   16.29 + * NOW() returns the current time.
   16.30 + * The other macros are for convenience to approximate short intervals
   16.31 + * of real time into system time 
   16.32 + */
   16.33 +typedef s64 s_time_t;
   16.34 +#define NOW()                   ((s_time_t)get_s_time())
   16.35 +#define SECONDS(_s)             (((s_time_t)(_s))  * 1000000000UL )
   16.36 +#define TENTHS(_ts)             (((s_time_t)(_ts)) * 100000000UL )
   16.37 +#define HUNDREDTHS(_hs)         (((s_time_t)(_hs)) * 10000000UL )
   16.38 +#define MILLISECS(_ms)          (((s_time_t)(_ms)) * 1000000UL )
   16.39 +#define MICROSECS(_us)          (((s_time_t)(_us)) * 1000UL )
   16.40 +#define Time_Max                ((s_time_t) 0x7fffffffffffffffLL)
   16.41 +#define FOREVER                 Time_Max
   16.42 +
   16.43 +
   16.44 +/* wall clock time  */
   16.45 +typedef long time_t;
   16.46 +typedef long suseconds_t;
   16.47 +struct timeval {
   16.48 +	time_t		tv_sec;		/* seconds */
   16.49 +	suseconds_t	tv_usec;	/* microseconds */
   16.50 +};
   16.51 +
   16.52 +
   16.53 +/* prototypes */
   16.54 +void     init_time(void);
   16.55 +s_time_t get_s_time(void);
   16.56 +s_time_t get_v_time(void);
   16.57 +void     gettimeofday(struct timeval *tv);
   16.58 +void     block(u32 millisecs);
   16.59 +
   16.60 +#endif /* _TIME_H_ */
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/extras/mini-os/include/traps.h	Wed Jul 06 10:46:29 2005 +0000
    17.3 @@ -0,0 +1,41 @@
    17.4 +/* 
    17.5 + ****************************************************************************
    17.6 + * (C) 2005 - Grzegorz Milos - Intel Reseach Cambridge
    17.7 + ****************************************************************************
    17.8 + *
    17.9 + *        File: traps.h
   17.10 + *      Author: Grzegorz Milos (gm281@cam.ac.uk)
   17.11 + *              
   17.12 + *        Date: Jun 2005
   17.13 + * 
   17.14 + * Environment: Xen Minimal OS
   17.15 + * Description: Deals with traps
   17.16 + *
   17.17 + ****************************************************************************
   17.18 + */
   17.19 +
   17.20 +#ifndef _TRAPS_H_
   17.21 +#define _TRAPS_H_
   17.22 +
   17.23 +struct pt_regs {
   17.24 +	long ebx;
   17.25 +	long ecx;
   17.26 +	long edx;
   17.27 +	long esi;
   17.28 +	long edi;
   17.29 +	long ebp;
   17.30 +	long eax;
   17.31 +	int  xds;
   17.32 +	int  xes;
   17.33 +	long orig_eax;
   17.34 +	long eip;
   17.35 +	int  xcs;
   17.36 +	long eflags;
   17.37 +	long esp;
   17.38 +	int  xss;
   17.39 +};
   17.40 +
   17.41 +
   17.42 +void dump_regs(struct pt_regs *regs);
   17.43 +
   17.44 +#endif /* _TRAPS_H_ */
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/extras/mini-os/include/types.h	Wed Jul 06 10:46:29 2005 +0000
    18.3 @@ -0,0 +1,52 @@
    18.4 +/* -*-  Mode:C; c-basic-offset:4; tab-width:4 -*-
    18.5 + ****************************************************************************
    18.6 + * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge
    18.7 + ****************************************************************************
    18.8 + *
    18.9 + *        File: types.h
   18.10 + *      Author: Rolf Neugebauer (neugebar@dcs.gla.ac.uk)
   18.11 + *     Changes: 
   18.12 + *              
   18.13 + *        Date: May 2003
   18.14 + * 
   18.15 + * Environment: Xen Minimal OS
   18.16 + * Description: a random collection of type definitions
   18.17 + *
   18.18 + ****************************************************************************
   18.19 + * $Id: h-insert.h,v 1.4 2002/11/08 16:03:55 rn Exp $
   18.20 + ****************************************************************************
   18.21 + */
   18.22 +
   18.23 +#ifndef _TYPES_H_
   18.24 +#define _TYPES_H_
   18.25 +
   18.26 +typedef signed char         s8;
   18.27 +typedef unsigned char       u8;
   18.28 +typedef signed short        s16;
   18.29 +typedef unsigned short      u16;
   18.30 +typedef signed int          s32;
   18.31 +typedef unsigned int        u32;
   18.32 +#ifdef __i386__
   18.33 +typedef signed long long    s64;
   18.34 +typedef unsigned long long  u64;
   18.35 +#elif defined(__x86_64__)
   18.36 +typedef signed long         s64;
   18.37 +typedef unsigned long       u64;
   18.38 +#endif
   18.39 +
   18.40 +typedef unsigned int        size_t;
   18.41 +
   18.42 +/* FreeBSD compat types */
   18.43 +typedef unsigned char       u_char;
   18.44 +typedef unsigned int        u_int;
   18.45 +typedef unsigned long       u_long;
   18.46 +#ifdef __i386__
   18.47 +typedef long long           quad_t;
   18.48 +typedef unsigned long long  u_quad_t;
   18.49 +typedef unsigned int        uintptr_t;
   18.50 +#elif defined(__x86_64__)
   18.51 +typedef long                quad_t;
   18.52 +typedef unsigned long       u_quad_t;
   18.53 +typedef unsigned long       uintptr_t;
   18.54 +#endif
   18.55 +#endif /* _TYPES_H_ */
    19.1 --- a/extras/mini-os/kernel.c	Wed Jul 06 08:50:11 2005 +0000
    19.2 +++ b/extras/mini-os/kernel.c	Wed Jul 06 10:46:29 2005 +0000
    19.3 @@ -5,6 +5,7 @@
    19.4   * from head.S.
    19.5   * 
    19.6   * Copyright (c) 2002-2003, K A Fraser & R Neugebauer
    19.7 + * Copyright (c) 2005, Grzegorz Milos, Intel Research Cambridge
    19.8   * 
    19.9   * Permission is hereby granted, free of charge, to any person obtaining a copy
   19.10   * of this software and associated documentation files (the "Software"), to
   19.11 @@ -56,10 +57,6 @@ char stack[8192];
   19.12  void hypervisor_callback(void);
   19.13  void failsafe_callback(void);
   19.14  
   19.15 -/* default event handlers */
   19.16 -static void exit_handler(int ev, struct pt_regs *regs);
   19.17 -static void debug_handler(int ev, struct pt_regs *regs);
   19.18 -
   19.19  extern char shared_info[PAGE_SIZE];
   19.20  
   19.21  static shared_info_t *map_shared_info(unsigned long pa)
   19.22 @@ -80,6 +77,7 @@ static shared_info_t *map_shared_info(un
   19.23  void start_kernel(start_info_t *si)
   19.24  {
   19.25      static char hello[] = "Bootstrapping...\n";
   19.26 +    int i;
   19.27      (void)HYPERVISOR_console_io(CONSOLEIO_write, strlen(hello), hello);
   19.28  
   19.29      /* Copy the start_info struct to a globally-accessible area. */
   19.30 @@ -126,28 +124,32 @@ void start_kernel(start_info_t *si)
   19.31      init_mm();
   19.32  
   19.33      /* set up events */
   19.34 -//    init_events();
   19.35 -
   19.36 -    /*
   19.37 -     * These need to be replaced with event-channel/control-interface
   19.38 -     * equivalents.
   19.39 -     */
   19.40 -#if 0
   19.41 -    /* Install some handlers. */
   19.42 -    add_ev_action(EV_DIE, &exit_handler);
   19.43 -    enable_ev_action(EV_DIE);
   19.44 -    enable_hypervisor_event(EV_DIE);
   19.45 -
   19.46 -    add_ev_action(EV_DEBUG, &debug_handler);
   19.47 -    enable_ev_action(EV_DEBUG);
   19.48 -    enable_hypervisor_event(EV_DEBUG);
   19.49 -#endif
   19.50 -
   19.51 +    init_events();
   19.52      /* init time and timers */
   19.53 -//    init_time();
   19.54 +    init_time();
   19.55  
   19.56      /* do nothing */
   19.57 -    for ( ; ; ) HYPERVISOR_yield();
   19.58 +    i = 0;
   19.59 +    for ( ; ; ) 
   19.60 +    {      
   19.61 +        if(i >= 1000)         
   19.62 +        {
   19.63 +            {
   19.64 +                unsigned long saved;
   19.65 +                __asm__ ("movl %%esp, %0"
   19.66 +                         :"=r"(saved)  /* y is output operand */
   19.67 +                            /* x is input operand */);
   19.68 +//                        :"a"); /* %eax is clobbered register */
   19.69 +                printk("ESP=0x%lx\n", saved);
   19.70 +            }
   19.71 +            
   19.72 +            printk("1000 bloks\n");
   19.73 +            i=0;            
   19.74 +        }
   19.75 +//        HYPERVISOR_yield();
   19.76 +        block(1);
   19.77 +        i++;
   19.78 +    }
   19.79  }
   19.80  
   19.81  
   19.82 @@ -163,13 +165,3 @@ void do_exit(void)
   19.83      printk("do_exit called!\n");
   19.84      for ( ;; ) HYPERVISOR_shutdown();
   19.85  }
   19.86 -static void exit_handler(int ev, struct pt_regs *regs) {
   19.87 -    do_exit();
   19.88 -}
   19.89 -
   19.90 -/*
   19.91 - * a debug handler to print out some state from the guest
   19.92 - */
   19.93 -static void debug_handler(int ev, struct pt_regs *regs) {
   19.94 -    dump_regs(regs);
   19.95 -}
    20.1 --- a/extras/mini-os/time.c	Wed Jul 06 08:50:11 2005 +0000
    20.2 +++ b/extras/mini-os/time.c	Wed Jul 06 10:46:29 2005 +0000
    20.3 @@ -2,10 +2,12 @@
    20.4   ****************************************************************************
    20.5   * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge
    20.6   * (C) 2002-2003 - Keir Fraser - University of Cambridge 
    20.7 + * (C) 2005 - Grzegorz Milos - Intel Research Cambridge
    20.8   ****************************************************************************
    20.9   *
   20.10   *        File: time.c
   20.11   *      Author: Rolf Neugebauer and Keir Fraser
   20.12 + *     Changes: Grzegorz Milos
   20.13   *
   20.14   * Description: Simple time and timer functions
   20.15   *
   20.16 @@ -30,6 +32,7 @@
   20.17  
   20.18  
   20.19  #include <os.h>
   20.20 +#include <traps.h>
   20.21  #include <types.h>
   20.22  #include <hypervisor.h>
   20.23  #include <events.h>
   20.24 @@ -40,9 +43,13 @@
   20.25   * Time functions
   20.26   *************************************************************************/
   20.27  
   20.28 -static unsigned int rdtsc_bitshift;
   20.29 -static u32 st_scale_f; /* convert ticks -> usecs */
   20.30 -static u32 st_scale_i; /* convert ticks -> usecs */
   20.31 +/* Cached *multiplier* to convert TSC counts to microseconds.
   20.32 + * (see the equation below).
   20.33 + * Equal to 2^32 * (1 / (clocks per usec) ).
   20.34 + * Initialized in time_init.
   20.35 + */
   20.36 +static unsigned long fast_gettimeoffset_quotient;
   20.37 +
   20.38  
   20.39  /* These are peridically updated in shared_info, and then copied here. */
   20.40  static u32 shadow_tsc_stamp;
   20.41 @@ -70,7 +77,7 @@ static void get_time_values_from_xen(voi
   20.42          rmb();
   20.43          shadow_tv.tv_sec    = HYPERVISOR_shared_info->wc_sec;
   20.44          shadow_tv.tv_usec   = HYPERVISOR_shared_info->wc_usec;
   20.45 -        shadow_tsc_stamp    = HYPERVISOR_shared_info->tsc_timestamp.tsc_bits;
   20.46 +        shadow_tsc_stamp    = (u32)HYPERVISOR_shared_info->tsc_timestamp;
   20.47          shadow_system_time  = HYPERVISOR_shared_info->system_time;
   20.48          rmb();
   20.49      }
   20.50 @@ -81,22 +88,33 @@ static void get_time_values_from_xen(voi
   20.51  #define TIME_VALUES_UP_TO_DATE \
   20.52      (shadow_time_version == HYPERVISOR_shared_info->time_version2)
   20.53  
   20.54 -
   20.55 -static __inline__ unsigned long get_time_delta_usecs(void)
   20.56 +static u32  get_time_delta_usecs(void)
   20.57  {
   20.58 -    s32      delta_tsc;
   20.59 -    u32      low;
   20.60 -    u64      delta, tsc;
   20.61 +	register unsigned long eax, edx;
   20.62  
   20.63 -    rdtscll(tsc);
   20.64 -    low = (u32)(tsc >> rdtsc_bitshift);
   20.65 -    delta_tsc = (s32)(low - shadow_tsc_stamp);
   20.66 -    if ( unlikely(delta_tsc < 0) ) delta_tsc = 0;
   20.67 -    delta = ((u64)delta_tsc * st_scale_f);
   20.68 -    delta >>= 32;
   20.69 -    delta += ((u64)delta_tsc * st_scale_i);
   20.70 +	/* Read the Time Stamp Counter */
   20.71  
   20.72 -    return (unsigned long)delta;
   20.73 +	rdtsc(eax,edx);
   20.74 +
   20.75 +	/* .. relative to previous jiffy (32 bits is enough) */
   20.76 +	eax -= shadow_tsc_stamp;
   20.77 +
   20.78 +	/*
   20.79 +	 * Time offset = (tsc_low delta) * fast_gettimeoffset_quotient
   20.80 +	 *             = (tsc_low delta) * (usecs_per_clock)
   20.81 +	 *             = (tsc_low delta) * (usecs_per_jiffy / clocks_per_jiffy)
   20.82 +	 *
   20.83 +	 * Using a mull instead of a divl saves up to 31 clock cycles
   20.84 +	 * in the critical path.
   20.85 +	 */
   20.86 +
   20.87 +	__asm__("mull %2"
   20.88 +		:"=a" (eax), "=d" (edx)
   20.89 +		:"rm" (fast_gettimeoffset_quotient),
   20.90 +		 "0" (eax));
   20.91 +
   20.92 +	/* our adjusted time offset in microseconds */
   20.93 +	return edx;
   20.94  }
   20.95  
   20.96  s64 get_s_time (void)
   20.97 @@ -139,6 +157,25 @@ void gettimeofday(struct timeval *tv)
   20.98      *tv = _tv;
   20.99  }
  20.100  
  20.101 +static void print_current_time(void)
  20.102 +{
  20.103 +    struct timeval tv;
  20.104 +
  20.105 +    get_time_values_from_xen();
  20.106 +
  20.107 +    gettimeofday(&tv);
  20.108 +    printk("T(s=%ld us=%ld)\n", tv.tv_sec, tv.tv_usec);
  20.109 +}
  20.110 +
  20.111 +void block(u32 millisecs)
  20.112 +{
  20.113 +    struct timeval tv;
  20.114 +    gettimeofday(&tv);
  20.115 +    //printk("tv.tv_sec=%ld, tv.tv_usec=%ld, shadow_system_time=%lld\n", tv.tv_sec, tv.tv_usec, shadow_system_time );
  20.116 +    HYPERVISOR_set_timer_op(get_s_time() + 1000000LL * (s64) millisecs);
  20.117 +    HYPERVISOR_block();
  20.118 +}
  20.119 +
  20.120  
  20.121  /*
  20.122   * Just a dummy 
  20.123 @@ -146,41 +183,38 @@ void gettimeofday(struct timeval *tv)
  20.124  static void timer_handler(int ev, struct pt_regs *regs)
  20.125  {
  20.126      static int i;
  20.127 -    struct timeval tv;
  20.128  
  20.129      get_time_values_from_xen();
  20.130  
  20.131      i++;
  20.132      if (i >= 1000) {
  20.133 -        gettimeofday(&tv);
  20.134 -        printf("T(s=%ld us=%ld)\n", tv.tv_sec, tv.tv_usec);
  20.135 +        print_current_time();
  20.136          i = 0;
  20.137      }
  20.138  }
  20.139  
  20.140  
  20.141 +
  20.142  void init_time(void)
  20.143  {
  20.144 -    u64         __cpu_khz, cpu_freq, scale;
  20.145 +    u64         __cpu_khz;
  20.146      unsigned long cpu_khz;
  20.147  
  20.148      __cpu_khz = HYPERVISOR_shared_info->cpu_freq;
  20.149 -    cpu_khz = (u32) (__cpu_khz/1000);
  20.150 -
  20.151 -    rdtsc_bitshift = HYPERVISOR_shared_info->tsc_timestamp.tsc_bitshift;
  20.152 -    cpu_freq       = HYPERVISOR_shared_info->cpu_freq;
  20.153  
  20.154 -    scale = 1000000LL << (32 + rdtsc_bitshift);
  20.155 -    scale /= cpu_freq;
  20.156 -
  20.157 -    st_scale_f = scale & 0xffffffff;
  20.158 -    st_scale_i = scale >> 32;
  20.159 +    cpu_khz = (u32) (__cpu_khz/1000);
  20.160  
  20.161      printk("Xen reported: %lu.%03lu MHz processor.\n", 
  20.162             cpu_khz / 1000, cpu_khz % 1000);
  20.163 +	/* (10^6 * 2^32) / cpu_hz = (10^3 * 2^32) / cpu_khz =
  20.164 +	   (2^32 * 1 / (clocks/us)) */
  20.165 +	{	
  20.166 +		unsigned long eax=0, edx=1000;
  20.167 +		__asm__("divl %2"
  20.168 +		    :"=a" (fast_gettimeoffset_quotient), "=d" (edx)
  20.169 +		    :"r" (cpu_khz),
  20.170 +		    "0" (eax), "1" (edx));
  20.171 +	}
  20.172  
  20.173 -    add_ev_action(EV_TIMER, &timer_handler);
  20.174 -    enable_ev_action(EV_TIMER);
  20.175 -    enable_hypervisor_event(EV_TIMER);
  20.176 -
  20.177 +    bind_virq(VIRQ_TIMER, &timer_handler);
  20.178  }
    21.1 --- a/extras/mini-os/traps.c	Wed Jul 06 08:50:11 2005 +0000
    21.2 +++ b/extras/mini-os/traps.c	Wed Jul 06 10:46:29 2005 +0000
    21.3 @@ -1,5 +1,6 @@
    21.4  
    21.5  #include <os.h>
    21.6 +#include <traps.h>
    21.7  #include <hypervisor.h>
    21.8  #include <mm.h>
    21.9  #include <lib.h>
   21.10 @@ -37,21 +38,22 @@ void dump_regs(struct pt_regs *regs)
   21.11  
   21.12  #ifdef __x86_64__
   21.13      esp = regs->rsp;
   21.14 -    ss  = regs->ss;
   21.15 +    ss  = regs->xss;
   21.16  #else
   21.17      esp = (unsigned long) (&regs->esp);
   21.18      ss = __KERNEL_DS;
   21.19 -    if (regs->cs & 2) {
   21.20 +    if (regs->xcs & 2) {
   21.21 +printk("CS is true, esp is %x\n", regs->esp);
   21.22          esp = regs->esp;
   21.23 -        ss = regs->ss & 0xffff;
   21.24 +        ss = regs->xss & 0xffff;
   21.25      }
   21.26  #endif
   21.27 -    printf("EIP:    %04x:[<%p>] %08x\n",
   21.28 -           0xffff & regs->cs , regs->eip, regs->error_code);
   21.29 +    printf("EIP:    %04x:[<%p>]\n",
   21.30 +           0xffff & regs->xcs , regs->eip);
   21.31      printf("EFLAGS: %p\n",regs->eflags);
   21.32 -    printf("eax: %p   ebx: %p   ecx: %p   edx: %p\n",
   21.33 +    printf("eax: %08lx   ebx: %08lx   ecx: %08lx   edx: %08lx\n",
   21.34             regs->eax, regs->ebx, regs->ecx, regs->edx);
   21.35 -    printf("esi: %p   edi: %p   ebp: %p   esp: %p\n",
   21.36 +    printf("esi: %08lx   edi: %08lx   ebp: %08lx   esp: %08lx\n",
   21.37             regs->esi, regs->edi, regs->ebp, esp);
   21.38  #ifdef __x86_64__
   21.39      printf("r8 : %p   r9 : %p   r10: %p   r11: %p\n",
   21.40 @@ -60,40 +62,28 @@ void dump_regs(struct pt_regs *regs)
   21.41             regs->r12, regs->r13, regs->r14, regs->r15);
   21.42  #endif
   21.43      printf("ds: %04x   es: %04x   ss: %04x\n",
   21.44 -           regs->ds & 0xffff, regs->es & 0xffff, ss);
   21.45 +           regs->xds & 0xffff, regs->xes & 0xffff, ss);
   21.46  }	
   21.47  
   21.48  
   21.49 -static __inline__ void dump_code(unsigned long eip)
   21.50 +static void do_trap(int trapnr, char *str, struct pt_regs * regs, unsigned long error_code)
   21.51  {
   21.52 -    unsigned char *ptr = (unsigned char *)eip;
   21.53 -    int x;
   21.54 -    
   21.55 -    printk("Bytes at eip: ");
   21.56 -    for ( x = -4; x < 5; x++ )
   21.57 -        printf("%02x ", ptr[x]);
   21.58 -    printk("\n");
   21.59 -}
   21.60 -
   21.61 -static void __inline__ do_trap(int trapnr, char *str,
   21.62 -                               struct pt_regs * regs)
   21.63 -{
   21.64 -    printk("FATAL:  Unhandled Trap %d (%s)\n", trapnr, str);
   21.65 +    printk("FATAL:  Unhandled Trap %d (%s), error code=0x%lx\n", trapnr, str, error_code);
   21.66 +    printk("Regs address %p\n", regs);
   21.67      dump_regs(regs);
   21.68 -    dump_code(regs->eip);
   21.69      do_exit();
   21.70  }
   21.71  
   21.72  #define DO_ERROR(trapnr, str, name) \
   21.73 -void do_##name(struct pt_regs * regs) \
   21.74 +void do_##name(struct pt_regs * regs, unsigned long error_code) \
   21.75  { \
   21.76 -	do_trap(trapnr, str, regs); \
   21.77 +	do_trap(trapnr, str, regs, error_code); \
   21.78  }
   21.79  
   21.80  #define DO_ERROR_INFO(trapnr, str, name, sicode, siaddr) \
   21.81 -void do_##name(struct pt_regs * regs) \
   21.82 +void do_##name(struct pt_regs * regs, unsigned long error_code) \
   21.83  { \
   21.84 -	do_trap(trapnr, str, regs); \
   21.85 +	do_trap(trapnr, str, regs, error_code); \
   21.86  }
   21.87  
   21.88  DO_ERROR_INFO( 0, "divide error", divide_error, FPE_INTDIV, regs->eip)
   21.89 @@ -109,13 +99,11 @@ DO_ERROR(12, "stack segment", stack_segm
   21.90  DO_ERROR_INFO(17, "alignment check", alignment_check, BUS_ADRALN, 0)
   21.91  DO_ERROR(18, "machine check", machine_check)
   21.92  
   21.93 -extern unsigned long virt_cr2;
   21.94 -void do_page_fault(struct pt_regs *regs)
   21.95 +void do_page_fault(struct pt_regs *regs, unsigned long error_code,
   21.96 +								                     unsigned long addr)
   21.97  {
   21.98 -    unsigned long addr = virt_cr2;
   21.99      printk("Page fault at linear address %p\n", addr);
  21.100      dump_regs(regs);
  21.101 -    dump_code(regs->eip);
  21.102  #ifdef __x86_64__
  21.103      {
  21.104          unsigned long *tab = (unsigned long *)start_info.pt_base;
  21.105 @@ -126,35 +114,33 @@ void do_page_fault(struct pt_regs *regs)
  21.106          page = tab[l4_table_offset(addr)];
  21.107          tab = __va(mfn_to_pfn(pte_to_mfn(page)) << PAGE_SHIFT);
  21.108          printk(" L4 = %p (%p)\n", page, tab);
  21.109 -        if ( !(page & _PAGE_PRESENT) )
  21.110 +        if ( !(page & AGERESENT) )
  21.111              goto out;
  21.112  
  21.113          page = tab[l3_table_offset(addr)];
  21.114          tab = __va(mfn_to_pfn(pte_to_mfn(page)) << PAGE_SHIFT);
  21.115          printk("  L3 = %p (%p)\n", page, tab);
  21.116 -        if ( !(page & _PAGE_PRESENT) )
  21.117 +        if ( !(page & AGERESENT) )
  21.118              goto out;
  21.119          
  21.120          page = tab[l2_table_offset(addr)];
  21.121          tab = __va(mfn_to_pfn(pte_to_mfn(page)) << PAGE_SHIFT);
  21.122          printk("   L2 = %p (%p) %s\n", page, tab,
  21.123 -               (page & _PAGE_PSE) ? "(2MB)" : "");
  21.124 -        if ( !(page & _PAGE_PRESENT) || (page & _PAGE_PSE) )
  21.125 +               (page & AGESE) ? "(2MB)" : "");
  21.126 +        if ( !(page & AGERESENT) || (page & AGESE) )
  21.127              goto out;
  21.128          
  21.129          page = tab[l1_table_offset(addr)];
  21.130          printk("    L1 = %p\n", page);
  21.131      }
  21.132  #endif
  21.133 - out:
  21.134      do_exit();
  21.135  }
  21.136  
  21.137 -void do_general_protection(struct pt_regs *regs)
  21.138 +void do_general_protection(struct pt_regs *regs, long error_code)
  21.139  {
  21.140 -    printk("GPF\n");
  21.141 +    printk("GPF %p, error_code=%lx\n", regs, error_code);
  21.142      dump_regs(regs);
  21.143 -    dump_code(regs->eip);
  21.144      do_exit();
  21.145  }
  21.146  
  21.147 @@ -172,7 +158,6 @@ void do_coprocessor_error(struct pt_regs
  21.148  {
  21.149      printk("Copro error\n");
  21.150      dump_regs(regs);
  21.151 -    dump_code(regs->eip);
  21.152      do_exit();
  21.153  }
  21.154  
  21.155 @@ -196,28 +181,25 @@ void do_spurious_interrupt_bug(struct pt
  21.156   * The 'privilege ring' field specifies the least-privileged ring that
  21.157   * can trap to that vector using a software-interrupt instruction (INT).
  21.158   */
  21.159 -#ifdef __x86_64__
  21.160 -#define _P 0,
  21.161 -#endif
  21.162  static trap_info_t trap_table[] = {
  21.163 -    {  0, 0, __KERNEL_CS, _P (unsigned long)divide_error                },
  21.164 -    {  1, 0, __KERNEL_CS, _P (unsigned long)debug                       },
  21.165 -    {  3, 3, __KERNEL_CS, _P (unsigned long)int3                        },
  21.166 -    {  4, 3, __KERNEL_CS, _P (unsigned long)overflow                    },
  21.167 -    {  5, 3, __KERNEL_CS, _P (unsigned long)bounds                      },
  21.168 -    {  6, 0, __KERNEL_CS, _P (unsigned long)invalid_op                  },
  21.169 -    {  7, 0, __KERNEL_CS, _P (unsigned long)device_not_available        },
  21.170 -    {  9, 0, __KERNEL_CS, _P (unsigned long)coprocessor_segment_overrun },
  21.171 -    { 10, 0, __KERNEL_CS, _P (unsigned long)invalid_TSS                 },
  21.172 -    { 11, 0, __KERNEL_CS, _P (unsigned long)segment_not_present         },
  21.173 -    { 12, 0, __KERNEL_CS, _P (unsigned long)stack_segment               },
  21.174 -    { 13, 0, __KERNEL_CS, _P (unsigned long)general_protection          },
  21.175 -    { 14, 0, __KERNEL_CS, _P (unsigned long)page_fault                  },
  21.176 -    { 15, 0, __KERNEL_CS, _P (unsigned long)spurious_interrupt_bug      },
  21.177 -    { 16, 0, __KERNEL_CS, _P (unsigned long)coprocessor_error           },
  21.178 -    { 17, 0, __KERNEL_CS, _P (unsigned long)alignment_check             },
  21.179 -    { 18, 0, __KERNEL_CS, _P (unsigned long)machine_check               },
  21.180 -    { 19, 0, __KERNEL_CS, _P (unsigned long)simd_coprocessor_error      },
  21.181 +    {  0, 0, __KERNEL_CS, (unsigned long)divide_error                },
  21.182 +    {  1, 0, __KERNEL_CS, (unsigned long)debug                       },
  21.183 +    {  3, 3, __KERNEL_CS, (unsigned long)int3                        },
  21.184 +    {  4, 3, __KERNEL_CS, (unsigned long)overflow                    },
  21.185 +    {  5, 3, __KERNEL_CS, (unsigned long)bounds                      },
  21.186 +    {  6, 0, __KERNEL_CS, (unsigned long)invalid_op                  },
  21.187 +    {  7, 0, __KERNEL_CS, (unsigned long)device_not_available        },
  21.188 +    {  9, 0, __KERNEL_CS, (unsigned long)coprocessor_segment_overrun },
  21.189 +    { 10, 0, __KERNEL_CS, (unsigned long)invalid_TSS                 },
  21.190 +    { 11, 0, __KERNEL_CS, (unsigned long)segment_not_present         },
  21.191 +    { 12, 0, __KERNEL_CS, (unsigned long)stack_segment               },
  21.192 +    { 13, 0, __KERNEL_CS, (unsigned long)general_protection          },
  21.193 +    { 14, 0, __KERNEL_CS, (unsigned long)page_fault                  },
  21.194 +    { 15, 0, __KERNEL_CS, (unsigned long)spurious_interrupt_bug      },
  21.195 +    { 16, 0, __KERNEL_CS, (unsigned long)coprocessor_error           },
  21.196 +    { 17, 0, __KERNEL_CS, (unsigned long)alignment_check             },
  21.197 +    { 18, 0, __KERNEL_CS, (unsigned long)machine_check               },
  21.198 +    { 19, 0, __KERNEL_CS, (unsigned long)simd_coprocessor_error      },
  21.199      {  0, 0,           0, 0                           }
  21.200  };
  21.201      
  21.202 @@ -227,3 +209,4 @@ void trap_init(void)
  21.203  {
  21.204      HYPERVISOR_set_trap_table(trap_table);    
  21.205  }
  21.206 +
    22.1 --- a/extras/mini-os/x86_32.S	Wed Jul 06 08:50:11 2005 +0000
    22.2 +++ b/extras/mini-os/x86_32.S	Wed Jul 06 10:46:29 2005 +0000
    22.3 @@ -1,4 +1,6 @@
    22.4  #include <os.h>
    22.5 +#include <xen/arch-x86_32.h>
    22.6 +
    22.7  
    22.8  .section __xen_guest
    22.9          .asciz  "XEN_VER=3.0,LOADER=generic,PT_MODE_WRITABLE"
   22.10 @@ -21,6 +23,7 @@ stack_start:
   22.11  shared_info:
   22.12          .org 0x2000
   22.13          
   22.14 +
   22.15  ES		= 0x20
   22.16  ORIG_EAX	= 0x24
   22.17  EIP		= 0x28
   22.18 @@ -62,6 +65,31 @@ ENTRY(divide_error)
   22.19  do_exception:
   22.20  	pushl %ds
   22.21  	pushl %eax
   22.22 +	xorl %eax, %eax
   22.23 +	pushl %ebp
   22.24 +	pushl %edi
   22.25 +	pushl %esi
   22.26 +	pushl %edx
   22.27 +	decl %eax			# eax = -1
   22.28 +	pushl %ecx
   22.29 +	pushl %ebx
   22.30 +	cld
   22.31 +	movl %es, %ecx
   22.32 +	movl ES(%esp), %edi		# get the function address
   22.33 +	movl ORIG_EAX(%esp), %edx	# get the error code
   22.34 +	movl %eax, ORIG_EAX(%esp)
   22.35 +	movl %ecx, ES(%esp)
   22.36 +	movl $(__KERNEL_DS), %ecx
   22.37 +	movl %ecx, %ds
   22.38 +	movl %ecx, %es
   22.39 +	movl %esp,%eax			# pt_regs pointer
   22.40 +    pushl %edx
   22.41 +    pushl %eax
   22.42 +	call *%edi
   22.43 +    addl $8,%esp
   22.44 +    
   22.45 +/*    pushl %ds
   22.46 +	pushl %eax
   22.47  	xorl %eax,%eax
   22.48  	pushl %ebp
   22.49  	pushl %edi
   22.50 @@ -83,7 +111,7 @@ do_exception:
   22.51  	movl %edx,%ds
   22.52  	movl %edx,%es
   22.53  	call *%edi
   22.54 -	addl $8,%esp
   22.55 +	addl $8,%esp  */
   22.56  
   22.57          
   22.58  ret_from_exception:
   22.59 @@ -112,19 +140,19 @@ ENTRY(hypervisor_callback)
   22.60          cmpl $ecrit,%eax
   22.61          jb   critical_region_fixup
   22.62  11:     push %esp
   22.63 -#        call do_hypervisor_callback
   22.64 +        call do_hypervisor_callback
   22.65          add  $4,%esp
   22.66          movl HYPERVISOR_shared_info,%esi
   22.67          xorl %eax,%eax
   22.68          movb CS(%esp),%cl
   22.69      	test $2,%cl          # slow return to ring 2 or 3
   22.70          jne  safesti
   22.71 -safesti:btsl $31,4(%esi)     # reenable event callbacks
   22.72 +safesti:movb $0,1(%esi)     # reenable event callbacks
   22.73  scrit:  /**** START OF CRITICAL REGION ****/
   22.74 -        cmpl %eax,(%esi)
   22.75 -        jne  14f              # process more events if necessary...
   22.76 +        testb $0xFF,(%esi)
   22.77 +        jnz  14f              # process more events if necessary...
   22.78          RESTORE_ALL
   22.79 -14:     btrl %eax,4(%esi)
   22.80 +14:     movb $1,1(%esi)
   22.81          jmp  11b
   22.82  ecrit:  /**** END OF CRITICAL REGION ****/
   22.83  # [How we do the fixup]. We want to merge the current stack frame with the
   22.84 @@ -153,7 +181,7 @@ 16:     movl %edi,%esp        # final %e
   22.85          jmp  11b
   22.86           
   22.87  critical_fixup_table:        
   22.88 -        .byte 0x00,0x00                       # cmpl %eax,(%esi)
   22.89 +        .byte 0x00,0x00,0x00                  # testb $0xff,(%esi)
   22.90          .byte 0x00,0x00                       # jne  14f
   22.91          .byte 0x00                            # pop  %ebx
   22.92          .byte 0x04                            # pop  %ecx
   22.93 @@ -166,7 +194,7 @@ critical_fixup_table:
   22.94          .byte 0x20                            # pop  %es
   22.95          .byte 0x24,0x24,0x24                  # add  $4,%esp
   22.96          .byte 0x28                            # iret
   22.97 -        .byte 0x00,0x00,0x00,0x00,0x00        # btrl $31,4(%esi)
   22.98 +        .byte 0x00,0x00,0x00,0x00             # movb $1,1(%esi)
   22.99          .byte 0x00,0x00                       # jmp  11b
  22.100         
  22.101  # Hypervisor uses this for application faults while it executes.
  22.102 @@ -220,10 +248,6 @@ ENTRY(coprocessor_segment_overrun)
  22.103  	pushl $do_coprocessor_segment_overrun
  22.104  	jmp do_exception
  22.105  
  22.106 -ENTRY(double_fault)
  22.107 -	pushl $do_double_fault
  22.108 -	jmp do_exception
  22.109 -
  22.110  ENTRY(invalid_TSS)
  22.111  	pushl $do_invalid_TSS
  22.112  	jmp do_exception
  22.113 @@ -246,32 +270,30 @@ ENTRY(alignment_check)
  22.114  
  22.115  # This handler is special, because it gets an extra value on its stack,
  22.116  # which is the linear faulting address.
  22.117 +# fastcall register usage:  %eax = pt_regs, %edx = error code,
  22.118 +#			    %ecx = fault address
  22.119  ENTRY(page_fault)
  22.120  	pushl %ds
  22.121  	pushl %eax
  22.122 -	xorl %eax,%eax
  22.123 +	xorl %eax, %eax
  22.124  	pushl %ebp
  22.125  	pushl %edi
  22.126  	pushl %esi
  22.127  	pushl %edx
  22.128 -	decl %eax			# eax = -1
  22.129 +	decl %eax			/* eax = -1 */
  22.130  	pushl %ecx
  22.131  	pushl %ebx
  22.132  	cld
  22.133 -	movl %es,%ecx
  22.134 -	movl ORIG_EAX(%esp), %esi	# get the error code
  22.135 -	movl ES(%esp), %edi		# get the faulting address
  22.136 +	movl %es,%edi
  22.137 +	movl ES(%esp), %ecx		/* get the faulting address */
  22.138 +	movl ORIG_EAX(%esp), %edx	/* get the error code */
  22.139  	movl %eax, ORIG_EAX(%esp)
  22.140 -	movl %ecx, ES(%esp)
  22.141 -	movl %esp,%edx
  22.142 -        pushl %edi                      # push the faulting address
  22.143 -	pushl %esi			# push the error code
  22.144 -	pushl %edx			# push the pt_regs pointer
  22.145 -	movl $(__KERNEL_DS),%edx
  22.146 -	movl %edx,%ds
  22.147 -	movl %edx,%es
  22.148 +	movl %edi, ES(%esp)
  22.149 +	movl $(__KERNEL_DS),%eax
  22.150 +	movl %eax, %ds
  22.151 +	movl %eax, %es
  22.152 +	movl %esp,%eax			/* pt_regs pointer */
  22.153  	call do_page_fault
  22.154 -	addl $12,%esp
  22.155  	jmp ret_from_exception
  22.156  
  22.157  ENTRY(machine_check)