Debian Codegraph @

purgatory/arch/x86_64/entry64.S

raw
1 /*
2 * kexec: Linux boots Linux
3 *
4 * Copyright (C) 2003,2004 Eric Biederman ([email protected])
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation (version 2 of the License).
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include "arch/debug.h"
21
22 .text
23 .code64
24 .balign 16
25 .globl entry64, entry64_regs
26 entry64:
27 /* Don't worry about special registers... */
28
29 /* Setup a gdt that should be preserved */
30 lgdt gdt(%rip)
31
32 /* load the data segments */
33 movl $0x18, %eax /* data segment */
34 movl %eax, %ds
35 movl %eax, %es
36 movl %eax, %ss
37 movl %eax, %fs
38 movl %eax, %gs
39
40 leaq stack_init(%rip), %rsp
41 pushq $0x10 /* CS */
42 leaq new_cs_exit(%rip), %rax
43 pushq %rax
44 lretq
45 new_cs_exit:
46
47 /* Load the registers */
48 movq rax(%rip), %rax
49 movq rbx(%rip), %rbx
50 movq rcx(%rip), %rcx
51 movq rdx(%rip), %rdx
52 movq rsi(%rip), %rsi
53 movq rdi(%rip), %rdi
54 movq rsp(%rip), %rsp
55 movq rbp(%rip), %rbp
56 movq r8(%rip), %r8
57 movq r9(%rip), %r9
58 movq r10(%rip), %r10
59 movq r11(%rip), %r11
60 movq r12(%rip), %r12
61 movq r13(%rip), %r13
62 movq r14(%rip), %r14
63 movq r15(%rip), %r15
64
65 /* Jump to the new code... */
66 jmpq *rip(%rip)
67
68 .section ".rodata"
69 .balign 4
70 entry64_regs:
71 rax: .quad 0x00000000
72 rbx: .quad 0x00000000
73 rcx: .quad 0x00000000
74 rdx: .quad 0x00000000
75 rsi: .quad 0x00000000
76 rdi: .quad 0x00000000
77 rsp: .quad 0x00000000
78 rbp: .quad 0x00000000
79 r8: .quad 0x00000000
80 r9: .quad 0x00000000
81 r10: .quad 0x00000000
82 r11: .quad 0x00000000
83 r12: .quad 0x00000000
84 r13: .quad 0x00000000
85 r14: .quad 0x00000000
86 r15: .quad 0x00000000
87 rip: .quad entry32
88 .size entry64_regs, . - entry64_regs
89
90 .section ".rodata"
91 .balign 16
92 gdt: /* 0x00 unusable segment
93 * 0x08 unused
94 * so use them as the gdt ptr
95 */
96 .word gdt_end - gdt - 1
97 .quad gdt
98 .word 0, 0, 0
99
100 /* 0x10 4GB flat code segment */
101 .word 0xFFFF, 0x0000, 0x9A00, 0x00AF
102
103 /* 0x18 4GB flat data segment */
104 .word 0xFFFF, 0x0000, 0x9200, 0x00CF
105 gdt_end:
106 stack: .quad 0, 0
107 stack_init: