source: mainline/kernel/arch/ia32/src/boot/multiboot2.S@ 8f4f444

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 8f4f444 was f66c203d, checked in by Martin Decky <martin@…>, 13 years ago

explicitly load default BIOS IDT for real-mode VESA BIOS access (GRUB 2.00 setups an empty IDT for bootstrap)
always use an empty IDT during bootstrap (for consistency)
make sure the interrupts are disabled during bootstrap
make sure correct GDT is set after returning from VESA BIOS

  • Property mode set to 100644
File size: 4.8 KB
Line 
1/*
2 * Copyright (c) 2011 Martin Decky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (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.
27 */
28
29#include <arch/boot/boot.h>
30#include <arch/pm.h>
31#include <arch/cpuid.h>
32#include <genarch/multiboot/multiboot2.h>
33
34#define START_STACK (BOOT_OFFSET - BOOT_STACK_SIZE)
35
36.section K_TEXT_START, "ax"
37
38.code32
39
40.align 8
41.global multiboot2_image_start
42multiboot2_header_start:
43 .long MULTIBOOT2_HEADER_MAGIC
44 .long MULTIBOOT2_HEADER_ARCH_I386
45 .long multiboot2_header_end - multiboot2_header_start
46 .long -(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT2_HEADER_ARCH_I386 + (multiboot2_header_end - multiboot2_header_start))
47
48 /* Information request tag */
49 tag_info_req_start:
50 .word MULTIBOOT2_TAG_INFO_REQ
51 .word MULTIBOOT2_FLAGS_REQUIRED
52 .long tag_info_req_end - tag_info_req_start
53 .long MULTIBOOT2_TAG_MODULE
54 .long MULTIBOOT2_TAG_MEMMAP
55#ifdef CONFIG_FB
56 .long MULTIBOOT2_TAG_FBINFO
57#endif
58 tag_info_req_end:
59
60 /* Address tag */
61 tag_address_start:
62 .word MULTIBOOT2_TAG_ADDRESS
63 .word MULTIBOOT2_FLAGS_REQUIRED
64 .long tag_address_end - tag_address_start
65 .long multiboot2_header_start
66 .long unmapped_ktext_start
67 .long 0
68 .long 0
69 tag_address_end:
70
71 /* Entry address tag */
72 tag_entry_address_start:
73 .word MULTIBOOT2_TAG_ENTRY_ADDRESS
74 .word MULTIBOOT2_FLAGS_REQUIRED
75 .long tag_entry_address_end - tag_entry_address_start
76 .long multiboot2_image_start
77 tag_entry_address_end:
78
79 /* Flags tag */
80 tag_flags_start:
81 .word MULTIBOOT2_TAG_FLAGS
82 .word MULTIBOOT2_FLAGS_REQUIRED
83 .long tag_flags_end - tag_flags_start
84 .long MULTIBOOT2_FLAGS_CONSOLE
85 tag_flags_end:
86
87#ifdef CONFIG_FB
88 /* Framebuffer tag */
89 tag_framebuffer_start:
90 .word MULTIBOOT2_TAG_FRAMEBUFFER
91 .word MULTIBOOT2_FLAGS_REQUIRED
92 .long tag_framebuffer_end - tag_framebuffer_start
93 .long CONFIG_BFB_WIDTH
94 .long CONFIG_BFB_HEIGHT
95 .long CONFIG_BFB_BPP
96 tag_framebuffer_end:
97#endif
98
99 /* Module alignment tag */
100 tag_module_align_start:
101 .word MULTIBOOT2_TAG_MODULE_ALIGN
102 .word MULTIBOOT2_FLAGS_REQUIRED
103 .long tag_module_align_end - tag_module_align_start
104 .long 0
105 tag_module_align_end:
106
107 /* Tag terminator */
108 tag_terminator_start:
109 .word MULTIBOOT2_TAG_TERMINATOR
110 .word MULTIBOOT2_FLAGS_REQUIRED
111 .long tag_terminator_end - tag_terminator_start
112 tag_terminator_end:
113multiboot2_header_end:
114
115multiboot2_image_start:
116 cli
117 cld
118
119 /* Initialize stack pointer */
120 movl $START_STACK, %esp
121
122 /*
123 * Initialize Global Descriptor Table and
124 * Interrupt Descriptor Table registers
125 */
126 lgdtl bootstrap_gdtr
127 lidtl bootstrap_idtr
128
129 /* Kernel data + stack */
130 movw $GDT_SELECTOR(KDATA_DES), %cx
131 movw %cx, %es
132 movw %cx, %fs
133 movw %cx, %gs
134 movw %cx, %ds
135 movw %cx, %ss
136
137 jmpl $GDT_SELECTOR(KTEXT_DES), $multiboot2_meeting_point
138 multiboot2_meeting_point:
139
140 /* Save multiboot arguments */
141 movl %eax, multiboot_eax
142 movl %ebx, multiboot_ebx
143
144#ifndef PROCESSOR_i486
145
146 movl $(INTEL_CPUID_LEVEL), %eax
147 cpuid
148 cmp $0x0, %eax /* any function > 0? */
149 jbe pse_unsupported
150
151 movl $(INTEL_CPUID_STANDARD), %eax
152 cpuid
153 bt $(INTEL_PSE), %edx
154 jnc pse_unsupported
155
156 /* Map kernel and turn paging on */
157 call map_kernel_pse
158 jmp stack_init
159
160#endif /* PROCESSOR_i486 */
161
162 pse_unsupported:
163
164 /* Map kernel and turn paging on */
165 call map_kernel_non_pse
166
167 stack_init:
168
169 /* Create the first stack frame */
170 pushl $0
171 movl %esp, %ebp
172
173 /* Call arch_pre_main(multiboot_eax, multiboot_ebx) */
174 pushl multiboot_ebx
175 pushl multiboot_eax
176 call arch_pre_main
177
178 /* Call main_bsp() */
179 call main_bsp
180
181 /* Not reached */
182 cli
183 hlt0:
184 hlt
185 jmp hlt0
Note: See TracBrowser for help on using the repository browser.