remove all trailing whitespace
[grub2/phcoder/solaris.git] / loader / i386 / linux_trampoline.S
blob4acea7b1161a2cd415e976760f6815ef307f249a
1 /*
2  *  GRUB  --  GRand Unified Bootloader
3  *  Copyright (C) 2009  Free Software Foundation, Inc.
4  *
5  *  GRUB is free software: you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation, either version 3 of the License, or
8  *  (at your option) any later version.
9  *
10  *  GRUB 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 GRUB.  If not, see <http://www.gnu.org/licenses/>.
17  */
19 #include <grub/symbol.h>
22         .p2align        4       /* force 16-byte alignment */
23 VARIABLE(grub_linux_trampoline_start)
24         cli
25         /* %rdi contains protected memory start and %rsi
26         contains real memory start. */
28         mov %rsi, %rbx
30         call base
31 base:
32         pop %rsi
34 #ifdef APPLE_CC
35         lea (cont1 - base) (%esi, 1), %rax
36         mov %eax, (jump_vector - base) (%esi, 1)
38         lea (gdt - base) (%esi, 1), %rax
39         mov %rax, (gdtaddr - base) (%esi, 1)
41         /* Switch to compatibility mode. */
43         lidt (idtdesc - base) (%esi, 1)
44         lgdt (gdtdesc - base) (%esi, 1)
46         /* Update %cs. Thanks to David Miller for pointing this mistake out. */
47         ljmp *(jump_vector - base) (%esi, 1)
48 #else
49         lea (cont1 - base) (%rsi, 1), %rax
50         mov %eax, (jump_vector - base) (%rsi, 1)
52         lea (gdt - base) (%rsi, 1), %rax
53         mov %rax, (gdtaddr - base) (%rsi, 1)
55         /* Switch to compatibility mode. */
57         lidt (idtdesc - base) (%rsi, 1)
58         lgdt (gdtdesc - base) (%rsi, 1)
60         /* Update %cs. Thanks to David Miller for pointing this mistake out. */
61         ljmp *(jump_vector - base) (%rsi, 1)
62 #endif
64 cont1:
65         .code32
67         /* Update other registers. */
68         mov $0x18, %eax
69         mov %eax, %ds
70         mov %eax, %es
71         mov %eax, %fs
72         mov %eax, %gs
73         mov %eax, %ss
75         /* Disable paging. */
76         mov %cr0, %eax
77         and $0x7fffffff, %eax
78         mov %eax, %cr0
80         /* Disable amd64. */
81         mov $0xc0000080, %ecx
82         rdmsr
83         and $0xfffffeff, %eax
84         wrmsr
86         /* Turn off PAE. */
87         movl %cr4, %eax
88         and $0xffffffcf, %eax
89         mov %eax, %cr4
91         jmp cont2
92 cont2:
93         .code32
95         mov %ebx, %esi
97         jmp *%edi
99         /* GDT. */
100         .p2align 4
101 gdt:
102         /* NULL.  */
103         .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
105         /* Reserved.  */
106         .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
108         /* Code segment.  */
109         .byte 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x9A, 0xCF, 0x00
111         /* Data segment.  */
112         .byte 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x92, 0xCF, 0x00
114 gdtdesc:
115         .word 31
116 gdtaddr:
117         .quad gdt
119 idtdesc:
120         .word 0
121 idtaddr:
122         .quad 0
124         .p2align 4
125 jump_vector:
126         /* Jump location. Is filled by the code */
127         .long 0
128         .long 0x10
129 VARIABLE(grub_linux_trampoline_end)