Updated PCI IDs to latest snapshot.
[tangerine.git] / arch / common / boot / grub2 / kern / i386 / coreboot / init.c
blob3a50050998969147fcaf1216cfbd53be370c9744
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>
36 #include <grub/cpu/kernel.h>
38 #define GRUB_FLOPPY_REG_DIGITAL_OUTPUT 0x3f2
40 extern char _start[];
41 extern char _end[];
43 grub_addr_t grub_os_area_addr;
44 grub_size_t grub_os_area_size;
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_vga_text_init ();
81 grub_at_keyboard_init ();
83 auto int NESTED_FUNC_ATTR heap_init (grub_uint64_t, grub_uint64_t, grub_uint32_t);
84 int NESTED_FUNC_ATTR heap_init (grub_uint64_t addr, grub_uint64_t size, grub_uint32_t type)
86 #if GRUB_CPU_SIZEOF_VOID_P == 4
87 /* Restrict ourselves to 32-bit memory space. */
88 if (addr > ULONG_MAX)
90 grub_upper_mem = ULONG_MAX;
91 return 0;
93 if (addr + size > ULONG_MAX)
94 size = ULONG_MAX - addr;
95 #endif
97 grub_upper_mem = grub_max (grub_upper_mem, addr + size);
99 if (type != GRUB_MACHINE_MEMORY_AVAILABLE)
100 return 0;
102 /* Avoid the lower memory. */
103 if (addr < GRUB_MEMORY_MACHINE_LOWER_SIZE)
105 if (addr + size <= GRUB_MEMORY_MACHINE_LOWER_SIZE)
106 return 0;
107 else
109 size -= GRUB_MEMORY_MACHINE_LOWER_SIZE - addr;
110 addr = GRUB_MEMORY_MACHINE_LOWER_SIZE;
114 if (addr == GRUB_MEMORY_MACHINE_UPPER_START
115 || (addr >= GRUB_MEMORY_MACHINE_LOWER_SIZE
116 && addr <= GRUB_MEMORY_MACHINE_UPPER_START
117 && (addr + size > GRUB_MEMORY_MACHINE_UPPER_START)))
119 grub_size_t quarter = size >> 2;
121 grub_os_area_addr = addr;
122 grub_os_area_size = size - quarter;
123 grub_mm_init_region ((void *) (grub_os_area_addr + grub_os_area_size),
124 quarter);
126 else
127 grub_mm_init_region ((void *) (grub_addr_t) addr, (grub_size_t) size);
129 return 0;
132 grub_machine_mmap_init ();
133 grub_machine_mmap_iterate (heap_init);
135 /* This variable indicates size, not offset. */
136 grub_upper_mem -= GRUB_MEMORY_MACHINE_UPPER_START;
138 grub_tsc_init ();
141 void
142 grub_machine_set_prefix (void)
144 /* Initialize the prefix. */
145 grub_env_set ("prefix", grub_prefix);
148 void
149 grub_machine_fini (void)
151 grub_at_keyboard_fini ();
152 grub_vga_text_fini ();
155 /* Return the end of the core image. */
156 grub_addr_t
157 grub_arch_modules_addr (void)
159 return ALIGN_UP((grub_addr_t) _end, GRUB_MOD_ALIGN);