Subversion Repositories HelenOS

Rev

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

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