entry64.S 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright (C) 2003,2004 Eric Biederman (ebiederm@xmission.com)
  3. * Copyright (C) 2014 Red Hat Inc.
  4. * Author(s): Vivek Goyal <vgoyal@redhat.com>
  5. *
  6. * This code has been taken from kexec-tools.
  7. *
  8. * This source code is licensed under the GNU General Public License,
  9. * Version 2. See the file COPYING for more details.
  10. */
  11. .text
  12. .balign 16
  13. .code64
  14. .globl entry64, entry64_regs
  15. entry64:
  16. /* Setup a gdt that should be preserved */
  17. lgdt gdt(%rip)
  18. /* load the data segments */
  19. movl $0x18, %eax /* data segment */
  20. movl %eax, %ds
  21. movl %eax, %es
  22. movl %eax, %ss
  23. movl %eax, %fs
  24. movl %eax, %gs
  25. /* Setup new stack */
  26. leaq stack_init(%rip), %rsp
  27. pushq $0x10 /* CS */
  28. leaq new_cs_exit(%rip), %rax
  29. pushq %rax
  30. lretq
  31. new_cs_exit:
  32. /* Load the registers */
  33. movq rax(%rip), %rax
  34. movq rbx(%rip), %rbx
  35. movq rcx(%rip), %rcx
  36. movq rdx(%rip), %rdx
  37. movq rsi(%rip), %rsi
  38. movq rdi(%rip), %rdi
  39. movq rsp(%rip), %rsp
  40. movq rbp(%rip), %rbp
  41. movq r8(%rip), %r8
  42. movq r9(%rip), %r9
  43. movq r10(%rip), %r10
  44. movq r11(%rip), %r11
  45. movq r12(%rip), %r12
  46. movq r13(%rip), %r13
  47. movq r14(%rip), %r14
  48. movq r15(%rip), %r15
  49. /* Jump to the new code... */
  50. jmpq *rip(%rip)
  51. .section ".rodata"
  52. .balign 4
  53. entry64_regs:
  54. rax: .quad 0x0
  55. rcx: .quad 0x0
  56. rdx: .quad 0x0
  57. rbx: .quad 0x0
  58. rsp: .quad 0x0
  59. rbp: .quad 0x0
  60. rsi: .quad 0x0
  61. rdi: .quad 0x0
  62. r8: .quad 0x0
  63. r9: .quad 0x0
  64. r10: .quad 0x0
  65. r11: .quad 0x0
  66. r12: .quad 0x0
  67. r13: .quad 0x0
  68. r14: .quad 0x0
  69. r15: .quad 0x0
  70. rip: .quad 0x0
  71. .size entry64_regs, . - entry64_regs
  72. /* GDT */
  73. .section ".rodata"
  74. .balign 16
  75. gdt:
  76. /* 0x00 unusable segment
  77. * 0x08 unused
  78. * so use them as gdt ptr
  79. */
  80. .word gdt_end - gdt - 1
  81. .quad gdt
  82. .word 0, 0, 0
  83. /* 0x10 4GB flat code segment */
  84. .word 0xFFFF, 0x0000, 0x9A00, 0x00AF
  85. /* 0x18 4GB flat data segment */
  86. .word 0xFFFF, 0x0000, 0x9200, 0x00CF
  87. gdt_end:
  88. stack: .quad 0, 0
  89. stack_init: