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. .text
  13. .globl purgatory_start
  14. .balign 16
  15. purgatory_start:
  16. .code64
  17. /* Load a gdt so I know what the segment registers are */
  18. lgdt gdt(%rip)
  19. /* load the data segments */
  20. movl $0x18, %eax /* data segment */
  21. movl %eax, %ds
  22. movl %eax, %es
  23. movl %eax, %ss
  24. movl %eax, %fs
  25. movl %eax, %gs
  26. /* Setup a stack */
  27. leaq lstack_end(%rip), %rsp
  28. /* Call the C code */
  29. call purgatory
  30. jmp entry64
  31. .section ".rodata"
  32. .balign 16
  33. gdt: /* 0x00 unusable segment
  34. * 0x08 unused
  35. * so use them as the gdt ptr
  36. */
  37. .word gdt_end - gdt - 1
  38. .quad gdt
  39. .word 0, 0, 0
  40. /* 0x10 4GB flat code segment */
  41. .word 0xFFFF, 0x0000, 0x9A00, 0x00AF
  42. /* 0x18 4GB flat data segment */
  43. .word 0xFFFF, 0x0000, 0x9200, 0x00CF
  44. gdt_end:
  45. .bss
  46. .balign 4096
  47. lstack:
  48. .skip 4096
  49. lstack_end: