~ubuntu-branches/ubuntu/trusty/grub2/trusty-updates

« back to all changes in this revision

Viewing changes to lib/i386/relocator.c

Tags: upstream-1.99~20101122
ImportĀ upstreamĀ versionĀ 1.99~20101122

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  GRUB  --  GRand Unified Bootloader
3
 
 *  Copyright (C) 2009  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/types.h>
24
 
#include <grub/err.h>
25
 
 
26
 
#include <grub/i386/relocator.h>
27
 
 
28
 
extern grub_uint8_t grub_relocator32_forward_start;
29
 
extern grub_uint8_t grub_relocator32_forward_end;
30
 
extern grub_uint8_t grub_relocator32_backward_start;
31
 
extern grub_uint8_t grub_relocator32_backward_end;
32
 
 
33
 
extern grub_uint32_t grub_relocator32_backward_dest;
34
 
extern grub_uint32_t grub_relocator32_backward_size;
35
 
extern grub_addr_t grub_relocator32_backward_src;
36
 
 
37
 
extern grub_uint32_t grub_relocator32_forward_dest;
38
 
extern grub_uint32_t grub_relocator32_forward_size;
39
 
extern grub_addr_t grub_relocator32_forward_src;
40
 
 
41
 
extern grub_uint32_t grub_relocator32_forward_eax;
42
 
extern grub_uint32_t grub_relocator32_forward_ebx;
43
 
extern grub_uint32_t grub_relocator32_forward_ecx;
44
 
extern grub_uint32_t grub_relocator32_forward_edx;
45
 
extern grub_uint32_t grub_relocator32_forward_eip;
46
 
extern grub_uint32_t grub_relocator32_forward_esp;
47
 
 
48
 
extern grub_uint32_t grub_relocator32_backward_eax;
49
 
extern grub_uint32_t grub_relocator32_backward_ebx;
50
 
extern grub_uint32_t grub_relocator32_backward_ecx;
51
 
extern grub_uint32_t grub_relocator32_backward_edx;
52
 
extern grub_uint32_t grub_relocator32_backward_eip;
53
 
extern grub_uint32_t grub_relocator32_backward_esp;
54
 
 
55
 
#define RELOCATOR_SIZEOF(x)     (&grub_relocator32_##x##_end - &grub_relocator32_##x##_start)
56
 
#define RELOCATOR_ALIGN 16
57
 
#define PREFIX(x) grub_relocator32_ ## x
58
 
 
59
 
static void
60
 
write_call_relocator_bw (void *ptr, void *src, grub_uint32_t dest,
61
 
                         grub_size_t size, struct grub_relocator32_state state)
62
 
{
63
 
  grub_relocator32_backward_dest = dest;
64
 
  grub_relocator32_backward_src = PTR_TO_UINT64 (src);
65
 
  grub_relocator32_backward_size = size;
66
 
 
67
 
  grub_relocator32_backward_eax = state.eax;
68
 
  grub_relocator32_backward_ebx = state.ebx;
69
 
  grub_relocator32_backward_ecx = state.ecx;
70
 
  grub_relocator32_backward_edx = state.edx;
71
 
  grub_relocator32_backward_eip = state.eip;
72
 
  grub_relocator32_backward_esp = state.esp;
73
 
 
74
 
  grub_memmove (ptr,
75
 
                &grub_relocator32_backward_start,
76
 
                RELOCATOR_SIZEOF (backward));
77
 
  ((void (*) (void)) ptr) ();
78
 
}
79
 
 
80
 
static void
81
 
write_call_relocator_fw (void *ptr, void *src, grub_uint32_t dest,
82
 
                         grub_size_t size, struct grub_relocator32_state state)
83
 
{
84
 
 
85
 
  grub_relocator32_forward_dest = dest;
86
 
  grub_relocator32_forward_src = PTR_TO_UINT64 (src);
87
 
  grub_relocator32_forward_size = size;
88
 
 
89
 
  grub_relocator32_forward_eax = state.eax;
90
 
  grub_relocator32_forward_ebx = state.ebx;
91
 
  grub_relocator32_forward_ecx = state.ecx;
92
 
  grub_relocator32_forward_edx = state.edx;
93
 
  grub_relocator32_forward_eip = state.eip;
94
 
  grub_relocator32_forward_esp = state.esp;
95
 
 
96
 
  grub_memmove (ptr,
97
 
                &grub_relocator32_forward_start,
98
 
                RELOCATOR_SIZEOF (forward));
99
 
  ((void (*) (void)) ptr) ();
100
 
}
101
 
 
102
 
#include "../relocator.c"