Debian Codegraph @

purgatory/arch/x86_64/setup-x86_64.S

raw
1 /*
2 * purgatory: setup code
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
23 #undef i386
24
25 .text
26 .globl purgatory_start
27 .balign 16
28 purgatory_start:
29 .code64
30
31 /* Load a gdt so I know what the segment registers are */
32 lgdt gdt(%rip)
33
34 /* load the data segments */
35 movl $0x18, %eax /* data segment */
36 movl %eax, %ds
37 movl %eax, %es
38 movl %eax, %ss
39 movl %eax, %fs
40 movl %eax, %gs
41
42 /* In 64bit mode the code segment is meaningless */
43
44 movq 0(%rsp), %rax
45 movq %rax, jump_back_entry(%rip)
46
47 /* Setup a stack */
48 leaq lstack_end(%rip), %rsp
49
50 /* Call the C code */
51 call purgatory
52 jmp entry64
53
54 .section ".rodata"
55 .balign 16
56 gdt: /* 0x00 unusable segment
57 * 0x08 unused
58 * so use them as the gdt ptr
59 */
60 .word gdt_end - gdt - 1
61 .quad gdt
62 .word 0, 0, 0
63
64 /* 0x10 4GB flat code segment */
65 .word 0xFFFF, 0x0000, 0x9A00, 0x00AF
66
67 /* 0x18 4GB flat data segment */
68 .word 0xFFFF, 0x0000, 0x9200, 0x00CF
69 gdt_end:
70
71 .bss
72 .balign 4096
73 lstack:
74 .skip 4096
75 lstack_end:
76