ia64/xen-unstable

changeset 17471:681cfd0eda78

stubdom: sparse application's BSS by linking it separately first, put
markers at its beginning and end, and then link with mini-os.
That permits to stick a bit more to upstream qemu.

Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Apr 16 10:05:57 2008 +0100 (2008-04-16)
parents 1ac2a314aa3c
children e35a379e7fe9
files extras/mini-os/Makefile extras/mini-os/app.lds extras/mini-os/arch/ia64/minios-ia64.lds extras/mini-os/arch/x86/minios-x86_32.lds extras/mini-os/arch/x86/minios-x86_64.lds extras/mini-os/arch/x86/mm.c extras/mini-os/include/ia64/arch_mm.h extras/mini-os/include/lib.h extras/mini-os/include/mm.h extras/mini-os/lib/sys.c extras/mini-os/main.c extras/mini-os/mm.c tools/ioemu/vl.c
line diff
     1.1 --- a/extras/mini-os/Makefile	Wed Apr 16 10:04:22 2008 +0100
     1.2 +++ b/extras/mini-os/Makefile	Wed Apr 16 10:05:57 2008 +0100
     1.3 @@ -19,6 +19,7 @@ include minios.mk
     1.4  
     1.5  # Define some default flags for linking.
     1.6  LDLIBS := 
     1.7 +APP_LDLIBS := 
     1.8  LDARCHLIB := -L$(TARGET_ARCH_DIR) -l$(ARCH_LIB_NAME)
     1.9  LDFLAGS_FINAL := -T $(TARGET_ARCH_DIR)/minios-$(XEN_TARGET_ARCH).lds
    1.10  
    1.11 @@ -33,6 +34,7 @@ TARGET := mini-os
    1.12  SUBDIRS := lib xenbus console
    1.13  
    1.14  # The common mini-os objects to build.
    1.15 +APP_OBJS :=
    1.16  OBJS := $(patsubst %.c,%.o,$(wildcard *.c))
    1.17  OBJS += $(patsubst %.c,%.o,$(wildcard lib/*.c))
    1.18  OBJS += $(patsubst %.c,%.o,$(wildcard xenbus/*.c))
    1.19 @@ -75,28 +77,28 @@ OBJS := $(filter-out lwip%.o $(LWO), $(O
    1.20  
    1.21  ifeq ($(caml),y)
    1.22  CAMLLIB = $(shell ocamlc -where)
    1.23 -OBJS += $(CAMLDIR)/caml.o
    1.24 -OBJS += $(CAMLLIB)/libasmrun.a
    1.25 +APP_OBJS += main-caml.o
    1.26 +APP_OBJS += $(CAMLDIR)/caml.o
    1.27 +APP_OBJS += $(CAMLLIB)/libasmrun.a
    1.28  CFLAGS += -I$(CAMLLIB)
    1.29 -LDLIBS += -lm
    1.30 -else
    1.31 +APP_LDLIBS += -lm
    1.32 +endif
    1.33  OBJS := $(filter-out main-caml.o, $(OBJS))
    1.34 -endif
    1.35  
    1.36  ifeq ($(qemu),y)
    1.37 -OBJS += $(QEMUDIR)/i386-dm-stubdom/qemu.a $(QEMUDIR)/i386-dm-stubdom/libqemu.a
    1.38 +APP_OBJS += $(QEMUDIR)/i386-dm-stubdom/qemu.a $(QEMUDIR)/i386-dm-stubdom/libqemu.a
    1.39  CFLAGS += -DCONFIG_QEMU
    1.40  endif
    1.41  
    1.42  ifneq ($(CDIR),)
    1.43 -OBJS += $(CDIR)/main.a
    1.44 -LDLIBS += 
    1.45 +APP_OBJS += $(CDIR)/main.a
    1.46 +APP_LDLIBS += 
    1.47  endif
    1.48  
    1.49  ifeq ($(libc),y)
    1.50  LDLIBS += -L$(XEN_ROOT)/stubdom/libxc -lxenctrl -lxenguest
    1.51 -LDLIBS += -lpci
    1.52 -LDLIBS += -lz
    1.53 +APP_LDLIBS += -lpci
    1.54 +APP_LDLIBS += -lz
    1.55  LDLIBS += -lc
    1.56  endif
    1.57  
    1.58 @@ -104,8 +106,11 @@ ifneq ($(caml)-$(qemu)-$(CDIR)-$(lwip),-
    1.59  OBJS := $(filter-out daytime.o, $(OBJS))
    1.60  endif
    1.61  
    1.62 -$(TARGET): links $(OBJS) arch_lib
    1.63 -	$(LD) -r $(LDFLAGS) $(HEAD_OBJ) $(OBJS) $(LDARCHLIB) $(LDLIBS) -o $@.o
    1.64 +app.o: $(APP_OBJS) app.lds
    1.65 +	$(LD) -r -d $(LDFLAGS) $^ $(APP_LDLIBS) --undefined main -o $@
    1.66 +
    1.67 +$(TARGET): links $(OBJS) app.o arch_lib
    1.68 +	$(LD) -r $(LDFLAGS) $(HEAD_OBJ) app.o $(OBJS) $(LDARCHLIB) $(LDLIBS) -o $@.o
    1.69  	$(OBJCOPY) -w -G $(GLOBAL_PREFIX)* -G _start $@.o $@.o
    1.70  	$(LD) $(LDFLAGS) $(LDFLAGS_FINAL) $@.o $(EXTRA_OBJS) -o $@
    1.71  	gzip -f -9 -c $@ >$@.gz
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/extras/mini-os/app.lds	Wed Apr 16 10:05:57 2008 +0100
     2.3 @@ -0,0 +1,11 @@
     2.4 +SECTIONS
     2.5 +{
     2.6 +        .app.bss : {
     2.7 +                __app_bss_start = . ;
     2.8 +                *(.bss .bss.*)
     2.9 +                *(COMMON)
    2.10 +                *(.lbss .lbss.*)
    2.11 +                *(LARGE_COMMON)
    2.12 +                __app_bss_end = . ;
    2.13 +        }
    2.14 +}
     3.1 --- a/extras/mini-os/arch/ia64/minios-ia64.lds	Wed Apr 16 10:04:22 2008 +0100
     3.2 +++ b/extras/mini-os/arch/ia64/minios-ia64.lds	Wed Apr 16 10:05:57 2008 +0100
     3.3 @@ -59,7 +59,10 @@ SECTIONS
     3.4    { *(.IA_64.unwind) }
     3.5  
     3.6    .bss : AT(ADDR(.bss) - (((5<<(61))+0x100000000) - (1 << 20)))
     3.7 -  { *(.bss) }
     3.8 +  {
     3.9 +    *(.bss)
    3.10 +    *(.app.bss)
    3.11 +  }
    3.12  
    3.13    _end = .;
    3.14  
     4.1 --- a/extras/mini-os/arch/x86/minios-x86_32.lds	Wed Apr 16 10:04:22 2008 +0100
     4.2 +++ b/extras/mini-os/arch/x86/minios-x86_32.lds	Wed Apr 16 10:05:57 2008 +0100
     4.3 @@ -38,6 +38,7 @@ SECTIONS
     4.4    __bss_start = .;		/* BSS */
     4.5    .bss : {
     4.6  	*(.bss)
     4.7 +        *(.app.bss)
     4.8  	}
     4.9    _end = . ;
    4.10  
     5.1 --- a/extras/mini-os/arch/x86/minios-x86_64.lds	Wed Apr 16 10:04:22 2008 +0100
     5.2 +++ b/extras/mini-os/arch/x86/minios-x86_64.lds	Wed Apr 16 10:05:57 2008 +0100
     5.3 @@ -38,6 +38,7 @@ SECTIONS
     5.4    __bss_start = .;		/* BSS */
     5.5    .bss : {
     5.6  	*(.bss)
     5.7 +        *(.app.bss)
     5.8  	}
     5.9    _end = . ;
    5.10  
     6.1 --- a/extras/mini-os/arch/x86/mm.c	Wed Apr 16 10:04:22 2008 +0100
     6.2 +++ b/extras/mini-os/arch/x86/mm.c	Wed Apr 16 10:05:57 2008 +0100
     6.3 @@ -556,7 +556,6 @@ void *map_frames_ex(unsigned long *f, un
     6.4  
     6.5  static void clear_bootstrap(void)
     6.6  {
     6.7 -    struct xen_memory_reservation reservation;
     6.8      xen_pfn_t mfns[] = { virt_to_mfn(&shared_info) };
     6.9      int n = sizeof(mfns)/sizeof(*mfns);
    6.10      pte_t nullpte = { };
    6.11 @@ -567,11 +566,7 @@ static void clear_bootstrap(void)
    6.12      if (HYPERVISOR_update_va_mapping((unsigned long) &_text, nullpte, UVMF_INVLPG))
    6.13  	printk("Unable to unmap first page\n");
    6.14  
    6.15 -    set_xen_guest_handle(reservation.extent_start, mfns);
    6.16 -    reservation.nr_extents = n;
    6.17 -    reservation.extent_order = 0;
    6.18 -    reservation.domid = DOMID_SELF;
    6.19 -    if (HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation) != n)
    6.20 +    if (free_physical_pages(mfns, n) != n)
    6.21  	printk("Unable to free bootstrap pages\n");
    6.22  }
    6.23  
     7.1 --- a/extras/mini-os/include/ia64/arch_mm.h	Wed Apr 16 10:04:22 2008 +0100
     7.2 +++ b/extras/mini-os/include/ia64/arch_mm.h	Wed Apr 16 10:05:57 2008 +0100
     7.3 @@ -38,6 +38,6 @@
     7.4  #define map_frames(f, n) map_frames_ex(f, n, 1, 0, 1, DOMID_SELF, 0, 0)
     7.5  /* TODO */
     7.6  #define map_zero(n, a) map_frames_ex(NULL, n, 0, 0, a, DOMID_SELF, 0, 0)
     7.7 -#define do_map_zero(start, n) ((void)0)
     7.8 +#define do_map_zero(start, n) ASSERT(n == 0)
     7.9  
    7.10  #endif /* __ARCH_MM_H__ */
     8.1 --- a/extras/mini-os/include/lib.h	Wed Apr 16 10:04:22 2008 +0100
     8.2 +++ b/extras/mini-os/include/lib.h	Wed Apr 16 10:05:57 2008 +0100
     8.3 @@ -187,6 +187,7 @@ extern struct file {
     8.4  int alloc_fd(enum fd_type type);
     8.5  void close_all_files(void);
     8.6  extern struct thread *main_thread;
     8.7 +void sparse(unsigned long data, size_t size);
     8.8  #endif
     8.9  
    8.10  #endif /* _LIB_H_ */
     9.1 --- a/extras/mini-os/include/mm.h	Wed Apr 16 10:04:22 2008 +0100
     9.2 +++ b/extras/mini-os/include/mm.h	Wed Apr 16 10:05:57 2008 +0100
     9.3 @@ -70,4 +70,6 @@ void *map_frames_ex(unsigned long *f, un
     9.4  extern unsigned long heap, brk, heap_mapped, heap_end;
     9.5  #endif
     9.6  
     9.7 +int free_physical_pages(xen_pfn_t *mfns, int n);
     9.8 +
     9.9  #endif /* _MM_H_ */
    10.1 --- a/extras/mini-os/lib/sys.c	Wed Apr 16 10:04:22 2008 +0100
    10.2 +++ b/extras/mini-os/lib/sys.c	Wed Apr 16 10:05:57 2008 +0100
    10.3 @@ -1108,6 +1108,41 @@ int munmap(void *start, size_t length)
    10.4      return 0;
    10.5  }
    10.6  
    10.7 +void sparse(unsigned long data, size_t size)
    10.8 +{
    10.9 +    unsigned long newdata;
   10.10 +    xen_pfn_t *mfns;
   10.11 +    int i, n;
   10.12 +
   10.13 +    newdata = (data + PAGE_SIZE - 1) & PAGE_MASK;
   10.14 +    if (newdata - data > size)
   10.15 +        return;
   10.16 +    size -= newdata - data;
   10.17 +    data = newdata;
   10.18 +    n = size / PAGE_SIZE;
   10.19 +    size = n * PAGE_SIZE;
   10.20 +
   10.21 +    mfns = malloc(n * sizeof(*mfns));
   10.22 +    for (i = 0; i < n; i++) {
   10.23 +#ifdef LIBC_DEBUG
   10.24 +        int j;
   10.25 +        for (j=0; j<PAGE_SIZE; j++)
   10.26 +            if (((char*)data + i * PAGE_SIZE)[j]) {
   10.27 +                printk("%lx is not zero!\n", data + i * PAGE_SIZE + j);
   10.28 +                exit(1);
   10.29 +            }
   10.30 +#endif
   10.31 +        mfns[i] = virtual_to_mfn(data + i * PAGE_SIZE);
   10.32 +    }
   10.33 +
   10.34 +    printk("sparsing %ldMB at %lx\n", size >> 20, data);
   10.35 +
   10.36 +    munmap((void *) data, size);
   10.37 +    free_physical_pages(mfns, n);
   10.38 +    do_map_zero(data, n);
   10.39 +}
   10.40 +
   10.41 +
   10.42  /* Not supported by FS yet.  */
   10.43  unsupported_function_crash(link);
   10.44  unsupported_function(int, readlink, -1);
    11.1 --- a/extras/mini-os/main.c	Wed Apr 16 10:04:22 2008 +0100
    11.2 +++ b/extras/mini-os/main.c	Wed Apr 16 10:05:57 2008 +0100
    11.3 @@ -39,6 +39,7 @@ void _fini(void)
    11.4  {
    11.5  }
    11.6  
    11.7 +extern char __app_bss_start, __app_bss_end;
    11.8  static void call_main(void *p)
    11.9  {
   11.10      char *args, /**path,*/ *msg, *c;
   11.11 @@ -56,6 +57,7 @@ static void call_main(void *p)
   11.12       * crashing. */
   11.13      //sleep(1);
   11.14  
   11.15 +    sparse((unsigned long) &__app_bss_start, &__app_bss_end - &__app_bss_start);
   11.16      start_networking();
   11.17      init_fs_frontend();
   11.18  
    12.1 --- a/extras/mini-os/mm.c	Wed Apr 16 10:04:22 2008 +0100
    12.2 +++ b/extras/mini-os/mm.c	Wed Apr 16 10:05:57 2008 +0100
    12.3 @@ -36,6 +36,7 @@
    12.4  
    12.5  #include <os.h>
    12.6  #include <hypervisor.h>
    12.7 +#include <xen/memory.h>
    12.8  #include <mm.h>
    12.9  #include <types.h>
   12.10  #include <lib.h>
   12.11 @@ -360,6 +361,17 @@ void free_pages(void *pointer, int order
   12.12     
   12.13  }
   12.14  
   12.15 +int free_physical_pages(xen_pfn_t *mfns, int n)
   12.16 +{
   12.17 +    struct xen_memory_reservation reservation;
   12.18 +
   12.19 +    set_xen_guest_handle(reservation.extent_start, mfns);
   12.20 +    reservation.nr_extents = n;
   12.21 +    reservation.extent_order = 0;
   12.22 +    reservation.domid = DOMID_SELF;
   12.23 +    return HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation);
   12.24 +}
   12.25 +
   12.26  #ifdef HAVE_LIBC
   12.27  void *sbrk(ptrdiff_t increment)
   12.28  {
    13.1 --- a/tools/ioemu/vl.c	Wed Apr 16 10:04:22 2008 +0100
    13.2 +++ b/tools/ioemu/vl.c	Wed Apr 16 10:05:57 2008 +0100
    13.3 @@ -140,9 +140,9 @@
    13.4  #define MAX_IOPORTS 65536
    13.5  
    13.6  const char *bios_dir = CONFIG_QEMU_SHAREDIR;
    13.7 -void **ioport_opaque;
    13.8 -IOPortReadFunc *(*ioport_read_table)[MAX_IOPORTS];
    13.9 -IOPortWriteFunc *(*ioport_write_table)[MAX_IOPORTS];
   13.10 +void *ioport_opaque[MAX_IOPORTS];
   13.11 +IOPortReadFunc *ioport_read_table[3][MAX_IOPORTS];
   13.12 +IOPortWriteFunc *ioport_write_table[3][MAX_IOPORTS];
   13.13  /* Note: bs_table[MAX_DISKS] is a dummy block driver if none available
   13.14     to store the VM snapshots */
   13.15  BlockDriverState *bs_table[MAX_DISKS + MAX_SCSI_DISKS + 1], *fd_table[MAX_FD];
   13.16 @@ -281,9 +281,6 @@ void default_ioport_writel(void *opaque,
   13.17  
   13.18  void init_ioports(void)
   13.19  {
   13.20 -    ioport_opaque = calloc(MAX_IOPORTS, sizeof(*ioport_opaque));
   13.21 -    ioport_read_table = calloc(3 * MAX_IOPORTS, sizeof(**ioport_read_table));
   13.22 -    ioport_write_table = calloc(3 * MAX_IOPORTS, sizeof(**ioport_write_table));
   13.23  }
   13.24  
   13.25  /* size is the word size in byte */