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

Last change on this file was ec18e454, checked in by Jiri Svoboda <jiri@…>, 7 years ago

Revert "Deduplicate bootstrap code" - needs more work

This reverts commit 17aa6d19228b3aab97f8e989dd9a36d576f1d896.

  • Property mode set to 100644
File size: 4.9 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 <abi/asmtool.h>
30#include <arch/boot/boot.h>
31#include <arch/pm.h>
32#include <arch/cpuid.h>
33#include <genarch/multiboot/multiboot2.h>
34
35#define START_STACK (BOOT_OFFSET - BOOT_STACK_SIZE)
36
37.section K_TEXT_START, "ax"
38
39.code32
40
41.align 8
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 .align 8
50 tag_info_req_start:
51 .word MULTIBOOT2_TAG_INFO_REQ
52 .word MULTIBOOT2_FLAGS_REQUIRED
53 .long tag_info_req_end - tag_info_req_start
54 .long MULTIBOOT2_TAG_CMDLINE
55 .long MULTIBOOT2_TAG_MODULE
56 .long MULTIBOOT2_TAG_MEMMAP
57#ifdef CONFIG_FB
58 .long MULTIBOOT2_TAG_FBINFO
59#endif
60 tag_info_req_end:
61
62 /* Address tag */
63 .align 8
64 tag_address_start:
65 .word MULTIBOOT2_TAG_ADDRESS
66 .word MULTIBOOT2_FLAGS_REQUIRED
67 .long tag_address_end - tag_address_start
68 .long multiboot2_header_start
69 .long unmapped_start
70 .long 0
71 .long 0
72 tag_address_end:
73
74 /* Entry address tag */
75 .align 8
76 tag_entry_address_start:
77 .word MULTIBOOT2_TAG_ENTRY_ADDRESS
78 .word MULTIBOOT2_FLAGS_REQUIRED
79 .long tag_entry_address_end - tag_entry_address_start
80 .long multiboot2_image_start
81 tag_entry_address_end:
82
83 /* Flags tag */
84 .align 8
85 tag_flags_start:
86 .word MULTIBOOT2_TAG_FLAGS
87 .word MULTIBOOT2_FLAGS_REQUIRED
88 .long tag_flags_end - tag_flags_start
89 .long MULTIBOOT2_FLAGS_CONSOLE
90 tag_flags_end:
91
92#ifdef CONFIG_FB
93 /* Framebuffer tag */
94 .align 8
95 tag_framebuffer_start:
96 .word MULTIBOOT2_TAG_FRAMEBUFFER
97 .word MULTIBOOT2_FLAGS_REQUIRED
98 .long tag_framebuffer_end - tag_framebuffer_start
99 .long CONFIG_BFB_WIDTH
100 .long CONFIG_BFB_HEIGHT
101 .long CONFIG_BFB_BPP
102 tag_framebuffer_end:
103#endif
104
105 /* Module alignment tag */
106 .align 8
107 tag_module_align_start:
108 .word MULTIBOOT2_TAG_MODULE_ALIGN
109 .word MULTIBOOT2_FLAGS_REQUIRED
110 .long tag_module_align_end - tag_module_align_start
111 .long 0
112 tag_module_align_end:
113
114 /* Tag terminator */
115 .align 8
116 tag_terminator_start:
117 .word MULTIBOOT2_TAG_TERMINATOR
118 .word MULTIBOOT2_FLAGS_REQUIRED
119 .long tag_terminator_end - tag_terminator_start
120 tag_terminator_end:
121multiboot2_header_end:
122
123SYMBOL(multiboot2_image_start)
124 cli
125 cld
126
127 /* Initialize stack pointer */
128 movl $START_STACK, %esp
129
130 /*
131 * Initialize Global Descriptor Table and
132 * Interrupt Descriptor Table registers
133 */
134 lgdtl bootstrap_gdtr
135 lidtl bootstrap_idtr
136
137 /* Kernel data + stack */
138 movw $GDT_SELECTOR(KDATA_DES), %cx
139 movw %cx, %es
140 movw %cx, %fs
141 movw %cx, %gs
142 movw %cx, %ds
143 movw %cx, %ss
144
145 jmpl $GDT_SELECTOR(KTEXT_DES), $multiboot2_meeting_point
146 multiboot2_meeting_point:
147
148 /* Save multiboot arguments */
149 movl %eax, multiboot_eax
150 movl %ebx, multiboot_ebx
151
152#ifndef PROCESSOR_i486
153
154 movl $(INTEL_CPUID_LEVEL), %eax
155 cpuid
156 cmp $0x0, %eax /* any function > 0? */
157 jbe pse_unsupported
158
159 movl $(INTEL_CPUID_STANDARD), %eax
160 cpuid
161 bt $(INTEL_PSE), %edx
162 jnc pse_unsupported
163
164 /* Map kernel and turn paging on */
165 call map_kernel_pse
166 jmp stack_init
167
168#endif /* PROCESSOR_i486 */
169
170 pse_unsupported:
171
172 /* Map kernel and turn paging on */
173 call map_kernel_non_pse
174
175 stack_init:
176
177 /* Create the first stack frame */
178 pushl $0
179 movl %esp, %ebp
180
181 /* Call ia32_pre_main(multiboot_eax, multiboot_ebx) */
182 pushl multiboot_ebx
183 pushl multiboot_eax
184 call ia32_pre_main
185
186 /* Call main_bsp() */
187 call main_bsp
188
189 /* Not reached */
190 cli
191 hlt0:
192 hlt
193 jmp hlt0
Note: See TracBrowser for help on using the repository browser.