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