reboot.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2011 Free Software Foundation, Inc.
  4. *
  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.
  9. *
  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.
  14. *
  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/>.
  17. */
  18. #include <grub/relocator.h>
  19. #include <grub/cpu/relocator.h>
  20. #include <grub/misc.h>
  21. #include <grub/mm.h>
  22. #include <grub/cpu/reboot.h>
  23. #include <grub/i386/floppy.h>
  24. void
  25. grub_reboot (void)
  26. {
  27. struct grub_relocator *relocator = NULL;
  28. grub_relocator_chunk_t ch;
  29. grub_err_t err;
  30. void *buf;
  31. struct grub_relocator16_state state;
  32. grub_uint16_t segment;
  33. relocator = grub_relocator_new ();
  34. if (!relocator)
  35. while (1);
  36. err = grub_relocator_alloc_chunk_align (relocator, &ch, 0x1000, 0x1000,
  37. grub_reboot_end - grub_reboot_start,
  38. 16, GRUB_RELOCATOR_PREFERENCE_NONE,
  39. 0);
  40. if (err)
  41. while (1);
  42. buf = get_virtual_current_address (ch);
  43. grub_memcpy (buf, grub_reboot_start, grub_reboot_end - grub_reboot_start);
  44. segment = ((grub_addr_t) get_physical_target_address (ch)) >> 4;
  45. state.gs = state.fs = state.es = state.ds = state.ss = segment;
  46. state.sp = 0;
  47. state.cs = segment;
  48. state.ip = 0;
  49. state.a20 = 0;
  50. grub_stop_floppy ();
  51. err = grub_relocator16_boot (relocator, state);
  52. while (1);
  53. }