Subversion Repositories HelenOS

Rev

Rev 1832 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1810 decky 1
/*
2
 * Copyright (C) 2001-2004 Jakub Jermar
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
 
29
/** @addtogroup xen32
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>
64
 
1813 decky 65
start_info_t start_info;
1824 decky 66
memzone_t meminfo;
1813 decky 67
 
1829 decky 68
extern void xen_callback(void);
69
extern void xen_failsafe_callback(void);
70
 
1824 decky 71
void arch_pre_main(void)
72
{
73
    xen_vm_assist(VMASST_CMD_ENABLE, VMASST_TYPE_WRITABLE_PAGETABLES);
74
 
75
    pte_t pte;
76
    memsetb((uintptr_t) &pte, sizeof(pte), 0);
77
 
78
    pte.present = 1;
79
    pte.writeable = 1;
80
    pte.frame_address = ADDR2PFN((uintptr_t) start_info.shared_info);
81
    xen_update_va_mapping(&shared_info, pte, UVMF_INVLPG);
82
 
1832 decky 83
    pte.present = 1;
84
    pte.writeable = 1;
85
    pte.frame_address = start_info.console_mfn;
86
    xen_update_va_mapping(&console_page, pte, UVMF_INVLPG);
87
 
1829 decky 88
    xen_set_callbacks(XEN_CS, xen_callback, XEN_CS, xen_failsafe_callback);
89
 
1824 decky 90
    /* Create identity mapping */
91
 
92
    meminfo.start = ADDR2PFN(ALIGN_UP(KA2PA(start_info.ptl0), PAGE_SIZE)) + start_info.pt_frames;
93
    meminfo.size = start_info.frames - meminfo.start;
94
    meminfo.reserved = 0;
95
 
96
    uintptr_t pa;
97
    index_t last_ptl0 = 0;
98
    for (pa = PFN2ADDR(meminfo.start); pa < PFN2ADDR(meminfo.start + meminfo.size); pa += FRAME_SIZE) {
99
        uintptr_t va = PA2KA(pa);
100
 
101
        if ((PTL0_INDEX(va) != last_ptl0) && (GET_PTL1_FLAGS(start_info.ptl0, PTL0_INDEX(va)) & PAGE_NOT_PRESENT)) {
102
            /* New page directory entry needed */
103
            uintptr_t tpa = PFN2ADDR(meminfo.start + meminfo.reserved);
104
            uintptr_t tva = PA2KA(tpa);
105
 
106
            memsetb(tva, PAGE_SIZE, 0);
107
 
108
            pte_t *tptl3 = (pte_t *) PA2KA(GET_PTL1_ADDRESS(start_info.ptl0, PTL0_INDEX(tva)));
109
            SET_FRAME_FLAGS(tptl3, PTL3_INDEX(tva), PAGE_PRESENT);
110
            SET_PTL1_ADDRESS(start_info.ptl0, PTL0_INDEX(va), tpa);
111
 
112
            last_ptl0 = PTL0_INDEX(va);
113
            meminfo.reserved++;
114
        }
115
 
116
        pte_t *ptl3 = (pte_t *) PA2KA(GET_PTL1_ADDRESS(start_info.ptl0, PTL0_INDEX(va)));
117
 
118
        SET_FRAME_ADDRESS(ptl3, PTL3_INDEX(va), pa);
119
        SET_FRAME_FLAGS(ptl3, PTL3_INDEX(va), PAGE_PRESENT | PAGE_WRITE);
120
    }
121
}
122
 
1810 decky 123
void arch_pre_mm_init(void)
124
{
1816 decky 125
    pm_init();
1810 decky 126
 
127
    if (config.cpu_active == 1) {
128
//      bios_init();
129
 
1829 decky 130
        exc_register(VECTOR_SYSCALL, "syscall", (iroutine) syscall);
1810 decky 131
 
132
        #ifdef CONFIG_SMP
1829 decky 133
        exc_register(VECTOR_TLB_SHOOTDOWN_IPI, "tlb_shootdown",
134
                 (iroutine) tlb_shootdown_ipi);
1810 decky 135
        #endif /* CONFIG_SMP */
136
    }
137
}
138
 
139
void arch_post_mm_init(void)
140
{
141
    if (config.cpu_active == 1) {
1816 decky 142
        /* video */
143
        xen_console_init();
1810 decky 144
        /* Enable debugger */
145
        debugger_init();
146
        /* Merge all memory zones to 1 big zone */
147
        zone_merge_all();
148
    }
149
}
150
 
151
void arch_pre_smp_init(void)
152
{
153
    if (config.cpu_active == 1) {
154
        memory_print_map();
155
 
156
        #ifdef CONFIG_SMP
157
        acpi_init();
158
        #endif /* CONFIG_SMP */
159
    }
160
}
161
 
162
void arch_post_smp_init(void)
163
{
164
}
165
 
166
void calibrate_delay_loop(void)
167
{
1816 decky 168
//  i8254_calibrate_delay_loop();
1810 decky 169
    if (config.cpu_active == 1) {
170
        /*
171
         * This has to be done only on UP.
172
         * On SMP, i8254 is not used for time keeping and its interrupt pin remains masked.
173
         */
1816 decky 174
//      i8254_normal_operation();
1810 decky 175
    }
176
}
177
 
178
/** Set thread-local-storage pointer
179
 *
180
 * TLS pointer is set in GS register. That means, the GS contains
181
 * selector, and the descriptor->base is the correct address.
182
 */
183
unative_t sys_tls_set(unative_t addr)
184
{
185
    THREAD->arch.tls = addr;
186
    set_tls_desc(addr);
187
 
188
    return 0;
189
}
190
 
191
/** Acquire console back for kernel
192
 *
193
 */
194
void arch_grab_console(void)
195
{
196
}
1816 decky 197
 
1810 decky 198
/** Return console to userspace
199
 *
200
 */
201
void arch_release_console(void)
202
{
203
}
204
 
205
/** @}
206
 */