Rev 534 | Rev 809 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 534 | Rev 696 | ||
|---|---|---|---|
| Line 1... | Line 1... | ||
| 1 | # |
1 | # |
| 2 | # Copyright (C) 2001-2004 Jakub Jermar |
2 | # Copyright (C) 2001-2004 Jakub Jermar |
| - | 3 | # Copyright (C) 2005-2006 Martin Decky |
|
| 3 | # All rights reserved. |
4 | # All rights reserved. |
| 4 | # |
5 | # |
| 5 | # Redistribution and use in source and binary forms, with or without |
6 | # Redistribution and use in source and binary forms, with or without |
| 6 | # modification, are permitted provided that the following conditions |
7 | # modification, are permitted provided that the following conditions |
| 7 | # are met: |
8 | # are met: |
| Line 29... | Line 30... | ||
| 29 | # |
30 | # |
| 30 | # Init code for application processors. |
31 | # Init code for application processors. |
| 31 | # |
32 | # |
| 32 | 33 | ||
| 33 | #include <arch/boot/boot.h> |
34 | #include <arch/boot/boot.h> |
| - | 35 | #include <arch/boot/memmap.h> |
|
| - | 36 | #include <arch/mm/page.h> |
|
| 34 | #include <arch/pm.h> |
37 | #include <arch/pm.h> |
| 35 | #include <arch/cpu.h> |
38 | #include <arch/cpu.h> |
| 36 | #include <arch/cpuid.h> |
39 | #include <arch/cpuid.h> |
| 37 | #include <arch/mm/page.h> |
- | |
| 38 | 40 | ||
| 39 | .section K_TEXT_START_2, "ax" |
41 | .section K_TEXT_START, "ax" |
| 40 | 42 | ||
| 41 | #ifdef CONFIG_SMP |
43 | #ifdef CONFIG_SMP |
| 42 | 44 | ||
| 43 | .global ap_boot |
45 | .global unmapped_ap_boot |
| 44 | 46 | ||
| 45 | # This piece of code is real-mode and is meant to be alligned at 4K boundary. |
47 | # This piece of code is real-mode and is meant to be alligned at 4K boundary. |
| 46 | # The requirement for such an alignment comes from MP Specification's STARTUP IPI |
48 | # The requirement for such an alignment comes from MP Specification's STARTUP IPI |
| 47 | # requirements. |
49 | # requirements. |
| 48 | 50 | ||
| 49 | .align 4096 |
51 | .align 4096 |
| 50 | ap_boot: |
52 | unmapped_ap_boot: |
| 51 | .code16 |
53 | .code16 |
| 52 | cli |
54 | cli |
| 53 | xorw %ax, %ax |
55 | xorw %ax, %ax |
| 54 | movw %ax, %ds |
56 | movw %ax, %ds |
| 55 | 57 | ||
| 56 | lgdt real_bootstrap_gdtr_boot # initialize Global Descriptor Table register |
58 | lgdt ap_gdtr # initialize Global Descriptor Table register |
| 57 | 59 | ||
| 58 | movl %cr0, %eax |
60 | movl %cr0, %eax |
| 59 | orl $1, %eax |
61 | orl $1, %eax |
| 60 | movl %eax, %cr0 # switch to protected mode |
62 | movl %eax, %cr0 # switch to protected mode |
| - | 63 | jmpl $gdtselector(KTEXT32_DES), $jump_to_kernel - BOOT_OFFSET + AP_BOOT_OFFSET |
|
| 61 | 64 | ||
| 62 | jmpl $gdtselector(KTEXT32_DES), $now_in_prot |
65 | jump_to_kernel: |
| 63 | - | ||
| 64 | .code32 |
66 | .code32 |
| 65 | now_in_prot: |
- | |
| 66 | movw $gdtselector(KDATA_DES), %ax |
67 | movw $gdtselector(KDATA_DES), %ax |
| 67 | movw %ax, %ds |
68 | movw %ax, %ds |
| - | 69 | movw %ax, %es |
|
| 68 | movw %ax, %ss |
70 | movw %ax, %ss |
| 69 | 71 | ||
| 70 | - | ||
| 71 | # Enable 64-bit page transaltion entries - CR4.PAE = 1. |
72 | # Enable 64-bit page transaltion entries - CR4.PAE = 1. |
| 72 | # Paging is not enabled until after long mode is enabled |
73 | # Paging is not enabled until after long mode is enabled |
| - | 74 | ||
| 73 | movl %cr4, %eax |
75 | movl %cr4, %eax |
| 74 | btsl $5, %eax |
76 | btsl $5, %eax |
| 75 | movl %eax, %cr4 |
77 | movl %eax, %cr4 |
| 76 | 78 | ||
| 77 | # Set up NEW paging tables, that are |
- | |
| 78 | # already moved BOOT_OFFSET up |
- | |
| 79 | leal ptl_0+BOOT_OFFSET, %eax |
79 | leal ptl_0, %eax |
| 80 | movl %eax, %cr3 |
80 | movl %eax, %cr3 |
| 81 | 81 | ||
| 82 | # Enable long mode |
82 | # Enable long mode |
| 83 | movl $EFER_MSR_NUM, %ecx # EFER MSR number |
83 | movl $EFER_MSR_NUM, %ecx # EFER MSR number |
| 84 | rdmsr # Read EFER |
84 | rdmsr # Read EFER |
| Line 89... | Line 89... | ||
| 89 | movl %cr0, %eax |
89 | movl %cr0, %eax |
| 90 | btsl $31, %eax |
90 | btsl $31, %eax |
| 91 | movl %eax, %cr0 |
91 | movl %eax, %cr0 |
| 92 | 92 | ||
| 93 | # At this point we are in compatibility mode |
93 | # At this point we are in compatibility mode |
| 94 | jmpl $gdtselector(KTEXT_DES), $start64 |
94 | jmpl $gdtselector(KTEXT_DES), $start64 - BOOT_OFFSET + AP_BOOT_OFFSET |
| 95 | 95 | ||
| 96 | .code64 |
96 | .code64 |
| 97 | start64: |
97 | start64: |
| 98 | movq (ctx), %rsp |
98 | movq (ctx), %rsp |
| 99 | call main_ap # never returns |
99 | call main_ap - AP_BOOT_OFFSET + BOOT_OFFSET # never returns |
| 100 | 100 | ||
| - | 101 | #endif /* CONFIG_SMP */ |
|
| - | 102 | ||
| - | 103 | .section K_DATA_START, "ax" |
|
| - | 104 | ||
| - | 105 | #ifdef CONFIG_SMP |
|
| - | 106 | ||
| - | 107 | .global unmapped_ap_gdtr |
|
| - | 108 | ||
| - | 109 | unmapped_ap_gdtr: |
|
| - | 110 | .word 0 |
|
| - | 111 | .long 0 |
|
| 101 | 112 | ||
| 102 | #endif /* CONFIG_SMP */ |
113 | #endif /* CONFIG_SMP */ |