Rev 273 | Rev 277 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 273 | Rev 275 | ||
---|---|---|---|
Line 30... | Line 30... | ||
30 | 30 | ||
31 | #include <arch/mm/page.h> |
31 | #include <arch/mm/page.h> |
32 | #include <arch/mm/ptl.h> |
32 | #include <arch/mm/ptl.h> |
33 | #include <arch/pm.h> |
33 | #include <arch/pm.h> |
34 | #include <arch/cpu.h> |
34 | #include <arch/cpu.h> |
- | 35 | #include <arch/cpuid.h> |
|
- | 36 | #include <arch/boot/boot.h> |
|
35 | 37 | ||
36 | #define START_STACK 0x7c00 |
- | |
37 | #define START_STACK_64 0xffffffff80007c00 |
38 | #define START_STACK_64 0xffffffff80007c00 |
38 | 39 | ||
39 | # |
40 | # |
40 | # This is where we require any SPARTAN-kernel-compatible boot loader |
41 | # This is where we require any SPARTAN-kernel-compatible boot loader |
41 | # to pass control in real mode. |
42 | # to pass control in real mode. |
42 | # |
43 | # |
43 | # Protected mode tables are statically initialised during compile |
44 | # Protected mode tables are statically initialised during compile |
44 | # time. So we can just load the respective table registers and |
45 | # time. So we can just load the respective table registers and |
45 | # switch to protected mode. |
46 | # switch to protected mode. |
46 | # |
47 | # |
- | 48 | ||
- | 49 | #define START_STACK (BOOTSTRAP_OFFSET-0x400) |
|
- | 50 | ||
47 | .section K_TEXT_START |
51 | .section K_TEXT_START |
48 | .code16 |
52 | .code16 |
49 | .global kernel_image_start |
53 | .global kernel_image_start |
50 | kernel_image_start: |
54 | kernel_image_start: |
51 | cli |
55 | cli |
52 | xorw %ax,%ax |
56 | xorw %ax,%ax |
53 | movw %ax,%ds |
57 | movw %ax,%ds |
54 | movw %ax,%ss # initialize stack segment register |
58 | movw %ax,%ss # initialize stack segment register |
55 | movl $(START_STACK),%esp # initialize stack pointer |
59 | movl $(START_STACK), %esp # initialize stack pointer |
56 | 60 | ||
57 | call memmap_arch_init |
61 | call memmap_arch_init |
58 | 62 | ||
59 | movl $0x80000000, %eax |
63 | movl $0x80000000, %eax |
60 | cpuid |
64 | cpuid |
61 | cmp $0x80000000, %eax # any function > 80000000h? |
65 | cmp $0x80000000, %eax # any function > 80000000h? |
62 | jbe no_long_mode |
66 | jbe no_long_mode |
63 | movl $0x80000001, %eax # Extended function code 80000001 |
67 | movl $(AMD_CPUID_EXTENDED), %eax # Extended function code 80000001 |
64 | cpuid |
68 | cpuid |
65 | bt $29, %edx # Test if long mode is supported. |
69 | bt $29, %edx # Test if long mode is supported. |
66 | jnc no_long_mode |
70 | jnc no_long_mode |
67 | 71 | ||
68 | # Load gdtr, idtr |
72 | # Load gdtr, idtr |
Line 86... | Line 90... | ||
86 | movw %ax, %ds |
90 | movw %ax, %ds |
87 | movw %ax, %fs |
91 | movw %ax, %fs |
88 | movw %ax, %gs |
92 | movw %ax, %gs |
89 | movw %ax, %ss |
93 | movw %ax, %ss |
90 | 94 | ||
- | 95 | movb $0xd1, %al # enable A20 using the keyboard controller |
|
- | 96 | outb %al, $0x64 |
|
- | 97 | movb $0xdf, %al |
|
- | 98 | outb %al, $0x60 |
|
- | 99 | ||
- | 100 | ||
91 | # Enable 64-bit page transaltion entries - CR4.PAE = 1. |
101 | # Enable 64-bit page transaltion entries - CR4.PAE = 1. |
92 | # Paging is not enabled until after long mode is enabled |
102 | # Paging is not enabled until after long mode is enabled |
93 | movl %cr4, %eax |
103 | movl %cr4, %eax |
94 | btsl $5, %eax |
104 | btsl $5, %eax |
95 | movl %eax, %cr4 |
105 | movl %eax, %cr4 |
96 | 106 | ||
97 | # Set up paging tables |
107 | # Set up paging tables |
98 | leal ptl_0, %eax |
108 | leal ptl_0, %eax |
99 | movl %eax, %cr3 |
109 | movl %eax, %cr3 |
100 | 110 | ||
101 | # Enable long mode |
111 | # Enable long mode |
102 | movl $EFER_MSR_NUM, %ecx # EFER MSR number |
112 | movl $EFER_MSR_NUM, %ecx # EFER MSR number |
103 | rdmsr # Read EFER |
113 | rdmsr # Read EFER |
104 | btsl $AMD_LME_FLAG, %eax # Set LME=1 |
114 | btsl $AMD_LME_FLAG, %eax # Set LME=1 |
105 | wrmsr # Write EFER |
115 | wrmsr # Write EFER |
Line 112... | Line 122... | ||
112 | # At this point we are in compatibility mode |
122 | # At this point we are in compatibility mode |
113 | jmpl $gdtselector(KTEXT_DES), $start64 |
123 | jmpl $gdtselector(KTEXT_DES), $start64 |
114 | 124 | ||
115 | .code64 |
125 | .code64 |
116 | start64: |
126 | start64: |
117 | movq $(START_STACK_64), %rsp |
127 | movq $(PA2KA(START_STACK)), %rsp |
- | 128 | ||
- | 129 | # Copy kernel to higher physical memory |
|
- | 130 | movq $BOOTSTRAP_OFFSET, %rsi |
|
- | 131 | movq $BOOTSTRAP_OFFSET + BOOT_OFFSET, %rdi |
|
- | 132 | movq $_hardcoded_kernel_size, %rcx |
|
- | 133 | cld |
|
- | 134 | rep movsb |
|
118 | 135 | ||
119 | call main_bsp # never returns |
136 | call main_bsp # never returns |
120 | 1: |
137 | 1: |
121 | jmp 1b |
138 | jmp 1b |
122 | 139 | ||
Line 151... | Line 168... | ||
151 | .quad ptl_1 + (PTL_WRITABLE | PTL_PRESENT) |
168 | .quad ptl_1 + (PTL_WRITABLE | PTL_PRESENT) |
152 | 169 | ||
153 | .global gdtr_inst |
170 | .global gdtr_inst |
154 | bsp_bootstrap_gdtr: |
171 | bsp_bootstrap_gdtr: |
155 | .word gdtselector(GDT_ITEMS) |
172 | .word gdtselector(GDT_ITEMS) |
156 | .long KA2PA(gdt) |
173 | .long KA2PA(gdt)-BOOT_OFFSET |
157 | 174 | ||
158 | .global ap_bootstrap_gdtr |
175 | .global ap_bootstrap_gdtr |
159 | ap_bootstrap_gdtr: |
176 | ap_bootstrap_gdtr: |
160 | .word gdtselector(GDT_ITEMS) |
177 | .word gdtselector(GDT_ITEMS) |
161 | .long KA2PA(gdt) |
- | |
162 | 178 | .long KA2PA(gdt)-BOOT_OFFSET |
|
- | 179 |