[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 05/23] x86/boot/reloc: create generic alloc and copy functions
From: |
Daniel Kiper |
Subject: |
[PATCH v2 05/23] x86/boot/reloc: create generic alloc and copy functions |
Date: |
Mon, 20 Jul 2015 16:29:00 +0200 |
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 <address@hidden>
Reviewed-by: Andrew Cooper <address@hidden>
---
v2 - suggestions/fixes:
- generalize new functions names
(suggested by Jan Beulich),
- reduce number of casts
(suggested by Jan Beulich).
---
xen/arch/x86/boot/reloc.c | 59 ++++++++++++++++++++++++++++-----------------
1 file changed, 37 insertions(+), 22 deletions(-)
diff --git a/xen/arch/x86/boot/reloc.c b/xen/arch/x86/boot/reloc.c
index 708898f..09fd540 100644
--- a/xen/arch/x86/boot/reloc.c
+++ b/xen/arch/x86/boot/reloc.c
@@ -45,9 +45,10 @@ asm (
typedef unsigned int u32;
#include "../../../include/xen/multiboot.h"
-static void *reloc_mbi_struct(void *old, unsigned int bytes)
+static u32 alloc_mem(u32 bytes)
{
- void *new;
+ u32 s;
+
asm(
" call 1f \n"
"1: pop %%edx \n"
@@ -55,50 +56,64 @@ 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 char *reloc_mbi_string(char *old)
+static u32 copy_mem(u32 src, u32 bytes)
{
- char *p;
- for ( p = old; *p != '\0'; p++ )
+ u32 dst, dst_asm;
+
+ dst = alloc_mem(bytes);
+ dst_asm = dst;
+
+ asm volatile("rep movsb" : "+S" (src), "+D" (dst_asm), "+c" (bytes) : :
"memory");
+
+ return dst;
+}
+
+static u32 copy_string(u32 src)
+{
+ u32 p;
+
+ if ( src == 0 )
+ return 0;
+
+ for ( p = src; *(char *)p != '\0'; p++ )
continue;
- return reloc_mbi_struct(old, p - old + 1);
+
+ return copy_mem(src, p - src + 1);
}
-multiboot_info_t *reloc(multiboot_info_t *mbi_old)
+multiboot_info_t *reloc(u32 mbi_old)
{
- multiboot_info_t *mbi = reloc_mbi_struct(mbi_old, sizeof(*mbi));
+ multiboot_info_t *mbi = (multiboot_info_t *)copy_mem(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;
- mbi->mods_addr = (u32)mods;
+ mbi->mods_addr = copy_mem(mbi->mods_addr, mbi->mods_count *
sizeof(module_t));
+
+ mods = (module_t *)mbi->mods_addr;
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_mem(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 |
--
1.7.10.4
- [PATCH v2 00/23] x86: multiboot2 protocol support, Daniel Kiper, 2015/07/20
- [PATCH v2 01/23] x86/boot: remove unneeded instruction, Daniel Kiper, 2015/07/20
- [PATCH v2 04/23] x86/boot: call reloc() using cdecl calling convention, Daniel Kiper, 2015/07/20
- [PATCH v2 03/23] x86: zero BSS using stosl instead of stosb, Daniel Kiper, 2015/07/20
- [PATCH v2 07/23] x86/boot/reloc: Rename some variables and rearrange code a bit, Daniel Kiper, 2015/07/20
- [PATCH v2 06/23] x86/boot: use %ecx instead of %eax, Daniel Kiper, 2015/07/20
- [PATCH v2 05/23] x86/boot/reloc: create generic alloc and copy functions,
Daniel Kiper <=
- [PATCH v2 08/23] x86: add multiboot2 protocol support, Daniel Kiper, 2015/07/20
- [PATCH v2 11/23] efi: split out efi_init(), Daniel Kiper, 2015/07/20
- [PATCH v2 12/23] efi: split out efi_console_set_mode(), Daniel Kiper, 2015/07/20
- [PATCH v2 02/23] x86/boot: copy only text section from *.lnk file to *.bin file, Daniel Kiper, 2015/07/20
- [PATCH v2 13/23] efi: split out efi_get_gop(), Daniel Kiper, 2015/07/20
- [PATCH v2 16/23] efi: split out efi_variables(), Daniel Kiper, 2015/07/20
- [PATCH v2 19/23] x86/efi: create new early memory allocator, Daniel Kiper, 2015/07/20
- [PATCH v2 18/23] efi: split out efi_exit_boot(), Daniel Kiper, 2015/07/20
- [PATCH v2 21/23] x86/boot: implement early command line parser in C, Daniel Kiper, 2015/07/20
- [PATCH v2 20/23] x86: add multiboot2 protocol support for EFI platforms, Daniel Kiper, 2015/07/20