source: grub-pc/trunk/fuentes/grub-core/lib/i386/relocator_common_c.c @ 22

Last change on this file since 22 was 22, checked in by mabarracus, 4 years ago

updated version and apply net.ifnames=0 into debian/rules

File size: 3.0 KB
Line 
1/*
2 *  GRUB  --  GRand Unified Bootloader
3 *  Copyright (C) 2009-2013  Free Software Foundation, Inc.
4 *
5 *  GRUB is free software: you can redistribute it and/or modify
6 *  it under the terms of the GNU General Public License as published by
7 *  the Free Software Foundation, either version 3 of the License, or
8 *  (at your option) any later version.
9 *
10 *  GRUB is distributed in the hope that it will be useful,
11 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 *  GNU General Public License for more details.
14 *
15 *  You should have received a copy of the GNU General Public License
16 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <grub/mm.h>
20#include <grub/misc.h>
21
22#include <grub/types.h>
23#include <grub/err.h>
24#include <grub/term.h>
25
26#include <grub/relocator.h>
27#include <grub/relocator_private.h>
28
29extern grub_uint8_t grub_relocator_forward_start;
30extern grub_uint8_t grub_relocator_forward_end;
31extern grub_uint8_t grub_relocator_backward_start;
32extern grub_uint8_t grub_relocator_backward_end;
33
34extern void *grub_relocator_backward_dest;
35extern void *grub_relocator_backward_src;
36extern grub_size_t grub_relocator_backward_chunk_size;
37
38extern void *grub_relocator_forward_dest;
39extern void *grub_relocator_forward_src;
40extern grub_size_t grub_relocator_forward_chunk_size;
41
42#define RELOCATOR_SIZEOF(x)     (&grub_relocator##x##_end - &grub_relocator##x##_start)
43
44grub_size_t grub_relocator_align = 1;
45grub_size_t grub_relocator_forward_size;
46grub_size_t grub_relocator_backward_size;
47#ifdef __x86_64__
48grub_size_t grub_relocator_jumper_size = 12;
49#else
50grub_size_t grub_relocator_jumper_size = 7;
51#endif
52
53void
54grub_cpu_relocator_init (void)
55{
56  grub_relocator_forward_size = RELOCATOR_SIZEOF (_forward);
57  grub_relocator_backward_size = RELOCATOR_SIZEOF (_backward);
58}
59
60void
61grub_cpu_relocator_jumper (void *rels, grub_addr_t addr)
62{
63  grub_uint8_t *ptr;
64  ptr = rels;
65#ifdef __x86_64__
66  /* movq imm64, %rax (for relocator) */
67  *(grub_uint8_t *) ptr = 0x48;
68  ptr++;
69  *(grub_uint8_t *) ptr = 0xb8;
70  ptr++;
71  *(grub_uint64_t *) ptr = addr;
72  ptr += sizeof (grub_uint64_t);
73#else
74  /* movl imm32, %eax (for relocator) */
75  *(grub_uint8_t *) ptr = 0xb8;
76  ptr++;
77  *(grub_uint32_t *) ptr = addr;
78  ptr += sizeof (grub_uint32_t);
79#endif
80  /* jmp $eax/$rax */
81  *(grub_uint8_t *) ptr = 0xff;
82  ptr++;
83  *(grub_uint8_t *) ptr = 0xe0;
84  ptr++;
85}
86
87void
88grub_cpu_relocator_backward (void *ptr, void *src, void *dest,
89                             grub_size_t size)
90{
91  grub_relocator_backward_dest = dest;
92  grub_relocator_backward_src = src;
93  grub_relocator_backward_chunk_size = size;
94
95  grub_memmove (ptr,
96                &grub_relocator_backward_start, RELOCATOR_SIZEOF (_backward));
97}
98
99void
100grub_cpu_relocator_forward (void *ptr, void *src, void *dest,
101                            grub_size_t size)
102{
103  grub_relocator_forward_dest = dest;
104  grub_relocator_forward_src = src;
105  grub_relocator_forward_chunk_size = size;
106
107  grub_memmove (ptr,
108                &grub_relocator_forward_start, RELOCATOR_SIZEOF (_forward));
109}
Note: See TracBrowser for help on using the repository browser.