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>
37 #define GRUB_FLOPPY_REG_DIGITAL_OUTPUT 0x3f2
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;
52 return grub_time_tics
;
55 /* Stop the floppy drive from spinning, so that other software is
56 jumped to with a known state. */
58 grub_stop_floppy (void)
60 grub_outb (0, GRUB_FLOPPY_REG_DIGITAL_OUTPUT
);
66 grub_printf ("grub_exit() is not implemented.\n");
71 grub_arch_sync_caches (void *address
__attribute__ ((unused
)),
72 grub_size_t len
__attribute__ ((unused
)))
77 grub_machine_init (void)
79 /* Initialize the console as early as possible. */
82 grub_lower_mem
= GRUB_MEMORY_MACHINE_LOWER_USABLE
;
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. */
95 grub_upper_mem
= ULONG_MAX
;
98 if (addr
+ size
> ULONG_MAX
)
99 size
= ULONG_MAX
- addr
;
102 grub_upper_mem
= grub_max (grub_upper_mem
, addr
+ size
);
104 if (mem_region
->type
!= GRUB_LINUXBIOS_MEMORY_AVAILABLE
)
107 /* Avoid the lower memory. */
108 if (addr
< GRUB_MEMORY_MACHINE_LOWER_SIZE
)
110 if (addr
+ size
<= GRUB_MEMORY_MACHINE_LOWER_SIZE
)
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
),
132 grub_mm_init_region ((void *) (grub_addr_t
) addr
, (grub_size_t
) size
);
137 grub_available_iterate (heap_init
);
139 /* This variable indicates size, not offset. */
140 grub_upper_mem
-= GRUB_MEMORY_MACHINE_UPPER_START
;
146 grub_machine_set_prefix (void)
148 /* Initialize the prefix. */
149 grub_env_set ("prefix", grub_prefix
);
153 grub_machine_fini (void)
155 grub_console_fini ();
158 /* Return the end of the core image. */
160 grub_arch_modules_addr (void)
162 return ALIGN_UP((grub_addr_t
) _end
, GRUB_MOD_ALIGN
);