Rev 458 | Rev 501 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 458 | Rev 472 | ||
---|---|---|---|
1 | # |
1 | # |
2 | # Copyright (C) 2001-2004 Jakub Jermar |
2 | # Copyright (C) 2001-2004 Jakub Jermar |
3 | # All rights reserved. |
3 | # All rights reserved. |
4 | # |
4 | # |
5 | # Redistribution and use in source and binary forms, with or without |
5 | # Redistribution and use in source and binary forms, with or without |
6 | # modification, are permitted provided that the following conditions |
6 | # modification, are permitted provided that the following conditions |
7 | # are met: |
7 | # are met: |
8 | # |
8 | # |
9 | # - Redistributions of source code must retain the above copyright |
9 | # - Redistributions of source code must retain the above copyright |
10 | # notice, this list of conditions and the following disclaimer. |
10 | # notice, this list of conditions and the following disclaimer. |
11 | # - Redistributions in binary form must reproduce the above copyright |
11 | # - Redistributions in binary form must reproduce the above copyright |
12 | # notice, this list of conditions and the following disclaimer in the |
12 | # notice, this list of conditions and the following disclaimer in the |
13 | # documentation and/or other materials provided with the distribution. |
13 | # documentation and/or other materials provided with the distribution. |
14 | # - The name of the author may not be used to endorse or promote products |
14 | # - The name of the author may not be used to endorse or promote products |
15 | # derived from this software without specific prior written permission. |
15 | # derived from this software without specific prior written permission. |
16 | # |
16 | # |
17 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | # |
27 | # |
28 | 28 | ||
29 | # |
29 | # |
30 | # Init code for application processors. |
30 | # Init code for application processors. |
31 | # |
31 | # |
32 | 32 | ||
33 | #define __ASM__ |
- | |
34 | #include <arch/boot/boot.h> |
33 | #include <arch/boot/boot.h> |
35 | #include <arch/pm.h> |
34 | #include <arch/pm.h> |
36 | #include <arch/cpu.h> |
35 | #include <arch/cpu.h> |
37 | #include <arch/cpuid.h> |
36 | #include <arch/cpuid.h> |
38 | #include <arch/mm/page.h> |
37 | #include <arch/mm/page.h> |
39 | 38 | ||
40 | .section K_TEXT_START_2, "ax" |
39 | .section K_TEXT_START_2, "ax" |
41 | 40 | ||
42 | #ifdef CONFIG_SMP |
41 | #ifdef CONFIG_SMP |
43 | 42 | ||
44 | .global ap_boot |
43 | .global ap_boot |
45 | 44 | ||
46 | # This piece of code is real-mode and is meant to be alligned at 4K boundary. |
45 | # This piece of code is real-mode and is meant to be alligned at 4K boundary. |
47 | # The requirement for such an alignment comes from MP Specification's STARTUP IPI |
46 | # The requirement for such an alignment comes from MP Specification's STARTUP IPI |
48 | # requirements. |
47 | # requirements. |
49 | 48 | ||
50 | .align 4096 |
49 | .align 4096 |
51 | ap_boot: |
50 | ap_boot: |
52 | .code16 |
51 | .code16 |
53 | cli |
52 | cli |
54 | xorw %ax, %ax |
53 | xorw %ax, %ax |
55 | movw %ax, %ds |
54 | movw %ax, %ds |
56 | 55 | ||
57 | lgdt real_bootstrap_gdtr_boot # initialize Global Descriptor Table register |
56 | lgdt real_bootstrap_gdtr_boot # initialize Global Descriptor Table register |
58 | 57 | ||
59 | movl %cr0, %eax |
58 | movl %cr0, %eax |
60 | orl $1, %eax |
59 | orl $1, %eax |
61 | movl %eax, %cr0 # switch to protected mode |
60 | movl %eax, %cr0 # switch to protected mode |
62 | 61 | ||
63 | jmpl $gdtselector(KTEXT32_DES), $now_in_prot |
62 | jmpl $gdtselector(KTEXT32_DES), $now_in_prot |
64 | 63 | ||
65 | .code32 |
64 | .code32 |
66 | now_in_prot: |
65 | now_in_prot: |
67 | movw $gdtselector(KDATA_DES), %ax |
66 | movw $gdtselector(KDATA_DES), %ax |
68 | movw %ax, %ds |
67 | movw %ax, %ds |
69 | movw %ax, %ss |
68 | movw %ax, %ss |
70 | 69 | ||
71 | 70 | ||
72 | # Enable 64-bit page transaltion entries - CR4.PAE = 1. |
71 | # Enable 64-bit page transaltion entries - CR4.PAE = 1. |
73 | # Paging is not enabled until after long mode is enabled |
72 | # Paging is not enabled until after long mode is enabled |
74 | movl %cr4, %eax |
73 | movl %cr4, %eax |
75 | btsl $5, %eax |
74 | btsl $5, %eax |
76 | movl %eax, %cr4 |
75 | movl %eax, %cr4 |
77 | 76 | ||
78 | # Set up NEW paging tables, that are |
77 | # Set up NEW paging tables, that are |
79 | # already moved BOOT_OFFSET up |
78 | # already moved BOOT_OFFSET up |
80 | leal ptl_0+BOOT_OFFSET, %eax |
79 | leal ptl_0+BOOT_OFFSET, %eax |
81 | movl %eax, %cr3 |
80 | movl %eax, %cr3 |
82 | 81 | ||
83 | # Enable long mode |
82 | # Enable long mode |
84 | movl $EFER_MSR_NUM, %ecx # EFER MSR number |
83 | movl $EFER_MSR_NUM, %ecx # EFER MSR number |
85 | rdmsr # Read EFER |
84 | rdmsr # Read EFER |
86 | btsl $AMD_LME_FLAG, %eax # Set LME=1 |
85 | btsl $AMD_LME_FLAG, %eax # Set LME=1 |
87 | wrmsr # Write EFER |
86 | wrmsr # Write EFER |
88 | 87 | ||
89 | # Enable paging to activate long mode (set CR0.PG=1) |
88 | # Enable paging to activate long mode (set CR0.PG=1) |
90 | movl %cr0, %eax |
89 | movl %cr0, %eax |
91 | btsl $31, %eax |
90 | btsl $31, %eax |
92 | movl %eax, %cr0 |
91 | movl %eax, %cr0 |
93 | 92 | ||
94 | # At this point we are in compatibility mode |
93 | # At this point we are in compatibility mode |
95 | jmpl $gdtselector(KTEXT_DES), $start64 |
94 | jmpl $gdtselector(KTEXT_DES), $start64 |
96 | 95 | ||
97 | .code64 |
96 | .code64 |
98 | start64: |
97 | start64: |
99 | movq (ctx), %rsp |
98 | movq (ctx), %rsp |
100 | call main_ap # never returns |
99 | call main_ap # never returns |
101 | 100 | ||
102 | 101 | ||
103 | #endif /* CONFIG_SMP */ |
102 | #endif /* CONFIG_SMP */ |
104 | 103 |