relocator_asm.S 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 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 <grub/symbol.h>
  19. #include <grub/i386/memory.h>
  20. .p2align 2
  21. VARIABLE(grub_relocator_backward_start)
  22. /* mov imm32, %eax */
  23. .byte 0xb8
  24. VARIABLE(grub_relocator_backward_dest)
  25. .long 0
  26. movl %eax, %edi
  27. /* mov imm32, %eax */
  28. .byte 0xb8
  29. VARIABLE(grub_relocator_backward_src)
  30. .long 0
  31. movl %eax, %esi
  32. /* mov imm32, %ecx */
  33. .byte 0xb9
  34. VARIABLE(grub_relocator_backward_chunk_size)
  35. .long 0
  36. add %ecx, %esi
  37. add %ecx, %edi
  38. /* Backward movsb is implicitly off-by-one. compensate that. */
  39. sub $1, %esi
  40. sub $1, %edi
  41. /* Backward copy. */
  42. std
  43. rep
  44. movsb
  45. VARIABLE(grub_relocator_backward_end)
  46. VARIABLE(grub_relocator_forward_start)
  47. /* mov imm32, %eax */
  48. .byte 0xb8
  49. VARIABLE(grub_relocator_forward_dest)
  50. .long 0
  51. movl %eax, %edi
  52. /* mov imm32, %rax */
  53. .byte 0xb8
  54. VARIABLE(grub_relocator_forward_src)
  55. .long 0
  56. movl %eax, %esi
  57. /* mov imm32, %ecx */
  58. .byte 0xb9
  59. VARIABLE(grub_relocator_forward_chunk_size)
  60. .long 0
  61. /* Forward copy. */
  62. cld
  63. rep
  64. movsb
  65. VARIABLE(grub_relocator_forward_end)