~darkmuggle-deactivatedaccount/ubuntu/quantal/grub2/fix-872244

« back to all changes in this revision

Viewing changes to lib/i386/relocator_asm.S

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2010-01-11 11:12:55 UTC
  • mfrom: (17.3.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100111111255-lr8ebkqw5x41gq6j
Tags: 1.98~20100101-1ubuntu1
* Resynchronise with Debian. Remaining changes:
  - Adjust for default Ubuntu boot options ("quiet splash").
  - Default to hiding the menu; holding down Shift at boot will show it.
  - Set a monochromatic theme for Ubuntu.
  - Apply Ubuntu GRUB Legacy changes to legacy update-grub script: title,
    recovery mode, quiet option, tweak how memtest86+ is displayed, and
    use UUIDs where appropriate.
  - Conflict with grub (<< 0.97-54) as well as grub-legacy.
  - Fix backslash-escaping in merge_debconf_into_conf.
  - Remove "GNU/Linux" from default distributor string.
  - Add crashkernel= options if kdump and makedumpfile are available.
  - If other operating systems are installed, then automatically unhide
    the menu. Otherwise, if GRUB_HIDDEN_TIMEOUT is 0, then use keystatus
    if available to check whether Shift is pressed. If it is, show the
    menu, otherwise boot immediately. If keystatus is not available, then
    fall back to a short delay interruptible with Escape.
  - Allow Shift to interrupt 'sleep --interruptible'.
  - Don't display introductory message about line editing unless we're
    actually offering a shell prompt. Don't clear the screen just before
    booting if we never drew the menu in the first place.
  - Remove some verbose messages printed before reading the configuration
    file.
  - If the environment variable "quiet" is set to something other than 0,
    suppress progress messages as the kernel and initrd load. Set this for
    non-recovery kernel menu entries.
  - Add GRUB_DEFAULT=saved, as well as grub-set-default and grub-reboot
    utilities. Provides functionality essentially equivalent to GRUB
    Legacy's savedefault.
  - Keep the loopback file open so that subsequent changes to the "root"
    environment variable don't affect it.
  - Change prepare_grub_to_access_device to handle filesystems
    loop-mounted on file images.
  - Ignore devices loop-mounted from files in 10_linux.
  - Show the boot menu if the previous boot failed, that is if it failed
    to get to the end of one of the normal runlevels.
  - Handle RAID devices containing virtio components.
* Update savedefault patch from current Bazaar branch, fixing grub-reboot
  to have distinct behaviour from grub-set-default (LP: #497326).
* Fix grub-mkisofs compilation error with FORTIFY_SOURCE.
* Convert recordfail boilerplate in each menu entry to use a function.

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/symbol.h>
 
20
#include <grub/i386/memory.h>
 
21
 
 
22
#ifdef BACKWARD
 
23
#define RELOCATOR_VARIABLE(x) VARIABLE(grub_relocator32_backward_ ## x)
 
24
#else
 
25
#define RELOCATOR_VARIABLE(x) VARIABLE(grub_relocator32_forward_ ## x)
 
26
#endif
 
27
#ifdef __x86_64__
 
28
#define RAX %rax
 
29
#define RCX %rcx
 
30
#define RDI %rdi
 
31
#define RSI %rdi
 
32
#else
 
33
#define RAX %eax
 
34
#define RCX %ecx
 
35
#define RDI %edi
 
36
#define RSI %esi
 
37
#endif
 
38
 
 
39
/* The code segment of the protected mode.  */
 
40
#define CODE_SEGMENT    0x10
 
41
 
 
42
/* The data segment of the protected mode.  */
 
43
#define DATA_SEGMENT    0x18
 
44
 
 
45
        .p2align        4       /* force 16-byte alignment */
 
46
 
 
47
RELOCATOR_VARIABLE(start)
 
48
#ifdef BACKWARD
 
49
LOCAL(base):
 
50
#endif
 
51
        cli
 
52
 
 
53
#ifndef __x86_64__
 
54
        /* mov imm32, %eax */
 
55
        .byte   0xb8
 
56
RELOCATOR_VARIABLE(dest)
 
57
        .long   0
 
58
        movl    %eax, %edi
 
59
 
 
60
        /* mov imm32, %eax */
 
61
        .byte   0xb8
 
62
RELOCATOR_VARIABLE(src)
 
63
        .long   0
 
64
        movl    %eax, %esi
 
65
 
 
66
        /* mov imm32, %ecx */
 
67
        .byte   0xb9
 
68
RELOCATOR_VARIABLE(size)
 
69
        .long   0
 
70
#else
 
71
        xorq    %rax, %rax
 
72
 
 
73
        /* mov imm32, %eax */
 
74
        .byte   0xb8
 
75
RELOCATOR_VARIABLE(dest)
 
76
        .long   0
 
77
        movq    %rax, %rdi
 
78
 
 
79
        /* mov imm64, %rax */
 
80
        .byte   0x48
 
81
        .byte   0xb8
 
82
RELOCATOR_VARIABLE(src)
 
83
        .long   0, 0
 
84
        movq    %rax, %rsi
 
85
 
 
86
        xorq    %rcx, %rcx
 
87
        /* mov imm32, %ecx */
 
88
        .byte   0xb9
 
89
RELOCATOR_VARIABLE(size)
 
90
        .long   0
 
91
 
 
92
#endif
 
93
 
 
94
        mov     RDI, RAX
 
95
 
 
96
#ifdef BACKWARD
 
97
        add     RCX, RSI
 
98
        add     RCX, RDI
 
99
#endif
 
100
 
 
101
#ifndef BACKWARD
 
102
        add     RCX, RAX
 
103
#endif
 
104
        add     $0x3, RCX
 
105
        shr     $2, RCX
 
106
 
 
107
 
 
108
#ifdef BACKWARD
 
109
        /* Backward movsl is implicitly off-by-four.  compensate that.  */
 
110
        sub     $4,     RSI
 
111
        sub     $4,     RDI
 
112
 
 
113
        /* Backward copy.  */
 
114
        std
 
115
 
 
116
        rep
 
117
        movsl
 
118
 
 
119
#else
 
120
        /* Forward copy.  */
 
121
        cld
 
122
        rep
 
123
        movsl
 
124
#endif
 
125
 
 
126
        /* %rax contains now our new 'base'.  */
 
127
        mov     RAX, RSI
 
128
        add     $(LOCAL(cont0) - LOCAL(base)), RAX
 
129
        jmp     *RAX
 
130
LOCAL(cont0):
 
131
        lea     (LOCAL(cont1) - LOCAL(base)) (RSI, 1), RAX
 
132
        movl    %eax, (LOCAL(jump_vector) - LOCAL(base)) (RSI, 1)
 
133
 
 
134
        lea     (LOCAL(gdt) - LOCAL(base)) (RSI, 1), RAX
 
135
        mov     RAX, (LOCAL(gdt_addr) - LOCAL(base)) (RSI, 1)
 
136
 
 
137
        /* Switch to compatibility mode. */
 
138
 
 
139
        lgdt    (LOCAL(gdtdesc) - LOCAL(base)) (RSI, 1)
 
140
 
 
141
        /* Update %cs.  */
 
142
        ljmp    *(LOCAL(jump_vector) - LOCAL(base)) (RSI, 1)
 
143
 
 
144
LOCAL(cont1):
 
145
        .code32
 
146
 
 
147
        /* Update other registers. */
 
148
        movl    $DATA_SEGMENT, %eax
 
149
        movl    %eax, %ds
 
150
        movl    %eax, %es
 
151
        movl    %eax, %fs
 
152
        movl    %eax, %gs
 
153
        movl    %eax, %ss
 
154
 
 
155
        /* Disable paging. */
 
156
        movl    %cr0, %eax
 
157
        andl    $(~GRUB_MEMORY_CPU_CR0_PAGING_ON), %eax
 
158
        movl    %eax, %cr0
 
159
 
 
160
        /* Disable amd64. */
 
161
        movl    $GRUB_MEMORY_CPU_AMD64_MSR, %ecx
 
162
        rdmsr
 
163
        andl    $(~GRUB_MEMORY_CPU_AMD64_MSR_ON), %eax
 
164
        wrmsr
 
165
 
 
166
        /* Turn off PAE. */
 
167
        movl    %cr4, %eax
 
168
        andl    $GRUB_MEMORY_CPU_CR4_PAE_ON, %eax
 
169
        movl    %eax, %cr4
 
170
 
 
171
        jmp     LOCAL(cont2)
 
172
LOCAL(cont2):
 
173
        .code32
 
174
 
 
175
        /* mov imm32, %eax */
 
176
        .byte   0xb8
 
177
RELOCATOR_VARIABLE (esp)
 
178
        .long   0
 
179
 
 
180
        movl    %eax, %esp
 
181
 
 
182
        /* mov imm32, %eax */
 
183
        .byte   0xb8
 
184
RELOCATOR_VARIABLE (eax)
 
185
        .long   0
 
186
 
 
187
        /* mov imm32, %ebx */
 
188
        .byte   0xbb
 
189
RELOCATOR_VARIABLE (ebx)
 
190
        .long   0
 
191
 
 
192
        /* mov imm32, %ecx */
 
193
        .byte   0xb9
 
194
RELOCATOR_VARIABLE (ecx)
 
195
        .long   0
 
196
 
 
197
        /* mov imm32, %edx */
 
198
        .byte   0xba
 
199
RELOCATOR_VARIABLE (edx)
 
200
        .long   0
 
201
 
 
202
        /* Cleared direction flag is of no problem with any current
 
203
           payload and makes this implementation easier.  */
 
204
        cld
 
205
 
 
206
        .byte   0xea
 
207
RELOCATOR_VARIABLE (eip)
 
208
        .long   0
 
209
        .word   CODE_SEGMENT
 
210
 
 
211
        /* GDT. Copied from loader/i386/linux.c. */
 
212
        .p2align        4
 
213
LOCAL(gdt):
 
214
        /* NULL.  */
 
215
        .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
 
216
 
 
217
        /* Reserved.  */
 
218
        .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
 
219
 
 
220
        /* Code segment.  */
 
221
        .byte 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x9A, 0xCF, 0x00
 
222
 
 
223
        /* Data segment.  */
 
224
        .byte 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x92, 0xCF, 0x00
 
225
 
 
226
        .p2align        4
 
227
LOCAL(gdtdesc):
 
228
        .word   0x27
 
229
LOCAL(gdt_addr):
 
230
#ifdef __x86_64__
 
231
        /* Filled by the code. */
 
232
        .quad   0
 
233
#else
 
234
        /* Filled by the code. */
 
235
        .long   0
 
236
#endif
 
237
 
 
238
        .p2align        4
 
239
LOCAL(jump_vector):
 
240
        /* Jump location. Is filled by the code */
 
241
        .long   0
 
242
        .long   CODE_SEGMENT
 
243
 
 
244
#ifndef BACKWARD
 
245
LOCAL(base):
 
246
#endif
 
247
 
 
248
RELOCATOR_VARIABLE(end)