startup.S 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 1999,2000,2001,2002,2003,2005,2006,2007,2008,2009 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 <config.h>
  19. #include <grub/symbol.h>
  20. #include <grub/machine/memory.h>
  21. #include <grub/machine/kernel.h>
  22. .text
  23. .code32
  24. .globl _start
  25. _start:
  26. jmp codestart
  27. .org GRUB_KERNEL_I386_QEMU_CORE_ENTRY_ADDR
  28. VARIABLE(grub_core_entry_addr)
  29. .long 0
  30. codestart:
  31. /* Relocate to low memory. First we figure out our location.
  32. We will derive the rom start address from it. */
  33. call 1f
  34. 1: popl %esi
  35. /* Rom size is a multiple of 64 kiB. With this we get the
  36. value of `grub_core_entry_addr' in %esi. */
  37. xorw %si, %si
  38. movl $(_edata - _start), %ecx
  39. movl $_start, %edi
  40. cld
  41. rep
  42. movsb
  43. ljmp $GRUB_MEMORY_MACHINE_PROT_MODE_CSEG, $1f
  44. 1:
  45. /* clean out the bss */
  46. movl $BSS_START_SYMBOL, %edi
  47. /* compute the bss length */
  48. movl $END_SYMBOL, %ecx
  49. subl %edi, %ecx
  50. /* clean out */
  51. xorl %eax, %eax
  52. cld
  53. rep
  54. stosb
  55. /*
  56. * Call the start of main body of C code.
  57. */
  58. call EXT_C(grub_main)
  59. /* This should never happen. */
  60. cli
  61. 1:
  62. hlt
  63. jmp 1b