ia64/xen-unstable

view xen/arch/x86/boot/reloc.c @ 19160:faf20eb0b69e

x86: Relocate Multiboot module command-line strings.

Missed this in the original patch.

Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Feb 04 13:27:17 2009 +0000 (2009-02-04)
parents aca402831ac1
children
line source
1 /******************************************************************************
2 * reloc.c
3 *
4 * 32-bit flat memory-map routines for relocating Multiboot structures
5 * and modules. This is most easily done early with paging disabled.
6 *
7 * Copyright (c) 2009, Citrix Systems, Inc.
8 *
9 * Authors:
10 * Keir Fraser <keir.fraser@citrix.com>
11 */
13 asm (
14 " .text \n"
15 " .globl _start \n"
16 "_start: \n"
17 " mov $_start,%edi \n"
18 " call 1f \n"
19 "1: pop %esi \n"
20 " sub $1b-_start,%esi \n"
21 " mov $__bss_start-_start,%ecx \n"
22 " rep movsb \n"
23 " xor %eax,%eax \n"
24 " mov $_end,%ecx \n"
25 " sub %edi,%ecx \n"
26 " rep stosb \n"
27 " mov $reloc,%eax \n"
28 " jmp *%eax \n"
29 );
31 typedef unsigned int u32;
32 #include "../../../include/xen/multiboot.h"
34 extern char _start[];
36 static void *memcpy(void *dest, const void *src, unsigned int n)
37 {
38 char *s = (char *)src, *d = dest;
39 while ( n-- )
40 *d++ = *s++;
41 return dest;
42 }
44 static void *reloc_mbi_struct(void *old, unsigned int bytes)
45 {
46 static void *alloc = &_start;
47 alloc = (void *)(((unsigned long)alloc - bytes) & ~15ul);
48 return memcpy(alloc, old, bytes);
49 }
51 static char *reloc_mbi_string(char *old)
52 {
53 char *p;
54 for ( p = old; *p != '\0'; p++ )
55 continue;
56 return reloc_mbi_struct(old, p - old + 1);
57 }
59 multiboot_info_t *reloc(multiboot_info_t *mbi_old)
60 {
61 multiboot_info_t *mbi = reloc_mbi_struct(mbi_old, sizeof(*mbi));
62 int i;
64 if ( mbi->flags & MBI_CMDLINE )
65 mbi->cmdline = (u32)reloc_mbi_string((char *)mbi->cmdline);
67 if ( mbi->flags & MBI_MODULES )
68 {
69 module_t *mods = reloc_mbi_struct(
70 (module_t *)mbi->mods_addr, mbi->mods_count * sizeof(module_t));
71 mbi->mods_addr = (u32)mods;
72 for ( i = 0; i < mbi->mods_count; i++ )
73 if ( mods[i].string )
74 mods[i].string = (u32)reloc_mbi_string((char *)mods[i].string);
75 }
77 if ( mbi->flags & MBI_MEMMAP )
78 mbi->mmap_addr = (u32)reloc_mbi_struct(
79 (memory_map_t *)mbi->mmap_addr, mbi->mmap_length);
81 /* Mask features we don't understand or don't relocate. */
82 mbi->flags &= (MBI_MEMLIMITS |
83 MBI_DRIVES |
84 MBI_CMDLINE |
85 MBI_MODULES |
86 MBI_MEMMAP);
88 return mbi;
89 }