args changelog should mention this too
[grub2/phcoder.git] / kern / loader.c
blob2b67d49b965bfb54cb2d9170ba9393a1ccd17e5a
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2002,2003,2004,2006,2007 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/loader.h>
20 #include <grub/misc.h>
21 #include <grub/mm.h>
22 #include <grub/err.h>
23 #include <grub/kernel.h>
25 static grub_err_t (*grub_loader_boot_func) (void);
26 static grub_err_t (*grub_loader_unload_func) (void);
27 static int grub_loader_noreturn;
29 static int grub_loader_loaded;
31 int
32 grub_loader_is_loaded (void)
34 return grub_loader_loaded;
37 void
38 grub_loader_set (grub_err_t (*boot) (void),
39 grub_err_t (*unload) (void),
40 int noreturn)
42 if (grub_loader_loaded && grub_loader_unload_func)
43 grub_loader_unload_func ();
45 grub_loader_boot_func = boot;
46 grub_loader_unload_func = unload;
47 grub_loader_noreturn = noreturn;
49 grub_loader_loaded = 1;
52 void
53 grub_loader_unset(void)
55 if (grub_loader_loaded && grub_loader_unload_func)
56 grub_loader_unload_func ();
58 grub_loader_boot_func = 0;
59 grub_loader_unload_func = 0;
61 grub_loader_loaded = 0;
64 grub_err_t
65 grub_loader_boot (void)
67 if (! grub_loader_loaded)
68 return grub_error (GRUB_ERR_NO_KERNEL, "no loaded kernel");
70 if (grub_loader_noreturn)
71 grub_machine_fini ();
73 return (grub_loader_boot_func) ();