ia64/xen-unstable

changeset 10061:dc213d745642

Allow linking of mini-os with application-specific object code.
From: Jacob Gorm Hansen
Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Mon May 15 16:32:09 2006 +0100 (2006-05-15)
parents cb70d4f8d718
children 4fd6ba0e3336
files extras/mini-os/Makefile extras/mini-os/include/mm.h extras/mini-os/kernel.c extras/mini-os/mm.c
line diff
     1.1 --- a/extras/mini-os/Makefile	Mon May 15 07:51:07 2006 +0100
     1.2 +++ b/extras/mini-os/Makefile	Mon May 15 16:32:09 2006 +0100
     1.3 @@ -6,18 +6,23 @@ include $(CURDIR)/../../Config.mk
     1.4  override TARGET_ARCH     := $(XEN_TARGET_ARCH)
     1.5  
     1.6  # NB. '-Wcast-qual' is nasty, so I omitted it.
     1.7 -CFLAGS := -fno-builtin -Wall -Werror -Iinclude/ -Wredundant-decls -Wno-format
     1.8 +CFLAGS := -fno-builtin -Wall -Werror -Wredundant-decls -Wno-format
     1.9  CFLAGS += -Wstrict-prototypes -Wnested-externs -Wpointer-arith -Winline
    1.10  
    1.11 +override CPPFLAGS := -Iinclude $(CPPFLAGS)
    1.12 +ASFLAGS = -D__ASSEMBLY__
    1.13 +
    1.14 +LDFLAGS := -N -T minios-$(TARGET_ARCH).lds
    1.15 +
    1.16  ifeq ($(TARGET_ARCH),x86_32)
    1.17  CFLAGS += -m32 -march=i686
    1.18 -LDFLAGS := -m elf_i386
    1.19 +LDFLAGS += -m elf_i386
    1.20  endif
    1.21  
    1.22  ifeq ($(TARGET_ARCH),x86_64)
    1.23  CFLAGS += -m64 -mno-red-zone -fpic -fno-reorder-blocks
    1.24  CFLAGS += -fno-asynchronous-unwind-tables
    1.25 -LDFLAGS := -m elf_x86_64
    1.26 +LDFLAGS += -m elf_x86_64
    1.27  endif
    1.28  
    1.29  ifeq ($(debug),y)
    1.30 @@ -28,12 +33,12 @@ endif
    1.31  
    1.32  TARGET := mini-os
    1.33  
    1.34 -OBJS := $(TARGET_ARCH).o
    1.35 -OBJS += $(patsubst %.c,%.o,$(wildcard *.c))
    1.36 +HEAD := $(TARGET_ARCH).o
    1.37 +OBJS := $(patsubst %.c,%.o,$(wildcard *.c))
    1.38  OBJS += $(patsubst %.c,%.o,$(wildcard lib/*.c))
    1.39  OBJS += $(patsubst %.c,%.o,$(wildcard xenbus/*.c))
    1.40  OBJS += $(patsubst %.c,%.o,$(wildcard console/*.c))
    1.41 -										   
    1.42 +
    1.43  HDRS := $(wildcard include/*.h)
    1.44  HDRS += $(wildcard include/xen/*.h)
    1.45  
    1.46 @@ -44,21 +49,25 @@ default: $(TARGET)
    1.47  links:
    1.48  	[ -e include/xen ] || ln -sf ../../../xen/include/public include/xen
    1.49  
    1.50 -$(TARGET): links $(OBJS)
    1.51 -	$(LD) -N -T minios-$(TARGET_ARCH).lds $(OBJS) -o $@.elf
    1.52 +libminios.a: $(OBJS) $(HEAD)
    1.53 +	ar r libminios.a $(HEAD) $(OBJS)
    1.54 +
    1.55 +$(TARGET): links libminios.a $(HEAD)
    1.56 +	$(LD) $(LDFLAGS) $(HEAD) -L. -lminios -o $@.elf
    1.57  	gzip -f -9 -c $@.elf >$@.gz
    1.58  
    1.59  .PHONY: clean
    1.60  clean:
    1.61  	find . -type f -name '*.o' | xargs rm -f
    1.62  	rm -f *.o *~ core $(TARGET).elf $(TARGET).raw $(TARGET) $(TARGET).gz
    1.63 +	rm -f libminios.a
    1.64  	find . -type l | xargs rm -f
    1.65  
    1.66  %.o: %.c $(HDRS) Makefile
    1.67 -	$(CC) $(CFLAGS) -c $< -o $@
    1.68 +	$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
    1.69  
    1.70  %.o: %.S $(HDRS) Makefile
    1.71 -	$(CC) $(CFLAGS) -D__ASSEMBLY__ -c $< -o $@
    1.72 +	$(CC) $(ASFLAGS) $(CPPFLAGS) -c $< -o $@
    1.73  
    1.74  define all_sources
    1.75       ( find . -follow -name SCCS -prune -o -name '*.[chS]' -print )
     2.1 --- a/extras/mini-os/include/mm.h	Mon May 15 07:51:07 2006 +0100
     2.2 +++ b/extras/mini-os/include/mm.h	Mon May 15 16:32:09 2006 +0100
     2.3 @@ -130,6 +130,7 @@
     2.4  #define PAGE_ALIGN(addr)        (((addr)+PAGE_SIZE-1)&PAGE_MASK)
     2.5  
     2.6  extern unsigned long *phys_to_machine_mapping;
     2.7 +extern char _text, _etext, _edata, _end;
     2.8  #define pfn_to_mfn(_pfn) (phys_to_machine_mapping[(_pfn)])
     2.9  static __inline__ unsigned long phys_to_machine(unsigned long phys)
    2.10  {
    2.11 @@ -147,11 +148,7 @@ static __inline__ unsigned long machine_
    2.12      return phys;
    2.13  }
    2.14  
    2.15 -#if defined(__x86_64__)
    2.16 -#define VIRT_START              0xFFFFFFFF80000000UL
    2.17 -#elif defined(__i386__)
    2.18 -#define VIRT_START              0xC0000000UL
    2.19 -#endif
    2.20 +#define VIRT_START                 ((unsigned long)&_text)
    2.21  
    2.22  #define to_phys(x)                 ((unsigned long)(x)-VIRT_START)
    2.23  #define to_virt(x)                 ((void *)((unsigned long)(x)+VIRT_START))
     3.1 --- a/extras/mini-os/kernel.c	Mon May 15 07:51:07 2006 +0100
     3.2 +++ b/extras/mini-os/kernel.c	Mon May 15 16:32:09 2006 +0100
     3.3 @@ -106,6 +106,12 @@ void setup_xen_features(void)
     3.4      }
     3.5  }
     3.6  
     3.7 +/* This should be overridden by the application we are linked against. */
     3.8 +__attribute__((weak)) int app_main(start_info_t *si)
     3.9 +{
    3.10 +    printk("Dummy main: start_info=%p\n", si);
    3.11 +    return 0;
    3.12 +}
    3.13  
    3.14  /*
    3.15   * INITIAL C ENTRY POINT.
    3.16 @@ -165,12 +171,15 @@ void start_kernel(start_info_t *si)
    3.17      /* Init the console driver. */
    3.18      init_console();
    3.19   
    3.20 -   /* Init scheduler. */
    3.21 +    /* Init scheduler. */
    3.22      init_sched();
    3.23   
    3.24      /* Init XenBus from a separate thread */
    3.25      create_thread("init_xs", init_xs, NULL);
    3.26  
    3.27 +    /* Call (possibly overridden) app_main() */
    3.28 +    app_main(&start_info);
    3.29 +
    3.30      /* Everything initialised, start idle thread */
    3.31      run_idle_thread();
    3.32  }
     4.1 --- a/extras/mini-os/mm.c	Mon May 15 07:51:07 2006 +0100
     4.2 +++ b/extras/mini-os/mm.c	Mon May 15 16:32:09 2006 +0100
     4.3 @@ -50,7 +50,6 @@
     4.4  
     4.5  unsigned long *phys_to_machine_mapping;
     4.6  extern char *stack;
     4.7 -extern char _text, _etext, _edata, _end;
     4.8  extern void page_walk(unsigned long virt_addr);
     4.9  
    4.10  /*********************