ia64/xen-unstable

changeset 16736:8f6640070a86

minios: make stack size configurable

Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
Signed-off-by: Grzegorz Milos <gm281@cam.ac.uk>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jan 17 14:41:44 2008 +0000 (2008-01-17)
parents 1101ca828ad9
children 8984cc0a1d80
files extras/mini-os/arch/ia64/sched.c extras/mini-os/arch/x86/sched.c extras/mini-os/arch/x86/setup.c extras/mini-os/arch/x86/x86_32.S extras/mini-os/arch/x86/x86_64.S extras/mini-os/include/ia64/arch_mm.h extras/mini-os/include/x86/arch_mm.h extras/mini-os/include/x86/arch_sched.h extras/mini-os/sched.c
line diff
     1.1 --- a/extras/mini-os/arch/ia64/sched.c	Thu Jan 17 14:41:12 2008 +0000
     1.2 +++ b/extras/mini-os/arch/ia64/sched.c	Thu Jan 17 14:41:44 2008 +0000
     1.3 @@ -40,11 +40,11 @@ arch_create_thread(char *name, void (*fu
     1.4  	struct thread* _thread;
     1.5  
     1.6  	_thread = (struct thread*)_xmalloc(sizeof(struct thread), 16);
     1.7 -	/* Allocate 2 pages for stack, stack will be 2pages aligned */
     1.8 -	_thread->stack = (char *)alloc_pages(1);
     1.9 +	/* Allocate pages for stack, stack will be aligned */
    1.10 +	_thread->stack = (char *)alloc_pages(STACK_SIZE_PAGE_ORDER);
    1.11  	_thread->name = name;
    1.12  	memset((void*)&(_thread->regs), 0, sizeof(_thread->regs));
    1.13 -	_thread->regs.sp = ((uint64_t)_thread->stack) + 2 * PAGE_SIZE - 16;
    1.14 +	_thread->regs.sp = ((uint64_t)_thread->stack) + STACK_SIZE - 16;
    1.15  	_thread->regs.bsp = ((uint64_t)_thread->stack) + 0x10;
    1.16  	_thread->regs.rp = FDESC_FUNC(thread_starter);
    1.17  	_thread->regs.pfs = 0x82;
     2.1 --- a/extras/mini-os/arch/x86/sched.c	Thu Jan 17 14:41:12 2008 +0000
     2.2 +++ b/extras/mini-os/arch/x86/sched.c	Thu Jan 17 14:41:44 2008 +0000
     2.3 @@ -57,7 +57,7 @@
     2.4  
     2.5  void dump_stack(struct thread *thread)
     2.6  {
     2.7 -    unsigned long *bottom = (unsigned long *)(thread->stack + 2*4*1024); 
     2.8 +    unsigned long *bottom = (unsigned long *)(thread->stack + STACK_SIZE); 
     2.9      unsigned long *pointer = (unsigned long *)thread->sp;
    2.10      int count;
    2.11      if(thread == current)
    2.12 @@ -98,13 +98,13 @@ struct thread* arch_create_thread(char *
    2.13      struct thread *thread;
    2.14      
    2.15      thread = xmalloc(struct thread);
    2.16 -    /* Allocate 2 pages for stack, stack will be 2pages aligned */
    2.17 -    thread->stack = (char *)alloc_pages(1);
    2.18 +    /* We can't use lazy allocation here since the trap handler runs on the stack */
    2.19 +    thread->stack = (char *)alloc_pages(STACK_SIZE_PAGE_ORDER);
    2.20      thread->name = name;
    2.21      printk("Thread \"%s\": pointer: 0x%lx, stack: 0x%lx\n", name, thread, 
    2.22              thread->stack);
    2.23      
    2.24 -    thread->sp = (unsigned long)thread->stack + 4096 * 2;
    2.25 +    thread->sp = (unsigned long)thread->stack + STACK_SIZE;
    2.26      /* Save pointer to the thread on the stack, used by current macro */
    2.27      *((unsigned long *)thread->stack) = (unsigned long)thread;
    2.28      
     3.1 --- a/extras/mini-os/arch/x86/setup.c	Thu Jan 17 14:41:12 2008 +0000
     3.2 +++ b/extras/mini-os/arch/x86/setup.c	Thu Jan 17 14:41:44 2008 +0000
     3.3 @@ -45,7 +45,7 @@ union start_info_union start_info_union;
     3.4   * Just allocate the kernel stack here. SS:ESP is set up to point here
     3.5   * in head.S.
     3.6   */
     3.7 -char stack[2*8192];
     3.8 +char stack[2*STACK_SIZE];
     3.9  
    3.10  extern char shared_info[PAGE_SIZE];
    3.11  
    3.12 @@ -102,7 +102,7 @@ arch_init(start_info_t *si)
    3.13  void
    3.14  arch_print_info(void)
    3.15  {
    3.16 -	printk("  stack:      %p-%p\n", stack, stack + 2*8192);
    3.17 +	printk("  stack:      %p-%p\n", stack, stack + sizeof(stack));
    3.18  }
    3.19  
    3.20  
     4.1 --- a/extras/mini-os/arch/x86/x86_32.S	Thu Jan 17 14:41:12 2008 +0000
     4.2 +++ b/extras/mini-os/arch/x86/x86_32.S	Thu Jan 17 14:41:44 2008 +0000
     4.3 @@ -1,4 +1,5 @@
     4.4  #include <os.h>
     4.5 +#include <arch_mm.h>
     4.6  #include <xen/arch-x86_32.h>
     4.7  
     4.8  .section __xen_guest
     4.9 @@ -21,12 +22,12 @@
    4.10  _start:
    4.11          cld
    4.12          lss stack_start,%esp
    4.13 -        andl $(~(8192-1)), %esp
    4.14 +        andl $(~(STACK_SIZE-1)), %esp
    4.15          push %esi 
    4.16          call start_kernel
    4.17  
    4.18  stack_start:
    4.19 -	.long stack+(2*8192), __KERNEL_SS
    4.20 +	.long stack+(2*STACK_SIZE), __KERNEL_SS
    4.21  
    4.22          /* Unpleasant -- the PTE that maps this page is actually overwritten */
    4.23          /* to map the real shared-info page! :-)                             */
     5.1 --- a/extras/mini-os/arch/x86/x86_64.S	Thu Jan 17 14:41:12 2008 +0000
     5.2 +++ b/extras/mini-os/arch/x86/x86_64.S	Thu Jan 17 14:41:44 2008 +0000
     5.3 @@ -1,4 +1,5 @@
     5.4  #include <os.h>
     5.5 +#include <arch_mm.h>
     5.6  #include <xen/features.h>
     5.7  
     5.8  .section __xen_guest
     5.9 @@ -18,12 +19,12 @@
    5.10  _start:
    5.11          cld
    5.12          movq stack_start(%rip),%rsp
    5.13 -        andq $(~(8192-1)), %rsp
    5.14 +        andq $(~(STACK_SIZE-1)), %rsp
    5.15          movq %rsi,%rdi
    5.16          call start_kernel
    5.17  
    5.18  stack_start:
    5.19 -        .quad stack+(2*8192)
    5.20 +        .quad stack+(2*STACK_SIZE)
    5.21  
    5.22          /* Unpleasant -- the PTE that maps this page is actually overwritten */
    5.23          /* to map the real shared-info page! :-)                             */
     6.1 --- a/extras/mini-os/include/ia64/arch_mm.h	Thu Jan 17 14:41:12 2008 +0000
     6.2 +++ b/extras/mini-os/include/ia64/arch_mm.h	Thu Jan 17 14:41:44 2008 +0000
     6.3 @@ -33,4 +33,7 @@
     6.4  
     6.5  #define virt_to_mfn(x)	virt_to_pfn(x)
     6.6  
     6.7 +#define STACK_SIZE_PAGE_ORDER   1
     6.8 +#define STACK_SIZE              (PAGE_SIZE * (1 << STACK_SIZE_PAGE_ORDER))
     6.9 +
    6.10  #endif /* __ARCH_MM_H__ */
     7.1 --- a/extras/mini-os/include/x86/arch_mm.h	Thu Jan 17 14:41:12 2008 +0000
     7.2 +++ b/extras/mini-os/include/x86/arch_mm.h	Thu Jan 17 14:41:44 2008 +0000
     7.3 @@ -25,6 +25,8 @@
     7.4  #ifndef _ARCH_MM_H_
     7.5  #define _ARCH_MM_H_
     7.6  
     7.7 +#ifndef __ASSEMBLY__
     7.8 +#include <xen/xen.h>
     7.9  #if defined(__i386__)
    7.10  #include <xen/arch-x86_32.h>
    7.11  #elif defined(__x86_64__)
    7.12 @@ -32,6 +34,7 @@
    7.13  #else
    7.14  #error "Unsupported architecture"
    7.15  #endif
    7.16 +#endif
    7.17  
    7.18  #define L1_FRAME                1
    7.19  #define L2_FRAME                2
    7.20 @@ -53,7 +56,9 @@
    7.21  
    7.22  #define NOT_L1_FRAMES           1
    7.23  #define PRIpte "08lx"
    7.24 +#ifndef __ASSEMBLY__
    7.25  typedef unsigned long pgentry_t;
    7.26 +#endif
    7.27  
    7.28  #else /* defined(CONFIG_X86_PAE) */
    7.29  
    7.30 @@ -76,7 +81,9 @@ typedef unsigned long pgentry_t;
    7.31   */
    7.32  #define NOT_L1_FRAMES           3
    7.33  #define PRIpte "016llx"
    7.34 +#ifndef __ASSEMBLY__
    7.35  typedef uint64_t pgentry_t;
    7.36 +#endif
    7.37  
    7.38  #endif /* !defined(CONFIG_X86_PAE) */
    7.39  
    7.40 @@ -102,7 +109,9 @@ typedef uint64_t pgentry_t;
    7.41  
    7.42  #define NOT_L1_FRAMES           3
    7.43  #define PRIpte "016lx"
    7.44 +#ifndef __ASSEMBLY__
    7.45  typedef unsigned long pgentry_t;
    7.46 +#endif
    7.47  
    7.48  #endif
    7.49  
    7.50 @@ -146,11 +155,15 @@ typedef unsigned long pgentry_t;
    7.51  #define L4_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER)
    7.52  #endif /* __i386__ || __x86_64__ */
    7.53  
    7.54 +#ifdef __ASSEMBLY__
    7.55 +#define PAGE_SIZE       (1 << L1_PAGETABLE_SHIFT)
    7.56 +#else
    7.57  #ifndef CONFIG_X86_PAE
    7.58  #define PAGE_SIZE       (1UL << L1_PAGETABLE_SHIFT)
    7.59  #else
    7.60  #define PAGE_SIZE       (1ULL << L1_PAGETABLE_SHIFT)
    7.61  #endif
    7.62 +#endif
    7.63  #define PAGE_SHIFT      L1_PAGETABLE_SHIFT
    7.64  #define PAGE_MASK       (~(PAGE_SIZE-1))
    7.65  
    7.66 @@ -162,6 +175,10 @@ typedef unsigned long pgentry_t;
    7.67  /* to align the pointer to the (next) page boundary */
    7.68  #define PAGE_ALIGN(addr)        (((addr)+PAGE_SIZE-1)&PAGE_MASK)
    7.69  
    7.70 +#define STACK_SIZE_PAGE_ORDER  1
    7.71 +#define STACK_SIZE             (PAGE_SIZE * (1 << STACK_SIZE_PAGE_ORDER))
    7.72 +
    7.73 +#ifndef __ASSEMBLY__
    7.74  /* Definitions for machine and pseudophysical addresses. */
    7.75  #ifdef CONFIG_X86_PAE
    7.76  typedef unsigned long long paddr_t;
    7.77 @@ -188,6 +205,7 @@ static __inline__ paddr_t machine_to_phy
    7.78  	phys = (phys << PAGE_SHIFT) | (machine & ~PAGE_MASK);
    7.79  	return phys;
    7.80  }
    7.81 +#endif
    7.82  
    7.83  #define VIRT_START                 ((unsigned long)&_text)
    7.84  
     8.1 --- a/extras/mini-os/include/x86/arch_sched.h	Thu Jan 17 14:41:12 2008 +0000
     8.2 +++ b/extras/mini-os/include/x86/arch_sched.h	Thu Jan 17 14:41:44 2008 +0000
     8.3 @@ -2,6 +2,7 @@
     8.4  #ifndef __ARCH_SCHED_H__
     8.5  #define __ARCH_SCHED_H__
     8.6  
     8.7 +#include <arch_mm.h>
     8.8  
     8.9  static inline struct thread* get_current(void)
    8.10  {
    8.11 @@ -11,7 +12,7 @@ static inline struct thread* get_current
    8.12  #else
    8.13      register unsigned long sp asm("rsp");
    8.14  #endif 
    8.15 -    current = (void *)(sp & ~8191UL);
    8.16 +    current = (void *)(sp & ~(STACK_SIZE-1));
    8.17      return *current;
    8.18  }
    8.19  
     9.1 --- a/extras/mini-os/sched.c	Thu Jan 17 14:41:12 2008 +0000
     9.2 +++ b/extras/mini-os/sched.c	Thu Jan 17 14:41:44 2008 +0000
     9.3 @@ -139,7 +139,7 @@ void schedule(void)
     9.4          if(thread != prev)
     9.5          {
     9.6              list_del(&thread->thread_list);
     9.7 -            free_pages(thread->stack, 1);
     9.8 +            free_pages(thread->stack, STACK_SIZE_PAGE_ORDER);
     9.9              xfree(thread);
    9.10          }
    9.11      }