From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Daniel Kiper <daniel.kiper@oracle.com>,
<xen-devel@lists.xenproject.org>, <grub-devel@gnu.org>
Cc: jgross@suse.com, keir@xen.org, ian.campbell@citrix.com,
phcoder@gmail.com, stefano.stabellini@eu.citrix.com,
roy.franz@linaro.org, ning.sun@intel.com,
david.vrabel@citrix.com, jbeulich@suse.com,
qiaowei.ren@intel.com, richard.l.maliszewski@intel.com,
gang.wei@intel.com, fu.wei@linaro.org
Subject: Re: [PATCH 02/18] x86/boot/reloc: create generic alloc and copy functions
Date: Fri, 30 Jan 2015 18:02:10 +0000 [thread overview]
Message-ID: <54CBC722.6010303@citrix.com> (raw)
In-Reply-To: <1422640462-28103-3-git-send-email-daniel.kiper@oracle.com>
On 30/01/15 17:54, Daniel Kiper wrote:
> Create generic alloc and copy functions. We need
> separate tools for memory allocation and copy to
> provide multiboot2 protocol support.
>
> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
> ---
> xen/arch/x86/boot/reloc.c | 52 ++++++++++++++++++++++++++++-----------------
> 1 file changed, 33 insertions(+), 19 deletions(-)
>
> diff --git a/xen/arch/x86/boot/reloc.c b/xen/arch/x86/boot/reloc.c
> index 63045c0..f964cda 100644
> --- a/xen/arch/x86/boot/reloc.c
> +++ b/xen/arch/x86/boot/reloc.c
> @@ -33,9 +33,10 @@ asm (
> typedef unsigned int u32;
> #include "../../../include/xen/multiboot.h"
>
> -static void *reloc_mbi_struct(void *old, unsigned int bytes)
> +static u32 alloc_struct(u32 bytes)
> {
> - void *new;
> + u32 s;
> +
> asm(
> " call 1f \n"
> "1: pop %%edx \n"
> @@ -43,50 +44,63 @@ static void *reloc_mbi_struct(void *old, unsigned int bytes)
> " sub %1,%0 \n"
> " and $~15,%0 \n"
> " mov %0,alloc-1b(%%edx) \n"
> - " mov %0,%%edi \n"
> - " rep movsb \n"
> - : "=&r" (new), "+c" (bytes), "+S" (old)
> - : : "edx", "edi", "memory");
> - return new;
> + : "=&r" (s) : "r" (bytes) : "edx", "memory");
> +
> + return s;
> +}
> +
> +static u32 copy_struct(u32 src, u32 bytes)
> +{
> + u32 dst, dst_asm;
> +
> + dst = alloc_struct(bytes);
> + dst_asm = dst;
> +
> + asm volatile("rep movsb" : "+S" (src), "+D" (dst_asm), "+c" (bytes) : : "memory");
> +
> + return dst;
> }
>
> -static char *reloc_mbi_string(char *old)
> +static u32 copy_string(u32 src)
> {
> char *p;
> - for ( p = old; *p != '\0'; p++ )
> +
> + if ( src == 0 )
> + return 0;
> +
> + for ( p = (char *)src; *p != '\0'; p++ )
> continue;
> - return reloc_mbi_struct(old, p - old + 1);
> +
> + return copy_struct(src, p - (char *)src + 1);
> }
>
> multiboot_info_t *reloc(multiboot_info_t *mbi_old)
> {
> - multiboot_info_t *mbi = reloc_mbi_struct(mbi_old, sizeof(*mbi));
> + multiboot_info_t *mbi = (multiboot_info_t *)copy_struct((u32)mbi_old, sizeof(*mbi));
> int i;
>
> if ( mbi->flags & MBI_CMDLINE )
> - mbi->cmdline = (u32)reloc_mbi_string((char *)mbi->cmdline);
> + mbi->cmdline = copy_string(mbi->cmdline);
>
> if ( mbi->flags & MBI_MODULES )
> {
> - module_t *mods = reloc_mbi_struct(
> - (module_t *)mbi->mods_addr, mbi->mods_count * sizeof(module_t));
> + module_t *mods = (module_t *)copy_struct(
> + mbi->mods_addr, mbi->mods_count * sizeof(module_t));
>
> mbi->mods_addr = (u32)mods;
>
> for ( i = 0; i < mbi->mods_count; i++ )
> {
> if ( mods[i].string )
> - mods[i].string = (u32)reloc_mbi_string((char *)mods[i].string);
> + mods[i].string = copy_string(mods[i].string);
> }
> }
>
> if ( mbi->flags & MBI_MEMMAP )
> - mbi->mmap_addr = (u32)reloc_mbi_struct(
> - (memory_map_t *)mbi->mmap_addr, mbi->mmap_length);
> + mbi->mmap_addr = copy_struct(mbi->mmap_addr, mbi->mmap_length);
>
> if ( mbi->flags & MBI_LOADERNAME )
> - mbi->boot_loader_name = (u32)reloc_mbi_string(
> - (char *)mbi->boot_loader_name);
> + mbi->boot_loader_name = copy_string(mbi->boot_loader_name);
>
> /* Mask features we don't understand or don't relocate. */
> mbi->flags &= (MBI_MEMLIMITS |
next prev parent reply other threads:[~2015-01-30 18:02 UTC|newest]
Thread overview: 92+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-30 17:54 [PATCH 00/18] x86: multiboot2 protocol support Daniel Kiper
2015-01-30 17:54 ` [PATCH 01/18] x86/boot/reloc: mask out MBI_BOOTDEV from mbi flags Daniel Kiper
2015-01-30 17:59 ` [Xen-devel] " Andrew Cooper
2015-01-30 17:54 ` [PATCH 02/18] x86/boot/reloc: create generic alloc and copy functions Daniel Kiper
2015-01-30 18:02 ` Andrew Cooper [this message]
2015-02-03 10:13 ` Jan Beulich
2015-01-30 17:54 ` [PATCH 03/18] x86/boot: use %ecx instead of %eax Daniel Kiper
2015-02-03 10:02 ` Jan Beulich
2015-02-03 17:43 ` Daniel Kiper
2015-01-30 17:54 ` [PATCH 04/18] xen/x86: add multiboot2 protocol support Daniel Kiper
2015-01-30 18:11 ` Andrew Cooper
2015-02-20 16:06 ` Jan Beulich
2015-03-27 10:56 ` Daniel Kiper
2015-03-27 11:20 ` Jan Beulich
2015-03-27 12:22 ` Daniel Kiper
2015-03-27 12:42 ` Jan Beulich
2015-01-30 17:54 ` [PATCH 05/18] efi: split efi_enabled to efi_platform and efi_loader Daniel Kiper
2015-02-20 16:17 ` Jan Beulich
2015-03-27 13:32 ` Daniel Kiper
2015-03-27 13:43 ` Jan Beulich
2015-03-27 13:53 ` Andrew Cooper
2015-03-27 14:04 ` Jan Beulich
2015-03-27 14:09 ` Lennart Sorensen
2015-03-27 14:19 ` [Xen-devel] " Jan Beulich
2015-03-27 14:21 ` Lennart Sorensen
2015-03-02 17:21 ` Stefano Stabellini
2015-03-02 18:43 ` Roy Franz
2015-03-02 23:40 ` Roy Franz
2015-03-03 8:49 ` Jan Beulich
2015-01-30 17:54 ` [PATCH 06/18] x86: remove commented out stale references to efi_enabled Daniel Kiper
2015-01-30 17:54 ` [PATCH 07/18] efi: run EFI specific code on EFI platform only Daniel Kiper
2015-02-20 16:47 ` Jan Beulich
2015-01-30 17:54 ` [PATCH 08/18] efi: build xen.gz with EFI code Daniel Kiper
2015-03-02 16:14 ` Jan Beulich
2015-03-27 11:14 ` Daniel Kiper
2015-03-27 11:46 ` Jan Beulich
2015-03-27 11:54 ` Andrew Cooper
2015-01-30 17:54 ` [PATCH 09/18] efi: create efi_init() Daniel Kiper
2015-01-30 17:54 ` [PATCH 10/18] efi: create efi_console_set_mode() Daniel Kiper
2015-01-30 17:54 ` [PATCH 11/18] efi: create efi_get_gop() Daniel Kiper
2015-01-30 17:54 ` [PATCH 12/18] efi: create efi_find_gop_mode() Daniel Kiper
2015-01-30 17:54 ` [PATCH 13/18] efi: create efi_tables() Daniel Kiper
2015-01-30 17:54 ` [PATCH 14/18] efi: create efi_variables() Daniel Kiper
2015-01-30 17:54 ` [PATCH 15/18] efi: create efi_set_gop_mode() Daniel Kiper
2015-01-30 17:54 ` [PATCH 16/18] efi: create efi_exit_boot() Daniel Kiper
2015-03-02 16:45 ` Jan Beulich
2015-03-27 12:00 ` Daniel Kiper
2015-03-27 12:10 ` Jan Beulich
2015-03-27 12:43 ` Daniel Kiper
2015-03-27 13:17 ` Ian Campbell
2015-01-30 17:54 ` [PATCH 17/18] x86/efi: create new early memory allocator Daniel Kiper
2015-03-02 17:23 ` Jan Beulich
2015-03-02 20:25 ` Roy Franz
2015-03-03 8:04 ` Jan Beulich
2015-03-03 9:39 ` Daniel Kiper
2015-03-27 12:57 ` Daniel Kiper
2015-03-27 13:35 ` Jan Beulich
2015-03-27 14:28 ` Daniel Kiper
2015-01-30 17:54 ` [PATCH 18/18] x86: add multiboot2 protocol support for EFI platforms Daniel Kiper
2015-01-30 19:06 ` Andrew Cooper
2015-01-30 23:43 ` Daniel Kiper
2015-01-31 0:47 ` Andrew Cooper
2015-02-10 21:27 ` Daniel Kiper
2015-02-10 22:41 ` Andrew Cooper
2015-02-11 8:20 ` Jan Beulich
2015-02-14 17:23 ` Andrei Borzenkov
2015-02-15 21:00 ` Daniel Kiper
2015-03-17 10:32 ` Jan Beulich
2015-03-17 12:47 ` Daniel Kiper
2015-03-27 13:06 ` Daniel Kiper
2015-03-27 13:36 ` Jan Beulich
2015-03-27 14:26 ` Daniel Kiper
2015-03-27 14:34 ` Jan Beulich
2015-03-27 14:57 ` Daniel Kiper
2015-03-27 15:06 ` Jan Beulich
2015-03-27 15:10 ` Daniel Kiper
2015-01-30 18:04 ` [PATCH 00/18] x86: multiboot2 protocol support Daniel Kiper
2015-01-31 7:22 ` João Jerónimo
2015-02-02 9:28 ` Jan Beulich
2015-02-03 17:14 ` Daniel Kiper
2015-02-04 9:04 ` Andrew Cooper
2015-02-04 9:51 ` Jan Beulich
2015-02-05 10:59 ` Andrew Cooper
2015-02-05 11:50 ` Vladimir 'phcoder' Serbinenko
2015-02-05 12:00 ` Jan Beulich
2015-02-09 17:59 ` Daniel Kiper
2015-02-10 9:05 ` Jan Beulich
2015-03-03 12:10 ` Ian Campbell
2015-03-03 12:36 ` Daniel Kiper
2015-03-03 12:39 ` Ian Campbell
2015-03-03 12:51 ` Daniel Kiper
2015-03-27 10:59 ` 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=54CBC722.6010303@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=daniel.kiper@oracle.com \
--cc=david.vrabel@citrix.com \
--cc=fu.wei@linaro.org \
--cc=gang.wei@intel.com \
--cc=grub-devel@gnu.org \
--cc=ian.campbell@citrix.com \
--cc=jbeulich@suse.com \
--cc=jgross@suse.com \
--cc=keir@xen.org \
--cc=ning.sun@intel.com \
--cc=phcoder@gmail.com \
--cc=qiaowei.ren@intel.com \
--cc=richard.l.maliszewski@intel.com \
--cc=roy.franz@linaro.org \
--cc=stefano.stabellini@eu.citrix.com \
--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).