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

« back to all changes in this revision

Viewing changes to grub-core/kern/i386/pc/init.c

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2012-09-13 18:02:04 UTC
  • mfrom: (1.17.15 upstream)
  • mto: (17.6.27 experimental)
  • mto: This revision was merged to the branch mainline in revision 145.
  • Revision ID: package-import@ubuntu.com-20120913180204-mojnmocbimlom4im
Tags: upstream-2.00
ImportĀ upstreamĀ versionĀ 2.00

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#include <grub/cache.h>
34
34
#include <grub/time.h>
35
35
#include <grub/cpu/tsc.h>
 
36
#include <grub/machine/time.h>
36
37
 
37
38
struct mem_region
38
39
{
45
46
static struct mem_region mem_regions[MAX_REGIONS];
46
47
static int num_regions;
47
48
 
48
 
static char *
49
 
make_install_device (void)
50
 
{
 
49
void (*grub_pc_net_config) (char **device, char **path);
 
50
 
 
51
/*
 
52
 *      return the real time in ticks, of which there are about
 
53
 *      18-20 per second
 
54
 */
 
55
grub_uint32_t
 
56
grub_get_rtc (void)
 
57
{
 
58
  struct grub_bios_int_registers regs;
 
59
 
 
60
  regs.eax = 0;
 
61
  regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT;
 
62
  grub_bios_interrupt (0x1a, &regs);
 
63
 
 
64
  return (regs.ecx << 16) | (regs.edx & 0xffff);
 
65
}
 
66
 
 
67
void
 
68
grub_machine_get_bootlocation (char **device, char **path)
 
69
{
 
70
  char *ptr;
 
71
  grub_uint8_t boot_drive, dos_part, bsd_part;
 
72
 
 
73
  boot_drive = (grub_boot_device >> 24);
 
74
  dos_part = (grub_boot_device >> 16);
 
75
  bsd_part = (grub_boot_device >> 8);
 
76
 
 
77
  /* No hardcoded root partition - make it from the boot drive and the
 
78
     partition number encoded at the install time.  */
 
79
  if (boot_drive == GRUB_BOOT_MACHINE_PXE_DL)
 
80
    {
 
81
      if (grub_pc_net_config)
 
82
        grub_pc_net_config (device, path);
 
83
      return;
 
84
    }
 
85
 
51
86
  /* XXX: This should be enough.  */
52
 
  char dev[100], *ptr = dev;
53
 
 
54
 
  if (grub_prefix[0] != '(')
55
 
    {
56
 
      /* No hardcoded root partition - make it from the boot drive and the
57
 
         partition number encoded at the install time.  */
58
 
      if (grub_boot_drive == GRUB_BOOT_MACHINE_PXE_DL)
59
 
        {
60
 
          grub_strcpy (dev, "(pxe");
61
 
          ptr += sizeof ("(pxe") - 1;
62
 
        }
63
 
      else
64
 
        {
65
 
          grub_snprintf (dev, sizeof (dev),
66
 
                         "(%cd%u", (grub_boot_drive & 0x80) ? 'h' : 'f',
67
 
                         grub_boot_drive & 0x7f);
68
 
          ptr += grub_strlen (ptr);
69
 
 
70
 
          if (grub_install_dos_part >= 0)
71
 
            grub_snprintf (ptr, sizeof (dev) - (ptr - dev),
72
 
                           ",%u", grub_install_dos_part + 1);
73
 
          ptr += grub_strlen (ptr);
74
 
 
75
 
          if (grub_install_bsd_part >= 0)
76
 
            grub_snprintf (ptr, sizeof (dev) - (ptr - dev), ",%u",
77
 
                           grub_install_bsd_part + 1);
78
 
          ptr += grub_strlen (ptr);
79
 
        }
80
 
 
81
 
      grub_snprintf (ptr, sizeof (dev) - (ptr - dev), ")%s", grub_prefix);
82
 
      grub_strcpy (grub_prefix, dev);
83
 
    }
84
 
  else if (grub_prefix[1] == ',' || grub_prefix[1] == ')')
85
 
    {
86
 
      /* We have a prefix, but still need to fill in the boot drive.  */
87
 
      grub_snprintf (dev, sizeof (dev),
88
 
                     "(%cd%u%s", (grub_boot_drive & 0x80) ? 'h' : 'f',
89
 
                     grub_boot_drive & 0x7f, grub_prefix + 1);
90
 
      grub_strcpy (grub_prefix, dev);
91
 
    }
92
 
 
93
 
  return grub_prefix;
 
87
#define DEV_SIZE 100
 
88
  *device = grub_malloc (DEV_SIZE);
 
89
  ptr = *device;
 
90
  grub_snprintf (*device, DEV_SIZE,
 
91
                 "%cd%u", (boot_drive & 0x80) ? 'h' : 'f',
 
92
                 boot_drive & 0x7f);
 
93
  ptr += grub_strlen (ptr);
 
94
 
 
95
  if (dos_part != 0xff)
 
96
    grub_snprintf (ptr, DEV_SIZE - (ptr - *device),
 
97
                   ",%u", dos_part + 1);
 
98
  ptr += grub_strlen (ptr);
 
99
 
 
100
  if (bsd_part != 0xff)
 
101
    grub_snprintf (ptr, DEV_SIZE - (ptr - *device), ",%u",
 
102
                   bsd_part + 1);
 
103
  ptr += grub_strlen (ptr);
 
104
  *ptr = 0;
94
105
}
95
106
 
96
107
/* Add a memory region.  */
140
151
      }
141
152
}
142
153
 
 
154
grub_addr_t grub_modbase;
 
155
extern grub_uint8_t _start[], _edata[];
 
156
 
143
157
void
144
158
grub_machine_init (void)
145
159
{
148
162
  int grub_lower_mem;
149
163
#endif
150
164
 
 
165
  grub_modbase = GRUB_MEMORY_MACHINE_DECOMPRESSION_ADDR + (_edata - _start);
 
166
 
151
167
  /* Initialize the console as early as possible.  */
152
168
  grub_console_init ();
153
169
 
212
228
}
213
229
 
214
230
void
215
 
grub_machine_set_prefix (void)
216
 
{
217
 
  /* Initialize the prefix.  */
218
 
  grub_env_set ("prefix", make_install_device ());
219
 
}
220
 
 
221
 
void
222
231
grub_machine_fini (void)
223
232
{
224
233
  grub_console_fini ();
225
234
  grub_stop_floppy ();
226
235
}
227
 
 
228
 
/* Return the end of the core image.  */
229
 
grub_addr_t
230
 
grub_arch_modules_addr (void)
231
 
{
232
 
  return GRUB_MEMORY_MACHINE_DECOMPRESSION_ADDR
233
 
    + (grub_kernel_image_size - GRUB_KERNEL_MACHINE_RAW_SIZE);
234
 
}