Rev 1959 | Rev 2071 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1810 | decky | 1 | /* |
1840 | decky | 2 | * Copyright (C) 2006 Martin Decky |
1810 | decky | 3 | * All rights reserved. |
4 | * |
||
5 | * Redistribution and use in source and binary forms, with or without |
||
6 | * modification, are permitted provided that the following conditions |
||
7 | * are met: |
||
8 | * |
||
9 | * - Redistributions of source code must retain the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer. |
||
11 | * - Redistributions in binary form must reproduce the above copyright |
||
12 | * notice, this list of conditions and the following disclaimer in the |
||
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 |
||
15 | * derived from this software without specific prior written permission. |
||
16 | * |
||
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 |
||
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
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 |
||
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 |
||
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
27 | */ |
||
28 | |||
1952 | jermar | 29 | /** @addtogroup ia32xen |
1810 | decky | 30 | * @{ |
31 | */ |
||
32 | /** @file |
||
33 | */ |
||
34 | |||
35 | #include <arch.h> |
||
1833 | decky | 36 | #include <main/main.h> |
1810 | decky | 37 | |
38 | #include <arch/types.h> |
||
39 | #include <typedefs.h> |
||
1824 | decky | 40 | #include <align.h> |
1810 | decky | 41 | |
42 | #include <arch/pm.h> |
||
43 | |||
1816 | decky | 44 | #include <arch/drivers/xconsole.h> |
1824 | decky | 45 | #include <arch/mm/page.h> |
1810 | decky | 46 | |
47 | #include <arch/context.h> |
||
48 | |||
49 | #include <config.h> |
||
50 | |||
51 | #include <arch/interrupt.h> |
||
52 | #include <arch/asm.h> |
||
53 | #include <genarch/acpi/acpi.h> |
||
54 | |||
55 | #include <arch/bios/bios.h> |
||
56 | |||
1813 | decky | 57 | #include <arch/boot/boot.h> |
1810 | decky | 58 | #include <arch/mm/memory_init.h> |
59 | #include <interrupt.h> |
||
60 | #include <arch/debugger.h> |
||
61 | #include <proc/thread.h> |
||
62 | #include <syscall/syscall.h> |
||
63 | #include <console/console.h> |
||
1959 | decky | 64 | #include <ddi/irq.h> |
1810 | decky | 65 | |
1813 | decky | 66 | start_info_t start_info; |
1824 | decky | 67 | memzone_t meminfo; |
1813 | decky | 68 | |
1829 | decky | 69 | extern void xen_callback(void); |
70 | extern void xen_failsafe_callback(void); |
||
71 | |||
1824 | decky | 72 | void arch_pre_main(void) |
73 | { |
||
74 | pte_t pte; |
||
75 | memsetb((uintptr_t) &pte, sizeof(pte), 0); |
||
76 | |||
77 | pte.present = 1; |
||
78 | pte.writeable = 1; |
||
79 | pte.frame_address = ADDR2PFN((uintptr_t) start_info.shared_info); |
||
2017 | decky | 80 | ASSERT(xen_update_va_mapping(&shared_info, pte, UVMF_INVLPG) == 0); |
1824 | decky | 81 | |
2017 | decky | 82 | if (!(start_info.flags & SIF_INITDOMAIN)) { |
83 | /* Map console frame */ |
||
84 | pte.present = 1; |
||
85 | pte.writeable = 1; |
||
86 | pte.frame_address = start_info.console.domU.mfn; |
||
87 | ASSERT(xen_update_va_mapping(&console_page, pte, UVMF_INVLPG) == 0); |
||
88 | } else |
||
89 | start_info.console.domU.evtchn = 0; |
||
1832 | decky | 90 | |
2017 | decky | 91 | ASSERT(xen_set_callbacks(XEN_CS, xen_callback, XEN_CS, xen_failsafe_callback) == 0); |
1829 | decky | 92 | |
1824 | decky | 93 | /* Create identity mapping */ |
94 | |||
95 | meminfo.start = ADDR2PFN(ALIGN_UP(KA2PA(start_info.ptl0), PAGE_SIZE)) + start_info.pt_frames; |
||
96 | meminfo.size = start_info.frames - meminfo.start; |
||
97 | meminfo.reserved = 0; |
||
2017 | decky | 98 | |
1824 | decky | 99 | uintptr_t pa; |
100 | index_t last_ptl0 = 0; |
||
101 | for (pa = PFN2ADDR(meminfo.start); pa < PFN2ADDR(meminfo.start + meminfo.size); pa += FRAME_SIZE) { |
||
102 | uintptr_t va = PA2KA(pa); |
||
103 | |||
104 | if ((PTL0_INDEX(va) != last_ptl0) && (GET_PTL1_FLAGS(start_info.ptl0, PTL0_INDEX(va)) & PAGE_NOT_PRESENT)) { |
||
105 | /* New page directory entry needed */ |
||
106 | uintptr_t tpa = PFN2ADDR(meminfo.start + meminfo.reserved); |
||
107 | uintptr_t tva = PA2KA(tpa); |
||
108 | |||
109 | memsetb(tva, PAGE_SIZE, 0); |
||
110 | |||
111 | pte_t *tptl3 = (pte_t *) PA2KA(GET_PTL1_ADDRESS(start_info.ptl0, PTL0_INDEX(tva))); |
||
2017 | decky | 112 | SET_FRAME_ADDRESS(tptl3, PTL3_INDEX(tva), 0); |
1824 | decky | 113 | SET_PTL1_ADDRESS(start_info.ptl0, PTL0_INDEX(va), tpa); |
2017 | decky | 114 | SET_FRAME_ADDRESS(tptl3, PTL3_INDEX(tva), tpa); |
1824 | decky | 115 | |
116 | last_ptl0 = PTL0_INDEX(va); |
||
117 | meminfo.reserved++; |
||
118 | } |
||
119 | |||
120 | pte_t *ptl3 = (pte_t *) PA2KA(GET_PTL1_ADDRESS(start_info.ptl0, PTL0_INDEX(va))); |
||
121 | |||
122 | SET_FRAME_ADDRESS(ptl3, PTL3_INDEX(va), pa); |
||
123 | SET_FRAME_FLAGS(ptl3, PTL3_INDEX(va), PAGE_PRESENT | PAGE_WRITE); |
||
124 | } |
||
1834 | decky | 125 | |
126 | /* Put initial stack safely in the mapped area */ |
||
127 | stack_safe = PA2KA(PFN2ADDR(meminfo.start + meminfo.reserved)); |
||
1824 | decky | 128 | } |
129 | |||
1810 | decky | 130 | void arch_pre_mm_init(void) |
131 | { |
||
1816 | decky | 132 | pm_init(); |
1810 | decky | 133 | |
134 | if (config.cpu_active == 1) { |
||
1959 | decky | 135 | interrupt_init(); |
1810 | decky | 136 | // bios_init(); |
137 | |||
138 | } |
||
139 | } |
||
140 | |||
141 | void arch_post_mm_init(void) |
||
142 | { |
||
143 | if (config.cpu_active == 1) { |
||
1959 | decky | 144 | /* Initialize IRQ routing */ |
145 | irq_init(IRQ_COUNT, IRQ_COUNT); |
||
146 | |||
147 | /* Video */ |
||
1816 | decky | 148 | xen_console_init(); |
1959 | decky | 149 | |
1810 | decky | 150 | /* Enable debugger */ |
151 | debugger_init(); |
||
1959 | decky | 152 | |
1810 | decky | 153 | /* Merge all memory zones to 1 big zone */ |
154 | zone_merge_all(); |
||
155 | } |
||
156 | } |
||
157 | |||
1901 | jermar | 158 | void arch_post_cpu_init(void) |
159 | { |
||
160 | } |
||
161 | |||
1810 | decky | 162 | void arch_pre_smp_init(void) |
163 | { |
||
164 | if (config.cpu_active == 1) { |
||
165 | memory_print_map(); |
||
166 | |||
167 | #ifdef CONFIG_SMP |
||
168 | acpi_init(); |
||
169 | #endif /* CONFIG_SMP */ |
||
170 | } |
||
171 | } |
||
172 | |||
173 | void arch_post_smp_init(void) |
||
174 | { |
||
175 | } |
||
176 | |||
177 | void calibrate_delay_loop(void) |
||
178 | { |
||
1816 | decky | 179 | // i8254_calibrate_delay_loop(); |
1810 | decky | 180 | if (config.cpu_active == 1) { |
181 | /* |
||
182 | * This has to be done only on UP. |
||
183 | * On SMP, i8254 is not used for time keeping and its interrupt pin remains masked. |
||
184 | */ |
||
1816 | decky | 185 | // i8254_normal_operation(); |
1810 | decky | 186 | } |
187 | } |
||
188 | |||
189 | /** Set thread-local-storage pointer |
||
190 | * |
||
191 | * TLS pointer is set in GS register. That means, the GS contains |
||
192 | * selector, and the descriptor->base is the correct address. |
||
193 | */ |
||
194 | unative_t sys_tls_set(unative_t addr) |
||
195 | { |
||
196 | THREAD->arch.tls = addr; |
||
197 | set_tls_desc(addr); |
||
198 | |||
199 | return 0; |
||
200 | } |
||
201 | |||
202 | /** Acquire console back for kernel |
||
203 | * |
||
204 | */ |
||
205 | void arch_grab_console(void) |
||
206 | { |
||
207 | } |
||
1816 | decky | 208 | |
1810 | decky | 209 | /** Return console to userspace |
210 | * |
||
211 | */ |
||
212 | void arch_release_console(void) |
||
213 | { |
||
214 | } |
||
215 | |||
216 | /** @} |
||
217 | */ |