entry64.S 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2003,2004 Eric Biederman ([email protected])
  4. * Copyright (C) 2014 Red Hat Inc.
  5. * Author(s): Vivek Goyal <[email protected]>
  6. *
  7. * This code has been taken from kexec-tools.
  8. */
  9. #include <linux/linkage.h>
  10. .text
  11. .balign 16
  12. .code64
  13. SYM_CODE_START(entry64)
  14. /* Setup a gdt that should be preserved */
  15. lgdt gdt(%rip)
  16. /* load the data segments */
  17. movl $0x18, %eax /* data segment */
  18. movl %eax, %ds
  19. movl %eax, %es
  20. movl %eax, %ss
  21. movl %eax, %fs
  22. movl %eax, %gs
  23. /* Setup new stack */
  24. leaq stack_init(%rip), %rsp
  25. pushq $0x10 /* CS */
  26. leaq new_cs_exit(%rip), %rax
  27. pushq %rax
  28. lretq
  29. new_cs_exit:
  30. /* Load the registers */
  31. movq rax(%rip), %rax
  32. movq rbx(%rip), %rbx
  33. movq rcx(%rip), %rcx
  34. movq rdx(%rip), %rdx
  35. movq rsi(%rip), %rsi
  36. movq rdi(%rip), %rdi
  37. movq rsp(%rip), %rsp
  38. movq rbp(%rip), %rbp
  39. movq r8(%rip), %r8
  40. movq r9(%rip), %r9
  41. movq r10(%rip), %r10
  42. movq r11(%rip), %r11
  43. movq r12(%rip), %r12
  44. movq r13(%rip), %r13
  45. movq r14(%rip), %r14
  46. movq r15(%rip), %r15
  47. /* Jump to the new code... */
  48. jmpq *rip(%rip)
  49. SYM_CODE_END(entry64)
  50. .section ".rodata"
  51. .balign 4
  52. SYM_DATA_START(entry64_regs)
  53. rax: .quad 0x0
  54. rcx: .quad 0x0
  55. rdx: .quad 0x0
  56. rbx: .quad 0x0
  57. rsp: .quad 0x0
  58. rbp: .quad 0x0
  59. rsi: .quad 0x0
  60. rdi: .quad 0x0
  61. r8: .quad 0x0
  62. r9: .quad 0x0
  63. r10: .quad 0x0
  64. r11: .quad 0x0
  65. r12: .quad 0x0
  66. r13: .quad 0x0
  67. r14: .quad 0x0
  68. r15: .quad 0x0
  69. rip: .quad 0x0
  70. SYM_DATA_END(entry64_regs)
  71. /* GDT */
  72. .section ".rodata"
  73. .balign 16
  74. SYM_DATA_START_LOCAL(gdt)
  75. /*
  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. SYM_DATA_END_LABEL(gdt, SYM_L_LOCAL, gdt_end)
  88. SYM_DATA_START_LOCAL(stack)
  89. .quad 0, 0
  90. SYM_DATA_END_LABEL(stack, SYM_L_LOCAL, stack_init)