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