Rev 4015 | Rev 4193 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 4015 | Rev 4022 | ||
|---|---|---|---|
| Line 1... | Line 1... | ||
| 1 | /* |
1 | /* |
| 2 | * Copyright (c) 2001-2004 Jakub Jermar |
- | |
| 3 | * Copyright (c) 2009 Jiri Svoboda |
2 | * Copyright (c) 2009 Jiri Svoboda |
| 4 | * Copyright (c) 2009 Martin Decky |
- | |
| 5 | * All rights reserved. |
3 | * All rights reserved. |
| 6 | * |
4 | * |
| 7 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
| 9 | * are met: |
7 | * are met: |
| Line 26... | Line 24... | ||
| 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | * (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 |
| 28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
27 | */ |
| 30 | 28 | ||
| 31 | /** @addtogroup ia32 |
29 | /** @addtogroup genarch |
| 32 | * @{ |
30 | * @{ |
| 33 | */ |
31 | */ |
| 34 | /** @file |
32 | /** @file |
| 35 | */ |
33 | */ |
| 36 | 34 | ||
| 37 | #include <arch.h> |
35 | #include <genarch/multiboot/multiboot.h> |
| 38 | - | ||
| 39 | #include <arch/types.h> |
36 | #include <arch/types.h> |
| 40 | - | ||
| 41 | #include <arch/pm.h> |
37 | #include <typedefs.h> |
| 42 | - | ||
| 43 | #include <genarch/drivers/legacy/ia32/io.h> |
- | |
| 44 | #include <genarch/drivers/ega/ega.h> |
- | |
| 45 | #include <arch/drivers/vesa.h> |
- | |
| 46 | #include <genarch/kbd/i8042.h> |
- | |
| 47 | #include <arch/drivers/i8254.h> |
- | |
| 48 | #include <arch/drivers/i8259.h> |
- | |
| 49 | - | ||
| 50 | #include <arch/context.h> |
- | |
| 51 | - | ||
| 52 | #include <config.h> |
38 | #include <config.h> |
| 53 | - | ||
| 54 | #include <arch/interrupt.h> |
- | |
| 55 | #include <arch/asm.h> |
- | |
| 56 | #include <genarch/acpi/acpi.h> |
- | |
| 57 | - | ||
| 58 | #include <arch/bios/bios.h> |
- | |
| 59 | - | ||
| 60 | #include <interrupt.h> |
- | |
| 61 | #include <ddi/irq.h> |
- | |
| 62 | #include <arch/debugger.h> |
- | |
| 63 | #include <proc/thread.h> |
- | |
| 64 | #include <syscall/syscall.h> |
- | |
| 65 | #include <console/console.h> |
- | |
| 66 | #include <ddi/device.h> |
- | |
| 67 | #include <sysinfo/sysinfo.h> |
- | |
| 68 | #include <arch/boot/boot.h> |
- | |
| 69 | #include <string.h> |
39 | #include <string.h> |
| 70 | #include <macros.h> |
40 | #include <macros.h> |
| 71 | 41 | ||
| 72 | #ifdef CONFIG_SMP |
- | |
| 73 | #include <arch/smp/apic.h> |
- | |
| 74 | #endif |
- | |
| 75 | - | ||
| 76 | /** Extract command name from the multiboot module command line. |
42 | /** Extract command name from the multiboot module command line. |
| 77 | * |
43 | * |
| 78 | * @param buf Destination buffer (will always null-terminate). |
44 | * @param buf Destination buffer (will always null-terminate). |
| 79 | * @param n Size of destination buffer. |
45 | * @param n Size of destination buffer. |
| 80 | * @param cmd_line Input string (the command line). |
46 | * @param cmd_line Input string (the command line). |
| Line 108... | Line 74... | ||
| 108 | max_len = min(n - 1, (size_t) (end - start)); |
74 | max_len = min(n - 1, (size_t) (end - start)); |
| 109 | strncpy(buf, start, max_len + 1); |
75 | strncpy(buf, start, max_len + 1); |
| 110 | buf[max_len] = '\0'; |
76 | buf[max_len] = '\0'; |
| 111 | } |
77 | } |
| 112 | 78 | ||
| 113 | /** C part of ia32 boot sequence. |
79 | /** Parse multiboot information structure. |
| - | 80 | * |
|
| - | 81 | * If @a signature does not contain a valid multiboot signature, |
|
| - | 82 | * assumes no multiboot information is available. |
|
| 114 | * |
83 | * |
| 115 | * @param signature Should contain the multiboot signature. |
84 | * @param signature Should contain the multiboot signature. |
| 116 | * @param mi Pointer to the multiboot information structure. |
85 | * @param mi Pointer to the multiboot information structure. |
| 117 | */ |
86 | */ |
| 118 | void arch_pre_main(uint32_t signature, const mb_info_t *mi) |
87 | void multiboot_info_parse(uint32_t signature, const multiboot_info_t *mi) |
| 119 | { |
88 | { |
| 120 | uint32_t flags; |
89 | uint32_t flags; |
| 121 | mb_mod_t *mods; |
90 | multiboot_mod_t *mods; |
| 122 | uint32_t i; |
91 | uint32_t i; |
| 123 | 92 | ||
| 124 | if (signature == MULTIBOOT_LOADER_MAGIC) |
93 | if (signature == MULTIBOOT_LOADER_MAGIC) |
| 125 | flags = mi->flags; |
94 | flags = mi->flags; |
| 126 | else { |
95 | else { |
| Line 130... | Line 99... | ||
| 130 | 99 | ||
| 131 | /* Copy module information. */ |
100 | /* Copy module information. */ |
| 132 | 101 | ||
| 133 | if ((flags & MBINFO_FLAGS_MODS) != 0) { |
102 | if ((flags & MBINFO_FLAGS_MODS) != 0) { |
| 134 | init.cnt = mi->mods_count; |
103 | init.cnt = mi->mods_count; |
| 135 | mods = mi->mods_addr; |
104 | mods = (multiboot_mod_t *) MULTIBOOT_PTR(mi->mods_addr); |
| 136 | 105 | ||
| 137 | for (i = 0; i < init.cnt; i++) { |
106 | for (i = 0; i < init.cnt; i++) { |
| 138 | init.tasks[i].addr = mods[i].start + 0x80000000; |
107 | init.tasks[i].addr = PA2KA(mods[i].start); |
| 139 | init.tasks[i].size = mods[i].end - mods[i].start; |
108 | init.tasks[i].size = mods[i].end - mods[i].start; |
| 140 | 109 | ||
| 141 | /* Copy command line, if available. */ |
110 | /* Copy command line, if available. */ |
| 142 | if (mods[i].string) { |
111 | if (mods[i].string) { |
| 143 | extract_command(init.tasks[i].name, |
112 | extract_command(init.tasks[i].name, |
| 144 | CONFIG_TASK_NAME_BUFLEN, |
113 | CONFIG_TASK_NAME_BUFLEN, |
| 145 | mods[i].string); |
114 | MULTIBOOT_PTR(mods[i].string)); |
| 146 | } else |
115 | } else |
| 147 | init.tasks[i].name[0] = '\0'; |
116 | init.tasks[i].name[0] = '\0'; |
| 148 | } |
117 | } |
| 149 | } else |
118 | } else |
| 150 | init.cnt = 0; |
119 | init.cnt = 0; |
| 151 | 120 | ||
| 152 | /* Copy memory map. */ |
121 | /* Copy memory map. */ |
| 153 | 122 | ||
| 154 | int32_t mmap_length; |
123 | int32_t mmap_length; |
| 155 | mb_mmap_t *mme; |
124 | multiboot_mmap_t *mme; |
| 156 | uint32_t size; |
125 | uint32_t size; |
| 157 | 126 | ||
| 158 | if ((flags & MBINFO_FLAGS_MMAP) != 0) { |
127 | if ((flags & MBINFO_FLAGS_MMAP) != 0) { |
| 159 | mmap_length = mi->mmap_length; |
128 | mmap_length = mi->mmap_length; |
| 160 | mme = mi->mmap_addr; |
129 | mme = MULTIBOOT_PTR(mi->mmap_addr); |
| 161 | e820counter = 0; |
130 | e820counter = 0; |
| 162 | 131 | ||
| 163 | i = 0; |
132 | i = 0; |
| 164 | while (mmap_length > 0) { |
133 | while (mmap_length > 0) { |
| 165 | e820table[i++] = mme->mm_info; |
134 | e820table[i++] = mme->mm_info; |
| Line 171... | Line 140... | ||
| 171 | } |
140 | } |
| 172 | 141 | ||
| 173 | e820counter = i; |
142 | e820counter = i; |
| 174 | } else |
143 | } else |
| 175 | e820counter = 0; |
144 | e820counter = 0; |
| 176 | - | ||
| 177 | #ifdef CONFIG_SMP |
- | |
| 178 | /* Copy AP bootstrap routines below 1 MB. */ |
- | |
| 179 | memcpy((void *) AP_BOOT_OFFSET, (void *) BOOT_OFFSET, |
- | |
| 180 | (size_t) &_hardcoded_unmapped_size); |
- | |
| 181 | #endif |
- | |
| 182 | } |
- | |
| 183 | - | ||
| 184 | void arch_pre_mm_init(void) |
- | |
| 185 | { |
- | |
| 186 | pm_init(); |
- | |
| 187 | - | ||
| 188 | if (config.cpu_active == 1) { |
- | |
| 189 | interrupt_init(); |
- | |
| 190 | bios_init(); |
- | |
| 191 | - | ||
| 192 | /* PIC */ |
- | |
| 193 | i8259_init(); |
- | |
| 194 | } |
- | |
| 195 | } |
- | |
| 196 | - | ||
| 197 | void arch_post_mm_init(void) |
- | |
| 198 | { |
- | |
| 199 | if (config.cpu_active == 1) { |
- | |
| 200 | /* Initialize IRQ routing */ |
- | |
| 201 | irq_init(IRQ_COUNT, IRQ_COUNT); |
- | |
| 202 | - | ||
| 203 | /* hard clock */ |
- | |
| 204 | i8254_init(); |
- | |
| 205 | - | ||
| 206 | #ifdef CONFIG_FB |
- | |
| 207 | if (vesa_present()) |
- | |
| 208 | vesa_init(); |
- | |
| 209 | else |
- | |
| 210 | #endif |
- | |
| 211 | ega_init(EGA_BASE, EGA_VIDEORAM); /* video */ |
- | |
| 212 | - | ||
| 213 | /* Enable debugger */ |
- | |
| 214 | debugger_init(); |
- | |
| 215 | /* Merge all memory zones to 1 big zone */ |
- | |
| 216 | zone_merge_all(); |
- | |
| 217 | } |
- | |
| 218 | } |
- | |
| 219 | - | ||
| 220 | void arch_post_cpu_init() |
- | |
| 221 | { |
- | |
| 222 | #ifdef CONFIG_SMP |
- | |
| 223 | if (config.cpu_active > 1) { |
- | |
| 224 | l_apic_init(); |
- | |
| 225 | l_apic_debug(); |
- | |
| 226 | } |
- | |
| 227 | #endif |
- | |
| 228 | } |
- | |
| 229 | - | ||
| 230 | void arch_pre_smp_init(void) |
- | |
| 231 | { |
- | |
| 232 | if (config.cpu_active == 1) { |
- | |
| 233 | #ifdef CONFIG_SMP |
- | |
| 234 | acpi_init(); |
- | |
| 235 | #endif /* CONFIG_SMP */ |
- | |
| 236 | } |
- | |
| 237 | } |
- | |
| 238 | - | ||
| 239 | void arch_post_smp_init(void) |
- | |
| 240 | { |
- | |
| 241 | devno_t devno = device_assign_devno(); |
- | |
| 242 | /* keyboard controller */ |
- | |
| 243 | (void) i8042_init((i8042_t *) I8042_BASE, devno, IRQ_KBD); |
- | |
| 244 | - | ||
| 245 | /* |
- | |
| 246 | * This is the necessary evil until the userspace driver is entirely |
- | |
| 247 | * self-sufficient. |
- | |
| 248 | */ |
- | |
| 249 | sysinfo_set_item_val("kbd", NULL, true); |
- | |
| 250 | sysinfo_set_item_val("kbd.devno", NULL, devno); |
- | |
| 251 | sysinfo_set_item_val("kbd.inr", NULL, IRQ_KBD); |
- | |
| 252 | } |
- | |
| 253 | - | ||
| 254 | void calibrate_delay_loop(void) |
- | |
| 255 | { |
- | |
| 256 | i8254_calibrate_delay_loop(); |
- | |
| 257 | if (config.cpu_active == 1) { |
- | |
| 258 | /* |
- | |
| 259 | * This has to be done only on UP. |
- | |
| 260 | * On SMP, i8254 is not used for time keeping and its interrupt pin remains masked. |
- | |
| 261 | */ |
- | |
| 262 | i8254_normal_operation(); |
- | |
| 263 | } |
- | |
| 264 | } |
- | |
| 265 | - | ||
| 266 | /** Set thread-local-storage pointer |
- | |
| 267 | * |
- | |
| 268 | * TLS pointer is set in GS register. That means, the GS contains |
- | |
| 269 | * selector, and the descriptor->base is the correct address. |
- | |
| 270 | */ |
- | |
| 271 | unative_t sys_tls_set(unative_t addr) |
- | |
| 272 | { |
- | |
| 273 | THREAD->arch.tls = addr; |
- | |
| 274 | set_tls_desc(addr); |
- | |
| 275 | - | ||
| 276 | return 0; |
- | |
| 277 | } |
- | |
| 278 | - | ||
| 279 | /** Acquire console back for kernel |
- | |
| 280 | * |
- | |
| 281 | */ |
- | |
| 282 | void arch_grab_console(void) |
- | |
| 283 | { |
- | |
| 284 | #ifdef CONFIG_FB |
- | |
| 285 | vesa_redraw(); |
- | |
| 286 | #else |
- | |
| 287 | ega_redraw(); |
- | |
| 288 | #endif |
- | |
| 289 | } |
- | |
| 290 | - | ||
| 291 | /** Return console to userspace |
- | |
| 292 | * |
- | |
| 293 | */ |
- | |
| 294 | void arch_release_console(void) |
- | |
| 295 | { |
- | |
| 296 | } |
- | |
| 297 | - | ||
| 298 | /** Construct function pointer |
- | |
| 299 | * |
- | |
| 300 | * @param fptr function pointer structure |
- | |
| 301 | * @param addr function address |
- | |
| 302 | * @param caller calling function address |
- | |
| 303 | * |
- | |
| 304 | * @return address of the function pointer |
- | |
| 305 | * |
- | |
| 306 | */ |
- | |
| 307 | void *arch_construct_function(fncptr_t *fptr, void *addr, void *caller) |
- | |
| 308 | { |
- | |
| 309 | return addr; |
- | |
| 310 | } |
145 | } |
| 311 | 146 | ||
| 312 | /** @} |
147 | /** @} |
| 313 | */ |
148 | */ |