ia64/xen-unstable

changeset 1793:726a6efbd601

bitkeeper revision 1.1089 (40f56f24SZs3MuUGeXcTUoYhNLto6g)

Merge scramble.cl.cam.ac.uk:/auto/groups/xeno/BK/xeno.bk
into scramble.cl.cam.ac.uk:/local/scratch/kaf24/xeno
author kaf24@scramble.cl.cam.ac.uk
date Wed Jul 14 17:36:36 2004 +0000 (2004-07-14)
parents b0c6d5d450ad f48ee6e94073
children a427ad2ca16c 04e543701c68
files .rootkeys README.CD docs/HOWTOs/Xen-HOWTO xen/arch/x86/boot/x86_32.S xen/arch/x86/boot/x86_64.S xen/arch/x86/x86_32/mm.c xen/common/kernel.c xen/include/asm-x86/config.h xen/include/asm-x86/page.h xen/include/asm-x86/x86_64/page.h
line diff
     1.1 --- a/.rootkeys	Wed Jul 14 17:17:52 2004 +0000
     1.2 +++ b/.rootkeys	Wed Jul 14 17:36:36 2004 +0000
     1.3 @@ -586,7 +586,6 @@ 3ddb79c3M2n1ROZH6xk3HbyN4CPDqg xen/inclu
     1.4  404f1b9ceJeGVaPNIENm2FkK0AgEOQ xen/include/asm-x86/x86_64/current.h
     1.5  404f1b9fl6AQ_a-T1TDK3fuwTPXmHw xen/include/asm-x86/x86_64/desc.h
     1.6  404f1badfXZJZ2sU8sh9PS2EZvd19Q xen/include/asm-x86/x86_64/ldt.h
     1.7 -404f1bb1LSCqrMDSfRAti5NdMQPJBQ xen/include/asm-x86/x86_64/page.h
     1.8  404f1bb86rAXB3aLS1vYdcqpJiEcyg xen/include/asm-x86/x86_64/ptrace.h
     1.9  40e1966azOJZfNI6Ilthe6Q-T3Hewg xen/include/asm-x86/x86_64/string.h
    1.10  404f1bc4tWkB9Qr8RkKtZGW5eMQzhw xen/include/asm-x86/x86_64/uaccess.h
     2.1 --- a/README.CD	Wed Jul 14 17:17:52 2004 +0000
     2.2 +++ b/README.CD	Wed Jul 14 17:36:36 2004 +0000
     2.3 @@ -305,7 +305,7 @@ that may be able to help diagnose proble
     2.4                    shared by two subsystems (eg. console and
     2.5                    debugger). Sharing is controlled by MSB of each
     2.6                    transmitted/received character.
     2.7 - [NB. Default for this option is 'com1,tty']
     2.8 + [NB. Default for this option is 'com1,vga']
     2.9  
    2.10   conswitch=<switch-char><auto-switch-char>
    2.11                    Specify how to switch serial-console input between
     3.1 --- a/docs/HOWTOs/Xen-HOWTO	Wed Jul 14 17:17:52 2004 +0000
     3.2 +++ b/docs/HOWTOs/Xen-HOWTO	Wed Jul 14 17:36:36 2004 +0000
     3.3 @@ -251,7 +251,7 @@ The following is a list of command line 
     3.4                    shared by two subsystems (eg. console and
     3.5                    debugger). Sharing is controlled by MSB of each
     3.6                    transmitted/received character.
     3.7 - [NB. Default for this option is 'com1,tty']
     3.8 + [NB. Default for this option is 'com1,vga']
     3.9  
    3.10   conswitch=<switch-char><auto-switch-char>
    3.11                    Specify how to switch serial-console input between
     4.1 --- a/xen/arch/x86/boot/x86_32.S	Wed Jul 14 17:17:52 2004 +0000
     4.2 +++ b/xen/arch/x86/boot/x86_32.S	Wed Jul 14 17:36:36 2004 +0000
     4.3 @@ -20,9 +20,15 @@ ENTRY(start)
     4.4  	.long	-0x1BADB004
     4.5          
     4.6  bad_cpu_msg:
     4.7 -        .asciz "Bad CPU: we need at least a P6-compatible core."
     4.8 +        .asciz "ERR: Not a P6-compatible CPU!"
     4.9 +not_multiboot_msg:
    4.10 +        .asciz "ERR: Not a Multiboot bootloader!"
    4.11  bad_cpu:
    4.12          mov     $SYMBOL_NAME(bad_cpu_msg)-__PAGE_OFFSET,%esi
    4.13 +        jmp     print_err
    4.14 +not_multiboot:
    4.15 +        mov     $SYMBOL_NAME(not_multiboot_msg)-__PAGE_OFFSET,%esi
    4.16 +print_err:
    4.17          mov     $0xB8000,%edi  # VGA framebuffer
    4.18  1:      mov     (%esi),%bl
    4.19          test    %bl,%bl        # Terminate on '\0' sentinel
    4.20 @@ -79,9 +85,13 @@ 1:      lss     stack_start-__PAGE_OFFSE
    4.21          cmp     $(SECONDARY_CPU_FLAG),%ebx
    4.22          je      start_paging
    4.23                  
    4.24 +        /* Check for Multiboot bootloader */
    4.25 +        cmp     $0x2BADB002,%eax
    4.26 +        jne     not_multiboot
    4.27 +
    4.28 +        /* Save the Multiboot info structure for later use. */
    4.29  	add     $__PAGE_OFFSET,%ebx
    4.30 -        push    %ebx /* Multiboot info struct */
    4.31 -        push    %eax /* Multiboot magic value */
    4.32 +        push    %ebx
    4.33  
    4.34          /* Initialize BSS (no nasty surprises!) */
    4.35          mov     $__bss_start-__PAGE_OFFSET,%edi
     5.1 --- a/xen/arch/x86/boot/x86_64.S	Wed Jul 14 17:17:52 2004 +0000
     5.2 +++ b/xen/arch/x86/boot/x86_64.S	Wed Jul 14 17:36:36 2004 +0000
     5.3 @@ -21,9 +21,15 @@ ENTRY(start)
     5.4          .long   -0x1BADB004
     5.5  
     5.6          .org    0x010
     5.7 -        .asciz "Bad CPU: does not support 64-bit (long) mode."
     5.8 +        .asciz "ERR: Not a 64-bit CPU!"
     5.9 +        .org    0x028
    5.10 +        .asciz "ERR: Not a Multiboot bootloader!"
    5.11  bad_cpu:
    5.12          mov     $0x100010,%esi # Error message
    5.13 +        jmp     print_err
    5.14 +not_multiboot:
    5.15 +        mov     $0x100028,%esi # Error message
    5.16 +print_err:
    5.17          mov     $0xB8000,%edi  # VGA framebuffer
    5.18  1:      mov     (%esi),%bl
    5.19          test    %bl,%bl        # Terminate on '\0' sentinel
    5.20 @@ -50,6 +56,16 @@ 3:      in      %dx,%al
    5.21          mov     %ecx,%ds
    5.22          mov     %ecx,%es
    5.23  
    5.24 +        /* Check for Multiboot bootloader */
    5.25 +        cmp     $(SECONDARY_CPU_FLAG),%ebx
    5.26 +        je      skip_multiboot_check
    5.27 +        cmp     $0x2BADB002,%eax
    5.28 +        jne     not_multiboot
    5.29 +skip_multiboot_check:
    5.30 +        
    5.31 +        /* Save the Multiboot info structure for later use. */
    5.32 +        mov     %ebx,0x1001e0
    5.33 +
    5.34          /* We begin by interrogating the CPU for the presence of long mode. */
    5.35          mov     $0x80000000,%eax
    5.36          cpuid
    5.37 @@ -67,9 +83,6 @@ 3:      in      %dx,%al
    5.38          mov     $0x20,%ecx # X86_CR4_PAE
    5.39          mov     %ecx,%cr4
    5.40  
    5.41 -        mov     %ebx,0x1001e0 /* Multiboot info struct */
    5.42 -        mov     %eax,0x1001e4 /* Multiboot magic value */
    5.43 -
    5.44          /* Load pagetable base register. */
    5.45          mov     $0x101000,%eax   /* idle_pg_table */
    5.46          mov     %eax,%cr3
    5.47 @@ -138,14 +151,11 @@ 1:      mov     %eax,(%rdi)
    5.48          add     $8,%rdi
    5.49          loop    1b
    5.50  
    5.51 -        mov     0x1001e0,%eax /* Multiboot info struct */
    5.52 -        lea     start(%rip),%rbx
    5.53 -        sub     $0x100000,%rbx
    5.54 -        add     %rbx,%rax
    5.55 -        push    %rax
    5.56 -        mov     0x1001e4,%eax /* Multiboot magic value */
    5.57 -        push    %rax
    5.58 -        
    5.59 +        /* Pass off the Multiboot info structure to C land. */
    5.60 +        mov     0x1001e0,%edi
    5.61 +        lea     start(%rip),%rax
    5.62 +        sub     $0x100000,%rax
    5.63 +        add     %rax,%rdi
    5.64          call    cmain
    5.65  
    5.66  /* This is the default interrupt handler. */
    5.67 @@ -156,8 +166,7 @@ ignore_int:
    5.68          mov     $(__HYPERVISOR_DS),%eax
    5.69          mov     %eax,%ds
    5.70          mov     %eax,%es
    5.71 -        lea     int_msg(%rip),%rax
    5.72 -        push    %rax
    5.73 +        lea     int_msg(%rip),%rdi
    5.74          call    SYMBOL_NAME(printf)
    5.75  1:      jmp     1b
    5.76  
    5.77 @@ -267,9 +276,11 @@ continue_nonidle_task:
    5.78  __get_user_1:
    5.79  paging_init:
    5.80  trap_init: 
    5.81 -.globl __get_user_8, zap_low_mappings, set_debugreg
    5.82 +.globl __get_user_8, zap_low_mappings, set_debugreg,synchronise_pagetables
    5.83  __get_user_8:
    5.84  zap_low_mappings:
    5.85  set_debugreg:
    5.86 +synchronise_pagetables:
    5.87 +.globl destroy_gdt
    5.88 +destroy_gdt:    
    5.89          
    5.90 -        
     6.1 --- a/xen/arch/x86/x86_32/mm.c	Wed Jul 14 17:17:52 2004 +0000
     6.2 +++ b/xen/arch/x86/x86_32/mm.c	Wed Jul 14 17:36:36 2004 +0000
     6.3 @@ -68,7 +68,7 @@ static void __init fixrange_init(unsigne
     6.4  
     6.5      for ( ; (i < ENTRIES_PER_L2_PAGETABLE) && (vaddr != end); l2e++, i++ ) 
     6.6      {
     6.7 -        if ( !l2_pgentry_empty(*l2e) )
     6.8 +        if ( l2_pgentry_val(*l2e) != 0 )
     6.9              continue;
    6.10          page = (unsigned long)get_free_page();
    6.11          clear_page(page);
    6.12 @@ -104,9 +104,9 @@ void __init paging_init(void)
    6.13  
    6.14      /* Create read-only mapping of MPT for guest-OS use. */
    6.15      idle_pg_table[RO_MPT_VIRT_START >> L2_PAGETABLE_SHIFT] =
    6.16 -        idle_pg_table[RDWR_MPT_VIRT_START >> L2_PAGETABLE_SHIFT];
    6.17 -    mk_l2_readonly(idle_pg_table + 
    6.18 -                   (RO_MPT_VIRT_START >> L2_PAGETABLE_SHIFT));
    6.19 +        mk_l2_pgentry(l2_pgentry_val(
    6.20 +            idle_pg_table[RDWR_MPT_VIRT_START >> L2_PAGETABLE_SHIFT]) & 
    6.21 +                      ~_PAGE_RW);
    6.22  
    6.23      /* Set up mapping cache for domain pages. */
    6.24      mapcache = (unsigned long *)get_free_page();
     7.1 --- a/xen/common/kernel.c	Wed Jul 14 17:17:52 2004 +0000
     7.2 +++ b/xen/common/kernel.c	Wed Jul 14 17:36:36 2004 +0000
     7.3 @@ -108,7 +108,7 @@ static struct {
     7.4  };
     7.5  
     7.6  
     7.7 -void cmain(unsigned long magic, multiboot_info_t *mbi)
     7.8 +void cmain(multiboot_info_t *mbi)
     7.9  {
    7.10      struct domain *new_dom;
    7.11      unsigned long max_page;
    7.12 @@ -173,12 +173,6 @@ void cmain(unsigned long magic, multiboo
    7.13             XEN_COMPILER, XEN_COMPILE_DATE);
    7.14      set_printk_prefix("(XEN) ");
    7.15  
    7.16 -    if ( magic != MULTIBOOT_BOOTLOADER_MAGIC )
    7.17 -    {
    7.18 -        printk("FATAL ERROR: Invalid magic number: 0x%08lx\n", magic);
    7.19 -        for ( ; ; ) ;
    7.20 -    }
    7.21 -
    7.22      /* We require memory and module information. */
    7.23      if ( (mbi->flags & 9) != 9 )
    7.24      {
     8.1 --- a/xen/include/asm-x86/config.h	Wed Jul 14 17:17:52 2004 +0000
     8.2 +++ b/xen/include/asm-x86/config.h	Wed Jul 14 17:36:36 2004 +0000
     8.3 @@ -94,6 +94,11 @@ extern void __out_of_line_bug(int line) 
     8.4  #define out_of_line_bug() __out_of_line_bug(__LINE__)
     8.5  #endif /* __ASSEMBLY__ */
     8.6  
     8.7 +#define BUG() do {					\
     8.8 +	printk("BUG at %s:%d\n", __FILE__, __LINE__);	\
     8.9 +	__asm__ __volatile__("ud2");			\
    8.10 +} while (0)
    8.11 +
    8.12  #if defined(__x86_64__)
    8.13  
    8.14  #define XENHEAP_DEFAULT_MB (16)
     9.1 --- a/xen/include/asm-x86/page.h	Wed Jul 14 17:17:52 2004 +0000
     9.2 +++ b/xen/include/asm-x86/page.h	Wed Jul 14 17:36:36 2004 +0000
     9.3 @@ -1,10 +1,27 @@
     9.4 -#ifndef _I386_PAGE_H
     9.5 -#define _I386_PAGE_H
     9.6 +/******************************************************************************
     9.7 + * asm-x86/page.h
     9.8 + * 
     9.9 + * Definitions relating to page tables.
    9.10 + */
    9.11 +
    9.12 +#ifndef __X86_PAGE_H__
    9.13 +#define __X86_PAGE_H__
    9.14 +
    9.15 +#if defined(__x86_64__)
    9.16  
    9.17 -#define BUG() do {					\
    9.18 -	printk("BUG at %s:%d\n", __FILE__, __LINE__);	\
    9.19 -	__asm__ __volatile__("ud2");			\
    9.20 -} while (0)
    9.21 +#define L1_PAGETABLE_SHIFT       12
    9.22 +#define L2_PAGETABLE_SHIFT       21
    9.23 +#define L3_PAGETABLE_SHIFT       30
    9.24 +#define L4_PAGETABLE_SHIFT       39
    9.25 +
    9.26 +#define ENTRIES_PER_L1_PAGETABLE 512
    9.27 +#define ENTRIES_PER_L2_PAGETABLE 512
    9.28 +#define ENTRIES_PER_L3_PAGETABLE 512
    9.29 +#define ENTRIES_PER_L4_PAGETABLE 512
    9.30 +
    9.31 +#define __PAGE_OFFSET		(0xFFFF830000000000)
    9.32 +
    9.33 +#elif defined(__i386__)
    9.34  
    9.35  #define L1_PAGETABLE_SHIFT       12
    9.36  #define L2_PAGETABLE_SHIFT       22
    9.37 @@ -12,6 +29,10 @@
    9.38  #define ENTRIES_PER_L1_PAGETABLE 1024
    9.39  #define ENTRIES_PER_L2_PAGETABLE 1024
    9.40  
    9.41 +#define __PAGE_OFFSET		(0xFC400000)
    9.42 +
    9.43 +#endif
    9.44 +
    9.45  #define PAGE_SHIFT               L1_PAGETABLE_SHIFT
    9.46  #define PAGE_SIZE	         (1UL << PAGE_SHIFT)
    9.47  #define PAGE_MASK	         (~(PAGE_SIZE-1))
    9.48 @@ -23,44 +44,60 @@
    9.49  #include <xen/config.h>
    9.50  typedef struct { unsigned long l1_lo; } l1_pgentry_t;
    9.51  typedef struct { unsigned long l2_lo; } l2_pgentry_t;
    9.52 -typedef l1_pgentry_t *l1_pagetable_t;
    9.53 -typedef l2_pgentry_t *l2_pagetable_t;
    9.54 +typedef struct { unsigned long l3_lo; } l3_pgentry_t;
    9.55 +typedef struct { unsigned long l4_lo; } l4_pgentry_t;
    9.56  typedef struct { unsigned long pt_lo; } pagetable_t;
    9.57  #endif /* !__ASSEMBLY__ */
    9.58  
    9.59  /* Strip type from a table entry. */
    9.60  #define l1_pgentry_val(_x) ((_x).l1_lo)
    9.61  #define l2_pgentry_val(_x) ((_x).l2_lo)
    9.62 +#define l3_pgentry_val(_x) ((_x).l3_lo)
    9.63 +#define l4_pgentry_val(_x) ((_x).l4_lo)
    9.64  #define pagetable_val(_x)  ((_x).pt_lo)
    9.65  
    9.66  /* Add type to a table entry. */
    9.67  #define mk_l1_pgentry(_x)  ( (l1_pgentry_t) { (_x) } )
    9.68  #define mk_l2_pgentry(_x)  ( (l2_pgentry_t) { (_x) } )
    9.69 +#define mk_l3_pgentry(_x)  ( (l3_pgentry_t) { (_x) } )
    9.70 +#define mk_l4_pgentry(_x)  ( (l4_pgentry_t) { (_x) } )
    9.71  #define mk_pagetable(_x)   ( (pagetable_t) { (_x) } )
    9.72  
    9.73  /* Turn a typed table entry into a page index. */
    9.74  #define l1_pgentry_to_pagenr(_x) (l1_pgentry_val(_x) >> PAGE_SHIFT) 
    9.75  #define l2_pgentry_to_pagenr(_x) (l2_pgentry_val(_x) >> PAGE_SHIFT)
    9.76 +#define l3_pgentry_to_pagenr(_x) (l3_pgentry_val(_x) >> PAGE_SHIFT)
    9.77 +#define l4_pgentry_to_pagenr(_x) (l4_pgentry_val(_x) >> PAGE_SHIFT)
    9.78  
    9.79  /* Turn a typed table entry into a physical address. */
    9.80  #define l1_pgentry_to_phys(_x) (l1_pgentry_val(_x) & PAGE_MASK)
    9.81  #define l2_pgentry_to_phys(_x) (l2_pgentry_val(_x) & PAGE_MASK)
    9.82 +#define l3_pgentry_to_phys(_x) (l3_pgentry_val(_x) & PAGE_MASK)
    9.83 +#define l4_pgentry_to_phys(_x) (l4_pgentry_val(_x) & PAGE_MASK)
    9.84  
    9.85 -/* Dereference a typed level-2 entry to yield a typed level-1 table. */
    9.86 -#define l2_pgentry_to_l1(_x)     \
    9.87 +/* Pagetable walking. */
    9.88 +#define l2_pgentry_to_l1(_x) \
    9.89    ((l1_pgentry_t *)__va(l2_pgentry_val(_x) & PAGE_MASK))
    9.90 +#define l3_pgentry_to_l2(_x) \
    9.91 +  ((l2_pgentry_t *)__va(l3_pgentry_val(_x) & PAGE_MASK))
    9.92 +#define l4_pgentry_to_l3(_x) \
    9.93 +  ((l3_pgentry_t *)__va(l4_pgentry_val(_x) & PAGE_MASK))
    9.94  
    9.95  /* Given a virtual address, get an entry offset into a page table. */
    9.96  #define l1_table_offset(_a) \
    9.97    (((_a) >> L1_PAGETABLE_SHIFT) & (ENTRIES_PER_L1_PAGETABLE - 1))
    9.98 +#if defined(__i386__)
    9.99  #define l2_table_offset(_a) \
   9.100    ((_a) >> L2_PAGETABLE_SHIFT)
   9.101 +#elif defined(__x86_64__)
   9.102 +#define l2_table_offset(_a) \
   9.103 +  (((_a) >> L2_PAGETABLE_SHIFT) & (ENTRIES_PER_L2_PAGETABLE -1))
   9.104 +#define l3_table_offset(_a) \
   9.105 +  (((_a) >> L3_PAGETABLE_SHIFT) & (ENTRIES_PER_L3_PAGETABLE -1))
   9.106 +#define l4_table_offset(_a) \
   9.107 +  ((_a) >> L4_PAGETABLE_SHIFT)
   9.108 +#endif
   9.109  
   9.110 -/* Hypervisor table entries use zero to sugnify 'empty'. */
   9.111 -#define l1_pgentry_empty(_x) (!l1_pgentry_val(_x))
   9.112 -#define l2_pgentry_empty(_x) (!l2_pgentry_val(_x))
   9.113 -
   9.114 -#define __PAGE_OFFSET		(0xFC400000)
   9.115  #define PAGE_OFFSET		((unsigned long)__PAGE_OFFSET)
   9.116  #define __pa(x)			((unsigned long)(x)-PAGE_OFFSET)
   9.117  #define __va(x)			((void *)((unsigned long)(x)+PAGE_OFFSET))
   9.118 @@ -148,25 +185,12 @@ extern void paging_init(void);
   9.119  	(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED)
   9.120  #define __PAGE_HYPERVISOR_NOCACHE \
   9.121  	(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_PCD | _PAGE_ACCESSED)
   9.122 -#define __PAGE_HYPERVISOR_RO \
   9.123 -	(_PAGE_PRESENT | _PAGE_DIRTY | _PAGE_ACCESSED)
   9.124  
   9.125  #define MAKE_GLOBAL(_x) ((_x) | _PAGE_GLOBAL)
   9.126  
   9.127  #define PAGE_HYPERVISOR MAKE_GLOBAL(__PAGE_HYPERVISOR)
   9.128 -#define PAGE_HYPERVISOR_RO MAKE_GLOBAL(__PAGE_HYPERVISOR_RO)
   9.129  #define PAGE_HYPERVISOR_NOCACHE MAKE_GLOBAL(__PAGE_HYPERVISOR_NOCACHE)
   9.130  
   9.131 -#define mk_l2_writeable(_p) \
   9.132 -    (*(_p) = mk_l2_pgentry(l2_pgentry_val(*(_p)) |  _PAGE_RW))
   9.133 -#define mk_l2_readonly(_p) \
   9.134 -    (*(_p) = mk_l2_pgentry(l2_pgentry_val(*(_p)) & ~_PAGE_RW))
   9.135 -#define mk_l1_writeable(_p) \
   9.136 -    (*(_p) = mk_l1_pgentry(l1_pgentry_val(*(_p)) |  _PAGE_RW))
   9.137 -#define mk_l1_readonly(_p) \
   9.138 -    (*(_p) = mk_l1_pgentry(l1_pgentry_val(*(_p)) & ~_PAGE_RW))
   9.139 -
   9.140 -
   9.141  #ifndef __ASSEMBLY__
   9.142  static __inline__ int get_order(unsigned long size)
   9.143  {
   9.144 @@ -184,4 +208,4 @@ static __inline__ int get_order(unsigned
   9.145  extern void zap_low_mappings(void);
   9.146  #endif
   9.147  
   9.148 -#endif /* _I386_PAGE_H */
   9.149 +#endif /* __I386_PAGE_H__ */
    10.1 --- a/xen/include/asm-x86/x86_64/page.h	Wed Jul 14 17:17:52 2004 +0000
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,300 +0,0 @@
    10.4 -#ifndef _X86_64_PAGE_H
    10.5 -#define _X86_64_PAGE_H
    10.6 -
    10.7 -#define BUG() do {					\
    10.8 -	printk("BUG at %s:%d\n", __FILE__, __LINE__);	\
    10.9 -	__asm__ __volatile__("ud2");			\
   10.10 -} while (0)
   10.11 - 
   10.12 -#define __PHYSICAL_MASK       0x0000ffffffffffffUL
   10.13 -#define PHYSICAL_PAGE_MASK    0x0000fffffffff000UL
   10.14 -#define PTE_MASK	PHYSICAL_PAGE_MASK
   10.15 -
   10.16 -/* PAGE_SHIFT determines the page size */
   10.17 -#define PAGE_SHIFT	12
   10.18 -#ifdef __ASSEMBLY__
   10.19 -#define PAGE_SIZE	(0x1 << PAGE_SHIFT)
   10.20 -#else
   10.21 -#define PAGE_SIZE	(1UL << PAGE_SHIFT)
   10.22 -#endif
   10.23 -#define PAGE_MASK	(~(PAGE_SIZE-1))
   10.24 -#define LARGE_PAGE_MASK (~(LARGE_PAGE_SIZE-1))
   10.25 -#define LARGE_PAGE_SIZE (1UL << PMD_SHIFT)
   10.26 -
   10.27 -#define L1_PAGETABLE_SHIFT       12
   10.28 -#define L2_PAGETABLE_SHIFT       21
   10.29 -#define L3_PAGETABLE_SHIFT	 30
   10.30 -#define L4_PAGETABLE_SHIFT	 39
   10.31 -#define LARGE_PFN	(LARGE_PAGE_SIZE / PAGE_SIZE)
   10.32 -
   10.33 -#define ENTRIES_PER_L1_PAGETABLE 512 
   10.34 -#define ENTRIES_PER_L2_PAGETABLE 512 
   10.35 -#define ENTRIES_PER_L3_PAGETABLE 512
   10.36 -#define ENTRIES_PER_L4_PAGETABLE 512
   10.37 -
   10.38 -#define KERNEL_TEXT_SIZE  (40UL*1024*1024)
   10.39 -#define KERNEL_TEXT_START 0xffffffff80000000UL 
   10.40 -
   10.41 -/* Changing the next two defines should be enough to increase the kernel stack */
   10.42 -/* We still hope 8K is enough, but ... */
   10.43 -#define THREAD_ORDER    1
   10.44 -#define THREAD_SIZE    (2*PAGE_SIZE)
   10.45 -
   10.46 -#define INIT_TASK_SIZE THREAD_SIZE
   10.47 -#define CURRENT_MASK (~(THREAD_SIZE-1))
   10.48 -
   10.49 -#define clear_page(_p)           memset((void *)(_p), 0, PAGE_SIZE)
   10.50 -#define copy_page(_t,_f)         memcpy((void *)(_t), (void *)(_f), PAGE_SIZE)
   10.51 -
   10.52 -#ifndef __ASSEMBLY__
   10.53 -#include <xen/config.h>
   10.54 -typedef struct { unsigned long l1_lo; } l1_pgentry_t;
   10.55 -typedef struct { unsigned long l2_lo; } l2_pgentry_t;
   10.56 -typedef struct { unsigned long l3_lo; } l3_pgentry_t;
   10.57 -typedef struct { unsigned long l4_lo; } l4_pgentry_t;
   10.58 -typedef l1_pgentry_t *l1_pagetable_t;
   10.59 -typedef l2_pgentry_t *l2_pagetable_t;
   10.60 -typedef l3_pgentry_t *l3_pagetable_t;
   10.61 -typedef l4_pgentry_t *l4_pagetable_t;
   10.62 -typedef struct { unsigned long pt_lo; } pagetable_t;
   10.63 -typedef struct { unsigned long pgprot; } pgprot_t;
   10.64 -#endif /* !__ASSEMBLY__ */
   10.65 -
   10.66 -/* Strip type from a table entry. */
   10.67 -#define l1_pgentry_val(_x) ((_x).l1_lo)
   10.68 -#define l2_pgentry_val(_x) ((_x).l2_lo)
   10.69 -#define l3_pgentry_val(_x) ((_x).l3_lo)
   10.70 -#define l4_pgentry_val(_x) ((_x).l4_lo)
   10.71 -#define pagetable_val(_x)  ((_x).pt_lo)
   10.72 -
   10.73 -/* Add type to a table entry. */
   10.74 -#define mk_l1_pgentry(_x)  ( (l1_pgentry_t) { (_x) } )
   10.75 -#define mk_l2_pgentry(_x)  ( (l2_pgentry_t) { (_x) } )
   10.76 -#define mk_l3_pgentry(_x)  ( (l3_pgentry_t) { (_x) } )
   10.77 -#define mk_l4_pgentry(_x)  ( (l4_pgentry_t) { (_x) } )
   10.78 -#define mk_pagetable(_x)   ( (pagetable_t) { (_x) } )
   10.79 -
   10.80 -/* Turn a typed table entry into a page index. */
   10.81 -#define l1_pgentry_to_pagenr(_x) (l1_pgentry_val(_x) >> PAGE_SHIFT) 
   10.82 -#define l2_pgentry_to_pagenr(_x) (l2_pgentry_val(_x) >> PAGE_SHIFT)
   10.83 -#define l3_pgentry_to_pagenr(_x) (l3_pgentry_val(_x) >> PAGE_SHIFT) 
   10.84 -#define l4_pgentry_to_pagenr(_x) (l4_pgentry_val(_x) >> PAGE_SHIFT)
   10.85 -
   10.86 -/* Turn a typed table entry into a physical address. */
   10.87 -#define l1_pgentry_to_phys(_x) (l1_pgentry_val(_x) & PAGE_MASK)
   10.88 -#define l2_pgentry_to_phys(_x) (l2_pgentry_val(_x) & PAGE_MASK)
   10.89 -#define l3_pgentry_to_phys(_x) (l3_pgentry_val(_x) & PAGE_MASK)
   10.90 -#define l4_pgentry_to_phys(_x) (l4_pgentry_val(_x) & PAGE_MASK)
   10.91 -
   10.92 -/* Dereference a typed level-2 entry to yield a typed level-1 table. */
   10.93 -#define l2_pgentry_to_l1(_x)     \
   10.94 -  ((l1_pgentry_t *)__va(l2_pgentry_val(_x) & PAGE_MASK))
   10.95 -
   10.96 -/* Dereference a typed level-4 entry to yield a typed level-3 table. */
   10.97 -#define l4_pgentry_to_l3(_x)     \
   10.98 -  ((l3_pgentry_t *)__va(l4_pgentry_val(_x) & PAGE_MASK))
   10.99 -
  10.100 -/* Dereference a typed level-3 entry to yield a typed level-2 table. */
  10.101 -#define l3_pgentry_to_l2(_x)     \
  10.102 -  ((l2_pgentry_t *)__va(l3_pgentry_val(_x) & PAGE_MASK))
  10.103 -
  10.104 -/* Given a virtual address, get an entry offset into a page table. */
  10.105 -#define l1_table_offset(_a) \
  10.106 -  (((_a) >> L1_PAGETABLE_SHIFT) & (ENTRIES_PER_L1_PAGETABLE - 1))
  10.107 -#define l2_table_offset(_a) \
  10.108 -  (((_a) >> L2_PAGETABLE_SHIFT) & (ENTRIES_PER_L2_PAGETABLE - 1))
  10.109 -#define l3_table_offset(_a) \
  10.110 -  (((_a) >> L3_PAGETABLE_SHIFT) & (ENTRIES_PER_L3_PAGETABLE - 1))
  10.111 -#define l4_table_offset(_a) \
  10.112 -  ((_a) >> L4_PAGETABLE_SHIFT)
  10.113 -
  10.114 -/* Hypervisor table entries use zero to sugnify 'empty'. */
  10.115 -#define l1_pgentry_empty(_x) (!l1_pgentry_val(_x))
  10.116 -#define l2_pgentry_empty(_x) (!l2_pgentry_val(_x))
  10.117 -#define l3_pgentry_empty(_x) (!l3_pgentry_val(_x))
  10.118 -#define l4_pgentry_empty(_x) (!l4_pgentry_val(_x))
  10.119 -
  10.120 -
  10.121 -#define pgprot_val(x)	((x).pgprot)
  10.122 -#define __pgprot(x)	((pgprot_t) { (x) } )
  10.123 - 
  10.124 -#define clear_user_page(page, vaddr)	clear_page(page)
  10.125 -#define copy_user_page(to, from, vaddr)	copy_page(to, from)
  10.126 -
  10.127 -/* to align the pointer to the (next) page boundary */
  10.128 -#define PAGE_ALIGN(addr)	(((addr)+PAGE_SIZE-1)&PAGE_MASK)
  10.129 -
  10.130 -/*
  10.131 - * NB. We don't currently track I/O holes in the physical RAM space.
  10.132 - * For now we guess that I/O devices will be mapped in the first 1MB
  10.133 - * (e.g., VGA buffers) or beyond the end of physical RAM.
  10.134 - */
  10.135 -#define pfn_is_ram(_pfn)        (((_pfn) > 0x100) && ((_pfn) < max_page))
  10.136 -
  10.137 -/* High table entries are reserved by the hypervisor. */
  10.138 -#define DOMAIN_ENTRIES_PER_L4_PAGETABLE	    \
  10.139 -  (HYPERVISOR_VIRT_START >> L4_PAGETABLE_SHIFT)
  10.140 -#define HYPERVISOR_ENTRIES_PER_L4_PAGETABLE \
  10.141 -  (ENTRIES_PER_L4_PAGETABLE - DOMAIN_ENTRIES_PER_L4_PAGETABLE)
  10.142 -
  10.143 -#define __START_KERNEL		0xffffffff80100000
  10.144 -#define __START_KERNEL_map	0xffffffff80000000
  10.145 -#define __PAGE_OFFSET           0x0000010000000000
  10.146 -#define PAGE_OFFSET		((unsigned long)__PAGE_OFFSET)
  10.147 -
  10.148 -#ifndef __ASSEMBLY__
  10.149 -#include <asm/processor.h>
  10.150 -#include <asm/fixmap.h>
  10.151 -#include <asm/bitops.h>
  10.152 -#include <asm/flushtlb.h>
  10.153 -
  10.154 -extern unsigned long vm_stack_flags, vm_stack_flags32;
  10.155 -extern unsigned long vm_data_default_flags, vm_data_default_flags32;
  10.156 -extern unsigned long vm_force_exec32;
  10.157 -
  10.158 -#define linear_pg_table ((l1_pgentry_t *)LINEAR_PT_VIRT_START)
  10.159 -
  10.160 -extern l2_pgentry_t idle_pg_table[ENTRIES_PER_L2_PAGETABLE];
  10.161 -extern void paging_init(void);
  10.162 -
  10.163 -#define __flush_tlb()                                    \
  10.164 -    do {                                                 \
  10.165 -        __asm__ __volatile__ (                           \
  10.166 -            "movl %%cr3, %%eax; movl %%eax, %%cr3"       \
  10.167 -            : : : "memory", "eax" );                     \
  10.168 -        tlb_clocktick();                                 \
  10.169 -    } while ( 0 )
  10.170 -
  10.171 -/* Flush global pages as well. */
  10.172 -
  10.173 -#define __pge_off()                                                     \
  10.174 -        do {                                                            \
  10.175 -                __asm__ __volatile__(                                   \
  10.176 -                        "movl %0, %%cr4;  # turn off PGE     "          \
  10.177 -                        :: "r" (mmu_cr4_features & ~X86_CR4_PGE));      \
  10.178 -        } while (0)
  10.179 -
  10.180 -#define __pge_on()                                                      \
  10.181 -        do {                                                            \
  10.182 -                __asm__ __volatile__(                                   \
  10.183 -                        "movl %0, %%cr4;  # turn off PGE     "          \
  10.184 -                        :: "r" (mmu_cr4_features));                     \
  10.185 -        } while (0)
  10.186 -
  10.187 -
  10.188 -#define __flush_tlb_pge()						\
  10.189 -	do {								\
  10.190 -                __pge_off();                                            \
  10.191 -		__flush_tlb();						\
  10.192 -                __pge_on();                                             \
  10.193 -	} while (0)
  10.194 -
  10.195 -#define __flush_tlb_one(__addr) \
  10.196 -__asm__ __volatile__("invlpg %0": :"m" (*(char *) (__addr)))
  10.197 -
  10.198 -#include <xen/config.h>
  10.199 -
  10.200 -/*
  10.201 - * Tell the user there is some problem.  The exception handler decodes this frame.
  10.202 - */
  10.203 -struct bug_frame { 
  10.204 -       unsigned char ud2[2];          
  10.205 -       char *filename;    /* should use 32bit offset instead, but the assembler doesn't like it */ 
  10.206 -       unsigned short line; 
  10.207 -} __attribute__((packed)); 
  10.208 -#define HEADER_BUG() asm volatile("ud2 ; .quad %P1 ; .short %P0" :: "i"(__LINE__), \
  10.209 -		"i" (__stringify(__FILE__)))
  10.210 -#define PAGE_BUG(page) BUG()
  10.211 -
  10.212 -#endif /* ASSEMBLY */
  10.213 -
  10.214 -#define _PAGE_PRESENT	0x001
  10.215 -#define _PAGE_RW	0x002
  10.216 -#define _PAGE_USER	0x004
  10.217 -#define _PAGE_PWT	0x008
  10.218 -#define _PAGE_PCD	0x010
  10.219 -#define _PAGE_ACCESSED	0x020
  10.220 -#define _PAGE_DIRTY	0x040
  10.221 -#define _PAGE_PAT       0x080
  10.222 -#define _PAGE_PSE	0x080
  10.223 -#define _PAGE_GLOBAL	0x100
  10.224 -
  10.225 -#define __PAGE_HYPERVISOR \
  10.226 -	(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED)
  10.227 -#define __PAGE_HYPERVISOR_NOCACHE \
  10.228 -	(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_PCD | _PAGE_ACCESSED)
  10.229 -#define __PAGE_HYPERVISOR_RO \
  10.230 -	(_PAGE_PRESENT | _PAGE_DIRTY | _PAGE_ACCESSED)
  10.231 -
  10.232 -#define MAKE_GLOBAL(_x) ((_x) | _PAGE_GLOBAL)
  10.233 -
  10.234 -#define PAGE_HYPERVISOR MAKE_GLOBAL(__PAGE_HYPERVISOR)
  10.235 -#define PAGE_HYPERVISOR_RO MAKE_GLOBAL(__PAGE_HYPERVISOR_RO)
  10.236 -#define PAGE_HYPERVISOR_NOCACHE MAKE_GLOBAL(__PAGE_HYPERVISOR_NOCACHE)
  10.237 -
  10.238 -#define mk_l4_writeable(_p) \
  10.239 -    (*(_p) = mk_l4_pgentry(l4_pgentry_val(*(_p)) |  _PAGE_RW))
  10.240 -#define mk_l4_readonly(_p) \
  10.241 -    (*(_p) = mk_l4_pgentry(l4_pgentry_val(*(_p)) & ~_PAGE_RW))
  10.242 -#define mk_l3_writeable(_p) \
  10.243 -    (*(_p) = mk_l3_pgentry(l3_pgentry_val(*(_p)) |  _PAGE_RW))
  10.244 -#define mk_l3_readonly(_p) \
  10.245 -    (*(_p) = mk_l3_pgentry(l3_pgentry_val(*(_p)) & ~_PAGE_RW))
  10.246 -#define mk_l2_writeable(_p) \
  10.247 -    (*(_p) = mk_l2_pgentry(l2_pgentry_val(*(_p)) |  _PAGE_RW))
  10.248 -#define mk_l2_readonly(_p) \
  10.249 -    (*(_p) = mk_l2_pgentry(l2_pgentry_val(*(_p)) & ~_PAGE_RW))
  10.250 -#define mk_l1_writeable(_p) \
  10.251 -    (*(_p) = mk_l1_pgentry(l1_pgentry_val(*(_p)) |  _PAGE_RW))
  10.252 -#define mk_l1_readonly(_p) \
  10.253 -    (*(_p) = mk_l1_pgentry(l1_pgentry_val(*(_p)) & ~_PAGE_RW))
  10.254 -
  10.255 -/* Note: __pa(&symbol_visible_to_c) should be always replaced with __pa_symbol.
  10.256 -   Otherwise you risk miscompilation. */ 
  10.257 -#define __pa(x)			(((unsigned long)(x)>=__START_KERNEL_map)?(unsigned long)(x) - (unsigned long)__START_KERNEL_map:(unsigned long)(x) - PAGE_OFFSET)
  10.258 -/* __pa_symbol should use for C visible symbols, but only for them. 
  10.259 -   This seems to be the official gcc blessed way to do such arithmetic. */ 
  10.260 -#define __pa_symbol(x)		\
  10.261 -	({unsigned long v;  \
  10.262 -	  asm("" : "=r" (v) : "0" (x)); \
  10.263 -	 v - __START_KERNEL_map; })
  10.264 -#define __pa_maybe_symbol(x)		\
  10.265 -	({unsigned long v;  \
  10.266 -	  asm("" : "=r" (v) : "0" (x)); \
  10.267 -	  __pa(v); })
  10.268 -#define __va(x)			((void *)((unsigned long)(x)+PAGE_OFFSET))
  10.269 -#ifndef CONFIG_DISCONTIGMEM
  10.270 -#define virt_to_page(kaddr)	(frame_table + (__pa(kaddr) >> PAGE_SHIFT))
  10.271 -#define pfn_to_page(pfn)	(frame_table + (pfn)) 
  10.272 -#define page_address(_p)        (__va(((_p) - frame_table) << PAGE_SHIFT))
  10.273 -#define VALID_PAGE(page)	(((page) - frame_table) < max_mapnr)
  10.274 -#endif
  10.275 -
  10.276 -#ifndef __ASSEMBLY__
  10.277 -static __inline__ int get_order(unsigned long size)
  10.278 -{
  10.279 -    int order;
  10.280 -    
  10.281 -    size = (size-1) >> (PAGE_SHIFT-1);
  10.282 -    order = -1;
  10.283 -    do {
  10.284 -        size >>= 1;
  10.285 -        order++;
  10.286 -    } while (size);
  10.287 -    return order;
  10.288 -}
  10.289 -#endif
  10.290 -
  10.291 -#define phys_to_pfn(phys)	((phys) >> PAGE_SHIFT)
  10.292 -
  10.293 -#define __VM_DATA_DEFAULT_FLAGS	(VM_READ | VM_WRITE | VM_EXEC | \
  10.294 -				 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
  10.295 -#define __VM_STACK_FLAGS 	(VM_GROWSDOWN | VM_READ | VM_WRITE | VM_EXEC | \
  10.296 -				 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
  10.297 -
  10.298 -#define VM_DATA_DEFAULT_FLAGS \
  10.299 -	((current->thread.flags & THREAD_IA32) ? vm_data_default_flags32 : \
  10.300 -	  vm_data_default_flags) 
  10.301 -#define VM_STACK_FLAGS	vm_stack_flags
  10.302 -
  10.303 -#endif /* _X86_64_PAGE_H */