direct-io.hg

changeset 4447:da63c1ee596f

bitkeeper revision 1.1159.258.88 (424f0cd9Oldi24NGanGDdr82_K9qpQ)

From: YAMAMOTO Takashi <yamt@mwd.biglobe.ne.jp>
Add support to domain0 builder to load a (Net)BSD symtab for domain0.

Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk[cl349]
date Sat Apr 02 21:21:29 2005 +0000 (2005-04-02)
parents 88fed5c27d6d
children ccf5f154c35d b719ddfcd506
files xen/arch/x86/domain.c xen/common/elf.c xen/include/xen/elf.h xen/include/xen/sched.h
line diff
     1.1 --- a/xen/arch/x86/domain.c	Fri Apr 01 17:44:25 2005 +0000
     1.2 +++ b/xen/arch/x86/domain.c	Sat Apr 02 21:21:29 2005 +0000
     1.3 @@ -667,6 +667,9 @@ int construct_dom0(struct domain *p,
     1.4      if ( rc != 0 )
     1.5          return rc;
     1.6  
     1.7 +    if (dsi.load_bsd_symtab)
     1.8 +        loadelfsymtab(image_start, 0, &dsi);
     1.9 +
    1.10      /* Set up domain options */
    1.11      if ( dsi.use_writable_pagetables )
    1.12          vm_assist(p, VMASST_CMD_enable, VMASST_TYPE_writable_pagetables);
    1.13 @@ -684,7 +687,7 @@ int construct_dom0(struct domain *p,
    1.14       * read-only). We have a pair of simultaneous equations in two unknowns, 
    1.15       * which we solve by exhaustive search.
    1.16       */
    1.17 -    vinitrd_start    = round_pgup(dsi.v_kernend);
    1.18 +    vinitrd_start    = round_pgup(dsi.v_end);
    1.19      vinitrd_end      = vinitrd_start + initrd_len;
    1.20      vphysmap_start   = round_pgup(vinitrd_end);
    1.21      vphysmap_end     = vphysmap_start + (nr_pages * sizeof(unsigned long));
    1.22 @@ -884,6 +887,9 @@ int construct_dom0(struct domain *p,
    1.23      /* Copy the OS image. */
    1.24      (void)loadelfimage(image_start);
    1.25  
    1.26 +    if (dsi.load_bsd_symtab)
    1.27 +        loadelfsymtab(image_start, 1, &dsi);
    1.28 +
    1.29      /* Copy the initial ramdisk. */
    1.30      if ( initrd_len != 0 )
    1.31          memcpy((void *)vinitrd_start, initrd_start, initrd_len);
     2.1 --- a/xen/common/elf.c	Fri Apr 01 17:44:25 2005 +0000
     2.2 +++ b/xen/common/elf.c	Sat Apr 02 21:21:29 2005 +0000
     2.3 @@ -125,12 +125,18 @@ int parseelfimage(char *elfbase,
     2.4          
     2.5          if ( (p = strstr(guestinfo, "PT_MODE_WRITABLE")) != NULL )
     2.6              dsi->use_writable_pagetables = 1;
     2.7 +
     2.8 +        if ( (p = strstr(guestinfo, "BSD_SYMTAB")) != NULL )
     2.9 +            dsi->load_bsd_symtab = 1;
    2.10 +
    2.11      }
    2.12  
    2.13      dsi->v_kernstart = kernstart;
    2.14      dsi->v_kernend   = kernend;
    2.15      dsi->v_kernentry = ehdr->e_entry;
    2.16  
    2.17 +    dsi->v_end       = dsi->v_kernend;
    2.18 +
    2.19      return 0;
    2.20  }
    2.21  
    2.22 @@ -155,3 +161,97 @@ int loadelfimage(char *elfbase)
    2.23  
    2.24      return 0;
    2.25  }
    2.26 +
    2.27 +#define ELFROUND (ELFSIZE / 8)
    2.28 +
    2.29 +int loadelfsymtab(char *elfbase, int doload, struct domain_setup_info *dsi)
    2.30 +{
    2.31 +    Elf_Ehdr *ehdr = (Elf_Ehdr *)elfbase, *sym_ehdr;
    2.32 +    Elf_Shdr *shdr;
    2.33 +    unsigned long maxva, symva;
    2.34 +    char *p;
    2.35 +    int h, i;
    2.36 +
    2.37 +    maxva = (dsi->v_kernend + ELFROUND - 1) & ~(ELFROUND - 1);
    2.38 +    symva = maxva;
    2.39 +    maxva += sizeof(int);
    2.40 +    dsi->symtab_addr = maxva;
    2.41 +    dsi->symtab_len = 0;
    2.42 +    maxva += sizeof(Elf_Ehdr) + ehdr->e_shnum * sizeof(Elf_Shdr);
    2.43 +    maxva = (maxva + ELFROUND - 1) & ~(ELFROUND - 1);
    2.44 +    if (doload) {
    2.45 +	p = (void *)symva;
    2.46 +
    2.47 +	shdr = (Elf_Shdr *)(p + sizeof(int) + sizeof(Elf_Ehdr));
    2.48 +	memcpy(shdr, elfbase + ehdr->e_shoff, ehdr->e_shnum * sizeof(Elf_Shdr));
    2.49 +    } else {
    2.50 +	shdr = (Elf_Shdr *)(elfbase + ehdr->e_shoff);
    2.51 +	p = NULL; /* XXX: gcc */
    2.52 +    }
    2.53 +
    2.54 +    for ( h = 0; h < ehdr->e_shnum; h++ ) 
    2.55 +    {
    2.56 +        if ( shdr[h].sh_type == SHT_STRTAB )
    2.57 +        {
    2.58 +            /* Look for a strtab @i linked to symtab @h. */
    2.59 +            for ( i = 0; i < ehdr->e_shnum; i++ )
    2.60 +                if ( (shdr[i].sh_type == SHT_SYMTAB) &&
    2.61 +                     (shdr[i].sh_link == h) )
    2.62 +                    break;
    2.63 +            /* Skip symtab @h if we found no corresponding strtab @i. */
    2.64 +            if ( i == ehdr->e_shnum )
    2.65 +            {
    2.66 +		if (doload) {
    2.67 +		    shdr[h].sh_offset = 0;
    2.68 +		}
    2.69 +                continue;
    2.70 +            }
    2.71 +        }
    2.72 +
    2.73 +        if ( (shdr[h].sh_type == SHT_STRTAB) ||
    2.74 +             (shdr[h].sh_type == SHT_SYMTAB) )
    2.75 +        {
    2.76 +	    if (doload) {
    2.77 +		memcpy((void *)maxva, elfbase + shdr[h].sh_offset,
    2.78 +		    shdr[h].sh_size);
    2.79 +
    2.80 +		/* Mangled to be based on ELF header location. */
    2.81 +		shdr[h].sh_offset = maxva - dsi->symtab_addr;
    2.82 +
    2.83 +	    }
    2.84 +	    dsi->symtab_len += shdr[h].sh_size;
    2.85 +	    maxva += shdr[h].sh_size;
    2.86 +	    maxva = (maxva + ELFROUND - 1) & ~(ELFROUND - 1);
    2.87 +        }
    2.88 +
    2.89 +        if (doload) {
    2.90 +	    shdr[h].sh_name = 0;  /* Name is NULL. */
    2.91 +	}
    2.92 +    }
    2.93 +
    2.94 +    if ( dsi->symtab_len == 0 )
    2.95 +    {
    2.96 +        dsi->symtab_addr = 0;
    2.97 +        goto out;
    2.98 +    }
    2.99 +
   2.100 +    if (doload) {
   2.101 +	*(int *)p = maxva - dsi->symtab_addr;
   2.102 +	sym_ehdr = (Elf_Ehdr *)(p + sizeof(int));
   2.103 +	memcpy(sym_ehdr, ehdr, sizeof(Elf_Ehdr));
   2.104 +	sym_ehdr->e_phoff = 0;
   2.105 +	sym_ehdr->e_shoff = sizeof(Elf_Ehdr);
   2.106 +	sym_ehdr->e_phentsize = 0;
   2.107 +	sym_ehdr->e_phnum = 0;
   2.108 +	sym_ehdr->e_shstrndx = SHN_UNDEF;
   2.109 +    }
   2.110 +
   2.111 +#define round_pgup(_p)    (((_p)+(PAGE_SIZE-1))&PAGE_MASK) /* XXX */
   2.112 +
   2.113 +    dsi->symtab_len = maxva - dsi->symtab_addr;
   2.114 +    dsi->v_end = round_pgup(maxva);
   2.115 +
   2.116 + out:
   2.117 +
   2.118 +    return 0;
   2.119 +}
     3.1 --- a/xen/include/xen/elf.h	Fri Apr 01 17:44:25 2005 +0000
     3.2 +++ b/xen/include/xen/elf.h	Sat Apr 02 21:21:29 2005 +0000
     3.3 @@ -526,6 +526,7 @@ typedef struct {
     3.4  
     3.5  struct domain_setup_info;
     3.6  extern int loadelfimage(char *);
     3.7 +extern int loadelfsymtab(char *, int, struct domain_setup_info *);
     3.8  extern int parseelfimage(char *, unsigned long, struct domain_setup_info *);
     3.9  
    3.10  #endif /* __XEN_ELF_H__ */
     4.1 --- a/xen/include/xen/sched.h	Fri Apr 01 17:44:25 2005 +0000
     4.2 +++ b/xen/include/xen/sched.h	Sat Apr 02 21:21:29 2005 +0000
     4.3 @@ -119,11 +119,16 @@ struct domain
     4.4  struct domain_setup_info
     4.5  {
     4.6      unsigned long v_start;
     4.7 +    unsigned long v_end;
     4.8      unsigned long v_kernstart;
     4.9      unsigned long v_kernend;
    4.10      unsigned long v_kernentry;
    4.11  
    4.12      unsigned int use_writable_pagetables;
    4.13 +    unsigned int load_bsd_symtab;
    4.14 +
    4.15 +    unsigned long symtab_addr;
    4.16 +    unsigned long symtab_len;
    4.17  };
    4.18  
    4.19  #include <asm/uaccess.h> /* for KERNEL_DS */