setup-x86_64.S 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * purgatory: setup code
  3. *
  4. * Copyright (C) 2003,2004 Eric Biederman (ebiederm@xmission.com)
  5. * Copyright (C) 2014 Red Hat Inc.
  6. *
  7. * This code has been taken from kexec-tools.
  8. *
  9. * This source code is licensed under the GNU General Public License,
  10. * Version 2. See the file COPYING for more details.
  11. */
  12. #include <asm/purgatory.h>
  13. .text
  14. .globl purgatory_start
  15. .balign 16
  16. purgatory_start:
  17. .code64
  18. /* Load a gdt so I know what the segment registers are */
  19. lgdt gdt(%rip)
  20. /* load the data segments */
  21. movl $0x18, %eax /* data segment */
  22. movl %eax, %ds
  23. movl %eax, %es
  24. movl %eax, %ss
  25. movl %eax, %fs
  26. movl %eax, %gs
  27. /* Setup a stack */
  28. leaq lstack_end(%rip), %rsp
  29. /* Call the C code */
  30. call purgatory
  31. jmp entry64
  32. .section ".rodata"
  33. .balign 16
  34. gdt: /* 0x00 unusable segment
  35. * 0x08 unused
  36. * so use them as the gdt ptr
  37. */
  38. .word gdt_end - gdt - 1
  39. .quad gdt
  40. .word 0, 0, 0
  41. /* 0x10 4GB flat code segment */
  42. .word 0xFFFF, 0x0000, 0x9A00, 0x00AF
  43. /* 0x18 4GB flat data segment */
  44. .word 0xFFFF, 0x0000, 0x9200, 0x00CF
  45. gdt_end:
  46. .bss
  47. .balign 4096
  48. lstack:
  49. .skip 4096
  50. lstack_end: