Subversion Repositories HelenOS

Rev

Rev 4015 | Rev 4026 | Go to most recent revision | 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
4015 decky 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
 
4022 svoboda 43
#include <genarch/multiboot/multiboot.h>
3932 jermar 44
#include <genarch/drivers/legacy/ia32/io.h>
3779 jermar 45
#include <genarch/drivers/ega/ega.h>
1477 decky 46
#include <arch/drivers/vesa.h>
1842 jermar 47
#include <genarch/kbd/i8042.h>
1477 decky 48
#include <arch/drivers/i8254.h>
49
#include <arch/drivers/i8259.h>
1 jermar 50
 
51
#include <arch/context.h>
52
 
53
#include <config.h>
54
 
55
#include <arch/interrupt.h>
28 jermar 56
#include <arch/asm.h>
452 decky 57
#include <genarch/acpi/acpi.h>
195 vana 58
 
59
#include <arch/bios/bios.h>
60
 
576 palkovsky 61
#include <interrupt.h>
1956 decky 62
#include <ddi/irq.h>
1074 palkovsky 63
#include <arch/debugger.h>
1112 palkovsky 64
#include <proc/thread.h>
65
#include <syscall/syscall.h>
1474 palkovsky 66
#include <console/console.h>
1956 decky 67
#include <ddi/device.h>
3982 jermar 68
#include <sysinfo/sysinfo.h>
4015 decky 69
#include <arch/boot/boot.h>
1 jermar 70
 
1901 jermar 71
#ifdef CONFIG_SMP
72
#include <arch/smp/apic.h>
73
#endif
74
 
4022 svoboda 75
/** Perform ia32-specific initialization before main_bsp() is called.
4015 decky 76
 *
77
 * @param signature Should contain the multiboot signature.
78
 * @param mi        Pointer to the multiboot information structure.
79
 */
4022 svoboda 80
void arch_pre_main(uint32_t signature, const multiboot_info_t *mi)
4015 decky 81
{
4022 svoboda 82
    /* Parse multiboot information obtained from the bootloader. */
83
    multiboot_info_parse(signature, mi);   
4015 decky 84
 
85
#ifdef CONFIG_SMP
86
    /* Copy AP bootstrap routines below 1 MB. */
87
    memcpy((void *) AP_BOOT_OFFSET, (void *) BOOT_OFFSET,
88
        (size_t) &_hardcoded_unmapped_size);
89
#endif
90
}
91
 
26 jermar 92
void arch_pre_mm_init(void)
1 jermar 93
{
94
    pm_init();
95
 
96
    if (config.cpu_active == 1) {
1956 decky 97
        interrupt_init();
30 jermar 98
        bios_init();
235 decky 99
 
1956 decky 100
        /* PIC */
101
        i8259_init();
1 jermar 102
    }
103
}
104
 
72 decky 105
void arch_post_mm_init(void)
23 jermar 106
{
24 jermar 107
    if (config.cpu_active == 1) {
1956 decky 108
        /* Initialize IRQ routing */
109
        irq_init(IRQ_COUNT, IRQ_COUNT);
110
 
111
        /* hard clock */
112
        i8254_init();
1287 vana 113
 
114
#ifdef CONFIG_FB
1303 palkovsky 115
        if (vesa_present())
116
            vesa_init();
1287 vana 117
        else
118
#endif
3779 jermar 119
            ega_init(EGA_BASE, EGA_VIDEORAM);   /* video */
1287 vana 120
 
1074 palkovsky 121
        /* Enable debugger */
122
        debugger_init();
1303 palkovsky 123
        /* Merge all memory zones to 1 big zone */
124
        zone_merge_all();
32 jermar 125
    }
126
}
127
 
1901 jermar 128
void arch_post_cpu_init()
129
{
130
#ifdef CONFIG_SMP
131
        if (config.cpu_active > 1) {
132
        l_apic_init();
133
        l_apic_debug();
134
    }
135
#endif
136
}
137
 
503 jermar 138
void arch_pre_smp_init(void)
32 jermar 139
{
140
    if (config.cpu_active == 1) {
2107 jermar 141
#ifdef CONFIG_SMP
29 jermar 142
        acpi_init();
2107 jermar 143
#endif /* CONFIG_SMP */
24 jermar 144
    }
23 jermar 145
}
146
 
503 jermar 147
void arch_post_smp_init(void)
148
{
3982 jermar 149
    devno_t devno = device_assign_devno();
1956 decky 150
    /* keyboard controller */
3982 jermar 151
    (void) i8042_init((i8042_t *) I8042_BASE, devno, IRQ_KBD);
152
 
153
    /*
154
     * This is the necessary evil until the userspace driver is entirely
155
     * self-sufficient.
156
     */
157
    sysinfo_set_item_val("kbd", NULL, true);
158
    sysinfo_set_item_val("kbd.devno", NULL, devno);
159
    sysinfo_set_item_val("kbd.inr", NULL, IRQ_KBD);
503 jermar 160
}
161
 
1 jermar 162
void calibrate_delay_loop(void)
163
{
164
    i8254_calibrate_delay_loop();
514 jermar 165
    if (config.cpu_active == 1) {
166
        /*
167
         * This has to be done only on UP.
168
         * On SMP, i8254 is not used for time keeping and its interrupt pin remains masked.
169
         */
170
        i8254_normal_operation();
171
    }
1 jermar 172
}
1112 palkovsky 173
 
1121 jermar 174
/** Set thread-local-storage pointer
1112 palkovsky 175
 *
1119 palkovsky 176
 * TLS pointer is set in GS register. That means, the GS contains
177
 * selector, and the descriptor->base is the correct address.
1112 palkovsky 178
 */
1780 jermar 179
unative_t sys_tls_set(unative_t addr)
1112 palkovsky 180
{
1184 jermar 181
    THREAD->arch.tls = addr;
1112 palkovsky 182
    set_tls_desc(addr);
183
 
184
    return 0;
185
}
1474 palkovsky 186
 
187
/** Acquire console back for kernel
188
 *
189
 */
190
void arch_grab_console(void)
191
{
3707 decky 192
#ifdef CONFIG_FB
193
    vesa_redraw();
194
#else
195
    ega_redraw();
196
#endif
1474 palkovsky 197
}
3707 decky 198
 
1474 palkovsky 199
/** Return console to userspace
200
 *
201
 */
202
void arch_release_console(void)
203
{
204
}
1702 cejka 205
 
3880 decky 206
/** Construct function pointer
207
 *
208
 * @param fptr   function pointer structure
209
 * @param addr   function address
210
 * @param caller calling function address
211
 *
212
 * @return address of the function pointer
213
 *
214
 */
215
void *arch_construct_function(fncptr_t *fptr, void *addr, void *caller)
216
{
217
    return addr;
218
}
219
 
1888 jermar 220
/** @}
1702 cejka 221
 */