Subversion Repositories HelenOS

Rev

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

Rev 3022 Rev 4055
1
/*
1
/*
2
 * Copyright (c) 2001-2004 Jakub Jermar
2
 * Copyright (c) 2001-2004 Jakub Jermar
-
 
3
 * Copyright (c) 2009 Jiri Svoboda
-
 
4
 * Copyright (c) 2009 Martin Decky
3
 * All rights reserved.
5
 * All rights reserved.
4
 *
6
 *
5
 * Redistribution and use in source and binary forms, with or without
7
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
8
 * modification, are permitted provided that the following conditions
7
 * are met:
9
 * are met:
8
 *
10
 *
9
 * - Redistributions of source code must retain the above copyright
11
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
12
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
13
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
14
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
15
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
16
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
17
 *   derived from this software without specific prior written permission.
16
 *
18
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27
 * (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.
28
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
29
 */
28
 
30
 
29
/** @addtogroup ia32
31
/** @addtogroup ia32
30
 * @{
32
 * @{
31
 */
33
 */
32
/** @file
34
/** @file
33
 */
35
 */
34
 
36
 
35
#include <arch.h>
37
#include <arch.h>
36
 
38
 
37
#include <arch/types.h>
39
#include <arch/types.h>
38
 
40
 
39
#include <arch/pm.h>
41
#include <arch/pm.h>
40
 
42
 
-
 
43
#include <genarch/multiboot/multiboot.h>
-
 
44
#include <genarch/drivers/legacy/ia32/io.h>
41
#include <arch/drivers/ega.h>
45
#include <genarch/drivers/ega/ega.h>
42
#include <arch/drivers/vesa.h>
46
#include <arch/drivers/vesa.h>
-
 
47
#include <genarch/drivers/i8042/i8042.h>
43
#include <genarch/kbd/i8042.h>
48
#include <genarch/kbrd/kbrd.h>
44
#include <arch/drivers/i8254.h>
49
#include <arch/drivers/i8254.h>
45
#include <arch/drivers/i8259.h>
50
#include <arch/drivers/i8259.h>
46
 
51
 
47
#include <arch/context.h>
52
#include <arch/context.h>
48
 
53
 
49
#include <config.h>
54
#include <config.h>
50
 
55
 
51
#include <arch/interrupt.h>
56
#include <arch/interrupt.h>
52
#include <arch/asm.h>
57
#include <arch/asm.h>
53
#include <genarch/acpi/acpi.h>
58
#include <genarch/acpi/acpi.h>
54
 
59
 
55
#include <arch/bios/bios.h>
60
#include <arch/bios/bios.h>
56
 
61
 
57
#include <interrupt.h>
62
#include <interrupt.h>
58
#include <ddi/irq.h>
63
#include <ddi/irq.h>
59
#include <arch/debugger.h>
64
#include <arch/debugger.h>
60
#include <proc/thread.h>
65
#include <proc/thread.h>
61
#include <syscall/syscall.h>
66
#include <syscall/syscall.h>
62
#include <console/console.h>
67
#include <console/console.h>
63
#include <ddi/device.h>
68
#include <ddi/device.h>
-
 
69
#include <sysinfo/sysinfo.h>
-
 
70
#include <arch/boot/boot.h>
64
 
71
 
65
#ifdef CONFIG_SMP
72
#ifdef CONFIG_SMP
66
#include <arch/smp/apic.h>
73
#include <arch/smp/apic.h>
67
#endif
74
#endif
68
 
75
 
-
 
76
/** Perform ia32-specific initialization before main_bsp() is called.
-
 
77
 *
-
 
78
 * @param signature Should contain the multiboot signature.
-
 
79
 * @param mi        Pointer to the multiboot information structure.
-
 
80
 */
-
 
81
void arch_pre_main(uint32_t signature, const multiboot_info_t *mi)
-
 
82
{
-
 
83
    /* Parse multiboot information obtained from the bootloader. */
-
 
84
    multiboot_info_parse(signature, mi);   
-
 
85
   
-
 
86
#ifdef CONFIG_SMP
-
 
87
    /* Copy AP bootstrap routines below 1 MB. */
-
 
88
    memcpy((void *) AP_BOOT_OFFSET, (void *) BOOT_OFFSET,
-
 
89
        (size_t) &_hardcoded_unmapped_size);
-
 
90
#endif
-
 
91
}
-
 
92
 
69
void arch_pre_mm_init(void)
93
void arch_pre_mm_init(void)
70
{
94
{
71
    pm_init();
95
    pm_init();
72
 
96
 
73
    if (config.cpu_active == 1) {
97
    if (config.cpu_active == 1) {
74
        interrupt_init();
98
        interrupt_init();
75
        bios_init();
99
        bios_init();
76
       
100
       
77
        /* PIC */
101
        /* PIC */
78
        i8259_init();
102
        i8259_init();
79
    }
103
    }
80
}
104
}
81
 
105
 
82
void arch_post_mm_init(void)
106
void arch_post_mm_init(void)
83
{
107
{
84
    if (config.cpu_active == 1) {
108
    if (config.cpu_active == 1) {
85
        /* Initialize IRQ routing */
109
        /* Initialize IRQ routing */
86
        irq_init(IRQ_COUNT, IRQ_COUNT);
110
        irq_init(IRQ_COUNT, IRQ_COUNT);
87
       
111
       
88
        /* hard clock */
112
        /* hard clock */
89
        i8254_init();
113
        i8254_init();
90
 
114
 
91
#ifdef CONFIG_FB
115
#ifdef CONFIG_FB
92
        if (vesa_present())
116
        if (vesa_present())
93
            vesa_init();
117
            vesa_init();
94
        else
118
        else
95
#endif
119
#endif
96
            ega_init(); /* video */
120
            ega_init(EGA_BASE, EGA_VIDEORAM);   /* video */
97
       
121
       
98
        /* Enable debugger */
122
        /* Enable debugger */
99
        debugger_init();
123
        debugger_init();
100
        /* Merge all memory zones to 1 big zone */
124
        /* Merge all memory zones to 1 big zone */
101
        zone_merge_all();
125
        zone_merge_all();
102
    }
126
    }
103
}
127
}
104
 
128
 
105
void arch_post_cpu_init()
129
void arch_post_cpu_init()
106
{
130
{
107
#ifdef CONFIG_SMP
131
#ifdef CONFIG_SMP
108
        if (config.cpu_active > 1) {
132
        if (config.cpu_active > 1) {
109
        l_apic_init();
133
        l_apic_init();
110
        l_apic_debug();
134
        l_apic_debug();
111
    }
135
    }
112
#endif
136
#endif
113
}
137
}
114
 
138
 
115
void arch_pre_smp_init(void)
139
void arch_pre_smp_init(void)
116
{
140
{
117
    if (config.cpu_active == 1) {
141
    if (config.cpu_active == 1) {
118
#ifdef CONFIG_SMP
142
#ifdef CONFIG_SMP
119
        acpi_init();
143
        acpi_init();
120
#endif /* CONFIG_SMP */
144
#endif /* CONFIG_SMP */
121
    }
145
    }
122
}
146
}
123
 
147
 
124
void arch_post_smp_init(void)
148
void arch_post_smp_init(void)
125
{
149
{
126
    devno_t kbd = device_assign_devno();
150
    devno_t devno = device_assign_devno();
-
 
151
 
-
 
152
    /*
127
    devno_t mouse = device_assign_devno();
153
     * Initialize the keyboard module and conect it to stdin. Then
-
 
154
     * initialize the i8042 controller and connect it to kbrdin. Enable
128
    /* keyboard controller */
155
     * keyboard interrupts.
-
 
156
     */
-
 
157
    kbrd_init(stdin);
129
    i8042_init(kbd, IRQ_KBD, mouse, IRQ_MOUSE);
158
    (void) i8042_init((i8042_t *) I8042_BASE, devno, IRQ_KBD, &kbrdin);
-
 
159
    trap_virtual_enable_irqs(1 << IRQ_KBD);
-
 
160
 
-
 
161
    /*
-
 
162
     * This is the necessary evil until the userspace driver is entirely
-
 
163
     * self-sufficient.
-
 
164
     */
-
 
165
    sysinfo_set_item_val("kbd", NULL, true);
-
 
166
    sysinfo_set_item_val("kbd.devno", NULL, devno);
-
 
167
    sysinfo_set_item_val("kbd.inr", NULL, IRQ_KBD);
-
 
168
    sysinfo_set_item_val("kbd.address.physical", NULL,
-
 
169
        (uintptr_t) I8042_BASE);
-
 
170
    sysinfo_set_item_val("kbd.address.kernel", NULL,
-
 
171
        (uintptr_t) I8042_BASE);
130
}
172
}
131
 
173
 
132
void calibrate_delay_loop(void)
174
void calibrate_delay_loop(void)
133
{
175
{
134
    i8254_calibrate_delay_loop();
176
    i8254_calibrate_delay_loop();
135
    if (config.cpu_active == 1) {
177
    if (config.cpu_active == 1) {
136
        /*
178
        /*
137
         * This has to be done only on UP.
179
         * This has to be done only on UP.
138
         * On SMP, i8254 is not used for time keeping and its interrupt pin remains masked.
180
         * On SMP, i8254 is not used for time keeping and its interrupt pin remains masked.
139
         */
181
         */
140
        i8254_normal_operation();
182
        i8254_normal_operation();
141
    }
183
    }
142
}
184
}
143
 
185
 
144
/** Set thread-local-storage pointer
186
/** Set thread-local-storage pointer
145
 *
187
 *
146
 * TLS pointer is set in GS register. That means, the GS contains
188
 * TLS pointer is set in GS register. That means, the GS contains
147
 * selector, and the descriptor->base is the correct address.
189
 * selector, and the descriptor->base is the correct address.
148
 */
190
 */
149
unative_t sys_tls_set(unative_t addr)
191
unative_t sys_tls_set(unative_t addr)
150
{
192
{
151
    THREAD->arch.tls = addr;
193
    THREAD->arch.tls = addr;
152
    set_tls_desc(addr);
194
    set_tls_desc(addr);
153
 
195
 
154
    return 0;
196
    return 0;
155
}
197
}
156
 
198
 
157
/** Acquire console back for kernel
199
/** Acquire console back for kernel
158
 *
200
 *
159
 */
201
 */
160
void arch_grab_console(void)
202
void arch_grab_console(void)
161
{
203
{
-
 
204
#ifdef CONFIG_FB
-
 
205
    vesa_redraw();
-
 
206
#else
162
    i8042_grab();
207
    ega_redraw();
-
 
208
#endif
163
}
209
}
-
 
210
 
164
/** Return console to userspace
211
/** Return console to userspace
165
 *
212
 *
166
 */
213
 */
167
void arch_release_console(void)
214
void arch_release_console(void)
168
{
215
{
-
 
216
}
-
 
217
 
-
 
218
/** Construct function pointer
-
 
219
 *
-
 
220
 * @param fptr   function pointer structure
-
 
221
 * @param addr   function address
-
 
222
 * @param caller calling function address
-
 
223
 *
-
 
224
 * @return address of the function pointer
-
 
225
 *
-
 
226
 */
-
 
227
void *arch_construct_function(fncptr_t *fptr, void *addr, void *caller)
-
 
228
{
169
    i8042_release();
229
    return addr;
170
}
230
}
171
 
231
 
172
/** @}
232
/** @}
173
 */
233
 */
174
 
234