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

« back to all changes in this revision

Viewing changes to kern/powerpc/ieee1275/init.c

  • Committer: Bazaar Package Importer
  • Author(s): Otavio Salvador
  • Date: 2006-01-05 15:20:40 UTC
  • mto: (17.3.1 squeeze) (1.9.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20060105152040-b72i5pq1a82z22yi
Tags: upstream-1.92
ImportĀ upstreamĀ versionĀ 1.92

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  init.c -- Initialize GRUB on the newworld mac (PPC).  */
 
2
/*
 
3
 *  GRUB  --  GRand Unified Bootloader
 
4
 *  Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
 
5
 *
 
6
 *  This program 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 2 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  This program 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 this program; if not, write to the Free Software
 
18
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
19
 */
 
20
 
 
21
#include <grub/kernel.h>
 
22
#include <grub/dl.h>
 
23
#include <grub/disk.h>
 
24
#include <grub/mm.h>
 
25
#include <grub/partition.h>
 
26
#include <grub/normal.h>
 
27
#include <grub/fs.h>
 
28
#include <grub/setjmp.h>
 
29
#include <grub/env.h>
 
30
#include <grub/misc.h>
 
31
#include <grub/machine/console.h>
 
32
#include <grub/machine/time.h>
 
33
#include <grub/machine/kernel.h>
 
34
#include <grub/ieee1275/ofdisk.h>
 
35
#include <grub/ieee1275/ieee1275.h>
 
36
 
 
37
/* Apple OF 1.0.5 reserves 0x0 to 0x4000 for the exception handlers.  */
 
38
static const grub_addr_t grub_heap_start = 0x4000;
 
39
static grub_addr_t grub_heap_len;
 
40
 
 
41
void
 
42
abort (void)
 
43
{
 
44
  /* Trap to Open Firmware.  */
 
45
  asm ("trap");
 
46
 
 
47
  for (;;);
 
48
}
 
49
 
 
50
/* Translate an OF filesystem path (separated by backslashes), into a GRUB
 
51
   path (separated by forward slashes).  */
 
52
static void
 
53
grub_translate_ieee1275_path (char *filepath)
 
54
{
 
55
  char *backslash;
 
56
 
 
57
  backslash = grub_strchr (filepath, '\\');
 
58
  while (backslash != 0)
 
59
    {
 
60
      *backslash = '/';
 
61
      backslash = grub_strchr (filepath, '\\');
 
62
    }
 
63
}
 
64
 
 
65
static void
 
66
grub_set_prefix (void)
 
67
{
 
68
  char bootpath[64]; /* XXX check length */
 
69
  char *filename;
 
70
  char *prefix;
 
71
 
 
72
  if (grub_ieee1275_get_property (grub_ieee1275_chosen, "bootpath", &bootpath,
 
73
                                  sizeof (bootpath), 0))
 
74
    {
 
75
      /* Should never happen.  */
 
76
      grub_printf ("/chosen/bootpath property missing!\n");
 
77
      grub_env_set ("prefix", "");
 
78
      return;
 
79
    }
 
80
 
 
81
  /* Transform an OF device path to a GRUB path.  */
 
82
 
 
83
  prefix = grub_ieee1275_encode_devname (bootpath);
 
84
 
 
85
  filename = grub_ieee1275_get_filename (bootpath);
 
86
  if (filename)
 
87
    {
 
88
      char *newprefix;
 
89
      char *lastslash = grub_strrchr (filename, '\\');
 
90
 
 
91
      /* Truncate at last directory.  */
 
92
      if (lastslash)
 
93
        {
 
94
          *lastslash = '\0';
 
95
          grub_translate_ieee1275_path (filename);
 
96
 
 
97
          newprefix = grub_malloc (grub_strlen (prefix)
 
98
                                   + grub_strlen (filename));
 
99
          grub_sprintf (newprefix, "%s%s", prefix, filename);
 
100
          grub_free (prefix);
 
101
          prefix = newprefix;
 
102
        }
 
103
    }
 
104
 
 
105
  grub_env_set ("prefix", prefix);
 
106
 
 
107
  grub_free (filename);
 
108
  grub_free (prefix);
 
109
}
 
110
 
 
111
void
 
112
grub_machine_init (void)
 
113
{
 
114
  char args[256];
 
115
  grub_ieee1275_phandle_t chosen;
 
116
  int actual;
 
117
  extern char _start;
 
118
 
 
119
  grub_console_init ();
 
120
 
 
121
  /* Apple OF 3.1.1 reserves an extra 0x1000 bytes below the load address
 
122
     of an ELF file.  */
 
123
  grub_heap_len = (grub_addr_t) &_start - 0x1000 - grub_heap_start;
 
124
 
 
125
  if (grub_ieee1275_claim (grub_heap_start, grub_heap_len, 0, 0))
 
126
    {
 
127
      grub_printf ("Failed to claim heap at 0x%x, len 0x%x\n", grub_heap_start,
 
128
                   grub_heap_len);
 
129
      abort ();
 
130
    }
 
131
  grub_mm_init_region ((void *) grub_heap_start, grub_heap_len);
 
132
 
 
133
  grub_set_prefix ();
 
134
 
 
135
  grub_ofdisk_init ();
 
136
 
 
137
  /* Process commandline.  */
 
138
  grub_ieee1275_finddevice ("/chosen", &chosen);
 
139
  if (grub_ieee1275_get_property (chosen, "bootargs", &args,
 
140
                                  sizeof args, &actual) == 0
 
141
      && actual > 1)
 
142
    {
 
143
      int i = 0;
 
144
 
 
145
      while (i < actual)
 
146
        {
 
147
          char *command = &args[i];
 
148
          char *end;
 
149
          char *val;
 
150
 
 
151
          end = grub_strchr (command, ';');
 
152
          if (end == 0)
 
153
            i = actual; /* No more commands after this one.  */
 
154
          else
 
155
            {
 
156
              *end = '\0';
 
157
              i += end - command + 1;
 
158
              while (grub_isspace(args[i]))
 
159
                i++;
 
160
            }
 
161
 
 
162
          /* Process command.  */
 
163
          val = grub_strchr (command, '=');
 
164
          if (val)
 
165
            {
 
166
              *val = '\0';
 
167
              grub_env_set (command, val + 1);
 
168
            }
 
169
        }
 
170
    }
 
171
}
 
172
 
 
173
void
 
174
grub_machine_fini (void)
 
175
{
 
176
  grub_ofdisk_fini ();
 
177
  grub_console_fini ();
 
178
}
 
179
 
 
180
void
 
181
grub_stop (void)
 
182
{
 
183
  for (;;);
 
184
}
 
185
 
 
186
grub_uint32_t
 
187
grub_get_rtc (void)
 
188
{
 
189
  grub_uint32_t msecs = 0;
 
190
 
 
191
  grub_ieee1275_milliseconds (&msecs);
 
192
 
 
193
  return msecs;
 
194
}
 
195
 
 
196
grub_addr_t
 
197
grub_arch_modules_addr (void)
 
198
{
 
199
  return GRUB_IEEE1275_MODULE_BASE;
 
200
}