2 * relocate_kernel.S - put the kernel image in place to boot
3 * Copyright (C) 2002-2005 Eric Biederman <ebiederm@xmission.com>
5 * This source code is licensed under the GNU General Public License,
6 * Version 2. See the file COPYING for more details.
9 #include <linux/linkage.h>
12 * Must be relocatable PIC code callable as a C function, that once
13 * it starts can not use the previous processes stack.
15 .globl relocate_new_kernel
19 * %rsi reboot_code_buffer
26 /* zero out flags, and disable interrupts */
30 /* set a new stack at the bottom of our page... */
33 /* store the parameters back on the stack */
34 pushq %rdx /* store the start address */
36 /* Set cr0 to a known state:
37 * 31 1 == Paging enabled
38 * 18 0 == Alignment check disabled
39 * 16 0 == Write protect disabled
40 * 3 0 == No task switch
41 * 2 0 == Don't do FP software emulation.
42 * 0 1 == Proctected mode enabled
45 andq $~((1<<18)|(1<<16)|(1<<3)|(1<<2)), %rax
46 orl $((1<<31)|(1<<0)), %eax
49 /* Set cr4 to a known state:
50 * 10 0 == xmm exceptions disabled
51 * 9 0 == xmm registers instructions disabled
52 * 8 0 == performance monitoring counter disabled
53 * 7 0 == page global disabled
54 * 6 0 == machine check exceptions disabled
55 * 5 1 == physical address extension enabled
56 * 4 0 == page size extensions disabled
57 * 3 0 == Debug extensions disabled
58 * 2 0 == Time stamp disable (disabled)
59 * 1 0 == Protected mode virtual interrupts disabled
69 /* Switch to the identity mapped page tables,
75 movq %rdi, %rcx /* Put the page_list in %rcx */
80 0: /* top, read another word for the indirection page */
85 testq $0x1, %rcx /* is it a destination page? */
88 andq $0xfffffffffffff000, %rdi
91 testq $0x2, %rcx /* is it an indirection page? */
94 andq $0xfffffffffffff000, %rbx
97 testq $0x4, %rcx /* is it the done indicator? */
101 testq $0x8, %rcx /* is it the source indicator? */
102 jz 0b /* Ignore it otherwise */
103 movq %rcx, %rsi /* For ever source page do a copy */
104 andq $0xfffffffffffff000, %rsi
111 /* To be certain of avoiding problems with self-modifying code
112 * I need to execute a serializing instruction here.
113 * So I flush the TLB by reloading %cr3 here, it's handy,
114 * and not processor dependent.
119 /* set all of the registers to known values */
120 /* leave %rsp alone */
139 relocate_new_kernel_end:
141 .globl relocate_new_kernel_size
142 relocate_new_kernel_size:
143 .quad relocate_new_kernel_end - relocate_new_kernel