Subversion Repositories HelenOS

Rev

Rev 3431 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 jermar 1
/*
2071 jermar 2
 * Copyright (c) 2001-2004 Jakub Jermar
4377 svoboda 3
 * Copyright (c) 2009 Jiri Svoboda
4
 * Copyright (c) 2009 Martin Decky
1 jermar 5
 * All rights reserved.
6
 *
7
 * Redistribution and use in source and binary forms, with or without
8
 * modification, are permitted provided that the following conditions
9
 * are met:
10
 *
11
 * - Redistributions of source code must retain the above copyright
12
 *   notice, this list of conditions and the following disclaimer.
13
 * - Redistributions in binary form must reproduce the above copyright
14
 *   notice, this list of conditions and the following disclaimer in the
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
17
 *   derived from this software without specific prior written permission.
18
 *
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
21
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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
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
28
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
 */
30
 
1888 jermar 31
/** @addtogroup ia32
1702 cejka 32
 * @{
33
 */
34
/** @file
35
 */
36
 
1 jermar 37
#include <arch.h>
38
 
39
#include <arch/types.h>
40
 
41
#include <arch/pm.h>
42
 
4377 svoboda 43
#include <genarch/multiboot/multiboot.h>
44
#include <genarch/drivers/legacy/ia32/io.h>
45
#include <genarch/drivers/ega/ega.h>
1477 decky 46
#include <arch/drivers/vesa.h>
4377 svoboda 47
#include <genarch/drivers/i8042/i8042.h>
48
#include <genarch/kbrd/kbrd.h>
1477 decky 49
#include <arch/drivers/i8254.h>
50
#include <arch/drivers/i8259.h>
1 jermar 51
 
52
#include <arch/context.h>
53
 
54
#include <config.h>
55
 
56
#include <arch/interrupt.h>
28 jermar 57
#include <arch/asm.h>
452 decky 58
#include <genarch/acpi/acpi.h>
195 vana 59
 
60
#include <arch/bios/bios.h>
61
 
576 palkovsky 62
#include <interrupt.h>
1956 decky 63
#include <ddi/irq.h>
1074 palkovsky 64
#include <arch/debugger.h>
2918 svoboda 65
#include <arch/breakpoint.h>
1112 palkovsky 66
#include <proc/thread.h>
67
#include <syscall/syscall.h>
1474 palkovsky 68
#include <console/console.h>
4377 svoboda 69
#include <sysinfo/sysinfo.h>
70
#include <arch/boot/boot.h>
1 jermar 71
 
1901 jermar 72
#ifdef CONFIG_SMP
73
#include <arch/smp/apic.h>
74
#endif
75
 
4377 svoboda 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
 
26 jermar 93
void arch_pre_mm_init(void)
1 jermar 94
{
95
    pm_init();
96
 
97
    if (config.cpu_active == 1) {
1956 decky 98
        interrupt_init();
30 jermar 99
        bios_init();
235 decky 100
 
1956 decky 101
        /* PIC */
102
        i8259_init();
1 jermar 103
    }
104
}
105
 
72 decky 106
void arch_post_mm_init(void)
23 jermar 107
{
24 jermar 108
    if (config.cpu_active == 1) {
1956 decky 109
        /* Initialize IRQ routing */
110
        irq_init(IRQ_COUNT, IRQ_COUNT);
111
 
112
        /* hard clock */
113
        i8254_init();
4377 svoboda 114
 
1287 vana 115
#ifdef CONFIG_FB
4377 svoboda 116
        if (vesa_present())
1303 palkovsky 117
            vesa_init();
1287 vana 118
        else
119
#endif
4377 svoboda 120
#ifdef CONFIG_EGA
121
            ega_init(EGA_BASE, EGA_VIDEORAM);  /* video */
122
#else
123
            {}
124
#endif
1287 vana 125
 
1074 palkovsky 126
        /* Enable debugger */
127
        debugger_init();
3431 svoboda 128
 
129
#ifdef CONFIG_UDEBUG
2918 svoboda 130
        /* Enable INT3 breakpoint handler */
131
        breakpoint_init();
3431 svoboda 132
#endif
1303 palkovsky 133
        /* Merge all memory zones to 1 big zone */
134
        zone_merge_all();
32 jermar 135
    }
136
}
137
 
1901 jermar 138
void arch_post_cpu_init()
139
{
140
#ifdef CONFIG_SMP
141
        if (config.cpu_active > 1) {
142
        l_apic_init();
143
        l_apic_debug();
144
    }
145
#endif
146
}
147
 
503 jermar 148
void arch_pre_smp_init(void)
32 jermar 149
{
150
    if (config.cpu_active == 1) {
2107 jermar 151
#ifdef CONFIG_SMP
29 jermar 152
        acpi_init();
2107 jermar 153
#endif /* CONFIG_SMP */
24 jermar 154
    }
23 jermar 155
}
156
 
503 jermar 157
void arch_post_smp_init(void)
158
{
4377 svoboda 159
#ifdef CONFIG_PC_KBD
160
    /*
161
     * Initialize the i8042 controller. Then initialize the keyboard
162
     * module and connect it to i8042. Enable keyboard interrupts.
163
     */
164
    i8042_instance_t *i8042_instance = i8042_init((i8042_t *) I8042_BASE, IRQ_KBD);
165
    if (i8042_instance) {
166
        kbrd_instance_t *kbrd_instance = kbrd_init();
167
        if (kbrd_instance) {
168
            indev_t *sink = stdin_wire();
169
            indev_t *kbrd = kbrd_wire(kbrd_instance, sink);
170
            i8042_wire(i8042_instance, kbrd);
171
            trap_virtual_enable_irqs(1 << IRQ_KBD);
172
        }
173
    }
174
 
175
    /*
176
     * This is the necessary evil until the userspace driver is entirely
177
     * self-sufficient.
178
     */
179
    sysinfo_set_item_val("kbd", NULL, true);
180
    sysinfo_set_item_val("kbd.inr", NULL, IRQ_KBD);
181
    sysinfo_set_item_val("kbd.address.physical", NULL,
182
        (uintptr_t) I8042_BASE);
183
    sysinfo_set_item_val("kbd.address.kernel", NULL,
184
        (uintptr_t) I8042_BASE);
185
#endif
503 jermar 186
}
187
 
1 jermar 188
void calibrate_delay_loop(void)
189
{
190
    i8254_calibrate_delay_loop();
514 jermar 191
    if (config.cpu_active == 1) {
192
        /*
193
         * This has to be done only on UP.
194
         * On SMP, i8254 is not used for time keeping and its interrupt pin remains masked.
195
         */
196
        i8254_normal_operation();
197
    }
1 jermar 198
}
1112 palkovsky 199
 
1121 jermar 200
/** Set thread-local-storage pointer
1112 palkovsky 201
 *
1119 palkovsky 202
 * TLS pointer is set in GS register. That means, the GS contains
203
 * selector, and the descriptor->base is the correct address.
1112 palkovsky 204
 */
1780 jermar 205
unative_t sys_tls_set(unative_t addr)
1112 palkovsky 206
{
1184 jermar 207
    THREAD->arch.tls = addr;
1112 palkovsky 208
    set_tls_desc(addr);
209
 
210
    return 0;
211
}
1474 palkovsky 212
 
213
/** Acquire console back for kernel
214
 *
215
 */
216
void arch_grab_console(void)
217
{
4377 svoboda 218
#ifdef CONFIG_FB
219
    if (vesa_present())
220
        vesa_redraw();
221
    else
222
#endif
223
#ifdef CONFIG_EGA
224
        ega_redraw();
225
#else
226
        {}
227
#endif
1474 palkovsky 228
}
4377 svoboda 229
 
1474 palkovsky 230
/** Return console to userspace
231
 *
232
 */
233
void arch_release_console(void)
234
{
235
}
1702 cejka 236
 
4377 svoboda 237
/** Construct function pointer
238
 *
239
 * @param fptr   function pointer structure
240
 * @param addr   function address
241
 * @param caller calling function address
242
 *
243
 * @return address of the function pointer
244
 *
245
 */
246
void *arch_construct_function(fncptr_t *fptr, void *addr, void *caller)
247
{
248
    return addr;
249
}
250
 
251
void arch_reboot(void)
252
{
253
#ifdef CONFIG_PC_KBD
254
    i8042_cpu_reset((i8042_t *) I8042_BASE);
255
#endif
256
}
257
 
1888 jermar 258
/** @}
1702 cejka 259
 */