Rev 2302 | Rev 2703 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 2692 | decky | 1 | |
| 2071 | jermar | 2 | # Copyright (c) 2005 Ondrej Palkovsky |
| 3 | # Copyright (c) 2006 Martin Decky |
||
| 164 | palkovsky | 4 | # All rights reserved. |
| 5 | # |
||
| 6 | # Redistribution and use in source and binary forms, with or without |
||
| 7 | # modification, are permitted provided that the following conditions |
||
| 8 | # are met: |
||
| 9 | # |
||
| 10 | # - Redistributions of source code must retain the above copyright |
||
| 11 | # notice, this list of conditions and the following disclaimer. |
||
| 12 | # - Redistributions in binary form must reproduce the above copyright |
||
| 13 | # notice, this list of conditions and the following disclaimer in the |
||
| 14 | # documentation and/or other materials provided with the distribution. |
||
| 15 | # - The name of the author may not be used to endorse or promote products |
||
| 16 | # derived from this software without specific prior written permission. |
||
| 17 | # |
||
| 18 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
||
| 19 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
||
| 20 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
| 21 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
| 22 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
| 23 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||
| 24 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||
| 25 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
| 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
||
| 27 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
| 28 | # |
||
| 29 | |||
| 695 | decky | 30 | #include <arch/boot/boot.h> |
| 31 | #include <arch/boot/memmap.h> |
||
| 194 | palkovsky | 32 | #include <arch/mm/page.h> |
| 188 | palkovsky | 33 | #include <arch/mm/ptl.h> |
| 194 | palkovsky | 34 | #include <arch/pm.h> |
| 251 | palkovsky | 35 | #include <arch/cpu.h> |
| 275 | palkovsky | 36 | #include <arch/cpuid.h> |
| 164 | palkovsky | 37 | |
| 694 | decky | 38 | #define START_STACK (BOOT_OFFSET - BOOT_STACK_SIZE) |
| 275 | palkovsky | 39 | |
| 406 | jermar | 40 | .section K_TEXT_START, "ax" |
| 695 | decky | 41 | |
| 680 | decky | 42 | .code32 |
| 43 | .align 4 |
||
| 695 | decky | 44 | .global multiboot_image_start |
| 680 | decky | 45 | multiboot_header: |
| 46 | .long MULTIBOOT_HEADER_MAGIC |
||
| 47 | .long MULTIBOOT_HEADER_FLAGS |
||
| 48 | .long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS) # checksum |
||
| 694 | decky | 49 | .long multiboot_header |
| 50 | .long unmapped_ktext_start |
||
| 680 | decky | 51 | .long 0 |
| 52 | .long 0 |
||
| 694 | decky | 53 | .long multiboot_image_start |
| 188 | palkovsky | 54 | |
| 680 | decky | 55 | multiboot_image_start: |
| 695 | decky | 56 | movl $START_STACK, %esp # initialize stack pointer |
| 57 | lgdt bootstrap_gdtr # initialize Global Descriptor Table register |
||
| 680 | decky | 58 | |
| 685 | decky | 59 | movw $gdtselector(KDATA_DES), %cx |
| 60 | movw %cx, %es |
||
| 61 | movw %cx, %ds # kernel data + stack |
||
| 62 | movw %cx, %ss |
||
| 807 | palkovsky | 63 | # Simics seems to remove hidden part of GS on entering user mode |
| 64 | # when _visible_ part of GS does not point to user-mode segment |
||
| 65 | movw $gdtselector(UDATA_DES), %cx |
||
| 66 | movw %cx, %fs |
||
| 67 | movw %cx, %gs |
||
| 685 | decky | 68 | |
| 695 | decky | 69 | jmpl $gdtselector(KTEXT32_DES), $multiboot_meeting_point |
| 685 | decky | 70 | multiboot_meeting_point: |
| 71 | |||
| 695 | decky | 72 | movl %eax, grub_eax # save parameters from GRUB |
| 73 | movl %ebx, grub_ebx |
||
| 74 | |||
| 2219 | decky | 75 | # Protected 32-bit. We want to reuse the code-seg descriptor, |
| 76 | # the Default operand size must not be 1 when entering long mode |
||
| 77 | |||
| 2692 | decky | 78 | movl $(INTEL_CPUID_EXTENDED), %eax |
| 2219 | decky | 79 | cpuid |
| 2692 | decky | 80 | cmp $(INTEL_CPUID_EXTENDED), %eax |
| 81 | ja extended_cpuid_supported |
||
| 82 | |||
| 83 | movl $extended_cpuid_msg, %esi |
||
| 84 | jmp error_halt |
||
| 85 | |||
| 86 | extended_cpuid_supported: |
||
| 87 | |||
| 88 | movl $(AMD_CPUID_EXTENDED), %eax |
||
| 2219 | decky | 89 | cpuid |
| 2692 | decky | 90 | bt $(AMD_EXT_LONG_MODE), %edx |
| 2219 | decky | 91 | jc long_mode_supported |
| 2692 | decky | 92 | |
| 2219 | decky | 93 | movl $long_mode_msg, %esi |
| 94 | jmp error_halt |
||
| 2692 | decky | 95 | |
| 2219 | decky | 96 | long_mode_supported: |
| 97 | |||
| 2692 | decky | 98 | bt $(AMD_EXT_NOEXECUTE), %edx |
| 99 | jc noexecute_supported |
||
| 100 | |||
| 101 | movl $noexecute_msg, %esi |
||
| 102 | jmp error_halt |
||
| 103 | |||
| 104 | noexecute_supported: |
||
| 105 | |||
| 106 | movl $(INTEL_CPUID_STANDARD), %eax |
||
| 107 | cpuid |
||
| 108 | bt $(INTEL_FXSAVE), %edx |
||
| 109 | jc fx_supported |
||
| 110 | |||
| 111 | movl $fx_msg, %esi |
||
| 112 | jmp error_halt |
||
| 113 | |||
| 114 | fx_supported: |
||
| 115 | |||
| 116 | bt $(INTEL_SSE2), %edx |
||
| 117 | jc sse2_supported |
||
| 118 | |||
| 119 | movl $sse2_msg, %esi |
||
| 120 | jmp error_halt |
||
| 121 | |||
| 122 | sse2_supported: |
||
| 123 | |||
| 1289 | vana | 124 | #ifdef CONFIG_FB |
| 2219 | decky | 125 | mov $vesa_init, %esi |
| 1641 | decky | 126 | mov $VESA_INIT_SEGMENT << 4, %edi |
| 127 | mov $e_vesa_init - vesa_init, %ecx |
||
| 128 | cld |
||
| 129 | rep movsb |
||
| 1289 | vana | 130 | |
| 1641 | decky | 131 | mov $VESA_INIT_SEGMENT << 4, %edi |
| 132 | jmpl *%edi |
||
| 133 | |||
| 134 | vesa_meeting_point: |
||
| 135 | |||
| 136 | mov %esi, KA2PA(vesa_ph_addr) |
||
| 137 | mov %di, KA2PA(vesa_height) |
||
| 138 | shr $16, %edi |
||
| 139 | mov %di, KA2PA(vesa_width) |
||
| 140 | mov %bx, KA2PA(vesa_scanline) |
||
| 141 | shr $16, %ebx |
||
| 142 | mov %bx, KA2PA(vesa_bpp) |
||
| 1289 | vana | 143 | #endif |
| 275 | palkovsky | 144 | |
| 2692 | decky | 145 | # Enable 64-bit page translation entries - CR4.PAE = 1. |
| 188 | palkovsky | 146 | # Paging is not enabled until after long mode is enabled |
| 694 | decky | 147 | |
| 188 | palkovsky | 148 | movl %cr4, %eax |
| 149 | btsl $5, %eax |
||
| 150 | movl %eax, %cr4 |
||
| 151 | |||
| 152 | # Set up paging tables |
||
| 694 | decky | 153 | |
| 188 | palkovsky | 154 | leal ptl_0, %eax |
| 155 | movl %eax, %cr3 |
||
| 275 | palkovsky | 156 | |
| 188 | palkovsky | 157 | # Enable long mode |
| 178 | palkovsky | 158 | |
| 694 | decky | 159 | movl $EFER_MSR_NUM, %ecx # EFER MSR number |
| 160 | rdmsr # Read EFER |
||
| 2692 | decky | 161 | btsl $AMD_LME_FLAG, %eax # Set LME = 1 |
| 694 | decky | 162 | wrmsr # Write EFER |
| 163 | |||
| 2692 | decky | 164 | # Enable paging to activate long mode (set CR0.PG = 1) |
| 694 | decky | 165 | |
| 188 | palkovsky | 166 | movl %cr0, %eax |
| 167 | btsl $31, %eax |
||
| 168 | movl %eax, %cr0 |
||
| 169 | |||
| 170 | # At this point we are in compatibility mode |
||
| 694 | decky | 171 | |
| 206 | palkovsky | 172 | jmpl $gdtselector(KTEXT_DES), $start64 |
| 164 | palkovsky | 173 | |
| 188 | palkovsky | 174 | .code64 |
| 175 | start64: |
||
| 275 | palkovsky | 176 | movq $(PA2KA(START_STACK)), %rsp |
| 695 | decky | 177 | movl grub_eax, %eax |
| 178 | movl grub_ebx, %ebx |
||
| 179 | |||
| 180 | cmpl $MULTIBOOT_LOADER_MAGIC, %eax # compare GRUB signature |
||
| 181 | je valid_boot |
||
| 182 | |||
| 183 | xorl %ecx, %ecx # no memory size or map available |
||
| 184 | movl %ecx, e801memorysize |
||
| 185 | movl %ecx, e820counter |
||
| 186 | |||
| 187 | jmp invalid_boot |
||
| 188 | |||
| 189 | valid_boot: |
||
| 190 | |||
| 191 | movl (%ebx), %eax # ebx = physical address of struct multiboot_info |
||
| 192 | |||
| 193 | bt $0, %eax # mbi->flags[0] (mem_lower, mem_upper valid) |
||
| 194 | jc mem_valid |
||
| 195 | |||
| 196 | xorl %ecx, %ecx |
||
| 197 | jmp mem_invalid |
||
| 198 | |||
| 199 | mem_valid: |
||
| 200 | movl 4(%ebx), %ecx # mbi->mem_lower |
||
| 201 | addl 8(%ebx), %ecx # mbi->mem_upper |
||
| 202 | |||
| 203 | mem_invalid: |
||
| 204 | movl %ecx, e801memorysize |
||
| 205 | |||
| 1039 | decky | 206 | bt $3, %eax # mbi->flags[3] (mods_count, mods_addr valid) |
| 695 | decky | 207 | jc mods_valid |
| 208 | |||
| 1052 | decky | 209 | xorq %rcx, %rcx |
| 210 | movq %rcx, init |
||
| 1039 | decky | 211 | jmp mods_end |
| 695 | decky | 212 | |
| 213 | mods_valid: |
||
| 1039 | decky | 214 | |
| 215 | xorq %rcx, %rcx |
||
| 695 | decky | 216 | movl 20(%ebx), %ecx # mbi->mods_count |
| 1052 | decky | 217 | movq %rcx, init |
| 1039 | decky | 218 | |
| 695 | decky | 219 | cmpl $0, %ecx |
| 1039 | decky | 220 | je mods_end |
| 695 | decky | 221 | |
| 222 | movl 24(%ebx), %esi # mbi->mods_addr |
||
| 1039 | decky | 223 | movq $init, %rdi |
| 695 | decky | 224 | |
| 1039 | decky | 225 | mods_loop: |
| 226 | |||
| 227 | xorq %rdx, %rdx |
||
| 228 | movl 0(%esi), %edx # mods->mod_start |
||
| 1063 | palkovsky | 229 | movq $0xffff800000000000, %r10 |
| 230 | addq %r10, %rdx |
||
| 1052 | decky | 231 | movq %rdx, 8(%rdi) |
| 1039 | decky | 232 | |
| 233 | xorq %rdx, %rdx |
||
| 234 | movl 4(%esi), %edx |
||
| 235 | subl 0(%esi), %edx # mods->mod_end - mods->mod_start |
||
| 1052 | decky | 236 | movq %rdx, 16(%rdi) |
| 1039 | decky | 237 | |
| 238 | addl $16, %esi |
||
| 239 | addq $16, %rdi |
||
| 240 | |||
| 241 | loop mods_loop |
||
| 242 | |||
| 243 | mods_end: |
||
| 695 | decky | 244 | |
| 245 | bt $6, %eax # mbi->flags[6] (mmap_length, mmap_addr valid) |
||
| 246 | jc mmap_valid |
||
| 247 | |||
| 248 | xorl %edx, %edx |
||
| 249 | jmp mmap_invalid |
||
| 250 | |||
| 251 | mmap_valid: |
||
| 252 | movl 44(%ebx), %ecx # mbi->mmap_length |
||
| 253 | movl 48(%ebx), %esi # mbi->mmap_addr |
||
| 254 | movq $e820table, %rdi |
||
| 255 | xorl %edx, %edx |
||
| 256 | |||
| 257 | mmap_loop: |
||
| 258 | cmpl $0, %ecx |
||
| 259 | jle mmap_end |
||
| 260 | |||
| 261 | movl 4(%esi), %eax # mmap->base_addr_low |
||
| 262 | movl %eax, (%rdi) |
||
| 263 | |||
| 264 | movl 8(%esi), %eax # mmap->base_addr_high |
||
| 265 | movl %eax, 4(%rdi) |
||
| 266 | |||
| 267 | movl 12(%esi), %eax # mmap->length_low |
||
| 268 | movl %eax, 8(%rdi) |
||
| 269 | |||
| 270 | movl 16(%esi), %eax # mmap->length_high |
||
| 271 | movl %eax, 12(%rdi) |
||
| 272 | |||
| 273 | movl 20(%esi), %eax # mmap->type |
||
| 274 | movl %eax, 16(%rdi) |
||
| 275 | |||
| 276 | movl (%esi), %eax # mmap->size |
||
| 277 | addl $0x4, %eax |
||
| 278 | addl %eax, %esi |
||
| 279 | subl %eax, %ecx |
||
| 280 | addq $MEMMAP_E820_RECORD_SIZE, %rdi |
||
| 281 | incl %edx |
||
| 282 | jmp mmap_loop |
||
| 283 | |||
| 284 | mmap_end: |
||
| 285 | |||
| 286 | mmap_invalid: |
||
| 287 | movl %edx, e820counter |
||
| 288 | |||
| 289 | invalid_boot: |
||
| 290 | |||
| 696 | decky | 291 | #ifdef CONFIG_SMP |
| 292 | |||
| 293 | # copy AP bootstrap routines below 1 MB |
||
| 294 | |||
| 295 | movq $BOOT_OFFSET, %rsi |
||
| 296 | movq $AP_BOOT_OFFSET, %rdi |
||
| 297 | movq $_hardcoded_unmapped_size, %rcx |
||
| 298 | cld |
||
| 299 | rep movsb |
||
| 300 | |||
| 301 | #endif |
||
| 302 | |||
| 694 | decky | 303 | call main_bsp # never returns |
| 178 | palkovsky | 304 | |
| 694 | decky | 305 | cli |
| 306 | hlt |
||
| 1289 | vana | 307 | |
| 308 | #ifdef CONFIG_FB |
||
| 309 | .code32 |
||
| 310 | vesa_init: |
||
| 1641 | decky | 311 | jmp $gdtselector(VESA_INIT_DES), $vesa_init_real - vesa_init |
| 312 | |||
| 1289 | vana | 313 | .code16 |
| 1641 | decky | 314 | vesa_init_real: |
| 1289 | vana | 315 | |
| 1641 | decky | 316 | mov %cr0, %eax |
| 317 | and $~1, %eax |
||
| 318 | mov %eax, %cr0 |
||
| 319 | |||
| 320 | jmp $VESA_INIT_SEGMENT, $vesa_init_real2 - vesa_init |
||
| 321 | |||
| 322 | vesa_init_real2: |
||
| 323 | |||
| 324 | mov $VESA_INIT_SEGMENT, %bx |
||
| 325 | |||
| 326 | mov %bx, %es |
||
| 327 | mov %bx, %fs |
||
| 328 | mov %bx, %gs |
||
| 329 | mov %bx, %ds |
||
| 330 | mov %bx, %ss |
||
| 331 | |||
| 332 | movl $0x0000fffc, %esp |
||
| 333 | movl $0x0000fffc, %ebp |
||
| 334 | |||
| 1289 | vana | 335 | #define VESA_INFO_SIZE 1024 |
| 336 | |||
| 2302 | decky | 337 | #define VESA_MODE_ATTRIBUTES_OFFSET 0 |
| 1641 | decky | 338 | #define VESA_MODE_LIST_PTR_OFFSET 14 |
| 2302 | decky | 339 | #define VESA_MODE_SCANLINE_OFFSET 16 |
| 1289 | vana | 340 | #define VESA_MODE_WIDTH_OFFSET 18 |
| 341 | #define VESA_MODE_HEIGHT_OFFSET 20 |
||
| 342 | #define VESA_MODE_BPP_OFFSET 25 |
||
| 343 | #define VESA_MODE_PHADDR_OFFSET 40 |
||
| 344 | |||
| 1641 | decky | 345 | #define VESA_END_OF_MODES 0xffff |
| 1289 | vana | 346 | |
| 1641 | decky | 347 | #define VESA_OK 0x4f |
| 1289 | vana | 348 | |
| 1641 | decky | 349 | #define VESA_GET_INFO 0x4f00 |
| 1289 | vana | 350 | #define VESA_GET_MODE_INFO 0x4f01 |
| 351 | #define VESA_SET_MODE 0x4f02 |
||
| 2302 | decky | 352 | #define VESA_SET_PALETTE 0x4f09 |
| 1289 | vana | 353 | |
| 354 | #define CONFIG_VESA_BPP_a 255 |
||
| 355 | |||
| 1641 | decky | 356 | #if CONFIG_VESA_BPP == 24 |
| 2302 | decky | 357 | #define CONFIG_VESA_BPP_VARIANT 32 |
| 1289 | vana | 358 | #endif |
| 2302 | decky | 359 | |
| 1641 | decky | 360 | mov $VESA_GET_INFO, %ax |
| 361 | mov $e_vesa_init - vesa_init, %di |
||
| 362 | push %di |
||
| 363 | int $0x10 |
||
| 364 | |||
| 365 | pop %di |
||
| 366 | cmp $VESA_OK, %al |
||
| 367 | jnz 0f |
||
| 368 | |||
| 369 | mov 2 + VESA_MODE_LIST_PTR_OFFSET(%di), %si |
||
| 370 | mov %si, %gs |
||
| 371 | mov VESA_MODE_LIST_PTR_OFFSET(%di), %si |
||
| 372 | |||
| 373 | add $VESA_INFO_SIZE, %di |
||
| 2302 | decky | 374 | |
| 1289 | vana | 375 | 1:# Try next mode |
| 1641 | decky | 376 | mov %gs:(%si), %cx |
| 377 | cmp $VESA_END_OF_MODES, %cx |
||
| 378 | jz 0f |
||
| 379 | |||
| 380 | inc %si |
||
| 381 | inc %si |
||
| 382 | push %cx |
||
| 383 | push %di |
||
| 384 | push %si |
||
| 385 | mov $VESA_GET_MODE_INFO, %ax |
||
| 386 | int $0x10 |
||
| 387 | |||
| 388 | pop %si |
||
| 389 | pop %di |
||
| 390 | pop %cx |
||
| 391 | cmp $VESA_OK, %al |
||
| 392 | jnz 0f |
||
| 393 | |||
| 394 | mov $CONFIG_VESA_WIDTH, %ax |
||
| 395 | cmp VESA_MODE_WIDTH_OFFSET(%di), %ax |
||
| 396 | jnz 1b |
||
| 397 | |||
| 398 | mov $CONFIG_VESA_HEIGHT, %ax |
||
| 399 | cmp VESA_MODE_HEIGHT_OFFSET(%di), %ax |
||
| 400 | jnz 1b |
||
| 401 | |||
| 402 | mov $CONFIG_VESA_BPP, %al |
||
| 403 | cmp VESA_MODE_BPP_OFFSET(%di), %al |
||
| 2302 | decky | 404 | |
| 405 | #ifdef CONFIG_VESA_BPP_VARIANT |
||
| 1641 | decky | 406 | jz 2f |
| 407 | |||
| 2302 | decky | 408 | mov $CONFIG_VESA_BPP_VARIANT, %al |
| 1641 | decky | 409 | cmp VESA_MODE_BPP_OFFSET(%di), %al |
| 2302 | decky | 410 | #endif |
| 1641 | decky | 411 | jnz 1b |
| 412 | |||
| 1289 | vana | 413 | 2: |
| 414 | |||
| 1641 | decky | 415 | mov %cx, %bx |
| 416 | or $0xc000, %bx |
||
| 417 | push %di |
||
| 418 | mov $VESA_SET_MODE, %ax |
||
| 419 | int $0x10 |
||
| 1289 | vana | 420 | |
| 1641 | decky | 421 | pop %di |
| 422 | cmp $VESA_OK, %al |
||
| 423 | jnz 0f |
||
| 2302 | decky | 424 | |
| 425 | #if CONFIG_VESA_BPP == 8 |
||
| 1289 | vana | 426 | |
| 2302 | decky | 427 | # Set 3:2:3 VGA palette |
| 428 | |||
| 429 | mov VESA_MODE_ATTRIBUTES_OFFSET(%di), %ax |
||
| 430 | push %di |
||
| 431 | mov $vga323 - vesa_init, %di |
||
| 432 | mov $0x100, %ecx |
||
| 433 | |||
| 434 | bt $5, %ax # Test if VGA compatible registers are present |
||
| 435 | jnc vga_compat |
||
| 436 | |||
| 437 | # Try VESA routine to set palette |
||
| 438 | |||
| 439 | mov $VESA_SET_PALETTE, %ax |
||
| 440 | xor %bl, %bl |
||
| 441 | xor %dx, %dx |
||
| 442 | int $0x10 |
||
| 443 | |||
| 444 | jmp vga_not_compat |
||
| 445 | |||
| 446 | vga_compat: |
||
| 447 | |||
| 448 | # Try VGA registers to set palette |
||
| 449 | |||
| 450 | movw $0x3c6, %dx # Set palette mask |
||
| 451 | movb $0xff, %al |
||
| 452 | outb %al, %dx |
||
| 453 | |||
| 454 | movw $0x3c8, %dx # First index to set |
||
| 455 | xor %al, %al |
||
| 456 | outb %al, %dx |
||
| 457 | |||
| 458 | movw $0x3c9, %dx # Data port |
||
| 459 | vga_loop: |
||
| 460 | movb %es:2(%di), %al |
||
| 461 | outb %al, %dx |
||
| 462 | |||
| 463 | movb %es:1(%di), %al |
||
| 464 | outb %al, %dx |
||
| 465 | |||
| 466 | movb %es:(%di), %al |
||
| 467 | outb %al, %dx |
||
| 468 | |||
| 469 | addw $4, %di |
||
| 470 | loop vga_loop |
||
| 471 | |||
| 472 | vga_not_compat: |
||
| 473 | |||
| 474 | pop %di |
||
| 475 | |||
| 476 | #endif |
||
| 477 | |||
| 1641 | decky | 478 | mov VESA_MODE_PHADDR_OFFSET(%di), %esi |
| 479 | mov VESA_MODE_WIDTH_OFFSET(%di), %ax |
||
| 480 | shl $16, %eax |
||
| 481 | mov VESA_MODE_HEIGHT_OFFSET(%di), %ax |
||
| 482 | mov VESA_MODE_BPP_OFFSET(%di), %bl |
||
| 483 | xor %bh, %bh |
||
| 484 | shl $16, %ebx |
||
| 485 | mov VESA_MODE_SCANLINE_OFFSET(%di), %bx |
||
| 486 | mov %eax, %edi |
||
| 487 | |||
| 488 | 8: |
||
| 489 | |||
| 490 | mov %cr0, %eax |
||
| 491 | or $1, %eax |
||
| 492 | mov %eax, %cr0 |
||
| 493 | |||
| 494 | jmp 9f |
||
| 1289 | vana | 495 | 9: |
| 1641 | decky | 496 | |
| 497 | ljmpl $gdtselector(KTEXT32_DES), $(vesa_init_protect - vesa_init + VESA_INIT_SEGMENT << 4) |
||
| 498 | |||
| 499 | 0:# No prefered mode found |
||
| 500 | mov $0x111, %cx |
||
| 501 | push %di |
||
| 502 | push %cx |
||
| 503 | mov $VESA_GET_MODE_INFO, %ax |
||
| 504 | int $0x10 |
||
| 505 | |||
| 506 | pop %cx |
||
| 507 | pop %di |
||
| 508 | cmp $VESA_OK, %al |
||
| 509 | jnz 1f |
||
| 510 | jz 2b # Force relative jump |
||
| 1289 | vana | 511 | |
| 1641 | decky | 512 | 1: |
| 513 | mov $0x0003, %ax |
||
| 514 | int $0x10 |
||
| 515 | mov $0xffffffff, %edi # EGA text mode used, because of problems with VESA |
||
| 516 | xor %ax, %ax |
||
| 517 | jz 8b # Force relative jump |
||
| 2302 | decky | 518 | |
| 519 | vga323: |
||
| 520 | #include "vga323.pal" |
||
| 1641 | decky | 521 | |
| 1289 | vana | 522 | .code32 |
| 1641 | decky | 523 | vesa_init_protect: |
| 524 | movw $gdtselector(KDATA_DES), %cx |
||
| 525 | movw %cx, %es |
||
| 526 | movw %cx, %ds # kernel data + stack |
||
| 527 | movw %cx, %ss |
||
| 528 | # Simics seems to remove hidden part of GS on entering user mode |
||
| 529 | # when _visible_ part of GS does not point to user-mode segment |
||
| 530 | movw $gdtselector(UDATA_DES), %cx |
||
| 531 | movw %cx, %fs |
||
| 532 | movw %cx, %gs |
||
| 533 | |||
| 2222 | decky | 534 | movl $START_STACK, %esp # initialize stack pointer |
| 535 | |||
| 1641 | decky | 536 | jmpl $gdtselector(KTEXT32_DES), $vesa_meeting_point |
| 537 | |||
| 1289 | vana | 538 | .align 4 |
| 539 | e_vesa_init: |
||
| 2219 | decky | 540 | #endif |
| 541 | |||
| 542 | # Print string from %esi to EGA display (in red) and halt |
||
| 543 | error_halt: |
||
| 544 | movl $0xb8000, %edi # base of EGA text mode memory |
||
| 545 | xorl %eax, %eax |
||
| 546 | |||
| 547 | movw $0x3d4, %dx # read bits 8 - 15 of the cursor address |
||
| 548 | movb $0xe, %al |
||
| 549 | outb %al, %dx |
||
| 550 | |||
| 551 | movw $0x3d5, %dx |
||
| 552 | inb %dx, %al |
||
| 553 | shl $8, %ax |
||
| 554 | |||
| 555 | movw $0x3d4, %dx # read bits 0 - 7 of the cursor address |
||
| 556 | movb $0xf, %al |
||
| 557 | outb %al, %dx |
||
| 558 | |||
| 559 | movw $0x3d5, %dx |
||
| 560 | inb %dx, %al |
||
| 561 | |||
| 562 | cmp $1920, %ax |
||
| 563 | jbe cursor_ok |
||
| 564 | movw $1920, %ax # sanity check for the cursor on the last line |
||
| 565 | cursor_ok: |
||
| 566 | |||
| 567 | movw %ax, %bx |
||
| 568 | shl $1, %eax |
||
| 569 | addl %eax, %edi |
||
| 570 | |||
| 571 | movw $0x0c00, %ax # black background, light red foreground |
||
| 572 | cld |
||
| 573 | |||
| 574 | ploop: |
||
| 575 | lodsb |
||
| 576 | cmp $0, %al |
||
| 577 | je ploop_end |
||
| 578 | stosw |
||
| 579 | inc %bx |
||
| 580 | jmp ploop |
||
| 581 | ploop_end: |
||
| 582 | |||
| 583 | movw $0x3d4, %dx # write bits 8 - 15 of the cursor address |
||
| 584 | movb $0xe, %al |
||
| 585 | outb %al, %dx |
||
| 586 | |||
| 587 | movw $0x3d5, %dx |
||
| 588 | movb %bh, %al |
||
| 589 | outb %al, %dx |
||
| 590 | |||
| 591 | movw $0x3d4, %dx # write bits 0 - 7 of the cursor address |
||
| 592 | movb $0xf, %al |
||
| 593 | outb %al, %dx |
||
| 594 | |||
| 595 | movw $0x3d5, %dx |
||
| 596 | movb %bl, %al |
||
| 597 | outb %al, %dx |
||
| 598 | |||
| 599 | cli |
||
| 600 | hlt |
||
| 206 | palkovsky | 601 | |
| 406 | jermar | 602 | .section K_DATA_START, "aw", @progbits |
| 164 | palkovsky | 603 | .align 4096 |
| 206 | palkovsky | 604 | |
| 417 | palkovsky | 605 | # Identical mapping of first 64MB and the same of -2GB -> 0 |
| 188 | palkovsky | 606 | .global ptl_2 |
| 607 | ptl_2: |
||
| 608 | .quad 0x0 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
||
| 609 | .quad 0x200000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
||
| 610 | .quad 0x400000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
||
| 611 | .quad 0x600000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
||
| 612 | .quad 0x800000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
||
| 613 | .quad 0xa00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
||
| 614 | .quad 0xc00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
||
| 615 | .quad 0xe00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
||
| 417 | palkovsky | 616 | .quad 0x1000000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
| 617 | .quad 0x1200000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
||
| 618 | .quad 0x1400000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
||
| 619 | .quad 0x1600000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
||
| 620 | .quad 0x1800000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
||
| 621 | .quad 0x1a00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
||
| 622 | .quad 0x1c00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
||
| 623 | .quad 0x1e00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
||
| 624 | .quad 0x2000000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
||
| 625 | .quad 0x2200000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
||
| 626 | .quad 0x2400000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
||
| 627 | .quad 0x2600000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
||
| 628 | .quad 0x2800000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
||
| 629 | .quad 0x2a00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
||
| 630 | .quad 0x2c00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
||
| 631 | .quad 0x2e00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
||
| 632 | .quad 0x3000000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
||
| 633 | .quad 0x3200000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
||
| 634 | .quad 0x3400000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
||
| 635 | .quad 0x3600000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
||
| 636 | .quad 0x3800000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
||
| 637 | .quad 0x3a00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
||
| 638 | .quad 0x3c00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
||
| 639 | .quad 0x3e00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) |
||
| 188 | palkovsky | 640 | |
| 641 | .align 4096 |
||
| 642 | .global ptl_1 |
||
| 643 | ptl_1: |
||
| 644 | .quad ptl_2 + (PTL_WRITABLE | PTL_PRESENT) |
||
| 645 | .fill 509,8,0 |
||
| 646 | .quad ptl_2 + (PTL_WRITABLE | PTL_PRESENT) |
||
| 293 | palkovsky | 647 | .fill 1,8,0 |
| 188 | palkovsky | 648 | |
| 649 | .align 4096 |
||
| 650 | .global ptl_0 |
||
| 651 | ptl_0: |
||
| 652 | .quad ptl_1 + (PTL_WRITABLE | PTL_PRESENT) |
||
| 1063 | palkovsky | 653 | .fill 255,8,0 |
| 188 | palkovsky | 654 | .quad ptl_1 + (PTL_WRITABLE | PTL_PRESENT) |
| 1063 | palkovsky | 655 | .fill 254,8,0 |
| 656 | .quad ptl_1 + (PTL_WRITABLE | PTL_PRESENT) |
||
| 178 | palkovsky | 657 | |
| 695 | decky | 658 | .global bootstrap_gdtr |
| 659 | bootstrap_gdtr: |
||
| 685 | decky | 660 | .word gdtselector(GDT_ITEMS) |
| 661 | .long KA2PA(gdt) |
||
| 695 | decky | 662 | |
| 663 | grub_eax: |
||
| 664 | .long 0 |
||
| 665 | |||
| 666 | grub_ebx: |
||
| 667 | .long 0 |
||
| 2219 | decky | 668 | |
| 2692 | decky | 669 | extended_cpuid_msg: |
| 670 | .asciz "Extended CPUID not supported. System halted." |
||
| 2219 | decky | 671 | long_mode_msg: |
| 2302 | decky | 672 | .asciz "64 bit long mode not supported. System halted." |
| 2692 | decky | 673 | noexecute_msg: |
| 674 | .asciz "No-execute pages not supported. System halted." |
||
| 675 | fx_msg: |
||
| 676 | .asciz "FXSAVE/FXRESTORE instructions not supported. System halted." |
||
| 677 | sse2_msg: |
||
| 678 | .asciz "SSE2 instructions not supported. System halted." |