xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Kiper <daniel.kiper@oracle.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: jgross@suse.com, sstabellini@kernel.org, konrad.wilk@oracle.com,
	cardoe@cardoe.com, pgnet.dev@gmail.com, ning.sun@intel.com,
	julien.grall@arm.com, jbeulich@suse.com,
	xen-devel@lists.xenproject.org, qiaowei.ren@intel.com,
	gang.wei@intel.com, fu.wei@linaro.org
Subject: Re: [PATCH v12 02/10] x86: add multiboot2 protocol support
Date: Fri, 20 Jan 2017 18:24:05 +0100	[thread overview]
Message-ID: <20170120172405.GY23864@olila.local.net-space.pl> (raw)
In-Reply-To: <9916b930-2938-9eaf-b165-42d54218b61a@citrix.com>

On Fri, Jan 20, 2017 at 04:52:30PM +0000, Andrew Cooper wrote:
> On 20/01/17 01:34, Daniel Kiper wrote:
> > @@ -101,3 +112,126 @@ multiboot_info_t __stdcall *reloc(u32 mbi_in, u32 trampoline)
> >
> >      return mbi_out;
> >  }
> > +
> > +static multiboot_info_t *mbi2_reloc(u32 mbi_in)
> > +{
> > +    const multiboot2_fixed_t *mbi_fix = _p(mbi_in);
> > +    const multiboot2_memory_map_t *mmap_src;
> > +    const multiboot2_tag_t *tag;
> > +    module_t *mbi_out_mods = NULL;
> > +    memory_map_t *mmap_dst;
> > +    multiboot_info_t *mbi_out;
> > +    u32 ptr;
> > +    unsigned int i, mod_idx = 0;
> > +
> > +    ptr = alloc_mem(sizeof(*mbi_out));
> > +    mbi_out = _p(ptr);
> > +    zero_mem(ptr, sizeof(*mbi_out));
> > +
> > +    /* Skip Multiboot2 information fixed part. */
> > +    ptr = ALIGN_UP(mbi_in + sizeof(*mbi_fix), MULTIBOOT2_TAG_ALIGN);
> > +
> > +    /* Get the number of modules. */
> > +    for ( tag = _p(ptr); (u32)tag - mbi_in < mbi_fix->total_size;
> > +          tag = _p(ALIGN_UP((u32)tag + tag->size, MULTIBOOT2_TAG_ALIGN)) )
> > +    {
> > +        if ( tag->type == MULTIBOOT2_TAG_TYPE_MODULE )
> > +            ++mbi_out->mods_count;
> > +        else if ( tag->type == MULTIBOOT2_TAG_TYPE_END )
> > +            break;
> > +    }
> > +
> > +    if ( mbi_out->mods_count )
> > +    {
> > +        mbi_out->flags |= MBI_MODULES;
> > +        mbi_out->mods_addr = alloc_mem(mbi_out->mods_count * sizeof(*mbi_out_mods));
> > +        mbi_out_mods = _p(mbi_out->mods_addr);
> > +    }
> > +
> > +    /* Skip Multiboot2 information fixed part. */
> > +    ptr = ALIGN_UP(mbi_in + sizeof(*mbi_fix), MULTIBOOT2_TAG_ALIGN);
> > +
> > +    /* Put all needed data into mbi_out. */
> > +    for ( tag = _p(ptr); (u32)tag - mbi_in < mbi_fix->total_size;
> > +          tag = _p(ALIGN_UP((u32)tag + tag->size, MULTIBOOT2_TAG_ALIGN)) )
> > +        switch ( tag->type )
> > +        {
> > +        case MULTIBOOT2_TAG_TYPE_BOOT_LOADER_NAME:
> > +            mbi_out->flags |= MBI_LOADERNAME;
> > +            ptr = get_mb2_string(tag, string, string);
> > +            mbi_out->boot_loader_name = copy_string(ptr);
> > +            break;
> > +
> > +        case MULTIBOOT2_TAG_TYPE_CMDLINE:
> > +            mbi_out->flags |= MBI_CMDLINE;
> > +            ptr = get_mb2_string(tag, string, string);
> > +            mbi_out->cmdline = copy_string(ptr);
> > +            break;
> > +
> > +        case MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO:
> > +            mbi_out->flags |= MBI_MEMLIMITS;
> > +            mbi_out->mem_lower = get_mb2_data(tag, basic_meminfo, mem_lower);
> > +            mbi_out->mem_upper = get_mb2_data(tag, basic_meminfo, mem_upper);
> > +            break;
> > +
> > +        case MULTIBOOT2_TAG_TYPE_MMAP:
> > +            if ( get_mb2_data(tag, mmap, entry_size) < sizeof(*mmap_src) )
> > +                break;
> > +
> > +            mbi_out->flags |= MBI_MEMMAP;
> > +            mbi_out->mmap_length = get_mb2_data(tag, mmap, size);
> > +            mbi_out->mmap_length -= sizeof(multiboot2_tag_mmap_t);
> > +            mbi_out->mmap_length /= get_mb2_data(tag, mmap, entry_size);
> > +            mbi_out->mmap_length *= sizeof(*mmap_dst);
> > +
> > +            mbi_out->mmap_addr = alloc_mem(mbi_out->mmap_length);
> > +
> > +            mmap_src = get_mb2_data(tag, mmap, entries);
> > +            mmap_dst = _p(mbi_out->mmap_addr);
> > +
> > +            for ( i = 0; i < mbi_out->mmap_length / sizeof(*mmap_dst); i++ )
> > +            {
> > +                /* Init size member properly. */
> > +                mmap_dst[i].size = sizeof(*mmap_dst);
> > +                mmap_dst[i].size -= sizeof(mmap_dst[i].size);
> > +                /* Now copy a given region data. */
> > +                mmap_dst[i].base_addr_low = (u32)mmap_src->addr;
> > +                mmap_dst[i].base_addr_high = (u32)(mmap_src->addr >> 32);
> > +                mmap_dst[i].length_low = (u32)mmap_src->len;
> > +                mmap_dst[i].length_high = (u32)(mmap_src->len >> 32);
> > +                mmap_dst[i].type = mmap_src->type;
> > +                mmap_src = _p(mmap_src) + get_mb2_data(tag, mmap, entry_size);
> > +            }
> > +            break;
> > +
> > +        case MULTIBOOT2_TAG_TYPE_MODULE:
> > +            if ( mod_idx >= mbi_out->mods_count )
> > +                break;
> > +
> > +            mbi_out_mods[mod_idx].mod_start = get_mb2_data(tag, module, mod_start);
> > +            mbi_out_mods[mod_idx].mod_end = get_mb2_data(tag, module, mod_end);
> > +            ptr = get_mb2_string(tag, module, cmdline);
> > +            mbi_out_mods[mod_idx].string = copy_string(ptr);
> > +            mbi_out_mods[mod_idx].reserved = 0;
> > +            ++mod_idx;
> > +            break;
> > +
> > +        case MULTIBOOT2_TAG_TYPE_END:
> > +            return mbi_out;
> > +
> > +        default:
> > +            break;
> > +        }
> > +
> > +    return mbi_out;
> > +}
> > +
> > +multiboot_info_t __stdcall *reloc(u32 mb_magic, u32 mbi_in, u32 trampoline)
> > +{
> > +    alloc = trampoline;
> > +
> > +    if ( mb_magic == MULTIBOOT2_BOOTLOADER_MAGIC )
> > +        return mbi2_reloc(mbi_in);
> > +    else
> > +        return mbi_reloc(mbi_in);
> > +}
>
> Can we get a
>
> /*
>
>  * Local
> variables:
>
>  * mode:
> C
>
>  * c-file-style:
> "BSD"
>
>  * c-basic-offset:
> 4
>
>  * indent-tabs-mode:
> nil
>
>  *
> End:
>
>  */
>
> here please?

Will do.

> With this, Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>

Thanks!

> With this patch present, should legacy booting with MB2 work properly?
> If so, I have a good mind to take the patch now so it can get better
> testing (at which point I can fix up this one issue).

Yep, however, you have to remember that there is no support for
relocatable images here. It is added by subsequent patches.

Daniel

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  reply	other threads:[~2017-01-20 17:24 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-20  1:34 [PATCH v12 00/10] x86: multiboot2 protocol support Daniel Kiper
2017-01-20  1:34 ` [PATCH v12 01/10] x86/boot: implement early command line parser in C Daniel Kiper
2017-01-20 16:37   ` Doug Goldstein
2017-01-20 16:41     ` Doug Goldstein
2017-01-20  1:34 ` [PATCH v12 02/10] x86: add multiboot2 protocol support Daniel Kiper
2017-01-20 16:52   ` Andrew Cooper
2017-01-20 17:24     ` Daniel Kiper [this message]
2017-01-20 18:07       ` Andrew Cooper
2017-01-20 19:01   ` Doug Goldstein
2017-01-20  1:34 ` [PATCH v12 03/10] efi: build xen.gz with EFI code Daniel Kiper
2017-01-20  1:34 ` [PATCH v12 04/10] efi: create new early memory allocator Daniel Kiper
2017-01-20  1:34 ` [PATCH v12 05/10] x86: add multiboot2 protocol support for EFI platforms Daniel Kiper
2017-01-20  4:37   ` Doug Goldstein
2017-01-20  9:46   ` Jan Beulich
2017-01-20 11:43     ` Daniel Kiper
2017-01-20 12:40       ` Jan Beulich
2017-01-20 13:46         ` Daniel Kiper
2017-01-20 14:10           ` Jan Beulich
2017-01-20 14:43             ` Daniel Kiper
2017-01-20 15:23               ` Jan Beulich
2017-01-20 19:04   ` Doug Goldstein
2017-01-20 19:05     ` Andrew Cooper
2017-01-20 19:34   ` Doug Goldstein
2017-01-20 21:42     ` Daniel Kiper
2017-01-20  1:34 ` [PATCH v12 06/10] x86: change default load address from 1 MiB to 2 MiB Daniel Kiper
2017-01-20  4:06   ` Doug Goldstein
2017-01-20  8:49     ` Jan Beulich
2017-01-20 10:29       ` Daniel Kiper
2017-01-20  1:34 ` [PATCH v12 07/10] x86/setup: use XEN_IMG_OFFSET instead of Daniel Kiper
2017-01-20  4:07   ` Doug Goldstein
2017-01-20  1:34 ` [PATCH v12 08/10] x86: make Xen early boot code relocatable Daniel Kiper
2017-01-20  1:34 ` [PATCH v12 09/10] x86/boot: rename sym_phys() to sym_offs() Daniel Kiper
2017-01-20  4:08   ` Doug Goldstein
2017-01-20  1:34 ` [PATCH v12 10/10] x86: add multiboot2 protocol support for relocatable images Daniel Kiper
2017-01-20  4:08   ` Doug Goldstein
2017-01-20 16:22 ` [PATCH v12 00/10] x86: multiboot2 protocol support Doug Goldstein
2017-01-20 17:21   ` Daniel Kiper
2017-01-20 18:53     ` Doug Goldstein
2017-01-20 19:28     ` Doug Goldstein
2017-01-20 19:42 ` Doug Goldstein
2017-01-20 19:52   ` Doug Goldstein
2017-01-20 20:01   ` Konrad Rzeszutek Wilk
2017-01-20 21:54   ` Daniel Kiper
2017-01-23 13:08     ` Daniel Kiper
2017-01-23 14:28       ` Konrad Rzeszutek Wilk
2017-01-23 16:03         ` Doug Goldstein
2017-01-23 18:12           ` Daniel Kiper
2017-01-23 15:35       ` Doug Goldstein
2017-01-23 15:45         ` Daniel Kiper
2017-01-23 16:07           ` Doug Goldstein
2017-01-23 18:16             ` Daniel Kiper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170120172405.GY23864@olila.local.net-space.pl \
    --to=daniel.kiper@oracle.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=cardoe@cardoe.com \
    --cc=fu.wei@linaro.org \
    --cc=gang.wei@intel.com \
    --cc=jbeulich@suse.com \
    --cc=jgross@suse.com \
    --cc=julien.grall@arm.com \
    --cc=konrad.wilk@oracle.com \
    --cc=ning.sun@intel.com \
    --cc=pgnet.dev@gmail.com \
    --cc=qiaowei.ren@intel.com \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).