# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1208336757 -3600
# Node ID 681cfd0eda786f5345b9e1dc226486dc04e1f4b3
# Parent 1ac2a314aa3cf10bb0e264942cdae7fda945d7b8
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@xxxxxxxxxxxxx>
---
extras/mini-os/Makefile | 29 ++++++++++++++----------
extras/mini-os/app.lds | 11 +++++++++
extras/mini-os/arch/ia64/minios-ia64.lds | 5 +++-
extras/mini-os/arch/x86/minios-x86_32.lds | 1
extras/mini-os/arch/x86/minios-x86_64.lds | 1
extras/mini-os/arch/x86/mm.c | 7 ------
extras/mini-os/include/ia64/arch_mm.h | 2 -
extras/mini-os/include/lib.h | 1
extras/mini-os/include/mm.h | 2 +
extras/mini-os/lib/sys.c | 35 ++++++++++++++++++++++++++++++
extras/mini-os/main.c | 2 +
extras/mini-os/mm.c | 12 ++++++++++
tools/ioemu/vl.c | 9 ++-----
13 files changed, 91 insertions(+), 26 deletions(-)
diff -r 1ac2a314aa3c -r 681cfd0eda78 extras/mini-os/Makefile
--- a/extras/mini-os/Makefile Wed Apr 16 10:04:22 2008 +0100
+++ b/extras/mini-os/Makefile Wed Apr 16 10:05:57 2008 +0100
@@ -19,6 +19,7 @@ include minios.mk
# Define some default flags for linking.
LDLIBS :=
+APP_LDLIBS :=
LDARCHLIB := -L$(TARGET_ARCH_DIR) -l$(ARCH_LIB_NAME)
LDFLAGS_FINAL := -T $(TARGET_ARCH_DIR)/minios-$(XEN_TARGET_ARCH).lds
@@ -33,6 +34,7 @@ SUBDIRS := lib xenbus console
SUBDIRS := lib xenbus console
# The common mini-os objects to build.
+APP_OBJS :=
OBJS := $(patsubst %.c,%.o,$(wildcard *.c))
OBJS += $(patsubst %.c,%.o,$(wildcard lib/*.c))
OBJS += $(patsubst %.c,%.o,$(wildcard xenbus/*.c))
@@ -75,28 +77,28 @@ OBJS := $(filter-out lwip%.o $(LWO), $(O
ifeq ($(caml),y)
CAMLLIB = $(shell ocamlc -where)
-OBJS += $(CAMLDIR)/caml.o
-OBJS += $(CAMLLIB)/libasmrun.a
+APP_OBJS += main-caml.o
+APP_OBJS += $(CAMLDIR)/caml.o
+APP_OBJS += $(CAMLLIB)/libasmrun.a
CFLAGS += -I$(CAMLLIB)
-LDLIBS += -lm
-else
+APP_LDLIBS += -lm
+endif
OBJS := $(filter-out main-caml.o, $(OBJS))
-endif
ifeq ($(qemu),y)
-OBJS += $(QEMUDIR)/i386-dm-stubdom/qemu.a $(QEMUDIR)/i386-dm-stubdom/libqemu.a
+APP_OBJS += $(QEMUDIR)/i386-dm-stubdom/qemu.a
$(QEMUDIR)/i386-dm-stubdom/libqemu.a
CFLAGS += -DCONFIG_QEMU
endif
ifneq ($(CDIR),)
-OBJS += $(CDIR)/main.a
-LDLIBS +=
+APP_OBJS += $(CDIR)/main.a
+APP_LDLIBS +=
endif
ifeq ($(libc),y)
LDLIBS += -L$(XEN_ROOT)/stubdom/libxc -lxenctrl -lxenguest
-LDLIBS += -lpci
-LDLIBS += -lz
+APP_LDLIBS += -lpci
+APP_LDLIBS += -lz
LDLIBS += -lc
endif
@@ -104,8 +106,11 @@ OBJS := $(filter-out daytime.o, $(OBJS))
OBJS := $(filter-out daytime.o, $(OBJS))
endif
-$(TARGET): links $(OBJS) arch_lib
- $(LD) -r $(LDFLAGS) $(HEAD_OBJ) $(OBJS) $(LDARCHLIB) $(LDLIBS) -o $@.o
+app.o: $(APP_OBJS) app.lds
+ $(LD) -r -d $(LDFLAGS) $^ $(APP_LDLIBS) --undefined main -o $@
+
+$(TARGET): links $(OBJS) app.o arch_lib
+ $(LD) -r $(LDFLAGS) $(HEAD_OBJ) app.o $(OBJS) $(LDARCHLIB) $(LDLIBS) -o
$@.o
$(OBJCOPY) -w -G $(GLOBAL_PREFIX)* -G _start $@.o $@.o
$(LD) $(LDFLAGS) $(LDFLAGS_FINAL) $@.o $(EXTRA_OBJS) -o $@
gzip -f -9 -c $@ >$@.gz
diff -r 1ac2a314aa3c -r 681cfd0eda78 extras/mini-os/app.lds
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/extras/mini-os/app.lds Wed Apr 16 10:05:57 2008 +0100
@@ -0,0 +1,11 @@
+SECTIONS
+{
+ .app.bss : {
+ __app_bss_start = . ;
+ *(.bss .bss.*)
+ *(COMMON)
+ *(.lbss .lbss.*)
+ *(LARGE_COMMON)
+ __app_bss_end = . ;
+ }
+}
diff -r 1ac2a314aa3c -r 681cfd0eda78 extras/mini-os/arch/ia64/minios-ia64.lds
--- a/extras/mini-os/arch/ia64/minios-ia64.lds Wed Apr 16 10:04:22 2008 +0100
+++ b/extras/mini-os/arch/ia64/minios-ia64.lds Wed Apr 16 10:05:57 2008 +0100
@@ -59,7 +59,10 @@ SECTIONS
{ *(.IA_64.unwind) }
.bss : AT(ADDR(.bss) - (((5<<(61))+0x100000000) - (1 << 20)))
- { *(.bss) }
+ {
+ *(.bss)
+ *(.app.bss)
+ }
_end = .;
diff -r 1ac2a314aa3c -r 681cfd0eda78 extras/mini-os/arch/x86/minios-x86_32.lds
--- a/extras/mini-os/arch/x86/minios-x86_32.lds Wed Apr 16 10:04:22 2008 +0100
+++ b/extras/mini-os/arch/x86/minios-x86_32.lds Wed Apr 16 10:05:57 2008 +0100
@@ -38,6 +38,7 @@ SECTIONS
__bss_start = .; /* BSS */
.bss : {
*(.bss)
+ *(.app.bss)
}
_end = . ;
diff -r 1ac2a314aa3c -r 681cfd0eda78 extras/mini-os/arch/x86/minios-x86_64.lds
--- a/extras/mini-os/arch/x86/minios-x86_64.lds Wed Apr 16 10:04:22 2008 +0100
+++ b/extras/mini-os/arch/x86/minios-x86_64.lds Wed Apr 16 10:05:57 2008 +0100
@@ -38,6 +38,7 @@ SECTIONS
__bss_start = .; /* BSS */
.bss : {
*(.bss)
+ *(.app.bss)
}
_end = . ;
diff -r 1ac2a314aa3c -r 681cfd0eda78 extras/mini-os/arch/x86/mm.c
--- a/extras/mini-os/arch/x86/mm.c Wed Apr 16 10:04:22 2008 +0100
+++ b/extras/mini-os/arch/x86/mm.c Wed Apr 16 10:05:57 2008 +0100
@@ -556,7 +556,6 @@ void *map_frames_ex(unsigned long *f, un
static void clear_bootstrap(void)
{
- struct xen_memory_reservation reservation;
xen_pfn_t mfns[] = { virt_to_mfn(&shared_info) };
int n = sizeof(mfns)/sizeof(*mfns);
pte_t nullpte = { };
@@ -567,11 +566,7 @@ static void clear_bootstrap(void)
if (HYPERVISOR_update_va_mapping((unsigned long) &_text, nullpte,
UVMF_INVLPG))
printk("Unable to unmap first page\n");
- set_xen_guest_handle(reservation.extent_start, mfns);
- reservation.nr_extents = n;
- reservation.extent_order = 0;
- reservation.domid = DOMID_SELF;
- if (HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation) != n)
+ if (free_physical_pages(mfns, n) != n)
printk("Unable to free bootstrap pages\n");
}
diff -r 1ac2a314aa3c -r 681cfd0eda78 extras/mini-os/include/ia64/arch_mm.h
--- a/extras/mini-os/include/ia64/arch_mm.h Wed Apr 16 10:04:22 2008 +0100
+++ b/extras/mini-os/include/ia64/arch_mm.h Wed Apr 16 10:05:57 2008 +0100
@@ -38,6 +38,6 @@
#define map_frames(f, n) map_frames_ex(f, n, 1, 0, 1, DOMID_SELF, 0, 0)
/* TODO */
#define map_zero(n, a) map_frames_ex(NULL, n, 0, 0, a, DOMID_SELF, 0, 0)
-#define do_map_zero(start, n) ((void)0)
+#define do_map_zero(start, n) ASSERT(n == 0)
#endif /* __ARCH_MM_H__ */
diff -r 1ac2a314aa3c -r 681cfd0eda78 extras/mini-os/include/lib.h
--- a/extras/mini-os/include/lib.h Wed Apr 16 10:04:22 2008 +0100
+++ b/extras/mini-os/include/lib.h Wed Apr 16 10:05:57 2008 +0100
@@ -187,6 +187,7 @@ int alloc_fd(enum fd_type type);
int alloc_fd(enum fd_type type);
void close_all_files(void);
extern struct thread *main_thread;
+void sparse(unsigned long data, size_t size);
#endif
#endif /* _LIB_H_ */
diff -r 1ac2a314aa3c -r 681cfd0eda78 extras/mini-os/include/mm.h
--- a/extras/mini-os/include/mm.h Wed Apr 16 10:04:22 2008 +0100
+++ b/extras/mini-os/include/mm.h Wed Apr 16 10:05:57 2008 +0100
@@ -70,4 +70,6 @@ extern unsigned long heap, brk, heap_map
extern unsigned long heap, brk, heap_mapped, heap_end;
#endif
+int free_physical_pages(xen_pfn_t *mfns, int n);
+
#endif /* _MM_H_ */
diff -r 1ac2a314aa3c -r 681cfd0eda78 extras/mini-os/lib/sys.c
--- a/extras/mini-os/lib/sys.c Wed Apr 16 10:04:22 2008 +0100
+++ b/extras/mini-os/lib/sys.c Wed Apr 16 10:05:57 2008 +0100
@@ -1108,6 +1108,41 @@ int munmap(void *start, size_t length)
return 0;
}
+void sparse(unsigned long data, size_t size)
+{
+ unsigned long newdata;
+ xen_pfn_t *mfns;
+ int i, n;
+
+ newdata = (data + PAGE_SIZE - 1) & PAGE_MASK;
+ if (newdata - data > size)
+ return;
+ size -= newdata - data;
+ data = newdata;
+ n = size / PAGE_SIZE;
+ size = n * PAGE_SIZE;
+
+ mfns = malloc(n * sizeof(*mfns));
+ for (i = 0; i < n; i++) {
+#ifdef LIBC_DEBUG
+ int j;
+ for (j=0; j<PAGE_SIZE; j++)
+ if (((char*)data + i * PAGE_SIZE)[j]) {
+ printk("%lx is not zero!\n", data + i * PAGE_SIZE + j);
+ exit(1);
+ }
+#endif
+ mfns[i] = virtual_to_mfn(data + i * PAGE_SIZE);
+ }
+
+ printk("sparsing %ldMB at %lx\n", size >> 20, data);
+
+ munmap((void *) data, size);
+ free_physical_pages(mfns, n);
+ do_map_zero(data, n);
+}
+
+
/* Not supported by FS yet. */
unsupported_function_crash(link);
unsupported_function(int, readlink, -1);
diff -r 1ac2a314aa3c -r 681cfd0eda78 extras/mini-os/main.c
--- a/extras/mini-os/main.c Wed Apr 16 10:04:22 2008 +0100
+++ b/extras/mini-os/main.c Wed Apr 16 10:05:57 2008 +0100
@@ -39,6 +39,7 @@ void _fini(void)
{
}
+extern char __app_bss_start, __app_bss_end;
static void call_main(void *p)
{
char *args, /**path,*/ *msg, *c;
@@ -56,6 +57,7 @@ static void call_main(void *p)
* crashing. */
//sleep(1);
+ sparse((unsigned long) &__app_bss_start, &__app_bss_end -
&__app_bss_start);
start_networking();
init_fs_frontend();
diff -r 1ac2a314aa3c -r 681cfd0eda78 extras/mini-os/mm.c
--- a/extras/mini-os/mm.c Wed Apr 16 10:04:22 2008 +0100
+++ b/extras/mini-os/mm.c Wed Apr 16 10:05:57 2008 +0100
@@ -36,6 +36,7 @@
#include <os.h>
#include <hypervisor.h>
+#include <xen/memory.h>
#include <mm.h>
#include <types.h>
#include <lib.h>
@@ -360,6 +361,17 @@ void free_pages(void *pointer, int order
}
+int free_physical_pages(xen_pfn_t *mfns, int n)
+{
+ struct xen_memory_reservation reservation;
+
+ set_xen_guest_handle(reservation.extent_start, mfns);
+ reservation.nr_extents = n;
+ reservation.extent_order = 0;
+ reservation.domid = DOMID_SELF;
+ return HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation);
+}
+
#ifdef HAVE_LIBC
void *sbrk(ptrdiff_t increment)
{
diff -r 1ac2a314aa3c -r 681cfd0eda78 tools/ioemu/vl.c
--- a/tools/ioemu/vl.c Wed Apr 16 10:04:22 2008 +0100
+++ b/tools/ioemu/vl.c Wed Apr 16 10:05:57 2008 +0100
@@ -140,9 +140,9 @@
#define MAX_IOPORTS 65536
const char *bios_dir = CONFIG_QEMU_SHAREDIR;
-void **ioport_opaque;
-IOPortReadFunc *(*ioport_read_table)[MAX_IOPORTS];
-IOPortWriteFunc *(*ioport_write_table)[MAX_IOPORTS];
+void *ioport_opaque[MAX_IOPORTS];
+IOPortReadFunc *ioport_read_table[3][MAX_IOPORTS];
+IOPortWriteFunc *ioport_write_table[3][MAX_IOPORTS];
/* Note: bs_table[MAX_DISKS] is a dummy block driver if none available
to store the VM snapshots */
BlockDriverState *bs_table[MAX_DISKS + MAX_SCSI_DISKS + 1], *fd_table[MAX_FD];
@@ -281,9 +281,6 @@ void default_ioport_writel(void *opaque,
void init_ioports(void)
{
- ioport_opaque = calloc(MAX_IOPORTS, sizeof(*ioport_opaque));
- ioport_read_table = calloc(3 * MAX_IOPORTS, sizeof(**ioport_read_table));
- ioport_write_table = calloc(3 * MAX_IOPORTS, sizeof(**ioport_write_table));
}
/* size is the word size in byte */
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|