merged relocators into mips

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2009-11-26 21:42:31 +01:00
commit 105b69abbd
9 changed files with 263 additions and 63 deletions

View file

@ -0,0 +1,30 @@
/* memory.h - describe the memory map */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2002,2007,2008 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GRUB_MEMORY_CPU_HEADER
#define GRUB_MEMORY_CPU_HEADER 1
/* The flag for protected mode. */
#define GRUB_MEMORY_CPU_CR0_PE_ON 0x1
#define GRUB_MEMORY_CPU_CR4_PAE_ON 0x00000040
#define GRUB_MEMORY_CPU_CR0_PAGING_ON 0x80000000
#define GRUB_MEMORY_CPU_AMD64_MSR 0xc0000080
#define GRUB_MEMORY_CPU_AMD64_MSR_ON 0x00000100
#endif /* ! GRUB_MEMORY_CPU_HEADER */

View file

@ -0,0 +1,41 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GRUB_RELOCATOR_CPU_HEADER
#define GRUB_RELOCATOR_CPU_HEADER 1
#include <grub/types.h>
#include <grub/err.h>
struct grub_relocator32_state
{
grub_uint32_t esp;
grub_uint32_t eax;
grub_uint32_t ebx;
grub_uint32_t ecx;
grub_uint32_t edx;
grub_uint32_t eip;
};
void *grub_relocator32_alloc (grub_size_t size);
grub_err_t grub_relocator32_boot (void *relocator, grub_uint32_t dest,
struct grub_relocator32_state state);
void *grub_relocator32_realloc (void *relocator, grub_size_t size);
void grub_relocator32_free (void *relocator);
#endif /* ! GRUB_RELOCATOR_CPU_HEADER */

102
lib/i386/relocator.c.moved Normal file
View file

@ -0,0 +1,102 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/mm.h>
#include <grub/misc.h>
#include <grub/types.h>
#include <grub/types.h>
#include <grub/err.h>
#include <grub/i386/relocator.h>
extern grub_uint8_t grub_relocator32_forward_start;
extern grub_uint8_t grub_relocator32_forward_end;
extern grub_uint8_t grub_relocator32_backward_start;
extern grub_uint8_t grub_relocator32_backward_end;
extern grub_uint32_t grub_relocator32_backward_dest;
extern grub_uint32_t grub_relocator32_backward_size;
extern grub_addr_t grub_relocator32_backward_src;
extern grub_uint32_t grub_relocator32_forward_dest;
extern grub_uint32_t grub_relocator32_forward_size;
extern grub_addr_t grub_relocator32_forward_src;
extern grub_uint32_t grub_relocator32_forward_eax;
extern grub_uint32_t grub_relocator32_forward_ebx;
extern grub_uint32_t grub_relocator32_forward_ecx;
extern grub_uint32_t grub_relocator32_forward_edx;
extern grub_uint32_t grub_relocator32_forward_eip;
extern grub_uint32_t grub_relocator32_forward_esp;
extern grub_uint32_t grub_relocator32_backward_eax;
extern grub_uint32_t grub_relocator32_backward_ebx;
extern grub_uint32_t grub_relocator32_backward_ecx;
extern grub_uint32_t grub_relocator32_backward_edx;
extern grub_uint32_t grub_relocator32_backward_eip;
extern grub_uint32_t grub_relocator32_backward_esp;
#define RELOCATOR_SIZEOF(x) (&grub_relocator32_##x##_end - &grub_relocator32_##x##_start)
#define RELOCATOR_ALIGN 16
#define PREFIX(x) grub_relocator32_ ## x
static void
write_call_relocator_bw (void *ptr, void *src, grub_uint32_t dest,
grub_size_t size, struct grub_relocator32_state state)
{
grub_relocator32_backward_dest = dest;
grub_relocator32_backward_src = PTR_TO_UINT64 (src);
grub_relocator32_backward_size = size;
grub_relocator32_backward_eax = state.eax;
grub_relocator32_backward_ebx = state.ebx;
grub_relocator32_backward_ecx = state.ecx;
grub_relocator32_backward_edx = state.edx;
grub_relocator32_backward_eip = state.eip;
grub_relocator32_backward_esp = state.esp;
grub_memmove (ptr,
&grub_relocator32_backward_start,
RELOCATOR_SIZEOF (backward));
((void (*) (void)) ptr) ();
}
static void
write_call_relocator_fw (void *ptr, void *src, grub_uint32_t dest,
grub_size_t size, struct grub_relocator32_state state)
{
grub_relocator32_forward_dest = dest;
grub_relocator32_forward_src = PTR_TO_UINT64 (src);
grub_relocator32_forward_size = size;
grub_relocator32_forward_eax = state.eax;
grub_relocator32_forward_ebx = state.ebx;
grub_relocator32_forward_ecx = state.ecx;
grub_relocator32_forward_edx = state.edx;
grub_relocator32_forward_eip = state.eip;
grub_relocator32_forward_esp = state.esp;
grub_memmove (ptr,
&grub_relocator32_forward_start,
RELOCATOR_SIZEOF (forward));
((void (*) (void)) ptr) ();
}
#include "../relocator.c"

View file

@ -208,7 +208,7 @@ RELOCATOR_VARIABLE (edx)
.byte 0xea
RELOCATOR_VARIABLE (eip)
.long 0
.word 0x08
.word CODE_SEGMENT
/* GDT. Copied from loader/i386/linux.c. */
.p2align 4

View file

@ -0,0 +1,2 @@
#define BACKWARD
#include "relocator_asm.S"

View file

@ -16,15 +16,17 @@
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#define MAX_OVERHEAD ((RELOCATOR_SIZEOF (forward) + RELOCATOR_ALIGN) \
+ (RELOCATOR_SIZEOF (backward) + RELOCATOR_ALIGN) \
+ (RELOCATOR_SIZEOF (forward) + RELOCATOR_ALIGN) \
+ (RELOCATOR_SIZEOF (backward) + RELOCATOR_ALIGN))
void *
PREFIX (alloc) (grub_size_t size)
{
char *playground;
playground = grub_malloc ((RELOCATOR_SIZEOF (forward) + RELOCATOR_ALIGN)
+ size
+ (RELOCATOR_SIZEOF (backward) +
RELOCATOR_ALIGN));
playground = grub_malloc (size + MAX_OVERHEAD);
if (!playground)
return 0;
@ -40,10 +42,7 @@ PREFIX (realloc) (void *relocator, grub_size_t size)
playground = (char *) relocator - RELOCATOR_SIZEOF (forward);
playground = grub_realloc (playground,
(RELOCATOR_SIZEOF (forward) + RELOCATOR_ALIGN)
+ size
+ (RELOCATOR_SIZEOF (backward) + RELOCATOR_ALIGN));
playground = grub_realloc (playground, size + MAX_OVERHEAD);
if (!playground)
return 0;
@ -73,6 +72,25 @@ PREFIX (boot) (void *relocator, grub_uint32_t dest,
"Relocator: source: %p, destination: 0x%x, size: 0x%x\n",
relocator, dest, size);
/* Very unlikely condition: Relocator may risk overwrite itself.
Just move it a bit up. */
if ((grub_uint8_t *) UINT_TO_PTR (dest) - (grub_uint8_t *) relocator
< (RELOCATOR_SIZEOF (backward) + RELOCATOR_ALIGN)
&& (grub_uint8_t *) UINT_TO_PTR (dest) - (grub_uint8_t *) relocator
> - (RELOCATOR_SIZEOF (forward) + RELOCATOR_ALIGN))
{
void *relocator_new = ((grub_uint8_t *) relocator)
+ (RELOCATOR_SIZEOF (forward) + RELOCATOR_ALIGN)
+ (RELOCATOR_SIZEOF (backward) + RELOCATOR_ALIGN);
grub_dprintf ("relocator", "Overwrite condition detected moving "
"relocator from %p to %p\n", relocator, relocator_new);
grub_memmove (relocator_new, relocator,
(RELOCATOR_SIZEOF (forward) + RELOCATOR_ALIGN)
+ size
+ (RELOCATOR_SIZEOF (backward) + RELOCATOR_ALIGN));
relocator = relocator_new;
}
if (UINT_TO_PTR (dest) >= relocator)
{
int overhead;

View file

@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: GNU GRUB\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2009-11-25 23:02+0100\n"
"POT-Creation-Date: 2009-11-25 23:35+0100\n"
"PO-Revision-Date: 2009-11-17 12:26+0100\n"
"Last-Translator: Robert Millan <rmh.grub@aybabtu.com>\n"
"Language-Team: None <no-team-yet@li.org>\n"
@ -14,33 +14,38 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: util/grub-mkrawimage.c:66
#: util/i386/pc/grub-mkimage.c:65
msgid "the core image is too small"
msgstr ""
#: util/grub-mkrawimage.c:78
#: util/i386/pc/grub-mkimage.c:77
msgid "cannot compress the kernel image"
msgstr ""
#: util/grub-mkrawimage.c:152
msgid "prefix too long"
#: util/i386/pc/grub-mkimage.c:138
msgid "prefix is too long"
msgstr ""
#: util/grub-mkrawimage.c:236
#: util/i386/pc/grub-mkimage.c:206
msgid "the core image is too big"
msgstr ""
#: util/grub-mkrawimage.c:241
#: util/i386/pc/grub-mkimage.c:211
#, c-format
msgid "diskboot.img size must be %u bytes"
msgstr ""
#: util/grub-mkrawimage.c:315
#: util/i386/pc/grub-mkimage.c:284
#, c-format
msgid "Core image is too big (%p > %p)\n"
msgstr ""
#: util/grub-mkrawimage.c:424
#: util/i386/pc/grub-mkimage.c:321 util/i386/pc/grub-setup.c:589
#, c-format
msgid "Try ``%s --help'' for more information.\n"
msgstr "Proveu «%s --help» per a obtenir més informació.\n"
#: util/i386/pc/grub-mkimage.c:323
#, c-format
msgid ""
"Usage: grub-mkimage [OPTION]... [MODULES]\n"
@ -50,13 +55,16 @@ msgid ""
" -d, --directory=DIR use images and modules under DIR [default=%s]\n"
" -p, --prefix=DIR set grub_prefix directory [default=%s]\n"
" -m, --memdisk=FILE embed FILE as a memdisk image\n"
" -f, --font=FILE embed FILE as a boot font\n"
" -c, --config=FILE embed FILE as boot config\n"
" -o, --output=FILE output a generated image to FILE [default=stdout]\n"
" -O, --format=FORMAT generate an image in format [default="
" -h, --help display this message and exit\n"
" -V, --version print version information and exit\n"
" -v, --verbose print verbose messages\n"
"\n"
"Report bugs to <%s>.\n"
msgstr ""
#: util/grub-mkrawimage.c:566
#: util/i386/pc/grub-mkimage.c:429
#, c-format
msgid "cannot open %s"
msgstr ""
@ -186,11 +194,6 @@ msgstr ""
msgid "Cannot open `%s'"
msgstr ""
#: util/i386/pc/grub-setup.c:589
#, c-format
msgid "Try ``%s --help'' for more information.\n"
msgstr "Proveu «%s --help» per a obtenir més informació.\n"
#: util/i386/pc/grub-setup.c:591
#, c-format
msgid ""

View file

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: grub 1.97+20091122\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2009-11-25 23:02+0100\n"
"POT-Creation-Date: 2009-11-25 23:35+0100\n"
"PO-Revision-Date: 2009-11-22 20:00+0700\n"
"Last-Translator: Arif E. Nugroho <arif_endro@yahoo.com>\n"
"Language-Team: Indonesian <translation-team-id@lists.sourceforge.net>\n"
@ -15,35 +15,39 @@ msgstr ""
"Content-Type: text/plain; charset=ISO-8859-1\n"
"Content-Transfer-Encoding: 8bit\n"
#: util/grub-mkrawimage.c:66
#: util/i386/pc/grub-mkimage.c:65
msgid "the core image is too small"
msgstr "image core terlalu kecil"
#: util/grub-mkrawimage.c:78
#: util/i386/pc/grub-mkimage.c:77
msgid "cannot compress the kernel image"
msgstr "tidak dapat mengkompress image kernel"
#: util/grub-mkrawimage.c:152
#, fuzzy
msgid "prefix too long"
#: util/i386/pc/grub-mkimage.c:138
msgid "prefix is too long"
msgstr "awalan terlalu panjang"
#: util/grub-mkrawimage.c:236
#: util/i386/pc/grub-mkimage.c:206
msgid "the core image is too big"
msgstr "image core terlalu besar"
#: util/grub-mkrawimage.c:241
#: util/i386/pc/grub-mkimage.c:211
#, c-format
msgid "diskboot.img size must be %u bytes"
msgstr "besar diskboot.img seharusnya %u bytes"
#: util/grub-mkrawimage.c:315
#: util/i386/pc/grub-mkimage.c:284
#, c-format
msgid "Core image is too big (%p > %p)\n"
msgstr "Image core terlalu besar (%p >%p)\n"
#: util/grub-mkrawimage.c:424
#, fuzzy, c-format
#: util/i386/pc/grub-mkimage.c:321 util/i386/pc/grub-setup.c:589
#, c-format
msgid "Try ``%s --help'' for more information.\n"
msgstr "Coba ``%s --help'' untuk informasi lebih lanjut.\n"
#: util/i386/pc/grub-mkimage.c:323
#, c-format
msgid ""
"Usage: grub-mkimage [OPTION]... [MODULES]\n"
"\n"
@ -52,10 +56,13 @@ msgid ""
" -d, --directory=DIR use images and modules under DIR [default=%s]\n"
" -p, --prefix=DIR set grub_prefix directory [default=%s]\n"
" -m, --memdisk=FILE embed FILE as a memdisk image\n"
" -f, --font=FILE embed FILE as a boot font\n"
" -c, --config=FILE embed FILE as boot config\n"
" -o, --output=FILE output a generated image to FILE [default=stdout]\n"
" -O, --format=FORMAT generate an image in format [default="
" -h, --help display this message and exit\n"
" -V, --version print version information and exit\n"
" -v, --verbose print verbose messages\n"
"\n"
"Report bugs to <%s>.\n"
msgstr ""
"Penggunaan: grub-mkimage [PILIHAN]... [MODUL]\n"
"\n"
@ -73,7 +80,7 @@ msgstr ""
"\n"
"Laporkan bugs ke <%s>.\n"
#: util/grub-mkrawimage.c:566
#: util/i386/pc/grub-mkimage.c:429
#, c-format
msgid "cannot open %s"
msgstr "tidak dapat membuka %s"
@ -223,11 +230,6 @@ msgstr "Gagal untuk membaca sektor selanjutnya dari image core"
msgid "Cannot open `%s'"
msgstr "Tidak dapat membuka `%s'"
#: util/i386/pc/grub-setup.c:589
#, c-format
msgid "Try ``%s --help'' for more information.\n"
msgstr "Coba ``%s --help'' untuk informasi lebih lanjut.\n"
#: util/i386/pc/grub-setup.c:591
#, c-format
msgid ""

View file

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: grub 1.97+20091122\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2009-11-25 23:02+0100\n"
"POT-Creation-Date: 2009-11-25 23:35+0100\n"
"PO-Revision-Date: 2009-11-23 18:36+0800\n"
"Last-Translator: Aron Xu <happyaron.xu@gmail.com>\n"
"Language-Team: Chinese (simplified) <translation-team-zh-cn@lists."
@ -17,34 +17,38 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: util/grub-mkrawimage.c:66
#: util/i386/pc/grub-mkimage.c:65
msgid "the core image is too small"
msgstr "核心映像太小"
#: util/grub-mkrawimage.c:78
#: util/i386/pc/grub-mkimage.c:77
msgid "cannot compress the kernel image"
msgstr "无法压缩内核映像"
#: util/grub-mkrawimage.c:152
#, fuzzy
msgid "prefix too long"
#: util/i386/pc/grub-mkimage.c:138
msgid "prefix is too long"
msgstr "前缀太长"
#: util/grub-mkrawimage.c:236
#: util/i386/pc/grub-mkimage.c:206
msgid "the core image is too big"
msgstr "核心映像太大"
#: util/grub-mkrawimage.c:241
#: util/i386/pc/grub-mkimage.c:211
#, c-format
msgid "diskboot.img size must be %u bytes"
msgstr "diskboot.img 的大小必须为 %u 字节"
#: util/grub-mkrawimage.c:315
#: util/i386/pc/grub-mkimage.c:284
#, c-format
msgid "Core image is too big (%p > %p)\n"
msgstr "核心映像太大(%p > %p)\n"
#: util/grub-mkrawimage.c:424
#: util/i386/pc/grub-mkimage.c:321 util/i386/pc/grub-setup.c:589
#, c-format
msgid "Try ``%s --help'' for more information.\n"
msgstr "请尝试运行 ``%s --help'' 以获得更多信息。\n"
#: util/i386/pc/grub-mkimage.c:323
#, c-format
msgid ""
"Usage: grub-mkimage [OPTION]... [MODULES]\n"
@ -54,13 +58,16 @@ msgid ""
" -d, --directory=DIR use images and modules under DIR [default=%s]\n"
" -p, --prefix=DIR set grub_prefix directory [default=%s]\n"
" -m, --memdisk=FILE embed FILE as a memdisk image\n"
" -f, --font=FILE embed FILE as a boot font\n"
" -c, --config=FILE embed FILE as boot config\n"
" -o, --output=FILE output a generated image to FILE [default=stdout]\n"
" -O, --format=FORMAT generate an image in format [default="
" -h, --help display this message and exit\n"
" -V, --version print version information and exit\n"
" -v, --verbose print verbose messages\n"
"\n"
"Report bugs to <%s>.\n"
msgstr ""
#: util/grub-mkrawimage.c:566
#: util/i386/pc/grub-mkimage.c:429
#, c-format
msgid "cannot open %s"
msgstr "无法打开 %s"
@ -190,11 +197,6 @@ msgstr ""
msgid "Cannot open `%s'"
msgstr "无法打开 `%s'"
#: util/i386/pc/grub-setup.c:589
#, c-format
msgid "Try ``%s --help'' for more information.\n"
msgstr "请尝试运行 ``%s --help'' 以获得更多信息。\n"
#: util/i386/pc/grub-setup.c:591
#, c-format
msgid ""