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>
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>
29 #include <grub/misc.h>
30 #include <grub/loader.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>
37 #include <grub/cpu/tsc.h>
39 #define GRUB_FLOPPY_REG_DIGITAL_OUTPUT 0x3f2
44 grub_addr_t grub_os_area_addr
;
45 grub_size_t grub_os_area_size
;
50 grub_fatal ("grub_get_rtc() is not implemented.\n");
53 /* Stop the floppy drive from spinning, so that other software is
54 jumped to with a known state. */
56 grub_stop_floppy (void)
58 grub_outb (0, GRUB_FLOPPY_REG_DIGITAL_OUTPUT
);
64 grub_fatal ("grub_exit() is not implemented.\n");
68 grub_arch_sync_caches (void *address
__attribute__ ((unused
)),
69 grub_size_t len
__attribute__ ((unused
)))
74 grub_machine_init (void)
76 /* Initialize the console as early as possible. */
77 grub_vga_text_init ();
79 auto int NESTED_FUNC_ATTR
heap_init (grub_uint64_t
, grub_uint64_t
, grub_uint32_t
);
80 int NESTED_FUNC_ATTR
heap_init (grub_uint64_t addr
, grub_uint64_t size
, grub_uint32_t type
)
82 #if GRUB_CPU_SIZEOF_VOID_P == 4
83 /* Restrict ourselves to 32-bit memory space. */
84 if (addr
> GRUB_ULONG_MAX
)
86 if (addr
+ size
> GRUB_ULONG_MAX
)
87 size
= GRUB_ULONG_MAX
- addr
;
90 if (type
!= GRUB_MACHINE_MEMORY_AVAILABLE
)
93 /* Avoid the lower memory. */
94 if (addr
< GRUB_MEMORY_MACHINE_LOWER_SIZE
)
96 if (addr
+ size
<= GRUB_MEMORY_MACHINE_LOWER_SIZE
)
100 size
-= GRUB_MEMORY_MACHINE_LOWER_SIZE
- addr
;
101 addr
= GRUB_MEMORY_MACHINE_LOWER_SIZE
;
105 if (addr
== GRUB_MEMORY_MACHINE_UPPER_START
106 || (addr
>= GRUB_MEMORY_MACHINE_LOWER_SIZE
107 && addr
<= GRUB_MEMORY_MACHINE_UPPER_START
108 && (addr
+ size
> GRUB_MEMORY_MACHINE_UPPER_START
)))
110 grub_size_t quarter
= size
>> 2;
112 grub_os_area_addr
= addr
;
113 grub_os_area_size
= size
- quarter
;
114 grub_mm_init_region ((void *) (grub_os_area_addr
+ grub_os_area_size
),
118 grub_mm_init_region ((void *) (grub_addr_t
) addr
, (grub_size_t
) size
);
123 grub_machine_mmap_init ();
124 grub_machine_mmap_iterate (heap_init
);
130 grub_machine_set_prefix (void)
132 /* Initialize the prefix. */
133 grub_env_set ("prefix", grub_prefix
);
137 grub_machine_fini (void)
139 grub_vga_text_fini ();
143 /* Return the end of the core image. */
145 grub_arch_modules_addr (void)
147 return ALIGN_UP((grub_addr_t
) _end
, GRUB_MOD_ALIGN
);