Subversion Repositories HelenOS

Rev

Rev 1824 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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