Rev 1816 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1816 | Rev 1824 | ||
---|---|---|---|
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 | /** @addtogroup xen32 |
29 | /** @addtogroup xen32 |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | /** @file |
32 | /** @file |
33 | */ |
33 | */ |
34 | 34 | ||
35 | #include <arch.h> |
35 | #include <arch.h> |
36 | 36 | ||
37 | #include <arch/types.h> |
37 | #include <arch/types.h> |
38 | #include <typedefs.h> |
38 | #include <typedefs.h> |
- | 39 | #include <align.h> |
|
39 | 40 | ||
40 | #include <arch/pm.h> |
41 | #include <arch/pm.h> |
41 | 42 | ||
42 | #include <arch/drivers/xconsole.h> |
43 | #include <arch/drivers/xconsole.h> |
- | 44 | #include <arch/mm/page.h> |
|
43 | 45 | ||
44 | #include <arch/context.h> |
46 | #include <arch/context.h> |
45 | 47 | ||
46 | #include <config.h> |
48 | #include <config.h> |
47 | 49 | ||
48 | #include <arch/interrupt.h> |
50 | #include <arch/interrupt.h> |
49 | #include <arch/asm.h> |
51 | #include <arch/asm.h> |
50 | #include <genarch/acpi/acpi.h> |
52 | #include <genarch/acpi/acpi.h> |
51 | 53 | ||
52 | #include <arch/bios/bios.h> |
54 | #include <arch/bios/bios.h> |
53 | 55 | ||
54 | #include <arch/boot/boot.h> |
56 | #include <arch/boot/boot.h> |
55 | #include <arch/mm/memory_init.h> |
57 | #include <arch/mm/memory_init.h> |
56 | #include <interrupt.h> |
58 | #include <interrupt.h> |
57 | #include <arch/debugger.h> |
59 | #include <arch/debugger.h> |
58 | #include <proc/thread.h> |
60 | #include <proc/thread.h> |
59 | #include <syscall/syscall.h> |
61 | #include <syscall/syscall.h> |
60 | #include <console/console.h> |
62 | #include <console/console.h> |
61 | 63 | ||
62 | start_info_t start_info; |
64 | start_info_t start_info; |
- | 65 | memzone_t meminfo; |
|
- | 66 | ||
- | 67 | void arch_pre_main(void) |
|
- | 68 | { |
|
- | 69 | xen_vm_assist(VMASST_CMD_ENABLE, VMASST_TYPE_WRITABLE_PAGETABLES); |
|
- | 70 | ||
- | 71 | pte_t pte; |
|
- | 72 | memsetb((uintptr_t) &pte, sizeof(pte), 0); |
|
- | 73 | ||
- | 74 | pte.present = 1; |
|
- | 75 | pte.writeable = 1; |
|
- | 76 | pte.frame_address = ADDR2PFN((uintptr_t) start_info.shared_info); |
|
- | 77 | xen_update_va_mapping(&shared_info, pte, UVMF_INVLPG); |
|
- | 78 | ||
- | 79 | /* Create identity mapping */ |
|
- | 80 | ||
- | 81 | meminfo.start = ADDR2PFN(ALIGN_UP(KA2PA(start_info.ptl0), PAGE_SIZE)) + start_info.pt_frames; |
|
- | 82 | meminfo.size = start_info.frames - meminfo.start; |
|
- | 83 | meminfo.reserved = 0; |
|
- | 84 | ||
- | 85 | uintptr_t pa; |
|
- | 86 | index_t last_ptl0 = 0; |
|
- | 87 | for (pa = PFN2ADDR(meminfo.start); pa < PFN2ADDR(meminfo.start + meminfo.size); pa += FRAME_SIZE) { |
|
- | 88 | uintptr_t va = PA2KA(pa); |
|
- | 89 | ||
- | 90 | if ((PTL0_INDEX(va) != last_ptl0) && (GET_PTL1_FLAGS(start_info.ptl0, PTL0_INDEX(va)) & PAGE_NOT_PRESENT)) { |
|
- | 91 | /* New page directory entry needed */ |
|
- | 92 | uintptr_t tpa = PFN2ADDR(meminfo.start + meminfo.reserved); |
|
- | 93 | uintptr_t tva = PA2KA(tpa); |
|
- | 94 | ||
- | 95 | memsetb(tva, PAGE_SIZE, 0); |
|
- | 96 | ||
- | 97 | pte_t *tptl3 = (pte_t *) PA2KA(GET_PTL1_ADDRESS(start_info.ptl0, PTL0_INDEX(tva))); |
|
- | 98 | SET_FRAME_FLAGS(tptl3, PTL3_INDEX(tva), PAGE_PRESENT); |
|
- | 99 | SET_PTL1_ADDRESS(start_info.ptl0, PTL0_INDEX(va), tpa); |
|
- | 100 | ||
- | 101 | last_ptl0 = PTL0_INDEX(va); |
|
- | 102 | meminfo.reserved++; |
|
- | 103 | } |
|
- | 104 | ||
- | 105 | pte_t *ptl3 = (pte_t *) PA2KA(GET_PTL1_ADDRESS(start_info.ptl0, PTL0_INDEX(va))); |
|
- | 106 | ||
- | 107 | SET_FRAME_ADDRESS(ptl3, PTL3_INDEX(va), pa); |
|
- | 108 | SET_FRAME_FLAGS(ptl3, PTL3_INDEX(va), PAGE_PRESENT | PAGE_WRITE); |
|
- | 109 | } |
|
- | 110 | } |
|
63 | 111 | ||
64 | void arch_pre_mm_init(void) |
112 | void arch_pre_mm_init(void) |
65 | { |
113 | { |
66 | pm_init(); |
114 | pm_init(); |
67 | 115 | ||
68 | if (config.cpu_active == 1) { |
116 | if (config.cpu_active == 1) { |
69 | // bios_init(); |
117 | // bios_init(); |
70 | 118 | ||
71 | // exc_register(VECTOR_SYSCALL, "syscall", (iroutine) syscall); |
119 | // exc_register(VECTOR_SYSCALL, "syscall", (iroutine) syscall); |
72 | 120 | ||
73 | #ifdef CONFIG_SMP |
121 | #ifdef CONFIG_SMP |
74 | // exc_register(VECTOR_TLB_SHOOTDOWN_IPI, "tlb_shootdown", |
122 | // exc_register(VECTOR_TLB_SHOOTDOWN_IPI, "tlb_shootdown", |
75 | // (iroutine) tlb_shootdown_ipi); |
123 | // (iroutine) tlb_shootdown_ipi); |
76 | #endif /* CONFIG_SMP */ |
124 | #endif /* CONFIG_SMP */ |
77 | } |
125 | } |
78 | } |
126 | } |
79 | 127 | ||
80 | void arch_post_mm_init(void) |
128 | void arch_post_mm_init(void) |
81 | { |
129 | { |
82 | if (config.cpu_active == 1) { |
130 | if (config.cpu_active == 1) { |
83 | /* video */ |
131 | /* video */ |
84 | xen_console_init(); |
132 | xen_console_init(); |
85 | /* Enable debugger */ |
133 | /* Enable debugger */ |
86 | debugger_init(); |
134 | debugger_init(); |
87 | /* Merge all memory zones to 1 big zone */ |
135 | /* Merge all memory zones to 1 big zone */ |
88 | zone_merge_all(); |
136 | zone_merge_all(); |
89 | } |
137 | } |
90 | } |
138 | } |
91 | 139 | ||
92 | void arch_pre_smp_init(void) |
140 | void arch_pre_smp_init(void) |
93 | { |
141 | { |
94 | if (config.cpu_active == 1) { |
142 | if (config.cpu_active == 1) { |
95 | memory_print_map(); |
143 | memory_print_map(); |
96 | 144 | ||
97 | #ifdef CONFIG_SMP |
145 | #ifdef CONFIG_SMP |
98 | acpi_init(); |
146 | acpi_init(); |
99 | #endif /* CONFIG_SMP */ |
147 | #endif /* CONFIG_SMP */ |
100 | } |
148 | } |
101 | } |
149 | } |
102 | 150 | ||
103 | void arch_post_smp_init(void) |
151 | void arch_post_smp_init(void) |
104 | { |
152 | { |
105 | } |
153 | } |
106 | 154 | ||
107 | void calibrate_delay_loop(void) |
155 | void calibrate_delay_loop(void) |
108 | { |
156 | { |
109 | // i8254_calibrate_delay_loop(); |
157 | // i8254_calibrate_delay_loop(); |
110 | if (config.cpu_active == 1) { |
158 | if (config.cpu_active == 1) { |
111 | /* |
159 | /* |
112 | * This has to be done only on UP. |
160 | * This has to be done only on UP. |
113 | * On SMP, i8254 is not used for time keeping and its interrupt pin remains masked. |
161 | * On SMP, i8254 is not used for time keeping and its interrupt pin remains masked. |
114 | */ |
162 | */ |
115 | // i8254_normal_operation(); |
163 | // i8254_normal_operation(); |
116 | } |
164 | } |
117 | } |
165 | } |
118 | 166 | ||
119 | /** Set thread-local-storage pointer |
167 | /** Set thread-local-storage pointer |
120 | * |
168 | * |
121 | * TLS pointer is set in GS register. That means, the GS contains |
169 | * TLS pointer is set in GS register. That means, the GS contains |
122 | * selector, and the descriptor->base is the correct address. |
170 | * selector, and the descriptor->base is the correct address. |
123 | */ |
171 | */ |
124 | unative_t sys_tls_set(unative_t addr) |
172 | unative_t sys_tls_set(unative_t addr) |
125 | { |
173 | { |
126 | THREAD->arch.tls = addr; |
174 | THREAD->arch.tls = addr; |
127 | set_tls_desc(addr); |
175 | set_tls_desc(addr); |
128 | 176 | ||
129 | return 0; |
177 | return 0; |
130 | } |
178 | } |
131 | 179 | ||
132 | /** Acquire console back for kernel |
180 | /** Acquire console back for kernel |
133 | * |
181 | * |
134 | */ |
182 | */ |
135 | void arch_grab_console(void) |
183 | void arch_grab_console(void) |
136 | { |
184 | { |
137 | } |
185 | } |
138 | 186 | ||
139 | /** Return console to userspace |
187 | /** Return console to userspace |
140 | * |
188 | * |
141 | */ |
189 | */ |
142 | void arch_release_console(void) |
190 | void arch_release_console(void) |
143 | { |
191 | { |
144 | } |
192 | } |
145 | 193 | ||
146 | /** @} |
194 | /** @} |
147 | */ |
195 | */ |
148 | 196 |