2008-08-11 Robert Millan <rmh@aybabtu.com>
[grub2/jjazz.git] / kern / i386 / coreboot / init.c
blob0e6567b9df49041e69b17b62d9e347489290a17c
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2002,2003,2004,2005,2006,2007,2008 Free Software Foundation, Inc.
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.
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.
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/>.
19 #include <grub/kernel.h>
20 #include <grub/mm.h>
21 #include <grub/machine/time.h>
22 #include <grub/machine/init.h>
23 #include <grub/machine/memory.h>
24 #include <grub/machine/console.h>
25 #include <grub/machine/kernel.h>
26 #include <grub/types.h>
27 #include <grub/err.h>
28 #include <grub/dl.h>
29 #include <grub/misc.h>
30 #include <grub/loader.h>
31 #include <grub/env.h>
32 #include <grub/cache.h>
33 #include <grub/time.h>
34 #include <grub/symbol.h>
35 #include <grub/cpu/io.h>
37 #define GRUB_FLOPPY_REG_DIGITAL_OUTPUT 0x3f2
39 extern char _start[];
40 extern char _end[];
42 grub_addr_t grub_os_area_addr;
43 grub_size_t grub_os_area_size;
44 grub_size_t grub_lower_mem, grub_upper_mem;
46 /* FIXME: we need interrupts to do this right */
47 static grub_uint32_t grub_time_tics = 0;
49 grub_uint32_t
50 grub_get_rtc (void)
52 return grub_time_tics;
55 /* Stop the floppy drive from spinning, so that other software is
56 jumped to with a known state. */
57 void
58 grub_stop_floppy (void)
60 grub_outb (0, GRUB_FLOPPY_REG_DIGITAL_OUTPUT);
63 void
64 grub_exit (void)
66 grub_printf ("grub_exit() is not implemented.\n");
67 grub_stop ();
70 void
71 grub_arch_sync_caches (void *address __attribute__ ((unused)),
72 grub_size_t len __attribute__ ((unused)))
76 void
77 grub_machine_init (void)
79 /* Initialize the console as early as possible. */
80 grub_console_init ();
82 grub_lower_mem = GRUB_MEMORY_MACHINE_LOWER_USABLE;
83 grub_upper_mem = 0;
85 auto int heap_init (mem_region_t);
86 int heap_init (mem_region_t mem_region)
88 grub_uint64_t addr = mem_region->addr;
89 grub_uint64_t size = mem_region->size;
91 #if GRUB_CPU_SIZEOF_VOID_P == 4
92 /* Restrict ourselves to 32-bit memory space. */
93 if (addr > ULONG_MAX)
95 grub_upper_mem = ULONG_MAX;
96 return 0;
98 if (addr + size > ULONG_MAX)
99 size = ULONG_MAX - addr;
100 #endif
102 grub_upper_mem = grub_max (grub_upper_mem, addr + size);
104 if (mem_region->type != GRUB_LINUXBIOS_MEMORY_AVAILABLE)
105 return 0;
107 /* Avoid the lower memory. */
108 if (addr < GRUB_MEMORY_MACHINE_LOWER_SIZE)
110 if (addr + size <= GRUB_MEMORY_MACHINE_LOWER_SIZE)
111 return 0;
112 else
114 size -= GRUB_MEMORY_MACHINE_LOWER_SIZE - addr;
115 addr = GRUB_MEMORY_MACHINE_LOWER_SIZE;
119 if (addr == GRUB_MEMORY_MACHINE_UPPER_START
120 || (addr >= GRUB_MEMORY_MACHINE_LOWER_SIZE
121 && addr <= GRUB_MEMORY_MACHINE_UPPER_START
122 && (addr + size > GRUB_MEMORY_MACHINE_UPPER_START)))
124 grub_size_t quarter = size >> 2;
126 grub_os_area_addr = addr;
127 grub_os_area_size = size - quarter;
128 grub_mm_init_region ((void *) (grub_os_area_addr + grub_os_area_size),
129 quarter);
131 else
132 grub_mm_init_region ((void *) (grub_addr_t) addr, (grub_size_t) size);
134 return 0;
137 grub_available_iterate (heap_init);
139 /* This variable indicates size, not offset. */
140 grub_upper_mem -= GRUB_MEMORY_MACHINE_UPPER_START;
142 grub_tsc_init ();
145 void
146 grub_machine_set_prefix (void)
148 /* Initialize the prefix. */
149 grub_env_set ("prefix", grub_prefix);
152 void
153 grub_machine_fini (void)
155 grub_console_fini ();
158 /* Return the end of the core image. */
159 grub_addr_t
160 grub_arch_modules_addr (void)
162 return ALIGN_UP((grub_addr_t) _end, GRUB_MOD_ALIGN);