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