| [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 |
|
|---|
| [8844e70] | 29 | #include <abi/asmtool.h>
|
|---|
| [1f5c9c96] | 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
|
|---|
| 42 | multiboot2_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))
|
|---|
| [a35b458] | 47 |
|
|---|
| [1f5c9c96] | 48 | /* Information request tag */
|
|---|
| [cfb1217] | 49 | .align 8
|
|---|
| [1f5c9c96] | 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
|
|---|
| [9ef1fade] | 54 | .long MULTIBOOT2_TAG_CMDLINE
|
|---|
| [1f5c9c96] | 55 | .long MULTIBOOT2_TAG_MODULE
|
|---|
| 56 | .long MULTIBOOT2_TAG_MEMMAP
|
|---|
| [40898df] | 57 | #ifdef CONFIG_FB
|
|---|
| [1f5c9c96] | 58 | .long MULTIBOOT2_TAG_FBINFO
|
|---|
| [40898df] | 59 | #endif
|
|---|
| [1f5c9c96] | 60 | tag_info_req_end:
|
|---|
| [a35b458] | 61 |
|
|---|
| [1f5c9c96] | 62 | /* Address tag */
|
|---|
| [cfb1217] | 63 | .align 8
|
|---|
| [1f5c9c96] | 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
|
|---|
| [bae43dc] | 69 | .long unmapped_start
|
|---|
| [1f5c9c96] | 70 | .long 0
|
|---|
| 71 | .long 0
|
|---|
| 72 | tag_address_end:
|
|---|
| [a35b458] | 73 |
|
|---|
| [1f5c9c96] | 74 | /* Entry address tag */
|
|---|
| [cfb1217] | 75 | .align 8
|
|---|
| [1f5c9c96] | 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:
|
|---|
| [a35b458] | 82 |
|
|---|
| [1f5c9c96] | 83 | /* Flags tag */
|
|---|
| [cfb1217] | 84 | .align 8
|
|---|
| [1f5c9c96] | 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:
|
|---|
| [a35b458] | 91 |
|
|---|
| [40898df] | 92 | #ifdef CONFIG_FB
|
|---|
| [1f5c9c96] | 93 | /* Framebuffer tag */
|
|---|
| [cfb1217] | 94 | .align 8
|
|---|
| [1f5c9c96] | 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:
|
|---|
| [40898df] | 103 | #endif
|
|---|
| [a35b458] | 104 |
|
|---|
| [1f5c9c96] | 105 | /* Module alignment tag */
|
|---|
| [cfb1217] | 106 | .align 8
|
|---|
| [1f5c9c96] | 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:
|
|---|
| [a35b458] | 113 |
|
|---|
| [1f5c9c96] | 114 | /* Tag terminator */
|
|---|
| [cfb1217] | 115 | .align 8
|
|---|
| [1f5c9c96] | 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:
|
|---|
| 121 | multiboot2_header_end:
|
|---|
| 122 |
|
|---|
| [8844e70] | 123 | SYMBOL(multiboot2_image_start)
|
|---|
| [f66c203d] | 124 | cli
|
|---|
| [1f5c9c96] | 125 | cld
|
|---|
| [a35b458] | 126 |
|
|---|
| [1f5c9c96] | 127 | /* Initialize stack pointer */
|
|---|
| 128 | movl $START_STACK, %esp
|
|---|
| [a35b458] | 129 |
|
|---|
| [f66c203d] | 130 | /*
|
|---|
| 131 | * Initialize Global Descriptor Table and
|
|---|
| 132 | * Interrupt Descriptor Table registers
|
|---|
| 133 | */
|
|---|
| [1f5c9c96] | 134 | lgdtl bootstrap_gdtr
|
|---|
| [f66c203d] | 135 | lidtl bootstrap_idtr
|
|---|
| [a35b458] | 136 |
|
|---|
| [1f5c9c96] | 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
|
|---|
| [a35b458] | 144 |
|
|---|
| [1f5c9c96] | 145 | jmpl $GDT_SELECTOR(KTEXT_DES), $multiboot2_meeting_point
|
|---|
| 146 | multiboot2_meeting_point:
|
|---|
| [a35b458] | 147 |
|
|---|
| [1f5c9c96] | 148 | /* Save multiboot arguments */
|
|---|
| 149 | movl %eax, multiboot_eax
|
|---|
| 150 | movl %ebx, multiboot_ebx
|
|---|
| [a35b458] | 151 |
|
|---|
| [1f5c9c96] | 152 | #ifndef PROCESSOR_i486
|
|---|
| [a35b458] | 153 |
|
|---|
| [1f5c9c96] | 154 | movl $(INTEL_CPUID_LEVEL), %eax
|
|---|
| 155 | cpuid
|
|---|
| 156 | cmp $0x0, %eax /* any function > 0? */
|
|---|
| 157 | jbe pse_unsupported
|
|---|
| [a35b458] | 158 |
|
|---|
| [1f5c9c96] | 159 | movl $(INTEL_CPUID_STANDARD), %eax
|
|---|
| 160 | cpuid
|
|---|
| 161 | bt $(INTEL_PSE), %edx
|
|---|
| 162 | jnc pse_unsupported
|
|---|
| [a35b458] | 163 |
|
|---|
| [1f5c9c96] | 164 | /* Map kernel and turn paging on */
|
|---|
| 165 | call map_kernel_pse
|
|---|
| 166 | jmp stack_init
|
|---|
| [a35b458] | 167 |
|
|---|
| [1f5c9c96] | 168 | #endif /* PROCESSOR_i486 */
|
|---|
| [a35b458] | 169 |
|
|---|
| [1f5c9c96] | 170 | pse_unsupported:
|
|---|
| [a35b458] | 171 |
|
|---|
| [1f5c9c96] | 172 | /* Map kernel and turn paging on */
|
|---|
| 173 | call map_kernel_non_pse
|
|---|
| [a35b458] | 174 |
|
|---|
| [1f5c9c96] | 175 | stack_init:
|
|---|
| [a35b458] | 176 |
|
|---|
| [1f5c9c96] | 177 | /* Create the first stack frame */
|
|---|
| 178 | pushl $0
|
|---|
| 179 | movl %esp, %ebp
|
|---|
| [a35b458] | 180 |
|
|---|
| [36df4109] | 181 | /* Call ia32_pre_main(multiboot_eax, multiboot_ebx) */
|
|---|
| [1f5c9c96] | 182 | pushl multiboot_ebx
|
|---|
| 183 | pushl multiboot_eax
|
|---|
| [36df4109] | 184 | call ia32_pre_main
|
|---|
| [a35b458] | 185 |
|
|---|
| [1f5c9c96] | 186 | /* Call main_bsp() */
|
|---|
| 187 | call main_bsp
|
|---|
| [a35b458] | 188 |
|
|---|
| [1f5c9c96] | 189 | /* Not reached */
|
|---|
| 190 | cli
|
|---|
| 191 | hlt0:
|
|---|
| 192 | hlt
|
|---|
| 193 | jmp hlt0
|
|---|