source: mainline/kernel/arch/amd64/src/boot/multiboot2.S@ 76d0981d

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 76d0981d was a35b458, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

  • Property mode set to 100644
File size: 6.3 KB
RevLine 
[1f5c9c96]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
[3b0f1b9a]29#include <abi/asmtool.h>
[1f5c9c96]30#include <arch/boot/boot.h>
31#include <arch/mm/page.h>
32#include <arch/pm.h>
33#include <arch/cpuid.h>
34#include <arch/cpu.h>
35#include <genarch/multiboot/multiboot2.h>
36
37#define START_STACK (BOOT_OFFSET - BOOT_STACK_SIZE)
38
39.section K_TEXT_START, "ax"
40
41.code32
42
43.align 8
44multiboot2_header_start:
45 .long MULTIBOOT2_HEADER_MAGIC
46 .long MULTIBOOT2_HEADER_ARCH_I386
47 .long multiboot2_header_end - multiboot2_header_start
48 .long -(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT2_HEADER_ARCH_I386 + (multiboot2_header_end - multiboot2_header_start))
[a35b458]49
[1f5c9c96]50 /* Information request tag */
[cfb1217]51 .align 8
[1f5c9c96]52 tag_info_req_start:
53 .word MULTIBOOT2_TAG_INFO_REQ
54 .word MULTIBOOT2_FLAGS_REQUIRED
55 .long tag_info_req_end - tag_info_req_start
[9ef1fade]56 .long MULTIBOOT2_TAG_CMDLINE
[1f5c9c96]57 .long MULTIBOOT2_TAG_MODULE
58 .long MULTIBOOT2_TAG_MEMMAP
[40898df]59#ifdef CONFIG_FB
[1f5c9c96]60 .long MULTIBOOT2_TAG_FBINFO
[40898df]61#endif
[1f5c9c96]62 tag_info_req_end:
[a35b458]63
[1f5c9c96]64 /* Address tag */
[cfb1217]65 .align 8
[1f5c9c96]66 tag_address_start:
67 .word MULTIBOOT2_TAG_ADDRESS
68 .word MULTIBOOT2_FLAGS_REQUIRED
69 .long tag_address_end - tag_address_start
70 .long multiboot2_header_start
71 .long unmapped_ktext_start
72 .long 0
73 .long 0
74 tag_address_end:
[a35b458]75
[1f5c9c96]76 /* Entry address tag */
[cfb1217]77 .align 8
[1f5c9c96]78 tag_entry_address_start:
79 .word MULTIBOOT2_TAG_ENTRY_ADDRESS
80 .word MULTIBOOT2_FLAGS_REQUIRED
81 .long tag_entry_address_end - tag_entry_address_start
82 .long multiboot2_image_start
83 tag_entry_address_end:
[a35b458]84
[1f5c9c96]85 /* Flags tag */
[cfb1217]86 .align 8
[1f5c9c96]87 tag_flags_start:
88 .word MULTIBOOT2_TAG_FLAGS
89 .word MULTIBOOT2_FLAGS_REQUIRED
90 .long tag_flags_end - tag_flags_start
91 .long MULTIBOOT2_FLAGS_CONSOLE
92 tag_flags_end:
[a35b458]93
[40898df]94#ifdef CONFIG_FB
[1f5c9c96]95 /* Framebuffer tag */
[cfb1217]96 .align 8
[1f5c9c96]97 tag_framebuffer_start:
98 .word MULTIBOOT2_TAG_FRAMEBUFFER
99 .word MULTIBOOT2_FLAGS_REQUIRED
100 .long tag_framebuffer_end - tag_framebuffer_start
101 .long CONFIG_BFB_WIDTH
102 .long CONFIG_BFB_HEIGHT
103 .long CONFIG_BFB_BPP
104 tag_framebuffer_end:
[40898df]105#endif
[a35b458]106
[1f5c9c96]107 /* Module alignment tag */
[cfb1217]108 .align 8
[1f5c9c96]109 tag_module_align_start:
110 .word MULTIBOOT2_TAG_MODULE_ALIGN
111 .word MULTIBOOT2_FLAGS_REQUIRED
112 .long tag_module_align_end - tag_module_align_start
113 .long 0
114 tag_module_align_end:
[a35b458]115
[1f5c9c96]116 /* Tag terminator */
[cfb1217]117 .align 8
[1f5c9c96]118 tag_terminator_start:
119 .word MULTIBOOT2_TAG_TERMINATOR
120 .word MULTIBOOT2_FLAGS_REQUIRED
121 .long tag_terminator_end - tag_terminator_start
122 tag_terminator_end:
123multiboot2_header_end:
124
[3b0f1b9a]125SYMBOL(multiboot2_image_start)
[f66c203d]126 cli
[1f5c9c96]127 cld
[a35b458]128
[1f5c9c96]129 /* Initialize stack pointer */
130 movl $START_STACK, %esp
[a35b458]131
[f66c203d]132 /*
133 * Initialize Global Descriptor Table and
134 * Interrupt Descriptor Table registers
135 */
[1f5c9c96]136 lgdtl bootstrap_gdtr
[f66c203d]137 lidtl bootstrap_idtr
[a35b458]138
[1f5c9c96]139 /* Kernel data + stack */
140 movw $GDT_SELECTOR(KDATA_DES), %cx
141 movw %cx, %es
142 movw %cx, %ds
143 movw %cx, %ss
[a35b458]144
[1f5c9c96]145 /*
146 * Simics seems to remove hidden part of GS on entering user mode
147 * when _visible_ part of GS does not point to user-mode segment.
148 */
149 movw $GDT_SELECTOR(UDATA_DES), %cx
150 movw %cx, %fs
151 movw %cx, %gs
[a35b458]152
[1f5c9c96]153 jmpl $GDT_SELECTOR(KTEXT32_DES), $multiboot2_meeting_point
154 multiboot2_meeting_point:
[a35b458]155
[1f5c9c96]156 /*
157 * Protected 32-bit. We want to reuse the code-seg descriptor,
158 * the Default operand size must not be 1 when entering long mode.
159 */
[a35b458]160
[1f5c9c96]161 /* Save multiboot arguments */
162 movl %eax, multiboot_eax
163 movl %ebx, multiboot_ebx
[a35b458]164
[1f5c9c96]165 movl $(INTEL_CPUID_EXTENDED), %eax
166 cpuid
167 cmp $(INTEL_CPUID_EXTENDED), %eax
168 ja extended_cpuid_supported
[a35b458]169
[1f5c9c96]170 jmp pm_error_halt
[a35b458]171
[1f5c9c96]172 extended_cpuid_supported:
[a35b458]173
[1f5c9c96]174 movl $(AMD_CPUID_EXTENDED), %eax
175 cpuid
176 bt $(AMD_EXT_LONG_MODE), %edx
177 jc long_mode_supported
[a35b458]178
[1f5c9c96]179 jmp pm_error_halt
[a35b458]180
[1f5c9c96]181 long_mode_supported:
[a35b458]182
[1f5c9c96]183 bt $(AMD_EXT_NOEXECUTE), %edx
184 jc noexecute_supported
[a35b458]185
[1f5c9c96]186 jmp pm_error_halt
[a35b458]187
[1f5c9c96]188 noexecute_supported:
[a35b458]189
[1f5c9c96]190 movl $(INTEL_CPUID_STANDARD), %eax
191 cpuid
192 bt $(INTEL_FXSAVE), %edx
193 jc fx_supported
[a35b458]194
[1f5c9c96]195 jmp pm_error_halt
[a35b458]196
[1f5c9c96]197 fx_supported:
[a35b458]198
[1f5c9c96]199 bt $(INTEL_SSE2), %edx
200 jc sse2_supported
[a35b458]201
[1f5c9c96]202 jmp pm_error_halt
[a35b458]203
[1f5c9c96]204 sse2_supported:
[a35b458]205
[1f5c9c96]206 /*
207 * Enable 64-bit page translation entries - CR4.PAE = 1.
208 * Paging is not enabled until after long mode is enabled.
209 */
[a35b458]210
[1f5c9c96]211 movl %cr4, %eax
[811770c]212 orl $CR4_PAE, %eax
[1f5c9c96]213 movl %eax, %cr4
[a35b458]214
[1f5c9c96]215 /* Set up paging tables */
216 leal ptl_0, %eax
217 movl %eax, %cr3
[a35b458]218
[1f5c9c96]219 /* Enable long mode */
[811770c]220 movl $AMD_MSR_EFER, %ecx
[1f5c9c96]221 rdmsr /* read EFER */
[811770c]222 orl $AMD_LME, %eax /* set LME = 1 */
[1f5c9c96]223 wrmsr
[a35b458]224
[1f5c9c96]225 /* Enable paging to activate long mode (set CR0.PG = 1) */
226 movl %cr0, %eax
[811770c]227 orl $CR0_PG, %eax
[1f5c9c96]228 movl %eax, %cr0
[a35b458]229
[1f5c9c96]230 /* At this point we are in compatibility mode */
231 jmpl $GDT_SELECTOR(KTEXT_DES), $start64
232
233pm_error_halt:
234 cli
235 hlt1:
236 hlt
237 jmp hlt1
238
239.code64
240
241start64:
[a35b458]242
[1f5c9c96]243 /*
244 * Long mode.
245 */
[a35b458]246
[1f5c9c96]247 movq $(PA2KA(START_STACK)), %rsp
[a35b458]248
[1f5c9c96]249 /* Create the first stack frame */
250 pushq $0
251 movq %rsp, %rbp
[a35b458]252
[36df4109]253 /* Call amd64_pre_main(multiboot_eax, multiboot_ebx) */
[1f5c9c96]254 movl multiboot_eax, %edi
255 movl multiboot_ebx, %esi
[a35b458]256
[4bf0926e]257#ifdef MEMORY_MODEL_large
258 movabsq $amd64_pre_main, %rax
259 callq *%rax
260#else
261 callq amd64_pre_main
262#endif
[a35b458]263
[1f5c9c96]264 /* Call main_bsp() */
[4bf0926e]265#ifdef MEMORY_MODEL_large
266 movabsq $main_bsp, %rax
267 callq *%rax
268#else
269 callq main_bsp
270#endif
[a35b458]271
[1f5c9c96]272 /* Not reached */
273 cli
274 hlt0:
275 hlt
276 jmp hlt0
Note: See TracBrowser for help on using the repository browser.