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

« back to all changes in this revision

Viewing changes to kern/mips/dl.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Evan Broder, Mario Limonciello
  • Date: 2010-11-24 13:59:55 UTC
  • mfrom: (1.17.6 upstream) (17.6.15 experimental)
  • Revision ID: james.westby@ubuntu.com-20101124135955-r6ii5sepayr7jt53
Tags: 1.99~20101124-1ubuntu1
[ Colin Watson ]
* Resynchronise with Debian experimental.  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.
  - 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.
  - Suppress progress messages as the kernel and initrd load for
    non-recovery kernel menu entries.
  - 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.
  - Don't generate /boot/grub/device.map during grub-install or
    grub-mkconfig by default.
  - Adjust upgrade version checks for Ubuntu.
  - Don't display "GRUB loading" unless Shift is held down.
  - Adjust versions of grub-doc and grub-legacy-doc conflicts to tolerate
    our backport of the grub-doc split.
  - Fix LVM/RAID probing in the absence of /boot/grub/device.map.
  - Look for .mo files in /usr/share/locale-langpack as well, in
    preference.
  - Make sure GRUB_TIMEOUT isn't quoted unnecessarily.
  - Probe all devices in 'grub-probe --target=drive' if
    /boot/grub/device.map is missing.
  - Build-depend on qemu-kvm rather than qemu-system for grub-pc tests.
  - Use qemu rather than qemu-system-i386.
  - Program vesafb on BIOS systems rather than efifb.
  - Add a grub-rescue-efi-amd64 package containing a rescue CD-ROM image
    for EFI-AMD64.
  - On Wubi, don't ask for an install device, but just update wubildr
    using the diverted grub-install.
  - When embedding the core image in a post-MBR gap, check for and avoid
    sectors matching any of a list of known signatures.
  - Disable video_bochs and video_cirrus on PC BIOS systems, as probing
    PCI space seems to break on some systems.
* Downgrade "ACPI shutdown failed" error to a debug message, since it can
  cause spurious test failures.

[ Evan Broder ]
* Enable lua from grub-extras.
* Incorporate the bitop library into lua.
* Add enum_pci function to grub module in lua.
* Switch back to gfxpayload=keep by default, unless the video hardware
  is known to not support it.

[ Mario Limonciello ]
* Built part_msdos and vfat into bootx64.efi (LP: #677758)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* dl-386.c - arch-dependent part of loadable module support */
2
 
/*
3
 
 *  GRUB  --  GRand Unified Bootloader
4
 
 *  Copyright (C) 2002,2005,2007,2009  Free Software Foundation, Inc.
5
 
 *
6
 
 *  GRUB is free software: you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation, either version 3 of the License, or
9
 
 *  (at your option) any later version.
10
 
 *
11
 
 *  GRUB is distributed in the hope that it will be useful,
12
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 *  GNU General Public License for more details.
15
 
 *
16
 
 *  You should have received a copy of the GNU General Public License
17
 
 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
18
 
 */
19
 
 
20
 
#include <grub/dl.h>
21
 
#include <grub/elf.h>
22
 
#include <grub/misc.h>
23
 
#include <grub/err.h>
24
 
#include <grub/cpu/types.h>
25
 
#include <grub/mm.h>
26
 
 
27
 
/* Dummy __gnu_local_gp. Resolved by linker.  */
28
 
static char __gnu_local_gp_dummy;
29
 
 
30
 
/* Check if EHDR is a valid ELF header.  */
31
 
grub_err_t
32
 
grub_arch_dl_check_header (void *ehdr)
33
 
{
34
 
  Elf_Ehdr *e = ehdr;
35
 
 
36
 
  /* Check the magic numbers.  */
37
 
#ifdef WORDS_BIGENDIAN
38
 
  if (e->e_ident[EI_CLASS] != ELFCLASS32
39
 
      || e->e_ident[EI_DATA] != ELFDATA2MSB
40
 
      || e->e_machine != EM_MIPS)
41
 
#else
42
 
  if (e->e_ident[EI_CLASS] != ELFCLASS32
43
 
      || e->e_ident[EI_DATA] != ELFDATA2LSB
44
 
      || e->e_machine != EM_MIPS)
45
 
#endif
46
 
    return grub_error (GRUB_ERR_BAD_OS, "invalid arch specific ELF magic");
47
 
 
48
 
  return GRUB_ERR_NONE;
49
 
}
50
 
 
51
 
/* Relocate symbols.  */
52
 
grub_err_t
53
 
grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
54
 
{
55
 
  Elf_Ehdr *e = ehdr;
56
 
  Elf_Shdr *s;
57
 
  Elf_Word entsize;
58
 
  unsigned i;
59
 
  grub_size_t gp_size = 0;
60
 
  /* FIXME: suboptimal.  */
61
 
  grub_uint32_t *gp, *gpptr;
62
 
  grub_uint32_t gp0;
63
 
 
64
 
  /* Find a symbol table.  */
65
 
  for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
66
 
       i < e->e_shnum;
67
 
       i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
68
 
    if (s->sh_type == SHT_SYMTAB)
69
 
      break;
70
 
 
71
 
  if (i == e->e_shnum)
72
 
    return grub_error (GRUB_ERR_BAD_MODULE, "no symtab found");
73
 
 
74
 
  entsize = s->sh_entsize;
75
 
 
76
 
  /* Find reginfo. */
77
 
  for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
78
 
       i < e->e_shnum;
79
 
       i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
80
 
    if (s->sh_type == SHT_MIPS_REGINFO)
81
 
      break;
82
 
 
83
 
  if (i == e->e_shnum)
84
 
    return grub_error (GRUB_ERR_BAD_MODULE, "no reginfo found");
85
 
 
86
 
  gp0 = ((grub_uint32_t *)((char *) e + s->sh_offset))[5];
87
 
 
88
 
  for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
89
 
       i < e->e_shnum;
90
 
       i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
91
 
    if (s->sh_type == SHT_REL)
92
 
      {
93
 
        grub_dl_segment_t seg;
94
 
 
95
 
        /* Find the target segment.  */
96
 
        for (seg = mod->segment; seg; seg = seg->next)
97
 
          if (seg->section == s->sh_info)
98
 
            break;
99
 
 
100
 
        if (seg)
101
 
          {
102
 
            Elf_Rel *rel, *max;
103
 
 
104
 
            for (rel = (Elf_Rel *) ((char *) e + s->sh_offset),
105
 
                   max = rel + s->sh_size / s->sh_entsize;
106
 
                 rel < max;
107
 
                 rel++)
108
 
                switch (ELF_R_TYPE (rel->r_info))
109
 
                  {
110
 
                  case R_MIPS_GOT16:
111
 
                  case R_MIPS_CALL16:
112
 
                  case R_MIPS_GPREL32:
113
 
                    gp_size += 4;
114
 
                    break;
115
 
                  }
116
 
          }
117
 
      }
118
 
 
119
 
  if (gp_size > 0x08000)
120
 
    return grub_error (GRUB_ERR_OUT_OF_RANGE, "__gnu_local_gp is too big\n");
121
 
 
122
 
  gpptr = gp = grub_malloc (gp_size);
123
 
  if (!gp)
124
 
    return grub_errno;
125
 
 
126
 
  for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
127
 
       i < e->e_shnum;
128
 
       i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
129
 
    if (s->sh_type == SHT_REL)
130
 
      {
131
 
        grub_dl_segment_t seg;
132
 
 
133
 
        /* Find the target segment.  */
134
 
        for (seg = mod->segment; seg; seg = seg->next)
135
 
          if (seg->section == s->sh_info)
136
 
            break;
137
 
 
138
 
        if (seg)
139
 
          {
140
 
            Elf_Rel *rel, *max;
141
 
 
142
 
            for (rel = (Elf_Rel *) ((char *) e + s->sh_offset),
143
 
                   max = rel + s->sh_size / s->sh_entsize;
144
 
                 rel < max;
145
 
                 rel++)
146
 
              {
147
 
                Elf_Word *addr;
148
 
                Elf_Sym *sym;
149
 
 
150
 
                if (seg->size < rel->r_offset)
151
 
                  return grub_error (GRUB_ERR_BAD_MODULE,
152
 
                                     "reloc offset is out of the segment");
153
 
 
154
 
                addr = (Elf_Word *) ((char *) seg->addr + rel->r_offset);
155
 
                sym = (Elf_Sym *) ((char *) mod->symtab
156
 
                                     + entsize * ELF_R_SYM (rel->r_info));
157
 
                if (sym->st_value == (grub_addr_t) &__gnu_local_gp_dummy)
158
 
                  sym->st_value = (grub_addr_t) gp;
159
 
 
160
 
                switch (ELF_R_TYPE (rel->r_info))
161
 
                  {
162
 
                  case R_MIPS_HI16:
163
 
                    {
164
 
                      grub_uint32_t value;
165
 
                      Elf_Rel *rel2;
166
 
                      
167
 
                      /* Handle partner lo16 relocation. Lower part is
168
 
                         treated as signed. Hence add 0x8000 to compensate. 
169
 
                       */
170
 
                      value = (*(grub_uint16_t *) addr << 16)
171
 
                        + sym->st_value + 0x8000;
172
 
                      for (rel2 = rel + 1; rel2 < max; rel2++)
173
 
                        if (ELF_R_SYM (rel2->r_info)
174
 
                            == ELF_R_SYM (rel->r_info)
175
 
                            && ELF_R_TYPE (rel2->r_info) == R_MIPS_LO16)
176
 
                          {
177
 
                            value += *(grub_int16_t *)
178
 
                              ((char *) seg->addr + rel2->r_offset);
179
 
                            break;
180
 
                          }
181
 
                      *(grub_uint16_t *) addr = (value >> 16) & 0xffff;
182
 
                    }
183
 
                    break;
184
 
                  case R_MIPS_LO16:
185
 
                    *(grub_uint16_t *) addr += (sym->st_value) & 0xffff;
186
 
                    break;
187
 
                  case R_MIPS_32:
188
 
                    *(grub_uint32_t *) addr += sym->st_value;
189
 
                    break;
190
 
                  case R_MIPS_GPREL32:
191
 
                    *(grub_uint32_t *) addr = sym->st_value
192
 
                      + *(grub_uint32_t *) addr + gp0 - (grub_uint32_t)gp;
193
 
                    break;
194
 
 
195
 
                  case R_MIPS_26:
196
 
                    {
197
 
                      grub_uint32_t value;
198
 
                      grub_uint32_t raw;
199
 
                      raw = (*(grub_uint32_t *) addr) & 0x3ffffff;
200
 
                      value = raw << 2;
201
 
                      value += sym->st_value;
202
 
                      raw = (value >> 2) & 0x3ffffff;
203
 
                        
204
 
                      *(grub_uint32_t *) addr = 
205
 
                        raw | ((*(grub_uint32_t *) addr) & 0xfc000000);
206
 
                    }
207
 
                    break;
208
 
                  case R_MIPS_GOT16:
209
 
                  case R_MIPS_CALL16:
210
 
                    /* FIXME: reuse*/
211
 
                    *gpptr = sym->st_value + *(grub_uint16_t *) addr;
212
 
                    *(grub_uint16_t *) addr
213
 
                      = sizeof (grub_uint32_t) * (gpptr - gp);
214
 
                    gpptr++;
215
 
                    break;
216
 
                  default:
217
 
                    {
218
 
                      grub_free (gp);
219
 
                      return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
220
 
                                         "Unknown relocation type %d\n",
221
 
                                         ELF_R_TYPE (rel->r_info));
222
 
                    }
223
 
                    break;
224
 
                  }
225
 
              }
226
 
          }
227
 
      }
228
 
 
229
 
  return GRUB_ERR_NONE;
230
 
}
231
 
 
232
 
void 
233
 
grub_arch_dl_init_linker (void)
234
 
{
235
 
  grub_dl_register_symbol ("__gnu_local_gp", &__gnu_local_gp_dummy, 0);
236
 
}
237