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